@designcrowd/library.brand-page 5.18.1-undo-22 → 5.18.1-undo-23
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-Q1oYxhFA.js → CreatedOnBrandCrowd-de-de-AFaRM8AB.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-en-us-QDl7ywkQ.js → CreatedOnBrandCrowd-en-us-Hzq-a60h.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-es-es-DcbldLR8.js → CreatedOnBrandCrowd-es-es-JcJzcPt4.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-fr-CtKg-kmK.js → CreatedOnBrandCrowd-fr-ca-BvfD6_cT.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-ca-CtKg-kmK.js → CreatedOnBrandCrowd-fr-fr-BvfD6_cT.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-pt-B8LdULlM.js → CreatedOnBrandCrowd-pt-br-CvCBHtHz.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-br-B8LdULlM.js → CreatedOnBrandCrowd-pt-pt-CvCBHtHz.js} +1 -1
- package/lib/src/{CreatedOnDcom-de-de-B8a5JB3V.js → CreatedOnDcom-de-de-DY72j1HT.js} +1 -1
- package/lib/src/{CreatedOnDcom-en-us-BxJb4VxH.js → CreatedOnDcom-en-us-CQlkVR3f.js} +1 -1
- package/lib/src/{CreatedOnDcom-es-es-_YCAGVL0.js → CreatedOnDcom-es-es-B308Qq0k.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-ca-DV5JKmY0.js → CreatedOnDcom-fr-ca-CmZfNZDD.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-fr-CjGeFt2Y.js → CreatedOnDcom-fr-fr-YEMbYuns.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-br-fPa9wQ6j.js → CreatedOnDcom-pt-br-DC06ZQTq.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-pt-BEC57JU6.js → CreatedOnDcom-pt-pt-gbUCpWPU.js} +1 -1
- package/lib/src/brand-page-maker/components/action-bar/ActionBar.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/components/brand-page-maker/BrandPageMakerTemplateSettings.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/components/brandpage-maker-page/BrandPageMakerPage.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/components/brandpage-settings/ReplaceImageSettingsForBrandPageSettings.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/components/seo-settings/SeoPageSettings.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/components/seo-settings/UrlSettings.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/components/social-share/SocialShare.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/components/template-preview/TemplatePreview.mixin.d.ts +2 -2
- package/lib/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.d.ts +2 -2
- package/lib/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.js +33 -4
- package/lib/src/brand-page-maker/stores/history/history-store.d.ts +17 -1
- package/lib/src/brand-page-maker/stores/history/history-store.js +71 -27
- package/lib/src/index.mjs +1 -1
- package/lib/src/{lib-BxlBHrQd.js → lib-gUHeBTLS.js} +8581 -8547
- package/lib/src/shared/content-settings/components/content-settings/ContentSettings.mixin.d.ts +2 -2
- package/lib/src/shared/content-settings/components/content-settings/ReplaceImageSettingsForContent.mixin.d.ts +2 -2
- package/lib/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.d.ts +2 -2
- package/lib/src/shared/logo-settings/components/LogoSettings.mixin.d.ts +2 -2
- package/lib/src/shared/page-settings/components/page-settings/PageSettings.mixin.d.ts +2 -2
- package/lib/src/shared/page-settings/components/page-settings-section-styles/PageSettingsSectionStyles.mixin.d.ts +2 -2
- package/lib/src/shared/publish-brand-page-with-state/PublishBrandPageModalWithState.mixin.d.ts +2 -2
- package/lib/src/shared/style-settings/components/StyleSettings.mixin.d.ts +2 -2
- package/package.json +1 -1
- package/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.test.ts +169 -0
- package/src/brand-page-maker/stores/brandpage-maker/brandpage-maker-store.ts +40 -3
- package/src/brand-page-maker/stores/history/history-store.test.ts +240 -11
- package/src/brand-page-maker/stores/history/history-store.ts +97 -27
|
@@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
|
2
2
|
import { createPinia, setActivePinia } from 'pinia';
|
|
3
3
|
import { useHistoryStore } from './history-store';
|
|
4
4
|
import { useEventTracker } from '../../composables/useEventTracker';
|
|
5
|
+
import { useUiEditableLogoStore } from '@shared/logo-settings/store/editable-logo-store';
|
|
5
6
|
import type { BrandPageModel } from '@brand-page';
|
|
6
7
|
|
|
7
8
|
// Shared mock maker store — methods are vi.fn() so we can assert calls.
|
|
@@ -306,15 +307,16 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
306
307
|
expect(store.entries.length).toBe(2);
|
|
307
308
|
});
|
|
308
309
|
|
|
309
|
-
// BP-5506 follow-up: editing logo text via the Logo sidebar
|
|
310
|
-
// `editableLogoStore.logoEdits` (
|
|
311
|
-
//
|
|
312
|
-
// per-page logo content.
|
|
313
|
-
//
|
|
314
|
-
//
|
|
315
|
-
//
|
|
316
|
-
//
|
|
317
|
-
|
|
310
|
+
// BP-5506 follow-up: editing logo text/colors/font via the Logo sidebar
|
|
311
|
+
// mutates `editableLogoStore.logoEdits` (sidecar — captured on the
|
|
312
|
+
// history entry's `logoEdits` field) AND re-renders the result into
|
|
313
|
+
// `logoImageBase64Url` on every header/footer + per-page logo content.
|
|
314
|
+
// The base64 IS the canonical signal that a logo edit happened, so it
|
|
315
|
+
// MUST commit. Restoring the sidebar form fields on undo is handled by
|
|
316
|
+
// `_syncLogoSettingsFromSnapshot` reading the per-entry `logoEdits`
|
|
317
|
+
// sidecar — without committing on a base64 diff, the watcher would
|
|
318
|
+
// never produce that entry in the first place.
|
|
319
|
+
it('commits when logoImageBase64Url changes (logo property edit)', async () => {
|
|
318
320
|
const store = useHistoryStore();
|
|
319
321
|
|
|
320
322
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -346,8 +348,8 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
346
348
|
|
|
347
349
|
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
348
350
|
|
|
349
|
-
expect(result).toBe('
|
|
350
|
-
expect(store.entries.length).toBe(
|
|
351
|
+
expect(result).toBe('committed');
|
|
352
|
+
expect(store.entries.length).toBe(2);
|
|
351
353
|
});
|
|
352
354
|
|
|
353
355
|
// BYO-upload undo MUST still work — that diff is in
|
|
@@ -708,6 +710,92 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
708
710
|
expect(result).toBe('committed');
|
|
709
711
|
expect(store.entries.length).toBe(2);
|
|
710
712
|
});
|
|
713
|
+
|
|
714
|
+
// BP-5506 follow-up: stored content uses the codebase's URL-encoded
|
|
715
|
+
// newline (`ESCAPED_NEWLINE_CHARACTER` = `%0A`). On first canvas/section
|
|
716
|
+
// interaction, TipTap mounts and re-emits the same content with `<br>`
|
|
717
|
+
// in place of each `%0A`. Same logical text, no user edit — dedup must
|
|
718
|
+
// collapse.
|
|
719
|
+
it('treats %0A → <br> hydration as a no-op', async () => {
|
|
720
|
+
const store = useHistoryStore();
|
|
721
|
+
|
|
722
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
723
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
724
|
+
{
|
|
725
|
+
contents: [
|
|
726
|
+
{
|
|
727
|
+
type: 'banner',
|
|
728
|
+
description:
|
|
729
|
+
'WARNING: our business is a rocketship and it is about to take flight%0A%0A',
|
|
730
|
+
successMessage:
|
|
731
|
+
'Thank you for reaching out!%0A%0AWe will get back to you shortly.',
|
|
732
|
+
},
|
|
733
|
+
],
|
|
734
|
+
},
|
|
735
|
+
];
|
|
736
|
+
await store.captureBaseline();
|
|
737
|
+
|
|
738
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
739
|
+
const c = (mockMakerStore.brandPageData as any).pages[0].contents[0];
|
|
740
|
+
|
|
741
|
+
c.description =
|
|
742
|
+
'<p style="text-align: center;"><span style="font-size: 1.5em; line-height: 1.5;">WARNING: our business is a rocketship and it is about to take flight<br><br></span></p>';
|
|
743
|
+
c.successMessage =
|
|
744
|
+
'<p><span style="color: red;">Thank you for reaching out!<br><br>We will get back to you shortly.</span></p>';
|
|
745
|
+
|
|
746
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
747
|
+
|
|
748
|
+
expect(result).toBe('noop');
|
|
749
|
+
expect(store.entries.length).toBe(1);
|
|
750
|
+
});
|
|
751
|
+
|
|
752
|
+
// Adversarial: a real user edit that adds a hard break where there was
|
|
753
|
+
// none before MUST surface as a real diff. The collapse rule is bidirectional
|
|
754
|
+
// (`%0A` ↔ `<br>`), but adding a newline to a previously-newline-free string
|
|
755
|
+
// is still a real edit.
|
|
756
|
+
it('still commits when an edit adds a new <br> where none existed', async () => {
|
|
757
|
+
const store = useHistoryStore();
|
|
758
|
+
|
|
759
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
760
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
761
|
+
{
|
|
762
|
+
contents: [{ type: 'banner', description: 'A B' }],
|
|
763
|
+
},
|
|
764
|
+
];
|
|
765
|
+
await store.captureBaseline();
|
|
766
|
+
|
|
767
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
768
|
+
(mockMakerStore.brandPageData as any).pages[0].contents[0].description =
|
|
769
|
+
'<p><span>A<br><br>B</span></p>';
|
|
770
|
+
|
|
771
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
772
|
+
|
|
773
|
+
expect(result).toBe('committed');
|
|
774
|
+
expect(store.entries.length).toBe(2);
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
// Adversarial: <br> with attributes is not part of TipTap's hydration
|
|
778
|
+
// shape — preserve as a real diff.
|
|
779
|
+
it('still commits when an edit adds a <br> carrying attributes', async () => {
|
|
780
|
+
const store = useHistoryStore();
|
|
781
|
+
|
|
782
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
783
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
784
|
+
{
|
|
785
|
+
contents: [{ type: 'banner', description: 'A%0AB' }],
|
|
786
|
+
},
|
|
787
|
+
];
|
|
788
|
+
await store.captureBaseline();
|
|
789
|
+
|
|
790
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
791
|
+
(mockMakerStore.brandPageData as any).pages[0].contents[0].description =
|
|
792
|
+
'<p><span>A<br data-x="y">B</span></p>';
|
|
793
|
+
|
|
794
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
795
|
+
|
|
796
|
+
expect(result).toBe('committed');
|
|
797
|
+
expect(store.entries.length).toBe(2);
|
|
798
|
+
});
|
|
711
799
|
});
|
|
712
800
|
|
|
713
801
|
it('reentrancy guard: capture no-ops when isApplyingSnapshot is true', async () => {
|
|
@@ -767,9 +855,11 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
767
855
|
// Undo restores the baseline snapshot — the parsed BrandPageModel must
|
|
768
856
|
// round-trip back through applyHistorySnapshot. Second arg is the
|
|
769
857
|
// resolved activePageId (undefined here because no entry has one).
|
|
858
|
+
// Third arg is the captured logoEdits JSON sidecar.
|
|
770
859
|
expect(mockMakerStore.applyHistorySnapshot).toHaveBeenCalledWith(
|
|
771
860
|
expect.objectContaining(baselineBrandPageData),
|
|
772
861
|
undefined,
|
|
862
|
+
expect.any(String),
|
|
773
863
|
);
|
|
774
864
|
});
|
|
775
865
|
|
|
@@ -1031,6 +1121,7 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
1031
1121
|
expect(mockMakerStore.applyHistorySnapshot).toHaveBeenCalledWith(
|
|
1032
1122
|
expect.anything(),
|
|
1033
1123
|
'page-home',
|
|
1124
|
+
expect.any(String),
|
|
1034
1125
|
);
|
|
1035
1126
|
});
|
|
1036
1127
|
|
|
@@ -1064,6 +1155,7 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
1064
1155
|
expect(mockMakerStore.applyHistorySnapshot).toHaveBeenCalledWith(
|
|
1065
1156
|
expect.anything(),
|
|
1066
1157
|
'page-home',
|
|
1158
|
+
expect.any(String),
|
|
1067
1159
|
);
|
|
1068
1160
|
});
|
|
1069
1161
|
|
|
@@ -1104,6 +1196,7 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
1104
1196
|
expect(mockMakerStore.applyHistorySnapshot).toHaveBeenCalledWith(
|
|
1105
1197
|
expect.anything(),
|
|
1106
1198
|
'page-about',
|
|
1199
|
+
expect.any(String),
|
|
1107
1200
|
);
|
|
1108
1201
|
});
|
|
1109
1202
|
|
|
@@ -1140,6 +1233,7 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
1140
1233
|
expect(mockMakerStore.applyHistorySnapshot).toHaveBeenCalledWith(
|
|
1141
1234
|
expect.anything(),
|
|
1142
1235
|
'page-new',
|
|
1236
|
+
expect.any(String),
|
|
1143
1237
|
);
|
|
1144
1238
|
});
|
|
1145
1239
|
|
|
@@ -1172,6 +1266,7 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
1172
1266
|
expect(mockMakerStore.applyHistorySnapshot).toHaveBeenCalledWith(
|
|
1173
1267
|
expect.anything(),
|
|
1174
1268
|
'page-home',
|
|
1269
|
+
expect.any(String),
|
|
1175
1270
|
);
|
|
1176
1271
|
|
|
1177
1272
|
// Now redo. Pointer moves forward to entry 1 (page-x captured),
|
|
@@ -1181,6 +1276,7 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
1181
1276
|
expect(mockMakerStore.applyHistorySnapshot).toHaveBeenCalledWith(
|
|
1182
1277
|
expect.anything(),
|
|
1183
1278
|
'page-x',
|
|
1279
|
+
expect.any(String),
|
|
1184
1280
|
);
|
|
1185
1281
|
});
|
|
1186
1282
|
});
|
|
@@ -1243,4 +1339,137 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
1243
1339
|
expect(store.currentIndex).toBe(-1);
|
|
1244
1340
|
});
|
|
1245
1341
|
});
|
|
1342
|
+
|
|
1343
|
+
// BP-5506 follow-up: pre-purchase logo-tab edits (template switch, logo
|
|
1344
|
+
// colors, logo text, support text) author through `editableLogoStore.logoEdits`,
|
|
1345
|
+
// a sidecar that's NOT in `brandPageData`. The history entry carries a
|
|
1346
|
+
// `logoEdits` JSON sidecar — captured at the same instant as the snapshot,
|
|
1347
|
+
// applied on undo via `_syncLogoSettingsFromSnapshot`. Without this,
|
|
1348
|
+
// save-after-undo would re-derive metadata from the post-edit `logoEdits`
|
|
1349
|
+
// and silently reapply the change the user undid.
|
|
1350
|
+
describe('logoEdits sidecar capture', () => {
|
|
1351
|
+
it('stashes editableLogoStore.logoEdits as a JSON string on baseline', async () => {
|
|
1352
|
+
const editableLogoStore = useUiEditableLogoStore();
|
|
1353
|
+
|
|
1354
|
+
editableLogoStore.logoEdits.textObjects = [
|
|
1355
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1356
|
+
{
|
|
1357
|
+
id: 't1',
|
|
1358
|
+
role: 'primary-text',
|
|
1359
|
+
text: 'Acme',
|
|
1360
|
+
textEnabled: true,
|
|
1361
|
+
} as any,
|
|
1362
|
+
];
|
|
1363
|
+
|
|
1364
|
+
const store = useHistoryStore();
|
|
1365
|
+
|
|
1366
|
+
await store.captureBaseline();
|
|
1367
|
+
|
|
1368
|
+
const stashed = store.entries[0].logoEdits;
|
|
1369
|
+
|
|
1370
|
+
expect(typeof stashed).toBe('string');
|
|
1371
|
+
|
|
1372
|
+
const parsed = JSON.parse(stashed!);
|
|
1373
|
+
|
|
1374
|
+
expect(parsed.textObjects).toEqual([
|
|
1375
|
+
{ id: 't1', role: 'primary-text', text: 'Acme', textEnabled: true },
|
|
1376
|
+
]);
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
it('captures distinct logoEdits per entry as the user edits', async () => {
|
|
1380
|
+
const editableLogoStore = useUiEditableLogoStore();
|
|
1381
|
+
|
|
1382
|
+
editableLogoStore.logoEdits.textObjects = [
|
|
1383
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1384
|
+
{
|
|
1385
|
+
id: 't1',
|
|
1386
|
+
role: 'primary-text',
|
|
1387
|
+
text: 'Acme',
|
|
1388
|
+
textEnabled: true,
|
|
1389
|
+
} as any,
|
|
1390
|
+
];
|
|
1391
|
+
|
|
1392
|
+
const store = useHistoryStore();
|
|
1393
|
+
|
|
1394
|
+
await store.captureBaseline();
|
|
1395
|
+
|
|
1396
|
+
// User types into the logo-text input — `logoEdits.textObjects[0].text`
|
|
1397
|
+
// mutates and `updateEditableLogoImageUrlAsync` writes new base64 into
|
|
1398
|
+
// brandPageData. The base64 mutation is what triggers the watcher; we
|
|
1399
|
+
// simulate by also bumping `v` so the snapshot bytes change.
|
|
1400
|
+
editableLogoStore.logoEdits.textObjects[0].text = 'AcmeCo';
|
|
1401
|
+
captureMutated(store);
|
|
1402
|
+
|
|
1403
|
+
const baselineLogoEdits = JSON.parse(store.entries[0].logoEdits!);
|
|
1404
|
+
const editLogoEdits = JSON.parse(store.entries[1].logoEdits!);
|
|
1405
|
+
|
|
1406
|
+
expect(baselineLogoEdits.textObjects[0].text).toBe('Acme');
|
|
1407
|
+
expect(editLogoEdits.textObjects[0].text).toBe('AcmeCo');
|
|
1408
|
+
});
|
|
1409
|
+
|
|
1410
|
+
it('forwards captured logoEdits to applyHistorySnapshot on undo', async () => {
|
|
1411
|
+
const editableLogoStore = useUiEditableLogoStore();
|
|
1412
|
+
|
|
1413
|
+
editableLogoStore.logoEdits.textObjects = [
|
|
1414
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1415
|
+
{
|
|
1416
|
+
id: 't1',
|
|
1417
|
+
role: 'primary-text',
|
|
1418
|
+
text: 'Acme',
|
|
1419
|
+
textEnabled: true,
|
|
1420
|
+
} as any,
|
|
1421
|
+
];
|
|
1422
|
+
|
|
1423
|
+
const store = useHistoryStore();
|
|
1424
|
+
|
|
1425
|
+
await store.captureBaseline();
|
|
1426
|
+
|
|
1427
|
+
editableLogoStore.logoEdits.textObjects[0].text = 'AcmeCo';
|
|
1428
|
+
captureMutated(store);
|
|
1429
|
+
|
|
1430
|
+
mockMakerStore.applyHistorySnapshot.mockClear();
|
|
1431
|
+
await store.undo();
|
|
1432
|
+
|
|
1433
|
+
// Third arg is the entry's `logoEdits` — undo should hand the
|
|
1434
|
+
// baseline's pre-edit blob back to the maker store.
|
|
1435
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1436
|
+
const callArgs = mockMakerStore.applyHistorySnapshot.mock
|
|
1437
|
+
.calls[0] as any[];
|
|
1438
|
+
const passedLogoEdits = JSON.parse(callArgs[2]);
|
|
1439
|
+
|
|
1440
|
+
expect(passedLogoEdits.textObjects[0].text).toBe('Acme');
|
|
1441
|
+
});
|
|
1442
|
+
|
|
1443
|
+
it('forwards the post-edit logoEdits on redo', async () => {
|
|
1444
|
+
const editableLogoStore = useUiEditableLogoStore();
|
|
1445
|
+
|
|
1446
|
+
editableLogoStore.logoEdits.textObjects = [
|
|
1447
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1448
|
+
{
|
|
1449
|
+
id: 't1',
|
|
1450
|
+
role: 'primary-text',
|
|
1451
|
+
text: 'Acme',
|
|
1452
|
+
textEnabled: true,
|
|
1453
|
+
} as any,
|
|
1454
|
+
];
|
|
1455
|
+
|
|
1456
|
+
const store = useHistoryStore();
|
|
1457
|
+
|
|
1458
|
+
await store.captureBaseline();
|
|
1459
|
+
|
|
1460
|
+
editableLogoStore.logoEdits.textObjects[0].text = 'AcmeCo';
|
|
1461
|
+
captureMutated(store);
|
|
1462
|
+
|
|
1463
|
+
await store.undo();
|
|
1464
|
+
mockMakerStore.applyHistorySnapshot.mockClear();
|
|
1465
|
+
await store.redo();
|
|
1466
|
+
|
|
1467
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1468
|
+
const callArgs = mockMakerStore.applyHistorySnapshot.mock
|
|
1469
|
+
.calls[0] as any[];
|
|
1470
|
+
const passedLogoEdits = JSON.parse(callArgs[2]);
|
|
1471
|
+
|
|
1472
|
+
expect(passedLogoEdits.textObjects[0].text).toBe('AcmeCo');
|
|
1473
|
+
});
|
|
1474
|
+
});
|
|
1246
1475
|
});
|
|
@@ -5,6 +5,8 @@ import { useBrandPageMakerStore } from '../brandpage-maker/brandpage-maker-store
|
|
|
5
5
|
import { useAiWebsiteBuilderThreadStore } from '../ai-thread/ai-website-builder-thread-store';
|
|
6
6
|
import { useEventTracker } from '../../composables/useEventTracker';
|
|
7
7
|
import { usePageNavigationStore } from '@shared/page-navigation/store/page-navigation-store';
|
|
8
|
+
import { useUiEditableLogoStore } from '@shared/logo-settings/store/editable-logo-store';
|
|
9
|
+
import { ESCAPED_NEWLINE_CHARACTER } from '@src/constants/ui';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* A single history entry.
|
|
@@ -21,7 +23,10 @@ import { usePageNavigationStore } from '@shared/page-navigation/store/page-navig
|
|
|
21
23
|
* the Logo sidebar, the active `logoTemplateAsset`, the active
|
|
22
24
|
* `logoDraftToken`) is restored on undo by `_syncLogoSettingsFromSnapshot`
|
|
23
25
|
* via per-draft-token caches on the logo / editable-logo stores — keyed off
|
|
24
|
-
* `logoImage.logoDraftToken` which IS in the snapshot.
|
|
26
|
+
* `logoImage.logoDraftToken` which IS in the snapshot. Pre-purchase logo-tab
|
|
27
|
+
* property edits (text, support text, logo colors, font, outline, shadow)
|
|
28
|
+
* live on `editableLogoStore.logoEdits` and ride along on the `logoEdits`
|
|
29
|
+
* sidecar below.
|
|
25
30
|
*/
|
|
26
31
|
export interface HistoryEntry {
|
|
27
32
|
/** JSON.stringify(BrandPageModel) at the moment of capture. */
|
|
@@ -54,6 +59,20 @@ export interface HistoryEntry {
|
|
|
54
59
|
* first router push). Always a real id once the editor has settled.
|
|
55
60
|
*/
|
|
56
61
|
activePageId: string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* `JSON.stringify(editableLogoStore.logoEdits)` at the moment of capture.
|
|
65
|
+
* Sidecar — `logoEdits` is NOT part of `brandPageData` but its state
|
|
66
|
+
* (logo text, support text, logo colors, fonts, outlines, shadows) drives
|
|
67
|
+
* what the pre-purchase save path POSTs to fabric-render to regenerate
|
|
68
|
+
* the persisted draft metadata. Without restoring it on undo, save after
|
|
69
|
+
* an undo would re-derive metadata from the post-edit `logoEdits` and
|
|
70
|
+
* silently reapply the change the user just undid.
|
|
71
|
+
*
|
|
72
|
+
* Undefined for sessions where the editable-logo store has never been
|
|
73
|
+
* touched (no logo tab interaction yet) — restore is a no-op in that case.
|
|
74
|
+
*/
|
|
75
|
+
logoEdits?: string;
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
/**
|
|
@@ -161,6 +180,23 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
161
180
|
return usePageNavigationStore().activePageId ?? '';
|
|
162
181
|
}
|
|
163
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Serialize the current `editableLogoStore.logoEdits` as a sidecar to the
|
|
185
|
+
* snapshot — see `HistoryEntry.logoEdits`. Returns undefined when the
|
|
186
|
+
* editable-logo store hasn't initialized yet (no logo tab interaction).
|
|
187
|
+
*/
|
|
188
|
+
function serializeCurrentLogoEdits(): string | undefined {
|
|
189
|
+
try {
|
|
190
|
+
const editableLogoStore = useUiEditableLogoStore();
|
|
191
|
+
|
|
192
|
+
return JSON.stringify(toRaw(editableLogoStore.logoEdits));
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error('history-store: failed to serialize logoEdits', error);
|
|
195
|
+
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
164
200
|
/**
|
|
165
201
|
* Normalize a snapshot for the dedup byte-compare. Strips/canonicalizes
|
|
166
202
|
* fields that get mutated by sidebar-open reactive cascades but aren't
|
|
@@ -176,6 +212,11 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
176
212
|
* to mirror the resolved `textStyle.fontWeight / fontStyle /
|
|
177
213
|
* textDecoration` (e.g. plain `"text"` →
|
|
178
214
|
* `<p>...<span>...<strong>text</strong></span></p>`).
|
|
215
|
+
* - TipTap rendering the codebase's URL-encoded newline
|
|
216
|
+
* (`ESCAPED_NEWLINE_CHARACTER` = `%0A`) as `<br>` on first hydration
|
|
217
|
+
* (e.g. plain `"A%0AB"` → `<p><span>A<br>B</span></p>`). Plain-side
|
|
218
|
+
* `%0A` is decoded to `\n` and attributeless `<br>` is collapsed to
|
|
219
|
+
* `\n` in `extractCanonicalText`, so the two sides converge.
|
|
179
220
|
* - Lazy hydration of `*Style` objects when a content settings panel —
|
|
180
221
|
* or section selection on the canvas — resolves `textStyleType` and
|
|
181
222
|
* writes the full resolved style (fontFamily, fontSize, color,
|
|
@@ -183,12 +224,16 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
183
224
|
* onto the model. The `textStyleType` itself is the authoring
|
|
184
225
|
* intent; the resolved keys are just cached values.
|
|
185
226
|
* - `isModifiedAfterTemplateApplied` flipping on first edit gesture.
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
227
|
+
*
|
|
228
|
+
* Note: `logoImageBase64Url` (the rendered logo PNG) is NOT stripped here.
|
|
229
|
+
* Pre-purchase logo-tab edits (text, support text, logo colors, fonts)
|
|
230
|
+
* land in `editableLogoStore.logoEdits` (sidecar — see
|
|
231
|
+
* `HistoryEntry.logoEdits`) AND trigger a fabric-render that writes the
|
|
232
|
+
* new base64 into `pageHeaderDesktop.logoImageBase64Url` + per-page
|
|
233
|
+
* logo content. The base64 IS the canonical signal that a logo edit
|
|
234
|
+
* happened; stripping it would dedup real logo edits as no-ops. The
|
|
235
|
+
* 2-second `BASELINE_SETTLE_MS` window already collapses initial-load
|
|
236
|
+
* base64 churn into the baseline.
|
|
192
237
|
*
|
|
193
238
|
* RTE strings are canonicalized by parsing the HTML with DOMParser and
|
|
194
239
|
* walking the tree; only attributeless format wrappers (and a tightly
|
|
@@ -320,6 +365,15 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
320
365
|
}
|
|
321
366
|
|
|
322
367
|
const el = node as Element;
|
|
368
|
+
|
|
369
|
+
// Attributeless <br> is TipTap's deterministic emission of a hard break.
|
|
370
|
+
// Treated as `\n` so a hydrated `<p><span>A<br>B</span></p>` canonicalizes
|
|
371
|
+
// to `"A\nB"` and matches the plain-side `"A%0AB"` after newline decoding.
|
|
372
|
+
// <br> with any attribute (e.g. `<br data-x>`) bails as before.
|
|
373
|
+
if (el.tagName === 'BR') {
|
|
374
|
+
return el.attributes.length === 0 ? '\n' : null;
|
|
375
|
+
}
|
|
376
|
+
|
|
323
377
|
const isStructural = STRUCTURAL_HYDRATION_TAGS.has(el.tagName);
|
|
324
378
|
const isFormat = FORMAT_HYDRATION_TAGS.has(el.tagName);
|
|
325
379
|
|
|
@@ -364,15 +418,26 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
364
418
|
* once and writes back wrapped HTML with no user-visible delta.
|
|
365
419
|
*/
|
|
366
420
|
function canonicalizeRteString(value: string): string {
|
|
367
|
-
//
|
|
368
|
-
|
|
421
|
+
// Decode the codebase's URL-encoded newline (`%0A` — see
|
|
422
|
+
// `ESCAPED_NEWLINE_CHARACTER`) on the plain-text side. The hydrated side
|
|
423
|
+
// emits `<br>` for the same logical newline, and `extractCanonicalText`
|
|
424
|
+
// collapses attributeless `<br>` to `\n`, so the two converge.
|
|
425
|
+
// `split`/`join` rather than `decodeURIComponent` keeps this narrow —
|
|
426
|
+
// we don't want to decode `%20`, `%3C`, etc., which would change real
|
|
427
|
+
// user content.
|
|
428
|
+
const decodeNewlines = (s: string): string =>
|
|
429
|
+
s.split(ESCAPED_NEWLINE_CHARACTER).join('\n');
|
|
430
|
+
|
|
431
|
+
// Cheap exit: no tags at all. Still decode `%0A` so a plain-text entry
|
|
432
|
+
// matches a hydrated entry whose only diff is `<br>`-vs-newline.
|
|
433
|
+
if (!value.includes('<')) return decodeNewlines(value);
|
|
369
434
|
|
|
370
435
|
if (isEmptyRteHtml(value)) return '';
|
|
371
436
|
|
|
372
437
|
// DOMParser is unavailable in some non-browser test environments;
|
|
373
438
|
// fall back to leaving the value as-is so the caller produces a
|
|
374
439
|
// real diff (i.e. fail open — never falsely collapse).
|
|
375
|
-
if (typeof DOMParser === 'undefined') return value;
|
|
440
|
+
if (typeof DOMParser === 'undefined') return decodeNewlines(value);
|
|
376
441
|
|
|
377
442
|
let doc: Document;
|
|
378
443
|
|
|
@@ -382,24 +447,30 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
382
447
|
'text/html',
|
|
383
448
|
);
|
|
384
449
|
} catch {
|
|
385
|
-
return value;
|
|
450
|
+
return decodeNewlines(value);
|
|
386
451
|
}
|
|
387
452
|
|
|
388
453
|
const root = doc.getElementById('__rte_root__');
|
|
389
454
|
|
|
390
|
-
if (!root) return value;
|
|
455
|
+
if (!root) return decodeNewlines(value);
|
|
391
456
|
|
|
392
|
-
|
|
457
|
+
// Join top-level blocks with `\n`. TipTap renders an Enter keypress as
|
|
458
|
+
// a new top-level `<p>` sibling — without the join, `<p>Hello</p>` and
|
|
459
|
+
// `<p>Hello</p><p></p>` (or `<p>Hello</p><p>World</p>`) collapse to the
|
|
460
|
+
// same canonical text and the Enter is invisible to dedup. The join
|
|
461
|
+
// also matches plain-side `%0A` between paragraphs (e.g. stored
|
|
462
|
+
// `Hello%0AWorld` ↔ hydrated `<p>Hello</p><p>World</p>`).
|
|
463
|
+
const parts: string[] = [];
|
|
393
464
|
|
|
394
465
|
for (const child of Array.from(root.childNodes)) {
|
|
395
466
|
const part = extractCanonicalText(child);
|
|
396
467
|
|
|
397
|
-
if (part === null) return value;
|
|
468
|
+
if (part === null) return decodeNewlines(value);
|
|
398
469
|
|
|
399
|
-
|
|
470
|
+
parts.push(part);
|
|
400
471
|
}
|
|
401
472
|
|
|
402
|
-
return
|
|
473
|
+
return parts.join('\n');
|
|
403
474
|
}
|
|
404
475
|
|
|
405
476
|
function normalizeNode(node: unknown): unknown {
|
|
@@ -417,17 +488,6 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
417
488
|
// represent a user-visible change.
|
|
418
489
|
if (key === 'isModifiedAfterTemplateApplied') continue;
|
|
419
490
|
|
|
420
|
-
// Strip the rendered logo PNG. Logo property edits (text, color,
|
|
421
|
-
// font, outline, shadow) authored via the Logo sidebar live in
|
|
422
|
-
// `editableLogoStore.logoEdits` — which is NOT in `brandPageData`,
|
|
423
|
-
// so an undo would revert this base64 image on the canvas without
|
|
424
|
-
// touching the sidebar fields. Per V1 scope, logo property edits
|
|
425
|
-
// are non-undoable (parallels the PRD's admin-logo exclusion);
|
|
426
|
-
// BYO-upload undo still works because that change shows up in
|
|
427
|
-
// `logoImage.logoDraftToken`, not here. Stripping the field keeps
|
|
428
|
-
// those isolated render-output diffs out of the stack entirely.
|
|
429
|
-
if (key === 'logoImageBase64Url') continue;
|
|
430
|
-
|
|
431
491
|
// Collapse RTE default-hydration wrappers down to the plain text
|
|
432
492
|
// they wrap. Plain "X" and `<p style="..."><span ...><mark ...>X
|
|
433
493
|
// </mark></span></p>` share the same canonical "X" so a sidebar
|
|
@@ -539,6 +599,7 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
539
599
|
actor: HistoryEntry['actor'];
|
|
540
600
|
label?: string;
|
|
541
601
|
activePageId: string;
|
|
602
|
+
logoEdits?: string;
|
|
542
603
|
}): 'committed' | 'oversized' | 'noop' {
|
|
543
604
|
const current = entries.value[currentIndex.value];
|
|
544
605
|
|
|
@@ -575,6 +636,7 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
575
636
|
label: args.label,
|
|
576
637
|
sizeBytes: args.snapshot.length,
|
|
577
638
|
activePageId: args.activePageId,
|
|
639
|
+
logoEdits: args.logoEdits,
|
|
578
640
|
};
|
|
579
641
|
|
|
580
642
|
// FR-11: truncate redo tail, then append.
|
|
@@ -668,6 +730,7 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
668
730
|
if (!snapshot) return;
|
|
669
731
|
|
|
670
732
|
const activePageId = getCurrentActivePageId();
|
|
733
|
+
const logoEdits = serializeCurrentLogoEdits();
|
|
671
734
|
|
|
672
735
|
// During the post-init settle window, fold any captured mutation back
|
|
673
736
|
// into the baseline (entry 0). Async cascades like template
|
|
@@ -690,6 +753,7 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
690
753
|
timestamp: new Date().toISOString(),
|
|
691
754
|
sizeBytes: snapshot.length,
|
|
692
755
|
activePageId,
|
|
756
|
+
logoEdits,
|
|
693
757
|
},
|
|
694
758
|
];
|
|
695
759
|
|
|
@@ -701,6 +765,7 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
701
765
|
source: 'manual_edit',
|
|
702
766
|
actor: 'user',
|
|
703
767
|
activePageId,
|
|
768
|
+
logoEdits,
|
|
704
769
|
});
|
|
705
770
|
};
|
|
706
771
|
|
|
@@ -752,6 +817,7 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
752
817
|
label: 'baseline',
|
|
753
818
|
sizeBytes: snapshot.length,
|
|
754
819
|
activePageId: getCurrentActivePageId(),
|
|
820
|
+
logoEdits: serializeCurrentLogoEdits(),
|
|
755
821
|
},
|
|
756
822
|
];
|
|
757
823
|
currentIndex.value = 0;
|
|
@@ -782,6 +848,7 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
782
848
|
return commitEntry({
|
|
783
849
|
snapshot,
|
|
784
850
|
activePageId: getCurrentActivePageId(),
|
|
851
|
+
logoEdits: serializeCurrentLogoEdits(),
|
|
785
852
|
...args,
|
|
786
853
|
});
|
|
787
854
|
}
|
|
@@ -900,12 +967,15 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
900
967
|
}
|
|
901
968
|
}
|
|
902
969
|
|
|
970
|
+
const targetEntry = entries.value[targetIndex];
|
|
971
|
+
|
|
903
972
|
isApplyingSnapshot.value = true;
|
|
904
973
|
|
|
905
974
|
try {
|
|
906
975
|
await brandPageMakerStore.applyHistorySnapshot(
|
|
907
976
|
snapshot,
|
|
908
977
|
resolvedActivePageId,
|
|
978
|
+
targetEntry?.logoEdits,
|
|
909
979
|
);
|
|
910
980
|
await nextTick();
|
|
911
981
|
} finally {
|