@rytass/bpm-core-react 0.22.0 → 0.23.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 (87) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/chunks/{FormBuilderView-DbfbLZCI.js → FormBuilderView-D_bN9gzT.js} +675 -614
  3. package/dist/chunks/FormBuilderView-D_bN9gzT.js.map +1 -0
  4. package/dist/chunks/FormBuilderView-bm8P55hp.cjs +4 -0
  5. package/dist/chunks/FormBuilderView-bm8P55hp.cjs.map +1 -0
  6. package/dist/chunks/FormRendererView-BlQgJOkI.cjs +6 -0
  7. package/dist/chunks/FormRendererView-BlQgJOkI.cjs.map +1 -0
  8. package/dist/chunks/{FormRendererView-CAyPXhPq.js → FormRendererView-CemHvfAT.js} +298 -290
  9. package/dist/chunks/FormRendererView-CemHvfAT.js.map +1 -0
  10. package/dist/chunks/compose-CdKVQfjB.cjs +2 -0
  11. package/dist/chunks/compose-CdKVQfjB.cjs.map +1 -0
  12. package/dist/chunks/{compose-U1zs3Yof.js → compose-N9657E5u.js} +161 -147
  13. package/dist/chunks/compose-N9657E5u.js.map +1 -0
  14. package/dist/chunks/{designer-DPG7R_WP.js → designer-CKwG_vM5.js} +1913 -1715
  15. package/dist/chunks/designer-CKwG_vM5.js.map +1 -0
  16. package/dist/chunks/designer-JPs7EijM.cjs +69 -0
  17. package/dist/chunks/designer-JPs7EijM.cjs.map +1 -0
  18. package/dist/chunks/detail-Dqu0K9QM.cjs +5 -0
  19. package/dist/chunks/detail-Dqu0K9QM.cjs.map +1 -0
  20. package/dist/chunks/{detail-CHZDNNM6.js → detail-fW0vJudE.js} +902 -895
  21. package/dist/chunks/detail-fW0vJudE.js.map +1 -0
  22. package/dist/chunks/instance-error-message-BKt07-Bo.js +270 -0
  23. package/dist/chunks/instance-error-message-BKt07-Bo.js.map +1 -0
  24. package/dist/chunks/instance-error-message-BL_X7Af8.cjs +2 -0
  25. package/dist/chunks/instance-error-message-BL_X7Af8.cjs.map +1 -0
  26. package/dist/pages/instances/detail/index.cjs +1 -1
  27. package/dist/pages/instances/detail/index.js +1 -1
  28. package/dist/pages/templates/compose/index.cjs +1 -1
  29. package/dist/pages/templates/compose/index.js +1 -1
  30. package/dist/pages/templates/designer/index.cjs +1 -1
  31. package/dist/pages/templates/designer/index.js +1 -1
  32. package/dist/views/forms/builder/index.cjs +1 -1
  33. package/dist/views/forms/builder/index.js +1 -1
  34. package/dist/views/forms/renderer/FormRendererView.d.cts +26 -1
  35. package/dist/views/forms/renderer/FormRendererView.d.ts +26 -1
  36. package/dist/views/forms/renderer/index.cjs +1 -1
  37. package/dist/views/forms/renderer/index.js +1 -1
  38. package/dist/views/instances/approver-filled-form.d.cts +56 -20
  39. package/dist/views/instances/approver-filled-form.d.ts +56 -20
  40. package/dist/views/instances/detail/index.cjs +1 -1
  41. package/dist/views/instances/detail/index.js +1 -1
  42. package/dist/views/instances/detail/sections/InstanceFormSection.d.cts +7 -0
  43. package/dist/views/instances/detail/sections/InstanceFormSection.d.ts +7 -0
  44. package/dist/views/instances/detail/sections/InstanceTasksSection.d.cts +1 -1
  45. package/dist/views/instances/detail/sections/InstanceTasksSection.d.ts +1 -1
  46. package/dist/views/instances/new/index.cjs +1 -1
  47. package/dist/views/instances/new/index.js +2 -2
  48. package/dist/views/templates/compose/index.cjs +1 -1
  49. package/dist/views/templates/compose/index.js +1 -1
  50. package/dist/views/templates/compose/steps/ComposeReviewStep.d.cts +3 -1
  51. package/dist/views/templates/compose/steps/ComposeReviewStep.d.ts +3 -1
  52. package/dist/views/templates/compose/steps/ComposeWorkflowStep.d.cts +4 -1
  53. package/dist/views/templates/compose/steps/ComposeWorkflowStep.d.ts +4 -1
  54. package/dist/views/templates/compose/use-template-compose-wizard.d.cts +3 -1
  55. package/dist/views/templates/compose/use-template-compose-wizard.d.ts +3 -1
  56. package/dist/views/templates/designer/TemplateDesignerView.d.cts +10 -1
  57. package/dist/views/templates/designer/TemplateDesignerView.d.ts +10 -1
  58. package/dist/views/templates/designer/field-access-matrix/FieldAccessMatrixDrawer.d.cts +3 -1
  59. package/dist/views/templates/designer/field-access-matrix/FieldAccessMatrixDrawer.d.ts +3 -1
  60. package/dist/views/templates/designer/field-access-matrix/field-access-copy.d.cts +3 -2
  61. package/dist/views/templates/designer/field-access-matrix/field-access-copy.d.ts +3 -2
  62. package/dist/views/templates/designer/index.cjs +1 -1
  63. package/dist/views/templates/designer/index.js +1 -1
  64. package/dist/views/templates/designer/launch-mode.d.cts +19 -0
  65. package/dist/views/templates/designer/launch-mode.d.ts +19 -0
  66. package/dist/views/templates/designer/publish-default-value-check.d.cts +36 -0
  67. package/dist/views/templates/designer/publish-default-value-check.d.ts +36 -0
  68. package/package.json +3 -3
  69. package/dist/chunks/FormBuilderView-Bok4Y59D.cjs +0 -4
  70. package/dist/chunks/FormBuilderView-Bok4Y59D.cjs.map +0 -1
  71. package/dist/chunks/FormBuilderView-DbfbLZCI.js.map +0 -1
  72. package/dist/chunks/FormRendererView-CAyPXhPq.js.map +0 -1
  73. package/dist/chunks/FormRendererView-iLlHFIUR.cjs +0 -6
  74. package/dist/chunks/FormRendererView-iLlHFIUR.cjs.map +0 -1
  75. package/dist/chunks/compose-DP1N4twA.cjs +0 -2
  76. package/dist/chunks/compose-DP1N4twA.cjs.map +0 -1
  77. package/dist/chunks/compose-U1zs3Yof.js.map +0 -1
  78. package/dist/chunks/designer-CWL-dCQ_.cjs +0 -69
  79. package/dist/chunks/designer-CWL-dCQ_.cjs.map +0 -1
  80. package/dist/chunks/designer-DPG7R_WP.js.map +0 -1
  81. package/dist/chunks/detail-BUfsSal0.cjs +0 -5
  82. package/dist/chunks/detail-BUfsSal0.cjs.map +0 -1
  83. package/dist/chunks/detail-CHZDNNM6.js.map +0 -1
  84. package/dist/chunks/instance-error-message-BEM4O_Kj.js +0 -208
  85. package/dist/chunks/instance-error-message-BEM4O_Kj.js.map +0 -1
  86. package/dist/chunks/instance-error-message-BpCLCOjp.cjs +0 -2
  87. package/dist/chunks/instance-error-message-BpCLCOjp.cjs.map +0 -1
