@liveblocks/core 3.23.2-exp1 → 3.24.0

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/index.cjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "3.23.2-exp1";
9
+ var PKG_VERSION = "3.24.0";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -1108,6 +1108,39 @@ function* nodeStreamToCompactNodes(nodes) {
1108
1108
  // src/internal.ts
1109
1109
  var kInternal = /* @__PURE__ */ Symbol();
1110
1110
 
1111
+ // src/lib/fancy-console.ts
1112
+ var fancy_console_exports = {};
1113
+ __export(fancy_console_exports, {
1114
+ error: () => error2,
1115
+ errorWithTitle: () => errorWithTitle,
1116
+ warn: () => warn,
1117
+ warnWithTitle: () => warnWithTitle
1118
+ });
1119
+ var badge = "background:#0e0d12;border-radius:9999px;color:#fff;padding:3px 7px;font-family:sans-serif;font-weight:600;";
1120
+ var bold = "font-weight:600";
1121
+ function wrap(method) {
1122
+ return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
1123
+ /* istanbul ignore next */
1124
+ (message, ...args) => console[method]("%cLiveblocks", badge, message, ...args)
1125
+ );
1126
+ }
1127
+ var warn = wrap("warn");
1128
+ var error2 = wrap("error");
1129
+ function wrapWithTitle(method) {
1130
+ return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
1131
+ /* istanbul ignore next */
1132
+ (title, message, ...args) => console[method](
1133
+ `%cLiveblocks%c ${title}`,
1134
+ badge,
1135
+ bold,
1136
+ message,
1137
+ ...args
1138
+ )
1139
+ );
1140
+ }
1141
+ var warnWithTitle = wrapWithTitle("warn");
1142
+ var errorWithTitle = wrapWithTitle("error");
1143
+
1111
1144
  // src/lib/position.ts
1112
1145
  var MIN_CODE = 32;
1113
1146
  var MAX_CODE = 126;
