@designcrowd/library.brand-page 6.0.19 → 6.0.20

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 (97) hide show
  1. package/lib/src/{CreatedOnBrandCrowd-de-de-DCwwdYPj.js → CreatedOnBrandCrowd-de-de-C52IyXZu.js} +1 -1
  2. package/lib/src/{CreatedOnBrandCrowd-en-us-DTmZeDQ1.js → CreatedOnBrandCrowd-en-us-DhTy_dEV.js} +1 -1
  3. package/lib/src/{CreatedOnBrandCrowd-es-es-Dbrz6TXv.js → CreatedOnBrandCrowd-es-es-BJelIAQ4.js} +1 -1
  4. package/lib/src/{CreatedOnBrandCrowd-fr-fr-DLQhgn8T.js → CreatedOnBrandCrowd-fr-ca-DwJohy0T.js} +1 -1
  5. package/lib/src/{CreatedOnBrandCrowd-fr-ca-DLQhgn8T.js → CreatedOnBrandCrowd-fr-fr-DwJohy0T.js} +1 -1
  6. package/lib/src/{CreatedOnBrandCrowd-pt-pt-yAzzD2ik.js → CreatedOnBrandCrowd-pt-br-CMzKbxdG.js} +1 -1
  7. package/lib/src/{CreatedOnBrandCrowd-pt-br-yAzzD2ik.js → CreatedOnBrandCrowd-pt-pt-CMzKbxdG.js} +1 -1
  8. package/lib/src/{CreatedOnDcom-de-de-CNmNNE5o.js → CreatedOnDcom-de-de-DAy1GHrw.js} +1 -1
  9. package/lib/src/{CreatedOnDcom-en-us-BUmLFlS_.js → CreatedOnDcom-en-us-CgBDAkJN.js} +1 -1
  10. package/lib/src/{CreatedOnDcom-es-es-DfygM_0q.js → CreatedOnDcom-es-es-Ds9d5rem.js} +1 -1
  11. package/lib/src/{CreatedOnDcom-fr-ca-DIEft8xE.js → CreatedOnDcom-fr-ca-CZL0BQ-u.js} +1 -1
  12. package/lib/src/{CreatedOnDcom-fr-fr-Cn3jWG2n.js → CreatedOnDcom-fr-fr-BVYh5Wvo.js} +1 -1
  13. package/lib/src/{CreatedOnDcom-pt-br-DXhgGwEh.js → CreatedOnDcom-pt-br-1hsWNXfq.js} +1 -1
  14. package/lib/src/{CreatedOnDcom-pt-pt-BvE9ckw1.js → CreatedOnDcom-pt-pt-DvM0N-3M.js} +1 -1
  15. package/lib/src/brand-page/components/contact-form/ContactForm.mixin.js +2 -5
  16. package/lib/src/brand-page/models/index.d.ts +26 -34
  17. package/lib/src/brand-page/utils/migration.util.js +0 -11
  18. package/lib/src/brand-page/utils/text.util.d.ts +1 -1
  19. package/lib/src/brand-page/utils/text.util.js +0 -32
  20. package/lib/src/brand-page/utils/vcard.util.js +4 -4
  21. package/lib/src/brand-page/utils/view-model.util.d.ts +0 -1
  22. package/lib/src/brand-page/utils/view-model.util.js +20 -68
  23. package/lib/src/brand-page/view-models.d.ts +3 -3
  24. package/lib/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.js +100 -21
  25. package/lib/src/brand-page-maker/utils/index.d.ts +0 -2
  26. package/lib/src/brand-page-maker/utils/index.js +0 -2
  27. package/lib/src/brand-page-maker/utils/rich-text-editor.util.d.ts +5 -19
  28. package/lib/src/brand-page-maker/utils/rich-text-editor.util.js +5 -35
  29. package/lib/src/brand-page-maker/validators/field.validator.js +2 -10
  30. package/lib/src/css/library.brand-page-brandCrowd.min.css +1 -1
  31. package/lib/src/css/library.brand-page-brandPage.min.css +1 -1
  32. package/lib/src/css/library.brand-page-designCom.min.css +1 -1
  33. package/lib/src/css/library.brand-page-preview.min.css +1 -1
  34. package/lib/src/index.d.ts +0 -1
  35. package/lib/src/index.mjs +138 -143
  36. package/lib/src/{lib-Bm-fYap1.js → lib-CK2FPBv5.js} +55098 -55367
  37. package/lib/src/lib.js +0 -2
  38. package/lib/src/metadata-builder/builders/update-content-text-builder.js +15 -20
  39. package/lib/src/metadata-builder/builders/update-content-text-style-builder.js +3 -8
  40. package/lib/src/metadata-builder/helpers/rte.helpers.d.ts +2 -2
  41. package/lib/src/metadata-builder/helpers/rte.helpers.js +3 -6
  42. package/lib/src/shared/content-settings/components/GenericTextInput.mixin.js +1 -14
  43. package/lib/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.js +3 -12
  44. package/lib/src/utils/minify-brand-page-metadata.js +1 -4
  45. package/package.json +1 -1
  46. package/src/brand-page/components/contact-form/ContactForm.mixin.ts +2 -5
  47. package/src/brand-page/components/text-wrapper/TextWrapper.vue +6 -17
  48. package/src/brand-page/models/index.ts +26 -35
  49. package/src/brand-page/utils/__snapshots__/migration.util.test.ts.snap +3 -3
  50. package/src/brand-page/utils/migration.util.ts +0 -12
  51. package/src/brand-page/utils/style.util.test.ts +0 -51
  52. package/src/brand-page/utils/text.util.ts +4 -43
  53. package/src/brand-page/utils/vcard.util.ts +4 -6
  54. package/src/brand-page/utils/view-model.util.ts +26 -94
  55. package/src/brand-page/view-models.ts +2 -3
  56. package/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.ts +107 -23
  57. package/src/brand-page-maker/utils/index.ts +0 -2
  58. package/src/brand-page-maker/utils/rich-text-editor.util.test.ts +3 -4
  59. package/src/brand-page-maker/utils/rich-text-editor.util.ts +11 -50
  60. package/src/brand-page-maker/validators/field.validator.ts +2 -10
  61. package/src/lib.ts +0 -9
  62. package/src/metadata-builder/builders/update-content-text-builder.ts +18 -32
  63. package/src/metadata-builder/builders/update-content-text-style-builder.ts +4 -14
  64. package/src/metadata-builder/helpers/rte.helpers.ts +7 -11
  65. package/src/shared/content-settings/components/GenericTextInput.mixin.ts +1 -17
  66. package/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.ts +3 -16
  67. package/src/utils/minify-brand-page-metadata.ts +1 -4
  68. package/lib/src/brand-page/utils/migration/migration-19.d.ts +0 -2
  69. package/lib/src/brand-page/utils/migration/migration-19.js +0 -71
  70. package/lib/src/brand-page-maker/__fixtures__/complex-rte.fixture.d.ts +0 -22
  71. package/lib/src/brand-page-maker/__fixtures__/complex-rte.fixture.js +0 -22
  72. package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.d.ts +0 -14
  73. package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.js +0 -39
  74. package/lib/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.d.ts +0 -28
  75. package/lib/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.js +0 -66
  76. package/lib/src/brand-page-maker/utils/rte-render.util.d.ts +0 -33
  77. package/lib/src/brand-page-maker/utils/rte-render.util.js +0 -50
  78. package/lib/src/brand-page-maker/utils/rte-sanitize.util.d.ts +0 -6
  79. package/lib/src/brand-page-maker/utils/rte-sanitize.util.js +0 -158
  80. package/lib/src/brand-page-maker/utils/rte-serializer.d.ts +0 -5
  81. package/lib/src/brand-page-maker/utils/rte-serializer.js +0 -112
  82. package/src/brand-page/utils/migration/migration-19.test.ts +0 -72
  83. package/src/brand-page/utils/migration/migration-19.ts +0 -83
  84. package/src/brand-page/utils/text.util.test.ts +0 -47
  85. package/src/brand-page/utils/view-model.pageid-rte.test.ts +0 -104
  86. package/src/brand-page-maker/__fixtures__/complex-rte.fixture.ts +0 -23
  87. package/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.test.ts +0 -52
  88. package/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.ts +0 -42
  89. package/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.ts +0 -113
  90. package/src/brand-page-maker/utils/__snapshots__/rte-render-parity.test.ts.snap +0 -200
  91. package/src/brand-page-maker/utils/rte-features.test.ts +0 -330
  92. package/src/brand-page-maker/utils/rte-render-parity.test.ts +0 -156
  93. package/src/brand-page-maker/utils/rte-render.util.ts +0 -77
  94. package/src/brand-page-maker/utils/rte-sanitize-json.test.ts +0 -158
  95. package/src/brand-page-maker/utils/rte-sanitize.util.ts +0 -195
  96. package/src/brand-page-maker/utils/rte-serializer.ts +0 -172
  97. package/src/brand-page-maker/validators/field.validator.test.ts +0 -55
