@fluig-kit/ecm 1.0.0 → 1.0.2

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.
@@ -1,530 +1,272 @@
1
- import we, { createContext as q, useState as se, useMemo as R, useCallback as C, useContext as U, useEffect as x, useRef as be } from "react";
2
- import { appendErrors as Ee, useWatch as Ae, useForm as Se, FormProvider as Re, useFormContext as le } from "react-hook-form";
3
- import { validateFieldsNatively as _e, toNestErrors as Te } from "@hookform/resolvers";
4
- import { z as xe } from "zod";
5
- import { parentProxy as X, DebugLogger as T, createFluigClient as ke } from "@fluig-kit/core";
6
- import { DebugLogger as yt, createFluigClient as ht, parentProxy as gt } from "@fluig-kit/core";
7
- import Y from "chalk";
8
- var M = { exports: {} }, j = {};
9
- var ne;
10
- function Ie() {
11
- if (ne) return j;
12
- ne = 1;
13
- var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
14
- function n(o, i, s) {
15
- var u = null;
16
- if (s !== void 0 && (u = "" + s), i.key !== void 0 && (u = "" + i.key), "key" in i) {
17
- s = {};
18
- for (var l in i)
19
- l !== "key" && (s[l] = i[l]);
20
- } else s = i;
21
- return i = s.ref, {
22
- $$typeof: e,
23
- type: o,
24
- key: u,
25
- ref: i !== void 0 ? i : null,
26
- props: s
27
- };
28
- }
29
- return j.Fragment = r, j.jsx = n, j.jsxs = n, j;
30
- }
31
- var N = {};
32
- var oe;
33
- function Fe() {
34
- return oe || (oe = 1, process.env.NODE_ENV !== "production" && (function() {
35
- function e(t) {
36
- if (t == null) return null;
37
- if (typeof t == "function")
38
- return t.$$typeof === ye ? null : t.displayName || t.name || null;
39
- if (typeof t == "string") return t;
40
- switch (t) {
41
- case E:
42
- return "Fragment";
43
- case W:
44
- return "Profiler";
45
- case _:
46
- return "StrictMode";
47
- case B:
48
- return "Suspense";
49
- case I:
50
- return "SuspenseList";
51
- case D:
52
- return "Activity";
53
- }
54
- if (typeof t == "object")
55
- switch (typeof t.tag == "number" && console.error(
56
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
57
- ), t.$$typeof) {
58
- case p:
59
- return "Portal";
60
- case k:
61
- return t.displayName || "Context";
62
- case S:
63
- return (t._context.displayName || "Context") + ".Consumer";
64
- case O:
65
- var d = t.render;
66
- return t = t.displayName, t || (t = d.displayName || d.name || "", t = t !== "" ? "ForwardRef(" + t + ")" : "ForwardRef"), t;
67
- case V:
68
- return d = t.displayName || null, d !== null ? d : e(t.type) || "Memo";
69
- case F:
70
- d = t._payload, t = t._init;
71
- try {
72
- return e(t(d));
73
- } catch {
74
- }
75
- }
76
- return null;
77
- }
78
- function r(t) {
79
- return "" + t;
80
- }
81
- function n(t) {
82
- try {
83
- r(t);
84
- var d = !1;
85
- } catch {
86
- d = !0;
87
- }
88
- if (d) {
89
- d = console;
90
- var y = d.error, w = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
91
- return y.call(
92
- d,
93
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
94
- w
95
- ), r(t);
96
- }
97
- }
98
- function o(t) {
99
- if (t === E) return "<>";
100
- if (typeof t == "object" && t !== null && t.$$typeof === F)
101
- return "<...>";
102
- try {
103
- var d = e(t);
104
- return d ? "<" + d + ">" : "<...>";
105
- } catch {
106
- return "<...>";
107
- }
108
- }
109
- function i() {
110
- var t = z.A;
111
- return t === null ? null : t.getOwner();
112
- }
113
- function s() {
114
- return Error("react-stack-top-frame");
115
- }
116
- function u(t) {
117
- if (Z.call(t, "key")) {
118
- var d = Object.getOwnPropertyDescriptor(t, "key").get;
119
- if (d && d.isReactWarning) return !1;
120
- }
121
- return t.key !== void 0;
122
- }
123
- function l(t, d) {
124
- function y() {
125
- Q || (Q = !0, console.error(
126
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
127
- d
128
- ));
129
- }
130
- y.isReactWarning = !0, Object.defineProperty(t, "key", {
131
- get: y,
132
- configurable: !0
133
- });
134
- }
135
- function c() {
136
- var t = e(this.type);
137
- return K[t] || (K[t] = !0, console.error(
138
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
139
- )), t = this.props.ref, t !== void 0 ? t : null;
140
- }
141
- function a(t, d, y, w, L, J) {
142
- var b = y.ref;
143
- return t = {
144
- $$typeof: g,
145
- type: t,
146
- key: d,
147
- props: y,
148
- _owner: w
149
- }, (b !== void 0 ? b : null) !== null ? Object.defineProperty(t, "ref", {
150
- enumerable: !1,
151
- get: c
152
- }) : Object.defineProperty(t, "ref", { enumerable: !1, value: null }), t._store = {}, Object.defineProperty(t._store, "validated", {
153
- configurable: !1,
154
- enumerable: !1,
155
- writable: !0,
156
- value: 0
157
- }), Object.defineProperty(t, "_debugInfo", {
158
- configurable: !1,
159
- enumerable: !1,
160
- writable: !0,
161
- value: null
162
- }), Object.defineProperty(t, "_debugStack", {
163
- configurable: !1,
164
- enumerable: !1,
165
- writable: !0,
166
- value: L
167
- }), Object.defineProperty(t, "_debugTask", {
168
- configurable: !1,
169
- enumerable: !1,
170
- writable: !0,
171
- value: J
172
- }), Object.freeze && (Object.freeze(t.props), Object.freeze(t)), t;
173
- }
174
- function v(t, d, y, w, L, J) {
175
- var b = d.children;
176
- if (b !== void 0)
177
- if (w)
178
- if (he(b)) {
179
- for (w = 0; w < b.length; w++)
180
- m(b[w]);
181
- Object.freeze && Object.freeze(b);
182
- } else
183
- console.error(
184
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
185
- );
186
- else m(b);
187
- if (Z.call(d, "key")) {
188
- b = e(t);
189
- var P = Object.keys(d).filter(function(ge) {
190
- return ge !== "key";
191
- });
192
- w = 0 < P.length ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}", re[b + w] || (P = 0 < P.length ? "{" + P.join(": ..., ") + ": ...}" : "{}", console.error(
193
- `A props object containing a "key" prop is being spread into JSX:
194
- let props = %s;
195
- <%s {...props} />
196
- React keys must be passed directly to JSX without using spread:
197
- let props = %s;
198
- <%s key={someKey} {...props} />`,
199
- w,
200
- b,
201
- P,
202
- b
203
- ), re[b + w] = !0);
204
- }
205
- if (b = null, y !== void 0 && (n(y), b = "" + y), u(d) && (n(d.key), b = "" + d.key), "key" in d) {
206
- y = {};
207
- for (var H in d)
208
- H !== "key" && (y[H] = d[H]);
209
- } else y = d;
210
- return b && l(
211
- y,
212
- typeof t == "function" ? t.displayName || t.name || "Unknown" : t
213
- ), a(
214
- t,
215
- b,
216
- y,
217
- i(),
218
- L,
219
- J
220
- );
221
- }
222
- function m(t) {
223
- h(t) ? t._store && (t._store.validated = 1) : typeof t == "object" && t !== null && t.$$typeof === F && (t._payload.status === "fulfilled" ? h(t._payload.value) && t._payload.value._store && (t._payload.value._store.validated = 1) : t._store && (t._store.validated = 1));
224
- }
225
- function h(t) {
226
- return typeof t == "object" && t !== null && t.$$typeof === g;
227
- }
228
- var f = we, g = /* @__PURE__ */ Symbol.for("react.transitional.element"), p = /* @__PURE__ */ Symbol.for("react.portal"), E = /* @__PURE__ */ Symbol.for("react.fragment"), _ = /* @__PURE__ */ Symbol.for("react.strict_mode"), W = /* @__PURE__ */ Symbol.for("react.profiler"), S = /* @__PURE__ */ Symbol.for("react.consumer"), k = /* @__PURE__ */ Symbol.for("react.context"), O = /* @__PURE__ */ Symbol.for("react.forward_ref"), B = /* @__PURE__ */ Symbol.for("react.suspense"), I = /* @__PURE__ */ Symbol.for("react.suspense_list"), V = /* @__PURE__ */ Symbol.for("react.memo"), F = /* @__PURE__ */ Symbol.for("react.lazy"), D = /* @__PURE__ */ Symbol.for("react.activity"), ye = /* @__PURE__ */ Symbol.for("react.client.reference"), z = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Z = Object.prototype.hasOwnProperty, he = Array.isArray, G = console.createTask ? console.createTask : function() {
229
- return null;
230
- };
231
- f = {
232
- react_stack_bottom_frame: function(t) {
233
- return t();
234
- }
235
- };
236
- var Q, K = {}, ee = f.react_stack_bottom_frame.bind(
237
- f,
238
- s
239
- )(), te = G(o(s)), re = {};
240
- N.Fragment = E, N.jsx = function(t, d, y) {
241
- var w = 1e4 > z.recentlyCreatedOwnerStacks++;
242
- return v(
243
- t,
244
- d,
245
- y,
246
- !1,
247
- w ? Error("react-stack-top-frame") : ee,
248
- w ? G(o(t)) : te
249
- );
250
- }, N.jsxs = function(t, d, y) {
251
- var w = 1e4 > z.recentlyCreatedOwnerStacks++;
252
- return v(
253
- t,
254
- d,
255
- y,
256
- !0,
257
- w ? Error("react-stack-top-frame") : ee,
258
- w ? G(o(t)) : te
259
- );
260
- };
261
- })()), N;
262
- }
263
- var ie;
264
- function Pe() {
265
- return ie || (ie = 1, process.env.NODE_ENV === "production" ? M.exports = Ie() : M.exports = Fe()), M.exports;
266
- }
267
- var A = Pe(), Ce = function(e, r) {
1
+ import { jsx as g, jsxs as N } from "react/jsx-runtime";
2
+ import { createContext as C, useState as O, useMemo as w, useCallback as E, useContext as x, useEffect as A, useRef as H } from "react";
3
+ import { appendErrors as Z, useWatch as K, useForm as J, FormProvider as Q, useFormContext as q } from "react-hook-form";
4
+ import { validateFieldsNatively as X, toNestErrors as ee } from "@hookform/resolvers";
5
+ import { z as te } from "zod";
6
+ import { parentProxy as T, DebugLogger as b, createFluigClient as ne } from "@fluig-kit/core";
7
+ import { DebugLogger as Ye, createFluigClient as Be, parentProxy as We } from "@fluig-kit/core";
8
+ import F from "chalk";
9
+ var re = function(e, t) {
268
10
  for (var n = {}; e.length; ) {
269
- var o = e[0], i = o.code, s = o.message, u = o.path.join(".");
270
- if (!n[u]) if ("unionErrors" in o) {
271
- var l = o.unionErrors[0].errors[0];
272
- n[u] = { message: l.message, type: l.code };
273
- } else n[u] = { message: s, type: i };
274
- if ("unionErrors" in o && o.unionErrors.forEach(function(v) {
275
- return v.errors.forEach(function(m) {
276
- return e.push(m);
11
+ var r = e[0], i = r.code, s = r.message, c = r.path.join(".");
12
+ if (!n[c]) if ("unionErrors" in r) {
13
+ var a = r.unionErrors[0].errors[0];
14
+ n[c] = { message: a.message, type: a.code };
15
+ } else n[c] = { message: s, type: i };
16
+ if ("unionErrors" in r && r.unionErrors.forEach(function(f) {
17
+ return f.errors.forEach(function(d) {
18
+ return e.push(d);
277
19
  });
278
- }), r) {
279
- var c = n[u].types, a = c && c[o.code];
280
- n[u] = Ee(u, r, n, i, a ? [].concat(a, o.message) : o.message);
20
+ }), t) {
21
+ var l = n[c].types, o = l && l[r.code];
22
+ n[c] = Z(c, t, n, i, o ? [].concat(o, r.message) : r.message);
281
23
  }
282
24
  e.shift();
283
25
  }
284
26
  return n;
285
- }, Ve = function(e, r, n) {
286
- return n === void 0 && (n = {}), function(o, i, s) {
27
+ }, oe = function(e, t, n) {
28
+ return n === void 0 && (n = {}), function(r, i, s) {
287
29
  try {
288
- return Promise.resolve((function(u, l) {
30
+ return Promise.resolve((function(c, a) {
289
31
  try {
290
- var c = Promise.resolve(e[n.mode === "sync" ? "parse" : "parseAsync"](o, r)).then(function(a) {
291
- return s.shouldUseNativeValidation && _e({}, s), { errors: {}, values: n.raw ? o : a };
32
+ var l = Promise.resolve(e[n.mode === "sync" ? "parse" : "parseAsync"](r, t)).then(function(o) {
33
+ return s.shouldUseNativeValidation && X({}, s), { errors: {}, values: n.raw ? r : o };
292
34
  });
293
- } catch (a) {
294
- return l(a);
35
+ } catch (o) {
36
+ return a(o);
295
37
  }
296
- return c && c.then ? c.then(void 0, l) : c;
297
- })(0, function(u) {
298
- if ((function(l) {
299
- return Array.isArray(l?.errors);
300
- })(u)) return { values: {}, errors: Te(Ce(u.errors, !s.shouldUseNativeValidation && s.criteriaMode === "all"), s) };
301
- throw u;
38
+ return l && l.then ? l.then(void 0, a) : l;
39
+ })(0, function(c) {
40
+ if ((function(a) {
41
+ return Array.isArray(a?.errors);
42
+ })(c)) return { values: {}, errors: ee(re(c.errors, !s.shouldUseNativeValidation && s.criteriaMode === "all"), s) };
43
+ throw c;
302
44
  }));
303
- } catch (u) {
304
- return Promise.reject(u);
45
+ } catch (c) {
46
+ return Promise.reject(c);
305
47
  }
306
48
  };
307
49
  };
308
- const ue = q(
50
+ const j = C(
309
51
  null
310
52
  );
311
- function at({
53
+ function Te({
312
54
  children: e,
313
- baseSchema: r
55
+ baseSchema: t
314
56
  }) {
315
- const [n, o] = se([]), i = R(() => r ?? xe.object({}), [r]), s = C((a, v) => {
316
- o((m) => m.some((h) => h.id === a) ? m : [...m, { id: a, schema: v }]);
317
- }, []), u = C((a) => {
318
- o((v) => v.some((m) => m.id === a) ? v.filter((m) => m.id !== a) : v);
319
- }, []), l = R(() => n.length ? n.map((a) => a.schema).reduce((a, v) => a.and(v), i) : i, [n, i]), c = R(
57
+ const [n, r] = O([]), i = w(() => t ?? te.object({}), [t]), s = E((o, f) => {
58
+ r((d) => d.some((y) => y.id === o) ? d : [...d, { id: o, schema: f }]);
59
+ }, []), c = E((o) => {
60
+ r((f) => f.some((d) => d.id === o) ? f.filter((d) => d.id !== o) : f);
61
+ }, []), a = w(() => n.length ? n.map((o) => o.schema).reduce((o, f) => o.and(f), i) : i, [n, i]), l = w(
320
62
  () => ({
321
63
  registerSchema: s,
322
- unregisterSchema: u,
323
- mergedSchema: l
64
+ unregisterSchema: c,
65
+ mergedSchema: a
324
66
  }),
325
- [s, u, l]
67
+ [s, c, a]
326
68
  );
327
- return /* @__PURE__ */ A.jsx(ue.Provider, { value: c, children: e });
69
+ return /* @__PURE__ */ g(j.Provider, { value: l, children: e });
328
70
  }
329
- function ce() {
330
- const e = U(ue);
71
+ function M() {
72
+ const e = x(j);
331
73
  if (!e)
332
74
  throw new Error(
333
75
  "useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>"
334
76
  );
335
77
  return e;
336
78
  }
337
- function ae(e) {
79
+ function _(e) {
338
80
  return typeof e == "number" ? e : isNaN(Number(e)) ? null : Number(e);
339
81
  }
340
- function de(e, r, n) {
82
+ function U(e, t, n) {
341
83
  if (!e) return !0;
342
- const o = Array.isArray(r) ? r[0] : r, i = e.field ?? o, s = n?.[i];
84
+ const r = Array.isArray(t) ? t[0] : t, i = e.field ?? r, s = n?.[i];
343
85
  return e.hasValue !== void 0 ? e.hasValue ? s != null && s !== "" : s == null || s === "" : e.equals !== void 0 ? s === e.equals : e.notEquals !== void 0 ? s !== e.notEquals : !0;
344
86
  }
345
- function je(e, r, n, o, i) {
346
- const s = new Set(e), u = new Set(r);
347
- return n?.forEach((l) => {
348
- if (l.from !== void 0) {
349
- const a = Array.isArray(l.from) ? l.from : [l.from];
350
- if (o === null || !a.includes(o)) return;
87
+ function ie(e, t, n, r, i) {
88
+ const s = new Set(e), c = new Set(t);
89
+ return n?.forEach((a) => {
90
+ if (a.from !== void 0) {
91
+ const o = Array.isArray(a.from) ? a.from : [a.from];
92
+ if (r === null || !o.includes(r)) return;
351
93
  }
352
- if (!de(l.when, l.target, i)) return;
353
- const c = Array.isArray(l.target) ? l.target : [l.target];
354
- switch (l.type) {
94
+ if (!U(a.when, a.target, i)) return;
95
+ const l = Array.isArray(a.target) ? a.target : [a.target];
96
+ switch (a.type) {
355
97
  case "readonly":
356
- c.forEach((a) => {
357
- u.add(a), s.delete(a);
98
+ l.forEach((o) => {
99
+ c.add(o), s.delete(o);
358
100
  });
359
101
  break;
360
102
  case "active":
361
- c.forEach((a) => {
362
- s.add(a), u.delete(a);
103
+ l.forEach((o) => {
104
+ s.add(o), c.delete(o);
363
105
  });
364
106
  break;
365
107
  case "hidden":
366
- c.forEach((a) => {
367
- s.delete(a), u.delete(a);
108
+ l.forEach((o) => {
109
+ s.delete(o), c.delete(o);
368
110
  });
369
111
  break;
370
112
  }
371
- }), { active: Array.from(s), readonly: Array.from(u) };
113
+ }), { active: Array.from(s), readonly: Array.from(c) };
372
114
  }
373
- function Ne(e, r, n, o) {
374
- const i = new Set(e.active), s = new Set(e.readonly), u = new Set(e.hidden ?? []);
375
- return r?.forEach((l) => {
376
- if (l.from !== void 0) {
377
- const a = Array.isArray(l.from) ? l.from : [l.from];
378
- if (n === null || !a.includes(n)) return;
115
+ function ae(e, t, n, r) {
116
+ const i = new Set(e.active), s = new Set(e.readonly), c = new Set(e.hidden ?? []);
117
+ return t?.forEach((a) => {
118
+ if (a.from !== void 0) {
119
+ const o = Array.isArray(a.from) ? a.from : [a.from];
120
+ if (n === null || !o.includes(n)) return;
379
121
  }
380
- if (!de(l.when, l.target, o)) return;
381
- const c = Array.isArray(l.target) ? l.target : [l.target];
382
- switch (l.type) {
122
+ if (!U(a.when, a.target, r)) return;
123
+ const l = Array.isArray(a.target) ? a.target : [a.target];
124
+ switch (a.type) {
383
125
  case "hidden":
384
- c.forEach((a) => {
385
- u.add(a), i.delete(a), s.delete(a);
126
+ l.forEach((o) => {
127
+ c.add(o), i.delete(o), s.delete(o);
386
128
  });
387
129
  break;
388
130
  case "active":
389
- c.forEach((a) => {
390
- i.add(a), s.delete(a), u.delete(a);
131
+ l.forEach((o) => {
132
+ i.add(o), s.delete(o), c.delete(o);
391
133
  });
392
134
  break;
393
135
  case "readonly":
394
- c.forEach((a) => {
395
- s.add(a), i.delete(a), u.delete(a);
136
+ l.forEach((o) => {
137
+ s.add(o), i.delete(o), c.delete(o);
396
138
  });
397
139
  break;
398
140
  }
399
141
  }), {
400
142
  active: Array.from(i),
401
143
  readonly: Array.from(s),
402
- hidden: Array.from(u)
144
+ hidden: Array.from(c)
403
145
  };
404
146
  }
405
- function Oe(e, r) {
406
- if (!e?.length) return r;
407
- const n = new Map(r.map((i) => [i.name, i])), o = [];
147
+ function se(e, t) {
148
+ if (!e?.length) return t;
149
+ const n = new Map(t.map((i) => [i.name, i])), r = [];
408
150
  return e.forEach((i) => {
409
- n.has(i) && (o.push(n.get(i)), n.delete(i));
410
- }), n.forEach((i) => o.push(i)), o;
151
+ n.has(i) && (r.push(n.get(i)), n.delete(i));
152
+ }), n.forEach((i) => r.push(i)), r;
411
153
  }
412
- function De(e) {
413
- const r = /* @__PURE__ */ new Set(), n = (o = []) => {
414
- o.forEach((i) => {
415
- i.target && (Array.isArray(i.target) ? i.target : [i.target]).forEach((u) => r.add(u)), i.when?.field && r.add(i.when.field);
154
+ function ce(e) {
155
+ const t = /* @__PURE__ */ new Set(), n = (r = []) => {
156
+ r.forEach((i) => {
157
+ i.target && (Array.isArray(i.target) ? i.target : [i.target]).forEach((c) => t.add(c)), i.when?.field && t.add(i.when.field);
416
158
  });
417
159
  };
418
- return n(e?.fields?.rules), n(e?.sections?.rules), Array.from(r);
160
+ return n(e?.fields?.rules), n(e?.sections?.rules), Array.from(t);
419
161
  }
420
- function Le({
162
+ function le({
421
163
  activityId: e,
422
- previousActivityId: r,
164
+ previousActivityId: t,
423
165
  control: n,
424
- workflowStructure: o,
166
+ workflowStructure: r,
425
167
  sectionsRegistry: i
426
168
  }) {
427
- const { registerSchema: s, unregisterSchema: u } = ce(), l = ae(e), c = ae(r), a = l !== null ? o[l] : null, v = R(() => De(a), [l, a]), m = Ae({
169
+ const { registerSchema: s, unregisterSchema: c } = M(), a = _(e), l = _(t), o = a !== null ? r[a] : null, f = w(() => ce(o), [a, o]), d = K({
428
170
  control: n,
429
- name: v,
171
+ name: f,
430
172
  defaultValue: {}
431
- }), h = R(() => {
432
- const g = {};
433
- return v.forEach((p, E) => {
434
- g[p] = Array.isArray(m) ? m[E] : m;
435
- }), g;
436
- }, [m, v]), f = R(() => {
437
- if (!a)
173
+ }), y = w(() => {
174
+ const v = {};
175
+ return f.forEach((m, p) => {
176
+ v[m] = Array.isArray(d) ? d[p] : d;
177
+ }), v;
178
+ }, [d, f]), u = w(() => {
179
+ if (!o)
438
180
  return {
439
181
  sections: [],
440
182
  fields: { active: [], readonly: [], hidden: [] }
441
183
  };
442
- const g = je(
443
- a.sections.active,
444
- a.sections.readonly,
445
- a.sections.rules,
446
- c,
447
- h
184
+ const v = ie(
185
+ o.sections.active,
186
+ o.sections.readonly,
187
+ o.sections.rules,
188
+ l,
189
+ y
448
190
  );
449
- let p = [
450
- ...g.readonly.map((_) => ({
451
- name: _,
191
+ let m = [
192
+ ...v.readonly.map((S) => ({
193
+ name: S,
452
194
  mode: "readonly"
453
195
  })),
454
- ...g.active.map((_) => ({
455
- name: _,
196
+ ...v.active.map((S) => ({
197
+ name: S,
456
198
  mode: "active"
457
199
  }))
458
200
  ];
459
- p = Oe(a.sections.order, p);
460
- const E = Ne(
201
+ m = se(o.sections.order, m);
202
+ const p = ae(
461
203
  {
462
- active: a.fields.active,
463
- readonly: a.fields.readonly,
464
- hidden: a.fields.hidden
204
+ active: o.fields.active,
205
+ readonly: o.fields.readonly,
206
+ hidden: o.fields.hidden
465
207
  },
466
- a.fields.rules,
467
- c,
468
- h
208
+ o.fields.rules,
209
+ l,
210
+ y
469
211
  );
470
- return { sections: p, fields: E };
471
- }, [a, c, h, i]);
472
- return x(() => {
473
- const g = f.sections.filter((p) => p.mode === "active").map((p) => p.name);
474
- g.forEach((p) => {
475
- const E = i?.[p]?.schema;
476
- E && s(p, E);
477
- }), Object.keys(i ?? {}).filter((p) => !g.includes(p)).forEach(u);
478
- }, [f.sections, i, s, u]), f;
212
+ return { sections: m, fields: p };
213
+ }, [o, l, y, i]);
214
+ return A(() => {
215
+ const v = u.sections.filter((m) => m.mode === "active").map((m) => m.name);
216
+ v.forEach((m) => {
217
+ const p = i?.[m]?.schema;
218
+ p && s(m, p);
219
+ }), Object.keys(i ?? {}).filter((m) => !v.includes(m)).forEach(c);
220
+ }, [u.sections, i, s, c]), u;
479
221
  }
480
- function Ye() {
222
+ function ue() {
481
223
  if (typeof document > "u") return {};
482
224
  const e = {};
483
- return document.querySelectorAll("input[type='radio'][name]").forEach((r) => {
484
- const n = r, o = n.getAttribute("name");
485
- o && n.checked && (e[o] = n.value);
486
- }), document.querySelectorAll("input[name], textarea[name], select[name]").forEach((r) => {
487
- const n = r, o = n.getAttribute("name");
488
- if (!o || e[o] !== void 0) return;
225
+ return document.querySelectorAll("input[type='radio'][name]").forEach((t) => {
226
+ const n = t, r = n.getAttribute("name");
227
+ r && n.checked && (e[r] = n.value);
228
+ }), document.querySelectorAll("input[name], textarea[name], select[name]").forEach((t) => {
229
+ const n = t, r = n.getAttribute("name");
230
+ if (!r || e[r] !== void 0) return;
489
231
  const i = n.getAttribute("value") ?? n.value ?? n.textContent ?? "";
490
- e[o] = String(i).trim();
491
- }), document.querySelectorAll("span[name]").forEach((r) => {
492
- const n = r, o = n.getAttribute("name");
493
- if (o) {
232
+ e[r] = String(i).trim();
233
+ }), document.querySelectorAll("span[name]").forEach((t) => {
234
+ const n = t, r = n.getAttribute("name");
235
+ if (r) {
494
236
  const i = n.textContent?.trim() ?? "";
495
- i !== "" && (e[o] = i);
237
+ i !== "" && (e[r] = i);
496
238
  }
497
239
  }), e;
498
240
  }
499
- const fe = () => typeof window > "u" ? null : new URLSearchParams(window.location.search).get("edit"), Me = () => typeof window > "u" || !window.top ? null : window.top.ECM?.workflowView ? "process" : "document", qe = () => {
500
- if (Me() === "process") {
501
- const r = window.top?.ECM?.workflowView;
502
- if (!r) return !1;
503
- const n = r.newRequest ?? r.isNewRequest, o = r.colleagueLogin;
504
- return n === !0 || !!o && o.trim() !== "";
241
+ const Y = () => typeof window > "u" ? null : new URLSearchParams(window.location.search).get("edit"), de = () => typeof window > "u" || !window.top ? null : window.top.ECM?.workflowView ? "process" : "document", fe = () => {
242
+ if (de() === "process") {
243
+ const t = window.top?.ECM?.workflowView;
244
+ if (!t) return !1;
245
+ const n = t.newRequest ?? t.isNewRequest, r = t.colleagueLogin;
246
+ return n === !0 || !!r && r.trim() !== "";
505
247
  }
506
- return fe() === null;
507
- }, Ue = () => fe() === "true", me = q(null);
508
- function st({
248
+ return Y() === null;
249
+ }, me = () => Y() === "true", B = C(null);
250
+ function ke({
509
251
  children: e,
510
- devConfig: r
252
+ devConfig: t
511
253
  }) {
512
- const [n, o] = se(null), i = R(() => Ye() ?? {}, []);
513
- return x(() => {
254
+ const [n, r] = O(null), i = w(() => ue() ?? {}, []);
255
+ return A(() => {
514
256
  let s = !0;
515
257
  return (async () => {
516
- const l = typeof window < "u" && window.location.hostname === "localhost", c = typeof window < "u" && window.self !== window.top;
517
- let a = null;
258
+ const a = typeof window < "u" && window.location.hostname === "localhost", l = typeof window < "u" && window.self !== window.top;
259
+ let o = null;
518
260
  try {
519
- const f = await X.top.ECM.workflowView.sequence;
520
- f != null && (a = Number(f), r?.showDebugLogs && console.log("[FluigRuntime] Atividade:", a));
521
- } catch (f) {
522
- console.warn("[FluigRuntime] Falha ao detectar atividade:", f);
261
+ const u = await T.top.ECM.workflowView.sequence;
262
+ u != null && (o = Number(u), t?.showDebugLogs && console.log("[FluigRuntime] Atividade:", o));
263
+ } catch (u) {
264
+ console.warn("[FluigRuntime] Falha ao detectar atividade:", u);
523
265
  }
524
- const v = !l && c && !(qe() || Ue()), m = {
525
- isView: v,
526
- isReadOnly: v,
527
- activityId: a,
266
+ const f = !a && l && !(fe() || me()), d = {
267
+ isView: f,
268
+ isReadOnly: f,
269
+ activityId: o,
528
270
  // Usa o valor real detectado
529
271
  previousActivityId: null,
530
272
  prefilledValues: i,
@@ -532,46 +274,46 @@ function st({
532
274
  showDebugLogs: !1,
533
275
  isDev: !1
534
276
  };
535
- let h = m;
536
- if (r?.enabled) {
537
- const f = r.isView ?? m.isView;
538
- h = {
539
- ...m,
540
- ...r,
541
- isView: f,
542
- isReadOnly: f,
277
+ let y = d;
278
+ if (t?.enabled) {
279
+ const u = t.isView ?? d.isView;
280
+ y = {
281
+ ...d,
282
+ ...t,
283
+ isView: u,
284
+ isReadOnly: u,
543
285
  isDev: !0,
544
286
  // Se devConfig tiver activityId definido explicitamente, usa ele.
545
287
  // Se não, mantém o detectado (permite usar devConfig só para logs, por exemplo)
546
- activityId: r.activityId !== void 0 ? r.activityId : a
288
+ activityId: t.activityId !== void 0 ? t.activityId : o
547
289
  };
548
290
  }
549
- typeof window < "u" && (window.__FLUIG_DEBUG_ENABLED__ = h.showDebugLogs), h.showDebugLogs && s && (T.header("Runtime Initialized"), T.table("State", {
550
- "Detected Activity": a,
551
- "Final Activity": h.activityId,
552
- "Dev Mode": h.isDev
553
- }), T.end()), s && o(h);
291
+ typeof window < "u" && (window.__FLUIG_DEBUG_ENABLED__ = y.showDebugLogs), y.showDebugLogs && s && (b.header("Runtime Initialized"), b.table("State", {
292
+ "Detected Activity": o,
293
+ "Final Activity": y.activityId,
294
+ "Dev Mode": y.isDev
295
+ }), b.end()), s && r(y);
554
296
  })(), () => {
555
297
  s = !1;
556
298
  };
557
- }, [r, i]), n ? /* @__PURE__ */ A.jsx(me.Provider, { value: n, children: e }) : null;
299
+ }, [t, i]), n ? /* @__PURE__ */ g(B.Provider, { value: n, children: e }) : null;
558
300
  }
559
- function $() {
560
- const e = U(me);
301
+ function R() {
302
+ const e = x(B);
561
303
  if (!e)
562
304
  throw new Error(
563
305
  "useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>"
564
306
  );
565
307
  return e;
566
308
  }
567
- function $e(e) {
568
- const { activityId: r, previousActivityId: n } = $();
569
- x(() => {
570
- r != null && e.setValue("CURRENTACTIVITYID", r), n != null && e.setValue("LASTACTIVITYID", n);
571
- }, [r, n, e]), x(() => {
309
+ function ve(e) {
310
+ const { activityId: t, previousActivityId: n } = R();
311
+ A(() => {
312
+ t != null && e.setValue("CURRENTACTIVITYID", t), n != null && e.setValue("LASTACTIVITYID", n);
313
+ }, [t, n, e]), A(() => {
572
314
  if (typeof window > "u") return;
573
- const o = window.top?.document.getElementById("send-process-button") || window.parent?.document.getElementById("workflow-actions-send") || document.getElementById("send-process-button");
574
- if (!o) {
315
+ const r = window.top?.document.getElementById("send-process-button") || window.parent?.document.getElementById("workflow-actions-send") || document.getElementById("send-process-button");
316
+ if (!r) {
575
317
  console.warn("[FluigWorkflowReact] Botão de envio do Fluig não encontrado. A validação automática pode falhar.");
576
318
  return;
577
319
  }
@@ -579,9 +321,9 @@ function $e(e) {
579
321
  () => {
580
322
  window.beforeSendValidate = () => !0;
581
323
  try {
582
- o.dispatchEvent(new MouseEvent("click", { view: window, bubbles: !0, cancelable: !0 }));
324
+ r.dispatchEvent(new MouseEvent("click", { view: window, bubbles: !0, cancelable: !0 }));
583
325
  } catch {
584
- o.click();
326
+ r.click();
585
327
  }
586
328
  },
587
329
  (i) => {
@@ -595,220 +337,220 @@ function $e(e) {
595
337
  };
596
338
  }, [e]);
597
339
  }
598
- const We = ({
340
+ const ye = ({
599
341
  workflowStructure: e,
600
- sectionsRegistry: r,
342
+ sectionsRegistry: t,
601
343
  className: n
602
344
  }) => {
603
- const { control: o, handleSubmit: i, register: s, setValue: u, getValues: l } = le(), c = $(), a = be(!1);
604
- x(() => {
605
- a.current || (c.activityId != null && u("CURRENTACTIVITYID", c.activityId), c.previousActivityId != null && u("LASTACTIVITYID", c.previousActivityId), a.current = !0);
606
- }, [c, u]);
607
- const { sections: v, fields: m } = Le({
608
- control: o,
609
- activityId: c.activityId,
610
- previousActivityId: c.previousActivityId,
345
+ const { control: r, handleSubmit: i, register: s, setValue: c, getValues: a } = q(), l = R(), o = H(!1);
346
+ A(() => {
347
+ o.current || (l.activityId != null && c("CURRENTACTIVITYID", l.activityId), l.previousActivityId != null && c("LASTACTIVITYID", l.previousActivityId), o.current = !0);
348
+ }, [l, c]);
349
+ const { sections: f, fields: d } = le({
350
+ control: r,
351
+ activityId: l.activityId,
352
+ previousActivityId: l.previousActivityId,
611
353
  workflowStructure: e,
612
- sectionsRegistry: r
613
- }), h = (f) => {
614
- console.log("✅ [FluigWorkflowForm] Dados válidos:", f);
615
- };
616
- return /* @__PURE__ */ A.jsxs(
354
+ sectionsRegistry: t
355
+ });
356
+ return /* @__PURE__ */ N(
617
357
  "form",
618
358
  {
619
359
  id: "fluig-react-form",
620
360
  className: n,
621
- onSubmit: i(h),
361
+ onSubmit: i((u) => {
362
+ console.log("✅ [FluigWorkflowForm] Dados válidos:", u);
363
+ }),
622
364
  noValidate: !0,
623
365
  children: [
624
- /* @__PURE__ */ A.jsxs("div", { className: "hidden", style: { display: "none" }, children: [
625
- /* @__PURE__ */ A.jsx("input", { type: "hidden", ...s("CURRENTACTIVITYID") }),
626
- /* @__PURE__ */ A.jsx("input", { type: "hidden", ...s("LASTACTIVITYID") })
366
+ /* @__PURE__ */ N("div", { className: "hidden", style: { display: "none" }, children: [
367
+ /* @__PURE__ */ g("input", { type: "hidden", ...s("CURRENTACTIVITYID") }),
368
+ /* @__PURE__ */ g("input", { type: "hidden", ...s("LASTACTIVITYID") })
627
369
  ] }),
628
- v.length === 0 && c.activityId !== null && /* @__PURE__ */ A.jsxs("p", { children: [
370
+ f.length === 0 && l.activityId !== null && /* @__PURE__ */ N("p", { children: [
629
371
  "Não foi possível encontrar a atividade: ",
630
- String(c.activityId)
372
+ String(l.activityId)
631
373
  ] }),
632
- v.map(({ name: f, mode: g }) => {
633
- if (g === "hidden") return null;
634
- const p = r[f];
635
- if (!p) return null;
636
- const E = p.Component;
637
- return /* @__PURE__ */ A.jsx(
638
- E,
374
+ f.map(({ name: u, mode: v }) => {
375
+ if (v === "hidden") return null;
376
+ const m = t[u];
377
+ if (!m) return null;
378
+ const p = m.Component;
379
+ return /* @__PURE__ */ g(
380
+ p,
639
381
  {
640
- id: f,
641
- fields: m,
642
- readOnly: g === "readonly"
382
+ id: u,
383
+ fields: d,
384
+ readOnly: v === "readonly"
643
385
  },
644
- f
386
+ u
645
387
  );
646
388
  }),
647
- c.isDev && c.showDebugSubmit && /* @__PURE__ */ A.jsx("div", { style: { width: "100%", padding: "16px", paddingTop: "0" }, children: /* @__PURE__ */ A.jsx("button", { type: "submit", className: "btn btn-primary btn-lg btn-block", children: "Submit (Debug)" }) })
389
+ l.isDev && l.showDebugSubmit && /* @__PURE__ */ g("div", { style: { width: "100%", padding: "16px", paddingTop: "0" }, children: /* @__PURE__ */ g("button", { type: "submit", className: "btn btn-primary btn-lg btn-block", children: "Submit (Debug)" }) })
648
390
  ]
649
391
  }
650
392
  );
651
- }, lt = (e) => {
652
- const { mergedSchema: r } = ce(), n = $(), o = Se({
653
- resolver: r ? Ve(r) : void 0,
393
+ }, Le = (e) => {
394
+ const { mergedSchema: t } = M(), n = R(), r = J({
395
+ resolver: t ? oe(t) : void 0,
654
396
  defaultValues: n.prefilledValues,
655
397
  mode: "onBlur"
656
398
  });
657
- return $e(o), x(() => {
658
- n.showDebugLogs && (T.header("Form Initialized"), T.table(
399
+ return ve(r), A(() => {
400
+ n.showDebugLogs && (b.header("Form Initialized"), b.table(
659
401
  "Prefilled Values (DOM Capture)",
660
402
  n.prefilledValues
661
- ), T.info("RHF Current Values", o.getValues()), T.end());
662
- }, [n.showDebugLogs, n.prefilledValues, o]), /* @__PURE__ */ A.jsx(Re, { ...o, children: /* @__PURE__ */ A.jsx(We, { ...e }) });
403
+ ), b.info("RHF Current Values", r.getValues()), b.end());
404
+ }, [n.showDebugLogs, n.prefilledValues, r]), /* @__PURE__ */ g(Q, { ...r, children: /* @__PURE__ */ g(ye, { ...e }) });
663
405
  };
664
- async function Be(e) {
406
+ async function he(e) {
665
407
  if (!e)
666
408
  return console.warn("[setFluigNextActivity] Nenhuma atividade informada."), !1;
667
- const { wfView: r, wkfView: n } = await ze();
668
- if (!r || !n) return !1;
669
- Ge(r);
670
- const o = Number(e), i = Je(r, o);
671
- return i ? (He(r, n, i, o), console.log(`[setFluigNextActivity] Próxima atividade definida: ${o}`), !0) : (console.warn(`[setFluigNextActivity] Estado ${o} não encontrado nas próximas atividades disponíveis.`), console.log("Estados disponíveis:", r.availableStatesCOPY || r.availableStates), !1);
409
+ const { wfView: t, wkfView: n } = await ge();
410
+ if (!t || !n) return !1;
411
+ pe(t);
412
+ const r = Number(e), i = we(t, r);
413
+ return i ? (be(t, n, 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:", t.availableStatesCOPY || t.availableStates), !1);
672
414
  }
673
- async function ze() {
674
- const e = await X.top.ECM.workflowView, r = await X.top.ECM_WKFView;
675
- return !e || !r ? (console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."), {}) : { wfView: e, wkfView: r };
415
+ async function ge() {
416
+ const e = await T.top.ECM.workflowView, t = await T.top.ECM_WKFView;
417
+ return !e || !t ? (console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."), {}) : { wfView: e, wkfView: t };
676
418
  }
677
- function Ge(e) {
419
+ function pe(e) {
678
420
  e.availableStatesCOPY || (e.availableStatesCOPY = e.availableStates);
679
421
  }
680
- function Je(e, r) {
681
- return (e.availableStatesCOPY || e.availableStates)?.find((o) => o.sequence === r);
422
+ function we(e, t) {
423
+ return (e.availableStatesCOPY || e.availableStates)?.find((r) => r.sequence === t);
682
424
  }
683
- function He(e, r, n, o) {
684
- e.availableUsers.users = [], e.availableStates = [n], r.selectActivity = () => o;
425
+ function be(e, t, n, r) {
426
+ e.availableUsers.users = [], e.availableStates = [n], t.selectActivity = () => r;
685
427
  }
686
- const ve = q(null);
687
- function ut() {
688
- const e = U(ve);
428
+ const W = C(null);
429
+ function Pe() {
430
+ const e = x(W);
689
431
  if (!e)
690
432
  throw new Error(
691
433
  "useSection deve ser usado dentro de um componente <Section>"
692
434
  );
693
435
  return e;
694
436
  }
695
- function ct({
437
+ function _e({
696
438
  id: e,
697
- className: r,
439
+ className: t,
698
440
  schema: n,
699
- children: o,
441
+ children: r,
700
442
  form: i,
701
443
  prefilledValues: s,
702
- readOnly: u,
703
- fields: l = {},
704
- hidden: c = !1
444
+ readOnly: c,
445
+ fields: a = {},
446
+ hidden: l = !1
705
447
  }) {
706
- const { isView: a, activityId: v } = $(), m = v, h = le(), f = i || h;
707
- if (!f)
448
+ const { isView: o, activityId: f } = R(), d = f, y = q(), u = i || y;
449
+ if (!u)
708
450
  return console.error(
709
451
  `[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`
710
452
  ), null;
711
- if (c) return null;
712
- const g = C(
713
- (S) => l.hidden?.includes(S) ? "hidden" : l.readonly?.includes(S) ? "readonly" : l.active?.includes(S) ? "active" : u ? "readonly" : "active",
714
- [l, u]
715
- ), p = C(
716
- (S) => g(S) === "hidden",
717
- [g]
718
- ), E = C(
719
- (S) => g(S) === "readonly",
720
- [g]
721
- ), _ = C(
722
- (S) => {
723
- if (!S) return;
724
- const k = f.getValues("CURRENTACTIVITYID");
725
- f.setValue("LASTACTIVITYID", k), f.setValue("CURRENTACTIVITYID", m), Be(Number(S));
453
+ if (l) return null;
454
+ const v = E(
455
+ (h) => a.hidden?.includes(h) ? "hidden" : a.readonly?.includes(h) ? "readonly" : a.active?.includes(h) ? "active" : c ? "readonly" : "active",
456
+ [a, c]
457
+ ), m = E(
458
+ (h) => v(h) === "hidden",
459
+ [v]
460
+ ), p = E(
461
+ (h) => v(h) === "readonly",
462
+ [v]
463
+ ), S = E(
464
+ (h) => {
465
+ if (!h) return;
466
+ const I = u.getValues("CURRENTACTIVITYID");
467
+ u.setValue("LASTACTIVITYID", I), u.setValue("CURRENTACTIVITYID", d), he(Number(h));
726
468
  },
727
- [f, m]
469
+ [u, d]
728
470
  );
729
- x(() => {
730
- if (!a || !s || !n || !f) return;
731
- const S = f.getValues(), k = n.shape;
732
- k && Object.entries(k).forEach(([O, B]) => {
733
- let I = B;
734
- for (; I?._def?.schema; )
735
- I = I._def.schema;
736
- const V = I?._def?.fluig;
737
- if (V?.type !== "options" || !Array.isArray(V.values) || S[O] !== void 0) return;
738
- const F = {};
739
- V.values.forEach((D) => {
740
- F[D] = s[D] === "on";
741
- }), f.setValue(O, F, {
471
+ A(() => {
472
+ if (!o || !s || !n || !u) return;
473
+ const h = u.getValues(), I = n.shape;
474
+ I && Object.entries(I).forEach(([k, z]) => {
475
+ let V = z;
476
+ for (; V?._def?.schema; )
477
+ V = V._def.schema;
478
+ const D = V?._def?.fluig;
479
+ if (D?.type !== "options" || !Array.isArray(D.values) || h[k] !== void 0) return;
480
+ const L = {};
481
+ D.values.forEach((P) => {
482
+ L[P] = s[P] === "on";
483
+ }), u.setValue(k, L, {
742
484
  shouldDirty: !1,
743
485
  shouldValidate: !1
744
486
  });
745
487
  });
746
- }, [a, s, n, f]);
747
- const W = R(
488
+ }, [o, s, n, u]);
489
+ const G = w(
748
490
  () => ({
749
491
  id: e,
750
- form: f,
751
- isHidden: p,
752
- isReadOnly: E,
753
- isView: a,
754
- next: _,
755
- wf_activity_id: m
492
+ form: u,
493
+ isHidden: m,
494
+ isReadOnly: p,
495
+ isView: o,
496
+ next: S,
497
+ wf_activity_id: d
756
498
  }),
757
- [e, f, p, E, a, _, m]
499
+ [e, u, m, p, o, S, d]
758
500
  );
759
- return /* @__PURE__ */ A.jsx(ve.Provider, { value: W, children: /* @__PURE__ */ A.jsx("section", { id: e, className: [e, r].filter(Boolean).join(" "), children: o }) });
501
+ return /* @__PURE__ */ g(W.Provider, { value: G, children: /* @__PURE__ */ g("section", { id: e, className: [e, t].filter(Boolean).join(" "), children: r }) });
760
502
  }
761
- const pe = q(null);
762
- function dt({ children: e, config: r }) {
763
- const n = R(() => ke(r), [r]);
764
- return /* @__PURE__ */ A.jsx(pe.Provider, { value: n, children: e });
503
+ const $ = C(null);
504
+ function Oe({ children: e, config: t }) {
505
+ const n = w(() => ne(t), [t]);
506
+ return /* @__PURE__ */ g($.Provider, { value: n, children: e });
765
507
  }
766
- function ft() {
767
- const e = U(pe);
508
+ function qe() {
509
+ const e = x($);
768
510
  if (!e)
769
511
  throw new Error(
770
512
  "useFluigApi deve ser usado dentro de um <FluigApiProvider>"
771
513
  );
772
514
  return e;
773
515
  }
774
- function Xe(e) {
516
+ function Ae(e) {
775
517
  return e._def?.schema ?? e;
776
518
  }
777
- function Ze(e) {
778
- let r = e._def?.fluig;
779
- if (r?.values) return r.values;
780
- const n = Xe(e);
781
- if (n !== e && (r = n._def?.fluig, r?.values))
782
- return r.values;
783
- const o = n._def;
784
- return (o?.meta ?? o?.metadata)?.fluig?.values ?? null;
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;
785
527
  }
786
- function Qe(e) {
528
+ function Ee(e) {
787
529
  return e?._def?.typeName !== "ZodObject" ? [] : Object.entries(e.shape);
788
530
  }
789
- function Ke(e) {
790
- const r = /* @__PURE__ */ new Set();
791
- return (Array.isArray(e) ? e : Object.values(e).map((o) => o.schema).filter(Boolean)).forEach((o) => {
792
- let i = o;
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;
793
535
  for (; i._def?.schema; )
794
536
  i = i._def.schema;
795
- i._def?.typeName === "ZodObject" && Qe(i).forEach(([s, u]) => {
796
- r.add(s);
797
- const l = Ze(u);
798
- l?.length && l.forEach((c) => r.add(c));
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));
799
541
  });
800
- }), Array.from(r);
542
+ }), Array.from(t);
801
543
  }
802
- function mt(e) {
803
- const r = Ke(e), n = r.map(
804
- (o) => `<input type="hidden" name="${o}" />`
544
+ function je(e) {
545
+ const t = Ie(e), n = t.map(
546
+ (r) => `<input type="hidden" name="${r}" />`
805
547
  ).join(`
806
548
  `);
807
- return console.log(Y.blue.bold(`
549
+ return console.log(F.blue.bold(`
808
550
  === Inputs gerados (Build Script) ===
809
- `)), r.forEach((o, i) => {
810
- console.log(`${Y.yellow(i + 1 + ".")} ${Y.green(o)}`);
811
- }), console.log(Y.blue.bold(`
551
+ `)), t.forEach((r, i) => {
552
+ console.log(`${F.yellow(i + 1 + ".")} ${F.green(r)}`);
553
+ }), console.log(F.blue.bold(`
812
554
  =====================================
813
555
  `)), `<!DOCTYPE html>
814
556
  <html lang="pt-br">
@@ -833,17 +575,17 @@ function mt(e) {
833
575
  </html>`;
834
576
  }
835
577
  export {
836
- yt as DebugLogger,
837
- dt as FluigApiProvider,
838
- st as FluigRuntimeProvider,
839
- lt as FluigWorkflowForm,
840
- at as SchemaRegistryProvider,
841
- ct as Section,
842
- ht as createFluigClient,
843
- mt as generateHtmlTemplate,
844
- gt as parentProxy,
845
- ft as useFluigApi,
846
- $ as useFluigRuntime,
847
- ce as useSchemaRegistry,
848
- ut as useSection
578
+ Ye as DebugLogger,
579
+ Oe as FluigApiProvider,
580
+ ke as FluigRuntimeProvider,
581
+ Le as FluigWorkflowForm,
582
+ Te as SchemaRegistryProvider,
583
+ _e as Section,
584
+ Be as createFluigClient,
585
+ je as generateHtmlTemplate,
586
+ We as parentProxy,
587
+ qe as useFluigApi,
588
+ R as useFluigRuntime,
589
+ M as useSchemaRegistry,
590
+ Pe as useSection
849
591
  };
@@ -1,12 +1,7 @@
1
- (function(g,d){typeof exports=="object"&&typeof module<"u"?d(exports,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","react-hook-form","@hookform/resolvers","zod","@fluig-kit/core","chalk"],d):(g=typeof globalThis<"u"?globalThis:g||self,d(g.FluigKitECM={},g.React,g.reactHookForm,g.resolvers,g.zod,g.FluigKitCore,g.chalk))})(this,(function(g,d,k,H,fe,_,D){"use strict";var L={exports:{}},j={};var K;function me(){if(K)return j;K=1;var e=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(o,a,s){var l=null;if(s!==void 0&&(l=""+s),a.key!==void 0&&(l=""+a.key),"key"in a){s={};for(var u in a)u!=="key"&&(s[u]=a[u])}else s=a;return a=s.ref,{$$typeof:e,type:o,key:l,ref:a!==void 0?a:null,props:s}}return j.Fragment=r,j.jsx=n,j.jsxs=n,j}var O={};var Q;function ve(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&(function(){function e(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Je?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case R:return"Fragment";case z:return"Profiler";case x:return"StrictMode";case B:return"Suspense";case I:return"SuspenseList";case Y:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case p:return"Portal";case C:return t.displayName||"Context";case T:return(t._context.displayName||"Context")+".Consumer";case M:var f=t.render;return t=t.displayName,t||(t=f.displayName||f.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case N:return f=t.displayName||null,f!==null?f:e(t.type)||"Memo";case P:f=t._payload,t=t._init;try{return e(t(f))}catch{}}return null}function r(t){return""+t}function n(t){try{r(t);var f=!1}catch{f=!0}if(f){f=console;var h=f.error,E=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return h.call(f,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",E),r(t)}}function o(t){if(t===R)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===P)return"<...>";try{var f=e(t);return f?"<"+f+">":"<...>"}catch{return"<...>"}}function a(){var t=G.A;return t===null?null:t.getOwner()}function s(){return Error("react-stack-top-frame")}function l(t){if(ie.call(t,"key")){var f=Object.getOwnPropertyDescriptor(t,"key").get;if(f&&f.isReactWarning)return!1}return t.key!==void 0}function u(t,f){function h(){se||(se=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",f))}h.isReactWarning=!0,Object.defineProperty(t,"key",{get:h,configurable:!0})}function c(){var t=e(this.type);return ue[t]||(ue[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function i(t,f,h,E,U,X){var A=h.ref;return t={$$typeof:b,type:t,key:f,props:h,_owner:E},(A!==void 0?A:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:c}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:X}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function y(t,f,h,E,U,X){var A=f.children;if(A!==void 0)if(E)if(Xe(A)){for(E=0;E<A.length;E++)v(A[E]);Object.freeze&&Object.freeze(A)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else v(A);if(ie.call(f,"key")){A=e(t);var F=Object.keys(f).filter(function(Ze){return Ze!=="key"});E=0<F.length?"{key: someKey, "+F.join(": ..., ")+": ...}":"{key: someKey}",de[A+E]||(F=0<F.length?"{"+F.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
- let props = %s;
3
- <%s {...props} />
4
- React keys must be passed directly to JSX without using spread:
5
- let props = %s;
6
- <%s key={someKey} {...props} />`,E,A,F,A),de[A+E]=!0)}if(A=null,h!==void 0&&(n(h),A=""+h),l(f)&&(n(f.key),A=""+f.key),"key"in f){h={};for(var Z in f)Z!=="key"&&(h[Z]=f[Z])}else h=f;return A&&u(h,typeof t=="function"?t.displayName||t.name||"Unknown":t),i(t,A,h,a(),U,X)}function v(t){w(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===P&&(t._payload.status==="fulfilled"?w(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function w(t){return typeof t=="object"&&t!==null&&t.$$typeof===b}var m=d,b=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),R=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),z=Symbol.for("react.profiler"),T=Symbol.for("react.consumer"),C=Symbol.for("react.context"),M=Symbol.for("react.forward_ref"),B=Symbol.for("react.suspense"),I=Symbol.for("react.suspense_list"),N=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),Y=Symbol.for("react.activity"),Je=Symbol.for("react.client.reference"),G=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ie=Object.prototype.hasOwnProperty,Xe=Array.isArray,J=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(t){return t()}};var se,ue={},le=m.react_stack_bottom_frame.bind(m,s)(),ce=J(o(s)),de={};O.Fragment=R,O.jsx=function(t,f,h){var E=1e4>G.recentlyCreatedOwnerStacks++;return y(t,f,h,!1,E?Error("react-stack-top-frame"):le,E?J(o(t)):ce)},O.jsxs=function(t,f,h){var E=1e4>G.recentlyCreatedOwnerStacks++;return y(t,f,h,!0,E?Error("react-stack-top-frame"):le,E?J(o(t)):ce)}})()),O}var q;function ge(){return q||(q=1,process.env.NODE_ENV==="production"?L.exports=me():L.exports=ve()),L.exports}var S=ge(),ye=function(e,r){for(var n={};e.length;){var o=e[0],a=o.code,s=o.message,l=o.path.join(".");if(!n[l])if("unionErrors"in o){var u=o.unionErrors[0].errors[0];n[l]={message:u.message,type:u.code}}else n[l]={message:s,type:a};if("unionErrors"in o&&o.unionErrors.forEach(function(y){return y.errors.forEach(function(v){return e.push(v)})}),r){var c=n[l].types,i=c&&c[o.code];n[l]=k.appendErrors(l,r,n,a,i?[].concat(i,o.message):o.message)}e.shift()}return n},pe=function(e,r,n){return n===void 0&&(n={}),function(o,a,s){try{return Promise.resolve((function(l,u){try{var c=Promise.resolve(e[n.mode==="sync"?"parse":"parseAsync"](o,r)).then(function(i){return s.shouldUseNativeValidation&&H.validateFieldsNatively({},s),{errors:{},values:n.raw?o:i}})}catch(i){return u(i)}return c&&c.then?c.then(void 0,u):c})(0,function(l){if((function(u){return Array.isArray(u?.errors)})(l))return{values:{},errors:H.toNestErrors(ye(l.errors,!s.shouldUseNativeValidation&&s.criteriaMode==="all"),s)};throw l}))}catch(l){return Promise.reject(l)}}};const $=d.createContext(null);function he({children:e,baseSchema:r}){const[n,o]=d.useState([]),a=d.useMemo(()=>r??fe.z.object({}),[r]),s=d.useCallback((i,y)=>{o(v=>v.some(w=>w.id===i)?v:[...v,{id:i,schema:y}])},[]),l=d.useCallback(i=>{o(y=>y.some(v=>v.id===i)?y.filter(v=>v.id!==i):y)},[]),u=d.useMemo(()=>n.length?n.map(i=>i.schema).reduce((i,y)=>i.and(y),a):a,[n,a]),c=d.useMemo(()=>({registerSchema:s,unregisterSchema:l,mergedSchema:u}),[s,l,u]);return S.jsx($.Provider,{value:c,children:e})}function W(){const e=d.useContext($);if(!e)throw new Error("useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>");return e}function ee(e){return typeof e=="number"?e:isNaN(Number(e))?null:Number(e)}function te(e,r,n){if(!e)return!0;const o=Array.isArray(r)?r[0]:r,a=e.field??o,s=n?.[a];return e.hasValue!==void 0?e.hasValue?s!=null&&s!=="":s==null||s==="":e.equals!==void 0?s===e.equals:e.notEquals!==void 0?s!==e.notEquals:!0}function we(e,r,n,o,a){const s=new Set(e),l=new Set(r);return n?.forEach(u=>{if(u.from!==void 0){const i=Array.isArray(u.from)?u.from:[u.from];if(o===null||!i.includes(o))return}if(!te(u.when,u.target,a))return;const c=Array.isArray(u.target)?u.target:[u.target];switch(u.type){case"readonly":c.forEach(i=>{l.add(i),s.delete(i)});break;case"active":c.forEach(i=>{s.add(i),l.delete(i)});break;case"hidden":c.forEach(i=>{s.delete(i),l.delete(i)});break}}),{active:Array.from(s),readonly:Array.from(l)}}function be(e,r,n,o){const a=new Set(e.active),s=new Set(e.readonly),l=new Set(e.hidden??[]);return r?.forEach(u=>{if(u.from!==void 0){const i=Array.isArray(u.from)?u.from:[u.from];if(n===null||!i.includes(n))return}if(!te(u.when,u.target,o))return;const c=Array.isArray(u.target)?u.target:[u.target];switch(u.type){case"hidden":c.forEach(i=>{l.add(i),a.delete(i),s.delete(i)});break;case"active":c.forEach(i=>{a.add(i),s.delete(i),l.delete(i)});break;case"readonly":c.forEach(i=>{s.add(i),a.delete(i),l.delete(i)});break}}),{active:Array.from(a),readonly:Array.from(s),hidden:Array.from(l)}}function Ee(e,r){if(!e?.length)return r;const n=new Map(r.map(a=>[a.name,a])),o=[];return e.forEach(a=>{n.has(a)&&(o.push(n.get(a)),n.delete(a))}),n.forEach(a=>o.push(a)),o}function Ae(e){const r=new Set,n=(o=[])=>{o.forEach(a=>{a.target&&(Array.isArray(a.target)?a.target:[a.target]).forEach(l=>r.add(l)),a.when?.field&&r.add(a.when.field)})};return n(e?.fields?.rules),n(e?.sections?.rules),Array.from(r)}function Se({activityId:e,previousActivityId:r,control:n,workflowStructure:o,sectionsRegistry:a}){const{registerSchema:s,unregisterSchema:l}=W(),u=ee(e),c=ee(r),i=u!==null?o[u]:null,y=d.useMemo(()=>Ae(i),[u,i]),v=k.useWatch({control:n,name:y,defaultValue:{}}),w=d.useMemo(()=>{const b={};return y.forEach((p,R)=>{b[p]=Array.isArray(v)?v[R]:v}),b},[v,y]),m=d.useMemo(()=>{if(!i)return{sections:[],fields:{active:[],readonly:[],hidden:[]}};const b=we(i.sections.active,i.sections.readonly,i.sections.rules,c,w);let p=[...b.readonly.map(x=>({name:x,mode:"readonly"})),...b.active.map(x=>({name:x,mode:"active"}))];p=Ee(i.sections.order,p);const R=be({active:i.fields.active,readonly:i.fields.readonly,hidden:i.fields.hidden},i.fields.rules,c,w);return{sections:p,fields:R}},[i,c,w,a]);return d.useEffect(()=>{const b=m.sections.filter(p=>p.mode==="active").map(p=>p.name);b.forEach(p=>{const R=a?.[p]?.schema;R&&s(p,R)}),Object.keys(a??{}).filter(p=>!b.includes(p)).forEach(l)},[m.sections,a,s,l]),m}function Re(){if(typeof document>"u")return{};const e={};return document.querySelectorAll("input[type='radio'][name]").forEach(r=>{const n=r,o=n.getAttribute("name");o&&n.checked&&(e[o]=n.value)}),document.querySelectorAll("input[name], textarea[name], select[name]").forEach(r=>{const n=r,o=n.getAttribute("name");if(!o||e[o]!==void 0)return;const a=n.getAttribute("value")??n.value??n.textContent??"";e[o]=String(a).trim()}),document.querySelectorAll("span[name]").forEach(r=>{const n=r,o=n.getAttribute("name");if(o){const a=n.textContent?.trim()??"";a!==""&&(e[o]=a)}}),e}const re=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("edit"),_e=()=>typeof window>"u"||!window.top?null:window.top.ECM?.workflowView?"process":"document",Te=()=>{if(_e()==="process"){const r=window.top?.ECM?.workflowView;if(!r)return!1;const n=r.newRequest??r.isNewRequest,o=r.colleagueLogin;return n===!0||!!o&&o.trim()!==""}return re()===null},xe=()=>re()==="true",ne=d.createContext(null);function ke({children:e,devConfig:r}){const[n,o]=d.useState(null),a=d.useMemo(()=>Re()??{},[]);return d.useEffect(()=>{let s=!0;return(async()=>{const u=typeof window<"u"&&window.location.hostname==="localhost",c=typeof window<"u"&&window.self!==window.top;let i=null;try{const m=await _.parentProxy.top.ECM.workflowView.sequence;m!=null&&(i=Number(m),r?.showDebugLogs&&console.log("[FluigRuntime] Atividade:",i))}catch(m){console.warn("[FluigRuntime] Falha ao detectar atividade:",m)}const y=!u&&c&&!(Te()||xe()),v={isView:y,isReadOnly:y,activityId:i,previousActivityId:null,prefilledValues:a,showDebugSubmit:!1,showDebugLogs:!1,isDev:!1};let w=v;if(r?.enabled){const m=r.isView??v.isView;w={...v,...r,isView:m,isReadOnly:m,isDev:!0,activityId:r.activityId!==void 0?r.activityId:i}}typeof window<"u"&&(window.__FLUIG_DEBUG_ENABLED__=w.showDebugLogs),w.showDebugLogs&&s&&(_.DebugLogger.header("Runtime Initialized"),_.DebugLogger.table("State",{"Detected Activity":i,"Final Activity":w.activityId,"Dev Mode":w.isDev}),_.DebugLogger.end()),s&&o(w)})(),()=>{s=!1}},[r,a]),n?S.jsx(ne.Provider,{value:n,children:e}):null}function V(){const e=d.useContext(ne);if(!e)throw new Error("useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>");return e}function Ce(e){const{activityId:r,previousActivityId:n}=V();d.useEffect(()=>{r!=null&&e.setValue("CURRENTACTIVITYID",r),n!=null&&e.setValue("LASTACTIVITYID",n)},[r,n,e]),d.useEffect(()=>{if(typeof window>"u")return;const o=window.top?.document.getElementById("send-process-button")||window.parent?.document.getElementById("workflow-actions-send")||document.getElementById("send-process-button");if(!o){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{o.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}))}catch{o.click()}},a=>{console.error("[Validation Errors]",a),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 Ie=({workflowStructure:e,sectionsRegistry:r,className:n})=>{const{control:o,handleSubmit:a,register:s,setValue:l,getValues:u}=k.useFormContext(),c=V(),i=d.useRef(!1);d.useEffect(()=>{i.current||(c.activityId!=null&&l("CURRENTACTIVITYID",c.activityId),c.previousActivityId!=null&&l("LASTACTIVITYID",c.previousActivityId),i.current=!0)},[c,l]);const{sections:y,fields:v}=Se({control:o,activityId:c.activityId,previousActivityId:c.previousActivityId,workflowStructure:e,sectionsRegistry:r}),w=m=>{console.log("✅ [FluigWorkflowForm] Dados válidos:",m)};return S.jsxs("form",{id:"fluig-react-form",className:n,onSubmit:a(w),noValidate:!0,children:[S.jsxs("div",{className:"hidden",style:{display:"none"},children:[S.jsx("input",{type:"hidden",...s("CURRENTACTIVITYID")}),S.jsx("input",{type:"hidden",...s("LASTACTIVITYID")})]}),y.length===0&&c.activityId!==null&&S.jsxs("p",{children:["Não foi possível encontrar a atividade: ",String(c.activityId)]}),y.map(({name:m,mode:b})=>{if(b==="hidden")return null;const p=r[m];if(!p)return null;const R=p.Component;return S.jsx(R,{id:m,fields:v,readOnly:b==="readonly"},m)}),c.isDev&&c.showDebugSubmit&&S.jsx("div",{style:{width:"100%",padding:"16px",paddingTop:"0"},children:S.jsx("button",{type:"submit",className:"btn btn-primary btn-lg btn-block",children:"Submit (Debug)"})})]})},Pe=e=>{const{mergedSchema:r}=W(),n=V(),o=k.useForm({resolver:r?pe(r):void 0,defaultValues:n.prefilledValues,mode:"onBlur"});return Ce(o),d.useEffect(()=>{n.showDebugLogs&&(_.DebugLogger.header("Form Initialized"),_.DebugLogger.table("Prefilled Values (DOM Capture)",n.prefilledValues),_.DebugLogger.info("RHF Current Values",o.getValues()),_.DebugLogger.end())},[n.showDebugLogs,n.prefilledValues,o]),S.jsx(k.FormProvider,{...o,children:S.jsx(Ie,{...e})})};async function Fe(e){if(!e)return console.warn("[setFluigNextActivity] Nenhuma atividade informada."),!1;const{wfView:r,wkfView:n}=await je();if(!r||!n)return!1;Oe(r);const o=Number(e),a=Ve(r,o);return a?(Ne(r,n,a,o),console.log(`[setFluigNextActivity] Próxima atividade definida: ${o}`),!0):(console.warn(`[setFluigNextActivity] Estado ${o} não encontrado nas próximas atividades disponíveis.`),console.log("Estados disponíveis:",r.availableStatesCOPY||r.availableStates),!1)}async function je(){const e=await _.parentProxy.top.ECM.workflowView,r=await _.parentProxy.top.ECM_WKFView;return!e||!r?(console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."),{}):{wfView:e,wkfView:r}}function Oe(e){e.availableStatesCOPY||(e.availableStatesCOPY=e.availableStates)}function Ve(e,r){return(e.availableStatesCOPY||e.availableStates)?.find(o=>o.sequence===r)}function Ne(e,r,n,o){e.availableUsers.users=[],e.availableStates=[n],r.selectActivity=()=>o}const oe=d.createContext(null);function De(){const e=d.useContext(oe);if(!e)throw new Error("useSection deve ser usado dentro de um componente <Section>");return e}function Le({id:e,className:r,schema:n,children:o,form:a,prefilledValues:s,readOnly:l,fields:u={},hidden:c=!1}){const{isView:i,activityId:y}=V(),v=y,w=k.useFormContext(),m=a||w;if(!m)return console.error(`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`),null;if(c)return null;const b=d.useCallback(T=>u.hidden?.includes(T)?"hidden":u.readonly?.includes(T)?"readonly":u.active?.includes(T)?"active":l?"readonly":"active",[u,l]),p=d.useCallback(T=>b(T)==="hidden",[b]),R=d.useCallback(T=>b(T)==="readonly",[b]),x=d.useCallback(T=>{if(!T)return;const C=m.getValues("CURRENTACTIVITYID");m.setValue("LASTACTIVITYID",C),m.setValue("CURRENTACTIVITYID",v),Fe(Number(T))},[m,v]);d.useEffect(()=>{if(!i||!s||!n||!m)return;const T=m.getValues(),C=n.shape;C&&Object.entries(C).forEach(([M,B])=>{let I=B;for(;I?._def?.schema;)I=I._def.schema;const N=I?._def?.fluig;if(N?.type!=="options"||!Array.isArray(N.values)||T[M]!==void 0)return;const P={};N.values.forEach(Y=>{P[Y]=s[Y]==="on"}),m.setValue(M,P,{shouldDirty:!1,shouldValidate:!1})})},[i,s,n,m]);const z=d.useMemo(()=>({id:e,form:m,isHidden:p,isReadOnly:R,isView:i,next:x,wf_activity_id:v}),[e,m,p,R,i,x,v]);return S.jsx(oe.Provider,{value:z,children:S.jsx("section",{id:e,className:[e,r].filter(Boolean).join(" "),children:o})})}const ae=d.createContext(null);function Me({children:e,config:r}){const n=d.useMemo(()=>_.createFluigClient(r),[r]);return S.jsx(ae.Provider,{value:n,children:e})}function Ye(){const e=d.useContext(ae);if(!e)throw new Error("useFluigApi deve ser usado dentro de um <FluigApiProvider>");return e}function Ue(e){return e._def?.schema??e}function We(e){let r=e._def?.fluig;if(r?.values)return r.values;const n=Ue(e);if(n!==e&&(r=n._def?.fluig,r?.values))return r.values;const o=n._def;return(o?.meta??o?.metadata)?.fluig?.values??null}function ze(e){return e?._def?.typeName!=="ZodObject"?[]:Object.entries(e.shape)}function Be(e){const r=new Set;return(Array.isArray(e)?e:Object.values(e).map(o=>o.schema).filter(Boolean)).forEach(o=>{let a=o;for(;a._def?.schema;)a=a._def.schema;a._def?.typeName==="ZodObject"&&ze(a).forEach(([s,l])=>{r.add(s);const u=We(l);u?.length&&u.forEach(c=>r.add(c))})}),Array.from(r)}function Ge(e){const r=Be(e),n=r.map(o=>`<input type="hidden" name="${o}" />`).join(`
7
- `);return console.log(D.blue.bold(`
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(`
8
3
  === Inputs gerados (Build Script) ===
9
- `)),r.forEach((o,a)=>{console.log(`${D.yellow(a+1+".")} ${D.green(o)}`)}),console.log(D.blue.bold(`
4
+ `)),t.forEach((i,o)=>{console.log(`${F.yellow(o+1+".")} ${F.green(i)}`)}),console.log(F.blue.bold(`
10
5
  =====================================
11
6
  `)),`<!DOCTYPE html>
12
7
  <html lang="pt-br">
@@ -28,4 +23,4 @@ React keys must be passed directly to JSX without using spread:
28
23
 
29
24
  <script src="./bundle.js"><\/script>
30
25
  </body>
31
- </html>`}Object.defineProperty(g,"DebugLogger",{enumerable:!0,get:()=>_.DebugLogger}),Object.defineProperty(g,"createFluigClient",{enumerable:!0,get:()=>_.createFluigClient}),Object.defineProperty(g,"parentProxy",{enumerable:!0,get:()=>_.parentProxy}),g.FluigApiProvider=Me,g.FluigRuntimeProvider=ke,g.FluigWorkflowForm=Pe,g.SchemaRegistryProvider=he,g.Section=Le,g.generateHtmlTemplate=Ge,g.useFluigApi=Ye,g.useFluigRuntime=V,g.useSchemaRegistry=W,g.useSection=De,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluig-kit/ecm",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "./dist/fluig-kit-ecm.umd.js",
6
6
  "private": false,
@@ -21,7 +21,7 @@
21
21
  "build": "vite build && shx cp ../../README.md ."
22
22
  },
23
23
  "dependencies": {
24
- "@fluig-kit/core": "*",
24
+ "@fluig-kit/core": "1.0.0",
25
25
  "chalk": "^4.1.2"
26
26
  },
27
27
  "peerDependencies": {