@rytass/bpm-core-react 0.11.0 → 0.12.0

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 (51) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/chunks/FormBuilderView-CLFlfDGe.cjs +3 -0
  3. package/dist/chunks/FormBuilderView-CLFlfDGe.cjs.map +1 -0
  4. package/dist/chunks/FormBuilderView-D4xIuPYB.js +1960 -0
  5. package/dist/chunks/FormBuilderView-D4xIuPYB.js.map +1 -0
  6. package/dist/chunks/FormRendererView-BxGT16z0.cjs +2 -0
  7. package/dist/chunks/FormRendererView-BxGT16z0.cjs.map +1 -0
  8. package/dist/chunks/FormRendererView-DUceSOXe.js +798 -0
  9. package/dist/chunks/FormRendererView-DUceSOXe.js.map +1 -0
  10. package/dist/chunks/{compose-CUOe5Ia9.js → compose-Bb-REfoB.js} +4 -4
  11. package/dist/chunks/{compose-CUOe5Ia9.js.map → compose-Bb-REfoB.js.map} +1 -1
  12. package/dist/chunks/{compose-CyRkXdeu.cjs → compose-DzRYZcqe.cjs} +2 -2
  13. package/dist/chunks/{compose-CyRkXdeu.cjs.map → compose-DzRYZcqe.cjs.map} +1 -1
  14. package/dist/chunks/{designer-Cb3WAC46.js → designer-C6oIO9Kq.js} +2 -2
  15. package/dist/chunks/{designer-Cb3WAC46.js.map → designer-C6oIO9Kq.js.map} +1 -1
  16. package/dist/chunks/{designer-zLliyrHu.cjs → designer-gFUdImeZ.cjs} +2 -2
  17. package/dist/chunks/{designer-zLliyrHu.cjs.map → designer-gFUdImeZ.cjs.map} +1 -1
  18. package/dist/chunks/{detail-Cmw-aQcu.js → detail-BgKgMvYx.js} +391 -390
  19. package/dist/chunks/{detail-Cmw-aQcu.js.map → detail-BgKgMvYx.js.map} +1 -1
  20. package/dist/chunks/{detail-Bp2Nv0cs.cjs → detail-Dnz5aaI-.cjs} +2 -2
  21. package/dist/chunks/{detail-Bp2Nv0cs.cjs.map → detail-Dnz5aaI-.cjs.map} +1 -1
  22. package/dist/pages/instances/detail/index.cjs +1 -1
  23. package/dist/pages/instances/detail/index.js +1 -1
  24. package/dist/pages/templates/compose/index.cjs +1 -1
  25. package/dist/pages/templates/compose/index.js +1 -1
  26. package/dist/pages/templates/designer/index.cjs +1 -1
  27. package/dist/pages/templates/designer/index.js +1 -1
  28. package/dist/views/forms/builder/index.cjs +1 -1
  29. package/dist/views/forms/builder/index.js +1 -1
  30. package/dist/views/forms/renderer/form-data-source-field.d.ts +16 -0
  31. package/dist/views/forms/renderer/index.cjs +1 -1
  32. package/dist/views/forms/renderer/index.js +1 -1
  33. package/dist/views/instances/detail/index.cjs +1 -1
  34. package/dist/views/instances/detail/index.js +1 -1
  35. package/dist/views/instances/new/index.cjs +1 -1
  36. package/dist/views/instances/new/index.cjs.map +1 -1
  37. package/dist/views/instances/new/index.js +48 -48
  38. package/dist/views/instances/new/index.js.map +1 -1
  39. package/dist/views/templates/compose/index.cjs +1 -1
  40. package/dist/views/templates/compose/index.js +1 -1
  41. package/dist/views/templates/designer/index.cjs +1 -1
  42. package/dist/views/templates/designer/index.js +1 -1
  43. package/package.json +3 -3
  44. package/dist/chunks/FormBuilderView-CAqjOYAP.cjs +0 -3
  45. package/dist/chunks/FormBuilderView-CAqjOYAP.cjs.map +0 -1
  46. package/dist/chunks/FormBuilderView-TzSezeqC.js +0 -1479
  47. package/dist/chunks/FormBuilderView-TzSezeqC.js.map +0 -1
  48. package/dist/chunks/FormRendererView-BurlEDUu.js +0 -580
  49. package/dist/chunks/FormRendererView-BurlEDUu.js.map +0 -1
  50. package/dist/chunks/FormRendererView-Dde1s3I0.cjs +0 -2
  51. package/dist/chunks/FormRendererView-Dde1s3I0.cjs.map +0 -1
