@pie-lib/editable-html 11.1.2-next.0 → 11.2.0-beta.2
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 +50 -158
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +11 -6
- package/src/__tests__/editor.test.jsx +363 -0
- package/src/__tests__/serialization.test.js +291 -0
- package/src/__tests__/utils.js +36 -0
- package/src/block-tags.js +17 -0
- package/src/constants.js +7 -0
- package/src/editor.jsx +303 -49
- package/src/index.jsx +19 -10
- package/src/plugins/characters/index.jsx +11 -3
- package/src/plugins/characters/utils.js +12 -12
- package/src/plugins/css/icons/index.jsx +17 -0
- package/src/plugins/css/index.jsx +346 -0
- package/src/plugins/customPlugin/index.jsx +85 -0
- package/src/plugins/html/index.jsx +9 -6
- package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +51 -0
- package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +27 -0
- package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +44 -0
- package/src/plugins/image/__tests__/component.test.jsx +41 -0
- package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +42 -0
- package/src/plugins/image/__tests__/image-toolbar.test.jsx +11 -0
- package/src/plugins/image/__tests__/index.test.js +95 -0
- package/src/plugins/image/__tests__/insert-image-handler.test.js +113 -0
- package/src/plugins/image/__tests__/mock-change.js +15 -0
- package/src/plugins/image/index.jsx +2 -1
- package/src/plugins/image/insert-image-handler.js +13 -6
- package/src/plugins/index.jsx +248 -5
- package/src/plugins/list/__tests__/index.test.js +54 -0
- package/src/plugins/list/index.jsx +130 -0
- package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +48 -0
- package/src/plugins/math/__tests__/index.test.jsx +245 -0
- package/src/plugins/math/index.jsx +87 -56
- package/src/plugins/media/__tests__/index.test.js +75 -0
- package/src/plugins/media/index.jsx +3 -2
- package/src/plugins/media/media-dialog.js +106 -57
- package/src/plugins/rendering/index.js +31 -0
- package/src/plugins/respArea/drag-in-the-blank/choice.jsx +4 -1
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +10 -8
- package/src/plugins/respArea/index.jsx +53 -7
- package/src/plugins/respArea/inline-dropdown/index.jsx +13 -6
- package/src/plugins/respArea/math-templated/index.jsx +104 -0
- package/src/plugins/respArea/utils.jsx +11 -0
- package/src/plugins/table/CustomTablePlugin.js +113 -0
- package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +44 -0
- package/src/plugins/table/__tests__/index.test.jsx +401 -0
- package/src/plugins/table/__tests__/table-toolbar.test.jsx +42 -0
- package/src/plugins/table/index.jsx +46 -59
- package/src/plugins/table/table-toolbar.jsx +39 -2
- package/src/plugins/textAlign/icons/index.jsx +139 -0
- package/src/plugins/textAlign/index.jsx +23 -0
- package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +923 -0
- package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +20 -0
- package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +36 -0
- package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +46 -0
- package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +94 -0
- package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +37 -0
- package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +51 -0
- package/src/plugins/toolbar/__tests__/toolbar.test.jsx +106 -0
- package/src/plugins/toolbar/default-toolbar.jsx +82 -20
- package/src/plugins/toolbar/done-button.jsx +3 -1
- package/src/plugins/toolbar/editor-and-toolbar.jsx +18 -13
- package/src/plugins/toolbar/toolbar-buttons.jsx +52 -11
- package/src/plugins/toolbar/toolbar.jsx +31 -8
- package/src/serialization.jsx +213 -38
- package/README.md +0 -45
- package/deploy.sh +0 -16
- package/lib/editor.js +0 -1094
- package/lib/editor.js.map +0 -1
- package/lib/index.js +0 -253
- package/lib/index.js.map +0 -1
- package/lib/parse-html.js +0 -16
- package/lib/parse-html.js.map +0 -1
- package/lib/plugins/characters/custom-popper.js +0 -73
- package/lib/plugins/characters/custom-popper.js.map +0 -1
- package/lib/plugins/characters/index.js +0 -300
- package/lib/plugins/characters/index.js.map +0 -1
- package/lib/plugins/characters/utils.js +0 -381
- package/lib/plugins/characters/utils.js.map +0 -1
- package/lib/plugins/html/icons/index.js +0 -38
- package/lib/plugins/html/icons/index.js.map +0 -1
- package/lib/plugins/html/index.js +0 -76
- package/lib/plugins/html/index.js.map +0 -1
- package/lib/plugins/image/alt-dialog.js +0 -129
- package/lib/plugins/image/alt-dialog.js.map +0 -1
- package/lib/plugins/image/component.js +0 -419
- package/lib/plugins/image/component.js.map +0 -1
- package/lib/plugins/image/image-toolbar.js +0 -177
- package/lib/plugins/image/image-toolbar.js.map +0 -1
- package/lib/plugins/image/index.js +0 -262
- package/lib/plugins/image/index.js.map +0 -1
- package/lib/plugins/image/insert-image-handler.js +0 -152
- package/lib/plugins/image/insert-image-handler.js.map +0 -1
- package/lib/plugins/index.js +0 -143
- package/lib/plugins/index.js.map +0 -1
- package/lib/plugins/list/index.js +0 -204
- package/lib/plugins/list/index.js.map +0 -1
- package/lib/plugins/math/index.js +0 -419
- package/lib/plugins/math/index.js.map +0 -1
- package/lib/plugins/media/index.js +0 -384
- package/lib/plugins/media/index.js.map +0 -1
- package/lib/plugins/media/media-dialog.js +0 -668
- package/lib/plugins/media/media-dialog.js.map +0 -1
- package/lib/plugins/media/media-toolbar.js +0 -101
- package/lib/plugins/media/media-toolbar.js.map +0 -1
- package/lib/plugins/media/media-wrapper.js +0 -93
- package/lib/plugins/media/media-wrapper.js.map +0 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +0 -251
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +0 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +0 -97
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +0 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +0 -55
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +0 -1
- package/lib/plugins/respArea/icons/index.js +0 -95
- package/lib/plugins/respArea/icons/index.js.map +0 -1
- package/lib/plugins/respArea/index.js +0 -293
- package/lib/plugins/respArea/index.js.map +0 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +0 -70
- package/lib/plugins/respArea/inline-dropdown/index.js.map +0 -1
- package/lib/plugins/respArea/utils.js +0 -110
- package/lib/plugins/respArea/utils.js.map +0 -1
- package/lib/plugins/table/icons/index.js +0 -69
- package/lib/plugins/table/icons/index.js.map +0 -1
- package/lib/plugins/table/index.js +0 -499
- package/lib/plugins/table/index.js.map +0 -1
- package/lib/plugins/table/table-toolbar.js +0 -158
- package/lib/plugins/table/table-toolbar.js.map +0 -1
- package/lib/plugins/toolbar/default-toolbar.js +0 -174
- package/lib/plugins/toolbar/default-toolbar.js.map +0 -1
- package/lib/plugins/toolbar/done-button.js +0 -50
- package/lib/plugins/toolbar/done-button.js.map +0 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +0 -287
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +0 -1
- package/lib/plugins/toolbar/index.js +0 -34
- package/lib/plugins/toolbar/index.js.map +0 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +0 -161
- package/lib/plugins/toolbar/toolbar-buttons.js.map +0 -1
- package/lib/plugins/toolbar/toolbar.js +0 -352
- package/lib/plugins/toolbar/toolbar.js.map +0 -1
- package/lib/plugins/utils.js +0 -62
- package/lib/plugins/utils.js.map +0 -1
- package/lib/serialization.js +0 -488
- package/lib/serialization.js.map +0 -1
- package/lib/theme.js +0 -9
- package/lib/theme.js.map +0 -1
- package/playground/image/data.js +0 -59
- package/playground/image/index.html +0 -22
- package/playground/image/index.jsx +0 -81
- package/playground/index.html +0 -25
- package/playground/mathquill/index.html +0 -22
- package/playground/mathquill/index.jsx +0 -155
- package/playground/package.json +0 -15
- package/playground/prod-test/index.html +0 -22
- package/playground/prod-test/index.jsx +0 -28
- package/playground/schema-override/data.js +0 -29
- package/playground/schema-override/image-plugin.jsx +0 -41
- package/playground/schema-override/index.html +0 -21
- package/playground/schema-override/index.jsx +0 -97
- package/playground/serialization/data.js +0 -29
- package/playground/serialization/image-plugin.jsx +0 -41
- package/playground/serialization/index.html +0 -22
- package/playground/serialization/index.jsx +0 -12
- package/playground/static.json +0 -3
- package/playground/table-examples.html +0 -70
- package/playground/webpack.config.js +0 -42
- package/static.json +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`renders correctly 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
<span>
|
|
6
|
+
|
|
7
|
+
</span>,
|
|
8
|
+
<div
|
|
9
|
+
className=""
|
|
10
|
+
style={
|
|
11
|
+
Object {
|
|
12
|
+
"justifyContent": "flex-start",
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
>
|
|
16
|
+
<div
|
|
17
|
+
className="MuiLinearProgress-root-1 MuiLinearProgress-colorPrimary-2 MuiLinearProgress-indeterminate-5"
|
|
18
|
+
mode="determinate"
|
|
19
|
+
role="progressbar"
|
|
20
|
+
>
|
|
21
|
+
<div
|
|
22
|
+
className="MuiLinearProgress-bar-11 MuiLinearProgress-barColorPrimary-12 MuiLinearProgress-bar1Indeterminate-14"
|
|
23
|
+
style={Object {}}
|
|
24
|
+
/>
|
|
25
|
+
<div
|
|
26
|
+
className="MuiLinearProgress-bar-11 MuiLinearProgress-barColorPrimary-12 MuiLinearProgress-bar2Indeterminate-17"
|
|
27
|
+
style={Object {}}
|
|
28
|
+
/>
|
|
29
|
+
</div>
|
|
30
|
+
<div>
|
|
31
|
+
<img
|
|
32
|
+
className=""
|
|
33
|
+
onLoad={[Function]}
|
|
34
|
+
style={
|
|
35
|
+
Object {
|
|
36
|
+
"height": "50px",
|
|
37
|
+
"objectFit": "contain",
|
|
38
|
+
"width": "50px",
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/>
|
|
42
|
+
<div
|
|
43
|
+
className="resize"
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
</div>,
|
|
47
|
+
<span>
|
|
48
|
+
|
|
49
|
+
</span>,
|
|
50
|
+
]
|
|
51
|
+
`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ImageToolbar onChange renders 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<AlignmentButton
|
|
6
|
+
active={false}
|
|
7
|
+
alignment="left"
|
|
8
|
+
onClick={[Function]}
|
|
9
|
+
/>
|
|
10
|
+
<AlignmentButton
|
|
11
|
+
active={false}
|
|
12
|
+
alignment="center"
|
|
13
|
+
onClick={[Function]}
|
|
14
|
+
/>
|
|
15
|
+
<AlignmentButton
|
|
16
|
+
active={false}
|
|
17
|
+
alignment="right"
|
|
18
|
+
onClick={[Function]}
|
|
19
|
+
/>
|
|
20
|
+
<span
|
|
21
|
+
className="undefined"
|
|
22
|
+
onMouseDown={[Function]}
|
|
23
|
+
>
|
|
24
|
+
Alt text
|
|
25
|
+
</span>
|
|
26
|
+
</div>
|
|
27
|
+
`;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`renders correctly 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="ImageToolbar-holder-1 holder"
|
|
6
|
+
>
|
|
7
|
+
<button
|
|
8
|
+
aria-label="left"
|
|
9
|
+
aria-pressed={false}
|
|
10
|
+
className="RawMarkButton-button-4"
|
|
11
|
+
onKeyDown={[Function]}
|
|
12
|
+
onMouseDown={[Function]}
|
|
13
|
+
tabIndex={0}
|
|
14
|
+
>
|
|
15
|
+
left
|
|
16
|
+
</button>
|
|
17
|
+
<button
|
|
18
|
+
aria-label="center"
|
|
19
|
+
aria-pressed={false}
|
|
20
|
+
className="RawMarkButton-button-4"
|
|
21
|
+
onKeyDown={[Function]}
|
|
22
|
+
onMouseDown={[Function]}
|
|
23
|
+
tabIndex={0}
|
|
24
|
+
>
|
|
25
|
+
center
|
|
26
|
+
</button>
|
|
27
|
+
<button
|
|
28
|
+
aria-label="right"
|
|
29
|
+
aria-pressed={false}
|
|
30
|
+
className="RawMarkButton-button-4"
|
|
31
|
+
onKeyDown={[Function]}
|
|
32
|
+
onMouseDown={[Function]}
|
|
33
|
+
tabIndex={0}
|
|
34
|
+
>
|
|
35
|
+
right
|
|
36
|
+
</button>
|
|
37
|
+
<span
|
|
38
|
+
className="ImageToolbar-disabled-2 ImageToolbar-altButton-3"
|
|
39
|
+
onMouseDown={[Function]}
|
|
40
|
+
>
|
|
41
|
+
Alt text
|
|
42
|
+
</span>
|
|
43
|
+
</div>
|
|
44
|
+
`;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Data, Block } from 'slate';
|
|
2
|
+
import { Component } from '../component';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import renderer from 'react-test-renderer';
|
|
5
|
+
|
|
6
|
+
it('renders correctly', () => {
|
|
7
|
+
const node = Block.fromJSON({
|
|
8
|
+
type: 'image',
|
|
9
|
+
data: Data.create({
|
|
10
|
+
width: 50,
|
|
11
|
+
height: 50,
|
|
12
|
+
}),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const editor = {
|
|
16
|
+
value: {},
|
|
17
|
+
change: jest.fn(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const onDelete = jest.fn();
|
|
21
|
+
|
|
22
|
+
const classes = {
|
|
23
|
+
active: 'active',
|
|
24
|
+
loading: 'loading',
|
|
25
|
+
pendingDelete: 'pendingDelete',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const tree = renderer
|
|
29
|
+
.create(<Component node={node} editor={editor} classes={classes} onDelete={onDelete} />, {
|
|
30
|
+
createNodeMock: (el) => {
|
|
31
|
+
if (el.type === 'img') {
|
|
32
|
+
return {
|
|
33
|
+
naturalWidth: 100,
|
|
34
|
+
naturalHeight: 100,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
.toJSON();
|
|
40
|
+
expect(tree).toMatchSnapshot();
|
|
41
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { configure, shallow } from 'enzyme';
|
|
2
|
+
|
|
3
|
+
import { Data, Block, Value } from 'slate';
|
|
4
|
+
import { ImageToolbar } from '../image-toolbar';
|
|
5
|
+
import MockChange from './mock-change';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
describe('ImageToolbar', () => {
|
|
9
|
+
let onChange;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
onChange = jest.fn();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const mkWrapper = (extras) => {
|
|
16
|
+
const props = {
|
|
17
|
+
onChange,
|
|
18
|
+
classes: {},
|
|
19
|
+
...extras,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return shallow(<ImageToolbar {...props} />);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('onChange', () => {
|
|
26
|
+
it('renders', function() {
|
|
27
|
+
return expect(mkWrapper()).toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('calls onChange with alignment', () => {
|
|
31
|
+
const w = mkWrapper();
|
|
32
|
+
w.instance().onAlignmentClick('center');
|
|
33
|
+
expect(onChange).toHaveBeenCalledWith({ alignment: 'center' });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('calls onChange with alt text', () => {
|
|
37
|
+
const w = mkWrapper();
|
|
38
|
+
w.instance().onAltTextDone('alt text');
|
|
39
|
+
expect(onChange).toHaveBeenCalledWith({ alt: 'alt text' }, true);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Toolbar from '../image-toolbar';
|
|
3
|
+
import renderer from 'react-test-renderer';
|
|
4
|
+
import { Data, Block, Value } from 'slate';
|
|
5
|
+
|
|
6
|
+
it('renders correctly', () => {
|
|
7
|
+
const classes = { holder: 'holder' };
|
|
8
|
+
|
|
9
|
+
const tree = renderer.create(<Toolbar percent={50} classes={classes} onChange={jest.fn()} />).toJSON();
|
|
10
|
+
expect(tree).toMatchSnapshot();
|
|
11
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import MockChange, { MockDocument } from './mock-change';
|
|
2
|
+
|
|
3
|
+
import { Data } from 'slate';
|
|
4
|
+
import ImageToolbar from '../';
|
|
5
|
+
|
|
6
|
+
describe('image plugin', () => {
|
|
7
|
+
let value = {};
|
|
8
|
+
|
|
9
|
+
const imageSupport = {
|
|
10
|
+
delete: jest.fn(),
|
|
11
|
+
add: jest.fn(),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const imagePlugin = ImageToolbar({
|
|
15
|
+
onDelete: (src, done) => {
|
|
16
|
+
imageSupport.delete(src, (e) => {
|
|
17
|
+
done(e, value);
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
insertImageRequested: (node, getHandler) => {
|
|
21
|
+
const handler = getHandler(() => value);
|
|
22
|
+
imageSupport.add(handler);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('normalizeNode', () => {
|
|
27
|
+
it('should exit the function if the node is not of type document', () => {
|
|
28
|
+
const returnValue = imagePlugin.normalizeNode({ object: 'image' });
|
|
29
|
+
|
|
30
|
+
expect(returnValue).toEqual(undefined);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should exit if the function if there are no changes needed', () => {
|
|
34
|
+
const nodes = [
|
|
35
|
+
{
|
|
36
|
+
object: 'text',
|
|
37
|
+
text: 'Before Image',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'image',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
object: 'text',
|
|
44
|
+
text: 'After Image',
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
const returnValue = imagePlugin.normalizeNode({
|
|
48
|
+
object: 'document',
|
|
49
|
+
findDescendant: jest.fn((callback) => {
|
|
50
|
+
nodes.forEach((n) => callback(n));
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
expect(returnValue).toEqual(undefined);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return a function if there is a node with an empty text before an image', () => {
|
|
57
|
+
const nodes = [
|
|
58
|
+
{
|
|
59
|
+
object: 'text',
|
|
60
|
+
text: '',
|
|
61
|
+
key: '1',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: 'image',
|
|
65
|
+
key: '2',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
object: 'text',
|
|
69
|
+
text: 'After Image',
|
|
70
|
+
key: '3',
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
const findDescendant = jest.fn((callback) => {
|
|
74
|
+
nodes.forEach((n) => callback(n));
|
|
75
|
+
});
|
|
76
|
+
const change = {
|
|
77
|
+
withoutNormalization: jest.fn((callback) => {
|
|
78
|
+
callback();
|
|
79
|
+
}),
|
|
80
|
+
insertTextByKey: jest.fn(),
|
|
81
|
+
};
|
|
82
|
+
const returnValue = imagePlugin.normalizeNode({
|
|
83
|
+
object: 'document',
|
|
84
|
+
findDescendant,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(returnValue).toEqual(expect.any(Function));
|
|
88
|
+
|
|
89
|
+
returnValue(change);
|
|
90
|
+
|
|
91
|
+
expect(change.withoutNormalization).toHaveBeenCalledWith(expect.any(Function));
|
|
92
|
+
expect(change.insertTextByKey).toHaveBeenCalledWith('1', 0, ' ');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import MockChange, { MockDocument } from './mock-change';
|
|
2
|
+
|
|
3
|
+
import { Data } from 'slate';
|
|
4
|
+
import InsertImageHandler from '../insert-image-handler';
|
|
5
|
+
|
|
6
|
+
expect.extend({
|
|
7
|
+
toMatchData: (received, argument) => {
|
|
8
|
+
const argData = Data.create(argument);
|
|
9
|
+
const pass = argData.equals(received.data);
|
|
10
|
+
if (pass) {
|
|
11
|
+
return {
|
|
12
|
+
message: () => `expected ${received.toJSON()} not to be divisible by ${argData.toJSON()}`,
|
|
13
|
+
pass: true,
|
|
14
|
+
};
|
|
15
|
+
} else {
|
|
16
|
+
return {
|
|
17
|
+
message: () => `expected ${received.toJSON()} to be divisible by ${argData.toJSON()}`,
|
|
18
|
+
pass: false,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
describe('insert image handler', () => {
|
|
24
|
+
let change, document, value;
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
document = new MockDocument();
|
|
27
|
+
change = new MockChange();
|
|
28
|
+
value = {
|
|
29
|
+
change: () => change,
|
|
30
|
+
document,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const block = { key: 1 };
|
|
35
|
+
const onChange = jest.fn();
|
|
36
|
+
|
|
37
|
+
const handler = new InsertImageHandler(
|
|
38
|
+
block,
|
|
39
|
+
() => {},
|
|
40
|
+
() => value,
|
|
41
|
+
onChange,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
test('it constructs', () => {
|
|
45
|
+
expect(handler).not.toEqual(undefined);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('fileChosen', () => {
|
|
49
|
+
let fileReader;
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
fileReader = {
|
|
52
|
+
readAsDataURL: jest.fn(),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
global.FileReader = () => fileReader;
|
|
56
|
+
handler.fileChosen({});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('calls readAsDataURL', () => {
|
|
60
|
+
expect(fileReader.readAsDataURL).toBeCalledWith({});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('calls onChange with src -> dataUrl', () => {
|
|
64
|
+
fileReader.result = 'dataURL';
|
|
65
|
+
fileReader.onload();
|
|
66
|
+
expect(change.setNodeByKey).toBeCalledWith(block.key, expect.anything());
|
|
67
|
+
expect(change.setNodeByKey.mock.calls[0][1]).toMatchData({
|
|
68
|
+
src: 'dataURL',
|
|
69
|
+
});
|
|
70
|
+
expect(onChange).toBeCalledWith(change);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('progress', () => {
|
|
75
|
+
test('calls change w/ percent', () => {
|
|
76
|
+
handler.progress(40, 40, 100);
|
|
77
|
+
expect(change.setNodeByKey).toBeCalledWith(block.key, expect.anything());
|
|
78
|
+
|
|
79
|
+
expect(change.setNodeByKey.mock.calls[0][1].data.toJS()).toMatchObject({
|
|
80
|
+
percent: 40,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('done', () => {
|
|
86
|
+
test('calls setNodeByKey', () => {
|
|
87
|
+
handler.done(null, 'src');
|
|
88
|
+
|
|
89
|
+
expect(change.setNodeByKey).toBeCalledWith(block.key, expect.anything());
|
|
90
|
+
|
|
91
|
+
expect(change.setNodeByKey.mock.calls[0][1].data.toJS()).toMatchObject({
|
|
92
|
+
src: 'src',
|
|
93
|
+
loaded: true,
|
|
94
|
+
percent: 100,
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('cancel', () => {
|
|
100
|
+
beforeEach(() => {
|
|
101
|
+
document.getChild = jest.fn().mockReturnValue({ data: Data.create({}), key: block.key });
|
|
102
|
+
handler.cancel();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('calls onChange', () => {
|
|
106
|
+
expect(onChange).toBeCalled();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('calls removeNodeByKey', () => {
|
|
110
|
+
expect(change.removeNodeByKey).toBeCalledWith(block.key);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Data } from 'slate';
|
|
2
|
+
|
|
3
|
+
export default function MockChange() {
|
|
4
|
+
this.setNodeByKey = jest.fn().mockReturnValue(this);
|
|
5
|
+
this.removeNodeByKey = jest.fn().mockReturnValue(this);
|
|
6
|
+
this.insertInline = jest.fn().mockReturnValue(this);
|
|
7
|
+
this.moveFocusTo = jest.fn().mockReturnValue(this);
|
|
8
|
+
this.moveAnchorTo = jest.fn().mockReturnValue(this);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function MockDocument() {
|
|
12
|
+
this.getChild = jest.fn().mockReturnValue({ data: Data.create({}) });
|
|
13
|
+
|
|
14
|
+
this.getDescendant = jest.fn();
|
|
15
|
+
}
|
|
@@ -12,6 +12,7 @@ const log = debug('@pie-lib:editable-html:plugins:image');
|
|
|
12
12
|
export default function ImagePlugin(opts) {
|
|
13
13
|
const toolbar = opts.insertImageRequested && {
|
|
14
14
|
icon: <Image />,
|
|
15
|
+
ariaLabel: 'Insert Image',
|
|
15
16
|
onClick: (value, onChange) => {
|
|
16
17
|
log('[toolbar] onClick');
|
|
17
18
|
const inline = Inline.create({
|
|
@@ -71,7 +72,7 @@ export default function ImagePlugin(opts) {
|
|
|
71
72
|
let change = value.change().setNodeByKey(node.key, { data: update });
|
|
72
73
|
|
|
73
74
|
onChange(change);
|
|
74
|
-
opts.onDelete(node
|
|
75
|
+
opts.onDelete(node, (err, v) => {
|
|
75
76
|
if (!err) {
|
|
76
77
|
change = v.change().removeNodeByKey(node.key);
|
|
77
78
|
} else {
|
|
@@ -34,19 +34,26 @@ class InsertImageHandler {
|
|
|
34
34
|
if (child) {
|
|
35
35
|
return child;
|
|
36
36
|
} else {
|
|
37
|
-
//eslint-disable-next-line
|
|
37
|
+
// eslint-disable-next-line
|
|
38
38
|
throw new Error("insert-image: Can't find placeholder!");
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
cancel() {
|
|
43
43
|
log('insert cancelled');
|
|
44
|
-
const c = this.getValue()
|
|
45
|
-
.change()
|
|
46
|
-
.removeNodeByKey(this.placeholderBlock.key);
|
|
47
|
-
this.onChange(c);
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
try {
|
|
46
|
+
const value = this.getValue();
|
|
47
|
+
const child = this.getPlaceholderInDocument(value);
|
|
48
|
+
|
|
49
|
+
if (child) {
|
|
50
|
+
const c = value.change().removeNodeByKey(child.key);
|
|
51
|
+
this.onChange(c);
|
|
52
|
+
this.onFinish(false);
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
//
|
|
56
|
+
}
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
done(err, src) {
|