@zealicsolutions/web-ui 1.1.82 → 1.1.84

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.
@@ -1,2 +1,2 @@
1
- import{jsx as e}from"../node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.esm.js";import"../contexts/AccountButtonContext/AccountButtonContext.js";import{useRef as t,useMemo as r,useCallback as o,useEffect as n}from"react";import"../contexts/ApiContext/ApiContext.js";import"../contexts/ContainerRuntimeContext/ContainerRuntimeContext.js";import"../contexts/FormStepContext/FormStepContext.js";import{FormStepContextProvider as i}from"../contexts/FormStepContext/FormStepContextProvider.js";import"../contexts/LayoutContext/LayoutContext.js";import"../theme/theme.js";import"../theme/provider.js";import"../theme/toastStyles.js";import"../contexts/MlrRichTextViewerContext/MlrRichTextViewerContext.js";import"../contexts/OrganismContext/OrganismContext.js";import{useOrganismContext as a}from"../contexts/OrganismContext/useOrganismContext.js";import"../contexts/PopupContext/PopupContext.js";import"../contexts/ReplicatorFormContext/ReplicatorFormContext.js";import"../contexts/ReplicatorRegistryContext/ReplicatorRegistryContext.js";import{ReplicatorRegistryContextProvider as s}from"../contexts/ReplicatorRegistryContext/ReplicatorRegistryContextProvider.js";import"../contexts/StateContext/StateContext.js";import{decodeBase64UrlToObject as c}from"../helpers/rwoContext.js";import{useForm as l,FormProvider as u}from"../node_modules/react-hook-form/dist/index.esm.mjs.js";import"../contexts/WebpageContext/WebpageContext.js";import{useStateModifierHandler as p}from"./hooks/useStateModifierHandler.js";const d=(e,t)=>{Object.values(e).forEach(e=>{const r=e,o=r&&r._f;o?t(o):r&&"object"==typeof r&&d(r,t)})},f=e=>{if(!e)return null;if("object"!=typeof e)return null;if(0===Object.keys(e).length)return null;try{return JSON.stringify(e)}catch{return null}},m=({mode:m="onChange",state:h,children:g})=>{const y=l({mode:m,defaultValues:{}}),{onStateChange:x}=p(),{formId:w="",routing:j,prefillData:C,loadRecordData:b,isLoadingData:k}=a(),S=t(null),O=t(!1),R=t(null),D=t(!1);t(!1);const v=t(!1),F=t(null),P=t(!1),$=r(()=>!!w&&(!j?.organismIdFromUrl||j.organismIdFromUrl===w),[w,j?.organismIdFromUrl]),E=j?.rwoRecordIdFromUrl||null,I=o((e,t)=>{if(!$)return;const r=f(e);r&&S.current!==r&&(y.reset(e,{keepErrors:!1,keepDirty:!1,keepTouched:!1,keepValues:!1}),S.current=r)},[$,y,w]),T=o((e,t)=>{const r=JSON.stringify(e);let o="";if("undefined"!=typeof window&&"function"==typeof window.btoa)o=window.btoa(unescape(encodeURIComponent(r)));else{const e=globalThis?.Buffer;o=e?e.from(r,"utf8").toString("base64"):""}return/[-_]/.test(t)&&!/[+/]/.test(t)?o.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,""):o},[]),U=o(e=>{const t=c(e);if(t)return t;try{const t=e.replace(/ /g,"+");let r="";if("undefined"!=typeof window&&"function"==typeof window.atob)r=decodeURIComponent(escape(window.atob(t)));else{const e=globalThis?.Buffer;r=e?e.from(t,"base64").toString("utf8"):""}return JSON.parse(r)}catch{return null}},[]),_=o(()=>{if("undefined"==typeof window)return;if(!w)return;const{source:e,params:t,hashPath:r}=(()=>{const e=new URLSearchParams(window.location.search);if(e.has("rwoContext"))return{source:"search",params:e,hashPath:window.location.hash};const t=window.location.hash||"",r=t.indexOf("?");if(-1!==r){const e=t.slice(0,r),o=t.slice(r+1),n=new URLSearchParams(o);if(n.has("rwoContext"))return{source:"hash",params:n,hashPath:e}}return{source:"search",params:e,hashPath:window.location.hash}})(),o=t.get("rwoContext");if(!o)return;const n=U(o);if(!n||"object"!=typeof n)return;let i=!1;const a=(e,t)=>{const r=e[t];if(!r||"object"!=typeof r)return!1;if(!Object.prototype.hasOwnProperty.call(r,"prefillData"))return!1;const o={...r};return delete o.prefillData,0===Object.keys(o).length?delete e[t]:e[t]=o,!0};Object.entries(n).forEach(([e,t])=>{if(!t||"object"!=typeof t||Array.isArray(t))return;const r={...t};a(r,w)&&(0===Object.keys(r).length?delete n[e]:n[e]=r,i=!0)});const s={...n};if(a(s,w)&&(Object.assign(n,s),i=!0),!i)return;if(0===Object.keys(n).length)t.delete("rwoContext");else{const e=T(n,o);t.set("rwoContext",e)}const c=t.toString(),l="hash"===e?`${window.location.pathname}${window.location.search}${r}${c?`?${c}`:""}`:`${window.location.pathname}${c?`?${c}`:""}${window.location.hash}`;l!==`${window.location.pathname}${window.location.search}${window.location.hash}`&&window.history.replaceState(null,"",l)},[w,T,U]);return n(()=>{if(h){if("default"===h)return y.reset({},{keepErrors:!1,keepDirty:!1,keepTouched:!1,keepValues:!1}),y.clearErrors(),void(S.current=null);if("required_error"===h)return y.reset({},{keepErrors:!1,keepDirty:!1,keepTouched:!1,keepValues:!1}),S.current=null,void y.trigger();if("validation_error"===h){const e=setTimeout(async()=>{y.reset({},{keepErrors:!1,keepDirty:!1,keepTouched:!1,keepValues:!1}),S.current=null,d(y.control._fields,({name:e,pattern:t})=>{t?.value instanceof RegExp&&".+"===t.value.source&&""===t.value.flags||y.setError(e,{type:"required",message:"object"==typeof t&&t?.message||"Invalid value"})})},0);return()=>clearTimeout(e)}}},[h,y]),n(()=>{y.formState.isDirty&&!D.current&&(D.current=!0,x({id:w,type:"started"}))},[y.formState.isDirty,w,x]),n(()=>{E!==R.current&&(S.current=null,D.current=!1,v.current=!1,P.current=!1,F.current=null,R.current=E)},[E]),n(()=>{O.current=Boolean(k)},[k]),n(()=>{if($&&C&&"object"==typeof C){const e="data"in C&&"object"==typeof C.data?C.data:C;if(Object.keys(e).length>0){const t=f(e),r=!!t&&t!==F.current;if(r&&(S.current=null,v.current=!1,P.current=!1,F.current=t),v.current)return S.current===t?(console.log("⏭️ [FormContainer] Skipping prefillData - already applied"),void(P.current||(_(),P.current=!0))):(console.log("⏭️ [FormContainer] Skipping prefillData - already applied once (preserving user changes)"),void(P.current||(_(),P.current=!0)));if((Object.keys(y.formState.dirtyFields||{}).length>0||Object.keys(y.formState.touchedFields||{}).length>0)&&!r)return console.log("⏭️ [FormContainer] Skipping prefillData - form has been interacted with"),v.current=!0,void(P.current||(_(),P.current=!0));console.group("🟢 [FormContainer] Applying Prefill Data"),console.log("📥 Received prefillData:",JSON.stringify(C,null,2)),console.log("📋 Data to apply:",JSON.stringify(e,null,2)),console.log("🆔 Form ID:",w),I(e,"prefillData"),console.log("✅ Prefill data applied"),console.groupEnd(),v.current=!0,t&&(F.current=t),P.current||(_(),P.current=!0)}}},[$,C,I,w]),n(()=>{$&&E&&"function"==typeof b&&(k||C&&"object"==typeof C&&Object.keys(C).length>0||null===S.current&&(O.current=!0,(async()=>{try{const e=await b({rwoRecordId:E});e&&"object"==typeof e&&Object.keys(e).length>0&&I(e,"loadRecordData")}catch{}finally{O.current=!1}})()))},[$,E,b,I,k,C,w]),e(u,{...y,children:e(s,{children:e(i,{children:g})})})};export{m as FormContainer,d as walkFields};
1
+ import{jsx as e}from"../node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.esm.js";import"../contexts/AccountButtonContext/AccountButtonContext.js";import{useRef as t,useMemo as r,useCallback as o,useEffect as n}from"react";import"../contexts/ApiContext/ApiContext.js";import"../contexts/ContainerRuntimeContext/ContainerRuntimeContext.js";import"../contexts/FormStepContext/FormStepContext.js";import{FormStepContextProvider as i}from"../contexts/FormStepContext/FormStepContextProvider.js";import"../contexts/LayoutContext/LayoutContext.js";import"../theme/theme.js";import"../theme/provider.js";import"../theme/toastStyles.js";import"../contexts/MlrRichTextViewerContext/MlrRichTextViewerContext.js";import"../contexts/OrganismContext/OrganismContext.js";import{useOrganismContext as a}from"../contexts/OrganismContext/useOrganismContext.js";import"../contexts/PopupContext/PopupContext.js";import"../contexts/ReplicatorFormContext/ReplicatorFormContext.js";import"../contexts/ReplicatorRegistryContext/ReplicatorRegistryContext.js";import{ReplicatorRegistryContextProvider as s}from"../contexts/ReplicatorRegistryContext/ReplicatorRegistryContextProvider.js";import"../contexts/StateContext/StateContext.js";import{useForm as c,FormProvider as l}from"../node_modules/react-hook-form/dist/index.esm.mjs.js";import"../contexts/WebpageContext/WebpageContext.js";import{decodeBase64UrlToObject as u}from"../helpers/rwoContext.js";import{useStateModifierHandler as p}from"./hooks/useStateModifierHandler.js";const d=(e,t)=>{Object.values(e).forEach(e=>{const r=e,o=r&&r._f;o?t(o):r&&"object"==typeof r&&d(r,t)})},f=e=>{if(!e)return null;if("object"!=typeof e)return null;if(0===Object.keys(e).length)return null;try{return JSON.stringify(e)}catch{return null}},m=({mode:m="onChange",state:h,children:g})=>{const y=c({mode:m,defaultValues:{}}),{onStateChange:x}=p(),{formId:w="",routing:j,prefillData:C,loadRecordData:b,isLoadingData:k}=a(),S=t(null),O=t(!1),R=t(null),D=t(!1);t(!1);const v=t(!1),F=t(null),P=t(!1),$=r(()=>!!w&&(!j?.organismIdFromUrl||j.organismIdFromUrl===w),[w,j?.organismIdFromUrl]),E=j?.rwoRecordIdFromUrl||null,I=o((e,t)=>{if(!$)return;const r=f(e);r&&S.current!==r&&(y.reset(e,{keepErrors:!1,keepDirty:!1,keepTouched:!1,keepValues:!1}),S.current=r)},[$,y,w]),T=o((e,t)=>{const r=JSON.stringify(e);let o="";if("undefined"!=typeof window&&"function"==typeof window.btoa)o=window.btoa(unescape(encodeURIComponent(r)));else{const e=globalThis?.Buffer;o=e?e.from(r,"utf8").toString("base64"):""}return/[-_]/.test(t)&&!/[+/]/.test(t)?o.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,""):o},[]),U=o(e=>{const t=u(e);if(t)return t;try{const t=e.replace(/ /g,"+");let r="";if("undefined"!=typeof window&&"function"==typeof window.atob)r=decodeURIComponent(escape(window.atob(t)));else{const e=globalThis?.Buffer;r=e?e.from(t,"base64").toString("utf8"):""}return JSON.parse(r)}catch{return null}},[]),_=o(()=>{if("undefined"==typeof window)return;if(!w)return;const{source:e,params:t,hashPath:r}=(()=>{const e=new URLSearchParams(window.location.search);if(e.has("rwoContext"))return{source:"search",params:e,hashPath:window.location.hash};const t=window.location.hash||"",r=t.indexOf("?");if(-1!==r){const e=t.slice(0,r),o=t.slice(r+1),n=new URLSearchParams(o);if(n.has("rwoContext"))return{source:"hash",params:n,hashPath:e}}return{source:"search",params:e,hashPath:window.location.hash}})(),o=t.get("rwoContext");if(!o)return;const n=U(o);if(!n||"object"!=typeof n)return;let i=!1;const a=(e,t)=>{const r=e[t];if(!r||"object"!=typeof r)return!1;if(!Object.prototype.hasOwnProperty.call(r,"prefillData"))return!1;const o={...r};return delete o.prefillData,0===Object.keys(o).length?delete e[t]:e[t]=o,!0};Object.entries(n).forEach(([e,t])=>{if(!t||"object"!=typeof t||Array.isArray(t))return;const r={...t};a(r,w)&&(0===Object.keys(r).length?delete n[e]:n[e]=r,i=!0)});const s={...n};if(a(s,w)&&(Object.assign(n,s),i=!0),!i)return;if(0===Object.keys(n).length)t.delete("rwoContext");else{const e=T(n,o);t.set("rwoContext",e)}const c=t.toString(),l="hash"===e?`${window.location.pathname}${window.location.search}${r}${c?`?${c}`:""}`:`${window.location.pathname}${c?`?${c}`:""}${window.location.hash}`;l!==`${window.location.pathname}${window.location.search}${window.location.hash}`&&window.history.replaceState(null,"",l)},[w,T,U]);return n(()=>{if(h){if("default"===h)return y.reset({},{keepErrors:!1,keepDirty:!1,keepTouched:!1,keepValues:!1}),y.clearErrors(),void(S.current=null);if("required_error"===h)return y.reset({},{keepErrors:!1,keepDirty:!1,keepTouched:!1,keepValues:!1}),S.current=null,void y.trigger();if("validation_error"===h){const e=setTimeout(async()=>{y.reset({},{keepErrors:!1,keepDirty:!1,keepTouched:!1,keepValues:!1}),S.current=null,d(y.control._fields,({name:e,pattern:t})=>{t?.value instanceof RegExp&&".+"===t.value.source&&""===t.value.flags||y.setError(e,{type:"required",message:"object"==typeof t&&t?.message||"Invalid value"})})},0);return()=>clearTimeout(e)}}},[h,y]),n(()=>{y.formState.isDirty&&!D.current&&(D.current=!0,x({id:w,type:"started"}))},[y.formState.isDirty,w,x]),n(()=>{E!==R.current&&(S.current=null,D.current=!1,v.current=!1,P.current=!1,F.current=null,R.current=E)},[E]),n(()=>{O.current=Boolean(k)},[k]),n(()=>{if($&&C&&"object"==typeof C){const e="data"in C&&"object"==typeof C.data?C.data:C;if(Object.keys(e).length>0){const t=f(e),r=!!t&&t!==F.current;if(r&&(S.current=null,v.current=!1,P.current=!1,F.current=t),v.current)return S.current===t?(console.log("⏭️ [FormContainer] Skipping prefillData - already applied"),void(P.current||(_(),P.current=!0))):(console.log("⏭️ [FormContainer] Skipping prefillData - already applied once (preserving user changes)"),void(P.current||(_(),P.current=!0)));if((Object.keys(y.formState.dirtyFields||{}).length>0||Object.keys(y.formState.touchedFields||{}).length>0)&&!r)return console.log("⏭️ [FormContainer] Skipping prefillData - form has been interacted with"),v.current=!0,void(P.current||(_(),P.current=!0));console.group("🟢 [FormContainer] Applying Prefill Data"),console.log("📥 Received prefillData:",JSON.stringify(C,null,2)),console.log("📋 Data to apply:",JSON.stringify(e,null,2)),console.log("🆔 Form ID:",w),I(e,"prefillData"),console.log("✅ Prefill data applied"),console.groupEnd(),v.current=!0,t&&(F.current=t),P.current||(_(),P.current=!0)}}},[$,C,I,w]),n(()=>{$&&E&&"function"==typeof b&&(k||C&&"object"==typeof C&&Object.keys(C).length>0||null===S.current&&(O.current=!0,(async()=>{try{const e=await b({rwoRecordId:E});e&&"object"==typeof e&&Object.keys(e).length>0&&I(e,"loadRecordData")}catch{}finally{O.current=!1}})()))},[$,E,b,I,k,C,w]),e(l,{...y,children:e(s,{children:e(i,{children:g})})})};export{m as FormContainer,d as walkFields};
2
2
  //# sourceMappingURL=FormContainer.js.map
