@designcrowd/library.brand-page 5.18.1-undo-31 → 5.18.1-undo-33

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.
Files changed (42) hide show
  1. package/lib/src/{CreatedOnBrandCrowd-de-de-o_EZLLMS.js → CreatedOnBrandCrowd-de-de-986OpXvU.js} +1 -1
  2. package/lib/src/{CreatedOnBrandCrowd-en-us-BD9czE0V.js → CreatedOnBrandCrowd-en-us-CTZuZ366.js} +1 -1
  3. package/lib/src/{CreatedOnBrandCrowd-es-es-BymhYJ3W.js → CreatedOnBrandCrowd-es-es-CHrTgX9-.js} +1 -1
  4. package/lib/src/{CreatedOnBrandCrowd-fr-fr-CUAEgyAJ.js → CreatedOnBrandCrowd-fr-ca-xJAvxQ-x.js} +1 -1
  5. package/lib/src/{CreatedOnBrandCrowd-fr-ca-CUAEgyAJ.js → CreatedOnBrandCrowd-fr-fr-xJAvxQ-x.js} +1 -1
  6. package/lib/src/{CreatedOnBrandCrowd-pt-pt--zSZt-Xl.js → CreatedOnBrandCrowd-pt-br-lpRIGIcs.js} +1 -1
  7. package/lib/src/{CreatedOnBrandCrowd-pt-br--zSZt-Xl.js → CreatedOnBrandCrowd-pt-pt-lpRIGIcs.js} +1 -1
  8. package/lib/src/{CreatedOnDcom-de-de-BDLX7HCP.js → CreatedOnDcom-de-de-CZuim3ee.js} +1 -1
  9. package/lib/src/{CreatedOnDcom-en-us-BqM2Nkb9.js → CreatedOnDcom-en-us-DG4I5f4s.js} +1 -1
  10. package/lib/src/{CreatedOnDcom-es-es-DJ1TGVBd.js → CreatedOnDcom-es-es-Hpieh1wX.js} +1 -1
  11. package/lib/src/{CreatedOnDcom-fr-ca-Bsml5qLX.js → CreatedOnDcom-fr-ca-DWr5P-df.js} +1 -1
  12. package/lib/src/{CreatedOnDcom-fr-fr-a_Kmgb0N.js → CreatedOnDcom-fr-fr-CHfOyS6V.js} +1 -1
  13. package/lib/src/{CreatedOnDcom-pt-br-c6WK8bRr.js → CreatedOnDcom-pt-br-bQwCCDDI.js} +1 -1
  14. package/lib/src/{CreatedOnDcom-pt-pt-BacuWl6v.js → CreatedOnDcom-pt-pt-bo-i_h0N.js} +1 -1
  15. package/lib/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.js +2 -11
  16. package/lib/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.js +15 -47
  17. package/lib/src/brand-page-maker/stores/history/history-store.d.ts +7 -47
  18. package/lib/src/brand-page-maker/stores/history/history-store.js +67 -271
  19. package/lib/src/index.mjs +1 -1
  20. package/lib/src/{lib-8q5RIrss.js → lib-DNHBgZyy.js} +4520 -4534
  21. package/lib/src/shared/content-settings/components/GenericTextInput.mixin.d.ts +1 -1
  22. package/lib/src/shared/content-settings/components/content-settings/ContentSettings.mixin.d.ts +64 -0
  23. package/lib/src/shared/content-settings/components/content-settings/ContentSettings.mixin.js +5 -0
  24. package/lib/src/shared/content-settings/components/email-field/EmailField.mixin.d.ts +1 -1
  25. package/lib/src/shared/content-settings/components/payment-config-field/PaymentConfigField.mixin.js +2 -8
  26. package/lib/src/shared/content-settings/components/radio-field/RadioField.mixin.d.ts +1 -1
  27. package/lib/src/shared/content-settings/components/tel-field/TelField.mixin.d.ts +1 -1
  28. package/lib/src/shared/content-settings/components/text-field/TextField.mixin.d.ts +1 -1
  29. package/lib/src/shared/content-settings/components/textarea-field/TextareaField.mixin.d.ts +1 -1
  30. package/lib/src/shared/content-settings/components/url-field/UrlField.mixin.d.ts +1 -1
  31. package/lib/src/shared/content-settings/components/youtube-video-field/YoutubeVideoField.mixin.d.ts +1 -1
  32. package/lib/src/shared/logo-settings/store/editable-logo-store.d.ts +0 -18
  33. package/lib/src/shared/logo-settings/store/editable-logo-store.js +6 -24
  34. package/package.json +1 -1
  35. package/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.ts +2 -11
  36. package/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.ts +15 -47
  37. package/src/brand-page-maker/stores/history/history-store.test.ts +29 -0
  38. package/src/brand-page-maker/stores/history/history-store.ts +77 -327
  39. package/src/shared/content-settings/components/content-settings/ContentSettings.mixin.ts +5 -0
  40. package/src/shared/content-settings/components/page-dropdown-field/PageDropdownField.vue +1 -4
  41. package/src/shared/content-settings/components/payment-config-field/PaymentConfigField.mixin.ts +2 -8
  42. package/src/shared/logo-settings/store/editable-logo-store.ts +9 -29
@@ -6,57 +6,27 @@ import { useAiWebsiteBuilderThreadStore } from '../ai-thread/ai-website-builder-
6
6
  import { useEventTracker } from '../../composables/useEventTracker';
7
7
  import { usePageNavigationStore } from '@shared/page-navigation/store/page-navigation-store';
8
8
  import { useUiEditableLogoStore } from '@shared/logo-settings/store/editable-logo-store';
9
- /**
10
- * Single-stack history model with a pointer instead of two stacks.
11
- *
12
- * entries: [e0, e1, e2, e3, e4]
13
- * ^
14
- * currentIndex
15
- *
16
- * canUndo = currentIndex > 0
17
- * canRedo = currentIndex < entries.length - 1
18
- *
19
- * capture → entries = entries.slice(0, currentIndex + 1); push; currentIndex = end
20
- * undo → currentIndex--; applySnapshot(entries[currentIndex])
21
- * redo → currentIndex++; applySnapshot(entries[currentIndex])
22
- *
23
- * This model:
24
- * - eliminates the two-stack-desync risk class (mutating two refs in sequence)
25
- * - makes FR-11 "clear redo on new change" a single array truncation
26
- * - makes it trivial to build a V2 timeline UI (iterate entries, highlight
27
- * currentIndex)
28
- */
29
- // Collapses multi-step mutations into a single capture. Monotonic: first
30
- // mutation starts the timer, further mutations inside the window do not
31
- // reset it. A max-wait ceiling forces a commit during continuous activity
32
- // so a user holding down a key for 15 s still gets periodic snapshots.
9
+ // Monotonic burst — first mutation starts the timer, subsequent mutations
10
+ // don't reset it; max-wait ceiling forces a commit during continuous typing.
33
11
  const CAPTURE_DEBOUNCE_MS = 1700;
34
12
  const CAPTURE_MAX_WAIT_MS = 10000;
35
- // FR-12: 40-entry cap. FR-13: 100 MB memory budget. FR-13c: per-entry
36
- // oversize threshold — entries above this are skipped + emit telemetry.
37
- // 25 MB accommodates a high-res BYO logo upload, which renders ~2.5 MB
38
- // of base64 PNG into each of four viewport sections (~10 MB) plus per-page
39
- // logo content blocks. The variations grid (~10 MB) does NOT live in the
40
- // snapshot — it sits on the editable-logo store keyed by draft token, and
41
- // is restored on undo from there. The 100 MB total budget still evicts
42
- // oldest non-baseline entries to keep memory bounded.
13
+ // FR-12 / FR-13 / FR-13c. 25 MB per-entry accommodates a high-res BYO logo
14
+ // rendered into 4 viewport sections + per-page logo blocks. Oversize
15
+ // entries are skipped with telemetry; 100 MB total evicts oldest
16
+ // non-baseline entries.
43
17
  const MAX_ENTRIES = 40;
44
18
  const MAX_MEMORY_BYTES = 100 * 1024 * 1024;
45
19
  const MAX_ENTRY_BYTES = 25 * 1024 * 1024;
46
- // Window after baseline-capture during which any auto-captured snapshot
47
- // REPLACES the baseline rather than pushing a new entry. Covers post-init
48
- // reactive cascades (template loadPageNo, router afterEach, layout settle)
49
- // that would otherwise make undo light up before the user has done anything.
20
+ // Window after baseline during which captured mutations REPLACE the
21
+ // baseline instead of pushing — covers async post-init cascades
22
+ // (template load, router afterEach, layout settle).
50
23
  const BASELINE_SETTLE_MS = 2000;
51
24
  export const useHistoryStore = defineStore('history', () => {
52
25
  const eventTracker = useEventTracker();
53
26
  // --- State ---
54
- /**
55
- * `shallowRef` keeps the array ref reactive (so dependent computeds recompute
56
- * when we swap the array) but prevents Pinia / Vue from proxying every entry
57
- * object inside. Combined with string snapshots, entries are fully opaque to
58
- * reactivity traversal — which is what we want for a history log.
59
- */
27
+ // shallowRef keeps the array reactive but prevents Pinia from proxying
28
+ // every entry — combined with stringified snapshots, entries are
29
+ // fully opaque to reactivity traversal.
60
30
  const entries = shallowRef([]);
61
31
  const currentIndex = ref(-1); // -1 means "no baseline yet"
62
32
  const isApplyingSnapshot = ref(false);
@@ -67,24 +37,10 @@ export const useHistoryStore = defineStore('history', () => {
67
37
  const canUndo = computed(() => currentIndex.value > 0);
68
38
  const canRedo = computed(() => currentIndex.value >= 0 && currentIndex.value < entries.value.length - 1);
69
39
  // --- Internals ---
70
- /**
71
- * Cached reference to the maker store. Set once when the watcher installs so
72
- * the capture hot path is synchronous.
73
- */
74
- let cachedMakerStore = null;
75
- /**
76
- * Walk `brandPageData` and null `logoImageBase64Url` on every logo
77
- * placement (header/footer × desktop/mobile + per-page logo content).
78
- * Pre-purchase only — the same gate the save path uses
79
- * (see `brand-page-container-store.ts:805`).
80
- *
81
- * Each rendered base64 is ~2-4 MB and the brand-site templates put the
82
- * same logo in 6-8 places, so unstripped pre-purchase snapshots run
83
- * 18-24 MB and bump the 25 MB per-entry cap, which silently drops the
84
- * entry. The base64 is repopulated on undo by `_syncLogoSettingsFromSnapshot`
85
- * (designed: re-issue fabric-render; BYO: stamp from per-token cache),
86
- * so the snapshot doesn't need to carry it.
87
- */
40
+ // Pre-purchase only (matches the save-path strip in
41
+ // `brand-page-container-store.ts:805`). Each rendered base64 is ~2-4 MB
42
+ // across 6-8 placements, so unstripped snapshots bump the 25 MB cap.
43
+ // `_syncLogoSettingsFromSnapshot` repopulates on undo.
88
44
  function stripLogoBase64IfPrePurchase(data) {
89
45
  try {
90
46
  if (!useBrandPageContainerStore().isPrePurchase)
@@ -119,16 +75,9 @@ export const useHistoryStore = defineStore('history', () => {
119
75
  }
120
76
  }
121
77
  }
122
- /**
123
- * Serialize the current `brandPageData` into a detached JSON string.
124
- * Synchronous — safe to call inside a microtask without racing a follow-up
125
- * mutation.
126
- */
127
78
  function serializeCurrentSnapshot() {
128
- if (!cachedMakerStore)
129
- return null;
130
79
  try {
131
- const cloned = JSON.parse(JSON.stringify(toRaw(cachedMakerStore.brandPageData)));
80
+ const cloned = JSON.parse(JSON.stringify(toRaw(useBrandPageMakerStore().brandPageData)));
132
81
  stripLogoBase64IfPrePurchase(cloned);
133
82
  return JSON.stringify(cloned);
134
83
  }
@@ -137,19 +86,9 @@ export const useHistoryStore = defineStore('history', () => {
137
86
  return null;
138
87
  }
139
88
  }
140
- /**
141
- * Read the currently active pageId from `pageNavigationStore`. Sidecar to
142
- * the snapshot string — see `HistoryEntry.activePageId`. Empty string when
143
- * no page is active yet.
144
- */
145
89
  function getCurrentActivePageId() {
146
90
  return usePageNavigationStore().activePageId ?? '';
147
91
  }
148
- /**
149
- * Serialize the current `editableLogoStore.logoEdits` as a sidecar to the
150
- * snapshot — see `HistoryEntry.logoEdits`. Returns undefined when the
151
- * editable-logo store hasn't initialized yet (no logo tab interaction).
152
- */
153
92
  function serializeCurrentLogoEdits() {
154
93
  try {
155
94
  const editableLogoStore = useUiEditableLogoStore();
@@ -160,60 +99,27 @@ export const useHistoryStore = defineStore('history', () => {
160
99
  return undefined;
161
100
  }
162
101
  }
163
- /**
164
- * One-shot "fold next mutation back into the baseline (or current entry)
165
- * rather than pushing a new entry" flag.
166
- *
167
- * Hydration write sites (TipTap mount, lazy paymentConfig fill,
168
- * stale-page-ref clear) all run from a lifecycle hook on first sidebar
169
- * open / section click. Each site mutates `brandPageData` exactly once
170
- * with a value the user can't see as a change — but the deep watcher
171
- * fires anyway, and without this gate the next idle flush would land a
172
- * phantom undo entry.
173
- *
174
- * Each call site sets the flag immediately before the imperative write
175
- * it knows is a hydration. The watcher's flush consumes the flag (clears
176
- * it) and merges the resulting snapshot into `entries[currentIndex]`
177
- * instead of pushing. No TTL — the flag stays armed until either:
178
- * - the watcher fires and consumes it, or
179
- * - a snapshot apply (undo/redo) clears it (we don't want a hydration
180
- * flag set immediately before an apply to swallow the post-apply
181
- * watcher tick), or
182
- * - `reset()` clears it on save.
183
- *
184
- * Multiple call sites in the same burst all set the same flag — they
185
- * collapse together into a single merge into the current head, which is
186
- * the semantics we want.
187
- */
102
+ // One-shot flag set by hydration write sites (TipTap mount, lazy
103
+ // paymentConfig fill, stale-page-ref clear, ContentSettings RTE
104
+ // rewrap) before their imperative write. The watcher's next flush
105
+ // consumes the flag and merges the snapshot into the current head
106
+ // instead of pushing — preventing phantom undo entries on first
107
+ // sidebar open / section click. Cleared on apply and reset.
188
108
  const mergeNextFlush = ref(false);
189
- /**
190
- * Commit a new entry into the stack at the current pointer position.
191
- *
192
- * Returns 'committed' when the entry lands in the stack, 'oversized' when
193
- * the entry exceeds `MAX_ENTRY_BYTES` and is skipped (FR-13c), or 'noop'
194
- * when the snapshot is byte-identical to the entry at the current pointer.
195
- * Callers can use the return to emit telemetry — analytics wiring lives
196
- * in U5.
197
- *
198
- * Enforces these invariants in order:
199
- * 1. Drop no-op duplicates — if the new snapshot is identical to the
200
- * entry at the current pointer, skip it. Color/text settle paths,
201
- * template-switch confirms with no real diff, and AI applies that
202
- * land identical state would otherwise create undo/redo steps that
203
- * do nothing visible.
204
- * 2. FR-13c — if the new entry exceeds 5 MB, skip it entirely.
205
- * 3. FR-11 — truncate any redo tail.
206
- * 4. FR-12 — cap at 40 entries; drop oldest non-baseline on overflow.
207
- * 5. FR-13 — keep total memory under 100 MB; drop oldest non-baseline
208
- * repeatedly until we're under budget.
209
- *
210
- * Baseline (entry 0) is never evicted so "undo everything" always returns
211
- * to session start.
212
- */
109
+ // Returns 'noop' when no-change vs current head, 'oversized' when over
110
+ // MAX_ENTRY_BYTES, else 'committed'. Truncates the redo tail, caps at
111
+ // MAX_ENTRIES, evicts oldest non-baseline to stay under MAX_MEMORY_BYTES.
112
+ // Baseline (index 0) is never evicted.
213
113
  function commitEntry(args) {
214
114
  const current = entries.value[currentIndex.value];
215
- if (current && current.snapshot === args.snapshot)
115
+ // Compare both snapshot AND logoEdits sidecar — pre-purchase logo
116
+ // edits don't change brandPageData (base64 is stripped) so the
117
+ // sidecar is the only signal that distinguishes them.
118
+ if (current &&
119
+ current.snapshot === args.snapshot &&
120
+ current.logoEdits === args.logoEdits) {
216
121
  return 'noop';
122
+ }
217
123
  if (args.snapshot.length > MAX_ENTRY_BYTES) {
218
124
  eventTracker.sendHistoryOversizedEvent({
219
125
  attempted_bytes: args.snapshot.length,
@@ -261,26 +167,8 @@ export const useHistoryStore = defineStore('history', () => {
261
167
  }
262
168
  return 'committed';
263
169
  }
264
- /**
265
- * Install a deep watcher on `brandPageData` that auto-captures mutations.
266
- *
267
- * Debounce strategy (FR-16 / ADR-005):
268
- * - Monotonic — the first mutation starts the idle timer; subsequent
269
- * mutations inside the window DO NOT reset it. This is what collapses
270
- * e.g. an RTE italic click's sync style write + ~100 ms-later HTML
271
- * update into a single capture.
272
- * - Idle flush — the idle timer fires CAPTURE_DEBOUNCE_MS after the
273
- * first mutation in a burst (2 s by default).
274
- * - Max-wait ceiling — if mutations keep arriving and the idle timer
275
- * keeps being "one more edit away", a second timer forces a commit at
276
- * CAPTURE_MAX_WAIT_MS after the burst started (10 s by default). This
277
- * is what keeps a user holding down a key from losing undo resolution.
278
- *
279
- * Both timers clear after a commit fires, so the next mutation starts a
280
- * fresh burst.
281
- */
282
- // Hoisted so force-commit paths (template switch, AI apply) can cancel any
283
- // pending auto-capture that would otherwise duplicate their entry.
170
+ // Hoisted so force-commit paths (template switch, AI apply) can cancel
171
+ // any pending auto-capture that would otherwise duplicate their entry.
284
172
  let idleTimerId = null;
285
173
  let maxWaitTimerId = null;
286
174
  function cancelPendingAutoCapture() {
@@ -296,7 +184,6 @@ export const useHistoryStore = defineStore('history', () => {
296
184
  function installWatcher() {
297
185
  if (watcherInstalled.value)
298
186
  return;
299
- cachedMakerStore = useBrandPageMakerStore();
300
187
  const flush = () => {
301
188
  cancelPendingAutoCapture();
302
189
  if (isApplyingSnapshot.value)
@@ -308,26 +195,13 @@ export const useHistoryStore = defineStore('history', () => {
308
195
  return;
309
196
  const activePageId = getCurrentActivePageId();
310
197
  const logoEdits = serializeCurrentLogoEdits();
311
- // During the post-init settle window, fold any captured mutation back
312
- // into the baseline (entry 0). Async cascades like template
313
- // `loadPageNo`, the router's `afterEach`, and layout settling all
314
- // mutate `brandPageData` after baseline is taken — without this they
315
- // would each look like an undoable user edit on first paint. The
316
- // baseline's `activePageId` is also overwritten so it tracks where
317
- // the user actually settled (the router's `afterEach` runs inside
318
- // this window, so the post-init `activePageId` is more accurate
319
- // than the pre-router value captured in `captureBaseline`).
198
+ // Settle window: fold post-init reactive cascades back into the
199
+ // baseline so undo doesn't light up before the user has done
200
+ // anything.
320
201
  const inSettleWindow = currentIndex.value === 0 &&
321
202
  Date.now() - baselineCapturedAt < BASELINE_SETTLE_MS;
322
- // Merge branch — a hydration write site (TipTap mount, lazy
323
- // paymentConfig fill, stale-page-ref clear) flagged this flush as
324
- // "fold into the head, don't push". Replace `entries[currentIndex]`
325
- // in place so the user-visible undo stack stays exactly as it was
326
- // before the hydration burst arrived. Consume the flag whether or
327
- // not we're in the settle window — `inSettleWindow` already merges
328
- // into the baseline, but past that window the same merge has to
329
- // happen against the current head for hydrations that fire when the
330
- // user clicks into a section after the settle elapsed.
203
+ // Merge: a hydration write site flagged this flush — replace the
204
+ // current head in place instead of pushing. Consumed once.
331
205
  const shouldMerge = mergeNextFlush.value;
332
206
  mergeNextFlush.value = false;
333
207
  if (inSettleWindow) {
@@ -364,12 +238,9 @@ export const useHistoryStore = defineStore('history', () => {
364
238
  logoEdits,
365
239
  });
366
240
  };
367
- // Monotonic burst arming. `isApplyingSnapshot` is gated here so an
368
- // undo/redo doesn't leave a stale timer ticking that later flushes
369
- // mid-keystroke when the user starts editing inside the debounce
370
- // window. `baselineCaptured` is not gated here — `installWatcher` is
371
- // only called from `captureBaseline`, so by the time this fires it is
372
- // always true, and `flush` re-checks it.
241
+ // Monotonic — first mutation arms; subsequent ones inside the window
242
+ // don't reset. Gated on isApplyingSnapshot so undo/redo don't leave
243
+ // a stale timer ticking.
373
244
  const scheduleAutoCapture = () => {
374
245
  if (isApplyingSnapshot.value)
375
246
  return;
@@ -378,17 +249,14 @@ export const useHistoryStore = defineStore('history', () => {
378
249
  idleTimerId = setTimeout(flush, CAPTURE_DEBOUNCE_MS);
379
250
  maxWaitTimerId = setTimeout(flush, CAPTURE_MAX_WAIT_MS);
380
251
  };
381
- watch(() => cachedMakerStore.brandPageData, scheduleAutoCapture, {
252
+ watch(() => useBrandPageMakerStore().brandPageData, scheduleAutoCapture, {
382
253
  deep: true,
383
254
  });
384
255
  watcherInstalled.value = true;
385
256
  }
386
257
  // --- Actions ---
387
- /**
388
- * Captures the baseline entry. Called once per session, typically by
389
- * `BrandPageMaker.mixin.ts` immediately after `setIsBrandPageLoaded(true)`.
390
- * Installs the reactive watcher so subsequent mutations auto-capture.
391
- */
258
+ // Called once per session by BrandPageMaker.mixin.ts after
259
+ // setIsBrandPageLoaded(true). Installs the watcher.
392
260
  function captureBaseline() {
393
261
  if (baselineCaptured.value)
394
262
  return;
@@ -396,7 +264,6 @@ export const useHistoryStore = defineStore('history', () => {
396
264
  const snapshot = serializeCurrentSnapshot();
397
265
  if (!snapshot)
398
266
  return;
399
- // Baseline starts a fresh stack of exactly 1 entry with pointer at 0.
400
267
  entries.value = [
401
268
  {
402
269
  snapshot,
@@ -413,13 +280,7 @@ export const useHistoryStore = defineStore('history', () => {
413
280
  baselineCaptured.value = true;
414
281
  baselineCapturedAt = Date.now();
415
282
  }
416
- /**
417
- * Force-commit capture used by non-watcher call sites (template switch,
418
- * AI apply). The watcher path commits atomically on its own.
419
- *
420
- * Returns the `commitEntry` result so force-commit callers can log
421
- * oversized telemetry — analytics wiring lives in U5.
422
- */
283
+ // Force-commit for non-watcher call sites (template switch, AI apply).
423
284
  function capture(args) {
424
285
  if (isApplyingSnapshot.value)
425
286
  return 'skipped';
@@ -435,47 +296,22 @@ export const useHistoryStore = defineStore('history', () => {
435
296
  ...args,
436
297
  });
437
298
  }
438
- /**
439
- * Force-commit a `template_switch` entry. Cancels any pending auto-capture
440
- * so the template-switch change lands as exactly one entry (not a duplicate
441
- * with the watcher's eventual flush).
442
- */
299
+ // Cancel pending auto-capture so the forced entry doesn't duplicate
300
+ // with the watcher's eventual flush.
443
301
  function captureTemplateSwitch(label) {
444
302
  cancelPendingAutoCapture();
445
303
  return capture({ source: 'template_switch', actor: 'user', label });
446
304
  }
447
- /**
448
- * Force-commit an `ai_changeset` entry. Cancels any pending auto-capture
449
- * so the AI apply lands as exactly one entry per prompt (US-E1).
450
- */
451
305
  function captureAiChangeset(label) {
452
306
  cancelPendingAutoCapture();
453
307
  return capture({ source: 'ai_changeset', actor: 'ai_builder', label });
454
308
  }
455
- /**
456
- * Parse a stringified snapshot and push it through the maker store's
457
- * dedicated `applyHistorySnapshot` action, which rehydrates every Pinia
458
- * source store + own-store scalar fields that `brandPageData` reads from.
459
- *
460
- * Holds `isApplyingSnapshot` for the duration of the apply so the
461
- * watcher guard suppresses the cascade of mutations from being
462
- * re-captured as a spurious duplicate entry.
463
- *
464
- * Active-page resolution priority:
465
- * 1. Diff against `cameFromIndex` — any page present in the target
466
- * snapshot but absent from the source snapshot is being "restored"
467
- * by this transition. Navigate there. Covers undo-of-delete (lands
468
- * on the deleted page) and redo-of-add (lands on the newly-added
469
- * page) — both of which the user expects to "follow" the change.
470
- * Without this, undo of a page-delete would resolve via walk-back
471
- * to whatever page the user was on at the previous baseline, not
472
- * the page they just un-deleted.
473
- * 2. Walk back from `targetIndex` to find the closest entry whose
474
- * captured `activePageId` still exists in the restored snapshot.
475
- * Covers undo-of-add (falls back to the page the user was on
476
- * before they added the new one) and any non-page-structural
477
- * edits.
478
- */
309
+ // Active-page resolution priority:
310
+ // 1. Diff `cameFromIndex` against target — pages present in target
311
+ // but absent from source are being restored/added; navigate there
312
+ // (undo-of-delete, redo-of-add).
313
+ // 2. Walk back from targetIndex for the closest entry whose
314
+ // activePageId still exists (undo-of-add and non-page edits).
479
315
  async function applySnapshotString(snapshotStr, targetIndex, cameFromIndex) {
480
316
  const brandPageMakerStore = useBrandPageMakerStore();
481
317
  let snapshot;
@@ -492,9 +328,7 @@ export const useHistoryStore = defineStore('history', () => {
492
328
  restoredPageIds.add(p.id);
493
329
  });
494
330
  let resolvedActivePageId;
495
- // Step 1: diff against the source-of-transition. The first page in
496
- // the target snapshot whose id is absent from the source is the page
497
- // being restored/added by this apply.
331
+ // Step 1: diff cameFromIndex → first page absent from source wins.
498
332
  const sourceEntry = entries.value[cameFromIndex];
499
333
  if (sourceEntry) {
500
334
  const sourcePageIds = new Set();
@@ -515,9 +349,7 @@ export const useHistoryStore = defineStore('history', () => {
515
349
  // Source snapshot unparseable — fall through to walk-back.
516
350
  }
517
351
  }
518
- // Step 2: walk-back fallback. Used when no page-structural diff
519
- // applies (style/content edits) or when the diff produced nothing
520
- // viable.
352
+ // Step 2: walk-back fallback for non-page-structural edits.
521
353
  if (!resolvedActivePageId) {
522
354
  for (let i = targetIndex; i >= 0; i--) {
523
355
  const candidate = entries.value[i]?.activePageId;
@@ -529,10 +361,8 @@ export const useHistoryStore = defineStore('history', () => {
529
361
  }
530
362
  const targetEntry = entries.value[targetIndex];
531
363
  isApplyingSnapshot.value = true;
532
- // Drop any merge flag a hydration site might have armed but the
533
- // watcher hasn't yet consumed — otherwise the post-apply watcher
534
- // tick would silently fold the freshly-restored snapshot into the
535
- // entry at the new pointer position and erase the user's redo.
364
+ // Clear any unconsumed merge flag — a stale flag would fold the
365
+ // post-apply tick into the restored entry and erase the redo.
536
366
  mergeNextFlush.value = false;
537
367
  cancelPendingAutoCapture();
538
368
  try {
@@ -542,14 +372,13 @@ export const useHistoryStore = defineStore('history', () => {
542
372
  isApplyingSnapshot.value = false;
543
373
  }
544
374
  }
545
- /** Move the pointer back one step and apply the entry at the new position. */
546
375
  async function undo() {
547
376
  if (!canUndo.value)
548
377
  return;
549
378
  const aiThreadStore = useAiWebsiteBuilderThreadStore();
550
379
  if (aiThreadStore.isProcessing)
551
380
  return;
552
- // Capture the actor of the entry we're leaving — that's the change being undone.
381
+ // Actor of the entry being undone (the one we're leaving).
553
382
  const undoneActor = entries.value[currentIndex.value]?.actor;
554
383
  const cameFromIndex = currentIndex.value;
555
384
  currentIndex.value -= 1;
@@ -562,7 +391,6 @@ export const useHistoryStore = defineStore('history', () => {
562
391
  actor: undoneActor,
563
392
  });
564
393
  }
565
- /** Move the pointer forward one step and apply the entry at the new position. */
566
394
  async function redo() {
567
395
  if (!canRedo.value)
568
396
  return;
@@ -575,33 +403,14 @@ export const useHistoryStore = defineStore('history', () => {
575
403
  if (target) {
576
404
  await applySnapshotString(target.snapshot, currentIndex.value, cameFromIndex);
577
405
  }
578
- // Actor of the entry we're moving onto — that's the change being re-applied.
579
406
  eventTracker.sendRedoEvent({
580
407
  entries_count: entries.value.length,
581
408
  actor: target?.actor,
582
409
  });
583
410
  }
584
- /**
585
- * Clear the stack and re-baseline against the just-saved state.
586
- *
587
- * PRD §3 Non-Goals: undo history resets on save/publish — the saved state
588
- * becomes the new clean baseline so a user can't accidentally undo back
589
- * past a save. Called by `brand-page-container-store.saveBrandPage` on a
590
- * successful save (covers both Save Progress and Publish, since publish
591
- * routes through `saveBrandPage`).
592
- *
593
- * No-ops when no baseline has ever been captured — the undo/redo feature
594
- * is gated by `userStore.features.canUseUndoRedo` (see
595
- * BrandPageMaker.mixin.ts), and only flagged sessions install the watcher
596
- * + capture a baseline. Without this guard, calling reset() in an
597
- * unflagged session would install the watcher and start eating memory
598
- * for snapshots the user can never see.
599
- *
600
- * Re-runs `captureBaseline` synchronously so the next mutation lands as
601
- * an actual undoable edit rather than disappearing into a fresh settle
602
- * window. The watcher stays installed; `installWatcher` early-returns
603
- * if `watcherInstalled` is already true.
604
- */
411
+ // PRD §3: undo history resets on save/publish. Called by
412
+ // brand-page-container-store.saveBrandPage. No-ops when no baseline
413
+ // exists — unflagged sessions never installed the watcher.
605
414
  function reset() {
606
415
  if (!baselineCaptured.value)
607
416
  return;
@@ -613,29 +422,16 @@ export const useHistoryStore = defineStore('history', () => {
613
422
  baselineCapturedAt = 0;
614
423
  captureBaseline();
615
424
  }
616
- /**
617
- * Arm the next watcher flush to fold its snapshot into the current head
618
- * entry instead of pushing a new one. Hydration write sites (TipTap mount,
619
- * lazy paymentConfig fill, stale-page-ref clear) call this immediately
620
- * before the imperative `update:modelValue` / `$emit` they know is a
621
- * hydration mutation. The next flush consumes (clears) the flag.
622
- *
623
- * Idempotent — multiple call sites in the same burst all set the same
624
- * flag and collapse together into a single merge into the current head.
625
- *
626
- * No-op when the watcher hasn't yet baselined: hydration writes inside
627
- * the settle window already merge into the baseline; outside a flagged
628
- * session the flag has no observable effect.
629
- */
425
+ // Hydration write sites call this immediately before their imperative
426
+ // mutation; the next watcher flush merges into the current head
427
+ // instead of pushing. Idempotent and one-shot.
630
428
  function mergeNextMutation() {
631
429
  mergeNextFlush.value = true;
632
430
  }
633
431
  // --- Instrumentation (NFR-04a) ---
634
- /** Sum of all entries' serialized sizes in bytes. */
635
432
  function getCurrentSizeBytes() {
636
433
  return entries.value.reduce((sum, e) => sum + e.sizeBytes, 0);
637
434
  }
638
- /** Total number of entries currently in the stack. */
639
435
  function getCurrentEntryCount() {
640
436
  return entries.value.length;
641
437
  }
package/lib/src/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as E, a as T, b as s, c as I, d as S, e as N, f as e, B as A, g as O, h as C, i as G, j as D, k as P, l as t, m as R, n as L, o as M, p as o, q as r, r as b, s as n, t as F, u as i, v as l, w as g, x as B, y as c, z as Y, C as U, D as d, E as u, F as H, G as p, H as y, I as K, J as k, K as m, L as V, M as X, N as h, O as v, P as W, Q as f, R as x, S as z, T as w, U as Z, V as j, W as Q, X as q, Y as J, Z as $, $ as aa, a0 as _a, a1 as Ea, a2 as Ta, a3 as sa, a4 as Ia, a5 as Sa, a6 as Na, a7 as ea, a8 as Aa, a9 as Oa, aa as Ca, ab as Ga, ac as Da, ad as Pa, ae as ta, af as Ra, ag as La, ah as Ma, ai as oa, aj as ra, ak as ba, al as na, am as Fa, an as ia, ao as la, ap as ga, aq as Ba, ar as ca, as as Ya, at as Ua, au as da, av as ua, aw as Ha, ax as pa, ay as ya, az as Ka, aA as ka, aB as ma, aC as Va, aD as Xa, aE as ha, aF as va, aG as Wa, aH as fa, aI as xa, aJ as za, aK as wa, aL as Za, aM as ja, aN as Qa, aO as qa, aP as Ja, aQ as $a, aR as a_, aS as __, aT as E_, aU as T_, aV as s_, aW as I_, aX as S_, aY as N_, aZ as e_, a_ as A_, a$ as O_, b0 as C_, b1 as G_, b2 as D_, b3 as P_, b4 as t_, b5 as R_, b6 as L_, b7 as M_, b8 as o_, b9 as r_, ba as b_, bb as n_, bc as F_, bd as i_, be as l_, bf as g_, bg as B_, bh as c_, bi as Y_, bj as U_, bk as d_, bl as u_, bm as H_, bn as p_, bo as y_, bp as K_, bq as k_, br as m_, bs as V_, bt as X_, bu as h_, bv as v_, bw as W_, bx as f_, by as x_, bz as z_, bA as w_, bB as Z_, bC as j_, bD as Q_, bE as q_, bF as J_, bG as $_, bH as aE, bI as _E, bJ as EE, bK as TE, bL as sE, bM as IE, bN as SE, bO as NE, bP as eE, bQ as AE, bR as OE, bS as CE, bT as GE, bU as DE, bV as PE, bW as tE, bX as RE, bY as LE, bZ as ME, b_ as oE, b$ as rE, c0 as bE, c1 as nE, c2 as FE, c3 as iE, c4 as lE, c5 as gE, c6 as BE, c7 as cE, c8 as YE, c9 as UE, ca as dE, cb as uE, cc as HE, cd as pE, ce as yE, cf as KE, cg as kE, ch as mE, ci as VE, cj as XE, ck as hE, cl as vE, cm as WE, cn as fE, co as xE } from "./lib-8q5RIrss.js";
1
+ import { A as E, a as T, b as s, c as I, d as S, e as N, f as e, B as A, g as O, h as C, i as G, j as D, k as P, l as t, m as R, n as L, o as M, p as o, q as r, r as b, s as n, t as F, u as i, v as l, w as g, x as B, y as c, z as Y, C as U, D as d, E as u, F as H, G as p, H as y, I as K, J as k, K as m, L as V, M as X, N as h, O as v, P as W, Q as f, R as x, S as z, T as w, U as Z, V as j, W as Q, X as q, Y as J, Z as $, $ as aa, a0 as _a, a1 as Ea, a2 as Ta, a3 as sa, a4 as Ia, a5 as Sa, a6 as Na, a7 as ea, a8 as Aa, a9 as Oa, aa as Ca, ab as Ga, ac as Da, ad as Pa, ae as ta, af as Ra, ag as La, ah as Ma, ai as oa, aj as ra, ak as ba, al as na, am as Fa, an as ia, ao as la, ap as ga, aq as Ba, ar as ca, as as Ya, at as Ua, au as da, av as ua, aw as Ha, ax as pa, ay as ya, az as Ka, aA as ka, aB as ma, aC as Va, aD as Xa, aE as ha, aF as va, aG as Wa, aH as fa, aI as xa, aJ as za, aK as wa, aL as Za, aM as ja, aN as Qa, aO as qa, aP as Ja, aQ as $a, aR as a_, aS as __, aT as E_, aU as T_, aV as s_, aW as I_, aX as S_, aY as N_, aZ as e_, a_ as A_, a$ as O_, b0 as C_, b1 as G_, b2 as D_, b3 as P_, b4 as t_, b5 as R_, b6 as L_, b7 as M_, b8 as o_, b9 as r_, ba as b_, bb as n_, bc as F_, bd as i_, be as l_, bf as g_, bg as B_, bh as c_, bi as Y_, bj as U_, bk as d_, bl as u_, bm as H_, bn as p_, bo as y_, bp as K_, bq as k_, br as m_, bs as V_, bt as X_, bu as h_, bv as v_, bw as W_, bx as f_, by as x_, bz as z_, bA as w_, bB as Z_, bC as j_, bD as Q_, bE as q_, bF as J_, bG as $_, bH as aE, bI as _E, bJ as EE, bK as TE, bL as sE, bM as IE, bN as SE, bO as NE, bP as eE, bQ as AE, bR as OE, bS as CE, bT as GE, bU as DE, bV as PE, bW as tE, bX as RE, bY as LE, bZ as ME, b_ as oE, b$ as rE, c0 as bE, c1 as nE, c2 as FE, c3 as iE, c4 as lE, c5 as gE, c6 as BE, c7 as cE, c8 as YE, c9 as UE, ca as dE, cb as uE, cc as HE, cd as pE, ce as yE, cf as KE, cg as kE, ch as mE, ci as VE, cj as XE, ck as hE, cl as vE, cm as WE, cn as fE, co as xE } from "./lib-DNHBgZyy.js";
2
2
  import { createPinia as wE, setActivePinia as ZE } from "pinia";
3
3
  export {
4
4
  E as ABOUT_SECTION_SETTINGS_CONFIG,