@pie-lib/editable-html 11.1.2-next.0 → 11.3.0-beta.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.
Files changed (194) hide show
  1. package/CHANGELOG.md +8 -4
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/lib/__tests__/editor.test.js +470 -0
  4. package/lib/__tests__/serialization.test.js +246 -0
  5. package/lib/__tests__/utils.js +106 -0
  6. package/lib/block-tags.js +25 -0
  7. package/lib/constants.js +16 -0
  8. package/lib/editor.js +349 -88
  9. package/lib/index.js +26 -10
  10. package/lib/parse-html.js +1 -1
  11. package/lib/plugins/characters/custom-popper.js +1 -1
  12. package/lib/plugins/characters/index.js +9 -4
  13. package/lib/plugins/characters/utils.js +13 -13
  14. package/lib/plugins/css/icons/index.js +37 -0
  15. package/lib/plugins/css/index.js +397 -0
  16. package/lib/plugins/customPlugin/index.js +114 -0
  17. package/lib/plugins/html/icons/index.js +1 -1
  18. package/lib/plugins/html/index.js +12 -8
  19. package/lib/plugins/image/__tests__/component.test.js +51 -0
  20. package/lib/plugins/image/__tests__/image-toolbar-logic.test.js +56 -0
  21. package/lib/plugins/image/__tests__/image-toolbar.test.js +26 -0
  22. package/lib/plugins/image/__tests__/index.test.js +98 -0
  23. package/lib/plugins/image/__tests__/insert-image-handler.test.js +125 -0
  24. package/lib/plugins/image/__tests__/mock-change.js +25 -0
  25. package/lib/plugins/image/alt-dialog.js +1 -1
  26. package/lib/plugins/image/component.js +1 -1
  27. package/lib/plugins/image/image-toolbar.js +1 -1
  28. package/lib/plugins/image/index.js +3 -2
  29. package/lib/plugins/image/insert-image-handler.js +14 -5
  30. package/lib/plugins/index.js +271 -12
  31. package/lib/plugins/list/__tests__/index.test.js +79 -0
  32. package/lib/plugins/list/index.js +131 -1
  33. package/lib/plugins/math/__tests__/index.test.js +300 -0
  34. package/lib/plugins/math/index.js +92 -57
  35. package/lib/plugins/media/__tests__/index.test.js +71 -0
  36. package/lib/plugins/media/index.js +6 -3
  37. package/lib/plugins/media/media-dialog.js +99 -58
  38. package/lib/plugins/media/media-toolbar.js +1 -1
  39. package/lib/plugins/media/media-wrapper.js +1 -1
  40. package/lib/plugins/rendering/index.js +46 -0
  41. package/lib/plugins/respArea/drag-in-the-blank/choice.js +6 -3
  42. package/lib/plugins/respArea/drag-in-the-blank/index.js +1 -1
  43. package/lib/plugins/respArea/explicit-constructed-response/index.js +12 -10
  44. package/lib/plugins/respArea/icons/index.js +1 -1
  45. package/lib/plugins/respArea/index.js +70 -22
  46. package/lib/plugins/respArea/inline-dropdown/index.js +11 -6
  47. package/lib/plugins/respArea/math-templated/index.js +130 -0
  48. package/lib/plugins/respArea/utils.js +17 -2
  49. package/lib/plugins/table/CustomTablePlugin.js +133 -0
  50. package/lib/plugins/table/__tests__/index.test.js +442 -0
  51. package/lib/plugins/table/__tests__/table-toolbar.test.js +54 -0
  52. package/lib/plugins/table/icons/index.js +1 -1
  53. package/lib/plugins/table/index.js +44 -60
  54. package/lib/plugins/table/table-toolbar.js +34 -5
  55. package/lib/plugins/textAlign/icons/index.js +226 -0
  56. package/lib/plugins/textAlign/index.js +34 -0
  57. package/lib/plugins/toolbar/__tests__/default-toolbar.test.js +128 -0
  58. package/lib/plugins/toolbar/__tests__/editor-and-toolbar.test.js +51 -0
  59. package/lib/plugins/toolbar/__tests__/toolbar-buttons.test.js +54 -0
  60. package/lib/plugins/toolbar/__tests__/toolbar.test.js +120 -0
  61. package/lib/plugins/toolbar/default-toolbar.js +83 -28
  62. package/lib/plugins/toolbar/done-button.js +6 -3
  63. package/lib/plugins/toolbar/editor-and-toolbar.js +19 -20
  64. package/lib/plugins/toolbar/index.js +1 -1
  65. package/lib/plugins/toolbar/toolbar-buttons.js +45 -12
  66. package/lib/plugins/toolbar/toolbar.js +36 -12
  67. package/lib/plugins/utils.js +1 -1
  68. package/lib/serialization.js +234 -45
  69. package/lib/theme.js +1 -1
  70. package/package.json +6 -6
  71. package/src/__tests__/editor.test.jsx +363 -0
  72. package/src/__tests__/serialization.test.js +291 -0
  73. package/src/__tests__/utils.js +36 -0
  74. package/src/block-tags.js +17 -0
  75. package/src/constants.js +7 -0
  76. package/src/editor.jsx +303 -49
  77. package/src/index.jsx +19 -10
  78. package/src/plugins/characters/index.jsx +11 -3
  79. package/src/plugins/characters/utils.js +12 -12
  80. package/src/plugins/css/icons/index.jsx +17 -0
  81. package/src/plugins/css/index.jsx +346 -0
  82. package/src/plugins/customPlugin/index.jsx +85 -0
  83. package/src/plugins/html/index.jsx +9 -6
  84. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +51 -0
  85. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +27 -0
  86. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +44 -0
  87. package/src/plugins/image/__tests__/component.test.jsx +41 -0
  88. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +42 -0
  89. package/src/plugins/image/__tests__/image-toolbar.test.jsx +11 -0
  90. package/src/plugins/image/__tests__/index.test.js +95 -0
  91. package/src/plugins/image/__tests__/insert-image-handler.test.js +113 -0
  92. package/src/plugins/image/__tests__/mock-change.js +15 -0
  93. package/src/plugins/image/index.jsx +2 -1
  94. package/src/plugins/image/insert-image-handler.js +13 -6
  95. package/src/plugins/index.jsx +248 -5
  96. package/src/plugins/list/__tests__/index.test.js +54 -0
  97. package/src/plugins/list/index.jsx +130 -0
  98. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +48 -0
  99. package/src/plugins/math/__tests__/index.test.jsx +245 -0
  100. package/src/plugins/math/index.jsx +87 -56
  101. package/src/plugins/media/__tests__/index.test.js +75 -0
  102. package/src/plugins/media/index.jsx +3 -2
  103. package/src/plugins/media/media-dialog.js +106 -57
  104. package/src/plugins/rendering/index.js +31 -0
  105. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +4 -1
  106. package/src/plugins/respArea/explicit-constructed-response/index.jsx +10 -8
  107. package/src/plugins/respArea/index.jsx +53 -7
  108. package/src/plugins/respArea/inline-dropdown/index.jsx +13 -6
  109. package/src/plugins/respArea/math-templated/index.jsx +104 -0
  110. package/src/plugins/respArea/utils.jsx +11 -0
  111. package/src/plugins/table/CustomTablePlugin.js +113 -0
  112. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +44 -0
  113. package/src/plugins/table/__tests__/index.test.jsx +401 -0
  114. package/src/plugins/table/__tests__/table-toolbar.test.jsx +42 -0
  115. package/src/plugins/table/index.jsx +46 -59
  116. package/src/plugins/table/table-toolbar.jsx +39 -2
  117. package/src/plugins/textAlign/icons/index.jsx +139 -0
  118. package/src/plugins/textAlign/index.jsx +23 -0
  119. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +923 -0
  120. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +20 -0
  121. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +36 -0
  122. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +46 -0
  123. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +94 -0
  124. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +37 -0
  125. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +51 -0
  126. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +106 -0
  127. package/src/plugins/toolbar/default-toolbar.jsx +80 -20
  128. package/src/plugins/toolbar/done-button.jsx +3 -1
  129. package/src/plugins/toolbar/editor-and-toolbar.jsx +18 -13
  130. package/src/plugins/toolbar/toolbar-buttons.jsx +52 -11
  131. package/src/plugins/toolbar/toolbar.jsx +31 -8
  132. package/src/serialization.jsx +213 -38
  133. package/README.md +0 -45
  134. package/deploy.sh +0 -16
  135. package/lib/editor.js.map +0 -1
  136. package/lib/index.js.map +0 -1
  137. package/lib/parse-html.js.map +0 -1
  138. package/lib/plugins/characters/custom-popper.js.map +0 -1
  139. package/lib/plugins/characters/index.js.map +0 -1
  140. package/lib/plugins/characters/utils.js.map +0 -1
  141. package/lib/plugins/html/icons/index.js.map +0 -1
  142. package/lib/plugins/html/index.js.map +0 -1
  143. package/lib/plugins/image/alt-dialog.js.map +0 -1
  144. package/lib/plugins/image/component.js.map +0 -1
  145. package/lib/plugins/image/image-toolbar.js.map +0 -1
  146. package/lib/plugins/image/index.js.map +0 -1
  147. package/lib/plugins/image/insert-image-handler.js.map +0 -1
  148. package/lib/plugins/index.js.map +0 -1
  149. package/lib/plugins/list/index.js.map +0 -1
  150. package/lib/plugins/math/index.js.map +0 -1
  151. package/lib/plugins/media/index.js.map +0 -1
  152. package/lib/plugins/media/media-dialog.js.map +0 -1
  153. package/lib/plugins/media/media-toolbar.js.map +0 -1
  154. package/lib/plugins/media/media-wrapper.js.map +0 -1
  155. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +0 -1
  156. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +0 -1
  157. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +0 -1
  158. package/lib/plugins/respArea/icons/index.js.map +0 -1
  159. package/lib/plugins/respArea/index.js.map +0 -1
  160. package/lib/plugins/respArea/inline-dropdown/index.js.map +0 -1
  161. package/lib/plugins/respArea/utils.js.map +0 -1
  162. package/lib/plugins/table/icons/index.js.map +0 -1
  163. package/lib/plugins/table/index.js.map +0 -1
  164. package/lib/plugins/table/table-toolbar.js.map +0 -1
  165. package/lib/plugins/toolbar/default-toolbar.js.map +0 -1
  166. package/lib/plugins/toolbar/done-button.js.map +0 -1
  167. package/lib/plugins/toolbar/editor-and-toolbar.js.map +0 -1
  168. package/lib/plugins/toolbar/index.js.map +0 -1
  169. package/lib/plugins/toolbar/toolbar-buttons.js.map +0 -1
  170. package/lib/plugins/toolbar/toolbar.js.map +0 -1
  171. package/lib/plugins/utils.js.map +0 -1
  172. package/lib/serialization.js.map +0 -1
  173. package/lib/theme.js.map +0 -1
  174. package/playground/image/data.js +0 -59
  175. package/playground/image/index.html +0 -22
  176. package/playground/image/index.jsx +0 -81
  177. package/playground/index.html +0 -25
  178. package/playground/mathquill/index.html +0 -22
  179. package/playground/mathquill/index.jsx +0 -155
  180. package/playground/package.json +0 -15
  181. package/playground/prod-test/index.html +0 -22
  182. package/playground/prod-test/index.jsx +0 -28
  183. package/playground/schema-override/data.js +0 -29
  184. package/playground/schema-override/image-plugin.jsx +0 -41
  185. package/playground/schema-override/index.html +0 -21
  186. package/playground/schema-override/index.jsx +0 -97
  187. package/playground/serialization/data.js +0 -29
  188. package/playground/serialization/image-plugin.jsx +0 -41
  189. package/playground/serialization/index.html +0 -22
  190. package/playground/serialization/index.jsx +0 -12
  191. package/playground/static.json +0 -3
  192. package/playground/table-examples.html +0 -70
  193. package/playground/webpack.config.js +0 -42
  194. 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.data.get('src'), (err, v) => {
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
- this.onFinish(false);
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) {