@guodun/antdv 1.4.4 → 1.4.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.
Files changed (93) hide show
  1. package/dist/es/components/contract-signing-location/src/ContractSigningLocation.vue.mjs +85 -85
  2. package/dist/es/components/dept-selector/src/dept.mjs +170 -142
  3. package/dist/es/components/index.mjs +1 -0
  4. package/dist/es/components/pro-contract-template-designer/index.mjs +1 -0
  5. package/dist/es/components/pro-contract-template-designer/src/ContractTemplateDesignerInspector.vue.mjs +372 -185
  6. package/dist/es/components/pro-contract-template-designer/src/ContractTemplateDesignerWorkspaceHeader.vue.mjs +59 -42
  7. package/dist/es/components/pro-contract-template-designer/src/ContractTemplateRendererField.vue.mjs +218 -85
  8. package/dist/es/components/pro-contract-template-designer/src/ContractTemplateVariableDataModal.mjs +5 -0
  9. package/dist/es/components/pro-contract-template-designer/src/ContractTemplateVariableDataModal.vue.mjs +97 -0
  10. package/dist/es/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.mjs +914 -853
  11. package/dist/es/components/pro-contract-template-designer/src/ProContractTemplateRenderer.vue.mjs +550 -245
  12. package/dist/es/components/pro-contract-template-designer/src/composables/use-template-designer.mjs +214 -139
  13. package/dist/es/components/pro-contract-template-designer/src/extensions/template-variable.mjs +53 -35
  14. package/dist/es/components/pro-contract-template-designer/src/types.mjs +15 -2
  15. package/dist/es/components/pro-contract-template-designer/src/utils/advanced-controls.mjs +91 -0
  16. package/dist/es/components/pro-contract-template-designer/src/utils/template-renderer.mjs +96 -65
  17. package/dist/es/components/pro-contract-template-designer/src/utils/template-tool-icons.mjs +23 -16
  18. package/dist/es/components/pro-contract-template-designer/style/index.css +1 -1
  19. package/dist/es/components/pro-selector/src/components/org-tree.mjs +130 -89
  20. package/dist/es/components/pro-selector/src/components/user.mjs +34 -26
  21. package/dist/es/components/pro-selector/src/pro-user.mjs +86 -72
  22. package/dist/es/components/pro-selector/src/types.mjs +4 -1
  23. package/dist/es/components/pro-selector/src/utils/orgTree.mjs +5 -2
  24. package/dist/es/components/pro-selector-group/src/compoents/dept-tree.vue.mjs +92 -65
  25. package/dist/es/components/pro-selector-group/src/compoents/dept.vue.mjs +3 -3
  26. package/dist/es/components/pro-selector-group/src/compoents/role.vue.mjs +98 -73
  27. package/dist/es/components/pro-selector-group/src/compoents/select-box.vue.mjs +12 -9
  28. package/dist/es/components/pro-selector-group/src/compoents/user.vue.mjs +101 -72
  29. package/dist/es/components/pro-selector-group/src/hooks/useApi.mjs +39 -22
  30. package/dist/es/components/pro-selector-group/src/index.vue.mjs +105 -83
  31. package/dist/es/components/pro-selector-group/src/utils/index.mjs +36 -0
  32. package/dist/es/components/role-selector/src/role.mjs +134 -120
  33. package/dist/es/index.mjs +50 -49
  34. package/dist/lib/components/contract-signing-location/src/ContractSigningLocation.vue.cjs +1 -1
  35. package/dist/lib/components/dept-selector/src/dept.cjs +1 -1
  36. package/dist/lib/components/index.cjs +1 -1
  37. package/dist/lib/components/pro-contract-template-designer/index.cjs +1 -1
  38. package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateDesignerInspector.vue.cjs +2 -1
  39. package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateDesignerWorkspaceHeader.vue.cjs +1 -1
  40. package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateRendererField.vue.cjs +1 -1
  41. package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateVariableDataModal.cjs +1 -0
  42. package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateVariableDataModal.vue.cjs +1 -0
  43. package/dist/lib/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.cjs +1 -1
  44. package/dist/lib/components/pro-contract-template-designer/src/ProContractTemplateRenderer.vue.cjs +1 -1
  45. package/dist/lib/components/pro-contract-template-designer/src/composables/use-template-designer.cjs +4 -4
  46. package/dist/lib/components/pro-contract-template-designer/src/extensions/template-variable.cjs +1 -1
  47. package/dist/lib/components/pro-contract-template-designer/src/types.cjs +1 -1
  48. package/dist/lib/components/pro-contract-template-designer/src/utils/advanced-controls.cjs +1 -0
  49. package/dist/lib/components/pro-contract-template-designer/src/utils/template-renderer.cjs +3 -3
  50. package/dist/lib/components/pro-contract-template-designer/src/utils/template-tool-icons.cjs +1 -1
  51. package/dist/lib/components/pro-contract-template-designer/style/index.css +1 -1
  52. package/dist/lib/components/pro-selector/src/components/org-tree.cjs +1 -1
  53. package/dist/lib/components/pro-selector/src/components/user.cjs +1 -1
  54. package/dist/lib/components/pro-selector/src/pro-user.cjs +1 -1
  55. package/dist/lib/components/pro-selector/src/types.cjs +1 -1
  56. package/dist/lib/components/pro-selector/src/utils/orgTree.cjs +1 -1
  57. package/dist/lib/components/pro-selector-group/src/compoents/dept-tree.vue.cjs +1 -1
  58. package/dist/lib/components/pro-selector-group/src/compoents/dept.vue.cjs +1 -1
  59. package/dist/lib/components/pro-selector-group/src/compoents/role.vue.cjs +1 -1
  60. package/dist/lib/components/pro-selector-group/src/compoents/select-box.vue.cjs +1 -1
  61. package/dist/lib/components/pro-selector-group/src/compoents/user.vue.cjs +1 -1
  62. package/dist/lib/components/pro-selector-group/src/hooks/useApi.cjs +1 -1
  63. package/dist/lib/components/pro-selector-group/src/index.vue.cjs +1 -1
  64. package/dist/lib/components/pro-selector-group/src/utils/index.cjs +1 -0
  65. package/dist/lib/components/role-selector/src/role.cjs +1 -1
  66. package/dist/lib/index.cjs +1 -1
  67. package/dist/theme/dept-selector.css +1 -1
  68. package/dist/theme/icon.css +1 -1
  69. package/dist/theme/index.css +1 -1
  70. package/dist/theme/pro-selector-group.css +1 -1
  71. package/dist/theme/pro-selector.css +1 -1
  72. package/dist/theme/role-selector.css +1 -1
  73. package/dist/types/components/contract-signing-location/src/ContractSigningLocation.vue.d.ts +3 -3
  74. package/dist/types/components/pro-contract-template-designer/index.d.ts +1 -0
  75. package/dist/types/components/pro-contract-template-designer/src/ContractTemplateDesignerInspector.vue.d.ts +1 -0
  76. package/dist/types/components/pro-contract-template-designer/src/ContractTemplateDesignerWorkspaceHeader.vue.d.ts +3 -0
  77. package/dist/types/components/pro-contract-template-designer/src/ContractTemplateRendererField.vue.d.ts +7 -1
  78. package/dist/types/components/pro-contract-template-designer/src/ContractTemplateVariableDataModal.vue.d.ts +14 -0
  79. package/dist/types/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.d.ts +13 -1
  80. package/dist/types/components/pro-contract-template-designer/src/ProContractTemplateRenderer.vue.d.ts +11 -1
  81. package/dist/types/components/pro-contract-template-designer/src/composables/use-template-designer.d.ts +4 -0
  82. package/dist/types/components/pro-contract-template-designer/src/extensions/template-variable.d.ts +11 -1
  83. package/dist/types/components/pro-contract-template-designer/src/types.d.ts +131 -2
  84. package/dist/types/components/pro-contract-template-designer/src/utils/advanced-controls.d.ts +15 -0
  85. package/dist/types/components/pro-contract-template-designer/src/utils/template-renderer.d.ts +10 -2
  86. package/dist/types/components/pro-selector/index.d.ts +9 -0
  87. package/dist/types/components/pro-selector/src/components/user.d.ts +9 -0
  88. package/dist/types/components/pro-selector/src/types.d.ts +2 -0
  89. package/dist/types/components/pro-selector/src/utils/orgTree.d.ts +4 -1
  90. package/dist/types/components/pro-selector-group/src/compoents/select-box.vue.d.ts +4 -4
  91. package/dist/types/components/pro-selector-group/src/hooks/useApi.d.ts +6 -1
  92. package/dist/types/components/pro-selector-group/src/utils/index.d.ts +8 -0
  93. package/package.json +3 -1