@@ -1,2 +1,2 @@
1
- import{jsx as e}from"../../node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.esm.js";import{paramKeys as t}from"../../constants/params.js";import{StateContext as r}from"./StateContext.js";import{decodeBase64UrlToObject as n}from"../../helpers/rwoContext.js";import{useRef as o,useMemo as i,useCallback as s,useEffect as a}from"react";import{useForm as c}from"../../node_modules/react-hook-form/dist/index.esm.mjs.js";const u=e=>Boolean(e)&&"object"==typeof e&&!Array.isArray(e),f=()=>{if("undefined"!=typeof window)try{return new URLSearchParams(window.location.search||"").get("rwoContext")||void 0}catch{return}},m=(e,t)=>{if(!e||!t)return;return[e.filterFormByPage,e.filtersByPage,e.filterParamsByPage,e.filterFormByWebpage,e.filtersByWebpage,e.filterParamsByWebpage].filter(u).map(e=>e[t]).find(u)},l=e=>{try{return JSON.parse(JSON.stringify(e))}catch{return{...e}}},d=e=>{if(null==e)return!1;if("string"==typeof e)return e.trim().length>0;if(Array.isArray(e))return e.some(e=>d(e));if("object"==typeof e){const t=Object.entries(e);return 0!==t.length&&t.some(([,e])=>d(e))}return!0},p=new Map,g=new Map,y=()=>{p.clear(),g.clear()},h=({initStateConfig:y,children:h,stateHandler:w,authenticated:b,pageId:j})=>{const S=o(new Map),P=o(p),v=o(g),B=i(()=>y||{},[y]),x=j||(()=>{if("undefined"!=typeof window)try{const e=new URLSearchParams(window.location.search||"");return e.get(t.runtimeSelectedWebpageId)||e.get(t.previewSelectedWebpageId)||void 0}catch{return}})(),C=f(),O=!(()=>{const e=f();if(!e)return!1;const t=n(e);return!(!t||"object"!=typeof t)&&d(t)})(),F=s(async(e,t={})=>{const{debounceMs:r=0,skipBackendSync:n=!1}=t,o={...B,...e},i=o;if(n)return w?.(i),o;const s=()=>{w?.(i)};if(r>0&&j){const e=S.current.get(j);e&&clearTimeout(e);const t=setTimeout(()=>{S.current.delete(j),s()},r);return S.current.set(j,t),o}return s(),o},[B,w,j]),W=s(()=>{if(x&&O){const e=v.current.get(x);if(e)return l(e)}const e=u(B?.params)?B.params:void 0,t=m(e,x)||m(B,x);if(t)return x&&O&&v.current.set(x,l(t)),t;if(x)return{};const r=e?.filterForm??e?.filters??e?.filterParams??B?.filterForm??B?.filters??B?.filterParams??void 0;return u(r)?r:{}},[B,x,O]),A=o(null);null===A.current&&(A.current=W());const M=c({defaultValues:A.current,mode:"onChange"}),$=i(()=>W(),[W]),k=o(`${x||""}|${C||""}`),I=s(e=>{if(!x||!O)return;const t=l(e),r=JSON.stringify(t);P.current.get(x)!==r&&(P.current.set(x,r),v.current.set(x,t))},[x,O]);a(()=>{const e=`${x||""}|${C||""}`;if(k.current!==e)return k.current=e,void M.reset($);M.formState.isDirty||M.reset($)},[x,C,$,M]),a(()=>{if(!M?.watch)return;const e=M.getValues?.()??{};x&&O&&I(e);const t=M.watch(e=>{x&&O&&I(e??{})});return()=>{t?.unsubscribe?.()}},[M,I,x,O]);const J=i(()=>({stateConfig:y,stateHandler:w,authenticated:b,stateObject:B,updateStateObject:F,filterForm:M}),[y,w,b,B,F,M]);return e(r.Provider,{value:J,children:h})};export{h as StateContextProvider,y as __resetStateContextFilterCacheForTests};
1
+ import{jsx as e}from"../../node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.esm.js";import{paramKeys as t}from"../../constants/params.js";import{StateContext as r}from"./StateContext.js";import{useRef as n,useMemo as a,useCallback as i,useEffect as o}from"react";import{useForm as s}from"../../node_modules/react-hook-form/dist/index.esm.mjs.js";const c=e=>Boolean(e)&&"object"==typeof e&&!Array.isArray(e),u=(e,t)=>{if(!e||!t)return;return[e.filterFormByPage,e.filtersByPage,e.filterParamsByPage,e.filterFormByWebpage,e.filtersByWebpage,e.filterParamsByWebpage].filter(c).map(e=>e[t]).find(c)},f=e=>{try{return JSON.parse(JSON.stringify(e))}catch{return{...e}}},m=new Map,l=new Map,d=()=>{m.clear(),l.clear()},p=({initStateConfig:d,children:p,stateHandler:g,authenticated:y,pageId:h})=>{const b=n(new Map),w=n(m),S=n(l),j=a(()=>d||{},[d]),P=h||(()=>{if("undefined"!=typeof window)try{const e=new URLSearchParams(window.location.search||"");return e.get(t.runtimeSelectedWebpageId)||e.get(t.previewSelectedWebpageId)||void 0}catch{return}})(),B=i(async(e,t={})=>{const{debounceMs:r=0,skipBackendSync:n=!1}=t,a={...j,...e},i=a;if(n)return g?.(i),a;const o=()=>{g?.(i)};if(r>0&&h){const e=b.current.get(h);e&&clearTimeout(e);const t=setTimeout(()=>{b.current.delete(h),o()},r);return b.current.set(h,t),a}return o(),a},[j,g,h]),v=i(()=>{if(P){const e=S.current.get(P);if(e)return f(e)}const e=c(j?.params)?j.params:void 0,t=u(e,P)||u(j,P);if(t)return P&&S.current.set(P,f(t)),t;if(P)return{};const r=e?.filterForm??e?.filters??e?.filterParams??j?.filterForm??j?.filters??j?.filterParams??void 0;return c(r)?r:{}},[j,P]),x=n(null);null===x.current&&(x.current=v());const F=s({defaultValues:x.current,mode:"onChange"}),O=a(()=>v(),[v]),W=n(P),C=i(e=>{if(!P)return;const t=f(e),r=JSON.stringify(t);w.current.get(P)!==r&&(w.current.set(P,r),S.current.set(P,t))},[P]);o(()=>{if(W.current!==P)return W.current=P,void F.reset(O);F.formState.isDirty||F.reset(O)},[P,O,F]),o(()=>{if(!F?.watch)return;const e=F.getValues?.()??{};P&&C(e);const t=F.watch(e=>{P&&C(e??{})});return()=>{t?.unsubscribe?.()}},[F,C,P]);const M=a(()=>({stateConfig:d,stateHandler:g,authenticated:y,stateObject:j,updateStateObject:B,filterForm:F}),[d,g,y,j,B,F]);return e(r.Provider,{value:M,children:p})};export{p as StateContextProvider,d as __resetStateContextFilterCacheForTests};
2
2
  //# sourceMappingURL=StateContextProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"StateContextProvider.js","sources":["../../../../../src/contexts/StateContext/StateContextProvider.tsx"],"sourcesContent":[null],"names":["isRecord","value","Boolean","Array","isArray","getRwoContextParamFromLocation","window","URLSearchParams","location","search","get","undefined","getPageScopedFilters","source","targetPageId","filterFormByPage","filtersByPage","filterParamsByPage","filterFormByWebpage","filtersByWebpage","filterParamsByWebpage","filter","map","candidate","find","cloneRecord","JSON","parse","stringify","hasMeaningfulContextValue","trim","length","some","item","entries","Object","nestedValue","sessionFilterHashesByPage","Map","sessionFilterValuesByPage","__resetStateContextFilterCacheForTests","clear","StateContextProvider","initStateConfig","children","stateHandler","authenticated","pageId","updateDebouncerRef","useRef","syncedFilterHashesRef","localFilterValuesByPageRef","stateObject","useMemo","resolvedPageId","params","paramKeys","runtimeSelectedWebpageId","previewSelectedWebpageId","getSelectedWebpageIdFromLocation","currentRwoContextParam","shouldUseLocalFilterCache","rwoContextParam","decoded","decodeBase64UrlToObject","hasMeaningfulRwoContextInLocation","updateStateObject","useCallback","async","updates","options","debounceMs","skipBackendSync","merged","updatedStateConfig","syncFn","existingTimer","current","clearTimeout","timer","setTimeout","delete","set","getInitialFilterValues","localCached","pageScoped","legacyCandidate","filterForm","filters","filterParams","filterDefaultsRef","useForm","defaultValues","mode","filterDefaultsSnapshot","previousNavigationScopeRef","persistFilterValuesByPage","rawValues","filterValues","hash","useEffect","navigationScope","reset","formState","isDirty","watch","initialValues","getValues","subscription","unsubscribe","contextValues","stateConfig","_jsx","StateContext","Provider"],"mappings":"sbA8BA,MAAMA,EAAYC,GAChBC,QAAQD,IAA2B,iBAAVA,IAAuBE,MAAMC,QAAQH,GAiB1DI,EAAiC,KACrC,GAAsB,oBAAXC,OAEX,IAEE,OADe,IAAIC,gBAAgBD,OAAOE,SAASC,QAAU,IAC/CC,IAAI,oBAAiBC,CACpC,CAAC,MACA,MACD,GAGGC,EAAuB,CAC3BC,EACAC,KAEA,IAAKD,IAAWC,EAAc,OAgB9B,MAdyB,CACvBD,EAAOE,iBACPF,EAAOG,cACPH,EAAOI,mBACPJ,EAAOK,oBACPL,EAAOM,iBACPN,EAAOO,uBAINC,OAAOrB,GACPsB,IAAKC,GAAcA,EAAUT,IAC7BU,KAAKxB,IAKJyB,EAAexB,IACnB,IACE,OAAOyB,KAAKC,MAAMD,KAAKE,UAAU3B,GAClC,CAAC,MACA,MAAO,IAAKA,EACb,GAGG4B,EAA6B5B,IACjC,GAAIA,QAAuC,OAAO,EAElD,GAAqB,iBAAVA,EACT,OAAOA,EAAM6B,OAAOC,OAAS,EAG/B,GAAI5B,MAAMC,QAAQH,GAChB,OAAOA,EAAM+B,KAAMC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EAAgBO,IAGnBuC,EAAU,KACR,MAAMC,EAAkB,GAAG/C,GAAkB,MAAMM,GAA0B,KAG7E,GAFkCmC,EAA2BlB,UAAYwB,EAKvE,OAFAN,EAA2BlB,QAAUwB,OACrCd,EAAWe,MAAMR,GAIfP,EAAWgB,UAAUC,SACzBjB,EAAWe,MAAMR,IAChB,CAACxC,EAAgBM,EAAwBkC,EAAwBP,IAEpEa,EAAU,KACR,IAAKb,GAAYkB,MAAO,OAExB,MAAMC,EAAiBnB,EAAWoB,eAAiB,CAAE,EACjDrD,GAAkBO,GACpBmC,EAA0BU,GAG5B,MAAME,EAAerB,EAAWkB,MAAOxG,IAEjCqD,GAAkBO,GACpBmC,EAFkB/F,GAAS,CAAA,KAM/B,MAAO,KACL2G,GAAcC,kBAEf,CAACtB,EAAYS,EAA2B1C,EAAgBO,IAE3D,MAAMiD,EAAgBzD,EACpB,KAAO,CACL0D,YAAapE,EACbE,eACAC,gBAEAM,cACAc,oBACAqB,eAEF,CAAC5C,EAAiBE,EAAcC,EAAeM,EAAac,EAAmBqB,IAGjF,OAAOyB,EAACC,EAAaC,SAAQ,CAACjH,MAAO6G,EAAalE,SAAGA"}
