@worm-print-platform/plugin-kit 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/chunk-JABNJAZR.js +62 -0
- package/dist/controls.cjs +425 -0
- package/dist/controls.d.cts +47 -0
- package/dist/controls.d.ts +47 -0
- package/dist/controls.js +349 -0
- package/dist/dom.cjs +90 -0
- package/dist/dom.d.cts +24 -0
- package/dist/dom.d.ts +24 -0
- package/dist/dom.js +14 -0
- package/dist/expression-editor.cjs +484 -0
- package/dist/expression-editor.d.cts +42 -0
- package/dist/expression-editor.d.ts +42 -0
- package/dist/expression-editor.js +411 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +17 -2
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/expression-editor.ts
|
|
21
|
+
var expression_editor_exports = {};
|
|
22
|
+
__export(expression_editor_exports, {
|
|
23
|
+
normalizeFieldDisplay: () => normalizeFieldDisplay,
|
|
24
|
+
renderExpressionEditor: () => renderExpressionEditor
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(expression_editor_exports);
|
|
27
|
+
var import_designer = require("@worm-print-platform/core/designer");
|
|
28
|
+
var import_core = require("@worm-print-platform/core");
|
|
29
|
+
|
|
30
|
+
// src/dom.ts
|
|
31
|
+
function h(tag, props = {}, children = []) {
|
|
32
|
+
return { tag, props, children };
|
|
33
|
+
}
|
|
34
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
35
|
+
var ENUM_BOOLEAN_ATTRS = /* @__PURE__ */ new Set(["draggable", "contenteditable", "spellcheck"]);
|
|
36
|
+
var PROPERTY_ONLY_BOOLS = /* @__PURE__ */ new Set(["indeterminate"]);
|
|
37
|
+
function isSvg(tag) {
|
|
38
|
+
return tag === "svg" || tag === "path" || tag === "circle" || tag === "rect" || tag === "line" || tag === "g";
|
|
39
|
+
}
|
|
40
|
+
function inSvgContext(parent) {
|
|
41
|
+
return parent instanceof Element && parent.namespaceURI === SVG_NS;
|
|
42
|
+
}
|
|
43
|
+
function render(node, parent) {
|
|
44
|
+
if (typeof node === "string") {
|
|
45
|
+
const t = document.createTextNode(node);
|
|
46
|
+
parent.appendChild(t);
|
|
47
|
+
return t;
|
|
48
|
+
}
|
|
49
|
+
if (node instanceof Node) {
|
|
50
|
+
parent.appendChild(node);
|
|
51
|
+
return node;
|
|
52
|
+
}
|
|
53
|
+
const { tag, props, children } = node;
|
|
54
|
+
const el = isSvg(tag) || inSvgContext(parent) ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
|
|
55
|
+
for (const [key, raw] of Object.entries(props)) {
|
|
56
|
+
if (raw === null || raw === void 0 || raw === false) continue;
|
|
57
|
+
if (key === "class") el.setAttribute("class", String(raw));
|
|
58
|
+
else if (key === "style") {
|
|
59
|
+
if (typeof raw === "string") el.style.cssText = raw;
|
|
60
|
+
else Object.assign(el.style, raw);
|
|
61
|
+
} else if (key === "html") el.innerHTML = String(raw);
|
|
62
|
+
else if (key === "text") el.textContent = String(raw);
|
|
63
|
+
else if (key.startsWith("on") && typeof raw === "function") {
|
|
64
|
+
el.addEventListener(key.slice(2).toLowerCase(), raw);
|
|
65
|
+
} else if (key === "dataset") {
|
|
66
|
+
for (const [dk, dv] of Object.entries(raw)) el.dataset[dk] = dv;
|
|
67
|
+
} else if (PROPERTY_ONLY_BOOLS.has(key)) {
|
|
68
|
+
el[key] = true;
|
|
69
|
+
} else if (typeof raw === "boolean") {
|
|
70
|
+
if (raw) el.setAttribute(key, ENUM_BOOLEAN_ATTRS.has(key) ? "true" : "");
|
|
71
|
+
} else el.setAttribute(key, String(raw));
|
|
72
|
+
}
|
|
73
|
+
for (const child of children) render(child, el);
|
|
74
|
+
parent.appendChild(el);
|
|
75
|
+
return el;
|
|
76
|
+
}
|
|
77
|
+
function clear(node) {
|
|
78
|
+
while (node.firstChild) node.removeChild(node.firstChild);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/expression-editor.ts
|
|
82
|
+
var ICON_PATHS = {
|
|
83
|
+
Check: '<path d="M20 6 9 17l-5-5" />',
|
|
84
|
+
Copy: '<rect width="14" height="14" x="8" y="8" rx="2" ry="2" /><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />'
|
|
85
|
+
};
|
|
86
|
+
function iconSvg(name, size = 16) {
|
|
87
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${ICON_PATHS[name] ?? ""}</svg>`;
|
|
88
|
+
}
|
|
89
|
+
function normalizeFieldDisplay(v) {
|
|
90
|
+
const s = typeof v === "string" ? v.trim().toLowerCase() : "";
|
|
91
|
+
return s === "label" || s === "key" || s === "both" ? s : "both";
|
|
92
|
+
}
|
|
93
|
+
var TABS = [
|
|
94
|
+
{ key: "field", text: "\u{1F4C1} \u5B57\u6BB5" },
|
|
95
|
+
{ key: "variable", text: "\u{1F527} \u53D8\u91CF" },
|
|
96
|
+
{ key: "function", text: "\u26A1 \u51FD\u6570" }
|
|
97
|
+
];
|
|
98
|
+
var PLACEHOLDER = {
|
|
99
|
+
field: "\u641C\u7D22\u5B57\u6BB5...",
|
|
100
|
+
variable: "\u641C\u7D22\u53D8\u91CF...",
|
|
101
|
+
function: "\u641C\u7D22\u51FD\u6570..."
|
|
102
|
+
};
|
|
103
|
+
var AGGREGATE_FUNCTIONS = [
|
|
104
|
+
{ name: "SUM", label: "\u6C42\u548C", template: "SUM()" },
|
|
105
|
+
{ name: "AVG", label: "\u5E73\u5747\u503C", template: "AVG()" },
|
|
106
|
+
{ name: "COUNT", label: "\u8BA1\u6570", template: "COUNT()" },
|
|
107
|
+
{ name: "MIN", label: "\u6700\u5C0F\u503C", template: "MIN()" },
|
|
108
|
+
{ name: "MAX", label: "\u6700\u5927\u503C", template: "MAX()" }
|
|
109
|
+
];
|
|
110
|
+
var MATH_FUNCTIONS = [
|
|
111
|
+
{ name: "ADD", label: "\u76F8\u52A0", template: "ADD()" },
|
|
112
|
+
{ name: "SUB", label: "\u76F8\u51CF", template: "SUB()" },
|
|
113
|
+
{ name: "MUL", label: "\u76F8\u4E58", template: "MUL()" },
|
|
114
|
+
{ name: "DIV", label: "\u76F8\u9664", template: "DIV()" },
|
|
115
|
+
{ name: "ROUND", label: "\u56DB\u820D\u4E94\u5165", template: "ROUND()" },
|
|
116
|
+
{ name: "ROUNDUP", label: "\u8FDB\u4E00\u6CD5", template: "ROUNDUP()" },
|
|
117
|
+
{ name: "ROUNDDOWN", label: "\u53BB\u5C3E\u6CD5", template: "ROUNDDOWN()" },
|
|
118
|
+
{ name: "ROUNDBANK", label: "\u56DB\u820D\u516D\u5165\u4E94\u6210\u53CC", template: "ROUNDBANK()" }
|
|
119
|
+
];
|
|
120
|
+
var FORMAT_FUNCTIONS = [
|
|
121
|
+
{ name: "MONEY", label: "\u91D1\u989D\u683C\u5F0F\u5316", template: "MONEY()" },
|
|
122
|
+
{ name: "DATE", label: "\u65E5\u671F\u683C\u5F0F\u5316", template: "DATE()" },
|
|
123
|
+
{ name: "UPPER", label: "\u5927\u5199\u91D1\u989D", template: "UPPER()" },
|
|
124
|
+
{ name: "IF", label: "\u6761\u4EF6\u5224\u65AD", template: "IF()" }
|
|
125
|
+
];
|
|
126
|
+
var SYSTEM_VARIABLES = [
|
|
127
|
+
{ name: "pageIndex", label: "\u5F53\u524D\u9875\u7801", template: "{pageIndex}" },
|
|
128
|
+
{ name: "totalPages", label: "\u603B\u9875\u6570", template: "{totalPages}" },
|
|
129
|
+
{ name: "printDate", label: "\u6253\u5370\u65E5\u671F", template: "{printDate}" },
|
|
130
|
+
{ name: "printTime", label: "\u6253\u5370\u65F6\u95F4", template: "{printTime}" }
|
|
131
|
+
];
|
|
132
|
+
var FUNC_GROUPS = [
|
|
133
|
+
{ title: "\u805A\u5408\u51FD\u6570", items: AGGREGATE_FUNCTIONS },
|
|
134
|
+
{ title: "\u6570\u503C\u8FD0\u7B97", items: MATH_FUNCTIONS },
|
|
135
|
+
{ title: "\u683C\u5F0F\u5316\u51FD\u6570", items: FORMAT_FUNCTIONS }
|
|
136
|
+
];
|
|
137
|
+
var EMPTY_PREVIEW = "\uFF08\u8F93\u5165\u8868\u8FBE\u5F0F\u540E\u9884\u89C8\uFF09";
|
|
138
|
+
var NO_VALUE_PREVIEW = "\uFF08\u65E0\u6CD5\u8BA1\u7B97\uFF09";
|
|
139
|
+
var ERROR_PREVIEW = "\uFF08\u8868\u8FBE\u5F0F\u9519\u8BEF\uFF09";
|
|
140
|
+
function previewText(expr, demoData) {
|
|
141
|
+
if (!expr.trim()) return EMPTY_PREVIEW;
|
|
142
|
+
try {
|
|
143
|
+
const ctx = { ...import_designer.DEFAULT_DEMO_DATA, ...demoData ?? {}, ...(0, import_core.resolveSystemVariables)() };
|
|
144
|
+
const result = (0, import_designer.evaluateTemplate)(expr, ctx);
|
|
145
|
+
if (result === void 0 || result === null) return NO_VALUE_PREVIEW;
|
|
146
|
+
return String(result);
|
|
147
|
+
} catch {
|
|
148
|
+
return ERROR_PREVIEW;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function matchKeyword(items, keyword) {
|
|
152
|
+
const kw = keyword.trim().toLowerCase();
|
|
153
|
+
if (!kw) return items;
|
|
154
|
+
return items.filter((it) => it.label.toLowerCase().includes(kw) || it.name.toLowerCase().includes(kw));
|
|
155
|
+
}
|
|
156
|
+
function cursorRegion(text, caret) {
|
|
157
|
+
const before = text.substring(0, caret);
|
|
158
|
+
const lastBlockOpen = before.lastIndexOf("{");
|
|
159
|
+
const insideBlock = lastBlockOpen !== -1 && !before.slice(lastBlockOpen + 1).includes("}");
|
|
160
|
+
const lastParenOpen = before.lastIndexOf("(");
|
|
161
|
+
const insideParens = lastParenOpen !== -1 && !before.slice(lastParenOpen + 1).includes(")");
|
|
162
|
+
return { insideBlock, insideParens };
|
|
163
|
+
}
|
|
164
|
+
var hasChineseKey = (key) => /[\u4e00-\u9fff]/.test(key);
|
|
165
|
+
var chineseKeyHint = (key) => `\u5B57\u6BB5\u300C${key}\u300D\u542B\u4E2D\u6587\uFF0C\u8BF7\u7528 {${key}} \u5F15\u7528\uFF08\u51FD\u6570\u53C2\u6570\u5185\u5199 ${key}\uFF09\uFF1B\u4E2D\u6587\u53EF\u76F4\u63A5\u5728 {} \u4E2D\u4F7F\u7528\uFF0C\u65E0\u9700 data['...'] \u65B9\u62EC\u53F7`;
|
|
166
|
+
function pureFieldBinding(expr, fields) {
|
|
167
|
+
const matched = /^\{\s*([^{}]+?)\s*\}$/.exec(expr.trim());
|
|
168
|
+
if (!matched) return null;
|
|
169
|
+
const key = matched[1] ?? "";
|
|
170
|
+
return fields.find((f) => f.fieldKey === key) ?? null;
|
|
171
|
+
}
|
|
172
|
+
function itemInfo(label, key, display = "both") {
|
|
173
|
+
if (display === "label") return h("div", { class: "ee-field-info" }, [
|
|
174
|
+
h("span", { class: "ee-item-label", text: label })
|
|
175
|
+
]);
|
|
176
|
+
if (display === "key") return h("div", { class: "ee-field-info" }, [
|
|
177
|
+
h("span", { class: "ee-item-key is-primary", text: key })
|
|
178
|
+
]);
|
|
179
|
+
return h("div", { class: "ee-field-info" }, [
|
|
180
|
+
h("span", { class: "ee-item-label", text: label }),
|
|
181
|
+
h("span", { class: "ee-item-key", text: key })
|
|
182
|
+
]);
|
|
183
|
+
}
|
|
184
|
+
function scope(ev) {
|
|
185
|
+
return ev.currentTarget.getRootNode();
|
|
186
|
+
}
|
|
187
|
+
function helpCard(modifier, title, lines) {
|
|
188
|
+
const content = [];
|
|
189
|
+
lines.forEach((line, i) => {
|
|
190
|
+
content.push(line);
|
|
191
|
+
if (i < lines.length - 1) content.push(h("br"));
|
|
192
|
+
});
|
|
193
|
+
return h("div", { class: `ee-help-card ${modifier}` }, [
|
|
194
|
+
h("div", { class: "ee-help-card-title", text: title }),
|
|
195
|
+
h("div", { class: "ee-help-card-content" }, content)
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
198
|
+
function helpSection() {
|
|
199
|
+
return h("div", { class: "ee-help-section" }, [
|
|
200
|
+
h("div", { class: "ee-help-title", text: "\u5E2E\u52A9\u4FE1\u606F" }),
|
|
201
|
+
h("div", { class: "ee-help-grid" }, [
|
|
202
|
+
helpCard("ee-help-field", "\u8F93\u5165\u65B9\u5F0F", [
|
|
203
|
+
"\u53CC\u51FB\u5DE6\u4FA7\u5B57\u6BB5\u3001\u53D8\u91CF\u3001\u51FD\u6570\u5373\u53EF\u63D2\u5165\u5230\u8868\u8FBE\u5F0F\u8F93\u5165\u6846\u4E2D",
|
|
204
|
+
"\u53CC\u51FB\u9014\u4E2D\u6309\u4F4F Ctrl\uFF08Mac \u4E3A \u2318\uFF09\u5207\u6362\u4E3A\u63D2\u5165\u5B57\u6BB5\u540D\u79F0\uFF0C\u5F53\u9759\u6001\u6587\u672C\u7528",
|
|
205
|
+
"\u9759\u6001\u6570\u636E\u76F4\u63A5\u8F93\u5165\u5373\u53EF\uFF0C\u5982\uFF1A\u4F9B\u5E94\u5546\u540D\u79F0",
|
|
206
|
+
"\u52A8\u6001\u89E3\u6790\u5B57\u6BB5\u3001\u53D8\u91CF\u3001\u51FD\u6570\u5FC5\u987B\u7528 {} \u5305\u88F9",
|
|
207
|
+
"\u793A\u4F8B\uFF1A{SUM(supplier.name)}",
|
|
208
|
+
"\u4E2D\u6587 key \u76F4\u63A5\u5199 {\u5B57\u6BB5\u540D}\uFF0C\u5982 {\u59D3\u540D}\u3001{supplier.\u540D\u79F0}",
|
|
209
|
+
"\u6CE8\u610F\uFF1A\u53EA\u80FD\u5D4C\u5957\u4E00\u5C42"
|
|
210
|
+
]),
|
|
211
|
+
helpCard("ee-help-function", "\u51FD\u6570\u4F7F\u7528", [
|
|
212
|
+
"SUM(\u5B57\u6BB5) - \u6C42\u548C",
|
|
213
|
+
"AVG(\u5B57\u6BB5) - \u5E73\u5747\u503C",
|
|
214
|
+
"COUNT(\u5B57\u6BB5) - \u8BA1\u6570",
|
|
215
|
+
"IF(\u6761\u4EF6, \u771F\u503C, \u5047\u503C) - \u6761\u4EF6\u5224\u65AD",
|
|
216
|
+
"\u56DB\u5219\u8FD0\u7B97\uFF1A{qty * price}\u3001{ADD(qty, 1)}",
|
|
217
|
+
"\u4FEE\u7EA6\uFF1AROUND \u56DB\u820D\u4E94\u5165 / ROUNDUP \u8FDB\u4E00 / ROUNDDOWN \u53BB\u5C3E / ROUNDBANK \u56DB\u820D\u516D\u5165\u4E94\u6210\u53CC"
|
|
218
|
+
]),
|
|
219
|
+
helpCard("ee-help-variable", "\u7CFB\u7EDF\u53D8\u91CF", [
|
|
220
|
+
"{pageIndex} - \u5F53\u524D\u9875\u7801",
|
|
221
|
+
"{totalPages} - \u603B\u9875\u6570",
|
|
222
|
+
"{printDate} - \u6253\u5370\u65E5\u671F"
|
|
223
|
+
]),
|
|
224
|
+
helpCard("ee-help-conditional", "\u793A\u4F8B", [
|
|
225
|
+
"\u9759\u6001\u6587\u672C\uFF1A\u4F9B\u5E94\u5546\u540D\u79F0",
|
|
226
|
+
"\u52A8\u6001\u5B57\u6BB5\uFF1A{supplier.name}",
|
|
227
|
+
"\u51FD\u6570\u8C03\u7528\uFF1A{SUM(amount)}",
|
|
228
|
+
'\u6761\u4EF6\u5224\u65AD\uFF1A{IF(amount>1000, "\u5927\u5355", "\u5C0F\u5355")}',
|
|
229
|
+
"\u8FD0\u7B97\u5E76\u4FEE\u7EA6\uFF1A{ROUND(qty * price, 2)}"
|
|
230
|
+
])
|
|
231
|
+
])
|
|
232
|
+
]);
|
|
233
|
+
}
|
|
234
|
+
function renderExpressionEditor(opts, target) {
|
|
235
|
+
const fieldDisplay = normalizeFieldDisplay(opts.fieldDisplay);
|
|
236
|
+
const state = {
|
|
237
|
+
activeTab: "field",
|
|
238
|
+
searchText: "",
|
|
239
|
+
expression: target.value || "",
|
|
240
|
+
/** 字段绑定模式标记:仅当调用方给了初始 key,才在确定时回写 binding/title */
|
|
241
|
+
binding: target.binding,
|
|
242
|
+
/** 最近一次复制成功的字段 key:按钮图标 1.2s 内显示对勾(对齐 Vue 3 轨的 copiedKey) */
|
|
243
|
+
copiedFieldKey: "",
|
|
244
|
+
/** 双击插入中文 key 后的格式提示;插入英文字段/手动编辑时清空 */
|
|
245
|
+
keyHint: ""
|
|
246
|
+
};
|
|
247
|
+
const query = (root, selector) => root.querySelector(selector);
|
|
248
|
+
const updatePreview = (root) => {
|
|
249
|
+
const el = query(root, ".ee-preview");
|
|
250
|
+
if (!el) return;
|
|
251
|
+
const text = previewText(state.expression, opts.demoData);
|
|
252
|
+
el.textContent = text;
|
|
253
|
+
el.classList.toggle("ee-preview-error", text === ERROR_PREVIEW);
|
|
254
|
+
};
|
|
255
|
+
const updateKeyHint = (root) => {
|
|
256
|
+
const el = query(root, ".ee-key-hint");
|
|
257
|
+
if (!el) return;
|
|
258
|
+
el.textContent = state.keyHint;
|
|
259
|
+
el.style.display = state.keyHint ? "" : "none";
|
|
260
|
+
};
|
|
261
|
+
const listItems = () => {
|
|
262
|
+
if (state.activeTab === "variable") {
|
|
263
|
+
return matchKeyword(SYSTEM_VARIABLES, state.searchText).map((sv) => h("div", {
|
|
264
|
+
class: "ee-list-item",
|
|
265
|
+
onDblclick: (ev) => {
|
|
266
|
+
const { insideParens } = region(ev);
|
|
267
|
+
insert(scope(ev), insideParens ? sv.template.replace(/^\{|\}$/g, "") : sv.template, void 0, "");
|
|
268
|
+
}
|
|
269
|
+
}, [itemInfo(sv.label, sv.template)]));
|
|
270
|
+
}
|
|
271
|
+
if (state.activeTab === "function") {
|
|
272
|
+
return FUNC_GROUPS.map((group) => h("div", { class: "ee-func-group" }, [
|
|
273
|
+
h("div", { class: "ee-func-group-title", text: group.title }),
|
|
274
|
+
...matchKeyword(group.items, state.searchText).map((fn) => h("div", {
|
|
275
|
+
class: "ee-list-item",
|
|
276
|
+
onDblclick: (ev) => {
|
|
277
|
+
const { insideBlock } = region(ev);
|
|
278
|
+
const text = insideBlock ? fn.template : `{${fn.template}}`;
|
|
279
|
+
insert(scope(ev), text, text.indexOf("(") + 1, "");
|
|
280
|
+
}
|
|
281
|
+
}, [itemInfo(fn.label, `${fn.name}()`)]))
|
|
282
|
+
]));
|
|
283
|
+
}
|
|
284
|
+
const groups = (0, import_designer.filterGroups)((0, import_designer.groupFields)(opts.fields ?? []), state.searchText);
|
|
285
|
+
if (!groups.length) return [h("p", { class: "pd-empty", text: "\u6682\u65E0\u5B57\u6BB5" })];
|
|
286
|
+
const nodes = [];
|
|
287
|
+
for (const group of groups) {
|
|
288
|
+
if (group.key) {
|
|
289
|
+
nodes.push(h("div", { class: `ee-field-group${group.isList ? " is-list" : ""}` }, [
|
|
290
|
+
h("span", { class: "ee-field-group-icon", text: group.isList ? "\u{1F4CB}" : "\u{1F4C1}" }),
|
|
291
|
+
h("span", { text: group.label })
|
|
292
|
+
]));
|
|
293
|
+
}
|
|
294
|
+
for (const field of group.fields) {
|
|
295
|
+
nodes.push(h("div", {
|
|
296
|
+
class: "ee-list-item ee-field-item",
|
|
297
|
+
style: { paddingLeft: group.key ? "22px" : "10px" },
|
|
298
|
+
onDblclick: (ev) => {
|
|
299
|
+
const { insideParens } = region(ev);
|
|
300
|
+
const mod = ev;
|
|
301
|
+
if (mod.ctrlKey || mod.metaKey) {
|
|
302
|
+
const name = field.fieldLabel || field.fieldKey;
|
|
303
|
+
insert(scope(ev), insideParens ? `"${name}"` : name, void 0, "");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
insert(
|
|
307
|
+
scope(ev),
|
|
308
|
+
insideParens ? field.fieldKey : `{${field.fieldKey}}`,
|
|
309
|
+
void 0,
|
|
310
|
+
hasChineseKey(field.fieldKey) ? chineseKeyHint(field.fieldKey) : ""
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
}, [
|
|
314
|
+
itemInfo(field.fieldLabel || field.fieldKey, field.fieldKey, fieldDisplay),
|
|
315
|
+
// 字段右侧复制按钮:复制字段中文名(对齐 canvas ExpressionEditor 的 .ee-copy-btn)
|
|
316
|
+
h("button", {
|
|
317
|
+
type: "button",
|
|
318
|
+
class: `ee-copy-btn${state.copiedFieldKey === field.fieldKey ? " is-copied" : ""}`,
|
|
319
|
+
// 提示浮层由 print-designer 的 hover-tip 委托承担(容器白名单含 .pd-dialog-overlay)
|
|
320
|
+
"data-tip": state.copiedFieldKey === field.fieldKey ? "\u5DF2\u590D\u5236" : `\u590D\u5236\u5B57\u6BB5\u540D\u300C${field.fieldLabel}\u300D`,
|
|
321
|
+
"aria-label": `\u590D\u5236\u5B57\u6BB5\u540D ${field.fieldLabel}`,
|
|
322
|
+
html: iconSvg(state.copiedFieldKey === field.fieldKey ? "Check" : "Copy", 13),
|
|
323
|
+
onClick: (ev) => {
|
|
324
|
+
ev.stopPropagation();
|
|
325
|
+
copyFieldName(ev, field);
|
|
326
|
+
},
|
|
327
|
+
onDblclick: (ev) => ev.stopPropagation()
|
|
328
|
+
})
|
|
329
|
+
]));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return nodes;
|
|
333
|
+
};
|
|
334
|
+
const repaint = (root) => {
|
|
335
|
+
const tabs = Array.from(root.querySelectorAll(".ee-nav-tab"));
|
|
336
|
+
tabs.forEach((el, i) => el.classList.toggle("active", TABS[i]?.key === state.activeTab));
|
|
337
|
+
const search = query(root, ".ee-content-search .pd-input");
|
|
338
|
+
if (search) {
|
|
339
|
+
const placeholder = PLACEHOLDER[state.activeTab];
|
|
340
|
+
if (search.placeholder !== placeholder) search.placeholder = placeholder;
|
|
341
|
+
if (search.value !== state.searchText) search.value = state.searchText;
|
|
342
|
+
}
|
|
343
|
+
const ta = query(root, ".ee-textarea");
|
|
344
|
+
if (ta && ta.value !== state.expression) ta.value = state.expression;
|
|
345
|
+
const list = query(root, ".ee-content-list");
|
|
346
|
+
if (list) {
|
|
347
|
+
clear(list);
|
|
348
|
+
for (const item of listItems()) render(item, list);
|
|
349
|
+
}
|
|
350
|
+
updatePreview(root);
|
|
351
|
+
updateKeyHint(root);
|
|
352
|
+
};
|
|
353
|
+
function copyFieldName(ev, field) {
|
|
354
|
+
const root = scope(ev);
|
|
355
|
+
(0, import_designer.copyTextToClipboard)(field.fieldLabel || field.fieldKey).then((ok) => {
|
|
356
|
+
if (!ok) return;
|
|
357
|
+
state.copiedFieldKey = field.fieldKey;
|
|
358
|
+
repaint(root);
|
|
359
|
+
setTimeout(() => {
|
|
360
|
+
if (state.copiedFieldKey !== field.fieldKey) return;
|
|
361
|
+
state.copiedFieldKey = "";
|
|
362
|
+
repaint(root);
|
|
363
|
+
}, 1200);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
const region = (ev) => {
|
|
367
|
+
const ta = query(scope(ev), ".ee-textarea");
|
|
368
|
+
const caret = ta?.selectionStart ?? state.expression.length;
|
|
369
|
+
return cursorRegion(state.expression, caret);
|
|
370
|
+
};
|
|
371
|
+
const insert = (root, text, caretOffset = text.length, keyHint) => {
|
|
372
|
+
if (keyHint !== void 0) state.keyHint = keyHint;
|
|
373
|
+
const ta = query(root, ".ee-textarea");
|
|
374
|
+
if (!ta) {
|
|
375
|
+
state.expression += text;
|
|
376
|
+
updatePreview(root);
|
|
377
|
+
updateKeyHint(root);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const start = ta.selectionStart ?? state.expression.length;
|
|
381
|
+
const end = ta.selectionEnd ?? start;
|
|
382
|
+
state.expression = state.expression.substring(0, start) + text + state.expression.substring(end);
|
|
383
|
+
const caret = start + caretOffset;
|
|
384
|
+
ta.value = state.expression;
|
|
385
|
+
ta.focus();
|
|
386
|
+
ta.selectionStart = ta.selectionEnd = caret;
|
|
387
|
+
updatePreview(root);
|
|
388
|
+
updateKeyHint(root);
|
|
389
|
+
};
|
|
390
|
+
const onConfirm = () => {
|
|
391
|
+
const formatter = state.expression;
|
|
392
|
+
if (state.binding === void 0) {
|
|
393
|
+
opts.onApply({ formatter });
|
|
394
|
+
opts.onClose();
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const field = pureFieldBinding(formatter, opts.fields ?? []);
|
|
398
|
+
opts.onApply(field ? { formatter, binding: field.fieldKey, title: field.fieldLabel } : { formatter });
|
|
399
|
+
opts.onClose();
|
|
400
|
+
};
|
|
401
|
+
const nav = h("div", { class: "ee-nav" }, [
|
|
402
|
+
h("div", { class: "ee-nav-title", text: "\u7C7B\u578B" }),
|
|
403
|
+
h("div", { class: "ee-nav-tabs" }, TABS.map((tab, i) => h("div", {
|
|
404
|
+
class: `ee-nav-tab${state.activeTab === tab.key ? " active" : ""}`,
|
|
405
|
+
text: tab.text,
|
|
406
|
+
onClick: (ev) => {
|
|
407
|
+
state.activeTab = TABS[i].key;
|
|
408
|
+
repaint(scope(ev));
|
|
409
|
+
}
|
|
410
|
+
})))
|
|
411
|
+
]);
|
|
412
|
+
const content = h("div", { class: "ee-content" }, [
|
|
413
|
+
h("div", { class: "ee-content-search" }, [
|
|
414
|
+
h("input", {
|
|
415
|
+
class: "pd-input",
|
|
416
|
+
placeholder: PLACEHOLDER[state.activeTab],
|
|
417
|
+
onInput: (ev) => {
|
|
418
|
+
state.searchText = ev.target.value;
|
|
419
|
+
repaint(scope(ev));
|
|
420
|
+
}
|
|
421
|
+
})
|
|
422
|
+
]),
|
|
423
|
+
h("div", { class: "ee-content-list" }, listItems())
|
|
424
|
+
]);
|
|
425
|
+
const initialPreview = previewText(state.expression, opts.demoData);
|
|
426
|
+
const editor = h("div", { class: "ee-editor" }, [
|
|
427
|
+
h("div", { class: "ee-editor-section" }, [
|
|
428
|
+
h("div", { class: "ee-editor-title", text: "\u8868\u8FBE\u5F0F\u7F16\u8F91" }),
|
|
429
|
+
h("textarea", {
|
|
430
|
+
class: "ee-textarea",
|
|
431
|
+
rows: 6,
|
|
432
|
+
placeholder: "\u53CC\u51FB\u5DE6\u4FA7\u5B57\u6BB5/\u53D8\u91CF/\u51FD\u6570\u63D2\u5165\uFF0C\u53CC\u51FB\u9014\u4E2D\u6309\u4F4F Ctrl\uFF08Mac \u4E3A \u2318\uFF09\u5207\u6362\u4E3A\u63D2\u5165\u5B57\u6BB5\u540D\uFF0C\u6216\u76F4\u63A5\u8F93\u5165\u9759\u6001\u5185\u5BB9",
|
|
433
|
+
text: state.expression,
|
|
434
|
+
onInput: (ev) => {
|
|
435
|
+
state.expression = ev.target.value;
|
|
436
|
+
state.keyHint = "";
|
|
437
|
+
updatePreview(scope(ev));
|
|
438
|
+
updateKeyHint(scope(ev));
|
|
439
|
+
}
|
|
440
|
+
}),
|
|
441
|
+
h("div", {
|
|
442
|
+
class: "pd-hint ee-key-hint",
|
|
443
|
+
style: { display: "none", color: "var(--pd-accent, #165DFF)" },
|
|
444
|
+
text: ""
|
|
445
|
+
})
|
|
446
|
+
]),
|
|
447
|
+
h("div", { class: "ee-editor-section" }, [
|
|
448
|
+
h("div", { class: "ee-editor-title", text: "\u9884\u89C8\u7ED3\u679C" }),
|
|
449
|
+
h("div", {
|
|
450
|
+
class: `ee-preview${initialPreview === ERROR_PREVIEW ? " ee-preview-error" : ""}`,
|
|
451
|
+
text: initialPreview
|
|
452
|
+
})
|
|
453
|
+
]),
|
|
454
|
+
helpSection()
|
|
455
|
+
]);
|
|
456
|
+
return h("div", {
|
|
457
|
+
class: "pd-dialog-overlay",
|
|
458
|
+
onKeydown: (ev) => {
|
|
459
|
+
if (ev.key === "Escape") opts.onClose();
|
|
460
|
+
}
|
|
461
|
+
}, [
|
|
462
|
+
h("section", {
|
|
463
|
+
class: "pd-dialog pd-dialog-large",
|
|
464
|
+
role: "dialog",
|
|
465
|
+
"aria-modal": "true",
|
|
466
|
+
"aria-labelledby": "expression-editor-title"
|
|
467
|
+
}, [
|
|
468
|
+
h("header", { class: "pd-dialog-header" }, [
|
|
469
|
+
h("strong", { id: "expression-editor-title", text: "\u7F16\u8F91\u8868\u8FBE\u5F0F" }),
|
|
470
|
+
h("button", { type: "button", class: "pd-close", "aria-label": "\u5173\u95ED", text: "\xD7", onClick: () => opts.onClose() })
|
|
471
|
+
]),
|
|
472
|
+
h("div", { class: "expression-editor" }, [nav, content, editor]),
|
|
473
|
+
h("footer", { class: "pd-dialog-footer" }, [
|
|
474
|
+
h("button", { type: "button", class: "pd-button", text: "\u53D6\u6D88", onClick: () => opts.onClose() }),
|
|
475
|
+
h("button", { type: "button", class: "pd-button primary", text: "\u786E\u5B9A", onClick: () => onConfirm() })
|
|
476
|
+
])
|
|
477
|
+
])
|
|
478
|
+
]);
|
|
479
|
+
}
|
|
480
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
481
|
+
0 && (module.exports = {
|
|
482
|
+
normalizeFieldDisplay,
|
|
483
|
+
renderExpressionEditor
|
|
484
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @worm-print-platform/plugin-kit v1.6.0
|
|
3
|
+
* Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
|
|
4
|
+
* SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/
|
|
7
|
+
import { PrintBusinessField } from '@worm-print-platform/core/designer';
|
|
8
|
+
import { El } from './dom.cjs';
|
|
9
|
+
|
|
10
|
+
interface ExpressionEditorTarget {
|
|
11
|
+
/** 元素 id(表格单元格时用于定位) */
|
|
12
|
+
elementId: string;
|
|
13
|
+
/** 要写回的目标路径,如 'options.formatter' 或 'cell:<rowId>:<colIndex>' */
|
|
14
|
+
targetPath: string;
|
|
15
|
+
/** 当前表达式文本 */
|
|
16
|
+
value: string;
|
|
17
|
+
/** 可选:字段绑定模式的初始字段 key */
|
|
18
|
+
binding?: string;
|
|
19
|
+
}
|
|
20
|
+
/** 字段行显示模式:中文名 / key / 两者(默认 both,保持既有行为) */
|
|
21
|
+
type FieldDisplayMode = 'label' | 'key' | 'both';
|
|
22
|
+
/** 归一化宿主传入的显示模式:trim + 小写;非法值静默回退 both */
|
|
23
|
+
declare function normalizeFieldDisplay(v: unknown): FieldDisplayMode;
|
|
24
|
+
interface ExpressionEditorOptions {
|
|
25
|
+
fields: PrintBusinessField[];
|
|
26
|
+
/** 求值预览用的样例行数据 */
|
|
27
|
+
demoData?: Record<string, any>;
|
|
28
|
+
/** 字段行显示模式;缺省 / 非法值按 both(中文名 + key) */
|
|
29
|
+
fieldDisplay?: FieldDisplayMode;
|
|
30
|
+
/** 关闭弹窗 */
|
|
31
|
+
onClose: () => void;
|
|
32
|
+
/** 点确定:把最终表达式回写 */
|
|
33
|
+
onApply: (next: {
|
|
34
|
+
formatter?: string;
|
|
35
|
+
binding?: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
}) => void;
|
|
38
|
+
}
|
|
39
|
+
/** 渲染表达式编辑器弹窗的 DOM 描述(内部已含遮罩层,render 进 shadow 根下即可) */
|
|
40
|
+
declare function renderExpressionEditor(opts: ExpressionEditorOptions, target: ExpressionEditorTarget): El;
|
|
41
|
+
|
|
42
|
+
export { type ExpressionEditorOptions, type ExpressionEditorTarget, type FieldDisplayMode, normalizeFieldDisplay, renderExpressionEditor };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @worm-print-platform/plugin-kit v1.6.0
|
|
3
|
+
* Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
|
|
4
|
+
* SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/
|
|
7
|
+
import { PrintBusinessField } from '@worm-print-platform/core/designer';
|
|
8
|
+
import { El } from './dom.js';
|
|
9
|
+
|
|
10
|
+
interface ExpressionEditorTarget {
|
|
11
|
+
/** 元素 id(表格单元格时用于定位) */
|
|
12
|
+
elementId: string;
|
|
13
|
+
/** 要写回的目标路径,如 'options.formatter' 或 'cell:<rowId>:<colIndex>' */
|
|
14
|
+
targetPath: string;
|
|
15
|
+
/** 当前表达式文本 */
|
|
16
|
+
value: string;
|
|
17
|
+
/** 可选:字段绑定模式的初始字段 key */
|
|
18
|
+
binding?: string;
|
|
19
|
+
}
|
|
20
|
+
/** 字段行显示模式:中文名 / key / 两者(默认 both,保持既有行为) */
|
|
21
|
+
type FieldDisplayMode = 'label' | 'key' | 'both';
|
|
22
|
+
/** 归一化宿主传入的显示模式:trim + 小写;非法值静默回退 both */
|
|
23
|
+
declare function normalizeFieldDisplay(v: unknown): FieldDisplayMode;
|
|
24
|
+
interface ExpressionEditorOptions {
|
|
25
|
+
fields: PrintBusinessField[];
|
|
26
|
+
/** 求值预览用的样例行数据 */
|
|
27
|
+
demoData?: Record<string, any>;
|
|
28
|
+
/** 字段行显示模式;缺省 / 非法值按 both(中文名 + key) */
|
|
29
|
+
fieldDisplay?: FieldDisplayMode;
|
|
30
|
+
/** 关闭弹窗 */
|
|
31
|
+
onClose: () => void;
|
|
32
|
+
/** 点确定:把最终表达式回写 */
|
|
33
|
+
onApply: (next: {
|
|
34
|
+
formatter?: string;
|
|
35
|
+
binding?: string;
|
|
36
|
+
title?: string;
|
|
37
|
+
}) => void;
|
|
38
|
+
}
|
|
39
|
+
/** 渲染表达式编辑器弹窗的 DOM 描述(内部已含遮罩层,render 进 shadow 根下即可) */
|
|
40
|
+
declare function renderExpressionEditor(opts: ExpressionEditorOptions, target: ExpressionEditorTarget): El;
|
|
41
|
+
|
|
42
|
+
export { type ExpressionEditorOptions, type ExpressionEditorTarget, type FieldDisplayMode, normalizeFieldDisplay, renderExpressionEditor };
|