@seafile/sdoc-editor 0.1.128 → 0.1.130

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.
@@ -23,7 +23,8 @@
23
23
  .sdoc-code-block-code .sdoc-code-line::before {
24
24
  content: counter(number);
25
25
  color: #ccc;
26
- margin-right: 24px;
26
+ display: inline-block;
27
+ width: 40px;
27
28
  }
28
29
 
29
30
  .sdoc-code-line
@@ -0,0 +1,8 @@
1
+ /* modify default css */
2
+ .sdoc-editor-container .article {
3
+ font-size: 16px;
4
+ }
5
+
6
+ .sdoc-editor-container .sdoc-code-block-pre {
7
+ font-size: 14px;
8
+ }
@@ -51,6 +51,19 @@ var EditorComment = function EditorComment() {
51
51
  setComments([]);
52
52
  setIsShowComments(false);
53
53
  }, [element_comments_map, selectionElement, editor.selection]);
54
+ var onHiddenComment = useCallback(function (e) {
55
+ if (e.target.className === 'article') {
56
+ setComments([]);
57
+ setIsShowComments(false);
58
+ }
59
+ }, []);
60
+ useEffect(function () {
61
+ window.addEventListener('click', onHiddenComment);
62
+ return function () {
63
+ window.removeEventListener('click', onHiddenComment);
64
+ };
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ }, []);
54
67
  return /*#__PURE__*/React.createElement("div", {
55
68
  className: "sdoc-comment-container"
56
69
  }, /*#__PURE__*/React.createElement("div", {
@@ -31,7 +31,8 @@ var FONT_WEIGHT_400_700 = [400, 700];
31
31
  var FONT_WEIGHT_100_400_700 = [100, 400, 700];
32
32
  var FONT_WEIGHT_100_400_700_800 = [100, 400, 700, 800];
33
33
  export var SPECIAL_FONT_SIZE_NAME = ['初号', '小初', '一号', '小一', '二号', '小二', '三号', '小三', '四号', '小四', '五号', '小五'];
34
- export var DEFAULT_COMMON_FONT_SIZE = 14;
34
+ export var DEFAULT_COMMON_FONT_SIZE = 16;
35
+ export var DEFAULT_CODE_FONT_SIZE = 14;
35
36
  export var FONT_SIZE = [{
36
37
  name: '初号',
37
38
  value: 42,
@@ -5,7 +5,7 @@ import * as ELEMENT_TYPE from './element-type';
5
5
  import { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, CLEAR_FORMAT, COLOR, HIGHLIGHT_COLOR, SDOC_LINK } from './element-type';
6
6
  import KEYBOARD from './keyboard';
7
7
  import { DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_LIST, DEFAULT_FONT_COLOR, RECENT_USED_HIGHLIGHT_COLORS_KEY, RECENT_USED_FONT_COLORS_KEY, RECENT_USED_TABLE_CELL_BG_COLORS_KEY, DEFAULT_LAST_USED_FONT_COLOR, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, DEFAULT_LAST_USED_TABLE_CELL_BG_COLOR } from './color';
8
- import { SPECIAL_FONT_SIZE_NAME, DEFAULT_COMMON_FONT_SIZE, FONT_SIZE, DEFAULT_FONT, FONT, GOOGLE_FONT_CLASS, RECENT_USED_FONTS_KEY, HEADER_FONT_SIZE } from './font';
8
+ import { SPECIAL_FONT_SIZE_NAME, DEFAULT_COMMON_FONT_SIZE, FONT_SIZE, DEFAULT_FONT, FONT, GOOGLE_FONT_CLASS, RECENT_USED_FONTS_KEY, HEADER_FONT_SIZE, DEFAULT_CODE_FONT_SIZE } from './font';
9
9
 
10
10
  // history
11
11
  export var UNDO = 'undo';
@@ -232,4 +232,4 @@ export var SIDE_MENUS_CONFIG = [{
232
232
  type: BLOCKQUOTE,
233
233
  title: 'Quote'
234
234
  }];
235
- export { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ELEMENT_TYPE, KEYBOARD, DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_LIST, CLEAR_FORMAT, DEFAULT_FONT_COLOR, RECENT_USED_HIGHLIGHT_COLORS_KEY, RECENT_USED_FONT_COLORS_KEY, RECENT_USED_TABLE_CELL_BG_COLORS_KEY, DEFAULT_LAST_USED_FONT_COLOR, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, DEFAULT_LAST_USED_TABLE_CELL_BG_COLOR, SPECIAL_FONT_SIZE_NAME, DEFAULT_COMMON_FONT_SIZE, FONT_SIZE, DEFAULT_FONT, FONT, GOOGLE_FONT_CLASS, RECENT_USED_FONTS_KEY, HEADER_FONT_SIZE, SDOC_LINK };
235
+ export { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ELEMENT_TYPE, KEYBOARD, DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_LIST, CLEAR_FORMAT, DEFAULT_FONT_COLOR, RECENT_USED_HIGHLIGHT_COLORS_KEY, RECENT_USED_FONT_COLORS_KEY, RECENT_USED_TABLE_CELL_BG_COLORS_KEY, DEFAULT_LAST_USED_FONT_COLOR, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, DEFAULT_LAST_USED_TABLE_CELL_BG_COLOR, SPECIAL_FONT_SIZE_NAME, DEFAULT_COMMON_FONT_SIZE, DEFAULT_CODE_FONT_SIZE, FONT_SIZE, DEFAULT_FONT, FONT, GOOGLE_FONT_CLASS, RECENT_USED_FONTS_KEY, HEADER_FONT_SIZE, SDOC_LINK };
@@ -121,4 +121,11 @@ export var setClipboardData = function setClipboardData(value) {
121
121
  data.setData('text/code-block', JSON.stringify(value));
122
122
  }
123
123
  });
124
+ };
125
+ export var deleteBackwardByLength = function deleteBackwardByLength(editor, len) {
126
+ var i = len >= 4 ? 4 : len;
127
+ while (i > 0) {
128
+ Editor.deleteBackward(editor, 'word');
129
+ i--;
130
+ }
124
131
  };
@@ -1,9 +1,12 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import _toArray from "@babel/runtime/helpers/esm/toArray";
3
4
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
5
  import slugid from 'slugid';
5
- import { Transforms, Node, Range, Editor } from '@seafile/slate';
6
+ import isHotkey from 'is-hotkey';
7
+ import { Transforms, Node, Range, Editor, Path } from '@seafile/slate';
6
8
  import { getNodeType, isLastNode, getSelectedNodeByType, generateEmptyElement } from '../../core';
9
+ import { deleteBackwardByLength } from './helpers';
7
10
  import { CODE_BLOCK, PARAGRAPH, CODE_LINE } from '../../constants';
8
11
  var withCodeBlock = function withCodeBlock(editor) {
9
12
  var normalizeNode = editor.normalizeNode,
@@ -22,6 +25,25 @@ var withCodeBlock = function withCodeBlock(editor) {
22
25
  return insertText(data);
23
26
  };
24
27
  newEditor.insertData = function (data) {
28
+ if (!newEditor.insertFragmentData(data)) {
29
+ var plaintext = data.getData('text/plain') || '';
30
+ if (plaintext) {
31
+ var fragmentData = [];
32
+ plaintext.split('\n').forEach(function (item) {
33
+ var codeLine = {
34
+ id: slugid.nice(),
35
+ type: CODE_LINE,
36
+ children: [{
37
+ text: item,
38
+ id: slugid.nice()
39
+ }]
40
+ };
41
+ fragmentData.push(codeLine);
42
+ });
43
+ newEditor.insertFragment(fragmentData);
44
+ return;
45
+ }
46
+ }
25
47
  if (data.types.includes('text/code-block') && !getSelectedNodeByType(editor, CODE_BLOCK)) {
26
48
  var codeBlockNode = JSON.parse(data.getData('text/code-block'));
27
49
  return insertNode(codeBlockNode);
@@ -147,6 +169,34 @@ var withCodeBlock = function withCodeBlock(editor) {
147
169
  // Perform default behavior
148
170
  return normalizeNode([node, path]);
149
171
  };
172
+ newEditor.codeBlockOnKeyDown = function (event) {
173
+ if (isHotkey('command+enter', event)) {
174
+ if (newEditor.selection && !Range.isExpanded(newEditor.selection)) {
175
+ var path = Editor.path(newEditor, newEditor.selection);
176
+ var p = generateEmptyElement(PARAGRAPH);
177
+ Transforms.insertNodes(newEditor, p, {
178
+ at: [path[0] + 1]
179
+ });
180
+ Transforms.select(newEditor, [path[0] + 1]);
181
+ }
182
+ }
183
+ if (isHotkey('tab', event)) {
184
+ newEditor.insertText(' ');
185
+ }
186
+ if (isHotkey('shift+tab', event)) {
187
+ var range = {
188
+ anchor: {
189
+ offset: 0,
190
+ path: newEditor.selection.focus.path
191
+ },
192
+ focus: _objectSpread({}, newEditor.selection.focus)
193
+ };
194
+ var str = Editor.string(newEditor, range);
195
+ if (str.trim() === '') {
196
+ deleteBackwardByLength(newEditor, str.length);
197
+ }
198
+ }
199
+ };
150
200
  return newEditor;
151
201
  };
152
202
  export default withCodeBlock;
@@ -1,6 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import { Editor, Element } from '@seafile/slate';
3
- import { CODE_BLOCK, DEFAULT_COMMON_FONT_SIZE, IMAGE, FONT_SIZE, SPECIAL_FONT_SIZE_NAME, DEFAULT_FONT, GOOGLE_FONT_CLASS, FONT, HEADER_FONT_SIZE, HEADERS } from '../../constants';
3
+ import { CODE_BLOCK, DEFAULT_COMMON_FONT_SIZE, IMAGE, FONT_SIZE, SPECIAL_FONT_SIZE_NAME, DEFAULT_FONT, GOOGLE_FONT_CLASS, FONT, HEADER_FONT_SIZE, HEADERS, ELEMENT_TYPE, DEFAULT_CODE_FONT_SIZE } from '../../constants';
4
4
  import { focusEditor, getParentNode } from '../../core';
5
5
  import context from '../../../../context';
6
6
  import { isMac } from '../../../../utils';
@@ -33,10 +33,9 @@ export var getFontSize = function getFontSize(editor) {
33
33
  at: Editor.unhangRange(editor, selection),
34
34
  match: function match(n) {
35
35
  if (!Editor.isEditor(n) && !Element.isElement(n)) {
36
- // console.log(n) && n['font-size']
37
36
  if (n['font-size']) return true;
38
37
  var _parentNode = getParentNode(editor.children, n.id);
39
- if (_parentNode && HEADERS.includes(_parentNode.type)) {
38
+ if (_parentNode && (HEADERS.includes(_parentNode.type) || _parentNode.type === ELEMENT_TYPE.CODE_LINE)) {
40
39
  return true;
41
40
  }
42
41
  return false;
@@ -51,6 +50,7 @@ export var getFontSize = function getFontSize(editor) {
51
50
  if (matched['font-size']) return matched['font-size'];
52
51
  var parentNode = getParentNode(editor.children, matched.id);
53
52
  if (HEADERS.includes(parentNode.type)) return HEADER_FONT_SIZE[parentNode.type];
53
+ if (parentNode.type === ELEMENT_TYPE.CODE_LINE) return DEFAULT_CODE_FONT_SIZE;
54
54
  return DEFAULT_COMMON_FONT_SIZE;
55
55
  };
56
56
  export var setFontSize = function setFontSize(editor, value) {
@@ -1,9 +1,11 @@
1
1
  import { deserializeHtml } from './helper';
2
+ import { getSelectedNodeByType } from '../../core';
3
+ import { CODE_BLOCK } from '../../constants';
2
4
  var withHtml = function withHtml(editor) {
3
5
  var insertData = editor.insertData;
4
6
  var newEditor = editor;
5
7
  newEditor.insertData = function (data) {
6
- if (!newEditor.insertFragmentData(data)) {
8
+ if (!newEditor.insertFragmentData(data) && !getSelectedNodeByType(editor, CODE_BLOCK)) {
7
9
  var htmlContent = data.getData('text/html') || '';
8
10
  if (htmlContent) {
9
11
  var content = deserializeHtml(htmlContent);
@@ -1,10 +1,13 @@
1
- import { Transforms, Path } from '@seafile/slate';
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { Transforms, Path, Editor, Element } from '@seafile/slate';
2
3
  import context from '../../../../context';
3
4
  import { insertImage } from './helpers';
5
+ import { focusEditor } from '../../core';
4
6
  var withImage = function withImage(editor) {
5
7
  var isInline = editor.isInline,
6
8
  isVoid = editor.isVoid,
7
- insertData = editor.insertData;
9
+ insertData = editor.insertData,
10
+ deleteBackward = editor.deleteBackward;
8
11
  var newEditor = editor;
9
12
 
10
13
  // rewrite isInline
@@ -53,6 +56,18 @@ var withImage = function withImage(editor) {
53
56
  return;
54
57
  }
55
58
  };
59
+ newEditor.deleteBackward = function (unit) {
60
+ deleteBackward(unit);
61
+ // After the delete operation, if the selected image is selected, the cursor moves backward one position
62
+ var selection = editor.selection;
63
+ var _Editor$parent = Editor.parent(editor, selection),
64
+ _Editor$parent2 = _slicedToArray(_Editor$parent, 2),
65
+ node = _Editor$parent2[0],
66
+ path = _Editor$parent2[1];
67
+ if (Element.isElement(node) && node.type === 'image') {
68
+ focusEditor(editor, Path.next(path));
69
+ }
70
+ };
56
71
  return newEditor;
57
72
  };
58
73
  export default withImage;
@@ -3,6 +3,7 @@ import classnames from 'classnames';
3
3
  import { ColorProvider } from '../hooks/use-color-context';
4
4
  import { Toolbar } from '../extension';
5
5
  import { isMobile } from '../../utils';
6
+ import '../assets/css/default.css';
6
7
  import '../assets/css/layout.css';
7
8
  import '../assets/css/sdoc-editor-plugins.css';
8
9
  import '../assets/css/dropdown-menu.css';
@@ -79,6 +79,7 @@ var EventProxy = /*#__PURE__*/_createClass(function EventProxy(_editor) {
79
79
  _this.editor.imageOnKeyDown(event);
80
80
  }
81
81
  if (getSelectedNodeByType(editor, ELEMENT_TYPE.CODE_BLOCK)) {
82
+ _this.editor.codeBlockOnKeyDown(event);
82
83
  var eventBus = EventBus.getInstance();
83
84
  eventBus.dispatch(INTERNAL_EVENT.HIDDEN_CODE_BLOCK_HOVER_MENU);
84
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.128",
3
+ "version": "0.1.130",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",