@seafile/seafile-editor 1.0.82-alpha3 → 1.0.82-alpha5

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.
@@ -29,11 +29,11 @@ const SimpleSlateEditor = _ref => {
29
29
  onExpandEditorToggle
30
30
  } = _ref;
31
31
  const [slateValue, setSlateValue] = (0, _react.useState)(value);
32
- const editor = (0, _react.useMemo)(() => (0, _withPropsEditor.default)(_extension.baseEditor, {
32
+ const editor = (0, _react.useMemo)(() => (0, _withPropsEditor.default)(isInline ? _extension.inlineEditor : _extension.baseEditor, {
33
33
  editorApi,
34
34
  onSave,
35
35
  columns
36
- }), [columns, editorApi, onSave]);
36
+ }), [columns, editorApi, onSave, isInline]);
37
37
  const eventProxy = (0, _react.useMemo)(() => {
38
38
  return new _eventHandler.default(editor);
39
39
  }, [editor]);
@@ -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.createSlateEditor = exports.baseEditor = void 0;
7
+ exports.inlineEditor = exports.createSlateEditor = exports.baseEditor = void 0;
8
8
  var _slate = require("slate");
9
9
  var _slateHistory = require("slate-history");
10
10
  var _slateReact = require("slate-react");
@@ -16,6 +16,13 @@ const baseEditor = exports.baseEditor = _plugins.default.reduce((editor, pluginI
16
16
  }
17
17
  return editor;
18
18
  }, (0, _slateHistory.withHistory)((0, _slateReact.withReact)((0, _slate.createEditor)())));
19
+ const inlineEditor = exports.inlineEditor = _plugins.default.reduce((editor, pluginItem) => {
20
+ const withPlugin = pluginItem.editorPlugin;
21
+ if (withPlugin) {
22
+ return withPlugin(editor);
23
+ }
24
+ return editor;
25
+ }, (0, _slateHistory.withHistory)((0, _slateReact.withReact)((0, _slate.createEditor)())));
19
26
  const createSlateEditor = () => {
20
27
  const editor = _plugins.default.reduce((editor, pluginItem) => {
21
28
  const withPlugin = pluginItem.editorPlugin;
@@ -40,6 +40,12 @@ Object.defineProperty(exports, "createSlateEditor", {
40
40
  return _editor.createSlateEditor;
41
41
  }
42
42
  });
43
+ Object.defineProperty(exports, "inlineEditor", {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _editor.inlineEditor;
47
+ }
48
+ });
43
49
  Object.defineProperty(exports, "isEmptyParagraph", {
44
50
  enumerable: true,
45
51
  get: function () {
@@ -72,7 +72,9 @@ const InlineToolbar = _ref => {
72
72
  onClick: onHelpIconToggle
73
73
  }, /*#__PURE__*/_react.default.createElement("span", {
74
74
  className: "iconfont icon-use-help"
75
- })))), onExpandEditorToggle && /*#__PURE__*/_react.default.createElement(_commons.MenuGroup, null, onExpandEditorToggle && /*#__PURE__*/_react.default.createElement(_commons.ExpandEditorMenu, commonProps)), isShowHelpModal && /*#__PURE__*/_react.default.createElement(_shortcutDialog.default, {
75
+ })))), onExpandEditorToggle && /*#__PURE__*/_react.default.createElement(_commons.MenuGroup, null, onExpandEditorToggle && /*#__PURE__*/_react.default.createElement(_commons.ExpandEditorMenu, Object.assign({}, commonProps, {
76
+ onExpandEditorToggle: onExpandEditorToggle
77
+ }))), isShowHelpModal && /*#__PURE__*/_react.default.createElement(_shortcutDialog.default, {
76
78
  isRichEditor: isRichEditor,
77
79
  toggleShortcutDialog: onHelpIconToggle
78
80
  }));
package/dist/index.js CHANGED
@@ -22,6 +22,12 @@ Object.defineProperty(exports, "EventBus", {
22
22
  return _eventBus.default;
23
23
  }
24
24
  });