1
+ {"version":3,"file":"StateContextProvider.js","sources":["../../../../../src/contexts/StateContext/StateContextProvider.tsx"],"sourcesContent":[null],"names":["isRecord","value","Boolean","Array","isArray","getPageScopedFilters","source","targetPageId","filterFormByPage","filtersByPage","filterParamsByPage","filterFormByWebpage","filtersByWebpage","filterParamsByWebpage","filter","map","candidate","find","cloneRecord","JSON","parse","stringify","sessionFilterHashesByPage","Map","sessionFilterValuesByPage","__resetStateContextFilterCacheForTests","clear","StateContextProvider","initStateConfig","children","stateHandler","authenticated","pageId","updateDebouncerRef","useRef","syncedFilterHashesRef","localFilterValuesByPageRef","stateObject","useMemo","resolvedPageId","window","params","URLSearchParams","location","search","get","paramKeys","runtimeSelectedWebpageId","previewSelectedWebpageId","undefined","getSelectedWebpageIdFromLocation","updateStateObject","useCallback","async","updates","options","debounceMs","skipBackendSync","merged","updatedStateConfig","syncFn","existingTimer","current","clearTimeout","timer","setTimeout","delete","set","getInitialFilterValues","localCached","pageScoped","legacyCandidate","filterForm","filters","filterParams","filterDefaultsRef","useForm","defaultValues","mode","filterDefaultsSnapshot","previousPageIdRef","persistFilterValuesByPage","rawValues","filterValues","hash","useEffect","reset","formState","isDirty","watch","initialValues","getValues","subscription","unsubscribe","contextValues","stateConfig","_jsx","StateContext","Provider"],"mappings":"gXA6BA,MAAMA,EAAYC,GAChBC,QAAQD,IAA2B,iBAAVA,IAAuBE,MAAMC,QAAQH,GAiB1DI,EAAuB,CAC3BC,EACAC,KAEA,IAAKD,IAAWC,EAAc,OAgB9B,MAdyB,CACvBD,EAAOE,iBACPF,EAAOG,cACPH,EAAOI,mBACPJ,EAAOK,oBACPL,EAAOM,iBACPN,EAAOO,uBAINC,OAAOd,GACPe,IAAKC,GAAcA,EAAUT,IAC7BU,KAAKjB,IAKJkB,EAAejB,IACnB,IACE,OAAOkB,KAAKC,MAAMD,KAAKE,UAAUpB,GAClC,CAAC,MACA,MAAO,IAAKA,EACb,GAIGqB,EAA4B,IAAIC,IAChCC,EAA4B,IAAID,IAEzBE,EAAyC,KACpDH,EAA0BI,QAC1BF,EAA0BE,SAGfC,EAAuB,EAClCC,kBACAC,WACAC,eACAC,gBACAC,aAGA,MAAMC,EAAqBC,EAAoC,IAAIX,KAC7DY,EAAwBD,EAA4BZ,GACpDc,EAA6BF,EACjCV,GAIIa,EAAcC,EAAgC,IAC1CV,GAA8C,CAAA,EACrD,CAACA,IAEEW,EAAiBP,GA1EgB,MACvC,GAAsB,oBAAXQ,OAEX,IACE,MAAMC,EAAS,IAAIC,gBAAgBF,OAAOG,SAASC,QAAU,IAC7D,OACEH,EAAOI,IAAIC,EAAUC,2BACrBN,EAAOI,IAAIC,EAAUE,gCACrBC,CAEH,CAAC,MACA,MACD,GA8DgCC,GAG3BC,EAAoBC,EACxBC,MACEC,EACAC,EAAoC,CAAA,KAE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E/C0C,EAA4B7B,EAC/B8B,IACC,IAAK3C,EAAgB,OAErB,MAAM4C,EAAejE,EAAYgE,GAC3BE,EAAOjE,KAAKE,UAAU8D,GACxBhD,EAAsB2B,QAAQjB,IAAIN,KAAoB6C,IAC1DjD,EAAsB2B,QAAQK,IAAI5B,EAAgB6C,GAClDhD,EAA2B0B,QAAQK,IAAI5B,EAAgB4C,KAEzD,CAAC5C,IAGH8C,EAAU,KAIR,GAHuBL,EAAkBlB,UACCvB,EAKxC,OAFAyC,EAAkBlB,QAAUvB,OAC5BiC,EAAWc,MAAMP,GAIfP,EAAWe,UAAUC,SACzBhB,EAAWc,MAAMP,IAChB,CAACxC,EAAgBwC,EAAwBP,IAE5Ca,EAAU,KACR,IAAKb,GAAYiB,MAAO,OAExB,MAAMC,EAAiBlB,EAAWmB,eAAiB,CAAE,EACjDpD,GACF0C,EAA0BS,GAG5B,MAAME,EAAepB,EAAWiB,MAAOxF,IAEjCsC,GACF0C,EAFkBhF,GAAS,CAAA,KAM/B,MAAO,KACL2F,GAAcC,kBAEf,CAACrB,EAAYS,EAA2B1C,IAE3C,MAAMuD,EAAgBxD,EACpB,KAAO,CACLyD,YAAanE,EACbE,eACAC,gBAEAM,cACAc,oBACAqB,eAEF,CAAC5C,EAAiBE,EAAcC,EAAeM,EAAac,EAAmBqB,IAGjF,OAAOwB,EAACC,EAAaC,SAAQ,CAACjG,MAAO6F,EAAajE,SAAGA"}
@@ -1,2 +1,2 @@
1
- import{useCallback as e}from"react";import{useFormContext as t}from"../node_modules/react-hook-form/dist/index.esm.mjs.js";import{useContainerRuntime as n}from"../contexts/ContainerRuntimeContext/ContainerRuntimeContext.js";import"react/jsx-runtime";import"../node_modules/@emotion/react/dist/emotion-element-d59e098f.esm.js";import"../node_modules/stylis/dist/umd/stylis.js";import"../node_modules/@babel/runtime/helpers/extends.js";import"../node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js";import{useOrganismContext as o}from"../contexts/OrganismContext/useOrganismContext.js";import{useStateContext as s}from"../contexts/StateContext/useStateContext.js";import{useWebpageContextSafe as a}from"../contexts/WebpageContext/useWebpageContext.js";import{unwrapDataCaptureValue as r,unwrapDataCaptureValueForPresentation as l}from"./formDataCapture.js";const i=e=>{if(!e||0===e.length)return"";const t=[];return e.forEach(e=>{const n=e.sourceDataPointerId||e.dmfId;n&&(void 0!==e.index?t.push(`${n}.${e.index}`):t.push(n))}),t.filter(Boolean).join(".")},d=(e,t)=>"none"===t?e:"presentation"===t?l(e):r(e),u=({form:e,nestedPathSegments:t,fieldId:n,unwrapMode:o})=>{if(!e||!t?.length||!n)return;const s=(r=n,(a=t)&&0!==a.length?[...a.map(e=>{const t=e.sourceDataPointerId||e.dmfId;return void 0!==e.index?`${t}.${e.index}`:t}),r].filter(Boolean).join("."):r);var a,r;try{const t=e.getValues(s);if(null!=t&&""!==t){const e=d(t,o);if(null!=e&&""!==e)return{value:e,resolvedPath:s}}}catch{}const l=["id","value"];for(const i of l){const t=`${s}.${i}`;try{const n=e.getValues(t);if(null!=n&&""!==n){const e=d(n,o);if(null!=e&&""!==e)return{value:e,resolvedPath:t}}}catch{}}},f=(e,t,n)=>{if(!e||""===e.trim())return;const o=!1!==n?.unwrapDataCapture,s=!0===n?.forPresentation,a=e=>o?s?l(e):r(e):e,i=e.match(/^\{(\w+):(.+)\}$/),[d,u]=i?[i[1],i[2]]:[void 0,e],{containerContext:f,webpageContext:m,stateObject:g,form:p}=t;if(p)try{const e=p.getValues(u);if(null!=e&&""!==e)return a(e)}catch{}if(f?.rowData){const e=c(f.rowData,u);if(null!=e&&""!==e)return a(e)}if(m){if(u in m){const e=m[u];if(null!=e&&""!==e)return a(e)}if(m.queryResults){const e=m.queryResults[u];if(e&&e.data)return e.data}if(m.dynamicContext&&u in m.dynamicContext){const e=m.dynamicContext[u];if(null!=e&&""!==e)return a(e)}}if(g&&(!d||"stateObject"===d)){const e=c(g,u);if(null!=e&&""!==e)return a(e)}};function c(e,t){return t.split(".").reduce((e,t)=>{if(e&&"object"==typeof e)return e[t]},e)}function m(e,t,n){if(!e||!t)return;const o=t.split(".");if(0===o.length)return n in e?e[n]:e.queryResults&&e.queryResults[n]?e.queryResults[n]?.data:void 0;let s;for(let a=0;a<o.length;a+=2){const t=o[a],n=a+1<o.length?parseInt(o[a+1],10):void 0;if(!e.queryResults||!e.queryResults[t])return;{const o=e.queryResults[t];if(o?.data)if(void 0===n||isNaN(n))s=o.data;else{if(!(Array.isArray(o.data)&&n<o.data.length))return;s=o.data[n]}}}if(s&&"object"==typeof s&&!Array.isArray(s)){return s[n]}}const g=(e,t,n)=>{if(!e)return;const o=t.split(".").filter(Boolean);if(0===o.length)return m(e,"",n);for(let s=o.length-2;s>=0;s-=2){const t=m(e,o.slice(0,s).join("."),n);if(null!=t&&""!==t)return t}if(n in e){const t=e[n];if(null!=t&&""!==t)return t}if(e.queryResults)for(const s of Object.values(e.queryResults))if(s?.data&&"object"==typeof s.data&&!Array.isArray(s.data)){const e=s.data[n];if(null!=e&&""!==e)return e}if(e.dynamicContext&&n in e.dynamicContext){const t=e.dynamicContext[n];if(null!=t&&""!==t)return t}};function p(e,l){const d=t(),p=a();let h,v,y,D;try{h=s().stateObject}catch{h=void 0}try{v=o().prefillData}catch{v=void 0}try{D=n(),y=D?.itemDataByDmfId?{rowData:D.itemDataByDmfId,rowIndex:D.itemIndex}:void 0}catch(C){D=void 0}const P=l||(D?.nestedPathSegments?.length?i(D.nestedPathSegments):D?.sourceDataPointerId||""),x=(e=>{if("undefined"==typeof window)return!1;try{const t=window.localStorage.getItem("zeal-ui:debug:useResolveData");if(!t)return!1;const n=t.trim();return!!n&&("*"===n||"1"===n||"true"===n.toLowerCase()||n.split(",").map(e=>e.trim()).filter(Boolean).includes(e))}catch{return!1}})(e);x&&console.log("🔍 [useResolveData] Diagnostic:",{fieldId:e,nestedPath:l,nestedPathFromContext:P,hasContainerContext:!!y,containerRowDataKeys:y?.rowData?Object.keys(y.rowData):[],containerRowDataSample:y?.rowData?JSON.stringify(y.rowData).substring(0,200):void 0,hasWebpageContext:!!p,webpageContextKeys:p?Object.keys(p).filter(e=>"queryResults"!==e&&"dynamicContext"!==e):[],webpageQueryResultsKeys:p?.queryResults?Object.keys(p.queryResults):[],hasStateObject:!!h,stateObjectKeys:h?Object.keys(h):[],hasPrefillData:!!v,prefillDataKeys:v?Object.keys(v):[],prefillDataSample:v?JSON.stringify(v).substring(0,500):void 0,hasForm:!!d,nestedPathSegments:D?.nestedPathSegments});const I=u({form:d,nestedPathSegments:D?.nestedPathSegments,fieldId:e,unwrapMode:"data"});if(I)return x&&console.log("✅ [useResolveData] Found via scoped nested form path:",{fieldId:e,resolvedPath:I.resolvedPath,value:I.value}),I.value;if(P&&p){const t=m(p,P,e);if(null!=t&&""!==t)return x&&console.log("✅ [useResolveData] Found via nested path (replicator level):",{fieldId:e,nestedPath:P,nestedValue:t}),r(t);""===t&&x&&console.log("⚠️ [useResolveData] Found empty string via nested path, treating as undefined:",{fieldId:e,nestedPath:P});const n=g(p,P,e);if(null!=n&&""!==n)return x&&console.log("✅ [useResolveData] Found via parent scope (webpage level):",{fieldId:e,nestedPath:P,parentScopeValue:n}),r(n)}const w=f(e,{containerContext:y,webpageContext:p,stateObject:h,form:D?.nestedPathSegments?.length?void 0:d},{unwrapDataCapture:!0});if(null!=w&&""!==w)return x&&console.log("✅ [useResolveData] Found via standard resolution:",{fieldId:e,resolved:w,resolvedType:typeof w}),w;if(""===w&&x&&console.log("⚠️ [useResolveData] Found empty string, treating as undefined:",{fieldId:e}),v){const t=P||void 0;if(x&&console.log("🔍 [useResolveData] Checking prefill data:",{fieldId:e,nestedPath:l,nestedPathFromContext:P,effectiveNestedPath:t,nestedPathSegments:D?.nestedPathSegments,prefillDataKeys:Object.keys(v),prefillDataSample:JSON.stringify(v).substring(0,500)}),t){const n=`${t}.${e}`,o=c(v,n);if(x&&console.log("🔍 [useResolveData] Nested prefill check:",{fieldId:e,nestedPrefillPath:n,nestedPrefill:o,nestedPrefillType:typeof o}),null!=o&&""!==o)return x&&console.log("✅ [useResolveData] Found via nested prefill:",{fieldId:e,effectiveNestedPath:t,nestedPrefill:o}),r(o);""===o&&x&&console.log("⚠️ [useResolveData] Found empty string via nested prefill, treating as undefined:",{fieldId:e,effectiveNestedPath:t});const s=["id","value"];for(const a of s){const n=`${t}.${e}.${a}`,o=c(v,n);if(x&&console.log(`🔍 [useResolveData] Nested prefill check (${a}):`,{fieldId:e,suffixedPrefillPath:n,suffixedPrefill:o,suffixedPrefillType:typeof o}),null!=o&&""!==o)return x&&console.log(`✅ [useResolveData] Found via nested prefill (${a}):`,{fieldId:e,suffixedPrefillPath:n,suffixedPrefill:o}),r(o)}}const n=c(v,e);if(x&&console.log("🔍 [useResolveData] Flat prefill check:",{fieldId:e,flatPrefill:n,flatPrefillType:typeof n}),null!=n&&""!==n)return x&&console.log("✅ [useResolveData] Found via flat prefill:",{fieldId:e,flatPrefill:n}),r(n);""===n&&x&&console.log("⚠️ [useResolveData] Found empty string via flat prefill, treating as undefined:",{fieldId:e})}else x&&console.log("⚠️ [useResolveData] No prefillData available:",{fieldId:e});x&&console.log("❌ [useResolveData] No value found:",{fieldId:e,nestedPath:l,nestedPathFromContext:P})}function h(e){const o=t(),r=a();let d,c,m;try{d=s().stateObject}catch{d=void 0}try{const e=n();m=e,c=e?.itemDataByDmfId?{rowData:e.itemDataByDmfId,rowIndex:e.itemIndex}:void 0}catch{c=void 0,m=void 0}const p=u({form:o,nestedPathSegments:m?.nestedPathSegments,fieldId:e,unwrapMode:"presentation"});if(p)return p.value;const h=f(e,{containerContext:c,webpageContext:r,stateObject:d,form:m?.nestedPathSegments?.length?void 0:o},{unwrapDataCapture:!0,forPresentation:!0});if((null==h||""===h)&&m?.nestedPathSegments?.length&&r){const t=i(m.nestedPathSegments),n=g(r,t,e);if(null!=n&&""!==n)return l(n)}return h}function v(){const o=t(),r=a();let l,d,g;try{l=s().stateObject}catch{l=void 0}try{g=n();const e=g?.rawItemDataByDmfId||g?.itemDataByDmfId;d=e?{rowData:e,rowIndex:g.itemIndex}:void 0}catch{d=void 0,g=void 0}const p=g?.nestedPathSegments?.length?i(g.nestedPathSegments):g?.sourceDataPointerId||"";return e(e=>{const t=e.match(/^\{(\w+):(.+)\}$/),n=t?t[1]:void 0,s=t?t[2]:e;if(!n){const e=u({form:o,nestedPathSegments:g?.nestedPathSegments,fieldId:s,unwrapMode:"none"});if(e)return e.value}if(!Boolean(g?.nestedPathSegments?.length)&&o)try{const e=o.getValues(s);if(null!=e&&""!==e)return e}catch{}if(d?.rowData){const e=c(d.rowData,s);if(null!=e&&""!==e)return e}if(!n&&p&&r){const e=m(r,p,s);if(null!=e&&""!==e)return e}return f(e,{containerContext:d,webpageContext:r,stateObject:l,form:g?.nestedPathSegments?.length?void 0:o},{unwrapDataCapture:!1})},[d,r,l,o,g?.nestedPathSegments,g?.sourceDataPointerId,p])}export{m as resolveValueFromNestedPath,p as useResolveData,h as useResolveDataForPresentation,v as useResolveDataResolverRaw};
1
+ import{useCallback as e}from"react";import{useFormContext as t}from"../node_modules/react-hook-form/dist/index.esm.mjs.js";import{useContainerRuntime as n}from"../contexts/ContainerRuntimeContext/ContainerRuntimeContext.js";import"react/jsx-runtime";import"../node_modules/@emotion/react/dist/emotion-element-d59e098f.esm.js";import"../node_modules/stylis/dist/umd/stylis.js";import"../node_modules/@babel/runtime/helpers/extends.js";import"../node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js";import{useOrganismContext as o}from"../contexts/OrganismContext/useOrganismContext.js";import{useStateContext as a}from"../contexts/StateContext/useStateContext.js";import{useWebpageContextSafe as s}from"../contexts/WebpageContext/useWebpageContext.js";import{unwrapDataCaptureValue as r,unwrapDataCaptureValueForPresentation as l}from"./formDataCapture.js";const i=e=>{if(!e||0===e.length)return"";const t=[];return e.forEach(e=>{const n=e.sourceDataPointerId||e.dmfId;n&&(void 0!==e.index?t.push(`${n}.${e.index}`):t.push(n))}),t.filter(Boolean).join(".")},d=(e,t)=>"none"===t?e:"presentation"===t?l(e):r(e),u=({form:e,nestedPathSegments:t,fieldId:n,unwrapMode:o})=>{if(!e||!t?.length||!n)return;const a=(r=n,(s=t)&&0!==s.length?[...s.map(e=>{const t=e.sourceDataPointerId||e.dmfId;return void 0!==e.index?`${t}.${e.index}`:t}),r].filter(Boolean).join("."):r);var s,r;try{const t=e.getValues(a);if(null!=t&&""!==t){const e=d(t,o);if(null!=e&&""!==e)return{value:e,resolvedPath:a}}}catch{}const l=["id","value"];for(const i of l){const t=`${a}.${i}`;try{const n=e.getValues(t);if(null!=n&&""!==n){const e=d(n,o);if(null!=e&&""!==e)return{value:e,resolvedPath:t}}}catch{}}},f=(e,t,n)=>{if(!e||""===e.trim())return;const o=!1!==n?.unwrapDataCapture,a=!0===n?.forPresentation,s=e=>o?a?l(e):r(e):e,i=e.match(/^\{(\w+):(.+)\}$/),[d,u]=i?[i[1],i[2]]:[void 0,e],{containerContext:f,webpageContext:c,stateObject:p,form:g}=t;if(g)try{const e=g.getValues(u);if(null!=e&&""!==e)return s(e)}catch{}if(f?.rowData){const e=m(f.rowData,u);if(null!=e&&""!==e)return s(e)}if(c){if(u in c){const e=c[u];if(null!=e&&""!==e)return s(e)}if(c.queryResults){const e=c.queryResults[u];if(e&&e.data)return e.data}if(c.dynamicContext&&u in c.dynamicContext){const e=c.dynamicContext[u];if(null!=e&&""!==e)return s(e)}}if(p&&(!d||"stateObject"===d)){const e=m(p,u);if(null!=e&&""!==e)return s(e)}},c=(e,t)=>!!t&&t.split(".").every(t=>!(!e||"object"!=typeof e)&&(!!Object.prototype.hasOwnProperty.call(e,t)&&(e=e[t],!0)));function m(e,t){return t.split(".").reduce((e,t)=>{if(e&&"object"==typeof e)return e[t]},e)}function p(e,t,n){if(!e||!t)return;const o=t.split(".");if(0===o.length)return n in e?e[n]:e.queryResults&&e.queryResults[n]?e.queryResults[n]?.data:void 0;let a;for(let s=0;s<o.length;s+=2){const t=o[s],n=s+1<o.length?parseInt(o[s+1],10):void 0;if(!e.queryResults||!e.queryResults[t])return;{const o=e.queryResults[t];if(o?.data)if(void 0===n||isNaN(n))a=o.data;else{if(!(Array.isArray(o.data)&&n<o.data.length))return;a=o.data[n]}}}if(a&&"object"==typeof a&&!Array.isArray(a)){return a[n]}}const g=(e,t,n)=>{if(!e)return;const o=t.split(".").filter(Boolean);if(0===o.length)return p(e,"",n);for(let a=o.length-2;a>=0;a-=2){const t=p(e,o.slice(0,a).join("."),n);if(null!=t&&""!==t)return t}if(n in e){const t=e[n];if(null!=t&&""!==t)return t}if(e.queryResults)for(const a of Object.values(e.queryResults))if(a?.data&&"object"==typeof a.data&&!Array.isArray(a.data)){const e=a.data[n];if(null!=e&&""!==e)return e}if(e.dynamicContext&&n in e.dynamicContext){const t=e.dynamicContext[n];if(null!=t&&""!==t)return t}};function h(e,l){const d=t(),h=s();let v,y,D,P;try{v=a().stateObject}catch{v=void 0}try{y=o().prefillData}catch{y=void 0}try{P=n(),D=P?.itemDataByDmfId?{rowData:P.itemDataByDmfId,rowIndex:P.itemIndex}:void 0}catch(C){P=void 0}const x=l||(P?.nestedPathSegments?.length?i(P.nestedPathSegments):P?.sourceDataPointerId||""),w=(e=>{if("undefined"==typeof window)return!1;try{const t=window.localStorage.getItem("zeal-ui:debug:useResolveData");if(!t)return!1;const n=t.trim();return!!n&&("*"===n||"1"===n||"true"===n.toLowerCase()||n.split(",").map(e=>e.trim()).filter(Boolean).includes(e))}catch{return!1}})(e);w&&console.log("🔍 [useResolveData] Diagnostic:",{fieldId:e,nestedPath:l,nestedPathFromContext:x,hasContainerContext:!!D,containerRowDataKeys:D?.rowData?Object.keys(D.rowData):[],containerRowDataSample:D?.rowData?JSON.stringify(D.rowData).substring(0,200):void 0,hasWebpageContext:!!h,webpageContextKeys:h?Object.keys(h).filter(e=>"queryResults"!==e&&"dynamicContext"!==e):[],webpageQueryResultsKeys:h?.queryResults?Object.keys(h.queryResults):[],hasStateObject:!!v,stateObjectKeys:v?Object.keys(v):[],hasPrefillData:!!y,prefillDataKeys:y?Object.keys(y):[],prefillDataSample:y?JSON.stringify(y).substring(0,500):void 0,hasForm:!!d,nestedPathSegments:P?.nestedPathSegments});const I=u({form:d,nestedPathSegments:P?.nestedPathSegments,fieldId:e,unwrapMode:"data"});if(I)return w&&console.log("✅ [useResolveData] Found via scoped nested form path:",{fieldId:e,resolvedPath:I.resolvedPath,value:I.value}),I.value;if(Boolean(P?.nestedPathSegments?.length)&&D?.rowData&&c(D.rowData,e)){const t=m(D.rowData,e);return null!=t&&""!==t?(w&&console.log("✅ [useResolveData] Found via scoped container row path:",{fieldId:e,value:t}),r(t)):void(w&&console.log("⚠️ [useResolveData] Scoped container path exists but value is empty; skipping webpage fallback:",{fieldId:e}))}if(x&&h){const t=p(h,x,e);if(null!=t&&""!==t)return w&&console.log("✅ [useResolveData] Found via nested path (replicator level):",{fieldId:e,nestedPath:x,nestedValue:t}),r(t);""===t&&w&&console.log("⚠️ [useResolveData] Found empty string via nested path, treating as undefined:",{fieldId:e,nestedPath:x});const n=g(h,x,e);if(null!=n&&""!==n)return w&&console.log("✅ [useResolveData] Found via parent scope (webpage level):",{fieldId:e,nestedPath:x,parentScopeValue:n}),r(n)}const b=f(e,{containerContext:D,webpageContext:h,stateObject:v,form:P?.nestedPathSegments?.length?void 0:d},{unwrapDataCapture:!0});if(null!=b&&""!==b)return w&&console.log("✅ [useResolveData] Found via standard resolution:",{fieldId:e,resolved:b,resolvedType:typeof b}),b;if(""===b&&w&&console.log("⚠️ [useResolveData] Found empty string, treating as undefined:",{fieldId:e}),y){const t=x||void 0;if(w&&console.log("🔍 [useResolveData] Checking prefill data:",{fieldId:e,nestedPath:l,nestedPathFromContext:x,effectiveNestedPath:t,nestedPathSegments:P?.nestedPathSegments,prefillDataKeys:Object.keys(y),prefillDataSample:JSON.stringify(y).substring(0,500)}),t){const n=`${t}.${e}`,o=m(y,n);if(w&&console.log("🔍 [useResolveData] Nested prefill check:",{fieldId:e,nestedPrefillPath:n,nestedPrefill:o,nestedPrefillType:typeof o}),null!=o&&""!==o)return w&&console.log("✅ [useResolveData] Found via nested prefill:",{fieldId:e,effectiveNestedPath:t,nestedPrefill:o}),r(o);""===o&&w&&console.log("⚠️ [useResolveData] Found empty string via nested prefill, treating as undefined:",{fieldId:e,effectiveNestedPath:t});const a=["id","value"];for(const s of a){const n=`${t}.${e}.${s}`,o=m(y,n);if(w&&console.log(`🔍 [useResolveData] Nested prefill check (${s}):`,{fieldId:e,suffixedPrefillPath:n,suffixedPrefill:o,suffixedPrefillType:typeof o}),null!=o&&""!==o)return w&&console.log(`✅ [useResolveData] Found via nested prefill (${s}):`,{fieldId:e,suffixedPrefillPath:n,suffixedPrefill:o}),r(o)}}const n=m(y,e);if(w&&console.log("🔍 [useResolveData] Flat prefill check:",{fieldId:e,flatPrefill:n,flatPrefillType:typeof n}),null!=n&&""!==n)return w&&console.log("✅ [useResolveData] Found via flat prefill:",{fieldId:e,flatPrefill:n}),r(n);""===n&&w&&console.log("⚠️ [useResolveData] Found empty string via flat prefill, treating as undefined:",{fieldId:e})}else w&&console.log("⚠️ [useResolveData] No prefillData available:",{fieldId:e});w&&console.log("❌ [useResolveData] No value found:",{fieldId:e,nestedPath:l,nestedPathFromContext:x})}function v(e){const o=t(),r=s();let d,p,h;try{d=a().stateObject}catch{d=void 0}try{const e=n();h=e,p=e?.itemDataByDmfId?{rowData:e.itemDataByDmfId,rowIndex:e.itemIndex}:void 0}catch{p=void 0,h=void 0}const v=u({form:o,nestedPathSegments:h?.nestedPathSegments,fieldId:e,unwrapMode:"presentation"});if(v)return v.value;if(Boolean(h?.nestedPathSegments?.length)&&p?.rowData&&c(p.rowData,e)){const t=m(p.rowData,e);return null!=t&&""!==t?l(t):void 0}const y=f(e,{containerContext:p,webpageContext:r,stateObject:d,form:h?.nestedPathSegments?.length?void 0:o},{unwrapDataCapture:!0,forPresentation:!0});if((null==y||""===y)&&h?.nestedPathSegments?.length&&r){const t=i(h.nestedPathSegments),n=g(r,t,e);if(null!=n&&""!==n)return l(n)}return y}function y(){const o=t(),r=s();let l,d,g;try{l=a().stateObject}catch{l=void 0}try{g=n();const e=g?.rawItemDataByDmfId||g?.itemDataByDmfId;d=e?{rowData:e,rowIndex:g.itemIndex}:void 0}catch{d=void 0,g=void 0}const h=g?.nestedPathSegments?.length?i(g.nestedPathSegments):g?.sourceDataPointerId||"";return e(e=>{const t=e.match(/^\{(\w+):(.+)\}$/),n=t?t[1]:void 0,a=t?t[2]:e;if(!n){const e=u({form:o,nestedPathSegments:g?.nestedPathSegments,fieldId:a,unwrapMode:"none"});if(e)return e.value}const s=Boolean(g?.nestedPathSegments?.length);if(!n&&s&&d?.rowData&&c(d.rowData,a)){const e=m(d.rowData,a);return null!=e&&""!==e?e:void 0}if(!s&&o)try{const e=o.getValues(a);if(null!=e&&""!==e)return e}catch{}if(d?.rowData){const e=m(d.rowData,a);if(null!=e&&""!==e)return e}if(!n&&h&&r){const e=p(r,h,a);if(null!=e&&""!==e)return e}return f(e,{containerContext:d,webpageContext:r,stateObject:l,form:g?.nestedPathSegments?.length?void 0:o},{unwrapDataCapture:!1})},[d,r,l,o,g?.nestedPathSegments,g?.sourceDataPointerId,h])}export{p as resolveValueFromNestedPath,h as useResolveData,v as useResolveDataForPresentation,y as useResolveDataResolverRaw};
2
2
  //# sourceMappingURL=useDataResolution.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDataResolution.js","sources":["../../../../src/helpers/useDataResolution.ts"],"sourcesContent":[null],"names":["buildNestedPathString","segments","length","pathParts","forEach","seg","pathId","sourceDataPointerId","dmfId","undefined","index","push","filter","Boolean","join","normalizeScopedFormValue","value","unwrapMode","unwrapDataCaptureValueForPresentation","unwrapDataCaptureValue","resolveScopedFormValue","form","nestedPathSegments","fieldId","baseNestedFormPath","fieldName","map","nestedFormValue","getValues","normalized","resolvedPath","suffixes","suffix","suffixedPath","suffixedValue","resolveValueFromSources","reference","sources","options","trim","shouldUnwrap","unwrapDataCapture","forPresentation","normalizeValue","match","source","path","containerContext","webpageContext","stateObject","formValue","rowData","getNestedValue","queryResults","queryResult","data","dynamicContext","obj","split","reduce","acc","segment","resolveValueFromNestedPath","nestedPath","currentData","i","parseInt","isNaN","Array","isArray","resolveValueFromParentScopes","len","slice","Object","values","fieldValue","useResolveData","useFormContext","useWebpageContextSafe","prefillData","containerRuntime","useStateContext","useOrganismContext","useContainerRuntime","itemDataByDmfId","rowIndex","itemIndex","error","nestedPathFromContext","shouldLog","window","rawDebugSetting","localStorage","getItem","debugSetting","toLowerCase","item","includes","isResolveDataLoggingEnabled","console","log","hasContainerContext","containerRowDataKeys","keys","containerRowDataSample","JSON","stringify","substring","hasWebpageContext","webpageContextKeys","k","webpageQueryResultsKeys","hasStateObject","stateObjectKeys","hasPrefillData","prefillDataKeys","prefillDataSample","hasForm","scopedFormResolution","nestedValue","parentScopeValue","resolved","resolvedType","effectiveNestedPath","nestedPrefillPath","nestedPrefill","nestedPrefillType","suffixedPrefillPath","suffixedPrefill","suffixedPrefillType","flatPrefill","flatPrefillType","useResolveDataForPresentation","runtime","useResolveDataResolverRaw","rawItemDataByDmfId","useCallback","scopedValue"],"mappings":"42BA+CA,MAAMA,EAAyBC,IAC7B,IAAKA,GAAgC,IAApBA,EAASC,OACxB,MAAO,GAGT,MAAMC,EAAsB,GAW5B,OAVAF,EAASG,QAASC,IAChB,MAAMC,EAASD,EAAIE,qBAAuBF,EAAIG,MACzCF,SACaG,IAAdJ,EAAIK,MACNP,EAAUQ,KAAK,GAAGL,KAAUD,EAAIK,SAEhCP,EAAUQ,KAAKL,MAIZH,EAAUS,OAAOC,SAASC,KAAK,MAmBlCC,EAA2B,CAACC,EAAgBC,IAC7B,SAAfA,EAA8BD,EACZ,iBAAfC,EACHC,EAAsCF,GACtCG,EAAuBH,GAGvBI,EAAyB,EAC7BC,OACAC,qBACAC,UACAN,iBAOA,IAAKI,IAASC,GAAoBpB,SAAWqB,EAAS,OAEtD,MAAMC,GApC2DC,EAoCGF,GApCxCtB,EAoCoBqB,IAn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GAAkB1D,mBAClB0D,GAAkBzE,oBAClBiF,GAGN"}
