@fluig-kit/ecm 1.0.7 → 1.0.8

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 h=require("react/jsx-runtime"),l=require("react"),x=require("react-hook-form"),L=require("@hookform/resolvers"),_=require("zod"),w=require("@fluig-kit/core");var B=function(e,n){for(var t={};e.length;){var o=e[0],i=o.code,s=o.message,u=o.path.join(".");if(!t[u])if("unionErrors"in o){var a=o.unionErrors[0].errors[0];t[u]={message:a.message,type:a.code}}else t[u]={message:s,type:i};if("unionErrors"in o&&o.unionErrors.forEach(function(m){return m.errors.forEach(function(f){return e.push(f)})}),n){var c=t[u].types,r=c&&c[o.code];t[u]=x.appendErrors(u,n,t,i,r?[].concat(r,o.message):o.message)}e.shift()}return t},z=function(e,n,t){return t===void 0&&(t={}),function(o,i,s){try{return Promise.resolve(function(u,a){try{var c=Promise.resolve(e[t.mode==="sync"?"parse":"parseAsync"](o,n)).then(function(r){return s.shouldUseNativeValidation&&L.validateFieldsNatively({},s),{errors:{},values:t.raw?o:r}})}catch(r){return a(r)}return c&&c.then?c.then(void 0,a):c}(0,function(u){if(function(a){return Array.isArray(a==null?void 0:a.errors)}(u))return{values:{},errors:L.toNestErrors(B(u.errors,!s.shouldUseNativeValidation&&s.criteriaMode==="all"),s)};throw u}))}catch(u){return Promise.reject(u)}}};const j=l.createContext(null);function G({children:e,baseSchema:n}){const[t,o]=l.useState([]),i=l.useMemo(()=>n??_.z.object({}),[n]),s=l.useCallback((r,m)=>{o(f=>f.some(v=>v.id===r)?f:[...f,{id:r,schema:m}])},[]),u=l.useCallback(r=>{o(m=>m.some(f=>f.id===r)?m.filter(f=>f.id!==r):m)},[]),a=l.useMemo(()=>t.length?t.map(r=>r.schema).reduce((r,m)=>r.and(m),i):i,[t,i]),c=l.useMemo(()=>({registerSchema:s,unregisterSchema:u,mergedSchema:a}),[s,u,a]);return h.jsx(j.Provider,{value:c,children:e})}function D(){const e=l.useContext(j);if(!e)throw new Error("useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>");return e}function T(e){return typeof e=="number"?e:isNaN(Number(e))?null:Number(e)}function M(e,n,t){if(!e)return!0;const o=Array.isArray(n)?n[0]:n,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 H(e,n,t,o,i){const s=new Set(e),u=new Set(n);return t==null||t.forEach(a=>{if(a.from!==void 0){const r=Array.isArray(a.from)?a.from:[a.from];if(o===null||!r.includes(o))return}if(!M(a.when,a.target,i))return;const c=Array.isArray(a.target)?a.target:[a.target];switch(a.type){case"readonly":c.forEach(r=>{u.add(r),s.delete(r)});break;case"active":c.forEach(r=>{s.add(r),u.delete(r)});break;case"hidden":c.forEach(r=>{s.delete(r),u.delete(r)});break}}),{active:Array.from(s),readonly:Array.from(u)}}function $(e,n,t,o){const i=new Set(e.active),s=new Set(e.readonly),u=new Set(e.hidden??[]);return n==null||n.forEach(a=>{if(a.from!==void 0){const r=Array.isArray(a.from)?a.from:[a.from];if(t===null||!r.includes(t))return}if(!M(a.when,a.target,o))return;const c=Array.isArray(a.target)?a.target:[a.target];switch(a.type){case"hidden":c.forEach(r=>{u.add(r),i.delete(r),s.delete(r)});break;case"active":c.forEach(r=>{i.add(r),s.delete(r),u.delete(r)});break;case"readonly":c.forEach(r=>{s.add(r),i.delete(r),u.delete(r)});break}}),{active:Array.from(i),readonly:Array.from(s),hidden:Array.from(u)}}function K(e,n){if(!(e!=null&&e.length))return n;const t=new Map(n.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 J(e){var o,i;const n=new Set,t=(s=[])=>{s.forEach(u=>{var a;u.target&&(Array.isArray(u.target)?u.target:[u.target]).forEach(r=>n.add(r)),(a=u.when)!=null&&a.field&&n.add(u.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(n)}function Q({activityId:e,previousActivityId:n,control:t,workflowStructure:o,sectionsRegistry:i}){const{registerSchema:s,unregisterSchema:u}=D(),a=T(e),c=T(n),r=a!==null?o[a]:null,m=l.useMemo(()=>J(r),[a,r]),f=x.useWatch({control:t,name:m,defaultValue:{}}),v=l.useMemo(()=>{const g={};return m.forEach((y,b)=>{g[y]=Array.isArray(f)?f[b]:f}),g},[f,m]),d=l.useMemo(()=>{if(!r)return{sections:[],fields:{active:[],readonly:[],hidden:[]}};const g=H(r.sections.active,r.sections.readonly,r.sections.rules,c,v);let y=[...g.readonly.map(A=>({name:A,mode:"readonly"})),...g.active.map(A=>({name:A,mode:"active"}))];y=K(r.sections.order,y);const b=$({active:r.fields.active,readonly:r.fields.readonly,hidden:r.fields.hidden},r.fields.rules,c,v);return{sections:y,fields:b}},[r,c,v,i]);return l.useEffect(()=>{const g=d.sections.filter(y=>y.mode==="active").map(y=>y.name);g.forEach(y=>{var A;const b=(A=i==null?void 0:i[y])==null?void 0:A.schema;b&&s(y,b)}),Object.keys(i??{}).filter(y=>!g.includes(y)).forEach(u)},[d.sections,i,s,u]),d}function X(){if(typeof document>"u")return{};const e={};return document.querySelectorAll("input[type='radio'][name]").forEach(n=>{const t=n,o=t.getAttribute("name");o&&t.checked&&(e[o]=t.value)}),document.querySelectorAll("input[name], textarea[name], select[name]").forEach(n=>{const t=n,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(n=>{var i;const t=n,o=t.getAttribute("name");if(o){const s=((i=t.textContent)==null?void 0:i.trim())??"";s!==""&&(e[o]=s)}}),e}const q=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("edit"),Z=()=>{var e;return typeof window>"u"||!window.top?null:(e=window.top.ECM)!=null&&e.workflowView?"process":"document"},ee=()=>{var n,t;if(Z()==="process"){const o=(t=(n=window.top)==null?void 0:n.ECM)==null?void 0:t.workflowView;if(!o)return!1;const i=o.newRequest??o.isNewRequest,s=o.colleagueLogin;return i===!0||!!s&&s.trim()!==""}return q()===null},te=()=>q()==="true",O=l.createContext(null);function ne({children:e,devConfig:n}){const[t,o]=l.useState(null),i=l.useMemo(()=>X()??{},[]);return l.useEffect(()=>{let s=!0;return(async()=>{const a=typeof window<"u"&&window.location.hostname==="localhost",c=typeof window<"u"&&window.self!==window.top;let r=null;try{const d=await w.parentProxy.top.ECM.workflowView.sequence;d!=null&&(r=Number(d),n!=null&&n.showDebugLogs&&console.log("[FluigRuntime] Atividade:",r))}catch(d){console.warn("[FluigRuntime] Falha ao detectar atividade:",d)}const m=!a&&c&&!(ee()||te()),f={isView:m,isReadOnly:m,activityId:r,previousActivityId:null,prefilledValues:i,showDebugSubmit:!1,showDebugLogs:!1,isDev:!1};let v=f;if(n!=null&&n.enabled){const d=n.isView??f.isView;v={...f,...n,isView:d,isReadOnly:d,isDev:!0,activityId:n.activityId!==void 0?n.activityId:r}}typeof window<"u"&&(window.__FLUIG_DEBUG_ENABLED__=v.showDebugLogs),v.showDebugLogs&&s&&(w.DebugLogger.header("Runtime Initialized"),w.DebugLogger.table("State",{"Detected Activity":r,"Final Activity":v.activityId,"Dev Mode":v.isDev}),w.DebugLogger.end()),s&&o(v)})(),()=>{s=!1}},[n,i]),t?h.jsx(O.Provider,{value:t,children:e}):null}function V(){const e=l.useContext(O);if(!e)throw new Error("useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>");return e}function re(e){const{activityId:n,previousActivityId:t}=V();l.useEffect(()=>{n!=null&&e.setValue("CURRENTACTIVITYID",n),t!=null&&e.setValue("LASTACTIVITYID",t)},[n,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.beforeSendValidate=()=>!0;try{o.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}))}catch{o.click()}},u=>{var a,c,r;console.error("[Validation Errors]",u),(c=(a=window.top)==null?void 0:a.FLUIGC)!=null&&c.toast?(r=window.top)==null||r.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 oe=({workflowStructure:e,sectionsRegistry:n,className:t})=>{const{control:o,handleSubmit:i,register:s,setValue:u,getValues:a}=x.useFormContext(),c=V(),r=l.useRef(!1);l.useEffect(()=>{r.current||(c.activityId!=null&&u("CURRENTACTIVITYID",c.activityId),c.previousActivityId!=null&&u("LASTACTIVITYID",c.previousActivityId),r.current=!0)},[c,u]);const{sections:m,fields:f}=Q({control:o,activityId:c.activityId,previousActivityId:c.previousActivityId,workflowStructure:e,sectionsRegistry:n}),v=d=>{console.log("✅ [FluigWorkflowForm] Dados válidos:",d)};return h.jsxs("form",{id:"fluig-react-form",className:t,onSubmit:i(v),noValidate:!0,children:[h.jsxs("div",{className:"hidden",style:{display:"none"},children:[h.jsx("input",{type:"hidden",...s("CURRENTACTIVITYID")}),h.jsx("input",{type:"hidden",...s("LASTACTIVITYID")})]}),m.length===0&&c.activityId!==null&&h.jsxs("p",{children:["Não foi possível encontrar a atividade: ",String(c.activityId)]}),m.map(({name:d,mode:g})=>{if(g==="hidden")return null;const y=n[d];if(!y)return null;const b=y.Component;return h.jsx(b,{id:d,fields:f,readOnly:g==="readonly"},d)}),c.isDev&&c.showDebugSubmit&&h.jsx("div",{style:{width:"100%",padding:"16px",paddingTop:"0"},children:h.jsx("button",{type:"submit",className:"btn btn-primary btn-lg btn-block",children:"Submit (Debug)"})})]})},ie=e=>{const{mergedSchema:n}=D(),t=V(),o=x.useForm({resolver:n?z(n):void 0,defaultValues:t.prefilledValues,mode:"onBlur"});return re(o),l.useEffect(()=>{t.showDebugLogs&&(w.DebugLogger.header("Form Initialized"),w.DebugLogger.table("Prefilled Values (DOM Capture)",t.prefilledValues),w.DebugLogger.info("RHF Current Values",o.getValues()),w.DebugLogger.end())},[t.showDebugLogs,t.prefilledValues,o]),h.jsx(x.FormProvider,{...o,children:h.jsx(oe,{...e})})};async function se(e){if(!e)return console.warn("[setFluigNextActivity] Nenhuma atividade informada."),!1;const{wfView:n,wkfView:t}=await ae();if(!n||!t)return!1;ue(n);const o=Number(e),i=ce(n,o);return i?(le(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)}async function ae(){const e=await w.parentProxy.top.ECM.workflowView,n=await w.parentProxy.top.ECM_WKFView;return!e||!n?(console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."),{}):{wfView:e,wkfView:n}}function ue(e){e.availableStatesCOPY||(e.availableStatesCOPY=e.availableStates)}function ce(e,n){const t=e.availableStatesCOPY||e.availableStates;return t==null?void 0:t.find(o=>o.sequence===n)}function le(e,n,t,o){e.availableUsers.users=[],e.availableStates=[t],n.selectActivity=()=>o}const U=l.createContext(null);function de(){const e=l.useContext(U);if(!e)throw new Error("useSection deve ser usado dentro de um componente <Section>");return e}function fe({id:e,className:n,schema:t,children:o,form:i,prefilledValues:s,readOnly:u,fields:a={},hidden:c=!1}){const{isView:r,activityId:m}=V(),f=m,v=x.useFormContext(),d=i||v;if(!d)return console.error(`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`),null;if(c)return null;const g=l.useCallback(p=>{var E,I,C;return(E=a.hidden)!=null&&E.includes(p)?"hidden":(I=a.readonly)!=null&&I.includes(p)?"readonly":(C=a.active)!=null&&C.includes(p)?"active":u?"readonly":"active"},[a,u]),y=l.useCallback(p=>g(p)==="hidden",[g]),b=l.useCallback(p=>g(p)==="readonly",[g]),A=l.useCallback(p=>{if(!p)return;const E=d.getValues("CURRENTACTIVITYID");d.setValue("LASTACTIVITYID",E),d.setValue("CURRENTACTIVITYID",f),se(Number(p))},[d,f]);l.useEffect(()=>{if(!r||!s||!t||!d)return;const p=d.getValues(),E=t.shape;E&&Object.entries(E).forEach(([I,C])=>{var R,k;let S=C;for(;(R=S==null?void 0:S._def)!=null&&R.schema;)S=S._def.schema;const F=(k=S==null?void 0:S._def)==null?void 0:k.fluig;if((F==null?void 0:F.type)!=="options"||!Array.isArray(F.values)||p[I]!==void 0)return;const P={};F.values.forEach(N=>{P[N]=s[N]==="on"}),d.setValue(I,P,{shouldDirty:!1,shouldValidate:!1})})},[r,s,t,d]);const W=l.useMemo(()=>({id:e,form:d,isHidden:y,isReadOnly:b,isView:r,next:A,wf_activity_id:f}),[e,d,y,b,r,A,f]);return h.jsx(U.Provider,{value:W,children:h.jsx("section",{id:e,className:[e,n].filter(Boolean).join(" "),children:o})})}const Y=l.createContext(null);function me({children:e,config:n}){const t=l.useMemo(()=>w.createFluigClient(n),[n]);return h.jsx(Y.Provider,{value:t,children:e})}function ye(){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:()=>w.DebugLogger});Object.defineProperty(exports,"createFluigClient",{enumerable:!0,get:()=>w.createFluigClient});Object.defineProperty(exports,"parentProxy",{enumerable:!0,get:()=>w.parentProxy});exports.FluigApiProvider=me;exports.FluigRuntimeProvider=ne;exports.FluigWorkflowForm=ie;exports.SchemaRegistryProvider=G;exports.Section=fe;exports.useFluigApi=ye;exports.useFluigRuntime=V;exports.useSchemaRegistry=D;exports.useSection=de;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),l=require("react"),I=require("react-hook-form"),N=require("@hookform/resolvers"),_=require("zod"),h=require("@fluig-kit/core");var B=function(e,n){for(var t={};e.length;){var o=e[0],i=o.code,s=o.message,u=o.path.join(".");if(!t[u])if("unionErrors"in o){var a=o.unionErrors[0].errors[0];t[u]={message:a.message,type:a.code}}else t[u]={message:s,type:i};if("unionErrors"in o&&o.unionErrors.forEach(function(y){return y.errors.forEach(function(m){return e.push(m)})}),n){var c=t[u].types,r=c&&c[o.code];t[u]=I.appendErrors(u,n,t,i,r?[].concat(r,o.message):o.message)}e.shift()}return t},z=function(e,n,t){return t===void 0&&(t={}),function(o,i,s){try{return Promise.resolve(function(u,a){try{var c=Promise.resolve(e[t.mode==="sync"?"parse":"parseAsync"](o,n)).then(function(r){return s.shouldUseNativeValidation&&N.validateFieldsNatively({},s),{errors:{},values:t.raw?o:r}})}catch(r){return a(r)}return c&&c.then?c.then(void 0,a):c}(0,function(u){if(function(a){return Array.isArray(a==null?void 0:a.errors)}(u))return{values:{},errors:N.toNestErrors(B(u.errors,!s.shouldUseNativeValidation&&s.criteriaMode==="all"),s)};throw u}))}catch(u){return Promise.reject(u)}}};const j=l.createContext(null);function G({children:e,baseSchema:n}){const[t,o]=l.useState([]),i=l.useMemo(()=>n??_.z.object({}),[n]),s=l.useCallback((r,y)=>{o(m=>m.some(w=>w.id===r)?m:[...m,{id:r,schema:y}])},[]),u=l.useCallback(r=>{o(y=>y.some(m=>m.id===r)?y.filter(m=>m.id!==r):y)},[]),a=l.useMemo(()=>t.length?t.map(r=>r.schema).reduce((r,y)=>r.and(y),i):i,[t,i]),c=l.useMemo(()=>({registerSchema:s,unregisterSchema:u,mergedSchema:a}),[s,u,a]);return g.jsx(j.Provider,{value:c,children:e})}function D(){const e=l.useContext(j);if(!e)throw new Error("useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>");return e}function L(e){return typeof e=="number"?e:isNaN(Number(e))?null:Number(e)}function M(e,n,t){if(!e)return!0;const o=Array.isArray(n)?n[0]:n,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 H(e,n,t,o,i){const s=new Set(e),u=new Set(n);return t==null||t.forEach(a=>{if(a.from!==void 0){const r=Array.isArray(a.from)?a.from:[a.from];if(o===null||!r.includes(o))return}if(!M(a.when,a.target,i))return;const c=Array.isArray(a.target)?a.target:[a.target];switch(a.type){case"readonly":c.forEach(r=>{u.add(r),s.delete(r)});break;case"active":c.forEach(r=>{s.add(r),u.delete(r)});break;case"hidden":c.forEach(r=>{s.delete(r),u.delete(r)});break}}),{active:Array.from(s),readonly:Array.from(u)}}function $(e,n,t,o){const i=new Set(e.active),s=new Set(e.readonly),u=new Set(e.hidden??[]);return n==null||n.forEach(a=>{if(a.from!==void 0){const r=Array.isArray(a.from)?a.from:[a.from];if(t===null||!r.includes(t))return}if(!M(a.when,a.target,o))return;const c=Array.isArray(a.target)?a.target:[a.target];switch(a.type){case"hidden":c.forEach(r=>{u.add(r),i.delete(r),s.delete(r)});break;case"active":c.forEach(r=>{i.add(r),s.delete(r),u.delete(r)});break;case"readonly":c.forEach(r=>{s.add(r),i.delete(r),u.delete(r)});break}}),{active:Array.from(i),readonly:Array.from(s),hidden:Array.from(u)}}function K(e,n){if(!(e!=null&&e.length))return n;const t=new Map(n.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 J(e){var o,i;const n=new Set,t=(s=[])=>{s.forEach(u=>{var a;u.target&&(Array.isArray(u.target)?u.target:[u.target]).forEach(r=>n.add(r)),(a=u.when)!=null&&a.field&&n.add(u.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(n)}function Q({activityId:e,previousActivityId:n,control:t,workflowStructure:o,sectionsRegistry:i}){const{registerSchema:s,unregisterSchema:u}=D(),a=L(e),c=L(n),r=a!==null?o[a]:null,y=l.useMemo(()=>J(r),[a,r]),m=I.useWatch({control:t,name:y,defaultValue:{}}),w=l.useMemo(()=>{const f={};return y.forEach((v,b)=>{f[v]=Array.isArray(m)?m[b]:m}),f},[m,y]),d=l.useMemo(()=>{if(!r)return{sections:[],fields:{active:[],readonly:[],hidden:[]}};const f=H(r.sections.active,r.sections.readonly,r.sections.rules,c,w);let v=[...f.readonly.map(A=>({name:A,mode:"readonly"})),...f.active.map(A=>({name:A,mode:"active"}))];v=K(r.sections.order,v);const b=$({active:r.fields.active,readonly:r.fields.readonly,hidden:r.fields.hidden},r.fields.rules,c,w);return{sections:v,fields:b}},[r,c,w,i]);return l.useEffect(()=>{const f=d.sections.filter(v=>v.mode==="active").map(v=>v.name);f.forEach(v=>{var A;const b=(A=i==null?void 0:i[v])==null?void 0:A.schema;b&&s(v,b)}),Object.keys(i??{}).filter(v=>!f.includes(v)).forEach(u)},[d.sections,i,s,u]),d}function X(){if(typeof document>"u")return{};const e={};return document.querySelectorAll("input[type='radio'][name]").forEach(n=>{const t=n,o=t.getAttribute("name");o&&t.checked&&(e[o]=t.value)}),document.querySelectorAll("input[name], textarea[name], select[name]").forEach(n=>{const t=n,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(n=>{var i;const t=n,o=t.getAttribute("name");if(o){const s=((i=t.textContent)==null?void 0:i.trim())??"";s!==""&&(e[o]=s)}}),e}const q=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("edit"),Z=()=>{var e;return typeof window>"u"||!window.top?null:(e=window.top.ECM)!=null&&e.workflowView?"process":"document"},ee=()=>{var n,t;if(Z()==="process"){const o=(t=(n=window.top)==null?void 0:n.ECM)==null?void 0:t.workflowView;if(!o)return!1;const i=o.newRequest??o.isNewRequest,s=o.colleagueLogin;return i===!0||!!s&&s.trim()!==""}return q()===null},te=()=>q()==="true",O=l.createContext(null);function ne({children:e,devConfig:n}){const[t,o]=l.useState(null),i=l.useMemo(()=>X()??{},[]);return l.useEffect(()=>{let s=!0;return(async()=>{const a=typeof window<"u"&&window.location.hostname==="localhost",c=typeof window<"u"&&window.self!==window.top;let r=null;try{const f=await h.parentProxy.top.ECM.workflowView.sequence;f!=null&&(r=Number(f),n!=null&&n.showDebugLogs&&console.log("[FluigRuntime] Atividade:",r))}catch(f){console.warn("[FluigRuntime] Falha ao detectar atividade:",f)}const y=!a&&c&&!(ee()||te()),m=i.LASTACTIVITYID?Number(i.LASTACTIVITYID):null,w={isView:y,isReadOnly:y,activityId:r,previousActivityId:m,prefilledValues:i,showDebugSubmit:!1,showDebugLogs:!1,isDev:!1};let d=w;if(n!=null&&n.enabled){const f=n.isView??w.isView;d={...w,...n,isView:f,isReadOnly:f,isDev:!0,activityId:n.activityId!==void 0?n.activityId:r}}typeof window<"u"&&(window.__FLUIG_DEBUG_ENABLED__=d.showDebugLogs),d.showDebugLogs&&s&&(h.DebugLogger.header("Runtime Initialized"),h.DebugLogger.table("State",{"Detected Activity":r,"Final Activity":d.activityId,"Dev Mode":d.isDev}),h.DebugLogger.end()),s&&o(d)})(),()=>{s=!1}},[n,i]),t?g.jsx(O.Provider,{value:t,children:e}):null}function F(){const e=l.useContext(O);if(!e)throw new Error("useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>");return e}function re(e){const{activityId:n,previousActivityId:t}=F();l.useEffect(()=>{n!=null&&e.setValue("CURRENTACTIVITYID",n),t!=null&&e.setValue("LASTACTIVITYID",t)},[n,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.beforeSendValidate=()=>!0;try{o.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}))}catch{o.click()}},u=>{var a,c,r;console.error("[Validation Errors]",u),(c=(a=window.top)==null?void 0:a.FLUIGC)!=null&&c.toast?(r=window.top)==null||r.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 oe=({workflowStructure:e,sectionsRegistry:n,className:t})=>{const{control:o,handleSubmit:i,register:s,setValue:u,getValues:a}=I.useFormContext(),c=F(),r=l.useRef(!1);l.useEffect(()=>{r.current||(c.activityId!=null&&u("CURRENTACTIVITYID",c.activityId),c.previousActivityId!=null&&u("LASTACTIVITYID",c.previousActivityId),r.current=!0)},[c,u]);const{sections:y,fields:m}=Q({control:o,activityId:c.activityId,previousActivityId:c.previousActivityId,workflowStructure:e,sectionsRegistry:n}),w=d=>{console.log("✅ [FluigWorkflowForm] Dados válidos:",d)};return g.jsxs("form",{id:"fluig-react-form",className:t,onSubmit:i(w),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&&c.activityId!==null&&g.jsxs("p",{children:["Não foi possível encontrar a atividade: ",String(c.activityId)]}),y.map(({name:d,mode:f})=>{if(f==="hidden")return null;const v=n[d];if(!v)return null;const b=v.Component;return g.jsx(b,{id:d,fields:m,readOnly:f==="readonly"},d)}),c.isDev&&c.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)"})})]})},ie=e=>{const{mergedSchema:n}=D(),t=F(),o=I.useForm({resolver:n?z(n):void 0,defaultValues:t.prefilledValues,mode:"onBlur"});return re(o),l.useEffect(()=>{t.showDebugLogs&&(h.DebugLogger.header("Form Initialized"),h.DebugLogger.table("Prefilled Values (DOM Capture)",t.prefilledValues),h.DebugLogger.info("RHF Current Values",o.getValues()),h.DebugLogger.end())},[t.showDebugLogs,t.prefilledValues,o]),g.jsx(I.FormProvider,{...o,children:g.jsx(oe,{...e})})};async function se(e){if(!e)return console.warn("[setFluigNextActivity] Nenhuma atividade informada."),!1;const{wfView:n,wkfView:t}=await ae();if(!n||!t)return!1;ue(n);const o=Number(e),i=ce(n,o);return i?(le(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)}async function ae(){const e=await h.parentProxy.top.ECM.workflowView,n=await h.parentProxy.top.ECM_WKFView;return!e||!n?(console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."),{}):{wfView:e,wkfView:n}}function ue(e){e.availableStatesCOPY||(e.availableStatesCOPY=e.availableStates)}function ce(e,n){const t=e.availableStatesCOPY||e.availableStates;return t==null?void 0:t.find(o=>o.sequence===n)}function le(e,n,t,o){e.availableUsers.users=[],e.availableStates=[t],n.selectActivity=()=>o}const Y=l.createContext(null);function de(){const e=l.useContext(Y);if(!e)throw new Error("useSection deve ser usado dentro de um componente <Section>");return e}function fe({id:e,className:n,schema:t,children:o,form:i,prefilledValues:s,readOnly:u,fields:a={},hidden:c=!1}){const{isView:r,activityId:y}=F(),m=y,w=I.useFormContext(),d=i||w;if(!d)return console.error(`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`),null;if(c)return null;const f=l.useCallback(p=>{var E,x,C;return(E=a.hidden)!=null&&E.includes(p)?"hidden":(x=a.readonly)!=null&&x.includes(p)?"readonly":(C=a.active)!=null&&C.includes(p)?"active":u?"readonly":"active"},[a,u]),v=l.useCallback(p=>f(p)==="hidden",[f]),b=l.useCallback(p=>f(p)==="readonly",[f]),A=l.useCallback(p=>{if(!p)return;const E=d.getValues("CURRENTACTIVITYID");d.setValue("LASTACTIVITYID",E),d.setValue("CURRENTACTIVITYID",m),se(Number(p))},[d,m]);l.useEffect(()=>{if(!r||!s||!t||!d)return;const p=d.getValues(),E=t.shape;E&&Object.entries(E).forEach(([x,C])=>{var R,T;let S=C;for(;(R=S==null?void 0:S._def)!=null&&R.schema;)S=S._def.schema;const V=(T=S==null?void 0:S._def)==null?void 0:T.fluig;if((V==null?void 0:V.type)!=="options"||!Array.isArray(V.values)||p[x]!==void 0)return;const P={};V.values.forEach(k=>{P[k]=s[k]==="on"}),d.setValue(x,P,{shouldDirty:!1,shouldValidate:!1})})},[r,s,t,d]);const W=l.useMemo(()=>({id:e,form:d,isHidden:v,isReadOnly:b,isView:r,next:A,wf_activity_id:m}),[e,d,v,b,r,A,m]);return g.jsx(Y.Provider,{value:W,children:g.jsx("section",{id:e,className:[e,n].filter(Boolean).join(" "),children:o})})}const U=l.createContext(null);function me({children:e,config:n}){const t=l.useMemo(()=>h.createFluigClient(n),[n]);return g.jsx(U.Provider,{value:t,children:e})}function ye(){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:()=>h.DebugLogger});Object.defineProperty(exports,"createFluigClient",{enumerable:!0,get:()=>h.createFluigClient});Object.defineProperty(exports,"parentProxy",{enumerable:!0,get:()=>h.parentProxy});exports.FluigApiProvider=me;exports.FluigRuntimeProvider=ne;exports.FluigWorkflowForm=ie;exports.SchemaRegistryProvider=G;exports.Section=fe;exports.useFluigApi=ye;exports.useFluigRuntime=F;exports.useSchemaRegistry=D;exports.useSection=de;
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { jsx as w, jsxs as T } from "react/jsx-runtime";
2
- import { createContext as D, useState as Y, useMemo as b, useCallback as V, useContext as N, useEffect as I, useRef as K } from "react";
1
+ import { jsx as w, jsxs as R } from "react/jsx-runtime";
2
+ import { createContext as T, useState as U, useMemo as A, useCallback as V, useContext as D, useEffect as E, useRef as K } from "react";
3
3
  import { appendErrors as J, useWatch as Q, useForm as X, FormProvider as Z, useFormContext as O } from "react-hook-form";
4
4
  import { validateFieldsNatively as ee, toNestErrors as te } from "@hookform/resolvers";
5
5
  import { z as ne } from "zod";
6
- import { parentProxy as k, DebugLogger as E, createFluigClient as re } from "@fluig-kit/core";
7
- import { DebugLogger as Me, createFluigClient as Ue, parentProxy as Ye } from "@fluig-kit/core";
6
+ import { parentProxy as P, DebugLogger as I, createFluigClient as re } from "@fluig-kit/core";
7
+ import { DebugLogger as Me, createFluigClient as Ye, parentProxy as Ue } from "@fluig-kit/core";
8
8
  var oe = function(e, n) {
9
9
  for (var t = {}; e.length; ) {
10
10
  var o = e[0], i = o.code, a = o.message, c = o.path.join(".");
@@ -12,9 +12,9 @@ var oe = function(e, n) {
12
12
  var s = o.unionErrors[0].errors[0];
13
13
  t[c] = { message: s.message, type: s.code };
14
14
  } else t[c] = { message: a, type: i };
15
- if ("unionErrors" in o && o.unionErrors.forEach(function(f) {
16
- return f.errors.forEach(function(d) {
17
- return e.push(d);
15
+ if ("unionErrors" in o && o.unionErrors.forEach(function(m) {
16
+ return m.errors.forEach(function(f) {
17
+ return e.push(f);
18
18
  });
19
19
  }), n) {
20
20
  var u = t[c].types, r = u && u[o.code];
@@ -46,18 +46,18 @@ var oe = function(e, n) {
46
46
  }
47
47
  };
48
48
  };
49
- const _ = D(
49
+ const _ = T(
50
50
  null
51
51
  );
52
52
  function Ce({
53
53
  children: e,
54
54
  baseSchema: n
55
55
  }) {
56
- const [t, o] = Y([]), i = b(() => n ?? ne.object({}), [n]), a = V((r, f) => {
57
- o((d) => d.some((v) => v.id === r) ? d : [...d, { id: r, schema: f }]);
56
+ const [t, o] = U([]), i = A(() => n ?? ne.object({}), [n]), a = V((r, m) => {
57
+ o((f) => f.some((v) => v.id === r) ? f : [...f, { id: r, schema: m }]);
58
58
  }, []), c = V((r) => {
59
- o((f) => f.some((d) => d.id === r) ? f.filter((d) => d.id !== r) : f);
60
- }, []), s = b(() => t.length ? t.map((r) => r.schema).reduce((r, f) => r.and(f), i) : i, [t, i]), u = b(
59
+ o((m) => m.some((f) => f.id === r) ? m.filter((f) => f.id !== r) : m);
60
+ }, []), s = A(() => t.length ? t.map((r) => r.schema).reduce((r, m) => r.and(m), i) : i, [t, i]), u = A(
61
61
  () => ({
62
62
  registerSchema: a,
63
63
  unregisterSchema: c,
@@ -68,14 +68,14 @@ function Ce({
68
68
  return /* @__PURE__ */ w(_.Provider, { value: u, children: e });
69
69
  }
70
70
  function W() {
71
- const e = N(_);
71
+ const e = D(_);
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 U(e) {
78
+ function Y(e) {
79
79
  return typeof e == "number" ? e : isNaN(Number(e)) ? null : Number(e);
80
80
  }
81
81
  function B(e, n, t) {
@@ -167,39 +167,39 @@ function le({
167
167
  workflowStructure: o,
168
168
  sectionsRegistry: i
169
169
  }) {
170
- const { registerSchema: a, unregisterSchema: c } = W(), s = U(e), u = U(n), r = s !== null ? o[s] : null, f = b(() => ue(r), [s, r]), d = Q({
170
+ const { registerSchema: a, unregisterSchema: c } = W(), s = Y(e), u = Y(n), r = s !== null ? o[s] : null, m = A(() => ue(r), [s, r]), f = Q({
171
171
  control: t,
172
- name: f,
172
+ name: m,
173
173
  defaultValue: {}
174
- }), v = b(() => {
175
- const y = {};
176
- return f.forEach((m, p) => {
177
- y[m] = Array.isArray(d) ? d[p] : d;
178
- }), y;
179
- }, [d, f]), l = b(() => {
174
+ }), v = A(() => {
175
+ const d = {};
176
+ return m.forEach((y, p) => {
177
+ d[y] = Array.isArray(f) ? f[p] : f;
178
+ }), d;
179
+ }, [f, m]), l = A(() => {
180
180
  if (!r)
181
181
  return {
182
182
  sections: [],
183
183
  fields: { active: [], readonly: [], hidden: [] }
184
184
  };
185
- const y = ae(
185
+ const d = ae(
186
186
  r.sections.active,
187
187
  r.sections.readonly,
188
188
  r.sections.rules,
189
189
  u,
190
190
  v
191
191
  );
192
- let m = [
193
- ...y.readonly.map((g) => ({
192
+ let y = [
193
+ ...d.readonly.map((g) => ({
194
194
  name: g,
195
195
  mode: "readonly"
196
196
  })),
197
- ...y.active.map((g) => ({
197
+ ...d.active.map((g) => ({
198
198
  name: g,
199
199
  mode: "active"
200
200
  }))
201
201
  ];
202
- m = ce(r.sections.order, m);
202
+ y = ce(r.sections.order, y);
203
203
  const p = se(
204
204
  {
205
205
  active: r.fields.active,
@@ -210,15 +210,15 @@ function le({
210
210
  u,
211
211
  v
212
212
  );
213
- return { sections: m, fields: p };
213
+ return { sections: y, fields: p };
214
214
  }, [r, u, v, i]);
215
- return I(() => {
216
- const y = l.sections.filter((m) => m.mode === "active").map((m) => m.name);
217
- y.forEach((m) => {
215
+ return E(() => {
216
+ const d = l.sections.filter((y) => y.mode === "active").map((y) => y.name);
217
+ d.forEach((y) => {
218
218
  var g;
219
- const p = (g = i == null ? void 0 : i[m]) == null ? void 0 : g.schema;
220
- p && a(m, p);
221
- }), Object.keys(i ?? {}).filter((m) => !y.includes(m)).forEach(c);
219
+ const p = (g = i == null ? void 0 : i[y]) == null ? void 0 : g.schema;
220
+ p && a(y, p);
221
+ }), Object.keys(i ?? {}).filter((y) => !d.includes(y)).forEach(c);
222
222
  }, [l.sections, i, a, c]), l;
223
223
  }
224
224
  function de() {
@@ -253,60 +253,60 @@ const j = () => typeof window > "u" ? null : new URLSearchParams(window.location
253
253
  return i === !0 || !!a && a.trim() !== "";
254
254
  }
255
255
  return j() === null;
256
- }, ye = () => j() === "true", z = D(null);
257
- function De({
256
+ }, ye = () => j() === "true", z = T(null);
257
+ function Te({
258
258
  children: e,
259
259
  devConfig: n
260
260
  }) {
261
- const [t, o] = Y(null), i = b(() => de() ?? {}, []);
262
- return I(() => {
261
+ const [t, o] = U(null), i = A(() => de() ?? {}, []);
262
+ return E(() => {
263
263
  let a = !0;
264
264
  return (async () => {
265
265
  const s = typeof window < "u" && window.location.hostname === "localhost", u = typeof window < "u" && window.self !== window.top;
266
266
  let r = null;
267
267
  try {
268
- const l = await k.top.ECM.workflowView.sequence;
269
- l != null && (r = Number(l), n != null && n.showDebugLogs && console.log("[FluigRuntime] Atividade:", r));
270
- } catch (l) {
271
- console.warn("[FluigRuntime] Falha ao detectar atividade:", l);
268
+ const d = await P.top.ECM.workflowView.sequence;
269
+ d != null && (r = Number(d), n != null && n.showDebugLogs && console.log("[FluigRuntime] Atividade:", r));
270
+ } catch (d) {
271
+ console.warn("[FluigRuntime] Falha ao detectar atividade:", d);
272
272
  }
273
- const f = !s && u && !(me() || ye()), d = {
274
- isView: f,
275
- isReadOnly: f,
273
+ const m = !s && u && !(me() || ye()), f = i.LASTACTIVITYID ? Number(i.LASTACTIVITYID) : null, v = {
274
+ isView: m,
275
+ isReadOnly: m,
276
276
  activityId: r,
277
277
  // Usa o valor real detectado
278
- previousActivityId: null,
278
+ previousActivityId: f,
279
279
  prefilledValues: i,
280
280
  showDebugSubmit: !1,
281
281
  showDebugLogs: !1,
282
282
  isDev: !1
283
283
  };
284
- let v = d;
284
+ let l = v;
285
285
  if (n != null && n.enabled) {
286
- const l = n.isView ?? d.isView;
287
- v = {
288
- ...d,
286
+ const d = n.isView ?? v.isView;
287
+ l = {
288
+ ...v,
289
289
  ...n,
290
- isView: l,
291
- isReadOnly: l,
290
+ isView: d,
291
+ isReadOnly: d,
292
292
  isDev: !0,
293
293
  // Se devConfig tiver activityId definido explicitamente, usa ele.
294
294
  // Se não, mantém o detectado (permite usar devConfig só para logs, por exemplo)
295
295
  activityId: n.activityId !== void 0 ? n.activityId : r
296
296
  };
297
297
  }
298
- typeof window < "u" && (window.__FLUIG_DEBUG_ENABLED__ = v.showDebugLogs), v.showDebugLogs && a && (E.header("Runtime Initialized"), E.table("State", {
298
+ typeof window < "u" && (window.__FLUIG_DEBUG_ENABLED__ = l.showDebugLogs), l.showDebugLogs && a && (I.header("Runtime Initialized"), I.table("State", {
299
299
  "Detected Activity": r,
300
- "Final Activity": v.activityId,
301
- "Dev Mode": v.isDev
302
- }), E.end()), a && o(v);
300
+ "Final Activity": l.activityId,
301
+ "Dev Mode": l.isDev
302
+ }), I.end()), a && o(l);
303
303
  })(), () => {
304
304
  a = !1;
305
305
  };
306
306
  }, [n, i]), t ? /* @__PURE__ */ w(z.Provider, { value: t, children: e }) : null;
307
307
  }
308
- function R() {
309
- const e = N(z);
308
+ function N() {
309
+ const e = D(z);
310
310
  if (!e)
311
311
  throw new Error(
312
312
  "useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>"
@@ -314,10 +314,10 @@ function R() {
314
314
  return e;
315
315
  }
316
316
  function ve(e) {
317
- const { activityId: n, previousActivityId: t } = R();
318
- I(() => {
317
+ const { activityId: n, previousActivityId: t } = N();
318
+ E(() => {
319
319
  n != null && e.setValue("CURRENTACTIVITYID", n), t != null && e.setValue("LASTACTIVITYID", t);
320
- }, [n, t, e]), I(() => {
320
+ }, [n, t, e]), E(() => {
321
321
  var i, a;
322
322
  if (typeof window > "u") return;
323
323
  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");
@@ -351,18 +351,18 @@ const he = ({
351
351
  sectionsRegistry: n,
352
352
  className: t
353
353
  }) => {
354
- const { control: o, handleSubmit: i, register: a, setValue: c, getValues: s } = O(), u = R(), r = K(!1);
355
- I(() => {
354
+ const { control: o, handleSubmit: i, register: a, setValue: c, getValues: s } = O(), u = N(), r = K(!1);
355
+ E(() => {
356
356
  r.current || (u.activityId != null && c("CURRENTACTIVITYID", u.activityId), u.previousActivityId != null && c("LASTACTIVITYID", u.previousActivityId), r.current = !0);
357
357
  }, [u, c]);
358
- const { sections: f, fields: d } = le({
358
+ const { sections: m, fields: f } = le({
359
359
  control: o,
360
360
  activityId: u.activityId,
361
361
  previousActivityId: u.previousActivityId,
362
362
  workflowStructure: e,
363
363
  sectionsRegistry: n
364
364
  });
365
- return /* @__PURE__ */ T(
365
+ return /* @__PURE__ */ R(
366
366
  "form",
367
367
  {
368
368
  id: "fluig-react-form",
@@ -372,25 +372,25 @@ const he = ({
372
372
  }),
373
373
  noValidate: !0,
374
374
  children: [
375
- /* @__PURE__ */ T("div", { className: "hidden", style: { display: "none" }, children: [
375
+ /* @__PURE__ */ R("div", { className: "hidden", style: { display: "none" }, children: [
376
376
  /* @__PURE__ */ w("input", { type: "hidden", ...a("CURRENTACTIVITYID") }),
377
377
  /* @__PURE__ */ w("input", { type: "hidden", ...a("LASTACTIVITYID") })
378
378
  ] }),
379
- f.length === 0 && u.activityId !== null && /* @__PURE__ */ T("p", { children: [
379
+ m.length === 0 && u.activityId !== null && /* @__PURE__ */ R("p", { children: [
380
380
  "Não foi possível encontrar a atividade: ",
381
381
  String(u.activityId)
382
382
  ] }),
383
- f.map(({ name: l, mode: y }) => {
384
- if (y === "hidden") return null;
385
- const m = n[l];
386
- if (!m) return null;
387
- const p = m.Component;
383
+ m.map(({ name: l, mode: d }) => {
384
+ if (d === "hidden") return null;
385
+ const y = n[l];
386
+ if (!y) return null;
387
+ const p = y.Component;
388
388
  return /* @__PURE__ */ w(
389
389
  p,
390
390
  {
391
391
  id: l,
392
- fields: d,
393
- readOnly: y === "readonly"
392
+ fields: f,
393
+ readOnly: d === "readonly"
394
394
  },
395
395
  l
396
396
  );
@@ -399,17 +399,17 @@ const he = ({
399
399
  ]
400
400
  }
401
401
  );
402
- }, Ne = (e) => {
403
- const { mergedSchema: n } = W(), t = R(), o = X({
402
+ }, De = (e) => {
403
+ const { mergedSchema: n } = W(), t = N(), o = X({
404
404
  resolver: n ? ie(n) : void 0,
405
405
  defaultValues: t.prefilledValues,
406
406
  mode: "onBlur"
407
407
  });
408
- return ve(o), I(() => {
409
- t.showDebugLogs && (E.header("Form Initialized"), E.table(
408
+ return ve(o), E(() => {
409
+ t.showDebugLogs && (I.header("Form Initialized"), I.table(
410
410
  "Prefilled Values (DOM Capture)",
411
411
  t.prefilledValues
412
- ), E.info("RHF Current Values", o.getValues()), E.end());
412
+ ), I.info("RHF Current Values", o.getValues()), I.end());
413
413
  }, [t.showDebugLogs, t.prefilledValues, o]), /* @__PURE__ */ w(Z, { ...o, children: /* @__PURE__ */ w(he, { ...e }) });
414
414
  };
415
415
  async function we(e) {
@@ -418,33 +418,33 @@ async function we(e) {
418
418
  const { wfView: n, wkfView: t } = await pe();
419
419
  if (!n || !t) return !1;
420
420
  ge(n);
421
- const o = Number(e), i = be(n, o);
422
- return i ? (Ae(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);
421
+ const o = Number(e), i = Ae(n, o);
422
+ return i ? (be(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);
423
423
  }
424
424
  async function pe() {
425
- const e = await k.top.ECM.workflowView, n = await k.top.ECM_WKFView;
425
+ const e = await P.top.ECM.workflowView, n = await P.top.ECM_WKFView;
426
426
  return !e || !n ? (console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."), {}) : { wfView: e, wkfView: n };
427
427
  }
428
428
  function ge(e) {
429
429
  e.availableStatesCOPY || (e.availableStatesCOPY = e.availableStates);
430
430
  }
431
- function be(e, n) {
431
+ function Ae(e, n) {
432
432
  const t = e.availableStatesCOPY || e.availableStates;
433
433
  return t == null ? void 0 : t.find((o) => o.sequence === n);
434
434
  }
435
- function Ae(e, n, t, o) {
435
+ function be(e, n, t, o) {
436
436
  e.availableUsers.users = [], e.availableStates = [t], n.selectActivity = () => o;
437
437
  }
438
- const G = D(null);
439
- function Re() {
440
- const e = N(G);
438
+ const G = T(null);
439
+ function Ne() {
440
+ const e = D(G);
441
441
  if (!e)
442
442
  throw new Error(
443
443
  "useSection deve ser usado dentro de um componente <Section>"
444
444
  );
445
445
  return e;
446
446
  }
447
- function Te({
447
+ function Re({
448
448
  id: e,
449
449
  className: n,
450
450
  schema: t,
@@ -455,72 +455,72 @@ function Te({
455
455
  fields: s = {},
456
456
  hidden: u = !1
457
457
  }) {
458
- const { isView: r, activityId: f } = R(), d = f, v = O(), l = i || v;
458
+ const { isView: r, activityId: m } = N(), f = m, v = O(), l = i || v;
459
459
  if (!l)
460
460
  return console.error(
461
461
  `[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`
462
462
  ), null;
463
463
  if (u) return null;
464
- const y = V(
464
+ const d = V(
465
465
  (h) => {
466
466
  var S, F, C;
467
467
  return (S = s.hidden) != null && S.includes(h) ? "hidden" : (F = s.readonly) != null && F.includes(h) ? "readonly" : (C = s.active) != null && C.includes(h) ? "active" : c ? "readonly" : "active";
468
468
  },
469
469
  [s, c]
470
- ), m = V(
471
- (h) => y(h) === "hidden",
472
- [y]
470
+ ), y = V(
471
+ (h) => d(h) === "hidden",
472
+ [d]
473
473
  ), p = V(
474
- (h) => y(h) === "readonly",
475
- [y]
474
+ (h) => d(h) === "readonly",
475
+ [d]
476
476
  ), g = V(
477
477
  (h) => {
478
478
  if (!h) return;
479
479
  const S = l.getValues("CURRENTACTIVITYID");
480
- l.setValue("LASTACTIVITYID", S), l.setValue("CURRENTACTIVITYID", d), we(Number(h));
480
+ l.setValue("LASTACTIVITYID", S), l.setValue("CURRENTACTIVITYID", f), we(Number(h));
481
481
  },
482
- [l, d]
482
+ [l, f]
483
483
  );
484
- I(() => {
484
+ E(() => {
485
485
  if (!r || !a || !t || !l) return;
486
486
  const h = l.getValues(), S = t.shape;
487
487
  S && Object.entries(S).forEach(([F, C]) => {
488
488
  var L, q;
489
- let A = C;
490
- for (; (L = A == null ? void 0 : A._def) != null && L.schema; )
491
- A = A._def.schema;
492
- const x = (q = A == null ? void 0 : A._def) == null ? void 0 : q.fluig;
489
+ let b = C;
490
+ for (; (L = b == null ? void 0 : b._def) != null && L.schema; )
491
+ b = b._def.schema;
492
+ const x = (q = b == null ? void 0 : b._def) == null ? void 0 : q.fluig;
493
493
  if ((x == null ? void 0 : x.type) !== "options" || !Array.isArray(x.values) || h[F] !== void 0) return;
494
- const P = {};
494
+ const k = {};
495
495
  x.values.forEach((M) => {
496
- P[M] = a[M] === "on";
497
- }), l.setValue(F, P, {
496
+ k[M] = a[M] === "on";
497
+ }), l.setValue(F, k, {
498
498
  shouldDirty: !1,
499
499
  shouldValidate: !1
500
500
  });
501
501
  });
502
502
  }, [r, a, t, l]);
503
- const H = b(
503
+ const H = A(
504
504
  () => ({
505
505
  id: e,
506
506
  form: l,
507
- isHidden: m,
507
+ isHidden: y,
508
508
  isReadOnly: p,
509
509
  isView: r,
510
510
  next: g,
511
- wf_activity_id: d
511
+ wf_activity_id: f
512
512
  }),
513
- [e, l, m, p, r, g, d]
513
+ [e, l, y, p, r, g, f]
514
514
  );
515
515
  return /* @__PURE__ */ w(G.Provider, { value: H, children: /* @__PURE__ */ w("section", { id: e, className: [e, n].filter(Boolean).join(" "), children: o }) });
516
516
  }
517
- const $ = D(null);
518
- function ke({ children: e, config: n }) {
519
- const t = b(() => re(n), [n]);
517
+ const $ = T(null);
518
+ function Pe({ children: e, config: n }) {
519
+ const t = A(() => re(n), [n]);
520
520
  return /* @__PURE__ */ w($.Provider, { value: t, children: e });
521
521
  }
522
- function Pe() {
523
- const e = N($);
522
+ function ke() {
523
+ const e = D($);
524
524
  if (!e)
525
525
  throw new Error(
526
526
  "useFluigApi deve ser usado dentro de um <FluigApiProvider>"
@@ -529,15 +529,15 @@ function Pe() {
529
529
  }
530
530
  export {
531
531
  Me as DebugLogger,
532
- ke as FluigApiProvider,
533
- De as FluigRuntimeProvider,
534
- Ne as FluigWorkflowForm,
532
+ Pe as FluigApiProvider,
533
+ Te as FluigRuntimeProvider,
534
+ De as FluigWorkflowForm,
535
535
  Ce as SchemaRegistryProvider,
536
- Te as Section,
537
- Ue as createFluigClient,
538
- Ye as parentProxy,
539
- Pe as useFluigApi,
540
- R as useFluigRuntime,
536
+ Re as Section,
537
+ Ye as createFluigClient,
538
+ Ue as parentProxy,
539
+ ke as useFluigApi,
540
+ N as useFluigRuntime,
541
541
  W as useSchemaRegistry,
542
- Re as useSection
542
+ Ne as useSection
543
543
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluig-kit/ecm",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "zod": "^3.0.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@fluig-kit/core": "^1.0.2",
38
+ "@fluig-kit/core": "^1.0.0",
39
39
  "@types/react": "^18.3.0",
40
40
  "@types/react-dom": "^18.3.0",
41
41
  "@vitejs/plugin-react": "^4.2.1",