@seafile/sdoc-editor 1.0.26 → 1.0.28

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.
@@ -3,14 +3,6 @@
3
3
  min-width: 12rem;
4
4
  }
5
5
 
6
- .sdoc-dropdown-menu .popover-inner {
7
- padding: 8px 0;
8
- }
9
-
10
- .sdoc-dropdown-menu.sdoc-sub-dropdown-menu .popover-inner {
11
- padding: 0;
12
- }
13
-
14
6
  .sdoc-dropdown-menu .sdoc-dropdown-menu-divider {
15
7
  width: 100%;
16
8
  height: 0;
@@ -147,6 +147,10 @@
147
147
  font-size: 12px;
148
148
  }
149
149
 
150
+ .sdoc-insert-image-menu-popover-container {
151
+ padding: 8px 0;
152
+ }
153
+
150
154
  /* caret */
151
155
  .sdoc-editor-container .article .caret-item .caret-name::before {
152
156
  content: attr(name);
@@ -1,5 +1,5 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import dayjs from 'dayjs';
4
4
  import EventBus from '../../../utils/event-bus';
5
5
  import useCommentList from '../../hooks/comment-hooks/use-comment-list';
@@ -31,7 +31,7 @@ export const searchCollaborators = (collaborators, searchValue) => {
31
31
  };
32
32
 
33
33
  // Mailto, file, tel, callto, sms, cid, xmpp, etc. are not support
34
- const ALLOWED_URL_REG = /((http|https):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g;
34
+ // const ALLOWED_URL_REG = /((http|https):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g;
35
35
  // export const textToHtml = (text) => {
36
36
  // if (!text) return '';
37
37
  // return text.replace(ALLOWED_URL_REG, '<a href="$1" target="_blank" class=' + COMMENT_URL_CLASSNAME + '>$1</a>');
@@ -1,7 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React, { useCallback, useMemo } from 'react';
3
3
  import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
4
- import { Editor, Node, Range } from '@seafile/slate';
4
+ import { Editor, Node } from '@seafile/slate';
5
5
  import isHotkey from 'is-hotkey';
6
6
  import scrollIntoView from 'scroll-into-view-if-needed';
7
7
  import { renderLeaf } from '../extension';
@@ -64,7 +64,7 @@ export const MENUS_CONFIG_MAP = {
64
64
  [CHECK_LIST_ITEM]: {
65
65
  id: CHECK_LIST_ITEM,
66
66
  iconClass: 'sdocfont sdoc-check-square',
67
- text: 'Check_list_item'
67
+ text: 'Check_list'
68
68
  },
69
69
  [CODE_BLOCK]: {
70
70
  id: CODE_BLOCK,
@@ -255,7 +255,7 @@ export const SIDE_TRANSFORM_MENUS_CONFIG = [{
255
255
  id: CHECK_LIST_ITEM,
256
256
  iconClass: 'sdocfont sdoc-check-square',
257
257
  type: CHECK_LIST_ITEM,
258
- text: 'Check_list_item'
258
+ text: 'Check_list'
259
259
  }, {
260
260
  id: BLOCKQUOTE,
261
261
  iconClass: 'sdocfont sdoc-quote1',
@@ -315,7 +315,7 @@ export const SIDE_INSERT_MENUS_CONFIG = {
315
315
  id: '',
316
316
  iconClass: 'sdocfont sdoc-check-square',
317
317
  type: CHECK_LIST_ITEM,
318
- text: 'Check_list_item'
318
+ text: 'Check_list'
319
319
  },
320
320
  [PARAGRAPH]: {
321
321
  id: PARAGRAPH,
@@ -451,4 +451,11 @@ export const isCurrentLineEmpty = editor => {
451
451
  };
452
452
  export const isCurrentLineHasText = node => {
453
453
  return Node.string(node).trim() !== '';
454
+ };
455
+ export const isMultiLevelList = listNode => {
456
+ const {
457
+ children
458
+ } = listNode || {};
459
+ let isMultiLevel = (children === null || children === void 0 ? void 0 : children.find(item => (item === null || item === void 0 ? void 0 : item.children.length) > 1)) ? true : false;
460
+ return isMultiLevel;
454
461
  };
@@ -17,10 +17,10 @@ export const match = (node, path, predicate) => {
17
17
  }
18
18
  return predicate(node, path);
19
19
  };
20
- export const generateDefaultText = () => {
20
+ export const generateDefaultText = text => {
21
21
  return {
22
22
  id: slugid.nice(),
23
- text: ''
23
+ text: text || ''
24
24
  };
25
25
  };
26
26
  export const generateDefaultParagraph = () => {
@@ -32,11 +32,12 @@ export const generateDefaultParagraph = () => {
32
32
  };
33
33
  export const generateEmptyElement = function (type) {
34
34
  let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
35
+ let text = arguments.length > 2 ? arguments[2] : undefined;
35
36
  return _objectSpread(_objectSpread({
36
37
  id: slugid.nice(),
37
38
  type
38
39
  }, props), {}, {
39
- children: [generateDefaultText()]
40
+ children: [generateDefaultText(text)]
40
41
  });
41
42
  };
42
43
  export function Placeholder(props) {
@@ -17,8 +17,7 @@ const withCallout = editor => {
17
17
  insertFragment,
18
18
  deleteBackward,
19
19
  onHotKeyDown,
20
- insertData,
21
- onCopy
20
+ insertData
22
21
  } = editor;
23
22
  const newEditor = editor;
24
23
  newEditor.deleteBackward = unit => {
@@ -1,6 +1,6 @@
1
- import { Transforms, Editor, Element } from '@seafile/slate';
2
- import { CHECK_LIST_ITEM, PARAGRAPH, ELEMENT_TYPE, INSERT_POSITION } from '../../constants';
3
- import { getSelectedNodeByType, generateEmptyElement } from '../../core';
1
+ import { Transforms, Editor, Element, Node } from '@seafile/slate';
2
+ import { CHECK_LIST_ITEM, PARAGRAPH, ELEMENT_TYPE, INSERT_POSITION, ORDERED_LIST, UNORDERED_LIST } from '../../constants';
3
+ import { getSelectedNodeByType, generateEmptyElement, isMultiLevelList } from '../../core';
4
4
  export const isMenuDisabled = (editor, readonly) => {
5
5
  if (readonly) return true;
6
6
  if (editor.selection == null) return true;
@@ -19,7 +19,7 @@ export const isMenuDisabled = (editor, readonly) => {
19
19
  } = element;
20
20
  if (type === ELEMENT_TYPE.CODE_LINE) return true;
21
21
  if (type === ELEMENT_TYPE.CODE_BLOCK) return true;
22
- if (type === ELEMENT_TYPE.LIST_ITEM) return true;
22
+ if ([ORDERED_LIST, UNORDERED_LIST].includes(type) && isMultiLevelList(element)) return true;
23
23
  if (type === ELEMENT_TYPE.TABLE) return true;
24
24
  if (type === ELEMENT_TYPE.TABLE_ROW) return true;
25
25
  if (type === ELEMENT_TYPE.TABLE_CELL) return true;
@@ -33,6 +33,27 @@ export const getCheckListItemType = editor => {
33
33
  if (!node) return PARAGRAPH;
34
34
  return node.type;
35
35
  };
36
+ export const convertToCheck = (editor, listNode, listPath) => {
37
+ const checkList = [];
38
+ const {
39
+ children
40
+ } = listNode || {};
41
+ children.forEach(item => {
42
+ const text = Node.string(item);
43
+ const checkNode = generateEmptyElement(CHECK_LIST_ITEM, {}, text);
44
+ checkList.push(checkNode);
45
+ });
46
+ Transforms.removeNodes(editor, {
47
+ at: [listPath[0]]
48
+ });
49
+ Transforms.insertNodes(editor, checkList, {
50
+ at: [listPath[0]]
51
+ });
52
+ Transforms.select(editor, {
53
+ path: [listPath[0], 0],
54
+ offset: 0
55
+ });
56
+ };
36
57
  export const setCheckListItemType = (editor, newType, insertPosition) => {
37
58
  if (insertPosition === INSERT_POSITION.AFTER) {
38
59
  const p = generateEmptyElement(PARAGRAPH);
@@ -42,6 +63,14 @@ export const setCheckListItemType = (editor, newType, insertPosition) => {
42
63
  });
43
64
  Transforms.select(editor, [path[0] + 1]);
44
65
  }
66
+ const path = Editor.path(editor, editor.selection);
67
+ if (path) {
68
+ const [targetNode, targetPath] = Editor.node(editor, [path[0]]);
69
+ if (targetNode && [ORDERED_LIST, UNORDERED_LIST].includes(targetNode === null || targetNode === void 0 ? void 0 : targetNode.type)) {
70
+ convertToCheck(editor, targetNode, targetPath);
71
+ return;
72
+ }
73
+ }
45
74
  Transforms.setNodes(editor, {
46
75
  type: newType
47
76
  });
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
2
  import { Input } from 'reactstrap';
3
3
  import { useTranslation, withTranslation } from 'react-i18next';
4
4
  import Tooltip from '../../../../../components/tooltip';
@@ -1,5 +1,5 @@
1
1
  import { Editor, Path, Range, Transforms } from '@seafile/slate';
2
- import { INSERT_POSITION, ORDERED_LIST, PARAGRAPH } from '../../../constants';
2
+ import { ORDERED_LIST, PARAGRAPH } from '../../../constants';
3
3
  import { getBeforeText, setListType } from '../helpers';
4
4
  import { focusEditor, getLastChild, getPreviousPath } from '../../../core';
5
5
  import { generateEmptyListItem } from '../model';
@@ -136,7 +136,7 @@ const ParticipantPopover = _ref => {
136
136
  setActiveCollaboratorIndex(nextActiveCollaboratorIndex);
137
137
  }, [searchedCollaborators, activeCollaboratorIndex]);
138
138
  const onSelectCollaborator = useCallback(collaborator => {
139
- const [node, path] = getMentionTempIptEntry(editor);
139
+ const [, path] = getMentionTempIptEntry(editor);
140
140
  insertMention(editor, collaborator);
141
141
  addParticipants(collaborator.username);
142
142
  Transforms.removeNodes(editor, {
@@ -15,7 +15,6 @@
15
15
  .sdoc-table-alignment-menu .sdoc-dropdown-menu-item .sdoc-check-mark {
16
16
  display: none;
17
17
  font-size: 16px !important;
18
- color: #6f59ff;
19
18
  }
20
19
  .sdoc-table-alignment-menu .sdoc-dropdown-menu-item .sdoc-check-mark.active {
21
20
  display: inline;
@@ -6,7 +6,8 @@
6
6
  }
7
7
 
8
8
  .menu-group .menu-group-item.sdoc-insert-toolbar-btn.disabled {
9
- width: 64px !important; /* 64: 76 - 12 */
9
+ /* 64: 76 - 12 */
10
+ width: 64px !important;
10
11
  color: #BDBDBD;
11
12
  }
12
13
 
@@ -21,3 +22,7 @@
21
22
  .sdoc-insert-menu-popover .popover {
22
23
  min-width: 200px;
23
24
  }
25
+
26
+ .sdoc-insert-menu-popover .sdoc-insert-menu-container {
27
+ padding: 8px 0;
28
+ }
@@ -3,12 +3,13 @@ import slugid from 'slugid';
3
3
  import { ReactEditor } from '@seafile/slate-react';
4
4
  import copy from 'copy-to-clipboard';
5
5
  import { toggleList } from '../../plugins/list/transforms';
6
- import { generateEmptyElement } from '../../core';
6
+ import { generateEmptyElement, findPath, isMultiLevelList } from '../../core';
7
7
  import { generateEmptyList } from '../../plugins/list/model';
8
8
  import { setClipboardCodeBlockData } from '../../plugins/code-block/helpers';
9
9
  import { ORDERED_LIST, UNORDERED_LIST, PARAGRAPH, CHECK_LIST_ITEM, IMAGE, TABLE, CODE_BLOCK, BLOCKQUOTE, LIST_ITEM_CORRELATION_TYPE, ADD_POSITION_OFFSET_TYPE, INSERT_POSITION, ELEMENT_TYPE, CALL_OUT } from '../../constants';
10
10
  import { EMPTY_SELECTED_RANGE } from '../../plugins/table/constants';
11
11
  import { unwrapCallout, wrapCallout } from '../../plugins/callout/helper';
12
+ import { convertToCheck } from '../../plugins/check-list/helpers';
12
13
  import { getHeaderHeight } from '../../../utils/dom-utils';
13
14
  export const onSetNodeType = (editor, element, type) => {
14
15
  if (!type) return;
@@ -21,6 +22,12 @@ export const onSetNodeType = (editor, element, type) => {
21
22
  return;
22
23
  }
23
24
  if (type === CHECK_LIST_ITEM) {
25
+ const path = findPath(editor, element);
26
+ const [targetNode, targetPath] = Editor.node(editor, [path[0]]) || [];
27
+ if (targetNode && [ORDERED_LIST, UNORDERED_LIST].includes(targetNode === null || targetNode === void 0 ? void 0 : targetNode.type) && !isMultiLevelList(targetNode)) {
28
+ convertToCheck(editor, targetNode, targetPath);
29
+ return;
30
+ }
24
31
  const newType = element.type === CHECK_LIST_ITEM ? PARAGRAPH : CHECK_LIST_ITEM;
25
32
  Transforms.setNodes(editor, {
26
33
  type: newType
@@ -3,8 +3,9 @@ import { UncontrolledPopover } from 'reactstrap';
3
3
  import { withTranslation } from 'react-i18next';
4
4
  import { ReactEditor, useSlateStatic } from '@seafile/slate-react';
5
5
  import { onSetNodeType } from './helpers';
6
- import { SIDE_TRANSFORM_MENUS_CONFIG, LIST_ITEM_SUPPORTED_TRANSFORMATION, LIST_ITEM_CORRELATION_TYPE, BLOCKQUOTE, CALL_OUT, HEADERS } from '../../constants';
6
+ import { SIDE_TRANSFORM_MENUS_CONFIG, LIST_ITEM_SUPPORTED_TRANSFORMATION, LIST_ITEM_CORRELATION_TYPE, BLOCKQUOTE, CALL_OUT, HEADERS, ORDERED_LIST, UNORDERED_LIST, CHECK_LIST_ITEM } from '../../constants';
7
7
  import DropdownMenuItem from '../../commons/dropdown-menu-item';
8
+ import { isMultiLevelList } from '../../core';
8
9
  const TransformMenus = _ref => {
9
10
  let {
10
11
  target,
@@ -37,6 +38,11 @@ const TransformMenus = _ref => {
37
38
  if (HEADERS.includes(highestNode.type)) {
38
39
  newSideMenusConfig = SIDE_TRANSFORM_MENUS_CONFIG.filter(item => item.type !== BLOCKQUOTE);
39
40
  }
41
+
42
+ // Multi-level list items cannot be converted to checks
43
+ if ([ORDERED_LIST, UNORDERED_LIST].includes(highestNode.type) && isMultiLevelList(highestNode)) {
44
+ newSideMenusConfig = SIDE_TRANSFORM_MENUS_CONFIG.filter(item => item.type !== CHECK_LIST_ITEM);
45
+ }
40
46
  }
41
47
  return newSideMenusConfig;
42
48
  // eslint-disable-next-line react-hooks/exhaustive-deps
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "Quote": "Quote",
17
17
  "Ordered_list": "Ordered list",
18
18
  "Unordered_list": "Unordered list",
19
- "Check_list_item": "Check list item",
19
+ "Check_list": "Check list",
20
20
  "Insert_image": "Insert image",
21
21
  "Insert_formula": "Insert formula",
22
22
  "Formula": "Formula",
@@ -16,7 +16,7 @@
16
16
  "Quote": "Цитата",
17
17
  "Ordered_list": "Нумерованный список",
18
18
  "Unordered_list": "Маркированный список",
19
- "Check_list": "Check list",
19
+ "Check_list": "Контрольный список",
20
20
  "Insert_image": "Вставить изображение",
21
21
  "Insert_formula": "Вставить формулу",
22
22
  "Formula": "Формула",