@liveblocks/core 3.18.1 → 3.18.2

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.d.cts CHANGED
@@ -1092,9 +1092,7 @@ type LiveNode = LiveStructure | LiveRegister<Json>;
1092
1092
  * A mapping of keys to Lson values. A Lson value is any valid JSON
1093
1093
  * value or a Live storage data structure (LiveMap, LiveList, etc.)
1094
1094
  */
1095
- type LsonObject = {
1096
- [key: string]: Lson | undefined;
1097
- };
1095
+ type LsonObject = Record<string, Lson | undefined>;
1098
1096
  /**
1099
1097
  * Helper type to convert any valid Lson type to the equivalent Json type.
1100
1098
  *
@@ -1110,8 +1108,10 @@ type LsonObject = {
1110
1108
  * ToJson<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
1111
1109
  * // { readonly a: null, readonly b: readonly string[], readonly c?: number }
1112
1110
  */
1113
- type ToJson<L extends Lson | LsonObject> = L extends LiveList<infer I> ? readonly ToJson<I>[] : L extends LiveObject<infer O> ? ToJson<O> : L extends LiveMap<infer KS, infer V> ? {
1114
- readonly [P in KS]: ToJson<V>;
1111
+ type ToJson<L extends Lson | LsonObject> = L extends LiveList<infer I extends Lson> ? Lson extends I ? readonly ReadonlyJson[] : readonly ToJson<I>[] : L extends LiveObject<infer O extends LsonObject> ? LsonObject extends O ? ReadonlyJsonObject : {
1112
+ readonly [K in keyof O]: ToJson<Exclude<O[K], undefined>> | (undefined extends O[K] ? undefined : never);
1113
+ } : L extends LiveMap<infer KS extends string, infer V extends Lson> ? Lson extends V ? ReadonlyJsonObject : {
1114
+ readonly [K in KS]: ToJson<V>;
1115
1115
  } : L extends LsonObject ? string extends keyof L ? ReadonlyJsonObject : {
1116
1116
  readonly [K in keyof L]: ToJson<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
1117
1117
  } : L extends Json ? L : never;
@@ -3288,9 +3288,27 @@ interface History {
3288
3288
  * // room.getPresence() equals { cursor: { x: 0, y: 0 } }
3289
3289
  */
3290
3290
  resume: () => void;
3291
- readonly [kInternal]: {
3292
- withoutHistory: <T>(fn: () => T) => T;
3293
- };
3291
+ /**
3292
+ * Executes a callback with history tracking temporarily disabled. Any
3293
+ * storage mutations made inside the callback will be applied normally
3294
+ * but will not appear on the undo/redo stacks.
3295
+ *
3296
+ * This is useful for background or async writes that should not be
3297
+ * undoable, such as writing back results from an AI generation task
3298
+ * or reconciling state from an external source.
3299
+ *
3300
+ * Returns the callback's return value. If the callback throws, the
3301
+ * undo/redo stacks are left unchanged (as if the callback never ran).
3302
+ *
3303
+ * @example
3304
+ * room.history.disable(() => {
3305
+ * root.set("generatedText", result);
3306
+ * });
3307
+ *
3308
+ * @experimental This API is experimental and may change or be removed
3309
+ * in a future release without following semver guarantees.
3310
+ */
3311
+ disable: <T>(fn: () => T) => T;
3294
3312
  }
3295
3313
  type HistoryEvent = {
3296
3314
  canUndo: boolean;
package/dist/index.d.ts CHANGED
@@ -1092,9 +1092,7 @@ type LiveNode = LiveStructure | LiveRegister<Json>;
1092
1092
  * A mapping of keys to Lson values. A Lson value is any valid JSON
1093
1093
  * value or a Live storage data structure (LiveMap, LiveList, etc.)
1094
1094
  */
1095
- type LsonObject = {
1096
- [key: string]: Lson | undefined;
1097
- };
1095
+ type LsonObject = Record<string, Lson | undefined>;
1098
1096
  /**
1099
1097
  * Helper type to convert any valid Lson type to the equivalent Json type.
1100
1098
  *
@@ -1110,8 +1108,10 @@ type LsonObject = {
1110
1108
  * ToJson<LiveObject<{ a: number, b: LiveList<string>, c?: number }>>
1111
1109
  * // { readonly a: null, readonly b: readonly string[], readonly c?: number }
1112
1110
  */
1113
- type ToJson<L extends Lson | LsonObject> = L extends LiveList<infer I> ? readonly ToJson<I>[] : L extends LiveObject<infer O> ? ToJson<O> : L extends LiveMap<infer KS, infer V> ? {
1114
- readonly [P in KS]: ToJson<V>;
1111
+ type ToJson<L extends Lson | LsonObject> = L extends LiveList<infer I extends Lson> ? Lson extends I ? readonly ReadonlyJson[] : readonly ToJson<I>[] : L extends LiveObject<infer O extends LsonObject> ? LsonObject extends O ? ReadonlyJsonObject : {
1112
+ readonly [K in keyof O]: ToJson<Exclude<O[K], undefined>> | (undefined extends O[K] ? undefined : never);
1113
+ } : L extends LiveMap<infer KS extends string, infer V extends Lson> ? Lson extends V ? ReadonlyJsonObject : {
1114
+ readonly [K in KS]: ToJson<V>;
1115
1115
  } : L extends LsonObject ? string extends keyof L ? ReadonlyJsonObject : {
1116
1116
  readonly [K in keyof L]: ToJson<Exclude<L[K], undefined>> | (undefined extends L[K] ? undefined : never);
1117
1117
  } : L extends Json ? L : never;
@@ -3288,9 +3288,27 @@ interface History {
3288
3288
  * // room.getPresence() equals { cursor: { x: 0, y: 0 } }
3289
3289
  */
3290
3290
  resume: () => void;
3291
- readonly [kInternal]: {
3292
- withoutHistory: <T>(fn: () => T) => T;
3293
- };
3291
+ /**
3292
+ * Executes a callback with history tracking temporarily disabled. Any
3293
+ * storage mutations made inside the callback will be applied normally
3294
+ * but will not appear on the undo/redo stacks.
3295
+ *
3296
+ * This is useful for background or async writes that should not be
3297
+ * undoable, such as writing back results from an AI generation task
3298
+ * or reconciling state from an external source.
3299
+ *
3300
+ * Returns the callback's return value. If the callback throws, the
3301
+ * undo/redo stacks are left unchanged (as if the callback never ran).
3302
+ *
3303
+ * @example
3304
+ * room.history.disable(() => {
3305
+ * root.set("generatedText", result);
3306
+ * });
3307
+ *
3308
+ * @experimental This API is experimental and may change or be removed
3309
+ * in a future release without following semver guarantees.
3310
+ */
3311
+ disable: <T>(fn: () => T) => T;
3294
3312
  }
3295
3313
  type HistoryEvent = {
3296
3314
  canUndo: boolean;
package/dist/index.js 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.18.1";
9
+ var PKG_VERSION = "3.18.2";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -9558,7 +9558,7 @@ function createRoom(options, config) {
9558
9558
  }
9559
9559
  const canWrite = self.get()?.canWrite ?? true;
9560
9560
  const root = context.root;
9561
- withoutHistory(() => {
9561
+ disableHistory(() => {
9562
9562
  for (const key in context.initialStorage) {
9563
9563
  if (root.get(key) === void 0) {
9564
9564
  if (canWrite) {
@@ -9843,6 +9843,7 @@ function createRoom(options, config) {
9843
9843
  return context.redoStack.length > 0;
9844
9844
  }
9845
9845
  function onHistoryChange() {
9846
+ if (historyDisabled > 0) return;
9846
9847
  eventHub.history.notify({ canUndo: canUndo(), canRedo: canRedo() });
9847
9848
  }
9848
9849
  function onUserJoinedMessage(message) {
@@ -10632,14 +10633,24 @@ function createRoom(options, config) {
10632
10633
  }
10633
10634
  commitPausedHistoryToUndoStack();
10634
10635
  }
10635
- function withoutHistory(fn) {
10636
- const undoBefore = context.undoStack.length;
10637
- const redoBefore = context.redoStack.length;
10636
+ let historyDisabled = 0;
10637
+ function disableHistory(fn) {
10638
+ const origUndo = context.undoStack;
10639
+ const origRedo = context.redoStack;
10640
+ const tempUndo = [];
10641
+ const tempRedo = [];
10642
+ context.undoStack = tempUndo;
10643
+ context.redoStack = tempRedo;
10644
+ historyDisabled++;
10638
10645
  try {
10639
10646
  return fn();
10640
10647
  } finally {
10641
- context.undoStack.length = undoBefore;
10642
- context.redoStack.length = redoBefore;
10648
+ historyDisabled--;
10649
+ if (context.undoStack !== tempUndo || context.redoStack !== tempRedo) {
10650
+ throw new Error("unexpected stack swap during history.disable()");
10651
+ }
10652
+ context.undoStack = origUndo;
10653
+ context.redoStack = origRedo;
10643
10654
  }
10644
10655
  }
10645
10656
  const syncSourceForStorage = config.createSyncSource();
@@ -10948,9 +10959,7 @@ function createRoom(options, config) {
10948
10959
  clear,
10949
10960
  pause: pauseHistory,
10950
10961
  resume: resumeHistory,
10951
- [kInternal]: {
10952
- withoutHistory
10953
- }
10962
+ disable: disableHistory
10954
10963
  },
10955
10964
  fetchYDoc,
10956
10965
  fetchFeeds,