@seafile/seafile-editor 1.0.4-1 → 1.0.4-10
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/dist/constants/event-types.js +2 -1
- package/dist/editors/simple-slate-editor /index.js +2 -2
- package/dist/editors/simple-slate-editor /style.css +72 -0
- package/dist/editors/slate-editor/index.js +7 -3
- package/dist/{assets/css/slate-editor.css → editors/slate-editor/style.css} +1 -0
- package/dist/editors/slate-viewer/index.js +4 -2
- package/dist/editors/slate-viewer/style.css +23 -1
- package/dist/extension/plugins/link/helper.js +2 -2
- package/dist/extension/plugins/link/render-elem/index.js +9 -5
- package/dist/extension/toolbar/header-toolbar/index.js +1 -1
- package/dist/pages/markdown-view.js +3 -1
- package/dist/slate-convert/md-to-slate/transform.js +10 -2
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import EventBus from '../../utils/event-bus';
|
|
|
6
6
|
import EventProxy from '../../utils/event-handler';
|
|
7
7
|
import withPropsEditor from './with-props-editor';
|
|
8
8
|
import { focusEditor } from '../../extension/core';
|
|
9
|
-
import '
|
|
9
|
+
import './style.css';
|
|
10
10
|
export default function SimpleSlateEditor(_ref) {
|
|
11
11
|
let {
|
|
12
12
|
value,
|
|
@@ -51,7 +51,7 @@ export default function SimpleSlateEditor(_ref) {
|
|
|
51
51
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
52
|
}, []);
|
|
53
53
|
return /*#__PURE__*/React.createElement("div", {
|
|
54
|
-
className: "sf-slate-editor-container"
|
|
54
|
+
className: "sf-simple-slate-editor-container"
|
|
55
55
|
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
56
56
|
editor: editor,
|
|
57
57
|
isSupportFormula: isSupportFormula
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
.sf-simple-slate-editor-container {
|
|
2
|
+
flex: 1;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
min-height: 0;
|
|
6
|
+
min-width: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.sf-simple-slate-editor-container .sf-slate-editor-toolbar {
|
|
10
|
+
display: flex;
|
|
11
|
+
justify-content: flex-start;
|
|
12
|
+
height: 44px;
|
|
13
|
+
align-items: center;
|
|
14
|
+
padding: 0 10px;
|
|
15
|
+
background-color: #fff;
|
|
16
|
+
user-select: none;
|
|
17
|
+
border-bottom: 1px solid #e5e6e8;
|
|
18
|
+
position: relative;
|
|
19
|
+
z-index: 102;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.sf-simple-slate-editor-container .sf-slate-editor-content {
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: calc(100% - 44px);
|
|
25
|
+
display: flex;
|
|
26
|
+
background: #f5f5f5;
|
|
27
|
+
position: relative;
|
|
28
|
+
min-height: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.sf-simple-slate-editor-container .sf-slate-scroll-container,
|
|
32
|
+
.sf-simple-slate-editor-container .sf-slate-article-container {
|
|
33
|
+
height: 100%;
|
|
34
|
+
width: 100%;
|
|
35
|
+
overflow: auto;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* .sf-simple-slate-editor-container .sf-slate-article-container {
|
|
39
|
+
flex: 1;
|
|
40
|
+
position: relative;
|
|
41
|
+
max-width: 950px;
|
|
42
|
+
min-width: 400px;
|
|
43
|
+
margin: 0 auto;
|
|
44
|
+
padding-top: 20px;
|
|
45
|
+
padding-bottom: 20px;
|
|
46
|
+
} */
|
|
47
|
+
|
|
48
|
+
.sf-simple-slate-editor-container .sf-slate-editor-content .article {
|
|
49
|
+
margin: 0;
|
|
50
|
+
padding: 10px;
|
|
51
|
+
height: 100%;
|
|
52
|
+
border: none;
|
|
53
|
+
background-color: #fff;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.sf-simple-slate-editor-container .sf-slate-editor-content .article div:first-child {
|
|
57
|
+
outline: none;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.sf-simple-slate-editor-container ::-webkit-scrollbar{
|
|
61
|
+
width: 8px;
|
|
62
|
+
height: 8px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.sf-simple-slate-editor-container ::-webkit-scrollbar-button {
|
|
66
|
+
display: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.sf-simple-slate-editor-container ::-webkit-scrollbar-thumb {
|
|
70
|
+
background-color: rgb(206, 206, 212);
|
|
71
|
+
border-radius: 10px;
|
|
72
|
+
}
|
|
@@ -8,7 +8,7 @@ import withPropsEditor from './with-props-editor';
|
|
|
8
8
|
import EditorHelp from './editor-help';
|
|
9
9
|
import { focusEditor } from '../../extension/core';
|
|
10
10
|
import { ScrollContext } from '../../hooks/use-scroll-context';
|
|
11
|
-
import '
|
|
11
|
+
import './style.css';
|
|
12
12
|
export default function SlateEditor(_ref) {
|
|
13
13
|
let {
|
|
14
14
|
value,
|
|
@@ -28,10 +28,14 @@ export default function SlateEditor(_ref) {
|
|
|
28
28
|
}, [editor]);
|
|
29
29
|
const onChange = useCallback(value => {
|
|
30
30
|
setSlateValue(value);
|
|
31
|
-
|
|
31
|
+
const operations = editor.operations;
|
|
32
|
+
const modifyOps = operations.filter(o => o.type !== 'set_selection');
|
|
33
|
+
if (modifyOps.length > 0) {
|
|
34
|
+
onSave && onSave(value);
|
|
35
|
+
}
|
|
32
36
|
const eventBus = EventBus.getInstance();
|
|
33
37
|
eventBus.dispatch('change');
|
|
34
|
-
}, [onSave]);
|
|
38
|
+
}, [editor.operations, onSave]);
|
|
35
39
|
|
|
36
40
|
// useMount: focus editor
|
|
37
41
|
useEffect(() => {
|
|
@@ -7,15 +7,17 @@ import './style.css';
|
|
|
7
7
|
export default function SlateViewer(_ref) {
|
|
8
8
|
let {
|
|
9
9
|
value,
|
|
10
|
-
isShowOutline
|
|
10
|
+
isShowOutline,
|
|
11
|
+
scrollRef: externalScrollRef
|
|
11
12
|
} = _ref;
|
|
12
13
|
const scrollRef = useRef(null);
|
|
14
|
+
const containerScrollRef = externalScrollRef ? externalScrollRef : scrollRef;
|
|
13
15
|
return /*#__PURE__*/React.createElement(Slate, {
|
|
14
16
|
editor: baseEditor,
|
|
15
17
|
initialValue: value
|
|
16
18
|
}, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
|
|
17
19
|
value: {
|
|
18
|
-
scrollRef
|
|
20
|
+
scrollRef: containerScrollRef
|
|
19
21
|
}
|
|
20
22
|
}, /*#__PURE__*/React.createElement("div", {
|
|
21
23
|
ref: scrollRef,
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
min-width: 0;
|
|
6
6
|
overflow: auto;
|
|
7
7
|
background: #f4f4f4;
|
|
8
|
-
border: 1px solid #ededed;
|
|
9
8
|
padding: 30px 0 15px;
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -37,4 +36,27 @@
|
|
|
37
36
|
background: #fff;
|
|
38
37
|
}
|
|
39
38
|
|
|
39
|
+
@media (max-width: 991.98px) {
|
|
40
|
+
.sf-slate-viewer-outline {
|
|
41
|
+
display: none !important;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@media (max-width: 768px) {
|
|
46
|
+
.sf-slate-viewer-article-container {
|
|
47
|
+
padding: 0 10px;
|
|
48
|
+
width: 100%;
|
|
49
|
+
margin: 0 !important;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.sf-slate-viewer-article-container .article {
|
|
53
|
+
margin: 0 !important;
|
|
54
|
+
padding: 20px !important;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.sf-slate-viewer-outline {
|
|
58
|
+
display: none !important;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
40
62
|
|
|
@@ -92,12 +92,12 @@ export const insertLink = props => {
|
|
|
92
92
|
const isCollapsed = Range.isCollapsed(selection);
|
|
93
93
|
if (isCollapsed) {
|
|
94
94
|
// If selection is collapsed, we insert a space and then insert link node that help operation easier
|
|
95
|
-
editor.insertText('
|
|
95
|
+
editor.insertText('');
|
|
96
96
|
Editor.insertFragment(editor, [linkNode]);
|
|
97
97
|
// Using insertText directly causes the added Spaces to be added to the linked text, as in the issue above, so replaced by insertFragment
|
|
98
98
|
Editor.insertFragment(editor, [{
|
|
99
99
|
id: slugid.nice(),
|
|
100
|
-
text: '
|
|
100
|
+
text: ''
|
|
101
101
|
}]);
|
|
102
102
|
focusEditor(editor);
|
|
103
103
|
return;
|
|
@@ -5,7 +5,7 @@ import { useReadOnly } from 'slate-react';
|
|
|
5
5
|
import LinkPopover from './link-popover';
|
|
6
6
|
import { getLinkInfo } from '../helper';
|
|
7
7
|
import EventBus from '../../../../utils/event-bus';
|
|
8
|
-
import { INTERNAL_EVENTS } from '../../../../constants/event-types';
|
|
8
|
+
import { EXTERNAL_EVENTS, INTERNAL_EVENTS } from '../../../../constants/event-types';
|
|
9
9
|
import './style.css';
|
|
10
10
|
const renderLink = (_ref, editor) => {
|
|
11
11
|
let {
|
|
@@ -30,11 +30,14 @@ const renderLink = (_ref, editor) => {
|
|
|
30
30
|
const unregisterClickEvent = useCallback(() => {
|
|
31
31
|
document.removeEventListener('click', onClosePopover);
|
|
32
32
|
}, [onClosePopover]);
|
|
33
|
-
const
|
|
34
|
-
if (isReadonly) return;
|
|
33
|
+
const onLinkClick = useCallback(e => {
|
|
35
34
|
e.stopPropagation();
|
|
36
|
-
// Only one popover can be open at the same time, close other popover and update new popover controller function.
|
|
37
35
|
const eventBus = EventBus.getInstance();
|
|
36
|
+
if (isReadonly) {
|
|
37
|
+
eventBus.dispatch(EXTERNAL_EVENTS.ON_LINK_CLICK, e);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Only one popover can be open at the same time, close other popover and update new popover controller function.
|
|
38
41
|
eventBus.dispatch(INTERNAL_EVENTS.ON_CLOSE_LINK_POPOVER);
|
|
39
42
|
eventBus.subscribe(INTERNAL_EVENTS.ON_CLOSE_LINK_POPOVER, () => setIsShowPopover(false));
|
|
40
43
|
const linkInfo = getLinkInfo(editor);
|
|
@@ -54,7 +57,8 @@ const renderLink = (_ref, editor) => {
|
|
|
54
57
|
registerClickEvent();
|
|
55
58
|
}, [editor, isReadonly, registerClickEvent]);
|
|
56
59
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", Object.assign({
|
|
57
|
-
onClick:
|
|
60
|
+
onClick: onLinkClick,
|
|
61
|
+
"data-url": element.url,
|
|
58
62
|
className: classNames('sf-virtual-link', {
|
|
59
63
|
selected: isShowPopover
|
|
60
64
|
})
|
|
@@ -65,7 +65,7 @@ const Toolbar = _ref => {
|
|
|
65
65
|
};
|
|
66
66
|
return /*#__PURE__*/React.createElement("div", {
|
|
67
67
|
className: "sf-slate-editor-toolbar"
|
|
68
|
-
}, /*#__PURE__*/React.createElement(MenuGroup, null), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(HeaderMenu, commonProps)), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(TextStyleMenu, Object.assign({}, commonProps, {
|
|
68
|
+
}, isRichEditor && /*#__PURE__*/React.createElement(MenuGroup, null), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(HeaderMenu, commonProps)), /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(TextStyleMenu, Object.assign({}, commonProps, {
|
|
69
69
|
type: TEXT_STYLE_MAP.BOLD
|
|
70
70
|
})), /*#__PURE__*/React.createElement(TextStyleMenu, Object.assign({}, commonProps, {
|
|
71
71
|
type: TEXT_STYLE_MAP.ITALIC
|
|
@@ -9,6 +9,7 @@ export default function MarkdownViewer(_ref) {
|
|
|
9
9
|
value,
|
|
10
10
|
mathJaxSource,
|
|
11
11
|
isShowOutline,
|
|
12
|
+
scrollRef,
|
|
12
13
|
beforeRenderCallback
|
|
13
14
|
} = _ref;
|
|
14
15
|
const [richValue, setRichValue] = useState([]);
|
|
@@ -28,7 +29,8 @@ export default function MarkdownViewer(_ref) {
|
|
|
28
29
|
const props = {
|
|
29
30
|
isSupportFormula: !!mathJaxSource,
|
|
30
31
|
value: richValue,
|
|
31
|
-
isShowOutline: isShowOutline
|
|
32
|
+
isShowOutline: isShowOutline,
|
|
33
|
+
scrollRef: scrollRef
|
|
32
34
|
};
|
|
33
35
|
if (isFetching || isLoading || isLoadingMathJax) {
|
|
34
36
|
return /*#__PURE__*/React.createElement(Loading, null);
|
|
@@ -274,7 +274,7 @@ export const transformHtml = node => {
|
|
|
274
274
|
} = new DOMParser().parseFromString(node.value, 'text/html');
|
|
275
275
|
const img = body.firstChild;
|
|
276
276
|
const src = img.getAttribute('src');
|
|
277
|
-
if (src) return defaultTextNode;
|
|
277
|
+
if (!src) return defaultTextNode;
|
|
278
278
|
const alt = img.getAttribute('alt');
|
|
279
279
|
const title = img.getAttribute('title');
|
|
280
280
|
const width = img.getAttribute('width');
|
|
@@ -304,6 +304,13 @@ export const transformHtml = node => {
|
|
|
304
304
|
}
|
|
305
305
|
return defaultTextNode;
|
|
306
306
|
};
|
|
307
|
+
export const transformBlockHtml = node => {
|
|
308
|
+
return {
|
|
309
|
+
id: slugid.nice(),
|
|
310
|
+
type: PARAGRAPH,
|
|
311
|
+
children: transformHtml(node)
|
|
312
|
+
};
|
|
313
|
+
};
|
|
307
314
|
export const transformMath = node => {
|
|
308
315
|
return {
|
|
309
316
|
id: slugid.nice(),
|
|
@@ -323,7 +330,8 @@ const elementHandlers = {
|
|
|
323
330
|
// ordered_list | unordered_list | check_list_item
|
|
324
331
|
'code': transformCodeBlock,
|
|
325
332
|
'thematicBreak': transformHr,
|
|
326
|
-
'math': transformMath
|
|
333
|
+
'math': transformMath,
|
|
334
|
+
'html': transformBlockHtml
|
|
327
335
|
};
|
|
328
336
|
export const formatMdToSlate = children => {
|
|
329
337
|
const validChildren = children.filter(child => elementHandlers[child.type]);
|