@@ -1,208 +0,0 @@
1
- import { isFormDataValueEmpty as e, omitFormDataKeys as t, readApproverFilledFieldKeys as n, readNodeFillableFieldKeys as r, readNodeRequiredFieldKeys as i } from "@rytass/bpm-core-shared";
2
- import { readFormDataSourceErrorMessage as a, readFormTableRows as o } from "@rytass/bpm-core-client/form";
3
- import { ATTACHMENT_NOT_BINDABLE_ERROR_CODE as s, isFormStaticOptionFieldDefinition as c, isOrgUnitFieldDefinition as l, isTableFieldDefinition as u } from "@rytass/bpm-core-shared/form";
4
- // src/views/instances/approver-filled-form.ts
5
- function d(e, t) {
6
- let r = n(t);
7
- return {
8
- ...e,
9
- fields: e.fields.filter((e) => !r.has(e.fieldKey))
10
- };
11
- }
12
- function f(e, r) {
13
- return t(e, n(r));
14
- }
15
- function p(e, t) {
16
- let n = r(t), i = m(e, t);
17
- return {
18
- ...i,
19
- fields: i.fields.filter((e) => n.has(e.fieldKey))
20
- };
21
- }
22
- function m(e, t) {
23
- let n = r(t), a = i(t);
24
- return {
25
- ...e,
26
- fields: e.fields.map((e) => n.has(e.fieldKey) ? {
27
- ...e,
28
- required: a.has(e.fieldKey),
29
- requiredWhen: void 0
30
- } : e)
31
- };
32
- }
33
- var h = (e) => e.nodes.filter((e) => e.type === "userTask");
34
- function g(e, t) {
35
- let n = t === null ? /* @__PURE__ */ new Set() : r(t);
36
- return h(e).reduce((e, t) => ({
37
- ...Object.fromEntries([...r(t)].map((e) => [e, n.has(e) ? "本關補填" : `${t.data.label || t.id}補填`])),
38
- ...e
39
- }), {});
40
- }
41
- function _(e, t) {
42
- return Object.fromEntries([...r(t)].filter((t) => Object.prototype.hasOwnProperty.call(e, t)).map((t) => [t, e[t] ?? null]));
43
- }
44
- function v({ draft: e, node: t, schema: n, stored: i, values: a }) {
45
- let o = r(t), s = n.fields.filter((e) => {
46
- let t = a[e.fieldKey];
47
- return u(e) && o.has(e.fieldKey) && !Object.prototype.hasOwnProperty.call(i, e.fieldKey) && Array.isArray(t) && t.length > 0;
48
- });
49
- return {
50
- ...Object.fromEntries(s.map((e) => [e.fieldKey, a[e.fieldKey]])),
51
- ...e
52
- };
53
- }
54
- function y(e) {
55
- return e.includes("form data changed; refresh and retry");
56
- }
57
- var b = /^欄位「(.+?)」(.+)$/, x = /^「(.+?)」第 (\d+) 列(?:的「(.+?)」)?(.+)$/, S = "缺少必填欄位:";
58
- function C(e, t, n) {
59
- let r = n.settings?.label || n.settings?.fieldKey || "";
60
- switch (e) {
61
- case "REQUIRED": return n.topLevel && r !== "" ? `${r}為必填欄位。` : "此欄為必填。";
62
- case "MIN_LENGTH": return `至少需要 ${t ?? 0} 個字。`;
63
- case "MAX_LENGTH": return `最多 ${t ?? 0} 個字。`;
64
- case "MIN_ROWS": return `至少需要 ${t ?? 0} 列。`;
65
- case "MAX_ROWS": return `最多 ${t ?? 0} 列。`;
66
- case "MAX_FILES": return `最多 ${t ?? 0} 個檔案。`;
67
- case "PATTERN": return (n.settings && (n.settings.type === "text" || n.settings.type === "textarea") ? n.settings.patternErrorMessage?.trim() : void 0) || "格式不正確。";
68
- case "PATTERN_TIMEOUT": return "格式檢查逾時,請縮短內容後再試,或請表單設計者簡化格式。";
69
- default: return "此欄內容不正確。";
70
- }
71
- }
72
- function w(e) {
73
- let t = /^至少需要 (\d+) 列$/.exec(e), n = /^最多 (\d+) 列$/.exec(e), r = /^至少需要 (\d+) 個字$/.exec(e), i = /^最多 (\d+) 個字$/.exec(e), a = /^最多 (\d+) 個檔案$/.exec(e);
74
- return e === "為必填" ? { reason: "REQUIRED" } : t ? {
75
- limit: Number(t[1]),
76
- reason: "MIN_ROWS"
77
- } : n ? {
78
- limit: Number(n[1]),
79
- reason: "MAX_ROWS"
80
- } : r ? {
81
- limit: Number(r[1]),
82
- reason: "MIN_LENGTH"
83
- } : i ? {
84
- limit: Number(i[1]),
85
- reason: "MAX_LENGTH"
86
- } : a ? {
87
- limit: Number(a[1]),
88
- reason: "MAX_FILES"
89
- } : e === "格式不正確" ? { reason: "PATTERN" } : e === "無法在時限內完成格式檢查" ? { reason: "PATTERN_TIMEOUT" } : { reason: "TYPE" };
90
- }
91
- function T(e, t) {
92
- let n = t.find((t) => e === t.fieldKey || u(t) && e.startsWith(`${t.fieldKey}[`));
93
- if (!n) return null;
94
- if (e === n.fieldKey) return {
95
- key: e,
96
- settings: n,
97
- topLevel: !0
98
- };
99
- if (!u(n)) return null;
100
- let r = /^\[(\d+)\](?:\.(.+))?$/u.exec(e.slice(n.fieldKey.length));
101
- if (!r) return null;
102
- let i = `${n.fieldKey}[${r[1]}]`, a = r[2];
103
- if (a === void 0) return {
104
- key: i,
105
- settings: void 0,
106
- topLevel: !1
107
- };
108
- let o = n.columns.find((e) => e.fieldKey === a);
109
- return o ? {
110
- key: `${i}.${o.fieldKey}`,
111
- settings: o,
112
- topLevel: !1
113
- } : null;
114
- }
115
- function E(e, t) {
116
- let n = e.map((e) => {
117
- let n = T(e.path, t);
118
- return n === null ? null : [n.key, C(e.reason, e.limit, n)];
119
- });
120
- return n.length === 0 || n.some((e) => e === null) ? null : Object.fromEntries(n.filter((e) => e !== null));
121
- }
122
- function D(e, t) {
123
- let n = b.exec(e);
124
- if (n) {
125
- let e = t.find((e) => (e.label || e.fieldKey) === n[1]);
126
- return e ? {
127
- reason: n[2],
128
- target: {
129
- key: e.fieldKey,
130
- settings: e,
131
- topLevel: !0
132
- }
133
- } : null;
134
- }
135
- let r = x.exec(e);
136
- if (!r) return null;
137
- let i = t.find((e) => u(e) && (e.label || e.fieldKey) === r[1]);
138
- if (!i || !u(i)) return null;
139
- let a = `${i.fieldKey}[${Number(r[2]) - 1}]`, o = r[3];
140
- if (o === void 0) return {
141
- reason: r[4],
142
- target: {
143
- key: a,
144
- settings: void 0,
145
- topLevel: !1
146
- }
147
- };
148
- let s = i.columns.find((e) => (e.label || e.fieldKey) === o);
149
- return s ? {
150
- reason: r[4],
151
- target: {
152
- key: `${a}.${s.fieldKey}`,
153
- settings: s,
154
- topLevel: !1
155
- }
156
- } : null;
157
- }
158
- function O(e, t, n, i = []) {
159
- let a = t.fields.filter((e) => r(n).has(e.fieldKey));
160
- if (i.length > 0) return E(i, a);
161
- if (e.startsWith(S)) {
162
- let t = `, ${e.slice(7)}, `, n = a.filter((e) => t.includes(`, ${e.label || e.fieldKey}, `));
163
- return n.length > 0 ? Object.fromEntries(n.map((e) => [e.fieldKey, `${e.label || e.fieldKey}為必填欄位。`])) : null;
164
- }
165
- let o = e.split(";").map((e) => D(e, a));
166
- return o.length === 0 || o.some((e) => e === null) ? null : Object.fromEntries(o.flatMap((e) => {
167
- if (e === null) return [];
168
- let { limit: t, reason: n } = w(e.reason);
169
- return [[e.target.key, C(n, t, e.target)]];
170
- }));
171
- }
172
- var k = "未知組織";
173
- function A(e, t) {
174
- return [...new Set(e.fields.filter(l).map((e) => t[e.fieldKey]).filter((e) => typeof e == "string" && e.trim().length > 0))];
175
- }
176
- function j(t, n, r, i) {
177
- if (u(t)) {
178
- let e = o(n), r = t.columns.filter((e) => e.type === "number" || e.type === "money").map((t) => ({
179
- label: t.label || t.fieldKey,
180
- total: e.reduce((e, n) => typeof n[t.fieldKey] == "number" && Number.isFinite(n[t.fieldKey]) ? e + n[t.fieldKey] : e, 0)
181
- }));
182
- return [`${e.length} 列`, ...e.length > 0 ? r.map(({ label: e, total: t }) => `${e}合計 ${t.toLocaleString("zh-TW")}`) : []].join(",");
183
- }
184
- if (e(n)) return "未填寫";
185
- if (typeof n == "boolean") return n ? "是" : "否";
186
- if (l(t)) return typeof n == "string" ? i.get(n) ?? "未知組織" : k;
187
- let a = Array.isArray(n) ? n : [n], s = c(t) ? new Map(t.options.map((e) => [e.value, e.label])) : t.type === "member" ? r : /* @__PURE__ */ new Map();
188
- return a.map((e) => typeof e == "string" ? s.get(e) ?? e : String(e)).join("、");
189
- }
190
- function M(e, t, n, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map()) {
191
- let o = r(t);
192
- return e.fields.filter((e) => o.has(e.fieldKey) && Object.prototype.hasOwnProperty.call(n, e.fieldKey)).map((e) => ({
193
- fieldKey: e.fieldKey,
194
- label: e.label || e.fieldKey,
195
- text: j(e, n[e.fieldKey], i, a)
196
- }));
197
- }
198
- // src/views/instances/instance-error-message.ts
199
- var N = "表單中有附件無法附加到這個案件(只能附加申請人為本案上傳的檔案),請移除後重新上傳再送出。";
200
- function P(e) {
201
- let t = a(e);
202
- if (t) return t;
203
- let n = e instanceof Error ? e.message : null;
204
- return n?.includes(s) ? N : n ?? "發生未知錯誤";
205
- }
206
- export { v as a, A as c, M as d, p as f, f as i, _ as l, y as n, m as o, d as r, g as s, P as t, O as u };
207
-
208
- //# sourceMappingURL=instance-error-message-BEM4O_Kj.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instance-error-message-BEM4O_Kj.js","names":["readApplicantFormSchema","approverFilledKeys","readApproverFilledFieldKeys","definition","schema","field","readApplicantSubmission","omitFormDataKeys","values","readFillValidationSchema","fillableKeys","readNodeFillableFieldKeys","node","displaySchema","readFillDisplaySchema","requiredKeys","readNodeRequiredFieldKeys","userTaskNodes","readFillLabelMarkers","viewerKeys","viewerFillNode","fieldKey","markers","readFillPayload","readFillChanges","seededTables","seeded","isTableFieldDefinition","stored","draft","isFillConflictMessage","message","TOP_LEVEL_REF_PATTERN","TABLE_REF_PATTERN","MISSING_FIELDS_PREFIX","readFillIssueText","name","target","reason","limit","readFillReasonFromSentence","atLeastRows","sentence","atMostRows","shortest","longest","mostFiles","readFillIssueTarget","fields","path","candidate","rowPath","rowKey","columnKey","column","readFillErrorsFromIssues","entries","issues","issue","entry","readFillErrorTarget","topLevel","part","tableRef","table","columnLabel","readFillServerErrors","fillableFields","formDataIssues","listed","missing","parts","UNKNOWN_FILL_ORG_UNIT_TEXT","readFillOrgUnitIds","isOrgUnitFieldDefinition","value","readFillValueText","rows","readFormTableRows","totals","row","sum","label","total","isFormDataValueEmpty","orgUnitNames","items","optionLabels","isFormStaticOptionFieldDefinition","option","memberNames","item","readFillSummary","ATTACHMENT_NOT_BINDABLE_MESSAGE","readErrorMessage","dataSourceMessage","readFormDataSourceErrorMessage","error","ATTACHMENT_NOT_BINDABLE_ERROR_CODE"],"sources":["../../src/views/instances/approver-filled-form.ts","../../src/views/instances/instance-error-message.ts"],"sourcesContent":["import {\n isFormDataValueEmpty,\n omitFormDataKeys,\n readApproverFilledFieldKeys,\n readNodeFillableFieldKeys,\n readNodeRequiredFieldKeys,\n type UserTaskNode,\n type WorkflowDefinition,\n} from '@rytass/bpm-core-shared';\nimport {\n isFormStaticOptionFieldDefinition,\n isOrgUnitFieldDefinition,\n isTableFieldDefinition,\n type FormDefinitionSchema,\n type FormFieldDefinition,\n type FormFieldValue,\n type FormDataIssue,\n type FormDataIssueReason,\n type TableColumnDefinition,\n} from '@rytass/bpm-core-shared/form';\nimport { readFormTableRows } from '@rytass/bpm-core-client/form';\nimport type { WorkflowFormData } from '@rytass/bpm-core-client/workflow';\n\n/**\n * The form as the applicant sees it: without the fields some approver fills in.\n * The server drops those keys from a submission, so rendering one would swallow\n * what the applicant types, and a `minRows` or `required` on it would block a\n * launch nobody can complete. Returns an equal schema when nothing is\n * approver-filled; never mutates its input.\n */\nexport function readApplicantFormSchema(\n schema: FormDefinitionSchema,\n definition: WorkflowDefinition,\n): FormDefinitionSchema {\n const approverFilledKeys = readApproverFilledFieldKeys(definition);\n\n return {\n ...schema,\n fields: schema.fields.filter(\n (field) => !approverFilledKeys.has(field.fieldKey),\n ),\n };\n}\n\n/** The payload the applicant may send: `values` without approver-filled keys. */\nexport function readApplicantSubmission(\n values: WorkflowFormData,\n definition: WorkflowDefinition,\n): WorkflowFormData {\n // Dropping keys cannot change a remaining value's type, which is all the\n // shared helper's `unknown` return forgets.\n return omitFormDataKeys(\n values,\n readApproverFilledFieldKeys(definition),\n ) as WorkflowFormData;\n}\n\n/**\n * The form an approver's fill is validated against: only the fields `node`\n * lets them fill in, each required exactly when the node says `REQUIRED`. A\n * required table needs at least one row, the rule `validateFormRendererValues`\n * already applies, so the result agrees with the server's fill check. Never\n * mutates its input.\n */\nexport function readFillValidationSchema(\n schema: FormDefinitionSchema,\n node: UserTaskNode,\n): FormDefinitionSchema {\n const fillableKeys = readNodeFillableFieldKeys(node);\n const displaySchema = readFillDisplaySchema(schema, node);\n\n // Derived from the display schema so the check and the asterisk read the\n // same rule.\n return {\n ...displaySchema,\n fields: displaySchema.fields.filter((field) =>\n fillableKeys.has(field.fieldKey),\n ),\n };\n}\n\n/**\n * The schema the fill node's approver sees: every field as the form defines\n * it, except that the node's fillable fields are required exactly when the\n * node says `REQUIRED`, so the asterisk matches what approving will check.\n */\nexport function readFillDisplaySchema(\n schema: FormDefinitionSchema,\n node: UserTaskNode,\n): FormDefinitionSchema {\n const fillableKeys = readNodeFillableFieldKeys(node);\n const requiredKeys = readNodeRequiredFieldKeys(node);\n\n return {\n ...schema,\n fields: schema.fields.map((field) =>\n fillableKeys.has(field.fieldKey)\n ? {\n ...field,\n required: requiredKeys.has(field.fieldKey),\n // The node alone decides; the server ignores the form's rule.\n requiredWhen: undefined,\n }\n : field,\n ),\n };\n}\n\nconst userTaskNodes = (definition: WorkflowDefinition): readonly UserTaskNode[] =>\n definition.nodes.filter(\n (node): node is UserTaskNode => node.type === 'userTask',\n );\n\n/**\n * The marker shown after each approver-filled field's label: 「本關補填」 on\n * the fields `viewerFillNode` lets the viewer fill, 「<node>補填」 on every\n * other approver-filled field (the first node in the definition that fills\n * it names it).\n */\nexport function readFillLabelMarkers(\n definition: WorkflowDefinition,\n viewerFillNode: UserTaskNode | null,\n): Readonly<Record<string, string>> {\n const viewerKeys =\n viewerFillNode === null\n ? new Set<string>()\n : readNodeFillableFieldKeys(viewerFillNode);\n\n return userTaskNodes(definition).reduce<Readonly<Record<string, string>>>(\n (markers, node) => ({\n ...Object.fromEntries(\n [...readNodeFillableFieldKeys(node)].map((fieldKey) => [\n fieldKey,\n viewerKeys.has(fieldKey)\n ? '本關補填'\n : `${node.data.label || node.id}補填`,\n ]),\n ),\n ...markers,\n }),\n {},\n );\n}\n\n/**\n * What approving sends as `fill.formData`: the keys of `values` that `node`\n * lets its approver fill, and nothing else (the server refuses any other key).\n * `values` is what the approver changed, not the rendered form — a renderer\n * default the approver never touched (a table's empty rows, a boolean's\n * `false`) is not theirs to sign, and would otherwise show up as filled in.\n */\nexport function readFillPayload(\n values: WorkflowFormData,\n node: UserTaskNode,\n): Readonly<Record<string, unknown>> {\n return Object.fromEntries(\n [...readNodeFillableFieldKeys(node)]\n .filter((fieldKey) =>\n Object.prototype.hasOwnProperty.call(values, fieldKey),\n )\n // A cleared field reads `undefined`, which JSON drops, and the server\n // would keep the old value; `null` clears it.\n .map((fieldKey) => [fieldKey, values[fieldKey] ?? null]),\n );\n}\n\n/**\n * What the approver's fill amounts to: the fields they changed (`draft`), plus\n * each fill table the page seeds with `minRows` rows that the case does not\n * store yet. The page shows those rows and validates them, so they are sent\n * too — left out, the server would refuse the approval for missing rows the\n * approver can see on screen.\n */\nexport function readFillChanges({\n draft,\n node,\n schema,\n stored,\n values,\n}: {\n readonly draft: WorkflowFormData;\n readonly node: UserTaskNode;\n readonly schema: FormDefinitionSchema;\n readonly stored: WorkflowFormData;\n readonly values: WorkflowFormData;\n}): WorkflowFormData {\n const fillableKeys = readNodeFillableFieldKeys(node);\n const seededTables = schema.fields.filter((field) => {\n const seeded = values[field.fieldKey];\n\n return (\n isTableFieldDefinition(field) &&\n fillableKeys.has(field.fieldKey) &&\n !Object.prototype.hasOwnProperty.call(stored, field.fieldKey) &&\n Array.isArray(seeded) &&\n seeded.length > 0\n );\n });\n\n return {\n ...Object.fromEntries(\n seededTables.map((field) => [field.fieldKey, values[field.fieldKey]]),\n ),\n ...draft,\n };\n}\n\n/** The server message of a fill against form data someone else changed. */\nexport function isFillConflictMessage(message: string): boolean {\n return message.includes('form data changed; refresh and retry');\n}\n\n// The server names a field by its label: `欄位「標籤」`, a table row as\n// `「表格」第 N 列` (1-based), and a cell as `「表格」第 N 列的「欄位」`.\n// Each part of a message is separated by `;`. This is the fallback for a\n// response that carries no `formDataIssues`: labels are not unique, so the\n// issues, which address each value by its path, are the primary route.\nconst TOP_LEVEL_REF_PATTERN = /^欄位「(.+?)」(.+)$/;\nconst TABLE_REF_PATTERN = /^「(.+?)」第 (\\d+) 列(?:的「(.+?)」)?(.+)$/;\nconst MISSING_FIELDS_PREFIX = '缺少必填欄位:';\n\n/** The field, or table column, a server error names, with its renderer key. */\ninterface FillErrorTarget {\n readonly key: string;\n readonly settings: FormFieldDefinition | TableColumnDefinition | undefined;\n readonly topLevel: boolean;\n}\n\n/** The sentence a refused value shows, by its reason. */\nfunction readFillIssueText(\n reason: FormDataIssueReason,\n limit: number | undefined,\n target: FillErrorTarget,\n): string {\n const name = target.settings?.label || target.settings?.fieldKey || '';\n\n switch (reason) {\n case 'REQUIRED':\n return target.topLevel && name !== ''\n ? `${name}為必填欄位。`\n : '此欄為必填。';\n case 'MIN_LENGTH':\n return `至少需要 ${limit ?? 0} 個字。`;\n case 'MAX_LENGTH':\n return `最多 ${limit ?? 0} 個字。`;\n case 'MIN_ROWS':\n return `至少需要 ${limit ?? 0} 列。`;\n case 'MAX_ROWS':\n return `最多 ${limit ?? 0} 列。`;\n case 'MAX_FILES':\n return `最多 ${limit ?? 0} 個檔案。`;\n case 'PATTERN': {\n const message =\n target.settings &&\n (target.settings.type === 'text' || target.settings.type === 'textarea')\n ? target.settings.patternErrorMessage?.trim()\n : undefined;\n\n return message || '格式不正確。';\n }\n // The server ran out of time on the format check; the value may be fine.\n case 'PATTERN_TIMEOUT':\n return '格式檢查逾時,請縮短內容後再試,或請表單設計者簡化格式。';\n default:\n return '此欄內容不正確。';\n }\n}\n\n/** The reason a message sentence stands for, for the message fallback. */\nfunction readFillReasonFromSentence(sentence: string): {\n readonly limit?: number;\n readonly reason: FormDataIssueReason;\n} {\n const atLeastRows = /^至少需要 (\\d+) 列$/.exec(sentence);\n const atMostRows = /^最多 (\\d+) 列$/.exec(sentence);\n const shortest = /^至少需要 (\\d+) 個字$/.exec(sentence);\n const longest = /^最多 (\\d+) 個字$/.exec(sentence);\n const mostFiles = /^最多 (\\d+) 個檔案$/.exec(sentence);\n\n if (sentence === '為必填') {\n return { reason: 'REQUIRED' };\n }\n\n if (atLeastRows) {\n return { limit: Number(atLeastRows[1]), reason: 'MIN_ROWS' };\n }\n\n if (atMostRows) {\n return { limit: Number(atMostRows[1]), reason: 'MAX_ROWS' };\n }\n\n if (shortest) {\n return { limit: Number(shortest[1]), reason: 'MIN_LENGTH' };\n }\n\n if (longest) {\n return { limit: Number(longest[1]), reason: 'MAX_LENGTH' };\n }\n\n if (mostFiles) {\n return { limit: Number(mostFiles[1]), reason: 'MAX_FILES' };\n }\n\n if (sentence === '格式不正確') {\n return { reason: 'PATTERN' };\n }\n\n if (sentence === '無法在時限內完成格式檢查') {\n return { reason: 'PATTERN_TIMEOUT' };\n }\n\n return { reason: 'TYPE' };\n}\n\n/**\n * The renderer key of the value an issue path addresses, among the fields\n * `fields` lets the approver fill. `items` is a table, `items[1]` a row,\n * `items[1].qty` a cell. `null` when the path names nothing fillable.\n */\nfunction readFillIssueTarget(\n path: string,\n fields: readonly FormFieldDefinition[],\n): FillErrorTarget | null {\n const field = fields.find(\n (candidate) =>\n path === candidate.fieldKey ||\n (isTableFieldDefinition(candidate) &&\n path.startsWith(`${candidate.fieldKey}[`)),\n );\n\n if (!field) {\n return null;\n }\n\n if (path === field.fieldKey) {\n return { key: path, settings: field, topLevel: true };\n }\n\n if (!isTableFieldDefinition(field)) {\n return null;\n }\n\n const rowPath = /^\\[(\\d+)\\](?:\\.(.+))?$/u.exec(\n path.slice(field.fieldKey.length),\n );\n\n if (!rowPath) {\n return null;\n }\n\n const rowKey = `${field.fieldKey}[${rowPath[1]}]`;\n const columnKey = rowPath[2];\n\n if (columnKey === undefined) {\n return { key: rowKey, settings: undefined, topLevel: false };\n }\n\n const column = field.columns.find(\n (candidate) => candidate.fieldKey === columnKey,\n );\n\n return column\n ? { key: `${rowKey}.${column.fieldKey}`, settings: column, topLevel: false }\n : null;\n}\n\nfunction readFillErrorsFromIssues(\n issues: readonly FormDataIssue[],\n fields: readonly FormFieldDefinition[],\n): Readonly<Record<string, string>> | null {\n const entries = issues.map((issue): readonly [string, string] | null => {\n const target = readFillIssueTarget(issue.path, fields);\n\n return target === null\n ? null\n : [target.key, readFillIssueText(issue.reason, issue.limit, target)];\n });\n\n if (entries.length === 0 || entries.some((entry) => entry === null)) {\n return null;\n }\n\n return Object.fromEntries(\n entries.filter(\n (entry): entry is readonly [string, string] => entry !== null,\n ),\n );\n}\n\nfunction readFillErrorTarget(\n part: string,\n fields: readonly FormFieldDefinition[],\n): { readonly target: FillErrorTarget; readonly reason: string } | null {\n const topLevel = TOP_LEVEL_REF_PATTERN.exec(part);\n\n if (topLevel) {\n const field = fields.find(\n (candidate) => (candidate.label || candidate.fieldKey) === topLevel[1],\n );\n\n return field\n ? {\n reason: topLevel[2],\n target: { key: field.fieldKey, settings: field, topLevel: true },\n }\n : null;\n }\n\n const tableRef = TABLE_REF_PATTERN.exec(part);\n\n if (!tableRef) {\n return null;\n }\n\n const table = fields.find(\n (candidate) =>\n isTableFieldDefinition(candidate) &&\n (candidate.label || candidate.fieldKey) === tableRef[1],\n );\n\n if (!table || !isTableFieldDefinition(table)) {\n return null;\n }\n\n const rowKey = `${table.fieldKey}[${Number(tableRef[2]) - 1}]`;\n const columnLabel = tableRef[3];\n\n if (columnLabel === undefined) {\n return {\n reason: tableRef[4],\n target: { key: rowKey, settings: undefined, topLevel: false },\n };\n }\n\n const column = table.columns.find(\n (candidate) => (candidate.label || candidate.fieldKey) === columnLabel,\n );\n\n return column\n ? {\n reason: tableRef[4],\n target: {\n key: `${rowKey}.${column.fieldKey}`,\n settings: column,\n topLevel: false,\n },\n }\n : null;\n}\n\n/**\n * Turns the server's fill validation refusal (docs/08 §8.5, error table 2)\n * into field errors keyed the way `FormRenderer` addresses them, so a check\n * the page missed still lands on the field. `formDataIssues` is the refusal's\n * structured list and wins when it is present: each issue names its value by\n * path, so two fields sharing a label stay apart. Without it, the Chinese\n * `message` is parsed. `null` when any part does not resolve to a fillable\n * field — the caller then shows the message as it is.\n */\nexport function readFillServerErrors(\n message: string,\n schema: FormDefinitionSchema,\n node: UserTaskNode,\n formDataIssues: readonly FormDataIssue[] = [],\n): Readonly<Record<string, string>> | null {\n const fillableFields = schema.fields.filter((field) =>\n readNodeFillableFieldKeys(node).has(field.fieldKey),\n );\n\n if (formDataIssues.length > 0) {\n return readFillErrorsFromIssues(formDataIssues, fillableFields);\n }\n\n if (message.startsWith(MISSING_FIELDS_PREFIX)) {\n // Labels may hold commas, so match each fillable field's label (or key)\n // against the list rather than splitting it.\n const listed = `, ${message.slice(MISSING_FIELDS_PREFIX.length)}, `;\n const missing = fillableFields.filter((field) =>\n listed.includes(`, ${field.label || field.fieldKey}, `),\n );\n\n return missing.length > 0\n ? Object.fromEntries(\n missing.map((field) => [\n field.fieldKey,\n `${field.label || field.fieldKey}為必填欄位。`,\n ]),\n )\n : null;\n }\n\n const parts = message\n .split(';')\n .map((part) => readFillErrorTarget(part, fillableFields));\n\n if (parts.length === 0 || parts.some((part) => part === null)) {\n return null;\n }\n\n return Object.fromEntries(\n parts.flatMap((part) => {\n if (part === null) {\n return [];\n }\n\n const { limit, reason } = readFillReasonFromSentence(part.reason);\n\n return [[part.target.key, readFillIssueText(reason, limit, part.target)]];\n }),\n );\n}\n\nexport interface FillSummaryItem {\n readonly fieldKey: string;\n readonly label: string;\n readonly text: string;\n}\n\nexport const UNKNOWN_FILL_ORG_UNIT_TEXT = '未知組織';\n\n/**\n * The org unit ids among `values`, once each and in form order, so the caller\n * can look up their names before building the summary.\n */\nexport function readFillOrgUnitIds(\n schema: FormDefinitionSchema,\n values: WorkflowFormData,\n): readonly string[] {\n return [\n ...new Set(\n schema.fields\n .filter(isOrgUnitFieldDefinition)\n .map((field) => values[field.fieldKey])\n .filter(\n (value): value is string =>\n typeof value === 'string' && value.trim().length > 0,\n ),\n ),\n ];\n}\n\nfunction readFillValueText(\n field: FormFieldDefinition,\n value: FormFieldValue | undefined,\n memberNames: ReadonlyMap<string, string>,\n orgUnitNames: ReadonlyMap<string, string>,\n): string {\n if (isTableFieldDefinition(field)) {\n const rows = readFormTableRows(value);\n const totals = field.columns\n .filter((column) => column.type === 'number' || column.type === 'money')\n .map((column) => ({\n label: column.label || column.fieldKey,\n total: rows.reduce(\n (sum, row) =>\n typeof row[column.fieldKey] === 'number' &&\n Number.isFinite(row[column.fieldKey])\n ? sum + (row[column.fieldKey] as number)\n : sum,\n 0,\n ),\n }));\n\n return [\n `${rows.length} 列`,\n ...(rows.length > 0\n ? totals.map(\n ({ label, total }) => `${label}合計 ${total.toLocaleString('zh-TW')}`,\n )\n : []),\n ].join(',');\n }\n\n if (isFormDataValueEmpty(value)) {\n return '未填寫';\n }\n\n if (typeof value === 'boolean') {\n return value ? '是' : '否';\n }\n\n if (isOrgUnitFieldDefinition(field)) {\n // `orgUnitNames` (`useOrgUnitNames`) maps an id still being looked up to\n // a loading text; an id the lookup did not name is 「未知組織」. Never the\n // raw id.\n return typeof value === 'string'\n ? (orgUnitNames.get(value) ?? UNKNOWN_FILL_ORG_UNIT_TEXT)\n : UNKNOWN_FILL_ORG_UNIT_TEXT;\n }\n\n const items = Array.isArray(value) ? value : [value];\n const optionLabels = isFormStaticOptionFieldDefinition(field)\n ? new Map(field.options.map((option) => [option.value, option.label]))\n : field.type === 'member'\n ? memberNames\n : new Map<string, string>();\n\n return items\n .map((item) =>\n typeof item === 'string' ? (optionLabels.get(item) ?? item) : String(item),\n )\n .join('、');\n}\n\n/**\n * One line per field `node` lets its approver fill, in form order, for the\n * approve dialog: what will be sent along with the approval. A member field\n * names each member found in `memberNames` and shows the id otherwise; an org\n * unit field names its unit from `orgUnitNames` and shows 「未知組織」 otherwise.\n */\nexport function readFillSummary(\n schema: FormDefinitionSchema,\n node: UserTaskNode,\n values: WorkflowFormData,\n memberNames: ReadonlyMap<string, string> = new Map(),\n orgUnitNames: ReadonlyMap<string, string> = new Map(),\n): readonly FillSummaryItem[] {\n const fillableKeys = readNodeFillableFieldKeys(node);\n\n return schema.fields\n .filter(\n (field) =>\n fillableKeys.has(field.fieldKey) &&\n Object.prototype.hasOwnProperty.call(values, field.fieldKey),\n )\n .map((field) => ({\n fieldKey: field.fieldKey,\n label: field.label || field.fieldKey,\n text: readFillValueText(\n field,\n values[field.fieldKey],\n memberNames,\n orgUnitNames,\n ),\n }));\n}\n","import { readFormDataSourceErrorMessage } from '@rytass/bpm-core-client/form';\nimport { ATTACHMENT_NOT_BINDABLE_ERROR_CODE } from '@rytass/bpm-core-shared/form';\n\nconst ATTACHMENT_NOT_BINDABLE_MESSAGE =\n '表單中有附件無法附加到這個案件(只能附加申請人為本案上傳的檔案),請移除後重新上傳再送出。';\n\n/**\n * The message a case page shows for a failed request: a stable server code\n * translated into words, otherwise the server's own message.\n */\nexport function readErrorMessage(error: unknown): string {\n // DataSource failures arrive as stable codes so the backend never leaks\n // upstream transport detail; translate them instead of showing the raw code.\n const dataSourceMessage = readFormDataSourceErrorMessage(error);\n\n if (dataSourceMessage) {\n return dataSourceMessage;\n }\n\n const message = error instanceof Error ? error.message : null;\n\n // Names the problem, not the attachment ids the server lists.\n if (message?.includes(ATTACHMENT_NOT_BINDABLE_ERROR_CODE)) {\n return ATTACHMENT_NOT_BINDABLE_MESSAGE;\n }\n\n return message ?? '發生未知錯誤';\n}\n"],"mappings":";;;;AA8BA,SAAgBA,EACd,GACA,GACsB;CACtB,IAAMC,IAAqBC,EAA4BC,CAAU;CAEjE,OAAO;EACL,GAAGC;EACH,QAAQA,EAAO,OAAO,QACnB,MAAU,CAACH,EAAmB,IAAII,EAAM,QAAQ,CACnD;CACF;AACF;AAGA,SAAgBC,EACd,GACA,GACkB;CAGlB,OAAOC,EACLC,GACAN,EAA4BC,CAAU,CACxC;AACF;AASA,SAAgBM,EACd,GACA,GACsB;CACt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AYJ,EAAa,IAAII,CAAI,KAAKA,IAAQ,OAAOA,CAAI,CAC3E,CAAC,CACA,KAAK,GAAG;AACb;AAQA,SAAgBC,EACd,GACA,GACA,GACA,oBAA2C,IAAI,IAAI,GACnD,oBAA4C,IAAI,IAAI,GACxB;CAC5B,IAAMlF,IAAeC,EAA0BC,CAAI;CAEnD,OAAOR,EAAO,OACX,QACE,MACCM,EAAa,IAAIL,EAAM,QAAQ,KAC/B,OAAO,UAAU,eAAe,KAAKG,GAAQH,EAAM,QAAQ,CAC/D,CAAC,CACA,KAAK,OAAW;EACf,UAAUA,EAAM;EAChB,OAAOA,EAAM,SAASA,EAAM;EAC5B,MAAMuE,EACJvE,GACAG,EAAOH,EAAM,WACbqF,GACAL,CACF;CACF,EAAE;AACN;;ACxnBA,IAAMQ,IACJ;AAMF,SAAgBC,EAAiB,GAAwB;CAGvD,IAAMC,IAAoBC,EAA+BC,CAAK;CAE9D,IAAIF,GACF,OAAOA;CAGT,IAAMhE,IAAUkE,aAAiB,QAAQA,EAAM,UAAU;CAOzD,OAJIlE,GAAS,SAASmE,CAAkC,IAC/CL,IAGF9D,KAAW;AACpB"}
@@ -1,2 +0,0 @@
1
- let e=require("@rytass/bpm-core-shared"),t=require("@rytass/bpm-core-client/form"),n=require("@rytass/bpm-core-shared/form");function r(t,n){let r=(0,e.readApproverFilledFieldKeys)(n);return{...t,fields:t.fields.filter(e=>!r.has(e.fieldKey))}}function i(t,n){return(0,e.omitFormDataKeys)(t,(0,e.readApproverFilledFieldKeys)(n))}function a(t,n){let r=(0,e.readNodeFillableFieldKeys)(n),i=o(t,n);return{...i,fields:i.fields.filter(e=>r.has(e.fieldKey))}}function o(t,n){let r=(0,e.readNodeFillableFieldKeys)(n),i=(0,e.readNodeRequiredFieldKeys)(n);return{...t,fields:t.fields.map(e=>r.has(e.fieldKey)?{...e,required:i.has(e.fieldKey),requiredWhen:void 0}:e)}}var s=e=>e.nodes.filter(e=>e.type===`userTask`);function c(t,n){let r=n===null?new Set:(0,e.readNodeFillableFieldKeys)(n);return s(t).reduce((t,n)=>({...Object.fromEntries([...(0,e.readNodeFillableFieldKeys)(n)].map(e=>[e,r.has(e)?`本關補填`:`${n.data.label||n.id}補填`])),...t}),{})}function l(t,n){return Object.fromEntries([...(0,e.readNodeFillableFieldKeys)(n)].filter(e=>Object.prototype.hasOwnProperty.call(t,e)).map(e=>[e,t[e]??null]))}function u({draft:t,node:r,schema:i,stored:a,values:o}){let s=(0,e.readNodeFillableFieldKeys)(r),c=i.fields.filter(e=>{let t=o[e.fieldKey];return(0,n.isTableFieldDefinition)(e)&&s.has(e.fieldKey)&&!Object.prototype.hasOwnProperty.call(a,e.fieldKey)&&Array.isArray(t)&&t.length>0});return{...Object.fromEntries(c.map(e=>[e.fieldKey,o[e.fieldKey]])),...t}}function d(e){return e.includes(`form data changed; refresh and retry`)}var f=/^欄位「(.+?)」(.+)$/,p=/^「(.+?)」第 (\d+) 列(?:的「(.+?)」)?(.+)$/,m=`缺少必填欄位:`;function h(e,t,n){let r=n.settings?.label||n.settings?.fieldKey||``;switch(e){case`REQUIRED`:return n.topLevel&&r!==``?`${r}為必填欄位。`:`此欄為必填。`;case`MIN_LENGTH`:return`至少需要 ${t??0} 個字。`;case`MAX_LENGTH`:return`最多 ${t??0} 個字。`;case`MIN_ROWS`:return`至少需要 ${t??0} 列。`;case`MAX_ROWS`:return`最多 ${t??0} 列。`;case`MAX_FILES`:return`最多 ${t??0} 個檔案。`;case`PATTERN`:return(n.settings&&(n.settings.type===`text`||n.settings.type===`textarea`)?n.settings.patternErrorMessage?.trim():void 0)||`格式不正確。`;case`PATTERN_TIMEOUT`:return`格式檢查逾時,請縮短內容後再試,或請表單設計者簡化格式。`;default:return`此欄內容不正確。`}}function g(e){let t=/^至少需要 (\d+) 列$/.exec(e),n=/^最多 (\d+) 列$/.exec(e),r=/^至少需要 (\d+) 個字$/.exec(e),i=/^最多 (\d+) 個字$/.exec(e),a=/^最多 (\d+) 個檔案$/.exec(e);return e===`為必填`?{reason:`REQUIRED`}:t?{limit:Number(t[1]),reason:`MIN_ROWS`}:n?{limit:Number(n[1]),reason:`MAX_ROWS`}:r?{limit:Number(r[1]),reason:`MIN_LENGTH`}:i?{limit:Number(i[1]),reason:`MAX_LENGTH`}:a?{limit:Number(a[1]),reason:`MAX_FILES`}:e===`格式不正確`?{reason:`PATTERN`}:e===`無法在時限內完成格式檢查`?{reason:`PATTERN_TIMEOUT`}:{reason:`TYPE`}}function _(e,t){let r=t.find(t=>e===t.fieldKey||(0,n.isTableFieldDefinition)(t)&&e.startsWith(`${t.fieldKey}[`));if(!r)return null;if(e===r.fieldKey)return{key:e,settings:r,topLevel:!0};if(!(0,n.isTableFieldDefinition)(r))return null;let i=/^\[(\d+)\](?:\.(.+))?$/u.exec(e.slice(r.fieldKey.length));if(!i)return null;let a=`${r.fieldKey}[${i[1]}]`,o=i[2];if(o===void 0)return{key:a,settings:void 0,topLevel:!1};let s=r.columns.find(e=>e.fieldKey===o);return s?{key:`${a}.${s.fieldKey}`,settings:s,topLevel:!1}:null}function v(e,t){let n=e.map(e=>{let n=_(e.path,t);return n===null?null:[n.key,h(e.reason,e.limit,n)]});return n.length===0||n.some(e=>e===null)?null:Object.fromEntries(n.filter(e=>e!==null))}function y(e,t){let r=f.exec(e);if(r){let e=t.find(e=>(e.label||e.fieldKey)===r[1]);return e?{reason:r[2],target:{key:e.fieldKey,settings:e,topLevel:!0}}:null}let i=p.exec(e);if(!i)return null;let a=t.find(e=>(0,n.isTableFieldDefinition)(e)&&(e.label||e.fieldKey)===i[1]);if(!a||!(0,n.isTableFieldDefinition)(a))return null;let o=`${a.fieldKey}[${Number(i[2])-1}]`,s=i[3];if(s===void 0)return{reason:i[4],target:{key:o,settings:void 0,topLevel:!1}};let c=a.columns.find(e=>(e.label||e.fieldKey)===s);return c?{reason:i[4],target:{key:`${o}.${c.fieldKey}`,settings:c,topLevel:!1}}:null}function b(t,n,r,i=[]){let a=n.fields.filter(t=>(0,e.readNodeFillableFieldKeys)(r).has(t.fieldKey));if(i.length>0)return v(i,a);if(t.startsWith(m)){let e=`, ${t.slice(7)}, `,n=a.filter(t=>e.includes(`, ${t.label||t.fieldKey}, `));return n.length>0?Object.fromEntries(n.map(e=>[e.fieldKey,`${e.label||e.fieldKey}為必填欄位。`])):null}let o=t.split(`;`).map(e=>y(e,a));return o.length===0||o.some(e=>e===null)?null:Object.fromEntries(o.flatMap(e=>{if(e===null)return[];let{limit:t,reason:n}=g(e.reason);return[[e.target.key,h(n,t,e.target)]]}))}var x=`未知組織`;function S(e,t){return[...new Set(e.fields.filter(n.isOrgUnitFieldDefinition).map(e=>t[e.fieldKey]).filter(e=>typeof e==`string`&&e.trim().length>0))]}function C(r,i,a,o){if((0,n.isTableFieldDefinition)(r)){let e=(0,t.readFormTableRows)(i),n=r.columns.filter(e=>e.type===`number`||e.type===`money`).map(t=>({label:t.label||t.fieldKey,total:e.reduce((e,n)=>typeof n[t.fieldKey]==`number`&&Number.isFinite(n[t.fieldKey])?e+n[t.fieldKey]:e,0)}));return[`${e.length} 列`,...e.length>0?n.map(({label:e,total:t})=>`${e}合計 ${t.toLocaleString(`zh-TW`)}`):[]].join(`,`)}if((0,e.isFormDataValueEmpty)(i))return`未填寫`;if(typeof i==`boolean`)return i?`是`:`否`;if((0,n.isOrgUnitFieldDefinition)(r))return typeof i==`string`?o.get(i)??`未知組織`:x;let s=Array.isArray(i)?i:[i],c=(0,n.isFormStaticOptionFieldDefinition)(r)?new Map(r.options.map(e=>[e.value,e.label])):r.type===`member`?a:new Map;return s.map(e=>typeof e==`string`?c.get(e)??e:String(e)).join(`、`)}function w(t,n,r,i=new Map,a=new Map){let o=(0,e.readNodeFillableFieldKeys)(n);return t.fields.filter(e=>o.has(e.fieldKey)&&Object.prototype.hasOwnProperty.call(r,e.fieldKey)).map(e=>({fieldKey:e.fieldKey,label:e.label||e.fieldKey,text:C(e,r[e.fieldKey],i,a)}))}var T=`表單中有附件無法附加到這個案件(只能附加申請人為本案上傳的檔案),請移除後重新上傳再送出。`;function E(e){let r=(0,t.readFormDataSourceErrorMessage)(e);if(r)return r;let i=e instanceof Error?e.message:null;return i?.includes(n.ATTACHMENT_NOT_BINDABLE_ERROR_CODE)?T:i??`發生未知錯誤`}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return b}});
2
- //# sourceMappingURL=instance-error-message-BpCLCOjp.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instance-error-message-BpCLCOjp.cjs","names":["readApproverFilledFieldKeys","omitFormDataKeys","readNodeFillableFieldKeys","readNodeRequiredFieldKeys","isTableFieldDefinition","isOrgUnitFieldDefinition","readFormTableRows","isFormDataValueEmpty","isFormStaticOptionFieldDefinition","readFormDataSourceErrorMessage","ATTACHMENT_NOT_BINDABLE_ERROR_CODE","_rytass_bpm_core_shared","_rytass_bpm_core_client_form","_rytass_bpm_core_shared_form","readApplicantFormSchema","approverFilledKeys","definition","schema","field","readApplicantSubmission","values","readFillValidationSchema","fillableKeys","node","displaySchema","readFillDisplaySchema","requiredKeys","userTaskNodes","readFillLabelMarkers","viewerKeys","viewerFillNode","fieldKey","markers","readFillPayload","readFillChanges","seededTables","seeded","stored","draft","isFillConflictMessage","message","TOP_LEVEL_REF_PATTERN","TABLE_REF_PATTERN","MISSING_FIELDS_PREFIX","readFillIssueText","name","target","reason","limit","readFillReasonFromSentence","atLeastRows","sentence","atMostRows","shortest","longest","mostFiles","readFillIssueTarget","fields","path","candidate","rowPath","rowKey","columnKey","column","readFillErrorsFromIssues","entries","issues","issue","entry","readFillErrorTarget","topLevel","part","tableRef","table","columnLabel","readFillServerErrors","fillableFields","formDataIssues","listed","missing","parts","UNKNOWN_FILL_ORG_UNIT_TEXT","readFillOrgUnitIds","value","readFillValueText","rows","totals","row","sum","label","total","orgUnitNames","items","optionLabels","option","memberNames","item","readFillSummary","ATTACHMENT_NOT_BINDABLE_MESSAGE","readErrorMessage","dataSourceMessage","error"],"sources":["../../src/views/instances/approver-filled-form.ts","../../src/views/instances/instance-error-message.ts"],"sourcesContent":["import {\n isFormDataValueEmpty,\n omitFormDataKeys,\n readApproverFilledFieldKeys,\n readNodeFillableFieldKeys,\n readNodeRequiredFieldKeys,\n type UserTaskNode,\n type WorkflowDefinition,\n} from '@rytass/bpm-core-shared';\nimport {\n isFormStaticOptionFieldDefinition,\n isOrgUnitFieldDefinition,\n isTableFieldDefinition,\n type FormDefinitionSchema,\n type FormFieldDefinition,\n type FormFieldValue,\n type FormDataIssue,\n type FormDataIssueReason,\n type TableColumnDefinition,\n} from '@rytass/bpm-core-shared/form';\nimport { readFormTableRows } from '@rytass/bpm-core-client/form';\nimport type { WorkflowFormData } from '@rytass/bpm-core-client/workflow';\n\n/**\n * The form as the applicant sees it: without the fields some approver fills in.\n * The server drops those keys from a submission, so rendering one would swallow\n * what the applicant types, and a `minRows` or `required` on it would block a\n * launch nobody can complete. Returns an equal schema when nothing is\n * approver-filled; never mutates its input.\n */\nexport function readApplicantFormSchema(\n schema: FormDefinitionSchema,\n definition: WorkflowDefinition,\n): FormDefinitionSchema {\n const approverFilledKeys = readApproverFilledFieldKeys(definition);\n\n return {\n ...schema,\n fields: schema.fields.filter(\n (field) => !approverFilledKeys.has(field.fieldKey),\n ),\n };\n}\n\n/** The payload the applicant may send: `values` without approver-filled keys. */\nexport function readApplicantSubmission(\n values: WorkflowFormData,\n definition: WorkflowDefinition,\n): WorkflowFormData {\n // Dropping keys cannot change a remaining value's type, which is all the\n // shared helper's `unknown` return forgets.\n return omitFormDataKeys(\n values,\n readApproverFilledFieldKeys(definition),\n ) as WorkflowFormData;\n}\n\n/**\n * The form an approver's fill is validated against: only the fields `node`\n * lets them fill in, each required exactly when the node says `REQUIRED`. A\n * required table needs at least one row, the rule `validateFormRendererValues`\n * already applies, so the result agrees with the server's fill check. Never\n * mutates its input.\n */\nexport function readFillValidationSchema(\n schema: FormDefinitionSchema,\n node: UserTaskNode,\n): FormDefinitionSchema {\n const fillableKeys = readNodeFillableFieldKeys(node);\n const displaySchema = readFillDisplaySchema(schema, node);\n\n // Derived from the display schema so the check and the asterisk read the\n // same rule.\n return {\n ...displaySchema,\n fields: displaySchema.fields.filter((field) =>\n fillableKeys.has(field.fieldKey),\n ),\n };\n}\n\n/**\n * The schema the fill node's approver sees: every field as the form defines\n * it, except that the node's fillable fields are required exactly when the\n * node says `REQUIRED`, so the asterisk matches what approving will check.\n */\nexport function readFillDisplaySchema(\n schema: FormDefinitionSchema,\n node: UserTaskNode,\n): FormDefinitionSchema {\n const fillableKeys = readNodeFillableFieldKeys(node);\n const requiredKeys = readNodeRequiredFieldKeys(node);\n\n return {\n ...schema,\n fields: schema.fields.map((field) =>\n fillableKeys.has(field.fieldKey)\n ? {\n ...field,\n required: requiredKeys.has(field.fieldKey),\n // The node alone decides; the server ignores the form's rule.\n requiredWhen: undefined,\n }\n : field,\n ),\n };\n}\n\nconst userTaskNodes = (definition: WorkflowDefinition): readonly UserTaskNode[] =>\n definition.nodes.filter(\n (node): node is UserTaskNode => node.type === 'userTask',\n );\n\n/**\n * The marker shown after each approver-filled field's label: 「本關補填」 on\n * the fields `viewerFillNode` lets the viewer fill, 「<node>補填」 on every\n * other approver-filled field (the first node in the definition that fills\n * it names it).\n */\nexport function readFillLabelMarkers(\n definition: WorkflowDefinition,\n viewerFillNode: UserTaskNode | null,\n): Readonly<Record<string, string>> {\n const viewerKeys =\n viewerFillNode === null\n ? new Set<string>()\n : readNodeFillableFieldKeys(viewerFillNode);\n\n return userTaskNodes(definition).reduce<Readonly<Record<string, string>>>(\n (markers, node) => ({\n ...Object.fromEntries(\n [...readNodeFillableFieldKeys(node)].map((fieldKey) => [\n fieldKey,\n viewerKeys.has(fieldKey)\n ? '本關補填'\n : `${node.data.label || node.id}補填`,\n ]),\n ),\n ...markers,\n }),\n {},\n );\n}\n\n/**\n * What approving sends as `fill.formData`: the keys of `values` that `node`\n * lets its approver fill, and nothing else (the server refuses any other key).\n * `values` is what the approver changed, not the rendered form — a renderer\n * default the approver never touched (a table's empty rows, a boolean's\n * `false`) is not theirs to sign, and would otherwise show up as filled in.\n */\nexport function readFillPayload(\n values: WorkflowFormData,\n node: UserTaskNode,\n): Readonly<Record<string, unknown>> {\n return Object.fromEntries(\n [...readNodeFillableFieldKeys(node)]\n .filter((fieldKey) =>\n Object.prototype.hasOwnProperty.call(values, fieldKey),\n )\n // A cleared field reads `undefined`, which JSON drops, and the server\n // would keep the old value; `null` clears it.\n .map((fieldKey) => [fieldKey, values[fieldKey] ?? null]),\n );\n}\n\n/**\n * What the approver's fill amounts to: the fields they changed (`draft`), plus\n * each fill table the page seeds with `minRows` rows that the case does not\n * store yet. The page shows those rows and validates them, so they are sent\n * too — left out, the server would refuse the approval for missing rows the\n * approver can see on screen.\n */\nexport function readFillChanges({\n draft,\n node,\n schema,\n stored,\n values,\n}: {\n readonly draft: WorkflowFormData;\n readonly node: UserTaskNode;\n readonly schema: FormDefinitionSchema;\n readonly stored: WorkflowFormData;\n readonly values: WorkflowFormData;\n}): WorkflowFormData {\n const fillableKeys = readNodeFillableFieldKeys(node);\n const seededTables = schema.fields.filter((field) => {\n const seeded = values[field.fieldKey];\n\n return (\n isTableFieldDefinition(field) &&\n fillableKeys.has(field.fieldKey) &&\n !Object.prototype.hasOwnProperty.call(stored, field.fieldKey) &&\n Array.isArray(seeded) &&\n seeded.length > 0\n );\n });\n\n return {\n ...Object.fromEntries(\n seededTables.map((field) => [field.fieldKey, values[field.fieldKey]]),\n ),\n ...draft,\n };\n}\n\n/** The server message of a fill against form data someone else changed. */\nexport function isFillConflictMessage(message: string): boolean {\n return message.includes('form data changed; refresh and retry');\n}\n\n// The server names a field by its label: `欄位「標籤」`, a table row as\n// `「表格」第 N 列` (1-based), and a cell as `「表格」第 N 列的「欄位」`.\n// Each part of a message is separated by `;`. This is the fallback for a\n// response that carries no `formDataIssues`: labels are not unique, so the\n// issues, which address each value by its path, are the primary route.\nconst TOP_LEVEL_REF_PATTERN = /^欄位「(.+?)」(.+)$/;\nconst TABLE_REF_PATTERN = /^「(.+?)」第 (\\d+) 列(?:的「(.+?)」)?(.+)$/;\nconst MISSING_FIELDS_PREFIX = '缺少必填欄位:';\n\n/** The field, or table column, a server error names, with its renderer key. */\ninterface FillErrorTarget {\n readonly key: string;\n readonly settings: FormFieldDefinition | TableColumnDefinition | undefined;\n readonly topLevel: boolean;\n}\n\n/** The sentence a refused value shows, by its reason. */\nfunction readFillIssueText(\n reason: FormDataIssueReason,\n limit: number | undefined,\n target: FillErrorTarget,\n): string {\n const name = target.settings?.label || target.settings?.fieldKey || '';\n\n switch (reason) {\n case 'REQUIRED':\n return target.topLevel && name !== ''\n ? `${name}為必填欄位。`\n : '此欄為必填。';\n case 'MIN_LENGTH':\n return `至少需要 ${limit ?? 0} 個字。`;\n case 'MAX_LENGTH':\n return `最多 ${limit ?? 0} 個字。`;\n case 'MIN_ROWS':\n return `至少需要 ${limit ?? 0} 列。`;\n case 'MAX_ROWS':\n return `最多 ${limit ?? 0} 列。`;\n case 'MAX_FILES':\n return `最多 ${limit ?? 0} 個檔案。`;\n case 'PATTERN': {\n const message =\n target.settings &&\n (target.settings.type === 'text' || target.settings.type === 'textarea')\n ? target.settings.patternErrorMessage?.trim()\n : undefined;\n\n return message || '格式不正確。';\n }\n // The server ran out of time on the format check; the value may be fine.\n case 'PATTERN_TIMEOUT':\n return '格式檢查逾時,請縮短內容後再試,或請表單設計者簡化格式。';\n default:\n return '此欄內容不正確。';\n }\n}\n\n/** The reason a message sentence stands for, for the message fallback. */\nfunction readFillReasonFromSentence(sentence: string): {\n readonly limit?: number;\n readonly reason: FormDataIssueReason;\n} {\n const atLeastRows = /^至少需要 (\\d+) 列$/.exec(sentence);\n const atMostRows = /^最多 (\\d+) 列$/.exec(sentence);\n const shortest = /^至少需要 (\\d+) 個字$/.exec(sentence);\n const longest = /^最多 (\\d+) 個字$/.exec(sentence);\n const mostFiles = /^最多 (\\d+) 個檔案$/.exec(sentence);\n\n if (sentence === '為必填') {\n return { reason: 'REQUIRED' };\n }\n\n if (atLeastRows) {\n return { limit: Number(atLeastRows[1]), reason: 'MIN_ROWS' };\n }\n\n if (atMostRows) {\n return { limit: Number(atMostRows[1]), reason: 'MAX_ROWS' };\n }\n\n if (shortest) {\n return { limit: Number(shortest[1]), reason: 'MIN_LENGTH' };\n }\n\n if (longest) {\n return { limit: Number(longest[1]), reason: 'MAX_LENGTH' };\n }\n\n if (mostFiles) {\n return { limit: Number(mostFiles[1]), reason: 'MAX_FILES' };\n }\n\n if (sentence === '格式不正確') {\n return { reason: 'PATTERN' };\n }\n\n if (sentence === '無法在時限內完成格式檢查') {\n return { reason: 'PATTERN_TIMEOUT' };\n }\n\n return { reason: 'TYPE' };\n}\n\n/**\n * The renderer key of the value an issue path addresses, among the fields\n * `fields` lets the approver fill. `items` is a table, `items[1]` a row,\n * `items[1].qty` a cell. `null` when the path names nothing fillable.\n */\nfunction readFillIssueTarget(\n path: string,\n fields: readonly FormFieldDefinition[],\n): FillErrorTarget | null {\n const field = fields.find(\n (candidate) =>\n path === candidate.fieldKey ||\n (isTableFieldDefinition(candidate) &&\n path.startsWith(`${candidate.fieldKey}[`)),\n );\n\n if (!field) {\n return null;\n }\n\n if (path === field.fieldKey) {\n return { key: path, settings: field, topLevel: true };\n }\n\n if (!isTableFieldDefinition(field)) {\n return null;\n }\n\n const rowPath = /^\\[(\\d+)\\](?:\\.(.+))?$/u.exec(\n path.slice(field.fieldKey.length),\n );\n\n if (!rowPath) {\n return null;\n }\n\n const rowKey = `${field.fieldKey}[${rowPath[1]}]`;\n const columnKey = rowPath[2];\n\n if (columnKey === undefined) {\n return { key: rowKey, settings: undefined, topLevel: false };\n }\n\n const column = field.columns.find(\n (candidate) => candidate.fieldKey === columnKey,\n );\n\n return column\n ? { key: `${rowKey}.${column.fieldKey}`, settings: column, topLevel: false }\n : null;\n}\n\nfunction readFillErrorsFromIssues(\n issues: readonly FormDataIssue[],\n fields: readonly FormFieldDefinition[],\n): Readonly<Record<string, string>> | null {\n const entries = issues.map((issue): readonly [string, string] | null => {\n const target = readFillIssueTarget(issue.path, fields);\n\n return target === null\n ? null\n : [target.key, readFillIssueText(issue.reason, issue.limit, target)];\n });\n\n if (entries.length === 0 || entries.some((entry) => entry === null)) {\n return null;\n }\n\n return Object.fromEntries(\n entries.filter(\n (entry): entry is readonly [string, string] => entry !== null,\n ),\n );\n}\n\nfunction readFillErrorTarget(\n part: string,\n fields: readonly FormFieldDefinition[],\n): { readonly target: FillErrorTarget; readonly reason: string } | null {\n const topLevel = TOP_LEVEL_REF_PATTERN.exec(part);\n\n if (topLevel) {\n const field = fields.find(\n (candidate) => (candidate.label || candidate.fieldKey) === topLevel[1],\n );\n\n return field\n ? {\n reason: topLevel[2],\n target: { key: field.fieldKey, settings: field, topLevel: true },\n }\n : null;\n }\n\n const tableRef = TABLE_REF_PATTERN.exec(part);\n\n if (!tableRef) {\n return null;\n }\n\n const table = fields.find(\n (candidate) =>\n isTableFieldDefinition(candidate) &&\n (candidate.label || candidate.fieldKey) === tableRef[1],\n );\n\n if (!table || !isTableFieldDefinition(table)) {\n return null;\n }\n\n const rowKey = `${table.fieldKey}[${Number(tableRef[2]) - 1}]`;\n const columnLabel = tableRef[3];\n\n if (columnLabel === undefined) {\n return {\n reason: tableRef[4],\n target: { key: rowKey, settings: undefined, topLevel: false },\n };\n }\n\n const column = table.columns.find(\n (candidate) => (candidate.label || candidate.fieldKey) === columnLabel,\n );\n\n return column\n ? {\n reason: tableRef[4],\n target: {\n key: `${rowKey}.${column.fieldKey}`,\n settings: column,\n topLevel: false,\n },\n }\n : null;\n}\n\n/**\n * Turns the server's fill validation refusal (docs/08 §8.5, error table 2)\n * into field errors keyed the way `FormRenderer` addresses them, so a check\n * the page missed still lands on the field. `formDataIssues` is the refusal's\n * structured list and wins when it is present: each issue names its value by\n * path, so two fields sharing a label stay apart. Without it, the Chinese\n * `message` is parsed. `null` when any part does not resolve to a fillable\n * field — the caller then shows the message as it is.\n */\nexport function readFillServerErrors(\n message: string,\n schema: FormDefinitionSchema,\n node: UserTaskNode,\n formDataIssues: readonly FormDataIssue[] = [],\n): Readonly<Record<string, string>> | null {\n const fillableFields = schema.fields.filter((field) =>\n readNodeFillableFieldKeys(node).has(field.fieldKey),\n );\n\n if (formDataIssues.length > 0) {\n return readFillErrorsFromIssues(formDataIssues, fillableFields);\n }\n\n if (message.startsWith(MISSING_FIELDS_PREFIX)) {\n // Labels may hold commas, so match each fillable field's label (or key)\n // against the list rather than splitting it.\n const listed = `, ${message.slice(MISSING_FIELDS_PREFIX.length)}, `;\n const missing = fillableFields.filter((field) =>\n listed.includes(`, ${field.label || field.fieldKey}, `),\n );\n\n return missing.length > 0\n ? Object.fromEntries(\n missing.map((field) => [\n field.fieldKey,\n `${field.label || field.fieldKey}為必填欄位。`,\n ]),\n )\n : null;\n }\n\n const parts = message\n .split(';')\n .map((part) => readFillErrorTarget(part, fillableFields));\n\n if (parts.length === 0 || parts.some((part) => part === null)) {\n return null;\n }\n\n return Object.fromEntries(\n parts.flatMap((part) => {\n if (part === null) {\n return [];\n }\n\n const { limit, reason } = readFillReasonFromSentence(part.reason);\n\n return [[part.target.key, readFillIssueText(reason, limit, part.target)]];\n }),\n );\n}\n\nexport interface FillSummaryItem {\n readonly fieldKey: string;\n readonly label: string;\n readonly text: string;\n}\n\nexport const UNKNOWN_FILL_ORG_UNIT_TEXT = '未知組織';\n\n/**\n * The org unit ids among `values`, once each and in form order, so the caller\n * can look up their names before building the summary.\n */\nexport function readFillOrgUnitIds(\n schema: FormDefinitionSchema,\n values: WorkflowFormData,\n): readonly string[] {\n return [\n ...new Set(\n schema.fields\n .filter(isOrgUnitFieldDefinition)\n .map((field) => values[field.fieldKey])\n .filter(\n (value): value is string =>\n typeof value === 'string' && value.trim().length > 0,\n ),\n ),\n ];\n}\n\nfunction readFillValueText(\n field: FormFieldDefinition,\n value: FormFieldValue | undefined,\n memberNames: ReadonlyMap<string, string>,\n orgUnitNames: ReadonlyMap<string, string>,\n): string {\n if (isTableFieldDefinition(field)) {\n const rows = readFormTableRows(value);\n const totals = field.columns\n .filter((column) => column.type === 'number' || column.type === 'money')\n .map((column) => ({\n label: column.label || column.fieldKey,\n total: rows.reduce(\n (sum, row) =>\n typeof row[column.fieldKey] === 'number' &&\n Number.isFinite(row[column.fieldKey])\n ? sum + (row[column.fieldKey] as number)\n : sum,\n 0,\n ),\n }));\n\n return [\n `${rows.length} 列`,\n ...(rows.length > 0\n ? totals.map(\n ({ label, total }) => `${label}合計 ${total.toLocaleString('zh-TW')}`,\n )\n : []),\n ].join(',');\n }\n\n if (isFormDataValueEmpty(value)) {\n return '未填寫';\n }\n\n if (typeof value === 'boolean') {\n return value ? '是' : '否';\n }\n\n if (isOrgUnitFieldDefinition(field)) {\n // `orgUnitNames` (`useOrgUnitNames`) maps an id still being looked up to\n // a loading text; an id the lookup did not name is 「未知組織」. Never the\n // raw id.\n return typeof value === 'string'\n ? (orgUnitNames.get(value) ?? UNKNOWN_FILL_ORG_UNIT_TEXT)\n : UNKNOWN_FILL_ORG_UNIT_TEXT;\n }\n\n const items = Array.isArray(value) ? value : [value];\n const optionLabels = isFormStaticOptionFieldDefinition(field)\n ? new Map(field.options.map((option) => [option.value, option.label]))\n : field.type === 'member'\n ? memberNames\n : new Map<string, string>();\n\n return items\n .map((item) =>\n typeof item === 'string' ? (optionLabels.get(item) ?? item) : String(item),\n )\n .join('、');\n}\n\n/**\n * One line per field `node` lets its approver fill, in form order, for the\n * approve dialog: what will be sent along with the approval. A member field\n * names each member found in `memberNames` and shows the id otherwise; an org\n * unit field names its unit from `orgUnitNames` and shows 「未知組織」 otherwise.\n */\nexport function readFillSummary(\n schema: FormDefinitionSchema,\n node: UserTaskNode,\n values: WorkflowFormData,\n memberNames: ReadonlyMap<string, string> = new Map(),\n orgUnitNames: ReadonlyMap<string, string> = new Map(),\n): readonly FillSummaryItem[] {\n const fillableKeys = readNodeFillableFieldKeys(node);\n\n return schema.fields\n .filter(\n (field) =>\n fillableKeys.has(field.fieldKey) &&\n Object.prototype.hasOwnProperty.call(values, field.fieldKey),\n )\n .map((field) => ({\n fieldKey: field.fieldKey,\n label: field.label || field.fieldKey,\n text: readFillValueText(\n field,\n values[field.fieldKey],\n memberNames,\n orgUnitNames,\n ),\n }));\n}\n","import { readFormDataSourceErrorMessage } from '@rytass/bpm-core-client/form';\nimport { ATTACHMENT_NOT_BINDABLE_ERROR_CODE } from '@rytass/bpm-core-shared/form';\n\nconst ATTACHMENT_NOT_BINDABLE_MESSAGE =\n '表單中有附件無法附加到這個案件(只能附加申請人為本案上傳的檔案),請移除後重新上傳再送出。';\n\n/**\n * The message a case page shows for a failed request: a stable server code\n * translated into words, otherwise the server's own message.\n */\nexport function readErrorMessage(error: unknown): string {\n // DataSource failures arrive as stable codes so the backend never leaks\n // upstream transport detail; translate them instead of showing the raw code.\n const dataSourceMessage = readFormDataSourceErrorMessage(error);\n\n if (dataSourceMessage) {\n return dataSourceMessage;\n }\n\n const message = error instanceof Error ? error.message : null;\n\n // Names the problem, not the attachment ids the server lists.\n if (message?.includes(ATTACHMENT_NOT_BINDABLE_ERROR_CODE)) {\n return ATTACHMENT_NOT_BINDABLE_MESSAGE;\n }\n\n return message ?? '發生未知錯誤';\n}\n"],"mappings":"A,6HA8BA,SAAgBc,EACd,EACA,EACsB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