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