@pie-lib/editable-html-tip-tap 1.0.2 → 1.0.4

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 (165) hide show
  1. package/lib/components/CharacterPicker.js +221 -0
  2. package/lib/components/CharacterPicker.js.map +1 -0
  3. package/lib/components/EditableHtml.js +323 -0
  4. package/lib/components/EditableHtml.js.map +1 -0
  5. package/lib/components/MenuBar.js +694 -0
  6. package/lib/components/MenuBar.js.map +1 -0
  7. package/lib/components/TiptapContainer.js +90 -0
  8. package/lib/components/TiptapContainer.js.map +1 -0
  9. package/lib/components/buttons/done-button.js +53 -0
  10. package/lib/components/characters/characterUtils.js +112 -0
  11. package/lib/components/characters/characterUtils.js.map +1 -0
  12. package/lib/components/characters/custom-popper.js +73 -0
  13. package/lib/components/characters/custom-popper.js.map +1 -0
  14. package/lib/components/common/done-button.js +53 -0
  15. package/lib/components/common/done-button.js.map +1 -0
  16. package/lib/components/common/toolbar-buttons.js +194 -0
  17. package/lib/components/icons/CssIcon.js +37 -0
  18. package/lib/components/icons/CssIcon.js.map +1 -0
  19. package/lib/components/icons/RespArea.js +95 -0
  20. package/lib/components/icons/RespArea.js.map +1 -0
  21. package/lib/components/icons/TableIcons.js +69 -0
  22. package/lib/components/icons/TableIcons.js.map +1 -0
  23. package/lib/components/icons/TextAlign.js +194 -0
  24. package/lib/components/icons/TextAlign.js.map +1 -0
  25. package/lib/components/icons/index.js +194 -0
  26. package/lib/components/image/AltDialog.js +129 -0
  27. package/lib/components/image/ImageToolbar.js +177 -0
  28. package/lib/components/image/ImageToolbar.js.map +1 -0
  29. package/lib/components/image/InsertImageHandler.js +115 -0
  30. package/lib/components/image/InsertImageHandler.js.map +1 -0
  31. package/lib/components/image/alt-dialog.js +2 -0
  32. package/lib/components/media/MediaDialog.js +709 -0
  33. package/lib/components/media/MediaDialog.js.map +1 -0
  34. package/lib/components/media/MediaToolbar.js +101 -0
  35. package/lib/components/media/MediaToolbar.js.map +1 -0
  36. package/lib/components/media/MediaWrapper.js +93 -0
  37. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +94 -0
  38. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -0
  39. package/lib/components/respArea/DragInTheBlank/choice.js +289 -0
  40. package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -0
  41. package/lib/components/respArea/DragInTheBlank.js +94 -0
  42. package/lib/components/respArea/ExplicitConstructedResponse.js +120 -0
  43. package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -0
  44. package/lib/components/respArea/InlineDropdown.js +126 -0
  45. package/lib/components/respArea/InlineDropdown.js.map +1 -0
  46. package/lib/components/respArea/ToolbarIcon.js +105 -0
  47. package/lib/components/respArea/ToolbarIcon.js.map +1 -0
  48. package/lib/components/respArea/choice.js +2 -0
  49. package/lib/constants.js.map +1 -0
  50. package/lib/extensions/component.js +5 -5
  51. package/lib/extensions/component.js.map +1 -0
  52. package/lib/extensions/css.js.map +1 -0
  53. package/lib/extensions/custom-toolbar-wrapper.js +2 -4
  54. package/lib/extensions/custom-toolbar-wrapper.js.map +1 -0
  55. package/lib/extensions/extended-table.js +30 -0
  56. package/lib/extensions/extended-table.js.map +1 -0
  57. package/lib/extensions/image.js +2 -8
  58. package/lib/extensions/image.js.map +1 -0
  59. package/lib/extensions/index.js +52 -0
  60. package/lib/extensions/index.js.map +1 -0
  61. package/lib/extensions/math.js.map +1 -0
  62. package/lib/extensions/media.js +7 -7
  63. package/lib/extensions/media.js.map +1 -0
  64. package/lib/extensions/responseArea.js +7 -7
  65. package/lib/extensions/responseArea.js.map +1 -0
  66. package/lib/index.js +16 -1481
  67. package/lib/index.js.map +1 -0
  68. package/lib/plugins/index.js +8 -80
  69. package/lib/styles/editorContainerStyles.js +200 -0
  70. package/lib/styles/editorContainerStyles.js.map +1 -0
  71. package/lib/theme.js.map +1 -0
  72. package/lib/utils/size.js +34 -0
  73. package/lib/utils/size.js.map +1 -0
  74. package/package.json +1 -1
  75. package/src/components/CharacterPicker.jsx +185 -0
  76. package/src/components/EditableHtml.jsx +306 -0
  77. package/src/components/MenuBar.jsx +630 -0
  78. package/src/components/TiptapContainer.jsx +96 -0
  79. package/src/components/characters/characterUtils.js +127 -0
  80. package/src/{plugins/image/image-toolbar.jsx → components/image/ImageToolbar.jsx} +2 -2
  81. package/src/{plugins/image/insert-image-handler.js → components/image/InsertImageHandler.js} +0 -1
  82. package/src/{plugins/media/media-dialog.js → components/media/MediaDialog.js} +2 -2
  83. package/src/{plugins/respArea/drag-in-the-blank → components/respArea/DragInTheBlank}/choice.jsx +1 -1
  84. package/src/{plugins/respArea/inline-dropdown/index.jsx → components/respArea/InlineDropdown.jsx} +1 -1
  85. package/src/components/respArea/ToolbarIcon.jsx +68 -0
  86. package/src/extensions/component.jsx +2 -2
  87. package/src/extensions/custom-toolbar-wrapper.jsx +6 -7
  88. package/src/extensions/extended-table.js +27 -0
  89. package/src/extensions/image.js +2 -2
  90. package/src/extensions/index.js +76 -0
  91. package/src/extensions/media.js +12 -7
  92. package/src/extensions/responseArea.js +7 -7
  93. package/src/index.jsx +3 -1440
  94. package/src/styles/editorContainerStyles.js +203 -0
  95. package/src/utils/size.js +32 -0
  96. package/src/__tests__/editor.test.jsx +0 -363
  97. package/src/__tests__/serialization.test.js +0 -291
  98. package/src/block-tags.js +0 -17
  99. package/src/editor.jsx +0 -1197
  100. package/src/extensions/characters.js +0 -46
  101. package/src/old-index.jsx +0 -162
  102. package/src/parse-html.js +0 -8
  103. package/src/plugins/README.md +0 -27
  104. package/src/plugins/characters/index.jsx +0 -284
  105. package/src/plugins/characters/utils.js +0 -447
  106. package/src/plugins/css/index.jsx +0 -340
  107. package/src/plugins/customPlugin/index.jsx +0 -85
  108. package/src/plugins/html/icons/index.jsx +0 -19
  109. package/src/plugins/html/index.jsx +0 -72
  110. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +0 -51
  111. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +0 -27
  112. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +0 -44
  113. package/src/plugins/image/__tests__/component.test.jsx +0 -41
  114. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +0 -42
  115. package/src/plugins/image/__tests__/image-toolbar.test.jsx +0 -11
  116. package/src/plugins/image/__tests__/index.test.js +0 -95
  117. package/src/plugins/image/__tests__/insert-image-handler.test.js +0 -113
  118. package/src/plugins/image/__tests__/mock-change.js +0 -15
  119. package/src/plugins/image/component.jsx +0 -343
  120. package/src/plugins/image/index.jsx +0 -227
  121. package/src/plugins/index.jsx +0 -377
  122. package/src/plugins/list/__tests__/index.test.js +0 -54
  123. package/src/plugins/list/index.jsx +0 -305
  124. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +0 -48
  125. package/src/plugins/math/__tests__/index.test.jsx +0 -245
  126. package/src/plugins/math/index.jsx +0 -379
  127. package/src/plugins/media/__tests__/index.test.js +0 -75
  128. package/src/plugins/media/index.jsx +0 -325
  129. package/src/plugins/rendering/index.js +0 -31
  130. package/src/plugins/respArea/index.jsx +0 -299
  131. package/src/plugins/respArea/math-templated/index.jsx +0 -104
  132. package/src/plugins/respArea/utils.jsx +0 -90
  133. package/src/plugins/table/CustomTablePlugin.js +0 -113
  134. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +0 -44
  135. package/src/plugins/table/__tests__/index.test.jsx +0 -401
  136. package/src/plugins/table/__tests__/table-toolbar.test.jsx +0 -42
  137. package/src/plugins/table/index.jsx +0 -427
  138. package/src/plugins/table/table-toolbar.jsx +0 -136
  139. package/src/plugins/textAlign/index.jsx +0 -23
  140. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +0 -923
  141. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +0 -20
  142. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +0 -36
  143. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +0 -46
  144. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +0 -94
  145. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +0 -37
  146. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +0 -51
  147. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +0 -106
  148. package/src/plugins/toolbar/default-toolbar.jsx +0 -206
  149. package/src/plugins/toolbar/editor-and-toolbar.jsx +0 -257
  150. package/src/plugins/toolbar/index.jsx +0 -23
  151. package/src/plugins/toolbar/toolbar.jsx +0 -338
  152. package/src/plugins/utils.js +0 -31
  153. package/src/serialization.jsx +0 -621
  154. /package/src/{plugins → components}/characters/custom-popper.js +0 -0
  155. /package/src/{plugins/toolbar → components/common}/done-button.jsx +0 -0
  156. /package/src/{plugins/toolbar → components/common}/toolbar-buttons.jsx +0 -0
  157. /package/src/{plugins/css/icons/index.jsx → components/icons/CssIcon.jsx} +0 -0
  158. /package/src/{plugins/respArea/icons/index.jsx → components/icons/RespArea.jsx} +0 -0
  159. /package/src/{plugins/table/icons/index.jsx → components/icons/TableIcons.jsx} +0 -0
  160. /package/src/{plugins/textAlign/icons/index.jsx → components/icons/TextAlign.jsx} +0 -0
  161. /package/src/{plugins/image/alt-dialog.jsx → components/image/AltDialog.jsx} +0 -0
  162. /package/src/{plugins/media/media-toolbar.jsx → components/media/MediaToolbar.jsx} +0 -0
  163. /package/src/{plugins/media/media-wrapper.jsx → components/media/MediaWrapper.jsx} +0 -0
  164. /package/src/{plugins/respArea/drag-in-the-blank/index.jsx → components/respArea/DragInTheBlank/DragInTheBlank.jsx} +0 -0
  165. /package/src/{plugins/respArea/explicit-constructed-response/index.jsx → components/respArea/ExplicitConstructedResponse.jsx} +0 -0
