@wcstack/state 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +25 -3
- package/README.md +25 -3
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/manifest.d.ts +2 -0
- package/dist/manifest.esm.js +1 -0
- package/dist/parser.esm.js +25 -0
- 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/mount.js +1 -1
- package/dist/split/chunks/mount.js.map +1 -1
- package/dist/split/chunks/pathDiagnostics.js +1 -1
- package/dist/split/chunks/pathDiagnostics.js.map +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/chunks/watchRuntime.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/diagnostics.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/wcs-manifest.json +1 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as t,c as e,a 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 h,h as c,i as u}from"./lifecycleHooks.js";import{r as p,d as f}from"./errorGuidance.js";import{d as _,k as m,l as g,af as y,c as b,x as k,H as S,ag as w,G as P,ah as v,ai as $,aj as C,ak as x,al as I,am as A,an as N,ao as E,ap as z,F as D,j as L,y as R,o as j,aq as H,ar as O,as as T,at as G,au as M,g as F,av as U,aw as W,ax as V,ay as q}from"./binder.js";import{t as K,u as B,v as J,b as Q,w as X,l as Y,D as Z,W as tt,R as et,x as st,y as nt,n as at,z as it,I as ot,A as rt,M as lt,c as dt,d as ht,g as ct,N as ut,i as pt,k as ft,B as _t,f as mt}from"./pathDiagnostics.js";import{d as gt,e as yt,w as bt,f as kt,r as St,c as wt,b as Pt,g as vt,s as $t,h as Ct,a as xt,i as It}from"./setAll.js";import{N as At,g as Nt,b as Et,c as zt,d as Dt,e as Lt,f as Rt,h as jt,i as Ht,j as Ot,k as Tt,l as Gt,m as Mt,n as Ft}from"./getAllPropertyDescriptors.js";import{p as Ut}from"./diagnosticsHooks.js";class Wt{_loopContextStack=Array(K).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>=K&&p(`Exceeded maximum loop context stack depth of ${K}. 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 Vt(t,e){const s=t.getterPaths;if(0===s.size)return!1;for(const t of ct(e).cumulativePaths)if(s.has(t))return!0;return!1}const qt=/^\$\d+$/,Kt=`${dt}${Z}`,Bt=`${ht}${Z}`,Jt=new WeakMap;function Qt(t,e,s,n){const a=ot[e];if(void 0===a&&"string"==typeof e&&36===e.charCodeAt(0)&&qt.test(e)&&p(`[wcs/index-param-range] "${e}" is not a valid list index parameter: they run from ${rt}1 to ${rt}${lt}, 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=S(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!==At)return o}}if("$"===e[0]){switch(e){case"$stateElement":return n.stateElement;case"$getAll":return(a,i)=>Pt(t,e,s,n)(a,i);case"$setAll":return(a,i,o,r)=>wt(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=gt(e),o=yt(t,i,s,n),r=m(i.pathInfo,o),l=g(a,r),d=b();d.enqueueAbsoluteAddress(l),bt(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 h=a.addressHooks;if(h){const t=h.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)=>St(t,e,s,n)(a,i,...o);case"$trackDependency":return t=>function(t,e,s,n){return t=>{-1!==t.indexOf(et)&&p(`[wcs/recursion-unsupported] $trackDependency("${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 e=n.lastAddressStack?.pathInfo??p("Internal error: lastAddressStack is null"),s=n.stateElement;n.stateElement.getterPaths.has(e.path)&&e.path!==t&&s.addDynamicDependency(t,e.path)}}(0,0,0,n)(t);case"$eq":return(t,e)=>{const a=n.addressStackLength>0?n.lastAddressStack:null;if(Vt(n.stateElement,t))return null!==a&&n.stateElement.getterPaths.has(a.pathInfo.path)&&w(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=Vt(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?w(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=S(a.listIndex,e-1,a.pathInfo.wildcardCount);if(null===i&&p(`$eqIndex("${t}", ${e}): no list index at that level.`),Vt(n.stateElement,t))return n.stateElement.getterPaths.has(a.pathInfo.path)&&w(n.stateElement,t),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?P(l):null;null!==e?v(n.stateElement,t,a.pathInfo,e,r):$(n.stateElement,t,i,g(n.stateElement,a),r)}return Object.is(r,i.index)};case"$untrackDependency":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 kt(n.stateElement)}if(!e.startsWith(Kt)&&!e.startsWith(Bt))return}const i=gt(e),o=yt(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=Jt.get(t);return void 0===e&&(e=new Map,Jt.set(t,e)),e}(n),i=a.get(e);if(void 0!==i)return i;let o;switch(e){case L: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 D:o=e=>vt(t,e,s,n);break;case z:o=e=>Ct(t,e,s,n);break;case E:o=(e,a)=>$t(t,e,a,s,n);break;case N:o=()=>async function(t,e,s){const n=Reflect.get(t,st);"function"==typeof n&&await n.call(s)}(t,0,s);break;case A:o=()=>function(t,e,s){const n=Reflect.get(t,nt);"function"==typeof n&&n.call(s)}(t,0,s);break;case I:o=e=>function(t,e,s,n){const a=Reflect.get(t,at);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)}}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,it);"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 Xt{_stateElement;_addressStack=Array(K).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>=K&&(this._hasRepeatedAddress()&&p(`[wcs/getter-cycle] Exceeded maximum address stack depth of ${K}. Possible circular dependency between path getters: ${this._describeAddressCycle()}`),p(`[wcs/getter-depth-exceeded] Exceeded maximum address stack depth of ${K} 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 Qt(t,e,s,this)}set(t,e,s,n){return xt(this),function(t,e,s,n,a){if("string"==typeof e){const i=gt(e),o=yt(t,i,n,a),r=m(i.pathInfo,o);return $t(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)}}const Yt="undefined"==typeof HTMLElement?class{}:HTMLElement;const Zt=new Set(["for","if","elseif","else"]);function te(e,s,n){const a=new Map;for(const t of n){const e=ct(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=G(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))}};M();try{if(e.createState("readonly",t=>{for(const n of s){const s=m(ct(n),null);r(s);try{bt(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)Zt.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=H("state",a);void 0!==o&&o.catch(O)}finally{T()}}class ee extends Yt{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return F(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 Wt}();_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){const e=this.__state,s=Ft();s.set("previousState",e),Et(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),zt(this,t,s),Dt(this,t,s),this._commandTokenNames=n,this._eventTokenNames=a,this._stateGeneration++,this.__state=t,void 0!==e&&Ut?.reset(this),this._hasUpdatedCallback=at in t,this._hasErrorCallback=it in t,U(this),Lt(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=Nt(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);Rt(this,t,s),this._listKeys=i,this._rebuildPathInfo(),jt(this,t,s),Ht(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")?W('the "enable-ssr" attribute').loadState(this):null}async _loadStateFromSource(){try{if(this.hasAttribute("state")){return function(t){const e=document.getElementById(t);if(e&&"application/json"===e.type)try{return JSON.parse(e.textContent||"{}")}catch(t){p("Failed to parse JSON from script element:"+t)}return{}}(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.`)},ut),s=await this._setStatePromise;return clearTimeout(t),s}}}{const t=this.getAttribute("src");if(t&&t.endsWith(".json"))return await async function(t){try{const e=await fetch(t);return e.ok||p(`Failed to fetch JSON file: ${e.statusText}`),await e.json()}catch(t){return console.error("Failed to load JSON file:",t),{}}}(t);if(t&&t.endsWith(".js"))return await n(t);p(`Unsupported src file type: ${t}`)}}catch(t){p(`Failed to initialize state: ${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&&(V(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;throw this._initializeFailed=!0,console.error(`[@wcstack/state] <${e.tagNames.state}> failed to initialize.`,t),this._resolveInitialize?.(),this._resolveLoading?.(),this._connectedCallbackPromise.catch(()=>{}),this._rejectConnectedCallback?.(t),s&&null!==this._rootNode&&null===R(this._rootNode)&&(q(this._rootNode,t),i(this,this._rootNode,t)),t}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{st in t&&await t[N]()})}_callStateDisconnectedCallback(){this.createState("writable",t=>{nt 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||V(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;const s=this.parentNode;if(s instanceof ShadowRoot&&s.host.hasAttribute(pt))try{r("dcc",`a <${e.tagNames.state}> inside a [${pt}] host`)}catch(t){this._failInitializeLoudly(t)}if(this.hasAttribute("mount"))try{r("scopes",'the "mount" attribute')}catch(t){this._failInitializeLoudly(t,!1)}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 W('the "enable-ssr" attribute').emitSnapshot(this)}catch(t){throw this._rejectConnectedCallback?.(t),t}Ht(this,n),this._resolveConnectedCallback?.()}disconnectedCallback(){if(!h(this)&&null!==this._rootNode){if(!this._initialized)return this._initializeFailed&&c(this,this._rootNode),void(this._rootNode=null);try{this._callStateDisconnectedCallback()}finally{V(this.rootNode,null),It(this),Ot(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()}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",ft)}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 _t(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=Tt(t,e);null===this._addressHooks&&(this._addressHooks=Gt()),Mt(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",mt)}_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){return this._addDependency(this._dynamicDependency,t,e)}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=ct(t);if(this._pathSet.add(t),Ut?.check(this,this.__state,t,s),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=ct(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 Xt(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(Nt(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){te(this,t,this._pathRegistrations.keys())}}const se=[];function ne(t){se.includes(t)||se.push(t)}function ae(t=customElements){for(let e=0;e<se.length;e++)se[e](t);t.get(e.tagNames.state)||t.define(e.tagNames.state,ee)}export{Yt as H,ne as a,ae as r};
|
|
1
|
+
import{i as t,c as e,a 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 h,h as c,i as u}from"./lifecycleHooks.js";import{r as p,d as f}from"./errorGuidance.js";import{d as _,k as m,l as g,af as y,c as b,x as k,I as S,ag as w,H as P,ah as v,ai as $,aj as C,ak as x,al as I,am as A,an as N,ao as E,ap as z,G as D,j as L,y as R,o as j,aq as H,ar as O,as as T,at as G,au as M,g as F,av as U,aw as W,ax as V,ay as q}from"./binder.js";import{u as K,v as B,w as J,b as Q,x as X,m as Y,D as Z,W as tt,R as et,y as st,z as nt,o as at,A as it,I as ot,B as rt,M as lt,c as dt,d as ht,g as ct,N as ut,i as pt,l as ft,C as _t,f as mt}from"./pathDiagnostics.js";import{d as gt,e as yt,w as bt,f as kt,r as St,c as wt,b as Pt,g as vt,s as $t,h as Ct,a as xt,i as It}from"./setAll.js";import{N as At,g as Nt,b as Et,c as zt,d as Dt,e as Lt,f as Rt,h as jt,i as Ht,j as Ot,k as Tt,l as Gt,m as Mt,n as Ft}from"./getAllPropertyDescriptors.js";import{p as Ut}from"./diagnosticsHooks.js";class Wt{_loopContextStack=Array(K).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>=K&&p(`Exceeded maximum loop context stack depth of ${K}. 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 Vt(t,e){const s=t.getterPaths;if(0===s.size)return!1;for(const t of ct(e).cumulativePaths)if(s.has(t))return!0;return!1}const qt=/^\$\d+$/,Kt=`${dt}${Z}`,Bt=`${ht}${Z}`,Jt=new WeakMap;function Qt(t,e,s,n){const a=ot[e];if(void 0===a&&"string"==typeof e&&36===e.charCodeAt(0)&&qt.test(e)&&p(`[wcs/index-param-range] "${e}" is not a valid list index parameter: they run from ${rt}1 to ${rt}${lt}, 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=S(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!==At)return o}}if("$"===e[0]){switch(e){case"$stateElement":return n.stateElement;case"$getAll":return(a,i)=>Pt(t,e,s,n)(a,i);case"$setAll":return(a,i,o,r)=>wt(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=gt(e),o=yt(t,i,s,n),r=m(i.pathInfo,o),l=g(a,r),d=b();d.enqueueAbsoluteAddress(l),bt(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 h=a.addressHooks;if(h){const t=h.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)=>St(t,e,s,n)(a,i,...o);case"$trackDependency":return t=>function(t,e,s,n){return t=>{-1!==t.indexOf(et)&&p(`[wcs/recursion-unsupported] $trackDependency("${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 e=n.lastAddressStack?.pathInfo??p("Internal error: lastAddressStack is null"),s=n.stateElement;n.stateElement.getterPaths.has(e.path)&&e.path!==t&&s.addDynamicDependency(t,e.path)}}(0,0,0,n)(t);case"$eq":return(t,e)=>{const a=n.addressStackLength>0?n.lastAddressStack:null;if(Vt(n.stateElement,t))return null!==a&&n.stateElement.getterPaths.has(a.pathInfo.path)&&w(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=Vt(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?w(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=S(a.listIndex,e-1,a.pathInfo.wildcardCount);if(null===i&&p(`$eqIndex("${t}", ${e}): no list index at that level.`),Vt(n.stateElement,t))return n.stateElement.getterPaths.has(a.pathInfo.path)&&w(n.stateElement,t),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?P(l):null;null!==e?v(n.stateElement,t,a.pathInfo,e,r):$(n.stateElement,t,i,g(n.stateElement,a),r)}return Object.is(r,i.index)};case"$untrackDependency":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 kt(n.stateElement)}if(!e.startsWith(Kt)&&!e.startsWith(Bt))return}const i=gt(e),o=yt(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=Jt.get(t);return void 0===e&&(e=new Map,Jt.set(t,e)),e}(n),i=a.get(e);if(void 0!==i)return i;let o;switch(e){case L: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 D:o=e=>vt(t,e,s,n);break;case z:o=e=>Ct(t,e,s,n);break;case E:o=(e,a)=>$t(t,e,a,s,n);break;case N:o=()=>async function(t,e,s){const n=Reflect.get(t,st);"function"==typeof n&&await n.call(s)}(t,0,s);break;case A:o=()=>function(t,e,s){const n=Reflect.get(t,nt);"function"==typeof n&&n.call(s)}(t,0,s);break;case I:o=e=>function(t,e,s,n){const a=Reflect.get(t,at);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)}}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,it);"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 Xt{_stateElement;_addressStack=Array(K).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>=K&&(this._hasRepeatedAddress()&&p(`[wcs/getter-cycle] Exceeded maximum address stack depth of ${K}. Possible circular dependency between path getters: ${this._describeAddressCycle()}`),p(`[wcs/getter-depth-exceeded] Exceeded maximum address stack depth of ${K} 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 Qt(t,e,s,this)}set(t,e,s,n){return xt(this),function(t,e,s,n,a){if("string"==typeof e){const i=gt(e),o=yt(t,i,n,a),r=m(i.pathInfo,o);return $t(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)}}const Yt="undefined"==typeof HTMLElement?class{}:HTMLElement;const Zt=new Set(["for","if","elseif","else"]);function te(e,s,n){const a=new Map;for(const t of n){const e=ct(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=G(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))}};M();try{if(e.createState("readonly",t=>{for(const n of s){const s=m(ct(n),null);r(s);try{bt(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)Zt.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=H("state",a);void 0!==o&&o.catch(O)}finally{T()}}class ee extends Yt{static hasConnectedCallbackPromise=!0;static getBindingsReady(t){return F(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 Wt}();_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){const e=this.__state,s=Ft();s.set("previousState",e),Et(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),zt(this,t,s),Dt(this,t,s),this._commandTokenNames=n,this._eventTokenNames=a,this._stateGeneration++,this.__state=t,void 0!==e&&Ut?.reset(this),this._hasUpdatedCallback=at in t,this._hasErrorCallback=it in t,U(this),Lt(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=Nt(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);Rt(this,t,s),this._listKeys=i,this._rebuildPathInfo(),jt(this,t,s),Ht(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")?W('the "enable-ssr" attribute').loadState(this):null}async _loadStateFromSource(){try{if(this.hasAttribute("state")){return function(t){const e=document.getElementById(t);if(e&&"application/json"===e.type)try{return JSON.parse(e.textContent||"{}")}catch(t){p("Failed to parse JSON from script element:"+t)}return{}}(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.`)},ut),s=await this._setStatePromise;return clearTimeout(t),s}}}{const t=this.getAttribute("src");if(t&&t.endsWith(".json"))return await async function(t){try{const e=await fetch(t);return e.ok||p(`Failed to fetch JSON file: ${e.statusText}`),await e.json()}catch(t){return console.error("Failed to load JSON file:",t),{}}}(t);if(t&&t.endsWith(".js"))return await n(t);p(`Unsupported src file type: ${t}`)}}catch(t){p(`Failed to initialize state: ${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&&(V(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;throw this._initializeFailed=!0,console.error(`[@wcstack/state] <${e.tagNames.state}> failed to initialize.`,t),this._resolveInitialize?.(),this._resolveLoading?.(),this._connectedCallbackPromise.catch(()=>{}),this._rejectConnectedCallback?.(t),s&&null!==this._rootNode&&null===R(this._rootNode)&&(q(this._rootNode,t),i(this,this._rootNode,t)),t}async _callStateConnectedCallback(){await this.createStateAsync("writable",async t=>{st in t&&await t[N]()})}_callStateDisconnectedCallback(){this.createState("writable",t=>{nt 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||V(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;const s=this.parentNode;if(s instanceof ShadowRoot&&s.host.hasAttribute(pt))try{r("dcc",`a <${e.tagNames.state}> inside a [${pt}] host`)}catch(t){this._failInitializeLoudly(t)}if(this.hasAttribute("mount"))try{r("scopes",'the "mount" attribute')}catch(t){this._failInitializeLoudly(t,!1)}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 W('the "enable-ssr" attribute').emitSnapshot(this)}catch(t){throw this._rejectConnectedCallback?.(t),t}Ht(this,n),this._resolveConnectedCallback?.()}disconnectedCallback(){if(!h(this)&&null!==this._rootNode){if(!this._initialized)return this._initializeFailed&&c(this,this._rootNode),void(this._rootNode=null);try{this._callStateDisconnectedCallback()}finally{V(this.rootNode,null),It(this),Ot(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()}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",ft)}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 _t(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=Tt(t,e);null===this._addressHooks&&(this._addressHooks=Gt()),Mt(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",mt)}_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){return this._addDependency(this._dynamicDependency,t,e)}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=ct(t);if(this._pathSet.add(t),Ut?.check(this,this.__state,t,s),null!==e.parentPath){let t=e;for(;null!==t.parentPath&&this.addStaticDependency(t.parentPath,t.path);)t=ct(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 Xt(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(Nt(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){te(this,t,this._pathRegistrations.keys())}}const se=[];function ne(t){se.includes(t)||se.push(t)}function ae(t=customElements){for(let e=0;e<se.length;e++)se[e](t);t.get(e.tagNames.state)||t.define(e.tagNames.state,ee)}export{Yt as H,ne as a,ae as r};
|
|
2
2
|
//# sourceMappingURL=registerComponents.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as t,v as e,C as n,W as s,E as a,l as o,D as l,o as r,F as i,G as d,s as c,H as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aA as h,H as p,l as g,aB as y,N as I,K as w,k as m,M as x,L as P,aC as v,F as A,aD as b,G as $,af as k,aE as R,aF as E,aG as S,aH as M,aI as j,aJ as C,aK as L,a6 as O,c as D,aL as T,ab as V,X as B,aM as N,J as H,x as G}from"./binder.js";import{N as q}from"./getAllPropertyDescriptors.js";import{c as z}from"./checkDependency.js";import{c as W}from"./filterRegistry.js";const F=new WeakMap;function K(t,e){let n=F.get(t);void 0===n&&(n=new Map,F.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const J=new WeakMap;function U(t){const e=J.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 K(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:K(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 J.set(t,n),n}function X(t){J.delete(t)}function Q(t){"readonly"===t.mutability&&u("This state is readonly.")}const Y=new Map;class Z{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const n=e.split("."),s=n.slice();let a=0,o=0,l=0,r="none";const i=[];for(let t=0;t<n.length;t++){const e=n[t];if("*"===e)s[t]="*",i.push(null),a++,l++;else{const n=Number(e);Number.isNaN(n)||(s[t]="*",i.push(n),o++,l++)}}const d=s.join("."),c=t(d);(a>0||o>0)&&(r=a===l?"context":o===l?"all":"partial"),this.path=e,this.segments=n,this.wildcardCount=l,this.wildcardType=r,this.wildcardIndexes=i,this.pathInfo=c}}function _(t){let e;return Y.get(t)??(Y.set(t,e=new Z(t)),e)}function tt(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const s=n.pathInfo.indexByWildcardPath[e];return void 0===s||null===n.listIndex?null:p(n.listIndex,s,n.pathInfo.wildcardCount)}function et(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function nt(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!==q)return r}}return q}function st(t,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}(U(i),o.pathInfo.segments);if(!(o.pathInfo.path in t)){if(null===o.parentAddress){const e=nt(i,o,null,l,r);if(e!==q)return e;u(n(o.pathInfo.path,t,i.getterPaths))}const e=at(t,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!==s&&!(d in Object(e))){const t=nt(i,o,Object(e),l,r);if(t!==q)return t}if(d===s){const t=o.listIndex?.index??u(a(`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(t,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(t,o.pathInfo.path,l)}finally{r.popAddress()}}function at(t,e,n,s){z(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!==q)return l}}return et(a,e)?function(t,e,n,s,a){const o=g(a,e),l=y(o),r=a.stateGeneration;if(null!==l&&!1===l.dirty&&l.generation===r)return l.value;const i=st(t,e,n,s,a);return I(o,{value:i,dirty:!1,generation:r}),i}(t,e,n,s,a):st(t,e,n,s,a)}function ot(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 p=m(h,o),y=g(n.stateElement,p),I=x(y),w=at(t,p,e,n),v=P(o,I,w).newIndexes,A=i[d]??null;if(l.set(y,w),null===A)for(let t=0;t<v.length;t++){const e=v[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=v[A]??u(`ListIndex not found at index ${A} 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())w(t,Array.isArray(e)?e:[]);return i}function lt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=at(t,m(r,o),e,n),d=v(i,o);null==d&&u(`ListIndexes not found: ${r.path}`);const c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function rt(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 it(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 dt(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];rt(i,n,s,r);const d=it(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 ct(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 ft(t,e,n,a){if(e.pathInfo.path in t)return!0;const o=e.parentAddress;if(null===o)return!1;const l=at(t,o,n,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=e.pathInfo.lastSegment;if(r===s){const t=e.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const ut=new WeakMap;function ht(t,e){null===e?ut.delete(t):ut.set(t,e)}function pt(e,n,s){const a=e.wildcardParentPaths[n],o=t(a),l=m(o,s),r=g(e.stateElement,l),i=x(r),d=e.stateProxy[A](l),c=P(l.listIndex,i,d);e.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 W.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,e.searchType);if(n===e.wildcardPaths.length-1)e.targetListIndexes.push(...f);else for(const t of f)pt(e,n+1,t)}const gt=[];function yt(t,e,n,s,a){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:a.newIndexes,movedRows:null}:0===a.addIndexSet.size&&0===a.changeIndexSet.size?0===a.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:gt,movedRows:null}:{fullRows:a.newIndexes,movedRows:null}:{fullRows:gt,movedRows:null}:{fullRows:a.addIndexSet,movedRows:a.changeIndexSet}}const It=[];function wt(e,n,s){const a=e.stateElement.indexDependentGetterPaths;if(!a||0===a.size)return It;let o=null;const r=n+l;for(const e of a){if(e!==n&&!e.startsWith(r))continue;const a=t(e);if(a.wildcardCount!==s.wildcardCount)return null;(o??=[]).push(a)}return o??It}function mt(e,n,a){const o=n.pathInfo.path,l=e.staticMap.get(o);if(l)for(const r of l){const l=t(r);if(e.listPathSet.has(o)&&l.lastSegment===s){const t=e.stateProxy[A](n),s=g(e.stateElement,n),i=x(s),d=P(n.listIndex,i,t);e.observedListValueByAbsAddress.set(s,Array.isArray(t)?t:[]);const c=yt(e,o,0,0,d);for(const t of c.fullRows){const n=m(l,t);e.result.add(n),a.push(n)}if(null!==c.movedRows){const t=wt(e,r,l);if(null===t)for(const t of c.movedRows){const n=m(l,t);e.result.add(n),a.push(n)}else if(t.length>0)for(const n of c.movedRows)for(const s of t){const t=m(s,n);e.result.add(t),a.push(t)}}}else{const t=m(l,n.listIndex);e.result.add(t),a.push(t)}}const r=e.dynamicMap.get(o);if(r)for(const s of r){const o=t(s),l=[];if(o.wildcardCount>0){const t=b(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=p(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};pt(a,t,s),l.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=p(n.listIndex,t-1,n.pathInfo.wildcardCount);l.push(e)}}else l.push(null);for(const t of l){const n=m(o,t);e.result.add(n),a.push(n)}}}function xt(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};!function(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),n(r),l.length=0,mt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}(f,e,r);for(const[t,e]of f.observedListValueByAbsAddress)w(t,e);return Array.from(f.result)}function Pt(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 vt(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 At(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 bt(t,e,n,s,a,o){const l=E(t,e),r=S(t,e);if(!l&&!r)return;const i=D(),d=W.enablePropagationContext?M()??null:null,c=t=>{k(t),i.enqueueAbsoluteAddress(t,d)};l&&j(t,e,n,s,a).forEach(c),r&&C(t,e,n?s:o(),a).forEach(c)}function $t(t,e,n,s,a,o,l="diff"){const r=W.enablePropagationContext?M()??L(-1):null,i=D();i.enqueueAbsoluteAddress(e,r),o&&k(e),xt(s.stateElement,t,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=g(s.stateElement,e);k(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:l,keyedMergePath:a})}function kt(t,e,n,s,a){a&&(t.getterPaths.has(e)?k(n):I(n,{value:s,dirty:!1,generation:t.stateGeneration}))}function Rt(t,e,n,o,l,r,i,d){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,o);const i=at(t,n,l,r),d=e.pathInfo.segments[e.pathInfo.segments.length-1];if(d===s){const t=e.listIndex?.index??u(a(`path "${e.pathInfo.path}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,o);r.pushAddress(e),r.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{$t(e,n,l,r,i,d)}}function Et(e,n,a,o,r,i,d,c){const f=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),h=at(e,f,r,i)??[];let p=(y=h,ut.get(y)??null);var y;if(null===p){const t=$(h)??[];p={value:[...h],listIndexes:[...t]},ht(h,p)}try{return Rt(e,n,a,o,r,i,d,c)}finally{const a=p.value.indexOf(o),d=at(e,f,r,i)??[],c=Array.isArray(d)?$(d)??[]:[],u=n.listIndex.index,y=-1!==a?p.listIndexes[a]:O(f.listIndex,-1);c[u]=y;if(new Set(d).size===p.value.length){for(let t=0;t<c.length;t++)c[t].index=t;ht(h,null),function(e,n,a,o,r,i){const d=i.stateElement,c=D(),f=g(d,e);T(f)===a&&(V(n.value,n.listIndexes),B(f,n.value),N(n.value));c.enqueueRenderOnlyAddress(f);const u=new Map;n.listIndexes.forEach((t,e)=>u.set(t,e));const h=t(e.pathInfo.path+l+s);for(let t=0;t<o.length;t++){const e=o[t],s=u.get(e);if(s===t)continue;const a=m(h,e),l=g(d,a);if(void 0===s){const e=H(d,h,n.listIndexes[t]??null);At(d,l,e),$t(a,l,r,i,null,et(d,a),"full");continue}xt(d,a,d.staticDependency,d.dynamicDependency,d.listPaths,r,"new",t=>{const e=g(d,t);k(e),c.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}}(f,p,d,c,r,i)}}}function St(e,n,a,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(a)){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=dt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=dt(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,a);if(null!==c)return function(e,n,a,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===$(o)&&P(c,null,o);const f=P(c,o,a.list),u=Mt(e,n,a.list,r,i,d),h=t(d+l+s);for(const n of a.matched){const s=ct(n.oldRow,n.newRow);if(0===s.length)continue;const a=f.newIndexes[n.position];for(const o of s){if(void 0===a){n.oldRow[o.field]=o.value;continue}const s=t(h.path+l+o.field);St(e,m(s,a),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return Mt(e,n,a,o,r,null)}function Mt(t,e,n,o,l,i){const d=l.stateElement,c=e.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let s=0;s<t.length;s++){const a=t[s](d,e,n,o,l);if(a!==q)return a}}const h=R();if(!(c in t)&&null!==e.parentAddress&&!d.elementPaths.has(c)){const p=at(t,e.parentAddress,o,l);if("object"==typeof p&&null!==p){const t=e.pathInfo.lastSegment,y=t===s?e.listIndex?.index:t;let I,w=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const t=void 0!==y&&y in p,e=void 0!==y?p[y]:void 0;if(t&&Object.is(e,n))return!0;I=e,w=!0}bt(d,c,w,I,n,()=>p[y]);const m=et(d,e),x=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:x,value:n,oldValue:I,hasOldValue:w}),Pt(d,c,x,I,w);let P=!1;try{if(void 0===y&&u(a(`path "${c}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0)),f&&0!==f.writeMissing.length&&t!==s&&!(y in p)){const t=f.writeMissing;for(let s=0;s<t.length;s++){P=!0;const a=t[s](d,e,p,y,n,o,l);if(a!==q)return a;P=!1}}return Reflect.set(p,y,n)}finally{$t(e,x,o,l,i,m),P?k(x):kt(d,c,x,n,m),vt(d,e.pathInfo,{value:n})}}}let p,y=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const s=at(t,e,o,l);if(ft(t,e,o,l)&&Object.is(s,n))return!0;p=s,y=!0}bt(d,c,y,p,n,()=>at(t,e,o,l));const I=d.elementPaths.has(e.pathInfo.path),w=et(d,e),m=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:m,value:n,oldValue:p,hasOldValue:y}),Pt(d,c,m,p,y);try{return I?Et(t,e,m,n,o,l,i,w):Rt(t,e,m,n,o,l,i,w)}finally{I||kt(d,c,m,n,w),vt(d,e.pathInfo,{value:n})}}function jt(e,n,s,a){return(n,o,...l)=>{const r=t(n);if(a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.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",n,r.wildcardParentPathInfos.length,o.length));const d=lt(e,s,a,r,o),c=m(r,d);if(0===l.length)return at(e,c,s,a);Q(a),St(e,c,l[0],s,a)}}function Ct(e,n,s,a){const o=jt(e,0,s,a);return(n,l)=>{const r=t(n);if(void 0===l||Array.isArray(l)||u(`$getAll("${n}") 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)+"."),a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.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",n,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=tt(a,r.wildcardPaths[t]);if(e){l=G(e,e.length);break}}if(void 0===l){const t=a.addressStackLength>0?a.lastAddressStack:null,e=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==e&&e.length>0&&u(d(n,t.pathInfo.path)),l=[]}}const c=ot(e,s,a,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function Lt(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return tt(s,a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`))??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=at(t,m(l,a),n,s),i=v(r,a)??u(`ListIndex not found: ${l.path}`),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 Ot(e,n,s,a){return(n,o,l,r)=>{Q(a);const d=t(n);Array.isArray(o)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),o.length>d.wildcardParentPathInfos.length&&u(i("$setAll",n,d.wildcardParentPathInfos.length,o.length));const h=!0===r?.spread,p="function"==typeof l;h&&p&&u(c(n,"cannot combine { spread: true } with a mapper function.")),h&&!Array.isArray(l)&&u(c(n,"requires an array as the value when { spread: true } is set."));const g=ot(e,s,a,d,o,{commitDiffBaseline:!1});h&&l.length!==g.length&&u(f(n,g.length,l.length));const y=[];for(let t=0;t<g.length;t++){const n=lt(e,s,a,d,g[t]);y.push(m(d,n))}let I=0;for(let t=0;t<y.length;t++){const n=y[t];let o;if(p){o=l(at(e,n,s,a),...g[t])}else o=h?l[t]:l;void 0!==o&&(St(e,n,o,s,a),I++)}return I}}export{Q as a,Ct as b,Ot as c,_ as d,Lt as e,U as f,at as g,ft as h,X as i,jt as r,St as s,xt as w};
|
|
1
|
+
import{g as t,w as e,E as n,W as s,F as a,m as o,D as l,p as r,G as i,H as d,t as c,J as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aA as h,I as p,l as g,aB as y,O as I,L as w,k as m,N as x,M as P,aC as v,G as A,aD as b,H as $,af as k,aE as R,aF as E,aG as S,aH as M,aI as j,aJ as O,aK as L,a6 as C,c as D,aL as T,ab as V,Y as B,aM as N,K as H,x as G}from"./binder.js";import{N as q}from"./getAllPropertyDescriptors.js";import{c as z}from"./checkDependency.js";import{c as W}from"./filterRegistry.js";const K=new WeakMap;function F(t,e){let n=K.get(t);void 0===n&&(n=new Map,K.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const J=new WeakMap;function U(t){const e=J.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 F(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:F(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 J.set(t,n),n}function Y(t){J.delete(t)}function Q(t){"readonly"===t.mutability&&u("This state is readonly.")}const X=new Map;class Z{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const n=e.split("."),s=n.slice();let a=0,o=0,l=0,r="none";const i=[];for(let t=0;t<n.length;t++){const e=n[t];if("*"===e)s[t]="*",i.push(null),a++,l++;else{const n=Number(e);Number.isNaN(n)||(s[t]="*",i.push(n),o++,l++)}}const d=s.join("."),c=t(d);(a>0||o>0)&&(r=a===l?"context":o===l?"all":"partial"),this.path=e,this.segments=n,this.wildcardCount=l,this.wildcardType=r,this.wildcardIndexes=i,this.pathInfo=c}}function _(t){let e;return X.get(t)??(X.set(t,e=new Z(t)),e)}function tt(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const s=n.pathInfo.indexByWildcardPath[e];return void 0===s||null===n.listIndex?null:p(n.listIndex,s,n.pathInfo.wildcardCount)}function et(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function nt(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!==q)return r}}return q}function st(t,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}(U(i),o.pathInfo.segments);if(!(o.pathInfo.path in t)){if(null===o.parentAddress){const e=nt(i,o,null,l,r);if(e!==q)return e;u(n(o.pathInfo.path,t,i.getterPaths))}const e=at(t,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!==s&&!(d in Object(e))){const t=nt(i,o,Object(e),l,r);if(t!==q)return t}if(d===s){const t=o.listIndex?.index??u(a(`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(t,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(t,o.pathInfo.path,l)}finally{r.popAddress()}}function at(t,e,n,s){z(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!==q)return l}}return et(a,e)?function(t,e,n,s,a){const o=g(a,e),l=y(o),r=a.stateGeneration;if(null!==l&&!1===l.dirty&&l.generation===r)return l.value;const i=st(t,e,n,s,a);return I(o,{value:i,dirty:!1,generation:r}),i}(t,e,n,s,a):st(t,e,n,s,a)}function ot(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 p=m(h,o),y=g(n.stateElement,p),I=x(y),w=at(t,p,e,n),v=P(o,I,w).newIndexes,A=i[d]??null;if(l.set(y,w),null===A)for(let t=0;t<v.length;t++){const e=v[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=v[A]??u(`ListIndex not found at index ${A} 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())w(t,Array.isArray(e)?e:[]);return i}function lt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=at(t,m(r,o),e,n),d=v(i,o);null==d&&u(`ListIndexes not found: ${r.path}`);const c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function rt(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 it(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 dt(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];rt(i,n,s,r);const d=it(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 ct(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 ft(t,e,n,a){if(e.pathInfo.path in t)return!0;const o=e.parentAddress;if(null===o)return!1;const l=at(t,o,n,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=e.pathInfo.lastSegment;if(r===s){const t=e.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const ut=new WeakMap;function ht(t,e){null===e?ut.delete(t):ut.set(t,e)}function pt(e,n,s){const a=e.wildcardParentPaths[n],o=t(a),l=m(o,s),r=g(e.stateElement,l),i=x(r),d=e.stateProxy[A](l),c=P(l.listIndex,i,d);e.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 W.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,e.searchType);if(n===e.wildcardPaths.length-1)e.targetListIndexes.push(...f);else for(const t of f)pt(e,n+1,t)}const gt=[];function yt(t,e,n,s,a){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:a.newIndexes,movedRows:null}:0===a.addIndexSet.size&&0===a.changeIndexSet.size?0===a.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:gt,movedRows:null}:{fullRows:a.newIndexes,movedRows:null}:{fullRows:gt,movedRows:null}:{fullRows:a.addIndexSet,movedRows:a.changeIndexSet}}const It=[];function wt(e,n,s){const a=e.stateElement.indexDependentGetterPaths;if(!a||0===a.size)return It;let o=null;const r=n+l;for(const e of a){if(e!==n&&!e.startsWith(r))continue;const a=t(e);if(a.wildcardCount!==s.wildcardCount)return null;(o??=[]).push(a)}return o??It}function mt(e,n,a){const o=n.pathInfo.path,l=e.staticMap.get(o);if(l)for(const r of l){const l=t(r);if(e.listPathSet.has(o)&&l.lastSegment===s){const t=e.stateProxy[A](n),s=g(e.stateElement,n),i=x(s),d=P(n.listIndex,i,t);e.observedListValueByAbsAddress.set(s,Array.isArray(t)?t:[]);const c=yt(e,o,0,0,d);for(const t of c.fullRows){const n=m(l,t);e.result.add(n),a.push(n)}if(null!==c.movedRows){const t=wt(e,r,l);if(null===t)for(const t of c.movedRows){const n=m(l,t);e.result.add(n),a.push(n)}else if(t.length>0)for(const n of c.movedRows)for(const s of t){const t=m(s,n);e.result.add(t),a.push(t)}}}else{const t=m(l,n.listIndex);e.result.add(t),a.push(t)}}const r=e.dynamicMap.get(o);if(r)for(const s of r){const o=t(s),l=[];if(o.wildcardCount>0){const t=b(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=p(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};pt(a,t,s),l.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=p(n.listIndex,t-1,n.pathInfo.wildcardCount);l.push(e)}}else l.push(null);for(const t of l){const n=m(o,t);e.result.add(n),a.push(n)}}}function xt(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};!function(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),n(r),l.length=0,mt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}(f,e,r);for(const[t,e]of f.observedListValueByAbsAddress)w(t,e);return Array.from(f.result)}function Pt(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 vt(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 At(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 bt(t,e,n,s,a,o){const l=E(t,e),r=S(t,e);if(!l&&!r)return;const i=D(),d=W.enablePropagationContext?M()??null:null,c=t=>{k(t),i.enqueueAbsoluteAddress(t,d)};l&&j(t,e,n,s,a).forEach(c),r&&O(t,e,n?s:o(),a).forEach(c)}function $t(t,e,n,s,a,o,l="diff"){const r=W.enablePropagationContext?M()??L(-1):null,i=D();i.enqueueAbsoluteAddress(e,r),o&&k(e),xt(s.stateElement,t,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=g(s.stateElement,e);k(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:l,keyedMergePath:a})}function kt(t,e,n,s,a){a&&(t.getterPaths.has(e)?k(n):I(n,{value:s,dirty:!1,generation:t.stateGeneration}))}function Rt(t,e,n,o,l,r,i,d){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,o);const i=at(t,n,l,r),d=e.pathInfo.segments[e.pathInfo.segments.length-1];if(d===s){const t=e.listIndex?.index??u(a(`path "${e.pathInfo.path}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,o);r.pushAddress(e),r.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{$t(e,n,l,r,i,d)}}function Et(e,n,a,o,r,i,d,c){const f=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),h=at(e,f,r,i)??[];let p=(y=h,ut.get(y)??null);var y;if(null===p){const t=$(h)??[];p={value:[...h],listIndexes:[...t]},ht(h,p)}try{return Rt(e,n,a,o,r,i,d,c)}finally{const a=p.value.indexOf(o),d=at(e,f,r,i)??[],c=Array.isArray(d)?$(d)??[]:[],u=n.listIndex.index,y=-1!==a?p.listIndexes[a]:C(f.listIndex,-1);c[u]=y;if(new Set(d).size===p.value.length){for(let t=0;t<c.length;t++)c[t].index=t;ht(h,null),function(e,n,a,o,r,i){const d=i.stateElement,c=D(),f=g(d,e);T(f)===a&&(V(n.value,n.listIndexes),B(f,n.value),N(n.value));c.enqueueRenderOnlyAddress(f);const u=new Map;n.listIndexes.forEach((t,e)=>u.set(t,e));const h=t(e.pathInfo.path+l+s);for(let t=0;t<o.length;t++){const e=o[t],s=u.get(e);if(s===t)continue;const a=m(h,e),l=g(d,a);if(void 0===s){const e=H(d,h,n.listIndexes[t]??null);At(d,l,e),$t(a,l,r,i,null,et(d,a),"full");continue}xt(d,a,d.staticDependency,d.dynamicDependency,d.listPaths,r,"new",t=>{const e=g(d,t);k(e),c.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}}(f,p,d,c,r,i)}}}function St(e,n,a,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(a)){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=dt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=dt(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,a);if(null!==c)return function(e,n,a,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===$(o)&&P(c,null,o);const f=P(c,o,a.list),u=Mt(e,n,a.list,r,i,d),h=t(d+l+s);for(const n of a.matched){const s=ct(n.oldRow,n.newRow);if(0===s.length)continue;const a=f.newIndexes[n.position];for(const o of s){if(void 0===a){n.oldRow[o.field]=o.value;continue}const s=t(h.path+l+o.field);St(e,m(s,a),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return Mt(e,n,a,o,r,null)}function Mt(t,e,n,o,l,i){const d=l.stateElement,c=e.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let s=0;s<t.length;s++){const a=t[s](d,e,n,o,l);if(a!==q)return a}}const h=R();if(!(c in t)&&null!==e.parentAddress&&!d.elementPaths.has(c)){const p=at(t,e.parentAddress,o,l);if("object"==typeof p&&null!==p){const t=e.pathInfo.lastSegment,y=t===s?e.listIndex?.index:t;let I,w=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const t=void 0!==y&&y in p,e=void 0!==y?p[y]:void 0;if(t&&Object.is(e,n))return!0;I=e,w=!0}bt(d,c,w,I,n,()=>p[y]);const m=et(d,e),x=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:x,value:n,oldValue:I,hasOldValue:w}),Pt(d,c,x,I,w);let P=!1;try{if(void 0===y&&u(a(`path "${c}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0)),f&&0!==f.writeMissing.length&&t!==s&&!(y in p)){const t=f.writeMissing;for(let s=0;s<t.length;s++){P=!0;const a=t[s](d,e,p,y,n,o,l);if(a!==q)return a;P=!1}}return Reflect.set(p,y,n)}finally{$t(e,x,o,l,i,m),P?k(x):kt(d,c,x,n,m),vt(d,e.pathInfo,{value:n})}}}let p,y=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const s=at(t,e,o,l);if(ft(t,e,o,l)&&Object.is(s,n))return!0;p=s,y=!0}bt(d,c,y,p,n,()=>at(t,e,o,l));const I=d.elementPaths.has(e.pathInfo.path),w=et(d,e),m=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:m,value:n,oldValue:p,hasOldValue:y}),Pt(d,c,m,p,y);try{return I?Et(t,e,m,n,o,l,i,w):Rt(t,e,m,n,o,l,i,w)}finally{I||kt(d,c,m,n,w),vt(d,e.pathInfo,{value:n})}}function jt(e,n,s,a){return(n,o,...l)=>{const r=t(n);if(a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.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",n,r.wildcardParentPathInfos.length,o.length));const d=lt(e,s,a,r,o),c=m(r,d);if(0===l.length)return at(e,c,s,a);Q(a),St(e,c,l[0],s,a)}}function Ot(e,n,s,a){const o=jt(e,0,s,a);return(n,l)=>{const r=t(n);if(void 0===l||Array.isArray(l)||u(`$getAll("${n}") 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)+"."),a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.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",n,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=tt(a,r.wildcardPaths[t]);if(e){l=G(e,e.length);break}}if(void 0===l){const t=a.addressStackLength>0?a.lastAddressStack:null,e=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==e&&e.length>0&&u(d(n,t.pathInfo.path)),l=[]}}const c=ot(e,s,a,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function Lt(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return tt(s,a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`))??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=at(t,m(l,a),n,s),i=v(r,a)??u(`ListIndex not found: ${l.path}`),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 Ct(e,n,s,a){return(n,o,l,r)=>{Q(a);const d=t(n);Array.isArray(o)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),o.length>d.wildcardParentPathInfos.length&&u(i("$setAll",n,d.wildcardParentPathInfos.length,o.length));const h=!0===r?.spread,p="function"==typeof l;h&&p&&u(c(n,"cannot combine { spread: true } with a mapper function.")),h&&!Array.isArray(l)&&u(c(n,"requires an array as the value when { spread: true } is set."));const g=ot(e,s,a,d,o,{commitDiffBaseline:!1});h&&l.length!==g.length&&u(f(n,g.length,l.length));const y=[];for(let t=0;t<g.length;t++){const n=lt(e,s,a,d,g[t]);y.push(m(d,n))}let I=0;for(let t=0;t<y.length;t++){const n=y[t];let o;if(p){o=l(at(e,n,s,a),...g[t])}else o=h?l[t]:l;void 0!==o&&(St(e,n,o,s,a),I++)}return I}}export{Q as a,Ot as b,Ct as c,_ as d,Lt as e,U as f,at as g,ft as h,Y as i,jt as r,St as s,xt as w};
|
|
2
2
|
//# sourceMappingURL=setAll.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const o="3.
|
|
1
|
+
const o="3.1.0";export{o as V};
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{E as t,F as e,k as n,G as o,H as r,I as s,x as a,c as i,f as c,e as u,J as f}from"./binder.js";import{S as l,o as d,k as h,g as p,M as w,p as y,q as m}from"./pathDiagnostics.js";import{a as g,r as v}from"./getAllPropertyDescriptors.js";import{i as b}from"./filterRegistry.js";import{r as $,L as x}from"./errorGuidance.js";const I=new WeakMap,P=new Set,j=new Set;function k(t){return t.byFromPath.size>0||t.byResetPath.size>0}function O(t,e,n){const o=t.get(e);void 0===o?t.set(e,[n]):o.push(n)}function M(t,e){E(t);const n=new Map,o=new Map,r=new Map;for(const t of e){"path"===t.source.kind&&O(n,t.source.path,t);for(const e of t.resetOn)O(o,e,t),"event"===t.source.kind&&O(r,e,t)}const s={entries:new Set(e),byFromPath:n,byResetPath:o,eventResetByPath:r};return I.set(t,s),s}function A(t){return I.get(t)}function E(t){S(t),I.delete(t)}function S(t){P.delete(t),j.delete(t)}const z=new WeakSet;let C=0;function W(t){return A(t.absolutePathInfo.stateElement)?.eventResetByPath.get(t.absolutePathInfo.pathInfo.path)}function R(t){if(0===j.size)return;if(e=t.absolutePathInfo.stateElement,!j.has(e))return;var e;const n=W(t);if(void 0!==n)for(const t of n)F(t)}function F(t){z.has(t)||(z.add(t),C++)}function D(t){return z.has(t)}function _(t){return!!z.delete(t)&&(C--,!0)}const B=/^(?:0|[1-9]\d*)$/;function G(t,e){const n=Object.getOwnPropertyDescriptor(t,e);return!0===n.enumerable&&"value"in n}function T(t){if("object"!=typeof t||null===t||Object.isFrozen(t))return null;const e=Object.getPrototypeOf(t);if(Array.isArray(t)){return e===Array.prototype&&Reflect.ownKeys(t).every(e=>"length"===e||"string"==typeof e&&B.test(e)&&G(t,e))?"array":null}return(e===Object.prototype||null===e)&&Reflect.ownKeys(t).every(e=>"string"==typeof e&&G(t,e))?"object":null}function q(t,e){const n=T(t);if(null===n)return t;const o=t,r=e.get(o);if(void 0!==r)return r;let s;s="array"===n?new Array(t.length):null===Object.getPrototypeOf(t)?Object.create(null):{},e.set(o,s);for(const t of Object.keys(o))s[t]=q(o[t],e);return s}function H(t){return q(t,new Map)}function K(t,e,n){if(Object.is(t,e))return!0;const o=T(e);if(null===o||"object"!=typeof t||null===t)return!1;const r=t,s=e;if("array"===o){if(!Array.isArray(t)||t.length!==e.length)return!1}else if(Array.isArray(t)||Object.keys(r).length!==Object.keys(s).length)return!1;if(T(t)!==o)return!1;let a=n.get(r);if(void 0===a)a=new Set,n.set(r,a);else if(a.has(s))return!0;if(a.add(s),"array"===o){for(let e=0;e<t.length;e++)if(!K(r[e],s[e],n))return!1;return!0}return Object.keys(s).every(t=>Object.prototype.hasOwnProperty.call(r,t)&&K(r[t],s[t],n))}function L(t,e){return K(t,e,new Map)}const N=new WeakMap;function J(t,e){if("function"!=typeof e)return;const n=N.get(e);void 0===n?N.set(e,new Set([t])):n.add(t)}function Q(t,e){return"function"==typeof e&&!0===N.get(e)?.has(t)}const U={"read-source":t=>`${l} could not read a "from" value for "${t}". That landing was not folded; the other landings of the batch still were.`,"read-output":t=>`${l} could not read the output "${t}". Nothing was folded or written.`,threw:t=>`${l} fold for "${t}" threw. The output was not written.`,"returned-promise":t=>`${l} fold for "${t}" returned a Promise. fold must be synchronous and return the next value; the output was not written.`,write:t=>`${l} could not write the output "${t}".`},V={"read-source":"evaluate","read-output":"evaluate",threw:"fold","returned-promise":"fold",write:"write"};function X(t,e,n){null!==d&&d({type:"state:watch-error",phase:e,path:`${l}.${t}`,error:n})}function Y(t,e,n){console.error(`[@wcstack/state] ${U[n](t)}`,e),X(t,V[n],e)}function Z(t){return null!==t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function tt(t,e){e.then(void 0,()=>{}),Y(t,new TypeError(`${l} fold for "${t}" returned a Promise. fold must be synchronous and return the next value.`),"returned-promise")}const et=new WeakSet;const nt=Symbol("wcs-stream-last-notified-uncertain"),ot=new WeakMap;function rt(t,e){return ot.get(t)?.get(e)??{status:"idle",error:null}}function st(t,e,n,o){let r=ot.get(t);void 0===r&&(r=new Map,ot.set(t,r)),r.set(e,{status:n,error:o})}function at(t,e){const n=ot.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function it(t,e){const n=ot.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:nt,error:Object.is(o.error,null)?null:nt})}const ct=new Set;function ut(t){ct.add(t)}function ft(t){ct.delete(t)}function lt(){return ct}const dt=new WeakMap;function ht(t,e){dt.set(t,e)}function pt(t){return dt.get(t)??new Map}function wt(t){ft(t);const e=dt.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,it(t,n.name)}function yt(t){wt(t),ft(t),dt.delete(t)}let mt=0,gt=0;function vt(t){mt=t+1}function bt(){mt=0}function $t(){mt>gt&&(gt=mt)}const xt=new WeakMap;function It(t,e,n){let o=xt.get(t);void 0===o&&(o=new Map,xt.set(t,o)),o.set(e,n)}const Pt=new Map;function jt(t,e){Pt.has(t)||Pt.set(t,e)}function kt(t){return Pt.get(t)}const Ot=new WeakMap,Mt=new WeakMap,At=new Set,Et=new Map;function St(t){return Ot.get(t)??Et}function zt(t){At.add(t),function(t){const e=I.get(t);void 0!==e&&(k(e)&&P.add(t),function(t){return t.eventResetByPath.size>0}(e)&&j.add(t))}(t)}function Ct(){return At}function Wt(t,e){let n=Mt.get(t);void 0===n&&(n=new Map,Mt.set(t,n));for(const t of e){const e=n.get(t.path);void 0===e?n.set(t.path,[t]):e.push(t)}}const Rt=new Map;function Ft(t){return Mt.get(t)??Rt}function Dt(t){0===t.length&&$(`[wcs/watch-declaration-invalid] ${h} entry name must be a non-empty state path.`),t.startsWith("$")&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not start with "$" (reserved namespace).${x}`),t.includes("@")&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not contain "@" — the name selector was removed in v2; watch only paths of the state tree.${x}`),t in Object.prototype&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const e=p(t);for(const n of e.segments)0===n.length&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" has an empty path segment.${x}`);return e.wildcardCount>w&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" exceeds the maximum wildcard depth (${w}).`),e}function _t(t,e){const n=e[h];if(void 0===n)return null;"object"==typeof n&&null!==n||$(`[wcs/watch-declaration-invalid] ${h} must be an object mapping state paths to handler functions.${x}`);const o=new Map,r=new Set;let s=0;for(const[e,a]of Object.entries(n)){"function"!=typeof a&&$(`[wcs/watch-declaration-invalid] ${h} entry "${e}" must be a function.${x}`);const n=Dt(e);o.set(e,{path:e,pathInfo:n,handler:a,order:s++}),r.add(e),t.setPathInfo(e,"prop","watch")}return function(t,e){Ot.set(t,e)}(t,o),r.size>0?r:null}const Bt={writeObserve(t,e,n,o,r){if(!r)return;const s=t.watchPaths,a=t.scanPaths;!0!==s?.has(e)&&!0!==a?.has(e)||jt(n,o)},swapped(t,e,n){var o;o=n,Pt.has(o)&&jt(e,kt(n))}};function Gt(e){for(let n=e;null!==n;n=n.parentListIndex)if(t(n))return!0;return!1}function Tt(a,i,c){const u=c.absAddress.listIndex;let f="current",l=null;for(let d=0;d<i.wildcardCount;d++){const h=a[e](n(i.wildcardParentPathInfos[d],l)),p=o(h)?.[c.indexes[d]];if(void 0===p)return"gone";const w=r(u,d,i.wildcardCount);if(p!==w&&!s(p,w)){if(t(w))return"gone";f="replaced"}l=p}return f}function qt(t,e,n){const o=new Map;for(const r of n){const n=Tt(t,e,r);if("gone"===n)continue;const s="current"===n?1:0,a=r.indexes.join(","),i=o.get(a);(void 0===i||s>i.rank)&&o.set(a,{row:r,rank:s})}return Array.from(o.values(),t=>t.row)}const Ht=Object.freeze([]);function Kt(t,e,n){let o=t.get(n);return void 0===o&&(o={stateElement:e,entry:n,rows:[],reset:!1},t.set(n,o)),o}function Lt(t,e){let n=0;for(;n<t.indexes.length-1&&t.indexes[n]===e.indexes[n];)n++;return t.indexes[n]-e.indexes[n]}function Nt(t,e){return e.has(t.stateElement)&&!0===A(t.stateElement)?.entries.has(t.entry)}function Jt(t){const{entry:e,stateElement:n}=t;"event"!==e.source.kind||e.resetOn.some(t=>Qt(n,t))||_(e)}function Qt(t,e){return i().hasQueuedPath(t,e)}function Ut(t,e){!function(t,e,n){if(0!==C)for(const o of t){const t=o.absolutePathInfo.stateElement;if(!0===e?.has(t))continue;const r=W(o);if(void 0!==r)for(const e of r)e.resetOn.some(e=>n(t,e))||_(e)}}(t,e,Qt)}function Vt(t,e,n){return 0===e.pathInfo.wildcardCount?t[e.path]:t.$resolve(e.path,n.indexes)}function Xt(t,e,n){if(!Nt(t,n))return Jt(t),null;const{stateElement:o,entry:r}=t;if(t.reset)return{group:t,next:r.initial};const s=r.source;if(function(t,e){for(const n of e.pathInfo.cumulativePaths)if(t.getterPaths.has(n))return!0;return!1}(o,s))return function(t,e,n){if(et.has(t))return;et.add(t);const o=`[wcs/scan-source-computed] ${l} entry "${e}" from "${n}" is now backed by a getter (registered after the declaration, e.g. by a volume). A getter re-evaluates whenever its inputs change, so this scan stopped folding. Fold the plain value the getter reads instead.`;console.error(`[@wcstack/state] ${o}`),X(e,"fold",new Error(o))}(r,r.name,s.path),null;if(function(t,e,n){const o=pt(t).get(e);if(void 0===o)return!1;for(const t of o.depAddresses)if(n.has(t))return!0;return!1}(o,s.pathInfo.segments[0],e))return null;const a={plan:null,failure:"read-output"};try{o.createState("readonly",e=>{const n=e[r.name],o=0===s.pathInfo.wildcardCount?t.rows:qt(e,s.pathInfo,t.rows);a.failure="threw";const i=r.fold;let c=n;for(const t of o.sort(Lt)){let n;try{n=Vt(e,s,t)}catch(t){Y(r.name,t,"read-source");continue}const o=i(c,n,kt(t.absAddress),...t.indexes);if(Z(o))return void tt(r.name,o);c=o}Object.is(c,n)||(a.plan={group:t,next:c})})}catch(t){Y(r.name,t,a.failure)}return a.plan}function Yt(t,e){const{group:n}=t;if(!Nt(n,e))return void Jt(n);const{stateElement:o,entry:r}=n;if(!n.reset||"event"!==r.source.kind||_(r))try{o.createState("writable",e=>{const o=e[r.name];if(n.reset?!L(o,r.initial):!Object.is(o,t.next)){const o=n.reset?H(r.initial):t.next;e[r.name]=o,J(r.name,o)}})}catch(t){Y(r.name,t,"write")}}function Zt(t,e,n){if(Ut(t,e),0===P.size)return Ht;const o=new Map;for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=A(t);if(void 0===r)continue;const s=n.absolutePathInfo.pathInfo,i=r.byFromPath.get(s.path);if(void 0!==i){let e=[];if(s.wildcardCount>0){if(null===n.listIndex)continue;e=a(n.listIndex,s.wildcardCount)}for(const r of i)Kt(o,t,r).rows.push({absAddress:n,indexes:e})}const c=r.byResetPath.get(s.path);if(void 0!==c)for(const e of c)Kt(o,t,e).reset=!0}if(0===o.size)return Ht;const r=Array.from(o.values()).sort((t,e)=>t.entry.order-e.entry.order),s=[];vt(n);try{for(const n of r){const o=Xt(n,t,e);null!==o&&s.push(o)}}finally{bt()}return s}function te(t){ue(),(0!==St(t).size||0!==Ft(t).size||function(t){const e=I.get(t);return void 0!==e&&k(e)}(t))&&(zt(t),function(t){const e=[];for(const n of St(t).values())ee(t,n)&&e.push(n);for(const n of Ft(t).values())for(const o of n)ee(t,o)&&e.push(o);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{It(t,f(t,o.pathInfo,null),n[o.path])}catch(e){oe(t,o.path,"prime",e)}})}(t))}function ee(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const ne={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function oe(t,e,n,o){console.error(`[@wcstack/state] $watch ${ne[n]} "${e}" threw.`,o),null!==d&&d({type:"state:watch-error",phase:n,path:e,error:o})}function re(t){const e=Ct();try{if(0===e.size)return void Ut(t,e);const n=function(){const t=gt;return gt=0,t}();if(n>m){Ut(t,null);const e=Array.from(t,t=>t.absolutePathInfo.pathInfo.path);return console.error("[@wcstack/state] $watch chain depth limit exceeded; $scan folds and $watch handlers for this batch were skipped.",{maxDepth:m,paths:e}),void(null!==d&&d({type:"state:watch-chain-limit",maxDepth:m,paths:e}))}!function(t,e,n){if(0!==t.length){vt(n);try{for(const n of t)Yt(n,e)}finally{bt()}}}(Zt(t,e,n),e,n),function(t,e,n){const o=[];for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=n.absolutePathInfo.pathInfo.path,s=St(t).get(r),i=Ft(t).get(r);if(void 0===s&&void 0===i)continue;const c=void 0===s?[]:[s];void 0!==i&&c.push(...i);for(const e of c){let r=[];if(e.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=a(n.listIndex,e.pathInfo.wildcardCount)}o.push({stateElement:t,entry:e,absAddress:n,indexes:r})}}if(0===o.length)return;o.sort(ae);const r=function(t){let e=null;for(let n=0;n<t.length;n++){const o=t[n];if(0===o.entry.pathInfo.wildcardCount)continue;const r=t[n-1];(Gt(o.absAddress.listIndex)||r?.entry===o.entry&&se(r.indexes,o.indexes))&&(e??=new Set).add(o.entry)}if(null===e)return t;const n=new Set;for(const o of e){const e=t.filter(t=>t.entry===o),r=e[0].stateElement;try{r.createState("readonly",t=>{const r=new Set(qt(t,o.pathInfo,e));for(const t of e)r.has(t)||n.add(t)})}catch(t){oe(0,o.path,"evaluate",t);for(const t of e)n.add(t)}}return t.filter(t=>!n.has(t))}(o);vt(n);try{for(const t of r){if(!e.has(t.stateElement))continue;const n=St(t.stateElement).get(t.entry.path)===t.entry,o=!0===Ft(t.stateElement).get(t.entry.path)?.includes(t.entry);(n||o)&&ie(t)}}finally{bt()}}(t,e,n)}finally{Pt.clear()}}function se(t,e){for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function ae(t,e){if(t.entry.order!==e.entry.order)return t.entry.order-e.entry.order;const n=Math.min(t.indexes.length,e.indexes.length);for(let o=0;o<n;o++)if(t.indexes[o]!==e.indexes[o])return t.indexes[o]-e.indexes[o];return t.indexes.length-e.indexes.length}function ie(t){const{stateElement:e,entry:n,absAddress:o,indexes:r}=t,s=ee(e,n);try{e.createState("writable",t=>{let a;try{a=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,n,r)}catch(t){return void oe(0,n.path,"evaluate",t)}const i=s?function(t,e){return xt.get(t)?.get(e)}(e,o):kt(o);s&&It(e,o,a),null!==d&&d({type:"state:watch-fired",path:n.path,stateElement:e}),n.handler.call(t,a,i,...r)})}catch(t){oe(0,n.path,"handler",t)}}let ce=!1;function ue(){ce||(ce=!0,g("watch",Bt),v("watch",fe),c(re,y),u($t))}const fe={order:10,register(t,e){var n;n=t,At.delete(n),S(n),Ot.delete(n),function(t){xt.delete(t)}(t);const o=_t(t,e);t.setWatchPaths?.(o),null===o&&null==t.scanPaths||t.attachAddressHooks?.("watch",null!==o?h:l)},activate(t,e){b()||null==t.connectedRootNode||(null===e?!0===t.initialized:e===t.connectGeneration)&&te(t)},deactivate(t){var e;e=t,At.delete(e),S(e)}};export{te as A,E as a,H as b,_ as c,Z as d,tt as e,Y as f,A as g,D as h,L as i,ht as j,pt as k,wt as l,F as m,R as n,yt as o,at as p,ut as q,J as r,M as s,lt as t,rt as u,st as v,Q as w,ue as x,Dt as y,Wt as z};
|
|
1
|
+
import{F as t,G as e,k as n,H as o,I as r,J as s,x as a,c as i,f as c,e as u,K as f}from"./binder.js";import{S as l,p as d,l as h,g as p,M as w,q as y,r as m}from"./pathDiagnostics.js";import{a as g,r as v}from"./getAllPropertyDescriptors.js";import{i as b}from"./filterRegistry.js";import{r as $,L as x}from"./errorGuidance.js";const I=new WeakMap,P=new Set,j=new Set;function k(t){return t.byFromPath.size>0||t.byResetPath.size>0}function O(t,e,n){const o=t.get(e);void 0===o?t.set(e,[n]):o.push(n)}function M(t,e){E(t);const n=new Map,o=new Map,r=new Map;for(const t of e){"path"===t.source.kind&&O(n,t.source.path,t);for(const e of t.resetOn)O(o,e,t),"event"===t.source.kind&&O(r,e,t)}const s={entries:new Set(e),byFromPath:n,byResetPath:o,eventResetByPath:r};return I.set(t,s),s}function A(t){return I.get(t)}function E(t){S(t),I.delete(t)}function S(t){P.delete(t),j.delete(t)}const z=new WeakSet;let C=0;function W(t){return A(t.absolutePathInfo.stateElement)?.eventResetByPath.get(t.absolutePathInfo.pathInfo.path)}function R(t){if(0===j.size)return;if(e=t.absolutePathInfo.stateElement,!j.has(e))return;var e;const n=W(t);if(void 0!==n)for(const t of n)F(t)}function F(t){z.has(t)||(z.add(t),C++)}function D(t){return z.has(t)}function _(t){return!!z.delete(t)&&(C--,!0)}const B=/^(?:0|[1-9]\d*)$/;function G(t,e){const n=Object.getOwnPropertyDescriptor(t,e);return!0===n.enumerable&&"value"in n}function K(t){if("object"!=typeof t||null===t||Object.isFrozen(t))return null;const e=Object.getPrototypeOf(t);if(Array.isArray(t)){return e===Array.prototype&&Reflect.ownKeys(t).every(e=>"length"===e||"string"==typeof e&&B.test(e)&&G(t,e))?"array":null}return(e===Object.prototype||null===e)&&Reflect.ownKeys(t).every(e=>"string"==typeof e&&G(t,e))?"object":null}function T(t,e){const n=K(t);if(null===n)return t;const o=t,r=e.get(o);if(void 0!==r)return r;let s;s="array"===n?new Array(t.length):null===Object.getPrototypeOf(t)?Object.create(null):{},e.set(o,s);for(const t of Object.keys(o))s[t]=T(o[t],e);return s}function q(t){return T(t,new Map)}function H(t,e,n){if(Object.is(t,e))return!0;const o=K(e);if(null===o||"object"!=typeof t||null===t)return!1;const r=t,s=e;if("array"===o){if(!Array.isArray(t)||t.length!==e.length)return!1}else if(Array.isArray(t)||Object.keys(r).length!==Object.keys(s).length)return!1;if(K(t)!==o)return!1;let a=n.get(r);if(void 0===a)a=new Set,n.set(r,a);else if(a.has(s))return!0;if(a.add(s),"array"===o){for(let e=0;e<t.length;e++)if(!H(r[e],s[e],n))return!1;return!0}return Object.keys(s).every(t=>Object.prototype.hasOwnProperty.call(r,t)&&H(r[t],s[t],n))}function L(t,e){return H(t,e,new Map)}const N=new WeakMap;function J(t,e){if("function"!=typeof e)return;const n=N.get(e);void 0===n?N.set(e,new Set([t])):n.add(t)}function Q(t,e){return"function"==typeof e&&!0===N.get(e)?.has(t)}const U={"read-source":t=>`${l} could not read a "from" value for "${t}". That landing was not folded; the other landings of the batch still were.`,"read-output":t=>`${l} could not read the output "${t}". Nothing was folded or written.`,threw:t=>`${l} fold for "${t}" threw. The output was not written.`,"returned-promise":t=>`${l} fold for "${t}" returned a Promise. fold must be synchronous and return the next value; the output was not written.`,write:t=>`${l} could not write the output "${t}".`},V={"read-source":"evaluate","read-output":"evaluate",threw:"fold","returned-promise":"fold",write:"write"};function X(t,e,n){null!==d&&d({type:"state:watch-error",phase:e,path:`${l}.${t}`,error:n})}function Y(t,e,n){console.error(`[@wcstack/state] ${U[n](t)}`,e),X(t,V[n],e)}function Z(t){return null!==t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function tt(t,e){e.then(void 0,()=>{}),Y(t,new TypeError(`${l} fold for "${t}" returned a Promise. fold must be synchronous and return the next value.`),"returned-promise")}const et=new WeakSet;const nt=Symbol("wcs-stream-last-notified-uncertain"),ot=new WeakMap;function rt(t,e){return ot.get(t)?.get(e)??{status:"idle",error:null}}function st(t,e,n,o){let r=ot.get(t);void 0===r&&(r=new Map,ot.set(t,r)),r.set(e,{status:n,error:o})}function at(t,e){const n=ot.get(t);if(void 0!==n)for(const t of n.keys())e.has(t)||n.delete(t)}function it(t,e){const n=ot.get(t);if(void 0===n)return;const o=n.get(e);void 0!==o&&n.set(e,{status:"idle"===o.status?o.status:nt,error:Object.is(o.error,null)?null:nt})}const ct=new Set;function ut(t){ct.add(t)}function ft(t){ct.delete(t)}function lt(){return ct}const dt=new WeakMap;function ht(t,e){dt.set(t,e)}function pt(t){return dt.get(t)??new Map}function wt(t){ft(t);const e=dt.get(t);if(void 0!==e)for(const n of e.values())n.controller?.abort(),n.controller=null,n.status="idle",n.error=null,it(t,n.name)}function yt(t){wt(t),ft(t),dt.delete(t)}let mt=0,gt=0;function vt(t){mt=t+1}function bt(){mt=0}function $t(){mt>gt&&(gt=mt)}const xt=new WeakMap;function It(t,e,n){let o=xt.get(t);void 0===o&&(o=new Map,xt.set(t,o)),o.set(e,n)}const Pt=new Map;function jt(t,e){Pt.has(t)||Pt.set(t,e)}function kt(t){return Pt.get(t)}const Ot=new WeakMap,Mt=new WeakMap,At=new Set,Et=new Map;function St(t){return Ot.get(t)??Et}function zt(t){At.add(t),function(t){const e=I.get(t);void 0!==e&&(k(e)&&P.add(t),function(t){return t.eventResetByPath.size>0}(e)&&j.add(t))}(t)}function Ct(){return At}function Wt(t,e){let n=Mt.get(t);void 0===n&&(n=new Map,Mt.set(t,n));for(const t of e){const e=n.get(t.path);void 0===e?n.set(t.path,[t]):e.push(t)}}const Rt=new Map;function Ft(t){return Mt.get(t)??Rt}function Dt(t){0===t.length&&$(`[wcs/watch-declaration-invalid] ${h} entry name must be a non-empty state path.`),t.startsWith("$")&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not start with "$" (reserved namespace).${x}`),t.includes("@")&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not contain "@" — the name selector was removed in v2; watch only paths of the state tree.${x}`),t in Object.prototype&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" must not be a property name inherited from Object.prototype (e.g. "__proto__", "constructor").`);const e=p(t);for(const n of e.segments)0===n.length&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" has an empty path segment.${x}`);return e.wildcardCount>w&&$(`[wcs/watch-declaration-invalid] ${h} entry "${t}" exceeds the maximum wildcard depth (${w}).`),e}function _t(t,e){const n=e[h];if(void 0===n)return null;"object"==typeof n&&null!==n||$(`[wcs/watch-declaration-invalid] ${h} must be an object mapping state paths to handler functions.${x}`);const o=new Map,r=new Set;let s=0;for(const[e,a]of Object.entries(n)){"function"!=typeof a&&$(`[wcs/watch-declaration-invalid] ${h} entry "${e}" must be a function.${x}`);const n=Dt(e);o.set(e,{path:e,pathInfo:n,handler:a,order:s++}),r.add(e),t.setPathInfo(e,"prop","watch")}return function(t,e){Ot.set(t,e)}(t,o),r.size>0?r:null}const Bt={writeObserve(t,e,n,o,r){if(!r)return;const s=t.watchPaths,a=t.scanPaths;!0!==s?.has(e)&&!0!==a?.has(e)||jt(n,o)},swapped(t,e,n){var o;o=n,Pt.has(o)&&jt(e,kt(n))}};function Gt(e){for(let n=e;null!==n;n=n.parentListIndex)if(t(n))return!0;return!1}function Kt(a,i,c){const u=c.absAddress.listIndex;let f="current",l=null;for(let d=0;d<i.wildcardCount;d++){const h=a[e](n(i.wildcardParentPathInfos[d],l)),p=o(h)?.[c.indexes[d]];if(void 0===p)return"gone";const w=r(u,d,i.wildcardCount);if(p!==w&&!s(p,w)){if(t(w))return"gone";f="replaced"}l=p}return f}function Tt(t,e,n){const o=new Map;for(const r of n){const n=Kt(t,e,r);if("gone"===n)continue;const s="current"===n?1:0,a=r.indexes.join(","),i=o.get(a);(void 0===i||s>i.rank)&&o.set(a,{row:r,rank:s})}return Array.from(o.values(),t=>t.row)}const qt=Object.freeze([]);function Ht(t,e,n){let o=t.get(n);return void 0===o&&(o={stateElement:e,entry:n,rows:[],reset:!1},t.set(n,o)),o}function Lt(t,e){let n=0;for(;n<t.indexes.length-1&&t.indexes[n]===e.indexes[n];)n++;return t.indexes[n]-e.indexes[n]}function Nt(t,e){return e.has(t.stateElement)&&!0===A(t.stateElement)?.entries.has(t.entry)}function Jt(t){const{entry:e,stateElement:n}=t;"event"!==e.source.kind||e.resetOn.some(t=>Qt(n,t))||_(e)}function Qt(t,e){return i().hasQueuedPath(t,e)}function Ut(t,e){!function(t,e,n){if(0!==C)for(const o of t){const t=o.absolutePathInfo.stateElement;if(!0===e?.has(t))continue;const r=W(o);if(void 0!==r)for(const e of r)e.resetOn.some(e=>n(t,e))||_(e)}}(t,e,Qt)}function Vt(t,e,n){return 0===e.pathInfo.wildcardCount?t[e.path]:t.$resolve(e.path,n.indexes)}function Xt(t,e,n){if(!Nt(t,n))return Jt(t),null;const{stateElement:o,entry:r}=t;if(t.reset)return{group:t,next:r.initial};const s=r.source;if(function(t,e){for(const n of e.pathInfo.cumulativePaths)if(t.getterPaths.has(n))return!0;return!1}(o,s))return function(t,e,n){if(et.has(t))return;et.add(t);const o=`[wcs/scan-source-computed] ${l} entry "${e}" from "${n}" is now backed by a getter (registered after the declaration, e.g. by a volume). A getter re-evaluates whenever its inputs change, so this scan stopped folding. Fold the plain value the getter reads instead.`;console.error(`[@wcstack/state] ${o}`),X(e,"fold",new Error(o))}(r,r.name,s.path),null;if(function(t,e,n){const o=pt(t).get(e);if(void 0===o)return!1;for(const t of o.depAddresses)if(n.has(t))return!0;return!1}(o,s.pathInfo.segments[0],e))return null;const a={plan:null,failure:"read-output"};try{o.createState("readonly",e=>{const n=e[r.name],o=0===s.pathInfo.wildcardCount?t.rows:Tt(e,s.pathInfo,t.rows);a.failure="threw";const i=r.fold;let c=n;for(const t of o.sort(Lt)){let n;try{n=Vt(e,s,t)}catch(t){Y(r.name,t,"read-source");continue}const o=i(c,n,kt(t.absAddress),...t.indexes);if(Z(o))return void tt(r.name,o);c=o}Object.is(c,n)||(a.plan={group:t,next:c})})}catch(t){Y(r.name,t,a.failure)}return a.plan}function Yt(t,e){const{group:n}=t;if(!Nt(n,e))return void Jt(n);const{stateElement:o,entry:r}=n;if(!n.reset||"event"!==r.source.kind||_(r))try{o.createState("writable",e=>{const o=e[r.name];if(n.reset?!L(o,r.initial):!Object.is(o,t.next)){const o=n.reset?q(r.initial):t.next;e[r.name]=o,J(r.name,o)}})}catch(t){Y(r.name,t,"write")}}function Zt(t,e,n){if(Ut(t,e),0===P.size)return qt;const o=new Map;for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=A(t);if(void 0===r)continue;const s=n.absolutePathInfo.pathInfo,i=r.byFromPath.get(s.path);if(void 0!==i){let e=[];if(s.wildcardCount>0){if(null===n.listIndex)continue;e=a(n.listIndex,s.wildcardCount)}for(const r of i)Ht(o,t,r).rows.push({absAddress:n,indexes:e})}const c=r.byResetPath.get(s.path);if(void 0!==c)for(const e of c)Ht(o,t,e).reset=!0}if(0===o.size)return qt;const r=Array.from(o.values()).sort((t,e)=>t.entry.order-e.entry.order),s=[];vt(n);try{for(const n of r){const o=Xt(n,t,e);null!==o&&s.push(o)}}finally{bt()}return s}function te(t){ue(),(0!==St(t).size||0!==Ft(t).size||function(t){const e=I.get(t);return void 0!==e&&k(e)}(t))&&(zt(t),function(t){const e=[];for(const n of St(t).values())ee(t,n)&&e.push(n);for(const n of Ft(t).values())for(const o of n)ee(t,o)&&e.push(o);if(0===e.length)return;t.createState("readonly",n=>{for(const o of e)try{It(t,f(t,o.pathInfo,null),n[o.path])}catch(e){oe(t,o.path,"prime",e)}})}(t))}function ee(t,e){return 0===e.pathInfo.wildcardCount&&t.getterPaths.has(e.path)}const ne={prime:"initial evaluation of",evaluate:"evaluation of",handler:"handler for"};function oe(t,e,n,o){console.error(`[@wcstack/state] $watch ${ne[n]} "${e}" threw.`,o),null!==d&&d({type:"state:watch-error",phase:n,path:e,error:o})}function re(t){const e=Ct();try{if(0===e.size)return void Ut(t,e);const n=function(){const t=gt;return gt=0,t}();if(n>m){Ut(t,null);const e=Array.from(t,t=>t.absolutePathInfo.pathInfo.path);return console.error("[@wcstack/state] $watch chain depth limit exceeded; $scan folds and $watch handlers for this batch were skipped.",{maxDepth:m,paths:e}),void(null!==d&&d({type:"state:watch-chain-limit",maxDepth:m,paths:e}))}!function(t,e,n){if(0!==t.length){vt(n);try{for(const n of t)Yt(n,e)}finally{bt()}}}(Zt(t,e,n),e,n),function(t,e,n){const o=[];for(const n of t){const t=n.absolutePathInfo.stateElement;if(!e.has(t))continue;const r=n.absolutePathInfo.pathInfo.path,s=St(t).get(r),i=Ft(t).get(r);if(void 0===s&&void 0===i)continue;const c=void 0===s?[]:[s];void 0!==i&&c.push(...i);for(const e of c){let r=[];if(e.pathInfo.wildcardCount>0){if(null===n.listIndex)continue;r=a(n.listIndex,e.pathInfo.wildcardCount)}o.push({stateElement:t,entry:e,absAddress:n,indexes:r})}}if(0===o.length)return;o.sort(ae);const r=function(t){let e=null;for(let n=0;n<t.length;n++){const o=t[n];if(0===o.entry.pathInfo.wildcardCount)continue;const r=t[n-1];(Gt(o.absAddress.listIndex)||r?.entry===o.entry&&se(r.indexes,o.indexes))&&(e??=new Set).add(o.entry)}if(null===e)return t;const n=new Set;for(const o of e){const e=t.filter(t=>t.entry===o),r=e[0].stateElement;try{r.createState("readonly",t=>{const r=new Set(Tt(t,o.pathInfo,e));for(const t of e)r.has(t)||n.add(t)})}catch(t){oe(0,o.path,"evaluate",t);for(const t of e)n.add(t)}}return t.filter(t=>!n.has(t))}(o);vt(n);try{for(const t of r){if(!e.has(t.stateElement))continue;const n=St(t.stateElement).get(t.entry.path)===t.entry,o=!0===Ft(t.stateElement).get(t.entry.path)?.includes(t.entry);(n||o)&&ie(t)}}finally{bt()}}(t,e,n)}finally{Pt.clear()}}function se(t,e){for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function ae(t,e){if(t.entry.order!==e.entry.order)return t.entry.order-e.entry.order;const n=Math.min(t.indexes.length,e.indexes.length);for(let o=0;o<n;o++)if(t.indexes[o]!==e.indexes[o])return t.indexes[o]-e.indexes[o];return t.indexes.length-e.indexes.length}function ie(t){const{stateElement:e,entry:n,absAddress:o,indexes:r}=t,s=ee(e,n);try{e.createState("writable",t=>{let a;try{a=function(t,e,n){if(0===e.pathInfo.wildcardCount)return t[e.path];return t.$resolve(e.path,n)}(t,n,r)}catch(t){return void oe(0,n.path,"evaluate",t)}const i=s?function(t,e){return xt.get(t)?.get(e)}(e,o):kt(o);s&&It(e,o,a),null!==d&&d({type:"state:watch-fired",path:n.path,stateElement:e}),n.handler.call(t,a,i,...r)})}catch(t){oe(0,n.path,"handler",t)}}let ce=!1;function ue(){ce||(ce=!0,g("watch",Bt),v("watch",fe),c(re,y),u($t))}const fe={order:10,register(t,e){var n;n=t,At.delete(n),S(n),Ot.delete(n),function(t){xt.delete(t)}(t);const o=_t(t,e);t.setWatchPaths?.(o),null===o&&null==t.scanPaths||t.attachAddressHooks?.("watch",null!==o?h:l)},activate(t,e){b()||null==t.connectedRootNode||(null===e?!0===t.initialized:e===t.connectGeneration)&&te(t)},deactivate(t){var e;e=t,At.delete(e),S(e)}};export{te as A,E as a,q as b,_ as c,Z as d,tt as e,Y as f,A as g,D as h,L as i,ht as j,pt as k,wt as l,F as m,R as n,yt as o,at as p,ut as q,J as r,M as s,lt as t,rt as u,st as v,Q as w,ue as x,Dt as y,Wt as z};
|
|
2
2
|
//# sourceMappingURL=watchRuntime.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as e,i as t}from"../chunks/filterRegistry.js";import{
|
|
1
|
+
import{c as e,i as t}from"../chunks/filterRegistry.js";import{K as n,p as s,L as o}from"../chunks/pathDiagnostics.js";import{aN as r,D as i,Q as a,aO as c,aP as l,aQ as u,f as d,aR as f,y as m}from"../chunks/binder.js";import{g as p}from"../chunks/mount.js";import{r as h}from"../chunks/errorGuidance.js";import{V as y}from"../chunks/version.js";const g=/^\s*@@\s*(.*?)\s*:\s*(.+?)\s*$/;function k(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}}const v="__WCSTACK_DEVTOOLS_HOOK__";function N(){const e=globalThis,t=e[v];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[v]=n,n}const S=e=>{null!==s&&s({type:"state:update-batch",addresses:e})};function T(e){const t=null!==s;o(e);const r=null!==e;r&&!t?d(S,n):!r&&t&&f(S)}function w(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 P(e){return m(e)??h("devtools: no state tree on this root")}let b=null;function x(){if(t())return;if(null!==b)return;const n={id:"state:"+Math.random().toString(36).slice(2,10),kind:"state",packageVersion:y,getStateElements(){const e=[];for(const t of u())e.push(w(t));return e},overlays(e){const t=P(e);return p(t).map(e=>({marker:e.marker,componentTag:e.component.tagName.toLowerCase(),stateProp:e.stateProp,mountTable:e.entries.map(e=>({inner:e.innerSegments.join("."),outer:e.outerPathInfo.path})),delta:e.delta,privateKeys:Object.keys(e.privateSnapshot),getterKeys:[...e.getterKeys],exports:[...e.exports.keys()]}))},keyedSubscriptions:e=>function(e){const t=l(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}(P(e)),keys(e){const t=P(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 P(e).createState("readonly",e=>{s=e.$resolve(t,n??[])}),s},write(e,t,n,s){P(e).createState("writable",e=>{void 0!==s&&s.length>0?e.$resolve(t,s,n):e[t]=n})},getDeclaredBindings:t=>function(t){const n=[],s=new Set,o=new Set,l=e=>{const t=function(e){const t=[...e.inFilters,...e.outFilters].map(e=>`${e.filterName}(${e.args.join(",")})`).join("|");return[e.statePathName,e.propName,e.bindingType,t].join("\0")}(e);s.has(t)||(s.add(t),n.push(e))},u=e=>{if(o.has(e))return;o.add(e);const t=a(e);if(null!==t)for(const e of t.nodeInfos)for(const t of e.parseBindTextResults)l(k(null,t,"fragment","")),null!=t.uuid&&u(t.uuid)},d=(t.ownerDocument??t).createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT);for(let t=d.nextNode();null!==t;t=d.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=r(n,i(s));for(const t of e)l(k(n,t,"attribute",s))}catch{}continue}const n=g.exec(t.data.trim());if(null===n)continue;const s=n[1]||e.commentTextPrefix,o=n[2],d=a(o);if(null===d){if(s===e.commentTextPrefix)try{l(k(t,c(o),"comment",o))}catch{}}else l(k(t,d.parseBindTextResult,"comment",o)),u(o)}return n}(t),_setSink:T};b=n,N().register(n)}const _={name:"devtools",install(){x()}};export{_ as default,_ as devtools};
|
|
2
2
|
//# sourceMappingURL=devtools.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{s as e}from"../chunks/diagnosticsHooks.js";import{g as t,
|
|
1
|
+
import{s as e}from"../chunks/diagnosticsHooks.js";import{g as t,C as n,W as s,a8 as i,a9 as r,aa as o,p as a,D as c}from"../chunks/pathDiagnostics.js";import{d,L as u}from"../chunks/errorGuidance.js";const g=Object.freeze({existence:"unknown",missingSegment:"",candidates:Object.freeze([])}),f=Object.freeze({existence:"exists",missingSegment:"",candidates:Object.freeze([])});const l=new WeakMap;const m=new WeakMap,h=new WeakSet,p=new WeakMap;function k(e,t,n,s){console.warn(`[@wcstack/state] [${r[n]}] ${o[n]} "${t}" does not resolve on the state tree: "${s.missingSegment}" is not declared.${d(s.missingSegment,s.candidates)} Updates to this path will be silently dropped.${u}`),null!==a&&a({type:"state:path-unresolved",source:n,path:t,missingSegment:s.missingSegment})}const v={check:function(e,r,o,a){if("internal"===a||void 0===r)return;if(o.startsWith("$"))return;if(-1!==o.indexOf("#"))return;const d=e.addressHooks;if(d){const t=d.suppressPathDiagnostic;for(let n=0;n<t.length;n++)if(t[n](e,o))return}const u=t(o).segments;if("binding"===a&&u.length<2)return;if(function(e,t){let n=l.get(e);return void 0===n&&(n=new Set,l.set(e,n)),!!n.has(t)||(n.add(t),!1)}(e,o))return;if(!0===e.hasRecursion&&null!==e.recursionRegistry.recursiveGetterOwning(o))return;const v=function(e,r,o){if(void 0!==n(e,r))return f;const a=t(r).segments;let d=e,u="";for(let t=0;t<a.length;t++){const r=a[t],l=u;if(u=0===t?r:u+c+r,t>0&&t<a.length-1&&void 0!==n(e,u))return g;if(Object(d)!==d)return g;if(r===s){if(!Array.isArray(d)||0===d.length)return g;d=d[0];continue}const m=n(d,r);if(void 0===m)return{existence:"missing",missingSegment:r,candidates:i(d,l,o)};if("function"==typeof m.get)return t===a.length-1?f:g;d=m.value}return f}(r,o,e.getterPaths);"missing"===v.existence&&(function(e,t){return!0===p.get(e)?.has(t)}(e,o)||("binding"!==a?k(e,o,a,v):function(e,t,n){let s=m.get(e);void 0===s&&(s=new Map,m.set(e,s));if(s.set(t,n),h.has(e))return;h.add(e),setTimeout(()=>function(e){h.delete(e);const t=m.get(e);if(void 0===t)return;m.delete(e);for(const[n,s]of t)k(e,n,"binding",s)}(e),0)}(e,o,v)))},reset:function(e){l.delete(e),m.delete(e)},markExported:function(e,t){let n=p.get(e);void 0===n&&(n=new Set,p.set(e,n)),n.add(t),m.get(e)?.delete(t)}};let w=!1;const S={name:"diagnostics",install(){w||(w=!0,e(v))}};export{S as default,S as diagnostics};
|
|
2
2
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,N as t,g as n,r}from"../chunks/getAllPropertyDescriptors.js";import{R as s,D as i,W as o,M as a,r as c,g as l,s as h,m as u}from"../chunks/pathDiagnostics.js";import{g as f,a as d,s as p,b as g,c as m,d as v,e as w}from"../chunks/setAll.js";import{K as $,k as y,l as x,L as P,M as _,N as A,J as b,G as k}from"../chunks/binder.js";import{r as I}from"../chunks/errorGuidance.js";import"../chunks/checkDependency.js";import"../chunks/filterRegistry.js";function L(e){return-1!==e.indexOf(s)}function R(e,t){if(t===e.recursiveAnchor)return"";const n=e.recursiveAnchor+i;if(!t.startsWith(n))return null;const r=t.slice(e.recursiveAnchor.length);if(L(r))return null;const s=r.slice(i.length).split(i);return s[0]===o||s.some(e=>0===e.length)?null:r}function j(e){return 0===e.length?e:i+S(e.slice(i.length))}function O(e,t,n){const r=i+e.repeat,s=t.length<=n.length?t:n,o=t.length<=n.length?n:t;if(!o.endsWith(s))return!1;const a=o.slice(0,o.length-s.length);if(0===a.length)return!0;if(a.length%r.length!==0)return!1;for(let e=0;e<a.length;e+=r.length)if(!a.startsWith(r,e))return!1;return!0}function W(e,t,n){for(let r=n.length;r>0;r=n.lastIndexOf(i,r-1))if(O(e,t,n.slice(0,r)))return!0;return!1}function S(e){const t=e.split(i);for(let e=0;e<t.length;e++)t[e]===o||Number.isNaN(Number(t[e]))||(t[e]=o);return t.join(i)}function N(e,t){const n=e.repeat.split(i),r=i+e.repeat;let s=t;for(;s.startsWith(r);)s=s.slice(r.length);if(0===s.length||s===i+e.repeatList+i+"length")return!0;for(let e=1;e<n.length;e++)if(s===i+n.slice(0,e).join(i))return!0;return!1}function B(e,t,n){n<0&&I(`Recursion depth must not be negative (got ${n}).`);let r=e.anchor;for(let t=0;t<n;t++)r+=i+e.repeat;const s=r+t;let c=0;for(const e of s.split(i))e===o&&c++;return c>a&&I(`[wcs/recursion-depth-exceeded] Recursion on "${e.anchor}" reached depth ${n} ("${s}"), which needs ${c} wildcard levels — the limit is ${a}. Either the data nests deeper than the engine can address, or the tree contains a cycle.`),s}function E(e,t){return B(e,"",t)}function C(e,t,n){if(!n.startsWith(e.anchor))return null;if(t.length>0&&!n.endsWith(t))return null;if(n.length<e.anchor.length+t.length)return null;const r=n.slice(e.anchor.length,n.length-t.length);if(0===r.length)return 0;const s=i+e.repeat;let o=0,a=0;for(;a<r.length;){if(!r.startsWith(s,a))return null;a+=s.length,o++}return o}function G(e,t){if(0===e.addressStackLength)return null;const n=e.lastAddressStack;if(null===n)return null;const r=t.accessorFor(n.pathInfo.path);return null!==r?r.depth:function(e,t){const n=e.spec;if(!t.startsWith(n.anchor))return null;const r=i+n.repeat;let s=0,o=n.anchor.length;for(;t.startsWith(r,o);)o+=r.length,s++;return o!==t.length&&46!==t.charCodeAt(o)?null:s}(t,n.pathInfo.path)}function D(e,t,n){const r=e.recursionRegistry,s=R(r.spec,n);null===s&&I(c(n,r.spec.recursiveAnchor));const i=G(t,r);return null===i&&I(`[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,i)}function M(e,t,n,r,s){const o=r.spec,a=[],c=new Map,h=[],u=o.repeatList,d=o.anchorList,p=new Set,g=new Set,m=(e,t,n)=>{const r=e.wildcardParentPathInfos;if(t>=r.length)return void a.push(y(e,n));const s=v(r[t],n,null).rows;for(let n=0;n<s.length;n++)m(e,t+1,s[n])};function v(r,s,i){const a=y(r,s),l=x(n.stateElement,a),h=f(e,a,t,n),d=null===i?null:((e,t,n)=>{if(!Array.isArray(t)||0===t.length)return null;const r=t;return p.has(r)&&I(`[wcs/recursion-cycle] "${e}" is reachable from itself: the recursion on "${o.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)&&I(`[wcs/recursion-shared-list] "${e}" is the same array instance as a list reached from another node. The recursion on "${o.anchor}" needs a tree: give each node its own "${u}" array.`),r})(r.path,h,i),g=P(s,_(l),h);return c.set(l,Array.isArray(h)?h:[]),null!==d&&null!==i&&i.add(d),{rows:g.newIndexes,tracked:d}}const w=(e,t,n)=>{const{rows:o,tracked:c}=v(t,n,g);if(0===o.length)return;const f=(e=>{const t=h[e];if(void 0!==t)return t;const n=r.concretePathAt(s,e),o=0===s.length?n:r.concretePathAt("",e),a={nodePath:o,concretePathInfo:l(n),childListPathInfo:l(o+i+u)};return h[e]=a,a})(e),d=c;p.add(d);const $=f.concretePathInfo.wildcardCount===e+1;for(let t=0;t<o.length;t++){const n=o[t];$?a.push(y(f.concretePathInfo,n)):m(f.concretePathInfo,e+1,n),w(e+1,f.childListPathInfo,n)}p.delete(d)};w(0,l(d),null);for(const[e,t]of c)$(e,t);return a}function z(e,t,n,r,s,i,o){d(n);const a=n.stateElement.recursionRegistry,l=R(a.spec,r);null===l&&I(c(r,a.spec.recursiveAnchor));const u=j(l);Array.isArray(s)||I(h(r,'with "**" requires an explicit empty indexes array ([]) — the write API takes no context.')),s.length>0&&I(`[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 i&&I(h(r,'with "**" does not take a mapper yet — the index tuple has a different length at each depth.')),!0===o?.spread&&I(h(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){N(e,n)&&I(`[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.`)}(a.spec,r,u);const f=a.conflictingRecursiveGetter(u);null!==f&&I(`[wcs/recursion-readonly] "${r}" writes into the recursive getter "${f}", 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 g=M(e,t,n,a,l);let m=0;for(let r=0;r<g.length;r++)void 0!==i&&(p(e,g[r],i,t,n),m++);return m}const T={write(e,n){if(!0!==e.hasRecursion)return t;const r=e.recursionRegistry.recursiveGetterOwningPath(n.pathInfo);return null!==r&&I(`[wcs/recursion-readonly] "${n.pathInfo.path}" writes into the recursive getter "${r}" (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.`),t},get(e,n,r,s){if(!0!==e.stateElement.hasRecursion)return t;if("$getAll"===n)return(t,i)=>{if(L(t)){if(void 0!==i)return function(e,t,n,r,s){const i=n.stateElement.recursionRegistry,o=R(i.spec,r);null===o&&I(c(r,i.spec.recursiveAnchor)),Array.isArray(s)||I(`[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&&I(`[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 a=M(e,t,n,i,o),l=[];for(let r=0;r<a.length;r++)l.push(f(e,a[r],t,n));return l}(s,r,e,t,i);t=D(e.stateElement,e,t)}return g(s,n,r,e)(t,i)};if("$setAll"===n)return(t,i,o,a)=>L(t)?z(s,r,e,t,i,o,a):m(s,n,r,e)(t,i,o,a);if(36!==n.charCodeAt(0)&&L(n)){const t=v(D(e.stateElement,e,n)),i=w(s,t,r,e);return f(s,y(t.pathInfo,i),r,e)}return t}};let F=!1;function q(e,t){"string"==typeof t&&0!==t.length||I(`[wcs/recursion-declaration-invalid] ${u} ${e} must be a non-empty string.`);const n=t.split(i);n.some(e=>0===e.length)&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not contain empty path segments.`),n.length<2&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must name a list element: a property path ending with "${i}${o}" (for example "nodes${i}${o}").`),n[n.length-1]!==o&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must end with "${i}${o}" — it names the element of the list, not the list itself.`),36===n[0].charCodeAt(0)&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not start with "$" — that namespace is reserved.`),-1!==t.indexOf("#")&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not contain "#" — that segment is reserved for mounts.`);for(let r=0;r<n.length-1;r++)n[r]===o&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must have exactly one "${o}", at the end. Wildcards in the middle are not supported in this version.`),n[r]===s&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not contain "${s}" — the declaration is what gives "${s}" its meaning.`),isNaN(Number(n[r]))||I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not contain an index segment ("${n[r]}") — the recursion is declared over the shape of the tree, not over one row.`)}const H=new WeakSet;function J(e){return"function"==typeof e.get&&H.has(e.get)}function K(e,t,n){if(0!==n.size){for(const e of n){const n=Object.getOwnPropertyDescriptor(t,e);void 0!==n&&J(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))}}!function(e,t,n){for(const r of n){const n=l(r),s=n.wildcardParentPathInfos,i=(t,r,o)=>{if(o===s.length)return void A(b(e,n,r),null);const a=0===o?0:s[o-1].segments.length+1;let c=t;for(const e of s[o].segments.slice(a))c=c?.[e];if(!Array.isArray(c))return;const l=k(c);if(null===l)return;const h=Math.min(l.length,c.length);for(let e=0;e<h;e++)i(c[e],l[e],o+1)};i(t,null,0)}}(e,t,n)}}const Q="[wcs/recursion-declaration-invalid]";class U{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=n(t);for(const[t,n]of Object.entries(r)){if(!L(t))continue;"function"==typeof n.set&&I(`${Q} Recursive setters are not supported in this version: "${t}". Declare a plain path setter, or write through the concrete path.`),"function"!=typeof n.get&&I(`${Q} "${t}" contains "**" but is not a getter. The recursion wildcard only names a family of computed paths.`);const r=R(e,t);null===r&&I(c(t,e.recursiveAnchor)),0===r.length&&I(`${Q} "${t}" names the recursive node itself. "**" names a computed path under a node (for example "${e.recursiveAnchor}${i}total"), not the node.`),N(e,j(r))&&I(`${Q} "${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}${i}total").`),this._definitions.set(t,{recursivePath:t,suffix:r,get:n.get})}this._assertNoColliding(),this._assertNoConcreteCollision(r)}_assertNoConcreteCollision(e){for(const[t,n]of Object.entries(e)){if(L(t)||J(n))continue;const e=this._matchExpansion(t);null!==e&&I(`${Q} "${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++)O(this.spec,e[t].suffix,e[n].suffix)&&I(`${Q} "${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(W(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 n=S(e),r=this._ownerByPath.get(n);if(void 0!==r)return r;let s=null;if(n.startsWith(this.spec.anchor)){s=this._matchExpansion(n);for(let e=n.lastIndexOf(i);null===s&&e>this.spec.anchor.length;e=n.lastIndexOf(i,e-1))s=this._matchExpansion(n.slice(0,e))}return this._ownerByPath.set(n,s),s}_matchExpansion(e){for(const t of this._definitions.values())if(null!==C(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=C(this.spec,e.suffix,t);null!==n&&(null!==r&&I(`"${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||J(s)||I(`"${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,H.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 n of function(e,t){const n=[];n.push(e.anchorList);for(let r=0;r<t;r++)n.push(E(e,r)+i+e.repeatList);return n}(this.spec,t))this._registeredListPaths.has(n)||(this._registeredListPaths.add(n),e.addListPath(n))}forgetGenerated(e,t){const n=new Set(this._accessors.keys());return K(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=B(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 V="recursionSpec",X="recursionRegistry",Y={order:5,validateEarly(e,t,n){const r=function(e){const t=e[u];if(void 0===t)return null;"object"==typeof t&&null!==t||I(`[wcs/recursion-declaration-invalid] ${u} must be an object mapping one anchor path to its repeating sub-path (for example { "nodes.*": "children.*" }).`);const n=Object.entries(t);0===n.length&&I(`[wcs/recursion-declaration-invalid] ${u} must declare exactly one anchor; it is empty.`),n.length>1&&I(`[wcs/recursion-declaration-invalid] ${u} declares ${n.length} anchors (${n.map(([e])=>`"${e}"`).join(", ")}). This version supports exactly one self-recursive anchor per state.`);const[r,a]=n[0];q("anchor",r),"string"!=typeof a&&I(`[wcs/recursion-declaration-invalid] ${u} entry "${r}" must map to the repeating sub-path as a string (for example "children${i}${o}").`),q("repeating sub-path",a);const c=r.slice(0,r.lastIndexOf(i)),l=a.slice(0,a.lastIndexOf(i)),h=c+i+s;return Object.freeze({anchor:r,repeat:a,recursiveAnchor:h,anchorList:c,repeatList:l})}(t);n.set(V,r),n.set(X,null===r?null:new U(r,t))},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(X)??null;e.setRecursionRegistry?.(s),null!==s&&e.attachAddressHooks?.("recursion",u)},apply(e,t,n){const r=n.get(V)??null;null!==r&&e.addListPath(r.anchorList)}};let Z=!1;function ee(){Z||(Z=!0,F||(F=!0,e("recursion",T)),r("recursion",Y))}const te={name:"recursion",install(){ee()}};export{te as default,te as recursion};
|
|
1
|
+
import{a as e,N as t,g as n,r}from"../chunks/getAllPropertyDescriptors.js";import{R as s,D as i,W as o,M as a,s as c,g as l,t as h,n as u}from"../chunks/pathDiagnostics.js";import{g as f,a as d,s as p,b as g,c as m,d as v,e as w}from"../chunks/setAll.js";import{L as $,k as y,l as x,M as P,N as _,O as A,K as b,H as k}from"../chunks/binder.js";import{r as I}from"../chunks/errorGuidance.js";import"../chunks/checkDependency.js";import"../chunks/filterRegistry.js";function L(e){return-1!==e.indexOf(s)}function R(e,t){if(t===e.recursiveAnchor)return"";const n=e.recursiveAnchor+i;if(!t.startsWith(n))return null;const r=t.slice(e.recursiveAnchor.length);if(L(r))return null;const s=r.slice(i.length).split(i);return s[0]===o||s.some(e=>0===e.length)?null:r}function j(e){return 0===e.length?e:i+S(e.slice(i.length))}function O(e,t,n){const r=i+e.repeat,s=t.length<=n.length?t:n,o=t.length<=n.length?n:t;if(!o.endsWith(s))return!1;const a=o.slice(0,o.length-s.length);if(0===a.length)return!0;if(a.length%r.length!==0)return!1;for(let e=0;e<a.length;e+=r.length)if(!a.startsWith(r,e))return!1;return!0}function W(e,t,n){for(let r=n.length;r>0;r=n.lastIndexOf(i,r-1))if(O(e,t,n.slice(0,r)))return!0;return!1}function S(e){const t=e.split(i);for(let e=0;e<t.length;e++)t[e]===o||Number.isNaN(Number(t[e]))||(t[e]=o);return t.join(i)}function N(e,t){const n=e.repeat.split(i),r=i+e.repeat;let s=t;for(;s.startsWith(r);)s=s.slice(r.length);if(0===s.length||s===i+e.repeatList+i+"length")return!0;for(let e=1;e<n.length;e++)if(s===i+n.slice(0,e).join(i))return!0;return!1}function B(e,t,n){n<0&&I(`Recursion depth must not be negative (got ${n}).`);let r=e.anchor;for(let t=0;t<n;t++)r+=i+e.repeat;const s=r+t;let c=0;for(const e of s.split(i))e===o&&c++;return c>a&&I(`[wcs/recursion-depth-exceeded] Recursion on "${e.anchor}" reached depth ${n} ("${s}"), which needs ${c} wildcard levels — the limit is ${a}. Either the data nests deeper than the engine can address, or the tree contains a cycle.`),s}function E(e,t){return B(e,"",t)}function C(e,t,n){if(!n.startsWith(e.anchor))return null;if(t.length>0&&!n.endsWith(t))return null;if(n.length<e.anchor.length+t.length)return null;const r=n.slice(e.anchor.length,n.length-t.length);if(0===r.length)return 0;const s=i+e.repeat;let o=0,a=0;for(;a<r.length;){if(!r.startsWith(s,a))return null;a+=s.length,o++}return o}function D(e,t){if(0===e.addressStackLength)return null;const n=e.lastAddressStack;if(null===n)return null;const r=t.accessorFor(n.pathInfo.path);return null!==r?r.depth:function(e,t){const n=e.spec;if(!t.startsWith(n.anchor))return null;const r=i+n.repeat;let s=0,o=n.anchor.length;for(;t.startsWith(r,o);)o+=r.length,s++;return o!==t.length&&46!==t.charCodeAt(o)?null:s}(t,n.pathInfo.path)}function G(e,t,n){const r=e.recursionRegistry,s=R(r.spec,n);null===s&&I(c(n,r.spec.recursiveAnchor));const i=D(t,r);return null===i&&I(`[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,i)}function M(e,t,n,r,s){const o=r.spec,a=[],c=new Map,h=[],u=o.repeatList,d=o.anchorList,p=new Set,g=new Set,m=(e,t,n)=>{const r=e.wildcardParentPathInfos;if(t>=r.length)return void a.push(y(e,n));const s=v(r[t],n,null).rows;for(let n=0;n<s.length;n++)m(e,t+1,s[n])};function v(r,s,i){const a=y(r,s),l=x(n.stateElement,a),h=f(e,a,t,n),d=null===i?null:((e,t,n)=>{if(!Array.isArray(t)||0===t.length)return null;const r=t;return p.has(r)&&I(`[wcs/recursion-cycle] "${e}" is reachable from itself: the recursion on "${o.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)&&I(`[wcs/recursion-shared-list] "${e}" is the same array instance as a list reached from another node. The recursion on "${o.anchor}" needs a tree: give each node its own "${u}" array.`),r})(r.path,h,i),g=P(s,_(l),h);return c.set(l,Array.isArray(h)?h:[]),null!==d&&null!==i&&i.add(d),{rows:g.newIndexes,tracked:d}}const w=(e,t,n)=>{const{rows:o,tracked:c}=v(t,n,g);if(0===o.length)return;const f=(e=>{const t=h[e];if(void 0!==t)return t;const n=r.concretePathAt(s,e),o=0===s.length?n:r.concretePathAt("",e),a={nodePath:o,concretePathInfo:l(n),childListPathInfo:l(o+i+u)};return h[e]=a,a})(e),d=c;p.add(d);const $=f.concretePathInfo.wildcardCount===e+1;for(let t=0;t<o.length;t++){const n=o[t];$?a.push(y(f.concretePathInfo,n)):m(f.concretePathInfo,e+1,n),w(e+1,f.childListPathInfo,n)}p.delete(d)};w(0,l(d),null);for(const[e,t]of c)$(e,t);return a}function z(e,t,n,r,s,i,o){d(n);const a=n.stateElement.recursionRegistry,l=R(a.spec,r);null===l&&I(c(r,a.spec.recursiveAnchor));const u=j(l);Array.isArray(s)||I(h(r,'with "**" requires an explicit empty indexes array ([]) — the write API takes no context.')),s.length>0&&I(`[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 i&&I(h(r,'with "**" does not take a mapper yet — the index tuple has a different length at each depth.')),!0===o?.spread&&I(h(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){N(e,n)&&I(`[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.`)}(a.spec,r,u);const f=a.conflictingRecursiveGetter(u);null!==f&&I(`[wcs/recursion-readonly] "${r}" writes into the recursive getter "${f}", 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 g=M(e,t,n,a,l);let m=0;for(let r=0;r<g.length;r++)void 0!==i&&(p(e,g[r],i,t,n),m++);return m}const T={write(e,n){if(!0!==e.hasRecursion)return t;const r=e.recursionRegistry.recursiveGetterOwningPath(n.pathInfo);return null!==r&&I(`[wcs/recursion-readonly] "${n.pathInfo.path}" writes into the recursive getter "${r}" (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.`),t},get(e,n,r,s){if(!0!==e.stateElement.hasRecursion)return t;if("$getAll"===n)return(t,i)=>{if(L(t)){if(void 0!==i)return function(e,t,n,r,s){const i=n.stateElement.recursionRegistry,o=R(i.spec,r);null===o&&I(c(r,i.spec.recursiveAnchor)),Array.isArray(s)||I(`[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&&I(`[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 a=M(e,t,n,i,o),l=[];for(let r=0;r<a.length;r++)l.push(f(e,a[r],t,n));return l}(s,r,e,t,i);t=G(e.stateElement,e,t)}return g(s,n,r,e)(t,i)};if("$setAll"===n)return(t,i,o,a)=>L(t)?z(s,r,e,t,i,o,a):m(s,n,r,e)(t,i,o,a);if(36!==n.charCodeAt(0)&&L(n)){const t=v(G(e.stateElement,e,n)),i=w(s,t,r,e);return f(s,y(t.pathInfo,i),r,e)}return t}};let F=!1;function H(e,t){"string"==typeof t&&0!==t.length||I(`[wcs/recursion-declaration-invalid] ${u} ${e} must be a non-empty string.`);const n=t.split(i);n.some(e=>0===e.length)&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not contain empty path segments.`),n.length<2&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must name a list element: a property path ending with "${i}${o}" (for example "nodes${i}${o}").`),n[n.length-1]!==o&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must end with "${i}${o}" — it names the element of the list, not the list itself.`),36===n[0].charCodeAt(0)&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not start with "$" — that namespace is reserved.`),-1!==t.indexOf("#")&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not contain "#" — that segment is reserved for mounts.`);for(let r=0;r<n.length-1;r++)n[r]===o&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must have exactly one "${o}", at the end. Wildcards in the middle are not supported in this version.`),n[r]===s&&I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not contain "${s}" — the declaration is what gives "${s}" its meaning.`),isNaN(Number(n[r]))||I(`[wcs/recursion-declaration-invalid] ${u} ${e} "${t}" must not contain an index segment ("${n[r]}") — the recursion is declared over the shape of the tree, not over one row.`)}const q=new WeakSet;function K(e){return"function"==typeof e.get&&q.has(e.get)}function J(e,t,n){if(0!==n.size){for(const e of n){const n=Object.getOwnPropertyDescriptor(t,e);void 0!==n&&K(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))}}!function(e,t,n){for(const r of n){const n=l(r),s=n.wildcardParentPathInfos,i=(t,r,o)=>{if(o===s.length)return void A(b(e,n,r),null);const a=0===o?0:s[o-1].segments.length+1;let c=t;for(const e of s[o].segments.slice(a))c=c?.[e];if(!Array.isArray(c))return;const l=k(c);if(null===l)return;const h=Math.min(l.length,c.length);for(let e=0;e<h;e++)i(c[e],l[e],o+1)};i(t,null,0)}}(e,t,n)}}const Q="[wcs/recursion-declaration-invalid]";class U{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=n(t);for(const[t,n]of Object.entries(r)){if(!L(t))continue;"function"==typeof n.set&&I(`${Q} Recursive setters are not supported in this version: "${t}". Declare a plain path setter, or write through the concrete path.`),"function"!=typeof n.get&&I(`${Q} "${t}" contains "**" but is not a getter. The recursion wildcard only names a family of computed paths.`);const r=R(e,t);null===r&&I(c(t,e.recursiveAnchor)),0===r.length&&I(`${Q} "${t}" names the recursive node itself. "**" names a computed path under a node (for example "${e.recursiveAnchor}${i}total"), not the node.`),N(e,j(r))&&I(`${Q} "${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}${i}total").`),this._definitions.set(t,{recursivePath:t,suffix:r,get:n.get})}this._assertNoColliding(),this._assertNoConcreteCollision(r)}_assertNoConcreteCollision(e){for(const[t,n]of Object.entries(e)){if(L(t)||K(n))continue;const e=this._matchExpansion(t);null!==e&&I(`${Q} "${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++)O(this.spec,e[t].suffix,e[n].suffix)&&I(`${Q} "${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(W(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 n=S(e),r=this._ownerByPath.get(n);if(void 0!==r)return r;let s=null;if(n.startsWith(this.spec.anchor)){s=this._matchExpansion(n);for(let e=n.lastIndexOf(i);null===s&&e>this.spec.anchor.length;e=n.lastIndexOf(i,e-1))s=this._matchExpansion(n.slice(0,e))}return this._ownerByPath.set(n,s),s}_matchExpansion(e){for(const t of this._definitions.values())if(null!==C(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=C(this.spec,e.suffix,t);null!==n&&(null!==r&&I(`"${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||K(s)||I(`"${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,q.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 n of function(e,t){const n=[];n.push(e.anchorList);for(let r=0;r<t;r++)n.push(E(e,r)+i+e.repeatList);return n}(this.spec,t))this._registeredListPaths.has(n)||(this._registeredListPaths.add(n),e.addListPath(n))}forgetGenerated(e,t){const n=new Set(this._accessors.keys());return J(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=B(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 V="recursionSpec",X="recursionRegistry",Y={order:5,validateEarly(e,t,n){const r=function(e){const t=e[u];if(void 0===t)return null;"object"==typeof t&&null!==t||I(`[wcs/recursion-declaration-invalid] ${u} must be an object mapping one anchor path to its repeating sub-path (for example { "nodes.*": "children.*" }).`);const n=Object.entries(t);0===n.length&&I(`[wcs/recursion-declaration-invalid] ${u} must declare exactly one anchor; it is empty.`),n.length>1&&I(`[wcs/recursion-declaration-invalid] ${u} declares ${n.length} anchors (${n.map(([e])=>`"${e}"`).join(", ")}). This version supports exactly one self-recursive anchor per state.`);const[r,a]=n[0];H("anchor",r),"string"!=typeof a&&I(`[wcs/recursion-declaration-invalid] ${u} entry "${r}" must map to the repeating sub-path as a string (for example "children${i}${o}").`),H("repeating sub-path",a);const c=r.slice(0,r.lastIndexOf(i)),l=a.slice(0,a.lastIndexOf(i)),h=c+i+s;return Object.freeze({anchor:r,repeat:a,recursiveAnchor:h,anchorList:c,repeatList:l})}(t);n.set(V,r),n.set(X,null===r?null:new U(r,t))},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(X)??null;e.setRecursionRegistry?.(s),null!==s&&e.attachAddressHooks?.("recursion",u)},apply(e,t,n){const r=n.get(V)??null;null!==r&&e.addListPath(r.anchorList)}};let Z=!1;function ee(){Z||(Z=!0,F||(F=!0,e("recursion",T)),r("recursion",Y))}const te={name:"recursion",install(){ee()}};export{te as default,te as recursion};
|
|
2
2
|
//# sourceMappingURL=recursion.js.map
|