25
+ Object.defineProperty(exports, "InlineLongTextEditor", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _inlineLongtextEditor.default;
29
+ }
30
+ });
25
31
  Object.defineProperty(exports, "LongTextEditorDialog", {
26
32
  enumerable: true,
27
33
  get: function () {
@@ -106,6 +112,7 @@ var _markdownView = _interopRequireDefault(require("./pages/markdown-view"));
106
112
  var _simpleEditor = _interopRequireDefault(require("./pages/simple-editor"));
107
113
  var _emailEditorDialog = _interopRequireDefault(require("./pages/email-editor-dialog"));
108
114
  var _longtextEditorDialog = _interopRequireDefault(require("./pages/longtext-editor-dialog"));
115
+ var _inlineLongtextEditor = _interopRequireDefault(require("./pages/inline-longtext-editor"));
109
116
  var _markdownPreview = _interopRequireDefault(require("./pages/markdown-preview"));
110
117
  var _seatableEditor = _interopRequireDefault(require("./pages/seatable-editor"));
111
118
  var _seatableViewer = _interopRequireDefault(require("./pages/seatable-viewer"));
@@ -0,0 +1,60 @@
1
+ .sf-inline-editor-container {
2
+ width: 100%;
3
+ height: 100%;
4
+ border: 1px solid rgba(0, 40, 100, .12);
5
+ border-radius: 3px;
6
+ transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
7
+ }
8
+
9
+ .sf-inline-editor-container .sf-simple-slate-editor-container {
10
+ width: 100%;
11
+ height: 100%;
12
+ }
13
+
14
+ .sf-inline-editor-container .sf-slate-editor-toolbar {
15
+ border-top-left-radius: 3px;
16
+ border-top-right-radius: 3px;
17
+ height: 33px;
18
+ }
19
+
20
+ .sf-inline-editor-container .sf-slate-editor-content {
21
+ border-bottom-left-radius: 3px;
22
+ border-bottom-right-radius: 3px;
23
+ overflow: hidden;
24
+ }
25
+
26
+ .sf-inline-editor-container .sf-slate-editor-toolbar .sf-menu-group:last-child {
27
+ border-right: none;
28
+ }
29
+
30
+ .sf-inline-editor-container .sf-simple-slate-editor-container .sf-slate-editor-content {
31
+ flex: 1;
32
+ }
33
+
34
+ /* preview */
35
+ .sf-inline-editor-container .longtext-preview-container {
36
+ padding: 10px;
37
+ background-color: #fff;
38
+ }
39
+
40
+ .sf-inline-editor-container .longtext-preview-container .article h1 {
41
+ margin-top: 1.2em;
42
+ }
43
+
44
+ .sf-inline-editor-container .longtext-preview-container .article p {
45
+ margin-top: 0.8em;
46
+ }
47
+
48
+ .sf-slate-editor-toolbar .sf-menu-group {
49
+ padding-top: 4px;
50
+ padding-bottom: 4px;
51
+ }
52
+
53
+ .sf-editor-menu-popover .popover-inner {
54
+ display: flex;
55
+ }
56
+
57
+ .sf-editor-menu-popover .popover-inner .sf-menu-group {
58
+ padding-top: 4px;
59
+ padding-bottom: 4px;
60
+ }
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
- var _classnames = _interopRequireDefault(require("classnames"));
11
10
  var _simpleEditor = _interopRequireDefault(require("../simple-editor"));
12
11
  var _getPreviewContent = _interopRequireDefault(require("../../utils/get-preview-content"));
13
12
  var _getBrowserInfo = _interopRequireDefault(require("../../utils/get-browser-Info"));
@@ -18,7 +17,7 @@ const InlineLongTextEditor = _ref => {
18
17
  let {
19
18
  lang,
20
19
  headerName,
21
- value,
20
+ value: propsValue,
22
21
  autoSave = true,
23
22
  saveDelay = 60000,
24
23
  isCheckBrowser = false,
@@ -26,98 +25,112 @@ const InlineLongTextEditor = _ref => {
26
25
  onSaveEditorValue,
27
26
  onEditorValueChanged
28
27
  } = _ref;
28
+ const editorContainerRef = (0, _react.useRef)(null);
29
29
  const editorRef = (0, _react.useRef)(null);
30
+ const [style, setStyle] = (0, _react.useState)({});
30
31
  const [isValueChanged, setValueChanged] = (0, _react.useState)(false);
31
32
  const [showExpandEditor, setShowExpandEditor] = (0, _react.useState)(false);
33
+ const [value, setValue] = (0, _react.useState)(typeof propsValue === 'string' ? {
34
+ text: propsValue
35
+ } : propsValue);
32
36
  const {
33
- isValidBrowser,
34
37
  isWindowsWechat
35
38
  } = (0, _react.useMemo)(() => {
36
39
  return (0, _getBrowserInfo.default)(isCheckBrowser);
37
40
  }, [isCheckBrowser]);
38
- const onUpdateEditorValue = (0, _react.useCallback)(() => {
39
- var _editorRef$current, _editorRef$current2;
40
- if (!isValueChanged) return;
41
- const markdownString = (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getValue();
42
- const slateNodes = (_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.getSlateValue();
43
- const {
44
- previewText,
45
- images,
46
- links,
47
- checklist
48
- } = (0, _getPreviewContent.default)(slateNodes, false);
49
- onSaveEditorValue({
50
- text: markdownString,
51
- preview: previewText,
52
- images: images,
53
- links: links,
54
- checklist
55
- });
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);
56
48
  setValueChanged(false);
57
- }, [isValueChanged, onSaveEditorValue]);
49
+ }, [onSaveEditorValue, onEditorValueChanged]);
50
+ const handelAutoSave = (0, _react.useCallback)(() => {
51
+ if (!isValueChanged) return;
52
+ saveValue(value, true);
53
+ }, [isValueChanged, value, saveValue]);
58
54
  const onContentChanged = (0, _react.useCallback)(() => {
59
55
  // delay to update editor's content
60
56
  setTimeout(() => {
57
+ var _editorRef$current, _editorRef$current2;
61
58
  // update parent's component cache value
62
- if (onEditorValueChanged && typeof onEditorValueChanged === 'function') {
63
- var _editorRef$current3, _editorRef$current4;
64
- const markdownString = (_editorRef$current3 = editorRef.current) === null || _editorRef$current3 === void 0 ? void 0 : _editorRef$current3.getValue();
65
- const slateNodes = (_editorRef$current4 = editorRef.current) === null || _editorRef$current4 === void 0 ? void 0 : _editorRef$current4.getSlateValue();
66
- const {
67
- previewText,
68
- images,
69
- links,
70
- checklist
71
- } = (0, _getPreviewContent.default)(slateNodes, false);
72
- onEditorValueChanged({
73
- text: markdownString,
74
- preview: previewText,
75
- images: images,
76
- links: links,
77
- checklist
78
- });
79
- }
80
- setValueChanged(true);
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);
81
75
  }, 0);
82
- }, [onEditorValueChanged]);
76
+ }, [saveValue]);
83
77
  const openEditorDialog = (0, _react.useCallback)(() => {
78
+ const {
79
+ height
80
+ } = editorContainerRef.current.getBoundingClientRect();
81
+ setStyle({
82
+ height
83
+ });
84
84
  setShowExpandEditor(true);
85
- }, []);
86
- const onCloseEditorDialog = (0, _react.useCallback)(() => {
87
- onUpdateEditorValue();
85
+ }, [editorContainerRef]);
86
+ const onCloseEditorDialog = (0, _react.useCallback)(value => {
87
+ value && saveValue(value);
88
+ setStyle({});
88
89
  setShowExpandEditor(false);
89
- }, [onUpdateEditorValue]);
90
+ }, [saveValue]);
90
91
  (0, _react.useEffect)(() => {
91
92
  let timer = null;
92
93
  if (autoSave) {
93
94
  timer = setTimeout(() => {
94
- onUpdateEditorValue();
95
+ handelAutoSave();
95
96
  }, saveDelay);
96
97
  }
97
98
  return () => {
98
99
  timer && clearTimeout(timer);
99
100
  };
100
- }, [autoSave, saveDelay, onUpdateEditorValue]);
101
+ }, [autoSave, saveDelay, handelAutoSave]);
101
102
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
102
- className: "sf-inline-editor-container"
103
- }, !isWindowsWechat && /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
103
+ className: "sf-inline-editor-container",
104
+ style: style,
105
+ ref: editorContainerRef
106
+ }, !showExpandEditor && !isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
104
107
  isInline: true,
