@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.
- package/lib/src/{CreatedOnBrandCrowd-de-de-CKBqjDH3.js → CreatedOnBrandCrowd-de-de-DU6YEVcW.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-en-us-CRXiimvT.js → CreatedOnBrandCrowd-en-us-DNWWK6Tj.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-es-es-DCYdY6sj.js → CreatedOnBrandCrowd-es-es-DVFvV9Qp.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-fr-Dk7LOhxE.js → CreatedOnBrandCrowd-fr-ca-B4ZkjNdw.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-ca-Dk7LOhxE.js → CreatedOnBrandCrowd-fr-fr-B4ZkjNdw.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-pt-Cp4ufHJP.js → CreatedOnBrandCrowd-pt-br-DP7AQGgW.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-br-Cp4ufHJP.js → CreatedOnBrandCrowd-pt-pt-DP7AQGgW.js} +1 -1
- package/lib/src/{CreatedOnDcom-de-de-ZSLkWMwM.js → CreatedOnDcom-de-de-CaC3GtG9.js} +1 -1
- package/lib/src/{CreatedOnDcom-en-us-BgdIGfT3.js → CreatedOnDcom-en-us-D16yT0-P.js} +1 -1
- package/lib/src/{CreatedOnDcom-es-es-D0KemkCZ.js → CreatedOnDcom-es-es-DA5sHgD_.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-ca-BuwNjNbC.js → CreatedOnDcom-fr-ca-CDv2SG1-.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-fr-DCQcsFPf.js → CreatedOnDcom-fr-fr-Cygc7c5d.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-br-DD-oLAS1.js → CreatedOnDcom-pt-br-B_3RIzgF.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-pt-D8qLq2wW.js → CreatedOnDcom-pt-pt-Bz5w-rrD.js} +1 -1
- package/lib/src/brand-page/components/contact-form/ContactForm.mixin.js +2 -5
- package/lib/src/brand-page/models/index.d.ts +26 -34
- package/lib/src/brand-page/utils/migration.util.js +0 -11
- package/lib/src/brand-page/utils/text.util.d.ts +1 -1
- package/lib/src/brand-page/utils/text.util.js +0 -32
- package/lib/src/brand-page/utils/vcard.util.js +4 -4
- package/lib/src/brand-page/utils/view-model.util.d.ts +0 -1
- package/lib/src/brand-page/utils/view-model.util.js +20 -68
- package/lib/src/brand-page/view-models.d.ts +3 -3
- package/lib/src/brand-page-maker/composables/ai-chat/useAiMetadataBuilder.d.ts +1 -0
- package/lib/src/brand-page-maker/composables/rich-text-editor/bubbleMenu.d.ts +9 -2
- package/lib/src/brand-page-maker/composables/rich-text-editor/bubbleMenu.js +10 -6
- package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontSize.d.ts +20 -0
- package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontSize.js +44 -0
- package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/LineHeight.d.ts +27 -0
- package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/LineHeight.js +44 -0
- package/lib/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.d.ts +1 -1
- package/lib/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.js +103 -24
- package/lib/src/brand-page-maker/utils/index.d.ts +0 -2
- package/lib/src/brand-page-maker/utils/index.js +0 -2
- package/lib/src/brand-page-maker/utils/rich-text-editor.util.d.ts +5 -28
- package/lib/src/brand-page-maker/utils/rich-text-editor.util.js +5 -48
- package/lib/src/brand-page-maker/validators/field.validator.js +2 -10
- package/lib/src/css/library.brand-page-brandCrowd.min.css +39 -39
- package/lib/src/css/library.brand-page-brandPage.min.css +39 -39
- package/lib/src/css/library.brand-page-designCom.min.css +39 -39
- package/lib/src/css/library.brand-page-preview.min.css +39 -39
- package/lib/src/index.d.ts +0 -1
- package/lib/src/index.mjs +138 -143
- package/lib/src/{lib-Db6j9fQZ.js → lib-6_P6kXPu.js} +51709 -55194
- package/lib/src/lib.js +0 -2
- package/lib/src/metadata-builder/ai-metadata-executor.d.ts +1 -0
- package/lib/src/metadata-builder/ai-metadata-executor.js +19 -0
- package/lib/src/metadata-builder/builders/section-builders/about-section-builder.js +3 -2
- package/lib/src/metadata-builder/builders/section-builders/banner-section-builder.js +3 -2
- package/lib/src/metadata-builder/builders/section-builders/booking-section-builder.js +3 -2
- package/lib/src/metadata-builder/builders/section-builders/contact-form-builder.js +4 -3
- package/lib/src/metadata-builder/builders/section-builders/images-section-builder.js +3 -2
- package/lib/src/metadata-builder/builders/section-builders/mailing-list-builder.js +2 -1
- package/lib/src/metadata-builder/builders/section-builders/mailing-list-section-builder.js +2 -1
- package/lib/src/metadata-builder/builders/section-builders/profile-section-builder.js +4 -3
- package/lib/src/metadata-builder/builders/section-builders/shapes-section-builder.js +3 -2
- package/lib/src/metadata-builder/builders/section-builders/testimonial-section-builder.js +2 -1
- package/lib/src/metadata-builder/builders/section-builders/text-section-builder.js +11 -15
- package/lib/src/metadata-builder/builders/update-content-text-builder.d.ts +17 -0
- package/lib/src/metadata-builder/builders/update-content-text-builder.js +103 -0
- package/lib/src/metadata-builder/builders/update-content-text-style-builder.d.ts +16 -0
- package/lib/src/metadata-builder/builders/update-content-text-style-builder.js +216 -0
- package/lib/src/metadata-builder/helpers/rte.helpers.d.ts +13 -11
- package/lib/src/metadata-builder/helpers/rte.helpers.js +73 -14
- package/lib/src/metadata-builder/metadata-executor.js +4 -0
- package/lib/src/metadata-builder/models.d.ts +2 -0
- package/lib/src/metadata-builder/models.js +2 -0
- package/lib/src/metadata-builder/parsers/ai-toolcall-parser.d.ts +19 -0
- package/lib/src/metadata-builder/parsers/ai-toolcall-parser.js +4 -0
- package/lib/src/metadata-builder/sanitizers/rte-schema-check.d.ts +8 -7
- package/lib/src/metadata-builder/sanitizers/rte-schema-check.js +52 -21
- package/lib/src/shared/content-settings/components/GenericTextInput.mixin.js +1 -14
- package/lib/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.js +3 -12
- package/lib/src/shared/content-settings/components/testimonial-items-field/TestimonialItemsField.mixin.d.ts +2 -3
- package/lib/src/shared/content-settings/components/testimonial-items-field/TestimonialItemsField.mixin.js +3 -10
- package/lib/src/shared/content-settings/components/text-items-field/TextItemsField.mixin.d.ts +1 -2
- package/lib/src/shared/content-settings/components/text-items-field/TextItemsField.mixin.js +1 -4
- package/lib/src/utils/minify-brand-page-metadata.js +1 -4
- package/package.json +15 -17
- package/src/brand-page/components/contact-form/ContactForm.mixin.ts +2 -5
- package/src/brand-page/components/text-wrapper/TextWrapper.vue +6 -17
- package/src/brand-page/models/index.ts +26 -35
- package/src/brand-page/utils/__snapshots__/migration.util.test.ts.snap +3 -3
- package/src/brand-page/utils/migration.util.ts +0 -12
- package/src/brand-page/utils/style.util.test.ts +0 -51
- package/src/brand-page/utils/text.util.ts +4 -43
- package/src/brand-page/utils/vcard.util.ts +4 -6
- package/src/brand-page/utils/view-model.util.ts +26 -94
- package/src/brand-page/view-models.ts +2 -3
- package/src/brand-page-maker/components/rich-text-editor/RichTextEditor.vue +3 -4
- package/src/brand-page-maker/composables/ai-chat/useAiMetadataBuilder.ts +1 -0
- package/src/brand-page-maker/composables/rich-text-editor/bubbleMenu.ts +10 -6
- package/src/brand-page-maker/composables/rich-text-editor/extensions/FontSize.ts +73 -0
- package/src/brand-page-maker/composables/rich-text-editor/extensions/LineHeight.ts +85 -0
- package/src/brand-page-maker/composables/rich-text-editor/useRichTextEditor.ts +111 -27
- package/src/brand-page-maker/utils/index.ts +0 -2
- package/src/brand-page-maker/utils/rich-text-editor.util.test.ts +3 -37
- package/src/brand-page-maker/utils/rich-text-editor.util.ts +11 -66
- package/src/brand-page-maker/validators/field.validator.ts +2 -10
- package/src/lib.ts +0 -9
- package/src/metadata-builder/ai-metadata-executor.ts +26 -0
- package/src/metadata-builder/builders/section-builders/about-section-builder.ts +3 -2
- package/src/metadata-builder/builders/section-builders/banner-section-builder.ts +3 -2
- package/src/metadata-builder/builders/section-builders/booking-section-builder.ts +5 -2
- package/src/metadata-builder/builders/section-builders/contact-form-builder.ts +4 -3
- package/src/metadata-builder/builders/section-builders/images-section-builder.ts +3 -2
- package/src/metadata-builder/builders/section-builders/mailing-list-builder.ts +2 -1
- package/src/metadata-builder/builders/section-builders/mailing-list-section-builder.ts +2 -1
- package/src/metadata-builder/builders/section-builders/profile-section-builder.ts +6 -3
- package/src/metadata-builder/builders/section-builders/shapes-section-builder.ts +3 -2
- package/src/metadata-builder/builders/section-builders/testimonial-section-builder.ts +2 -1
- package/src/metadata-builder/builders/section-builders/text-section-builder.ts +13 -19
- package/src/metadata-builder/builders/update-content-text-builder.ts +148 -0
- package/src/metadata-builder/builders/update-content-text-style-builder.ts +352 -0
- package/src/metadata-builder/helpers/rte.helpers.ts +101 -15
- package/src/metadata-builder/metadata-executor.ts +5 -0
- package/src/metadata-builder/models.ts +3 -0
- package/src/metadata-builder/parsers/ai-toolcall-parser.ts +27 -0
- package/src/metadata-builder/sanitizers/rte-schema-check.ts +53 -24
- package/src/shared/content-settings/components/GenericTextInput.mixin.ts +1 -17
- package/src/shared/content-settings/components/content-settings-item/ContentSettingsItemField.mixin.ts +3 -16
- package/src/shared/content-settings/components/testimonial-items-field/TestimonialItemsField.mixin.ts +4 -13
- package/src/shared/content-settings/components/testimonial-items-field/TestimonialItemsField.vue +4 -6
- package/src/shared/content-settings/components/text-image-field/TextImageField.vue +3 -6
- package/src/shared/content-settings/components/text-items-field/TextItemsField.mixin.ts +1 -6
- package/src/shared/content-settings/components/text-items-field/TextItemsField.vue +1 -1
- package/src/utils/minify-brand-page-metadata.ts +1 -4
- package/lib/src/brand-page/utils/migration/migration-20.d.ts +0 -2
- package/lib/src/brand-page/utils/migration/migration-20.js +0 -66
- package/lib/src/brand-page-maker/__fixtures__/complex-rte.fixture.d.ts +0 -22
- package/lib/src/brand-page-maker/__fixtures__/complex-rte.fixture.js +0 -22
- package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.d.ts +0 -14
- package/lib/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.js +0 -39
- package/lib/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.d.ts +0 -28
- package/lib/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.js +0 -90
- package/lib/src/brand-page-maker/utils/rte-render.util.d.ts +0 -63
- package/lib/src/brand-page-maker/utils/rte-render.util.js +0 -95
- package/lib/src/brand-page-maker/utils/rte-sanitize.util.d.ts +0 -6
- package/lib/src/brand-page-maker/utils/rte-sanitize.util.js +0 -158
- package/src/brand-page/utils/migration/migration-20.server.test.ts +0 -125
- package/src/brand-page/utils/migration/migration-20.test.ts +0 -72
- package/src/brand-page/utils/migration/migration-20.ts +0 -87
- package/src/brand-page/utils/text.util.test.ts +0 -47
- package/src/brand-page/utils/view-model.pageid-rte.test.ts +0 -104
- package/src/brand-page-maker/__fixtures__/complex-rte.fixture.ts +0 -23
- package/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.test.ts +0 -52
- package/src/brand-page-maker/composables/rich-text-editor/extensions/FontFamily.ts +0 -42
- package/src/brand-page-maker/composables/rich-text-editor/getRteExtensions.ts +0 -137
- package/src/brand-page-maker/utils/__snapshots__/rte-render-parity.test.ts.snap +0 -202
- package/src/brand-page-maker/utils/rte-features.test.ts +0 -351
- package/src/brand-page-maker/utils/rte-render-parity.test.ts +0 -157
- package/src/brand-page-maker/utils/rte-render.util.ts +0 -165
- package/src/brand-page-maker/utils/rte-sanitize-json.test.ts +0 -158
- package/src/brand-page-maker/utils/rte-sanitize.util.ts +0 -195
- package/src/brand-page-maker/validators/field.validator.test.ts +0 -55
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { JSONContent } from '@tiptap/vue-3';
|
|
2
|
-
import { isTiptapDocument, getRteJsonPlainText } from './rich-text-editor.util';
|
|
3
|
-
export { isTiptapDocument, getRteJsonPlainText };
|
|
4
|
-
/**
|
|
5
|
-
* BP-5787 — the boundary plumbing for storing RTE as Tiptap JSON.
|
|
6
|
-
*
|
|
7
|
-
* An RTE field is either a legacy inline-HTML string (pre-migration, or a
|
|
8
|
-
* not-yet-migrated published site) or a Tiptap JSON document (post-migration).
|
|
9
|
-
* These helpers let every consumer treat the two uniformly:
|
|
10
|
-
*
|
|
11
|
-
* - isTiptapDocument — the canonical discriminator (object with type 'doc').
|
|
12
|
-
* - renderRteToHtml — render either form to final HTML for display.
|
|
13
|
-
* - toRteJson — normalise either form to JSON for storage.
|
|
14
|
-
*
|
|
15
|
-
* The schema-driven core of both directions is Tiptap/ProseMirror, fed by the
|
|
16
|
-
* single-source-of-truth extension set (getRteExtensions) — so the mapping lives
|
|
17
|
-
* in the extensions' schema, not a hand-maintained copy that drifts:
|
|
18
|
-
*
|
|
19
|
-
* - renderRteToHtml uses @tiptap/static-renderer (renderToHTMLString). It is
|
|
20
|
-
* DOM-less, so it runs on the server (SSR/publish/preview), not just the
|
|
21
|
-
* browser, and needs no Editor instance.
|
|
22
|
-
* - toRteJson turns an HTML string into a DOM node with an INJECTED parser and
|
|
23
|
-
* feeds it to ProseMirror's schema-driven DOMParser. The HTML→DOM step needs
|
|
24
|
-
* a DOM parser; rather than read the global `window.DOMParser` (as Tiptap's
|
|
25
|
-
* `generateJSON` does — unusable on a pure-node server and fragile across SSR
|
|
26
|
-
* execution contexts), the parser is supplied by the caller: the native
|
|
27
|
-
* `DOMParser` in the browser, a jsdom `DOMParser` *instance* on the server
|
|
28
|
-
* (see resolveHtmlParser). No global is ever mutated, so the conversion is
|
|
29
|
-
* fully isomorphic regardless of how the SSR host bundles/executes this code.
|
|
30
|
-
*/
|
|
31
|
-
export type RichTextValue = string | JSONContent;
|
|
32
|
-
/**
|
|
33
|
-
* A `DOMParser`-compatible object: turns an HTML string into a Document whose
|
|
34
|
-
* `body` is a DOM node ProseMirror can parse. The browser's native `DOMParser`
|
|
35
|
-
* and jsdom's `DOMParser` both satisfy this, so the DOM dependency is injected
|
|
36
|
-
* rather than read from a global.
|
|
37
|
-
*/
|
|
38
|
-
export interface HtmlParser {
|
|
39
|
-
parseFromString(html: string, type: 'text/html'): Document;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Render an RTE value to final HTML. Legacy HTML strings pass through untouched
|
|
43
|
-
* (they are already HTML); Tiptap JSON is serialised by @tiptap/static-renderer
|
|
44
|
-
* from the extension schema — no editor, no DOM — so it works on the server
|
|
45
|
-
* (SSR/publish), not just the browser.
|
|
46
|
-
*/
|
|
47
|
-
export declare const renderRteToHtml: (value: RichTextValue | null | undefined) => string;
|
|
48
|
-
/**
|
|
49
|
-
* Resolve an HtmlParser for the current runtime: the native `DOMParser` in the
|
|
50
|
-
* browser (and jsdom-based test envs), or a jsdom `DOMParser` INSTANCE on a
|
|
51
|
-
* pure-node server — created and returned directly, never assigned to a global,
|
|
52
|
-
* so it is immune to SSR execution-context differences. The jsdom specifier is
|
|
53
|
-
* assembled at runtime so no bundler follows it into a browser build. Memoised
|
|
54
|
-
* on the server (JSDOM construction is relatively expensive).
|
|
55
|
-
*/
|
|
56
|
-
export declare const resolveHtmlParser: () => Promise<HtmlParser>;
|
|
57
|
-
/**
|
|
58
|
-
* Normalise an RTE value to a Tiptap JSON document. HTML strings are parsed with
|
|
59
|
-
* `parser` (defaults to the browser's native DOMParser); JSON documents pass
|
|
60
|
-
* through unchanged. Returns undefined for empty/blank input so callers can omit
|
|
61
|
-
* empty fields.
|
|
62
|
-
*/
|
|
63
|
-
export declare const toRteJson: (value: RichTextValue | null | undefined, parser?: HtmlParser) => JSONContent | undefined;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { getSchema } from '@tiptap/core';
|
|
2
|
-
import { DOMParser as ProseMirrorDOMParser } from '@tiptap/pm/model';
|
|
3
|
-
import { renderToHTMLString } from '@tiptap/static-renderer/pm/html-string';
|
|
4
|
-
import { getRteExtensions } from '../composables/rich-text-editor/getRteExtensions';
|
|
5
|
-
import { isTiptapDocument, getRteJsonPlainText } from './rich-text-editor.util';
|
|
6
|
-
export { isTiptapDocument, getRteJsonPlainText };
|
|
7
|
-
// One extension set shared by both directions (render + parse). Schema knowledge
|
|
8
|
-
// lives here, once — Tiptap/extension upgrades propagate to both automatically.
|
|
9
|
-
const RTE_EXTENSIONS = getRteExtensions({ includeLinkRel: true });
|
|
10
|
-
// ProseMirror schema derived once from the shared extension set. This is the
|
|
11
|
-
// schema-driven heart of HTML→JSON (no drift); only the HTML→DOM step is injected.
|
|
12
|
-
const RTE_SCHEMA = getSchema(RTE_EXTENSIONS);
|
|
13
|
-
/**
|
|
14
|
-
* Render an RTE value to final HTML. Legacy HTML strings pass through untouched
|
|
15
|
-
* (they are already HTML); Tiptap JSON is serialised by @tiptap/static-renderer
|
|
16
|
-
* from the extension schema — no editor, no DOM — so it works on the server
|
|
17
|
-
* (SSR/publish), not just the browser.
|
|
18
|
-
*/
|
|
19
|
-
export const renderRteToHtml = (value) => {
|
|
20
|
-
if (value == null || value === '')
|
|
21
|
-
return '';
|
|
22
|
-
if (typeof value === 'string')
|
|
23
|
-
return value;
|
|
24
|
-
return renderToHTMLString({ content: value, extensions: RTE_EXTENSIONS });
|
|
25
|
-
};
|
|
26
|
-
// Tiptap's elementFromString strips whitespace-only text nodes (pretty-print
|
|
27
|
-
// indentation between tags) before parsing; replicate it so injected-parser
|
|
28
|
-
// output stays identical to the previous generateJSON-based conversion.
|
|
29
|
-
const stripIndentationTextNodes = (node) => {
|
|
30
|
-
const children = node.childNodes;
|
|
31
|
-
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
32
|
-
const child = children[i];
|
|
33
|
-
if (child.nodeType === 3 &&
|
|
34
|
-
child.nodeValue &&
|
|
35
|
-
/^(\n\s\s|\n)$/.test(child.nodeValue)) {
|
|
36
|
-
node.removeChild(child);
|
|
37
|
-
}
|
|
38
|
-
else if (child.nodeType === 1) {
|
|
39
|
-
stripIndentationTextNodes(child);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return node;
|
|
43
|
-
};
|
|
44
|
-
const htmlToRteJson = (html, parser) => {
|
|
45
|
-
const body = parser.parseFromString(`<body>${html}</body>`, 'text/html').body;
|
|
46
|
-
const dom = stripIndentationTextNodes(body);
|
|
47
|
-
return ProseMirrorDOMParser.fromSchema(RTE_SCHEMA).parse(dom).toJSON();
|
|
48
|
-
};
|
|
49
|
-
let serverParserPromise = null;
|
|
50
|
-
/**
|
|
51
|
-
* Resolve an HtmlParser for the current runtime: the native `DOMParser` in the
|
|
52
|
-
* browser (and jsdom-based test envs), or a jsdom `DOMParser` INSTANCE on a
|
|
53
|
-
* pure-node server — created and returned directly, never assigned to a global,
|
|
54
|
-
* so it is immune to SSR execution-context differences. The jsdom specifier is
|
|
55
|
-
* assembled at runtime so no bundler follows it into a browser build. Memoised
|
|
56
|
-
* on the server (JSDOM construction is relatively expensive).
|
|
57
|
-
*/
|
|
58
|
-
export const resolveHtmlParser = async () => {
|
|
59
|
-
if (typeof DOMParser !== 'undefined')
|
|
60
|
-
return new DOMParser();
|
|
61
|
-
if (!serverParserPromise) {
|
|
62
|
-
const jsdomModuleId = ['js', 'dom'].join('');
|
|
63
|
-
serverParserPromise = import(/* @vite-ignore */ jsdomModuleId)
|
|
64
|
-
.then((mod) => {
|
|
65
|
-
const { JSDOM } = mod;
|
|
66
|
-
const { DOMParser: JsdomDOMParser } = new JSDOM('').window;
|
|
67
|
-
return new JsdomDOMParser();
|
|
68
|
-
})
|
|
69
|
-
.catch((error) => {
|
|
70
|
-
// Don't cache the failure — let a later call retry the import.
|
|
71
|
-
serverParserPromise = null;
|
|
72
|
-
throw error;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return serverParserPromise;
|
|
76
|
-
};
|
|
77
|
-
const getDefaultParser = () => {
|
|
78
|
-
if (typeof DOMParser !== 'undefined')
|
|
79
|
-
return new DOMParser();
|
|
80
|
-
throw new Error('toRteJson: no global DOMParser in this environment. On the server, pass an ' +
|
|
81
|
-
'explicit parser as the second argument (see resolveHtmlParser).');
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Normalise an RTE value to a Tiptap JSON document. HTML strings are parsed with
|
|
85
|
-
* `parser` (defaults to the browser's native DOMParser); JSON documents pass
|
|
86
|
-
* through unchanged. Returns undefined for empty/blank input so callers can omit
|
|
87
|
-
* empty fields.
|
|
88
|
-
*/
|
|
89
|
-
export const toRteJson = (value, parser) => {
|
|
90
|
-
if (value == null || value === '')
|
|
91
|
-
return undefined;
|
|
92
|
-
if (isTiptapDocument(value))
|
|
93
|
-
return value;
|
|
94
|
-
return htmlToRteJson(value, parser ?? getDefaultParser());
|
|
95
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { validateAndSanitizeHref } from './rich-text-editor.util';
|
|
2
|
-
/**
|
|
3
|
-
* BP-5787 — native JSON sanitiser for RTE content.
|
|
4
|
-
*
|
|
5
|
-
* Operates directly on the Tiptap document tree: no editor instantiation, no
|
|
6
|
-
* HTML round-trip, no DOMPurify. This is the hot path (runs on every editor
|
|
7
|
-
* update and on the server sanitise gate), so it is a single, allocation-light
|
|
8
|
-
* recursive walk.
|
|
9
|
-
*
|
|
10
|
-
* Security model (mirrors the HTML allowlist it replaces):
|
|
11
|
-
* - only allow-listed node and mark types survive; everything else is dropped;
|
|
12
|
-
* - textStyle / highlight attrs are restricted to known keys whose values must
|
|
13
|
-
* be "safe CSS values" (no quotes/angle-brackets/extra declarations/url()/
|
|
14
|
-
* expression()), preventing CSS-injection when the value is later rendered
|
|
15
|
-
* into a `style="…"` attribute;
|
|
16
|
-
* - link hrefs go through the same validateAndSanitizeHref used by the HTML
|
|
17
|
-
* sanitiser; unsafe links lose their href (and the mark);
|
|
18
|
-
* - heading levels are clamped to 1–6.
|
|
19
|
-
*/
|
|
20
|
-
// ProseMirror node types the editor schema can legitimately produce.
|
|
21
|
-
const ALLOWED_NODE_TYPES = new Set([
|
|
22
|
-
'doc',
|
|
23
|
-
'paragraph',
|
|
24
|
-
'heading',
|
|
25
|
-
'text',
|
|
26
|
-
'hardBreak',
|
|
27
|
-
'bulletList',
|
|
28
|
-
'orderedList',
|
|
29
|
-
'listItem',
|
|
30
|
-
'blockquote',
|
|
31
|
-
'codeBlock',
|
|
32
|
-
'horizontalRule',
|
|
33
|
-
]);
|
|
34
|
-
// Inline mark types the editor produces (strong/em/u/s/code/span/mark/a).
|
|
35
|
-
const ALLOWED_MARK_TYPES = new Set([
|
|
36
|
-
'bold',
|
|
37
|
-
'italic',
|
|
38
|
-
'underline',
|
|
39
|
-
'strike',
|
|
40
|
-
'code',
|
|
41
|
-
'textStyle',
|
|
42
|
-
'highlight',
|
|
43
|
-
'link',
|
|
44
|
-
]);
|
|
45
|
-
// textStyle attrs map to the allow-listed CSS properties (font-weight →
|
|
46
|
-
// bold mark, text-decoration → underline/strike, text-align → node attr,
|
|
47
|
-
// background-color → highlight, so they are intentionally not here).
|
|
48
|
-
const ALLOWED_TEXT_STYLE_ATTRS = new Set([
|
|
49
|
-
'color',
|
|
50
|
-
'fontFamily',
|
|
51
|
-
'fontSize',
|
|
52
|
-
'letterSpacing',
|
|
53
|
-
'lineHeight',
|
|
54
|
-
]);
|
|
55
|
-
/**
|
|
56
|
-
* A safe CSS value is a short string free of characters that could inject an
|
|
57
|
-
* extra declaration or escape the attribute, and free of the url()/expression()
|
|
58
|
-
* vectors. Legitimate values — `rgb(255, 0, 0)`, `#FF0000`,
|
|
59
|
-
* `var(--logo-text-color)`, `Open Sans`, `1.5em` — all pass.
|
|
60
|
-
*/
|
|
61
|
-
const isSafeCssValue = (value) => typeof value === 'string' &&
|
|
62
|
-
value.length > 0 &&
|
|
63
|
-
value.length <= 200 &&
|
|
64
|
-
!/[<>"';]/.test(value) &&
|
|
65
|
-
!/url\s*\(/i.test(value) &&
|
|
66
|
-
!/expression\s*\(/i.test(value);
|
|
67
|
-
const sanitizeTextStyleAttrs = (attrs) => {
|
|
68
|
-
const clean = {};
|
|
69
|
-
for (const key of Object.keys(attrs)) {
|
|
70
|
-
if (!ALLOWED_TEXT_STYLE_ATTRS.has(key))
|
|
71
|
-
continue;
|
|
72
|
-
const value = attrs[key];
|
|
73
|
-
// Tiptap emits '' for unset textStyle slots — preserve them.
|
|
74
|
-
if (value === '' || value == null) {
|
|
75
|
-
clean[key] = '';
|
|
76
|
-
}
|
|
77
|
-
else if (isSafeCssValue(value)) {
|
|
78
|
-
clean[key] = value;
|
|
79
|
-
}
|
|
80
|
-
// else: drop the unsafe value
|
|
81
|
-
}
|
|
82
|
-
return Object.keys(clean).length ? clean : null;
|
|
83
|
-
};
|
|
84
|
-
const sanitizeMark = (mark) => {
|
|
85
|
-
const type = mark?.type;
|
|
86
|
-
if (!type || !ALLOWED_MARK_TYPES.has(type))
|
|
87
|
-
return null;
|
|
88
|
-
const attrs = mark.attrs;
|
|
89
|
-
if (type === 'link') {
|
|
90
|
-
const href = typeof attrs?.href === 'string'
|
|
91
|
-
? validateAndSanitizeHref(attrs.href)
|
|
92
|
-
: null;
|
|
93
|
-
if (!href)
|
|
94
|
-
return null; // drop links with unsafe/empty href
|
|
95
|
-
const cleanAttrs = { href };
|
|
96
|
-
if (attrs?.target != null)
|
|
97
|
-
cleanAttrs.target = attrs.target;
|
|
98
|
-
if (attrs?.rel != null)
|
|
99
|
-
cleanAttrs.rel = attrs.rel;
|
|
100
|
-
return { type, attrs: cleanAttrs };
|
|
101
|
-
}
|
|
102
|
-
if (type === 'textStyle') {
|
|
103
|
-
const clean = attrs ? sanitizeTextStyleAttrs(attrs) : null;
|
|
104
|
-
return clean ? { type, attrs: clean } : null;
|
|
105
|
-
}
|
|
106
|
-
if (type === 'highlight') {
|
|
107
|
-
return isSafeCssValue(attrs?.color)
|
|
108
|
-
? { type, attrs: { color: attrs.color } }
|
|
109
|
-
: { type };
|
|
110
|
-
}
|
|
111
|
-
// Plain marks (bold/italic/underline/strike/code) carry no attrs.
|
|
112
|
-
return { type };
|
|
113
|
-
};
|
|
114
|
-
const ALIGN_VALUES = new Set(['left', 'center', 'right', 'justify']);
|
|
115
|
-
const sanitizeNode = (node) => {
|
|
116
|
-
const type = node?.type;
|
|
117
|
-
if (!type || !ALLOWED_NODE_TYPES.has(type))
|
|
118
|
-
return null;
|
|
119
|
-
const clean = { type };
|
|
120
|
-
const attrs = {};
|
|
121
|
-
if (type === 'heading') {
|
|
122
|
-
const level = Number(node.attrs?.level);
|
|
123
|
-
attrs.level = level >= 1 && level <= 6 ? level : 1;
|
|
124
|
-
}
|
|
125
|
-
if (type === 'heading' || type === 'paragraph') {
|
|
126
|
-
const align = node.attrs?.textAlign;
|
|
127
|
-
if (typeof align === 'string' && ALIGN_VALUES.has(align)) {
|
|
128
|
-
attrs.textAlign = align;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (Object.keys(attrs).length)
|
|
132
|
-
clean.attrs = attrs;
|
|
133
|
-
if (typeof node.text === 'string')
|
|
134
|
-
clean.text = node.text;
|
|
135
|
-
if (Array.isArray(node.marks)) {
|
|
136
|
-
const marks = node.marks
|
|
137
|
-
.map((m) => sanitizeMark(m))
|
|
138
|
-
.filter(Boolean);
|
|
139
|
-
if (marks && marks.length)
|
|
140
|
-
clean.marks = marks;
|
|
141
|
-
}
|
|
142
|
-
if (Array.isArray(node.content)) {
|
|
143
|
-
const content = node.content
|
|
144
|
-
.map(sanitizeNode)
|
|
145
|
-
.filter(Boolean);
|
|
146
|
-
if (content.length)
|
|
147
|
-
clean.content = content;
|
|
148
|
-
}
|
|
149
|
-
return clean;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Sanitise a Tiptap JSON document (returns a new clean doc). Returns a minimal
|
|
153
|
-
* empty doc if the input isn't a usable document.
|
|
154
|
-
*/
|
|
155
|
-
export const sanitizeRteJson = (doc) => {
|
|
156
|
-
const clean = doc && typeof doc === 'object' ? sanitizeNode(doc) : null;
|
|
157
|
-
return clean && clean.type === 'doc' ? clean : { type: 'doc', content: [] };
|
|
158
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BP-5787 — migration-20 must convert HTML RTE → Tiptap JSON on the SERVER, not
|
|
3
|
-
* just the browser. The HTML→JSON parse needs a DOM parser, which pure-node SSR
|
|
4
|
-
* lacks. migration-20 resolves one via `resolveHtmlParser` — a jsdom `DOMParser`
|
|
5
|
-
* INSTANCE on the server (no global mutation), threaded explicitly into the pass.
|
|
6
|
-
*
|
|
7
|
-
* These tests run under the default jsdom environment but DELETE the global
|
|
8
|
-
* `window`/`document`/`DOMParser` around each case, so `resolveHtmlParser` takes
|
|
9
|
-
* its real pure-node branch (dynamic jsdom import → parser instance). The sibling
|
|
10
|
-
* migration-20.test.ts guards the browser path (native global DOMParser).
|
|
11
|
-
*/
|
|
12
|
-
import { describe, test, expect, beforeEach, afterEach } from 'vitest';
|
|
13
|
-
import { migration20 } from './migration-20';
|
|
14
|
-
import type { MigrationData } from '../migration.util';
|
|
15
|
-
import { isTiptapDocument, getRteJsonPlainText } from '@brand-page-maker/utils';
|
|
16
|
-
|
|
17
|
-
const createMigrationData = (brandPageData: any): MigrationData =>
|
|
18
|
-
({ brandPageModel: brandPageData }) as MigrationData;
|
|
19
|
-
|
|
20
|
-
const model = (contents: any[]) => ({
|
|
21
|
-
pages: [{ id: 'p1', title: 'Home', slug: 'home', contents }],
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const g = globalThis as any;
|
|
25
|
-
let savedWindow: unknown;
|
|
26
|
-
let savedDocument: unknown;
|
|
27
|
-
let savedDOMParser: unknown;
|
|
28
|
-
|
|
29
|
-
describe('migration20 (server / no DOM) — HTML RTE → Tiptap JSON', () => {
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
// Force the pure-node path: no global window/document AND no global
|
|
32
|
-
// DOMParser, so resolveHtmlParser must load jsdom itself.
|
|
33
|
-
savedWindow = g.window;
|
|
34
|
-
savedDocument = g.document;
|
|
35
|
-
savedDOMParser = g.DOMParser;
|
|
36
|
-
delete g.window;
|
|
37
|
-
delete g.document;
|
|
38
|
-
delete g.DOMParser;
|
|
39
|
-
|
|
40
|
-
expect(typeof window).toBe('undefined');
|
|
41
|
-
expect(typeof document).toBe('undefined');
|
|
42
|
-
expect(typeof DOMParser).toBe('undefined');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
afterEach(() => {
|
|
46
|
-
g.window = savedWindow;
|
|
47
|
-
g.document = savedDocument;
|
|
48
|
-
g.DOMParser = savedDOMParser;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('converts a top-level HTML RTE field with no global DOM', async () => {
|
|
52
|
-
const data = model([
|
|
53
|
-
{
|
|
54
|
-
id: '1',
|
|
55
|
-
type: 'banner-section',
|
|
56
|
-
title:
|
|
57
|
-
'<p><span style="color: var(--logo-text-color)">Hello</span></p>',
|
|
58
|
-
},
|
|
59
|
-
]);
|
|
60
|
-
|
|
61
|
-
const result = await migration20(createMigrationData(data));
|
|
62
|
-
const title = (result.brandPageModel.pages[0].contents[0] as any).title;
|
|
63
|
-
|
|
64
|
-
expect(isTiptapDocument(title)).toBe(true);
|
|
65
|
-
expect(getRteJsonPlainText(title)).toContain('Hello');
|
|
66
|
-
// theme token ref preserved through the server-side parse
|
|
67
|
-
expect(JSON.stringify(title)).toContain('var(--logo-text-color)');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('converts RTE inside item arrays server-side (marks preserved)', async () => {
|
|
71
|
-
const data = model([
|
|
72
|
-
{
|
|
73
|
-
id: '2',
|
|
74
|
-
type: 'text',
|
|
75
|
-
textItems: [{ id: 'ti1', text: '<p><strong>bold</strong> item</p>' }],
|
|
76
|
-
},
|
|
77
|
-
]);
|
|
78
|
-
|
|
79
|
-
const result = await migration20(createMigrationData(data));
|
|
80
|
-
const item = (result.brandPageModel.pages[0].contents[0] as any)
|
|
81
|
-
.textItems[0];
|
|
82
|
-
|
|
83
|
-
expect(isTiptapDocument(item.text)).toBe(true);
|
|
84
|
-
expect(getRteJsonPlainText(item.text)).toContain('bold');
|
|
85
|
-
// the <strong> mark survived the jsdom parse
|
|
86
|
-
expect(JSON.stringify(item.text)).toContain('bold');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('leaves plain strings and already-JSON content untouched (idempotent)', async () => {
|
|
90
|
-
const jsonDoc = {
|
|
91
|
-
type: 'doc',
|
|
92
|
-
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'X' }] }],
|
|
93
|
-
};
|
|
94
|
-
const data = model([
|
|
95
|
-
{
|
|
96
|
-
id: '3',
|
|
97
|
-
type: 'banner-section',
|
|
98
|
-
title: jsonDoc, // already JSON
|
|
99
|
-
url: 'https://example.com', // plain string, not RTE
|
|
100
|
-
titleStyle: { color: '#fff', fontSize: '1em' }, // style object, untouched
|
|
101
|
-
},
|
|
102
|
-
]);
|
|
103
|
-
|
|
104
|
-
const result = await migration20(createMigrationData(data));
|
|
105
|
-
const c = result.brandPageModel.pages[0].contents[0] as any;
|
|
106
|
-
|
|
107
|
-
expect(c.title).toEqual(jsonDoc);
|
|
108
|
-
expect(c.url).toBe('https://example.com');
|
|
109
|
-
expect(c.titleStyle).toEqual({ color: '#fff', fontSize: '1em' });
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('does not mutate globalThis (no window/document/DOMParser leak)', async () => {
|
|
113
|
-
const data = model([
|
|
114
|
-
{ id: '4', type: 'banner-section', title: '<p>Leak check</p>' },
|
|
115
|
-
]);
|
|
116
|
-
|
|
117
|
-
await migration20(createMigrationData(data));
|
|
118
|
-
|
|
119
|
-
// The pass resolves a parser INSTANCE and never assigns to globalThis, so the
|
|
120
|
-
// deleted globals must stay absent — no transient install, nothing to leak.
|
|
121
|
-
expect(typeof window).toBe('undefined');
|
|
122
|
-
expect(typeof document).toBe('undefined');
|
|
123
|
-
expect(typeof DOMParser).toBe('undefined');
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'vitest';
|
|
2
|
-
import { migration20 } from './migration-20';
|
|
3
|
-
import type { MigrationData } from '../migration.util';
|
|
4
|
-
import { isTiptapDocument, getRteJsonPlainText } from '@brand-page-maker/utils';
|
|
5
|
-
|
|
6
|
-
const createMigrationData = (brandPageData: any): MigrationData =>
|
|
7
|
-
({ brandPageModel: brandPageData }) as MigrationData;
|
|
8
|
-
|
|
9
|
-
const model = (contents: any[]) => ({
|
|
10
|
-
pages: [{ id: 'p1', title: 'Home', slug: 'home', contents }],
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe('migration20 — HTML RTE → Tiptap JSON', () => {
|
|
14
|
-
test('converts a top-level HTML RTE field to a JSON document', async () => {
|
|
15
|
-
const data = model([
|
|
16
|
-
{
|
|
17
|
-
id: '1',
|
|
18
|
-
type: 'banner-section',
|
|
19
|
-
title:
|
|
20
|
-
'<p><span style="color: var(--logo-text-color)">Hello</span></p>',
|
|
21
|
-
},
|
|
22
|
-
]);
|
|
23
|
-
|
|
24
|
-
const result = await migration20(createMigrationData(data));
|
|
25
|
-
const title = (result.brandPageModel.pages[0].contents[0] as any).title;
|
|
26
|
-
|
|
27
|
-
expect(isTiptapDocument(title)).toBe(true);
|
|
28
|
-
expect(getRteJsonPlainText(title)).toContain('Hello');
|
|
29
|
-
// theme token ref preserved through migration
|
|
30
|
-
expect(JSON.stringify(title)).toContain('var(--logo-text-color)');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('converts RTE inside item arrays (text items / testimonials)', async () => {
|
|
34
|
-
const data = model([
|
|
35
|
-
{
|
|
36
|
-
id: '2',
|
|
37
|
-
type: 'text',
|
|
38
|
-
textItems: [{ id: 'ti1', text: '<p><strong>bold</strong> item</p>' }],
|
|
39
|
-
},
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
const result = await migration20(createMigrationData(data));
|
|
43
|
-
const item = (result.brandPageModel.pages[0].contents[0] as any)
|
|
44
|
-
.textItems[0];
|
|
45
|
-
|
|
46
|
-
expect(isTiptapDocument(item.text)).toBe(true);
|
|
47
|
-
expect(getRteJsonPlainText(item.text)).toContain('bold');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('leaves plain strings and already-JSON content untouched (idempotent)', async () => {
|
|
51
|
-
const jsonDoc = {
|
|
52
|
-
type: 'doc',
|
|
53
|
-
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'X' }] }],
|
|
54
|
-
};
|
|
55
|
-
const data = model([
|
|
56
|
-
{
|
|
57
|
-
id: '3',
|
|
58
|
-
type: 'banner-section',
|
|
59
|
-
title: jsonDoc, // already JSON
|
|
60
|
-
url: 'https://example.com', // plain string, not RTE
|
|
61
|
-
titleStyle: { color: '#fff', fontSize: '1em' }, // style object, untouched
|
|
62
|
-
},
|
|
63
|
-
]);
|
|
64
|
-
|
|
65
|
-
const result = await migration20(createMigrationData(data));
|
|
66
|
-
const c = result.brandPageModel.pages[0].contents[0] as any;
|
|
67
|
-
|
|
68
|
-
expect(c.title).toEqual(jsonDoc);
|
|
69
|
-
expect(c.url).toBe('https://example.com');
|
|
70
|
-
expect(c.titleStyle).toEqual({ color: '#fff', fontSize: '1em' });
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { BrandPageModel } from '../../models';
|
|
2
|
-
import type { MigrationData } from '../migration.util';
|
|
3
|
-
import {
|
|
4
|
-
hasRTEContent,
|
|
5
|
-
toRteJson,
|
|
6
|
-
resolveHtmlParser,
|
|
7
|
-
type HtmlParser,
|
|
8
|
-
} from '../../../brand-page-maker/utils';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* BP-5787 — migrate existing inline-HTML RTE content to Tiptap JSON.
|
|
12
|
-
*
|
|
13
|
-
* The editor emits, and the renderer reads, Tiptap JSON. Existing
|
|
14
|
-
* published/saved sites still hold RTE fields as HTML strings. This converts
|
|
15
|
-
* them on load, in EVERY environment:
|
|
16
|
-
* - maker (browser): the loaded model is JSON, so the next save persists JSON.
|
|
17
|
-
* - web-renderer (SSR / server API routes): converted on read, so old sites
|
|
18
|
-
* are normalised without a re-save and downstream code can treat RTE as JSON.
|
|
19
|
-
*
|
|
20
|
-
* This is a one-time, versioned migration (runAlways is NOT set): legacy sites
|
|
21
|
-
* are at model version < 20 and convert on first load in any environment; once
|
|
22
|
-
* `v` is stamped to 20 the conversion is skipped. This is only safe because the
|
|
23
|
-
* AI section builders now emit Tiptap JSON directly (they no longer write HTML),
|
|
24
|
-
* so there is no recurring post-load source of HTML to normalise.
|
|
25
|
-
*
|
|
26
|
-
* HTML→JSON parsing needs a DOM parser. Rather than mutate a global `window`,
|
|
27
|
-
* the parser is resolved once (native `DOMParser` in the browser, a jsdom
|
|
28
|
-
* `DOMParser` instance on the server) and threaded explicitly through the
|
|
29
|
-
* conversion — see resolveHtmlParser / toRteJson. No global state is touched, so
|
|
30
|
-
* the pass is safe on any server runtime and under concurrent requests.
|
|
31
|
-
*
|
|
32
|
-
* Scope: only HTML-RTE strings (hasRTEContent) are converted. Plain strings,
|
|
33
|
-
* numbers, and already-JSON docs are left untouched, so the migration is
|
|
34
|
-
* idempotent (re-running on JSON content is a no-op — non-string values are
|
|
35
|
-
* skipped). Nested RTE inside item arrays (textItems, testimonials, images…)
|
|
36
|
-
* is handled by recursing into arrays; style objects are intentionally not
|
|
37
|
-
* descended into (they never hold RTE content).
|
|
38
|
-
*/
|
|
39
|
-
const convertRteStringsToJson = (value: unknown, parser: HtmlParser): void => {
|
|
40
|
-
if (Array.isArray(value)) {
|
|
41
|
-
value.forEach((item) => convertRteStringsToJson(item, parser));
|
|
42
|
-
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!value || typeof value !== 'object') return;
|
|
47
|
-
|
|
48
|
-
const record = value as Record<string, unknown>;
|
|
49
|
-
|
|
50
|
-
Object.keys(record).forEach((key) => {
|
|
51
|
-
const field = record[key];
|
|
52
|
-
|
|
53
|
-
if (typeof field === 'string' && hasRTEContent(field)) {
|
|
54
|
-
const json = toRteJson(field, parser);
|
|
55
|
-
|
|
56
|
-
if (json) record[key] = json;
|
|
57
|
-
} else if (Array.isArray(field)) {
|
|
58
|
-
convertRteStringsToJson(field, parser);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const convertModel = (
|
|
64
|
-
brandPageModel: BrandPageModel,
|
|
65
|
-
parser: HtmlParser,
|
|
66
|
-
): void => {
|
|
67
|
-
for (const page of brandPageModel.pages) {
|
|
68
|
-
for (const content of page.contents) {
|
|
69
|
-
convertRteStringsToJson(content, parser);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const migration20 = async (
|
|
75
|
-
migrationResult: MigrationData,
|
|
76
|
-
): Promise<MigrationData> => {
|
|
77
|
-
const { brandPageModel } = migrationResult;
|
|
78
|
-
|
|
79
|
-
// Resolve a DOM parser for this environment (native in the browser, a jsdom
|
|
80
|
-
// instance on the server — never touching globals), then convert every
|
|
81
|
-
// HTML-RTE field to Tiptap JSON with it.
|
|
82
|
-
const parser = await resolveHtmlParser();
|
|
83
|
-
|
|
84
|
-
convertModel(brandPageModel, parser);
|
|
85
|
-
|
|
86
|
-
return migrationResult;
|
|
87
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { escapeContentText, getRenderText } from './text.util';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* BP-5787 — escapeContentText / getRenderText must accept either a legacy
|
|
6
|
-
* inline-HTML string or a Tiptap JSON document without throwing. Section
|
|
7
|
-
* components call these on RTE fields (e.g. banner description), which are now
|
|
8
|
-
* JSON; the previous string-only versions threw `.replace is not a function`
|
|
9
|
-
* and broke the field's reactivity (strike/format edits stopped rendering).
|
|
10
|
-
*/
|
|
11
|
-
const doc = {
|
|
12
|
-
type: 'doc',
|
|
13
|
-
content: [
|
|
14
|
-
{
|
|
15
|
-
type: 'paragraph',
|
|
16
|
-
content: [
|
|
17
|
-
{ type: 'text', text: 'WARNING', marks: [{ type: 'strike' }] },
|
|
18
|
-
{ type: 'text', text: ': take flight' },
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
describe('escapeContentText (BP-5787 dual-read)', () => {
|
|
25
|
-
it('extracts plain text from a Tiptap JSON document', () => {
|
|
26
|
-
expect(escapeContentText(doc)).toBe('WARNING : take flight');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('still strips tags from a legacy HTML string', () => {
|
|
30
|
-
expect(escapeContentText('<p><s>WARNING</s></p>')).toBe('WARNING');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('returns falsy input unchanged', () => {
|
|
34
|
-
expect(escapeContentText('')).toBe('');
|
|
35
|
-
expect(escapeContentText(undefined)).toBeUndefined();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('getRenderText (BP-5787 JSON-safe)', () => {
|
|
40
|
-
it('passes a Tiptap JSON document through untouched (no throw)', () => {
|
|
41
|
-
expect(getRenderText(doc as unknown as string)).toBe(doc);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('still converts newlines to <br/> for plain strings', () => {
|
|
45
|
-
expect(getRenderText('a\nb')).toBe('a<br/>b');
|
|
46
|
-
});
|
|
47
|
-
});
|