@extend-ai/react-docx 0.11.2 → 0.11.3

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.js CHANGED
@@ -42903,6 +42903,9 @@ function DocxEditorViewer({
42903
42903
  );
42904
42904
  const runTableContextMenuAction = React3.useCallback(
42905
42905
  (actionId, providedContext) => {
42906
+ if (isReadOnly) {
42907
+ return;
42908
+ }
42906
42909
  const context = providedContext ?? tableContextMenuState;
42907
42910
  if (!context) {
42908
42911
  return;
@@ -42948,7 +42951,7 @@ function DocxEditorViewer({
42948
42951
  }
42949
42952
  closeTableContextMenu();
42950
42953
  },
42951
- [closeTableContextMenu, editor, tableContextMenuState]
42954
+ [closeTableContextMenu, editor, isReadOnly, tableContextMenuState]
42952
42955
  );
42953
42956
  const tableContextMenuActions = React3.useMemo(
42954
42957
  () => [...DEFAULT_TABLE_CONTEXT_MENU_ACTIONS],
@@ -45265,7 +45268,7 @@ function DocxEditorViewer({
45265
45268
  );
45266
45269
  const onViewerContextMenu = React3.useCallback(
45267
45270
  (event) => {
45268
- if (isReadOnly || event.defaultPrevented) {
45271
+ if (event.defaultPrevented) {
45269
45272
  return;
45270
45273
  }
45271
45274
  const target = event.target;
@@ -45295,8 +45298,10 @@ function DocxEditorViewer({
45295
45298
  if (!boundary) {
45296
45299
  return;
45297
45300
  }
45298
- clearTableCellSelection();
45299
- setSelectionFromDocxBoundaries(boundary, boundary);
45301
+ if (!isReadOnly) {
45302
+ clearTableCellSelection();
45303
+ setSelectionFromDocxBoundaries(boundary, boundary);
45304
+ }
45300
45305
  resolvedRange = {
45301
45306
  start: {
45302
45307
  location: cloneTextRangeLocation(boundary.location),
@@ -45307,7 +45312,7 @@ function DocxEditorViewer({
45307
45312
  offset: boundary.offset
45308
45313
  }
45309
45314
  };
45310
- } else if (resolvedRange) {
45315
+ } else if (resolvedRange && !isReadOnly) {
45311
45316
  clearTableCellSelection();
45312
45317
  editor.setActiveTextRange(resolvedRange);
45313
45318
  }
@@ -45316,9 +45321,11 @@ function DocxEditorViewer({
45316
45321
  ) : void 0;
45317
45322
  event.preventDefault();
45318
45323
  event.stopPropagation();
45324
+ const tableContext = isReadOnly ? parseTableCellLocationFromElement(target) : void 0;
45319
45325
  openContextMenu(
45320
45326
  {
45321
- kind: "text",
45327
+ kind: tableContext ? "table" : "text",
45328
+ tableContext,
45322
45329
  activeTextRange: resolvedRange ? normalizeTextRange(resolvedRange) : void 0,
45323
45330
  location
45324
45331
  },
@@ -45743,7 +45750,7 @@ function DocxEditorViewer({
45743
45750
  );
45744
45751
  const resolveContextMenuActions = React3.useCallback(
45745
45752
  (context) => {
45746
- if (context.kind === "table") {
45753
+ if (context.kind === "table" && !isReadOnly) {
45747
45754
  return tableContextMenuActions.map((action) => ({
45748
45755
  id: action.id,
45749
45756
  label: action.label,
@@ -45763,6 +45770,9 @@ function DocxEditorViewer({
45763
45770
  disabled: (action.id === "cut" || action.id === "copy") && !hasExpandedRange
45764
45771
  })
45765
45772
  );
45773
+ if (isReadOnly) {
45774
+ return clipboardActions.filter((action) => action.id === "copy");
45775
+ }
45766
45776
  if (context.kind !== "image") {
45767
45777
  return clipboardActions;
45768
45778
  }
@@ -45844,10 +45854,13 @@ function DocxEditorViewer({
45844
45854
  ...layerActions
45845
45855
  ];
45846
45856
  },
45847
- [tableContextMenuActions]
45857
+ [isReadOnly, tableContextMenuActions]
45848
45858
  );
45849
45859
  const runContextMenuAction = React3.useCallback(
45850
45860
  (actionId, providedContext) => {
45861
+ if (isReadOnly && actionId !== "copy") {
45862
+ return;
45863
+ }
45851
45864
  const isTableAction = (value) => value === "insert-row-above" || value === "insert-row-below" || value === "insert-column-left" || value === "insert-column-right" || value === "delete-row" || value === "delete-column" || value === "delete-table";
45852
45865
  if (isTableAction(actionId)) {
45853
45866
  const providedTableContext = providedContext?.kind === "table" ? providedContext.tableContext : void 0;
@@ -46208,7 +46221,7 @@ function DocxEditorViewer({
46208
46221
  if (!hasExpandedRange) {
46209
46222
  break;
46210
46223
  }
46211
- if (currentRange) {
46224
+ if (currentRange && !isReadOnly) {
46212
46225
  restoreDomSelectionFromRange(currentRange);
46213
46226
  }
46214
46227
  const selectedText = resolveSelectedTextForRange(currentRange);
@@ -46368,6 +46381,7 @@ function DocxEditorViewer({
46368
46381
  editor,
46369
46382
  focusWrappedParagraphRange,
46370
46383
  focusWrappedParagraphTextarea,
46384
+ isReadOnly,
46371
46385
  replaceExpandedSelectionWithText,
46372
46386
  resolveActiveRangeFromDomSelection,
46373
46387
  runTableContextMenuAction,
@@ -51208,14 +51222,13 @@ function DocxEditorViewer({
51208
51222
  }
51209
51223
  },
51210
51224
  onContextMenu: (event) => {
51211
- if (isReadOnly) {
51212
- return;
51213
- }
51214
51225
  event.preventDefault();
51215
51226
  event.stopPropagation();
51216
- clearTableCellSelection();
51217
- setSelectedSectionImageKey(void 0);
51218
- setSelectedImage(manualImageLocation);
51227
+ if (!isReadOnly) {
51228
+ clearTableCellSelection();
51229
+ setSelectedSectionImageKey(void 0);
51230
+ setSelectedImage(manualImageLocation);
51231
+ }
51219
51232
  openContextMenu(
51220
51233
  {
51221
51234
  kind: "image",
@@ -51481,14 +51494,13 @@ function DocxEditorViewer({
51481
51494
  }
51482
51495
  },
51483
51496
  onContextMenu: (event) => {
51484
- if (isReadOnly) {
51485
- return;
51486
- }
51487
51497
  event.preventDefault();
51488
51498
  event.stopPropagation();
51489
- clearTableCellSelection();
51490
- setSelectedSectionImageKey(void 0);
51491
- setSelectedImage(manualImageLocation);
51499
+ if (!isReadOnly) {
51500
+ clearTableCellSelection();
51501
+ setSelectedSectionImageKey(void 0);
51502
+ setSelectedImage(manualImageLocation);
51503
+ }
51492
51504
  openContextMenu(
51493
51505
  {
51494
51506
  kind: "image",
@@ -51704,14 +51716,13 @@ function DocxEditorViewer({
51704
51716
  }
51705
51717
  },
51706
51718
  onContextMenu: (event) => {
51707
- if (isReadOnly) {
51708
- return;
51709
- }
51710
51719
  event.preventDefault();
51711
51720
  event.stopPropagation();
51712
- clearTableCellSelection();
51713
- setSelectedSectionImageKey(void 0);
51714
- setSelectedImage(manualImageLocation);
51721
+ if (!isReadOnly) {
51722
+ clearTableCellSelection();
51723
+ setSelectedSectionImageKey(void 0);
51724
+ setSelectedImage(manualImageLocation);
51725
+ }
51715
51726
  openContextMenu(
51716
51727
  {
51717
51728
  kind: "image",
@@ -52158,14 +52169,16 @@ function DocxEditorViewer({
52158
52169
  }
52159
52170
  },
52160
52171
  onContextMenu: (event) => {
52161
- if (isReadOnly || behavesAsDecorativeBehindTextBackground) {
52172
+ if (behavesAsDecorativeBehindTextBackground) {
52162
52173
  return;
52163
52174
  }
52164
52175
  event.preventDefault();
52165
52176
  event.stopPropagation();
52166
- clearTableCellSelection();
52167
- setSelectedSectionImageKey(void 0);
52168
- setSelectedImage(imageLocation);
52177
+ if (!isReadOnly) {
52178
+ clearTableCellSelection();
52179
+ setSelectedSectionImageKey(void 0);
52180
+ setSelectedImage(imageLocation);
52181
+ }
52169
52182
  openContextMenu(
52170
52183
  {
52171
52184
  kind: "image",
@@ -52481,9 +52494,11 @@ function DocxEditorViewer({
52481
52494
  onContextMenu: (event) => {
52482
52495
  event.preventDefault();
52483
52496
  event.stopPropagation();
52484
- clearTableCellSelection();
52485
- setSelectedSectionImageKey(void 0);
52486
- setSelectedImage(imageLocation);
52497
+ if (!isReadOnly) {
52498
+ clearTableCellSelection();
52499
+ setSelectedSectionImageKey(void 0);
52500
+ setSelectedImage(imageLocation);
52501
+ }
52487
52502
  openContextMenu(
52488
52503
  {
52489
52504
  kind: "image",
@@ -59731,13 +59746,13 @@ ${currentText.slice(end)}`;
59731
59746
  }
59732
59747
  }
59733
59748
  ) : null,
59734
- !isReadOnly ? (() => {
59749
+ contextMenuState || tableContextMenuState ? (() => {
59735
59750
  const hasCustomContextMenuState = Boolean(contextMenuState);
59736
59751
  const hasTableContextMenuState = Boolean(tableContextMenuState);
59737
59752
  if (!hasCustomContextMenuState && !hasTableContextMenuState) {
59738
59753
  return null;
59739
59754
  }
59740
- if (hasCustomContextMenuState || renderContextMenu) {
59755
+ if (hasCustomContextMenuState || renderContextMenu || isReadOnly) {
59741
59756
  const tableContext = tableContextMenuState ? {
59742
59757
  tableIndex: tableContextMenuState.tableIndex,
59743
59758
  rowIndex: tableContextMenuState.rowIndex,