@symbo.ls/sync 3.14.599 → 3.14.700
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/CHANGELOG.md +8 -0
- package/applier.js +56 -0
- package/dist/cjs/applier.js +1 -1
- package/dist/cjs/handlers.js +1 -1
- package/dist/esm/applier.js +1 -1
- package/dist/esm/handlers.js +1 -1
- package/handlers.js +33 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/applier.js
CHANGED
|
@@ -69,3 +69,59 @@ export const applyOpsToCtx = (ctx, changes) => {
|
|
|
69
69
|
}
|
|
70
70
|
return topLevelChanged
|
|
71
71
|
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Design-system re-init source for HMR/livesync.
|
|
75
|
+
*
|
|
76
|
+
* `ctx.designSystem` is scratch's PROCESSED config, mutated in place at
|
|
77
|
+
* boot — feeding it back into `init()` (as the handlers previously did) is
|
|
78
|
+
* a double-processing hazard: processed color entries re-enter the token
|
|
79
|
+
* transformers and the emitted CSS vars can lose their alpha channel
|
|
80
|
+
* (captured live: `--color-transparent` rgba(0,0,0,0) → rgba(0,0,0,1),
|
|
81
|
+
* i.e. every `background: 'transparent'` element painted solid black
|
|
82
|
+
* until a manual reload).
|
|
83
|
+
*
|
|
84
|
+
* This helper keeps a PRISTINE raw copy on the context (`__rawDesignSystem`):
|
|
85
|
+
* - seed it once from a raw source (server snapshot DS, or the project's
|
|
86
|
+
* authored DS before processing),
|
|
87
|
+
* - apply DS ops against the raw copy,
|
|
88
|
+
* - hand `init()` a deep clone of raw (never the live processed object),
|
|
89
|
+
* with the shared-library design systems deep-defaulted in — the same
|
|
90
|
+
* merge boot performs — so a re-init doesn't strip brand tokens.
|
|
91
|
+
*/
|
|
92
|
+
export const seedRawDesignSystem = (ctx, rawDs) => {
|
|
93
|
+
if (!ctx || !rawDs || typeof rawDs !== 'object') return
|
|
94
|
+
ctx.__rawDesignSystem = JSON.parse(JSON.stringify(rawDs))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const deepDefaultsInto = (target, source) => {
|
|
98
|
+
for (const k in source) {
|
|
99
|
+
if (FORBIDDEN_SEGMENTS.has(k)) continue
|
|
100
|
+
const sv = source[k]
|
|
101
|
+
const tv = target[k]
|
|
102
|
+
if (sv && typeof sv === 'object' && !Array.isArray(sv)) {
|
|
103
|
+
if (!tv || typeof tv !== 'object' || Array.isArray(tv)) {
|
|
104
|
+
if (!(k in target)) target[k] = JSON.parse(JSON.stringify(sv))
|
|
105
|
+
continue
|
|
106
|
+
}
|
|
107
|
+
deepDefaultsInto(tv, sv)
|
|
108
|
+
} else if (!(k in target)) {
|
|
109
|
+
target[k] = sv
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const buildReinitDesignSystem = (ctx, dsOps) => {
|
|
115
|
+
if (!ctx || !ctx.__rawDesignSystem) return null
|
|
116
|
+
if (Array.isArray(dsOps) && dsOps.length) {
|
|
117
|
+
const holder = { designSystem: ctx.__rawDesignSystem }
|
|
118
|
+
applyOpsToCtx(holder, dsOps)
|
|
119
|
+
}
|
|
120
|
+
const out = JSON.parse(JSON.stringify(ctx.__rawDesignSystem))
|
|
121
|
+
const libs = Array.isArray(ctx.sharedLibraries) ? ctx.sharedLibraries : []
|
|
122
|
+
for (const lib of libs) {
|
|
123
|
+
const libDs = lib && lib.designSystem
|
|
124
|
+
if (libDs && typeof libDs === 'object') deepDefaultsInto(out, libDs)
|
|
125
|
+
}
|
|
126
|
+
return out
|
|
127
|
+
}
|
package/dist/cjs/applier.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var o=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var c=(e,r)=>{for(var n in r)o(e,n,{get:r[n],enumerable:!0})},h=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of g(r))!_.call(e,t)&&t!==n&&o(e,t,{get:()=>r[t],enumerable:!(i=A(r,t))||i.enumerable});return e};var b=e=>h(o({},"__esModule",{value:!0}),e);var N={};c(N,{FORBIDDEN_SEGMENTS:()=>f,applyOpsToCtx:()=>d,buildReinitDesignSystem:()=>D,deletePath:()=>u,isSafePath:()=>a,seedRawDesignSystem:()=>m,setPath:()=>l});module.exports=b(N);const f=new Set(["__proto__","constructor","prototype"]),a=e=>{if(!Array.isArray(e))return!1;for(let r=0;r<e.length;r++)if(f.has(e[r]))return!1;return!0},u=(e,r)=>{!e||!a(r)||r.reduce((n,i,t,s)=>{if(n&&i in n){if(t!==s.length-1)return n[i];delete n[i]}},e)},l=(e,r,n,i=!1)=>{!e||!a(r)||r.reduce((t,s,S,p)=>{if(t){if(S!==p.length-1)return!t[s]&&i&&(t[s]={}),t[s];t[s]=n}},e)},d=(e,r)=>{const n=new Set;if(!Array.isArray(r))return n;for(const[i,t,s]of r)if(!(!Array.isArray(t)||!t.length))switch(n.add(t[0]),i){case"delete":u(e,t);break;case"update":case"set":l(e,t,s,!0);break;default:break}return n},m=(e,r)=>{!e||!r||typeof r!="object"||(e.__rawDesignSystem=JSON.parse(JSON.stringify(r)))},y=(e,r)=>{for(const n in r){if(f.has(n))continue;const i=r[n],t=e[n];if(i&&typeof i=="object"&&!Array.isArray(i)){if(!t||typeof t!="object"||Array.isArray(t)){n in e||(e[n]=JSON.parse(JSON.stringify(i)));continue}y(t,i)}else n in e||(e[n]=i)}},D=(e,r)=>{if(!e||!e.__rawDesignSystem)return null;if(Array.isArray(r)&&r.length){const t={designSystem:e.__rawDesignSystem};d(t,r)}const n=JSON.parse(JSON.stringify(e.__rawDesignSystem)),i=Array.isArray(e.sharedLibraries)?e.sharedLibraries:[];for(const t of i){const s=t&&t.designSystem;s&&typeof s=="object"&&y(n,s)}return n};
|
package/dist/cjs/handlers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var A=(t,i)=>{for(var s in i)h(t,s,{get:i[s],enumerable:!0})},S=(t,i,s,a)=>{if(i&&typeof i=="object"||typeof i=="function")for(let e of g(i))!u.call(t,e)&&e!==s&&h(t,e,{get:()=>i[e],enumerable:!(a=y(i,e))||a.enumerable});return t};var w=t=>S(h({},"__esModule",{value:!0}),t);var D={};A(D,{onOps:()=>b,onSnapshot:()=>O});module.exports=w(D);var m=require("smbls"),c=require("@symbo.ls/utils"),f=require("./applier.js");const O=(t,i,s)=>{let a=!1;return(e={})=>{let{data:n}=e;const{schema:l}=e;n&&(n=t.call("deepDestringifyFunctions",n,Array.isArray(n)?[]:{}),Object.entries(n).forEach(([o,r])=>{if(s[o]&&typeof s[o]=="object")if(o==="designSystem"){if((0,f.seedRawDesignSystem)(s,r),a){const p=(0,f.buildReinitDesignSystem)(s);p&&(0,m.init)(p)}}else(0,c.overwriteShallow)(s[o],r);else s[o]=r}),a=!0,l&&(s.schema=l))}},b=(t,i,s)=>(a={})=>{let{changes:e}=a;if(!e||!Array.isArray(e)||!e.length)return;e=t.call("deepDestringifyFunctions",e,Array.isArray(e)?[]:{});const n=e.filter(r=>Array.isArray(r)&&Array.isArray(r[1])&&r[1][0]==="designSystem"),l=n.length?e.filter(r=>!n.includes(r)):e,o=(0,f.applyOpsToCtx)(s,l);if(n.length&&o.add("designSystem"),o.has("state")&&i.update(s.state),["pages","components","snippets","functions","assets"].some(r=>o.has(r))){const{pathname:r,search:p,hash:d}=s.window.location;t.call("router",r+p+d,t.__ref.root,{},{scrollToTop:!1})}if(o.has("designSystem")){const r=(0,f.buildReinitDesignSystem)(s,n);(0,m.init)(r||s.designSystem)}};
|
package/dist/esm/applier.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const o=new Set(["__proto__","constructor","prototype"]),f=e=>{if(!Array.isArray(e))return!1;for(let r=0;r<e.length;r++)if(o.has(e[r]))return!1;return!0},l=(e,r)=>{!e||!f(r)||r.reduce((n,i,t,s)=>{if(n&&i in n){if(t!==s.length-1)return n[i];delete n[i]}},e)},d=(e,r,n,i=!1)=>{!e||!f(r)||r.reduce((t,s,y,u)=>{if(t){if(y!==u.length-1)return!t[s]&&i&&(t[s]={}),t[s];t[s]=n}},e)},S=(e,r)=>{const n=new Set;if(!Array.isArray(r))return n;for(const[i,t,s]of r)if(!(!Array.isArray(t)||!t.length))switch(n.add(t[0]),i){case"delete":l(e,t);break;case"update":case"set":d(e,t,s,!0);break;default:break}return n},p=(e,r)=>{!e||!r||typeof r!="object"||(e.__rawDesignSystem=JSON.parse(JSON.stringify(r)))},a=(e,r)=>{for(const n in r){if(o.has(n))continue;const i=r[n],t=e[n];if(i&&typeof i=="object"&&!Array.isArray(i)){if(!t||typeof t!="object"||Array.isArray(t)){n in e||(e[n]=JSON.parse(JSON.stringify(i)));continue}a(t,i)}else n in e||(e[n]=i)}},A=(e,r)=>{if(!e||!e.__rawDesignSystem)return null;if(Array.isArray(r)&&r.length){const t={designSystem:e.__rawDesignSystem};S(t,r)}const n=JSON.parse(JSON.stringify(e.__rawDesignSystem)),i=Array.isArray(e.sharedLibraries)?e.sharedLibraries:[];for(const t of i){const s=t&&t.designSystem;s&&typeof s=="object"&&a(n,s)}return n};export{o as FORBIDDEN_SEGMENTS,S as applyOpsToCtx,A as buildReinitDesignSystem,l as deletePath,f as isSafePath,p as seedRawDesignSystem,d as setPath};
|
package/dist/esm/handlers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{init as p}from"smbls";import{overwriteShallow as c}from"@symbo.ls/utils";import{applyOpsToCtx as h}from"./applier.js";const
|
|
1
|
+
import{init as p}from"smbls";import{overwriteShallow as c}from"@symbo.ls/utils";import{applyOpsToCtx as d,seedRawDesignSystem as y,buildReinitDesignSystem as h}from"./applier.js";const S=(n,l,e)=>{let o=!1;return(r={})=>{let{data:t}=r;const{schema:a}=r;t&&(t=n.call("deepDestringifyFunctions",t,Array.isArray(t)?[]:{}),Object.entries(t).forEach(([i,s])=>{if(e[i]&&typeof e[i]=="object")if(i==="designSystem"){if(y(e,s),o){const f=h(e);f&&p(f)}}else c(e[i],s);else e[i]=s}),o=!0,a&&(e.schema=a))}},w=(n,l,e)=>(o={})=>{let{changes:r}=o;if(!r||!Array.isArray(r)||!r.length)return;r=n.call("deepDestringifyFunctions",r,Array.isArray(r)?[]:{});const t=r.filter(s=>Array.isArray(s)&&Array.isArray(s[1])&&s[1][0]==="designSystem"),a=t.length?r.filter(s=>!t.includes(s)):r,i=d(e,a);if(t.length&&i.add("designSystem"),i.has("state")&&l.update(e.state),["pages","components","snippets","functions","assets"].some(s=>i.has(s))){const{pathname:s,search:f,hash:m}=e.window.location;n.call("router",s+f+m,n.__ref.root,{},{scrollToTop:!1})}if(i.has("designSystem")){const s=h(e,t);p(s||e.designSystem)}};export{w as onOps,S as onSnapshot};
|
package/handlers.js
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
import { init } from 'smbls'
|
|
7
7
|
import { overwriteShallow } from '@symbo.ls/utils'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
applyOpsToCtx,
|
|
10
|
+
seedRawDesignSystem,
|
|
11
|
+
buildReinitDesignSystem
|
|
12
|
+
} from './applier.js'
|
|
9
13
|
|
|
10
14
|
export const onSnapshot = (el, s, ctx) => {
|
|
11
15
|
// The FIRST snapshot the server pushes on connect is just the already-rendered
|
|
@@ -33,7 +37,15 @@ export const onSnapshot = (el, s, ctx) => {
|
|
|
33
37
|
Object.entries(data).forEach(([key, val]) => {
|
|
34
38
|
if (ctx[key] && typeof ctx[key] === 'object') {
|
|
35
39
|
if (key === 'designSystem') {
|
|
36
|
-
|
|
40
|
+
// Track the RAW server copy on every snapshot (the boot snapshot
|
|
41
|
+
// included) — it is the only clean re-init source. Never init from
|
|
42
|
+
// `ctx.designSystem`: that object is scratch's processed config
|
|
43
|
+
// and re-processing it corrupts emitted vars (transparent→black).
|
|
44
|
+
seedRawDesignSystem(ctx, val)
|
|
45
|
+
if (booted) {
|
|
46
|
+
const raw = buildReinitDesignSystem(ctx)
|
|
47
|
+
if (raw) init(raw)
|
|
48
|
+
}
|
|
37
49
|
} else {
|
|
38
50
|
overwriteShallow(ctx[key], val)
|
|
39
51
|
}
|
|
@@ -59,7 +71,19 @@ export const onOps =
|
|
|
59
71
|
Array.isArray(changes) ? [] : {}
|
|
60
72
|
)
|
|
61
73
|
|
|
62
|
-
|
|
74
|
+
// DS ops are split off BEFORE the ctx apply: they must land on the raw
|
|
75
|
+
// copy (buildReinitDesignSystem applies them there), never be spliced
|
|
76
|
+
// into the live processed config — a processed/raw hybrid fed back into
|
|
77
|
+
// init() is the double-processing hazard.
|
|
78
|
+
const dsOps = changes.filter(
|
|
79
|
+
(op) => Array.isArray(op) && Array.isArray(op[1]) && op[1][0] === 'designSystem'
|
|
80
|
+
)
|
|
81
|
+
const otherOps = dsOps.length
|
|
82
|
+
? changes.filter((op) => !dsOps.includes(op))
|
|
83
|
+
: changes
|
|
84
|
+
|
|
85
|
+
const changed = applyOpsToCtx(ctx, otherOps)
|
|
86
|
+
if (dsOps.length) changed.add('designSystem')
|
|
63
87
|
|
|
64
88
|
// State changes → re-run state. Editor-driven navigation now goes
|
|
65
89
|
// through explicit `el.router(route)` calls (or a dedicated `navigate`
|
|
@@ -90,6 +114,11 @@ export const onOps =
|
|
|
90
114
|
}
|
|
91
115
|
|
|
92
116
|
if (changed.has('designSystem')) {
|
|
93
|
-
init
|
|
117
|
+
// Re-init from the raw copy + shared-library defaults — see the
|
|
118
|
+
// seedRawDesignSystem note in onSnapshot. Fall back to the live
|
|
119
|
+
// config ONLY when no raw source was ever seeded (a client that
|
|
120
|
+
// never received a snapshot), matching the old behavior.
|
|
121
|
+
const raw = buildReinitDesignSystem(ctx, dsOps)
|
|
122
|
+
init(raw || ctx.designSystem)
|
|
94
123
|
}
|
|
95
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/sync",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.700",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@symbo.ls/router": "^3.14.599",
|
|
49
49
|
"@symbo.ls/utils": "^3.14.599",
|
|
50
|
-
"@symbo.ls/scratch": "^3.14.
|
|
50
|
+
"@symbo.ls/scratch": "^3.14.700",
|
|
51
51
|
"@symbo.ls/default-config": "^3.14.599",
|
|
52
52
|
"chalk": "^5.6.2",
|
|
53
53
|
"socket.io-client": "^4.8.3"
|