@seafile/sdoc-editor 0.5.18 → 0.5.20

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.
@@ -1719,49 +1719,82 @@ export const generateDragMoveElement = tipText => {
1719
1719
  const canvasId = 'sdoc-drag-image';
1720
1720
  let canvas = document.getElementById(canvasId);
1721
1721
  if (!canvas) {
1722
+ let dpr = window.devicePixelRatio;
1722
1723
  canvas = document.createElement('canvas');
1723
- canvas.width = 150;
1724
+ canvas.width = 115;
1724
1725
  canvas.height = 30;
1725
1726
  canvas.id = canvasId;
1726
1727
  document.body.appendChild(canvas);
1728
+ let {
1729
+ width: cssWidth,
1730
+ height: cssHeight
1731
+ } = canvas.getBoundingClientRect();
1732
+ canvas.style.width = canvas.width + 'px';
1733
+ canvas.style.height = canvas.height + 'px';
1734
+ canvas.width = dpr * cssWidth;
1735
+ canvas.height = dpr * cssHeight;
1736
+ canvas.style.position = 'fixed';
1727
1737
  }
1728
1738
  canvas.style.display = 'block';
1729
- canvas.style.position = 'fixed';
1730
1739
  const context = canvas.getContext('2d');
1731
1740
  context.clearRect(0, 0, canvas.width, canvas.height);
1732
- context.textAlign = 'center';
1733
- context.fillStyle = 'rgb(66, 129, 219)';
1741
+ context.fillStyle = 'rgb(241,243,246)';
1734
1742
  context.fillRect(0, 0, canvas.width, canvas.height);
1735
- context.font = '12px';
1743
+ context.font = '22px Arial';
1736
1744
  context.textBaseline = 'middle';
1737
- context.fillStyle = 'white';
1745
+ context.textAlign = 'center';
1746
+ context.fillStyle = 'black';
1738
1747
  context.fillText(tipText, canvas.width / 2, canvas.height / 2);
1739
1748
  return canvas;
1740
1749
  };