@@ -1,29 +1,37 @@
1
1
  import "../constants.mjs";
2
2
  import { resolveTemplateVariablePresentation as e } from "../utils/template-variable-render.mjs";
3
- import { Node as t, mergeAttributes as n } from "@tiptap/core";
3
+ import { decodeContractTemplateJsonAttribute as t, encodeContractTemplateJsonAttribute as n } from "../utils/advanced-controls.mjs";
4
+ import { Node as r, mergeAttributes as i } from "@tiptap/core";
4
5
  //#region src/components/pro-contract-template-designer/src/extensions/template-variable.ts
5
- function r(e, t, n = "") {
6
+ function a(e, t, n = "") {
6
7
  return {
7
8
  default: n,
8
9
  parseHTML: (e) => e.getAttribute(t) ?? n,
9
10
  renderHTML: (n) => ({ [t]: n[e] })
10
11
  };
11
12
  }
12
- function i(e, t, n) {
13
+ function o(e, t, n) {
13
14
  return {
14
15
  default: n,
15
16
  parseHTML: (e) => Number(e.getAttribute(t) || n),
16
17
  renderHTML: (n) => ({ [t]: n[e] })
17
18
  };
18
19
  }
19
- function a(e, t) {
20
+ function s(e, t) {
20
21
  return {
21
22
  default: !1,
22
23
  parseHTML: (e) => e.getAttribute(t) === "true",
23
24
  renderHTML: (n) => ({ [t]: String(!!n[e]) })
24
25
  };
25
26
  }
26
- var o = t.create({
27
+ function c(e, r, i) {
28
+ return {
29
+ default: i,
30
+ parseHTML: (e) => t(e.getAttribute(r)) ?? i,
31
+ renderHTML: (t) => t[e] === void 0 || t[e] === null ? {} : { [r]: n(t[e]) }
32
+ };
33
+ }
34
+ var l = r.create({
27
35
  name: "templateVariable",
28
36
  group: "inline",
29
37
  inline: !0,
@@ -32,19 +40,19 @@ var o = t.create({
32
40
  draggable: !0,
33
41
  addAttributes() {
34
42
  return {
35
- key: r("key", "data-key"),
43
+ key: a("key", "data-key"),
36
44
  label: {
37
45
  default: "",
38
46
  parseHTML: (e) => e.getAttribute("data-label") ?? e.textContent ?? "",
39
47
  renderHTML: (e) => ({ "data-label": e.label })
40
48
  },
41
- type: r("type", "data-variable-type", "text"),
42
- placeholder: r("placeholder", "data-placeholder"),
43
- width: i("width", "data-width", 160),
44
- height: i("height", "data-height", 32),
45
- required: a("required", "data-required"),
46
- defaultValue: r("defaultValue", "data-default-value"),
47
- format: r("format", "data-format"),
49
+ type: a("type", "data-variable-type", "text"),
50
+ placeholder: a("placeholder", "data-placeholder"),
51
+ width: o("width", "data-width", 160),
52
+ height: o("height", "data-height", 32),
53
+ required: s("required", "data-required"),
54
+ defaultValue: a("defaultValue", "data-default-value"),
55
+ format: a("format", "data-format"),
48
56
  precision: {
49
57
  default: void 0,
50
58
  parseHTML: (e) => {
@@ -61,37 +69,42 @@ var o = t.create({
61
69
  },
62
70
  renderHTML: (e) => e.useGrouping === void 0 ? {} : { "data-use-grouping": String(!!e.useGrouping) }
63
71
  },
64
- checkedText: r("checkedText", "data-checked-text"),
65
- uncheckedText: r("uncheckedText", "data-unchecked-text"),
66
- multiline: a("multiline", "data-multiline"),
67
- rows: i("rows", "data-rows", 3),
68
- lineHeight: i("lineHeight", "data-line-height", 28),
69
- border: a("border", "data-border"),
70
- underline: a("underline", "data-underline"),
71
- color: r("color", "data-color", "#1f2937"),
72
- background: r("background", "data-background", "transparent"),
73
- fontSize: i("fontSize", "data-font-size", 14),
72
+ checkedText: a("checkedText", "data-checked-text"),
73
+ uncheckedText: a("uncheckedText", "data-unchecked-text"),
74
+ options: c("options", "data-control-options", []),
75
+ dataSource: c("dataSource", "data-control-source", void 0),
76
+ multiple: s("multiple", "data-multiple"),
77
+ componentKey: a("componentKey", "data-component-key"),
78
+ componentConfig: c("componentConfig", "data-component-config", {}),
79
+ multiline: s("multiline", "data-multiline"),
80
+ rows: o("rows", "data-rows", 3),
81
+ lineHeight: o("lineHeight", "data-line-height", 28),
82
+ border: s("border", "data-border"),
83
+ underline: s("underline", "data-underline"),
84
+ color: a("color", "data-color", "#1f2937"),
85
+ background: a("background", "data-background", "transparent"),
86
+ fontSize: o("fontSize", "data-font-size", 14),
74
87
  fontFamily: {
75
88
  default: "",
76
89
  parseHTML: (e) => e.getAttribute("data-font-family") ?? "",
77
90
  renderHTML: (e) => e.fontFamily ? { "data-font-family": e.fontFamily } : {}
78
91
  },
79
- placeholderColor: r("placeholderColor", "data-placeholder-color", "#7a818b"),
80
- lineColor: r("lineColor", "data-line-color", "#565b66"),
81
- textAlign: r("textAlign", "data-text-align", "left"),
82
- borderStyle: r("borderStyle", "data-border-style", "solid"),
83
- objectFit: r("objectFit", "data-object-fit", "contain")
92
+ placeholderColor: a("placeholderColor", "data-placeholder-color", "#7a818b"),
93
+ lineColor: a("lineColor", "data-line-color", "#565b66"),
94
+ textAlign: a("textAlign", "data-text-align", "left"),
95
+ borderStyle: a("borderStyle", "data-border-style", "solid"),
96
+ objectFit: a("objectFit", "data-object-fit", "contain")
84
97
  };
85
98
  },
86
99
  parseHTML() {
87
100
  return [{ tag: "span[data-template-variable]" }];
88
101
  },
89
102
  renderHTML({ HTMLAttributes: t }) {
90
- let r = t["data-border"] ?? t.border, i = t["data-precision"] ?? t.precision, a = i === void 0 || i === "" ? void 0 : Number(i), o = t["data-use-grouping"] ?? t.useGrouping, s = o === void 0 || o === "" ? void 0 : o === !0 || o === "true", c = e({
103
+ let n = t["data-border"] ?? t.border, r = t["data-precision"] ?? t.precision, a = r === void 0 || r === "" ? void 0 : Number(r), o = t["data-use-grouping"] ?? t.useGrouping, s = o === void 0 || o === "" ? void 0 : o === !0 || o === "true", c = e({
91
104
  type: String(t["data-variable-type"] || t.type || "text"),
92
105
  width: t["data-width"] || t.width || 160,
93
106
  height: t["data-height"] || t.height || 32,
94
- border: r === !0 || r === "true",
107
+ border: n === !0 || n === "true",
95
108
  underline: t["data-underline"] === "true" || t.underline === !0,
96
109
  color: String(t["data-color"] || t.color || "#1f2937"),
97
110
  background: String(t["data-background"] || t.background || "transparent"),
@@ -115,7 +128,7 @@ var o = t.create({
115
128
  });
116
129
  return [
117
130
  "span",
118
- n(t, {
131
+ i(t, {
119
132
  "data-template-variable": "true",
120
133
  "data-variable-type": c.type,
121
134
  "data-width": String(c.width),
@@ -141,7 +154,7 @@ var o = t.create({
141
154
  ];
142
155
  }
143
156
  });
144
- function s(e) {
157
+ function u(e) {
145
158
  return {
146
159
  key: e.key,
147
160
  label: e.label,
@@ -156,6 +169,11 @@ function s(e) {
156
169
  useGrouping: e.useGrouping,
157
170
  checkedText: e.checkedText || "",
158
171
  uncheckedText: e.uncheckedText || "",
172
+ options: e.options?.map((e) => ({ ...e })) ?? [],
173
+ dataSource: e.dataSource ? { ...e.dataSource } : void 0,
174
+ multiple: !!e.multiple,
175
+ componentKey: e.componentKey || "",
176
+ componentConfig: e.componentConfig ? { ...e.componentConfig } : {},
159
177
  multiline: !!e.multiline,
160
178
  rows: Math.max(1, Math.round(e.rows ?? 3)),
161
179
  lineHeight: Math.max(18, Math.round(e.lineHeight ?? 28)),
@@ -172,13 +190,13 @@ function s(e) {
172
190
  objectFit: e.style?.objectFit || "contain"
173
191
  };
174
192
  }
175
- function c(e, t, n) {
193
+ function d(e, t, n) {
176
194
  if (!e) return !1;
177
195
  let r = {
178
196
  type: "templateVariable",
179
- attrs: s(t)
197
+ attrs: u(t)
180
198
  }, i = e.chain().focus();
181
199
  return typeof n == "number" ? i.insertContentAt(n, r).run() : i.insertContent(r).run();
182
200
  }
183
201
  //#endregion
184
- export { o as TemplateVariable, s as buildTemplateVariableAttrs, c as insertTemplateVariableNode };
202
+ export { l as TemplateVariable, u as buildTemplateVariableAttrs, d as insertTemplateVariableNode };
@@ -4,10 +4,23 @@ var e = [
4
4
  "date",
5
5
  "number",
6
6
  "image",
7
- "checkbox"
7
+ "checkbox",
8
+ "select",
9
+ "radio",
10
+ "user-selector",
11
+ "dept-selector",
12
+ "role-selector",
13
+ "org-selector",
14
+ "custom"
8
15
  ];
9
16
  function t(t) {
10
17
  return typeof t == "string" && e.includes(t);
11
18
  }
19
+ function n(e) {
20
+ return e === "select" || e === "radio";
21
+ }
22
+ function r(e) {
23
+ return e === "user-selector" || e === "dept-selector" || e === "role-selector" || e === "org-selector";
24
+ }
12
25
  //#endregion
13
- export { t as isContractTemplateFieldType };
26
+ export { n as isContractTemplateAdvancedChoiceFieldType, r as isContractTemplateBuiltinSelectorFieldType, t as isContractTemplateFieldType };
@@ -0,0 +1,91 @@
1
+ //#region src/components/pro-contract-template-designer/src/utils/advanced-controls.ts
2
+ function e(e) {
3
+ if (!e || typeof e != "object" || Array.isArray(e)) return !1;
4
+ let t = e;
5
+ return (typeof t.value == "string" || typeof t.value == "number") && typeof t.label == "string" && typeof t.type == "string";
6
+ }
7
+ function t(t, r) {
8
+ if (e(t)) return {
9
+ ...n(t),
10
+ value: t.value,
11
+ label: t.label,
12
+ type: t.type || r
13
+ };
14
+ if (typeof t == "string" || typeof t == "number") return {
15
+ value: t,
16
+ label: String(t),
17
+ type: r
18
+ };
19
+ }
20
+ function n(e) {
21
+ let t = {};
22
+ return Object.entries(e).forEach(([e, n]) => {
23
+ if (!(e === "value" || e === "label" || e === "type")) try {
24
+ JSON.stringify(n), t[e] = n;
25
+ } catch {}
26
+ }), t;
27
+ }
28
+ function r(e, n, r) {
29
+ let i = (Array.isArray(e) ? e : e == null || e === "" ? [] : [e]).map((e) => t(e, n)).filter(Boolean);
30
+ return r ? i : i[0];
31
+ }
32
+ function i(t) {
33
+ return Array.isArray(t) ? t.map((e) => e.displayText || e.label || String(e.value)).filter(Boolean).join("、") : e(t) ? t.displayText || t.label || String(t.value) : t == null ? "" : String(t);
34
+ }
35
+ function a(e) {
36
+ try {
37
+ return encodeURIComponent(JSON.stringify(e ?? null));
38
+ } catch {
39
+ return "";
40
+ }
41
+ }
42
+ function o(e) {
43
+ if (!(typeof e != "string" || !e)) try {
44
+ return JSON.parse(decodeURIComponent(e));
45
+ } catch {
46
+ return;
47
+ }
48
+ }
49
+ function s(e, t, n) {
50
+ let r = u(e, t?.dataPath), i = Array.isArray(r) ? r : [], a = t?.valueField || "value", o = t?.labelField || "label";
51
+ return i.flatMap((e) => {
52
+ if (!e || typeof e != "object") return [];
53
+ let t = e, r = t[a];
54
+ return typeof r != "string" && typeof r != "number" ? [] : [{
55
+ value: r,
56
+ label: String(t[o] ?? r),
57
+ type: typeof t.type == "string" && t.type ? t.type : n,
58
+ ...typeof t.disabled == "boolean" ? { disabled: t.disabled } : {}
59
+ }];
60
+ });
61
+ }
62
+ function c(e, t) {
63
+ let n = e.trim();
64
+ if (/^\/(?!\/)/.test(n)) return !0;
65
+ try {
66
+ let e = new URL(n);
67
+ return e.protocol !== "https:" && e.protocol !== "http:" ? !1 : t.some((t) => {
68
+ try {
69
+ return new URL(t).origin === e.origin;
70
+ } catch {
71
+ return !1;
72
+ }
73
+ });
74
+ } catch {
75
+ return !1;
76
+ }
77
+ }
78
+ function l(e, t = 1e4) {
79
+ let n = Number.isFinite(t) ? Math.max(500, Math.floor(t)) : 1e4, r = Number(e);
80
+ return Number.isFinite(r) ? Math.min(n, Math.max(500, Math.floor(r))) : n;
81
+ }
82
+ function u(e, t) {
83
+ return t ? t.split(".").filter(Boolean).reduce((e, t) => {
84
+ if (!(!e || typeof e != "object" || Array.isArray(e))) return e[t];
85
+ }, e) : e;
86
+ }
87
+ function d(e) {
88
+ return e && typeof e == "object" && !Array.isArray(e) ? e : {};
89
+ }
90
+ //#endregion
91
+ export { o as decodeContractTemplateJsonAttribute, a as encodeContractTemplateJsonAttribute, i as formatContractTemplateRenderValue, c as isAllowedContractTemplateRemoteUrl, e as isContractTemplateSelectionValue, s as normalizeContractTemplateControlOptions, d as normalizeContractTemplateJsonObject, l as normalizeContractTemplateRequestTimeout, t as normalizeContractTemplateSelectionValue, r as normalizeContractTemplateSelectionValues };
@@ -2,30 +2,55 @@ import { canParseHtmlDocument as e, canUseDomHtml as t, collectFromHtmlTags as n
2
2
  import { resolveTemplateVariablePresentation as c } from "./template-variable-render.mjs";
3
3
  import { buildPageDecorationClassNames as l, buildPageDecorationsHtml as u, collectPageDecorationVariableKeys as d, normalizePageDecorations as f, validatePageDecorations as p } from "./page-decorations.mjs";
4
4
  import { isContractTemplateFieldType as m } from "../types.mjs";
5
- import { CONTRACT_TEMPLATE_RESERVED_VARIABLE_KEYS as h, CONTRACT_TEMPLATE_VARIABLE_KEY_PATTERN as g, DEFAULT_PAGE_SIZE as _, resolvePageSize as v, validateContractTemplateVariableKey as y } from "../composables/use-template-designer.mjs";
6
- import { isSafeContractImageUrl as b } from "./image-url.mjs";
5
+ import { formatContractTemplateRenderValue as h, isContractTemplateSelectionValue as g } from "./advanced-controls.mjs";
6
+ import { CONTRACT_TEMPLATE_RESERVED_VARIABLE_KEYS as _, CONTRACT_TEMPLATE_VARIABLE_KEY_PATTERN as v, DEFAULT_PAGE_SIZE as y, resolvePageSize as b, validateContractTemplateVariableKey as x } from "../composables/use-template-designer.mjs";
7
+ import { isSafeContractImageUrl as S } from "./image-url.mjs";
7
8
  //#region src/components/pro-contract-template-designer/src/utils/template-renderer.ts
8
- var x = new Set([
9
+ function C(e) {
10
+ let t = Array.isArray(e?.variables) ? e.variables : [], n = t.map((e) => w(e)), r = {};
11
+ return t.forEach((e) => {
12
+ let t = typeof e?.key == "string" ? e.key : "";
13
+ if (t) {
14
+ if (e.type === "checkbox") {
15
+ r[t] = !1;
16
+ return;
17
+ }
18
+ if (e.type === "number") {
19
+ let n = typeof e.defaultValue == "string" ? e.defaultValue.trim().length > 0 : e.defaultValue !== void 0, i = Number(e.defaultValue);
20
+ r[t] = n && Number.isFinite(i) ? i : "";
21
+ return;
22
+ }
23
+ r[t] = e.defaultValue ?? "";
24
+ }
25
+ }), {
26
+ values: r,
27
+ variables: n
28
+ };
29
+ }
30
+ function w(e) {
31
+ return JSON.parse(JSON.stringify(e));
32
+ }
33
+ var T = new Set([
9
34
  "action",
10
35
  "formaction",
11
36
  "href",
12
37
  "src",
13
38
  "xlink:href"
14
- ]), S = /<[^>]+data-template-variable=["']true["'][^>]*>/gi;
15
- function C(e) {
39
+ ]), E = /<[^>]+data-template-variable=["']true["'][^>]*>/gi;
40
+ function D(e) {
16
41
  let t = {};
17
42
  return (Array.isArray(e?.variables) ? e.variables : []).forEach((e) => {
18
- e?.key && (t[e.key] = I(e));
43
+ e?.key && (t[e.key] = B(e));
19
44
  }), t;
20
45
  }
21
- function w(e, t) {
46
+ function O(e, t) {
22
47
  return {
23
- ...C(e),
48
+ ...D(e),
24
49
  ...t ?? {}
25
50
  };
26
51
  }
27
- function T(e, t) {
28
- let n = D(e);
52
+ function k(e, t) {
53
+ let n = j(e);
29
54
  if (!e) return n;
30
55
  let r = Array.isArray(e.variables) ? e.variables : [], i = new Set(r.map((e) => e?.key).filter(Boolean));
31
56
  return Object.keys(t).forEach((e) => {
@@ -39,7 +64,7 @@ function T(e, t) {
39
64
  }), r.forEach((e) => {
40
65
  if (!e?.key) return;
41
66
  let r = t[e.key];
42
- if (e.required && A(r)) {
67
+ if (e.required && P(r)) {
43
68
  n.push({
44
69
  type: "variable",
45
70
  id: e.id,
@@ -49,7 +74,7 @@ function T(e, t) {
49
74
  });
50
75
  return;
51
76
  }
52
- A(r) || (e.type === "number" && (typeof r != "number" || !Number.isFinite(r)) && n.push({
77
+ P(r) || (e.type === "number" && (typeof r != "number" || !Number.isFinite(r)) && n.push({
53
78
  type: "variable",
54
79
  id: e.id,
55
80
  variableKey: e.key,
@@ -61,25 +86,31 @@ function T(e, t) {
61
86
  variableKey: e.key,
62
87
  message: `${e.label || e.key} 不是合法复选值`,
63
88
  code: "VARIABLE_TYPE_INVALID"
64
- }), e.type === "date" && !K(r) && n.push({
89
+ }), e.type === "date" && !X(r) && n.push({
65
90
  type: "variable",
66
91
  id: e.id,
67
92
  variableKey: e.key,
68
93
  message: `${e.label || e.key} 不是合法日期`,
69
94
  code: "VARIABLE_TYPE_INVALID"
70
- }), e.type === "image" && !b(String(r)) && n.push({
95
+ }), e.type === "image" && !S(String(r)) && n.push({
71
96
  type: "security",
72
97
  id: e.id,
73
98
  variableKey: e.key,
74
99
  message: `${e.label || e.key} 不是安全的图片地址`,
75
100
  code: "IMAGE_URL_UNSAFE"
76
- }));
101
+ }), (e.type === "select" || e.type === "radio" || e.type === "user-selector" || e.type === "dept-selector" || e.type === "role-selector" || e.type === "org-selector") && r !== void 0 && ((Array.isArray(r) ? r.every(g) : g(r)) || n.push({
102
+ type: "variable",
103
+ id: e.id,
104
+ variableKey: e.key,
105
+ message: `${e.label || e.key} 不是合法选择值`,
106
+ code: "VARIABLE_SELECTION_INVALID"
107
+ })));
77
108
  }), n;
78
109
  }
79
- function E(e, t, n) {
80
- return n ? T(e, t) : D(e);
110
+ function A(e, t, n) {
111
+ return n ? k(e, t) : j(e);
81
112
  }
82
- function D(e) {
113
+ function j(e) {
83
114
  if (!e) return [{
84
115
  type: "page",
85
116
  id: "template",
@@ -114,7 +145,7 @@ function D(e) {
114
145
  });
115
146
  return;
116
147
  }
117
- let a = e.key.trim(), o = r.some((t) => t?.id !== e.id && typeof t?.key == "string" && t.key.trim() === a), s = y(e.key, r, e.id), c = !g.test(a) || h.has(a);
148
+ let a = e.key.trim(), o = r.some((t) => t?.id !== e.id && typeof t?.key == "string" && t.key.trim() === a), s = x(e.key, r, e.id), c = !v.test(a) || _.has(a);
118
149
  s && (c || !o || e.key !== a) && t.push({
119
150
  type: "variable",
120
151
  id: e.id || `variable-${n}`,
@@ -155,7 +186,7 @@ function D(e) {
155
186
  pageId: e.id,
156
187
  message: `${e.title || `第 ${n + 1} 页`}:页面尺寸无效,已回退为安全尺寸`,
157
188
  code: "PAGE_SIZE_INVALID"
158
- }), V(e.contentHtml).forEach((e) => a.add(e)), H(e.contentHtml).forEach((r, i) => {
189
+ }), G(e.contentHtml).forEach((e) => a.add(e)), K(e.contentHtml).forEach((r, i) => {
159
190
  t.push({
160
191
  type: "security",
161
192
  id: `${e.id}-security-${i}`,
@@ -184,59 +215,59 @@ function D(e) {
184
215
  });
185
216
  }), t.push(...p(e.pageDecorations, r)), t;
186
217
  }
187
- function O(e, t, n = {}) {
218
+ function M(e, t, n = {}) {
188
219
  if (!e || !Array.isArray(e.pages)) return [];
189
- let r = Array.isArray(e.variables) ? e.variables : [], i = new Map(r.filter((e) => e?.key).map((e) => [e.key, e])), a = o(e.pageSize) ? e.pageSize : _;
220
+ let r = Array.isArray(e.variables) ? e.variables : [], i = new Map(r.filter((e) => e?.key).map((e) => [e.key, e])), a = o(e.pageSize) ? e.pageSize : y;
190
221
  return e.pages.flatMap((o) => {
191
222
  if (!o || typeof o.id != "string" || !o.id.trim() || typeof o.contentHtml != "string") return [];
192
- let s = v(o.pageSize, a);
223
+ let s = b(o.pageSize, a);
193
224
  return [{
194
225
  id: o.id,
195
226
  title: o.title || "未命名页面",
196
227
  format: s.format ?? "Custom",
197
228
  width: s.width,
198
229
  height: s.height,
199
- contentHtml: j(o.contentHtml, i, t, n),
230
+ contentHtml: F(o.contentHtml, i, t, n),
200
231
  ...e.pageDecorations ? { pageDecorations: f(e.pageDecorations) } : {},
201
232
  decorationVariables: r,
202
233
  decorationValues: t
203
234
  }];
204
235
  });
205
236
  }
206
- function k(e, t, n = {}) {
207
- return O(e, t, n).map((e, t, n) => {
237
+ function N(e, t, n = {}) {
238
+ return M(e, t, n).map((e, t, n) => {
208
239
  let i = u(e.pageDecorations, t + 1, n.length, e.decorationVariables, e.decorationValues);
209
240
  return `<section class="${l(e.pageDecorations, t + 1)}" data-page-id="${r(e.id)}" data-page-format="${r(e.format)}" data-page-width="${e.width}" data-page-height="${e.height}" style="width:${e.width}px;min-height:${e.height}px">${i}<div class="gd-contract-template-page__content">${e.contentHtml}</div></section>`;
210
241
  }).join("\n");
211
242
  }
212
- function A(e) {
213
- return e == null || e === "";
243
+ function P(e) {
244
+ return e == null || e === "" || Array.isArray(e) && e.length === 0;
214
245
  }
215
- function j(e, n, r, i) {
246
+ function F(e, n, r, i) {
216
247
  if (!e) return e;
217
- let o = B(e);
248
+ let o = W(e);
218
249
  if (t()) {
219
250
  let e = new DOMParser().parseFromString(o, "text/html");
220
251
  return e.querySelectorAll("[data-template-variable]").forEach((e) => {
221
- M(e, n, r, i);
252
+ I(e, n, r, i);
222
253
  }), e.body.innerHTML;
223
254
  }
224
255
  return s(o, (e, t) => {
225
256
  let o = a(t, "data-key");
226
- return o ? N(n.get(o), o, r[o], i) : e;
257
+ return o ? L(n.get(o), o, r[o], i) : e;
227
258
  });
228
259
  }
229
- function M(e, t, n, r) {
260
+ function I(e, t, n, r) {
230
261
  let i = e.dataset.key || "", a = t.get(i);
231
262
  if (!i || !a) return;
232
- let o = new DOMParser().parseFromString(N(a, i, n[i], r), "text/html").body.firstElementChild;
263
+ let o = new DOMParser().parseFromString(L(a, i, n[i], r), "text/html").body.firstElementChild;
233
264
  o && e.replaceWith(o);
234
265
  }
235
- function N(e, t, n, r) {
236
- return r.mode === "display" ? P(e, t, n, r) : F(e, t, n, r);
266
+ function L(e, t, n, r) {
267
+ return r.mode === "display" ? R(e, t, n, r) : z(e, t, n, r);
237
268
  }
238
- function P(e, t, n, a) {
239
- let o = e?.type ?? "text", s = n ?? I(e), l = o === "image" && !A(s) && !b(String(s)) ? "" : s, u = R(l), d = c({
269
+ function R(e, t, n, a) {
270
+ let o = e?.type ?? "text", s = n ?? B(e), l = o === "image" && !P(s) && !S(String(s)) ? "" : s, u = H(l), d = c({
240
271
  type: o,
241
272
  width: e?.width,
242
273
  height: e?.height,
@@ -257,7 +288,7 @@ function P(e, t, n, a) {
257
288
  "gd-contract-template-renderer__preview-control",
258
289
  ...d.classes,
259
290
  a.activeKey === t ? "is-active" : "",
260
- A(l) ? "is-empty" : ""
291
+ P(l) ? "is-empty" : ""
261
292
  ].filter(Boolean).join(" "))}"`,
262
293
  `style="${r(d.styleText)}"`,
263
294
  "data-contract-render-wrapper=\"true\"",
@@ -268,10 +299,10 @@ function P(e, t, n, a) {
268
299
  a.disabled ? "" : "role=\"button\"",
269
300
  a.disabled ? "" : "tabindex=\"0\""
270
301
  ].filter(Boolean).join(" ");
271
- return o === "checkbox" ? `<span ${p}><span class="gd-contract-template-renderer__checkbox-mark" aria-hidden="true">${z(l) ? "✓" : ""}</span>${i(f)}</span>` : o === "image" && !A(l) ? `<span ${p}></span>` : `<span ${p}>${i(f)}</span>`;
302
+ return o === "checkbox" ? `<span ${p}><span class="gd-contract-template-renderer__checkbox-mark" aria-hidden="true">${U(l) ? "✓" : ""}</span>${i(f)}</span>` : o === "image" && !P(l) ? `<span ${p}></span>` : `<span ${p}>${i(f)}</span>`;
272
303
  }
273
- function F(e, t, n, a) {
274
- let o = e?.type ?? "text", s = !!a.readonly, l = L(n ?? I(e)), u = c({
304
+ function z(e, t, n, a) {
305
+ let o = e?.type ?? "text", s = !!a.readonly, l = V(n ?? B(e)), u = c({
275
306
  type: o,
276
307
  width: e?.width,
277
308
  height: e?.height,
@@ -294,49 +325,49 @@ function F(e, t, n, a) {
294
325
  d ? "disabled" : "",
295
326
  s ? "readonly" : ""
296
327
  ].filter(Boolean).join(" "), p = `style="${r(u.styleText)}"`, m = r(["gd-contract-template-renderer__control", ...u.classes].join(" "));
297
- return o === "checkbox" ? `<label class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}"><input type="checkbox" ${f} ${z(l) ? "checked" : ""}>${i(e?.checkedText || e?.label || t)}</label>` : s ? `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${i(u.displayText || l)}</span>` : o === "number" ? `<input class="${m}" ${p} type="number" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">` : o === "date" ? `<input class="${m}" ${p} type="date" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">` : e?.multiline ? `<textarea class="${m}" ${p} ${f} placeholder="${r(e.placeholder || "")}">${i(l)}</textarea>` : `<input class="${m}" ${p} type="text" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">`;
328
+ return o === "checkbox" ? `<label class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}"><input type="checkbox" ${f} ${U(l) ? "checked" : ""}>${i(e?.checkedText || e?.label || t)}</label>` : s ? `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${i(u.displayText || l)}</span>` : o === "number" ? `<input class="${m}" ${p} type="number" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">` : o === "date" ? `<input class="${m}" ${p} type="date" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">` : o === "select" || o === "radio" || o.endsWith("-selector") || o === "custom" ? `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${i(h(n))}</span>` : e?.multiline ? `<textarea class="${m}" ${p} ${f} placeholder="${r(e.placeholder || "")}">${i(l)}</textarea>` : `<input class="${m}" ${p} type="text" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">`;
298
329
  }
299
- function I(e) {
330
+ function B(e) {
300
331
  if (!e) return "";
301
- if (e.type === "checkbox") return z(e.defaultValue);
332
+ if (e.type === "checkbox") return U(e.defaultValue);
302
333
  if (e.type === "number" && e.defaultValue !== void 0) {
303
334
  let t = Number(e.defaultValue);
304
335
  return Number.isFinite(t) ? t : e.defaultValue;
305
336
  }
306
- return e.defaultValue ?? "";
337
+ if (!(e.type === "select" || e.type === "radio" || e.type?.endsWith("-selector"))) return e.defaultValue ?? "";
307
338
  }
308
- function L(e) {
309
- return typeof e == "boolean" ? e ? "true" : "" : e == null ? "" : String(e);
339
+ function V(e) {
340
+ return typeof e == "boolean" ? e ? "true" : "" : e == null ? "" : h(e);
310
341
  }
311
- function R(e) {
312
- return typeof e == "boolean" ? e ? "true" : "false" : e == null ? "" : String(e);
342
+ function H(e) {
343
+ return typeof e == "boolean" ? e ? "true" : "false" : e == null ? "" : h(e);
313
344
  }
314
- function z(e) {
345
+ function U(e) {
315
346
  return e === !0 || e === "true" || e === "1" || e === "yes" || e === "是" || e === "已选";
316
347
  }
317
- function B(t) {
348
+ function W(t) {
318
349
  if (e()) {
319
350
  let e = new DOMParser().parseFromString(t, "text/html");
320
351
  return e.querySelectorAll("script,style,meta,link,iframe,object,embed").forEach((e) => e.remove()), e.querySelectorAll("*").forEach((e) => {
321
352
  Array.from(e.attributes).forEach((t) => {
322
353
  let n = t.name.toLowerCase();
323
- (n.startsWith("on") || n === "srcdoc" || x.has(n) && U(t.value) || n === "style" && G(t.value)) && e.removeAttribute(t.name);
354
+ (n.startsWith("on") || n === "srcdoc" || T.has(n) && q(t.value) || n === "style" && Y(t.value)) && e.removeAttribute(t.name);
324
355
  });
325
356
  }), e.body.innerHTML;
326
357
  }
327
358
  return t.replace(/<\s*(script|style|iframe|object|embed)\b[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi, "").replace(/<\s*\/?\s*(?:script|style|meta|link|iframe|object|embed)\b[^>]*>/gi, "").replace(/\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(/\s+srcdoc\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(/\s+(action|formaction|href|src|xlink:href)\s*=\s*(?:(["'])(.*?)\2|([^\s>]+))/gi, (e, t, n, r, i) => {
328
359
  let a = r ?? i ?? "";
329
- return U(a) ? "" : n ? ` ${t}=${n}${a}${n}` : ` ${t}=${a}`;
330
- }).replace(/\s+style\s*=\s*(["'])(.*?)\1/gi, (e, t, n) => G(n) ? "" : ` style=${t}${n}${t}`);
360
+ return q(a) ? "" : n ? ` ${t}=${n}${a}${n}` : ` ${t}=${a}`;
361
+ }).replace(/\s+style\s*=\s*(["'])(.*?)\1/gi, (e, t, n) => Y(n) ? "" : ` style=${t}${n}${t}`);
331
362
  }
332
- function V(e) {
333
- return n(e, S, (e) => a(e, "data-key"));
363
+ function G(e) {
364
+ return n(e, E, (e) => a(e, "data-key"));
334
365
  }
335
- function H(e) {
366
+ function K(e) {
336
367
  let t = [];
337
- return /<\s*(script|style|meta|link|iframe|object|embed)\b/i.test(e) && t.push("正文包含已移除的危险标签"), /\s(?:on[a-z]+|srcdoc)\s*=/i.test(e) && t.push("正文包含已移除的事件或嵌入属性"), (W(e) || /style\s*=\s*["'][^"']*(?:expression\s*\(|url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html))/i.test(e)) && t.push("正文包含已移除的危险 URL 或样式"), t;
368
+ return /<\s*(script|style|meta|link|iframe|object|embed)\b/i.test(e) && t.push("正文包含已移除的危险标签"), /\s(?:on[a-z]+|srcdoc)\s*=/i.test(e) && t.push("正文包含已移除的事件或嵌入属性"), (J(e) || /style\s*=\s*["'][^"']*(?:expression\s*\(|url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html))/i.test(e)) && t.push("正文包含已移除的危险 URL 或样式"), t;
338
369
  }
339
- function U(e) {
370
+ function q(e) {
340
371
  let t = e.replace(/&#(?:x([\da-f]+)|(\d+));?/gi, (e, t, n) => {
341
372
  let r = Number.parseInt(t ?? n ?? "", t ? 16 : 10);
342
373
  try {
@@ -351,22 +382,22 @@ function U(e) {
351
382
  })[t.toLowerCase()] ?? "").trim().replace(/[\u0000-\u0020\u007F]+/g, "");
352
383
  return /^(?:javascript|vbscript|data:text\/html)/i.test(t);
353
384
  }
354
- function W(e) {
385
+ function J(e) {
355
386
  let t = /\s+(?:action|formaction|href|src|xlink:href)\s*=\s*(?:(["'])(.*?)\1|([^\s>]+))/gi, n = t.exec(e);
356
387
  for (; n;) {
357
- if (U(n[2] ?? n[3] ?? "")) return !0;
388
+ if (q(n[2] ?? n[3] ?? "")) return !0;
358
389
  n = t.exec(e);
359
390
  }
360
391
  return !1;
361
392
  }
362
- function G(e) {
393
+ function Y(e) {
363
394
  return /expression\s*\(|url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html)/i.test(e);
364
395
  }
365
- function K(e) {
396
+ function X(e) {
366
397
  let t = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(e));
367
398
  if (!t) return !1;
368
399
  let n = /* @__PURE__ */ new Date(`${t[1]}-${t[2]}-${t[3]}T00:00:00Z`);
369
400
  return !Number.isNaN(n.getTime()) && n.getUTCFullYear() === Number(t[1]) && n.getUTCMonth() + 1 === Number(t[2]) && n.getUTCDate() === Number(t[3]);
370
401
  }
371
402
  //#endregion
372
- export { C as buildInitialRenderValues, k as buildTemplateRenderHtml, O as buildTemplateRenderPages, A as isEmptyRenderValue, w as normalizeRenderValues, E as resolveTemplateRenderSubmitErrors, B as sanitizeContractRendererHtml, D as validateTemplateRenderStructure, T as validateTemplateRenderValues };
403
+ export { D as buildInitialRenderValues, N as buildTemplateRenderHtml, M as buildTemplateRenderPages, C as buildTemplateVariableData, P as isEmptyRenderValue, O as normalizeRenderValues, A as resolveTemplateRenderSubmitErrors, W as sanitizeContractRendererHtml, j as validateTemplateRenderStructure, k as validateTemplateRenderValues };