@seafile/seafile-editor 1.0.82-alpha2 → 1.0.82-alpha4

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,18 +29,18 @@ 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]);
40
- const decorate = (0, _extension.useHighlight)(editor);
41
40
  const ToolbarComponent = (0, _react.useMemo)(() => {
42
41
  return isInline ? _extension.InlineToolbar : _extension.Toolbar;
43
42
  }, [isInline]);
43
+ const decorate = (0, _extension.useHighlight)(editor);
44
44
  const onChange = (0, _react.useCallback)(value => {
45
45
  setSlateValue(value);
46
46
  if (editor.forceNormalize) return;
@@ -115,4 +115,8 @@
115
115
 
116
116
  .sf-dropdown-list .sf-dropdown-list-item:hover {
117
117
  background-color: #F2F2F2;
118
- }
118
+ }
119
+
120
+ .sf-icon-btn-hover:hover {
121
+ cursor: pointer;
122
+ }
@@ -2,3 +2,23 @@
2
2
  padding: 8px 0;
3
3
  min-width: 12rem;
4
4
  }
5
+
6
+ .sf-editor-menu-popover .popover-inner .sf-slate-help-info-control {
7
+ height: 24px;
8
+ width: 24px;
9
+ margin: 4px 8px;
10
+ display: flex;
11
+ align-items: center;
12
+ justify-content: center;
13
+ }
14
+
15
+ .sf-editor-menu-popover .popover-inner .sf-slate-help-info-control:hover {
16
+ background-color: #f2f2f2;
17
+ border-radius: 2px;
18
+ cursor: pointer;
19
+ }
20
+
21
+ .sf-editor-menu-popover .popover-inner .sf-slate-help-info-control .icon-use-help {
22
+ font-size: 13px;
23
+ color: #555;
24
+ }
@@ -32,7 +32,7 @@ const MoreMenu = _ref => {
32
32
  className: config.iconClass
33
33
  })), /*#__PURE__*/_react.default.createElement(_reactstrap.UncontrolledPopover, {
34
34
  target: config.id,
35
- className: "sf-editor-menu-popover",
35
+ className: "sf-editor-menu-popover sf-editor--more-menu-popover",
36
36
  trigger: "legacy",
37
37
  placement: "bottom-end",
38
38
  hideArrow: true,
@@ -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 () {
@@ -53,6 +53,9 @@ const withCodeBlock = editor => {
53
53
  if (node.type === _elementTypes.CODE_BLOCK) {
54
54
  const codeLineArr = node.children.map(line => line);
55
55
  data.splice(index, 1, ...codeLineArr);
56
+ // Paste the copied content in place in code_block
57
+ } else if (node.type === _elementTypes.CODE_LINE) {
58
+ data.splice(index, 1, node);
56
59
  }
57
60
  });
58
61
  const insertCodeLines = data.map(node => {
@@ -65,6 +68,12 @@ const withCodeBlock = editor => {
65
68
 
66
69
  // Current focus code-line string not empty
67
70
  const string = _slate.Editor.string(newEditor, newEditor.selection.focus.path);
71
+ // Paste the copied content in place in code_block
72
+ if (insertCodeLines.length === 1 && _slate.Range.isExpanded(newEditor.selection)) {
73
+ const text = _slate.Node.string(insertCodeLines[0]);
74
+ insertText(text);
75
+ return;
76
+ }
68
77
  if (string.length !== 0 && _slate.Range.isCollapsed(newEditor.selection)) {
69
78
  const [node, ...restNode] = insertCodeLines;
70
79
  const text = _slate.Node.string(node);
@@ -18,7 +18,7 @@ const withHtml = editor => {
18
18
  newEditor.insertData = data => {
19
19
  // If the text is a link and is not within the code_block block, it is processed as link
20
20
  const text = data.getData('text/plain') || '';
21
- if ((0, _isUrl.default)(text) && !(0, _helpers.isInCodeBlock)(newEditor)) {
21
+ if (text.trim() && (0, _isUrl.default)(text.trim()) && !(0, _helpers.isInCodeBlock)(newEditor)) {
22
22
  insertData(data);
23
23
  return;
24
24
  }
@@ -110,7 +110,7 @@ var _formula = _interopRequireDefault(require("./formula"));
110
110
  var _column = _interopRequireDefault(require("./column"));
111
111
  var _markdown = _interopRequireDefault(require("./markdown"));
112
112
  var _html = _interopRequireDefault(require("./html"));
113
- const Plugins = [_paragraph.default, _textStyle.default, _header.default, _image.default, _link.default, _codeBlock.default, _checkList.default, _list.default, _table.default, _blockquote.default, _formula.default, _markdown.default, _html.default, _column.default,
113
+ const Plugins = [_paragraph.default, _textStyle.default, _header.default, _image.default, _link.default, _checkList.default, _list.default, _codeBlock.default, _table.default, _blockquote.default, _formula.default, _markdown.default, _html.default, _column.default,
114
114
  // put at the end
115
115
  _nodeId.default];
116
116
  var _default = exports.default = Plugins;
@@ -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.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,104 +17,118 @@ 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,
25
24
  editorApi,
26
- onSaveEditorValue,
27
- onEditorValueChanged
25
+ onSaveEditorValue
28
26
  } = _ref;
27
+ const editorContainerRef = (0, _react.useRef)(null);
29
28
  const editorRef = (0, _react.useRef)(null);
29
+ const [style, setStyle] = (0, _react.useState)({});
30
30
  const [isValueChanged, setValueChanged] = (0, _react.useState)(false);
31
31
  const [showExpandEditor, setShowExpandEditor] = (0, _react.useState)(false);
32
+ const [value, setValue] = (0, _react.useState)(typeof propsValue === 'string' ? {
33
+ text: propsValue
34
+ } : propsValue);
32
35
  const {
33
- isValidBrowser,
34
36
  isWindowsWechat
35
37
  } = (0, _react.useMemo)(() => {
36
38
  return (0, _getBrowserInfo.default)(isCheckBrowser);
37
39
  }, [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
- });
40
+ const saveValue = (0, _react.useCallback)(function (value) {
41
+ let save = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
42
+ setValueChanged(true);
43
+ setValue(value);
44
+ if (!save) return;
45
+ onSaveEditorValue && onSaveEditorValue(value);
56
46
  setValueChanged(false);
57
- }, [isValueChanged, onSaveEditorValue]);
47
+ }, [onSaveEditorValue]);
48
+ const handelAutoSave = (0, _react.useCallback)(() => {
49
+ if (!isValueChanged) return;
50
+ saveValue(value, true);
51
+ }, [isValueChanged, value, saveValue]);
58
52
  const onContentChanged = (0, _react.useCallback)(() => {
59
53
  // delay to update editor's content
60
54
  setTimeout(() => {
55
+ var _editorRef$current, _editorRef$current2;
61
56
  // 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);
57
+ const markdownString = (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 ? void 0 : _editorRef$current.getValue();
58
+ const slateNodes = (_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.getSlateValue();
59
+ const {
60
+ previewText,
61
+ images,
62
+ links,
63
+ checklist
64
+ } = (0, _getPreviewContent.default)(slateNodes, false);
65
+ const value = {
66
+ text: markdownString,
67
+ preview: previewText,
68
+ images: images,
69
+ links: links,
70
+ checklist
71
+ };
72
+ saveValue(value);
81
73
  }, 0);
82
- }, [onEditorValueChanged]);
74
+ }, [saveValue]);
83
75
  const openEditorDialog = (0, _react.useCallback)(() => {
76
+ const {
77
+ height
78
+ } = editorContainerRef.current.getBoundingClientRect();
79
+ setStyle({
80
+ height
81
+ });
84
82
  setShowExpandEditor(true);
85
- }, []);
86
- const onCloseEditorDialog = (0, _react.useCallback)(() => {
87
- onUpdateEditorValue();
83
+ }, [editorContainerRef]);
84
+ const onCloseEditorDialog = (0, _react.useCallback)(value => {
85
+ value && saveValue(value);
86
+ setStyle({});
88
87
  setShowExpandEditor(false);
89
- }, [onUpdateEditorValue]);
88
+ }, [saveValue]);
90
89
  (0, _react.useEffect)(() => {
91
90
  let timer = null;
92
91
  if (autoSave) {
93
92
  timer = setTimeout(() => {
94
- onUpdateEditorValue();
93
+ handelAutoSave();
95
94
  }, saveDelay);
96
95
  }
97
96
  return () => {
98
97
  timer && clearTimeout(timer);
99
98
  };
100
- }, [autoSave, saveDelay, onUpdateEditorValue]);
101
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", null, !isWindowsWechat && /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
99
+ }, [autoSave, saveDelay, handelAutoSave]);
100
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
101
+ className: "sf-inline-editor-container",
102
+ style: style,
103
+ ref: editorContainerRef
104
+ }, !showExpandEditor && !isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
102
105
  isInline: true,
103
106
  ref: editorRef,
104
- value: value,
107
+ value: value.text,
105
108
  editorApi: editorApi,
106
109
  onContentChanged: onContentChanged,
107
110
  onExpandEditorToggle: openEditorDialog
108
- })), showExpandEditor && /*#__PURE__*/_react.default.createElement(_longtextEditorDialog.default, {
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, {
109
122
  lang: lang,
110
123
  readOnly: false,
111
124
  headerName: headerName,
112
- value: value,
125
+ value: value.text,
113
126
  autoSave: autoSave,
114
127
  saveDelay: saveDelay,
115
128
  isCheckBrowser: isCheckBrowser,
116
129
  editorApi: editorApi,
117
- onSaveEditorValue: onSaveEditorValue,
118
- onEditorValueChanged: onEditorValueChanged,
130
+ onSaveEditorValue: saveValue,
131
+ onEditorValueChanged: saveValue,
119
132
  onCloseEditorDialog: onCloseEditorDialog
120
133
  }));
121
134
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.82alpha2",
3
+ "version": "1.0.82alpha4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {