@pie-lib/mask-markup 3.0.4-next.0 → 3.0.4-next.104
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.json +17 -0
- package/CHANGELOG.md +1256 -0
- package/LICENSE.md +5 -0
- package/lib/choices/choice.js +120 -0
- package/lib/choices/choice.js.map +1 -0
- package/lib/choices/index.js +103 -0
- package/lib/choices/index.js.map +1 -0
- package/lib/componentize.js +21 -0
- package/lib/componentize.js.map +1 -0
- package/lib/components/blank.js +412 -0
- package/lib/components/blank.js.map +1 -0
- package/lib/components/correct-input.js +94 -0
- package/lib/components/correct-input.js.map +1 -0
- package/lib/components/dropdown.js +483 -0
- package/lib/components/dropdown.js.map +1 -0
- package/lib/components/input.js +50 -0
- package/lib/components/input.js.map +1 -0
- package/lib/constructed-response.js +101 -0
- package/lib/constructed-response.js.map +1 -0
- package/lib/customizable.js +42 -0
- package/lib/customizable.js.map +1 -0
- package/lib/drag-in-the-blank.js +254 -0
- package/lib/drag-in-the-blank.js.map +1 -0
- package/lib/index.js +55 -0
- package/lib/index.js.map +1 -0
- package/lib/inline-dropdown.js +40 -0
- package/lib/inline-dropdown.js.map +1 -0
- package/lib/mask.js +198 -0
- package/lib/mask.js.map +1 -0
- package/lib/serialization.js +261 -0
- package/lib/serialization.js.map +1 -0
- package/lib/with-mask.js +97 -0
- package/lib/with-mask.js.map +1 -0
- package/package.json +17 -35
- package/src/__tests__/drag-in-the-blank.test.js +111 -0
- package/src/__tests__/index.test.js +38 -0
- package/src/__tests__/mask.test.js +381 -0
- package/src/__tests__/serialization.test.js +54 -0
- package/src/__tests__/utils.js +1 -0
- package/src/__tests__/with-mask.test.js +76 -0
- package/src/choices/__tests__/index.test.js +109 -0
- package/src/choices/choice.jsx +100 -0
- package/src/choices/index.jsx +64 -0
- package/src/componentize.js +13 -0
- package/src/components/__tests__/blank.test.js +232 -0
- package/src/components/__tests__/correct-input.test.js +90 -0
- package/src/components/__tests__/dropdown.test.js +129 -0
- package/src/components/__tests__/input.test.js +102 -0
- package/src/components/blank.jsx +431 -0
- package/src/components/correct-input.jsx +82 -0
- package/src/components/dropdown.jsx +423 -0
- package/src/components/input.jsx +48 -0
- package/src/constructed-response.jsx +87 -0
- package/src/customizable.jsx +34 -0
- package/src/drag-in-the-blank.jsx +241 -0
- package/src/index.js +16 -0
- package/src/inline-dropdown.jsx +29 -0
- package/src/mask.jsx +172 -0
- package/src/serialization.js +260 -0
- package/src/with-mask.jsx +75 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -4
- package/dist/choices/choice.d.ts +0 -24
- package/dist/choices/choice.js +0 -77
- package/dist/choices/index.d.ts +0 -25
- package/dist/choices/index.js +0 -49
- package/dist/componentize.d.ts +0 -12
- package/dist/componentize.js +0 -4
- package/dist/components/blank.d.ts +0 -39
- package/dist/components/blank.js +0 -240
- package/dist/components/correct-input.d.ts +0 -11
- package/dist/components/dropdown.d.ts +0 -37
- package/dist/components/dropdown.js +0 -320
- package/dist/components/input.d.ts +0 -37
- package/dist/constructed-response.d.ts +0 -44
- package/dist/constructed-response.js +0 -55
- package/dist/customizable.d.ts +0 -43
- package/dist/customizable.js +0 -8
- package/dist/drag-in-the-blank.d.ts +0 -37
- package/dist/drag-in-the-blank.js +0 -164
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -7
- package/dist/inline-dropdown.d.ts +0 -44
- package/dist/inline-dropdown.js +0 -24
- package/dist/mask.d.ts +0 -30
- package/dist/mask.js +0 -99
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +0 -17
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +0 -9
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +0 -26
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +0 -11
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +0 -11
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +0 -11
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +0 -24
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +0 -32
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +0 -29
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +0 -14
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +0 -8
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +0 -12
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +0 -11
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +0 -10
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +0 -10
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +0 -55
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +0 -16
- package/dist/serialization.d.ts +0 -34
- package/dist/serialization.js +0 -132
- package/dist/with-mask.d.ts +0 -55
- package/dist/with-mask.js +0 -45
package/package.json
CHANGED
|
@@ -1,50 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/mask-markup",
|
|
3
|
-
"version": "3.0.4-next.
|
|
3
|
+
"version": "3.0.4-next.104+8e93df66f",
|
|
4
4
|
"description": "",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "src/index.js",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": "pie-framework/pie-lib",
|
|
5
11
|
"dependencies": {
|
|
6
12
|
"@emotion/react": "^11.14.0",
|
|
7
|
-
"@emotion/
|
|
13
|
+
"@emotion/styled": "^11.14.1",
|
|
8
14
|
"@mui/icons-material": "^7.3.4",
|
|
9
15
|
"@mui/material": "^7.3.4",
|
|
10
|
-
"@pie-lib/drag": "4.0.
|
|
11
|
-
"@pie-lib/editable-html-tip-tap": "2.1.2-next.
|
|
12
|
-
"@pie-lib/math-rendering": "0.
|
|
13
|
-
"@pie-lib/render-ui": "6.1.
|
|
16
|
+
"@pie-lib/drag": "^4.0.2",
|
|
17
|
+
"@pie-lib/editable-html-tip-tap": "^2.1.2-next.104+8e93df66f",
|
|
18
|
+
"@pie-lib/math-rendering": "^5.0.2",
|
|
19
|
+
"@pie-lib/render-ui": "^6.1.0",
|
|
14
20
|
"classnames": "^2.2.6",
|
|
15
21
|
"debug": "^4.1.1",
|
|
16
22
|
"lodash-es": "^4.17.23",
|
|
17
23
|
"prop-types": "^15.7.2",
|
|
18
24
|
"react": "^18.2.0",
|
|
19
25
|
"react-dom": "^18.2.0",
|
|
20
|
-
"to-style": "^1.3.3"
|
|
21
|
-
"@pie-element/shared-math-rendering-mathjax": "0.1.0",
|
|
22
|
-
"@dnd-kit/core": "6.3.1",
|
|
23
|
-
"@dnd-kit/utilities": "3.2.2"
|
|
24
|
-
},
|
|
25
|
-
"type": "module",
|
|
26
|
-
"main": "./dist/index.js",
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
28
|
-
"exports": {
|
|
29
|
-
".": {
|
|
30
|
-
"types": "./dist/index.d.ts",
|
|
31
|
-
"default": "./dist/index.js"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"files": [
|
|
35
|
-
"dist"
|
|
36
|
-
],
|
|
37
|
-
"sideEffects": false,
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "bun x vite build && bun x tsc --emitDeclarationOnly",
|
|
40
|
-
"dev": "bun x vite",
|
|
41
|
-
"test": "bun x vitest run"
|
|
26
|
+
"to-style": "^1.3.3"
|
|
42
27
|
},
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"@types/react": "^18.2.0",
|
|
48
|
-
"@types/react-dom": "^18.2.0"
|
|
49
|
-
}
|
|
28
|
+
"keywords": [],
|
|
29
|
+
"author": "",
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"gitHead": "8e93df66fd174842bc85d9fba0e203898993ca18"
|
|
50
32
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import DragInTheBlank from '../drag-in-the-blank';
|
|
4
|
+
|
|
5
|
+
const markup = `<div>
|
|
6
|
+
<img src="https://image.shutterstock.com/image-vector/cow-jumped-over-moon-traditional-260nw-1152899330.jpg"></img>
|
|
7
|
+
<h5>Hey Diddle Diddle <i>by ?</i></h5>
|
|
8
|
+
<p>1: Hey, diddle, diddle,</p>
|
|
9
|
+
<p>2: The cat and the fiddle,</p>
|
|
10
|
+
<p>3: The cow {{0}} over the moon;</p>
|
|
11
|
+
<p>4: The little dog {{1}},</p>
|
|
12
|
+
<p>5: To see such sport,</p>
|
|
13
|
+
<p>6: And the dish ran away with the {{2}}.</p>
|
|
14
|
+
</div>`;
|
|
15
|
+
const choice = (v, id) => ({ value: v, id });
|
|
16
|
+
|
|
17
|
+
// Mock DragProvider and DragDroppablePlaceholder to avoid DndContext requirement
|
|
18
|
+
jest.mock('@pie-lib/drag', () => ({
|
|
19
|
+
DragProvider: ({ children, onDragStart, onDragEnd }) => {
|
|
20
|
+
// Simple wrapper that doesn't require DndContext
|
|
21
|
+
return <div data-testid="drag-provider">{children}</div>;
|
|
22
|
+
},
|
|
23
|
+
DragDroppablePlaceholder: ({ children, disabled, instanceId }) => {
|
|
24
|
+
// Simple wrapper that doesn't require useDroppable
|
|
25
|
+
return <div data-testid="drag-droppable-placeholder">{children}</div>;
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
// Mock @dnd-kit/core components and hooks used by DragInTheBlank and child components
|
|
30
|
+
jest.mock('@dnd-kit/core', () => ({
|
|
31
|
+
DragOverlay: ({ children }) => <div data-testid="drag-overlay">{children}</div>,
|
|
32
|
+
closestCenter: jest.fn(),
|
|
33
|
+
useDraggable: jest.fn(() => ({
|
|
34
|
+
attributes: {},
|
|
35
|
+
listeners: {},
|
|
36
|
+
setNodeRef: jest.fn(),
|
|
37
|
+
transform: null,
|
|
38
|
+
isDragging: false,
|
|
39
|
+
})),
|
|
40
|
+
useDroppable: jest.fn(() => ({
|
|
41
|
+
setNodeRef: jest.fn(),
|
|
42
|
+
isOver: false,
|
|
43
|
+
active: null,
|
|
44
|
+
})),
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
jest.mock('@dnd-kit/utilities', () => ({
|
|
48
|
+
CSS: {
|
|
49
|
+
Translate: {
|
|
50
|
+
toString: jest.fn(() => 'translate3d(0, 0, 0)'),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
describe('DragInTheBlank', () => {
|
|
56
|
+
const defaultProps = {
|
|
57
|
+
disabled: false,
|
|
58
|
+
feedback: {},
|
|
59
|
+
markup,
|
|
60
|
+
choices: [
|
|
61
|
+
choice('Jumped', '0'),
|
|
62
|
+
choice('Laughed', '1'),
|
|
63
|
+
choice('Spoon', '2'),
|
|
64
|
+
choice('Fork', '3'),
|
|
65
|
+
choice('Bumped', '4'),
|
|
66
|
+
choice('Smiled', '5'),
|
|
67
|
+
],
|
|
68
|
+
|
|
69
|
+
value: {
|
|
70
|
+
0: undefined,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
describe('render', () => {
|
|
75
|
+
it('renders correctly with default props', () => {
|
|
76
|
+
const { container } = render(<DragInTheBlank {...defaultProps} />);
|
|
77
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
78
|
+
// Check that markup content is rendered
|
|
79
|
+
expect(screen.getByText(/Hey Diddle Diddle/)).toBeInTheDocument();
|
|
80
|
+
expect(screen.getByText(/Hey, diddle, diddle,/)).toBeInTheDocument();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('renders correctly with disabled prop as true', () => {
|
|
84
|
+
const { container } = render(<DragInTheBlank {...defaultProps} disabled={true} />);
|
|
85
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('renders correctly with feedback', () => {
|
|
89
|
+
const { container } = render(
|
|
90
|
+
<DragInTheBlank
|
|
91
|
+
{...defaultProps}
|
|
92
|
+
feedback={{
|
|
93
|
+
0: {
|
|
94
|
+
value: 'Jumped',
|
|
95
|
+
correct: 'Jumped',
|
|
96
|
+
},
|
|
97
|
+
1: {
|
|
98
|
+
value: 'Laughed',
|
|
99
|
+
correct: 'Laughed',
|
|
100
|
+
},
|
|
101
|
+
2: {
|
|
102
|
+
value: 'Spoon',
|
|
103
|
+
correct: 'Spoon',
|
|
104
|
+
},
|
|
105
|
+
}}
|
|
106
|
+
/>,
|
|
107
|
+
);
|
|
108
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import componentize from '../componentize';
|
|
2
|
+
import { deserialize } from '../serialization';
|
|
3
|
+
|
|
4
|
+
describe('index', () => {
|
|
5
|
+
describe('componentize', () => {
|
|
6
|
+
it('should return an array with the appropriate markup', () => {
|
|
7
|
+
const dropDownMarkup = componentize('{{0}} foo {{1}}', 'dropdown');
|
|
8
|
+
|
|
9
|
+
expect(dropDownMarkup).toEqual({
|
|
10
|
+
markup:
|
|
11
|
+
'<span data-component="dropdown" data-id="0"></span> foo <span data-component="dropdown" data-id="1"></span>',
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('serialization', () => {
|
|
17
|
+
it('should have default node a span', () => {
|
|
18
|
+
expect(deserialize('something')).toEqual(
|
|
19
|
+
expect.objectContaining({
|
|
20
|
+
object: 'value',
|
|
21
|
+
document: {
|
|
22
|
+
object: 'document',
|
|
23
|
+
data: {},
|
|
24
|
+
nodes: [
|
|
25
|
+
{
|
|
26
|
+
object: 'block',
|
|
27
|
+
data: {},
|
|
28
|
+
isVoid: false,
|
|
29
|
+
type: 'span',
|
|
30
|
+
nodes: [{ object: 'text', leaves: [{ text: 'something' }] }],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import Mask from '../mask';
|
|
4
|
+
|
|
5
|
+
describe('Mask', () => {
|
|
6
|
+
// Don't mock renderChildren - let the component render naturally
|
|
7
|
+
const onChange = jest.fn();
|
|
8
|
+
const defaultProps = {
|
|
9
|
+
onChange,
|
|
10
|
+
layout: {
|
|
11
|
+
nodes: [
|
|
12
|
+
{
|
|
13
|
+
object: 'text',
|
|
14
|
+
leaves: [
|
|
15
|
+
{
|
|
16
|
+
text: 'Foo',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
value: {},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
onChange.mockClear();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('rendering', () => {
|
|
30
|
+
it('renders with default props', () => {
|
|
31
|
+
const { container } = render(<Mask {...defaultProps} />);
|
|
32
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('renders text content', () => {
|
|
36
|
+
render(<Mask {...defaultProps} />);
|
|
37
|
+
expect(screen.getByText('Foo')).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('renders a paragraph element', () => {
|
|
41
|
+
const { container } = render(
|
|
42
|
+
<Mask
|
|
43
|
+
{...defaultProps}
|
|
44
|
+
layout={{
|
|
45
|
+
nodes: [
|
|
46
|
+
{
|
|
47
|
+
type: 'p',
|
|
48
|
+
nodes: [
|
|
49
|
+
{
|
|
50
|
+
object: 'text',
|
|
51
|
+
leaves: [
|
|
52
|
+
{
|
|
53
|
+
text: 'Foo',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
}}
|
|
61
|
+
/>,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// Paragraph is rendered as a styled div, not a <p> tag
|
|
65
|
+
expect(screen.getByText('Foo')).toBeInTheDocument();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('renders nested div and paragraph', () => {
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<Mask
|
|
71
|
+
{...defaultProps}
|
|
72
|
+
layout={{
|
|
73
|
+
nodes: [
|
|
74
|
+
{
|
|
75
|
+
type: 'div',
|
|
76
|
+
data: {
|
|
77
|
+
attributes: {},
|
|
78
|
+
},
|
|
79
|
+
nodes: [
|
|
80
|
+
{
|
|
81
|
+
type: 'p',
|
|
82
|
+
data: {
|
|
83
|
+
attributes: {},
|
|
84
|
+
},
|
|
85
|
+
nodes: [
|
|
86
|
+
{
|
|
87
|
+
object: 'text',
|
|
88
|
+
leaves: [
|
|
89
|
+
{
|
|
90
|
+
text: 'Foo',
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
}}
|
|
100
|
+
/>,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(container.querySelector('div')).toBeInTheDocument();
|
|
104
|
+
// Paragraph is rendered as a styled div, not a <p> tag
|
|
105
|
+
expect(screen.getByText('Foo')).toBeInTheDocument();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('renders text with italic marks', () => {
|
|
109
|
+
const { container } = render(
|
|
110
|
+
<Mask
|
|
111
|
+
{...defaultProps}
|
|
112
|
+
layout={{
|
|
113
|
+
nodes: [
|
|
114
|
+
{
|
|
115
|
+
leaves: [{ text: 'Foo ' }],
|
|
116
|
+
object: 'text',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
leaves: [
|
|
120
|
+
{
|
|
121
|
+
marks: [
|
|
122
|
+
{
|
|
123
|
+
data: undefined,
|
|
124
|
+
type: 'italic',
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
text: 'x',
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
object: 'text',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
leaves: [{ text: ' bar' }],
|
|
134
|
+
object: 'text',
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
object: 'block',
|
|
138
|
+
type: 'div',
|
|
139
|
+
}}
|
|
140
|
+
/>,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// Text "Foo " is split with spaces, use regex
|
|
144
|
+
expect(screen.getByText(/Foo/)).toBeInTheDocument();
|
|
145
|
+
expect(screen.getByText('x')).toBeInTheDocument();
|
|
146
|
+
expect(screen.getByText(/bar/)).toBeInTheDocument();
|
|
147
|
+
// Check for italic/em element
|
|
148
|
+
const em = container.querySelector('em, i');
|
|
149
|
+
expect(em).toBeInTheDocument();
|
|
150
|
+
expect(em.textContent).toBe('x');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('renders tbody without extra space', () => {
|
|
154
|
+
const da = () => ({ data: { attributes: {} } });
|
|
155
|
+
const { container } = render(
|
|
156
|
+
<Mask
|
|
157
|
+
{...defaultProps}
|
|
158
|
+
layout={{
|
|
159
|
+
nodes: [
|
|
160
|
+
{
|
|
161
|
+
type: 'table',
|
|
162
|
+
...da(),
|
|
163
|
+
nodes: [
|
|
164
|
+
{
|
|
165
|
+
type: 'tbody',
|
|
166
|
+
...da(),
|
|
167
|
+
nodes: [
|
|
168
|
+
{
|
|
169
|
+
object: 'text',
|
|
170
|
+
leaves: [{ text: ' ' }],
|
|
171
|
+
},
|
|
172
|
+
{ type: 'tr', ...da(), nodes: [] },
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
}}
|
|
179
|
+
/>,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(container.querySelector('table')).toBeInTheDocument();
|
|
183
|
+
expect(container.querySelector('tbody')).toBeInTheDocument();
|
|
184
|
+
expect(container.querySelector('tr')).toBeInTheDocument();
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('spacer rendering for DnD components', () => {
|
|
189
|
+
it('adds spacers before and after DnD blank components', () => {
|
|
190
|
+
const mockRenderChildren = jest.fn((n) => {
|
|
191
|
+
if (n.data?.dataset?.component === 'blank') {
|
|
192
|
+
return <span data-testid="blank-component">Blank</span>;
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const { container } = render(
|
|
198
|
+
<Mask
|
|
199
|
+
{...defaultProps}
|
|
200
|
+
renderChildren={mockRenderChildren}
|
|
201
|
+
layout={{
|
|
202
|
+
nodes: [
|
|
203
|
+
{
|
|
204
|
+
type: 'div',
|
|
205
|
+
data: {
|
|
206
|
+
dataset: { component: 'blank' },
|
|
207
|
+
attributes: {},
|
|
208
|
+
},
|
|
209
|
+
nodes: [],
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
}}
|
|
213
|
+
/>,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
// Check that renderChildren was called and spacers are present
|
|
217
|
+
// Count all children in the container - should be: spacer + blank + spacer = 3 elements
|
|
218
|
+
const maskContainer = container.firstChild;
|
|
219
|
+
expect(maskContainer.childNodes.length).toBe(3);
|
|
220
|
+
expect(screen.getByTestId('blank-component')).toBeInTheDocument();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('does not add spacers for non-DnD components', () => {
|
|
224
|
+
const mockRenderChildren = jest.fn((n) => {
|
|
225
|
+
return <span data-testid="regular-component">Regular</span>;
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const { container } = render(
|
|
229
|
+
<Mask
|
|
230
|
+
{...defaultProps}
|
|
231
|
+
renderChildren={mockRenderChildren}
|
|
232
|
+
layout={{
|
|
233
|
+
nodes: [
|
|
234
|
+
{
|
|
235
|
+
type: 'div',
|
|
236
|
+
data: {
|
|
237
|
+
attributes: {},
|
|
238
|
+
},
|
|
239
|
+
nodes: [],
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
}}
|
|
243
|
+
/>,
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
// Should not have spacers - only the regular component
|
|
247
|
+
const maskContainer = container.firstChild;
|
|
248
|
+
expect(maskContainer.childNodes.length).toBe(1);
|
|
249
|
+
expect(screen.getByTestId('regular-component')).toBeInTheDocument();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('adds spacers regardless of parent node type', () => {
|
|
253
|
+
const mockRenderChildren = jest.fn((n) => {
|
|
254
|
+
if (n.data?.dataset?.component === 'blank') {
|
|
255
|
+
return <span data-testid="blank-in-td">Blank in TD</span>;
|
|
256
|
+
}
|
|
257
|
+
return null;
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const { container } = render(
|
|
261
|
+
<Mask
|
|
262
|
+
{...defaultProps}
|
|
263
|
+
renderChildren={mockRenderChildren}
|
|
264
|
+
elementType="drag-in-the-blank"
|
|
265
|
+
layout={{
|
|
266
|
+
nodes: [
|
|
267
|
+
{
|
|
268
|
+
type: 'table',
|
|
269
|
+
data: { attributes: {} },
|
|
270
|
+
nodes: [
|
|
271
|
+
{
|
|
272
|
+
type: 'tbody',
|
|
273
|
+
data: { attributes: {} },
|
|
274
|
+
nodes: [
|
|
275
|
+
{
|
|
276
|
+
type: 'tr',
|
|
277
|
+
data: { attributes: {} },
|
|
278
|
+
nodes: [
|
|
279
|
+
{
|
|
280
|
+
type: 'td',
|
|
281
|
+
data: { attributes: {} },
|
|
282
|
+
nodes: [
|
|
283
|
+
{
|
|
284
|
+
type: 'div',
|
|
285
|
+
data: {
|
|
286
|
+
dataset: { component: 'blank' },
|
|
287
|
+
attributes: {},
|
|
288
|
+
},
|
|
289
|
+
nodes: [],
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
}}
|
|
301
|
+
/>,
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
// Should have spacers even inside td element
|
|
305
|
+
const td = container.querySelector('td');
|
|
306
|
+
expect(td.childNodes.length).toBe(3); // spacer + blank + spacer
|
|
307
|
+
expect(screen.getByTestId('blank-in-td')).toBeInTheDocument();
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('does not add spacers for text content', () => {
|
|
311
|
+
const { container } = render(
|
|
312
|
+
<Mask
|
|
313
|
+
{...defaultProps}
|
|
314
|
+
elementType="drag-in-the-blank"
|
|
315
|
+
layout={{
|
|
316
|
+
nodes: [
|
|
317
|
+
{
|
|
318
|
+
object: 'text',
|
|
319
|
+
leaves: [
|
|
320
|
+
{
|
|
321
|
+
text: 'Some text',
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
}}
|
|
327
|
+
/>,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
// Should not have spacers for plain text - just text node
|
|
331
|
+
const maskContainer = container.firstChild;
|
|
332
|
+
expect(maskContainer.childNodes.length).toBe(1);
|
|
333
|
+
expect(maskContainer.childNodes[0].nodeType).toBe(Node.TEXT_NODE);
|
|
334
|
+
expect(screen.getByText('Some text')).toBeInTheDocument();
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('handles multiple DnD components with correct spacer placement', () => {
|
|
338
|
+
const mockRenderChildren = jest.fn((n) => {
|
|
339
|
+
if (n.data?.dataset?.component === 'blank') {
|
|
340
|
+
return <span data-testid={`blank-${n.data.testId}`}>Blank</span>;
|
|
341
|
+
}
|
|
342
|
+
return null;
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const { container } = render(
|
|
346
|
+
<Mask
|
|
347
|
+
{...defaultProps}
|
|
348
|
+
renderChildren={mockRenderChildren}
|
|
349
|
+
layout={{
|
|
350
|
+
nodes: [
|
|
351
|
+
{
|
|
352
|
+
type: 'div',
|
|
353
|
+
data: {
|
|
354
|
+
dataset: { component: 'blank' },
|
|
355
|
+
attributes: {},
|
|
356
|
+
testId: '1',
|
|
357
|
+
},
|
|
358
|
+
nodes: [],
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
type: 'div',
|
|
362
|
+
data: {
|
|
363
|
+
dataset: { component: 'blank' },
|
|
364
|
+
attributes: {},
|
|
365
|
+
testId: '2',
|
|
366
|
+
},
|
|
367
|
+
nodes: [],
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
}}
|
|
371
|
+
/>,
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
// Should have 2 spacers per component = 4 spacers + 2 blanks = 6 total children
|
|
375
|
+
const maskContainer = container.firstChild;
|
|
376
|
+
expect(maskContainer.childNodes.length).toBe(6);
|
|
377
|
+
expect(screen.getByTestId('blank-1')).toBeInTheDocument();
|
|
378
|
+
expect(screen.getByTestId('blank-2')).toBeInTheDocument();
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { deserialize } from '../serialization';
|
|
2
|
+
|
|
3
|
+
describe('serialization', () => {
|
|
4
|
+
it('ignores comments', () => {
|
|
5
|
+
const out = deserialize(`<!-- hi -->`);
|
|
6
|
+
expect(out.document.nodes[0]).toEqual(expect.objectContaining({ type: 'span' }));
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('ignores comments', () => {
|
|
10
|
+
const out = deserialize(`<!-- hi --><div>foo</div>`);
|
|
11
|
+
expect(out.document.nodes[0]).toEqual(
|
|
12
|
+
expect.objectContaining({
|
|
13
|
+
type: 'div',
|
|
14
|
+
nodes: [
|
|
15
|
+
expect.objectContaining({
|
|
16
|
+
object: 'text',
|
|
17
|
+
leaves: [{ text: 'foo' }],
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('deserializes an em', () => {
|
|
25
|
+
const out = deserialize(`<!-- hi --><div> <em>x</em> </div>`);
|
|
26
|
+
expect(out.document.nodes[0]).toEqual(
|
|
27
|
+
expect.objectContaining({
|
|
28
|
+
type: 'div',
|
|
29
|
+
nodes: [
|
|
30
|
+
expect.objectContaining({
|
|
31
|
+
object: 'text',
|
|
32
|
+
}),
|
|
33
|
+
expect.objectContaining({
|
|
34
|
+
leaves: [
|
|
35
|
+
{
|
|
36
|
+
marks: [
|
|
37
|
+
{
|
|
38
|
+
data: undefined,
|
|
39
|
+
type: 'italic',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
text: 'x',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
object: 'text',
|
|
46
|
+
}),
|
|
47
|
+
expect.objectContaining({
|
|
48
|
+
object: 'text',
|
|
49
|
+
}),
|
|
50
|
+
],
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const choice = (v, id) => ({ label: v, value: v, id });
|