@stonecrop/desktop 0.10.15 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions-Bg0Mh5s7.js +137 -0
- package/dist/actions-Bg0Mh5s7.js.map +1 -0
- package/dist/desktop.css +1 -1
- package/dist/desktop.js +721 -727
- package/dist/desktop.js.map +1 -1
- package/dist/desktop.umd.cjs +85 -0
- package/dist/desktop.umd.cjs.map +1 -0
- package/dist/index-C3nXTrEd.js +1895 -0
- package/dist/index-C3nXTrEd.js.map +1 -0
- package/dist/operation-log-DB-dGNT9-C9cIr4-e.js +592 -0
- package/dist/operation-log-DB-dGNT9-C9cIr4-e.js.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/plugins/index.js +17 -0
- package/dist/src/router.js +6 -0
- package/dist/src/tsdoc-metadata.json +11 -0
- package/dist/src/types/index.js +0 -0
- package/package.json +5 -5
- package/src/components/Desktop.vue +1 -3
|
@@ -0,0 +1,85 @@
|
|
|
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),d=t.ref(!1);t.onMounted(()=>{l()});const l=()=>{n.value={}},u=()=>{s.value=!0,i.value=setTimeout(()=>{s.value&&(r.value=!0)},500)},f=()=>{s.value=!1,d.value=!1,clearTimeout(i.value),r.value=!1},v=R=>{const N=!n.value[R];l(),N&&(n.value[R]=!0)},g=(R,N)=>{a("actionClick",N,R)};return(R,N)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass([{"open-set":r.value,"hovered-and-closed":d.value},"action-set collapse"]),onMouseover:u,onMouseleave:f},[t.createElementVNode("div",Fe,[t.createElementVNode("div",{id:"chevron",onClick:N[0]||(N[0]=O=>d.value=!d.value)},[...N[1]||(N[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)])])]),N[2]||(N[2]=t.createElementVNode("div",{style:{"margin-right":"30px"}},null,-1)),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.elements,(O,x)=>(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:I=>g(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:I=>v(x)},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,(I,T)=>(t.openBlock(),t.createElementBlock("div",{key:I.label},[I.action!=null?(t.openBlock(),t.createElementBlock("button",{key:0,class:"dropdown-item",onClick:j=>g(I.action,I.label)},t.toDisplayString(I.label),9,ze)):I.link!=null?(t.openBlock(),t.createElementBlock("a",{key:1,href:I.link},[t.createElementVNode("button",Ge,t.toDisplayString(I.label),1)],8,Je)):t.createCommentVNode("",!0)]))),128))])],512),[[t.vShow,n.value[x]]])])):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 d=()=>{a("close")},l=f=>{switch(f.key){case"Escape":d();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&&u(s.value[r.value]);break}},u=f=>{a("select",f),d()};return(f,v)=>(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:d},[t.createElementVNode("div",{class:"command-palette",onClick:v[1]||(v[1]=t.withModifiers(()=>{},["stop"]))},[t.createElementVNode("div",Ze,[t.withDirectives(t.createElementVNode("input",{ref:"input","onUpdate:modelValue":v[0]||(v[0]=g=>n.value=g),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,(g,R)=>(t.openBlock(),t.createElementBlock("div",{key:R,class:t.normalizeClass(["command-palette-result",{selected:R===r.value}]),onClick:N=>u(g),onMouseover:N=>r.value=R},[t.createElementVNode("div",et,[t.renderSlot(f.$slots,"title",{result:g})]),t.createElementVNode("div",tt,[t.renderSlot(f.$slots,"content",{result:g})])],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,d=a.state.value[o];let l;function u(){!d&&(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((v,g)=>(process.env.NODE_ENV!=="production"&&g in f&&console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${g}" in store "${o}".`),v[g]=t.markRaw(t.computed(()=>{re(a);const R=a._s.get(o);return s[g].call(R,R)})),v),{}))}return l=me(o,u,e,a,n,!0),l}function me(o,e,a={},n,r,i){let s;const d=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=b=>{u?R=b:u==!1&&!$._hotUpdating&&(Array.isArray(R)?R.push(b):console.error("🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug."))});let u,f,v=new Set,g=new Set,R;const N=n.state.value[o];!i&&!N&&(process.env.NODE_ENV==="production"||!r)&&(n.state.value[o]={});const O=t.ref({});let x;function I(b){let y;u=f=!1,process.env.NODE_ENV!=="production"&&(R=[]),typeof b=="function"?(b(n.state.value[o]),y={type:oe.patchFunction,storeId:o,events:R}):(he(n.state.value[o],b),y={type:oe.patchObject,payload:b,storeId:o,events:R});const V=x=Symbol();t.nextTick().then(()=>{x===V&&(u=!0)}),f=!0,X(v,y,n.state.value[o])}const T=i?function(){const{state:b}=a,y=b?b():{};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(),v.clear(),g.clear(),n._s.delete(o)}const K=(b,y="")=>{if(Re in b)return b[fe]=y,b;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(g,{args:P,name:V[fe],store:$,after:A,onError:B});let S;try{S=b.apply(this&&this.$id===o?this:$,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,g),$patch:I,$reset:T,$subscribe(b,y={}){const V=_e(v,b,y.detached,()=>P()),P=s.run(()=>t.watch(()=>n.state.value[o],U=>{(y.flush==="sync"?f:u)&&b({storeId:o,type:oe.direct,events:R},U)},z({},l,y)));return V},$dispose:j},$=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,$);const M=(n._a&&n._a.runWithContext||nt)(()=>n._e.run(()=>(s=t.effectScope()).run(()=>e({action:K}))));for(const b in M){const y=M[b];if(t.isRef(y)&&!De(y)||t.isReactive(y))process.env.NODE_ENV!=="production"&&r?O.value[b]=t.toRef(M,b):i||(N&&st(y)&&(t.isRef(y)?y.value=N[b]:he(y,N[b])),n.state.value[o][b]=y),process.env.NODE_ENV!=="production"&&H.state.push(b);else if(typeof y=="function"){const V=process.env.NODE_ENV!=="production"&&r?y:K(y,b);M[b]=V,process.env.NODE_ENV!=="production"&&(H.actions[b]=y),d.actions[b]=y}else process.env.NODE_ENV!=="production"&&De(y)&&(H.getters[b]=i?a.getters[b]:y,ee&&(M._getters||(M._getters=t.markRaw([]))).push(b))}if(z($,M),z(t.toRaw($),M),Object.defineProperty($,"$state",{get:()=>process.env.NODE_ENV!=="production"&&r?O.value:n.state.value[o],set:b=>{if(process.env.NODE_ENV!=="production"&&r)throw new Error("cannot set hotState");I(y=>{z(y,b)})}}),process.env.NODE_ENV!=="production"&&($._hotUpdate=t.markRaw(b=>{$._hotUpdating=!0,b._hmrPayload.state.forEach(y=>{if(y in $.$state){const V=b.$state[y],P=$.$state[y];typeof V=="object"&&Q(V)&&Q(P)?Ne(V,P):b.$state[y]=P}$[y]=t.toRef(b.$state,y)}),Object.keys($.$state).forEach(y=>{y in b.$state||delete $[y]}),u=!1,f=!1,n.state.value[o]=t.toRef(b._hmrPayload,"hotState"),f=!0,t.nextTick().then(()=>{u=!0});for(const y in b._hmrPayload.actions){const V=b[y];$[y]=K(V,y)}for(const y in b._hmrPayload.getters){const V=b._hmrPayload.getters[y],P=i?t.computed(()=>(re(n),V.call($,$))):V;$[y]=P}Object.keys($._hmrPayload.getters).forEach(y=>{y in b._hmrPayload.getters||delete $[y]}),Object.keys($._hmrPayload.actions).forEach(y=>{y in b._hmrPayload.actions||delete $[y]}),$._hmrPayload=b._hmrPayload,$._getters=b._getters,$._hotUpdating=!1})),process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&ee){const b={writable:!0,configurable:!0,enumerable:!1};["_p","_hmrPayload","_getters","_customProperties"].forEach(y=>{Object.defineProperty($,y,z({value:$[y]},b))})}return n._p.forEach(b=>{if(process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="test"&&ee){const y=s.run(()=>b({store:$,app:n._a,pinia:n,options:d}));Object.keys(y||{}).forEach(V=>$._customProperties.add(V)),z($,y)}else z($,s.run(()=>b({store:$,app:n._a,pinia:n,options:d})))}),process.env.NODE_ENV!=="production"&&$.$state&&typeof $.$state=="object"&&typeof $.$state.constructor=="function"&&!$.$state.constructor.toString().includes("[native code]")&&console.warn(`[🍍]: The "state" must be a plain object. It cannot be
|
|
2
|
+
state: () => new MyClass()
|
|
3
|
+
Found in store "${$.$id}".`),N&&i&&a.hydrate&&a.hydrate($.$state,N),u=!0,f=!0,$}function it(o,e,a){let n;const r=typeof e=="function";n=r?a:e;function i(s,d){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
|
+
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 u=s._s.get(o);if(process.env.NODE_ENV!=="production"&&d){const f="__hot:"+o,v=r?me(f,e,n,s,!0):Oe(f,z({},n),s,!0);d._hotUpdate(v),delete s.state.value[f],s._s.delete(f)}if(process.env.NODE_ENV!=="production"&&ee){const f=t.getCurrentInstance();if(f&&f.proxy&&!d){const v=f.proxy,g="_pStores"in v?v._pStores:v._pStores={};g[o]=u}}return u}return i.$id=o,i}function lt(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=(...d)=>{n.value&&o(...d)};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:d,resume:l,isActive:u}=mt(n,{initialState:r});return{stop:yt(o,e,{...i,eventFilter:s}),pause:d,resume:l,isActive:u}}function wt(o,e=!0,a){gt()?t.onMounted(o,a):e?o():t.nextTick(o)}function bt(o,e,a){return t.watch(o,e,{...a,immediate:!0})}const se=ct?window:void 0;function St(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 bt(()=>{var n,r;return[(n=(r=a.value)===null||r===void 0?void 0:r.map(i=>St(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],d,l)=>{if(!n?.length||!r?.length||!i?.length)return;const u=dt(s)?{...s}:s,f=n.flatMap(v=>r.flatMap(g=>i.map(R=>e(v,g,R,u))));l(()=>{f.forEach(v=>v())})},{flush:"post"})}const ie=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},le="__vueuse_ssr_handlers__",Et=kt();function kt(){return le in ie||(ie[le]=ie[le]||{}),ie[le]}function Nt(o,e){return Et[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 _t={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:d=!0,writeDefaults:l=!0,mergeDefaults:u=!1,shallow:f,window:v=se,eventFilter:g,onError:R=D=>{console.error(D)},initOnMounted:N}=n,O=(f?t.shallowRef:t.ref)(e),x=t.computed(()=>t.toValue(o));if(!a)try{a=Nt("getDefaultStorage",()=>se?.localStorage)()}catch(D){R(D)}if(!a)return O;const I=t.toValue(e),T=$t(I),j=(r=n.serializer)!==null&&r!==void 0?r:_t[T],{pause:K,resume:H}=vt(O,D=>y(D),{flush:i,deep:s,eventFilter:g});t.watch(x,()=>P(),{flush:i});let F=!1;const $=D=>{N&&!F||P(D)},M=D=>{N&&!F||U(D)};v&&d&&(a instanceof Storage?Ve(v,"storage",$,{passive:!0}):Ve(v,Te,M)),N?wt(()=>{F=!0,P()}):P();function b(D,A){if(v){const B={key:x.value,oldValue:D,newValue:A,storageArea:a};v.dispatchEvent(a instanceof Storage?new StorageEvent("storage",B):new CustomEvent(Te,{detail:B}))}}function y(D){try{const A=a.getItem(x.value);if(D==null)b(A,null),a.removeItem(x.value);else{const B=j.write(D);A!==B&&(a.setItem(x.value,B),b(A,B))}}catch(A){R(A)}}function V(D){const A=D?D.newValue:a.getItem(x.value);if(A==null)return l&&I!=null&&a.setItem(x.value,j.write(I)),I;if(!D&&u){const B=j.read(A);return typeof u=="function"?u(B,I):T==="object"&&!Array.isArray(B)?{...I,...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=I;return}if(!(D&&D.key!==x.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 Dt(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 Ot(o){const e={type:o.type,clientId:o.clientId,timestamp:new Date(o.timestamp)};return o.operation&&(e.operation={...o.operation,timestamp:new Date(o.operation.timestamp)}),o.operations&&(e.operations=o.operations.map(a=>({...a,timestamp:new Date(a.timestamp)}))),e}const Ae=it("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),d=t.computed(()=>a.value<0?!1:e.value[a.value]?.reversible??!1),l=t.computed(()=>a.value<e.value.length-1),u=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),v=t.computed(()=>({canUndo:d.value,canRedo:l.value,undoCount:u.value,redoCount:f.value,currentIndex:a.value}));function g(h){o.value={...o.value,...h},o.value.enablePersistence&&(S(),_()),o.value.enableCrossTabSync&&V()}function R(h,m="user"){const w={...h,id:ye(),timestamp:new Date,source:m,userId:o.value.userId};if(o.value.operationFilter&&!o.value.operationFilter(w))return w.id;if(r.value)return i.value.push(w),w.id;if(a.value<e.value.length-1&&(e.value=e.value.slice(0,a.value+1)),e.value.push(w),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(w),w.id}function N(){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,w=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:w,irreversibleReason:w?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 x(){r.value=!1,i.value=[],s.value=null}function I(h){if(!d.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 w=m.childOperationIds.length-1;w>=0;w--){const c=m.childOperationIds[w],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(w){return typeof console<"u"&&console.error("Undo failed:",w),!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 w of m.childOperationIds){const c=e.value.find(p=>p.id===w);c&&K(c,h)}else K(m,h);return a.value++,o.value.enableCrossTabSync&&A(m),!0}catch(w){return typeof console<"u"&&console.error("Redo failed:",w),!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(w=>w.reversible).length,m=e.value.map(w=>w.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(w=>w.getTime()))):void 0,newestOperation:m.length>0?new Date(Math.max(...m.map(w=>w.getTime()))):void 0}}function F(){e.value=[],a.value=-1}function $(h,m){return e.value.filter(w=>w.doctype===h&&(m===void 0||w.recordId===m))}function M(h,m){const w=e.value.find(c=>c.id===h);w&&(w.reversible=!1,w.irreversibleReason=m)}function b(h,m,w,c="success",p){const E={type:"action",path:w&&w.length>0?`${h}.${w[0]}`:h,fieldname:"",beforeValue:null,afterValue:null,doctype:h,recordId:w&&w.length>0?w[0]:void 0,reversible:!1,actionName:m,actionRecordIds:w,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 w=Ot(m);w.clientId!==n.value&&(w.type==="operation"&&w.operation?(e.value.push({...w.operation,source:"sync"}),a.value=e.value.length-1):w.type==="operation"&&w.operations&&(e.value.push(...w.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 w={type:"operation",operations:[...h,m],clientId:n.value,timestamp:new Date};y.postMessage(ce(w))}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=Dt("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:v,canUndo:d,canRedo:l,undoCount:u,redoCount:f,configure:g,addOperation:R,startBatch:N,commitBatch:O,cancelBatch:x,undo:I,redo:T,clear:F,getOperationsFor:$,getSnapshot:H,markIrreversible:M,logAction:b}});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(),d=[];let l=!1,u=!1,f;const v=this.getFieldRollback(n,r),g=a.enableRollback??v??this.options.enableRollback;g&&e.store&&(f=this.captureSnapshot(e));for(const O of i)try{const x=await this.executeAction(O,e,a.timeout);if(d.push(x),!x.success){l=!0;break}}catch(x){const I={success:!1,error:x instanceof Error?x:new Error(String(x)),executionTime:0,action:O};d.push(I),l=!0;break}if(g&&l&&f&&e.store)try{this.restoreSnapshot(e,f),u=!0}catch(O){console.error("[FieldTriggers] Rollback failed:",O)}const R=performance.now()-s,N=d.filter(O=>!O.success);if(N.length>0&&this.options.errorHandler)for(const O of N)try{this.options.errorHandler(O.error,e,O.action)}catch(x){console.error("[FieldTriggers] Error in global error handler:",x)}return{path:e.path,actionResults:d,totalExecutionTime:R,allSucceeded:d.every(O=>O.success),stoppedOnError:l,rolledBack:u,snapshot:this.options.debug&&g?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 u=await this.executeTransitionAction(l,e,a.timeout);if(s.push(u),!u.success)break}catch(u){const f={success:!1,error:u instanceof Error?u:new Error(String(u)),executionTime:0,action:l,transition:r};s.push(f);break}const d=s.filter(l=>!l.success);if(d.length>0&&this.options.errorHandler)for(const l of d)try{this.options.errorHandler(l.error,e,l.action)}catch(u){console.error("[FieldTriggers] Error in global error handler:",u)}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 d=this.globalActions.get(e);d&&(s=d)}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 d=performance.now()-r;return{success:!1,error:s instanceof Error?s:new Error(String(s)),executionTime:d,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],d=r[i];if(s!=="*"&&s!==d)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 d=performance.now()-r;return{success:!1,error:s instanceof Error?s:new Error(String(s)),executionTime:d,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(d=>{clearTimeout(s),r(d)}).catch(d=>{clearTimeout(s),i(d)})})}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 xe(o){return new ae(o)}function Ie(){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,d){if(d in s)return s[d];const l=String(d);return s.getNode(l)},set(s,d,l){const u=String(d);return s.set(u,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=Ie();if(s&&typeof s.addOperation=="function"){const d=r.split("."),l=this.doctype==="StonecropStore"&&d.length>=1?d[0]:this.doctype,u=d.length>=2?d[1]:void 0,f=d.slice(2).join(".")||d[d.length-1],v=a===void 0&&i!==void 0?"delete":"set";s.addOperation({type:v,path:r,fieldname:f,beforeValue:i,afterValue:a,doctype:l,recordId:u,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=xe(),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 d={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=Ie();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(d)}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=xe(),s=r.slice(2).join(".")||r[r.length-1];let d=this.doctype;this.doctype==="StonecropStore"&&r.length>=1&&(d=r[0]);let l;r.length>=2&&(l=r[1]);const u={path:e,fieldname:s,beforeValue:a,afterValue:n,operation:"set",doctype:d,recordId:l,timestamp:new Date,store:this.rootNode||void 0};await i.executeFieldTriggers(u)}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 u=l.constructor.name;s=typeof u=="string"?u:void 0}}catch{s=void 0}const d=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&&d)}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 Ct(o,e,a){return new ue(o,e,"",null,a)}class Vt{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=Ct(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(u=>typeof u=="string"):void 0,s=this.getOperationLogStore();let d="success",l;try{r&&r.length>0&&r.forEach(u=>{try{new Function("args",u)(n)}catch(f){throw d="failure",l=f instanceof Error?f.message:"Unknown error",f}})}catch{}finally{s.logAction(e.doctype,a,i,d,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 Tt(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(),d=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 u=t.ref([]),f=t.ref(-1),v=t.computed(()=>n.value?.getOperationLogStore().canUndo??!1),g=t.computed(()=>n.value?.getOperationLogStore().canRedo??!1),R=t.computed(()=>n.value?.getOperationLogStore().undoCount??0),N=t.computed(()=>n.value?.getOperationLogStore().redoCount??0),O=t.computed(()=>n.value?.getOperationLogStore().undoRedoState??{canUndo:!1,canRedo:!1,undoCount:0,redoCount:0,currentIndex:-1}),x=S=>n.value?.getOperationLogStore().undo(S)??!1,I=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.value?.getOperationLogStore().getSnapshot()??{operations:[],currentIndex:-1,totalOperations:0,reversibleOperations:0,irreversibleOperations:0},M=(S,k)=>{n.value?.getOperationLogStore().markIrreversible(S,k)},b=(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 Vt(e);try{const S=n.value.getOperationLogStore(),k=lt(S);u.value=k.operations.value,f.value=k.currentIndex.value,t.watch(()=>k.operations.value,_=>{u.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,d.value=_,r.value=n.value.getStore(),e){const w=m.schema?Array.isArray(m.schema)?m.schema:Array.from(m.schema):[];l.value=e.resolveSchema(w)}if(_&&_!=="new"){const w=n.value.getRecordById(m,_);if(w)i.value=w.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||d.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 w=_[0],c=_[1];if(r.value.has(`${w}.${c}`)||n.value.addRecord(k,c,{...i.value}),_.length>3){const p=`${w}.${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:At(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):[],w=(e?e.resolveSchema(m):m).filter(c=>"fieldtype"in c&&c.fieldtype==="Doctype"&&"schema"in c&&Array.isArray(c.schema));for(const c of w){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:u,currentIndex:f,undoRedoState:O,canUndo:v,canRedo:g,undoCount:R,redoCount:N,undo:x,redo:I,startBatch:T,commitBatch:j,cancelBatch:K,clear:H,getOperationsFor:F,getSnapshot:$,markIrreversible:M,logAction:b,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 d=`${i}.${s}`;try{n.set(d,r[s])}catch{}})},{deep:!0})}function At(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,d=`${e}.${s.fieldname}`,l=Be(s.schema,d,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 It=()=>{};function Pt(...o){if(o.length!==1)return t.toRef(...o);const e=o[0];return typeof e=="function"?t.readonly(t.customRef(()=>({get:e,set:It}))):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 Bt(o,e=!1){const a=t.shallowRef(e);let n="";t.watch(Pt(o),s=>{const d=ve(t.toValue(s));if(d){const l=d;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 Mt(){let o=!1;const e=t.shallowRef(!1);return(a,n)=>{if(e.value=n.value,o)return;o=!0;const r=Bt(a,n.value);t.watch(e,i=>r.value=i)}}Mt();const jt=(o,e)=>{const a=o.__vccOpts||o;for(const[n,r]of e)a[n]=r;return a};function Ft(o,e){return t.getCurrentScope()?(t.onScopeDispose(o,e),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Lt=()=>{};function Ht(...o){if(o.length!==1)return t.toRef(...o);const e=o[0];return typeof e=="function"?t.readonly(t.customRef(()=>({get:e,set:Lt}))):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 Ut(o,e=!1){const a=t.shallowRef(e);let n="";t.watch(Ht(o),s=>{const d=be(t.toValue(s));if(d){const l=d;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 Ft(i),t.computed({get(){return a.value},set(s){s?r():i()}})}function Wt(){let o=!1;const e=t.shallowRef(!1);return(a,n)=>{if(e.value=n.value,o)return;o=!0;const r=Ut(a,n.value);t.watch(e,i=>r.value=i)}}Wt(),typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Kt={class:"aform"},zt={key:0,class:"aform-nested-section"},Jt={key:0,class:"aform-nested-label"},Gt=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.watch(()=>n.value,u=>{!o.schema||!u||o.schema.forEach(f=>{"schema"in f&&Array.isArray(f.schema)&&f.schema.length>0&&(r.value[f.fieldname]=u[f.fieldname]??{})})},{immediate:!0});const i=(u,f)=>{r.value[u]=f,n.value&&(n.value[u]=f,a("update:data",n.value))};t.watchEffect(()=>{n.value&&o.schema&&o.schema.forEach(u=>{u.fieldname&&n.value[u.fieldname]!==void 0&&(u.value=n.value[u.fieldname])})});const s=u=>{const f={};for(const[v,g]of Object.entries(u))["component","fieldtype"].includes(v)||(f[v]=g),v==="rows"&&(!g||Array.isArray(g)&&g.length===0)&&(f.rows=n.value[u.fieldname]||[]);return f},d=t.ref([]);t.watchEffect(()=>{o.schema&&d.value.length!==o.schema.length&&(d.value=o.schema.map((u,f)=>t.computed({get(){return u.value},set:v=>{const g=o.schema[f].fieldname;o.schema[f].value=v,g&&n.value&&(n.value[g]=v,a("update:data",n.value)),a("update:schema",o.schema)}})))});const l=t.computed(()=>d.value);return(u,f)=>{const v=t.resolveComponent("AForm",!0);return t.openBlock(),t.createElementBlock("form",Kt,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.schema,(g,R)=>(t.openBlock(),t.createElementBlock(t.Fragment,{key:R},["schema"in g&&Array.isArray(g.schema)&&g.schema.length>0?(t.openBlock(),t.createElementBlock("div",zt,[g.label?(t.openBlock(),t.createElementBlock("h4",Jt,t.toDisplayString(g.label),1)):t.createCommentVNode("",!0),t.createVNode(v,{data:r.value[g.fieldname],"onUpdate:data":N=>i(g.fieldname,N),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:l.value[R].value,"onUpdate:modelValue":N=>l.value[R].value=N,schema:g,data:n.value[g.fieldname],"read-only":o.readOnly},{ref_for:!0},s(g)),null,16,["modelValue","onUpdate:modelValue","schema","data","read-only"]))],64))),128))])}}}),qt=jt(Gt,[["__scopeId","data-v-a3cba83d"]]),Zt={class:"tabs"},Qt={tabindex:"0"},Xt={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},d=async()=>{a.value=!a.value,await t.nextTick(()=>{r.value?.focus()})},l=v=>{v.preventDefault(),v.stopPropagation()},u=async v=>{v.preventDefault(),v.stopPropagation(),await d()},f=()=>{};return(v,g)=>{const R=t.resolveComponent("router-link");return t.openBlock(),t.createElementBlock("footer",null,[t.createElementVNode("ul",Zt,[t.createElementVNode("li",{class:"hidebreadcrumbs",onClick:s,onKeydown:t.withKeys(s,["enter"])},[t.createElementVNode("a",Qt,[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(()=>[...g[5]||(g[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",Xt,[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:d,onKeydown:t.withKeys(d,["enter"])},[...g[6]||(g[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":g[0]||(g[0]=N=>n.value=N),type:"text",placeholder:"Search...",onClick:g[1]||(g[1]=t.withModifiers(()=>{},["stop"])),onInput:g[2]||(g[2]=N=>l(N)),onBlur:g[3]||(g[3]=N=>u(N)),onKeydown:[g[4]||(g[4]=t.withKeys(N=>u(N),["enter"])),t.withKeys(d,["escape"])]},null,544),[[t.vShow,a.value],[t.vModelText,n.value]])])],6),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.breadcrumbs,N=>(t.openBlock(),t.createElementBlock("li",{key:N.title,style:t.normalizeStyle({display:e.value?"block":"none"})},[t.createVNode(R,{tabindex:"0",to:N.to},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(N.title),1)]),_:2},1032,["to"])],4))),128))])])}}}),[["__scopeId","data-v-eb5bcbb6"]]),Yt={key:1,class:"loading"},eo={key:2,class:"loading"},Me=t.defineComponent({__name:"Desktop",props:{availableDoctypes:{default:()=>[]}},setup(o){const{stonecrop:e}=Tt(),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)),d=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]:""}),u=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]:""}),v=t.computed(()=>f.value?.startsWith("new-")),g=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=v.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",oo=async()=>{const je=e.value?.getRecordById(l.value,f.value);if(je){const ao=i.value||{};await je.triggerTransition(W,{currentState:E,targetState:G,fsmContext:ao})}};return{label:`${W} (→ ${G})`,action:oo}}):[]}catch(c){return console.warn("Error getting available transitions:",c),[]}},N=t.computed(()=>{const c=[];switch(g.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 g.value==="records"&&u.value?c.push({title:"Home",to:"/"},{title:T(u.value),to:`/${u.value}`}):g.value==="record"&&u.value&&c.push({title:"Home",to:"/"},{title:T(u.value),to:`/${u.value}`},{title:v.value?"New Record":"Edit Record",to:s.value?.fullPath||""}),c}),x=c=>{const p=[{title:"Go Home",description:"Navigate to the home page",action:()=>{d.value?.push("/")}},{title:"Toggle Command Palette",description:"Open/close the command palette",action:()=>r.value=!r.value}];return u.value&&(p.push({title:`View ${T(u.value)} Records`,description:`Navigate to ${u.value} list`,action:()=>{d.value?.push(`/${u.value}`)}}),p.push({title:`Create New ${T(u.value)}`,description:`Create a new ${u.value} record`,action:()=>{F()}})),o.availableDoctypes.forEach(E=>{p.push({title:`View ${T(E)}`,description:`Navigate to ${E} list`,action:()=>{d.value?.push(`/${E}`)}})}),c?p.filter(E=>E.title.toLowerCase().includes(c.toLowerCase())||E.description.toLowerCase().includes(c.toLowerCase())):p},I=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 d.value?.push(`/${c}`)},H=async c=>{await d.value?.push(`/${u.value}/${c}`)},F=async()=>{const c=`new-${Date.now()}`;await d.value?.push(`/${u.value}/${c}`)},$=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
|
+
<div class="view-header">
|
|
7
|
+
<h1>Available Doctypes</h1>
|
|
8
|
+
</div>
|
|
9
|
+
`},{fieldname:"doctypes_table",component:"ATable",columns:[{label:"Doctype",name:"doctype",fieldtype:"Data",align:"left",edit:!1,width:"20ch"},{label:"Name",name:"display_name",fieldtype:"Data",align:"left",edit:!1,width:"30ch"},{label:"Records",name:"record_count",fieldtype:"Int",align:"center",edit:!1,width:"15ch"},{label:"Actions",name:"actions",fieldtype:"Data",align:"center",edit:!1,width:"20ch"}],config:{view:"list",fullWidth:!0},rows:c}]},b=()=>{if(!l.value)return[];if(!e.value)return[];const c=V(),p=P();if(p.length===0)return[{fieldname:"header",component:"div",value:`
|
|
10
|
+
<div class="view-header">
|
|
11
|
+
<nav class="breadcrumbs">
|
|
12
|
+
<a href="/">Home</a>
|
|
13
|
+
<span class="separator">/</span>
|
|
14
|
+
<span class="current">${T(u.value||l.value)}</span>
|
|
15
|
+
</nav>
|
|
16
|
+
<h1>${T(u.value||l.value)} Records</h1>
|
|
17
|
+
</div>
|
|
18
|
+
`},{fieldname:"loading",component:"div",value:`
|
|
19
|
+
<div class="loading-state">
|
|
20
|
+
<p>Loading ${T(u.value||l.value)} schema...</p>
|
|
21
|
+
</div>
|
|
22
|
+
`}];const E=c.map(C=>({...C,id:C.id||"",actions:"Edit | Delete"}));return[{fieldname:"header",component:"div",value:`
|
|
23
|
+
<div class="view-header">
|
|
24
|
+
<nav class="breadcrumbs">
|
|
25
|
+
<a href="/">Home</a>
|
|
26
|
+
<span class="separator">/</span>
|
|
27
|
+
<span class="current">${T(u.value||l.value)}</span>
|
|
28
|
+
</nav>
|
|
29
|
+
<h1>${T(u.value||l.value)} Records</h1>
|
|
30
|
+
</div>
|
|
31
|
+
`},{fieldname:"actions",component:"div",value:`
|
|
32
|
+
<div class="view-actions">
|
|
33
|
+
<button class="btn-primary" data-action="create">
|
|
34
|
+
New ${T(u.value||l.value)}
|
|
35
|
+
</button>
|
|
36
|
+
</div>
|
|
37
|
+
`},...c.length===0?[{fieldname:"empty_state",component:"div",value:`
|
|
38
|
+
<div class="empty-state">
|
|
39
|
+
<p>No ${u.value||l.value} records found.</p>
|
|
40
|
+
<button class="btn-primary" data-action="create">
|
|
41
|
+
Create First Record
|
|
42
|
+
</button>
|
|
43
|
+
</div>
|
|
44
|
+
`}]:[{fieldname:"records_table",component:"ATable",columns:[...p.map(C=>({label:C.label,name:C.fieldname,fieldtype:C.fieldtype,align:"left",edit:!1,width:"20ch"})),{label:"Actions",name:"actions",fieldtype:"Data",align:"center",edit:!1,width:"20ch"}],config:{view:"list",fullWidth:!0},rows:E}]]},y=()=>{if(!l.value)return[];if(!e.value)return[];try{const p=e.value?.registry?.registry[l.value];if(!p?.schema)return[{fieldname:"header",component:"div",value:`
|
|
45
|
+
<div class="view-header">
|
|
46
|
+
<nav class="breadcrumbs">
|
|
47
|
+
<a href="/">Home</a>
|
|
48
|
+
<span class="separator">/</span>
|
|
49
|
+
<a href="/${u.value||l.value}">${T(u.value||l.value)}</a>
|
|
50
|
+
<span class="separator">/</span>
|
|
51
|
+
<span class="current">${v.value?"New Record":f.value}</span>
|
|
52
|
+
</nav>
|
|
53
|
+
<h1>${v.value?`New ${T(u.value||l.value)}`:`Edit ${T(u.value||l.value)}`}</h1>
|
|
54
|
+
</div>
|
|
55
|
+
`},{fieldname:"loading",component:"div",value:`
|
|
56
|
+
<div class="loading-state">
|
|
57
|
+
<p>Loading ${T(u.value||l.value)} form...</p>
|
|
58
|
+
</div>
|
|
59
|
+
`}];const E="toArray"in p.schema?p.schema.toArray():p.schema,C=U();return[{fieldname:"header",component:"div",value:`
|
|
60
|
+
<div class="view-header">
|
|
61
|
+
<nav class="breadcrumbs">
|
|
62
|
+
<a href="/">Home</a>
|
|
63
|
+
<span class="separator">/</span>
|
|
64
|
+
<a href="/${u.value||l.value}">${T(u.value||l.value)}</a>
|
|
65
|
+
<span class="separator">/</span>
|
|
66
|
+
<span class="current">${v.value?"New Record":f.value}</span>
|
|
67
|
+
</nav>
|
|
68
|
+
<h1>
|
|
69
|
+
${v.value?`New ${T(u.value||l.value)}`:`Edit ${T(u.value||l.value)}`}
|
|
70
|
+
</h1>
|
|
71
|
+
</div>
|
|
72
|
+
`},{fieldname:"actions",component:"div",value:`
|
|
73
|
+
<div class="view-actions">
|
|
74
|
+
<button class="btn-primary" data-action="save" ${n.value?"disabled":""}>
|
|
75
|
+
${n.value?"Saving...":"Save"}
|
|
76
|
+
</button>
|
|
77
|
+
<button class="btn-secondary" data-action="cancel">Cancel</button>
|
|
78
|
+
${v.value?"":'<button class="btn-danger" data-action="delete">Delete</button>'}
|
|
79
|
+
</div>
|
|
80
|
+
`},...E.map(L=>({...L,value:C[L.fieldname]||""}))]}catch{return[{fieldname:"error",component:"div",value:`
|
|
81
|
+
<div class="error-state">
|
|
82
|
+
<p>Unable to load form schema for ${T(u.value||l.value)}</p>
|
|
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||v.value?{}:e.value.getRecordById(l.value,f.value)?.get("")||{},D=t.computed(()=>{switch(g.value){case"doctypes":return M();case"records":return b();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||v.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(v.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 d.value?.replace(`/${u.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(v.value)await d.value?.push(`/${u.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),g.value==="record"&&await d.value?.push(`/${u.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([g,l,f],()=>{g.value==="record"&&m()},{immediate:!0}),t.watch(e,c=>{},{immediate:!0}),t.watch([g,l,e],([c,p,E])=>{c==="records"&&p&&E&&$(p)},{immediate:!0});const m=()=>{if(!(!e.value||!l.value)){a.value=!0;try{v.value||e.value.getRecordById(l.value,f.value)}catch(c){console.warn("Error loading record data:",c)}finally{a.value=!1}}},w={navigateToDoctype:K,openRecord:H,createNewRecord:F,handleSave:B,handleCancel:S,handleDelete:_};return t.provide("desktopMethods",w),t.onMounted(()=>{t.nextTick(()=>{g.value==="records"&&l.value&&e.value&&$(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:N.value,onActionClick:k},null,8,["elements"]),A.value.length>0?(t.openBlock(),t.createBlock(t.unref(qt),{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",eo,[t.createElementVNode("p",null,"Loading "+t.toDisplayString(g.value)+" data...",1)])):(t.openBlock(),t.createElementBlock("div",Yt,[...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:x,placeholder:"Type a command or search...",onSelect:I,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"])]))}}),to={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=to,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"})}));
|
|
85
|
+
//# sourceMappingURL=desktop.umd.cjs.map
|