@symbo.ls/sync 2.29.55 → 2.29.57

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/index.js CHANGED
@@ -76,8 +76,10 @@ const applyOpsToCtx = (ctx, changes) => {
76
76
  };
77
77
  const fetchServiceToken = async () => {
78
78
  try {
79
- const urlBase = isLocalhost ? "http://localhost:8080" : "https://api.symbols.app";
80
- const res = await import_utils.window.fetch(`${urlBase}/service-token`, { method: "GET" });
79
+ const urlBase = "https://api.symbols.app";
80
+ const res = await import_utils.window.fetch(`${urlBase}/service-token`, {
81
+ method: "GET"
82
+ });
81
83
  let txt;
82
84
  try {
83
85
  const json = await res.clone().json();
@@ -94,8 +96,9 @@ const fetchServiceToken = async () => {
94
96
  };
95
97
  const onSnapshot = (el, s, ctx) => (payload = {}) => {
96
98
  var _a;
97
- const { data, schema } = payload;
99
+ let { data, schema } = payload;
98
100
  if (!data) return;
101
+ data = el.call("deepDestringify", data, Array.isArray(data) ? [] : {});
99
102
  Object.entries(data).forEach(([key, val]) => {
100
103
  if (ctx[key] && typeof ctx[key] === "object") {
101
104
  (0, import_utils.overwriteShallow)(ctx[key], val);
@@ -108,23 +111,28 @@ const onSnapshot = (el, s, ctx) => (payload = {}) => {
108
111
  (((_a = ctx.utils) == null ? void 0 : _a.router) || import_router.router)(pathname + search + hash, el, {});
109
112
  };
110
113
  const onOps = (el, s, ctx) => (payload = {}) => {
111
- var _a, _b, _c;
112
- console.log("onOps", payload);
113
- const { changes } = payload;
114
+ var _a;
115
+ let { changes } = payload;
114
116
  if (!changes || !Array.isArray(changes) || !changes.length) return;
117
+ changes = el.call(
118
+ "deepDestringify",
119
+ changes,
120
+ Array.isArray(changes) ? [] : {}
121
+ );
115
122
  const changed = applyOpsToCtx(ctx, changes);
116
123
  if (changed.has("state")) {
117
124
  const route = (_a = ctx.state) == null ? void 0 : _a.route;
118
125
  if (route) {
119
- ;
120
- (((_b = ctx.utils) == null ? void 0 : _b.router) || import_router.router)(route.replace("/state", "") || "/", el, {});
126
+ el.call("router", route.replace("/state", "") || "/");
121
127
  } else {
122
128
  s.update(ctx.state);
123
129
  }
124
130
  }
125
- if (["pages", "components", "snippets", "functions"].some((k) => changed.has(k))) {
131
+ if (["pages", "components", "snippets", "functions"].some(
132
+ (k) => changed.has(k)
133
+ )) {
126
134
  const { pathname, search, hash } = ctx.window.location;
127
- (((_c = ctx.utils) == null ? void 0 : _c.router) || import_router.router)(pathname + search + hash, el, {});
135
+ el.call("router", pathname + search + hash);
128
136
  }
129
137
  if (changed.has("designSystem")) {
130
138
  (0, import_init.init)(ctx.designSystem);
@@ -138,10 +146,12 @@ const connectToSocket = async (el, s, ctx) => {
138
146
  }
139
147
  const projectKey = ctx.key;
140
148
  if (!projectKey) {
141
- console.warn("[sync] ctx.key missing \u2013 cannot establish collaborative connection");
149
+ console.warn(
150
+ "[sync] ctx.key missing \u2013 cannot establish collaborative connection"
151
+ );
142
152
  return null;
143
153
  }
144
- const socketBaseUrl = isLocalhost ? "http://localhost:8080" : "https://api.symbols.app";
154
+ const socketBaseUrl = "https://api.symbols.app";
145
155
  const socket = (0, import_socket.io)(socketBaseUrl, {
146
156
  path: "/collab-socket",
147
157
  transports: ["websocket"],
@@ -169,7 +179,8 @@ const connectToSocket = async (el, s, ctx) => {
169
179
  });
170
180
  socket.on("disconnect", (reason) => {
171
181
  var _a;
172
- if ((_a = ctx.editor) == null ? void 0 : _a.verbose) console.info("[sync] Disconnected from collab socket", reason);
182
+ if ((_a = ctx.editor) == null ? void 0 : _a.verbose)
183
+ console.info("[sync] Disconnected from collab socket", reason);
173
184
  });
174
185
  return socket;
175
186
  };
package/dist/esm/index.js CHANGED
@@ -49,8 +49,10 @@ const applyOpsToCtx = (ctx, changes) => {
49
49
  };
50
50
  const fetchServiceToken = async () => {
51
51
  try {
52
- const urlBase = isLocalhost ? "http://localhost:8080" : "https://api.symbols.app";
53
- const res = await window.fetch(`${urlBase}/service-token`, { method: "GET" });
52
+ const urlBase = "https://api.symbols.app";
53
+ const res = await window.fetch(`${urlBase}/service-token`, {
54
+ method: "GET"
55
+ });
54
56
  let txt;
55
57
  try {
56
58
  const json = await res.clone().json();
@@ -67,8 +69,9 @@ const fetchServiceToken = async () => {
67
69
  };
68
70
  const onSnapshot = (el, s, ctx) => (payload = {}) => {
69
71
  var _a;
70
- const { data, schema } = payload;
72
+ let { data, schema } = payload;
71
73
  if (!data) return;
74
+ data = el.call("deepDestringify", data, Array.isArray(data) ? [] : {});
72
75
  Object.entries(data).forEach(([key, val]) => {
73
76
  if (ctx[key] && typeof ctx[key] === "object") {
74
77
  overwriteShallow(ctx[key], val);
@@ -81,23 +84,28 @@ const onSnapshot = (el, s, ctx) => (payload = {}) => {
81
84
  (((_a = ctx.utils) == null ? void 0 : _a.router) || router)(pathname + search + hash, el, {});
82
85
  };
83
86
  const onOps = (el, s, ctx) => (payload = {}) => {
84
- var _a, _b, _c;
85
- console.log("onOps", payload);
86
- const { changes } = payload;
87
+ var _a;
88
+ let { changes } = payload;
87
89
  if (!changes || !Array.isArray(changes) || !changes.length) return;
90
+ changes = el.call(
91
+ "deepDestringify",
92
+ changes,
93
+ Array.isArray(changes) ? [] : {}
94
+ );
88
95
  const changed = applyOpsToCtx(ctx, changes);
89
96
  if (changed.has("state")) {
90
97
  const route = (_a = ctx.state) == null ? void 0 : _a.route;
91
98
  if (route) {
92
- ;
93
- (((_b = ctx.utils) == null ? void 0 : _b.router) || router)(route.replace("/state", "") || "/", el, {});
99
+ el.call("router", route.replace("/state", "") || "/");
94
100
  } else {
95
101
  s.update(ctx.state);
96
102
  }
97
103
  }
98
- if (["pages", "components", "snippets", "functions"].some((k) => changed.has(k))) {
104
+ if (["pages", "components", "snippets", "functions"].some(
105
+ (k) => changed.has(k)
106
+ )) {
99
107
  const { pathname, search, hash } = ctx.window.location;
100
- (((_c = ctx.utils) == null ? void 0 : _c.router) || router)(pathname + search + hash, el, {});
108
+ el.call("router", pathname + search + hash);
101
109
  }
102
110
  if (changed.has("designSystem")) {
103
111
  init(ctx.designSystem);
@@ -111,10 +119,12 @@ const connectToSocket = async (el, s, ctx) => {
111
119
  }
112
120
  const projectKey = ctx.key;
113
121
  if (!projectKey) {
114
- console.warn("[sync] ctx.key missing \u2013 cannot establish collaborative connection");
122
+ console.warn(
123
+ "[sync] ctx.key missing \u2013 cannot establish collaborative connection"
124
+ );
115
125
  return null;
116
126
  }
117
- const socketBaseUrl = isLocalhost ? "http://localhost:8080" : "https://api.symbols.app";
127
+ const socketBaseUrl = "https://api.symbols.app";
118
128
  const socket = io(socketBaseUrl, {
119
129
  path: "/collab-socket",
120
130
  transports: ["websocket"],
@@ -142,7 +152,8 @@ const connectToSocket = async (el, s, ctx) => {
142
152
  });
143
153
  socket.on("disconnect", (reason) => {
144
154
  var _a;
145
- if ((_a = ctx.editor) == null ? void 0 : _a.verbose) console.info("[sync] Disconnected from collab socket", reason);
155
+ if ((_a = ctx.editor) == null ? void 0 : _a.verbose)
156
+ console.info("[sync] Disconnected from collab socket", reason);
146
157
  });
147
158
  return socket;
148
159
  };
package/index.js CHANGED
@@ -64,8 +64,13 @@ const applyOpsToCtx = (ctx, changes) => {
64
64
 
65
65
  const fetchServiceToken = async () => {
66
66
  try {
67
- const urlBase = isLocalhost ? 'http://localhost:8080' : 'https://api.symbols.app'
68
- const res = await window.fetch(`${urlBase}/service-token`, { method: 'GET' })
67
+ // const urlBase = isLocalhost
68
+ // ? 'http://localhost:8080'
69
+ // : 'https://api.symbols.app'
70
+ const urlBase = 'https://api.symbols.app'
71
+ const res = await window.fetch(`${urlBase}/service-token`, {
72
+ method: 'GET'
73
+ })
69
74
 
70
75
  // Attempt to parse JSON first – recent versions return `{ token: "..." }`
71
76
  // Fall back to treating the response as raw text for backward-compatibility.
@@ -87,53 +92,67 @@ const fetchServiceToken = async () => {
87
92
  }
88
93
  }
89
94
 
90
- const onSnapshot = (el, s, ctx) => (payload = {}) => {
91
- const { data, schema } = payload
92
- if (!data) return
95
+ const onSnapshot =
96
+ (el, s, ctx) =>
97
+ (payload = {}) => {
98
+ let { data, schema } = payload
99
+ if (!data) return
100
+ data = el.call('deepDestringify', data, Array.isArray(data) ? [] : {})
101
+
102
+ // Overwrite high-level objects shallowly so references are preserved
103
+ Object.entries(data).forEach(([key, val]) => {
104
+ if (ctx[key] && typeof ctx[key] === 'object') {
105
+ overwriteShallow(ctx[key], val)
106
+ } else {
107
+ ctx[key] = val
108
+ }
109
+ })
110
+
111
+ // Optionally make schema available on ctx
112
+ if (schema) ctx.schema = schema
113
+
114
+ // Trigger routing so UI reflects latest data
115
+ const { pathname, search, hash } = ctx.window.location
116
+ ;(ctx.utils?.router || router)(pathname + search + hash, el, {})
117
+ }
93
118
 
94
- // Overwrite high-level objects shallowly so references are preserved
95
- Object.entries(data).forEach(([key, val]) => {
96
- if (ctx[key] && typeof ctx[key] === 'object') {
97
- overwriteShallow(ctx[key], val)
98
- } else {
99
- ctx[key] = val
119
+ const onOps =
120
+ (el, s, ctx) =>
121
+ (payload = {}) => {
122
+ let { changes } = payload
123
+ if (!changes || !Array.isArray(changes) || !changes.length) return
124
+
125
+ changes = el.call(
126
+ 'deepDestringify',
127
+ changes,
128
+ Array.isArray(changes) ? [] : {}
129
+ )
130
+
131
+ const changed = applyOpsToCtx(ctx, changes)
132
+
133
+ // React to specific top-level changes
134
+ if (changed.has('state')) {
135
+ const route = ctx.state?.route
136
+ if (route) {
137
+ el.call('router', route.replace('/state', '') || '/')
138
+ } else {
139
+ s.update(ctx.state)
140
+ }
100
141
  }
101
- })
102
-
103
- // Optionally make schema available on ctx
104
- if (schema) ctx.schema = schema
105
-
106
- // Trigger routing so UI reflects latest data
107
- const { pathname, search, hash } = ctx.window.location
108
- ;(ctx.utils?.router || router)(pathname + search + hash, el, {})
109
- }
110
-
111
- const onOps = (el, s, ctx) => (payload = {}) => {
112
- console.log('onOps', payload)
113
- const { changes } = payload
114
- if (!changes || !Array.isArray(changes) || !changes.length) return
115
142
 
116
- const changed = applyOpsToCtx(ctx, changes)
117
-
118
- // React to specific top-level changes
119
- if (changed.has('state')) {
120
- const route = ctx.state?.route
121
- if (route) {
122
- ;(ctx.utils?.router || router)(route.replace('/state', '') || '/', el, {})
123
- } else {
124
- s.update(ctx.state)
143
+ if (
144
+ ['pages', 'components', 'snippets', 'functions'].some((k) =>
145
+ changed.has(k)
146
+ )
147
+ ) {
148
+ const { pathname, search, hash } = ctx.window.location
149
+ el.call('router', pathname + search + hash)
125
150
  }
126
- }
127
-
128
- if (['pages', 'components', 'snippets', 'functions'].some(k => changed.has(k))) {
129
- const { pathname, search, hash } = ctx.window.location
130
- ;(ctx.utils?.router || router)(pathname + search + hash, el, {})
131
- }
132
151
 
133
- if (changed.has('designSystem')) {
134
- init(ctx.designSystem)
152
+ if (changed.has('designSystem')) {
153
+ init(ctx.designSystem)
154
+ }
135
155
  }
136
- }
137
156
 
138
157
  export const connectToSocket = async (el, s, ctx) => {
139
158
  const token = await fetchServiceToken()
@@ -144,11 +163,16 @@ export const connectToSocket = async (el, s, ctx) => {
144
163
 
145
164
  const projectKey = ctx.key
146
165
  if (!projectKey) {
147
- console.warn('[sync] ctx.key missing – cannot establish collaborative connection')
166
+ console.warn(
167
+ '[sync] ctx.key missing – cannot establish collaborative connection'
168
+ )
148
169
  return null
149
170
  }
150
171
 
151
- const socketBaseUrl = isLocalhost ? 'http://localhost:8080' : 'https://api.symbols.app'
172
+ const socketBaseUrl = 'https://api.symbols.app'
173
+ // const socketBaseUrl = isLocalhost
174
+ // ? 'http://localhost:8080'
175
+ // : 'https://api.symbols.app'
152
176
 
153
177
  const socket = io(socketBaseUrl, {
154
178
  path: '/collab-socket',
@@ -178,7 +202,8 @@ export const connectToSocket = async (el, s, ctx) => {
178
202
  })
179
203
 
180
204
  socket.on('disconnect', (reason) => {
181
- if (ctx.editor?.verbose) console.info('[sync] Disconnected from collab socket', reason)
205
+ if (ctx.editor?.verbose)
206
+ console.info('[sync] Disconnected from collab socket', reason)
182
207
  })
183
208
 
184
209
  return socket
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@symbo.ls/sync",
3
- "version": "2.29.55",
3
+ "version": "2.29.57",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
- "gitHead": "7d09091d21bdf6f6668a4cba3c581406f768c0fe",
6
+ "gitHead": "e906d60cdc66f68af447a6c73ed09e71055cba02",
7
7
  "files": [
8
8
  "*.js",
9
9
  "dist"
@@ -29,12 +29,12 @@
29
29
  "prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
30
30
  },
31
31
  "dependencies": {
32
- "@domql/router": "^2.29.55",
33
- "@domql/utils": "^2.29.55",
34
- "@symbo.ls/init": "^2.29.55",
35
- "@symbo.ls/scratch": "^2.29.55",
36
- "@symbo.ls/socket": "^2.29.55",
37
- "@symbo.ls/uikit": "^2.29.55",
32
+ "@domql/router": "^2.29.57",
33
+ "@domql/utils": "^2.29.57",
34
+ "@symbo.ls/init": "^2.29.57",
35
+ "@symbo.ls/scratch": "^2.29.57",
36
+ "@symbo.ls/socket": "^2.29.57",
37
+ "@symbo.ls/uikit": "^2.29.57",
38
38
  "socket.io-client": "^4.8.1"
39
39
  },
40
40
  "devDependencies": {