105
108
  ref: editorRef,
106
- value: value,
109
+ value: value.text,
107
110
  editorApi: editorApi,
108
111
  onContentChanged: onContentChanged,
109
112
  onExpandEditorToggle: openEditorDialog
110
- })), showExpandEditor && /*#__PURE__*/_react.default.createElement(_longtextEditorDialog.default, {
113
+ }) : /*#__PURE__*/_react.default.createElement("div", {
114
+ className: "sf-simple-slate-editor-container"
115
+ }, /*#__PURE__*/_react.default.createElement("div", {
116
+ className: "sf-slate-editor-toolbar"
117
+ }), /*#__PURE__*/_react.default.createElement("div", {
118
+ className: "sf-slate-editor-content"
119
+ }, /*#__PURE__*/_react.default.createElement(_markdownPreview.default, {
120
+ isWindowsWechat: isWindowsWechat,
121
+ value: value.text,
122
+ isShowOutline: false
123
+ })))), showExpandEditor && /*#__PURE__*/_react.default.createElement(_longtextEditorDialog.default, {
111
124
  lang: lang,
112
125
  readOnly: false,
113
126
  headerName: headerName,
114
- value: value,
127
+ value: value.text,
115
128
  autoSave: autoSave,
116
129
  saveDelay: saveDelay,
117
130
  isCheckBrowser: isCheckBrowser,
118
131
  editorApi: editorApi,
119
- onSaveEditorValue: onSaveEditorValue,
120
- onEditorValueChanged: onEditorValueChanged,
132
+ onSaveEditorValue: saveValue,
133
+ onEditorValueChanged: saveValue,
121
134
  onCloseEditorDialog: onCloseEditorDialog
122
135
  }));
123
136
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.82alpha3",
3
+ "version": "1.0.82alpha5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {