@symbo.ls/utils 3.14.776 → 3.14.778
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/methods.js +5 -5
- package/dist/cjs/state.js +1 -1
- package/dist/esm/methods.js +7 -7
- package/dist/esm/state.js +1 -1
- package/methods.js +16 -4
- package/package.json +1 -1
- package/state.js +61 -5
package/dist/cjs/methods.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var D=Object.create;var g=Object.defineProperty;var
|
|
2
|
-
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function
|
|
1
|
+
"use strict";var D=Object.create;var g=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},$=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of T(t))!L.call(e,r)&&r!==n&&g(e,r,{get:()=>t[r],enumerable:!(o=I(t,r))||o.enumerable});return e};var J=(e,t,n)=>(n=e!=null?D(F(e)):{},$(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),G=e=>$(g({},"__esModule",{value:!0}),e);var Rt={};M(Rt,{call:()=>ht,defineSetter:()=>it,error:()=>R,get:()=>W,getChildren:()=>K,getContext:()=>st,getDB:()=>dt,getPath:()=>X,getQuery:()=>_t,getRef:()=>Z,getRoot:()=>nt,getRootContext:()=>rt,getRootData:()=>ot,getRootState:()=>et,isMethod:()=>Ot,keys:()=>N,log:()=>ct,lookdown:()=>z,lookdownAll:()=>H,lookup:()=>V,nextElement:()=>ft,parse:()=>j,parseDeep:()=>O,previousElement:()=>ut,promoteActiveRootState:()=>tt,remove:()=>U,setActiveRootState:()=>q,setNodeStyles:()=>C,setProps:()=>Y,spotByPath:()=>B,variables:()=>at,verbose:()=>Q,warn:()=>lt});module.exports=G(Rt);var w=require("./triggerEvent.js"),d=require("./keys.js"),f=require("./types.js"),y=require("./object.js"),P=require("./env.js"),A=require("./array.js"),b=require("./cache.js");const h="production";function B(e){const t=this,{__ref:n}=t,o=[].concat(e);let r=n.root[o[0]];if(!o||!o.length)return console.log(o,"on",t.key,"is undefined");for(;r.key===o[0]&&(o.shift(),!!o.length);)if(r=r[o[0]],!r)return;return r}function V(e){const t=this;let{parent:n}=t;if((0,f.isFunction)(e))return n.state&&e(n,n.state,n.context)?n:n.parent?n.lookup(e):void 0;if(t[e])return t[e];for(;n.param!==e;){if(n[e])return n[e];if(n=n.parent,!n)return}return n}function z(e){const t=this,{__ref:n}=t,o=n?.__children;if(o)for(let r=0;r<o.length;r++){const s=o[r],i=t[s];if(s===e)return i;if((0,f.isFunction)(e)){const l=e(i,i.state,i.context);if(i.state&&l)return i}const c=i?.lookdown?.(e);if(c)return c}}function H(e,t=[]){const n=this,{__ref:o}=n,r=o?.__children;if(r){for(let s=0;s<r.length;s++){const i=r[s],c=n[i];if(i===e)t.push(c);else if((0,f.isFunction)(e)){const l=e(c,c.state,c.context);c.state&&l&&t.push(c)}c?.lookdownAll?.(e,t)}return t.length?t:void 0}}function C(e={}){const t=this;if(t.node?.style){for(const n in e){const o=e[n],r=t[n];if((0,f.isObject)(o)&&r)C.call(r,o);else if(o!=null){const s=n.replace(/[A-Z]/g,c=>"-"+c.toLowerCase()),i=String(o).replace(/\s*!important\s*$/,"");t.node.style.setProperty(s,i,"important")}}return t}}function U(e){const t=this;if((0,w.triggerEventOn)("beforeRemove",t,e)===!1)return t;(0,f.isFunction)(t.node.remove)?t.node.remove():(0,P.isProduction)()||(console.warn("This item cant be removed"),t.log()),delete t.parent[t.key],t.parent.__ref&&(t.parent.__ref.__children=(0,A.removeValueFromArray)(t.parent.__ref.__children,t.key)),(0,w.triggerEventOn)("remove",t,e)}function W(e){return this[e]}function Y(e,t){const n=this;if(e)return n.update(e,t),n}function Z(e){return e?this.__ref&&this.__ref[e]:this.__ref}function K(){const e=this.getRef("__children");return Array.isArray(e)?e.map(t=>this[t]):[]}function X(){return this.getRef().path}let m=null;const q=e=>{m=e||null},tt=(e,t)=>{e&&t&&m===e&&(m=t)},k=()=>m||null;function et(e){let t=null;const n=o=>o.__element&&o.root?.isRootState;if(!this)t=k();else if(n(this))t=this.root;else if(this.__ref&&this.__ref.path){const o=this.state&&n(this.state),r=(0,f.isFunction)(this.state)&&this.parent.state&&n(this.parent.state);(o||r)&&(t=this.state.root||this.parent.state.root)}return t||(t=k()),e?t?.[e]:t}function nt(e){const t=this?.__ref?.root||this.getRootState()?.__element;if(!t)throw new Error(`[smbls] getRoot() could not resolve a root element for "${this?.key||"<unknown>"}" \u2014 it has no __ref (never went through create()) and no root state is registered. Answering undefined here used to no-op silently for every caller.`);return Object.keys(t).length>0&&e?t[e]:t}function ot(e){return this.getRoot("data")&&Object.keys(this.getRoot("data")).length>0&&e?this.getRoot("data")[e]:this.getRoot("data")}function rt(e){const t=this.getRoot()?.context;return e?t[e]:t}function st(e){const t=this.context;return e?t[e]:t}const it=(e,t,n,o)=>Object.defineProperty(e,t,{get:n,set:o});function N(){const e=this,t=[];for(const n in e)!Object.prototype.hasOwnProperty.call(e,n)||d.DOMQ_PROPERTIES.has(n)&&!d.PARSED_DOMQ_PROPERTIES.has(n)||t.push(n);return t}function j(e=[]){const t=this,n={},o=N.call(t),r=o.includes("children"),s=e.length?new Set(e):null;for(let i=0;i<o.length;i++){const c=o[i];if(s&&s.has(c)||!Object.prototype.hasOwnProperty.call(t,c)||r&&c==="content")continue;const l=t[c];if(c==="state"){if(t.__ref&&!t.__ref.__hasRootState)continue;const u=(0,f.isFunction)(l&&l.parse)?l.parse():l;n[c]=(0,f.isFunction)(u)?u:JSON.parse(JSON.stringify(u||{}))}else if(c==="scope"){if(t.__ref&&!t.__ref.__hasRootScope)continue;n[c]=JSON.parse(JSON.stringify(l||{}))}else if(c==="props"){const{__element:u,update:a,...p}=t[c];n[c]=p}else(0,f.isDefined)(l)&&Object.prototype.hasOwnProperty.call(t,c)&&(n[c]=l)}return n}function O(e=[],t=new WeakSet){const n=this;if(t.has(n))return;t.add(n);const o=j.call(n,e),r=e.length?new Set(e):null;for(const s in o){if(r&&r.has(s)||!Object.prototype.hasOwnProperty.call(n,s))continue;const i=o[s];Array.isArray(i)?o[s]=i.map(c=>(0,f.isObjectLike)(c)?O.call(c,e,t):c):(0,f.isObjectLike)(i)&&(o[s]=O.call(i,e,t))}return o}function Q(...e){if(h!=="test"&&h!=="development")return;const t=this,{__ref:n}=t;return console.groupCollapsed(t.key),e.length?e.forEach(o=>console.log(`%c${o}:
|
|
2
|
+
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function ct(...e){(h==="test"||h==="development")&&console.log(...e)}function lt(...e){(h==="test"||h==="development")&&console.warn(...e)}function R(...e){if(h==="test"||h==="development"){if(e[e.length-1]?.debugger)debugger;throw e[e.length-1]?.verbose&&Q.call(this),new Error(...e)}}function ft(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function ut(e){const t=e||this,{key:n,parent:o}=t,{__children:r}=o.__ref;if(!r)return;const s=r.indexOf(n);return o[r[s-1]]}function at(e={}){const t=this;t.data||(t.data={}),t.data.varCaches||(t.data.varCaches={});const n=t.data.varCaches,o={};let r;for(const s in e)e[s]!==n[s]&&(r=!0,o[s]=e[s]);return{changed:s=>{if(!r)return;const i=s(o,(0,y.deepClone)(n));for(const c in o)n[c]=o[c];return i},timeout:(s,i)=>{if(!r)return;const c=setTimeout(()=>{s(o),clearTimeout(c)},i)}}}function ht(e,...t){const n=this.context,o=n.utils?.[e]||n.functions?.[e]||n.methods?.[e]||n.snippets?.[e];if(o&&!(0,y.isFailedRevival)(o))try{const r=o.call(this,...t);return r&&typeof r.then=="function"&&r.catch(s=>{R.call(this,s)}),r}catch(r){if(R.call(this,r),n?.strictMode)throw r}}const pt="[smbls] getDB needs @symbo.ls/fetch, which the smbls embed bundle does not include: add @symbo.ls/fetch to the page's importmap (the runtime import then resolves) or use the full smbls bundle.",x=()=>import("@symbo.ls/fetch").catch(e=>{throw new Error(pt,{cause:e})});async function dt(){const e=this,t=e.context?.fetch;if(!t)return null;if(typeof t.select=="function"){if(!t.__authInitialized&&t.getSession){const{initAdapterAuth:r}=await x();await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await x();await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=x().then(({resolveDb:r})=>r(t));t.__resolving=n;const o=await n;if(t.__resolved=o,e.context.fetch=o,delete t.__resolving,o?.getSession){const{initAdapterAuth:r}=await x();await r(o,e.context)}return o}function _t(e){const t=this,n=e||b.OPTIONS.useStateQuery||t.context?.useStateQuery;if(!n)return null;const o={};if(S(t,o),n===!0)return o;const r=wt[n];return r?r(o):o}const S=(e,t)=>{const n=e.__ref;if(!n)return;const o=n.__state;o&&typeof o=="string"&>(t,o);const r=n.__children;if(r)for(let c=0;c<r.length;c++){const l=e[r[c]];l&&l.__ref&&S(l,t)}const s=n.contentElementKey||"content",i=e[s];i&&i.__ref&&S(i,t)},gt=(e,t)=>{const o=t.replaceAll("../","").replaceAll("~/","").split("/");let r=e;for(let s=0;s<o.length;s++){const i=o[s];s===o.length-1?r[i]||(r[i]=!0):(r[i]===!0&&(r[i]={}),r[i]||(r[i]={}),r=r[i])}},E=(e,t=0)=>{const n=" ".repeat(t),o=Object.entries(e);return o.length?o.map(([s,i])=>i===!0?`${n}${s}`:`${n}${s} {
|
|
3
3
|
${E(i,t+1)}
|
|
4
4
|
${n}}`).join(`
|
|
5
|
-
`):""},
|
|
5
|
+
`):""},mt=e=>`{
|
|
6
6
|
${E(e,1)}
|
|
7
|
-
}`,
|
|
7
|
+
}`,xt=e=>{const t={fields:{},include:[]},n=(o,r)=>{const s=[];for(const i in o)if(o[i]===!0)s.push(i);else{const c=r?`${r}.${i}`:i;t.include.push(c),n(o[i],c)}s.length&&(t.fields[r||"_root"]=s)};return n(e,""),t},yt=e=>{const t=s=>{const i=[],c=[];for(const l in s)if(s[l]===!0)i.push(l);else{const u=t(s[l]),a=[];u.select&&a.push(`$select=${u.select}`),u.expand&&a.push(`$expand=${u.expand}`),c.push(a.length?`${l}(${a.join(";")})`:l)}return{select:i.length?i.join(","):"",expand:c.length?c.join(","):""}},{select:n,expand:o}=t(e),r=[];return n&&r.push(`$select=${n}`),o&&r.push(`$expand=${o}`),r.join("&")},vt=(e,t)=>{const n=[],o=[],r=new Set,s=(a,p,v)=>{r.add(p),v&&o.push(`LEFT JOIN ${p} ON ${p}.${v}_id = ${v}.id`);for(const _ in a)a[_]===!0?n.push(`${p}.${_}`):s(a[_],_,p)},i=Object.keys(e);i.length===1&&e[i[0]]!==!0?s(e[i[0]],i[0],null):s(e,"_root",null);const c=[...r][0]||"_root",l=n.length?n.join(", "):"*",u=o.length?`
|
|
8
8
|
`+o.join(`
|
|
9
9
|
`):"";return`SELECT ${l}
|
|
10
|
-
FROM ${c}${u}`},
|
|
10
|
+
FROM ${c}${u}`},St=e=>{const t=[],n=(o,r)=>{for(const s in o){const i=r?`${r}/${s}`:s;o[s]===!0?t.push(i):n(o[s],i)}};return n(e,""),t},wt={graphql:mt,"json-api":xt,odata:yt,sql:vt,paths:St};function Ot(e,t){return!!(d.METHODS.has(e)||t?.context?.methods?.[e])}
|
package/dist/cjs/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var E=(e,r)=>{for(var n in r)d(e,n,{get:r[n],enumerable:!0})},A=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of v(r))!x.call(e,o)&&o!==n&&d(e,o,{get:()=>r[o],enumerable:!(t=j(r,o))||t.enumerable});return e};var I=e=>A(d({},"__esModule",{value:!0}),e);var U={};E(U,{applyDependentState:()=>B,checkForStateTypes:()=>D,checkIfInherits:()=>O,createInheritedState:()=>K,createNestedObjectByKeyPath:()=>T,findInheritedState:()=>m,getChildStateInKey:()=>w,getParentStateInKey:()=>P,getRootStateInKey:()=>b,isPolyglotRetranslatableKey:()=>F,isPolyglotWritableKey:()=>M,isState:()=>R,markPolyglotSeeded:()=>L,overwriteState:()=>C,polyglotSeededKeys:()=>p});module.exports=I(U);var S=require("./array.js"),f=require("./keys.js"),c=require("./object.js"),l=require("./types.js");const D=e=>{const{state:r,props:n,__ref:t}=e,o=n?.state||r;return(0,l.is)(o)("string","number")?(t.__state=o,{value:o}):o===!0?(t.__state=e.key,{}):o?(t.__hasRootState=!0,o):!1},b=(e,r)=>{if(!e.includes("~/"))return;if(e.split("~/").length>1)return r.root},P=(e,r)=>{if(!e.includes("../"))return;const t=e.split("../").length-1;for(let o=0;o<t;o++){if(!r.parent)return null;r=r.parent}return r},w=(e,r,n={})=>{const t=(0,l.isString)(e)?e.split("/"):[e],o=t.length-1;for(let i=0;i<o;i++){const s=t[i],u=t[i+1];if(s==="__proto__"||u==="__proto__")return;let a=r[s];a||(a=r[s]={}),a[u]||(a[u]={}),e=u,r=a}return n.returnParent?r:r[e]},m=(e,r,n={})=>{let o=e.__ref.__state;if(!O(e))return;const i=b(o,r.state);let s=r.state;if(i)s=i,o=o.replaceAll("~/","");else{const u=P(o,r.state);u&&(s=u,o=o.replaceAll("../",""))}if(s)return w(o,s,n)},K=(e,r)=>{const n=e.__ref,t=m(e,r);if(t===void 0)return e.state;if((0,l.is)(t)("object","array"))return(0,c.deepClone)(t);if((0,l.is)(t)("string","number","boolean"))return n.__stateType=typeof t,{value:t};console.warn(n.__state,"is not present. Replacing with",{})},O=e=>{const{__ref:r}=e,n=r?.__state;return!!(n&&(0,l.is)(n)("number","string","boolean"))},R=function(e){return(0,l.isObjectLike)(e)?!!(e.update&&e.parse&&e.clean&&e.create&&e.parent&&e.destroy&&e.rootUpdate&&e.parentUpdate&&e.keys&&e.values&&e.toggle&&e.replace&&e.quietUpdate&&e.quietReplace&&e.add&&e.apply&&e.applyReplace&&e.setByPath&&e.setPathCollection&&e.removeByPath&&e.removePathCollection&&e.getByPath&&e.applyFunction&&e.__element&&e.__children):!1},T=(e,r)=>{if(!e)return r||{};const n=e.split("/"),t={};let o=t;const i=n.length-1;for(let s=0;s<=i;s++)o[n[s]]=s===i?r||{}:{},o=o[n[s]];return t},B=(e,r)=>{const{__element:n}=r,t=n?.state;if(!t)return;const o=(0,c.deepClone)(t,f.STATE_METHODS),i={[e.key]:o},s=(0,l.isObject)(t.__depends)?{...t.__depends,...i}:i;return Array.isArray(t)?(0,S.addProtoToArray)(t,{...Object.getPrototypeOf(t),__depends:s}):Object.setPrototypeOf(t,{...Object.getPrototypeOf(t),__depends:s}),o},C=(e,r,n={})=>{const{overwrite:t}=n;if(!t)return;const o=t==="shallow";if(t==="merge"){(0,c.deepMerge)(e,r,f.STATE_METHODS);return}(o?c.overwriteShallow:c.overwriteDeep)(e,r,f.STATE_METHODS)},_="__polyglotSeededKeys",p=e=>{if(!(0,l.isObject)(e))return new Set;let r=e[_];if(!(r instanceof Set)){r=new Set;try{Object.defineProperty(e,_,{value:r,enumerable:!1,writable:!0,configurable:!0})}catch{}}return r},M=(e,r,n)=>p(e).has(r)?!0:!(0,l.isObject)(n)||n[r]===void 0,g="__polyglotSeededValues",y=e=>{if(!(0,l.isObject)(e))return new Map;let r=e[g];if(!(r instanceof Map)){r=new Map;try{Object.defineProperty(e,g,{value:r,enumerable:!1,writable:!0,configurable:!0})}catch{}}return r},h=e=>{if(e===null||typeof e!="object")return typeof e+":"+String(e);try{return"json:"+JSON.stringify(e)}catch{return null}},F=(e,r,n)=>{if(!p(e).has(r))return!1;const t=y(e);if(!t.has(r))return!0;const o=(0,l.isObject)(n)||Array.isArray(n)?n[r]:void 0,i=h(o);return i!==null&&i===t.get(r)},L=(e,r,...n)=>(p(e).add(r),n.length&&y(e).set(r,h(n[0])),r);
|
package/dist/esm/methods.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{triggerEventOn as
|
|
2
|
-
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function
|
|
3
|
-
${
|
|
1
|
+
import{triggerEventOn as y}from"./triggerEvent.js";import{DOMQ_PROPERTIES as $,METHODS as k,PARSED_DOMQ_PROPERTIES as E}from"./keys.js";import{isDefined as P,isFunction as p,isObject as A,isObjectLike as v}from"./types.js";import{deepClone as b,isFailedRevival as C}from"./object.js";import{isProduction as N}from"./env.js";import{removeValueFromArray as j}from"./array.js";import{OPTIONS as Q}from"./cache.js";const a="production";function tt(e){const t=this,{__ref:n}=t,o=[].concat(e);let r=n.root[o[0]];if(!o||!o.length)return console.log(o,"on",t.key,"is undefined");for(;r.key===o[0]&&(o.shift(),!!o.length);)if(r=r[o[0]],!r)return;return r}function et(e){const t=this;let{parent:n}=t;if(p(e))return n.state&&e(n,n.state,n.context)?n:n.parent?n.lookup(e):void 0;if(t[e])return t[e];for(;n.param!==e;){if(n[e])return n[e];if(n=n.parent,!n)return}return n}function nt(e){const t=this,{__ref:n}=t,o=n?.__children;if(o)for(let r=0;r<o.length;r++){const s=o[r],i=t[s];if(s===e)return i;if(p(e)){const l=e(i,i.state,i.context);if(i.state&&l)return i}const c=i?.lookdown?.(e);if(c)return c}}function ot(e,t=[]){const n=this,{__ref:o}=n,r=o?.__children;if(r){for(let s=0;s<r.length;s++){const i=r[s],c=n[i];if(i===e)t.push(c);else if(p(e)){const l=e(c,c.state,c.context);c.state&&l&&t.push(c)}c?.lookdownAll?.(e,t)}return t.length?t:void 0}}function D(e={}){const t=this;if(t.node?.style){for(const n in e){const o=e[n],r=t[n];if(A(o)&&r)D.call(r,o);else if(o!=null){const s=n.replace(/[A-Z]/g,c=>"-"+c.toLowerCase()),i=String(o).replace(/\s*!important\s*$/,"");t.node.style.setProperty(s,i,"important")}}return t}}function rt(e){const t=this;if(y("beforeRemove",t,e)===!1)return t;p(t.node.remove)?t.node.remove():N()||(console.warn("This item cant be removed"),t.log()),delete t.parent[t.key],t.parent.__ref&&(t.parent.__ref.__children=j(t.parent.__ref.__children,t.key)),y("remove",t,e)}function st(e){return this[e]}function it(e,t){const n=this;if(e)return n.update(e,t),n}function ct(e){return e?this.__ref&&this.__ref[e]:this.__ref}function lt(){const e=this.getRef("__children");return Array.isArray(e)?e.map(t=>this[t]):[]}function ft(){return this.getRef().path}let _=null;const ut=e=>{_=e||null},at=(e,t)=>{e&&t&&_===e&&(_=t)},S=()=>_||null;function ht(e){let t=null;const n=o=>o.__element&&o.root?.isRootState;if(!this)t=S();else if(n(this))t=this.root;else if(this.__ref&&this.__ref.path){const o=this.state&&n(this.state),r=p(this.state)&&this.parent.state&&n(this.parent.state);(o||r)&&(t=this.state.root||this.parent.state.root)}return t||(t=S()),e?t?.[e]:t}function pt(e){const t=this?.__ref?.root||this.getRootState()?.__element;if(!t)throw new Error(`[smbls] getRoot() could not resolve a root element for "${this?.key||"<unknown>"}" \u2014 it has no __ref (never went through create()) and no root state is registered. Answering undefined here used to no-op silently for every caller.`);return Object.keys(t).length>0&&e?t[e]:t}function dt(e){return this.getRoot("data")&&Object.keys(this.getRoot("data")).length>0&&e?this.getRoot("data")[e]:this.getRoot("data")}function _t(e){const t=this.getRoot()?.context;return e?t[e]:t}function gt(e){const t=this.context;return e?t[e]:t}const mt=(e,t,n,o)=>Object.defineProperty(e,t,{get:n,set:o});function I(){const e=this,t=[];for(const n in e)!Object.prototype.hasOwnProperty.call(e,n)||$.has(n)&&!E.has(n)||t.push(n);return t}function T(e=[]){const t=this,n={},o=I.call(t),r=o.includes("children"),s=e.length?new Set(e):null;for(let i=0;i<o.length;i++){const c=o[i];if(s&&s.has(c)||!Object.prototype.hasOwnProperty.call(t,c)||r&&c==="content")continue;const l=t[c];if(c==="state"){if(t.__ref&&!t.__ref.__hasRootState)continue;const f=p(l&&l.parse)?l.parse():l;n[c]=p(f)?f:JSON.parse(JSON.stringify(f||{}))}else if(c==="scope"){if(t.__ref&&!t.__ref.__hasRootScope)continue;n[c]=JSON.parse(JSON.stringify(l||{}))}else if(c==="props"){const{__element:f,update:u,...h}=t[c];n[c]=h}else P(l)&&Object.prototype.hasOwnProperty.call(t,c)&&(n[c]=l)}return n}function w(e=[],t=new WeakSet){const n=this;if(t.has(n))return;t.add(n);const o=T.call(n,e),r=e.length?new Set(e):null;for(const s in o){if(r&&r.has(s)||!Object.prototype.hasOwnProperty.call(n,s))continue;const i=o[s];Array.isArray(i)?o[s]=i.map(c=>v(c)?w.call(c,e,t):c):v(i)&&(o[s]=w.call(i,e,t))}return o}function F(...e){if(a!=="test"&&a!=="development")return;const t=this,{__ref:n}=t;return console.groupCollapsed(t.key),e.length?e.forEach(o=>console.log(`%c${o}:
|
|
2
|
+
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function xt(...e){(a==="test"||a==="development")&&console.log(...e)}function yt(...e){(a==="test"||a==="development")&&console.warn(...e)}function O(...e){if(a==="test"||a==="development"){if(e[e.length-1]?.debugger)debugger;throw e[e.length-1]?.verbose&&F.call(this),new Error(...e)}}function vt(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function St(e){const t=e||this,{key:n,parent:o}=t,{__children:r}=o.__ref;if(!r)return;const s=r.indexOf(n);return o[r[s-1]]}function wt(e={}){const t=this;t.data||(t.data={}),t.data.varCaches||(t.data.varCaches={});const n=t.data.varCaches,o={};let r;for(const s in e)e[s]!==n[s]&&(r=!0,o[s]=e[s]);return{changed:s=>{if(!r)return;const i=s(o,b(n));for(const c in o)n[c]=o[c];return i},timeout:(s,i)=>{if(!r)return;const c=setTimeout(()=>{s(o),clearTimeout(c)},i)}}}function Ot(e,...t){const n=this.context,o=n.utils?.[e]||n.functions?.[e]||n.methods?.[e]||n.snippets?.[e];if(o&&!C(o))try{const r=o.call(this,...t);return r&&typeof r.then=="function"&&r.catch(s=>{O.call(this,s)}),r}catch(r){if(O.call(this,r),n?.strictMode)throw r}}const L="[smbls] getDB needs @symbo.ls/fetch, which the smbls embed bundle does not include: add @symbo.ls/fetch to the page's importmap (the runtime import then resolves) or use the full smbls bundle.",g=()=>import("@symbo.ls/fetch").catch(e=>{throw new Error(L,{cause:e})});async function Rt(){const e=this,t=e.context?.fetch;if(!t)return null;if(typeof t.select=="function"){if(!t.__authInitialized&&t.getSession){const{initAdapterAuth:r}=await g();await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await g();await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=g().then(({resolveDb:r})=>r(t));t.__resolving=n;const o=await n;if(t.__resolved=o,e.context.fetch=o,delete t.__resolving,o?.getSession){const{initAdapterAuth:r}=await g();await r(o,e.context)}return o}function $t(e){const t=this,n=e||Q.useStateQuery||t.context?.useStateQuery;if(!n)return null;const o={};if(x(t,o),n===!0)return o;const r=H[n];return r?r(o):o}const x=(e,t)=>{const n=e.__ref;if(!n)return;const o=n.__state;o&&typeof o=="string"&&M(t,o);const r=n.__children;if(r)for(let c=0;c<r.length;c++){const l=e[r[c]];l&&l.__ref&&x(l,t)}const s=n.contentElementKey||"content",i=e[s];i&&i.__ref&&x(i,t)},M=(e,t)=>{const o=t.replaceAll("../","").replaceAll("~/","").split("/");let r=e;for(let s=0;s<o.length;s++){const i=o[s];s===o.length-1?r[i]||(r[i]=!0):(r[i]===!0&&(r[i]={}),r[i]||(r[i]={}),r=r[i])}},R=(e,t=0)=>{const n=" ".repeat(t),o=Object.entries(e);return o.length?o.map(([s,i])=>i===!0?`${n}${s}`:`${n}${s} {
|
|
3
|
+
${R(i,t+1)}
|
|
4
4
|
${n}}`).join(`
|
|
5
|
-
`):""},
|
|
6
|
-
${
|
|
7
|
-
}`,
|
|
5
|
+
`):""},J=e=>`{
|
|
6
|
+
${R(e,1)}
|
|
7
|
+
}`,G=e=>{const t={fields:{},include:[]},n=(o,r)=>{const s=[];for(const i in o)if(o[i]===!0)s.push(i);else{const c=r?`${r}.${i}`:i;t.include.push(c),n(o[i],c)}s.length&&(t.fields[r||"_root"]=s)};return n(e,""),t},B=e=>{const t=s=>{const i=[],c=[];for(const l in s)if(s[l]===!0)i.push(l);else{const f=t(s[l]),u=[];f.select&&u.push(`$select=${f.select}`),f.expand&&u.push(`$expand=${f.expand}`),c.push(u.length?`${l}(${u.join(";")})`:l)}return{select:i.length?i.join(","):"",expand:c.length?c.join(","):""}},{select:n,expand:o}=t(e),r=[];return n&&r.push(`$select=${n}`),o&&r.push(`$expand=${o}`),r.join("&")},V=(e,t)=>{const n=[],o=[],r=new Set,s=(u,h,m)=>{r.add(h),m&&o.push(`LEFT JOIN ${h} ON ${h}.${m}_id = ${m}.id`);for(const d in u)u[d]===!0?n.push(`${h}.${d}`):s(u[d],d,h)},i=Object.keys(e);i.length===1&&e[i[0]]!==!0?s(e[i[0]],i[0],null):s(e,"_root",null);const c=[...r][0]||"_root",l=n.length?n.join(", "):"*",f=o.length?`
|
|
8
8
|
`+o.join(`
|
|
9
9
|
`):"";return`SELECT ${l}
|
|
10
|
-
FROM ${c}${f}`},
|
|
10
|
+
FROM ${c}${f}`},z=e=>{const t=[],n=(o,r)=>{for(const s in o){const i=r?`${r}/${s}`:s;o[s]===!0?t.push(i):n(o[s],i)}};return n(e,""),t},H={graphql:J,"json-api":G,odata:B,sql:V,paths:z};function kt(e,t){return!!(k.has(e)||t?.context?.methods?.[e])}export{Ot as call,mt as defineSetter,O as error,st as get,lt as getChildren,gt as getContext,Rt as getDB,ft as getPath,$t as getQuery,ct as getRef,pt as getRoot,_t as getRootContext,dt as getRootData,ht as getRootState,kt as isMethod,I as keys,xt as log,nt as lookdown,ot as lookdownAll,et as lookup,vt as nextElement,T as parse,w as parseDeep,St as previousElement,at as promoteActiveRootState,rt as remove,ut as setActiveRootState,D as setNodeStyles,it as setProps,tt as spotByPath,wt as variables,F as verbose,yt as warn};
|
package/dist/esm/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{addProtoToArray as
|
|
1
|
+
import{addProtoToArray as S}from"./array.js";import{STATE_METHODS as f}from"./keys.js";import{deepClone as d,deepMerge as b,overwriteDeep as P,overwriteShallow as w}from"./object.js";import{is as a,isObject as u,isObjectLike as m,isString as O}from"./types.js";const T=e=>{const{state:r,props:n,__ref:t}=e,o=n?.state||r;return a(o)("string","number")?(t.__state=o,{value:o}):o===!0?(t.__state=e.key,{}):o?(t.__hasRootState=!0,o):!1},j=(e,r)=>{if(!e.includes("~/"))return;if(e.split("~/").length>1)return r.root},v=(e,r)=>{if(!e.includes("../"))return;const t=e.split("../").length-1;for(let o=0;o<t;o++){if(!r.parent)return null;r=r.parent}return r},x=(e,r,n={})=>{const t=O(e)?e.split("/"):[e],o=t.length-1;for(let i=0;i<o;i++){const s=t[i],l=t[i+1];if(s==="__proto__"||l==="__proto__")return;let c=r[s];c||(c=r[s]={}),c[l]||(c[l]={}),e=l,r=c}return n.returnParent?r:r[e]},E=(e,r,n={})=>{let o=e.__ref.__state;if(!A(e))return;const i=j(o,r.state);let s=r.state;if(i)s=i,o=o.replaceAll("~/","");else{const l=v(o,r.state);l&&(s=l,o=o.replaceAll("../",""))}if(s)return x(o,s,n)},B=(e,r)=>{const n=e.__ref,t=E(e,r);if(t===void 0)return e.state;if(a(t)("object","array"))return d(t);if(a(t)("string","number","boolean"))return n.__stateType=typeof t,{value:t};console.warn(n.__state,"is not present. Replacing with",{})},A=e=>{const{__ref:r}=e,n=r?.__state;return!!(n&&a(n)("number","string","boolean"))},C=function(e){return m(e)?!!(e.update&&e.parse&&e.clean&&e.create&&e.parent&&e.destroy&&e.rootUpdate&&e.parentUpdate&&e.keys&&e.values&&e.toggle&&e.replace&&e.quietUpdate&&e.quietReplace&&e.add&&e.apply&&e.applyReplace&&e.setByPath&&e.setPathCollection&&e.removeByPath&&e.removePathCollection&&e.getByPath&&e.applyFunction&&e.__element&&e.__children):!1},M=(e,r)=>{if(!e)return r||{};const n=e.split("/"),t={};let o=t;const i=n.length-1;for(let s=0;s<=i;s++)o[n[s]]=s===i?r||{}:{},o=o[n[s]];return t},F=(e,r)=>{const{__element:n}=r,t=n?.state;if(!t)return;const o=d(t,f),i={[e.key]:o},s=u(t.__depends)?{...t.__depends,...i}:i;return Array.isArray(t)?S(t,{...Object.getPrototypeOf(t),__depends:s}):Object.setPrototypeOf(t,{...Object.getPrototypeOf(t),__depends:s}),o},L=(e,r,n={})=>{const{overwrite:t}=n;if(!t)return;const o=t==="shallow";if(t==="merge"){b(e,r,f);return}(o?w:P)(e,r,f)},_="__polyglotSeededKeys",p=e=>{if(!u(e))return new Set;let r=e[_];if(!(r instanceof Set)){r=new Set;try{Object.defineProperty(e,_,{value:r,enumerable:!1,writable:!0,configurable:!0})}catch{}}return r},U=(e,r,n)=>p(e).has(r)?!0:!u(n)||n[r]===void 0,g="__polyglotSeededValues",y=e=>{if(!u(e))return new Map;let r=e[g];if(!(r instanceof Map)){r=new Map;try{Object.defineProperty(e,g,{value:r,enumerable:!1,writable:!0,configurable:!0})}catch{}}return r},h=e=>{if(e===null||typeof e!="object")return typeof e+":"+String(e);try{return"json:"+JSON.stringify(e)}catch{return null}},k=(e,r,n)=>{if(!p(e).has(r))return!1;const t=y(e);if(!t.has(r))return!0;const o=u(n)||Array.isArray(n)?n[r]:void 0,i=h(o);return i!==null&&i===t.get(r)},V=(e,r,...n)=>(p(e).add(r),n.length&&y(e).set(r,h(n[0])),r);export{F as applyDependentState,T as checkForStateTypes,A as checkIfInherits,B as createInheritedState,M as createNestedObjectByKeyPath,E as findInheritedState,x as getChildStateInKey,v as getParentStateInKey,j as getRootStateInKey,k as isPolyglotRetranslatableKey,U as isPolyglotWritableKey,C as isState,V as markPolyglotSeeded,L as overwriteState,p as polyglotSeededKeys};
|
package/methods.js
CHANGED
|
@@ -509,20 +509,32 @@ export function call (fnKey, ...args) {
|
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
+
// The fetch plugin, loaded on demand — getDB needs it only when the context
|
|
513
|
+
// configures a database (`context.fetch`). A bundle that ships without
|
|
514
|
+
// plugins (the smbls embed IIFE keeps `@symbo.ls/fetch` external,
|
|
515
|
+
// FW-EMBED-BUNDLE-UNDER-64K-OR-JUSTIFY-72K-1) cannot resolve it, so the
|
|
516
|
+
// failure names the cause instead of a bare module-specifier error.
|
|
517
|
+
const FETCH_PLUGIN_MISSING_MESSAGE =
|
|
518
|
+
"[smbls] getDB needs @symbo.ls/fetch, which the smbls embed bundle does not include: " +
|
|
519
|
+
"add @symbo.ls/fetch to the page's importmap (the runtime import then resolves) or use the full smbls bundle."
|
|
520
|
+
const loadFetchPlugin = () => import('@symbo.ls/fetch').catch((err) => {
|
|
521
|
+
throw new Error(FETCH_PLUGIN_MISSING_MESSAGE, { cause: err })
|
|
522
|
+
})
|
|
523
|
+
|
|
512
524
|
export async function getDB () {
|
|
513
525
|
const element = this
|
|
514
526
|
const db = element.context?.fetch
|
|
515
527
|
if (!db) return null
|
|
516
528
|
if (typeof db.select === 'function') {
|
|
517
529
|
if (!db.__authInitialized && db.getSession) {
|
|
518
|
-
const { initAdapterAuth } = await
|
|
530
|
+
const { initAdapterAuth } = await loadFetchPlugin()
|
|
519
531
|
await initAdapterAuth(db, element.context)
|
|
520
532
|
}
|
|
521
533
|
return db
|
|
522
534
|
}
|
|
523
535
|
if (db.__resolved) {
|
|
524
536
|
if (!db.__resolved.__authInitialized && db.__resolved.getSession) {
|
|
525
|
-
const { initAdapterAuth } = await
|
|
537
|
+
const { initAdapterAuth } = await loadFetchPlugin()
|
|
526
538
|
await initAdapterAuth(db.__resolved, element.context)
|
|
527
539
|
}
|
|
528
540
|
return db.__resolved
|
|
@@ -530,7 +542,7 @@ export async function getDB () {
|
|
|
530
542
|
if (db.__resolving) return db.__resolving
|
|
531
543
|
// Set __resolving synchronously BEFORE the async import to prevent
|
|
532
544
|
// resolveAdapter() from starting a parallel resolveDb() during the yield
|
|
533
|
-
const resolvePromise =
|
|
545
|
+
const resolvePromise = loadFetchPlugin().then(({ resolveDb }) => resolveDb(db))
|
|
534
546
|
db.__resolving = resolvePromise
|
|
535
547
|
const resolved = await resolvePromise
|
|
536
548
|
db.__resolved = resolved
|
|
@@ -545,7 +557,7 @@ export async function getDB () {
|
|
|
545
557
|
// unwinds the entire fetch boot — silently breaking every consumer
|
|
546
558
|
// that depended on the adapter.
|
|
547
559
|
if (resolved?.getSession) {
|
|
548
|
-
const { initAdapterAuth } = await
|
|
560
|
+
const { initAdapterAuth } = await loadFetchPlugin()
|
|
549
561
|
await initAdapterAuth(resolved, element.context)
|
|
550
562
|
}
|
|
551
563
|
return resolved
|
package/package.json
CHANGED
package/state.js
CHANGED
|
@@ -250,10 +250,14 @@ export const polyglotSeededKeys = (context) => {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
|
-
* May
|
|
254
|
-
* before, or when nothing declares it yet. A key a project, an app or a
|
|
253
|
+
* May BOOT seeding write `key` into the root state? Only when polyglot seeded
|
|
254
|
+
* it before, or when nothing declares it yet. A key a project, an app or a
|
|
255
255
|
* shared library declares is never polyglot's to overwrite.
|
|
256
256
|
*
|
|
257
|
+
* A language SWITCH asks `isPolyglotRetranslatableKey` instead: "nothing
|
|
258
|
+
* declares it yet" is true of every app flag that is not in state.js, so on a
|
|
259
|
+
* switch it handed any such flag whose NAME matched a text key that key's text.
|
|
260
|
+
*
|
|
257
261
|
* @param {object} context - the app context carrying the seeded-key record
|
|
258
262
|
* @param {string} key - the translation key about to be written
|
|
259
263
|
* @param {object} [declared] - the state to test the key against
|
|
@@ -263,11 +267,63 @@ export const isPolyglotWritableKey = (context, key, declared) => {
|
|
|
263
267
|
return !isObject(declared) || declared[key] === undefined
|
|
264
268
|
}
|
|
265
269
|
|
|
270
|
+
// What polyglot last wrote into each key it seeded — a signature, so a store
|
|
271
|
+
// proxy over the same array or object still matches. Non-enumerable on the
|
|
272
|
+
// context, like SEEDED_KEYS.
|
|
273
|
+
const SEEDED_VALUES = '__polyglotSeededValues'
|
|
274
|
+
const seededValues = (context) => {
|
|
275
|
+
if (!isObject(context)) return new Map()
|
|
276
|
+
let values = context[SEEDED_VALUES]
|
|
277
|
+
if (!(values instanceof Map)) {
|
|
278
|
+
values = new Map()
|
|
279
|
+
try {
|
|
280
|
+
Object.defineProperty(context, SEEDED_VALUES, {
|
|
281
|
+
value: values,
|
|
282
|
+
enumerable: false,
|
|
283
|
+
writable: true,
|
|
284
|
+
configurable: true
|
|
285
|
+
})
|
|
286
|
+
} catch (e) { /* a frozen context keeps no record — see polyglotSeededKeys */ }
|
|
287
|
+
}
|
|
288
|
+
return values
|
|
289
|
+
}
|
|
290
|
+
const seededSignature = (value) => {
|
|
291
|
+
if (value === null || typeof value !== 'object') return typeof value + ':' + String(value)
|
|
292
|
+
try { return 'json:' + JSON.stringify(value) } catch (e) { return null }
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* May a language SWITCH (setLang) write `key` into the root state? Only when
|
|
297
|
+
* polyglot seeded the key itself AND the slot still holds exactly what
|
|
298
|
+
* polyglot wrote. Never by name alone:
|
|
299
|
+
* - a key polyglot never seeded is the app's, even when it is empty — an
|
|
300
|
+
* undeclared app flag whose name matches a text key stays untouched
|
|
301
|
+
* (measured on dev, CRM app 1.0.87, 2026-10-01: an en <-> ka switch wrote
|
|
302
|
+
* "Delete deal" into the `crmDealDelete` open flag and opened the dialog);
|
|
303
|
+
* - a seeded key the app has since set to its own value is the app's now.
|
|
304
|
+
* A bare `{{ key }}` template still translates: the template resolver falls
|
|
305
|
+
* back to the active translation map when the state holds nothing.
|
|
306
|
+
*
|
|
307
|
+
* @param {object} context - the app context carrying the seeded-key record
|
|
308
|
+
* @param {string} key - the translation key about to be written
|
|
309
|
+
* @param {object} [current] - the root state holding the key now
|
|
310
|
+
*/
|
|
311
|
+
export const isPolyglotRetranslatableKey = (context, key, current) => {
|
|
312
|
+
if (!polyglotSeededKeys(context).has(key)) return false
|
|
313
|
+
const values = seededValues(context)
|
|
314
|
+
if (!values.has(key)) return true // seeded by a caller that recorded no value
|
|
315
|
+
const now = isObject(current) || Array.isArray(current) ? current[key] : undefined
|
|
316
|
+
const sig = seededSignature(now)
|
|
317
|
+
return sig !== null && sig === values.get(key)
|
|
318
|
+
}
|
|
319
|
+
|
|
266
320
|
/**
|
|
267
|
-
* Record that polyglot seeded `key
|
|
268
|
-
* it
|
|
321
|
+
* Record that polyglot seeded `key` (and, when given, the value it wrote), so
|
|
322
|
+
* a later language switch may retranslate it while the slot still holds that
|
|
323
|
+
* value. Returns the key, for use inline.
|
|
269
324
|
*/
|
|
270
|
-
export const markPolyglotSeeded = (context, key) => {
|
|
325
|
+
export const markPolyglotSeeded = (context, key, ...written) => {
|
|
271
326
|
polyglotSeededKeys(context).add(key)
|
|
327
|
+
if (written.length) seededValues(context).set(key, seededSignature(written[0]))
|
|
272
328
|
return key
|
|
273
329
|
}
|