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