kre-form
Version:
本项目由 Angular8+ 编写的表单设计器和表单应用,所有的配置都是 JSON 结构体组成,PC 端是基于 ANT 组件库封装
1,299 lines • 110 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
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 {?} */
const 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");
}
export class DeonCodemirror {
/**
* @param {?} _differs
* @param {?} _ngZone
* @param {?} el
* @param {?} message
* @param {?} nzConfigService
*/
constructor(_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 = `
<ul class="intro-wrapper default">
<li>从左侧面板选择字段名和函数,或输入函数</li>
<li>公式编辑举例:
<span class="formula-name">AVERAGE</span>
(
<span class="formula-field">语文成绩</span>
,
<span class="formula-field">数学成绩</span>
)
</li>
</ul>
`;
this.onChange = (/**
* @param {?} _
* @return {?}
*/
(_) => { });
this.onTouched = (/**
* @return {?}
*/
() => { });
}
/**
* @param {?} value
* @return {?}
*/
set options(value) {
this._options = value;
if (!this._differ && value) {
this._differ = this._differs.find(value).create();
}
}
/**
* 可用变量对象
* {
* formFields:[],tableList:[]
* }
* @param {?} value
* @return {?}
*/
set fieldData(value) {
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 {?}
*/
(el) => {
if (el && el.formFields && Array.isArray(el.formFields)) {
el.formFields.forEach((/**
* @param {?} item
* @return {?}
*/
(item) => {
this.labelMap[`$_widget_${item.key}#`] = item.label;
}));
}
if (el && el.tableList && Array.isArray(el.tableList)) {
el.tableList.forEach((/**
* @param {?} table
* @return {?}
*/
(table) => {
if (table && table.fields && Array.isArray(table.fields)) {
table.fields.forEach((/**
* @param {?} item
* @return {?}
*/
(item) => {
this.labelMap[`$_widget_${item.key}#`] = item.label;
}));
}
}));
}
}));
}
else {
if (value && value.formFields && Array.isArray(value.formFields)) {
value.formFields.forEach((/**
* @param {?} item
* @return {?}
*/
(item) => {
this.labelMap[`$_widget_${item.key}#`] = item.label;
}));
}
if (value && value.tableList && Array.isArray(value.tableList)) {
value.tableList.forEach((/**
* @param {?} table
* @return {?}
*/
(table) => {
if (table && table.fields && Array.isArray(table.fields)) {
table.fields.forEach((/**
* @param {?} item
* @return {?}
*/
(item) => {
this.labelMap[`$_widget_${item.key}#`] = item.label;
}));
}
}));
}
}
}
/**
* @return {?}
*/
get fieldData() {
return this._fieldData;
}
/**
* @return {?}
*/
get dateType() {
/** @type {?} */
const t = Array.isArray(this.fieldData);
return t ? "array" : "object";
}
/**
* @param {?} value
* @return {?}
*/
set variableSearch(value) {
/** @type {?} */
let variableSearchList;
if ("array" === this.dateType) {
variableSearchList = searchArrayVariable(value, this.fieldData);
}
else {
variableSearchList = searchVariable(value, this.fieldData);
}
this.variableSearchList = variableSearchList;
this._variableSearch = value;
}
/**
* @return {?}
*/
get variableSearch() {
return this._variableSearch;
}
/**
* @param {?} value
* @return {?}
*/
set usageFunSearch(value) {
// TODO 只显示当前公式编辑器支持的函数
this.usageFunSearchList = searchUsageFun(value, this.FormulaUsage);
this._usageFunSearch = value;
}
/**
* @return {?}
*/
get usageFunSearch() {
return this._usageFunSearch;
}
/**
* 所有支持函数分组信息
* name 分组名称 string
* code 分组code string
* items 函数名集合 string[]
* @return {?}
*/
get globalCategorys() {
/** @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;
}
/**
* 获取全局CodeMirror
* @return {?}
*/
get codeMirrorGlobal() {
if (this._codeMirror) {
return this._codeMirror;
}
this._codeMirror =
typeof CodeMirror !== "undefined" ? CodeMirror : require("codemirror");
return this._codeMirror;
}
/**
* @return {?}
*/
ngOnInit() {
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 {?}
*/
filterUsageByBlackList(formulaUsage) {
// const FormulaUsage = _.cloneDeep(this.fml.FormulaUsage);
/** @type {?} */
let FormulaUsageList = [];
// console.log(list);
formulaUsage.forEach((/**
* @param {?} el
* @return {?}
*/
(el) => {
el.contains.forEach((/**
* @param {?} formula
* @return {?}
*/
(formula) => {
// 黑名单列表内的Index。
/** @type {?} */
const blackIndex = indexOf(this.blacklist, formula.name);
if (blackIndex < 0) {
if (FormulaUsageList.findIndex((/**
* @param {?} ele
* @return {?}
*/
(ele) => ele.category === el.category)) >
-1) {
/** @type {?} */
let index = FormulaUsageList.findIndex((/**
* @param {?} ele
* @return {?}
*/
(ele) => ele.category === el.category));
((/** @type {?} */ (FormulaUsageList[index].contains))).push(formula);
}
else {
/** @type {?} */
let item = {
category: el.category,
contains: [],
};
item.contains.push(formula);
FormulaUsageList.push(item);
}
}
}));
}));
return FormulaUsageList;
}
/**
* 组装显示的函数
* @return {?}
*/
resolveDisplayFormula() {
console.log("resolveDisplayFormula");
/** @type {?} */
let 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 {?} */
const displayCategory = _.keyBy(this.categorys, (/**
* @param {?} o
* @return {?}
*/
function (o) {
return o;
}));
// 过滤出需显示的函数
this.globalCategorys.map((/**
* @param {?} c
* @return {?}
*/
(c) => {
if (c.items && displayCategory[c.code]) {
displayFormula = displayFormula.concat(c.items);
}
}));
}
return displayFormula || [];
}
/**
* 组装FomulaContext
* @return {?}
*/
resolveFomulaContext() {
/** @type {?} */
const fomlaArray = [];
if (!this.FormulaUsage) {
return fomlaArray;
}
this.FormulaUsage.map((/**
* @param {?} usage
* @return {?}
*/
(usage) => {
/** @type {?} */
const contains = _.flatMap(usage.contains, (/**
* @param {?} c
* @return {?}
*/
function (c) {
return c.name;
}));
fomlaArray.push(...contains);
}));
this._fomulaContext = fomlaArray;
return fomlaArray;
}
/**
* @return {?}
*/
ngAfterViewInit() {
/** @type {?} */
var FormulaUsage = _.cloneDeep(this.fml.FormulaUsage);
// 显示的公式
/** @type {?} */
const displayFormula = this.resolveDisplayFormula();
// 黑名单
/** @type {?} */
let 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 {?} */
let list = displayFormula;
if (!_.isEmpty(list)) {
/** @type {?} */
let FormulaUsageList = [];
// console.log(list);
list.forEach((/**
* @param {?} name
* @return {?}
*/
(name) => {
FormulaUsage.forEach((/**
* @param {?} el
* @return {?}
*/
(el) => {
el.contains.forEach((/**
* @param {?} formula
* @return {?}
*/
(formula) => {
if (formula.name === name) {
if (FormulaUsageList.findIndex((/**
* @param {?} ele
* @return {?}
*/
(ele) => ele.category === el.category)) > -1) {
/** @type {?} */
let index = FormulaUsageList.findIndex((/**
* @param {?} ele
* @return {?}
*/
(ele) => ele.category === el.category));
((/** @type {?} */ (FormulaUsageList[index].contains))).push(formula);
}
else {
/** @type {?} */
let item = {
category: el.category,
contains: [],
};
item.contains.push(formula);
FormulaUsageList.push(item);
}
}
}));
}));
}));
this.FormulaUsage = FormulaUsageList;
}
else {
this.FormulaUsage = FormulaUsage;
}
}
else {
this.FormulaUsage = FormulaUsage.filter((/**
* @param {?} el
* @return {?}
*/
(el) => el.contains[0].name !== "PositionHeadcount"));
}
if (!this.ref) {
return;
}
this._ngZone.runOutsideAngular((/**
* @return {?}
*/
() => {
this.codeMirror = (/** @type {?} */ (this.codeMirrorGlobal.fromTextArea(this.ref.nativeElement, this._options)));
this.codeMirror.on("cursorActivity", (/**
* @param {?} cm
* @return {?}
*/
(cm) => this._ngZone.run((/**
* @return {?}
*/
() => this.cursorActive(cm)))));
this.codeMirror.on("scroll", this.scrollChanged.bind(this));
this.codeMirror.on("blur", (/**
* @return {?}
*/
() => this._ngZone.run((/**
* @return {?}
*/
() => this.focusChanged(false)))));
this.codeMirror.on("focus", (/**
* @return {?}
*/
() => this._ngZone.run((/**
* @return {?}
*/
() => this.focusChanged(true)))));
this.codeMirror.on("change", (/**
* @param {?} cm
* @param {?} change
* @return {?}
*/
(cm, change) => {
this._ngZone.run((/**
* @return {?}
*/
() => this.codemirrorValueChanged(cm, change)));
}));
this.codeMirror.on("drop", (/**
* @param {?} cm
* @param {?} e
* @return {?}
*/
(cm, e) => {
this._ngZone.run((/**
* @return {?}
*/
() => this.dropFiles(cm, e)));
}));
this.codeMirror.setValue(this.value);
// CodeMirror.fomulaContext = this.resolveFomulaContext();
CodeMirror.fomulaContext = Object.keys(this.fml.Formula);
}));
}
/**
* @return {?}
*/
ngDoCheck() {
if (!this._differ) {
return;
}
/** @type {?} */
const changes = this._differ.diff(this._options);
if (changes) {
changes.forEachChangedItem((/**
* @param {?} option
* @return {?}
*/
(option) => this.setOptionIfChanged(option.key, option.currentValue)));
changes.forEachAddedItem((/**
* @param {?} option
* @return {?}
*/
(option) => this.setOptionIfChanged(option.key, option.currentValue)));
changes.forEachRemovedItem((/**
* @param {?} option
* @return {?}
*/
(option) => this.setOptionIfChanged(option.key, option.currentValue)));
}
}
/**
* @return {?}
*/
ngOnDestroy() {
if (this.codeMirror) {
this.codeMirror.toTextArea();
}
}
/**
* @param {?} cm
* @param {?} change
* @return {?}
*/
codemirrorValueChanged(cm, change) {
//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 {?}
*/
() => {
this.getValue();
}), 0);
// }
}
/**
* @param {?} optionName
* @param {?} newValue
* @return {?}
*/
setOptionIfChanged(optionName, newValue) {
if (!this.codeMirror) {
return;
}
this.codeMirror.setOption((/** @type {?} */ (optionName)), newValue);
}
/**
* @param {?} focused
* @return {?}
*/
focusChanged(focused) {
this.onTouched();
this.isFocused = focused;
// CodeMirror.fomulaContext = this._fomulaContext;
this.focusChange.emit(focused);
}
/**
* @param {?} cm
* @return {?}
*/
scrollChanged(cm) {
this.scroll.emit(cm.getScrollInfo());
}
/**
* @param {?} cm
* @return {?}
*/
cursorActive(cm) {
this.cursorActivity.emit(cm);
}
/**
* @param {?} cm
* @param {?} e
* @return {?}
*/
dropFiles(cm, e) {
this.drop.emit([cm, e]);
}
/**
* @param {?} value
* @return {?}
*/
writeValue(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 {?}
*/
registerOnChange(fn) {
this.onChange = fn;
}
/**
* @param {?} fn
* @return {?}
*/
registerOnTouched(fn) {
this.onTouched = fn;
}
/**
* @param {?} isDisabled
* @return {?}
*/
setDisabledState(isDisabled) {
this.disabled = isDisabled;
this.setOptionIfChanged("readOnly", this.disabled);
}
/**
* 函数鼠标滑动时事件
* @param {?} e
* @return {?}
*/
usageMouseover(e) {
this.usageDescription = `
<div class="formula-title">${e.name}</div>
<ul class="intro-wrapper">
<li class="intro">
${e.intro}
</li>
<li class="usage">
用法:${e.usage}
</li>
<li class="example">示例:${e.example}</li>
</ul>
`;
}
/**
* 插入函数
* @param {?} e
* @return {?}
*/
insertUsageFun(e) {
if (this.codeMirror && this.codeMirror !== null) {
/** @type {?} */
let c = this.codeMirror.getCursor();
this.codeMirror.replaceSelection(`${e.name}`);
/** @type {?} */
let d = this.codeMirror.getCursor();
this.insertBarcket();
this.getValue();
}
}
/**
* 插入可用变量
* @param {?} event
* @return {?}
*/
insertField(event) {
if (this.codeMirror && this.codeMirror !== null) {
/** @type {?} */
let c = this.codeMirror.getCursor();
this.codeMirror.replaceSelection("" + event.label + "");
/** @type {?} */
let d = this.codeMirror.getCursor();
/** @type {?} */
let 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
/**
* @return {?}
*/
copy() {
if (!!`${this.value}`) {
// this.clipboardService.copyFromContent(text);
// ↵
/** @type {?} */
let value = ((/** @type {?} */ (_.cloneDeep(this.value)))).replace("↵", "");
localStorage.setItem("codemirror", value);
this.message.success(`复制成功`);
}
else {
this.message.warning(`公式为空,请配置公式后复制`);
}
}
/**
* @return {?}
*/
paste() {
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(`粘贴成功`);
}
else {
this.message.warning(`没有需要粘贴的数据,请先复制`);
}
// 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 {?}
*/
markField(e) {
if (this.codeMirror && this.codeMirror !== null) {
/** @type {?} */
let 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 {?} */
let d = this.codeMirror.getCursor();
}
}
/**
* @private
* @return {?}
*/
insertBarcket() {
if (this.codeMirror && this.codeMirror !== null) {
/** @type {?} */
let c = this.codeMirror.getCursor();
this.codeMirror.replaceSelection("(");
/** @type {?} */
let d = this.codeMirror.getCursor();
/** @type {?} */
let c1 = this.codeMirror.getCursor();
this.codeMirror.replaceSelection(")");
/** @type {?} */
let d1 = this.codeMirror.getCursor();
this.codeMirror.setCursor(d);
this.codeMirror.focus();
}
}
/**
* @private
* @return {?}
*/
getValue() {
/** @type {?} */
let result = [];
/** @type {?} */
let codeContent = this.el.nativeElement.querySelectorAll(".CodeMirror-line");
this.fml.Utils.forEach(codeContent, (/**
* @param {?} t
* @param {?} e
* @return {?}
*/
(t, e) => {
this.fml.Utils.forEach(e.children, (/**
* @param {?} t1
* @param {?} e1
* @return {?}
*/
(t1, e1) => {
this.fml.Utils.forEach(e1.children, (/**
* @param {?} t2
* @param {?} e2
* @return {?}
*/
(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 {?}
*/
(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 {?}
*/
fakeLabel(t) {
return t ? t.replace(/[\[\]()'"]/g, " ") : "";
}
/**
* @private
* @return {?}
*/
setValue() {
if (this.value === undefined || this.value === null || this.value === "") {
return;
}
/** @type {?} */
let e = [];
/** @type {?} */
let p = [];
/** @type {?} */
let t = this.value.split("\n");
this.fml.Utils.forEach(t, (/**
* @param {?} c
* @param {?} t1
* @return {?}
*/
(c, t1) => {
/** @type {?} */
let d = "";
/** @type {?} */
let t = t1.split(new RegExp(this.fml.FormulaEditor.COMMON_REG.FORM_FORMULA, "g"));
this.fml.Utils.forEach(t, (/**
* @param {?} t
* @param {?} e
* @return {?}
*/
(t, e) => {
/** @type {?} */
let i;
/** @type {?} */
let a;
/** @type {?} */
let n;
/** @type {?} */
let s;
/** @type {?} */
let o;
/** @type {?} */
let r;
/** @type {?} */
let 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 {?}
*/
(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 {?}
*/
() => DeonCodemirror)),
multi: true,
},
],
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush
}] }
];
/** @nocollapse */
DeonCodemirror.ctorParameters = () => [
{ 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 },] }]
};
if (false) {
/** @type {?} */
DeonCodemirror.prototype.itemTitle;
/**
* 黑名单 值为函数名数组
* @type {?}
*/
DeonCodemirror.prototype.blacklist;
/** @type {?} */
DeonCodemirror.prototype.fml;
/** @type {?} */
DeonCodemirror.prototype.name;
/** @type {?} */
DeonCodemirror.prototype.title;
/** @type {?} */
DeonCodemirror.prototype.autoFocus;
/**
* 函数显示类型
* 班次 attendance 所有 // attendance-items 精度 进位规则
*
* 与categorys互斥,有type时使用type
* @type {?}
*/
DeonCodemirror.prototype.type;
/**
* 显示的函数组
* 与type 互斥,如果type有值,当前参数无效。
* @type {?}
*/
DeonCodemirror.prototype.categorys;
/** @type {?} */
DeonCodemirror.prototype.typeList;
/** @type {?} */
DeonCodemirror.prototype.preserveScrollPosition;
/** @type {?} */
DeonCodemirror.prototype.labelMap;
/** @type {?} */
DeonCodemirror.prototype._fieldData;
/** @type {?} */
DeonCodemirror.prototype.cursorActivity;
/** @type {?} */
DeonCodemirror.prototype.focusChange;
/** @type {?} */
DeonCodemirror.prototype.scroll;
/** @type {?} */
DeonCodemirror.prototype.drop;
/** @type {?} */
DeonCodemirror.prototype.textChange;
/** @type {?} */
DeonCodemirror.prototype.ref;
/** @type {?} */
DeonCodemirror.prototype.value;
/** @type {?} */
DeonCodemirror.prototype.disabled;
/** @type {?} */
DeonCodemirror.prototype.isFocused;
/** @type {?} */
DeonCodemirror.prototype.codeMirror;
/**
* 存放匹配的变量集合
* @type {?}
*/
DeonCodemirror.prototype.variableSearchList;
/**
* 存放匹配的函数集合
* @type {?}
*/
DeonCodemirror.prototype.usageFunSearchList;
/** @type {?} */
DeonCodemirror.prototype.FormulaUsage;
/**
* 查询可用变量
* @type {?}
*/
DeonCodemirror.prototype._variableSearch;
/**
* 查询可用函数
* @type {?}
*/
DeonCodemirror.prototype._usageFunSearch;
/**
* 函数描述
* @type {?}
*/
DeonCodemirror.prototype.usageDescription;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype._codeMirror;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype._differ;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype._options;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype._fomulaContext;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype.onChange;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype.onTouched;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype._differs;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype._ngZone;
/** @type {?} */
DeonCodemirror.prototype.el;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype.message;
/**
* @type {?}
* @private
*/
DeonCodemirror.prototype.nzConfigService;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6Im5nOi8vQGtyZS1mb3JtL2FiYy8iLCJzb3VyY2VzIjpbImxpYi9jb2RlbWlycm9yL2luZGV4LmNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsT0FBTyxFQUVMLHVCQUF1QixFQUN2QixTQUFTLEVBRVQsVUFBVSxFQUNWLFlBQVksRUFDWixVQUFVLEVBQ1YsS0FBSyxFQUVMLGVBQWUsRUFDZixNQUFNLEVBR04sTUFBTSxFQUNOLFNBQVMsR0FDVixNQUFNLGVBQWUsQ0FBQztBQUN2QixPQUFPLEVBQXdCLGlCQUFpQixFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFekUsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBQzNDLE9BQU8sRUFDTCxjQUFjLEVBQ2QsY0FBYyxFQUNkLG1CQUFtQixHQUNwQixNQUFNLGlCQUFpQixDQUFDO0FBQ3pCLE9BQU8sS0FBSyxDQUFDLE1BQU0sUUFBUSxDQUFDO0FBQzVCLE9BQU8sRUFBRSxlQUFlLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUNyRCxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUN6RCxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sUUFBUSxDQUFDOztNQUMzQixVQUFVLEdBQUcsT0FBTyxDQUFDLDJCQUEyQixDQUFDOzs7Ozs7QUFNdkQsU0FBUyxvQkFBb0IsQ0FBQyxHQUFXO0lBQ3ZDLElBQUksQ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