@designcrowd/library.brand-page 5.17.25-undo-3 → 5.17.25-undo-5
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-xR_8611Z.js → CreatedOnBrandCrowd-de-de-CHMMocnx.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-en-us-CrKMPM86.js → CreatedOnBrandCrowd-en-us-DHlWLkwc.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-es-es-C7lJoCwP.js → CreatedOnBrandCrowd-es-es-DeoGQeBU.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-fr-B2P1kNsi.js → CreatedOnBrandCrowd-fr-ca-DmZV08MV.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-ca-B2P1kNsi.js → CreatedOnBrandCrowd-fr-fr-DmZV08MV.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-pt-Cg9ulkXK.js → CreatedOnBrandCrowd-pt-br-COuMaj13.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-br-Cg9ulkXK.js → CreatedOnBrandCrowd-pt-pt-COuMaj13.js} +1 -1
- package/lib/src/{CreatedOnDcom-de-de-RKjXZKTE.js → CreatedOnDcom-de-de-C9XvdB6Y.js} +1 -1
- package/lib/src/{CreatedOnDcom-en-us-Bma4WSgm.js → CreatedOnDcom-en-us-CSIczk-e.js} +1 -1
- package/lib/src/{CreatedOnDcom-es-es-CAqF8RQd.js → CreatedOnDcom-es-es-B8PxGq85.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-ca-BZzsaA-O.js → CreatedOnDcom-fr-ca-ClXbe4Tz.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-fr-lB4hUGDb.js → CreatedOnDcom-fr-fr-DvVB8qIo.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-br-dD3iqhZb.js → CreatedOnDcom-pt-br-DmBFmt7n.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-pt-80E4SvnQ.js → CreatedOnDcom-pt-pt-DdPrMHbl.js} +1 -1
- package/lib/src/brand-page-maker/stores/history/history-store.js +118 -2
- package/lib/src/index.mjs +1 -1
- package/lib/src/{lib-BBctNsms.js → lib-Cox69cyq.js} +4033 -3996
- package/package.json +1 -1
- package/src/brand-page-maker/stores/history/history-store.test.ts +241 -0
- package/src/brand-page-maker/stores/history/history-store.ts +137 -1
package/package.json
CHANGED
|
@@ -156,6 +156,247 @@ describe('history-store (single stack + JSON-string snapshots)', () => {
|
|
|
156
156
|
expect(store.currentIndex).toBe(1);
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
+
// BP-5506 phantom-undo dedup: opening a content settings panel can
|
|
160
|
+
// mutate `brandPageData` in ways the user can't see (RTE empty-paragraph
|
|
161
|
+
// init, lazy textStyle hydration, isModifiedAfterTemplateApplied flip).
|
|
162
|
+
// The dedup gate normalizes these out so capture returns 'noop'.
|
|
163
|
+
describe('phantom-edit dedup (sidebar-open cascades)', () => {
|
|
164
|
+
it('treats RTE empty-paragraph init as a no-op', async () => {
|
|
165
|
+
const store = useHistoryStore();
|
|
166
|
+
|
|
167
|
+
// Baseline has description = "" (cold start).
|
|
168
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
169
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
170
|
+
{
|
|
171
|
+
contents: [{ type: 'contact-form', description: '' }],
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
await store.captureBaseline();
|
|
175
|
+
|
|
176
|
+
// Sidebar open writes back TipTap's empty-paragraph default.
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
+
(mockMakerStore.brandPageData as any).pages[0].contents[0].description =
|
|
179
|
+
'<p style="text-align: center;"></p>';
|
|
180
|
+
|
|
181
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
182
|
+
|
|
183
|
+
expect(result).toBe('noop');
|
|
184
|
+
expect(store.entries.length).toBe(1);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('treats lazy textStyle hydration (fontSize / letterSpacing) as a no-op', async () => {
|
|
188
|
+
const store = useHistoryStore();
|
|
189
|
+
|
|
190
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
191
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
192
|
+
{
|
|
193
|
+
contents: [
|
|
194
|
+
{
|
|
195
|
+
type: 'contact-form',
|
|
196
|
+
titleStyle: { textStyleType: 'titles' },
|
|
197
|
+
descriptionStyle: { textStyleType: 'paragraphs' },
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
await store.captureBaseline();
|
|
203
|
+
|
|
204
|
+
// Settings panel resolves textStyleType → fills in fontSize / letterSpacing.
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
+
const cf = (mockMakerStore.brandPageData as any).pages[0].contents[0];
|
|
207
|
+
|
|
208
|
+
cf.titleStyle.fontSize = '2.25em';
|
|
209
|
+
cf.titleStyle.letterSpacing = '0';
|
|
210
|
+
cf.descriptionStyle.fontSize = '1em';
|
|
211
|
+
cf.descriptionStyle.letterSpacing = '0';
|
|
212
|
+
|
|
213
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
214
|
+
|
|
215
|
+
expect(result).toBe('noop');
|
|
216
|
+
expect(store.entries.length).toBe(1);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('treats isModifiedAfterTemplateApplied flip as a no-op', async () => {
|
|
220
|
+
const store = useHistoryStore();
|
|
221
|
+
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
223
|
+
(mockMakerStore.brandPageData as any).isModifiedAfterTemplateApplied =
|
|
224
|
+
false;
|
|
225
|
+
await store.captureBaseline();
|
|
226
|
+
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
228
|
+
(mockMakerStore.brandPageData as any).isModifiedAfterTemplateApplied =
|
|
229
|
+
true;
|
|
230
|
+
|
|
231
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
232
|
+
|
|
233
|
+
expect(result).toBe('noop');
|
|
234
|
+
expect(store.entries.length).toBe(1);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('treats RTE empty-paragraph init as a no-op when the prior key was absent', async () => {
|
|
238
|
+
const store = useHistoryStore();
|
|
239
|
+
|
|
240
|
+
// Baseline content has NO `description` key at all (the cold-start
|
|
241
|
+
// shape for sections like testimonial-section before any editor
|
|
242
|
+
// mounts). JSON.stringify drops `undefined`, so the captured snapshot
|
|
243
|
+
// simply lacks the key.
|
|
244
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
245
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
246
|
+
{
|
|
247
|
+
contents: [{ type: 'testimonial-section', title: 'A' }],
|
|
248
|
+
},
|
|
249
|
+
];
|
|
250
|
+
await store.captureBaseline();
|
|
251
|
+
|
|
252
|
+
// Sidebar open writes back TipTap's empty-paragraph default, creating
|
|
253
|
+
// the key that was previously absent.
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
255
|
+
(mockMakerStore.brandPageData as any).pages[0].contents[0].description =
|
|
256
|
+
'<p style="text-align: center;"></p>';
|
|
257
|
+
|
|
258
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
259
|
+
|
|
260
|
+
expect(result).toBe('noop');
|
|
261
|
+
expect(store.entries.length).toBe(1);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('treats RTE default-hydration wrapper around plain text as a no-op', async () => {
|
|
265
|
+
const store = useHistoryStore();
|
|
266
|
+
|
|
267
|
+
// Cold-start: titles/descriptions are plain strings (no <p> wrapper).
|
|
268
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
269
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
270
|
+
{
|
|
271
|
+
contents: [
|
|
272
|
+
{
|
|
273
|
+
type: 'banner',
|
|
274
|
+
title: 'Makeup Artist ✦ Eleanor Reeves',
|
|
275
|
+
description: 'Creating Flawless Looks',
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
type: 'about-section',
|
|
279
|
+
title: 'Passionate About Makeup',
|
|
280
|
+
paragraph:
|
|
281
|
+
'Makeup is my art form, and I believe that everyone deserves to feel confident.',
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
];
|
|
286
|
+
await store.captureBaseline();
|
|
287
|
+
|
|
288
|
+
// Opening any content sidebar mounts every RTE editor on the page; each
|
|
289
|
+
// one writes back its plain-text input wrapped in TipTap's default
|
|
290
|
+
// <p>/<span>/<mark> hydration HTML. Same visible text, no real edit.
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
|
+
const banner = (mockMakerStore.brandPageData as any).pages[0].contents[0];
|
|
293
|
+
|
|
294
|
+
banner.title =
|
|
295
|
+
'<p style="text-align: center;"><span style="font-family: Belleza; font-size: 1.5625em; letter-spacing: 0.02em; line-height: 1.5; color: rgb(209, 128, 47);"><mark data-color="#fffde9" style="background-color: rgb(255, 253, 233); color: inherit;">Makeup Artist ✦ Eleanor Reeves</mark></span></p>';
|
|
296
|
+
banner.description =
|
|
297
|
+
'<p style="text-align: center;"><span style="font-family: Gloock; font-size: 4.6875em; letter-spacing: 0.05em; line-height: 1.4; color: rgb(209, 128, 47);"><mark data-color="#fffde9" style="background-color: rgb(255, 253, 233); color: inherit;">Creating Flawless Looks</mark></span></p>';
|
|
298
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
299
|
+
const about = (mockMakerStore.brandPageData as any).pages[0].contents[1];
|
|
300
|
+
|
|
301
|
+
about.title =
|
|
302
|
+
'<p style="text-align: left;"><span style="font-family: Gloock; font-size: 3.125em; letter-spacing: 0.05em; line-height: 1.3; color: rgb(255, 253, 233);">Passionate About Makeup</span></p>';
|
|
303
|
+
about.paragraph =
|
|
304
|
+
'<p style="text-align: left;"><span style="font-family: Belleza; font-size: 1.375em; letter-spacing: 0px; line-height: 1.5; color: rgb(255, 253, 233);">Makeup is my art form, and I believe that everyone deserves to feel confident.</span></p>';
|
|
305
|
+
|
|
306
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
307
|
+
|
|
308
|
+
expect(result).toBe('noop');
|
|
309
|
+
expect(store.entries.length).toBe(1);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('treats bare <p>plain text</p> hydration as a no-op', async () => {
|
|
313
|
+
const store = useHistoryStore();
|
|
314
|
+
|
|
315
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
316
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
317
|
+
{
|
|
318
|
+
contents: [
|
|
319
|
+
{
|
|
320
|
+
type: 'contact-form',
|
|
321
|
+
successMessage:
|
|
322
|
+
"Thank you! We'll get in touch with you as soon as possible.",
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
},
|
|
326
|
+
];
|
|
327
|
+
await store.captureBaseline();
|
|
328
|
+
|
|
329
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
330
|
+
(
|
|
331
|
+
mockMakerStore.brandPageData as any
|
|
332
|
+
).pages[0].contents[0].successMessage =
|
|
333
|
+
"<p>Thank you! We'll get in touch with you as soon as possible.</p>";
|
|
334
|
+
|
|
335
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
336
|
+
|
|
337
|
+
expect(result).toBe('noop');
|
|
338
|
+
expect(store.entries.length).toBe(1);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('still commits when RTE content has real inline formatting tags', async () => {
|
|
342
|
+
const store = useHistoryStore();
|
|
343
|
+
|
|
344
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
345
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
346
|
+
{
|
|
347
|
+
contents: [
|
|
348
|
+
{
|
|
349
|
+
type: 'banner',
|
|
350
|
+
title: 'Hello world',
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
},
|
|
354
|
+
];
|
|
355
|
+
await store.captureBaseline();
|
|
356
|
+
|
|
357
|
+
// Real formatting (the <strong> tag) must NOT be collapsed to plain
|
|
358
|
+
// text — it represents a user-visible diff.
|
|
359
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
360
|
+
(mockMakerStore.brandPageData as any).pages[0].contents[0].title =
|
|
361
|
+
'<p>Hello <strong>world</strong></p>';
|
|
362
|
+
|
|
363
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
364
|
+
|
|
365
|
+
expect(result).toBe('committed');
|
|
366
|
+
expect(store.entries.length).toBe(2);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('still commits when a real edit accompanies a phantom field', async () => {
|
|
370
|
+
const store = useHistoryStore();
|
|
371
|
+
|
|
372
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
373
|
+
(mockMakerStore.brandPageData as any).pages = [
|
|
374
|
+
{
|
|
375
|
+
contents: [
|
|
376
|
+
{
|
|
377
|
+
type: 'contact-form',
|
|
378
|
+
buttonText: 'Send',
|
|
379
|
+
description: '',
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
},
|
|
383
|
+
];
|
|
384
|
+
await store.captureBaseline();
|
|
385
|
+
|
|
386
|
+
// Real edit + phantom together — must commit.
|
|
387
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
388
|
+
const cf = (mockMakerStore.brandPageData as any).pages[0].contents[0];
|
|
389
|
+
|
|
390
|
+
cf.buttonText = 'Submit';
|
|
391
|
+
cf.description = '<p style="text-align: center;"></p>';
|
|
392
|
+
|
|
393
|
+
const result = store.capture({ source: 'manual_edit', actor: 'user' });
|
|
394
|
+
|
|
395
|
+
expect(result).toBe('committed');
|
|
396
|
+
expect(store.entries.length).toBe(2);
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
159
400
|
it('reentrancy guard: capture no-ops when isApplyingSnapshot is true', async () => {
|
|
160
401
|
const store = useHistoryStore();
|
|
161
402
|
|
|
@@ -128,6 +128,128 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Normalize a snapshot for the dedup byte-compare. Strips/canonicalizes
|
|
133
|
+
* fields that get mutated by sidebar-open reactive cascades but aren't
|
|
134
|
+
* user-visible edits — without this, opening a content panel produces an
|
|
135
|
+
* undo step that "does nothing" when replayed.
|
|
136
|
+
*
|
|
137
|
+
* Known phantom sources (BP-5506):
|
|
138
|
+
* - TipTap RTE writing back its empty-paragraph default on first mount
|
|
139
|
+
* (e.g. `""` → `<p style="text-align: center;"></p>`).
|
|
140
|
+
* - Lazy hydration of `textStyle` fields (`fontSize`, `letterSpacing`)
|
|
141
|
+
* when a content settings panel computes resolved values from
|
|
142
|
+
* `textStyleType` and writes them onto the model.
|
|
143
|
+
* - `isModifiedAfterTemplateApplied` flipping on first edit gesture.
|
|
144
|
+
*
|
|
145
|
+
* Used ONLY for dedup comparison. Stored snapshots remain unchanged so
|
|
146
|
+
* `applyHistorySnapshot` always sees the real state.
|
|
147
|
+
*/
|
|
148
|
+
// Empty paragraph forms TipTap emits when an editor mounts on an empty
|
|
149
|
+
// string. Treated as equivalent to `""` for dedup.
|
|
150
|
+
const EMPTY_RTE_HTML = /^<p(\s[^>]*)?>(<br\s*\/?>)?<\/p>$/;
|
|
151
|
+
|
|
152
|
+
// TipTap's default-hydration shape: a single <p> (with optional align
|
|
153
|
+
// attr) containing the original plain text, optionally wrapped in
|
|
154
|
+
// default-styled <span> (font-family / font-size / color) and/or
|
|
155
|
+
// <mark> (highlight) tags. The inner capture intentionally rejects any
|
|
156
|
+
// string that itself contains `<` or `>` so that real formatting tags
|
|
157
|
+
// — `<strong>`, `<em>`, `<a>`, nested spans with non-default styles —
|
|
158
|
+
// are preserved as a real diff rather than collapsed.
|
|
159
|
+
const RTE_DEFAULT_HYDRATION =
|
|
160
|
+
/^<p(\s[^>]*)?>(<span(\s[^>]*)?>)?(<mark(\s[^>]*)?>)?([^<>]*)(<\/mark>)?(<\/span>)?<\/p>$/;
|
|
161
|
+
|
|
162
|
+
function isEmptyRteHtml(value: unknown): boolean {
|
|
163
|
+
return typeof value === 'string' && EMPTY_RTE_HTML.test(value);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* If `value` is TipTap's default-hydration wrapper around a plain text
|
|
168
|
+
* (no inline formatting tags), return the bare inner text. Otherwise
|
|
169
|
+
* return the original string. This collapses the BP-5506 phantom where
|
|
170
|
+
* opening a content sidebar mounts every RTE editor at once and writes
|
|
171
|
+
* back wrapped HTML with no user-visible delta.
|
|
172
|
+
*/
|
|
173
|
+
function canonicalizeRteString(value: string): string {
|
|
174
|
+
if (EMPTY_RTE_HTML.test(value)) return '';
|
|
175
|
+
|
|
176
|
+
const match = value.match(RTE_DEFAULT_HYDRATION);
|
|
177
|
+
|
|
178
|
+
if (!match) return value;
|
|
179
|
+
|
|
180
|
+
return match[6] ?? '';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function normalizeNode(node: unknown): unknown {
|
|
184
|
+
if (Array.isArray(node)) return node.map(normalizeNode);
|
|
185
|
+
|
|
186
|
+
if (node === null || typeof node !== 'object') return node;
|
|
187
|
+
|
|
188
|
+
const out: Record<string, unknown> = {};
|
|
189
|
+
|
|
190
|
+
for (const key of Object.keys(node as Record<string, unknown>)) {
|
|
191
|
+
let v: unknown = (node as Record<string, unknown>)[key];
|
|
192
|
+
|
|
193
|
+
// Strip the template-modified flag — it's meta-state that flips on
|
|
194
|
+
// first edit gesture (e.g. clicking into a panel) and does not
|
|
195
|
+
// represent a user-visible change.
|
|
196
|
+
if (key === 'isModifiedAfterTemplateApplied') continue;
|
|
197
|
+
|
|
198
|
+
// Collapse RTE default-hydration wrappers down to the plain text
|
|
199
|
+
// they wrap. Plain "X" and `<p style="..."><span ...><mark ...>X
|
|
200
|
+
// </mark></span></p>` share the same canonical "X" so a sidebar
|
|
201
|
+
// open that mounts every editor at once doesn't generate phantom
|
|
202
|
+
// undo steps.
|
|
203
|
+
if (typeof v === 'string') {
|
|
204
|
+
v = canonicalizeRteString(v);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Empty TipTap paragraphs collapse to "" — and an empty string is
|
|
208
|
+
// equivalent to the key being absent (JSON.stringify drops `undefined`),
|
|
209
|
+
// so skip the key entirely. Otherwise the normalizer would emit
|
|
210
|
+
// `"description": ""` here while the baseline snapshot — captured when
|
|
211
|
+
// `description` was `undefined` — has no `description` key at all,
|
|
212
|
+
// and the two normalized strings would differ.
|
|
213
|
+
if (isEmptyRteHtml(v) || v === '') continue;
|
|
214
|
+
|
|
215
|
+
// textStyle / descriptionStyle / titleStyle / *Style objects:
|
|
216
|
+
// strip lazily-hydrated fields that get filled in when the settings
|
|
217
|
+
// panel computes resolved values from `textStyleType`.
|
|
218
|
+
if (
|
|
219
|
+
v !== null &&
|
|
220
|
+
typeof v === 'object' &&
|
|
221
|
+
!Array.isArray(v) &&
|
|
222
|
+
/Style$/.test(key)
|
|
223
|
+
) {
|
|
224
|
+
const styleObj = v as Record<string, unknown>;
|
|
225
|
+
const cleanedStyle: Record<string, unknown> = {};
|
|
226
|
+
|
|
227
|
+
for (const sk of Object.keys(styleObj)) {
|
|
228
|
+
if (sk === 'fontSize' || sk === 'letterSpacing') continue;
|
|
229
|
+
|
|
230
|
+
cleanedStyle[sk] = normalizeNode(styleObj[sk]);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
out[key] = cleanedStyle;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
out[key] = normalizeNode(v);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function normalizeSnapshotForDedup(snapshotStr: string): string {
|
|
244
|
+
try {
|
|
245
|
+
const parsed = JSON.parse(snapshotStr);
|
|
246
|
+
|
|
247
|
+
return JSON.stringify(normalizeNode(parsed));
|
|
248
|
+
} catch {
|
|
249
|
+
return snapshotStr;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
131
253
|
/**
|
|
132
254
|
* Commit a new entry into the stack at the current pointer position.
|
|
133
255
|
*
|
|
@@ -160,7 +282,21 @@ export const useHistoryStore = defineStore('history', () => {
|
|
|
160
282
|
}): 'committed' | 'oversized' | 'noop' {
|
|
161
283
|
const current = entries.value[currentIndex.value];
|
|
162
284
|
|
|
163
|
-
if (current
|
|
285
|
+
if (current) {
|
|
286
|
+
if (current.snapshot === args.snapshot) return 'noop';
|
|
287
|
+
|
|
288
|
+
// Phantom-edit dedup: normalize both snapshots to ignore
|
|
289
|
+
// sidebar-open reactive cascades (RTE empty-paragraph init, lazy
|
|
290
|
+
// textStyle hydration, isModifiedAfterTemplateApplied flips). If
|
|
291
|
+
// they're equal after normalization, this capture has no
|
|
292
|
+
// user-visible diff vs. the entry at the pointer.
|
|
293
|
+
if (
|
|
294
|
+
normalizeSnapshotForDedup(current.snapshot) ===
|
|
295
|
+
normalizeSnapshotForDedup(args.snapshot)
|
|
296
|
+
) {
|
|
297
|
+
return 'noop';
|
|
298
|
+
}
|
|
299
|
+
}
|
|
164
300
|
|
|
165
301
|
if (args.snapshot.length > MAX_ENTRY_BYTES) {
|
|
166
302
|
eventTracker.sendHistoryOversizedEvent({
|