@extend-ai/react-docx 0.11.0 → 0.11.2
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/docx_wasm_bg.wasm +0 -0
- package/dist/index.cjs +102 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -45414,6 +45414,100 @@ function DocxEditorViewer({
|
|
|
45414
45414
|
tableCellSelectionRange
|
|
45415
45415
|
]
|
|
45416
45416
|
);
|
|
45417
|
+
const extendSelectionVertically = React3.useCallback(
|
|
45418
|
+
(direction) => {
|
|
45419
|
+
const selection = window.getSelection();
|
|
45420
|
+
if (!selection?.anchorNode || !selection.focusNode) {
|
|
45421
|
+
return false;
|
|
45422
|
+
}
|
|
45423
|
+
const anchor = resolveParagraphBoundaryFromSelectionPoint(
|
|
45424
|
+
selection.anchorNode,
|
|
45425
|
+
selection.anchorOffset
|
|
45426
|
+
);
|
|
45427
|
+
const focus = resolveParagraphBoundaryFromSelectionPoint(
|
|
45428
|
+
selection.focusNode,
|
|
45429
|
+
selection.focusOffset
|
|
45430
|
+
);
|
|
45431
|
+
if (!anchor || !focus || anchor.location.kind !== "paragraph" || focus.location.kind !== "paragraph") {
|
|
45432
|
+
return false;
|
|
45433
|
+
}
|
|
45434
|
+
const spansParagraphs = !sameParagraphLocation(
|
|
45435
|
+
anchor.location,
|
|
45436
|
+
focus.location
|
|
45437
|
+
);
|
|
45438
|
+
const lineRectsOf = (element) => {
|
|
45439
|
+
const range = document.createRange();
|
|
45440
|
+
range.selectNodeContents(element);
|
|
45441
|
+
return Array.from(range.getClientRects()).filter(
|
|
45442
|
+
(rect) => rect.width > 0 && rect.height > 0
|
|
45443
|
+
);
|
|
45444
|
+
};
|
|
45445
|
+
const caretRange = document.createRange();
|
|
45446
|
+
try {
|
|
45447
|
+
caretRange.setStart(selection.focusNode, selection.focusOffset);
|
|
45448
|
+
} catch {
|
|
45449
|
+
return spansParagraphs;
|
|
45450
|
+
}
|
|
45451
|
+
caretRange.collapse(true);
|
|
45452
|
+
const caretRect = caretRange.getClientRects()[0] ?? caretRange.getBoundingClientRect();
|
|
45453
|
+
const focusHost = resolveParagraphHostElement(focus.location);
|
|
45454
|
+
if (!caretRect || caretRect.height <= 0 || !focusHost) {
|
|
45455
|
+
return spansParagraphs;
|
|
45456
|
+
}
|
|
45457
|
+
const focusLines = lineRectsOf(focusHost);
|
|
45458
|
+
const edgeLine = direction > 0 ? focusLines[focusLines.length - 1] : focusLines[0];
|
|
45459
|
+
const caretMiddle = caretRect.top + caretRect.height / 2;
|
|
45460
|
+
const onEdgeLine = !edgeLine || caretMiddle >= edgeLine.top - 1 && caretMiddle <= edgeLine.bottom + 1;
|
|
45461
|
+
let target;
|
|
45462
|
+
if (!onEdgeLine) {
|
|
45463
|
+
if (!spansParagraphs) {
|
|
45464
|
+
return false;
|
|
45465
|
+
}
|
|
45466
|
+
target = resolveBoundaryFromPoint({
|
|
45467
|
+
x: caretRect.left,
|
|
45468
|
+
y: caretMiddle + direction * caretRect.height
|
|
45469
|
+
});
|
|
45470
|
+
if (!target || !sameParagraphLocation(target.location, focus.location)) {
|
|
45471
|
+
return true;
|
|
45472
|
+
}
|
|
45473
|
+
} else {
|
|
45474
|
+
let next;
|
|
45475
|
+
if (direction > 0) {
|
|
45476
|
+
next = nextParagraphLocation(editor.model, focus.location);
|
|
45477
|
+
} else {
|
|
45478
|
+
for (let nodeIndex = focus.location.nodeIndex - 1; nodeIndex >= 0 && !next; nodeIndex -= 1) {
|
|
45479
|
+
next = lastParagraphLocationInNode(editor.model, nodeIndex);
|
|
45480
|
+
}
|
|
45481
|
+
}
|
|
45482
|
+
const nextParagraph = next?.kind === "paragraph" ? getParagraphAtLocation(editor.model, next).paragraph : void 0;
|
|
45483
|
+
const nextHost = next ? resolveParagraphHostElement(next) : void 0;
|
|
45484
|
+
if (!next || !nextParagraph || !nextHost) {
|
|
45485
|
+
return spansParagraphs;
|
|
45486
|
+
}
|
|
45487
|
+
nextHost.scrollIntoView({ block: "nearest" });
|
|
45488
|
+
const nextLines = lineRectsOf(nextHost);
|
|
45489
|
+
const line = direction > 0 ? nextLines[0] : nextLines[nextLines.length - 1];
|
|
45490
|
+
const candidate = line ? resolveBoundaryFromPoint({
|
|
45491
|
+
x: clampNumber(caretRect.left, line.left, line.right),
|
|
45492
|
+
y: line.top + line.height / 2
|
|
45493
|
+
}) : void 0;
|
|
45494
|
+
target = candidate && sameParagraphLocation(candidate.location, next) ? candidate : {
|
|
45495
|
+
location: next,
|
|
45496
|
+
offset: direction > 0 ? 0 : paragraphText(nextParagraph).length
|
|
45497
|
+
};
|
|
45498
|
+
}
|
|
45499
|
+
viewerRootRef.current?.focus({ preventScroll: true });
|
|
45500
|
+
setSelectionFromDocxBoundaries(anchor, target);
|
|
45501
|
+
return true;
|
|
45502
|
+
},
|
|
45503
|
+
[
|
|
45504
|
+
editor,
|
|
45505
|
+
resolveBoundaryFromPoint,
|
|
45506
|
+
resolveParagraphBoundaryFromSelectionPoint,
|
|
45507
|
+
resolveParagraphHostElement,
|
|
45508
|
+
setSelectionFromDocxBoundaries
|
|
45509
|
+
]
|
|
45510
|
+
);
|
|
45417
45511
|
const onViewerKeyDown = React3.useCallback(
|
|
45418
45512
|
(event) => {
|
|
45419
45513
|
commandSelectionGuardRef.current = void 0;
|
|
@@ -45476,6 +45570,13 @@ function DocxEditorViewer({
|
|
|
45476
45570
|
}
|
|
45477
45571
|
}
|
|
45478
45572
|
}
|
|
45573
|
+
if (!isReadOnly && (event.key === "ArrowDown" || event.key === "ArrowUp") && event.shiftKey && !event.metaKey && !event.ctrlKey && !event.altKey && !event.defaultPrevented && // The wrapped-paragraph textarea handles its own lines and the first
|
|
45574
|
+
// step into the next paragraph.
|
|
45575
|
+
document.activeElement !== wrappedParagraphTextareaRef.current && extendSelectionVertically(event.key === "ArrowDown" ? 1 : -1)) {
|
|
45576
|
+
event.preventDefault();
|
|
45577
|
+
event.stopPropagation();
|
|
45578
|
+
return;
|
|
45579
|
+
}
|
|
45479
45580
|
const isSelectAll = (event.key === "a" || event.key === "A") && (event.ctrlKey || event.metaKey);
|
|
45480
45581
|
if (!isSelectAll || event.shiftKey || event.altKey) {
|
|
45481
45582
|
return;
|
|
@@ -45496,6 +45597,7 @@ function DocxEditorViewer({
|
|
|
45496
45597
|
},
|
|
45497
45598
|
[
|
|
45498
45599
|
editor,
|
|
45600
|
+
extendSelectionVertically,
|
|
45499
45601
|
handleDeleteAcrossTableCellSelection,
|
|
45500
45602
|
isReadOnly,
|
|
45501
45603
|
resolveParagraphBoundaryFromSelectionPoint,
|