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 +7 -6
- package/src/lib.js +11 -10
- package/src/plugins/editorResetter.js +9 -7
- package/src/plugins/mention.js +19 -17
- package/dist/app.js +0 -38
- package/dist/app.js.map +0 -1
- package/dist/lib.js +0 -9
- package/dist/lib.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hero-editor",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
36
|
-
"slate-react": "0.
|
|
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
|
|
74
|
-
|
|
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
|
-
|
|
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(
|
|
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 {
|
|
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
|
|
10
|
-
editor.
|
|
11
|
-
|
|
12
|
-
|
|
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
|
);
|
package/src/plugins/mention.js
CHANGED
|
@@ -95,25 +95,27 @@ const MentionListWrapper = ({ renderMentionList }) => {
|
|
|
95
95
|
({ data }) => {
|
|
96
96
|
const wrapperEl = wrapper.current;
|
|
97
97
|
|
|
98
|
-
if
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
wrapperEl.
|
|
110
|
-
|
|
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.
|
|
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);
|