1
+ {"version":3,"file":"useDataResolution.js","sources":["../../../../src/helpers/useDataResolution.ts"],"sourcesContent":[null],"names":["buildNestedPathString","segments","length","pathParts","forEach","seg","pathId","sourceDataPointerId","dmfId","undefined","index","push","filter","Boolean","join","normalizeScopedFormValue","value","unwrapMode","unwrapDataCaptureValueForPresentation","unwrapDataCaptureValue","resolveScopedFormValue","form","nestedPathSegments","fieldId","baseNestedFormPath","fieldName","map","nestedFormValue","getValues","normalized","resolvedPath","suffixes","suffix","suffixedPath","suffixedValue","resolveValueFromSources","reference","sources","options","trim","shouldUnwrap","unwrapDataCapture","forPresentation","normalizeValue","match","source","path","containerContext","webpageContext","stateObject","formValue","rowData","getNestedValue","queryResults","queryResult","data","dynamicContext","hasNestedPath","obj","split","every","segment","Object","prototype","hasOwnProperty","call","reduce","acc","resolveValueFromNestedPath","nestedPath","currentData","i","parseInt","isNaN","Array","isArray","resolveValueFromParentScopes","len","slice","values","fieldValue","useResolveData","useFormContext","useWebpageContextSafe","prefillData","containerRuntime","useStateContext","useOrganismContext","useContainerRuntime","itemDataByDmfId","rowIndex","itemIndex","error","nestedPathFromContext","shouldLog","window","rawDebugSetting","localStorage","getItem","debugSetting","toLowerCase","item","includes","isResolveDataLoggingEnabled","console","log","hasContainerContext","containerRowDataKeys","keys","containerRowDataSample","JSON","stringify","substring","hasWebpageContext","webpageContextKeys","k","webpageQueryResultsKeys","hasStateObject","stateObjectKeys","hasPrefillData","prefillDataKeys","prefillDataSample","hasForm","scopedFormResolution","scopedContainerValue","nestedValue","parentScopeValue","resolved","resolvedType","effectiveNestedPath","nestedPrefillPath","nestedPrefill","nestedPrefillType","suffixedPrefillPath","suffixedPrefill","suffixedPrefillType","flatPrefill","flatPrefillType","useResolveDataForPresentation","runtime","useResolveDataResolverRaw","rawItemDataByDmfId","useCallback","hasNestedContainerScope","scopedValue"],"mappings":"42BA+CA,MAAMA,EAAyBC,IAC7B,IA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5B,KAAMgE,GAAkB/D,oBAAoBpB,YAASO,EAAYY,GAEnE,CAAEoB,mBAAmB,KAGzB,CACEM,EACAC,EACAC,EACA5B,EACAgE,GAAkB/D,mBAClB+D,GAAkB9E,oBAClBsF,GAGN"}
@@ -1,2 +1,2 @@
1
- import"../contexts/AccountButtonContext/AccountButtonContext.js";import"react/jsx-runtime";import"../node_modules/@emotion/react/dist/emotion-element-d59e098f.esm.js";import"react";import"../node_modules/stylis/dist/umd/stylis.js";import"../node_modules/@babel/runtime/helpers/extends.js";import"../node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js";import"../contexts/ApiContext/ApiContext.js";import"../contexts/ContainerRuntimeContext/ContainerRuntimeContext.js";import"../contexts/FormStepContext/FormStepContext.js";import"../contexts/LayoutContext/LayoutContext.js";import"../theme/theme.js";import"../theme/provider.js";import"../theme/toastStyles.js";import"../contexts/MlrRichTextViewerContext/MlrRichTextViewerContext.js";import"../contexts/OrganismContext/OrganismContext.js";import"../contexts/PopupContext/PopupContext.js";import"../contexts/ReplicatorFormContext/ReplicatorFormContext.js";import"../contexts/ReplicatorRegistryContext/ReplicatorRegistryContext.js";import"../contexts/StateContext/StateContext.js";import{paramKeys as e}from"../constants/params.js";import{decodeBase64UrlToObject as t}from"./rwoContext.js";export{encodeObjectToBase64Url,getByPath}from"./rwoContext.js";import"../contexts/WebpageContext/WebpageContext.js";import"../molecules/Button/Button.js";import"@tanstack/react-query";import{urlPattern as n}from"./validations.js";import"../node_modules/@emotion/react/dist/emotion-react.esm.js";import"../components/Buttons/TextButton.js";import"../components/Buttons/TouchableOpacity.js";import"../components/Circle/Circle.js";import"../components/CircularIndicator/CircularIndicator.js";import"../components/ContentWrapper/ContentWrapper.js";import"../components/CustomValidation/CustomValidation.js";import"../components/HorizontalButtons/HorizontalButtons.js";import"../components/Input/Input.js";import"../components/Paddings/Paddings.js";import"../components/PdfDocument/PdfDocument.js";import"../components/RadioButtons/RadioButtons.js";import"../components/RegularImage/RegularImage.js";import{richTextDefaultValue as r}from"../components/RichTextViewer/RichTextViewer.js";import"../node_modules/slate/dist/index.es.js";import"../components/TextWrapper/TextWrapper.js";import"../components/Select/styles.js";import"../components/Spacer/Spacer.js";import"../components/Spinner/Spinner.js";import{toast as o}from"../components/Toast/toast.js";import"../components/Tooltip/Tooltip.js";import"../components/ValidationTag/ValidationTag.js";import"../components/ZealUIModal/ZealUIModal.js";const i=e=>{if(n.test(e)){window.open(e,"_blank","noopener,noreferrer")&&setTimeout(()=>{window.blur()},100)}},a=(e,t)=>{if(!t||"string"!=typeof t)return"";const n=t.match(new RegExp(`[?&]${e}=([^&]*)`));return n?decodeURIComponent(n[1]):""},l=e=>{const n=e||window.location.href,r=a("rwoContext",n);if(r)try{const e=t(r);if(e){const t=[];return Object.entries(e).forEach(([e,n])=>{n&&"object"==typeof n&&"rwoRecordId"in n&&n.rwoRecordId&&t.push({organismId:e,recordId:n.rwoRecordId})}),t}}catch(i){}const o=a("rwoTargets",n);if(!o)return[];try{return o.split(",").map(e=>{const[t,n]=e.split(":");return{organismId:t,recordId:n}}).filter(e=>e.organismId&&e.recordId)}catch(i){return[]}},s=(e,n,r)=>{const o=n||window.location.href,i=a("rwoContext",o);if(i)try{const n=t(i);if(!n)return;if(r){const t=n[r];if(!t)return c(n,e,r);const o=t[e];return o?.rwoRecordId?o.rwoRecordId:void 0}return c(n,e,void 0)}catch(l){return}},c=(e,t,n)=>{const r=e.selectedWebpageId;if(r&&n&&r!==n)return;const o=e[t];return o?.rwoRecordId?o.rwoRecordId:void 0},d=(t,n,r=!1)=>{if(!n)return t;const o=a(e.internalLinkWebpageId,n),i=a(e.internalLinkApplicationId,n);if(!o||!i)return t;const l=new URLSearchParams(t.toString());return r?(t.has(e.previewApplicationId)&&l.set(e.previewApplicationId,i),t.has(e.previewSelectedWebpageId)&&l.set(e.previewSelectedWebpageId,o)):(t.has(e.runtimeSelectedWebpageId)&&l.set(e.runtimeSelectedWebpageId,o),l.set(e.runtimeSelectedWebpageId,o)),l},p=async(e="",t="Downloaded file")=>{try{const n=await fetch(e),r=await n.blob(),o=URL.createObjectURL(r),i=document.createElement("a");i.href=o,i.download=t,i.click(),URL.revokeObjectURL(o)}catch(n){o({message:`Failed to download the file: ${n}`,type:"error"})}},u=e=>{if(!e)return;if("object"==typeof e&&"type"in e){const t=e;if(x(t))return;return f(t.externalLink)}return f(e)},m=(e,t)=>{if(e){if("object"==typeof e&&"type"in e){const n=e;if(g(n))return;return x(n)?void(t&&n.internalLink?t({link:n.internalLink}):n.internalLink&&(window.location.href=n.internalLink)):u(n.externalLink)}return u(e)}},f=e=>{if(!e||"string"!=typeof e)return;if(n.test(e))try{const t=window.open(e,"_blank","noopener,noreferrer");if(t){[20,120,300,600].forEach(e=>{setTimeout(()=>{try{t.blur()}catch(e){}try{window.focus()}catch(e){}},e)})}}catch(t){}else try{console.error("navigateToExternalLink: invalid external URL",{url:e})}catch(t){}},x=e=>{if(!e)return!1;const t=e?.type||e?.linkType;return"internal_link"===t||"internalLink"===t},g=e=>!!e&&("data_driven_link"===e.type||"dataDrivenLink"===e.type),I=e=>/^https?:\/\//i.test(e),w=(e,t)=>{if(!g(e))return null;if(!e.internalLinkFieldId&&!e.externalLinkFieldId)return null;let r=null;if(e.dataDrivenLinkType){const n=t?.[e.dataDrivenLinkType];null!=n&&(r=(e=>{if(null==e)return null;if("object"==typeof e&&null!==e){const t=e;if("code"in t&&"string"==typeof t.code){const e=t.code.toLowerCase();if("internal"===e||"internal_link"===e)return"internal";if("external"===e||"external_link"===e)return"external"}if("label"in t&&"string"==typeof t.label){const e=t.label.toLowerCase();if("internal"===e||"internal link"===e)return"internal";if("external"===e||"external link"===e)return"external"}if("value"in t&&"string"==typeof t.value){const e=t.value.toLowerCase();if("internal"===e||"internal_link"===e||"internal link"===e)return"internal";if("external"===e||"external_link"===e||"external link"===e)return"external"}}if("string"==typeof e){const t=e.toLowerCase();if("internal"===t||"internal_link"===t||"internal link"===t)return"internal";if("external"===t||"external_link"===t||"external link"===t)return"external"}return null})(n),r||e.dataDrivenLinkType)}if(!r){const t=!!e.internalLinkFieldId,n=!!e.externalLinkFieldId;if(n&&!t)r="external";else{if(!t||n)return null;r="internal"}}if("internal"===r){if(!e.internalLinkFieldId)return null;const n=t?.[e.internalLinkFieldId],r=(e=>{if(null!=e){if("object"==typeof e&&null!==e){const t=e;if("id"in t&&("string"==typeof t.id||"number"==typeof t.id))return String(t.id)}return"string"==typeof e?e:void 0}})(n);if(!r)return e.internalLinkFieldId,null;const o=e.rwoRecordIdFieldId?(e=>{if(null!=e){if("object"==typeof e&&null!==e){const t=e;if("id"in t&&("string"==typeof t.id||"number"==typeof t.id))return String(t.id);if("value"in t&&("string"==typeof t.value||"number"==typeof t.value))return String(t.value)}return"string"==typeof e?e:"number"==typeof e?String(e):void 0}})(t?.[e.rwoRecordIdFieldId]):void 0;return{destination:`?internalTaskTagId=${encodeURIComponent(r)}`,isExternal:!1,recordId:o,webpageAlias:r}}if("external"===r){if(!e.externalLinkFieldId)return null;const r=t?.[e.externalLinkFieldId],o=(e=>{if(null!=e){if("object"==typeof e&&null!==e){const t=e;if("value"in t&&("string"==typeof t.value||"number"==typeof t.value))return String(t.value)}return"string"==typeof e?e:void 0}})(r);return o?n.test(o)?{destination:o,isExternal:!0,recordId:void 0,webpageAlias:void 0}:(console.error("Data-driven link: invalid external URL",{externalLinkFieldId:e.externalLinkFieldId,url:o}),null):(console.error("Data-driven link: could not extract URL from externalLinkFieldId",{externalLinkFieldId:e.externalLinkFieldId,rawValue:r}),null)}return null},j=(e,t)=>{if(!e)return;const n=new URL(window.location.href),r=d(n.searchParams,e,t);return n.search=r.toString(),n.toString()},y=(e,t)=>{if(e)return x(e)?j(e?.internalLink,t):e?.externalLink},k=e=>{const t=e?.replace(/\\/g,"");try{return JSON.parse(e)}catch(n){try{return JSON.parse(t)}catch(o){return r}}},h=e=>{if(!e)return null;try{const t=e.startsWith("http")?e:new URL(e,window.location.origin).toString();return new URL(t)}catch(t){return null}},L=(e,t)=>{const n=h(e);if(!n)return;return n.searchParams.get(t)??void 0},b=t=>{if(!t)return;const n=h(t);if(n){const t=n.searchParams,r=t.get(e.internalLinkWebpageId)||t.get(e.runtimeSelectedWebpageId)||t.get(e.previewSelectedWebpageId);if(r)return r;const o=(n.pathname||"").split("/").map(e=>e.trim()).filter(e=>e.length>0);for(const n of o){const[t,r]=n.split("=");if(t&&null!=r&&(t===e.internalLinkWebpageId||t===e.runtimeSelectedWebpageId||t===e.previewSelectedWebpageId))return decodeURIComponent(r)}}const r=t.split("/").map(e=>e.trim()).filter(e=>e.length>0);for(const o of r){const[t,n]=o.split("=");if(t&&null!=n&&(t===e.internalLinkWebpageId||t===e.runtimeSelectedWebpageId||t===e.previewSelectedWebpageId))return decodeURIComponent(n)}},C=()=>{try{const t=new URLSearchParams(window.location.search||"");return t.get(e.runtimeSelectedWebpageId)||t.get(e.previewSelectedWebpageId)||void 0}catch(t){return}};export{j as addInternalParamsToCurrentLink,g as checkIsDataDrivenLink,x as checkIsInternalLink,p as downloadFile,y as getHref,L as getParamFromInternalLink,a as getParameterByName,s as getRwoRecordIdForOrganism,l as getRwoTargets,b as getSelectedWebpageIdFromInternalLink,C as getSelectedWebpageIdFromLocation,I as isExternalUrl,u as navigateToExternalLink,m as navigateToLink,k as parseDescendantContent,h as parseInternalLink,w as resolveDataDrivenLink,d as updateSearchParams,i as validateAndOpenUrl};
1
+ import"../contexts/AccountButtonContext/AccountButtonContext.js";import"react/jsx-runtime";import"../node_modules/@emotion/react/dist/emotion-element-d59e098f.esm.js";import"react";import"../node_modules/stylis/dist/umd/stylis.js";import"../node_modules/@babel/runtime/helpers/extends.js";import"../node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js";import"../contexts/ApiContext/ApiContext.js";import"../contexts/ContainerRuntimeContext/ContainerRuntimeContext.js";import"../contexts/FormStepContext/FormStepContext.js";import"../contexts/LayoutContext/LayoutContext.js";import"../theme/theme.js";import"../theme/provider.js";import"../theme/toastStyles.js";import"../contexts/MlrRichTextViewerContext/MlrRichTextViewerContext.js";import"../contexts/OrganismContext/OrganismContext.js";import"../contexts/PopupContext/PopupContext.js";import"../contexts/ReplicatorFormContext/ReplicatorFormContext.js";import"../contexts/ReplicatorRegistryContext/ReplicatorRegistryContext.js";import"../contexts/StateContext/StateContext.js";import{paramKeys as e}from"../constants/params.js";import"../contexts/WebpageContext/WebpageContext.js";import"../molecules/Button/Button.js";import"@tanstack/react-query";import{decodeBase64UrlToObject as t}from"./rwoContext.js";export{encodeObjectToBase64Url,getByPath}from"./rwoContext.js";import{urlPattern as n}from"./validations.js";import"../node_modules/@emotion/react/dist/emotion-react.esm.js";import"../components/Buttons/TextButton.js";import"../components/Buttons/TouchableOpacity.js";import"../components/Circle/Circle.js";import"../components/CircularIndicator/CircularIndicator.js";import"../components/ContentWrapper/ContentWrapper.js";import"../components/CustomValidation/CustomValidation.js";import"../components/HorizontalButtons/HorizontalButtons.js";import"../components/Input/Input.js";import"../components/Paddings/Paddings.js";import"../components/PdfDocument/PdfDocument.js";import"../components/RadioButtons/RadioButtons.js";import"../components/RegularImage/RegularImage.js";import{richTextDefaultValue as r}from"../components/RichTextViewer/RichTextViewer.js";import"../node_modules/slate/dist/index.es.js";import"../components/TextWrapper/TextWrapper.js";import"../components/Select/styles.js";import"../components/Spacer/Spacer.js";import"../components/Spinner/Spinner.js";import{toast as o}from"../components/Toast/toast.js";import"../components/Tooltip/Tooltip.js";import"../components/ValidationTag/ValidationTag.js";import"../components/ZealUIModal/ZealUIModal.js";const i=e=>{if(n.test(e)){window.open(e,"_blank","noopener,noreferrer")&&setTimeout(()=>{window.blur()},100)}},a=(e,t)=>{if(!t||"string"!=typeof t)return"";const n=t.match(new RegExp(`[?&]${e}=([^&]*)`));return n?decodeURIComponent(n[1]):""},l=e=>{const n=e||window.location.href,r=a("rwoContext",n);if(r)try{const e=t(r);if(e){const t=[];return Object.entries(e).forEach(([e,n])=>{n&&"object"==typeof n&&"rwoRecordId"in n&&n.rwoRecordId&&t.push({organismId:e,recordId:n.rwoRecordId})}),t}}catch(i){}const o=a("rwoTargets",n);if(!o)return[];try{return o.split(",").map(e=>{const[t,n]=e.split(":");return{organismId:t,recordId:n}}).filter(e=>e.organismId&&e.recordId)}catch(i){return[]}},s=(e,n,r)=>{const o=n||window.location.href,i=a("rwoContext",o);if(i)try{const n=t(i);if(!n)return;if(r){const t=n[r];if(!t)return c(n,e,r);const o=t[e];return o?.rwoRecordId?o.rwoRecordId:void 0}return c(n,e,void 0)}catch(l){return}},c=(e,t,n)=>{const r=e.selectedWebpageId;if(r&&n&&r!==n)return;const o=e[t];return o?.rwoRecordId?o.rwoRecordId:void 0},d=(t,n,r=!1)=>{if(!n)return t;const o=a(e.internalLinkWebpageId,n),i=a(e.internalLinkApplicationId,n);if(!o||!i)return t;const l=new URLSearchParams(t.toString());return r?(t.has(e.previewApplicationId)&&l.set(e.previewApplicationId,i),t.has(e.previewSelectedWebpageId)&&l.set(e.previewSelectedWebpageId,o)):(t.has(e.runtimeSelectedWebpageId)&&l.set(e.runtimeSelectedWebpageId,o),l.set(e.runtimeSelectedWebpageId,o)),l},p=async(e="",t="Downloaded file")=>{try{const n=await fetch(e),r=await n.blob(),o=URL.createObjectURL(r),i=document.createElement("a");i.href=o,i.download=t,i.click(),URL.revokeObjectURL(o)}catch(n){o({message:`Failed to download the file: ${n}`,type:"error"})}},u=e=>{if(!e)return;if("object"==typeof e&&"type"in e){const t=e;if(x(t))return;return f(t.externalLink)}return f(e)},m=(e,t)=>{if(e){if("object"==typeof e&&"type"in e){const n=e;if(g(n))return;return x(n)?void(t&&n.internalLink?t({link:n.internalLink}):n.internalLink&&(window.location.href=n.internalLink)):u(n.externalLink)}return u(e)}},f=e=>{if(!e||"string"!=typeof e)return;if(n.test(e))try{const t=window.open(e,"_blank","noopener,noreferrer");if(t){[20,120,300,600].forEach(e=>{setTimeout(()=>{try{t.blur()}catch(e){}try{window.focus()}catch(e){}},e)})}}catch(t){}else try{console.error("navigateToExternalLink: invalid external URL",{url:e})}catch(t){}},x=e=>{if(!e)return!1;const t=e?.type||e?.linkType;return"internal_link"===t||"internalLink"===t},g=e=>!!e&&("data_driven_link"===e.type||"dataDrivenLink"===e.type),I=e=>/^https?:\/\//i.test(e),w=(e,t)=>{if(!g(e))return null;if(!e.internalLinkFieldId&&!e.externalLinkFieldId)return null;let r=null;if(e.dataDrivenLinkType){const n=t?.[e.dataDrivenLinkType];null!=n&&(r=(e=>{if(null==e)return null;if("object"==typeof e&&null!==e){const t=e;if("code"in t&&"string"==typeof t.code){const e=t.code.toLowerCase();if("internal"===e||"internal_link"===e)return"internal";if("external"===e||"external_link"===e)return"external"}if("label"in t&&"string"==typeof t.label){const e=t.label.toLowerCase();if("internal"===e||"internal link"===e)return"internal";if("external"===e||"external link"===e)return"external"}if("value"in t&&"string"==typeof t.value){const e=t.value.toLowerCase();if("internal"===e||"internal_link"===e||"internal link"===e)return"internal";if("external"===e||"external_link"===e||"external link"===e)return"external"}}if("string"==typeof e){const t=e.toLowerCase();if("internal"===t||"internal_link"===t||"internal link"===t)return"internal";if("external"===t||"external_link"===t||"external link"===t)return"external"}return null})(n),r||e.dataDrivenLinkType)}if(!r){const t=!!e.internalLinkFieldId,n=!!e.externalLinkFieldId;if(n&&!t)r="external";else{if(!t||n)return null;r="internal"}}if("internal"===r){if(!e.internalLinkFieldId)return null;const n=t?.[e.internalLinkFieldId],r=(e=>{if(null!=e){if("object"==typeof e&&null!==e){const t=e;if("id"in t&&("string"==typeof t.id||"number"==typeof t.id))return String(t.id)}return"string"==typeof e?e:void 0}})(n);if(!r)return e.internalLinkFieldId,null;const o=e.rwoRecordIdFieldId?(e=>{if(null!=e){if("object"==typeof e&&null!==e){const t=e;if("id"in t&&("string"==typeof t.id||"number"==typeof t.id))return String(t.id);if("value"in t&&("string"==typeof t.value||"number"==typeof t.value))return String(t.value)}return"string"==typeof e?e:"number"==typeof e?String(e):void 0}})(t?.[e.rwoRecordIdFieldId]):void 0;return{destination:`?internalTaskTagId=${encodeURIComponent(r)}`,isExternal:!1,recordId:o,webpageAlias:r}}if("external"===r){if(!e.externalLinkFieldId)return null;const r=t?.[e.externalLinkFieldId],o=(e=>{if(null!=e){if("object"==typeof e&&null!==e){const t=e;if("value"in t&&("string"==typeof t.value||"number"==typeof t.value))return String(t.value)}return"string"==typeof e?e:void 0}})(r);return o?n.test(o)?{destination:o,isExternal:!0,recordId:void 0,webpageAlias:void 0}:(console.error("Data-driven link: invalid external URL",{externalLinkFieldId:e.externalLinkFieldId,url:o}),null):(console.error("Data-driven link: could not extract URL from externalLinkFieldId",{externalLinkFieldId:e.externalLinkFieldId,rawValue:r}),null)}return null},j=(e,t)=>{if(!e)return;const n=new URL(window.location.href),r=d(n.searchParams,e,t);return n.search=r.toString(),n.toString()},y=(e,t)=>{if(e)return x(e)?j(e?.internalLink,t):e?.externalLink},k=e=>{const t=e?.replace(/\\/g,"");try{return JSON.parse(e)}catch(n){try{return JSON.parse(t)}catch(o){return r}}},h=e=>{if(!e)return null;try{const t=e.startsWith("http")?e:new URL(e,window.location.origin).toString();return new URL(t)}catch(t){return null}},L=(e,t)=>{const n=h(e);if(!n)return;return n.searchParams.get(t)??void 0},b=t=>{if(!t)return;const n=h(t);if(n){const t=n.searchParams,r=t.get(e.internalLinkWebpageId)||t.get(e.runtimeSelectedWebpageId)||t.get(e.previewSelectedWebpageId);if(r)return r;const o=(n.pathname||"").split("/").map(e=>e.trim()).filter(e=>e.length>0);for(const n of o){const[t,r]=n.split("=");if(t&&null!=r&&(t===e.internalLinkWebpageId||t===e.runtimeSelectedWebpageId||t===e.previewSelectedWebpageId))return decodeURIComponent(r)}}const r=t.split("/").map(e=>e.trim()).filter(e=>e.length>0);for(const o of r){const[t,n]=o.split("=");if(t&&null!=n&&(t===e.internalLinkWebpageId||t===e.runtimeSelectedWebpageId||t===e.previewSelectedWebpageId))return decodeURIComponent(n)}},C=()=>{try{const t=new URLSearchParams(window.location.search||"");return t.get(e.runtimeSelectedWebpageId)||t.get(e.previewSelectedWebpageId)||void 0}catch(t){return}};export{j as addInternalParamsToCurrentLink,g as checkIsDataDrivenLink,x as checkIsInternalLink,p as downloadFile,y as getHref,L as getParamFromInternalLink,a as getParameterByName,s as getRwoRecordIdForOrganism,l as getRwoTargets,b as getSelectedWebpageIdFromInternalLink,C as getSelectedWebpageIdFromLocation,I as isExternalUrl,u as navigateToExternalLink,m as navigateToLink,k as parseDescendantContent,h as parseInternalLink,w as resolveDataDrivenLink,d as updateSearchParams,i as validateAndOpenUrl};
2
2
  //# sourceMappingURL=utils.js.map
