@tarviks/lexical-rich-editor 1.3.8 → 1.3.10

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.mjs CHANGED
@@ -358,6 +358,7 @@ var init_ImageComponent = __esm({
358
358
  };
359
359
  img3.onerror = () => {
360
360
  imageCache.add(src);
361
+ resolve(null);
361
362
  };
362
363
  });
363
364
  }
@@ -417,6 +418,7 @@ var init_ImageComponent = __esm({
417
418
  node.remove();
418
419
  }
419
420
  });
421
+ return true;
420
422
  }
421
423
  return false;
422
424
  },
@@ -586,6 +588,7 @@ var init_ImageComponent = __esm({
586
588
  {
587
589
  draggable,
588
590
  style: { position: "relative", display: "inline-block" },
591
+ onClick: (e) => onClick(e.nativeEvent),
589
592
  children: [
590
593
  isLoadError ? /* @__PURE__ */ jsx(BrokenImage, {}) : /* @__PURE__ */ jsx(
591
594
  LazyImage,
@@ -863,6 +866,10 @@ var init_InlineImageComponent = __esm({
863
866
  imageCache2.add(src);
864
867
  resolve(null);
865
868
  };
869
+ img3.onerror = () => {
870
+ imageCache2.add(src);
871
+ resolve(null);
872
+ };
866
873
  });
867
874
  }
868
875
  };
@@ -907,6 +914,7 @@ var init_InlineImageComponent = __esm({
907
914
  }
908
915
  });
909
916
  }
917
+ return true;
910
918
  }
911
919
  return false;
912
920
  },
@@ -1026,34 +1034,42 @@ var init_InlineImageComponent = __esm({
1026
1034
  };
1027
1035
  const draggable = !isResizing;
1028
1036
  const isFocused = (isSelected || isResizing) && isEditable;
1029
- return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsxs("span", { draggable, style: { position: "relative", display: "inline-block" }, children: [
1030
- /* @__PURE__ */ jsx(
1031
- LazyImage2,
1032
- {
1033
- className: isFocused ? `focused ${$isNodeSelection(selection) ? "draggable" : ""}` : null,
1034
- src,
1035
- altText,
1036
- imageRef,
1037
- width,
1038
- height,
1039
- position
1040
- }
1041
- ),
1042
- $isNodeSelection(selection) && isFocused && /* @__PURE__ */ jsx(
1043
- ImageResizer_default,
1044
- {
1045
- showCaption: false,
1046
- setShowCaption: () => {
1047
- },
1048
- captionsEnabled: false,
1049
- editor,
1050
- buttonRef,
1051
- imageRef,
1052
- onResizeStart,
1053
- onResizeEnd
1054
- }
1055
- )
1056
- ] }) });
1037
+ return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsxs(
1038
+ "span",
1039
+ {
1040
+ draggable,
1041
+ style: { position: "relative", display: "inline-block" },
1042
+ onClick: (e) => onClick(e.nativeEvent),
1043
+ children: [
1044
+ /* @__PURE__ */ jsx(
1045
+ LazyImage2,
1046
+ {
1047
+ className: isFocused ? `focused ${$isNodeSelection(selection) ? "draggable" : ""}` : null,
1048
+ src,
1049
+ altText,
1050
+ imageRef,
1051
+ width,
1052
+ height,
1053
+ position
1054
+ }
1055
+ ),
1056
+ $isNodeSelection(selection) && isFocused && /* @__PURE__ */ jsx(
1057
+ ImageResizer_default,
1058
+ {
1059
+ showCaption: false,
1060
+ setShowCaption: () => {
1061
+ },
1062
+ captionsEnabled: false,
1063
+ editor,
1064
+ buttonRef,
1065
+ imageRef,
1066
+ onResizeStart,
1067
+ onResizeEnd
1068
+ }
1069
+ )
1070
+ ]
1071
+ }
1072
+ ) });
1057
1073
  };
1058
1074
  InlineImageComponent_default = InlineImageComponent;
1059
1075
  }
@@ -2934,6 +2950,7 @@ var ALLOWED_ATTRS = /* @__PURE__ */ new Set([
2934
2950
  "allowfullscreen"
2935
2951
  ]);
2936
2952
  var DANGEROUS_URL = /^\s*(javascript|data\s*:|vbscript)/i;
