@pie-lib/editable-html 10.0.0-beta.5 → 10.0.0-beta.7
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.
- package/CHANGELOG.md +255 -152
- package/lib/components.js +15 -39
- package/lib/components.js.map +1 -1
- package/lib/editor.js +200 -356
- package/lib/editor.js.map +1 -1
- package/lib/index.js +25 -49
- package/lib/index.js.map +1 -1
- package/lib/new-serialization.js +6 -67
- package/lib/new-serialization.js.map +1 -1
- package/lib/parse-html.js +7 -6
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js +3 -13
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js +20 -59
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js +1 -1
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/hotKeys/index.js +9 -16
- package/lib/plugins/hotKeys/index.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js +6 -27
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js +42 -99
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +14 -50
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +16 -59
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +13 -25
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +6 -36
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +11 -46
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +89 -93
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +32 -109
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +107 -195
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +7 -27
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +9 -14
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +13 -53
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +6 -20
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +5 -10
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +16 -31
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +7 -54
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +3 -10
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +6 -21
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js +1 -8
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +54 -187
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +12 -44
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +17 -46
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +2 -10
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +134 -144
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +2 -6
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +9 -40
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +29 -83
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js +8 -30
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js +11 -69
- package/lib/serialization.js.map +1 -1
- package/lib/test-serializer.js +3 -46
- package/lib/test-serializer.js.map +1 -1
- package/lib/theme.js +1 -1
- package/lib/theme.js.map +1 -1
- package/package.json +7 -7
- package/playground/image/data.js +20 -20
- package/playground/image/index.html +20 -22
- package/playground/image/index.jsx +10 -12
- package/playground/index.html +23 -25
- package/playground/mathquill/index.html +20 -23
- package/playground/mathquill/index.jsx +22 -18
- package/playground/prod-test/index.html +20 -24
- package/playground/prod-test/index.jsx +3 -5
- package/playground/schema-override/data.js +10 -10
- package/playground/schema-override/image-plugin.jsx +4 -3
- package/playground/schema-override/index.html +19 -21
- package/playground/schema-override/index.jsx +14 -13
- package/playground/serialization/data.js +10 -10
- package/playground/serialization/image-plugin.jsx +4 -3
- package/playground/serialization/index.html +20 -22
- package/playground/table-examples.html +8 -5
- package/playground/webpack.config.js +10 -10
- package/src/components.js +7 -7
- package/src/editor.jsx +144 -155
- package/src/index.jsx +24 -17
- package/src/new-serialization.jsx +22 -22
- package/src/parse-html.js +1 -1
- package/src/plugins/characters/custom-popper.js +7 -7
- package/src/plugins/characters/index.jsx +36 -26
- package/src/plugins/characters/utils.js +81 -81
- package/src/plugins/hotKeys/index.js +3 -3
- package/src/plugins/image/alt-dialog.jsx +5 -4
- package/src/plugins/image/component.jsx +52 -53
- package/src/plugins/image/image-toolbar.jsx +19 -27
- package/src/plugins/image/index.jsx +41 -47
- package/src/plugins/image/insert-image-handler.js +23 -14
- package/src/plugins/index.jsx +8 -10
- package/src/plugins/list/index.jsx +21 -24
- package/src/plugins/math/index.jsx +93 -40
- package/src/plugins/media/index.jsx +42 -42
- package/src/plugins/media/media-dialog.js +63 -89
- package/src/plugins/media/media-toolbar.jsx +8 -8
- package/src/plugins/media/media-wrapper.jsx +10 -7
- package/src/plugins/respArea/drag-in-the-blank/choice.jsx +19 -21
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +10 -12
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +6 -5
- package/src/plugins/respArea/icons/index.jsx +14 -11
- package/src/plugins/respArea/index.jsx +32 -56
- package/src/plugins/respArea/inline-dropdown/index.jsx +6 -6
- package/src/plugins/respArea/utils.jsx +15 -11
- package/src/plugins/table/icons/index.jsx +11 -17
- package/src/plugins/table/index.jsx +69 -69
- package/src/plugins/table/table-toolbar.jsx +8 -13
- package/src/plugins/toolbar/default-toolbar.jsx +15 -17
- package/src/plugins/toolbar/done-button.jsx +4 -4
- package/src/plugins/toolbar/editor-and-toolbar.jsx +50 -54
- package/src/plugins/toolbar/index.jsx +3 -2
- package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
- package/src/plugins/toolbar/toolbar.jsx +43 -42
- package/src/plugins/utils.js +7 -8
- package/src/serialization.jsx +34 -32
- package/src/test-serializer.js +13 -13
- package/lib/old-serialization.js +0 -330
- package/lib/slate-editor.js +0 -302
- package/package-lock.json +0 -3762
|
@@ -5,7 +5,6 @@ import { jsx } from 'slate-hyperscript';
|
|
|
5
5
|
import { ReactEditor } from 'slate-react';
|
|
6
6
|
import TheatersIcon from '@material-ui/icons/Theaters';
|
|
7
7
|
import VolumeUpIcon from '@material-ui/icons/VolumeUp';
|
|
8
|
-
import get from 'lodash/get';
|
|
9
8
|
import omit from 'lodash/omit';
|
|
10
9
|
|
|
11
10
|
import debug from 'debug';
|
|
@@ -18,10 +17,10 @@ const log = debug('@pie-lib:editable-html:plugins:image');
|
|
|
18
17
|
const removeDialogs = () => {
|
|
19
18
|
const prevDialogs = document.querySelectorAll('.insert-media-dialog');
|
|
20
19
|
|
|
21
|
-
prevDialogs.forEach(s => s.remove());
|
|
20
|
+
prevDialogs.forEach((s) => s.remove());
|
|
22
21
|
};
|
|
23
22
|
|
|
24
|
-
export const insertDialog = props => {
|
|
23
|
+
export const insertDialog = (props) => {
|
|
25
24
|
const newEl = document.createElement('div');
|
|
26
25
|
const { type, callback, opts, ...rest } = props;
|
|
27
26
|
const initialBodyOverflow = document.body.style.overflow;
|
|
@@ -55,7 +54,7 @@ export const insertDialog = props => {
|
|
|
55
54
|
|
|
56
55
|
const getNodeBy = (editor, callback) => {
|
|
57
56
|
const descendants = SlateNode.descendants(editor, {
|
|
58
|
-
reverse: true
|
|
57
|
+
reverse: true,
|
|
59
58
|
});
|
|
60
59
|
|
|
61
60
|
for (const [descendant, descendantPath] of descendants) {
|
|
@@ -81,7 +80,7 @@ const types = ['audio', 'video'];
|
|
|
81
80
|
export default function MediaPlugin(type, opts) {
|
|
82
81
|
const toolbar = {
|
|
83
82
|
icon: type === 'audio' ? <VolumeUpIcon /> : <TheatersIcon />,
|
|
84
|
-
onClick: editor => {
|
|
83
|
+
onClick: (editor) => {
|
|
85
84
|
log('[toolbar] onClick');
|
|
86
85
|
const inline = {
|
|
87
86
|
type: type,
|
|
@@ -95,9 +94,9 @@ export default function MediaPlugin(type, opts) {
|
|
|
95
94
|
starts: undefined,
|
|
96
95
|
src: undefined,
|
|
97
96
|
url: undefined,
|
|
98
|
-
width: undefined
|
|
97
|
+
width: undefined,
|
|
99
98
|
},
|
|
100
|
-
children: [{ text: '' }]
|
|
99
|
+
children: [{ text: '' }],
|
|
101
100
|
};
|
|
102
101
|
|
|
103
102
|
editor.insertNode(inline);
|
|
@@ -112,55 +111,55 @@ export default function MediaPlugin(type, opts) {
|
|
|
112
111
|
if (!val) {
|
|
113
112
|
editor.apply({
|
|
114
113
|
type: 'remove_node',
|
|
115
|
-
path: nodePath
|
|
114
|
+
path: nodePath,
|
|
116
115
|
});
|
|
117
116
|
} else {
|
|
118
117
|
editor.apply({
|
|
119
118
|
type: 'set_node',
|
|
120
119
|
path: nodePath,
|
|
121
120
|
properties: {
|
|
122
|
-
data: inline.data
|
|
121
|
+
data: inline.data,
|
|
123
122
|
},
|
|
124
123
|
newProperties: {
|
|
125
124
|
data: {
|
|
126
125
|
...data,
|
|
127
|
-
newMedia: false
|
|
128
|
-
}
|
|
129
|
-
}
|
|
126
|
+
newMedia: false,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
130
129
|
});
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
moveFocusAfterMedia(editor, inline);
|
|
135
|
-
}
|
|
134
|
+
},
|
|
136
135
|
});
|
|
137
|
-
}
|
|
136
|
+
},
|
|
138
137
|
};
|
|
139
138
|
|
|
140
139
|
return {
|
|
141
140
|
name: type,
|
|
142
141
|
toolbar,
|
|
143
|
-
rules: editor => {
|
|
142
|
+
rules: (editor) => {
|
|
144
143
|
const { isVoid, isInline } = editor;
|
|
145
144
|
|
|
146
|
-
editor.isVoid = element => {
|
|
145
|
+
editor.isVoid = (element) => {
|
|
147
146
|
return ['audio', 'video'].includes(element.type) ? true : isVoid(element);
|
|
148
147
|
};
|
|
149
148
|
|
|
150
|
-
editor.isInline = element => {
|
|
149
|
+
editor.isInline = (element) => {
|
|
151
150
|
return ['audio', 'video'].includes(element.type) ? true : isInline(element);
|
|
152
151
|
};
|
|
153
152
|
|
|
154
153
|
return editor;
|
|
155
154
|
},
|
|
156
|
-
supports: node => node.type === type,
|
|
155
|
+
supports: (node) => node.type === type,
|
|
157
156
|
renderNode(props) {
|
|
158
157
|
if (props.node.type === type) {
|
|
159
158
|
const { node, editor } = props;
|
|
160
159
|
const { data } = node;
|
|
161
160
|
const { src, height, width, editing, tag, ...rest } = omit(data, ['newMedia', 'urlToUse']);
|
|
162
161
|
const attributes = { ...rest, ...props.attributes };
|
|
163
|
-
const handleEdit = event => {
|
|
162
|
+
const handleEdit = (event) => {
|
|
164
163
|
const nodeToEdit = ReactEditor.toSlateNode(editor, event.target);
|
|
165
164
|
const nodePath = ReactEditor.findPath(editor, nodeToEdit);
|
|
166
165
|
|
|
@@ -168,14 +167,14 @@ export default function MediaPlugin(type, opts) {
|
|
|
168
167
|
type: 'set_node',
|
|
169
168
|
path: nodePath,
|
|
170
169
|
properties: {
|
|
171
|
-
data: node.data
|
|
170
|
+
data: node.data,
|
|
172
171
|
},
|
|
173
172
|
newProperties: {
|
|
174
173
|
data: {
|
|
175
174
|
...data,
|
|
176
|
-
editing: true
|
|
177
|
-
}
|
|
178
|
-
}
|
|
175
|
+
editing: true,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
179
178
|
});
|
|
180
179
|
|
|
181
180
|
insertDialog({
|
|
@@ -191,41 +190,43 @@ export default function MediaPlugin(type, opts) {
|
|
|
191
190
|
type: 'set_node',
|
|
192
191
|
path: nodePath,
|
|
193
192
|
properties: {
|
|
194
|
-
data: node.data
|
|
193
|
+
data: node.data,
|
|
195
194
|
},
|
|
196
195
|
newProperties: {
|
|
197
196
|
data: {
|
|
198
197
|
...data,
|
|
199
|
-
editing: true
|
|
200
|
-
}
|
|
201
|
-
}
|
|
198
|
+
editing: true,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
202
201
|
});
|
|
203
202
|
}
|
|
204
|
-
}
|
|
203
|
+
},
|
|
205
204
|
});
|
|
206
205
|
};
|
|
207
|
-
const handleDelete = event => {
|
|
206
|
+
const handleDelete = (event) => {
|
|
208
207
|
const nodeToEdit = ReactEditor.toSlateNode(editor, event.target);
|
|
209
208
|
const nodePath = ReactEditor.findPath(editor, nodeToEdit);
|
|
210
209
|
|
|
211
210
|
editor.apply({
|
|
212
211
|
type: 'remove_node',
|
|
213
|
-
path: nodePath
|
|
212
|
+
path: nodePath,
|
|
214
213
|
});
|
|
215
214
|
};
|
|
216
|
-
const
|
|
215
|
+
const computedProps = {};
|
|
217
216
|
|
|
218
217
|
if (width) {
|
|
219
|
-
|
|
218
|
+
computedProps.width = `${width}px`;
|
|
220
219
|
}
|
|
221
220
|
|
|
222
221
|
if (height) {
|
|
223
|
-
|
|
222
|
+
computedProps.height = `${height}px`;
|
|
224
223
|
}
|
|
225
224
|
|
|
225
|
+
computedProps.editing = editing ? 1 : 0;
|
|
226
|
+
|
|
226
227
|
if (tag === 'audio') {
|
|
227
228
|
return (
|
|
228
|
-
<MediaWrapper data-type={type} width={
|
|
229
|
+
<MediaWrapper data-type={type} width={computedProps.width} attributes={attributes}>
|
|
229
230
|
<audio controls="controls">
|
|
230
231
|
<source type="audio/mp3" src={src} />
|
|
231
232
|
</audio>
|
|
@@ -236,16 +237,15 @@ export default function MediaPlugin(type, opts) {
|
|
|
236
237
|
}
|
|
237
238
|
|
|
238
239
|
return (
|
|
239
|
-
<MediaWrapper data-type={type} width={
|
|
240
|
+
<MediaWrapper data-type={type} width={computedProps.width} attributes={attributes}>
|
|
240
241
|
<div contentEditable={false}>
|
|
241
242
|
<iframe
|
|
242
243
|
frameBorder="0"
|
|
243
244
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
|
244
245
|
allowFullScreen
|
|
245
246
|
src={src}
|
|
246
|
-
editing={editing ? 1 : 0}
|
|
247
247
|
{...rest}
|
|
248
|
-
{...
|
|
248
|
+
{...computedProps}
|
|
249
249
|
/>
|
|
250
250
|
<MediaToolbar onEdit={handleEdit} onRemove={handleDelete} />
|
|
251
251
|
</div>
|
|
@@ -291,8 +291,8 @@ export const serialization = {
|
|
|
291
291
|
starts,
|
|
292
292
|
title,
|
|
293
293
|
width,
|
|
294
|
-
url
|
|
295
|
-
}
|
|
294
|
+
url,
|
|
295
|
+
},
|
|
296
296
|
});
|
|
297
297
|
|
|
298
298
|
log('return object: ', out);
|
|
@@ -323,11 +323,11 @@ export const serialization = {
|
|
|
323
323
|
'data-ends': ends,
|
|
324
324
|
'data-starts': starts,
|
|
325
325
|
'data-title': title,
|
|
326
|
-
'data-url': url
|
|
326
|
+
'data-url': url,
|
|
327
327
|
};
|
|
328
328
|
const props = {
|
|
329
329
|
...style,
|
|
330
|
-
src
|
|
330
|
+
src,
|
|
331
331
|
};
|
|
332
332
|
|
|
333
333
|
if (tag === 'audio') {
|
|
@@ -349,5 +349,5 @@ export const serialization = {
|
|
|
349
349
|
{...props}
|
|
350
350
|
/>
|
|
351
351
|
);
|
|
352
|
-
}
|
|
352
|
+
},
|
|
353
353
|
};
|
|
@@ -18,7 +18,7 @@ import ActionDelete from '@material-ui/icons/Delete';
|
|
|
18
18
|
|
|
19
19
|
const log = debug('@pie-lib:editable-html:plugins:media:dialog');
|
|
20
20
|
|
|
21
|
-
const matchYoutubeUrl = url => {
|
|
21
|
+
const matchYoutubeUrl = (url) => {
|
|
22
22
|
if (!url) {
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
@@ -30,13 +30,13 @@ const matchYoutubeUrl = url => {
|
|
|
30
30
|
return false;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const matchVimeoUrl = url =>
|
|
33
|
+
const matchVimeoUrl = (url) =>
|
|
34
34
|
url &&
|
|
35
35
|
/(http|https)?:\/\/(www\.)?(player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^/]*)\/videos\/|)(video\/)?(\d+)(?:|\/\?)/.test(
|
|
36
|
-
url
|
|
36
|
+
url,
|
|
37
37
|
);
|
|
38
38
|
|
|
39
|
-
const matchSoundCloudUrl = url => {
|
|
39
|
+
const matchSoundCloudUrl = (url) => {
|
|
40
40
|
if (!url) {
|
|
41
41
|
return false;
|
|
42
42
|
}
|
|
@@ -45,12 +45,12 @@ const matchSoundCloudUrl = url => {
|
|
|
45
45
|
return url.match(regexp) && url.match(regexp)[2];
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
const makeApiRequest = url => {
|
|
49
|
-
return new Promise(resolve => {
|
|
48
|
+
const makeApiRequest = (url) => {
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
50
|
try {
|
|
51
51
|
fetch(`https://soundcloud.com/oembed?format=json&url=${url}`)
|
|
52
|
-
.then(response => response.json())
|
|
53
|
-
.then(json => {
|
|
52
|
+
.then((response) => response.json())
|
|
53
|
+
.then((json) => {
|
|
54
54
|
const d = document.createElement('div');
|
|
55
55
|
|
|
56
56
|
d.innerHTML = json.html;
|
|
@@ -59,7 +59,7 @@ const makeApiRequest = url => {
|
|
|
59
59
|
|
|
60
60
|
resolve(iframe.src);
|
|
61
61
|
})
|
|
62
|
-
.catch(err => {
|
|
62
|
+
.catch((err) => {
|
|
63
63
|
resolve('');
|
|
64
64
|
log(err);
|
|
65
65
|
});
|
|
@@ -71,7 +71,7 @@ const makeApiRequest = url => {
|
|
|
71
71
|
|
|
72
72
|
const typeMap = {
|
|
73
73
|
video: 'Video',
|
|
74
|
-
audio: 'Audio'
|
|
74
|
+
audio: 'Audio',
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
export class MediaDialog extends React.Component {
|
|
@@ -83,7 +83,7 @@ export class MediaDialog extends React.Component {
|
|
|
83
83
|
handleClose: PropTypes.func,
|
|
84
84
|
uploadSoundSupport: PropTypes.shape({
|
|
85
85
|
add: PropTypes.func,
|
|
86
|
-
delete: PropTypes.func
|
|
86
|
+
delete: PropTypes.func,
|
|
87
87
|
}),
|
|
88
88
|
type: PropTypes.string,
|
|
89
89
|
src: PropTypes.string,
|
|
@@ -92,7 +92,7 @@ export class MediaDialog extends React.Component {
|
|
|
92
92
|
starts: PropTypes.number,
|
|
93
93
|
ends: PropTypes.number,
|
|
94
94
|
height: PropTypes.number,
|
|
95
|
-
width: PropTypes.number
|
|
95
|
+
width: PropTypes.number,
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
constructor(props) {
|
|
@@ -114,8 +114,8 @@ export class MediaDialog extends React.Component {
|
|
|
114
114
|
fileUpload: {
|
|
115
115
|
loading: false,
|
|
116
116
|
url: '',
|
|
117
|
-
error: null
|
|
118
|
-
}
|
|
117
|
+
error: null,
|
|
118
|
+
},
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -123,8 +123,8 @@ export class MediaDialog extends React.Component {
|
|
|
123
123
|
if (this.props.url) {
|
|
124
124
|
this.urlChange({
|
|
125
125
|
target: {
|
|
126
|
-
value: this.props.url
|
|
127
|
-
}
|
|
126
|
+
value: this.props.url,
|
|
127
|
+
},
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -171,20 +171,20 @@ export class MediaDialog extends React.Component {
|
|
|
171
171
|
this.setState({ formattedUrl: null, updating: true }, callback);
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
handleStateChange = newState => this.setState(newState, this.formatUrl);
|
|
174
|
+
handleStateChange = (newState) => this.setState(newState, this.formatUrl);
|
|
175
175
|
|
|
176
|
-
urlChange = e => {
|
|
176
|
+
urlChange = (e) => {
|
|
177
177
|
const { value } = e.target || {};
|
|
178
178
|
const { type } = this.props;
|
|
179
179
|
|
|
180
180
|
if (type && type === 'audio') {
|
|
181
181
|
if (matchSoundCloudUrl(value)) {
|
|
182
182
|
makeApiRequest(value)
|
|
183
|
-
.then(urlToUse => {
|
|
183
|
+
.then((urlToUse) => {
|
|
184
184
|
this.handleStateChange({
|
|
185
185
|
urlToUse,
|
|
186
186
|
invalid: !urlToUse,
|
|
187
|
-
url: value || ''
|
|
187
|
+
url: value || '',
|
|
188
188
|
});
|
|
189
189
|
})
|
|
190
190
|
.catch(log);
|
|
@@ -203,7 +203,7 @@ export class MediaDialog extends React.Component {
|
|
|
203
203
|
this.handleStateChange({
|
|
204
204
|
urlToUse,
|
|
205
205
|
url: value || '',
|
|
206
|
-
invalid: false
|
|
206
|
+
invalid: false,
|
|
207
207
|
});
|
|
208
208
|
|
|
209
209
|
return;
|
|
@@ -219,7 +219,7 @@ export class MediaDialog extends React.Component {
|
|
|
219
219
|
urlToUse,
|
|
220
220
|
url: value || '',
|
|
221
221
|
ends: null,
|
|
222
|
-
invalid: false
|
|
222
|
+
invalid: false,
|
|
223
223
|
});
|
|
224
224
|
|
|
225
225
|
return;
|
|
@@ -229,13 +229,13 @@ export class MediaDialog extends React.Component {
|
|
|
229
229
|
this.handleStateChange({
|
|
230
230
|
urlToUse: '',
|
|
231
231
|
url: '',
|
|
232
|
-
invalid: true
|
|
232
|
+
invalid: true,
|
|
233
233
|
});
|
|
234
234
|
};
|
|
235
235
|
|
|
236
|
-
changeHandler = type => e => this.handleStateChange({ [type]: e.target.value });
|
|
236
|
+
changeHandler = (type) => (e) => this.handleStateChange({ [type]: e.target.value });
|
|
237
237
|
|
|
238
|
-
handleDone = val => {
|
|
238
|
+
handleDone = (val) => {
|
|
239
239
|
const { handleClose } = this.props;
|
|
240
240
|
const { tabValue, fileUpload } = this.state;
|
|
241
241
|
const isInsertURL = tabValue === 0;
|
|
@@ -257,25 +257,25 @@ export class MediaDialog extends React.Component {
|
|
|
257
257
|
width,
|
|
258
258
|
url,
|
|
259
259
|
urlToUse,
|
|
260
|
-
src: formattedUrl
|
|
260
|
+
src: formattedUrl,
|
|
261
261
|
});
|
|
262
262
|
} else {
|
|
263
263
|
handleClose(val, {
|
|
264
264
|
tag: 'audio',
|
|
265
|
-
src: fileUpload.url
|
|
265
|
+
src: fileUpload.url,
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
268
|
};
|
|
269
269
|
|
|
270
|
-
handleUploadFile = async e => {
|
|
270
|
+
handleUploadFile = async (e) => {
|
|
271
271
|
e.preventDefault();
|
|
272
272
|
|
|
273
273
|
this.setState({
|
|
274
274
|
fileUpload: {
|
|
275
275
|
...this.state.fileUpload,
|
|
276
276
|
error: null,
|
|
277
|
-
loading: true
|
|
278
|
-
}
|
|
277
|
+
loading: true,
|
|
278
|
+
},
|
|
279
279
|
});
|
|
280
280
|
|
|
281
281
|
const fileChosen = e.target.files[0];
|
|
@@ -288,8 +288,8 @@ export class MediaDialog extends React.Component {
|
|
|
288
288
|
this.setState({
|
|
289
289
|
fileUpload: {
|
|
290
290
|
...this.state.fileUpload,
|
|
291
|
-
url: dataURL
|
|
292
|
-
}
|
|
291
|
+
url: dataURL,
|
|
292
|
+
},
|
|
293
293
|
});
|
|
294
294
|
};
|
|
295
295
|
reader.readAsDataURL(fileChosen);
|
|
@@ -305,32 +305,32 @@ export class MediaDialog extends React.Component {
|
|
|
305
305
|
fileUpload: {
|
|
306
306
|
...this.state.fileUpload,
|
|
307
307
|
loading: false,
|
|
308
|
-
error: err
|
|
309
|
-
}
|
|
308
|
+
error: err,
|
|
309
|
+
},
|
|
310
310
|
});
|
|
311
311
|
} else {
|
|
312
312
|
this.setState({
|
|
313
313
|
fileUpload: {
|
|
314
314
|
...this.state.fileUpload,
|
|
315
315
|
loading: false,
|
|
316
|
-
url: src
|
|
317
|
-
}
|
|
316
|
+
url: src,
|
|
317
|
+
},
|
|
318
318
|
});
|
|
319
319
|
}
|
|
320
|
-
}
|
|
320
|
+
},
|
|
321
321
|
});
|
|
322
322
|
};
|
|
323
323
|
|
|
324
324
|
handleRemoveFile = async () => {
|
|
325
|
-
this.props.uploadSoundSupport.delete(this.state.fileUpload.url, err => {
|
|
325
|
+
this.props.uploadSoundSupport.delete(this.state.fileUpload.url, (err) => {
|
|
326
326
|
if (err) {
|
|
327
327
|
//eslint-disable-next-line
|
|
328
328
|
console.log(err);
|
|
329
329
|
this.setState({
|
|
330
330
|
fileUpload: {
|
|
331
331
|
...this.state.fileUpload,
|
|
332
|
-
error: err
|
|
333
|
-
}
|
|
332
|
+
error: err,
|
|
333
|
+
},
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
336
|
});
|
|
@@ -340,36 +340,23 @@ export class MediaDialog extends React.Component {
|
|
|
340
340
|
fileUpload: {
|
|
341
341
|
...this.state.fileUpload,
|
|
342
342
|
loading: false,
|
|
343
|
-
url: ''
|
|
344
|
-
}
|
|
343
|
+
url: '',
|
|
344
|
+
},
|
|
345
345
|
});
|
|
346
346
|
};
|
|
347
347
|
|
|
348
348
|
render() {
|
|
349
349
|
const { classes, open, disablePortal, type, edit, uploadSoundSupport } = this.props;
|
|
350
|
-
const {
|
|
351
|
-
ends,
|
|
352
|
-
height,
|
|
353
|
-
invalid,
|
|
354
|
-
starts,
|
|
355
|
-
width,
|
|
356
|
-
url,
|
|
357
|
-
formattedUrl,
|
|
358
|
-
updating,
|
|
359
|
-
tabValue,
|
|
360
|
-
fileUpload
|
|
361
|
-
} = this.state;
|
|
350
|
+
const { ends, height, invalid, starts, width, url, formattedUrl, updating, tabValue, fileUpload } = this.state;
|
|
362
351
|
const isYoutube = matchYoutubeUrl(url);
|
|
363
352
|
const isInsertURL = tabValue === 0;
|
|
364
353
|
const isUploadMedia = tabValue === 1;
|
|
365
|
-
const submitIsDisabled = isInsertURL
|
|
366
|
-
? invalid || url === null || url === undefined
|
|
367
|
-
: !fileUpload.url;
|
|
354
|
+
const submitIsDisabled = isInsertURL ? invalid || url === null || url === undefined : !fileUpload.url;
|
|
368
355
|
|
|
369
356
|
return (
|
|
370
357
|
<Dialog
|
|
371
358
|
classes={{
|
|
372
|
-
paper: classes.paper
|
|
359
|
+
paper: classes.paper,
|
|
373
360
|
}}
|
|
374
361
|
disablePortal={disablePortal}
|
|
375
362
|
open={open}
|
|
@@ -387,9 +374,7 @@ export class MediaDialog extends React.Component {
|
|
|
387
374
|
this.setState({ tabValue: value });
|
|
388
375
|
}}
|
|
389
376
|
>
|
|
390
|
-
<MuiTab
|
|
391
|
-
label={type === 'video' ? 'Insert YouTube or Vimeo URL' : 'Insert SoundCloud URL'}
|
|
392
|
-
/>
|
|
377
|
+
<MuiTab label={type === 'video' ? 'Insert YouTube or Vimeo URL' : 'Insert SoundCloud URL'} />
|
|
393
378
|
{uploadSoundSupport?.add && uploadSoundSupport?.delete && type !== 'video' ? (
|
|
394
379
|
<MuiTab label="Upload file" />
|
|
395
380
|
) : null}
|
|
@@ -413,7 +398,7 @@ export class MediaDialog extends React.Component {
|
|
|
413
398
|
{type === 'video' && (
|
|
414
399
|
<DialogContent
|
|
415
400
|
classes={{
|
|
416
|
-
root: classes.properties
|
|
401
|
+
root: classes.properties,
|
|
417
402
|
}}
|
|
418
403
|
>
|
|
419
404
|
<DialogContentText>Video Properties</DialogContentText>
|
|
@@ -453,7 +438,7 @@ export class MediaDialog extends React.Component {
|
|
|
453
438
|
<React.Fragment>
|
|
454
439
|
<DialogContent
|
|
455
440
|
classes={{
|
|
456
|
-
root: classes.properties
|
|
441
|
+
root: classes.properties,
|
|
457
442
|
}}
|
|
458
443
|
>
|
|
459
444
|
<TextField
|
|
@@ -492,25 +477,14 @@ export class MediaDialog extends React.Component {
|
|
|
492
477
|
<audio controls="controls">
|
|
493
478
|
<source type="audio/mp3" src={fileUpload.url} />
|
|
494
479
|
</audio>
|
|
495
|
-
<IconButton
|
|
496
|
-
aria-label="delete"
|
|
497
|
-
className={classes.deleteIcon}
|
|
498
|
-
onClick={this.handleRemoveFile}
|
|
499
|
-
>
|
|
480
|
+
<IconButton aria-label="delete" className={classes.deleteIcon} onClick={this.handleRemoveFile}>
|
|
500
481
|
<ActionDelete />
|
|
501
482
|
</IconButton>
|
|
502
483
|
</div>
|
|
503
|
-
{fileUpload.loading ?
|
|
504
|
-
<Typography variant="subheading">Loading...</Typography>
|
|
505
|
-
) : null}
|
|
484
|
+
{fileUpload.loading ? <Typography variant="subheading">Loading...</Typography> : null}
|
|
506
485
|
</>
|
|
507
486
|
) : !fileUpload.loading ? (
|
|
508
|
-
<input
|
|
509
|
-
accept="audio/*"
|
|
510
|
-
className={classes.input}
|
|
511
|
-
onChange={this.handleUploadFile}
|
|
512
|
-
type="file"
|
|
513
|
-
/>
|
|
487
|
+
<input accept="audio/*" className={classes.input} onChange={this.handleUploadFile} type="file" />
|
|
514
488
|
) : null}
|
|
515
489
|
{!!fileUpload.error && (
|
|
516
490
|
<Typography className={classes.error} variant="caption">
|
|
@@ -535,35 +509,35 @@ export class MediaDialog extends React.Component {
|
|
|
535
509
|
}
|
|
536
510
|
}
|
|
537
511
|
|
|
538
|
-
const styles = () => ({
|
|
512
|
+
const styles = (theme) => ({
|
|
539
513
|
paper: {
|
|
540
|
-
minWidth: '500px'
|
|
514
|
+
minWidth: '500px',
|
|
541
515
|
},
|
|
542
516
|
properties: {
|
|
543
|
-
padding: 0
|
|
517
|
+
padding: 0,
|
|
544
518
|
},
|
|
545
519
|
row: {
|
|
546
520
|
display: 'flex',
|
|
547
|
-
flexDirection: 'space-between'
|
|
521
|
+
flexDirection: 'space-between',
|
|
548
522
|
},
|
|
549
523
|
rowItem: {
|
|
550
|
-
marginRight:
|
|
551
|
-
cursor: 'pointer'
|
|
524
|
+
marginRight: theme.spacing.unit * 1.5,
|
|
525
|
+
cursor: 'pointer',
|
|
552
526
|
},
|
|
553
527
|
active: {
|
|
554
528
|
color: color.primary(),
|
|
555
|
-
borderBottom: `2px solid ${color.primary()}
|
|
529
|
+
borderBottom: `2px solid ${color.primary()}`,
|
|
556
530
|
},
|
|
557
531
|
uploadInput: {
|
|
558
|
-
marginTop:
|
|
532
|
+
marginTop: theme.spacing.unit * 1.5,
|
|
559
533
|
},
|
|
560
534
|
error: {
|
|
561
|
-
marginTop:
|
|
562
|
-
color:
|
|
535
|
+
marginTop: theme.spacing.unit * 1.5,
|
|
536
|
+
color: theme.palette.error.main,
|
|
563
537
|
},
|
|
564
538
|
deleteIcon: {
|
|
565
|
-
marginLeft:
|
|
566
|
-
}
|
|
539
|
+
marginLeft: theme.spacing.unit * 1.5,
|
|
540
|
+
},
|
|
567
541
|
});
|
|
568
542
|
|
|
569
543
|
export default withStyles(styles)(MediaDialog);
|
|
@@ -2,29 +2,29 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { withStyles } from '@material-ui/core/styles';
|
|
4
4
|
|
|
5
|
-
const useStyles = withStyles(theme => ({
|
|
5
|
+
const useStyles = withStyles((theme) => ({
|
|
6
6
|
root: {
|
|
7
7
|
position: 'relative',
|
|
8
8
|
bottom: '5px',
|
|
9
9
|
left: 0,
|
|
10
10
|
width: '100%',
|
|
11
|
-
background:
|
|
11
|
+
background: theme.palette.common.white,
|
|
12
12
|
display: 'inline-flex',
|
|
13
13
|
padding: '5px',
|
|
14
|
-
boxShadow: '0px 4px 4px rgba(0, 0, 0, 0.25)'
|
|
14
|
+
boxShadow: '0px 4px 4px rgba(0, 0, 0, 0.25)',
|
|
15
15
|
},
|
|
16
16
|
editContainer: {
|
|
17
17
|
cursor: 'pointer',
|
|
18
18
|
flex: 3,
|
|
19
|
-
border:
|
|
19
|
+
border: `solid ${theme.palette.common.black}`,
|
|
20
20
|
textAlign: 'right',
|
|
21
21
|
borderWidth: '0 2px 0 0',
|
|
22
22
|
marginRight: '5px',
|
|
23
|
-
paddingRight: '5px'
|
|
23
|
+
paddingRight: '5px',
|
|
24
24
|
},
|
|
25
25
|
removeContainer: {
|
|
26
|
-
cursor: 'pointer'
|
|
27
|
-
}
|
|
26
|
+
cursor: 'pointer',
|
|
27
|
+
},
|
|
28
28
|
}));
|
|
29
29
|
|
|
30
30
|
class MediaToolbar extends React.Component {
|
|
@@ -32,7 +32,7 @@ class MediaToolbar extends React.Component {
|
|
|
32
32
|
classes: PropTypes.object,
|
|
33
33
|
onEdit: PropTypes.func,
|
|
34
34
|
hideEdit: PropTypes.bool,
|
|
35
|
-
onRemove: PropTypes.func
|
|
35
|
+
onRemove: PropTypes.func,
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
render() {
|