@worm-print-platform/plugin-kit 1.6.4 → 1.6.5

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 CHANGED
@@ -4,7 +4,7 @@
4
4
  </p>
5
5
 
6
6
  <p align="center">
7
- <img src="https://img.shields.io/badge/npm-v1.6.4-384BFF" alt="npm">
7
+ <img src="https://img.shields.io/badge/npm-v1.6.5-384BFF" alt="npm">
8
8
  <img src="https://img.shields.io/badge/license-MIT-9A9A9A" alt="license">
9
9
  </p>
10
10
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/plugin-kit v1.6.4
2
+ * @worm-print-platform/plugin-kit v1.6.5
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
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/plugin-kit v1.6.4
2
+ * @worm-print-platform/plugin-kit v1.6.5
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
package/dist/dom.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/plugin-kit v1.6.4
2
+ * @worm-print-platform/plugin-kit v1.6.5
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
package/dist/dom.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/plugin-kit v1.6.4
2
+ * @worm-print-platform/plugin-kit v1.6.5
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
@@ -92,12 +92,13 @@ function normalizeFieldDisplay(v) {
92
92
  const s = typeof v === "string" ? v.trim().toLowerCase() : "";
93
93
  return s === "label" || s === "key" || s === "both" ? s : "both";
94
94
  }
95
- function getTabs() {
96
- return [
95
+ function getTabs(fieldOnly = false) {
96
+ const tabs = [
97
97
  { key: "field", text: tr("expression.tabField") },
98
98
  { key: "variable", text: tr("expression.tabVariable") },
99
99
  { key: "function", text: tr("expression.tabFunction") }
100
100
  ];
101
+ return fieldOnly ? tabs.slice(0, 1) : tabs;
101
102
  }
102
103
  function getPlaceholder() {
103
104
  return {
@@ -312,7 +313,22 @@ function renderExpressionEditor(opts, target) {
312
313
  nodes.push(h("div", {
313
314
  class: "ee-list-item ee-field-item",
314
315
  style: { paddingLeft: group.key ? "22px" : "10px" },
316
+ onClick: (ev) => {
317
+ if (!target.fieldOnly) return;
318
+ state.expression = `{${field.fieldKey}}`;
319
+ const root = scope(ev);
320
+ const textarea = query(root, ".ee-textarea");
321
+ if (textarea) {
322
+ textarea.value = state.expression;
323
+ textarea.focus();
324
+ textarea.selectionStart = textarea.selectionEnd = state.expression.length;
325
+ }
326
+ state.keyHint = hasChineseKey(field.fieldKey) ? chineseKeyHint(field.fieldKey) : "";
327
+ updatePreview(root);
328
+ updateKeyHint(root);
329
+ },
315
330
  onDblclick: (ev) => {
331
+ if (target.fieldOnly) return;
316
332
  const { insideParens } = region(ev);
317
333
  const mod = ev;
318
334
  if (mod.ctrlKey || mod.metaKey) {
@@ -350,7 +366,7 @@ function renderExpressionEditor(opts, target) {
350
366
  };
351
367
  const repaint = (root) => {
352
368
  const tabs = Array.from(root.querySelectorAll(".ee-nav-tab"));
353
- tabs.forEach((el, i) => el.classList.toggle("active", getTabs()[i]?.key === state.activeTab));
369
+ tabs.forEach((el, i) => el.classList.toggle("active", getTabs(target.fieldOnly)[i]?.key === state.activeTab));
354
370
  const search = query(root, ".ee-content-search .pd-input");
355
371
  if (search) {
356
372
  const placeholder = getPlaceholder()[state.activeTab];
@@ -417,11 +433,11 @@ function renderExpressionEditor(opts, target) {
417
433
  };
418
434
  const nav = h("div", { class: "ee-nav" }, [
419
435
  h("div", { class: "ee-nav-title", text: tr("expression.k29") }),
420
- h("div", { class: "ee-nav-tabs" }, getTabs().map((tab, i) => h("div", {
436
+ h("div", { class: "ee-nav-tabs" }, getTabs(target.fieldOnly).map((tab, i) => h("div", {
421
437
  class: `ee-nav-tab${state.activeTab === tab.key ? " active" : ""}`,
422
438
  text: tab.text,
423
439
  onClick: (ev) => {
424
- state.activeTab = getTabs()[i].key;
440
+ state.activeTab = getTabs(target.fieldOnly)[i].key;
425
441
  repaint(scope(ev));
426
442
  }
427
443
  })))
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/plugin-kit v1.6.4
2
+ * @worm-print-platform/plugin-kit v1.6.5
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
@@ -17,6 +17,10 @@ interface ExpressionEditorTarget {
17
17
  value: string;
18
18
  /** 可选:字段绑定模式的初始字段 key */
19
19
  binding?: string;
20
+ /** 仅显示字段页签,用于图表等只需选择字段的场景 */
21
+ fieldOnly?: boolean;
22
+ /** 可选字段清单;缺省使用宿主完整业务字段 */
23
+ fields?: readonly PrintBusinessField[];
20
24
  }
21
25
  /** 字段行显示模式:中文名 / key / 两者(默认 both,保持既有行为) */
22
26
  type FieldDisplayMode = 'label' | 'key' | 'both';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/plugin-kit v1.6.4
2
+ * @worm-print-platform/plugin-kit v1.6.5
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
@@ -17,6 +17,10 @@ interface ExpressionEditorTarget {
17
17
  value: string;
18
18
  /** 可选:字段绑定模式的初始字段 key */
19
19
  binding?: string;
20
+ /** 仅显示字段页签,用于图表等只需选择字段的场景 */
21
+ fieldOnly?: boolean;
22
+ /** 可选字段清单;缺省使用宿主完整业务字段 */
23
+ fields?: readonly PrintBusinessField[];
20
24
  }
21
25
  /** 字段行显示模式:中文名 / key / 两者(默认 both,保持既有行为) */
22
26
  type FieldDisplayMode = 'label' | 'key' | 'both';
@@ -20,12 +20,13 @@ function normalizeFieldDisplay(v) {
20
20
  const s = typeof v === "string" ? v.trim().toLowerCase() : "";
21
21
  return s === "label" || s === "key" || s === "both" ? s : "both";
22
22
  }
23
- function getTabs() {
24
- return [
23
+ function getTabs(fieldOnly = false) {
24
+ const tabs = [
25
25
  { key: "field", text: tr("expression.tabField") },
26
26
  { key: "variable", text: tr("expression.tabVariable") },
27
27
  { key: "function", text: tr("expression.tabFunction") }
28
28
  ];
29
+ return fieldOnly ? tabs.slice(0, 1) : tabs;
29
30
  }
30
31
  function getPlaceholder() {
31
32
  return {
@@ -240,7 +241,22 @@ function renderExpressionEditor(opts, target) {
240
241
  nodes.push(h("div", {
241
242
  class: "ee-list-item ee-field-item",
242
243
  style: { paddingLeft: group.key ? "22px" : "10px" },
244
+ onClick: (ev) => {
245
+ if (!target.fieldOnly) return;
246
+ state.expression = `{${field.fieldKey}}`;
247
+ const root = scope(ev);
248
+ const textarea = query(root, ".ee-textarea");
249
+ if (textarea) {
250
+ textarea.value = state.expression;
251
+ textarea.focus();
252
+ textarea.selectionStart = textarea.selectionEnd = state.expression.length;
253
+ }
254
+ state.keyHint = hasChineseKey(field.fieldKey) ? chineseKeyHint(field.fieldKey) : "";
255
+ updatePreview(root);
256
+ updateKeyHint(root);
257
+ },
243
258
  onDblclick: (ev) => {
259
+ if (target.fieldOnly) return;
244
260
  const { insideParens } = region(ev);
245
261
  const mod = ev;
246
262
  if (mod.ctrlKey || mod.metaKey) {
@@ -278,7 +294,7 @@ function renderExpressionEditor(opts, target) {
278
294
  };
279
295
  const repaint = (root) => {
280
296
  const tabs = Array.from(root.querySelectorAll(".ee-nav-tab"));
281
- tabs.forEach((el, i) => el.classList.toggle("active", getTabs()[i]?.key === state.activeTab));
297
+ tabs.forEach((el, i) => el.classList.toggle("active", getTabs(target.fieldOnly)[i]?.key === state.activeTab));
282
298
  const search = query(root, ".ee-content-search .pd-input");
283
299
  if (search) {
284
300
  const placeholder = getPlaceholder()[state.activeTab];
@@ -345,11 +361,11 @@ function renderExpressionEditor(opts, target) {
345
361
  };
346
362
  const nav = h("div", { class: "ee-nav" }, [
347
363
  h("div", { class: "ee-nav-title", text: tr("expression.k29") }),
348
- h("div", { class: "ee-nav-tabs" }, getTabs().map((tab, i) => h("div", {
364
+ h("div", { class: "ee-nav-tabs" }, getTabs(target.fieldOnly).map((tab, i) => h("div", {
349
365
  class: `ee-nav-tab${state.activeTab === tab.key ? " active" : ""}`,
350
366
  text: tab.text,
351
367
  onClick: (ev) => {
352
- state.activeTab = getTabs()[i].key;
368
+ state.activeTab = getTabs(target.fieldOnly)[i].key;
353
369
  repaint(scope(ev));
354
370
  }
355
371
  })))
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/plugin-kit v1.6.4
2
+ * @worm-print-platform/plugin-kit v1.6.5
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
@@ -7,6 +7,8 @@
7
7
  import { RuntimeElement, PrintBusinessField, ElementOptions } from '@worm-print-platform/core/designer';
8
8
  import { Translate } from '@worm-print-platform/core/i18n';
9
9
  export { Translate, getMissingKeys } from '@worm-print-platform/core/i18n';
10
+ import { ExpressionEditorTarget } from './expression-editor.cjs';
11
+ import './dom.cjs';
10
12
 
11
13
  /** 插件产出的可视内容:HTML 字符串或真实 DOM 节点 */
12
14
  type ElementUINode = string | Node;
@@ -36,7 +38,7 @@ interface ElementUIPropertyContext {
36
38
  data?: readonly Record<string, unknown>[];
37
39
  /**
38
40
  * 宿主的业务字段清单(fieldKey / fieldLabel / fieldType)。
39
- * 图表类插件据此生成「数据源 / 类目 / 数值字段」下拉,不必再从 demo 数据的键里猜;
41
+ * 图表类插件据此生成「数据源 / 类目 / 数值字段」选择器,不必再从 demo 数据的键里猜;
40
42
  * 未注入时为 undefined 或空数组,插件应自行回落到 data[0] 的键。
41
43
  */
42
44
  fields?: readonly PrintBusinessField[];
@@ -46,6 +48,12 @@ interface ElementUIPropertyContext {
46
48
  repaint(): void;
47
49
  /** 当前 locale 的翻译函数;缺省用全局 t */
48
50
  t?: Translate;
51
+ /** 必填:请求宿主打开表达式编辑器;图表等字段选择场景可限制为字段页签(无下拉框回退) */
52
+ openExpression: (target: ExpressionEditorTarget, onApply: (next: {
53
+ formatter?: string;
54
+ binding?: string;
55
+ title?: string;
56
+ }) => void) => void;
49
57
  }
50
58
  /**
51
59
  * 一份插件设计器 UI,可覆盖同一插件的多个元素类型。
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/plugin-kit v1.6.4
2
+ * @worm-print-platform/plugin-kit v1.6.5
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
@@ -7,6 +7,8 @@
7
7
  import { RuntimeElement, PrintBusinessField, ElementOptions } from '@worm-print-platform/core/designer';
8
8
  import { Translate } from '@worm-print-platform/core/i18n';
9
9
  export { Translate, getMissingKeys } from '@worm-print-platform/core/i18n';
10
+ import { ExpressionEditorTarget } from './expression-editor.js';
11
+ import './dom.js';
10
12
 
11
13
  /** 插件产出的可视内容:HTML 字符串或真实 DOM 节点 */
12
14
  type ElementUINode = string | Node;
@@ -36,7 +38,7 @@ interface ElementUIPropertyContext {
36
38
  data?: readonly Record<string, unknown>[];
37
39
  /**
38
40
  * 宿主的业务字段清单(fieldKey / fieldLabel / fieldType)。
39
- * 图表类插件据此生成「数据源 / 类目 / 数值字段」下拉,不必再从 demo 数据的键里猜;
41
+ * 图表类插件据此生成「数据源 / 类目 / 数值字段」选择器,不必再从 demo 数据的键里猜;
40
42
  * 未注入时为 undefined 或空数组,插件应自行回落到 data[0] 的键。
41
43
  */
42
44
  fields?: readonly PrintBusinessField[];
@@ -46,6 +48,12 @@ interface ElementUIPropertyContext {
46
48
  repaint(): void;
47
49
  /** 当前 locale 的翻译函数;缺省用全局 t */
48
50
  t?: Translate;
51
+ /** 必填:请求宿主打开表达式编辑器;图表等字段选择场景可限制为字段页签(无下拉框回退) */
52
+ openExpression: (target: ExpressionEditorTarget, onApply: (next: {
53
+ formatter?: string;
54
+ binding?: string;
55
+ title?: string;
56
+ }) => void) => void;
49
57
  }
50
58
  /**
51
59
  * 一份插件设计器 UI,可覆盖同一插件的多个元素类型。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worm-print-platform/plugin-kit",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "type": "module",
5
5
  "description": "打印模板自定义元素的框架无关设计器 UI 契约与注册表:插件写一份 DOM 渲染能力,canvas(原生)与 /vue3(门面)同时消费",
6
6
  "main": "./dist/index.cjs",
@@ -51,7 +51,7 @@
51
51
  "test:watch": "vitest"
52
52
  },
53
53
  "dependencies": {
54
- "@worm-print-platform/core": "^1.6.4"
54
+ "@worm-print-platform/core": "^1.6.5"
55
55
  },
56
56
  "devDependencies": {
57
57
  "happy-dom": "^20.10.6",