@pie-lib/editable-html-tip-tap 0.1.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 (158) hide show
  1. package/dist/components/CharacterPicker.d.ts +31 -0
  2. package/dist/components/CharacterPicker.d.ts.map +1 -0
  3. package/dist/components/CharacterPicker.js +129 -0
  4. package/dist/components/EditableHtml.d.ts +11 -0
  5. package/dist/components/EditableHtml.d.ts.map +1 -0
  6. package/dist/components/EditableHtml.js +270 -0
  7. package/dist/components/MenuBar.d.ts +11 -0
  8. package/dist/components/MenuBar.d.ts.map +1 -0
  9. package/dist/components/MenuBar.js +460 -0
  10. package/dist/components/TiptapContainer.d.ts +11 -0
  11. package/dist/components/TiptapContainer.d.ts.map +1 -0
  12. package/dist/components/TiptapContainer.js +157 -0
  13. package/dist/components/characters/characterUtils.d.ts +36 -0
  14. package/dist/components/characters/characterUtils.d.ts.map +1 -0
  15. package/dist/components/characters/characterUtils.js +465 -0
  16. package/dist/components/characters/custom-popper.d.ts +14 -0
  17. package/dist/components/characters/custom-popper.d.ts.map +1 -0
  18. package/dist/components/characters/custom-popper.js +32 -0
  19. package/dist/components/common/done-button.d.ts +30 -0
  20. package/dist/components/common/done-button.d.ts.map +1 -0
  21. package/dist/components/common/done-button.js +26 -0
  22. package/dist/components/common/toolbar-buttons.d.ts +39 -0
  23. package/dist/components/common/toolbar-buttons.d.ts.map +1 -0
  24. package/dist/components/common/toolbar-buttons.js +91 -0
  25. package/dist/components/icons/CssIcon.d.ts +11 -0
  26. package/dist/components/icons/CssIcon.d.ts.map +1 -0
  27. package/dist/components/icons/CssIcon.js +14 -0
  28. package/dist/components/icons/RespArea.d.ts +26 -0
  29. package/dist/components/icons/RespArea.d.ts.map +1 -0
  30. package/dist/components/icons/RespArea.js +42 -0
  31. package/dist/components/icons/TableIcons.d.ts +14 -0
  32. package/dist/components/icons/TableIcons.d.ts.map +1 -0
  33. package/dist/components/icons/TableIcons.js +32 -0
  34. package/dist/components/icons/TextAlign.d.ts +18 -0
  35. package/dist/components/icons/TextAlign.d.ts.map +1 -0
  36. package/dist/components/icons/TextAlign.js +134 -0
  37. package/dist/components/image/AltDialog.d.ts +23 -0
  38. package/dist/components/image/AltDialog.d.ts.map +1 -0
  39. package/dist/components/image/AltDialog.js +61 -0
  40. package/dist/components/image/ImageToolbar.d.ts +25 -0
  41. package/dist/components/image/ImageToolbar.d.ts.map +1 -0
  42. package/dist/components/image/ImageToolbar.js +80 -0
  43. package/dist/components/image/InsertImageHandler.d.ts +33 -0
  44. package/dist/components/image/InsertImageHandler.d.ts.map +1 -0
  45. package/dist/components/image/InsertImageHandler.js +55 -0
  46. package/dist/components/media/MediaDialog.d.ts +44 -0
  47. package/dist/components/media/MediaDialog.d.ts.map +1 -0
  48. package/dist/components/media/MediaDialog.js +389 -0
  49. package/dist/components/media/MediaToolbar.d.ts +20 -0
  50. package/dist/components/media/MediaToolbar.d.ts.map +1 -0
  51. package/dist/components/media/MediaToolbar.js +41 -0
  52. package/dist/components/media/MediaWrapper.d.ts +20 -0
  53. package/dist/components/media/MediaWrapper.d.ts.map +1 -0
  54. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
  55. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts.map +1 -0
  56. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
  57. package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
  58. package/dist/components/respArea/DragInTheBlank/choice.d.ts.map +1 -0
  59. package/dist/components/respArea/DragInTheBlank/choice.js +156 -0
  60. package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
  61. package/dist/components/respArea/ExplicitConstructedResponse.d.ts.map +1 -0
  62. package/dist/components/respArea/ExplicitConstructedResponse.js +67 -0
  63. package/dist/components/respArea/InlineDropdown.d.ts +18 -0
  64. package/dist/components/respArea/InlineDropdown.d.ts.map +1 -0
  65. package/dist/components/respArea/InlineDropdown.js +91 -0
  66. package/dist/components/respArea/MathTemplated.d.ts +19 -0
  67. package/dist/components/respArea/MathTemplated.d.ts.map +1 -0
  68. package/dist/components/respArea/MathTemplated.js +97 -0
  69. package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
  70. package/dist/components/respArea/ToolbarIcon.d.ts.map +1 -0
  71. package/dist/components/respArea/ToolbarIcon.js +17 -0
  72. package/dist/constants.d.ts +14 -0
  73. package/dist/constants.d.ts.map +1 -0
  74. package/dist/constants.js +4 -0
  75. package/dist/extensions/css.d.ts +12 -0
  76. package/dist/extensions/css.d.ts.map +1 -0
  77. package/dist/extensions/css.js +115 -0
  78. package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
  79. package/dist/extensions/custom-toolbar-wrapper.d.ts.map +1 -0
  80. package/dist/extensions/custom-toolbar-wrapper.js +58 -0
  81. package/dist/extensions/div-node.d.ts +11 -0
  82. package/dist/extensions/div-node.d.ts.map +1 -0
  83. package/dist/extensions/div-node.js +25 -0
  84. package/dist/extensions/extended-table.d.ts +11 -0
  85. package/dist/extensions/extended-table.d.ts.map +1 -0
  86. package/dist/extensions/extended-table.js +15 -0
  87. package/dist/extensions/image-component.d.ts +22 -0
  88. package/dist/extensions/image-component.d.ts.map +1 -0
  89. package/dist/extensions/image-component.js +200 -0
  90. package/dist/extensions/image.d.ts +11 -0
  91. package/dist/extensions/image.d.ts.map +1 -0
  92. package/dist/extensions/image.js +42 -0
  93. package/dist/extensions/index.d.ts +17 -0
  94. package/dist/extensions/index.d.ts.map +1 -0
  95. package/dist/extensions/index.js +65 -0
  96. package/dist/extensions/math.d.ts +15 -0
  97. package/dist/extensions/math.d.ts.map +1 -0
  98. package/dist/extensions/math.js +150 -0
  99. package/dist/extensions/media.d.ts +19 -0
  100. package/dist/extensions/media.d.ts.map +1 -0
  101. package/dist/extensions/media.js +147 -0
  102. package/dist/extensions/responseArea.d.ts +28 -0
  103. package/dist/extensions/responseArea.d.ts.map +1 -0
  104. package/dist/extensions/responseArea.js +259 -0
  105. package/dist/index.d.ts +13 -0
  106. package/dist/index.d.ts.map +1 -0
  107. package/dist/index.js +6 -0
  108. package/dist/styles/editorContainerStyles.d.ts +135 -0
  109. package/dist/styles/editorContainerStyles.d.ts.map +1 -0
  110. package/dist/theme.d.ts +10 -0
  111. package/dist/theme.d.ts.map +1 -0
  112. package/dist/utils/helper.d.ts +10 -0
  113. package/dist/utils/helper.d.ts.map +1 -0
  114. package/dist/utils/helper.js +7 -0
  115. package/dist/utils/size.d.ts +10 -0
  116. package/dist/utils/size.d.ts.map +1 -0
  117. package/dist/utils/size.js +14 -0
  118. package/package.json +71 -0
  119. package/src/components/CharacterPicker.tsx +210 -0
  120. package/src/components/EditableHtml.tsx +416 -0
  121. package/src/components/MenuBar.tsx +558 -0
  122. package/src/components/TiptapContainer.tsx +228 -0
  123. package/src/components/characters/characterUtils.ts +457 -0
  124. package/src/components/characters/custom-popper.tsx +48 -0
  125. package/src/components/common/done-button.tsx +37 -0
  126. package/src/components/common/toolbar-buttons.tsx +132 -0
  127. package/src/components/icons/CssIcon.tsx +25 -0
  128. package/src/components/icons/RespArea.tsx +81 -0
  129. package/src/components/icons/TableIcons.tsx +62 -0
  130. package/src/components/icons/TextAlign.tsx +124 -0
  131. package/src/components/image/AltDialog.tsx +92 -0
  132. package/src/components/image/ImageToolbar.tsx +109 -0
  133. package/src/components/image/InsertImageHandler.ts +121 -0
  134. package/src/components/media/MediaDialog.tsx +606 -0
  135. package/src/components/media/MediaToolbar.tsx +59 -0
  136. package/src/components/media/MediaWrapper.tsx +49 -0
  137. package/src/components/respArea/DragInTheBlank/DragInTheBlank.tsx +86 -0
  138. package/src/components/respArea/DragInTheBlank/choice.tsx +266 -0
  139. package/src/components/respArea/ExplicitConstructedResponse.tsx +122 -0
  140. package/src/components/respArea/InlineDropdown.tsx +152 -0
  141. package/src/components/respArea/MathTemplated.tsx +134 -0
  142. package/src/components/respArea/ToolbarIcon.tsx +76 -0
  143. package/src/constants.ts +15 -0
  144. package/src/extensions/css.tsx +230 -0
  145. package/src/extensions/custom-toolbar-wrapper.tsx +88 -0
  146. package/src/extensions/div-node.tsx +46 -0
  147. package/src/extensions/extended-table.ts +34 -0
  148. package/src/extensions/image-component.tsx +303 -0
  149. package/src/extensions/image.tsx +64 -0
  150. package/src/extensions/index.tsx +91 -0
  151. package/src/extensions/math.tsx +285 -0
  152. package/src/extensions/media.tsx +198 -0
  153. package/src/extensions/responseArea.tsx +404 -0
  154. package/src/index.tsx +15 -0
  155. package/src/styles/editorContainerStyles.ts +155 -0
  156. package/src/theme.ts +11 -0
  157. package/src/utils/helper.tsx +27 -0
  158. package/src/utils/size.ts +42 -0
