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