@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.
- package/README.md +1 -1
- package/dist/chunk-JABNJAZR.js +62 -0
- package/dist/controls.cjs +429 -0
- package/dist/controls.d.cts +50 -0
- package/dist/controls.d.ts +50 -0
- package/dist/controls.js +353 -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 +501 -0
- package/dist/expression-editor.d.cts +45 -0
- package/dist/expression-editor.d.ts +45 -0
- package/dist/expression-editor.js +428 -0
- package/dist/index.cjs +37 -4
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +33 -1
- package/package.json +17 -2
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clear,
|
|
3
|
+
h,
|
|
4
|
+
render
|
|
5
|
+
} from "./chunk-JABNJAZR.js";
|
|
6
|
+
|
|
7
|
+
// src/expression-editor.ts
|
|
8
|
+
import { DEFAULT_DEMO_DATA, copyTextToClipboard, evaluateTemplate, filterGroups, groupFields } from "@worm-print-platform/core/designer";
|
|
9
|
+
import { t as globalT } from "@worm-print-platform/core/i18n";
|
|
10
|
+
import { resolveSystemVariables } from "@worm-print-platform/core";
|
|
11
|
+
var tr = globalT;
|
|
12
|
+
var ICON_PATHS = {
|
|
13
|
+
Check: '<path d="M20 6 9 17l-5-5" />',
|
|
14
|
+
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" />'
|
|
15
|
+
};
|
|
16
|
+
function iconSvg(name, size = 16) {
|
|
17
|
+
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>`;
|
|
18
|
+
}
|
|
19
|
+
function normalizeFieldDisplay(v) {
|
|
20
|
+
const s = typeof v === "string" ? v.trim().toLowerCase() : "";
|
|
21
|
+
return s === "label" || s === "key" || s === "both" ? s : "both";
|
|
22
|
+
}
|
|
23
|
+
function getTabs() {
|
|
24
|
+
return [
|
|
25
|
+
{ key: "field", text: tr("expression.tabField") },
|
|
26
|
+
{ key: "variable", text: tr("expression.tabVariable") },
|
|
27
|
+
{ key: "function", text: tr("expression.tabFunction") }
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
function getPlaceholder() {
|
|
31
|
+
return {
|
|
32
|
+
field: tr("expression.placeholderField"),
|
|
33
|
+
variable: tr("expression.placeholderVariable"),
|
|
34
|
+
function: tr("expression.placeholderFunction")
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function getAggregateFunctions() {
|
|
38
|
+
return [
|
|
39
|
+
{ name: "SUM", label: tr("expression.fnSum"), template: "SUM()" },
|
|
40
|
+
{ name: "AVG", label: tr("expression.fnAvg"), template: "AVG()" },
|
|
41
|
+
{ name: "COUNT", label: tr("expression.fnCount"), template: "COUNT()" },
|
|
42
|
+
{ name: "MIN", label: tr("expression.fnMin"), template: "MIN()" },
|
|
43
|
+
{ name: "MAX", label: tr("expression.fnMax"), template: "MAX()" }
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
function getMathFunctions() {
|
|
47
|
+
return [
|
|
48
|
+
{ name: "ADD", label: tr("expression.fnAdd"), template: "ADD()" },
|
|
49
|
+
{ name: "SUB", label: tr("expression.fnSub"), template: "SUB()" },
|
|
50
|
+
{ name: "MUL", label: tr("expression.fnMul"), template: "MUL()" },
|
|
51
|
+
{ name: "DIV", label: tr("expression.fnDiv"), template: "DIV()" },
|
|
52
|
+
{ name: "ROUND", label: tr("expression.fnRound"), template: "ROUND()" },
|
|
53
|
+
{ name: "ROUNDUP", label: tr("expression.fnRoundUp"), template: "ROUNDUP()" },
|
|
54
|
+
{ name: "ROUNDDOWN", label: tr("expression.fnRoundDown"), template: "ROUNDDOWN()" },
|
|
55
|
+
{ name: "ROUNDBANK", label: tr("expression.fnRoundBank"), template: "ROUNDBANK()" }
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
function getFormatFunctions() {
|
|
59
|
+
return [
|
|
60
|
+
{ name: "MONEY", label: tr("expression.fnMoney"), template: "MONEY()" },
|
|
61
|
+
{ name: "DATE", label: tr("expression.fnDate"), template: "DATE()" },
|
|
62
|
+
{ name: "UPPER", label: tr("expression.fnUpper"), template: "UPPER()" },
|
|
63
|
+
{ name: "IF", label: tr("expression.fnIf"), template: "IF()" }
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
function getSystemVariables() {
|
|
67
|
+
return [
|
|
68
|
+
{ name: "pageIndex", label: tr("expression.varPageIndex"), template: "{pageIndex}" },
|
|
69
|
+
{ name: "totalPages", label: tr("expression.varTotalPages"), template: "{totalPages}" },
|
|
70
|
+
{ name: "printDate", label: tr("expression.varPrintDate"), template: "{printDate}" },
|
|
71
|
+
{ name: "printTime", label: tr("expression.varPrintTime"), template: "{printTime}" }
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
function getFuncGroups() {
|
|
75
|
+
return [
|
|
76
|
+
{ title: tr("expression.groupAggregate"), items: getAggregateFunctions() },
|
|
77
|
+
{ title: tr("expression.groupMath"), items: getMathFunctions() },
|
|
78
|
+
{ title: tr("expression.groupFormat"), items: getFormatFunctions() }
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
var EMPTY_PREVIEW_KEY = "expression.previewEmpty";
|
|
82
|
+
var NO_VALUE_PREVIEW_KEY = "expression.previewNoValue";
|
|
83
|
+
var ERROR_PREVIEW_KEY = "expression.previewError";
|
|
84
|
+
function previewText(expr, demoData) {
|
|
85
|
+
if (!expr.trim()) return tr(EMPTY_PREVIEW_KEY);
|
|
86
|
+
try {
|
|
87
|
+
const ctx = { ...DEFAULT_DEMO_DATA, ...demoData ?? {}, ...resolveSystemVariables() };
|
|
88
|
+
const result = evaluateTemplate(expr, ctx);
|
|
89
|
+
if (result === void 0 || result === null) return tr(NO_VALUE_PREVIEW_KEY);
|
|
90
|
+
return String(result);
|
|
91
|
+
} catch {
|
|
92
|
+
return tr(ERROR_PREVIEW_KEY);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function matchKeyword(items, keyword) {
|
|
96
|
+
const kw = keyword.trim().toLowerCase();
|
|
97
|
+
if (!kw) return items;
|
|
98
|
+
return items.filter((it) => it.label.toLowerCase().includes(kw) || it.name.toLowerCase().includes(kw));
|
|
99
|
+
}
|
|
100
|
+
function cursorRegion(text, caret) {
|
|
101
|
+
const before = text.substring(0, caret);
|
|
102
|
+
const lastBlockOpen = before.lastIndexOf("{");
|
|
103
|
+
const insideBlock = lastBlockOpen !== -1 && !before.slice(lastBlockOpen + 1).includes("}");
|
|
104
|
+
const lastParenOpen = before.lastIndexOf("(");
|
|
105
|
+
const insideParens = lastParenOpen !== -1 && !before.slice(lastParenOpen + 1).includes(")");
|
|
106
|
+
return { insideBlock, insideParens };
|
|
107
|
+
}
|
|
108
|
+
var hasChineseKey = (key) => /[\u4e00-\u9fff]/.test(key);
|
|
109
|
+
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`;
|
|
110
|
+
function pureFieldBinding(expr, fields) {
|
|
111
|
+
const matched = /^\{\s*([^{}]+?)\s*\}$/.exec(expr.trim());
|
|
112
|
+
if (!matched) return null;
|
|
113
|
+
const key = matched[1] ?? "";
|
|
114
|
+
return fields.find((f) => f.fieldKey === key) ?? null;
|
|
115
|
+
}
|
|
116
|
+
function itemInfo(label, key, display = "both") {
|
|
117
|
+
if (display === "label") return h("div", { class: "ee-field-info" }, [
|
|
118
|
+
h("span", { class: "ee-item-label", text: label })
|
|
119
|
+
]);
|
|
120
|
+
if (display === "key") return h("div", { class: "ee-field-info" }, [
|
|
121
|
+
h("span", { class: "ee-item-key is-primary", text: key })
|
|
122
|
+
]);
|
|
123
|
+
return h("div", { class: "ee-field-info" }, [
|
|
124
|
+
h("span", { class: "ee-item-label", text: label }),
|
|
125
|
+
h("span", { class: "ee-item-key", text: key })
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
function scope(ev) {
|
|
129
|
+
return ev.currentTarget.getRootNode();
|
|
130
|
+
}
|
|
131
|
+
function helpCard(modifier, title, lines) {
|
|
132
|
+
const content = [];
|
|
133
|
+
lines.forEach((line, i) => {
|
|
134
|
+
content.push(line);
|
|
135
|
+
if (i < lines.length - 1) content.push(h("br"));
|
|
136
|
+
});
|
|
137
|
+
return h("div", { class: `ee-help-card ${modifier}` }, [
|
|
138
|
+
h("div", { class: "ee-help-card-title", text: title }),
|
|
139
|
+
h("div", { class: "ee-help-card-content" }, content)
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
function helpSection() {
|
|
143
|
+
return h("div", { class: "ee-help-section" }, [
|
|
144
|
+
h("div", { class: "ee-help-title", text: tr("expression.k1") }),
|
|
145
|
+
h("div", { class: "ee-help-grid" }, [
|
|
146
|
+
helpCard("ee-help-field", tr("expression.k2"), [
|
|
147
|
+
tr("expression.k3"),
|
|
148
|
+
tr("expression.k4"),
|
|
149
|
+
tr("expression.k5"),
|
|
150
|
+
tr("expression.k6"),
|
|
151
|
+
tr("expression.k7"),
|
|
152
|
+
tr("expression.k8"),
|
|
153
|
+
tr("expression.k9")
|
|
154
|
+
]),
|
|
155
|
+
helpCard("ee-help-function", tr("expression.k10"), [
|
|
156
|
+
tr("expression.k11"),
|
|
157
|
+
tr("expression.k12"),
|
|
158
|
+
tr("expression.k13"),
|
|
159
|
+
tr("expression.k14"),
|
|
160
|
+
tr("expression.k15"),
|
|
161
|
+
tr("expression.k16")
|
|
162
|
+
]),
|
|
163
|
+
helpCard("ee-help-variable", tr("expression.k17"), [
|
|
164
|
+
tr("expression.k18"),
|
|
165
|
+
tr("expression.k19"),
|
|
166
|
+
tr("expression.k20")
|
|
167
|
+
]),
|
|
168
|
+
helpCard("ee-help-conditional", tr("expression.k21"), [
|
|
169
|
+
tr("expression.k22"),
|
|
170
|
+
tr("expression.k23"),
|
|
171
|
+
tr("expression.k24"),
|
|
172
|
+
tr("expression.k25"),
|
|
173
|
+
tr("expression.k26")
|
|
174
|
+
])
|
|
175
|
+
])
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
function renderExpressionEditor(opts, target) {
|
|
179
|
+
tr = opts.t ?? globalT;
|
|
180
|
+
const fieldDisplay = normalizeFieldDisplay(opts.fieldDisplay);
|
|
181
|
+
const state = {
|
|
182
|
+
activeTab: "field",
|
|
183
|
+
searchText: "",
|
|
184
|
+
expression: target.value || "",
|
|
185
|
+
/** 字段绑定模式标记:仅当调用方给了初始 key,才在确定时回写 binding/title */
|
|
186
|
+
binding: target.binding,
|
|
187
|
+
/** 最近一次复制成功的字段 key:按钮图标 1.2s 内显示对勾(对齐 Vue 3 轨的 copiedKey) */
|
|
188
|
+
copiedFieldKey: "",
|
|
189
|
+
/** 双击插入中文 key 后的格式提示;插入英文字段/手动编辑时清空 */
|
|
190
|
+
keyHint: ""
|
|
191
|
+
};
|
|
192
|
+
const query = (root, selector) => root.querySelector(selector);
|
|
193
|
+
const updatePreview = (root) => {
|
|
194
|
+
const el = query(root, ".ee-preview");
|
|
195
|
+
if (!el) return;
|
|
196
|
+
const text = previewText(state.expression, opts.demoData);
|
|
197
|
+
el.textContent = text;
|
|
198
|
+
el.classList.toggle("ee-preview-error", text === tr(ERROR_PREVIEW_KEY));
|
|
199
|
+
};
|
|
200
|
+
const updateKeyHint = (root) => {
|
|
201
|
+
const el = query(root, ".ee-key-hint");
|
|
202
|
+
if (!el) return;
|
|
203
|
+
el.textContent = state.keyHint;
|
|
204
|
+
el.style.display = state.keyHint ? "" : "none";
|
|
205
|
+
};
|
|
206
|
+
const listItems = () => {
|
|
207
|
+
if (state.activeTab === "variable") {
|
|
208
|
+
return matchKeyword(getSystemVariables(), state.searchText).map((sv) => h("div", {
|
|
209
|
+
class: "ee-list-item",
|
|
210
|
+
onDblclick: (ev) => {
|
|
211
|
+
const { insideParens } = region(ev);
|
|
212
|
+
insert(scope(ev), insideParens ? sv.template.replace(/^\{|\}$/g, "") : sv.template, void 0, "");
|
|
213
|
+
}
|
|
214
|
+
}, [itemInfo(sv.label, sv.template)]));
|
|
215
|
+
}
|
|
216
|
+
if (state.activeTab === "function") {
|
|
217
|
+
return getFuncGroups().map((group) => h("div", { class: "ee-func-group" }, [
|
|
218
|
+
h("div", { class: "ee-func-group-title", text: group.title }),
|
|
219
|
+
...matchKeyword(group.items, state.searchText).map((fn) => h("div", {
|
|
220
|
+
class: "ee-list-item",
|
|
221
|
+
onDblclick: (ev) => {
|
|
222
|
+
const { insideBlock } = region(ev);
|
|
223
|
+
const text = insideBlock ? fn.template : `{${fn.template}}`;
|
|
224
|
+
insert(scope(ev), text, text.indexOf("(") + 1, "");
|
|
225
|
+
}
|
|
226
|
+
}, [itemInfo(fn.label, `${fn.name}()`)]))
|
|
227
|
+
]));
|
|
228
|
+
}
|
|
229
|
+
const groups = filterGroups(groupFields(opts.fields ?? []), state.searchText);
|
|
230
|
+
if (!groups.length) return [h("p", { class: "pd-empty", text: tr("expression.k27") })];
|
|
231
|
+
const nodes = [];
|
|
232
|
+
for (const group of groups) {
|
|
233
|
+
if (group.key) {
|
|
234
|
+
nodes.push(h("div", { class: `ee-field-group${group.isList ? " is-list" : ""}` }, [
|
|
235
|
+
h("span", { class: "ee-field-group-icon", text: group.isList ? "\u{1F4CB}" : "\u{1F4C1}" }),
|
|
236
|
+
h("span", { text: group.label })
|
|
237
|
+
]));
|
|
238
|
+
}
|
|
239
|
+
for (const field of group.fields) {
|
|
240
|
+
nodes.push(h("div", {
|
|
241
|
+
class: "ee-list-item ee-field-item",
|
|
242
|
+
style: { paddingLeft: group.key ? "22px" : "10px" },
|
|
243
|
+
onDblclick: (ev) => {
|
|
244
|
+
const { insideParens } = region(ev);
|
|
245
|
+
const mod = ev;
|
|
246
|
+
if (mod.ctrlKey || mod.metaKey) {
|
|
247
|
+
const name = field.fieldLabel || field.fieldKey;
|
|
248
|
+
insert(scope(ev), insideParens ? `"${name}"` : name, void 0, "");
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
insert(
|
|
252
|
+
scope(ev),
|
|
253
|
+
insideParens ? field.fieldKey : `{${field.fieldKey}}`,
|
|
254
|
+
void 0,
|
|
255
|
+
hasChineseKey(field.fieldKey) ? chineseKeyHint(field.fieldKey) : ""
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}, [
|
|
259
|
+
itemInfo(field.fieldLabel || field.fieldKey, field.fieldKey, fieldDisplay),
|
|
260
|
+
// 字段右侧复制按钮:复制字段中文名(对齐 canvas ExpressionEditor 的 .ee-copy-btn)
|
|
261
|
+
h("button", {
|
|
262
|
+
type: "button",
|
|
263
|
+
class: `ee-copy-btn${state.copiedFieldKey === field.fieldKey ? " is-copied" : ""}`,
|
|
264
|
+
// 提示浮层由 print-designer 的 hover-tip 委托承担(容器白名单含 .pd-dialog-overlay)
|
|
265
|
+
"data-tip": state.copiedFieldKey === field.fieldKey ? tr("expression.k28") : `\u590D\u5236\u5B57\u6BB5\u540D\u300C${field.fieldLabel}\u300D`,
|
|
266
|
+
"aria-label": `\u590D\u5236\u5B57\u6BB5\u540D ${field.fieldLabel}`,
|
|
267
|
+
html: iconSvg(state.copiedFieldKey === field.fieldKey ? "Check" : "Copy", 13),
|
|
268
|
+
onClick: (ev) => {
|
|
269
|
+
ev.stopPropagation();
|
|
270
|
+
copyFieldName(ev, field);
|
|
271
|
+
},
|
|
272
|
+
onDblclick: (ev) => ev.stopPropagation()
|
|
273
|
+
})
|
|
274
|
+
]));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return nodes;
|
|
278
|
+
};
|
|
279
|
+
const repaint = (root) => {
|
|
280
|
+
const tabs = Array.from(root.querySelectorAll(".ee-nav-tab"));
|
|
281
|
+
tabs.forEach((el, i) => el.classList.toggle("active", getTabs()[i]?.key === state.activeTab));
|
|
282
|
+
const search = query(root, ".ee-content-search .pd-input");
|
|
283
|
+
if (search) {
|
|
284
|
+
const placeholder = getPlaceholder()[state.activeTab];
|
|
285
|
+
if (search.placeholder !== placeholder) search.placeholder = placeholder;
|
|
286
|
+
if (search.value !== state.searchText) search.value = state.searchText;
|
|
287
|
+
}
|
|
288
|
+
const ta = query(root, ".ee-textarea");
|
|
289
|
+
if (ta && ta.value !== state.expression) ta.value = state.expression;
|
|
290
|
+
const list = query(root, ".ee-content-list");
|
|
291
|
+
if (list) {
|
|
292
|
+
clear(list);
|
|
293
|
+
for (const item of listItems()) render(item, list);
|
|
294
|
+
}
|
|
295
|
+
updatePreview(root);
|
|
296
|
+
updateKeyHint(root);
|
|
297
|
+
};
|
|
298
|
+
function copyFieldName(ev, field) {
|
|
299
|
+
const root = scope(ev);
|
|
300
|
+
copyTextToClipboard(field.fieldLabel || field.fieldKey).then((ok) => {
|
|
301
|
+
if (!ok) return;
|
|
302
|
+
state.copiedFieldKey = field.fieldKey;
|
|
303
|
+
repaint(root);
|
|
304
|
+
setTimeout(() => {
|
|
305
|
+
if (state.copiedFieldKey !== field.fieldKey) return;
|
|
306
|
+
state.copiedFieldKey = "";
|
|
307
|
+
repaint(root);
|
|
308
|
+
}, 1200);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
const region = (ev) => {
|
|
312
|
+
const ta = query(scope(ev), ".ee-textarea");
|
|
313
|
+
const caret = ta?.selectionStart ?? state.expression.length;
|
|
314
|
+
return cursorRegion(state.expression, caret);
|
|
315
|
+
};
|
|
316
|
+
const insert = (root, text, caretOffset = text.length, keyHint) => {
|
|
317
|
+
if (keyHint !== void 0) state.keyHint = keyHint;
|
|
318
|
+
const ta = query(root, ".ee-textarea");
|
|
319
|
+
if (!ta) {
|
|
320
|
+
state.expression += text;
|
|
321
|
+
updatePreview(root);
|
|
322
|
+
updateKeyHint(root);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const start = ta.selectionStart ?? state.expression.length;
|
|
326
|
+
const end = ta.selectionEnd ?? start;
|
|
327
|
+
state.expression = state.expression.substring(0, start) + text + state.expression.substring(end);
|
|
328
|
+
const caret = start + caretOffset;
|
|
329
|
+
ta.value = state.expression;
|
|
330
|
+
ta.focus();
|
|
331
|
+
ta.selectionStart = ta.selectionEnd = caret;
|
|
332
|
+
updatePreview(root);
|
|
333
|
+
updateKeyHint(root);
|
|
334
|
+
};
|
|
335
|
+
const onConfirm = () => {
|
|
336
|
+
const formatter = state.expression;
|
|
337
|
+
if (state.binding === void 0) {
|
|
338
|
+
opts.onApply({ formatter });
|
|
339
|
+
opts.onClose();
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const field = pureFieldBinding(formatter, opts.fields ?? []);
|
|
343
|
+
opts.onApply(field ? { formatter, binding: field.fieldKey, title: field.fieldLabel } : { formatter });
|
|
344
|
+
opts.onClose();
|
|
345
|
+
};
|
|
346
|
+
const nav = h("div", { class: "ee-nav" }, [
|
|
347
|
+
h("div", { class: "ee-nav-title", text: tr("expression.k29") }),
|
|
348
|
+
h("div", { class: "ee-nav-tabs" }, getTabs().map((tab, i) => h("div", {
|
|
349
|
+
class: `ee-nav-tab${state.activeTab === tab.key ? " active" : ""}`,
|
|
350
|
+
text: tab.text,
|
|
351
|
+
onClick: (ev) => {
|
|
352
|
+
state.activeTab = getTabs()[i].key;
|
|
353
|
+
repaint(scope(ev));
|
|
354
|
+
}
|
|
355
|
+
})))
|
|
356
|
+
]);
|
|
357
|
+
const content = h("div", { class: "ee-content" }, [
|
|
358
|
+
h("div", { class: "ee-content-search" }, [
|
|
359
|
+
h("input", {
|
|
360
|
+
class: "pd-input",
|
|
361
|
+
placeholder: getPlaceholder()[state.activeTab],
|
|
362
|
+
onInput: (ev) => {
|
|
363
|
+
state.searchText = ev.target.value;
|
|
364
|
+
repaint(scope(ev));
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
]),
|
|
368
|
+
h("div", { class: "ee-content-list" }, listItems())
|
|
369
|
+
]);
|
|
370
|
+
const initialPreview = previewText(state.expression, opts.demoData);
|
|
371
|
+
const editor = h("div", { class: "ee-editor" }, [
|
|
372
|
+
h("div", { class: "ee-editor-section" }, [
|
|
373
|
+
h("div", { class: "ee-editor-title", text: tr("expression.k30") }),
|
|
374
|
+
h("textarea", {
|
|
375
|
+
class: "ee-textarea",
|
|
376
|
+
rows: 6,
|
|
377
|
+
placeholder: tr("expression.k31"),
|
|
378
|
+
text: state.expression,
|
|
379
|
+
onInput: (ev) => {
|
|
380
|
+
state.expression = ev.target.value;
|
|
381
|
+
state.keyHint = "";
|
|
382
|
+
updatePreview(scope(ev));
|
|
383
|
+
updateKeyHint(scope(ev));
|
|
384
|
+
}
|
|
385
|
+
}),
|
|
386
|
+
h("div", {
|
|
387
|
+
class: "pd-hint ee-key-hint",
|
|
388
|
+
style: { display: "none", color: "var(--pd-accent, #165DFF)" },
|
|
389
|
+
text: ""
|
|
390
|
+
})
|
|
391
|
+
]),
|
|
392
|
+
h("div", { class: "ee-editor-section" }, [
|
|
393
|
+
h("div", { class: "ee-editor-title", text: tr("expression.k32") }),
|
|
394
|
+
h("div", {
|
|
395
|
+
class: `ee-preview${initialPreview === tr(ERROR_PREVIEW_KEY) ? " ee-preview-error" : ""}`,
|
|
396
|
+
text: initialPreview
|
|
397
|
+
})
|
|
398
|
+
]),
|
|
399
|
+
helpSection()
|
|
400
|
+
]);
|
|
401
|
+
return h("div", {
|
|
402
|
+
class: "pd-dialog-overlay",
|
|
403
|
+
onKeydown: (ev) => {
|
|
404
|
+
if (ev.key === "Escape") opts.onClose();
|
|
405
|
+
}
|
|
406
|
+
}, [
|
|
407
|
+
h("section", {
|
|
408
|
+
class: "pd-dialog pd-dialog-large",
|
|
409
|
+
role: "dialog",
|
|
410
|
+
"aria-modal": "true",
|
|
411
|
+
"aria-labelledby": "expression-editor-title"
|
|
412
|
+
}, [
|
|
413
|
+
h("header", { class: "pd-dialog-header" }, [
|
|
414
|
+
h("strong", { id: "expression-editor-title", text: tr("expression.k33") }),
|
|
415
|
+
h("button", { type: "button", class: "pd-close", "aria-label": tr("expression.k34"), text: "\xD7", onClick: () => opts.onClose() })
|
|
416
|
+
]),
|
|
417
|
+
h("div", { class: "expression-editor" }, [nav, content, editor]),
|
|
418
|
+
h("footer", { class: "pd-dialog-footer" }, [
|
|
419
|
+
h("button", { type: "button", class: "pd-button", text: tr("expression.k35"), onClick: () => opts.onClose() }),
|
|
420
|
+
h("button", { type: "button", class: "pd-button primary", text: tr("expression.k36"), onClick: () => onConfirm() })
|
|
421
|
+
])
|
|
422
|
+
])
|
|
423
|
+
]);
|
|
424
|
+
}
|
|
425
|
+
export {
|
|
426
|
+
normalizeFieldDisplay,
|
|
427
|
+
renderExpressionEditor
|
|
428
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
23
|
TOOLBAR_OVERFLOW_KEY: () => TOOLBAR_OVERFLOW_KEY,
|
|
24
24
|
clearElementUIs: () => clearElementUIs,
|
|
25
25
|
defineElementUI: () => defineElementUI,
|
|
@@ -27,12 +27,14 @@ __export(index_exports, {
|
|
|
27
27
|
getElementUIEntries: () => getElementUIEntries,
|
|
28
28
|
getElementUITypes: () => getElementUITypes,
|
|
29
29
|
getElementUIs: () => getElementUIs,
|
|
30
|
+
getMissingKeys: () => import_i18n2.getMissingKeys,
|
|
30
31
|
registerElementUI: () => registerElementUI,
|
|
31
32
|
subscribeElementUIRegistry: () => subscribeElementUIRegistry
|
|
32
33
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
35
|
|
|
35
36
|
// src/registry.ts
|
|
37
|
+
var import_i18n = require("@worm-print-platform/core/i18n");
|
|
36
38
|
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("worm-print-platform.element-ui-registry.v1");
|
|
37
39
|
var host = globalThis;
|
|
38
40
|
function state() {
|
|
@@ -66,6 +68,22 @@ function assertElementUI(ui) {
|
|
|
66
68
|
if (ui.renderProperty !== void 0 && typeof ui.renderProperty !== "function") {
|
|
67
69
|
throw new Error(`registerElementUI: ${ui.types.join(",")} \u7684 renderProperty \u5FC5\u987B\u662F\u51FD\u6570`);
|
|
68
70
|
}
|
|
71
|
+
if (ui.locales !== void 0) {
|
|
72
|
+
if (typeof ui.locales !== "object" || ui.locales === null) {
|
|
73
|
+
throw new Error("registerElementUI: locales \u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
74
|
+
}
|
|
75
|
+
const prefix = `${ui.i18nId ?? ui.types[0]}.`;
|
|
76
|
+
for (const messages of Object.values(ui.locales)) {
|
|
77
|
+
if (typeof messages !== "object" || messages === null) {
|
|
78
|
+
throw new Error("registerElementUI: locales \u7684\u6BCF\u4E2A\u8BED\u8A00\u5305\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
79
|
+
}
|
|
80
|
+
for (const key of Object.keys(messages)) {
|
|
81
|
+
if (!key.startsWith(prefix)) {
|
|
82
|
+
throw new Error(`registerElementUI: \u8BED\u8A00\u5305\u952E\u5FC5\u987B\u4EE5 "${prefix}" \u5F00\u5934\uFF0C\u6536\u5230 "${key}"`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
69
87
|
}
|
|
70
88
|
function defineElementUI(ui) {
|
|
71
89
|
assertElementUI(ui);
|
|
@@ -75,9 +93,12 @@ function registerElementUI(ui) {
|
|
|
75
93
|
assertElementUI(ui);
|
|
76
94
|
const s = state();
|
|
77
95
|
const seq = s.nextSeq++;
|
|
78
|
-
|
|
96
|
+
const pluginId = ui.i18nId ?? ui.types[0];
|
|
97
|
+
const disposeLocales = ui.locales ? Object.entries(ui.locales).map(([locale, messages]) => (0, import_i18n.registerPluginMessages)(locale, pluginId, messages)) : [];
|
|
98
|
+
for (const type of ui.types) s.entries.set(type, { ui, seq, disposeLocales });
|
|
79
99
|
notify();
|
|
80
100
|
return () => {
|
|
101
|
+
for (const dispose of disposeLocales) dispose();
|
|
81
102
|
let removed = false;
|
|
82
103
|
for (const type of ui.types) {
|
|
83
104
|
const current = s.entries.get(type);
|
|
@@ -120,12 +141,23 @@ function subscribeElementUIRegistry(listener) {
|
|
|
120
141
|
function clearElementUIs() {
|
|
121
142
|
const s = state();
|
|
122
143
|
if (s.entries.size === 0 && s.listeners.size === 0) return;
|
|
144
|
+
const disposed = /* @__PURE__ */ new Set();
|
|
145
|
+
for (const entry of s.entries.values()) {
|
|
146
|
+
for (const dispose of entry.disposeLocales ?? []) {
|
|
147
|
+
if (disposed.has(dispose)) continue;
|
|
148
|
+
disposed.add(dispose);
|
|
149
|
+
dispose();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
123
152
|
s.entries.clear();
|
|
124
153
|
notify();
|
|
125
154
|
}
|
|
126
155
|
|
|
127
156
|
// src/toolbar-overflow-key.ts
|
|
128
157
|
var TOOLBAR_OVERFLOW_KEY = /* @__PURE__ */ Symbol.for("worm-print-platform.toolbar-overflow.v1");
|
|
158
|
+
|
|
159
|
+
// src/index.ts
|
|
160
|
+
var import_i18n2 = require("@worm-print-platform/core/i18n");
|
|
129
161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
130
162
|
0 && (module.exports = {
|
|
131
163
|
TOOLBAR_OVERFLOW_KEY,
|
|
@@ -135,6 +167,7 @@ var TOOLBAR_OVERFLOW_KEY = /* @__PURE__ */ Symbol.for("worm-print-platform.toolb
|
|
|
135
167
|
getElementUIEntries,
|
|
136
168
|
getElementUITypes,
|
|
137
169
|
getElementUIs,
|
|
170
|
+
getMissingKeys,
|
|
138
171
|
registerElementUI,
|
|
139
172
|
subscribeElementUIRegistry
|
|
140
173
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @worm-print-platform/plugin-kit v1.
|
|
2
|
+
* @worm-print-platform/plugin-kit v1.6.1
|
|
3
3
|
* Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
|
|
4
4
|
* SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
|
|
5
5
|
* SPDX-License-Identifier: MIT
|
|
6
6
|
*/
|
|
7
7
|
import { RuntimeElement, PrintBusinessField, ElementOptions } from '@worm-print-platform/core/designer';
|
|
8
|
+
import { Translate } from '@worm-print-platform/core/i18n';
|
|
9
|
+
export { Translate, getMissingKeys } from '@worm-print-platform/core/i18n';
|
|
8
10
|
|
|
9
11
|
/** 插件产出的可视内容:HTML 字符串或真实 DOM 节点 */
|
|
10
12
|
type ElementUINode = string | Node;
|
|
@@ -21,6 +23,8 @@ interface ElementUICanvasContext {
|
|
|
21
23
|
data?: readonly Record<string, unknown>[];
|
|
22
24
|
/** 设计态为 true;宿主未来做只读预览时可传 false */
|
|
23
25
|
designMode?: boolean;
|
|
26
|
+
/** 当前 locale 的翻译函数;缺省用全局 t */
|
|
27
|
+
t?: Translate;
|
|
24
28
|
}
|
|
25
29
|
/**
|
|
26
30
|
* 属性台「自定义属性」渲染上下文。
|
|
@@ -40,6 +44,8 @@ interface ElementUIPropertyContext {
|
|
|
40
44
|
update(partial: Partial<ElementOptions>): void;
|
|
41
45
|
/** 仅请求宿主重绘,不写数据、不记历史(面板内部态变化用) */
|
|
42
46
|
repaint(): void;
|
|
47
|
+
/** 当前 locale 的翻译函数;缺省用全局 t */
|
|
48
|
+
t?: Translate;
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
51
|
* 一份插件设计器 UI,可覆盖同一插件的多个元素类型。
|
|
@@ -60,6 +66,10 @@ interface ElementUI {
|
|
|
60
66
|
readonly searchKeywords?: readonly string[];
|
|
61
67
|
/** 宿主注入到自身样式作用域:common 注入 Shadow DOM,canvas 注入 document.head */
|
|
62
68
|
readonly styles?: string;
|
|
69
|
+
/** 语言包键前缀(插件 id);缺省取 types[0] */
|
|
70
|
+
readonly i18nId?: string;
|
|
71
|
+
/** 按 locale 提供的语言包;注册时合并进 core 引擎的插件层 */
|
|
72
|
+
readonly locales?: Record<string, Record<string, string>>;
|
|
63
73
|
}
|
|
64
74
|
/** 类型→UI 的解析视图(供宿主遍历注册态) */
|
|
65
75
|
interface ElementUIEntry {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @worm-print-platform/plugin-kit v1.
|
|
2
|
+
* @worm-print-platform/plugin-kit v1.6.1
|
|
3
3
|
* Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
|
|
4
4
|
* SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
|
|
5
5
|
* SPDX-License-Identifier: MIT
|
|
6
6
|
*/
|
|
7
7
|
import { RuntimeElement, PrintBusinessField, ElementOptions } from '@worm-print-platform/core/designer';
|
|
8
|
+
import { Translate } from '@worm-print-platform/core/i18n';
|
|
9
|
+
export { Translate, getMissingKeys } from '@worm-print-platform/core/i18n';
|
|
8
10
|
|
|
9
11
|
/** 插件产出的可视内容:HTML 字符串或真实 DOM 节点 */
|
|
10
12
|
type ElementUINode = string | Node;
|
|
@@ -21,6 +23,8 @@ interface ElementUICanvasContext {
|
|
|
21
23
|
data?: readonly Record<string, unknown>[];
|
|
22
24
|
/** 设计态为 true;宿主未来做只读预览时可传 false */
|
|
23
25
|
designMode?: boolean;
|
|
26
|
+
/** 当前 locale 的翻译函数;缺省用全局 t */
|
|
27
|
+
t?: Translate;
|
|
24
28
|
}
|
|
25
29
|
/**
|
|
26
30
|
* 属性台「自定义属性」渲染上下文。
|
|
@@ -40,6 +44,8 @@ interface ElementUIPropertyContext {
|
|
|
40
44
|
update(partial: Partial<ElementOptions>): void;
|
|
41
45
|
/** 仅请求宿主重绘,不写数据、不记历史(面板内部态变化用) */
|
|
42
46
|
repaint(): void;
|
|
47
|
+
/** 当前 locale 的翻译函数;缺省用全局 t */
|
|
48
|
+
t?: Translate;
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
51
|
* 一份插件设计器 UI,可覆盖同一插件的多个元素类型。
|
|
@@ -60,6 +66,10 @@ interface ElementUI {
|
|
|
60
66
|
readonly searchKeywords?: readonly string[];
|
|
61
67
|
/** 宿主注入到自身样式作用域:common 注入 Shadow DOM,canvas 注入 document.head */
|
|
62
68
|
readonly styles?: string;
|
|
69
|
+
/** 语言包键前缀(插件 id);缺省取 types[0] */
|
|
70
|
+
readonly i18nId?: string;
|
|
71
|
+
/** 按 locale 提供的语言包;注册时合并进 core 引擎的插件层 */
|
|
72
|
+
readonly locales?: Record<string, Record<string, string>>;
|
|
63
73
|
}
|
|
64
74
|
/** 类型→UI 的解析视图(供宿主遍历注册态) */
|
|
65
75
|
interface ElementUIEntry {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/registry.ts
|
|
2
|
+
import { registerPluginMessages } from "@worm-print-platform/core/i18n";
|
|
2
3
|
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("worm-print-platform.element-ui-registry.v1");
|
|
3
4
|
var host = globalThis;
|
|
4
5
|
function state() {
|
|
@@ -32,6 +33,22 @@ function assertElementUI(ui) {
|
|
|
32
33
|
if (ui.renderProperty !== void 0 && typeof ui.renderProperty !== "function") {
|
|
33
34
|
throw new Error(`registerElementUI: ${ui.types.join(",")} \u7684 renderProperty \u5FC5\u987B\u662F\u51FD\u6570`);
|
|
34
35
|
}
|
|
36
|
+
if (ui.locales !== void 0) {
|
|
37
|
+
if (typeof ui.locales !== "object" || ui.locales === null) {
|
|
38
|
+
throw new Error("registerElementUI: locales \u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
39
|
+
}
|
|
40
|
+
const prefix = `${ui.i18nId ?? ui.types[0]}.`;
|
|
41
|
+
for (const messages of Object.values(ui.locales)) {
|
|
42
|
+
if (typeof messages !== "object" || messages === null) {
|
|
43
|
+
throw new Error("registerElementUI: locales \u7684\u6BCF\u4E2A\u8BED\u8A00\u5305\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
44
|
+
}
|
|
45
|
+
for (const key of Object.keys(messages)) {
|
|
46
|
+
if (!key.startsWith(prefix)) {
|
|
47
|
+
throw new Error(`registerElementUI: \u8BED\u8A00\u5305\u952E\u5FC5\u987B\u4EE5 "${prefix}" \u5F00\u5934\uFF0C\u6536\u5230 "${key}"`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
35
52
|
}
|
|
36
53
|
function defineElementUI(ui) {
|
|
37
54
|
assertElementUI(ui);
|
|
@@ -41,9 +58,12 @@ function registerElementUI(ui) {
|
|
|
41
58
|
assertElementUI(ui);
|
|
42
59
|
const s = state();
|
|
43
60
|
const seq = s.nextSeq++;
|
|
44
|
-
|
|
61
|
+
const pluginId = ui.i18nId ?? ui.types[0];
|
|
62
|
+
const disposeLocales = ui.locales ? Object.entries(ui.locales).map(([locale, messages]) => registerPluginMessages(locale, pluginId, messages)) : [];
|
|
63
|
+
for (const type of ui.types) s.entries.set(type, { ui, seq, disposeLocales });
|
|
45
64
|
notify();
|
|
46
65
|
return () => {
|
|
66
|
+
for (const dispose of disposeLocales) dispose();
|
|
47
67
|
let removed = false;
|
|
48
68
|
for (const type of ui.types) {
|
|
49
69
|
const current = s.entries.get(type);
|
|
@@ -86,12 +106,23 @@ function subscribeElementUIRegistry(listener) {
|
|
|
86
106
|
function clearElementUIs() {
|
|
87
107
|
const s = state();
|
|
88
108
|
if (s.entries.size === 0 && s.listeners.size === 0) return;
|
|
109
|
+
const disposed = /* @__PURE__ */ new Set();
|
|
110
|
+
for (const entry of s.entries.values()) {
|
|
111
|
+
for (const dispose of entry.disposeLocales ?? []) {
|
|
112
|
+
if (disposed.has(dispose)) continue;
|
|
113
|
+
disposed.add(dispose);
|
|
114
|
+
dispose();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
89
117
|
s.entries.clear();
|
|
90
118
|
notify();
|
|
91
119
|
}
|
|
92
120
|
|
|
93
121
|
// src/toolbar-overflow-key.ts
|
|
94
122
|
var TOOLBAR_OVERFLOW_KEY = /* @__PURE__ */ Symbol.for("worm-print-platform.toolbar-overflow.v1");
|
|
123
|
+
|
|
124
|
+
// src/index.ts
|
|
125
|
+
import { getMissingKeys } from "@worm-print-platform/core/i18n";
|
|
95
126
|
export {
|
|
96
127
|
TOOLBAR_OVERFLOW_KEY,
|
|
97
128
|
clearElementUIs,
|
|
@@ -100,6 +131,7 @@ export {
|
|
|
100
131
|
getElementUIEntries,
|
|
101
132
|
getElementUITypes,
|
|
102
133
|
getElementUIs,
|
|
134
|
+
getMissingKeys,
|
|
103
135
|
registerElementUI,
|
|
104
136
|
subscribeElementUIRegistry
|
|
105
137
|
};
|