@seafile/seafile-editor 1.0.86-beta2 → 1.0.86-beta3
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/editors/inline-editor/index.js +12 -11
- package/dist/pages/longtext-inline-editor/fallback-editor.js +4 -4
- package/dist/pages/longtext-inline-editor/index.js +12 -23
- package/dist/pages/longtext-inline-editor/normal-editor.js +5 -7
- package/package.json +1 -1
- package/dist/pages/longtext-inline-editor/formatter/index.css +0 -68
- package/dist/pages/longtext-inline-editor/formatter/index.js +0 -66
|
@@ -19,8 +19,7 @@ require("./index.css");
|
|
|
19
19
|
const isMacOS = (0, _common.isMac)();
|
|
20
20
|
const InlineEditor = _ref => {
|
|
21
21
|
let {
|
|
22
|
-
|
|
23
|
-
focusRange,
|
|
22
|
+
enableEdit,
|
|
24
23
|
value,
|
|
25
24
|
editorApi,
|
|
26
25
|
onSave,
|
|
@@ -28,9 +27,10 @@ const InlineEditor = _ref => {
|
|
|
28
27
|
onContentChanged,
|
|
29
28
|
isSupportFormula,
|
|
30
29
|
onExpandEditorToggle,
|
|
31
|
-
|
|
30
|
+
handelEnableEdit
|
|
32
31
|
} = _ref;
|
|
33
32
|
const [slateValue, setSlateValue] = (0, _react.useState)(value);
|
|
33
|
+
const [focusRange, setFocusRange] = (0, _react.useState)(null);
|
|
34
34
|
const editor = (0, _react.useMemo)(() => {
|
|
35
35
|
const baseEditor = (0, _extension.inlineEditor)();
|
|
36
36
|
return (0, _withPropsEditor.default)(baseEditor, {
|
|
@@ -57,7 +57,7 @@ const InlineEditor = _ref => {
|
|
|
57
57
|
const focusNode = (0, _react.useCallback)((editor, focusRange) => {
|
|
58
58
|
const [firstNode] = editor.children;
|
|
59
59
|
if (!firstNode) return;
|
|
60
|
-
if (focusRange &&
|
|
60
|
+
if (focusRange && focusRange !== null && focusRange !== void 0 && focusRange.anchor) {
|
|
61
61
|
const startOfFirstNode = _slate.Editor.start(editor, focusRange.anchor.path);
|
|
62
62
|
const range = {
|
|
63
63
|
anchor: startOfFirstNode,
|
|
@@ -94,10 +94,10 @@ const InlineEditor = _ref => {
|
|
|
94
94
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
95
|
}, []);
|
|
96
96
|
(0, _react.useEffect)(() => {
|
|
97
|
-
if (!
|
|
97
|
+
if (!enableEdit) return;
|
|
98
98
|
focusNode(editor, focusRange);
|
|
99
99
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
|
-
}, [
|
|
100
|
+
}, [enableEdit, focusRange]);
|
|
101
101
|
|
|
102
102
|
// willUnmount
|
|
103
103
|
(0, _react.useEffect)(() => {
|
|
@@ -111,18 +111,19 @@ const InlineEditor = _ref => {
|
|
|
111
111
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
112
|
}, []);
|
|
113
113
|
const onEditorClick = (0, _react.useCallback)(() => {
|
|
114
|
-
if (!
|
|
115
|
-
|
|
114
|
+
if (!enableEdit) {
|
|
115
|
+
setFocusRange(editor.selection);
|
|
116
|
+
handelEnableEdit();
|
|
116
117
|
return;
|
|
117
118
|
}
|
|
118
119
|
const value = editor.children;
|
|
119
120
|
if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
|
|
120
121
|
focusNode(editor);
|
|
121
122
|
}
|
|
122
|
-
}, [
|
|
123
|
+
}, [enableEdit, editor, focusNode, handelEnableEdit]);
|
|
123
124
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
124
125
|
className: "sf-simple-slate-editor-container"
|
|
125
|
-
},
|
|
126
|
+
}, enableEdit && /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
|
|
126
127
|
editor: editor,
|
|
127
128
|
isSupportFormula: isSupportFormula,
|
|
128
129
|
isSupportColumn: !!columns,
|
|
@@ -141,7 +142,7 @@ const InlineEditor = _ref => {
|
|
|
141
142
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
142
143
|
className: "article"
|
|
143
144
|
}, /*#__PURE__*/_react.default.createElement(_extension.SetNodeToDecorations, null), /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
|
|
144
|
-
readOnly: !
|
|
145
|
+
readOnly: !enableEdit,
|
|
145
146
|
decorate: decorate,
|
|
146
147
|
renderElement: _extension.renderElement,
|
|
147
148
|
renderLeaf: _extension.renderLeaf,
|
|
@@ -10,7 +10,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _isHotkey = _interopRequireDefault(require("is-hotkey"));
|
|
11
11
|
const FallbackEditor = _ref => {
|
|
12
12
|
let {
|
|
13
|
-
|
|
13
|
+
enableEdit,
|
|
14
14
|
value: propsValue,
|
|
15
15
|
onChange: propsOnChange,
|
|
16
16
|
closeEditor
|
|
@@ -19,11 +19,11 @@ const FallbackEditor = _ref => {
|
|
|
19
19
|
const showEditorRef = (0, _react.useRef)(false);
|
|
20
20
|
const inputRef = (0, _react.useRef)(null);
|
|
21
21
|
(0, _react.useEffect)(() => {
|
|
22
|
-
if (
|
|
23
|
-
if (
|
|
22
|
+
if (enableEdit === showEditorRef.current) return;
|
|
23
|
+
if (enableEdit && !showEditorRef.current) {
|
|
24
24
|
setTimeout(() => inputRef.current.focus());
|
|
25
25
|
}
|
|
26
|
-
}, [
|
|
26
|
+
}, [enableEdit]);
|
|
27
27
|
const onChange = (0, _react.useCallback)(event => {
|
|
28
28
|
const newValue = event.target.value;
|
|
29
29
|
if (newValue === value) return;
|
|
@@ -21,39 +21,29 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
|
|
|
21
21
|
value,
|
|
22
22
|
lang,
|
|
23
23
|
headerName,
|
|
24
|
-
|
|
24
|
+
onClick,
|
|
25
25
|
onSaveEditorValue,
|
|
26
26
|
editorApi
|
|
27
27
|
} = _ref;
|
|
28
|
-
const [
|
|
28
|
+
const [enableEdit, setEnableEdit] = (0, _react.useState)(false);
|
|
29
29
|
const valueRef = (0, _react.useRef)(typeof value === 'string' ? {
|
|
30
30
|
text: value
|
|
31
31
|
} : value);
|
|
32
32
|
const longTextValueChangedRef = (0, _react.useRef)(false);
|
|
33
|
-
const [focusRange, setFocusRange] = (0, _react.useState)(null);
|
|
34
33
|
const {
|
|
35
34
|
isWindowsWechat
|
|
36
35
|
} = (0, _react.useMemo)(() => {
|
|
37
36
|
return (0, _getBrowserInfo.default)(isCheckBrowser);
|
|
38
37
|
}, [isCheckBrowser]);
|
|
39
|
-
const openEditor = (0, _react.useCallback)(
|
|
40
|
-
|
|
41
|
-
setFocusRange(focusRange);
|
|
42
|
-
setShowEditor(true);
|
|
38
|
+
const openEditor = (0, _react.useCallback)(() => {
|
|
39
|
+
setEnableEdit(true);
|
|
43
40
|
}, []);
|
|
44
41
|
const closeEditor = (0, _react.useCallback)(() => {
|
|
45
42
|
if (longTextValueChangedRef.current) {
|
|
46
43
|
onSaveEditorValue(valueRef.current);
|
|
47
44
|
}
|
|
48
|
-
|
|
45
|
+
setEnableEdit(false);
|
|
49
46
|
}, [longTextValueChangedRef, valueRef, onSaveEditorValue]);
|
|
50
|
-
const getAttributeNode = (0, _react.useCallback)(function (node, attribute) {
|
|
51
|
-
let deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
|
|
52
|
-
if (!node || !node.getAttribute) return null;
|
|
53
|
-
if (deep === -1) return null;
|
|
54
|
-
if (node.getAttribute(attribute)) return node.getAttribute(attribute);
|
|
55
|
-
if (node.parentNode) return getAttributeNode(node.parentNode, attribute, deep--);
|
|
56
|
-
}, []);
|
|
57
47
|
const onEditorValueChanged = (0, _react.useCallback)(value => {
|
|
58
48
|
valueRef.current = value;
|
|
59
49
|
longTextValueChangedRef.current = true;
|
|
@@ -74,26 +64,25 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
|
|
|
74
64
|
closeEditor: closeEditor
|
|
75
65
|
};
|
|
76
66
|
}, [openEditor, closeEditor]);
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
openEditor(
|
|
80
|
-
}, [openEditor,
|
|
67
|
+
const handelEnableEdit = (0, _react.useCallback)(() => {
|
|
68
|
+
onClick && onClick();
|
|
69
|
+
openEditor();
|
|
70
|
+
}, [openEditor, onClick]);
|
|
81
71
|
return /*#__PURE__*/_react.default.createElement(_clickOutside.default, {
|
|
82
72
|
onClickOutside: closeEditor
|
|
83
73
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
84
74
|
className: "w-100",
|
|
85
75
|
onKeyDown: onHotKey
|
|
86
76
|
}, isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_fallbackEditor.default, {
|
|
87
|
-
|
|
77
|
+
enableEdit: enableEdit,
|
|
88
78
|
value: valueRef.current.text,
|
|
89
79
|
onChange: onEditorValueChanged,
|
|
90
80
|
closeEditor: closeEditor
|
|
91
81
|
}) : /*#__PURE__*/_react.default.createElement(_normalEditor.default, {
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
enableEdit: enableEdit,
|
|
83
|
+
handelEnableEdit: handelEnableEdit,
|
|
94
84
|
lang: lang,
|
|
95
85
|
headerName: headerName,
|
|
96
|
-
focusRange: focusRange,
|
|
97
86
|
value: valueRef.current.text,
|
|
98
87
|
autoSave: autoSave,
|
|
99
88
|
saveDelay: saveDelay,
|
|
@@ -14,9 +14,8 @@ var _longtextEditorDialog = _interopRequireDefault(require("../longtext-editor-d
|
|
|
14
14
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
15
|
const NormalEditor = _ref => {
|
|
16
16
|
let {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
focusRange,
|
|
17
|
+
enableEdit,
|
|
18
|
+
handelEnableEdit,
|
|
20
19
|
lang,
|
|
21
20
|
headerName,
|
|
22
21
|
value: propsValue,
|
|
@@ -100,17 +99,16 @@ const NormalEditor = _ref => {
|
|
|
100
99
|
}, [autoSave, saveDelay, handelAutoSave]);
|
|
101
100
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
102
101
|
className: (0, _classnames.default)('sf-long-text-inline-editor-container', {
|
|
103
|
-
'preview': !
|
|
102
|
+
'preview': !enableEdit
|
|
104
103
|
}),
|
|
105
104
|
style: style,
|
|
106
105
|
ref: editorContainerRef
|
|
107
106
|
}, !showExpandEditor ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
|
|
108
107
|
ref: editorRef,
|
|
109
|
-
|
|
110
|
-
updateFocus: updateFocus,
|
|
108
|
+
enableEdit: enableEdit,
|
|
111
109
|
isInline: true,
|
|
112
|
-
focusRange: focusRange,
|
|
113
110
|
value: valueRef.current.text,
|
|
111
|
+
handelEnableEdit: handelEnableEdit,
|
|
114
112
|
onSave: handelAutoSave,
|
|
115
113
|
editorApi: editorApi,
|
|
116
114
|
onContentChanged: onContentChanged,
|
package/package.json
CHANGED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container {
|
|
2
|
-
width: 100%;
|
|
3
|
-
height: 100%;
|
|
4
|
-
overflow: hidden;
|
|
5
|
-
border-radius: 3px;
|
|
6
|
-
cursor: pointer;
|
|
7
|
-
padding: 16px 12px;
|
|
8
|
-
background-color: #FFF;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container .sf-slate-viewer-scroll-container {
|
|
12
|
-
overflow-y: auto;
|
|
13
|
-
height: fit-content;
|
|
14
|
-
padding: 0;
|
|
15
|
-
background: #fff;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container .sf-slate-viewer-article-container {
|
|
19
|
-
height: 100%;
|
|
20
|
-
width: 100%;
|
|
21
|
-
margin: 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container .sf-slate-viewer-article-container .article {
|
|
25
|
-
padding: 0;
|
|
26
|
-
height: auto;
|
|
27
|
-
min-height: 100% !important;
|
|
28
|
-
border: 0;
|
|
29
|
-
color: #212529;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container ol,
|
|
33
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container ul {
|
|
34
|
-
padding-inline-start: 40px;
|
|
35
|
-
margin-bottom: 1em;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container ol li a,
|
|
39
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container ul li a {
|
|
40
|
-
word-break: break-all;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container ul.contains-task-list,
|
|
44
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container ol.contains-task-list {
|
|
45
|
-
padding-inline-start: 20px;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container ul li.task-list-item,
|
|
49
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container ol li.task-list-item {
|
|
50
|
-
min-height: 20px;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container li.task-list-item input[type=checkbox] {
|
|
54
|
-
position: absolute;
|
|
55
|
-
left: -1.4em;
|
|
56
|
-
top: .4em;
|
|
57
|
-
display: inline-block;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container thead tr {
|
|
61
|
-
min-height: 42px;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.sf-long-text-inline-editor-container.preview .longtext-preview-container tbody tr {
|
|
65
|
-
font-weight: normal;
|
|
66
|
-
min-height: 42px;
|
|
67
|
-
}
|
|
68
|
-
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _loading = _interopRequireDefault(require("../../../containers/loading"));
|
|
11
|
-
var _slateConvert = require("../../../slate-convert");
|
|
12
|
-
var _slateViewer = _interopRequireDefault(require("../../../editors/slate-viewer"));
|
|
13
|
-
require("./index.css");
|
|
14
|
-
// Windows old Wechat (3.0 or earlier) inner core is chrome 53 and don't support ECMA6, can't use seafile-editor markdownViewer
|
|
15
|
-
// Windows new Wechat (lastest version 3.3.5) support seafile-editor markdownViewer
|
|
16
|
-
// so use dangerouslySetInnerHTML to preview
|
|
17
|
-
class Formatter extends _react.default.PureComponent {
|
|
18
|
-
constructor(props) {
|
|
19
|
-
super(props);
|
|
20
|
-
(0, _defineProperty2.default)(this, "convertMarkdown", mdFile => {
|
|
21
|
-
_slateConvert.processor.process(mdFile).then(result => {
|
|
22
|
-
let innerHtml = String(result).replace(/<a /ig, '<a target="_blank" tabindex="-1"');
|
|
23
|
-
this.setState({
|
|
24
|
-
innerHtml
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
this.state = {
|
|
29
|
-
innerHtml: null
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
componentDidMount() {
|
|
33
|
-
const {
|
|
34
|
-
isWindowsWechat,
|
|
35
|
-
value
|
|
36
|
-
} = this.props;
|
|
37
|
-
if (isWindowsWechat) {
|
|
38
|
-
this.convertMarkdown(value);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
render() {
|
|
42
|
-
const {
|
|
43
|
-
isWindowsWechat,
|
|
44
|
-
value,
|
|
45
|
-
isShowOutline
|
|
46
|
-
} = this.props;
|
|
47
|
-
const {
|
|
48
|
-
innerHtml
|
|
49
|
-
} = this.state;
|
|
50
|
-
if (isWindowsWechat && innerHtml === null) {
|
|
51
|
-
return /*#__PURE__*/_react.default.createElement(_loading.default, null);
|
|
52
|
-
}
|
|
53
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
54
|
-
className: "longtext-preview-container"
|
|
55
|
-
}, isWindowsWechat && /*#__PURE__*/_react.default.createElement("div", {
|
|
56
|
-
className: "article",
|
|
57
|
-
dangerouslySetInnerHTML: {
|
|
58
|
-
__html: this.state.innerHtml
|
|
59
|
-
}
|
|
60
|
-
}), !isWindowsWechat && /*#__PURE__*/_react.default.createElement(_slateViewer.default, {
|
|
61
|
-
value: value,
|
|
62
|
-
isShowOutline: isShowOutline
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
var _default = exports.default = Formatter;
|