@mirrormedia/lilith-draft-editor 1.1.0-alpha.1 → 1.1.0-alpha.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 (72) hide show
  1. package/lib/draft-js/buttons/annotation.js +0 -22
  2. package/lib/draft-js/buttons/audio.js +52 -0
  3. package/lib/draft-js/buttons/background-color.js +0 -26
  4. package/lib/draft-js/buttons/background-image.js +13 -32
  5. package/lib/draft-js/buttons/background-video.js +13 -32
  6. package/lib/draft-js/buttons/color-box.js +5 -21
  7. package/lib/draft-js/buttons/divider.js +3 -12
  8. package/lib/draft-js/buttons/embedded-code.js +5 -16
  9. package/lib/draft-js/buttons/enlarge.js +0 -3
  10. package/lib/draft-js/buttons/font-color.js +0 -26
  11. package/lib/draft-js/buttons/image.js +5 -16
  12. package/lib/draft-js/buttons/info-box.js +5 -21
  13. package/lib/draft-js/buttons/link.js +0 -19
  14. package/lib/draft-js/buttons/media.js +3 -16
  15. package/lib/draft-js/buttons/related-post.js +3 -14
  16. package/lib/draft-js/buttons/selector/align-selector.js +2 -11
  17. package/lib/draft-js/buttons/selector/audio-selector.js +252 -0
  18. package/lib/draft-js/buttons/selector/image-selector.js +6 -50
  19. package/lib/draft-js/buttons/selector/pagination.js +2 -6
  20. package/lib/draft-js/buttons/selector/post-selector.js +6 -39
  21. package/lib/draft-js/buttons/selector/search-box.js +0 -9
  22. package/lib/draft-js/buttons/selector/video-selector.js +4 -33
  23. package/lib/draft-js/buttons/side-index.js +15 -31
  24. package/lib/draft-js/buttons/slideshow.js +7 -16
  25. package/lib/draft-js/buttons/table.js +5 -11
  26. package/lib/draft-js/buttons/text-align.js +0 -14
  27. package/lib/draft-js/buttons/video.js +52 -0
  28. package/lib/draft-js/const.js +0 -2
  29. package/lib/draft-js/draft-converter/api-data-instance.js +0 -14
  30. package/lib/draft-js/draft-converter/atomic-block-processor.js +12 -41
  31. package/lib/draft-js/draft-converter/entities.js +1 -0
  32. package/lib/draft-js/draft-converter/index.js +10 -29
  33. package/lib/draft-js/draft-converter/inline-styles-processor.js +22 -55
  34. package/lib/draft-js/modifier.js +5 -13
  35. package/lib/index.js +0 -4
  36. package/lib/website/mirrormedia/block-renderer/background-image-block.js +2 -14
  37. package/lib/website/mirrormedia/block-renderer/background-video-block.js +2 -14
  38. package/lib/website/mirrormedia/block-renderer/color-box-block.js +2 -14
  39. package/lib/website/mirrormedia/block-renderer/embedded-code-block.js +3 -12
  40. package/lib/website/mirrormedia/block-renderer/info-box-block.js +2 -14
  41. package/lib/website/mirrormedia/block-renderer/side-index-block.js +2 -13
  42. package/lib/website/mirrormedia/block-renderer/slideshow-block.js +4 -11
  43. package/lib/website/mirrormedia/block-renderer/table-block.js +28 -62
  44. package/lib/website/mirrormedia/block-renderer-fn.js +11 -29
  45. package/lib/website/mirrormedia/draft-editor.js +31 -105
  46. package/lib/website/mirrormedia/entity-decorator.js +0 -4
  47. package/lib/website/mirrormedia/index.js +0 -3
  48. package/lib/website/mirrormedia/selector/align-selector.js +2 -11
  49. package/lib/website/mirrormedia/selector/audio-selector.js +252 -0
  50. package/lib/website/mirrormedia/selector/image-selector.js +10 -50
  51. package/lib/website/mirrormedia/selector/pagination.js +2 -6
  52. package/lib/website/mirrormedia/selector/post-selector.js +6 -39
  53. package/lib/website/mirrormedia/selector/search-box.js +0 -9
  54. package/lib/website/mirrormedia/selector/video-selector.js +8 -33
  55. package/lib/website/readr/block-renderer/background-image-block.js +2 -14
  56. package/lib/website/readr/block-renderer/background-video-block.js +2 -14
  57. package/lib/website/readr/block-renderer/color-box-block.js +2 -14
  58. package/lib/website/readr/block-renderer/info-box-block.js +2 -14
  59. package/lib/website/readr/block-renderer/side-index-block.js +2 -13
  60. package/lib/website/readr/block-renderer/table-block.js +28 -62
  61. package/lib/website/readr/block-renderer-fn.js +11 -27
  62. package/lib/website/readr/draft-editor.js +31 -105
  63. package/lib/website/readr/entity-decorator.js +0 -4
  64. package/lib/website/readr/index.js +0 -3
  65. package/lib/website/readr/selector/align-selector.js +2 -11
  66. package/lib/website/readr/selector/audio-selector.js +252 -0
  67. package/lib/website/readr/selector/image-selector.js +10 -50
  68. package/lib/website/readr/selector/pagination.js +2 -6
  69. package/lib/website/readr/selector/post-selector.js +6 -39
  70. package/lib/website/readr/selector/search-box.js +0 -9
  71. package/lib/website/readr/selector/video-selector.js +8 -33
  72. package/package.json +2 -2
