@pie-lib/editable-html-tip-tap 1.0.1 → 1.0.3

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 (129) hide show
  1. package/lib/components/CharacterPicker.js +221 -0
  2. package/lib/components/EditableHtml.js +323 -0
  3. package/lib/components/MenuBar.js +693 -0
  4. package/lib/components/TiptapContainer.js +90 -0
  5. package/lib/components/buttons/done-button.js +53 -0
  6. package/lib/components/characters/characterUtils.js +112 -0
  7. package/lib/components/characters/custom-popper.js +73 -0
  8. package/lib/components/common/done-button.js +53 -0
  9. package/lib/components/icons/CssIcon.js +37 -0
  10. package/lib/components/icons/RespArea.js +95 -0
  11. package/lib/components/icons/TableIcons.js +69 -0
  12. package/lib/components/icons/TextAlign.js +194 -0
  13. package/lib/components/icons/index.js +194 -0
  14. package/lib/components/image/ImageToolbar.js +16 -0
  15. package/lib/components/image/InsertImageHandler.js +16 -0
  16. package/lib/components/media/MediaDialog.js +16 -0
  17. package/lib/components/media/MediaToolbar.js +16 -0
  18. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +94 -0
  19. package/lib/components/respArea/DragInTheBlank/choice.js +289 -0
  20. package/lib/components/respArea/DragInTheBlank.js +94 -0
  21. package/lib/components/respArea/ExplicitConstructedResponse.js +120 -0
  22. package/lib/components/respArea/InlineDropdown.js +126 -0
  23. package/lib/components/respArea/ToolbarIcon.js +105 -0
  24. package/lib/components/respArea/choice.js +2 -0
  25. package/lib/extensions/component.js +5 -5
  26. package/lib/extensions/custom-toolbar-wrapper.js +2 -4
  27. package/lib/extensions/extended-table.js +30 -0
  28. package/lib/extensions/index.js +52 -0
  29. package/lib/extensions/media.js +5 -5
  30. package/lib/extensions/responseArea.js +7 -7
  31. package/lib/index.js +16 -1454
  32. package/lib/plugins/index.js +10 -82
  33. package/lib/styles/editorContainerStyles.js +200 -0
  34. package/lib/utils/size.js +34 -0
  35. package/package.json +1 -1
  36. package/src/components/CharacterPicker.jsx +185 -0
  37. package/src/components/EditableHtml.jsx +306 -0
  38. package/src/components/MenuBar.jsx +630 -0
  39. package/src/components/TiptapContainer.jsx +96 -0
  40. package/src/components/characters/characterUtils.js +127 -0
  41. package/src/components/image/ImageToolbar.jsx +1 -0
  42. package/src/components/image/InsertImageHandler.js +1 -0
  43. package/src/components/media/MediaDialog.js +1 -0
  44. package/src/components/media/MediaToolbar.jsx +1 -0
  45. package/src/{plugins/respArea/drag-in-the-blank → components/respArea/DragInTheBlank}/choice.jsx +1 -1
  46. package/src/{plugins/respArea/inline-dropdown/index.jsx → components/respArea/InlineDropdown.jsx} +1 -1
  47. package/src/components/respArea/ToolbarIcon.jsx +68 -0
  48. package/src/extensions/component.jsx +2 -2
  49. package/src/extensions/custom-toolbar-wrapper.jsx +6 -7
  50. package/src/extensions/extended-table.js +27 -0
  51. package/src/extensions/index.js +76 -0
  52. package/src/extensions/media.js +10 -4
  53. package/src/extensions/responseArea.js +7 -7
  54. package/src/index.jsx +3 -1409
  55. package/src/styles/editorContainerStyles.js +203 -0
  56. package/src/utils/size.js +32 -0
  57. package/src/__tests__/editor.test.jsx +0 -363
  58. package/src/__tests__/serialization.test.js +0 -291
  59. package/src/block-tags.js +0 -17
  60. package/src/editor.jsx +0 -1197
  61. package/src/extensions/characters.js +0 -46
  62. package/src/old-index.jsx +0 -162
  63. package/src/parse-html.js +0 -8
  64. package/src/plugins/README.md +0 -27
  65. package/src/plugins/characters/index.jsx +0 -284
  66. package/src/plugins/characters/utils.js +0 -447
  67. package/src/plugins/css/index.jsx +0 -340
  68. package/src/plugins/customPlugin/index.jsx +0 -85
  69. package/src/plugins/html/icons/index.jsx +0 -19
  70. package/src/plugins/html/index.jsx +0 -72
  71. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +0 -51
  72. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +0 -27
  73. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +0 -44
  74. package/src/plugins/image/__tests__/component.test.jsx +0 -41
  75. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +0 -42
  76. package/src/plugins/image/__tests__/image-toolbar.test.jsx +0 -11
  77. package/src/plugins/image/__tests__/index.test.js +0 -95
  78. package/src/plugins/image/__tests__/insert-image-handler.test.js +0 -113
  79. package/src/plugins/image/__tests__/mock-change.js +0 -15
  80. package/src/plugins/image/alt-dialog.jsx +0 -82
  81. package/src/plugins/image/component.jsx +0 -343
  82. package/src/plugins/image/image-toolbar.jsx +0 -100
  83. package/src/plugins/image/index.jsx +0 -227
  84. package/src/plugins/image/insert-image-handler.js +0 -79
  85. package/src/plugins/index.jsx +0 -377
  86. package/src/plugins/list/__tests__/index.test.js +0 -54
  87. package/src/plugins/list/index.jsx +0 -305
  88. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +0 -48
  89. package/src/plugins/math/__tests__/index.test.jsx +0 -245
  90. package/src/plugins/math/index.jsx +0 -379
  91. package/src/plugins/media/__tests__/index.test.js +0 -75
  92. package/src/plugins/media/index.jsx +0 -325
  93. package/src/plugins/media/media-dialog.js +0 -624
  94. package/src/plugins/media/media-toolbar.jsx +0 -56
  95. package/src/plugins/media/media-wrapper.jsx +0 -43
  96. package/src/plugins/rendering/index.js +0 -31
  97. package/src/plugins/respArea/index.jsx +0 -299
  98. package/src/plugins/respArea/math-templated/index.jsx +0 -104
  99. package/src/plugins/respArea/utils.jsx +0 -90
  100. package/src/plugins/table/CustomTablePlugin.js +0 -113
  101. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +0 -44
  102. package/src/plugins/table/__tests__/index.test.jsx +0 -401
  103. package/src/plugins/table/__tests__/table-toolbar.test.jsx +0 -42
  104. package/src/plugins/table/index.jsx +0 -427
  105. package/src/plugins/table/table-toolbar.jsx +0 -136
  106. package/src/plugins/textAlign/index.jsx +0 -23
  107. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +0 -923
  108. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +0 -20
  109. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +0 -36
  110. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +0 -46
  111. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +0 -94
  112. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +0 -37
  113. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +0 -51
  114. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +0 -106
  115. package/src/plugins/toolbar/default-toolbar.jsx +0 -206
  116. package/src/plugins/toolbar/editor-and-toolbar.jsx +0 -257
  117. package/src/plugins/toolbar/index.jsx +0 -23
  118. package/src/plugins/toolbar/toolbar-buttons.jsx +0 -138
  119. package/src/plugins/toolbar/toolbar.jsx +0 -338
  120. package/src/plugins/utils.js +0 -31
  121. package/src/serialization.jsx +0 -621
  122. /package/src/{plugins → components}/characters/custom-popper.js +0 -0
  123. /package/src/{plugins/toolbar → components/common}/done-button.jsx +0 -0
  124. /package/src/{plugins/css/icons/index.jsx → components/icons/CssIcon.jsx} +0 -0
  125. /package/src/{plugins/respArea/icons/index.jsx → components/icons/RespArea.jsx} +0 -0
  126. /package/src/{plugins/table/icons/index.jsx → components/icons/TableIcons.jsx} +0 -0
  127. /package/src/{plugins/textAlign/icons/index.jsx → components/icons/TextAlign.jsx} +0 -0
  128. /package/src/{plugins/respArea/drag-in-the-blank/index.jsx → components/respArea/DragInTheBlank/DragInTheBlank.jsx} +0 -0
  129. /package/src/{plugins/respArea/explicit-constructed-response/index.jsx → components/respArea/ExplicitConstructedResponse.jsx} +0 -0
