@fluig-kit/ecm 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fluig-kit-ecm.es.js +246 -309
- package/dist/fluig-kit-ecm.umd.js +1 -26
- package/dist/index.d.ts +0 -2
- package/package.json +7 -2
package/dist/fluig-kit-ecm.es.js
CHANGED
|
@@ -1,45 +1,44 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { appendErrors as
|
|
4
|
-
import { validateFieldsNatively as X, toNestErrors as
|
|
5
|
-
import { z as
|
|
6
|
-
import { parentProxy as
|
|
7
|
-
import { DebugLogger as
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} else n[c] = { message: s, type: i };
|
|
1
|
+
import { jsx as w, jsxs as D } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as F, useState as q, useMemo as p, useCallback as E, useContext as C, useEffect as A, useRef as $ } from "react";
|
|
3
|
+
import { appendErrors as H, useWatch as K, useForm as J, FormProvider as Q, useFormContext as M } from "react-hook-form";
|
|
4
|
+
import { validateFieldsNatively as X, toNestErrors as Z } from "@hookform/resolvers";
|
|
5
|
+
import { z as ee } from "zod";
|
|
6
|
+
import { parentProxy as N, DebugLogger as b, createFluigClient as te } from "@fluig-kit/core";
|
|
7
|
+
import { DebugLogger as Le, createFluigClient as qe, parentProxy as Me } from "@fluig-kit/core";
|
|
8
|
+
var ne = function(e, n) {
|
|
9
|
+
for (var t = {}; e.length; ) {
|
|
10
|
+
var r = e[0], i = r.code, a = r.message, c = r.path.join(".");
|
|
11
|
+
if (!t[c]) if ("unionErrors" in r) {
|
|
12
|
+
var s = r.unionErrors[0].errors[0];
|
|
13
|
+
t[c] = { message: s.message, type: s.code };
|
|
14
|
+
} else t[c] = { message: a, type: i };
|
|
16
15
|
if ("unionErrors" in r && r.unionErrors.forEach(function(f) {
|
|
17
16
|
return f.errors.forEach(function(d) {
|
|
18
17
|
return e.push(d);
|
|
19
18
|
});
|
|
20
|
-
}),
|
|
21
|
-
var
|
|
22
|
-
|
|
19
|
+
}), n) {
|
|
20
|
+
var u = t[c].types, o = u && u[r.code];
|
|
21
|
+
t[c] = H(c, n, t, i, o ? [].concat(o, r.message) : r.message);
|
|
23
22
|
}
|
|
24
23
|
e.shift();
|
|
25
24
|
}
|
|
26
|
-
return
|
|
27
|
-
},
|
|
28
|
-
return
|
|
25
|
+
return t;
|
|
26
|
+
}, re = function(e, n, t) {
|
|
27
|
+
return t === void 0 && (t = {}), function(r, i, a) {
|
|
29
28
|
try {
|
|
30
|
-
return Promise.resolve((function(c,
|
|
29
|
+
return Promise.resolve((function(c, s) {
|
|
31
30
|
try {
|
|
32
|
-
var
|
|
33
|
-
return
|
|
31
|
+
var u = Promise.resolve(e[t.mode === "sync" ? "parse" : "parseAsync"](r, n)).then(function(o) {
|
|
32
|
+
return a.shouldUseNativeValidation && X({}, a), { errors: {}, values: t.raw ? r : o };
|
|
34
33
|
});
|
|
35
34
|
} catch (o) {
|
|
36
|
-
return
|
|
35
|
+
return s(o);
|
|
37
36
|
}
|
|
38
|
-
return
|
|
37
|
+
return u && u.then ? u.then(void 0, s) : u;
|
|
39
38
|
})(0, function(c) {
|
|
40
|
-
if ((function(
|
|
41
|
-
return Array.isArray(
|
|
42
|
-
})(c)) return { values: {}, errors:
|
|
39
|
+
if ((function(s) {
|
|
40
|
+
return Array.isArray(s?.errors);
|
|
41
|
+
})(c)) return { values: {}, errors: Z(ne(c.errors, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a) };
|
|
43
42
|
throw c;
|
|
44
43
|
}));
|
|
45
44
|
} catch (c) {
|
|
@@ -47,145 +46,145 @@ var re = function(e, t) {
|
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
48
|
};
|
|
50
|
-
const
|
|
49
|
+
const U = F(
|
|
51
50
|
null
|
|
52
51
|
);
|
|
53
|
-
function
|
|
52
|
+
function Fe({
|
|
54
53
|
children: e,
|
|
55
|
-
baseSchema:
|
|
54
|
+
baseSchema: n
|
|
56
55
|
}) {
|
|
57
|
-
const [
|
|
56
|
+
const [t, r] = q([]), i = p(() => n ?? ee.object({}), [n]), a = E((o, f) => {
|
|
58
57
|
r((d) => d.some((y) => y.id === o) ? d : [...d, { id: o, schema: f }]);
|
|
59
58
|
}, []), c = E((o) => {
|
|
60
59
|
r((f) => f.some((d) => d.id === o) ? f.filter((d) => d.id !== o) : f);
|
|
61
|
-
}, []),
|
|
60
|
+
}, []), s = p(() => t.length ? t.map((o) => o.schema).reduce((o, f) => o.and(f), i) : i, [t, i]), u = p(
|
|
62
61
|
() => ({
|
|
63
|
-
registerSchema:
|
|
62
|
+
registerSchema: a,
|
|
64
63
|
unregisterSchema: c,
|
|
65
|
-
mergedSchema:
|
|
64
|
+
mergedSchema: s
|
|
66
65
|
}),
|
|
67
|
-
[
|
|
66
|
+
[a, c, s]
|
|
68
67
|
);
|
|
69
|
-
return /* @__PURE__ */
|
|
68
|
+
return /* @__PURE__ */ w(U.Provider, { value: u, children: e });
|
|
70
69
|
}
|
|
71
|
-
function
|
|
72
|
-
const e =
|
|
70
|
+
function Y() {
|
|
71
|
+
const e = C(U);
|
|
73
72
|
if (!e)
|
|
74
73
|
throw new Error(
|
|
75
74
|
"useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>"
|
|
76
75
|
);
|
|
77
76
|
return e;
|
|
78
77
|
}
|
|
79
|
-
function
|
|
78
|
+
function L(e) {
|
|
80
79
|
return typeof e == "number" ? e : isNaN(Number(e)) ? null : Number(e);
|
|
81
80
|
}
|
|
82
|
-
function
|
|
81
|
+
function O(e, n, t) {
|
|
83
82
|
if (!e) return !0;
|
|
84
|
-
const r = Array.isArray(
|
|
85
|
-
return e.hasValue !== void 0 ? e.hasValue ?
|
|
83
|
+
const r = Array.isArray(n) ? n[0] : n, i = e.field ?? r, a = t?.[i];
|
|
84
|
+
return e.hasValue !== void 0 ? e.hasValue ? a != null && a !== "" : a == null || a === "" : e.equals !== void 0 ? a === e.equals : e.notEquals !== void 0 ? a !== e.notEquals : !0;
|
|
86
85
|
}
|
|
87
|
-
function
|
|
88
|
-
const
|
|
89
|
-
return
|
|
90
|
-
if (
|
|
91
|
-
const o = Array.isArray(
|
|
86
|
+
function oe(e, n, t, r, i) {
|
|
87
|
+
const a = new Set(e), c = new Set(n);
|
|
88
|
+
return t?.forEach((s) => {
|
|
89
|
+
if (s.from !== void 0) {
|
|
90
|
+
const o = Array.isArray(s.from) ? s.from : [s.from];
|
|
92
91
|
if (r === null || !o.includes(r)) return;
|
|
93
92
|
}
|
|
94
|
-
if (!
|
|
95
|
-
const
|
|
96
|
-
switch (
|
|
93
|
+
if (!O(s.when, s.target, i)) return;
|
|
94
|
+
const u = Array.isArray(s.target) ? s.target : [s.target];
|
|
95
|
+
switch (s.type) {
|
|
97
96
|
case "readonly":
|
|
98
|
-
|
|
99
|
-
c.add(o),
|
|
97
|
+
u.forEach((o) => {
|
|
98
|
+
c.add(o), a.delete(o);
|
|
100
99
|
});
|
|
101
100
|
break;
|
|
102
101
|
case "active":
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
u.forEach((o) => {
|
|
103
|
+
a.add(o), c.delete(o);
|
|
105
104
|
});
|
|
106
105
|
break;
|
|
107
106
|
case "hidden":
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
u.forEach((o) => {
|
|
108
|
+
a.delete(o), c.delete(o);
|
|
110
109
|
});
|
|
111
110
|
break;
|
|
112
111
|
}
|
|
113
|
-
}), { active: Array.from(
|
|
112
|
+
}), { active: Array.from(a), readonly: Array.from(c) };
|
|
114
113
|
}
|
|
115
|
-
function
|
|
116
|
-
const i = new Set(e.active),
|
|
117
|
-
return
|
|
118
|
-
if (
|
|
119
|
-
const o = Array.isArray(
|
|
120
|
-
if (
|
|
114
|
+
function ie(e, n, t, r) {
|
|
115
|
+
const i = new Set(e.active), a = new Set(e.readonly), c = new Set(e.hidden ?? []);
|
|
116
|
+
return n?.forEach((s) => {
|
|
117
|
+
if (s.from !== void 0) {
|
|
118
|
+
const o = Array.isArray(s.from) ? s.from : [s.from];
|
|
119
|
+
if (t === null || !o.includes(t)) return;
|
|
121
120
|
}
|
|
122
|
-
if (!
|
|
123
|
-
const
|
|
124
|
-
switch (
|
|
121
|
+
if (!O(s.when, s.target, r)) return;
|
|
122
|
+
const u = Array.isArray(s.target) ? s.target : [s.target];
|
|
123
|
+
switch (s.type) {
|
|
125
124
|
case "hidden":
|
|
126
|
-
|
|
127
|
-
c.add(o), i.delete(o),
|
|
125
|
+
u.forEach((o) => {
|
|
126
|
+
c.add(o), i.delete(o), a.delete(o);
|
|
128
127
|
});
|
|
129
128
|
break;
|
|
130
129
|
case "active":
|
|
131
|
-
|
|
132
|
-
i.add(o),
|
|
130
|
+
u.forEach((o) => {
|
|
131
|
+
i.add(o), a.delete(o), c.delete(o);
|
|
133
132
|
});
|
|
134
133
|
break;
|
|
135
134
|
case "readonly":
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
u.forEach((o) => {
|
|
136
|
+
a.add(o), i.delete(o), c.delete(o);
|
|
138
137
|
});
|
|
139
138
|
break;
|
|
140
139
|
}
|
|
141
140
|
}), {
|
|
142
141
|
active: Array.from(i),
|
|
143
|
-
readonly: Array.from(
|
|
142
|
+
readonly: Array.from(a),
|
|
144
143
|
hidden: Array.from(c)
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
|
-
function se(e,
|
|
148
|
-
if (!e?.length) return
|
|
149
|
-
const
|
|
146
|
+
function se(e, n) {
|
|
147
|
+
if (!e?.length) return n;
|
|
148
|
+
const t = new Map(n.map((i) => [i.name, i])), r = [];
|
|
150
149
|
return e.forEach((i) => {
|
|
151
|
-
|
|
152
|
-
}),
|
|
150
|
+
t.has(i) && (r.push(t.get(i)), t.delete(i));
|
|
151
|
+
}), t.forEach((i) => r.push(i)), r;
|
|
153
152
|
}
|
|
154
|
-
function
|
|
155
|
-
const
|
|
153
|
+
function ae(e) {
|
|
154
|
+
const n = /* @__PURE__ */ new Set(), t = (r = []) => {
|
|
156
155
|
r.forEach((i) => {
|
|
157
|
-
i.target && (Array.isArray(i.target) ? i.target : [i.target]).forEach((c) =>
|
|
156
|
+
i.target && (Array.isArray(i.target) ? i.target : [i.target]).forEach((c) => n.add(c)), i.when?.field && n.add(i.when.field);
|
|
158
157
|
});
|
|
159
158
|
};
|
|
160
|
-
return
|
|
159
|
+
return t(e?.fields?.rules), t(e?.sections?.rules), Array.from(n);
|
|
161
160
|
}
|
|
162
|
-
function
|
|
161
|
+
function ce({
|
|
163
162
|
activityId: e,
|
|
164
|
-
previousActivityId:
|
|
165
|
-
control:
|
|
163
|
+
previousActivityId: n,
|
|
164
|
+
control: t,
|
|
166
165
|
workflowStructure: r,
|
|
167
166
|
sectionsRegistry: i
|
|
168
167
|
}) {
|
|
169
|
-
const { registerSchema:
|
|
170
|
-
control:
|
|
168
|
+
const { registerSchema: a, unregisterSchema: c } = Y(), s = L(e), u = L(n), o = s !== null ? r[s] : null, f = p(() => ae(o), [s, o]), d = K({
|
|
169
|
+
control: t,
|
|
171
170
|
name: f,
|
|
172
171
|
defaultValue: {}
|
|
173
|
-
}), y =
|
|
172
|
+
}), y = p(() => {
|
|
174
173
|
const v = {};
|
|
175
|
-
return f.forEach((m,
|
|
176
|
-
v[m] = Array.isArray(d) ? d[
|
|
174
|
+
return f.forEach((m, g) => {
|
|
175
|
+
v[m] = Array.isArray(d) ? d[g] : d;
|
|
177
176
|
}), v;
|
|
178
|
-
}, [d, f]),
|
|
177
|
+
}, [d, f]), l = p(() => {
|
|
179
178
|
if (!o)
|
|
180
179
|
return {
|
|
181
180
|
sections: [],
|
|
182
181
|
fields: { active: [], readonly: [], hidden: [] }
|
|
183
182
|
};
|
|
184
|
-
const v =
|
|
183
|
+
const v = oe(
|
|
185
184
|
o.sections.active,
|
|
186
185
|
o.sections.readonly,
|
|
187
186
|
o.sections.rules,
|
|
188
|
-
|
|
187
|
+
u,
|
|
189
188
|
y
|
|
190
189
|
);
|
|
191
190
|
let m = [
|
|
@@ -199,71 +198,71 @@ function le({
|
|
|
199
198
|
}))
|
|
200
199
|
];
|
|
201
200
|
m = se(o.sections.order, m);
|
|
202
|
-
const
|
|
201
|
+
const g = ie(
|
|
203
202
|
{
|
|
204
203
|
active: o.fields.active,
|
|
205
204
|
readonly: o.fields.readonly,
|
|
206
205
|
hidden: o.fields.hidden
|
|
207
206
|
},
|
|
208
207
|
o.fields.rules,
|
|
209
|
-
|
|
208
|
+
u,
|
|
210
209
|
y
|
|
211
210
|
);
|
|
212
|
-
return { sections: m, fields:
|
|
213
|
-
}, [o,
|
|
211
|
+
return { sections: m, fields: g };
|
|
212
|
+
}, [o, u, y, i]);
|
|
214
213
|
return A(() => {
|
|
215
|
-
const v =
|
|
214
|
+
const v = l.sections.filter((m) => m.mode === "active").map((m) => m.name);
|
|
216
215
|
v.forEach((m) => {
|
|
217
|
-
const
|
|
218
|
-
|
|
216
|
+
const g = i?.[m]?.schema;
|
|
217
|
+
g && a(m, g);
|
|
219
218
|
}), Object.keys(i ?? {}).filter((m) => !v.includes(m)).forEach(c);
|
|
220
|
-
}, [
|
|
219
|
+
}, [l.sections, i, a, c]), l;
|
|
221
220
|
}
|
|
222
221
|
function ue() {
|
|
223
222
|
if (typeof document > "u") return {};
|
|
224
223
|
const e = {};
|
|
225
|
-
return document.querySelectorAll("input[type='radio'][name]").forEach((
|
|
226
|
-
const
|
|
227
|
-
r &&
|
|
228
|
-
}), document.querySelectorAll("input[name], textarea[name], select[name]").forEach((
|
|
229
|
-
const
|
|
224
|
+
return document.querySelectorAll("input[type='radio'][name]").forEach((n) => {
|
|
225
|
+
const t = n, r = t.getAttribute("name");
|
|
226
|
+
r && t.checked && (e[r] = t.value);
|
|
227
|
+
}), document.querySelectorAll("input[name], textarea[name], select[name]").forEach((n) => {
|
|
228
|
+
const t = n, r = t.getAttribute("name");
|
|
230
229
|
if (!r || e[r] !== void 0) return;
|
|
231
|
-
const i =
|
|
230
|
+
const i = t.getAttribute("value") ?? t.value ?? t.textContent ?? "";
|
|
232
231
|
e[r] = String(i).trim();
|
|
233
|
-
}), document.querySelectorAll("span[name]").forEach((
|
|
234
|
-
const
|
|
232
|
+
}), document.querySelectorAll("span[name]").forEach((n) => {
|
|
233
|
+
const t = n, r = t.getAttribute("name");
|
|
235
234
|
if (r) {
|
|
236
|
-
const i =
|
|
235
|
+
const i = t.textContent?.trim() ?? "";
|
|
237
236
|
i !== "" && (e[r] = i);
|
|
238
237
|
}
|
|
239
238
|
}), e;
|
|
240
239
|
}
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
245
|
-
const
|
|
246
|
-
return
|
|
240
|
+
const _ = () => typeof window > "u" ? null : new URLSearchParams(window.location.search).get("edit"), le = () => typeof window > "u" || !window.top ? null : window.top.ECM?.workflowView ? "process" : "document", de = () => {
|
|
241
|
+
if (le() === "process") {
|
|
242
|
+
const n = window.top?.ECM?.workflowView;
|
|
243
|
+
if (!n) return !1;
|
|
244
|
+
const t = n.newRequest ?? n.isNewRequest, r = n.colleagueLogin;
|
|
245
|
+
return t === !0 || !!r && r.trim() !== "";
|
|
247
246
|
}
|
|
248
|
-
return
|
|
249
|
-
},
|
|
250
|
-
function
|
|
247
|
+
return _() === null;
|
|
248
|
+
}, fe = () => _() === "true", W = F(null);
|
|
249
|
+
function Ce({
|
|
251
250
|
children: e,
|
|
252
|
-
devConfig:
|
|
251
|
+
devConfig: n
|
|
253
252
|
}) {
|
|
254
|
-
const [
|
|
253
|
+
const [t, r] = q(null), i = p(() => ue() ?? {}, []);
|
|
255
254
|
return A(() => {
|
|
256
|
-
let
|
|
255
|
+
let a = !0;
|
|
257
256
|
return (async () => {
|
|
258
|
-
const
|
|
257
|
+
const s = typeof window < "u" && window.location.hostname === "localhost", u = typeof window < "u" && window.self !== window.top;
|
|
259
258
|
let o = null;
|
|
260
259
|
try {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
} catch (
|
|
264
|
-
console.warn("[FluigRuntime] Falha ao detectar atividade:",
|
|
260
|
+
const l = await N.top.ECM.workflowView.sequence;
|
|
261
|
+
l != null && (o = Number(l), n?.showDebugLogs && console.log("[FluigRuntime] Atividade:", o));
|
|
262
|
+
} catch (l) {
|
|
263
|
+
console.warn("[FluigRuntime] Falha ao detectar atividade:", l);
|
|
265
264
|
}
|
|
266
|
-
const f = !
|
|
265
|
+
const f = !s && u && !(de() || fe()), d = {
|
|
267
266
|
isView: f,
|
|
268
267
|
isReadOnly: f,
|
|
269
268
|
activityId: o,
|
|
@@ -275,42 +274,42 @@ function ke({
|
|
|
275
274
|
isDev: !1
|
|
276
275
|
};
|
|
277
276
|
let y = d;
|
|
278
|
-
if (
|
|
279
|
-
const
|
|
277
|
+
if (n?.enabled) {
|
|
278
|
+
const l = n.isView ?? d.isView;
|
|
280
279
|
y = {
|
|
281
280
|
...d,
|
|
282
|
-
...
|
|
283
|
-
isView:
|
|
284
|
-
isReadOnly:
|
|
281
|
+
...n,
|
|
282
|
+
isView: l,
|
|
283
|
+
isReadOnly: l,
|
|
285
284
|
isDev: !0,
|
|
286
285
|
// Se devConfig tiver activityId definido explicitamente, usa ele.
|
|
287
286
|
// Se não, mantém o detectado (permite usar devConfig só para logs, por exemplo)
|
|
288
|
-
activityId:
|
|
287
|
+
activityId: n.activityId !== void 0 ? n.activityId : o
|
|
289
288
|
};
|
|
290
289
|
}
|
|
291
|
-
typeof window < "u" && (window.__FLUIG_DEBUG_ENABLED__ = y.showDebugLogs), y.showDebugLogs &&
|
|
290
|
+
typeof window < "u" && (window.__FLUIG_DEBUG_ENABLED__ = y.showDebugLogs), y.showDebugLogs && a && (b.header("Runtime Initialized"), b.table("State", {
|
|
292
291
|
"Detected Activity": o,
|
|
293
292
|
"Final Activity": y.activityId,
|
|
294
293
|
"Dev Mode": y.isDev
|
|
295
|
-
}), b.end()),
|
|
294
|
+
}), b.end()), a && r(y);
|
|
296
295
|
})(), () => {
|
|
297
|
-
|
|
296
|
+
a = !1;
|
|
298
297
|
};
|
|
299
|
-
}, [
|
|
298
|
+
}, [n, i]), t ? /* @__PURE__ */ w(W.Provider, { value: t, children: e }) : null;
|
|
300
299
|
}
|
|
301
|
-
function
|
|
302
|
-
const e =
|
|
300
|
+
function x() {
|
|
301
|
+
const e = C(W);
|
|
303
302
|
if (!e)
|
|
304
303
|
throw new Error(
|
|
305
304
|
"useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>"
|
|
306
305
|
);
|
|
307
306
|
return e;
|
|
308
307
|
}
|
|
309
|
-
function
|
|
310
|
-
const { activityId:
|
|
308
|
+
function me(e) {
|
|
309
|
+
const { activityId: n, previousActivityId: t } = x();
|
|
311
310
|
A(() => {
|
|
312
|
-
|
|
313
|
-
}, [
|
|
311
|
+
n != null && e.setValue("CURRENTACTIVITYID", n), t != null && e.setValue("LASTACTIVITYID", t);
|
|
312
|
+
}, [n, t, e]), A(() => {
|
|
314
313
|
if (typeof window > "u") return;
|
|
315
314
|
const r = window.top?.document.getElementById("send-process-button") || window.parent?.document.getElementById("workflow-actions-send") || document.getElementById("send-process-button");
|
|
316
315
|
if (!r) {
|
|
@@ -337,255 +336,193 @@ function ve(e) {
|
|
|
337
336
|
};
|
|
338
337
|
}, [e]);
|
|
339
338
|
}
|
|
340
|
-
const
|
|
339
|
+
const ve = ({
|
|
341
340
|
workflowStructure: e,
|
|
342
|
-
sectionsRegistry:
|
|
343
|
-
className:
|
|
341
|
+
sectionsRegistry: n,
|
|
342
|
+
className: t
|
|
344
343
|
}) => {
|
|
345
|
-
const { control: r, handleSubmit: i, register:
|
|
344
|
+
const { control: r, handleSubmit: i, register: a, setValue: c, getValues: s } = M(), u = x(), o = $(!1);
|
|
346
345
|
A(() => {
|
|
347
|
-
o.current || (
|
|
348
|
-
}, [
|
|
349
|
-
const { sections: f, fields: d } =
|
|
346
|
+
o.current || (u.activityId != null && c("CURRENTACTIVITYID", u.activityId), u.previousActivityId != null && c("LASTACTIVITYID", u.previousActivityId), o.current = !0);
|
|
347
|
+
}, [u, c]);
|
|
348
|
+
const { sections: f, fields: d } = ce({
|
|
350
349
|
control: r,
|
|
351
|
-
activityId:
|
|
352
|
-
previousActivityId:
|
|
350
|
+
activityId: u.activityId,
|
|
351
|
+
previousActivityId: u.previousActivityId,
|
|
353
352
|
workflowStructure: e,
|
|
354
|
-
sectionsRegistry:
|
|
353
|
+
sectionsRegistry: n
|
|
355
354
|
});
|
|
356
|
-
return /* @__PURE__ */
|
|
355
|
+
return /* @__PURE__ */ D(
|
|
357
356
|
"form",
|
|
358
357
|
{
|
|
359
358
|
id: "fluig-react-form",
|
|
360
|
-
className:
|
|
361
|
-
onSubmit: i((
|
|
362
|
-
console.log("✅ [FluigWorkflowForm] Dados válidos:",
|
|
359
|
+
className: t,
|
|
360
|
+
onSubmit: i((l) => {
|
|
361
|
+
console.log("✅ [FluigWorkflowForm] Dados válidos:", l);
|
|
363
362
|
}),
|
|
364
363
|
noValidate: !0,
|
|
365
364
|
children: [
|
|
366
|
-
/* @__PURE__ */
|
|
367
|
-
/* @__PURE__ */
|
|
368
|
-
/* @__PURE__ */
|
|
365
|
+
/* @__PURE__ */ D("div", { className: "hidden", style: { display: "none" }, children: [
|
|
366
|
+
/* @__PURE__ */ w("input", { type: "hidden", ...a("CURRENTACTIVITYID") }),
|
|
367
|
+
/* @__PURE__ */ w("input", { type: "hidden", ...a("LASTACTIVITYID") })
|
|
369
368
|
] }),
|
|
370
|
-
f.length === 0 &&
|
|
369
|
+
f.length === 0 && u.activityId !== null && /* @__PURE__ */ D("p", { children: [
|
|
371
370
|
"Não foi possível encontrar a atividade: ",
|
|
372
|
-
String(
|
|
371
|
+
String(u.activityId)
|
|
373
372
|
] }),
|
|
374
|
-
f.map(({ name:
|
|
373
|
+
f.map(({ name: l, mode: v }) => {
|
|
375
374
|
if (v === "hidden") return null;
|
|
376
|
-
const m =
|
|
375
|
+
const m = n[l];
|
|
377
376
|
if (!m) return null;
|
|
378
|
-
const
|
|
379
|
-
return /* @__PURE__ */
|
|
380
|
-
|
|
377
|
+
const g = m.Component;
|
|
378
|
+
return /* @__PURE__ */ w(
|
|
379
|
+
g,
|
|
381
380
|
{
|
|
382
|
-
id:
|
|
381
|
+
id: l,
|
|
383
382
|
fields: d,
|
|
384
383
|
readOnly: v === "readonly"
|
|
385
384
|
},
|
|
386
|
-
|
|
385
|
+
l
|
|
387
386
|
);
|
|
388
387
|
}),
|
|
389
|
-
|
|
388
|
+
u.isDev && u.showDebugSubmit && /* @__PURE__ */ w("div", { style: { width: "100%", padding: "16px", paddingTop: "0" }, children: /* @__PURE__ */ w("button", { type: "submit", className: "btn btn-primary btn-lg btn-block", children: "Submit (Debug)" }) })
|
|
390
389
|
]
|
|
391
390
|
}
|
|
392
391
|
);
|
|
393
|
-
},
|
|
394
|
-
const { mergedSchema:
|
|
395
|
-
resolver:
|
|
396
|
-
defaultValues:
|
|
392
|
+
}, xe = (e) => {
|
|
393
|
+
const { mergedSchema: n } = Y(), t = x(), r = J({
|
|
394
|
+
resolver: n ? re(n) : void 0,
|
|
395
|
+
defaultValues: t.prefilledValues,
|
|
397
396
|
mode: "onBlur"
|
|
398
397
|
});
|
|
399
|
-
return
|
|
400
|
-
|
|
398
|
+
return me(r), A(() => {
|
|
399
|
+
t.showDebugLogs && (b.header("Form Initialized"), b.table(
|
|
401
400
|
"Prefilled Values (DOM Capture)",
|
|
402
|
-
|
|
401
|
+
t.prefilledValues
|
|
403
402
|
), b.info("RHF Current Values", r.getValues()), b.end());
|
|
404
|
-
}, [
|
|
403
|
+
}, [t.showDebugLogs, t.prefilledValues, r]), /* @__PURE__ */ w(Q, { ...r, children: /* @__PURE__ */ w(ve, { ...e }) });
|
|
405
404
|
};
|
|
406
|
-
async function
|
|
405
|
+
async function ye(e) {
|
|
407
406
|
if (!e)
|
|
408
407
|
return console.warn("[setFluigNextActivity] Nenhuma atividade informada."), !1;
|
|
409
|
-
const { wfView:
|
|
410
|
-
if (!
|
|
411
|
-
|
|
412
|
-
const r = Number(e), i =
|
|
413
|
-
return i ? (
|
|
408
|
+
const { wfView: n, wkfView: t } = await he();
|
|
409
|
+
if (!n || !t) return !1;
|
|
410
|
+
we(n);
|
|
411
|
+
const r = Number(e), i = ge(n, r);
|
|
412
|
+
return i ? (pe(n, t, i, r), console.log(`[setFluigNextActivity] Próxima atividade definida: ${r}`), !0) : (console.warn(`[setFluigNextActivity] Estado ${r} não encontrado nas próximas atividades disponíveis.`), console.log("Estados disponíveis:", n.availableStatesCOPY || n.availableStates), !1);
|
|
414
413
|
}
|
|
415
|
-
async function
|
|
416
|
-
const e = await
|
|
417
|
-
return !e || !
|
|
414
|
+
async function he() {
|
|
415
|
+
const e = await N.top.ECM.workflowView, n = await N.top.ECM_WKFView;
|
|
416
|
+
return !e || !n ? (console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."), {}) : { wfView: e, wkfView: n };
|
|
418
417
|
}
|
|
419
|
-
function
|
|
418
|
+
function we(e) {
|
|
420
419
|
e.availableStatesCOPY || (e.availableStatesCOPY = e.availableStates);
|
|
421
420
|
}
|
|
422
|
-
function
|
|
423
|
-
return (e.availableStatesCOPY || e.availableStates)?.find((r) => r.sequence ===
|
|
421
|
+
function ge(e, n) {
|
|
422
|
+
return (e.availableStatesCOPY || e.availableStates)?.find((r) => r.sequence === n);
|
|
424
423
|
}
|
|
425
|
-
function
|
|
426
|
-
e.availableUsers.users = [], e.availableStates = [
|
|
424
|
+
function pe(e, n, t, r) {
|
|
425
|
+
e.availableUsers.users = [], e.availableStates = [t], n.selectActivity = () => r;
|
|
427
426
|
}
|
|
428
|
-
const
|
|
429
|
-
function
|
|
430
|
-
const e =
|
|
427
|
+
const B = F(null);
|
|
428
|
+
function Re() {
|
|
429
|
+
const e = C(B);
|
|
431
430
|
if (!e)
|
|
432
431
|
throw new Error(
|
|
433
432
|
"useSection deve ser usado dentro de um componente <Section>"
|
|
434
433
|
);
|
|
435
434
|
return e;
|
|
436
435
|
}
|
|
437
|
-
function
|
|
436
|
+
function De({
|
|
438
437
|
id: e,
|
|
439
|
-
className:
|
|
440
|
-
schema:
|
|
438
|
+
className: n,
|
|
439
|
+
schema: t,
|
|
441
440
|
children: r,
|
|
442
441
|
form: i,
|
|
443
|
-
prefilledValues:
|
|
442
|
+
prefilledValues: a,
|
|
444
443
|
readOnly: c,
|
|
445
|
-
fields:
|
|
446
|
-
hidden:
|
|
444
|
+
fields: s = {},
|
|
445
|
+
hidden: u = !1
|
|
447
446
|
}) {
|
|
448
|
-
const { isView: o, activityId: f } =
|
|
449
|
-
if (!
|
|
447
|
+
const { isView: o, activityId: f } = x(), d = f, y = M(), l = i || y;
|
|
448
|
+
if (!l)
|
|
450
449
|
return console.error(
|
|
451
450
|
`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`
|
|
452
451
|
), null;
|
|
453
|
-
if (
|
|
452
|
+
if (u) return null;
|
|
454
453
|
const v = E(
|
|
455
|
-
(h) =>
|
|
456
|
-
[
|
|
454
|
+
(h) => s.hidden?.includes(h) ? "hidden" : s.readonly?.includes(h) ? "readonly" : s.active?.includes(h) ? "active" : c ? "readonly" : "active",
|
|
455
|
+
[s, c]
|
|
457
456
|
), m = E(
|
|
458
457
|
(h) => v(h) === "hidden",
|
|
459
458
|
[v]
|
|
460
|
-
),
|
|
459
|
+
), g = E(
|
|
461
460
|
(h) => v(h) === "readonly",
|
|
462
461
|
[v]
|
|
463
462
|
), S = E(
|
|
464
463
|
(h) => {
|
|
465
464
|
if (!h) return;
|
|
466
|
-
const I =
|
|
467
|
-
|
|
465
|
+
const I = l.getValues("CURRENTACTIVITYID");
|
|
466
|
+
l.setValue("LASTACTIVITYID", I), l.setValue("CURRENTACTIVITYID", d), ye(Number(h));
|
|
468
467
|
},
|
|
469
|
-
[
|
|
468
|
+
[l, d]
|
|
470
469
|
);
|
|
471
470
|
A(() => {
|
|
472
|
-
if (!o || !
|
|
473
|
-
const h =
|
|
474
|
-
I && Object.entries(I).forEach(([
|
|
475
|
-
let V =
|
|
471
|
+
if (!o || !a || !t || !l) return;
|
|
472
|
+
const h = l.getValues(), I = t.shape;
|
|
473
|
+
I && Object.entries(I).forEach(([T, G]) => {
|
|
474
|
+
let V = G;
|
|
476
475
|
for (; V?._def?.schema; )
|
|
477
476
|
V = V._def.schema;
|
|
478
|
-
const
|
|
479
|
-
if (
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
}),
|
|
477
|
+
const R = V?._def?.fluig;
|
|
478
|
+
if (R?.type !== "options" || !Array.isArray(R.values) || h[T] !== void 0) return;
|
|
479
|
+
const k = {};
|
|
480
|
+
R.values.forEach((P) => {
|
|
481
|
+
k[P] = a[P] === "on";
|
|
482
|
+
}), l.setValue(T, k, {
|
|
484
483
|
shouldDirty: !1,
|
|
485
484
|
shouldValidate: !1
|
|
486
485
|
});
|
|
487
486
|
});
|
|
488
|
-
}, [o,
|
|
489
|
-
const
|
|
487
|
+
}, [o, a, t, l]);
|
|
488
|
+
const z = p(
|
|
490
489
|
() => ({
|
|
491
490
|
id: e,
|
|
492
|
-
form:
|
|
491
|
+
form: l,
|
|
493
492
|
isHidden: m,
|
|
494
|
-
isReadOnly:
|
|
493
|
+
isReadOnly: g,
|
|
495
494
|
isView: o,
|
|
496
495
|
next: S,
|
|
497
496
|
wf_activity_id: d
|
|
498
497
|
}),
|
|
499
|
-
[e,
|
|
498
|
+
[e, l, m, g, o, S, d]
|
|
500
499
|
);
|
|
501
|
-
return /* @__PURE__ */
|
|
500
|
+
return /* @__PURE__ */ w(B.Provider, { value: z, children: /* @__PURE__ */ w("section", { id: e, className: [e, n].filter(Boolean).join(" "), children: r }) });
|
|
502
501
|
}
|
|
503
|
-
const
|
|
504
|
-
function
|
|
505
|
-
const
|
|
506
|
-
return /* @__PURE__ */
|
|
502
|
+
const j = F(null);
|
|
503
|
+
function Ne({ children: e, config: n }) {
|
|
504
|
+
const t = p(() => te(n), [n]);
|
|
505
|
+
return /* @__PURE__ */ w(j.Provider, { value: t, children: e });
|
|
507
506
|
}
|
|
508
|
-
function
|
|
509
|
-
const e =
|
|
507
|
+
function Te() {
|
|
508
|
+
const e = C(j);
|
|
510
509
|
if (!e)
|
|
511
510
|
throw new Error(
|
|
512
511
|
"useFluigApi deve ser usado dentro de um <FluigApiProvider>"
|
|
513
512
|
);
|
|
514
513
|
return e;
|
|
515
514
|
}
|
|
516
|
-
function Ae(e) {
|
|
517
|
-
return e._def?.schema ?? e;
|
|
518
|
-
}
|
|
519
|
-
function Se(e) {
|
|
520
|
-
let t = e._def?.fluig;
|
|
521
|
-
if (t?.values) return t.values;
|
|
522
|
-
const n = Ae(e);
|
|
523
|
-
if (n !== e && (t = n._def?.fluig, t?.values))
|
|
524
|
-
return t.values;
|
|
525
|
-
const r = n._def;
|
|
526
|
-
return (r?.meta ?? r?.metadata)?.fluig?.values ?? null;
|
|
527
|
-
}
|
|
528
|
-
function Ee(e) {
|
|
529
|
-
return e?._def?.typeName !== "ZodObject" ? [] : Object.entries(e.shape);
|
|
530
|
-
}
|
|
531
|
-
function Ie(e) {
|
|
532
|
-
const t = /* @__PURE__ */ new Set();
|
|
533
|
-
return (Array.isArray(e) ? e : Object.values(e).map((r) => r.schema).filter(Boolean)).forEach((r) => {
|
|
534
|
-
let i = r;
|
|
535
|
-
for (; i._def?.schema; )
|
|
536
|
-
i = i._def.schema;
|
|
537
|
-
i._def?.typeName === "ZodObject" && Ee(i).forEach(([s, c]) => {
|
|
538
|
-
t.add(s);
|
|
539
|
-
const a = Se(c);
|
|
540
|
-
a?.length && a.forEach((l) => t.add(l));
|
|
541
|
-
});
|
|
542
|
-
}), Array.from(t);
|
|
543
|
-
}
|
|
544
|
-
function je(e) {
|
|
545
|
-
const t = Ie(e), n = t.map(
|
|
546
|
-
(r) => `<input type="hidden" name="${r}" />`
|
|
547
|
-
).join(`
|
|
548
|
-
`);
|
|
549
|
-
return console.log(F.blue.bold(`
|
|
550
|
-
=== Inputs gerados (Build Script) ===
|
|
551
|
-
`)), t.forEach((r, i) => {
|
|
552
|
-
console.log(`${F.yellow(i + 1 + ".")} ${F.green(r)}`);
|
|
553
|
-
}), console.log(F.blue.bold(`
|
|
554
|
-
=====================================
|
|
555
|
-
`)), `<!DOCTYPE html>
|
|
556
|
-
<html lang="pt-br">
|
|
557
|
-
<head>
|
|
558
|
-
<meta charset="UTF-8">
|
|
559
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
560
|
-
<title>Workflow Fluig</title>
|
|
561
|
-
|
|
562
|
-
<link rel="stylesheet" href="/portal/style-guide/css/fluig-style-guide.min.css">
|
|
563
|
-
|
|
564
|
-
<link rel="stylesheet" crossorigin href="./main.css">
|
|
565
|
-
</head>
|
|
566
|
-
<body>
|
|
567
|
-
<form id="form" name="form">
|
|
568
|
-
<div id="root">
|
|
569
|
-
${n}
|
|
570
|
-
</div>
|
|
571
|
-
</form>
|
|
572
|
-
|
|
573
|
-
<script src="./bundle.js"><\/script>
|
|
574
|
-
</body>
|
|
575
|
-
</html>`;
|
|
576
|
-
}
|
|
577
515
|
export {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
Pe as useSection
|
|
516
|
+
Le as DebugLogger,
|
|
517
|
+
Ne as FluigApiProvider,
|
|
518
|
+
Ce as FluigRuntimeProvider,
|
|
519
|
+
xe as FluigWorkflowForm,
|
|
520
|
+
Fe as SchemaRegistryProvider,
|
|
521
|
+
De as Section,
|
|
522
|
+
qe as createFluigClient,
|
|
523
|
+
Me as parentProxy,
|
|
524
|
+
Te as useFluigApi,
|
|
525
|
+
x as useFluigRuntime,
|
|
526
|
+
Y as useSchemaRegistry,
|
|
527
|
+
Re as useSection
|
|
591
528
|
};
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
(function(f,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("react/jsx-runtime"),require("react"),require("react-hook-form"),require("@hookform/resolvers"),require("zod"),require("@fluig-kit/core"),require("chalk")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-hook-form","@hookform/resolvers","zod","@fluig-kit/core","chalk"],v):(f=typeof globalThis<"u"?globalThis:f||self,v(f.FluigKitECM={},f.jsxRuntime,f.React,f.reactHookForm,f.resolvers,f.zod,f.FluigKitCore,f.chalk))})(this,(function(f,v,c,S,k,U,p,F){"use strict";var Y=function(e,t){for(var n={};e.length;){var i=e[0],o=i.code,a=i.message,u=i.path.join(".");if(!n[u])if("unionErrors"in i){var s=i.unionErrors[0].errors[0];n[u]={message:s.message,type:s.code}}else n[u]={message:a,type:o};if("unionErrors"in i&&i.unionErrors.forEach(function(g){return g.errors.forEach(function(m){return e.push(m)})}),t){var l=n[u].types,r=l&&l[i.code];n[u]=S.appendErrors(u,t,n,o,r?[].concat(r,i.message):i.message)}e.shift()}return n},B=function(e,t,n){return n===void 0&&(n={}),function(i,o,a){try{return Promise.resolve((function(u,s){try{var l=Promise.resolve(e[n.mode==="sync"?"parse":"parseAsync"](i,t)).then(function(r){return a.shouldUseNativeValidation&&k.validateFieldsNatively({},a),{errors:{},values:n.raw?i:r}})}catch(r){return s(r)}return l&&l.then?l.then(void 0,s):l})(0,function(u){if((function(s){return Array.isArray(s?.errors)})(u))return{values:{},errors:k.toNestErrors(Y(u.errors,!a.shouldUseNativeValidation&&a.criteriaMode==="all"),a)};throw u}))}catch(u){return Promise.reject(u)}}};const P=c.createContext(null);function W({children:e,baseSchema:t}){const[n,i]=c.useState([]),o=c.useMemo(()=>t??U.z.object({}),[t]),a=c.useCallback((r,g)=>{i(m=>m.some(h=>h.id===r)?m:[...m,{id:r,schema:g}])},[]),u=c.useCallback(r=>{i(g=>g.some(m=>m.id===r)?g.filter(m=>m.id!==r):g)},[]),s=c.useMemo(()=>n.length?n.map(r=>r.schema).reduce((r,g)=>r.and(g),o):o,[n,o]),l=c.useMemo(()=>({registerSchema:a,unregisterSchema:u,mergedSchema:s}),[a,u,s]);return v.jsx(P.Provider,{value:l,children:e})}function D(){const e=c.useContext(P);if(!e)throw new Error("useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>");return e}function T(e){return typeof e=="number"?e:isNaN(Number(e))?null:Number(e)}function L(e,t,n){if(!e)return!0;const i=Array.isArray(t)?t[0]:t,o=e.field??i,a=n?.[o];return e.hasValue!==void 0?e.hasValue?a!=null&&a!=="":a==null||a==="":e.equals!==void 0?a===e.equals:e.notEquals!==void 0?a!==e.notEquals:!0}function z(e,t,n,i,o){const a=new Set(e),u=new Set(t);return n?.forEach(s=>{if(s.from!==void 0){const r=Array.isArray(s.from)?s.from:[s.from];if(i===null||!r.includes(i))return}if(!L(s.when,s.target,o))return;const l=Array.isArray(s.target)?s.target:[s.target];switch(s.type){case"readonly":l.forEach(r=>{u.add(r),a.delete(r)});break;case"active":l.forEach(r=>{a.add(r),u.delete(r)});break;case"hidden":l.forEach(r=>{a.delete(r),u.delete(r)});break}}),{active:Array.from(a),readonly:Array.from(u)}}function $(e,t,n,i){const o=new Set(e.active),a=new Set(e.readonly),u=new Set(e.hidden??[]);return t?.forEach(s=>{if(s.from!==void 0){const r=Array.isArray(s.from)?s.from:[s.from];if(n===null||!r.includes(n))return}if(!L(s.when,s.target,i))return;const l=Array.isArray(s.target)?s.target:[s.target];switch(s.type){case"hidden":l.forEach(r=>{u.add(r),o.delete(r),a.delete(r)});break;case"active":l.forEach(r=>{o.add(r),a.delete(r),u.delete(r)});break;case"readonly":l.forEach(r=>{a.add(r),o.delete(r),u.delete(r)});break}}),{active:Array.from(o),readonly:Array.from(a),hidden:Array.from(u)}}function G(e,t){if(!e?.length)return t;const n=new Map(t.map(o=>[o.name,o])),i=[];return e.forEach(o=>{n.has(o)&&(i.push(n.get(o)),n.delete(o))}),n.forEach(o=>i.push(o)),i}function K(e){const t=new Set,n=(i=[])=>{i.forEach(o=>{o.target&&(Array.isArray(o.target)?o.target:[o.target]).forEach(u=>t.add(u)),o.when?.field&&t.add(o.when.field)})};return n(e?.fields?.rules),n(e?.sections?.rules),Array.from(t)}function Z({activityId:e,previousActivityId:t,control:n,workflowStructure:i,sectionsRegistry:o}){const{registerSchema:a,unregisterSchema:u}=D(),s=T(e),l=T(t),r=s!==null?i[s]:null,g=c.useMemo(()=>K(r),[s,r]),m=S.useWatch({control:n,name:g,defaultValue:{}}),h=c.useMemo(()=>{const w={};return g.forEach((y,A)=>{w[y]=Array.isArray(m)?m[A]:m}),w},[m,g]),d=c.useMemo(()=>{if(!r)return{sections:[],fields:{active:[],readonly:[],hidden:[]}};const w=z(r.sections.active,r.sections.readonly,r.sections.rules,l,h);let y=[...w.readonly.map(E=>({name:E,mode:"readonly"})),...w.active.map(E=>({name:E,mode:"active"}))];y=G(r.sections.order,y);const A=$({active:r.fields.active,readonly:r.fields.readonly,hidden:r.fields.hidden},r.fields.rules,l,h);return{sections:y,fields:A}},[r,l,h,o]);return c.useEffect(()=>{const w=d.sections.filter(y=>y.mode==="active").map(y=>y.name);w.forEach(y=>{const A=o?.[y]?.schema;A&&a(y,A)}),Object.keys(o??{}).filter(y=>!w.includes(y)).forEach(u)},[d.sections,o,a,u]),d}function H(){if(typeof document>"u")return{};const e={};return document.querySelectorAll("input[type='radio'][name]").forEach(t=>{const n=t,i=n.getAttribute("name");i&&n.checked&&(e[i]=n.value)}),document.querySelectorAll("input[name], textarea[name], select[name]").forEach(t=>{const n=t,i=n.getAttribute("name");if(!i||e[i]!==void 0)return;const o=n.getAttribute("value")??n.value??n.textContent??"";e[i]=String(o).trim()}),document.querySelectorAll("span[name]").forEach(t=>{const n=t,i=n.getAttribute("name");if(i){const o=n.textContent?.trim()??"";o!==""&&(e[i]=o)}}),e}const N=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("edit"),J=()=>typeof window>"u"||!window.top?null:window.top.ECM?.workflowView?"process":"document",Q=()=>{if(J()==="process"){const t=window.top?.ECM?.workflowView;if(!t)return!1;const n=t.newRequest??t.isNewRequest,i=t.colleagueLogin;return n===!0||!!i&&i.trim()!==""}return N()===null},X=()=>N()==="true",R=c.createContext(null);function ee({children:e,devConfig:t}){const[n,i]=c.useState(null),o=c.useMemo(()=>H()??{},[]);return c.useEffect(()=>{let a=!0;return(async()=>{const s=typeof window<"u"&&window.location.hostname==="localhost",l=typeof window<"u"&&window.self!==window.top;let r=null;try{const d=await p.parentProxy.top.ECM.workflowView.sequence;d!=null&&(r=Number(d),t?.showDebugLogs&&console.log("[FluigRuntime] Atividade:",r))}catch(d){console.warn("[FluigRuntime] Falha ao detectar atividade:",d)}const g=!s&&l&&!(Q()||X()),m={isView:g,isReadOnly:g,activityId:r,previousActivityId:null,prefilledValues:o,showDebugSubmit:!1,showDebugLogs:!1,isDev:!1};let h=m;if(t?.enabled){const d=t.isView??m.isView;h={...m,...t,isView:d,isReadOnly:d,isDev:!0,activityId:t.activityId!==void 0?t.activityId:r}}typeof window<"u"&&(window.__FLUIG_DEBUG_ENABLED__=h.showDebugLogs),h.showDebugLogs&&a&&(p.DebugLogger.header("Runtime Initialized"),p.DebugLogger.table("State",{"Detected Activity":r,"Final Activity":h.activityId,"Dev Mode":h.isDev}),p.DebugLogger.end()),a&&i(h)})(),()=>{a=!1}},[t,o]),n?v.jsx(R.Provider,{value:n,children:e}):null}function I(){const e=c.useContext(R);if(!e)throw new Error("useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>");return e}function te(e){const{activityId:t,previousActivityId:n}=I();c.useEffect(()=>{t!=null&&e.setValue("CURRENTACTIVITYID",t),n!=null&&e.setValue("LASTACTIVITYID",n)},[t,n,e]),c.useEffect(()=>{if(typeof window>"u")return;const i=window.top?.document.getElementById("send-process-button")||window.parent?.document.getElementById("workflow-actions-send")||document.getElementById("send-process-button");if(!i){console.warn("[FluigWorkflowReact] Botão de envio do Fluig não encontrado. A validação automática pode falhar.");return}return window.beforeSendValidate=()=>(e.handleSubmit(()=>{window.beforeSendValidate=()=>!0;try{i.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}))}catch{i.click()}},o=>{console.error("[Validation Errors]",o),window.top?.FLUIGC?.toast?window.top?.FLUIGC.toast({title:"Atenção",message:"Verifique os campos obrigatórios destacados em vermelho.",type:"danger"}):alert("Verifique os campos obrigatórios.")})(),!1),()=>{}},[e])}const ne=({workflowStructure:e,sectionsRegistry:t,className:n})=>{const{control:i,handleSubmit:o,register:a,setValue:u,getValues:s}=S.useFormContext(),l=I(),r=c.useRef(!1);c.useEffect(()=>{r.current||(l.activityId!=null&&u("CURRENTACTIVITYID",l.activityId),l.previousActivityId!=null&&u("LASTACTIVITYID",l.previousActivityId),r.current=!0)},[l,u]);const{sections:g,fields:m}=Z({control:i,activityId:l.activityId,previousActivityId:l.previousActivityId,workflowStructure:e,sectionsRegistry:t}),h=d=>{console.log("✅ [FluigWorkflowForm] Dados válidos:",d)};return v.jsxs("form",{id:"fluig-react-form",className:n,onSubmit:o(h),noValidate:!0,children:[v.jsxs("div",{className:"hidden",style:{display:"none"},children:[v.jsx("input",{type:"hidden",...a("CURRENTACTIVITYID")}),v.jsx("input",{type:"hidden",...a("LASTACTIVITYID")})]}),g.length===0&&l.activityId!==null&&v.jsxs("p",{children:["Não foi possível encontrar a atividade: ",String(l.activityId)]}),g.map(({name:d,mode:w})=>{if(w==="hidden")return null;const y=t[d];if(!y)return null;const A=y.Component;return v.jsx(A,{id:d,fields:m,readOnly:w==="readonly"},d)}),l.isDev&&l.showDebugSubmit&&v.jsx("div",{style:{width:"100%",padding:"16px",paddingTop:"0"},children:v.jsx("button",{type:"submit",className:"btn btn-primary btn-lg btn-block",children:"Submit (Debug)"})})]})},ie=e=>{const{mergedSchema:t}=D(),n=I(),i=S.useForm({resolver:t?B(t):void 0,defaultValues:n.prefilledValues,mode:"onBlur"});return te(i),c.useEffect(()=>{n.showDebugLogs&&(p.DebugLogger.header("Form Initialized"),p.DebugLogger.table("Prefilled Values (DOM Capture)",n.prefilledValues),p.DebugLogger.info("RHF Current Values",i.getValues()),p.DebugLogger.end())},[n.showDebugLogs,n.prefilledValues,i]),v.jsx(S.FormProvider,{...i,children:v.jsx(ne,{...e})})};async function re(e){if(!e)return console.warn("[setFluigNextActivity] Nenhuma atividade informada."),!1;const{wfView:t,wkfView:n}=await oe();if(!t||!n)return!1;se(t);const i=Number(e),o=ae(t,i);return o?(ue(t,n,o,i),console.log(`[setFluigNextActivity] Próxima atividade definida: ${i}`),!0):(console.warn(`[setFluigNextActivity] Estado ${i} não encontrado nas próximas atividades disponíveis.`),console.log("Estados disponíveis:",t.availableStatesCOPY||t.availableStates),!1)}async function oe(){const e=await p.parentProxy.top.ECM.workflowView,t=await p.parentProxy.top.ECM_WKFView;return!e||!t?(console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."),{}):{wfView:e,wkfView:t}}function se(e){e.availableStatesCOPY||(e.availableStatesCOPY=e.availableStates)}function ae(e,t){return(e.availableStatesCOPY||e.availableStates)?.find(i=>i.sequence===t)}function ue(e,t,n,i){e.availableUsers.users=[],e.availableStates=[n],t.selectActivity=()=>i}const M=c.createContext(null);function le(){const e=c.useContext(M);if(!e)throw new Error("useSection deve ser usado dentro de um componente <Section>");return e}function ce({id:e,className:t,schema:n,children:i,form:o,prefilledValues:a,readOnly:u,fields:s={},hidden:l=!1}){const{isView:r,activityId:g}=I(),m=g,h=S.useFormContext(),d=o||h;if(!d)return console.error(`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`),null;if(l)return null;const w=c.useCallback(b=>s.hidden?.includes(b)?"hidden":s.readonly?.includes(b)?"readonly":s.active?.includes(b)?"active":u?"readonly":"active",[s,u]),y=c.useCallback(b=>w(b)==="hidden",[w]),A=c.useCallback(b=>w(b)==="readonly",[w]),E=c.useCallback(b=>{if(!b)return;const C=d.getValues("CURRENTACTIVITYID");d.setValue("LASTACTIVITYID",C),d.setValue("CURRENTACTIVITYID",m),re(Number(b))},[d,m]);c.useEffect(()=>{if(!r||!a||!n||!d)return;const b=d.getValues(),C=n.shape;C&&Object.entries(C).forEach(([O,pe])=>{let V=pe;for(;V?._def?.schema;)V=V._def.schema;const x=V?._def?.fluig;if(x?.type!=="options"||!Array.isArray(x.values)||b[O]!==void 0)return;const j={};x.values.forEach(_=>{j[_]=a[_]==="on"}),d.setValue(O,j,{shouldDirty:!1,shouldValidate:!1})})},[r,a,n,d]);const we=c.useMemo(()=>({id:e,form:d,isHidden:y,isReadOnly:A,isView:r,next:E,wf_activity_id:m}),[e,d,y,A,r,E,m]);return v.jsx(M.Provider,{value:we,children:v.jsx("section",{id:e,className:[e,t].filter(Boolean).join(" "),children:i})})}const q=c.createContext(null);function de({children:e,config:t}){const n=c.useMemo(()=>p.createFluigClient(t),[t]);return v.jsx(q.Provider,{value:n,children:e})}function fe(){const e=c.useContext(q);if(!e)throw new Error("useFluigApi deve ser usado dentro de um <FluigApiProvider>");return e}function me(e){return e._def?.schema??e}function ge(e){let t=e._def?.fluig;if(t?.values)return t.values;const n=me(e);if(n!==e&&(t=n._def?.fluig,t?.values))return t.values;const i=n._def;return(i?.meta??i?.metadata)?.fluig?.values??null}function ye(e){return e?._def?.typeName!=="ZodObject"?[]:Object.entries(e.shape)}function ve(e){const t=new Set;return(Array.isArray(e)?e:Object.values(e).map(i=>i.schema).filter(Boolean)).forEach(i=>{let o=i;for(;o._def?.schema;)o=o._def.schema;o._def?.typeName==="ZodObject"&&ye(o).forEach(([a,u])=>{t.add(a);const s=ge(u);s?.length&&s.forEach(l=>t.add(l))})}),Array.from(t)}function he(e){const t=ve(e),n=t.map(i=>`<input type="hidden" name="${i}" />`).join(`
|
|
2
|
-
`);return console.log(F.blue.bold(`
|
|
3
|
-
=== Inputs gerados (Build Script) ===
|
|
4
|
-
`)),t.forEach((i,o)=>{console.log(`${F.yellow(o+1+".")} ${F.green(i)}`)}),console.log(F.blue.bold(`
|
|
5
|
-
=====================================
|
|
6
|
-
`)),`<!DOCTYPE html>
|
|
7
|
-
<html lang="pt-br">
|
|
8
|
-
<head>
|
|
9
|
-
<meta charset="UTF-8">
|
|
10
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
11
|
-
<title>Workflow Fluig</title>
|
|
12
|
-
|
|
13
|
-
<link rel="stylesheet" href="/portal/style-guide/css/fluig-style-guide.min.css">
|
|
14
|
-
|
|
15
|
-
<link rel="stylesheet" crossorigin href="./main.css">
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
<form id="form" name="form">
|
|
19
|
-
<div id="root">
|
|
20
|
-
${n}
|
|
21
|
-
</div>
|
|
22
|
-
</form>
|
|
23
|
-
|
|
24
|
-
<script src="./bundle.js"><\/script>
|
|
25
|
-
</body>
|
|
26
|
-
</html>`}Object.defineProperty(f,"DebugLogger",{enumerable:!0,get:()=>p.DebugLogger}),Object.defineProperty(f,"createFluigClient",{enumerable:!0,get:()=>p.createFluigClient}),Object.defineProperty(f,"parentProxy",{enumerable:!0,get:()=>p.parentProxy}),f.FluigApiProvider=de,f.FluigRuntimeProvider=ee,f.FluigWorkflowForm=ie,f.SchemaRegistryProvider=W,f.Section=ce,f.generateHtmlTemplate=he,f.useFluigApi=fe,f.useFluigRuntime=I,f.useSchemaRegistry=D,f.useSection=le,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(m,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react/jsx-runtime"),require("react"),require("react-hook-form"),require("@hookform/resolvers"),require("zod"),require("@fluig-kit/core")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-hook-form","@hookform/resolvers","zod","@fluig-kit/core"],y):(m=typeof globalThis<"u"?globalThis:m||self,y(m.FluigKitECM={},m.jsxRuntime,m.React,m.reactHookForm,m.resolvers,m.zod,m.FluigKitCore))})(this,(function(m,y,c,S,D,U,p){"use strict";var Y=function(e,n){for(var t={};e.length;){var i=e[0],r=i.code,a=i.message,u=i.path.join(".");if(!t[u])if("unionErrors"in i){var s=i.unionErrors[0].errors[0];t[u]={message:s.message,type:s.code}}else t[u]={message:a,type:r};if("unionErrors"in i&&i.unionErrors.forEach(function(g){return g.errors.forEach(function(f){return e.push(f)})}),n){var l=t[u].types,o=l&&l[i.code];t[u]=S.appendErrors(u,n,t,r,o?[].concat(o,i.message):i.message)}e.shift()}return t},W=function(e,n,t){return t===void 0&&(t={}),function(i,r,a){try{return Promise.resolve((function(u,s){try{var l=Promise.resolve(e[t.mode==="sync"?"parse":"parseAsync"](i,n)).then(function(o){return a.shouldUseNativeValidation&&D.validateFieldsNatively({},a),{errors:{},values:t.raw?i:o}})}catch(o){return s(o)}return l&&l.then?l.then(void 0,s):l})(0,function(u){if((function(s){return Array.isArray(s?.errors)})(u))return{values:{},errors:D.toNestErrors(Y(u.errors,!a.shouldUseNativeValidation&&a.criteriaMode==="all"),a)};throw u}))}catch(u){return Promise.reject(u)}}};const P=c.createContext(null);function _({children:e,baseSchema:n}){const[t,i]=c.useState([]),r=c.useMemo(()=>n??U.z.object({}),[n]),a=c.useCallback((o,g)=>{i(f=>f.some(h=>h.id===o)?f:[...f,{id:o,schema:g}])},[]),u=c.useCallback(o=>{i(g=>g.some(f=>f.id===o)?g.filter(f=>f.id!==o):g)},[]),s=c.useMemo(()=>t.length?t.map(o=>o.schema).reduce((o,g)=>o.and(g),r):r,[t,r]),l=c.useMemo(()=>({registerSchema:a,unregisterSchema:u,mergedSchema:s}),[a,u,s]);return y.jsx(P.Provider,{value:l,children:e})}function F(){const e=c.useContext(P);if(!e)throw new Error("useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>");return e}function k(e){return typeof e=="number"?e:isNaN(Number(e))?null:Number(e)}function N(e,n,t){if(!e)return!0;const i=Array.isArray(n)?n[0]:n,r=e.field??i,a=t?.[r];return e.hasValue!==void 0?e.hasValue?a!=null&&a!=="":a==null||a==="":e.equals!==void 0?a===e.equals:e.notEquals!==void 0?a!==e.notEquals:!0}function B(e,n,t,i,r){const a=new Set(e),u=new Set(n);return t?.forEach(s=>{if(s.from!==void 0){const o=Array.isArray(s.from)?s.from:[s.from];if(i===null||!o.includes(i))return}if(!N(s.when,s.target,r))return;const l=Array.isArray(s.target)?s.target:[s.target];switch(s.type){case"readonly":l.forEach(o=>{u.add(o),a.delete(o)});break;case"active":l.forEach(o=>{a.add(o),u.delete(o)});break;case"hidden":l.forEach(o=>{a.delete(o),u.delete(o)});break}}),{active:Array.from(a),readonly:Array.from(u)}}function z(e,n,t,i){const r=new Set(e.active),a=new Set(e.readonly),u=new Set(e.hidden??[]);return n?.forEach(s=>{if(s.from!==void 0){const o=Array.isArray(s.from)?s.from:[s.from];if(t===null||!o.includes(t))return}if(!N(s.when,s.target,i))return;const l=Array.isArray(s.target)?s.target:[s.target];switch(s.type){case"hidden":l.forEach(o=>{u.add(o),r.delete(o),a.delete(o)});break;case"active":l.forEach(o=>{r.add(o),a.delete(o),u.delete(o)});break;case"readonly":l.forEach(o=>{a.add(o),r.delete(o),u.delete(o)});break}}),{active:Array.from(r),readonly:Array.from(a),hidden:Array.from(u)}}function G(e,n){if(!e?.length)return n;const t=new Map(n.map(r=>[r.name,r])),i=[];return e.forEach(r=>{t.has(r)&&(i.push(t.get(r)),t.delete(r))}),t.forEach(r=>i.push(r)),i}function K(e){const n=new Set,t=(i=[])=>{i.forEach(r=>{r.target&&(Array.isArray(r.target)?r.target:[r.target]).forEach(u=>n.add(u)),r.when?.field&&n.add(r.when.field)})};return t(e?.fields?.rules),t(e?.sections?.rules),Array.from(n)}function $({activityId:e,previousActivityId:n,control:t,workflowStructure:i,sectionsRegistry:r}){const{registerSchema:a,unregisterSchema:u}=F(),s=k(e),l=k(n),o=s!==null?i[s]:null,g=c.useMemo(()=>K(o),[s,o]),f=S.useWatch({control:t,name:g,defaultValue:{}}),h=c.useMemo(()=>{const w={};return g.forEach((v,A)=>{w[v]=Array.isArray(f)?f[A]:f}),w},[f,g]),d=c.useMemo(()=>{if(!o)return{sections:[],fields:{active:[],readonly:[],hidden:[]}};const w=B(o.sections.active,o.sections.readonly,o.sections.rules,l,h);let v=[...w.readonly.map(E=>({name:E,mode:"readonly"})),...w.active.map(E=>({name:E,mode:"active"}))];v=G(o.sections.order,v);const A=z({active:o.fields.active,readonly:o.fields.readonly,hidden:o.fields.hidden},o.fields.rules,l,h);return{sections:v,fields:A}},[o,l,h,r]);return c.useEffect(()=>{const w=d.sections.filter(v=>v.mode==="active").map(v=>v.name);w.forEach(v=>{const A=r?.[v]?.schema;A&&a(v,A)}),Object.keys(r??{}).filter(v=>!w.includes(v)).forEach(u)},[d.sections,r,a,u]),d}function J(){if(typeof document>"u")return{};const e={};return document.querySelectorAll("input[type='radio'][name]").forEach(n=>{const t=n,i=t.getAttribute("name");i&&t.checked&&(e[i]=t.value)}),document.querySelectorAll("input[name], textarea[name], select[name]").forEach(n=>{const t=n,i=t.getAttribute("name");if(!i||e[i]!==void 0)return;const r=t.getAttribute("value")??t.value??t.textContent??"";e[i]=String(r).trim()}),document.querySelectorAll("span[name]").forEach(n=>{const t=n,i=t.getAttribute("name");if(i){const r=t.textContent?.trim()??"";r!==""&&(e[i]=r)}}),e}const T=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("edit"),Q=()=>typeof window>"u"||!window.top?null:window.top.ECM?.workflowView?"process":"document",X=()=>{if(Q()==="process"){const n=window.top?.ECM?.workflowView;if(!n)return!1;const t=n.newRequest??n.isNewRequest,i=n.colleagueLogin;return t===!0||!!i&&i.trim()!==""}return T()===null},Z=()=>T()==="true",L=c.createContext(null);function H({children:e,devConfig:n}){const[t,i]=c.useState(null),r=c.useMemo(()=>J()??{},[]);return c.useEffect(()=>{let a=!0;return(async()=>{const s=typeof window<"u"&&window.location.hostname==="localhost",l=typeof window<"u"&&window.self!==window.top;let o=null;try{const d=await p.parentProxy.top.ECM.workflowView.sequence;d!=null&&(o=Number(d),n?.showDebugLogs&&console.log("[FluigRuntime] Atividade:",o))}catch(d){console.warn("[FluigRuntime] Falha ao detectar atividade:",d)}const g=!s&&l&&!(X()||Z()),f={isView:g,isReadOnly:g,activityId:o,previousActivityId:null,prefilledValues:r,showDebugSubmit:!1,showDebugLogs:!1,isDev:!1};let h=f;if(n?.enabled){const d=n.isView??f.isView;h={...f,...n,isView:d,isReadOnly:d,isDev:!0,activityId:n.activityId!==void 0?n.activityId:o}}typeof window<"u"&&(window.__FLUIG_DEBUG_ENABLED__=h.showDebugLogs),h.showDebugLogs&&a&&(p.DebugLogger.header("Runtime Initialized"),p.DebugLogger.table("State",{"Detected Activity":o,"Final Activity":h.activityId,"Dev Mode":h.isDev}),p.DebugLogger.end()),a&&i(h)})(),()=>{a=!1}},[n,r]),t?y.jsx(L.Provider,{value:t,children:e}):null}function I(){const e=c.useContext(L);if(!e)throw new Error("useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>");return e}function ee(e){const{activityId:n,previousActivityId:t}=I();c.useEffect(()=>{n!=null&&e.setValue("CURRENTACTIVITYID",n),t!=null&&e.setValue("LASTACTIVITYID",t)},[n,t,e]),c.useEffect(()=>{if(typeof window>"u")return;const i=window.top?.document.getElementById("send-process-button")||window.parent?.document.getElementById("workflow-actions-send")||document.getElementById("send-process-button");if(!i){console.warn("[FluigWorkflowReact] Botão de envio do Fluig não encontrado. A validação automática pode falhar.");return}return window.beforeSendValidate=()=>(e.handleSubmit(()=>{window.beforeSendValidate=()=>!0;try{i.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}))}catch{i.click()}},r=>{console.error("[Validation Errors]",r),window.top?.FLUIGC?.toast?window.top?.FLUIGC.toast({title:"Atenção",message:"Verifique os campos obrigatórios destacados em vermelho.",type:"danger"}):alert("Verifique os campos obrigatórios.")})(),!1),()=>{}},[e])}const te=({workflowStructure:e,sectionsRegistry:n,className:t})=>{const{control:i,handleSubmit:r,register:a,setValue:u,getValues:s}=S.useFormContext(),l=I(),o=c.useRef(!1);c.useEffect(()=>{o.current||(l.activityId!=null&&u("CURRENTACTIVITYID",l.activityId),l.previousActivityId!=null&&u("LASTACTIVITYID",l.previousActivityId),o.current=!0)},[l,u]);const{sections:g,fields:f}=$({control:i,activityId:l.activityId,previousActivityId:l.previousActivityId,workflowStructure:e,sectionsRegistry:n}),h=d=>{console.log("✅ [FluigWorkflowForm] Dados válidos:",d)};return y.jsxs("form",{id:"fluig-react-form",className:t,onSubmit:r(h),noValidate:!0,children:[y.jsxs("div",{className:"hidden",style:{display:"none"},children:[y.jsx("input",{type:"hidden",...a("CURRENTACTIVITYID")}),y.jsx("input",{type:"hidden",...a("LASTACTIVITYID")})]}),g.length===0&&l.activityId!==null&&y.jsxs("p",{children:["Não foi possível encontrar a atividade: ",String(l.activityId)]}),g.map(({name:d,mode:w})=>{if(w==="hidden")return null;const v=n[d];if(!v)return null;const A=v.Component;return y.jsx(A,{id:d,fields:f,readOnly:w==="readonly"},d)}),l.isDev&&l.showDebugSubmit&&y.jsx("div",{style:{width:"100%",padding:"16px",paddingTop:"0"},children:y.jsx("button",{type:"submit",className:"btn btn-primary btn-lg btn-block",children:"Submit (Debug)"})})]})},ne=e=>{const{mergedSchema:n}=F(),t=I(),i=S.useForm({resolver:n?W(n):void 0,defaultValues:t.prefilledValues,mode:"onBlur"});return ee(i),c.useEffect(()=>{t.showDebugLogs&&(p.DebugLogger.header("Form Initialized"),p.DebugLogger.table("Prefilled Values (DOM Capture)",t.prefilledValues),p.DebugLogger.info("RHF Current Values",i.getValues()),p.DebugLogger.end())},[t.showDebugLogs,t.prefilledValues,i]),y.jsx(S.FormProvider,{...i,children:y.jsx(te,{...e})})};async function ie(e){if(!e)return console.warn("[setFluigNextActivity] Nenhuma atividade informada."),!1;const{wfView:n,wkfView:t}=await oe();if(!n||!t)return!1;re(n);const i=Number(e),r=se(n,i);return r?(ae(n,t,r,i),console.log(`[setFluigNextActivity] Próxima atividade definida: ${i}`),!0):(console.warn(`[setFluigNextActivity] Estado ${i} não encontrado nas próximas atividades disponíveis.`),console.log("Estados disponíveis:",n.availableStatesCOPY||n.availableStates),!1)}async function oe(){const e=await p.parentProxy.top.ECM.workflowView,n=await p.parentProxy.top.ECM_WKFView;return!e||!n?(console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."),{}):{wfView:e,wkfView:n}}function re(e){e.availableStatesCOPY||(e.availableStatesCOPY=e.availableStates)}function se(e,n){return(e.availableStatesCOPY||e.availableStates)?.find(i=>i.sequence===n)}function ae(e,n,t,i){e.availableUsers.users=[],e.availableStates=[t],n.selectActivity=()=>i}const R=c.createContext(null);function ue(){const e=c.useContext(R);if(!e)throw new Error("useSection deve ser usado dentro de um componente <Section>");return e}function le({id:e,className:n,schema:t,children:i,form:r,prefilledValues:a,readOnly:u,fields:s={},hidden:l=!1}){const{isView:o,activityId:g}=I(),f=g,h=S.useFormContext(),d=r||h;if(!d)return console.error(`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`),null;if(l)return null;const w=c.useCallback(b=>s.hidden?.includes(b)?"hidden":s.readonly?.includes(b)?"readonly":s.active?.includes(b)?"active":u?"readonly":"active",[s,u]),v=c.useCallback(b=>w(b)==="hidden",[w]),A=c.useCallback(b=>w(b)==="readonly",[w]),E=c.useCallback(b=>{if(!b)return;const C=d.getValues("CURRENTACTIVITYID");d.setValue("LASTACTIVITYID",C),d.setValue("CURRENTACTIVITYID",f),ie(Number(b))},[d,f]);c.useEffect(()=>{if(!o||!a||!t||!d)return;const b=d.getValues(),C=t.shape;C&&Object.entries(C).forEach(([q,me])=>{let V=me;for(;V?._def?.schema;)V=V._def.schema;const x=V?._def?.fluig;if(x?.type!=="options"||!Array.isArray(x.values)||b[q]!==void 0)return;const j={};x.values.forEach(O=>{j[O]=a[O]==="on"}),d.setValue(q,j,{shouldDirty:!1,shouldValidate:!1})})},[o,a,t,d]);const fe=c.useMemo(()=>({id:e,form:d,isHidden:v,isReadOnly:A,isView:o,next:E,wf_activity_id:f}),[e,d,v,A,o,E,f]);return y.jsx(R.Provider,{value:fe,children:y.jsx("section",{id:e,className:[e,n].filter(Boolean).join(" "),children:i})})}const M=c.createContext(null);function ce({children:e,config:n}){const t=c.useMemo(()=>p.createFluigClient(n),[n]);return y.jsx(M.Provider,{value:t,children:e})}function de(){const e=c.useContext(M);if(!e)throw new Error("useFluigApi deve ser usado dentro de um <FluigApiProvider>");return e}Object.defineProperty(m,"DebugLogger",{enumerable:!0,get:()=>p.DebugLogger}),Object.defineProperty(m,"createFluigClient",{enumerable:!0,get:()=>p.createFluigClient}),Object.defineProperty(m,"parentProxy",{enumerable:!0,get:()=>p.parentProxy}),m.FluigApiProvider=ce,m.FluigRuntimeProvider=H,m.FluigWorkflowForm=ne,m.SchemaRegistryProvider=_,m.Section=le,m.useFluigApi=de,m.useFluigRuntime=I,m.useSchemaRegistry=F,m.useSection=ue,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluig-kit/ecm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/fluig-kit-ecm.umd.js",
|
|
6
6
|
"private": false,
|
|
@@ -15,19 +15,24 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"import": "./dist/fluig-kit-ecm.es.js",
|
|
17
17
|
"require": "./dist/fluig-kit-ecm.umd.js"
|
|
18
|
+
},
|
|
19
|
+
"./node": {
|
|
20
|
+
"types": "./src/services/generateHtmlTemplate.ts",
|
|
21
|
+
"import": "./src/services/generateHtmlTemplate.ts",
|
|
22
|
+
"require": "./src/services/generateHtmlTemplate.ts"
|
|
18
23
|
}
|
|
19
24
|
},
|
|
20
25
|
"scripts": {
|
|
21
26
|
"build": "vite build && shx cp ../../README.md ."
|
|
22
27
|
},
|
|
23
28
|
"dependencies": {
|
|
24
|
-
"@fluig-kit/core": "1.0.0",
|
|
25
29
|
"chalk": "^4.1.2"
|
|
26
30
|
},
|
|
27
31
|
"peerDependencies": {
|
|
28
32
|
"react": "^18.0.0 || ^19.0.0",
|
|
29
33
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
30
34
|
"react-hook-form": "^7.0.0",
|
|
35
|
+
"@fluig-kit/core": "1.0.0",
|
|
31
36
|
"@hookform/resolvers": "^3.0.0",
|
|
32
37
|
"zod": "^3.0.0"
|
|
33
38
|
},
|