@seafile/seafile-editor 1.0.85-beta → 1.0.85-beta2

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.
@@ -20,6 +20,7 @@ const isMacOS = (0, _common.isMac)();
20
20
  const SimpleSlateEditor = _ref => {
21
21
  let {
22
22
  isInline,
23
+ focusNodePath,
23
24
  value,
24
25
  editorApi,
25
26
  onSave,
@@ -52,9 +53,21 @@ const SimpleSlateEditor = _ref => {
52
53
  const eventBus = _eventBus.default.getInstance();
53
54
  eventBus.dispatch('change');
54
55
  }, [editor, onContentChanged]);
55
- const focusFirstNode = (0, _react.useCallback)(editor => {
56
+ const focusNode = (0, _react.useCallback)((editor, focusNodePath) => {
56
57
  const [firstNode] = editor.children;
57
58
  if (!firstNode) return;
59
+ if (focusNodePath) {
60
+ const customFocusNodePath = (0, _core.getNode)(editor, focusNodePath);
61
+ if (customFocusNodePath) {
62
+ const startOfFirstNode = _slate.Editor.start(editor, focusNodePath);
63
+ const range = {
64
+ anchor: startOfFirstNode,
65
+ focus: startOfFirstNode
66
+ };
67
+ (0, _core.focusEditor)(editor, range);
68
+ return;
69
+ }
70
+ }
58
71
  const [firstNodeFirstChild] = firstNode.children;
59
72
  if (firstNodeFirstChild) {
60
73
  const startOfFirstNode = _slate.Editor.start(editor, [0, 0]);
@@ -90,7 +103,7 @@ const SimpleSlateEditor = _ref => {
90
103
  });
91
104
  const timer = setTimeout(() => {
92
105
  editor.forceNormalize = false;
93
- focusFirstNode(editor);
106
+ focusNode(editor, focusNodePath);
94
107
  }, 300);
95
108
  return () => {
96
109
  editor.forceNormalize = false;
@@ -113,9 +126,9 @@ const SimpleSlateEditor = _ref => {
113
126
  const onEditorClick = (0, _react.useCallback)(() => {
114
127
  const value = editor.children;
115
128
  if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
116
- focusFirstNode(editor);
129
+ focusNode(editor);
117
130
  }
118
- }, [editor, focusFirstNode]);
131
+ }, [editor, focusNode]);
119
132
  return /*#__PURE__*/_react.default.createElement("div", {
120
133
  className: "sf-simple-slate-editor-container"
121
134
  }, /*#__PURE__*/_react.default.createElement(ToolbarComponent, {
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isLastNode = exports.isLastChild = exports.isFirstNode = exports.isFirstChild = exports.isEndPoint = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getSelectedNodeEntryByTypes = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getInlineNodes = exports.getEditorString = exports.getDeepInlineChildren = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
7
+ exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isLastNode = exports.isLastChild = exports.isFirstNode = exports.isFirstChild = exports.isEndPoint = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getSelectedNodeEntryByTypes = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodePathById = exports.getNodeEntries = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getInlineNodes = exports.getEditorString = exports.getDeepInlineChildren = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
8
8
  var _slate = require("slate");
9
9
  var _slateReact = require("slate-react");
10
10
  var _slugid = _interopRequireDefault(require("slugid"));
@@ -476,4 +476,20 @@ const getInlineNodes = node => {
476
476
  });
477
477
  return result.flat();
478
478
  };
479
- exports.getInlineNodes = getInlineNodes;
479
+ exports.getInlineNodes = getInlineNodes;
480
+ const getNodePathById = function (rootNode, nodeId) {
481
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
482
+ if (rootNode.id === nodeId) return path;
483
+ const {
484
+ children = []
485
+ } = rootNode;
486
+ for (let i = 0; i < children.length; i++) {
487
+ const child = children[i];
488
+ path.push(i);
489
+ const nodePath = getNodePathById(child, nodeId, path);
490
+ if (nodePath) return nodePath;
491
+ path.pop();
492
+ }
493
+ return null;
494
+ };
495
+ exports.getNodePathById = getNodePathById;
@@ -40,6 +40,12 @@ Object.defineProperty(exports, "createSlateEditor", {
40
40
  return _editor.createSlateEditor;
41
41
  }
42
42
  });
43
+ Object.defineProperty(exports, "getNodePathById", {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _core.getNodePathById;
47
+ }
48
+ });
43
49
  Object.defineProperty(exports, "inlineEditor", {
44
50
  enumerable: true,
45
51
  get: function () {
@@ -28,9 +28,6 @@ const renderLink = (_ref, editor) => {
28
28
  left: 0
29
29
  });
30
30
  const isReadonly = (0, _slateReact.useReadOnly)();
31
-
32
- // eslint-disable-next-line react-hooks/exhaustive-deps
33
- const isLinkActive = (0, _react.useMemo)(() => (0, _helper.isLinkType)(editor), [editor.selection]);
34
31
  const onClosePopover = (0, _react.useCallback)(e => {
35
32
  unregisterClickEvent();
36
33
  setIsShowPopover(false);
@@ -80,7 +77,7 @@ const renderLink = (_ref, editor) => {
80
77
  }, attributes), /*#__PURE__*/_react.default.createElement("a", {
81
78
  href: element.url,
82
79
  onClick: onHrefClick
83
- }, children)), isLinkActive && isShowPopover && /*#__PURE__*/_react.default.createElement(_linkPopover.default, {
80
+ }, children)), isShowPopover && /*#__PURE__*/_react.default.createElement(_linkPopover.default, {
84
81
  popoverPosition: popoverPosition,
85
82
  linkUrl: element.url,
86
83
  editor: editor,
@@ -14,6 +14,7 @@ var _helper = require("../helper");
14
14
  var _common = require("../../../../utils/common");
15
15
  var _eventTypes = require("../../../../constants/event-types");
16
16
  var _constants = require("../../../../constants");
17
+ require("./style.css");
17
18
  const LinkPopover = _ref => {
18
19
  let {
19
20
  linkUrl,
@@ -59,4 +59,4 @@
59
59
 
60
60
  .sf-link-op-icon:hover {
61
61
  background: #f2f2f2;
62
- }
62
+ }
@@ -0,0 +1,86 @@
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
+ /**
11
+ * Detecting outside click on a react component is surprisingly hard.
12
+ * A general approach is to have a global click handler on the document
13
+ * which checks if the click target is inside the editor container or
14
+ * not using editorContainer.contains(e.target). This approach works well
15
+ * until portals are used for editors. Portals render children into a DOM
16
+ * node that exists outside the DOM hierarchy of the parent component so
17
+ * editorContainer.contains(e.target) does not work. Here are some examples
18
+ * of the DOM structure with different types of editors
19
+ *
20
+ *
21
+ * SimpleEditor for example Texbox (No Portals)
22
+ * <div react-data-grid>..<div>
23
+ * <div portal-created-by-the-grid-for-editors>
24
+ * <div editor-container>
25
+ * <div simple-editor>..</div>
26
+ * </div>
27
+ * <div>
28
+ *
29
+ * ComplexEditor for example Modals (using Portals)
30
+ * <div react-data-grid>..<div>
31
+ * <div portal-created-by-the-grid-for-editors>
32
+ * <div editor-container>
33
+ * // Nothing here
34
+ * </div>
35
+ * <div>
36
+ * <div portal-created-by-the-editor>
37
+ * <div complex-editor>..</div>
38
+ * </div>
39
+ *
40
+ *
41
+ * One approach to detect outside click is to use event bubbling through
42
+ * portals. An event fired from inside a portal will propagate to ancestors
43
+ * in the containing React tree, even if those elements are not ancestors
44
+ * in the DOM tree. This means a click handler can be attached on the document
45
+ * and on the editor container. The editor container can set a flag to notify
46
+ * that the click was inside the editor and the document click handler can use
47
+ * this flag to call onClickOutside. This approach however has a few caveats
48
+ * - Click handler on the document is set using document.addEventListener
49
+ * - Click handler on the editor container is set using onClick prop
50
+ *
51
+ * This means if a child component inside the editor calls e.stopPropagation
52
+ * then the click handler on the editor container will not be called whereas
53
+ * document click handler will be called.
54
+ * https://github.com/facebook/react/issues/12518
55
+ *
56
+ * To solve this issue onClickCapture event is used.
57
+ */
58
+
59
+ class ClickOutside extends _react.default.Component {
60
+ constructor() {
61
+ super(...arguments);
62
+ (0, _defineProperty2.default)(this, "isClickedInside", false);
63
+ (0, _defineProperty2.default)(this, "handleDocumentClick", e => {
64
+ if (this.isClickedInside) {
65
+ this.isClickedInside = false;
66
+ return;
67
+ }
68
+ this.props.onClickOutside(e);
69
+ });
70
+ (0, _defineProperty2.default)(this, "handleMouseDown", () => {
71
+ this.isClickedInside = true;
72
+ });
73
+ }
74
+ componentDidMount() {
75
+ document.addEventListener('mousedown', this.handleDocumentClick);
76
+ }
77
+ componentWillUnmount() {
78
+ document.removeEventListener('mousedown', this.handleDocumentClick);
79
+ }
80
+ render() {
81
+ return /*#__PURE__*/_react.default.cloneElement(_react.default.Children.only(this.props.children), {
82
+ onMouseDownCapture: this.handleMouseDown
83
+ });
84
+ }
85
+ }
86
+ var _default = exports.default = ClickOutside;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _simpleEditor = _interopRequireDefault(require("../simple-editor"));
11
+ var _getPreviewContent = _interopRequireDefault(require("../../utils/get-preview-content"));
12
+ var _markdownPreview = _interopRequireDefault(require("../markdown-preview"));
13
+ var _longtextEditorDialog = _interopRequireDefault(require("../longtext-editor-dialog"));
14
+ require("./index.css");
15
+ const Editor = _ref => {
16
+ let {
17
+ lang,
18
+ headerName,
19
+ value: propsValue,
20
+ isWindowsWechat,
21
+ focusNodePath,
22
+ autoSave = true,
23
+ saveDelay = 60000,
24
+ isCheckBrowser = false,
25
+ editorApi,
26
+ onSaveEditorValue,
27
+ onEditorValueChanged
28
+ } = _ref;
29
+ const editorContainerRef = (0, _react.useRef)(null);
30
+ const editorRef = (0, _react.useRef)(null);
31
+ const [style, setStyle] = (0, _react.useState)({});
32
+ const [isValueChanged, setValueChanged] = (0, _react.useState)(false);
33
+ const [showExpandEditor, setShowExpandEditor] = (0, _react.useState)(false);
34
+ const [value, setValue] = (0, _react.useState)(typeof propsValue === 'string' ? {
35
+ text: propsValue
36
+ } : propsValue);
37
+ const saveValue = (0, _react.useCallback)(function (value) {
38
+ let save = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
39
+ setValueChanged(true);
40
+ setValue(value);
41
+ onEditorValueChanged && onEditorValueChanged(value);
42
+ if (!save) return;
43
+ onSaveEditorValue && onSaveEditorValue(value);
44
+ setValueChanged(false);
45
+ }, [onSaveEditorValue, onEditorValueChanged]);
46
+ const handelAutoSave = (0, _react.useCallback)(() => {
47
+ if (!isValueChanged) return;
48
+ saveValue(value, true);
49
+ }, [isValueChanged, value, saveValue]);
50
+ const onContentChanged = (0, _react.useCallback)(() => {
51
+ // delay to update editor's content
52
+ setTimeout(() => {
53
+ var _editorRef$current, _editorRef$current2;
54
+ // update parent's component cache value
55
+ const markdownString = (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getValue();
56
+ const slateNodes = (_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.getSlateValue();
57
+ const {
58
+ previewText,
59
+ images,
60
+ links,
61
+ checklist
62
+ } = (0, _getPreviewContent.default)(slateNodes, false);
63
+ const value = {
64
+ text: markdownString,
65
+ preview: previewText,
66
+ images: images,
67
+ links: links,
68
+ checklist
69
+ };
70
+ saveValue(value);
71
+ }, 0);
72
+ }, [saveValue]);
73
+ const openEditorDialog = (0, _react.useCallback)(() => {
74
+ const {
75
+ height
76
+ } = editorContainerRef.current.getBoundingClientRect();
77
+ setStyle({
78
+ height
79
+ });
80
+ setShowExpandEditor(true);
81
+ }, [editorContainerRef]);
82
+ const onCloseEditorDialog = (0, _react.useCallback)(value => {
83
+ value && saveValue(value);
84
+ setStyle({});
85
+ setShowExpandEditor(false);
86
+ }, [saveValue]);
87
+ (0, _react.useEffect)(() => {
88
+ let timer = null;
89
+ if (autoSave) {
90
+ timer = setTimeout(() => {
91
+ handelAutoSave();
92
+ }, saveDelay);
93
+ }
94
+ return () => {
95
+ timer && clearTimeout(timer);
96
+ };
97
+ }, [autoSave, saveDelay, handelAutoSave]);
98
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
99
+ className: "sf-long-text-inline-editor-container",
100
+ style: style,
101
+ ref: editorContainerRef
102
+ }, !showExpandEditor && !isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
103
+ isInline: true,
104
+ focusNodePath: focusNodePath,
105
+ ref: editorRef,
106
+ value: value.text,
107
+ onSave: handelAutoSave,
108
+ editorApi: editorApi,
109
+ onContentChanged: onContentChanged,
110
+ onExpandEditorToggle: openEditorDialog
111
+ }) : /*#__PURE__*/_react.default.createElement("div", {
112
+ className: "sf-simple-slate-editor-container"
113
+ }, /*#__PURE__*/_react.default.createElement("div", {
114
+ className: "sf-slate-editor-toolbar"
115
+ }), /*#__PURE__*/_react.default.createElement("div", {
116
+ className: "sf-slate-editor-content"
117
+ }, /*#__PURE__*/_react.default.createElement(_markdownPreview.default, {
118
+ isWindowsWechat: isWindowsWechat,
119
+ value: value.text,
120
+ isShowOutline: false
121
+ })))), showExpandEditor && /*#__PURE__*/_react.default.createElement(_longtextEditorDialog.default, {
122
+ lang: lang,
123
+ readOnly: false,
124
+ headerName: headerName,
125
+ value: value.text,
126
+ autoSave: autoSave,
127
+ saveDelay: saveDelay,
128
+ isCheckBrowser: isCheckBrowser,
129
+ editorApi: editorApi,
130
+ onSaveEditorValue: saveValue,
131
+ onEditorValueChanged: saveValue,
132
+ onCloseEditorDialog: onCloseEditorDialog
133
+ }));
134
+ };
135
+ var _default = exports.default = Editor;
@@ -0,0 +1,31 @@
1
+ .longtext-preview-container {
2
+ width: 100%;
3
+ height: 100%;
4
+ padding: 16px;
5
+ overflow: auto;
6
+ }
7
+
8
+ .longtext-preview-container .sf-slate-viewer-scroll-container {
9
+ overflow-y: auto;
10
+ height: fit-content;
11
+ padding: 0;
12
+ background: #fff;
13
+ }
14
+
15
+ .longtext-preview-container .sf-slate-viewer-article-container {
16
+ height: 100%;
17
+ width: 100%;
18
+ margin: 0;
19
+ }
20
+
21
+ .longtext-preview-container .sf-slate-viewer-article-container .article {
22
+ padding: 0;
23
+ height: auto;
24
+ min-height: 100% !important;
25
+ border: 0;
26
+ color: #212529;
27
+ }
28
+
29
+ .longtext-preview-container .article :first-child {
30
+ margin-top: 0;
31
+ }
@@ -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;
@@ -7,132 +7,108 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
- var _simpleEditor = _interopRequireDefault(require("../simple-editor"));
11
- var _getPreviewContent = _interopRequireDefault(require("../../utils/get-preview-content"));
10
+ var _isHotkey = _interopRequireDefault(require("is-hotkey"));
11
+ var _ClickOutside = _interopRequireDefault(require("./ClickOutside"));
12
+ var _formatter = _interopRequireDefault(require("./formatter"));
13
+ var _editor = _interopRequireDefault(require("./editor"));
14
+ var _slateConvert = require("../../slate-convert");
12
15
  var _getBrowserInfo = _interopRequireDefault(require("../../utils/get-browser-Info"));
13
- var _markdownPreview = _interopRequireDefault(require("../markdown-preview"));
14
- var _longtextEditorDialog = _interopRequireDefault(require("../longtext-editor-dialog"));
15
- require("./index.css");
16
- const LongTextInlineEditor = _ref => {
16
+ var _extension = require("../../extension");
17
+ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
17
18
  let {
19
+ autoSave,
20
+ isCheckBrowser,
21
+ saveDelay,
22
+ value,
18
23
  lang,
19
24
  headerName,
20
- value: propsValue,
21
- autoSave = true,
22
- saveDelay = 60000,
23
- isCheckBrowser = false,
24
- editorApi,
25
+ onPreviewClick,
25
26
  onSaveEditorValue,
26
- onEditorValueChanged
27
+ editorApi
27
28
  } = _ref;
28
- const editorContainerRef = (0, _react.useRef)(null);
29
- const editorRef = (0, _react.useRef)(null);
30
- const [style, setStyle] = (0, _react.useState)({});
31
- const [isValueChanged, setValueChanged] = (0, _react.useState)(false);
32
- const [showExpandEditor, setShowExpandEditor] = (0, _react.useState)(false);
33
- const [value, setValue] = (0, _react.useState)(typeof propsValue === 'string' ? {
34
- text: propsValue
35
- } : propsValue);
29
+ const [isShowEditor, setShowEditor] = (0, _react.useState)(false);
30
+ const valueRef = (0, _react.useRef)(typeof value === 'string' ? {
31
+ text: value
32
+ } : value);
33
+ const longTextValueChangedRef = (0, _react.useRef)(false);
34
+ const [focusNodePath, setFocusNodePath] = (0, _react.useState)([0, 0]);
36
35
  const {
37
36
  isWindowsWechat
38
37
  } = (0, _react.useMemo)(() => {
39
38
  return (0, _getBrowserInfo.default)(isCheckBrowser);
40
39
  }, [isCheckBrowser]);
41
- const saveValue = (0, _react.useCallback)(function (value) {
42
- let save = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
43
- setValueChanged(true);
44
- setValue(value);
45
- onEditorValueChanged && onEditorValueChanged(value);
46
- if (!save) return;
47
- onSaveEditorValue && onSaveEditorValue(value);
48
- setValueChanged(false);
49
- }, [onSaveEditorValue, onEditorValueChanged]);
50
- const handelAutoSave = (0, _react.useCallback)(() => {
51
- if (!isValueChanged) return;
52
- saveValue(value, true);
53
- }, [isValueChanged, value, saveValue]);
54
- const onContentChanged = (0, _react.useCallback)(() => {
55
- // delay to update editor's content
56
- setTimeout(() => {
57
- var _editorRef$current, _editorRef$current2;
58
- // update parent's component cache value
59
- const markdownString = (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getValue();
60
- const slateNodes = (_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.getSlateValue();
61
- const {
62
- previewText,
63
- images,
64
- links,
65
- checklist
66
- } = (0, _getPreviewContent.default)(slateNodes, false);
67
- const value = {
68
- text: markdownString,
69
- preview: previewText,
70
- images: images,
71
- links: links,
72
- checklist
73
- };
74
- saveValue(value);
75
- }, 0);
76
- }, [saveValue]);
77
- const openEditorDialog = (0, _react.useCallback)(() => {
78
- const {
79
- height
80
- } = editorContainerRef.current.getBoundingClientRect();
81
- setStyle({
82
- height
83
- });
84
- setShowExpandEditor(true);
85
- }, [editorContainerRef]);
86
- const onCloseEditorDialog = (0, _react.useCallback)(value => {
87
- value && saveValue(value);
88
- setStyle({});
89
- setShowExpandEditor(false);
90
- }, [saveValue]);
91
- (0, _react.useEffect)(() => {
92
- let timer = null;
93
- if (autoSave) {
94
- timer = setTimeout(() => {
95
- handelAutoSave();
96
- }, saveDelay);
40
+ const openEditor = (0, _react.useCallback)(function () {
41
+ let focusNodePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0];
42
+ setFocusNodePath(focusNodePath);
43
+ setShowEditor(true);
44
+ }, []);
45
+ const closeEditor = (0, _react.useCallback)(() => {
46
+ if (longTextValueChangedRef.current) {
47
+ onSaveEditorValue(valueRef.current);
97
48
  }
98
- return () => {
99
- timer && clearTimeout(timer);
49
+ setShowEditor(false);
50
+ }, [longTextValueChangedRef, valueRef, onSaveEditorValue]);
51
+ const getAttributeNode = (0, _react.useCallback)(function (node, attribute) {
52
+ let deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
53
+ if (!node || !node.getAttribute) return null;
54
+ if (deep === -1) return null;
55
+ if (node.getAttribute(attribute)) return node.getAttribute(attribute);
56
+ if (node.parentNode) return getAttributeNode(node.parentNode, attribute, deep--);
57
+ }, []);
58
+ const previewClick = (0, _react.useCallback)((event, richValue) => {
59
+ if (event.target.nodeName === 'A') return;
60
+ const nodeId = getAttributeNode(event.target, 'data-id');
61
+ onPreviewClick && onPreviewClick();
62
+ openEditor((0, _extension.getNodePathById)({
63
+ children: richValue
64
+ }, nodeId));
65
+ }, [onPreviewClick, openEditor, getAttributeNode]);
66
+ const onEditorValueChanged = (0, _react.useCallback)(value => {
67
+ valueRef.current = value;
68
+ longTextValueChangedRef.current = true;
69
+ }, []);
70
+ const onHotKey = (0, _react.useCallback)(event => {
71
+ const keyCode = event.keyCode;
72
+ const isModP = (0, _isHotkey.default)('mod+p', event);
73
+ if (keyCode === 27 || isModP) {
74
+ event.preventDefault();
75
+ !isModP && event.stopPropagation();
76
+ closeEditor();
77
+ return;
78
+ }
79
+ }, [closeEditor]);
80
+ (0, _react.useImperativeHandle)(ref, () => {
81
+ return {
82
+ openEditor: openEditor,
83
+ closeEditor: closeEditor
100
84
  };
101
- }, [autoSave, saveDelay, handelAutoSave]);
102
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
103
- className: "sf-long-text-inline-editor-container",
104
- style: style,
105
- ref: editorContainerRef
106
- }, !showExpandEditor && !isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
107
- isInline: true,
108
- ref: editorRef,
109
- value: value.text,
110
- onSave: handelAutoSave,
111
- editorApi: editorApi,
112
- onContentChanged: onContentChanged,
113
- onExpandEditorToggle: openEditorDialog
114
- }) : /*#__PURE__*/_react.default.createElement("div", {
115
- className: "sf-simple-slate-editor-container"
85
+ }, [openEditor, closeEditor]);
86
+ if (!isShowEditor) {
87
+ const richValue = (0, _slateConvert.mdStringToSlate)(valueRef.current.text);
88
+ return /*#__PURE__*/_react.default.createElement("div", {
89
+ className: "sf-long-text-inline-editor-container preview",
90
+ onClick: event => previewClick(event, richValue)
91
+ }, /*#__PURE__*/_react.default.createElement(_formatter.default, {
92
+ value: isWindowsWechat ? valueRef.current : richValue
93
+ }));
94
+ }
95
+ return /*#__PURE__*/_react.default.createElement(_ClickOutside.default, {
96
+ onClickOutside: closeEditor
116
97
  }, /*#__PURE__*/_react.default.createElement("div", {
117
- className: "sf-slate-editor-toolbar"
118
- }), /*#__PURE__*/_react.default.createElement("div", {
119
- className: "sf-slate-editor-content"
120
- }, /*#__PURE__*/_react.default.createElement(_markdownPreview.default, {
121
- isWindowsWechat: isWindowsWechat,
122
- value: value.text,
123
- isShowOutline: false
124
- })))), showExpandEditor && /*#__PURE__*/_react.default.createElement(_longtextEditorDialog.default, {
98
+ className: "w-100",
99
+ onKeyDown: onHotKey
100
+ }, /*#__PURE__*/_react.default.createElement(_editor.default, {
125
101
  lang: lang,
126
- readOnly: false,
102
+ isWindowsWechat: isWindowsWechat,
127
103
  headerName: headerName,
128
- value: value.text,
104
+ focusNodePath: focusNodePath,
105
+ value: valueRef.current.text,
129
106
  autoSave: autoSave,
130
107
  saveDelay: saveDelay,
131
108
  isCheckBrowser: isCheckBrowser,
132
109
  editorApi: editorApi,
133
- onSaveEditorValue: saveValue,
134
- onEditorValueChanged: saveValue,
135
- onCloseEditorDialog: onCloseEditorDialog
136
- }));
137
- };
110
+ onSaveEditorValue: onSaveEditorValue,
111
+ onEditorValueChanged: onEditorValueChanged
112
+ })));
113
+ });
138
114
  var _default = exports.default = LongTextInlineEditor;
