@worm-print-platform/plugin-kit 1.5.3 → 1.6.1

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.
@@ -0,0 +1,501 @@
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_i18n = require("@worm-print-platform/core/i18n");
29
+ var import_core = require("@worm-print-platform/core");
30
+
31
+ // src/dom.ts
32
+ function h(tag, props = {}, children = []) {
33
+ return { tag, props, children };
34
+ }
35
+ var SVG_NS = "http://www.w3.org/2000/svg";
36
+ var ENUM_BOOLEAN_ATTRS = /* @__PURE__ */ new Set(["draggable", "contenteditable", "spellcheck"]);
37
+ var PROPERTY_ONLY_BOOLS = /* @__PURE__ */ new Set(["indeterminate"]);
38
+ function isSvg(tag) {
39
+ return tag === "svg" || tag === "path" || tag === "circle" || tag === "rect" || tag === "line" || tag === "g";
40
+ }
41
+ function inSvgContext(parent) {
42
+ return parent instanceof Element && parent.namespaceURI === SVG_NS;
43
+ }
44
+ function render(node, parent) {
45
+ if (typeof node === "string") {
46
+ const t = document.createTextNode(node);
47
+ parent.appendChild(t);
48
+ return t;
49
+ }
50
+ if (node instanceof Node) {
51
+ parent.appendChild(node);
52
+ return node;
53
+ }
54
+ const { tag, props, children } = node;
55
+ const el = isSvg(tag) || inSvgContext(parent) ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
56
+ for (const [key, raw] of Object.entries(props)) {
57
+ if (raw === null || raw === void 0 || raw === false) continue;
58
+ if (key === "class") el.setAttribute("class", String(raw));
59
+ else if (key === "style") {
60
+ if (typeof raw === "string") el.style.cssText = raw;
61
+ else Object.assign(el.style, raw);
62
+ } else if (key === "html") el.innerHTML = String(raw);
63
+ else if (key === "text") el.textContent = String(raw);
64
+ else if (key.startsWith("on") && typeof raw === "function") {
65
+ el.addEventListener(key.slice(2).toLowerCase(), raw);
66
+ } else if (key === "dataset") {
67
+ for (const [dk, dv] of Object.entries(raw)) el.dataset[dk] = dv;
68
+ } else if (PROPERTY_ONLY_BOOLS.has(key)) {
69
+ el[key] = true;
70
+ } else if (typeof raw === "boolean") {
71
+ if (raw) el.setAttribute(key, ENUM_BOOLEAN_ATTRS.has(key) ? "true" : "");
72
+ } else el.setAttribute(key, String(raw));
73
+ }
74
+ for (const child of children) render(child, el);
75
+ parent.appendChild(el);
76
+ return el;
77
+ }
78
+ function clear(node) {
79
+ while (node.firstChild) node.removeChild(node.firstChild);
80
+ }
81
+
82
+ // src/expression-editor.ts
83
+ var tr = import_i18n.t;
84
+ var ICON_PATHS = {
85
+ Check: '<path d="M20 6 9 17l-5-5" />',
86
+ 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" />'
87
+ };
88
+ function iconSvg(name, size = 16) {
89
+ 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>`;
90
+ }
91
+ function normalizeFieldDisplay(v) {
92
+ const s = typeof v === "string" ? v.trim().toLowerCase() : "";
93
+ return s === "label" || s === "key" || s === "both" ? s : "both";
94
+ }
95
+ function getTabs() {
96
+ return [
97
+ { key: "field", text: tr("expression.tabField") },
98
+ { key: "variable", text: tr("expression.tabVariable") },
99
+ { key: "function", text: tr("expression.tabFunction") }
100
+ ];
101
+ }
102
+ function getPlaceholder() {
103
+ return {
104
+ field: tr("expression.placeholderField"),
105
+ variable: tr("expression.placeholderVariable"),
106
+ function: tr("expression.placeholderFunction")
107
+ };
108
+ }
109
+ function getAggregateFunctions() {
110
+ return [
111
+ { name: "SUM", label: tr("expression.fnSum"), template: "SUM()" },
112
+ { name: "AVG", label: tr("expression.fnAvg"), template: "AVG()" },
113
+ { name: "COUNT", label: tr("expression.fnCount"), template: "COUNT()" },
114
+ { name: "MIN", label: tr("expression.fnMin"), template: "MIN()" },
115
+ { name: "MAX", label: tr("expression.fnMax"), template: "MAX()" }
116
+ ];
117
+ }
118
+ function getMathFunctions() {
119
+ return [
120
+ { name: "ADD", label: tr("expression.fnAdd"), template: "ADD()" },
121
+ { name: "SUB", label: tr("expression.fnSub"), template: "SUB()" },
122
+ { name: "MUL", label: tr("expression.fnMul"), template: "MUL()" },
123
+ { name: "DIV", label: tr("expression.fnDiv"), template: "DIV()" },
124
+ { name: "ROUND", label: tr("expression.fnRound"), template: "ROUND()" },
125
+ { name: "ROUNDUP", label: tr("expression.fnRoundUp"), template: "ROUNDUP()" },
126
+ { name: "ROUNDDOWN", label: tr("expression.fnRoundDown"), template: "ROUNDDOWN()" },
127
+ { name: "ROUNDBANK", label: tr("expression.fnRoundBank"), template: "ROUNDBANK()" }
128
+ ];
129
+ }
130
+ function getFormatFunctions() {
131
+ return [
132
+ { name: "MONEY", label: tr("expression.fnMoney"), template: "MONEY()" },
133
+ { name: "DATE", label: tr("expression.fnDate"), template: "DATE()" },
134
+ { name: "UPPER", label: tr("expression.fnUpper"), template: "UPPER()" },
135
+ { name: "IF", label: tr("expression.fnIf"), template: "IF()" }
136
+ ];
137
+ }
138
+ function getSystemVariables() {
139
+ return [
140
+ { name: "pageIndex", label: tr("expression.varPageIndex"), template: "{pageIndex}" },
141
+ { name: "totalPages", label: tr("expression.varTotalPages"), template: "{totalPages}" },
142
+ { name: "printDate", label: tr("expression.varPrintDate"), template: "{printDate}" },
143
+ { name: "printTime", label: tr("expression.varPrintTime"), template: "{printTime}" }
144
+ ];
145
+ }
146
+ function getFuncGroups() {
147
+ return [
148
+ { title: tr("expression.groupAggregate"), items: getAggregateFunctions() },
149
+ { title: tr("expression.groupMath"), items: getMathFunctions() },
150
+ { title: tr("expression.groupFormat"), items: getFormatFunctions() }
151
+ ];
152
+ }
153
+ var EMPTY_PREVIEW_KEY = "expression.previewEmpty";
154
+ var NO_VALUE_PREVIEW_KEY = "expression.previewNoValue";
155
+ var ERROR_PREVIEW_KEY = "expression.previewError";
156
+ function previewText(expr, demoData) {
157
+ if (!expr.trim()) return tr(EMPTY_PREVIEW_KEY);
158
+ try {
159
+ const ctx = { ...import_designer.DEFAULT_DEMO_DATA, ...demoData ?? {}, ...(0, import_core.resolveSystemVariables)() };
160
+ const result = (0, import_designer.evaluateTemplate)(expr, ctx);
161
+ if (result === void 0 || result === null) return tr(NO_VALUE_PREVIEW_KEY);
162
+ return String(result);
163
+ } catch {
164
+ return tr(ERROR_PREVIEW_KEY);
165
+ }
166
+ }
167
+ function matchKeyword(items, keyword) {
168
+ const kw = keyword.trim().toLowerCase();
169
+ if (!kw) return items;
170
+ return items.filter((it) => it.label.toLowerCase().includes(kw) || it.name.toLowerCase().includes(kw));
171
+ }
172
+ function cursorRegion(text, caret) {
173
+ const before = text.substring(0, caret);
174
+ const lastBlockOpen = before.lastIndexOf("{");
175
+ const insideBlock = lastBlockOpen !== -1 && !before.slice(lastBlockOpen + 1).includes("}");
176
+ const lastParenOpen = before.lastIndexOf("(");
177
+ const insideParens = lastParenOpen !== -1 && !before.slice(lastParenOpen + 1).includes(")");
178
+ return { insideBlock, insideParens };
179
+ }
180
+ var hasChineseKey = (key) => /[\u4e00-\u9fff]/.test(key);
181
+ 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`;
182
+ function pureFieldBinding(expr, fields) {
183
+ const matched = /^\{\s*([^{}]+?)\s*\}$/.exec(expr.trim());
184
+ if (!matched) return null;
185
+ const key = matched[1] ?? "";
186
+ return fields.find((f) => f.fieldKey === key) ?? null;
187
+ }
188
+ function itemInfo(label, key, display = "both") {
189
+ if (display === "label") return h("div", { class: "ee-field-info" }, [
190
+ h("span", { class: "ee-item-label", text: label })
191
+ ]);
192
+ if (display === "key") return h("div", { class: "ee-field-info" }, [
193
+ h("span", { class: "ee-item-key is-primary", text: key })
194
+ ]);
195
+ return h("div", { class: "ee-field-info" }, [
196
+ h("span", { class: "ee-item-label", text: label }),
197
+ h("span", { class: "ee-item-key", text: key })
198
+ ]);
199
+ }
200
+ function scope(ev) {
201
+ return ev.currentTarget.getRootNode();
202
+ }
203
+ function helpCard(modifier, title, lines) {
204
+ const content = [];
205
+ lines.forEach((line, i) => {
206
+ content.push(line);
207
+ if (i < lines.length - 1) content.push(h("br"));
208
+ });
209
+ return h("div", { class: `ee-help-card ${modifier}` }, [
210
+ h("div", { class: "ee-help-card-title", text: title }),
211
+ h("div", { class: "ee-help-card-content" }, content)
212
+ ]);
213
+ }
214
+ function helpSection() {
215
+ return h("div", { class: "ee-help-section" }, [
216
+ h("div", { class: "ee-help-title", text: tr("expression.k1") }),
217
+ h("div", { class: "ee-help-grid" }, [
218
+ helpCard("ee-help-field", tr("expression.k2"), [
219
+ tr("expression.k3"),
220
+ tr("expression.k4"),
221
+ tr("expression.k5"),
222
+ tr("expression.k6"),
223
+ tr("expression.k7"),
224
+ tr("expression.k8"),
225
+ tr("expression.k9")
226
+ ]),
227
+ helpCard("ee-help-function", tr("expression.k10"), [
228
+ tr("expression.k11"),
229
+ tr("expression.k12"),
230
+ tr("expression.k13"),
231
+ tr("expression.k14"),
232
+ tr("expression.k15"),
233
+ tr("expression.k16")
234
+ ]),
235
+ helpCard("ee-help-variable", tr("expression.k17"), [
236
+ tr("expression.k18"),
237
+ tr("expression.k19"),
238
+ tr("expression.k20")
239
+ ]),
240
+ helpCard("ee-help-conditional", tr("expression.k21"), [
241
+ tr("expression.k22"),
242
+ tr("expression.k23"),
243
+ tr("expression.k24"),
244
+ tr("expression.k25"),
245
+ tr("expression.k26")
246
+ ])
247
+ ])
248
+ ]);
249
+ }
250
+ function renderExpressionEditor(opts, target) {
251
+ tr = opts.t ?? import_i18n.t;
252
+ const fieldDisplay = normalizeFieldDisplay(opts.fieldDisplay);
253
+ const state = {
254
+ activeTab: "field",
255
+ searchText: "",
256
+ expression: target.value || "",
257
+ /** 字段绑定模式标记:仅当调用方给了初始 key,才在确定时回写 binding/title */
258
+ binding: target.binding,
259
+ /** 最近一次复制成功的字段 key:按钮图标 1.2s 内显示对勾(对齐 Vue 3 轨的 copiedKey) */
260
+ copiedFieldKey: "",
261
+ /** 双击插入中文 key 后的格式提示;插入英文字段/手动编辑时清空 */
262
+ keyHint: ""
263
+ };
264
+ const query = (root, selector) => root.querySelector(selector);
265
+ const updatePreview = (root) => {
266
+ const el = query(root, ".ee-preview");
267
+ if (!el) return;
268
+ const text = previewText(state.expression, opts.demoData);
269
+ el.textContent = text;
270
+ el.classList.toggle("ee-preview-error", text === tr(ERROR_PREVIEW_KEY));
271
+ };
272
+ const updateKeyHint = (root) => {
273
+ const el = query(root, ".ee-key-hint");
274
+ if (!el) return;
275
+ el.textContent = state.keyHint;
276
+ el.style.display = state.keyHint ? "" : "none";
277
+ };
278
+ const listItems = () => {
279
+ if (state.activeTab === "variable") {
280
+ return matchKeyword(getSystemVariables(), state.searchText).map((sv) => h("div", {
281
+ class: "ee-list-item",
282
+ onDblclick: (ev) => {
283
+ const { insideParens } = region(ev);
284
+ insert(scope(ev), insideParens ? sv.template.replace(/^\{|\}$/g, "") : sv.template, void 0, "");
285
+ }
286
+ }, [itemInfo(sv.label, sv.template)]));
287
+ }
288
+ if (state.activeTab === "function") {
289
+ return getFuncGroups().map((group) => h("div", { class: "ee-func-group" }, [
290
+ h("div", { class: "ee-func-group-title", text: group.title }),
291
+ ...matchKeyword(group.items, state.searchText).map((fn) => h("div", {
292
+ class: "ee-list-item",
293
+ onDblclick: (ev) => {
294
+ const { insideBlock } = region(ev);
295
+ const text = insideBlock ? fn.template : `{${fn.template}}`;
296
+ insert(scope(ev), text, text.indexOf("(") + 1, "");
297
+ }
298
+ }, [itemInfo(fn.label, `${fn.name}()`)]))
299
+ ]));
300
+ }
301
+ const groups = (0, import_designer.filterGroups)((0, import_designer.groupFields)(opts.fields ?? []), state.searchText);
302
+ if (!groups.length) return [h("p", { class: "pd-empty", text: tr("expression.k27") })];
303
+ const nodes = [];
304
+ for (const group of groups) {
305
+ if (group.key) {
306
+ nodes.push(h("div", { class: `ee-field-group${group.isList ? " is-list" : ""}` }, [
307
+ h("span", { class: "ee-field-group-icon", text: group.isList ? "\u{1F4CB}" : "\u{1F4C1}" }),
308
+ h("span", { text: group.label })
309
+ ]));
310
+ }
311
+ for (const field of group.fields) {
312
+ nodes.push(h("div", {
313
+ class: "ee-list-item ee-field-item",
314
+ style: { paddingLeft: group.key ? "22px" : "10px" },
315
+ onDblclick: (ev) => {
316
+ const { insideParens } = region(ev);
317
+ const mod = ev;
318
+ if (mod.ctrlKey || mod.metaKey) {
319
+ const name = field.fieldLabel || field.fieldKey;
320
+ insert(scope(ev), insideParens ? `"${name}"` : name, void 0, "");
321
+ return;
322
+ }
323
+ insert(
324
+ scope(ev),
325
+ insideParens ? field.fieldKey : `{${field.fieldKey}}`,
326
+ void 0,
327
+ hasChineseKey(field.fieldKey) ? chineseKeyHint(field.fieldKey) : ""
328
+ );
329
+ }
330
+ }, [
331
+ itemInfo(field.fieldLabel || field.fieldKey, field.fieldKey, fieldDisplay),
332
+ // 字段右侧复制按钮:复制字段中文名(对齐 canvas ExpressionEditor 的 .ee-copy-btn)
333
+ h("button", {
334
+ type: "button",
335
+ class: `ee-copy-btn${state.copiedFieldKey === field.fieldKey ? " is-copied" : ""}`,
336
+ // 提示浮层由 print-designer 的 hover-tip 委托承担(容器白名单含 .pd-dialog-overlay)
337
+ "data-tip": state.copiedFieldKey === field.fieldKey ? tr("expression.k28") : `\u590D\u5236\u5B57\u6BB5\u540D\u300C${field.fieldLabel}\u300D`,
338
+ "aria-label": `\u590D\u5236\u5B57\u6BB5\u540D ${field.fieldLabel}`,
339
+ html: iconSvg(state.copiedFieldKey === field.fieldKey ? "Check" : "Copy", 13),
340
+ onClick: (ev) => {
341
+ ev.stopPropagation();
342
+ copyFieldName(ev, field);
343
+ },
344
+ onDblclick: (ev) => ev.stopPropagation()
345
+ })
346
+ ]));
347
+ }
348
+ }
349
+ return nodes;
350
+ };
351
+ const repaint = (root) => {
352
+ const tabs = Array.from(root.querySelectorAll(".ee-nav-tab"));
353
+ tabs.forEach((el, i) => el.classList.toggle("active", getTabs()[i]?.key === state.activeTab));
354
+ const search = query(root, ".ee-content-search .pd-input");
355
+ if (search) {
356
+ const placeholder = getPlaceholder()[state.activeTab];
357
+ if (search.placeholder !== placeholder) search.placeholder = placeholder;
358
+ if (search.value !== state.searchText) search.value = state.searchText;
359
+ }
360
+ const ta = query(root, ".ee-textarea");
361
+ if (ta && ta.value !== state.expression) ta.value = state.expression;
362
+ const list = query(root, ".ee-content-list");
363
+ if (list) {
364
+ clear(list);
365
+ for (const item of listItems()) render(item, list);
366
+ }
367
+ updatePreview(root);
368
+ updateKeyHint(root);
369
+ };
370
+ function copyFieldName(ev, field) {
371
+ const root = scope(ev);
372
+ (0, import_designer.copyTextToClipboard)(field.fieldLabel || field.fieldKey).then((ok) => {
373
+ if (!ok) return;
374
+ state.copiedFieldKey = field.fieldKey;
375
+ repaint(root);
376
+ setTimeout(() => {
377
+ if (state.copiedFieldKey !== field.fieldKey) return;
378
+ state.copiedFieldKey = "";
379
+ repaint(root);
380
+ }, 1200);
381
+ });
382
+ }
383
+ const region = (ev) => {
384
+ const ta = query(scope(ev), ".ee-textarea");
385
+ const caret = ta?.selectionStart ?? state.expression.length;
386
+ return cursorRegion(state.expression, caret);
387
+ };
388
+ const insert = (root, text, caretOffset = text.length, keyHint) => {
389
+ if (keyHint !== void 0) state.keyHint = keyHint;
390
+ const ta = query(root, ".ee-textarea");
391
+ if (!ta) {
392
+ state.expression += text;
393
+ updatePreview(root);
394
+ updateKeyHint(root);
395
+ return;
396
+ }
397
+ const start = ta.selectionStart ?? state.expression.length;
398
+ const end = ta.selectionEnd ?? start;
399
+ state.expression = state.expression.substring(0, start) + text + state.expression.substring(end);
400
+ const caret = start + caretOffset;
401
+ ta.value = state.expression;
402
+ ta.focus();
403
+ ta.selectionStart = ta.selectionEnd = caret;
404
+ updatePreview(root);
405
+ updateKeyHint(root);
406
+ };
407
+ const onConfirm = () => {
408
+ const formatter = state.expression;
409
+ if (state.binding === void 0) {
410
+ opts.onApply({ formatter });
411
+ opts.onClose();
412
+ return;
413
+ }
414
+ const field = pureFieldBinding(formatter, opts.fields ?? []);
415
+ opts.onApply(field ? { formatter, binding: field.fieldKey, title: field.fieldLabel } : { formatter });
416
+ opts.onClose();
417
+ };
418
+ const nav = h("div", { class: "ee-nav" }, [
419
+ h("div", { class: "ee-nav-title", text: tr("expression.k29") }),
420
+ h("div", { class: "ee-nav-tabs" }, getTabs().map((tab, i) => h("div", {
421
+ class: `ee-nav-tab${state.activeTab === tab.key ? " active" : ""}`,
422
+ text: tab.text,
423
+ onClick: (ev) => {
424
+ state.activeTab = getTabs()[i].key;
425
+ repaint(scope(ev));
426
+ }
427
+ })))
428
+ ]);
429
+ const content = h("div", { class: "ee-content" }, [
430
+ h("div", { class: "ee-content-search" }, [
431
+ h("input", {
432
+ class: "pd-input",
433
+ placeholder: getPlaceholder()[state.activeTab],
434
+ onInput: (ev) => {
435
+ state.searchText = ev.target.value;
436
+ repaint(scope(ev));
437
+ }
438
+ })
439
+ ]),
440
+ h("div", { class: "ee-content-list" }, listItems())
441
+ ]);
442
+ const initialPreview = previewText(state.expression, opts.demoData);
443
+ const editor = h("div", { class: "ee-editor" }, [
444
+ h("div", { class: "ee-editor-section" }, [
445
+ h("div", { class: "ee-editor-title", text: tr("expression.k30") }),
446
+ h("textarea", {
447
+ class: "ee-textarea",
448
+ rows: 6,
449
+ placeholder: tr("expression.k31"),
450
+ text: state.expression,
451
+ onInput: (ev) => {
452
+ state.expression = ev.target.value;
453
+ state.keyHint = "";
454
+ updatePreview(scope(ev));
455
+ updateKeyHint(scope(ev));
456
+ }
457
+ }),
458
+ h("div", {
459
+ class: "pd-hint ee-key-hint",
460
+ style: { display: "none", color: "var(--pd-accent, #165DFF)" },
461
+ text: ""
462
+ })
463
+ ]),
464
+ h("div", { class: "ee-editor-section" }, [
465
+ h("div", { class: "ee-editor-title", text: tr("expression.k32") }),
466
+ h("div", {
467
+ class: `ee-preview${initialPreview === tr(ERROR_PREVIEW_KEY) ? " ee-preview-error" : ""}`,
468
+ text: initialPreview
469
+ })
470
+ ]),
471
+ helpSection()
472
+ ]);
473
+ return h("div", {
474
+ class: "pd-dialog-overlay",
475
+ onKeydown: (ev) => {
476
+ if (ev.key === "Escape") opts.onClose();
477
+ }
478
+ }, [
479
+ h("section", {
480
+ class: "pd-dialog pd-dialog-large",
481
+ role: "dialog",
482
+ "aria-modal": "true",
483
+ "aria-labelledby": "expression-editor-title"
484
+ }, [
485
+ h("header", { class: "pd-dialog-header" }, [
486
+ h("strong", { id: "expression-editor-title", text: tr("expression.k33") }),
487
+ h("button", { type: "button", class: "pd-close", "aria-label": tr("expression.k34"), text: "\xD7", onClick: () => opts.onClose() })
488
+ ]),
489
+ h("div", { class: "expression-editor" }, [nav, content, editor]),
490
+ h("footer", { class: "pd-dialog-footer" }, [
491
+ h("button", { type: "button", class: "pd-button", text: tr("expression.k35"), onClick: () => opts.onClose() }),
492
+ h("button", { type: "button", class: "pd-button primary", text: tr("expression.k36"), onClick: () => onConfirm() })
493
+ ])
494
+ ])
495
+ ]);
496
+ }
497
+ // Annotate the CommonJS export names for ESM import in node:
498
+ 0 && (module.exports = {
499
+ normalizeFieldDisplay,
500
+ renderExpressionEditor
501
+ });
@@ -0,0 +1,45 @@
1
+ /*!
2
+ * @worm-print-platform/plugin-kit v1.6.1
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 { Translate } from '@worm-print-platform/core/i18n';
9
+ import { El } from './dom.cjs';
10
+
11
+ interface ExpressionEditorTarget {
12
+ /** 元素 id(表格单元格时用于定位) */
13
+ elementId: string;
14
+ /** 要写回的目标路径,如 'options.formatter' 或 'cell:<rowId>:<colIndex>' */
15
+ targetPath: string;
16
+ /** 当前表达式文本 */
17
+ value: string;
18
+ /** 可选:字段绑定模式的初始字段 key */
19
+ binding?: string;
20
+ }
21
+ /** 字段行显示模式:中文名 / key / 两者(默认 both,保持既有行为) */
22
+ type FieldDisplayMode = 'label' | 'key' | 'both';
23
+ /** 归一化宿主传入的显示模式:trim + 小写;非法值静默回退 both */
24
+ declare function normalizeFieldDisplay(v: unknown): FieldDisplayMode;
25
+ interface ExpressionEditorOptions {
26
+ fields: PrintBusinessField[];
27
+ /** 求值预览用的样例行数据 */
28
+ demoData?: Record<string, any>;
29
+ /** 字段行显示模式;缺省 / 非法值按 both(中文名 + key) */
30
+ fieldDisplay?: FieldDisplayMode;
31
+ /** 当前 locale 的翻译函数;缺省用全局 t */
32
+ t?: Translate;
33
+ /** 关闭弹窗 */
34
+ onClose: () => void;
35
+ /** 点确定:把最终表达式回写 */
36
+ onApply: (next: {
37
+ formatter?: string;
38
+ binding?: string;
39
+ title?: string;
40
+ }) => void;
41
+ }
42
+ /** 渲染表达式编辑器弹窗的 DOM 描述(内部已含遮罩层,render 进 shadow 根下即可) */
43
+ declare function renderExpressionEditor(opts: ExpressionEditorOptions, target: ExpressionEditorTarget): El;
44
+
45
+ export { type ExpressionEditorOptions, type ExpressionEditorTarget, type FieldDisplayMode, normalizeFieldDisplay, renderExpressionEditor };
@@ -0,0 +1,45 @@
1
+ /*!
2
+ * @worm-print-platform/plugin-kit v1.6.1
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 { Translate } from '@worm-print-platform/core/i18n';
9
+ import { El } from './dom.js';
10
+
11
+ interface ExpressionEditorTarget {
12
+ /** 元素 id(表格单元格时用于定位) */
13
+ elementId: string;
14
+ /** 要写回的目标路径,如 'options.formatter' 或 'cell:<rowId>:<colIndex>' */
15
+ targetPath: string;
16
+ /** 当前表达式文本 */
17
+ value: string;
18
+ /** 可选:字段绑定模式的初始字段 key */
19
+ binding?: string;
20
+ }
21
+ /** 字段行显示模式:中文名 / key / 两者(默认 both,保持既有行为) */
22
+ type FieldDisplayMode = 'label' | 'key' | 'both';
23
+ /** 归一化宿主传入的显示模式:trim + 小写;非法值静默回退 both */
24
+ declare function normalizeFieldDisplay(v: unknown): FieldDisplayMode;
25
+ interface ExpressionEditorOptions {
26
+ fields: PrintBusinessField[];
27
+ /** 求值预览用的样例行数据 */
28
+ demoData?: Record<string, any>;
29
+ /** 字段行显示模式;缺省 / 非法值按 both(中文名 + key) */
30
+ fieldDisplay?: FieldDisplayMode;
31
+ /** 当前 locale 的翻译函数;缺省用全局 t */
32
+ t?: Translate;
33
+ /** 关闭弹窗 */
34
+ onClose: () => void;
35
+ /** 点确定:把最终表达式回写 */
36
+ onApply: (next: {
37
+ formatter?: string;
38
+ binding?: string;
39
+ title?: string;
40
+ }) => void;
41
+ }
42
+ /** 渲染表达式编辑器弹窗的 DOM 描述(内部已含遮罩层,render 进 shadow 根下即可) */
43
+ declare function renderExpressionEditor(opts: ExpressionEditorOptions, target: ExpressionEditorTarget): El;
44
+
45
+ export { type ExpressionEditorOptions, type ExpressionEditorTarget, type FieldDisplayMode, normalizeFieldDisplay, renderExpressionEditor };