@fluig-kit/ecm 1.0.5 → 1.0.7

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