@squiz/formatted-text-editor 2.7.2 → 2.8.0
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/CHANGELOG.md +6 -0
- package/jest.config.ts +2 -0
- package/jest.preset-mocks.ts +17 -0
- package/lib/Extensions/CodeBlockExtension/CodeBlockExtension.js +3 -0
- package/package.json +1 -1
- package/src/Extensions/CodeBlockExtension/CodeBlockExtension.spec.ts +6 -8
- package/src/Extensions/CodeBlockExtension/CodeBlockExtension.ts +3 -0
- package/src/Extensions/ImageExtension/AssetImageExtension.spec.ts +2 -1
- package/src/Extensions/ImageExtension/DAMImageExtension.spec.ts +2 -1
- package/tests/highchartsReactMock.ts +17 -0
package/CHANGELOG.md
CHANGED
package/jest.config.ts
CHANGED
|
@@ -19,7 +19,9 @@ export default {
|
|
|
19
19
|
resetMocks: true,
|
|
20
20
|
resetModules: true,
|
|
21
21
|
testEnvironment: 'jsdom',
|
|
22
|
+
setupFiles: ['<rootDir>/jest.preset-mocks.ts'],
|
|
22
23
|
moduleNameMapper: {
|
|
24
|
+
'^@highcharts/react(.*)$': '<rootDir>/tests/highchartsReactMock.ts',
|
|
23
25
|
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css|scss)$':
|
|
24
26
|
'<rootDir>/file-transformer.js',
|
|
25
27
|
},
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
/**
|
|
3
|
+
* Runs via `setupFiles`, i.e. before any test module (and before jest.bootstrap.ts) is loaded.
|
|
4
|
+
*/
|
|
5
|
+
import { TextDecoder, TextEncoder } from 'node:util';
|
|
6
|
+
|
|
7
|
+
// Required by react-router (pulled in via @squiz/sds) under jsdom.
|
|
8
|
+
Object.assign(globalThis, { TextEncoder, TextDecoder });
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* jest-remirror imports sanitize-html, which depends on the ESM-only htmlparser2@12 that Jest 29 cannot load.
|
|
12
|
+
* Only jest-remirror's test helpers use it, so a passthrough stub is enough for these unit tests.
|
|
13
|
+
*/
|
|
14
|
+
jest.mock('sanitize-html', () => {
|
|
15
|
+
const sanitize = (dirty: string) => dirty;
|
|
16
|
+
return { __esModule: true, default: sanitize };
|
|
17
|
+
});
|
|
@@ -36,6 +36,9 @@ let CodeBlockExtension = class CodeBlockExtension extends core_1.NodeExtension {
|
|
|
36
36
|
{
|
|
37
37
|
tag: 'pre',
|
|
38
38
|
preserveWhitespace: 'full',
|
|
39
|
+
// Read the content from the nested <code> element, otherwise the nested <code> is parsed as a
|
|
40
|
+
// second code block (which cannot be nested), leaving this one empty.
|
|
41
|
+
contentElement: 'code',
|
|
39
42
|
getAttrs: (node) => {
|
|
40
43
|
if (!(0, remirror_1.isElementDomNode)(node) || !(0, remirror_1.isElementDomNode)(node.querySelector('code'))) {
|
|
41
44
|
return false;
|
package/package.json
CHANGED
|
@@ -40,20 +40,18 @@ describe('CodeBlockExtension', () => {
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
it('Does not parse a non-<code> HTML tag wrapped in a <pre> tag', async () => {
|
|
43
|
-
const { getJsonContent } = await renderWithEditor(null, {
|
|
44
|
-
content: `<pre><p>This is an un-expected node structure.</p></
|
|
43
|
+
const { getJsonContent, editor } = await renderWithEditor(null, {
|
|
44
|
+
content: `<pre><p>This is an un-expected node structure.</p></pre>`,
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
expect(getJsonContent()).toEqual({
|
|
48
48
|
// parsed by the PreformattedExtension, not the CodeBlockExtension.
|
|
49
49
|
type: 'preformatted',
|
|
50
50
|
attrs: expect.any(Object),
|
|
51
|
-
content: [
|
|
52
|
-
{
|
|
53
|
-
type: 'text',
|
|
54
|
-
text: 'This is an un-expected node structure.',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
51
|
});
|
|
52
|
+
|
|
53
|
+
// A <p> is not valid inline content, so it is lifted out of the preformatted node into a sibling paragraph.
|
|
54
|
+
expect(editor.state.doc.child(1).type.name).toBe('paragraph');
|
|
55
|
+
expect(editor.state.doc.textContent).toBe('This is an un-expected node structure.');
|
|
58
56
|
});
|
|
59
57
|
});
|
|
@@ -50,6 +50,9 @@ export class CodeBlockExtension extends NodeExtension<CodeBlockOptions> {
|
|
|
50
50
|
{
|
|
51
51
|
tag: 'pre',
|
|
52
52
|
preserveWhitespace: 'full',
|
|
53
|
+
// Read the content from the nested <code> element, otherwise the nested <code> is parsed as a
|
|
54
|
+
// second code block (which cannot be nested), leaving this one empty.
|
|
55
|
+
contentElement: 'code',
|
|
53
56
|
getAttrs: (node) => {
|
|
54
57
|
if (!isElementDomNode(node) || !isElementDomNode(node.querySelector('code'))) {
|
|
55
58
|
return false;
|
|
@@ -64,7 +64,8 @@ describe('AssetImageExtension', () => {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
expect(getHtmlContent()).toEqual(
|
|
67
|
-
'<img ' +
|
|
67
|
+
'<img class="ProseMirror-separator" alt="">' +
|
|
68
|
+
'<img ' +
|
|
68
69
|
'src="https://default-resource/" ' +
|
|
69
70
|
'data-matrix-asset-id="123" ' +
|
|
70
71
|
'data-matrix-identifier="matrix-api-identifier" ' +
|
|
@@ -73,7 +73,8 @@ describe('DAMImageExtension', () => {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
expect(getHtmlContent()).toEqual(
|
|
76
|
-
'<img ' +
|
|
76
|
+
'<img class="ProseMirror-separator" alt="">' +
|
|
77
|
+
'<img ' +
|
|
77
78
|
'src="https://default-resource/" ' +
|
|
78
79
|
'data-dam-object-id="5ce8e8dc-1adc-4254-87a8-d1f5a5c9045a" ' +
|
|
79
80
|
'data-dam-system-identifier="byder001" ' +
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jest stub for the ESM-only @highcharts/react packages pulled in via @squiz/sds Chart components.
|
|
3
|
+
* Tests never render charts; loading the real modules breaks Jest's CJS pipeline.
|
|
4
|
+
*/
|
|
5
|
+
const component = () => null;
|
|
6
|
+
|
|
7
|
+
const highchartsReactMock = new Proxy({ __esModule: true, default: component } as Record<string, unknown>, {
|
|
8
|
+
get(target, prop) {
|
|
9
|
+
if (typeof prop === 'string' && prop in target) {
|
|
10
|
+
return target[prop];
|
|
11
|
+
}
|
|
12
|
+
return component;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export default highchartsReactMock;
|
|
17
|
+
module.exports = highchartsReactMock;
|