@@ -1403,6 +1436,8 @@ ${parentKey}`;
1403
1436
  };
1404
1437
 
1405
1438
  // src/crdts/AbstractCrdt.ts
1439
+ var warnedOrphanedNodes = /* @__PURE__ */ new WeakSet();
1440
+ var ORPHANED_NODE_WARNING = "Cannot sync changes made to this Live structure because it is no longer part of Storage. Retrieve the current value from its parent before mutating it.";
1406
1441
  function createManagedPool(options) {
1407
1442
  const {
1408
1443
  getCurrentConnectionId,
@@ -1494,6 +1529,17 @@ var AbstractCrdt = class {
1494
1529
  return this.#parent;
1495
1530
  }
1496
1531
  /** @internal */
1532
+ _warnIfOrphaned() {
1533
+ const node = crdtAsLiveNode(this);
1534
+ if (this.parent.type === "Orphaned" && !warnedOrphanedNodes.has(node)) {
1535
+ warnedOrphanedNodes.add(node);
1536
+ warn(ORPHANED_NODE_WARNING, {
1537
+ type: node.constructor.name,
1538
+ formerParentKey: this.parent.oldKey
1539
+ });
1540
+ }
1541
+ }
1542
+ /** @internal */
1497
1543
  get _parentKey() {
1498
1544
  switch (this.parent.type) {
1499
1545
  case "HasParent":
@@ -1725,39 +1771,6 @@ var LiveFile = class _LiveFile extends AbstractCrdt {
1725
1771
  }
1726
1772
  };
1727
1773
 
1728
- // src/lib/fancy-console.ts
1729
- var fancy_console_exports = {};
1730
- __export(fancy_console_exports, {
1731
- error: () => error2,
1732
- errorWithTitle: () => errorWithTitle,
1733
- warn: () => warn,
1734
- warnWithTitle: () => warnWithTitle
1735
- });
1736
- var badge = "background:#0e0d12;border-radius:9999px;color:#fff;padding:3px 7px;font-family:sans-serif;font-weight:600;";
1737
- var bold = "font-weight:600";
1738
- function wrap(method) {
1739
- return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
1740
- /* istanbul ignore next */
1741
- (message, ...args) => console[method]("%cLiveblocks", badge, message, ...args)
1742
- );
1743
- }
1744
- var warn = wrap("warn");
1745
- var error2 = wrap("error");
1746
- function wrapWithTitle(method) {
1747
- return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
1748
- /* istanbul ignore next */
1749
- (title, message, ...args) => console[method](
1750
- `%cLiveblocks%c ${title}`,
1751
- badge,
1752
- bold,
1753
- message,
1754
- ...args
1755
- )
1756
- );
1757
- }
1758
- var warnWithTitle = wrapWithTitle("warn");
1759
- var errorWithTitle = wrapWithTitle("error");
1760
-
1761
1774
  // src/lib/guards.ts
1762
1775
  function isDefined(value) {
1763
1776
  return value !== null && value !== void 0;
@@ -7722,6 +7735,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7722
7735
  * instead of resolving its position against the client's stale view.
7723
7736
  */
7724
7737
  #injectAt(element, index, intent) {
7738
+ this._warnIfOrphaned();
7725
7739
  _optionalChain([this, 'access', _181 => _181._pool, 'optionalAccess', _182 => _182.assertStorageIsWritable, 'call', _183 => _183()]);
7726
7740
  if (index < 0 || index > this.#items.length) {
7727
7741
  throw new Error(
@@ -7753,6 +7767,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7753
7767
  * @param targetIndex The index where the element should be after moving.
7754
7768
  */
7755
7769
  move(index, targetIndex) {
7770
+ this._warnIfOrphaned();
7756
7771
  _optionalChain([this, 'access', _192 => _192._pool, 'optionalAccess', _193 => _193.assertStorageIsWritable, 'call', _194 => _194()]);
7757
7772
  if (targetIndex < 0) {
7758
7773
  throw new Error("targetIndex cannot be less than 0");
@@ -7813,6 +7828,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7813
7828
  * @param index The index of the element to delete
7814
7829
  */
7815
7830
  delete(index) {
7831
+ this._warnIfOrphaned();
7816
7832
  _optionalChain([this, 'access', _203 => _203._pool, 'optionalAccess', _204 => _204.assertStorageIsWritable, 'call', _205 => _205()]);
7817
7833
  if (index < 0 || index >= this.#items.length) {
7818
7834
  throw new Error(
@@ -7846,6 +7862,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7846
7862
  }
7847
7863
  }
7848
7864
  clear() {
7865
+ this._warnIfOrphaned();
7849
7866
  _optionalChain([this, 'access', _206 => _206._pool, 'optionalAccess', _207 => _207.assertStorageIsWritable, 'call', _208 => _208()]);
7850
7867
  if (this._pool) {
7851
7868
  const ops = [];
@@ -7883,6 +7900,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
7883
7900
  }
7884
7901
  }
7885
7902
  set(index, item) {
7903
+ this._warnIfOrphaned();
7886
7904
  _optionalChain([this, 'access', _209 => _209._pool, 'optionalAccess', _210 => _210.assertStorageIsWritable, 'call', _211 => _211()]);
7887
7905
  if (index < 0 || index >= this.#items.length) {
7888
7906
  throw new Error(
@@ -8297,6 +8315,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
8297
8315
  * @param value The value of the element to add. Should be serializable to JSON.
8298
8316
  */
8299
8317
  set(key, value) {
8318
+ this._warnIfOrphaned();
8300
8319
  _optionalChain([this, 'access', _216 => _216._pool, 'optionalAccess', _217 => _217.assertStorageIsWritable, 'call', _218 => _218()]);
8301
8320
  const oldValue = this.#map.get(key);
8302
8321
  if (oldValue) {
@@ -8344,6 +8363,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
8344
8363
  * @returns true if an element existed and has been removed, or false if the element does not exist.
8345
8364
  */
8346
8365
  delete(key) {
8366
+ this._warnIfOrphaned();
8347
8367
  _optionalChain([this, 'access', _219 => _219._pool, 'optionalAccess', _220 => _220.assertStorageIsWritable, 'call', _221 => _221()]);
8348
8368
  const item = this.#map.get(key);
8349
8369
  if (item === void 0) {
@@ -8963,6 +8983,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8963
8983
  * Caveat: this method will not add changes to the undo/redo stack.
8964
8984
  */
8965
8985
  setLocal(key, value) {
8986
+ this._warnIfOrphaned();
8966
8987
  _optionalChain([this, 'access', _222 => _222._pool, 'optionalAccess', _223 => _223.assertStorageIsWritable, 'call', _224 => _224()]);
8967
8988
  const deleteResult = this.#prepareDelete(key);
8968
8989
  this.#local.set(key, value);
@@ -8997,6 +9018,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
8997
9018
  * #synced or pool/id are unavailable. Does NOT dispatch.
8998
9019
  */
8999
9020
  #prepareDelete(key) {
9021
+ this._warnIfOrphaned();
9000
9022
  _optionalChain([this, 'access', _229 => _229._pool, 'optionalAccess', _230 => _230.assertStorageIsWritable, 'call', _231 => _231()]);
9001
9023
  const k = key;
9002
9024
  if (this.#local.has(k) && !this.#synced.has(k)) {
@@ -9083,6 +9105,7 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
9083
9105
  * @param patch The object used to overrides properties
9084
9106
  */
9085
9107
  update(patch) {
9108
+ this._warnIfOrphaned();
9086
9109
  _optionalChain([this, 'access', _235 => _235._pool, 'optionalAccess', _236 => _236.assertStorageIsWritable, 'call', _237 => _237()]);
9087
9110
  if (_LiveObject.detectLargeObjects) {
9088
9111
  const data = {};
@@ -10078,6 +10101,7 @@ var LiveText = class _LiveText extends AbstractCrdt {
10078
10101
  if (ops.length === 0) {
10079
10102
  return;
10080
10103
  }
10104
+ this._warnIfOrphaned();
10081
10105
  _optionalChain([this, 'access', _241 => _241._pool, 'optionalAccess', _242 => _242.assertStorageIsWritable, 'call', _243 => _243()]);
10082
10106
  const attached = this._pool !== void 0 && this._id !== void 0;
10083
10107
  const reverse = attached ? this.#invertOperations(ops) : [];