@@ -0,0 +1,606 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/components/media/MediaDialog.js
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import debug from 'debug';
14
+ import { styled } from '@mui/material/styles';
15
+ import Button from '@mui/material/Button';
16
+ import Dialog from '@mui/material/Dialog';
17
+ import MuiTabs from '@mui/material/Tabs';
18
+ import MuiTab from '@mui/material/Tab';
19
+ import DialogTitle from '@mui/material/DialogTitle';
20
+ import DialogContent from '@mui/material/DialogContent';
21
+ import DialogContentText from '@mui/material/DialogContentText';
22
+ import DialogActions from '@mui/material/DialogActions';
23
+ import TextField from '@mui/material/TextField';
24
+ import Typography from '@mui/material/Typography';
25
+ import IconButton from '@mui/material/IconButton';
26
+ import ActionDelete from '@mui/icons-material/Delete';
27
+
28
+ const log = debug('@pie-lib:editable-html:plugins:media:dialog');
29
+
30
+ const matchYoutubeUrl = (url) => {
31
+ if (!url) {
32
+ return false;
33
+ }
34
+
35
+ const p =
36
+ /^(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
37
+ if (url.match(p)) {
38
+ return url.match(p)[1];
39
+ }
40
+ return false;
41
+ };
42
+
43
+ const matchVimeoUrl = (url) =>
44
+ url &&
45
+ /(http|https)?:\/\/(www\.)?(player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^/]*)\/videos\/|)(video\/)?(\d+)(?:|\/\?)/.test(
46
+ url,
47
+ );
48
+
49
+ const matchDriveUrl = (url) =>
50
+ url && /^https:\/\/drive\.google\.com\/(?:file\/d\/|drive\/(?:u\/\d+\/)?folders\/|uc\?id=)([a-zA-Z0-9_-]+)/.test(url);
51
+
52
+ const matchSoundCloudUrl = (url) => {
53
+ if (!url) {
54
+ return false;
55
+ }
56
+
57
+ const regexp = /^https?:\/\/(soundcloud\.com|snd\.sc)\/(.*)$/;
58
+ return url.match(regexp) && url.match(regexp)[2];
59
+ };
60
+
61
+ const makeApiRequest = (url) => {
62
+ return new Promise((resolve) => {
63
+ try {
64
+ fetch(`https://soundcloud.com/oembed?format=json&url=${url}`)
65
+ .then((response) => response.json())
66
+ .then((json) => {
67
+ const d = document.createElement('div');
68
+
69
+ d.innerHTML = json.html;
70
+
71
+ const iframe = d.querySelector('iframe');
72
+
73
+ resolve(iframe.src);
74
+ })
75
+ .catch((err) => {
76
+ resolve('');
77
+ log(err);
78
+ });
79
+ } catch (err) {
80
+ resolve('');
81
+ }
82
+ });
83
+ };
84
+
85
+ const typeMap = {
86
+ video: 'Video',
87
+ audio: 'Audio',
88
+ };
89
+
90
+ const tabsTypeMap = {
91
+ uploadFile: 'upload-file',
92
+ insertUrl: 'insert-url',
93
+ };
94
+
95
+ const StyledDialog: any = styled(Dialog)(({ theme }) => ({
96
+ '& .MuiDialog-paper': {
97
+ minWidth: '500px',
98
+ },
99
+ }));
100
+
101
+ const StyledDialogContent: any = styled(DialogContent)(({ theme }) => ({
102
+ padding: 0,
103
+ }));
104
+
105
+ const StyledRow: any = styled('div')(({ theme }) => ({
106
+ display: 'flex',
107
+ flexDirection: 'space-between',
108
+ }));
109
+
110
+ const StyledUploadInput: any = styled('div')(({ theme }) => ({
111
+ marginTop: theme.spacing(1.5),
112
+ }));
113
+
114
+ const StyledInput: any = styled('input')(({ theme }) => ({}));
115
+
116
+ const StyledError: any = styled(Typography)(({ theme }) => ({
117
+ marginTop: theme.spacing(1.5),
118
+ color: theme.palette.error.main,
119
+ }));
120
+
121
+ const StyledIconButton: any = styled(IconButton)(({ theme }) => ({
122
+ marginLeft: theme.spacing(1.5),
123
+ }));
124
+
125
+ export class MediaDialog extends React.Component {
126
+ static propTypes = {
127
+ open: PropTypes.bool,
128
+ edit: PropTypes.bool,
129
+ disablePortal: PropTypes.bool,
130
+ handleClose: PropTypes.func,
131
+ uploadSoundSupport: PropTypes.shape({
132
+ add: PropTypes.func,
133
+ delete: PropTypes.func,
134
+ }),
135
+ type: PropTypes.string,
136
+ src: PropTypes.string,
137
+ url: PropTypes.string,
138
+ urlToUse: PropTypes.string,
139
+ starts: PropTypes.number,
140
+ ends: PropTypes.number,
141
+ height: PropTypes.number,
142
+ width: PropTypes.number,
143
+ };
144
+
145
+ constructor(props) {
146
+ super(props);
147
+
148
+ const { ends, height, src, starts, type, uploadSoundSupport, url, urlToUse, width } = props;
149
+ const showUploadFile = uploadSoundSupport?.add && uploadSoundSupport?.delete && type !== 'video' && !src;
150
+
151
+ this.state = {
152
+ ends: ends || 0,
153
+ url: url,
154
+ urlToUse: urlToUse,
155
+ formattedUrl: src,
156
+ height: height || 315,
157
+ invalid: false,
158
+ starts: starts || 0,
159
+ width: width || 560,
160
+ // default selected tab should be upload file if available
161
+ tabValue: showUploadFile ? tabsTypeMap.uploadFile : tabsTypeMap.insertUrl,
162
+ fileUpload: {
163
+ error: null,
164
+ loading: false,
165
+ scheduled: false,
166
+ url: '',
167
+ mimeType: '',
168
+ },
169
+ };
170
+ }
171
+
172
+ componentDidMount() {
173
+ if (this.props.url) {
174
+ this.urlChange({
175
+ target: {
176
+ value: this.props.url,
177
+ },
178
+ });
179
+ }
180
+ }
181
+
182
+ formatUrl: any = () => {
183
+ const { url, urlToUse, starts, ends } = this.state;
184
+ const isYoutube = matchYoutubeUrl(url);
185
+ const isVimeo = matchVimeoUrl(url);
186
+ let formattedUrl = urlToUse;
187
+
188
+ if ((isYoutube || isVimeo) && urlToUse) {
189
+ const params = [];
190
+
191
+ let paramName;
192
+ let paramStart;
193
+
194
+ switch (true) {
195
+ case isVimeo:
196
+ paramName = 't';
197
+ paramStart = '#';
198
+ break;
199
+ case isYoutube:
200
+ paramName = 'start';
201
+ paramStart = '?';
202
+ break;
203
+ default:
204
+ paramName = 'start';
205
+ paramStart = '?';
206
+ }
207
+
208
+ if (starts) {
209
+ params.push(`${paramName}=${starts}`);
210
+ }
211
+
212
+ if (ends) {
213
+ params.push(`end=${ends}`);
214
+ }
215
+
216
+ formattedUrl = `${urlToUse}${params.length ? paramStart : ''}${params.join('&')}`;
217
+ }
218
+
219
+ const callback = () => this.setState({ formattedUrl, updating: false });
220
+
221
+ this.setState({ formattedUrl: null, updating: true }, callback);
222
+ };
223
+
224
+ handleStateChange = (newState) => this.setState(newState, this.formatUrl);
225
+
226
+ checkAudio: any = (value) => {
227
+ if (matchSoundCloudUrl(value)) {
228
+ makeApiRequest(value)
229
+ .then((urlToUse) => {
230
+ this.handleStateChange({
231
+ urlToUse,
232
+ invalid: !urlToUse,
233
+ url: value,
234
+ });
235
+ })
236
+ .catch(log);
237
+ }
238
+ };
239
+
240
+ checkVideo: any = (value) => {
241
+ if (matchYoutubeUrl(value)) {
242
+ const regExp = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
243
+ const match = value.match(regExp);
244
+ const id = match[2];
245
+ const urlToUse = `https://youtube.com/embed/${id}`;
246
+
247
+ log('is youtube');
248
+
249
+ this.handleStateChange({
250
+ urlToUse,
251
+ url: value,
252
+ invalid: false,
253
+ });
254
+ }
255
+
256
+ if (matchVimeoUrl(value)) {
257
+ const id = value.replace(/.*vimeo.com\/(.*)/g, '$1');
258
+ const urlToUse = `https://player.vimeo.com/video/${id}`;
259
+
260
+ log('is vimeo');
261
+
262
+ this.handleStateChange({
263
+ urlToUse,
264
+ url: value,
265
+ ends: null,
266
+ invalid: false,
267
+ });
268
+ }
269
+
270
+ if (matchDriveUrl(value)) {
271
+ // https://drive.google.com/file/d/11QkK_gUO068amNvZBm9cxZpKX74WYb8q/view
272
+ const id = value.replace(
273
+ /^https:\/\/drive\.google\.com\/(?:file\/d\/|drive\/(?:u\/\d+\/)?folders\/|uc\?id=)([a-zA-Z0-9_-]+)\/.*/,
274
+ '$1',
275
+ );
276
+ const urlToUse = `https://drive.google.com/file/d/${id}/preview`;
277
+
278
+ log('is google drive');
279
+
280
+ this.handleStateChange({
281
+ urlToUse,
282
+ url: value,
283
+ ends: null,
284
+ invalid: false,
285
+ });
286
+ }
287
+ };
288
+
289
+ urlChange: any = (e) => {
290
+ const { value } = e.target || {};
291
+ const { type } = this.props;
292
+
293
+ if (type && type === 'audio') {
294
+ this.checkAudio(value);
295
+ return;
296
+ } else if (type && type === 'video') {
297
+ this.checkVideo(value);
298
+ return;
299
+ }
300
+
301
+ this.handleStateChange({
302
+ urlToUse: null,
303
+ url: null,
304
+ invalid: true,
305
+ });
306
+ };
307
+
308
+ changeHandler = (type) => (e) => this.handleStateChange({ [type]: e.target.value });
309
+
310
+ handleDone: any = (val) => {
311
+ const { handleClose } = this.props;
312
+ const { tabValue, fileUpload } = this.state;
313
+ const isInsertURL = tabValue === tabsTypeMap.insertUrl;
314
+
315
+ if (!val) {
316
+ if (fileUpload.url) {
317
+ this.handleRemoveFile();
318
+ }
319
+
320
+ handleClose(val);
321
+ return;
322
+ }
323
+
324
+ if (isInsertURL) {
325
+ const { ends, height, url, urlToUse, formattedUrl, starts, width } = this.state;
326
+
327
+ handleClose(val, {
328
+ tag: 'iframe',
329
+ ends,
330
+ height,
331
+ starts,
332
+ width,
333
+ url,
334
+ urlToUse,
335
+ src: formattedUrl,
336
+ });
337
+ return;
338
+ }
339
+
340
+ if (!fileUpload.loading) {
341
+ handleClose(val, {
342
+ tag: 'audio',
343
+ src: fileUpload.url,
344
+ });
345
+ return;
346
+ }
347
+
348
+ this.setState({
349
+ fileUpload: {
350
+ ...fileUpload,
351
+ scheduled: true,
352
+ },
353
+ });
354
+ };
355
+
356
+ handleUploadFile = async (e) => {
357
+ e.preventDefault();
358
+
359
+ this.setState({
360
+ fileUpload: {
361
+ ...this.state.fileUpload,
362
+ error: null,
363
+ loading: true,
364
+ },
365
+ });
366
+
367
+ const fileChosen = e.target.files[0];
368
+
369
+ const reader = new FileReader();
370
+
371
+ reader.onload = () => {
372
+ const dataURL = reader.result;
373
+
374
+ this.setState({
375
+ fileUpload: {
376
+ ...this.state.fileUpload,
377
+ url: dataURL,
378
+ mimeType: fileChosen.type,
379
+ },
380
+ });
381
+ };
382
+ reader.readAsDataURL(fileChosen);
383
+
384
+ this.props.uploadSoundSupport.add({
385
+ fileChosen,
386
+ done: (err, src) => {
387
+ log('done: err:', err);
388
+ if (err) {
389
+ //eslint-disable-next-line
390
+ console.log(err);
391
+ this.setState({
392
+ fileUpload: {
393
+ ...this.state.fileUpload,
394
+ scheduled: false,
395
+ loading: false,
396
+ error: err,
397
+ },
398
+ });
399
+ return;
400
+ }
401
+
402
+ const { fileUpload } = this.state;
403
+ const callback = fileUpload && fileUpload.scheduled ? this.handleDone.bind(this, true) : undefined;
404
+
405
+ this.setState(
406
+ {
407
+ fileUpload: {
408
+ ...fileUpload,
409
+ scheduled: false,
410
+ loading: false,
411
+ url: src,
412
+ },
413
+ },
414
+ callback,
415
+ );
416
+ },
417
+ });
418
+ };
419
+
420
+ handleRemoveFile = async () => {
421
+ this.props.uploadSoundSupport.delete(this.state.fileUpload.url, (err) => {
422
+ if (err) {
423
+ //eslint-disable-next-line
424
+ console.log(err);
425
+ this.setState({
426
+ fileUpload: {
427
+ ...this.state.fileUpload,
428
+ error: err,
429
+ },
430
+ });
431
+ }
432
+ });
433
+
434
+ // we should put it inside uploadSoundSupport.delete but we can leave it here for testing purposes
435
+ this.setState({
436
+ fileUpload: {
437
+ ...this.state.fileUpload,
438
+ loading: false,
439
+ url: '',
440
+ mimeType: '',
441
+ },
442
+ });
443
+ };
444
+
445
+ render() {
446
+ const { open, disablePortal, type, edit, uploadSoundSupport } = this.props;
447
+ const { ends, height, invalid, starts, width, url, mimeType, formattedUrl, updating, tabValue, fileUpload } =
448
+ this.state;
449
+ const isYoutube = matchYoutubeUrl(url);
450
+ const isInsertURL = tabValue === tabsTypeMap.insertUrl;
451
+ const isUploadMedia = tabValue === tabsTypeMap.uploadFile;
452
+ const submitIsDisabled = isInsertURL
453
+ ? invalid || url === null || url === undefined
454
+ : !fileUpload.url || fileUpload.scheduled;
455
+ const showUploadFile = uploadSoundSupport?.add && uploadSoundSupport?.delete && type !== 'video';
456
+
457
+ return (
458
+ <StyledDialog
459
+ disablePortal={disablePortal}
460
+ open={open}
461
+ onClose={() => this.handleDone(false)}
462
+ aria-labelledby="form-dialog-title"
463
+ >
464
+ <DialogTitle id="form-dialog-title">Insert {typeMap[type]}</DialogTitle>
465
+ <DialogContent>
466
+ <div>
467
+ <StyledRow>
468
+ <MuiTabs
469
+ indicatorColor="primary"
470
+ value={tabValue}
471
+ onChange={(event, value) => {
472
+ this.setState({ tabValue: value });
473
+ }}
474
+ >
475
+ {showUploadFile ? <MuiTab value={tabsTypeMap.uploadFile} label="Upload file" /> : null}
476
+ <MuiTab
477
+ value={tabsTypeMap.insertUrl}
478
+ label={type === 'video' ? 'Insert YouTube, Vimeo, or Google Drive URL' : 'Insert SoundCloud URL'}
479
+ />
480
+ </MuiTabs>
481
+ </StyledRow>
482
+ {isInsertURL && (
483
+ <div>
484
+ <TextField
485
+ autoFocus
486
+ error={invalid}
487
+ helperText={invalid ? 'Invalid URL' : ''}
488
+ margin="dense"
489
+ id="name"
490
+ label="URL"
491
+ placeholder={`Paste URL of ${type}...`}
492
+ type="text"
493
+ onChange={this.urlChange}
494
+ value={url}
495
+ fullWidth
496
+ />
497
+ {type === 'video' && (
498
+ <StyledDialogContent>
499
+ <DialogContentText>Video Properties</DialogContentText>
500
+ <TextField
501
+ autoFocus
502
+ margin="dense"
503
+ id="width"
504
+ label="Width"
505
+ type="number"
506
+ placeholder="Width"
507
+ value={width}
508
+ onChange={this.changeHandler('width')}
509
+ />
510
+ <TextField
511
+ autoFocus
512
+ margin="dense"
513
+ id="height"
514
+ label="Height"
515
+ type="number"
516
+ placeholder="Height"
517
+ value={height}
518
+ onChange={this.changeHandler('height')}
519
+ />
520
+ </StyledDialogContent>
521
+ )}
522
+ {formattedUrl && (
523
+ <iframe
524
+ width={width}
525
+ height={height}
526
+ src={formattedUrl}
527
+ frameBorder="0"
528
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
529
+ allowFullScreen
530
+ />
531
+ )}
532
+ {type === 'video' && (formattedUrl || updating) && !invalid && (
533
+ <React.Fragment>
534
+ <StyledDialogContent>
535
+ <TextField
536
+ autoFocus
537
+ margin="dense"
538
+ id="starts"
539
+ label="Starts"
540
+ type="number"
541
+ placeholder="Starts"
542
+ value={starts}
543
+ onChange={this.changeHandler('starts')}
544
+ />
545
+ {isYoutube && (
546
+ <TextField
547
+ autoFocus
548
+ margin="dense"
549
+ id="ends"
550
+ label="Ends"
551
+ type="number"
552
+ placeholder="Ends"
553
+ value={ends}
554
+ onChange={this.changeHandler('ends')}
555
+ />
556
+ )}
557
+ </StyledDialogContent>
558
+ </React.Fragment>
559
+ )}
560
+ </div>
561
+ )}
562
+ {isUploadMedia && (
563
+ <StyledUploadInput>
564
+ <div>
565
+ {fileUpload.url ? (
566
+ <>
567
+ <StyledRow>
568
+ <audio controls="controls" controlsList="nodownload">
569
+ <source type={mimeType} src={fileUpload.url} />
570
+ </audio>
571
+ <StyledIconButton aria-label="delete" onClick={this.handleRemoveFile}>
572
+ <ActionDelete />
573
+ </StyledIconButton>
574
+ </StyledRow>
575
+ {!fileUpload.scheduled && fileUpload.loading ? (
576
+ <Typography variant="subheading">Loading...</Typography>
577
+ ) : null}
578
+ {fileUpload.scheduled ? (
579
+ <Typography variant="subheading">
580
+ Waiting for Upload to finish, then inserting item...
581
+ </Typography>
582
+ ) : null}
583
+ </>
584
+ ) : !fileUpload.loading ? (
585
+ <StyledInput accept="audio/*" onChange={this.handleUploadFile} type="file" />
586
+ ) : null}
587
+ {!!fileUpload.error && <StyledError variant="caption">{fileUpload.error}</StyledError>}
588
+ </div>
589
+ </StyledUploadInput>
590
+ )}
591
+ </div>
592
+ </DialogContent>
593
+ <DialogActions>
594
+ <Button onClick={() => this.handleDone(false)} color="primary">
595
+ Cancel
596
+ </Button>
597
+ <Button disabled={submitIsDisabled} onClick={() => this.handleDone(true)} color="primary">
598
+ {edit ? 'Update' : 'Insert'}
599
+ </Button>
600
+ </DialogActions>
601
+ </StyledDialog>
602
+ );
603
+ }
604
+ }
605
+
606
+ export default MediaDialog;
@@ -0,0 +1,59 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/components/media/MediaToolbar.jsx
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import { styled } from '@mui/material/styles';
14
+
15
+ const StyledRoot: any = styled('span')(({ theme }) => ({
16
+ position: 'relative',
17
+ bottom: '5px',
18
+ left: 0,
19
+ width: '100%',
20
+ background: theme.palette.common.white,
21
+ display: 'inline-flex',
22
+ padding: '5px',
23
+ boxShadow: '0px 4px 4px rgba(0, 0, 0, 0.25)',
24
+ }));
25
+
26
+ const StyledEditContainer: any = styled('span')(({ theme }) => ({
27
+ cursor: 'pointer',
28
+ flex: 3,
29
+ border: `solid ${theme.palette.common.black}`,
30
+ textAlign: 'right',
31
+ borderWidth: '0 2px 0 0',
32
+ marginRight: '5px',
33
+ paddingRight: '5px',
34
+ }));
35
+
36
+ const StyledRemoveContainer: any = styled('span')({
37
+ cursor: 'pointer',
38
+ });
39
+
40
+ class MediaToolbar extends React.Component {
41
+ static propTypes = {
42
+ onEdit: PropTypes.func,
43
+ hideEdit: PropTypes.bool,
44
+ onRemove: PropTypes.func,
45
+ };
46
+
47
+ render() {
48
+ const { hideEdit, onEdit, onRemove } = this.props;
49
+
50
+ return (
51
+ <StyledRoot>
52
+ {hideEdit ? null : <StyledEditContainer onClick={onEdit}>Edit Settings</StyledEditContainer>}
53
+ <StyledRemoveContainer onClick={onRemove}>Remove</StyledRemoveContainer>
54
+ </StyledRoot>
55
+ );
56
+ }
57
+ }
58
+
59
+ export default MediaToolbar;
@@ -0,0 +1,49 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/components/media/MediaWrapper.jsx
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import { styled } from '@mui/material/styles';
14
+
15
+ const StyledWrapper: any = styled('span', {
16
+ shouldForwardProp: (prop) => prop !== 'editor',
17
+ })(({ editor }) => ({
18
+ position: 'relative',
19
+ ...(editor && {
20
+ display: 'inline-block',
21
+ overflow: 'hidden',
22
+ }),
23
+ }));
24
+
25
+ class MediaWrapper extends React.Component {
26
+ static propTypes = {
27
+ children: PropTypes.array,
28
+ editor: PropTypes.bool,
29
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
30
+ };
31
+
32
+ render() {
33
+ const { editor, children, width, ...rest } = this.props;
34
+
35
+ return (
36
+ <StyledWrapper
37
+ editor={editor}
38
+ {...rest}
39
+ style={{
40
+ width: width || 300,
41
+ }}
42
+ >
43
+ {children}
44
+ </StyledWrapper>
45
+ );
46
+ }
47
+ }
48
+
49
+ export default MediaWrapper;