@fluig-kit/ecm 1.0.17 → 1.0.19

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