@designcrowd/library.brand-page 6.0.26-json-prereq-2 → 6.0.26

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 (155) hide show
  1. package/lib/src/{CreatedOnBrandCrowd-de-de-CKBqjDH3.js → CreatedOnBrandCrowd-de-de-DU6YEVcW.js} +1 -1
  2. package/lib/src/{CreatedOnBrandCrowd-en-us-CRXiimvT.js → CreatedOnBrandCrowd-en-us-DNWWK6Tj.js} +1 -1
  3. package/lib/src/{CreatedOnBrandCrowd-es-es-DCYdY6sj.js → CreatedOnBrandCrowd-es-es-DVFvV9Qp.js} +1 -1
  4. package/lib/src/{CreatedOnBrandCrowd-fr-fr-Dk7LOhxE.js → CreatedOnBrandCrowd-fr-ca-B4ZkjNdw.js} +1 -1
  5. package/lib/src/{CreatedOnBrandCrowd-fr-ca-Dk7LOhxE.js → CreatedOnBrandCrowd-fr-fr-B4ZkjNdw.js} +1 -1
  6. package/lib/src/{CreatedOnBrandCrowd-pt-pt-Cp4ufHJP.js → CreatedOnBrandCrowd-pt-br-DP7AQGgW.js} +1 -1
  7. package/lib/src/{CreatedOnBrandCrowd-pt-br-Cp4ufHJP.js → CreatedOnBrandCrowd-pt-pt-DP7AQGgW.js} +1 -1
  8. package/lib/src/{CreatedOnDcom-de-de-ZSLkWMwM.js → CreatedOnDcom-de-de-CaC3GtG9.js} +1 -1
  9. package/lib/src/{CreatedOnDcom-en-us-BgdIGfT3.js → CreatedOnDcom-en-us-D16yT0-P.js} +1 -1
  10. package/lib/src/{CreatedOnDcom-es-es-D0KemkCZ.js → CreatedOnDcom-es-es-DA5sHgD_.js} +1 -1
  11. package/lib/src/{CreatedOnDcom-fr-ca-BuwNjNbC.js → CreatedOnDcom-fr-ca-CDv2SG1-.js} +1 -1
  12. package/lib/src/{CreatedOnDcom-fr-fr-DCQcsFPf.js → CreatedOnDcom-fr-fr-Cygc7c5d.js} +1 -1
  13. package/lib/src/{CreatedOnDcom-pt-br-DD-oLAS1.js → CreatedOnDcom-pt-br-B_3RIzgF.js} +1 -1
  14. package/lib/src/{CreatedOnDcom-pt-pt-D8qLq2wW.js → CreatedOnDcom-pt-pt-Bz5w-rrD.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/ai-chat/useAiMetadataBuilder.d.ts +1 -0
  25. package/lib/src/brand-page-maker/composables/rich-text-editor/bubbleMenu.d.ts +9 -2
  26. package/lib/src/brand-page-maker/composables/rich-text-editor/bubbleMenu.js +10 -6
  27. package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontSize.d.ts +20 -0
  28. package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontSize.js +44 -0
  29. package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/LineHeight.d.ts +27 -0
  30. package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/LineHeight.js +44 -0
  31. package/lib/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.d.ts +1 -1
  32. package/lib/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.js +103 -24
  33. package/lib/src/brand-page-maker/utils/index.d.ts +0 -2
  34. package/lib/src/brand-page-maker/utils/index.js +0 -2
  35. package/lib/src/brand-page-maker/utils/rich-text-editor.util.d.ts +5 -28
  36. package/lib/src/brand-page-maker/utils/rich-text-editor.util.js +5 -48
  37. package/lib/src/brand-page-maker/validators/field.validator.js +2 -10
  38. package/lib/src/css/library.brand-page-brandCrowd.min.css +39 -39
  39. package/lib/src/css/library.brand-page-brandPage.min.css +39 -39
  40. package/lib/src/css/library.brand-page-designCom.min.css +39 -39
  41. package/lib/src/css/library.brand-page-preview.min.css +39 -39
  42. package/lib/src/index.d.ts +0 -1
  43. package/lib/src/index.mjs +138 -143
  44. package/lib/src/{lib-Db6j9fQZ.js → lib-6_P6kXPu.js} +51709 -55194
  45. package/lib/src/lib.js +0 -2
  46. package/lib/src/metadata-builder/ai-metadata-executor.d.ts +1 -0
  47. package/lib/src/metadata-builder/ai-metadata-executor.js +19 -0
  48. package/lib/src/metadata-builder/builders/section-builders/about-section-builder.js +3 -2
  49. package/lib/src/metadata-builder/builders/section-builders/banner-section-builder.js +3 -2
  50. package/lib/src/metadata-builder/builders/section-builders/booking-section-builder.js +3 -2
  51. package/lib/src/metadata-builder/builders/section-builders/contact-form-builder.js +4 -3
  52. package/lib/src/metadata-builder/builders/section-builders/images-section-builder.js +3 -2
  53. package/lib/src/metadata-builder/builders/section-builders/mailing-list-builder.js +2 -1
  54. package/lib/src/metadata-builder/builders/section-builders/mailing-list-section-builder.js +2 -1
  55. package/lib/src/metadata-builder/builders/section-builders/profile-section-builder.js +4 -3
  56. package/lib/src/metadata-builder/builders/section-builders/shapes-section-builder.js +3 -2
  57. package/lib/src/metadata-builder/builders/section-builders/testimonial-section-builder.js +2 -1
  58. package/lib/src/metadata-builder/builders/section-builders/text-section-builder.js +11 -15
  59. package/lib/src/metadata-builder/builders/update-content-text-builder.d.ts +17 -0
  60. package/lib/src/metadata-builder/builders/update-content-text-builder.js +103 -0
  61. package/lib/src/metadata-builder/builders/update-content-text-style-builder.d.ts +16 -0
  62. package/lib/src/metadata-builder/builders/update-content-text-style-builder.js +216 -0
  63. package/lib/src/metadata-builder/helpers/rte.helpers.d.ts +13 -11
  64. package/lib/src/metadata-builder/helpers/rte.helpers.js +73 -14
  65. package/lib/src/metadata-builder/metadata-executor.js +4 -0
  66. package/lib/src/metadata-builder/models.d.ts +2 -0
  67. package/lib/src/metadata-builder/models.js +2 -0
  68. package/lib/src/metadata-builder/parsers/ai-toolcall-parser.d.ts +19 -0
  69. package/lib/src/metadata-builder/parsers/ai-toolcall-parser.js +4 -0
  70. package/lib/src/metadata-builder/sanitizers/rte-schema-check.d.ts +8 -7
  71. package/lib/src/metadata-builder/sanitizers/rte-schema-check.js +52 -21
  72. package/lib/src/shared/content-settings/components/GenericTextInput.mixin.js +1 -14
  73. package/lib/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.js +3 -12
  74. package/lib/src/shared/content-settings/components/testimonial-items-field/TestimonialItemsField.mixin.d.ts +2 -3
  75. package/lib/src/shared/content-settings/components/testimonial-items-field/TestimonialItemsField.mixin.js +3 -10
  76. package/lib/src/shared/content-settings/components/text-items-field/TextItemsField.mixin.d.ts +1 -2
  77. package/lib/src/shared/content-settings/components/text-items-field/TextItemsField.mixin.js +1 -4
  78. package/lib/src/utils/minify-brand-page-metadata.js +1 -4
  79. package/package.json +15 -17
  80. package/src/brand-page/components/contact-form/ContactForm.mixin.ts +2 -5
  81. package/src/brand-page/components/text-wrapper/TextWrapper.vue +6 -17
  82. package/src/brand-page/models/index.ts +26 -35
  83. package/src/brand-page/utils/__snapshots__/migration.util.test.ts.snap +3 -3
  84. package/src/brand-page/utils/migration.util.ts +0 -12
  85. package/src/brand-page/utils/style.util.test.ts +0 -51
  86. package/src/brand-page/utils/text.util.ts +4 -43
  87. package/src/brand-page/utils/vcard.util.ts +4 -6
  88. package/src/brand-page/utils/view-model.util.ts +26 -94
  89. package/src/brand-page/view-models.ts +2 -3
  90. package/src/brand-page-maker/components/rich-text-editor/RichTextEditor.vue +3 -4
  91. package/src/brand-page-maker/composables/ai-chat/useAiMetadataBuilder.ts +1 -0
  92. package/src/brand-page-maker/composables/rich-text-editor/bubbleMenu.ts +10 -6
  93. package/src/brand-page-maker/composables/rich-text-editor/extensions/FontSize.ts +73 -0
  94. package/src/brand-page-maker/composables/rich-text-editor/extensions/LineHeight.ts +85 -0
  95. package/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.ts +111 -27
  96. package/src/brand-page-maker/utils/index.ts +0 -2
  97. package/src/brand-page-maker/utils/rich-text-editor.util.test.ts +3 -37
  98. package/src/brand-page-maker/utils/rich-text-editor.util.ts +11 -66
  99. package/src/brand-page-maker/validators/field.validator.ts +2 -10
  100. package/src/lib.ts +0 -9
  101. package/src/metadata-builder/ai-metadata-executor.ts +26 -0
  102. package/src/metadata-builder/builders/section-builders/about-section-builder.ts +3 -2
  103. package/src/metadata-builder/builders/section-builders/banner-section-builder.ts +3 -2
  104. package/src/metadata-builder/builders/section-builders/booking-section-builder.ts +5 -2
  105. package/src/metadata-builder/builders/section-builders/contact-form-builder.ts +4 -3
  106. package/src/metadata-builder/builders/section-builders/images-section-builder.ts +3 -2
  107. package/src/metadata-builder/builders/section-builders/mailing-list-builder.ts +2 -1
  108. package/src/metadata-builder/builders/section-builders/mailing-list-section-builder.ts +2 -1
  109. package/src/metadata-builder/builders/section-builders/profile-section-builder.ts +6 -3
  110. package/src/metadata-builder/builders/section-builders/shapes-section-builder.ts +3 -2
  111. package/src/metadata-builder/builders/section-builders/testimonial-section-builder.ts +2 -1
  112. package/src/metadata-builder/builders/section-builders/text-section-builder.ts +13 -19
  113. package/src/metadata-builder/builders/update-content-text-builder.ts +148 -0
  114. package/src/metadata-builder/builders/update-content-text-style-builder.ts +352 -0
  115. package/src/metadata-builder/helpers/rte.helpers.ts +101 -15
  116. package/src/metadata-builder/metadata-executor.ts +5 -0
  117. package/src/metadata-builder/models.ts +3 -0
  118. package/src/metadata-builder/parsers/ai-toolcall-parser.ts +27 -0
  119. package/src/metadata-builder/sanitizers/rte-schema-check.ts +53 -24
  120. package/src/shared/content-settings/components/GenericTextInput.mixin.ts +1 -17
  121. package/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.ts +3 -16
  122. package/src/shared/content-settings/components/testimonial-items-field/TestimonialItemsField.mixin.ts +4 -13
  123. package/src/shared/content-settings/components/testimonial-items-field/TestimonialItemsField.vue +4 -6
  124. package/src/shared/content-settings/components/text-image-field/TextImageField.vue +3 -6
  125. package/src/shared/content-settings/components/text-items-field/TextItemsField.mixin.ts +1 -6
  126. package/src/shared/content-settings/components/text-items-field/TextItemsField.vue +1 -1
  127. package/src/utils/minify-brand-page-metadata.ts +1 -4
  128. package/lib/src/brand-page/utils/migration/migration-20.d.ts +0 -2
  129. package/lib/src/brand-page/utils/migration/migration-20.js +0 -66
  130. package/lib/src/brand-page-maker/__fixtures__/complex-rte.fixture.d.ts +0 -22
  131. package/lib/src/brand-page-maker/__fixtures__/complex-rte.fixture.js +0 -22
  132. package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.d.ts +0 -14
  133. package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.js +0 -39
  134. package/lib/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.d.ts +0 -28
  135. package/lib/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.js +0 -90
  136. package/lib/src/brand-page-maker/utils/rte-render.util.d.ts +0 -63
  137. package/lib/src/brand-page-maker/utils/rte-render.util.js +0 -95
  138. package/lib/src/brand-page-maker/utils/rte-sanitize.util.d.ts +0 -6
  139. package/lib/src/brand-page-maker/utils/rte-sanitize.util.js +0 -158
  140. package/src/brand-page/utils/migration/migration-20.server.test.ts +0 -125
  141. package/src/brand-page/utils/migration/migration-20.test.ts +0 -72
  142. package/src/brand-page/utils/migration/migration-20.ts +0 -87
  143. package/src/brand-page/utils/text.util.test.ts +0 -47
  144. package/src/brand-page/utils/view-model.pageid-rte.test.ts +0 -104
  145. package/src/brand-page-maker/__fixtures__/complex-rte.fixture.ts +0 -23
  146. package/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.test.ts +0 -52
  147. package/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.ts +0 -42
  148. package/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.ts +0 -137
  149. package/src/brand-page-maker/utils/__snapshots__/rte-render-parity.test.ts.snap +0 -202
  150. package/src/brand-page-maker/utils/rte-features.test.ts +0 -351
  151. package/src/brand-page-maker/utils/rte-render-parity.test.ts +0 -157
  152. package/src/brand-page-maker/utils/rte-render.util.ts +0 -165
  153. package/src/brand-page-maker/utils/rte-sanitize-json.test.ts +0 -158
  154. package/src/brand-page-maker/utils/rte-sanitize.util.ts +0 -195
  155. package/src/brand-page-maker/validators/field.validator.test.ts +0 -55
@@ -1,158 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { sanitizeRteJson } from './rte-sanitize.util';
3
- import { toRteJson } from './rte-render.util';
4
- import { COMPLEX_RTE_HTML } from '../__fixtures__/complex-rte.fixture';
5
-
6
- /**
7
- * BP-5787 — native JSON sanitiser (T5). Operates on the Tiptap tree directly
8
- * (no editor, no HTML, no DOMPurify). Mirrors the HTML allowlist's guarantees.
9
- */
10
- const doc = (content: unknown[]): unknown => ({ type: 'doc', content });
11
- const para = (content: unknown[]) => ({ type: 'paragraph', content });
12
- const text = (t: string, marks?: unknown[]) => ({
13
- type: 'text',
14
- text: t,
15
- marks,
16
- });
17
- const json = (v: unknown) => JSON.stringify(v);
18
-
19
- describe('sanitizeRteJson (native)', () => {
20
- it('drops unknown node types but keeps their valid text siblings', () => {
21
- const out = sanitizeRteJson(
22
- doc([
23
- para([text('keep me')]),
24
- { type: 'image', attrs: { src: 'x', onerror: 'alert(1)' } },
25
- { type: 'script', content: [text('alert(1)')] },
26
- ]),
27
- );
28
-
29
- expect(json(out)).toContain('keep me');
30
- expect(json(out)).not.toContain('image');
31
- expect(json(out)).not.toContain('script');
32
- expect(json(out)).not.toContain('alert(1)');
33
- });
34
-
35
- it('drops unknown mark types, keeps allow-listed ones', () => {
36
- const out = sanitizeRteJson(
37
- doc([
38
- para([
39
- text('bold', [{ type: 'bold' }]),
40
- text('evil', [{ type: 'onclick', attrs: { js: 'alert(1)' } }]),
41
- ]),
42
- ]),
43
- );
44
-
45
- expect(json(out)).toContain('"type":"bold"');
46
- expect(json(out)).not.toContain('onclick');
47
- expect(json(out)).not.toContain('alert(1)');
48
- });
49
-
50
- it('strips javascript: / data: hrefs from link marks (drops the mark)', () => {
51
- const out = sanitizeRteJson(
52
- doc([
53
- para([
54
- // eslint-disable-next-line no-script-url
55
- text('click', [
56
- { type: 'link', attrs: { href: 'javascript:alert(1)' } },
57
- ]),
58
- ]),
59
- ]),
60
- );
61
-
62
- expect(json(out)).toContain('click'); // text kept
63
- expect(json(out)).not.toContain('javascript:');
64
- expect(json(out)).not.toContain('"type":"link"');
65
- });
66
-
67
- it('keeps safe links', () => {
68
- const out = sanitizeRteJson(
69
- doc([
70
- para([
71
- text('site', [
72
- {
73
- type: 'link',
74
- attrs: { href: 'https://example.com', target: '_blank' },
75
- },
76
- ]),
77
- ]),
78
- ]),
79
- );
80
-
81
- expect(json(out)).toContain('https://example.com');
82
- });
83
-
84
- it('keeps safe textStyle attrs incl. theme token, drops injection values', () => {
85
- const out = sanitizeRteJson(
86
- doc([
87
- para([
88
- text('ok', [
89
- {
90
- type: 'textStyle',
91
- attrs: {
92
- color: 'var(--logo-text-color)',
93
- fontFamily: 'Open Sans',
94
- fontSize: '1.5em',
95
- },
96
- },
97
- ]),
98
- text('bad', [
99
- {
100
- type: 'textStyle',
101
- attrs: {
102
- color: 'red; position: fixed; top: 0',
103
- fontSize: '1em" onload="x',
104
- },
105
- },
106
- ]),
107
- ]),
108
- ]),
109
- );
110
-
111
- const s = json(out);
112
-
113
- expect(s).toContain('var(--logo-text-color)');
114
- expect(s).toContain('Open Sans');
115
- expect(s).toContain('1.5em');
116
- // injection values dropped
117
- expect(s).not.toContain('position: fixed');
118
- expect(s).not.toContain('onload');
119
- });
120
-
121
- it('clamps heading level and keeps valid textAlign', () => {
122
- const out: any = sanitizeRteJson(
123
- doc([
124
- {
125
- type: 'heading',
126
- attrs: { level: 99, textAlign: 'center' },
127
- content: [text('H')],
128
- },
129
- {
130
- type: 'paragraph',
131
- attrs: { textAlign: 'evil' },
132
- content: [text('P')],
133
- },
134
- ]),
135
- );
136
-
137
- expect(out.content[0].attrs.level).toBe(1);
138
- expect(out.content[0].attrs.textAlign).toBe('center');
139
- expect(out.content[1].attrs?.textAlign).toBeUndefined();
140
- });
141
-
142
- it('passes the clean complex fixture through unchanged (idempotent)', () => {
143
- const clean = toRteJson(COMPLEX_RTE_HTML);
144
- const once = sanitizeRteJson(clean);
145
- const twice = sanitizeRteJson(once);
146
-
147
- expect(twice).toEqual(once);
148
- // legitimate content preserved
149
- expect(json(once)).toContain('var(--logo-text-color)');
150
- expect(json(once)).toContain('Montserrat');
151
- expect(json(once)).toContain('https://example.com');
152
- });
153
-
154
- it('returns an empty doc for non-document input', () => {
155
- expect(sanitizeRteJson(null)).toEqual({ type: 'doc', content: [] });
156
- expect(sanitizeRteJson('<p>x</p>')).toEqual({ type: 'doc', content: [] });
157
- });
158
- });
@@ -1,195 +0,0 @@
1
- import type { JSONContent } from '@tiptap/vue-3';
2
- import { validateAndSanitizeHref } from './rich-text-editor.util';
3
-
4
- /**
5
- * BP-5787 — native JSON sanitiser for RTE content.
6
- *
7
- * Operates directly on the Tiptap document tree: no editor instantiation, no
8
- * HTML round-trip, no DOMPurify. This is the hot path (runs on every editor
9
- * update and on the server sanitise gate), so it is a single, allocation-light
10
- * recursive walk.
11
- *
12
- * Security model (mirrors the HTML allowlist it replaces):
13
- * - only allow-listed node and mark types survive; everything else is dropped;
14
- * - textStyle / highlight attrs are restricted to known keys whose values must
15
- * be "safe CSS values" (no quotes/angle-brackets/extra declarations/url()/
16
- * expression()), preventing CSS-injection when the value is later rendered
17
- * into a `style="…"` attribute;
18
- * - link hrefs go through the same validateAndSanitizeHref used by the HTML
19
- * sanitiser; unsafe links lose their href (and the mark);
20
- * - heading levels are clamped to 1–6.
21
- */
22
-
23
- // ProseMirror node types the editor schema can legitimately produce.
24
- const ALLOWED_NODE_TYPES = new Set([
25
- 'doc',
26
- 'paragraph',
27
- 'heading',
28
- 'text',
29
- 'hardBreak',
30
- 'bulletList',
31
- 'orderedList',
32
- 'listItem',
33
- 'blockquote',
34
- 'codeBlock',
35
- 'horizontalRule',
36
- ]);
37
-
38
- // Inline mark types the editor produces (strong/em/u/s/code/span/mark/a).
39
- const ALLOWED_MARK_TYPES = new Set([
40
- 'bold',
41
- 'italic',
42
- 'underline',
43
- 'strike',
44
- 'code',
45
- 'textStyle',
46
- 'highlight',
47
- 'link',
48
- ]);
49
-
50
- // textStyle attrs map to the allow-listed CSS properties (font-weight →
51
- // bold mark, text-decoration → underline/strike, text-align → node attr,
52
- // background-color → highlight, so they are intentionally not here).
53
- const ALLOWED_TEXT_STYLE_ATTRS = new Set([
54
- 'color',
55
- 'fontFamily',
56
- 'fontSize',
57
- 'letterSpacing',
58
- 'lineHeight',
59
- ]);
60
-
61
- type Mark = { type?: string; attrs?: Record<string, unknown> };
62
-
63
- /**
64
- * A safe CSS value is a short string free of characters that could inject an
65
- * extra declaration or escape the attribute, and free of the url()/expression()
66
- * vectors. Legitimate values — `rgb(255, 0, 0)`, `#FF0000`,
67
- * `var(--logo-text-color)`, `Open Sans`, `1.5em` — all pass.
68
- */
69
- const isSafeCssValue = (value: unknown): value is string =>
70
- typeof value === 'string' &&
71
- value.length > 0 &&
72
- value.length <= 200 &&
73
- !/[<>"';]/.test(value) &&
74
- !/url\s*\(/i.test(value) &&
75
- !/expression\s*\(/i.test(value);
76
-
77
- const sanitizeTextStyleAttrs = (
78
- attrs: Record<string, unknown>,
79
- ): Record<string, unknown> | null => {
80
- const clean: Record<string, unknown> = {};
81
-
82
- for (const key of Object.keys(attrs)) {
83
- if (!ALLOWED_TEXT_STYLE_ATTRS.has(key)) continue;
84
-
85
- const value = attrs[key];
86
-
87
- // Tiptap emits '' for unset textStyle slots — preserve them.
88
- if (value === '' || value == null) {
89
- clean[key] = '';
90
- } else if (isSafeCssValue(value)) {
91
- clean[key] = value;
92
- }
93
- // else: drop the unsafe value
94
- }
95
-
96
- return Object.keys(clean).length ? clean : null;
97
- };
98
-
99
- const sanitizeMark = (mark: Mark): Mark | null => {
100
- const type = mark?.type;
101
-
102
- if (!type || !ALLOWED_MARK_TYPES.has(type)) return null;
103
-
104
- const attrs = mark.attrs;
105
-
106
- if (type === 'link') {
107
- const href =
108
- typeof attrs?.href === 'string'
109
- ? validateAndSanitizeHref(attrs.href)
110
- : null;
111
-
112
- if (!href) return null; // drop links with unsafe/empty href
113
-
114
- const cleanAttrs: Record<string, unknown> = { href };
115
-
116
- if (attrs?.target != null) cleanAttrs.target = attrs.target;
117
-
118
- if (attrs?.rel != null) cleanAttrs.rel = attrs.rel;
119
-
120
- return { type, attrs: cleanAttrs };
121
- }
122
-
123
- if (type === 'textStyle') {
124
- const clean = attrs ? sanitizeTextStyleAttrs(attrs) : null;
125
-
126
- return clean ? { type, attrs: clean } : null;
127
- }
128
-
129
- if (type === 'highlight') {
130
- return isSafeCssValue(attrs?.color)
131
- ? { type, attrs: { color: attrs!.color } }
132
- : { type };
133
- }
134
-
135
- // Plain marks (bold/italic/underline/strike/code) carry no attrs.
136
- return { type };
137
- };
138
-
139
- const ALIGN_VALUES = new Set(['left', 'center', 'right', 'justify']);
140
-
141
- const sanitizeNode = (node: JSONContent): JSONContent | null => {
142
- const type = node?.type;
143
-
144
- if (!type || !ALLOWED_NODE_TYPES.has(type)) return null;
145
-
146
- const clean: JSONContent = { type };
147
- const attrs: Record<string, unknown> = {};
148
-
149
- if (type === 'heading') {
150
- const level = Number((node.attrs as { level?: unknown })?.level);
151
-
152
- attrs.level = level >= 1 && level <= 6 ? level : 1;
153
- }
154
-
155
- if (type === 'heading' || type === 'paragraph') {
156
- const align = (node.attrs as { textAlign?: unknown })?.textAlign;
157
-
158
- if (typeof align === 'string' && ALIGN_VALUES.has(align)) {
159
- attrs.textAlign = align;
160
- }
161
- }
162
-
163
- if (Object.keys(attrs).length) clean.attrs = attrs;
164
-
165
- if (typeof node.text === 'string') clean.text = node.text;
166
-
167
- if (Array.isArray(node.marks)) {
168
- const marks = node.marks
169
- .map((m) => sanitizeMark(m as Mark))
170
- .filter(Boolean) as JSONContent['marks'];
171
-
172
- if (marks && marks.length) clean.marks = marks;
173
- }
174
-
175
- if (Array.isArray(node.content)) {
176
- const content = node.content
177
- .map(sanitizeNode)
178
- .filter(Boolean) as JSONContent[];
179
-
180
- if (content.length) clean.content = content;
181
- }
182
-
183
- return clean;
184
- };
185
-
186
- /**
187
- * Sanitise a Tiptap JSON document (returns a new clean doc). Returns a minimal
188
- * empty doc if the input isn't a usable document.
189
- */
190
- export const sanitizeRteJson = (doc: unknown): JSONContent => {
191
- const clean =
192
- doc && typeof doc === 'object' ? sanitizeNode(doc as JSONContent) : null;
193
-
194
- return clean && clean.type === 'doc' ? clean : { type: 'doc', content: [] };
195
- };
@@ -1,55 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { validatorDict } from './field.validator';
3
-
4
- /**
5
- * BP-5857 — the `title` validator must preserve pre-JSON (staging) semantics.
6
- * An RTE field's value used to be inline HTML: an empty editor was "<p></p>",
7
- * a non-empty string, so the required check always PASSED for RTE fields — it
8
- * only failed for genuinely empty PLAIN inputs. RTE fields are now Tiptap JSON
9
- * docs, so any doc must likewise count as "present" (valid); a plain string is
10
- * still required to be non-empty.
11
- */
12
- describe('field.validator — title (nonEmptyString)', () => {
13
- const titleValidator = validatorDict.title;
14
-
15
- const jsonDoc = (text: string) => ({
16
- type: 'doc',
17
- content: [
18
- {
19
- type: 'paragraph',
20
- content: text
21
- ? [{ type: 'text', text, marks: [{ type: 'bold' }] }]
22
- : [],
23
- },
24
- ],
25
- });
26
-
27
- it('accepts a non-empty plain string', () => {
28
- expect(titleValidator.validate('title', 'Payments').isValid).toBe(true);
29
- });
30
-
31
- it('rejects an empty plain string (required still enforced for plain inputs)', () => {
32
- expect(titleValidator.validate('title', '').isValid).toBe(false);
33
- });
34
-
35
- it('accepts legacy empty RTE HTML "<p></p>" (non-empty string — staging parity)', () => {
36
- expect(titleValidator.validate('title', '<p></p>').isValid).toBe(true);
37
- });
38
-
39
- it('accepts a Tiptap JSON doc with visible text', () => {
40
- expect(titleValidator.validate('title', jsonDoc('Payments')).isValid).toBe(
41
- true,
42
- );
43
- });
44
-
45
- it('accepts an empty Tiptap JSON doc (RTE parity — empty editor is "present")', () => {
46
- expect(titleValidator.validate('title', jsonDoc('')).isValid).toBe(true);
47
- });
48
-
49
- it('rejects null/undefined without throwing', () => {
50
- expect(titleValidator.validate('title', null as any).isValid).toBe(false);
51
- expect(titleValidator.validate('title', undefined as any).isValid).toBe(
52
- false,
53
- );
54
- });
55
- });