1741
- export const isHideDragHandlerLine = (editor, displayType, table, cellPath) => {
1750
+ export const isHideDragHandlerLine = (editor, displayType, table, cellPath, isDragOverCellHalf) => {
1742
1751
  const pathLength = cellPath.length;
1743
- const rowIndex = cellPath[pathLength - 2];
1744
- const cellIndex = cellPath[pathLength - 1];
1752
+ let rowIndex = cellPath[pathLength - 2];
1753
+ let cellIndex = cellPath[pathLength - 1];
1754
+
1755
+ // Check is above cell selected
1756
+ let currentCellDom = ReactEditor.toDOMNode(editor, table.children[rowIndex].children[cellIndex]);
1757
+ let isCurrentCellSelected = currentCellDom.classList.contains(CELL_SELECTED);
1758
+ if (isCurrentCellSelected) return true;
1759
+ if (isDragOverCellHalf) {
1760
+ if (displayType === DRAG_HANDLER_COLUMN) {
1761
+ cellIndex = cellIndex + 1;
1762
+ } else {
1763
+ rowIndex = rowIndex + 1;
1764
+ }
1765
+ }
1766
+ const isEndOfRowOrColumn = displayType === DRAG_HANDLER_COLUMN && cellIndex === table.columns.length || displayType === DRAG_HANDLER_ROW && rowIndex === table.children.length;
1767
+ if (isEndOfRowOrColumn) return false;
1745
1768
  let preCellDom = null;
1746
- if (displayType === DRAG_HANDLER_COLUMN && cellIndex > 1) {
1769
+ if (displayType === DRAG_HANDLER_COLUMN && cellIndex > 0) {
1747
1770
  const prevCell = table.children[rowIndex].children[cellIndex - 1];
1748
1771
  preCellDom = ReactEditor.toDOMNode(editor, prevCell);
1749
- } else if (displayType === DRAG_HANDLER_ROW && rowIndex > 1) {
1772
+ } else if (displayType === DRAG_HANDLER_ROW && rowIndex > 0) {
1750
1773
  const prevCell = table.children[rowIndex - 1].children[cellIndex];
1751
1774
  preCellDom = ReactEditor.toDOMNode(editor, prevCell);
1752
1775
  }
1753
- const isPrevCellSelected = preCellDom ? preCellDom.classList.contains(CELL_SELECTED) : false;
1776
+
1777
+ // Check is above cell selected
1778
+ currentCellDom = ReactEditor.toDOMNode(editor, table.children[rowIndex].children[cellIndex]);
1779
+ isCurrentCellSelected = currentCellDom.classList.contains(CELL_SELECTED);
1780
+ if (isCurrentCellSelected) return true;
1754
1781
 
1755
1782
  // Check if the previous cell is selected
1783
+ const isPrevCellSelected = preCellDom && preCellDom.classList.contains(CELL_SELECTED);
1756
1784
  if (isPrevCellSelected) return true;
1757
-
1785
+ let isCombined = false;
1758
1786
  // Check if the combined cell
1759
1787
  if (displayType === DRAG_HANDLER_COLUMN) {
1760
- const isCombined = table.children.some(row => row.children[cellIndex].is_combined);
1761
- return isCombined;
1788
+ isCombined = table.children.some(row => row.children[cellIndex - isDragOverCellHalf].is_combined);
1762
1789
  } else {
1763
- const isCombined = table.children[rowIndex].children.some(cell => cell.is_combined);
1764
- return isCombined;
1790
+ isCombined = table.children[rowIndex - isDragOverCellHalf].children.some(cell => cell.is_combined);
1791
+ }
1792
+ if (isCombined) return true;
1793
+
1794
+ // Check is the last column
1795
+ if (displayType === DRAG_HANDLER_COLUMN) {
1796
+ const isLastColumn = cellIndex === table.columns.length - 1;
1797
+ if (isLastColumn) return false;
1765
1798
  }
1766
1799
  };
1767
1800
  export const getTableRowSelectedRange = (table, rowIndex) => {
@@ -14,7 +14,7 @@ const DragHandlers = _ref => {
14
14
  });
15
15
  const [displayType, setDisplayType] = useState('');
16
16
  const tableID = table.id;
17
- const handleShowResizeHandler = useCallback(_ref2 => {
17
+ const handleShowDragHandler = useCallback(_ref2 => {
18
18
  let {
19
19
  displayType,
20
20
  left,
@@ -31,11 +31,11 @@ const DragHandlers = _ref => {
31
31
  }, [tableID]);
32
32
  useEffect(() => {
33
33
  const eventBus = EventBus.getInstance();
34
- const unsubscribe = eventBus.subscribe(INTERNAL_EVENT.TABLE_SHOW_DRAG_HANDLER, handleShowResizeHandler);
34
+ const unsubscribe = eventBus.subscribe(INTERNAL_EVENT.TABLE_SHOW_DRAG_HANDLER, handleShowDragHandler);
35
35
  return () => {
36
36
  unsubscribe();
37
37
  };
38
- }, [handleShowResizeHandler]);
38
+ }, [handleShowDragHandler]);
39
39
  return /*#__PURE__*/React.createElement(React.Fragment, null, displayType === DRAG_HANDLER_ROW && /*#__PURE__*/React.createElement(RowDragHandler, {
40
40
  top: linePosition.top
41
41
  }), displayType === DRAG_HANDLER_COLUMN && /*#__PURE__*/React.createElement(ColumnDragHandler, {
@@ -40,6 +40,7 @@ const TableCell = _ref => {
40
40
  const eventBus = EventBus.getInstance();
41
41
  const tableId = tableEntry[0].id;
42
42
  const canDrop = useRef(false);
43
+ const isDragOverHalfCell = useRef(false);
43
44
  const onContextMenu = useCallback(event => {
44
45
  const path = findPath(editor, element);
45
46
  focusEditor(editor, path);
@@ -100,7 +101,34 @@ const TableCell = _ref => {
100
101
  mouseDownEvent: event,
101
102
  tableId
102
103
  });
103
- const isHideHandleLine = isHideDragHandlerLine(editor, displayType, table, cellPath);
104
+ if (cellInfo.displayType === DRAG_HANDLER_COLUMN) {
105
+ const offsetX = cellInfo.mouseDownEvent.nativeEvent.offsetX;
106
+ const cellWidth = cellInfo.width;
107
+ const cellIndex = cellInfo.cellIndex;
108
+ // To avoid the drag handler line being covered by the table border
109
+ if (cellIndex === 0) cellInfo.left += 1;
110
+ if (cellIndex === table.children[0].children.length - 1) cellInfo.left -= 2;
111
+ if (offsetX >= cellWidth / 2) {
112
+ cellInfo.left = cellInfo.left + cellWidth;
113
+ isDragOverHalfCell.current = true;
114
+ } else {
115
+ isDragOverHalfCell.current = false;
116
+ }
117
+ } else {
118
+ const offsetY = cellInfo.mouseDownEvent.nativeEvent.offsetY;
119
+ const cellHeight = cellInfo.height;
120
+ const rowIndex = cellInfo.rowIndex;
121
+ // To avoid the drag handler line being covered by the table border
122
+ if (rowIndex === 0) cellInfo.top += 1;
123
+ if (rowIndex === table.children.length - 1) cellInfo.top -= 2;
124
+ if (offsetY >= cellHeight / 2) {
125
+ cellInfo.top = cellInfo.top + cellHeight;
126
+ isDragOverHalfCell.current = true;
127
+ } else {
128
+ isDragOverHalfCell.current = false;
129
+ }
130
+ }
131
+ const isHideHandleLine = isHideDragHandlerLine(editor, displayType, table, cellPath, isDragOverHalfCell.current);
104
132
  canDrop.current = !isHideHandleLine;
105
133
  if (target.classList.contains(CELL_SELECTED) || isHideHandleLine) {
106
134
  cellInfo.top = -9999;
@@ -120,6 +148,7 @@ const TableCell = _ref => {
120
148
  if (!dragDataJson) return;
121
149
  const dragData = JSON.parse(dragDataJson);
122
150
  if (dragData) {
151
+ const offset = isDragOverHalfCell.current ? 1 : 0;
123
152
  const {
124
153
  tableId: dragTableId,
125
154
  startIndex,
@@ -127,8 +156,8 @@ const TableCell = _ref => {
127
156
  dragType
128
157
  } = dragData;
129
158
  if (dragTableId !== tableId) return;
130
- dragType === DRAG_HANDLER_COLUMN ? moveColumns(editor, cellIndex, startIndex, endIndex) : moveRows(editor, rowIndex, startIndex, endIndex);
131
- const range = dragType === DRAG_HANDLER_COLUMN ? getTableSelectedRangeAfterDrag(tableEntry[0], dragType, cellIndex, startIndex, endIndex) : getTableSelectedRangeAfterDrag(tableEntry[0], dragType, rowIndex, startIndex, endIndex);
159
+ dragType === DRAG_HANDLER_COLUMN ? moveColumns(editor, cellIndex + offset, startIndex, endIndex) : moveRows(editor, rowIndex + offset, startIndex, endIndex);
160
+ const range = dragType === DRAG_HANDLER_COLUMN ? getTableSelectedRangeAfterDrag(tableEntry[0], dragType, cellIndex + offset, startIndex, endIndex) : getTableSelectedRangeAfterDrag(tableEntry[0], dragType, rowIndex + offset, startIndex, endIndex);
132
161
  eventBus.dispatch(INTERNAL_EVENT.SET_TABLE_SELECT_RANGE, tableEntry[0], range);
133
162
  }
134
163
  }, [cellIndex, editor, eventBus, rowIndex, tableEntry, tableId]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.18",
3
+ "version": "0.5.20",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -18,8 +18,8 @@
18
18
  "Unordered_list": "Neseřazený seznam",
19
19
  "Check_list_item": "Check list item",
20
20
  "Insert_image": "Insert image",
21
- "Insert_formula": "Insert formula",
22
- "Formula": "Formula",
21
+ "Insert_formula": "Vložit vzorec",
22
+ "Formula": "Vzorec",
23
23
  "Insert_file": "Insert file",
24
24
  "Code": "Řádkový kód",
25
25
  "Code_block": "Code block",
@@ -42,8 +42,8 @@
42
42
  "Delete_table": "Delete table",
43
43
  "Delete_row": "Delete row",
44
44
  "Delete_column": "Delete column",
45
- "Insert_row": "Insert row",
46
- "Insert_column": "Insert column",
45
+ "Insert_row": "Vložit řádek",
46
+ "Insert_column": "Vložit sloupec",
47
47
  "Set_align": "Nastavit zarovnání",
48
48
  "Left": "Vlevo",
49
49
  "Center": "Střed",
@@ -140,10 +140,10 @@
140
140
  "Insert_library_image": "Vložit obrázek knihovny",
141
141
  "Size": "Velikost",
142
142
  "Location": "Umístění",
143
- "Last_update": "Last update",
143
+ "Last_update": "Poslední aktualizace",
144
144
  "Tags": "Štítky",
145
145
  "Add_participants": "Přidat účastníky",
146
- "Clear_format": "Clear format",
146
+ "Clear_format": "Jasný formát",
147
147
  "MarkdownLint": {
148
148
  "missing_h1": {
149
149
  "description": "V dokumentu není žádný h1",
@@ -158,7 +158,7 @@
158
158
  "issue": "Problém s úrovní nadpisu"
159
159
  }
160
160
  },
161
- "Shortcut_help": "Shortcut help",
161
+ "Shortcut_help": "Zkratka nápovědy",
162
162
  "User_help": {
163
163
  "title": "Klávesové zkratky",
164
164
  "userHelpData": [
@@ -209,7 +209,7 @@
209
209
  {
210
210
  "shortcutType": "Zkratky vzorečku",
211
211
  "shortcutData": {
212
- "Insert_Formula": "Insert Formula"
212
+ "Insert_Formula": "Vložit vzorec"
213
213
  }
214
214
  },
215
215
  {
@@ -448,5 +448,7 @@
448
448
  "Create": "Vytvořit",
449
449
  "Top_align": "Top",
450
450
  "Center_align": "Middle",
451
- "Bottom_align": "Bottom"
451
+ "Bottom_align": "Bottom",
452
+ "Move_column_count": "Moving {{count}} column(s)",
453
+ "Move_row_count": "Moving {{count}} row(s)"
452
454
  }
@@ -18,7 +18,7 @@
18
18
  "Unordered_list": "Ungeordnete Liste",
19
19
  "Check_list_item": "Check list item",
20
20
  "Insert_image": "Insert image",
21
- "Insert_formula": "Insert formula",
21
+ "Insert_formula": "Formel einfügen",
22
22
  "Formula": "Formel",
23
23
  "Insert_file": "Insert file",
24
24
  "Code": "Inline-Code",
@@ -42,8 +42,8 @@
42
42
  "Delete_table": "Delete table",
43
43
  "Delete_row": "Delete row",
44
44
  "Delete_column": "Delete column",
45
- "Insert_row": "Insert row",
46
- "Insert_column": "Insert column",
45
+ "Insert_row": "Zeile einfügen",
46
+ "Insert_column": "Spalte einfügen",
47
47
  "Set_align": "Ausrichtung festlegen",
48
48
  "Left": "Links",
49
49
  "Center": "Zentrieren",
@@ -140,10 +140,10 @@
140
140
  "Insert_library_image": "Bild aus Bibliothek einfügen",
141
141
  "Size": "Größe",
142
142
  "Location": "Ort",
143
- "Last_update": "Last update",
143
+ "Last_update": "Letzte Änderung",
144
144
  "Tags": "Tags",
145
145
  "Add_participants": "Teilnehmer hinzufügen",
146
- "Clear_format": "Clear format",
146
+ "Clear_format": "Formatierung löschen",
147
147
  "MarkdownLint": {
148
148
  "missing_h1": {
149
149
  "description": "Es gibt keine Hauptüberschrift (h1) in dem Text",
@@ -288,7 +288,7 @@
288
288
  "Load_doc_content_error": "Load doc content error",
289
289
  "Sdoc_format_invalid": "The content of the document does not conform to the sdoc specification",
290
290
  "Draft": "Entwurf",
291
- "Unmark_as_draft": "Unmark as draft",
291
+ "Unmark_as_draft": "Entwurfsmarkierung entfernen",
292
292
  "Background_color": "Background color",
293
293
  "No_color": "No color",
294
294
  "Standard_color": "Standard color",
@@ -367,10 +367,10 @@
367
367
  "Table": "Tabelle",
368
368
  "Link": "Link",
369
369
  "Transform_to": "Transform to",
370
- "Last_modification": "Last modification",
371
- "Next_modification": "Next modification",
370
+ "Last_modification": "Letzte Änderung",
371
+ "Next_modification": "Nächste Änderung",
372
372
  "Changes": "Änderungen",
373
- "No_changes": "No changes",
373
+ "No_changes": "Keine Änderungen",
374
374
  "Title": "Titel",
375
375
  "Subtitle": "Subtitle",
376
376
  "Link_sdoc": "Link sdoc",
@@ -402,10 +402,10 @@
402
402
  "No_collaborators_available": "No_collaborators_available",
403
403
  "Find_a_collaborator": "Find a collaborator",
404
404
  "Doc_comments": "Document comments",
405
- "Tag_not_found": "Tag not found",
405
+ "Tag_not_found": "Der Tag wurde nicht gefunden",
406
406
  "Create_a_new_tag": "Neues Tag erstellen",
407
407
  "Search_tags": "Search tags",
408
- "No_options_available": "Tag not found",
408
+ "No_options_available": "Der Tag wurde nicht gefunden",
409
409
  "Add_option": "Neues Tag erstellen",
410
410
  "Find_an_option": "Search tags",
411
411
  "Copy_link_of_section": "Copy link of section",
@@ -448,5 +448,7 @@
448
448
  "Create": "Erstellen",
449
449
  "Top_align": "Top",
450
450
  "Center_align": "Middle",
451
- "Bottom_align": "Bottom"
451
+ "Bottom_align": "Bottom",
452
+ "Move_column_count": "Moving {{count}} column(s)",
453
+ "Move_row_count": "Moving {{count}} row(s)"
452
454
  }
@@ -448,5 +448,7 @@
448
448
  "Create": "Crear",
449
449
  "Top_align": "Top",
450
450
  "Center_align": "Middle",
451
- "Bottom_align": "Bottom"
451
+ "Bottom_align": "Bottom",
452
+ "Move_column_count": "Moving {{count}} column(s)",
453
+ "Move_row_count": "Moving {{count}} row(s)"
452
454
  }
@@ -448,5 +448,7 @@
448
448
  "Create": "Créer",
449
449
  "Top_align": "Top",
450
450
  "Center_align": "Middle",
451
- "Bottom_align": "Bottom"
451
+ "Bottom_align": "Bottom",
452
+ "Move_column_count": "Moving {{count}} column(s)",
453
+ "Move_row_count": "Moving {{count}} row(s)"
452
454
  }
@@ -448,5 +448,7 @@
448
448
  "Create": "Crea",
449
449
  "Top_align": "Top",
450
450
  "Center_align": "Middle",
451
- "Bottom_align": "Bottom"
451
+ "Bottom_align": "Bottom",
452
+ "Move_column_count": "Moving {{count}} column(s)",
453
+ "Move_row_count": "Moving {{count}} row(s)"
452
454
  }
@@ -446,7 +446,9 @@
446
446
  "The_document_does_not_exist": "Документ не существует",
447
447
  "Create_a_new_sdoc_file": "Создать новый файл sdoc",
448
448
  "Create": "Создать",
449
- "Top_align": "Top",
450
- "Center_align": "Middle",
451
- "Bottom_align": "Bottom"
449
+ "Top_align": "Верх",
450
+ "Center_align": "Середина",
451
+ "Bottom_align": "Низ",
452
+ "Move_column_count": "Перемещение {{count}} столбцов",
453
+ "Move_row_count": "Перемещение {{count}} строк"
452
454
  }
@@ -449,6 +449,6 @@
449
449
  "Top_align": "顶端对齐",
450
450
  "Center_align": "居中对齐",
451
451
  "Bottom_align": "底端对齐",
452
- "Move_column_count": "正在移动{{count}}列",
453
- "Move_row_count": "正在移动{{count}}行"
452
+ "Move_column_count": "移动{{count}}列",
453
+ "Move_row_count": "移动{{count}}行"
454
454
  }