@rytass/bpm-core-react 0.8.0 → 0.9.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 (154) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +18 -2
  3. package/dist/chunks/FormBuilderView-BPLwAJGv.cjs +3 -0
  4. package/dist/chunks/FormBuilderView-BPLwAJGv.cjs.map +1 -0
  5. package/dist/chunks/FormBuilderView-Do9-MIAe.js +1477 -0
  6. package/dist/chunks/FormBuilderView-Do9-MIAe.js.map +1 -0
  7. package/dist/chunks/FormRendererView-C5POZbWz.js +492 -0
  8. package/dist/chunks/FormRendererView-C5POZbWz.js.map +1 -0
  9. package/dist/chunks/FormRendererView-DNtNodNl.cjs +2 -0
  10. package/dist/chunks/FormRendererView-DNtNodNl.cjs.map +1 -0
  11. package/dist/chunks/{approval-instance-list-page-YZcGGDD8.js → approval-instance-list-page-BjX2kaoF.js} +56 -54
  12. package/dist/chunks/approval-instance-list-page-BjX2kaoF.js.map +1 -0
  13. package/dist/chunks/approval-instance-list-page-C408vxE2.cjs +2 -0
  14. package/dist/chunks/approval-instance-list-page-C408vxE2.cjs.map +1 -0
  15. package/dist/chunks/{categories-DBPoSrsi.js → categories-DGlxuC6X.js} +5 -5
  16. package/dist/chunks/{categories-DBPoSrsi.js.map → categories-DGlxuC6X.js.map} +1 -1
  17. package/dist/chunks/{categories-B6QZKZRt.cjs → categories-DUfldZ_9.cjs} +2 -2
  18. package/dist/chunks/{categories-B6QZKZRt.cjs.map → categories-DUfldZ_9.cjs.map} +1 -1
  19. package/dist/chunks/compose-CULMDsLS.cjs +2 -0
  20. package/dist/chunks/compose-CULMDsLS.cjs.map +1 -0
  21. package/dist/chunks/{compose-CQHDT7vh.js → compose-DJBlA5PD.js} +60 -58
  22. package/dist/chunks/compose-DJBlA5PD.js.map +1 -0
  23. package/dist/chunks/{delegations-DDEk-WI6.cjs → delegations-CGj-tZNO.cjs} +2 -2
  24. package/dist/chunks/{delegations-DDEk-WI6.cjs.map → delegations-CGj-tZNO.cjs.map} +1 -1
  25. package/dist/chunks/{delegations-iVnRi3QE.js → delegations-DLEEFBlH.js} +231 -231
  26. package/dist/chunks/{delegations-iVnRi3QE.js.map → delegations-DLEEFBlH.js.map} +1 -1
  27. package/dist/chunks/{delegations-ZNtodFaD.js → delegations-DqMpI_Nk.js} +168 -167
  28. package/dist/chunks/delegations-DqMpI_Nk.js.map +1 -0
  29. package/dist/chunks/delegations-kbMOSEif.cjs +2 -0
  30. package/dist/chunks/delegations-kbMOSEif.cjs.map +1 -0
  31. package/dist/chunks/{designer-CUbVXEtS.js → designer-BszXJ5RO.js} +1227 -990
  32. package/dist/chunks/designer-BszXJ5RO.js.map +1 -0
  33. package/dist/chunks/designer-CmqAU92b.cjs +65 -0
  34. package/dist/chunks/designer-CmqAU92b.cjs.map +1 -0
  35. package/dist/chunks/detail-CDexqBoU.cjs +2 -0
  36. package/dist/chunks/detail-CDexqBoU.cjs.map +1 -0
  37. package/dist/chunks/{detail-Cts5_gVp.js → detail-DAak2OXS.js} +704 -622
  38. package/dist/chunks/detail-DAak2OXS.js.map +1 -0
  39. package/dist/chunks/notifications--hwl-DR0.cjs +2 -0
  40. package/dist/chunks/{notifications-BKs4--96.cjs.map → notifications--hwl-DR0.cjs.map} +1 -1
  41. package/dist/chunks/{notifications-CSulztkU.js → notifications-DJ5wzCye.js} +7 -7
  42. package/dist/chunks/{notifications-CSulztkU.js.map → notifications-DJ5wzCye.js.map} +1 -1
  43. package/dist/chunks/{orgs-CrNxqlwp.js → orgs-DytLvZ_X.js} +243 -241
  44. package/dist/chunks/{orgs-CrNxqlwp.js.map → orgs-DytLvZ_X.js.map} +1 -1
  45. package/dist/chunks/orgs-Ni22buHs.cjs +2 -0
  46. package/dist/chunks/orgs-Ni22buHs.cjs.map +1 -0
  47. package/dist/chunks/providers-DEqcuXw9.js +506 -0
  48. package/dist/chunks/providers-DEqcuXw9.js.map +1 -0
  49. package/dist/chunks/providers-D_zTbkQH.cjs +2 -0
  50. package/dist/chunks/providers-D_zTbkQH.cjs.map +1 -0
  51. package/dist/chunks/{users-qghSMtLn.cjs → users-0HqlM_VQ.cjs} +2 -2
  52. package/dist/chunks/{users-qghSMtLn.cjs.map → users-0HqlM_VQ.cjs.map} +1 -1
  53. package/dist/chunks/{users-CUY139DF.js → users-FWrb3ehW.js} +5 -5
  54. package/dist/chunks/{users-CUY139DF.js.map → users-FWrb3ehW.js.map} +1 -1
  55. package/dist/components/notification-drawer.d.ts +4 -3
  56. package/dist/index.cjs +1 -1
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.js +21 -428
  59. package/dist/index.js.map +1 -1
  60. package/dist/next/index.cjs +1 -1
  61. package/dist/next/index.cjs.map +1 -1
  62. package/dist/next/index.js +16 -15
  63. package/dist/next/index.js.map +1 -1
  64. package/dist/pages/admin/delegations/index.cjs +1 -1
  65. package/dist/pages/admin/delegations/index.js +1 -1
  66. package/dist/pages/admin/orgs/index.cjs +1 -1
  67. package/dist/pages/admin/orgs/index.js +1 -1
  68. package/dist/pages/admin/users/index.cjs +1 -1
  69. package/dist/pages/admin/users/index.js +1 -1
  70. package/dist/pages/delegations/index.cjs +1 -1
  71. package/dist/pages/delegations/index.js +1 -1
  72. package/dist/pages/instances/detail/index.cjs +1 -1
  73. package/dist/pages/instances/detail/index.js +1 -1
  74. package/dist/pages/settings/notifications/index.cjs +1 -1
  75. package/dist/pages/settings/notifications/index.js +1 -1
  76. package/dist/pages/templates/categories/index.cjs +1 -1
  77. package/dist/pages/templates/categories/index.js +1 -1
  78. package/dist/pages/templates/compose/index.cjs +1 -1
  79. package/dist/pages/templates/compose/index.js +1 -1
  80. package/dist/pages/templates/designer/index.cjs +1 -1
  81. package/dist/pages/templates/designer/index.js +1 -1
  82. package/dist/views/admin/delegations/index.cjs +1 -1
  83. package/dist/views/admin/delegations/index.js +1 -1
  84. package/dist/views/admin/index.cjs +1 -1
  85. package/dist/views/admin/index.js +3 -3
  86. package/dist/views/admin/orgs/index.cjs +1 -1
  87. package/dist/views/admin/orgs/index.js +1 -1
  88. package/dist/views/admin/users/index.cjs +1 -1
  89. package/dist/views/admin/users/index.js +1 -1
  90. package/dist/views/cc/index.cjs +1 -1
  91. package/dist/views/cc/index.js +1 -1
  92. package/dist/views/delegations/index.cjs +1 -1
  93. package/dist/views/delegations/index.js +1 -1
  94. package/dist/views/forms/builder/index.cjs +1 -1
  95. package/dist/views/forms/builder/index.js +1 -1
  96. package/dist/views/forms/renderer/FormRendererView.d.ts +7 -2
  97. package/dist/views/forms/renderer/form-data-source-field.d.ts +34 -0
  98. package/dist/views/forms/renderer/index.cjs +1 -1
  99. package/dist/views/forms/renderer/index.d.ts +1 -0
  100. package/dist/views/forms/renderer/index.js +2 -2
  101. package/dist/views/instances/detail/index.cjs +1 -1
  102. package/dist/views/instances/detail/index.js +1 -1
  103. package/dist/views/instances/detail/sections/InstanceFormSection.d.ts +4 -1
  104. package/dist/views/instances/detail/sections/InstanceTasksSection.d.ts +5 -1
  105. package/dist/views/instances/new/index.cjs +1 -1
  106. package/dist/views/instances/new/index.cjs.map +1 -1
  107. package/dist/views/instances/new/index.js +105 -86
  108. package/dist/views/instances/new/index.js.map +1 -1
  109. package/dist/views/search/index.cjs +1 -1
  110. package/dist/views/search/index.js +1 -1
  111. package/dist/views/sent/index.cjs +1 -1
  112. package/dist/views/sent/index.js +1 -1
  113. package/dist/views/settings/index.cjs +1 -1
  114. package/dist/views/settings/index.js +1 -1
  115. package/dist/views/settings/notifications/index.cjs +1 -1
  116. package/dist/views/settings/notifications/index.js +1 -1
  117. package/dist/views/templates/categories/index.cjs +1 -1
  118. package/dist/views/templates/categories/index.js +1 -1
  119. package/dist/views/templates/compose/TemplateComposeWizardView.d.ts +3 -2
  120. package/dist/views/templates/compose/index.cjs +1 -1
  121. package/dist/views/templates/compose/index.js +1 -1
  122. package/dist/views/templates/designer/index.cjs +1 -1
  123. package/dist/views/templates/designer/index.js +1 -1
  124. package/dist/views/templates/index.cjs +1 -1
  125. package/dist/views/templates/index.cjs.map +1 -1
  126. package/dist/views/templates/index.js +153 -112
  127. package/dist/views/templates/index.js.map +1 -1
  128. package/package.json +41 -5
  129. package/dist/chunks/FormBuilderView-B_KGPjlp.cjs +0 -3
  130. package/dist/chunks/FormBuilderView-B_KGPjlp.cjs.map +0 -1
  131. package/dist/chunks/FormBuilderView-D8DrQOXD.js +0 -1090
  132. package/dist/chunks/FormBuilderView-D8DrQOXD.js.map +0 -1
  133. package/dist/chunks/FormRendererView-BwVsH2eX.cjs +0 -2
  134. package/dist/chunks/FormRendererView-BwVsH2eX.cjs.map +0 -1
  135. package/dist/chunks/FormRendererView-DrHsuSVo.js +0 -220
  136. package/dist/chunks/FormRendererView-DrHsuSVo.js.map +0 -1
  137. package/dist/chunks/approval-instance-list-page-BMUKxzcz.cjs +0 -2
  138. package/dist/chunks/approval-instance-list-page-BMUKxzcz.cjs.map +0 -1
  139. package/dist/chunks/approval-instance-list-page-YZcGGDD8.js.map +0 -1
  140. package/dist/chunks/compose-CQHDT7vh.js.map +0 -1
  141. package/dist/chunks/compose-Ds_cAefe.cjs +0 -2
  142. package/dist/chunks/compose-Ds_cAefe.cjs.map +0 -1
  143. package/dist/chunks/delegations-C2wLWsDQ.cjs +0 -2
  144. package/dist/chunks/delegations-C2wLWsDQ.cjs.map +0 -1
  145. package/dist/chunks/delegations-ZNtodFaD.js.map +0 -1
  146. package/dist/chunks/designer-CQ9hxSdD.cjs +0 -65
  147. package/dist/chunks/designer-CQ9hxSdD.cjs.map +0 -1
  148. package/dist/chunks/designer-CUbVXEtS.js.map +0 -1
  149. package/dist/chunks/detail-B-Q4W-iw.cjs +0 -2
  150. package/dist/chunks/detail-B-Q4W-iw.cjs.map +0 -1
  151. package/dist/chunks/detail-Cts5_gVp.js.map +0 -1
  152. package/dist/chunks/notifications-BKs4--96.cjs +0 -2
  153. package/dist/chunks/orgs-iNJ0QEcK.cjs +0 -2
  154. package/dist/chunks/orgs-iNJ0QEcK.cjs.map +0 -1
