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