@lexical/table 0.14.2 → 0.14.4
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.
- package/LexicalTable.dev.js +224 -31
- package/{LexicalTable.dev.esm.js → LexicalTable.dev.mjs} +225 -32
- package/{LexicalTable.esm.js → LexicalTable.mjs} +2 -2
- package/LexicalTable.node.mjs +43 -0
- package/LexicalTable.prod.js +78 -72
- package/LexicalTable.prod.mjs +7 -0
- package/LexicalTableObserver.d.ts +1 -0
- package/LexicalTableSelectionHelpers.d.ts +2 -0
- package/index.d.ts +0 -1
- package/package.json +23 -7
- package/LexicalTable.prod.esm.js +0 -7
@@ -5,7 +5,7 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
7
|
import { addClassNamesToElement, $findMatchingParent, removeClassNamesFromElement, isHTMLElement } from '@lexical/utils';
|
8
|
-
import { ElementNode, $applyNodeReplacement, $createParagraphNode, $isElementNode, $isLineBreakNode, createCommand, $createTextNode, $getSelection, $isRangeSelection, $normalizeSelection__EXPERIMENTAL, $getNodeByKey, isCurrentlyReadOnlyMode, $createPoint, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $
|
8
|
+
import { ElementNode, $applyNodeReplacement, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, createCommand, $createTextNode, $getSelection, $isRangeSelection, $normalizeSelection__EXPERIMENTAL, $getNodeByKey, isCurrentlyReadOnlyMode, $createPoint, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND } from 'lexical';
|
9
9
|
|
10
10
|
/**
|
11
11
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
@@ -219,6 +219,11 @@ function convertTableCellNodeElement(domNode) {
|
|
219
219
|
if (backgroundColor !== '') {
|
220
220
|
tableCellNode.__backgroundColor = backgroundColor;
|
221
221
|
}
|
222
|
+
const style = domNode_.style;
|
223
|
+
const hasBoldFontWeight = style.fontWeight === '700' || style.fontWeight === 'bold';
|
224
|
+
const hasLinethroughTextDecoration = style.textDecoration === 'line-through';
|
225
|
+
const hasItalicFontStyle = style.fontStyle === 'italic';
|
226
|
+
const hasUnderlineTextDecoration = style.textDecoration === 'underline';
|
222
227
|
return {
|
223
228
|
after: childLexicalNodes => {
|
224
229
|
if (childLexicalNodes.length === 0) {
|
@@ -232,6 +237,20 @@ function convertTableCellNodeElement(domNode) {
|
|
232
237
|
if ($isLineBreakNode(lexicalNode) && lexicalNode.getTextContent() === '\n') {
|
233
238
|
return null;
|
234
239
|
}
|
240
|
+
if ($isTextNode(lexicalNode)) {
|
241
|
+
if (hasBoldFontWeight) {
|
242
|
+
lexicalNode.toggleFormat('bold');
|
243
|
+
}
|
244
|
+
if (hasLinethroughTextDecoration) {
|
245
|
+
lexicalNode.toggleFormat('strikethrough');
|
246
|
+
}
|
247
|
+
if (hasItalicFontStyle) {
|
248
|
+
lexicalNode.toggleFormat('italic');
|
249
|
+
}
|
250
|
+
if (hasUnderlineTextDecoration) {
|
251
|
+
lexicalNode.toggleFormat('underline');
|
252
|
+
}
|
253
|
+
}
|
235
254
|
paragraphNode.append(lexicalNode);
|
236
255
|
return paragraphNode;
|
237
256
|
}
|
@@ -1294,7 +1313,6 @@ function $getChildrenRecursively(node) {
|
|
1294
1313
|
* LICENSE file in the root directory of this source tree.
|
1295
1314
|
*
|
1296
1315
|
*/
|
1297
|
-
const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
|
1298
1316
|
class TableObserver {
|
1299
1317
|
constructor(editor, tableNodeKey) {
|
1300
1318
|
this.isHighlightingCells = false;
|
@@ -1317,6 +1335,7 @@ class TableObserver {
|
|
1317
1335
|
this.focusCell = null;
|
1318
1336
|
this.hasHijackedSelectionStyles = false;
|
1319
1337
|
this.trackTable();
|
1338
|
+
this.isSelecting = false;
|
1320
1339
|
}
|
1321
1340
|
getTable() {
|
1322
1341
|
return this.table;
|
@@ -1456,7 +1475,7 @@ class TableObserver {
|
|
1456
1475
|
this.focusY = cellY;
|
1457
1476
|
if (this.isHighlightingCells) {
|
1458
1477
|
const focusTableCellNode = $getNearestNodeFromDOMNode(cell.elem);
|
1459
|
-
if (this.tableSelection != null && this.anchorCellNodeKey != null && $isTableCellNode(focusTableCellNode)) {
|
1478
|
+
if (this.tableSelection != null && this.anchorCellNodeKey != null && $isTableCellNode(focusTableCellNode) && tableNode.is($findTableNode(focusTableCellNode))) {
|
1460
1479
|
const focusNodeKey = focusTableCellNode.getKey();
|
1461
1480
|
this.tableSelection = this.tableSelection.clone() || $createTableSelection();
|
1462
1481
|
this.focusCellNodeKey = focusNodeKey;
|
@@ -1554,6 +1573,7 @@ class TableObserver {
|
|
1554
1573
|
*
|
1555
1574
|
*/
|
1556
1575
|
const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
|
1576
|
+
const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
|
1557
1577
|
function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
1558
1578
|
const rootElement = editor.getRootElement();
|
1559
1579
|
if (rootElement === null) {
|
@@ -1562,6 +1582,24 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1562
1582
|
const tableObserver = new TableObserver(editor, tableNode.getKey());
|
1563
1583
|
const editorWindow = editor._window || window;
|
1564
1584
|
attachTableObserverToTableElement(tableElement, tableObserver);
|
1585
|
+
const createMouseHandlers = () => {
|
1586
|
+
const onMouseUp = () => {
|
1587
|
+
tableObserver.isSelecting = false;
|
1588
|
+
editorWindow.removeEventListener('mouseup', onMouseUp);
|
1589
|
+
editorWindow.removeEventListener('mousemove', onMouseMove);
|
1590
|
+
};
|
1591
|
+
const onMouseMove = moveEvent => {
|
1592
|
+
const focusCell = getDOMCellFromTarget(moveEvent.target);
|
1593
|
+
if (focusCell !== null && (tableObserver.anchorX !== focusCell.x || tableObserver.anchorY !== focusCell.y)) {
|
1594
|
+
moveEvent.preventDefault();
|
1595
|
+
tableObserver.setFocusCellForSelection(focusCell);
|
1596
|
+
}
|
1597
|
+
};
|
1598
|
+
return {
|
1599
|
+
onMouseMove: onMouseMove,
|
1600
|
+
onMouseUp: onMouseUp
|
1601
|
+
};
|
1602
|
+
};
|
1565
1603
|
tableElement.addEventListener('mousedown', event => {
|
1566
1604
|
setTimeout(() => {
|
1567
1605
|
if (event.button !== 0) {
|
@@ -1575,17 +1613,11 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1575
1613
|
stopEvent(event);
|
1576
1614
|
tableObserver.setAnchorCellForSelection(anchorCell);
|
1577
1615
|
}
|
1578
|
-
const
|
1579
|
-
|
1580
|
-
|
1581
|
-
};
|
1582
|
-
|
1583
|
-
const focusCell = getDOMCellFromTarget(moveEvent.target);
|
1584
|
-
if (focusCell !== null && (tableObserver.anchorX !== focusCell.x || tableObserver.anchorY !== focusCell.y)) {
|
1585
|
-
moveEvent.preventDefault();
|
1586
|
-
tableObserver.setFocusCellForSelection(focusCell);
|
1587
|
-
}
|
1588
|
-
};
|
1616
|
+
const {
|
1617
|
+
onMouseUp,
|
1618
|
+
onMouseMove
|
1619
|
+
} = createMouseHandlers();
|
1620
|
+
tableObserver.isSelecting = true;
|
1589
1621
|
editorWindow.addEventListener('mouseup', onMouseUp);
|
1590
1622
|
editorWindow.addEventListener('mousemove', onMouseMove);
|
1591
1623
|
}, 0);
|
@@ -1653,18 +1685,6 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1653
1685
|
// TODO: Fix Delete Line in Table Cells.
|
1654
1686
|
return true;
|
1655
1687
|
}
|
1656
|
-
if (command === DELETE_CHARACTER_COMMAND || command === DELETE_WORD_COMMAND) {
|
1657
|
-
if (selection.isCollapsed() && selection.anchor.offset === 0) {
|
1658
|
-
if (nearestElementNode !== topLevelCellElementNode) {
|
1659
|
-
const children = nearestElementNode.getChildren();
|
1660
|
-
const newParagraphNode = $createParagraphNode();
|
1661
|
-
children.forEach(child => newParagraphNode.append(child));
|
1662
|
-
nearestElementNode.replace(newParagraphNode);
|
1663
|
-
nearestElementNode.getWritable().__parent = tableCellNode.getKey();
|
1664
|
-
return true;
|
1665
|
-
}
|
1666
|
-
}
|
1667
|
-
}
|
1668
1688
|
}
|
1669
1689
|
return false;
|
1670
1690
|
};
|
@@ -1750,6 +1770,13 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1750
1770
|
if (!$isTableCellNode(tableCellNode)) {
|
1751
1771
|
return false;
|
1752
1772
|
}
|
1773
|
+
if (typeof payload === 'string') {
|
1774
|
+
const edgePosition = $getTableEdgeCursorPosition(editor, selection, tableNode);
|
1775
|
+
if (edgePosition) {
|
1776
|
+
$insertParagraphAtTableEdge(edgePosition, tableNode, [$createTextNode(payload)]);
|
1777
|
+
return true;
|
1778
|
+
}
|
1779
|
+
}
|
1753
1780
|
}
|
1754
1781
|
return false;
|
1755
1782
|
}, COMMAND_PRIORITY_CRITICAL));
|
@@ -1880,7 +1907,11 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1880
1907
|
const isBackward = selection.isBackward();
|
1881
1908
|
if (isPartialyWithinTable) {
|
1882
1909
|
const newSelection = selection.clone();
|
1883
|
-
|
1910
|
+
if (isFocusInside) {
|
1911
|
+
newSelection.focus.set(tableNode.getParentOrThrow().getKey(), isBackward ? tableNode.getIndexWithinParent() : tableNode.getIndexWithinParent() + 1, 'element');
|
1912
|
+
} else {
|
1913
|
+
newSelection.anchor.set(tableNode.getParentOrThrow().getKey(), isBackward ? tableNode.getIndexWithinParent() + 1 : tableNode.getIndexWithinParent(), 'element');
|
1914
|
+
}
|
1884
1915
|
$setSelection(newSelection);
|
1885
1916
|
$addHighlightStyleToTable(editor, tableObserver);
|
1886
1917
|
} else if (isWithinTable) {
|
@@ -1889,6 +1920,34 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1889
1920
|
if (!anchorCellNode.is(focusCellNode)) {
|
1890
1921
|
tableObserver.setAnchorCellForSelection(getObserverCellFromCellNode(anchorCellNode));
|
1891
1922
|
tableObserver.setFocusCellForSelection(getObserverCellFromCellNode(focusCellNode), true);
|
1923
|
+
if (!tableObserver.isSelecting) {
|
1924
|
+
setTimeout(() => {
|
1925
|
+
const {
|
1926
|
+
onMouseUp,
|
1927
|
+
onMouseMove
|
1928
|
+
} = createMouseHandlers();
|
1929
|
+
tableObserver.isSelecting = true;
|
1930
|
+
editorWindow.addEventListener('mouseup', onMouseUp);
|
1931
|
+
editorWindow.addEventListener('mousemove', onMouseMove);
|
1932
|
+
}, 0);
|
1933
|
+
}
|
1934
|
+
}
|
1935
|
+
}
|
1936
|
+
} else if (selection && $isTableSelection(selection) && selection.is(prevSelection) && selection.tableKey === tableNode.getKey()) {
|
1937
|
+
// if selection goes outside of the table we need to change it to Range selection
|
1938
|
+
const domSelection = getDOMSelection(editor._window);
|
1939
|
+
if (domSelection && domSelection.anchorNode && domSelection.focusNode) {
|
1940
|
+
const focusNode = $getNearestNodeFromDOMNode(domSelection.focusNode);
|
1941
|
+
const isFocusOutside = focusNode && !tableNode.is($findTableNode(focusNode));
|
1942
|
+
const anchorNode = $getNearestNodeFromDOMNode(domSelection.anchorNode);
|
1943
|
+
const isAnchorInside = anchorNode && tableNode.is($findTableNode(anchorNode));
|
1944
|
+
if (isFocusOutside && isAnchorInside && domSelection.rangeCount > 0) {
|
1945
|
+
const newSelection = $createRangeSelectionFromDom(domSelection, editor);
|
1946
|
+
if (newSelection) {
|
1947
|
+
newSelection.anchor.set(tableNode.getKey(), selection.isBackward() ? tableNode.getChildrenSize() : 0, 'element');
|
1948
|
+
domSelection.removeAllRanges();
|
1949
|
+
$setSelection(newSelection);
|
1950
|
+
}
|
1892
1951
|
}
|
1893
1952
|
}
|
1894
1953
|
}
|
@@ -1907,6 +1966,18 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
1907
1966
|
}
|
1908
1967
|
return false;
|
1909
1968
|
}, COMMAND_PRIORITY_CRITICAL));
|
1969
|
+
tableObserver.listenersToRemove.add(editor.registerCommand(INSERT_PARAGRAPH_COMMAND, () => {
|
1970
|
+
const selection = $getSelection();
|
1971
|
+
if (!$isRangeSelection(selection) || !selection.isCollapsed() || !$isSelectionInTable(selection, tableNode)) {
|
1972
|
+
return false;
|
1973
|
+
}
|
1974
|
+
const edgePosition = $getTableEdgeCursorPosition(editor, selection, tableNode);
|
1975
|
+
if (edgePosition) {
|
1976
|
+
$insertParagraphAtTableEdge(edgePosition, tableNode);
|
1977
|
+
return true;
|
1978
|
+
}
|
1979
|
+
return false;
|
1980
|
+
}, COMMAND_PRIORITY_CRITICAL));
|
1910
1981
|
return tableObserver;
|
1911
1982
|
}
|
1912
1983
|
function attachTableObserverToTableElement(tableElement, tableObserver) {
|
@@ -2163,14 +2234,31 @@ function $findTableNode(node) {
|
|
2163
2234
|
function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
|
2164
2235
|
const selection = $getSelection();
|
2165
2236
|
if (!$isSelectionInTable(selection, tableNode)) {
|
2237
|
+
if (direction === 'backward' && $isRangeSelection(selection) && selection.isCollapsed()) {
|
2238
|
+
const anchorType = selection.anchor.type;
|
2239
|
+
const anchorOffset = selection.anchor.offset;
|
2240
|
+
if (anchorType !== 'element' && !(anchorType === 'text' && anchorOffset === 0)) {
|
2241
|
+
return false;
|
2242
|
+
}
|
2243
|
+
const anchorNode = selection.anchor.getNode();
|
2244
|
+
if (!anchorNode) {
|
2245
|
+
return false;
|
2246
|
+
}
|
2247
|
+
const parentNode = $findMatchingParent(anchorNode, n => $isElementNode(n) && !n.isInline());
|
2248
|
+
if (!parentNode) {
|
2249
|
+
return false;
|
2250
|
+
}
|
2251
|
+
const siblingNode = parentNode.getPreviousSibling();
|
2252
|
+
if (!siblingNode || !$isTableNode(siblingNode)) {
|
2253
|
+
return false;
|
2254
|
+
}
|
2255
|
+
stopEvent(event);
|
2256
|
+
siblingNode.selectEnd();
|
2257
|
+
return true;
|
2258
|
+
}
|
2166
2259
|
return false;
|
2167
2260
|
}
|
2168
2261
|
if ($isRangeSelection(selection) && selection.isCollapsed()) {
|
2169
|
-
// Horizontal move between cels seem to work well without interruption
|
2170
|
-
// so just exit early, and handle vertical moves
|
2171
|
-
if (direction === 'backward' || direction === 'forward') {
|
2172
|
-
return false;
|
2173
|
-
}
|
2174
2262
|
const {
|
2175
2263
|
anchor,
|
2176
2264
|
focus
|
@@ -2188,6 +2276,18 @@ function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
|
|
2188
2276
|
return $handleArrowKey(editor, event, direction, anchorCellTable, tableObserver);
|
2189
2277
|
}
|
2190
2278
|
}
|
2279
|
+
if (direction === 'backward' || direction === 'forward') {
|
2280
|
+
const anchorType = anchor.type;
|
2281
|
+
const anchorOffset = anchor.offset;
|
2282
|
+
const anchorNode = anchor.getNode();
|
2283
|
+
if (!anchorNode) {
|
2284
|
+
return false;
|
2285
|
+
}
|
2286
|
+
if (isExitingTableAnchor(anchorType, anchorOffset, anchorNode, direction)) {
|
2287
|
+
return $handleTableExit(event, anchorNode, tableNode, direction);
|
2288
|
+
}
|
2289
|
+
return false;
|
2290
|
+
}
|
2191
2291
|
const anchorCellDom = editor.getElementByKey(anchorCellNode.__key);
|
2192
2292
|
const anchorDOM = editor.getElementByKey(anchor.key);
|
2193
2293
|
if (anchorDOM == null || anchorCellDom == null) {
|
@@ -2259,6 +2359,99 @@ function stopEvent(event) {
|
|
2259
2359
|
event.stopImmediatePropagation();
|
2260
2360
|
event.stopPropagation();
|
2261
2361
|
}
|
2362
|
+
function isExitingTableAnchor(type, offset, anchorNode, direction) {
|
2363
|
+
return isExitingTableElementAnchor(type, anchorNode, direction) || isExitingTableTextAnchor(type, offset, anchorNode, direction);
|
2364
|
+
}
|
2365
|
+
function isExitingTableElementAnchor(type, anchorNode, direction) {
|
2366
|
+
return type === 'element' && (direction === 'backward' ? anchorNode.getPreviousSibling() === null : anchorNode.getNextSibling() === null);
|
2367
|
+
}
|
2368
|
+
function isExitingTableTextAnchor(type, offset, anchorNode, direction) {
|
2369
|
+
const parentNode = $findMatchingParent(anchorNode, n => $isElementNode(n) && !n.isInline());
|
2370
|
+
if (!parentNode) {
|
2371
|
+
return false;
|
2372
|
+
}
|
2373
|
+
const hasValidOffset = direction === 'backward' ? offset === 0 : offset === anchorNode.getTextContentSize();
|
2374
|
+
return type === 'text' && hasValidOffset && (direction === 'backward' ? parentNode.getPreviousSibling() === null : parentNode.getNextSibling() === null);
|
2375
|
+
}
|
2376
|
+
function $handleTableExit(event, anchorNode, tableNode, direction) {
|
2377
|
+
const anchorCellNode = $findMatchingParent(anchorNode, $isTableCellNode);
|
2378
|
+
if (!$isTableCellNode(anchorCellNode)) {
|
2379
|
+
return false;
|
2380
|
+
}
|
2381
|
+
const [tableMap, cellValue] = $computeTableMap(tableNode, anchorCellNode, anchorCellNode);
|
2382
|
+
if (!isExitingCell(tableMap, cellValue, direction)) {
|
2383
|
+
return false;
|
2384
|
+
}
|
2385
|
+
const toNode = getExitingToNode(anchorNode, direction, tableNode);
|
2386
|
+
if (!toNode || $isTableNode(toNode)) {
|
2387
|
+
return false;
|
2388
|
+
}
|
2389
|
+
stopEvent(event);
|
2390
|
+
if (direction === 'backward') {
|
2391
|
+
toNode.selectEnd();
|
2392
|
+
} else {
|
2393
|
+
toNode.selectStart();
|
2394
|
+
}
|
2395
|
+
return true;
|
2396
|
+
}
|
2397
|
+
function isExitingCell(tableMap, cellValue, direction) {
|
2398
|
+
const firstCell = tableMap[0][0];
|
2399
|
+
const lastCell = tableMap[tableMap.length - 1][tableMap[0].length - 1];
|
2400
|
+
const {
|
2401
|
+
startColumn,
|
2402
|
+
startRow
|
2403
|
+
} = cellValue;
|
2404
|
+
return direction === 'backward' ? startColumn === firstCell.startColumn && startRow === firstCell.startRow : startColumn === lastCell.startColumn && startRow === lastCell.startRow;
|
2405
|
+
}
|
2406
|
+
function getExitingToNode(anchorNode, direction, tableNode) {
|
2407
|
+
const parentNode = $findMatchingParent(anchorNode, n => $isElementNode(n) && !n.isInline());
|
2408
|
+
if (!parentNode) {
|
2409
|
+
return undefined;
|
2410
|
+
}
|
2411
|
+
const anchorSibling = direction === 'backward' ? parentNode.getPreviousSibling() : parentNode.getNextSibling();
|
2412
|
+
return anchorSibling && $isTableNode(anchorSibling) ? anchorSibling : direction === 'backward' ? tableNode.getPreviousSibling() : tableNode.getNextSibling();
|
2413
|
+
}
|
2414
|
+
function $insertParagraphAtTableEdge(edgePosition, tableNode, children) {
|
2415
|
+
const paragraphNode = $createParagraphNode();
|
2416
|
+
if (edgePosition === 'first') {
|
2417
|
+
tableNode.insertBefore(paragraphNode);
|
2418
|
+
} else {
|
2419
|
+
tableNode.insertAfter(paragraphNode);
|
2420
|
+
}
|
2421
|
+
paragraphNode.append(...(children || []));
|
2422
|
+
paragraphNode.selectEnd();
|
2423
|
+
}
|
2424
|
+
function $getTableEdgeCursorPosition(editor, selection, tableNode) {
|
2425
|
+
// TODO: Add support for nested tables
|
2426
|
+
const domSelection = window.getSelection();
|
2427
|
+
if (!domSelection || domSelection.anchorNode !== editor.getRootElement()) {
|
2428
|
+
return undefined;
|
2429
|
+
}
|
2430
|
+
const anchorCellNode = $findMatchingParent(selection.anchor.getNode(), n => $isTableCellNode(n));
|
2431
|
+
if (!anchorCellNode) {
|
2432
|
+
return undefined;
|
2433
|
+
}
|
2434
|
+
const parentTable = $findMatchingParent(anchorCellNode, n => $isTableNode(n));
|
2435
|
+
if (!$isTableNode(parentTable) || !parentTable.is(tableNode)) {
|
2436
|
+
return undefined;
|
2437
|
+
}
|
2438
|
+
const [tableMap, cellValue] = $computeTableMap(tableNode, anchorCellNode, anchorCellNode);
|
2439
|
+
const firstCell = tableMap[0][0];
|
2440
|
+
const lastCell = tableMap[tableMap.length - 1][tableMap[0].length - 1];
|
2441
|
+
const {
|
2442
|
+
startRow,
|
2443
|
+
startColumn
|
2444
|
+
} = cellValue;
|
2445
|
+
const isAtFirstCell = startRow === firstCell.startRow && startColumn === firstCell.startColumn;
|
2446
|
+
const isAtLastCell = startRow === lastCell.startRow && startColumn === lastCell.startColumn;
|
2447
|
+
if (isAtFirstCell) {
|
2448
|
+
return 'first';
|
2449
|
+
} else if (isAtLastCell) {
|
2450
|
+
return 'last';
|
2451
|
+
} else {
|
2452
|
+
return undefined;
|
2453
|
+
}
|
2454
|
+
}
|
2262
2455
|
|
2263
2456
|
/**
|
2264
2457
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
@@ -4,8 +4,8 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
|
-
import * as modDev from './LexicalTable.dev.
|
8
|
-
import * as modProd from './LexicalTable.prod.
|
7
|
+
import * as modDev from './LexicalTable.dev.mjs';
|
8
|
+
import * as modProd from './LexicalTable.prod.mjs';
|
9
9
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
10
10
|
export const $computeTableMap = mod.$computeTableMap;
|
11
11
|
export const $createTableCellNode = mod.$createTableCellNode;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalTable.dev.mjs') : import('./LexicalTable.prod.mjs'));
|
8
|
+
export const $computeTableMap = mod.$computeTableMap;
|
9
|
+
export const $createTableCellNode = mod.$createTableCellNode;
|
10
|
+
export const $createTableNode = mod.$createTableNode;
|
11
|
+
export const $createTableNodeWithDimensions = mod.$createTableNodeWithDimensions;
|
12
|
+
export const $createTableRowNode = mod.$createTableRowNode;
|
13
|
+
export const $createTableSelection = mod.$createTableSelection;
|
14
|
+
export const $deleteTableColumn = mod.$deleteTableColumn;
|
15
|
+
export const $deleteTableColumn__EXPERIMENTAL = mod.$deleteTableColumn__EXPERIMENTAL;
|
16
|
+
export const $deleteTableRow__EXPERIMENTAL = mod.$deleteTableRow__EXPERIMENTAL;
|
17
|
+
export const $getElementForTableNode = mod.$getElementForTableNode;
|
18
|
+
export const $getNodeTriplet = mod.$getNodeTriplet;
|
19
|
+
export const $getTableCellNodeFromLexicalNode = mod.$getTableCellNodeFromLexicalNode;
|
20
|
+
export const $getTableCellNodeRect = mod.$getTableCellNodeRect;
|
21
|
+
export const $getTableColumnIndexFromTableCellNode = mod.$getTableColumnIndexFromTableCellNode;
|
22
|
+
export const $getTableNodeFromLexicalNodeOrThrow = mod.$getTableNodeFromLexicalNodeOrThrow;
|
23
|
+
export const $getTableRowIndexFromTableCellNode = mod.$getTableRowIndexFromTableCellNode;
|
24
|
+
export const $getTableRowNodeFromTableCellNodeOrThrow = mod.$getTableRowNodeFromTableCellNodeOrThrow;
|
25
|
+
export const $insertTableColumn = mod.$insertTableColumn;
|
26
|
+
export const $insertTableColumn__EXPERIMENTAL = mod.$insertTableColumn__EXPERIMENTAL;
|
27
|
+
export const $insertTableRow = mod.$insertTableRow;
|
28
|
+
export const $insertTableRow__EXPERIMENTAL = mod.$insertTableRow__EXPERIMENTAL;
|
29
|
+
export const $isTableCellNode = mod.$isTableCellNode;
|
30
|
+
export const $isTableNode = mod.$isTableNode;
|
31
|
+
export const $isTableRowNode = mod.$isTableRowNode;
|
32
|
+
export const $isTableSelection = mod.$isTableSelection;
|
33
|
+
export const $removeTableRowAtIndex = mod.$removeTableRowAtIndex;
|
34
|
+
export const $unmergeCell = mod.$unmergeCell;
|
35
|
+
export const INSERT_TABLE_COMMAND = mod.INSERT_TABLE_COMMAND;
|
36
|
+
export const TableCellHeaderStates = mod.TableCellHeaderStates;
|
37
|
+
export const TableCellNode = mod.TableCellNode;
|
38
|
+
export const TableNode = mod.TableNode;
|
39
|
+
export const TableObserver = mod.TableObserver;
|
40
|
+
export const TableRowNode = mod.TableRowNode;
|
41
|
+
export const applyTableHandlers = mod.applyTableHandlers;
|
42
|
+
export const getDOMCellFromTarget = mod.getDOMCellFromTarget;
|
43
|
+
export const getTableObserverFromTableElement = mod.getTableObserverFromTableElement;
|