@rytass/bpm-core-react 0.23.0 → 0.24.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 (128) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -0
  3. package/dist/chunks/{FormBuilderView-bm8P55hp.cjs → FormBuilderView-Bg9ftYz-.cjs} +2 -2
  4. package/dist/chunks/{FormBuilderView-bm8P55hp.cjs.map → FormBuilderView-Bg9ftYz-.cjs.map} +1 -1
  5. package/dist/chunks/{FormBuilderView-D_bN9gzT.js → FormBuilderView-CBvdcg_t.js} +2 -2
  6. package/dist/chunks/{FormBuilderView-D_bN9gzT.js.map → FormBuilderView-CBvdcg_t.js.map} +1 -1
  7. package/dist/chunks/FormRendererView-D-p6GDQB.cjs +6 -0
  8. package/dist/chunks/FormRendererView-D-p6GDQB.cjs.map +1 -0
  9. package/dist/chunks/FormRendererView-DHXmekC3.js +1319 -0
  10. package/dist/chunks/FormRendererView-DHXmekC3.js.map +1 -0
  11. package/dist/chunks/{approval-instance-list-page-Cv5I1YPX.cjs → approval-instance-list-page-BqkG9jiR.cjs} +2 -2
  12. package/dist/chunks/{approval-instance-list-page-Cv5I1YPX.cjs.map → approval-instance-list-page-BqkG9jiR.cjs.map} +1 -1
  13. package/dist/chunks/{approval-instance-list-page-BI5fIXc-.js → approval-instance-list-page-CsSpIN4C.js} +2 -2
  14. package/dist/chunks/{approval-instance-list-page-BI5fIXc-.js.map → approval-instance-list-page-CsSpIN4C.js.map} +1 -1
  15. package/dist/chunks/{compose-CdKVQfjB.cjs → compose-B43jtdyL.cjs} +2 -2
  16. package/dist/chunks/{compose-CdKVQfjB.cjs.map → compose-B43jtdyL.cjs.map} +1 -1
  17. package/dist/chunks/{compose-N9657E5u.js → compose-C7yS6bJm.js} +5 -5
  18. package/dist/chunks/{compose-N9657E5u.js.map → compose-C7yS6bJm.js.map} +1 -1
  19. package/dist/chunks/{dashboard-page-BoqNhjT_.js → dashboard-page-DBJCsPya.js} +2 -2
  20. package/dist/chunks/{dashboard-page-BoqNhjT_.js.map → dashboard-page-DBJCsPya.js.map} +1 -1
  21. package/dist/chunks/{dashboard-page-D7YJ3udk.cjs → dashboard-page-lqlLELKs.cjs} +2 -2
  22. package/dist/chunks/{dashboard-page-D7YJ3udk.cjs.map → dashboard-page-lqlLELKs.cjs.map} +1 -1
  23. package/dist/chunks/{designer-CKwG_vM5.js → designer-B9Ut4xze.js} +1736 -1611
  24. package/dist/chunks/designer-B9Ut4xze.js.map +1 -0
  25. package/dist/chunks/designer-eXw7R9ug.cjs +69 -0
  26. package/dist/chunks/designer-eXw7R9ug.cjs.map +1 -0
  27. package/dist/chunks/{detail-fW0vJudE.js → detail-BB_uYaoM.js} +7 -6
  28. package/dist/chunks/detail-BB_uYaoM.js.map +1 -0
  29. package/dist/chunks/detail-DN8pEzUJ.cjs +5 -0
  30. package/dist/chunks/detail-DN8pEzUJ.cjs.map +1 -0
  31. package/dist/chunks/member-profile-resolution-CJlgVdTR.js +44 -0
  32. package/dist/chunks/member-profile-resolution-CJlgVdTR.js.map +1 -0
  33. package/dist/chunks/member-profile-resolution-DiH-P-Vh.cjs +2 -0
  34. package/dist/chunks/member-profile-resolution-DiH-P-Vh.cjs.map +1 -0
  35. package/dist/chunks/{providers-CQWekD7_.js → providers-D35lBOTd.js} +2 -2
  36. package/dist/chunks/{providers-CQWekD7_.js.map → providers-D35lBOTd.js.map} +1 -1
  37. package/dist/chunks/{providers-VUOh6i0i.cjs → providers-Dz4Wqxr6.cjs} +2 -2
  38. package/dist/chunks/{providers-VUOh6i0i.cjs.map → providers-Dz4Wqxr6.cjs.map} +1 -1
  39. package/dist/chunks/{routes-config-C1j_vFKo.cjs → routes-config-BWjZDAU3.cjs} +2 -2
  40. package/dist/chunks/{routes-config-C1j_vFKo.cjs.map → routes-config-BWjZDAU3.cjs.map} +1 -1
  41. package/dist/chunks/{routes-config-BcNaWJWJ.js → routes-config-DjEOE9eP.js} +3 -2
  42. package/dist/chunks/{routes-config-BcNaWJWJ.js.map → routes-config-DjEOE9eP.js.map} +1 -1
  43. package/dist/chunks/users-C_Dtw_sR.cjs +2 -0
  44. package/dist/chunks/users-C_Dtw_sR.cjs.map +1 -0
  45. package/dist/chunks/users-wgM3TqU3.js +513 -0
  46. package/dist/chunks/users-wgM3TqU3.js.map +1 -0
  47. package/dist/index.cjs +1 -1
  48. package/dist/index.js +4 -4
  49. package/dist/lib/routes-config.d.cts +2 -0
  50. package/dist/lib/routes-config.d.ts +2 -0
  51. package/dist/next/index.cjs +1 -1
  52. package/dist/next/index.js +2 -2
  53. package/dist/pages/admin/stuck-instances/index.cjs +2 -0
  54. package/dist/pages/admin/stuck-instances/index.cjs.map +1 -0
  55. package/dist/pages/admin/stuck-instances/index.d.cts +4 -0
  56. package/dist/pages/admin/stuck-instances/index.d.ts +4 -0
  57. package/dist/pages/admin/stuck-instances/index.js +13 -0
  58. package/dist/pages/admin/stuck-instances/index.js.map +1 -0
  59. package/dist/pages/admin/users/index.cjs +1 -1
  60. package/dist/pages/admin/users/index.js +1 -1
  61. package/dist/pages/instances/detail/index.cjs +1 -1
  62. package/dist/pages/instances/detail/index.js +1 -1
  63. package/dist/pages/templates/compose/index.cjs +1 -1
  64. package/dist/pages/templates/compose/index.js +1 -1
  65. package/dist/pages/templates/designer/index.cjs +1 -1
  66. package/dist/pages/templates/designer/index.js +1 -1
  67. package/dist/views/admin/index.cjs +1 -1
  68. package/dist/views/admin/index.d.cts +1 -0
  69. package/dist/views/admin/index.d.ts +1 -0
  70. package/dist/views/admin/index.js +3 -2
  71. package/dist/views/admin/stuck-instances/AdminStuckInstancesView.d.cts +10 -0
  72. package/dist/views/admin/stuck-instances/AdminStuckInstancesView.d.ts +10 -0
  73. package/dist/views/admin/stuck-instances/StuckInstanceCancelModal.d.cts +14 -0
  74. package/dist/views/admin/stuck-instances/StuckInstanceCancelModal.d.ts +14 -0
  75. package/dist/views/admin/stuck-instances/index.cjs +2 -0
  76. package/dist/views/admin/stuck-instances/index.cjs.map +1 -0
  77. package/dist/views/admin/stuck-instances/index.d.cts +2 -0
  78. package/dist/views/admin/stuck-instances/index.d.ts +2 -0
  79. package/dist/views/admin/stuck-instances/index.js +237 -0
  80. package/dist/views/admin/stuck-instances/index.js.map +1 -0
  81. package/dist/views/admin/users/index.cjs +1 -1
  82. package/dist/views/admin/users/index.js +1 -1
  83. package/dist/views/cc/index.cjs +1 -1
  84. package/dist/views/cc/index.js +1 -1
  85. package/dist/views/dashboard/index.cjs +1 -1
  86. package/dist/views/dashboard/index.js +1 -1
  87. package/dist/views/forms/builder/index.cjs +1 -1
  88. package/dist/views/forms/builder/index.js +1 -1
  89. package/dist/views/forms/renderer/index.cjs +1 -1
  90. package/dist/views/forms/renderer/index.js +1 -1
  91. package/dist/views/inbox/index.cjs +1 -1
  92. package/dist/views/inbox/index.js +1 -1
  93. package/dist/views/instances/detail/index.cjs +1 -1
  94. package/dist/views/instances/detail/index.js +1 -1
  95. package/dist/views/instances/new/index.cjs +1 -1
  96. package/dist/views/instances/new/index.js +4 -4
  97. package/dist/views/instances/new/index.js.map +1 -1
  98. package/dist/views/search/index.cjs +1 -1
  99. package/dist/views/search/index.js +1 -1
  100. package/dist/views/sent/index.cjs +1 -1
  101. package/dist/views/sent/index.js +1 -1
  102. package/dist/views/templates/compose/index.cjs +1 -1
  103. package/dist/views/templates/compose/index.js +1 -1
  104. package/dist/views/templates/designer/approver-resolver-model.d.cts +31 -0
  105. package/dist/views/templates/designer/approver-resolver-model.d.ts +31 -0
  106. package/dist/views/templates/designer/index.cjs +1 -1
  107. package/dist/views/templates/designer/index.js +1 -1
  108. package/dist/views/templates/designer/node-actor-resolver-options.d.cts +30 -3
  109. package/dist/views/templates/designer/node-actor-resolver-options.d.ts +30 -3
  110. package/dist/views/templates/index.cjs +1 -1
  111. package/dist/views/templates/index.js +1 -1
  112. package/dist/views/templates/versions/index.cjs +1 -1
  113. package/dist/views/templates/versions/index.js +1 -1
  114. package/package.json +23 -3
  115. package/dist/chunks/FormRendererView-BlQgJOkI.cjs +0 -6
  116. package/dist/chunks/FormRendererView-BlQgJOkI.cjs.map +0 -1
  117. package/dist/chunks/FormRendererView-CemHvfAT.js +0 -1359
  118. package/dist/chunks/FormRendererView-CemHvfAT.js.map +0 -1
  119. package/dist/chunks/designer-CKwG_vM5.js.map +0 -1
  120. package/dist/chunks/designer-JPs7EijM.cjs +0 -69
  121. package/dist/chunks/designer-JPs7EijM.cjs.map +0 -1
  122. package/dist/chunks/detail-Dqu0K9QM.cjs +0 -5
  123. package/dist/chunks/detail-Dqu0K9QM.cjs.map +0 -1
  124. package/dist/chunks/detail-fW0vJudE.js.map +0 -1
  125. package/dist/chunks/users-BBtiZ9QQ.js +0 -486
  126. package/dist/chunks/users-BBtiZ9QQ.js.map +0 -1
  127. package/dist/chunks/users-EqSzDhuj.cjs +0 -2
  128. package/dist/chunks/users-EqSzDhuj.cjs.map +0 -1
