@fluig-kit/ecm 1.0.16 → 1.0.18

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