hero-editor 1.9.25 → 1.11.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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "hero-editor",
3
- "version": "1.9.25",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "main": "dist/lib.js",
6
6
  "scripts": {
7
- "build:lib": "webpack --config webpack.lib.js",
8
- "build:app": "webpack --config webpack.app.js",
9
- "dev": "webpack --config webpack.dev.js --watch",
7
+ "build:lib": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack --config webpack.lib.js",
8
+ "build:app": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack --config webpack.app.js",
9
+ "dev": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack --config webpack.dev.js --watch",
10
10
  "build": "yarn build:lib && yarn build:app",
11
11
  "test": "jest --verbose"
12
12
  },
@@ -32,8 +32,9 @@
32
32
  "dependencies": {
33
33
  "@juggle/resize-observer": "^3.4.0",
34
34
  "is-url": "^1.2.4",
35
- "slate": "0.94.1",
36
- "slate-react": "0.98.1"
35
+ "slate": "0.101.5",
36
+ "slate-react": "0.101.5",
37
+ "slate-history": "0.100.0"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "react": "^16.13.1",
package/src/lib.js CHANGED
@@ -1,6 +1,7 @@
1
- import React, { useMemo, useEffect, useRef } from 'react';
1
+ import React, { useMemo, useEffect, useRef, useState } from 'react';
2
2
  import { createEditor, Editor, Transforms } from 'slate';
3
3
  import { Slate, Editable, withReact } from 'slate-react';
4
+ import { withHistory } from 'slate-history';
4
5
  import {
5
6
  composeRenderLeaf,
6
7
  composeRenderElement,
@@ -70,24 +71,24 @@ const HeroEditor = ({
70
71
  const wrapper = useRef(null);
71
72
  const wrapperLayout = useRef({ width: 0, height: 0 });
72
73
 
73
- const editorRef = useRef();
74
- if (!editorRef.current)
75
- editorRef.current = flow(
74
+ const [editor] = useState(() =>
75
+ flow(
76
76
  createEditor,
77
+ withHistory,
77
78
  withReact,
78
79
  withId(id),
79
80
  ...map(get('enhanceEditor'))(plugins),
80
- )();
81
- const editor = editorRef.current;
81
+ )(),
82
+ );
82
83
 
83
84
  const renderLeaf = useMemo(() => composeRenderLeaf(plugins), [plugins]);
84
85
 
85
86
  const renderElement = useMemo(() => composeRenderElement(plugins), [plugins]);
86
87
 
87
- const renderCustom = useMemo(() => () => getCustomElements(editor)(plugins), [
88
- plugins,
89
- value,
90
- ]);
88
+ const renderCustom = useMemo(
89
+ () => () => getCustomElements(editor)(plugins),
90
+ [plugins, value],
91
+ );
91
92
 
92
93
  const toolBarButtons = useMemo(() => getToolbarButtons(plugins), [plugins]);
93
94
 
@@ -1,16 +1,18 @@
1
- import { createPlugin, addMessageListener } from '../helpers';
1
+ import { Transforms } from 'slate';
2
+
2
3
  import { EMPTY_VALUE } from '../constants';
4
+ import { addMessageListener, createPlugin } from '../helpers';
3
5
 
4
6
  const name = 'editor-resetter';
5
-
6
7
  const handleMessage = addMessageListener(
7
8
  'reset',
8
9
  ({ editor, data = EMPTY_VALUE }) => {
9
- editor.children = data;
10
- editor.selection = {
11
- anchor: { path: [0, 0], offset: 0 },
12
- focus: { path: [0, 0], offset: 0 },
13
- };
10
+ // Delete all editor content
11
+ editor.children.map(() => {
12
+ Transforms.delete(editor, { at: [0] });
13
+ });
14
+
15
+ Transforms.insertNodes(editor, data);
14
16
  editor.onChange();
15
17
  },
16
18
  );
@@ -95,25 +95,27 @@ const MentionListWrapper = ({ renderMentionList }) => {
95
95
  ({ data }) => {
96
96
  const wrapperEl = wrapper.current;
97
97
 
98
- if (data.target) {
99
- const domRange = ReactEditor.toDOMRange(editor, data.target);
100
- const rangeRect = domRange.getBoundingClientRect();
101
- const editorRect = wrapperEl.parentElement.getBoundingClientRect();
102
-
103
- const wrapperLeft = rangeRect.left - editorRect.left;
104
- const wrapperRight = editorRect.right - rangeRect.right;
105
-
106
- wrapperEl.style.display = 'block';
107
- wrapperEl.style.top = `${rangeRect.top - editorRect.top + 20}px`;
108
- if (wrapperEl.offsetWidth > editorRect.width - wrapperLeft) {
109
- wrapperEl.style.left = 'unset';
110
- wrapperEl.style.right = `${wrapperRight}px`;
98
+ if(wrapperEl) {
99
+ if (data.target) {
100
+ const domRange = ReactEditor.toDOMRange(editor, data.target);
101
+ const rangeRect = domRange.getBoundingClientRect();
102
+ const editorRect = wrapperEl.parentElement.getBoundingClientRect();
103
+
104
+ const wrapperLeft = rangeRect.left - editorRect.left;
105
+ const wrapperRight = editorRect.right - rangeRect.right;
106
+
107
+ wrapperEl.style.display = 'block';
108
+ wrapperEl.style.top = `${rangeRect.top - editorRect.top + 20}px`;
109
+ if (wrapperEl.offsetWidth > editorRect.width - wrapperLeft) {
110
+ wrapperEl.style.left = 'unset';
111
+ wrapperEl.style.right = `${wrapperRight}px`;
112
+ } else {
113
+ wrapperEl.style.left = `${wrapperLeft}px`;
114
+ wrapperEl.style.right = 'unset';
115
+ }
111
116
  } else {
112
- wrapperEl.style.left = `${wrapperLeft}px`;
113
- wrapperEl.style.right = 'unset';
117
+ wrapperEl.style.display = 'none';
114
118
  }
115
- } else {
116
- wrapperEl.style.display = 'none';
117
119
  }
118
120
 
119
121
  setSearch(data.search);