@@ -4,49 +4,34 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.TableEditorBlock = void 0;
7
-
8
7
  var _react = _interopRequireWildcard(require("react"));
9
-
10
8
  var _styledComponents = _interopRequireDefault(require("styled-components"));
11
-
12
9
  var _draftJs = require("draft-js");
13
-
14
10
  var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  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
13
  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
14
  const _ = {
23
15
  cloneDeep: _cloneDeep.default
24
16
  };
25
- var ActionType;
26
-
27
- (function (ActionType) {
17
+ var ActionType = /*#__PURE__*/function (ActionType) {
28
18
  ActionType["Insert"] = "insert";
29
19
  ActionType["Delete"] = "delete";
30
20
  ActionType["Update"] = "update";
31
- })(ActionType || (ActionType = {}));
32
-
33
- var TableEnum;
34
-
35
- (function (TableEnum) {
21
+ return ActionType;
22
+ }(ActionType || {});
23
+ var TableEnum = /*#__PURE__*/function (TableEnum) {
36
24
  TableEnum["Row"] = "row";
37
25
  TableEnum["Column"] = "column";
38
- })(TableEnum || (TableEnum = {}));
39
-
26
+ return TableEnum;
27
+ }(TableEnum || {});
40
28
  function createEmptyRow(colLen = 0, emptyValue) {
41
29
  const rtn = [];
42
-
43
30
  for (let i = 0; i < colLen; i++) {
44
31
  rtn.push(emptyValue);
45
32
  }
46
-
47
33
  return rtn;
48
34
  }
49
-
50
35
  function resolveTableStyles(action, tableStyles) {
51
36
  switch (action === null || action === void 0 ? void 0 : action.type) {
52
37
  case ActionType.Insert:
@@ -56,12 +41,10 @@ function resolveTableStyles(action, tableStyles) {
56
41
  return Object.assign({}, tableStyles, {
57
42
  rows
58
43
  });
59
- } // TODO: handle target === TableEnum.Column if needed
60
-
61
-
44
+ }
45
+ // TODO: handle target === TableEnum.Column if needed
62
46
  return tableStyles;
63
47
  }
64
-
65
48
  case ActionType.Delete:
66
49
  {
67
50
  if (action.target === TableEnum.Row) {
@@ -69,75 +52,61 @@ function resolveTableStyles(action, tableStyles) {
69
52
  return Object.assign({}, tableStyles, {
70
53
  rows
71
54
  });
72
- } // TODO: handle target === TableEnum.Column if needed
73
-
74
-
55
+ }
56
+ // TODO: handle target === TableEnum.Column if needed
75
57
  return tableStyles;
76
58
  }
77
59
  // TODO: handle action.type === ActionType.Update if needed
78
-
79
60
  default:
80
61
  {
81
62
  return tableStyles;
82
63
  }
83
64
  }
84
65
  }
85
-
86
66
  function resolveTableData(action, tableData) {
87
67
  switch (action === null || action === void 0 ? void 0 : action.type) {
88
68
  case ActionType.Insert:
89
69
  {
90
70
  var _tableData$;
91
-
92
71
  if (typeof (action === null || action === void 0 ? void 0 : action.index) !== 'number') {
93
72
  return tableData;
94
73
  }
95
-
96
74
  if ((action === null || action === void 0 ? void 0 : action.target) === TableEnum.Column) {
97
75
  // add the new column at specific position in each row
98
76
  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
-
77
+ }
78
+ // add the new row
102
79
  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
80
  }
104
-
105
81
  case ActionType.Delete:
106
82
  {
107
83
  if (typeof (action === null || action === void 0 ? void 0 : action.index) !== 'number') {
108
84
  return tableData;
109
85
  }
110
-
111
86
  if ((action === null || action === void 0 ? void 0 : action.target) === 'column') {
112
87
  // delete the column at specific position in each row
113
88
  return tableData.map(r => [...r.slice(0, action.index), ...r.slice(action.index + 1)]);
114
- } // delete the column
115
-
116
-
89
+ }
90
+ // delete the column
117
91
  return [...tableData.slice(0, action.index), ...tableData.slice(action.index + 1)];
118
92
  }
119
-
120
93
  case ActionType.Update:
121
94
  {
122
95
  // The reason we copy the array is to make sure
123
96
  // that React component re-renders.
124
97
  const copiedData = [...tableData];
125
-
126
98
  if (typeof (action === null || action === void 0 ? void 0 : action.rIndex) !== 'number' || typeof (action === null || action === void 0 ? void 0 : action.cIndex) !== 'number') {
127
99
  return copiedData;
128
100
  }
129
-
130
101
  copiedData[action.rIndex][action.cIndex] = action === null || action === void 0 ? void 0 : action.value;
131
102
  return copiedData;
132
103
  }
133
-
134
104
  default:
135
105
  {
136
106
  return tableData;
137
107
  }
138
108
  }
139
109
  }
