@fluig-kit/ecm 1.0.20 → 1.0.21

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 p=require("react/jsx-runtime"),l=require("react"),F=require("react-hook-form"),N=require("@hookform/resolvers"),W=require("zod"),A=require("@fluig-kit/core");var U=function(e,o){for(var t={};e.length;){var r=e[0],i=r.code,s=r.message,a=r.path.join(".");if(!t[a])if("unionErrors"in r){var c=r.unionErrors[0].errors[0];t[a]={message:c.message,type:c.code}}else t[a]={message:s,type:i};if("unionErrors"in r&&r.unionErrors.forEach(function(g){return g.errors.forEach(function(d){return e.push(d)})}),o){var u=t[a].types,n=u&&u[r.code];t[a]=F.appendErrors(a,o,t,i,n?[].concat(n,r.message):r.message)}e.shift()}return t},B=function(e,o,t){return t===void 0&&(t={}),function(r,i,s){try{return Promise.resolve(function(a,c){try{var u=Promise.resolve(e[t.mode==="sync"?"parse":"parseAsync"](r,o)).then(function(n){return s.shouldUseNativeValidation&&N.validateFieldsNatively({},s),{errors:{},values:t.raw?r:n}})}catch(n){return c(n)}return u&&u.then?u.then(void 0,c):u}(0,function(a){if(function(c){return Array.isArray(c==null?void 0:c.errors)}(a))return{values:{},errors:N.toNestErrors(U(a.errors,!s.shouldUseNativeValidation&&s.criteriaMode==="all"),s)};throw a}))}catch(a){return Promise.reject(a)}}};const O=l.createContext(null);function z({children:e,baseSchema:o}){const[t,r]=l.useState([]),i=l.useMemo(()=>o??W.z.object({}),[o]),s=l.useCallback((n,g)=>{r(d=>d.some(w=>w.id===n)?d:[...d,{id:n,schema:g}])},[]),a=l.useCallback(n=>{r(g=>g.some(d=>d.id===n)?g.filter(d=>d.id!==n):g)},[]),c=l.useMemo(()=>t.length?t.map(n=>n.schema).reduce((n,g)=>n.and(g),i):i,[t,i]),u=l.useMemo(()=>({registerSchema:s,unregisterSchema:a,mergedSchema:c}),[s,a,c]);return p.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 j(e){return typeof e=="number"?e:isNaN(Number(e))?null:Number(e)}function L(e,o,t){if(!e)return!0;const r=Array.isArray(o)?o[0]:o,i=e.field??r,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 G(e,o,t,r,i){const s=new Set(e),a=new Set(o);return t==null||t.forEach(c=>{if(c.from!==void 0){const n=Array.isArray(c.from)?c.from:[c.from];if(r===null||!n.includes(r))return}if(!L(c.when,c.target,i))return;const u=Array.isArray(c.target)?c.target:[c.target];switch(c.type){case"readonly":u.forEach(n=>{a.add(n),s.delete(n)});break;case"active":u.forEach(n=>{s.add(n),a.delete(n)});break;case"hidden":u.forEach(n=>{s.delete(n),a.delete(n)});break}}),{active:Array.from(s),readonly:Array.from(a)}}function H(e,o,t,r){const i=new Set(e.active),s=new Set(e.readonly),a=new Set(e.hidden??[]);return o==null||o.forEach(c=>{if(c.from!==void 0){const n=Array.isArray(c.from)?c.from:[c.from];if(t===null||!n.includes(t))return}if(!L(c.when,c.target,r))return;const u=Array.isArray(c.target)?c.target:[c.target];switch(c.type){case"hidden":u.forEach(n=>{a.add(n),i.delete(n),s.delete(n)});break;case"active":u.forEach(n=>{i.add(n),s.delete(n),a.delete(n)});break;case"readonly":u.forEach(n=>{s.add(n),i.delete(n),a.delete(n)});break}}),{active:Array.from(i),readonly:Array.from(s),hidden:Array.from(a)}}function $(e,o){if(!(e!=null&&e.length))return o;const t=new Map(o.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 K(e){var r,i;const o=new Set,t=(s=[])=>{s.forEach(a=>{var c;a.target&&(Array.isArray(a.target)?a.target:[a.target]).forEach(n=>o.add(n)),(c=a.when)!=null&&c.field&&o.add(a.when.field)})};return t((r=e==null?void 0:e.fields)==null?void 0:r.rules),t((i=e==null?void 0:e.sections)==null?void 0:i.rules),Array.from(o)}function J({activityId:e,previousActivityId:o,control:t,workflowStructure:r,sectionsRegistry:i}){const{registerSchema:s,unregisterSchema:a}=T(),c=j(e),u=j(o),n=c!==null?r[c]:null,g=l.useMemo(()=>K(n),[c,n]),d=F.useWatch({control:t,name:g,defaultValue:{}}),w=l.useMemo(()=>{const m={};return g.forEach((f,v)=>{m[f]=Array.isArray(d)?d[v]:d}),m},[d,g]),y=l.useMemo(()=>{if(!n)return{sections:[],fields:{active:[],readonly:[],hidden:[]}};const m=G(n.sections.active,n.sections.readonly,n.sections.rules,u,w);let f=[...m.readonly.map(h=>({name:h,mode:"readonly"})),...m.active.map(h=>({name:h,mode:"active"}))];f=$(n.sections.order,f);const v=H({active:n.fields.active,readonly:n.fields.readonly,hidden:n.fields.hidden},n.fields.rules,u,w);return{sections:f,fields:v}},[n,u,w,i]);return l.useEffect(()=>{const m=y.sections.filter(f=>f.mode==="active").map(f=>f.name);m.forEach(f=>{var h;const v=(h=i==null?void 0:i[f])==null?void 0:h.schema;v&&s(f,v)}),Object.keys(i??{}).filter(f=>!m.includes(f)).forEach(a)},[y.sections,i,s,a]),y}function Q(){if(typeof document>"u")return{};const e={};return document.querySelectorAll("input[type='radio'][name]").forEach(o=>{const t=o,r=t.getAttribute("name");r&&t.checked&&(e[r]=t.value)}),document.querySelectorAll("input[name], textarea[name], select[name]").forEach(o=>{const t=o,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(o=>{var i;const t=o,r=t.getAttribute("name");if(r){const s=((i=t.textContent)==null?void 0:i.trim())??"";s!==""&&(e[r]=s)}}),e}const q=l.createContext(null);function X({children:e,devConfig:o}){const[t,r]=l.useState(null),i=l.useRef(o);l.useEffect(()=>{i.current=o},[o]);const s=l.useMemo(()=>Q()??{},[]);return l.useEffect(()=>{let a=!0;return(async()=>{var m,f;const u=typeof window<"u"&&window.location.hostname==="localhost";let n=null;try{const v=await((m=A.parentProxy.top.ECM)==null?void 0:m.workflowView);if(v){const h=await v.sequence;n=h!==void 0?Number(h):null}}catch(v){u||console.warn("[FluigRuntime] Erro Proxy:",v)}const d=(s.FORM_MODE||"").toLowerCase()==="view",w={isView:d,isReadOnly:d,activityId:n,previousActivityId:s.LASTACTIVITYID?Number(s.LASTACTIVITYID):null,prefilledValues:s,showDebugSubmit:!1,showDebugLogs:!1,isDev:!1};let y={...w};if((f=i.current)!=null&&f.enabled){const v=i.current,h=v.isView??w.isView;y={...w,...v,isView:h,isReadOnly:h,isDev:!0,activityId:v.activityId!==void 0?v.activityId:n}}a&&r(y)})(),()=>{a=!1}},[s]),t?p.jsx(q.Provider,{value:t,children:e}):null}function x(){const e=l.useContext(q);if(!e)throw new Error("useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>");return e}function Z(e){const{activityId:o,previousActivityId:t}=x();l.useEffect(()=>{o!=null&&e.setValue("CURRENTACTIVITYID",o),t!=null&&e.setValue("LASTACTIVITYID",t)},[o,t,e]),l.useEffect(()=>{if(typeof window>"u"||!window.top)return;const r=window.top.document,i=s=>{const a=s.target;(a.closest("[data-take-decision]")||a.closest("[data-take-task]")||a.closest(".movement-button"))&&(console.log("[FluigLifecycle] Ação detectada: setando modo 'edit'"),e.setValue("FORM_MODE","edit"))};return r.addEventListener("click",i),()=>r.removeEventListener("click",i)},[e]),l.useEffect(()=>{var i,s;if(typeof window>"u")return;const r=((i=window.top)==null?void 0:i.document.getElementById("send-process-button"))||((s=window.parent)==null?void 0:s.document.getElementById("workflow-actions-send"));r&&(window.beforeSendValidate=()=>{let a=!1;return e.handleSubmit(()=>{window.top.__FLUIG_REACT_FORM_DATA__=e.getValues(),e.setValue("FORM_MODE","view"),window.beforeSendValidate=()=>!0,a=!0,r.click()},c=>{var u,n;console.error("[Validation Errors]",c),(n=(u=window.top)==null?void 0:u.FLUIGC)!=null&&n.toast&&window.top.FLUIGC.toast({title:"Atenção",message:"Verifique os campos obrigatórios.",type:"danger"})})(),a})},[e])}const ee=({workflowStructure:e,sectionsRegistry:o,className:t})=>{const{control:r,handleSubmit:i,register:s,setValue:a,watch:c}=F.useFormContext(),u=x(),n=c("FORM_MODE"),g=l.useRef(!1);l.useEffect(()=>{g.current||(u.activityId!=null&&a("CURRENTACTIVITYID",u.activityId),u.previousActivityId!=null&&a("LASTACTIVITYID",u.previousActivityId),g.current=!0)},[u,a]);const{sections:d,fields:w}=J({control:r,activityId:u.activityId,previousActivityId:u.previousActivityId,workflowStructure:e,sectionsRegistry:o}),y=m=>{console.log("✅ [FluigWorkflowForm] Dados válidos:",m)};return p.jsxs("form",{id:"fluig-react-form",className:t,onSubmit:i(y),noValidate:!0,children:[p.jsxs("div",{className:"hidden",style:{display:"none"},children:[p.jsx("input",{type:"hidden",...s("CURRENTACTIVITYID")}),p.jsx("input",{type:"hidden",...s("LASTACTIVITYID")}),p.jsx("input",{type:"hidden",...s("FORM_MODE")})]}),d.length===0&&u.activityId!==null&&p.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 v=o[m];if(!v)return null;const h=v.Component,R=n==="VIEW";return p.jsx(h,{id:m,fields:w,readOnly:f==="readonly"||R},m)}),u.isDev&&u.showDebugSubmit&&p.jsx("div",{style:{width:"100%",padding:"16px",paddingTop:"0"},children:p.jsx("button",{type:"submit",className:"btn btn-primary btn-lg btn-block",children:"Submit (Debug)"})})]})},te=e=>{const{mergedSchema:o}=T(),t=x(),r=F.useForm({resolver:o?B(o):void 0,defaultValues:t.prefilledValues,mode:"onBlur"});return Z(r),l.useEffect(()=>{t.showDebugLogs&&(A.DebugLogger.header("Form Initialized"),A.DebugLogger.table("Prefilled Values (DOM Capture)",t.prefilledValues),A.DebugLogger.info("RHF Current Values",r.getValues()),A.DebugLogger.end())},[t.showDebugLogs,t.prefilledValues,r]),p.jsx(F.FormProvider,{...r,children:p.jsx(ee,{...e})})};async function ne(e){if(!e)return console.warn("[setFluigNextActivity] Nenhuma atividade informada."),!1;const{wfView:o,wkfView:t}=await re();if(!o||!t)return!1;oe(o);const r=Number(e),i=ie(o,r);return i?(se(o,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:",o.availableStatesCOPY||o.availableStates),!1)}async function re(){const e=await A.parentProxy.top.ECM.workflowView,o=await A.parentProxy.top.ECM_WKFView;return!e||!o?(console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."),{}):{wfView:e,wkfView:o}}function oe(e){e.availableStatesCOPY||(e.availableStatesCOPY=e.availableStates)}function ie(e,o){const t=e.availableStatesCOPY||e.availableStates;return t==null?void 0:t.find(r=>r.sequence===o)}function se(e,o,t,r){e.availableUsers.users=[],e.availableStates=[t],o.selectActivity=()=>r}const _=l.createContext(null);function ae(){const e=l.useContext(_);if(!e)throw new Error("useSection deve ser usado dentro de um componente <Section>");return e}function ce({id:e,className:o,schema:t,children:r,form:i,prefilledValues:s,readOnly:a,fields:c={},hidden:u=!1}){const{isView:n,activityId:g}=x(),d=g,w=F.useFormContext(),y=i||w;if(!y)return console.error(`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`),null;if(u)return null;const m=l.useCallback(b=>{var E,V,C;return(E=c.hidden)!=null&&E.includes(b)?"hidden":(V=c.readonly)!=null&&V.includes(b)?"readonly":(C=c.active)!=null&&C.includes(b)?"active":a?"readonly":"active"},[c,a]),f=l.useCallback(b=>m(b)==="hidden",[m]),v=l.useCallback(b=>m(b)==="readonly",[m]),h=l.useCallback(b=>{if(!b)return;const E=y.getValues("CURRENTACTIVITYID");y.setValue("LASTACTIVITYID",E),y.setValue("CURRENTACTIVITYID",d),ne(Number(b))},[y,d]);l.useEffect(()=>{if(!n||!s||!t||!y)return;const b=y.getValues(),E=t.shape;E&&Object.entries(E).forEach(([V,C])=>{var k,P;let S=C;for(;(k=S==null?void 0:S._def)!=null&&k.schema;)S=S._def.schema;const I=(P=S==null?void 0:S._def)==null?void 0:P.fluig;if((I==null?void 0:I.type)!=="options"||!Array.isArray(I.values)||b[V]!==void 0)return;const D={};I.values.forEach(M=>{D[M]=s[M]==="on"}),y.setValue(V,D,{shouldDirty:!1,shouldValidate:!1})})},[n,s,t,y]);const R=l.useMemo(()=>({id:e,form:y,isHidden:f,isReadOnly:v,isView:n,next:h,wf_activity_id:d}),[e,y,f,v,n,h,d]);return p.jsx(_.Provider,{value:R,children:p.jsx("section",{id:e,className:[e,o].filter(Boolean).join(" "),children:r})})}const Y=l.createContext(null);function ue({children:e,config:o}){const t=l.useMemo(()=>A.createFluigClient(o),[o]);return p.jsx(Y.Provider,{value:t,children:e})}function le(){const e=l.useContext(Y);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=ue;exports.FluigRuntimeProvider=X;exports.FluigWorkflowForm=te;exports.SchemaRegistryProvider=z;exports.Section=ce;exports.useFluigApi=le;exports.useFluigRuntime=x;exports.useSchemaRegistry=T;exports.useSection=ae;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),l=require("react"),I=require("react-hook-form"),P=require("@hookform/resolvers"),Y=require("zod"),A=require("@fluig-kit/core");var U=function(e,o){for(var t={};e.length;){var r=e[0],i=r.code,s=r.message,c=r.path.join(".");if(!t[c])if("unionErrors"in r){var a=r.unionErrors[0].errors[0];t[c]={message:a.message,type:a.code}}else t[c]={message:s,type:i};if("unionErrors"in r&&r.unionErrors.forEach(function(g){return g.errors.forEach(function(d){return e.push(d)})}),o){var u=t[c].types,n=u&&u[r.code];t[c]=I.appendErrors(c,o,t,i,n?[].concat(n,r.message):r.message)}e.shift()}return t},B=function(e,o,t){return t===void 0&&(t={}),function(r,i,s){try{return Promise.resolve(function(c,a){try{var u=Promise.resolve(e[t.mode==="sync"?"parse":"parseAsync"](r,o)).then(function(n){return s.shouldUseNativeValidation&&P.validateFieldsNatively({},s),{errors:{},values:t.raw?r: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:P.toNestErrors(U(c.errors,!s.shouldUseNativeValidation&&s.criteriaMode==="all"),s)};throw c}))}catch(c){return Promise.reject(c)}}};const j=l.createContext(null);function z({children:e,baseSchema:o}){const[t,r]=l.useState([]),i=l.useMemo(()=>o??Y.z.object({}),[o]),s=l.useCallback((n,g)=>{r(d=>d.some(w=>w.id===n)?d:[...d,{id:n,schema:g}])},[]),c=l.useCallback(n=>{r(g=>g.some(d=>d.id===n)?g.filter(d=>d.id!==n):g)},[]),a=l.useMemo(()=>t.length?t.map(n=>n.schema).reduce((n,g)=>n.and(g),i):i,[t,i]),u=l.useMemo(()=>({registerSchema:s,unregisterSchema:c,mergedSchema:a}),[s,c,a]);return p.jsx(j.Provider,{value:u,children:e})}function T(){const e=l.useContext(j);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,t){if(!e)return!0;const r=Array.isArray(o)?o[0]:o,i=e.field??r,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 G(e,o,t,r,i){const s=new Set(e),c=new Set(o);return t==null||t.forEach(a=>{if(a.from!==void 0){const n=Array.isArray(a.from)?a.from:[a.from];if(r===null||!n.includes(r))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,o,t,r){const i=new Set(e.active),s=new Set(e.readonly),c=new Set(e.hidden??[]);return o==null||o.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,r))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,o){if(!(e!=null&&e.length))return o;const t=new Map(o.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 K(e){var r,i;const o=new Set,t=(s=[])=>{s.forEach(c=>{var a;c.target&&(Array.isArray(c.target)?c.target:[c.target]).forEach(n=>o.add(n)),(a=c.when)!=null&&a.field&&o.add(c.when.field)})};return t((r=e==null?void 0:e.fields)==null?void 0:r.rules),t((i=e==null?void 0:e.sections)==null?void 0:i.rules),Array.from(o)}function J({activityId:e,previousActivityId:o,control:t,workflowStructure:r,sectionsRegistry:i}){const{registerSchema:s,unregisterSchema:c}=T(),a=N(e),u=N(o),n=a!==null?r[a]:null,g=l.useMemo(()=>K(n),[a,n]),d=I.useWatch({control:t,name:g,defaultValue:{}}),w=l.useMemo(()=>{const m={};return g.forEach((f,v)=>{m[f]=Array.isArray(d)?d[v]:d}),m},[d,g]),y=l.useMemo(()=>{if(!n)return{sections:[],fields:{active:[],readonly:[],hidden:[]}};const m=G(n.sections.active,n.sections.readonly,n.sections.rules,u,w);let f=[...m.readonly.map(h=>({name:h,mode:"readonly"})),...m.active.map(h=>({name:h,mode:"active"}))];f=$(n.sections.order,f);const v=H({active:n.fields.active,readonly:n.fields.readonly,hidden:n.fields.hidden},n.fields.rules,u,w);return{sections:f,fields:v}},[n,u,w,i]);return l.useEffect(()=>{const m=y.sections.filter(f=>f.mode==="active").map(f=>f.name);m.forEach(f=>{var h;const v=(h=i==null?void 0:i[f])==null?void 0:h.schema;v&&s(f,v)}),Object.keys(i??{}).filter(f=>!m.includes(f)).forEach(c)},[y.sections,i,s,c]),y}function Q(){if(typeof document>"u")return{};const e={};return document.querySelectorAll("input[type='radio'][name]").forEach(o=>{const t=o,r=t.getAttribute("name");r&&t.checked&&(e[r]=t.value)}),document.querySelectorAll("input[name], textarea[name], select[name]").forEach(o=>{const t=o,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(o=>{var i;const t=o,r=t.getAttribute("name");if(r){const s=((i=t.textContent)==null?void 0:i.trim())??"";s!==""&&(e[r]=s)}}),e}const q=l.createContext(null);function X({children:e,devConfig:o}){const[t,r]=l.useState(null),i=l.useRef(o);l.useEffect(()=>{i.current=o},[o]);const s=l.useMemo(()=>Q()??{},[]);return l.useEffect(()=>{let c=!0;return(async()=>{var m,f;const u=typeof window<"u"&&window.location.hostname==="localhost";let n=null;try{const v=await((m=A.parentProxy.top.ECM)==null?void 0:m.workflowView);if(v){const h=await v.sequence;n=h!==void 0?Number(h):null}}catch(v){u||console.warn("[FluigRuntime] Erro Proxy:",v)}const d=(s.FORM_MODE||"").toLowerCase()==="VIEW",w={isView:d,isReadOnly:d,activityId:n,previousActivityId:s.LASTACTIVITYID?Number(s.LASTACTIVITYID):null,prefilledValues:s,showDebugSubmit:!1,showDebugLogs:!1,isDev:!1};let y={...w};if((f=i.current)!=null&&f.enabled){const v=i.current,h=v.isView??w.isView;y={...w,...v,isView:h,isReadOnly:h,isDev:!0,activityId:v.activityId!==void 0?v.activityId:n}}c&&r(y)})(),()=>{c=!1}},[s]),t?p.jsx(q.Provider,{value:t,children:e}):null}function x(){const e=l.useContext(q);if(!e)throw new Error("useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>");return e}function Z(e){const{activityId:o,previousActivityId:t}=x();l.useEffect(()=>{o!=null&&e.setValue("CURRENTACTIVITYID",o),t!=null&&e.setValue("LASTACTIVITYID",t)},[o,t,e]),l.useEffect(()=>{if(typeof window>"u"||!window.top)return;const r=window.top.document,i=s=>{if(s.target.closest("[data-take-decision], [data-take-task], .movement-button")){e.setValue("FORM_MODE","EDIT"),console.log("MODO EDIT");const a=document.querySelector('input[name="FORM_MODE"]');a&&(a.value="EDIT")}};return r.addEventListener("click",i),()=>r.removeEventListener("click",i)},[e]),l.useEffect(()=>{var s,c;if(typeof window>"u")return;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"));if(!r)return;let i=!1;window.beforeSendValidate=()=>i?!0:(e.handleSubmit(a=>{window.top.__FLUIG_REACT_FORM_DATA__=a,e.setValue("FORM_MODE","VIEW"),console.log("MODO VIEW");const u=document.querySelector('input[name="FORM_MODE"]');u&&(u.value="VIEW"),i=!0,setTimeout(()=>{r.click()},1)},a=>{var u,n;console.error("[Validation Errors]",a),i=!1,(n=(u=window.top)==null?void 0:u.FLUIGC)!=null&&n.toast&&window.top.FLUIGC.toast({title:"Atenção",message:"Verifique os campos obrigatórios.",type:"danger"})})(),!1)},[e])}const ee=({workflowStructure:e,sectionsRegistry:o,className:t})=>{const{control:r,handleSubmit:i,register:s,setValue:c,watch:a}=I.useFormContext(),u=x(),n=a("FORM_MODE"),g=l.useRef(!1);l.useEffect(()=>{g.current||(u.activityId!=null&&c("CURRENTACTIVITYID",u.activityId),u.previousActivityId!=null&&c("LASTACTIVITYID",u.previousActivityId),g.current=!0)},[u,c]);const{sections:d,fields:w}=J({control:r,activityId:u.activityId,previousActivityId:u.previousActivityId,workflowStructure:e,sectionsRegistry:o}),y=m=>{console.log("✅ [FluigWorkflowForm] Dados válidos:",m)};return p.jsxs("form",{id:"fluig-react-form",className:t,onSubmit:i(y),noValidate:!0,children:[p.jsxs("div",{className:"hidden",style:{display:"none"},children:[p.jsx("input",{type:"hidden",...s("CURRENTACTIVITYID")}),p.jsx("input",{type:"hidden",...s("LASTACTIVITYID")}),p.jsx("input",{type:"hidden",...s("FORM_MODE")})]}),d.length===0&&u.activityId!==null&&p.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 v=o[m];if(!v)return null;const h=v.Component,D=n==="VIEW";return p.jsx(h,{id:m,fields:w,readOnly:f==="readonly"||D},m)}),u.isDev&&u.showDebugSubmit&&p.jsx("div",{style:{width:"100%",padding:"16px",paddingTop:"0"},children:p.jsx("button",{type:"submit",className:"btn btn-primary btn-lg btn-block",children:"Submit (Debug)"})})]})},te=e=>{const{mergedSchema:o}=T(),t=x(),r=I.useForm({resolver:o?B(o):void 0,defaultValues:t.prefilledValues,mode:"onBlur"});return Z(r),l.useEffect(()=>{t.showDebugLogs&&(A.DebugLogger.header("Form Initialized"),A.DebugLogger.table("Prefilled Values (DOM Capture)",t.prefilledValues),A.DebugLogger.info("RHF Current Values",r.getValues()),A.DebugLogger.end())},[t.showDebugLogs,t.prefilledValues,r]),p.jsx(I.FormProvider,{...r,children:p.jsx(ee,{...e})})};async function ne(e){if(!e)return console.warn("[setFluigNextActivity] Nenhuma atividade informada."),!1;const{wfView:o,wkfView:t}=await re();if(!o||!t)return!1;oe(o);const r=Number(e),i=ie(o,r);return i?(se(o,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:",o.availableStatesCOPY||o.availableStates),!1)}async function re(){const e=await A.parentProxy.top.ECM.workflowView,o=await A.parentProxy.top.ECM_WKFView;return!e||!o?(console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."),{}):{wfView:e,wkfView:o}}function oe(e){e.availableStatesCOPY||(e.availableStatesCOPY=e.availableStates)}function ie(e,o){const t=e.availableStatesCOPY||e.availableStates;return t==null?void 0:t.find(r=>r.sequence===o)}function se(e,o,t,r){e.availableUsers.users=[],e.availableStates=[t],o.selectActivity=()=>r}const _=l.createContext(null);function ae(){const e=l.useContext(_);if(!e)throw new Error("useSection deve ser usado dentro de um componente <Section>");return e}function ce({id:e,className:o,schema:t,children:r,form:i,prefilledValues:s,readOnly:c,fields:a={},hidden:u=!1}){const{isView:n,activityId:g}=x(),d=g,w=I.useFormContext(),y=i||w;if(!y)return console.error(`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`),null;if(u)return null;const m=l.useCallback(b=>{var S,F,C;return(S=a.hidden)!=null&&S.includes(b)?"hidden":(F=a.readonly)!=null&&F.includes(b)?"readonly":(C=a.active)!=null&&C.includes(b)?"active":c?"readonly":"active"},[a,c]),f=l.useCallback(b=>m(b)==="hidden",[m]),v=l.useCallback(b=>m(b)==="readonly",[m]),h=l.useCallback(b=>{if(!b)return;const S=y.getValues("CURRENTACTIVITYID");y.setValue("LASTACTIVITYID",S),y.setValue("CURRENTACTIVITYID",d),ne(Number(b))},[y,d]);l.useEffect(()=>{if(!n||!s||!t||!y)return;const b=y.getValues(),S=t.shape;S&&Object.entries(S).forEach(([F,C])=>{var M,k;let E=C;for(;(M=E==null?void 0:E._def)!=null&&M.schema;)E=E._def.schema;const V=(k=E==null?void 0:E._def)==null?void 0:k.fluig;if((V==null?void 0:V.type)!=="options"||!Array.isArray(V.values)||b[F]!==void 0)return;const R={};V.values.forEach(O=>{R[O]=s[O]==="on"}),y.setValue(F,R,{shouldDirty:!1,shouldValidate:!1})})},[n,s,t,y]);const D=l.useMemo(()=>({id:e,form:y,isHidden:f,isReadOnly:v,isView:n,next:h,wf_activity_id:d}),[e,y,f,v,n,h,d]);return p.jsx(_.Provider,{value:D,children:p.jsx("section",{id:e,className:[e,o].filter(Boolean).join(" "),children:r})})}const W=l.createContext(null);function ue({children:e,config:o}){const t=l.useMemo(()=>A.createFluigClient(o),[o]);return p.jsx(W.Provider,{value:t,children:e})}function le(){const e=l.useContext(W);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=ue;exports.FluigRuntimeProvider=X;exports.FluigWorkflowForm=te;exports.SchemaRegistryProvider=z;exports.Section=ce;exports.useFluigApi=le;exports.useFluigRuntime=x;exports.useSchemaRegistry=T;exports.useSection=ae;
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
- import { jsx as g, jsxs as N } from "react/jsx-runtime";
2
- import { createContext as x, useState as q, useMemo as A, useCallback as I, useContext as D, useEffect as b, useRef as U } from "react";
3
- import { appendErrors as K, useWatch as J, useForm as Q, FormProvider as X, useFormContext as W } from "react-hook-form";
1
+ import { jsx as g, jsxs as M } from "react/jsx-runtime";
2
+ import { createContext as D, useState as Y, useMemo as A, useCallback as b, useContext as x, useEffect as E, useRef as q } from "react";
3
+ import { appendErrors as K, useWatch as J, useForm as Q, FormProvider as X, useFormContext as U } from "react-hook-form";
4
4
  import { validateFieldsNatively as Z, toNestErrors as ee } from "@hookform/resolvers";
5
5
  import { z as te } from "zod";
6
- import { parentProxy as k, DebugLogger as T, createFluigClient as ne } from "@fluig-kit/core";
7
- import { DebugLogger as ke, createFluigClient as Pe, parentProxy as Me } from "@fluig-kit/core";
6
+ import { parentProxy as O, DebugLogger as T, createFluigClient as ne } from "@fluig-kit/core";
7
+ import { DebugLogger as Oe, createFluigClient as Ne, parentProxy as ke } from "@fluig-kit/core";
8
8
  var re = function(e, o) {
9
9
  for (var t = {}; e.length; ) {
10
- var r = e[0], i = r.code, a = r.message, s = r.path.join(".");
11
- if (!t[s]) if ("unionErrors" in r) {
12
- var c = r.unionErrors[0].errors[0];
13
- t[s] = { message: c.message, type: c.code };
14
- } else t[s] = { message: a, type: i };
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
15
  if ("unionErrors" in r && r.unionErrors.forEach(function(v) {
16
16
  return v.errors.forEach(function(l) {
17
17
  return e.push(l);
18
18
  });
19
19
  }), o) {
20
- var u = t[s].types, n = u && u[r.code];
21
- t[s] = K(s, o, t, i, n ? [].concat(n, r.message) : r.message);
20
+ var u = t[c].types, n = u && u[r.code];
21
+ t[c] = K(c, o, t, i, n ? [].concat(n, r.message) : r.message);
22
22
  }
23
23
  e.shift();
24
24
  }
@@ -26,56 +26,56 @@ var re = function(e, o) {
26
26
  }, oe = function(e, o, t) {
27
27
  return t === void 0 && (t = {}), function(r, i, a) {
28
28
  try {
29
- return Promise.resolve(function(s, c) {
29
+ return Promise.resolve(function(c, s) {
30
30
  try {
31
31
  var u = Promise.resolve(e[t.mode === "sync" ? "parse" : "parseAsync"](r, o)).then(function(n) {
32
32
  return a.shouldUseNativeValidation && Z({}, a), { errors: {}, values: t.raw ? r : n };
33
33
  });
34
34
  } catch (n) {
35
- return c(n);
35
+ return s(n);
36
36
  }
37
- return u && u.then ? u.then(void 0, c) : u;
38
- }(0, function(s) {
39
- if (function(c) {
40
- return Array.isArray(c == null ? void 0 : c.errors);
41
- }(s)) return { values: {}, errors: ee(re(s.errors, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a) };
42
- throw s;
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;
43
43
  }));
44
- } catch (s) {
45
- return Promise.reject(s);
44
+ } catch (c) {
45
+ return Promise.reject(c);
46
46
  }
47
47
  };
48
48
  };
49
- const j = x(
49
+ const j = D(
50
50
  null
51
51
  );
52
- function Ie({
52
+ function be({
53
53
  children: e,
54
54
  baseSchema: o
55
55
  }) {
56
- const [t, r] = q([]), i = A(() => o ?? te.object({}), [o]), a = I((n, v) => {
56
+ const [t, r] = Y([]), i = A(() => o ?? te.object({}), [o]), a = b((n, v) => {
57
57
  r((l) => l.some((p) => p.id === n) ? l : [...l, { id: n, schema: v }]);
58
- }, []), s = I((n) => {
58
+ }, []), c = b((n) => {
59
59
  r((v) => v.some((l) => l.id === n) ? v.filter((l) => l.id !== n) : v);
60
- }, []), c = A(() => t.length ? t.map((n) => n.schema).reduce((n, v) => n.and(v), i) : i, [t, i]), u = A(
60
+ }, []), s = A(() => t.length ? t.map((n) => n.schema).reduce((n, v) => n.and(v), i) : i, [t, i]), u = A(
61
61
  () => ({
62
62
  registerSchema: a,
63
- unregisterSchema: s,
64
- mergedSchema: c
63
+ unregisterSchema: c,
64
+ mergedSchema: s
65
65
  }),
66
- [a, s, c]
66
+ [a, c, s]
67
67
  );
68
68
  return /* @__PURE__ */ g(j.Provider, { value: u, children: e });
69
69
  }
70
70
  function B() {
71
- const e = D(j);
71
+ const e = x(j);
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 Y(e) {
78
+ function W(e) {
79
79
  return typeof e == "number" ? e : isNaN(Number(e)) ? null : Number(e);
80
80
  }
81
81
  function z(e, o, t) {
@@ -84,63 +84,63 @@ function z(e, o, t) {
84
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
85
  }
86
86
  function ie(e, o, t, r, i) {
87
- const a = new Set(e), s = new Set(o);
88
- return t == null || t.forEach((c) => {
89
- if (c.from !== void 0) {
90
- const n = Array.isArray(c.from) ? c.from : [c.from];
87
+ const a = new Set(e), c = new Set(o);
88
+ return t == null || t.forEach((s) => {
89
+ if (s.from !== void 0) {
90
+ const n = Array.isArray(s.from) ? s.from : [s.from];
91
91
  if (r === null || !n.includes(r)) return;
92
92
  }
93
- if (!z(c.when, c.target, i)) return;
94
- const u = Array.isArray(c.target) ? c.target : [c.target];
95
- switch (c.type) {
93
+ if (!z(s.when, s.target, i)) return;
94
+ const u = Array.isArray(s.target) ? s.target : [s.target];
95
+ switch (s.type) {
96
96
  case "readonly":
97
97
  u.forEach((n) => {
98
- s.add(n), a.delete(n);
98
+ c.add(n), a.delete(n);
99
99
  });
100
100
  break;
101
101
  case "active":
102
102
  u.forEach((n) => {
103
- a.add(n), s.delete(n);
103
+ a.add(n), c.delete(n);
104
104
  });
105
105
  break;
106
106
  case "hidden":
107
107
  u.forEach((n) => {
108
- a.delete(n), s.delete(n);
108
+ a.delete(n), c.delete(n);
109
109
  });
110
110
  break;
111
111
  }
112
- }), { active: Array.from(a), readonly: Array.from(s) };
112
+ }), { active: Array.from(a), readonly: Array.from(c) };
113
113
  }
114
114
  function ae(e, o, t, r) {
115
- const i = new Set(e.active), a = new Set(e.readonly), s = new Set(e.hidden ?? []);
116
- return o == null || o.forEach((c) => {
117
- if (c.from !== void 0) {
118
- const n = Array.isArray(c.from) ? c.from : [c.from];
115
+ const i = new Set(e.active), a = new Set(e.readonly), c = new Set(e.hidden ?? []);
116
+ return o == null || o.forEach((s) => {
117
+ if (s.from !== void 0) {
118
+ const n = Array.isArray(s.from) ? s.from : [s.from];
119
119
  if (t === null || !n.includes(t)) return;
120
120
  }
121
- if (!z(c.when, c.target, r)) return;
122
- const u = Array.isArray(c.target) ? c.target : [c.target];
123
- switch (c.type) {
121
+ if (!z(s.when, s.target, r)) return;
122
+ const u = Array.isArray(s.target) ? s.target : [s.target];
123
+ switch (s.type) {
124
124
  case "hidden":
125
125
  u.forEach((n) => {
126
- s.add(n), i.delete(n), a.delete(n);
126
+ c.add(n), i.delete(n), a.delete(n);
127
127
  });
128
128
  break;
129
129
  case "active":
130
130
  u.forEach((n) => {
131
- i.add(n), a.delete(n), s.delete(n);
131
+ i.add(n), a.delete(n), c.delete(n);
132
132
  });
133
133
  break;
134
134
  case "readonly":
135
135
  u.forEach((n) => {
136
- a.add(n), i.delete(n), s.delete(n);
136
+ a.add(n), i.delete(n), c.delete(n);
137
137
  });
138
138
  break;
139
139
  }
140
140
  }), {
141
141
  active: Array.from(i),
142
142
  readonly: Array.from(a),
143
- hidden: Array.from(s)
143
+ hidden: Array.from(c)
144
144
  };
145
145
  }
146
146
  function se(e, o) {
@@ -153,9 +153,9 @@ function se(e, o) {
153
153
  function ce(e) {
154
154
  var r, i;
155
155
  const o = /* @__PURE__ */ new Set(), t = (a = []) => {
156
- a.forEach((s) => {
157
- var c;
158
- s.target && (Array.isArray(s.target) ? s.target : [s.target]).forEach((n) => o.add(n)), (c = s.when) != null && c.field && o.add(s.when.field);
156
+ a.forEach((c) => {
157
+ var s;
158
+ c.target && (Array.isArray(c.target) ? c.target : [c.target]).forEach((n) => o.add(n)), (s = c.when) != null && s.field && o.add(c.when.field);
159
159
  });
160
160
  };
161
161
  return t((r = e == null ? void 0 : e.fields) == null ? void 0 : r.rules), t((i = e == null ? void 0 : e.sections) == null ? void 0 : i.rules), Array.from(o);
@@ -167,7 +167,7 @@ function ue({
167
167
  workflowStructure: r,
168
168
  sectionsRegistry: i
169
169
  }) {
170
- const { registerSchema: a, unregisterSchema: s } = B(), c = Y(e), u = Y(o), n = c !== null ? r[c] : null, v = A(() => ce(n), [c, n]), l = J({
170
+ const { registerSchema: a, unregisterSchema: c } = B(), s = W(e), u = W(o), n = s !== null ? r[s] : null, v = A(() => ce(n), [s, n]), l = J({
171
171
  control: t,
172
172
  name: v,
173
173
  defaultValue: {}
@@ -212,14 +212,14 @@ function ue({
212
212
  );
213
213
  return { sections: d, fields: m };
214
214
  }, [n, u, p, i]);
215
- return b(() => {
215
+ return E(() => {
216
216
  const f = y.sections.filter((d) => d.mode === "active").map((d) => d.name);
217
217
  f.forEach((d) => {
218
218
  var h;
219
219
  const m = (h = i == null ? void 0 : i[d]) == null ? void 0 : h.schema;
220
220
  m && a(d, m);
221
- }), Object.keys(i ?? {}).filter((d) => !f.includes(d)).forEach(s);
222
- }, [y.sections, i, a, s]), y;
221
+ }), Object.keys(i ?? {}).filter((d) => !f.includes(d)).forEach(c);
222
+ }, [y.sections, i, a, c]), y;
223
223
  }
224
224
  function le() {
225
225
  if (typeof document > "u") return {};
@@ -241,24 +241,24 @@ function le() {
241
241
  }
242
242
  }), e;
243
243
  }
244
- const G = x(null);
245
- function Ee({
244
+ const G = D(null);
245
+ function Ve({
246
246
  children: e,
247
247
  devConfig: o
248
248
  }) {
249
- const [t, r] = q(null), i = U(o);
250
- b(() => {
249
+ const [t, r] = Y(null), i = q(o);
250
+ E(() => {
251
251
  i.current = o;
252
252
  }, [o]);
253
253
  const a = A(() => le() ?? {}, []);
254
- return b(() => {
255
- let s = !0;
254
+ return E(() => {
255
+ let c = !0;
256
256
  return (async () => {
257
257
  var f, d;
258
258
  const u = typeof window < "u" && window.location.hostname === "localhost";
259
259
  let n = null;
260
260
  try {
261
- const m = await ((f = k.top.ECM) == null ? void 0 : f.workflowView);
261
+ const m = await ((f = O.top.ECM) == null ? void 0 : f.workflowView);
262
262
  if (m) {
263
263
  const h = await m.sequence;
264
264
  n = h !== void 0 ? Number(h) : null;
@@ -266,7 +266,7 @@ function Ee({
266
266
  } catch (m) {
267
267
  u || console.warn("[FluigRuntime] Erro Proxy:", m);
268
268
  }
269
- const l = (a.FORM_MODE || "").toLowerCase() === "view", p = {
269
+ const l = (a.FORM_MODE || "").toLowerCase() === "VIEW", p = {
270
270
  isView: l,
271
271
  isReadOnly: l,
272
272
  activityId: n,
@@ -288,14 +288,14 @@ function Ee({
288
288
  activityId: m.activityId !== void 0 ? m.activityId : n
289
289
  };
290
290
  }
291
- s && r(y);
291
+ c && r(y);
292
292
  })(), () => {
293
- s = !1;
293
+ c = !1;
294
294
  };
295
295
  }, [a]), t ? /* @__PURE__ */ g(G.Provider, { value: t, children: e }) : null;
296
296
  }
297
297
  function R() {
298
- const e = D(G);
298
+ const e = x(G);
299
299
  if (!e)
300
300
  throw new Error(
301
301
  "useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>"
@@ -304,35 +304,41 @@ function R() {
304
304
  }
305
305
  function de(e) {
306
306
  const { activityId: o, previousActivityId: t } = R();
307
- b(() => {
307
+ E(() => {
308
308
  o != null && e.setValue("CURRENTACTIVITYID", o), t != null && e.setValue("LASTACTIVITYID", t);
309
- }, [o, t, e]), b(() => {
309
+ }, [o, t, e]), E(() => {
310
310
  if (typeof window > "u" || !window.top) return;
311
311
  const r = window.top.document, i = (a) => {
312
- const s = a.target;
313
- (s.closest("[data-take-decision]") || s.closest("[data-take-task]") || s.closest(".movement-button")) && (console.log("[FluigLifecycle] Ação detectada: setando modo 'edit'"), e.setValue("FORM_MODE", "edit"));
312
+ if (a.target.closest("[data-take-decision], [data-take-task], .movement-button")) {
313
+ e.setValue("FORM_MODE", "EDIT"), console.log("MODO EDIT");
314
+ const s = document.querySelector('input[name="FORM_MODE"]');
315
+ s && (s.value = "EDIT");
316
+ }
314
317
  };
315
318
  return r.addEventListener("click", i), () => r.removeEventListener("click", i);
316
- }, [e]), b(() => {
317
- var i, a;
319
+ }, [e]), E(() => {
320
+ var a, c;
318
321
  if (typeof window > "u") return;
319
- const r = ((i = window.top) == null ? void 0 : i.document.getElementById("send-process-button")) || ((a = window.parent) == null ? void 0 : a.document.getElementById("workflow-actions-send"));
320
- r && (window.beforeSendValidate = () => {
321
- let s = !1;
322
- return e.handleSubmit(
323
- () => {
324
- window.top.__FLUIG_REACT_FORM_DATA__ = e.getValues(), e.setValue("FORM_MODE", "view"), window.beforeSendValidate = () => !0, s = !0, r.click();
325
- },
326
- (c) => {
327
- var u, n;
328
- console.error("[Validation Errors]", c), (n = (u = window.top) == null ? void 0 : u.FLUIGC) != null && n.toast && window.top.FLUIGC.toast({
329
- title: "Atenção",
330
- message: "Verifique os campos obrigatórios.",
331
- type: "danger"
332
- });
333
- }
334
- )(), s;
335
- });
322
+ const r = ((a = window.top) == null ? void 0 : a.document.getElementById("send-process-button")) || ((c = window.parent) == null ? void 0 : c.document.getElementById("workflow-actions-send"));
323
+ if (!r) return;
324
+ let i = !1;
325
+ window.beforeSendValidate = () => i ? !0 : (e.handleSubmit(
326
+ (s) => {
327
+ window.top.__FLUIG_REACT_FORM_DATA__ = s, e.setValue("FORM_MODE", "VIEW"), console.log("MODO VIEW");
328
+ const u = document.querySelector('input[name="FORM_MODE"]');
329
+ u && (u.value = "VIEW"), i = !0, setTimeout(() => {
330
+ r.click();
331
+ }, 1);
332
+ },
333
+ (s) => {
334
+ var u, n;
335
+ console.error("[Validation Errors]", s), i = !1, (n = (u = window.top) == null ? void 0 : u.FLUIGC) != null && n.toast && window.top.FLUIGC.toast({
336
+ title: "Atenção",
337
+ message: "Verifique os campos obrigatórios.",
338
+ type: "danger"
339
+ });
340
+ }
341
+ )(), !1);
336
342
  }, [e]);
337
343
  }
338
344
  const fe = ({
@@ -340,10 +346,10 @@ const fe = ({
340
346
  sectionsRegistry: o,
341
347
  className: t
342
348
  }) => {
343
- const { control: r, handleSubmit: i, register: a, setValue: s, watch: c } = W(), u = R(), n = c("FORM_MODE"), v = U(!1);
344
- b(() => {
345
- v.current || (u.activityId != null && s("CURRENTACTIVITYID", u.activityId), u.previousActivityId != null && s("LASTACTIVITYID", u.previousActivityId), v.current = !0);
346
- }, [u, s]);
349
+ const { control: r, handleSubmit: i, register: a, setValue: c, watch: s } = U(), u = R(), n = s("FORM_MODE"), v = q(!1);
350
+ E(() => {
351
+ v.current || (u.activityId != null && c("CURRENTACTIVITYID", u.activityId), u.previousActivityId != null && c("LASTACTIVITYID", u.previousActivityId), v.current = !0);
352
+ }, [u, c]);
347
353
  const { sections: l, fields: p } = ue({
348
354
  control: r,
349
355
  activityId: u.activityId,
@@ -351,7 +357,7 @@ const fe = ({
351
357
  workflowStructure: e,
352
358
  sectionsRegistry: o
353
359
  });
354
- return /* @__PURE__ */ N(
360
+ return /* @__PURE__ */ M(
355
361
  "form",
356
362
  {
357
363
  id: "fluig-react-form",
@@ -361,12 +367,12 @@ const fe = ({
361
367
  }),
362
368
  noValidate: !0,
363
369
  children: [
364
- /* @__PURE__ */ N("div", { className: "hidden", style: { display: "none" }, children: [
370
+ /* @__PURE__ */ M("div", { className: "hidden", style: { display: "none" }, children: [
365
371
  /* @__PURE__ */ g("input", { type: "hidden", ...a("CURRENTACTIVITYID") }),
366
372
  /* @__PURE__ */ g("input", { type: "hidden", ...a("LASTACTIVITYID") }),
367
373
  /* @__PURE__ */ g("input", { type: "hidden", ...a("FORM_MODE") })
368
374
  ] }),
369
- l.length === 0 && u.activityId !== null && /* @__PURE__ */ N("p", { children: [
375
+ l.length === 0 && u.activityId !== null && /* @__PURE__ */ M("p", { children: [
370
376
  "Não foi possível encontrar a atividade: ",
371
377
  String(u.activityId)
372
378
  ] }),
@@ -395,7 +401,7 @@ const fe = ({
395
401
  defaultValues: t.prefilledValues,
396
402
  mode: "onBlur"
397
403
  });
398
- return de(r), b(() => {
404
+ return de(r), E(() => {
399
405
  t.showDebugLogs && (T.header("Form Initialized"), T.table(
400
406
  "Prefilled Values (DOM Capture)",
401
407
  t.prefilledValues
@@ -412,7 +418,7 @@ async function me(e) {
412
418
  return i ? (pe(o, 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:", o.availableStatesCOPY || o.availableStates), !1);
413
419
  }
414
420
  async function ve() {
415
- const e = await k.top.ECM.workflowView, o = await k.top.ECM_WKFView;
421
+ const e = await O.top.ECM.workflowView, o = await O.top.ECM_WKFView;
416
422
  return !e || !o ? (console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."), {}) : { wfView: e, wkfView: o };
417
423
  }
418
424
  function ye(e) {
@@ -425,9 +431,9 @@ function he(e, o) {
425
431
  function pe(e, o, t, r) {
426
432
  e.availableUsers.users = [], e.availableStates = [t], o.selectActivity = () => r;
427
433
  }
428
- const $ = x(null);
434
+ const $ = D(null);
429
435
  function Ce() {
430
- const e = D($);
436
+ const e = x($);
431
437
  if (!e)
432
438
  throw new Error(
433
439
  "useSection deve ser usado dentro de um componente <Section>"
@@ -441,56 +447,56 @@ function Te({
441
447
  children: r,
442
448
  form: i,
443
449
  prefilledValues: a,
444
- readOnly: s,
445
- fields: c = {},
450
+ readOnly: c,
451
+ fields: s = {},
446
452
  hidden: u = !1
447
453
  }) {
448
- const { isView: n, activityId: v } = R(), l = v, p = W(), y = i || p;
454
+ const { isView: n, activityId: v } = R(), l = v, p = U(), y = i || p;
449
455
  if (!y)
450
456
  return console.error(
451
457
  `[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`
452
458
  ), null;
453
459
  if (u) return null;
454
- const f = I(
460
+ const f = b(
455
461
  (w) => {
456
- var V, E, C;
457
- return (V = c.hidden) != null && V.includes(w) ? "hidden" : (E = c.readonly) != null && E.includes(w) ? "readonly" : (C = c.active) != null && C.includes(w) ? "active" : s ? "readonly" : "active";
462
+ var S, V, C;
463
+ return (S = s.hidden) != null && S.includes(w) ? "hidden" : (V = s.readonly) != null && V.includes(w) ? "readonly" : (C = s.active) != null && C.includes(w) ? "active" : c ? "readonly" : "active";
458
464
  },
459
- [c, s]
460
- ), d = I(
465
+ [s, c]
466
+ ), d = b(
461
467
  (w) => f(w) === "hidden",
462
468
  [f]
463
- ), m = I(
469
+ ), m = b(
464
470
  (w) => f(w) === "readonly",
465
471
  [f]
466
- ), h = I(
472
+ ), h = b(
467
473
  (w) => {
468
474
  if (!w) return;
469
- const V = y.getValues("CURRENTACTIVITYID");
470
- y.setValue("LASTACTIVITYID", V), y.setValue("CURRENTACTIVITYID", l), me(Number(w));
475
+ const S = y.getValues("CURRENTACTIVITYID");
476
+ y.setValue("LASTACTIVITYID", S), y.setValue("CURRENTACTIVITYID", l), me(Number(w));
471
477
  },
472
478
  [y, l]
473
479
  );
474
- b(() => {
480
+ E(() => {
475
481
  if (!n || !a || !t || !y) return;
476
- const w = y.getValues(), V = t.shape;
477
- V && Object.entries(V).forEach(([E, C]) => {
478
- var O, L;
479
- let S = C;
480
- for (; (O = S == null ? void 0 : S._def) != null && O.schema; )
481
- S = S._def.schema;
482
- const F = (L = S == null ? void 0 : S._def) == null ? void 0 : L.fluig;
483
- if ((F == null ? void 0 : F.type) !== "options" || !Array.isArray(F.values) || w[E] !== void 0) return;
484
- const M = {};
482
+ const w = y.getValues(), S = t.shape;
483
+ S && Object.entries(S).forEach(([V, C]) => {
484
+ var P, L;
485
+ let I = C;
486
+ for (; (P = I == null ? void 0 : I._def) != null && P.schema; )
487
+ I = I._def.schema;
488
+ const F = (L = I == null ? void 0 : I._def) == null ? void 0 : L.fluig;
489
+ if ((F == null ? void 0 : F.type) !== "options" || !Array.isArray(F.values) || w[V] !== void 0) return;
490
+ const k = {};
485
491
  F.values.forEach((_) => {
486
- M[_] = a[_] === "on";
487
- }), y.setValue(E, M, {
492
+ k[_] = a[_] === "on";
493
+ }), y.setValue(V, k, {
488
494
  shouldDirty: !1,
489
495
  shouldValidate: !1
490
496
  });
491
497
  });
492
498
  }, [n, a, t, y]);
493
- const P = A(
499
+ const N = A(
494
500
  () => ({
495
501
  id: e,
496
502
  form: y,
@@ -502,15 +508,15 @@ function Te({
502
508
  }),
503
509
  [e, y, d, m, n, h, l]
504
510
  );
505
- return /* @__PURE__ */ g($.Provider, { value: P, children: /* @__PURE__ */ g("section", { id: e, className: [e, o].filter(Boolean).join(" "), children: r }) });
511
+ return /* @__PURE__ */ g($.Provider, { value: N, children: /* @__PURE__ */ g("section", { id: e, className: [e, o].filter(Boolean).join(" "), children: r }) });
506
512
  }
507
- const H = x(null);
508
- function xe({ children: e, config: o }) {
513
+ const H = D(null);
514
+ function De({ children: e, config: o }) {
509
515
  const t = A(() => ne(o), [o]);
510
516
  return /* @__PURE__ */ g(H.Provider, { value: t, children: e });
511
517
  }
512
- function De() {
513
- const e = D(H);
518
+ function xe() {
519
+ const e = x(H);
514
520
  if (!e)
515
521
  throw new Error(
516
522
  "useFluigApi deve ser usado dentro de um <FluigApiProvider>"
@@ -518,15 +524,15 @@ function De() {
518
524
  return e;
519
525
  }
520
526
  export {
521
- ke as DebugLogger,
522
- xe as FluigApiProvider,
523
- Ee as FluigRuntimeProvider,
527
+ Oe as DebugLogger,
528
+ De as FluigApiProvider,
529
+ Ve as FluigRuntimeProvider,
524
530
  Fe as FluigWorkflowForm,
525
- Ie as SchemaRegistryProvider,
531
+ be as SchemaRegistryProvider,
526
532
  Te as Section,
527
- Pe as createFluigClient,
528
- Me as parentProxy,
529
- De as useFluigApi,
533
+ Ne as createFluigClient,
534
+ ke as parentProxy,
535
+ xe as useFluigApi,
530
536
  R as useFluigRuntime,
531
537
  B as useSchemaRegistry,
532
538
  Ce as useSection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluig-kit/ecm",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",