@@ -1,200 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`BP-5787 RTE render parity (golden master) > T1 — editor renders the complex fixture to the frozen HTML baseline > editor-normalized-html 1`] = `"<h2 style="text-align: center;"><span style="color: var(--logo-text-color);">Themed heading</span></h2><p><strong>bold</strong> <em>italic</em> <u>underline</u> <s>strike</s> <span style="font-family: Montserrat; font-size: 1.5em; letter-spacing: 0.05em; line-height: 1.4;">styled span</span> <mark data-color="#ffe08a" style="background-color: rgb(255, 224, 138); color: inherit;">highlight</mark> <span style="color: rgb(255, 0, 0);">literal hex</span> <a href="/about" target="_self">internal link</a> <a href="https://example.com" target="_blank" rel="noopener noreferrer nofollow">external link</a></p><p style="text-align: right;">second paragraph, right-aligned</p>"`;
4
-
5
- exports[`BP-5787 RTE render parity (golden master) > T1 — render-from-JSON (DOM-less serialiser) produces equivalent HTML > serializer-html 1`] = `"<h2 style="text-align: center"><span style="color: var(--logo-text-color)">Themed heading</span></h2><p><strong>bold</strong> <em>italic</em> <u>underline</u> <s>strike</s> <span style="font-family: Montserrat; font-size: 1.5em; letter-spacing: 0.05em; line-height: 1.4">styled span</span> <mark data-color="#ffe08a" style="background-color: #ffe08a; color: inherit;">highlight</mark> <span style="color: rgb(255, 0, 0)">literal hex</span> <a href="/about" target="_self">internal link</a> <a href="https://example.com" target="_blank" rel="noopener noreferrer nofollow">external link</a></p><p style="text-align: right">second paragraph, right-aligned</p>"`;
6
-
7
- exports[`BP-5787 RTE render parity (golden master) > T6 — freezes the JSON shape that becomes the stored form > editor-json 1`] = `
8
- {
9
- "content": [
10
- {
11
- "attrs": {
12
- "level": 2,
13
- "textAlign": "center",
14
- },
15
- "content": [
16
- {
17
- "marks": [
18
- {
19
- "attrs": {
20
- "color": "var(--logo-text-color)",
21
- "fontFamily": "",
22
- "fontSize": "",
23
- "letterSpacing": "",
24
- "lineHeight": "",
25
- },
26
- "type": "textStyle",
27
- },
28
- ],
29
- "text": "Themed heading",
30
- "type": "text",
31
- },
32
- ],
33
- "type": "heading",
34
- },
35
- {
36
- "attrs": {
37
- "textAlign": null,
38
- },
39
- "content": [
40
- {
41
- "marks": [
42
- {
43
- "type": "bold",
44
- },
45
- ],
46
- "text": "bold",
47
- "type": "text",
48
- },
49
- {
50
- "text": " ",
51
- "type": "text",
52
- },
53
- {
54
- "marks": [
55
- {
56
- "type": "italic",
57
- },
58
- ],
59
- "text": "italic",
60
- "type": "text",
61
- },
62
- {
63
- "text": " ",
64
- "type": "text",
65
- },
66
- {
67
- "marks": [
68
- {
69
- "type": "underline",
70
- },
71
- ],
72
- "text": "underline",
73
- "type": "text",
74
- },
75
- {
76
- "text": " ",
77
- "type": "text",
78
- },
79
- {
80
- "marks": [
81
- {
82
- "type": "strike",
83
- },
84
- ],
85
- "text": "strike",
86
- "type": "text",
87
- },
88
- {
89
- "text": " ",
90
- "type": "text",
91
- },
92
- {
93
- "marks": [
94
- {
95
- "attrs": {
96
- "color": "",
97
- "fontFamily": "Montserrat",
98
- "fontSize": "1.5em",
99
- "letterSpacing": "0.05em",
100
- "lineHeight": "1.4",
101
- },
102
- "type": "textStyle",
103
- },
104
- ],
105
- "text": "styled span",
106
- "type": "text",
107
- },
108
- {
109
- "text": " ",
110
- "type": "text",
111
- },
112
- {
113
- "marks": [
114
- {
115
- "attrs": {
116
- "color": "#ffe08a",
117
- },
118
- "type": "highlight",
119
- },
120
- ],
121
- "text": "highlight",
122
- "type": "text",
123
- },
124
- {
125
- "text": " ",
126
- "type": "text",
127
- },
128
- {
129
- "marks": [
130
- {
131
- "attrs": {
132
- "color": "rgb(255, 0, 0)",
133
- "fontFamily": "",
134
- "fontSize": "",
135
- "letterSpacing": "",
136
- "lineHeight": "",
137
- },
138
- "type": "textStyle",
139
- },
140
- ],
141
- "text": "literal hex",
142
- "type": "text",
143
- },
144
- {
145
- "text": " ",
146
- "type": "text",
147
- },
148
- {
149
- "marks": [
150
- {
151
- "attrs": {
152
- "class": undefined,
153
- "href": "/about",
154
- "rel": undefined,
155
- "target": "_self",
156
- },
157
- "type": "link",
158
- },
159
- ],
160
- "text": "internal link",
161
- "type": "text",
162
- },
163
- {
164
- "text": " ",
165
- "type": "text",
166
- },
167
- {
168
- "marks": [
169
- {
170
- "attrs": {
171
- "class": undefined,
172
- "href": "https://example.com",
173
- "rel": "noopener noreferrer nofollow",
174
- "target": "_blank",
175
- },
176
- "type": "link",
177
- },
178
- ],
179
- "text": "external link",
180
- "type": "text",
181
- },
182
- ],
183
- "type": "paragraph",
184
- },
185
- {
186
- "attrs": {
187
- "textAlign": "right",
188
- },
189
- "content": [
190
- {
191
- "text": "second paragraph, right-aligned",
192
- "type": "text",
193
- },
194
- ],
195
- "type": "paragraph",
196
- },
197
- ],
198
- "type": "doc",
199
- }
200
- `;
@@ -1,330 +0,0 @@
1
- import { describe, it, expect, afterEach } from 'vitest';
2
- import { Editor } from '@tiptap/vue-3';
3
- import { getRteExtensions } from '../composables/rich-text-editor/getRteExtensions';
4
- import { toRteJson, renderRteToHtml } from './rte-render.util';
5
- import { sanitizeRteJson } from './rte-sanitize.util';
6
-
7
- /**
8
- * BP-5787 — feature-by-feature coverage of the whole RTE JSON pipeline.
9
- *
10
- * Each case runs a piece of authored HTML through the exact production path:
11
- * HTML → toRteJson (headless editor parse) → sanitizeRteJson → renderRteToHtml
12
- * (DOM-less serialiser)
13
- * and asserts the feature survives end-to-end. One combined golden-master lives
14
- * in rte-render-parity.test.ts; this file isolates every feature so a
15
- * regression in any single one (a mark, a textStyle attr, a link, alignment, a
16
- * block node) fails on its own line instead of inside one opaque snapshot.
17
- */
18
- const pipe = (html: string): string => {
19
- const json = toRteJson(html);
20
-
21
- return renderRteToHtml(sanitizeRteJson(json));
22
- };
23
-
24
- describe('RTE features — inline marks', () => {
25
- it('bold → <strong>', () => {
26
- expect(pipe('<p><strong>x</strong></p>')).toContain('<strong>x</strong>');
27
- });
28
- it('italic → <em>', () => {
29
- expect(pipe('<p><em>x</em></p>')).toContain('<em>x</em>');
30
- });
31
- it('underline → <u>', () => {
32
- expect(pipe('<p><u>x</u></p>')).toContain('<u>x</u>');
33
- });
34
- it('strikethrough → <s>', () => {
35
- expect(pipe('<p><s>x</s></p>')).toContain('<s>x</s>');
36
- });
37
- it('inline code → <code>', () => {
38
- expect(pipe('<p><code>x</code></p>')).toContain('<code>x</code>');
39
- });
40
- });
41
-
42
- describe('RTE features — textStyle attrs (colour/font/spacing)', () => {
43
- it('rgb colour is preserved', () => {
44
- expect(
45
- pipe('<p><span style="color: rgb(255, 0, 0)">x</span></p>'),
46
- ).toContain('color: rgb(255, 0, 0)');
47
- });
48
-
49
- it('hex colour is normalised to rgb() by the editor', () => {
50
- expect(pipe('<p><span style="color: #00ff00">x</span></p>')).toContain(
51
- 'color: rgb(0, 255, 0)',
52
- );
53
- });
54
-
55
- it('theme token var(--…) colour survives verbatim (NOT flattened to rgb)', () => {
56
- const out = pipe(
57
- '<p><span style="color: var(--logo-text-color)">x</span></p>',
58
- );
59
-
60
- expect(out).toContain('color: var(--logo-text-color)');
61
- expect(out).not.toContain('rgb(');
62
- });
63
-
64
- it('single-word font-family is preserved', () => {
65
- expect(
66
- pipe('<p><span style="font-family: Montserrat">x</span></p>'),
67
- ).toContain('font-family: Montserrat');
68
- });
69
-
70
- it('multi-word font-family is preserved UNQUOTED (BP-5787 quote-strip)', () => {
71
- const out = pipe('<p><span style="font-family: Open Sans">x</span></p>');
72
-
73
- expect(out).toContain('font-family: Open Sans');
74
- // must not carry the CSS quotes that the sanitiser would otherwise drop
75
- expect(out).not.toContain('font-family: "Open Sans"');
76
- expect(out).not.toContain('&quot;');
77
- });
78
-
79
- it('font-size / letter-spacing / line-height are preserved', () => {
80
- expect(pipe('<p><span style="font-size: 2em">x</span></p>')).toContain(
81
- 'font-size: 2em',
82
- );
83
- expect(
84
- pipe('<p><span style="letter-spacing: 0.1em">x</span></p>'),
85
- ).toContain('letter-spacing: 0.1em');
86
- expect(pipe('<p><span style="line-height: 1.5">x</span></p>')).toContain(
87
- 'line-height: 1.5',
88
- );
89
- });
90
- });
91
-
92
- describe('RTE features — background colour (highlight)', () => {
93
- it('highlight → <mark> with data-color + background-color + color:inherit', () => {
94
- const out = pipe(
95
- '<p><mark data-color="#ffe08a" style="background-color: #ffe08a">x</mark></p>',
96
- );
97
-
98
- expect(out).toContain(
99
- '<mark data-color="#ffe08a" style="background-color: #ffe08a; color: inherit;">x</mark>',
100
- );
101
- });
102
-
103
- it('theme token background colour survives verbatim', () => {
104
- const out = pipe(
105
- '<p><mark data-color="var(--logo-primary-color)" style="background-color: var(--logo-primary-color)">x</mark></p>',
106
- );
107
-
108
- expect(out).toContain('background-color: var(--logo-primary-color)');
109
- });
110
- });
111
-
112
- describe('RTE features — hyperlinks', () => {
113
- it('external link keeps href + target + rel', () => {
114
- const out = pipe(
115
- '<p><a target="_blank" rel="noopener noreferrer" href="https://example.com">x</a></p>',
116
- );
117
-
118
- expect(out).toContain('href="https://example.com"');
119
- expect(out).toContain('target="_blank"');
120
- expect(out).toContain('rel="noopener noreferrer"');
121
- });
122
-
123
- it('internal relative link keeps its href', () => {
124
- expect(pipe('<p><a href="/about">x</a></p>')).toContain('href="/about"');
125
- });
126
-
127
- it('internal page reference (pageid:) survives the sanitiser', () => {
128
- // pageid: hrefs are resolved to real routes later in the view-model
129
- // transform; the sanitiser must not strip them.
130
- expect(pipe('<p><a href="pageid:abc-123">x</a></p>')).toContain(
131
- 'href="pageid:abc-123"',
132
- );
133
- });
134
-
135
- it('javascript: link is dropped (mark removed, text kept)', () => {
136
- const out = pipe('<p><a href="javascript:alert(1)">x</a></p>');
137
-
138
- expect(out).not.toContain('<a');
139
- expect(out).not.toContain('javascript:');
140
- expect(out).toContain('x');
141
- });
142
-
143
- it('data: link is dropped', () => {
144
- const out = pipe(
145
- '<p><a href="data:text/html,<script>1</script>">x</a></p>',
146
- );
147
-
148
- expect(out).not.toContain('<a');
149
- expect(out).not.toContain('data:');
150
- });
151
- });
152
-
153
- describe('RTE features — text alignment', () => {
154
- for (const align of ['center', 'right', 'justify', 'left'] as const) {
155
- it(`paragraph text-align: ${align}`, () => {
156
- expect(pipe(`<p style="text-align: ${align}">x</p>`)).toContain(
157
- `<p style="text-align: ${align}">`,
158
- );
159
- });
160
- }
161
-
162
- it('heading carries its alignment', () => {
163
- expect(pipe('<h2 style="text-align: center">x</h2>')).toContain(
164
- '<h2 style="text-align: center">',
165
- );
166
- });
167
- });
168
-
169
- describe('RTE features — block nodes', () => {
170
- it('headings h1–h6', () => {
171
- for (const level of [1, 2, 3, 4, 5, 6]) {
172
- expect(pipe(`<h${level}>x</h${level}>`)).toContain(`<h${level}`);
173
- expect(pipe(`<h${level}>x</h${level}>`)).toContain(`</h${level}>`);
174
- }
175
- });
176
-
177
- it('bullet list → <ul><li>', () => {
178
- const out = pipe('<ul><li>a</li><li>b</li></ul>');
179
-
180
- expect(out).toContain('<ul>');
181
- expect(out).toContain('<li>');
182
- expect(out).toContain('a');
183
- expect(out).toContain('b');
184
- });
185
-
186
- it('ordered list → <ol><li>', () => {
187
- expect(pipe('<ol><li>a</li></ol>')).toContain('<ol>');
188
- });
189
-
190
- it('blockquote → <blockquote>', () => {
191
- expect(pipe('<blockquote><p>q</p></blockquote>')).toContain('<blockquote>');
192
- });
193
-
194
- it('code block → <pre><code>', () => {
195
- expect(pipe('<pre><code>c</code></pre>')).toContain('<pre><code>');
196
- });
197
-
198
- it('hard break → <br>', () => {
199
- expect(pipe('<p>a<br>b</p>')).toContain('<br>');
200
- });
201
-
202
- it('horizontal rule → <hr>', () => {
203
- expect(pipe('<p>a</p><hr><p>b</p>')).toContain('<hr>');
204
- });
205
- });
206
-
207
- describe('RTE features — combinations & escaping', () => {
208
- it('nested marks (colour + bold + italic) all survive on the same run', () => {
209
- const out = pipe(
210
- '<p><span style="color: rgb(1, 2, 3)"><strong><em>x</em></strong></span></p>',
211
- );
212
-
213
- expect(out).toContain('color: rgb(1, 2, 3)');
214
- expect(out).toContain('<strong>');
215
- expect(out).toContain('<em>');
216
- });
217
-
218
- it('a styled hyperlink keeps both the colour and the link', () => {
219
- const out = pipe(
220
- '<p><a href="https://x.com"><span style="color: rgb(0, 151, 215)">x</span></a></p>',
221
- );
222
-
223
- expect(out).toContain('href="https://x.com"');
224
- expect(out).toContain('color: rgb(0, 151, 215)');
225
- });
226
-
227
- it('HTML-special characters in text are escaped', () => {
228
- const out = pipe('<p>a &lt;b&gt; &amp; "c"</p>');
229
-
230
- expect(out).toContain('&lt;b&gt;');
231
- expect(out).toContain('&amp;');
232
- expect(out).not.toContain('<b>');
233
- });
234
-
235
- it('serialisation is idempotent (serialize(json) === serialize(reparse))', () => {
236
- const html =
237
- '<h2 style="text-align: center"><span style="color: var(--logo-text-color); font-family: Open Sans; font-size: 1.5em">Heading</span></h2>' +
238
- '<p><strong>bold</strong> <em>italic</em> <u>u</u> <s>s</s> ' +
239
- '<mark data-color="#ffe08a" style="background-color: #ffe08a">hl</mark> ' +
240
- '<a target="_blank" rel="noopener noreferrer" href="https://x.com">link</a></p>';
241
- const once = pipe(html);
242
- const twice = renderRteToHtml(sanitizeRteJson(toRteJson(once)));
243
-
244
- expect(twice).toEqual(once);
245
- });
246
- });
247
-
248
- describe('RTE features — maker toolbar commands (emit path)', () => {
249
- let editors: Editor[] = [];
250
-
251
- afterEach(() => {
252
- editors.forEach((e) => e.destroy());
253
- editors = [];
254
- });
255
-
256
- // Apply a real editor command to a full selection (as the toolbar does),
257
- // then run the emitted JSON through sanitise + serialise.
258
- const applied = (fn: (e: Editor) => void): string => {
259
- const editor = new Editor({
260
- extensions: getRteExtensions({ restrictStarterKit: true }),
261
- });
262
-
263
- editors.push(editor);
264
- editor.commands.setContent('<p>styled text</p>');
265
- editor.commands.selectAll();
266
- fn(editor);
267
-
268
- return renderRteToHtml(sanitizeRteJson(editor.getJSON()));
269
- };
270
-
271
- it('setColor', () => {
272
- expect(applied((e) => e.commands.setColor('rgb(255, 0, 0)'))).toContain(
273
- 'color: rgb(255, 0, 0)',
274
- );
275
- });
276
-
277
- it('setHighlight (background colour)', () => {
278
- const out = applied((e) => e.commands.setHighlight({ color: '#ffe08a' }));
279
-
280
- expect(out).toContain('background-color: #ffe08a');
281
- expect(out).toContain('<mark');
282
- });
283
-
284
- it('toggleBold / toggleItalic / toggleUnderline / toggleStrike', () => {
285
- expect(applied((e) => e.commands.toggleBold())).toContain('<strong>');
286
- expect(applied((e) => e.commands.toggleItalic())).toContain('<em>');
287
- expect(applied((e) => e.commands.toggleUnderline())).toContain('<u>');
288
- expect(applied((e) => e.commands.toggleStrike())).toContain('<s>');
289
- });
290
-
291
- it('setFontFamily (multi-word, unquoted)', () => {
292
- const out = applied((e) =>
293
- (e.commands as { setFontFamily: (f: string) => boolean }).setFontFamily(
294
- 'Open Sans',
295
- ),
296
- );
297
-
298
- expect(out).toContain('font-family: Open Sans');
299
- expect(out).not.toContain('&quot;');
300
- });
301
-
302
- it('setFontSize / setLetterSpacing', () => {
303
- expect(
304
- applied((e) =>
305
- (e.commands as { setFontSize: (v: string) => boolean }).setFontSize(
306
- '2em',
307
- ),
308
- ),
309
- ).toContain('font-size: 2em');
310
- expect(
311
- applied((e) =>
312
- (
313
- e.commands as { setLetterSpacing: (v: string) => boolean }
314
- ).setLetterSpacing('0.1em'),
315
- ),
316
- ).toContain('letter-spacing: 0.1em');
317
- });
318
-
319
- it('setTextAlign', () => {
320
- expect(applied((e) => e.commands.setTextAlign('center'))).toContain(
321
- 'text-align: center',
322
- );
323
- });
324
-
325
- it('setLink keeps the href through the pipeline', () => {
326
- expect(
327
- applied((e) => e.commands.setLink({ href: 'https://x.com' })),
328
- ).toContain('href="https://x.com"');
329
- });
330
- });
@@ -1,156 +0,0 @@
1
- import { describe, it, expect, afterEach } from 'vitest';
2
- import type { Editor } from '@tiptap/vue-3';
3
- import { useExternalRichTextEditor } from '../composables/rich-text-editor/useRichTextEditor';
4
- import {
5
- renderRteToHtml,
6
- toRteJson,
7
- getRteJsonPlainText,
8
- } from './rte-render.util';
9
- import {
10
- COMPLEX_RTE_HTML,
11
- THEME_TOKEN_REF,
12
- } from '../__fixtures__/complex-rte.fixture';
13
-
14
- /**
15
- * BP-5787 — golden-master render-parity baseline.
16
- *
17
- * Captured on the CURRENT (HTML) pipeline. These committed snapshots are the
18
- * frozen reference for the HTML→JSON migration:
19
- *
20
- * - `editor-normalized-html` is what the editor renders the fixture to today.
21
- * After the migration, `htmlFromJson(getJSON())` MUST equal this snapshot —
22
- * i.e. the JSON pipeline reproduces identical rendered output (no drift).
23
- *
24
- * - `editor-json` freezes the JSON shape that BECOMES the stored form. It is
25
- * expected to change exactly once, intentionally, when storage flips to JSON
26
- * (see "expected vs forbidden drift" in docs/plans/BP-5787-...html).
27
- *
28
- * The headless editor uses the SAME extension set as the live editor
29
- * (useExternalRichTextEditor), so it is a faithful stand-in for the renderer.
30
- */
31
- describe('BP-5787 RTE render parity (golden master)', () => {
32
- let editor: Editor;
33
-
34
- const makeEditor = (): Editor => {
35
- editor = useExternalRichTextEditor().externalEditor;
36
-
37
- return editor;
38
- };
39
-
40
- afterEach(() => {
41
- editor?.destroy();
42
- });
43
-
44
- it('T1 — editor renders the complex fixture to the frozen HTML baseline', () => {
45
- const ed = makeEditor();
46
-
47
- ed.commands.setContent(COMPLEX_RTE_HTML);
48
-
49
- // The golden master. The JSON pipeline must reproduce this exactly.
50
- expect(ed.getHTML()).toMatchSnapshot('editor-normalized-html');
51
- });
52
-
53
- it('T1 — round-trip is idempotent (html → json → html === json → html)', () => {
54
- const ed = makeEditor();
55
-
56
- ed.commands.setContent(COMPLEX_RTE_HTML);
57
- const pass1 = ed.getHTML();
58
- const json = ed.getJSON();
59
-
60
- // Re-seed from the JSON the migration will store, render again.
61
- ed.commands.setContent(json);
62
- const pass2 = ed.getHTML();
63
-
64
- expect(pass2).toEqual(pass1);
65
- });
66
-
67
- it('T6 — freezes the JSON shape that becomes the stored form', () => {
68
- const ed = makeEditor();
69
-
70
- ed.commands.setContent(COMPLEX_RTE_HTML);
71
-
72
- expect(ed.getJSON()).toMatchSnapshot('editor-json');
73
- });
74
-
75
- it('T2 — theme token ref survives the round-trip (NOT flattened to rgb)', () => {
76
- const ed = makeEditor();
77
-
78
- ed.commands.setContent(COMPLEX_RTE_HTML);
79
-
80
- // Today the editor preserves var(--…) in marks; the migration must keep it.
81
- expect(ed.getHTML()).toContain(THEME_TOKEN_REF);
82
- expect(JSON.stringify(ed.getJSON())).toContain(THEME_TOKEN_REF);
83
- });
84
-
85
- it('T1 — render-from-JSON (DOM-less serialiser) produces equivalent HTML', () => {
86
- // renderRteToHtml now serialises JSON → HTML with a pure function (no
87
- // editor/DOM, so it works on the server). Output is semantically identical
88
- // to the editor's — the Playwright visual golden-master is the authority on
89
- // pixel parity; here we freeze the serialiser output and assert structure.
90
- const viaJson = renderRteToHtml(toRteJson(COMPLEX_RTE_HTML));
91
-
92
- expect(viaJson).toMatchSnapshot('serializer-html');
93
-
94
- // marks/nodes preserved
95
- expect(viaJson).toContain('<strong>bold</strong>');
96
- expect(viaJson).toContain('<em>italic</em>');
97
- expect(viaJson).toContain('<u>underline</u>');
98
- expect(viaJson).toContain('<s>strike</s>');
99
- expect(viaJson).toContain('font-family: Montserrat');
100
- expect(viaJson).toContain('font-size: 1.5em');
101
- // theme token ref preserved (the crux of BP-5787)
102
- expect(viaJson).toContain('color: var(--logo-text-color)');
103
- // links + alignment
104
- expect(viaJson).toContain('href="/about"');
105
- expect(viaJson).toContain('href="https://example.com"');
106
- expect(viaJson).toContain('text-align: center');
107
- expect(viaJson).toContain('text-align: right');
108
- });
109
-
110
- it('T4 — legacy HTML strings render unchanged (back-compat passthrough)', () => {
111
- expect(renderRteToHtml(COMPLEX_RTE_HTML)).toEqual(COMPLEX_RTE_HTML);
112
- });
113
-
114
- it('T8 — getRteJsonPlainText extracts visible text only (for fraud/translate)', () => {
115
- const json = toRteJson(COMPLEX_RTE_HTML)!;
116
- const text = getRteJsonPlainText(json);
117
-
118
- expect(text).toContain('Themed heading');
119
- expect(text).toContain('bold');
120
- expect(text).toContain('external link');
121
- // no markup or token refs leak into the extracted text
122
- expect(text).not.toContain('<');
123
- expect(text).not.toContain('var(--');
124
- expect(text).not.toContain('font-size');
125
- });
126
-
127
- it('T1 — preserves every mark/node in the fixture', () => {
128
- const ed = makeEditor();
129
-
130
- ed.commands.setContent(COMPLEX_RTE_HTML);
131
- const html = ed.getHTML();
132
-
133
- // bold / italic / underline / strike
134
- expect(html).toContain('<strong>');
135
- expect(html).toContain('<em>');
136
- expect(html).toContain('<u>');
137
- expect(html).toContain('<s>');
138
- // textStyle attrs
139
- expect(html).toContain('font-family: Montserrat');
140
- expect(html).toContain('font-size: 1.5em');
141
- expect(html).toContain('letter-spacing: 0.05em');
142
- expect(html).toContain('line-height: 1.4');
143
- // highlight: data-color keeps the hex; the rendered style is normalised to rgb()
144
- expect(html).toContain('data-color="#ffe08a"');
145
- expect(html).toContain('background-color: rgb(255, 224, 138)');
146
- // literal hex colour is normalised to rgb() by the editor...
147
- expect(html).toContain('color: rgb(255, 0, 0)');
148
- // ...but the THEME TOKEN ref is preserved verbatim (the crux of BP-5787)
149
- expect(html).toContain('color: var(--logo-text-color)');
150
- expect(html).toContain('text-align: center');
151
- expect(html).toContain('text-align: right');
152
- // links
153
- expect(html).toContain('href="/about"');
154
- expect(html).toContain('href="https://example.com"');
155
- });
156
- });