@pie-lib/editable-html-tip-tap 1.0.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 (167) hide show
  1. package/CHANGELOG.json +32 -0
  2. package/CHANGELOG.md +2280 -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 +1356 -0
  9. package/lib/extensions/MediaView.js +112 -0
  10. package/lib/extensions/characters.js +65 -0
  11. package/lib/extensions/component.js +325 -0
  12. package/lib/extensions/css.js +252 -0
  13. package/lib/extensions/custom-toolbar-wrapper.js +124 -0
  14. package/lib/extensions/image.js +106 -0
  15. package/lib/extensions/math.js +330 -0
  16. package/lib/extensions/media.js +276 -0
  17. package/lib/extensions/responseArea.js +278 -0
  18. package/lib/index.js +1213 -0
  19. package/lib/old-index.js +269 -0
  20. package/lib/parse-html.js +16 -0
  21. package/lib/plugins/characters/custom-popper.js +73 -0
  22. package/lib/plugins/characters/index.js +305 -0
  23. package/lib/plugins/characters/utils.js +381 -0
  24. package/lib/plugins/css/icons/index.js +37 -0
  25. package/lib/plugins/css/index.js +390 -0
  26. package/lib/plugins/customPlugin/index.js +114 -0
  27. package/lib/plugins/html/icons/index.js +38 -0
  28. package/lib/plugins/html/index.js +81 -0
  29. package/lib/plugins/image/__tests__/component.test.js +51 -0
  30. package/lib/plugins/image/__tests__/image-toolbar-logic.test.js +56 -0
  31. package/lib/plugins/image/__tests__/image-toolbar.test.js +26 -0
  32. package/lib/plugins/image/__tests__/index.test.js +98 -0
  33. package/lib/plugins/image/__tests__/insert-image-handler.test.js +125 -0
  34. package/lib/plugins/image/__tests__/mock-change.js +25 -0
  35. package/lib/plugins/image/alt-dialog.js +129 -0
  36. package/lib/plugins/image/component.js +419 -0
  37. package/lib/plugins/image/image-toolbar.js +177 -0
  38. package/lib/plugins/image/index.js +263 -0
  39. package/lib/plugins/image/insert-image-handler.js +117 -0
  40. package/lib/plugins/index.js +413 -0
  41. package/lib/plugins/list/__tests__/index.test.js +79 -0
  42. package/lib/plugins/list/index.js +334 -0
  43. package/lib/plugins/math/__tests__/index.test.js +300 -0
  44. package/lib/plugins/math/index.js +454 -0
  45. package/lib/plugins/media/__tests__/index.test.js +71 -0
  46. package/lib/plugins/media/index.js +387 -0
  47. package/lib/plugins/media/media-dialog.js +709 -0
  48. package/lib/plugins/media/media-toolbar.js +101 -0
  49. package/lib/plugins/media/media-wrapper.js +93 -0
  50. package/lib/plugins/rendering/index.js +46 -0
  51. package/lib/plugins/respArea/drag-in-the-blank/choice.js +289 -0
  52. package/lib/plugins/respArea/drag-in-the-blank/index.js +94 -0
  53. package/lib/plugins/respArea/explicit-constructed-response/index.js +120 -0
  54. package/lib/plugins/respArea/icons/index.js +95 -0
  55. package/lib/plugins/respArea/index.js +341 -0
  56. package/lib/plugins/respArea/inline-dropdown/index.js +126 -0
  57. package/lib/plugins/respArea/math-templated/index.js +130 -0
  58. package/lib/plugins/respArea/utils.js +125 -0
  59. package/lib/plugins/table/CustomTablePlugin.js +133 -0
  60. package/lib/plugins/table/__tests__/index.test.js +442 -0
  61. package/lib/plugins/table/__tests__/table-toolbar.test.js +54 -0
  62. package/lib/plugins/table/icons/index.js +69 -0
  63. package/lib/plugins/table/index.js +483 -0
  64. package/lib/plugins/table/table-toolbar.js +187 -0
  65. package/lib/plugins/textAlign/icons/index.js +194 -0
  66. package/lib/plugins/textAlign/index.js +34 -0
  67. package/lib/plugins/toolbar/__tests__/default-toolbar.test.js +128 -0
  68. package/lib/plugins/toolbar/__tests__/editor-and-toolbar.test.js +51 -0
  69. package/lib/plugins/toolbar/__tests__/toolbar-buttons.test.js +54 -0
  70. package/lib/plugins/toolbar/__tests__/toolbar.test.js +120 -0
  71. package/lib/plugins/toolbar/default-toolbar.js +229 -0
  72. package/lib/plugins/toolbar/done-button.js +53 -0
  73. package/lib/plugins/toolbar/editor-and-toolbar.js +286 -0
  74. package/lib/plugins/toolbar/index.js +34 -0
  75. package/lib/plugins/toolbar/toolbar-buttons.js +194 -0
  76. package/lib/plugins/toolbar/toolbar.js +376 -0
  77. package/lib/plugins/utils.js +62 -0
  78. package/lib/serialization.js +677 -0
  79. package/lib/shared/alert-dialog.js +75 -0
  80. package/lib/theme.js +9 -0
  81. package/package.json +69 -0
  82. package/src/__tests__/editor.test.jsx +363 -0
  83. package/src/__tests__/serialization.test.js +291 -0
  84. package/src/__tests__/utils.js +36 -0
  85. package/src/block-tags.js +17 -0
  86. package/src/constants.js +7 -0
  87. package/src/editor.jsx +1197 -0
  88. package/src/extensions/characters.js +46 -0
  89. package/src/extensions/component.jsx +294 -0
  90. package/src/extensions/css.js +217 -0
  91. package/src/extensions/custom-toolbar-wrapper.jsx +100 -0
  92. package/src/extensions/image.js +55 -0
  93. package/src/extensions/math.js +259 -0
  94. package/src/extensions/media.js +182 -0
  95. package/src/extensions/responseArea.js +205 -0
  96. package/src/index.jsx +1462 -0
  97. package/src/old-index.jsx +162 -0
  98. package/src/parse-html.js +8 -0
  99. package/src/plugins/README.md +27 -0
  100. package/src/plugins/characters/custom-popper.js +48 -0
  101. package/src/plugins/characters/index.jsx +284 -0
  102. package/src/plugins/characters/utils.js +447 -0
  103. package/src/plugins/css/icons/index.jsx +17 -0
  104. package/src/plugins/css/index.jsx +340 -0
  105. package/src/plugins/customPlugin/index.jsx +85 -0
  106. package/src/plugins/html/icons/index.jsx +19 -0
  107. package/src/plugins/html/index.jsx +72 -0
  108. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +51 -0
  109. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +27 -0
  110. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +44 -0
  111. package/src/plugins/image/__tests__/component.test.jsx +41 -0
  112. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +42 -0
  113. package/src/plugins/image/__tests__/image-toolbar.test.jsx +11 -0
  114. package/src/plugins/image/__tests__/index.test.js +95 -0
  115. package/src/plugins/image/__tests__/insert-image-handler.test.js +113 -0
  116. package/src/plugins/image/__tests__/mock-change.js +15 -0
  117. package/src/plugins/image/alt-dialog.jsx +82 -0
  118. package/src/plugins/image/component.jsx +343 -0
  119. package/src/plugins/image/image-toolbar.jsx +100 -0
  120. package/src/plugins/image/index.jsx +227 -0
  121. package/src/plugins/image/insert-image-handler.js +79 -0
  122. package/src/plugins/index.jsx +377 -0
  123. package/src/plugins/list/__tests__/index.test.js +54 -0
  124. package/src/plugins/list/index.jsx +305 -0
  125. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +48 -0
  126. package/src/plugins/math/__tests__/index.test.jsx +245 -0
  127. package/src/plugins/math/index.jsx +379 -0
  128. package/src/plugins/media/__tests__/index.test.js +75 -0
  129. package/src/plugins/media/index.jsx +325 -0
  130. package/src/plugins/media/media-dialog.js +624 -0
  131. package/src/plugins/media/media-toolbar.jsx +56 -0
  132. package/src/plugins/media/media-wrapper.jsx +43 -0
  133. package/src/plugins/rendering/index.js +31 -0
  134. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +215 -0
  135. package/src/plugins/respArea/drag-in-the-blank/index.jsx +70 -0
  136. package/src/plugins/respArea/explicit-constructed-response/index.jsx +92 -0
  137. package/src/plugins/respArea/icons/index.jsx +71 -0
  138. package/src/plugins/respArea/index.jsx +299 -0
  139. package/src/plugins/respArea/inline-dropdown/index.jsx +108 -0
  140. package/src/plugins/respArea/math-templated/index.jsx +104 -0
  141. package/src/plugins/respArea/utils.jsx +90 -0
  142. package/src/plugins/table/CustomTablePlugin.js +113 -0
  143. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +44 -0
  144. package/src/plugins/table/__tests__/index.test.jsx +401 -0
  145. package/src/plugins/table/__tests__/table-toolbar.test.jsx +42 -0
  146. package/src/plugins/table/icons/index.jsx +53 -0
  147. package/src/plugins/table/index.jsx +427 -0
  148. package/src/plugins/table/table-toolbar.jsx +136 -0
  149. package/src/plugins/textAlign/icons/index.jsx +114 -0
  150. package/src/plugins/textAlign/index.jsx +23 -0
  151. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +923 -0
  152. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +20 -0
  153. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +36 -0
  154. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +46 -0
  155. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +94 -0
  156. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +37 -0
  157. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +51 -0
  158. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +106 -0
  159. package/src/plugins/toolbar/default-toolbar.jsx +206 -0
  160. package/src/plugins/toolbar/done-button.jsx +38 -0
  161. package/src/plugins/toolbar/editor-and-toolbar.jsx +257 -0
  162. package/src/plugins/toolbar/index.jsx +23 -0
  163. package/src/plugins/toolbar/toolbar-buttons.jsx +138 -0
  164. package/src/plugins/toolbar/toolbar.jsx +338 -0
  165. package/src/plugins/utils.js +31 -0
  166. package/src/serialization.jsx +621 -0
  167. package/src/theme.js +1 -0
