@fluig-kit/ecm 1.0.4 → 1.0.5
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/node.cjs +25 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.js +64 -0
- package/package.json +4 -4
- package/dist/fluig-kit-ecm.umd.js +0 -1
- /package/dist/{fluig-kit-ecm.es.js → index.js} +0 -0
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"),S=require("react-hook-form"),P=require("@hookform/resolvers"),Y=require("zod"),w=require("@fluig-kit/core");var W=function(e,n){for(var t={};e.length;){var r=e[0],i=r.code,a=r.message,u=r.path.join(".");if(!t[u])if("unionErrors"in r){var s=r.unionErrors[0].errors[0];t[u]={message:s.message,type:s.code}}else t[u]={message:a,type:i};if("unionErrors"in r&&r.unionErrors.forEach(function(m){return m.errors.forEach(function(f){return e.push(f)})}),n){var c=t[u].types,o=c&&c[r.code];t[u]=S.appendErrors(u,n,t,i,o?[].concat(o,r.message):r.message)}e.shift()}return t},_=function(e,n,t){return t===void 0&&(t={}),function(r,i,a){try{return Promise.resolve((function(u,s){try{var c=Promise.resolve(e[t.mode==="sync"?"parse":"parseAsync"](r,n)).then(function(o){return a.shouldUseNativeValidation&&P.validateFieldsNatively({},a),{errors:{},values:t.raw?r:o}})}catch(o){return s(o)}return c&&c.then?c.then(void 0,s):c})(0,function(u){if((function(s){return Array.isArray(s?.errors)})(u))return{values:{},errors:P.toNestErrors(W(u.errors,!a.shouldUseNativeValidation&&a.criteriaMode==="all"),a)};throw u}))}catch(u){return Promise.reject(u)}}};const N=l.createContext(null);function B({children:e,baseSchema:n}){const[t,r]=l.useState([]),i=l.useMemo(()=>n??Y.z.object({}),[n]),a=l.useCallback((o,m)=>{r(f=>f.some(v=>v.id===o)?f:[...f,{id:o,schema:m}])},[]),u=l.useCallback(o=>{r(m=>m.some(f=>f.id===o)?m.filter(f=>f.id!==o):m)},[]),s=l.useMemo(()=>t.length?t.map(o=>o.schema).reduce((o,m)=>o.and(m),i):i,[t,i]),c=l.useMemo(()=>({registerSchema:a,unregisterSchema:u,mergedSchema:s}),[a,u,s]);return h.jsx(N.Provider,{value:c,children:e})}function V(){const e=l.useContext(N);if(!e)throw new Error("useSchemaRegistry deve ser usado dentro de <SchemaRegistryProvider>");return e}function k(e){return typeof e=="number"?e:isNaN(Number(e))?null:Number(e)}function L(e,n,t){if(!e)return!0;const r=Array.isArray(n)?n[0]:n,i=e.field??r,a=t?.[i];return e.hasValue!==void 0?e.hasValue?a!=null&&a!=="":a==null||a==="":e.equals!==void 0?a===e.equals:e.notEquals!==void 0?a!==e.notEquals:!0}function z(e,n,t,r,i){const a=new Set(e),u=new Set(n);return t?.forEach(s=>{if(s.from!==void 0){const o=Array.isArray(s.from)?s.from:[s.from];if(r===null||!o.includes(r))return}if(!L(s.when,s.target,i))return;const c=Array.isArray(s.target)?s.target:[s.target];switch(s.type){case"readonly":c.forEach(o=>{u.add(o),a.delete(o)});break;case"active":c.forEach(o=>{a.add(o),u.delete(o)});break;case"hidden":c.forEach(o=>{a.delete(o),u.delete(o)});break}}),{active:Array.from(a),readonly:Array.from(u)}}function G(e,n,t,r){const i=new Set(e.active),a=new Set(e.readonly),u=new Set(e.hidden??[]);return n?.forEach(s=>{if(s.from!==void 0){const o=Array.isArray(s.from)?s.from:[s.from];if(t===null||!o.includes(t))return}if(!L(s.when,s.target,r))return;const c=Array.isArray(s.target)?s.target:[s.target];switch(s.type){case"hidden":c.forEach(o=>{u.add(o),i.delete(o),a.delete(o)});break;case"active":c.forEach(o=>{i.add(o),a.delete(o),u.delete(o)});break;case"readonly":c.forEach(o=>{a.add(o),i.delete(o),u.delete(o)});break}}),{active:Array.from(i),readonly:Array.from(a),hidden:Array.from(u)}}function H(e,n){if(!e?.length)return n;const t=new Map(n.map(i=>[i.name,i])),r=[];return e.forEach(i=>{t.has(i)&&(r.push(t.get(i)),t.delete(i))}),t.forEach(i=>r.push(i)),r}function $(e){const n=new Set,t=(r=[])=>{r.forEach(i=>{i.target&&(Array.isArray(i.target)?i.target:[i.target]).forEach(u=>n.add(u)),i.when?.field&&n.add(i.when.field)})};return t(e?.fields?.rules),t(e?.sections?.rules),Array.from(n)}function K({activityId:e,previousActivityId:n,control:t,workflowStructure:r,sectionsRegistry:i}){const{registerSchema:a,unregisterSchema:u}=V(),s=k(e),c=k(n),o=s!==null?r[s]:null,m=l.useMemo(()=>$(o),[s,o]),f=S.useWatch({control:t,name:m,defaultValue:{}}),v=l.useMemo(()=>{const y={};return m.forEach((g,b)=>{y[g]=Array.isArray(f)?f[b]:f}),y},[f,m]),d=l.useMemo(()=>{if(!o)return{sections:[],fields:{active:[],readonly:[],hidden:[]}};const y=z(o.sections.active,o.sections.readonly,o.sections.rules,c,v);let g=[...y.readonly.map(A=>({name:A,mode:"readonly"})),...y.active.map(A=>({name:A,mode:"active"}))];g=H(o.sections.order,g);const b=G({active:o.fields.active,readonly:o.fields.readonly,hidden:o.fields.hidden},o.fields.rules,c,v);return{sections:g,fields:b}},[o,c,v,i]);return l.useEffect(()=>{const y=d.sections.filter(g=>g.mode==="active").map(g=>g.name);y.forEach(g=>{const b=i?.[g]?.schema;b&&a(g,b)}),Object.keys(i??{}).filter(g=>!y.includes(g)).forEach(u)},[d.sections,i,a,u]),d}function J(){if(typeof document>"u")return{};const e={};return document.querySelectorAll("input[type='radio'][name]").forEach(n=>{const t=n,r=t.getAttribute("name");r&&t.checked&&(e[r]=t.value)}),document.querySelectorAll("input[name], textarea[name], select[name]").forEach(n=>{const t=n,r=t.getAttribute("name");if(!r||e[r]!==void 0)return;const i=t.getAttribute("value")??t.value??t.textContent??"";e[r]=String(i).trim()}),document.querySelectorAll("span[name]").forEach(n=>{const t=n,r=t.getAttribute("name");if(r){const i=t.textContent?.trim()??"";i!==""&&(e[r]=i)}}),e}const T=()=>typeof window>"u"?null:new URLSearchParams(window.location.search).get("edit"),Q=()=>typeof window>"u"||!window.top?null:window.top.ECM?.workflowView?"process":"document",X=()=>{if(Q()==="process"){const n=window.top?.ECM?.workflowView;if(!n)return!1;const t=n.newRequest??n.isNewRequest,r=n.colleagueLogin;return t===!0||!!r&&r.trim()!==""}return T()===null},Z=()=>T()==="true",j=l.createContext(null);function ee({children:e,devConfig:n}){const[t,r]=l.useState(null),i=l.useMemo(()=>J()??{},[]);return l.useEffect(()=>{let a=!0;return(async()=>{const s=typeof window<"u"&&window.location.hostname==="localhost",c=typeof window<"u"&&window.self!==window.top;let o=null;try{const d=await w.parentProxy.top.ECM.workflowView.sequence;d!=null&&(o=Number(d),n?.showDebugLogs&&console.log("[FluigRuntime] Atividade:",o))}catch(d){console.warn("[FluigRuntime] Falha ao detectar atividade:",d)}const m=!s&&c&&!(X()||Z()),f={isView:m,isReadOnly:m,activityId:o,previousActivityId:null,prefilledValues:i,showDebugSubmit:!1,showDebugLogs:!1,isDev:!1};let v=f;if(n?.enabled){const d=n.isView??f.isView;v={...f,...n,isView:d,isReadOnly:d,isDev:!0,activityId:n.activityId!==void 0?n.activityId:o}}typeof window<"u"&&(window.__FLUIG_DEBUG_ENABLED__=v.showDebugLogs),v.showDebugLogs&&a&&(w.DebugLogger.header("Runtime Initialized"),w.DebugLogger.table("State",{"Detected Activity":o,"Final Activity":v.activityId,"Dev Mode":v.isDev}),w.DebugLogger.end()),a&&r(v)})(),()=>{a=!1}},[n,i]),t?h.jsx(j.Provider,{value:t,children:e}):null}function E(){const e=l.useContext(j);if(!e)throw new Error("useFluigRuntime deve ser usado dentro de <FluigRuntimeProvider>");return e}function te(e){const{activityId:n,previousActivityId:t}=E();l.useEffect(()=>{n!=null&&e.setValue("CURRENTACTIVITYID",n),t!=null&&e.setValue("LASTACTIVITYID",t)},[n,t,e]),l.useEffect(()=>{if(typeof window>"u")return;const r=window.top?.document.getElementById("send-process-button")||window.parent?.document.getElementById("workflow-actions-send")||document.getElementById("send-process-button");if(!r){console.warn("[FluigWorkflowReact] Botão de envio do Fluig não encontrado. A validação automática pode falhar.");return}return window.beforeSendValidate=()=>(e.handleSubmit(()=>{window.beforeSendValidate=()=>!0;try{r.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}))}catch{r.click()}},i=>{console.error("[Validation Errors]",i),window.top?.FLUIGC?.toast?window.top?.FLUIGC.toast({title:"Atenção",message:"Verifique os campos obrigatórios destacados em vermelho.",type:"danger"}):alert("Verifique os campos obrigatórios.")})(),!1),()=>{}},[e])}const ne=({workflowStructure:e,sectionsRegistry:n,className:t})=>{const{control:r,handleSubmit:i,register:a,setValue:u,getValues:s}=S.useFormContext(),c=E(),o=l.useRef(!1);l.useEffect(()=>{o.current||(c.activityId!=null&&u("CURRENTACTIVITYID",c.activityId),c.previousActivityId!=null&&u("LASTACTIVITYID",c.previousActivityId),o.current=!0)},[c,u]);const{sections:m,fields:f}=K({control:r,activityId:c.activityId,previousActivityId:c.previousActivityId,workflowStructure:e,sectionsRegistry:n}),v=d=>{console.log("✅ [FluigWorkflowForm] Dados válidos:",d)};return h.jsxs("form",{id:"fluig-react-form",className:t,onSubmit:i(v),noValidate:!0,children:[h.jsxs("div",{className:"hidden",style:{display:"none"},children:[h.jsx("input",{type:"hidden",...a("CURRENTACTIVITYID")}),h.jsx("input",{type:"hidden",...a("LASTACTIVITYID")})]}),m.length===0&&c.activityId!==null&&h.jsxs("p",{children:["Não foi possível encontrar a atividade: ",String(c.activityId)]}),m.map(({name:d,mode:y})=>{if(y==="hidden")return null;const g=n[d];if(!g)return null;const b=g.Component;return h.jsx(b,{id:d,fields:f,readOnly:y==="readonly"},d)}),c.isDev&&c.showDebugSubmit&&h.jsx("div",{style:{width:"100%",padding:"16px",paddingTop:"0"},children:h.jsx("button",{type:"submit",className:"btn btn-primary btn-lg btn-block",children:"Submit (Debug)"})})]})},re=e=>{const{mergedSchema:n}=V(),t=E(),r=S.useForm({resolver:n?_(n):void 0,defaultValues:t.prefilledValues,mode:"onBlur"});return te(r),l.useEffect(()=>{t.showDebugLogs&&(w.DebugLogger.header("Form Initialized"),w.DebugLogger.table("Prefilled Values (DOM Capture)",t.prefilledValues),w.DebugLogger.info("RHF Current Values",r.getValues()),w.DebugLogger.end())},[t.showDebugLogs,t.prefilledValues,r]),h.jsx(S.FormProvider,{...r,children:h.jsx(ne,{...e})})};async function oe(e){if(!e)return console.warn("[setFluigNextActivity] Nenhuma atividade informada."),!1;const{wfView:n,wkfView:t}=await ie();if(!n||!t)return!1;se(n);const r=Number(e),i=ae(n,r);return i?(ue(n,t,i,r),console.log(`[setFluigNextActivity] Próxima atividade definida: ${r}`),!0):(console.warn(`[setFluigNextActivity] Estado ${r} não encontrado nas próximas atividades disponíveis.`),console.log("Estados disponíveis:",n.availableStatesCOPY||n.availableStates),!1)}async function ie(){const e=await w.parentProxy.top.ECM.workflowView,n=await w.parentProxy.top.ECM_WKFView;return!e||!n?(console.warn("[setFluigNextActivity] Contexto Fluig inválido ou não carregado."),{}):{wfView:e,wkfView:n}}function se(e){e.availableStatesCOPY||(e.availableStatesCOPY=e.availableStates)}function ae(e,n){return(e.availableStatesCOPY||e.availableStates)?.find(r=>r.sequence===n)}function ue(e,n,t,r){e.availableUsers.users=[],e.availableStates=[t],n.selectActivity=()=>r}const M=l.createContext(null);function ce(){const e=l.useContext(M);if(!e)throw new Error("useSection deve ser usado dentro de um componente <Section>");return e}function le({id:e,className:n,schema:t,children:r,form:i,prefilledValues:a,readOnly:u,fields:s={},hidden:c=!1}){const{isView:o,activityId:m}=E(),f=m,v=S.useFormContext(),d=i||v;if(!d)return console.error(`[FluigWorkflowReact] Section "${e}" não encontrou o 'form'.`),null;if(c)return null;const y=l.useCallback(p=>s.hidden?.includes(p)?"hidden":s.readonly?.includes(p)?"readonly":s.active?.includes(p)?"active":u?"readonly":"active",[s,u]),g=l.useCallback(p=>y(p)==="hidden",[y]),b=l.useCallback(p=>y(p)==="readonly",[y]),A=l.useCallback(p=>{if(!p)return;const x=d.getValues("CURRENTACTIVITYID");d.setValue("LASTACTIVITYID",x),d.setValue("CURRENTACTIVITYID",f),oe(Number(p))},[d,f]);l.useEffect(()=>{if(!o||!a||!t||!d)return;const p=d.getValues(),x=t.shape;x&&Object.entries(x).forEach(([C,U])=>{let I=U;for(;I?._def?.schema;)I=I._def.schema;const F=I?._def?.fluig;if(F?.type!=="options"||!Array.isArray(F.values)||p[C]!==void 0)return;const R={};F.values.forEach(D=>{R[D]=a[D]==="on"}),d.setValue(C,R,{shouldDirty:!1,shouldValidate:!1})})},[o,a,t,d]);const O=l.useMemo(()=>({id:e,form:d,isHidden:g,isReadOnly:b,isView:o,next:A,wf_activity_id:f}),[e,d,g,b,o,A,f]);return h.jsx(M.Provider,{value:O,children:h.jsx("section",{id:e,className:[e,n].filter(Boolean).join(" "),children:r})})}const q=l.createContext(null);function de({children:e,config:n}){const t=l.useMemo(()=>w.createFluigClient(n),[n]);return h.jsx(q.Provider,{value:t,children:e})}function fe(){const e=l.useContext(q);if(!e)throw new Error("useFluigApi deve ser usado dentro de um <FluigApiProvider>");return e}Object.defineProperty(exports,"DebugLogger",{enumerable:!0,get:()=>w.DebugLogger});Object.defineProperty(exports,"createFluigClient",{enumerable:!0,get:()=>w.createFluigClient});Object.defineProperty(exports,"parentProxy",{enumerable:!0,get:()=>w.parentProxy});exports.FluigApiProvider=de;exports.FluigRuntimeProvider=ee;exports.FluigWorkflowForm=re;exports.SchemaRegistryProvider=B;exports.Section=le;exports.useFluigApi=fe;exports.useFluigRuntime=E;exports.useSchemaRegistry=V;exports.useSection=ce;
|
package/dist/node.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("chalk");function c(e){return e._def?.schema??e}function d(e){let t=e._def?.fluig;if(t?.values)return t.values;const l=c(e);if(l!==e&&(t=l._def?.fluig,t?.values))return t.values;const n=l._def;return(n?.meta??n?.metadata)?.fluig?.values??null}function f(e){return e?._def?.typeName!=="ZodObject"?[]:Object.entries(e.shape)}function m(e){const t=new Set;return(Array.isArray(e)?e:Object.values(e).map(n=>n.schema).filter(Boolean)).forEach(n=>{let r=n;for(;r._def?.schema;)r=r._def.schema;r._def?.typeName==="ZodObject"&&f(r).forEach(([a,s])=>{t.add(a);const i=d(s);i?.length&&i.forEach(u=>t.add(u))})}),Array.from(t)}function g(e){const t=m(e),l=t.map(n=>`<input type="hidden" name="${n}" />`).join(`
|
|
2
|
+
`);return console.log(o.blue.bold(`
|
|
3
|
+
=== Inputs gerados (Build Script) ===
|
|
4
|
+
`)),t.forEach((n,r)=>{console.log(`${o.yellow(r+1+".")} ${o.green(n)}`)}),console.log(o.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=g;
|
package/dist/node.d.ts
ADDED
package/dist/node.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import l from "chalk";
|
|
2
|
+
function f(e) {
|
|
3
|
+
return e._def?.schema ?? e;
|
|
4
|
+
}
|
|
5
|
+
function u(e) {
|
|
6
|
+
let t = e._def?.fluig;
|
|
7
|
+
if (t?.values) return t.values;
|
|
8
|
+
const o = f(e);
|
|
9
|
+
if (o !== e && (t = o._def?.fluig, t?.values))
|
|
10
|
+
return t.values;
|
|
11
|
+
const n = o._def;
|
|
12
|
+
return (n?.meta ?? n?.metadata)?.fluig?.values ?? null;
|
|
13
|
+
}
|
|
14
|
+
function d(e) {
|
|
15
|
+
return e?._def?.typeName !== "ZodObject" ? [] : Object.entries(e.shape);
|
|
16
|
+
}
|
|
17
|
+
function m(e) {
|
|
18
|
+
const t = /* @__PURE__ */ new Set();
|
|
19
|
+
return (Array.isArray(e) ? e : Object.values(e).map((n) => n.schema).filter(Boolean)).forEach((n) => {
|
|
20
|
+
let r = n;
|
|
21
|
+
for (; r._def?.schema; )
|
|
22
|
+
r = r._def.schema;
|
|
23
|
+
r._def?.typeName === "ZodObject" && d(r).forEach(([a, s]) => {
|
|
24
|
+
t.add(a);
|
|
25
|
+
const i = u(s);
|
|
26
|
+
i?.length && i.forEach((c) => t.add(c));
|
|
27
|
+
});
|
|
28
|
+
}), Array.from(t);
|
|
29
|
+
}
|
|
30
|
+
function h(e) {
|
|
31
|
+
const t = m(e), o = t.map(
|
|
32
|
+
(n) => `<input type="hidden" name="${n}" />`
|
|
33
|
+
).join(`
|
|
34
|
+
`);
|
|
35
|
+
return console.log(l.blue.bold(`
|
|
36
|
+
=== Inputs gerados (Build Script) ===
|
|
37
|
+
`)), t.forEach((n, r) => {
|
|
38
|
+
console.log(`${l.yellow(r + 1 + ".")} ${l.green(n)}`);
|
|
39
|
+
}), console.log(l.blue.bold(`
|
|
40
|
+
=====================================
|
|
41
|
+
`)), `<!DOCTYPE html>
|
|
42
|
+
<html lang="pt-br">
|
|
43
|
+
<head>
|
|
44
|
+
<meta charset="UTF-8">
|
|
45
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
46
|
+
<title>Workflow Fluig</title>
|
|
47
|
+
|
|
48
|
+
<link rel="stylesheet" href="/portal/style-guide/css/fluig-style-guide.min.css">
|
|
49
|
+
<link rel="stylesheet" crossorigin href="./main.css">
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<form id="form" name="form">
|
|
53
|
+
<div id="root">
|
|
54
|
+
${o}
|
|
55
|
+
</div>
|
|
56
|
+
</form>
|
|
57
|
+
|
|
58
|
+
<script src="./bundle.js"><\/script>
|
|
59
|
+
</body>
|
|
60
|
+
</html>`;
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
h as generateHtmlTemplate
|
|
64
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluig-kit/ecm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/fluig-kit-ecm.umd.js",
|
|
6
6
|
"private": false,
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"require": "./dist/fluig-kit-ecm.umd.js"
|
|
18
18
|
},
|
|
19
19
|
"./node": {
|
|
20
|
-
"types": "./
|
|
21
|
-
"import": "./
|
|
22
|
-
"require": "./
|
|
20
|
+
"types": "./dist/services/generateHtmlTemplate.d.ts",
|
|
21
|
+
"import": "./dist/node.js",
|
|
22
|
+
"require": "./dist/node.cjs"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
@@ -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"})}));
|
|
File without changes
|