@seafile/seafile-editor 1.0.86-beta3 → 1.0.86
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 +17 -27
- package/dist/pages/longtext-inline-editor/fallback-editor.js +4 -4
- package/dist/pages/longtext-inline-editor/formatter/index.css +68 -0
- package/dist/pages/longtext-inline-editor/formatter/index.js +66 -0
- package/dist/pages/longtext-inline-editor/index.css +1 -1
- package/dist/pages/longtext-inline-editor/index.js +37 -12
- package/dist/pages/longtext-inline-editor/normal-editor.js +3 -8
- package/package.json +1 -1
|
@@ -19,18 +19,16 @@ require("./index.css");
|
|
|
19
19
|
const isMacOS = (0, _common.isMac)();
|
|
20
20
|
const InlineEditor = _ref => {
|
|
21
21
|
let {
|
|
22
|
-
|
|
22
|
+
focusNodePath,
|
|
23
23
|
value,
|
|
24
24
|
editorApi,
|
|
25
25
|
onSave,
|
|
26
26
|
columns,
|
|
27
27
|
onContentChanged,
|
|
28
28
|
isSupportFormula,
|
|
29
|
-
onExpandEditorToggle
|
|
30
|
-
handelEnableEdit
|
|
29
|
+
onExpandEditorToggle
|
|
31
30
|
} = _ref;
|
|
32
31
|
const [slateValue, setSlateValue] = (0, _react.useState)(value);
|
|
33
|
-
const [focusRange, setFocusRange] = (0, _react.useState)(null);
|
|
34
32
|
const editor = (0, _react.useMemo)(() => {
|
|
35
33
|
const baseEditor = (0, _extension.inlineEditor)();
|
|
36
34
|
return (0, _withPropsEditor.default)(baseEditor, {
|
|
@@ -54,18 +52,20 @@ const InlineEditor = _ref => {
|
|
|
54
52
|
const eventBus = _eventBus.default.getInstance();
|
|
55
53
|
eventBus.dispatch('change');
|
|
56
54
|
}, [editor, onContentChanged]);
|
|
57
|
-
const focusNode = (0, _react.useCallback)((editor,
|
|
55
|
+
const focusNode = (0, _react.useCallback)((editor, focusNodePath) => {
|
|
58
56
|
const [firstNode] = editor.children;
|
|
59
57
|
if (!firstNode) return;
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
if (focusNodePath) {
|
|
59
|
+
const customFocusNodePath = (0, _core.getNode)(editor, focusNodePath);
|
|
60
|
+
if (customFocusNodePath) {
|
|
61
|
+
const startOfFirstNode = _slate.Editor.start(editor, focusNodePath);
|
|
62
|
+
const range = {
|
|
63
|
+
anchor: startOfFirstNode,
|
|
64
|
+
focus: startOfFirstNode
|
|
65
|
+
};
|
|
66
|
+
(0, _core.focusEditor)(editor, range);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
69
|
}
|
|
70
70
|
const [firstNodeFirstChild] = firstNode.children;
|
|
71
71
|
if (firstNodeFirstChild) {
|
|
@@ -86,6 +86,7 @@ const InlineEditor = _ref => {
|
|
|
86
86
|
});
|
|
87
87
|
const timer = setTimeout(() => {
|
|
88
88
|
editor.forceNormalize = false;
|
|
89
|
+
focusNode(editor, focusNodePath);
|
|
89
90
|
}, 300);
|
|
90
91
|
return () => {
|
|
91
92
|
editor.forceNormalize = false;
|
|
@@ -93,11 +94,6 @@ const InlineEditor = _ref => {
|
|
|
93
94
|
};
|
|
94
95
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
96
|
}, []);
|
|
96
|
-
(0, _react.useEffect)(() => {
|
|
97
|
-
if (!enableEdit) return;
|
|
98
|
-
focusNode(editor, focusRange);
|
|
99
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
|
-
}, [enableEdit, focusRange]);
|
|
101
97
|
|
|
102
98
|
// willUnmount
|
|
103
99
|
(0, _react.useEffect)(() => {
|
|
@@ -111,19 +107,14 @@ const InlineEditor = _ref => {
|
|
|
111
107
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
108
|
}, []);
|
|
113
109
|
const onEditorClick = (0, _react.useCallback)(() => {
|
|
114
|
-
if (!enableEdit) {
|
|
115
|
-
setFocusRange(editor.selection);
|
|
116
|
-
handelEnableEdit();
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
110
|
const value = editor.children;
|
|
120
111
|
if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
|
|
121
112
|
focusNode(editor);
|
|
122
113
|
}
|
|
123
|
-
}, [
|
|
114
|
+
}, [editor, focusNode]);
|
|
124
115
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
125
116
|
className: "sf-simple-slate-editor-container"
|
|
126
|
-
},
|
|
117
|
+
}, /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
|
|
127
118
|
editor: editor,
|
|
128
119
|
isSupportFormula: isSupportFormula,
|
|
129
120
|
isSupportColumn: !!columns,
|
|
@@ -142,7 +133,6 @@ const InlineEditor = _ref => {
|
|
|
142
133
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
143
134
|
className: "article"
|
|
144
135
|
}, /*#__PURE__*/_react.default.createElement(_extension.SetNodeToDecorations, null), /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
|
|
145
|
-
readOnly: !enableEdit,
|
|
146
136
|
decorate: decorate,
|
|
147
137
|
renderElement: _extension.renderElement,
|
|
148
138
|
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
|
+
isShowEditor,
|
|
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 (isShowEditor === showEditorRef.current) return;
|
|
23
|
+
if (isShowEditor && !showEditorRef.current) {
|
|
24
24
|
setTimeout(() => inputRef.current.focus());
|
|
25
25
|
}
|
|
26
|
-
}, [
|
|
26
|
+
}, [isShowEditor]);
|
|
27
27
|
const onChange = (0, _react.useCallback)(event => {
|
|
28
28
|
const newValue = event.target.value;
|
|
29
29
|
if (newValue === value) return;
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
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;
|
|
@@ -9,9 +9,12 @@ exports.default = void 0;
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _isHotkey = _interopRequireDefault(require("is-hotkey"));
|
|
11
11
|
var _clickOutside = _interopRequireDefault(require("./click-outside"));
|
|
12
|
+
var _formatter = _interopRequireDefault(require("./formatter"));
|
|
12
13
|
var _fallbackEditor = _interopRequireDefault(require("./fallback-editor"));
|
|
13
14
|
var _normalEditor = _interopRequireDefault(require("./normal-editor"));
|
|
15
|
+
var _slateConvert = require("../../slate-convert");
|
|
14
16
|
var _getBrowserInfo = _interopRequireDefault(require("../../utils/get-browser-Info"));
|
|
17
|
+
var _extension = require("../../extension");
|
|
15
18
|
require("./index.css");
|
|
16
19
|
const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
17
20
|
let {
|
|
@@ -21,29 +24,47 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
|
|
|
21
24
|
value,
|
|
22
25
|
lang,
|
|
23
26
|
headerName,
|
|
24
|
-
|
|
27
|
+
onPreviewClick,
|
|
25
28
|
onSaveEditorValue,
|
|
26
29
|
editorApi
|
|
27
30
|
} = _ref;
|
|
28
|
-
const [
|
|
31
|
+
const [isShowEditor, setShowEditor] = (0, _react.useState)(false);
|
|
29
32
|
const valueRef = (0, _react.useRef)(typeof value === 'string' ? {
|
|
30
33
|
text: value
|
|
31
34
|
} : value);
|
|
32
35
|
const longTextValueChangedRef = (0, _react.useRef)(false);
|
|
36
|
+
const [focusNodePath, setFocusNodePath] = (0, _react.useState)([0, 0]);
|
|
33
37
|
const {
|
|
34
38
|
isWindowsWechat
|
|
35
39
|
} = (0, _react.useMemo)(() => {
|
|
36
40
|
return (0, _getBrowserInfo.default)(isCheckBrowser);
|
|
37
41
|
}, [isCheckBrowser]);
|
|
38
|
-
const openEditor = (0, _react.useCallback)(()
|
|
39
|
-
|
|
42
|
+
const openEditor = (0, _react.useCallback)(function () {
|
|
43
|
+
let focusNodePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0];
|
|
44
|
+
setFocusNodePath(focusNodePath);
|
|
45
|
+
setShowEditor(true);
|
|
40
46
|
}, []);
|
|
41
47
|
const closeEditor = (0, _react.useCallback)(() => {
|
|
42
48
|
if (longTextValueChangedRef.current) {
|
|
43
49
|
onSaveEditorValue(valueRef.current);
|
|
44
50
|
}
|
|
45
|
-
|
|
51
|
+
setShowEditor(false);
|
|
46
52
|
}, [longTextValueChangedRef, valueRef, onSaveEditorValue]);
|
|
53
|
+
const getAttributeNode = (0, _react.useCallback)(function (node, attribute) {
|
|
54
|
+
let deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
|
|
55
|
+
if (!node || !node.getAttribute) return null;
|
|
56
|
+
if (deep === -1) return null;
|
|
57
|
+
if (node.getAttribute(attribute)) return node.getAttribute(attribute);
|
|
58
|
+
if (node.parentNode) return getAttributeNode(node.parentNode, attribute, deep--);
|
|
59
|
+
}, []);
|
|
60
|
+
const previewClick = (0, _react.useCallback)((event, richValue) => {
|
|
61
|
+
if (event.target.nodeName === 'A') return;
|
|
62
|
+
const nodeId = getAttributeNode(event.target, 'data-id');
|
|
63
|
+
onPreviewClick && onPreviewClick();
|
|
64
|
+
openEditor((0, _extension.getNodePathById)({
|
|
65
|
+
children: richValue
|
|
66
|
+
}, nodeId));
|
|
67
|
+
}, [onPreviewClick, openEditor, getAttributeNode]);
|
|
47
68
|
const onEditorValueChanged = (0, _react.useCallback)(value => {
|
|
48
69
|
valueRef.current = value;
|
|
49
70
|
longTextValueChangedRef.current = true;
|
|
@@ -64,25 +85,29 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
|
|
|
64
85
|
closeEditor: closeEditor
|
|
65
86
|
};
|
|
66
87
|
}, [openEditor, closeEditor]);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
if (!isShowEditor) {
|
|
89
|
+
const richValue = (0, _slateConvert.mdStringToSlate)(valueRef.current.text);
|
|
90
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
91
|
+
className: "sf-long-text-inline-editor-container preview",
|
|
92
|
+
onClick: event => previewClick(event, richValue)
|
|
93
|
+
}, valueRef.current.text && /*#__PURE__*/_react.default.createElement(_formatter.default, {
|
|
94
|
+
value: isWindowsWechat ? valueRef.current : richValue
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
71
97
|
return /*#__PURE__*/_react.default.createElement(_clickOutside.default, {
|
|
72
98
|
onClickOutside: closeEditor
|
|
73
99
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
74
100
|
className: "w-100",
|
|
75
101
|
onKeyDown: onHotKey
|
|
76
102
|
}, isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_fallbackEditor.default, {
|
|
77
|
-
|
|
103
|
+
isShowEditor: isShowEditor,
|
|
78
104
|
value: valueRef.current.text,
|
|
79
105
|
onChange: onEditorValueChanged,
|
|
80
106
|
closeEditor: closeEditor
|
|
81
107
|
}) : /*#__PURE__*/_react.default.createElement(_normalEditor.default, {
|
|
82
|
-
enableEdit: enableEdit,
|
|
83
|
-
handelEnableEdit: handelEnableEdit,
|
|
84
108
|
lang: lang,
|
|
85
109
|
headerName: headerName,
|
|
110
|
+
focusNodePath: focusNodePath,
|
|
86
111
|
value: valueRef.current.text,
|
|
87
112
|
autoSave: autoSave,
|
|
88
113
|
saveDelay: saveDelay,
|
|
@@ -11,11 +11,9 @@ var _simpleEditor = _interopRequireDefault(require("../simple-editor"));
|
|
|
11
11
|
var _getPreviewContent = _interopRequireDefault(require("../../utils/get-preview-content"));
|
|
12
12
|
var _markdownPreview = _interopRequireDefault(require("../markdown-preview"));
|
|
13
13
|
var _longtextEditorDialog = _interopRequireDefault(require("../longtext-editor-dialog"));
|
|
14
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
14
|
const NormalEditor = _ref => {
|
|
16
15
|
let {
|
|
17
|
-
|
|
18
|
-
handelEnableEdit,
|
|
16
|
+
focusNodePath,
|
|
19
17
|
lang,
|
|
20
18
|
headerName,
|
|
21
19
|
value: propsValue,
|
|
@@ -98,17 +96,14 @@ const NormalEditor = _ref => {
|
|
|
98
96
|
};
|
|
99
97
|
}, [autoSave, saveDelay, handelAutoSave]);
|
|
100
98
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
101
|
-
className:
|
|
102
|
-
'preview': !enableEdit
|
|
103
|
-
}),
|
|
99
|
+
className: "sf-long-text-inline-editor-container",
|
|
104
100
|
style: style,
|
|
105
101
|
ref: editorContainerRef
|
|
106
102
|
}, !showExpandEditor ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
|
|
107
103
|
ref: editorRef,
|
|
108
|
-
enableEdit: enableEdit,
|
|
109
104
|
isInline: true,
|
|
105
|
+
focusNodePath: focusNodePath,
|
|
110
106
|
value: valueRef.current.text,
|
|
111
|
-
handelEnableEdit: handelEnableEdit,
|
|
112
107
|
onSave: handelAutoSave,
|
|
113
108
|
editorApi: editorApi,
|
|
114
109
|
onContentChanged: onContentChanged,
|