@wcstack/state 3.3.0 → 3.4.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 +37 -10
- package/README.md +37 -10
- package/dist/auto.min.js +1 -1
- package/dist/auto.min.js.map +1 -1
- package/dist/index.d.ts +29 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/split/chunks/binder.js +1 -1
- package/dist/split/chunks/binder.js.map +1 -1
- package/dist/split/chunks/checkDependency.js +1 -1
- package/dist/split/chunks/checkDependency.js.map +1 -1
- package/dist/split/chunks/diagnosticsHooks.js.map +1 -1
- package/dist/split/chunks/featureBridge.js +1 -1
- package/dist/split/chunks/filterRegistry.js +1 -1
- package/dist/split/chunks/filterRegistry.js.map +1 -1
- package/dist/split/chunks/getAllPropertyDescriptors.js +1 -1
- package/dist/split/chunks/lifecycleHooks.js +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/registerComponents.js.map +1 -1
- package/dist/split/chunks/setAll.js +1 -1
- package/dist/split/chunks/setAll.js.map +1 -1
- package/dist/split/chunks/version.js +1 -1
- package/dist/split/core.d.ts +54 -0
- package/dist/split/core.js +1 -1
- package/dist/split/features/devtools.js +1 -1
- package/dist/split/features/devtools.js.map +1 -1
- package/dist/split/features/diagnostics.js +1 -1
- package/dist/split/features/diagnostics.js.map +1 -1
- package/dist/split/features/formats.js +1 -1
- package/dist/split/features/recursion.js +1 -1
- package/dist/split/features/recursion.js.map +1 -1
- package/dist/split/features/scopes.js +1 -1
- package/dist/split/features/scopes.js.map +1 -1
- package/dist/split/features/ssr.js +1 -1
- package/dist/split/features/ssr.js.map +1 -1
- package/dist/split/features/temporal.js +1 -1
- package/dist/split/features/temporal.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as t,w as e,E as n,W as s,F as a,q as o,D as l,d 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{aC as h,m as p,l as g,aD as y,aE as I,M as w,j as m,O as x,N as P,aF as v,aG as A,h as b,aH as $,k,ai as E,aI as R,aJ as S,aK as j,aL as M,aM as O,aN as C,aO as L,a9 as D,c as N,aP as T,ae as V,$ as q,aQ as B,p as H,o as z}from"./binder.js";import{N as G}from"./getAllPropertyDescriptors.js";import{c as W}from"./checkDependency.js";import{c as F}from"./filterRegistry.js";const J=new WeakMap;function K(t,e){let n=J.get(t);void 0===n&&(n=new Map,J.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const U=new WeakMap;function Q(t){const e=U.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 U.set(t,n),n}function X(t){U.delete(t)}function Y(t){"readonly"===t.mutability&&u("This state is readonly.")}const Z=new Map;class _{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 tt(t){let e;return Z.get(t)??(Z.set(t,e=new _(t)),e)}function et(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 nt(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function st(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!==G)return r}}return G}function at(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}(Q(i),o.pathInfo.segments);if(!(o.pathInfo.path in t)){if(null===o.parentAddress){const e=st(i,o,null,l,r);if(e!==G)return e;u(n(o.pathInfo.path,t,i.getterPaths))}const e=ot(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=st(i,o,Object(e),l,r);if(t!==G)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 ot(t,e,n,s){W(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!==G)return l}}return nt(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=at(t,e,n,s,a);return I(o,{value:i,dirty:!1,generation:r}),i}(t,e,n,s,a):at(t,e,n,s,a)}function lt(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=ot(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 rt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=ot(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 it(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 dt(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 ct(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];it(i,n,s,r);const d=dt(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 ft(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 ut(t,e,n,a){if(e.pathInfo.path in t)return!0;const o=e.parentAddress;if(null===o)return!1;const l=ot(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 ht=new WeakMap;function pt(t,e){null===e?ht.delete(t):ht.set(t,e)}function gt(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[b](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 F.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)gt(e,n+1,t)}const yt=[];function It(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:yt,movedRows:null}:{fullRows:a.newIndexes,movedRows:null}:{fullRows:yt,movedRows:null}:{fullRows:a.addIndexSet,movedRows:a.changeIndexSet}}const wt=[];function mt(e,n,s){const a=e.stateElement.indexDependentGetterPaths;if(!a||0===a.size)return wt;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??wt}function xt(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,Pt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}function Pt(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[b](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=It(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=mt(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=$(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};gt(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 vt(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};xt(f,e,r),function(t,e){for(let n=0;n<1e3;n++){const n=A(t.stateElement);if(null===n)return;n.forEach(n=>{xt(t,m(n.absolutePathInfo.pathInfo,n.listIndex),e)})}}(f,r);for(const[t,e]of f.observedListValueByAbsAddress)w(t,e);return Array.from(f.result)}function At(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 bt(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 $t(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 kt(t,e,n,s,a,o){const l=R(t,e),r=S(t,e);if(!l&&!r)return null;const i=[],d=Rt(i);return l&&j(t,e,n,s,a).forEach(d),r&&M(t,e,n?s:o(),a).forEach(d),i}function Et(){return F.enablePropagationContext?C()??null:null}function Rt(t){const e=N(),n=Et();return s=>{E(s),e.enqueueAbsoluteAddress(s,n),t.push(s)}}function St(t,e,n){if(null===t||0===t.length)return;const s=n.stateElement,a=s.staticDependency,o=s.dynamicDependency,l=N(),r=Et();for(let n=0;n<t.length;n++){const i=t[n].absolutePathInfo,d=i.pathInfo.path;if(!a.has(d)&&!o.has(d))continue;const c=m(i.pathInfo,t[n].listIndex);vt(s,c,a,o,s.listPaths,e,"new",t=>{if(t===c)return;const e=g(s,t);E(e),l.enqueueAbsoluteAddress(e,r)},{listExpansion:"diff"})}}function jt(t,e,n,s,a){const o=R(t,e),l=S(t,e);if(!o&&!l)return;const r=n(),i=[],d=Rt(i);o&&j(t,e,!1,void 0,r).forEach(d),l&&M(t,e,void 0,r,!1).forEach(d),St(i,s,a)}function Mt(t,e,n,s,a,o,l="diff"){const r=F.enablePropagationContext?C()??L(-1):null,i=N();i.enqueueAbsoluteAddress(e,r),o&&E(e),vt(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);E(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:l,keyedMergePath:a})}function Ot(t,e,n,s,a){a&&(t.getterPaths.has(e)?E(n):I(n,{value:s,dirty:!1,generation:t.stateGeneration}))}function Ct(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=ot(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{Mt(e,n,l,r,i,d)}}function Lt(e,n,a,o,r,i,d,c){const f=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),h=ot(e,f,r,i)??[];let p=(y=h,ht.get(y)??null);var y;if(null===p){const t=k(h)??[];p={value:[...h],listIndexes:[...t]},pt(h,p)}try{return Ct(e,n,a,o,r,i,d,c)}finally{const a=p.value.indexOf(o),d=ot(e,f,r,i)??[],c=Array.isArray(d)?k(d)??[]:[],u=n.listIndex.index,y=-1!==a?p.listIndexes[a]:D(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;pt(h,null),function(e,n,a,o,r,i){const d=i.stateElement,c=N(),f=g(d,e);T(f)===a&&(V(n.value,n.listIndexes),q(f,n.value),B(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);$t(d,l,e),Mt(a,l,r,i,null,nt(d,a),"full");continue}vt(d,a,d.staticDependency,d.dynamicDependency,d.listPaths,r,"new",t=>{const e=g(d,t);E(e),c.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}}(f,p,d,c,r,i)}}}function Dt(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=ot(e,n,o,r),c=function(t,e,n,s){const a=ct(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=ct(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===k(o)&&P(c,null,o);const f=P(c,o,a.list),u=Nt(e,n,a.list,r,i,d),h=t(d+l+s);for(const n of a.matched){const s=ft(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);Dt(e,m(s,a),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return Nt(e,n,a,o,r,null)}function Nt(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!==G)return a}}const h=O();if(!(c in t)&&null!==e.parentAddress&&!d.elementPaths.has(c)){const p=ot(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&&F.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}const m=kt(d,c,w,I,n,()=>p[y]),x=nt(d,e),P=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:P,value:n,oldValue:I,hasOldValue:w}),At(d,c,P,I,w);let v=!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++){v=!0;const a=t[s](d,e,p,y,n,o,l);if(a!==G)return a;v=!1}}return Reflect.set(p,y,n)}finally{Mt(e,P,o,l,i,x),St(m,o,l),v?E(P):Ot(d,c,P,n,x),bt(d,e.pathInfo,{value:n})}}}let p,y=!1;if(!h&&F.sameValueGuard&&(null===n||"object"!=typeof n)){const s=ot(t,e,o,l);if(ut(t,e,o,l)&&Object.is(s,n))return!0;p=s,y=!0}const I=kt(d,c,y,p,n,()=>ot(t,e,o,l)),w=d.elementPaths.has(e.pathInfo.path),m=nt(d,e),x=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:x,value:n,oldValue:p,hasOldValue:y}),At(d,c,x,p,y);try{return w?Lt(t,e,x,n,o,l,i,m):Ct(t,e,x,n,o,l,i,m)}finally{St(I,o,l),w||Ot(d,c,x,n,m),bt(d,e.pathInfo,{value:n})}}function Tt(e,n,s,a){return(n,o,...l)=>{Array.isArray(o)||u(`$resolve("${n}") requires an explicit indexes array (pass [] when the path has no wildcards) — got `+(null===o?"null":typeof o)+"."),l.length>1&&u(`$resolve("${n}") takes 2 arguments to read and 3 to write (path, indexes, value) — got ${2+l.length}.`);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=rt(e,s,a,r,o),c=m(r,d);if(0===l.length)return ot(e,c,s,a);Y(a),Dt(e,c,l[0],s,a)}}function Vt(e,n,s,a){const o=Tt(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=et(a,r.wildcardPaths[t]);if(e){l=z(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=lt(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 qt(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return et(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=ot(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 Bt(e,n,s,a){return(n,o,l,r)=>{Y(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=lt(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=rt(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(ot(e,n,s,a),...g[t])}else o=h?l[t]:l;void 0!==o&&(Dt(e,n,o,s,a),I++)}return I}}export{Y as a,Vt as b,Bt as c,tt as d,qt as e,Q as f,ot as g,ut as h,X as i,jt as n,Tt as r,Dt as s,vt as w};
|
|
1
|
+
import{W as t,w as e,F as n,G as s,g as a,q as o,D as l,d as r,H as i,J as d,t as c,K as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aO as h,l as p,aP as g,aQ as I,aR as y,j as w,m as x,aS as m,M as P,O as b,N as v,aT as A,aU as $,au as k,aV as R,h as E,k as S,aW as M,aX as j,aY as O,aZ as C,a_ as D,a$ as L,b0 as q,b1 as V,ah as T,b2 as B,b3 as H,a0 as W,b4 as z,b5 as G,b6 as N,b7 as U,b8 as K,b9 as F,ba as J,bb as Q,p as X,bc as Y,bd as Z,be as _,bf as tt,bg as et,c as nt,bh as st,bi as at,a1 as ot,bj as lt,o as rt}from"./binder.js";import{c as it,a as dt}from"./checkDependency.js";import{N as ct}from"./getAllPropertyDescriptors.js";import{c as ft}from"./filterRegistry.js";const ut=new WeakMap;function ht(t,e){let n=ut.get(t);void 0===n&&(n=new Map,ut.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const pt=new WeakMap;function gt(t){const e=pt.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return ht(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:ht(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return pt.set(t,n),n}function It(t){pt.delete(t)}function yt(t){"readonly"===t.mutability&&u("This state is readonly.")}function wt(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function xt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==ct)return r}}return ct}function mt(a,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(gt(i),o.pathInfo.segments);if(!(o.pathInfo.path in a)){if(null===o.parentAddress){const t=xt(i,o,null,l,r);if(t!==ct)return t;u(n(o.pathInfo.path,a,i.getterPaths))}const e=At(a,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==t&&!(d in Object(e))){const t=xt(i,o,Object(e),l,r);if(t!==ct)return t}if(d===t){const t=o.listIndex?.index??u(s(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(a,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(a,o.pathInfo.path,l)}finally{r.popAddress()}}function Pt(e,n,s,o,l){const r=p(l,n),i=g(r),d=l.stateGeneration,c=n.pathInfo.lastSegment===t?void 0:I(n.listIndex);if(null!==i&&!1===i.dirty&&i.generation===d&&i.rowStamp===c)return i.value;const f=mt(e,n,s,o,l);"function"!=typeof f&&y(r,{value:f,dirty:!1,generation:d,rowStamp:c});const u=i?.value;return Array.isArray(f)&&f!==u&&l.getterPaths.has(n.pathInfo.path)&&function(t,e,n,s,o,l){const{path:r,wildcardCount:i}=e.pathInfo;l.beginUntrack();try{for(const[d,c]of l.stateElement.dynamicDependency){const f=a(d);if(!c.includes(r)||f.wildcardCount>i)continue;const u=At(t,w(f,x(e.listIndex,f.wildcardCount-1,i)),o,l);u===n?bt.add(e.pathInfo):u===s&&m(n,s)}}finally{l.endUntrack()}}(e,n,f,u,s,o),f}const bt=new WeakSet;function vt(t){return bt.has(t)}function At(t,e,n,s){it(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==ct)return l}}return wt(a,e)?Pt(t,e,n,s,a):mt(t,e,n,s,a)}function $t(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const g=w(h,o),I=p(n.stateElement,g),y=b(I),x=At(t,g,e,n),m=v(o,y,x).newIndexes,P=i[d]??null;if(l.set(I,x),null===P)for(let t=0;t<m.length;t++){const e=m[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=m[P]??u(`ListIndex not found at index ${P} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())P(t,Array.isArray(e)?e:[]);return i}function kt(t,e,n){const s=A(n,e.listIndex);if(null!==s)return s;const a=p(t.stateElement,e),o=v(e.listIndex,b(a),n);return P(a,Array.isArray(n)?n:[]),o.newIndexes}function Rt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=w(r,o),d=kt(n,i,At(t,i,e,n)),c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function Et(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function St(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function Mt(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];Et(i,n,s,r);const d=St(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function jt(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function Ot(e,n,s,a){if(n.pathInfo.path in e)return!0;const o=n.parentAddress;if(null===o)return!1;const l=At(e,o,s,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=n.pathInfo.lastSegment;if(r===t){const t=n.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const Ct=new WeakMap;function Dt(t){return Ct.get(t)??null}function Lt(t,e){null===e?Ct.delete(t):($(e.listIndexes),Ct.set(t,e))}function qt(t,e,n){const s=t.wildcardParentPaths[e],o=a(s),l=w(o,n),r=p(t.stateElement,l),i=b(r),d=t.stateProxy[E](l),c=v(l.listIndex,i,d);t.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return ft.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,t.searchType);if(e===t.wildcardPaths.length-1)t.targetListIndexes.push(...f);else for(const n of f)qt(t,e+1,n)}function Vt(t,e,n,s){n?t.result.has(e)||t.quiet.add(e):t.quiet.delete(e),t.result.add(e),s.push(e)}const Tt=[];function Bt(t,e,n){return"full"!==t.listExpansion&&t.listPathSet.has(e)?t.stateElement.crossRowListPaths?.has(e)?{fullRows:n.newIndexes,movedRows:null}:0===n.addIndexSet.size&&0===n.changeIndexSet.size?0===n.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:Tt,movedRows:null}:{fullRows:n.newIndexes,movedRows:null}:{fullRows:Tt,movedRows:null}:{fullRows:n.addIndexSet,movedRows:n.changeIndexSet}:{fullRows:n.newIndexes,movedRows:null}}const Ht=[];function Wt(t,e,n){const s=t.stateElement.indexDependentGetterPaths;if(!s||0===s.size)return Ht;let o=null;const r=e+l;for(const t of s){if(t!==e&&!t.startsWith(r))continue;const s=a(t);if(s.wildcardCount!==n.wildcardCount)return null;(o??=[]).push(s)}return o??Ht}function zt(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),t.quiet.has(r)?k(p(t.stateElement,r)):n(r),l.length=0,Gt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}function Gt(e,n,s){const o=n.pathInfo.path,l=e.quiet.has(n),r=e.staticMap.get(o);if(r)for(const i of r){const r=a(i);if(r.lastSegment===t){const t=e.stateProxy[E](n),a=Array.isArray(t)?t:[],d=p(e.stateElement,n),c=b(d),f=e.listPathSet.has(o);if(!f&&"diff"===e.listExpansion&&(e.keyedMergePath===o||S(a)?.length!==a.length&&!M(c,a)))continue;const u=v(n.listIndex,c,a);e.observedListValueByAbsAddress.set(d,a);const h=Bt(e,o,u);for(const t of h.fullRows)Vt(e,w(r,t),l||!f,s);for(const t of u.valueChangeIndexes??Tt)Vt(e,w(r,t),l||!f,s);if(null!==h.movedRows){const t=Wt(e,i,r);if(null===t)for(const t of h.movedRows)Vt(e,w(r,t),l,s);else if(t.length>0)for(const n of h.movedRows)for(const a of t)Vt(e,w(a,n),l,s)}}else Vt(e,w(r,n.listIndex),l,s)}const i=e.dynamicMap.get(o);if(i)for(const t of i){const o=a(t),r=[];if(o.wildcardCount>0){const t=j(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=x(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};qt(a,t,s),r.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=x(n.listIndex,t-1,n.pathInfo.wildcardCount);r.push(e)}}else r.push(null);for(const t of r)Vt(e,w(o,t),l,s)}}function Nt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null,quiet:new Set};zt(f,e,r),function(t,e){for(let n=0;n<1e3;n++){const n=R(t.stateElement);if(null===n)return;n.forEach(n=>{zt(t,w(n.absolutePathInfo.pathInfo,n.listIndex),e)})}}(f,r);for(const[t,e]of f.observedListValueByAbsAddress)P(t,e);return Array.from(f.result)}function Ut(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function Kt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Ft(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function Jt(t,e,n,s,a,o){const l=D(t,e),r=L(t,e);if(!l&&!r)return null;const i=[],d=Xt(i);return l&&q(t,e,n,s,a).forEach(d),r&&V(t,e,n?s:o(),a).forEach(d),i}function Qt(){return ft.enablePropagationContext?K()??null:null}function Xt(t){const e=nt(),n=Qt();return s=>{k(s),e.enqueueAbsoluteAddress(s,n),t.push(s)}}function Yt(t,e,n){if(null===t||0===t.length)return;const s=n.stateElement,a=s.staticDependency,o=s.dynamicDependency,l=nt(),r=Qt();for(let n=0;n<t.length;n++){const i=t[n].absolutePathInfo,d=i.pathInfo.path;if(!a.has(d)&&!o.has(d))continue;const c=w(i.pathInfo,t[n].listIndex);Nt(s,c,a,o,s.listPaths,e,"new",t=>{if(t===c)return;const e=p(s,t);k(e),l.enqueueAbsoluteAddress(e,r)},{listExpansion:"diff"})}}function Zt(t,e,n,s,a){const o=D(t,e),l=L(t,e);if(!o&&!l)return;const r=n(),i=[],d=Xt(i);o&&q(t,e,!1,void 0,r).forEach(d),l&&V(t,e,void 0,r,!1).forEach(d),Yt(i,s,a)}function _t(e,n,s,o,r,i,d="diff"){const c=ft.enablePropagationContext?K()??F(-1):null,f=nt(),u=o.stateElement;f.enqueueAbsoluteAddress(n,c),i&&k(n);const h=t=>Nt(u,t,u.staticDependency,u.dynamicDependency,u.listPaths,s,"new",t=>{if(t===e)return;const n=p(u,t);k(n),f.enqueueAbsoluteAddress(n,c)},{listExpansion:d,keyedMergePath:r});if(h(e),e.pathInfo.lastSegment!==t&&null!==e.listIndex&&null!==e.listIndex.parentListIndex){const n=e.listIndex,o=e.pathInfo.wildcardParentPathInfos[n.position],r=w(o,n.parentListIndex),i=()=>s[E](r),d=t=>{k(t),f.enqueueRenderOnlyAddress(t)};for(const t of J(n,i))d(p(u,w(e.pathInfo,t)));const c=e.pathInfo.path.slice(e.pathInfo.wildcardPaths[n.position].length);for(const e of Q(p(u,r),i())){const s=e.absolutePathInfo.pathInfo;s!==o&&s.wildcardCount===o.wildcardCount&&d(X(u,a(s.path+l+t+c),n))}}const{path:g,lastSegment:I,wildcardCount:y,wildcardParentPaths:m,wildcardParentPathInfos:P}=e.pathInfo,b=e.listIndex;for(let e=0;b&&e<y;e++){const n=x(b,e-1,y);for(const o of u.dynamicDependency.get(m[e])??[]){const l=a(o);if(u.listPaths.has(o)&&l.wildcardCount===e&&vt(l)&&s[E](w(l,n))===s[E](w(P[e],n))){const n=w(a(o+g.slice(m[e].length)),b);h(n),I===t&&f.enqueueRenderOnlyAddress(p(u,n.parentAddress))}}}}function te(e,n,s,a,o){o&&(e.getterPaths.has(n)?k(s):y(s,{value:a,dirty:!1,generation:e.stateGeneration,rowStamp:s.absolutePathInfo.pathInfo.lastSegment===t?void 0:I(s.listIndex)}))}function ee(e,n,a,o,l,r,i,d,c=!0){try{if(!(n.pathInfo.path in e)){const a=n.parentAddress;if(null===a)return Reflect.set(e,n.pathInfo.path,o);const i=At(e,a,l,r),d=n.pathInfo.segments[n.pathInfo.segments.length-1];if(d===t){const t=n.listIndex?.index??u(s(`path "${n.pathInfo.path}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(n.pathInfo.path))return Reflect.set(e,n.pathInfo.path,o);r.pushAddress(n),r.beginUntrack();try{return Reflect.set(e,n.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{c&&_t(n,a,l,r,i,d)}}function ne(e,n,s,o,r,i,d,c,f){const h=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),g=At(e,h,r,i)??[],I=Dt(g);if(f)return I&&(I.value[n.listIndex.index]=o),Y(n.listIndex,o),ee(e,n,s,o,r,i,d,c);const y=n.listIndex,x=I??{value:[...g],listIndexes:S(g)??[],written:new Map};try{return ee(e,n,s,o,r,i,d,c,!1)}finally{const e=function(t,e,n){const{value:s,listIndexes:a}=t,o=new Map;a.forEach((t,n)=>{if(e[n]!==s[n]){const e=o.get(s[n]);e?e.push(t):o.set(s[n],[t])}});let l,r=0;const i=[];for(let t=0;t<a.length;t++){const n=e[t]===s[t]?a[t]:o.get(e[t])?.shift();if(!n&&(r++?(l??=new Set(s)).has(e[t]):s.includes(e[t])))return null;i.push(n)}return i.map((t,e)=>t??T(n,e))}(x,g,h.listIndex);if(null===e)Lt(g,x),Y(y,o),x.written.set(y,Z),_(y),_t(n,s,r,i,d,c);else{Lt(g,null);const n=[y.index];tt(y),x.written.forEach((t,e)=>{tt(e),Y(e,x.value[e.index]),t===Z&&n.push(e.index)}),x.written.delete(y),e.forEach((t,e)=>{t.index=e}),W(g,e),N(x.listIndexes,e),function(e,n,s,o,r,i,d){const c=i.stateElement,f=nt(),u=p(c,e);W(n.value,n.listIndexes),st(n.value),z(s,n.value),at(u)===s&&ot(u,n.value);f.enqueueRenderOnlyAddress(u);for(const t of Q(u,s))lt(t,s)&&f.enqueueRenderOnlyAddress(t);const h=new Map;n.listIndexes.forEach((t,e)=>h.set(t,e));const g=a(e.pathInfo.path+l+t);for(let t=0;t<o.length;t++){const e=o[t],s=h.get(e);if(s===t)continue;const a=w(g,e),l=p(c,a);if(void 0===s){const e=X(c,g,n.listIndexes[t]);Ft(c,l,e),_t(a,l,r,i,null,wt(c,a),"full");continue}Nt(c,a,c.staticDependency,c.dynamicDependency,c.listPaths,r,"new",t=>{const e=p(c,t);k(e),f.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}for(const t of d){const e=o[t];if(h.has(e)&&n.written.get(e)!==Z){const s=w(g,e),a=p(c,s);Ft(c,a,X(c,g,n.listIndexes[t])),_t(s,a,r,i,null,wt(c,s))}}}(h,x,g,e,r,i,n)}}}function se(e,n,s,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(s)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=At(e,n,o,r),c=function(t,e,n,s){const a=Mt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=Mt(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,s);if(null!==c)return function(e,n,s,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===S(o)&&v(c,null,o);const f=v(c,o,s.list),u=ae(e,n,s.list,r,i,d),h=a(d+l+t);for(const t of s.matched){const n=jt(t.oldRow,t.newRow);if(0===n.length)continue;const s=f.newIndexes[t.position];for(const o of n){if(void 0===s){t.oldRow[o.field]=o.value;continue}const n=a(h.path+l+o.field);se(e,w(n,s),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return ae(e,n,s,o,r,null)}function ae(e,n,a,o,l,i){const d=l.stateElement,c=n.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let e=0;e<t.length;e++){const s=t[e](d,n,a,o,l);if(s!==ct)return s}}const h=et(),g=h>1;if(!(c in e)&&null!==n.parentAddress&&!d.elementPaths.has(c)){const h=At(e,n.parentAddress,o,l);if("object"==typeof h&&null!==h){const e=n.pathInfo.lastSegment,I=e===t?n.listIndex?.index:e;let y,x=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=void 0!==I&&I in h,e=void 0!==I?h[I]:void 0;if(t&&Object.is(e,a))return!0;y=e,x=!0}e===t&&(n=function(t,e,n,s,a){const o=e.listIndex,l=S(n);if(l?.[s]!==o||n[s]===a)return e;const r=T(o.parentListIndex,s,B(o));if(H(n)){const t=Dt(n)??{value:n.slice(),listIndexes:l};W(t.value,t.listIndexes),z(n,t.value)}const i=G(l)?l:l.slice();i[s]=r,W(n,i,!0),N(l,i),U([o]);const d=w(e.pathInfo,r);return Ft(t,p(t,d),p(t,e)),d}(d,n,h,I,a));const P=Jt(d,c,x,y,a,()=>h[I]),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:y,hasOldValue:x}),Ut(d,c,v,y,x);let A=!1;try{if(void 0===I&&u(s(`path "${c}"`,n.pathInfo.wildcardCount,n.listIndex?.length??0)),f&&0!==f.writeMissing.length&&e!==t&&!(I in h)){const t=f.writeMissing;for(let e=0;e<t.length;e++){A=!0;const s=t[e](d,n,h,I,a,o,l);if(s!==ct)return s;A=!1}}if(e!==t&&null!==n.listIndex){const t=h[I];t!==a&&(O(t,n.listIndex,h,e)&&Array.isArray(a)&&m(a,t),C(a,n.listIndex))}return Reflect.set(h,I,a)}finally{_t(n,v,o,l,i,b),Yt(P,o,l),A?k(v):te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}}let I,y=!1;if(!g&&ft.sameValueGuard&&(null===a||"object"!=typeof a)){const t=At(e,n,o,l);if(Ot(e,n,o,l)&&Object.is(t,a))return!0;I=t,y=!0}const x=Jt(d,c,y,I,a,()=>At(e,n,o,l)),P=d.elementPaths.has(n.pathInfo.path),b=wt(d,n),v=p(d,n);null!==r&&r({type:"state:write",absoluteAddress:v,value:a,oldValue:I,hasOldValue:y}),Ut(d,c,v,I,y);try{return P?ne(e,n,v,a,o,l,i,b,h):ee(e,n,v,a,o,l,i,b)}finally{Yt(x,o,l),P||te(d,c,v,a,b),Kt(d,n.pathInfo,{value:a})}}function oe(t,e,n,s){return(e,o,...l)=>{Array.isArray(o)||u(`$resolve("${e}") requires an explicit indexes array (pass [] when the path has no wildcards) — got `+(null===o?"null":typeof o)+"."),l.length>1&&u(`$resolve("${e}") takes 2 arguments to read and 3 to write (path, indexes, value) — got ${2+l.length}.`);const r=a(e);if(s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",e,r.wildcardParentPathInfos.length,o.length));const d=Rt(t,n,s,r,o),c=w(r,d);if(0===l.length)return At(t,c,n,s);yt(s),se(t,c,l[0],n,s)}}function le(t,e,n,s){const o=oe(t,0,n,s);return(e,l)=>{const r=a(e);if(void 0===l||Array.isArray(l)||u(`$getAll("${e}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),s.addressStackLength>0){const t=s.lastAddressStack?.pathInfo??null,e=s.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",e,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=dt(s,r.wildcardPaths[t]);if(e){l=rt(e,e.length);break}}if(void 0===l){const t=s.addressStackLength>0?s.lastAddressStack:null,n=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==n&&n.length>0&&u(d(e,t.pathInfo.path)),l=[]}}const c=$t(t,n,s,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function re(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":{const t=a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`);return dt(s,t)??u(`ListIndex not found: ${e.pathInfo.path}`)}case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=w(l,a),i=kt(s,r,At(t,r,n,s)),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function ie(e,n,s,o){return(n,l,r,d)=>{yt(o);const h=a(n);Array.isArray(l)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),l.length>h.wildcardParentPathInfos.length&&u(i("$setAll",n,h.wildcardParentPathInfos.length,l.length));const p=!0===d?.spread,g="function"==typeof r;p&&g&&u(c(n,"cannot combine { spread: true } with a mapper function.")),p&&!Array.isArray(r)&&u(c(n,"requires an array as the value when { spread: true } is set."));const I=$t(e,s,o,h,l,{commitDiffBaseline:!1});p&&r.length!==I.length&&u(f(n,I.length,r.length));const y=[];for(let t=0;t<I.length;t++){const n=Rt(e,s,o,h,I[t]);y.push(w(h,n))}const x=h.lastSegment===t;let m=0;for(let t=0;t<y.length;t++){const n=x?w(h,Rt(e,s,o,h,I[t])):y[t];let a;if(g){a=r(At(e,n,s,o),...I[t])}else a=p?r[t]:r;void 0!==a&&(se(e,n,a,s,o),m++)}return m}}export{yt as a,le as b,ie as c,re as d,gt as e,It as f,At as g,Ot as h,Zt as n,oe as r,se as s,Nt as w};
|
|
2
2
|
//# sourceMappingURL=setAll.js.map
|