@@ -0,0 +1,44 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`table-toolbar snapshot renders 1`] = `
4
+ <div
5
+ className="table-toolbar"
6
+ >
7
+ <div>
8
+ <WithStyles(RawButton)
9
+ onClick={[MockFunction]}
10
+ >
11
+ <WithStyles(Component) />
12
+ </WithStyles(RawButton)>
13
+ <WithStyles(RawButton)
14
+ onClick={[MockFunction]}
15
+ >
16
+ <WithStyles(Component) />
17
+ </WithStyles(RawButton)>
18
+ <WithStyles(RawButton)
19
+ onClick={[MockFunction]}
20
+ >
21
+ <WithStyles(Component) />
22
+ </WithStyles(RawButton)>
23
+ <WithStyles(RawButton)
24
+ onClick={[MockFunction]}
25
+ >
26
+ <WithStyles(Component) />
27
+ </WithStyles(RawButton)>
28
+ <WithStyles(RawButton)
29
+ onClick={[MockFunction]}
30
+ >
31
+ <WithStyles(Component) />
32
+ </WithStyles(RawButton)>
33
+ <WithStyles(RawButton)
34
+ active={true}
35
+ onClick={[MockFunction]}
36
+ >
37
+ <pure(BorderAllIcon) />
38
+ </WithStyles(RawButton)>
39
+ </div>
40
+ <WithStyles(RawDoneButton)
41
+ onClick={[Function]}
42
+ />
43
+ </div>
44
+ `;
@@ -0,0 +1,401 @@
1
+ import EditTable from 'slate-edit-table';
2
+ import TablePlugin, { serialization, parseStyleString, reactAttributes } from '../index';
3
+ import { Data, Block, PathUtils } from 'slate';
4
+ import React from 'react';
5
+
6
+ jest.mock('slate-edit-table', () => {
7
+ const mock = {
8
+ default: jest.fn().mockReturnThis(),
9
+ utils: {
10
+ isSelectionInTable: jest.fn().mockReturnValue(true),
11
+ createTable: jest.fn(function(c) {
12
+ return {
13
+ toJSON: jest.fn().mockReturnValue({ object: 'block', type: 'table' }),
14
+ };
15
+ }),
16
+ },
17
+ changes: {
18
+ insertTable: jest.fn(function(c) {
19
+ return c;
20
+ }),
21
+ },
22
+ };
23
+
24
+ return jest.fn().mockReturnValue(mock);
25
+ });
26
+
27
+ describe('table', () => {
28
+ describe('toolbar', () => {
29
+ describe('onClick', () => {
30
+ let plugin;
31
+ let onChange;
32
+ let findDescendant;
33
+ let insertBlock;
34
+ let changeMock;
35
+
36
+ beforeEach(() => {
37
+ plugin = TablePlugin();
38
+ onChange = jest.fn();
39
+ insertBlock = jest.fn();
40
+ findDescendant = jest.fn();
41
+ changeMock = jest.fn().mockReturnValue({
42
+ insertBlock,
43
+ value: {
44
+ document: {
45
+ findDescendant,
46
+ },
47
+ },
48
+ });
49
+ });
50
+
51
+ it('calls utils.createTable', () => {
52
+ plugin.toolbar.onClick({ change: changeMock }, onChange);
53
+
54
+ expect(EditTable().utils.createTable).toHaveBeenCalledWith(2, 2);
55
+ });
56
+
57
+ it('creates table with border: 1 as default', () => {
58
+ plugin.toolbar.onClick({ change: changeMock }, onChange);
59
+
60
+ expect(insertBlock).toHaveBeenCalledWith(
61
+ Block.create({ key: '2', type: 'table', data: { border: '1', newTable: true } }),
62
+ );
63
+ });
64
+
65
+ it('moves cursor to first cell of the table and removes the newTable property', () => {
66
+ const dataRemoveFn = jest.fn().mockReturnValue({ border: '1' });
67
+ const setNodeByKey = jest.fn();
68
+ const newTableBlock = {
69
+ key: '2',
70
+ data: {
71
+ remove: dataRemoveFn,
72
+ },
73
+ };
74
+ const collapseToStartOf = jest.fn();
75
+
76
+ changeMock = jest.fn().mockReturnValue({
77
+ insertBlock,
78
+ collapseToStartOf,
79
+ setNodeByKey,
80
+ value: {
81
+ document: {
82
+ findDescendant: jest.fn().mockReturnValue(newTableBlock),
83
+ },
84
+ },
85
+ });
86
+ plugin.toolbar.onClick({ change: changeMock }, onChange);
87
+
88
+ expect(collapseToStartOf).toHaveBeenCalledWith(newTableBlock);
89
+ expect(dataRemoveFn).toHaveBeenCalledWith('newTable');
90
+ expect(setNodeByKey).toHaveBeenCalledWith('2', { data: { border: '1' } });
91
+ });
92
+ });
93
+
94
+ describe('supports', () => {
95
+ const assertSupports = (inTable, object, expected) => {
96
+ it(`inTable: ${inTable}, type: ${object} => ${expected}`, () => {
97
+ EditTable().utils.isSelectionInTable.mockReturnValue(inTable);
98
+ const plugin = TablePlugin();
99
+ const supports = plugin.toolbar.supports({ object });
100
+ expect(supports).toEqual(expected);
101
+ });
102
+ };
103
+
104
+ assertSupports(true, 'block', true);
105
+ assertSupports(false, 'block', false);
106
+ assertSupports(true, 'inline', false);
107
+ assertSupports(false, 'inline', false);
108
+ });
109
+
110
+ describe('customToolbar', () => {
111
+ describe('toggleBorder', () => {
112
+ const assertToggle = (border, expectedBorder) => {
113
+ describe(`with initial border of ${border}`, () => {
114
+ let change;
115
+ let done;
116
+
117
+ beforeEach(() => {
118
+ const plugin = TablePlugin();
119
+ change = {
120
+ setNodeByKey: jest.fn().mockReturnThis(),
121
+ };
122
+ plugin.utils.getTableBlock = jest.fn().mockReturnValue({
123
+ key: 'tableKey',
124
+ data: Data.create({ border }),
125
+ });
126
+ const node = { key: 'nodeKey' };
127
+ const value = {
128
+ change: jest.fn().mockReturnValue(change),
129
+ };
130
+ done = jest.fn();
131
+ const Comp = plugin.toolbar.customToolbar(node, value, done);
132
+ const c = Comp();
133
+ c.props.onToggleBorder();
134
+ });
135
+
136
+ it(`calls setNodeByKey with ${expectedBorder}`, () => {
137
+ expect(change.setNodeByKey).toHaveBeenCalledWith('tableKey', {
138
+ data: Data.create({ border: expectedBorder }),
139
+ });
140
+ });
141
+
142
+ it('calls onToolbarDone', () => {
143
+ expect(done).toHaveBeenCalledWith(change, false);
144
+ });
145
+ });
146
+ };
147
+
148
+ assertToggle(null, '1');
149
+ assertToggle(undefined, '1');
150
+ assertToggle('0', '1');
151
+ assertToggle('1', '0');
152
+ assertToggle('2', '0');
153
+ });
154
+ });
155
+
156
+ describe('normalizeNode', () => {
157
+ it('should exit the function if the node is not of type document', () => {
158
+ const tablePlugin = TablePlugin();
159
+ const returnValue = tablePlugin.normalizeNode({ object: 'table' });
160
+
161
+ expect(returnValue).toEqual(undefined);
162
+ });
163
+
164
+ it('should exit there are no changes needed', () => {
165
+ const tablePlugin = TablePlugin();
166
+ const nodes = {
167
+ size: 3,
168
+ findLastIndex: jest.fn().mockReturnValue(1),
169
+ };
170
+ const returnValue = tablePlugin.normalizeNode({
171
+ object: 'document',
172
+ nodes,
173
+ findDescendant: jest.fn().mockReturnValue({ object: 'block', type: 'table' }),
174
+ getParent: jest.fn().mockReturnValue(undefined),
175
+ });
176
+ expect(returnValue).toEqual(undefined);
177
+ });
178
+
179
+ it('should return a function if a table does not have a node before or after it', () => {
180
+ const tablePlugin = TablePlugin();
181
+ const nodes = [
182
+ {
183
+ object: 'block',
184
+ type: 'table',
185
+ key: '99',
186
+ data: Data.create({
187
+ newTable: true,
188
+ }),
189
+ },
190
+ ];
191
+ const findDescendant = jest.fn((callback) => {
192
+ nodes.forEach((n) => callback(n));
193
+ });
194
+ const change = {
195
+ insertNodeByPath: jest.fn(),
196
+ value: {
197
+ document: {
198
+ getPath: jest.fn().mockReturnValue(PathUtils.create([0, 0])),
199
+ },
200
+ },
201
+ };
202
+
203
+ const returnValue = tablePlugin.normalizeNode({
204
+ object: 'document',
205
+ findDescendant,
206
+ getPath: jest.fn().mockReturnValue(PathUtils.create([0, 0])),
207
+ getPreviousNode: jest.fn().mockReturnValue(undefined),
208
+ getNextNode: jest.fn().mockReturnValue(undefined),
209
+ });
210
+
211
+ expect(returnValue).toEqual(expect.any(Function));
212
+
213
+ returnValue(change);
214
+
215
+ expect(change.insertNodeByPath).toHaveBeenCalledWith([0], 0, {
216
+ object: 'block',
217
+ type: 'div',
218
+ });
219
+ });
220
+ });
221
+ });
222
+ });
223
+
224
+ describe('parseStyleString', () => {
225
+ const parses = (s, expected) => {
226
+ it(`parses ${s} -> ${JSON.stringify(expected)}`, () => {
227
+ const result = parseStyleString(s);
228
+ expect(result).toEqual(expected);
229
+ });
230
+ };
231
+ parses(' width: 10px ', { width: '10px' });
232
+ parses(' width: 10px; ', { width: '10px' });
233
+ parses(' border-width: 10px; ', { 'border-width': '10px' });
234
+ parses(' border: solid 1px red; height: 1px', {
235
+ border: 'solid 1px red',
236
+ height: '1px',
237
+ });
238
+ });
239
+
240
+ describe('toStyleString', () => {
241
+ const styleString = (o, expected) => {
242
+ it(`${JSON.stringify(s)} -> ${expected}`, () => {
243
+ const result = toStyleString(o);
244
+ expect(result).toEqual(expected);
245
+ });
246
+ };
247
+ });
248
+
249
+ describe('reactAttributes', () => {
250
+ const attributes = (o, expected) => {
251
+ it(`${JSON.stringify(o)} -> ${JSON.stringify(expected)}`, () => {
252
+ const result = reactAttributes(o);
253
+ expect(result).toEqual(expected);
254
+ });
255
+ };
256
+ attributes({ 'border-width': '10px', 'line-height': 1.56 }, { borderWidth: '10px', lineHeight: '1.56' });
257
+ });
258
+
259
+ describe('serialization', () => {
260
+ describe('deserialize', () => {
261
+ let next;
262
+
263
+ beforeEach(() => {
264
+ next = jest.fn().mockReturnValue([]);
265
+ });
266
+
267
+ describe('table', () => {
268
+ let el;
269
+ let out;
270
+ beforeEach(() => {
271
+ el = {
272
+ tagName: 'table',
273
+ children: [],
274
+ getAttribute: jest.fn((name) => {
275
+ switch (name) {
276
+ case 'border':
277
+ return '1';
278
+ case 'cellspacing':
279
+ return '2';
280
+ case 'cellpadding':
281
+ return '3';
282
+ case 'class':
283
+ return 'table-class';
284
+ case 'style':
285
+ return 'width: 10px';
286
+ }
287
+ }),
288
+ };
289
+ out = serialization.deserialize(el, next);
290
+ });
291
+
292
+ const assertData = (name, value) => {
293
+ it(`data.${name} should eql ${value}`, () => {
294
+ expect(out.data[name]).toEqual(value);
295
+ });
296
+ };
297
+
298
+ assertData('border', '1');
299
+ assertData('cellspacing', '2');
300
+ assertData('cellpadding', '3');
301
+ assertData('class', 'table-class');
302
+ assertData('style', { width: '10px' });
303
+ it('returns a table block', () => {
304
+ expect(out).toMatchObject({
305
+ object: 'block',
306
+ type: 'table',
307
+ nodes: [],
308
+ });
309
+ });
310
+ });
311
+
312
+ it('deserializes tr', () => {
313
+ const el = {
314
+ tagName: 'tr',
315
+ children: [],
316
+ };
317
+
318
+ const out = serialization.deserialize(el, next);
319
+
320
+ expect(out).toEqual({
321
+ object: 'block',
322
+ type: 'table_row',
323
+ nodes: [],
324
+ });
325
+ });
326
+
327
+ it('deserializes td', () => {
328
+ const el = {
329
+ tagName: 'td',
330
+ childNodes: [],
331
+ getAttribute: jest.fn(function(name) {
332
+ const o = {
333
+ class: 'class name',
334
+ colspan: '1',
335
+ rowspan: '1',
336
+ };
337
+ return o[name];
338
+ }),
339
+ };
340
+
341
+ const out = serialization.deserialize(el, next);
342
+
343
+ expect(out).toEqual({
344
+ object: 'block',
345
+ type: 'table_cell',
346
+ nodes: [],
347
+ data: {
348
+ colspan: '1',
349
+ rowspan: '1',
350
+ class: 'class name',
351
+ header: false,
352
+ },
353
+ });
354
+ });
355
+ });
356
+
357
+ describe('serialize', () => {
358
+ it('serializes table', () => {
359
+ const el = serialization.serialize({
360
+ object: 'block',
361
+ type: 'table',
362
+ nodes: [],
363
+ data: Data.create({
364
+ border: '1',
365
+ cellpadding: '2',
366
+ cellspacing: '3',
367
+ }),
368
+ });
369
+
370
+ expect(el).toEqual(
371
+ <table border="1" cellPadding="2" cellSpacing="3">
372
+ <tbody />
373
+ </table>,
374
+ );
375
+ });
376
+
377
+ it('serializes table_row', () => {
378
+ const el = serialization.serialize({
379
+ object: 'block',
380
+ type: 'table_row',
381
+ nodes: [],
382
+ });
383
+
384
+ expect(el).toEqual(<tr />);
385
+ });
386
+ it('serializes table_cell', () => {
387
+ const el = serialization.serialize({
388
+ object: 'block',
389
+ type: 'table_cell',
390
+ nodes: [],
391
+ data: Data.create({
392
+ header: false,
393
+ style: { width: '10px' },
394
+ class: 'foo',
395
+ }),
396
+ });
397
+
398
+ expect(el).toEqual(<td style={{ width: '10px' }} className={'foo'} />);
399
+ });
400
+ });
401
+ });
@@ -0,0 +1,42 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { TableToolbar } from '../table-toolbar';
4
+ describe('table-toolbar', () => {
5
+ let onDone, onAddColumn, onAddRow, onRemoveColumn, onRemoveRow, onRemoveTable, onToggleBorder;
6
+
7
+ beforeEach(() => {
8
+ onAddColumn = jest.fn();
9
+ onAddRow = jest.fn();
10
+ onRemoveColumn = jest.fn();
11
+ onRemoveRow = jest.fn();
12
+ onRemoveTable = jest.fn();
13
+ onDone = jest.fn();
14
+ onToggleBorder = jest.fn();
15
+ });
16
+
17
+ const mkWrapper = (extras) => {
18
+ const props = {
19
+ onDone,
20
+ onAddRow,
21
+ onRemoveRow,
22
+ onAddColumn,
23
+ onRemoveColumn,
24
+ onRemoveTable,
25
+ hasBorder: true,
26
+ onToggleBorder,
27
+ classes: {
28
+ tableToolbar: 'table-toolbar',
29
+ },
30
+ ...extras,
31
+ };
32
+
33
+ return shallow(<TableToolbar {...props} />);
34
+ };
35
+
36
+ describe('snapshot', () => {
37
+ it('renders', () => {
38
+ const w = mkWrapper();
39
+ expect(w).toMatchSnapshot();
40
+ });
41
+ });
42
+ });
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+ import { withStyles } from '@material-ui/core/styles';
3
+
4
+ const styles = {
5
+ icon: {
6
+ fill: 'grey',
7
+ '&:hover': {
8
+ fill: 'black',
9
+ },
10
+ },
11
+ };
12
+
13
+ const SvgIcon = (Component) => {
14
+ return withStyles(styles)((props) => (
15
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="24" height="24" viewBox="0 0 24 24">
16
+ <Component className={props.classes.icon} />
17
+ </svg>
18
+ ));
19
+ };
20
+ export const AddRow = SvgIcon((props) => (
21
+ <path
22
+ {...props}
23
+ d="M22,10A2,2 0 0,1 20,12H4A2,2 0 0,1 2,10V3H4V5H8V3H10V5H14V3H16V5H20V3H22V10M4,10H8V7H4V10M10,10H14V7H10V10M20,10V7H16V10H20M11,14H13V17H16V19H13V22H11V19H8V17H11V14Z"
24
+ />
25
+ ));
26
+
27
+ export const RemoveRow = SvgIcon((props) => (
28
+ <path
29
+ {...props}
30
+ d="M9.41,13L12,15.59L14.59,13L16,14.41L13.41,17L16,19.59L14.59,21L12,18.41L9.41,21L8,19.59L10.59,17L8,14.41L9.41,13M22,9A2,2 0 0,1 20,11H4A2,2 0 0,1 2,9V6A2,2 0 0,1 4,4H20A2,2 0 0,1 22,6V9M4,9H8V6H4V9M10,9H14V6H10V9M16,9H20V6H16V9Z"
31
+ />
32
+ ));
33
+
34
+ export const AddColumn = SvgIcon((props) => (
35
+ <path
36
+ {...props}
37
+ d="M11,2A2,2 0 0,1 13,4V20A2,2 0 0,1 11,22H2V2H11M4,10V14H11V10H4M4,16V20H11V16H4M4,4V8H11V4H4M15,11H18V8H20V11H23V13H20V16H18V13H15V11Z"
38
+ />
39
+ ));
40
+
41
+ export const RemoveColumn = SvgIcon((props) => (
42
+ <path
43
+ {...props}
44
+ d="M4,2H11A2,2 0 0,1 13,4V20A2,2 0 0,1 11,22H4A2,2 0 0,1 2,20V4A2,2 0 0,1 4,2M4,10V14H11V10H4M4,16V20H11V16H4M4,4V8H11V4H4M17.59,12L15,9.41L16.41,8L19,10.59L21.59,8L23,9.41L20.41,12L23,14.59L21.59,16L19,13.41L16.41,16L15,14.59L17.59,12Z"
45
+ />
46
+ ));
47
+
48
+ export const RemoveTable = SvgIcon((props) => (
49
+ <path
50
+ {...props}
51
+ d="M15.46,15.88L16.88,14.46L19,16.59L21.12,14.46L22.54,15.88L20.41,18L22.54,20.12L21.12,21.54L19,19.41L16.88,21.54L15.46,20.12L17.59,18L15.46,15.88M4,3H18A2,2 0 0,1 20,5V12.08C18.45,11.82 16.92,12.18 15.68,13H12V17H13.08C12.97,17.68 12.97,18.35 13.08,19H4A2,2 0 0,1 2,17V5A2,2 0 0,1 4,3M4,7V11H10V7H4M12,7V11H18V7H12M4,13V17H10V13H4Z"
52
+ />
53
+ ));