@stonecrop/stonecrop 0.6.3 → 0.7.0

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,6 +1,6 @@
1
- (function(C,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(C=typeof globalThis<"u"?globalThis:C||self,a(C["@stonecrop/stonecrop"]={},C.Vue))})(this,(function(C,a){"use strict";const q=typeof window<"u";let J;const ne=o=>J=o;process.env.NODE_ENV;const ue=process.env.NODE_ENV!=="production"?Symbol("pinia"):Symbol();function G(o){return o&&typeof o=="object"&&Object.prototype.toString.call(o)==="[object Object]"&&typeof o.toJSON!="function"}var te;(function(o){o.direct="direct",o.patchObject="patch object",o.patchFunction="patch function"})(te||(te={}));function ve(o,e){for(const t in e){const r=e[t];if(!(t in o))continue;const n=o[t];G(n)&&G(r)&&!a.isRef(r)&&!a.isReactive(r)?o[t]=ve(n,r):o[t]=r}return o}const Se=()=>{};function be(o,e,t,r=Se){o.add(e);const n=()=>{o.delete(e)&&r()};return!t&&a.getCurrentScope()&&a.onScopeDispose(n),n}function Y(o,...e){o.forEach(t=>{t(...e)})}const $e=o=>o(),we=Symbol(),fe=Symbol();function de(o,e){o instanceof Map&&e instanceof Map?e.forEach((t,r)=>o.set(r,t)):o instanceof Set&&e instanceof Set&&e.forEach(o.add,o);for(const t in e){if(!e.hasOwnProperty(t))continue;const r=e[t],n=o[t];G(n)&&G(r)&&o.hasOwnProperty(t)&&!a.isRef(r)&&!a.isReactive(r)?o[t]=de(n,r):o[t]=r}return o}const Ce=process.env.NODE_ENV!=="production"?Symbol("pinia:skipHydration"):Symbol();function Ae(o){return!G(o)||!Object.prototype.hasOwnProperty.call(o,Ce)}const{assign:U}=Object;function Ee(o){return!!(a.isRef(o)&&o.effect)}function Oe(o,e,t,r){const{state:n,actions:s,getters:i}=e,c=t.state.value[o];let l;function g(){!c&&(process.env.NODE_ENV==="production"||!r)&&(t.state.value[o]=n?n():{});const w=process.env.NODE_ENV!=="production"&&r?a.toRefs(a.ref(n?n():{}).value):a.toRefs(t.state.value[o]);return U(w,s,Object.keys(i||{}).reduce((E,N)=>(process.env.NODE_ENV!=="production"&&N in w&&console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${N}" in store "${o}".`),E[N]=a.markRaw(a.computed(()=>{ne(t);const D=t._s.get(o);return i[N].call(D,D)})),E),{}))}return l=pe(o,g,e,t,r,!0),l}function pe(o,e,t={},r,n,s){let i;const c=U({actions:{}},t);if(process.env.NODE_ENV!=="production"&&!r._e.active)throw new Error("Pinia destroyed");const l={deep:!0};process.env.NODE_ENV!=="production"&&(l.onTrigger=u=>{g?D=u:g==!1&&!y._hotUpdating&&(Array.isArray(D)?D.push(u):console.error("🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug."))});let g,w,E=new Set,N=new Set,D;const V=r.state.value[o];!s&&!V&&(process.env.NODE_ENV==="production"||!n)&&(r.state.value[o]={});const L=a.ref({});let P;function $(u){let f;g=w=!1,process.env.NODE_ENV!=="production"&&(D=[]),typeof u=="function"?(u(r.state.value[o]),f={type:te.patchFunction,storeId:o,events:D}):(de(r.state.value[o],u),f={type:te.patchObject,payload:u,storeId:o,events:D});const R=P=Symbol();a.nextTick().then(()=>{P===R&&(g=!0)}),w=!0,Y(E,f,r.state.value[o])}const _=s?function(){const{state:f}=t,R=f?f():{};this.$patch(v=>{U(v,R)})}:process.env.NODE_ENV!=="production"?()=>{throw new Error(`🍍: Store "${o}" is built using the setup syntax and does not implement $reset().`)}:Se;function b(){i.stop(),E.clear(),N.clear(),r._s.delete(o)}const A=(u,f="")=>{if(we in u)return u[fe]=f,u;const R=function(){ne(r);const v=Array.from(arguments),d=new Set,S=new Set;function T(F){d.add(F)}function k(F){S.add(F)}Y(N,{args:v,name:R[fe],store:y,after:T,onError:k});let j;try{j=u.apply(this&&this.$id===o?this:y,v)}catch(F){throw Y(S,F),F}return j instanceof Promise?j.then(F=>(Y(d,F),F)).catch(F=>(Y(S,F),Promise.reject(F))):(Y(d,j),j)};return R[we]=!0,R[fe]=f,R},O=a.markRaw({actions:{},getters:{},state:[],hotState:L}),I={_p:r,$id:o,$onAction:be.bind(null,N),$patch:$,$reset:_,$subscribe(u,f={}){const R=be(E,u,f.detached,()=>v()),v=i.run(()=>a.watch(()=>r.state.value[o],d=>{(f.flush==="sync"?w:g)&&u({storeId:o,type:te.direct,events:D},d)},U({},l,f)));return R},$dispose:b},y=a.reactive(process.env.NODE_ENV!=="production"||process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&q?U({_hmrPayload:O,_customProperties:a.markRaw(new Set)},I):I);r._s.set(o,y);const x=(r._a&&r._a.runWithContext||$e)(()=>r._e.run(()=>(i=a.effectScope()).run(()=>e({action:A}))));for(const u in x){const f=x[u];if(a.isRef(f)&&!Ee(f)||a.isReactive(f))process.env.NODE_ENV!=="production"&&n?L.value[u]=a.toRef(x,u):s||(V&&Ae(f)&&(a.isRef(f)?f.value=V[u]:de(f,V[u])),r.state.value[o][u]=f),process.env.NODE_ENV!=="production"&&O.state.push(u);else if(typeof f=="function"){const R=process.env.NODE_ENV!=="production"&&n?f:A(f,u);x[u]=R,process.env.NODE_ENV!=="production"&&(O.actions[u]=f),c.actions[u]=f}else process.env.NODE_ENV!=="production"&&Ee(f)&&(O.getters[u]=s?t.getters[u]:f,q&&(x._getters||(x._getters=a.markRaw([]))).push(u))}if(U(y,x),U(a.toRaw(y),x),Object.defineProperty(y,"$state",{get:()=>process.env.NODE_ENV!=="production"&&n?L.value:r.state.value[o],set:u=>{if(process.env.NODE_ENV!=="production"&&n)throw new Error("cannot set hotState");$(f=>{U(f,u)})}}),process.env.NODE_ENV!=="production"&&(y._hotUpdate=a.markRaw(u=>{y._hotUpdating=!0,u._hmrPayload.state.forEach(f=>{if(f in y.$state){const R=u.$state[f],v=y.$state[f];typeof R=="object"&&G(R)&&G(v)?ve(R,v):u.$state[f]=v}y[f]=a.toRef(u.$state,f)}),Object.keys(y.$state).forEach(f=>{f in u.$state||delete y[f]}),g=!1,w=!1,r.state.value[o]=a.toRef(u._hmrPayload,"hotState"),w=!0,a.nextTick().then(()=>{g=!0});for(const f in u._hmrPayload.actions){const R=u[f];y[f]=A(R,f)}for(const f in u._hmrPayload.getters){const R=u._hmrPayload.getters[f],v=s?a.computed(()=>(ne(r),R.call(y,y))):R;y[f]=v}Object.keys(y._hmrPayload.getters).forEach(f=>{f in u._hmrPayload.getters||delete y[f]}),Object.keys(y._hmrPayload.actions).forEach(f=>{f in u._hmrPayload.actions||delete y[f]}),y._hmrPayload=u._hmrPayload,y._getters=u._getters,y._hotUpdating=!1})),process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&q){const u={writable:!0,configurable:!0,enumerable:!1};["_p","_hmrPayload","_getters","_customProperties"].forEach(f=>{Object.defineProperty(y,f,U({value:y[f]},u))})}return r._p.forEach(u=>{if(process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&q){const f=i.run(()=>u({store:y,app:r._a,pinia:r,options:c}));Object.keys(f||{}).forEach(R=>y._customProperties.add(R)),U(y,f)}else U(y,i.run(()=>u({store:y,app:r._a,pinia:r,options:c})))}),process.env.NODE_ENV!=="production"&&y.$state&&typeof y.$state=="object"&&typeof y.$state.constructor=="function"&&!y.$state.constructor.toString().includes("[native code]")&&console.warn(`[🍍]: The "state" must be a plain object. It cannot be
1
+ (function(D,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(D=typeof globalThis<"u"?globalThis:D||self,a(D["@stonecrop/stonecrop"]={},D.Vue))})(this,(function(D,a){"use strict";const Z=typeof window<"u";let q;const oe=n=>q=n;process.env.NODE_ENV;const ue=process.env.NODE_ENV!=="production"?Symbol("pinia"):Symbol();function J(n){return n&&typeof n=="object"&&Object.prototype.toString.call(n)==="[object Object]"&&typeof n.toJSON!="function"}var te;(function(n){n.direct="direct",n.patchObject="patch object",n.patchFunction="patch function"})(te||(te={}));function ve(n,e){for(const t in e){const r=e[t];if(!(t in n))continue;const o=n[t];J(o)&&J(r)&&!a.isRef(r)&&!a.isReactive(r)?n[t]=ve(o,r):n[t]=r}return n}const Se=()=>{};function be(n,e,t,r=Se){n.add(e);const o=()=>{n.delete(e)&&r()};return!t&&a.getCurrentScope()&&a.onScopeDispose(o),o}function Y(n,...e){n.forEach(t=>{t(...e)})}const ke=n=>n(),we=Symbol(),fe=Symbol();function de(n,e){n instanceof Map&&e instanceof Map?e.forEach((t,r)=>n.set(r,t)):n instanceof Set&&e instanceof Set&&e.forEach(n.add,n);for(const t in e){if(!e.hasOwnProperty(t))continue;const r=e[t],o=n[t];J(o)&&J(r)&&n.hasOwnProperty(t)&&!a.isRef(r)&&!a.isReactive(r)?n[t]=de(o,r):n[t]=r}return n}const Ve=process.env.NODE_ENV!=="production"?Symbol("pinia:skipHydration"):Symbol();function Fe(n){return!J(n)||!Object.prototype.hasOwnProperty.call(n,Ve)}const{assign:W}=Object;function Ee(n){return!!(a.isRef(n)&&n.effect)}function Re(n,e,t,r){const{state:o,actions:i,getters:s}=e,c=t.state.value[n];let l;function g(){!c&&(process.env.NODE_ENV==="production"||!r)&&(t.state.value[n]=o?o():{});const y=process.env.NODE_ENV!=="production"&&r?a.toRefs(a.ref(o?o():{}).value):a.toRefs(t.state.value[n]);return W(y,i,Object.keys(s||{}).reduce((E,P)=>(process.env.NODE_ENV!=="production"&&P in y&&console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${P}" in store "${n}".`),E[P]=a.markRaw(a.computed(()=>{oe(t);const T=t._s.get(n);return s[P].call(T,T)})),E),{}))}return l=pe(n,g,e,t,r,!0),l}function pe(n,e,t={},r,o,i){let s;const c=W({actions:{}},t);if(process.env.NODE_ENV!=="production"&&!r._e.active)throw new Error("Pinia destroyed");const l={deep:!0};process.env.NODE_ENV!=="production"&&(l.onTrigger=u=>{g?T=u:g==!1&&!m._hotUpdating&&(Array.isArray(T)?T.push(u):console.error("🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug."))});let g,y,E=new Set,P=new Set,T;const k=r.state.value[n];!i&&!k&&(process.env.NODE_ENV==="production"||!o)&&(r.state.value[n]={});const M=a.ref({});let _;function $(u){let f;g=y=!1,process.env.NODE_ENV!=="production"&&(T=[]),typeof u=="function"?(u(r.state.value[n]),f={type:te.patchFunction,storeId:n,events:T}):(de(r.state.value[n],u),f={type:te.patchObject,payload:u,storeId:n,events:T});const O=_=Symbol();a.nextTick().then(()=>{_===O&&(g=!0)}),y=!0,Y(E,f,r.state.value[n])}const N=i?function(){const{state:f}=t,O=f?f():{};this.$patch(S=>{W(S,O)})}:process.env.NODE_ENV!=="production"?()=>{throw new Error(`🍍: Store "${n}" is built using the setup syntax and does not implement $reset().`)}:Se;function w(){s.stop(),E.clear(),P.clear(),r._s.delete(n)}const C=(u,f="")=>{if(we in u)return u[fe]=f,u;const O=function(){oe(r);const S=Array.from(arguments),d=new Set,b=new Set;function I(F){d.add(F)}function V(F){b.add(F)}Y(P,{args:S,name:O[fe],store:m,after:I,onError:V});let B;try{B=u.apply(this&&this.$id===n?this:m,S)}catch(F){throw Y(b,F),F}return B instanceof Promise?B.then(F=>(Y(d,F),F)).catch(F=>(Y(b,F),Promise.reject(F))):(Y(d,B),B)};return O[we]=!0,O[fe]=f,O},R=a.markRaw({actions:{},getters:{},state:[],hotState:M}),A={_p:r,$id:n,$onAction:be.bind(null,P),$patch:$,$reset:N,$subscribe(u,f={}){const O=be(E,u,f.detached,()=>S()),S=s.run(()=>a.watch(()=>r.state.value[n],d=>{(f.flush==="sync"?y:g)&&u({storeId:n,type:te.direct,events:T},d)},W({},l,f)));return O},$dispose:w},m=a.reactive(process.env.NODE_ENV!=="production"||process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&Z?W({_hmrPayload:R,_customProperties:a.markRaw(new Set)},A):A);r._s.set(n,m);const x=(r._a&&r._a.runWithContext||ke)(()=>r._e.run(()=>(s=a.effectScope()).run(()=>e({action:C}))));for(const u in x){const f=x[u];if(a.isRef(f)&&!Ee(f)||a.isReactive(f))process.env.NODE_ENV!=="production"&&o?M.value[u]=a.toRef(x,u):i||(k&&Fe(f)&&(a.isRef(f)?f.value=k[u]:de(f,k[u])),r.state.value[n][u]=f),process.env.NODE_ENV!=="production"&&R.state.push(u);else if(typeof f=="function"){const O=process.env.NODE_ENV!=="production"&&o?f:C(f,u);x[u]=O,process.env.NODE_ENV!=="production"&&(R.actions[u]=f),c.actions[u]=f}else process.env.NODE_ENV!=="production"&&Ee(f)&&(R.getters[u]=i?t.getters[u]:f,Z&&(x._getters||(x._getters=a.markRaw([]))).push(u))}if(W(m,x),W(a.toRaw(m),x),Object.defineProperty(m,"$state",{get:()=>process.env.NODE_ENV!=="production"&&o?M.value:r.state.value[n],set:u=>{if(process.env.NODE_ENV!=="production"&&o)throw new Error("cannot set hotState");$(f=>{W(f,u)})}}),process.env.NODE_ENV!=="production"&&(m._hotUpdate=a.markRaw(u=>{m._hotUpdating=!0,u._hmrPayload.state.forEach(f=>{if(f in m.$state){const O=u.$state[f],S=m.$state[f];typeof O=="object"&&J(O)&&J(S)?ve(O,S):u.$state[f]=S}m[f]=a.toRef(u.$state,f)}),Object.keys(m.$state).forEach(f=>{f in u.$state||delete m[f]}),g=!1,y=!1,r.state.value[n]=a.toRef(u._hmrPayload,"hotState"),y=!0,a.nextTick().then(()=>{g=!0});for(const f in u._hmrPayload.actions){const O=u[f];m[f]=C(O,f)}for(const f in u._hmrPayload.getters){const O=u._hmrPayload.getters[f],S=i?a.computed(()=>(oe(r),O.call(m,m))):O;m[f]=S}Object.keys(m._hmrPayload.getters).forEach(f=>{f in u._hmrPayload.getters||delete m[f]}),Object.keys(m._hmrPayload.actions).forEach(f=>{f in u._hmrPayload.actions||delete m[f]}),m._hmrPayload=u._hmrPayload,m._getters=u._getters,m._hotUpdating=!1})),process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&Z){const u={writable:!0,configurable:!0,enumerable:!1};["_p","_hmrPayload","_getters","_customProperties"].forEach(f=>{Object.defineProperty(m,f,W({value:m[f]},u))})}return r._p.forEach(u=>{if(process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&Z){const f=s.run(()=>u({store:m,app:r._a,pinia:r,options:c}));Object.keys(f||{}).forEach(O=>m._customProperties.add(O)),W(m,f)}else W(m,s.run(()=>u({store:m,app:r._a,pinia:r,options:c})))}),process.env.NODE_ENV!=="production"&&m.$state&&typeof m.$state=="object"&&typeof m.$state.constructor=="function"&&!m.$state.constructor.toString().includes("[native code]")&&console.warn(`[🍍]: The "state" must be a plain object. It cannot be
2
2
  state: () => new MyClass()
3
- Found in store "${y.$id}".`),V&&s&&t.hydrate&&t.hydrate(y.$state,V),g=!0,w=!0,y}function Ve(o,e,t){let r;const n=typeof e=="function";r=n?t:e;function s(i,c){const l=a.hasInjectionContext();if(i=(process.env.NODE_ENV==="test"&&J&&J._testing?null:i)||(l?a.inject(ue,null):null),i&&ne(i),process.env.NODE_ENV!=="production"&&!J)throw new Error(`[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"?
3
+ Found in store "${m.$id}".`),k&&i&&t.hydrate&&t.hydrate(m.$state,k),g=!0,y=!0,m}function Le(n,e,t){let r;const o=typeof e=="function";r=o?t:e;function i(s,c){const l=a.hasInjectionContext();if(s=(process.env.NODE_ENV==="test"&&q&&q._testing?null:s)||(l?a.inject(ue,null):null),s&&oe(s),process.env.NODE_ENV!=="production"&&!q)throw new Error(`[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"?
4
4
  See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help.
5
- This will fail in production.`);i=J,i._s.has(o)||(n?pe(o,e,r,i):Oe(o,r,i),process.env.NODE_ENV!=="production"&&(s._pinia=i));const g=i._s.get(o);if(process.env.NODE_ENV!=="production"&&c){const w="__hot:"+o,E=n?pe(w,e,r,i,!0):Oe(w,U({},r),i,!0);c._hotUpdate(E),delete i.state.value[w],i._s.delete(w)}if(process.env.NODE_ENV!=="production"&&q){const w=a.getCurrentInstance();if(w&&w.proxy&&!c){const E=w.proxy,N="_pStores"in E?E._pStores:E._pStores={};N[o]=g}}return g}return s.$id=o,s}function Re(o){const e=a.toRaw(o),t={};for(const r in e){const n=e[r];n.effect?t[r]=a.computed({get:()=>o[r],set(s){o[r]=s}}):(a.isRef(n)||a.isReactive(n))&&(t[r]=a.toRef(o,r))}return t}const ke=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Fe=Object.prototype.toString,Me=o=>Fe.call(o)==="[object Object]",_e=()=>{};function Le(...o){if(o.length!==1)return a.toRef(...o);const e=o[0];return typeof e=="function"?a.readonly(a.customRef(()=>({get:e,set:_e}))):a.ref(e)}function xe(o,e){function t(...r){return new Promise((n,s)=>{Promise.resolve(o(()=>e.apply(this,r),{fn:e,thisArg:this,args:r})).then(n).catch(s)})}return t}const Pe=o=>o();function Be(o=Pe,e={}){const{initialState:t="active"}=e,r=Le(t==="active");function n(){r.value=!1}function s(){r.value=!0}const i=(...c)=>{r.value&&o(...c)};return{isActive:a.readonly(r),pause:n,resume:s,eventFilter:i}}function he(o){return Array.isArray(o)?o:[o]}function je(o){return a.getCurrentInstance()}function Ue(o,e,t={}){const{eventFilter:r=Pe,...n}=t;return a.watch(o,xe(r,e),n)}function We(o,e,t={}){const{eventFilter:r,initialState:n="active",...s}=t,{eventFilter:i,pause:c,resume:l,isActive:g}=Be(r,{initialState:n});return{stop:Ue(o,e,{...s,eventFilter:i}),pause:c,resume:l,isActive:g}}const ze=We;function He(o,e=!0,t){je()?a.onMounted(o,t):e?o():a.nextTick(o)}function Je(o,e,t){return a.watch(o,e,{...t,immediate:!0})}function re(o,e,t){return a.watch(o,(n,s,i)=>{n&&e(n,s,i)},{...t,once:!1})}const K=ke?window:void 0;function Ge(o){var e;const t=a.toValue(o);return(e=t?.$el)!==null&&e!==void 0?e:t}function Q(...o){const e=(r,n,s,i)=>(r.addEventListener(n,s,i),()=>r.removeEventListener(n,s,i)),t=a.computed(()=>{const r=he(a.toValue(o[0])).filter(n=>n!=null);return r.every(n=>typeof n!="string")?r:void 0});return Je(()=>{var r,n;return[(r=(n=t.value)===null||n===void 0?void 0:n.map(s=>Ge(s)))!==null&&r!==void 0?r:[K].filter(s=>s!=null),he(a.toValue(t.value?o[1]:o[0])),he(a.unref(t.value?o[2]:o[1])),a.toValue(t.value?o[3]:o[2])]},([r,n,s,i],c,l)=>{if(!r?.length||!n?.length||!s?.length)return;const g=Me(i)?{...i}:i,w=r.flatMap(E=>n.flatMap(N=>s.map(D=>e(E,N,D,g))));l(()=>{w.forEach(E=>E())})},{flush:"post"})}const se=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},ie="__vueuse_ssr_handlers__",Ke=Ze();function Ze(){return ie in se||(se[ie]=se[ie]||{}),se[ie]}function qe(o,e){return Ke[o]||e}function Ye(o){return o==null?"any":o instanceof Set?"set":o instanceof Map?"map":o instanceof Date?"date":typeof o=="boolean"?"boolean":typeof o=="string"?"string":typeof o=="object"?"object":Number.isNaN(o)?"any":"number"}const Qe={boolean:{read:o=>o==="true",write:o=>String(o)},object:{read:o=>JSON.parse(o),write:o=>JSON.stringify(o)},number:{read:o=>Number.parseFloat(o),write:o=>String(o)},any:{read:o=>o,write:o=>String(o)},string:{read:o=>o,write:o=>String(o)},map:{read:o=>new Map(JSON.parse(o)),write:o=>JSON.stringify(Array.from(o.entries()))},set:{read:o=>new Set(JSON.parse(o)),write:o=>JSON.stringify(Array.from(o))},date:{read:o=>new Date(o),write:o=>o.toISOString()}},Ne="vueuse-storage";function Xe(o,e,t,r={}){var n;const{flush:s="pre",deep:i=!0,listenToStorageChanges:c=!0,writeDefaults:l=!0,mergeDefaults:g=!1,shallow:w,window:E=K,eventFilter:N,onError:D=d=>{console.error(d)},initOnMounted:V}=r,L=(w?a.shallowRef:a.ref)(e),P=a.computed(()=>a.toValue(o));if(!t)try{t=qe("getDefaultStorage",()=>K?.localStorage)()}catch(d){D(d)}if(!t)return L;const $=a.toValue(e),_=Ye($),b=(n=r.serializer)!==null&&n!==void 0?n:Qe[_],{pause:A,resume:O}=ze(L,d=>u(d),{flush:s,deep:i,eventFilter:N});a.watch(P,()=>R(),{flush:s});let I=!1;const y=d=>{V&&!I||R(d)},B=d=>{V&&!I||v(d)};E&&c&&(t instanceof Storage?Q(E,"storage",y,{passive:!0}):Q(E,Ne,B)),V?He(()=>{I=!0,R()}):R();function x(d,S){if(E){const T={key:P.value,oldValue:d,newValue:S,storageArea:t};E.dispatchEvent(t instanceof Storage?new StorageEvent("storage",T):new CustomEvent(Ne,{detail:T}))}}function u(d){try{const S=t.getItem(P.value);if(d==null)x(S,null),t.removeItem(P.value);else{const T=b.write(d);S!==T&&(t.setItem(P.value,T),x(S,T))}}catch(S){D(S)}}function f(d){const S=d?d.newValue:t.getItem(P.value);if(S==null)return l&&$!=null&&t.setItem(P.value,b.write($)),$;if(!d&&g){const T=b.read(S);return typeof g=="function"?g(T,$):_==="object"&&!Array.isArray(T)?{...$,...T}:T}else return typeof S!="string"?S:b.read(S)}function R(d){if(!(d&&d.storageArea!==t)){if(d&&d.key==null){L.value=$;return}if(!(d&&d.key!==P.value)){A();try{const S=b.write(L.value);(d===void 0||d?.newValue!==S)&&(L.value=f(d))}catch(S){D(S)}finally{d?a.nextTick(O):O()}}}}function v(d){R(d.detail)}return L}function et(o,e,t={}){const{window:r=K}=t;return Xe(o,e,r?.localStorage,t)}const tt={ctrl:"control",command:"meta",cmd:"meta",option:"alt",up:"arrowup",down:"arrowdown",left:"arrowleft",right:"arrowright"};function rt(o={}){const{reactive:e=!1,target:t=K,aliasMap:r=tt,passive:n=!0,onEventFired:s=_e}=o,i=a.reactive(new Set),c={toJSON(){return{}},current:i},l=e?a.reactive(c):c,g=new Set,w=new Map([["Meta",g],["Shift",new Set],["Alt",new Set]]),E=new Set;function N(_,b){_ in l&&(e?l[_]=b:l[_].value=b)}function D(){i.clear();for(const _ of E)N(_,!1)}function V(_,b,A){if(!(!_||typeof b.getModifierState!="function")){for(const[O,I]of w)if(b.getModifierState(O)){A.forEach(y=>I.add(y));break}}}function L(_,b){if(_)return;const A=`${b[0].toUpperCase()}${b.slice(1)}`,O=w.get(A);if(!["shift","alt"].includes(b)||!O)return;const I=Array.from(O),y=I.indexOf(b);I.forEach((B,x)=>{x>=y&&(i.delete(B),N(B,!1))}),O.clear()}function P(_,b){var A,O;const I=(A=_.key)===null||A===void 0?void 0:A.toLowerCase(),y=[(O=_.code)===null||O===void 0?void 0:O.toLowerCase(),I].filter(Boolean);if(I!==""){I&&(b?i.add(I):i.delete(I));for(const B of y)E.add(B),N(B,b);V(b,_,[...i,...y]),L(b,I),I==="meta"&&!b&&(g.forEach(B=>{i.delete(B),N(B,!1)}),g.clear())}}Q(t,"keydown",_=>(P(_,!0),s(_)),{passive:n}),Q(t,"keyup",_=>(P(_,!1),s(_)),{passive:n}),Q("blur",D,{passive:n}),Q("focus",D,{passive:n});const $=new Proxy(l,{get(_,b,A){if(typeof b!="string")return Reflect.get(_,b,A);if(b=b.toLowerCase(),b in r&&(b=r[b]),!(b in l))if(/[+_-]/.test(b)){const I=b.split(/[+_-]/g).map(y=>y.trim());l[b]=a.computed(()=>I.map(y=>a.toValue($[y])).every(Boolean))}else l[b]=a.shallowRef(!1);const O=Reflect.get(_,b,A);return e?a.toValue(O):O}});return $}function ge(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function ae(o){const e={type:o.type,clientId:o.clientId,timestamp:o.timestamp.toISOString()};return o.operation&&(e.operation={...o.operation,timestamp:o.operation.timestamp.toISOString()}),o.operations&&(e.operations=o.operations.map(t=>({...t,timestamp:t.timestamp.toISOString()}))),e}function ot(o){const e={type:o.type,clientId:o.clientId,timestamp:new Date(o.timestamp)};return o.operation&&(e.operation={...o.operation,timestamp:new Date(o.operation.timestamp)}),o.operations&&(e.operations=o.operations.map(t=>({...t,timestamp:new Date(t.timestamp)}))),e}const X=Ve("hst-operation-log",()=>{const o=a.ref({maxOperations:100,enableCrossTabSync:!0,autoSyncInterval:3e4,enablePersistence:!1,persistenceKeyPrefix:"stonecrop-ops"}),e=a.ref([]),t=a.ref(-1),r=a.ref(ge()),n=a.ref(!1),s=a.ref([]),i=a.ref(null),c=a.computed(()=>t.value<0?!1:e.value[t.value]?.reversible??!1),l=a.computed(()=>t.value<e.value.length-1),g=a.computed(()=>{let p=0;for(let h=t.value;h>=0&&e.value[h]?.reversible;h--)p++;return p}),w=a.computed(()=>e.value.length-1-t.value),E=a.computed(()=>({canUndo:c.value,canRedo:l.value,undoCount:g.value,redoCount:w.value,currentIndex:t.value}));function N(p){o.value={...o.value,...p},o.value.enablePersistence&&(k(),F()),o.value.enableCrossTabSync&&f()}function D(p,h="user"){const m={...p,id:ge(),timestamp:new Date,source:h,userId:o.value.userId};if(o.value.operationFilter&&!o.value.operationFilter(m))return m.id;if(n.value)return s.value.push(m),m.id;if(t.value<e.value.length-1&&(e.value=e.value.slice(0,t.value+1)),e.value.push(m),t.value++,o.value.maxOperations&&e.value.length>o.value.maxOperations){const M=e.value.length-o.value.maxOperations;e.value=e.value.slice(M),t.value-=M}return o.value.enableCrossTabSync&&R(m),m.id}function V(){n.value=!0,s.value=[],i.value=ge()}function L(p){if(!n.value||s.value.length===0)return n.value=!1,s.value=[],i.value=null,null;const h=i.value,m=s.value.every(W=>W.reversible),M={id:h,type:"batch",path:"",fieldname:"",beforeValue:null,afterValue:null,doctype:s.value[0]?.doctype||"",timestamp:new Date,source:"user",reversible:m,irreversibleReason:m?void 0:"Contains irreversible operations",childOperationIds:s.value.map(W=>W.id),metadata:{description:p}};s.value.forEach(W=>{W.parentOperationId=h}),e.value.push(...s.value,M),t.value=e.value.length-1,o.value.enableCrossTabSync&&v(s.value,M);const z=h;return n.value=!1,s.value=[],i.value=null,z}function P(){n.value=!1,s.value=[],i.value=null}function $(p){if(!c.value)return!1;const h=e.value[t.value];if(!h.reversible)return typeof console<"u"&&h.irreversibleReason&&console.warn("Cannot undo irreversible operation:",h.irreversibleReason),!1;try{if(h.type==="batch"&&h.childOperationIds)for(let m=h.childOperationIds.length-1;m>=0;m--){const M=h.childOperationIds[m],z=e.value.find(W=>W.id===M);z&&b(z,p)}else b(h,p);return t.value--,o.value.enableCrossTabSync&&d(h),!0}catch(m){return typeof console<"u"&&console.error("Undo failed:",m),!1}}function _(p){if(!l.value)return!1;const h=e.value[t.value+1];try{if(h.type==="batch"&&h.childOperationIds)for(const m of h.childOperationIds){const M=e.value.find(z=>z.id===m);M&&A(M,p)}else A(h,p);return t.value++,o.value.enableCrossTabSync&&S(h),!0}catch(m){return typeof console<"u"&&console.error("Redo failed:",m),!1}}function b(p,h){(p.type==="set"||p.type==="delete")&&h&&typeof h.set=="function"&&h.set(p.path,p.beforeValue,"undo")}function A(p,h){(p.type==="set"||p.type==="delete")&&h&&typeof h.set=="function"&&h.set(p.path,p.afterValue,"redo")}function O(){const p=e.value.filter(m=>m.reversible).length,h=e.value.map(m=>m.timestamp);return{operations:[...e.value],currentIndex:t.value,totalOperations:e.value.length,reversibleOperations:p,irreversibleOperations:e.value.length-p,oldestOperation:h.length>0?new Date(Math.min(...h.map(m=>m.getTime()))):void 0,newestOperation:h.length>0?new Date(Math.max(...h.map(m=>m.getTime()))):void 0}}function I(){e.value=[],t.value=-1}function y(p,h){return e.value.filter(m=>m.doctype===p&&(h===void 0||m.recordId===h))}function B(p,h){const m=e.value.find(M=>M.id===p);m&&(m.reversible=!1,m.irreversibleReason=h)}function x(p,h,m,M="success",z){const W={type:"action",path:m&&m.length>0?`${p}.${m[0]}`:p,fieldname:"",beforeValue:null,afterValue:null,doctype:p,recordId:m&&m.length>0?m[0]:void 0,reversible:!1,actionName:h,actionRecordIds:m,actionResult:M,actionError:z};return D(W)}let u=null;function f(){typeof window>"u"||!window.BroadcastChannel||(u=new BroadcastChannel("stonecrop-operation-log"),u.addEventListener("message",p=>{const h=p.data;if(!h||typeof h!="object")return;const m=ot(h);m.clientId!==r.value&&(m.type==="operation"&&m.operation?(e.value.push({...m.operation,source:"sync"}),t.value=e.value.length-1):m.type==="operation"&&m.operations&&(e.value.push(...m.operations.map(M=>({...M,source:"sync"}))),t.value=e.value.length-1))}))}function R(p){if(!u)return;const h={type:"operation",operation:p,clientId:r.value,timestamp:new Date};u.postMessage(ae(h))}function v(p,h){if(!u)return;const m={type:"operation",operations:[...p,h],clientId:r.value,timestamp:new Date};u.postMessage(ae(m))}function d(p){if(!u)return;const h={type:"undo",operation:p,clientId:r.value,timestamp:new Date};u.postMessage(ae(h))}function S(p){if(!u)return;const h={type:"redo",operation:p,clientId:r.value,timestamp:new Date};u.postMessage(ae(h))}const T=et("stonecrop-ops-operations",null,{serializer:{read:p=>{try{return JSON.parse(p)}catch{return null}},write:p=>p?JSON.stringify(p):""}});function k(){if(!(typeof window>"u"))try{const p=T.value;p&&Array.isArray(p.operations)&&(e.value=p.operations.map(h=>({...h,timestamp:new Date(h.timestamp)})),t.value=p.currentIndex??-1)}catch(p){typeof console<"u"&&console.error("Failed to load operations from persistence:",p)}}function j(){if(!(typeof window>"u"))try{T.value={operations:e.value.map(p=>({...p,timestamp:p.timestamp.toISOString()})),currentIndex:t.value}}catch(p){typeof console<"u"&&console.error("Failed to save operations to persistence:",p)}}function F(){a.watch([e,t],()=>{o.value.enablePersistence&&j()},{deep:!0})}return{operations:e,currentIndex:t,config:o,clientId:r,undoRedoState:E,canUndo:c,canRedo:l,undoCount:g,redoCount:w,configure:N,addOperation:D,startBatch:V,commitBatch:L,cancelBatch:P,undo:$,redo:_,clear:I,getOperationsFor:y,getSnapshot:O,markIrreversible:B,logAction:x}});class oe{static _root;options;doctypeActions=new Map;doctypeTransitions=new Map;fieldRollbackConfig=new Map;globalActions=new Map;globalTransitionActions=new Map;constructor(e={}){if(oe._root)return oe._root;oe._root=this,this.options={defaultTimeout:e.defaultTimeout??5e3,debug:e.debug??!1,enableRollback:e.enableRollback??!0,errorHandler:e.errorHandler}}registerAction(e,t){this.globalActions.set(e,t)}registerTransitionAction(e,t){this.globalTransitionActions.set(e,t)}setFieldRollback(e,t,r){this.fieldRollbackConfig.has(e)||this.fieldRollbackConfig.set(e,new Map),this.fieldRollbackConfig.get(e).set(t,r)}getFieldRollback(e,t){return this.fieldRollbackConfig.get(e)?.get(t)}registerDoctypeActions(e,t){if(!t)return;const r=new Map,n=new Map;if(typeof t.entrySeq=="function")t.entrySeq().forEach(([s,i])=>{this.categorizeAction(s,i,r,n)});else if(t instanceof Map)for(const[s,i]of t)this.categorizeAction(s,i,r,n);else t&&typeof t=="object"&&Object.entries(t).forEach(([s,i])=>{this.categorizeAction(s,i,r,n)});this.doctypeActions.set(e,r),this.doctypeTransitions.set(e,n)}categorizeAction(e,t,r,n){this.isTransitionKey(e)?n.set(e,t):r.set(e,t)}isTransitionKey(e){return/^[A-Z0-9_]+$/.test(e)&&e.length>0}async executeFieldTriggers(e,t={}){const{doctype:r,fieldname:n}=e,s=this.findFieldTriggers(r,n);if(s.length===0)return{path:e.path,actionResults:[],totalExecutionTime:0,allSucceeded:!0,stoppedOnError:!1,rolledBack:!1};const i=performance.now(),c=[];let l=!1,g=!1,w;const E=this.getFieldRollback(r,n),N=t.enableRollback??E??this.options.enableRollback;N&&e.store&&(w=this.captureSnapshot(e));for(const P of s)try{const $=await this.executeAction(P,e,t.timeout);if(c.push($),!$.success){l=!0;break}}catch($){const b={success:!1,error:$ instanceof Error?$:new Error(String($)),executionTime:0,action:P};c.push(b),l=!0;break}if(N&&l&&w&&e.store)try{this.restoreSnapshot(e,w),g=!0}catch(P){console.error("[FieldTriggers] Rollback failed:",P)}const D=performance.now()-i,V=c.filter(P=>!P.success);if(V.length>0&&this.options.errorHandler)for(const P of V)try{this.options.errorHandler(P.error,e,P.action)}catch($){console.error("[FieldTriggers] Error in global error handler:",$)}return{path:e.path,actionResults:c,totalExecutionTime:D,allSucceeded:c.every(P=>P.success),stoppedOnError:l,rolledBack:g,snapshot:this.options.debug&&N?w:void 0}}async executeTransitionActions(e,t={}){const{doctype:r,transition:n}=e,s=this.findTransitionActions(r,n);if(s.length===0)return[];const i=[];for(const l of s)try{const g=await this.executeTransitionAction(l,e,t.timeout);if(i.push(g),!g.success)break}catch(g){const E={success:!1,error:g instanceof Error?g:new Error(String(g)),executionTime:0,action:l,transition:n};i.push(E);break}const c=i.filter(l=>!l.success);if(c.length>0&&this.options.errorHandler)for(const l of c)try{this.options.errorHandler(l.error,e,l.action)}catch(g){console.error("[FieldTriggers] Error in global error handler:",g)}return i}findTransitionActions(e,t){const r=this.doctypeTransitions.get(e);return r?r.get(t)||[]:[]}async executeTransitionAction(e,t,r){const n=performance.now(),s=r??this.options.defaultTimeout;try{let i=this.globalTransitionActions.get(e);if(!i){const l=this.globalActions.get(e);l&&(i=l)}if(!i)throw new Error(`Transition action "${e}" not found in registry`);return await this.executeWithTimeout(i,t,s),{success:!0,executionTime:performance.now()-n,action:e,transition:t.transition}}catch(i){const c=performance.now()-n;return{success:!1,error:i instanceof Error?i:new Error(String(i)),executionTime:c,action:e,transition:t.transition}}}findFieldTriggers(e,t){const r=this.doctypeActions.get(e);if(!r)return[];const n=[];for(const[s,i]of r)this.isFieldTriggerKey(s,t)&&n.push(...i);return n}isFieldTriggerKey(e,t){return e===t?!0:e.includes(".")?this.matchFieldPattern(e,t):e.includes("*")?this.matchFieldPattern(e,t):!1}matchFieldPattern(e,t){const r=e.split("."),n=t.split(".");if(r.length!==n.length)return!1;for(let s=0;s<r.length;s++){const i=r[s],c=n[s];if(i!=="*"&&i!==c)return!1}return!0}async executeAction(e,t,r){const n=performance.now(),s=r??this.options.defaultTimeout;try{const i=this.globalActions.get(e);if(!i)throw new Error(`Action "${e}" not found in registry`);return await this.executeWithTimeout(i,t,s),{success:!0,executionTime:performance.now()-n,action:e}}catch(i){const c=performance.now()-n;return{success:!1,error:i instanceof Error?i:new Error(String(i)),executionTime:c,action:e}}}async executeWithTimeout(e,t,r){return new Promise((n,s)=>{const i=setTimeout(()=>{s(new Error(`Action timeout after ${r}ms`))},r);Promise.resolve(e(t)).then(c=>{clearTimeout(i),n(c)}).catch(c=>{clearTimeout(i),s(c)})})}captureSnapshot(e){if(!(!e.store||!e.doctype||!e.recordId))try{const t=`${e.doctype}.${e.recordId}`,r=e.store.get(t);return!r||typeof r!="object"?void 0:JSON.parse(JSON.stringify(r))}catch(t){this.options.debug&&console.warn("[FieldTriggers] Failed to capture snapshot:",t);return}}restoreSnapshot(e,t){if(!(!e.store||!e.doctype||!e.recordId||!t))try{const r=`${e.doctype}.${e.recordId}`;e.store.set(r,t),this.options.debug&&console.log(`[FieldTriggers] Rolled back ${r} to previous state`)}catch(r){throw console.error("[FieldTriggers] Failed to restore snapshot:",r),r}}}function H(o){return new oe(o)}function nt(o,e){H().registerAction(o,e)}function st(o,e){H().registerTransitionAction(o,e)}function it(o,e,t){H().setFieldRollback(o,e,t)}async function at(o,e,t){const r=H(),n={path:t?.path||(t?.recordId?`${o}.${t.recordId}`:o),fieldname:"",beforeValue:void 0,afterValue:void 0,operation:"set",doctype:o,recordId:t?.recordId,timestamp:new Date,transition:e,currentState:t?.currentState,targetState:t?.targetState,fsmContext:t?.fsmContext};return await r.executeTransitionActions(n)}function ct(o,e){if(o)try{X().markIrreversible(o,e)}catch{}}function Ie(){try{return X()}catch{return null}}class Z{static instance;static getInstance(){return Z.instance||(Z.instance=new Z),Z.instance}getRegistry(){if(typeof globalThis<"u"){const e=globalThis.Registry?._root;if(e)return e}if(typeof window<"u"){const e=window.Registry?._root;if(e)return e}if(typeof global<"u"&&global){const e=global.Registry?._root;if(e)return e}}getDoctypeMeta(e){const t=this.getRegistry();if(t&&typeof t=="object"&&"registry"in t)return t.registry[e]}}class ce{target;parentPath;rootNode;doctype;parentDoctype;hst;constructor(e,t,r="",n=null,s){return this.target=e,this.parentPath=r,this.rootNode=n||this,this.doctype=t,this.parentDoctype=s,this.hst=Z.getInstance(),new Proxy(this,{get(i,c){if(c in i)return i[c];const l=String(c);return i.getNode(l)},set(i,c,l){const g=String(c);return i.set(g,l),!0}})}get(e){return this.resolveValue(e)}getNode(e){const t=this.resolvePath(e),r=this.resolveValue(e),n=t.split(".");let s=this.doctype;return this.doctype==="StonecropStore"&&n.length>=1&&(s=n[0]),typeof r=="object"&&r!==null&&!this.isPrimitive(r)?new ce(r,s,t,this.rootNode,this.parentDoctype):new ce(r,s,t,this.rootNode,this.parentDoctype)}set(e,t,r="user"){const n=this.resolvePath(e),s=this.has(e)?this.get(e):void 0;if(r!=="undo"&&r!=="redo"){const i=Ie();if(i&&typeof i.addOperation=="function"){const c=n.split("."),l=this.doctype==="StonecropStore"&&c.length>=1?c[0]:this.doctype,g=c.length>=2?c[1]:void 0,w=c.slice(2).join(".")||c[c.length-1],N=t===void 0&&s!==void 0?"delete":"set";i.addOperation({type:N,path:n,fieldname:w,beforeValue:s,afterValue:t,doctype:l,recordId:g,reversible:!0},r)}}this.updateValue(e,t),this.triggerFieldActions(n,s,t)}has(e){try{if(e==="")return!0;const t=this.parsePath(e);let r=this.target;for(let n=0;n<t.length;n++){const s=t[n];if(r==null)return!1;if(n===t.length-1)return this.isImmutable(r)?r.has(s):this.isPiniaStore(r)&&r.$state&&s in r.$state||s in r;r=this.getProperty(r,s)}return!1}catch{return!1}}getParent(){if(!this.parentPath)return null;const t=this.parentPath.split(".").slice(0,-1).join(".");return t===""?this.rootNode:this.rootNode.getNode(t)}getRoot(){return this.rootNode}getPath(){return this.parentPath}getDepth(){return this.parentPath?this.parentPath.split(".").length:0}getBreadcrumbs(){return this.parentPath?this.parentPath.split("."):[]}async triggerTransition(e,t){const r=H(),n=this.parentPath.split(".");let s=this.doctype,i;this.doctype==="StonecropStore"&&n.length>=1&&(s=n[0]),n.length>=2&&(i=n[1]);const c={path:this.parentPath,fieldname:"",beforeValue:void 0,afterValue:void 0,operation:"set",doctype:s,recordId:i,timestamp:new Date,store:this.rootNode||void 0,transition:e,currentState:t?.currentState,targetState:t?.targetState,fsmContext:t?.fsmContext},l=Ie();return l&&typeof l.addOperation=="function"&&l.addOperation({type:"transition",path:this.parentPath,fieldname:e,beforeValue:t?.currentState,afterValue:t?.targetState,doctype:s,recordId:i,reversible:!1,metadata:{transition:e,currentState:t?.currentState,targetState:t?.targetState,fsmContext:t?.fsmContext}},"user"),await r.executeTransitionActions(c)}resolvePath(e){return e===""?this.parentPath:this.parentPath?`${this.parentPath}.${e}`:e}resolveValue(e){if(e==="")return this.target;const t=this.parsePath(e);let r=this.target;for(const n of t){if(r==null)return;r=this.getProperty(r,n)}return r}updateValue(e,t){if(e==="")throw new Error("Cannot set value on empty path");const r=this.parsePath(e),n=r.pop();let s=this.target;for(const i of r)if(s=this.getProperty(s,i),s==null)throw new Error(`Cannot set property on null/undefined path: ${e}`);this.setProperty(s,n,t)}getProperty(e,t){return this.isImmutable(e)?e.get(t):this.isVueReactive(e)?e[t]:this.isPiniaStore(e)?e.$state?.[t]??e[t]:e[t]}setProperty(e,t,r){if(this.isImmutable(e))throw new Error("Cannot directly mutate immutable objects. Use immutable update methods instead.");if(this.isPiniaStore(e)){e.$patch?e.$patch({[t]:r}):e[t]=r;return}e[t]=r}async triggerFieldActions(e,t,r){try{if(!e||typeof e!="string")return;const n=e.split(".");if(n.length<3)return;const s=H(),i=n.slice(2).join(".")||n[n.length-1];let c=this.doctype;this.doctype==="StonecropStore"&&n.length>=1&&(c=n[0]);let l;n.length>=2&&(l=n[1]);const g={path:e,fieldname:i,beforeValue:t,afterValue:r,operation:"set",doctype:c,recordId:l,timestamp:new Date,store:this.rootNode||void 0};await s.executeFieldTriggers(g)}catch(n){n instanceof Error&&console.warn("Field trigger error:",n.message)}}isVueReactive(e){return e&&typeof e=="object"&&"__v_isReactive"in e&&e.__v_isReactive===!0}isPiniaStore(e){return e&&typeof e=="object"&&("$state"in e||"$patch"in e||"$id"in e)}isImmutable(e){if(!e||typeof e!="object")return!1;const t="get"in e&&typeof e.get=="function",r="set"in e&&typeof e.set=="function",n="has"in e&&typeof e.has=="function",s="__ownerID"in e||"_map"in e||"_list"in e||"_origin"in e||"_capacity"in e||"_defaultValues"in e||"_tail"in e||"_root"in e||"size"in e&&t&&r;let i;try{const l=e;if("constructor"in l&&l.constructor&&typeof l.constructor=="object"&&"name"in l.constructor){const g=l.constructor.name;i=typeof g=="string"?g:void 0}}catch{i=void 0}const c=i&&(i.includes("Map")||i.includes("List")||i.includes("Set")||i.includes("Stack")||i.includes("Seq"))&&(t||r);return!!(t&&r&&n&&s||t&&r&&c)}isPrimitive(e){return e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="function"||typeof e=="symbol"||typeof e=="bigint"}parsePath(e){return e?e.split(".").filter(t=>t.length>0):[]}}function Te(o,e,t){return new ce(o,e,"",null,t)}class ye{hstStore;_operationLogStore;_operationLogConfig;registry;constructor(e,t){this.registry=e,this._operationLogConfig=t,this.initializeHSTStore(),this.setupRegistrySync()}getOperationLogStore(){return this._operationLogStore||(this._operationLogStore=X(),this._operationLogConfig&&this._operationLogStore.configure(this._operationLogConfig)),this._operationLogStore}initializeHSTStore(){const e={};Object.keys(this.registry.registry).forEach(t=>{e[t]={}}),this.hstStore=Te(e,"StonecropStore")}setupRegistrySync(){const e=this.registry.addDoctype.bind(this.registry);this.registry.addDoctype=t=>{e(t),this.hstStore.has(t.slug)||this.hstStore.set(t.slug,{})}}records(e){const t=typeof e=="string"?e:e.slug;return this.ensureDoctypeExists(t),this.hstStore.getNode(t)}addRecord(e,t,r){const n=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(n),this.hstStore.set(`${n}.${t}`,r)}getRecordById(e,t){const r=typeof e=="string"?e:e.slug;if(this.ensureDoctypeExists(r),!(!this.hstStore.has(`${r}.${t}`)||this.hstStore.get(`${r}.${t}`)===void 0))return this.hstStore.getNode(`${r}.${t}`)}removeRecord(e,t){const r=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(r),this.hstStore.has(`${r}.${t}`)&&this.hstStore.set(`${r}.${t}`,void 0)}getRecordIds(e){const t=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(t);const r=this.hstStore.get(t);return!r||typeof r!="object"?[]:Object.keys(r).filter(n=>r[n]!==void 0)}clearRecords(e){const t=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(t),this.getRecordIds(t).forEach(n=>{this.hstStore.set(`${t}.${n}`,void 0)})}setup(e){this.ensureDoctypeExists(e.slug)}runAction(e,t,r){const s=this.registry.registry[e.slug]?.actions?.get(t),i=Array.isArray(r)?r.filter(w=>typeof w=="string"):void 0,c=this.getOperationLogStore();let l="success",g;try{s&&s.length>0&&s.forEach(w=>{try{new Function("args",w)(r)}catch(E){throw l="failure",g=E instanceof Error?E.message:"Unknown error",E}})}catch{}finally{c.logAction(e.doctype,t,i,l,g)}}async getRecords(e){(await(await fetch(`/${e.slug}`)).json()).forEach(n=>{n.id&&this.addRecord(e,n.id,n)})}async getRecord(e,t){const n=await(await fetch(`/${e.slug}/${t}`)).json();this.addRecord(e,t,n)}ensureDoctypeExists(e){this.hstStore.has(e)||this.hstStore.set(e,{})}async getMeta(e){if(!this.registry.getMeta)throw new Error("No getMeta function provided to Registry");return await this.registry.getMeta(e)}getStore(){return this.hstStore}}function lt(o){o||(o={});const e=o.registry||a.inject("$registry"),t=a.inject("$stonecrop"),r=a.ref(),n=a.ref(),s=a.ref({}),i=a.ref(),c=a.ref(),l=a.ref([]),g=a.ref(-1),w=a.computed(()=>r.value?.getOperationLogStore().canUndo??!1),E=a.computed(()=>r.value?.getOperationLogStore().canRedo??!1),N=a.computed(()=>r.value?.getOperationLogStore().undoCount??0),D=a.computed(()=>r.value?.getOperationLogStore().redoCount??0),V=a.computed(()=>r.value?.getOperationLogStore().undoRedoState??{canUndo:!1,canRedo:!1,undoCount:0,redoCount:0,currentIndex:-1}),L=v=>r.value?.getOperationLogStore().undo(v)??!1,P=v=>r.value?.getOperationLogStore().redo(v)??!1,$=()=>{r.value?.getOperationLogStore().startBatch()},_=v=>r.value?.getOperationLogStore().commitBatch(v)??null,b=()=>{r.value?.getOperationLogStore().cancelBatch()},A=()=>{r.value?.getOperationLogStore().clear()},O=(v,d)=>r.value?.getOperationLogStore().getOperationsFor(v,d)??[],I=()=>r.value?.getOperationLogStore().getSnapshot()??{operations:[],currentIndex:-1,totalOperations:0,reversibleOperations:0,irreversibleOperations:0},y=(v,d)=>{r.value?.getOperationLogStore().markIrreversible(v,d)},B=(v,d,S,T="success",k)=>r.value?.getOperationLogStore().logAction(v,d,S,T,k)??"",x=v=>{r.value?.getOperationLogStore().configure(v)};a.onMounted(async()=>{if(e){r.value=t||new ye(e);try{const v=r.value.getOperationLogStore(),d=Re(v);l.value=d.operations.value,g.value=d.currentIndex.value,a.watch(()=>d.operations.value,S=>{l.value=S}),a.watch(()=>d.currentIndex.value,S=>{g.value=S})}catch{}if(!o.doctype&&e.router){const v=e.router.currentRoute.value;if(!v.path)return;const d=v.path.split("/").filter(T=>T.length>0),S=d[1]?.toLowerCase();if(d.length>0){const T={path:v.path,segments:d},k=await e.getMeta?.(T);if(k){if(e.addDoctype(k),r.value.setup(k),i.value=k,c.value=S,n.value=r.value.getStore(),S&&S!=="new"){const j=r.value.getRecordById(k,S);if(j)s.value=j.get("")||{};else try{await r.value.getRecord(k,S);const F=r.value.getRecordById(k,S);F&&(s.value=F.get("")||{})}catch{s.value=le(k)}}else s.value=le(k);n.value&&De(k,S||"new",s,n.value),r.value.runAction(k,"load",S?[S]:void 0)}}}if(o.doctype){n.value=r.value.getStore();const v=o.doctype,d=o.recordId;if(d&&d!=="new"){const S=r.value.getRecordById(v,d);if(S)s.value=S.get("")||{};else try{await r.value.getRecord(v,d);const T=r.value.getRecordById(v,d);T&&(s.value=T.get("")||{})}catch{s.value=le(v)}}else s.value=le(v);n.value&&De(v,d||"new",s,n.value)}}});const u=(v,d)=>{const S=o.doctype||i.value;if(!S)return"";const T=d||o.recordId||c.value||"new";return`${S.slug}.${T}.${v}`},f=v=>{const d=o.doctype||i.value;if(!(!n.value||!r.value||!d))try{const S=v.path.split(".");if(S.length>=2){const j=S[0],F=S[1];if(n.value.has(`${j}.${F}`)||r.value.addRecord(d,F,{...s.value}),S.length>3){const p=`${j}.${F}`,h=S.slice(2);let m=p;for(let M=0;M<h.length-1;M++)if(m+=`.${h[M]}`,!n.value.has(m)){const z=h[M+1],W=!isNaN(Number(z));n.value.set(m,W?[]:{})}}}n.value.set(v.path,v.value);const T=v.fieldname.split("."),k={...s.value};T.length===1?k[T[0]]=v.value:ut(k,T,v.value),s.value=k}catch{}};(o.doctype||e?.router)&&(a.provide("hstPathProvider",u),a.provide("hstChangeHandler",f));const R={operations:l,currentIndex:g,undoRedoState:V,canUndo:w,canRedo:E,undoCount:N,redoCount:D,undo:L,redo:P,startBatch:$,commitBatch:_,cancelBatch:b,clear:A,getOperationsFor:O,getSnapshot:I,markIrreversible:y,logAction:B,configure:x};return o.doctype?{stonecrop:r,operationLog:R,provideHSTPath:u,handleHSTChange:f,hstStore:n,formData:s}:!o.doctype&&e?.router?{stonecrop:r,operationLog:R,provideHSTPath:u,handleHSTChange:f,hstStore:n,formData:s}:{stonecrop:r,operationLog:R}}function le(o){const e={};return o.schema&&o.schema.forEach(t=>{switch("fieldtype"in t?t.fieldtype:"Data"){case"Data":case"Text":e[t.fieldname]="";break;case"Check":e[t.fieldname]=!1;break;case"Int":case"Float":e[t.fieldname]=0;break;case"Table":e[t.fieldname]=[];break;case"JSON":e[t.fieldname]={};break;default:e[t.fieldname]=null}}),e}function De(o,e,t,r){a.watch(t,n=>{const s=`${o.slug}.${e}`;Object.keys(n).forEach(i=>{const c=`${s}.${i}`;try{r.set(c,n[i])}catch{}})},{deep:!0})}function ut(o,e,t){let r=o;for(let s=0;s<e.length-1;s++){const i=e[s];(!(i in r)||typeof r[i]!="object")&&(r[i]=isNaN(Number(e[s+1]))?{}:[]),r=r[i]}const n=e[e.length-1];r[n]=t}function me(o){const t=a.inject("$operationLogStore",void 0)||X();o&&t.configure(o);const{operations:r,currentIndex:n,undoRedoState:s,canUndo:i,canRedo:c,undoCount:l,redoCount:g}=Re(t);function w(O){return t.undo(O)}function E(O){return t.redo(O)}function N(){t.startBatch()}function D(O){return t.commitBatch(O)}function V(){t.cancelBatch()}function L(){t.clear()}function P(O,I){return t.getOperationsFor(O,I)}function $(){return t.getSnapshot()}function _(O,I){t.markIrreversible(O,I)}function b(O,I,y,B="success",x){return t.logAction(O,I,y,B,x)}function A(O){t.configure(O)}return{operations:r,currentIndex:n,undoRedoState:s,canUndo:i,canRedo:c,undoCount:l,redoCount:g,undo:w,redo:E,startBatch:N,commitBatch:D,cancelBatch:V,clear:L,getOperationsFor:P,getSnapshot:$,markIrreversible:_,logAction:b,configure:A}}function ft(o,e=!0){if(!e)return;const{undo:t,redo:r,canUndo:n,canRedo:s}=me(),i=rt();re(i["Ctrl+Z"],()=>{n.value&&t(o)}),re(i["Meta+Z"],()=>{n.value&&t(o)}),re(i["Ctrl+Shift+Z"],()=>{s.value&&r(o)}),re(i["Meta+Shift+Z"],()=>{s.value&&r(o)}),re(i["Ctrl+Y"],()=>{s.value&&r(o)})}async function dt(o,e){const{startBatch:t,commitBatch:r,cancelBatch:n}=me();t();try{return await o(),r(e)}catch(s){throw n(),s}}class pt{doctype;schema;workflow;actions;component;constructor(e,t,r,n,s){this.doctype=e,this.schema=t,this.workflow=r,this.actions=n,this.component=s}get slug(){return this.doctype.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}}class ee{static _root;name;registry;router;constructor(e,t){if(ee._root)return ee._root;ee._root=this,this.name="Registry",this.registry={},this.router=e,this.getMeta=t}getMeta;addDoctype(e){e.doctype in Object.keys(this.registry)||(this.registry[e.slug]=e);const t=H();t.registerDoctypeActions(e.doctype,e.actions),e.slug!==e.doctype&&t.registerDoctypeActions(e.slug,e.actions),e.component&&this.router&&!this.router.hasRoute(e.doctype)&&this.router.addRoute({path:`/${e.slug}`,name:e.slug,component:e.component})}}async function ht(o,e,t){await a.nextTick();try{await t(o,e)}catch{}}const gt={install:(o,e)=>{const t=o.config.globalProperties.$router,r=e?.router,n=t||r;!t&&r&&o.use(r);const s=new ee(n,e?.getMeta);o.provide("$registry",s),o.config.globalProperties.$registry=s;const i=new ye(s);o.provide("$stonecrop",i),o.config.globalProperties.$stonecrop=i;try{const c=o.config.globalProperties.$pinia;if(c){const l=X(c);o.provide("$operationLogStore",l),o.config.globalProperties.$operationLogStore=l}}catch(c){console.warn("Pinia not available - operation log features will be disabled:",c)}if(e?.components)for(const[c,l]of Object.entries(e.components))o.component(c,l);e?.autoInitializeRouter&&e.onRouterInitialized&&ht(s,i,e.onRouterInitialized)}};C.DoctypeMeta=pt,C.HST=Z,C.Registry=ee,C.Stonecrop=ye,C.createHST=Te,C.default=gt,C.getGlobalTriggerEngine=H,C.markOperationIrreversible=ct,C.registerGlobalAction=nt,C.registerTransitionAction=st,C.setFieldRollback=it,C.triggerTransition=at,C.useOperationLog=me,C.useOperationLogStore=X,C.useStonecrop=lt,C.useUndoRedoShortcuts=ft,C.withBatch=dt,Object.defineProperties(C,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
5
+ This will fail in production.`);s=q,s._s.has(n)||(o?pe(n,e,r,s):Re(n,r,s),process.env.NODE_ENV!=="production"&&(i._pinia=s));const g=s._s.get(n);if(process.env.NODE_ENV!=="production"&&c){const y="__hot:"+n,E=o?pe(y,e,r,s,!0):Re(y,W({},r),s,!0);c._hotUpdate(E),delete s.state.value[y],s._s.delete(y)}if(process.env.NODE_ENV!=="production"&&Z){const y=a.getCurrentInstance();if(y&&y.proxy&&!c){const E=y.proxy,P="_pStores"in E?E._pStores:E._pStores={};P[n]=g}}return g}return i.$id=n,i}function Oe(n){const e=a.toRaw(n),t={};for(const r in e){const o=e[r];o.effect?t[r]=a.computed({get:()=>n[r],set(i){n[r]=i}}):(a.isRef(o)||a.isReactive(o))&&(t[r]=a.toRef(n,r))}return t}const Me=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const xe=Object.prototype.toString,je=n=>xe.call(n)==="[object Object]",Pe=()=>{};function Be(...n){if(n.length!==1)return a.toRef(...n);const e=n[0];return typeof e=="function"?a.readonly(a.customRef(()=>({get:e,set:Pe}))):a.ref(e)}function We(n,e){function t(...r){return new Promise((o,i)=>{Promise.resolve(n(()=>e.apply(this,r),{fn:e,thisArg:this,args:r})).then(o).catch(i)})}return t}const Ne=n=>n();function Ue(n=Ne,e={}){const{initialState:t="active"}=e,r=Be(t==="active");function o(){r.value=!1}function i(){r.value=!0}const s=(...c)=>{r.value&&n(...c)};return{isActive:a.readonly(r),pause:o,resume:i,eventFilter:s}}function he(n){return Array.isArray(n)?n:[n]}function ze(n){return a.getCurrentInstance()}function He(n,e,t={}){const{eventFilter:r=Ne,...o}=t;return a.watch(n,We(r,e),o)}function qe(n,e,t={}){const{eventFilter:r,initialState:o="active",...i}=t,{eventFilter:s,pause:c,resume:l,isActive:g}=Ue(r,{initialState:o});return{stop:He(n,e,{...i,eventFilter:s}),pause:c,resume:l,isActive:g}}const Je=qe;function Ge(n,e=!0,t){ze()?a.onMounted(n,t):e?n():a.nextTick(n)}function Ke(n,e,t){return a.watch(n,e,{...t,immediate:!0})}function re(n,e,t){return a.watch(n,(o,i,s)=>{o&&e(o,i,s)},{...t,once:!1})}const G=Me?window:void 0;function Ze(n){var e;const t=a.toValue(n);return(e=t?.$el)!==null&&e!==void 0?e:t}function Q(...n){const e=(r,o,i,s)=>(r.addEventListener(o,i,s),()=>r.removeEventListener(o,i,s)),t=a.computed(()=>{const r=he(a.toValue(n[0])).filter(o=>o!=null);return r.every(o=>typeof o!="string")?r:void 0});return Ke(()=>{var r,o;return[(r=(o=t.value)===null||o===void 0?void 0:o.map(i=>Ze(i)))!==null&&r!==void 0?r:[G].filter(i=>i!=null),he(a.toValue(t.value?n[1]:n[0])),he(a.unref(t.value?n[2]:n[1])),a.toValue(t.value?n[3]:n[2])]},([r,o,i,s],c,l)=>{if(!r?.length||!o?.length||!i?.length)return;const g=je(s)?{...s}:s,y=r.flatMap(E=>o.flatMap(P=>i.map(T=>e(E,P,T,g))));l(()=>{y.forEach(E=>E())})},{flush:"post"})}const ie=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},se="__vueuse_ssr_handlers__",Ye=Qe();function Qe(){return se in ie||(ie[se]=ie[se]||{}),ie[se]}function Xe(n,e){return Ye[n]||e}function et(n){return n==null?"any":n instanceof Set?"set":n instanceof Map?"map":n instanceof Date?"date":typeof n=="boolean"?"boolean":typeof n=="string"?"string":typeof n=="object"?"object":Number.isNaN(n)?"any":"number"}const tt={boolean:{read:n=>n==="true",write:n=>String(n)},object:{read:n=>JSON.parse(n),write:n=>JSON.stringify(n)},number:{read:n=>Number.parseFloat(n),write:n=>String(n)},any:{read:n=>n,write:n=>String(n)},string:{read:n=>n,write:n=>String(n)},map:{read:n=>new Map(JSON.parse(n)),write:n=>JSON.stringify(Array.from(n.entries()))},set:{read:n=>new Set(JSON.parse(n)),write:n=>JSON.stringify(Array.from(n))},date:{read:n=>new Date(n),write:n=>n.toISOString()}},_e="vueuse-storage";function rt(n,e,t,r={}){var o;const{flush:i="pre",deep:s=!0,listenToStorageChanges:c=!0,writeDefaults:l=!0,mergeDefaults:g=!1,shallow:y,window:E=G,eventFilter:P,onError:T=d=>{console.error(d)},initOnMounted:k}=r,M=(y?a.shallowRef:a.ref)(e),_=a.computed(()=>a.toValue(n));if(!t)try{t=Xe("getDefaultStorage",()=>G?.localStorage)()}catch(d){T(d)}if(!t)return M;const $=a.toValue(e),N=et($),w=(o=r.serializer)!==null&&o!==void 0?o:tt[N],{pause:C,resume:R}=Je(M,d=>u(d),{flush:i,deep:s,eventFilter:P});a.watch(_,()=>O(),{flush:i});let A=!1;const m=d=>{k&&!A||O(d)},j=d=>{k&&!A||S(d)};E&&c&&(t instanceof Storage?Q(E,"storage",m,{passive:!0}):Q(E,_e,j)),k?Ge(()=>{A=!0,O()}):O();function x(d,b){if(E){const I={key:_.value,oldValue:d,newValue:b,storageArea:t};E.dispatchEvent(t instanceof Storage?new StorageEvent("storage",I):new CustomEvent(_e,{detail:I}))}}function u(d){try{const b=t.getItem(_.value);if(d==null)x(b,null),t.removeItem(_.value);else{const I=w.write(d);b!==I&&(t.setItem(_.value,I),x(b,I))}}catch(b){T(b)}}function f(d){const b=d?d.newValue:t.getItem(_.value);if(b==null)return l&&$!=null&&t.setItem(_.value,w.write($)),$;if(!d&&g){const I=w.read(b);return typeof g=="function"?g(I,$):N==="object"&&!Array.isArray(I)?{...$,...I}:I}else return typeof b!="string"?b:w.read(b)}function O(d){if(!(d&&d.storageArea!==t)){if(d&&d.key==null){M.value=$;return}if(!(d&&d.key!==_.value)){C();try{const b=w.write(M.value);(d===void 0||d?.newValue!==b)&&(M.value=f(d))}catch(b){T(b)}finally{d?a.nextTick(R):R()}}}}function S(d){O(d.detail)}return M}function nt(n,e,t={}){const{window:r=G}=t;return rt(n,e,r?.localStorage,t)}const ot={ctrl:"control",command:"meta",cmd:"meta",option:"alt",up:"arrowup",down:"arrowdown",left:"arrowleft",right:"arrowright"};function it(n={}){const{reactive:e=!1,target:t=G,aliasMap:r=ot,passive:o=!0,onEventFired:i=Pe}=n,s=a.reactive(new Set),c={toJSON(){return{}},current:s},l=e?a.reactive(c):c,g=new Set,y=new Map([["Meta",g],["Shift",new Set],["Alt",new Set]]),E=new Set;function P(N,w){N in l&&(e?l[N]=w:l[N].value=w)}function T(){s.clear();for(const N of E)P(N,!1)}function k(N,w,C){if(!(!N||typeof w.getModifierState!="function")){for(const[R,A]of y)if(w.getModifierState(R)){C.forEach(m=>A.add(m));break}}}function M(N,w){if(N)return;const C=`${w[0].toUpperCase()}${w.slice(1)}`,R=y.get(C);if(!["shift","alt"].includes(w)||!R)return;const A=Array.from(R),m=A.indexOf(w);A.forEach((j,x)=>{x>=m&&(s.delete(j),P(j,!1))}),R.clear()}function _(N,w){var C,R;const A=(C=N.key)===null||C===void 0?void 0:C.toLowerCase(),m=[(R=N.code)===null||R===void 0?void 0:R.toLowerCase(),A].filter(Boolean);if(A!==""){A&&(w?s.add(A):s.delete(A));for(const j of m)E.add(j),P(j,w);k(w,N,[...s,...m]),M(w,A),A==="meta"&&!w&&(g.forEach(j=>{s.delete(j),P(j,!1)}),g.clear())}}Q(t,"keydown",N=>(_(N,!0),i(N)),{passive:o}),Q(t,"keyup",N=>(_(N,!1),i(N)),{passive:o}),Q("blur",T,{passive:o}),Q("focus",T,{passive:o});const $=new Proxy(l,{get(N,w,C){if(typeof w!="string")return Reflect.get(N,w,C);if(w=w.toLowerCase(),w in r&&(w=r[w]),!(w in l))if(/[+_-]/.test(w)){const A=w.split(/[+_-]/g).map(m=>m.trim());l[w]=a.computed(()=>A.map(m=>a.toValue($[m])).every(Boolean))}else l[w]=a.shallowRef(!1);const R=Reflect.get(N,w,C);return e?a.toValue(R):R}});return $}function ge(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function ae(n){const e={type:n.type,clientId:n.clientId,timestamp:n.timestamp.toISOString()};return n.operation&&(e.operation={...n.operation,timestamp:n.operation.timestamp.toISOString()}),n.operations&&(e.operations=n.operations.map(t=>({...t,timestamp:t.timestamp.toISOString()}))),e}function st(n){const e={type:n.type,clientId:n.clientId,timestamp:new Date(n.timestamp)};return n.operation&&(e.operation={...n.operation,timestamp:new Date(n.operation.timestamp)}),n.operations&&(e.operations=n.operations.map(t=>({...t,timestamp:new Date(t.timestamp)}))),e}const X=Le("hst-operation-log",()=>{const n=a.ref({maxOperations:100,enableCrossTabSync:!0,autoSyncInterval:3e4,enablePersistence:!1,persistenceKeyPrefix:"stonecrop-ops"}),e=a.ref([]),t=a.ref(-1),r=a.ref(ge()),o=a.ref(!1),i=a.ref([]),s=a.ref(null),c=a.computed(()=>t.value<0?!1:e.value[t.value]?.reversible??!1),l=a.computed(()=>t.value<e.value.length-1),g=a.computed(()=>{let p=0;for(let h=t.value;h>=0&&e.value[h]?.reversible;h--)p++;return p}),y=a.computed(()=>e.value.length-1-t.value),E=a.computed(()=>({canUndo:c.value,canRedo:l.value,undoCount:g.value,redoCount:y.value,currentIndex:t.value}));function P(p){n.value={...n.value,...p},n.value.enablePersistence&&(V(),F()),n.value.enableCrossTabSync&&f()}function T(p,h="user"){const v={...p,id:ge(),timestamp:new Date,source:h,userId:n.value.userId};if(n.value.operationFilter&&!n.value.operationFilter(v))return v.id;if(o.value)return i.value.push(v),v.id;if(t.value<e.value.length-1&&(e.value=e.value.slice(0,t.value+1)),e.value.push(v),t.value++,n.value.maxOperations&&e.value.length>n.value.maxOperations){const L=e.value.length-n.value.maxOperations;e.value=e.value.slice(L),t.value-=L}return n.value.enableCrossTabSync&&O(v),v.id}function k(){o.value=!0,i.value=[],s.value=ge()}function M(p){if(!o.value||i.value.length===0)return o.value=!1,i.value=[],s.value=null,null;const h=s.value,v=i.value.every(U=>U.reversible),L={id:h,type:"batch",path:"",fieldname:"",beforeValue:null,afterValue:null,doctype:i.value[0]?.doctype||"",timestamp:new Date,source:"user",reversible:v,irreversibleReason:v?void 0:"Contains irreversible operations",childOperationIds:i.value.map(U=>U.id),metadata:{description:p}};i.value.forEach(U=>{U.parentOperationId=h}),e.value.push(...i.value,L),t.value=e.value.length-1,n.value.enableCrossTabSync&&S(i.value,L);const z=h;return o.value=!1,i.value=[],s.value=null,z}function _(){o.value=!1,i.value=[],s.value=null}function $(p){if(!c.value)return!1;const h=e.value[t.value];if(!h.reversible)return typeof console<"u"&&h.irreversibleReason&&console.warn("Cannot undo irreversible operation:",h.irreversibleReason),!1;try{if(h.type==="batch"&&h.childOperationIds)for(let v=h.childOperationIds.length-1;v>=0;v--){const L=h.childOperationIds[v],z=e.value.find(U=>U.id===L);z&&w(z,p)}else w(h,p);return t.value--,n.value.enableCrossTabSync&&d(h),!0}catch(v){return typeof console<"u"&&console.error("Undo failed:",v),!1}}function N(p){if(!l.value)return!1;const h=e.value[t.value+1];try{if(h.type==="batch"&&h.childOperationIds)for(const v of h.childOperationIds){const L=e.value.find(z=>z.id===v);L&&C(L,p)}else C(h,p);return t.value++,n.value.enableCrossTabSync&&b(h),!0}catch(v){return typeof console<"u"&&console.error("Redo failed:",v),!1}}function w(p,h){(p.type==="set"||p.type==="delete")&&h&&typeof h.set=="function"&&h.set(p.path,p.beforeValue,"undo")}function C(p,h){(p.type==="set"||p.type==="delete")&&h&&typeof h.set=="function"&&h.set(p.path,p.afterValue,"redo")}function R(){const p=e.value.filter(v=>v.reversible).length,h=e.value.map(v=>v.timestamp);return{operations:[...e.value],currentIndex:t.value,totalOperations:e.value.length,reversibleOperations:p,irreversibleOperations:e.value.length-p,oldestOperation:h.length>0?new Date(Math.min(...h.map(v=>v.getTime()))):void 0,newestOperation:h.length>0?new Date(Math.max(...h.map(v=>v.getTime()))):void 0}}function A(){e.value=[],t.value=-1}function m(p,h){return e.value.filter(v=>v.doctype===p&&(h===void 0||v.recordId===h))}function j(p,h){const v=e.value.find(L=>L.id===p);v&&(v.reversible=!1,v.irreversibleReason=h)}function x(p,h,v,L="success",z){const U={type:"action",path:v&&v.length>0?`${p}.${v[0]}`:p,fieldname:"",beforeValue:null,afterValue:null,doctype:p,recordId:v&&v.length>0?v[0]:void 0,reversible:!1,actionName:h,actionRecordIds:v,actionResult:L,actionError:z};return T(U)}let u=null;function f(){typeof window>"u"||!window.BroadcastChannel||(u=new BroadcastChannel("stonecrop-operation-log"),u.addEventListener("message",p=>{const h=p.data;if(!h||typeof h!="object")return;const v=st(h);v.clientId!==r.value&&(v.type==="operation"&&v.operation?(e.value.push({...v.operation,source:"sync"}),t.value=e.value.length-1):v.type==="operation"&&v.operations&&(e.value.push(...v.operations.map(L=>({...L,source:"sync"}))),t.value=e.value.length-1))}))}function O(p){if(!u)return;const h={type:"operation",operation:p,clientId:r.value,timestamp:new Date};u.postMessage(ae(h))}function S(p,h){if(!u)return;const v={type:"operation",operations:[...p,h],clientId:r.value,timestamp:new Date};u.postMessage(ae(v))}function d(p){if(!u)return;const h={type:"undo",operation:p,clientId:r.value,timestamp:new Date};u.postMessage(ae(h))}function b(p){if(!u)return;const h={type:"redo",operation:p,clientId:r.value,timestamp:new Date};u.postMessage(ae(h))}const I=nt("stonecrop-ops-operations",null,{serializer:{read:p=>{try{return JSON.parse(p)}catch{return null}},write:p=>p?JSON.stringify(p):""}});function V(){if(!(typeof window>"u"))try{const p=I.value;p&&Array.isArray(p.operations)&&(e.value=p.operations.map(h=>({...h,timestamp:new Date(h.timestamp)})),t.value=p.currentIndex??-1)}catch(p){typeof console<"u"&&console.error("Failed to load operations from persistence:",p)}}function B(){if(!(typeof window>"u"))try{I.value={operations:e.value.map(p=>({...p,timestamp:p.timestamp.toISOString()})),currentIndex:t.value}}catch(p){typeof console<"u"&&console.error("Failed to save operations to persistence:",p)}}function F(){a.watch([e,t],()=>{n.value.enablePersistence&&B()},{deep:!0})}return{operations:e,currentIndex:t,config:n,clientId:r,undoRedoState:E,canUndo:c,canRedo:l,undoCount:g,redoCount:y,configure:P,addOperation:T,startBatch:k,commitBatch:M,cancelBatch:_,undo:$,redo:N,clear:A,getOperationsFor:m,getSnapshot:R,markIrreversible:j,logAction:x}});class ne{static _root;options;doctypeActions=new Map;doctypeTransitions=new Map;fieldRollbackConfig=new Map;globalActions=new Map;globalTransitionActions=new Map;constructor(e={}){if(ne._root)return ne._root;ne._root=this,this.options={defaultTimeout:e.defaultTimeout??5e3,debug:e.debug??!1,enableRollback:e.enableRollback??!0,errorHandler:e.errorHandler}}registerAction(e,t){this.globalActions.set(e,t)}registerTransitionAction(e,t){this.globalTransitionActions.set(e,t)}setFieldRollback(e,t,r){this.fieldRollbackConfig.has(e)||this.fieldRollbackConfig.set(e,new Map),this.fieldRollbackConfig.get(e).set(t,r)}getFieldRollback(e,t){return this.fieldRollbackConfig.get(e)?.get(t)}registerDoctypeActions(e,t){if(!t)return;const r=new Map,o=new Map;if(typeof t.entrySeq=="function")t.entrySeq().forEach(([i,s])=>{this.categorizeAction(i,s,r,o)});else if(t instanceof Map)for(const[i,s]of t)this.categorizeAction(i,s,r,o);else t&&typeof t=="object"&&Object.entries(t).forEach(([i,s])=>{this.categorizeAction(i,s,r,o)});this.doctypeActions.set(e,r),this.doctypeTransitions.set(e,o)}categorizeAction(e,t,r,o){this.isTransitionKey(e)?o.set(e,t):r.set(e,t)}isTransitionKey(e){return/^[A-Z0-9_]+$/.test(e)&&e.length>0}async executeFieldTriggers(e,t={}){const{doctype:r,fieldname:o}=e,i=this.findFieldTriggers(r,o);if(i.length===0)return{path:e.path,actionResults:[],totalExecutionTime:0,allSucceeded:!0,stoppedOnError:!1,rolledBack:!1};const s=performance.now(),c=[];let l=!1,g=!1,y;const E=this.getFieldRollback(r,o),P=t.enableRollback??E??this.options.enableRollback;P&&e.store&&(y=this.captureSnapshot(e));for(const _ of i)try{const $=await this.executeAction(_,e,t.timeout);if(c.push($),!$.success){l=!0;break}}catch($){const w={success:!1,error:$ instanceof Error?$:new Error(String($)),executionTime:0,action:_};c.push(w),l=!0;break}if(P&&l&&y&&e.store)try{this.restoreSnapshot(e,y),g=!0}catch(_){console.error("[FieldTriggers] Rollback failed:",_)}const T=performance.now()-s,k=c.filter(_=>!_.success);if(k.length>0&&this.options.errorHandler)for(const _ of k)try{this.options.errorHandler(_.error,e,_.action)}catch($){console.error("[FieldTriggers] Error in global error handler:",$)}return{path:e.path,actionResults:c,totalExecutionTime:T,allSucceeded:c.every(_=>_.success),stoppedOnError:l,rolledBack:g,snapshot:this.options.debug&&P?y:void 0}}async executeTransitionActions(e,t={}){const{doctype:r,transition:o}=e,i=this.findTransitionActions(r,o);if(i.length===0)return[];const s=[];for(const l of i)try{const g=await this.executeTransitionAction(l,e,t.timeout);if(s.push(g),!g.success)break}catch(g){const E={success:!1,error:g instanceof Error?g:new Error(String(g)),executionTime:0,action:l,transition:o};s.push(E);break}const c=s.filter(l=>!l.success);if(c.length>0&&this.options.errorHandler)for(const l of c)try{this.options.errorHandler(l.error,e,l.action)}catch(g){console.error("[FieldTriggers] Error in global error handler:",g)}return s}findTransitionActions(e,t){const r=this.doctypeTransitions.get(e);return r?r.get(t)||[]:[]}async executeTransitionAction(e,t,r){const o=performance.now(),i=r??this.options.defaultTimeout;try{let s=this.globalTransitionActions.get(e);if(!s){const l=this.globalActions.get(e);l&&(s=l)}if(!s)throw new Error(`Transition action "${e}" not found in registry`);return await this.executeWithTimeout(s,t,i),{success:!0,executionTime:performance.now()-o,action:e,transition:t.transition}}catch(s){const c=performance.now()-o;return{success:!1,error:s instanceof Error?s:new Error(String(s)),executionTime:c,action:e,transition:t.transition}}}findFieldTriggers(e,t){const r=this.doctypeActions.get(e);if(!r)return[];const o=[];for(const[i,s]of r)this.isFieldTriggerKey(i,t)&&o.push(...s);return o}isFieldTriggerKey(e,t){return e===t?!0:e.includes(".")?this.matchFieldPattern(e,t):e.includes("*")?this.matchFieldPattern(e,t):!1}matchFieldPattern(e,t){const r=e.split("."),o=t.split(".");if(r.length!==o.length)return!1;for(let i=0;i<r.length;i++){const s=r[i],c=o[i];if(s!=="*"&&s!==c)return!1}return!0}async executeAction(e,t,r){const o=performance.now(),i=r??this.options.defaultTimeout;try{const s=this.globalActions.get(e);if(!s)throw new Error(`Action "${e}" not found in registry`);return await this.executeWithTimeout(s,t,i),{success:!0,executionTime:performance.now()-o,action:e}}catch(s){const c=performance.now()-o;return{success:!1,error:s instanceof Error?s:new Error(String(s)),executionTime:c,action:e}}}async executeWithTimeout(e,t,r){return new Promise((o,i)=>{const s=setTimeout(()=>{i(new Error(`Action timeout after ${r}ms`))},r);Promise.resolve(e(t)).then(c=>{clearTimeout(s),o(c)}).catch(c=>{clearTimeout(s),i(c)})})}captureSnapshot(e){if(!(!e.store||!e.doctype||!e.recordId))try{const t=`${e.doctype}.${e.recordId}`,r=e.store.get(t);return!r||typeof r!="object"?void 0:JSON.parse(JSON.stringify(r))}catch(t){this.options.debug&&console.warn("[FieldTriggers] Failed to capture snapshot:",t);return}}restoreSnapshot(e,t){if(!(!e.store||!e.doctype||!e.recordId||!t))try{const r=`${e.doctype}.${e.recordId}`;e.store.set(r,t),this.options.debug&&console.log(`[FieldTriggers] Rolled back ${r} to previous state`)}catch(r){throw console.error("[FieldTriggers] Failed to restore snapshot:",r),r}}}function H(n){return new ne(n)}function at(n,e){H().registerAction(n,e)}function ct(n,e){H().registerTransitionAction(n,e)}function lt(n,e,t){H().setFieldRollback(n,e,t)}async function ut(n,e,t){const r=H(),o={path:t?.path||(t?.recordId?`${n}.${t.recordId}`:n),fieldname:"",beforeValue:void 0,afterValue:void 0,operation:"set",doctype:n,recordId:t?.recordId,timestamp:new Date,transition:e,currentState:t?.currentState,targetState:t?.targetState,fsmContext:t?.fsmContext};return await r.executeTransitionActions(o)}function ft(n,e){if(n)try{X().markIrreversible(n,e)}catch{}}function Ae(){try{return X()}catch{return null}}class K{static instance;static getInstance(){return K.instance||(K.instance=new K),K.instance}getRegistry(){if(typeof globalThis<"u"){const e=globalThis.Registry?._root;if(e)return e}if(typeof window<"u"){const e=window.Registry?._root;if(e)return e}if(typeof global<"u"&&global){const e=global.Registry?._root;if(e)return e}}getDoctypeMeta(e){const t=this.getRegistry();if(t&&typeof t=="object"&&"registry"in t)return t.registry[e]}}class ce{target;parentPath;rootNode;doctype;parentDoctype;hst;constructor(e,t,r="",o=null,i){return this.target=e,this.parentPath=r,this.rootNode=o||this,this.doctype=t,this.parentDoctype=i,this.hst=K.getInstance(),new Proxy(this,{get(s,c){if(c in s)return s[c];const l=String(c);return s.getNode(l)},set(s,c,l){const g=String(c);return s.set(g,l),!0}})}get(e){return this.resolveValue(e)}getNode(e){const t=this.resolvePath(e),r=this.resolveValue(e),o=t.split(".");let i=this.doctype;return this.doctype==="StonecropStore"&&o.length>=1&&(i=o[0]),typeof r=="object"&&r!==null&&!this.isPrimitive(r)?new ce(r,i,t,this.rootNode,this.parentDoctype):new ce(r,i,t,this.rootNode,this.parentDoctype)}set(e,t,r="user"){const o=this.resolvePath(e),i=this.has(e)?this.get(e):void 0;if(r!=="undo"&&r!=="redo"){const s=Ae();if(s&&typeof s.addOperation=="function"){const c=o.split("."),l=this.doctype==="StonecropStore"&&c.length>=1?c[0]:this.doctype,g=c.length>=2?c[1]:void 0,y=c.slice(2).join(".")||c[c.length-1],P=t===void 0&&i!==void 0?"delete":"set";s.addOperation({type:P,path:o,fieldname:y,beforeValue:i,afterValue:t,doctype:l,recordId:g,reversible:!0},r)}}this.updateValue(e,t),this.triggerFieldActions(o,i,t)}has(e){try{if(e==="")return!0;const t=this.parsePath(e);let r=this.target;for(let o=0;o<t.length;o++){const i=t[o];if(r==null)return!1;if(o===t.length-1)return this.isImmutable(r)?r.has(i):this.isPiniaStore(r)&&r.$state&&i in r.$state||i in r;r=this.getProperty(r,i)}return!1}catch{return!1}}getParent(){if(!this.parentPath)return null;const t=this.parentPath.split(".").slice(0,-1).join(".");return t===""?this.rootNode:this.rootNode.getNode(t)}getRoot(){return this.rootNode}getPath(){return this.parentPath}getDepth(){return this.parentPath?this.parentPath.split(".").length:0}getBreadcrumbs(){return this.parentPath?this.parentPath.split("."):[]}async triggerTransition(e,t){const r=H(),o=this.parentPath.split(".");let i=this.doctype,s;this.doctype==="StonecropStore"&&o.length>=1&&(i=o[0]),o.length>=2&&(s=o[1]);const c={path:this.parentPath,fieldname:"",beforeValue:void 0,afterValue:void 0,operation:"set",doctype:i,recordId:s,timestamp:new Date,store:this.rootNode||void 0,transition:e,currentState:t?.currentState,targetState:t?.targetState,fsmContext:t?.fsmContext},l=Ae();return l&&typeof l.addOperation=="function"&&l.addOperation({type:"transition",path:this.parentPath,fieldname:e,beforeValue:t?.currentState,afterValue:t?.targetState,doctype:i,recordId:s,reversible:!1,metadata:{transition:e,currentState:t?.currentState,targetState:t?.targetState,fsmContext:t?.fsmContext}},"user"),await r.executeTransitionActions(c)}resolvePath(e){return e===""?this.parentPath:this.parentPath?`${this.parentPath}.${e}`:e}resolveValue(e){if(e==="")return this.target;const t=this.parsePath(e);let r=this.target;for(const o of t){if(r==null)return;r=this.getProperty(r,o)}return r}updateValue(e,t){if(e==="")throw new Error("Cannot set value on empty path");const r=this.parsePath(e),o=r.pop();let i=this.target;for(const s of r)if(i=this.getProperty(i,s),i==null)throw new Error(`Cannot set property on null/undefined path: ${e}`);this.setProperty(i,o,t)}getProperty(e,t){return this.isImmutable(e)?e.get(t):this.isVueReactive(e)?e[t]:this.isPiniaStore(e)?e.$state?.[t]??e[t]:e[t]}setProperty(e,t,r){if(this.isImmutable(e))throw new Error("Cannot directly mutate immutable objects. Use immutable update methods instead.");if(this.isPiniaStore(e)){e.$patch?e.$patch({[t]:r}):e[t]=r;return}e[t]=r}async triggerFieldActions(e,t,r){try{if(!e||typeof e!="string")return;const o=e.split(".");if(o.length<3)return;const i=H(),s=o.slice(2).join(".")||o[o.length-1];let c=this.doctype;this.doctype==="StonecropStore"&&o.length>=1&&(c=o[0]);let l;o.length>=2&&(l=o[1]);const g={path:e,fieldname:s,beforeValue:t,afterValue:r,operation:"set",doctype:c,recordId:l,timestamp:new Date,store:this.rootNode||void 0};await i.executeFieldTriggers(g)}catch(o){o instanceof Error&&console.warn("Field trigger error:",o.message)}}isVueReactive(e){return e&&typeof e=="object"&&"__v_isReactive"in e&&e.__v_isReactive===!0}isPiniaStore(e){return e&&typeof e=="object"&&("$state"in e||"$patch"in e||"$id"in e)}isImmutable(e){if(!e||typeof e!="object")return!1;const t="get"in e&&typeof e.get=="function",r="set"in e&&typeof e.set=="function",o="has"in e&&typeof e.has=="function",i="__ownerID"in e||"_map"in e||"_list"in e||"_origin"in e||"_capacity"in e||"_defaultValues"in e||"_tail"in e||"_root"in e||"size"in e&&t&&r;let s;try{const l=e;if("constructor"in l&&l.constructor&&typeof l.constructor=="object"&&"name"in l.constructor){const g=l.constructor.name;s=typeof g=="string"?g:void 0}}catch{s=void 0}const c=s&&(s.includes("Map")||s.includes("List")||s.includes("Set")||s.includes("Stack")||s.includes("Seq"))&&(t||r);return!!(t&&r&&o&&i||t&&r&&c)}isPrimitive(e){return e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="function"||typeof e=="symbol"||typeof e=="bigint"}parsePath(e){return e?e.split(".").filter(t=>t.length>0):[]}}function Ie(n,e,t){return new ce(n,e,"",null,t)}class ye{hstStore;_operationLogStore;_operationLogConfig;registry;constructor(e,t){this.registry=e,this._operationLogConfig=t,this.initializeHSTStore(),this.setupRegistrySync()}getOperationLogStore(){return this._operationLogStore||(this._operationLogStore=X(),this._operationLogConfig&&this._operationLogStore.configure(this._operationLogConfig)),this._operationLogStore}initializeHSTStore(){const e={};Object.keys(this.registry.registry).forEach(t=>{e[t]={}}),this.hstStore=Ie(e,"StonecropStore")}setupRegistrySync(){const e=this.registry.addDoctype.bind(this.registry);this.registry.addDoctype=t=>{e(t),this.hstStore.has(t.slug)||this.hstStore.set(t.slug,{})}}records(e){const t=typeof e=="string"?e:e.slug;return this.ensureDoctypeExists(t),this.hstStore.getNode(t)}addRecord(e,t,r){const o=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(o),this.hstStore.set(`${o}.${t}`,r)}getRecordById(e,t){const r=typeof e=="string"?e:e.slug;if(this.ensureDoctypeExists(r),!(!this.hstStore.has(`${r}.${t}`)||this.hstStore.get(`${r}.${t}`)===void 0))return this.hstStore.getNode(`${r}.${t}`)}removeRecord(e,t){const r=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(r),this.hstStore.has(`${r}.${t}`)&&this.hstStore.set(`${r}.${t}`,void 0)}getRecordIds(e){const t=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(t);const r=this.hstStore.get(t);return!r||typeof r!="object"?[]:Object.keys(r).filter(o=>r[o]!==void 0)}clearRecords(e){const t=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(t),this.getRecordIds(t).forEach(o=>{this.hstStore.set(`${t}.${o}`,void 0)})}setup(e){this.ensureDoctypeExists(e.slug)}runAction(e,t,r){const i=this.registry.registry[e.slug]?.actions?.get(t),s=Array.isArray(r)?r.filter(y=>typeof y=="string"):void 0,c=this.getOperationLogStore();let l="success",g;try{i&&i.length>0&&i.forEach(y=>{try{new Function("args",y)(r)}catch(E){throw l="failure",g=E instanceof Error?E.message:"Unknown error",E}})}catch{}finally{c.logAction(e.doctype,t,s,l,g)}}async getRecords(e){(await(await fetch(`/${e.slug}`)).json()).forEach(o=>{o.id&&this.addRecord(e,o.id,o)})}async getRecord(e,t){const o=await(await fetch(`/${e.slug}/${t}`)).json();this.addRecord(e,t,o)}ensureDoctypeExists(e){this.hstStore.has(e)||this.hstStore.set(e,{})}async getMeta(e){if(!this.registry.getMeta)throw new Error("No getMeta function provided to Registry");return await this.registry.getMeta(e)}getStore(){return this.hstStore}}function dt(n){n||(n={});const e=n.registry||a.inject("$registry"),t=a.inject("$stonecrop"),r=a.ref(),o=a.ref(),i=a.ref({}),s=a.ref(),c=a.ref(),l=a.ref([]),g=a.ref(-1),y=a.computed(()=>r.value?.getOperationLogStore().canUndo??!1),E=a.computed(()=>r.value?.getOperationLogStore().canRedo??!1),P=a.computed(()=>r.value?.getOperationLogStore().undoCount??0),T=a.computed(()=>r.value?.getOperationLogStore().redoCount??0),k=a.computed(()=>r.value?.getOperationLogStore().undoRedoState??{canUndo:!1,canRedo:!1,undoCount:0,redoCount:0,currentIndex:-1}),M=S=>r.value?.getOperationLogStore().undo(S)??!1,_=S=>r.value?.getOperationLogStore().redo(S)??!1,$=()=>{r.value?.getOperationLogStore().startBatch()},N=S=>r.value?.getOperationLogStore().commitBatch(S)??null,w=()=>{r.value?.getOperationLogStore().cancelBatch()},C=()=>{r.value?.getOperationLogStore().clear()},R=(S,d)=>r.value?.getOperationLogStore().getOperationsFor(S,d)??[],A=()=>r.value?.getOperationLogStore().getSnapshot()??{operations:[],currentIndex:-1,totalOperations:0,reversibleOperations:0,irreversibleOperations:0},m=(S,d)=>{r.value?.getOperationLogStore().markIrreversible(S,d)},j=(S,d,b,I="success",V)=>r.value?.getOperationLogStore().logAction(S,d,b,I,V)??"",x=S=>{r.value?.getOperationLogStore().configure(S)};a.onMounted(async()=>{if(e){r.value=t||new ye(e);try{const S=r.value.getOperationLogStore(),d=Oe(S);l.value=d.operations.value,g.value=d.currentIndex.value,a.watch(()=>d.operations.value,b=>{l.value=b}),a.watch(()=>d.currentIndex.value,b=>{g.value=b})}catch{}if(!n.doctype&&e.router){const S=e.router.currentRoute.value;if(!S.path)return;const d=S.path.split("/").filter(I=>I.length>0),b=d[1]?.toLowerCase();if(d.length>0){const I={path:S.path,segments:d},V=await e.getMeta?.(I);if(V){if(e.addDoctype(V),r.value.setup(V),s.value=V,c.value=b,o.value=r.value.getStore(),b&&b!=="new"){const B=r.value.getRecordById(V,b);if(B)i.value=B.get("")||{};else try{await r.value.getRecord(V,b);const F=r.value.getRecordById(V,b);F&&(i.value=F.get("")||{})}catch{i.value=le(V)}}else i.value=le(V);o.value&&Te(V,b||"new",i,o.value),r.value.runAction(V,"load",b?[b]:void 0)}}}if(n.doctype){o.value=r.value.getStore();const S=n.doctype,d=n.recordId;if(d&&d!=="new"){const b=r.value.getRecordById(S,d);if(b)i.value=b.get("")||{};else try{await r.value.getRecord(S,d);const I=r.value.getRecordById(S,d);I&&(i.value=I.get("")||{})}catch{i.value=le(S)}}else i.value=le(S);o.value&&Te(S,d||"new",i,o.value)}}});const u=(S,d)=>{const b=n.doctype||s.value;if(!b)return"";const I=d||n.recordId||c.value||"new";return`${b.slug}.${I}.${S}`},f=S=>{const d=n.doctype||s.value;if(!(!o.value||!r.value||!d))try{const b=S.path.split(".");if(b.length>=2){const B=b[0],F=b[1];if(o.value.has(`${B}.${F}`)||r.value.addRecord(d,F,{...i.value}),b.length>3){const p=`${B}.${F}`,h=b.slice(2);let v=p;for(let L=0;L<h.length-1;L++)if(v+=`.${h[L]}`,!o.value.has(v)){const z=h[L+1],U=!isNaN(Number(z));o.value.set(v,U?[]:{})}}}o.value.set(S.path,S.value);const I=S.fieldname.split("."),V={...i.value};I.length===1?V[I[0]]=S.value:pt(V,I,S.value),i.value=V}catch{}};(n.doctype||e?.router)&&(a.provide("hstPathProvider",u),a.provide("hstChangeHandler",f));const O={operations:l,currentIndex:g,undoRedoState:k,canUndo:y,canRedo:E,undoCount:P,redoCount:T,undo:M,redo:_,startBatch:$,commitBatch:N,cancelBatch:w,clear:C,getOperationsFor:R,getSnapshot:A,markIrreversible:m,logAction:j,configure:x};return n.doctype?{stonecrop:r,operationLog:O,provideHSTPath:u,handleHSTChange:f,hstStore:o,formData:i}:!n.doctype&&e?.router?{stonecrop:r,operationLog:O,provideHSTPath:u,handleHSTChange:f,hstStore:o,formData:i}:{stonecrop:r,operationLog:O}}function le(n){const e={};return n.schema&&n.schema.forEach(t=>{switch("fieldtype"in t?t.fieldtype:"Data"){case"Data":case"Text":e[t.fieldname]="";break;case"Check":e[t.fieldname]=!1;break;case"Int":case"Float":e[t.fieldname]=0;break;case"Table":e[t.fieldname]=[];break;case"JSON":e[t.fieldname]={};break;default:e[t.fieldname]=null}}),e}function Te(n,e,t,r){a.watch(t,o=>{const i=`${n.slug}.${e}`;Object.keys(o).forEach(s=>{const c=`${i}.${s}`;try{r.set(c,o[s])}catch{}})},{deep:!0})}function pt(n,e,t){let r=n;for(let i=0;i<e.length-1;i++){const s=e[i];(!(s in r)||typeof r[s]!="object")&&(r[s]=isNaN(Number(e[i+1]))?{}:[]),r=r[s]}const o=e[e.length-1];r[o]=t}function me(n){const t=a.inject("$operationLogStore",void 0)||X();n&&t.configure(n);const{operations:r,currentIndex:o,undoRedoState:i,canUndo:s,canRedo:c,undoCount:l,redoCount:g}=Oe(t);function y(R){return t.undo(R)}function E(R){return t.redo(R)}function P(){t.startBatch()}function T(R){return t.commitBatch(R)}function k(){t.cancelBatch()}function M(){t.clear()}function _(R,A){return t.getOperationsFor(R,A)}function $(){return t.getSnapshot()}function N(R,A){t.markIrreversible(R,A)}function w(R,A,m,j="success",x){return t.logAction(R,A,m,j,x)}function C(R){t.configure(R)}return{operations:r,currentIndex:o,undoRedoState:i,canUndo:s,canRedo:c,undoCount:l,redoCount:g,undo:y,redo:E,startBatch:P,commitBatch:T,cancelBatch:k,clear:M,getOperationsFor:_,getSnapshot:$,markIrreversible:N,logAction:w,configure:C}}function ht(n,e=!0){if(!e)return;const{undo:t,redo:r,canUndo:o,canRedo:i}=me(),s=it();re(s["Ctrl+Z"],()=>{o.value&&t(n)}),re(s["Meta+Z"],()=>{o.value&&t(n)}),re(s["Ctrl+Shift+Z"],()=>{i.value&&r(n)}),re(s["Meta+Shift+Z"],()=>{i.value&&r(n)}),re(s["Ctrl+Y"],()=>{i.value&&r(n)})}async function gt(n,e){const{startBatch:t,commitBatch:r,cancelBatch:o}=me();t();try{return await n(),r(e)}catch(i){throw o(),i}}class yt{doctype;schema;workflow;actions;component;constructor(e,t,r,o,i){this.doctype=e,this.schema=t,this.workflow=r,this.actions=o,this.component=i}get slug(){return this.doctype.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}}class ee{static _root;name;registry;router;constructor(e,t){if(ee._root)return ee._root;ee._root=this,this.name="Registry",this.registry={},this.router=e,this.getMeta=t}getMeta;addDoctype(e){e.doctype in Object.keys(this.registry)||(this.registry[e.slug]=e);const t=H();t.registerDoctypeActions(e.doctype,e.actions),e.slug!==e.doctype&&t.registerDoctypeActions(e.slug,e.actions),e.component&&this.router&&!this.router.hasRoute(e.doctype)&&this.router.addRoute({path:`/${e.slug}`,name:e.slug,component:e.component})}}async function mt(n,e,t){await a.nextTick();try{await t(n,e)}catch{}}const vt={install:(n,e)=>{const t=n.config.globalProperties.$router,r=e?.router,o=t||r;!t&&r&&n.use(r);const i=new ee(o,e?.getMeta);n.provide("$registry",i),n.config.globalProperties.$registry=i;const s=new ye(i);n.provide("$stonecrop",s),n.config.globalProperties.$stonecrop=s;try{const c=n.config.globalProperties.$pinia;if(c){const l=X(c);n.provide("$operationLogStore",l),n.config.globalProperties.$operationLogStore=l}}catch(c){console.warn("Pinia not available - operation log features will be disabled:",c)}if(e?.components)for(const[c,l]of Object.entries(e.components))n.component(c,l);e?.autoInitializeRouter&&e.onRouterInitialized&&mt(i,s,e.onRouterInitialized)}};var $e=(n=>(n.ERROR="error",n.WARNING="warning",n.INFO="info",n))($e||{});class De{options;constructor(e={}){this.options={registry:e.registry||null,validateLinkTargets:e.validateLinkTargets??!0,validateActions:e.validateActions??!0,validateWorkflows:e.validateWorkflows??!0,validateRequiredProperties:e.validateRequiredProperties??!0}}validate(e,t,r,o){const i=[],s=t?Array.isArray(t)?t:t.toArray():[];if(this.options.validateRequiredProperties&&i.push(...this.validateRequiredProperties(e,s)),this.options.validateLinkTargets&&this.options.registry&&i.push(...this.validateLinkFields(e,s,this.options.registry)),this.options.validateWorkflows&&r&&i.push(...this.validateWorkflow(e,r)),this.options.validateActions&&o){const y=o instanceof Map?o:o.toObject();i.push(...this.validateActionRegistration(e,y))}const c=i.filter(y=>y.severity==="error").length,l=i.filter(y=>y.severity==="warning").length,g=i.filter(y=>y.severity==="info").length;return{valid:c===0,issues:i,errorCount:c,warningCount:l,infoCount:g}}validateRequiredProperties(e,t){const r=[];for(const o of t){if(!o.fieldname){r.push({severity:"error",rule:"required-fieldname",message:"Field is missing required property: fieldname",doctype:e,context:{field:o}});continue}if(!o.component&&!("fieldtype"in o)&&r.push({severity:"error",rule:"required-component-or-fieldtype",message:`Field "${o.fieldname}" must have either component or fieldtype property`,doctype:e,fieldname:o.fieldname}),"schema"in o){const i=o.schema,s=Array.isArray(i)?i:i.toArray?.()||[];r.push(...this.validateRequiredProperties(e,s))}}return r}validateLinkFields(e,t,r){const o=[];for(const i of t){if(("fieldtype"in i?i.fieldtype:void 0)==="Link"){const c="options"in i?i.options:void 0;if(!c){o.push({severity:"error",rule:"link-missing-options",message:`Link field "${i.fieldname}" is missing options property (target doctype)`,doctype:e,fieldname:i.fieldname});continue}const l=typeof c=="string"?c:"";if(!l){o.push({severity:"error",rule:"link-invalid-options",message:`Link field "${i.fieldname}" has invalid options format (expected string doctype name)`,doctype:e,fieldname:i.fieldname});continue}r.registry[l]||r.registry[l.toLowerCase()]||o.push({severity:"error",rule:"link-invalid-target",message:`Link field "${i.fieldname}" references non-existent doctype: "${l}"`,doctype:e,fieldname:i.fieldname,context:{targetDoctype:l}})}if("schema"in i){const c=i.schema,l=Array.isArray(c)?c:c.toArray?.()||[];o.push(...this.validateLinkFields(e,l,r))}}return o}validateWorkflow(e,t){const r=[];if(!t.initial&&!t.type&&r.push({severity:"warning",rule:"workflow-missing-initial",message:"Workflow is missing initial state property",doctype:e}),!t.states||Object.keys(t.states).length===0)return r.push({severity:"warning",rule:"workflow-no-states",message:"Workflow has no states defined",doctype:e}),r;t.initial&&typeof t.initial=="string"&&!t.states[t.initial]&&r.push({severity:"error",rule:"workflow-invalid-initial",message:`Workflow initial state "${t.initial}" does not exist in states`,doctype:e,context:{initialState:t.initial}});const o=Object.keys(t.states),i=new Set;t.initial&&typeof t.initial=="string"&&i.add(t.initial);for(const[s,c]of Object.entries(t.states)){const l=c;if(l.on){for(const[g,y]of Object.entries(l.on))if(typeof y=="string")i.add(y);else if(y&&typeof y=="object"){const E="target"in y?y.target:void 0;typeof E=="string"?i.add(E):Array.isArray(E)&&E.forEach(P=>{typeof P=="string"&&i.add(P)})}}}for(const s of o)i.has(s)||r.push({severity:"warning",rule:"workflow-unreachable-state",message:`Workflow state "${s}" may not be reachable`,doctype:e,context:{stateName:s}});return r}validateActionRegistration(e,t){const r=[],o=H();for(const[i,s]of Object.entries(t)){if(!Array.isArray(s)){r.push({severity:"error",rule:"action-invalid-format",message:`Action configuration for "${i}" must be an array`,doctype:e,context:{triggerName:i,actionNames:s}});continue}for(const c of s){const l=o;l.globalActions?.has(c)||l.globalTransitionActions?.has(c)||r.push({severity:"warning",rule:"action-not-registered",message:`Action "${c}" referenced in "${i}" is not registered in FieldTriggerEngine`,doctype:e,context:{triggerName:i,actionName:c}})}}return r}}function Ce(n,e){return new De({registry:n,...e})}function St(n,e,t,r,o){return Ce(t).validate(n,e,r,o)}D.DoctypeMeta=yt,D.HST=K,D.Registry=ee,D.SchemaValidator=De,D.Stonecrop=ye,D.ValidationSeverity=$e,D.createHST=Ie,D.createValidator=Ce,D.default=vt,D.getGlobalTriggerEngine=H,D.markOperationIrreversible=ft,D.registerGlobalAction=at,D.registerTransitionAction=ct,D.setFieldRollback=lt,D.triggerTransition=ut,D.useOperationLog=me,D.useOperationLogStore=X,D.useStonecrop=dt,D.useUndoRedoShortcuts=ht,D.validateSchema=St,D.withBatch=gt,Object.defineProperties(D,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
6
6
  //# sourceMappingURL=stonecrop.umd.cjs.map