@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.
Binary file
package/dist/index.cjs CHANGED
@@ -47243,6 +47243,100 @@ function DocxEditorViewer({
47243
47243
  tableCellSelectionRange
47244
47244
  ]
47245
47245
  );
47246
+ const extendSelectionVertically = React3.useCallback(
47247
+ (direction) => {
47248
+ const selection = window.getSelection();
47249
+ if (!selection?.anchorNode || !selection.focusNode) {
47250
+ return false;
47251
+ }
47252
+ const anchor = resolveParagraphBoundaryFromSelectionPoint(
47253
+ selection.anchorNode,
47254
+ selection.anchorOffset
47255
+ );
47256
+ const focus = resolveParagraphBoundaryFromSelectionPoint(
47257
+ selection.focusNode,
47258
+ selection.focusOffset
47259
+ );
47260
+ if (!anchor || !focus || anchor.location.kind !== "paragraph" || focus.location.kind !== "paragraph") {
47261
+ return false;
47262
+ }
47263
+ const spansParagraphs = !sameParagraphLocation(
47264
+ anchor.location,
47265
+ focus.location
47266
+ );
47267
+ const lineRectsOf = (element) => {
47268
+ const range = document.createRange();
47269
+ range.selectNodeContents(element);
47270
+ return Array.from(range.getClientRects()).filter(
47271
+ (rect) => rect.width > 0 && rect.height > 0
47272
+ );
47273
+ };
47274
+ const caretRange = document.createRange();
47275
+ try {
47276
+ caretRange.setStart(selection.focusNode, selection.focusOffset);
47277
+ } catch {
47278
+ return spansParagraphs;
47279
+ }
47280
+ caretRange.collapse(true);
47281
+ const caretRect = caretRange.getClientRects()[0] ?? caretRange.getBoundingClientRect();
47282
+ const focusHost = resolveParagraphHostElement(focus.location);
47283
+ if (!caretRect || caretRect.height <= 0 || !focusHost) {
47284
+ return spansParagraphs;
47285
+ }
47286
+ const focusLines = lineRectsOf(focusHost);
47287
+ const edgeLine = direction > 0 ? focusLines[focusLines.length - 1] : focusLines[0];
47288
+ const caretMiddle = caretRect.top + caretRect.height / 2;
47289
+ const onEdgeLine = !edgeLine || caretMiddle >= edgeLine.top - 1 && caretMiddle <= edgeLine.bottom + 1;
47290
+ let target;
47291
+ if (!onEdgeLine) {
47292
+ if (!spansParagraphs) {
47293
+ return false;
47294
+ }
47295
+ target = resolveBoundaryFromPoint({
47296
+ x: caretRect.left,
47297
+ y: caretMiddle + direction * caretRect.height
47298
+ });
47299
+ if (!target || !sameParagraphLocation(target.location, focus.location)) {
47300
+ return true;
47301
+ }
47302
+ } else {
47303
+ let next;
47304
+ if (direction > 0) {
47305
+ next = nextParagraphLocation(editor.model, focus.location);
47306
+ } else {
47307
+ for (let nodeIndex = focus.location.nodeIndex - 1; nodeIndex >= 0 && !next; nodeIndex -= 1) {
47308
+ next = lastParagraphLocationInNode(editor.model, nodeIndex);
47309
+ }
47310
+ }
47311
+ const nextParagraph = next?.kind === "paragraph" ? getParagraphAtLocation(editor.model, next).paragraph : void 0;
47312
+ const nextHost = next ? resolveParagraphHostElement(next) : void 0;
47313
+ if (!next || !nextParagraph || !nextHost) {
47314
+ return spansParagraphs;
47315
+ }
47316
+ nextHost.scrollIntoView({ block: "nearest" });
47317
+ const nextLines = lineRectsOf(nextHost);
47318
+ const line = direction > 0 ? nextLines[0] : nextLines[nextLines.length - 1];
47319
+ const candidate = line ? resolveBoundaryFromPoint({
47320
+ x: clampNumber(caretRect.left, line.left, line.right),
47321
+ y: line.top + line.height / 2
47322
+ }) : void 0;
47323
+ target = candidate && sameParagraphLocation(candidate.location, next) ? candidate : {
47324
+ location: next,
47325
+ offset: direction > 0 ? 0 : paragraphText(nextParagraph).length
47326
+ };
47327
+ }
47328
+ viewerRootRef.current?.focus({ preventScroll: true });
47329
+ setSelectionFromDocxBoundaries(anchor, target);
47330
+ return true;
47331
+ },
47332
+ [
47333
+ editor,
47334
+ resolveBoundaryFromPoint,
47335
+ resolveParagraphBoundaryFromSelectionPoint,
47336
+ resolveParagraphHostElement,
47337
+ setSelectionFromDocxBoundaries
47338
+ ]
47339
+ );
47246
47340
  const onViewerKeyDown = React3.useCallback(
47247
47341
  (event) => {
47248
47342
  commandSelectionGuardRef.current = void 0;
@@ -47305,6 +47399,13 @@ function DocxEditorViewer({
47305
47399
  }
47306
47400
  }
47307
47401
  }
47402
+ 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
47403
+ // step into the next paragraph.
47404
+ document.activeElement !== wrappedParagraphTextareaRef.current && extendSelectionVertically(event.key === "ArrowDown" ? 1 : -1)) {
47405
+ event.preventDefault();
47406
+ event.stopPropagation();
47407
+ return;
47408
+ }
47308
47409
  const isSelectAll = (event.key === "a" || event.key === "A") && (event.ctrlKey || event.metaKey);
47309
47410
  if (!isSelectAll || event.shiftKey || event.altKey) {
47310
47411
  return;
@@ -47325,6 +47426,7 @@ function DocxEditorViewer({
47325
47426
  },
47326
47427
  [
47327
47428
  editor,
47429
+ extendSelectionVertically,
47328
47430
  handleDeleteAcrossTableCellSelection,
47329
47431
  isReadOnly,
47330
47432
  resolveParagraphBoundaryFromSelectionPoint,