@fluig-kit/ecm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,849 @@
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) {
268
+ 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);
277
+ });
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);
281
+ }
282
+ e.shift();
283
+ }
284
+ return n;
285
+ }, Ve = function(e, r, n) {
286
+ return n === void 0 && (n = {}), function(o, i, s) {
287
+ try {
288
+ return Promise.resolve((function(u, l) {
289
+ 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 };
292
+ });
293
+ } catch (a) {
294
+ return l(a);
295
+ }
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;
302
+ }));
303
+ } catch (u) {
304
+ return Promise.reject(u);
305
+ }
306
+ };
307
+ };
308
+ const ue = q(
309
+ null
310
+ );
311
+ function at({
312
+ children: e,
313
+ baseSchema: r
314
+ }) {
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(
320
+ () => ({
321
+ registerSchema: s,
322
+ unregisterSchema: u,
323
+ mergedSchema: l
324
+ }),
325
+ [s, u, l]
326
+ );
327
+ return /* @__PURE__ */ A.jsx(ue.Provider, { value: c, children: e });
328
+ }
329
+ function ce() {
330
+ const e = U(ue);
331
+ if (!e)
332
+ throw new Error(
333
+ "useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>"
334
+ );
335
+ return e;
336
+ }
337
+ function ae(e) {
338
+ return typeof e == "number" ? e : isNaN(Number(e)) ? null : Number(e);
339
+ }
340
+ function de(e, r, n) {
341
+ if (!e) return !0;
342
+ const o = Array.isArray(r) ? r[0] : r, i = e.field ?? o, s = n?.[i];
343
+ 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
+ }
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;
351
+ }
352
+ if (!de(l.when, l.target, i)) return;
353
+ const c = Array.isArray(l.target) ? l.target : [l.target];
354
+ switch (l.type) {
355
+ case "readonly":
356
+ c.forEach((a) => {
357
+ u.add(a), s.delete(a);
358
+ });
359
+ break;
360
+ case "active":
361
+ c.forEach((a) => {
362
+ s.add(a), u.delete(a);
363
+ });
364
+ break;
365
+ case "hidden":
366
+ c.forEach((a) => {
367
+ s.delete(a), u.delete(a);
368
+ });
369
+ break;
370
+ }
371
+ }), { active: Array.from(s), readonly: Array.from(u) };
372
+ }
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;
379
+ }
380
+ if (!de(l.when, l.target, o)) return;
381
+ const c = Array.isArray(l.target) ? l.target : [l.target];
382
+ switch (l.type) {
383
+ case "hidden":
384
+ c.forEach((a) => {
385
+ u.add(a), i.delete(a), s.delete(a);
386
+ });
387
+ break;
388
+ case "active":
389
+ c.forEach((a) => {
390
+ i.add(a), s.delete(a), u.delete(a);
391
+ });
392
+ break;
393
+ case "readonly":
394
+ c.forEach((a) => {
395
+ s.add(a), i.delete(a), u.delete(a);
396
+ });
397
+ break;
398
+ }
399
+ }), {
400
+ active: Array.from(i),
401
+ readonly: Array.from(s),
402
+ hidden: Array.from(u)
403
+ };
404
+ }
405
+ function Oe(e, r) {
406
+ if (!e?.length) return r;
407
+ const n = new Map(r.map((i) => [i.name, i])), o = [];
408
+ return e.forEach((i) => {
409
+ n.has(i) && (o.push(n.get(i)), n.delete(i));
410
+ }), n.forEach((i) => o.push(i)), o;
411
+ }
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);
416
+ });
417
+ };
418
+ return n(e?.fields?.rules), n(e?.sections?.rules), Array.from(r);
419
+ }
420
+ function Le({
421
+ activityId: e,
422
+ previousActivityId: r,
423
+ control: n,
424
+ workflowStructure: o,
425
+ sectionsRegistry: i
426
+ }) {
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({
428
+ control: n,
429
+ name: v,
430
+ 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)
438
+ return {
439
+ sections: [],
440
+ fields: { active: [], readonly: [], hidden: [] }
441
+ };
442
+ const g = je(
443
+ a.sections.active,
444
+ a.sections.readonly,
445
+ a.sections.rules,
446
+ c,
447
+ h
448
+ );
449
+ let p = [
450
+ ...g.readonly.map((_) => ({
451
+ name: _,
452
+ mode: "readonly"
453
+ })),
454
+ ...g.active.map((_) => ({
455
+ name: _,
456
+ mode: "active"
457
+ }))
458
+ ];
459
+ p = Oe(a.sections.order, p);
460
+ const E = Ne(
461
+ {
462
+ active: a.fields.active,
463
+ readonly: a.fields.readonly,
464
+ hidden: a.fields.hidden
465
+ },
466
+ a.fields.rules,
467
+ c,
468
+ h
469
+ );
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;
479
+ }
480
+ function Ye() {
481
+ if (typeof document > "u") return {};
482
+ 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;
489
+ 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) {
494
+ const i = n.textContent?.trim() ?? "";
495
+ i !== "" && (e[o] = i);
496
+ }
497
+ }), e;
498
+ }
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() !== "";
505
+ }
506
+ return fe() === null;
507
+ }, Ue = () => fe() === "true", me = q(null);
508
+ function st({
509
+ children: e,
510
+ devConfig: r
511
+ }) {
512
+ const [n, o] = se(null), i = R(() => Ye() ?? {}, []);
513
+ return x(() => {
514
+ let s = !0;
515
+ return (async () => {
516
+ const l = typeof window < "u" && window.location.hostname === "localhost", c = typeof window < "u" && window.self !== window.top;
517
+ let a = null;
518
+ 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);
523
+ }
524
+ const v = !l && c && !(qe() || Ue()), m = {
525
+ isView: v,
526
+ isReadOnly: v,
527
+ activityId: a,
528
+ // Usa o valor real detectado
529
+ previousActivityId: null,
530
+ prefilledValues: i,
531
+ showDebugSubmit: !1,
532
+ showDebugLogs: !1,
533
+ isDev: !1
534
+ };
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,
543
+ isDev: !0,
544
+ // Se devConfig tiver activityId definido explicitamente, usa ele.
545
+ // Se não, mantém o detectado (permite usar devConfig só para logs, por exemplo)
546
+ activityId: r.activityId !== void 0 ? r.activityId : a
547
+ };
548
+ }
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);
554
+ })(), () => {
555
+ s = !1;
556
+ };
557
+ }, [r, i]), n ? /* @__PURE__ */ A.jsx(me.Provider, { value: n, children: e }) : null;
558
+ }
559
+ function $() {
560
+ const e = U(me);
561
+ if (!e)
562
+ throw new Error(
563
+ "useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>"
564
+ );
565
+ return e;
566
+ }
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(() => {
572
+ 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) {
575
+ console.warn("[FluigWorkflowReact] Botão de envio do Fluig não encontrado. A validação automática pode falhar.");
576
+ return;
577
+ }
578
+ return window.beforeSendValidate = () => (e.handleSubmit(
579
+ () => {
580
+ window.beforeSendValidate = () => !0;
581
+ try {
582
+ o.dispatchEvent(new MouseEvent("click", { view: window, bubbles: !0, cancelable: !0 }));
583
+ } catch {
584
+ o.click();
585
+ }
586
+ },
587
+ (i) => {
588
+ console.error("[Validation Errors]", i), window.top?.FLUIGC?.toast ? window.top?.FLUIGC.toast({
589
+ title: "Atenção",
590
+ message: "Verifique os campos obrigatórios destacados em vermelho.",
591
+ type: "danger"
592
+ }) : alert("Verifique os campos obrigatórios.");
593
+ }
594
+ )(), !1), () => {
595
+ };
596
+ }, [e]);
597
+ }
598
+ const We = ({
599
+ workflowStructure: e,
600
+ sectionsRegistry: r,
601
+ className: n
602
+ }) => {
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,
611
+ workflowStructure: e,
612
+ sectionsRegistry: r
613
+ }), h = (f) => {
614
+ console.log("✅ [FluigWorkflowForm] Dados válidos:", f);
615
+ };
616
+ return /* @__PURE__ */ A.jsxs(
617
+ "form",
618
+ {
619
+ id: "fluig-react-form",
620
+ className: n,
621
+ onSubmit: i(h),
622
+ noValidate: !0,
623
+ 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") })
627
+ ] }),
628
+ v.length === 0 && c.activityId !== null && /* @__PURE__ */ A.jsxs("p", { children: [
629
+ "Não foi possível encontrar a atividade: ",
630
+ String(c.activityId)
631
+ ] }),
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,
639
+ {
640
+ id: f,
641
+ fields: m,
642
+ readOnly: g === "readonly"
643
+ },
644
+ f
645
+ );
646
+ }),
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)" }) })
648
+ ]
649
+ }
650
+ );
651
+ }, lt = (e) => {
652
+ const { mergedSchema: r } = ce(), n = $(), o = Se({
653
+ resolver: r ? Ve(r) : void 0,
654
+ defaultValues: n.prefilledValues,
655
+ mode: "onBlur"
656
+ });
657
+ return $e(o), x(() => {
658
+ n.showDebugLogs && (T.header("Form Initialized"), T.table(
659
+ "Prefilled Values (DOM Capture)",
660
+ 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 }) });
663
+ };
664
+ async function Be(e) {
665
+ if (!e)
666
+ 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);
672
+ }
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 };
676
+ }
677
+ function Ge(e) {
678
+ e.availableStatesCOPY || (e.availableStatesCOPY = e.availableStates);
679
+ }
680
+ function Je(e, r) {
681
+ return (e.availableStatesCOPY || e.availableStates)?.find((o) => o.sequence === r);
682
+ }
683
+ function He(e, r, n, o) {
684
+ e.availableUsers.users = [], e.availableStates = [n], r.selectActivity = () => o;
685
+ }
686
+ const ve = q(null);
687
+ function ut() {
688
+ const e = U(ve);
689
+ if (!e)
690
+ throw new Error(
691
+ "useSection deve ser usado dentro de um componente <Section>"
692
+ );
693
+ return e;
694
+ }
695
+ function ct({
696
+ id: e,
697
+ className: r,
698
+ schema: n,
699
+ children: o,
700
+ form: i,
701
+ prefilledValues: s,
702
+ readOnly: u,
703
+ fields: l = {},
704
+ hidden: c = !1
705
+ }) {
706
+ const { isView: a, activityId: v } = $(), m = v, h = le(), f = i || h;
707
+ if (!f)
708
+ return console.error(
709
+ `[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`
710
+ ), 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));
726
+ },
727
+ [f, m]
728
+ );
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, {
742
+ shouldDirty: !1,
743
+ shouldValidate: !1
744
+ });
745
+ });
746
+ }, [a, s, n, f]);
747
+ const W = R(
748
+ () => ({
749
+ id: e,
750
+ form: f,
751
+ isHidden: p,
752
+ isReadOnly: E,
753
+ isView: a,
754
+ next: _,
755
+ wf_activity_id: m
756
+ }),
757
+ [e, f, p, E, a, _, m]
758
+ );
759
+ return /* @__PURE__ */ A.jsx(ve.Provider, { value: W, children: /* @__PURE__ */ A.jsx("section", { id: e, className: [e, r].filter(Boolean).join(" "), children: o }) });
760
+ }
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 });
765
+ }
766
+ function ft() {
767
+ const e = U(pe);
768
+ if (!e)
769
+ throw new Error(
770
+ "useFluigApi deve ser usado dentro de um <FluigApiProvider>"
771
+ );
772
+ return e;
773
+ }
774
+ function Xe(e) {
775
+ return e._def?.schema ?? e;
776
+ }
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;
785
+ }
786
+ function Qe(e) {
787
+ return e?._def?.typeName !== "ZodObject" ? [] : Object.entries(e.shape);
788
+ }
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;
793
+ for (; i._def?.schema; )
794
+ 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));
799
+ });
800
+ }), Array.from(r);
801
+ }
802
+ function mt(e) {
803
+ const r = Ke(e), n = r.map(
804
+ (o) => `<input type="hidden" name="${o}" />`
805
+ ).join(`
806
+ `);
807
+ return console.log(Y.blue.bold(`
808
+ === 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(`
812
+ =====================================
813
+ `)), `<!DOCTYPE html>
814
+ <html lang="pt-br">
815
+ <head>
816
+ <meta charset="UTF-8">
817
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
818
+ <title>Workflow Fluig</title>
819
+
820
+ <link rel="stylesheet" href="/portal/style-guide/css/fluig-style-guide.min.css">
821
+
822
+ <link rel="stylesheet" crossorigin href="./main.css">
823
+ </head>
824
+ <body>
825
+ <form id="form" name="form">
826
+ <div id="root">
827
+ ${n}
828
+ </div>
829
+ </form>
830
+
831
+ <script src="./bundle.js"><\/script>
832
+ </body>
833
+ </html>`;
834
+ }
835
+ 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
849
+ };