import { shortcut, Widget, extend, i18nText, createWidget, Controller, isEmptyString, isEmptyArray } from "@/core"; import { StateEditor } from "@/case"; @shortcut() export class MultiSelectEditor extends Widget { static xtype = "bi.multi_select_editor"; static EVENT_FOCUS = "EVENT_FOCUS"; static EVENT_BLUR = "EVENT_BLUR"; static EVENT_PAUSE = "EVENT_PAUSE"; _defaultConfig() { return extend(super._defaultConfig(...arguments), { baseCls: "bi-multi-select-editor", el: {}, watermark: i18nText("BI-Basic_Search"), }); } _init() { super._init(...arguments); const self = this, o = this.options; this.editor = createWidget(o.el, { type: "bi.select_patch_editor", element: this, height: o.height, watermark: o.watermark, allowBlank: true, value: o.value, defaultText: o.defaultText, text: o.text, tipType: o.tipType, warningTitle: o.warningTitle, }); this.editor.on(Controller.EVENT_CHANGE, function () { self.fireEvent(Controller.EVENT_CHANGE, arguments); }); this.editor.on(StateEditor.EVENT_FOCUS, () => { self.fireEvent(MultiSelectEditor.EVENT_FOCUS); }); this.editor.on(StateEditor.EVENT_BLUR, () => { self.fireEvent(MultiSelectEditor.EVENT_BLUR); }); } focus() { this.editor.focus(); } blur() { this.editor.blur(); } setState(state) { this.editor.setState(state); } setValue(v) { this.editor.setValue(v); } setTipType(v) { this.editor.setTipType(v); } getValue() { return this.editor.getValue(); } getState() { return this.editor.getText(); } getKeywords() { const val = this.editor.getValue(); let keywords = val.split(/\u200b\s\u200b/); if (isEmptyString(keywords[keywords.length - 1])) { keywords = keywords.slice(0, keywords.length - 1); } if (/\u200b\s\u200b$/.test(val)) { return keywords.concat([BI.BlankSplitChar]); } return keywords; } getKeyword() { const val = this.editor.getValue(); let keywords = val.split(/\u200b\s\u200b/); if (isEmptyString(keywords[keywords.length - 1])) { keywords = keywords.slice(0, keywords.length - 1); } return isEmptyArray(keywords) ? "" : keywords[keywords.length - 1]; } populate(items) {} setWaterMark(v) { this.editor.setWaterMark(v); } }