@stonecrop/stonecrop 0.6.1 → 0.6.3

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,10 +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";/*!
2
- * pinia v3.0.3
3
- * (c) 2025 Eduardo San Martin Morote
4
- * @license MIT
5
- */let X;const ne=r=>X=r,De=process.env.NODE_ENV!=="production"?Symbol("pinia"):Symbol();function J(r){return r&&typeof r=="object"&&Object.prototype.toString.call(r)==="[object Object]"&&typeof r.toJSON!="function"}var ee;(function(r){r.direct="direct",r.patchObject="patch object",r.patchFunction="patch function"})(ee||(ee={}));const te=typeof window<"u";function me(r,e){for(const t in e){const o=e[t];if(!(t in r))continue;const n=r[t];J(n)&&J(o)&&!a.isRef(o)&&!a.isReactive(o)?r[t]=me(n,o):r[t]=o}return r}const ve=()=>{};function Se(r,e,t,o=ve){r.push(e);const n=()=>{const s=r.indexOf(e);s>-1&&(r.splice(s,1),o())};return!t&&a.getCurrentScope()&&a.onScopeDispose(n),n}function Z(r,...e){r.slice().forEach(t=>{t(...e)})}const $e=r=>r(),be=Symbol(),ue=Symbol();function fe(r,e){r instanceof Map&&e instanceof Map?e.forEach((t,o)=>r.set(o,t)):r instanceof Set&&e instanceof Set&&e.forEach(r.add,r);for(const t in e){if(!e.hasOwnProperty(t))continue;const o=e[t],n=r[t];J(n)&&J(o)&&r.hasOwnProperty(t)&&!a.isRef(o)&&!a.isReactive(o)?r[t]=fe(n,o):r[t]=o}return r}const Ce=process.env.NODE_ENV!=="production"?Symbol("pinia:skipHydration"):Symbol();function Ae(r){return!J(r)||!Object.prototype.hasOwnProperty.call(r,Ce)}const{assign:U}=Object;function we(r){return!!(a.isRef(r)&&r.effect)}function Ee(r,e,t,o){const{state:n,actions:s,getters:i}=e,c=t.state.value[r];let l;function f(){!c&&(process.env.NODE_ENV==="production"||!o)&&(t.state.value[r]=n?n():{});const b=process.env.NODE_ENV!=="production"&&o?a.toRefs(a.ref(n?n():{}).value):a.toRefs(t.state.value[r]);return U(b,s,Object.keys(i||{}).reduce((E,N)=>(process.env.NODE_ENV!=="production"&&N in b&&console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${N}" in store "${r}".`),E[N]=a.markRaw(a.computed(()=>{ne(t);const D=t._s.get(r);return i[N].call(D,D)})),E),{}))}return l=de(r,f,e,t,o,!0),l}function de(r,e,t={},o,n,s){let i;const c=U({actions:{}},t);if(process.env.NODE_ENV!=="production"&&!o._e.active)throw new Error("Pinia destroyed");const l={deep:!0};process.env.NODE_ENV!=="production"&&(l.onTrigger=u=>{f?D=u:f==!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 f,b,E=[],N=[],D;const A=o.state.value[r];!s&&!A&&(process.env.NODE_ENV==="production"||!n)&&(o.state.value[r]={});const L=a.ref({});let P;function $(u){let d;f=b=!1,process.env.NODE_ENV!=="production"&&(D=[]),typeof u=="function"?(u(o.state.value[r]),d={type:ee.patchFunction,storeId:r,events:D}):(fe(o.state.value[r],u),d={type:ee.patchObject,payload:u,storeId:r,events:D});const R=P=Symbol();a.nextTick().then(()=>{P===R&&(f=!0)}),b=!0,Z(E,d,o.state.value[r])}const _=s?function(){const{state:d}=t,R=d?d():{};this.$patch(v=>{U(v,R)})}:process.env.NODE_ENV!=="production"?()=>{throw new Error(`🍍: Store "${r}" is built using the setup syntax and does not implement $reset().`)}:ve;function w(){i.stop(),E=[],N=[],o._s.delete(r)}const V=(u,d="")=>{if(be in u)return u[ue]=d,u;const R=function(){ne(o);const v=Array.from(arguments),p=[],S=[];function I(F){p.push(F)}function k(F){S.push(F)}Z(N,{args:v,name:R[ue],store:y,after:I,onError:k});let j;try{j=u.apply(this&&this.$id===r?this:y,v)}catch(F){throw Z(S,F),F}return j instanceof Promise?j.then(F=>(Z(p,F),F)).catch(F=>(Z(S,F),Promise.reject(F))):(Z(p,j),j)};return R[be]=!0,R[ue]=d,R},O=a.markRaw({actions:{},getters:{},state:[],hotState:L}),T={_p:o,$id:r,$onAction:Se.bind(null,N),$patch:$,$reset:_,$subscribe(u,d={}){const R=Se(E,u,d.detached,()=>v()),v=i.run(()=>a.watch(()=>o.state.value[r],p=>{(d.flush==="sync"?b:f)&&u({storeId:r,type:ee.direct,events:D},p)},U({},l,d)));return R},$dispose:w},y=a.reactive(process.env.NODE_ENV!=="production"||process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&te?U({_hmrPayload:O,_customProperties:a.markRaw(new Set)},T):T);o._s.set(r,y);const x=(o._a&&o._a.runWithContext||$e)(()=>o._e.run(()=>(i=a.effectScope()).run(()=>e({action:V}))));for(const u in x){const d=x[u];if(a.isRef(d)&&!we(d)||a.isReactive(d))process.env.NODE_ENV!=="production"&&n?L.value[u]=a.toRef(x,u):s||(A&&Ae(d)&&(a.isRef(d)?d.value=A[u]:fe(d,A[u])),o.state.value[r][u]=d),process.env.NODE_ENV!=="production"&&O.state.push(u);else if(typeof d=="function"){const R=process.env.NODE_ENV!=="production"&&n?d:V(d,u);x[u]=R,process.env.NODE_ENV!=="production"&&(O.actions[u]=d),c.actions[u]=d}else process.env.NODE_ENV!=="production"&&we(d)&&(O.getters[u]=s?t.getters[u]:d,te&&(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:o.state.value[r],set:u=>{if(process.env.NODE_ENV!=="production"&&n)throw new Error("cannot set hotState");$(d=>{U(d,u)})}}),process.env.NODE_ENV!=="production"&&(y._hotUpdate=a.markRaw(u=>{y._hotUpdating=!0,u._hmrPayload.state.forEach(d=>{if(d in y.$state){const R=u.$state[d],v=y.$state[d];typeof R=="object"&&J(R)&&J(v)?me(R,v):u.$state[d]=v}y[d]=a.toRef(u.$state,d)}),Object.keys(y.$state).forEach(d=>{d in u.$state||delete y[d]}),f=!1,b=!1,o.state.value[r]=a.toRef(u._hmrPayload,"hotState"),b=!0,a.nextTick().then(()=>{f=!0});for(const d in u._hmrPayload.actions){const R=u[d];y[d]=V(R,d)}for(const d in u._hmrPayload.getters){const R=u._hmrPayload.getters[d],v=s?a.computed(()=>(ne(o),R.call(y,y))):R;y[d]=v}Object.keys(y._hmrPayload.getters).forEach(d=>{d in u._hmrPayload.getters||delete y[d]}),Object.keys(y._hmrPayload.actions).forEach(d=>{d in u._hmrPayload.actions||delete y[d]}),y._hmrPayload=u._hmrPayload,y._getters=u._getters,y._hotUpdating=!1})),process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&te){const u={writable:!0,configurable:!0,enumerable:!1};["_p","_hmrPayload","_getters","_customProperties"].forEach(d=>{Object.defineProperty(y,d,U({value:y[d]},u))})}return o._p.forEach(u=>{if(process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&te){const d=i.run(()=>u({store:y,app:o._a,pinia:o,options:c}));Object.keys(d||{}).forEach(R=>y._customProperties.add(R)),U(y,d)}else U(y,i.run(()=>u({store:y,app:o._a,pinia:o,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(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
6
2
  state: () => new MyClass()
7
- Found in store "${y.$id}".`),A&&s&&t.hydrate&&t.hydrate(y.$state,A),f=!0,b=!0,y}/*! #__NO_SIDE_EFFECTS__ */function Ve(r,e,t){let o;const n=typeof e=="function";o=n?t:e;function s(i,c){const l=a.hasInjectionContext();if(i=(process.env.NODE_ENV==="test"&&X&&X._testing?null:i)||(l?a.inject(De,null):null),i&&ne(i),process.env.NODE_ENV!=="production"&&!X)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 "${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)"?
8
4
  See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help.
9
- This will fail in production.`);i=X,i._s.has(r)||(n?de(r,e,o,i):Ee(r,o,i),process.env.NODE_ENV!=="production"&&(s._pinia=i));const f=i._s.get(r);if(process.env.NODE_ENV!=="production"&&c){const b="__hot:"+r,E=n?de(b,e,o,i,!0):Ee(b,U({},o),i,!0);c._hotUpdate(E),delete i.state.value[b],i._s.delete(b)}if(process.env.NODE_ENV!=="production"&&te){const b=a.getCurrentInstance();if(b&&b.proxy&&!c){const E=b.proxy,N="_pStores"in E?E._pStores:E._pStores={};N[r]=f}}return f}return s.$id=r,s}function Oe(r){const e=a.toRaw(r),t={};for(const o in e){const n=e[o];n.effect?t[o]=a.computed({get:()=>r[o],set(s){r[o]=s}}):(a.isRef(n)||a.isReactive(n))&&(t[o]=a.toRef(r,o))}return t}function ke(r,e){return a.getCurrentScope()?(a.onScopeDispose(r,e),!0):!1}const Fe=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Me=Object.prototype.toString,Le=r=>Me.call(r)==="[object Object]",Re=()=>{};function xe(...r){if(r.length!==1)return a.toRef(...r);const e=r[0];return typeof e=="function"?a.readonly(a.customRef(()=>({get:e,set:Re}))):a.ref(e)}function Be(r,e){function t(...o){return new Promise((n,s)=>{Promise.resolve(r(()=>e.apply(this,o),{fn:e,thisArg:this,args:o})).then(n).catch(s)})}return t}const _e=r=>r();function je(r=_e,e={}){const{initialState:t="active"}=e,o=xe(t==="active");function n(){o.value=!1}function s(){o.value=!0}const i=(...c)=>{o.value&&r(...c)};return{isActive:a.readonly(o),pause:n,resume:s,eventFilter:i}}function pe(r){return Array.isArray(r)?r:[r]}function Ue(r){return a.getCurrentInstance()}function We(r,e,t={}){const{eventFilter:o=_e,...n}=t;return a.watch(r,Be(o,e),n)}function ze(r,e,t={}){const{eventFilter:o,initialState:n="active",...s}=t,{eventFilter:i,pause:c,resume:l,isActive:f}=je(o,{initialState:n});return{stop:We(r,e,{...s,eventFilter:i}),pause:c,resume:l,isActive:f}}const He=ze;function Je(r,e=!0,t){Ue()?a.onMounted(r,t):e?r():a.nextTick(r)}function Ge(r,e,t){return a.watch(r,e,{...t,immediate:!0})}function re(r,e,t){return a.watch(r,(n,s,i)=>{n&&e(n,s,i)},{...t,once:!1})}const G=Fe?window:void 0;function Ke(r){var e;const t=a.toValue(r);return(e=t?.$el)!==null&&e!==void 0?e:t}function q(...r){const e=[],t=()=>{e.forEach(c=>c()),e.length=0},o=(c,l,f,b)=>(c.addEventListener(l,f,b),()=>c.removeEventListener(l,f,b)),n=a.computed(()=>{const c=pe(a.toValue(r[0])).filter(l=>l!=null);return c.every(l=>typeof l!="string")?c:void 0}),s=Ge(()=>{var c,l;return[(c=(l=n.value)===null||l===void 0?void 0:l.map(f=>Ke(f)))!==null&&c!==void 0?c:[G].filter(f=>f!=null),pe(a.toValue(n.value?r[1]:r[0])),pe(a.unref(n.value?r[2]:r[1])),a.toValue(n.value?r[3]:r[2])]},([c,l,f,b])=>{if(t(),!c?.length||!l?.length||!f?.length)return;const E=Le(b)?{...b}:b;e.push(...c.flatMap(N=>l.flatMap(D=>f.map(A=>o(N,D,A,E)))))},{flush:"post"}),i=()=>{s(),t()};return ke(t),i}const se=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},ie="__vueuse_ssr_handlers__",Ze=qe();function qe(){return ie in se||(se[ie]=se[ie]||{}),se[ie]}function Ye(r,e){return Ze[r]||e}function Qe(r){return r==null?"any":r instanceof Set?"set":r instanceof Map?"map":r instanceof Date?"date":typeof r=="boolean"?"boolean":typeof r=="string"?"string":typeof r=="object"?"object":Number.isNaN(r)?"any":"number"}const Xe={boolean:{read:r=>r==="true",write:r=>String(r)},object:{read:r=>JSON.parse(r),write:r=>JSON.stringify(r)},number:{read:r=>Number.parseFloat(r),write:r=>String(r)},any:{read:r=>r,write:r=>String(r)},string:{read:r=>r,write:r=>String(r)},map:{read:r=>new Map(JSON.parse(r)),write:r=>JSON.stringify(Array.from(r.entries()))},set:{read:r=>new Set(JSON.parse(r)),write:r=>JSON.stringify(Array.from(r))},date:{read:r=>new Date(r),write:r=>r.toISOString()}},Pe="vueuse-storage";function et(r,e,t,o={}){var n;const{flush:s="pre",deep:i=!0,listenToStorageChanges:c=!0,writeDefaults:l=!0,mergeDefaults:f=!1,shallow:b,window:E=G,eventFilter:N,onError:D=p=>{console.error(p)},initOnMounted:A}=o,L=(b?a.shallowRef:a.ref)(e),P=a.computed(()=>a.toValue(r));if(!t)try{t=Ye("getDefaultStorage",()=>G?.localStorage)()}catch(p){D(p)}if(!t)return L;const $=a.toValue(e),_=Qe($),w=(n=o.serializer)!==null&&n!==void 0?n:Xe[_],{pause:V,resume:O}=He(L,p=>u(p),{flush:s,deep:i,eventFilter:N});a.watch(P,()=>R(),{flush:s});let T=!1;const y=p=>{A&&!T||R(p)},B=p=>{A&&!T||v(p)};E&&c&&(t instanceof Storage?q(E,"storage",y,{passive:!0}):q(E,Pe,B)),A?Je(()=>{T=!0,R()}):R();function x(p,S){if(E){const I={key:P.value,oldValue:p,newValue:S,storageArea:t};E.dispatchEvent(t instanceof Storage?new StorageEvent("storage",I):new CustomEvent(Pe,{detail:I}))}}function u(p){try{const S=t.getItem(P.value);if(p==null)x(S,null),t.removeItem(P.value);else{const I=w.write(p);S!==I&&(t.setItem(P.value,I),x(S,I))}}catch(S){D(S)}}function d(p){const S=p?p.newValue:t.getItem(P.value);if(S==null)return l&&$!=null&&t.setItem(P.value,w.write($)),$;if(!p&&f){const I=w.read(S);return typeof f=="function"?f(I,$):_==="object"&&!Array.isArray(I)?{...$,...I}:I}else return typeof S!="string"?S:w.read(S)}function R(p){if(!(p&&p.storageArea!==t)){if(p&&p.key==null){L.value=$;return}if(!(p&&p.key!==P.value)){V();try{const S=w.write(L.value);(p===void 0||p?.newValue!==S)&&(L.value=d(p))}catch(S){D(S)}finally{p?a.nextTick(O):O()}}}}function v(p){R(p.detail)}return L}function tt(r,e,t={}){const{window:o=G}=t;return et(r,e,o?.localStorage,t)}const rt={ctrl:"control",command:"meta",cmd:"meta",option:"alt",up:"arrowup",down:"arrowdown",left:"arrowleft",right:"arrowright"};function ot(r={}){const{reactive:e=!1,target:t=G,aliasMap:o=rt,passive:n=!0,onEventFired:s=Re}=r,i=a.reactive(new Set),c={toJSON(){return{}},current:i},l=e?a.reactive(c):c,f=new Set,b=new Map([["Meta",f],["Shift",new Set],["Alt",new Set]]),E=new Set;function N(_,w){_ in l&&(e?l[_]=w:l[_].value=w)}function D(){i.clear();for(const _ of E)N(_,!1)}function A(_,w,V){if(!(!_||typeof w.getModifierState!="function")){for(const[O,T]of b)if(w.getModifierState(O)){V.forEach(y=>T.add(y));break}}}function L(_,w){if(_)return;const V=`${w[0].toUpperCase()}${w.slice(1)}`,O=b.get(V);if(!["shift","alt"].includes(w)||!O)return;const T=Array.from(O),y=T.indexOf(w);T.forEach((B,x)=>{x>=y&&(i.delete(B),N(B,!1))}),O.clear()}function P(_,w){var V,O;const T=(V=_.key)===null||V===void 0?void 0:V.toLowerCase(),y=[(O=_.code)===null||O===void 0?void 0:O.toLowerCase(),T].filter(Boolean);T&&(w?i.add(T):i.delete(T));for(const B of y)E.add(B),N(B,w);A(w,_,[...i,...y]),L(w,T),T==="meta"&&!w&&(f.forEach(B=>{i.delete(B),N(B,!1)}),f.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(_,w,V){if(typeof w!="string")return Reflect.get(_,w,V);if(w=w.toLowerCase(),w in o&&(w=o[w]),!(w in l))if(/[+_-]/.test(w)){const T=w.split(/[+_-]/g).map(y=>y.trim());l[w]=a.computed(()=>T.map(y=>a.toValue($[y])).every(Boolean))}else l[w]=a.shallowRef(!1);const O=Reflect.get(_,w,V);return e?a.toValue(O):O}});return $}function he(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function ae(r){const e={type:r.type,clientId:r.clientId,timestamp:r.timestamp.toISOString()};return r.operation&&(e.operation={...r.operation,timestamp:r.operation.timestamp.toISOString()}),r.operations&&(e.operations=r.operations.map(t=>({...t,timestamp:t.timestamp.toISOString()}))),e}function nt(r){const e={type:r.type,clientId:r.clientId,timestamp:new Date(r.timestamp)};return r.operation&&(e.operation={...r.operation,timestamp:new Date(r.operation.timestamp)}),r.operations&&(e.operations=r.operations.map(t=>({...t,timestamp:new Date(t.timestamp)}))),e}const Y=Ve("hst-operation-log",()=>{const r=a.ref({maxOperations:100,enableCrossTabSync:!0,autoSyncInterval:3e4,enablePersistence:!1,persistenceKeyPrefix:"stonecrop-ops"}),e=a.ref([]),t=a.ref(-1),o=a.ref(he()),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),f=a.computed(()=>{let h=0;for(let g=t.value;g>=0&&e.value[g]?.reversible;g--)h++;return h}),b=a.computed(()=>e.value.length-1-t.value),E=a.computed(()=>({canUndo:c.value,canRedo:l.value,undoCount:f.value,redoCount:b.value,currentIndex:t.value}));function N(h){r.value={...r.value,...h},r.value.enablePersistence&&(k(),F()),r.value.enableCrossTabSync&&d()}function D(h,g="user"){const m={...h,id:he(),timestamp:new Date,source:g,userId:r.value.userId};if(r.value.operationFilter&&!r.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++,r.value.maxOperations&&e.value.length>r.value.maxOperations){const M=e.value.length-r.value.maxOperations;e.value=e.value.slice(M),t.value-=M}return r.value.enableCrossTabSync&&R(m),m.id}function A(){n.value=!0,s.value=[],i.value=he()}function L(h){if(!n.value||s.value.length===0)return n.value=!1,s.value=[],i.value=null,null;const g=i.value,m=s.value.every(W=>W.reversible),M={id:g,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:h}};s.value.forEach(W=>{W.parentOperationId=g}),e.value.push(...s.value,M),t.value=e.value.length-1,r.value.enableCrossTabSync&&v(s.value,M);const z=g;return n.value=!1,s.value=[],i.value=null,z}function P(){n.value=!1,s.value=[],i.value=null}function $(h){if(!c.value)return!1;const g=e.value[t.value];if(!g.reversible)return typeof console<"u"&&g.irreversibleReason&&console.warn("Cannot undo irreversible operation:",g.irreversibleReason),!1;try{if(g.type==="batch"&&g.childOperationIds)for(let m=g.childOperationIds.length-1;m>=0;m--){const M=g.childOperationIds[m],z=e.value.find(W=>W.id===M);z&&w(z,h)}else w(g,h);return t.value--,r.value.enableCrossTabSync&&p(g),!0}catch(m){return typeof console<"u"&&console.error("Undo failed:",m),!1}}function _(h){if(!l.value)return!1;const g=e.value[t.value+1];try{if(g.type==="batch"&&g.childOperationIds)for(const m of g.childOperationIds){const M=e.value.find(z=>z.id===m);M&&V(M,h)}else V(g,h);return t.value++,r.value.enableCrossTabSync&&S(g),!0}catch(m){return typeof console<"u"&&console.error("Redo failed:",m),!1}}function w(h,g){(h.type==="set"||h.type==="delete")&&g&&typeof g.set=="function"&&g.set(h.path,h.beforeValue,"undo")}function V(h,g){(h.type==="set"||h.type==="delete")&&g&&typeof g.set=="function"&&g.set(h.path,h.afterValue,"redo")}function O(){const h=e.value.filter(m=>m.reversible).length,g=e.value.map(m=>m.timestamp);return{operations:[...e.value],currentIndex:t.value,totalOperations:e.value.length,reversibleOperations:h,irreversibleOperations:e.value.length-h,oldestOperation:g.length>0?new Date(Math.min(...g.map(m=>m.getTime()))):void 0,newestOperation:g.length>0?new Date(Math.max(...g.map(m=>m.getTime()))):void 0}}function T(){e.value=[],t.value=-1}function y(h,g){return e.value.filter(m=>m.doctype===h&&(g===void 0||m.recordId===g))}function B(h,g){const m=e.value.find(M=>M.id===h);m&&(m.reversible=!1,m.irreversibleReason=g)}function x(h,g,m,M="success",z){const W={type:"action",path:m&&m.length>0?`${h}.${m[0]}`:h,fieldname:"",beforeValue:null,afterValue:null,doctype:h,recordId:m&&m.length>0?m[0]:void 0,reversible:!1,actionName:g,actionRecordIds:m,actionResult:M,actionError:z};return D(W)}let u=null;function d(){typeof window>"u"||!window.BroadcastChannel||(u=new BroadcastChannel("stonecrop-operation-log"),u.addEventListener("message",h=>{const g=h.data;if(!g||typeof g!="object")return;const m=nt(g);m.clientId!==o.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(h){if(!u)return;const g={type:"operation",operation:h,clientId:o.value,timestamp:new Date};u.postMessage(ae(g))}function v(h,g){if(!u)return;const m={type:"operation",operations:[...h,g],clientId:o.value,timestamp:new Date};u.postMessage(ae(m))}function p(h){if(!u)return;const g={type:"undo",operation:h,clientId:o.value,timestamp:new Date};u.postMessage(ae(g))}function S(h){if(!u)return;const g={type:"redo",operation:h,clientId:o.value,timestamp:new Date};u.postMessage(ae(g))}const I=tt("stonecrop-ops-operations",null,{serializer:{read:h=>{try{return JSON.parse(h)}catch{return null}},write:h=>h?JSON.stringify(h):""}});function k(){if(!(typeof window>"u"))try{const h=I.value;h&&Array.isArray(h.operations)&&(e.value=h.operations.map(g=>({...g,timestamp:new Date(g.timestamp)})),t.value=h.currentIndex??-1)}catch(h){typeof console<"u"&&console.error("Failed to load operations from persistence:",h)}}function j(){if(!(typeof window>"u"))try{I.value={operations:e.value.map(h=>({...h,timestamp:h.timestamp.toISOString()})),currentIndex:t.value}}catch(h){typeof console<"u"&&console.error("Failed to save operations to persistence:",h)}}function F(){a.watch([e,t],()=>{r.value.enablePersistence&&j()},{deep:!0})}return{operations:e,currentIndex:t,config:r,clientId:o,undoRedoState:E,canUndo:c,canRedo:l,undoCount:f,redoCount:b,configure:N,addOperation:D,startBatch:A,commitBatch:L,cancelBatch:P,undo:$,redo:_,clear:T,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,o){this.fieldRollbackConfig.has(e)||this.fieldRollbackConfig.set(e,new Map),this.fieldRollbackConfig.get(e).set(t,o)}getFieldRollback(e,t){return this.fieldRollbackConfig.get(e)?.get(t)}registerDoctypeActions(e,t){if(!t)return;const o=new Map,n=new Map;if(typeof t.entrySeq=="function")t.entrySeq().forEach(([s,i])=>{this.categorizeAction(s,i,o,n)});else if(t instanceof Map)for(const[s,i]of t)this.categorizeAction(s,i,o,n);else t&&typeof t=="object"&&Object.entries(t).forEach(([s,i])=>{this.categorizeAction(s,i,o,n)});this.doctypeActions.set(e,o),this.doctypeTransitions.set(e,n)}categorizeAction(e,t,o,n){this.isTransitionKey(e)?n.set(e,t):o.set(e,t)}isTransitionKey(e){return/^[A-Z0-9_]+$/.test(e)&&e.length>0}async executeFieldTriggers(e,t={}){const{doctype:o,fieldname:n}=e,s=this.findFieldTriggers(o,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,f=!1,b;const E=this.getFieldRollback(o,n),N=t.enableRollback??E??this.options.enableRollback;N&&e.store&&(b=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 w={success:!1,error:$ instanceof Error?$:new Error(String($)),executionTime:0,action:P};c.push(w),l=!0;break}if(N&&l&&b&&e.store)try{this.restoreSnapshot(e,b),f=!0}catch(P){console.error("[FieldTriggers] Rollback failed:",P)}const D=performance.now()-i,A=c.filter(P=>!P.success);if(A.length>0&&this.options.errorHandler)for(const P of A)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:f,snapshot:this.options.debug&&N?b:void 0}}async executeTransitionActions(e,t={}){const{doctype:o,transition:n}=e,s=this.findTransitionActions(o,n);if(s.length===0)return[];const i=[];for(const l of s)try{const f=await this.executeTransitionAction(l,e,t.timeout);if(i.push(f),!f.success)break}catch(f){const E={success:!1,error:f instanceof Error?f:new Error(String(f)),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(f){console.error("[FieldTriggers] Error in global error handler:",f)}return i}findTransitionActions(e,t){const o=this.doctypeTransitions.get(e);return o?o.get(t)||[]:[]}async executeTransitionAction(e,t,o){const n=performance.now(),s=o??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 o=this.doctypeActions.get(e);if(!o)return[];const n=[];for(const[s,i]of o)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 o=e.split("."),n=t.split(".");if(o.length!==n.length)return!1;for(let s=0;s<o.length;s++){const i=o[s],c=n[s];if(i!=="*"&&i!==c)return!1}return!0}async executeAction(e,t,o){const n=performance.now(),s=o??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,o){return new Promise((n,s)=>{const i=setTimeout(()=>{s(new Error(`Action timeout after ${o}ms`))},o);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}`,o=e.store.get(t);return!o||typeof o!="object"?void 0:JSON.parse(JSON.stringify(o))}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 o=`${e.doctype}.${e.recordId}`;e.store.set(o,t),this.options.debug&&console.log(`[FieldTriggers] Rolled back ${o} to previous state`)}catch(o){throw console.error("[FieldTriggers] Failed to restore snapshot:",o),o}}}function H(r){return new oe(r)}function st(r,e){H().registerAction(r,e)}function it(r,e){H().registerTransitionAction(r,e)}function at(r,e,t){H().setFieldRollback(r,e,t)}async function ct(r,e,t){const o=H(),n={path:t?.path||(t?.recordId?`${r}.${t.recordId}`:r),fieldname:"",beforeValue:void 0,afterValue:void 0,operation:"set",doctype:r,recordId:t?.recordId,timestamp:new Date,transition:e,currentState:t?.currentState,targetState:t?.targetState,fsmContext:t?.fsmContext};return await o.executeTransitionActions(n)}function lt(r,e){if(r)try{Y().markIrreversible(r,e)}catch{}}function Ne(){try{return Y()}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,o="",n=null,s){return this.target=e,this.parentPath=o,this.rootNode=n||this,this.doctype=t,this.parentDoctype=s,this.hst=K.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 f=String(c);return i.set(f,l),!0}})}get(e){return this.resolveValue(e)}getNode(e){const t=this.resolvePath(e),o=this.resolveValue(e),n=t.split(".");let s=this.doctype;return this.doctype==="StonecropStore"&&n.length>=1&&(s=n[0]),typeof o=="object"&&o!==null&&!this.isPrimitive(o)?new ce(o,s,t,this.rootNode,this.parentDoctype):new ce(o,s,t,this.rootNode,this.parentDoctype)}set(e,t,o="user"){const n=this.resolvePath(e),s=this.has(e)?this.get(e):void 0;if(o!=="undo"&&o!=="redo"){const i=Ne();if(i&&typeof i.addOperation=="function"){const c=n.split("."),l=this.doctype==="StonecropStore"&&c.length>=1?c[0]:this.doctype,f=c.length>=2?c[1]:void 0,b=c.slice(2).join(".")||c[c.length-1],N=t===void 0&&s!==void 0?"delete":"set";i.addOperation({type:N,path:n,fieldname:b,beforeValue:s,afterValue:t,doctype:l,recordId:f,reversible:!0},o)}}this.updateValue(e,t),this.triggerFieldActions(n,s,t)}has(e){try{if(e==="")return!0;const t=this.parsePath(e);let o=this.target;for(let n=0;n<t.length;n++){const s=t[n];if(o==null)return!1;if(n===t.length-1)return this.isImmutable(o)?o.has(s):this.isPiniaStore(o)&&o.$state&&s in o.$state||s in o;o=this.getProperty(o,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 o=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=Ne();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 o.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 o=this.target;for(const n of t){if(o==null)return;o=this.getProperty(o,n)}return o}updateValue(e,t){if(e==="")throw new Error("Cannot set value on empty path");const o=this.parsePath(e),n=o.pop();let s=this.target;for(const i of o)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,o){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]:o}):e[t]=o;return}e[t]=o}async triggerFieldActions(e,t,o){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 f={path:e,fieldname:i,beforeValue:t,afterValue:o,operation:"set",doctype:c,recordId:l,timestamp:new Date,store:this.rootNode||void 0};await s.executeFieldTriggers(f)}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",o="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&&o;let i;try{const l=e;if("constructor"in l&&l.constructor&&typeof l.constructor=="object"&&"name"in l.constructor){const f=l.constructor.name;i=typeof f=="string"?f: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||o);return!!(t&&o&&n&&s||t&&o&&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(r,e,t){return new ce(r,e,"",null,t)}class ge{hstStore;_operationLogStore;_operationLogConfig;registry;constructor(e,t){this.registry=e,this._operationLogConfig=t,this.initializeHSTStore(),this.setupRegistrySync()}getOperationLogStore(){return this._operationLogStore||(this._operationLogStore=Y(),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,o){const n=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(n),this.hstStore.set(`${n}.${t}`,o)}getRecordById(e,t){const o=typeof e=="string"?e:e.slug;if(this.ensureDoctypeExists(o),!(!this.hstStore.has(`${o}.${t}`)||this.hstStore.get(`${o}.${t}`)===void 0))return this.hstStore.getNode(`${o}.${t}`)}removeRecord(e,t){const o=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(o),this.hstStore.has(`${o}.${t}`)&&this.hstStore.set(`${o}.${t}`,void 0)}getRecordIds(e){const t=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(t);const o=this.hstStore.get(t);return!o||typeof o!="object"?[]:Object.keys(o).filter(n=>o[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,o){const s=this.registry.registry[e.slug]?.actions?.get(t),i=Array.isArray(o)?o.filter(b=>typeof b=="string"):void 0,c=this.getOperationLogStore();let l="success",f;try{s&&s.length>0&&s.forEach(b=>{try{new Function("args",b)(o)}catch(E){throw l="failure",f=E instanceof Error?E.message:"Unknown error",E}})}catch{}finally{c.logAction(e.doctype,t,i,l,f)}}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 ut(r){r||(r={});const e=r.registry||a.inject("$registry"),t=a.inject("$stonecrop"),o=a.ref(),n=a.ref(),s=a.ref({}),i=a.ref(),c=a.ref(),l=a.ref([]),f=a.ref(-1),b=a.computed(()=>o.value?.getOperationLogStore().canUndo??!1),E=a.computed(()=>o.value?.getOperationLogStore().canRedo??!1),N=a.computed(()=>o.value?.getOperationLogStore().undoCount??0),D=a.computed(()=>o.value?.getOperationLogStore().redoCount??0),A=a.computed(()=>o.value?.getOperationLogStore().undoRedoState??{canUndo:!1,canRedo:!1,undoCount:0,redoCount:0,currentIndex:-1}),L=v=>o.value?.getOperationLogStore().undo(v)??!1,P=v=>o.value?.getOperationLogStore().redo(v)??!1,$=()=>{o.value?.getOperationLogStore().startBatch()},_=v=>o.value?.getOperationLogStore().commitBatch(v)??null,w=()=>{o.value?.getOperationLogStore().cancelBatch()},V=()=>{o.value?.getOperationLogStore().clear()},O=(v,p)=>o.value?.getOperationLogStore().getOperationsFor(v,p)??[],T=()=>o.value?.getOperationLogStore().getSnapshot()??{operations:[],currentIndex:-1,totalOperations:0,reversibleOperations:0,irreversibleOperations:0},y=(v,p)=>{o.value?.getOperationLogStore().markIrreversible(v,p)},B=(v,p,S,I="success",k)=>o.value?.getOperationLogStore().logAction(v,p,S,I,k)??"",x=v=>{o.value?.getOperationLogStore().configure(v)};a.onMounted(async()=>{if(e){o.value=t||new ge(e);try{const v=o.value.getOperationLogStore(),p=Oe(v);l.value=p.operations.value,f.value=p.currentIndex.value,a.watch(()=>p.operations.value,S=>{l.value=S}),a.watch(()=>p.currentIndex.value,S=>{f.value=S})}catch{}if(!r.doctype&&e.router){const v=e.router.currentRoute.value;if(!v.path)return;const p=v.path.split("/").filter(I=>I.length>0),S=p[1]?.toLowerCase();if(p.length>0){const I={path:v.path,segments:p},k=await e.getMeta?.(I);if(k){if(e.addDoctype(k),o.value.setup(k),i.value=k,c.value=S,n.value=o.value.getStore(),S&&S!=="new"){const j=o.value.getRecordById(k,S);if(j)s.value=j.get("")||{};else try{await o.value.getRecord(k,S);const F=o.value.getRecordById(k,S);F&&(s.value=F.get("")||{})}catch{s.value=le(k)}}else s.value=le(k);n.value&&Te(k,S||"new",s,n.value),o.value.runAction(k,"load",S?[S]:void 0)}}}if(r.doctype){n.value=o.value.getStore();const v=r.doctype,p=r.recordId;if(p&&p!=="new"){const S=o.value.getRecordById(v,p);if(S)s.value=S.get("")||{};else try{await o.value.getRecord(v,p);const I=o.value.getRecordById(v,p);I&&(s.value=I.get("")||{})}catch{s.value=le(v)}}else s.value=le(v);n.value&&Te(v,p||"new",s,n.value)}}});const u=(v,p)=>{const S=r.doctype||i.value;if(!S)return"";const I=p||r.recordId||c.value||"new";return`${S.slug}.${I}.${v}`},d=v=>{const p=r.doctype||i.value;if(!(!n.value||!o.value||!p))try{const S=v.path.split(".");if(S.length>=2){const j=S[0],F=S[1];if(n.value.has(`${j}.${F}`)||o.value.addRecord(p,F,{...s.value}),S.length>3){const h=`${j}.${F}`,g=S.slice(2);let m=h;for(let M=0;M<g.length-1;M++)if(m+=`.${g[M]}`,!n.value.has(m)){const z=g[M+1],W=!isNaN(Number(z));n.value.set(m,W?[]:{})}}}n.value.set(v.path,v.value);const I=v.fieldname.split("."),k={...s.value};I.length===1?k[I[0]]=v.value:ft(k,I,v.value),s.value=k}catch{}};(r.doctype||e?.router)&&(a.provide("hstPathProvider",u),a.provide("hstChangeHandler",d));const R={operations:l,currentIndex:f,undoRedoState:A,canUndo:b,canRedo:E,undoCount:N,redoCount:D,undo:L,redo:P,startBatch:$,commitBatch:_,cancelBatch:w,clear:V,getOperationsFor:O,getSnapshot:T,markIrreversible:y,logAction:B,configure:x};return r.doctype?{stonecrop:o,operationLog:R,provideHSTPath:u,handleHSTChange:d,hstStore:n,formData:s}:!r.doctype&&e?.router?{stonecrop:o,operationLog:R,provideHSTPath:u,handleHSTChange:d,hstStore:n,formData:s}:{stonecrop:o,operationLog:R}}function le(r){const e={};return r.schema&&r.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(r,e,t,o){a.watch(t,n=>{const s=`${r.slug}.${e}`;Object.keys(n).forEach(i=>{const c=`${s}.${i}`;try{o.set(c,n[i])}catch{}})},{deep:!0})}function ft(r,e,t){let o=r;for(let s=0;s<e.length-1;s++){const i=e[s];(!(i in o)||typeof o[i]!="object")&&(o[i]=isNaN(Number(e[s+1]))?{}:[]),o=o[i]}const n=e[e.length-1];o[n]=t}function ye(r){const t=a.inject("$operationLogStore",void 0)||Y();r&&t.configure(r);const{operations:o,currentIndex:n,undoRedoState:s,canUndo:i,canRedo:c,undoCount:l,redoCount:f}=Oe(t);function b(O){return t.undo(O)}function E(O){return t.redo(O)}function N(){t.startBatch()}function D(O){return t.commitBatch(O)}function A(){t.cancelBatch()}function L(){t.clear()}function P(O,T){return t.getOperationsFor(O,T)}function $(){return t.getSnapshot()}function _(O,T){t.markIrreversible(O,T)}function w(O,T,y,B="success",x){return t.logAction(O,T,y,B,x)}function V(O){t.configure(O)}return{operations:o,currentIndex:n,undoRedoState:s,canUndo:i,canRedo:c,undoCount:l,redoCount:f,undo:b,redo:E,startBatch:N,commitBatch:D,cancelBatch:A,clear:L,getOperationsFor:P,getSnapshot:$,markIrreversible:_,logAction:w,configure:V}}function dt(r,e=!0){if(!e)return;const{undo:t,redo:o,canUndo:n,canRedo:s}=ye(),i=ot();re(i["Ctrl+Z"],()=>{n.value&&t(r)}),re(i["Meta+Z"],()=>{n.value&&t(r)}),re(i["Ctrl+Shift+Z"],()=>{s.value&&o(r)}),re(i["Meta+Shift+Z"],()=>{s.value&&o(r)}),re(i["Ctrl+Y"],()=>{s.value&&o(r)})}async function pt(r,e){const{startBatch:t,commitBatch:o,cancelBatch:n}=ye();t();try{return await r(),o(e)}catch(s){throw n(),s}}class ht{doctype;schema;workflow;actions;component;constructor(e,t,o,n,s){this.doctype=e,this.schema=t,this.workflow=o,this.actions=n,this.component=s}get slug(){return this.doctype.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}}class Q{static _root;name;registry;router;constructor(e,t){if(Q._root)return Q._root;Q._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 gt(r,e,t){await a.nextTick();try{await t(r,e)}catch{}}const yt={install:(r,e)=>{const t=r.config.globalProperties.$router,o=e?.router,n=t||o;!t&&o&&r.use(o);const s=new Q(n,e?.getMeta);r.provide("$registry",s),r.config.globalProperties.$registry=s;const i=new ge(s);r.provide("$stonecrop",i),r.config.globalProperties.$stonecrop=i;try{const c=r.config.globalProperties.$pinia;if(c){const l=Y(c);r.provide("$operationLogStore",l),r.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))r.component(c,l);e?.autoInitializeRouter&&e.onRouterInitialized&&gt(s,i,e.onRouterInitialized)}};C.DoctypeMeta=ht,C.HST=K,C.Registry=Q,C.Stonecrop=ge,C.createHST=Ie,C.default=yt,C.getGlobalTriggerEngine=H,C.markOperationIrreversible=lt,C.registerGlobalAction=st,C.registerTransitionAction=it,C.setFieldRollback=at,C.triggerTransition=ct,C.useOperationLog=ye,C.useOperationLogStore=Y,C.useStonecrop=ut,C.useUndoRedoShortcuts=dt,C.withBatch=pt,Object.defineProperties(C,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
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"}})}));
10
6
  //# sourceMappingURL=stonecrop.umd.cjs.map