@stonecrop/desktop 0.8.1 → 0.8.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,8 +1,8 @@
1
- (function(J,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(J=typeof globalThis<"u"?globalThis:J||self,t(J["@stonecrop/desktop"]={},J.Vue))})(this,(function(J,t){"use strict";const Fe={class:"action-menu-icon"},Le=["disabled","onClick"],He={key:1},Ue=["onClick"],We={class:"dropdown-container"},Ke={class:"dropdown"},ze=["onClick"],Je=["href"],Ge={class:"dropdown-item"},qe=t.defineComponent({__name:"ActionSet",props:{elements:{default:()=>[]}},emits:["actionClick"],setup(o,{emit:e}){const a=e,n=t.ref({}),r=t.ref(!1),i=t.ref(-1),s=t.ref(!1),u=t.ref(!1);t.onMounted(()=>{l()});const l=()=>{n.value={}},d=()=>{s.value=!0,i.value=setTimeout(()=>{s.value&&(r.value=!0)},500)},f=()=>{s.value=!1,u.value=!1,clearTimeout(i.value),r.value=!1},g=R=>{const _=!n.value[R];l(),_&&(n.value[R]=!0)},b=(R,_)=>{a("actionClick",_,R)};return(R,_)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass([{"open-set":r.value,"hovered-and-closed":u.value},"action-set collapse"]),onMouseover:d,onMouseleave:f},[t.createElementVNode("div",Fe,[t.createElementVNode("div",{id:"chevron",onClick:_[0]||(_[0]=O=>u.value=!u.value)},[..._[1]||(_[1]=[t.createElementVNode("svg",{id:"Layer_1",class:"leftBar",version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",x:"0px",y:"0px",viewBox:"0 0 100 100","xml:space":"preserve",width:"50",height:"50"},[t.createElementVNode("polygon",{points:"54.2,33.4 29.2,58.8 25,54.6 50,29.2 "})],-1),t.createElementVNode("svg",{id:"Layer_1",class:"rightBar",version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",x:"0px",y:"0px",viewBox:"0 0 100 100","xml:space":"preserve",width:"50",height:"50"},[t.createElementVNode("polygon",{points:"70.8,58.8 45.8,33.4 50,29.2 75,54.6 "})],-1)])])]),_[2]||(_[2]=t.createElementVNode("div",{style:{"margin-right":"30px"}},null,-1)),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.elements,(O,I)=>(t.openBlock(),t.createElementBlock("div",{key:O.label,class:"action-element"},[O.type=="button"?(t.openBlock(),t.createElementBlock("button",{key:0,disabled:O.disabled,class:"button-default",onClick:x=>b(O.action,O.label)},t.toDisplayString(O.label),9,Le)):t.createCommentVNode("",!0),O.type=="dropdown"?(t.openBlock(),t.createElementBlock("div",He,[t.createElementVNode("button",{class:"button-default",onClick:x=>g(I)},t.toDisplayString(O.label),9,Ue),t.withDirectives(t.createElementVNode("div",We,[t.createElementVNode("div",Ke,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(O.actions,(x,T)=>(t.openBlock(),t.createElementBlock("div",{key:x.label},[x.action!=null?(t.openBlock(),t.createElementBlock("button",{key:0,class:"dropdown-item",onClick:j=>b(x.action,x.label)},t.toDisplayString(x.label),9,ze)):x.link!=null?(t.openBlock(),t.createElementBlock("a",{key:1,href:x.link},[t.createElementVNode("button",Ge,t.toDisplayString(x.label),1)],8,Je)):t.createCommentVNode("",!0)]))),128))])],512),[[t.vShow,n.value[I]]])])):t.createCommentVNode("",!0)]))),128))],34))}}),ke=(o,e)=>{const a=o.__vccOpts||o;for(const[n,r]of e)a[n]=r;return a},de=ke(qe,[["__scopeId","data-v-eb01c863"]]),Ze={class:"command-palette-header"},Qe=["placeholder"],Xe={key:0,class:"command-palette-results"},Ye=["onClick","onMouseover"],et={class:"result-title"},tt={class:"result-content"},ot={key:1,class:"command-palette-no-results"},pe=t.defineComponent({__name:"CommandPalette",props:{search:{type:Function},isOpen:{type:Boolean,default:!1},placeholder:{default:"Type a command or search..."},maxResults:{default:10}},emits:["select","close"],setup(o,{emit:e}){const a=e,n=t.ref(""),r=t.ref(0),i=t.useTemplateRef("input"),s=t.computed(()=>n.value?o.search(n.value).slice(0,o.maxResults):[]);t.watch(()=>o.isOpen,async f=>{f&&(n.value="",r.value=0,await t.nextTick(),i.value?.focus())}),t.watch(s,()=>{r.value=0});const u=()=>{a("close")},l=f=>{switch(f.key){case"Escape":u();break;case"ArrowDown":f.preventDefault(),s.value.length&&(r.value=(r.value+1)%s.value.length);break;case"ArrowUp":f.preventDefault(),s.value.length&&(r.value=(r.value-1+s.value.length)%s.value.length);break;case"Enter":s.value.length&&r.value>=0&&d(s.value[r.value]);break}},d=f=>{a("select",f),u()};return(f,g)=>(t.openBlock(),t.createBlock(t.Teleport,{to:"body"},[t.createVNode(t.Transition,{name:"fade"},{default:t.withCtx(()=>[o.isOpen?(t.openBlock(),t.createElementBlock("div",{key:0,class:"command-palette-overlay",onClick:u},[t.createElementVNode("div",{class:"command-palette",onClick:g[1]||(g[1]=t.withModifiers(()=>{},["stop"]))},[t.createElementVNode("div",Ze,[t.withDirectives(t.createElementVNode("input",{ref:"input","onUpdate:modelValue":g[0]||(g[0]=b=>n.value=b),type:"text",class:"command-palette-input",placeholder:o.placeholder,autofocus:"",onKeydown:l},null,40,Qe),[[t.vModelText,n.value]])]),s.value.length?(t.openBlock(),t.createElementBlock("div",Xe,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(s.value,(b,R)=>(t.openBlock(),t.createElementBlock("div",{key:R,class:t.normalizeClass(["command-palette-result",{selected:R===r.value}]),onClick:_=>d(b),onMouseover:_=>r.value=R},[t.createElementVNode("div",et,[t.renderSlot(f.$slots,"title",{result:b})]),t.createElementVNode("div",tt,[t.renderSlot(f.$slots,"content",{result:b})])],42,Ye))),128))])):n.value&&!s.value.length?(t.openBlock(),t.createElementBlock("div",ot,[t.renderSlot(f.$slots,"empty",{},()=>[t.createTextVNode(' No results found for "'+t.toDisplayString(n.value)+'" ',1)])])):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0)]),_:3})]))}}),ee=typeof window<"u";let te;const re=o=>te=o;process.env.NODE_ENV;const at=process.env.NODE_ENV!=="production"?Symbol("pinia"):Symbol();function Q(o){return o&&typeof o=="object"&&Object.prototype.toString.call(o)==="[object Object]"&&typeof o.toJSON!="function"}var oe;(function(o){o.direct="direct",o.patchObject="patch object",o.patchFunction="patch function"})(oe||(oe={}));function Ne(o,e){for(const a in e){const n=e[a];if(!(a in o))continue;const r=o[a];Q(r)&&Q(n)&&!t.isRef(n)&&!t.isReactive(n)?o[a]=Ne(r,n):o[a]=n}return o}const $e=()=>{};function _e(o,e,a,n=$e){o.add(e);const r=()=>{o.delete(e)&&n()};return!a&&t.getCurrentScope()&&t.onScopeDispose(r),r}function X(o,...e){o.forEach(a=>{a(...e)})}const nt=o=>o(),Re=Symbol(),fe=Symbol();function he(o,e){o instanceof Map&&e instanceof Map?e.forEach((a,n)=>o.set(n,a)):o instanceof Set&&e instanceof Set&&e.forEach(o.add,o);for(const a in e){if(!e.hasOwnProperty(a))continue;const n=e[a],r=o[a];Q(r)&&Q(n)&&o.hasOwnProperty(a)&&!t.isRef(n)&&!t.isReactive(n)?o[a]=he(r,n):o[a]=n}return o}const rt=process.env.NODE_ENV!=="production"?Symbol("pinia:skipHydration"):Symbol();function st(o){return!Q(o)||!Object.prototype.hasOwnProperty.call(o,rt)}const{assign:z}=Object;function De(o){return!!(t.isRef(o)&&o.effect)}function Oe(o,e,a,n){const{state:r,actions:i,getters:s}=e,u=a.state.value[o];let l;function d(){!u&&(process.env.NODE_ENV==="production"||!n)&&(a.state.value[o]=r?r():{});const f=process.env.NODE_ENV!=="production"&&n?t.toRefs(t.ref(r?r():{}).value):t.toRefs(a.state.value[o]);return z(f,i,Object.keys(s||{}).reduce((g,b)=>(process.env.NODE_ENV!=="production"&&b in f&&console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${b}" in store "${o}".`),g[b]=t.markRaw(t.computed(()=>{re(a);const R=a._s.get(o);return s[b].call(R,R)})),g),{}))}return l=me(o,d,e,a,n,!0),l}function me(o,e,a={},n,r,i){let s;const u=z({actions:{}},a);if(process.env.NODE_ENV!=="production"&&!n._e.active)throw new Error("Pinia destroyed");const l={deep:!0};process.env.NODE_ENV!=="production"&&(l.onTrigger=w=>{d?R=w:d==!1&&!N._hotUpdating&&(Array.isArray(R)?R.push(w):console.error("🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug."))});let d,f,g=new Set,b=new Set,R;const _=n.state.value[o];!i&&!_&&(process.env.NODE_ENV==="production"||!r)&&(n.state.value[o]={});const O=t.ref({});let I;function x(w){let y;d=f=!1,process.env.NODE_ENV!=="production"&&(R=[]),typeof w=="function"?(w(n.state.value[o]),y={type:oe.patchFunction,storeId:o,events:R}):(he(n.state.value[o],w),y={type:oe.patchObject,payload:w,storeId:o,events:R});const V=I=Symbol();t.nextTick().then(()=>{I===V&&(d=!0)}),f=!0,X(g,y,n.state.value[o])}const T=i?function(){const{state:w}=a,y=w?w():{};this.$patch(V=>{z(V,y)})}:process.env.NODE_ENV!=="production"?()=>{throw new Error(`🍍: Store "${o}" is built using the setup syntax and does not implement $reset().`)}:$e;function j(){s.stop(),g.clear(),b.clear(),n._s.delete(o)}const K=(w,y="")=>{if(Re in w)return w[fe]=y,w;const V=function(){re(n);const P=Array.from(arguments),U=new Set,D=new Set;function A(k){U.add(k)}function B(k){D.add(k)}X(b,{args:P,name:V[fe],store:N,after:A,onError:B});let S;try{S=w.apply(this&&this.$id===o?this:N,P)}catch(k){throw X(D,k),k}return S instanceof Promise?S.then(k=>(X(U,k),k)).catch(k=>(X(D,k),Promise.reject(k))):(X(U,S),S)};return V[Re]=!0,V[fe]=y,V},H=t.markRaw({actions:{},getters:{},state:[],hotState:O}),F={_p:n,$id:o,$onAction:_e.bind(null,b),$patch:x,$reset:T,$subscribe(w,y={}){const V=_e(g,w,y.detached,()=>P()),P=s.run(()=>t.watch(()=>n.state.value[o],U=>{(y.flush==="sync"?f:d)&&w({storeId:o,type:oe.direct,events:R},U)},z({},l,y)));return V},$dispose:j},N=t.reactive(process.env.NODE_ENV!=="production"||process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&ee?z({_hmrPayload:H,_customProperties:t.markRaw(new Set)},F):F);n._s.set(o,N);const M=(n._a&&n._a.runWithContext||nt)(()=>n._e.run(()=>(s=t.effectScope()).run(()=>e({action:K}))));for(const w in M){const y=M[w];if(t.isRef(y)&&!De(y)||t.isReactive(y))process.env.NODE_ENV!=="production"&&r?O.value[w]=t.toRef(M,w):i||(_&&st(y)&&(t.isRef(y)?y.value=_[w]:he(y,_[w])),n.state.value[o][w]=y),process.env.NODE_ENV!=="production"&&H.state.push(w);else if(typeof y=="function"){const V=process.env.NODE_ENV!=="production"&&r?y:K(y,w);M[w]=V,process.env.NODE_ENV!=="production"&&(H.actions[w]=y),u.actions[w]=y}else process.env.NODE_ENV!=="production"&&De(y)&&(H.getters[w]=i?a.getters[w]:y,ee&&(M._getters||(M._getters=t.markRaw([]))).push(w))}if(z(N,M),z(t.toRaw(N),M),Object.defineProperty(N,"$state",{get:()=>process.env.NODE_ENV!=="production"&&r?O.value:n.state.value[o],set:w=>{if(process.env.NODE_ENV!=="production"&&r)throw new Error("cannot set hotState");x(y=>{z(y,w)})}}),process.env.NODE_ENV!=="production"&&(N._hotUpdate=t.markRaw(w=>{N._hotUpdating=!0,w._hmrPayload.state.forEach(y=>{if(y in N.$state){const V=w.$state[y],P=N.$state[y];typeof V=="object"&&Q(V)&&Q(P)?Ne(V,P):w.$state[y]=P}N[y]=t.toRef(w.$state,y)}),Object.keys(N.$state).forEach(y=>{y in w.$state||delete N[y]}),d=!1,f=!1,n.state.value[o]=t.toRef(w._hmrPayload,"hotState"),f=!0,t.nextTick().then(()=>{d=!0});for(const y in w._hmrPayload.actions){const V=w[y];N[y]=K(V,y)}for(const y in w._hmrPayload.getters){const V=w._hmrPayload.getters[y],P=i?t.computed(()=>(re(n),V.call(N,N))):V;N[y]=P}Object.keys(N._hmrPayload.getters).forEach(y=>{y in w._hmrPayload.getters||delete N[y]}),Object.keys(N._hmrPayload.actions).forEach(y=>{y in w._hmrPayload.actions||delete N[y]}),N._hmrPayload=w._hmrPayload,N._getters=w._getters,N._hotUpdating=!1})),process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&ee){const w={writable:!0,configurable:!0,enumerable:!1};["_p","_hmrPayload","_getters","_customProperties"].forEach(y=>{Object.defineProperty(N,y,z({value:N[y]},w))})}return n._p.forEach(w=>{if(process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&ee){const y=s.run(()=>w({store:N,app:n._a,pinia:n,options:u}));Object.keys(y||{}).forEach(V=>N._customProperties.add(V)),z(N,y)}else z(N,s.run(()=>w({store:N,app:n._a,pinia:n,options:u})))}),process.env.NODE_ENV!=="production"&&N.$state&&typeof N.$state=="object"&&typeof N.$state.constructor=="function"&&!N.$state.constructor.toString().includes("[native code]")&&console.warn(`[🍍]: The "state" must be a plain object. It cannot be
1
+ (function(J,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(J=typeof globalThis<"u"?globalThis:J||self,t(J["@stonecrop/desktop"]={},J.Vue))})(this,(function(J,t){"use strict";const Fe={class:"action-menu-icon"},Le=["disabled","onClick"],He={key:1},Ue=["onClick"],We={class:"dropdown-container"},Ke={class:"dropdown"},ze=["onClick"],Je=["href"],Ge={class:"dropdown-item"},qe=t.defineComponent({__name:"ActionSet",props:{elements:{default:()=>[]}},emits:["actionClick"],setup(o,{emit:e}){const a=e,n=t.ref({}),r=t.ref(!1),i=t.ref(-1),s=t.ref(!1),u=t.ref(!1);t.onMounted(()=>{l()});const l=()=>{n.value={}},d=()=>{s.value=!0,i.value=setTimeout(()=>{s.value&&(r.value=!0)},500)},f=()=>{s.value=!1,u.value=!1,clearTimeout(i.value),r.value=!1},g=D=>{const _=!n.value[D];l(),_&&(n.value[D]=!0)},b=(D,_)=>{a("actionClick",_,D)};return(D,_)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass([{"open-set":r.value,"hovered-and-closed":u.value},"action-set collapse"]),onMouseover:d,onMouseleave:f},[t.createElementVNode("div",Fe,[t.createElementVNode("div",{id:"chevron",onClick:_[0]||(_[0]=O=>u.value=!u.value)},[..._[1]||(_[1]=[t.createElementVNode("svg",{id:"Layer_1",class:"leftBar",version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",x:"0px",y:"0px",viewBox:"0 0 100 100","xml:space":"preserve",width:"50",height:"50"},[t.createElementVNode("polygon",{points:"54.2,33.4 29.2,58.8 25,54.6 50,29.2 "})],-1),t.createElementVNode("svg",{id:"Layer_1",class:"rightBar",version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",x:"0px",y:"0px",viewBox:"0 0 100 100","xml:space":"preserve",width:"50",height:"50"},[t.createElementVNode("polygon",{points:"70.8,58.8 45.8,33.4 50,29.2 75,54.6 "})],-1)])])]),_[2]||(_[2]=t.createElementVNode("div",{style:{"margin-right":"30px"}},null,-1)),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.elements,(O,I)=>(t.openBlock(),t.createElementBlock("div",{key:O.label,class:"action-element"},[O.type=="button"?(t.openBlock(),t.createElementBlock("button",{key:0,disabled:O.disabled,class:"button-default",onClick:x=>b(O.action,O.label)},t.toDisplayString(O.label),9,Le)):t.createCommentVNode("",!0),O.type=="dropdown"?(t.openBlock(),t.createElementBlock("div",He,[t.createElementVNode("button",{class:"button-default",onClick:x=>g(I)},t.toDisplayString(O.label),9,Ue),t.withDirectives(t.createElementVNode("div",We,[t.createElementVNode("div",Ke,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(O.actions,(x,T)=>(t.openBlock(),t.createElementBlock("div",{key:x.label},[x.action!=null?(t.openBlock(),t.createElementBlock("button",{key:0,class:"dropdown-item",onClick:j=>b(x.action,x.label)},t.toDisplayString(x.label),9,ze)):x.link!=null?(t.openBlock(),t.createElementBlock("a",{key:1,href:x.link},[t.createElementVNode("button",Ge,t.toDisplayString(x.label),1)],8,Je)):t.createCommentVNode("",!0)]))),128))])],512),[[t.vShow,n.value[I]]])])):t.createCommentVNode("",!0)]))),128))],34))}}),ke=(o,e)=>{const a=o.__vccOpts||o;for(const[n,r]of e)a[n]=r;return a},de=ke(qe,[["__scopeId","data-v-eb01c863"]]),Ze={class:"command-palette-header"},Qe=["placeholder"],Xe={key:0,class:"command-palette-results"},Ye=["onClick","onMouseover"],et={class:"result-title"},tt={class:"result-content"},ot={key:1,class:"command-palette-no-results"},pe=t.defineComponent({__name:"CommandPalette",props:{search:{type:Function},isOpen:{type:Boolean,default:!1},placeholder:{default:"Type a command or search..."},maxResults:{default:10}},emits:["select","close"],setup(o,{emit:e}){const a=e,n=t.ref(""),r=t.ref(0),i=t.useTemplateRef("input"),s=t.computed(()=>n.value?o.search(n.value).slice(0,o.maxResults):[]);t.watch(()=>o.isOpen,async f=>{f&&(n.value="",r.value=0,await t.nextTick(),i.value?.focus())}),t.watch(s,()=>{r.value=0});const u=()=>{a("close")},l=f=>{switch(f.key){case"Escape":u();break;case"ArrowDown":f.preventDefault(),s.value.length&&(r.value=(r.value+1)%s.value.length);break;case"ArrowUp":f.preventDefault(),s.value.length&&(r.value=(r.value-1+s.value.length)%s.value.length);break;case"Enter":s.value.length&&r.value>=0&&d(s.value[r.value]);break}},d=f=>{a("select",f),u()};return(f,g)=>(t.openBlock(),t.createBlock(t.Teleport,{to:"body"},[t.createVNode(t.Transition,{name:"fade"},{default:t.withCtx(()=>[o.isOpen?(t.openBlock(),t.createElementBlock("div",{key:0,class:"command-palette-overlay",onClick:u},[t.createElementVNode("div",{class:"command-palette",onClick:g[1]||(g[1]=t.withModifiers(()=>{},["stop"]))},[t.createElementVNode("div",Ze,[t.withDirectives(t.createElementVNode("input",{ref:"input","onUpdate:modelValue":g[0]||(g[0]=b=>n.value=b),type:"text",class:"command-palette-input",placeholder:o.placeholder,autofocus:"",onKeydown:l},null,40,Qe),[[t.vModelText,n.value]])]),s.value.length?(t.openBlock(),t.createElementBlock("div",Xe,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(s.value,(b,D)=>(t.openBlock(),t.createElementBlock("div",{key:D,class:t.normalizeClass(["command-palette-result",{selected:D===r.value}]),onClick:_=>d(b),onMouseover:_=>r.value=D},[t.createElementVNode("div",et,[t.renderSlot(f.$slots,"title",{result:b})]),t.createElementVNode("div",tt,[t.renderSlot(f.$slots,"content",{result:b})])],42,Ye))),128))])):n.value&&!s.value.length?(t.openBlock(),t.createElementBlock("div",ot,[t.renderSlot(f.$slots,"empty",{},()=>[t.createTextVNode(' No results found for "'+t.toDisplayString(n.value)+'" ',1)])])):t.createCommentVNode("",!0)])])):t.createCommentVNode("",!0)]),_:3})]))}}),ee=typeof window<"u";let te;const re=o=>te=o;process.env.NODE_ENV;const at=process.env.NODE_ENV!=="production"?Symbol("pinia"):Symbol();function Q(o){return o&&typeof o=="object"&&Object.prototype.toString.call(o)==="[object Object]"&&typeof o.toJSON!="function"}var oe;(function(o){o.direct="direct",o.patchObject="patch object",o.patchFunction="patch function"})(oe||(oe={}));function Ne(o,e){for(const a in e){const n=e[a];if(!(a in o))continue;const r=o[a];Q(r)&&Q(n)&&!t.isRef(n)&&!t.isReactive(n)?o[a]=Ne(r,n):o[a]=n}return o}const $e=()=>{};function _e(o,e,a,n=$e){o.add(e);const r=()=>{o.delete(e)&&n()};return!a&&t.getCurrentScope()&&t.onScopeDispose(r),r}function X(o,...e){o.forEach(a=>{a(...e)})}const nt=o=>o(),De=Symbol(),fe=Symbol();function he(o,e){o instanceof Map&&e instanceof Map?e.forEach((a,n)=>o.set(n,a)):o instanceof Set&&e instanceof Set&&e.forEach(o.add,o);for(const a in e){if(!e.hasOwnProperty(a))continue;const n=e[a],r=o[a];Q(r)&&Q(n)&&o.hasOwnProperty(a)&&!t.isRef(n)&&!t.isReactive(n)?o[a]=he(r,n):o[a]=n}return o}const rt=process.env.NODE_ENV!=="production"?Symbol("pinia:skipHydration"):Symbol();function st(o){return!Q(o)||!Object.prototype.hasOwnProperty.call(o,rt)}const{assign:z}=Object;function Re(o){return!!(t.isRef(o)&&o.effect)}function Oe(o,e,a,n){const{state:r,actions:i,getters:s}=e,u=a.state.value[o];let l;function d(){!u&&(process.env.NODE_ENV==="production"||!n)&&(a.state.value[o]=r?r():{});const f=process.env.NODE_ENV!=="production"&&n?t.toRefs(t.ref(r?r():{}).value):t.toRefs(a.state.value[o]);return z(f,i,Object.keys(s||{}).reduce((g,b)=>(process.env.NODE_ENV!=="production"&&b in f&&console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${b}" in store "${o}".`),g[b]=t.markRaw(t.computed(()=>{re(a);const D=a._s.get(o);return s[b].call(D,D)})),g),{}))}return l=me(o,d,e,a,n,!0),l}function me(o,e,a={},n,r,i){let s;const u=z({actions:{}},a);if(process.env.NODE_ENV!=="production"&&!n._e.active)throw new Error("Pinia destroyed");const l={deep:!0};process.env.NODE_ENV!=="production"&&(l.onTrigger=w=>{d?D=w:d==!1&&!N._hotUpdating&&(Array.isArray(D)?D.push(w):console.error("🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug."))});let d,f,g=new Set,b=new Set,D;const _=n.state.value[o];!i&&!_&&(process.env.NODE_ENV==="production"||!r)&&(n.state.value[o]={});const O=t.ref({});let I;function x(w){let y;d=f=!1,process.env.NODE_ENV!=="production"&&(D=[]),typeof w=="function"?(w(n.state.value[o]),y={type:oe.patchFunction,storeId:o,events:D}):(he(n.state.value[o],w),y={type:oe.patchObject,payload:w,storeId:o,events:D});const V=I=Symbol();t.nextTick().then(()=>{I===V&&(d=!0)}),f=!0,X(g,y,n.state.value[o])}const T=i?function(){const{state:w}=a,y=w?w():{};this.$patch(V=>{z(V,y)})}:process.env.NODE_ENV!=="production"?()=>{throw new Error(`🍍: Store "${o}" is built using the setup syntax and does not implement $reset().`)}:$e;function j(){s.stop(),g.clear(),b.clear(),n._s.delete(o)}const K=(w,y="")=>{if(De in w)return w[fe]=y,w;const V=function(){re(n);const P=Array.from(arguments),U=new Set,R=new Set;function A(k){U.add(k)}function B(k){R.add(k)}X(b,{args:P,name:V[fe],store:N,after:A,onError:B});let S;try{S=w.apply(this&&this.$id===o?this:N,P)}catch(k){throw X(R,k),k}return S instanceof Promise?S.then(k=>(X(U,k),k)).catch(k=>(X(R,k),Promise.reject(k))):(X(U,S),S)};return V[De]=!0,V[fe]=y,V},H=t.markRaw({actions:{},getters:{},state:[],hotState:O}),F={_p:n,$id:o,$onAction:_e.bind(null,b),$patch:x,$reset:T,$subscribe(w,y={}){const V=_e(g,w,y.detached,()=>P()),P=s.run(()=>t.watch(()=>n.state.value[o],U=>{(y.flush==="sync"?f:d)&&w({storeId:o,type:oe.direct,events:D},U)},z({},l,y)));return V},$dispose:j},N=t.reactive(process.env.NODE_ENV!=="production"||process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&ee?z({_hmrPayload:H,_customProperties:t.markRaw(new Set)},F):F);n._s.set(o,N);const M=(n._a&&n._a.runWithContext||nt)(()=>n._e.run(()=>(s=t.effectScope()).run(()=>e({action:K}))));for(const w in M){const y=M[w];if(t.isRef(y)&&!Re(y)||t.isReactive(y))process.env.NODE_ENV!=="production"&&r?O.value[w]=t.toRef(M,w):i||(_&&st(y)&&(t.isRef(y)?y.value=_[w]:he(y,_[w])),n.state.value[o][w]=y),process.env.NODE_ENV!=="production"&&H.state.push(w);else if(typeof y=="function"){const V=process.env.NODE_ENV!=="production"&&r?y:K(y,w);M[w]=V,process.env.NODE_ENV!=="production"&&(H.actions[w]=y),u.actions[w]=y}else process.env.NODE_ENV!=="production"&&Re(y)&&(H.getters[w]=i?a.getters[w]:y,ee&&(M._getters||(M._getters=t.markRaw([]))).push(w))}if(z(N,M),z(t.toRaw(N),M),Object.defineProperty(N,"$state",{get:()=>process.env.NODE_ENV!=="production"&&r?O.value:n.state.value[o],set:w=>{if(process.env.NODE_ENV!=="production"&&r)throw new Error("cannot set hotState");x(y=>{z(y,w)})}}),process.env.NODE_ENV!=="production"&&(N._hotUpdate=t.markRaw(w=>{N._hotUpdating=!0,w._hmrPayload.state.forEach(y=>{if(y in N.$state){const V=w.$state[y],P=N.$state[y];typeof V=="object"&&Q(V)&&Q(P)?Ne(V,P):w.$state[y]=P}N[y]=t.toRef(w.$state,y)}),Object.keys(N.$state).forEach(y=>{y in w.$state||delete N[y]}),d=!1,f=!1,n.state.value[o]=t.toRef(w._hmrPayload,"hotState"),f=!0,t.nextTick().then(()=>{d=!0});for(const y in w._hmrPayload.actions){const V=w[y];N[y]=K(V,y)}for(const y in w._hmrPayload.getters){const V=w._hmrPayload.getters[y],P=i?t.computed(()=>(re(n),V.call(N,N))):V;N[y]=P}Object.keys(N._hmrPayload.getters).forEach(y=>{y in w._hmrPayload.getters||delete N[y]}),Object.keys(N._hmrPayload.actions).forEach(y=>{y in w._hmrPayload.actions||delete N[y]}),N._hmrPayload=w._hmrPayload,N._getters=w._getters,N._hotUpdating=!1})),process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&ee){const w={writable:!0,configurable:!0,enumerable:!1};["_p","_hmrPayload","_getters","_customProperties"].forEach(y=>{Object.defineProperty(N,y,z({value:N[y]},w))})}return n._p.forEach(w=>{if(process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&ee){const y=s.run(()=>w({store:N,app:n._a,pinia:n,options:u}));Object.keys(y||{}).forEach(V=>N._customProperties.add(V)),z(N,y)}else z(N,s.run(()=>w({store:N,app:n._a,pinia:n,options:u})))}),process.env.NODE_ENV!=="production"&&N.$state&&typeof N.$state=="object"&&typeof N.$state.constructor=="function"&&!N.$state.constructor.toString().includes("[native code]")&&console.warn(`[🍍]: The "state" must be a plain object. It cannot be
2
2
  state: () => new MyClass()
3
3
  Found in store "${N.$id}".`),_&&i&&a.hydrate&&a.hydrate(N.$state,_),d=!0,f=!0,N}function lt(o,e,a){let n;const r=typeof e=="function";n=r?a:e;function i(s,u){const l=t.hasInjectionContext();if(s=(process.env.NODE_ENV==="test"&&te&&te._testing?null:s)||(l?t.inject(at,null):null),s&&re(s),process.env.NODE_ENV!=="production"&&!te)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.`);s=te,s._s.has(o)||(r?me(o,e,n,s):Oe(o,n,s),process.env.NODE_ENV!=="production"&&(i._pinia=s));const d=s._s.get(o);if(process.env.NODE_ENV!=="production"&&u){const f="__hot:"+o,g=r?me(f,e,n,s,!0):Oe(f,z({},n),s,!0);u._hotUpdate(g),delete s.state.value[f],s._s.delete(f)}if(process.env.NODE_ENV!=="production"&&ee){const f=t.getCurrentInstance();if(f&&f.proxy&&!u){const g=f.proxy,b="_pStores"in g?g._pStores:g._pStores={};b[o]=d}}return d}return i.$id=o,i}function it(o){const e=t.toRaw(o),a={};for(const n in e){const r=e[n];r.effect?a[n]=t.computed({get:()=>o[n],set(i){o[n]=i}}):(t.isRef(r)||t.isReactive(r))&&(a[n]=t.toRef(o,n))}return a}const ct=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const ut=Object.prototype.toString,dt=o=>ut.call(o)==="[object Object]",pt=()=>{};function ft(...o){if(o.length!==1)return t.toRef(...o);const e=o[0];return typeof e=="function"?t.readonly(t.customRef(()=>({get:e,set:pt}))):t.ref(e)}function ht(o,e){function a(...n){return new Promise((r,i)=>{Promise.resolve(o(()=>e.apply(this,n),{fn:e,thisArg:this,args:n})).then(r).catch(i)})}return a}const Ce=o=>o();function mt(o=Ce,e={}){const{initialState:a="active"}=e,n=ft(a==="active");function r(){n.value=!1}function i(){n.value=!0}const s=(...u)=>{n.value&&o(...u)};return{isActive:t.readonly(n),pause:r,resume:i,eventFilter:s}}function ge(o){return Array.isArray(o)?o:[o]}function gt(o){return t.getCurrentInstance()}function yt(o,e,a={}){const{eventFilter:n=Ce,...r}=a;return t.watch(o,ht(n,e),r)}function vt(o,e,a={}){const{eventFilter:n,initialState:r="active",...i}=a,{eventFilter:s,pause:u,resume:l,isActive:d}=mt(n,{initialState:r});return{stop:yt(o,e,{...i,eventFilter:s}),pause:u,resume:l,isActive:d}}const wt=vt;function bt(o,e=!0,a){gt()?t.onMounted(o,a):e?o():t.nextTick(o)}function St(o,e,a){return t.watch(o,e,{...a,immediate:!0})}const se=ct?window:void 0;function Et(o){var e;const a=t.toValue(o);return(e=a?.$el)!==null&&e!==void 0?e:a}function Ve(...o){const e=(n,r,i,s)=>(n.addEventListener(r,i,s),()=>n.removeEventListener(r,i,s)),a=t.computed(()=>{const n=ge(t.toValue(o[0])).filter(r=>r!=null);return n.every(r=>typeof r!="string")?n:void 0});return St(()=>{var n,r;return[(n=(r=a.value)===null||r===void 0?void 0:r.map(i=>Et(i)))!==null&&n!==void 0?n:[se].filter(i=>i!=null),ge(t.toValue(a.value?o[1]:o[0])),ge(t.unref(a.value?o[2]:o[1])),t.toValue(a.value?o[3]:o[2])]},([n,r,i,s],u,l)=>{if(!n?.length||!r?.length||!i?.length)return;const d=dt(s)?{...s}:s,f=n.flatMap(g=>r.flatMap(b=>i.map(R=>e(g,b,R,d))));l(()=>{f.forEach(g=>g())})},{flush:"post"})}const le=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},ie="__vueuse_ssr_handlers__",kt=Nt();function Nt(){return ie in le||(le[ie]=le[ie]||{}),le[ie]}function $t(o,e){return kt[o]||e}function _t(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 Rt={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()}},Te="vueuse-storage";function Dt(o,e,a,n={}){var r;const{flush:i="pre",deep:s=!0,listenToStorageChanges:u=!0,writeDefaults:l=!0,mergeDefaults:d=!1,shallow:f,window:g=se,eventFilter:b,onError:R=D=>{console.error(D)},initOnMounted:_}=n,O=(f?t.shallowRef:t.ref)(e),I=t.computed(()=>t.toValue(o));if(!a)try{a=$t("getDefaultStorage",()=>se?.localStorage)()}catch(D){R(D)}if(!a)return O;const x=t.toValue(e),T=_t(x),j=(r=n.serializer)!==null&&r!==void 0?r:Rt[T],{pause:K,resume:H}=wt(O,D=>y(D),{flush:i,deep:s,eventFilter:b});t.watch(I,()=>P(),{flush:i});let F=!1;const N=D=>{_&&!F||P(D)},M=D=>{_&&!F||U(D)};g&&u&&(a instanceof Storage?Ve(g,"storage",N,{passive:!0}):Ve(g,Te,M)),_?bt(()=>{F=!0,P()}):P();function w(D,A){if(g){const B={key:I.value,oldValue:D,newValue:A,storageArea:a};g.dispatchEvent(a instanceof Storage?new StorageEvent("storage",B):new CustomEvent(Te,{detail:B}))}}function y(D){try{const A=a.getItem(I.value);if(D==null)w(A,null),a.removeItem(I.value);else{const B=j.write(D);A!==B&&(a.setItem(I.value,B),w(A,B))}}catch(A){R(A)}}function V(D){const A=D?D.newValue:a.getItem(I.value);if(A==null)return l&&x!=null&&a.setItem(I.value,j.write(x)),x;if(!D&&d){const B=j.read(A);return typeof d=="function"?d(B,x):T==="object"&&!Array.isArray(B)?{...x,...B}:B}else return typeof A!="string"?A:j.read(A)}function P(D){if(!(D&&D.storageArea!==a)){if(D&&D.key==null){O.value=x;return}if(!(D&&D.key!==I.value)){K();try{const A=j.write(O.value);(D===void 0||D?.newValue!==A)&&(O.value=V(D))}catch(A){R(A)}finally{D?t.nextTick(H):H()}}}}function U(D){P(D.detail)}return O}function Ot(o,e,a={}){const{window:n=se}=a;return Dt(o,e,n?.localStorage,a)}function ye(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function ce(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(a=>({...a,timestamp:a.timestamp.toISOString()}))),e}function Ct(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(a=>({...a,timestamp:new Date(a.timestamp)}))),e}const Ae=lt("hst-operation-log",()=>{const o=t.ref({maxOperations:100,enableCrossTabSync:!0,autoSyncInterval:3e4,enablePersistence:!1,persistenceKeyPrefix:"stonecrop-ops"}),e=t.ref([]),a=t.ref(-1),n=t.ref(ye()),r=t.ref(!1),i=t.ref([]),s=t.ref(null),u=t.computed(()=>a.value<0?!1:e.value[a.value]?.reversible??!1),l=t.computed(()=>a.value<e.value.length-1),d=t.computed(()=>{let h=0;for(let m=a.value;m>=0&&e.value[m]?.reversible;m--)h++;return h}),f=t.computed(()=>e.value.length-1-a.value),g=t.computed(()=>({canUndo:u.value,canRedo:l.value,undoCount:d.value,redoCount:f.value,currentIndex:a.value}));function b(h){o.value={...o.value,...h},o.value.enablePersistence&&(S(),$()),o.value.enableCrossTabSync&&V()}function R(h,m="user"){const v={...h,id:ye(),timestamp:new Date,source:m,userId:o.value.userId};if(o.value.operationFilter&&!o.value.operationFilter(v))return v.id;if(r.value)return i.value.push(v),v.id;if(a.value<e.value.length-1&&(e.value=e.value.slice(0,a.value+1)),e.value.push(v),a.value++,o.value.maxOperations&&e.value.length>o.value.maxOperations){const c=e.value.length-o.value.maxOperations;e.value=e.value.slice(c),a.value-=c}return o.value.enableCrossTabSync&&P(v),v.id}function _(){r.value=!0,i.value=[],s.value=ye()}function O(h){if(!r.value||i.value.length===0)return r.value=!1,i.value=[],s.value=null,null;const m=s.value,v=i.value.every(E=>E.reversible),c={id:m,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(E=>E.id),metadata:{description:h}};i.value.forEach(E=>{E.parentOperationId=m}),e.value.push(...i.value,c),a.value=e.value.length-1,o.value.enableCrossTabSync&&U(i.value,c);const p=m;return r.value=!1,i.value=[],s.value=null,p}function I(){r.value=!1,i.value=[],s.value=null}function x(h){if(!u.value)return!1;const m=e.value[a.value];if(!m.reversible)return typeof console<"u"&&m.irreversibleReason&&console.warn("Cannot undo irreversible operation:",m.irreversibleReason),!1;try{if(m.type==="batch"&&m.childOperationIds)for(let v=m.childOperationIds.length-1;v>=0;v--){const c=m.childOperationIds[v],p=e.value.find(E=>E.id===c);p&&j(p,h)}else j(m,h);return a.value--,o.value.enableCrossTabSync&&D(m),!0}catch(v){return typeof console<"u"&&console.error("Undo failed:",v),!1}}function T(h){if(!l.value)return!1;const m=e.value[a.value+1];try{if(m.type==="batch"&&m.childOperationIds)for(const v of m.childOperationIds){const c=e.value.find(p=>p.id===v);c&&K(c,h)}else K(m,h);return a.value++,o.value.enableCrossTabSync&&A(m),!0}catch(v){return typeof console<"u"&&console.error("Redo failed:",v),!1}}function j(h,m){(h.type==="set"||h.type==="delete")&&m&&typeof m.set=="function"&&m.set(h.path,h.beforeValue,"undo")}function K(h,m){(h.type==="set"||h.type==="delete")&&m&&typeof m.set=="function"&&m.set(h.path,h.afterValue,"redo")}function H(){const h=e.value.filter(v=>v.reversible).length,m=e.value.map(v=>v.timestamp);return{operations:[...e.value],currentIndex:a.value,totalOperations:e.value.length,reversibleOperations:h,irreversibleOperations:e.value.length-h,oldestOperation:m.length>0?new Date(Math.min(...m.map(v=>v.getTime()))):void 0,newestOperation:m.length>0?new Date(Math.max(...m.map(v=>v.getTime()))):void 0}}function F(){e.value=[],a.value=-1}function N(h,m){return e.value.filter(v=>v.doctype===h&&(m===void 0||v.recordId===m))}function M(h,m){const v=e.value.find(c=>c.id===h);v&&(v.reversible=!1,v.irreversibleReason=m)}function w(h,m,v,c="success",p){const E={type:"action",path:v&&v.length>0?`${h}.${v[0]}`:h,fieldname:"",beforeValue:null,afterValue:null,doctype:h,recordId:v&&v.length>0?v[0]:void 0,reversible:!1,actionName:m,actionRecordIds:v,actionResult:c,actionError:p};return R(E)}let y=null;function V(){typeof window>"u"||!window.BroadcastChannel||(y=new BroadcastChannel("stonecrop-operation-log"),y.addEventListener("message",h=>{const m=h.data;if(!m||typeof m!="object")return;const v=Ct(m);v.clientId!==n.value&&(v.type==="operation"&&v.operation?(e.value.push({...v.operation,source:"sync"}),a.value=e.value.length-1):v.type==="operation"&&v.operations&&(e.value.push(...v.operations.map(c=>({...c,source:"sync"}))),a.value=e.value.length-1))}))}function P(h){if(!y)return;const m={type:"operation",operation:h,clientId:n.value,timestamp:new Date};y.postMessage(ce(m))}function U(h,m){if(!y)return;const v={type:"operation",operations:[...h,m],clientId:n.value,timestamp:new Date};y.postMessage(ce(v))}function D(h){if(!y)return;const m={type:"undo",operation:h,clientId:n.value,timestamp:new Date};y.postMessage(ce(m))}function A(h){if(!y)return;const m={type:"redo",operation:h,clientId:n.value,timestamp:new Date};y.postMessage(ce(m))}const B=Ot("stonecrop-ops-operations",null,{serializer:{read:h=>{try{return JSON.parse(h)}catch{return null}},write:h=>h?JSON.stringify(h):""}});function S(){if(!(typeof window>"u"))try{const h=B.value;h&&Array.isArray(h.operations)&&(e.value=h.operations.map(m=>({...m,timestamp:new Date(m.timestamp)})),a.value=h.currentIndex??-1)}catch(h){typeof console<"u"&&console.error("Failed to load operations from persistence:",h)}}function k(){if(!(typeof window>"u"))try{B.value={operations:e.value.map(h=>({...h,timestamp:h.timestamp.toISOString()})),currentIndex:a.value}}catch(h){typeof console<"u"&&console.error("Failed to save operations to persistence:",h)}}function $(){t.watch([e,a],()=>{o.value.enablePersistence&&k()},{deep:!0})}return{operations:e,currentIndex:a,config:o,clientId:n,undoRedoState:g,canUndo:u,canRedo:l,undoCount:d,redoCount:f,configure:b,addOperation:R,startBatch:_,commitBatch:O,cancelBatch:I,undo:x,redo:T,clear:F,getOperationsFor:N,getSnapshot:H,markIrreversible:M,logAction:w}});class ae{static _root;options;doctypeActions=new Map;doctypeTransitions=new Map;fieldRollbackConfig=new Map;globalActions=new Map;globalTransitionActions=new Map;constructor(e={}){if(ae._root)return ae._root;ae._root=this,this.options={defaultTimeout:e.defaultTimeout??5e3,debug:e.debug??!1,enableRollback:e.enableRollback??!0,errorHandler:e.errorHandler}}registerAction(e,a){this.globalActions.set(e,a)}registerTransitionAction(e,a){this.globalTransitionActions.set(e,a)}setFieldRollback(e,a,n){this.fieldRollbackConfig.has(e)||this.fieldRollbackConfig.set(e,new Map),this.fieldRollbackConfig.get(e).set(a,n)}getFieldRollback(e,a){return this.fieldRollbackConfig.get(e)?.get(a)}registerDoctypeActions(e,a){if(!a)return;const n=new Map,r=new Map;if(typeof a.entrySeq=="function")a.entrySeq().forEach(([i,s])=>{this.categorizeAction(i,s,n,r)});else if(a instanceof Map)for(const[i,s]of a)this.categorizeAction(i,s,n,r);else a&&typeof a=="object"&&Object.entries(a).forEach(([i,s])=>{this.categorizeAction(i,s,n,r)});this.doctypeActions.set(e,n),this.doctypeTransitions.set(e,r)}categorizeAction(e,a,n,r){this.isTransitionKey(e)?r.set(e,a):n.set(e,a)}isTransitionKey(e){return/^[A-Z0-9_]+$/.test(e)&&e.length>0}async executeFieldTriggers(e,a={}){const{doctype:n,fieldname:r}=e,i=this.findFieldTriggers(n,r);if(i.length===0)return{path:e.path,actionResults:[],totalExecutionTime:0,allSucceeded:!0,stoppedOnError:!1,rolledBack:!1};const s=performance.now(),u=[];let l=!1,d=!1,f;const g=this.getFieldRollback(n,r),b=a.enableRollback??g??this.options.enableRollback;b&&e.store&&(f=this.captureSnapshot(e));for(const O of i)try{const I=await this.executeAction(O,e,a.timeout);if(u.push(I),!I.success){l=!0;break}}catch(I){const x={success:!1,error:I instanceof Error?I:new Error(String(I)),executionTime:0,action:O};u.push(x),l=!0;break}if(b&&l&&f&&e.store)try{this.restoreSnapshot(e,f),d=!0}catch(O){console.error("[FieldTriggers] Rollback failed:",O)}const R=performance.now()-s,_=u.filter(O=>!O.success);if(_.length>0&&this.options.errorHandler)for(const O of _)try{this.options.errorHandler(O.error,e,O.action)}catch(I){console.error("[FieldTriggers] Error in global error handler:",I)}return{path:e.path,actionResults:u,totalExecutionTime:R,allSucceeded:u.every(O=>O.success),stoppedOnError:l,rolledBack:d,snapshot:this.options.debug&&b?f:void 0}}async executeTransitionActions(e,a={}){const{doctype:n,transition:r}=e,i=this.findTransitionActions(n,r);if(i.length===0)return[];const s=[];for(const l of i)try{const d=await this.executeTransitionAction(l,e,a.timeout);if(s.push(d),!d.success)break}catch(d){const f={success:!1,error:d instanceof Error?d:new Error(String(d)),executionTime:0,action:l,transition:r};s.push(f);break}const u=s.filter(l=>!l.success);if(u.length>0&&this.options.errorHandler)for(const l of u)try{this.options.errorHandler(l.error,e,l.action)}catch(d){console.error("[FieldTriggers] Error in global error handler:",d)}return s}findTransitionActions(e,a){const n=this.doctypeTransitions.get(e);return n?n.get(a)||[]:[]}async executeTransitionAction(e,a,n){const r=performance.now(),i=n??this.options.defaultTimeout;try{let s=this.globalTransitionActions.get(e);if(!s){const u=this.globalActions.get(e);u&&(s=u)}if(!s)throw new Error(`Transition action "${e}" not found in registry`);return await this.executeWithTimeout(s,a,i),{success:!0,executionTime:performance.now()-r,action:e,transition:a.transition}}catch(s){const u=performance.now()-r;return{success:!1,error:s instanceof Error?s:new Error(String(s)),executionTime:u,action:e,transition:a.transition}}}findFieldTriggers(e,a){const n=this.doctypeActions.get(e);if(!n)return[];const r=[];for(const[i,s]of n)this.isFieldTriggerKey(i,a)&&r.push(...s);return r}isFieldTriggerKey(e,a){return e===a?!0:e.includes(".")?this.matchFieldPattern(e,a):e.includes("*")?this.matchFieldPattern(e,a):!1}matchFieldPattern(e,a){const n=e.split("."),r=a.split(".");if(n.length!==r.length)return!1;for(let i=0;i<n.length;i++){const s=n[i],u=r[i];if(s!=="*"&&s!==u)return!1}return!0}async executeAction(e,a,n){const r=performance.now(),i=n??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,a,i),{success:!0,executionTime:performance.now()-r,action:e}}catch(s){const u=performance.now()-r;return{success:!1,error:s instanceof Error?s:new Error(String(s)),executionTime:u,action:e}}}async executeWithTimeout(e,a,n){return new Promise((r,i)=>{const s=setTimeout(()=>{i(new Error(`Action timeout after ${n}ms`))},n);Promise.resolve(e(a)).then(u=>{clearTimeout(s),r(u)}).catch(u=>{clearTimeout(s),i(u)})})}captureSnapshot(e){if(!(!e.store||!e.doctype||!e.recordId))try{const a=`${e.doctype}.${e.recordId}`,n=e.store.get(a);return!n||typeof n!="object"?void 0:JSON.parse(JSON.stringify(n))}catch(a){this.options.debug&&console.warn("[FieldTriggers] Failed to capture snapshot:",a);return}}restoreSnapshot(e,a){if(!(!e.store||!e.doctype||!e.recordId||!a))try{const n=`${e.doctype}.${e.recordId}`;e.store.set(n,a),this.options.debug&&console.log(`[FieldTriggers] Rolled back ${n} to previous state`)}catch(n){throw console.error("[FieldTriggers] Failed to restore snapshot:",n),n}}}function Ie(o){return new ae(o)}function xe(){try{return Ae()}catch{return null}}class Y{static instance;static getInstance(){return Y.instance||(Y.instance=new Y),Y.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 a=this.getRegistry();if(a&&typeof a=="object"&&"registry"in a)return a.registry[e]}}class ue{target;parentPath;rootNode;doctype;parentDoctype;hst;constructor(e,a,n="",r=null,i){return this.target=e,this.parentPath=n,this.rootNode=r||this,this.doctype=a,this.parentDoctype=i,this.hst=Y.getInstance(),new Proxy(this,{get(s,u){if(u in s)return s[u];const l=String(u);return s.getNode(l)},set(s,u,l){const d=String(u);return s.set(d,l),!0}})}get(e){return this.resolveValue(e)}getNode(e){const a=this.resolvePath(e),n=this.resolveValue(e),r=a.split(".");let i=this.doctype;return this.doctype==="StonecropStore"&&r.length>=1&&(i=r[0]),typeof n=="object"&&n!==null&&!this.isPrimitive(n)?new ue(n,i,a,this.rootNode,this.parentDoctype):new ue(n,i,a,this.rootNode,this.parentDoctype)}set(e,a,n="user"){const r=this.resolvePath(e),i=this.has(e)?this.get(e):void 0;if(n!=="undo"&&n!=="redo"){const s=xe();if(s&&typeof s.addOperation=="function"){const u=r.split("."),l=this.doctype==="StonecropStore"&&u.length>=1?u[0]:this.doctype,d=u.length>=2?u[1]:void 0,f=u.slice(2).join(".")||u[u.length-1],g=a===void 0&&i!==void 0?"delete":"set";s.addOperation({type:g,path:r,fieldname:f,beforeValue:i,afterValue:a,doctype:l,recordId:d,reversible:!0},n)}}this.updateValue(e,a),this.triggerFieldActions(r,i,a)}has(e){try{if(e==="")return!0;const a=this.parsePath(e);let n=this.target;for(let r=0;r<a.length;r++){const i=a[r];if(n==null)return!1;if(r===a.length-1)return this.isImmutable(n)?n.has(i):this.isPiniaStore(n)&&n.$state&&i in n.$state||i in n;n=this.getProperty(n,i)}return!1}catch{return!1}}getParent(){if(!this.parentPath)return null;const e=this.parentPath.split(".").slice(0,-1).join(".");return e===""?this.rootNode:this.rootNode.getNode(e)}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,a){const n=Ie(),r=this.parentPath.split(".");let i=this.doctype,s;this.doctype==="StonecropStore"&&r.length>=1&&(i=r[0]),r.length>=2&&(s=r[1]);const u={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:a?.currentState,targetState:a?.targetState,fsmContext:a?.fsmContext},l=xe();return l&&typeof l.addOperation=="function"&&l.addOperation({type:"transition",path:this.parentPath,fieldname:e,beforeValue:a?.currentState,afterValue:a?.targetState,doctype:i,recordId:s,reversible:!1,metadata:{transition:e,currentState:a?.currentState,targetState:a?.targetState,fsmContext:a?.fsmContext}},"user"),await n.executeTransitionActions(u)}resolvePath(e){return e===""?this.parentPath:this.parentPath?`${this.parentPath}.${e}`:e}resolveValue(e){if(e==="")return this.target;const a=this.parsePath(e);let n=this.target;for(const r of a){if(n==null)return;n=this.getProperty(n,r)}return n}updateValue(e,a){if(e==="")throw new Error("Cannot set value on empty path");const n=this.parsePath(e),r=n.pop();let i=this.target;for(const s of n)if(i=this.getProperty(i,s),i==null)throw new Error(`Cannot set property on null/undefined path: ${e}`);this.setProperty(i,r,a)}getProperty(e,a){return this.isImmutable(e)?e.get(a):this.isVueReactive(e)?e[a]:this.isPiniaStore(e)?e.$state?.[a]??e[a]:e[a]}setProperty(e,a,n){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({[a]:n}):e[a]=n;return}e[a]=n}async triggerFieldActions(e,a,n){try{if(!e||typeof e!="string")return;const r=e.split(".");if(r.length<3)return;const i=Ie(),s=r.slice(2).join(".")||r[r.length-1];let u=this.doctype;this.doctype==="StonecropStore"&&r.length>=1&&(u=r[0]);let l;r.length>=2&&(l=r[1]);const d={path:e,fieldname:s,beforeValue:a,afterValue:n,operation:"set",doctype:u,recordId:l,timestamp:new Date,store:this.rootNode||void 0};await i.executeFieldTriggers(d)}catch(r){r instanceof Error&&console.warn("Field trigger error:",r.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 a="get"in e&&typeof e.get=="function",n="set"in e&&typeof e.set=="function",r="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&&a&&n;let s;try{const l=e;if("constructor"in l&&l.constructor&&typeof l.constructor=="object"&&"name"in l.constructor){const d=l.constructor.name;s=typeof d=="string"?d:void 0}}catch{s=void 0}const u=s&&(s.includes("Map")||s.includes("List")||s.includes("Set")||s.includes("Stack")||s.includes("Seq"))&&(a||n);return!!(a&&n&&r&&i||a&&n&&u)}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.replace(/\[(\d+)\]/g,".$1").split(".").filter(a=>a.length>0):[]}}function Vt(o,e,a){return new ue(o,e,"",null,a)}class Tt{hstStore;_operationLogStore;_operationLogConfig;registry;constructor(e,a){this.registry=e,this._operationLogConfig=a,this.initializeHSTStore(),this.setupRegistrySync()}getOperationLogStore(){return this._operationLogStore||(this._operationLogStore=Ae(),this._operationLogConfig&&this._operationLogStore.configure(this._operationLogConfig)),this._operationLogStore}initializeHSTStore(){const e={};Object.keys(this.registry.registry).forEach(a=>{e[a]={}}),this.hstStore=Vt(t.reactive(e),"StonecropStore")}setupRegistrySync(){const e=this.registry.addDoctype.bind(this.registry);this.registry.addDoctype=a=>{e(a),this.hstStore.has(a.slug)||this.hstStore.set(a.slug,{})}}records(e){const a=typeof e=="string"?e:e.slug;return this.ensureDoctypeExists(a),this.hstStore.getNode(a)}addRecord(e,a,n){const r=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(r),this.hstStore.set(`${r}.${a}`,n)}getRecordById(e,a){const n=typeof e=="string"?e:e.slug;if(this.ensureDoctypeExists(n),!(!this.hstStore.has(`${n}.${a}`)||this.hstStore.get(`${n}.${a}`)===void 0))return this.hstStore.getNode(`${n}.${a}`)}removeRecord(e,a){const n=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(n),this.hstStore.has(`${n}.${a}`)&&this.hstStore.set(`${n}.${a}`,void 0)}getRecordIds(e){const a=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(a);const n=this.hstStore.get(a);return!n||typeof n!="object"?[]:Object.keys(n).filter(r=>n[r]!==void 0)}clearRecords(e){const a=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(a),this.getRecordIds(a).forEach(n=>{this.hstStore.set(`${a}.${n}`,void 0)})}setup(e){this.ensureDoctypeExists(e.slug)}runAction(e,a,n){const r=this.registry.registry[e.slug]?.actions?.get(a),i=Array.isArray(n)?n.filter(d=>typeof d=="string"):void 0,s=this.getOperationLogStore();let u="success",l;try{r&&r.length>0&&r.forEach(d=>{try{new Function("args",d)(n)}catch(f){throw u="failure",l=f instanceof Error?f.message:"Unknown error",f}})}catch{}finally{s.logAction(e.doctype,a,i,u,l)}}async getRecords(e){(await(await fetch(`/${e.slug}`)).json()).forEach(a=>{a.id&&this.addRecord(e,a.id,a)})}async getRecord(e,a){const n=await(await fetch(`/${e.slug}/${a}`)).json();this.addRecord(e,a,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 At(o){o||(o={});const e=o.registry||t.inject("$registry"),a=t.inject("$stonecrop"),n=t.ref(),r=t.ref(),i=t.ref({}),s=t.ref(),u=t.ref(),l=t.ref([]);if(o.doctype&&e){const S=o.doctype.schema?Array.isArray(o.doctype.schema)?o.doctype.schema:Array.from(o.doctype.schema):[];l.value=e.resolveSchema(S)}const d=t.ref([]),f=t.ref(-1),g=t.computed(()=>n.value?.getOperationLogStore().canUndo??!1),b=t.computed(()=>n.value?.getOperationLogStore().canRedo??!1),R=t.computed(()=>n.value?.getOperationLogStore().undoCount??0),_=t.computed(()=>n.value?.getOperationLogStore().redoCount??0),O=t.computed(()=>n.value?.getOperationLogStore().undoRedoState??{canUndo:!1,canRedo:!1,undoCount:0,redoCount:0,currentIndex:-1}),I=S=>n.value?.getOperationLogStore().undo(S)??!1,x=S=>n.value?.getOperationLogStore().redo(S)??!1,T=()=>{n.value?.getOperationLogStore().startBatch()},j=S=>n.value?.getOperationLogStore().commitBatch(S)??null,K=()=>{n.value?.getOperationLogStore().cancelBatch()},H=()=>{n.value?.getOperationLogStore().clear()},F=(S,k)=>n.value?.getOperationLogStore().getOperationsFor(S,k)??[],N=()=>n.value?.getOperationLogStore().getSnapshot()??{operations:[],currentIndex:-1,totalOperations:0,reversibleOperations:0,irreversibleOperations:0},M=(S,k)=>{n.value?.getOperationLogStore().markIrreversible(S,k)},w=(S,k,$,h="success",m)=>n.value?.getOperationLogStore().logAction(S,k,$,h,m)??"",y=S=>{n.value?.getOperationLogStore().configure(S)};t.onMounted(async()=>{if(e){n.value=a||new Tt(e);try{const S=n.value.getOperationLogStore(),k=it(S);d.value=k.operations.value,f.value=k.currentIndex.value,t.watch(()=>k.operations.value,$=>{d.value=$}),t.watch(()=>k.currentIndex.value,$=>{f.value=$})}catch{}if(!o.doctype&&e.router){const S=e.router.currentRoute.value;if(!S.path)return;const k=S.path.split("/").filter(h=>h.length>0),$=k[1]?.toLowerCase();if(k.length>0){const h={path:S.path,segments:k},m=await e.getMeta?.(h);if(m){if(e.addDoctype(m),n.value.setup(m),s.value=m,u.value=$,r.value=n.value.getStore(),e){const v=m.schema?Array.isArray(m.schema)?m.schema:Array.from(m.schema):[];l.value=e.resolveSchema(v)}if($&&$!=="new"){const v=n.value.getRecordById(m,$);if(v)i.value=v.get("")||{};else try{await n.value.getRecord(m,$);const c=n.value.getRecordById(m,$);c&&(i.value=c.get("")||{})}catch{i.value=Z(m)}}else i.value=Z(m);r.value&&Pe(m,$||"new",i,r.value),n.value.runAction(m,"load",$?[$]:void 0)}}}if(o.doctype){r.value=n.value.getStore();const S=o.doctype,k=o.recordId;if(k&&k!=="new"){const $=n.value.getRecordById(S,k);if($)i.value=$.get("")||{};else try{await n.value.getRecord(S,k);const h=n.value.getRecordById(S,k);h&&(i.value=h.get("")||{})}catch{i.value=Z(S)}}else i.value=Z(S);r.value&&Pe(S,k||"new",i,r.value)}}});const V=(S,k)=>{const $=o.doctype||s.value;if(!$)return"";const h=k||o.recordId||u.value||"new";return`${$.slug}.${h}.${S}`},P=S=>{const k=o.doctype||s.value;if(!(!r.value||!n.value||!k))try{const $=S.path.split(".");if($.length>=2){const v=$[0],c=$[1];if(r.value.has(`${v}.${c}`)||n.value.addRecord(k,c,{...i.value}),$.length>3){const p=`${v}.${c}`,E=$.slice(2);let C=p;for(let L=0;L<E.length-1;L++)if(C+=`.${E[L]}`,!r.value.has(C)){const q=E[L+1],W=!isNaN(Number(q));r.value.set(C,W?[]:{})}}}r.value.set(S.path,S.value);const h=S.fieldname.split("."),m={...i.value};h.length===1?m[h[0]]=S.value:It(m,h,S.value),i.value=m}catch{}};(o.doctype||e?.router)&&(t.provide("hstPathProvider",V),t.provide("hstChangeHandler",P));const U=(S,k,$)=>{if(!n.value)return Z(k);if($)try{const h=r.value?.get(S);return h&&typeof h=="object"?h:Z(k)}catch{return Z(k)}return Z(k)},D=async(S,k)=>{if(!r.value||!n.value)throw new Error("HST store not initialized");const $=`${S.slug}.${k}`,h={...r.value.get($)||{}},m=S.schema?Array.isArray(S.schema)?S.schema:Array.from(S.schema):[],v=(e?e.resolveSchema(m):m).filter(c=>"fieldtype"in c&&c.fieldtype==="Doctype"&&"schema"in c&&Array.isArray(c.schema));for(const c of v){const p=c,E=`${$}.${p.fieldname}`,C=Be(p.schema,E,r.value);h[p.fieldname]=C}return h},A=(S,k)=>({provideHSTPath:$=>`${S}.${$}`,handleHSTChange:$=>{const h=$.path.startsWith(S)?$.path:`${S}.${$.fieldname}`;P({...$,path:h})}}),B={operations:d,currentIndex:f,undoRedoState:O,canUndo:g,canRedo:b,undoCount:R,redoCount:_,undo:I,redo:x,startBatch:T,commitBatch:j,cancelBatch:K,clear:H,getOperationsFor:F,getSnapshot:N,markIrreversible:M,logAction:w,configure:y};return o.doctype?{stonecrop:n,operationLog:B,provideHSTPath:V,handleHSTChange:P,hstStore:r,formData:i,resolvedSchema:l,loadNestedData:U,saveRecursive:D,createNestedContext:A}:!o.doctype&&e?.router?{stonecrop:n,operationLog:B,provideHSTPath:V,handleHSTChange:P,hstStore:r,formData:i,resolvedSchema:l,loadNestedData:U,saveRecursive:D,createNestedContext:A}:{stonecrop:n,operationLog:B}}function Z(o){const e={};return o.schema&&o.schema.forEach(a=>{switch("fieldtype"in a?a.fieldtype:"Data"){case"Data":case"Text":e[a.fieldname]="";break;case"Check":e[a.fieldname]=!1;break;case"Int":case"Float":e[a.fieldname]=0;break;case"Table":e[a.fieldname]=[];break;case"JSON":e[a.fieldname]={};break;default:e[a.fieldname]=null}}),e}function Pe(o,e,a,n){t.watch(a,r=>{const i=`${o.slug}.${e}`;Object.keys(r).forEach(s=>{const u=`${i}.${s}`;try{n.set(u,r[s])}catch{}})},{deep:!0})}function It(o,e,a){let n=o;for(let i=0;i<e.length-1;i++){const s=e[i];(!(s in n)||typeof n[s]!="object")&&(n[s]=isNaN(Number(e[i+1]))?{}:[]),n=n[s]}const r=e[e.length-1];n[r]=a}function Be(o,e,a){const n={...a.get(e)||{}},r=o.filter(i=>"fieldtype"in i&&i.fieldtype==="Doctype"&&"schema"in i&&Array.isArray(i.schema));for(const i of r){const s=i,u=`${e}.${s.fieldname}`,l=Be(s.schema,u,a);n[s.fieldname]=l}return n}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;function xt(o,e){return t.getCurrentScope()?(t.onScopeDispose(o,e),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Pt=()=>{};function Bt(...o){if(o.length!==1)return t.toRef(...o);const e=o[0];return typeof e=="function"?t.readonly(t.customRef(()=>({get:e,set:Pt}))):t.ref(e)}function ve(o){return typeof Window<"u"&&o instanceof Window?o.document.documentElement:typeof Document<"u"&&o instanceof Document?o.documentElement:o}const we=new WeakMap;function Mt(o,e=!1){const a=t.shallowRef(e);let n="";t.watch(Bt(o),s=>{const u=ve(t.toValue(s));if(u){const l=u;if(we.get(l)||we.set(l,l.style.overflow),l.style.overflow!=="hidden"&&(n=l.style.overflow),l.style.overflow==="hidden")return a.value=!0;if(a.value)return l.style.overflow="hidden"}},{immediate:!0});const r=()=>{const s=ve(t.toValue(o));!s||a.value||(s.style.overflow="hidden",a.value=!0)},i=()=>{const s=ve(t.toValue(o));!s||!a.value||(s.style.overflow=n,we.delete(s),a.value=!1)};return xt(i),t.computed({get(){return a.value},set(s){s?r():i()}})}function jt(){let o=!1;const e=t.shallowRef(!1);return(a,n)=>{if(e.value=n.value,o)return;o=!0;const r=Mt(a,n.value);t.watch(e,i=>r.value=i)}}jt();const Ft=(o,e)=>{const a=o.__vccOpts||o;for(const[n,r]of e)a[n]=r;return a};function Lt(o,e){return t.getCurrentScope()?(t.onScopeDispose(o,e),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Ht=()=>{};function Ut(...o){if(o.length!==1)return t.toRef(...o);const e=o[0];return typeof e=="function"?t.readonly(t.customRef(()=>({get:e,set:Ht}))):t.ref(e)}function be(o){return typeof Window<"u"&&o instanceof Window?o.document.documentElement:typeof Document<"u"&&o instanceof Document?o.documentElement:o}const Se=new WeakMap;function Wt(o,e=!1){const a=t.shallowRef(e);let n="";t.watch(Ut(o),s=>{const u=be(t.toValue(s));if(u){const l=u;if(Se.get(l)||Se.set(l,l.style.overflow),l.style.overflow!=="hidden"&&(n=l.style.overflow),l.style.overflow==="hidden")return a.value=!0;if(a.value)return l.style.overflow="hidden"}},{immediate:!0});const r=()=>{const s=be(t.toValue(o));!s||a.value||(s.style.overflow="hidden",a.value=!0)},i=()=>{const s=be(t.toValue(o));!s||!a.value||(s.style.overflow=n,Se.delete(s),a.value=!1)};return Lt(i),t.computed({get(){return a.value},set(s){s?r():i()}})}function Kt(){let o=!1;const e=t.shallowRef(!1);return(a,n)=>{if(e.value=n.value,o)return;o=!0;const r=Wt(a,n.value);t.watch(e,i=>r.value=i)}}Kt(),typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const zt={class:"aform"},Jt={key:0,class:"aform-nested-section"},Gt={key:0,class:"aform-nested-label"},qt=t.defineComponent({__name:"AForm",props:t.mergeModels({schema:{},readOnly:{type:Boolean}},{data:{required:!0},dataModifiers:{}}),emits:t.mergeModels(["update:schema","update:data"],["update:data"]),setup(o,{emit:e}){const a=e,n=t.useModel(o,"data"),r=t.ref({});t.watchEffect(()=>{!o.schema||!n.value||o.schema.forEach(l=>{"schema"in l&&Array.isArray(l.schema)&&l.schema.length>0&&(!r.value[l.fieldname]&&n.value[l.fieldname]?r.value[l.fieldname]=n.value[l.fieldname]:r.value[l.fieldname]||(r.value[l.fieldname]={}))})}),t.watchEffect(()=>{Object.keys(r.value).forEach(l=>{n.value&&r.value[l]!==n.value[l]&&(n.value[l]=r.value[l],a("update:data",n.value))})}),t.watchEffect(()=>{n.value&&o.schema&&o.schema.forEach(l=>{l.fieldname&&n.value[l.fieldname]!==void 0&&(l.value=n.value[l.fieldname])})});const i=l=>{const d={};for(const[f,g]of Object.entries(l))["component","fieldtype"].includes(f)||(d[f]=g),f==="rows"&&(!g||Array.isArray(g)&&g.length===0)&&(d.rows=n.value[l.fieldname]||[]);return d},s=t.ref([]);t.watchEffect(()=>{o.schema&&s.value.length!==o.schema.length&&(s.value=o.schema.map((l,d)=>t.computed({get(){return l.value},set:f=>{const g=o.schema[d].fieldname;o.schema[d].value=f,g&&n.value&&(n.value[g]=f,a("update:data",n.value)),a("update:schema",o.schema)}})))});const u=t.computed(()=>s.value);return(l,d)=>{const f=t.resolveComponent("AForm",!0);return t.openBlock(),t.createElementBlock("form",zt,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.schema,(g,b)=>(t.openBlock(),t.createElementBlock(t.Fragment,{key:b},["schema"in g&&Array.isArray(g.schema)&&g.schema.length>0?(t.openBlock(),t.createElementBlock("div",Jt,[g.label?(t.openBlock(),t.createElementBlock("h4",Gt,t.toDisplayString(g.label),1)):t.createCommentVNode("",!0),t.createVNode(f,{data:r.value[g.fieldname],"onUpdate:data":R=>r.value[g.fieldname]=R,schema:g.schema,"read-only":o.readOnly||g.readOnly},null,8,["data","onUpdate:data","schema","read-only"])])):(t.openBlock(),t.createBlock(t.resolveDynamicComponent(g.component),t.mergeProps({key:1,modelValue:u.value[b].value,"onUpdate:modelValue":R=>u.value[b].value=R,schema:g,data:n.value[g.fieldname],"read-only":o.readOnly},{ref_for:!0},i(g)),null,16,["modelValue","onUpdate:modelValue","schema","data","read-only"]))],64))),128))])}}}),Zt=Ft(qt,[["__scopeId","data-v-06e17c5b"]]),Qt={class:"tabs"},Xt={tabindex:"0"},Yt={tabindex:"0"},Ee=ke(t.defineComponent({__name:"SheetNav",props:{breadcrumbs:{default:()=>[]}},setup(o){const e=t.ref(!0),a=t.ref(!1),n=t.ref(""),r=t.useTemplateRef("searchinput"),i=t.computed(()=>e.value?"unrotated":"rotated"),s=()=>{e.value=!e.value},u=async()=>{a.value=!a.value,await t.nextTick(()=>{r.value?.focus()})},l=g=>{g.preventDefault(),g.stopPropagation()},d=async g=>{g.preventDefault(),g.stopPropagation(),await u()},f=()=>{};return(g,b)=>{const R=t.resolveComponent("router-link");return t.openBlock(),t.createElementBlock("footer",null,[t.createElementVNode("ul",Qt,[t.createElementVNode("li",{class:"hidebreadcrumbs",onClick:s,onKeydown:t.withKeys(s,["enter"])},[t.createElementVNode("a",Xt,[t.createElementVNode("div",{class:t.normalizeClass(i.value)},"×",2)])],32),t.createElementVNode("li",{class:"hometab",style:t.normalizeStyle({display:e.value?"block":"none"}),onClick:f,onKeydown:t.withKeys(f,["enter"])},[t.createVNode(R,{to:"/",tabindex:"0"},{default:t.withCtx(()=>[...b[5]||(b[5]=[t.createElementVNode("svg",{class:"icon","aria-label":"Home",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[t.createElementVNode("path",{d:"M3 12l9-9 9 9"}),t.createElementVNode("path",{d:"M9 21V12h6v9"})],-1)])]),_:1})],36),t.createElementVNode("li",{class:t.normalizeClass(["searchtab",{"search-active":a.value}]),style:t.normalizeStyle({display:e.value?"block":"none"})},[t.createElementVNode("a",Yt,[t.withDirectives((t.openBlock(),t.createElementBlock("svg",{class:"icon search-icon",role:"button","aria-label":"Search",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",onClick:u,onKeydown:t.withKeys(u,["enter"])},[...b[6]||(b[6]=[t.createElementVNode("circle",{cx:"11",cy:"11",r:"7"},null,-1),t.createElementVNode("path",{d:"M21 21l-4.35-4.35"},null,-1)])],544)),[[t.vShow,!a.value]]),t.withDirectives(t.createElementVNode("input",{ref:"searchinput","onUpdate:modelValue":b[0]||(b[0]=_=>n.value=_),type:"text",placeholder:"Search...",onClick:b[1]||(b[1]=t.withModifiers(()=>{},["stop"])),onInput:b[2]||(b[2]=_=>l(_)),onBlur:b[3]||(b[3]=_=>d(_)),onKeydown:[b[4]||(b[4]=t.withKeys(_=>d(_),["enter"])),t.withKeys(u,["escape"])]},null,544),[[t.vShow,a.value],[t.vModelText,n.value]])])],6),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.breadcrumbs,_=>(t.openBlock(),t.createElementBlock("li",{key:_.title,style:t.normalizeStyle({display:e.value?"block":"none"})},[t.createVNode(R,{tabindex:"0",to:_.to},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(_.title),1)]),_:2},1032,["to"])],4))),128))])])}}}),[["__scopeId","data-v-eb5bcbb6"]]),eo={key:1,class:"loading"},to={key:2,class:"loading"},Me=t.defineComponent({__name:"Desktop",props:{availableDoctypes:{default:()=>[]}},setup(o){const{stonecrop:e}=At(),a=t.ref(!1),n=t.ref(!1),r=t.ref(!1),i=t.computed({get(){if(!e.value||!l.value||!f.value)return{};try{return e.value.getRecordById(l.value,f.value)?.get("")||{}}catch{return{}}},set(c){if(!(!e.value||!l.value||!f.value))try{const p=e.value.getStore();for(const[E,C]of Object.entries(c)){const L=`${l.value}.${f.value}.${E}`;p.set(L,C)}}catch(p){console.warn("HST update failed:",p)}}}),s=t.computed(()=>t.unref(e.value?.registry.router?.currentRoute)),u=t.computed(()=>e.value?.registry.router),l=t.computed(()=>{if(!s.value)return"";if(s.value.meta?.actualDoctype)return s.value.meta.actualDoctype;if(s.value.params.doctype)return s.value.params.doctype;const c=s.value.params.pathMatch;return c&&c.length>0?c[0]:""}),d=t.computed(()=>{if(!s.value)return"";if(s.value.meta?.doctype)return s.value.meta.doctype;if(s.value.params.doctype)return s.value.params.doctype;const c=s.value.params.pathMatch;return c&&c.length>0?c[0]:""}),f=t.computed(()=>{if(!s.value)return"";if(s.value.params.recordId)return s.value.params.recordId;const c=s.value.params.pathMatch;return c&&c.length>1?c[1]:""}),g=t.computed(()=>f.value?.startsWith("new-")),b=t.computed(()=>{if(!s.value||s.value.name==="home"||s.value.path==="/")return"doctypes";if(s.value.name&&s.value.name!=="catch-all"){const p=s.value.name;if(p.includes("form")||s.value.params.recordId)return"record";if(p.includes("list")||s.value.params.doctype)return"records"}const c=s.value.params.pathMatch;return c&&c.length>0?c.length===1?"records":"record":"doctypes"}),R=()=>{if(!e.value||!l.value||!f.value)return[];try{const p=e.value.registry.registry[l.value];if(!p?.workflow?.states)return[];const E=g.value?"creating":"editing",C=p.workflow.states[E];return C?.on?Object.keys(C.on).map(W=>{const ne=C.on?.[W],G=typeof ne=="string"?ne:"unknown",ao=async()=>{const je=e.value?.getRecordById(l.value,f.value);if(je){const no=i.value||{};await je.triggerTransition(W,{currentState:E,targetState:G,fsmContext:no})}};return{label:`${W} (→ ${G})`,action:ao}}):[]}catch(c){return console.warn("Error getting available transitions:",c),[]}},_=t.computed(()=>{const c=[];switch(b.value){case"doctypes":c.push({type:"button",label:"Refresh",action:()=>{window.location.reload()}});break;case"records":c.push({type:"button",label:"New Record",action:()=>{F()}},{type:"button",label:"Refresh",action:()=>{window.location.reload()}});break;case"record":{const p=R();p.length>0&&c.push({type:"dropdown",label:"Actions",actions:p});break}}return c}),O=t.computed(()=>{const c=[];return b.value==="records"&&d.value?c.push({title:"Home",to:"/"},{title:T(d.value),to:`/${d.value}`}):b.value==="record"&&d.value&&c.push({title:"Home",to:"/"},{title:T(d.value),to:`/${d.value}`},{title:g.value?"New Record":"Edit Record",to:s.value?.fullPath||""}),c}),I=c=>{const p=[{title:"Go Home",description:"Navigate to the home page",action:()=>{u.value?.push("/")}},{title:"Toggle Command Palette",description:"Open/close the command palette",action:()=>r.value=!r.value}];return d.value&&(p.push({title:`View ${T(d.value)} Records`,description:`Navigate to ${d.value} list`,action:()=>{u.value?.push(`/${d.value}`)}}),p.push({title:`Create New ${T(d.value)}`,description:`Create a new ${d.value} record`,action:()=>{F()}})),o.availableDoctypes.forEach(E=>{p.push({title:`View ${T(E)}`,description:`Navigate to ${E} list`,action:()=>{u.value?.push(`/${E}`)}})}),c?p.filter(E=>E.title.toLowerCase().includes(c.toLowerCase())||E.description.toLowerCase().includes(c.toLowerCase())):p},x=c=>{c.action(),r.value=!1},T=c=>c.split("-").map(p=>p.charAt(0).toUpperCase()+p.slice(1)).join(" "),j=c=>e.value?e.value.getRecordIds(c).length:0,K=async c=>{await u.value?.push(`/${c}`)},H=async c=>{await u.value?.push(`/${d.value}/${c}`)},F=async()=>{const c=`new-${Date.now()}`;await u.value?.push(`/${d.value}/${c}`)},N=c=>{if(e.value)try{e.value.records(c)}catch{}},M=()=>{if(!o.availableDoctypes.length)return[];const c=o.availableDoctypes.map(p=>({id:p,doctype:p,display_name:T(p),record_count:j(p),actions:"View Records"}));return[{fieldname:"header",component:"div",value:`
5
+ This will fail in production.`);s=te,s._s.has(o)||(r?me(o,e,n,s):Oe(o,n,s),process.env.NODE_ENV!=="production"&&(i._pinia=s));const d=s._s.get(o);if(process.env.NODE_ENV!=="production"&&u){const f="__hot:"+o,g=r?me(f,e,n,s,!0):Oe(f,z({},n),s,!0);u._hotUpdate(g),delete s.state.value[f],s._s.delete(f)}if(process.env.NODE_ENV!=="production"&&ee){const f=t.getCurrentInstance();if(f&&f.proxy&&!u){const g=f.proxy,b="_pStores"in g?g._pStores:g._pStores={};b[o]=d}}return d}return i.$id=o,i}function it(o){const e=t.toRaw(o),a={};for(const n in e){const r=e[n];r.effect?a[n]=t.computed({get:()=>o[n],set(i){o[n]=i}}):(t.isRef(r)||t.isReactive(r))&&(a[n]=t.toRef(o,n))}return a}const ct=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const ut=Object.prototype.toString,dt=o=>ut.call(o)==="[object Object]",pt=()=>{};function ft(...o){if(o.length!==1)return t.toRef(...o);const e=o[0];return typeof e=="function"?t.readonly(t.customRef(()=>({get:e,set:pt}))):t.ref(e)}function ht(o,e){function a(...n){return new Promise((r,i)=>{Promise.resolve(o(()=>e.apply(this,n),{fn:e,thisArg:this,args:n})).then(r).catch(i)})}return a}const Ce=o=>o();function mt(o=Ce,e={}){const{initialState:a="active"}=e,n=ft(a==="active");function r(){n.value=!1}function i(){n.value=!0}const s=(...u)=>{n.value&&o(...u)};return{isActive:t.readonly(n),pause:r,resume:i,eventFilter:s}}function ge(o){return Array.isArray(o)?o:[o]}function gt(o){return t.getCurrentInstance()}function yt(o,e,a={}){const{eventFilter:n=Ce,...r}=a;return t.watch(o,ht(n,e),r)}function vt(o,e,a={}){const{eventFilter:n,initialState:r="active",...i}=a,{eventFilter:s,pause:u,resume:l,isActive:d}=mt(n,{initialState:r});return{stop:yt(o,e,{...i,eventFilter:s}),pause:u,resume:l,isActive:d}}const wt=vt;function bt(o,e=!0,a){gt()?t.onMounted(o,a):e?o():t.nextTick(o)}function St(o,e,a){return t.watch(o,e,{...a,immediate:!0})}const se=ct?window:void 0;function Et(o){var e;const a=t.toValue(o);return(e=a?.$el)!==null&&e!==void 0?e:a}function Ve(...o){const e=(n,r,i,s)=>(n.addEventListener(r,i,s),()=>n.removeEventListener(r,i,s)),a=t.computed(()=>{const n=ge(t.toValue(o[0])).filter(r=>r!=null);return n.every(r=>typeof r!="string")?n:void 0});return St(()=>{var n,r;return[(n=(r=a.value)===null||r===void 0?void 0:r.map(i=>Et(i)))!==null&&n!==void 0?n:[se].filter(i=>i!=null),ge(t.toValue(a.value?o[1]:o[0])),ge(t.unref(a.value?o[2]:o[1])),t.toValue(a.value?o[3]:o[2])]},([n,r,i,s],u,l)=>{if(!n?.length||!r?.length||!i?.length)return;const d=dt(s)?{...s}:s,f=n.flatMap(g=>r.flatMap(b=>i.map(D=>e(g,b,D,d))));l(()=>{f.forEach(g=>g())})},{flush:"post"})}const le=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},ie="__vueuse_ssr_handlers__",kt=Nt();function Nt(){return ie in le||(le[ie]=le[ie]||{}),le[ie]}function $t(o,e){return kt[o]||e}function _t(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 Dt={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()}},Te="vueuse-storage";function Rt(o,e,a,n={}){var r;const{flush:i="pre",deep:s=!0,listenToStorageChanges:u=!0,writeDefaults:l=!0,mergeDefaults:d=!1,shallow:f,window:g=se,eventFilter:b,onError:D=R=>{console.error(R)},initOnMounted:_}=n,O=(f?t.shallowRef:t.ref)(e),I=t.computed(()=>t.toValue(o));if(!a)try{a=$t("getDefaultStorage",()=>se?.localStorage)()}catch(R){D(R)}if(!a)return O;const x=t.toValue(e),T=_t(x),j=(r=n.serializer)!==null&&r!==void 0?r:Dt[T],{pause:K,resume:H}=wt(O,R=>y(R),{flush:i,deep:s,eventFilter:b});t.watch(I,()=>P(),{flush:i});let F=!1;const N=R=>{_&&!F||P(R)},M=R=>{_&&!F||U(R)};g&&u&&(a instanceof Storage?Ve(g,"storage",N,{passive:!0}):Ve(g,Te,M)),_?bt(()=>{F=!0,P()}):P();function w(R,A){if(g){const B={key:I.value,oldValue:R,newValue:A,storageArea:a};g.dispatchEvent(a instanceof Storage?new StorageEvent("storage",B):new CustomEvent(Te,{detail:B}))}}function y(R){try{const A=a.getItem(I.value);if(R==null)w(A,null),a.removeItem(I.value);else{const B=j.write(R);A!==B&&(a.setItem(I.value,B),w(A,B))}}catch(A){D(A)}}function V(R){const A=R?R.newValue:a.getItem(I.value);if(A==null)return l&&x!=null&&a.setItem(I.value,j.write(x)),x;if(!R&&d){const B=j.read(A);return typeof d=="function"?d(B,x):T==="object"&&!Array.isArray(B)?{...x,...B}:B}else return typeof A!="string"?A:j.read(A)}function P(R){if(!(R&&R.storageArea!==a)){if(R&&R.key==null){O.value=x;return}if(!(R&&R.key!==I.value)){K();try{const A=j.write(O.value);(R===void 0||R?.newValue!==A)&&(O.value=V(R))}catch(A){D(A)}finally{R?t.nextTick(H):H()}}}}function U(R){P(R.detail)}return O}function Ot(o,e,a={}){const{window:n=se}=a;return Rt(o,e,n?.localStorage,a)}function ye(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function ce(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(a=>({...a,timestamp:a.timestamp.toISOString()}))),e}function Ct(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(a=>({...a,timestamp:new Date(a.timestamp)}))),e}const Ae=lt("hst-operation-log",()=>{const o=t.ref({maxOperations:100,enableCrossTabSync:!0,autoSyncInterval:3e4,enablePersistence:!1,persistenceKeyPrefix:"stonecrop-ops"}),e=t.ref([]),a=t.ref(-1),n=t.ref(ye()),r=t.ref(!1),i=t.ref([]),s=t.ref(null),u=t.computed(()=>a.value<0?!1:e.value[a.value]?.reversible??!1),l=t.computed(()=>a.value<e.value.length-1),d=t.computed(()=>{let h=0;for(let m=a.value;m>=0&&e.value[m]?.reversible;m--)h++;return h}),f=t.computed(()=>e.value.length-1-a.value),g=t.computed(()=>({canUndo:u.value,canRedo:l.value,undoCount:d.value,redoCount:f.value,currentIndex:a.value}));function b(h){o.value={...o.value,...h},o.value.enablePersistence&&(S(),$()),o.value.enableCrossTabSync&&V()}function D(h,m="user"){const v={...h,id:ye(),timestamp:new Date,source:m,userId:o.value.userId};if(o.value.operationFilter&&!o.value.operationFilter(v))return v.id;if(r.value)return i.value.push(v),v.id;if(a.value<e.value.length-1&&(e.value=e.value.slice(0,a.value+1)),e.value.push(v),a.value++,o.value.maxOperations&&e.value.length>o.value.maxOperations){const c=e.value.length-o.value.maxOperations;e.value=e.value.slice(c),a.value-=c}return o.value.enableCrossTabSync&&P(v),v.id}function _(){r.value=!0,i.value=[],s.value=ye()}function O(h){if(!r.value||i.value.length===0)return r.value=!1,i.value=[],s.value=null,null;const m=s.value,v=i.value.every(E=>E.reversible),c={id:m,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(E=>E.id),metadata:{description:h}};i.value.forEach(E=>{E.parentOperationId=m}),e.value.push(...i.value,c),a.value=e.value.length-1,o.value.enableCrossTabSync&&U(i.value,c);const p=m;return r.value=!1,i.value=[],s.value=null,p}function I(){r.value=!1,i.value=[],s.value=null}function x(h){if(!u.value)return!1;const m=e.value[a.value];if(!m.reversible)return typeof console<"u"&&m.irreversibleReason&&console.warn("Cannot undo irreversible operation:",m.irreversibleReason),!1;try{if(m.type==="batch"&&m.childOperationIds)for(let v=m.childOperationIds.length-1;v>=0;v--){const c=m.childOperationIds[v],p=e.value.find(E=>E.id===c);p&&j(p,h)}else j(m,h);return a.value--,o.value.enableCrossTabSync&&R(m),!0}catch(v){return typeof console<"u"&&console.error("Undo failed:",v),!1}}function T(h){if(!l.value)return!1;const m=e.value[a.value+1];try{if(m.type==="batch"&&m.childOperationIds)for(const v of m.childOperationIds){const c=e.value.find(p=>p.id===v);c&&K(c,h)}else K(m,h);return a.value++,o.value.enableCrossTabSync&&A(m),!0}catch(v){return typeof console<"u"&&console.error("Redo failed:",v),!1}}function j(h,m){(h.type==="set"||h.type==="delete")&&m&&typeof m.set=="function"&&m.set(h.path,h.beforeValue,"undo")}function K(h,m){(h.type==="set"||h.type==="delete")&&m&&typeof m.set=="function"&&m.set(h.path,h.afterValue,"redo")}function H(){const h=e.value.filter(v=>v.reversible).length,m=e.value.map(v=>v.timestamp);return{operations:[...e.value],currentIndex:a.value,totalOperations:e.value.length,reversibleOperations:h,irreversibleOperations:e.value.length-h,oldestOperation:m.length>0?new Date(Math.min(...m.map(v=>v.getTime()))):void 0,newestOperation:m.length>0?new Date(Math.max(...m.map(v=>v.getTime()))):void 0}}function F(){e.value=[],a.value=-1}function N(h,m){return e.value.filter(v=>v.doctype===h&&(m===void 0||v.recordId===m))}function M(h,m){const v=e.value.find(c=>c.id===h);v&&(v.reversible=!1,v.irreversibleReason=m)}function w(h,m,v,c="success",p){const E={type:"action",path:v&&v.length>0?`${h}.${v[0]}`:h,fieldname:"",beforeValue:null,afterValue:null,doctype:h,recordId:v&&v.length>0?v[0]:void 0,reversible:!1,actionName:m,actionRecordIds:v,actionResult:c,actionError:p};return D(E)}let y=null;function V(){typeof window>"u"||!window.BroadcastChannel||(y=new BroadcastChannel("stonecrop-operation-log"),y.addEventListener("message",h=>{const m=h.data;if(!m||typeof m!="object")return;const v=Ct(m);v.clientId!==n.value&&(v.type==="operation"&&v.operation?(e.value.push({...v.operation,source:"sync"}),a.value=e.value.length-1):v.type==="operation"&&v.operations&&(e.value.push(...v.operations.map(c=>({...c,source:"sync"}))),a.value=e.value.length-1))}))}function P(h){if(!y)return;const m={type:"operation",operation:h,clientId:n.value,timestamp:new Date};y.postMessage(ce(m))}function U(h,m){if(!y)return;const v={type:"operation",operations:[...h,m],clientId:n.value,timestamp:new Date};y.postMessage(ce(v))}function R(h){if(!y)return;const m={type:"undo",operation:h,clientId:n.value,timestamp:new Date};y.postMessage(ce(m))}function A(h){if(!y)return;const m={type:"redo",operation:h,clientId:n.value,timestamp:new Date};y.postMessage(ce(m))}const B=Ot("stonecrop-ops-operations",null,{serializer:{read:h=>{try{return JSON.parse(h)}catch{return null}},write:h=>h?JSON.stringify(h):""}});function S(){if(!(typeof window>"u"))try{const h=B.value;h&&Array.isArray(h.operations)&&(e.value=h.operations.map(m=>({...m,timestamp:new Date(m.timestamp)})),a.value=h.currentIndex??-1)}catch(h){typeof console<"u"&&console.error("Failed to load operations from persistence:",h)}}function k(){if(!(typeof window>"u"))try{B.value={operations:e.value.map(h=>({...h,timestamp:h.timestamp.toISOString()})),currentIndex:a.value}}catch(h){typeof console<"u"&&console.error("Failed to save operations to persistence:",h)}}function $(){t.watch([e,a],()=>{o.value.enablePersistence&&k()},{deep:!0})}return{operations:e,currentIndex:a,config:o,clientId:n,undoRedoState:g,canUndo:u,canRedo:l,undoCount:d,redoCount:f,configure:b,addOperation:D,startBatch:_,commitBatch:O,cancelBatch:I,undo:x,redo:T,clear:F,getOperationsFor:N,getSnapshot:H,markIrreversible:M,logAction:w}});class ae{static _root;options;doctypeActions=new Map;doctypeTransitions=new Map;fieldRollbackConfig=new Map;globalActions=new Map;globalTransitionActions=new Map;constructor(e={}){if(ae._root)return ae._root;ae._root=this,this.options={defaultTimeout:e.defaultTimeout??5e3,debug:e.debug??!1,enableRollback:e.enableRollback??!0,errorHandler:e.errorHandler}}registerAction(e,a){this.globalActions.set(e,a)}registerTransitionAction(e,a){this.globalTransitionActions.set(e,a)}setFieldRollback(e,a,n){this.fieldRollbackConfig.has(e)||this.fieldRollbackConfig.set(e,new Map),this.fieldRollbackConfig.get(e).set(a,n)}getFieldRollback(e,a){return this.fieldRollbackConfig.get(e)?.get(a)}registerDoctypeActions(e,a){if(!a)return;const n=new Map,r=new Map;if(typeof a.entrySeq=="function")a.entrySeq().forEach(([i,s])=>{this.categorizeAction(i,s,n,r)});else if(a instanceof Map)for(const[i,s]of a)this.categorizeAction(i,s,n,r);else a&&typeof a=="object"&&Object.entries(a).forEach(([i,s])=>{this.categorizeAction(i,s,n,r)});this.doctypeActions.set(e,n),this.doctypeTransitions.set(e,r)}categorizeAction(e,a,n,r){this.isTransitionKey(e)?r.set(e,a):n.set(e,a)}isTransitionKey(e){return/^[A-Z0-9_]+$/.test(e)&&e.length>0}async executeFieldTriggers(e,a={}){const{doctype:n,fieldname:r}=e,i=this.findFieldTriggers(n,r);if(i.length===0)return{path:e.path,actionResults:[],totalExecutionTime:0,allSucceeded:!0,stoppedOnError:!1,rolledBack:!1};const s=performance.now(),u=[];let l=!1,d=!1,f;const g=this.getFieldRollback(n,r),b=a.enableRollback??g??this.options.enableRollback;b&&e.store&&(f=this.captureSnapshot(e));for(const O of i)try{const I=await this.executeAction(O,e,a.timeout);if(u.push(I),!I.success){l=!0;break}}catch(I){const x={success:!1,error:I instanceof Error?I:new Error(String(I)),executionTime:0,action:O};u.push(x),l=!0;break}if(b&&l&&f&&e.store)try{this.restoreSnapshot(e,f),d=!0}catch(O){console.error("[FieldTriggers] Rollback failed:",O)}const D=performance.now()-s,_=u.filter(O=>!O.success);if(_.length>0&&this.options.errorHandler)for(const O of _)try{this.options.errorHandler(O.error,e,O.action)}catch(I){console.error("[FieldTriggers] Error in global error handler:",I)}return{path:e.path,actionResults:u,totalExecutionTime:D,allSucceeded:u.every(O=>O.success),stoppedOnError:l,rolledBack:d,snapshot:this.options.debug&&b?f:void 0}}async executeTransitionActions(e,a={}){const{doctype:n,transition:r}=e,i=this.findTransitionActions(n,r);if(i.length===0)return[];const s=[];for(const l of i)try{const d=await this.executeTransitionAction(l,e,a.timeout);if(s.push(d),!d.success)break}catch(d){const f={success:!1,error:d instanceof Error?d:new Error(String(d)),executionTime:0,action:l,transition:r};s.push(f);break}const u=s.filter(l=>!l.success);if(u.length>0&&this.options.errorHandler)for(const l of u)try{this.options.errorHandler(l.error,e,l.action)}catch(d){console.error("[FieldTriggers] Error in global error handler:",d)}return s}findTransitionActions(e,a){const n=this.doctypeTransitions.get(e);return n?n.get(a)||[]:[]}async executeTransitionAction(e,a,n){const r=performance.now(),i=n??this.options.defaultTimeout;try{let s=this.globalTransitionActions.get(e);if(!s){const u=this.globalActions.get(e);u&&(s=u)}if(!s)throw new Error(`Transition action "${e}" not found in registry`);return await this.executeWithTimeout(s,a,i),{success:!0,executionTime:performance.now()-r,action:e,transition:a.transition}}catch(s){const u=performance.now()-r;return{success:!1,error:s instanceof Error?s:new Error(String(s)),executionTime:u,action:e,transition:a.transition}}}findFieldTriggers(e,a){const n=this.doctypeActions.get(e);if(!n)return[];const r=[];for(const[i,s]of n)this.isFieldTriggerKey(i,a)&&r.push(...s);return r}isFieldTriggerKey(e,a){return e===a?!0:e.includes(".")?this.matchFieldPattern(e,a):e.includes("*")?this.matchFieldPattern(e,a):!1}matchFieldPattern(e,a){const n=e.split("."),r=a.split(".");if(n.length!==r.length)return!1;for(let i=0;i<n.length;i++){const s=n[i],u=r[i];if(s!=="*"&&s!==u)return!1}return!0}async executeAction(e,a,n){const r=performance.now(),i=n??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,a,i),{success:!0,executionTime:performance.now()-r,action:e}}catch(s){const u=performance.now()-r;return{success:!1,error:s instanceof Error?s:new Error(String(s)),executionTime:u,action:e}}}async executeWithTimeout(e,a,n){return new Promise((r,i)=>{const s=setTimeout(()=>{i(new Error(`Action timeout after ${n}ms`))},n);Promise.resolve(e(a)).then(u=>{clearTimeout(s),r(u)}).catch(u=>{clearTimeout(s),i(u)})})}captureSnapshot(e){if(!(!e.store||!e.doctype||!e.recordId))try{const a=`${e.doctype}.${e.recordId}`,n=e.store.get(a);return!n||typeof n!="object"?void 0:JSON.parse(JSON.stringify(n))}catch(a){this.options.debug&&console.warn("[FieldTriggers] Failed to capture snapshot:",a);return}}restoreSnapshot(e,a){if(!(!e.store||!e.doctype||!e.recordId||!a))try{const n=`${e.doctype}.${e.recordId}`;e.store.set(n,a),this.options.debug&&console.log(`[FieldTriggers] Rolled back ${n} to previous state`)}catch(n){throw console.error("[FieldTriggers] Failed to restore snapshot:",n),n}}}function Ie(o){return new ae(o)}function xe(){try{return Ae()}catch{return null}}class Y{static instance;static getInstance(){return Y.instance||(Y.instance=new Y),Y.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 a=this.getRegistry();if(a&&typeof a=="object"&&"registry"in a)return a.registry[e]}}class ue{target;parentPath;rootNode;doctype;parentDoctype;hst;constructor(e,a,n="",r=null,i){return this.target=e,this.parentPath=n,this.rootNode=r||this,this.doctype=a,this.parentDoctype=i,this.hst=Y.getInstance(),new Proxy(this,{get(s,u){if(u in s)return s[u];const l=String(u);return s.getNode(l)},set(s,u,l){const d=String(u);return s.set(d,l),!0}})}get(e){return this.resolveValue(e)}getNode(e){const a=this.resolvePath(e),n=this.resolveValue(e),r=a.split(".");let i=this.doctype;return this.doctype==="StonecropStore"&&r.length>=1&&(i=r[0]),typeof n=="object"&&n!==null&&!this.isPrimitive(n)?new ue(n,i,a,this.rootNode,this.parentDoctype):new ue(n,i,a,this.rootNode,this.parentDoctype)}set(e,a,n="user"){const r=this.resolvePath(e),i=this.has(e)?this.get(e):void 0;if(n!=="undo"&&n!=="redo"){const s=xe();if(s&&typeof s.addOperation=="function"){const u=r.split("."),l=this.doctype==="StonecropStore"&&u.length>=1?u[0]:this.doctype,d=u.length>=2?u[1]:void 0,f=u.slice(2).join(".")||u[u.length-1],g=a===void 0&&i!==void 0?"delete":"set";s.addOperation({type:g,path:r,fieldname:f,beforeValue:i,afterValue:a,doctype:l,recordId:d,reversible:!0},n)}}this.updateValue(e,a),this.triggerFieldActions(r,i,a)}has(e){try{if(e==="")return!0;const a=this.parsePath(e);let n=this.target;for(let r=0;r<a.length;r++){const i=a[r];if(n==null)return!1;if(r===a.length-1)return this.isImmutable(n)?n.has(i):this.isPiniaStore(n)&&n.$state&&i in n.$state||i in n;n=this.getProperty(n,i)}return!1}catch{return!1}}getParent(){if(!this.parentPath)return null;const e=this.parentPath.split(".").slice(0,-1).join(".");return e===""?this.rootNode:this.rootNode.getNode(e)}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,a){const n=Ie(),r=this.parentPath.split(".");let i=this.doctype,s;this.doctype==="StonecropStore"&&r.length>=1&&(i=r[0]),r.length>=2&&(s=r[1]);const u={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:a?.currentState,targetState:a?.targetState,fsmContext:a?.fsmContext},l=xe();return l&&typeof l.addOperation=="function"&&l.addOperation({type:"transition",path:this.parentPath,fieldname:e,beforeValue:a?.currentState,afterValue:a?.targetState,doctype:i,recordId:s,reversible:!1,metadata:{transition:e,currentState:a?.currentState,targetState:a?.targetState,fsmContext:a?.fsmContext}},"user"),await n.executeTransitionActions(u)}resolvePath(e){return e===""?this.parentPath:this.parentPath?`${this.parentPath}.${e}`:e}resolveValue(e){if(e==="")return this.target;const a=this.parsePath(e);let n=this.target;for(const r of a){if(n==null)return;n=this.getProperty(n,r)}return n}updateValue(e,a){if(e==="")throw new Error("Cannot set value on empty path");const n=this.parsePath(e),r=n.pop();let i=this.target;for(const s of n)if(i=this.getProperty(i,s),i==null)throw new Error(`Cannot set property on null/undefined path: ${e}`);this.setProperty(i,r,a)}getProperty(e,a){return this.isImmutable(e)?e.get(a):this.isVueReactive(e)?e[a]:this.isPiniaStore(e)?e.$state?.[a]??e[a]:e[a]}setProperty(e,a,n){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({[a]:n}):e[a]=n;return}e[a]=n}async triggerFieldActions(e,a,n){try{if(!e||typeof e!="string")return;const r=e.split(".");if(r.length<3)return;const i=Ie(),s=r.slice(2).join(".")||r[r.length-1];let u=this.doctype;this.doctype==="StonecropStore"&&r.length>=1&&(u=r[0]);let l;r.length>=2&&(l=r[1]);const d={path:e,fieldname:s,beforeValue:a,afterValue:n,operation:"set",doctype:u,recordId:l,timestamp:new Date,store:this.rootNode||void 0};await i.executeFieldTriggers(d)}catch(r){r instanceof Error&&console.warn("Field trigger error:",r.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 a="get"in e&&typeof e.get=="function",n="set"in e&&typeof e.set=="function",r="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&&a&&n;let s;try{const l=e;if("constructor"in l&&l.constructor&&typeof l.constructor=="object"&&"name"in l.constructor){const d=l.constructor.name;s=typeof d=="string"?d:void 0}}catch{s=void 0}const u=s&&(s.includes("Map")||s.includes("List")||s.includes("Set")||s.includes("Stack")||s.includes("Seq"))&&(a||n);return!!(a&&n&&r&&i||a&&n&&u)}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.replace(/\[(\d+)\]/g,".$1").split(".").filter(a=>a.length>0):[]}}function Vt(o,e,a){return new ue(o,e,"",null,a)}class Tt{hstStore;_operationLogStore;_operationLogConfig;registry;constructor(e,a){this.registry=e,this._operationLogConfig=a,this.initializeHSTStore(),this.setupRegistrySync()}getOperationLogStore(){return this._operationLogStore||(this._operationLogStore=Ae(),this._operationLogConfig&&this._operationLogStore.configure(this._operationLogConfig)),this._operationLogStore}initializeHSTStore(){const e={};Object.keys(this.registry.registry).forEach(a=>{e[a]={}}),this.hstStore=Vt(t.reactive(e),"StonecropStore")}setupRegistrySync(){const e=this.registry.addDoctype.bind(this.registry);this.registry.addDoctype=a=>{e(a),this.hstStore.has(a.slug)||this.hstStore.set(a.slug,{})}}records(e){const a=typeof e=="string"?e:e.slug;return this.ensureDoctypeExists(a),this.hstStore.getNode(a)}addRecord(e,a,n){const r=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(r),this.hstStore.set(`${r}.${a}`,n)}getRecordById(e,a){const n=typeof e=="string"?e:e.slug;if(this.ensureDoctypeExists(n),!(!this.hstStore.has(`${n}.${a}`)||this.hstStore.get(`${n}.${a}`)===void 0))return this.hstStore.getNode(`${n}.${a}`)}removeRecord(e,a){const n=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(n),this.hstStore.has(`${n}.${a}`)&&this.hstStore.set(`${n}.${a}`,void 0)}getRecordIds(e){const a=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(a);const n=this.hstStore.get(a);return!n||typeof n!="object"?[]:Object.keys(n).filter(r=>n[r]!==void 0)}clearRecords(e){const a=typeof e=="string"?e:e.slug;this.ensureDoctypeExists(a),this.getRecordIds(a).forEach(n=>{this.hstStore.set(`${a}.${n}`,void 0)})}setup(e){this.ensureDoctypeExists(e.slug)}runAction(e,a,n){const r=this.registry.registry[e.slug]?.actions?.get(a),i=Array.isArray(n)?n.filter(d=>typeof d=="string"):void 0,s=this.getOperationLogStore();let u="success",l;try{r&&r.length>0&&r.forEach(d=>{try{new Function("args",d)(n)}catch(f){throw u="failure",l=f instanceof Error?f.message:"Unknown error",f}})}catch{}finally{s.logAction(e.doctype,a,i,u,l)}}async getRecords(e){(await(await fetch(`/${e.slug}`)).json()).forEach(a=>{a.id&&this.addRecord(e,a.id,a)})}async getRecord(e,a){const n=await(await fetch(`/${e.slug}/${a}`)).json();this.addRecord(e,a,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 At(o){o||(o={});const e=o.registry||t.inject("$registry"),a=t.inject("$stonecrop"),n=t.ref(),r=t.ref(),i=t.ref({}),s=t.ref(),u=t.ref(),l=t.ref([]);if(o.doctype&&e){const S=o.doctype.schema?Array.isArray(o.doctype.schema)?o.doctype.schema:Array.from(o.doctype.schema):[];l.value=e.resolveSchema(S)}const d=t.ref([]),f=t.ref(-1),g=t.computed(()=>n.value?.getOperationLogStore().canUndo??!1),b=t.computed(()=>n.value?.getOperationLogStore().canRedo??!1),D=t.computed(()=>n.value?.getOperationLogStore().undoCount??0),_=t.computed(()=>n.value?.getOperationLogStore().redoCount??0),O=t.computed(()=>n.value?.getOperationLogStore().undoRedoState??{canUndo:!1,canRedo:!1,undoCount:0,redoCount:0,currentIndex:-1}),I=S=>n.value?.getOperationLogStore().undo(S)??!1,x=S=>n.value?.getOperationLogStore().redo(S)??!1,T=()=>{n.value?.getOperationLogStore().startBatch()},j=S=>n.value?.getOperationLogStore().commitBatch(S)??null,K=()=>{n.value?.getOperationLogStore().cancelBatch()},H=()=>{n.value?.getOperationLogStore().clear()},F=(S,k)=>n.value?.getOperationLogStore().getOperationsFor(S,k)??[],N=()=>n.value?.getOperationLogStore().getSnapshot()??{operations:[],currentIndex:-1,totalOperations:0,reversibleOperations:0,irreversibleOperations:0},M=(S,k)=>{n.value?.getOperationLogStore().markIrreversible(S,k)},w=(S,k,$,h="success",m)=>n.value?.getOperationLogStore().logAction(S,k,$,h,m)??"",y=S=>{n.value?.getOperationLogStore().configure(S)};t.onMounted(async()=>{if(e){n.value=a||new Tt(e);try{const S=n.value.getOperationLogStore(),k=it(S);d.value=k.operations.value,f.value=k.currentIndex.value,t.watch(()=>k.operations.value,$=>{d.value=$}),t.watch(()=>k.currentIndex.value,$=>{f.value=$})}catch{}if(!o.doctype&&e.router){const S=e.router.currentRoute.value;if(!S.path)return;const k=S.path.split("/").filter(h=>h.length>0),$=k[1]?.toLowerCase();if(k.length>0){const h={path:S.path,segments:k},m=await e.getMeta?.(h);if(m){if(e.addDoctype(m),n.value.setup(m),s.value=m,u.value=$,r.value=n.value.getStore(),e){const v=m.schema?Array.isArray(m.schema)?m.schema:Array.from(m.schema):[];l.value=e.resolveSchema(v)}if($&&$!=="new"){const v=n.value.getRecordById(m,$);if(v)i.value=v.get("")||{};else try{await n.value.getRecord(m,$);const c=n.value.getRecordById(m,$);c&&(i.value=c.get("")||{})}catch{i.value=Z(m)}}else i.value=Z(m);r.value&&Pe(m,$||"new",i,r.value),n.value.runAction(m,"load",$?[$]:void 0)}}}if(o.doctype){r.value=n.value.getStore();const S=o.doctype,k=o.recordId;if(k&&k!=="new"){const $=n.value.getRecordById(S,k);if($)i.value=$.get("")||{};else try{await n.value.getRecord(S,k);const h=n.value.getRecordById(S,k);h&&(i.value=h.get("")||{})}catch{i.value=Z(S)}}else i.value=Z(S);r.value&&Pe(S,k||"new",i,r.value)}}});const V=(S,k)=>{const $=o.doctype||s.value;if(!$)return"";const h=k||o.recordId||u.value||"new";return`${$.slug}.${h}.${S}`},P=S=>{const k=o.doctype||s.value;if(!(!r.value||!n.value||!k))try{const $=S.path.split(".");if($.length>=2){const v=$[0],c=$[1];if(r.value.has(`${v}.${c}`)||n.value.addRecord(k,c,{...i.value}),$.length>3){const p=`${v}.${c}`,E=$.slice(2);let C=p;for(let L=0;L<E.length-1;L++)if(C+=`.${E[L]}`,!r.value.has(C)){const q=E[L+1],W=!isNaN(Number(q));r.value.set(C,W?[]:{})}}}r.value.set(S.path,S.value);const h=S.fieldname.split("."),m={...i.value};h.length===1?m[h[0]]=S.value:It(m,h,S.value),i.value=m}catch{}};(o.doctype||e?.router)&&(t.provide("hstPathProvider",V),t.provide("hstChangeHandler",P));const U=(S,k,$)=>{if(!n.value)return Z(k);if($)try{const h=r.value?.get(S);return h&&typeof h=="object"?h:Z(k)}catch{return Z(k)}return Z(k)},R=async(S,k)=>{if(!r.value||!n.value)throw new Error("HST store not initialized");const $=`${S.slug}.${k}`,h={...r.value.get($)||{}},m=S.schema?Array.isArray(S.schema)?S.schema:Array.from(S.schema):[],v=(e?e.resolveSchema(m):m).filter(c=>"fieldtype"in c&&c.fieldtype==="Doctype"&&"schema"in c&&Array.isArray(c.schema));for(const c of v){const p=c,E=`${$}.${p.fieldname}`,C=Be(p.schema,E,r.value);h[p.fieldname]=C}return h},A=(S,k)=>({provideHSTPath:$=>`${S}.${$}`,handleHSTChange:$=>{const h=$.path.startsWith(S)?$.path:`${S}.${$.fieldname}`;P({...$,path:h})}}),B={operations:d,currentIndex:f,undoRedoState:O,canUndo:g,canRedo:b,undoCount:D,redoCount:_,undo:I,redo:x,startBatch:T,commitBatch:j,cancelBatch:K,clear:H,getOperationsFor:F,getSnapshot:N,markIrreversible:M,logAction:w,configure:y};return o.doctype?{stonecrop:n,operationLog:B,provideHSTPath:V,handleHSTChange:P,hstStore:r,formData:i,resolvedSchema:l,loadNestedData:U,saveRecursive:R,createNestedContext:A}:!o.doctype&&e?.router?{stonecrop:n,operationLog:B,provideHSTPath:V,handleHSTChange:P,hstStore:r,formData:i,resolvedSchema:l,loadNestedData:U,saveRecursive:R,createNestedContext:A}:{stonecrop:n,operationLog:B}}function Z(o){const e={};return o.schema&&o.schema.forEach(a=>{switch("fieldtype"in a?a.fieldtype:"Data"){case"Data":case"Text":e[a.fieldname]="";break;case"Check":e[a.fieldname]=!1;break;case"Int":case"Float":e[a.fieldname]=0;break;case"Table":e[a.fieldname]=[];break;case"JSON":e[a.fieldname]={};break;default:e[a.fieldname]=null}}),e}function Pe(o,e,a,n){t.watch(a,r=>{const i=`${o.slug}.${e}`;Object.keys(r).forEach(s=>{const u=`${i}.${s}`;try{n.set(u,r[s])}catch{}})},{deep:!0})}function It(o,e,a){let n=o;for(let i=0;i<e.length-1;i++){const s=e[i];(!(s in n)||typeof n[s]!="object")&&(n[s]=isNaN(Number(e[i+1]))?{}:[]),n=n[s]}const r=e[e.length-1];n[r]=a}function Be(o,e,a){const n={...a.get(e)||{}},r=o.filter(i=>"fieldtype"in i&&i.fieldtype==="Doctype"&&"schema"in i&&Array.isArray(i.schema));for(const i of r){const s=i,u=`${e}.${s.fieldname}`,l=Be(s.schema,u,a);n[s.fieldname]=l}return n}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;function xt(o,e){return t.getCurrentScope()?(t.onScopeDispose(o,e),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Pt=()=>{};function Bt(...o){if(o.length!==1)return t.toRef(...o);const e=o[0];return typeof e=="function"?t.readonly(t.customRef(()=>({get:e,set:Pt}))):t.ref(e)}function ve(o){return typeof Window<"u"&&o instanceof Window?o.document.documentElement:typeof Document<"u"&&o instanceof Document?o.documentElement:o}const we=new WeakMap;function Mt(o,e=!1){const a=t.shallowRef(e);let n="";t.watch(Bt(o),s=>{const u=ve(t.toValue(s));if(u){const l=u;if(we.get(l)||we.set(l,l.style.overflow),l.style.overflow!=="hidden"&&(n=l.style.overflow),l.style.overflow==="hidden")return a.value=!0;if(a.value)return l.style.overflow="hidden"}},{immediate:!0});const r=()=>{const s=ve(t.toValue(o));!s||a.value||(s.style.overflow="hidden",a.value=!0)},i=()=>{const s=ve(t.toValue(o));!s||!a.value||(s.style.overflow=n,we.delete(s),a.value=!1)};return xt(i),t.computed({get(){return a.value},set(s){s?r():i()}})}function jt(){let o=!1;const e=t.shallowRef(!1);return(a,n)=>{if(e.value=n.value,o)return;o=!0;const r=Mt(a,n.value);t.watch(e,i=>r.value=i)}}jt();const Ft=(o,e)=>{const a=o.__vccOpts||o;for(const[n,r]of e)a[n]=r;return a};function Lt(o,e){return t.getCurrentScope()?(t.onScopeDispose(o,e),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Ht=()=>{};function Ut(...o){if(o.length!==1)return t.toRef(...o);const e=o[0];return typeof e=="function"?t.readonly(t.customRef(()=>({get:e,set:Ht}))):t.ref(e)}function be(o){return typeof Window<"u"&&o instanceof Window?o.document.documentElement:typeof Document<"u"&&o instanceof Document?o.documentElement:o}const Se=new WeakMap;function Wt(o,e=!1){const a=t.shallowRef(e);let n="";t.watch(Ut(o),s=>{const u=be(t.toValue(s));if(u){const l=u;if(Se.get(l)||Se.set(l,l.style.overflow),l.style.overflow!=="hidden"&&(n=l.style.overflow),l.style.overflow==="hidden")return a.value=!0;if(a.value)return l.style.overflow="hidden"}},{immediate:!0});const r=()=>{const s=be(t.toValue(o));!s||a.value||(s.style.overflow="hidden",a.value=!0)},i=()=>{const s=be(t.toValue(o));!s||!a.value||(s.style.overflow=n,Se.delete(s),a.value=!1)};return Lt(i),t.computed({get(){return a.value},set(s){s?r():i()}})}function Kt(){let o=!1;const e=t.shallowRef(!1);return(a,n)=>{if(e.value=n.value,o)return;o=!0;const r=Wt(a,n.value);t.watch(e,i=>r.value=i)}}Kt(),typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const zt={class:"aform"},Jt={key:0,class:"aform-nested-section"},Gt={key:0,class:"aform-nested-label"},qt=t.defineComponent({__name:"AForm",props:t.mergeModels({schema:{},readOnly:{type:Boolean}},{data:{required:!0},dataModifiers:{}}),emits:t.mergeModels(["update:schema","update:data"],["update:data"]),setup(o,{emit:e}){const a=e,n=t.useModel(o,"data"),r=t.ref({});t.watchEffect(()=>{!o.schema||!n.value||o.schema.forEach(l=>{"schema"in l&&Array.isArray(l.schema)&&l.schema.length>0&&(!r.value[l.fieldname]&&n.value[l.fieldname]?r.value[l.fieldname]=n.value[l.fieldname]:r.value[l.fieldname]||(r.value[l.fieldname]={}))})}),t.watchEffect(()=>{Object.keys(r.value).forEach(l=>{n.value&&r.value[l]!==n.value[l]&&(n.value[l]=r.value[l],a("update:data",n.value))})}),t.watchEffect(()=>{n.value&&o.schema&&o.schema.forEach(l=>{l.fieldname&&n.value[l.fieldname]!==void 0&&(l.value=n.value[l.fieldname])})});const i=l=>{const d={};for(const[f,g]of Object.entries(l))["component","fieldtype"].includes(f)||(d[f]=g),f==="rows"&&(!g||Array.isArray(g)&&g.length===0)&&(d.rows=n.value[l.fieldname]||[]);return d},s=t.ref([]);t.watchEffect(()=>{o.schema&&s.value.length!==o.schema.length&&(s.value=o.schema.map((l,d)=>t.computed({get(){return l.value},set:f=>{const g=o.schema[d].fieldname;o.schema[d].value=f,g&&n.value&&(n.value[g]=f,a("update:data",n.value)),a("update:schema",o.schema)}})))});const u=t.computed(()=>s.value);return(l,d)=>{const f=t.resolveComponent("AForm",!0);return t.openBlock(),t.createElementBlock("form",zt,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.schema,(g,b)=>(t.openBlock(),t.createElementBlock(t.Fragment,{key:b},["schema"in g&&Array.isArray(g.schema)&&g.schema.length>0?(t.openBlock(),t.createElementBlock("div",Jt,[g.label?(t.openBlock(),t.createElementBlock("h4",Gt,t.toDisplayString(g.label),1)):t.createCommentVNode("",!0),t.createVNode(f,{data:r.value[g.fieldname],"onUpdate:data":D=>r.value[g.fieldname]=D,schema:g.schema,"read-only":o.readOnly||g.readOnly},null,8,["data","onUpdate:data","schema","read-only"])])):(t.openBlock(),t.createBlock(t.resolveDynamicComponent(g.component),t.mergeProps({key:1,modelValue:u.value[b].value,"onUpdate:modelValue":D=>u.value[b].value=D,schema:g,data:n.value[g.fieldname],"read-only":o.readOnly},{ref_for:!0},i(g)),null,16,["modelValue","onUpdate:modelValue","schema","data","read-only"]))],64))),128))])}}}),Zt=Ft(qt,[["__scopeId","data-v-06e17c5b"]]),Qt={class:"tabs"},Xt={tabindex:"0"},Yt={tabindex:"0"},Ee=ke(t.defineComponent({__name:"SheetNav",props:{breadcrumbs:{default:()=>[]}},setup(o){const e=t.ref(!0),a=t.ref(!1),n=t.ref(""),r=t.useTemplateRef("searchinput"),i=t.computed(()=>e.value?"unrotated":"rotated"),s=()=>{e.value=!e.value},u=async()=>{a.value=!a.value,await t.nextTick(()=>{r.value?.focus()})},l=g=>{g.preventDefault(),g.stopPropagation()},d=async g=>{g.preventDefault(),g.stopPropagation(),await u()},f=()=>{};return(g,b)=>{const D=t.resolveComponent("router-link");return t.openBlock(),t.createElementBlock("footer",null,[t.createElementVNode("ul",Qt,[t.createElementVNode("li",{class:"hidebreadcrumbs",onClick:s,onKeydown:t.withKeys(s,["enter"])},[t.createElementVNode("a",Xt,[t.createElementVNode("div",{class:t.normalizeClass(i.value)},"×",2)])],32),t.createElementVNode("li",{class:"hometab",style:t.normalizeStyle({display:e.value?"block":"none"}),onClick:f,onKeydown:t.withKeys(f,["enter"])},[t.createVNode(D,{to:"/",tabindex:"0"},{default:t.withCtx(()=>[...b[5]||(b[5]=[t.createElementVNode("svg",{class:"icon","aria-label":"Home",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[t.createElementVNode("path",{d:"M3 12l9-9 9 9"}),t.createElementVNode("path",{d:"M9 21V12h6v9"})],-1)])]),_:1})],36),t.createElementVNode("li",{class:t.normalizeClass(["searchtab",{"search-active":a.value}]),style:t.normalizeStyle({display:e.value?"block":"none"})},[t.createElementVNode("a",Yt,[t.withDirectives((t.openBlock(),t.createElementBlock("svg",{class:"icon search-icon",role:"button","aria-label":"Search",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",onClick:u,onKeydown:t.withKeys(u,["enter"])},[...b[6]||(b[6]=[t.createElementVNode("circle",{cx:"11",cy:"11",r:"7"},null,-1),t.createElementVNode("path",{d:"M21 21l-4.35-4.35"},null,-1)])],544)),[[t.vShow,!a.value]]),t.withDirectives(t.createElementVNode("input",{ref:"searchinput","onUpdate:modelValue":b[0]||(b[0]=_=>n.value=_),type:"text",placeholder:"Search...",onClick:b[1]||(b[1]=t.withModifiers(()=>{},["stop"])),onInput:b[2]||(b[2]=_=>l(_)),onBlur:b[3]||(b[3]=_=>d(_)),onKeydown:[b[4]||(b[4]=t.withKeys(_=>d(_),["enter"])),t.withKeys(u,["escape"])]},null,544),[[t.vShow,a.value],[t.vModelText,n.value]])])],6),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.breadcrumbs,_=>(t.openBlock(),t.createElementBlock("li",{key:_.title,style:t.normalizeStyle({display:e.value?"block":"none"})},[t.createVNode(D,{tabindex:"0",to:_.to},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(_.title),1)]),_:2},1032,["to"])],4))),128))])])}}}),[["__scopeId","data-v-eb5bcbb6"]]),eo={key:1,class:"loading"},to={key:2,class:"loading"},Me=t.defineComponent({__name:"Desktop",props:{availableDoctypes:{default:()=>[]}},setup(o){const{stonecrop:e}=At(),a=t.ref(!1),n=t.ref(!1),r=t.ref(!1),i=t.computed({get(){if(!e.value||!l.value||!f.value)return{};try{return e.value.getRecordById(l.value,f.value)?.get("")||{}}catch{return{}}},set(c){if(!(!e.value||!l.value||!f.value))try{const p=e.value.getStore();for(const[E,C]of Object.entries(c)){const L=`${l.value}.${f.value}.${E}`;p.set(L,C)}}catch(p){console.warn("HST update failed:",p)}}}),s=t.computed(()=>t.unref(e.value?.registry.router?.currentRoute)),u=t.computed(()=>e.value?.registry.router),l=t.computed(()=>{if(!s.value)return"";if(s.value.meta?.actualDoctype)return s.value.meta.actualDoctype;if(s.value.params.doctype)return s.value.params.doctype;const c=s.value.params.pathMatch;return c&&c.length>0?c[0]:""}),d=t.computed(()=>{if(!s.value)return"";if(s.value.meta?.doctype)return s.value.meta.doctype;if(s.value.params.doctype)return s.value.params.doctype;const c=s.value.params.pathMatch;return c&&c.length>0?c[0]:""}),f=t.computed(()=>{if(!s.value)return"";if(s.value.params.recordId)return s.value.params.recordId;const c=s.value.params.pathMatch;return c&&c.length>1?c[1]:""}),g=t.computed(()=>f.value?.startsWith("new-")),b=t.computed(()=>{if(!s.value||s.value.name==="home"||s.value.path==="/")return"doctypes";if(s.value.name&&s.value.name!=="catch-all"){const p=s.value.name;if(p.includes("form")||s.value.params.recordId)return"record";if(p.includes("list")||s.value.params.doctype)return"records"}const c=s.value.params.pathMatch;return c&&c.length>0?c.length===1?"records":"record":"doctypes"}),D=()=>{if(!e.value||!l.value||!f.value)return[];try{const p=e.value.registry.registry[l.value];if(!p?.workflow?.states)return[];const E=g.value?"creating":"editing",C=p.workflow.states[E];return C?.on?Object.keys(C.on).map(W=>{const ne=C.on?.[W],G=typeof ne=="string"?ne:"unknown",ao=async()=>{const je=e.value?.getRecordById(l.value,f.value);if(je){const no=i.value||{};await je.triggerTransition(W,{currentState:E,targetState:G,fsmContext:no})}};return{label:`${W} (→ ${G})`,action:ao}}):[]}catch(c){return console.warn("Error getting available transitions:",c),[]}},_=t.computed(()=>{const c=[];switch(b.value){case"doctypes":c.push({type:"button",label:"Refresh",action:()=>{window.location.reload()}});break;case"records":c.push({type:"button",label:"New Record",action:()=>{F()}},{type:"button",label:"Refresh",action:()=>{window.location.reload()}});break;case"record":{const p=D();p.length>0&&c.push({type:"dropdown",label:"Actions",actions:p});break}}return c}),O=t.computed(()=>{const c=[];return b.value==="records"&&d.value?c.push({title:"Home",to:"/"},{title:T(d.value),to:`/${d.value}`}):b.value==="record"&&d.value&&c.push({title:"Home",to:"/"},{title:T(d.value),to:`/${d.value}`},{title:g.value?"New Record":"Edit Record",to:s.value?.fullPath||""}),c}),I=c=>{const p=[{title:"Go Home",description:"Navigate to the home page",action:()=>{u.value?.push("/")}},{title:"Toggle Command Palette",description:"Open/close the command palette",action:()=>r.value=!r.value}];return d.value&&(p.push({title:`View ${T(d.value)} Records`,description:`Navigate to ${d.value} list`,action:()=>{u.value?.push(`/${d.value}`)}}),p.push({title:`Create New ${T(d.value)}`,description:`Create a new ${d.value} record`,action:()=>{F()}})),o.availableDoctypes.forEach(E=>{p.push({title:`View ${T(E)}`,description:`Navigate to ${E} list`,action:()=>{u.value?.push(`/${E}`)}})}),c?p.filter(E=>E.title.toLowerCase().includes(c.toLowerCase())||E.description.toLowerCase().includes(c.toLowerCase())):p},x=c=>{c.action(),r.value=!1},T=c=>c.split("-").map(p=>p.charAt(0).toUpperCase()+p.slice(1)).join(" "),j=c=>e.value?e.value.getRecordIds(c).length:0,K=async c=>{await u.value?.push(`/${c}`)},H=async c=>{await u.value?.push(`/${d.value}/${c}`)},F=async()=>{const c=`new-${Date.now()}`;await u.value?.push(`/${d.value}/${c}`)},N=c=>{if(e.value)try{e.value.records(c)}catch{}},M=()=>{if(!o.availableDoctypes.length)return[];const c=o.availableDoctypes.map(p=>({id:p,doctype:p,display_name:T(p),record_count:j(p),actions:"View Records"}));return[{fieldname:"header",component:"div",value:`
6
6
  <div class="view-header">
7
7
  <h1>Available Doctypes</h1>
8
8
  </div>
@@ -81,5 +81,5 @@ This will fail in production.`);s=te,s._s.has(o)||(r?me(o,e,n,s):Oe(o,n,s),proce
81
81
  <div class="error-state">
82
82
  <p>Unable to load form schema for ${T(d.value||l.value)}</p>
83
83
  </div>
84
- `}]}},V=()=>{if(!e.value||!l.value)return[];const p=e.value.records(l.value)?.get("");return p&&typeof p=="object"&&!Array.isArray(p)?Object.values(p):[]},P=()=>{if(!e.value||!l.value)return[];try{const p=e.value.registry.registry[l.value];if(p?.schema)return("toArray"in p.schema?p.schema.toArray():p.schema).map(C=>({fieldname:C.fieldname,label:"label"in C&&C.label||C.fieldname,fieldtype:"fieldtype"in C&&C.fieldtype||"Data"}))}catch{}return[]},U=()=>!e.value||!l.value||g.value?{}:e.value.getRecordById(l.value,f.value)?.get("")||{},D=t.computed(()=>{switch(b.value){case"doctypes":return M();case"records":return w();case"record":return y();default:return[]}}),A=t.ref([]);t.watch(D,c=>{A.value=[...c]},{immediate:!0,deep:!0}),t.watch(A,c=>{if(!(!e.value||!l.value||!f.value||g.value))try{const p=e.value.getStore();c.forEach(E=>{if(E.fieldname&&"value"in E&&!["header","actions","loading","error"].includes(E.fieldname)){const C=`${l.value}.${f.value}.${E.fieldname}`;(p.has(C)?p.get(C):void 0)!==E.value&&p.set(C,E.value)}})}catch(p){console.warn("HST schema sync failed:",p)}},{deep:!0});const B=async()=>{if(e.value){n.value=!0;try{const c=i.value||{};if(g.value){const p=`record-${Date.now()}`,E={id:p,...c};e.value.addRecord(l.value,p,E);const C=e.value.getRecordById(l.value,p);C&&await C.triggerTransition("SAVE",{currentState:"creating",targetState:"saved",fsmContext:E}),await u.value?.replace(`/${d.value}/${p}`)}else{const p={id:f.value,...c};e.value.addRecord(l.value,f.value,p);const E=e.value.getRecordById(l.value,f.value);E&&await E.triggerTransition("SAVE",{currentState:"editing",targetState:"saved",fsmContext:p})}}catch{}finally{n.value=!1}}},S=async()=>{if(g.value)await u.value?.push(`/${d.value}`);else{if(e.value){const c=e.value.getRecordById(l.value,f.value);c&&await c.triggerTransition("CANCEL",{currentState:"editing",targetState:"cancelled"})}m()}},k=(c,p)=>{p&&p()},$=async c=>{if(!e.value)return;const p=c||f.value;if(p&&confirm("Are you sure you want to delete this record?")){const E=e.value.getRecordById(l.value,p);E&&await E.triggerTransition("DELETE",{currentState:"editing",targetState:"deleted"}),e.value.removeRecord(l.value,p),b.value==="record"&&await u.value?.push(`/${d.value}`)}},h=async c=>{const p=c.target,E=p.getAttribute("data-action");if(E)switch(E){case"create":await F();break;case"save":await B();break;case"cancel":await S();break;case"delete":await $();break}const C=p.closest("td, th");if(C){const L=C.textContent?.trim(),q=C.closest("tr");if(L==="View Records"&&q){const W=q.querySelectorAll("td");if(W.length>0){const G=W[1].textContent?.trim();G&&await K(G)}}else if(L?.includes("Edit")&&q){const W=q.querySelectorAll("td");if(W.length>0){const G=W[0].textContent?.trim();G&&await H(G)}}else if(L?.includes("Delete")&&q){const W=q.querySelectorAll("td");if(W.length>0){const G=W[0].textContent?.trim();G&&await $(G)}}}};t.watch([b,l,f],()=>{b.value==="record"&&m()},{immediate:!0}),t.watch(e,c=>{},{immediate:!0}),t.watch([b,l,e],([c,p,E])=>{c==="records"&&p&&E&&N(p)},{immediate:!0});const m=()=>{if(!(!e.value||!l.value)){a.value=!0;try{g.value||e.value.getRecordById(l.value,f.value)}catch(c){console.warn("Error loading record data:",c)}finally{a.value=!1}}},v={navigateToDoctype:K,openRecord:H,createNewRecord:F,handleSave:B,handleCancel:S,handleDelete:$};return t.provide("desktopMethods",v),t.onMounted(()=>{t.nextTick(()=>{b.value==="records"&&l.value&&e.value&&N(l.value)});const c=p=>{(p.ctrlKey||p.metaKey)&&p.key==="k"&&(p.preventDefault(),r.value=!0),p.key==="Escape"&&r.value&&(r.value=!1)};return document.addEventListener("keydown",c),()=>{document.removeEventListener("keydown",c)}}),(c,p)=>(t.openBlock(),t.createElementBlock("div",{class:"desktop",onClick:h},[t.createVNode(de,{elements:_.value,onActionClick:k},null,8,["elements"]),A.value.length>0?(t.openBlock(),t.createBlock(t.unref(Zt),{key:0,modelValue:A.value,"onUpdate:modelValue":p[0]||(p[0]=E=>A.value=E),data:i.value},null,8,["modelValue","data"])):t.unref(e)?(t.openBlock(),t.createElementBlock("div",to,[t.createElementVNode("p",null,"Loading "+t.toDisplayString(b.value)+" data...",1)])):(t.openBlock(),t.createElementBlock("div",eo,[...p[2]||(p[2]=[t.createElementVNode("p",null,"Initializing Stonecrop...",-1)])])),t.createVNode(Ee,{breadcrumbs:O.value},null,8,["breadcrumbs"]),t.createVNode(pe,{"is-open":r.value,search:I,placeholder:"Type a command or search...",onSelect:x,onClose:p[1]||(p[1]=E=>r.value=!1)},{title:t.withCtx(({result:E})=>[t.createTextVNode(t.toDisplayString(E.title),1)]),content:t.withCtx(({result:E})=>[t.createTextVNode(t.toDisplayString(E.description),1)]),_:1},8,["is-open"])]))}}),oo={install:o=>{o.component("ActionSet",de),o.component("CommandPalette",pe),o.component("Desktop",Me),o.component("SheetNav",Ee)}};J.ActionSet=de,J.CommandPalette=pe,J.Desktop=Me,J.SheetNav=Ee,J.StonecropDesktop=oo,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"})}));
84
+ `}]}},V=()=>{if(!e.value||!l.value)return[];const p=e.value.records(l.value)?.get("");return p&&typeof p=="object"&&!Array.isArray(p)?Object.values(p):[]},P=()=>{if(!e.value||!l.value)return[];try{const p=e.value.registry.registry[l.value];if(p?.schema)return("toArray"in p.schema?p.schema.toArray():p.schema).map(C=>({fieldname:C.fieldname,label:"label"in C&&C.label||C.fieldname,fieldtype:"fieldtype"in C&&C.fieldtype||"Data"}))}catch{}return[]},U=()=>!e.value||!l.value||g.value?{}:e.value.getRecordById(l.value,f.value)?.get("")||{},R=t.computed(()=>{switch(b.value){case"doctypes":return M();case"records":return w();case"record":return y();default:return[]}}),A=t.ref([]);t.watch(R,c=>{A.value=[...c]},{immediate:!0,deep:!0}),t.watch(A,c=>{if(!(!e.value||!l.value||!f.value||g.value))try{const p=e.value.getStore();c.forEach(E=>{if(E.fieldname&&"value"in E&&!["header","actions","loading","error"].includes(E.fieldname)){const C=`${l.value}.${f.value}.${E.fieldname}`;(p.has(C)?p.get(C):void 0)!==E.value&&p.set(C,E.value)}})}catch(p){console.warn("HST schema sync failed:",p)}},{deep:!0});const B=async()=>{if(e.value){n.value=!0;try{const c=i.value||{};if(g.value){const p=`record-${Date.now()}`,E={id:p,...c};e.value.addRecord(l.value,p,E);const C=e.value.getRecordById(l.value,p);C&&await C.triggerTransition("SAVE",{currentState:"creating",targetState:"saved",fsmContext:E}),await u.value?.replace(`/${d.value}/${p}`)}else{const p={id:f.value,...c};e.value.addRecord(l.value,f.value,p);const E=e.value.getRecordById(l.value,f.value);E&&await E.triggerTransition("SAVE",{currentState:"editing",targetState:"saved",fsmContext:p})}}catch{}finally{n.value=!1}}},S=async()=>{if(g.value)await u.value?.push(`/${d.value}`);else{if(e.value){const c=e.value.getRecordById(l.value,f.value);c&&await c.triggerTransition("CANCEL",{currentState:"editing",targetState:"cancelled"})}m()}},k=(c,p)=>{p&&p()},$=async c=>{if(!e.value)return;const p=c||f.value;if(p&&confirm("Are you sure you want to delete this record?")){const E=e.value.getRecordById(l.value,p);E&&await E.triggerTransition("DELETE",{currentState:"editing",targetState:"deleted"}),e.value.removeRecord(l.value,p),b.value==="record"&&await u.value?.push(`/${d.value}`)}},h=async c=>{const p=c.target,E=p.getAttribute("data-action");if(E)switch(E){case"create":await F();break;case"save":await B();break;case"cancel":await S();break;case"delete":await $();break}const C=p.closest("td, th");if(C){const L=C.textContent?.trim(),q=C.closest("tr");if(L==="View Records"&&q){const W=q.querySelectorAll("td");if(W.length>0){const G=W[1].textContent?.trim();G&&await K(G)}}else if(L?.includes("Edit")&&q){const W=q.querySelectorAll("td");if(W.length>0){const G=W[0].textContent?.trim();G&&await H(G)}}else if(L?.includes("Delete")&&q){const W=q.querySelectorAll("td");if(W.length>0){const G=W[0].textContent?.trim();G&&await $(G)}}}};t.watch([b,l,f],()=>{b.value==="record"&&m()},{immediate:!0}),t.watch(e,c=>{},{immediate:!0}),t.watch([b,l,e],([c,p,E])=>{c==="records"&&p&&E&&N(p)},{immediate:!0});const m=()=>{if(!(!e.value||!l.value)){a.value=!0;try{g.value||e.value.getRecordById(l.value,f.value)}catch(c){console.warn("Error loading record data:",c)}finally{a.value=!1}}},v={navigateToDoctype:K,openRecord:H,createNewRecord:F,handleSave:B,handleCancel:S,handleDelete:$};return t.provide("desktopMethods",v),t.onMounted(()=>{t.nextTick(()=>{b.value==="records"&&l.value&&e.value&&N(l.value)});const c=p=>{(p.ctrlKey||p.metaKey)&&p.key==="k"&&(p.preventDefault(),r.value=!0),p.key==="Escape"&&r.value&&(r.value=!1)};return document.addEventListener("keydown",c),()=>{document.removeEventListener("keydown",c)}}),(c,p)=>(t.openBlock(),t.createElementBlock("div",{class:"desktop",onClick:h},[t.createVNode(de,{elements:_.value,onActionClick:k},null,8,["elements"]),A.value.length>0?(t.openBlock(),t.createBlock(t.unref(Zt),{key:0,modelValue:A.value,"onUpdate:modelValue":p[0]||(p[0]=E=>A.value=E),data:i.value},null,8,["modelValue","data"])):t.unref(e)?(t.openBlock(),t.createElementBlock("div",to,[t.createElementVNode("p",null,"Loading "+t.toDisplayString(b.value)+" data...",1)])):(t.openBlock(),t.createElementBlock("div",eo,[...p[2]||(p[2]=[t.createElementVNode("p",null,"Initializing Stonecrop...",-1)])])),t.createVNode(Ee,{breadcrumbs:O.value},null,8,["breadcrumbs"]),t.createVNode(pe,{"is-open":r.value,search:I,placeholder:"Type a command or search...",onSelect:x,onClose:p[1]||(p[1]=E=>r.value=!1)},{title:t.withCtx(({result:E})=>[t.createTextVNode(t.toDisplayString(E.title),1)]),content:t.withCtx(({result:E})=>[t.createTextVNode(t.toDisplayString(E.description),1)]),_:1},8,["is-open"])]))}}),oo={install:o=>{o.component("ActionSet",de),o.component("CommandPalette",pe),o.component("Desktop",Me),o.component("SheetNav",Ee)}};J.ActionSet=de,J.CommandPalette=pe,J.Desktop=Me,J.SheetNav=Ee,J.StonecropDesktop=oo,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"})}));
85
85
  //# sourceMappingURL=desktop.umd.cjs.map