@symbo.ls/utils 3.14.775 → 3.14.776
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/keys.js +1 -1
- package/dist/cjs/methods.js +5 -5
- package/dist/cjs/sharedLibraries.js +1 -1
- package/dist/cjs/string.js +3 -3
- package/dist/esm/keys.js +1 -1
- package/dist/esm/methods.js +4 -4
- package/dist/esm/sharedLibraries.js +1 -1
- package/dist/esm/string.js +3 -3
- package/keys.js +37 -0
- package/methods.js +19 -0
- package/package.json +1 -1
- package/sharedLibraries.js +96 -4
- package/string.js +43 -0
package/dist/cjs/keys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var E=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},h=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _(t))!i.call(e,o)&&o!==n&&a(e,o,{get:()=>t[o],enumerable:!(s=c(t,o))||s.enumerable});return e};var x=e=>h(a({},"__esModule",{value:!0}),e);var y={};E(y,{DOMQL_EVENTS:()=>g,DOMQ_PROPERTIES:()=>S,ELEMENT_METHOD_OVERRIDE_POINTS:()=>l,METHODS:()=>r,METHODS_EXL:()=>f,PARSED_DOMQ_PROPERTIES:()=>R,PROPS_METHODS:()=>d,STATE_METHODS:()=>p,STATE_PROPERTIES:()=>u,isBuiltinElementMethod:()=>m,isProtectedElementMethod:()=>P});module.exports=x(y);const S=new Set(["attr","style","text","html","content","data","classlist","state","scope","root","deps","extend","extends","$router","routes","children","childExtend","childExtends","childExtendRecursive","childExtendsRecursive","props","if","define","__name","__ref","__hash","__text","key","tag","query","parent","node","variables","on","fetch","component","context","preventContentUpdate","preventContentRecreate"]),R=new Set(["attr","style","text","html","content","data","class","state","scope","children","props","if","key","tag","query","on","context"]),u=["ref","parent","__element","__depends","__ref","__children","root"],p=new Set(["update","parse","clean","create","destroy","add","toggle","remove","apply","set","reset","replace","quietReplace","quietUpdate","applyReplace","applyFunction","keys","values","ref","rootUpdate","parentUpdate","parent","__element","__depends","__ref","__children","root","setByPath","setPathCollection","removeByPath","removePathCollection","getByPath"]),d=new Set(["update","__element"]),r=new Set(["set","reset","update","remove","updateContent","removeContent","lookup","lookdown","lookdownAll","getRef","getPath","setNodeStyles","spotByPath","keys","parse","setProps","parseDeep","variables","if","log","verbose","warn","error","call","nextElement","previousElement","getRootState","getRoot","getRootData","getRootContext","getContext","getQuery","getDB","getChildren","preventContentUpdate","preventContentRecreate"]),m=e=>r.has(e),l=new Set(["log","warn","error","verbose"]),P=e=>r.has(e)&&!l.has(e),f=new Set(["node","context","extends","__element","__ref",...r,...p,...d]),g=new Set(["init","beforeClassAssign","render","renderRouter","attachNode","stateInit","stateCreated","beforeStateUpdate","stateUpdate","beforeUpdate","done","create","complete","frame","update","fetchError","fetchComplete"]);
|
package/dist/cjs/methods.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var D=Object.create;var g=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})}
|
|
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 T=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var I=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 F(t))!L.call(e,r)&&r!==n&&g(e,r,{get:()=>t[r],enumerable:!(o=T(t,r))||o.enumerable});return e};var m=(e,t,n)=>(n=e!=null?D(I(e)):{},$(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),J=e=>$(g({},"__esModule",{value:!0}),e);var wt={};M(wt,{call:()=>at,defineSetter:()=>st,error:()=>R,get:()=>U,getChildren:()=>Z,getContext:()=>rt,getDB:()=>ht,getPath:()=>K,getQuery:()=>pt,getRef:()=>Y,getRoot:()=>et,getRootContext:()=>ot,getRootData:()=>nt,getRootState:()=>tt,isMethod:()=>St,keys:()=>j,log:()=>it,lookdown:()=>z,lookdownAll:()=>G,lookup:()=>B,nextElement:()=>lt,parse:()=>Q,parseDeep:()=>O,previousElement:()=>ft,promoteActiveRootState:()=>q,remove:()=>H,setActiveRootState:()=>X,setNodeStyles:()=>C,setProps:()=>W,spotByPath:()=>V,variables:()=>ut,verbose:()=>N,warn:()=>ct});module.exports=J(wt);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 V(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 B(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 G(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 H(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 U(e){return this[e]}function W(e,t){const n=this;if(e)return n.update(e,t),n}function Y(e){return e?this.__ref&&this.__ref[e]:this.__ref}function Z(){const e=this.getRef("__children");return Array.isArray(e)?e.map(t=>this[t]):[]}function K(){return this.getRef().path}let x=null;const X=e=>{x=e||null},q=(e,t)=>{e&&t&&x===e&&(x=t)},k=()=>x||null;function tt(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 et(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 nt(e){return this.getRoot("data")&&Object.keys(this.getRoot("data")).length>0&&e?this.getRoot("data")[e]:this.getRoot("data")}function ot(e){const t=this.getRoot()?.context;return e?t[e]:t}function rt(e){const t=this.context;return e?t[e]:t}const st=(e,t,n,o)=>Object.defineProperty(e,t,{get:n,set:o});function j(){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 Q(e=[]){const t=this,n={},o=j.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=Q.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 N(...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 it(...e){(h==="test"||h==="development")&&console.log(...e)}function ct(...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&&N.call(this),new Error(...e)}}function lt(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function ft(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 ut(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 at(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}}async function ht(){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 import("@symbo.ls/fetch");await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=import("@symbo.ls/fetch").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 import("@symbo.ls/fetch");await r(o,e.context)}return o}function pt(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=vt[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"&&dt(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)},dt=(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
|
+
`):""},_t=e=>`{
|
|
6
6
|
${E(e,1)}
|
|
7
|
-
}`,
|
|
7
|
+
}`,gt=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},mt=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("&")},xt=(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}`},yt=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},vt={graphql:_t,"json-api":gt,odata:mt,sql:xt,paths:yt};function St(e,t){return!!(d.METHODS.has(e)||t?.context?.methods?.[e])}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var P=(n,t)=>{for(var o in t)h(n,o,{get:t[o],enumerable:!0})},M=(n,t,o,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of F(t))!U.call(n,s)&&s!==o&&h(n,s,{get:()=>t[s],enumerable:!(e=E(t,s))||e.enumerable});return n};var D=n=>M(h({},"__esModule",{value:!0}),n);var nn={};P(nn,{__resetBuiltinMethodWarnings:()=>Y,deepDefaults:()=>p,fetchLibraryData:()=>j,isWrappedLibrary:()=>w,mergeSharedLibraries:()=>Q,normalizeIgnoreList:()=>y,normalizeLibraryKey:()=>u,resolveSharedLibraries:()=>Z,sharedLibrary:()=>K});module.exports=D(nn);var l=require("./types.js"),f=require("./keys.js"),I=require("./env.js");const k="system",T="https://smbls-kv.nika-980.workers.dev",C="https://api.symbols.app";function u(n){const t=String(n||"").trim();if(!t)return{owner:k,key:"",full:""};let o=null,e=t;if(t.includes("/")){const r=t.indexOf("/");o=t.slice(0,r),e=t.slice(r+1)}e=e.replace(/\.symbo\.ls$/iu,""),o||(o=k);const s=e?`${o}/${e}`:"";return{owner:o,key:e,full:s}}const p=(n,t,o,e)=>{for(const s in t){const r=e?`${e}/${s}`:s;o&&o.has(r)||(s in n?(0,l.isObject)(n[s])&&(0,l.isObject)(t[s])&&p(n[s],t[s],o,r):n[s]=t[s])}},$=(n,t,o)=>{if(!(0,l.isObject)(n)||!t.size)return n;const e=`${o}/`;let s=!1;for(const a of t)if(a.startsWith(e)){s=!0;break}if(!s)return n;const r={};for(const a in n){if(!Object.prototype.hasOwnProperty.call(n,a))continue;const i=`${o}/${a}`;t.has(i)||(r[a]=$(n[a],t,i))}return r},N=new Set,G=new Set(["components","pages","functions","snippets","methods"]),L=(n,t)=>t===""&&G.has(n),A=["fontFamily","fontfamily","font_family","FONT_FAMILY"],W=n=>{const t=new Map;if(!(0,l.isObject)(n))return t;for(const o of A){const e=n[o];if((0,l.isObject)(e))for(const s in e)!(0,l.isObject)(e[s])||!e[s].isDefault||(t.has(o)||t.set(o,new Set),t.get(o).add(s))}return t},z=(n,t)=>{for(const o of A){const e=n[o];if(!(0,l.isObject)(e))continue;const s=t.get(o);let r=null;for(const a in e){const i=e[a];if(!(0,l.isObject)(i)||!i.isDefault||s&&s.has(a))continue;const c={...i};delete c.isDefault,r||(r={...e}),r[a]=c}r&&(n[o]=r)}},J=n=>n.replace(/\.js$/iu,""),y=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const o of n){if(!(0,l.isString)(o))continue;const e=o.split("/").map(s=>J(s.trim())).filter(Boolean).join("/");e&&t.add(e)}return t},K=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),w=n=>(0,l.isObject)(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),S=n=>n.library!==void 0?n.library:n.key??n.name,m=new Set,Y=()=>{m.clear()},x=(n,t)=>{const o=t.filter(e=>!m.has(e));if(o.length){for(const e of o)m.add(e);(0,I.isLoudDevRuntime)()&&console.warn(`[smbls] shared library "${n}" ships ${o.map(e=>`methods.${e}`).join(", ")} \u2014 named like a built-in element method. Refused: the built-in wins; a library cannot replace an element method on the consuming app. If the app wants this version, declare it in the app's OWN methods.`)}},V=(n,t,o)=>{let e=null;for(const s in n)if((0,f.isProtectedElementMethod)(s)&&(t.has(`methods/${s}`)||o.push(s),!e)){e={};for(const r in n)(0,f.isProtectedElementMethod)(r)||(e[r]=n[r])}return e||n},q=(n,t,o,e="library")=>{const s=y(t.sharedLibIgnore);t.sharePages===!1&&s.add("pages");const r=s.size?new Set([...o,...s]):o,a=[];for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)&&!(i==="sharePages"||i==="sharedLibIgnore")&&i!=="app"&&!r.has(i)){if((0,l.isObject)(t[i])&&(0,l.isObject)(n[i])){if(i==="designSystem")p(n[i],t[i],r,i);else for(const c in t[i])if(!r.has(`${i}/${c}`)){if(i==="methods"&&(0,f.isProtectedElementMethod)(c)){c in n[i]||a.push(c);continue}c in n[i]?L(i,n[i][c])&&!L(i,t[i][c])&&(n[i][c]=t[i][c]):n[i][c]=t[i][c]}}else if(!(i in n)){const c=t[i],d=i==="methods"&&c&&typeof c=="object"?V(c,r,a):c;n[i]=$(d,r,i)}}a.length&&x(e,a)},H=(n,t,o)=>{if(n!==t){const e=S(n);if((0,l.isString)(e)&&e)return e;if(n.key||n.name)return n.key||n.name}return t&&(t.key||t.name)||`sharedLibraries[${o}]`},Q=(n,t)=>{if(!t||!t.length)return;const o=W(n.designSystem);for(let e=0;e<t.length;e++){const s=t[e];let r=s,a=N;w(r)&&(a=y(r.ignoreList),r=r.library),(0,l.isObject)(r)&&q(n,r,a,H(s,r,e))}o.size&&z(n.designSystem,o)};async function j(n,t={}){if((t.provider||"kv")==="api")return _(n,t);const e=await X(n,t);return e||_(n,t)}async function X(n,t={}){const o=t.kvBaseUrl||T,e=t.env||"production",s=`${o}/kv/${encodeURIComponent(n)}?env=${e}`;try{const r=await fetch(s,{method:"GET"});return r.ok&&(await r.json())?.value||null}catch{return null}}async function _(n,t={}){const o=t.apiBaseUrl||C,{key:e}=u(n);try{const s=`${o}/core/projects/libraries/available?search=${encodeURIComponent(e)}&limit=10`,r=await fetch(s,{method:"GET"});if(!r.ok)return null;const a=await r.json(),c=(a?.items||a?.data||(Array.isArray(a)?a:[])).find(O=>{const{key:B}=u(O?.key);return B.toLowerCase()===e.toLowerCase()});if(!c?.id&&!c?._id)return null;const d=c.id||c._id,R=`${o}/core/projects/${encodeURIComponent(d)}/data?branch=main`,b=await fetch(R,{method:"GET"});if(!b.ok)return null;const g=await b.json();return g?.data||g||null}catch{return null}}async function v(n,t={}){if((0,l.isObject)(n))return n;if((0,l.isString)(n)){const{full:o}=u(n);if(!o)return null;try{const e=await j(o,t);return e||console.warn(`[smbls] Shared library "${o}" not found`),e}catch(e){return console.warn(`[smbls] Failed to fetch shared library "${o}":`,e.message),null}}return null}async function Z(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async e=>{if(w(e)){const s=await v(S(e),t);return s?{library:s,ignoreList:e.ignoreList}:null}return v(e,t)}))).filter(Boolean)}
|
package/dist/cjs/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);let
|
|
3
|
-
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),P=/[^a-zA-Z0-9\s]/g,
|
|
1
|
+
"use strict";var _=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var t in n)_(e,t,{get:n[t],enumerable:!0})},O=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let c of L(n))!j.call(e,c)&&c!==t&&_(e,c,{get:()=>n[c],enumerable:!(s=A(n,c))||s.enumerable});return e};var R=e=>O(_({},"__esModule",{value:!0}),e);var M={};N(M,{customDecodeURIComponent:()=>z,customEncodeURIComponent:()=>q,decodeNewlines:()=>K,encodeNewlines:()=>D,findKeyPosition:()=>v,lowercaseFirstLetter:()=>T,replaceLiteralsWithObjectFields:()=>F,replaceOctalEscapeSequences:()=>V,stringIncludesAny:()=>I,trimStringFromSymbols:()=>k});module.exports=R(M);const I=(e,n)=>{for(const t of n)if(e.includes(t))return!0;return!1},k=(e,n)=>{const t=new RegExp(`[${n.join("\\")}]`,"g");return e.replace(t,"")},E={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},x=(e,n)=>n.split(".").reduce((t,s)=>t?.[s],e),$=(e,n)=>{if(!e||!e.__ref)return!0;let t=e;for(;t;){if(t.allowRuntimeTemplates===!0)return!0;const s=t.__ref&&t.__ref.__authoredTemplates;if(s&&s.has(n))return!0;t=t.parent}return!1};function F(e,n,t={}){const{bracketsLength:s=2}=t,c=s===3?"{{{":"{{";if(!e.includes(c)||!$(this,e))return e;const m=E[s],a=n||this.state||{},u=this;return e.replace(m,(p,d,r,i)=>{const g=r.trim();if(i){const l=u?.context,o=l?.functions?.[i]||l?.utils?.[i]||l?.methods?.[i]||l?.snippets?.[i]||u?.[i];if(o&&typeof o=="function")try{return String(o.call(u,g)??"")}catch{return""}return""}if(d){const l=(d.match(/\.\.\//g)||[]).length;let o=a;for(let f=0;f<l;f++){if(!o||!o.parent)return"";o=o.parent}if(g==="parent")return String(o.value??"");const h=x(o,g);return h!=null&&typeof h=="object"?"":String(h??"")}else{const l=x(a,g);if(l!=null&&typeof l!="object")return String(l);const o=u?.context?.polyglot;if(o?.translations){const h=a?.root?.lang||a?.lang||u?.context?.state?.lang||o.defaultLang||"en",f=o.translations[h];if(f){const C=x(f,g);if(C!=null&&typeof C!="object")return String(C);for(const w in f){const b=f[w];if(b&&typeof b=="object"&&!Array.isArray(b)){const S=x(b,g);if(S!=null&&typeof S!="object")return String(S)}}}const y=x(o.translations,g);if(y!=null&&typeof y!="object")return String(y)}return""}})}const T=e=>`${e.charAt(0).toLowerCase()}${e.slice(1)}`,v=(e,n)=>{const t=e.split(`
|
|
2
|
+
`);let s=-1,c=-1,m=-1,a=-1;const u=new RegExp(`\\b${n}\\b\\s*:\\s*`);let p=0,d=!1;for(let r=0;r<t.length;r++)if(u.test(t[r])&&!d){if(d=!0,s=r+1,m=t[r].indexOf(n)+1,t[r].includes("{}")){c=s,a=t[r].indexOf("{}")+3;break}const i=t[r].slice(m+n.length);if(i.includes("{")||i.includes("["))p=1;else{c=r+1,a=t[r].length+1;break}}else if(d&&(p+=(t[r].match(/{/g)||[]).length,p+=(t[r].match(/\[/g)||[]).length,p-=(t[r].match(/}/g)||[]).length,p-=(t[r].match(/]/g)||[]).length,p===0)){c=r+1,a=t[r].lastIndexOf("}")!==-1?t[r].lastIndexOf("}")+2:t[r].length+1;break}return{startColumn:m,endColumn:a,startLineNumber:s,endLineNumber:c}},U=/\\([0-7]{1,3})/g,V=e=>e.replace(U,(n,t)=>String.fromCharCode(parseInt(t,8))),D=e=>e.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),K=e=>e.replace(/\/\/\/\/\/n/g,`
|
|
3
|
+
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),P=/[^a-zA-Z0-9\s]/g,q=e=>e.replace(P,n=>"%"+n.charCodeAt(0).toString(16).toUpperCase()),z=e=>e.replace(/%[0-9A-Fa-f]{2}/g,n=>String.fromCharCode(parseInt(n.slice(1),16)));
|
package/dist/esm/keys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const a=new Set(["attr","style","text","html","content","data","classlist","state","scope","root","deps","extend","extends","$router","routes","children","childExtend","childExtends","childExtendRecursive","childExtendsRecursive","props","if","define","__name","__ref","__hash","__text","key","tag","query","parent","node","variables","on","fetch","component","context","preventContentUpdate","preventContentRecreate"]),s=new Set(["attr","style","text","html","content","data","class","state","scope","children","props","if","key","tag","query","on","context"]),p=["ref","parent","__element","__depends","__ref","__children","root"],o=new Set(["update","parse","clean","create","destroy","add","toggle","remove","apply","set","reset","replace","quietReplace","quietUpdate","applyReplace","applyFunction","keys","values","ref","rootUpdate","parentUpdate","parent","__element","__depends","__ref","__children","root","setByPath","setPathCollection","removeByPath","removePathCollection","getByPath"]),n=new Set(["update","__element"]),t=new Set(["set","reset","update","remove","updateContent","removeContent","lookup","lookdown","lookdownAll","getRef","getPath","setNodeStyles","spotByPath","keys","parse","setProps","parseDeep","variables","if","log","verbose","warn","error","call","nextElement","previousElement","getRootState","getRoot","getRootData","getRootContext","getContext","getQuery","getDB","getChildren","preventContentUpdate","preventContentRecreate"]),d=e=>t.has(e),r=new Set(["log","warn","error","verbose"]),l=e=>t.has(e)&&!r.has(e),c=new Set(["node","context","extends","__element","__ref",...t,...o,...n]),_=new Set(["init","beforeClassAssign","render","renderRouter","attachNode","stateInit","stateCreated","beforeStateUpdate","stateUpdate","beforeUpdate","done","create","complete","frame","update","fetchError","fetchComplete"]);export{_ as DOMQL_EVENTS,a as DOMQ_PROPERTIES,r as ELEMENT_METHOD_OVERRIDE_POINTS,t as METHODS,c as METHODS_EXL,s as PARSED_DOMQ_PROPERTIES,n as PROPS_METHODS,o as STATE_METHODS,p as STATE_PROPERTIES,d as isBuiltinElementMethod,l as isProtectedElementMethod};
|
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
|
|
1
|
+
import{triggerEventOn as x}from"./triggerEvent.js";import{DOMQ_PROPERTIES as R,METHODS as $,PARSED_DOMQ_PROPERTIES as k}from"./keys.js";import{isDefined as E,isFunction as p,isObject as P,isObjectLike as y}from"./types.js";import{deepClone as A,isFailedRevival as b}from"./object.js";import{isProduction as C}from"./env.js";import{removeValueFromArray as j}from"./array.js";import{OPTIONS as Q}from"./cache.js";const a="production";function X(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 q(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 tt(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 et(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 N(e={}){const t=this;if(t.node?.style){for(const n in e){const o=e[n],r=t[n];if(P(o)&&r)N.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 nt(e){const t=this;if(x("beforeRemove",t,e)===!1)return t;p(t.node.remove)?t.node.remove():C()||(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)),x("remove",t,e)}function ot(e){return this[e]}function rt(e,t){const n=this;if(e)return n.update(e,t),n}function st(e){return e?this.__ref&&this.__ref[e]:this.__ref}function it(){const e=this.getRef("__children");return Array.isArray(e)?e.map(t=>this[t]):[]}function ct(){return this.getRef().path}let _=null;const lt=e=>{_=e||null},ft=(e,t)=>{e&&t&&_===e&&(_=t)},v=()=>_||null;function ut(e){let t=null;const n=o=>o.__element&&o.root?.isRootState;if(!this)t=v();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=v()),e?t?.[e]:t}function at(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 ht(e){return this.getRoot("data")&&Object.keys(this.getRoot("data")).length>0&&e?this.getRoot("data")[e]:this.getRoot("data")}function pt(e){const t=this.getRoot()?.context;return e?t[e]:t}function dt(e){const t=this.context;return e?t[e]:t}const _t=(e,t,n,o)=>Object.defineProperty(e,t,{get:n,set:o});function D(){const e=this,t=[];for(const n in e)!Object.prototype.hasOwnProperty.call(e,n)||R.has(n)&&!k.has(n)||t.push(n);return t}function T(e=[]){const t=this,n={},o=D.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 E(l)&&Object.prototype.hasOwnProperty.call(t,c)&&(n[c]=l)}return n}function S(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=>y(c)?S.call(c,e,t):c):y(i)&&(o[s]=S.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 gt(...e){(a==="test"||a==="development")&&console.log(...e)}function mt(...e){(a==="test"||a==="development")&&console.warn(...e)}function w(...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 xt(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function yt(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 vt(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,A(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 St(e,...t){const n=this.context,o=n.utils?.[e]||n.functions?.[e]||n.methods?.[e]||n.snippets?.[e];if(o&&!b(o))try{const r=o.call(this,...t);return r&&typeof r.then=="function"&&r.catch(s=>{w.call(this,s)}),r}catch(r){if(w.call(this,r),n?.strictMode)throw r}}async function wt(){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 import("@symbo.ls/fetch");await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await import("@symbo.ls/fetch");await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=import("@symbo.ls/fetch").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 import("@symbo.ls/fetch");await r(o,e.context)}return o}function Ot(e){const t=this,n=e||Q.useStateQuery||t.context?.useStateQuery;if(!n)return null;const o={};if(m(t,o),n===!0)return o;const r=z[n];return r?r(o):o}const m=(e,t)=>{const n=e.__ref;if(!n)return;const o=n.__state;o&&typeof o=="string"&&I(t,o);const r=n.__children;if(r)for(let c=0;c<r.length;c++){const l=e[r[c]];l&&l.__ref&&m(l,t)}const s=n.contentElementKey||"content",i=e[s];i&&i.__ref&&m(i,t)},I=(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])}},O=(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
|
${O(i,t+1)}
|
|
4
4
|
${n}}`).join(`
|
|
5
5
|
`):""},L=e=>`{
|
|
6
6
|
${O(e,1)}
|
|
7
|
-
}`,M=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},J=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,
|
|
7
|
+
}`,M=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},J=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,g)=>{r.add(h),g&&o.push(`LEFT JOIN ${h} ON ${h}.${g}_id = ${g}.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}`},B=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},z={graphql:L,"json-api":M,odata:J,sql:V,paths:B};function
|
|
10
|
+
FROM ${c}${f}`},B=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},z={graphql:L,"json-api":M,odata:J,sql:V,paths:B};function Rt(e,t){return!!($.has(e)||t?.context?.methods?.[e])}export{St as call,_t as defineSetter,w as error,ot as get,it as getChildren,dt as getContext,wt as getDB,ct as getPath,Ot as getQuery,st as getRef,at as getRoot,pt as getRootContext,ht as getRootData,ut as getRootState,Rt as isMethod,D as keys,gt as log,tt as lookdown,et as lookdownAll,q as lookup,xt as nextElement,T as parse,S as parseDeep,yt as previousElement,ft as promoteActiveRootState,nt as remove,lt as setActiveRootState,N as setNodeStyles,rt as setProps,X as spotByPath,vt as variables,F as verbose,mt as warn};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as
|
|
1
|
+
import{isObject as l,isString as u}from"./types.js";import{isProtectedElementMethod as d}from"./keys.js";import{isLoudDevRuntime as O}from"./env.js";const w="system",B="https://smbls-kv.nika-980.workers.dev",E="https://api.symbols.app";function h(n){const t=String(n||"").trim();if(!t)return{owner:w,key:"",full:""};let o=null,e=t;if(t.includes("/")){const r=t.indexOf("/");o=t.slice(0,r),e=t.slice(r+1)}e=e.replace(/\.symbo\.ls$/iu,""),o||(o=w);const s=e?`${o}/${e}`:"";return{owner:o,key:e,full:s}}const b=(n,t,o,e)=>{for(const s in t){const r=e?`${e}/${s}`:s;o&&o.has(r)||(s in n?l(n[s])&&l(t[s])&&b(n[s],t[s],o,r):n[s]=t[s])}},g=(n,t,o)=>{if(!l(n)||!t.size)return n;const e=`${o}/`;let s=!1;for(const a of t)if(a.startsWith(e)){s=!0;break}if(!s)return n;const r={};for(const a in n){if(!Object.prototype.hasOwnProperty.call(n,a))continue;const i=`${o}/${a}`;t.has(i)||(r[a]=g(n[a],t,i))}return r},F=new Set,U=new Set(["components","pages","functions","snippets","methods"]),k=(n,t)=>t===""&&U.has(n),$=["fontFamily","fontfamily","font_family","FONT_FAMILY"],P=n=>{const t=new Map;if(!l(n))return t;for(const o of $){const e=n[o];if(l(e))for(const s in e)!l(e[s])||!e[s].isDefault||(t.has(o)||t.set(o,new Set),t.get(o).add(s))}return t},M=(n,t)=>{for(const o of $){const e=n[o];if(!l(e))continue;const s=t.get(o);let r=null;for(const a in e){const i=e[a];if(!l(i)||!i.isDefault||s&&s.has(a))continue;const c={...i};delete c.isDefault,r||(r={...e}),r[a]=c}r&&(n[o]=r)}},D=n=>n.replace(/\.js$/iu,""),L=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const o of n){if(!u(o))continue;const e=o.split("/").map(s=>D(s.trim())).filter(Boolean).join("/");e&&t.add(e)}return t},x=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),A=n=>l(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),S=n=>n.library!==void 0?n.library:n.key??n.name,m=new Set,V=()=>{m.clear()},T=(n,t)=>{const o=t.filter(e=>!m.has(e));if(o.length){for(const e of o)m.add(e);O()&&console.warn(`[smbls] shared library "${n}" ships ${o.map(e=>`methods.${e}`).join(", ")} \u2014 named like a built-in element method. Refused: the built-in wins; a library cannot replace an element method on the consuming app. If the app wants this version, declare it in the app's OWN methods.`)}},C=(n,t,o)=>{let e=null;for(const s in n)if(d(s)&&(t.has(`methods/${s}`)||o.push(s),!e)){e={};for(const r in n)d(r)||(e[r]=n[r])}return e||n},N=(n,t,o,e="library")=>{const s=L(t.sharedLibIgnore);t.sharePages===!1&&s.add("pages");const r=s.size?new Set([...o,...s]):o,a=[];for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)&&!(i==="sharePages"||i==="sharedLibIgnore")&&i!=="app"&&!r.has(i)){if(l(t[i])&&l(n[i])){if(i==="designSystem")b(n[i],t[i],r,i);else for(const c in t[i])if(!r.has(`${i}/${c}`)){if(i==="methods"&&d(c)){c in n[i]||a.push(c);continue}c in n[i]?k(i,n[i][c])&&!k(i,t[i][c])&&(n[i][c]=t[i][c]):n[i][c]=t[i][c]}}else if(!(i in n)){const c=t[i],f=i==="methods"&&c&&typeof c=="object"?C(c,r,a):c;n[i]=g(f,r,i)}}a.length&&T(e,a)},G=(n,t,o)=>{if(n!==t){const e=S(n);if(u(e)&&e)return e;if(n.key||n.name)return n.key||n.name}return t&&(t.key||t.name)||`sharedLibraries[${o}]`},q=(n,t)=>{if(!t||!t.length)return;const o=P(n.designSystem);for(let e=0;e<t.length;e++){const s=t[e];let r=s,a=F;A(r)&&(a=L(r.ignoreList),r=r.library),l(r)&&N(n,r,a,G(s,r,e))}o.size&&M(n.designSystem,o)};async function W(n,t={}){if((t.provider||"kv")==="api")return _(n,t);const e=await z(n,t);return e||_(n,t)}async function z(n,t={}){const o=t.kvBaseUrl||B,e=t.env||"production",s=`${o}/kv/${encodeURIComponent(n)}?env=${e}`;try{const r=await fetch(s,{method:"GET"});return r.ok&&(await r.json())?.value||null}catch{return null}}async function _(n,t={}){const o=t.apiBaseUrl||E,{key:e}=h(n);try{const s=`${o}/core/projects/libraries/available?search=${encodeURIComponent(e)}&limit=10`,r=await fetch(s,{method:"GET"});if(!r.ok)return null;const a=await r.json(),c=(a?.items||a?.data||(Array.isArray(a)?a:[])).find(j=>{const{key:R}=h(j?.key);return R.toLowerCase()===e.toLowerCase()});if(!c?.id&&!c?._id)return null;const f=c.id||c._id,I=`${o}/core/projects/${encodeURIComponent(f)}/data?branch=main`,p=await fetch(I,{method:"GET"});if(!p.ok)return null;const y=await p.json();return y?.data||y||null}catch{return null}}async function v(n,t={}){if(l(n))return n;if(u(n)){const{full:o}=h(n);if(!o)return null;try{const e=await W(o,t);return e||console.warn(`[smbls] Shared library "${o}" not found`),e}catch(e){return console.warn(`[smbls] Failed to fetch shared library "${o}":`,e.message),null}}return null}async function H(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async e=>{if(A(e)){const s=await v(S(e),t);return s?{library:s,ignoreList:e.ignoreList}:null}return v(e,t)}))).filter(Boolean)}export{V as __resetBuiltinMethodWarnings,b as deepDefaults,W as fetchLibraryData,A as isWrappedLibrary,q as mergeSharedLibraries,L as normalizeIgnoreList,h as normalizeLibraryKey,H as resolveSharedLibraries,x as sharedLibrary};
|
package/dist/esm/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const N=(
|
|
2
|
-
`);let
|
|
3
|
-
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),
|
|
1
|
+
const N=(t,r)=>{for(const e of r)if(t.includes(e))return!0;return!1},O=(t,r)=>{const e=new RegExp(`[${r.join("\\")}]`,"g");return t.replace(e,"")},w={2:/{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,3:/{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g},x=(t,r)=>r.split(".").reduce((e,s)=>e?.[s],t),A=(t,r)=>{if(!t||!t.__ref)return!0;let e=t;for(;e;){if(e.allowRuntimeTemplates===!0)return!0;const s=e.__ref&&e.__ref.__authoredTemplates;if(s&&s.has(r))return!0;e=e.parent}return!1};function R(t,r,e={}){const{bracketsLength:s=2}=e,f=s===3?"{{{":"{{";if(!t.includes(f)||!A(this,t))return t;const m=w[s],l=r||this.state||{},i=this;return t.replace(m,(u,d,n,a)=>{const p=n.trim();if(a){const c=i?.context,o=c?.functions?.[a]||c?.utils?.[a]||c?.methods?.[a]||c?.snippets?.[a]||i?.[a];if(o&&typeof o=="function")try{return String(o.call(i,p)??"")}catch{return""}return""}if(d){const c=(d.match(/\.\.\//g)||[]).length;let o=l;for(let g=0;g<c;g++){if(!o||!o.parent)return"";o=o.parent}if(p==="parent")return String(o.value??"");const h=x(o,p);return h!=null&&typeof h=="object"?"":String(h??"")}else{const c=x(l,p);if(c!=null&&typeof c!="object")return String(c);const o=i?.context?.polyglot;if(o?.translations){const h=l?.root?.lang||l?.lang||i?.context?.state?.lang||o.defaultLang||"en",g=o.translations[h];if(g){const C=x(g,p);if(C!=null&&typeof C!="object")return String(C);for(const _ in g){const b=g[_];if(b&&typeof b=="object"&&!Array.isArray(b)){const S=x(b,p);if(S!=null&&typeof S!="object")return String(S)}}}const y=x(o.translations,p);if(y!=null&&typeof y!="object")return String(y)}return""}})}const I=t=>`${t.charAt(0).toLowerCase()}${t.slice(1)}`,k=(t,r)=>{const e=t.split(`
|
|
2
|
+
`);let s=-1,f=-1,m=-1,l=-1;const i=new RegExp(`\\b${r}\\b\\s*:\\s*`);let u=0,d=!1;for(let n=0;n<e.length;n++)if(i.test(e[n])&&!d){if(d=!0,s=n+1,m=e[n].indexOf(r)+1,e[n].includes("{}")){f=s,l=e[n].indexOf("{}")+3;break}const a=e[n].slice(m+r.length);if(a.includes("{")||a.includes("["))u=1;else{f=n+1,l=e[n].length+1;break}}else if(d&&(u+=(e[n].match(/{/g)||[]).length,u+=(e[n].match(/\[/g)||[]).length,u-=(e[n].match(/}/g)||[]).length,u-=(e[n].match(/]/g)||[]).length,u===0)){f=n+1,l=e[n].lastIndexOf("}")!==-1?e[n].lastIndexOf("}")+2:e[n].length+1;break}return{startColumn:m,endColumn:l,startLineNumber:s,endLineNumber:f}},L=/\\([0-7]{1,3})/g,E=t=>t.replace(L,(r,e)=>String.fromCharCode(parseInt(e,8))),$=t=>t.replace(/\n/g,"/////n").replace(/`/g,"/////tilde").replace(/\$/g,"/////dlrsgn"),F=t=>t.replace(/\/\/\/\/\/n/g,`
|
|
3
|
+
`).replace(/\/\/\/\/\/tilde/g,"`").replace(/\/\/\/\/\/dlrsgn/g,"$"),j=/[^a-zA-Z0-9\s]/g,T=t=>t.replace(j,r=>"%"+r.charCodeAt(0).toString(16).toUpperCase()),v=t=>t.replace(/%[0-9A-Fa-f]{2}/g,r=>String.fromCharCode(parseInt(r.slice(1),16)));export{v as customDecodeURIComponent,T as customEncodeURIComponent,F as decodeNewlines,$ as encodeNewlines,k as findKeyPosition,I as lowercaseFirstLetter,R as replaceLiteralsWithObjectFields,E as replaceOctalEscapeSequences,N as stringIncludesAny,O as trimStringFromSymbols};
|
package/keys.js
CHANGED
|
@@ -148,6 +148,43 @@ export const METHODS = new Set([
|
|
|
148
148
|
'preventContentRecreate'
|
|
149
149
|
])
|
|
150
150
|
|
|
151
|
+
// Is `name` a built-in element method (or a reserved element key)? Every method
|
|
152
|
+
// on @symbo.ls/element's prototype is in METHODS — locked by
|
|
153
|
+
// element/__tests__/libraryMethodsCannotShadowBuiltins.test.js.
|
|
154
|
+
export const isBuiltinElementMethod = (name) => METHODS.has(name)
|
|
155
|
+
|
|
156
|
+
// The built-in element methods a SHARED LIBRARY may replace — the OVERRIDE
|
|
157
|
+
// POINTS (FW-LIBRARY-METHODS-CANNOT-SHADOW-BUILTIN-ELEMENT-METHODS-1). They are
|
|
158
|
+
// observability hooks, not element semantics: the element's own tree, state
|
|
159
|
+
// and rendering never depend on what they do, so a library's version cannot
|
|
160
|
+
// break the element the way a stale getRoot / getRootState copy did — and
|
|
161
|
+
// apps link libraries precisely to route these outputs. Every other built-in
|
|
162
|
+
// is protected: a library copy is refused, the built-in wins. The app's OWN
|
|
163
|
+
// methods win over both, as for any method.
|
|
164
|
+
export const ELEMENT_METHOD_OVERRIDE_POINTS = new Set([
|
|
165
|
+
// Message logging. The built-in is a debug dump — element `log(...keys)`
|
|
166
|
+
// prints `{ key: el[key] }`; a library's `log(...params)` prints its
|
|
167
|
+
// messages, which is what its own methods call it for.
|
|
168
|
+
'log',
|
|
169
|
+
// Warning channel. The built-in prints only in test/development; a library
|
|
170
|
+
// routes warnings in every environment (console, telemetry) and continues.
|
|
171
|
+
'warn',
|
|
172
|
+
// Error channel. The built-in THROWS in test/development and is silent in
|
|
173
|
+
// production; a library reports and continues (`return this.error('…')` is
|
|
174
|
+
// an early exit that must not become an exception), with its own hooks
|
|
175
|
+
// (`onError`, `verbose`, `debugger` options).
|
|
176
|
+
'error',
|
|
177
|
+
// Debug inspector for an element — a development aid a library may style
|
|
178
|
+
// or redirect.
|
|
179
|
+
'verbose'
|
|
180
|
+
])
|
|
181
|
+
|
|
182
|
+
// A built-in element method that a library can NOT replace: METHODS minus the
|
|
183
|
+
// override points. The single test the shared-library merge and the element's
|
|
184
|
+
// fold / `el.call` paths use.
|
|
185
|
+
export const isProtectedElementMethod = (name) =>
|
|
186
|
+
METHODS.has(name) && !ELEMENT_METHOD_OVERRIDE_POINTS.has(name)
|
|
187
|
+
|
|
151
188
|
export const METHODS_EXL = new Set([
|
|
152
189
|
'node', 'context', 'extends', '__element', '__ref',
|
|
153
190
|
...METHODS,
|
package/methods.js
CHANGED
|
@@ -214,6 +214,25 @@ export const setActiveRootState = (state) => {
|
|
|
214
214
|
_activeRootState = state || null
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
/**
|
|
218
|
+
* `prepareContext` registers the PREPARED root state — a plain object — before
|
|
219
|
+
* the app root element exists. The root element then builds its OWN reactive
|
|
220
|
+
* store from that object (@symbo.ls/element createElementState), so the
|
|
221
|
+
* registered object is only a boot-time copy: it names no element, never sees
|
|
222
|
+
* a write and has no store methods. Every `getRootState()` fallback read went
|
|
223
|
+
* stale, and `getRoot()`'s fallback (`getRootState()?.__element`) could never
|
|
224
|
+
* resolve the app for an element whose `__ref` was cleared by `remove()`
|
|
225
|
+
* (FW-ROOT-STATE-REGISTERED-AS-A-DETACHED-PLAIN-COPY-1).
|
|
226
|
+
*
|
|
227
|
+
* @symbo.ls/element calls this when it builds a store from `source`: if the
|
|
228
|
+
* registry holds exactly `source`, it now holds the live `store`. Gated on
|
|
229
|
+
* identity, so an unrelated element tree created later can never take the
|
|
230
|
+
* registry over.
|
|
231
|
+
*/
|
|
232
|
+
export const promoteActiveRootState = (source, store) => {
|
|
233
|
+
if (source && store && _activeRootState === source) _activeRootState = store
|
|
234
|
+
}
|
|
235
|
+
|
|
217
236
|
const readFallbackState = () => {
|
|
218
237
|
// The framework-managed registry (set by prepareContext during
|
|
219
238
|
// create(...)) is the single source of truth for the active root
|
package/package.json
CHANGED
package/sharedLibraries.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { isObject, isString } from './types.js'
|
|
4
|
+
import { isProtectedElementMethod } from './keys.js'
|
|
5
|
+
import { isLoudDevRuntime } from './env.js'
|
|
4
6
|
|
|
5
7
|
const DEFAULT_LIBRARY_OWNER = 'system'
|
|
6
8
|
|
|
@@ -271,7 +273,68 @@ export const isWrappedLibrary = (entry) =>
|
|
|
271
273
|
const wrappedLibraryRef = (entry) =>
|
|
272
274
|
entry.library !== undefined ? entry.library : (entry.key ?? entry.name)
|
|
273
275
|
|
|
274
|
-
|
|
276
|
+
/**
|
|
277
|
+
* A library's `methods` never replace a PROTECTED built-in element method
|
|
278
|
+
* (FW-LIBRARY-METHODS-CANNOT-SHADOW-BUILTIN-ELEMENT-METHODS-1).
|
|
279
|
+
*
|
|
280
|
+
* `@symbo.ls/element` layers `context.methods` over its built-in element methods
|
|
281
|
+
* (getContextProto) and `el.call(name)` reads `context.methods` first, so a
|
|
282
|
+
* library key named `getRoot` / `getRootState` / … used to replace the built-in
|
|
283
|
+
* on every element of the consuming app, silently — and kept replacing it after
|
|
284
|
+
* the framework fixed the built-in. Measured on a live app: a library's
|
|
285
|
+
* pre-FW-GETROOT `getRoot` copy answered undefined inside installed modules and
|
|
286
|
+
* every module popover was dead with no error.
|
|
287
|
+
*
|
|
288
|
+
* So the merge refuses such a key on both branches and the built-in wins —
|
|
289
|
+
* except for the OVERRIDE POINTS (keys.js ELEMENT_METHOD_OVERRIDE_POINTS: the
|
|
290
|
+
* logging hooks log / warn / error / verbose), which merge like any library
|
|
291
|
+
* method: a library's "log and continue" versions are what its consumers rely
|
|
292
|
+
* on, and no element semantics depend on them. The APP's OWN `methods` are
|
|
293
|
+
* untouched (they were in the bag before any library merged) and win over
|
|
294
|
+
* both. One dev warning per refused name for the page.
|
|
295
|
+
*/
|
|
296
|
+
const _warnedBuiltinMethods = new Set()
|
|
297
|
+
|
|
298
|
+
// Test-only: forget which names already warned.
|
|
299
|
+
export const __resetBuiltinMethodWarnings = () => {
|
|
300
|
+
_warnedBuiltinMethods.clear()
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const warnRefusedBuiltinMethods = (label, names) => {
|
|
304
|
+
const fresh = names.filter((n) => !_warnedBuiltinMethods.has(n))
|
|
305
|
+
if (!fresh.length) return
|
|
306
|
+
for (const n of fresh) _warnedBuiltinMethods.add(n)
|
|
307
|
+
if (!isLoudDevRuntime()) return
|
|
308
|
+
console.warn(
|
|
309
|
+
`[smbls] shared library "${label}" ships ${fresh.map((n) => `methods.${n}`).join(', ')} — ` +
|
|
310
|
+
`named like a built-in element method. Refused: the built-in wins; a library cannot ` +
|
|
311
|
+
`replace an element method on the consuming app. If the app wants this version, ` +
|
|
312
|
+
`declare it in the app's OWN methods.`
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// The library's `methods` bag without protected built-in names, for the
|
|
317
|
+
// wholesale-copy branch. Same reference when there is nothing to drop (the
|
|
318
|
+
// common case — no allocation, exactly as before); otherwise a copy, because
|
|
319
|
+
// the library's own bag is shared by every consumer and is never edited.
|
|
320
|
+
// A name the consumer ignores (`methods/<name>` in skip) is dropped by
|
|
321
|
+
// copyWithNestedIgnores anyway and is not reported as refused.
|
|
322
|
+
const withoutProtectedMethods = (bag, skip, refused) => {
|
|
323
|
+
let copy = null
|
|
324
|
+
for (const k in bag) {
|
|
325
|
+
if (!isProtectedElementMethod(k)) continue
|
|
326
|
+
if (!skip.has(`methods/${k}`)) refused.push(k)
|
|
327
|
+
if (!copy) {
|
|
328
|
+
copy = {}
|
|
329
|
+
for (const j in bag) {
|
|
330
|
+
if (!isProtectedElementMethod(j)) copy[j] = bag[j]
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return copy || bag
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const mergeOneLibrary = (context, sharedLib, ignore, label = 'library') => {
|
|
275
338
|
// A library can declare parts of itself private via `sharedLibIgnore` on
|
|
276
339
|
// its own context — same path grammar as the consumer-side `ignoreList`
|
|
277
340
|
// (top-level keys or nested 'components/Header'). A library serving its
|
|
@@ -285,6 +348,7 @@ const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
|
285
348
|
const skip = libIgnore.size
|
|
286
349
|
? new Set([...ignore, ...libIgnore])
|
|
287
350
|
: ignore
|
|
351
|
+
const refusedMethods = []
|
|
288
352
|
for (const key in sharedLib) {
|
|
289
353
|
if (!Object.prototype.hasOwnProperty.call(sharedLib, key)) continue
|
|
290
354
|
// merge directives, not library content
|
|
@@ -307,6 +371,14 @@ const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
|
307
371
|
} else {
|
|
308
372
|
for (const k in sharedLib[key]) {
|
|
309
373
|
if (skip.has(`${key}/${k}`)) continue // nested skip: 'components/Header'
|
|
374
|
+
if (key === 'methods' && isProtectedElementMethod(k)) {
|
|
375
|
+
// The built-in wins. An app-own key of that name is the app's
|
|
376
|
+
// declared override and stays — nothing to report for it. The
|
|
377
|
+
// override points (log / warn / error / verbose) are not protected
|
|
378
|
+
// and fall through to the normal add-missing merge below.
|
|
379
|
+
if (!(k in context[key])) refusedMethods.push(k)
|
|
380
|
+
continue
|
|
381
|
+
}
|
|
310
382
|
if (!(k in context[key])) {
|
|
311
383
|
context[key][k] = sharedLib[key][k]
|
|
312
384
|
} else if (isStubPhantom(key, context[key][k]) && !isStubPhantom(key, sharedLib[key][k])) {
|
|
@@ -318,9 +390,28 @@ const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
|
318
390
|
}
|
|
319
391
|
}
|
|
320
392
|
} else if (!(key in context)) {
|
|
321
|
-
|
|
393
|
+
// Any object bag, not only a plain one: a native-ESM module namespace
|
|
394
|
+
// (`import * as methods` outside a bundler) has a null prototype and
|
|
395
|
+
// fails isObject, yet lands here and becomes `context.methods` as is.
|
|
396
|
+
const bag = sharedLib[key]
|
|
397
|
+
const value = key === 'methods' && bag && typeof bag === 'object'
|
|
398
|
+
? withoutProtectedMethods(bag, skip, refusedMethods)
|
|
399
|
+
: bag
|
|
400
|
+
context[key] = copyWithNestedIgnores(value, skip, key)
|
|
322
401
|
}
|
|
323
402
|
}
|
|
403
|
+
if (refusedMethods.length) warnRefusedBuiltinMethods(label, refusedMethods)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// A readable name for a library in the refusal warning: the wrapped entry's
|
|
407
|
+
// identifier, else the library context's own key/name, else its position.
|
|
408
|
+
const libraryLabel = (entry, lib, index) => {
|
|
409
|
+
if (entry !== lib) {
|
|
410
|
+
const ref = wrappedLibraryRef(entry)
|
|
411
|
+
if (isString(ref) && ref) return ref
|
|
412
|
+
if (entry.key || entry.name) return entry.key || entry.name
|
|
413
|
+
}
|
|
414
|
+
return (lib && (lib.key || lib.name)) || `sharedLibraries[${index}]`
|
|
324
415
|
}
|
|
325
416
|
|
|
326
417
|
/**
|
|
@@ -345,14 +436,15 @@ export const mergeSharedLibraries = (context, libraries) => {
|
|
|
345
436
|
// consumer's own bags and the two can no longer be told apart.
|
|
346
437
|
const ownDefaultFonts = defaultFontClaims(context.designSystem)
|
|
347
438
|
for (let i = 0; i < libraries.length; i++) {
|
|
348
|
-
|
|
439
|
+
const entry = libraries[i]
|
|
440
|
+
let sharedLib = entry
|
|
349
441
|
let ignore = EMPTY_IGNORE
|
|
350
442
|
if (isWrappedLibrary(sharedLib)) {
|
|
351
443
|
ignore = normalizeIgnoreList(sharedLib.ignoreList)
|
|
352
444
|
sharedLib = sharedLib.library
|
|
353
445
|
}
|
|
354
446
|
if (!isObject(sharedLib)) continue
|
|
355
|
-
mergeOneLibrary(context, sharedLib, ignore)
|
|
447
|
+
mergeOneLibrary(context, sharedLib, ignore, libraryLabel(entry, sharedLib, i))
|
|
356
448
|
}
|
|
357
449
|
if (ownDefaultFonts.size) yieldLibraryDefaultFonts(context.designSystem, ownDefaultFonts)
|
|
358
450
|
}
|
package/string.js
CHANGED
|
@@ -35,10 +35,53 @@ const getNestedValue = (obj, path) => {
|
|
|
35
35
|
}, obj)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Is this exact string a template the AUTHOR wrote?
|
|
40
|
+
*
|
|
41
|
+
* FW-ELEMENT-TEMPLATES-RESOLVED-IN-RUNTIME-TEXT-FUNCTION-INJECTION-1.
|
|
42
|
+
* A `{{ key | fn }}` template invokes a project function, so resolving one
|
|
43
|
+
* inside a string that CAME FROM DATA turns content into code: a customer
|
|
44
|
+
* typing `{{ x | nkTheme }}` into a chat box flipped the theme, and
|
|
45
|
+
* `nkToast('info', 'literal test {{ demoShort | polyglot }} end')` rendered
|
|
46
|
+
* the translation. Every function on `context.functions` was reachable from
|
|
47
|
+
* user text, an AI reply or an API response.
|
|
48
|
+
*
|
|
49
|
+
* The contract: a template is an author-time literal. `create()` records
|
|
50
|
+
* every `{{ }}` string a definition declares (`__ref.__authoredTemplates`,
|
|
51
|
+
* see registerEffects), and only those strings resolve. A factory may
|
|
52
|
+
* FORWARD an authored template — the framework `Input` atom does exactly
|
|
53
|
+
* that with `attr.placeholder: el => el.placeholder` — but it may never
|
|
54
|
+
* introduce one. The parent chain counts, so a template declared on an
|
|
55
|
+
* ancestor and forwarded down still resolves; every entry in every set is a
|
|
56
|
+
* source literal, so no state-derived string is ever in one.
|
|
57
|
+
*
|
|
58
|
+
* `allowRuntimeTemplates: true` on an element is the explicit opt-out, for
|
|
59
|
+
* the rare surface that really does build templates at runtime. It re-opens
|
|
60
|
+
* function invocation from that element's content — never set it on an
|
|
61
|
+
* element that renders text a user or a model produced.
|
|
62
|
+
*
|
|
63
|
+
* This reads `this` by duck-typing (`__ref`, `parent`), exactly as the state
|
|
64
|
+
* and polyglot lookups below already do — `utils` never imports `element`.
|
|
65
|
+
* A caller with no `__ref` is not an element (a bare util call, a test) and
|
|
66
|
+
* keeps the old unconditional behaviour.
|
|
67
|
+
*/
|
|
68
|
+
const isAuthoredTemplate = (element, str) => {
|
|
69
|
+
if (!element || !element.__ref) return true
|
|
70
|
+
let el = element
|
|
71
|
+
while (el) {
|
|
72
|
+
if (el.allowRuntimeTemplates === true) return true
|
|
73
|
+
const authored = el.__ref && el.__ref.__authoredTemplates
|
|
74
|
+
if (authored && authored.has(str)) return true
|
|
75
|
+
el = el.parent
|
|
76
|
+
}
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
|
|
38
80
|
export function replaceLiteralsWithObjectFields (str, state, options = {}) {
|
|
39
81
|
const { bracketsLength = 2 } = options
|
|
40
82
|
const bracketPattern = bracketsLength === 3 ? '{{{' : '{{'
|
|
41
83
|
if (!str.includes(bracketPattern)) return str
|
|
84
|
+
if (!isAuthoredTemplate(this, str)) return str
|
|
42
85
|
|
|
43
86
|
const reg = brackRegex[bracketsLength]
|
|
44
87
|
const obj = state || this.state || {}
|