@seafile/sdoc-editor 0.4.37 → 0.5.1

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.
@@ -26,7 +26,7 @@ const HistoryFiles = _ref => {
26
26
  const historyFilesInputRef = useRef();
27
27
  const [files, setFiles] = useState([]);
28
28
  const [position, setPosition] = useState({});
29
- const [header, setHeader] = useState(t('Recent_previews'));
29
+ const [header, setHeader] = useState(t('Recent_visited'));
30
30
  const [newFileName, setNewFileName] = useState('');
31
31
  const getPosition = useCallback(() => {
32
32
  const {
@@ -109,7 +109,7 @@ const HistoryFiles = _ref => {
109
109
 
110
110
  // Show history files when search is empty
111
111
  if (e.target.value.trim().length === 0) {
112
- setHeader(t('Recent_previews'));
112
+ setHeader(t('Recent_visited'));
113
113
  setNewFileName('');
114
114
  getHistoryFiles();
115
115
  return;
@@ -56,12 +56,13 @@ const withBlockquote = editor => {
56
56
  }
57
57
  const blockQuoteEntry = getSelectedNodeEntryByType(editor, BLOCKQUOTE);
58
58
  if (blockQuoteEntry) {
59
+ const [, blockQuotePath] = blockQuoteEntry;
59
60
  const [currentLineEntry] = Editor.nodes(newEditor, {
60
- match: n => Element.isElement(n) && n.type === PARAGRAPH,
61
- mode: 'lowest'
61
+ match: (n, p) => Element.isElement(n) && p.length === blockQuotePath.length + 1 && n.type === PARAGRAPH
62
62
  });
63
63
  if (!currentLineEntry) return deleteBackward(unit);
64
- const currentLineIndex = currentLineEntry[1].slice(-1)[0];
64
+ const [, currentLinePath] = currentLineEntry;
65
+ const currentLineIndex = currentLinePath[blockQuotePath.length];
65
66
  // Transforms to paragraph when Select at the beginning of the first line
66
67
  if (currentLineIndex === 0 && isBlockAboveEmpty(newEditor)) {
67
68
  const emptyParagraph = generateEmptyElement(PARAGRAPH);
@@ -29,15 +29,50 @@ export const getSelectCodeElem = editor => {
29
29
  if (codeNode == null) return null;
30
30
  return codeNode;
31
31
  };
32
+ export const getCodeBlockNode = language => {
33
+ const node = {
34
+ id: slugid.nice(),
35
+ type: CODE_BLOCK,
36
+ language,
37
+ style: {
38
+ white_space: 'nowrap'
39
+ },
40
+ // default nowrap
41
+ children: [{
42
+ id: slugid.nice(),
43
+ type: CODE_LINE,
44
+ children: [{
45
+ text: '',
46
+ id: slugid.nice()
47
+ }]
48
+ }]
49
+ };
50
+ return node;
51
+ };
32
52
  export const changeToCodeBlock = function (editor) {
33
53
  let language = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
34
54
  let position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : INSERT_POSITION.CURRENT;
35
- // Summarizes the strings for the selected highest-level node
36
- let strArr = [];
37
- let path = Editor.path(editor, editor.selection);
55
+ if (!editor.selection) return;
56
+ let strArr = []; // Summarizes the strings for the selected highest-level node
57
+ const path = Editor.path(editor, editor.selection, {
58
+ edge: 'start'
59
+ });
60
+ const newCodeBlockNode = getCodeBlockNode(language); // New code-block node
61
+
62
+ // Insert after
38
63
  if (position === INSERT_POSITION.AFTER) {
39
64
  strArr = [''];
40
- } else {
65
+ newCodeBlockNode.children[0].children[0].text = strArr.join('\n');
66
+ Transforms.insertNodes(editor, newCodeBlockNode, {
67
+ mode: 'highest',
68
+ at: [path[0] + 1]
69
+ });
70
+ Transforms.select(editor, [path[0] + 1, 0, 0]);
71
+ return;
72
+ }
73
+
74
+ // Insert current
75
+ if (position === INSERT_POSITION.CURRENT) {
41
76
  // Select the plain text of the node
42
77
  const nodeEntries = Editor.nodes(editor, {
43
78
  match: n => editor.children.includes(n),
@@ -48,55 +83,33 @@ export const changeToCodeBlock = function (editor) {
48
83
  const [n] = nodeEntry;
49
84
  if (n) strArr.push(Node.string(n));
50
85
  }
51
-
52
86
  // Deletes the selected node at the highest level
53
87
  Transforms.removeNodes(editor, {
54
88
  mode: 'highest'
55
89
  });
56
- }
57
-
58
- // Insert the codeBlockNode node
59
- const newCodeBlockNode = {
60
- id: slugid.nice(),
61
- type: CODE_BLOCK,
62
- language,
63
- style: {
64
- white_space: 'nowrap' // default nowrap
65
- },
66
90
 
67
- children: [{
68
- id: slugid.nice(),
69
- type: CODE_LINE,
70
- children: [{
71
- text: strArr.join('\n'),
72
- id: slugid.nice()
73
- }]
74
- }]
75
- };
76
- if (position === INSERT_POSITION.AFTER) {
91
+ // Modify location
92
+ const atPath = [path[0]];
93
+ const atPoint = {
94
+ anchor: {
95
+ offset: 0,
96
+ path: [path[0], 0, 0]
97
+ },
98
+ focus: {
99
+ offset: 0,
100
+ path: [path[0], 0, 0]
101
+ }
102
+ };
103
+ // Insert new node
104
+ newCodeBlockNode.children[0].children[0].text = strArr.join('\n');
77
105
  Transforms.insertNodes(editor, newCodeBlockNode, {
78
106
  mode: 'highest',
79
- at: [path[0] + 1]
107
+ at: atPath
108
+ });
109
+ queueMicrotask(() => {
110
+ Transforms.select(editor, atPoint);
80
111
  });
81
- Transforms.select(editor, [path[0] + 1, 0, 0]);
82
- return;
83
112
  }
84
- const atPath = path ? [path[0]] : editor.selection;
85
- const atPoint = path ? {
86
- anchor: {
87
- offset: 0,
88
- path: [path[0], 0, 0]
89
- },
90
- focus: {
91
- offset: 0,
92
- path: [path[0], 0, 0]
93
- }
94
- } : editor.selection;
95
- Transforms.insertNodes(editor, newCodeBlockNode, {
96
- mode: 'highest',
97
- at: atPath
98
- });
99
- Transforms.select(editor, atPoint);
100
113
  };
101
114
  export const changeToPlainText = editor => {
102
115
  const elem = getSelectCodeElem(editor);
@@ -3,12 +3,15 @@ import { onTabHandle } from './on-tab-handle';
3
3
  import { normalizeList } from './normalize-list';
4
4
  import { insertFragmentList } from './insert-fragment-list';
5
5
  import { handleShortcut } from './shortcut';
6
+ import { getAboveBlockNode, getSelectedNodeEntryByType } from '../../../core';
7
+ import { BLOCKQUOTE, LIST_ITEM } from '../../../constants';
8
+ import { Editor, Transforms } from '@seafile/slate';
6
9
  const withList = editor => {
7
10
  const {
8
11
  insertBreak,
9
- deleteBackWord,
10
12
  handleTab,
11
- insertText
13
+ insertText,
14
+ deleteBackward
12
15
  } = editor;
13
16
  const newEditor = editor;
14
17
  newEditor.insertBreak = () => {
@@ -16,16 +19,32 @@ const withList = editor => {
16
19
  insertBreak();
17
20
  return;
18
21
  };
19
- newEditor.deleteBackWord = unit => {
22
+ newEditor.deleteBackward = unit => {
20
23
  const {
21
24
  selection
22
25
  } = newEditor;
23
26
  if (selection === null) {
24
- deleteBackWord(unit);
27
+ deleteBackward(unit);
25
28
  return;
26
29
  }
30
+ const listItemEntry = getSelectedNodeEntryByType(editor, LIST_ITEM);
31
+ if (listItemEntry) {
32
+ const [, listItemPath] = listItemEntry;
33
+ const blockQuoteEntry = getSelectedNodeEntryByType(editor, BLOCKQUOTE);
34
+ if (blockQuoteEntry) {
35
+ const isStart = Editor.isStart(editor, editor.selection.anchor, listItemPath);
36
+ if (isStart) {
37
+ // This is a tricky way to delete the blockquote and create a new paragraph
38
+ Transforms.removeNodes(editor, {
39
+ at: listItemPath
40
+ });
41
+ insertBreak();
42
+ return;
43
+ }
44
+ }
45
+ }
27
46
  // nothing todo
28
- deleteBackWord(unit);
47
+ deleteBackward(unit);
29
48
  };
30
49
  newEditor.handleTab = event => {
31
50
  if (!newEditor.selection) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.4.37",
3
+ "version": "0.5.1",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "Are you sure to replace all {{number}} '{{originalWord}}' in this document with '{{replacedWord}}'?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "Are you sure to clear all {{number}} '{{originalWord}}' in this document?",
444
444
  "Search_not_found": "Not found",
445
- "Recent_previews": "Recent previews",
445
+ "Recent_visited": "Recent visited",
446
446
  "The_document_does_not_exist": "The document does not exist",
447
447
  "Create_a_new_sdoc_file": "Create a new sdoc file",
448
448
  "Create": "Vytvořit"
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "Are you sure to replace all {{number}} '{{originalWord}}' in this document with '{{replacedWord}}'?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "Are you sure to clear all {{number}} '{{originalWord}}' in this document?",
444
444
  "Search_not_found": "Not found",
445
- "Recent_previews": "Recent previews",
445
+ "Recent_visited": "Recent visited",
446
446
  "The_document_does_not_exist": "The document does not exist",
447
447
  "Create_a_new_sdoc_file": "Create a new sdoc file",
448
448
  "Create": "Erstellen"
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "Are you sure to replace all {{number}} '{{originalWord}}' in this document with '{{replacedWord}}'?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "Are you sure to clear all {{number}} '{{originalWord}}' in this document?",
444
444
  "Search_not_found": "Not found",
445
- "Recent_previews": "Recent previews",
445
+ "Recent_visited": "Recent visited",
446
446
  "The_document_does_not_exist": "The document does not exist",
447
447
  "Create_a_new_sdoc_file": "Create a new sdoc file",
448
448
  "Create": "Create"
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "Are you sure to replace all {{number}} '{{originalWord}}' in this document with '{{replacedWord}}'?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "Are you sure to clear all {{number}} '{{originalWord}}' in this document?",
444
444
  "Search_not_found": "Not found",
445
- "Recent_previews": "Recent previews",
445
+ "Recent_visited": "Recent visited",
446
446
  "The_document_does_not_exist": "The document does not exist",
447
447
  "Create_a_new_sdoc_file": "Create a new sdoc file",
448
448
  "Create": "Crear"
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "Are you sure to replace all {{number}} '{{originalWord}}' in this document with '{{replacedWord}}'?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "Are you sure to clear all {{number}} '{{originalWord}}' in this document?",
444
444
  "Search_not_found": "Not found",
445
- "Recent_previews": "Recent previews",
445
+ "Recent_visited": "Recent visited",
446
446
  "The_document_does_not_exist": "The document does not exist",
447
447
  "Create_a_new_sdoc_file": "Create a new sdoc file",
448
448
  "Create": "Créer"
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "Are you sure to replace all {{number}} '{{originalWord}}' in this document with '{{replacedWord}}'?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "Are you sure to clear all {{number}} '{{originalWord}}' in this document?",
444
444
  "Search_not_found": "Not found",
445
- "Recent_previews": "Recent previews",
445
+ "Recent_visited": "Recent visited",
446
446
  "The_document_does_not_exist": "The document does not exist",
447
447
  "Create_a_new_sdoc_file": "Create a new sdoc file",
448
448
  "Create": "Crea"
@@ -428,7 +428,7 @@
428
428
  "My_modification": "Моя модификация",
429
429
  "Document_history": "История документа",
430
430
  "Freeze_document": "Заморозить документ",
431
- "Document_frozen": "Document frozen",
431
+ "Document_frozen": "Документ заморожен",
432
432
  "Unfreeze": "Разморозить",
433
433
  "Search_and_replace": "Поиск и замена",
434
434
  "Search": "Поиск",
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "Вы уверены, что хотите заменить все {{number}} '{{originalWord}}' в этом документе на '{{replacedWord}}'?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "Вы уверены, что хотите очистить все {{number}} '{{originalWord}}' в этом документе?",
444
444
  "Search_not_found": "Не найдено",
445
- "Recent_previews": "Последние предпросмотры",
445
+ "Recent_visited": "Recent visited",
446
446
  "The_document_does_not_exist": "Документ не существует",
447
447
  "Create_a_new_sdoc_file": "Создать новый файл sdoc",
448
448
  "Create": "Создать"
@@ -442,7 +442,7 @@
442
442
  "Are_you_sure_to_replace_all_number_xxx_in_this_document_with_yyy": "确定要将此文档内的 {{number}} 处 \"{{originalWord}} \" 替换为 \"{{replacedWord}} \" 吗?",
443
443
  "Are_you_sure_to_clear_all_number_xxx_in_this_document": "确定将此文档内的 {{number}} 处 \"{{originalWord}}\" 全部清除吗?",
444
444
  "Search_not_found": "未找到",
445
- "Recent_previews": "最近浏览",
445
+ "Recent_visited": "最近浏览",
446
446
  "The_document_does_not_exist": "不存在该文档",
447
447
  "Create_a_new_sdoc_file": "新建 sdoc 文件",
448
448
  "Create": "创建"