@@ -0,0 +1,1960 @@
1
+ "use client";
2
+ import { t as e } from "./bpm-form-field-Cao0rMol.js";
3
+ import { t } from "./FormRendererView-DUceSOXe.js";
4
+ import { useEffect as n, useMemo as r, useState as i } from "react";
5
+ import { Accordion as a, Badge as o, BaseCard as s, Button as c, DatePicker as l, DateTimePicker as u, Icon as d, Input as f, Modal as ee, Section as te, SectionGroup as ne, Select as p, Tab as re, TabItem as m, Table as ie, Tag as ae, Textarea as oe, Toggle as se, Typography as h } from "@mezzanine-ui/react";
6
+ import { Fragment as g, jsx as _, jsxs as v } from "react/jsx-runtime";
7
+ import { FormFieldLayout as ce } from "@mezzanine-ui/core/form";
8
+ import { AlignLeftIcon as le, CalendarIcon as y, CheckedIcon as ue, CheckedOutlineIcon as de, CurrencyDollarIcon as b, DotDragVerticalIcon as fe, DotGridIcon as x, FileAttachmentIcon as S, FileIcon as C, ListIcon as pe, PlusIcon as me, TrashIcon as he } from "@mezzanine-ui/icons";
9
+ import { buildConditionExpression as w, buildFormRendererValues as ge, clampOptionalNumber as _e, createFieldDefinition as ve, createTableColumnDefinition as ye, formatDatePickerValue as be, formatDateTimePickerValue as xe, isDateFieldDefinition as Se, isFormDataSourceDescriptorCompatible as Ce, isNumberFieldDefinition as we, isSelectFieldDefinition as Te, lintFormSchema as Ee, listFormDataSources as De, parseConditionRule as Oe, parseOptionalNumberInput as ke, readCompatibleFormDataSourceBindingFields as Ae, readCompatibleFormDataSourceDescriptors as je, readCompatibleFormTableColumnBindingFields as Me, readConditionOperatorOption as Ne, readConditionOperatorOptions as Pe, readDatePickerValue as Fe, readDefaultConditionOperator as Ie, readDefaultConditionValue as Le, readFieldOptionAsSelectOption as Re, readFormDataSourceBinding as T, readFormDataSourceBindingValue as ze, readFormDataSourceBindingValueKind as Be, readFormDataSourceFieldDependencyKeys as Ve, readFormSchemaLintMessage as He, readFormTableRowBounds as Ue, readSelectOption as E, renameFormDataSourceFieldBindings as We, renameFormTableColumnBindings as Ge, upsertFormDataSourceFieldBinding as Ke } from "@rytass/bpm-core-client/form";
10
+ import { FORM_TABLE_MAX_ROWS as qe, isFormDataSourceFieldDefinition as D, isFormOptionFieldDefinition as Je, isFormStaticOptionFieldDefinition as O, isTableColumnFieldType as Ye, isTableFieldDefinition as k, readFormFieldSelectionMode as A } from "@rytass/bpm-core-shared/form";
11
+ import { DragDropContext as Xe, Draggable as Ze, Droppable as Qe } from "@hello-pangea/dnd";
12
+ import $e from "next/dynamic";
13
+ import { json as j } from "@codemirror/lang-json";
14
+ import { EditorView as M } from "@codemirror/view";
15
+ //#region src/views/forms/builder/json-code-editor.tsx
16
+ var N = {
17
+ alignItems: "center",
18
+ border: "1px solid var(--mzn-color-border-neutral)",
19
+ borderRadius: 4,
20
+ color: "var(--mzn-color-text-neutral)",
21
+ display: "flex",
22
+ minHeight: 160,
23
+ padding: 12,
24
+ width: "100%"
25
+ }, et = [
26
+ j(),
27
+ M.lineWrapping,
28
+ M.theme({
29
+ "&": {
30
+ border: "1px solid var(--mzn-color-border-neutral)",
31
+ borderRadius: "4px",
32
+ fontSize: "13px",
33
+ width: "100%"
34
+ },
35
+ "&.cm-focused": { outline: "1px solid var(--mzn-color-border-primary)" },
36
+ ".cm-content": {
37
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", monospace",
38
+ minHeight: "100%"
39
+ },
40
+ ".cm-editor": { width: "100%" },
41
+ ".cm-gutters": { borderRight: "1px solid var(--mzn-color-border-neutral)" },
42
+ ".cm-scroller": { fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", monospace" }
43
+ })
44
+ ], P = $e(() => import("@uiw/react-codemirror"), {
45
+ loading: () => /* @__PURE__ */ _("div", {
46
+ style: N,
47
+ children: "載入 JSON 編輯器"
48
+ }),
49
+ ssr: !1
50
+ });
51
+ function tt({ disabled: e = !1, height: t, name: n, onChange: r, placeholder: i, value: a }) {
52
+ return /* @__PURE__ */ _(P, {
53
+ "aria-label": n,
54
+ basicSetup: {
55
+ autocompletion: !0,
56
+ bracketMatching: !0,
57
+ closeBrackets: !0,
58
+ defaultKeymap: !0,
59
+ foldGutter: !0,
60
+ highlightActiveLine: !0,
61
+ highlightSelectionMatches: !0,
62
+ lineNumbers: !0,
63
+ syntaxHighlighting: !0
64
+ },
65
+ editable: !e,
66
+ extensions: [...et],
67
+ height: t,
68
+ indentWithTab: !1,
69
+ onChange: r,
70
+ placeholder: i,
71
+ readOnly: e,
72
+ theme: "light",
73
+ value: a,
74
+ width: "100%"
75
+ });
76
+ }
77
+ //#endregion
78
+ //#region src/views/forms/builder/FormBuilderView.tsx
79
+ var F = [
80
+ {
81
+ description: "單行文字、姓名、編號",
82
+ icon: le,
83
+ label: "文字",
84
+ type: "text"
85
+ },
86
+ {
87
+ description: "多行補充內容",
88
+ icon: C,
89
+ label: "長文字",
90
+ type: "textarea"
91
+ },
92
+ {
93
+ description: "金額、數量、分數",
94
+ icon: b,
95
+ label: "數字",
96
+ type: "number"
97
+ },
98
+ {
99
+ description: "金額與費用",
100
+ icon: b,
101
+ label: "金額",
102
+ type: "money"
103
+ },
104
+ {
105
+ description: "日期或到期日",
106
+ icon: y,
107
+ label: "日期",
108
+ type: "date"
109
+ },
110
+ {
111
+ description: "日期與時間",
112
+ icon: y,
113
+ label: "日期時間",
114
+ type: "datetime"
115
+ },
116
+ {
117
+ description: "是 / 否狀態",
118
+ icon: ue,
119
+ label: "開關",
120
+ type: "boolean"
121
+ },
122
+ {
123
+ description: "固定選項擇一",
124
+ icon: pe,
125
+ label: "下拉選單",
126
+ type: "select"
127
+ },
128
+ {
129
+ description: "可搜尋的固定選項",
130
+ icon: pe,
131
+ label: "自動完成",
132
+ type: "autocomplete"
133
+ },
134
+ {
135
+ description: "固定選項單選",
136
+ icon: x,
137
+ label: "單選",
138
+ type: "radio"
139
+ },
140
+ {
141
+ description: "固定選項複選",
142
+ icon: de,
143
+ label: "複選",
144
+ type: "checkbox"
145
+ },
146
+ {
147
+ description: "附件或佐證資料",
148
+ icon: S,
149
+ label: "附件",
150
+ type: "file_upload"
151
+ },
152
+ {
153
+ description: "多列多欄明細",
154
+ icon: x,
155
+ label: "表格",
156
+ type: "table"
157
+ }
158
+ ], I = F.filter((e) => Ye(e.type)).map((e) => ({
159
+ id: e.type,
160
+ name: e.label
161
+ })), nt = {
162
+ alignItems: "start",
163
+ display: "flex",
164
+ flexWrap: "wrap",
165
+ gap: 16
166
+ }, rt = {
167
+ flex: "0.55 1 300px",
168
+ minWidth: 0
169
+ }, it = {
170
+ flex: "1.45 1 720px",
171
+ minWidth: 620,
172
+ paddingBottom: 260
173
+ }, at = 240, ot = {
174
+ BOOLEAN: "開關",
175
+ NUMBER: "數字",
176
+ STRING: "文字或選單",
177
+ STRING_ARRAY: "多選"
178
+ }, st = /^schema\.fields\[(\d+)\](?:\.columns\[(\d+)\])?\.dataSource\.bindings missing required parameter: (.+)$/u, ct = /^schema\.fields\[(\d+)\](?:\.columns\[(\d+)\])?\.dataSource\.bindings unknown parameter: (.+)$/u, L = {
179
+ display: "grid",
180
+ gap: 12
181
+ }, lt = {
182
+ display: "flex",
183
+ flexWrap: "wrap",
184
+ gap: 6
185
+ }, ut = {
186
+ flex: "0 0 auto",
187
+ whiteSpace: "nowrap"
188
+ }, dt = {
189
+ display: "grid",
190
+ gap: 8
191
+ }, ft = {
192
+ alignItems: "center",
193
+ cursor: "grab",
194
+ display: "flex",
195
+ gap: 12,
196
+ touchAction: "none"
197
+ }, pt = {
198
+ display: "grid",
199
+ flex: "1 1 auto",
200
+ gap: 2,
201
+ minWidth: 0
202
+ }, mt = {
203
+ alignItems: "center",
204
+ display: "flex",
205
+ flex: "0 0 auto",
206
+ gap: 4
207
+ }, ht = {
208
+ alignItems: "center",
209
+ display: "flex",
210
+ gap: 6
211
+ }, gt = {
212
+ cursor: "pointer",
213
+ userSelect: "none"
214
+ }, _t = { filter: "drop-shadow(0 8px 18px rgba(0, 0, 0, 0.12))" }, vt = {
215
+ backgroundColor: "color-mix(in srgb, var(--mzn-color-primary) 8%, var(--mzn-color-bg-surface))",
216
+ boxShadow: "inset 0 0 0 1px var(--mzn-color-border-primary)"
217
+ }, yt = {
218
+ alignItems: "center",
219
+ border: "1px dashed var(--mzn-color-border-neutral)",
220
+ borderRadius: 6,
221
+ display: "grid",
222
+ gap: 12,
223
+ minHeight: 240,
224
+ padding: 32,
225
+ textAlign: "center"
226
+ }, bt = {
227
+ display: "flex",
228
+ gap: 8,
229
+ justifyContent: "center"
230
+ }, xt = {
231
+ display: "grid",
232
+ gap: 14
233
+ }, St = {
234
+ display: "grid",
235
+ columnGap: 16,
236
+ gridTemplateColumns: "repeat(auto-fit, minmax(280px, 360px))",
237
+ justifyContent: "start",
238
+ maxWidth: 736,
239
+ rowGap: 8
240
+ }, Ct = { gridColumn: "1 / -1" }, wt = {
241
+ alignItems: "center",
242
+ display: "flex",
243
+ gap: 8,
244
+ gridColumn: "1 / -1",
245
+ justifyContent: "flex-end"
246
+ }, Tt = { gridColumn: "1 / -1" }, Et = {
247
+ alignItems: "start",
248
+ display: "block",
249
+ width: "100%"
250
+ }, Dt = {
251
+ ...Et,
252
+ gridColumn: "1 / -1"
253
+ }, Ot = {
254
+ minWidth: 0,
255
+ width: "100%"
256
+ }, kt = {
257
+ minWidth: "100%",
258
+ width: "100%"
259
+ }, At = {
260
+ display: "grid",
261
+ gap: 14
262
+ }, jt = {
263
+ alignItems: "start",
264
+ display: "block",
265
+ width: "100%"
266
+ }, Mt = {
267
+ minWidth: 0,
268
+ width: "100%"
269
+ }, Nt = { gridColumn: "2 / -1" }, Pt = {
270
+ display: "grid",
271
+ gap: 10,
272
+ width: "100%"
273
+ }, Ft = {
274
+ display: "grid",
275
+ gap: 8,
276
+ gridTemplateColumns: "repeat(auto-fit, minmax(160px, 1fr))"
277
+ }, It = { display: "inline-flex" }, Lt = {
278
+ display: "grid",
279
+ gap: 16
280
+ }, Rt = {
281
+ display: "grid",
282
+ gap: 8
283
+ }, zt = {
284
+ display: "flex",
285
+ justifyContent: "flex-end"
286
+ }, Bt = {
287
+ color: "var(--mzn-color-text-error)",
288
+ fontSize: "0.72em",
289
+ lineHeight: 0,
290
+ marginLeft: 2,
291
+ verticalAlign: "super"
292
+ }, Vt = {
293
+ display: "grid",
294
+ gap: 10,
295
+ gridColumn: "1 / -1"
296
+ }, Ht = {
297
+ display: "grid",
298
+ gap: 2
299
+ }, Ut = {
300
+ display: "grid",
301
+ gap: 8
302
+ }, Wt = {
303
+ display: "flex",
304
+ justifyContent: "flex-start"
305
+ }, Gt = {
306
+ display: "flex",
307
+ flexWrap: "wrap",
308
+ gap: 4
309
+ }, Kt = {
310
+ backgroundColor: "var(--mzn-color-bg-surface-secondary)",
311
+ borderRadius: 6,
312
+ display: "grid",
313
+ gap: 4,
314
+ padding: 10
315
+ }, qt = {
316
+ ...St,
317
+ gridTemplateColumns: "minmax(280px, 520px)",
318
+ padding: "4px 0 8px"
319
+ }, Jt = {
320
+ display: "grid",
321
+ gap: 8,
322
+ gridColumn: "1 / -1"
323
+ }, Yt = {
324
+ alignItems: "center",
325
+ display: "flex",
326
+ gap: 12,
327
+ justifyContent: "space-between"
328
+ }, Xt = {
329
+ alignItems: "baseline",
330
+ display: "flex",
331
+ gap: 2
332
+ }, Zt = {
333
+ display: "grid",
334
+ gap: 4
335
+ };
336
+ function Qt(e) {
337
+ e && (e.style.width = "100%");
338
+ }
339
+ var $t = {
340
+ fields: [],
341
+ schemaVersion: 1
342
+ }, en = {
343
+ layout: [],
344
+ schemaVersion: 1
345
+ }, tn = "__STATIC_OPTIONS__", nn = "__CONSTANT__", rn = "__ROW_FIELD__:", an = "__UNBOUND__", on = [{
346
+ id: tn,
347
+ name: "靜態選項"
348
+ }], sn = [{
349
+ id: "single",
350
+ name: "單選"
351
+ }, {
352
+ id: "multiple",
353
+ name: "複選"
354
+ }], cn = [
355
+ {
356
+ id: "unset",
357
+ name: "不預設"
358
+ },
359
+ {
360
+ id: "true",
361
+ name: "是"
362
+ },
363
+ {
364
+ id: "false",
365
+ name: "否"
366
+ }
367
+ ], ln = [{
368
+ id: "true",
369
+ name: "是"
370
+ }, {
371
+ id: "false",
372
+ name: "否"
373
+ }], un = [
374
+ {
375
+ label: "顯示",
376
+ name: "fieldVisibleWhen",
377
+ supportingText: "符合條件時才顯示這個欄位。",
378
+ target: "visibleWhen"
379
+ },
380
+ {
381
+ label: "必填",
382
+ name: "fieldRequiredWhen",
383
+ supportingText: "符合條件時才要求填寫這個欄位。",
384
+ target: "requiredWhen"
385
+ },
386
+ {
387
+ label: "唯讀",
388
+ name: "fieldReadonlyWhen",
389
+ supportingText: "符合條件時不允許修改這個欄位。",
390
+ target: "readonlyWhen"
391
+ }
392
+ ];
393
+ function R({ onChange: le, value: y }) {
394
+ let ue = y?.schema ?? $t, de = y?.uiSchema ?? en, [b, x] = i(ue), [S, C] = i(de), [pe, O] = i(V(ue)), [$e, j] = i(V(de)), [M, N] = i({}), [et, P] = i(null), [R, gn] = i("design"), [z, B] = i(null), [H, jn] = i([]), [Mn, Nn] = i(null), [Pn, Fn] = i("loading"), [In, U] = i(null), [Ln, Rn] = i(!1), [W, G] = i(null), [zn, K] = i(null);
395
+ n(() => {
396
+ let e = !0;
397
+ return De().then((t) => {
398
+ e && (jn(t), Nn(null), Fn("ready"));
399
+ }).catch((t) => {
400
+ e && (jn([]), Nn("目前無法載入 DataSource Catalog,請稍後重試。"), Fn("unavailable"));
401
+ }), () => {
402
+ e = !1;
403
+ };
404
+ }, []), n(() => {
405
+ b.fields.some((e) => e.fieldKey === z) || B(b.fields[0]?.fieldKey ?? null);
406
+ }, [b.fields, z]), n(() => {
407
+ N((e) => ge(b.fields, e));
408
+ }, [b.fields]), n(() => {
409
+ R !== "advanced" && (O(V(b)), j(V(S)));
410
+ }, [
411
+ R,
412
+ b,
413
+ S
414
+ ]);
415
+ let q = r(() => b.fields.find((e) => e.fieldKey === z) ?? b.fields[0] ?? null, [b.fields, z]);
416
+ n(() => {
417
+ le?.({
418
+ schema: b,
419
+ uiSchema: S
420
+ });
421
+ }, [b, S]);
422
+ function Bn(e) {
423
+ let t = b.fields.length + 1, n = ve(e, t);
424
+ x({
425
+ ...b,
426
+ fields: [...b.fields, n]
427
+ }), C({
428
+ ...S,
429
+ layout: [...S.layout, {
430
+ fieldKey: n.fieldKey,
431
+ width: e === "textarea" || e === "file_upload" || e === "table" ? "FULL" : "HALF"
432
+ }]
433
+ }), B(n.fieldKey), gn("design"), P(null);
434
+ }
435
+ function Vn(e) {
436
+ let t = e;
437
+ t === "advanced" && R !== "advanced" && (O(V(b)), j(V(S))), gn(t);
438
+ }
439
+ function Hn(e) {
440
+ let t = b.fields.flatMap((t) => k(t) ? t.columns.flatMap((n) => D(n) && Ve(n).includes(e) ? [`${t.fieldKey}.${n.fieldKey}`] : []) : D(t) && Ve(t).includes(e) ? [t.fieldKey] : []);
441
+ if (t.length > 0) {
442
+ G({
443
+ affectedFieldKeys: t,
444
+ fieldKey: e,
445
+ kind: "remove-field"
446
+ });
447
+ return;
448
+ }
449
+ Un(e);
450
+ }
451
+ function Un(e) {
452
+ let t = b.fields.filter((t) => t.fieldKey !== e);
453
+ x({
454
+ ...b,
455
+ fields: t
456
+ }), C({
457
+ ...S,
458
+ layout: S.layout.filter((t) => t.fieldKey !== e)
459
+ }), B(z === e ? t[0]?.fieldKey ?? null : z), P(null), U(null);
460
+ }
461
+ function Wn(e) {
462
+ let t = e.destination;
463
+ t && e.source.index !== t.index && (x((n) => ({
464
+ ...n,
465
+ fields: An(n.fields, e.source.index, t.index)
466
+ })), C((n) => ({
467
+ ...n,
468
+ layout: An(n.layout, e.source.index, t.index)
469
+ })), P(null));
470
+ }
471
+ function J(e) {
472
+ Gn((t) => ({
473
+ ...t,
474
+ ...e
475
+ }));
476
+ }
477
+ function Gn(e) {
478
+ if (!q) return;
479
+ let t = q.fieldKey, n = e(q), r = n.fieldKey, i = {
480
+ ...b,
481
+ fields: b.fields.map((e) => e.fieldKey === t ? n : e)
482
+ }, a = t === r ? i : We(i, t, r);
483
+ x(a), C({
484
+ ...S,
485
+ layout: S.layout.map((e) => e.fieldKey === t ? {
486
+ ...e,
487
+ fieldKey: r
488
+ } : e)
489
+ }), B(r), P(null), U(null);
490
+ }
491
+ function Kn(e) {
492
+ Gn(() => e);
493
+ }
494
+ function Y(e, t) {
495
+ x((n) => ({
496
+ ...n,
497
+ fields: n.fields.map((n) => n.fieldKey === e && k(n) ? t(n) : n)
498
+ })), P(null), U(null);
499
+ }
500
+ function X(e, t, n) {
501
+ let r = e.columns[t]?.fieldKey;
502
+ Y(e.fieldKey, (e) => {
503
+ let i = {
504
+ ...e,
505
+ columns: e.columns.map((e, r) => r === t ? n : e)
506
+ };
507
+ return typeof r == "string" && r !== n.fieldKey ? Ge(i, r, n.fieldKey) : i;
508
+ });
509
+ }
510
+ function qn(e) {
511
+ let t = ye(e.columns, "text");
512
+ Y(e.fieldKey, (e) => ({
513
+ ...e,
514
+ columns: [...e.columns, t]
515
+ })), K(e.columns.length);
516
+ }
517
+ function Jn(e, t) {
518
+ Y(e, (e) => ({
519
+ ...e,
520
+ columns: e.columns.filter((e, n) => n !== t)
521
+ })), K((e) => e === null || e < t ? e : e === t ? null : e - 1);
522
+ }
523
+ function Yn(e, t, n) {
524
+ Y(e.fieldKey, (e) => ({
525
+ ...e,
526
+ columns: An(e.columns, t, n)
527
+ })), K((e) => e === null ? e : e === t ? n : e > t && e <= n ? e - 1 : e < t && e >= n ? e + 1 : e);
528
+ }
529
+ function Xn(e, t, n) {
530
+ if (e.type !== "select" && e.type !== "autocomplete" || A(e) === t) return;
531
+ let r = e.defaultValue, i = t === "multiple" ? typeof r == "string" ? [r] : r : Array.isArray(r) ? r[0] : r;
532
+ n(e, {
533
+ ...e,
534
+ defaultValue: i,
535
+ mode: t
536
+ }, "選擇模式變更可能轉換或捨棄既有預設值。");
537
+ }
538
+ function Zn(e, t, n = "此變更會替換目前選項來源;既有 options、dynamic reference 或 bindings 可能失效。") {
539
+ JSON.stringify(e) !== JSON.stringify(t) && G({
540
+ fieldKey: e.fieldKey,
541
+ impact: n,
542
+ kind: "replace-field",
543
+ nextField: t
544
+ });
545
+ }
546
+ function Qn(e, t, n) {
547
+ if (!t) return;
548
+ if (t === tn) {
549
+ if (!D(e)) return;
550
+ let { dataSource: t, defaultValue: r, ...i } = e;
551
+ n({
552
+ ...i,
553
+ options: []
554
+ });
555
+ return;
556
+ }
557
+ let r = H.find((e) => fn(e) === t);
558
+ if (!r) return;
559
+ if (D(e)) {
560
+ let t = new Set(r.parameters.map((e) => e.key)), i = e.dataSource.bindings.filter((e) => t.has(e.parameter));
561
+ n({
562
+ ...e,
563
+ dataSource: {
564
+ bindings: i,
565
+ key: r.key,
566
+ version: r.version
567
+ }
568
+ });
569
+ return;
570
+ }
571
+ let { options: i, defaultValue: a, ...o } = e;
572
+ n({
573
+ ...o,
574
+ dataSource: {
575
+ bindings: [],
576
+ key: r.key,
577
+ version: r.version
578
+ }
579
+ });
580
+ }
581
+ function $n() {
582
+ W && (er(W), G(null));
583
+ }
584
+ function er(e) {
585
+ if (e.kind === "remove-field") {
586
+ Un(e.fieldKey);
587
+ return;
588
+ }
589
+ if (e.kind === "remove-column") {
590
+ Jn(e.fieldKey, e.columnIndex);
591
+ return;
592
+ }
593
+ if (e.kind === "replace-column") {
594
+ Y(e.fieldKey, (t) => ({
595
+ ...t,
596
+ columns: t.columns.map((t) => t.fieldKey === e.columnKey ? e.nextColumn : t)
597
+ })), K(e.columnIndex);
598
+ return;
599
+ }
600
+ x({
601
+ ...b,
602
+ fields: b.fields.map((t) => t.fieldKey === e.fieldKey ? e.nextField : t)
603
+ }), P(null), U(null);
604
+ }
605
+ async function tr() {
606
+ Rn(!0);
607
+ try {
608
+ let e = await Ee(b, S);
609
+ U(e.errors.map(nr));
610
+ } catch {
611
+ U(["目前無法完成 DataSource schema 驗證。"]);
612
+ } finally {
613
+ Rn(!1);
614
+ }
615
+ }
616
+ function nr(e) {
617
+ let t = st.exec(e);
618
+ if (t?.[1] && t[3]) return `${rr(t[1], t[2])}尚未指定必要參數「${ir(t[1], t[2], t[3])}」的來源`;
619
+ let n = ct.exec(e);
620
+ return n?.[1] && n[3] ? `${rr(n[1], n[2])}綁定了來源沒有的參數「${n[3]}」` : He(e);
621
+ }
622
+ function rr(e, t) {
623
+ let n = b.fields[Number(e)];
624
+ if (!n) return "";
625
+ let r = n.label || n.fieldKey, i = ar(n, t);
626
+ return i ? `「${r}」表格的「${i.label || i.fieldKey}」欄` : `「${r}」欄位`;
627
+ }
628
+ function ir(e, t, n) {
629
+ let r = b.fields[Number(e)];
630
+ if (!r) return n;
631
+ let i = ar(r, t) ?? r, a = D(i) ? i.dataSource : null;
632
+ return (a ? H.find((e) => e.key === a.key && e.version === a.version) : void 0)?.parameters.find((e) => e.key === n)?.label || n;
633
+ }
634
+ function ar(e, t) {
635
+ return typeof t == "string" && k(e) ? e.columns[Number(t)] : void 0;
636
+ }
637
+ function or(e) {
638
+ N(e);
639
+ }
640
+ function sr(e, t) {
641
+ x((n) => ({
642
+ ...n,
643
+ fields: n.fields.map((n) => n.fieldKey === e ? {
644
+ ...n,
645
+ required: t
646
+ } : n)
647
+ })), P(null);
648
+ }
649
+ function cr(e) {
650
+ O(e);
651
+ try {
652
+ x(JSON.parse(e)), P(null);
653
+ } catch {
654
+ P("Form Schema JSON 格式不正確");
655
+ }
656
+ }
657
+ function lr(e) {
658
+ j(e);
659
+ try {
660
+ C(JSON.parse(e)), P(null);
661
+ } catch {
662
+ P("UI Schema JSON 格式不正確");
663
+ }
664
+ }
665
+ return /* @__PURE__ */ v(g, { children: [/* @__PURE__ */ _(g, { children: /* @__PURE__ */ _(ne, { children: /* @__PURE__ */ _(te, { children: /* @__PURE__ */ v("div", {
666
+ style: Lt,
667
+ children: [
668
+ /* @__PURE__ */ v(re, {
669
+ activeKey: R,
670
+ onChange: Vn,
671
+ size: "sub",
672
+ children: [
673
+ /* @__PURE__ */ _(m, { children: "設計" }, "design"),
674
+ /* @__PURE__ */ _(m, { children: "預覽" }, "preview"),
675
+ /* @__PURE__ */ _(m, { children: "進階" }, "advanced")
676
+ ]
677
+ }),
678
+ R === "design" ? ur() : null,
679
+ R === "preview" ? Yr() : null,
680
+ R === "advanced" ? Xr() : null
681
+ ]
682
+ }) }) }) }), W ? /* @__PURE__ */ _(ee, {
683
+ cancelText: "返回",
684
+ confirmText: "確認變更",
685
+ modalType: "standard",
686
+ onCancel: () => G(null),
687
+ onClose: () => G(null),
688
+ onConfirm: $n,
689
+ open: !0,
690
+ showModalFooter: !0,
691
+ showModalHeader: !0,
692
+ title: yn(W),
693
+ children: W.kind === "remove-field" ? /* @__PURE__ */ v("div", {
694
+ style: Rt,
695
+ children: [/* @__PURE__ */ _(h, {
696
+ variant: "body",
697
+ children: "此欄位仍被下列 DataSource binding 使用;移除後請重新設定這些欄位。"
698
+ }), /* @__PURE__ */ _(h, {
699
+ color: "text-warning",
700
+ variant: "body",
701
+ children: W.affectedFieldKeys.join("、")
702
+ })]
703
+ }) : W.kind === "remove-column" ? /* @__PURE__ */ v(h, {
704
+ variant: "body",
705
+ children: [
706
+ "移除欄「",
707
+ W.columnKey,
708
+ "」後,既有案件仍保留原本的表單版本,但新版本的這一欄資料將不再被填寫。"
709
+ ]
710
+ }) : /* @__PURE__ */ _(h, {
711
+ variant: "body",
712
+ children: W.impact
713
+ })
714
+ }) : null] });
715
+ function ur() {
716
+ return /* @__PURE__ */ v("div", {
717
+ style: L,
718
+ children: [/* @__PURE__ */ v("div", {
719
+ style: dt,
720
+ children: [/* @__PURE__ */ _(h, {
721
+ component: "h2",
722
+ variant: "label-primary",
723
+ children: "新增欄位"
724
+ }), /* @__PURE__ */ _("div", {
725
+ style: lt,
726
+ children: F.map((e) => /* @__PURE__ */ _(c, {
727
+ icon: e.icon,
728
+ iconType: "leading",
729
+ onClick: () => Bn(e.type),
730
+ size: "sub",
731
+ style: ut,
732
+ type: "button",
733
+ variant: "base-secondary",
734
+ children: e.label
735
+ }, e.type))
736
+ })]
737
+ }), /* @__PURE__ */ v("div", {
738
+ style: nt,
739
+ children: [/* @__PURE__ */ v("div", {
740
+ style: {
741
+ ...L,
742
+ ...rt
743
+ },
744
+ children: [/* @__PURE__ */ _(h, {
745
+ component: "h2",
746
+ variant: "label-primary",
747
+ children: "表單畫布"
748
+ }), b.fields.length > 0 ? /* @__PURE__ */ _(Xe, {
749
+ onDragEnd: Wn,
750
+ children: /* @__PURE__ */ _(Qe, {
751
+ droppableId: "form-builder-fields",
752
+ children: (e) => /* @__PURE__ */ v("div", {
753
+ ...e.droppableProps,
754
+ ref: e.innerRef,
755
+ style: L,
756
+ children: [b.fields.map((e, t) => /* @__PURE__ */ _(Ze, {
757
+ draggableId: e.fieldKey,
758
+ index: t,
759
+ children: (t, n) => qr(e, t, n.isDragging)
760
+ }, e.fieldKey)), e.placeholder]
761
+ })
762
+ })
763
+ }) : /* @__PURE__ */ v("div", {
764
+ style: yt,
765
+ children: [/* @__PURE__ */ v("div", {
766
+ style: L,
767
+ children: [/* @__PURE__ */ _(h, {
768
+ component: "h3",
769
+ variant: "h3",
770
+ children: "尚未建立欄位"
771
+ }), /* @__PURE__ */ _(h, {
772
+ color: "text-neutral",
773
+ variant: "body",
774
+ children: "從上方新增第一個欄位,或直接建立常用文字欄位開始設計。"
775
+ })]
776
+ }), /* @__PURE__ */ v("div", {
777
+ style: bt,
778
+ children: [/* @__PURE__ */ _(c, {
779
+ onClick: () => Bn("text"),
780
+ variant: "base-primary",
781
+ children: "新增文字欄位"
782
+ }), /* @__PURE__ */ _(c, {
783
+ onClick: () => Bn("textarea"),
784
+ variant: "base-secondary",
785
+ children: "新增長文字"
786
+ })]
787
+ })]
788
+ })]
789
+ }), /* @__PURE__ */ v("div", {
790
+ style: {
791
+ ...L,
792
+ ...it
793
+ },
794
+ children: [/* @__PURE__ */ _(h, {
795
+ component: "h2",
796
+ variant: "label-primary",
797
+ children: "欄位設定"
798
+ }), q ? dr(q) : /* @__PURE__ */ _(h, {
799
+ color: "text-neutral",
800
+ variant: "body",
801
+ children: "請先新增或選取欄位。"
802
+ })]
803
+ })]
804
+ })]
805
+ });
806
+ }
807
+ function dr(e) {
808
+ return /* @__PURE__ */ v("div", {
809
+ style: xt,
810
+ children: [
811
+ fr(e),
812
+ k(e) ? gr(e) : null,
813
+ pr(e)
814
+ ]
815
+ });
816
+ }
817
+ function fr(e) {
818
+ return /* @__PURE__ */ v("div", {
819
+ style: St,
820
+ children: [
821
+ /* @__PURE__ */ _("div", {
822
+ style: wt,
823
+ children: /* @__PURE__ */ _(o, {
824
+ size: "main",
825
+ text: dn(e.type),
826
+ variant: "text-info"
827
+ })
828
+ }),
829
+ $("標題", "fieldLabel", /* @__PURE__ */ _(f, {
830
+ onChange: (e) => J({ label: e.target.value }),
831
+ placeholder: "例如:申請金額",
832
+ value: e.label,
833
+ variant: "base"
834
+ })),
835
+ $("欄位 Key", "fieldKey", /* @__PURE__ */ _(f, {
836
+ onChange: (e) => J({ fieldKey: e.target.value }),
837
+ placeholder: "例如:amount",
838
+ value: e.fieldKey,
839
+ variant: "base"
840
+ })),
841
+ k(e) ? null : $("提示文字", "fieldPlaceholder", /* @__PURE__ */ _(f, {
842
+ onChange: (e) => J({ placeholder: e.target.value || void 0 }),
843
+ placeholder: "例如:請輸入申請金額",
844
+ value: e.placeholder ?? "",
845
+ variant: "base"
846
+ })),
847
+ mr(e, Kn, Zn)
848
+ ]
849
+ });
850
+ }
851
+ function pr(e) {
852
+ return /* @__PURE__ */ _(a, {
853
+ defaultExpanded: Sn(e),
854
+ size: "sub",
855
+ title: "進階設定",
856
+ children: /* @__PURE__ */ v("div", {
857
+ style: St,
858
+ children: [
859
+ /* @__PURE__ */ _(h, {
860
+ component: "h3",
861
+ style: Ct,
862
+ variant: "label-primary",
863
+ children: "條件規則"
864
+ }),
865
+ /* @__PURE__ */ _(h, {
866
+ color: "text-neutral",
867
+ style: Tt,
868
+ variant: "body",
869
+ children: "只有需要根據其他欄位改變顯示、必填或唯讀狀態時才需要設定。"
870
+ }),
871
+ Vr(e)
872
+ ]
873
+ })
874
+ });
875
+ }
876
+ function mr(e, t, n, r) {
877
+ return wn(e) ? Sr(e, t) : we(e) ? Cr(e, t) : Se(e) ? wr(e, t) : Je(e) ? Tr(e, t, n, r) : e.type === "boolean" ? zr(e, t) : e.type === "file_upload" ? Br(e, t) : k(e) ? hr(e) : null;
878
+ }
879
+ function hr(e) {
880
+ let t = Ue(e);
881
+ return /* @__PURE__ */ v(g, { children: [
882
+ $("最少列數", "fieldMinRows", Q(e.minRows, (t) => Y(e.fieldKey, (e) => ({
883
+ ...e,
884
+ minRows: t
885
+ })), "例如:1", {
886
+ max: t.maxRows,
887
+ min: 0
888
+ })),
889
+ $("最多列數", "fieldMaxRows", Q(e.maxRows, (t) => Y(e.fieldKey, (e) => ({
890
+ ...e,
891
+ maxRows: t
892
+ })), `未設定即為 ${qe}`, {
893
+ max: qe,
894
+ min: Math.max(t.minRows, 1)
895
+ })),
896
+ $("新增列按鈕文字", "fieldAddRowLabel", /* @__PURE__ */ _(f, {
897
+ onChange: (t) => Y(e.fieldKey, (e) => ({
898
+ ...e,
899
+ addRowLabel: t.target.value || void 0
900
+ })),
901
+ placeholder: "預設為「新增一列」",
902
+ value: e.addRowLabel ?? "",
903
+ variant: "base"
904
+ }))
905
+ ] });
906
+ }
907
+ function gr(e) {
908
+ return /* @__PURE__ */ v("div", {
909
+ style: Jt,
910
+ children: [/* @__PURE__ */ v("div", {
911
+ style: Yt,
912
+ children: [/* @__PURE__ */ v(h, {
913
+ component: "h3",
914
+ variant: "label-primary",
915
+ children: [
916
+ "欄(",
917
+ e.columns.length,
918
+ ")"
919
+ ]
920
+ }), /* @__PURE__ */ _(c, {
921
+ icon: me,
922
+ iconType: "leading",
923
+ onClick: () => qn(e),
924
+ size: "sub",
925
+ type: "button",
926
+ variant: "base-secondary",
927
+ children: "新增欄"
928
+ })]
929
+ }), _r(e)]
930
+ });
931
+ }
932
+ function _r(e) {
933
+ let t = e.columns.map((t, n) => ({
934
+ fieldKey: t.fieldKey,
935
+ index: n,
936
+ key: `${e.fieldKey}-column-${n}`,
937
+ label: t.label,
938
+ type: t.type
939
+ })), n = [
940
+ {
941
+ key: "label",
942
+ render: (t) => /* @__PURE__ */ _(f, {
943
+ fullWidth: !0,
944
+ onChange: (n) => X(e, t.index, {
945
+ ...xr(e, t.index),
946
+ label: n.target.value
947
+ }),
948
+ placeholder: "例如:數量",
949
+ size: "sub",
950
+ value: t.label,
951
+ variant: "base"
952
+ }),
953
+ title: "標題"
954
+ },
955
+ {
956
+ key: "type",
957
+ render: (t) => /* @__PURE__ */ _(p, {
958
+ fullWidth: !0,
959
+ clearable: !1,
960
+ menuMaxHeight: at,
961
+ onChange: (n) => yr(e, t.index, n?.id),
962
+ options: [...I],
963
+ size: "sub",
964
+ value: E(I, t.type)
965
+ }),
966
+ title: "型別"
967
+ },
968
+ {
969
+ key: "required",
970
+ render: (t) => /* @__PURE__ */ _(se, {
971
+ checked: xr(e, t.index).required === !0,
972
+ inputProps: { "aria-label": `${t.label || t.fieldKey} 必填` },
973
+ onChange: (n) => X(e, t.index, {
974
+ ...xr(e, t.index),
975
+ required: n.target.checked
976
+ }),
977
+ size: "sub"
978
+ }),
979
+ title: "必填"
980
+ }
981
+ ], r = {
982
+ render: (t) => [{
983
+ disabled: () => e.columns.length <= 1,
984
+ icon: he,
985
+ iconType: "leading",
986
+ name: "移除此欄",
987
+ onClick: () => G({
988
+ columnIndex: t.index,
989
+ columnKey: t.fieldKey,
990
+ fieldKey: e.fieldKey,
991
+ kind: "remove-column"
992
+ }),
993
+ variant: "destructive-ghost"
994
+ }],
995
+ width: 104
996
+ }, i = zn === null ? void 0 : t[zn]?.key;
997
+ return /* @__PURE__ */ _(ie, {
998
+ actions: r,
999
+ columns: n,
1000
+ dataSource: t,
1001
+ draggable: {
1002
+ enabled: !0,
1003
+ onDragEnd: (t, n) => Yn(e, n.fromIndex, n.toIndex)
1004
+ },
1005
+ expandable: {
1006
+ expandedRowKeys: i ? [i] : [],
1007
+ expandedRowRender: (t) => vr(e, t.index),
1008
+ onExpand: (e, t) => K(e ? t.index : null)
1009
+ },
1010
+ fullWidth: !0,
1011
+ rowHeightPreset: "roomy",
1012
+ showHeader: !0,
1013
+ size: "sub"
1014
+ });
1015
+ }
1016
+ function vr(e, t) {
1017
+ let n = e.columns[t];
1018
+ return n ? /* @__PURE__ */ v("div", {
1019
+ style: qt,
1020
+ children: [
1021
+ $("欄位 Key", "columnFieldKey", /* @__PURE__ */ _(f, {
1022
+ onChange: (r) => X(e, t, {
1023
+ ...n,
1024
+ fieldKey: r.target.value
1025
+ }),
1026
+ placeholder: "例如:qty",
1027
+ value: n.fieldKey,
1028
+ variant: "base"
1029
+ })),
1030
+ $("提示文字", "columnPlaceholder", /* @__PURE__ */ _(f, {
1031
+ onChange: (r) => X(e, t, {
1032
+ ...n,
1033
+ placeholder: r.target.value || void 0
1034
+ }),
1035
+ placeholder: "例如:請輸入數量",
1036
+ value: n.placeholder ?? "",
1037
+ variant: "base"
1038
+ })),
1039
+ mr(n, (n) => {
1040
+ Ye(n.type) && X(e, t, n);
1041
+ }, (n, r) => {
1042
+ Ye(r.type) && X(e, t, r);
1043
+ }, e.columns)
1044
+ ]
1045
+ }) : null;
1046
+ }
1047
+ function yr(e, t, n) {
1048
+ let r = e.columns[t], i = I.find((e) => e.id === n)?.id;
1049
+ if (!r || !i || r.type === i) return;
1050
+ let a = xn(r, i), o = bn(r);
1051
+ if (o.length === 0) {
1052
+ X(e, t, a), K(t);
1053
+ return;
1054
+ }
1055
+ G({
1056
+ columnIndex: t,
1057
+ columnKey: r.fieldKey,
1058
+ fieldKey: e.fieldKey,
1059
+ impact: `「${r.label || r.fieldKey}」改為${br(i)}後,這一欄的${o.join("、")}會被捨棄。`,
1060
+ kind: "replace-column",
1061
+ nextColumn: a
1062
+ });
1063
+ }
1064
+ function br(e) {
1065
+ return I.find((t) => t.id === e)?.name ?? e;
1066
+ }
1067
+ function xr(e, t) {
1068
+ let n = e.columns[t];
1069
+ if (!n) throw Error(`Table ${e.fieldKey} has no column at index ${t}.`);
1070
+ return n;
1071
+ }
1072
+ function Sr(e, t) {
1073
+ return /* @__PURE__ */ v(g, { children: [
1074
+ $("預設值", "fieldDefaultValue", e.type === "textarea" ? Wr({
1075
+ name: "fieldDefaultValue",
1076
+ onChange: (n) => t({
1077
+ ...e,
1078
+ defaultValue: n || void 0
1079
+ }),
1080
+ placeholder: "輸入此欄位的預設文字",
1081
+ rows: 3,
1082
+ value: Tn(e.defaultValue)
1083
+ }) : /* @__PURE__ */ _(f, {
1084
+ onChange: (n) => t({
1085
+ ...e,
1086
+ defaultValue: n.target.value || void 0
1087
+ }),
1088
+ placeholder: "輸入此欄位的預設文字",
1089
+ value: Tn(e.defaultValue),
1090
+ variant: "base"
1091
+ })),
1092
+ $("最小長度", "fieldMinLength", Q(e.minLength, (n) => t({
1093
+ ...e,
1094
+ minLength: n
1095
+ }), "例如:2", { min: 0 })),
1096
+ $("最大長度", "fieldMaxLength", Q(e.maxLength, (n) => t({
1097
+ ...e,
1098
+ maxLength: n
1099
+ }), "例如:100", { min: 1 }))
1100
+ ] });
1101
+ }
1102
+ function Cr(e, t) {
1103
+ return /* @__PURE__ */ v(g, { children: [
1104
+ $("預設值", "fieldDefaultValue", Q(typeof e.defaultValue == "number" ? e.defaultValue : void 0, (n) => t({
1105
+ ...e,
1106
+ defaultValue: n
1107
+ }), e.type === "money" ? "例如:1000" : "輸入預設數值", {
1108
+ max: e.maximum,
1109
+ min: e.minimum
1110
+ })),
1111
+ $("最小值", "fieldMinimum", Q(e.minimum, (n) => t({
1112
+ ...e,
1113
+ minimum: n
1114
+ }), "例如:0")),
1115
+ $("最大值", "fieldMaximum", Q(e.maximum, (n) => t({
1116
+ ...e,
1117
+ maximum: n
1118
+ }), "例如:999999"))
1119
+ ] });
1120
+ }
1121
+ function wr(e, t) {
1122
+ return $("預設值", "fieldDefaultValue", Gr(e, Tn(e.defaultValue), (n) => t({
1123
+ ...e,
1124
+ defaultValue: n
1125
+ })));
1126
+ }
1127
+ function Tr(e, t, n, r) {
1128
+ let i = je(e.type, H), a = {
1129
+ commit: (e) => t(e),
1130
+ rowColumns: r
1131
+ }, o = D(e) ? fn(e.dataSource) : tn, s = D(e) ? H.find((t) => t.key === e.dataSource.key && t.version === e.dataSource.version) : null, c = s ? i.some((e) => e.key === s.key && e.version === s.version) : !1, l = [
1132
+ ...on,
1133
+ ...i.map(mn),
1134
+ ...D(e) && !c ? [{
1135
+ id: o,
1136
+ name: `${e.dataSource.key} v${e.dataSource.version}(目前不可用或不支援)`
1137
+ }] : []
1138
+ ], u = A(e);
1139
+ return /* @__PURE__ */ v(g, { children: [
1140
+ e.type === "select" || e.type === "autocomplete" ? $("選擇模式", "fieldSelectionMode", /* @__PURE__ */ _(p, {
1141
+ clearable: !1,
1142
+ onChange: (t) => {
1143
+ (t?.id === "single" || t?.id === "multiple") && Xn(e, t.id, n);
1144
+ },
1145
+ options: [...sn],
1146
+ value: E(sn, u)
1147
+ })) : $("選擇模式", "fieldSelectionMode", /* @__PURE__ */ _(h, {
1148
+ color: "text-neutral",
1149
+ variant: "body",
1150
+ children: u === "multiple" ? "固定複選" : "固定單選"
1151
+ })),
1152
+ $("選項來源", "fieldOptionSource", /* @__PURE__ */ _(p, {
1153
+ clearable: !1,
1154
+ disabled: Pn === "loading" && !D(e),
1155
+ onChange: (n) => Qn(e, n?.id, t),
1156
+ options: l,
1157
+ placeholder: "選擇選項來源",
1158
+ value: E(l, o)
1159
+ })),
1160
+ D(e) ? Er(e, i, a) : Rr(e, t)
1161
+ ] });
1162
+ }
1163
+ function Er(e, t, n) {
1164
+ let r = H.find((t) => t.key === e.dataSource.key && t.version === e.dataSource.version), i = r && !Ce(r, e.type);
1165
+ return /* @__PURE__ */ v("div", {
1166
+ style: Vt,
1167
+ children: [
1168
+ Pn === "loading" ? /* @__PURE__ */ _(h, {
1169
+ color: "text-neutral",
1170
+ variant: "body",
1171
+ children: "正在載入可用的選項來源…"
1172
+ }) : null,
1173
+ Mn ? /* @__PURE__ */ _(h, {
1174
+ color: "text-error",
1175
+ variant: "body",
1176
+ children: Mn
1177
+ }) : null,
1178
+ r ? null : /* @__PURE__ */ _(h, {
1179
+ color: "text-warning",
1180
+ variant: "body",
1181
+ children: "找不到目前設定的來源版本。設定會保留,但這張表單在來源恢復前無法發布。"
1182
+ }),
1183
+ i ? /* @__PURE__ */ _(h, {
1184
+ color: "text-error",
1185
+ variant: "body",
1186
+ children: "這個來源不支援目前的控制項,請改選其他來源。"
1187
+ }) : null,
1188
+ r ? Dr(r) : null,
1189
+ r && r.parameters.length > 0 ? Or(e, r, n) : null,
1190
+ t.length === 0 && !Mn ? /* @__PURE__ */ _(h, {
1191
+ color: "text-warning",
1192
+ variant: "body",
1193
+ children: "沒有支援目前控制項的已註冊來源。"
1194
+ }) : null,
1195
+ /* @__PURE__ */ _("div", {
1196
+ style: Wt,
1197
+ children: /* @__PURE__ */ _(c, {
1198
+ disabled: Ln,
1199
+ loading: Ln,
1200
+ onClick: () => void tr(),
1201
+ size: "sub",
1202
+ type: "button",
1203
+ variant: "base-secondary",
1204
+ children: "檢查全部動態選項設定"
1205
+ })
1206
+ }),
1207
+ In ? /* @__PURE__ */ _("div", {
1208
+ style: Ht,
1209
+ children: In.length > 0 ? In.map((e) => /* @__PURE__ */ _(h, {
1210
+ color: "text-error",
1211
+ variant: "caption",
1212
+ children: e
1213
+ }, e)) : /* @__PURE__ */ _(h, {
1214
+ color: "text-success",
1215
+ variant: "caption",
1216
+ children: "這張表單的動態選項設定都可以使用。"
1217
+ })
1218
+ }) : null
1219
+ ]
1220
+ });
1221
+ }
1222
+ function Dr(e) {
1223
+ return /* @__PURE__ */ v("div", {
1224
+ style: Kt,
1225
+ children: [
1226
+ e.description ? /* @__PURE__ */ _(h, {
1227
+ variant: "body",
1228
+ children: e.description
1229
+ }) : null,
1230
+ /* @__PURE__ */ _("div", {
1231
+ style: Gt,
1232
+ children: pn(e).map((e) => /* @__PURE__ */ _(ae, {
1233
+ label: e,
1234
+ readOnly: !0,
1235
+ size: "minor"
1236
+ }, e))
1237
+ }),
1238
+ /* @__PURE__ */ v(h, {
1239
+ color: "text-neutral",
1240
+ variant: "caption",
1241
+ children: [
1242
+ "來源代號:",
1243
+ e.key,
1244
+ " · v",
1245
+ e.version
1246
+ ]
1247
+ })
1248
+ ]
1249
+ });
1250
+ }
1251
+ function Or(e, t, n) {
1252
+ let r = t.parameters.map((e, t) => ({
1253
+ key: e.key,
1254
+ index: t,
1255
+ parameter: e
1256
+ }));
1257
+ return /* @__PURE__ */ v("div", {
1258
+ style: Ut,
1259
+ children: [/* @__PURE__ */ _(h, {
1260
+ color: "text-neutral",
1261
+ variant: "label-secondary",
1262
+ children: "這個來源需要的條件"
1263
+ }), /* @__PURE__ */ _(ie, {
1264
+ columns: [
1265
+ {
1266
+ key: "parameter",
1267
+ render: (e) => /* @__PURE__ */ v("div", {
1268
+ style: Xt,
1269
+ children: [/* @__PURE__ */ _(h, {
1270
+ variant: "input",
1271
+ children: e.parameter.label ?? e.parameter.key
1272
+ }), e.parameter.required ? /* @__PURE__ */ _(h, {
1273
+ color: "text-error",
1274
+ variant: "input",
1275
+ children: "*"
1276
+ }) : null]
1277
+ }),
1278
+ title: "條件",
1279
+ width: 100
1280
+ },
1281
+ {
1282
+ key: "binding",
1283
+ width: 268,
1284
+ render: (t) => Ar(e, t.parameter, n),
1285
+ title: "值從哪裡來"
1286
+ },
1287
+ {
1288
+ key: "constant",
1289
+ width: 140,
1290
+ render: (t) => Be(T(e, t.parameter.key)) === "CONSTANT" ? Pr(e, t.parameter.key, t.parameter.type, T(e, t.parameter.key), n) : /* @__PURE__ */ _(h, {
1291
+ color: "text-neutral",
1292
+ variant: "caption",
1293
+ children: "—"
1294
+ }),
1295
+ title: "固定值"
1296
+ },
1297
+ {
1298
+ key: "meaning",
1299
+ render: (t) => /* @__PURE__ */ _(h, {
1300
+ color: "text-neutral",
1301
+ variant: "caption",
1302
+ children: Mr(T(e, t.parameter.key), t.parameter, n, kr(e, t.parameter, n))
1303
+ }),
1304
+ title: "填寫時的行為"
1305
+ }
1306
+ ],
1307
+ dataSource: r,
1308
+ fullWidth: !0,
1309
+ showHeader: !0,
1310
+ size: "sub"
1311
+ })]
1312
+ });
1313
+ }
1314
+ function kr(e, t, n) {
1315
+ return Ae(t.type, b.fields, e.fieldKey).length + (n.rowColumns ? Me(t.type, n.rowColumns, e.fieldKey).length : 0);
1316
+ }
1317
+ function Ar(e, t, n) {
1318
+ let r = hn(T(e, t.key)), i = n.rowColumns ? Me(t.type, n.rowColumns, e.fieldKey).map((e) => ({
1319
+ id: `${rn}${e.id}`,
1320
+ name: `同列:${e.name}`
1321
+ })) : [], a = [
1322
+ ...t.required ? [] : [{
1323
+ id: an,
1324
+ name: "未綁定"
1325
+ }],
1326
+ ...i,
1327
+ ...Ae(t.type, b.fields, e.fieldKey),
1328
+ ...t.type === "STRING_ARRAY" ? [] : [{
1329
+ id: nn,
1330
+ name: "固定常數"
1331
+ }]
1332
+ ];
1333
+ return /* @__PURE__ */ _("div", {
1334
+ "data-data-source-parameter": t.key,
1335
+ style: Zt,
1336
+ children: /* @__PURE__ */ _(p, {
1337
+ clearable: !1,
1338
+ fullWidth: !0,
1339
+ inputProps: {
1340
+ "aria-label": `${t.label ?? t.key} 的值來源`,
1341
+ title: E(a, r)?.name ?? ""
1342
+ },
1343
+ onChange: (r) => Ir(e, t.key, t.type, r?.id, n),
1344
+ options: a,
1345
+ placeholder: "選擇欄位或常數",
1346
+ size: "sub",
1347
+ value: E(a, r)
1348
+ })
1349
+ });
1350
+ }
1351
+ function jr(e) {
1352
+ return ot[e];
1353
+ }
1354
+ function Mr(e, t, n, r) {
1355
+ let i = Be(e);
1356
+ return i === "CONSTANT" ? "固定值,不隨填寫變動" : i === "FIELD" ? `隨欄位「${Nr(e, n)}」變動` : i === "ROW_FIELD" ? `隨同列「${Nr(e, n)}」變動` : t.required ? r > 0 ? "尚未設定,選項無法載入" : `沒有相容的${jr(t.type)}欄位,請改用固定值` : "未設定,不做這層篩選";
1357
+ }
1358
+ function Nr(e, t) {
1359
+ let n = e?.from;
1360
+ if (n?.kind === "FIELD") {
1361
+ let e = b.fields.find((e) => e.fieldKey === n.fieldKey);
1362
+ return e ? e.label || e.fieldKey : "";
1363
+ }
1364
+ if (n?.kind === "ROW_FIELD") {
1365
+ let e = t.rowColumns?.find((e) => e.fieldKey === n.columnKey);
1366
+ return e ? e.label || e.fieldKey : "";
1367
+ }
1368
+ return "";
1369
+ }
1370
+ function Pr(e, t, n, r, i) {
1371
+ return /* @__PURE__ */ _("div", {
1372
+ "data-data-source-constant": t,
1373
+ children: Fr(e, t, n, r, i)
1374
+ });
1375
+ }
1376
+ function Fr(e, t, n, r, i) {
1377
+ let a = ze(e, t);
1378
+ if (n === "BOOLEAN") {
1379
+ let n = [{
1380
+ id: "true",
1381
+ name: "是"
1382
+ }, {
1383
+ id: "false",
1384
+ name: "否"
1385
+ }];
1386
+ return /* @__PURE__ */ _(p, {
1387
+ clearable: !1,
1388
+ fullWidth: !0,
1389
+ onChange: (n) => Lr(e, t, n?.id === "true", i),
1390
+ options: n,
1391
+ size: "sub",
1392
+ value: E(n, a === !0 ? "true" : "false")
1393
+ });
1394
+ }
1395
+ return n === "STRING_ARRAY" ? /* @__PURE__ */ _(h, {
1396
+ color: "text-warning",
1397
+ variant: "caption",
1398
+ children: "這個條件要收多個值,請綁定一個複選欄位;不接受固定值。"
1399
+ }) : /* @__PURE__ */ _(f, {
1400
+ onChange: (r) => Lr(e, t, n === "NUMBER" ? ke(r.target.value) ?? 0 : r.target.value, i),
1401
+ placeholder: n === "NUMBER" ? "輸入數字" : "輸入固定值",
1402
+ value: _n(r, n),
1403
+ variant: "base"
1404
+ });
1405
+ }
1406
+ function Ir(e, t, n, r, i) {
1407
+ i.commit(Ke(e, t, vn(t, n, r)));
1408
+ }
1409
+ function Lr(e, t, n, r) {
1410
+ r.commit(Ke(e, t, {
1411
+ from: {
1412
+ kind: "CONSTANT",
1413
+ value: n
1414
+ },
1415
+ parameter: t
1416
+ }));
1417
+ }
1418
+ function Rr(e, t) {
1419
+ let n = A(e), r = Array.isArray(e.defaultValue) ? e.defaultValue : [], i = e.options.map(Re), a = i.filter((e) => r.includes(e.id));
1420
+ return /* @__PURE__ */ v(g, { children: [$("預設值", "fieldDefaultValue", n === "multiple" ? /* @__PURE__ */ _(p, {
1421
+ clearable: !0,
1422
+ mode: "multiple",
1423
+ onChange: (n) => t({
1424
+ ...e,
1425
+ defaultValue: n.length ? n.map((e) => e.id) : void 0
1426
+ }),
1427
+ options: i,
1428
+ placeholder: "選擇一或多個預設選項",
1429
+ value: a
1430
+ }) : /* @__PURE__ */ _(p, {
1431
+ clearable: !0,
1432
+ onChange: (n) => t({
1433
+ ...e,
1434
+ defaultValue: n?.id || void 0
1435
+ }),
1436
+ options: i,
1437
+ placeholder: "選擇預設選項",
1438
+ value: typeof e.defaultValue == "string" ? E(i, e.defaultValue) : null
1439
+ })), $("選項", "fieldOptions", Kr(e, t), !0)] });
1440
+ }
1441
+ function zr(e, t) {
1442
+ let n = typeof e.defaultValue == "boolean" ? String(e.defaultValue) : "unset";
1443
+ return $("預設值", "fieldDefaultValue", /* @__PURE__ */ _(p, {
1444
+ clearable: !1,
1445
+ onChange: (n) => t({
1446
+ ...e,
1447
+ defaultValue: n?.id === "true" || n?.id !== "false" && void 0
1448
+ }),
1449
+ options: [...cn],
1450
+ placeholder: "選擇預設狀態",
1451
+ value: E(cn, n)
1452
+ }));
1453
+ }
1454
+ function Br(e, t) {
1455
+ return /* @__PURE__ */ v(g, { children: [$("檔案數", "fieldMaxFiles", Q(e.maxFiles, (n) => t({
1456
+ ...e,
1457
+ maxFiles: n
1458
+ }), "例如:1", { min: 1 })), $("MIME", "fieldAcceptedMimeTypes", Wr({
1459
+ name: "fieldAcceptedMimeTypes",
1460
+ onChange: (n) => t({
1461
+ ...e,
1462
+ acceptedMimeTypes: En(n)
1463
+ }),
1464
+ placeholder: "每行一個 MIME type,例如:application/pdf",
1465
+ rows: 3,
1466
+ value: Dn(e.acceptedMimeTypes)
1467
+ }), !1)] });
1468
+ }
1469
+ function Vr(e) {
1470
+ let t = b.fields.filter((t) => t.fieldKey !== e.fieldKey);
1471
+ return t.length ? /* @__PURE__ */ _(g, { children: un.map((n) => Hr(e, n, t)) }) : /* @__PURE__ */ _(h, {
1472
+ color: "text-neutral",
1473
+ style: Tt,
1474
+ variant: "body",
1475
+ children: "目前沒有其他欄位可作為條件來源。新增更多欄位後即可設定條件規則。"
1476
+ });
1477
+ }
1478
+ function Hr(e, t, n) {
1479
+ let r = e[t.target], i = r ? Oe(r) : null, a = n.find((e) => e.fieldKey === i?.fieldKey), o = a ?? n[0], s = n.map(Cn), c = Pe(o), l = i && c.some((e) => e.id === i.operator) ? i.operator : Ie(o), u = i?.value ?? Le(o), d = !!r, f = d && (!i || !a);
1480
+ return $(t.label, t.name, /* @__PURE__ */ v("div", {
1481
+ style: Pt,
1482
+ children: [/* @__PURE__ */ _(se, {
1483
+ checked: d,
1484
+ label: d ? "已啟用" : "不啟用",
1485
+ onChange: (e) => Z(t.target, e.target.checked ? w(o, Ie(o), Le(o)) : void 0),
1486
+ size: "sub",
1487
+ supportingText: t.supportingText
1488
+ }), d ? f ? /* @__PURE__ */ _(h, {
1489
+ color: "text-warning",
1490
+ variant: "body",
1491
+ children: "這個規則不是目前 UI 支援的格式。重新選擇條件後會取代既有規則。"
1492
+ }) : /* @__PURE__ */ v("div", {
1493
+ style: Ft,
1494
+ children: [
1495
+ /* @__PURE__ */ _(p, {
1496
+ clearable: !1,
1497
+ onChange: (e) => {
1498
+ let r = n.find((t) => t.fieldKey === e?.id) ?? o;
1499
+ Z(t.target, w(r, Ie(r), Le(r)));
1500
+ },
1501
+ options: s,
1502
+ placeholder: "選擇欄位",
1503
+ value: E(s, o.fieldKey)
1504
+ }),
1505
+ /* @__PURE__ */ _(p, {
1506
+ clearable: !1,
1507
+ onChange: (e) => Z(t.target, w(o, Ne(e?.id) ?? l, u)),
1508
+ options: [...c],
1509
+ placeholder: "判斷方式",
1510
+ value: E(c, l)
1511
+ }),
1512
+ Ur(o, u, (e) => Z(t.target, w(o, l, e)))
1513
+ ]
1514
+ }) : null]
1515
+ }), !0);
1516
+ }
1517
+ function Z(e, t) {
1518
+ J({ [e]: t });
1519
+ }
1520
+ function Ur(e, t, n) {
1521
+ if (e.type === "boolean") return /* @__PURE__ */ _(p, {
1522
+ clearable: !1,
1523
+ onChange: (e) => n(e?.id ?? "true"),
1524
+ options: [...ln],
1525
+ placeholder: "比較值",
1526
+ value: E(ln, t === "false" ? "false" : "true")
1527
+ });
1528
+ if (Te(e)) {
1529
+ let r = e.options.map(Re);
1530
+ return /* @__PURE__ */ _(p, {
1531
+ clearable: !1,
1532
+ onChange: (e) => n(e?.id ?? r[0]?.id ?? ""),
1533
+ options: r,
1534
+ placeholder: "比較值",
1535
+ value: E(r, t)
1536
+ });
1537
+ }
1538
+ return we(e) ? Q(ke(t), (e) => n(String(e ?? 0)), "比較值") : Se(e) ? Gr(e, t, (e) => n(e ?? "")) : /* @__PURE__ */ _(f, {
1539
+ onChange: (e) => n(e.target.value),
1540
+ placeholder: "比較值",
1541
+ value: t,
1542
+ variant: "base"
1543
+ });
1544
+ }
1545
+ function Wr({ name: e, onChange: t, placeholder: n, rows: r, value: i }) {
1546
+ return /* @__PURE__ */ _(oe, {
1547
+ "aria-label": e,
1548
+ onChange: (e) => t(e.target.value),
1549
+ placeholder: n,
1550
+ ref: Qt,
1551
+ resize: "vertical",
1552
+ rows: r,
1553
+ style: kt,
1554
+ value: i
1555
+ });
1556
+ }
1557
+ function Q(e, t, n, r = {}) {
1558
+ return /* @__PURE__ */ _(f, {
1559
+ max: r.max,
1560
+ min: r.min,
1561
+ onChange: (e) => t(_e(ke(e.target.value), r)),
1562
+ placeholder: n,
1563
+ showSpinner: !0,
1564
+ step: r.step ?? 1,
1565
+ value: typeof e == "number" ? String(e) : "",
1566
+ variant: "measure"
1567
+ });
1568
+ }
1569
+ function Gr(e, t, n) {
1570
+ return e.type === "datetime" ? /* @__PURE__ */ _(u, {
1571
+ formatDate: "YYYY-MM-DD",
1572
+ formatTime: "HH:mm",
1573
+ hideSecond: !0,
1574
+ onChange: (e) => n(xe(e)),
1575
+ placeholderLeft: "選擇日期",
1576
+ placeholderRight: "選擇時間",
1577
+ value: Fe(t)
1578
+ }) : /* @__PURE__ */ _(l, {
1579
+ format: "YYYY-MM-DD",
1580
+ onChange: (e) => n(be(e)),
1581
+ placeholder: "選擇日期",
1582
+ value: Fe(t)
1583
+ });
1584
+ }
1585
+ function Kr(e, t) {
1586
+ let n = e.options.map((t, n) => ({
1587
+ index: n,
1588
+ key: `${e.fieldKey}-${n}`,
1589
+ label: t.label,
1590
+ value: t.value
1591
+ }));
1592
+ return /* @__PURE__ */ v("div", {
1593
+ style: Rt,
1594
+ children: [/* @__PURE__ */ _(ie, {
1595
+ actions: {
1596
+ render: (n) => [{
1597
+ disabled: () => e.options.length <= 1,
1598
+ icon: he,
1599
+ iconType: "icon-only",
1600
+ name: "移除選項",
1601
+ onClick: () => t({
1602
+ ...e,
1603
+ options: e.options.filter((e, t) => t !== n.index)
1604
+ }),
1605
+ variant: "destructive-ghost"
1606
+ }],
1607
+ width: 56
1608
+ },
1609
+ columns: [{
1610
+ key: "label",
1611
+ render: (n) => /* @__PURE__ */ _(f, {
1612
+ onChange: (r) => t({
1613
+ ...e,
1614
+ options: On(e.options, n.index, { label: r.target.value })
1615
+ }),
1616
+ placeholder: "例如:主管",
1617
+ size: "sub",
1618
+ value: n.label,
1619
+ variant: "base"
1620
+ }),
1621
+ title: "Label"
1622
+ }, {
1623
+ key: "value",
1624
+ render: (n) => /* @__PURE__ */ _(f, {
1625
+ onChange: (r) => t({
1626
+ ...e,
1627
+ options: On(e.options, n.index, { value: r.target.value })
1628
+ }),
1629
+ placeholder: "例如:manager",
1630
+ size: "sub",
1631
+ value: n.value,
1632
+ variant: "base"
1633
+ }),
1634
+ title: "Value"
1635
+ }],
1636
+ dataSource: n,
1637
+ showHeader: !0,
1638
+ size: "sub"
1639
+ }), /* @__PURE__ */ _("div", {
1640
+ style: zt,
1641
+ children: /* @__PURE__ */ _(c, {
1642
+ icon: me,
1643
+ iconType: "leading",
1644
+ onClick: () => t({
1645
+ ...e,
1646
+ options: [...e.options, kn(e.options)]
1647
+ }),
1648
+ variant: "base-secondary",
1649
+ children: "新增選項"
1650
+ })
1651
+ })]
1652
+ });
1653
+ }
1654
+ function qr(e, t, n) {
1655
+ return /* @__PURE__ */ _("div", {
1656
+ ...t.draggableProps,
1657
+ "data-form-builder-field-key": e.fieldKey,
1658
+ ref: t.innerRef,
1659
+ style: {
1660
+ ...gt,
1661
+ ...n ? _t : null,
1662
+ ...t.draggableProps.style
1663
+ },
1664
+ children: /* @__PURE__ */ _(s, {
1665
+ style: e.fieldKey === q?.fieldKey ? vt : void 0,
1666
+ children: Jr(e, t, n)
1667
+ })
1668
+ });
1669
+ }
1670
+ function $(t, n, r, i = !1) {
1671
+ return /* @__PURE__ */ _("div", {
1672
+ style: i ? Dt : Et,
1673
+ children: /* @__PURE__ */ _("div", {
1674
+ style: Ot,
1675
+ children: /* @__PURE__ */ _(e, {
1676
+ label: t,
1677
+ layout: i ? ce.VERTICAL : ce.STRETCH,
1678
+ name: n,
1679
+ children: r
1680
+ })
1681
+ })
1682
+ });
1683
+ }
1684
+ function Jr(e, t, n) {
1685
+ return /* @__PURE__ */ v("div", {
1686
+ ...t.dragHandleProps ?? {},
1687
+ "aria-label": "選取或拖曳排序欄位",
1688
+ onClick: () => B(e.fieldKey),
1689
+ style: ft,
1690
+ title: "點擊選取,拖曳排序",
1691
+ children: [
1692
+ /* @__PURE__ */ _("span", {
1693
+ "aria-label": "拖曳排序",
1694
+ role: "img",
1695
+ style: It,
1696
+ title: "拖曳排序",
1697
+ children: /* @__PURE__ */ _(d, {
1698
+ icon: fe,
1699
+ size: 20
1700
+ })
1701
+ }),
1702
+ /* @__PURE__ */ v("div", {
1703
+ style: pt,
1704
+ children: [/* @__PURE__ */ v(h, {
1705
+ component: "span",
1706
+ ellipsis: !0,
1707
+ variant: "label-primary",
1708
+ children: [e.label, e.required ? /* @__PURE__ */ _("sup", {
1709
+ "aria-label": "必填",
1710
+ style: Bt,
1711
+ children: "*"
1712
+ }) : null]
1713
+ }), /* @__PURE__ */ v(h, {
1714
+ color: "text-neutral",
1715
+ component: "span",
1716
+ ellipsis: !0,
1717
+ variant: "caption",
1718
+ children: [
1719
+ dn(e.type),
1720
+ " ·",
1721
+ e.required ? " 必填" : " 選填",
1722
+ " ·",
1723
+ e.fieldKey
1724
+ ]
1725
+ })]
1726
+ }),
1727
+ /* @__PURE__ */ v("div", {
1728
+ onClick: (e) => e.stopPropagation(),
1729
+ style: mt,
1730
+ children: [/* @__PURE__ */ _("div", {
1731
+ style: ht,
1732
+ children: /* @__PURE__ */ _(se, {
1733
+ checked: !!e.required,
1734
+ disabled: n,
1735
+ label: "必填",
1736
+ onChange: (t) => sr(e.fieldKey, t.target.checked)
1737
+ })
1738
+ }), /* @__PURE__ */ _(c, {
1739
+ disabled: n,
1740
+ icon: he,
1741
+ iconType: "icon-only",
1742
+ onClick: () => Hn(e.fieldKey),
1743
+ variant: "destructive-ghost",
1744
+ children: "移除欄位"
1745
+ })]
1746
+ })
1747
+ ]
1748
+ });
1749
+ }
1750
+ function Yr() {
1751
+ return /* @__PURE__ */ v("div", {
1752
+ style: L,
1753
+ children: [/* @__PURE__ */ _(h, {
1754
+ component: "h2",
1755
+ variant: "h3",
1756
+ children: "填寫預覽"
1757
+ }), /* @__PURE__ */ _(t, {
1758
+ dataSourceContext: { kind: "preview" },
1759
+ onChange: or,
1760
+ schema: b,
1761
+ uiSchema: S,
1762
+ value: M
1763
+ })]
1764
+ });
1765
+ }
1766
+ function Xr() {
1767
+ return /* @__PURE__ */ v("div", {
1768
+ style: L,
1769
+ children: [/* @__PURE__ */ _(h, {
1770
+ component: "h2",
1771
+ variant: "h3",
1772
+ children: "Schema"
1773
+ }), /* @__PURE__ */ v("div", {
1774
+ style: At,
1775
+ children: [
1776
+ Zr("Form Schema", "schemaJson", /* @__PURE__ */ _(tt, {
1777
+ height: "360px",
1778
+ name: "schemaJson",
1779
+ onChange: cr,
1780
+ placeholder: "輸入 Form Schema JSON",
1781
+ value: pe
1782
+ })),
1783
+ Zr("UI Schema", "uiSchemaJson", /* @__PURE__ */ _(tt, {
1784
+ height: "240px",
1785
+ name: "uiSchemaJson",
1786
+ onChange: lr,
1787
+ placeholder: "輸入 UI Schema JSON",
1788
+ value: $e
1789
+ })),
1790
+ et ? /* @__PURE__ */ _(h, {
1791
+ color: "text-error",
1792
+ style: Nt,
1793
+ variant: "body",
1794
+ children: et
1795
+ }) : null
1796
+ ]
1797
+ })]
1798
+ });
1799
+ }
1800
+ function Zr(t, n, r) {
1801
+ return /* @__PURE__ */ _("div", {
1802
+ style: jt,
1803
+ children: /* @__PURE__ */ _("div", {
1804
+ style: Mt,
1805
+ children: /* @__PURE__ */ _(e, {
1806
+ label: t,
1807
+ name: n,
1808
+ children: r
1809
+ })
1810
+ })
1811
+ });
1812
+ }
1813
+ }
1814
+ function dn(e) {
1815
+ return F.find((t) => t.type === e)?.label ?? e;
1816
+ }
1817
+ function fn(e) {
1818
+ return `${e.key}@${e.version}`;
1819
+ }
1820
+ function pn(e) {
1821
+ return [
1822
+ e.supportsSearch ? `可輸入關鍵字搜尋${e.minimumSearchLength > 1 ? `(至少 ${e.minimumSearchLength} 字)` : ""}` : "不支援搜尋",
1823
+ e.paginationMode === "CURSOR" ? `捲動載入更多(每次 ${e.pageSize} 筆)` : `一次載入完整清單(最多 ${e.maximumResultCount} 筆)`,
1824
+ e.revalidationPolicy === "ALWAYS" ? "退回重送時一律重新確認" : "值與條件未變時沿用上次結果"
1825
+ ];
1826
+ }
1827
+ function mn(e) {
1828
+ return {
1829
+ id: fn(e),
1830
+ name: e.label
1831
+ };
1832
+ }
1833
+ function hn(e) {
1834
+ return e ? e.from.kind === "FIELD" ? e.from.fieldKey : e.from.kind === "ROW_FIELD" ? `${rn}${e.from.columnKey}` : nn : an;
1835
+ }
1836
+ function gn(e) {
1837
+ switch (e) {
1838
+ case "BOOLEAN": return !1;
1839
+ case "NUMBER": return 0;
1840
+ case "STRING_ARRAY": return "";
1841
+ case "STRING": return "";
1842
+ default: return "";
1843
+ }
1844
+ }
1845
+ function _n(e, t) {
1846
+ let n = e?.from.kind === "CONSTANT" ? e.from.value : "";
1847
+ return t === "NUMBER" ? typeof n == "number" ? String(n) : "" : typeof n == "string" ? n : "";
1848
+ }
1849
+ function vn(e, t, n) {
1850
+ return !n || n === an ? null : n === nn ? {
1851
+ from: {
1852
+ kind: "CONSTANT",
1853
+ value: gn(t)
1854
+ },
1855
+ parameter: e
1856
+ } : n.startsWith(rn) ? {
1857
+ from: {
1858
+ columnKey: n.slice(14),
1859
+ kind: "ROW_FIELD"
1860
+ },
1861
+ parameter: e
1862
+ } : {
1863
+ from: {
1864
+ fieldKey: n,
1865
+ kind: "FIELD"
1866
+ },
1867
+ parameter: e
1868
+ };
1869
+ }
1870
+ function yn(e) {
1871
+ return e.kind === "remove-field" ? "確認移除 dependency 欄位" : e.kind === "remove-column" ? "確認移除表格欄" : e.kind === "replace-column" ? "確認變更欄型別" : "確認變更選擇模式";
1872
+ }
1873
+ var z = [{
1874
+ label: "選項 A",
1875
+ value: "option_a"
1876
+ }, {
1877
+ label: "選項 B",
1878
+ value: "option_b"
1879
+ }];
1880
+ function bn(e) {
1881
+ let t = [];
1882
+ return e.defaultValue !== void 0 && t.push("預設值"), e.type === "text" && (typeof e.minLength == "number" || typeof e.maxLength == "number") && t.push("長度限制"), (e.type === "number" || e.type === "money") && (typeof e.minimum == "number" || typeof e.maximum == "number") && t.push("數值範圍"), D(e) ? t.push("選項來源設定") : O(e) && !B(e.options) && t.push(`${e.options.length} 個選項`), (e.type === "select" || e.type === "autocomplete") && e.mode === "multiple" && t.push("選擇模式"), t;
1883
+ }
1884
+ function B(e) {
1885
+ return e.length === z.length && e.every((e, t) => e.label === z[t]?.label && e.value === z[t]?.value);
1886
+ }
1887
+ function xn(e, t) {
1888
+ let n = {
1889
+ fieldKey: e.fieldKey,
1890
+ label: e.label,
1891
+ required: e.required,
1892
+ ...e.description ? { description: e.description } : {},
1893
+ ...e.placeholder ? { placeholder: e.placeholder } : {}
1894
+ };
1895
+ return t === "select" || t === "autocomplete" ? {
1896
+ ...n,
1897
+ mode: "single",
1898
+ options: [...z],
1899
+ type: t
1900
+ } : {
1901
+ ...n,
1902
+ type: t
1903
+ };
1904
+ }
1905
+ function Sn(e) {
1906
+ return !!(e.visibleWhen || e.requiredWhen || e.readonlyWhen);
1907
+ }
1908
+ function Cn(e) {
1909
+ return {
1910
+ id: e.fieldKey,
1911
+ name: e.label
1912
+ };
1913
+ }
1914
+ function wn(e) {
1915
+ return e.type === "text" || e.type === "textarea";
1916
+ }
1917
+ function Tn(e) {
1918
+ return typeof e == "string" ? e : "";
1919
+ }
1920
+ function En(e) {
1921
+ let t = e.split(/[\n,]/u).map((e) => e.trim()).filter(Boolean);
1922
+ return t.length ? t : void 0;
1923
+ }
1924
+ function Dn(e) {
1925
+ return e?.join("\n") ?? "";
1926
+ }
1927
+ function V(e) {
1928
+ return JSON.stringify(e, null, 2);
1929
+ }
1930
+ function On(e, t, n) {
1931
+ return e.map((e, r) => r === t ? {
1932
+ ...e,
1933
+ ...n
1934
+ } : e);
1935
+ }
1936
+ function kn(e) {
1937
+ let t = e.length + 1;
1938
+ return {
1939
+ label: `選項 ${t}`,
1940
+ value: H(e, t)
1941
+ };
1942
+ }
1943
+ function H(e, t) {
1944
+ let n = `option_${t}`;
1945
+ return e.some((e) => e.value === n) ? H(e, t + 1) : n;
1946
+ }
1947
+ function An(e, t, n) {
1948
+ let r = e[t];
1949
+ if (!r || t === n) return [...e];
1950
+ let i = e.filter((e, n) => n !== t);
1951
+ return [
1952
+ ...i.slice(0, n),
1953
+ r,
1954
+ ...i.slice(n)
1955
+ ];
1956
+ }
1957
+ //#endregion
1958
+ export { R as t };
1959
+
1960
+ //# sourceMappingURL=FormBuilderView-D4xIuPYB.js.map