@seafile/sdoc-editor 0.1.79 → 0.1.80-beta
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/basic-sdk/editor.js +1 -0
- package/dist/basic-sdk/extension/plugins/code-block/helpers.js +5 -8
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +6 -9
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +30 -53
- package/dist/basic-sdk/hooks/use-article-width.js +11 -0
- package/package.json +1 -1
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -17,6 +17,7 @@ import CommentContextProvider from './comment/comment-context-provider';
|
|
|
17
17
|
import CommentWrapper from './comment';
|
|
18
18
|
import { usePipDecorate } from './decorates';
|
|
19
19
|
import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
|
|
20
|
+
import { ArticleContext } from './hooks/use-article-width';
|
|
20
21
|
import './assets/css/layout.css';
|
|
21
22
|
import './assets/css/sdoc-editor-plugins.css';
|
|
22
23
|
var SDocEditor = function SDocEditor(_ref) {
|
|
@@ -114,13 +114,10 @@ export var setClipboardData = function setClipboardData(value) {
|
|
|
114
114
|
return Node.string(line);
|
|
115
115
|
}).join('\n');
|
|
116
116
|
copy(text, {
|
|
117
|
-
format: 'text/plain'
|
|
117
|
+
format: 'text/plain',
|
|
118
|
+
onCopy: function onCopy(data) {
|
|
119
|
+
// Set the sdoc editor to format the data
|
|
120
|
+
data.setData('text/code-block', JSON.stringify(value));
|
|
121
|
+
}
|
|
118
122
|
});
|
|
119
|
-
|
|
120
|
-
// Store the code block data
|
|
121
|
-
var clipboardData = {
|
|
122
|
-
text: text,
|
|
123
|
-
codeBlockNode: value
|
|
124
|
-
};
|
|
125
|
-
sessionStorage.setItem('clipboardData', JSON.stringify(clipboardData));
|
|
126
123
|
};
|
|
@@ -22,11 +22,8 @@ var withCodeBlock = function withCodeBlock(editor) {
|
|
|
22
22
|
return insertText(data);
|
|
23
23
|
};
|
|
24
24
|
newEditor.insertData = function (data) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
storageText = _ref.text,
|
|
28
|
-
codeBlockNode = _ref.codeBlockNode;
|
|
29
|
-
if (codeBlockNode && text === storageText && !getSelectedNodeByType(editor, CODE_BLOCK)) {
|
|
25
|
+
if (data.types.includes('text/code-block') && !getSelectedNodeByType(editor, CODE_BLOCK)) {
|
|
26
|
+
var codeBlockNode = JSON.parse(data.getData('text/code-block'));
|
|
30
27
|
return insertNode(codeBlockNode);
|
|
31
28
|
}
|
|
32
29
|
return insertData(data);
|
|
@@ -95,10 +92,10 @@ var withCodeBlock = function withCodeBlock(editor) {
|
|
|
95
92
|
};
|
|
96
93
|
|
|
97
94
|
// Rewrite normalizeNode
|
|
98
|
-
newEditor.normalizeNode = function (
|
|
99
|
-
var
|
|
100
|
-
node =
|
|
101
|
-
path =
|
|
95
|
+
newEditor.normalizeNode = function (_ref) {
|
|
96
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
97
|
+
node = _ref2[0],
|
|
98
|
+
path = _ref2[1];
|
|
102
99
|
var type = getNodeType(node);
|
|
103
100
|
if (type === CODE_BLOCK) {
|
|
104
101
|
// code-block is the last node in the editor and needs to be followed by a p node
|
|
@@ -1,60 +1,37 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
|
-
import React from 'react';
|
|
2
|
+
import React, { useCallback } from 'react';
|
|
7
3
|
import { withTranslation } from 'react-i18next';
|
|
8
4
|
import { insertTable, isTableMenuDisabled } from '../../helpers';
|
|
9
5
|
import { TABLE, MENUS_CONFIG_MAP } from '../../../../constants';
|
|
10
6
|
import { MenuItem } from '../../../../menu';
|
|
11
7
|
import TableSizePopover from '../../popover/table-size-popover';
|
|
12
|
-
var TableMenu =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var menuConfig = MENUS_CONFIG_MAP[TABLE];
|
|
42
|
-
var props = _objectSpread(_objectSpread({
|
|
43
|
-
isRichEditor: isRichEditor,
|
|
44
|
-
className: className
|
|
45
|
-
}, menuConfig), {}, {
|
|
46
|
-
disabled: this.isDisabled(),
|
|
47
|
-
isActive: this.isActive(),
|
|
48
|
-
onMouseDown: function onMouseDown() {}
|
|
49
|
-
});
|
|
50
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
51
|
-
className: "table-menu"
|
|
52
|
-
}, /*#__PURE__*/React.createElement(MenuItem, props)), /*#__PURE__*/React.createElement(TableSizePopover, {
|
|
53
|
-
target: menuConfig.id,
|
|
54
|
-
createTable: this.createTable
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
}]);
|
|
58
|
-
return TableMenu;
|
|
59
|
-
}(React.Component);
|
|
8
|
+
var TableMenu = function TableMenu(_ref) {
|
|
9
|
+
var editor = _ref.editor,
|
|
10
|
+
isRichEditor = _ref.isRichEditor,
|
|
11
|
+
className = _ref.className;
|
|
12
|
+
var isActive = useCallback(function () {
|
|
13
|
+
return false;
|
|
14
|
+
}, []);
|
|
15
|
+
var isDisabled = useCallback(function () {
|
|
16
|
+
return isTableMenuDisabled(editor);
|
|
17
|
+
}, [editor]);
|
|
18
|
+
var createTable = useCallback(function (size) {
|
|
19
|
+
insertTable(editor, size);
|
|
20
|
+
}, [editor]);
|
|
21
|
+
var menuConfig = MENUS_CONFIG_MAP[TABLE];
|
|
22
|
+
var props = _objectSpread(_objectSpread({
|
|
23
|
+
isRichEditor: isRichEditor,
|
|
24
|
+
className: className
|
|
25
|
+
}, menuConfig), {}, {
|
|
26
|
+
disabled: isDisabled(),
|
|
27
|
+
isActive: isActive(),
|
|
28
|
+
onMouseDown: function onMouseDown() {}
|
|
29
|
+
});
|
|
30
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
31
|
+
className: "table-menu"
|
|
32
|
+
}, /*#__PURE__*/React.createElement(MenuItem, props)), /*#__PURE__*/React.createElement(TableSizePopover, {
|
|
33
|
+
target: menuConfig.id,
|
|
34
|
+
createTable: createTable
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
60
37
|
export default withTranslation('sdoc-editor')(TableMenu);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
export var ArticleContext = React.createContext(null);
|
|
3
|
+
export var useArticleWidth = function useArticleWidth() {
|
|
4
|
+
var context = useContext(ArticleContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error('The \`useArticleWidth\` hook must be used inside the <ArticleContext> component\'s context.');
|
|
7
|
+
}
|
|
8
|
+
var articleRef = context.articleRef;
|
|
9
|
+
if (!articleRef.current) return 0;
|
|
10
|
+
return articleRef.current.firstChild.clientWidth;
|
|
11
|
+
};
|