2953
+ var SAFE_IMAGE_DATA_URL = /^\s*data:image\/[a-z0-9.+-]+;base64,/i;
2937
2954
  function sanitizeElement(el) {
2938
2955
  for (const child of Array.from(el.children)) {
2939
2956
  sanitizeElement(child);
@@ -2965,7 +2982,8 @@ function sanitizeElement(el) {
2965
2982
  continue;
2966
2983
  }
2967
2984
  if (lname === "href" || lname === "src") {
2968
- if (DANGEROUS_URL.test(value)) {
2985
+ const isSafeImageDataUrl = tag === "img" && lname === "src" && SAFE_IMAGE_DATA_URL.test(value);
2986
+ if (DANGEROUS_URL.test(value) && !isSafeImageDataUrl) {
2969
2987
  el.removeAttribute(name);
2970
2988
  }
2971
2989
  }
@@ -4131,11 +4149,6 @@ var InlineImagePlugin = () => {
4131
4149
  if ($isRootOrShadowRoot(imageNode.getParentOrThrow())) {
4132
4150
  $wrapNodeInElement(imageNode, $createParagraphNode).selectEnd();
4133
4151
  }
4134
- const parent = imageNode.getParent();
4135
- if (parent && typeof parent.setFormat === "function") {
4136
- const fmt = payload.position === "right" ? "right" : payload.position === "full" ? "center" : "left";
4137
- parent.setFormat(fmt);
4138
- }
4139
4152
  return true;
4140
4153
  },
4141
4154
  COMMAND_PRIORITY_EDITOR
@@ -5088,6 +5101,7 @@ function SpellCheckPlugin({
5088
5101
  }
5089
5102
  function TableActionMenuPlugin({ disabled = false }) {
5090
5103
  const [editor] = useLexicalComposerContext();
5104
+ const portalContainer = useFloatingPortalContainer(editor);
5091
5105
  const [isInTable, setIsInTable] = React9.useState(false);
5092
5106
  const [anchorRect, setAnchorRect] = React9.useState(null);
5093
5107
  const [contentRight, setContentRight] = React9.useState(null);
@@ -5170,6 +5184,18 @@ function TableActionMenuPlugin({ disabled = false }) {
5170
5184
  })
5171
5185
  );
5172
5186
  }, [editor, updateFromSelection]);
5187
+ React9.useEffect(() => {
5188
+ const root = editor.getRootElement();
5189
+ const reposition = () => updateFromSelection();
5190
+ window.addEventListener("resize", reposition);
5191
+ window.addEventListener("scroll", reposition, true);
5192
+ root?.addEventListener("scroll", reposition, { passive: true });
5193
+ return () => {
5194
+ window.removeEventListener("resize", reposition);
5195
+ window.removeEventListener("scroll", reposition, true);
5196
+ root?.removeEventListener("scroll", reposition);
5197
+ };
5198
+ }, [editor, updateFromSelection]);
5173
5199
  React9.useEffect(() => {
5174
5200
  return editor.registerCommand(
5175
5201
  KEY_DOWN_COMMAND,
@@ -5221,7 +5247,10 @@ function TableActionMenuPlugin({ disabled = false }) {
5221
5247
  position: "fixed",
5222
5248
  top,
5223
5249
  left,
5224
- zIndex: 9999
5250
+ // Matches the other floating surfaces (see FloatingPortal.ts): must clear
5251
+ // Fluent's Panel/Modal Layer host (z-index 1000000), otherwise this
5252
+ // button renders behind the modal chrome in a full-page/Panel view.
5253
+ zIndex: 10000010
5225
5254
  };
5226
5255
  }, [anchorRect, contentRight]);
5227
5256
  const dangerStyle = {
@@ -5264,7 +5293,7 @@ function TableActionMenuPlugin({ disabled = false }) {
5264
5293
  if (tableNode) tableNode.remove();
5265
5294
  });
5266
5295
  };
5267
- if (!canShow || !handleStyle) return null;
5296
+ if (!canShow || !handleStyle || !portalContainer) return null;
5268
5297
  return createPortal(
5269
5298
  /* @__PURE__ */ jsx("div", { style: handleStyle, className: "aoTableActionHandleRoot", "data-lexical-editor-portal": "true", children: /* @__PURE__ */ jsxs(Menu, { open, onOpenChange: (_, data) => {
5270
5299
  openRef.current = data.open;
@@ -5321,7 +5350,7 @@ function TableActionMenuPlugin({ disabled = false }) {
5321
5350
  ] })
5322
5351
  ] }) })
5323
5352
  ] }) }),
5324
- document.body
5353
+ portalContainer
5325
5354
  );
5326
5355
  }
5327
5356
  var MIN_ROW_HEIGHT = 33;
@@ -6020,6 +6049,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon, onOpenChange
6020
6049
  "div",
6021
6050
  {
6022
6051
  ref: svRef,
6052
+ "data-testid": "color-sv-box",
6023
6053
  onPointerDown: handleSVPointerDown,
6024
6054
  onPointerMove: handleSVPointerMove,
6025
6055
  style: {
@@ -6077,6 +6107,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon, onOpenChange
6077
6107
  "div",
6078
6108
  {
6079
6109
  ref: hueRef,
6110
+ "data-testid": "color-hue-bar",
6080
6111
  onPointerDown: handleHuePointerDown,
6081
6112
  onPointerMove: handleHuePointerMove,
6082
6113
  style: {
@@ -6126,6 +6157,7 @@ var ColorPickerControl = ({ value, title, disabled, onChange, icon, onOpenChange
6126
6157
  /* @__PURE__ */ jsx(
6127
6158
  TextField,
6128
6159
  {
6160
+ "data-testid": "color-hex-input",
6129
6161
  value: hexText,
6130
6162
  onChange: handleHexChange,
6131
6163
  onBlur: handleHexBlur,
@@ -6609,7 +6641,7 @@ var TableItemPlugin = ({ disabled }) => {
6609
6641
  const col = Number(columns);
6610
6642
  if (!row || !col) return;
6611
6643
  editor.update(() => {
6612
- const tableNode = $createTableNodeWithDimensions(row, col, true);
6644
+ const tableNode = $createTableNodeWithDimensions(row, col, { columns: false, rows: true });
6613
6645
  $insertNodeToNearestRoot(tableNode);
6614
6646
  });
6615
6647
  setRows("");