@symbo.ls/sdk 2.31.37 → 2.32.1

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/esm/index.js CHANGED
@@ -9166,7 +9166,7 @@ var require_dexie = __commonJS({
9166
9166
  });
9167
9167
  }
9168
9168
  }
9169
- var DEXIE_VERSION = "4.2.0";
9169
+ var DEXIE_VERSION = "4.2.1";
9170
9170
  var maxString = String.fromCharCode(65535);
9171
9171
  var minKey = -Infinity;
9172
9172
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -9291,6 +9291,73 @@ var require_dexie = __commonJS({
9291
9291
  return res;
9292
9292
  });
9293
9293
  }
9294
+ var PropModification2 = (function() {
9295
+ function PropModification3(spec) {
9296
+ this["@@propmod"] = spec;
9297
+ }
9298
+ PropModification3.prototype.execute = function(value2) {
9299
+ var _a2;
9300
+ var spec = this["@@propmod"];
9301
+ if (spec.add !== void 0) {
9302
+ var term = spec.add;
9303
+ if (isArray3(term)) {
9304
+ return __spreadArray(__spreadArray([], isArray3(value2) ? value2 : [], true), term, true).sort();
9305
+ }
9306
+ if (typeof term === "number")
9307
+ return (Number(value2) || 0) + term;
9308
+ if (typeof term === "bigint") {
9309
+ try {
9310
+ return BigInt(value2) + term;
9311
+ } catch (_b) {
9312
+ return BigInt(0) + term;
9313
+ }
9314
+ }
9315
+ throw new TypeError("Invalid term ".concat(term));
9316
+ }
9317
+ if (spec.remove !== void 0) {
9318
+ var subtrahend_1 = spec.remove;
9319
+ if (isArray3(subtrahend_1)) {
9320
+ return isArray3(value2) ? value2.filter(function(item) {
9321
+ return !subtrahend_1.includes(item);
9322
+ }).sort() : [];
9323
+ }
9324
+ if (typeof subtrahend_1 === "number")
9325
+ return Number(value2) - subtrahend_1;
9326
+ if (typeof subtrahend_1 === "bigint") {
9327
+ try {
9328
+ return BigInt(value2) - subtrahend_1;
9329
+ } catch (_c) {
9330
+ return BigInt(0) - subtrahend_1;
9331
+ }
9332
+ }
9333
+ throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
9334
+ }
9335
+ var prefixToReplace = (_a2 = spec.replacePrefix) === null || _a2 === void 0 ? void 0 : _a2[0];
9336
+ if (prefixToReplace && typeof value2 === "string" && value2.startsWith(prefixToReplace)) {
9337
+ return spec.replacePrefix[1] + value2.substring(prefixToReplace.length);
9338
+ }
9339
+ return value2;
9340
+ };
9341
+ return PropModification3;
9342
+ })();
9343
+ function applyUpdateSpec(obj, changes) {
9344
+ var keyPaths = keys2(changes);
9345
+ var numKeys = keyPaths.length;
9346
+ var anythingModified = false;
9347
+ for (var i = 0; i < numKeys; ++i) {
9348
+ var keyPath = keyPaths[i];
9349
+ var value2 = changes[keyPath];
9350
+ var origValue = getByKeyPath(obj, keyPath);
9351
+ if (value2 instanceof PropModification2) {
9352
+ setByKeyPath(obj, keyPath, value2.execute(origValue));
9353
+ anythingModified = true;
9354
+ } else if (origValue !== value2) {
9355
+ setByKeyPath(obj, keyPath, value2);
9356
+ anythingModified = true;
9357
+ }
9358
+ }
9359
+ return anythingModified;
9360
+ }
9294
9361
  var Table = (function() {
9295
9362
  function Table2() {
9296
9363
  }
@@ -9486,6 +9553,28 @@ var require_dexie = __commonJS({
9486
9553
  return lastResult;
9487
9554
  });
9488
9555
  };
9556
+ Table2.prototype.upsert = function(key, modifications) {
9557
+ var _this = this;
9558
+ var keyPath = this.schema.primKey.keyPath;
9559
+ return this._trans("readwrite", function(trans) {
9560
+ return _this.core.get({ trans, key }).then(function(existing) {
9561
+ var obj = existing !== null && existing !== void 0 ? existing : {};
9562
+ applyUpdateSpec(obj, modifications);
9563
+ if (keyPath)
9564
+ setByKeyPath(obj, keyPath, key);
9565
+ return _this.core.mutate({
9566
+ trans,
9567
+ type: "put",
9568
+ values: [obj],
9569
+ keys: [key],
9570
+ upsert: true,
9571
+ updates: { keys: [key], changeSpecs: [modifications] }
9572
+ }).then(function(res) {
9573
+ return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing;
9574
+ });
9575
+ });
9576
+ });
9577
+ };
9489
9578
  Table2.prototype.update = function(keyOrObject, modifications) {
9490
9579
  if (typeof keyOrObject === "object" && !isArray3(keyOrObject)) {
9491
9580
  var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
@@ -9848,55 +9937,6 @@ var require_dexie = __commonJS({
9848
9937
  }
9849
9938
  });
9850
9939
  }
9851
- var PropModification2 = (function() {
9852
- function PropModification3(spec) {
9853
- this["@@propmod"] = spec;
9854
- }
9855
- PropModification3.prototype.execute = function(value2) {
9856
- var _a2;
9857
- var spec = this["@@propmod"];
9858
- if (spec.add !== void 0) {
9859
- var term = spec.add;
9860
- if (isArray3(term)) {
9861
- return __spreadArray(__spreadArray([], isArray3(value2) ? value2 : [], true), term, true).sort();
9862
- }
9863
- if (typeof term === "number")
9864
- return (Number(value2) || 0) + term;
9865
- if (typeof term === "bigint") {
9866
- try {
9867
- return BigInt(value2) + term;
9868
- } catch (_b) {
9869
- return BigInt(0) + term;
9870
- }
9871
- }
9872
- throw new TypeError("Invalid term ".concat(term));
9873
- }
9874
- if (spec.remove !== void 0) {
9875
- var subtrahend_1 = spec.remove;
9876
- if (isArray3(subtrahend_1)) {
9877
- return isArray3(value2) ? value2.filter(function(item) {
9878
- return !subtrahend_1.includes(item);
9879
- }).sort() : [];
9880
- }
9881
- if (typeof subtrahend_1 === "number")
9882
- return Number(value2) - subtrahend_1;
9883
- if (typeof subtrahend_1 === "bigint") {
9884
- try {
9885
- return BigInt(value2) - subtrahend_1;
9886
- } catch (_c) {
9887
- return BigInt(0) - subtrahend_1;
9888
- }
9889
- }
9890
- throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
9891
- }
9892
- var prefixToReplace = (_a2 = spec.replacePrefix) === null || _a2 === void 0 ? void 0 : _a2[0];
9893
- if (prefixToReplace && typeof value2 === "string" && value2.startsWith(prefixToReplace)) {
9894
- return spec.replacePrefix[1] + value2.substring(prefixToReplace.length);
9895
- }
9896
- return value2;
9897
- };
9898
- return PropModification3;
9899
- })();
9900
9940
  var Collection = (function() {
9901
9941
  function Collection2() {
9902
9942
  }
@@ -10176,23 +10216,8 @@ var require_dexie = __commonJS({
10176
10216
  if (typeof changes === "function") {
10177
10217
  modifyer = changes;
10178
10218
  } else {
10179
- var keyPaths = keys2(changes);
10180
- var numKeys = keyPaths.length;
10181
10219
  modifyer = function(item) {
10182
- var anythingModified = false;
10183
- for (var i = 0; i < numKeys; ++i) {
10184
- var keyPath = keyPaths[i];
10185
- var val = changes[keyPath];
10186
- var origVal = getByKeyPath(item, keyPath);
10187
- if (val instanceof PropModification2) {
10188
- setByKeyPath(item, keyPath, val.execute(origVal));
10189
- anythingModified = true;
10190
- } else if (origVal !== val) {
10191
- setByKeyPath(item, keyPath, val);
10192
- anythingModified = true;
10193
- }
10194
- }
10195
- return anythingModified;
10220
+ return applyUpdateSpec(item, changes);
10196
10221
  };
10197
10222
  }
10198
10223
  var coreTable = ctx.table.core;
@@ -12196,8 +12221,8 @@ var require_dexie = __commonJS({
12196
12221
  state.vcFired = true;
12197
12222
  db.on("versionchange").fire(ev);
12198
12223
  });
12199
- idbdb.onclose = wrap(function(ev) {
12200
- db.on("close").fire(ev);
12224
+ idbdb.onclose = wrap(function() {
12225
+ db.close({ disableAutoOpen: false });
12201
12226
  });
12202
12227
  if (wasCreated)
12203
12228
  _onDatabaseCreated(db._deps, dbName);
@@ -28245,6 +28270,262 @@ var validateParams = {
28245
28270
 
28246
28271
  // src/services/CollabService.js
28247
28272
  import { deepStringifyFunctions } from "@domql/utils";
28273
+
28274
+ // src/utils/ordering.js
28275
+ function isObjectLike(val) {
28276
+ return val && typeof val === "object" && !Array.isArray(val);
28277
+ }
28278
+ function normalizePath(path) {
28279
+ if (Array.isArray(path)) {
28280
+ return path;
28281
+ }
28282
+ if (typeof path === "string") {
28283
+ return [path];
28284
+ }
28285
+ return [];
28286
+ }
28287
+ function getParentPathsFromTuples(tuples = []) {
28288
+ const seen = /* @__PURE__ */ new Set();
28289
+ const parents = [];
28290
+ const META_KEYS = /* @__PURE__ */ new Set([
28291
+ "style",
28292
+ "class",
28293
+ "text",
28294
+ "html",
28295
+ "content",
28296
+ "data",
28297
+ "attr",
28298
+ "state",
28299
+ "scope",
28300
+ "props",
28301
+ "define",
28302
+ "on",
28303
+ "extend",
28304
+ "extends",
28305
+ "childExtend",
28306
+ "childExtends",
28307
+ "childProps",
28308
+ "children",
28309
+ "component",
28310
+ "context",
28311
+ "tag",
28312
+ "key",
28313
+ "__order",
28314
+ "if"
28315
+ ]);
28316
+ for (let i = 0; i < tuples.length; i++) {
28317
+ const tuple = tuples[i];
28318
+ if (!Array.isArray(tuple) || tuple.length < 2) {
28319
+ continue;
28320
+ }
28321
+ const path = normalizePath(tuple[1]);
28322
+ if (!path.length) {
28323
+ continue;
28324
+ }
28325
+ if (path[0] === "schema") {
28326
+ continue;
28327
+ }
28328
+ const immediateParent = path.slice(0, -1);
28329
+ if (immediateParent.length) {
28330
+ const key = JSON.stringify(immediateParent);
28331
+ if (!seen.has(key)) {
28332
+ seen.add(key);
28333
+ parents.push(immediateParent);
28334
+ }
28335
+ }
28336
+ const last2 = path[path.length - 1];
28337
+ if (META_KEYS.has(last2) && path.length >= 2) {
28338
+ const containerParent = path.slice(0, -2);
28339
+ if (containerParent.length) {
28340
+ const key2 = JSON.stringify(containerParent);
28341
+ if (!seen.has(key2)) {
28342
+ seen.add(key2);
28343
+ parents.push(containerParent);
28344
+ }
28345
+ }
28346
+ }
28347
+ for (let j = 0; j < path.length; j++) {
28348
+ const seg = path[j];
28349
+ if (!META_KEYS.has(seg)) {
28350
+ continue;
28351
+ }
28352
+ const containerParent2 = path.slice(0, j);
28353
+ if (!containerParent2.length) {
28354
+ continue;
28355
+ }
28356
+ const key3 = JSON.stringify(containerParent2);
28357
+ if (!seen.has(key3)) {
28358
+ seen.add(key3);
28359
+ parents.push(containerParent2);
28360
+ }
28361
+ }
28362
+ }
28363
+ return parents;
28364
+ }
28365
+ function computeOrdersFromState(root, parentPaths = []) {
28366
+ if (!root || typeof root.getByPath !== "function") {
28367
+ return [];
28368
+ }
28369
+ const orders = [];
28370
+ const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
28371
+ for (let i = 0; i < parentPaths.length; i++) {
28372
+ const parentPath = parentPaths[i];
28373
+ const obj = (() => {
28374
+ try {
28375
+ return root.getByPath(parentPath);
28376
+ } catch {
28377
+ return null;
28378
+ }
28379
+ })();
28380
+ if (!isObjectLike(obj)) {
28381
+ continue;
28382
+ }
28383
+ const keys2 = Object.keys(obj).filter((k) => !EXCLUDE_KEYS.has(k));
28384
+ orders.push({ path: parentPath, keys: keys2 });
28385
+ }
28386
+ return orders;
28387
+ }
28388
+ function normaliseSchemaCode(code) {
28389
+ if (typeof code !== "string" || !code.length) {
28390
+ return "";
28391
+ }
28392
+ return code.replaceAll("/////n", "\n").replaceAll("/////tilde", "`");
28393
+ }
28394
+ function parseExportedObject(code) {
28395
+ const src = normaliseSchemaCode(code);
28396
+ if (!src) {
28397
+ return null;
28398
+ }
28399
+ const body = src.replace(/^\s*export\s+default\s*/u, "return ");
28400
+ try {
28401
+ return new Function(body)();
28402
+ } catch {
28403
+ return null;
28404
+ }
28405
+ }
28406
+ function extractTopLevelKeysFromCode(code) {
28407
+ const obj = parseExportedObject(code);
28408
+ if (!obj || typeof obj !== "object") {
28409
+ return [];
28410
+ }
28411
+ return Object.keys(obj);
28412
+ }
28413
+ function computeOrdersForTuples(root, tuples = []) {
28414
+ const pendingChildrenByContainer = /* @__PURE__ */ new Map();
28415
+ for (let i = 0; i < tuples.length; i++) {
28416
+ const t = tuples[i];
28417
+ if (!Array.isArray(t)) {
28418
+ continue;
28419
+ }
28420
+ const [action, path] = t;
28421
+ const p = normalizePath(path);
28422
+ if (!Array.isArray(p) || p.length < 3) {
28423
+ continue;
28424
+ }
28425
+ if (p[0] === "schema") {
28426
+ continue;
28427
+ }
28428
+ const [typeName, containerKey, childKey] = p;
28429
+ const containerPath = [typeName, containerKey];
28430
+ const key = JSON.stringify(containerPath);
28431
+ if (!pendingChildrenByContainer.has(key)) {
28432
+ pendingChildrenByContainer.set(key, /* @__PURE__ */ new Set());
28433
+ }
28434
+ if (action === "update" || action === "set") {
28435
+ pendingChildrenByContainer.get(key).add(childKey);
28436
+ }
28437
+ }
28438
+ const preferredOrderMap = /* @__PURE__ */ new Map();
28439
+ for (let i = 0; i < tuples.length; i++) {
28440
+ const t = tuples[i];
28441
+ if (!Array.isArray(t)) {
28442
+ continue;
28443
+ }
28444
+ const [action, path, value2] = t;
28445
+ const p = normalizePath(path);
28446
+ if (action !== "update" || !Array.isArray(p) || p.length < 3) {
28447
+ continue;
28448
+ }
28449
+ if (p[0] !== "schema") {
28450
+ continue;
28451
+ }
28452
+ const [, type, key] = p;
28453
+ const containerPath = [type, key];
28454
+ const uses = value2 && Array.isArray(value2.uses) ? value2.uses : null;
28455
+ const code = value2 && value2.code;
28456
+ const obj = (() => {
28457
+ try {
28458
+ return root && typeof root.getByPath === "function" ? root.getByPath(containerPath) : null;
28459
+ } catch {
28460
+ return null;
28461
+ }
28462
+ })();
28463
+ if (!obj) {
28464
+ continue;
28465
+ }
28466
+ const present = new Set(Object.keys(obj));
28467
+ const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
28468
+ const codeKeys = extractTopLevelKeysFromCode(code);
28469
+ let resolved = [];
28470
+ const pendingKey = JSON.stringify(containerPath);
28471
+ const pendingChildren = pendingChildrenByContainer.get(pendingKey) || /* @__PURE__ */ new Set();
28472
+ const eligible = /* @__PURE__ */ new Set([...present, ...pendingChildren]);
28473
+ if (Array.isArray(codeKeys) && codeKeys.length) {
28474
+ resolved = codeKeys.filter((k) => eligible.has(k) && !EXCLUDE_KEYS.has(k));
28475
+ }
28476
+ if (Array.isArray(uses) && uses.length) {
28477
+ for (let u = 0; u < uses.length; u++) {
28478
+ const keyName = uses[u];
28479
+ if (eligible.has(keyName) && !EXCLUDE_KEYS.has(keyName) && !resolved.includes(keyName)) {
28480
+ resolved.push(keyName);
28481
+ }
28482
+ }
28483
+ }
28484
+ if (pendingChildren.size) {
28485
+ for (const child of pendingChildren) {
28486
+ if (!EXCLUDE_KEYS.has(child) && !resolved.includes(child)) {
28487
+ resolved.push(child);
28488
+ }
28489
+ }
28490
+ }
28491
+ if (resolved.length) {
28492
+ preferredOrderMap.set(JSON.stringify(containerPath), { path: containerPath, keys: resolved });
28493
+ }
28494
+ }
28495
+ const parents = getParentPathsFromTuples(tuples);
28496
+ const orders = [];
28497
+ const seen = /* @__PURE__ */ new Set();
28498
+ preferredOrderMap.forEach((v) => {
28499
+ const k = JSON.stringify(v.path);
28500
+ if (!seen.has(k)) {
28501
+ seen.add(k);
28502
+ orders.push(v);
28503
+ }
28504
+ });
28505
+ const fallbackOrders = computeOrdersFromState(root, parents);
28506
+ for (let i = 0; i < fallbackOrders.length; i++) {
28507
+ const v = fallbackOrders[i];
28508
+ const k = JSON.stringify(v.path);
28509
+ if (seen.has(k)) {
28510
+ continue;
28511
+ }
28512
+ const pending = pendingChildrenByContainer.get(k);
28513
+ if (pending && pending.size) {
28514
+ const existing = new Set(v.keys);
28515
+ for (const child of pending) {
28516
+ if (existing.has(child)) {
28517
+ continue;
28518
+ }
28519
+ v.keys.push(child);
28520
+ }
28521
+ }
28522
+ seen.add(k);
28523
+ orders.push(v);
28524
+ }
28525
+ return orders;
28526
+ }
28527
+
28528
+ // src/services/CollabService.js
28248
28529
  var CollabService = class extends BaseService {
28249
28530
  constructor(config) {
28250
28531
  super(config);
@@ -28344,53 +28625,49 @@ var CollabService = class extends BaseService {
28344
28625
  if (this._client) {
28345
28626
  await this.disconnect();
28346
28627
  }
28347
- try {
28348
- this._client = new CollabClient({
28349
- jwt,
28350
- projectId,
28351
- branch,
28352
- live: Boolean(pro)
28353
- });
28354
- await new Promise((resolve) => {
28355
- var _a2, _b2;
28356
- if ((_a2 = this._client.socket) == null ? void 0 : _a2.connected) {
28357
- resolve();
28358
- } else {
28359
- (_b2 = this._client.socket) == null ? void 0 : _b2.once("connect", resolve);
28360
- }
28361
- });
28362
- (_b = this._client.socket) == null ? void 0 : _b.on("ops", ({ changes }) => {
28363
- console.log(`ops event`);
28364
- this._stateManager.applyChanges(changes, { fromSocket: true });
28365
- });
28366
- (_c = this._client.socket) == null ? void 0 : _c.on("commit", ({ version: version2 }) => {
28367
- if (version2) {
28368
- this._stateManager.setVersion(version2);
28369
- }
28370
- rootBus.emit("checkpoint:done", { version: version2, origin: "auto" });
28371
- });
28372
- (_d = this._client.socket) == null ? void 0 : _d.on("clients", this._handleClientsEvent.bind(this));
28373
- (_e = this._client.socket) == null ? void 0 : _e.on(
28374
- "bundle:done",
28375
- this._handleBundleDoneEvent.bind(this)
28376
- );
28377
- (_f = this._client.socket) == null ? void 0 : _f.on(
28378
- "bundle:error",
28379
- this._handleBundleErrorEvent.bind(this)
28380
- );
28381
- if (this._pendingOps.length) {
28382
- console.log(
28383
- `[CollabService] Flushing ${this._pendingOps.length} offline operation batch(es)`
28384
- );
28385
- this._pendingOps.forEach(({ tuples }) => {
28386
- this.socket.emit("ops", { changes: tuples, ts: Date.now() });
28387
- });
28388
- this._pendingOps.length = 0;
28628
+ this._client = new CollabClient({
28629
+ jwt,
28630
+ projectId,
28631
+ branch,
28632
+ live: Boolean(pro)
28633
+ });
28634
+ await new Promise((resolve) => {
28635
+ var _a2, _b2;
28636
+ if ((_a2 = this._client.socket) == null ? void 0 : _a2.connected) {
28637
+ resolve();
28638
+ } else {
28639
+ (_b2 = this._client.socket) == null ? void 0 : _b2.once("connect", resolve);
28389
28640
  }
28390
- this._connected = true;
28391
- } catch (err) {
28392
- throw err;
28641
+ });
28642
+ (_b = this._client.socket) == null ? void 0 : _b.on("ops", ({ changes }) => {
28643
+ console.log(`ops event`);
28644
+ this._stateManager.applyChanges(changes, { fromSocket: true });
28645
+ });
28646
+ (_c = this._client.socket) == null ? void 0 : _c.on("commit", ({ version: version2 }) => {
28647
+ if (version2) {
28648
+ this._stateManager.setVersion(version2);
28649
+ }
28650
+ rootBus.emit("checkpoint:done", { version: version2, origin: "auto" });
28651
+ });
28652
+ (_d = this._client.socket) == null ? void 0 : _d.on("clients", this._handleClientsEvent.bind(this));
28653
+ (_e = this._client.socket) == null ? void 0 : _e.on(
28654
+ "bundle:done",
28655
+ this._handleBundleDoneEvent.bind(this)
28656
+ );
28657
+ (_f = this._client.socket) == null ? void 0 : _f.on(
28658
+ "bundle:error",
28659
+ this._handleBundleErrorEvent.bind(this)
28660
+ );
28661
+ if (this._pendingOps.length) {
28662
+ console.log(
28663
+ `[CollabService] Flushing ${this._pendingOps.length} offline operation batch(es)`
28664
+ );
28665
+ this._pendingOps.forEach(({ changes, orders }) => {
28666
+ this.socket.emit("ops", { changes, orders, ts: Date.now() });
28667
+ });
28668
+ this._pendingOps.length = 0;
28393
28669
  }
28670
+ this._connected = true;
28394
28671
  }
28395
28672
  disconnect() {
28396
28673
  var _a;
@@ -28428,24 +28705,128 @@ var CollabService = class extends BaseService {
28428
28705
  }
28429
28706
  /* ---------- data helpers ---------- */
28430
28707
  updateData(tuples, options = {}) {
28431
- var _a;
28708
+ var _a, _b;
28432
28709
  this._ensureStateManager();
28433
28710
  const { isUndo = false, isRedo = false } = options;
28434
28711
  if (!isUndo && !isRedo && !this._isUndoRedo) {
28435
28712
  this._trackForUndo(tuples, options);
28436
28713
  }
28714
+ const processedTuples = (() => {
28715
+ var _a2;
28716
+ try {
28717
+ const root = (_a2 = this._stateManager) == null ? void 0 : _a2.root;
28718
+ const isPlainObject2 = (o) => o && typeof o === "object" && !Array.isArray(o);
28719
+ const getByPath = (state2, path) => {
28720
+ if (!state2 || typeof state2.getByPath !== "function") {
28721
+ return null;
28722
+ }
28723
+ try {
28724
+ return state2.getByPath(path);
28725
+ } catch {
28726
+ return null;
28727
+ }
28728
+ };
28729
+ const expandTuple = (t) => {
28730
+ const [action, path, value2] = t || [];
28731
+ const isSchemaPath = Array.isArray(path) && path[0] === "schema";
28732
+ if (action === "delete" || isSchemaPath) {
28733
+ return [t];
28734
+ }
28735
+ const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2) && isPlainObject2(value2);
28736
+ if (!canConsiderExpansion) {
28737
+ return [t];
28738
+ }
28739
+ const prev = getByPath(root, path) || {};
28740
+ const next = value2 || {};
28741
+ if (!isPlainObject2(prev) || !isPlainObject2(next)) {
28742
+ return [t];
28743
+ }
28744
+ const ops = diffJson(prev, next, []);
28745
+ if (!ops.length) {
28746
+ return [];
28747
+ }
28748
+ const arr = [];
28749
+ for (let j = 0; j < ops.length; j++) {
28750
+ const op = ops[j];
28751
+ const fullPath = [...path, ...op.path];
28752
+ const last2 = fullPath[fullPath.length - 1];
28753
+ if (op.action === "set") {
28754
+ arr.push(["update", fullPath, op.value]);
28755
+ } else if (op.action === "del") {
28756
+ if (last2 !== "__order") {
28757
+ arr.push(["delete", fullPath]);
28758
+ }
28759
+ }
28760
+ }
28761
+ return arr;
28762
+ };
28763
+ const minimizeTuples = (inputTuples) => {
28764
+ const out = [];
28765
+ for (let i = 0; i < inputTuples.length; i++) {
28766
+ const expanded = expandTuple(inputTuples[i]);
28767
+ for (let k = 0; k < expanded.length; k++) {
28768
+ const tuple = expanded[k];
28769
+ const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
28770
+ const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
28771
+ if (!isOrderKey) {
28772
+ out.push(tuple);
28773
+ }
28774
+ }
28775
+ }
28776
+ console.log(`Minimized tuples`, out);
28777
+ return out;
28778
+ };
28779
+ console.log(`Processing tuples`, tuples);
28780
+ return minimizeTuples(tuples);
28781
+ } catch (err) {
28782
+ console.warn(
28783
+ "[CollabService] Minimal diff expansion failed \u2013 using original tuples",
28784
+ err
28785
+ );
28786
+ return tuples;
28787
+ }
28788
+ })();
28437
28789
  if (options.append && options.append.length) {
28438
- tuples.push(...options.append);
28790
+ processedTuples.push(...options.append);
28439
28791
  }
28440
28792
  this._stateManager.applyChanges(tuples, { ...options });
28441
- tuples = deepStringifyFunctions(tuples, []);
28793
+ const state = (_a = this._stateManager) == null ? void 0 : _a.root;
28794
+ const el = state == null ? void 0 : state.__element;
28795
+ const orders = computeOrdersForTuples(state, processedTuples);
28796
+ const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
28797
+ "deepStringifyFunctions",
28798
+ processedTuples,
28799
+ Array.isArray(processedTuples) ? [] : {}
28800
+ ) : deepStringifyFunctions(
28801
+ processedTuples,
28802
+ Array.isArray(processedTuples) ? [] : {}
28803
+ );
28804
+ const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
28805
+ "deepStringifyFunctions",
28806
+ tuples,
28807
+ Array.isArray(tuples) ? [] : {}
28808
+ ) : deepStringifyFunctions(
28809
+ tuples,
28810
+ Array.isArray(tuples) ? [] : {}
28811
+ );
28442
28812
  if (!this.isConnected()) {
28443
28813
  console.warn("[CollabService] Not connected, queuing real-time update");
28444
- this._pendingOps.push({ tuples, options });
28814
+ this._pendingOps.push({ changes: stringifiedTuples, granularChanges: stringifiedGranularTuples, orders, options });
28445
28815
  return;
28446
28816
  }
28447
- if ((_a = this.socket) == null ? void 0 : _a.connected) {
28448
- this.socket.emit("ops", { changes: tuples, ts: Date.now() });
28817
+ if ((_b = this.socket) == null ? void 0 : _b.connected) {
28818
+ console.log("[CollabService] Sending operations to the backend", {
28819
+ changes: stringifiedTuples,
28820
+ granularChanges: stringifiedGranularTuples,
28821
+ orders,
28822
+ ts: Date.now()
28823
+ });
28824
+ this.socket.emit("ops", {
28825
+ changes: stringifiedTuples,
28826
+ granularChanges: stringifiedGranularTuples,
28827
+ orders,
28828
+ ts: Date.now()
28829
+ });
28449
28830
  }
28450
28831
  return { success: true };
28451
28832
  }
@@ -29290,6 +29671,8 @@ var ProjectService = class extends BaseService {
29290
29671
  throw new Error("Changes must be an array");
29291
29672
  }
29292
29673
  const { message, branch = "main", type = "patch" } = options;
29674
+ const state = this._context && this._context.state;
29675
+ const derivedOrders = options.orders || (state ? computeOrdersForTuples(state, changes) : []);
29293
29676
  try {
29294
29677
  const response = await this._request(`/projects/${projectId}/changes`, {
29295
29678
  method: "POST",
@@ -29297,7 +29680,8 @@ var ProjectService = class extends BaseService {
29297
29680
  changes,
29298
29681
  message,
29299
29682
  branch,
29300
- type
29683
+ type,
29684
+ ...derivedOrders && derivedOrders.length ? { orders: derivedOrders } : {}
29301
29685
  }),
29302
29686
  methodName: "applyProjectChanges"
29303
29687
  });
@@ -32512,8 +32896,8 @@ var ScreenshotService = class extends BaseService {
32512
32896
  waitAfterRecreateMs = 2e4,
32513
32897
  recreate = {
32514
32898
  process_pages: true,
32515
- process_components: true,
32516
- process_descriptions: true,
32899
+ process_components: false,
32900
+ process_descriptions: false,
32517
32901
  force: false,
32518
32902
  priority: 5
32519
32903
  },