@@ -26,8 +26,7 @@ class MarkdownPreview extends _react.default.PureComponent {
26
26
  });
27
27
  });
28
28
  this.state = {
29
- innerHtml: null,
30
- richValue: null
29
+ innerHtml: null
31
30
  };
32
31
  }
33
32
  componentDidMount() {
@@ -37,27 +36,20 @@ class MarkdownPreview extends _react.default.PureComponent {
37
36
  } = this.props;
38
37
  if (isWindowsWechat) {
39
38
  this.convertMarkdown(value);
40
- } else {
41
- const richValue = (0, _slateConvert.mdStringToSlate)(value);
42
- this.setState({
43
- richValue
44
- });
45
- this.props.beforeRenderCallback && this.props.beforeRenderCallback(richValue);
46
39
  }
47
40
  }
48
41
  render() {
49
42
  const {
50
43
  isWindowsWechat,
44
+ value,
51
45
  isShowOutline
52
46
  } = this.props;
53
47
  const {
54
- innerHtml,
55
- richValue
48
+ innerHtml
56
49
  } = this.state;
57
50
  if (isWindowsWechat && innerHtml === null) {
58
51
  return /*#__PURE__*/_react.default.createElement(_loading.default, null);
59
52
  }
60
- if (!isWindowsWechat && !richValue) return null;
61
53
  return /*#__PURE__*/_react.default.createElement("div", {
62
54
  className: "longtext-preview-container"
63
55
  }, isWindowsWechat && /*#__PURE__*/_react.default.createElement("div", {
@@ -66,7 +58,7 @@ class MarkdownPreview extends _react.default.PureComponent {
66
58
  __html: this.state.innerHtml
67
59
  }
68
60
  }), !isWindowsWechat && /*#__PURE__*/_react.default.createElement(_slateViewer.default, {
69
- value: richValue,
61
+ value: (0, _slateConvert.mdStringToSlate)(value),
70
62
  isShowOutline: isShowOutline
71
63
  }));
72
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.85beta",
3
+ "version": "1.0.85beta2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {