UNPKG

kre-form

Version:

本项目由 Angular8+ 编写的表单设计器和表单应用,所有的配置都是 JSON 结构体组成,PC 端是基于 ANT 组件库封装

1,362 lines 118 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ import * as tslib_1 from "tslib"; import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, forwardRef, Input, KeyValueDiffers, NgZone, Output, ViewChild, } from "@angular/core"; import { NG_VALUE_ACCESSOR } from "@angular/forms"; import { Formula } from "../tools/formula"; import { searchUsageFun, searchVariable, searchArrayVariable, } from "../tools/common"; import * as _ from "lodash"; import { NzConfigService } from "ng-zorro-antd/core"; import { NzMessageService } from "ng-zorro-antd/message"; import { indexOf } from "lodash"; /** @type {?} */ var CodeMirror = require("codemirror/lib/codemirror"); // import * as CodeMirror from "codemirror/lib/codemirror"; /** * @param {?} str * @return {?} */ function normalizeLineEndings(str) { if (!str) { return str; } return str.replace(/\r\n|\r/g, "\n"); } var DeonCodemirror = /** @class */ (function () { function DeonCodemirror(_differs, _ngZone, el, message, nzConfigService) { this._differs = _differs; this._ngZone = _ngZone; this.el = el; this.message = message; this.nzConfigService = nzConfigService; this.itemTitle = { tablesName: "加班/休假/公出项目", fieldsName: "分析项目", }; this.fml = new Formula(); this.name = "codemirror"; this.title = ""; this.autoFocus = false; /** * 函数显示类型 * 班次 attendance 所有 // attendance-items 精度 进位规则 * * 与categorys互斥,有type时使用type */ this.type = ""; this.typeList = { "attendance-items": [ "MANHOURS", "CalendarDay", "PRECISION", "DepartmentScope", "AND", "OR", "IF", "IN", ], Daycalculation: [ "Daycalculation", "Hourcalculation", "SUM", "Daycompute", "PositionHeadcount", ], }; this.preserveScrollPosition = false; this.labelMap = {}; this._fieldData = {}; this.cursorActivity = new EventEmitter(); this.focusChange = new EventEmitter(); this.scroll = new EventEmitter(); this.drop = new EventEmitter(); this.textChange = new EventEmitter(); this.value = ""; this.disabled = false; this.isFocused = false; /** * 存放匹配的变量集合 */ this.variableSearchList = []; /** * 存放匹配的函数集合 */ this.usageFunSearchList = []; this.FormulaUsage = []; /** * 查询可用变量 */ this._variableSearch = null; /** * 查询可用函数 */ this._usageFunSearch = null; /** * 函数描述 */ this.usageDescription = "\n <ul class=\"intro-wrapper default\">\n <li>\u4ECE\u5DE6\u4FA7\u9762\u677F\u9009\u62E9\u5B57\u6BB5\u540D\u548C\u51FD\u6570\uFF0C\u6216\u8F93\u5165\u51FD\u6570</li>\n <li>\u516C\u5F0F\u7F16\u8F91\u4E3E\u4F8B\uFF1A\n <span class=\"formula-name\">AVERAGE</span>\n (\n <span class=\"formula-field\">\u8BED\u6587\u6210\u7EE9</span>\n ,\n <span class=\"formula-field\">\u6570\u5B66\u6210\u7EE9</span>\n )\n </li>\n </ul>\n "; this.onChange = (/** * @param {?} _ * @return {?} */ function (_) { }); this.onTouched = (/** * @return {?} */ function () { }); } Object.defineProperty(DeonCodemirror.prototype, "options", { set: /** * @param {?} value * @return {?} */ function (value) { this._options = value; if (!this._differ && value) { this._differ = this._differs.find(value).create(); } }, enumerable: true, configurable: true }); Object.defineProperty(DeonCodemirror.prototype, "fieldData", { get: /** * @return {?} */ function () { return this._fieldData; }, /** * 可用变量对象 * { * formFields:[],tableList:[] * } */ set: /** * 可用变量对象 * { * formFields:[],tableList:[] * } * @param {?} value * @return {?} */ function (value) { var _this = this; if (!this.itemTitle.tablesName) { this.itemTitle.tablesName = "加班/休假/公出项目"; } if (!this.itemTitle.fieldsName) { this.itemTitle.fieldsName = "分析项目"; } this._fieldData = value; if (Array.isArray(value) && value.length) { value.forEach((/** * @param {?} el * @return {?} */ function (el) { if (el && el.formFields && Array.isArray(el.formFields)) { el.formFields.forEach((/** * @param {?} item * @return {?} */ function (item) { _this.labelMap["$_widget_" + item.key + "#"] = item.label; })); } if (el && el.tableList && Array.isArray(el.tableList)) { el.tableList.forEach((/** * @param {?} table * @return {?} */ function (table) { if (table && table.fields && Array.isArray(table.fields)) { table.fields.forEach((/** * @param {?} item * @return {?} */ function (item) { _this.labelMap["$_widget_" + item.key + "#"] = item.label; })); } })); } })); } else { if (value && value.formFields && Array.isArray(value.formFields)) { value.formFields.forEach((/** * @param {?} item * @return {?} */ function (item) { _this.labelMap["$_widget_" + item.key + "#"] = item.label; })); } if (value && value.tableList && Array.isArray(value.tableList)) { value.tableList.forEach((/** * @param {?} table * @return {?} */ function (table) { if (table && table.fields && Array.isArray(table.fields)) { table.fields.forEach((/** * @param {?} item * @return {?} */ function (item) { _this.labelMap["$_widget_" + item.key + "#"] = item.label; })); } })); } } }, enumerable: true, configurable: true }); Object.defineProperty(DeonCodemirror.prototype, "dateType", { get: /** * @return {?} */ function () { /** @type {?} */ var t = Array.isArray(this.fieldData); return t ? "array" : "object"; }, enumerable: true, configurable: true }); Object.defineProperty(DeonCodemirror.prototype, "variableSearch", { get: /** * @return {?} */ function () { return this._variableSearch; }, set: /** * @param {?} value * @return {?} */ function (value) { /** @type {?} */ var variableSearchList; if ("array" === this.dateType) { variableSearchList = searchArrayVariable(value, this.fieldData); } else { variableSearchList = searchVariable(value, this.fieldData); } this.variableSearchList = variableSearchList; this._variableSearch = value; }, enumerable: true, configurable: true }); Object.defineProperty(DeonCodemirror.prototype, "usageFunSearch", { get: /** * @return {?} */ function () { return this._usageFunSearch; }, set: /** * @param {?} value * @return {?} */ function (value) { // TODO 只显示当前公式编辑器支持的函数 this.usageFunSearchList = searchUsageFun(value, this.FormulaUsage); this._usageFunSearch = value; }, enumerable: true, configurable: true }); Object.defineProperty(DeonCodemirror.prototype, "globalCategorys", { /** * 所有支持函数分组信息 * name 分组名称 string * code 分组code string * items 函数名集合 string[] */ get: /** * 所有支持函数分组信息 * name 分组名称 string * code 分组code string * items 函数名集合 string[] * @return {?} */ function () { /** @type {?} */ var info = []; _.forEach(this.fml.FormulaUsage, (/** * @param {?} item * @return {?} */ function (item) { info.push({ // name 分组名称 string name: item.category, // code 分组code string code: item.categoryCode, // items 函数名集合 string[] items: _.flatMap(item.contains, (/** * @param {?} c * @return {?} */ function (c) { return c.name; })), }); })); return info; }, enumerable: true, configurable: true }); Object.defineProperty(DeonCodemirror.prototype, "codeMirrorGlobal", { /** * 获取全局CodeMirror */ get: /** * 获取全局CodeMirror * @return {?} */ function () { if (this._codeMirror) { return this._codeMirror; } this._codeMirror = typeof CodeMirror !== "undefined" ? CodeMirror : require("codemirror"); return this._codeMirror; }, enumerable: true, configurable: true }); /** * @return {?} */ DeonCodemirror.prototype.ngOnInit = /** * @return {?} */ function () { this.nzConfigService.set("message", { nzMaxStack: 1, nzAnimate: false, }); // document.addEventListener("paste", async (e) => { // e.preventDefault(); // const value = await navigator.clipboard.readText(); // // console.log("Pasted text: ", text); // if (!!value && _.isString(value)) { // this.value = value; // this.setValue(); // this.message.success(`粘贴成功`); // } else { // this.message.warning(`粘贴失败`); // } // // var content; // // e.preventDefault(); // // if (e["clipboardData"]) { // // content = e["clipboardData"].getData("text/plain"); // // document.execCommand("insertText", false, content); // // return false; // // } else if (window["clipboardData"]) { // // content = window["clipboardData"].getData("Text"); // // if (window.getSelection) // // window // // .getSelection() // // .getRangeAt(0) // // .insertNode(document.createTextNode(content)); // // } // // console.log(content); // // this.value = content; // // this.setValue(); // }); }; /** * 根据黑名单过滤公式 */ /** * 根据黑名单过滤公式 * @param {?} formulaUsage * @return {?} */ DeonCodemirror.prototype.filterUsageByBlackList = /** * 根据黑名单过滤公式 * @param {?} formulaUsage * @return {?} */ function (formulaUsage) { var _this = this; // const FormulaUsage = _.cloneDeep(this.fml.FormulaUsage); /** @type {?} */ var FormulaUsageList = []; // console.log(list); formulaUsage.forEach((/** * @param {?} el * @return {?} */ function (el) { el.contains.forEach((/** * @param {?} formula * @return {?} */ function (formula) { // 黑名单列表内的Index。 /** @type {?} */ var blackIndex = indexOf(_this.blacklist, formula.name); if (blackIndex < 0) { if (FormulaUsageList.findIndex((/** * @param {?} ele * @return {?} */ function (ele) { return ele.category === el.category; })) > -1) { /** @type {?} */ var index = FormulaUsageList.findIndex((/** * @param {?} ele * @return {?} */ function (ele) { return ele.category === el.category; })); ((/** @type {?} */ (FormulaUsageList[index].contains))).push(formula); } else { /** @type {?} */ var item = { category: el.category, contains: [], }; item.contains.push(formula); FormulaUsageList.push(item); } } })); })); return FormulaUsageList; }; /** * 组装显示的函数 */ /** * 组装显示的函数 * @return {?} */ DeonCodemirror.prototype.resolveDisplayFormula = /** * 组装显示的函数 * @return {?} */ function () { console.log("resolveDisplayFormula"); /** @type {?} */ var displayFormula = []; if (this.type && !_.isEmpty(this.type)) { displayFormula = this.typeList[this.type]; return displayFormula || []; } /** * this.categorys 显示的函数组 * 与this.type 互斥,this.type优先级最高。 */ if (this.categorys && Array.isArray(this.categorys)) { // 显示函数组数组转对象 /** @type {?} */ var displayCategory_1 = _.keyBy(this.categorys, (/** * @param {?} o * @return {?} */ function (o) { return o; })); // 过滤出需显示的函数 this.globalCategorys.map((/** * @param {?} c * @return {?} */ function (c) { if (c.items && displayCategory_1[c.code]) { displayFormula = displayFormula.concat(c.items); } })); } return displayFormula || []; }; /** * 组装FomulaContext */ /** * 组装FomulaContext * @return {?} */ DeonCodemirror.prototype.resolveFomulaContext = /** * 组装FomulaContext * @return {?} */ function () { /** @type {?} */ var fomlaArray = []; if (!this.FormulaUsage) { return fomlaArray; } this.FormulaUsage.map((/** * @param {?} usage * @return {?} */ function (usage) { /** @type {?} */ var contains = _.flatMap(usage.contains, (/** * @param {?} c * @return {?} */ function (c) { return c.name; })); fomlaArray.push.apply(fomlaArray, tslib_1.__spread(contains)); })); this._fomulaContext = fomlaArray; return fomlaArray; }; /** * @return {?} */ DeonCodemirror.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var FormulaUsage = _.cloneDeep(this.fml.FormulaUsage); // 显示的公式 /** @type {?} */ var displayFormula = this.resolveDisplayFormula(); // 黑名单 /** @type {?} */ var blacklist = this.blacklist || []; // 不指定显示函数时 默认屏蔽 if ("attendance-items" != this.type) { //日报专用表达式屏蔽 blacklist.push("CalendarDay", "IN", "DepartmentScope"); } if ("Daycalculation" != this.type) { // 不是Daycalculation类型的表单默认屏蔽 独有函数 blacklist.push("Daycompute", "Hourcalculation", "SUM", "PositionHeadcount"); } // 排除黑名单内公式. if (this.blacklist && Array.isArray(this.blacklist)) { FormulaUsage = this.filterUsageByBlackList(FormulaUsage); } if (displayFormula && displayFormula.length > 0) { /** @type {?} */ var list = displayFormula; if (!_.isEmpty(list)) { /** @type {?} */ var FormulaUsageList_1 = []; // console.log(list); list.forEach((/** * @param {?} name * @return {?} */ function (name) { FormulaUsage.forEach((/** * @param {?} el * @return {?} */ function (el) { el.contains.forEach((/** * @param {?} formula * @return {?} */ function (formula) { if (formula.name === name) { if (FormulaUsageList_1.findIndex((/** * @param {?} ele * @return {?} */ function (ele) { return ele.category === el.category; })) > -1) { /** @type {?} */ var index = FormulaUsageList_1.findIndex((/** * @param {?} ele * @return {?} */ function (ele) { return ele.category === el.category; })); ((/** @type {?} */ (FormulaUsageList_1[index].contains))).push(formula); } else { /** @type {?} */ var item = { category: el.category, contains: [], }; item.contains.push(formula); FormulaUsageList_1.push(item); } } })); })); })); this.FormulaUsage = FormulaUsageList_1; } else { this.FormulaUsage = FormulaUsage; } } else { this.FormulaUsage = FormulaUsage.filter((/** * @param {?} el * @return {?} */ function (el) { return el.contains[0].name !== "PositionHeadcount"; })); } if (!this.ref) { return; } this._ngZone.runOutsideAngular((/** * @return {?} */ function () { _this.codeMirror = (/** @type {?} */ (_this.codeMirrorGlobal.fromTextArea(_this.ref.nativeElement, _this._options))); _this.codeMirror.on("cursorActivity", (/** * @param {?} cm * @return {?} */ function (cm) { return _this._ngZone.run((/** * @return {?} */ function () { return _this.cursorActive(cm); })); })); _this.codeMirror.on("scroll", _this.scrollChanged.bind(_this)); _this.codeMirror.on("blur", (/** * @return {?} */ function () { return _this._ngZone.run((/** * @return {?} */ function () { return _this.focusChanged(false); })); })); _this.codeMirror.on("focus", (/** * @return {?} */ function () { return _this._ngZone.run((/** * @return {?} */ function () { return _this.focusChanged(true); })); })); _this.codeMirror.on("change", (/** * @param {?} cm * @param {?} change * @return {?} */ function (cm, change) { _this._ngZone.run((/** * @return {?} */ function () { return _this.codemirrorValueChanged(cm, change); })); })); _this.codeMirror.on("drop", (/** * @param {?} cm * @param {?} e * @return {?} */ function (cm, e) { _this._ngZone.run((/** * @return {?} */ function () { return _this.dropFiles(cm, e); })); })); _this.codeMirror.setValue(_this.value); // CodeMirror.fomulaContext = this.resolveFomulaContext(); CodeMirror.fomulaContext = Object.keys(_this.fml.Formula); })); }; /** * @return {?} */ DeonCodemirror.prototype.ngDoCheck = /** * @return {?} */ function () { var _this = this; if (!this._differ) { return; } /** @type {?} */ var changes = this._differ.diff(this._options); if (changes) { changes.forEachChangedItem((/** * @param {?} option * @return {?} */ function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); })); changes.forEachAddedItem((/** * @param {?} option * @return {?} */ function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); })); changes.forEachRemovedItem((/** * @param {?} option * @return {?} */ function (option) { return _this.setOptionIfChanged(option.key, option.currentValue); })); } }; /** * @return {?} */ DeonCodemirror.prototype.ngOnDestroy = /** * @return {?} */ function () { if (this.codeMirror) { this.codeMirror.toTextArea(); } }; /** * @param {?} cm * @param {?} change * @return {?} */ DeonCodemirror.prototype.codemirrorValueChanged = /** * @param {?} cm * @param {?} change * @return {?} */ function (cm, change) { var _this = this; //console.log("codemirrorValueChanged"); if (change.origin !== "complete") { cm.showHint({ hint: CodeMirror.hint.formula, completeSingle: false, shown: (/** * @return {?} */ function () { }), select: (/** * @param {?} cpt * @param {?} ele * @return {?} */ function (cpt, ele) { }), pick: (/** * @param {?} item * @return {?} */ function (item) { }), }); } else { this.insertBarcket(); } // if (change.origin !== "setValue") { setTimeout((/** * @return {?} */ function () { _this.getValue(); }), 0); // } }; /** * @param {?} optionName * @param {?} newValue * @return {?} */ DeonCodemirror.prototype.setOptionIfChanged = /** * @param {?} optionName * @param {?} newValue * @return {?} */ function (optionName, newValue) { if (!this.codeMirror) { return; } this.codeMirror.setOption((/** @type {?} */ (optionName)), newValue); }; /** * @param {?} focused * @return {?} */ DeonCodemirror.prototype.focusChanged = /** * @param {?} focused * @return {?} */ function (focused) { this.onTouched(); this.isFocused = focused; // CodeMirror.fomulaContext = this._fomulaContext; this.focusChange.emit(focused); }; /** * @param {?} cm * @return {?} */ DeonCodemirror.prototype.scrollChanged = /** * @param {?} cm * @return {?} */ function (cm) { this.scroll.emit(cm.getScrollInfo()); }; /** * @param {?} cm * @return {?} */ DeonCodemirror.prototype.cursorActive = /** * @param {?} cm * @return {?} */ function (cm) { this.cursorActivity.emit(cm); }; /** * @param {?} cm * @param {?} e * @return {?} */ DeonCodemirror.prototype.dropFiles = /** * @param {?} cm * @param {?} e * @return {?} */ function (cm, e) { this.drop.emit([cm, e]); }; /** * @param {?} value * @return {?} */ DeonCodemirror.prototype.writeValue = /** * @param {?} value * @return {?} */ function (value) { if (value === null || value === undefined) { if (this.codeMirror) { this.codeMirror.setValue(""); } return; } this.value = value; this.setValue(); // const cur = this.codeMirror.getValue(); // if ( // value !== cur && // normalizeLineEndings(cur) !== normalizeLineEndings(value) // ) { // this.value = value; // if (this.preserveScrollPosition) { // const prevScrollPosition = this.codeMirror.getScrollInfo(); // this.codeMirror.setValue(this.value); // this.codeMirror.scrollTo( // prevScrollPosition.left, // prevScrollPosition.top // ); // } else { // this.codeMirror.setValue(this.value); // } // this.setValue(); // } }; /** * @param {?} fn * @return {?} */ DeonCodemirror.prototype.registerOnChange = /** * @param {?} fn * @return {?} */ function (fn) { this.onChange = fn; }; /** * @param {?} fn * @return {?} */ DeonCodemirror.prototype.registerOnTouched = /** * @param {?} fn * @return {?} */ function (fn) { this.onTouched = fn; }; /** * @param {?} isDisabled * @return {?} */ DeonCodemirror.prototype.setDisabledState = /** * @param {?} isDisabled * @return {?} */ function (isDisabled) { this.disabled = isDisabled; this.setOptionIfChanged("readOnly", this.disabled); }; /** * 函数鼠标滑动时事件 * @param e */ /** * 函数鼠标滑动时事件 * @param {?} e * @return {?} */ DeonCodemirror.prototype.usageMouseover = /** * 函数鼠标滑动时事件 * @param {?} e * @return {?} */ function (e) { this.usageDescription = "\n <div class=\"formula-title\">" + e.name + "</div>\n <ul class=\"intro-wrapper\">\n <li class=\"intro\">\n " + e.intro + "\n </li>\n <li class=\"usage\">\n \u7528\u6CD5\uFF1A" + e.usage + "\n </li>\n <li class=\"example\">\u793A\u4F8B\uFF1A" + e.example + "</li>\n </ul>\n "; }; /** * 插入函数 * @param e */ /** * 插入函数 * @param {?} e * @return {?} */ DeonCodemirror.prototype.insertUsageFun = /** * 插入函数 * @param {?} e * @return {?} */ function (e) { if (this.codeMirror && this.codeMirror !== null) { /** @type {?} */ var c = this.codeMirror.getCursor(); this.codeMirror.replaceSelection("" + e.name); /** @type {?} */ var d = this.codeMirror.getCursor(); this.insertBarcket(); this.getValue(); } }; /** * 插入可用变量 * @param event */ /** * 插入可用变量 * @param {?} event * @return {?} */ DeonCodemirror.prototype.insertField = /** * 插入可用变量 * @param {?} event * @return {?} */ function (event) { if (this.codeMirror && this.codeMirror !== null) { /** @type {?} */ var c = this.codeMirror.getCursor(); this.codeMirror.replaceSelection("" + event.label + ""); /** @type {?} */ var d = this.codeMirror.getCursor(); /** @type {?} */ var e = { from: c, to: d, key: "$_widget_" + event.key + "#", // 工作项ID label: event.label, }; this.markField(e); this.codeMirror.focus(); this.getValue(); } }; // copy() { // if (!!`${this.value}`) { // window.navigator.clipboard.writeText(this.value); // this.message.success(`复制成功`); // } else { // this.message.warning(`公式为空,请配置公式后复制`); // } // } // tslint:disable-next-line:member-ordering // copy() { // if (!!`${this.value}`) { // window.navigator.clipboard.writeText(this.value); // this.message.success(`复制成功`); // } else { // this.message.warning(`公式为空,请配置公式后复制`); // } // } // tslint:disable-next-line:member-ordering /** * @return {?} */ DeonCodemirror.prototype.copy = // copy() { // if (!!`${this.value}`) { // window.navigator.clipboard.writeText(this.value); // this.message.success(`复制成功`); // } else { // this.message.warning(`公式为空,请配置公式后复制`); // } // } // tslint:disable-next-line:member-ordering /** * @return {?} */ function () { if (!!("" + this.value)) { // this.clipboardService.copyFromContent(text); // ↵ /** @type {?} */ var value = ((/** @type {?} */ (_.cloneDeep(this.value)))).replace("↵", ""); localStorage.setItem("codemirror", value); this.message.success("\u590D\u5236\u6210\u529F"); } else { this.message.warning("\u516C\u5F0F\u4E3A\u7A7A,\u8BF7\u914D\u7F6E\u516C\u5F0F\u540E\u590D\u5236"); } }; /** * @return {?} */ DeonCodemirror.prototype.paste = /** * @return {?} */ function () { if (!!localStorage.getItem("codemirror")) { if (!this.value) { this.value = (/** @type {?} */ (localStorage.getItem("codemirror"))); } else { this.value = "" + this.value + (/** @type {?} */ (localStorage.getItem("codemirror"))); } this.setValue(); this.message.success("\u7C98\u8D34\u6210\u529F"); } else { this.message.warning("\u6CA1\u6709\u9700\u8981\u7C98\u8D34\u7684\u6570\u636E\uFF0C\u8BF7\u5148\u590D\u5236"); } // console.log(event); // if (event["clipboardData"] || event["originalEvent"]) { // var clipboardData = // event["clipboardData"] || (window as any)["clipboardData"]; // var val = clipboardData.getData("text"); // console.log(val); // event.preventDefault(); // } // clipboardy.read(); // console.log(clipboard.readSync()); // window.clipboardData.getData("Text"); // window.navigator.clipboard.readText().then((value) => { // console.log(value); // if (!!value && _.isString(value)) { // this.value = value; // this.setValue(); // this.message.success(`粘贴成功`); // } else { // this.message.warning(`粘贴失败`); // } // }); // let content; // if (e.clipboardData) { // content = e.clipboardData.getData("text/plain"); // document.execCommand("insertText", false, content); // return false; // } else if (window["clipboardData"]) { // content = window["clipboardData"].getData("Text"); // if (window.getSelection) // window // .getSelection() // .getRangeAt(0) // .insertNode(document.createTextNode(content)); // } // console.log(content); }; /** * @private * @param {?} e * @return {?} */ DeonCodemirror.prototype.markField = /** * @private * @param {?} e * @return {?} */ function (e) { if (this.codeMirror && this.codeMirror !== null) { /** @type {?} */ var node = document.createElement("span"); node.innerHTML = e.label; node.className = "cm-field cm-field-value"; node.setAttribute("field-key", e.key); this.codeMirror.markText(e.from, e.to, { handleMouseEvents: !0, atomic: !0, replacedWith: node, }); /** @type {?} */ var d = this.codeMirror.getCursor(); } }; /** * @private * @return {?} */ DeonCodemirror.prototype.insertBarcket = /** * @private * @return {?} */ function () { if (this.codeMirror && this.codeMirror !== null) { /** @type {?} */ var c = this.codeMirror.getCursor(); this.codeMirror.replaceSelection("("); /** @type {?} */ var d = this.codeMirror.getCursor(); /** @type {?} */ var c1 = this.codeMirror.getCursor(); this.codeMirror.replaceSelection(")"); /** @type {?} */ var d1 = this.codeMirror.getCursor(); this.codeMirror.setCursor(d); this.codeMirror.focus(); } }; /** * @private * @return {?} */ DeonCodemirror.prototype.getValue = /** * @private * @return {?} */ function () { var _this = this; /** @type {?} */ var result = []; /** @type {?} */ var codeContent = this.el.nativeElement.querySelectorAll(".CodeMirror-line"); this.fml.Utils.forEach(codeContent, (/** * @param {?} t * @param {?} e * @return {?} */ function (t, e) { _this.fml.Utils.forEach(e.children, (/** * @param {?} t1 * @param {?} e1 * @return {?} */ function (t1, e1) { _this.fml.Utils.forEach(e1.children, (/** * @param {?} t2 * @param {?} e2 * @return {?} */ function (t2, e2) { if (e2.getAttribute("cm-text") !== undefined && e2.getAttribute("cm-text") !== null) { result.push("↵"); } else { if (e2.className === "CodeMirror-widget") { _this.fml.Utils.forEach(e2.children, (/** * @param {?} t3 * @param {?} e3 * @return {?} */ function (t3, e3) { if (e3.getAttribute("field-key") !== undefined && e3.getAttribute("field-key") !== null) { result.push(e3.getAttribute("field-key")); } else { result.push(e3.innerText); } })); } else { result.push(e2.innerText); } } })); })); })); if (result[0] === "↵") { result.splice(0, 1); } this.value = result.join(""); if (this.codeMirror) { this.textChange.emit(this.codeMirror.getValue()); } this.onChange(this.value); }; /** * @private * @param {?} t * @return {?} */ DeonCodemirror.prototype.fakeLabel = /** * @private * @param {?} t * @return {?} */ function (t) { return t ? t.replace(/[\[\]()'"]/g, " ") : ""; }; /** * @private * @return {?} */ DeonCodemirror.prototype.setValue = /** * @private * @return {?} */ function () { var _this = this; if (this.value === undefined || this.value === null || this.value === "") { return; } /** @type {?} */ var e = []; /** @type {?} */ var p = []; /** @type {?} */ var t = this.value.split("\n"); this.fml.Utils.forEach(t, (/** * @param {?} c * @param {?} t1 * @return {?} */ function (c, t1) { /** @type {?} */ var d = ""; /** @type {?} */ var t = t1.split(new RegExp(_this.fml.FormulaEditor.COMMON_REG.FORM_FORMULA, "g")); _this.fml.Utils.forEach(t, (/** * @param {?} t * @param {?} e * @return {?} */ function (t, e) { /** @type {?} */ var i; /** @type {?} */ var a; /** @type {?} */ var n; /** @type {?} */ var s; /** @type {?} */ var o; /** @type {?} */ var r; /** @type {?} */ var l; _this.fml.FormulaEditor.CONST.FIELD_REG.test(e) ? ((a = !1), _this.labelMap && (i = _this.labelMap[e] ? _this.labelMap[e] : " ") && ((i = _this.fakeLabel(i)), (a = !0)), (n = !1), _this.fml.Utils.isNull(i) && ((i = 1), (n = !0)), (s = (l = e.replace("$", "").split("#"))[0]), (o = l[1]), (r = CodeMirror.Pos(c, d.length)), (d += i), (l = CodeMirror.Pos(c, d.length)), p.push({ from: r, to: l, key: "$" + s + "#", label: a ? (_this.labelMap[e] ? _this.labelMap[e] : "") : null, })) : (d += e); })); e.push(d); })); if (this.codeMirror) { this.codeMirror.setValue(e.join("\n")); this.fml.Utils.forEach(p, (/** * @param {?} t * @param {?} e * @return {?} */ function (t, e) { _this.markField(e); })); } }; DeonCodemirror.decorators = [ { type: Component, args: [{ selector: "deon-codemirror", template: "<div class=\"formula-head\">\n <div class=\"formula-title\">\n <span class=\"formula-name\">{{ title }}</span\n ><span class=\"formula-equal\">=</span>\n </div>\n <div class=\"formula-textarea\">\n <textarea [name]=\"name\" autocomplete=\"off\" [autofocus]=\"autoFocus\" #ref>\n </textarea>\n <div class=\"btn-box\">\n <button\n nz-tooltip\n nzTooltipTitle=\"\u590D\u5236\"\n nzOverlayClassName=\" shiftMark-tooltip\"\n (click)=\"copy()\"\n class=\"copy\"\n nz-button\n type=\"button\"\n nzSize=\"small\"\n >\n <!-- [ngxClipboard]='value'\n (cbOnSuccess)='successFun($event)'\n (cbOnError)='errorFun($event)' -->\n <i nz-icon nzType=\"copy\"></i>\n </button>\n <button\n nz-tooltip\n nzTooltipTitle=\"\u7C98\u8D34\"\n nzOverlayClassName=\" shiftMark-tooltip\"\n (click)=\"paste()\"\n nzSize=\"small\"\n class=\"paste\"\n type=\"button\"\n nz-button\n >\n <i class=\"icon-other-WenBen\"></i>\n </button>\n </div>\n </div>\n</div>\n<div class=\"formula-wrapper\">\n <div class=\"field-list\">\n <div class=\"field-label\">\u53EF\u7528\u53D8\u91CF</div>\n <div class=\"field-main\">\n <div class=\"formula-search\">\n <nz-input-group\n [nzPrefix]=\"suffixIconSearch1\"\n [nzSuffix]=\"inputClearTpl1\"\n >\n <input\n type=\"text\"\n nz-input\n placeholder=\"\u641C\u7D22\u53EF\u7528\u53D8\u91CF\"\n [(ngModel)]=\"variableSearch\"\n />\n </nz-input-group>\n <ng-template #suffixIconSearch1>\n <i nz-icon nzType=\"search\"></i>\n </ng-template>\n <ng-template #inputClearTpl1\n ><i\n nz-icon\n class=\"ant-input-clear-icon\"\n nzType=\"close-circle\"\n *ngIf=\"variableSearch\"\n (click)=\"variableSearch = ''\"\n ></i>\n </ng-template>\n </div>\n <div class=\"formula-collapse\">\n <ng-container\n *ngIf=\"\n variableSearch === null || variableSearch === '';\n else varSearchPanel\n \"\n >\n <!-- \u517C\u5BB9 {}\u683C\u5F0F -->\n <ng-container *ngIf=\"dateType !== 'array'; else arrayTemp\">\n <ng-container *ngTemplateOutlet=\"ctx; context: fieldData\">\n </ng-container>\n </ng-container>\n </ng-container>\n\n <!-- \u6570\u7EC4 st -->\n <ng-template #arrayTemp>\n <ng-container *ngFor=\"let item of fieldData\">\n <ng-container *ngTemplateOutlet=\"ctx; context: item\">\n </ng-container>\n </ng-container>\n </ng-template>\n <!-- \u6570\u7EC4 end-->\n\n <!-- content st -->\n <ng-template\n #ctx\n let-filds=\"formFields\"\n let-tl=\"tableList\"\n let-fieldsName=\"fieldsName\"\n let-tablesName=\"tablesName\"\n >\n <nz-collapse nzGhost>\n <!-- formFields -->\n <nz-collapse-panel\n [nzHeader]=\"fieldsName || itemTitle.fieldsName\"\n *ngIf=\"filds && filds != null && filds.length\"\n >\n <ul>\n <li *ngFor=\"let field of filds\" (click)=\"insertField(field)\">\n {{ field.label }}\n </li>\n </ul>\n </nz-collapse-panel>\n\n <!-- tableList -->\n <nz-collapse-panel\n [nzHeader]=\"tablesName || itemTitle.tablesName\"\n *ngIf=\"tl && tl != null && tl.length\"\n >\n <nz-collapse nzGhost>\n <nz-collapse-panel\n *ngFor=\"let table of tl\"\n [nzHeader]=\"table.label\"\n >\n <ul>\n <li\n *ngFor=\"let field of table.fields\"\n (click)=\"insertField(field)\"\n >\n {{ field.label }}\n </li>\n </ul>\n </nz-collapse-panel>\n </nz-collapse>\n </nz-collapse-panel>\n </nz-collapse>\n </ng-template>\n <!-- content end -->\n\n <ng-template #varSearchPanel>\n <ul>\n <li\n *ngFor=\"let item of variableSearchList\"\n (click)=\"insertField(item)\"\n >\n {{ item.label }}\n </li>\n </ul>\n </ng-template>\n </div>\n </div>\n </div>\n <div class=\"formula-list\">\n <div class=\"formula-label\">\u51FD\u6570</div>\n <div class=\"formula-main\">\n <div class=\"formula-menu\">\n <div class=\"formula-search\">\n <nz-input-group\n [nzPrefix]=\"suffixIconSearch2\"\n [nzSuffix]=\"inputClearTpl2\"\n >\n <input\n type=\"text\"\n nz-input\n placeholder=\"\u641C\u7D22\u51FD\u6570\"\n [(ngModel)]=\"usageFunSearch\"\n />\n </nz-input-group>\n <ng-template #suffixIconSearch2>\n <i nz-icon nzType=\"search\"></i>\n </ng-template>\n <ng-template #inputClearTpl2\n ><i\n nz-icon\n class=\"ant-input-clear-icon\"\n nzType=\"close-circle\"\n *ngIf=\"usageFunSearch\"\n (click)=\"usageFunSearch = ''\"\n ></i>\n </ng-template>\n </div>\n <div class=\"formula-collapse\">\n <nz-collapse\n nzGhost\n *ngIf=\"\n usageFunSearch === null || usageFunSearch === '';\n else searchPanel\n \"\n >\n <nz-collapse-panel\n *ngFor=\"let usage of FormulaUsage\"\n [nzHeader]=\"usage.category\"\n >\n <ul>\n <li\n *ngFor=\"let item of usage.contains\"\n (mouseover)=\"usageMouseover(item)\"\n (click)=\"insertUsageFun(item)\"\n >\n {{ item.name }}\n </li>\n </ul>\n </nz-collapse-panel>\n </nz-collapse>\n <ng-template #searchPanel>\n <ul>\n <li\n *ngFor=\"let item of usageFunSearchList\"\n (mouseover)=\"usageMouseover(item)\"\n (click)=\"insertUsageFun(item)\"\n >\n {{ item.name }}\n </li>\n </ul>\n </ng-template>\n </div>\n </div>\n <div\n class=\"formula-intro\"\n [innerHtml]=\"usageDescription | safeHtml\"\n ></div>\n </div>\n </div>\n</div>\n", providers: [ { provide: NG_VALUE_ACCESSOR, // tslint:disable-next-line:no-forward-ref useExisting: forwardRef((/** * @return {?} */ function () { return DeonCodemirror; })), multi: true, }, ], preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush }] } ]; /** @nocollapse */ DeonCodemirror.ctorParameters = function () { return [ { type: KeyValueDiffers }, { type: NgZone }, { type: ElementRef }, { type: NzMessageService }, { type: NzConfigService } ]; }; DeonCodemirror.propDecorators = { itemTitle: [{ type: Input }], options: [{ type: Input }], fieldData: [{ type: Input }], blacklist: [{ type: Input }], name: [{ type: Input }], title: [{ type: Input }], autoFocus: [{ type: Input }], type: [{ type: Input }], categorys: [{ type: Input }], preserveScrollPosition: [{ type: Input }], cursorActivity: [{ type: Output }], focusChange: [{ type: Output }], scroll: [{ type: Output }], drop: [{ type: Output }], textChange: [{ type: Output }], ref: [{ type: ViewChild, args: ["ref", { static: true },] }] }; return DeonCodemirror; }()); export { DeonCodemirror }; if (false) { /** @type {?} */ DeonCodemirror.prototype.itemTitle; /** * 黑名单 值为函数名数组 * @type {?} */ DeonCodemirror.prototype.blacklist; /** @type {?} */ DeonCodemirror.prototype.fml; /** @type {?} */ DeonCodemirror.prototype.name; /** @type {?} */ DeonCodemirror.prototype.title; /** @type {?} */ DeonCodemirror.prototy