@wcstack/state 3.5.1 → 3.5.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.
- package/README.ja.md +3 -3
- package/README.md +3 -3
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/split/chunks/binder.js +1 -1
- package/dist/split/chunks/binder.js.map +1 -1
- package/dist/split/chunks/checkDependency.js +1 -1
- package/dist/split/chunks/featureBridge.js +1 -1
- package/dist/split/chunks/getAllPropertyDescriptors.js +1 -1
- package/dist/split/chunks/lifecycleHooks.js +1 -1
- package/dist/split/chunks/registerComponents.js +1 -1
- package/dist/split/chunks/setAll.js +1 -1
- package/dist/split/chunks/version.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/recursion.js +1 -1
- package/dist/split/features/scopes.js +1 -1
- package/dist/split/features/scopes.js.map +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/dist/split/features/ssr.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as t}from"./pathDiagnostics.js";import{m as n,
|
|
1
|
+
import{g as t}from"./pathDiagnostics.js";import{m as n,aY as a}from"./binder.js";const s=new Map;class l{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(n){const a=n.split("."),s=a.slice();let l=0,e=0,i=0,o="none";const d=[];for(let t=0;t<a.length;t++){const n=a[t];if("*"===n)s[t]="*",d.push(null),l++,i++;else{const a=Number(n);Number.isNaN(a)||(s[t]="*",d.push(a),e++,i++)}}const r=s.join("."),c=t(r);(l>0||e>0)&&(o=l===i?"context":e===i?"all":"partial"),this.path=n,this.segments=a,this.wildcardCount=i,this.wildcardType=o,this.wildcardIndexes=d,this.pathInfo=c}}function e(t){let n;return s.get(t)??(s.set(t,n=new l(t)),n)}function i(t,a){if(0===t.addressStackLength)return null;const s=t.lastAddressStack;if(null===s)return null;const l=s.pathInfo.indexByWildcardPath[a];return void 0===l||null===s.listIndex?null:n(s.listIndex,l,s.pathInfo.wildcardCount)}function o(t,s){if(!t.untracking&&t.addressStackLength>0){const l=t.lastAddressStack,e=l?.pathInfo??null,i=t.stateElement;if(null!==e&&i.getterPaths.has(e.path)&&e.path!==s.pathInfo.path&&(i.addDynamicDependency(s.pathInfo.path,e.path),s.pathInfo.wildcardCount>0&&e.wildcardCount>0)){const t=a(s.pathInfo,e);if(t>0){let a=!1;const o=s.listIndex??null,d=l.listIndex??null;for(let l=0;l<t;l++){if((null!==o?n(o,l,s.pathInfo.wildcardCount):null)!==(null!==d?n(d,l,e.wildcardCount):null)){a=!0;break}}if(a)for(let n=0;n<t;n++)i.addCrossRowListPath?.(s.pathInfo.wildcardParentPaths[n])}}}}export{i as a,o as c,e as g};
|
|
2
2
|
//# sourceMappingURL=checkDependency.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aO as n}from"./binder.js";import{r as t}from"./errorGuidance.js";let r=null;function e(n){r=n}function a(e){return r??t(n("watch",`"$watch" in <wcs-state mount="${e}">`))}let o=null;function s(n){o=n}const u=Object.freeze([]);function c(n){return null===o?u:o(n)}export{s as a,c as g,a as r,e as s};
|
|
2
2
|
//# sourceMappingURL=featureBridge.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e}from"./errorGuidance.js";import{
|
|
1
|
+
import{r as e}from"./errorGuidance.js";import{aO as t}from"./binder.js";const s=Symbol("wcs.notHandled"),r=["read","readMissing","write","writeMissing","writeObserve","written","swapped","get","indexShift","handlerScope","updated","suppressPathDiagnostic","rowReused"],n=new Map;function i(e,t){n.set(e,t)}function o(s,r){const i=n.get(s);return void 0===i&&e(t(s,`"${r}"`)),i}function a(){return{read:[],readMissing:[],write:[],writeMissing:[],writeObserve:[],written:[],swapped:[],get:[],indexShift:[],handlerScope:[],updated:[],suppressPathDiagnostic:[],rowReused:[]}}function c(e,t){for(let s=0;s<r.length;s++){const n=r[s],i=t[n];if(void 0===i)continue;const o=e[n];o.includes(i)||o.push(i)}}function d(e){const t=[];let s=e;for(;s&&s!==Object.prototype;)t.push(s),s=Object.getPrototypeOf(s);const r={};for(let e=t.length-1;e>=0;e--)Object.assign(r,Object.getOwnPropertyDescriptors(t[e]));return r}export{s as N,o as a,c as b,a as c,d as g,i as r};
|
|
2
2
|
//# sourceMappingURL=getAllPropertyDescriptors.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as t}from"./errorGuidance.js";import{
|
|
1
|
+
import{r as t}from"./errorGuidance.js";import{aO as e}from"./binder.js";const n="https://github.com/wcstack/wcstack/blob/main/docs/csp.md";let r=0;async function i(t,e){let i=null;const o=`\n//# sourceURL=${e}#${++r}\n`;let a=!1;const c=t=>{t.effectiveDirective.startsWith("script-src")&&(a=!0)};document.addEventListener("securitypolicyviolation",c);try{if("function"==typeof URL.createObjectURL){const e=new Blob([t.text+o],{type:"application/javascript"}),n=URL.createObjectURL(e);try{i=await import(n)}finally{URL.revokeObjectURL(n)}}else{const e=btoa(String.fromCodePoint(...(new TextEncoder).encode(t.text+o)));i=await import(`data:application/javascript;base64,${e}`)}}catch(t){throw await new Promise(t=>setTimeout(t)),new Error(`[@wcstack/state] ${function(t,e,r){const i=e?.message??String(e);return r?`The inline <script> of state "${t}" was blocked by Content-Security-Policy. Inline state is evaluated through a blob: URL: give the page's nonce to the <script> that loads @wcstack/state, or allow blob: in script-src. Moving the state into an external file (src="./state.js") needs neither. See ${n}`:`Failed to evaluate the inline <script> of state "${t}": ${i}. If this page sets a Content-Security-Policy, see ${n}`}(e,t,a)}`,{cause:t})}finally{document.removeEventListener("securitypolicyviolation",c)}return i&&"object"==typeof i.default?i.default:{}}async function o(t){const e=await import(function(t){return new URL(t,document.baseURI).href}(t));return e.default||{}}const a=Promise.resolve(),c=new Map;let s=[];function l(t,e){c.set(t,e),s=Array.from(c.values()).sort((t,e)=>t.order-e.order)}function u(n,r){return t(e(n,r))}function f(t){for(let e=0;e<s.length;e++){const n=s[e].connecting?.(t);if(null!=n)return n}return null}function p(t){for(let e=0;e<s.length;e++){const n=s[e].preparing?.(t);if(null!=n)return n}return null}function d(t){for(let e=0;e<s.length;e++)if(!0===s[e].reconnecting?.(t))return!0;return!1}function h(t){for(let e=0;e<s.length;e++)s[e].replacingState?.(t)}function g(t,e,n){for(let r=0;r<s.length;r++)s[r].initializeFailed?.(t,e,n)}function m(t,e){for(let n=0;n<s.length;n++)s[n].initializeFailureCleared?.(t,e)}function b(t){for(let e=0;e<s.length;e++)if(!0===s[e].disconnecting?.(t))return!0;return!1}export{a as C,i as a,g as b,f as c,u as d,p as e,d as f,b as g,m as h,h as i,o as l,l as r};
|
|
2
2
|
//# sourceMappingURL=lifecycleHooks.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as t,c as e,b as s}from"./filterRegistry.js";import{l as n,a,b as i,c as o,d as r,e as l,f as d,g as c,h,i as u}from"./lifecycleHooks.js";import{r as p,d as f}from"./errorGuidance.js";import{d as _,j as m,l as g,au as y,c as b,o as k,m as w,av as P,k as S,aw as $,ax as v,ay as C,az as x,aA as I,aB as A,aC as N,aD as E,h as z,w as D,F as R,x as j,aE as L,aF as T,aG as H,aH as O,aI as G,g as M,aJ as U,aK as F,aL as W,aM as K,aN as V}from"./binder.js";import{u as q,v as B,w as J,b as Q,x as X,q as Y,D as Z,W as tt,R as et,g as st,y as nt,z as at,A as it,o as ot,B as rt,I as lt,C as dt,M as ct,c as ht,e as ut,N as pt,m as ft,i as _t,E as mt,k as gt,S as yt,a as bt,r as kt}from"./pathDiagnostics.js";import{n as wt}from"./declarationAliases.js";import{d as Pt,n as St,w as $t,g as vt,e as Ct,r as xt,c as It,b as At,h as Nt,s as Et,a as zt,f as Dt}from"./setAll.js";import{N as Rt,g as jt,a as Lt,c as Tt,b as Ht}from"./getAllPropertyDescriptors.js";import{a as Ot,b as Gt,c as Mt,d as Ut,e as Ft,f as Wt,g as Kt,h as Vt,i as qt,j as Bt}from"./declarationHooks.js";import{g as Jt}from"./checkDependency.js";import{p as Qt}from"./diagnosticsHooks.js";class Xt{_loopContextStack=Array(q).fill(void 0);_length=0;createLoopContext(t,e){null===t.listIndex&&p("Cannot create loop context for a state address that does not have a list index.");const s=t;this._length>=q&&p(`Exceeded maximum loop context stack depth of ${q}. Possible infinite loop.`);const n=this._loopContextStack[this._length-1];if(void 0!==n){n.pathInfo.wildcardCount+1!==s.pathInfo.wildcardCount&&p("Cannot push loop context for a list whose wildcard count is not exactly one more than the current active loop context.");const t=s.pathInfo.wildcardPathInfos[s.pathInfo.wildcardPathInfos.length-2];n.pathInfo!==t&&p("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else s.listIndex.length!==s.pathInfo.wildcardCount&&p(`Cannot push loop context when there is no active loop context: the list index chain (length ${s.listIndex.length}) does not cover the wildcard path (wildcard count ${s.pathInfo.wildcardCount}).`);let a;this._loopContextStack[this._length]=s,this._length++;try{a=e(s)}finally{a instanceof Promise?a.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return a}}function Yt(t,e){if("all"===Jt(e).wildcardType)return!0;const s=t.getterPaths;if(0===s.size)return!1;for(const t of st(e).cumulativePaths)if(s.has(t))return!0;return!1}const Zt=/^\$\d+$/,te=`${ht}${Z}`,ee=`${ut}${Z}`,se=new WeakMap;function ne(t,e,s,n){const a=lt[e];if(void 0===a&&"string"==typeof e&&36===e.charCodeAt(0)&&Zt.test(e)&&p(`[wcs/index-param-range] "${e}" is not a valid list index parameter: they run from ${dt}1 to ${dt}${ct}, with no leading zeros.`),void 0!==a){0===n.addressStackLength&&p(`No active state reference to get list index for "${e.toString()}".`);const t=n.lastAddressStack,s=t?.pathInfo;s&&!n.untracking&&n.stateElement?.getterPaths.has(s.path)&&n.stateElement.addIndexDependentGetterPath?.(s.path);const i=t?.listIndex;null==i&&p(`ListIndex not found: ${e.toString()}`);let o=a;const r=t.pathInfo,l=n.stateElement?.addressHooks;if(l){const e=l.indexShift;for(let s=0;s<e.length;s++)o+=e[s](n,t)}const d=w(i,o,r.wildcardCount);return d?.index??p(`ListIndex not found: ${e.toString()}`)}if("string"==typeof e){const a=n.stateElement?.addressHooks;if(a){const i=a.get;for(let a=0;a<i.length;a++){const o=i[a](n,e,s,t);if(o!==Rt)return o}}if("$"===e[0]){switch(e){case"$stateElement":return n.stateElement;case"$getAll":return(a,i)=>At(t,e,s,n)(a,i);case"$setAll":return(a,i,o,r)=>It(t,e,s,n)(a,i,o,r);case"$postUpdate":return e=>function(t,e,s,n){const a=n.stateElement;return e=>{const i=Jt(e),o=Pt(t,i,s,n),r=m(i.pathInfo,o),l=g(a,r),d=b();d.enqueueAbsoluteAddress(l),St(a,i.pathInfo.path,()=>vt(t,r,s,n),s,n),$t(n.stateElement,r,n.stateElement.staticDependency,n.stateElement.dynamicDependency,n.stateElement.listPaths,s,"new",t=>{const e=g(a,t);y(e),d.enqueueAbsoluteAddress(e)});const c=a.addressHooks;if(c){const t=c.written;for(let e=0;e<t.length;e++)t[e](a,r.pathInfo)}}}(t,0,s,n)(e);case"$resolve":return(a,i,...o)=>xt(t,e,s,n)(a,i,...o);case"$trackDependency":case"$dependOn":return t=>function(t,e,s,n){return t=>{-1!==t.indexOf(et)&&p(`[wcs/recursion-unsupported] ${String(e)}("${t}") cannot take "**" — a dependency is registered against a concrete path (a fixed number of "*"). Track the concrete depth, or read the path through this[...] / $getAll inside the getter so the dependency is recorded automatically.`),0===n.addressStackLength&&p(`No active state reference to track dependency for path "${t}".`);const s=n.lastAddressStack?.pathInfo??p("Internal error: lastAddressStack is null"),a=n.stateElement;n.stateElement.getterPaths.has(s.path)&&s.path!==t&&a.addDynamicDependency(t,s.path)}}(0,e,0,n)(t);case"$eq":return(t,e)=>{const a=n.addressStackLength>0?n.lastAddressStack:null;if(Yt(n.stateElement,t))return null!==a&&n.stateElement.getterPaths.has(a.pathInfo.path)&&P(n.stateElement,t),Object.is(s[t],e);let i;n.beginUntrack();try{i=s[t]}finally{n.endUntrack()}return null!==a&&n.stateElement.getterPaths.has(a.pathInfo.path)&&C(n.stateElement,t,e,g(n.stateElement,a),i),Object.is(i,e)};case"$eqPath":return(t,e)=>{const a=n.addressStackLength>0?n.lastAddressStack:null,i=Yt(n.stateElement,t);let o,r=i?s[t]:void 0;n.beginUntrack();try{i||(r=s[t]),o=s[e]}finally{n.endUntrack()}return null!==a&&n.stateElement.getterPaths.has(a.pathInfo.path)&&(i?P(n.stateElement,t):C(n.stateElement,t,o,g(n.stateElement,a),r)),Object.is(r,o)};case"$eqIndex":return(t,e=1)=>{const a=n.addressStackLength>0?n.lastAddressStack:null;null!==a&&null!==a.listIndex||p(`$eqIndex("${t}") needs a list row scope.`);const i=w(a.listIndex,e-1,a.pathInfo.wildcardCount);if(null===i&&p(`$eqIndex("${t}", ${e}): no list index at that level.`),Yt(n.stateElement,t))return n.stateElement.getterPaths.has(a.pathInfo.path)&&(P(n.stateElement,t),n.stateElement.addIndexDependentGetterPath?.(a.pathInfo.path)),Object.is(s[t],i.index);const o=e===a.pathInfo.wildcardCount;let r,l;n.beginUntrack();try{r=s[t],o&&(l=s[a.pathInfo.wildcardParentPaths[e-1]])}finally{n.endUntrack()}if(n.stateElement.getterPaths.has(a.pathInfo.path)){const e=o?S(l):null;null!==e?$(n.stateElement,t,a.pathInfo,e,r):v(n.stateElement,t,i,g(n.stateElement,a),r)}return Object.is(r,i.index)};case"$untrackDependency":case"$untracked":return t=>function(t,e,s,n){return t=>{n.beginUntrack();try{return t()}finally{n.endUntrack()}}}(0,0,0,n)(t);case J:return Ct(n.stateElement)}if(!e.startsWith(te)&&!e.startsWith(ee))return}const i=Jt(e),o=Pt(t,i,s,n),r=m(i.pathInfo,o);return vt(t,r,s,n)}if("symbol"==typeof e){const a=function(t){let e=se.get(t);return void 0===e&&(e=new Map,se.set(t,e)),e}(n),i=a.get(e);if(void 0!==i)return i;let o;switch(e){case D:o=(t,e=()=>{})=>function(t,e,s){void 0!==t.loopContext&&p("already in loop context"),t.setLoopContext(e);try{t.pushAddress(e);try{return s()}finally{t.popAddress()}}finally{t.clearLoopContext()}}(n,t,e);break;case z:o=e=>vt(t,e,s,n);break;case E:o=e=>Nt(t,e,s,n);break;case N:o=()=>async function(t,e,s){const n=Reflect.get(t,at);"function"==typeof n&&await n.call(s)}(t,0,s);break;case A:o=()=>function(t,e,s){const n=Reflect.get(t,it);"function"==typeof n&&n.call(s)}(t,0,s);break;case I:o=e=>function(t,e,s,n){const a=Reflect.get(t,ot);let i;if("function"==typeof a){const t=new Set,o={};for(const s of e){if(s.absolutePathInfo.stateElement!==n.stateElement)continue;const e=s.absolutePathInfo.pathInfo,a=e.path;if(-1===a.indexOf("#")&&(t.add(a),e.wildcardCount>0)){const t=k(s.listIndex,e.wildcardCount),n=o[a];void 0===n?o[a]=[t]:n.push(t)}}(t.size>0||0===e.length)&&(i=a.call(s,Array.from(t),o))}const o=n.stateElement?.addressHooks;if(o){const t=o.updated;for(let a=0;a<t.length;a++)t[a](n.stateElement,e,s)}return i}(t,e,s,n);break;case x:o=(e,n)=>function(t,e,s,n){const a=Reflect.get(t,rt);"function"==typeof a&&a.call(n,e,s)}(t,e,n,s);break;default:return Reflect.get(t,e,s)}return a.set(e,o),o}}class ae{_stateElement;_addressStack=Array(q).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;_untrackDepth=0;constructor(t,e){const s=R(t);null===s&&p("StateHandler: no state tree found on this root."),this._stateElement=s,this._mutability=e}get stateElement(){return this._stateElement}get mutability(){return this._mutability}get lastAddressStack(){let t;return this._addressStackIndex>=0&&(t=this._addressStack[this._addressStackIndex]),void 0===t&&p("Last address stack is undefined."),t}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(t){this._addressStackIndex+1>=q&&(this._hasRepeatedAddress()&&p(`[wcs/getter-cycle] Exceeded maximum address stack depth of ${q}. Possible circular dependency between path getters: ${this._describeAddressCycle()}`),p(`[wcs/getter-depth-exceeded] Exceeded maximum address stack depth of ${q} with no address visited twice — the data is simply nested deeper than the engine evaluates in one pass. Deepest path first: ${this._describeAddressCycle()}`)),this._addressStackIndex++,this._addressStack[this._addressStackIndex]=t}_hasRepeatedAddress(){const t=new Set;for(let e=0;e<=this._addressStackIndex;e++){const s=this._addressStack[e];if(s){if(t.has(s))return!0;t.add(s)}}return!1}_tailAddressPaths(){const t=[];for(let e=this._addressStackIndex;e>=0&&t.length<8;e--){const s=this._addressStack[e];s&&t.push(s.pathInfo.path)}return t}_describeAddressCycle(){const t=this._tailAddressPaths();return`${Array.from(new Set(t)).reverse().join(" -> ")} -> ...`}popAddress(){if(this._addressStackIndex<0)return null;const t=this._addressStack[this._addressStackIndex];return void 0===t&&p(`Address stack at index ${this._addressStackIndex} is undefined.`),this._addressStack[this._addressStackIndex]=void 0,this._addressStackIndex--,t}setLoopContext(t){this._loopContext=t}clearLoopContext(){this._loopContext=void 0}get untracking(){return this._untrackDepth>0}beginUntrack(){this._untrackDepth++}endUntrack(){this._untrackDepth--}get(t,e,s){return ne(t,e,s,this)}set(t,e,s,n){return zt(this),function(t,e,s,n,a){if("string"==typeof e){const i=Jt(e),o=Pt(t,i,n,a),r=m(i.pathInfo,o);return Et(t,r,s,n,a)}return Reflect.set(t,e,s,n)}(t,e,s,n,this)}has(t,e){return Reflect.has(t,e)}deleteProperty(t,e){return zt(this),Reflect.deleteProperty(t,e)}defineProperty(t,e,s){return zt(this),Reflect.defineProperty(t,e,s)}}const ie="undefined"==typeof HTMLElement?class{}:HTMLElement;const oe=new Set(["for","if","elseif","else"]);function re(e,s,n){const a=new Map;for(const t of n){const e=st(t);if(null===e.lastWildcardPath)continue;const s=a.get(e.lastWildcardPath);void 0===s?a.set(e.lastWildcardPath,[e]):s.push(e)}const i=[],o=new Set,r=t=>{const s=g(e,t);if(o.has(s))return;o.add(s);const n=O(s);if(n instanceof Set?i.push(...n):void 0!==n&&i.push(n),null!==t.listIndex){const e=a.get(t.pathInfo.path);if(void 0!==e)for(const s of e)r(m(s,t.listIndex))}};G();try{if(e.createState("readonly",t=>{for(const n of s){const s=m(st(n),null);r(s);try{$t(e,s,e.staticDependency,e.dynamicDependency,e.listPaths,t,"new",r)}catch{}}}),0===i.length)return;const n=function(t){const e=[],s=[];for(const n of t)oe.has(n.bindingType)?e.push(n):s.push(n);return e.sort((t,e)=>0!==(t.replaceNode.compareDocumentPosition(e.replaceNode)&Node.DOCUMENT_POSITION_FOLLOWING)?-1:1),e.concat(s)}(i),a=()=>{j(n,void 0,{updatedCallback:!1})};if(t())return void a();const o=L("state",a);void 0!==o&&o.catch(T)}finally{H()}}const le=[[_t,"watch"],[yt,"scan"],[bt,"streams"],[kt,"recursion"]];class de extends ie{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return M(t)}static get observedAttributes(){return["mount"]}__state;_hasUpdatedCallback=!1;_hasErrorCallback=!1;_hydratedFromSsr=!1;_crossRowListPaths=new Set;_indexDependentGetterPaths=new Set;_initialized=!1;_initializeFailed=!1;_initializationLanded=!1;_initializePromise;_resolveInitialize=null;_connectedCallbackPromise;_resolveConnectedCallback=null;_rejectConnectedCallback=null;_loadingPromise;_resolveLoading=null;_setStatePromise=null;_resolveSetState=null;_listPaths=new Set;_listKeys=null;_recursionRegistry=null;_elementPaths=new Set;_getterPaths=new Set;_setterPaths=new Set;_loopContextStack=function(){return new Xt}();_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_stateGeneration=0;_pathRegistrations=new Map;_pendingReapplyPaths=null;_generatedPaths=new Set;_watchPaths=null;_scanPaths=null;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_hasMounts=!1;_hasGraftedVolumes=!1;_addressHooks=null;_bindableEventMap={};_commandTokenNames=new Set;_eventTokenNames=new Set;_treeless=!1;_connectGeneration=0;constructor(){super(),this._initializePromise=new Promise(t=>{this._resolveInitialize=t}),this._connectedCallbackPromise=new Promise((t,e)=>{this._resolveConnectedCallback=t,this._rejectConnectedCallback=e}),this._loadingPromise=new Promise(t=>{this._resolveLoading=t}),this._setStatePromise=new Promise(t=>{this._resolveSetState=t})}get _state(){return void 0===this.__state&&p(`${e.tagNames.state} _state is not initialized yet.`),this.__state}set _state(t){wt(t),function(t){for(let e=0;e<le.length;e++){const[s,n]=le[e];s in t&&!Bt(n)&&p(V(n,`"${s}"`))}}(t);const e=this.__state,s=qt();s.set("previousState",e),Ot(this,t,s);const n=function(t){const e=new Set,s=t[B];if(void 0===s)return e;Array.isArray(s)||p(`${B} must be an array of strings.`);for(const t of s)"string"==typeof t&&0!==t.length||p(`${B} entries must be non-empty strings.`),t===J&&p(`${B} entry "${t}" conflicts with the reserved namespace name "${J}".`),e.has(t)&&p(`${B} entry "${t}" is duplicated.`),e.add(t);return e}(t),a=function(t){const e=new Set,s=t[Q];if(void 0===s)return e;Array.isArray(s)||p(`${Q} must be an array of strings.`);for(const t of s)"string"==typeof t&&0!==t.length||p(`${Q} entries must be non-empty strings.`),e.has(t)&&p(`${Q} entry "${t}" is duplicated.`),e.add(t);return e}(t),i=function(t){const e=t[Y];if(void 0===e)return null;"object"==typeof e&&null!==e||p(`${Y} must be an object mapping list paths to key specs.`);const s=new Map;for(const[t,n]of Object.entries(e)){0===t.length&&p(`${Y} entry path must be a non-empty string.`);const e=t.split(Z);e.some(t=>0===t.length)&&p(`${Y} entry "${t}" must not contain empty path segments.`),e[e.length-1]===tt&&p(`${Y} entry "${t}" must be the list path itself, not the element path (drop the trailing "${Z}${tt}").`),-1!==t.indexOf(et)&&p(`[wcs/recursion-unsupported] ${Y} entry "${t}" uses "${et}", which ${Y} does not interpret — a keyed list is one concrete list path. Declare the key per depth instead (for example "nodes${Z}${tt}${Z}children").`),"function"!=typeof n?("string"!=typeof n&&p(`${Y} entry "${t}" key spec must be a field name (string) or a function.`),0===n.length&&p(`${Y} entry "${t}" key field name must be a non-empty string.`),(n.includes(Z)||n.includes(tt))&&p(`${Y} entry "${t}" key field name "${n}" must be a flat property name ("${Z}" / "${tt}" are not allowed).`),n in Object.prototype&&p(`${Y} entry "${t}" key field name "${n}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),s.set(t,n)):s.set(t,n)}return s.size>0?s:null}(t);s.set("eventTokenNames",a),Gt(this,t,s),Mt(this,t,s),this._commandTokenNames=n,this._eventTokenNames=a,this._stateGeneration++,this.__state=t,void 0!==e&&Qt?.reset(this),this._hasUpdatedCallback=ot in t,this._hasErrorCallback=rt in t,U(this),Ut(this,t,s),function(t,e,s){const n=e[X];if(void 0!==n){"object"==typeof n&&null!==n||p(`${X} must be an object mapping event-token names to handler functions.`);for(const[e,a]of Object.entries(n))s.has(e)||p(`${X} entry "${e}" is not declared in $eventTokens.${f(e,s)}`),"function"!=typeof a&&p(`${X} entry "${e}" must be a function.`),_(t,e).subscribe(a)}}(this,t,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const o=function(t){const e=new Set,s=new Set,n=jt(t);for(const[t,a]of Object.entries(n))"function"==typeof a.get&&e.add(t),"function"==typeof a.set&&s.add(t);return{getterPaths:e,setterPaths:s}}(t);for(const t of o.getterPaths)this._getterPaths.add(t);for(const t of o.setterPaths)this._setterPaths.add(t);Ft(this,t,s),this._listKeys=i,this._rebuildPathInfo(),Wt(this,t,s),Kt(this,null),this._resolveLoading?.()}attributeChangedCallback(t,s,n){this._initialized&&s!==n&&console.warn(`[@wcstack/state] Changing the "mount" attribute after initialization is not supported and is ignored (was ${null===s?"absent":`"${s}"`}, now ${null===n?"absent":`"${n}"`}). Remove this <${e.tagNames.state}> element and create a new one with the desired mount path instead.`)}_loadFromSsrElement(){return this.hasAttribute("enable-ssr")?F('the "enable-ssr" attribute').loadState(this):null}async _loadStateFromSource(){if(this.hasAttribute("state")){return function(t){const e=document.getElementById(t);return e&&"application/json"===e.type?JSON.parse(e.textContent||"{}"):(console.warn(`[@wcstack/state] state="${t}": no <script type="application/json" id="${t}"> in the document (3.x does not look inside shadow roots), so the state starts empty.`),{})}(this.getAttribute("state"))}if(!this.hasAttribute("src")){if(this.hasAttribute("json")){const t=this.getAttribute("json");return JSON.parse(t)}{const t=this.querySelector('script[type="module"]');if(t)return await a(t,e.tagNames.state);{const t=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${e.tagNames.state}> element.`)},pt),s=await this._setStatePromise;return clearTimeout(t),s}}}{const t=this.getAttribute("src");if(t&&t.endsWith(".json"))return await async function(t){let e;try{const s=await fetch(t);if(s.ok)return await s.json();e=`HTTP ${s.status} ${s.statusText}`}catch(t){e=t}return console.error(`[@wcstack/state] Failed to load JSON file "${t}", so the state starts empty (4.0 rejects instead):`,e),{}}(t);if(t&&t.endsWith(".js"))return await n(t);p(`Unsupported src file type: ${t}`)}}async _initialize(){const e=t()?null:this._loadFromSsrElement();if(null!==e&&(this._hydratedFromSsr=!0),this._state=await this._loadStateFromSource(),null!==e&&this.__state)for(const[t,s]of Object.entries(e)){if(t in this.__state){const e=Object.getOwnPropertyDescriptor(this.__state,t);if(e&&(e.get||e.set))continue;if("function"==typeof this.__state[t])continue}this.__state[t]=s}return await this._loadingPromise,null!==this._rootNode&&(W(this._rootNode,this),!0)}_failInitialization(t){this._initializationLanded=!0,this._resolveInitialize?.(),this._resolveLoading?.(),this._resolveConnectedCallback?.(),p(t)}_failInitializeLoudly(t,s=!0){if(this._initializationLanded)throw t;this._initializeFailed=!0;const n=["state","src"].find(t=>this.hasAttribute(t));throw console.error(`[@wcstack/state] <${e.tagNames.state}${n?` ${n}="${this.getAttribute(n)}"`:""}> failed to initialize.`,t),this._resolveInitialize?.(),this._resolveLoading?.(),this._connectedCallbackPromise.catch(()=>{}),this._rejectConnectedCallback?.(t),s&&null!==this._rootNode&&null===R(this._rootNode)&&(K(this._rootNode,t),i(this,this._rootNode,t)),t}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{at in t&&await t[N]()})}_callStateDisconnectedCallback(){this.createState("writable",t=>{it in t&&t[A]()})}async connectedCallback(){this._rootNode=this.getRootNode();const n=++this._connectGeneration;if(this._initializationLanded=!1,this._initialized){if(d(this))return void this._resolveConnectedCallback?.();this._treeless||R(this._rootNode)===this||W(this._rootNode,this)}else{this.hasAttribute("name")&&this._failInitialization(this.hasAttribute("mount")?'"mount" replaces "name" — a volume has no name of its own. Remove the name attribute.':`The "name" attribute was removed in v2 — there is a single state tree per root. Mount this state onto the tree instead: <wcs-state mount="${this.getAttribute("name")}" ...> and read it as "${this.getAttribute("name")}.<path>".`);const t=o(this);if(null!==t)return void await t;if(this.hasAttribute("mount"))try{r("scopes",'the "mount" attribute')}catch(t){this._failInitializeLoudly(t,!1)}const s=this.parentNode;if(s instanceof ShadowRoot&&s.host.hasAttribute(ft))try{r("dcc",`a <${e.tagNames.state}> inside a [${ft}] host`)}catch(t){this._failInitializeLoudly(t)}let n=!1;try{const t=l(this);null===t&&this.hasAttribute("bind-component")&&r("scopes",'the "bind-component" attribute'),n=await(t??!1)}catch(t){this._failInitializeLoudly(t)}if(n)return;let a=!1;try{a=await this._initialize()}catch(t){this._failInitializeLoudly(t)}if(!a)return;this._initialized=!0,this._resolveInitialize?.()}if(null!==this._pendingReapplyPaths){const t=this._pendingReapplyPaths;this._pendingReapplyPaths=null,this._reapplyBindings(t)}if(this.hasAttribute("enable-ssr")&&!t()||n!==this._connectGeneration||await this._callStateConnectedCallback(),t()&&this.hasAttribute("enable-ssr")&&!s())try{await F('the "enable-ssr" attribute').emitSnapshot(this)}catch(t){throw this._rejectConnectedCallback?.(t),t}Kt(this,n),this._resolveConnectedCallback?.()}disconnectedCallback(){if(!c(this)&&null!==this._rootNode){if(!this._initialized)return this._initializeFailed&&h(this,this._rootNode),void(this._rootNode=null);try{this._callStateDisconnectedCallback()}finally{W(this.rootNode,null),Dt(this),Vt(this),this._rootNode=null}}}get initialized(){return this._initialized}get connectedRootNode(){return this._rootNode}clearConnectedRootNode(){this._rootNode=null}markInitialized(){this._initialized=!0}settleInitialization(){this._resolveInitialize?.(),this._resolveLoading?.(),this._resolveConnectedCallback?.()}loadStateFromSource(){return this._loadStateFromSource().then(t=>(wt(t),t))}markTreeless(){this._treeless=!0}failInitializeLoudly(t){return this._failInitializeLoudly(t)}get connectGeneration(){return this._connectGeneration}setWatchPaths(t){this._watchPaths=t}setScanPaths(t){this._scanPaths=t}landInitialization(){this._initializationLanded=!0,this._resolveInitialize?.(),this._resolveLoading?.(),this._resolveConnectedCallback?.()}setRecursionRegistry(t){this._recursionRegistry=t}addGeneratedPath(t){this._generatedPaths.add(t)}setBoundComponent(t,e){this._boundComponent=t,this._boundComponentStateProp=e}get initializePromise(){return this._initializePromise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get listPaths(){return this._listPaths}get listKeys(){return this._listKeys}get hasRecursion(){return null!==this._recursionRegistry}get recursionRegistry(){return this._recursionRegistry}get watchPaths(){return this._watchPaths}get scanPaths(){return this._scanPaths}get elementPaths(){return this._elementPaths}addVolumeWatchPaths(t){if(0===t.size)return;const e=new Set(this._watchPaths??[]);for(const s of t)e.add(s);this._watchPaths=e,this.attachAddressHooks("watch",_t)}mergeVolumeListKeys(t){if(0===t.size)return;const e=new Map(this._listKeys??[]);for(const[s,n]of t)e.has(s)&&p(`$listKeys entry "${s}" is declared by both the root and a volume (or two volumes). Keep exactly one.`),e.set(s,n);this._listKeys=e}enableUpdatedCallback(){this._hasUpdatedCallback=!0}get hydratedFromSsr(){return this._hydratedFromSsr}addListPath(t){this._listPaths.add(t)}findStateDescriptor(t){return mt(this._state,t)}defineTreeAccessor(t,e){Object.defineProperty(this._state,t,e),"function"==typeof e.get&&this._getterPaths.add(t),"function"==typeof e.set&&this._setterPaths.add(t),this.setPathInfo(t,"prop","internal")}get getterPaths(){return this._getterPaths}get setterPaths(){return this._setterPaths}get loopContextStack(){return this._loopContextStack}get dynamicDependency(){return this._dynamicDependency}get staticDependency(){return this._staticDependency}get version(){return this._version}get stateGeneration(){return this._stateGeneration}get rootNode(){return null===this._rootNode&&p("State rootNode is not available."),this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get hasMounts(){return this._hasMounts}markHasMounts(){this._hasMounts=!0,this._attachScopeHooks("bind-component")}get hasGraftedVolumes(){return this._hasGraftedVolumes}get addressHooks(){return this._addressHooks}attachAddressHooks(t,e){const s=Lt(t,e);null===this._addressHooks&&(this._addressHooks=Tt()),Ht(this._addressHooks,s)}markHasGraftedVolumes(){this._hasGraftedVolumes=!0,this._attachScopeHooks("mount")}markHasVolume(){this._attachScopeHooks("mount")}_attachScopeHooks(t){this.attachAddressHooks("scopes",t)}get bindableEventMap(){return this._bindableEventMap}get commandTokenNames(){return this._commandTokenNames}get eventTokenNames(){return this._eventTokenNames}setBindableEventMap(t){this._bindableEventMap=t,this.attachAddressHooks("dcc",gt)}_addDependency(t,e,s){const n=t.get(e);return void 0===n?(t.set(e,[s]),!0):!n.includes(s)&&(n.push(s),!0)}addDynamicDependency(t,e){if(!this._addDependency(this._dynamicDependency,t,e))return!1;const s=st(t);for(let t=s.parentPathInfo;null!==t&&t.wildcardCount>0&&t.wildcardCount===s.wildcardCount;t=t.parentPathInfo)this._addDependency(this._dynamicDependency,t.path,e);return!0}addStaticDependency(t,e){return this._addDependency(this._staticDependency,t,e)}setPathInfo(t,e,s="binding"){if("internal"!==s){const n=this._pathRegistrations.get(t);void 0===n?this._pathRegistrations.set(t,{bindingType:e,bound:"binding"===s}):"for"!==n.bindingType&&this._pathRegistrations.set(t,{bindingType:e,bound:n.bound||"binding"===s})}if("for"===e&&(this._listPaths.add(t),this._elementPaths.add(t+"."+tt)),!this._pathSet.has(t)){const e=st(t);this._pathSet.add(t);const n=function(t,e){const s=Jt(e);return"all"===s.wildcardType&&1===s.wildcardIndexes.length&&isNaN(+s.segments[0])&&!e.includes("#")&&Object.isExtensible(t)&&!(e in t)}(this.__state,t);if(Qt?.check(this,this.__state,t,s,n),n&&function(t,e){const{segments:s,cumulativePaths:n}=st(e),a=s.length-1,i=(t,i,o)=>{let r,l=!1;for(let d=0;d<=a;d++){const c=s[d];if(l||=!(isNaN(+c)||Array.isArray(r)&&+c in r),i&&d===a)return l?r[c]=o:t[e]=o;r=l?r?.[c]:t[n[d]]}return r},o=function(){return i(this)};nt.set(o,Jt(e).pathInfo.path),t.defineTreeAccessor(e,{get:o,set(t){i(this,!0,t)},configurable:!0})}(this,t),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=st(t.parentPath)}}}_rebuildPathInfo(){for(const[t,e]of Array.from(this._pathRegistrations))e.bound&&!this._generatedPaths.has(t)&&this.setPathInfo(t,e.bindingType)}_createState(t,e,s){try{const n=function(t,e,s){const n=new ae(t,s);return new Proxy(e,n)}(t,this._state,e);return s(n)}finally{}}async createStateAsync(t,e){return await this._createState(this.rootNode,t,e)}createState(t,e){this._createState(this.rootNode,t,e)}nextVersion(){return this._version++,this._version}get hasUpdatedCallback(){return this._hasUpdatedCallback}get hasErrorCallback(){return this._hasErrorCallback}get crossRowListPaths(){return this._crossRowListPaths}addCrossRowListPath(t){this._crossRowListPaths.add(t)}get indexDependentGetterPaths(){return this._indexDependentGetterPaths}addIndexDependentGetterPath(t){this._indexDependentGetterPaths.add(t)}setInitialState(t){if(!this._initialized)return this._initializeFailed&&p(`<${e.tagNames.state}> failed to initialize (the diagnostic was reported when it connected), so its state cannot be replaced. Remove this element and create a new one with the corrected state.`),void this._resolveSetState?.(t);u(this),(this._hasGraftedVolumes||this._hasMounts)&&p("Cannot replace the whole state of a tree that has grafted volumes or mounted components: re-setting would silently drop grafted data, tree accessors and mount ledgers (D22). Write the changed paths instead.");const s=this.__state;this._state=t;const n=function(t){const e=new Set;for(const s of t)if(void 0!==s)for(const[t,n]of Object.entries(jt(s)))t.startsWith("$")||t.includes(tt)||"function"==typeof n.value||e.add(t);return e}([s,t]);null!==this._rootNode?this._reapplyBindings(n):this._pendingReapplyPaths=new Set([...this._pendingReapplyPaths??[],...n])}_reapplyBindings(t){re(this,t,this._pathRegistrations.keys())}}const ce=[],he=[];function ue(){const t=[];let e=0;for(let s=0;s<he.length;s++){const n=he[s].deref();void 0!==n&&(t.push(n),he[e++]=he[s])}return he.length=e,t}function pe(t){if(!ce.includes(t)){ce.push(t);for(const e of ue())t(e)}}function fe(t=customElements){ue().includes(t)||he.push(new WeakRef(t));for(let e=0;e<ce.length;e++)ce[e](t);t.get(e.tagNames.state)||t.define(e.tagNames.state,de)}export{ie as H,pe as a,fe as r};
|
|
1
|
+
import{i as t,c as e,b as s}from"./filterRegistry.js";import{l as n,a,b as i,c as o,d as r,e as l,f as d,g as c,h,i as u}from"./lifecycleHooks.js";import{r as p,d as f}from"./errorGuidance.js";import{d as _,j as m,l as g,av as y,c as b,o as k,m as w,aw as P,k as S,ax as $,ay as v,az as C,aA as x,aB as I,aC as A,aD as N,aE as E,h as z,w as D,G as R,x as j,aF as L,aG as T,aH as H,aI as O,aJ as G,g as M,aK as U,aL as F,aM as W,aN as K,aO as V}from"./binder.js";import{u as q,v as B,w as J,b as Q,x as X,q as Y,D as Z,W as tt,R as et,g as st,y as nt,z as at,A as it,o as ot,B as rt,I as lt,C as dt,M as ct,c as ht,e as ut,N as pt,m as ft,i as _t,E as mt,k as gt,S as yt,a as bt,r as kt}from"./pathDiagnostics.js";import{n as wt}from"./declarationAliases.js";import{d as Pt,n as St,w as $t,g as vt,e as Ct,r as xt,c as It,b as At,h as Nt,s as Et,a as zt,f as Dt}from"./setAll.js";import{N as Rt,g as jt,a as Lt,c as Tt,b as Ht}from"./getAllPropertyDescriptors.js";import{a as Ot,b as Gt,c as Mt,d as Ut,e as Ft,f as Wt,g as Kt,h as Vt,i as qt,j as Bt}from"./declarationHooks.js";import{g as Jt}from"./checkDependency.js";import{p as Qt}from"./diagnosticsHooks.js";class Xt{_loopContextStack=Array(q).fill(void 0);_length=0;createLoopContext(t,e){null===t.listIndex&&p("Cannot create loop context for a state address that does not have a list index.");const s=t;this._length>=q&&p(`Exceeded maximum loop context stack depth of ${q}. Possible infinite loop.`);const n=this._loopContextStack[this._length-1];if(void 0!==n){n.pathInfo.wildcardCount+1!==s.pathInfo.wildcardCount&&p("Cannot push loop context for a list whose wildcard count is not exactly one more than the current active loop context.");const t=s.pathInfo.wildcardPathInfos[s.pathInfo.wildcardPathInfos.length-2];n.pathInfo!==t&&p("Cannot push loop context for a list whose parent wildcard path info does not match the current active loop context.")}else s.listIndex.length!==s.pathInfo.wildcardCount&&p(`Cannot push loop context when there is no active loop context: the list index chain (length ${s.listIndex.length}) does not cover the wildcard path (wildcard count ${s.pathInfo.wildcardCount}).`);let a;this._loopContextStack[this._length]=s,this._length++;try{a=e(s)}finally{a instanceof Promise?a.finally(()=>{this._length--,this._loopContextStack[this._length]=void 0}):(this._length--,this._loopContextStack[this._length]=void 0)}return a}}function Yt(t,e){if("all"===Jt(e).wildcardType)return!0;const s=t.getterPaths;if(0===s.size)return!1;for(const t of st(e).cumulativePaths)if(s.has(t))return!0;return!1}const Zt=/^\$\d+$/,te=`${ht}${Z}`,ee=`${ut}${Z}`,se=new WeakMap;function ne(t,e,s,n){const a=lt[e];if(void 0===a&&"string"==typeof e&&36===e.charCodeAt(0)&&Zt.test(e)&&p(`[wcs/index-param-range] "${e}" is not a valid list index parameter: they run from ${dt}1 to ${dt}${ct}, with no leading zeros.`),void 0!==a){0===n.addressStackLength&&p(`No active state reference to get list index for "${e.toString()}".`);const t=n.lastAddressStack,s=t?.pathInfo;s&&!n.untracking&&n.stateElement?.getterPaths.has(s.path)&&n.stateElement.addIndexDependentGetterPath?.(s.path);const i=t?.listIndex;null==i&&p(`ListIndex not found: ${e.toString()}`);let o=a;const r=t.pathInfo,l=n.stateElement?.addressHooks;if(l){const e=l.indexShift;for(let s=0;s<e.length;s++)o+=e[s](n,t)}const d=w(i,o,r.wildcardCount);return d?.index??p(`ListIndex not found: ${e.toString()}`)}if("string"==typeof e){const a=n.stateElement?.addressHooks;if(a){const i=a.get;for(let a=0;a<i.length;a++){const o=i[a](n,e,s,t);if(o!==Rt)return o}}if("$"===e[0]){switch(e){case"$stateElement":return n.stateElement;case"$getAll":return(a,i)=>At(t,e,s,n)(a,i);case"$setAll":return(a,i,o,r)=>It(t,e,s,n)(a,i,o,r);case"$postUpdate":return e=>function(t,e,s,n){const a=n.stateElement;return e=>{const i=Jt(e),o=Pt(t,i,s,n),r=m(i.pathInfo,o),l=g(a,r),d=b();d.enqueueAbsoluteAddress(l),St(a,i.pathInfo.path,()=>vt(t,r,s,n),s,n),$t(n.stateElement,r,n.stateElement.staticDependency,n.stateElement.dynamicDependency,n.stateElement.listPaths,s,"new",t=>{const e=g(a,t);y(e),d.enqueueAbsoluteAddress(e)});const c=a.addressHooks;if(c){const t=c.written;for(let e=0;e<t.length;e++)t[e](a,r.pathInfo)}}}(t,0,s,n)(e);case"$resolve":return(a,i,...o)=>xt(t,e,s,n)(a,i,...o);case"$trackDependency":case"$dependOn":return t=>function(t,e,s,n){return t=>{-1!==t.indexOf(et)&&p(`[wcs/recursion-unsupported] ${String(e)}("${t}") cannot take "**" — a dependency is registered against a concrete path (a fixed number of "*"). Track the concrete depth, or read the path through this[...] / $getAll inside the getter so the dependency is recorded automatically.`),0===n.addressStackLength&&p(`No active state reference to track dependency for path "${t}".`);const s=n.lastAddressStack?.pathInfo??p("Internal error: lastAddressStack is null"),a=n.stateElement;n.stateElement.getterPaths.has(s.path)&&s.path!==t&&a.addDynamicDependency(t,s.path)}}(0,e,0,n)(t);case"$eq":return(t,e)=>{const a=n.addressStackLength>0?n.lastAddressStack:null;if(Yt(n.stateElement,t))return null!==a&&n.stateElement.getterPaths.has(a.pathInfo.path)&&P(n.stateElement,t),Object.is(s[t],e);let i;n.beginUntrack();try{i=s[t]}finally{n.endUntrack()}return null!==a&&n.stateElement.getterPaths.has(a.pathInfo.path)&&C(n.stateElement,t,e,g(n.stateElement,a),i),Object.is(i,e)};case"$eqPath":return(t,e)=>{const a=n.addressStackLength>0?n.lastAddressStack:null,i=Yt(n.stateElement,t);let o,r=i?s[t]:void 0;n.beginUntrack();try{i||(r=s[t]),o=s[e]}finally{n.endUntrack()}return null!==a&&n.stateElement.getterPaths.has(a.pathInfo.path)&&(i?P(n.stateElement,t):C(n.stateElement,t,o,g(n.stateElement,a),r)),Object.is(r,o)};case"$eqIndex":return(t,e=1)=>{const a=n.addressStackLength>0?n.lastAddressStack:null;null!==a&&null!==a.listIndex||p(`$eqIndex("${t}") needs a list row scope.`);const i=w(a.listIndex,e-1,a.pathInfo.wildcardCount);if(null===i&&p(`$eqIndex("${t}", ${e}): no list index at that level.`),Yt(n.stateElement,t))return n.stateElement.getterPaths.has(a.pathInfo.path)&&(P(n.stateElement,t),n.stateElement.addIndexDependentGetterPath?.(a.pathInfo.path)),Object.is(s[t],i.index);const o=e===a.pathInfo.wildcardCount;let r,l;n.beginUntrack();try{r=s[t],o&&(l=s[a.pathInfo.wildcardParentPaths[e-1]])}finally{n.endUntrack()}if(n.stateElement.getterPaths.has(a.pathInfo.path)){const e=o?S(l):null;null!==e?$(n.stateElement,t,a.pathInfo,e,r):v(n.stateElement,t,i,g(n.stateElement,a),r)}return Object.is(r,i.index)};case"$untrackDependency":case"$untracked":return t=>function(t,e,s,n){return t=>{n.beginUntrack();try{return t()}finally{n.endUntrack()}}}(0,0,0,n)(t);case J:return Ct(n.stateElement)}if(!e.startsWith(te)&&!e.startsWith(ee))return}const i=Jt(e),o=Pt(t,i,s,n),r=m(i.pathInfo,o);return vt(t,r,s,n)}if("symbol"==typeof e){const a=function(t){let e=se.get(t);return void 0===e&&(e=new Map,se.set(t,e)),e}(n),i=a.get(e);if(void 0!==i)return i;let o;switch(e){case D:o=(t,e=()=>{})=>function(t,e,s){void 0!==t.loopContext&&p("already in loop context"),t.setLoopContext(e);try{t.pushAddress(e);try{return s()}finally{t.popAddress()}}finally{t.clearLoopContext()}}(n,t,e);break;case z:o=e=>vt(t,e,s,n);break;case E:o=e=>Nt(t,e,s,n);break;case N:o=()=>async function(t,e,s){const n=Reflect.get(t,at);"function"==typeof n&&await n.call(s)}(t,0,s);break;case A:o=()=>function(t,e,s){const n=Reflect.get(t,it);"function"==typeof n&&n.call(s)}(t,0,s);break;case I:o=e=>function(t,e,s,n){const a=Reflect.get(t,ot);let i;if("function"==typeof a){const t=new Set,o={};for(const s of e){if(s.absolutePathInfo.stateElement!==n.stateElement)continue;const e=s.absolutePathInfo.pathInfo,a=e.path;if(-1===a.indexOf("#")&&(t.add(a),e.wildcardCount>0)){const t=k(s.listIndex,e.wildcardCount),n=o[a];void 0===n?o[a]=[t]:n.push(t)}}(t.size>0||0===e.length)&&(i=a.call(s,Array.from(t),o))}const o=n.stateElement?.addressHooks;if(o){const t=o.updated;for(let a=0;a<t.length;a++)t[a](n.stateElement,e,s)}return i}(t,e,s,n);break;case x:o=(e,n)=>function(t,e,s,n){const a=Reflect.get(t,rt);"function"==typeof a&&a.call(n,e,s)}(t,e,n,s);break;default:return Reflect.get(t,e,s)}return a.set(e,o),o}}class ae{_stateElement;_addressStack=Array(q).fill(void 0);_addressStackIndex=-1;_loopContext;_mutability;_untrackDepth=0;constructor(t,e){const s=R(t);null===s&&p("StateHandler: no state tree found on this root."),this._stateElement=s,this._mutability=e}get stateElement(){return this._stateElement}get mutability(){return this._mutability}get lastAddressStack(){let t;return this._addressStackIndex>=0&&(t=this._addressStack[this._addressStackIndex]),void 0===t&&p("Last address stack is undefined."),t}get addressStackLength(){return this._addressStackIndex+1}get loopContext(){return this._loopContext}pushAddress(t){this._addressStackIndex+1>=q&&(this._hasRepeatedAddress()&&p(`[wcs/getter-cycle] Exceeded maximum address stack depth of ${q}. Possible circular dependency between path getters: ${this._describeAddressCycle()}`),p(`[wcs/getter-depth-exceeded] Exceeded maximum address stack depth of ${q} with no address visited twice — the data is simply nested deeper than the engine evaluates in one pass. Deepest path first: ${this._describeAddressCycle()}`)),this._addressStackIndex++,this._addressStack[this._addressStackIndex]=t}_hasRepeatedAddress(){const t=new Set;for(let e=0;e<=this._addressStackIndex;e++){const s=this._addressStack[e];if(s){if(t.has(s))return!0;t.add(s)}}return!1}_tailAddressPaths(){const t=[];for(let e=this._addressStackIndex;e>=0&&t.length<8;e--){const s=this._addressStack[e];s&&t.push(s.pathInfo.path)}return t}_describeAddressCycle(){const t=this._tailAddressPaths();return`${Array.from(new Set(t)).reverse().join(" -> ")} -> ...`}popAddress(){if(this._addressStackIndex<0)return null;const t=this._addressStack[this._addressStackIndex];return void 0===t&&p(`Address stack at index ${this._addressStackIndex} is undefined.`),this._addressStack[this._addressStackIndex]=void 0,this._addressStackIndex--,t}setLoopContext(t){this._loopContext=t}clearLoopContext(){this._loopContext=void 0}get untracking(){return this._untrackDepth>0}beginUntrack(){this._untrackDepth++}endUntrack(){this._untrackDepth--}get(t,e,s){return ne(t,e,s,this)}set(t,e,s,n){return zt(this),function(t,e,s,n,a){if("string"==typeof e){const i=Jt(e),o=Pt(t,i,n,a),r=m(i.pathInfo,o);return Et(t,r,s,n,a)}return Reflect.set(t,e,s,n)}(t,e,s,n,this)}has(t,e){return Reflect.has(t,e)}deleteProperty(t,e){return zt(this),Reflect.deleteProperty(t,e)}defineProperty(t,e,s){return zt(this),Reflect.defineProperty(t,e,s)}}const ie="undefined"==typeof HTMLElement?class{}:HTMLElement;const oe=new Set(["for","if","elseif","else"]);function re(e,s,n){const a=new Map;for(const t of n){const e=st(t);if(null===e.lastWildcardPath)continue;const s=a.get(e.lastWildcardPath);void 0===s?a.set(e.lastWildcardPath,[e]):s.push(e)}const i=[],o=new Set,r=t=>{const s=g(e,t);if(o.has(s))return;o.add(s);const n=O(s);if(n instanceof Set?i.push(...n):void 0!==n&&i.push(n),null!==t.listIndex){const e=a.get(t.pathInfo.path);if(void 0!==e)for(const s of e)r(m(s,t.listIndex))}};G();try{if(e.createState("readonly",t=>{for(const n of s){const s=m(st(n),null);r(s);try{$t(e,s,e.staticDependency,e.dynamicDependency,e.listPaths,t,"new",r)}catch{}}}),0===i.length)return;const n=function(t){const e=[],s=[];for(const n of t)oe.has(n.bindingType)?e.push(n):s.push(n);return e.sort((t,e)=>0!==(t.replaceNode.compareDocumentPosition(e.replaceNode)&Node.DOCUMENT_POSITION_FOLLOWING)?-1:1),e.concat(s)}(i),a=()=>{j(n,void 0,{updatedCallback:!1})};if(t())return void a();const o=L("state",a);void 0!==o&&o.catch(T)}finally{H()}}const le=[[_t,"watch"],[yt,"scan"],[bt,"streams"],[kt,"recursion"]];class de extends ie{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return M(t)}static get observedAttributes(){return["mount"]}__state;_hasUpdatedCallback=!1;_hasErrorCallback=!1;_hydratedFromSsr=!1;_crossRowListPaths=new Set;_indexDependentGetterPaths=new Set;_initialized=!1;_initializeFailed=!1;_initializationLanded=!1;_initializePromise;_resolveInitialize=null;_connectedCallbackPromise;_resolveConnectedCallback=null;_rejectConnectedCallback=null;_loadingPromise;_resolveLoading=null;_setStatePromise=null;_resolveSetState=null;_listPaths=new Set;_listKeys=null;_recursionRegistry=null;_elementPaths=new Set;_getterPaths=new Set;_setterPaths=new Set;_loopContextStack=function(){return new Xt}();_dynamicDependency=new Map;_staticDependency=new Map;_pathSet=new Set;_stateGeneration=0;_pathRegistrations=new Map;_pendingReapplyPaths=null;_generatedPaths=new Set;_watchPaths=null;_scanPaths=null;_version=0;_rootNode=null;_boundComponent=null;_boundComponentStateProp=null;_hasMounts=!1;_hasGraftedVolumes=!1;_addressHooks=null;_bindableEventMap={};_commandTokenNames=new Set;_eventTokenNames=new Set;_treeless=!1;_connectGeneration=0;constructor(){super(),this._initializePromise=new Promise(t=>{this._resolveInitialize=t}),this._connectedCallbackPromise=new Promise((t,e)=>{this._resolveConnectedCallback=t,this._rejectConnectedCallback=e}),this._loadingPromise=new Promise(t=>{this._resolveLoading=t}),this._setStatePromise=new Promise(t=>{this._resolveSetState=t})}get _state(){return void 0===this.__state&&p(`${e.tagNames.state} _state is not initialized yet.`),this.__state}set _state(t){wt(t),function(t){for(let e=0;e<le.length;e++){const[s,n]=le[e];s in t&&!Bt(n)&&p(V(n,`"${s}"`))}}(t);const e=this.__state,s=qt();s.set("previousState",e),Ot(this,t,s);const n=function(t){const e=new Set,s=t[B];if(void 0===s)return e;Array.isArray(s)||p(`${B} must be an array of strings.`);for(const t of s)"string"==typeof t&&0!==t.length||p(`${B} entries must be non-empty strings.`),t===J&&p(`${B} entry "${t}" conflicts with the reserved namespace name "${J}".`),e.has(t)&&p(`${B} entry "${t}" is duplicated.`),e.add(t);return e}(t),a=function(t){const e=new Set,s=t[Q];if(void 0===s)return e;Array.isArray(s)||p(`${Q} must be an array of strings.`);for(const t of s)"string"==typeof t&&0!==t.length||p(`${Q} entries must be non-empty strings.`),e.has(t)&&p(`${Q} entry "${t}" is duplicated.`),e.add(t);return e}(t),i=function(t){const e=t[Y];if(void 0===e)return null;"object"==typeof e&&null!==e||p(`${Y} must be an object mapping list paths to key specs.`);const s=new Map;for(const[t,n]of Object.entries(e)){0===t.length&&p(`${Y} entry path must be a non-empty string.`);const e=t.split(Z);e.some(t=>0===t.length)&&p(`${Y} entry "${t}" must not contain empty path segments.`),e[e.length-1]===tt&&p(`${Y} entry "${t}" must be the list path itself, not the element path (drop the trailing "${Z}${tt}").`),-1!==t.indexOf(et)&&p(`[wcs/recursion-unsupported] ${Y} entry "${t}" uses "${et}", which ${Y} does not interpret — a keyed list is one concrete list path. Declare the key per depth instead (for example "nodes${Z}${tt}${Z}children").`),"function"!=typeof n?("string"!=typeof n&&p(`${Y} entry "${t}" key spec must be a field name (string) or a function.`),0===n.length&&p(`${Y} entry "${t}" key field name must be a non-empty string.`),(n.includes(Z)||n.includes(tt))&&p(`${Y} entry "${t}" key field name "${n}" must be a flat property name ("${Z}" / "${tt}" are not allowed).`),n in Object.prototype&&p(`${Y} entry "${t}" key field name "${n}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`),s.set(t,n)):s.set(t,n)}return s.size>0?s:null}(t);s.set("eventTokenNames",a),Gt(this,t,s),Mt(this,t,s),this._commandTokenNames=n,this._eventTokenNames=a,this._stateGeneration++,this.__state=t,void 0!==e&&Qt?.reset(this),this._hasUpdatedCallback=ot in t,this._hasErrorCallback=rt in t,U(this),Ut(this,t,s),function(t,e,s){const n=e[X];if(void 0!==n){"object"==typeof n&&null!==n||p(`${X} must be an object mapping event-token names to handler functions.`);for(const[e,a]of Object.entries(n))s.has(e)||p(`${X} entry "${e}" is not declared in $eventTokens.${f(e,s)}`),"function"!=typeof a&&p(`${X} entry "${e}" must be a function.`),_(t,e).subscribe(a)}}(this,t,this._eventTokenNames),this._listPaths.clear(),this._elementPaths.clear(),this._getterPaths.clear(),this._setterPaths.clear(),this._pathSet.clear();const o=function(t){const e=new Set,s=new Set,n=jt(t);for(const[t,a]of Object.entries(n))"function"==typeof a.get&&e.add(t),"function"==typeof a.set&&s.add(t);return{getterPaths:e,setterPaths:s}}(t);for(const t of o.getterPaths)this._getterPaths.add(t);for(const t of o.setterPaths)this._setterPaths.add(t);Ft(this,t,s),this._listKeys=i,this._rebuildPathInfo(),Wt(this,t,s),Kt(this,null),this._resolveLoading?.()}attributeChangedCallback(t,s,n){this._initialized&&s!==n&&console.warn(`[@wcstack/state] Changing the "mount" attribute after initialization is not supported and is ignored (was ${null===s?"absent":`"${s}"`}, now ${null===n?"absent":`"${n}"`}). Remove this <${e.tagNames.state}> element and create a new one with the desired mount path instead.`)}_loadFromSsrElement(){return this.hasAttribute("enable-ssr")?F('the "enable-ssr" attribute').loadState(this):null}async _loadStateFromSource(){if(this.hasAttribute("state")){return function(t){const e=document.getElementById(t);return e&&"application/json"===e.type?JSON.parse(e.textContent||"{}"):(console.warn(`[@wcstack/state] state="${t}": no <script type="application/json" id="${t}"> in the document (3.x does not look inside shadow roots), so the state starts empty.`),{})}(this.getAttribute("state"))}if(!this.hasAttribute("src")){if(this.hasAttribute("json")){const t=this.getAttribute("json");return JSON.parse(t)}{const t=this.querySelector('script[type="module"]');if(t)return await a(t,e.tagNames.state);{const t=setTimeout(()=>{console.warn(`[@wcstack/state] Warning: No state source found for <${e.tagNames.state}> element.`)},pt),s=await this._setStatePromise;return clearTimeout(t),s}}}{const t=this.getAttribute("src");if(t&&t.endsWith(".json"))return await async function(t){let e;try{const s=await fetch(t);if(s.ok)return await s.json();e=`HTTP ${s.status} ${s.statusText}`}catch(t){e=t}return console.error(`[@wcstack/state] Failed to load JSON file "${t}", so the state starts empty (4.0 rejects instead):`,e),{}}(t);if(t&&t.endsWith(".js"))return await n(t);p(`Unsupported src file type: ${t}`)}}async _initialize(){const e=t()?null:this._loadFromSsrElement();if(null!==e&&(this._hydratedFromSsr=!0),this._state=await this._loadStateFromSource(),null!==e&&this.__state)for(const[t,s]of Object.entries(e)){if(t in this.__state){const e=Object.getOwnPropertyDescriptor(this.__state,t);if(e&&(e.get||e.set))continue;if("function"==typeof this.__state[t])continue}this.__state[t]=s}return await this._loadingPromise,null!==this._rootNode&&(W(this._rootNode,this),!0)}_failInitialization(t){this._initializationLanded=!0,this._resolveInitialize?.(),this._resolveLoading?.(),this._resolveConnectedCallback?.(),p(t)}_failInitializeLoudly(t,s=!0){if(this._initializationLanded)throw t;this._initializeFailed=!0;const n=["state","src"].find(t=>this.hasAttribute(t));throw console.error(`[@wcstack/state] <${e.tagNames.state}${n?` ${n}="${this.getAttribute(n)}"`:""}> failed to initialize.`,t),this._resolveInitialize?.(),this._resolveLoading?.(),this._connectedCallbackPromise.catch(()=>{}),this._rejectConnectedCallback?.(t),s&&null!==this._rootNode&&null===R(this._rootNode)&&(K(this._rootNode,t),i(this,this._rootNode,t)),t}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{at in t&&await t[N]()})}_callStateDisconnectedCallback(){this.createState("writable",t=>{it in t&&t[A]()})}async connectedCallback(){this._rootNode=this.getRootNode();const n=++this._connectGeneration;if(this._initializationLanded=!1,this._initialized){if(d(this))return void this._resolveConnectedCallback?.();this._treeless||R(this._rootNode)===this||W(this._rootNode,this)}else{this.hasAttribute("name")&&this._failInitialization(this.hasAttribute("mount")?'"mount" replaces "name" — a volume has no name of its own. Remove the name attribute.':`The "name" attribute was removed in v2 — there is a single state tree per root. Mount this state onto the tree instead: <wcs-state mount="${this.getAttribute("name")}" ...> and read it as "${this.getAttribute("name")}.<path>".`);const t=o(this);if(null!==t)return void await t;if(this.hasAttribute("mount"))try{r("scopes",'the "mount" attribute')}catch(t){this._failInitializeLoudly(t,!1)}const s=this.parentNode;if(s instanceof ShadowRoot&&s.host.hasAttribute(ft))try{r("dcc",`a <${e.tagNames.state}> inside a [${ft}] host`)}catch(t){this._failInitializeLoudly(t)}let n=!1;try{const t=l(this);null===t&&this.hasAttribute("bind-component")&&r("scopes",'the "bind-component" attribute'),n=await(t??!1)}catch(t){this._failInitializeLoudly(t)}if(n)return;let a=!1;try{a=await this._initialize()}catch(t){this._failInitializeLoudly(t)}if(!a)return;this._initialized=!0,this._resolveInitialize?.()}if(null!==this._pendingReapplyPaths){const t=this._pendingReapplyPaths;this._pendingReapplyPaths=null,this._reapplyBindings(t)}if(this.hasAttribute("enable-ssr")&&!t()||n!==this._connectGeneration||await this._callStateConnectedCallback(),t()&&this.hasAttribute("enable-ssr")&&!s())try{await F('the "enable-ssr" attribute').emitSnapshot(this)}catch(t){throw this._rejectConnectedCallback?.(t),t}Kt(this,n),this._resolveConnectedCallback?.()}disconnectedCallback(){if(!c(this)&&null!==this._rootNode){if(!this._initialized)return this._initializeFailed&&h(this,this._rootNode),void(this._rootNode=null);try{this._callStateDisconnectedCallback()}finally{W(this.rootNode,null),Dt(this),Vt(this),this._rootNode=null}}}get initialized(){return this._initialized}get connectedRootNode(){return this._rootNode}clearConnectedRootNode(){this._rootNode=null}markInitialized(){this._initialized=!0}settleInitialization(){this._resolveInitialize?.(),this._resolveLoading?.(),this._resolveConnectedCallback?.()}loadStateFromSource(){return this._loadStateFromSource().then(t=>(wt(t),t))}markTreeless(){this._treeless=!0}failInitializeLoudly(t){return this._failInitializeLoudly(t)}get connectGeneration(){return this._connectGeneration}setWatchPaths(t){this._watchPaths=t}setScanPaths(t){this._scanPaths=t}landInitialization(){this._initializationLanded=!0,this._resolveInitialize?.(),this._resolveLoading?.(),this._resolveConnectedCallback?.()}setRecursionRegistry(t){this._recursionRegistry=t}addGeneratedPath(t){this._generatedPaths.add(t)}setBoundComponent(t,e){this._boundComponent=t,this._boundComponentStateProp=e}get initializePromise(){return this._initializePromise}get connectedCallbackPromise(){return this._connectedCallbackPromise}get listPaths(){return this._listPaths}get listKeys(){return this._listKeys}get hasRecursion(){return null!==this._recursionRegistry}get recursionRegistry(){return this._recursionRegistry}get watchPaths(){return this._watchPaths}get scanPaths(){return this._scanPaths}get elementPaths(){return this._elementPaths}addVolumeWatchPaths(t){if(0===t.size)return;const e=new Set(this._watchPaths??[]);for(const s of t)e.add(s);this._watchPaths=e,this.attachAddressHooks("watch",_t)}mergeVolumeListKeys(t){if(0===t.size)return;const e=new Map(this._listKeys??[]);for(const[s,n]of t)e.has(s)&&p(`$listKeys entry "${s}" is declared by both the root and a volume (or two volumes). Keep exactly one.`),e.set(s,n);this._listKeys=e}enableUpdatedCallback(){this._hasUpdatedCallback=!0}get hydratedFromSsr(){return this._hydratedFromSsr}addListPath(t){this._listPaths.add(t)}findStateDescriptor(t){return mt(this._state,t)}defineTreeAccessor(t,e){Object.defineProperty(this._state,t,e),"function"==typeof e.get&&this._getterPaths.add(t),"function"==typeof e.set&&this._setterPaths.add(t),this.setPathInfo(t,"prop","internal")}get getterPaths(){return this._getterPaths}get setterPaths(){return this._setterPaths}get loopContextStack(){return this._loopContextStack}get dynamicDependency(){return this._dynamicDependency}get staticDependency(){return this._staticDependency}get version(){return this._version}get stateGeneration(){return this._stateGeneration}get rootNode(){return null===this._rootNode&&p("State rootNode is not available."),this._rootNode}get boundComponentStateProp(){return this._boundComponentStateProp}get hasMounts(){return this._hasMounts}markHasMounts(){this._hasMounts=!0,this._attachScopeHooks("bind-component")}get hasGraftedVolumes(){return this._hasGraftedVolumes}get addressHooks(){return this._addressHooks}attachAddressHooks(t,e){const s=Lt(t,e);null===this._addressHooks&&(this._addressHooks=Tt()),Ht(this._addressHooks,s)}markHasGraftedVolumes(){this._hasGraftedVolumes=!0,this._attachScopeHooks("mount")}markHasVolume(){this._attachScopeHooks("mount")}_attachScopeHooks(t){this.attachAddressHooks("scopes",t)}get bindableEventMap(){return this._bindableEventMap}get commandTokenNames(){return this._commandTokenNames}get eventTokenNames(){return this._eventTokenNames}setBindableEventMap(t){this._bindableEventMap=t,this.attachAddressHooks("dcc",gt)}_addDependency(t,e,s){const n=t.get(e);return void 0===n?(t.set(e,[s]),!0):!n.includes(s)&&(n.push(s),!0)}addDynamicDependency(t,e){if(!this._addDependency(this._dynamicDependency,t,e))return!1;const s=st(t);for(let t=s.parentPathInfo;null!==t&&t.wildcardCount>0&&t.wildcardCount===s.wildcardCount;t=t.parentPathInfo)this._addDependency(this._dynamicDependency,t.path,e);return!0}addStaticDependency(t,e){return this._addDependency(this._staticDependency,t,e)}setPathInfo(t,e,s="binding"){if("internal"!==s){const n=this._pathRegistrations.get(t);void 0===n?this._pathRegistrations.set(t,{bindingType:e,bound:"binding"===s}):"for"!==n.bindingType&&this._pathRegistrations.set(t,{bindingType:e,bound:n.bound||"binding"===s})}if("for"===e&&(this._listPaths.add(t),this._elementPaths.add(t+"."+tt)),!this._pathSet.has(t)){const e=st(t);this._pathSet.add(t);const n=function(t,e){const s=Jt(e);return"all"===s.wildcardType&&1===s.wildcardIndexes.length&&isNaN(+s.segments[0])&&!e.includes("#")&&Object.isExtensible(t)&&!(e in t)}(this.__state,t);if(Qt?.check(this,this.__state,t,s,n),n&&function(t,e){const{segments:s,cumulativePaths:n}=st(e),a=s.length-1,i=(t,i,o)=>{let r,l=!1;for(let d=0;d<=a;d++){const c=s[d];if(l||=!(isNaN(+c)||Array.isArray(r)&&+c in r),i&&d===a)return l?r[c]=o:t[e]=o;r=l?r?.[c]:t[n[d]]}return r},o=function(){return i(this)};nt.set(o,Jt(e).pathInfo.path),t.defineTreeAccessor(e,{get:o,set(t){i(this,!0,t)},configurable:!0})}(this,t),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=st(t.parentPath)}}}_rebuildPathInfo(){for(const[t,e]of Array.from(this._pathRegistrations))e.bound&&!this._generatedPaths.has(t)&&this.setPathInfo(t,e.bindingType)}_createState(t,e,s){try{const n=function(t,e,s){const n=new ae(t,s);return new Proxy(e,n)}(t,this._state,e);return s(n)}finally{}}async createStateAsync(t,e){return await this._createState(this.rootNode,t,e)}createState(t,e){this._createState(this.rootNode,t,e)}nextVersion(){return this._version++,this._version}get hasUpdatedCallback(){return this._hasUpdatedCallback}get hasErrorCallback(){return this._hasErrorCallback}get crossRowListPaths(){return this._crossRowListPaths}addCrossRowListPath(t){this._crossRowListPaths.add(t)}get indexDependentGetterPaths(){return this._indexDependentGetterPaths}addIndexDependentGetterPath(t){this._indexDependentGetterPaths.add(t)}setInitialState(t){if(!this._initialized)return this._initializeFailed&&p(`<${e.tagNames.state}> failed to initialize (the diagnostic was reported when it connected), so its state cannot be replaced. Remove this element and create a new one with the corrected state.`),void this._resolveSetState?.(t);u(this),(this._hasGraftedVolumes||this._hasMounts)&&p("Cannot replace the whole state of a tree that has grafted volumes or mounted components: re-setting would silently drop grafted data, tree accessors and mount ledgers (D22). Write the changed paths instead.");const s=this.__state;this._state=t;const n=function(t){const e=new Set;for(const s of t)if(void 0!==s)for(const[t,n]of Object.entries(jt(s)))t.startsWith("$")||t.includes(tt)||"function"==typeof n.value||e.add(t);return e}([s,t]);null!==this._rootNode?this._reapplyBindings(n):this._pendingReapplyPaths=new Set([...this._pendingReapplyPaths??[],...n])}_reapplyBindings(t){re(this,t,this._pathRegistrations.keys())}}const ce=[],he=[];function ue(){const t=[];let e=0;for(let s=0;s<he.length;s++){const n=he[s].deref();void 0!==n&&(t.push(n),he[e++]=he[s])}return he.length=e,t}function pe(t){if(!ce.includes(t)){ce.push(t);for(const e of ue())t(e)}}function fe(t=customElements){ue().includes(t)||he.push(new WeakRef(t));for(let e=0;e<ce.length;e++)ce[e](t);t.get(e.tagNames.state)||t.define(e.tagNames.state,de)}export{ie as H,pe as a,fe as r};
|
|
2
2
|
//# sourceMappingURL=registerComponents.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{W as t,w as e,F as n,G as s,g as a,q as o,D as l,d as r,H as i,J as d,t as c,K as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aO as h,l as p,aP as g,aQ as I,aR as y,j as w,m as x,aS as m,M as P,O as b,N as v,aT as A,aU as $,au as k,aV as R,h as E,k as S,aW as M,aX as j,aY as O,aZ as C,a_ as D,a$ as L,b0 as q,b1 as V,ah as T,b2 as B,b3 as H,a0 as W,b4 as z,b5 as G,b6 as N,b7 as U,b8 as K,b9 as F,ba as J,bb as Q,p as X,bc as Y,bd as Z,be as _,bf as tt,bg as et,c as nt,bh as st,bi as at,a1 as ot,bj as lt,o as rt}from"./binder.js";import{c as it,a as dt}from"./checkDependency.js";import{N as ct}from"./getAllPropertyDescriptors.js";import{c as ft}from"./filterRegistry.js";const ut=new WeakMap;function ht(t,e){let n=ut.get(t);void 0===n&&(n=new Map,ut.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const pt=new WeakMap;function gt(t){const e=pt.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return ht(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:ht(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return pt.set(t,n),n}function It(t){pt.delete(t)}function yt(t){"readonly"===t.mutability&&u("This state is readonly.")}function wt(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function xt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==ct)return r}}return ct}function mt(a,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(gt(i),o.pathInfo.segments);if(!(o.pathInfo.path in a)){if(null===o.parentAddress){const t=xt(i,o,null,l,r);if(t!==ct)return t;u(n(o.pathInfo.path,a,i.getterPaths))}const e=At(a,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==t&&!(d in Object(e))){const t=xt(i,o,Object(e),l,r);if(t!==ct)return t}if(d===t){const t=o.listIndex?.index??u(s(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(a,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(a,o.pathInfo.path,l)}finally{r.popAddress()}}function Pt(e,n,s,o,l){const r=p(l,n),i=g(r),d=l.stateGeneration,c=n.pathInfo.lastSegment===t?void 0:I(n.listIndex);if(null!==i&&!1===i.dirty&&i.generation===d&&i.rowStamp===c)return i.value;const f=mt(e,n,s,o,l);"function"!=typeof f&&y(r,{value:f,dirty:!1,generation:d,rowStamp:c});const u=i?.value;return Array.isArray(f)&&f!==u&&l.getterPaths.has(n.pathInfo.path)&&function(t,e,n,s,o,l){const{path:r,wildcardCount:i}=e.pathInfo;l.beginUntrack();try{for(const[d,c]of l.stateElement.dynamicDependency){const f=a(d);if(!c.includes(r)||f.wildcardCount>i)continue;const u=At(t,w(f,x(e.listIndex,f.wildcardCount-1,i)),o,l);u===n?bt.add(e.pathInfo):u===s&&m(n,s)}}finally{l.endUntrack()}}(e,n,f,u,s,o),f}const bt=new WeakSet;function vt(t){return bt.has(t)}function At(t,e,n,s){it(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==ct)return l}}return wt(a,e)?Pt(t,e,n,s,a):mt(t,e,n,s,a)}function $t(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const g=w(h,o),I=p(n.stateElement,g),y=b(I),x=At(t,g,e,n),m=v(o,y,x).newIndexes,P=i[d]??null;if(l.set(I,x),null===P)for(let t=0;t<m.length;t++){const e=m[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=m[P]??u(`ListIndex not found at index ${P} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())P(t,Array.isArray(e)?e:[]);return i}function kt(t,e,n){const s=A(n,e.listIndex);if(null!==s)return s;const a=p(t.stateElement,e),o=v(e.listIndex,b(a),n);return P(a,Array.isArray(n)?n:[]),o.newIndexes}function Rt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=w(r,o),d=kt(n,i,At(t,i,e,n)),c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function Et(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function St(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function Mt(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];Et(i,n,s,r);const d=St(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function jt(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function Ot(e,n,s,a){if(n.pathInfo.path in e)return!0;const o=n.parentAddress;if(null===o)return!1;const l=At(e,o,s,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=n.pathInfo.lastSegment;if(r===t){const t=n.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const Ct=new WeakMap;function Dt(t){return Ct.get(t)??null}function Lt(t,e){null===e?Ct.delete(t):($(e.listIndexes),Ct.set(t,e))}function qt(t,e,n){const s=t.wildcardParentPaths[e],o=a(s),l=w(o,n),r=p(t.stateElement,l),i=b(r),d=t.stateProxy[E](l),c=v(l.listIndex,i,d);t.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return ft.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...f);else for(const n of f)qt(t,e+1,n)}function Vt(t,e,n,s){n?t.result.has(e)||t.quiet.add(e):t.quiet.delete(e),t.result.add(e),s.push(e)}const Tt=[];function Bt(t,e,n){return"full"!==t.listExpansion&&t.listPathSet.has(e)?t.stateElement.crossRowListPaths?.has(e)?{fullRows:n.newIndexes,movedRows:null}:0===n.addIndexSet.size&&0===n.changeIndexSet.size?0===n.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:Tt,movedRows:null}:{fullRows:n.newIndexes,movedRows:null}:{fullRows:Tt,movedRows:null}:{fullRows:n.addIndexSet,movedRows:n.changeIndexSet}:{fullRows:n.newIndexes,movedRows:null}}const Ht=[];function Wt(t,e,n){const s=t.stateElement.indexDependentGetterPaths;if(!s||0===s.size)return Ht;let o=null;const r=e+l;for(const t of s){if(t!==e&&!t.startsWith(r))continue;const s=a(t);if(s.wildcardCount!==n.wildcardCount)return null;(o??=[]).push(s)}return o??Ht}function zt(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),t.quiet.has(r)?k(p(t.stateElement,r)):n(r),l.length=0,Gt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}function Gt(e,n,s){const o=n.pathInfo.path,l=e.quiet.has(n),r=e.staticMap.get(o);if(r)for(const i of r){const r=a(i);if(r.lastSegment===t){const t=e.stateProxy[E](n),a=Array.isArray(t)?t:[],d=p(e.stateElement,n),c=b(d),f=e.listPathSet.has(o);if(!f&&"diff"===e.listExpansion&&(e.keyedMergePath===o||S(a)?.length!==a.length&&!M(c,a)))continue;const u=v(n.listIndex,c,a);e.observedListValueByAbsAddress.set(d,a);const h=Bt(e,o,u);for(const t of h.fullRows)Vt(e,w(r,t),l||!f,s);for(const t of u.valueChangeIndexes??Tt)Vt(e,w(r,t),l||!f,s);if(null!==h.movedRows){const t=Wt(e,i,r);if(null===t)for(const t of h.movedRows)Vt(e,w(r,t),l,s);else if(t.length>0)for(const n of h.movedRows)for(const a of t)Vt(e,w(a,n),l,s)}}else Vt(e,w(r,n.listIndex),l,s)}const i=e.dynamicMap.get(o);if(i)for(const t of i){const o=a(t),r=[];if(o.wildcardCount>0){const t=j(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=x(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};qt(a,t,s),r.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=x(n.listIndex,t-1,n.pathInfo.wildcardCount);r.push(e)}}else r.push(null);for(const t of r)Vt(e,w(o,t),l,s)}}function Nt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null,quiet:new Set};zt(f,e,r),function(t,e){for(let n=0;n<1e3;n++){const n=R(t.stateElement);if(null===n)return;n.forEach(n=>{zt(t,w(n.absolutePathInfo.pathInfo,n.listIndex),e)})}}(f,r);for(const[t,e]of f.observedListValueByAbsAddress)P(t,e);return Array.from(f.result)}function Ut(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function Kt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Ft(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Jt(t,e,n,s,a,o){const l=D(t,e),r=L(t,e);if(!l&&!r)return null;const i=[],d=Xt(i);return l&&q(t,e,n,s,a).forEach(d),r&&V(t,e,n?s:o(),a).forEach(d),i}function Qt(){return ft.enablePropagationContext?K()??null:null}function Xt(t){const e=nt(),n=Qt();return s=>{k(s),e.enqueueAbsoluteAddress(s,n),t.push(s)}}function Yt(t,e,n){if(null===t||0===t.length)return;const s=n.stateElement,a=s.staticDependency,o=s.dynamicDependency,l=nt(),r=Qt();for(let n=0;n<t.length;n++){const i=t[n].absolutePathInfo,d=i.pathInfo.path;if(!a.has(d)&&!o.has(d))continue;const c=w(i.pathInfo,t[n].listIndex);Nt(s,c,a,o,s.listPaths,e,"new",t=>{if(t===c)return;const e=p(s,t);k(e),l.enqueueAbsoluteAddress(e,r)},{listExpansion:"diff"})}}function Zt(t,e,n,s,a){const o=D(t,e),l=L(t,e);if(!o&&!l)return;const r=n(),i=[],d=Xt(i);o&&q(t,e,!1,void 0,r).forEach(d),l&&V(t,e,void 0,r,!1).forEach(d),Yt(i,s,a)}function _t(e,n,s,o,r,i,d="diff"){const c=ft.enablePropagationContext?K()??F(-1):null,f=nt(),u=o.stateElement;f.enqueueAbsoluteAddress(n,c),i&&k(n);const h=t=>Nt(u,t,u.staticDependency,u.dynamicDependency,u.listPaths,s,"new",t=>{if(t===e)return;const n=p(u,t);k(n),f.enqueueAbsoluteAddress(n,c)},{listExpansion:d,keyedMergePath:r});if(h(e),e.pathInfo.lastSegment!==t&&null!==e.listIndex&&null!==e.listIndex.parentListIndex){const n=e.listIndex,o=e.pathInfo.wildcardParentPathInfos[n.position],r=w(o,n.parentListIndex),i=()=>s[E](r),d=t=>{k(t),f.enqueueRenderOnlyAddress(t)};for(const t of J(n,i))d(p(u,w(e.pathInfo,t)));const c=e.pathInfo.path.slice(e.pathInfo.wildcardPaths[n.position].length);for(const e of Q(p(u,r),i())){const s=e.absolutePathInfo.pathInfo;s!==o&&s.wildcardCount===o.wildcardCount&&d(X(u,a(s.path+l+t+c),n))}}const{path:g,lastSegment:I,wildcardCount:y,wildcardParentPaths:m,wildcardParentPathInfos:P}=e.pathInfo,b=e.listIndex;for(let e=0;b&&e<y;e++){const n=x(b,e-1,y);for(const o of u.dynamicDependency.get(m[e])??[]){const l=a(o);if(u.listPaths.has(o)&&l.wildcardCount===e&&vt(l)&&s[E](w(l,n))===s[E](w(P[e],n))){const n=w(a(o+g.slice(m[e].length)),b);h(n),I===t&&f.enqueueRenderOnlyAddress(p(u,n.parentAddress))}}}}function te(e,n,s,a,o){o&&(e.getterPaths.has(n)?k(s):y(s,{value:a,dirty:!1,generation:e.stateGeneration,rowStamp:s.absolutePathInfo.pathInfo.lastSegment===t?void 0:I(s.listIndex)}))}function ee(e,n,a,o,l,r,i,d,c=!0){try{if(!(n.pathInfo.path in e)){const a=n.parentAddress;if(null===a)return Reflect.set(e,n.pathInfo.path,o);const i=At(e,a,l,r),d=n.pathInfo.segments[n.pathInfo.segments.length-1];if(d===t){const t=n.listIndex?.index??u(s(`path "${n.pathInfo.path}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(n.pathInfo.path))return Reflect.set(e,n.pathInfo.path,o);r.pushAddress(n),r.beginUntrack();try{return Reflect.set(e,n.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{c&&_t(n,a,l,r,i,d)}}function ne(e,n,s,o,r,i,d,c,f){const h=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),g=At(e,h,r,i)??[],I=Dt(g);if(f)return I&&(I.value[n.listIndex.index]=o),Y(n.listIndex,o),ee(e,n,s,o,r,i,d,c);const y=n.listIndex,x=I??{value:[...g],listIndexes:S(g)??[],written:new Map};try{return ee(e,n,s,o,r,i,d,c,!1)}finally{const e=function(t,e,n){const{value:s,listIndexes:a}=t,o=new Map;a.forEach((t,n)=>{if(e[n]!==s[n]){const e=o.get(s[n]);e?e.push(t):o.set(s[n],[t])}});let l,r=0;const i=[];for(let t=0;t<a.length;t++){const n=e[t]===s[t]?a[t]:o.get(e[t])?.shift();if(!n&&(r++?(l??=new Set(s)).has(e[t]):s.includes(e[t])))return null;i.push(n)}return i.map((t,e)=>t??T(n,e))}(x,g,h.listIndex);if(null===e)Lt(g,x),Y(y,o),x.written.set(y,Z),_(y),_t(n,s,r,i,d,c);else{Lt(g,null);const n=[y.index];tt(y),x.written.forEach((t,e)=>{tt(e),Y(e,x.value[e.index]),t===Z&&n.push(e.index)}),x.written.delete(y),e.forEach((t,e)=>{t.index=e}),W(g,e),N(x.listIndexes,e),function(e,n,s,o,r,i,d){const c=i.stateElement,f=nt(),u=p(c,e);W(n.value,n.listIndexes),st(n.value),z(s,n.value),at(u)===s&&ot(u,n.value);f.enqueueRenderOnlyAddress(u);for(const t of Q(u,s))lt(t,s)&&f.enqueueRenderOnlyAddress(t);const h=new Map;n.listIndexes.forEach((t,e)=>h.set(t,e));const g=a(e.pathInfo.path+l+t);for(let t=0;t<o.length;t++){const e=o[t],s=h.get(e);if(s===t)continue;const a=w(g,e),l=p(c,a);if(void 0===s){const e=X(c,g,n.listIndexes[t]);Ft(c,l,e),_t(a,l,r,i,null,wt(c,a),"full");continue}Nt(c,a,c.staticDependency,c.dynamicDependency,c.listPaths,r,"new",t=>{const e=p(c,t);k(e),f.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}for(const t of d){const e=o[t];if(h.has(e)&&n.written.get(e)!==Z){const s=w(g,e),a=p(c,s);Ft(c,a,X(c,g,n.listIndexes[t])),_t(s,a,r,i,null,wt(c,s))}}}(h,x,g,e,r,i,n)}}}function se(e,n,s,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(s)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=At(e,n,o,r),c=function(t,e,n,s){const a=Mt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=Mt(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,s);if(null!==c)return function(e,n,s,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===S(o)&&v(c,null,o);const f=v(c,o,s.list),u=ae(e,n,s.list,r,i,d),h=a(d+l+t);for(const t of s.matched){const n=jt(t.oldRow,t.newRow);if(0===n.length)continue;const s=f.newIndexes[t.position];for(const o of n){if(void 0===s){t.oldRow[o.field]=o.value;continue}const n=a(h.path+l+o.field);se(e,w(n,s),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return ae(e,n,s,o,r,null)}function ae(e,n,a,o,l,i){const d=l.stateElement,c=n.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let e=0;e<t.length;e++){const s=t[e](d,n,a,o,l);if(s!==ct)return s}}const h=et(),g=h>1;if(!(c in e)&&null!==n.parentAddress&&!d.elementPaths.has(c)){const h=At(e,n.parentAddress,o,l);if("object"==typeof h&&null!==h){const e=n.pathInfo.lastSegment,I=e===t?n.listIndex?.index:e;let y,x=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=void 0!==I&&I in h,e=void 0!==I?h[I]:void 0;if(t&&Object.is(e,a))return!0;y=e,x=!0}e===t&&(n=function(t,e,n,s,a){const o=e.listIndex,l=S(n);if(l?.[s]!==o||n[s]===a)return e;const r=T(o.parentListIndex,s,B(o));if(H(n)){const t=Dt(n)??{value:n.slice(),listIndexes:l};W(t.value,t.listIndexes),z(n,t.value)}const i=G(l)?l:l.slice();i[s]=r,W(n,i,!0),N(l,i),U([o]);const d=w(e.pathInfo,r);return Ft(t,p(t,d),p(t,e)),d}(d,n,h,I,a));const P=Jt(d,c,x,y,a,()=>h[I]),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:y,hasOldValue:x}),Ut(d,c,v,y,x);let A=!1;try{if(void 0===I&&u(s(`path "${c}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0)),f&&0!==f.writeMissing.length&&e!==t&&!(I in h)){const t=f.writeMissing;for(let e=0;e<t.length;e++){A=!0;const s=t[e](d,n,h,I,a,o,l);if(s!==ct)return s;A=!1}}if(e!==t&&null!==n.listIndex){const t=h[I];t!==a&&(O(t,n.listIndex,h,e)&&Array.isArray(a)&&m(a,t),C(a,n.listIndex))}return Reflect.set(h,I,a)}finally{_t(n,v,o,l,i,b),Yt(P,o,l),A?k(v):te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}}let I,y=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=At(e,n,o,l);if(Ot(e,n,o,l)&&Object.is(t,a))return!0;I=t,y=!0}const x=Jt(d,c,y,I,a,()=>At(e,n,o,l)),P=d.elementPaths.has(n.pathInfo.path),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:I,hasOldValue:y}),Ut(d,c,v,I,y);try{return P?ne(e,n,v,a,o,l,i,b,h):ee(e,n,v,a,o,l,i,b)}finally{Yt(x,o,l),P||te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}function oe(t,e,n,s){return(e,o,...l)=>{Array.isArray(o)||u(`$resolve("${e}") requires an explicit indexes array (pass [] when the path has no wildcards) — got `+(null===o?"null":typeof o)+"."),l.length>1&&u(`$resolve("${e}") takes 2 arguments to read and 3 to write (path, indexes, value) — got ${2+l.length}.`);const r=a(e);if(s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",e,r.wildcardParentPathInfos.length,o.length));const d=Rt(t,n,s,r,o),c=w(r,d);if(0===l.length)return At(t,c,n,s);yt(s),se(t,c,l[0],n,s)}}function le(t,e,n,s){const o=oe(t,0,n,s);return(e,l)=>{const r=a(e);if(void 0===l||Array.isArray(l)||u(`$getAll("${e}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",e,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=dt(s,r.wildcardPaths[t]);if(e){l=rt(e,e.length);break}}if(void 0===l){const t=s.addressStackLength>0?s.lastAddressStack:null,n=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==n&&n.length>0&&u(d(e,t.pathInfo.path)),l=[]}}const c=$t(t,n,s,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function re(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":{const t=a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`);return dt(s,t)??u(`ListIndex not found: ${e.pathInfo.path}`)}case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=w(l,a),i=kt(s,r,At(t,r,n,s)),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function ie(e,n,s,o){return(n,l,r,d)=>{yt(o);const h=a(n);Array.isArray(l)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),l.length>h.wildcardParentPathInfos.length&&u(i("$setAll",n,h.wildcardParentPathInfos.length,l.length));const p=!0===d?.spread,g="function"==typeof r;p&&g&&u(c(n,"cannot combine { spread: true } with a mapper function.")),p&&!Array.isArray(r)&&u(c(n,"requires an array as the value when { spread: true } is set."));const I=$t(e,s,o,h,l,{commitDiffBaseline:!1});p&&r.length!==I.length&&u(f(n,I.length,r.length));const y=[];for(let t=0;t<I.length;t++){const n=Rt(e,s,o,h,I[t]);y.push(w(h,n))}const x=h.lastSegment===t;let m=0;for(let t=0;t<y.length;t++){const n=x?w(h,Rt(e,s,o,h,I[t])):y[t];let a;if(g){a=r(At(e,n,s,o),...I[t])}else a=p?r[t]:r;void 0!==a&&(se(e,n,a,s,o),m++)}return m}}export{yt as a,le as b,ie as c,re as d,gt as e,It as f,At as g,Ot as h,Zt as n,oe as r,se as s,Nt as w};
|
|
1
|
+
import{W as t,w as e,F as n,G as s,g as a,q as o,D as l,d as r,H as i,J as d,t as c,K as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aP as h,l as p,aQ as g,aR as I,aS as y,j as w,m as x,aT as m,N as P,P as b,O as v,aU as A,aV as $,av as k,aW as R,h as E,k as S,aX as j,aY as M,aZ as C,a_ as O,a$ as D,b0 as L,b1 as q,b2 as V,aj as T,b3 as B,b4 as H,a2 as W,b5 as z,b6 as G,b7 as N,b8 as U,b9 as K,ba as F,bb as J,bc as Q,p as X,bd as Y,be as Z,bf as _,bg as tt,bh as et,c as nt,bi as st,bj as at,a3 as ot,bk as lt,o as rt}from"./binder.js";import{c as it,a as dt}from"./checkDependency.js";import{N as ct}from"./getAllPropertyDescriptors.js";import{c as ft}from"./filterRegistry.js";const ut=new WeakMap;function ht(t,e){let n=ut.get(t);void 0===n&&(n=new Map,ut.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const pt=new WeakMap;function gt(t){const e=pt.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return ht(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:ht(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return pt.set(t,n),n}function It(t){pt.delete(t)}function yt(t){"readonly"===t.mutability&&u("This state is readonly.")}function wt(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function xt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==ct)return r}}return ct}function mt(a,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(gt(i),o.pathInfo.segments);if(!(o.pathInfo.path in a)){if(null===o.parentAddress){const t=xt(i,o,null,l,r);if(t!==ct)return t;u(n(o.pathInfo.path,a,i.getterPaths))}const e=At(a,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==t&&!(d in Object(e))){const t=xt(i,o,Object(e),l,r);if(t!==ct)return t}if(d===t){const t=o.listIndex?.index??u(s(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(a,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(a,o.pathInfo.path,l)}finally{r.popAddress()}}function Pt(e,n,s,o,l){const r=p(l,n),i=g(r),d=l.stateGeneration,c=n.pathInfo.lastSegment===t?void 0:I(n.listIndex);if(null!==i&&!1===i.dirty&&i.generation===d&&i.rowStamp===c)return i.value;const f=mt(e,n,s,o,l);"function"!=typeof f&&y(r,{value:f,dirty:!1,generation:d,rowStamp:c});const u=i?.value;return Array.isArray(f)&&f!==u&&l.getterPaths.has(n.pathInfo.path)&&function(t,e,n,s,o,l){const{path:r,wildcardCount:i}=e.pathInfo;l.beginUntrack();try{for(const[d,c]of l.stateElement.dynamicDependency){const f=a(d);if(!c.includes(r)||f.wildcardCount>i)continue;const u=At(t,w(f,x(e.listIndex,f.wildcardCount-1,i)),o,l);u===n?bt.add(e.pathInfo):u===s&&m(n,s)}}finally{l.endUntrack()}}(e,n,f,u,s,o),f}const bt=new WeakSet;function vt(t){return bt.has(t)}function At(t,e,n,s){it(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==ct)return l}}return wt(a,e)?Pt(t,e,n,s,a):mt(t,e,n,s,a)}function $t(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const g=w(h,o),I=p(n.stateElement,g),y=b(I),x=At(t,g,e,n),m=v(o,y,x).newIndexes,P=i[d]??null;if(l.set(I,x),null===P)for(let t=0;t<m.length;t++){const e=m[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=m[P]??u(`ListIndex not found at index ${P} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())P(t,Array.isArray(e)?e:[]);return i}function kt(t,e,n){const s=A(n,e.listIndex);if(null!==s)return s;const a=p(t.stateElement,e),o=v(e.listIndex,b(a),n);return P(a,Array.isArray(n)?n:[]),o.newIndexes}function Rt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=w(r,o),d=kt(n,i,At(t,i,e,n)),c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function Et(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function St(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function jt(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];Et(i,n,s,r);const d=St(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function Mt(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function Ct(e,n,s,a){if(n.pathInfo.path in e)return!0;const o=n.parentAddress;if(null===o)return!1;const l=At(e,o,s,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=n.pathInfo.lastSegment;if(r===t){const t=n.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const Ot=new WeakMap;function Dt(t){return Ot.get(t)??null}function Lt(t,e){null===e?Ot.delete(t):($(e.listIndexes),Ot.set(t,e))}function qt(t,e,n){const s=t.wildcardParentPaths[e],o=a(s),l=w(o,n),r=p(t.stateElement,l),i=b(r),d=t.stateProxy[E](l),c=v(l.listIndex,i,d);t.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return ft.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...f);else for(const n of f)qt(t,e+1,n)}function Vt(t,e,n,s){n?t.result.has(e)||t.quiet.add(e):t.quiet.delete(e),t.result.add(e),s.push(e)}const Tt=[];function Bt(t,e,n){return"full"!==t.listExpansion&&t.listPathSet.has(e)?t.stateElement.crossRowListPaths?.has(e)?{fullRows:n.newIndexes,movedRows:null}:0===n.addIndexSet.size&&0===n.changeIndexSet.size?0===n.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:Tt,movedRows:null}:{fullRows:n.newIndexes,movedRows:null}:{fullRows:Tt,movedRows:null}:{fullRows:n.addIndexSet,movedRows:n.changeIndexSet}:{fullRows:n.newIndexes,movedRows:null}}const Ht=[];function Wt(t,e,n){const s=t.stateElement.indexDependentGetterPaths;if(!s||0===s.size)return Ht;let o=null;const r=e+l;for(const t of s){if(t!==e&&!t.startsWith(r))continue;const s=a(t);if(s.wildcardCount!==n.wildcardCount)return null;(o??=[]).push(s)}return o??Ht}function zt(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),t.quiet.has(r)?k(p(t.stateElement,r)):n(r),l.length=0,Gt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}function Gt(e,n,s){const o=n.pathInfo.path,l=e.quiet.has(n),r=e.staticMap.get(o);if(r)for(const i of r){const r=a(i);if(r.lastSegment===t){const t=e.stateProxy[E](n),a=Array.isArray(t)?t:[],d=p(e.stateElement,n),c=b(d),f=e.listPathSet.has(o);if(!f&&"diff"===e.listExpansion&&(e.keyedMergePath===o||S(a)?.length!==a.length&&!j(c,a)))continue;const u=v(n.listIndex,c,a);e.observedListValueByAbsAddress.set(d,a);const h=Bt(e,o,u);for(const t of h.fullRows)Vt(e,w(r,t),l||!f,s);for(const t of u.valueChangeIndexes??Tt)Vt(e,w(r,t),l||!f,s);if(null!==h.movedRows){const t=Wt(e,i,r);if(null===t)for(const t of h.movedRows)Vt(e,w(r,t),l,s);else if(t.length>0)for(const n of h.movedRows)for(const a of t)Vt(e,w(a,n),l,s)}}else Vt(e,w(r,n.listIndex),l,s)}const i=e.dynamicMap.get(o);if(i)for(const t of i){const o=a(t),r=[];if(o.wildcardCount>0){const t=M(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=x(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};qt(a,t,s),r.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=x(n.listIndex,t-1,n.pathInfo.wildcardCount);r.push(e)}}else r.push(null);for(const t of r)Vt(e,w(o,t),l,s)}}function Nt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null,quiet:new Set};zt(f,e,r),function(t,e){for(let n=0;n<1e3;n++){const n=R(t.stateElement);if(null===n)return;n.forEach(n=>{zt(t,w(n.absolutePathInfo.pathInfo,n.listIndex),e)})}}(f,r);for(const[t,e]of f.observedListValueByAbsAddress)P(t,e);return Array.from(f.result)}function Ut(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function Kt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Ft(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Jt(t,e,n,s,a,o){const l=D(t,e),r=L(t,e);if(!l&&!r)return null;const i=[],d=Xt(i);return l&&q(t,e,n,s,a).forEach(d),r&&V(t,e,n?s:o(),a).forEach(d),i}function Qt(){return ft.enablePropagationContext?K()??null:null}function Xt(t){const e=nt(),n=Qt();return s=>{k(s),e.enqueueAbsoluteAddress(s,n),t.push(s)}}function Yt(t,e,n){if(null===t||0===t.length)return;const s=n.stateElement,a=s.staticDependency,o=s.dynamicDependency,l=nt(),r=Qt();for(let n=0;n<t.length;n++){const i=t[n].absolutePathInfo,d=i.pathInfo.path;if(!a.has(d)&&!o.has(d))continue;const c=w(i.pathInfo,t[n].listIndex);Nt(s,c,a,o,s.listPaths,e,"new",t=>{if(t===c)return;const e=p(s,t);k(e),l.enqueueAbsoluteAddress(e,r)},{listExpansion:"diff"})}}function Zt(t,e,n,s,a){const o=D(t,e),l=L(t,e);if(!o&&!l)return;const r=n(),i=[],d=Xt(i);o&&q(t,e,!1,void 0,r).forEach(d),l&&V(t,e,void 0,r,!1).forEach(d),Yt(i,s,a)}function _t(e,n,s,o,r,i,d="diff"){const c=ft.enablePropagationContext?K()??F(-1):null,f=nt(),u=o.stateElement;f.enqueueAbsoluteAddress(n,c),i&&k(n);const h=t=>Nt(u,t,u.staticDependency,u.dynamicDependency,u.listPaths,s,"new",t=>{if(t===e)return;const n=p(u,t);k(n),f.enqueueAbsoluteAddress(n,c)},{listExpansion:d,keyedMergePath:r});if(h(e),e.pathInfo.lastSegment!==t&&null!==e.listIndex&&null!==e.listIndex.parentListIndex){const n=e.listIndex,o=e.pathInfo.wildcardParentPathInfos[n.position],r=w(o,n.parentListIndex),i=()=>s[E](r),d=t=>{k(t),f.enqueueRenderOnlyAddress(t)};for(const t of J(n,i))d(p(u,w(e.pathInfo,t)));const c=e.pathInfo.path.slice(e.pathInfo.wildcardPaths[n.position].length);for(const e of Q(p(u,r),i())){const s=e.absolutePathInfo.pathInfo;s!==o&&s.wildcardCount===o.wildcardCount&&d(X(u,a(s.path+l+t+c),n))}}const{path:g,lastSegment:I,wildcardCount:y,wildcardParentPaths:m,wildcardParentPathInfos:P}=e.pathInfo,b=e.listIndex;for(let e=0;b&&e<y;e++){const n=x(b,e-1,y);for(const o of u.dynamicDependency.get(m[e])??[]){const l=a(o);if(u.listPaths.has(o)&&l.wildcardCount===e&&vt(l)&&s[E](w(l,n))===s[E](w(P[e],n))){const n=w(a(o+g.slice(m[e].length)),b);h(n),I===t&&f.enqueueRenderOnlyAddress(p(u,n.parentAddress))}}}}function te(e,n,s,a,o){o&&(e.getterPaths.has(n)?k(s):y(s,{value:a,dirty:!1,generation:e.stateGeneration,rowStamp:s.absolutePathInfo.pathInfo.lastSegment===t?void 0:I(s.listIndex)}))}function ee(e,n,a,o,l,r,i,d,c=!0){try{if(!(n.pathInfo.path in e)){const a=n.parentAddress;if(null===a)return Reflect.set(e,n.pathInfo.path,o);const i=At(e,a,l,r),d=n.pathInfo.segments[n.pathInfo.segments.length-1];if(d===t){const t=n.listIndex?.index??u(s(`path "${n.pathInfo.path}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(n.pathInfo.path))return Reflect.set(e,n.pathInfo.path,o);r.pushAddress(n),r.beginUntrack();try{return Reflect.set(e,n.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{c&&_t(n,a,l,r,i,d)}}function ne(e,n,s,o,r,i,d,c,f){const h=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),g=At(e,h,r,i)??[],I=Dt(g);if(f)return I&&(I.value[n.listIndex.index]=o),Y(n.listIndex,o),ee(e,n,s,o,r,i,d,c);const y=n.listIndex,x=I??{value:[...g],listIndexes:S(g)??[],written:new Map};try{return ee(e,n,s,o,r,i,d,c,!1)}finally{const e=function(t,e,n){const{value:s,listIndexes:a}=t,o=new Map;a.forEach((t,n)=>{if(e[n]!==s[n]){const e=o.get(s[n]);e?e.push(t):o.set(s[n],[t])}});let l,r=0;const i=[];for(let t=0;t<a.length;t++){const n=e[t]===s[t]?a[t]:o.get(e[t])?.shift();if(!n&&(r++?(l??=new Set(s)).has(e[t]):s.includes(e[t])))return null;i.push(n)}return i.map((t,e)=>t??T(n,e))}(x,g,h.listIndex);if(null===e)Lt(g,x),Y(y,o),x.written.set(y,Z),_(y),_t(n,s,r,i,d,c);else{Lt(g,null);const n=[y.index];tt(y),x.written.forEach((t,e)=>{tt(e),Y(e,x.value[e.index]),t===Z&&n.push(e.index)}),x.written.delete(y),e.forEach((t,e)=>{t.index=e}),W(g,e),N(x.listIndexes,e),function(e,n,s,o,r,i,d){const c=i.stateElement,f=nt(),u=p(c,e);W(n.value,n.listIndexes),st(n.value),z(s,n.value),at(u)===s&&ot(u,n.value);f.enqueueRenderOnlyAddress(u);for(const t of Q(u,s))lt(t,s)&&f.enqueueRenderOnlyAddress(t);const h=new Map;n.listIndexes.forEach((t,e)=>h.set(t,e));const g=a(e.pathInfo.path+l+t);for(let t=0;t<o.length;t++){const e=o[t],s=h.get(e);if(s===t)continue;const a=w(g,e),l=p(c,a);if(void 0===s){const e=X(c,g,n.listIndexes[t]);Ft(c,l,e),_t(a,l,r,i,null,wt(c,a),"full");continue}Nt(c,a,c.staticDependency,c.dynamicDependency,c.listPaths,r,"new",t=>{const e=p(c,t);k(e),f.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}for(const t of d){const e=o[t];if(h.has(e)&&n.written.get(e)!==Z){const s=w(g,e),a=p(c,s);Ft(c,a,X(c,g,n.listIndexes[t])),_t(s,a,r,i,null,wt(c,s))}}}(h,x,g,e,r,i,n)}}}function se(e,n,s,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(s)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=At(e,n,o,r),c=function(t,e,n,s){const a=jt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=jt(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,s);if(null!==c)return function(e,n,s,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===S(o)&&v(c,null,o);const f=v(c,o,s.list),u=ae(e,n,s.list,r,i,d),h=a(d+l+t);for(const t of s.matched){const n=Mt(t.oldRow,t.newRow);if(0===n.length)continue;const s=f.newIndexes[t.position];for(const o of n){if(void 0===s){t.oldRow[o.field]=o.value;continue}const n=a(h.path+l+o.field);se(e,w(n,s),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return ae(e,n,s,o,r,null)}function ae(e,n,a,o,l,i){const d=l.stateElement,c=n.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let e=0;e<t.length;e++){const s=t[e](d,n,a,o,l);if(s!==ct)return s}}const h=et(),g=h>1;if(!(c in e)&&null!==n.parentAddress&&!d.elementPaths.has(c)){const h=At(e,n.parentAddress,o,l);if("object"==typeof h&&null!==h){const e=n.pathInfo.lastSegment,I=e===t?n.listIndex?.index:e;let y,x=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=void 0!==I&&I in h,e=void 0!==I?h[I]:void 0;if(t&&Object.is(e,a))return!0;y=e,x=!0}e===t&&(n=function(t,e,n,s,a){const o=e.listIndex,l=S(n);if(l?.[s]!==o||n[s]===a)return e;const r=T(o.parentListIndex,s,B(o));if(H(n)){const t=Dt(n)??{value:n.slice(),listIndexes:l};W(t.value,t.listIndexes),z(n,t.value)}const i=G(l)?l:l.slice();i[s]=r,W(n,i,!0),N(l,i),U([o]);const d=w(e.pathInfo,r);return Ft(t,p(t,d),p(t,e)),d}(d,n,h,I,a));const P=Jt(d,c,x,y,a,()=>h[I]),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:y,hasOldValue:x}),Ut(d,c,v,y,x);let A=!1;try{if(void 0===I&&u(s(`path "${c}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0)),f&&0!==f.writeMissing.length&&e!==t&&!(I in h)){const t=f.writeMissing;for(let e=0;e<t.length;e++){A=!0;const s=t[e](d,n,h,I,a,o,l);if(s!==ct)return s;A=!1}}if(e!==t&&null!==n.listIndex){const t=h[I];t!==a&&(C(t,n.listIndex,h,e)&&Array.isArray(a)&&m(a,t),O(a,n.listIndex))}return Reflect.set(h,I,a)}finally{_t(n,v,o,l,i,b),Yt(P,o,l),A?k(v):te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}}let I,y=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=At(e,n,o,l);if(Ct(e,n,o,l)&&Object.is(t,a))return!0;I=t,y=!0}const x=Jt(d,c,y,I,a,()=>At(e,n,o,l)),P=d.elementPaths.has(n.pathInfo.path),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:I,hasOldValue:y}),Ut(d,c,v,I,y);try{return P?ne(e,n,v,a,o,l,i,b,h):ee(e,n,v,a,o,l,i,b)}finally{Yt(x,o,l),P||te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}function oe(t,e,n,s){return(e,o,...l)=>{Array.isArray(o)||u(`$resolve("${e}") requires an explicit indexes array (pass [] when the path has no wildcards) — got `+(null===o?"null":typeof o)+"."),l.length>1&&u(`$resolve("${e}") takes 2 arguments to read and 3 to write (path, indexes, value) — got ${2+l.length}.`);const r=a(e);if(s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",e,r.wildcardParentPathInfos.length,o.length));const d=Rt(t,n,s,r,o),c=w(r,d);if(0===l.length)return At(t,c,n,s);yt(s),se(t,c,l[0],n,s)}}function le(t,e,n,s){const o=oe(t,0,n,s);return(e,l)=>{const r=a(e);if(void 0===l||Array.isArray(l)||u(`$getAll("${e}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",e,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=dt(s,r.wildcardPaths[t]);if(e){l=rt(e,e.length);break}}if(void 0===l){const t=s.addressStackLength>0?s.lastAddressStack:null,n=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==n&&n.length>0&&u(d(e,t.pathInfo.path)),l=[]}}const c=$t(t,n,s,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function re(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":{const t=a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`);return dt(s,t)??u(`ListIndex not found: ${e.pathInfo.path}`)}case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=w(l,a),i=kt(s,r,At(t,r,n,s)),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function ie(e,n,s,o){return(n,l,r,d)=>{yt(o);const h=a(n);Array.isArray(l)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),l.length>h.wildcardParentPathInfos.length&&u(i("$setAll",n,h.wildcardParentPathInfos.length,l.length));const p=!0===d?.spread,g="function"==typeof r;p&&g&&u(c(n,"cannot combine { spread: true } with a mapper function.")),p&&!Array.isArray(r)&&u(c(n,"requires an array as the value when { spread: true } is set."));const I=$t(e,s,o,h,l,{commitDiffBaseline:!1});p&&r.length!==I.length&&u(f(n,I.length,r.length));const y=[];for(let t=0;t<I.length;t++){const n=Rt(e,s,o,h,I[t]);y.push(w(h,n))}const x=h.lastSegment===t;let m=0;for(let t=0;t<y.length;t++){const n=x?w(h,Rt(e,s,o,h,I[t])):y[t];let a;if(g){a=r(At(e,n,s,o),...I[t])}else a=p?r[t]:r;void 0!==a&&(se(e,n,a,s,o),m++)}return m}}export{yt as a,le as b,ie as c,re as d,gt as e,It as f,At as g,Ct as h,Zt as n,oe as r,se as s,Nt as w};
|
|
2
2
|
//# sourceMappingURL=setAll.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const o="3.5.
|
|
1
|
+
const o="3.5.3";export{o as V};
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as e,f as t,i as n}from"../chunks/filterRegistry.js";import{L as s,d as o,O as r}from"../chunks/pathDiagnostics.js";import{
|
|
1
|
+
import{c as e,f as t,i as n}from"../chunks/filterRegistry.js";import{L as s,d as o,O as r}from"../chunks/pathDiagnostics.js";import{bl as i,L as a,U as c,bm as l,bn as u,bo as d,f,bp as m,G as h}from"../chunks/binder.js";import{g as p}from"../chunks/featureBridge.js";import{r as g}from"../chunks/errorGuidance.js";import{V as y}from"../chunks/version.js";const k=/^\s*@@\s*(.*?)\s*:\s*(.+?)\s*$/;function v(e,t,n,s){return{node:e,propName:t.propName,statePathName:t.statePathName,bindingType:t.bindingType,inFilters:t.inFilters,outFilters:t.outFilters,origin:n,raw:s}}function N(n){const s=[],o=new Set,r=new Set,u=e=>{const n=function(e){const n=`${t(e.inFilters)}\0${t(e.outFilters)}`;return[e.statePathName,e.propName,e.bindingType,n].join("\0")}(e);o.has(n)||(o.add(n),s.push(e))},d=e=>{if(r.has(e))return;r.add(e);const t=c(e);if(null!==t)for(const e of t.nodeInfos)for(const t of e.parseBindTextResults)u(v(null,t,"fragment","")),null!=t.uuid&&d(t.uuid)},f=(n.ownerDocument??n).createTreeWalker(n,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT);for(let t=f.nextNode();null!==t;t=f.nextNode()){if(t.nodeType===Node.ELEMENT_NODE){const n=t,s=n.getAttribute(e.bindAttributeName);if(null===s||0===s.length)continue;try{const e=i(n,a(s));for(const t of e)u(v(n,t,"attribute",s))}catch{}continue}const n=k.exec(t.data.trim());if(null===n)continue;const s=n[1]||e.commentTextPrefix,o=n[2],r=c(o);if(null===r){if(s===e.commentTextPrefix)try{u(v(t,l(o),"comment",o))}catch{}}else u(v(t,r.parseBindTextResult,"comment",o)),d(o)}return s}const S="__WCSTACK_DEVTOOLS_HOOK__";function b(){const e=globalThis,t=e[S];if(void 0!==t)return 2!==t.version&&console.warn(`[wcstack/state] devtools hook registry version mismatch: found ${t.version}, expected 2. Keeping the existing registry (first-wins).`),t;const n=function(){const e=new Map,t=new Set,n=e=>{if(0===t.size)return void e._setSink(null);const n=e.id;e._setSink(e=>{for(const s of t)s.onEvent?.(n,e)})};return{version:2,sources:e,register(s){if(!e.has(s.id)){e.set(s.id,s),n(s);for(const e of t)e.onSourceRegistered?.(s)}},unregister(n){const s=e.get(n);if(void 0!==s){s._setSink(null),e.delete(n);for(const e of t)e.onSourceUnregistered?.(n)}},addListener(s){t.add(s);for(const t of e.values())n(t),s.onSourceRegistered?.(t);return()=>{if(t.delete(s))for(const t of e.values())n(t)}}}}();return e[S]=n,n}const w=e=>{null!==o&&o({type:"state:update-batch",addresses:e})};function T(e){const t=null!==o;r(e);const n=null!==e;n&&!t?f(w,s):!n&&t&&m(w)}function P(e){return{rootNode:e.rootNode,element:e,paths:{list:e.listPaths,element:e.elementPaths,getter:e.getterPaths,setter:e.setterPaths},commandTokenNames:e.commandTokenNames,eventTokenNames:e.eventTokenNames,staticDependency:e.staticDependency,dynamicDependency:e.dynamicDependency,watchPaths:e.watchPaths??null,keyedListPaths:void 0===e.listKeys||null===e.listKeys?null:new Set(e.listKeys.keys())}}function _(e){return h(e)??g("devtools: no state tree on this root")}let x=null;function E(){if(n())return;if(null!==x)return;const e={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:y,getStateElements(){const e=[];for(const t of d())e.push(P(t));return e},overlays:e=>p(_(e)),keyedSubscriptions:e=>function(e){const t=u(e);if(null===t)return[];const n=new Set([...t.byPath.keys(),...t.tracked]);if(void 0!==t.watchers)for(const e of t.watchers.keys())n.add(e);const s=[];for(const e of[...n].sort()){const n=t.byPath.get(e);let o=0;if(void 0!==n)for(const e of n.values())o+=e.size;s.push({path:e,tracked:t.tracked.has(e),rows:o,keys:n?.size??0,lists:t.watchers?.get(e)?.size??0,lastValue:t.lastValue.get(e)})}return s}(_(e)),keys(e){const t=_(e),n=[];return t.createState("readonly",e=>{for(const t of Object.keys(e))if(!t.includes("*")&&!t.startsWith("$")){try{if("function"==typeof e[t])continue}catch{}n.push(t)}}),n},read(e,t,n){let s;return _(e).createState("readonly",e=>{s=e.$resolve(t,n??[])}),s},write(e,t,n,s){_(e).createState("writable",e=>{void 0!==s&&s.length>0?e.$resolve(t,s,n):e[t]=n})},getDeclaredBindings:e=>N(e),_setSink:T};x=e,b().register(e)}const O={name:"devtools",install(){E()}};export{O as default,O as devtools};
|
|
2
2
|
//# sourceMappingURL=devtools.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e}from"../chunks/declarationHooks.js";import{R as t,D as n,W as r,M as s,s as i,g as o,t as a,r as c}from"../chunks/pathDiagnostics.js";import{g as l}from"../chunks/checkDependency.js";import{M as h,j as u,l as d,N as f,O as p}from"../chunks/binder.js";import{r as g,N as m,g as v}from"../chunks/getAllPropertyDescriptors.js";import{g as $,a as w,s as y,b as x,c as P,d as _}from"../chunks/setAll.js";import{r as A}from"../chunks/errorGuidance.js";import"../chunks/filterRegistry.js";function b(e){return-1!==e.indexOf(t)}function k(e,t){if(t===e.recursiveAnchor)return"";const s=e.recursiveAnchor+n;if(!t.startsWith(s))return null;const i=t.slice(e.recursiveAnchor.length);if(b(i))return null;const o=i.slice(n.length).split(n);return o[0]===r||o.some(e=>0===e.length)?null:i}function I(e){return 0===e.length?e:n+L(e.slice(n.length))}function j(e,t,r){const s=n+e.repeat,i=t.length<=r.length?t:r,o=t.length<=r.length?r:t;if(!o.endsWith(i))return!1;const a=o.slice(0,o.length-i.length);if(0===a.length)return!0;if(a.length%s.length!==0)return!1;for(let e=0;e<a.length;e+=s.length)if(!a.startsWith(s,e))return!1;return!0}function R(e,t,r){for(let s=r.length;s>0;s=r.lastIndexOf(n,s-1))if(j(e,t,r.slice(0,s)))return!0;return!1}function L(e){const t=e.split(n);for(let e=0;e<t.length;e++)t[e]===r||Number.isNaN(Number(t[e]))||(t[e]=r);return t.join(n)}function O(e,t){const r=e.repeat.split(n),s=n+e.repeat;let i=t;for(;i.startsWith(s);)i=i.slice(s.length);if(0===i.length||i===n+e.repeatList+n+"length")return!0;for(let e=1;e<r.length;e++)if(i===n+r.slice(0,e).join(n))return!0;return!1}function W(e,t,i){i<0&&A(`Recursion depth must not be negative (got ${i}).`);let o=e.anchor;for(let t=0;t<i;t++)o+=n+e.repeat;const a=o+t;let c=0;for(const e of a.split(n))e===r&&c++;return c>s&&A(`[wcs/recursion-depth-exceeded] Recursion on "${e.anchor}" reached depth ${i} ("${a}"), which needs ${c} wildcard levels — the limit is ${s}. Either the data nests deeper than the engine can address, or the tree contains a cycle.`),a}function S(e,t){return W(e,"",t)}function N(e,t,r){if(!r.startsWith(e.anchor))return null;if(t.length>0&&!r.endsWith(t))return null;if(r.length<e.anchor.length+t.length)return null;const s=r.slice(e.anchor.length,r.length-t.length);if(0===s.length)return 0;const i=n+e.repeat;let o=0,a=0;for(;a<s.length;){if(!s.startsWith(i,a))return null;a+=i.length,o++}return o}function B(e,t){if(0===e.addressStackLength)return null;const r=e.lastAddressStack;if(null===r)return null;const s=t.accessorFor(r.pathInfo.path);return null!==s?s.depth:function(e,t){const r=e.spec;if(!t.startsWith(r.anchor))return null;const s=n+r.repeat;let i=0,o=r.anchor.length;for(;t.startsWith(s,o);)o+=s.length,i++;return o!==t.length&&46!==t.charCodeAt(o)?null:i}(t,r.pathInfo.path)}function E(e,t,n){const r=e.recursionRegistry,s=k(r.spec,n);null===s&&A(i(n,r.spec.recursiveAnchor));const o=B(t,r);return null===o&&A(`[wcs/recursion-context] "${n}" uses "**", which is bound to the depth of the recursive getter being evaluated, and there is no recursion context here. Read it from inside a recursive getter or a row getter under "${r.spec.anchor}", or name a concrete depth (for example "${r.spec.anchor}${n.slice(r.spec.recursiveAnchor.length)}"). The depth comes from the innermost frame only: a plain getter reached from a recursive getter has no row of its own, so read "**" in the recursive getter and pass the value on.`),r.concretePathAt(s,o)}function C(e,t,r,s,i){const a=s.spec,c=[],l=new Map,g=[],m=a.repeatList,v=a.anchorList,w=new Set,y=new Set,x=(e,t,n)=>{const r=e.wildcardParentPathInfos;if(t>=r.length)return void c.push(u(e,n));const s=P(r[t],n,null).rows;for(let n=0;n<s.length;n++)x(e,t+1,s[n])};function P(n,s,i){const o=u(n,s),c=d(r.stateElement,o),h=$(e,o,t,r),g=null===i?null:((e,t,n)=>{if(!Array.isArray(t)||0===t.length)return null;const r=t;return w.has(r)&&A(`[wcs/recursion-cycle] "${e}" is reachable from itself: the recursion on "${a.anchor}" walked into a list that one of its own ancestors already owns. The data contains a cycle, which this version does not support.`),n.has(r)&&A(`[wcs/recursion-shared-list] "${e}" is the same array instance as a list reached from another node. The recursion on "${a.anchor}" needs a tree: give each node its own "${m}" array.`),r})(n.path,h,i),v=f(s,p(c),h);return l.set(c,Array.isArray(h)?h:[]),null!==g&&null!==i&&i.add(g),{rows:v.newIndexes,tracked:g}}const _=(e,t,r)=>{const{rows:a,tracked:l}=P(t,r,y);if(0===a.length)return;const h=(e=>{const t=g[e];if(void 0!==t)return t;const r=s.concretePathAt(i,e),a=0===i.length?r:s.concretePathAt("",e),c={nodePath:a,concretePathInfo:o(r),childListPathInfo:o(a+n+m)};return g[e]=c,c})(e),d=l;w.add(d);const f=h.concretePathInfo.wildcardCount===e+1;for(let t=0;t<a.length;t++){const n=a[t];f?c.push(u(h.concretePathInfo,n)):x(h.concretePathInfo,e+1,n),_(e+1,h.childListPathInfo,n)}w.delete(d)};_(0,o(v),null);for(const[e,t]of l)h(e,t);return c}function D(e,t,n,r,s,o,c){w(n);const l=n.stateElement.recursionRegistry,h=k(l.spec,r);null===h&&A(i(r,l.spec.recursiveAnchor));const u=I(h);Array.isArray(s)||A(a(r,'with "**" requires an explicit empty indexes array ([]) — the write API takes no context.')),s.length>0&&A(`[wcs/recursion-setall-form] $setAll("${r}", indexes, …) with "**" takes no partial prefix: a prefix cannot say which depth it applies to. Pass [] to broadcast to every depth.`),"function"==typeof o&&A(a(r,'with "**" does not take a mapper yet — the index tuple has a different length at each depth.')),!0===c?.spread&&A(a(r,'with "**" does not take { spread: true } — handing a flat array to a tree needs the author to know the walk order, which is not a usable contract.')),function(e,t,n){O(e,n)&&A(`[wcs/recursion-structural-write] "${t}" writes the recursion structure itself (a node, its "${e.repeatList}" list or that list's length, or an object on the way to that list). This version broadcasts to leaf properties only — replacing a node would invalidate the child addresses already resolved for this write.`)}(l.spec,r,u);const d=l.conflictingRecursiveGetter(u);null!==d&&A(`[wcs/recursion-readonly] "${r}" writes into the recursive getter "${d}", which has no setter — the two name the same family of concrete paths (or this path points inside the value that getter derives). Write the values it derives from instead.`);const f=C(e,t,n,l,h);let p=0;for(let r=0;r<f.length;r++)void 0!==o&&(y(e,f[r],o,t,n),p++);return p}const G={write(e,t){if(!0!==e.hasRecursion)return m;const n=e.recursionRegistry.recursiveGetterOwningPath(t.pathInfo);return null!==n&&A(`[wcs/recursion-readonly] "${t.pathInfo.path}" writes into the recursive getter "${n}" (this path is that getter at one depth, or a path inside the value it derives), which has no setter. Write the values it derives from instead.`),m},get(e,t,n,r){if(!0!==e.stateElement.hasRecursion)return m;if("$getAll"===t)return(s,o)=>{if(b(s)){if(void 0!==o)return function(e,t,n,r,s){const o=n.stateElement.recursionRegistry,a=k(o.spec,r);null===a&&A(i(r,o.spec.recursiveAnchor)),Array.isArray(s)||A(`[wcs/recursion-getall-form] $getAll("${r}", indexes) with "**" takes either no indexes (to read the depth of the recursive getter being evaluated) or [] (to walk every depth) — got ${null===s?"null":typeof s}.`),s.length>0&&A(`[wcs/recursion-getall-form] $getAll("${r}", indexes) with "**" takes no partial prefix: a prefix cannot say which depth it applies to. Omit the indexes to read the depth of the recursive getter being evaluated, or pass [] to walk every depth.`);const c=C(e,t,n,o,a),l=[];for(let r=0;r<c.length;r++)l.push($(e,c[r],t,n));return l}(r,n,e,s,o);s=E(e.stateElement,e,s)}return x(r,t,n,e)(s,o)};if("$setAll"===t)return(s,i,o,a)=>b(s)?D(r,n,e,s,i,o,a):P(r,t,n,e)(s,i,o,a);if(36!==t.charCodeAt(0)&&b(t)){const s=l(E(e.stateElement,e,t)),i=_(r,s,n,e);return $(r,u(s.pathInfo,i),n,e)}return m}};let z=!1;function M(e,s){"string"==typeof s&&0!==s.length||A(`[wcs/recursion-declaration-invalid] ${c} ${e} must be a non-empty string.`);const i=s.split(n);i.some(e=>0===e.length)&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain empty path segments.`),i.length<2&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must name a list element: a property path ending with "${n}${r}" (for example "nodes${n}${r}").`),i[i.length-1]!==r&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must end with "${n}${r}" — it names the element of the list, not the list itself.`),36===i[0].charCodeAt(0)&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not start with "$" — that namespace is reserved.`),-1!==s.indexOf("#")&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain "#" — that segment is reserved for mounts.`);for(let n=0;n<i.length-1;n++)i[n]===r&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must have exactly one "${r}", at the end. Wildcards in the middle are not supported in this version.`),i[n]===t&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain "${t}" — the declaration is what gives "${t}" its meaning.`),isNaN(Number(i[n]))||A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain an index segment ("${i[n]}") — the recursion is declared over the shape of the tree, not over one row.`)}const T=new WeakSet;function F(e){return"function"==typeof e.get&&T.has(e.get)}const H="[wcs/recursion-declaration-invalid]";class q{spec;_definitions=new Map;_accessors=new Map;_ownerByPath=new Map;_ownerByPathInfo=new WeakMap;_accessorByPathInfo=new WeakMap;_concreteBySuffix=new Map;_registeredListPaths=new Set;constructor(e,t){this.spec=e;const r=v(t);for(const[t,s]of Object.entries(r)){if(!b(t))continue;"function"==typeof s.set&&A(`${H} Recursive setters are not supported in this version: "${t}". Declare a plain path setter, or write through the concrete path.`),"function"!=typeof s.get&&A(`${H} "${t}" contains "**" but is not a getter. The recursion wildcard only names a family of computed paths.`);const r=k(e,t);null===r&&A(i(t,e.recursiveAnchor)),0===r.length&&A(`${H} "${t}" names the recursive node itself. "**" names a computed path under a node (for example "${e.recursiveAnchor}${n}total"), not the node.`),O(e,I(r))&&A(`${H} "${t}" names the recursion structure itself (a node, its "${e.repeatList}" list or that list's length, or an object on the way to that list). A recursive getter would hide the real child list at every depth — "**" names a computed leaf under a node (for example "${e.recursiveAnchor}${n}total").`),this._definitions.set(t,{recursivePath:t,suffix:r,get:s.get})}this._assertNoColliding(),this._assertNoConcreteCollision(r)}_assertNoConcreteCollision(e){for(const[t,n]of Object.entries(e)){if(b(t)||F(n))continue;const e=this._matchExpansion(t);null!==e&&A(`${H} "${t}" is already defined on the state, so the recursive getter "${e}" cannot expand to it. Rename one of them.`)}}_assertNoColliding(){const e=Array.from(this._definitions.values());for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++)j(this.spec,e[t].suffix,e[n].suffix)&&A(`${H} "${e[t].recursivePath}" and "${e[n].recursivePath}" expand to the same concrete path at different depths (they differ by whole repetitions of "${this.spec.repeat}"). Rename one of them.`)}get hasDefinitions(){return this._definitions.size>0}conflictingRecursiveGetter(e){for(const t of this._definitions.values())if(R(this.spec,t.suffix,e))return t.recursivePath;return null}recursiveGetterOwningPath(e){const t=this._ownerByPathInfo.get(e);if(void 0!==t)return t;const n=this.recursiveGetterOwning(e.path);return this._ownerByPathInfo.set(e,n),n}recursiveGetterOwning(e){const t=this._accessors.get(e);if(void 0!==t)return t.recursivePath;const r=L(e),s=this._ownerByPath.get(r);if(void 0!==s)return s;let i=null;if(r.startsWith(this.spec.anchor)){i=this._matchExpansion(r);for(let e=r.lastIndexOf(n);null===i&&e>this.spec.anchor.length;e=r.lastIndexOf(n,e-1))i=this._matchExpansion(r.slice(0,e))}return this._ownerByPath.set(r,i),i}_matchExpansion(e){for(const t of this._definitions.values())if(null!==N(this.spec,t.suffix,e))return t.recursivePath;return null}materializeForPathInfo(e,t){if(0===this._definitions.size)return null;const n=this._accessorByPathInfo.get(t);if(void 0!==n)return n;const r=this.materializeFor(e,t.path);return this._accessorByPathInfo.set(t,r),r}materializeFor(e,t){const n=this._accessors.get(t);if(void 0!==n)return n;if(!t.startsWith(this.spec.anchor))return null;let r=null,s=0;for(const e of this._definitions.values()){const n=N(this.spec,e.suffix,t);null!==n&&(null!==r&&A(`"${t}" matches both "${r.recursivePath}" and "${e.recursivePath}".`),r=e,s=n)}return null===r?null:this._define(e,r,s,t)}_define(e,t,n,r){const s=e.findStateDescriptor(r);void 0===s||F(s)||A(`"${r}" is already defined on the state, so the recursive getter "${t.recursivePath}" cannot expand to it. Rename one of them.`);const i=Object.freeze({recursivePath:t.recursivePath,depth:n}),o=t.get,a=function(){return o.call(this)};var c;return c=a,T.add(c),e.defineTreeAccessor(r,{get:a,enumerable:!1,configurable:!0}),this._registerListPaths(e,n),this._accessors.set(r,i),i}_registerListPaths(e,t){for(const r of function(e,t){const r=[];r.push(e.anchorList);for(let s=0;s<t;s++)r.push(S(e,s)+n+e.repeatList);return r}(this.spec,t))this._registeredListPaths.has(r)||(this._registeredListPaths.add(r),e.addListPath(r))}forgetGenerated(e,t){const n=new Set(this._accessors.keys());return function(e,t,n){if(0!==n.size){for(const e of n){const n=Object.getOwnPropertyDescriptor(t,e);void 0!==n&&F(n)&&delete t[e]}for(const t of[e.staticDependency,e.dynamicDependency]){for(const e of n)t.delete(e);for(const[e,r]of t){let s=null;for(let e=0;e<r.length;e++)n.has(r[e])?s??=r.slice(0,e):s?.push(r[e]);null!==s&&(0===s.length?t.delete(e):t.set(e,s))}}}}(e,t,n),n}concretePathAt(e,t){let n=this._concreteBySuffix.get(e);void 0===n&&(n=[],this._concreteBySuffix.set(e,n));let r=n[t];return void 0===r&&(r=W(this.spec,e,t),n[t]=r),r}accessorFor(e){return this._accessors.get(e)??null}get materializedPaths(){return new Set(this._accessors.keys())}}const J="recursionSpec",K="recursionRegistry",Q={order:5,validateEarly(e,s,i){const o=function(e){const s=e[c];if(void 0===s)return null;"object"==typeof s&&null!==s||A(`[wcs/recursion-declaration-invalid] ${c} must be an object mapping one anchor path to its repeating sub-path (for example { "nodes.*": "children.*" }).`);const i=Object.entries(s);0===i.length&&A(`[wcs/recursion-declaration-invalid] ${c} must declare exactly one anchor; it is empty.`),i.length>1&&A(`[wcs/recursion-declaration-invalid] ${c} declares ${i.length} anchors (${i.map(([e])=>`"${e}"`).join(", ")}). This version supports exactly one self-recursive anchor per state.`);const[o,a]=i[0];M("anchor",o),"string"!=typeof a&&A(`[wcs/recursion-declaration-invalid] ${c} entry "${o}" must map to the repeating sub-path as a string (for example "children${n}${r}").`),M("repeating sub-path",a);const l=o.slice(0,o.lastIndexOf(n)),h=a.slice(0,a.lastIndexOf(n)),u=l+n+t;return Object.freeze({anchor:o,repeat:a,recursiveAnchor:u,anchorList:l,repeatList:h})}(s);i.set(J,o),i.set(K,null===o?null:new q(o,s))},preCommit(e,t,n){const r=e.recursionRegistry;if(null!==r)for(const t of r.forgetGenerated(e,n.get("previousState")))e.addGeneratedPath?.(t);const s=n.get(K)??null;e.setRecursionRegistry?.(s),null!==s&&e.attachAddressHooks?.("recursion",c)},apply(e,t,n){const r=n.get(J)??null;null!==r&&e.addListPath(r.anchorList)}};let U=!1;function V(){U||(U=!0,z||(z=!0,g("recursion",G)),e("recursion",Q))}const X={name:"recursion",install(){V()}};export{X as default,X as recursion};
|
|
1
|
+
import{r as e}from"../chunks/declarationHooks.js";import{R as t,D as n,W as r,M as s,s as i,g as o,t as a,r as c}from"../chunks/pathDiagnostics.js";import{g as l}from"../chunks/checkDependency.js";import{N as h,j as u,l as d,O as f,P as p}from"../chunks/binder.js";import{r as g,N as m,g as v}from"../chunks/getAllPropertyDescriptors.js";import{g as $,a as w,s as y,b as x,c as P,d as _}from"../chunks/setAll.js";import{r as A}from"../chunks/errorGuidance.js";import"../chunks/filterRegistry.js";function b(e){return-1!==e.indexOf(t)}function k(e,t){if(t===e.recursiveAnchor)return"";const s=e.recursiveAnchor+n;if(!t.startsWith(s))return null;const i=t.slice(e.recursiveAnchor.length);if(b(i))return null;const o=i.slice(n.length).split(n);return o[0]===r||o.some(e=>0===e.length)?null:i}function I(e){return 0===e.length?e:n+L(e.slice(n.length))}function j(e,t,r){const s=n+e.repeat,i=t.length<=r.length?t:r,o=t.length<=r.length?r:t;if(!o.endsWith(i))return!1;const a=o.slice(0,o.length-i.length);if(0===a.length)return!0;if(a.length%s.length!==0)return!1;for(let e=0;e<a.length;e+=s.length)if(!a.startsWith(s,e))return!1;return!0}function R(e,t,r){for(let s=r.length;s>0;s=r.lastIndexOf(n,s-1))if(j(e,t,r.slice(0,s)))return!0;return!1}function L(e){const t=e.split(n);for(let e=0;e<t.length;e++)t[e]===r||Number.isNaN(Number(t[e]))||(t[e]=r);return t.join(n)}function O(e,t){const r=e.repeat.split(n),s=n+e.repeat;let i=t;for(;i.startsWith(s);)i=i.slice(s.length);if(0===i.length||i===n+e.repeatList+n+"length")return!0;for(let e=1;e<r.length;e++)if(i===n+r.slice(0,e).join(n))return!0;return!1}function W(e,t,i){i<0&&A(`Recursion depth must not be negative (got ${i}).`);let o=e.anchor;for(let t=0;t<i;t++)o+=n+e.repeat;const a=o+t;let c=0;for(const e of a.split(n))e===r&&c++;return c>s&&A(`[wcs/recursion-depth-exceeded] Recursion on "${e.anchor}" reached depth ${i} ("${a}"), which needs ${c} wildcard levels — the limit is ${s}. Either the data nests deeper than the engine can address, or the tree contains a cycle.`),a}function S(e,t){return W(e,"",t)}function N(e,t,r){if(!r.startsWith(e.anchor))return null;if(t.length>0&&!r.endsWith(t))return null;if(r.length<e.anchor.length+t.length)return null;const s=r.slice(e.anchor.length,r.length-t.length);if(0===s.length)return 0;const i=n+e.repeat;let o=0,a=0;for(;a<s.length;){if(!s.startsWith(i,a))return null;a+=i.length,o++}return o}function B(e,t){if(0===e.addressStackLength)return null;const r=e.lastAddressStack;if(null===r)return null;const s=t.accessorFor(r.pathInfo.path);return null!==s?s.depth:function(e,t){const r=e.spec;if(!t.startsWith(r.anchor))return null;const s=n+r.repeat;let i=0,o=r.anchor.length;for(;t.startsWith(s,o);)o+=s.length,i++;return o!==t.length&&46!==t.charCodeAt(o)?null:i}(t,r.pathInfo.path)}function E(e,t,n){const r=e.recursionRegistry,s=k(r.spec,n);null===s&&A(i(n,r.spec.recursiveAnchor));const o=B(t,r);return null===o&&A(`[wcs/recursion-context] "${n}" uses "**", which is bound to the depth of the recursive getter being evaluated, and there is no recursion context here. Read it from inside a recursive getter or a row getter under "${r.spec.anchor}", or name a concrete depth (for example "${r.spec.anchor}${n.slice(r.spec.recursiveAnchor.length)}"). The depth comes from the innermost frame only: a plain getter reached from a recursive getter has no row of its own, so read "**" in the recursive getter and pass the value on.`),r.concretePathAt(s,o)}function C(e,t,r,s,i){const a=s.spec,c=[],l=new Map,g=[],m=a.repeatList,v=a.anchorList,w=new Set,y=new Set,x=(e,t,n)=>{const r=e.wildcardParentPathInfos;if(t>=r.length)return void c.push(u(e,n));const s=P(r[t],n,null).rows;for(let n=0;n<s.length;n++)x(e,t+1,s[n])};function P(n,s,i){const o=u(n,s),c=d(r.stateElement,o),h=$(e,o,t,r),g=null===i?null:((e,t,n)=>{if(!Array.isArray(t)||0===t.length)return null;const r=t;return w.has(r)&&A(`[wcs/recursion-cycle] "${e}" is reachable from itself: the recursion on "${a.anchor}" walked into a list that one of its own ancestors already owns. The data contains a cycle, which this version does not support.`),n.has(r)&&A(`[wcs/recursion-shared-list] "${e}" is the same array instance as a list reached from another node. The recursion on "${a.anchor}" needs a tree: give each node its own "${m}" array.`),r})(n.path,h,i),v=f(s,p(c),h);return l.set(c,Array.isArray(h)?h:[]),null!==g&&null!==i&&i.add(g),{rows:v.newIndexes,tracked:g}}const _=(e,t,r)=>{const{rows:a,tracked:l}=P(t,r,y);if(0===a.length)return;const h=(e=>{const t=g[e];if(void 0!==t)return t;const r=s.concretePathAt(i,e),a=0===i.length?r:s.concretePathAt("",e),c={nodePath:a,concretePathInfo:o(r),childListPathInfo:o(a+n+m)};return g[e]=c,c})(e),d=l;w.add(d);const f=h.concretePathInfo.wildcardCount===e+1;for(let t=0;t<a.length;t++){const n=a[t];f?c.push(u(h.concretePathInfo,n)):x(h.concretePathInfo,e+1,n),_(e+1,h.childListPathInfo,n)}w.delete(d)};_(0,o(v),null);for(const[e,t]of l)h(e,t);return c}function D(e,t,n,r,s,o,c){w(n);const l=n.stateElement.recursionRegistry,h=k(l.spec,r);null===h&&A(i(r,l.spec.recursiveAnchor));const u=I(h);Array.isArray(s)||A(a(r,'with "**" requires an explicit empty indexes array ([]) — the write API takes no context.')),s.length>0&&A(`[wcs/recursion-setall-form] $setAll("${r}", indexes, …) with "**" takes no partial prefix: a prefix cannot say which depth it applies to. Pass [] to broadcast to every depth.`),"function"==typeof o&&A(a(r,'with "**" does not take a mapper yet — the index tuple has a different length at each depth.')),!0===c?.spread&&A(a(r,'with "**" does not take { spread: true } — handing a flat array to a tree needs the author to know the walk order, which is not a usable contract.')),function(e,t,n){O(e,n)&&A(`[wcs/recursion-structural-write] "${t}" writes the recursion structure itself (a node, its "${e.repeatList}" list or that list's length, or an object on the way to that list). This version broadcasts to leaf properties only — replacing a node would invalidate the child addresses already resolved for this write.`)}(l.spec,r,u);const d=l.conflictingRecursiveGetter(u);null!==d&&A(`[wcs/recursion-readonly] "${r}" writes into the recursive getter "${d}", which has no setter — the two name the same family of concrete paths (or this path points inside the value that getter derives). Write the values it derives from instead.`);const f=C(e,t,n,l,h);let p=0;for(let r=0;r<f.length;r++)void 0!==o&&(y(e,f[r],o,t,n),p++);return p}const G={write(e,t){if(!0!==e.hasRecursion)return m;const n=e.recursionRegistry.recursiveGetterOwningPath(t.pathInfo);return null!==n&&A(`[wcs/recursion-readonly] "${t.pathInfo.path}" writes into the recursive getter "${n}" (this path is that getter at one depth, or a path inside the value it derives), which has no setter. Write the values it derives from instead.`),m},get(e,t,n,r){if(!0!==e.stateElement.hasRecursion)return m;if("$getAll"===t)return(s,o)=>{if(b(s)){if(void 0!==o)return function(e,t,n,r,s){const o=n.stateElement.recursionRegistry,a=k(o.spec,r);null===a&&A(i(r,o.spec.recursiveAnchor)),Array.isArray(s)||A(`[wcs/recursion-getall-form] $getAll("${r}", indexes) with "**" takes either no indexes (to read the depth of the recursive getter being evaluated) or [] (to walk every depth) — got ${null===s?"null":typeof s}.`),s.length>0&&A(`[wcs/recursion-getall-form] $getAll("${r}", indexes) with "**" takes no partial prefix: a prefix cannot say which depth it applies to. Omit the indexes to read the depth of the recursive getter being evaluated, or pass [] to walk every depth.`);const c=C(e,t,n,o,a),l=[];for(let r=0;r<c.length;r++)l.push($(e,c[r],t,n));return l}(r,n,e,s,o);s=E(e.stateElement,e,s)}return x(r,t,n,e)(s,o)};if("$setAll"===t)return(s,i,o,a)=>b(s)?D(r,n,e,s,i,o,a):P(r,t,n,e)(s,i,o,a);if(36!==t.charCodeAt(0)&&b(t)){const s=l(E(e.stateElement,e,t)),i=_(r,s,n,e);return $(r,u(s.pathInfo,i),n,e)}return m}};let z=!1;function M(e,s){"string"==typeof s&&0!==s.length||A(`[wcs/recursion-declaration-invalid] ${c} ${e} must be a non-empty string.`);const i=s.split(n);i.some(e=>0===e.length)&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain empty path segments.`),i.length<2&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must name a list element: a property path ending with "${n}${r}" (for example "nodes${n}${r}").`),i[i.length-1]!==r&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must end with "${n}${r}" — it names the element of the list, not the list itself.`),36===i[0].charCodeAt(0)&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not start with "$" — that namespace is reserved.`),-1!==s.indexOf("#")&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain "#" — that segment is reserved for mounts.`);for(let n=0;n<i.length-1;n++)i[n]===r&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must have exactly one "${r}", at the end. Wildcards in the middle are not supported in this version.`),i[n]===t&&A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain "${t}" — the declaration is what gives "${t}" its meaning.`),isNaN(Number(i[n]))||A(`[wcs/recursion-declaration-invalid] ${c} ${e} "${s}" must not contain an index segment ("${i[n]}") — the recursion is declared over the shape of the tree, not over one row.`)}const T=new WeakSet;function F(e){return"function"==typeof e.get&&T.has(e.get)}const H="[wcs/recursion-declaration-invalid]";class q{spec;_definitions=new Map;_accessors=new Map;_ownerByPath=new Map;_ownerByPathInfo=new WeakMap;_accessorByPathInfo=new WeakMap;_concreteBySuffix=new Map;_registeredListPaths=new Set;constructor(e,t){this.spec=e;const r=v(t);for(const[t,s]of Object.entries(r)){if(!b(t))continue;"function"==typeof s.set&&A(`${H} Recursive setters are not supported in this version: "${t}". Declare a plain path setter, or write through the concrete path.`),"function"!=typeof s.get&&A(`${H} "${t}" contains "**" but is not a getter. The recursion wildcard only names a family of computed paths.`);const r=k(e,t);null===r&&A(i(t,e.recursiveAnchor)),0===r.length&&A(`${H} "${t}" names the recursive node itself. "**" names a computed path under a node (for example "${e.recursiveAnchor}${n}total"), not the node.`),O(e,I(r))&&A(`${H} "${t}" names the recursion structure itself (a node, its "${e.repeatList}" list or that list's length, or an object on the way to that list). A recursive getter would hide the real child list at every depth — "**" names a computed leaf under a node (for example "${e.recursiveAnchor}${n}total").`),this._definitions.set(t,{recursivePath:t,suffix:r,get:s.get})}this._assertNoColliding(),this._assertNoConcreteCollision(r)}_assertNoConcreteCollision(e){for(const[t,n]of Object.entries(e)){if(b(t)||F(n))continue;const e=this._matchExpansion(t);null!==e&&A(`${H} "${t}" is already defined on the state, so the recursive getter "${e}" cannot expand to it. Rename one of them.`)}}_assertNoColliding(){const e=Array.from(this._definitions.values());for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++)j(this.spec,e[t].suffix,e[n].suffix)&&A(`${H} "${e[t].recursivePath}" and "${e[n].recursivePath}" expand to the same concrete path at different depths (they differ by whole repetitions of "${this.spec.repeat}"). Rename one of them.`)}get hasDefinitions(){return this._definitions.size>0}conflictingRecursiveGetter(e){for(const t of this._definitions.values())if(R(this.spec,t.suffix,e))return t.recursivePath;return null}recursiveGetterOwningPath(e){const t=this._ownerByPathInfo.get(e);if(void 0!==t)return t;const n=this.recursiveGetterOwning(e.path);return this._ownerByPathInfo.set(e,n),n}recursiveGetterOwning(e){const t=this._accessors.get(e);if(void 0!==t)return t.recursivePath;const r=L(e),s=this._ownerByPath.get(r);if(void 0!==s)return s;let i=null;if(r.startsWith(this.spec.anchor)){i=this._matchExpansion(r);for(let e=r.lastIndexOf(n);null===i&&e>this.spec.anchor.length;e=r.lastIndexOf(n,e-1))i=this._matchExpansion(r.slice(0,e))}return this._ownerByPath.set(r,i),i}_matchExpansion(e){for(const t of this._definitions.values())if(null!==N(this.spec,t.suffix,e))return t.recursivePath;return null}materializeForPathInfo(e,t){if(0===this._definitions.size)return null;const n=this._accessorByPathInfo.get(t);if(void 0!==n)return n;const r=this.materializeFor(e,t.path);return this._accessorByPathInfo.set(t,r),r}materializeFor(e,t){const n=this._accessors.get(t);if(void 0!==n)return n;if(!t.startsWith(this.spec.anchor))return null;let r=null,s=0;for(const e of this._definitions.values()){const n=N(this.spec,e.suffix,t);null!==n&&(null!==r&&A(`"${t}" matches both "${r.recursivePath}" and "${e.recursivePath}".`),r=e,s=n)}return null===r?null:this._define(e,r,s,t)}_define(e,t,n,r){const s=e.findStateDescriptor(r);void 0===s||F(s)||A(`"${r}" is already defined on the state, so the recursive getter "${t.recursivePath}" cannot expand to it. Rename one of them.`);const i=Object.freeze({recursivePath:t.recursivePath,depth:n}),o=t.get,a=function(){return o.call(this)};var c;return c=a,T.add(c),e.defineTreeAccessor(r,{get:a,enumerable:!1,configurable:!0}),this._registerListPaths(e,n),this._accessors.set(r,i),i}_registerListPaths(e,t){for(const r of function(e,t){const r=[];r.push(e.anchorList);for(let s=0;s<t;s++)r.push(S(e,s)+n+e.repeatList);return r}(this.spec,t))this._registeredListPaths.has(r)||(this._registeredListPaths.add(r),e.addListPath(r))}forgetGenerated(e,t){const n=new Set(this._accessors.keys());return function(e,t,n){if(0!==n.size){for(const e of n){const n=Object.getOwnPropertyDescriptor(t,e);void 0!==n&&F(n)&&delete t[e]}for(const t of[e.staticDependency,e.dynamicDependency]){for(const e of n)t.delete(e);for(const[e,r]of t){let s=null;for(let e=0;e<r.length;e++)n.has(r[e])?s??=r.slice(0,e):s?.push(r[e]);null!==s&&(0===s.length?t.delete(e):t.set(e,s))}}}}(e,t,n),n}concretePathAt(e,t){let n=this._concreteBySuffix.get(e);void 0===n&&(n=[],this._concreteBySuffix.set(e,n));let r=n[t];return void 0===r&&(r=W(this.spec,e,t),n[t]=r),r}accessorFor(e){return this._accessors.get(e)??null}get materializedPaths(){return new Set(this._accessors.keys())}}const J="recursionSpec",K="recursionRegistry",Q={order:5,validateEarly(e,s,i){const o=function(e){const s=e[c];if(void 0===s)return null;"object"==typeof s&&null!==s||A(`[wcs/recursion-declaration-invalid] ${c} must be an object mapping one anchor path to its repeating sub-path (for example { "nodes.*": "children.*" }).`);const i=Object.entries(s);0===i.length&&A(`[wcs/recursion-declaration-invalid] ${c} must declare exactly one anchor; it is empty.`),i.length>1&&A(`[wcs/recursion-declaration-invalid] ${c} declares ${i.length} anchors (${i.map(([e])=>`"${e}"`).join(", ")}). This version supports exactly one self-recursive anchor per state.`);const[o,a]=i[0];M("anchor",o),"string"!=typeof a&&A(`[wcs/recursion-declaration-invalid] ${c} entry "${o}" must map to the repeating sub-path as a string (for example "children${n}${r}").`),M("repeating sub-path",a);const l=o.slice(0,o.lastIndexOf(n)),h=a.slice(0,a.lastIndexOf(n)),u=l+n+t;return Object.freeze({anchor:o,repeat:a,recursiveAnchor:u,anchorList:l,repeatList:h})}(s);i.set(J,o),i.set(K,null===o?null:new q(o,s))},preCommit(e,t,n){const r=e.recursionRegistry;if(null!==r)for(const t of r.forgetGenerated(e,n.get("previousState")))e.addGeneratedPath?.(t);const s=n.get(K)??null;e.setRecursionRegistry?.(s),null!==s&&e.attachAddressHooks?.("recursion",c)},apply(e,t,n){const r=n.get(J)??null;null!==r&&e.addListPath(r.anchorList)}};let U=!1;function V(){U||(U=!0,z||(z=!0,g("recursion",G)),e("recursion",Q))}const X={name:"recursion",install(){V()}};export{X as default,X as recursion};
|
|
2
2
|
//# sourceMappingURL=recursion.js.map
|