@@ -1,1359 +0,0 @@
1
- "use client";
2
- import { t as e } from "./bpm-form-field-9B-Det0u.js";
3
- import { t } from "./format-member-label-C73FuP-d.js";
4
- import { useCallback as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
5
- import { AutoComplete as s, Button as c, CheckboxGroup as l, DatePicker as u, DateTimePicker as d, Input as f, RadioGroup as p, Select as m, Table as h, Textarea as g, Toggle as _, Typography as v, Upload as y } from "@mezzanine-ui/react";
6
- import { resolveMembers as b, searchMembers as x } from "@rytass/bpm-core-client";
7
- import { jsx as S, jsxs as C } from "react/jsx-runtime";
8
- import { FormFieldDensity as w, FormFieldLayout as T } from "@mezzanine-ui/core/form";
9
- import { buildFormRendererValues as E, clampOptionalNumber as D, createFormTableRow as O, formatDatePickerValue as k, formatDateTimePickerValue as A, isFormRendererFieldReadonly as j, isFormRendererFieldRequired as M, mergeFormDataSourceOptions as N, parseOptionalNumberInput as P, previewFormFieldOptions as ee, previewResolveFormFieldOptions as te, readDatePickerValue as F, readFieldOptionAsSelectOption as I, readFormDataSourceErrorCode as ne, readFormDataSourceErrorMessage as re, readFormDataSourceSelectedValues as ie, readFormDataSourceValueSignature as L, readFormFieldOptions as ae, readFormTableCellPath as oe, readFormTableRowBounds as se, readFormTableRows as ce, readMissingFormDataSourceDependencies as le, readMissingFormDataSourceOptionValues as ue, readSelectOption as R, readSelectedFormDataSourceOptions as de, readVisibleFormRendererFields as z, resolveFormFieldOptions as fe } from "@rytass/bpm-core-client/form";
10
- import { PlusIcon as B, TrashIcon as V } from "@mezzanine-ui/icons";
11
- import { isFormDataSourceFieldDefinition as pe, isFormStaticOptionFieldDefinition as me, isFormTableCellValue as he, isTableFieldDefinition as H, readFormFieldSelectionMode as U, readFormMemberIds as ge } from "@rytass/bpm-core-shared/form";
12
- import { resolveOrgUnitOptions as _e, searchOrgUnitOptions as ve } from "@rytass/bpm-core-client/organization";
13
- // src/views/forms/renderer/form-data-source-field.ts
14
- var ye = {
15
- canRetry: !1,
16
- error: null,
17
- hasValue: !1,
18
- hasNextPage: !1,
19
- loadingNextPage: !1,
20
- invalidValues: [],
21
- onOpen: () => void 0,
22
- onReachBottom: () => void 0,
23
- onSearch: () => void 0,
24
- options: [],
25
- retry: () => void 0,
26
- status: "IDLE"
27
- }, W = [], be = 10, xe = 300, Se = ["FORM_DATA_SOURCE_SEARCH_NOT_SUPPORTED", "FORM_DATA_SOURCE_SEARCH_TOO_SHORT"];
28
- function Ce(e, t) {
29
- if (!t.row) return e;
30
- let n = t.fieldPath?.indexOf(".") ?? -1;
31
- return t.fieldPath && n > 0 ? t.fieldPath.slice(0, n) : null;
32
- }
33
- function we(e, t) {
34
- return t === null ? e : Object.fromEntries(Object.entries(e).filter(([e]) => e !== t));
35
- }
36
- function Te(e, t) {
37
- let n = e.from;
38
- switch (n.kind) {
39
- case "FIELD": return {
40
- fieldKey: n.fieldKey,
41
- value: t.formData[n.fieldKey]
42
- };
43
- case "CONSTANT": return { value: n.value };
44
- case "ROW_FIELD": return {
45
- columnKey: n.columnKey,
46
- value: t.rowValues?.[n.columnKey]
47
- };
48
- case "EXPRESSION": return {
49
- expression: n.expression,
50
- form: we(t.formData, t.ownFormKey),
51
- row: t.rowValues ? we(t.rowValues, t.ownRowKey) : null
52
- };
53
- default: return Ee(n);
54
- }
55
- }
56
- function Ee(e) {
57
- return { unsupported: !0 };
58
- }
59
- function De(e) {
60
- return JSON.stringify(G(e)) ?? "null";
61
- }
62
- function G(e) {
63
- return Array.isArray(e) ? e.map(G) : typeof e == "object" && e ? Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => [e, G(t)])) : e;
64
- }
65
- function Oe(e) {
66
- let t = pe(e.field) ? e.field : null, s = e.fieldPath ?? t?.fieldKey ?? "", c = t ? e.optionSnapshots?.[e.snapshotKey ?? t.fieldKey] : void 0, l = t ? JSON.stringify({
67
- dataSource: t.dataSource,
68
- fieldKey: t.fieldKey,
69
- type: t.type
70
- }) : "", u = JSON.stringify(c ?? null), d = i(() => c?.options ?? [], [u]), f = JSON.stringify(e.formData), p = JSON.stringify(e.initialFormData ?? {}), m = JSON.stringify(e.schema), h = JSON.stringify(e.uiSchema), g = e.context?.kind, _ = e.context?.kind === "runtime" ? e.context.instanceId : void 0, v = e.context?.kind === "runtime" ? e.context.templateId : void 0, y = JSON.stringify(e.row?.values ?? null), b = JSON.stringify(e.row?.initialValues ?? null), x = t ? e.row ? e.row.values[t.fieldKey] : e.formData[t.fieldKey] : void 0, S = L(x), C = i(() => ie(x), [S]), w = C.length > 0, T = t ? JSON.stringify(t.dataSource.bindings.map((n) => Te(n, {
71
- formData: e.formData,
72
- ownFormKey: Ce(t.fieldKey, e),
73
- ownRowKey: e.row ? t.fieldKey : null,
74
- rowValues: e.row?.values
75
- }))) : "", D = t ? JSON.stringify(e.initialFormData !== void 0 || e.initialValue !== void 0 ? x ?? null : null) : "", O = t ? `${T}\u0000${D}` : "", k = ke(T, t?.dataSource.bindings.some((e) => e.from.kind === "EXPRESSION") ? xe : 0), A = k !== T, j = i(() => {
76
- if (g === "preview") return { kind: "preview" };
77
- if (g === "runtime" && !e.readonly) return {
78
- instanceId: _,
79
- kind: "runtime",
80
- templateId: v
81
- };
82
- }, [
83
- _,
84
- g,
85
- v,
86
- e.readonly
87
- ]), M = t ? (e.initialFormData !== void 0 || e.initialValue !== void 0) && L(e.initialValue) !== S : !1, P = t ? e.initialFormData !== void 0 && t.dataSource.bindings.some((n) => {
88
- if (n.from.kind === "FIELD") return L(e.initialFormData?.[n.from.fieldKey]) !== L(e.formData[n.from.fieldKey]);
89
- if (n.from.kind === "ROW_FIELD" && e.row?.initialValues) return L(e.row.initialValues[n.from.columnKey]) !== L(e.row.values[n.from.columnKey]);
90
- if (n.from.kind === "EXPRESSION") {
91
- if (!j) return !1;
92
- let r = {
93
- ownFormKey: Ce(t.fieldKey, e),
94
- ownRowKey: e.row ? t.fieldKey : null
95
- };
96
- return De(Te(n, {
97
- ...r,
98
- formData: E(e.schema.fields, e.initialFormData ?? {}),
99
- rowValues: e.row?.initialValues ?? e.row?.values
100
- })) !== De(Te(n, {
101
- ...r,
102
- formData: E(e.schema.fields, e.formData),
103
- rowValues: e.row?.values
104
- }));
105
- }
106
- return !1;
107
- }) : !1, F = !!t?.dataSource.bindings.some((e) => e.from.kind === "EXPRESSION"), [I, oe] = o(() => ({
108
- bindings: k,
109
- value: S
110
- }));
111
- I.value !== S && oe({
112
- bindings: k,
113
- value: S
114
- });
115
- let se = !!(F && j && w && I.value === S && I.bindings !== k), ce = !(!t || c || e.initialFormData !== void 0 || e.initialValue !== void 0 || t.defaultValue === void 0 || S !== L(t.defaultValue)), ue = !!((c || w) && (M || P || se || ce)), R = !!(t && j && ue && w), z = Ne({
116
- hasSnapshot: !!c,
117
- hasValue: w,
118
- isStale: ue,
119
- readonly: e.readonly
120
- }), B = !!(t && j && t.type !== "autocomplete"), V = Pe(ue, B && t !== null && le(t, e.formData, e.row?.values).length > 0), me = a(z);
121
- me.current = z;
122
- let [he, H] = o([]), [U, ge] = o(""), [_e, ve] = o(null), [W, we] = o(null), [Ee, G] = o(() => t ? B ? V : z : "IDLE"), [Oe, K] = o(null), [Ae, je] = o(!1), q = a(0), J = a(0), Y = a(0), ze = a(null), Be = a(null), Ve = a(!1), He = a({
123
- cursor: null,
124
- searchText: ""
125
- }), X = i(() => Re(e.formData), [f]), Z = i(() => e.row ? Re(e.row.values) : void 0, [y]), Ue = i(() => N(d, he), [he, d]), We = W && W.signature === O && W.valueSignature === S ? W : null, Ge = R && !We, Ke = !!(se && We && We.unresolvedValues.length > 0), qe = Me({
126
- options: Ue,
127
- resolution: We,
128
- resolvePending: Ge,
129
- value: x
130
- }), Q = n((n, r) => {
131
- if (!t || !j) return;
132
- let i = J.current + 1;
133
- J.current = i, Ve.current = !0, He.current = {
134
- cursor: r,
135
- searchText: n
136
- }, ze.current?.abort();
137
- let a = new AbortController();
138
- ze.current = a, G(V), je(r !== null), K(null), (j.kind === "preview" ? ee({
139
- cursor: r,
140
- fieldKey: s,
141
- formData: X,
142
- rowValues: Z,
143
- schema: e.schema,
144
- searchText: n,
145
- signal: a.signal,
146
- uiSchema: e.uiSchema
147
- }) : ae({
148
- cursor: r,
149
- fieldKey: s,
150
- formData: X,
151
- instanceId: j.instanceId ?? null,
152
- rowValues: Z,
153
- searchText: n,
154
- signal: a.signal,
155
- templateId: j.templateId ?? null
156
- })).then((e) => {
157
- Le(a, J, i) || (je(!1), H((t) => {
158
- let n = de(x, t);
159
- return N(n, r ? t : [], e.options);
160
- }), ve(e.nextCursor), K(null), q.current = r ? q.current + e.options.length : e.options.length, e.nextCursor && e.options.length > 0 && q.current < be && Je.current(n, e.nextCursor), G(e.waitingForFieldKeys.length ? "WAITING_FOR_DEPENDENCIES" : "VALID"));
161
- }).catch((e) => {
162
- if (Le(a, J, i)) return;
163
- r === null && (Ve.current = !1), je(!1);
164
- let t = re(e) ?? "選項來源暫時無法使用。", n = ne(e);
165
- K(t), G(Fe(!!(n && Se.includes(n)), w));
166
- });
167
- }, [
168
- S,
169
- l,
170
- j,
171
- w,
172
- V,
173
- s,
174
- X,
175
- Z,
176
- m,
177
- h
178
- ]), Je = a(Q);
179
- Je.current = Q;
180
- let Ye = n(() => {
181
- if (!t || !j || C.length === 0) return;
182
- let n = O, r = S, i = Y.current + 1;
183
- Y.current = i, Be.current?.abort();
184
- let a = new AbortController();
185
- Be.current = a, K(null), (j.kind === "preview" ? te({
186
- fieldKey: s,
187
- formData: X,
188
- rowValues: Z,
189
- schema: e.schema,
190
- signal: a.signal,
191
- uiSchema: e.uiSchema,
192
- values: C
193
- }) : fe({
194
- fieldKey: s,
195
- formData: X,
196
- instanceId: j.instanceId ?? null,
197
- rowValues: Z,
198
- signal: a.signal,
199
- templateId: j.templateId ?? null,
200
- values: C
201
- })).then((e) => {
202
- Le(a, Y, i) || (e.waitingForFieldKeys.length ? G("WAITING_FOR_DEPENDENCIES") : (H((t) => N(t, e.options)), we({
203
- signature: n,
204
- unresolvedValues: e.unresolvedValues,
205
- valueSignature: r
206
- }), G("VALID")));
207
- }).catch((e) => {
208
- Le(a, Y, i) || (G("UNAVAILABLE"), K(re(e) ?? "選項來源暫時無法使用。"));
209
- });
210
- }, [
211
- S,
212
- O,
213
- l,
214
- j,
215
- s,
216
- X,
217
- Z,
218
- m,
219
- C,
220
- h
221
- ]), Xe = a(Ye);
222
- Xe.current = Ye, r(() => {
223
- J.current += 1, Ve.current = !1, ze.current?.abort(), je(!1), H((e) => de(x, e)), ve((e) => e === null ? e : null), ge((e) => e && ""), K((e) => e && null), t ? B ? Je.current("", null) : G(me.current) : G("IDLE");
224
- }, [
225
- B,
226
- l,
227
- j,
228
- k,
229
- D,
230
- p,
231
- b,
232
- e.readonly,
233
- u
234
- ]), r(() => {
235
- t && !B && G(z);
236
- }, [
237
- B,
238
- l,
239
- z
240
- ]), r(() => {
241
- R && !A && Xe.current();
242
- }, [
243
- j,
244
- R,
245
- A,
246
- k,
247
- D
248
- ]), r(() => () => {
249
- ze.current?.abort(), Be.current?.abort();
250
- }, []);
251
- let Ze = n((e) => {
252
- ge(e), H((e) => de(x, e)), ve(null), Q(e, null);
253
- }, [Q]), Qe = n(() => {
254
- B || !j || e.readonly || Ve.current && U === "" || Ze("");
255
- }, [
256
- B,
257
- j,
258
- e.readonly,
259
- Ze,
260
- U
261
- ]), $e = a({
262
- cursor: _e,
263
- searchText: U
264
- });
265
- $e.current = {
266
- cursor: _e,
267
- searchText: U
268
- };
269
- let et = n(() => {
270
- let { cursor: e, searchText: t } = $e.current;
271
- e && Je.current(t, e);
272
- }, []), tt = n(() => {
273
- j && (Q(He.current.searchText, He.current.cursor), R && Xe.current());
274
- }, [
275
- j,
276
- Q,
277
- R
278
- ]);
279
- return t ? {
280
- canRetry: !!j,
281
- error: Oe,
282
- hasValue: w,
283
- hasNextPage: !!_e,
284
- loadingNextPage: Ae,
285
- invalidValues: qe,
286
- onOpen: Qe,
287
- onReachBottom: et,
288
- onSearch: Ze,
289
- options: Ue,
290
- retry: tt,
291
- selectionExpired: Ke,
292
- status: A && j && (B || w) ? B ? V : "STALE" : Ie({
293
- invalidValues: qe,
294
- resolvePending: Ge,
295
- status: Ee
296
- })
297
- } : ye;
298
- }
299
- function ke(e, t) {
300
- let [n, i] = o(e);
301
- return r(() => {
302
- if (t <= 0) return;
303
- let n = setTimeout(() => {
304
- i(e);
305
- }, t);
306
- return () => {
307
- clearTimeout(n);
308
- };
309
- }, [t, e]), t > 0 ? n : e;
310
- }
311
- function K(e) {
312
- switch (e.status) {
313
- case "WAITING_FOR_DEPENDENCIES": return "請先填寫相依欄位。";
314
- case "STALE": return "選項需要重新載入或驗證。";
315
- case "INVALID": return e.selectionExpired ? re("FORM_DATA_SOURCE_VALUE_NOT_RESOLVED") : e.invalidValues.length ? `無法辨識選項:${e.invalidValues.join("、")}` : "目前選項已失效,請重新選擇。";
316
- case "UNAVAILABLE": return e.error ?? "選項來源暫時無法使用。";
317
- case "VALID": return e.error ?? (e.options.length ? null : "目前沒有可用選項。");
318
- default: return e.error;
319
- }
320
- }
321
- function Ae(e) {
322
- return e.hasValue && e.status !== "VALID";
323
- }
324
- function je(e) {
325
- let t = e.filter(Ae);
326
- return t.length === 0 ? null : t.some((e) => e.status === "INVALID" && e.selectionExpired === !0) ? re("FORM_DATA_SOURCE_VALUE_NOT_RESOLVED") : t.every((e) => e.status === "LOADING" || e.status === "STALE") ? "選項驗證中,請稍候再送出。" : "請先完成動態選項驗證。";
327
- }
328
- function Me(e) {
329
- return e.resolution ? e.resolution.unresolvedValues : e.resolvePending ? W : ue(e.value, e.options);
330
- }
331
- function Ne(e) {
332
- return e.isStale ? "STALE" : e.hasSnapshot ? "VALID" : e.readonly && e.hasValue ? "UNAVAILABLE" : "IDLE";
333
- }
334
- function Pe(e, t) {
335
- return t ? "WAITING_FOR_DEPENDENCIES" : e ? "STALE" : "LOADING";
336
- }
337
- function Fe(e, t) {
338
- return e ? t ? "VALID" : "IDLE" : "UNAVAILABLE";
339
- }
340
- function Ie(e) {
341
- return e.status === "LOADING" || e.status === "UNAVAILABLE" || e.status === "WAITING_FOR_DEPENDENCIES" ? e.status : e.invalidValues.length ? "INVALID" : e.resolvePending ? "STALE" : e.status;
342
- }
343
- function Le(e, t, n) {
344
- return e.signal.aborted || t.current !== n;
345
- }
346
- function Re(e) {
347
- return Object.entries(e).reduce((e, [t, n]) => n === void 0 ? e : {
348
- ...e,
349
- [t]: n
350
- }, {});
351
- }
352
- // src/views/forms/renderer/form-value-readers.ts
353
- function q(e) {
354
- return Array.isArray(e) && e.every((e) => typeof e == "string") ? e : [];
355
- }
356
- // src/views/forms/renderer/file-upload-field.tsx
357
- function J(e) {
358
- return e.some((e) => e.pendingCount > 0) ? "附件仍在上傳中,請稍候再送出。" : e.some((e) => e.failedCount > 0) ? "有附件上傳失敗,請重試或移除後再送出。" : null;
359
- }
360
- function Y() {
361
- let [e, t] = o({}), r = n((e, n) => t((t) => ({
362
- ...t,
363
- [e]: n
364
- })), []);
365
- return {
366
- blockMessage: J(Object.values(e)),
367
- onFileUploadStateChange: r
368
- };
369
- }
370
- var ze = "無法讀取檔名的附件", Be = "此處無法上傳附件";
371
- function Ve({ attachments: e, field: t, onChange: s, onDownloadAttachment: c, onStateChange: l, onUploadAttachment: u, readonly: d, value: f }) {
372
- let [p, m] = o([]), [h, g] = o(() => /* @__PURE__ */ new Map()), [_, v] = o([]), b = q(f), x = b.join("\n"), C = i(() => new Map((e ?? []).map((e) => [e.id, e])), [e]), w = i(() => {
373
- let e = new Map(_.map((e, t) => [e, t]));
374
- return [...b.map((e) => h.get(e) ?? He(e, C.get(e))), ...p].sort((t, n) => (e.get(t.id) ?? -1) - (e.get(n.id) ?? -1));
375
- }, [
376
- C,
377
- _,
378
- h,
379
- p,
380
- x
381
- ]), T = a(w), E = a(!0), D = a(M);
382
- D.current = M, r(() => {
383
- T.current = w;
384
- }, [w]);
385
- let O = n((e) => D.current(e), []), k = p.filter((e) => e.status === "loading").length, A = p.filter((e) => e.status === "error").length, j = a(l);
386
- j.current = l, r(() => {
387
- j.current?.({
388
- failedCount: A,
389
- pendingCount: k
390
- });
391
- }, [A, k]), r(() => (E.current = !0, () => {
392
- E.current = !1, j.current?.({
393
- failedCount: 0,
394
- pendingCount: 0
395
- });
396
- }), []);
397
- function M(e) {
398
- if (!E.current) return;
399
- let t = e.filter((e) => e.status === "done"), n = t.map((e) => e.id), r = new Set(b), i = t.filter((e) => e.file !== void 0 && !r.has(e.id));
400
- T.current = e, v(e.map((e) => e.id)), m(e.filter((e) => e.status !== "done")), i.length > 0 && g((e) => new Map([...e, ...i.map((e) => [e.id, e])])), n.join("\n") !== x && s(n.length ? n : void 0);
401
- }
402
- async function N(e) {
403
- if (!u) throw Error(Be);
404
- return {
405
- file: e,
406
- id: (await u(t, e)).id,
407
- progress: 100,
408
- status: "done"
409
- };
410
- }
411
- async function P(e, t) {
412
- let n = await N(t).catch((n) => ({
413
- errorMessage: Z(n),
414
- file: t,
415
- id: e,
416
- status: "error"
417
- }));
418
- D.current(T.current.map((t) => t.id === e ? n : t));
419
- }
420
- function ee(e, t) {
421
- h.has(e) ? Ue(t) : c?.(e);
422
- }
423
- let te = !!u && !d, F = [...!d && !u ? [{
424
- label: Be,
425
- type: "info"
426
- }] : [], ...p.filter((e) => e.status === "error").map((e) => ({
427
- label: `${e.file?.name ?? "檔案"}:${e.errorMessage ?? "上傳失敗"},未附加。請重試或刪除。`,
428
- type: "error"
429
- }))];
430
- return /* @__PURE__ */ S(y, {
431
- accept: t.acceptedMimeTypes?.join(","),
432
- disabled: !te,
433
- files: w,
434
- ...F.length > 0 ? { hints: F } : {},
435
- maxFiles: t.maxFiles,
436
- mode: "button-list",
437
- ...(t.maxFiles ?? 1) > 1 ? { multiple: !0 } : {},
438
- onChange: O,
439
- onDownload: ee,
440
- onReload: (e, t) => {
441
- P(e, t);
442
- },
443
- onUpload: async (e) => Promise.all(e.map(async (e) => N(e).catch((t) => ({
444
- errorMessage: Z(t),
445
- file: e,
446
- id: `failed-${e.name}-${e.lastModified}-${Math.random()}`,
447
- status: "error"
448
- })))),
449
- size: "sub"
450
- });
451
- }
452
- function He(e, t) {
453
- return t ? {
454
- file: X(t),
455
- id: e,
456
- progress: 100,
457
- status: "done"
458
- } : {
459
- id: e,
460
- progress: 100,
461
- status: "done",
462
- url: ze
463
- };
464
- }
465
- function X(e) {
466
- let t = new File([], e.filename), n = Number(e.sizeBytes);
467
- return Number.isFinite(n) && n >= 0 && Object.defineProperty(t, "size", { value: n }), t;
468
- }
469
- function Z(e) {
470
- return e instanceof Error && e.message ? `上傳失敗:${e.message}` : "上傳失敗,請重試。";
471
- }
472
- function Ue(e) {
473
- let t = URL.createObjectURL(e), n = document.createElement("a");
474
- n.href = t, n.download = e.name, n.style.display = "none", document.body.appendChild(n), n.click(), n.remove(), setTimeout(() => URL.revokeObjectURL(t), 3e4);
475
- }
476
- // src/views/forms/renderer/form-field-link.ts
477
- var We = /\s/u;
478
- function Ge(e) {
479
- return [...e].some((e) => {
480
- let t = e.codePointAt(0) ?? 0;
481
- return t <= 32 || t >= 127 && t <= 160 || We.test(e);
482
- });
483
- }
484
- var Ke = /^https?:\/\//iu;
485
- function qe(e) {
486
- return typeof e != "string" || !e || e.includes("\\") || Ge(e) ? null : e.startsWith("/") ? !e.startsWith("//") && Je(e) ? {
487
- external: !1,
488
- href: e
489
- } : null : Ke.test(e) && Ye(e) ? {
490
- external: !0,
491
- href: e
492
- } : null;
493
- }
494
- var Q = "http://placeholder.invalid";
495
- function Je(e) {
496
- try {
497
- let t = new URL(e, Q);
498
- return t.origin === Q && !t.pathname.startsWith("//");
499
- } catch {
500
- return !1;
501
- }
502
- }
503
- function Ye(e) {
504
- try {
505
- let t = new URL(e);
506
- return (t.protocol === "http:" || t.protocol === "https:") && !!t.hostname && !t.username && !t.password;
507
- } catch {
508
- return !1;
509
- }
510
- }
511
- async function Xe(e, t, n = {}) {
512
- let r = n.maxPerIdRequests ?? 20, i = Math.max(1, n.concurrency ?? 4);
513
- try {
514
- return {
515
- failedIds: [],
516
- profiles: await t(e),
517
- skippedIds: []
518
- };
519
- } catch {
520
- if (e.length <= 1) return {
521
- failedIds: e,
522
- profiles: [],
523
- skippedIds: []
524
- };
525
- }
526
- let a = e.slice(0, r), o = await Qe(a, i, (e) => t([e]));
527
- return {
528
- failedIds: a.filter((e, t) => o[t].status === "rejected"),
529
- profiles: o.flatMap((e) => e.status === "fulfilled" ? e.value : []),
530
- skippedIds: e.slice(r)
531
- };
532
- }
533
- function Ze(e, t) {
534
- return e.filter((e) => !t.has(e));
535
- }
536
- async function Qe(e, t, n) {
537
- let r = [], i = 0;
538
- async function a() {
539
- for (; i < e.length;) {
540
- let t = i;
541
- i += 1, r[t] = await n(e[t]).then((e) => ({
542
- status: "fulfilled",
543
- value: e
544
- }), (e) => ({
545
- reason: e,
546
- status: "rejected"
547
- }));
548
- }
549
- }
550
- return await Promise.all(Array.from({ length: Math.min(t, e.length) }, a)), r;
551
- }
552
- // src/views/forms/renderer/member-field-options.ts
553
- var $e = "未知會員";
554
- function et(e) {
555
- return {
556
- id: e.memberId,
557
- name: t(e.name, e.email)
558
- };
559
- }
560
- function tt(e) {
561
- return {
562
- id: e,
563
- name: $e,
564
- unresolved: !0
565
- };
566
- }
567
- function nt(e, t) {
568
- let n = new Map(t.filter((e) => !e.unresolved).map((e) => [e.id, e])), r = new Set(e.map((e) => e.id)), i = t.filter((e, n) => !r.has(e.id) && t.findIndex((t) => t.id === e.id) === n), a = e.map((e) => (e.unresolved ? n.get(e.id) : void 0) ?? e);
569
- return i.length > 0 || a.some((t, n) => t !== e[n]) ? [...a, ...i] : e;
570
- }
571
- function rt(e, t) {
572
- let n = new Set(t.filter((e) => !e.unresolved).map((e) => e.id));
573
- return ge(e).filter((e) => !n.has(e));
574
- }
575
- function it(e, t) {
576
- return ge(e).map((e) => t.find((t) => t.id === e) ?? tt(e));
577
- }
578
- function at(e, t) {
579
- if (e.length !== 0) return t ? e.map((e) => e.id) : e[0]?.id;
580
- }
581
- // src/views/forms/renderer/member-field.tsx
582
- function ot({ multiple: e, name: t, onChange: n, placeholder: i, readonly: c, size: l, value: u }) {
583
- let [d, f] = o([]), [p, m] = o([]), [h, g] = o(!1), _ = a(0), v = a(/* @__PURE__ */ new Set()), y = rt(u, d).join("\n");
584
- r(() => {
585
- let e = Ze(y ? y.split("\n") : [], v.current), t = !1;
586
- return e.length === 0 ? () => void 0 : (Xe(e, b).then(({ profiles: n, skippedIds: r }) => {
587
- if (t) return;
588
- let i = n.map(et), a = e.filter((e) => !i.some((t) => t.id === e)).map(tt);
589
- a.filter((e) => !r.includes(e.id)).forEach((e) => v.current.add(e.id)), f((e) => nt(e, [...i, ...a]));
590
- }), () => {
591
- t = !0;
592
- });
593
- }, [y]);
594
- async function C(e) {
595
- let t = _.current + 1;
596
- _.current = t, g(!0);
597
- try {
598
- let n = (await x(e)).map(et);
599
- _.current === t && (m(n), f((e) => nt(e, n)));
600
- } catch {
601
- _.current === t && m([]);
602
- } finally {
603
- _.current === t && g(!1);
604
- }
605
- }
606
- let w = it(u, d), T = [...nt(w, p)], E = {
607
- asyncData: !0,
608
- clearSearchText: !0,
609
- disabled: c,
610
- disabledOptionsFilter: !0,
611
- emptyText: "沒有符合的成員",
612
- globalPortal: !0,
613
- inputProps: {
614
- autoCapitalize: "none",
615
- autoCorrect: "off",
616
- name: t,
617
- spellCheck: !1
618
- },
619
- loading: h,
620
- loadingText: "搜尋成員中...",
621
- menuMaxHeight: 320,
622
- onSearch: C,
623
- onVisibilityChange: (e) => {
624
- e && (m([]), C(""));
625
- },
626
- options: T,
627
- placeholder: i ?? "搜尋姓名或信箱",
628
- readOnly: c,
629
- searchDebounceTime: 300,
630
- size: l
631
- };
632
- return e ? /* @__PURE__ */ S(s, {
633
- ...E,
634
- mode: "multiple",
635
- onChange: (e) => n(at(e, !0)),
636
- value: [...w]
637
- }) : /* @__PURE__ */ S(s, {
638
- ...E,
639
- mode: "single",
640
- onChange: (e) => n(at(e ? [e] : [], !1)),
641
- value: w[0] ?? null
642
- });
643
- }
644
- // src/views/forms/renderer/org-unit-field-options.ts
645
- var st = "未知組織", ct = "(已刪除)";
646
- function lt(e) {
647
- return {
648
- id: e.id,
649
- name: e.deleted ? `${e.name}${ct}` : e.name
650
- };
651
- }
652
- function ut(e) {
653
- return {
654
- id: e,
655
- name: e,
656
- unresolved: !0
657
- };
658
- }
659
- function dt(e) {
660
- return {
661
- id: e,
662
- name: st,
663
- unresolved: !0
664
- };
665
- }
666
- function ft(e) {
667
- return typeof e == "string" && e.trim() ? e : null;
668
- }
669
- function $(e) {
670
- return e.toLowerCase();
671
- }
672
- function pt(e, t) {
673
- return $(e) === $(t);
674
- }
675
- function mt(e, t) {
676
- let n = ft(e);
677
- return n === null ? null : t.find((e) => pt(e.id, n)) ?? ut(n);
678
- }
679
- function ht(e, t) {
680
- let n = ft(e);
681
- return n !== null && !t.some((e) => pt(e.id, n)) ? n : null;
682
- }
683
- function gt(e, t) {
684
- let n = new Map(t.filter((e) => !e.unresolved).map((e) => [$(e.id), e])), r = new Set(e.map((e) => $(e.id))), i = t.filter((e, n) => !r.has($(e.id)) && t.findIndex((t) => pt(t.id, e.id)) === n), a = e.map((e) => (e.unresolved ? n.get($(e.id)) : void 0) ?? e);
685
- return i.length > 0 || a.some((t, n) => t !== e[n]) ? [...a, ...i] : e;
686
- }
687
- function _t(e) {
688
- return e ? e.id : void 0;
689
- }
690
- // src/views/forms/renderer/org-unit-field.tsx
691
- var vt = "搜尋組織失敗,請稍後再試。";
692
- function yt({ name: e, onChange: t, placeholder: n, readonly: i, size: c, value: l }) {
693
- let [u, d] = o([]), [f, p] = o([]), [m, h] = o(!1), [g, _] = o(!1), y = a(0), b = ht(l, u);
694
- r(() => {
695
- let e = !1;
696
- return b === null ? () => void 0 : (_e([b]).then((e) => {
697
- let t = e.map(lt);
698
- return t.some((e) => e.id.toLowerCase() === b.toLowerCase()) ? t : [...t, dt(b)];
699
- }).catch(() => [dt(b)]).then((t) => {
700
- e || d((e) => gt(e, t));
701
- }), () => {
702
- e = !0;
703
- });
704
- }, [b]);
705
- async function x(e) {
706
- let t = y.current + 1;
707
- y.current = t, h(!0);
708
- try {
709
- let n = (await ve(e)).map(lt);
710
- y.current === t && (p(n), _(!1), d((e) => gt(e, n)));
711
- } catch {
712
- y.current === t && (p([]), _(!0));
713
- } finally {
714
- y.current === t && h(!1);
715
- }
716
- }
717
- let w = mt(l, u), T = [...gt(w ? [w] : [], f)];
718
- return /* @__PURE__ */ C("div", { children: [/* @__PURE__ */ S(s, {
719
- asyncData: !0,
720
- clearSearchText: !0,
721
- disabled: i,
722
- disabledOptionsFilter: !0,
723
- emptyText: "沒有符合的組織",
724
- globalPortal: !0,
725
- inputProps: {
726
- autoCapitalize: "none",
727
- autoCorrect: "off",
728
- name: e,
729
- spellCheck: !1
730
- },
731
- loading: m,
732
- loadingText: "搜尋組織中...",
733
- menuMaxHeight: 320,
734
- mode: "single",
735
- onChange: (e) => t(_t(e ?? null)),
736
- onSearch: x,
737
- onVisibilityChange: (e) => {
738
- e && (p([]), x(""));
739
- },
740
- options: T,
741
- placeholder: n ?? "搜尋組織名稱",
742
- readOnly: i,
743
- searchDebounceTime: 300,
744
- size: c,
745
- value: w
746
- }), g ? /* @__PURE__ */ S(v, {
747
- color: "text-error",
748
- variant: "caption",
749
- children: vt
750
- }) : null] });
751
- }
752
- // src/views/forms/renderer/FormRendererView.tsx
753
- var bt = {
754
- alignItems: "start",
755
- display: "grid",
756
- gap: 12,
757
- gridTemplateColumns: "repeat(12, minmax(0, 1fr))"
758
- }, xt = { gridColumn: "1 / -1" }, St = {
759
- alignItems: "start",
760
- display: "grid",
761
- gap: 8,
762
- minWidth: 0
763
- }, Ct = {
764
- minWidth: "100%",
765
- width: "100%"
766
- };
767
- function wt(e) {
768
- e && (e.style.width = "100%");
769
- }
770
- function Tt({ attachments: e, dataSourceContext: t, dataSourceInitialValues: n, emptyText: s = "尚未建立欄位。", errors: c = {}, fieldAccess: l, fieldLabelMarkers: u, maxWidth: d, onChange: f, onDataSourceStateChange: p, onDownloadAttachment: m, onFileUploadStateChange: h, onUploadAttachment: g, optionSnapshots: _, readonly: y = !1, schema: b, singleColumn: x = !1, tableAccess: C, uiSchema: w, value: T }) {
771
- let D = i(() => ({
772
- attachments: e,
773
- onDownloadAttachment: m,
774
- onStateChange: h,
775
- onUploadAttachment: g
776
- }), [
777
- e,
778
- m,
779
- h,
780
- g
781
- ]), [O, k] = o(() => E(b.fields, T ?? {})), A = i(() => E(b.fields, T ?? O), [
782
- O,
783
- b.fields,
784
- T
785
- ]), j = a(A), M = i(() => z(b, w, A).filter((e) => Et(l, e.fieldKey)?.visible !== !1), [
786
- l,
787
- b,
788
- w,
789
- A
790
- ]);
791
- r(() => {
792
- j.current = A;
793
- }, [A]), r(() => {
794
- k((e) => E(b.fields, T ?? e));
795
- }, [b.fields, T]);
796
- function N(e, t) {
797
- let n = {
798
- ...j.current,
799
- [e]: t
800
- };
801
- j.current = n, T || k(n), f?.(n);
802
- }
803
- return M.length ? /* @__PURE__ */ S("div", {
804
- style: {
805
- ...bt,
806
- ...x ? { width: "100%" } : {}
807
- },
808
- children: M.map((e) => /* @__PURE__ */ S(At, {
809
- dataSourceContext: t,
810
- dataSourceInitialValues: n,
811
- field: e,
812
- error: c[e.fieldKey] ?? null,
813
- errors: c,
814
- fields: b.fields,
815
- labelMarker: u !== void 0 && Object.prototype.hasOwnProperty.call(u, e.fieldKey) ? u[e.fieldKey] : void 0,
816
- onChange: N,
817
- fileUpload: D,
818
- onDataSourceStateChange: p,
819
- optionSnapshots: _,
820
- readonly: kt(e, Et(l, e.fieldKey), Ot(C, e.fieldKey), y),
821
- schema: b,
822
- tableAccess: Ot(C, e.fieldKey),
823
- style: {
824
- ...St,
825
- gridColumn: `span ${x ? 12 : Yt(e, w)}`,
826
- ...x && !H(e) ? { maxWidth: d } : {}
827
- },
828
- value: A[e.fieldKey],
829
- values: A,
830
- uiSchema: w
831
- }, e.fieldKey))
832
- }) : /* @__PURE__ */ S("div", {
833
- style: bt,
834
- children: /* @__PURE__ */ S(v, {
835
- color: "text-neutral",
836
- style: xt,
837
- variant: "body",
838
- children: b.fields.length > 0 ? "目前條件下沒有可填寫欄位。" : s
839
- })
840
- });
841
- }
842
- function Et(e, t) {
843
- return e !== void 0 && Object.prototype.hasOwnProperty.call(e, t) ? e[t] : void 0;
844
- }
845
- function Dt(e, t) {
846
- return e === void 0 ? t : !e.editable;
847
- }
848
- function Ot(e, t) {
849
- return e !== void 0 && Object.prototype.hasOwnProperty.call(e, t) ? e[t] : void 0;
850
- }
851
- function kt(e, t, n, r) {
852
- return n !== void 0 && H(e) ? r : Dt(t, r);
853
- }
854
- function At({ dataSourceContext: t, dataSourceInitialValues: n, error: i, errors: a, field: o, fields: s, fileUpload: l, labelMarker: u, onChange: d, onDataSourceStateChange: f, optionSnapshots: p, readonly: m, schema: h, style: g, tableAccess: _, value: y, values: b, uiSchema: x }) {
855
- let w = M(o, s, b), T = m || j(o, s, b), E = Oe({
856
- context: t,
857
- field: o,
858
- formData: b,
859
- initialFormData: n,
860
- initialValue: n?.[o.fieldKey],
861
- optionSnapshots: p,
862
- readonly: T,
863
- schema: h,
864
- uiSchema: x
865
- }), D = K(E), O = JSON.stringify({
866
- hasValue: E.hasValue,
867
- invalidValues: E.invalidValues,
868
- selectionExpired: E.selectionExpired === !0,
869
- status: E.status
870
- });
871
- return r(() => {
872
- pe(o) && f?.(o.fieldKey, {
873
- hasValue: E.hasValue,
874
- invalidValues: E.invalidValues,
875
- selectionExpired: E.selectionExpired === !0,
876
- status: E.status
877
- });
878
- }, [
879
- O,
880
- o.fieldKey,
881
- f
882
- ]), /* @__PURE__ */ C("div", {
883
- "data-form-field-key": o.fieldKey,
884
- style: g,
885
- children: [
886
- /* @__PURE__ */ S(e, {
887
- label: o.label,
888
- ...u ? { labelOptionalMarker: u } : {},
889
- ...H(o) ? Rt : {},
890
- name: o.fieldKey,
891
- required: w,
892
- children: H(o) ? /* @__PURE__ */ S(Bt, {
893
- dataSourceContext: t,
894
- dataSourceInitialValues: n,
895
- errors: a,
896
- field: o,
897
- onChange: d,
898
- onDataSourceStateChange: f,
899
- optionSnapshots: p,
900
- readonly: T,
901
- schema: h,
902
- tableAccess: _,
903
- uiSchema: x,
904
- value: y,
905
- values: b
906
- }) : Kt(o, y, T, d, l, t, E)
907
- }),
908
- i ? /* @__PURE__ */ S(v, {
909
- color: "text-error",
910
- variant: "caption",
911
- children: i
912
- }) : null,
913
- D ? /* @__PURE__ */ C("div", {
914
- style: Pt,
915
- children: [/* @__PURE__ */ S(v, {
916
- color: E.status === "INVALID" || E.status === "UNAVAILABLE" ? "text-error" : "text-neutral",
917
- variant: "caption",
918
- children: D
919
- }), E.status === "UNAVAILABLE" && E.canRetry ? /* @__PURE__ */ S(c, {
920
- onClick: E.retry,
921
- size: "sub",
922
- type: "button",
923
- variant: "base-ghost",
924
- children: "重試"
925
- }) : null]
926
- }) : null
927
- ]
928
- });
929
- }
930
- var jt = "(另開新分頁)", Mt = "另開新分頁", Nt = {
931
- color: "inherit",
932
- textDecoration: "underline",
933
- wordBreak: "break-all"
934
- }, Pt = {
935
- alignItems: "center",
936
- display: "flex",
937
- gap: 8
938
- }, Ft = {
939
- display: "grid",
940
- gap: 8,
941
- minWidth: 0,
942
- width: "100%"
943
- }, It = {
944
- display: "flex",
945
- justifyContent: "flex-start"
946
- }, Lt = 160, Rt = {
947
- density: w.BASE,
948
- layout: T.STRETCH
949
- }, zt = {
950
- display: "grid",
951
- gap: 4,
952
- minWidth: 0
953
- };
954
- function Bt({ dataSourceContext: e, dataSourceInitialValues: t, errors: n, field: i, onChange: s, onDataSourceStateChange: l, optionSnapshots: u, readonly: d, schema: f, tableAccess: p, uiSchema: m, value: g, values: _ }) {
955
- let v = ce(g), y = se(i), b = p?.lockRows === !0, x = (e) => p === void 0 || p.editableColumns.includes(e), w = a(0), [T, E] = o(() => v.map(() => Ut(w)));
956
- r(() => {
957
- T.length !== v.length && E(v.map(() => Ut(w)));
958
- }, [T.length, v.length]);
959
- function D(e) {
960
- s(i.fieldKey, e);
961
- }
962
- function k() {
963
- E([...T, Ut(w)]), D([...v, O(i.columns)]);
964
- }
965
- function A(e) {
966
- E(T.filter((t, n) => n !== e)), D(v.filter((t, n) => n !== e));
967
- }
968
- function j(e, t, n) {
969
- D(v.map((r, i) => i === e ? Wt(r, t, n) : r));
970
- }
971
- let M = v.map((e, t) => ({
972
- ...e,
973
- index: t,
974
- key: T[t] ?? `row-${t}`
975
- })), N = i.columns.map((r) => ({
976
- key: r.fieldKey,
977
- minWidth: Lt,
978
- render: (a) => /* @__PURE__ */ S(Vt, {
979
- column: r,
980
- dataSourceContext: e,
981
- error: n[oe(i.fieldKey, a.index, r.fieldKey)] ?? null,
982
- fieldPath: `${i.fieldKey}.${r.fieldKey}`,
983
- formData: _,
984
- initialFormData: t,
985
- initialRowValues: Ht(t?.[i.fieldKey], a.index),
986
- onChange: (e) => j(a.index, r.fieldKey, e),
987
- onDataSourceStateChange: l,
988
- optionSnapshots: u,
989
- path: oe(i.fieldKey, a.index, r.fieldKey),
990
- readonly: d || !x(r.fieldKey),
991
- rowValues: v[a.index] ?? {},
992
- schema: f,
993
- uiSchema: m
994
- }, `${T[a.index] ?? a.index}-${r.fieldKey}`),
995
- title: r.label || r.fieldKey
996
- })), P = d || b ? void 0 : {
997
- render: (e) => [{
998
- disabled: () => v.length <= y.minRows,
999
- icon: V,
1000
- iconType: "icon-only",
1001
- name: "刪除此列",
1002
- onClick: () => A(e.index),
1003
- variant: "destructive-ghost"
1004
- }],
1005
- fixed: "end",
1006
- width: 56
1007
- };
1008
- return /* @__PURE__ */ C("div", {
1009
- style: Ft,
1010
- children: [/* @__PURE__ */ S(h, {
1011
- ...P ? { actions: P } : {},
1012
- columns: N,
1013
- dataSource: [...M],
1014
- rowHeightPreset: "roomy",
1015
- showHeader: !0,
1016
- size: "sub"
1017
- }), d || b ? null : /* @__PURE__ */ S("div", {
1018
- style: It,
1019
- children: /* @__PURE__ */ S(c, {
1020
- disabled: v.length >= y.maxRows,
1021
- icon: B,
1022
- iconType: "leading",
1023
- onClick: k,
1024
- size: "sub",
1025
- type: "button",
1026
- variant: "base-secondary",
1027
- children: i.addRowLabel || "新增一列"
1028
- })
1029
- })]
1030
- });
1031
- }
1032
- function Vt({ column: e, dataSourceContext: t, error: n, fieldPath: i, formData: a, initialFormData: o, initialRowValues: s, onChange: l, onDataSourceStateChange: u, optionSnapshots: d, path: f, readonly: p, rowValues: m, schema: h, uiSchema: g }) {
1033
- let _ = Gt(m, e.fieldKey), y = Oe({
1034
- context: t,
1035
- field: e,
1036
- fieldPath: i,
1037
- formData: a,
1038
- initialFormData: o,
1039
- initialValue: s ? Gt(s, e.fieldKey) : void 0,
1040
- optionSnapshots: d,
1041
- readonly: p,
1042
- row: {
1043
- initialValues: s,
1044
- values: m
1045
- },
1046
- schema: h,
1047
- snapshotKey: f,
1048
- uiSchema: g
1049
- }), b = K(y), x = JSON.stringify({
1050
- hasValue: y.hasValue,
1051
- invalidValues: y.invalidValues,
1052
- selectionExpired: y.selectionExpired === !0,
1053
- status: y.status
1054
- });
1055
- return r(() => {
1056
- if (pe(e)) return u?.(f, {
1057
- hasValue: y.hasValue,
1058
- invalidValues: y.invalidValues,
1059
- selectionExpired: y.selectionExpired === !0,
1060
- status: y.status
1061
- }), () => {
1062
- u?.(f, {
1063
- hasValue: !1,
1064
- invalidValues: [],
1065
- status: "IDLE"
1066
- });
1067
- };
1068
- }, [
1069
- u,
1070
- f,
1071
- x
1072
- ]), /* @__PURE__ */ C("div", {
1073
- "data-form-field-key": f,
1074
- style: zt,
1075
- children: [
1076
- Kt(e, _, p, (e, t) => l(t), void 0, t, y, "sub"),
1077
- n ? /* @__PURE__ */ S(v, {
1078
- color: "text-error",
1079
- variant: "caption",
1080
- children: n
1081
- }) : null,
1082
- b ? /* @__PURE__ */ C("div", {
1083
- style: Pt,
1084
- children: [/* @__PURE__ */ S(v, {
1085
- color: y.status === "INVALID" || y.status === "UNAVAILABLE" ? "text-error" : "text-neutral",
1086
- variant: "caption",
1087
- children: b
1088
- }), y.status === "UNAVAILABLE" && y.canRetry ? /* @__PURE__ */ S(c, {
1089
- onClick: y.retry,
1090
- size: "sub",
1091
- type: "button",
1092
- variant: "base-ghost",
1093
- children: "重試"
1094
- }) : null]
1095
- }) : null
1096
- ]
1097
- });
1098
- }
1099
- function Ht(e, t) {
1100
- return ce(e)[t];
1101
- }
1102
- function Ut(e) {
1103
- return e.current += 1, `table-row-${e.current}`;
1104
- }
1105
- function Wt(e, t, n) {
1106
- return n === void 0 || !he(n) ? Object.fromEntries(Object.entries(e).filter(([e]) => e !== t)) : {
1107
- ...e,
1108
- [t]: n
1109
- };
1110
- }
1111
- function Gt(e, t) {
1112
- if (e && Object.prototype.hasOwnProperty.call(e, t)) return e[t];
1113
- }
1114
- function Kt(e, t, n, r, i, a, o, s = "main") {
1115
- return pe(e) ? Jt(e, t, n, r, a, o, s) : qt(e, t, n, r, i, s);
1116
- }
1117
- function qt(e, t, n, r, i, a = "main") {
1118
- let o = n && (e.type === "text" || e.type === "textarea") && e.displayAs === "link" ? qe(t) : null;
1119
- if (o) return /* @__PURE__ */ S(v, {
1120
- color: "text-brand",
1121
- component: "span",
1122
- variant: "body",
1123
- children: /* @__PURE__ */ S("a", {
1124
- href: o.href,
1125
- style: Nt,
1126
- ...o.external ? {
1127
- "aria-label": `${o.href}${jt}`,
1128
- rel: "noopener noreferrer",
1129
- target: "_blank",
1130
- title: Mt
1131
- } : {},
1132
- children: o.href
1133
- })
1134
- });
1135
- if (e.type === "textarea") return /* @__PURE__ */ S(g, {
1136
- onChange: (t) => r(e.fieldKey, t.target.value),
1137
- placeholder: e.placeholder ?? "請輸入多行文字",
1138
- readOnly: n,
1139
- ref: wt,
1140
- rows: 3,
1141
- style: Ct,
1142
- value: Xt(t)
1143
- });
1144
- if (e.type === "boolean") return /* @__PURE__ */ S(_, {
1145
- checked: t === !0,
1146
- disabled: n,
1147
- label: "啟用",
1148
- onChange: (t) => r(e.fieldKey, t.target.checked),
1149
- size: a
1150
- });
1151
- if (me(e) && e.type === "checkbox") {
1152
- let i = e.options.map(I);
1153
- return /* @__PURE__ */ S(m, {
1154
- menuMaxHeight: 320,
1155
- mode: "multiple",
1156
- onChange: (t) => r(e.fieldKey, t?.length ? t.map((e) => e.id) : void 0),
1157
- options: i,
1158
- placeholder: e.placeholder ?? "請選擇一或多個選項",
1159
- readOnly: n,
1160
- size: a,
1161
- value: i.filter((e) => q(t).includes(e.id))
1162
- });
1163
- }
1164
- if (me(e)) {
1165
- let i = e.options.map(I);
1166
- return /* @__PURE__ */ S(m, {
1167
- menuMaxHeight: 320,
1168
- onChange: (t) => r(e.fieldKey, t?.id ?? void 0),
1169
- options: i,
1170
- placeholder: e.placeholder ?? "請選擇",
1171
- readOnly: n,
1172
- size: a,
1173
- value: R(i, Xt(t))
1174
- });
1175
- }
1176
- return e.type === "member" ? /* @__PURE__ */ S(ot, {
1177
- multiple: e.multiple === !0,
1178
- name: e.fieldKey,
1179
- onChange: (t) => r(e.fieldKey, t),
1180
- placeholder: e.placeholder,
1181
- readonly: n,
1182
- size: a,
1183
- value: t
1184
- }) : e.type === "org_unit" ? /* @__PURE__ */ S(yt, {
1185
- name: e.fieldKey,
1186
- onChange: (t) => r(e.fieldKey, t),
1187
- placeholder: e.placeholder ?? Qt(e.type),
1188
- readonly: n,
1189
- size: a,
1190
- value: t
1191
- }) : e.type === "file_upload" ? /* @__PURE__ */ S(Ve, {
1192
- attachments: i?.attachments,
1193
- field: e,
1194
- onChange: (t) => r(e.fieldKey, t),
1195
- onDownloadAttachment: i?.onDownloadAttachment,
1196
- onStateChange: (t) => i?.onStateChange?.(e.fieldKey, t),
1197
- onUploadAttachment: i?.onUploadAttachment,
1198
- readonly: n,
1199
- value: t
1200
- }) : e.type === "date" ? /* @__PURE__ */ S(u, {
1201
- format: "YYYY-MM-DD",
1202
- fullWidth: !0,
1203
- onChange: (t) => r(e.fieldKey, k(t)),
1204
- placeholder: e.placeholder ?? Qt(e.type),
1205
- readOnly: n,
1206
- value: F(t)
1207
- }) : e.type === "datetime" ? /* @__PURE__ */ S(d, {
1208
- formatDate: "YYYY-MM-DD",
1209
- formatTime: "HH:mm",
1210
- fullWidth: !0,
1211
- hideSecond: !0,
1212
- onChange: (t) => r(e.fieldKey, A(t)),
1213
- placeholderLeft: "選擇日期",
1214
- placeholderRight: "選擇時間",
1215
- readOnly: n,
1216
- value: F(t)
1217
- }) : e.type === "number" || e.type === "money" ? /* @__PURE__ */ S(f, {
1218
- fullWidth: !0,
1219
- max: e.maximum,
1220
- min: e.minimum,
1221
- size: a,
1222
- onChange: (t) => r(e.fieldKey, D(P(t.target.value), {
1223
- max: e.maximum,
1224
- min: e.minimum
1225
- })),
1226
- placeholder: e.placeholder ?? Qt(e.type),
1227
- ...n ? { readonly: !0 } : {},
1228
- showSpinner: !0,
1229
- value: Zt(t),
1230
- variant: "measure"
1231
- }) : /* @__PURE__ */ S(f, {
1232
- fullWidth: !0,
1233
- onChange: (t) => r(e.fieldKey, t.target.value),
1234
- placeholder: e.placeholder ?? Qt(e.type),
1235
- ...n ? { readonly: !0 } : {},
1236
- size: a,
1237
- value: Xt(t),
1238
- variant: "base"
1239
- });
1240
- }
1241
- function Jt(e, t, n, r, i, a, o = "main") {
1242
- let c = a.options.map(I), u = de(t, a.options).map(I), d = a.status === "LOADING", f = d && !a.loadingNextPage, h = a.status === "WAITING_FOR_DEPENDENCIES", g = !!i && !n, _ = n || h, v = n;
1243
- return e.type === "autocomplete" ? U(e) === "multiple" ? /* @__PURE__ */ S(s, {
1244
- asyncData: g,
1245
- clearSearchText: !0,
1246
- disabled: v,
1247
- disabledOptionsFilter: g,
1248
- globalPortal: !0,
1249
- loading: f,
1250
- menuMaxHeight: 320,
1251
- mode: "multiple",
1252
- onChange: (t) => r(e.fieldKey, t.length ? t.map((e) => e.id) : void 0),
1253
- onReachBottom: a.onReachBottom,
1254
- onSearch: g ? a.onSearch : void 0,
1255
- onVisibilityChange: (e) => {
1256
- e && g && a.onOpen();
1257
- },
1258
- options: c,
1259
- placeholder: e.placeholder ?? "請輸入或選擇",
1260
- readOnly: n,
1261
- searchDebounceTime: 300,
1262
- size: o,
1263
- value: u
1264
- }) : /* @__PURE__ */ S(s, {
1265
- asyncData: g,
1266
- clearSearchText: !0,
1267
- disabled: v,
1268
- disabledOptionsFilter: g,
1269
- globalPortal: !0,
1270
- loading: f,
1271
- menuMaxHeight: 320,
1272
- mode: "single",
1273
- onChange: (t) => r(e.fieldKey, t?.id ?? void 0),
1274
- onReachBottom: a.onReachBottom,
1275
- onSearch: g ? a.onSearch : void 0,
1276
- onVisibilityChange: (e) => {
1277
- e && g && a.onOpen();
1278
- },
1279
- options: c,
1280
- placeholder: e.placeholder ?? "請輸入或選擇",
1281
- readOnly: n,
1282
- searchDebounceTime: 300,
1283
- size: o,
1284
- value: u[0] ?? null
1285
- }) : e.type === "radio" ? /* @__PURE__ */ S(p, {
1286
- disabled: _,
1287
- name: e.fieldKey,
1288
- onChange: (t) => r(e.fieldKey, t.target.value || void 0),
1289
- options: c,
1290
- value: Xt(t)
1291
- }) : e.type === "checkbox" ? /* @__PURE__ */ S(l, {
1292
- disabled: _,
1293
- name: e.fieldKey,
1294
- onChange: (t) => r(e.fieldKey, t.target.values.length ? t.target.values : void 0),
1295
- options: c.map((e) => ({
1296
- label: e.name,
1297
- value: e.id
1298
- })),
1299
- value: [...q(t)]
1300
- }) : U(e) === "multiple" ? /* @__PURE__ */ S(m, {
1301
- disabled: _,
1302
- loading: d,
1303
- menuMaxHeight: 320,
1304
- mode: "multiple",
1305
- onChange: (t) => r(e.fieldKey, t.length ? t.map((e) => e.id) : void 0),
1306
- onReachBottom: a.onReachBottom,
1307
- options: c,
1308
- placeholder: e.placeholder ?? "請選擇一或多個選項",
1309
- readOnly: n,
1310
- size: o,
1311
- value: u
1312
- }) : /* @__PURE__ */ S(m, {
1313
- disabled: _,
1314
- loading: d,
1315
- menuMaxHeight: 320,
1316
- onChange: (t) => r(e.fieldKey, t?.id ?? void 0),
1317
- onReachBottom: a.onReachBottom,
1318
- options: c,
1319
- placeholder: e.placeholder ?? "請選擇",
1320
- readOnly: n,
1321
- size: o,
1322
- value: u[0] ?? null
1323
- });
1324
- }
1325
- function Yt(e, t) {
1326
- return {
1327
- FULL: 12,
1328
- HALF: 6,
1329
- THIRD: 4
1330
- }[t.layout.find((t) => t.fieldKey === e.fieldKey)?.width ?? "FULL"];
1331
- }
1332
- function Xt(e) {
1333
- return typeof e == "string" ? e : "";
1334
- }
1335
- function Zt(e) {
1336
- return typeof e == "number" ? String(e) : "";
1337
- }
1338
- function Qt(e) {
1339
- return {
1340
- boolean: "",
1341
- autocomplete: "請輸入或選擇",
1342
- checkbox: "請選擇一或多個選項",
1343
- date: "請選擇日期",
1344
- datetime: "請選擇日期與時間",
1345
- file_upload: "請上傳附件",
1346
- member: "搜尋姓名或信箱",
1347
- money: "請輸入金額",
1348
- number: "請輸入數字",
1349
- org_unit: "搜尋組織名稱",
1350
- radio: "請選擇一個選項",
1351
- select: "請選擇一個選項",
1352
- table: "",
1353
- text: "請輸入文字",
1354
- textarea: "請輸入多行文字"
1355
- }[e];
1356
- }
1357
- export { J as a, K as c, Xe as i, je as l, lt as n, Y as o, Ze as r, Ae as s, Tt as t, Oe as u };
1358
-
1359
- //# sourceMappingURL=FormRendererView-CemHvfAT.js.map