@kids-reporter/draft-editor 0.1.1 → 0.2.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.
- package/lib/buttons/annotation.js +1 -14
- package/lib/buttons/image.js +0 -3
- package/lib/buttons/info-box.js +1 -4
- package/lib/draft-editor.js +61 -363
- package/package.json +7 -2
- package/lib/block-renderer/background-image-block.js +0 -141
- package/lib/block-renderer/background-video-block.js +0 -151
- package/lib/block-renderer/color-box-block.js +0 -86
- package/lib/block-renderer/info-box-block.js +0 -86
- package/lib/block-renderer/side-index-block.js +0 -90
- package/lib/block-renderer/table-block.js +0 -408
- package/lib/block-renderer-fn.js +0 -125
- package/lib/buttons/audio.js +0 -65
- package/lib/buttons/background-color.js +0 -122
- package/lib/buttons/background-image.js +0 -223
- package/lib/buttons/background-video.js +0 -223
- package/lib/buttons/color-box.js +0 -173
- package/lib/buttons/divider.js +0 -63
- package/lib/buttons/font-color.js +0 -115
- package/lib/buttons/media.js +0 -121
- package/lib/buttons/related-post.js +0 -71
- package/lib/buttons/selector/audio-selector.js +0 -279
- package/lib/buttons/selector/post-selector.js +0 -317
- package/lib/buttons/selector/video-selector.js +0 -281
- package/lib/buttons/side-index.js +0 -200
- package/lib/buttons/table.js +0 -67
- package/lib/buttons/text-align.js +0 -88
- package/lib/buttons/video.js +0 -65
- package/lib/buttons/youtube.js +0 -147
- package/lib/const.js +0 -18
- package/lib/draft-converter/api-data-instance.js +0 -58
- package/lib/draft-converter/atomic-block-processor.js +0 -233
- package/lib/draft-converter/entities.js +0 -76
- package/lib/draft-converter/index.js +0 -201
- package/lib/draft-converter/inline-styles-processor.js +0 -236
- package/lib/entity-decorator.js +0 -20
- package/lib/modifier.js +0 -68
- package/lib/theme/index.js +0 -39
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TableEditorBlock = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
-
|
|
12
|
-
var _draftJs = require("draft-js");
|
|
13
|
-
|
|
14
|
-
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
|
-
const _ = {
|
|
23
|
-
cloneDeep: _cloneDeep.default
|
|
24
|
-
};
|
|
25
|
-
var ActionType;
|
|
26
|
-
|
|
27
|
-
(function (ActionType) {
|
|
28
|
-
ActionType["Insert"] = "insert";
|
|
29
|
-
ActionType["Delete"] = "delete";
|
|
30
|
-
ActionType["Update"] = "update";
|
|
31
|
-
})(ActionType || (ActionType = {}));
|
|
32
|
-
|
|
33
|
-
var TableEnum;
|
|
34
|
-
|
|
35
|
-
(function (TableEnum) {
|
|
36
|
-
TableEnum["Row"] = "row";
|
|
37
|
-
TableEnum["Column"] = "column";
|
|
38
|
-
})(TableEnum || (TableEnum = {}));
|
|
39
|
-
|
|
40
|
-
function createEmptyRow(colLen = 0, emptyValue) {
|
|
41
|
-
const rtn = [];
|
|
42
|
-
|
|
43
|
-
for (let i = 0; i < colLen; i++) {
|
|
44
|
-
rtn.push(emptyValue);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return rtn;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function resolveTableStyles(action, tableStyles) {
|
|
51
|
-
switch (action === null || action === void 0 ? void 0 : action.type) {
|
|
52
|
-
case ActionType.Insert:
|
|
53
|
-
{
|
|
54
|
-
if (action.target === TableEnum.Row) {
|
|
55
|
-
const rows = [...tableStyles.rows.slice(0, action.index), {}, ...tableStyles.rows.slice(action.index)];
|
|
56
|
-
return Object.assign({}, tableStyles, {
|
|
57
|
-
rows
|
|
58
|
-
});
|
|
59
|
-
} // TODO: handle target === TableEnum.Column if needed
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return tableStyles;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
case ActionType.Delete:
|
|
66
|
-
{
|
|
67
|
-
if (action.target === TableEnum.Row) {
|
|
68
|
-
const rows = [...tableStyles.rows.slice(0, action.index), ...tableStyles.rows.slice(action.index + 1)];
|
|
69
|
-
return Object.assign({}, tableStyles, {
|
|
70
|
-
rows
|
|
71
|
-
});
|
|
72
|
-
} // TODO: handle target === TableEnum.Column if needed
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return tableStyles;
|
|
76
|
-
}
|
|
77
|
-
// TODO: handle action.type === ActionType.Update if needed
|
|
78
|
-
|
|
79
|
-
default:
|
|
80
|
-
{
|
|
81
|
-
return tableStyles;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function resolveTableData(action, tableData) {
|
|
87
|
-
switch (action === null || action === void 0 ? void 0 : action.type) {
|
|
88
|
-
case ActionType.Insert:
|
|
89
|
-
{
|
|
90
|
-
var _tableData$;
|
|
91
|
-
|
|
92
|
-
if (typeof (action === null || action === void 0 ? void 0 : action.index) !== 'number') {
|
|
93
|
-
return tableData;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if ((action === null || action === void 0 ? void 0 : action.target) === TableEnum.Column) {
|
|
97
|
-
// add the new column at specific position in each row
|
|
98
|
-
return tableData.map(r => [...r.slice(0, action === null || action === void 0 ? void 0 : action.index), _draftJs.EditorState.createEmpty(), ...r.slice(action === null || action === void 0 ? void 0 : action.index)]);
|
|
99
|
-
} // add the new row
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return [...tableData.slice(0, action === null || action === void 0 ? void 0 : action.index), createEmptyRow(tableData === null || tableData === void 0 ? void 0 : (_tableData$ = tableData[0]) === null || _tableData$ === void 0 ? void 0 : _tableData$.length, _draftJs.EditorState.createEmpty()), ...tableData.slice(action === null || action === void 0 ? void 0 : action.index)];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
case ActionType.Delete:
|
|
106
|
-
{
|
|
107
|
-
if (typeof (action === null || action === void 0 ? void 0 : action.index) !== 'number') {
|
|
108
|
-
return tableData;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if ((action === null || action === void 0 ? void 0 : action.target) === 'column') {
|
|
112
|
-
// delete the column at specific position in each row
|
|
113
|
-
return tableData.map(r => [...r.slice(0, action.index), ...r.slice(action.index + 1)]);
|
|
114
|
-
} // delete the column
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return [...tableData.slice(0, action.index), ...tableData.slice(action.index + 1)];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
case ActionType.Update:
|
|
121
|
-
{
|
|
122
|
-
// The reason we copy the array is to make sure
|
|
123
|
-
// that React component re-renders.
|
|
124
|
-
const copiedData = [...tableData];
|
|
125
|
-
|
|
126
|
-
if (typeof (action === null || action === void 0 ? void 0 : action.rIndex) !== 'number' || typeof (action === null || action === void 0 ? void 0 : action.cIndex) !== 'number') {
|
|
127
|
-
return copiedData;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
copiedData[action.rIndex][action.cIndex] = action === null || action === void 0 ? void 0 : action.value;
|
|
131
|
-
return copiedData;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
default:
|
|
135
|
-
{
|
|
136
|
-
return tableData;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function convertTableDataFromRaw(rawTableData) {
|
|
142
|
-
return rawTableData.map(rowData => {
|
|
143
|
-
return rowData.map(colData => {
|
|
144
|
-
const contentState = (0, _draftJs.convertFromRaw)(colData);
|
|
145
|
-
return _draftJs.EditorState.createWithContent(contentState);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function convertTableDataToRaw(tableData) {
|
|
151
|
-
return tableData.map(rowData => {
|
|
152
|
-
return rowData.map(colData => {
|
|
153
|
-
return (0, _draftJs.convertToRaw)(colData.getCurrentContent());
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const Table = _styledComponents.default.div`
|
|
159
|
-
display: table;
|
|
160
|
-
width: 95%;
|
|
161
|
-
border-collapse: collapse;
|
|
162
|
-
`;
|
|
163
|
-
const Tr = _styledComponents.default.div`
|
|
164
|
-
display: table-row;
|
|
165
|
-
`;
|
|
166
|
-
const Td = _styledComponents.default.div`
|
|
167
|
-
display: table-cell;
|
|
168
|
-
border-width: 1px;
|
|
169
|
-
min-width: 100px;
|
|
170
|
-
min-height: 40px;
|
|
171
|
-
padding: 10px;
|
|
172
|
-
`;
|
|
173
|
-
const StyledFirstRow = _styledComponents.default.div`
|
|
174
|
-
display: table-row;
|
|
175
|
-
height: 10px;
|
|
176
|
-
|
|
177
|
-
div {
|
|
178
|
-
display: table-cell;
|
|
179
|
-
position: relative;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
span {
|
|
183
|
-
cursor: pointer;
|
|
184
|
-
line-height: 10px;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
span:first-child {
|
|
188
|
-
position: absolute;
|
|
189
|
-
right: 50%;
|
|
190
|
-
transform: translateX(50%);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
span:first-child:before {
|
|
194
|
-
content: '•';
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
span:first-child:hover:before {
|
|
198
|
-
content: '➖';
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
span:last-child {
|
|
202
|
-
position: absolute;
|
|
203
|
-
right: -5px;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
span:last-child:before {
|
|
207
|
-
content: '•';
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
span:last-child:hover:before {
|
|
211
|
-
content: '➕';
|
|
212
|
-
}
|
|
213
|
-
`;
|
|
214
|
-
const StyledFirstColumn = _styledComponents.default.div`
|
|
215
|
-
display: table-cell;
|
|
216
|
-
width: 10px;
|
|
217
|
-
position: relative;
|
|
218
|
-
|
|
219
|
-
span {
|
|
220
|
-
cursor: pointer;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
span:first-child {
|
|
224
|
-
position: absolute;
|
|
225
|
-
bottom: 50%;
|
|
226
|
-
right: 0px;
|
|
227
|
-
transform: translateY(50%);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
span:first-child:before {
|
|
231
|
-
content: '•';
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
span:first-child:hover:before {
|
|
235
|
-
content: '➖';
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
span:last-child {
|
|
239
|
-
position: absolute;
|
|
240
|
-
bottom: -10px;
|
|
241
|
-
right: 0px;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
span:last-child:before {
|
|
245
|
-
content: '•';
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
span:last-child:hover:before {
|
|
249
|
-
content: '➕';
|
|
250
|
-
}
|
|
251
|
-
`;
|
|
252
|
-
const TableBlockContainer = _styledComponents.default.div`
|
|
253
|
-
margin: 15px 0;
|
|
254
|
-
position: relative;
|
|
255
|
-
overflow: scroll;
|
|
256
|
-
padding: 15px;
|
|
257
|
-
`;
|
|
258
|
-
|
|
259
|
-
const TableEditorBlock = props => {
|
|
260
|
-
var _tableData$2;
|
|
261
|
-
|
|
262
|
-
const {
|
|
263
|
-
block,
|
|
264
|
-
blockProps,
|
|
265
|
-
contentState
|
|
266
|
-
} = props;
|
|
267
|
-
const {
|
|
268
|
-
onEditStart,
|
|
269
|
-
onEditFinish,
|
|
270
|
-
getMainEditorReadOnly
|
|
271
|
-
} = blockProps;
|
|
272
|
-
const entityKey = block.getEntityAt(0);
|
|
273
|
-
const entity = contentState.getEntity(entityKey);
|
|
274
|
-
const {
|
|
275
|
-
tableData: rawTableData,
|
|
276
|
-
tableStyles: _tableStyles
|
|
277
|
-
} = entity.getData();
|
|
278
|
-
const [tableData, setTableData] = (0, _react.useState)(convertTableDataFromRaw(rawTableData)); // deep clone `_tableStyles` to prevent updating the entity data directly
|
|
279
|
-
|
|
280
|
-
const [tableStyles, setTableStyles] = (0, _react.useState)(_.cloneDeep(_tableStyles));
|
|
281
|
-
const tableRef = (0, _react.useRef)(null); // `TableBlock` will render other inner/nested DraftJS Editors inside the main Editor.
|
|
282
|
-
// However, main Editor's `readOnly` needs to be mutually exclusive with nested Editors' `readOnly`.
|
|
283
|
-
// If the main Editor and nested Editor are editable (`readOnly={false}`) at the same time,
|
|
284
|
-
// there will be a DraftJS Edtior Selection bug.
|
|
285
|
-
|
|
286
|
-
const [cellEditorReadOnly, setCellEditorReadOnly] = (0, _react.useState)(!getMainEditorReadOnly()); // The user clicks the table for editing
|
|
287
|
-
|
|
288
|
-
const onTableClick = () => {
|
|
289
|
-
// call `onEditStart` function to tell the main DraftJS Editor
|
|
290
|
-
// that we are going to interact with the custom atomic block.
|
|
291
|
-
onEditStart(); // make nested DraftJS Editors editable
|
|
292
|
-
|
|
293
|
-
setCellEditorReadOnly(false);
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
(0, _react.useEffect)(() => {
|
|
297
|
-
// The user clicks other places except the table,
|
|
298
|
-
// so we think he/she doesn't want to edit the table anymore.
|
|
299
|
-
// Therefore, we call `onEditFinish` function to pass modified table data
|
|
300
|
-
// back to the main DraftJS Edtior.
|
|
301
|
-
function handleClickOutside(event) {
|
|
302
|
-
// `!cellEditorReadOnly` condition is needed.
|
|
303
|
-
// If there are two tables in the main Editor,
|
|
304
|
-
// this `handleClickOutside` will only handle the just updated one.
|
|
305
|
-
if (tableRef.current && !tableRef.current.contains(event.target) && !cellEditorReadOnly) {
|
|
306
|
-
// make inner DraftJS Editors NOT editable
|
|
307
|
-
setCellEditorReadOnly(true); // call `onEditFinish` function tell the main DraftJS Editor
|
|
308
|
-
// that we are finishing interacting with the custom atomic block.
|
|
309
|
-
|
|
310
|
-
onEditFinish({
|
|
311
|
-
entityKey,
|
|
312
|
-
entityData: {
|
|
313
|
-
tableData: convertTableDataToRaw(tableData),
|
|
314
|
-
tableStyles
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
console.debug('(rich-text-editor/table): add click outside event listener');
|
|
321
|
-
document.addEventListener('mousedown', handleClickOutside);
|
|
322
|
-
return () => {
|
|
323
|
-
// Unbind the event listener on clean up
|
|
324
|
-
console.debug('(rich-text-editor/table): remove click outside event listener');
|
|
325
|
-
document.removeEventListener('mousedown', handleClickOutside);
|
|
326
|
-
};
|
|
327
|
-
}, // Skip running effect if `tableData` and `cellEditorReadOnly` are not changed.
|
|
328
|
-
[tableData, cellEditorReadOnly]);
|
|
329
|
-
return /*#__PURE__*/_react.default.createElement(TableBlockContainer, null, /*#__PURE__*/_react.default.createElement(Table, {
|
|
330
|
-
key: entityKey,
|
|
331
|
-
onClick: onTableClick,
|
|
332
|
-
ref: tableRef
|
|
333
|
-
}, /*#__PURE__*/_react.default.createElement(StyledFirstRow, null, /*#__PURE__*/_react.default.createElement("div", null), tableData === null || tableData === void 0 ? void 0 : (_tableData$2 = tableData[0]) === null || _tableData$2 === void 0 ? void 0 : _tableData$2.map((colData, cIndex) => {
|
|
334
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
335
|
-
key: `col_${cIndex + 1}`
|
|
336
|
-
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
337
|
-
onClick: () => {
|
|
338
|
-
const deleteColumn = {
|
|
339
|
-
type: ActionType.Delete,
|
|
340
|
-
target: TableEnum.Column,
|
|
341
|
-
index: cIndex
|
|
342
|
-
};
|
|
343
|
-
const updatedTableData = resolveTableData(deleteColumn, tableData);
|
|
344
|
-
setTableData(updatedTableData);
|
|
345
|
-
}
|
|
346
|
-
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
347
|
-
onClick: () => {
|
|
348
|
-
const insertColumn = {
|
|
349
|
-
type: ActionType.Insert,
|
|
350
|
-
target: TableEnum.Column,
|
|
351
|
-
index: cIndex + 1
|
|
352
|
-
};
|
|
353
|
-
const updatedTableData = resolveTableData(insertColumn, tableData);
|
|
354
|
-
setTableData(updatedTableData);
|
|
355
|
-
}
|
|
356
|
-
}));
|
|
357
|
-
})), tableData.map((rowData, rIndex) => {
|
|
358
|
-
var _tableStyles$rows;
|
|
359
|
-
|
|
360
|
-
const colsJsx = rowData.map((colData, cIndex) => {
|
|
361
|
-
return /*#__PURE__*/_react.default.createElement(Td, {
|
|
362
|
-
key: `col_${cIndex}`
|
|
363
|
-
}, /*#__PURE__*/_react.default.createElement(_draftJs.Editor, {
|
|
364
|
-
onChange: editorState => {
|
|
365
|
-
const updateAction = {
|
|
366
|
-
type: ActionType.Update,
|
|
367
|
-
cIndex,
|
|
368
|
-
rIndex,
|
|
369
|
-
value: editorState
|
|
370
|
-
};
|
|
371
|
-
const updatedTableData = resolveTableData(updateAction, tableData);
|
|
372
|
-
setTableData(updatedTableData);
|
|
373
|
-
},
|
|
374
|
-
editorState: colData,
|
|
375
|
-
readOnly: cellEditorReadOnly
|
|
376
|
-
}));
|
|
377
|
-
});
|
|
378
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
379
|
-
key: `row_${rIndex}`
|
|
380
|
-
}, /*#__PURE__*/_react.default.createElement(Tr, {
|
|
381
|
-
style: tableStyles === null || tableStyles === void 0 ? void 0 : (_tableStyles$rows = tableStyles.rows) === null || _tableStyles$rows === void 0 ? void 0 : _tableStyles$rows[rIndex]
|
|
382
|
-
}, /*#__PURE__*/_react.default.createElement(StyledFirstColumn, null, /*#__PURE__*/_react.default.createElement("span", {
|
|
383
|
-
onClick: () => {
|
|
384
|
-
const deleteRowAction = {
|
|
385
|
-
type: ActionType.Delete,
|
|
386
|
-
target: TableEnum.Row,
|
|
387
|
-
index: rIndex
|
|
388
|
-
};
|
|
389
|
-
const updatedTableData = resolveTableData(deleteRowAction, tableData);
|
|
390
|
-
setTableData(updatedTableData);
|
|
391
|
-
setTableStyles(resolveTableStyles(deleteRowAction, tableStyles));
|
|
392
|
-
}
|
|
393
|
-
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
394
|
-
onClick: () => {
|
|
395
|
-
const addRowAction = {
|
|
396
|
-
type: ActionType.Insert,
|
|
397
|
-
target: TableEnum.Row,
|
|
398
|
-
index: rIndex + 1
|
|
399
|
-
};
|
|
400
|
-
const updatedTableData = resolveTableData(addRowAction, tableData);
|
|
401
|
-
setTableData(updatedTableData);
|
|
402
|
-
setTableStyles(resolveTableStyles(addRowAction, tableStyles));
|
|
403
|
-
}
|
|
404
|
-
})), colsJsx));
|
|
405
|
-
})));
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
exports.TableEditorBlock = TableEditorBlock;
|
package/lib/block-renderer-fn.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.atomicBlockRenderer = atomicBlockRenderer;
|
|
7
|
-
|
|
8
|
-
var _infoBoxBlock = require("./block-renderer/info-box-block");
|
|
9
|
-
|
|
10
|
-
var _tableBlock = require("./block-renderer/table-block");
|
|
11
|
-
|
|
12
|
-
var _colorBoxBlock = require("./block-renderer/color-box-block");
|
|
13
|
-
|
|
14
|
-
var _backgroundImageBlock = require("./block-renderer/background-image-block");
|
|
15
|
-
|
|
16
|
-
var _backgroundVideoBlock = require("./block-renderer/background-video-block");
|
|
17
|
-
|
|
18
|
-
var _sideIndexBlock = require("./block-renderer/side-index-block");
|
|
19
|
-
|
|
20
|
-
var _draftRenderer = _interopRequireDefault(require("@kids-reporter/draft-renderer"));
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
const {
|
|
25
|
-
EmbeddedCodeBlock,
|
|
26
|
-
MediaBlock,
|
|
27
|
-
ImageBlock,
|
|
28
|
-
SlideshowBlock,
|
|
29
|
-
DividerBlock,
|
|
30
|
-
RelatedPostBlock,
|
|
31
|
-
VideoBlock,
|
|
32
|
-
AudioBlock
|
|
33
|
-
} = _draftRenderer.default.blockRenderers;
|
|
34
|
-
|
|
35
|
-
const AtomicBlock = props => {
|
|
36
|
-
const entity = props.contentState.getEntity(props.block.getEntityAt(0));
|
|
37
|
-
const entityType = entity.getType();
|
|
38
|
-
|
|
39
|
-
switch (entityType) {
|
|
40
|
-
case 'audioLink':
|
|
41
|
-
case 'imageLink':
|
|
42
|
-
case 'videoLink':
|
|
43
|
-
{
|
|
44
|
-
return MediaBlock(entity);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
case 'image':
|
|
48
|
-
{
|
|
49
|
-
return ImageBlock(entity);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
case 'slideshow':
|
|
53
|
-
{
|
|
54
|
-
return SlideshowBlock(entity);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
case 'EMBEDDEDCODE':
|
|
58
|
-
{
|
|
59
|
-
return EmbeddedCodeBlock(entity);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
case 'INFOBOX':
|
|
63
|
-
{
|
|
64
|
-
return (0, _infoBoxBlock.InfoBoxEditorBlock)(props);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
case 'DIVIDER':
|
|
68
|
-
{
|
|
69
|
-
return DividerBlock();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
case 'TABLE':
|
|
73
|
-
{
|
|
74
|
-
return (0, _tableBlock.TableEditorBlock)(props);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
case 'COLORBOX':
|
|
78
|
-
{
|
|
79
|
-
return (0, _colorBoxBlock.ColorBoxEditorBlock)(props);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
case 'BACKGROUNDIMAGE':
|
|
83
|
-
{
|
|
84
|
-
return (0, _backgroundImageBlock.BGImageEditorBlock)(props);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
case 'BACKGROUNDVIDEO':
|
|
88
|
-
{
|
|
89
|
-
return (0, _backgroundVideoBlock.BGVideoEditorBlock)(props);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
case 'RELATEDPOST':
|
|
93
|
-
{
|
|
94
|
-
return RelatedPostBlock(entity);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
case 'SIDEINDEX':
|
|
98
|
-
{
|
|
99
|
-
return (0, _sideIndexBlock.SideIndexEditorBlock)(props);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
case 'VIDEO':
|
|
103
|
-
{
|
|
104
|
-
return VideoBlock(entity);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
case 'AUDIO':
|
|
108
|
-
{
|
|
109
|
-
return AudioBlock(entity);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return null;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
function atomicBlockRenderer(block) {
|
|
117
|
-
if (block.getType() === 'atomic') {
|
|
118
|
-
return {
|
|
119
|
-
component: AtomicBlock,
|
|
120
|
-
editable: false
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return null;
|
|
125
|
-
}
|
package/lib/buttons/audio.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AudioButton = AudioButton;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _draftJs = require("draft-js");
|
|
11
|
-
|
|
12
|
-
var _audioSelector = require("./selector/audio-selector");
|
|
13
|
-
|
|
14
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
-
|
|
16
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
|
-
function AudioButton(props) {
|
|
19
|
-
const {
|
|
20
|
-
editorState,
|
|
21
|
-
onChange,
|
|
22
|
-
className,
|
|
23
|
-
AudioSelector = _audioSelector.AudioSelector
|
|
24
|
-
} = props;
|
|
25
|
-
const [toShowAudioSelector, setToShowAudioSelector] = (0, _react.useState)(false);
|
|
26
|
-
|
|
27
|
-
const promptForAudioSelector = () => {
|
|
28
|
-
setToShowAudioSelector(true);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const onAudioSelectorChange = selectedAudiosWithMeta => {
|
|
32
|
-
var _selectedAudiosWithMe;
|
|
33
|
-
|
|
34
|
-
const audio = selectedAudiosWithMeta === null || selectedAudiosWithMeta === void 0 ? void 0 : (_selectedAudiosWithMe = selectedAudiosWithMeta[0]) === null || _selectedAudiosWithMe === void 0 ? void 0 : _selectedAudiosWithMe.audio;
|
|
35
|
-
|
|
36
|
-
if (!audio) {
|
|
37
|
-
setToShowAudioSelector(false);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const contentState = editorState.getCurrentContent();
|
|
42
|
-
const contentStateWithEntity = contentState.createEntity('AUDIO', 'IMMUTABLE', {
|
|
43
|
-
audio
|
|
44
|
-
});
|
|
45
|
-
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
|
|
46
|
-
|
|
47
|
-
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
48
|
-
currentContent: contentStateWithEntity
|
|
49
|
-
}); // The third parameter here is a space string, not an empty string
|
|
50
|
-
// If you set an empty string, you will get an error: Unknown DraftEntity key: null
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
onChange(_draftJs.AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, ' '));
|
|
54
|
-
setToShowAudioSelector(false);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, toShowAudioSelector && /*#__PURE__*/_react.default.createElement(AudioSelector, {
|
|
58
|
-
onChange: onAudioSelectorChange
|
|
59
|
-
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
60
|
-
className: className,
|
|
61
|
-
onClick: promptForAudioSelector
|
|
62
|
-
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
63
|
-
className: "fa fa-file-audio"
|
|
64
|
-
}), /*#__PURE__*/_react.default.createElement("span", null, " Audio")));
|
|
65
|
-
}
|