@@ -1,427 +0,0 @@
1
- import React from 'react';
2
- import { Block } from 'slate';
3
- import debug from 'debug';
4
- import GridOn from '@material-ui/icons/GridOn';
5
- import TableToolbar from './table-toolbar';
6
- import PropTypes from 'prop-types';
7
- import SlatePropTypes from 'slate-prop-types';
8
- import { withStyles } from '@material-ui/core/styles';
9
- import convert from 'react-attr-converter';
10
- import { object as toStyleObject } from 'to-style';
11
- import CustomTablePlugin from './CustomTablePlugin';
12
-
13
- const log = debug('@pie-lib:editable-html:plugins:table');
14
-
15
- const Table = withStyles(() => ({
16
- table: {},
17
- }))((props) => {
18
- const nodeAttributes = dataToAttributes(props.node.data);
19
-
20
- return (
21
- <table
22
- className={props.classes.table}
23
- {...props.attributes}
24
- {...nodeAttributes}
25
- onFocus={props.onFocus}
26
- onBlur={props.onBlur}
27
- >
28
- <tbody>{props.children}</tbody>
29
- </table>
30
- );
31
- });
32
-
33
- Table.propTypes = {
34
- attributes: PropTypes.object,
35
- onFocus: PropTypes.func,
36
- onBlur: PropTypes.func,
37
- node: SlatePropTypes.node,
38
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
39
- };
40
-
41
- const TableRow = (props) => <tr {...props.attributes}>{props.children}</tr>;
42
-
43
- TableRow.propTypes = {
44
- attributes: PropTypes.object,
45
- onFocus: PropTypes.func,
46
- onBlur: PropTypes.func,
47
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
48
- };
49
-
50
- const TableCell = withStyles(() => ({
51
- td: {
52
- minWidth: '25px',
53
- },
54
- }))((props) => {
55
- const Tag = props.node.data.get('header') ? 'th' : 'td';
56
-
57
- const nodeAttributes = dataToAttributes(props.node.data);
58
- delete nodeAttributes.header;
59
-
60
- return (
61
- <Tag
62
- {...props.attributes}
63
- {...nodeAttributes}
64
- colSpan={props.node.data.get('colspan')}
65
- className={props.classes[Tag]}
66
- onFocus={props.onFocus}
67
- onBlur={props.onBlur}
68
- >
69
- {props.children}
70
- </Tag>
71
- );
72
- });
73
-
74
- TableCell.propTypes = {
75
- attributes: PropTypes.object,
76
- onFocus: PropTypes.func,
77
- onBlur: PropTypes.func,
78
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
79
- };
80
-
81
- export const moveFocusToBeginningOfTable = (change) => {
82
- const addedTable = change.value.document.findDescendant((d) => !!d.data && !!d.data.get('newTable'));
83
-
84
- if (!addedTable) {
85
- return;
86
- }
87
-
88
- change.collapseToStartOf(addedTable);
89
-
90
- const update = addedTable.data.remove('newTable');
91
-
92
- change.setNodeByKey(addedTable.key, { data: update });
93
- };
94
-
95
- export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
96
- const core = CustomTablePlugin(opts);
97
-
98
- // fix outdated schema
99
-
100
- if (core.schema && core.schema.blocks) {
101
- Object.keys(core.schema.blocks).forEach((key) => {
102
- const block = core.schema.blocks[key];
103
-
104
- if (block.parent) {
105
- if (block.nodes[0].types) {
106
- block.nodes[0] = {
107
- type: block.nodes[0].types[0],
108
- };
109
- }
110
-
111
- if (block.nodes[0].objects) {
112
- block.nodes[0] = {
113
- object: block.nodes[0].objects[0],
114
- };
115
- }
116
-
117
- block.parent = {
118
- type: block.parent.types[0],
119
- };
120
- } else {
121
- block.nodes[0] = { type: block.nodes[0].types[0] };
122
- }
123
- });
124
- }
125
-
126
- core.utils.getTableBlock = (containerNode, key) => {
127
- const node = containerNode.getDescendant(key);
128
- const ancestors = containerNode.getAncestors(key).push(node);
129
- return ancestors.findLast((p) => p.type === 'table');
130
- };
131
-
132
- core.utils.createTableWithOptions = (row, columns, extra) => {
133
- const createdTable = core.utils.createTable(row, columns);
134
- const newTable = Block.create({
135
- ...createdTable.toJSON(),
136
- ...extra,
137
- });
138
-
139
- return newTable;
140
- };
141
-
142
- core.toolbar = {
143
- type: 'table',
144
- icon: <GridOn />,
145
- ariaLabel: 'Insert Table',
146
- onClick: (value, onChange) => {
147
- log('insert table');
148
- const change = value.change();
149
- const newTable = core.utils.createTableWithOptions(2, 2, {
150
- data: {
151
- border: '1',
152
- newTable: true,
153
- },
154
- });
155
-
156
- change.insertBlock(newTable);
157
-
158
- moveFocusToBeginningOfTable(change);
159
- onChange(change);
160
- },
161
- supports: (node, value) => node && node.object === 'block' && core.utils.isSelectionInTable(value),
162
- /**
163
- * Note - the node may not be a table node - it may be a node inside a table.
164
- */
165
- customToolbar: (node, value, onToolbarDone, getFocusedValue) => {
166
- log('[customToolbar] node.data: ', node.data);
167
-
168
- const tableBlock = core.utils.getTableBlock(value.document, node?.key);
169
- log('[customToolbar] tableBlock: ', tableBlock);
170
-
171
- const hasBorder = () => tableBlock.data.get('border') && tableBlock.data.get('border') !== '0';
172
- const addRow = () => {
173
- const change = core.changes.insertRow(value.change());
174
- onToolbarDone(change, false);
175
- };
176
-
177
- const addColumn = () => {
178
- const change = core.changes.insertColumn(value.change());
179
- onToolbarDone(change, false);
180
- };
181
-
182
- const removeRow = () => {
183
- const change = core.changes.removeRow(value.change());
184
- onToolbarDone(change, false);
185
- };
186
-
187
- const removeColumn = () => {
188
- const change = core.changes.removeColumn(value.change());
189
- onToolbarDone(change, false);
190
- };
191
-
192
- const removeTable = () => {
193
- const change = core.changes.removeTable(value.change());
194
- onToolbarDone(change, false);
195
- };
196
-
197
- const toggleBorder = () => {
198
- const { data } = tableBlock;
199
- const update = data.set('border', hasBorder() ? '0' : '1');
200
- log('[toggleBorder] update: ', update);
201
- const change = value.change().setNodeByKey(tableBlock.key, { data: update });
202
- onToolbarDone(change, false);
203
- };
204
-
205
- const onDone = () => {
206
- log('[onDone] call onToolbarDone...');
207
- onToolbarDone(null, true);
208
- };
209
-
210
- const Tb = () => (
211
- <TableToolbar
212
- getFocusedValue={getFocusedValue}
213
- plugins={toolbarPlugins}
214
- onChange={(c) => onToolbarDone(c, false)}
215
- value={value}
216
- onAddRow={addRow}
217
- onRemoveRow={removeRow}
218
- onAddColumn={addColumn}
219
- onRemoveColumn={removeColumn}
220
- onRemoveTable={removeTable}
221
- hasBorder={hasBorder()}
222
- onToggleBorder={toggleBorder}
223
- onDone={onDone}
224
- />
225
- );
226
-
227
- return Tb;
228
- },
229
- };
230
-
231
- const Node = (props) => {
232
- switch (props.node.type) {
233
- case 'table':
234
- return <Table {...props} onFocus={opts.onFocus} onBlur={opts.onBlur} />;
235
- case 'table_row':
236
- return <TableRow {...props} />;
237
- case 'table_cell':
238
- return <TableCell {...props} onFocus={opts.onFocus} onBlur={opts.onBlur} />;
239
- default:
240
- return null;
241
- }
242
- };
243
- Node.propTypes = {
244
- node: PropTypes.object,
245
- };
246
-
247
- core.normalizeNode = (node) => {
248
- const addNodeBeforeArray = [];
249
-
250
- if (node.object !== 'document') return;
251
-
252
- node.findDescendant((d) => {
253
- if (d.type === 'table') {
254
- const tablePath = node.getPath(d.key);
255
- const prevNode = node.getPreviousNode(tablePath);
256
- const nextNode = node.getNextNode(tablePath);
257
-
258
- if (!prevNode || !nextNode) {
259
- addNodeBeforeArray.push({
260
- node: d,
261
- prevNode,
262
- nextNode,
263
- });
264
- }
265
- }
266
- });
267
-
268
- if (!addNodeBeforeArray.length) {
269
- return;
270
- }
271
-
272
- return (change) => {
273
- const newBlock = {
274
- object: 'block',
275
- type: 'div',
276
- };
277
-
278
- addNodeBeforeArray.forEach((n) => {
279
- const tablePath = change.value.document.getPath(n.node.key).toJSON();
280
- // removing tableIndex
281
- let indexToAdd = tablePath.splice(-1)[0];
282
-
283
- if (!n.prevNode) {
284
- // inserting block key before table
285
- change.insertNodeByPath(tablePath, indexToAdd, newBlock);
286
- // this will trigger another normalization, which will figure out if there's not
287
- // a block after the table and add it, so we exit for now
288
- return;
289
- }
290
-
291
- if (!n.nextNode) {
292
- // inserting block key after table
293
- change.insertNodeByPath(tablePath, indexToAdd + 1, newBlock);
294
- }
295
- });
296
- };
297
- };
298
-
299
- core.renderNode = Node;
300
- core.name = 'table';
301
-
302
- return core;
303
- };
304
-
305
- export const parseStyleString = (s) => {
306
- const regex = /([\w-]*)\s*:\s*([^;]*)/g;
307
- let match;
308
- const result = {};
309
- while ((match = regex.exec(s))) {
310
- result[match[1]] = match[2].trim();
311
- }
312
- return result;
313
- };
314
-
315
- export const reactAttributes = (o) => toStyleObject(o, { camelize: true, addUnits: false });
316
-
317
- const attributesToMap = (el) => (acc, attribute) => {
318
- const value = el.getAttribute(attribute);
319
- if (value) {
320
- if (attribute === 'style') {
321
- const styleString = el.getAttribute(attribute);
322
- const reactStyleObject = reactAttributes(parseStyleString(styleString));
323
- acc['style'] = reactStyleObject;
324
- } else {
325
- acc[attribute] = el.getAttribute(attribute);
326
- }
327
- }
328
- return acc;
329
- };
330
-
331
- const dataToAttributes = (data) => {
332
- if (!data || !data.get) {
333
- return {};
334
- }
335
-
336
- return data.reduce((acc, v, name) => {
337
- if (v) {
338
- acc[convert(name)] = v;
339
- }
340
- return acc;
341
- }, {});
342
- };
343
-
344
- const attributes = ['border', 'cellpadding', 'cellspacing', 'class', 'style'];
345
-
346
- const cellAttributes = ['colspan', 'rowspan', 'class', 'style'];
347
-
348
- export const serialization = {
349
- deserialize(el, next) {
350
- const tag = el.tagName.toLowerCase();
351
-
352
- switch (tag) {
353
- case 'table': {
354
- const children =
355
- el.children.length === 1 && el.children[0].tagName.toLowerCase() === 'tbody'
356
- ? el.children[0].children
357
- : el.children;
358
- const c = Array.from(children);
359
-
360
- return {
361
- object: 'block',
362
- type: 'table',
363
- nodes: next(c),
364
- data: attributes.reduce(attributesToMap(el), {}),
365
- };
366
- }
367
-
368
- case 'th': {
369
- return {
370
- object: 'block',
371
- type: 'table_cell',
372
- nodes: next(el.childNodes),
373
- data: cellAttributes.reduce(attributesToMap(el), { header: true }),
374
- };
375
- }
376
-
377
- case 'tr': {
378
- return {
379
- object: 'block',
380
- type: 'table_row',
381
- nodes: next(Array.from(el.children)),
382
- };
383
- }
384
-
385
- case 'td': {
386
- return {
387
- object: 'block',
388
- type: 'table_cell',
389
- nodes: next(Array.from(el.childNodes)),
390
- data: cellAttributes.reduce(attributesToMap(el), { header: false }),
391
- };
392
- }
393
- }
394
- },
395
- serialize(object, children) {
396
- if (object.object !== 'block') {
397
- return;
398
- }
399
-
400
- switch (object.type) {
401
- case 'table': {
402
- const attributes = dataToAttributes(object.data);
403
-
404
- return (
405
- <table {...attributes}>
406
- <tbody>{children}</tbody>
407
- </table>
408
- );
409
- }
410
-
411
- case 'table_row': {
412
- return <tr>{children}</tr>;
413
- }
414
-
415
- case 'table_cell': {
416
- const attributes = dataToAttributes(object.data);
417
- delete attributes.header;
418
-
419
- if (object.data.get('header')) {
420
- return <th {...attributes}>{children}</th>;
421
- } else {
422
- return <td {...attributes}>{children}</td>;
423
- }
424
- }
425
- }
426
- },
427
- };
@@ -1,136 +0,0 @@
1
- import React from 'react';
2
- import { withStyles } from '@material-ui/core/styles';
3
- import { Button } from '../toolbar/toolbar-buttons';
4
- import { DoneButton } from '../toolbar/done-button';
5
- import BorderAll from '@material-ui/icons/BorderAll';
6
- import { ToolbarButton } from '../toolbar/default-toolbar';
7
-
8
- import { AddRow, AddColumn, RemoveColumn, RemoveRow, RemoveTable } from './icons';
9
- import PropTypes from 'prop-types';
10
- import debug from 'debug';
11
-
12
- const log = debug('@pie-lib:editable-html:plugins:table-toolbar');
13
-
14
- export class TableToolbar extends React.Component {
15
- static propTypes = {
16
- plugins: PropTypes.array.isRequired,
17
- value: PropTypes.object.isRequired,
18
- onChange: PropTypes.func.isRequired,
19
- onAddRow: PropTypes.func.isRequired,
20
- onRemoveRow: PropTypes.func.isRequired,
21
- onAddColumn: PropTypes.func.isRequired,
22
- onRemoveColumn: PropTypes.func.isRequired,
23
- onRemoveTable: PropTypes.func.isRequired,
24
- onToggleBorder: PropTypes.func.isRequired,
25
- hasBorder: PropTypes.bool,
26
- onDone: PropTypes.func.isRequired,
27
- classes: PropTypes.object.isRequired,
28
- };
29
-
30
- static defaultProps = {
31
- plugins: [],
32
- value: {},
33
- onChange: () => {},
34
- };
35
-
36
- onDone = (e) => {
37
- const { onDone } = this.props;
38
- e.preventDefault();
39
- onDone();
40
- };
41
-
42
- render() {
43
- const {
44
- getFocusedValue,
45
- plugins,
46
- value,
47
- onChange,
48
- onAddRow,
49
- onRemoveRow,
50
- onAddColumn,
51
- onRemoveColumn,
52
- onRemoveTable,
53
- onToggleBorder,
54
- hasBorder,
55
- classes,
56
- } = this.props;
57
- log('[render] hasBorder:', hasBorder);
58
-
59
- // we're separating the response area plugin because we want to display it next to the done button
60
- const filteredPlugins = (plugins || []).reduce(
61
- (acc, plugin) => {
62
- if (plugin.name === 'response_area') {
63
- return {
64
- ...acc,
65
- respAreaPlugin: plugin,
66
- };
67
- }
68
-
69
- return {
70
- ...acc,
71
- otherPlugins: [...acc.otherPlugins, plugin],
72
- };
73
- },
74
- {
75
- respAreaPlugin: null,
76
- otherPlugins: [],
77
- },
78
- );
79
-
80
- return (
81
- <div className={classes.tableToolbar}>
82
- <div className={classes.toolbarButtons}>
83
- <Button onClick={onAddRow}>
84
- <AddRow />
85
- </Button>
86
- <Button onClick={onRemoveRow}>
87
- <RemoveRow />
88
- </Button>
89
- <Button onClick={onAddColumn}>
90
- <AddColumn />
91
- </Button>
92
- <Button onClick={onRemoveColumn}>
93
- <RemoveColumn />
94
- </Button>
95
- <Button onClick={onRemoveTable}>
96
- <RemoveTable />
97
- </Button>
98
- {(filteredPlugins.otherPlugins || []).map((p, index) => (
99
- <ToolbarButton
100
- key={`plugin-${index}`}
101
- {...p.toolbar}
102
- value={value}
103
- onChange={onChange}
104
- getFocusedValue={getFocusedValue}
105
- />
106
- ))}
107
- <Button onClick={onToggleBorder} active={hasBorder}>
108
- <BorderAll />
109
- </Button>
110
- </div>
111
- {filteredPlugins.respAreaPlugin && (
112
- <ToolbarButton
113
- key={'plugin-response-area'}
114
- {...filteredPlugins.respAreaPlugin.toolbar}
115
- value={value}
116
- onChange={onChange}
117
- getFocusedValue={getFocusedValue}
118
- />
119
- )}
120
- <DoneButton onClick={this.onDone} />
121
- </div>
122
- );
123
- }
124
- }
125
-
126
- const styles = () => ({
127
- tableToolbar: {
128
- width: '100%',
129
- display: 'flex',
130
- justifyContent: 'space-between',
131
- },
132
- toolbarButtons: {
133
- display: 'flex',
134
- },
135
- });
136
- export default withStyles(styles)(TableToolbar);
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import debug from 'debug';
3
- import TextAlignIcon from './icons';
4
-
5
- const log = debug('@pie-lib:editable-html:plugins:characters');
6
-
7
- /**
8
- * Plugin in order to be able to change alignment for the selected text(s) element(s).
9
- * @param opts
10
- * @constructor
11
- */
12
- export default function TextAlign(opts) {
13
- const plugin = {
14
- name: 'textAlign',
15
- toolbar: {
16
- icon: <TextAlignIcon {...opts} />,
17
- ariaLabel: 'Text Align',
18
- onClick: () => {},
19
- },
20
- };
21
-
22
- return plugin;
23
- }