@seafile/seafile-editor 3.0.41 → 3.0.43

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.
@@ -67,12 +67,12 @@ const MENUS_CONFIG_MAP = exports.MENUS_CONFIG_MAP = {
67
67
  [_elementTypes.IMAGE]: {
68
68
  id: "seafile_".concat(_elementTypes.IMAGE),
69
69
  iconClass: 'mdfont md-image',
70
- text: 'Insert_image'
70
+ text: 'Image'
71
71
  },
72
72
  [_elementTypes.TABLE]: {
73
73
  id: "seafile_".concat(_elementTypes.TABLE),
74
74
  iconClass: 'mdfont md-table',
75
- text: 'Insert_table'
75
+ text: 'Table'
76
76
  },
77
77
  [ITALIC]: {
78
78
  id: "seafile_".concat(ITALIC),
@@ -116,7 +116,7 @@ const MENUS_CONFIG_MAP = exports.MENUS_CONFIG_MAP = {
116
116
  [_elementTypes.FORMULA]: {
117
117
  id: "seafile_".concat(_elementTypes.FORMULA),
118
118
  iconClass: 'mdfont md-formula',
119
- text: 'Insert_formula'
119
+ text: 'Formula'
120
120
  },
121
121
  [CLEAR_FORMAT]: {
122
122
  id: "seafile_".concat(CLEAR_FORMAT),
@@ -126,7 +126,7 @@ const MENUS_CONFIG_MAP = exports.MENUS_CONFIG_MAP = {
126
126
  [_elementTypes.COLUMN]: {
127
127
  id: "seafile_".concat(_elementTypes.COLUMN),
128
128
  iconClass: 'mdfont md-choose-column',
129
- text: 'Insert_column'
129
+ text: 'Column'
130
130
  },
131
131
  [MORE_OPERATION]: {
132
132
  id: "seafile_".concat(MORE_OPERATION),
@@ -17,7 +17,51 @@ const transformToDivider = editor => {
17
17
  exports.transformToDivider = transformToDivider;
18
18
  const insertDivider = editor => {
19
19
  if (!editor.selection) return;
20
+ const blockEntry = _slate.Editor.above(editor, {
21
+ at: editor.selection,
22
+ match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n),
23
+ mode: 'highest'
24
+ });
20
25
  const dividerNode = (0, _core.generateElement)(_elementTypes.DIVIDER);
26
+ const paragraphNode = (0, _core.generateDefaultParagraph)();
27
+ const focusInsertedParagraph = () => {
28
+ const [paragraphEntry] = _slate.Editor.nodes(editor, {
29
+ at: [],
30
+ match: node => node.id === paragraphNode.id,
31
+ mode: 'highest'
32
+ });
33
+ if (paragraphEntry) {
34
+ (0, _core.focusEditor)(editor, _slate.Editor.start(editor, paragraphEntry[1]));
35
+ return;
36
+ }
37
+ (0, _core.focusEditor)(editor);
38
+ };
39
+ if (!blockEntry) {
40
+ _slate.Editor.withoutNormalizing(editor, () => {
41
+ _slate.Transforms.insertNodes(editor, [dividerNode, paragraphNode]);
42
+ focusInsertedParagraph();
43
+ });
44
+ return;
45
+ }
46
+ const [blockNode, blockPath] = blockEntry;
47
+ const isEmptyParagraph = blockNode.type === _elementTypes.PARAGRAPH && _slate.Node.string(blockNode) === '';
48
+ const insertPath = isEmptyParagraph ? blockPath : (0, _core.isSelectionAtBlockEnd)(editor, {
49
+ at: editor.selection
50
+ }) ? _slate.Path.next(blockPath) : null;
51
+ if (insertPath) {
52
+ _slate.Editor.withoutNormalizing(editor, () => {
53
+ if (isEmptyParagraph) {
54
+ _slate.Transforms.removeNodes(editor, {
55
+ at: blockPath
56
+ });
57
+ }
58
+ _slate.Transforms.insertNodes(editor, [dividerNode, paragraphNode], {
59
+ at: insertPath
60
+ });
61
+ focusInsertedParagraph();
62
+ });
63
+ return;
64
+ }
21
65
  _slate.Transforms.insertNodes(editor, dividerNode);
22
66
  (0, _core.focusEditor)(editor);
23
67
  };
@@ -28,7 +28,7 @@ const DividerMenu = _ref => {
28
28
  disabled: readonly,
29
29
  menuConfig: menuConfig,
30
30
  className: "pr-2",
31
- onClick: onMousedown
31
+ onMousedown: onMousedown
32
32
  });
33
33
  };
34
34
  var _default = exports.default = DividerMenu;
@@ -46,7 +46,7 @@ const HeaderMenu = _ref => {
46
46
  if (clickIsInMenu) return;
47
47
 
48
48
  // in header toggle
49
- if (headerToggleRef && headerPopoverRef.contains(e.target)) return;
49
+ if (headerToggleRef && headerToggleRef.current.contains(e.target)) return;
50
50
  setIsShowHeaderPopover(false);
51
51
  unregisterEventHandler();
52
52
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -13,17 +13,21 @@ var _classnames = _interopRequireDefault(require("classnames"));
13
13
  var _core = require("../../../../core");
14
14
  var _constants = require("../../../../../constants");
15
15
  var _tableOperations = require("../../table-operations");
16
+ var _helper = require("../../helper");
16
17
  require("./style.css");
17
18
  const HorizontalAlignPopover = _ref => {
18
19
  let {
19
20
  target,
20
21
  editor,
21
22
  readonly,
22
- horizontalAlign
23
+ horizontalAlign,
24
+ handleCloseContextMenu
23
25
  } = _ref;
24
26
  const {
25
27
  t
26
28
  } = (0, _reactI18next.useTranslation)(_constants.TRANSLATE_NAMESPACE);
29
+ const popoverRef = (0, _react.useRef)(null);
30
+ const [popoverClassName, setPopoverClassName] = (0, _react.useState)('sf-table-alignment-popover');
27
31
  const setTextAlignStyle = (0, _react.useCallback)(textAlign => {
28
32
  if (readonly) return;
29
33
  (0, _tableOperations.changeColumnAlign)(editor, textAlign);
@@ -34,7 +38,40 @@ const HorizontalAlignPopover = _ref => {
34
38
  setTimeout(() => {
35
39
  (0, _core.focusEditor)(editor, focusPoint);
36
40
  }, 0);
37
- }, [editor, readonly]);
41
+ handleCloseContextMenu();
42
+ }, [editor, handleCloseContextMenu, readonly]);
43
+ (0, _react.useEffect)(() => {
44
+ var _target$current;
45
+ const updatePlacement = () => {
46
+ var _popoverRef$current;
47
+ const popoverNode = (_popoverRef$current = popoverRef.current) === null || _popoverRef$current === void 0 ? void 0 : _popoverRef$current._element;
48
+ const targetNode = target === null || target === void 0 ? void 0 : target.current;
49
+ if (!popoverNode || !targetNode) return;
50
+ const boundaryRect = (0, _helper.getTableMenuBoundaryRect)(targetNode);
51
+ const targetRect = targetNode.getBoundingClientRect();
52
+ const popoverWidth = popoverNode.offsetWidth || 0;
53
+ const gap = 8;
54
+ const boundaryGap = 10;
55
+ const canShowRight = targetRect.right + gap + popoverWidth <= boundaryRect.right - boundaryGap;
56
+ const canShowLeft = targetRect.left - gap - popoverWidth >= boundaryRect.left + boundaryGap;
57
+ if (!canShowRight && canShowLeft) {
58
+ setPopoverClassName('sf-table-alignment-popover sf-table-alignment-popover-left');
59
+ return;
60
+ }
61
+ setPopoverClassName('sf-table-alignment-popover');
62
+ };
63
+ const handleMouseEnter = () => {
64
+ setTimeout(updatePlacement, 0);
65
+ };
66
+ updatePlacement();
67
+ target === null || target === void 0 ? void 0 : (_target$current = target.current) === null || _target$current === void 0 ? void 0 : _target$current.addEventListener('mouseenter', handleMouseEnter);
68
+ window.addEventListener('resize', updatePlacement);
69
+ return () => {
70
+ var _target$current2;
71
+ target === null || target === void 0 ? void 0 : (_target$current2 = target.current) === null || _target$current2 === void 0 ? void 0 : _target$current2.removeEventListener('mouseenter', handleMouseEnter);
72
+ window.removeEventListener('resize', updatePlacement);
73
+ };
74
+ }, [target]);
38
75
  return /*#__PURE__*/_react.default.createElement(_reactstrap.UncontrolledPopover, {
39
76
  target: target.current,
40
77
  trigger: "hover",
@@ -42,7 +79,8 @@ const HorizontalAlignPopover = _ref => {
42
79
  hideArrow: true,
43
80
  fade: false,
44
81
  offset: [0, 8],
45
- popperClassName: "sf-table-alignment-popover sf-popover-box-shadow"
82
+ popperClassName: "".concat(popoverClassName, " sf-popover-box-shadow"),
83
+ innerRef: popoverRef
46
84
  }, /*#__PURE__*/_react.default.createElement("div", {
47
85
  className: "sf-dropdown-menu sf-table-alignment-menu"
48
86
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -5,7 +5,14 @@
5
5
 
6
6
  .sf-table-alignment-popover {
7
7
  z-index: 2000;
8
+ }
9
+
10
+ .sf-table-alignment-popover .popover {
11
+ left: 0 !important;
12
+ }
8
13
 
14
+ .sf-table-alignment-popover-left .popover {
15
+ transform: translateX(calc(-100% - 16px));
9
16
  }
10
17
 
11
18
  .sf-table-alignment-menu {
@@ -118,7 +118,8 @@ const ContextMenu = _ref => {
118
118
  })), horizontalAlignRef.current && /*#__PURE__*/_react.default.createElement(_horizontalAlignPopover.default, {
119
119
  target: horizontalAlignRef,
120
120
  editor: editor,
121
- horizontalAlign: horizontalAlign
121
+ horizontalAlign: horizontalAlign,
122
+ handleCloseContextMenu: handleCloseContextMenu
122
123
  })));
123
124
  };
124
125
  var _default = exports.default = ContextMenu;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.selectCellByGrid = exports.pasteContentIntoTable = exports.jumpOutTableInEditor = exports.isSelectingMultipleTables = exports.isInTable = exports.isDisabled = exports.insertTable = exports.getTableFocusingInfos = exports.getTableEntry = exports.getSelectedTableCells = exports.getSelectGrid = exports.getContextMenuPosition = void 0;
7
+ exports.selectCellByGrid = exports.pasteContentIntoTable = exports.jumpOutTableInEditor = exports.isSelectingMultipleTables = exports.isInTable = exports.isDisabled = exports.insertTable = exports.getTableMenuBoundaryRect = exports.getTableFocusingInfos = exports.getTableEntry = exports.getSelectedTableCells = exports.getSelectGrid = exports.getContextMenuPosition = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
9
9
  var _slate = require("slate");
10
10
  var _slateReact = require("slate-react");
@@ -17,6 +17,8 @@ var _deserializeHtml = require("../../../utils/deserialize-html");
17
17
  var _common = require("../../../utils/common");
18
18
  var _helper = require("../link/helper");
19
19
  var _helper2 = require("../image/helper");
20
+ const TABLE_MENU_BOUNDARY_SELECTOR = '.longtext-dialog-container, .sf-long-text-inline-editor-container';
21
+ const TABLE_MENU_BOUNDARY_GAP = 10;
20
22
  const isDisabled = (editor, readonly) => {
21
23
  const {
22
24
  selection
@@ -275,57 +277,38 @@ const isSelectingMultipleTables = editor => {
275
277
  return isSelectedMultiple;
276
278
  };
277
279
  exports.isSelectingMultipleTables = isSelectingMultipleTables;
280
+ const getTableMenuBoundaryRect = targetNode => {
281
+ const boundaryContainer = targetNode === null || targetNode === void 0 ? void 0 : targetNode.closest(TABLE_MENU_BOUNDARY_SELECTOR);
282
+ if (boundaryContainer) {
283
+ return boundaryContainer.getBoundingClientRect();
284
+ }
285
+ return {
286
+ top: 0,
287
+ left: 0,
288
+ right: window.innerWidth,
289
+ bottom: window.innerHeight
290
+ };
291
+ };
292
+ exports.getTableMenuBoundaryRect = getTableMenuBoundaryRect;
278
293
  const getContextMenuPosition = (event, tableRef) => {
279
294
  const menuHeight = 240;
280
295
  const menuWidth = 350;
281
- const {
282
- clientHeight,
283
- clientWidth
284
- } = document.body; // page
285
- const {
286
- x,
287
- y
288
- } = tableRef.current.getBoundingClientRect(); // table
296
+ const boundaryRect = getTableMenuBoundaryRect(tableRef.current);
297
+ const tableRect = tableRef.current.getBoundingClientRect();
289
298
  const {
290
299
  clientY,
291
300
  clientX
292
301
  } = event; // cursor
293
302
 
294
- const isBeyondBottom = clientY + menuHeight > clientHeight;
295
- const isBeyondRight = clientX + menuWidth > clientWidth;
296
- const defaultTop = clientY - y;
297
- const defaultLeft = clientX - x;
298
- let top = 0;
299
- let left = 0;
300
- if (isBeyondBottom) {
301
- const hiddenHeight = menuHeight - (clientHeight - clientY);
302
- top = defaultTop - hiddenHeight;
303
- }
304
- if (isBeyondRight) {
305
- const hiddenWidth = menuWidth - (clientWidth - clientX);
306
- left = defaultLeft - hiddenWidth;
307
- }
308
- if (!isBeyondBottom && !isBeyondRight) {
309
- return {
310
- top: defaultTop,
311
- left: defaultLeft
312
- };
313
- }
314
- if (isBeyondBottom && isBeyondRight) {
315
- return {
316
- top,
317
- left
318
- };
319
- }
320
- if (isBeyondBottom) {
321
- return {
322
- top,
323
- left: defaultLeft
324
- };
325
- }
303
+ const minTop = Math.max(boundaryRect.top - tableRect.top, 0);
304
+ const minLeft = Math.max(boundaryRect.left - tableRect.left, 0);
305
+ const maxTop = Math.max(boundaryRect.bottom - tableRect.top - menuHeight, minTop);
306
+ const maxLeft = Math.max(boundaryRect.right - tableRect.left - menuWidth - TABLE_MENU_BOUNDARY_GAP, minLeft);
307
+ const defaultTop = clientY - tableRect.top;
308
+ const defaultLeft = clientX - tableRect.left;
326
309
  return {
327
- top: defaultTop,
328
- left
310
+ top: Math.min(Math.max(defaultTop, minTop), maxTop),
311
+ left: Math.min(Math.max(defaultLeft, minLeft), maxLeft)
329
312
  };
330
313
  };
331
314
  exports.getContextMenuPosition = getContextMenuPosition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "3.0.41",
3
+ "version": "3.0.43",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "Seřazený seznam",
14
14
  "Unordered_list": "Neseřazený seznam",
15
15
  "Check_list_item": "Pole zaškrtnutí",
16
- "Insert_image": "Vložit obrázek",
17
- "Insert_formula": "Vložit vzorec",
16
+ "Image": "Obrázek",
18
17
  "Formula": "Vzorec",
19
18
  "Insert_file": "Vložit soubor",
20
19
  "Code": "Řádkový kód",
21
20
  "Code_block": "Blok kódu",
22
21
  "Insert_link": "Vložit odkaz",
23
- "Insert_table": "Vložit tabulku",
22
+ "Table": "Tabulka",
24
23
  "Save": "Uložit",
25
24
  "More": "Více",
26
25
  "Invalid_url": "Chybná URL",
@@ -241,5 +240,6 @@
241
240
  "Copy_link": "Kopírovat odkaz",
242
241
  "Zoom_in": "Přiblížit",
243
242
  "Zoom_out": "Oddálit",
243
+ "Divider": "Divider",
244
244
  "Close": "Zavřít"
245
245
  }
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "Nummerierte Liste",
14
14
  "Unordered_list": "Ungeordnete Liste",
15
15
  "Check_list_item": "Checkbox Liste",
16
- "Insert_image": "Bild einfügen",
17
- "Insert_formula": "Formel einfügen",
16
+ "Image": "Bild",
18
17
  "Formula": "Formel",
19
18
  "Insert_file": "Datei einnfügen",
20
19
  "Code": "Inline-Code",
21
20
  "Code_block": "Codeblock",
22
21
  "Insert_link": "Link einfügen",
23
- "Insert_table": "Tabelle einfügen",
22
+ "Table": "Tabelle",
24
23
  "Save": "Speichern",
25
24
  "More": "Mehr",
26
25
  "Invalid_url": "Ungültige Adresse",
@@ -241,5 +240,6 @@
241
240
  "Copy_link": "Link kopieren",
242
241
  "Zoom_in": "Hineinzoomen",
243
242
  "Zoom_out": "Herauszoomen",
243
+ "Divider": "Divider",
244
244
  "Close": "Schließen"
245
245
  }
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "Ordered list",
14
14
  "Unordered_list": "Unordered list",
15
15
  "Check_list_item": "Check list item",
16
- "Insert_image": "Insert image",
17
- "Insert_formula": "Insert formula",
16
+ "Image": "Image",
18
17
  "Formula": "Formula",
19
18
  "Insert_file": "Insert file",
20
19
  "Code": "Inline code",
21
20
  "Code_block": "Code block",
22
21
  "Insert_link": "Insert link",
23
- "Insert_table": "Insert table",
22
+ "Table": "Table",
24
23
  "Save": "Save",
25
24
  "More": "More",
26
25
  "Invalid_url": "Invalid URL",
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "Lista ordenada",
14
14
  "Unordered_list": "Lista desordenada",
15
15
  "Check_list_item": "Elemento de lista de verificación",
16
- "Insert_image": "Insertar imagen",
17
- "Insert_formula": "Insertar fórmula",
16
+ "Image": "Imagen",
18
17
  "Formula": "Fórmula",
19
18
  "Insert_file": "Insertar archivo",
20
19
  "Code": "Inline code",
21
20
  "Code_block": "Bloque de código",
22
21
  "Insert_link": "Insertar enlace",
23
- "Insert_table": "Insertar tabla",
22
+ "Table": "Tabla",
24
23
  "Save": "Guardar",
25
24
  "More": "Más",
26
25
  "Invalid_url": "URL Inválida",
@@ -241,5 +240,6 @@
241
240
  "Copy_link": "Copiar enlace",
242
241
  "Zoom_in": "Acercar",
243
242
  "Zoom_out": "Alejar",
243
+ "Divider": "Divider",
244
244
  "Close": "Cerrar"
245
245
  }
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "Liste ordonnée",
14
14
  "Unordered_list": "Liste non ordonnée",
15
15
  "Check_list_item": "Élément de la liste de vérification",
16
- "Insert_image": "Insérer une image",
17
- "Insert_formula": "Insérer formule",
16
+ "Image": "Image",
18
17
  "Formula": "Formule",
19
18
  "Insert_file": "Insérer un fichier",
20
19
  "Code": "Ligne de code",
21
20
  "Code_block": "Bloc de code",
22
21
  "Insert_link": "Insérer un lien",
23
- "Insert_table": "Insérer un tableau",
22
+ "Table": "Tableau",
24
23
  "Save": "Sauvegarder",
25
24
  "More": "Plus",
26
25
  "Invalid_url": "L'adresse n'est pas valide.",
@@ -241,5 +240,6 @@
241
240
  "Copy_link": "Copier le lien",
242
241
  "Zoom_in": "Agrandir",
243
242
  "Zoom_out": "Dézoomer",
243
+ "Divider": "Divider",
244
244
  "Close": "Fermer"
245
245
  }
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "Elenco Ordiniato",
14
14
  "Unordered_list": "Elenco non ordinato",
15
15
  "Check_list_item": "Elemento di elenco verificato",
16
- "Insert_image": "Inserisci immagine",
17
- "Insert_formula": "Inserisci formula",
16
+ "Image": "Immagine",
18
17
  "Formula": "Formula",
19
18
  "Insert_file": "Inserisci file",
20
19
  "Code": "Codice in linea",
21
20
  "Code_block": "Blocco di codice",
22
21
  "Insert_link": "Inserisci collegamento",
23
- "Insert_table": "Inserisci tabella",
22
+ "Table": "Tabella",
24
23
  "Save": "Salvare",
25
24
  "More": "Altro",
26
25
  "Invalid_url": "URL non valida",
@@ -241,5 +240,6 @@
241
240
  "Copy_link": "Copia link",
242
241
  "Zoom_in": "Ingrandire",
243
242
  "Zoom_out": "Rimpicciolire",
243
+ "Divider": "Divider",
244
244
  "Close": "Chiudi"
245
245
  }
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "Нумерованный список",
14
14
  "Unordered_list": "Маркированный список",
15
15
  "Check_list_item": "Элемент контрольного списка",
16
- "Insert_image": "Вставить изображение",
17
- "Insert_formula": "Вставить формулу",
16
+ "Image": "Изображение",
18
17
  "Formula": "Формула",
19
18
  "Insert_file": "Вставить файл",
20
19
  "Code": "Встроенный код",
21
20
  "Code_block": "Блок кода",
22
21
  "Insert_link": "Вставить ссылку",
23
- "Insert_table": "Вставить таблицу",
22
+ "Table": "Таблица",
24
23
  "Save": "Сохранить",
25
24
  "More": "Подробнее",
26
25
  "Invalid_url": "Недопустимый URL",
@@ -241,5 +240,6 @@
241
240
  "Copy_link": "Копировать ссылку",
242
241
  "Zoom_in": "Увеличить",
243
242
  "Zoom_out": "Уменьшить",
243
+ "Divider": "Разделитель",
244
244
  "Close": "Закрыть"
245
245
  }
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "有序列表",
14
14
  "Unordered_list": "无序列表",
15
15
  "Check_list_item": "任务列表",
16
- "Insert_image": "插入图片",
17
- "Insert_formula": "插入公式",
16
+ "Image": "图片",
18
17
  "Formula": "公式",
19
18
  "Insert_file": "插入文件",
20
19
  "Code": "行内代码",
21
20
  "Code_block": "代码块",
22
21
  "Insert_link": "添加链接",
23
- "Insert_table": "添加表格",
22
+ "Table": "表格",
24
23
  "Save": "保存",
25
24
  "More": "更多",
26
25
  "Invalid_url": "无效链接",
@@ -13,14 +13,13 @@
13
13
  "Ordered_list": "有序列表",
14
14
  "Unordered_list": "无序列表",
15
15
  "Check_list_item": "任务列表",
16
- "Insert_image": "插入图片",
17
- "Insert_formula": "插入公式",
16
+ "Image": "图片",
18
17
  "Formula": "公式",
19
18
  "Insert_file": "插入文件",
20
19
  "Code": "行内代码",
21
20
  "Code_block": "代码块",
22
21
  "Insert_link": "添加链接",
23
- "Insert_table": "添加表格",
22
+ "Table": "表格",
24
23
  "Save": "保存",
25
24
  "More": "更多",
26
25
  "Invalid_url": "无效链接",