@seafile/seafile-editor 0.4.4 → 0.4.6
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/README.md +2 -1
- package/dist/components/load-script/index.js +1 -2
- package/dist/components/toast/toastManager.js +4 -0
- package/dist/containers/custom/split-nodes-at-point.js +1 -1
- package/dist/containers/editor-utils/block-element-utils/code-utils.js +6 -0
- package/dist/containers/editor-utils/block-element-utils/list-utils.js +11 -3
- package/dist/containers/editor-utils/text-utils.js +5 -8
- package/dist/editors/markdown-editor.js +1 -0
- package/dist/editors/plain-markdown-editor.js +4 -0
- package/dist/index.js +2 -1
- package/dist/utils/diff/compare-strings.js +1 -3
- package/dist/utils/diff/diff.js +2 -6
- package/dist/utils/utils.js +20 -20
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ var LoadScript = /*#__PURE__*/function (_React$Component) {
|
|
|
14
14
|
var _this;
|
|
15
15
|
_classCallCheck(this, LoadScript);
|
|
16
16
|
_this = _super.call(this, props);
|
|
17
|
+
// load mathjax
|
|
17
18
|
_this.loadScript = function () {
|
|
18
19
|
if (!_this.props.scriptSource) return;
|
|
19
20
|
if (!document.querySelector('#mathjax')) {
|
|
@@ -56,8 +57,6 @@ var LoadScript = /*#__PURE__*/function (_React$Component) {
|
|
|
56
57
|
}
|
|
57
58
|
return _this;
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
// load mathjax
|
|
61
60
|
_createClass(LoadScript, [{
|
|
62
61
|
key: "render",
|
|
63
62
|
value: function render() {
|
|
@@ -79,6 +79,10 @@ var ToastManager = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
79
79
|
intent: settings.intent
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* This will set isShown on the Toast which will close the toast.
|
|
84
|
+
* It won't remove the toast until onExited triggers onRemove.
|
|
85
|
+
*/
|
|
82
86
|
_this.closeToast = function (id) {
|
|
83
87
|
_this.setState(function (previousState) {
|
|
84
88
|
return {
|
|
@@ -92,7 +92,7 @@ var splitNodesAtPoint = function splitNodesAtPoint(editor) {
|
|
|
92
92
|
var isEnd = Editor.isEnd(editor, _point, path);
|
|
93
93
|
if (always || !beforeRef || !Editor.isEdge(editor, _point, path)) {
|
|
94
94
|
split = true;
|
|
95
|
-
var
|
|
95
|
+
var _text = node.text,
|
|
96
96
|
children = node.children,
|
|
97
97
|
properties = _objectWithoutProperties(node, _excluded);
|
|
98
98
|
editor.apply({
|
|
@@ -51,6 +51,12 @@ var CodeUtils = /*#__PURE__*/function () {
|
|
|
51
51
|
});
|
|
52
52
|
_this.insertIndent(indent);
|
|
53
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Todo: unwrap code block
|
|
56
|
+
* split: Is split the code block at selection when unwrap node
|
|
57
|
+
* split = true: Unwrap current code line from code block
|
|
58
|
+
* split = false: Unwrap whole code block
|
|
59
|
+
*/
|
|
54
60
|
this.unwrapCodeBlock = function () {
|
|
55
61
|
var split = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
56
62
|
var codeBlock = SfEditor.match(_this.editor, _this.editor.selection, {
|
|
@@ -158,6 +158,7 @@ var LitsUtils = /*#__PURE__*/_createClass(function LitsUtils(editor) {
|
|
|
158
158
|
});
|
|
159
159
|
});
|
|
160
160
|
};
|
|
161
|
+
// unwrap list wrap list
|
|
161
162
|
this.getCurrentListItem = function () {
|
|
162
163
|
var selection = _this.editor.selection;
|
|
163
164
|
if (!selection) {
|
|
@@ -214,11 +215,11 @@ var LitsUtils = /*#__PURE__*/_createClass(function LitsUtils(editor) {
|
|
|
214
215
|
var _endItem = _slicedToArray(endItem, 2),
|
|
215
216
|
endPath = _endItem[1];
|
|
216
217
|
if (Path.equals(startPath, endPath)) {
|
|
217
|
-
var
|
|
218
|
-
if (!
|
|
218
|
+
var _blockParent = Node.parent(_this.editor, startPath);
|
|
219
|
+
if (!_blockParent.type || _blockParent.type.indexOf('list') < 0) {
|
|
219
220
|
return [];
|
|
220
221
|
}
|
|
221
|
-
return [[
|
|
222
|
+
return [[_blockParent, startPath.slice(0, -1)]];
|
|
222
223
|
}
|
|
223
224
|
var commonPath = Path.common(focusPath, anchorPath);
|
|
224
225
|
var commonAncestor = Node.get(_this.editor, commonPath);
|
|
@@ -289,6 +290,13 @@ var LitsUtils = /*#__PURE__*/_createClass(function LitsUtils(editor) {
|
|
|
289
290
|
if (node.length > 0) return true;
|
|
290
291
|
return false;
|
|
291
292
|
};
|
|
293
|
+
/**
|
|
294
|
+
* When copying a sublist, the list item in the list returned by slate contains only one sublis,
|
|
295
|
+
* pasting the list item directly into the list will produce an incorrect list structure,
|
|
296
|
+
* the list item that contains only one list need to flatten
|
|
297
|
+
* Input: {type: 'list', children: [{type: 'list_item', children: [{type: 'list', children[{type: 'list_item'}, ...]}]}]}
|
|
298
|
+
* Output: [{type: 'list_item'},....]
|
|
299
|
+
*/
|
|
292
300
|
this.getNormalizedListItems = function (list) {
|
|
293
301
|
var listItems = [];
|
|
294
302
|
list.children.forEach(function (listItem) {
|
|
@@ -10,6 +10,10 @@ var CODEREG = /\`(\S+)\`/;
|
|
|
10
10
|
var TextUtils = /*#__PURE__*/_createClass(function TextUtils(_editor) {
|
|
11
11
|
var _this = this;
|
|
12
12
|
_classCallCheck(this, TextUtils);
|
|
13
|
+
// Get text related variables before current selection
|
|
14
|
+
// block: Parent of current text node
|
|
15
|
+
// range: From start of block to current selection
|
|
16
|
+
// beforeText: The text of block from start to selection
|
|
13
17
|
this.getTextInfoBeforeSelection = function () {
|
|
14
18
|
var editor = _this.editor;
|
|
15
19
|
var selection = _this.editor.selection;
|
|
@@ -109,12 +113,5 @@ var TextUtils = /*#__PURE__*/_createClass(function TextUtils(_editor) {
|
|
|
109
113
|
exec(command);
|
|
110
114
|
};
|
|
111
115
|
this.editor = _editor;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Get text related variables before current selection
|
|
115
|
-
// block: Parent of current text node
|
|
116
|
-
// range: From start of block to current selection
|
|
117
|
-
// beforeText: The text of block from start to selection
|
|
118
|
-
);
|
|
119
|
-
|
|
116
|
+
});
|
|
120
117
|
export default TextUtils;
|
|
@@ -109,6 +109,7 @@ var MarkdownEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
109
109
|
_this.editorRef.firstChild.focus();
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
+
// provide the api to seahub to insert files of library
|
|
112
113
|
_this.addLink = function (fileName, url, isImage) {
|
|
113
114
|
var selection = _this.editor.selection;
|
|
114
115
|
if (isImage) {
|
|
@@ -146,6 +146,10 @@ var PlainMarkdownEditor = /*#__PURE__*/function (_React$Component2) {
|
|
|
146
146
|
leftIsBindScroll: false,
|
|
147
147
|
rightIsBindScroll: false
|
|
148
148
|
};
|
|
149
|
+
/*
|
|
150
|
+
* the data about scroll, these variable has nothing to width react
|
|
151
|
+
* they are not state
|
|
152
|
+
* */
|
|
149
153
|
_this3.scrollData = {
|
|
150
154
|
scrollPercentage: 0,
|
|
151
155
|
leftPanel: null,
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ReactEditor } from '@seafile/slate-react';
|
|
1
2
|
import Toolbar from './components/toolbar';
|
|
2
3
|
import Outline from './components/outline';
|
|
3
4
|
import UserHelp from './components/user-help';
|
|
@@ -7,4 +8,4 @@ import { processor } from './utils/seafile-markdown2html';
|
|
|
7
8
|
import { replaceColumnData } from './utils/utils';
|
|
8
9
|
import { MarkdownEditor, SimpleEditor, PlainMarkdownEditor, SeatableEditor } from './editors';
|
|
9
10
|
import { DiffViewer, MarkdownViewer, SeatableViewer } from './viewer';
|
|
10
|
-
export { EditorContext, MarkdownEditor, SimpleEditor, PlainMarkdownEditor, DiffViewer, MarkdownViewer, SeatableViewer, Toolbar, Outline, UserHelp, deserialize, serialize, processor, SeatableEditor, replaceColumnData };
|
|
11
|
+
export { ReactEditor, EditorContext, MarkdownEditor, SimpleEditor, PlainMarkdownEditor, DiffViewer, MarkdownViewer, SeatableViewer, Toolbar, Outline, UserHelp, deserialize, serialize, processor, SeatableEditor, replaceColumnData };
|
|
@@ -25,9 +25,7 @@ function flattenDeep(arr) {
|
|
|
25
25
|
}
|
|
26
26
|
function letterPairs(str) {
|
|
27
27
|
var pairs = [];
|
|
28
|
-
for (var i = 0, max = str.length - 1; i < max; i++)
|
|
29
|
-
pairs[i] = str.substring(i, i + 2);
|
|
30
|
-
}
|
|
28
|
+
for (var i = 0, max = str.length - 1; i < max; i++) pairs[i] = str.substring(i, i + 2);
|
|
31
29
|
return pairs;
|
|
32
30
|
}
|
|
33
31
|
function wordLetterPairs(str) {
|
package/dist/utils/diff/diff.js
CHANGED
|
@@ -389,9 +389,7 @@ var Diff = /*#__PURE__*/function () {
|
|
|
389
389
|
var o = 0;
|
|
390
390
|
var table = [];
|
|
391
391
|
table[newLength] = [];
|
|
392
|
-
for (o = oldLength; o >= 0; table[newLength][o--] = 0)
|
|
393
|
-
;
|
|
394
|
-
}
|
|
392
|
+
for (o = oldLength; o >= 0; table[newLength][o--] = 0);
|
|
395
393
|
for (n = newLength - 1; n >= 0; n--) {
|
|
396
394
|
table[n] = [];
|
|
397
395
|
table[n][oldLength] = 0;
|
|
@@ -447,9 +445,7 @@ var Diff = /*#__PURE__*/function () {
|
|
|
447
445
|
|
|
448
446
|
// Build out the table
|
|
449
447
|
table[newLength] = [];
|
|
450
|
-
for (o = oldLength; o >= 0; table[newLength][o--] = 0)
|
|
451
|
-
;
|
|
452
|
-
}
|
|
448
|
+
for (o = oldLength; o >= 0; table[newLength][o--] = 0);
|
|
453
449
|
for (n = newLength - 1; n >= 0; n--) {
|
|
454
450
|
table[n] = [];
|
|
455
451
|
table[n][oldLength] = 0;
|
package/dist/utils/utils.js
CHANGED
|
@@ -26,34 +26,31 @@ export var isEmptyParagraph = function isEmptyParagraph(node) {
|
|
|
26
26
|
|
|
27
27
|
// root -> paragraph ->
|
|
28
28
|
export var replaceColumnData = function replaceColumnData(mdNodes, columns, getCellValue, updateImgUrl) {
|
|
29
|
-
|
|
29
|
+
var _loop = function _loop() {
|
|
30
30
|
var node = mdNodes[i];
|
|
31
31
|
if (node.type === 'column') {
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return "continue";
|
|
46
|
-
}();
|
|
47
|
-
if (_ret === "continue") continue;
|
|
32
|
+
var data = node.data;
|
|
33
|
+
var column = columns.find(function (column) {
|
|
34
|
+
return column.key === data.key;
|
|
35
|
+
});
|
|
36
|
+
var value = column ? getCellValue && getCellValue(column) : '';
|
|
37
|
+
// change column node to text node
|
|
38
|
+
var newNode = {
|
|
39
|
+
'text': value,
|
|
40
|
+
"BOLD": data.bold,
|
|
41
|
+
"ITALIC": data.italic
|
|
42
|
+
};
|
|
43
|
+
mdNodes.splice(i, 1, newNode);
|
|
44
|
+
return 1; // continue
|
|
48
45
|
}
|
|
49
46
|
// replace image node's src
|
|
50
47
|
if (node.type === 'image') {
|
|
51
|
-
var
|
|
48
|
+
var _data = node.data || {
|
|
52
49
|
src: ''
|
|
53
50
|
};
|
|
54
51
|
if (updateImgUrl && typeof updateImgUrl === 'function') {
|
|
55
|
-
var src = updateImgUrl(
|
|
56
|
-
var newData = _objectSpread(_objectSpread({},
|
|
52
|
+
var src = updateImgUrl(_data.src);
|
|
53
|
+
var newData = _objectSpread(_objectSpread({}, _data), {
|
|
57
54
|
src: src
|
|
58
55
|
});
|
|
59
56
|
node.data = newData;
|
|
@@ -64,5 +61,8 @@ export var replaceColumnData = function replaceColumnData(mdNodes, columns, getC
|
|
|
64
61
|
var nodes = node.children;
|
|
65
62
|
replaceColumnData(nodes, columns, getCellValue, updateImgUrl);
|
|
66
63
|
}
|
|
64
|
+
};
|
|
65
|
+
for (var i = 0; i < mdNodes.length; i++) {
|
|
66
|
+
if (_loop()) continue;
|
|
67
67
|
}
|
|
68
68
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/seafile-editor",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This is a custom markdown editor",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@seafile/react-image-lightbox": "2.0.2",
|
|
9
|
-
"@seafile/slate-react": "
|
|
9
|
+
"@seafile/slate-react": "0.54.13",
|
|
10
10
|
"codemirror": "^5.37.0",
|
|
11
11
|
"deepmerge": "^2.1.0",
|
|
12
12
|
"detect-indent": "^4.0.0",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"remark-parse": "^5.0.0",
|
|
28
28
|
"remark-rehype": "^3.0.0",
|
|
29
29
|
"remark-slug": "^5.0.0",
|
|
30
|
-
"slate": "
|
|
31
|
-
"slate-history": "
|
|
30
|
+
"slate": "0.54.2",
|
|
31
|
+
"slate-history": "0.54.2",
|
|
32
32
|
"slate-hyperscript": "0.54.2",
|
|
33
33
|
"unified": "7.0.0",
|
|
34
34
|
"url-parse": "^1.4.3",
|