@designcrowd/library.brand-page 5.18.3-undo-38 → 5.18.3
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/lib/src/{CreatedOnBrandCrowd-de-de-ydEGYl5O.js → CreatedOnBrandCrowd-de-de-CkuAAwKQ.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-en-us-BiJ8RmwM.js → CreatedOnBrandCrowd-en-us-Coln5kSU.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-es-es-C8CyL1ny.js → CreatedOnBrandCrowd-es-es-raGyXChm.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-fr-BMh0yIJJ.js → CreatedOnBrandCrowd-fr-ca-BT_WYYxW.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-ca-BMh0yIJJ.js → CreatedOnBrandCrowd-fr-fr-BT_WYYxW.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-pt-C0DghlQk.js → CreatedOnBrandCrowd-pt-br-BRbD_kiI.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-br-C0DghlQk.js → CreatedOnBrandCrowd-pt-pt-BRbD_kiI.js} +1 -1
- package/lib/src/{CreatedOnDcom-de-de-CZEnW0qm.js → CreatedOnDcom-de-de-DetCIFxa.js} +1 -1
- package/lib/src/{CreatedOnDcom-en-us-DPpRkfrD.js → CreatedOnDcom-en-us-D0LeF_V2.js} +1 -1
- package/lib/src/{CreatedOnDcom-es-es-8yTtB23v.js → CreatedOnDcom-es-es-CHa4stWS.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-ca-DdGwSBLy.js → CreatedOnDcom-fr-ca-ntW7A335.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-fr-DRGbffC4.js → CreatedOnDcom-fr-fr-C6rQcclc.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-br-CWm_1vbQ.js → CreatedOnDcom-pt-br-Cn07ZK_m.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-pt-DZBR79tn.js → CreatedOnDcom-pt-pt-CewmqYVY.js} +1 -1
- package/lib/src/brand-page-maker/components/action-bar/ActionBar.mixin.d.ts +2 -7
- package/lib/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.mixin.d.ts +2 -7
- package/lib/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.mixin.js +0 -10
- package/lib/src/brand-page-maker/components/brand-page-maker/BrandPageMakerTemplateSettings.mixin.d.ts +2 -7
- package/lib/src/brand-page-maker/components/brand-page-maker/__fixtures__/brand-page-examples.js +0 -1
- package/lib/src/brand-page-maker/components/brandpage-maker-page/BrandPageMakerPage.mixin.d.ts +2 -87
- package/lib/src/brand-page-maker/components/brandpage-maker-page/BrandPageMakerPage.mixin.js +0 -5
- package/lib/src/brand-page-maker/components/brandpage-settings/ReplaceImageSettingsForBrandPageSettings.mixin.d.ts +2 -7
- package/lib/src/brand-page-maker/components/quick-link-bar/QuickLinkBar.mixin.d.ts +0 -3
- package/lib/src/brand-page-maker/components/quick-link-bar/QuickLinkBar.mixin.js +0 -11
- package/lib/src/brand-page-maker/components/seo-settings/SeoPageSettings.mixin.d.ts +2 -7
- package/lib/src/brand-page-maker/components/seo-settings/UrlSettings.mixin.d.ts +2 -7
- package/lib/src/brand-page-maker/components/social-share/SocialShare.mixin.d.ts +2 -7
- package/lib/src/brand-page-maker/components/template-preview/TemplatePreview.mixin.d.ts +2 -7
- package/lib/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.js +0 -9
- package/lib/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.js +1 -20
- package/lib/src/brand-page-maker/composables/useEventTracker.d.ts +0 -20
- package/lib/src/brand-page-maker/composables/useEventTracker.js +0 -17
- package/lib/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.d.ts +2 -41
- package/lib/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.js +5 -307
- package/lib/src/brand-page-maker/stores/logo-store/logo-store.d.ts +0 -1
- package/lib/src/brand-page-maker/stores/user/user-store.js +0 -1
- package/lib/src/bundled-translations-B5Fkt3qd.js +175 -0
- package/lib/src/bundles/bundled-translations.json +1 -3
- package/lib/src/constants/ui.d.ts +0 -1
- package/lib/src/css/library.brand-page-brandCrowd.min.css +15 -20
- package/lib/src/css/library.brand-page-brandPage.min.css +16 -20
- package/lib/src/css/library.brand-page-designCom.min.css +15 -20
- package/lib/src/css/library.brand-page-preview.min.css +15 -20
- package/lib/src/index.mjs +1 -1
- package/lib/src/{lib-BZlXQjdd.js → lib-CGfmcIBb.js} +29373 -29970
- package/lib/src/shared/content-settings/components/content-settings/ContentSettings.mixin.d.ts +2 -87
- package/lib/src/shared/content-settings/components/content-settings/ContentSettings.mixin.js +0 -5
- package/lib/src/shared/content-settings/components/content-settings/ContentSettings.stories.js +0 -1
- package/lib/src/shared/content-settings/components/content-settings/ReplaceImageSettingsForContent.mixin.d.ts +2 -23
- package/lib/src/shared/content-settings/components/content-settings-item/ContentSettingsItem.mixin.d.ts +0 -16
- package/lib/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.d.ts +2 -7
- package/lib/src/shared/content-settings/components/draggable-item-list/DraggableItemList.mixin.d.ts +0 -3
- package/lib/src/shared/content-settings/components/draggable-item-list/DraggableItemList.mixin.js +2 -19
- package/lib/src/shared/content-settings/components/form-fields-field/FormFieldsField.mixin.js +8 -18
- package/lib/src/shared/content-settings/components/payment-config-field/PaymentConfigField.mixin.d.ts +0 -64
- package/lib/src/shared/content-settings/components/payment-config-field/PaymentConfigField.mixin.js +0 -6
- package/lib/src/shared/logo-settings/components/EditLogoSettings.mixin.d.ts +0 -19
- package/lib/src/shared/logo-settings/components/EditLogoSettings.mixin.js +0 -11
- package/lib/src/shared/logo-settings/components/LogoSettings.mixin.d.ts +2 -10
- package/lib/src/shared/logo-settings/store/editable-logo-store.d.ts +1 -5
- package/lib/src/shared/logo-settings/store/editable-logo-store.js +0 -31
- package/lib/src/shared/page-settings/components/page-settings/PageSettings.mixin.d.ts +2 -24
- package/lib/src/shared/page-settings/components/page-settings-section-styles/PageSettingsSectionStyles.mixin.d.ts +2 -10
- package/lib/src/shared/publish-brand-page-with-state/PublishBrandPageModalWithState.mixin.d.ts +2 -23
- package/lib/src/shared/side-bar/components/SideBarTabButton.mixin.d.ts +0 -16
- package/lib/src/shared/style-settings/components/StyleSettings.mixin.d.ts +2 -23
- package/lib/src/shared/template-settings/components/TemplatesSettings.mixin.d.ts +0 -16
- package/package.json +1 -1
- package/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.mixin.ts +0 -11
- package/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.vue +3 -2
- package/src/brand-page-maker/components/brand-page-maker/__fixtures__/brand-page-examples.ts +0 -1
- package/src/brand-page-maker/components/brandpage-maker-page/BrandPageMakerPage.mixin.ts +0 -5
- package/src/brand-page-maker/components/cookie-collection/CookieSettings.vue +17 -18
- package/src/brand-page-maker/components/quick-link-bar/QuickLinkBar.mixin.ts +0 -13
- package/src/brand-page-maker/components/quick-link-bar/QuickLinkBar.vue +3 -26
- package/src/brand-page-maker/components/quick-link-bar/i18n/quick-link-bar.json +1 -3
- package/src/brand-page-maker/components/save-contact/SaveContact.vue +19 -12
- package/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.ts +0 -10
- package/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.ts +1 -24
- package/src/brand-page-maker/composables/useEventTracker.ts +0 -29
- package/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.test.ts +0 -335
- package/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.ts +4 -371
- package/src/brand-page-maker/stores/logo-store/logo-store.ts +0 -5
- package/src/brand-page-maker/stores/user/user-store.ts +0 -1
- package/src/bundles/bundled-translations.json +1 -3
- package/src/constants/ui.ts +0 -1
- package/src/shared/content-settings/components/content-settings/ContentSettings.mixin.ts +0 -5
- package/src/shared/content-settings/components/content-settings/ContentSettings.stories.ts +0 -1
- package/src/shared/content-settings/components/draggable-item-list/DraggableItemList.mixin.ts +2 -19
- package/src/shared/content-settings/components/draggable-item-list/DraggableItemList.vue +1 -1
- package/src/shared/content-settings/components/form-fields-field/FormFieldsField.mixin.ts +10 -26
- package/src/shared/content-settings/components/logo-selection-field/LogoSelection.vue +48 -63
- package/src/shared/content-settings/components/page-dropdown-field/PageDropdownField.vue +0 -4
- package/src/shared/content-settings/components/payment-config-field/PaymentConfigField.mixin.ts +0 -7
- package/src/shared/content-settings/components/text-field/TextField.vue +0 -1
- package/src/shared/content-settings/components/text-image-field/TextImageField.vue +4 -33
- package/src/shared/logo-settings/components/EditLogoSettings.mixin.ts +0 -11
- package/src/shared/logo-settings/store/editable-logo-store.ts +1 -42
- package/lib/src/brand-page-maker/composables/useUndoRedoFlag.d.ts +0 -16
- package/lib/src/brand-page-maker/composables/useUndoRedoFlag.js +0 -22
- package/lib/src/brand-page-maker/stores/history/history-store.d.ts +0 -83
- package/lib/src/brand-page-maker/stores/history/history-store.js +0 -495
- package/lib/src/bundled-translations-D1q3rSEz.js +0 -175
- package/lib/src/metadata-builder/builders/reorder-pages-builder.d.ts +0 -13
- package/lib/src/metadata-builder/builders/reorder-pages-builder.js +0 -49
- package/src/brand-page-maker/components/quick-link-bar/RedoButton.vue +0 -66
- package/src/brand-page-maker/components/quick-link-bar/UndoButton.vue +0 -66
- package/src/brand-page-maker/components/quick-link-bar/undo-redo-buttons.test.ts +0 -116
- package/src/brand-page-maker/composables/useUndoRedoFlag.ts +0 -26
- package/src/brand-page-maker/stores/history/history-store.test.ts +0 -1120
- package/src/brand-page-maker/stores/history/history-store.ts +0 -660
- package/src/metadata-builder/builders/reorder-pages-builder.ts +0 -80
|
@@ -1,660 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia';
|
|
2
|
-
import { computed, ref, shallowRef, toRaw, watch } from 'vue';
|
|
3
|
-
import type { BrandPageModel } from '@brand-page';
|
|
4
|
-
import { useBrandPageMakerStore } from '../brandpage-maker/brandpage-maker-store';
|
|
5
|
-
import { useBrandPageContainerStore } from '../brandpage-container';
|
|
6
|
-
import { useAiWebsiteBuilderThreadStore } from '../ai-thread/ai-website-builder-thread-store';
|
|
7
|
-
import { useEventTracker } from '../../composables/useEventTracker';
|
|
8
|
-
import { usePageNavigationStore } from '@shared/page-navigation/store/page-navigation-store';
|
|
9
|
-
import { useUiEditableLogoStore } from '@shared/logo-settings/store/editable-logo-store';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A single history entry. `snapshot` is JSON-stringified up-front so Pinia
|
|
13
|
-
* treats it as opaque (no per-field reactivity) and `sizeBytes` is exact.
|
|
14
|
-
* Sidecar state not in `brandPageData` rides along on this entry —
|
|
15
|
-
* `activePageId` for page-tab restore, `logoEdits` for pre-purchase logo
|
|
16
|
-
* form state.
|
|
17
|
-
*/
|
|
18
|
-
export interface HistoryEntry {
|
|
19
|
-
snapshot: string;
|
|
20
|
-
timestamp: string;
|
|
21
|
-
source: 'manual_edit' | 'template_switch' | 'ai_changeset' | 'rich_text';
|
|
22
|
-
actor: 'user' | 'ai_builder';
|
|
23
|
-
label?: string;
|
|
24
|
-
sizeBytes: number;
|
|
25
|
-
/** Active page id at capture time. Empty before first router push. */
|
|
26
|
-
activePageId: string;
|
|
27
|
-
/** JSON-stringified `editableLogoStore.logoEdits`. Undefined if logo tab never opened. */
|
|
28
|
-
logoEdits?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Monotonic burst — first mutation starts the timer, subsequent mutations
|
|
32
|
-
// don't reset it; max-wait ceiling forces a commit during continuous typing.
|
|
33
|
-
const CAPTURE_DEBOUNCE_MS = 1700;
|
|
34
|
-
const CAPTURE_MAX_WAIT_MS = 10000;
|
|
35
|
-
|
|
36
|
-
// Merge bursts flush quickly — sync hydration writes land in <50ms,
|
|
37
|
-
// user typing takes >150ms, so a short debounce keeps user input out
|
|
38
|
-
// of the merge.
|
|
39
|
-
const MERGE_DEBOUNCE_MS = 50;
|
|
40
|
-
|
|
41
|
-
// FR-12 / FR-13 / FR-13c. 25 MB per-entry accommodates a high-res BYO logo
|
|
42
|
-
// rendered into 4 viewport sections + per-page logo blocks. Oversize
|
|
43
|
-
// entries are skipped with telemetry; 100 MB total evicts oldest
|
|
44
|
-
// non-baseline entries.
|
|
45
|
-
const MAX_ENTRIES = 40;
|
|
46
|
-
const MAX_MEMORY_BYTES = 100 * 1024 * 1024;
|
|
47
|
-
const MAX_ENTRY_BYTES = 25 * 1024 * 1024;
|
|
48
|
-
|
|
49
|
-
// Window after baseline during which captured mutations REPLACE the
|
|
50
|
-
// baseline instead of pushing — covers async post-init cascades
|
|
51
|
-
// (template load, router afterEach, layout settle).
|
|
52
|
-
const BASELINE_SETTLE_MS = 2000;
|
|
53
|
-
|
|
54
|
-
export const useHistoryStore = defineStore('history', () => {
|
|
55
|
-
const eventTracker = useEventTracker();
|
|
56
|
-
|
|
57
|
-
// --- State ---
|
|
58
|
-
|
|
59
|
-
// shallowRef keeps the array reactive but prevents Pinia from proxying
|
|
60
|
-
// every entry — combined with stringified snapshots, entries are
|
|
61
|
-
// fully opaque to reactivity traversal.
|
|
62
|
-
const entries = shallowRef<HistoryEntry[]>([]);
|
|
63
|
-
const currentIndex = ref(-1); // -1 means "no baseline yet"
|
|
64
|
-
const isApplyingSnapshot = ref(false);
|
|
65
|
-
const baselineCaptured = ref(false);
|
|
66
|
-
const watcherInstalled = ref(false);
|
|
67
|
-
let baselineCapturedAt = 0;
|
|
68
|
-
|
|
69
|
-
// --- Getters ---
|
|
70
|
-
|
|
71
|
-
const canUndo = computed(() => currentIndex.value > 0);
|
|
72
|
-
const canRedo = computed(
|
|
73
|
-
() =>
|
|
74
|
-
currentIndex.value >= 0 && currentIndex.value < entries.value.length - 1,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
// --- Internals ---
|
|
78
|
-
|
|
79
|
-
// Pre-purchase only (matches the save-path strip in
|
|
80
|
-
// `brand-page-container-store.ts:805`). Each rendered base64 is ~2-4 MB
|
|
81
|
-
// across 6-8 placements, so unstripped snapshots bump the 25 MB cap.
|
|
82
|
-
// `_syncLogoSettingsFromSnapshot` repopulates on undo.
|
|
83
|
-
function stripLogoBase64IfPrePurchase(data: {
|
|
84
|
-
pages?: { contents?: { logoImageBase64Url?: string }[] }[];
|
|
85
|
-
pageHeaderDesktop?: { logoImageBase64Url?: string };
|
|
86
|
-
pageHeaderMobile?: { logoImageBase64Url?: string };
|
|
87
|
-
pageFooterDesktop?: { logoImageBase64Url?: string };
|
|
88
|
-
pageFooterMobile?: { logoImageBase64Url?: string };
|
|
89
|
-
}): void {
|
|
90
|
-
try {
|
|
91
|
-
if (!useBrandPageContainerStore().isPrePurchase) return;
|
|
92
|
-
} catch {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (data.pageHeaderDesktop) {
|
|
97
|
-
data.pageHeaderDesktop.logoImageBase64Url = undefined;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (data.pageHeaderMobile) {
|
|
101
|
-
data.pageHeaderMobile.logoImageBase64Url = undefined;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (data.pageFooterDesktop) {
|
|
105
|
-
data.pageFooterDesktop.logoImageBase64Url = undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (data.pageFooterMobile) {
|
|
109
|
-
data.pageFooterMobile.logoImageBase64Url = undefined;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (Array.isArray(data.pages)) {
|
|
113
|
-
for (const page of data.pages) {
|
|
114
|
-
if (!Array.isArray(page?.contents)) continue;
|
|
115
|
-
|
|
116
|
-
for (const content of page.contents) {
|
|
117
|
-
if (
|
|
118
|
-
content &&
|
|
119
|
-
typeof content === 'object' &&
|
|
120
|
-
'logoImageBase64Url' in content
|
|
121
|
-
) {
|
|
122
|
-
content.logoImageBase64Url = undefined;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function serializeCurrentSnapshot(): string | null {
|
|
130
|
-
try {
|
|
131
|
-
const cloned = JSON.parse(
|
|
132
|
-
JSON.stringify(toRaw(useBrandPageMakerStore().brandPageData)),
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
stripLogoBase64IfPrePurchase(cloned);
|
|
136
|
-
|
|
137
|
-
return JSON.stringify(cloned);
|
|
138
|
-
} catch (error) {
|
|
139
|
-
console.error('history-store: failed to serialize snapshot', error);
|
|
140
|
-
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function getCurrentActivePageId(): string {
|
|
146
|
-
return usePageNavigationStore().activePageId ?? '';
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function serializeCurrentLogoEdits(): string | undefined {
|
|
150
|
-
try {
|
|
151
|
-
const editableLogoStore = useUiEditableLogoStore();
|
|
152
|
-
|
|
153
|
-
return JSON.stringify(toRaw(editableLogoStore.logoEdits));
|
|
154
|
-
} catch (error) {
|
|
155
|
-
console.error('history-store: failed to serialize logoEdits', error);
|
|
156
|
-
|
|
157
|
-
return undefined;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Two-phase merge flag. Hydration write sites call `mergeNextMutation()`
|
|
162
|
-
// immediately before their imperative write, which sets `mergeArmed`.
|
|
163
|
-
// When the watcher's `scheduleAutoCapture` arms a new idle timer, it
|
|
164
|
-
// transfers `mergeArmed` into `pendingTimerIsMerge`. The flush then
|
|
165
|
-
// consumes `pendingTimerIsMerge` and merges into the current head
|
|
166
|
-
// instead of pushing.
|
|
167
|
-
//
|
|
168
|
-
// The microtask cleanup on `mergeArmed` prevents stale flags surviving
|
|
169
|
-
// when the user navigates away (e.g. sidebar tab switch) before the
|
|
170
|
-
// flagged write actually happens — a previously-set arm is dropped
|
|
171
|
-
// synchronously after the current tick if no watcher fired.
|
|
172
|
-
const mergeArmed = ref(false);
|
|
173
|
-
let pendingTimerIsMerge = false;
|
|
174
|
-
|
|
175
|
-
// Returns 'noop' when no-change vs current head, 'oversized' when over
|
|
176
|
-
// MAX_ENTRY_BYTES, else 'committed'. Truncates the redo tail, caps at
|
|
177
|
-
// MAX_ENTRIES, evicts oldest non-baseline to stay under MAX_MEMORY_BYTES.
|
|
178
|
-
// Baseline (index 0) is never evicted.
|
|
179
|
-
function commitEntry(args: {
|
|
180
|
-
snapshot: string;
|
|
181
|
-
source: HistoryEntry['source'];
|
|
182
|
-
actor: HistoryEntry['actor'];
|
|
183
|
-
label?: string;
|
|
184
|
-
activePageId: string;
|
|
185
|
-
logoEdits?: string;
|
|
186
|
-
}): 'committed' | 'oversized' | 'noop' {
|
|
187
|
-
const current = entries.value[currentIndex.value];
|
|
188
|
-
|
|
189
|
-
// Compare both snapshot AND logoEdits sidecar — pre-purchase logo
|
|
190
|
-
// edits don't change brandPageData (base64 is stripped) so the
|
|
191
|
-
// sidecar is the only signal that distinguishes them.
|
|
192
|
-
if (
|
|
193
|
-
current &&
|
|
194
|
-
current.snapshot === args.snapshot &&
|
|
195
|
-
current.logoEdits === args.logoEdits
|
|
196
|
-
) {
|
|
197
|
-
return 'noop';
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (args.snapshot.length > MAX_ENTRY_BYTES) {
|
|
201
|
-
eventTracker.sendHistoryOversizedEvent({
|
|
202
|
-
attempted_bytes: args.snapshot.length,
|
|
203
|
-
source: args.source,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
return 'oversized';
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const entry: HistoryEntry = {
|
|
210
|
-
snapshot: args.snapshot,
|
|
211
|
-
timestamp: new Date().toISOString(),
|
|
212
|
-
source: args.source,
|
|
213
|
-
actor: args.actor,
|
|
214
|
-
label: args.label,
|
|
215
|
-
sizeBytes: args.snapshot.length,
|
|
216
|
-
activePageId: args.activePageId,
|
|
217
|
-
logoEdits: args.logoEdits,
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
// FR-11: truncate redo tail, then append.
|
|
221
|
-
const next = entries.value.slice(0, currentIndex.value + 1);
|
|
222
|
-
|
|
223
|
-
next.push(entry);
|
|
224
|
-
|
|
225
|
-
// FR-12: 40-entry cap. Drop oldest non-baseline (index 1) if we'd exceed.
|
|
226
|
-
let didEvict = false;
|
|
227
|
-
|
|
228
|
-
while (next.length > MAX_ENTRIES && next.length > 1) {
|
|
229
|
-
next.splice(1, 1);
|
|
230
|
-
didEvict = true;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// FR-13: keep total serialized size under 100 MB. Drop oldest
|
|
234
|
-
// non-baseline repeatedly until under budget. Baseline alone can exceed
|
|
235
|
-
// the budget on a very large page — in that pathological case we stop
|
|
236
|
-
// evicting at length 2 (baseline + newest) rather than dropping the
|
|
237
|
-
// baseline.
|
|
238
|
-
let totalBytes = next.reduce((sum, e) => sum + e.sizeBytes, 0);
|
|
239
|
-
|
|
240
|
-
while (totalBytes > MAX_MEMORY_BYTES && next.length > 2) {
|
|
241
|
-
totalBytes -= next[1].sizeBytes;
|
|
242
|
-
next.splice(1, 1);
|
|
243
|
-
didEvict = true;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
entries.value = next;
|
|
247
|
-
currentIndex.value = next.length - 1;
|
|
248
|
-
|
|
249
|
-
if (didEvict) {
|
|
250
|
-
eventTracker.sendHistoryCappedEvent({
|
|
251
|
-
entries_count: next.length,
|
|
252
|
-
size_bytes: totalBytes,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return 'committed';
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Hoisted so force-commit paths (template switch, AI apply) can cancel
|
|
260
|
-
// any pending auto-capture that would otherwise duplicate their entry.
|
|
261
|
-
let idleTimerId: ReturnType<typeof setTimeout> | null = null;
|
|
262
|
-
let maxWaitTimerId: ReturnType<typeof setTimeout> | null = null;
|
|
263
|
-
|
|
264
|
-
function cancelPendingAutoCapture(): void {
|
|
265
|
-
if (idleTimerId !== null) {
|
|
266
|
-
clearTimeout(idleTimerId);
|
|
267
|
-
idleTimerId = null;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (maxWaitTimerId !== null) {
|
|
271
|
-
clearTimeout(maxWaitTimerId);
|
|
272
|
-
maxWaitTimerId = null;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function installWatcher(): void {
|
|
277
|
-
if (watcherInstalled.value) return;
|
|
278
|
-
|
|
279
|
-
const flush = () => {
|
|
280
|
-
cancelPendingAutoCapture();
|
|
281
|
-
|
|
282
|
-
if (isApplyingSnapshot.value) return;
|
|
283
|
-
|
|
284
|
-
if (!baselineCaptured.value) return;
|
|
285
|
-
|
|
286
|
-
const snapshot = serializeCurrentSnapshot();
|
|
287
|
-
|
|
288
|
-
if (!snapshot) return;
|
|
289
|
-
|
|
290
|
-
const activePageId = getCurrentActivePageId();
|
|
291
|
-
const logoEdits = serializeCurrentLogoEdits();
|
|
292
|
-
|
|
293
|
-
// Settle window: fold post-init reactive cascades back into the
|
|
294
|
-
// baseline so undo doesn't light up before the user has done
|
|
295
|
-
// anything.
|
|
296
|
-
const inSettleWindow =
|
|
297
|
-
currentIndex.value === 0 &&
|
|
298
|
-
Date.now() - baselineCapturedAt < BASELINE_SETTLE_MS;
|
|
299
|
-
|
|
300
|
-
// Merge: the timer that fired this flush was armed during a
|
|
301
|
-
// hydration burst — replace the current head in place instead of
|
|
302
|
-
// pushing. Consumed once.
|
|
303
|
-
const shouldMerge = pendingTimerIsMerge;
|
|
304
|
-
|
|
305
|
-
pendingTimerIsMerge = false;
|
|
306
|
-
|
|
307
|
-
if (inSettleWindow) {
|
|
308
|
-
entries.value = [
|
|
309
|
-
{
|
|
310
|
-
...entries.value[0],
|
|
311
|
-
snapshot,
|
|
312
|
-
timestamp: new Date().toISOString(),
|
|
313
|
-
sizeBytes: snapshot.length,
|
|
314
|
-
activePageId,
|
|
315
|
-
logoEdits,
|
|
316
|
-
},
|
|
317
|
-
];
|
|
318
|
-
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (shouldMerge && entries.value[currentIndex.value]) {
|
|
323
|
-
const next = entries.value.slice();
|
|
324
|
-
|
|
325
|
-
next[currentIndex.value] = {
|
|
326
|
-
...next[currentIndex.value],
|
|
327
|
-
snapshot,
|
|
328
|
-
timestamp: new Date().toISOString(),
|
|
329
|
-
sizeBytes: snapshot.length,
|
|
330
|
-
activePageId,
|
|
331
|
-
logoEdits,
|
|
332
|
-
};
|
|
333
|
-
entries.value = next;
|
|
334
|
-
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
commitEntry({
|
|
339
|
-
snapshot,
|
|
340
|
-
source: 'manual_edit',
|
|
341
|
-
actor: 'user',
|
|
342
|
-
activePageId,
|
|
343
|
-
logoEdits,
|
|
344
|
-
});
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
// Monotonic — first mutation arms; subsequent ones inside the window
|
|
348
|
-
// don't reset. Gated on isApplyingSnapshot so undo/redo don't leave
|
|
349
|
-
// a stale timer ticking. If a hydration site armed `mergeArmed`
|
|
350
|
-
// immediately before the mutation that triggered this run, transfer
|
|
351
|
-
// the intent into `pendingTimerIsMerge` so the resulting flush
|
|
352
|
-
// merges instead of commits.
|
|
353
|
-
const scheduleAutoCapture = (): void => {
|
|
354
|
-
if (isApplyingSnapshot.value) return;
|
|
355
|
-
|
|
356
|
-
if (idleTimerId !== null) return;
|
|
357
|
-
|
|
358
|
-
if (mergeArmed.value) {
|
|
359
|
-
pendingTimerIsMerge = true;
|
|
360
|
-
mergeArmed.value = false;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const idle = pendingTimerIsMerge
|
|
364
|
-
? MERGE_DEBOUNCE_MS
|
|
365
|
-
: CAPTURE_DEBOUNCE_MS;
|
|
366
|
-
|
|
367
|
-
idleTimerId = setTimeout(flush, idle);
|
|
368
|
-
maxWaitTimerId = setTimeout(flush, CAPTURE_MAX_WAIT_MS);
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
watch(() => useBrandPageMakerStore().brandPageData, scheduleAutoCapture, {
|
|
372
|
-
deep: true,
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
watcherInstalled.value = true;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// --- Actions ---
|
|
379
|
-
|
|
380
|
-
// Called once per session by BrandPageMaker.mixin.ts after
|
|
381
|
-
// setIsBrandPageLoaded(true). Installs the watcher.
|
|
382
|
-
function captureBaseline(): void {
|
|
383
|
-
if (baselineCaptured.value) return;
|
|
384
|
-
|
|
385
|
-
installWatcher();
|
|
386
|
-
|
|
387
|
-
const snapshot = serializeCurrentSnapshot();
|
|
388
|
-
|
|
389
|
-
if (!snapshot) return;
|
|
390
|
-
|
|
391
|
-
entries.value = [
|
|
392
|
-
{
|
|
393
|
-
snapshot,
|
|
394
|
-
timestamp: new Date().toISOString(),
|
|
395
|
-
source: 'manual_edit',
|
|
396
|
-
actor: 'user',
|
|
397
|
-
label: 'baseline',
|
|
398
|
-
sizeBytes: snapshot.length,
|
|
399
|
-
activePageId: getCurrentActivePageId(),
|
|
400
|
-
logoEdits: serializeCurrentLogoEdits(),
|
|
401
|
-
},
|
|
402
|
-
];
|
|
403
|
-
currentIndex.value = 0;
|
|
404
|
-
baselineCaptured.value = true;
|
|
405
|
-
baselineCapturedAt = Date.now();
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// Force-commit for non-watcher call sites (template switch, AI apply).
|
|
409
|
-
function capture(args: {
|
|
410
|
-
source: HistoryEntry['source'];
|
|
411
|
-
actor: HistoryEntry['actor'];
|
|
412
|
-
label?: string;
|
|
413
|
-
}): 'committed' | 'oversized' | 'noop' | 'skipped' {
|
|
414
|
-
if (isApplyingSnapshot.value) return 'skipped';
|
|
415
|
-
|
|
416
|
-
if (!baselineCaptured.value) return 'skipped';
|
|
417
|
-
|
|
418
|
-
const snapshot = serializeCurrentSnapshot();
|
|
419
|
-
|
|
420
|
-
if (!snapshot) return 'skipped';
|
|
421
|
-
|
|
422
|
-
return commitEntry({
|
|
423
|
-
snapshot,
|
|
424
|
-
activePageId: getCurrentActivePageId(),
|
|
425
|
-
logoEdits: serializeCurrentLogoEdits(),
|
|
426
|
-
...args,
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// Cancel pending auto-capture so the forced entry doesn't duplicate
|
|
431
|
-
// with the watcher's eventual flush.
|
|
432
|
-
function captureTemplateSwitch(
|
|
433
|
-
label?: string,
|
|
434
|
-
): 'committed' | 'oversized' | 'noop' | 'skipped' {
|
|
435
|
-
cancelPendingAutoCapture();
|
|
436
|
-
|
|
437
|
-
return capture({ source: 'template_switch', actor: 'user', label });
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
function captureAiChangeset(
|
|
441
|
-
label?: string,
|
|
442
|
-
): 'committed' | 'oversized' | 'noop' | 'skipped' {
|
|
443
|
-
cancelPendingAutoCapture();
|
|
444
|
-
|
|
445
|
-
return capture({ source: 'ai_changeset', actor: 'ai_builder', label });
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// Active-page resolution priority:
|
|
449
|
-
// 1. Diff `cameFromIndex` against target — pages present in target
|
|
450
|
-
// but absent from source are being restored/added; navigate there
|
|
451
|
-
// (undo-of-delete, redo-of-add).
|
|
452
|
-
// 2. Walk back from targetIndex for the closest entry whose
|
|
453
|
-
// activePageId still exists (undo-of-add and non-page edits).
|
|
454
|
-
async function applySnapshotString(
|
|
455
|
-
snapshotStr: string,
|
|
456
|
-
targetIndex: number,
|
|
457
|
-
cameFromIndex: number,
|
|
458
|
-
): Promise<void> {
|
|
459
|
-
const brandPageMakerStore = useBrandPageMakerStore();
|
|
460
|
-
|
|
461
|
-
let snapshot: BrandPageModel;
|
|
462
|
-
|
|
463
|
-
try {
|
|
464
|
-
snapshot = JSON.parse(snapshotStr) as BrandPageModel;
|
|
465
|
-
} catch (error) {
|
|
466
|
-
console.error('history-store: failed to parse snapshot', error);
|
|
467
|
-
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
const restoredPageIds = new Set<string>();
|
|
472
|
-
|
|
473
|
-
snapshot.pages?.forEach((p) => {
|
|
474
|
-
if (p?.id) restoredPageIds.add(p.id);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
let resolvedActivePageId: string | undefined;
|
|
478
|
-
|
|
479
|
-
// Step 1: diff cameFromIndex → first page absent from source wins.
|
|
480
|
-
const sourceEntry = entries.value[cameFromIndex];
|
|
481
|
-
|
|
482
|
-
if (sourceEntry) {
|
|
483
|
-
const sourcePageIds = new Set<string>();
|
|
484
|
-
|
|
485
|
-
try {
|
|
486
|
-
const sourceSnap = JSON.parse(sourceEntry.snapshot) as BrandPageModel;
|
|
487
|
-
|
|
488
|
-
sourceSnap.pages?.forEach((p) => {
|
|
489
|
-
if (p?.id) sourcePageIds.add(p.id);
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
for (const p of snapshot.pages ?? []) {
|
|
493
|
-
if (p?.id && !sourcePageIds.has(p.id)) {
|
|
494
|
-
resolvedActivePageId = p.id;
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
} catch {
|
|
499
|
-
// Source snapshot unparseable — fall through to walk-back.
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// Step 2: walk-back fallback for non-page-structural edits.
|
|
504
|
-
if (!resolvedActivePageId) {
|
|
505
|
-
for (let i = targetIndex; i >= 0; i--) {
|
|
506
|
-
const candidate = entries.value[i]?.activePageId;
|
|
507
|
-
|
|
508
|
-
if (candidate && restoredPageIds.has(candidate)) {
|
|
509
|
-
resolvedActivePageId = candidate;
|
|
510
|
-
break;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
const targetEntry = entries.value[targetIndex];
|
|
516
|
-
|
|
517
|
-
isApplyingSnapshot.value = true;
|
|
518
|
-
// Clear any unconsumed merge intent — a stale flag would fold the
|
|
519
|
-
// post-apply tick into the restored entry and erase the redo.
|
|
520
|
-
mergeArmed.value = false;
|
|
521
|
-
pendingTimerIsMerge = false;
|
|
522
|
-
cancelPendingAutoCapture();
|
|
523
|
-
|
|
524
|
-
try {
|
|
525
|
-
await brandPageMakerStore.applyHistorySnapshot(
|
|
526
|
-
snapshot,
|
|
527
|
-
resolvedActivePageId,
|
|
528
|
-
targetEntry?.logoEdits,
|
|
529
|
-
);
|
|
530
|
-
} finally {
|
|
531
|
-
isApplyingSnapshot.value = false;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
async function undo(): Promise<void> {
|
|
536
|
-
if (!canUndo.value) return;
|
|
537
|
-
|
|
538
|
-
const aiThreadStore = useAiWebsiteBuilderThreadStore();
|
|
539
|
-
|
|
540
|
-
if (aiThreadStore.isProcessing) return;
|
|
541
|
-
|
|
542
|
-
// Actor of the entry being undone (the one we're leaving).
|
|
543
|
-
const undoneActor = entries.value[currentIndex.value]?.actor;
|
|
544
|
-
const cameFromIndex = currentIndex.value;
|
|
545
|
-
|
|
546
|
-
currentIndex.value -= 1;
|
|
547
|
-
const target = entries.value[currentIndex.value];
|
|
548
|
-
|
|
549
|
-
if (target) {
|
|
550
|
-
await applySnapshotString(
|
|
551
|
-
target.snapshot,
|
|
552
|
-
currentIndex.value,
|
|
553
|
-
cameFromIndex,
|
|
554
|
-
);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
eventTracker.sendUndoEvent({
|
|
558
|
-
entries_count: entries.value.length,
|
|
559
|
-
actor: undoneActor,
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
async function redo(): Promise<void> {
|
|
564
|
-
if (!canRedo.value) return;
|
|
565
|
-
|
|
566
|
-
const aiThreadStore = useAiWebsiteBuilderThreadStore();
|
|
567
|
-
|
|
568
|
-
if (aiThreadStore.isProcessing) return;
|
|
569
|
-
|
|
570
|
-
const cameFromIndex = currentIndex.value;
|
|
571
|
-
|
|
572
|
-
currentIndex.value += 1;
|
|
573
|
-
const target = entries.value[currentIndex.value];
|
|
574
|
-
|
|
575
|
-
if (target) {
|
|
576
|
-
await applySnapshotString(
|
|
577
|
-
target.snapshot,
|
|
578
|
-
currentIndex.value,
|
|
579
|
-
cameFromIndex,
|
|
580
|
-
);
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
eventTracker.sendRedoEvent({
|
|
584
|
-
entries_count: entries.value.length,
|
|
585
|
-
actor: target?.actor,
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// PRD §3: undo history resets on save/publish. Called by
|
|
590
|
-
// brand-page-container-store.saveBrandPage. No-ops when no baseline
|
|
591
|
-
// exists — unflagged sessions never installed the watcher.
|
|
592
|
-
function reset(): void {
|
|
593
|
-
if (!baselineCaptured.value) return;
|
|
594
|
-
|
|
595
|
-
cancelPendingAutoCapture();
|
|
596
|
-
mergeArmed.value = false;
|
|
597
|
-
pendingTimerIsMerge = false;
|
|
598
|
-
|
|
599
|
-
entries.value = [];
|
|
600
|
-
currentIndex.value = -1;
|
|
601
|
-
baselineCaptured.value = false;
|
|
602
|
-
baselineCapturedAt = 0;
|
|
603
|
-
|
|
604
|
-
captureBaseline();
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// Hydration write sites call this immediately before their imperative
|
|
608
|
-
// mutation. The arm is auto-cleared on the next Vue tick — `nextTick`
|
|
609
|
-
// runs AFTER all queued reactive effects (including the watcher), so
|
|
610
|
-
// if the hydration write triggered `scheduleAutoCapture`, the arm has
|
|
611
|
-
// already been transferred into `pendingTimerIsMerge` before this
|
|
612
|
-
// cleanup fires. If no mutation followed (e.g. the user navigated
|
|
613
|
-
// away before the flagged write), the cleanup drops the stale arm so
|
|
614
|
-
// it can't be consumed by an unrelated future mutation.
|
|
615
|
-
function mergeNextMutation(): void {
|
|
616
|
-
mergeArmed.value = true;
|
|
617
|
-
// setTimeout(0) is a macrotask — runs AFTER the synchronous write
|
|
618
|
-
// and AFTER Vue's microtask flush of the watcher's reactive effect.
|
|
619
|
-
// If `scheduleAutoCapture` fired in between (the imperative write
|
|
620
|
-
// triggered the watcher), the arm has already been transferred into
|
|
621
|
-
// `pendingTimerIsMerge` before this cleanup runs.
|
|
622
|
-
setTimeout(() => {
|
|
623
|
-
mergeArmed.value = false;
|
|
624
|
-
}, 0);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// --- Instrumentation (NFR-04a) ---
|
|
628
|
-
|
|
629
|
-
function getCurrentSizeBytes(): number {
|
|
630
|
-
return entries.value.reduce((sum, e) => sum + e.sizeBytes, 0);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
function getCurrentEntryCount(): number {
|
|
634
|
-
return entries.value.length;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
return {
|
|
638
|
-
// State
|
|
639
|
-
entries,
|
|
640
|
-
currentIndex,
|
|
641
|
-
isApplyingSnapshot,
|
|
642
|
-
baselineCaptured,
|
|
643
|
-
|
|
644
|
-
// Getters
|
|
645
|
-
canUndo,
|
|
646
|
-
canRedo,
|
|
647
|
-
|
|
648
|
-
// Actions
|
|
649
|
-
captureBaseline,
|
|
650
|
-
capture,
|
|
651
|
-
captureTemplateSwitch,
|
|
652
|
-
captureAiChangeset,
|
|
653
|
-
mergeNextMutation,
|
|
654
|
-
undo,
|
|
655
|
-
redo,
|
|
656
|
-
reset,
|
|
657
|
-
getCurrentSizeBytes,
|
|
658
|
-
getCurrentEntryCount,
|
|
659
|
-
};
|
|
660
|
-
});
|