@@ -0,0 +1,492 @@
1
+ "use client";
2
+ import { t as e } from "./bpm-form-field-Cao0rMol.js";
3
+ import { useCallback as t, useEffect as n, useMemo as r, useRef as i, useState as a } from "react";
4
+ import { AutoComplete as o, Button as s, CheckboxGroup as c, DatePicker as l, DateTimePicker as u, Input as d, RadioGroup as f, Select as p, Textarea as m, Toggle as h, Typography as g, Upload as _ } from "@mezzanine-ui/react";
5
+ import { jsx as v, jsxs as y } from "react/jsx-runtime";
6
+ import { buildFormRendererValues as b, clampOptionalNumber as x, formatDatePickerValue as S, formatDateTimePickerValue as C, isFormRendererFieldReadonly as w, isFormRendererFieldRequired as T, mergeFormDataSourceOptions as E, parseOptionalNumberInput as D, previewFormFieldOptions as ee, readDatePickerValue as O, readFieldOptionAsSelectOption as k, readFormDataSourceErrorMessage as te, readFormDataSourceValueSignature as A, readFormFieldOptions as j, readMissingFormDataSourceDependencies as ne, readMissingFormDataSourceOptionValues as re, readSelectOption as M, readSelectedFormDataSourceOptions as N, readVisibleFormRendererFields as P } from "@rytass/bpm-core-client/form";
7
+ import { isFormDataSourceFieldDefinition as F, isFormStaticOptionFieldDefinition as I, readFormFieldSelectionMode as L } from "@rytass/bpm-core-shared/form";
8
+ //#region src/views/forms/renderer/form-data-source-field.ts
9
+ var R = {
10
+ error: null,
11
+ hasValue: !1,
12
+ hasNextPage: !1,
13
+ invalidValues: [],
14
+ onReachBottom: () => void 0,
15
+ onSearch: () => void 0,
16
+ options: [],
17
+ retry: () => void 0,
18
+ status: "IDLE"
19
+ };
20
+ function z(e) {
21
+ let o = F(e.field) ? e.field : null, s = o ? e.optionSnapshots?.[o.fieldKey] : void 0, c = JSON.stringify(s ?? null), l = r(() => s?.options ?? [], [c]), u = JSON.stringify(e.formData), d = JSON.stringify(e.initialFormData ?? {}), f = JSON.stringify(e.schema), p = JSON.stringify(e.uiSchema), m = e.context?.kind, h = e.context?.kind === "runtime" ? e.context.instanceId : void 0, g = e.context?.kind === "runtime" ? e.context.templateId : void 0, _ = o ? ne(o, e.formData) : [], v = JSON.stringify(_), y = o ? JSON.stringify({
22
+ bindings: o.dataSource.bindings.map((t) => t.from.kind === "FIELD" ? {
23
+ fieldKey: t.from.fieldKey,
24
+ value: e.formData[t.from.fieldKey]
25
+ } : { value: t.from.value }),
26
+ value: e.initialFormData !== void 0 || e.initialValue !== void 0 ? e.formData[o.fieldKey] : void 0
27
+ }) : "", b = r(() => {
28
+ if (m === "preview") return { kind: "preview" };
29
+ if (m === "runtime" && !e.readonly) return {
30
+ instanceId: h,
31
+ kind: "runtime",
32
+ templateId: g
33
+ };
34
+ }, [
35
+ h,
36
+ m,
37
+ g,
38
+ e.readonly
39
+ ]), x = o ? (e.initialFormData !== void 0 || e.initialValue !== void 0) && A(e.initialValue) !== A(e.formData[o.fieldKey]) : !1, S = o ? e.initialFormData !== void 0 && o.dataSource.bindings.some((t) => t.from.kind === "FIELD" ? A(e.initialFormData?.[t.from.fieldKey]) !== A(e.formData[t.from.fieldKey]) : !1) : !1, C = !!(s && (x || S)), [w, T] = a([]), [D, O] = a(""), [k, M] = a(null), [P, I] = a(o && s ? C ? "STALE" : "VALID" : "IDLE"), [L, z] = a(null), B = i(0), V = i({
40
+ cursor: null,
41
+ searchText: ""
42
+ }), H = r(() => Object.entries(e.formData).reduce((e, [t, n]) => n === void 0 ? e : {
43
+ ...e,
44
+ [t]: n
45
+ }, {}), [u]), U = r(() => E(l, w), [w, l]), W = r(() => re(o ? e.formData[o.fieldKey] : void 0, U), [
46
+ o,
47
+ e.formData,
48
+ U
49
+ ]), G = ie(o ? e.formData[o.fieldKey] : void 0), K = t((t, n) => {
50
+ if (!o || !b) return;
51
+ if (_.length > 0) {
52
+ I("WAITING_FOR_DEPENDENCIES"), z(null);
53
+ return;
54
+ }
55
+ let r = B.current + 1;
56
+ B.current = r, V.current = {
57
+ cursor: n,
58
+ searchText: t
59
+ }, I(C ? "STALE" : "LOADING"), z(null), (b.kind === "preview" ? ee({
60
+ cursor: n,
61
+ fieldKey: o.fieldKey,
62
+ formData: H,
63
+ schema: e.schema,
64
+ searchText: t,
65
+ uiSchema: e.uiSchema
66
+ }) : j({
67
+ cursor: n,
68
+ fieldKey: o.fieldKey,
69
+ formData: H,
70
+ instanceId: b.instanceId ?? null,
71
+ searchText: t,
72
+ templateId: b.templateId ?? null
73
+ })).then((t) => {
74
+ B.current === r && (T((r) => E(N(o ? e.formData[o.fieldKey] : void 0, r), n ? r : [], t.options)), M(t.nextCursor), I("VALID"), z(null));
75
+ }).catch((e) => {
76
+ B.current === r && (I("UNAVAILABLE"), z(te(e) ?? (e instanceof Error ? e.message : "選項來源暫時無法使用。")));
77
+ });
78
+ }, [
79
+ o,
80
+ b,
81
+ C,
82
+ _.length,
83
+ H,
84
+ f,
85
+ p
86
+ ]), q = i(K);
87
+ q.current = K, n(() => {
88
+ if (B.current += 1, T((t) => N(o ? e.formData[o.fieldKey] : void 0, t)), M((e) => e === null ? e : null), O((e) => e && ""), z((e) => e && null), !o) {
89
+ I("IDLE");
90
+ return;
91
+ }
92
+ if (_.length > 0) {
93
+ I("WAITING_FOR_DEPENDENCIES");
94
+ return;
95
+ }
96
+ if (!b) {
97
+ I(s ? C ? "STALE" : "VALID" : e.readonly ? "UNAVAILABLE" : "IDLE");
98
+ return;
99
+ }
100
+ if (o.type === "autocomplete") {
101
+ I(s ? C ? "STALE" : "VALID" : "IDLE");
102
+ return;
103
+ }
104
+ q.current("", null);
105
+ }, [
106
+ o,
107
+ b,
108
+ y,
109
+ d,
110
+ e.readonly,
111
+ C,
112
+ v,
113
+ c
114
+ ]);
115
+ let J = t((t) => {
116
+ O(t), T((t) => N(o ? e.formData[o.fieldKey] : void 0, t)), M(null), K(t, null);
117
+ }, [K]), Y = t(() => {
118
+ k && K(D, k);
119
+ }, [
120
+ K,
121
+ k,
122
+ D
123
+ ]), X = t(() => {
124
+ K(V.current.searchText, V.current.cursor);
125
+ }, [K]);
126
+ return o ? {
127
+ error: L,
128
+ hasValue: G,
129
+ hasNextPage: !!k,
130
+ invalidValues: W,
131
+ onReachBottom: Y,
132
+ onSearch: J,
133
+ options: U,
134
+ retry: X,
135
+ status: P === "VALID" && W.length ? "INVALID" : P
136
+ } : R;
137
+ }
138
+ function B(e) {
139
+ switch (e.status) {
140
+ case "WAITING_FOR_DEPENDENCIES": return "請先填寫相依欄位。";
141
+ case "STALE": return "選項需要重新載入或驗證。";
142
+ case "INVALID": return e.invalidValues.length ? `無法辨識選項:${e.invalidValues.join("、")}` : "目前選項已失效,請重新選擇。";
143
+ case "UNAVAILABLE": return e.error ?? "選項來源暫時無法使用。";
144
+ case "VALID": return e.options.length ? null : "目前沒有可用選項。";
145
+ default: return null;
146
+ }
147
+ }
148
+ function V(e) {
149
+ return e.hasValue && e.status !== "VALID";
150
+ }
151
+ function ie(e) {
152
+ return e == null ? !1 : typeof e == "string" ? e.trim().length > 0 : Array.isArray(e) ? e.length > 0 : !0;
153
+ }
154
+ //#endregion
155
+ //#region src/views/forms/renderer/FormRendererView.tsx
156
+ var H = {
157
+ alignItems: "start",
158
+ display: "grid",
159
+ gap: 12,
160
+ gridTemplateColumns: "repeat(12, minmax(0, 1fr))"
161
+ }, U = { gridColumn: "1 / -1" }, W = {
162
+ alignItems: "start",
163
+ display: "grid",
164
+ gap: 8,
165
+ minWidth: 0
166
+ }, G = {
167
+ minWidth: "100%",
168
+ width: "100%"
169
+ };
170
+ function K(e) {
171
+ e && (e.style.width = "100%");
172
+ }
173
+ function q({ dataSourceContext: e, dataSourceInitialValues: t, emptyText: o = "尚未建立欄位。", errors: s = {}, maxWidth: c, onChange: l, onDataSourceStateChange: u, onUploadAttachment: d, optionSnapshots: f, readonly: p = !1, schema: m, singleColumn: h = !1, uiSchema: _, value: y }) {
174
+ let [x, S] = a(() => b(m.fields, y ?? {})), C = r(() => b(m.fields, y ?? x), [
175
+ x,
176
+ m.fields,
177
+ y
178
+ ]), w = i(C), T = r(() => P(m, _, C), [
179
+ m,
180
+ _,
181
+ C
182
+ ]);
183
+ n(() => {
184
+ w.current = C;
185
+ }, [C]), n(() => {
186
+ S((e) => b(m.fields, y ?? e));
187
+ }, [m.fields, y]);
188
+ function E(e, t) {
189
+ let n = {
190
+ ...w.current,
191
+ [e]: t
192
+ };
193
+ w.current = n, y || S(n), l?.(n);
194
+ }
195
+ return T.length ? /* @__PURE__ */ v("div", {
196
+ style: {
197
+ ...H,
198
+ ...h ? {
199
+ maxWidth: c,
200
+ width: "100%"
201
+ } : {}
202
+ },
203
+ children: T.map((n) => /* @__PURE__ */ v(J, {
204
+ dataSourceContext: e,
205
+ dataSourceInitialValues: t,
206
+ field: n,
207
+ error: s[n.fieldKey] ?? null,
208
+ fields: m.fields,
209
+ onChange: E,
210
+ onDataSourceStateChange: u,
211
+ onUploadAttachment: d,
212
+ optionSnapshots: f,
213
+ readonly: p,
214
+ schema: m,
215
+ style: {
216
+ ...W,
217
+ gridColumn: `span ${h ? 12 : oe(n, _)}`
218
+ },
219
+ value: C[n.fieldKey],
220
+ values: C,
221
+ uiSchema: _
222
+ }, n.fieldKey))
223
+ }) : /* @__PURE__ */ v("div", {
224
+ style: H,
225
+ children: /* @__PURE__ */ v(g, {
226
+ color: "text-neutral",
227
+ style: U,
228
+ variant: "body",
229
+ children: m.fields.length > 0 ? "目前條件下沒有可填寫欄位。" : o
230
+ })
231
+ });
232
+ }
233
+ function J({ dataSourceContext: t, dataSourceInitialValues: r, error: i, field: a, fields: o, onChange: c, onDataSourceStateChange: l, onUploadAttachment: u, optionSnapshots: d, readonly: f, schema: p, style: m, value: h, values: _, uiSchema: b }) {
234
+ let x = T(a, o, _), S = f || w(a, o, _), C = z({
235
+ context: t,
236
+ field: a,
237
+ formData: _,
238
+ initialFormData: r,
239
+ initialValue: r?.[a.fieldKey],
240
+ optionSnapshots: d,
241
+ readonly: S,
242
+ schema: p,
243
+ uiSchema: b
244
+ }), E = B(C);
245
+ return n(() => {
246
+ F(a) && l?.(a.fieldKey, {
247
+ hasValue: C.hasValue,
248
+ invalidValues: C.invalidValues,
249
+ status: C.status
250
+ });
251
+ }, [
252
+ JSON.stringify({
253
+ hasValue: C.hasValue,
254
+ invalidValues: C.invalidValues,
255
+ status: C.status
256
+ }),
257
+ a.fieldKey,
258
+ l
259
+ ]), /* @__PURE__ */ y("div", {
260
+ "data-form-field-key": a.fieldKey,
261
+ style: m,
262
+ children: [
263
+ /* @__PURE__ */ v(e, {
264
+ label: a.label,
265
+ name: a.fieldKey,
266
+ required: x,
267
+ children: X(a, h, S, c, u, t, C)
268
+ }),
269
+ i ? /* @__PURE__ */ v(g, {
270
+ color: "text-error",
271
+ variant: "caption",
272
+ children: i
273
+ }) : null,
274
+ E ? /* @__PURE__ */ y("div", {
275
+ style: Y,
276
+ children: [/* @__PURE__ */ v(g, {
277
+ color: C.status === "INVALID" || C.status === "UNAVAILABLE" ? "text-error" : "text-neutral",
278
+ variant: "caption",
279
+ children: E
280
+ }), C.status === "UNAVAILABLE" ? /* @__PURE__ */ v(s, {
281
+ onClick: C.retry,
282
+ size: "sub",
283
+ type: "button",
284
+ variant: "base-ghost",
285
+ children: "重試"
286
+ }) : null]
287
+ }) : null
288
+ ]
289
+ });
290
+ }
291
+ var Y = {
292
+ alignItems: "center",
293
+ display: "flex",
294
+ gap: 8
295
+ };
296
+ function X(e, t, n, r, i, a, o) {
297
+ if (e.type === "textarea") return /* @__PURE__ */ v(m, {
298
+ onChange: (t) => r(e.fieldKey, t.target.value),
299
+ placeholder: e.placeholder ?? "請輸入多行文字",
300
+ readOnly: n,
301
+ ref: K,
302
+ rows: 3,
303
+ style: G,
304
+ value: Z(t)
305
+ });
306
+ if (e.type === "boolean") return /* @__PURE__ */ v(h, {
307
+ checked: t === !0,
308
+ disabled: n,
309
+ label: "啟用",
310
+ onChange: (t) => r(e.fieldKey, t.target.checked)
311
+ });
312
+ if (F(e)) return ae(e, t, n, r, a, o);
313
+ if (I(e) && e.type === "checkbox") {
314
+ let i = e.options.map(k);
315
+ return /* @__PURE__ */ v(p, {
316
+ mode: "multiple",
317
+ onChange: (t) => r(e.fieldKey, t?.length ? t.map((e) => e.id) : void 0),
318
+ options: i,
319
+ placeholder: e.placeholder ?? "請選擇一或多個選項",
320
+ readOnly: n,
321
+ value: i.filter((e) => Q(t).includes(e.id))
322
+ });
323
+ }
324
+ if (I(e)) {
325
+ let i = e.options.map(k);
326
+ return /* @__PURE__ */ v(p, {
327
+ onChange: (t) => r(e.fieldKey, t?.id ?? void 0),
328
+ options: i,
329
+ placeholder: e.placeholder ?? "請選擇",
330
+ readOnly: n,
331
+ value: M(i, Z(t))
332
+ });
333
+ }
334
+ return e.type === "file_upload" ? /* @__PURE__ */ v(_, {
335
+ accept: e.acceptedMimeTypes?.join(","),
336
+ disabled: n,
337
+ maxFiles: e.maxFiles,
338
+ mode: "button-list",
339
+ ...(e.maxFiles ?? 1) > 1 ? { multiple: !0 } : {},
340
+ onChange: (t) => r(e.fieldKey, t.length ? t.map((e) => e.id) : void 0),
341
+ onUpload: async (t) => Promise.all(t.map(async (t) => ({
342
+ file: t,
343
+ id: (i ? await i(e, t) : { id: `${t.name}-${t.lastModified}` }).id,
344
+ progress: 100,
345
+ status: "done"
346
+ }))),
347
+ size: "sub"
348
+ }) : e.type === "date" ? /* @__PURE__ */ v(l, {
349
+ format: "YYYY-MM-DD",
350
+ fullWidth: !0,
351
+ onChange: (t) => r(e.fieldKey, S(t)),
352
+ placeholder: e.placeholder ?? $(e.type),
353
+ readOnly: n,
354
+ value: O(t)
355
+ }) : e.type === "datetime" ? /* @__PURE__ */ v(u, {
356
+ formatDate: "YYYY-MM-DD",
357
+ formatTime: "HH:mm",
358
+ fullWidth: !0,
359
+ hideSecond: !0,
360
+ onChange: (t) => r(e.fieldKey, C(t)),
361
+ placeholderLeft: "選擇日期",
362
+ placeholderRight: "選擇時間",
363
+ readOnly: n,
364
+ value: O(t)
365
+ }) : e.type === "number" || e.type === "money" ? /* @__PURE__ */ v(d, {
366
+ fullWidth: !0,
367
+ max: e.maximum,
368
+ min: e.minimum,
369
+ onChange: (t) => r(e.fieldKey, x(D(t.target.value), {
370
+ max: e.maximum,
371
+ min: e.minimum
372
+ })),
373
+ placeholder: e.placeholder ?? $(e.type),
374
+ ...n ? { readonly: !0 } : {},
375
+ showSpinner: !0,
376
+ value: se(t),
377
+ variant: "measure"
378
+ }) : /* @__PURE__ */ v(d, {
379
+ fullWidth: !0,
380
+ onChange: (t) => r(e.fieldKey, t.target.value),
381
+ placeholder: e.placeholder ?? $(e.type),
382
+ ...n ? { readonly: !0 } : {},
383
+ value: Z(t),
384
+ variant: "base"
385
+ });
386
+ }
387
+ function ae(e, t, n, r, i, a) {
388
+ let s = a.options.map(k), l = N(t, a.options).map(k), u = a.status === "LOADING", d = a.status === "WAITING_FOR_DEPENDENCIES", m = !!i && !n, h = n || d;
389
+ return e.type === "autocomplete" ? L(e) === "multiple" ? /* @__PURE__ */ v(o, {
390
+ asyncData: m,
391
+ clearSearchText: !0,
392
+ disabled: h,
393
+ disabledOptionsFilter: m,
394
+ globalPortal: !0,
395
+ loading: u,
396
+ mode: "multiple",
397
+ onChange: (t) => r(e.fieldKey, t.length ? t.map((e) => e.id) : void 0),
398
+ onReachBottom: a.hasNextPage ? a.onReachBottom : void 0,
399
+ onSearch: m ? a.onSearch : void 0,
400
+ options: s,
401
+ placeholder: e.placeholder ?? "請輸入或選擇",
402
+ readOnly: n,
403
+ searchDebounceTime: 300,
404
+ value: l
405
+ }) : /* @__PURE__ */ v(o, {
406
+ asyncData: m,
407
+ clearSearchText: !0,
408
+ disabled: h,
409
+ disabledOptionsFilter: m,
410
+ globalPortal: !0,
411
+ loading: u,
412
+ mode: "single",
413
+ onChange: (t) => r(e.fieldKey, t?.id ?? void 0),
414
+ onReachBottom: a.hasNextPage ? a.onReachBottom : void 0,
415
+ onSearch: m ? a.onSearch : void 0,
416
+ options: s,
417
+ placeholder: e.placeholder ?? "請輸入或選擇",
418
+ readOnly: n,
419
+ searchDebounceTime: 300,
420
+ value: l[0] ?? null
421
+ }) : e.type === "radio" ? /* @__PURE__ */ v(f, {
422
+ disabled: h,
423
+ name: e.fieldKey,
424
+ onChange: (t) => r(e.fieldKey, t.target.value || void 0),
425
+ options: s,
426
+ value: Z(t)
427
+ }) : e.type === "checkbox" ? /* @__PURE__ */ v(c, {
428
+ disabled: h,
429
+ name: e.fieldKey,
430
+ onChange: (t) => r(e.fieldKey, t.target.values.length ? t.target.values : void 0),
431
+ options: s.map((e) => ({
432
+ label: e.name,
433
+ value: e.id
434
+ })),
435
+ value: [...Q(t)]
436
+ }) : L(e) === "multiple" ? /* @__PURE__ */ v(p, {
437
+ disabled: h,
438
+ loading: u,
439
+ mode: "multiple",
440
+ onChange: (t) => r(e.fieldKey, t.length ? t.map((e) => e.id) : void 0),
441
+ onReachBottom: a.hasNextPage ? a.onReachBottom : void 0,
442
+ options: s,
443
+ placeholder: e.placeholder ?? "請選擇一或多個選項",
444
+ readOnly: n,
445
+ value: l
446
+ }) : /* @__PURE__ */ v(p, {
447
+ disabled: h,
448
+ loading: u,
449
+ onChange: (t) => r(e.fieldKey, t?.id ?? void 0),
450
+ onReachBottom: a.hasNextPage ? a.onReachBottom : void 0,
451
+ options: s,
452
+ placeholder: e.placeholder ?? "請選擇",
453
+ readOnly: n,
454
+ value: l[0] ?? null
455
+ });
456
+ }
457
+ function oe(e, t) {
458
+ return {
459
+ FULL: 12,
460
+ HALF: 6,
461
+ THIRD: 4
462
+ }[t.layout.find((t) => t.fieldKey === e.fieldKey)?.width ?? "FULL"];
463
+ }
464
+ function Z(e) {
465
+ return typeof e == "string" ? e : "";
466
+ }
467
+ function Q(e) {
468
+ return Array.isArray(e) ? e : [];
469
+ }
470
+ function se(e) {
471
+ return typeof e == "number" ? String(e) : "";
472
+ }
473
+ function $(e) {
474
+ return {
475
+ boolean: "",
476
+ autocomplete: "請輸入或選擇",
477
+ checkbox: "請選擇一或多個選項",
478
+ date: "請選擇日期",
479
+ datetime: "請選擇日期與時間",
480
+ file_upload: "請上傳附件",
481
+ money: "請輸入金額",
482
+ number: "請輸入數字",
483
+ radio: "請選擇一個選項",
484
+ select: "請選擇一個選項",
485
+ text: "請輸入文字",
486
+ textarea: "請輸入多行文字"
487
+ }[e];
488
+ }
489
+ //#endregion
490
+ export { z as i, V as n, B as r, q as t };
491
+
492
+ //# sourceMappingURL=FormRendererView-C5POZbWz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormRendererView-C5POZbWz.js","names":[],"sources":["../../src/views/forms/renderer/form-data-source-field.ts","../../src/views/forms/renderer/FormRendererView.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n FormDataSourceValueSnapshots,\n FormDefinitionSchema,\n FormFieldDefinition,\n FormFieldOption,\n FormFieldValue,\n FormUiSchema,\n isFormDataSourceFieldDefinition,\n} from '@rytass/bpm-core-shared/form';\nimport {\n FormDataSourceFieldStatus,\n FormRendererValues,\n mergeFormDataSourceOptions,\n readFormDataSourceErrorMessage,\n readMissingFormDataSourceOptionValues,\n previewFormFieldOptions,\n readFormDataSourceValueSignature,\n readMissingFormDataSourceDependencies,\n readSelectedFormDataSourceOptions,\n readFormFieldOptions,\n} from '@rytass/bpm-core-client/form';\n\nexport type FormRendererDataSourceContext =\n | { readonly kind: 'preview' }\n | {\n readonly instanceId?: string | null;\n readonly kind: 'runtime';\n readonly templateId?: string | null;\n };\n\nexport interface FormDataSourceFieldState {\n readonly error: string | null;\n readonly hasValue: boolean;\n readonly hasNextPage: boolean;\n readonly invalidValues: readonly string[];\n readonly onReachBottom: () => void;\n readonly onSearch: (searchText: string) => void;\n readonly options: readonly FormFieldOption[];\n readonly retry: () => void;\n readonly status: FormDataSourceFieldStatus;\n}\n\nexport interface UseFormDataSourceFieldInput {\n readonly context?: FormRendererDataSourceContext;\n readonly field: FormFieldDefinition;\n readonly formData: FormRendererValues;\n readonly initialFormData?: FormRendererValues;\n readonly initialValue?: FormFieldValue | undefined;\n readonly optionSnapshots?: FormDataSourceValueSnapshots;\n readonly readonly: boolean;\n readonly schema: FormDefinitionSchema;\n readonly uiSchema: FormUiSchema;\n}\n\nconst EMPTY_FIELD_STATE: FormDataSourceFieldState = {\n error: null,\n hasValue: false,\n hasNextPage: false,\n invalidValues: [],\n onReachBottom: (): void => undefined,\n onSearch: (): void => undefined,\n options: [],\n retry: (): void => undefined,\n status: 'IDLE',\n};\n\nexport function useFormDataSourceField(\n input: UseFormDataSourceFieldInput,\n): FormDataSourceFieldState {\n const dynamicField = isFormDataSourceFieldDefinition(input.field)\n ? input.field\n : null;\n const snapshot = dynamicField\n ? input.optionSnapshots?.[dynamicField.fieldKey]\n : undefined;\n const snapshotSignature = JSON.stringify(snapshot ?? null);\n const snapshotOptions = useMemo(\n (): readonly FormFieldOption[] => snapshot?.options ?? [],\n [snapshotSignature],\n );\n const formDataSignature = JSON.stringify(input.formData);\n const initialFormDataSignature = JSON.stringify(input.initialFormData ?? {});\n const schemaSignature = JSON.stringify(input.schema);\n const uiSchemaSignature = JSON.stringify(input.uiSchema);\n const contextKind = input.context?.kind;\n const contextInstanceId =\n input.context?.kind === 'runtime' ? input.context.instanceId : undefined;\n const contextTemplateId =\n input.context?.kind === 'runtime' ? input.context.templateId : undefined;\n const missingDependencies = dynamicField\n ? readMissingFormDataSourceDependencies(dynamicField, input.formData)\n : [];\n const missingDependenciesSignature = JSON.stringify(missingDependencies);\n const dataSourceRefreshSignature = dynamicField\n ? JSON.stringify({\n bindings: dynamicField.dataSource.bindings.map((binding) =>\n binding.from.kind === 'FIELD'\n ? {\n fieldKey: binding.from.fieldKey,\n value: input.formData[binding.from.fieldKey],\n }\n : { value: binding.from.value },\n ),\n value:\n typeof input.initialFormData !== 'undefined' ||\n typeof input.initialValue !== 'undefined'\n ? input.formData[dynamicField.fieldKey]\n : undefined,\n })\n : '';\n const effectiveContext = useMemo(\n (): FormRendererDataSourceContext | undefined => {\n if (contextKind === 'preview') {\n return { kind: 'preview' };\n }\n\n if (contextKind === 'runtime' && !input.readonly) {\n return {\n instanceId: contextInstanceId,\n kind: 'runtime',\n templateId: contextTemplateId,\n };\n }\n\n return undefined;\n },\n [\n contextInstanceId,\n contextKind,\n contextTemplateId,\n input.readonly,\n ],\n );\n const valueChanged = dynamicField\n ? (typeof input.initialFormData !== 'undefined' ||\n typeof input.initialValue !== 'undefined') &&\n readFormDataSourceValueSignature(input.initialValue) !==\n readFormDataSourceValueSignature(input.formData[dynamicField.fieldKey])\n : false;\n const bindingsChanged = dynamicField\n ? typeof input.initialFormData !== 'undefined' &&\n dynamicField.dataSource.bindings.some((binding) => {\n if (binding.from.kind !== 'FIELD') {\n return false;\n }\n\n return (\n readFormDataSourceValueSignature(\n input.initialFormData?.[binding.from.fieldKey],\n ) !==\n readFormDataSourceValueSignature(input.formData[binding.from.fieldKey])\n );\n })\n : false;\n const isStale = Boolean(snapshot && (valueChanged || bindingsChanged));\n const [remoteOptions, setRemoteOptions] = useState<readonly FormFieldOption[]>(\n [],\n );\n const [searchText, setSearchText] = useState('');\n const [nextCursor, setNextCursor] = useState<string | null>(null);\n const [status, setStatus] = useState<FormDataSourceFieldStatus>(\n dynamicField ? (snapshot ? (isStale ? 'STALE' : 'VALID') : 'IDLE') : 'IDLE',\n );\n const [error, setError] = useState<string | null>(null);\n const requestSequence = useRef(0);\n const lastRequest = useRef<{ readonly cursor: string | null; readonly searchText: string }>({\n cursor: null,\n searchText: '',\n });\n\n const queryFormData = useMemo(\n (): Readonly<Record<string, FormFieldValue>> =>\n Object.entries(input.formData).reduce<\n Readonly<Record<string, FormFieldValue>>\n >((values, [key, value]) => {\n if (typeof value === 'undefined') {\n return values;\n }\n\n return { ...values, [key]: value };\n }, {}),\n [formDataSignature],\n );\n const mergedOptions = useMemo(\n (): readonly FormFieldOption[] =>\n mergeFormDataSourceOptions(snapshotOptions, remoteOptions),\n [remoteOptions, snapshotOptions],\n );\n const invalidValues = useMemo(\n (): readonly string[] =>\n readMissingFormDataSourceOptionValues(\n dynamicField ? input.formData[dynamicField.fieldKey] : undefined,\n mergedOptions,\n ),\n [dynamicField, input.formData, mergedOptions],\n );\n const hasValue = readFormDataSourceValuePresent(\n dynamicField ? input.formData[dynamicField.fieldKey] : undefined,\n );\n\n const loadOptions = useCallback(\n (nextSearchTextToLoad: string, cursor: string | null): void => {\n if (!dynamicField || !effectiveContext) {\n return;\n }\n\n if (missingDependencies.length > 0) {\n setStatus('WAITING_FOR_DEPENDENCIES');\n setError(null);\n\n return;\n }\n\n const requestId = requestSequence.current + 1;\n requestSequence.current = requestId;\n lastRequest.current = {\n cursor,\n searchText: nextSearchTextToLoad,\n };\n setStatus(isStale ? 'STALE' : 'LOADING');\n setError(null);\n\n const request =\n effectiveContext.kind === 'preview'\n ? previewFormFieldOptions({\n cursor,\n fieldKey: dynamicField.fieldKey,\n formData: queryFormData,\n schema: input.schema,\n searchText: nextSearchTextToLoad,\n uiSchema: input.uiSchema,\n })\n : readFormFieldOptions({\n cursor,\n fieldKey: dynamicField.fieldKey,\n formData: queryFormData,\n instanceId: effectiveContext.instanceId ?? null,\n searchText: nextSearchTextToLoad,\n templateId: effectiveContext.templateId ?? null,\n });\n\n void request\n .then((result): void => {\n if (requestSequence.current !== requestId) {\n return;\n }\n\n setRemoteOptions((currentOptions) => {\n const currentValue = dynamicField\n ? input.formData[dynamicField.fieldKey]\n : undefined;\n const selectedOptions = readSelectedFormDataSourceOptions(\n currentValue,\n currentOptions,\n );\n\n return mergeFormDataSourceOptions(\n selectedOptions,\n cursor ? currentOptions : [],\n result.options,\n );\n });\n setNextCursor(result.nextCursor);\n setStatus('VALID');\n setError(null);\n })\n .catch((requestError: unknown): void => {\n if (requestSequence.current !== requestId) {\n return;\n }\n\n setStatus('UNAVAILABLE');\n // The backend answers with stable codes rather than prose, so show\n // the mapped copy instead of a raw `FORM_DATA_SOURCE_*` string.\n setError(\n readFormDataSourceErrorMessage(requestError) ??\n (requestError instanceof Error\n ? requestError.message\n : '選項來源暫時無法使用。'),\n );\n });\n },\n [\n dynamicField,\n effectiveContext,\n isStale,\n missingDependencies.length,\n queryFormData,\n schemaSignature,\n uiSchemaSignature,\n ],\n );\n const loadOptionsRef = useRef(loadOptions);\n loadOptionsRef.current = loadOptions;\n\n useEffect((): void => {\n requestSequence.current += 1;\n setRemoteOptions((currentOptions) => {\n const currentValue = dynamicField\n ? input.formData[dynamicField.fieldKey]\n : undefined;\n\n return readSelectedFormDataSourceOptions(currentValue, currentOptions);\n });\n setNextCursor((currentCursor) =>\n currentCursor === null ? currentCursor : null,\n );\n setSearchText((currentSearchText) =>\n currentSearchText ? '' : currentSearchText,\n );\n setError((currentError) => (currentError ? null : currentError));\n\n if (!dynamicField) {\n setStatus('IDLE');\n\n return;\n }\n\n if (missingDependencies.length > 0) {\n setStatus('WAITING_FOR_DEPENDENCIES');\n\n return;\n }\n\n if (!effectiveContext) {\n setStatus(\n snapshot\n ? isStale\n ? 'STALE'\n : 'VALID'\n : input.readonly\n ? 'UNAVAILABLE'\n : 'IDLE',\n );\n\n return;\n }\n\n if (dynamicField.type === 'autocomplete') {\n setStatus(snapshot ? (isStale ? 'STALE' : 'VALID') : 'IDLE');\n\n return;\n }\n\n loadOptionsRef.current('', null);\n }, [\n dynamicField,\n effectiveContext,\n dataSourceRefreshSignature,\n initialFormDataSignature,\n input.readonly,\n isStale,\n missingDependenciesSignature,\n snapshotSignature,\n ]);\n\n const onSearch = useCallback(\n (nextSearchTextToLoad: string): void => {\n setSearchText(nextSearchTextToLoad);\n setRemoteOptions((currentOptions) => {\n const currentValue = dynamicField\n ? input.formData[dynamicField.fieldKey]\n : undefined;\n\n return readSelectedFormDataSourceOptions(currentValue, currentOptions);\n });\n setNextCursor(null);\n loadOptions(nextSearchTextToLoad, null);\n },\n [loadOptions],\n );\n const onReachBottom = useCallback((): void => {\n if (nextCursor) {\n loadOptions(searchText, nextCursor);\n }\n }, [loadOptions, nextCursor, searchText]);\n const retry = useCallback((): void => {\n loadOptions(lastRequest.current.searchText, lastRequest.current.cursor);\n }, [loadOptions]);\n\n if (!dynamicField) {\n return EMPTY_FIELD_STATE;\n }\n\n return {\n error,\n hasValue,\n hasNextPage: Boolean(nextCursor),\n invalidValues,\n onReachBottom,\n onSearch,\n options: mergedOptions,\n retry,\n status: status === 'VALID' && invalidValues.length ? 'INVALID' : status,\n };\n}\n\nexport function readFormDataSourceFieldStatusMessage(\n state: FormDataSourceFieldState,\n): string | null {\n switch (state.status) {\n case 'WAITING_FOR_DEPENDENCIES':\n return '請先填寫相依欄位。';\n case 'STALE':\n return '選項需要重新載入或驗證。';\n case 'INVALID':\n return state.invalidValues.length\n ? `無法辨識選項:${state.invalidValues.join('、')}`\n : '目前選項已失效,請重新選擇。';\n case 'UNAVAILABLE':\n return state.error ?? '選項來源暫時無法使用。';\n case 'VALID':\n return state.options.length ? null : '目前沒有可用選項。';\n default:\n return null;\n }\n}\n\nexport function isFormDataSourceFieldSubmissionBlocked(\n state: Pick<FormDataSourceFieldState, 'hasValue' | 'status'>,\n): boolean {\n return state.hasValue && state.status !== 'VALID';\n}\n\nfunction readFormDataSourceValuePresent(\n value: FormFieldValue | undefined,\n): boolean {\n if (typeof value === 'undefined' || value === null) {\n return false;\n }\n\n if (typeof value === 'string') {\n return value.trim().length > 0;\n }\n\n if (Array.isArray(value)) {\n return value.length > 0;\n }\n\n return true;\n}\n","'use client';\n\nimport {\n ChangeEvent,\n CSSProperties,\n ReactElement,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport {\n AutoComplete,\n Button,\n CheckboxGroup,\n DatePicker,\n DateTimePicker,\n Input,\n RadioGroup,\n Select,\n Textarea,\n Toggle,\n Typography,\n Upload,\n} from '@mezzanine-ui/react';\nimport type { UploadFile } from '@mezzanine-ui/react/Upload';\nimport {\n FormDataSourceOptionFieldDefinition,\n FormDataSourceValueSnapshots,\n FormDefinitionSchema,\n FormFieldDefinition,\n FormFieldValue,\n FormUiSchema,\n isFormDataSourceFieldDefinition,\n isFormStaticOptionFieldDefinition,\n readFormFieldSelectionMode,\n} from '@rytass/bpm-core-shared/form';\nimport {\n buildFormRendererValues,\n clampOptionalNumber,\n formatDatePickerValue,\n formatDateTimePickerValue,\n FormRendererValues,\n isFormRendererFieldReadonly,\n isFormRendererFieldRequired,\n parseOptionalNumberInput,\n readDatePickerValue,\n readFieldOptionAsSelectOption,\n readSelectedFormDataSourceOptions,\n readSelectOption,\n readVisibleFormRendererFields,\n} from '@rytass/bpm-core-client/form';\nimport { BPMFormField } from '../../../components/bpm-form-field';\nimport {\n FormDataSourceFieldState,\n FormRendererDataSourceContext,\n readFormDataSourceFieldStatusMessage,\n useFormDataSourceField,\n} from './form-data-source-field';\n\nexport interface FormRendererProps {\n readonly dataSourceContext?: FormRendererDataSourceContext;\n readonly dataSourceInitialValues?: FormRendererValues;\n readonly emptyText?: string;\n readonly errors?: Readonly<Record<string, string>>;\n readonly maxWidth?: CSSProperties['maxWidth'];\n readonly onChange?: (values: FormRendererValues) => void;\n readonly onDataSourceStateChange?: (\n fieldKey: string,\n state: Pick<\n FormDataSourceFieldState,\n 'hasValue' | 'invalidValues' | 'status'\n >,\n ) => void;\n readonly onUploadAttachment?: (\n field: FormFieldDefinition,\n file: File,\n ) => Promise<{ readonly id: string }>;\n readonly optionSnapshots?: FormDataSourceValueSnapshots;\n readonly readonly?: boolean;\n readonly schema: FormDefinitionSchema;\n readonly singleColumn?: boolean;\n readonly uiSchema: FormUiSchema;\n readonly value?: FormRendererValues;\n}\n\nconst FORM_RENDERER_GRID_STYLE: CSSProperties = {\n alignItems: 'start',\n display: 'grid',\n gap: 12,\n gridTemplateColumns: 'repeat(12, minmax(0, 1fr))',\n};\n\nconst FORM_RENDERER_EMPTY_STYLE: CSSProperties = {\n gridColumn: '1 / -1',\n};\n\nconst FORM_RENDERER_FIELD_STYLE: CSSProperties = {\n alignItems: 'start',\n display: 'grid',\n gap: 8,\n minWidth: 0,\n};\n\nconst TEXTAREA_STYLE: CSSProperties = {\n minWidth: '100%',\n width: '100%',\n};\n\nfunction applyFullWidthTextareaHost(element: HTMLDivElement | null): void {\n if (!element) {\n return;\n }\n\n element.style.width = '100%';\n}\n\nexport function FormRenderer({\n dataSourceContext,\n dataSourceInitialValues,\n emptyText = '尚未建立欄位。',\n errors = {},\n maxWidth,\n onChange,\n onDataSourceStateChange,\n onUploadAttachment,\n optionSnapshots,\n readonly = false,\n schema,\n singleColumn = false,\n uiSchema,\n value,\n}: FormRendererProps): ReactElement {\n const [internalValues, setInternalValues] = useState<FormRendererValues>(() =>\n buildFormRendererValues(schema.fields, value ?? {}),\n );\n const values = useMemo(\n (): FormRendererValues =>\n buildFormRendererValues(schema.fields, value ?? internalValues),\n [internalValues, schema.fields, value],\n );\n const valuesRef = useRef<FormRendererValues>(values);\n const visibleFields = useMemo(\n (): readonly FormFieldDefinition[] =>\n readVisibleFormRendererFields(schema, uiSchema, values),\n [schema, uiSchema, values],\n );\n\n useEffect((): void => {\n valuesRef.current = values;\n }, [values]);\n\n useEffect((): void => {\n setInternalValues((currentValues) =>\n buildFormRendererValues(schema.fields, value ?? currentValues),\n );\n }, [schema.fields, value]);\n\n function updateValue(\n fieldKey: string,\n nextValue: FormFieldValue | undefined,\n ): void {\n const nextValues = {\n ...valuesRef.current,\n [fieldKey]: nextValue,\n };\n valuesRef.current = nextValues;\n\n if (!value) {\n setInternalValues(nextValues);\n }\n\n onChange?.(nextValues);\n }\n\n if (!visibleFields.length) {\n return (\n <div style={FORM_RENDERER_GRID_STYLE}>\n <Typography\n color=\"text-neutral\"\n style={FORM_RENDERER_EMPTY_STYLE}\n variant=\"body\"\n >\n {schema.fields.length > 0 ? '目前條件下沒有可填寫欄位。' : emptyText}\n </Typography>\n </div>\n );\n }\n\n return (\n <div\n style={{\n ...FORM_RENDERER_GRID_STYLE,\n ...(singleColumn ? { maxWidth, width: '100%' } : {}),\n }}\n >\n {visibleFields.map((field) => (\n <FormRendererField\n dataSourceContext={dataSourceContext}\n dataSourceInitialValues={dataSourceInitialValues}\n field={field}\n error={errors[field.fieldKey] ?? null}\n fields={schema.fields}\n key={field.fieldKey}\n onChange={updateValue}\n onDataSourceStateChange={onDataSourceStateChange}\n onUploadAttachment={onUploadAttachment}\n optionSnapshots={optionSnapshots}\n readonly={readonly}\n schema={schema}\n style={{\n ...FORM_RENDERER_FIELD_STYLE,\n gridColumn: `span ${\n singleColumn ? 12 : readFieldColumnSpan(field, uiSchema)\n }`,\n }}\n value={values[field.fieldKey]}\n values={values}\n uiSchema={uiSchema}\n />\n ))}\n </div>\n );\n}\n\nfunction FormRendererField({\n dataSourceContext,\n dataSourceInitialValues,\n error,\n field,\n fields,\n onChange,\n onDataSourceStateChange,\n onUploadAttachment,\n optionSnapshots,\n readonly,\n schema,\n style,\n value,\n values,\n uiSchema,\n}: {\n readonly dataSourceContext?: FormRendererDataSourceContext;\n readonly dataSourceInitialValues?: FormRendererValues;\n readonly error: string | null;\n readonly field: FormFieldDefinition;\n readonly fields: readonly FormFieldDefinition[];\n readonly onChange: (\n fieldKey: string,\n value: FormFieldValue | undefined,\n ) => void;\n readonly onDataSourceStateChange?: (\n fieldKey: string,\n state: Pick<\n FormDataSourceFieldState,\n 'hasValue' | 'invalidValues' | 'status'\n >,\n ) => void;\n readonly onUploadAttachment?:\n | ((\n field: FormFieldDefinition,\n file: File,\n ) => Promise<{ readonly id: string }>)\n | undefined;\n readonly optionSnapshots?: FormDataSourceValueSnapshots;\n readonly readonly: boolean;\n readonly schema: FormDefinitionSchema;\n readonly style: CSSProperties;\n readonly uiSchema: FormUiSchema;\n readonly value: FormFieldValue | undefined;\n readonly values: FormRendererValues;\n}): ReactElement {\n const required = isFormRendererFieldRequired(field, fields, values);\n const fieldReadonly =\n readonly || isFormRendererFieldReadonly(field, fields, values);\n const dataSourceState = useFormDataSourceField({\n context: dataSourceContext,\n field,\n formData: values,\n initialFormData: dataSourceInitialValues,\n initialValue: dataSourceInitialValues?.[field.fieldKey],\n optionSnapshots,\n readonly: fieldReadonly,\n schema,\n uiSchema,\n });\n const dataSourceStatusMessage = readFormDataSourceFieldStatusMessage(\n dataSourceState,\n );\n const dataSourceStateSignature = JSON.stringify({\n hasValue: dataSourceState.hasValue,\n invalidValues: dataSourceState.invalidValues,\n status: dataSourceState.status,\n });\n\n useEffect((): void => {\n if (!isFormDataSourceFieldDefinition(field)) {\n return;\n }\n\n onDataSourceStateChange?.(field.fieldKey, {\n hasValue: dataSourceState.hasValue,\n invalidValues: dataSourceState.invalidValues,\n status: dataSourceState.status,\n });\n }, [\n dataSourceStateSignature,\n field.fieldKey,\n onDataSourceStateChange,\n ]);\n\n return (\n <div data-form-field-key={field.fieldKey} style={style}>\n <BPMFormField\n label={field.label}\n name={field.fieldKey}\n required={required}\n >\n {renderControl(\n field,\n value,\n fieldReadonly,\n onChange,\n onUploadAttachment,\n dataSourceContext,\n dataSourceState,\n )}\n </BPMFormField>\n {error ? (\n <Typography color=\"text-error\" variant=\"caption\">\n {error}\n </Typography>\n ) : null}\n {dataSourceStatusMessage ? (\n <div style={DATA_SOURCE_FEEDBACK_STYLE}>\n <Typography\n color={\n dataSourceState.status === 'INVALID' ||\n dataSourceState.status === 'UNAVAILABLE'\n ? 'text-error'\n : 'text-neutral'\n }\n variant=\"caption\"\n >\n {dataSourceStatusMessage}\n </Typography>\n {dataSourceState.status === 'UNAVAILABLE' ? (\n <Button\n onClick={dataSourceState.retry}\n size=\"sub\"\n type=\"button\"\n variant=\"base-ghost\"\n >\n 重試\n </Button>\n ) : null}\n </div>\n ) : null}\n </div>\n );\n}\n\nconst DATA_SOURCE_FEEDBACK_STYLE: CSSProperties = {\n alignItems: 'center',\n display: 'flex',\n gap: 8,\n};\n\nfunction renderControl(\n field: FormFieldDefinition,\n value: FormFieldValue | undefined,\n readonly: boolean,\n onChange: (fieldKey: string, value: FormFieldValue | undefined) => void,\n onUploadAttachment:\n | ((\n field: FormFieldDefinition,\n file: File,\n ) => Promise<{ readonly id: string }>)\n | undefined,\n dataSourceContext: FormRendererDataSourceContext | undefined,\n dataSourceState: FormDataSourceFieldState,\n): ReactElement {\n if (field.type === 'textarea') {\n return (\n <Textarea\n onChange={(event: ChangeEvent<HTMLTextAreaElement>): void =>\n onChange(field.fieldKey, event.target.value)\n }\n placeholder={field.placeholder ?? '請輸入多行文字'}\n readOnly={readonly}\n ref={applyFullWidthTextareaHost}\n rows={3}\n style={TEXTAREA_STYLE}\n value={readStringValue(value)}\n />\n );\n }\n\n if (field.type === 'boolean') {\n return (\n <Toggle\n checked={value === true}\n disabled={readonly}\n label=\"啟用\"\n onChange={(event: ChangeEvent<HTMLInputElement>): void =>\n onChange(field.fieldKey, event.target.checked)\n }\n />\n );\n }\n\n if (isFormDataSourceFieldDefinition(field)) {\n return renderDynamicOptionControl(\n field,\n value,\n readonly,\n onChange,\n dataSourceContext,\n dataSourceState,\n );\n }\n\n if (isFormStaticOptionFieldDefinition(field) && field.type === 'checkbox') {\n const options = field.options.map(readFieldOptionAsSelectOption);\n\n return (\n <Select\n mode=\"multiple\"\n onChange={(options): void =>\n onChange(\n field.fieldKey,\n options?.length\n ? options.map((option) => option.id)\n : undefined,\n )\n }\n options={options}\n placeholder={field.placeholder ?? '請選擇一或多個選項'}\n readOnly={readonly}\n value={options.filter((option) =>\n readStringArrayValue(value).includes(option.id),\n )}\n />\n );\n }\n\n if (isFormStaticOptionFieldDefinition(field)) {\n const options = field.options.map(readFieldOptionAsSelectOption);\n\n return (\n <Select\n onChange={(option): void =>\n onChange(field.fieldKey, option?.id ?? undefined)\n }\n options={options}\n placeholder={field.placeholder ?? '請選擇'}\n readOnly={readonly}\n value={readSelectOption(options, readStringValue(value))}\n />\n );\n }\n\n if (field.type === 'file_upload') {\n return (\n <Upload\n accept={field.acceptedMimeTypes?.join(',')}\n disabled={readonly}\n maxFiles={field.maxFiles}\n mode=\"button-list\"\n {...((field.maxFiles ?? 1) > 1 ? { multiple: true } : {})}\n onChange={(files): void =>\n onChange(\n field.fieldKey,\n files.length ? files.map((file) => file.id) : undefined,\n )\n }\n onUpload={async (files): Promise<UploadFile[]> =>\n Promise.all(\n files.map(async (file): Promise<UploadFile> => {\n const uploadedFile = onUploadAttachment\n ? await onUploadAttachment(field, file)\n : { id: `${file.name}-${file.lastModified}` };\n\n return {\n file,\n id: uploadedFile.id,\n progress: 100,\n status: 'done',\n };\n }),\n )\n }\n size=\"sub\"\n />\n );\n }\n\n if (field.type === 'date') {\n return (\n <DatePicker\n format=\"YYYY-MM-DD\"\n fullWidth\n onChange={(nextValue): void =>\n onChange(field.fieldKey, formatDatePickerValue(nextValue))\n }\n placeholder={field.placeholder ?? readInputPlaceholder(field.type)}\n readOnly={readonly}\n value={readDatePickerValue(value)}\n />\n );\n }\n\n if (field.type === 'datetime') {\n return (\n <DateTimePicker\n formatDate=\"YYYY-MM-DD\"\n formatTime=\"HH:mm\"\n fullWidth\n hideSecond\n onChange={(nextValue): void =>\n onChange(field.fieldKey, formatDateTimePickerValue(nextValue))\n }\n placeholderLeft=\"選擇日期\"\n placeholderRight=\"選擇時間\"\n readOnly={readonly}\n value={readDatePickerValue(value)}\n />\n );\n }\n\n if (field.type === 'number' || field.type === 'money') {\n return (\n <Input\n fullWidth\n max={field.maximum}\n min={field.minimum}\n onChange={(event: ChangeEvent<HTMLInputElement>): void =>\n onChange(\n field.fieldKey,\n clampOptionalNumber(parseOptionalNumberInput(event.target.value), {\n max: field.maximum,\n min: field.minimum,\n }),\n )\n }\n placeholder={field.placeholder ?? readInputPlaceholder(field.type)}\n {...(readonly ? { readonly: true as const } : {})}\n showSpinner\n value={readNumberInputValue(value)}\n variant=\"measure\"\n />\n );\n }\n\n return (\n <Input\n fullWidth\n onChange={(event: ChangeEvent<HTMLInputElement>): void =>\n onChange(field.fieldKey, event.target.value)\n }\n placeholder={field.placeholder ?? readInputPlaceholder(field.type)}\n {...(readonly ? { readonly: true as const } : {})}\n value={readStringValue(value)}\n variant=\"base\"\n />\n );\n}\n\nfunction renderDynamicOptionControl(\n field: FormDataSourceOptionFieldDefinition,\n value: FormFieldValue | undefined,\n readonly: boolean,\n onChange: (fieldKey: string, value: FormFieldValue | undefined) => void,\n dataSourceContext: FormRendererDataSourceContext | undefined,\n dataSourceState: FormDataSourceFieldState,\n): ReactElement {\n const options = dataSourceState.options.map(readFieldOptionAsSelectOption);\n const selectedOptions = readSelectedFormDataSourceOptions(\n value,\n dataSourceState.options,\n ).map(readFieldOptionAsSelectOption);\n const loading = dataSourceState.status === 'LOADING';\n const waitingForDependencies =\n dataSourceState.status === 'WAITING_FOR_DEPENDENCIES';\n const interactiveSearch = Boolean(dataSourceContext) && !readonly;\n const optionControlDisabled = readonly || waitingForDependencies;\n\n if (field.type === 'autocomplete') {\n if (readFormFieldSelectionMode(field) === 'multiple') {\n return (\n <AutoComplete\n asyncData={interactiveSearch}\n clearSearchText\n disabled={optionControlDisabled}\n disabledOptionsFilter={interactiveSearch}\n globalPortal\n loading={loading}\n mode=\"multiple\"\n onChange={(nextOptions): void =>\n onChange(\n field.fieldKey,\n nextOptions.length\n ? nextOptions.map((option) => option.id)\n : undefined,\n )\n }\n onReachBottom={\n dataSourceState.hasNextPage\n ? dataSourceState.onReachBottom\n : undefined\n }\n onSearch={interactiveSearch ? dataSourceState.onSearch : undefined}\n options={options}\n placeholder={field.placeholder ?? '請輸入或選擇'}\n readOnly={readonly}\n searchDebounceTime={300}\n value={selectedOptions}\n />\n );\n }\n\n return (\n <AutoComplete\n asyncData={interactiveSearch}\n clearSearchText\n disabled={optionControlDisabled}\n disabledOptionsFilter={interactiveSearch}\n globalPortal\n loading={loading}\n mode=\"single\"\n onChange={(nextOption): void =>\n onChange(field.fieldKey, nextOption?.id ?? undefined)\n }\n onReachBottom={\n dataSourceState.hasNextPage\n ? dataSourceState.onReachBottom\n : undefined\n }\n onSearch={interactiveSearch ? dataSourceState.onSearch : undefined}\n options={options}\n placeholder={field.placeholder ?? '請輸入或選擇'}\n readOnly={readonly}\n searchDebounceTime={300}\n value={selectedOptions[0] ?? null}\n />\n );\n }\n\n if (field.type === 'radio') {\n return (\n <RadioGroup\n disabled={optionControlDisabled}\n name={field.fieldKey}\n onChange={(event): void =>\n onChange(field.fieldKey, event.target.value || undefined)\n }\n options={options}\n value={readStringValue(value)}\n />\n );\n }\n\n if (field.type === 'checkbox') {\n return (\n <CheckboxGroup\n disabled={optionControlDisabled}\n name={field.fieldKey}\n onChange={(event): void =>\n onChange(\n field.fieldKey,\n event.target.values.length ? event.target.values : undefined,\n )\n }\n options={options.map((option) => ({\n label: option.name,\n value: option.id,\n }))}\n value={[...readStringArrayValue(value)]}\n />\n );\n }\n\n if (readFormFieldSelectionMode(field) === 'multiple') {\n return (\n <Select\n disabled={optionControlDisabled}\n loading={loading}\n mode=\"multiple\"\n onChange={(nextOptions): void =>\n onChange(\n field.fieldKey,\n nextOptions.length\n ? nextOptions.map((option) => option.id)\n : undefined,\n )\n }\n onReachBottom={\n dataSourceState.hasNextPage\n ? dataSourceState.onReachBottom\n : undefined\n }\n options={options}\n placeholder={field.placeholder ?? '請選擇一或多個選項'}\n readOnly={readonly}\n value={selectedOptions}\n />\n );\n }\n\n return (\n <Select\n disabled={optionControlDisabled}\n loading={loading}\n onChange={(nextOption): void =>\n onChange(field.fieldKey, nextOption?.id ?? undefined)\n }\n onReachBottom={\n dataSourceState.hasNextPage\n ? dataSourceState.onReachBottom\n : undefined\n }\n options={options}\n placeholder={field.placeholder ?? '請選擇'}\n readOnly={readonly}\n value={selectedOptions[0] ?? null}\n />\n );\n}\n\nfunction readFieldColumnSpan(\n field: FormFieldDefinition,\n uiSchema: FormUiSchema,\n): number {\n const width =\n uiSchema.layout.find((item) => item.fieldKey === field.fieldKey)?.width ??\n 'FULL';\n const spans: Readonly<Record<typeof width, number>> = {\n FULL: 12,\n HALF: 6,\n THIRD: 4,\n };\n\n return spans[width];\n}\n\nfunction readStringValue(value: FormFieldValue | undefined): string {\n return typeof value === 'string' ? value : '';\n}\n\nfunction readStringArrayValue(\n value: FormFieldValue | undefined,\n): readonly string[] {\n return Array.isArray(value) ? value : [];\n}\n\nfunction readNumberInputValue(value: FormFieldValue | undefined): string {\n return typeof value === 'number' ? String(value) : '';\n}\n\nfunction readInputPlaceholder(type: FormFieldDefinition['type']): string {\n const placeholders: Readonly<Record<FormFieldDefinition['type'], string>> = {\n boolean: '',\n autocomplete: '請輸入或選擇',\n checkbox: '請選擇一或多個選項',\n date: '請選擇日期',\n datetime: '請選擇日期與時間',\n file_upload: '請上傳附件',\n money: '請輸入金額',\n number: '請輸入數字',\n radio: '請選擇一個選項',\n select: '請選擇一個選項',\n text: '請輸入文字',\n textarea: '請輸入多行文字',\n };\n\n return placeholders[type];\n}\n\nexport { FormRenderer as FormRendererView };\n"],"mappings":";;;;;;;;AAyDA,IAAM,IAA8C;CAClD,OAAO;CACP,UAAU;CACV,aAAa;CACb,eAAe,CAAC;CAChB,qBAA2B,KAAA;CAC3B,gBAAsB,KAAA;CACtB,SAAS,CAAC;CACV,aAAmB,KAAA;CACnB,QAAQ;AACV;AAEA,SAAgB,EACd,GAC0B;CAC1B,IAAM,IAAe,EAAgC,EAAM,KAAK,IAC5D,EAAM,QACN,MACE,IAAW,IACb,EAAM,kBAAkB,EAAa,YACrC,KAAA,GACE,IAAoB,KAAK,UAAU,KAAY,IAAI,GACnD,IAAkB,QACY,GAAU,WAAW,CAAC,GACxD,CAAC,CAAiB,CACpB,GACM,IAAoB,KAAK,UAAU,EAAM,QAAQ,GACjD,IAA2B,KAAK,UAAU,EAAM,mBAAmB,CAAC,CAAC,GACrE,IAAkB,KAAK,UAAU,EAAM,MAAM,GAC7C,IAAoB,KAAK,UAAU,EAAM,QAAQ,GACjD,IAAc,EAAM,SAAS,MAC7B,IACJ,EAAM,SAAS,SAAS,YAAY,EAAM,QAAQ,aAAa,KAAA,GAC3D,IACJ,EAAM,SAAS,SAAS,YAAY,EAAM,QAAQ,aAAa,KAAA,GAC3D,IAAsB,IACxB,GAAsC,GAAc,EAAM,QAAQ,IAClE,CAAC,GACC,IAA+B,KAAK,UAAU,CAAmB,GACjE,IAA6B,IAC/B,KAAK,UAAU;EACb,UAAU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CAAK,MAAM,aAEtC,kBAAC,GAAD;EACE,UAAU;EACD;EACT,MAAK;EACL,WAAW,MACT,EACE,EAAM,UACN,EAAY,SACR,EAAY,KAAK,MAAW,EAAO,EAAE,IACrC,KAAA,CACN;EAEF,eACE,EAAgB,cACZ,EAAgB,gBAChB,KAAA;EAEG;EACT,aAAa,EAAM,eAAe;EAClC,UAAU;EACV,OAAO;CACR,CAAA,IAKH,kBAAC,GAAD;EACE,UAAU;EACD;EACT,WAAW,MACT,EAAS,EAAM,UAAU,GAAY,MAAM,KAAA,CAAS;EAEtD,eACE,EAAgB,cACZ,EAAgB,gBAChB,KAAA;EAEG;EACT,aAAa,EAAM,eAAe;EAClC,UAAU;EACV,OAAO,EAAgB,MAAM;CAC9B,CAAA;AAEL;AAEA,SAAS,GACP,GACA,GACQ;CAUR,OAAO;EALL,MAAM;EACN,MAAM;EACN,OAAO;CAGF,EARL,EAAS,OAAO,MAAM,MAAS,EAAK,aAAa,EAAM,QAAQ,GAAG,SAClE;AAQJ;AAEA,SAAS,EAAgB,GAA2C;CAClE,OAAO,OAAO,KAAU,WAAW,IAAQ;AAC7C;AAEA,SAAS,EACP,GACmB;CACnB,OAAO,MAAM,QAAQ,CAAK,IAAI,IAAQ,CAAC;AACzC;AAEA,SAAS,GAAqB,GAA2C;CACvE,OAAO,OAAO,KAAU,WAAW,OAAO,CAAK,IAAI;AACrD;AAEA,SAAS,EAAqB,GAA2C;CAgBvE,OAAO;EAdL,SAAS;EACT,cAAc;EACd,UAAU;EACV,MAAM;EACN,UAAU;EACV,aAAa;EACb,OAAO;EACP,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,MAAM;EACN,UAAU;CAGL,EAAa;AACtB"}
@@ -0,0 +1,2 @@
1
+ "use client";const e=require("./bpm-form-field-Bc6k4ZEO.cjs");let t=require("react"),n=require("@mezzanine-ui/react"),r=require("react/jsx-runtime"),i=require("@rytass/bpm-core-client/form"),a=require("@rytass/bpm-core-shared/form");var o={error:null,hasValue:!1,hasNextPage:!1,invalidValues:[],onReachBottom:()=>void 0,onSearch:()=>void 0,options:[],retry:()=>void 0,status:`IDLE`};function s(e){let n=(0,a.isFormDataSourceFieldDefinition)(e.field)?e.field:null,r=n?e.optionSnapshots?.[n.fieldKey]:void 0,s=JSON.stringify(r??null),c=(0,t.useMemo)(()=>r?.options??[],[s]),l=JSON.stringify(e.formData),d=JSON.stringify(e.initialFormData??{}),f=JSON.stringify(e.schema),p=JSON.stringify(e.uiSchema),m=e.context?.kind,h=e.context?.kind===`runtime`?e.context.instanceId:void 0,g=e.context?.kind===`runtime`?e.context.templateId:void 0,_=n?(0,i.readMissingFormDataSourceDependencies)(n,e.formData):[],v=JSON.stringify(_),y=n?JSON.stringify({bindings:n.dataSource.bindings.map(t=>t.from.kind===`FIELD`?{fieldKey:t.from.fieldKey,value:e.formData[t.from.fieldKey]}:{value:t.from.value}),value:e.initialFormData!==void 0||e.initialValue!==void 0?e.formData[n.fieldKey]:void 0}):``,b=(0,t.useMemo)(()=>{if(m===`preview`)return{kind:`preview`};if(m===`runtime`&&!e.readonly)return{instanceId:h,kind:`runtime`,templateId:g}},[h,m,g,e.readonly]),x=n?(e.initialFormData!==void 0||e.initialValue!==void 0)&&(0,i.readFormDataSourceValueSignature)(e.initialValue)!==(0,i.readFormDataSourceValueSignature)(e.formData[n.fieldKey]):!1,S=n?e.initialFormData!==void 0&&n.dataSource.bindings.some(t=>t.from.kind===`FIELD`?(0,i.readFormDataSourceValueSignature)(e.initialFormData?.[t.from.fieldKey])!==(0,i.readFormDataSourceValueSignature)(e.formData[t.from.fieldKey]):!1):!1,C=!!(r&&(x||S)),[w,T]=(0,t.useState)([]),[E,D]=(0,t.useState)(``),[O,k]=(0,t.useState)(null),[A,j]=(0,t.useState)(n&&r?C?`STALE`:`VALID`:`IDLE`),[M,N]=(0,t.useState)(null),P=(0,t.useRef)(0),F=(0,t.useRef)({cursor:null,searchText:``}),I=(0,t.useMemo)(()=>Object.entries(e.formData).reduce((e,[t,n])=>n===void 0?e:{...e,[t]:n},{}),[l]),L=(0,t.useMemo)(()=>(0,i.mergeFormDataSourceOptions)(c,w),[w,c]),R=(0,t.useMemo)(()=>(0,i.readMissingFormDataSourceOptionValues)(n?e.formData[n.fieldKey]:void 0,L),[n,e.formData,L]),z=u(n?e.formData[n.fieldKey]:void 0),B=(0,t.useCallback)((t,r)=>{if(!n||!b)return;if(_.length>0){j(`WAITING_FOR_DEPENDENCIES`),N(null);return}let a=P.current+1;P.current=a,F.current={cursor:r,searchText:t},j(C?`STALE`:`LOADING`),N(null),(b.kind===`preview`?(0,i.previewFormFieldOptions)({cursor:r,fieldKey:n.fieldKey,formData:I,schema:e.schema,searchText:t,uiSchema:e.uiSchema}):(0,i.readFormFieldOptions)({cursor:r,fieldKey:n.fieldKey,formData:I,instanceId:b.instanceId??null,searchText:t,templateId:b.templateId??null})).then(t=>{P.current===a&&(T(a=>(0,i.mergeFormDataSourceOptions)((0,i.readSelectedFormDataSourceOptions)(n?e.formData[n.fieldKey]:void 0,a),r?a:[],t.options)),k(t.nextCursor),j(`VALID`),N(null))}).catch(e=>{P.current===a&&(j(`UNAVAILABLE`),N((0,i.readFormDataSourceErrorMessage)(e)??(e instanceof Error?e.message:`選項來源暫時無法使用。`)))})},[n,b,C,_.length,I,f,p]),V=(0,t.useRef)(B);V.current=B,(0,t.useEffect)(()=>{if(P.current+=1,T(t=>(0,i.readSelectedFormDataSourceOptions)(n?e.formData[n.fieldKey]:void 0,t)),k(e=>e===null?e:null),D(e=>e&&``),N(e=>e&&null),!n){j(`IDLE`);return}if(_.length>0){j(`WAITING_FOR_DEPENDENCIES`);return}if(!b){j(r?C?`STALE`:`VALID`:e.readonly?`UNAVAILABLE`:`IDLE`);return}if(n.type===`autocomplete`){j(r?C?`STALE`:`VALID`:`IDLE`);return}V.current(``,null)},[n,b,y,d,e.readonly,C,v,s]);let H=(0,t.useCallback)(t=>{D(t),T(t=>(0,i.readSelectedFormDataSourceOptions)(n?e.formData[n.fieldKey]:void 0,t)),k(null),B(t,null)},[B]),U=(0,t.useCallback)(()=>{O&&B(E,O)},[B,O,E]),W=(0,t.useCallback)(()=>{B(F.current.searchText,F.current.cursor)},[B]);return n?{error:M,hasValue:z,hasNextPage:!!O,invalidValues:R,onReachBottom:U,onSearch:H,options:L,retry:W,status:A===`VALID`&&R.length?`INVALID`:A}:o}function c(e){switch(e.status){case`WAITING_FOR_DEPENDENCIES`:return`請先填寫相依欄位。`;case`STALE`:return`選項需要重新載入或驗證。`;case`INVALID`:return e.invalidValues.length?`無法辨識選項:${e.invalidValues.join(`、`)}`:`目前選項已失效,請重新選擇。`;case`UNAVAILABLE`:return e.error??`選項來源暫時無法使用。`;case`VALID`:return e.options.length?null:`目前沒有可用選項。`;default:return null}}function l(e){return e.hasValue&&e.status!==`VALID`}function u(e){return e==null?!1:typeof e==`string`?e.trim().length>0:Array.isArray(e)?e.length>0:!0}var d={alignItems:`start`,display:`grid`,gap:12,gridTemplateColumns:`repeat(12, minmax(0, 1fr))`},f={gridColumn:`1 / -1`},p={alignItems:`start`,display:`grid`,gap:8,minWidth:0},m={minWidth:`100%`,width:`100%`};function h(e){e&&(e.style.width=`100%`)}function g({dataSourceContext:e,dataSourceInitialValues:a,emptyText:o=`尚未建立欄位。`,errors:s={},maxWidth:c,onChange:l,onDataSourceStateChange:u,onUploadAttachment:m,optionSnapshots:h,readonly:g=!1,schema:v,singleColumn:y=!1,uiSchema:b,value:S}){let[C,w]=(0,t.useState)(()=>(0,i.buildFormRendererValues)(v.fields,S??{})),T=(0,t.useMemo)(()=>(0,i.buildFormRendererValues)(v.fields,S??C),[C,v.fields,S]),E=(0,t.useRef)(T),D=(0,t.useMemo)(()=>(0,i.readVisibleFormRendererFields)(v,b,T),[v,b,T]);(0,t.useEffect)(()=>{E.current=T},[T]),(0,t.useEffect)(()=>{w(e=>(0,i.buildFormRendererValues)(v.fields,S??e))},[v.fields,S]);function O(e,t){let n={...E.current,[e]:t};E.current=n,S||w(n),l?.(n)}return D.length?(0,r.jsx)(`div`,{style:{...d,...y?{maxWidth:c,width:`100%`}:{}},children:D.map(t=>(0,r.jsx)(_,{dataSourceContext:e,dataSourceInitialValues:a,field:t,error:s[t.fieldKey]??null,fields:v.fields,onChange:O,onDataSourceStateChange:u,onUploadAttachment:m,optionSnapshots:h,readonly:g,schema:v,style:{...p,gridColumn:`span ${y?12:x(t,b)}`},value:T[t.fieldKey],values:T,uiSchema:b},t.fieldKey))}):(0,r.jsx)(`div`,{style:d,children:(0,r.jsx)(n.Typography,{color:`text-neutral`,style:f,variant:`body`,children:v.fields.length>0?`目前條件下沒有可填寫欄位。`:o})})}function _({dataSourceContext:o,dataSourceInitialValues:l,error:u,field:d,fields:f,onChange:p,onDataSourceStateChange:m,onUploadAttachment:h,optionSnapshots:g,readonly:_,schema:b,style:x,value:S,values:C,uiSchema:w}){let T=(0,i.isFormRendererFieldRequired)(d,f,C),E=_||(0,i.isFormRendererFieldReadonly)(d,f,C),D=s({context:o,field:d,formData:C,initialFormData:l,initialValue:l?.[d.fieldKey],optionSnapshots:g,readonly:E,schema:b,uiSchema:w}),O=c(D);return(0,t.useEffect)(()=>{(0,a.isFormDataSourceFieldDefinition)(d)&&m?.(d.fieldKey,{hasValue:D.hasValue,invalidValues:D.invalidValues,status:D.status})},[JSON.stringify({hasValue:D.hasValue,invalidValues:D.invalidValues,status:D.status}),d.fieldKey,m]),(0,r.jsxs)(`div`,{"data-form-field-key":d.fieldKey,style:x,children:[(0,r.jsx)(e.t,{label:d.label,name:d.fieldKey,required:T,children:y(d,S,E,p,h,o,D)}),u?(0,r.jsx)(n.Typography,{color:`text-error`,variant:`caption`,children:u}):null,O?(0,r.jsxs)(`div`,{style:v,children:[(0,r.jsx)(n.Typography,{color:D.status===`INVALID`||D.status===`UNAVAILABLE`?`text-error`:`text-neutral`,variant:`caption`,children:O}),D.status===`UNAVAILABLE`?(0,r.jsx)(n.Button,{onClick:D.retry,size:`sub`,type:`button`,variant:`base-ghost`,children:`重試`}):null]}):null]})}var v={alignItems:`center`,display:`flex`,gap:8};function y(e,t,o,s,c,l,u){if(e.type===`textarea`)return(0,r.jsx)(n.Textarea,{onChange:t=>s(e.fieldKey,t.target.value),placeholder:e.placeholder??`請輸入多行文字`,readOnly:o,ref:h,rows:3,style:m,value:S(t)});if(e.type===`boolean`)return(0,r.jsx)(n.Toggle,{checked:t===!0,disabled:o,label:`啟用`,onChange:t=>s(e.fieldKey,t.target.checked)});if((0,a.isFormDataSourceFieldDefinition)(e))return b(e,t,o,s,l,u);if((0,a.isFormStaticOptionFieldDefinition)(e)&&e.type===`checkbox`){let a=e.options.map(i.readFieldOptionAsSelectOption);return(0,r.jsx)(n.Select,{mode:`multiple`,onChange:t=>s(e.fieldKey,t?.length?t.map(e=>e.id):void 0),options:a,placeholder:e.placeholder??`請選擇一或多個選項`,readOnly:o,value:a.filter(e=>C(t).includes(e.id))})}if((0,a.isFormStaticOptionFieldDefinition)(e)){let a=e.options.map(i.readFieldOptionAsSelectOption);return(0,r.jsx)(n.Select,{onChange:t=>s(e.fieldKey,t?.id??void 0),options:a,placeholder:e.placeholder??`請選擇`,readOnly:o,value:(0,i.readSelectOption)(a,S(t))})}return e.type===`file_upload`?(0,r.jsx)(n.Upload,{accept:e.acceptedMimeTypes?.join(`,`),disabled:o,maxFiles:e.maxFiles,mode:`button-list`,...(e.maxFiles??1)>1?{multiple:!0}:{},onChange:t=>s(e.fieldKey,t.length?t.map(e=>e.id):void 0),onUpload:async t=>Promise.all(t.map(async t=>({file:t,id:(c?await c(e,t):{id:`${t.name}-${t.lastModified}`}).id,progress:100,status:`done`}))),size:`sub`}):e.type===`date`?(0,r.jsx)(n.DatePicker,{format:`YYYY-MM-DD`,fullWidth:!0,onChange:t=>s(e.fieldKey,(0,i.formatDatePickerValue)(t)),placeholder:e.placeholder??T(e.type),readOnly:o,value:(0,i.readDatePickerValue)(t)}):e.type===`datetime`?(0,r.jsx)(n.DateTimePicker,{formatDate:`YYYY-MM-DD`,formatTime:`HH:mm`,fullWidth:!0,hideSecond:!0,onChange:t=>s(e.fieldKey,(0,i.formatDateTimePickerValue)(t)),placeholderLeft:`選擇日期`,placeholderRight:`選擇時間`,readOnly:o,value:(0,i.readDatePickerValue)(t)}):e.type===`number`||e.type===`money`?(0,r.jsx)(n.Input,{fullWidth:!0,max:e.maximum,min:e.minimum,onChange:t=>s(e.fieldKey,(0,i.clampOptionalNumber)((0,i.parseOptionalNumberInput)(t.target.value),{max:e.maximum,min:e.minimum})),placeholder:e.placeholder??T(e.type),...o?{readonly:!0}:{},showSpinner:!0,value:w(t),variant:`measure`}):(0,r.jsx)(n.Input,{fullWidth:!0,onChange:t=>s(e.fieldKey,t.target.value),placeholder:e.placeholder??T(e.type),...o?{readonly:!0}:{},value:S(t),variant:`base`})}function b(e,t,o,s,c,l){let u=l.options.map(i.readFieldOptionAsSelectOption),d=(0,i.readSelectedFormDataSourceOptions)(t,l.options).map(i.readFieldOptionAsSelectOption),f=l.status===`LOADING`,p=l.status===`WAITING_FOR_DEPENDENCIES`,m=!!c&&!o,h=o||p;return e.type===`autocomplete`?(0,a.readFormFieldSelectionMode)(e)===`multiple`?(0,r.jsx)(n.AutoComplete,{asyncData:m,clearSearchText:!0,disabled:h,disabledOptionsFilter:m,globalPortal:!0,loading:f,mode:`multiple`,onChange:t=>s(e.fieldKey,t.length?t.map(e=>e.id):void 0),onReachBottom:l.hasNextPage?l.onReachBottom:void 0,onSearch:m?l.onSearch:void 0,options:u,placeholder:e.placeholder??`請輸入或選擇`,readOnly:o,searchDebounceTime:300,value:d}):(0,r.jsx)(n.AutoComplete,{asyncData:m,clearSearchText:!0,disabled:h,disabledOptionsFilter:m,globalPortal:!0,loading:f,mode:`single`,onChange:t=>s(e.fieldKey,t?.id??void 0),onReachBottom:l.hasNextPage?l.onReachBottom:void 0,onSearch:m?l.onSearch:void 0,options:u,placeholder:e.placeholder??`請輸入或選擇`,readOnly:o,searchDebounceTime:300,value:d[0]??null}):e.type===`radio`?(0,r.jsx)(n.RadioGroup,{disabled:h,name:e.fieldKey,onChange:t=>s(e.fieldKey,t.target.value||void 0),options:u,value:S(t)}):e.type===`checkbox`?(0,r.jsx)(n.CheckboxGroup,{disabled:h,name:e.fieldKey,onChange:t=>s(e.fieldKey,t.target.values.length?t.target.values:void 0),options:u.map(e=>({label:e.name,value:e.id})),value:[...C(t)]}):(0,a.readFormFieldSelectionMode)(e)===`multiple`?(0,r.jsx)(n.Select,{disabled:h,loading:f,mode:`multiple`,onChange:t=>s(e.fieldKey,t.length?t.map(e=>e.id):void 0),onReachBottom:l.hasNextPage?l.onReachBottom:void 0,options:u,placeholder:e.placeholder??`請選擇一或多個選項`,readOnly:o,value:d}):(0,r.jsx)(n.Select,{disabled:h,loading:f,onChange:t=>s(e.fieldKey,t?.id??void 0),onReachBottom:l.hasNextPage?l.onReachBottom:void 0,options:u,placeholder:e.placeholder??`請選擇`,readOnly:o,value:d[0]??null})}function x(e,t){return{FULL:12,HALF:6,THIRD:4}[t.layout.find(t=>t.fieldKey===e.fieldKey)?.width??`FULL`]}function S(e){return typeof e==`string`?e:``}function C(e){return Array.isArray(e)?e:[]}function w(e){return typeof e==`number`?String(e):``}function T(e){return{boolean:``,autocomplete:`請輸入或選擇`,checkbox:`請選擇一或多個選項`,date:`請選擇日期`,datetime:`請選擇日期與時間`,file_upload:`請上傳附件`,money:`請輸入金額`,number:`請輸入數字`,radio:`請選擇一個選項`,select:`請選擇一個選項`,text:`請輸入文字`,textarea:`請輸入多行文字`}[e]}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return g}});
2
+ //# sourceMappingURL=FormRendererView-DNtNodNl.cjs.map