@mmstack/primitives 21.8.0 → 21.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "21.8.0",
3
+ "version": "21.8.1",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -3767,6 +3767,12 @@ type StoreHistory = {
3767
3767
  undo(): void;
3768
3768
  /** Re-apply the most recently undone change. */
3769
3769
  redo(): void;
3770
+ /**
3771
+ * Close the current coalescing run: the next tracked change starts a NEW undo entry even if
3772
+ * it lands inside the `coalesce` window. Call it on the boundaries your UX considers an
3773
+ * action — a field blur, a selection change, a drag drop. A no-op without `coalesce`.
3774
+ */
3775
+ checkpoint(): void;
3770
3776
  /** Forget all tracked history (e.g. after a save boundary). */
3771
3777
  clear(): void;
3772
3778
  destroy(): void;
@@ -3778,11 +3784,29 @@ type StoreHistoryOptions = CreateOpLogOptions & {
3778
3784
  * The change stream to track. Defaults to self-diffing `source` (every change to the store
3779
3785
  * becomes undoable). For collaborative-safe undo, pass a sync client's LOCAL envelope stream
3780
3786
  * (e.g. an `opSync`'s `subscribe`, which fires only for this peer's own writes) — remote
3781
- * peers' changes then never land on your undo stack.
3787
+ * peers' changes then never land on your undo stack. When the stream exposes `flush` (an
3788
+ * `opSync` does), undo/redo drain it synchronously so their own emissions never echo back
3789
+ * onto the stack as fresh entries.
3782
3790
  */
3783
3791
  readonly track?: {
3784
3792
  subscribe(cb: (batch: OpBatch) => void): () => void;
3793
+ flush?(): void;
3794
+ };
3795
+ /**
3796
+ * Merge rapid consecutive edits into ONE undo entry, so a typing run undoes as a unit
3797
+ * instead of per keystroke. A tracked change arriving within `ms` of the previous one AND
3798
+ * touching the same paths with the same op kinds extends the previous entry (set
3799
+ * `samePath: false` to merge on time alone); anything else — a different field, a kind
3800
+ * change, a pause longer than `ms`, a `checkpoint()`, an undo/redo — starts a new entry.
3801
+ * The window is measured between consecutive changes, so an unbroken run keeps merging.
3802
+ * Undoing a merged entry is exactly equivalent to undoing its changes one by one.
3803
+ */
3804
+ readonly coalesce?: {
3805
+ readonly ms: number;
3806
+ readonly samePath?: boolean;
3785
3807
  };
3808
+ /** Clock for the coalescing window (injectable for tests; default `Date.now`). */
3809
+ readonly now?: () => number;
3786
3810
  };
3787
3811
  /**
3788
3812
  * Undo/redo for a copy-on-write store, built on the op-log: each tracked change is stored as
@@ -3792,7 +3816,8 @@ type StoreHistoryOptions = CreateOpLogOptions & {
3792
3816
  *
3793
3817
  * Composes with sync for collaborative undo: pass `track: syncClient` so only YOUR writes are
3794
3818
  * undoable, while `undo()` emits a normal op that propagates to peers (it writes through the
3795
- * store, which the sync client picks up).
3819
+ * store, which the sync client picks up). Coalescing groups only this stack's entries — what
3820
+ * goes over the wire is untouched.
3796
3821
  */
3797
3822
  declare function storeHistory<T extends object>(source: WritableSignal<T>, opt?: StoreHistoryOptions): StoreHistory;
3798
3823