@guodun/antdv 1.7.8 → 1.7.10
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/dist/es/components/contract-signing-location/src/ContractSigningLocation.vue.mjs +295 -296
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateChoiceOptionsEditor.mjs +5 -0
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateChoiceOptionsEditor.vue.mjs +132 -0
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateDesignerInspector.vue.mjs +267 -277
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateRendererField.vue.mjs +1 -1
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateSingleRenderer.vue.mjs +258 -252
- package/dist/es/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.mjs +1020 -1011
- package/dist/es/components/pro-contract-template-designer/src/composables/use-template-designer.mjs +193 -163
- package/dist/es/components/pro-contract-template-designer/src/extensions/template-variable.mjs +70 -68
- package/dist/es/components/pro-contract-template-designer/src/utils/advanced-controls.mjs +63 -25
- package/dist/es/components/pro-contract-template-designer/src/utils/contract-print-document.mjs +7 -1
- package/dist/es/components/pro-contract-template-designer/src/utils/template-renderer.mjs +158 -93
- package/dist/es/components/pro-contract-template-designer/src/utils/template-variable-render.mjs +45 -18
- package/dist/es/components/pro-contract-template-designer/style/index.css +1 -1
- package/dist/es/index.mjs +22 -22
- package/dist/lib/components/contract-signing-location/src/ContractSigningLocation.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateChoiceOptionsEditor.cjs +1 -0
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateChoiceOptionsEditor.vue.cjs +1 -0
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateDesignerInspector.vue.cjs +1 -2
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateRendererField.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateSingleRenderer.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/composables/use-template-designer.cjs +4 -4
- package/dist/lib/components/pro-contract-template-designer/src/extensions/template-variable.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/utils/advanced-controls.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/utils/contract-print-document.cjs +7 -1
- package/dist/lib/components/pro-contract-template-designer/src/utils/template-renderer.cjs +5 -3
- package/dist/lib/components/pro-contract-template-designer/src/utils/template-variable-render.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/style/index.css +1 -1
- package/dist/lib/index.cjs +1 -1
- package/dist/theme/icon.css +1 -1
- package/dist/theme/index.css +1 -1
- package/dist/types/components/pro-contract-template-designer/src/ContractTemplateChoiceOptionsEditor.vue.d.ts +12 -0
- package/dist/types/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.d.ts +2 -0
- package/dist/types/components/pro-contract-template-designer/src/composables/use-template-designer.d.ts +5 -1
- package/dist/types/components/pro-contract-template-designer/src/types.d.ts +18 -2
- package/dist/types/components/pro-contract-template-designer/src/utils/advanced-controls.d.ts +10 -0
- package/dist/types/components/pro-contract-template-designer/src/utils/contract-print-document.d.ts +1 -1
- package/dist/types/components/pro-contract-template-designer/src/utils/template-renderer.d.ts +2 -0
- package/dist/types/components/pro-contract-template-designer/src/utils/template-variable-render.d.ts +15 -2
- package/package.json +3 -3
|
@@ -2,12 +2,12 @@ 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 {
|
|
6
|
-
import { CONTRACT_TEMPLATE_RESERVED_VARIABLE_KEYS as
|
|
7
|
-
import { isSafeContractImageUrl as
|
|
5
|
+
import { buildRadioOptionsHtml as h, formatContractTemplateRenderValue as g, isContractTemplateSelectionValue as _ } from "./advanced-controls.mjs";
|
|
6
|
+
import { CONTRACT_TEMPLATE_RESERVED_VARIABLE_KEYS as v, CONTRACT_TEMPLATE_VARIABLE_KEY_PATTERN as y, DEFAULT_PAGE_SIZE as ee, resolvePageSize as te, validateContractTemplateVariableKey as ne } from "../composables/use-template-designer.mjs";
|
|
7
|
+
import { isSafeContractImageUrl as re } from "./image-url.mjs";
|
|
8
8
|
//#region src/components/pro-contract-template-designer/src/utils/template-renderer.ts
|
|
9
|
-
function
|
|
10
|
-
let t = Array.isArray(e?.variables) ? e.variables : [], n = t.map((e) =>
|
|
9
|
+
function ie(e) {
|
|
10
|
+
let t = Array.isArray(e?.variables) ? e.variables : [], n = t.map((e) => b(e)), r = {};
|
|
11
11
|
return t.forEach((e) => {
|
|
12
12
|
let t = typeof e?.key == "string" ? e.key : "";
|
|
13
13
|
if (t) {
|
|
@@ -27,30 +27,30 @@ function C(e) {
|
|
|
27
27
|
variables: n
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function b(e) {
|
|
31
31
|
return JSON.parse(JSON.stringify(e));
|
|
32
32
|
}
|
|
33
|
-
var
|
|
33
|
+
var x = new Set([
|
|
34
34
|
"action",
|
|
35
35
|
"formaction",
|
|
36
36
|
"href",
|
|
37
37
|
"src",
|
|
38
38
|
"xlink:href"
|
|
39
|
-
]),
|
|
40
|
-
function
|
|
39
|
+
]), S = /<[^>]+data-template-variable=["']true["'][^>]*>/gi, C = 100, w = 6e3, T = 6, E = /^data:image\/(?:png|jpe?g|webp|gif);base64,[A-Za-z0-9+/=]+$/i;
|
|
40
|
+
function D(e) {
|
|
41
41
|
let t = {};
|
|
42
42
|
return (Array.isArray(e?.variables) ? e.variables : []).forEach((e) => {
|
|
43
|
-
e?.key && (t[e.key] =
|
|
43
|
+
e?.key && (t[e.key] = B(e));
|
|
44
44
|
}), t;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function ae(e, t) {
|
|
47
47
|
return {
|
|
48
|
-
...
|
|
48
|
+
...D(e),
|
|
49
49
|
...t ?? {}
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
let n =
|
|
52
|
+
function O(e, t) {
|
|
53
|
+
let n = A(e);
|
|
54
54
|
if (!e) return n;
|
|
55
55
|
let r = Array.isArray(e.variables) ? e.variables : [], i = new Set(r.map((e) => e?.key).filter(Boolean));
|
|
56
56
|
return Object.keys(t).forEach((e) => {
|
|
@@ -63,8 +63,8 @@ function M(e, t) {
|
|
|
63
63
|
});
|
|
64
64
|
}), r.forEach((e) => {
|
|
65
65
|
if (!e?.key) return;
|
|
66
|
-
let r =
|
|
67
|
-
if (e.required &&
|
|
66
|
+
let r = Z(e, t[e.key]), i = e.label || e.key;
|
|
67
|
+
if (e.required && N(r)) {
|
|
68
68
|
n.push({
|
|
69
69
|
type: "variable",
|
|
70
70
|
id: e.id,
|
|
@@ -74,39 +74,39 @@ function M(e, t) {
|
|
|
74
74
|
});
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
-
if (
|
|
77
|
+
if (N(r)) return;
|
|
78
78
|
let a = e.type ?? "text";
|
|
79
|
-
a === "number" && !
|
|
79
|
+
a === "number" && !ue(r, e.precision, e.format) && n.push({
|
|
80
80
|
type: "variable",
|
|
81
81
|
id: e.id,
|
|
82
82
|
variableKey: e.key,
|
|
83
83
|
message: `${i} 不是合法数字或超出精度`,
|
|
84
84
|
code: "VARIABLE_TYPE_INVALID"
|
|
85
|
-
}), a === "checkbox" && !
|
|
85
|
+
}), a === "checkbox" && !de(r) && n.push({
|
|
86
86
|
type: "variable",
|
|
87
87
|
id: e.id,
|
|
88
88
|
variableKey: e.key,
|
|
89
89
|
message: `${i} 不是合法勾选值`,
|
|
90
90
|
code: "VARIABLE_TYPE_INVALID"
|
|
91
|
-
}), a === "date" && !
|
|
91
|
+
}), a === "date" && !Q(r) && n.push({
|
|
92
92
|
type: "variable",
|
|
93
93
|
id: e.id,
|
|
94
94
|
variableKey: e.key,
|
|
95
95
|
message: `${i} 不是合法日期`,
|
|
96
96
|
code: "VARIABLE_TYPE_INVALID"
|
|
97
|
-
}), a === "image" && !
|
|
97
|
+
}), a === "image" && !fe(String(r).trim()) && n.push({
|
|
98
98
|
type: "security",
|
|
99
99
|
id: e.id,
|
|
100
100
|
variableKey: e.key,
|
|
101
101
|
message: `${i} 必须使用安全的图片 data URL`,
|
|
102
102
|
code: "UNSAFE_IMAGE_URL"
|
|
103
|
-
}), a
|
|
103
|
+
}), n.push(...k(e, r)), pe(a) && (me(r, a !== "radio" && !!e.multiple) ? U(e) && !W(e, r) && n.push({
|
|
104
104
|
type: "variable",
|
|
105
105
|
id: e.id,
|
|
106
106
|
variableKey: e.key,
|
|
107
|
-
message: `${i}
|
|
108
|
-
code: "
|
|
109
|
-
})
|
|
107
|
+
message: `${i} 不在可选项中`,
|
|
108
|
+
code: "VARIABLE_TYPE_INVALID"
|
|
109
|
+
}) : n.push({
|
|
110
110
|
type: "variable",
|
|
111
111
|
id: e.id,
|
|
112
112
|
variableKey: e.key,
|
|
@@ -115,10 +115,23 @@ function M(e, t) {
|
|
|
115
115
|
}));
|
|
116
116
|
}), n;
|
|
117
117
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
118
|
+
function k(e, t) {
|
|
119
|
+
if ((e.type ?? "text") !== "text") return [];
|
|
120
|
+
let n = Z(e, t);
|
|
121
|
+
if (N(n) || !he(e, String(n))) return [];
|
|
122
|
+
let r = e.label || e.key;
|
|
123
|
+
return [{
|
|
124
|
+
type: "variable",
|
|
125
|
+
id: e.id,
|
|
126
|
+
variableKey: e.key,
|
|
127
|
+
message: e.multiline ? `${r} 内容超出正文预留的${e.rows ?? 3}行,请缩短内容或调整模板行数` : `${r} 内容超出变量范围`,
|
|
128
|
+
code: "VARIABLE_OVERFLOW"
|
|
129
|
+
}];
|
|
120
130
|
}
|
|
121
|
-
function
|
|
131
|
+
function oe(e, t, n) {
|
|
132
|
+
return O(e, t);
|
|
133
|
+
}
|
|
134
|
+
function A(e) {
|
|
122
135
|
if (!e) return [{
|
|
123
136
|
type: "page",
|
|
124
137
|
id: "template",
|
|
@@ -139,7 +152,7 @@ function P(e) {
|
|
|
139
152
|
}), $(e.pageSize) || t.push({
|
|
140
153
|
type: "page",
|
|
141
154
|
id: "template-page-size",
|
|
142
|
-
message: `模板默认页面尺寸必须在 ${
|
|
155
|
+
message: `模板默认页面尺寸必须在 ${C} ~ ${w} CSS px 之间`,
|
|
143
156
|
code: "TEMPLATE_PAGE_SIZE_INVALID"
|
|
144
157
|
});
|
|
145
158
|
let i = /* @__PURE__ */ new Map();
|
|
@@ -153,7 +166,7 @@ function P(e) {
|
|
|
153
166
|
});
|
|
154
167
|
return;
|
|
155
168
|
}
|
|
156
|
-
let a = e.key.trim(), o = r.some((t) => t?.id !== e.id && typeof t?.key == "string" && t.key.trim() === a), s =
|
|
169
|
+
let a = e.key.trim(), o = r.some((t) => t?.id !== e.id && typeof t?.key == "string" && t.key.trim() === a), s = ne(e.key, r, e.id), c = !y.test(a) || v.has(a);
|
|
157
170
|
s && (c || !o || e.key !== a) && t.push({
|
|
158
171
|
type: "variable",
|
|
159
172
|
id: e.id || `variable-${n}`,
|
|
@@ -192,9 +205,9 @@ function P(e) {
|
|
|
192
205
|
type: "page",
|
|
193
206
|
id: `${e.id}-page-size`,
|
|
194
207
|
pageId: e.id,
|
|
195
|
-
message: `${e.title || `第 ${n + 1} 页`}:页面尺寸必须在 ${
|
|
208
|
+
message: `${e.title || `第 ${n + 1} 页`}:页面尺寸必须在 ${C} ~ ${w} CSS px 之间`,
|
|
196
209
|
code: "PAGE_SIZE_INVALID"
|
|
197
|
-
}),
|
|
210
|
+
}), se(e.contentHtml).forEach((e) => a.add(e)), ce(e.contentHtml).forEach((r, i) => {
|
|
198
211
|
t.push({
|
|
199
212
|
type: "security",
|
|
200
213
|
id: `${e.id}-security-${i}`,
|
|
@@ -223,59 +236,59 @@ function P(e) {
|
|
|
223
236
|
});
|
|
224
237
|
}), t.push(...p(e.pageDecorations, r)), t;
|
|
225
238
|
}
|
|
226
|
-
function
|
|
239
|
+
function j(e, t, n = {}) {
|
|
227
240
|
if (!e || !Array.isArray(e.pages)) return [];
|
|
228
|
-
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 :
|
|
241
|
+
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 : ee;
|
|
229
242
|
return e.pages.flatMap((o) => {
|
|
230
243
|
if (!o || typeof o.id != "string" || !o.id.trim() || typeof o.contentHtml != "string") return [];
|
|
231
|
-
let s =
|
|
244
|
+
let s = te(o.pageSize, a);
|
|
232
245
|
return [{
|
|
233
246
|
id: o.id,
|
|
234
247
|
title: o.title || "未命名页面",
|
|
235
248
|
format: s.format ?? "Custom",
|
|
236
249
|
width: s.width,
|
|
237
250
|
height: s.height,
|
|
238
|
-
contentHtml:
|
|
251
|
+
contentHtml: P(o.contentHtml, i, t, n),
|
|
239
252
|
...e.pageDecorations ? { pageDecorations: f(e.pageDecorations) } : {},
|
|
240
253
|
decorationVariables: r,
|
|
241
254
|
decorationValues: t
|
|
242
255
|
}];
|
|
243
256
|
});
|
|
244
257
|
}
|
|
245
|
-
function
|
|
246
|
-
return
|
|
258
|
+
function M(e, t, n = {}) {
|
|
259
|
+
return j(e, t, n).map((e, t, n) => {
|
|
247
260
|
let i = u(e.pageDecorations, t + 1, n.length, e.decorationVariables, e.decorationValues);
|
|
248
261
|
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>`;
|
|
249
262
|
}).join("\n");
|
|
250
263
|
}
|
|
251
|
-
function
|
|
264
|
+
function N(e) {
|
|
252
265
|
return e == null || e === "" || Array.isArray(e) && e.length === 0;
|
|
253
266
|
}
|
|
254
|
-
function
|
|
267
|
+
function P(e, n, r, i) {
|
|
255
268
|
if (!e) return e;
|
|
256
|
-
let o =
|
|
269
|
+
let o = J(e);
|
|
257
270
|
if (t()) {
|
|
258
271
|
let e = new DOMParser().parseFromString(o, "text/html");
|
|
259
272
|
return e.querySelectorAll("[data-template-variable]").forEach((e) => {
|
|
260
|
-
|
|
261
|
-
}), e.body.innerHTML;
|
|
273
|
+
F(e, n, r, i);
|
|
274
|
+
}), e.body.innerHTML.replace(/(<textarea\b[^>]*data-contract-render-control="true"[^>]*>)(?=[\r\n])/gi, "$1\n");
|
|
262
275
|
}
|
|
263
276
|
return s(o, (e, t) => {
|
|
264
277
|
let o = a(t, "data-key");
|
|
265
|
-
return o ?
|
|
278
|
+
return o ? I(n.get(o), o, r[o], i) : e;
|
|
266
279
|
});
|
|
267
280
|
}
|
|
268
|
-
function
|
|
281
|
+
function F(e, t, n, r) {
|
|
269
282
|
let i = e.dataset.key || "", a = t.get(i);
|
|
270
283
|
if (!i || !a) return;
|
|
271
|
-
let o = new DOMParser().parseFromString(
|
|
272
|
-
o && e.replaceWith(o);
|
|
284
|
+
let o = new DOMParser().parseFromString(I(a, i, n[i], r), "text/html").body.firstElementChild;
|
|
285
|
+
o && (o.tagName === "TEXTAREA" && (o.textContent = G(z(a, n[i]))), e.replaceWith(o));
|
|
273
286
|
}
|
|
274
|
-
function
|
|
275
|
-
return r.mode === "display" ?
|
|
287
|
+
function I(e, t, n, r) {
|
|
288
|
+
return r.mode === "display" ? L(e, t, n, r) : R(e, t, n, r);
|
|
276
289
|
}
|
|
277
|
-
function
|
|
278
|
-
let o = e?.type ?? "text", s =
|
|
290
|
+
function L(e, t, n, a) {
|
|
291
|
+
let o = e?.type ?? "text", s = z(e, n), l = o === "image" && !N(s) && !re(String(s)) ? "" : s, u = K(l), d = c({
|
|
279
292
|
type: o,
|
|
280
293
|
width: e?.width,
|
|
281
294
|
height: e?.height,
|
|
@@ -296,7 +309,7 @@ function V(e, t, n, a) {
|
|
|
296
309
|
"gd-contract-template-renderer__preview-control",
|
|
297
310
|
...d.classes,
|
|
298
311
|
a.activeKey === t ? "is-active" : "",
|
|
299
|
-
|
|
312
|
+
N(l) ? "is-empty" : ""
|
|
300
313
|
].filter(Boolean).join(" "))}"`,
|
|
301
314
|
`style="${r(d.styleText)}"`,
|
|
302
315
|
"data-contract-render-wrapper=\"true\"",
|
|
@@ -307,10 +320,10 @@ function V(e, t, n, a) {
|
|
|
307
320
|
a.disabled ? "" : "role=\"button\"",
|
|
308
321
|
a.disabled ? "" : "tabindex=\"0\""
|
|
309
322
|
].filter(Boolean).join(" ");
|
|
310
|
-
return o === "checkbox" ? `<span ${p}><span class="gd-contract-template-renderer__checkbox-mark" aria-hidden="true">${
|
|
323
|
+
return o === "checkbox" ? `<span ${p}><span class="gd-contract-template-renderer__checkbox-mark" aria-hidden="true">${q(l) ? "✓" : ""}</span>${i(f)}</span>` : o === "radio" ? `<span ${p}>${h(e?.options, V(l)) || i(e?.placeholder || f)}</span>` : o === "select" ? `<span ${p}>${i(H(e, l) || f)}</span>` : o === "image" && !N(l) ? `<span ${p}></span>` : `<span ${p}>${i(f)}</span>`;
|
|
311
324
|
}
|
|
312
|
-
function
|
|
313
|
-
let o = e?.type ?? "text", s = !!a.readonly, l =
|
|
325
|
+
function R(e, t, n, a) {
|
|
326
|
+
let o = e?.type ?? "text", s = !!a.readonly, l = G(z(e, n)), u = c({
|
|
314
327
|
type: o,
|
|
315
328
|
width: e?.width,
|
|
316
329
|
height: e?.height,
|
|
@@ -333,49 +346,101 @@ function H(e, t, n, a) {
|
|
|
333
346
|
d ? "disabled" : "",
|
|
334
347
|
s ? "readonly" : ""
|
|
335
348
|
].filter(Boolean).join(" "), p = `style="${r(u.styleText)}"`, m = r(["gd-contract-template-renderer__control", ...u.classes].join(" "));
|
|
336
|
-
|
|
349
|
+
if (o === "checkbox") return `<label class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}"><input type="checkbox" ${f} ${q(l) ? "checked" : ""}>${i(e?.checkedText || e?.label || t)}</label>`;
|
|
350
|
+
if (o === "radio") {
|
|
351
|
+
let a = z(e, n), o = h(e?.options, V(a)) || i(u.displayText || e?.placeholder || "");
|
|
352
|
+
return `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${o}</span>`;
|
|
353
|
+
}
|
|
354
|
+
if (s) return `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${i(u.displayText || l)}</span>`;
|
|
355
|
+
if (o === "number") return `<input class="${m}" ${p} type="number" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">`;
|
|
356
|
+
if (o === "date") return `<input class="${m}" ${p} type="date" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">`;
|
|
357
|
+
if (o === "select" || o.endsWith("-selector") || o === "custom") {
|
|
358
|
+
let a = z(e, n), s = o === "select" ? H(e, a) : g(a);
|
|
359
|
+
return `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${i(s)}</span>`;
|
|
360
|
+
}
|
|
361
|
+
if (e?.multiline) {
|
|
362
|
+
let t = /^[\r\n]/.test(l) ? "\n" : "";
|
|
363
|
+
return `<textarea class="${m}" ${p} ${f} placeholder="${r(e.placeholder || "")}">${t}${i(l)}</textarea>`;
|
|
364
|
+
}
|
|
365
|
+
return `<input class="${m}" ${p} type="text" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">`;
|
|
337
366
|
}
|
|
338
|
-
function
|
|
367
|
+
function z(e, t) {
|
|
368
|
+
if (!(e?.type === "select" && e.multiple && N(t))) return t ?? B(e);
|
|
369
|
+
}
|
|
370
|
+
function B(e) {
|
|
339
371
|
if (!e) return "";
|
|
340
|
-
if (e.type === "checkbox") return
|
|
372
|
+
if (e.type === "checkbox") return q(e.defaultValue);
|
|
341
373
|
if (e.type === "number" && e.defaultValue !== void 0) {
|
|
342
374
|
let t = Number(e.defaultValue);
|
|
343
375
|
return Number.isFinite(t) ? t : e.defaultValue;
|
|
344
376
|
}
|
|
345
|
-
if (
|
|
377
|
+
if (e.type === "select" || e.type === "radio") {
|
|
378
|
+
if (e.type === "select" && e.multiple || !e.defaultValue) return;
|
|
379
|
+
let t = (e.options ?? []).find((t) => String(t.value) === String(e.defaultValue));
|
|
380
|
+
return t ? {
|
|
381
|
+
value: t.value,
|
|
382
|
+
label: t.label,
|
|
383
|
+
type: t.type || e.type
|
|
384
|
+
} : void 0;
|
|
385
|
+
}
|
|
386
|
+
if (!e.type?.endsWith("-selector")) return e.defaultValue ?? "";
|
|
387
|
+
}
|
|
388
|
+
function V(e) {
|
|
389
|
+
if (!Array.isArray(e)) {
|
|
390
|
+
if (_(e)) return e.value;
|
|
391
|
+
if (typeof e == "string" || typeof e == "number") return e;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function H(e, t) {
|
|
395
|
+
let n = Array.isArray(t) ? t : [t];
|
|
396
|
+
if (n.length && n.every((e) => _(e))) return g(t);
|
|
397
|
+
let r = n.flatMap((t) => {
|
|
398
|
+
let n = typeof t == "string" || typeof t == "number" ? t : void 0;
|
|
399
|
+
if (n === void 0) return [];
|
|
400
|
+
let r = e?.options?.find((e) => String(e.value) === String(n));
|
|
401
|
+
return r?.label ? [r.label] : [];
|
|
402
|
+
});
|
|
403
|
+
return r.length ? r.join("、") : g(t);
|
|
346
404
|
}
|
|
347
|
-
function
|
|
348
|
-
return
|
|
405
|
+
function U(e) {
|
|
406
|
+
return (e.type === "select" || e.type === "radio") && !e.dataSource && Array.isArray(e.options) && e.options.length > 0;
|
|
407
|
+
}
|
|
408
|
+
function W(e, t) {
|
|
409
|
+
let n = Array.isArray(t) ? t : [t];
|
|
410
|
+
return n.length > 0 && n.every((t) => _(t) && (e.options ?? []).some((e) => String(e.value) === String(t.value)));
|
|
349
411
|
}
|
|
350
412
|
function G(e) {
|
|
351
|
-
return typeof e == "boolean" ? e ? "true" : "
|
|
413
|
+
return typeof e == "boolean" ? e ? "true" : "" : e == null ? "" : g(e);
|
|
352
414
|
}
|
|
353
415
|
function K(e) {
|
|
416
|
+
return typeof e == "boolean" ? e ? "true" : "false" : e == null ? "" : g(e);
|
|
417
|
+
}
|
|
418
|
+
function q(e) {
|
|
354
419
|
return e === !0 || e === "true" || e === "1" || e === "yes" || e === "是" || e === "已选";
|
|
355
420
|
}
|
|
356
|
-
function
|
|
421
|
+
function J(t) {
|
|
357
422
|
if (e()) {
|
|
358
423
|
let e = new DOMParser().parseFromString(t, "text/html");
|
|
359
424
|
return e.querySelectorAll("script,style,meta,link,iframe,object,embed").forEach((e) => e.remove()), e.querySelectorAll("*").forEach((e) => {
|
|
360
425
|
Array.from(e.attributes).forEach((t) => {
|
|
361
426
|
let n = t.name.toLowerCase();
|
|
362
|
-
(n.startsWith("on") || n === "srcdoc" ||
|
|
427
|
+
(n.startsWith("on") || n === "srcdoc" || x.has(n) && Y(t.value) || n === "style" && X(t.value)) && e.removeAttribute(t.name);
|
|
363
428
|
});
|
|
364
429
|
}), e.body.innerHTML;
|
|
365
430
|
}
|
|
366
431
|
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) => {
|
|
367
432
|
let a = r ?? i ?? "";
|
|
368
|
-
return
|
|
369
|
-
}).replace(/\s+style\s*=\s*(["'])(.*?)\1/gi, (e, t, n) =>
|
|
433
|
+
return Y(a) ? "" : n ? ` ${t}=${n}${a}${n}` : ` ${t}=${a}`;
|
|
434
|
+
}).replace(/\s+style\s*=\s*(["'])(.*?)\1/gi, (e, t, n) => X(n) ? "" : ` style=${t}${n}${t}`);
|
|
370
435
|
}
|
|
371
|
-
function
|
|
372
|
-
return n(e,
|
|
436
|
+
function se(e) {
|
|
437
|
+
return n(e, S, (e) => a(e, "data-key"));
|
|
373
438
|
}
|
|
374
|
-
function
|
|
439
|
+
function ce(e) {
|
|
375
440
|
let t = [];
|
|
376
|
-
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("正文包含已移除的事件或嵌入属性"), (
|
|
441
|
+
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("正文包含已移除的事件或嵌入属性"), (le(e) || /style\s*=\s*["'][^"']*(?:expression\s*\(|url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html))/i.test(e)) && t.push("正文包含已移除的危险 URL 或样式"), t;
|
|
377
442
|
}
|
|
378
|
-
function
|
|
443
|
+
function Y(e) {
|
|
379
444
|
let t = e.replace(/&#(?:x([\da-f]+)|(\d+));?/gi, (e, t, n) => {
|
|
380
445
|
let r = Number.parseInt(t ?? n ?? "", t ? 16 : 10);
|
|
381
446
|
try {
|
|
@@ -390,40 +455,40 @@ function X(e) {
|
|
|
390
455
|
})[t.toLowerCase()] ?? "").trim().replace(/[\u0000-\u0020\u007F]+/g, "");
|
|
391
456
|
return /^(?:javascript|vbscript|data:text\/html)/i.test(t);
|
|
392
457
|
}
|
|
393
|
-
function
|
|
458
|
+
function le(e) {
|
|
394
459
|
let t = /\s+(?:action|formaction|href|src|xlink:href)\s*=\s*(?:(["'])(.*?)\1|([^\s>]+))/gi, n = t.exec(e);
|
|
395
460
|
for (; n;) {
|
|
396
|
-
if (
|
|
461
|
+
if (Y(n[2] ?? n[3] ?? "")) return !0;
|
|
397
462
|
n = t.exec(e);
|
|
398
463
|
}
|
|
399
464
|
return !1;
|
|
400
465
|
}
|
|
401
|
-
function
|
|
466
|
+
function X(e) {
|
|
402
467
|
return /expression\s*\(|url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html)/i.test(e);
|
|
403
468
|
}
|
|
404
|
-
function
|
|
405
|
-
return
|
|
469
|
+
function Z(e, t) {
|
|
470
|
+
return N(t) ? e.type === "select" || e.type === "radio" ? B(e) : N(e.defaultValue) ? t : e.defaultValue : t;
|
|
406
471
|
}
|
|
407
|
-
function
|
|
472
|
+
function ue(e, t, n) {
|
|
408
473
|
if (typeof e == "boolean" || typeof e != "number" && typeof e != "string") return !1;
|
|
409
|
-
let
|
|
410
|
-
if (!/^-?(?:\d+)(?:\.\d+)?$/.test(
|
|
411
|
-
let
|
|
412
|
-
if (!Number.isFinite(
|
|
474
|
+
let r = String(e).trim();
|
|
475
|
+
if (!/^-?(?:\d+)(?:\.\d+)?$/.test(r)) return !1;
|
|
476
|
+
let i = Number(r);
|
|
477
|
+
if (!Number.isFinite(i)) return !1;
|
|
413
478
|
if (t !== void 0) {
|
|
414
|
-
let e =
|
|
415
|
-
if (!Number.isInteger(t) || t < 0 || t >
|
|
479
|
+
let e = r.split(".")[1]?.length ?? 0, i = t + (n === "percent" ? 2 : 0);
|
|
480
|
+
if (!Number.isInteger(t) || t < 0 || t > T || e > i) return !1;
|
|
416
481
|
}
|
|
417
482
|
return !0;
|
|
418
483
|
}
|
|
419
|
-
function
|
|
484
|
+
function Q(e) {
|
|
420
485
|
if (typeof e != "string" && typeof e != "number") return !1;
|
|
421
486
|
let t = String(e).trim(), n = /^(\d{4})[-/年](\d{1,2})[-/月](\d{1,2})(?:日)?(?:[T\s].*)?$/.exec(t);
|
|
422
487
|
if (!n) return !1;
|
|
423
488
|
let r = Number(n[1]), i = Number(n[2]), a = Number(n[3]), o = new Date(Date.UTC(r, i - 1, a));
|
|
424
489
|
return o.getUTCFullYear() === r && o.getUTCMonth() === i - 1 && o.getUTCDate() === a;
|
|
425
490
|
}
|
|
426
|
-
function
|
|
491
|
+
function de(e) {
|
|
427
492
|
return typeof e == "boolean" ? !0 : [
|
|
428
493
|
"1",
|
|
429
494
|
"true",
|
|
@@ -439,16 +504,16 @@ function ie(e) {
|
|
|
439
504
|
"未选"
|
|
440
505
|
].includes(String(e).trim().toLowerCase());
|
|
441
506
|
}
|
|
442
|
-
function
|
|
443
|
-
return
|
|
507
|
+
function fe(e) {
|
|
508
|
+
return E.test(e);
|
|
444
509
|
}
|
|
445
|
-
function
|
|
510
|
+
function pe(e) {
|
|
446
511
|
return e === "select" || e === "radio" || e === "user-selector" || e === "dept-selector" || e === "role-selector" || e === "org-selector";
|
|
447
512
|
}
|
|
448
|
-
function
|
|
449
|
-
return t ? Array.isArray(e) && e.every(
|
|
513
|
+
function me(e, t) {
|
|
514
|
+
return t ? Array.isArray(e) && e.every(_) : _(e);
|
|
450
515
|
}
|
|
451
|
-
function
|
|
516
|
+
function he(e, t) {
|
|
452
517
|
let n = e.width;
|
|
453
518
|
if (!Number.isFinite(n) || n <= 0) return !1;
|
|
454
519
|
let r = Math.max(10, Number.isFinite(e.style?.fontSize) && (e.style?.fontSize ?? 0) > 0 ? e.style.fontSize : 14), i = Math.max(1, n - 12) / r, a = (e) => Array.from(e).reduce((e, t) => e + (/[^\x00-\x7f]/.test(t) ? 1 : .55), 0);
|
|
@@ -457,7 +522,7 @@ function ce(e, t) {
|
|
|
457
522
|
function $(e) {
|
|
458
523
|
if (!e || typeof e != "object") return !1;
|
|
459
524
|
let { width: t, height: n } = e;
|
|
460
|
-
return typeof t == "number" && typeof n == "number" && Number.isFinite(t) && Number.isFinite(n) && t >=
|
|
525
|
+
return typeof t == "number" && typeof n == "number" && Number.isFinite(t) && Number.isFinite(n) && t >= C && n >= C && t <= w && n <= w;
|
|
461
526
|
}
|
|
462
527
|
//#endregion
|
|
463
|
-
export {
|
|
528
|
+
export { D as buildInitialRenderValues, M as buildTemplateRenderHtml, j as buildTemplateRenderPages, ie as buildTemplateVariableData, N as isEmptyRenderValue, ae as normalizeRenderValues, oe as resolveTemplateRenderSubmitErrors, J as sanitizeContractRendererHtml, A as validateTemplateRenderStructure, O as validateTemplateRenderValues, k as validateTemplateTextOverflow };
|
package/dist/es/components/pro-contract-template-designer/src/utils/template-variable-render.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_CONTRACT_FONT_FAMILY as e } from "../constants.mjs";
|
|
2
2
|
//#region src/components/pro-contract-template-designer/src/utils/template-variable-render.ts
|
|
3
3
|
function t(t) {
|
|
4
|
-
let r = t.type === void 0 ? "text" : String(t.type), i = Math.max(24,
|
|
4
|
+
let r = t.type === void 0 ? "text" : String(t.type), i = Math.max(24, s(t.width, 160)), a = Math.max(24, s(t.height, 32)), c = t.style?.border ?? t.border ?? r === "image", l = t.style?.underline ?? t.underline ?? (r !== "image" && r !== "checkbox"), u = t.style?.color || t.color || "#1f2937", d = t.style?.background || t.background || "transparent", f = Math.max(10, s(t.style?.fontSize ?? t.fontSize, 14)), p = t.style?.fontFamily || t.fontFamily || e, m = t.style?.placeholderColor || t.placeholderColor || "#7a818b", h = t.style?.lineColor || t.lineColor || "#565b66", g = t.style?.textAlign || t.textAlign || "left", _ = t.style?.borderStyle || t.borderStyle || "solid", v = t.style?.objectFit || t.objectFit || "contain", y = !!t.multiline, b = Math.max(1, s(t.rows, 3)), x = Math.max(18, s(t.lineHeight, 28)), S = b * x, C = v === "fill" ? "100% 100%" : v, w = g === "right" ? "flex-end" : g === "center" ? "center" : "flex-start", T = r === "select" && t.multiple ? "" : String(t.defaultValue || ""), E = n({
|
|
5
5
|
type: r,
|
|
6
6
|
defaultValue: T,
|
|
7
7
|
placeholder: t.placeholder || "",
|
|
@@ -9,12 +9,14 @@ function t(t) {
|
|
|
9
9
|
precision: t.precision,
|
|
10
10
|
useGrouping: t.useGrouping,
|
|
11
11
|
checkedText: t.checkedText || "",
|
|
12
|
-
uncheckedText: t.uncheckedText || ""
|
|
13
|
-
|
|
12
|
+
uncheckedText: t.uncheckedText || "",
|
|
13
|
+
options: t.options,
|
|
14
|
+
multiple: t.multiple
|
|
15
|
+
}), D = T.trim().length > 0, O = !D && E.trim().length > 0, k = r === "checkbox" && o(T), A = r === "image" && D ? `;--gd-contract-variable-image:url('${T.replaceAll("'", "%27")}')` : "";
|
|
14
16
|
return {
|
|
15
17
|
type: r,
|
|
16
18
|
width: i,
|
|
17
|
-
height:
|
|
19
|
+
height: a,
|
|
18
20
|
border: c,
|
|
19
21
|
underline: l,
|
|
20
22
|
color: u,
|
|
@@ -40,16 +42,26 @@ function t(t) {
|
|
|
40
42
|
D ? "has-value" : "",
|
|
41
43
|
k ? "is-checked" : ""
|
|
42
44
|
].filter(Boolean),
|
|
43
|
-
styleText: `--gd-contract-variable-width:${i}px;--gd-contract-variable-height:${
|
|
45
|
+
styleText: `--gd-contract-variable-width:${i}px;--gd-contract-variable-height:${a}px;--gd-contract-variable-rows:${b};--gd-contract-variable-line-height:${x}px;--gd-contract-variable-multiline-height:${S}px;--gd-contract-variable-color:${u};--gd-contract-variable-background:${d};--gd-contract-variable-font-size:${f}px;--gd-contract-variable-font-family:${p};--gd-contract-variable-placeholder-color:${m};--gd-contract-variable-line-color:${h};--gd-contract-variable-text-align:${g};--gd-contract-variable-justify-content:${w};--gd-contract-variable-border-style:${_};--gd-contract-variable-object-fit:${C}${A}`
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
function n(e) {
|
|
47
|
-
let t = e.type || "text", n = e.defaultValue || "",
|
|
48
|
-
|
|
49
|
+
let t = e.type || "text", n = t === "select" && e.multiple ? "" : e.defaultValue || "", i = e.placeholder || "";
|
|
50
|
+
if (t === "checkbox") return n ? o(n) ? e.checkedText || i : e.uncheckedText || i : i;
|
|
51
|
+
if (!n) return i;
|
|
52
|
+
if (t === "date") return r(n, e.format || "");
|
|
53
|
+
if (t === "number") return a(n, {
|
|
49
54
|
format: e.format || "",
|
|
50
55
|
precision: e.precision,
|
|
51
56
|
useGrouping: e.useGrouping
|
|
52
|
-
})
|
|
57
|
+
});
|
|
58
|
+
if (t === "image") return i;
|
|
59
|
+
if (t === "select") {
|
|
60
|
+
let t = e.options?.find((e) => String(e.value ?? "") === n);
|
|
61
|
+
if (t?.label) return t.label;
|
|
62
|
+
if (e.options?.length) return i;
|
|
63
|
+
}
|
|
64
|
+
return n;
|
|
53
65
|
}
|
|
54
66
|
function r(e, t) {
|
|
55
67
|
if (!t) return e;
|
|
@@ -58,17 +70,32 @@ function r(e, t) {
|
|
|
58
70
|
let [, r, i, a] = n;
|
|
59
71
|
return t.replace("YYYY", r).replace("MM", i.padStart(2, "0")).replace("DD", a.padStart(2, "0"));
|
|
60
72
|
}
|
|
61
|
-
|
|
73
|
+
var i = [
|
|
74
|
+
{
|
|
75
|
+
value: "decimal",
|
|
76
|
+
label: "常规数字"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
value: "percent",
|
|
80
|
+
label: "百分比"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
value: "currency",
|
|
84
|
+
label: "人民币金额"
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
function a(e, t) {
|
|
62
88
|
let n = Number(e);
|
|
63
|
-
if (!Number.isFinite(n)) return e;
|
|
64
|
-
let r = n.toLocaleString("zh-CN", {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
89
|
+
if (!e.trim() || !Number.isFinite(n)) return e;
|
|
90
|
+
let r = typeof t.precision == "number" && Number.isInteger(t.precision) && t.precision >= 0 && t.precision <= 20 ? t.precision : void 0, i = n.toLocaleString("zh-CN", {
|
|
91
|
+
style: t.format === "percent" ? "percent" : "decimal",
|
|
92
|
+
useGrouping: t.useGrouping === !0,
|
|
93
|
+
minimumFractionDigits: r ?? 0,
|
|
94
|
+
maximumFractionDigits: r ?? 20
|
|
68
95
|
});
|
|
69
|
-
return t.format === "currency" ? `¥${
|
|
96
|
+
return t.format === "currency" ? `¥${i}` : i;
|
|
70
97
|
}
|
|
71
|
-
function
|
|
98
|
+
function o(e) {
|
|
72
99
|
return [
|
|
73
100
|
"1",
|
|
74
101
|
"true",
|
|
@@ -78,10 +105,10 @@ function a(e) {
|
|
|
78
105
|
"已选"
|
|
79
106
|
].includes(e.trim().toLowerCase());
|
|
80
107
|
}
|
|
81
|
-
function
|
|
108
|
+
function s(e, t) {
|
|
82
109
|
if (e == null || e === "") return t;
|
|
83
110
|
let n = Number(e);
|
|
84
111
|
return Number.isFinite(n) ? n : t;
|
|
85
112
|
}
|
|
86
113
|
//#endregion
|
|
87
|
-
export { t as resolveTemplateVariablePresentation };
|
|
114
|
+
export { i as TEMPLATE_NUMBER_FORMAT_OPTIONS, t as resolveTemplateVariablePresentation };
|