@trafica/editor 1.0.21 → 1.0.22
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/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +166 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -665,6 +665,10 @@ declare function replaceAllMatches(matches: SearchMatch[], replacement: string):
|
|
|
665
665
|
*
|
|
666
666
|
* Tab → move cursor to next cell (adds row if on last cell)
|
|
667
667
|
* Shift+Tab → move cursor to previous cell (no-op on first cell)
|
|
668
|
+
* ArrowRight → move to next cell when at end of current cell
|
|
669
|
+
* ArrowLeft → move to previous cell when at start of current cell
|
|
670
|
+
* ArrowDown → move to cell below when on bottom line
|
|
671
|
+
* ArrowUp → move to cell above when on top line
|
|
668
672
|
*
|
|
669
673
|
* Enter inside a cell is handled by the default handleEnter command because
|
|
670
674
|
* findContentBlockPath correctly resolves to the paragraph inside the cell
|
package/dist/index.d.ts
CHANGED
|
@@ -665,6 +665,10 @@ declare function replaceAllMatches(matches: SearchMatch[], replacement: string):
|
|
|
665
665
|
*
|
|
666
666
|
* Tab → move cursor to next cell (adds row if on last cell)
|
|
667
667
|
* Shift+Tab → move cursor to previous cell (no-op on first cell)
|
|
668
|
+
* ArrowRight → move to next cell when at end of current cell
|
|
669
|
+
* ArrowLeft → move to previous cell when at start of current cell
|
|
670
|
+
* ArrowDown → move to cell below when on bottom line
|
|
671
|
+
* ArrowUp → move to cell above when on top line
|
|
668
672
|
*
|
|
669
673
|
* Enter inside a cell is handled by the default handleEnter command because
|
|
670
674
|
* findContentBlockPath correctly resolves to the paragraph inside the cell
|
package/dist/index.js
CHANGED
|
@@ -8629,6 +8629,53 @@ function prettyPrintHTML(html) {
|
|
|
8629
8629
|
}
|
|
8630
8630
|
|
|
8631
8631
|
// src/editor/table/TablePlugin.ts
|
|
8632
|
+
function getCellDOMElement(cellPathJson) {
|
|
8633
|
+
return document.querySelector(`[data-block-path='${cellPathJson}']`);
|
|
8634
|
+
}
|
|
8635
|
+
function isCaretAtContainerStart(container) {
|
|
8636
|
+
const sel = window.getSelection();
|
|
8637
|
+
if (!sel || sel.rangeCount === 0 || !sel.isCollapsed) return false;
|
|
8638
|
+
const range = sel.getRangeAt(0);
|
|
8639
|
+
if (range.startOffset !== 0) return false;
|
|
8640
|
+
let node = range.startContainer;
|
|
8641
|
+
while (node && node !== container) {
|
|
8642
|
+
if (node.previousSibling) return false;
|
|
8643
|
+
node = node.parentNode;
|
|
8644
|
+
}
|
|
8645
|
+
return node === container;
|
|
8646
|
+
}
|
|
8647
|
+
function isCaretAtContainerEnd(container) {
|
|
8648
|
+
var _a, _b;
|
|
8649
|
+
const sel = window.getSelection();
|
|
8650
|
+
if (!sel || sel.rangeCount === 0 || !sel.isCollapsed) return false;
|
|
8651
|
+
const range = sel.getRangeAt(0);
|
|
8652
|
+
const endNode = range.endContainer;
|
|
8653
|
+
const endOffset = range.endOffset;
|
|
8654
|
+
const len = endNode.nodeType === Node.TEXT_NODE ? (_b = (_a = endNode.textContent) == null ? void 0 : _a.length) != null ? _b : 0 : endNode.childNodes.length;
|
|
8655
|
+
if (endOffset !== len) return false;
|
|
8656
|
+
let node = endNode;
|
|
8657
|
+
while (node && node !== container) {
|
|
8658
|
+
if (node.nextSibling) return false;
|
|
8659
|
+
node = node.parentNode;
|
|
8660
|
+
}
|
|
8661
|
+
return node === container;
|
|
8662
|
+
}
|
|
8663
|
+
function isCaretOnEdgeLine(container, direction) {
|
|
8664
|
+
const sel = window.getSelection();
|
|
8665
|
+
if (!sel || sel.rangeCount === 0 || !sel.isCollapsed) return false;
|
|
8666
|
+
const caretRange = sel.getRangeAt(0).cloneRange();
|
|
8667
|
+
caretRange.collapse(true);
|
|
8668
|
+
const caretRects = caretRange.getClientRects();
|
|
8669
|
+
if (!caretRects.length) return true;
|
|
8670
|
+
const caretRect = caretRects[0];
|
|
8671
|
+
const containerRect = container.getBoundingClientRect();
|
|
8672
|
+
const lineHeight = parseFloat(getComputedStyle(container).lineHeight) || 20;
|
|
8673
|
+
if (direction === "up") {
|
|
8674
|
+
return caretRect.top < containerRect.top + lineHeight;
|
|
8675
|
+
} else {
|
|
8676
|
+
return caretRect.bottom > containerRect.bottom - lineHeight;
|
|
8677
|
+
}
|
|
8678
|
+
}
|
|
8632
8679
|
var TablePlugin = {
|
|
8633
8680
|
name: "table",
|
|
8634
8681
|
keyBindings: {
|
|
@@ -8679,6 +8726,125 @@ var TablePlugin = {
|
|
|
8679
8726
|
engine.dispatch(tr);
|
|
8680
8727
|
return true;
|
|
8681
8728
|
},
|
|
8729
|
+
"ArrowRight": (engine) => {
|
|
8730
|
+
var _a;
|
|
8731
|
+
const state = engine.getState();
|
|
8732
|
+
const sel = state.selection;
|
|
8733
|
+
if (!sel) return false;
|
|
8734
|
+
const cellPos = findCellPosition(state.doc, sel.anchor.path);
|
|
8735
|
+
if (!cellPos) return false;
|
|
8736
|
+
const { tablePath, row, col } = cellPos;
|
|
8737
|
+
const cellPath = [...tablePath, row, col];
|
|
8738
|
+
const cellEl = getCellDOMElement(JSON.stringify(cellPath));
|
|
8739
|
+
if (!cellEl || !isCaretAtContainerEnd(cellEl)) return false;
|
|
8740
|
+
const table = getNodeAtPath(state.doc, tablePath);
|
|
8741
|
+
const { rows, cols } = getTableDimensions(table);
|
|
8742
|
+
let nextRow = row;
|
|
8743
|
+
let nextCol = col + 1;
|
|
8744
|
+
while (nextRow < rows) {
|
|
8745
|
+
if (nextCol >= cols) {
|
|
8746
|
+
nextCol = 0;
|
|
8747
|
+
nextRow++;
|
|
8748
|
+
continue;
|
|
8749
|
+
}
|
|
8750
|
+
const c = getNodeAtPath(state.doc, [...tablePath, nextRow, nextCol]);
|
|
8751
|
+
if (!((_a = c == null ? void 0 : c.attrs) == null ? void 0 : _a.covered)) break;
|
|
8752
|
+
nextCol++;
|
|
8753
|
+
}
|
|
8754
|
+
if (nextRow >= rows) return true;
|
|
8755
|
+
const pos = getCellFirstPosition(state.doc, tablePath, nextRow, nextCol);
|
|
8756
|
+
if (!pos) return false;
|
|
8757
|
+
const tr = createTransaction();
|
|
8758
|
+
tr.steps.push(tr_setSelection(makeCollapsedSelection(pos)));
|
|
8759
|
+
engine.dispatch(tr);
|
|
8760
|
+
return true;
|
|
8761
|
+
},
|
|
8762
|
+
"ArrowLeft": (engine) => {
|
|
8763
|
+
var _a;
|
|
8764
|
+
const state = engine.getState();
|
|
8765
|
+
const sel = state.selection;
|
|
8766
|
+
if (!sel) return false;
|
|
8767
|
+
const cellPos = findCellPosition(state.doc, sel.anchor.path);
|
|
8768
|
+
if (!cellPos) return false;
|
|
8769
|
+
const { tablePath, row, col } = cellPos;
|
|
8770
|
+
const cellPath = [...tablePath, row, col];
|
|
8771
|
+
const cellEl = getCellDOMElement(JSON.stringify(cellPath));
|
|
8772
|
+
if (!cellEl || !isCaretAtContainerStart(cellEl)) return false;
|
|
8773
|
+
const table = getNodeAtPath(state.doc, tablePath);
|
|
8774
|
+
const { cols } = getTableDimensions(table);
|
|
8775
|
+
let prevRow = row;
|
|
8776
|
+
let prevCol = col - 1;
|
|
8777
|
+
while (prevRow >= 0) {
|
|
8778
|
+
if (prevCol < 0) {
|
|
8779
|
+
prevCol = cols - 1;
|
|
8780
|
+
prevRow--;
|
|
8781
|
+
continue;
|
|
8782
|
+
}
|
|
8783
|
+
const c = getNodeAtPath(state.doc, [...tablePath, prevRow, prevCol]);
|
|
8784
|
+
if (!((_a = c == null ? void 0 : c.attrs) == null ? void 0 : _a.covered)) break;
|
|
8785
|
+
prevCol--;
|
|
8786
|
+
}
|
|
8787
|
+
if (prevRow < 0) return true;
|
|
8788
|
+
const pos = getCellLastPosition(state.doc, tablePath, prevRow, prevCol);
|
|
8789
|
+
if (!pos) return false;
|
|
8790
|
+
const tr = createTransaction();
|
|
8791
|
+
tr.steps.push(tr_setSelection(makeCollapsedSelection(pos)));
|
|
8792
|
+
engine.dispatch(tr);
|
|
8793
|
+
return true;
|
|
8794
|
+
},
|
|
8795
|
+
"ArrowDown": (engine) => {
|
|
8796
|
+
var _a;
|
|
8797
|
+
const state = engine.getState();
|
|
8798
|
+
const sel = state.selection;
|
|
8799
|
+
if (!sel) return false;
|
|
8800
|
+
const cellPos = findCellPosition(state.doc, sel.anchor.path);
|
|
8801
|
+
if (!cellPos) return false;
|
|
8802
|
+
const { tablePath, row, col } = cellPos;
|
|
8803
|
+
const cellPath = [...tablePath, row, col];
|
|
8804
|
+
const cellEl = getCellDOMElement(JSON.stringify(cellPath));
|
|
8805
|
+
if (!cellEl || !isCaretOnEdgeLine(cellEl, "down")) return false;
|
|
8806
|
+
const table = getNodeAtPath(state.doc, tablePath);
|
|
8807
|
+
const { rows, cols } = getTableDimensions(table);
|
|
8808
|
+
let nextRow = row + 1;
|
|
8809
|
+
while (nextRow < rows) {
|
|
8810
|
+
const c = getNodeAtPath(state.doc, [...tablePath, nextRow, col]);
|
|
8811
|
+
if (c && !((_a = c.attrs) == null ? void 0 : _a.covered)) break;
|
|
8812
|
+
nextRow++;
|
|
8813
|
+
}
|
|
8814
|
+
if (nextRow >= rows) return false;
|
|
8815
|
+
const pos = getCellFirstPosition(state.doc, tablePath, nextRow, col < cols ? col : 0);
|
|
8816
|
+
if (!pos) return false;
|
|
8817
|
+
const tr = createTransaction();
|
|
8818
|
+
tr.steps.push(tr_setSelection(makeCollapsedSelection(pos)));
|
|
8819
|
+
engine.dispatch(tr);
|
|
8820
|
+
return true;
|
|
8821
|
+
},
|
|
8822
|
+
"ArrowUp": (engine) => {
|
|
8823
|
+
var _a;
|
|
8824
|
+
const state = engine.getState();
|
|
8825
|
+
const sel = state.selection;
|
|
8826
|
+
if (!sel) return false;
|
|
8827
|
+
const cellPos = findCellPosition(state.doc, sel.anchor.path);
|
|
8828
|
+
if (!cellPos) return false;
|
|
8829
|
+
const { tablePath, row, col } = cellPos;
|
|
8830
|
+
const cellPath = [...tablePath, row, col];
|
|
8831
|
+
const cellEl = getCellDOMElement(JSON.stringify(cellPath));
|
|
8832
|
+
if (!cellEl || !isCaretOnEdgeLine(cellEl, "up")) return false;
|
|
8833
|
+
let prevRow = row - 1;
|
|
8834
|
+
while (prevRow >= 0) {
|
|
8835
|
+
const c = getNodeAtPath(state.doc, [...tablePath, prevRow, col]);
|
|
8836
|
+
if (c && !((_a = c.attrs) == null ? void 0 : _a.covered)) break;
|
|
8837
|
+
prevRow--;
|
|
8838
|
+
}
|
|
8839
|
+
if (prevRow < 0) return false;
|
|
8840
|
+
const { cols } = getTableDimensions(getNodeAtPath(state.doc, tablePath));
|
|
8841
|
+
const pos = getCellLastPosition(state.doc, tablePath, prevRow, col < cols ? col : 0);
|
|
8842
|
+
if (!pos) return false;
|
|
8843
|
+
const tr = createTransaction();
|
|
8844
|
+
tr.steps.push(tr_setSelection(makeCollapsedSelection(pos)));
|
|
8845
|
+
engine.dispatch(tr);
|
|
8846
|
+
return true;
|
|
8847
|
+
},
|
|
8682
8848
|
"Shift+Tab": (engine) => {
|
|
8683
8849
|
var _a;
|
|
8684
8850
|
const state = engine.getState();
|