@@ -1,2 +1,2 @@
1
- import{getDataByPath as e}from"../../../containers/utils/dataPathUtils.js";import"../../../contexts/AccountButtonContext/AccountButtonContext.js";import"react/jsx-runtime";import"../../../node_modules/@emotion/react/dist/emotion-element-d59e098f.esm.js";import{useState as t,useRef as o,useMemo as r,useContext as n,useCallback as a}from"react";import"../../../node_modules/stylis/dist/umd/stylis.js";import"../../../node_modules/@babel/runtime/helpers/extends.js";import"../../../node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js";import"../../../contexts/ApiContext/ApiContext.js";import{useContainerRuntime as i}from"../../../contexts/ContainerRuntimeContext/ContainerRuntimeContext.js";import"../../../contexts/FormStepContext/FormStepContext.js";import{useFormContext as s}from"../../../node_modules/react-hook-form/dist/index.esm.mjs.js";import"../../../contexts/LayoutContext/LayoutContext.js";import"../../../theme/theme.js";import"../../../theme/provider.js";import"../../../theme/toastStyles.js";import"../../../contexts/MlrRichTextViewerContext/MlrRichTextViewerContext.js";import"../../../contexts/OrganismContext/OrganismContext.js";import{useOrganismContext as c}from"../../../contexts/OrganismContext/useOrganismContext.js";import"../../../contexts/PopupContext/PopupContext.js";import{usePopupContext as l}from"../../../contexts/PopupContext/usePopupContext.js";import{useReplicatorForm as d}from"../../../contexts/ReplicatorFormContext/ReplicatorFormContext.js";import{useReplicatorRegistry as u}from"../../../contexts/ReplicatorRegistryContext/ReplicatorRegistryContext.js";import"../../../contexts/StateContext/StateContext.js";import{encodeObjectToBase64Url as f,getByPath as g,decodeBase64UrlToObject as p}from"../../../helpers/rwoContext.js";import{useStateContext as y}from"../../../contexts/StateContext/useStateContext.js";import{WebpageContext as m}from"../../../contexts/WebpageContext/WebpageContext.js";import{useSubmitForm as h}from"../../../contexts/ApiContext/globalQueries/form/useSubmitForm.js";import{useResolveDataResolverRaw as v}from"../../../helpers/useDataResolution.js";import{navigateToExternalLink as w,checkIsDataDrivenLink as b,resolveDataDrivenLink as I,checkIsInternalLink as x,downloadFile as _}from"../../../helpers/utils.js";const k=e=>{if(null==e)return e;if("object"==typeof e&&null!==e){const t=e;if("id"in t&&null!==t.id&&void 0!==t.id)return t.id;if("value"in t&&null!==t.value&&void 0!==t.value)return t.value}return e},F=e=>{if(null==e)return;const t=k(e);return"string"==typeof t||"number"==typeof t||"boolean"==typeof t?String(t):void 0},A=({targetWebpageId:e,sourceFieldId:t,inputParams:o,resolveValue:r})=>{const n={};if(t){const e=r(t);null!=e&&(n[t]=e)}return(o||[]).forEach(e=>{if(!e?.sourceFieldId)return;const t=r(e.sourceFieldId);null!=t&&(n[e.sourceFieldId]=t)}),0===Object.keys(n).length?{}:e?{[e]:n}:n},j=e=>{const t=e.match(/webpageId=([^/&#?]+)/);return t?t[1]:void 0},P=(e,t)=>{const o={...e};return Object.keys(t).forEach(e=>{const r=t[e],n=o[e];!r||"object"!=typeof r||Array.isArray(r)||!n||"object"!=typeof n||Array.isArray(n)?o[e]=r:o[e]=P(n,r)}),o},C=e=>Boolean(e)&&"object"==typeof e&&!Array.isArray(e),O=["filterFormByPage","filtersByPage","filterParamsByPage","filterFormByWebpage","filtersByWebpage","filterParamsByWebpage"],R=["filterForm","filters","filterParams"],S=e=>{if(null==e)return{value:e};if("object"==typeof e&&null!==e){const t=e;if("id"in t||"value"in t)return{...t}}return{value:e}},D=(e,t)=>{const o=Object.keys(t);if(0===o.length)return!1;if(o.every(o=>void 0!==e[o]&&JSON.stringify(e[o])===JSON.stringify(t[o])))return!0;for(const r of Object.values(e))if(Array.isArray(r))for(const e of r)if(e&&"object"==typeof e){const r=e;if(o.every(e=>void 0!==r[e]&&JSON.stringify(r[e])===JSON.stringify(t[e])))return!0}return!1},E=(e,t)=>{const o=Object.keys(t);if(0!==o.length){console.log("[findParentIndexByContainerData] VALUE FALLBACK: Searching for match of",o.length,"keys");for(let o=0;o<e.length;o+=1){const r=e[o];if(r&&"object"==typeof r){const e=D(r,t);if(console.log(`[findParentIndexByContainerData] Index ${o} matches:`,e),e)return o}}console.log("[findParentIndexByContainerData] No match found")}},L=(t,o,r,n,a,i,s,c)=>{const l=a.length>0?e(i,a):null;if(console.log("[resolveFieldFromDataLayer] DEBUG:",{fieldId:t,parentFieldId:o,containerDataKeys:Object.keys(r),containerDataSample:JSON.stringify(r).slice(0,200),localStateDataKeys:Object.keys(n),nestedPathSegments:a,currentItemIndex:s}),l&&void 0!==l[t])return l[t];if(o){const d=(()=>{if(l&&Array.isArray(l[o]))return l[o];const e=i[o];return Array.isArray(e)?e:void 0})(),u=n[o],f=!Array.isArray(u)&&c?c(o):void 0,g=d||(Array.isArray(u)?u:Array.isArray(f)?f:void 0);if(console.log("[resolveFieldFromDataLayer] parentArray exists:",Array.isArray(g),"length:",Array.isArray(g)?g.length:0),Array.isArray(g)){if(1===g.length){const e=g[0];if(e&&void 0!==e[t])return console.log("[resolveFieldFromDataLayer] Found via single-item parent array"),e[t]}if(a.length>0&&Object.keys(r).length>0){const e=a[0];if(e.dmfId&&void 0!==e.index){console.log("[resolveFieldFromDataLayer] PRIORITY 0 - trying reference identity match");const o=((e,t,o,r)=>{const n=Object.keys(r);if(0===n.length)return;console.log("[findParentIndexByNestedReference] Searching with:",{nestedArrayId:t,nestedItemIndex:o,containerKeysCount:n.length});const a=e.findIndex((e,a)=>{if(!e||"object"!=typeof e)return!1;const i=e[t];if(!Array.isArray(i))return!1;if(o>=i.length)return!1;const s=i[o];if(!s||"object"!=typeof s)return!1;const c=n.every(e=>r[e]===s[e]);return console.log(`[findParentIndexByNestedReference] Parent ${a}: refs match =`,c),c});if(-1!==a)return console.log("[findParentIndexByNestedReference] Found via reference identity at index:",a),a;console.log("[findParentIndexByNestedReference] No reference match found, falling back to value matching")})(g,e.dmfId,e.index,r);if(void 0!==o){const e=g[o];if(void 0!==e[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 0 (reference) at index:",o),e[t]}}}if(Object.keys(r).length>0){const e=E(g,r);if(console.log("[resolveFieldFromDataLayer] PRIORITY 1 (value fallback) - matchedIndex:",e),void 0!==e){const o=g[e];if(void 0!==o[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 1 at index:",e),o[t]}}for(let e=0;e<a.length;e+=1){const r=a[e];if(r.dmfId===o&&void 0!==r.index&&(console.log("[resolveFieldFromDataLayer] PRIORITY 2 - found segment at idx:",e,"with index:",r.index),r.index<g.length)){const e=g[r.index];if(e&&void 0!==e[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 2 at index:",r.index),e[t]}}if(void 0!==s&&s<g.length){console.log("[resolveFieldFromDataLayer] PRIORITY 3 - trying currentItemIndex:",s);const e=g[s];if(e&&void 0!==e[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 3 at index:",s),e[t]}const i=a.findIndex(e=>e.dmfId===o);if(console.log("[resolveFieldFromDataLayer] PRIORITY 4 - parentSegmentIndex:",i),i>=0){const o=a.slice(0,i+1),r=e(n,o);if(r&&void 0!==r[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 4"),r[t]}}}if(void 0!==i[t])return i[t];if(void 0!==r[t])return console.log("[resolveFieldFromDataLayer] Found in containerData"),r[t];for(let d=a.length-1;d>=0;d-=1){const o=a[d],i=n[o.dmfId];if(Array.isArray(i)){if(Object.keys(r).length>0){const e=E(i,r);if(void 0!==e){const o=i[e];if(void 0!==o[t])return o[t]}}const e=o.index;if(void 0!==e&&e<i.length){const o=i[e];if(o&&void 0!==o[t])return o[t]}}else{const o=a.slice(0,d+1),r=e(n,o);if(r&&void 0!==r[t])return r[t]}}if(c){const e=c(t);if(void 0!==e)return e}return void 0!==n[t]?n[t]:void 0},N=e=>{const t=new Map;return e.forEach(e=>{const o=`${e.sourceParent||"root"}:${e.destinationParent||"root"}`;t.has(o)||t.set(o,{sourceParent:e.sourceParent,destinationParent:e.destinationParent,mappings:[]}),t.get(o).mappings.push(e)}),Array.from(t.values())},M=(e,t,o)=>{if(!t)return;const r=t.split(".");let n=e;const a=e=>/^\d+$/.test(e);for(let i=0;i<r.length;i+=1){const e=r[i],t=i===r.length-1,s=r[i+1],c=!!s&&a(s);if(Array.isArray(n)){const r=Number(e);if(Number.isNaN(r))return;if(t)return void(n[r]=o);n[r]&&"object"==typeof n[r]||(n[r]=c?[]:{}),n=n[r]}else{if(t)return void(n[e]=o);e in n&&null!==n[e]&&"object"==typeof n[e]||(n[e]=c?[]:{}),n=n[e]}}},T=(e,t)=>{const o={};console.log("🔧 [buildDestinationValue] Called with:",{groupsCount:e.length,groups:e.map(e=>({sourceParent:e.sourceParent,destinationParent:e.destinationParent,mappingsCount:e.mappings.length}))});const r=new Set;return e.filter(e=>e.sourceParent&&e.destinationParent).forEach(e=>{e.destinationParent&&r.add(e.destinationParent)}),e.filter(e=>!e.destinationParent).forEach(e=>{e.mappings.forEach(e=>{if(r.has(e.destination))return;const n=t(e.source);if(void 0!==n)if(Array.isArray(n))console.log(` 📦 [buildDestinationValue] Scalar mapping (array): ${e.source} → ${e.destination}`,n),M(o,e.destination,n);else{const t=S(n);console.log(` 📝 [buildDestinationValue] Scalar mapping: ${e.source} → ${e.destination}`,{rawValue:n,wrapped:t}),M(o,e.destination,t)}})}),e.filter(e=>e.sourceParent&&e.destinationParent).forEach(e=>{const r=t(e.sourceParent);if(!Array.isArray(r))return;const n=r.map(t=>{const o={},r=t;return e.mappings.forEach(e=>{const t=r[e.source];void 0!==t&&(o[e.destination]=S(t))}),o});M(o,e.destinationParent,n)}),console.log("✅ [buildDestinationValue] Final result:",JSON.stringify(o,null,2)),o},B=(e,S={})=>{const{properties:D,moleculeId:E,onClick:M,disabled:B}=e,{onActionStart:V,onActionComplete:$,onActionError:W,onAllActionsComplete:J,onStatePatch:q,stopOnError:U=!0,executeAsync:H=!0}=S,[K,Y]=t(!1),[G,Q]=t(-1),[z,X]=t([]),[Z,ee]=t(null),te=o(null),oe=o(!1),re=r(()=>{const e=D?.action,t=e?.action,o=t||e;return o?Array.isArray(o)?o:o&&"object"==typeof o&&"type"in o?[o]:[]:[]},[D?.action]),{setActivePopup:ne,clearActivePopup:ae}=l(),ie=s()||{},se=c?.()||{},ce=i?.()||{},le=y?.()||{},de=le?.stateObject,ue=d(),fe=u(),ge=n(m),pe=v(),{onInternalNavigation:ye,formId:me,routing:he,submitHandler:ve,localState:we,localStateObject:be,organismInfo:Ie,prefillData:xe}=se,{submitForm:_e}=h()||{},ke=a(e=>{if(oe.current)return;const t=e&&e.length>0?e:te.current||null,o=Array.isArray(t)&&t.length>0;if(q)return q({id:E,type:"clicked",statePatch:o?{navigationHistory:t}:void 0,globalPatch:o?{navigationHistory:t}:void 0}),void(oe.current=!0);if(le?.stateHandler){const e={};o&&(e.navigationHistory=t),E&&(e[E]={interacted:"clicked",...o?{navigationHistory:t}:{}}),Object.keys(e).length>0&&(le.stateHandler(e),oe.current=!0)}},[E,q,le]),Fe=a(()=>{const e=le?.updateStateObject;if("function"!=typeof e)return;const t=C(le?.stateObject)?le.stateObject:{},o=C(t.params)?t.params:{},r=O.some(e=>{const t=o[e];return C(t)&&Object.keys(t).length>0}),n=R.some(e=>{const t=o[e];return C(t)&&Object.keys(t).length>0});if(!r&&!n)return;const a={...o};O.forEach(e=>{a[e]={}}),R.forEach(e=>{a[e]={}}),delete a.filterPageId,e({params:a},{debounceMs:0}).catch(()=>{})},[le]),Ae=a(e=>{const t=Array.isArray(te.current)?te.current:Array.isArray(de?.navigationHistory)?de?.navigationHistory:[],o=[{...e,timestamp:(new Date).toISOString()},...t].slice(0,10);return te.current=o,ke(o),o},[ke,de?.navigationHistory]),je=a(e=>{const{link:t,query:o,state:r,webpageAlias:n,targetWebpageId:a,rwoContext:i,clearFiltersWhenNoRwoContext:s=!1}=e,c=i?void 0:(e=>{if(e?.rwoContext)return p(e.rwoContext)??void 0})(o),l=i||c,d=C(l)&&Object.keys(l).length>0;s&&!d&&Fe();const u={link:t,...void 0!==o?{query:o}:{},...void 0!==r?{state:r}:{},...void 0!==n?{webpageAlias:n}:{},webpageId:a||j(t),...l?{rwoContext:l}:{}},f=Ae(u),g={link:t};return void 0!==o&&(g.query=o),void 0!==r&&(g.state=r),void 0!==n&&(g.webpageAlias=n),ye?.(g),f},[Fe,ye,Ae]),Pe=a(async e=>{if(!e.link)throw new Error("Link configuration missing");if("string"!=typeof e.link){if(b(e.link)){const t={};if(ie&&"function"==typeof ie.getValues){const e=ie.getValues();Object.assign(t,e)}ce?.rawItemDataByDmfId&&Object.keys(ce.rawItemDataByDmfId).forEach(e=>{e in t||(t[e]=ce.rawItemDataByDmfId[e])});const o=be?.data;o&&Object.keys(o).forEach(e=>{e in t||(t[e]=o[e])}),be&&Object.keys(be).forEach(e=>{e in t||(t[e]=be[e])}),le?.stateConfig&&Object.keys(le.stateConfig).forEach(e=>{e in t||(t[e]=le.stateConfig[e])});const r=I(e.link,t);if(!r)return;if(r.isExternal)w(r.destination);else{const o=e.link?.sourceDataModelFieldId||e.link?.rwoRecordIdFieldId||e.link?.recordIdFieldId||e?.sourceDataModelFieldId,n=e?.inputParams||e.link?.inputParams,a=A({sourceFieldId:o,inputParams:n,resolveValue:e=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:pe(e)});r.recordId&&void 0===a.rwoRecordId&&(a.rwoRecordId=r.recordId);const i=Object.keys(a).length>0?{rwoContext:f(a)}:void 0;je({link:r.destination,webpageAlias:r.webpageAlias,query:i,rwoContext:Object.keys(a).length>0?a:void 0,clearFiltersWhenNoRwoContext:!0})}return}if(x(e.link)){const t={};return e.link?.targetFormId&&(t.organismId=String(e.link?.targetFormId)),e.link?.rwoKey&&(t.rwo=String(e.link?.rwoKey)),void je({link:e.link.internalLink||"",query:t,clearFiltersWhenNoRwoContext:!0})}w(e.link.externalLink||"")}else w(e.link)},[ce,ie,be,le,ye,pe]),Ce=a(async e=>{if(!e.download)throw new Error("Download configuration missing");"string"!=typeof e.download?_(e.download.url,e.download.name):_(e.download,"")},[]),Oe=a(e=>{const t=e?.open_popup,o=t?.organismId;if(!o)throw new Error("Popup configuration missing");ne?.({id:o})},[ne]),Re=a(async e=>{if(!ie?.handleSubmit)throw new Error("Form context not available for submit action");const t=(me??"").toString();if(!t)throw new Error("Form ID missing in OrganismContext for submit action");let o,r;try{const e=new URLSearchParams(window.location.search),r=e.get("rwoContext"),n=e.get("selectedWebpageId");if(r&&n){const e=JSON.parse(atob(r))[n];if(e){const r=e[t];r?.rwoRecordId&&(o=r.rwoRecordId)}}}catch{}return await ie.handleSubmit(async n=>{const a={formId:t,data:n};let i;o&&(a.rwoRecordId=o),Ie?.pmiObjectId&&(a.pmiObjectId=Ie.pmiObjectId);try{if(ve)i=await ve(a);else{if(!_e)return;i=await _e(a)}}catch(d){const t=e.submit?.onError?.link;if(t&&t.internalLink)if(x(t)){const e={};t?.rwoKey&&(e.rwo=String(t?.rwoKey)),je({link:t.internalLink||"",query:e})}else w(t.externalLink||"");throw d}r=i;const s=le?.stateHandler;"function"==typeof s&&t&&s({[t]:{interacted:"completed"}});const c=e?.submit?.onSuccess?.link;if(c&&(c.internalLink||c.externalLink))if(x(c)){const e={};c?.rwoKey&&(e.rwo=String(c?.rwoKey)),je({link:c.internalLink||"",query:e})}else w(c.externalLink||"");const l=e.submit?.resetAfterSubmit;return!1!==l&&ie?.reset?.(),i},async e=>{throw new Error("Form validation failed")})(),r},[ie,_e,ye,me,he]),Se=a(async(e,t)=>{const o=We(e,t);if(!o)throw new Error(`Navigation configuration missing for ${t}`);switch(t){case"navigateToCreateForm":if(o.targetFormId){const e=`?organismId=${o.targetFormId}`;let t={};try{const e=new URLSearchParams(window.location.search).get("rwoContext");e&&(t=JSON.parse(atob(e)))}catch{}const r={};Object.keys(t).length>0&&(r.rwoContext=btoa(JSON.stringify(t))),je({link:e,query:Object.keys(r).length>0?r:void 0})}break;case"navigateToEditForm":if(o.targetFormId){const e=o?.link,t=e?.internalLink||`?organismId=${o.targetFormId}`,r=e=>{const t=e.match(/webpageId=([^/&#?]+)/);return t?t[1]:void 0},n=e?.internalLink?r(e.internalLink):void 0,a=o?.inputParams,i=ie&&"function"==typeof ie.getValues?ie.getValues():{},s=ce?.rawItemDataByDmfId||{},c=be?.data,l={};if(a&&a.length>0){const e=a[0];let t;if(void 0===t&&void 0!==s[e.sourceFieldId]&&(t=s[e.sourceFieldId]),void 0===t&&void 0!==i[e.sourceFieldId]&&(t=i[e.sourceFieldId]),void 0===t&&void 0!==c?.[e.sourceFieldId]&&(t=c[e.sourceFieldId]),void 0===t&&be){const o=g(be,e.sourceFieldId);void 0!==o&&(t=o)}if(void 0===t&&le?.stateConfig){const o=g(le.stateConfig,e.sourceFieldId);void 0!==o&&(t=o)}if(null!=t&&""!==t){const o=k(t),r=String(o);l[e.sourceFieldId]=r,l.rwoRecordId=r}}let d={};try{const e=new URLSearchParams(window.location.search).get("rwoContext");e&&(d=JSON.parse(atob(e)))}catch{}const u=(e,t)=>{const o={...e};return Object.keys(t).forEach(e=>{const r=t[e],n=o[e];r&&"object"==typeof r&&!Array.isArray(r)&&n&&"object"==typeof n&&!Array.isArray(n)?o[e]=u(n,r):void 0!==r&&(o[e]=r)}),o};let f={};Object.keys(l).length>0&&n&&(f={[n]:{[o.targetFormId]:l}});const p=u(d,f),y={};Object.keys(p).length>0&&(y.rwoContext=btoa(JSON.stringify(p))),je({link:t,query:Object.keys(y).length>0?y:void 0})}break;case"navigateToPrepopulateForm":{const e=o?.link?.internalLink||"",{targetFormId:t}=o||{};if(!t&&!e)break;const r=Array.isArray(o?.fieldMap)?o.fieldMap:[],n=(()=>{try{return new URLSearchParams(window.location.search).get("selectedWebpageId")||void 0}catch{return}})(),a=e?(e=>{const t=e.match(/webpageId=([^/&#?]+)/);return t?t[1]:void 0})(e):void 0,i=n&&a===n,s=ce?.rawItemDataByDmfId||{},c=ce?.nestedPathSegments||[],l=ce?.itemIndex,d=(()=>{const e=be?.data;if(e&&Object.keys(e).length>0)return e;if(we&&"object"==typeof we&&Object.keys(we).length>0)return we;if(be&&"object"==typeof be){const e=be;if(Object.values(e).some(e=>Array.isArray(e)))return e}return{}})(),u=ie&&"function"==typeof ie.getValues?ie.getValues():{},f=new Map;r.forEach(e=>{e.sourceParent&&f.set(e.source,e.sourceParent)});const g=N(r),p=T(g,e=>L(e,f.get(e),s,d,c,u,l,pe));console.group("🔵 [navigateToPrepopulateForm] Prefill Data Built"),console.log("📋 Field Map:",r),console.log("📍 Nested Path Segments:",c),console.log("📦 Container Data:",s),console.log("🏠 Local State Data:",d),console.log("📝 Form Values:",u),console.log("🎯 Target Form ID:",t),console.log("📊 Prefill Structure:",JSON.stringify(p,null,2)),console.groupEnd();const y=(()=>{try{const e=new URLSearchParams(window.location.search).get("rwoContext");return e?JSON.parse(atob(e)):{}}catch{return{}}})(),m={};if(Object.keys(p).length>0&&t){const e=a||n;let o;if(e){const r=y[e]||{},n=r[t]||{};o={...y,[e]:{...r,[t]:{...n,prefillData:p}}}}else o={...y,[t]:{prefillData:p}};m.rwoContext=btoa(JSON.stringify(o))}if(i){const e=window.location.pathname+window.location.search;je({link:e,query:Object.keys(m).length>0?m:void 0,state:{prefill:p,targetFormId:t}})}else{const o=e||`?organismId=${encodeURIComponent(String(t||""))}`;je({link:o,query:Object.keys(m).length>0?m:void 0,state:{prefill:p,targetFormId:t}})}}break;case"navigateToPageWithRwoContext":{const t=o?.link;if(!t?.internalLink)break;const r=j(t.internalLink),n=o?._mergedRwoContext;if(n){const e={};Object.keys(n).length>0&&(e.rwoContext=btoa(JSON.stringify(n))),je({link:t.internalLink,query:Object.keys(e).length>0?e:void 0,targetWebpageId:r,rwoContext:n});break}const a=A({targetWebpageId:r,sourceFieldId:o?.sourceDataModelFieldId||e?.sourceDataModelFieldId,inputParams:o?.inputParams||e?.inputParams,resolveValue:pe});let i={};try{const e=new URLSearchParams(window.location.search).get("rwoContext");e&&(i=JSON.parse(atob(e)))}catch{}const s=(e,t)=>{const o={...e};return Object.keys(t).forEach(e=>{const r=t[e],n=o[e];r&&"object"==typeof r&&!Array.isArray(r)&&n&&"object"==typeof n&&!Array.isArray(n)?o[e]=s(n,r):void 0!==r&&(o[e]=r)}),o},c=s(i,a),l={};Object.keys(c).length>0&&(l.rwoContext=btoa(JSON.stringify(c))),je({link:t.internalLink,query:Object.keys(l).length>0?l:void 0,targetWebpageId:r,rwoContext:c})}}},[ye,ie,we,be,Ie,he,pe]),De=a(e=>{ie?.reset?.()},[ie]),Ee=a(e=>{ie?.reset?.(),"function"==typeof ae?ae():"function"==typeof ne&&ne(null)},[ie,ae,ne]),Le=a(e=>{const t=e?.add_replicator||{},o=t.targetReplicatorFieldId;let r,n,a,i;if(o&&fe){const e=fe.getReplicator(o);if(!e)return void console.error(`[add_replicator] Replicator "${o}" not found in registry. Make sure the replicator container is rendered and has the correct sourceDataPointerId.`);r=o,n=fe.canAdd(o),a=e=>fe.append(o,e),i=e.fieldArrayMethods.fields.length}else{if(!ue)return void console.error("[add_replicator] No target replicator available. Either:\n1. Configure targetReplicatorFieldId in the button action, or\n2. Place the button inside a replicator container.");r=ue.replicatorFieldId,n=ue.canAdd,a=ue.fieldArrayMethods.append,i=ue.fieldArrayMethods.fields.length}if(n&&(a({}),!1!==t.scrollToNew)){const e=`[data-replicator-instance="${r}-${i}"]`,t=(o=3)=>{requestAnimationFrame(()=>{setTimeout(()=>{const r=document.querySelector(e);r?r.scrollIntoView({behavior:"smooth",block:"nearest"}):o>0&&t(o-1)},50)})};t()}},[ue,fe]),Ne=a(e=>{const t=(e?.delete_replicator||{}).targetReplicatorFieldId;let o,r,n,a,i;if(t&&fe){const e=fe.getReplicator(t);if(!e)return void console.error(`[delete_replicator] Replicator "${t}" not found in registry. Make sure the replicator container is rendered and has the correct sourceDataPointerId.`);o=t,r=fe.canRemove(t),n=e=>fe.remove(t,e),a=e.fieldArrayMethods.fields.length}else{if(!ue)return void console.error("[delete_replicator] No target replicator available. Either:\n1. Configure targetReplicatorFieldId in the button action, or\n2. Place the button inside a replicator container.");o=ue.replicatorFieldId,r=ue.canRemove,n=ue.fieldArrayMethods.remove,a=ue.fieldArrayMethods.fields.length}r&&(i=void 0===ce?.itemIndex||t?a-1:ce.itemIndex,i<0||i>=a?console.error(`[delete_replicator] Invalid index ${i} (length: ${a})`):n(i))},[ue,fe,ce]),Me=a(async e=>{if(!ge?.openAIChat)return;if(ge.isAIAvailable&&!ge.isAIAvailable())return;const t=e?.open_ai_chat||e?.openAIChat||{},o=t?.fieldMap,r=t?.inputParams,n=t?.cortexAgentId,a=ie&&"function"==typeof ie.getValues?ie.getValues():{},i=ce?.rawItemDataByDmfId||{},s=be?.data,c={},l=e=>{if(void 0!==i[e])return i[e];if(void 0!==a[e])return a[e];if(void 0!==s?.[e])return s[e];if(be){const t=g(be,e);if(void 0!==t)return t}if(le?.stateConfig){const t=g(le.stateConfig,e);if(void 0!==t)return t}};if(o&&o.length>0)o.forEach(e=>{const t=l(e.source);null!=t&&(c[e.destination]=k(t))});else if(r&&r.length>0)r.forEach(e=>{const t=l(e.sourceFieldId);null!=t&&(c[e.sourceFieldId]=k(t))});else{const e=t?.cortexRwoContext?.sourceDataModelFieldId;if(e){let t;if(!t&&ce?.rawItemDataByDmfId){const o=ce.rawItemDataByDmfId[e];t=F(o)}if(!t&&ie&&"function"==typeof ie.getValues){t=(e=>{if(null==e)return;const t=k(e);return"string"==typeof t||"number"==typeof t||"boolean"==typeof t?String(t):void 0})(g(ie.getValues(),e))}if(!t&&be){const o=g(be,e);t=F(o)}if(!t&&le?.stateConfig){const o=g(le.stateConfig,e);t=F(o)}t&&(c.rwoRecordId=t,c.sourceDataModelFieldId=e)}}const d=Object.keys(c).length>0?{inputParams:c}:void 0;await ge.openAIChat({cortexAgentId:n,cortexRwoContext:d,inputParams:Object.keys(c).length>0?c:void 0,aiContext:Object.keys(c).length>0?c:void 0})},[ge,ie,be,ce,le]),Te=a(e=>{const t=e?.set_context||e?.setContext;return C(t)?t:void 0},[]),Be=a((e,t)=>{const o=Array.isArray(e.fieldMap)?e.fieldMap.filter(e=>Boolean(e)&&"string"==typeof e.source&&e.source.length>0&&"string"==typeof e.destination&&e.destination.length>0).map(e=>({source:e.source,destination:e.destination})):[];if(o.length>0)return o;const r=[];((Array.isArray(e.inputParams)?e.inputParams:t?.inputParams)||[]).forEach(e=>{const t="string"==typeof e?.sourceFieldId?e.sourceFieldId:"";t&&r.push({source:t,destination:t})});const n="string"==typeof e.sourceDataModelFieldId&&e.sourceDataModelFieldId||("string"==typeof t?.sourceDataModelFieldId?t.sourceDataModelFieldId:void 0);return n&&r.push({source:n,destination:n}),r},[]),Ve=a((e,t)=>{const o={};return Be(e,t).forEach(({source:e,destination:t})=>{const r=pe(e);null!=r&&(o[t]=r)}),o},[Be,pe]),$e=a(e=>{const t=Te(e);if(!t)throw new Error("Set context configuration missing");if("filter_params"!==t.target&&"rwo_context"!==t.target)throw new Error("Set context target missing or invalid");const o=Ve(t,e);if(0===Object.keys(o).length)return;if("filter_params"===t.target){const e=le?.filterForm;if("function"!=typeof e?.setValue)return;return void Object.entries(o).forEach(([t,o])=>{e.setValue?.(t,o,{shouldDirty:!0})})}if("function"!=typeof ye)return;let r={};if("undefined"!=typeof window)try{const e=new URLSearchParams(window.location.search||"").get("rwoContext");e&&(r=p(e)||{})}catch{r={}}const n=(()=>{if("undefined"!=typeof window)try{const e=new URLSearchParams(window.location.search||"");return e.get("selectedWebpageId")||e.get("selected-webpage-id")||void 0}catch{return}})(),a=P(r,n?{[n]:o}:o),i="undefined"!=typeof window?`${window.location.pathname||""}${window.location.search||""}`:"";ye({link:i||"/",query:{rwoContext:f(a)}})},[Te,ye,Ve,le]),We=a((e,t)=>{switch(t){case"navigateToCreateForm":return e.navigateToCreateForm||e.navigate_to_create_form||null;case"navigateToEditForm":return e.navigateToEditForm||e.navigate_to_edit_form||null;case"navigateToPrepopulateForm":return e.navigateToPrepopulateForm||e.navigate_to_prepopulate_form||null;case"navigateToPageWithRwoContext":return e.navigateToPageWithRwoContext||e.navigate_to_page_with_rwo_context||null;default:return null}},[]),Je=a(async(e,t)=>{V?.(e,t);try{let o;switch(e.type){case"link":await Pe(e),o="Link executed";break;case"download":await Ce(e),o="Download executed";break;case"submit":o=await Re(e);break;case"open_popup":Oe(e),o="Popup opened";break;case"navigate_to_create_form":await Se(e,"navigateToCreateForm"),o="Navigation executed";break;case"navigate_to_edit_form":await Se(e,"navigateToEditForm"),o="Navigation executed";break;case"navigate_to_prepopulate_form":await Se(e,"navigateToPrepopulateForm"),o="Navigation executed";break;case"navigate_to_page_with_rwo_context":await Se(e,"navigateToPageWithRwoContext"),o="Navigation executed";break;case"navigate_to_organism_with_rwo_context":o="Deprecated navigation ignored";break;case"reset":De(e),o="Reset executed";break;case"destroy":Ee(e),o="Destroy executed";break;case"set_context":case"setContext":$e(e),o="Context set";break;case"open_ai_chat":await Me(e),o="AI Chat opened";break;case"add_replicator":Le(e),o="Replicator instance added";break;case"delete_replicator":Ne(e),o="Replicator instance deleted";break;default:throw new Error(`Unsupported action type: ${e.type}`)}return $?.(e,t,o),o}catch(o){const r=o instanceof Error?o:new Error(String(o));if(W?.(e,t,r),U)throw r;return null}},[V,$,W,U,Pe,Ce,Re,Oe,Se,De,Ee,$e,Me,Le,Ne]),qe=a(e=>{let t;switch(e.type){case"navigate_to_page_with_rwo_context":t=e?.navigate_to_page_with_rwo_context?.link;break;case"navigate_to_prepopulate_form":t=e?.navigate_to_prepopulate_form?.link;break;case"navigate_to_edit_form":t=e?.navigate_to_edit_form?.link;break;case"navigate_to_create_form":t=e?.navigate_to_create_form?.link;break;default:return}return t?.internalLink?j(t.internalLink):void 0},[]),Ue=a((e,t)=>{const o=e.type,r=ie&&"function"==typeof ie.getValues?ie.getValues():{},n=ce?.rawItemDataByDmfId||{},a=be?.data;switch(o){case"navigate_to_page_with_rwo_context":{const o=e?.navigate_to_page_with_rwo_context;return A({targetWebpageId:t,sourceFieldId:o?.sourceDataModelFieldId||e?.sourceDataModelFieldId,inputParams:o?.inputParams||e?.inputParams,resolveValue:pe})}case"navigate_to_prepopulate_form":{const o=e?.navigate_to_prepopulate_form,{targetFormId:a}=o||{},i=Array.isArray(o?.fieldMap)?o.fieldMap:[];if(!a)return{};const s=ce?.nestedPathSegments||[],c=ce?.itemIndex,l=(()=>{const e=be?.data;if(e&&Object.keys(e).length>0)return e;if(we&&"object"==typeof we&&Object.keys(we).length>0)return we;if(be&&"object"==typeof be){const e=be;if(Object.values(e).some(e=>Array.isArray(e)))return e}return{}})(),d=new Map;i.forEach(e=>{e.sourceParent&&d.set(e.source,e.sourceParent)});const u=N(i),f=T(u,e=>L(e,d.get(e),n,l,s,r,c,pe));return 0===Object.keys(f).length?{}:{[t]:{[a]:{prefillData:f}}}}case"navigate_to_edit_form":{const o=e?.navigate_to_edit_form,{targetFormId:i}=o||{},s=o?.inputParams;if(!i)return{};const c={};if(s&&s.length>0){const e=s[0];let t;if(void 0!==n[e.sourceFieldId]&&(t=n[e.sourceFieldId]),void 0===t&&void 0!==r[e.sourceFieldId]&&(t=r[e.sourceFieldId]),void 0===t&&void 0!==a?.[e.sourceFieldId]&&(t=a[e.sourceFieldId]),null!=t&&""!==t){const o=k(t),r=String(o);c[e.sourceFieldId]=r,c.rwoRecordId=r}}return 0===Object.keys(c).length?{}:{[t]:{[i]:c}}}default:return{}}},[ie,ce,be,we,le,pe]),He=a((e,t)=>{const o={...e};return Object.keys(t).forEach(e=>{const r=t[e],n=o[e];r&&"object"==typeof r&&!Array.isArray(r)&&n&&"object"==typeof n&&!Array.isArray(n)?o[e]=He(n,r):o[e]=r}),o},[]),Ke=a(()=>{const e=new Set(["navigate_to_prepopulate_form","navigate_to_page_with_rwo_context","navigate_to_edit_form"]),t=re.filter(t=>t&&e.has(t.type));if(t.length<2)return null;const o=new Map,r=[];t.forEach(e=>{const t=qe(e);if(t){const r=o.get(t)||[];r.push(e),o.set(t,r)}else r.push(e)});let n=!1;for(const i of o.values())if(i.length>1){n=!0;break}if(!n)return null;const a=[];re.forEach(t=>{e.has(t.type)||a.push(t)}),r.forEach(e=>{a.push(e)});for(const[i,s]of o.entries())if(1===s.length)a.push(s[0]);else{s.length;let e={};try{const t=new URLSearchParams(window.location.search).get("rwoContext");t&&(e=JSON.parse(atob(t)))}catch{}s.forEach(t=>{const o=Ue(t,i);e=He(e,o)});const t=s[0],o={id:`merged-${i}`,type:"navigate_to_page_with_rwo_context",navigate_to_page_with_rwo_context:{link:t?.navigate_to_page_with_rwo_context?.link||t?.navigate_to_prepopulate_form?.link||t?.navigate_to_edit_form?.link,_mergedRwoContext:e}};a.push(o)}return a},[re,qe,Ue,He]),Ye=a(async()=>{if(0===re.length)return[];Y(!0),Q(0),X([]),ee(null);try{const e=Ke()||re,t=e.some(e=>"submit"===e?.type),o=new Set(["link","navigate_to_create_form","navigate_to_edit_form","navigate_to_prepopulate_form","navigate_to_page_with_rwo_context"]),r=e=>"close"===e||"destroy"===e,n=(()=>{if(!t)return e;return[...e.filter(e=>e&&"submit"!==e.type&&!o.has(e.type)&&!r(e.type)),...e.filter(e=>e&&"submit"===e.type),...e.filter(e=>e&&r(e.type)),...e.filter(e=>e&&o.has(e.type))]})(),a=[];for(let i=0;i<n.length;i+=1){Q(i);const e=await Je(n[i],i);a.push(e),X([...a])}return J?.(a),a}catch(e){const t=e instanceof Error?e:new Error(String(e));throw ee(t),t}finally{Y(!1),Q(-1)}},[re,Je,J,Ke]),Ge=a(e=>{B||(oe.current=!1,te.current=null,M?(M(e),ke()):re.length>0?Ye().finally(()=>{ke()}).catch(()=>{}):ke())},[re,B,ke,M,Ye]);return{executeActions:Ye,handleAction:Ge,isExecuting:K,currentActionIndex:G,results:z,error:Z,lastNavigationHistory:te}};export{B as useButtonAction};
1
+ import{getDataByPath as e}from"../../../containers/utils/dataPathUtils.js";import"../../../contexts/AccountButtonContext/AccountButtonContext.js";import"react/jsx-runtime";import"../../../node_modules/@emotion/react/dist/emotion-element-d59e098f.esm.js";import{useState as t,useRef as o,useMemo as r,useContext as n,useCallback as i}from"react";import"../../../node_modules/stylis/dist/umd/stylis.js";import"../../../node_modules/@babel/runtime/helpers/extends.js";import"../../../node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js";import"../../../contexts/ApiContext/ApiContext.js";import{useContainerRuntime as a}from"../../../contexts/ContainerRuntimeContext/ContainerRuntimeContext.js";import"../../../contexts/FormStepContext/FormStepContext.js";import{useFormContext as s}from"../../../node_modules/react-hook-form/dist/index.esm.mjs.js";import"../../../contexts/LayoutContext/LayoutContext.js";import"../../../theme/theme.js";import"../../../theme/provider.js";import"../../../theme/toastStyles.js";import"../../../contexts/MlrRichTextViewerContext/MlrRichTextViewerContext.js";import"../../../contexts/OrganismContext/OrganismContext.js";import{useOrganismContext as c}from"../../../contexts/OrganismContext/useOrganismContext.js";import"../../../contexts/PopupContext/PopupContext.js";import{usePopupContext as l}from"../../../contexts/PopupContext/usePopupContext.js";import{useReplicatorForm as d}from"../../../contexts/ReplicatorFormContext/ReplicatorFormContext.js";import{useReplicatorRegistry as u}from"../../../contexts/ReplicatorRegistryContext/ReplicatorRegistryContext.js";import"../../../contexts/StateContext/StateContext.js";import{useStateContext as f}from"../../../contexts/StateContext/useStateContext.js";import{WebpageContext as g}from"../../../contexts/WebpageContext/WebpageContext.js";import{useSubmitForm as p}from"../../../contexts/ApiContext/globalQueries/form/useSubmitForm.js";import{encodeObjectToBase64Url as y,getByPath as m,decodeBase64UrlToObject as h}from"../../../helpers/rwoContext.js";import{useResolveDataResolverRaw as v}from"../../../helpers/useDataResolution.js";import{navigateToExternalLink as w,checkIsDataDrivenLink as I,resolveDataDrivenLink as b,checkIsInternalLink as x,downloadFile as _}from"../../../helpers/utils.js";const k=e=>{if(null==e)return e;if("object"==typeof e&&null!==e){const t=e;if("id"in t&&null!==t.id&&void 0!==t.id)return t.id;if("value"in t&&null!==t.value&&void 0!==t.value)return t.value}return e},F=e=>{if(null==e)return;const t=k(e);return"string"==typeof t||"number"==typeof t||"boolean"==typeof t?String(t):void 0},A=({targetWebpageId:e,sourceFieldId:t,inputParams:o,resolveValue:r})=>{const n={};if(t){const e=r(t);null!=e&&(n[t]=e)}return(o||[]).forEach(e=>{if(!e?.sourceFieldId)return;const t=r(e.sourceFieldId);null!=t&&(n[e.sourceFieldId]=t)}),0===Object.keys(n).length?{}:e?{[e]:n}:n},j=e=>{const t=e.match(/webpageId=([^/&#?]+)/);return t?t[1]:void 0},C=(e,t)=>{const o={...e};return Object.keys(t).forEach(e=>{const r=t[e],n=o[e];!r||"object"!=typeof r||Array.isArray(r)||!n||"object"!=typeof n||Array.isArray(n)?o[e]=r:o[e]=C(n,r)}),o},P=e=>{if(null==e)return{value:e};if("object"==typeof e&&null!==e){const t=e;if("id"in t||"value"in t)return{...t}}return{value:e}},O=(e,t)=>{const o=Object.keys(t);if(0===o.length)return!1;if(o.every(o=>void 0!==e[o]&&JSON.stringify(e[o])===JSON.stringify(t[o])))return!0;for(const r of Object.values(e))if(Array.isArray(r))for(const e of r)if(e&&"object"==typeof e){const r=e;if(o.every(e=>void 0!==r[e]&&JSON.stringify(r[e])===JSON.stringify(t[e])))return!0}return!1},S=(e,t)=>{const o=Object.keys(t);if(0!==o.length){console.log("[findParentIndexByContainerData] VALUE FALLBACK: Searching for match of",o.length,"keys");for(let o=0;o<e.length;o+=1){const r=e[o];if(r&&"object"==typeof r){const e=O(r,t);if(console.log(`[findParentIndexByContainerData] Index ${o} matches:`,e),e)return o}}console.log("[findParentIndexByContainerData] No match found")}},R=(t,o,r,n,i,a,s,c)=>{const l=i.length>0?e(a,i):null;if(console.log("[resolveFieldFromDataLayer] DEBUG:",{fieldId:t,parentFieldId:o,containerDataKeys:Object.keys(r),containerDataSample:JSON.stringify(r).slice(0,200),localStateDataKeys:Object.keys(n),nestedPathSegments:i,currentItemIndex:s}),l&&void 0!==l[t])return l[t];if(o){const d=(()=>{if(l&&Array.isArray(l[o]))return l[o];const e=a[o];return Array.isArray(e)?e:void 0})(),u=n[o],f=!Array.isArray(u)&&c?c(o):void 0,g=d||(Array.isArray(u)?u:Array.isArray(f)?f:void 0);if(console.log("[resolveFieldFromDataLayer] parentArray exists:",Array.isArray(g),"length:",Array.isArray(g)?g.length:0),Array.isArray(g)){if(1===g.length){const e=g[0];if(e&&void 0!==e[t])return console.log("[resolveFieldFromDataLayer] Found via single-item parent array"),e[t]}if(i.length>0&&Object.keys(r).length>0){const e=i[0];if(e.dmfId&&void 0!==e.index){console.log("[resolveFieldFromDataLayer] PRIORITY 0 - trying reference identity match");const o=((e,t,o,r)=>{const n=Object.keys(r);if(0===n.length)return;console.log("[findParentIndexByNestedReference] Searching with:",{nestedArrayId:t,nestedItemIndex:o,containerKeysCount:n.length});const i=e.findIndex((e,i)=>{if(!e||"object"!=typeof e)return!1;const a=e[t];if(!Array.isArray(a))return!1;if(o>=a.length)return!1;const s=a[o];if(!s||"object"!=typeof s)return!1;const c=n.every(e=>r[e]===s[e]);return console.log(`[findParentIndexByNestedReference] Parent ${i}: refs match =`,c),c});if(-1!==i)return console.log("[findParentIndexByNestedReference] Found via reference identity at index:",i),i;console.log("[findParentIndexByNestedReference] No reference match found, falling back to value matching")})(g,e.dmfId,e.index,r);if(void 0!==o){const e=g[o];if(void 0!==e[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 0 (reference) at index:",o),e[t]}}}if(Object.keys(r).length>0){const e=S(g,r);if(console.log("[resolveFieldFromDataLayer] PRIORITY 1 (value fallback) - matchedIndex:",e),void 0!==e){const o=g[e];if(void 0!==o[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 1 at index:",e),o[t]}}for(let e=0;e<i.length;e+=1){const r=i[e];if(r.dmfId===o&&void 0!==r.index&&(console.log("[resolveFieldFromDataLayer] PRIORITY 2 - found segment at idx:",e,"with index:",r.index),r.index<g.length)){const e=g[r.index];if(e&&void 0!==e[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 2 at index:",r.index),e[t]}}if(void 0!==s&&s<g.length){console.log("[resolveFieldFromDataLayer] PRIORITY 3 - trying currentItemIndex:",s);const e=g[s];if(e&&void 0!==e[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 3 at index:",s),e[t]}const a=i.findIndex(e=>e.dmfId===o);if(console.log("[resolveFieldFromDataLayer] PRIORITY 4 - parentSegmentIndex:",a),a>=0){const o=i.slice(0,a+1),r=e(n,o);if(r&&void 0!==r[t])return console.log("[resolveFieldFromDataLayer] Found via PRIORITY 4"),r[t]}}}if(void 0!==a[t])return a[t];if(void 0!==r[t])return console.log("[resolveFieldFromDataLayer] Found in containerData"),r[t];for(let d=i.length-1;d>=0;d-=1){const o=i[d],a=n[o.dmfId];if(Array.isArray(a)){if(Object.keys(r).length>0){const e=S(a,r);if(void 0!==e){const o=a[e];if(void 0!==o[t])return o[t]}}const e=o.index;if(void 0!==e&&e<a.length){const o=a[e];if(o&&void 0!==o[t])return o[t]}}else{const o=i.slice(0,d+1),r=e(n,o);if(r&&void 0!==r[t])return r[t]}}if(c){const e=c(t);if(void 0!==e)return e}return void 0!==n[t]?n[t]:void 0},D=e=>{const t=new Map;return e.forEach(e=>{const o=`${e.sourceParent||"root"}:${e.destinationParent||"root"}`;t.has(o)||t.set(o,{sourceParent:e.sourceParent,destinationParent:e.destinationParent,mappings:[]}),t.get(o).mappings.push(e)}),Array.from(t.values())},E=(e,t,o)=>{if(!t)return;const r=t.split(".");let n=e;const i=e=>/^\d+$/.test(e);for(let a=0;a<r.length;a+=1){const e=r[a],t=a===r.length-1,s=r[a+1],c=!!s&&i(s);if(Array.isArray(n)){const r=Number(e);if(Number.isNaN(r))return;if(t)return void(n[r]=o);n[r]&&"object"==typeof n[r]||(n[r]=c?[]:{}),n=n[r]}else{if(t)return void(n[e]=o);e in n&&null!==n[e]&&"object"==typeof n[e]||(n[e]=c?[]:{}),n=n[e]}}},L=(e,t)=>{const o={};console.log("🔧 [buildDestinationValue] Called with:",{groupsCount:e.length,groups:e.map(e=>({sourceParent:e.sourceParent,destinationParent:e.destinationParent,mappingsCount:e.mappings.length}))});const r=new Set;return e.filter(e=>e.sourceParent&&e.destinationParent).forEach(e=>{e.destinationParent&&r.add(e.destinationParent)}),e.filter(e=>!e.destinationParent).forEach(e=>{e.mappings.forEach(e=>{if(r.has(e.destination))return;const n=t(e.source);if(void 0!==n)if(Array.isArray(n))console.log(` 📦 [buildDestinationValue] Scalar mapping (array): ${e.source} → ${e.destination}`,n),E(o,e.destination,n);else{const t=P(n);console.log(` 📝 [buildDestinationValue] Scalar mapping: ${e.source} → ${e.destination}`,{rawValue:n,wrapped:t}),E(o,e.destination,t)}})}),e.filter(e=>e.sourceParent&&e.destinationParent).forEach(e=>{const r=t(e.sourceParent);if(!Array.isArray(r))return;const n=r.map(t=>{const o={},r=t;return e.mappings.forEach(e=>{const t=r[e.source];void 0!==t&&(o[e.destination]=P(t))}),o});E(o,e.destinationParent,n)}),console.log("✅ [buildDestinationValue] Final result:",JSON.stringify(o,null,2)),o},N=(e,P={})=>{const{properties:O,moleculeId:S,onClick:E,disabled:N}=e,{onActionStart:M,onActionComplete:T,onActionError:V,onAllActionsComplete:B,onStatePatch:$,stopOnError:J=!0,executeAsync:q=!0}=P,[W,U]=t(!1),[H,K]=t(-1),[Y,G]=t([]),[Q,z]=t(null),X=o(null),Z=o(!1),ee=r(()=>{const e=O?.action,t=e?.action,o=t||e;return o?Array.isArray(o)?o:o&&"object"==typeof o&&"type"in o?[o]:[]:[]},[O?.action]),{setActivePopup:te,clearActivePopup:oe}=l(),re=s()||{},ne=c?.()||{},ie=a?.()||{},ae=f?.()||{},se=ae?.stateObject,ce=d(),le=u(),de=n(g),ue=v(),{onInternalNavigation:fe,formId:ge,routing:pe,submitHandler:ye,localState:me,localStateObject:he,organismInfo:ve,prefillData:we}=ne,{submitForm:Ie}=p()||{},be=i(e=>{if(Z.current)return;const t=e&&e.length>0?e:X.current||null,o=Array.isArray(t)&&t.length>0;if($)return $({id:S,type:"clicked",statePatch:o?{navigationHistory:t}:void 0,globalPatch:o?{navigationHistory:t}:void 0}),void(Z.current=!0);if(ae?.stateHandler){const e={};o&&(e.navigationHistory=t),S&&(e[S]={interacted:"clicked",...o?{navigationHistory:t}:{}}),Object.keys(e).length>0&&(ae.stateHandler(e),Z.current=!0)}},[S,$,ae]),xe=i(e=>{const t=Array.isArray(X.current)?X.current:Array.isArray(se?.navigationHistory)?se?.navigationHistory:[],o=[{...e,timestamp:(new Date).toISOString()},...t].slice(0,10);return X.current=o,be(o),o},[be,se?.navigationHistory]),_e=i(e=>{const{link:t,query:o,state:r,webpageAlias:n,targetWebpageId:i,rwoContext:a}=e,s=a?void 0:(e=>{if(e?.rwoContext)return h(e.rwoContext)??void 0})(o),c=a||s,l={link:t,...void 0!==o?{query:o}:{},...void 0!==r?{state:r}:{},...void 0!==n?{webpageAlias:n}:{},webpageId:i||j(t),...c?{rwoContext:c}:{}},d=xe(l),u={link:t};return void 0!==o&&(u.query=o),void 0!==r&&(u.state=r),void 0!==n&&(u.webpageAlias=n),fe?.(u),d},[fe,xe]),ke=i(async e=>{if(!e.link)throw new Error("Link configuration missing");if("string"!=typeof e.link){if(I(e.link)){const t={};if(re&&"function"==typeof re.getValues){const e=re.getValues();Object.assign(t,e)}ie?.rawItemDataByDmfId&&Object.keys(ie.rawItemDataByDmfId).forEach(e=>{e in t||(t[e]=ie.rawItemDataByDmfId[e])});const o=he?.data;o&&Object.keys(o).forEach(e=>{e in t||(t[e]=o[e])}),he&&Object.keys(he).forEach(e=>{e in t||(t[e]=he[e])}),ae?.stateConfig&&Object.keys(ae.stateConfig).forEach(e=>{e in t||(t[e]=ae.stateConfig[e])});const r=b(e.link,t);if(!r)return;if(r.isExternal)w(r.destination);else{const o=e.link?.sourceDataModelFieldId||e.link?.rwoRecordIdFieldId||e.link?.recordIdFieldId||e?.sourceDataModelFieldId,n=e?.inputParams||e.link?.inputParams,i=A({sourceFieldId:o,inputParams:n,resolveValue:e=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:ue(e)});r.recordId&&void 0===i.rwoRecordId&&(i.rwoRecordId=r.recordId);const a=Object.keys(i).length>0?{rwoContext:y(i)}:void 0;_e({link:r.destination,webpageAlias:r.webpageAlias,query:a,rwoContext:Object.keys(i).length>0?i:void 0})}return}if(x(e.link)){const t={};return e.link?.targetFormId&&(t.organismId=String(e.link?.targetFormId)),e.link?.rwoKey&&(t.rwo=String(e.link?.rwoKey)),void _e({link:e.link.internalLink||"",query:t})}w(e.link.externalLink||"")}else w(e.link)},[ie,re,he,ae,fe,ue]),Fe=i(async e=>{if(!e.download)throw new Error("Download configuration missing");"string"!=typeof e.download?_(e.download.url,e.download.name):_(e.download,"")},[]),Ae=i(e=>{const t=e?.open_popup,o=t?.organismId;if(!o)throw new Error("Popup configuration missing");te?.({id:o})},[te]),je=i(async e=>{if(!re?.handleSubmit)throw new Error("Form context not available for submit action");const t=(ge??"").toString();if(!t)throw new Error("Form ID missing in OrganismContext for submit action");let o,r;try{const e=new URLSearchParams(window.location.search),r=e.get("rwoContext"),n=e.get("selectedWebpageId");if(r&&n){const e=JSON.parse(atob(r))[n];if(e){const r=e[t];r?.rwoRecordId&&(o=r.rwoRecordId)}}}catch{}return await re.handleSubmit(async n=>{const i={formId:t,data:n};let a;o&&(i.rwoRecordId=o),ve?.pmiObjectId&&(i.pmiObjectId=ve.pmiObjectId);try{if(ye)a=await ye(i);else{if(!Ie)return;a=await Ie(i)}}catch(d){const t=e.submit?.onError?.link;if(t&&t.internalLink)if(x(t)){const e={};t?.rwoKey&&(e.rwo=String(t?.rwoKey)),_e({link:t.internalLink||"",query:e})}else w(t.externalLink||"");throw d}r=a;const s=ae?.stateHandler;"function"==typeof s&&t&&s({[t]:{interacted:"completed"}});const c=e?.submit?.onSuccess?.link;if(c&&(c.internalLink||c.externalLink))if(x(c)){const e={};c?.rwoKey&&(e.rwo=String(c?.rwoKey)),_e({link:c.internalLink||"",query:e})}else w(c.externalLink||"");const l=e.submit?.resetAfterSubmit;return!1!==l&&re?.reset?.(),a},async e=>{throw new Error("Form validation failed")})(),r},[re,Ie,fe,ge,pe]),Ce=i(async(e,t)=>{const o=Te(e,t);if(!o)throw new Error(`Navigation configuration missing for ${t}`);switch(t){case"navigateToCreateForm":if(o.targetFormId){const e=`?organismId=${o.targetFormId}`;let t={};try{const e=new URLSearchParams(window.location.search).get("rwoContext");e&&(t=JSON.parse(atob(e)))}catch{}const r={};Object.keys(t).length>0&&(r.rwoContext=btoa(JSON.stringify(t))),_e({link:e,query:Object.keys(r).length>0?r:void 0})}break;case"navigateToEditForm":if(o.targetFormId){const e=o?.link,t=e?.internalLink||`?organismId=${o.targetFormId}`,r=e=>{const t=e.match(/webpageId=([^/&#?]+)/);return t?t[1]:void 0},n=e?.internalLink?r(e.internalLink):void 0,i=o?.inputParams,a=re&&"function"==typeof re.getValues?re.getValues():{},s=ie?.rawItemDataByDmfId||{},c=he?.data,l={};if(i&&i.length>0){const e=i[0];let t;if(void 0===t&&void 0!==s[e.sourceFieldId]&&(t=s[e.sourceFieldId]),void 0===t&&void 0!==a[e.sourceFieldId]&&(t=a[e.sourceFieldId]),void 0===t&&void 0!==c?.[e.sourceFieldId]&&(t=c[e.sourceFieldId]),void 0===t&&he){const o=m(he,e.sourceFieldId);void 0!==o&&(t=o)}if(void 0===t&&ae?.stateConfig){const o=m(ae.stateConfig,e.sourceFieldId);void 0!==o&&(t=o)}if(null!=t&&""!==t){const o=k(t),r=String(o);l[e.sourceFieldId]=r,l.rwoRecordId=r}}let d={};try{const e=new URLSearchParams(window.location.search).get("rwoContext");e&&(d=JSON.parse(atob(e)))}catch{}const u=(e,t)=>{const o={...e};return Object.keys(t).forEach(e=>{const r=t[e],n=o[e];r&&"object"==typeof r&&!Array.isArray(r)&&n&&"object"==typeof n&&!Array.isArray(n)?o[e]=u(n,r):void 0!==r&&(o[e]=r)}),o};let f={};Object.keys(l).length>0&&n&&(f={[n]:{[o.targetFormId]:l}});const g=u(d,f),p={};Object.keys(g).length>0&&(p.rwoContext=btoa(JSON.stringify(g))),_e({link:t,query:Object.keys(p).length>0?p:void 0})}break;case"navigateToPrepopulateForm":{const e=o?.link?.internalLink||"",{targetFormId:t}=o||{};if(!t&&!e)break;const r=Array.isArray(o?.fieldMap)?o.fieldMap:[],n=(()=>{try{return new URLSearchParams(window.location.search).get("selectedWebpageId")||void 0}catch{return}})(),i=e?(e=>{const t=e.match(/webpageId=([^/&#?]+)/);return t?t[1]:void 0})(e):void 0,a=n&&i===n,s=ie?.rawItemDataByDmfId||{},c=ie?.nestedPathSegments||[],l=ie?.itemIndex,d=(()=>{const e=he?.data;if(e&&Object.keys(e).length>0)return e;if(me&&"object"==typeof me&&Object.keys(me).length>0)return me;if(he&&"object"==typeof he){const e=he;if(Object.values(e).some(e=>Array.isArray(e)))return e}return{}})(),u=re&&"function"==typeof re.getValues?re.getValues():{},f=new Map;r.forEach(e=>{e.sourceParent&&f.set(e.source,e.sourceParent)});const g=D(r),p=L(g,e=>R(e,f.get(e),s,d,c,u,l,ue));console.group("🔵 [navigateToPrepopulateForm] Prefill Data Built"),console.log("📋 Field Map:",r),console.log("📍 Nested Path Segments:",c),console.log("📦 Container Data:",s),console.log("🏠 Local State Data:",d),console.log("📝 Form Values:",u),console.log("🎯 Target Form ID:",t),console.log("📊 Prefill Structure:",JSON.stringify(p,null,2)),console.groupEnd();const y=(()=>{try{const e=new URLSearchParams(window.location.search).get("rwoContext");return e?JSON.parse(atob(e)):{}}catch{return{}}})(),m={};if(Object.keys(p).length>0&&t){const e=i||n;let o;if(e){const r=y[e]||{},n=r[t]||{};o={...y,[e]:{...r,[t]:{...n,prefillData:p}}}}else o={...y,[t]:{prefillData:p}};m.rwoContext=btoa(JSON.stringify(o))}if(a){const e=window.location.pathname+window.location.search;_e({link:e,query:Object.keys(m).length>0?m:void 0,state:{prefill:p,targetFormId:t}})}else{const o=e||`?organismId=${encodeURIComponent(String(t||""))}`;_e({link:o,query:Object.keys(m).length>0?m:void 0,state:{prefill:p,targetFormId:t}})}}break;case"navigateToPageWithRwoContext":{const t=o?.link;if(!t?.internalLink)break;const r=j(t.internalLink),n=o?._mergedRwoContext;if(n){const e={};Object.keys(n).length>0&&(e.rwoContext=btoa(JSON.stringify(n))),_e({link:t.internalLink,query:Object.keys(e).length>0?e:void 0,targetWebpageId:r,rwoContext:n});break}const i=A({targetWebpageId:r,sourceFieldId:o?.sourceDataModelFieldId||e?.sourceDataModelFieldId,inputParams:o?.inputParams||e?.inputParams,resolveValue:ue});let a={};try{const e=new URLSearchParams(window.location.search).get("rwoContext");e&&(a=JSON.parse(atob(e)))}catch{}const s=(e,t)=>{const o={...e};return Object.keys(t).forEach(e=>{const r=t[e],n=o[e];r&&"object"==typeof r&&!Array.isArray(r)&&n&&"object"==typeof n&&!Array.isArray(n)?o[e]=s(n,r):void 0!==r&&(o[e]=r)}),o},c=s(a,i),l={};Object.keys(c).length>0&&(l.rwoContext=btoa(JSON.stringify(c))),_e({link:t.internalLink,query:Object.keys(l).length>0?l:void 0,targetWebpageId:r,rwoContext:c})}}},[fe,re,me,he,ve,pe,ue]),Pe=i(e=>{re?.reset?.()},[re]),Oe=i(e=>{re?.reset?.(),"function"==typeof oe?oe():"function"==typeof te&&te(null)},[re,oe,te]),Se=i(e=>{const t=e?.add_replicator||{},o=t.targetReplicatorFieldId;let r,n,i,a;if(o&&le){const e=le.getReplicator(o);if(!e)return void console.error(`[add_replicator] Replicator "${o}" not found in registry. Make sure the replicator container is rendered and has the correct sourceDataPointerId.`);r=o,n=le.canAdd(o),i=e=>le.append(o,e),a=e.fieldArrayMethods.fields.length}else{if(!ce)return void console.error("[add_replicator] No target replicator available. Either:\n1. Configure targetReplicatorFieldId in the button action, or\n2. Place the button inside a replicator container.");r=ce.replicatorFieldId,n=ce.canAdd,i=ce.fieldArrayMethods.append,a=ce.fieldArrayMethods.fields.length}if(n&&(i({}),!1!==t.scrollToNew)){const e=`[data-replicator-instance="${r}-${a}"]`,t=(o=3)=>{requestAnimationFrame(()=>{setTimeout(()=>{const r=document.querySelector(e);r?r.scrollIntoView({behavior:"smooth",block:"nearest"}):o>0&&t(o-1)},50)})};t()}},[ce,le]),Re=i(e=>{const t=(e?.delete_replicator||{}).targetReplicatorFieldId;let o,r,n,i,a;if(t&&le){const e=le.getReplicator(t);if(!e)return void console.error(`[delete_replicator] Replicator "${t}" not found in registry. Make sure the replicator container is rendered and has the correct sourceDataPointerId.`);o=t,r=le.canRemove(t),n=e=>le.remove(t,e),i=e.fieldArrayMethods.fields.length}else{if(!ce)return void console.error("[delete_replicator] No target replicator available. Either:\n1. Configure targetReplicatorFieldId in the button action, or\n2. Place the button inside a replicator container.");o=ce.replicatorFieldId,r=ce.canRemove,n=ce.fieldArrayMethods.remove,i=ce.fieldArrayMethods.fields.length}r&&(a=void 0===ie?.itemIndex||t?i-1:ie.itemIndex,a<0||a>=i?console.error(`[delete_replicator] Invalid index ${a} (length: ${i})`):n(a))},[ce,le,ie]),De=i(async e=>{if(!de?.openAIChat)return;if(de.isAIAvailable&&!de.isAIAvailable())return;const t=e?.open_ai_chat||e?.openAIChat||{},o=t?.fieldMap,r=t?.inputParams,n=t?.cortexAgentId,i=re&&"function"==typeof re.getValues?re.getValues():{},a=ie?.rawItemDataByDmfId||{},s=he?.data,c={},l=e=>{if(void 0!==a[e])return a[e];if(void 0!==i[e])return i[e];if(void 0!==s?.[e])return s[e];if(he){const t=m(he,e);if(void 0!==t)return t}if(ae?.stateConfig){const t=m(ae.stateConfig,e);if(void 0!==t)return t}};if(o&&o.length>0)o.forEach(e=>{const t=l(e.source);null!=t&&(c[e.destination]=k(t))});else if(r&&r.length>0)r.forEach(e=>{const t=l(e.sourceFieldId);null!=t&&(c[e.sourceFieldId]=k(t))});else{const e=t?.cortexRwoContext?.sourceDataModelFieldId;if(e){let t;if(!t&&ie?.rawItemDataByDmfId){const o=ie.rawItemDataByDmfId[e];t=F(o)}if(!t&&re&&"function"==typeof re.getValues){t=(e=>{if(null==e)return;const t=k(e);return"string"==typeof t||"number"==typeof t||"boolean"==typeof t?String(t):void 0})(m(re.getValues(),e))}if(!t&&he){const o=m(he,e);t=F(o)}if(!t&&ae?.stateConfig){const o=m(ae.stateConfig,e);t=F(o)}t&&(c.rwoRecordId=t,c.sourceDataModelFieldId=e)}}const d=Object.keys(c).length>0?{inputParams:c}:void 0;await de.openAIChat({cortexAgentId:n,cortexRwoContext:d,inputParams:Object.keys(c).length>0?c:void 0,aiContext:Object.keys(c).length>0?c:void 0})},[de,re,he,ie,ae]),Ee=i(e=>{const t=e?.set_context||e?.setContext;return o=t,Boolean(o)&&"object"==typeof o&&!Array.isArray(o)?t:void 0;var o},[]),Le=i((e,t)=>{const o=Array.isArray(e.fieldMap)?e.fieldMap.filter(e=>Boolean(e)&&"string"==typeof e.source&&e.source.length>0&&"string"==typeof e.destination&&e.destination.length>0).map(e=>({source:e.source,destination:e.destination})):[];if(o.length>0)return o;const r=[];((Array.isArray(e.inputParams)?e.inputParams:t?.inputParams)||[]).forEach(e=>{const t="string"==typeof e?.sourceFieldId?e.sourceFieldId:"";t&&r.push({source:t,destination:t})});const n="string"==typeof e.sourceDataModelFieldId&&e.sourceDataModelFieldId||("string"==typeof t?.sourceDataModelFieldId?t.sourceDataModelFieldId:void 0);return n&&r.push({source:n,destination:n}),r},[]),Ne=i((e,t)=>{const o={};return Le(e,t).forEach(({source:e,destination:t})=>{const r=ue(e);null!=r&&(o[t]=r)}),o},[Le,ue]),Me=i(e=>{const t=Ee(e);if(!t)throw new Error("Set context configuration missing");if("filter_params"!==t.target&&"rwo_context"!==t.target)throw new Error("Set context target missing or invalid");const o=Ne(t,e);if(0===Object.keys(o).length)return;if("filter_params"===t.target){const e=ae?.filterForm;if("function"!=typeof e?.setValue)return;return void Object.entries(o).forEach(([t,o])=>{e.setValue?.(t,o,{shouldDirty:!0})})}if("function"!=typeof fe)return;let r={};if("undefined"!=typeof window)try{const e=new URLSearchParams(window.location.search||"").get("rwoContext");e&&(r=h(e)||{})}catch{r={}}const n=(()=>{if("undefined"!=typeof window)try{const e=new URLSearchParams(window.location.search||"");return e.get("selectedWebpageId")||e.get("selected-webpage-id")||void 0}catch{return}})(),i=C(r,n?{[n]:o}:o),a="undefined"!=typeof window?`${window.location.pathname||""}${window.location.search||""}`:"";fe({link:a||"/",query:{rwoContext:y(i)}})},[Ee,fe,Ne,ae]),Te=i((e,t)=>{switch(t){case"navigateToCreateForm":return e.navigateToCreateForm||e.navigate_to_create_form||null;case"navigateToEditForm":return e.navigateToEditForm||e.navigate_to_edit_form||null;case"navigateToPrepopulateForm":return e.navigateToPrepopulateForm||e.navigate_to_prepopulate_form||null;case"navigateToPageWithRwoContext":return e.navigateToPageWithRwoContext||e.navigate_to_page_with_rwo_context||null;default:return null}},[]),Ve=i(async(e,t)=>{M?.(e,t);try{let o;switch(e.type){case"link":await ke(e),o="Link executed";break;case"download":await Fe(e),o="Download executed";break;case"submit":o=await je(e);break;case"open_popup":Ae(e),o="Popup opened";break;case"navigate_to_create_form":await Ce(e,"navigateToCreateForm"),o="Navigation executed";break;case"navigate_to_edit_form":await Ce(e,"navigateToEditForm"),o="Navigation executed";break;case"navigate_to_prepopulate_form":await Ce(e,"navigateToPrepopulateForm"),o="Navigation executed";break;case"navigate_to_page_with_rwo_context":await Ce(e,"navigateToPageWithRwoContext"),o="Navigation executed";break;case"navigate_to_organism_with_rwo_context":o="Deprecated navigation ignored";break;case"reset":Pe(e),o="Reset executed";break;case"destroy":Oe(e),o="Destroy executed";break;case"set_context":case"setContext":Me(e),o="Context set";break;case"open_ai_chat":await De(e),o="AI Chat opened";break;case"add_replicator":Se(e),o="Replicator instance added";break;case"delete_replicator":Re(e),o="Replicator instance deleted";break;default:throw new Error(`Unsupported action type: ${e.type}`)}return T?.(e,t,o),o}catch(o){const r=o instanceof Error?o:new Error(String(o));if(V?.(e,t,r),J)throw r;return null}},[M,T,V,J,ke,Fe,je,Ae,Ce,Pe,Oe,Me,De,Se,Re]),Be=i(e=>{let t;switch(e.type){case"navigate_to_page_with_rwo_context":t=e?.navigate_to_page_with_rwo_context?.link;break;case"navigate_to_prepopulate_form":t=e?.navigate_to_prepopulate_form?.link;break;case"navigate_to_edit_form":t=e?.navigate_to_edit_form?.link;break;case"navigate_to_create_form":t=e?.navigate_to_create_form?.link;break;default:return}return t?.internalLink?j(t.internalLink):void 0},[]),$e=i((e,t)=>{const o=e.type,r=re&&"function"==typeof re.getValues?re.getValues():{},n=ie?.rawItemDataByDmfId||{},i=he?.data;switch(o){case"navigate_to_page_with_rwo_context":{const o=e?.navigate_to_page_with_rwo_context;return A({targetWebpageId:t,sourceFieldId:o?.sourceDataModelFieldId||e?.sourceDataModelFieldId,inputParams:o?.inputParams||e?.inputParams,resolveValue:ue})}case"navigate_to_prepopulate_form":{const o=e?.navigate_to_prepopulate_form,{targetFormId:i}=o||{},a=Array.isArray(o?.fieldMap)?o.fieldMap:[];if(!i)return{};const s=ie?.nestedPathSegments||[],c=ie?.itemIndex,l=(()=>{const e=he?.data;if(e&&Object.keys(e).length>0)return e;if(me&&"object"==typeof me&&Object.keys(me).length>0)return me;if(he&&"object"==typeof he){const e=he;if(Object.values(e).some(e=>Array.isArray(e)))return e}return{}})(),d=new Map;a.forEach(e=>{e.sourceParent&&d.set(e.source,e.sourceParent)});const u=D(a),f=L(u,e=>R(e,d.get(e),n,l,s,r,c,ue));return 0===Object.keys(f).length?{}:{[t]:{[i]:{prefillData:f}}}}case"navigate_to_edit_form":{const o=e?.navigate_to_edit_form,{targetFormId:a}=o||{},s=o?.inputParams;if(!a)return{};const c={};if(s&&s.length>0){const e=s[0];let t;if(void 0!==n[e.sourceFieldId]&&(t=n[e.sourceFieldId]),void 0===t&&void 0!==r[e.sourceFieldId]&&(t=r[e.sourceFieldId]),void 0===t&&void 0!==i?.[e.sourceFieldId]&&(t=i[e.sourceFieldId]),null!=t&&""!==t){const o=k(t),r=String(o);c[e.sourceFieldId]=r,c.rwoRecordId=r}}return 0===Object.keys(c).length?{}:{[t]:{[a]:c}}}default:return{}}},[re,ie,he,me,ae,ue]),Je=i((e,t)=>{const o={...e};return Object.keys(t).forEach(e=>{const r=t[e],n=o[e];r&&"object"==typeof r&&!Array.isArray(r)&&n&&"object"==typeof n&&!Array.isArray(n)?o[e]=Je(n,r):o[e]=r}),o},[]),qe=i(()=>{const e=new Set(["navigate_to_prepopulate_form","navigate_to_page_with_rwo_context","navigate_to_edit_form"]),t=ee.filter(t=>t&&e.has(t.type));if(t.length<2)return null;const o=new Map,r=[];t.forEach(e=>{const t=Be(e);if(t){const r=o.get(t)||[];r.push(e),o.set(t,r)}else r.push(e)});let n=!1;for(const a of o.values())if(a.length>1){n=!0;break}if(!n)return null;const i=[];ee.forEach(t=>{e.has(t.type)||i.push(t)}),r.forEach(e=>{i.push(e)});for(const[a,s]of o.entries())if(1===s.length)i.push(s[0]);else{s.length;let e={};try{const t=new URLSearchParams(window.location.search).get("rwoContext");t&&(e=JSON.parse(atob(t)))}catch{}s.forEach(t=>{const o=$e(t,a);e=Je(e,o)});const t=s[0],o={id:`merged-${a}`,type:"navigate_to_page_with_rwo_context",navigate_to_page_with_rwo_context:{link:t?.navigate_to_page_with_rwo_context?.link||t?.navigate_to_prepopulate_form?.link||t?.navigate_to_edit_form?.link,_mergedRwoContext:e}};i.push(o)}return i},[ee,Be,$e,Je]),We=i(async()=>{if(0===ee.length)return[];U(!0),K(0),G([]),z(null);try{const e=qe()||ee,t=e.some(e=>"submit"===e?.type),o=new Set(["link","navigate_to_create_form","navigate_to_edit_form","navigate_to_prepopulate_form","navigate_to_page_with_rwo_context"]),r=e=>"close"===e||"destroy"===e,n=(()=>{if(!t)return e;return[...e.filter(e=>e&&"submit"!==e.type&&!o.has(e.type)&&!r(e.type)),...e.filter(e=>e&&"submit"===e.type),...e.filter(e=>e&&r(e.type)),...e.filter(e=>e&&o.has(e.type))]})(),i=[];for(let a=0;a<n.length;a+=1){K(a);const e=await Ve(n[a],a);i.push(e),G([...i])}return B?.(i),i}catch(e){const t=e instanceof Error?e:new Error(String(e));throw z(t),t}finally{U(!1),K(-1)}},[ee,Ve,B,qe]),Ue=i(e=>{N||(Z.current=!1,X.current=null,E?(E(e),be()):ee.length>0?We().finally(()=>{be()}).catch(()=>{}):be())},[ee,N,be,E,We]);return{executeActions:We,handleAction:Ue,isExecuting:W,currentActionIndex:H,results:Y,error:Q,lastNavigationHistory:X}};export{N as useButtonAction};
2
2
  //# sourceMappingURL=useButtonAction.js.map