140
-
141
110
  function convertTableDataFromRaw(rawTableData) {
142
111
  return rawTableData.map(rowData => {
143
112
  return rowData.map(colData => {
@@ -146,7 +115,6 @@ function convertTableDataFromRaw(rawTableData) {
146
115
  });
147
116
  });
148
117
  }
149
-
150
118
  function convertTableDataToRaw(tableData) {
151
119
  return tableData.map(rowData => {
152
120
  return rowData.map(colData => {
@@ -154,7 +122,6 @@ function convertTableDataToRaw(tableData) {
154
122
  });
155
123
  });
156
124
  }
157
-
158
125
  const Table = _styledComponents.default.div`
159
126
  display: table;
160
127
  width: 95%;
@@ -255,10 +222,8 @@ const TableBlockContainer = _styledComponents.default.div`
255
222
  overflow: scroll;
256
223
  padding: 15px;
257
224
  `;
258
-
259
225
  const TableEditorBlock = props => {
260
226
  var _tableData$2;
261
-
262
227
  const {
263
228
  block,
264
229
  blockProps,
@@ -275,24 +240,26 @@ const TableEditorBlock = props => {
275
240
  tableData: rawTableData,
276
241
  tableStyles: _tableStyles
277
242
  } = entity.getData();
278
- const [tableData, setTableData] = (0, _react.useState)(convertTableDataFromRaw(rawTableData)); // deep clone `_tableStyles` to prevent updating the entity data directly
279
-
243
+ const [tableData, setTableData] = (0, _react.useState)(convertTableDataFromRaw(rawTableData));
244
+ // deep clone `_tableStyles` to prevent updating the entity data directly
280
245
  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.
246
+ const tableRef = (0, _react.useRef)(null);
247
+
248
+ // `TableBlock` will render other inner/nested DraftJS Editors inside the main Editor.
282
249
  // However, main Editor's `readOnly` needs to be mutually exclusive with nested Editors' `readOnly`.
283
250
  // If the main Editor and nested Editor are editable (`readOnly={false}`) at the same time,
284
251
  // there will be a DraftJS Edtior Selection bug.
252
+ const [cellEditorReadOnly, setCellEditorReadOnly] = (0, _react.useState)(!getMainEditorReadOnly());
285
253
 
286
- const [cellEditorReadOnly, setCellEditorReadOnly] = (0, _react.useState)(!getMainEditorReadOnly()); // The user clicks the table for editing
287
-
254
+ // The user clicks the table for editing
288
255
  const onTableClick = () => {
289
256
  // call `onEditStart` function to tell the main DraftJS Editor
290
257
  // that we are going to interact with the custom atomic block.
291
- onEditStart(); // make nested DraftJS Editors editable
258
+ onEditStart();
292
259
 
260
+ // make nested DraftJS Editors editable
293
261
  setCellEditorReadOnly(false);
294
262
  };
295
-
296
263
  (0, _react.useEffect)(() => {
297
264
  // The user clicks other places except the table,
298
265
  // so we think he/she doesn't want to edit the table anymore.
@@ -304,9 +271,10 @@ const TableEditorBlock = props => {
304
271
  // this `handleClickOutside` will only handle the just updated one.
305
272
  if (tableRef.current && !tableRef.current.contains(event.target) && !cellEditorReadOnly) {
306
273
  // 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.
274
+ setCellEditorReadOnly(true);
309
275
 
276
+ // call `onEditFinish` function tell the main DraftJS Editor
277
+ // that we are finishing interacting with the custom atomic block.
310
278
  onEditFinish({
311
279
  entityKey,
312
280
  entityData: {
@@ -316,7 +284,6 @@ const TableEditorBlock = props => {
316
284
  });
317
285
  }
318
286
  }
319
-
320
287
  console.debug('(rich-text-editor/table): add click outside event listener');
321
288
  document.addEventListener('mousedown', handleClickOutside);
322
289
  return () => {
@@ -324,7 +291,8 @@ const TableEditorBlock = props => {
324
291
  console.debug('(rich-text-editor/table): remove click outside event listener');
325
292
  document.removeEventListener('mousedown', handleClickOutside);
326
293
  };
327
- }, // Skip running effect if `tableData` and `cellEditorReadOnly` are not changed.
294
+ },
295
+ // Skip running effect if `tableData` and `cellEditorReadOnly` are not changed.
328
296
  [tableData, cellEditorReadOnly]);
329
297
  return /*#__PURE__*/_react.default.createElement(TableBlockContainer, null, /*#__PURE__*/_react.default.createElement(Table, {
330
298
  key: entityKey,
@@ -356,7 +324,6 @@ const TableEditorBlock = props => {
356
324
  }));
357
325
  })), tableData.map((rowData, rIndex) => {
358
326
  var _tableStyles$rows;
359
-
360
327
  const colsJsx = rowData.map((colData, cIndex) => {
361
328
  return /*#__PURE__*/_react.default.createElement(Td, {
362
329
  key: `col_${cIndex}`
@@ -404,5 +371,4 @@ const TableEditorBlock = props => {
404
371
  })), colsJsx));
405
372
  })));
406
373
  };
407
-
408
374
  exports.TableEditorBlock = TableEditorBlock;
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.atomicBlockRenderer = atomicBlockRenderer;
7
-
8
7
  var _infoBoxBlock = require("./block-renderer/info-box-block");
9
-
10
8
  var _tableBlock = require("./block-renderer/table-block");
11
-
12
9
  var _colorBoxBlock = require("./block-renderer/color-box-block");
13
-
14
10
  var _backgroundImageBlock = require("./block-renderer/background-image-block");
15
-
16
11
  var _backgroundVideoBlock = require("./block-renderer/background-video-block");
17
-
18
12
  var _sideIndexBlock = require("./block-renderer/side-index-block");
19
-
20
13
  var _readr = _interopRequireDefault(require("@mirrormedia/lilith-draft-renderer/lib/website/readr"));
21
-
22
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
15
  const {
25
16
  EmbeddedCodeBlock,
26
17
  MediaBlock,
@@ -28,13 +19,13 @@ const {
28
19
  SlideshowBlock,
29
20
  SlideshowBlockV2,
30
21
  DividerBlock,
31
- RelatedPostBlock
22
+ RelatedPostBlock,
23
+ VideoBlock,
24
+ AudioBlock
32
25
  } = _readr.default.blockRenderers;
33
-
34
26
  const AtomicBlock = props => {
35
27
  const entity = props.contentState.getEntity(props.block.getEntityAt(0));
36
28
  const entityType = entity.getType();
37
-
38
29
  switch (entityType) {
39
30
  case 'audioLink':
40
31
  case 'imageLink':
@@ -42,71 +33,65 @@ const AtomicBlock = props => {
42
33
  {
43
34
  return MediaBlock(entity);
44
35
  }
45
-
46
36
  case 'image':
47
37
  {
48
38
  return ImageBlock(entity);
49
39
  }
50
-
51
40
  case 'slideshow':
52
41
  {
53
42
  return SlideshowBlock(entity);
54
43
  }
55
-
56
44
  case 'slideshow-v2':
57
45
  {
58
46
  return SlideshowBlockV2(entity);
59
47
  }
60
-
61
48
  case 'EMBEDDEDCODE':
62
49
  {
63
50
  return EmbeddedCodeBlock(entity);
64
51
  }
65
-
66
52
  case 'INFOBOX':
67
53
  {
68
54
  return (0, _infoBoxBlock.InfoBoxEditorBlock)(props);
69
55
  }
70
-
71
56
  case 'DIVIDER':
72
57
  {
73
58
  return DividerBlock();
74
59
  }
75
-
76
60
  case 'TABLE':
77
61
  {
78
62
  return (0, _tableBlock.TableEditorBlock)(props);
79
63
  }
80
-
81
64
  case 'COLORBOX':
82
65
  {
83
66
  return (0, _colorBoxBlock.ColorBoxEditorBlock)(props);
84
67
  }
85
-
86
68
  case 'BACKGROUNDIMAGE':
87
69
  {
88
70
  return (0, _backgroundImageBlock.BGImageEditorBlock)(props);
89
71
  }
90
-
91
72
  case 'BACKGROUNDVIDEO':
92
73
  {
93
74
  return (0, _backgroundVideoBlock.BGVideoEditorBlock)(props);
94
75
  }
95
-
96
76
  case 'RELATEDPOST':
97
77
  {
98
78
  return RelatedPostBlock(entity);
99
79
  }
100
-
101
80
  case 'SIDEINDEX':
102
81
  {
103
82
  return (0, _sideIndexBlock.SideIndexEditorBlock)(props);
104
83
  }
84
+ case 'VIDEO':
85
+ {
86
+ return VideoBlock(entity);
87
+ }
88
+ case 'AudioBlock':
89
+ {
90
+ return AudioBlock(entity);
91
+ }
105
92
  }
106
-
107
93
  return null;
108
94
  };
109
-
110
95
  function atomicBlockRenderer(block) {
111
96
  if (block.getType() === 'atomic') {
112
97
  return {
@@ -114,6 +99,5 @@ function atomicBlockRenderer(block) {
114
99
  editable: false
115
100
  };
116
101
  }
117
-
118
102
  return null;
119
103
  }