@seafile/seafile-editor 2.0.14 → 2.0.16
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.
|
@@ -16,6 +16,7 @@ var _constants = require("../../constants");
|
|
|
16
16
|
require("./index.css");
|
|
17
17
|
const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
18
18
|
let {
|
|
19
|
+
isAlwaysEnableEdit = false,
|
|
19
20
|
autoSave,
|
|
20
21
|
isCheckBrowser,
|
|
21
22
|
saveDelay,
|
|
@@ -26,7 +27,7 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
|
|
|
26
27
|
onSaveEditorValue,
|
|
27
28
|
editorApi
|
|
28
29
|
} = _ref;
|
|
29
|
-
const [enableEdit, setEnableEdit] = (0, _react.useState)(
|
|
30
|
+
const [enableEdit, setEnableEdit] = (0, _react.useState)(isAlwaysEnableEdit);
|
|
30
31
|
const valueRef = (0, _react.useRef)(typeof value === 'string' ? {
|
|
31
32
|
text: value
|
|
32
33
|
} : value);
|
|
@@ -37,14 +38,17 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
|
|
|
37
38
|
return (0, _getBrowserInfo.default)(isCheckBrowser);
|
|
38
39
|
}, [isCheckBrowser]);
|
|
39
40
|
const openEditor = (0, _react.useCallback)(() => {
|
|
41
|
+
if (isAlwaysEnableEdit) return;
|
|
40
42
|
setEnableEdit(true);
|
|
41
|
-
}, []);
|
|
43
|
+
}, [isAlwaysEnableEdit]);
|
|
42
44
|
const closeEditor = (0, _react.useCallback)(() => {
|
|
43
45
|
if (longTextValueChangedRef.current) {
|
|
44
46
|
onSaveEditorValue(valueRef.current);
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (!isAlwaysEnableEdit) {
|
|
49
|
+
setEnableEdit(false);
|
|
50
|
+
}
|
|
51
|
+
}, [isAlwaysEnableEdit, longTextValueChangedRef, valueRef, onSaveEditorValue]);
|
|
48
52
|
const onEditorValueChanged = (0, _react.useCallback)(value => {
|
|
49
53
|
valueRef.current = value;
|
|
50
54
|
longTextValueChangedRef.current = true;
|
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _unified = require("unified");
|
|
9
|
+
var _slate = require("slate");
|
|
9
10
|
var _remarkParse = _interopRequireDefault(require("remark-parse"));
|
|
10
11
|
var _remarkGfm = _interopRequireDefault(require("remark-gfm"));
|
|
11
12
|
var _remarkStringify = _interopRequireDefault(require("remark-stringify"));
|
|
12
13
|
var _remarkMath = _interopRequireDefault(require("remark-math"));
|
|
13
14
|
var _transform = require("./transform");
|
|
15
|
+
var _constants = require("../html-to-slate/constants");
|
|
14
16
|
const isContentValid = value => {
|
|
15
17
|
if (!value || !Array.isArray(value)) return false;
|
|
16
18
|
return true;
|
|
@@ -19,6 +21,20 @@ const isContentValid = value => {
|
|
|
19
21
|
// slateNode -> mdast -> mdString
|
|
20
22
|
const slateToMdString = value => {
|
|
21
23
|
if (!isContentValid(value)) return '';
|
|
24
|
+
if (value.length === 0) return '';
|
|
25
|
+
if (value.length === 1) {
|
|
26
|
+
const child = value[0];
|
|
27
|
+
if (child.type === _constants.PARAGRAPH && _slate.Node.string(child).length === 0) {
|
|
28
|
+
return [{
|
|
29
|
+
type: 'paragraph',
|
|
30
|
+
children: [{
|
|
31
|
+
type: 'text',
|
|
32
|
+
value: ''
|
|
33
|
+
}]
|
|
34
|
+
}];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
22
38
|
// slateNode -> mdast
|
|
23
39
|
// https://github.com/syntax-tree/mdast#phrasingcontent
|
|
24
40
|
const mdASTNodes = (0, _transform.formatSlateToMd)(value);
|