@@ -1,325 +0,0 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom';
3
- import { Inline } from 'slate';
4
- import TheatersIcon from '@material-ui/icons/Theaters';
5
- import VolumeUpIcon from '@material-ui/icons/VolumeUp';
6
- import debug from 'debug';
7
-
8
- import MediaDialog from './media-dialog';
9
- import MediaToolbar from './media-toolbar';
10
- import MediaWrapper from './media-wrapper';
11
-
12
- const log = debug('@pie-lib:editable-html:plugins:image');
13
-
14
- const removeDialogs = () => {
15
- const prevDialogs = document.querySelectorAll('.insert-media-dialog');
16
-
17
- prevDialogs.forEach((s) => s.remove());
18
- };
19
-
20
- export const insertDialog = (props) => {
21
- const newEl = document.createElement('div');
22
- const { type, callback, opts, ...rest } = props;
23
- const initialBodyOverflow = document.body.style.overflow;
24
-
25
- removeDialogs();
26
-
27
- newEl.className = 'insert-media-dialog';
28
- document.body.style.overflow = 'hidden';
29
-
30
- const handleClose = (val, data) => {
31
- callback(val, data);
32
- newEl.remove();
33
- document.body.style.overflow = initialBodyOverflow;
34
- };
35
-
36
- const el = (
37
- <MediaDialog
38
- {...rest}
39
- uploadSoundSupport={opts.uploadSoundSupport}
40
- type={type}
41
- disablePortal={true}
42
- open={true}
43
- handleClose={handleClose}
44
- />
45
- );
46
-
47
- ReactDOM.render(el, newEl);
48
-
49
- document.body.appendChild(newEl);
50
- };
51
-
52
- const types = ['audio', 'video'];
53
-
54
- export default function MediaPlugin(type, opts) {
55
- const toolbar = {
56
- icon: type === 'audio' ? <VolumeUpIcon /> : <TheatersIcon />,
57
- ariaLabel: type === 'audio' ? 'Insert audio' : 'Insert video',
58
- onClick: (value, onChange) => {
59
- log('[toolbar] onClick');
60
- const inline = Inline.create({
61
- type: type,
62
- isVoid: true,
63
- data: {
64
- editing: false,
65
- ends: undefined,
66
- height: undefined,
67
- title: undefined,
68
- starts: undefined,
69
- src: undefined,
70
- url: undefined,
71
- width: undefined,
72
- },
73
- });
74
-
75
- const change = value.change().insertInline(inline);
76
- onChange(change);
77
- insertDialog({
78
- type,
79
- opts,
80
- callback: (val, data) => {
81
- const nodeIsThere = change.value.document.findDescendant((d) => d.key === inline.key);
82
-
83
- if (nodeIsThere) {
84
- if (!val) {
85
- const c = change.removeNodeByKey(inline.key);
86
- onChange(c, () => opts.focus());
87
- } else {
88
- const c = change.setNodeByKey(inline.key, { data });
89
- onChange(c, () => opts.focus('beginning', nodeIsThere));
90
- }
91
- } else {
92
- opts.focus();
93
- }
94
- },
95
- });
96
- },
97
- supports: (node) => node.object === 'inline' && node.type === type,
98
- };
99
-
100
- return {
101
- name: type,
102
- toolbar,
103
- deleteNode: (e, node, value, onChange) => {
104
- e.preventDefault();
105
- const change = value.change().removeNodeByKey(node.key);
106
-
107
- onChange(change);
108
- },
109
- renderNode(props) {
110
- if (props.node.type === type) {
111
- const { node, key } = props;
112
- const { data } = node;
113
- const jsonData = data.toJSON();
114
- const { src, height, width, editing, tag, ...rest } = jsonData;
115
- const handleEdit = () => {
116
- const change = opts.createChange();
117
- const c = change.setNodeByKey(key, {
118
- data: {
119
- ...jsonData,
120
- editing: true,
121
- },
122
- });
123
-
124
- opts.onChange(c, () => {
125
- insertDialog({
126
- ...jsonData,
127
- edit: true,
128
- type,
129
- opts,
130
- callback: (val, data) => {
131
- const { key } = node;
132
-
133
- const nodeIsThere = change.value.document.findDescendant(
134
- (d) => d.type === type && d.data.get('editing'),
135
- );
136
-
137
- if (nodeIsThere && val) {
138
- const c = change.setNodeByKey(key, { data, editing: false });
139
- opts.onChange(c, () => opts.focus('beginning', nodeIsThere));
140
- } else {
141
- opts.focus();
142
- }
143
- },
144
- });
145
- });
146
- };
147
- const handleDelete = () => {
148
- const change = opts.createChange();
149
- const c = change.removeNodeByKey(node.key);
150
-
151
- opts.onChange(c);
152
- };
153
- const style = {};
154
-
155
- if (width) {
156
- style.width = `${width}px`;
157
- }
158
-
159
- if (height) {
160
- style.height = `${height}px`;
161
- }
162
-
163
- if (tag === 'audio') {
164
- return (
165
- <MediaWrapper editor data-type={type} width={style.width} {...rest}>
166
- <audio controls="controls" controlsList="nodownload">
167
- <source type="audio/mp3" src={src} />
168
- </audio>
169
- <MediaToolbar hideEdit onRemove={handleDelete} />
170
- </MediaWrapper>
171
- );
172
- }
173
-
174
- return (
175
- <MediaWrapper editor data-type={type} width={style.width} {...rest}>
176
- <iframe
177
- frameBorder="0"
178
- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
179
- allowFullScreen
180
- src={src}
181
- editing={editing ? 1 : 0}
182
- {...rest}
183
- {...style}
184
- />
185
- <MediaToolbar onEdit={handleEdit} onRemove={handleDelete} />
186
- </MediaWrapper>
187
- );
188
- }
189
- },
190
- normalizeNode: (node) => {
191
- const textNodeMap = {};
192
- const updateNodesArray = [];
193
- let index = 0;
194
-
195
- if (node.object !== 'document') return;
196
-
197
- node.findDescendant((d) => {
198
- if (d.object === 'text') {
199
- textNodeMap[index] = d;
200
- }
201
-
202
- const isMedia = types.indexOf(d.type) >= 0;
203
-
204
- if (isMedia) {
205
- if (index > 0 && textNodeMap[index - 1] && textNodeMap[index - 1].text === '') {
206
- updateNodesArray.push(textNodeMap[index - 1]);
207
- }
208
- }
209
-
210
- index++;
211
- });
212
-
213
- if (!updateNodesArray.length) return;
214
-
215
- return (change) => {
216
- change.withoutNormalization(() => {
217
- updateNodesArray.forEach((n) => change.insertTextByKey(n.key, 0, ' '));
218
- });
219
- };
220
- },
221
- };
222
- }
223
-
224
- export const serialization = {
225
- deserialize(el /*, next*/) {
226
- let type = el.dataset && el.dataset.type;
227
- let tag = 'iframe';
228
- let src;
229
- const typeIndex = types.indexOf(type);
230
-
231
- if (typeIndex < 0) {
232
- if (el instanceof Element && el.tagName.toLowerCase() === 'audio') {
233
- type = 'audio';
234
- tag = 'audio';
235
- src = el.firstChild?.getAttribute('src');
236
- } else {
237
- return;
238
- }
239
- }
240
-
241
- const { ends, starts, title, editing, url } = el.dataset || {};
242
-
243
- log('deserialize: ', name);
244
- const width = parseInt(el.getAttribute('width'), 10) || null;
245
- const height = parseInt(el.getAttribute('height'), 10) || null;
246
-
247
- const out = {
248
- object: 'inline',
249
- type: type,
250
- isVoid: true,
251
- data: {
252
- tag,
253
- src: src || el.getAttribute('src'),
254
- editing,
255
- ends,
256
- height,
257
- starts,
258
- title,
259
- width,
260
- url,
261
- },
262
- };
263
- log('return object: ', out);
264
- return out;
265
- },
266
- serialize(object /*, children*/) {
267
- const typeIndex = types.indexOf(object.type);
268
-
269
- if (typeIndex < 0) return;
270
-
271
- const type = types[typeIndex];
272
-
273
- const { data } = object;
274
- const editing = data.get('editing');
275
- const tag = data.get('tag');
276
- const ends = data.get('ends');
277
- const src = data.get('src');
278
- const starts = data.get('starts');
279
- const title = data.get('title');
280
- const width = data.get('width');
281
- const height = data.get('height');
282
- const url = data.get('url');
283
- const style = {};
284
-
285
- if (width) {
286
- style.width = `${width}px`;
287
- }
288
-
289
- if (height) {
290
- style.height = `${height}px`;
291
- }
292
-
293
- const divProps = {
294
- 'data-editing': editing,
295
- 'data-ends': ends,
296
- 'data-starts': starts,
297
- 'data-title': title,
298
- 'data-url': url,
299
- };
300
- const props = {
301
- ...style,
302
- src,
303
- };
304
-
305
- if (tag === 'audio') {
306
- return (
307
- <audio controls="controls" controlsList="nodownload">
308
- <source type="audio/mp3" src={src} />
309
- </audio>
310
- );
311
- }
312
-
313
- return (
314
- <iframe
315
- data-type={type}
316
- src={src}
317
- {...divProps}
318
- frameBorder="0"
319
- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
320
- allowFullScreen
321
- {...props}
322
- />
323
- );
324
- },
325
- };