@elementor/editor-controls 3.35.0-351 → 3.35.0-352

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
@@ -5909,16 +5909,19 @@ var DateTimeControl = createControl(({ inputDisabled }) => {
5909
5909
  // src/controls/inline-editing-control.tsx
5910
5910
  import * as React102 from "react";
5911
5911
  import { htmlPropTypeUtil } from "@elementor/editor-props";
5912
+ import { Box as Box23 } from "@elementor/ui";
5912
5913
 
5913
5914
  // src/components/inline-editor.tsx
5914
5915
  import * as React101 from "react";
5915
- import { useEffect as useEffect10, useRef as useRef26 } from "react";
5916
- import { Box as Box22 } from "@elementor/ui";
5916
+ import { useEffect as useEffect11, useRef as useRef27 } from "react";
5917
+ import { bindPopover as bindPopover8, Box as Box22, ClickAwayListener, Popover as Popover8, usePopupState as usePopupState9 } from "@elementor/ui";
5917
5918
  import Bold from "@tiptap/extension-bold";
5918
5919
  import Document from "@tiptap/extension-document";
5919
5920
  import HardBreak from "@tiptap/extension-hard-break";
5921
+ import Heading from "@tiptap/extension-heading";
5920
5922
  import Italic from "@tiptap/extension-italic";
5921
5923
  import Link3 from "@tiptap/extension-link";
5924
+ import Paragraph from "@tiptap/extension-paragraph";
5922
5925
  import Strike from "@tiptap/extension-strike";
5923
5926
  import Subscript from "@tiptap/extension-subscript";
5924
5927
  import Superscript from "@tiptap/extension-superscript";
@@ -5926,6 +5929,16 @@ import Text from "@tiptap/extension-text";
5926
5929
  import Underline from "@tiptap/extension-underline";
5927
5930
  import { EditorContent, useEditor } from "@tiptap/react";
5928
5931
 
5932
+ // src/utils/inline-editing.ts
5933
+ function isEmpty(value = "") {
5934
+ if (!value) {
5935
+ return true;
5936
+ }
5937
+ const pseudoElement = document.createElement("div");
5938
+ pseudoElement.innerHTML = value;
5939
+ return !pseudoElement.textContent?.length;
5940
+ }
5941
+
5929
5942
  // src/components/inline-editor-toolbar.tsx
5930
5943
  import * as React100 from "react";
5931
5944
  import { useMemo as useMemo12, useRef as useRef25, useState as useState17 } from "react";
@@ -6085,7 +6098,7 @@ var InlineEditorToolbar = ({ editor }) => {
6085
6098
  const [urlValue, setUrlValue] = useState17("");
6086
6099
  const [openInNewTab, setOpenInNewTab] = useState17(false);
6087
6100
  const toolbarRef = useRef25(null);
6088
- const popupState = usePopupState8({ variant: "popover" });
6101
+ const linkPopupState = usePopupState8({ variant: "popover" });
6089
6102
  const editorState = useEditorState({
6090
6103
  editor,
6091
6104
  selector: (ctx) => possibleFormats.filter((format) => ctx.editor.isActive(format))
@@ -6095,7 +6108,7 @@ var InlineEditorToolbar = ({ editor }) => {
6095
6108
  const linkAttrs = editor.getAttributes("link");
6096
6109
  setUrlValue(linkAttrs.href || "");
6097
6110
  setOpenInNewTab(linkAttrs.target === "_blank");
6098
- popupState.open(toolbarRef.current);
6111
+ linkPopupState.open(toolbarRef.current);
6099
6112
  };
6100
6113
  const handleUrlChange = (event) => {
6101
6114
  setUrlValue(event.target.value);
@@ -6112,16 +6125,16 @@ var InlineEditorToolbar = ({ editor }) => {
6112
6125
  } else {
6113
6126
  editor.chain().focus().unsetLink().run();
6114
6127
  }
6115
- popupState.close();
6128
+ linkPopupState.close();
6116
6129
  };
6130
+ React100.useEffect(() => {
6131
+ editor?.commands?.focus();
6132
+ }, [editor]);
6117
6133
  return /* @__PURE__ */ React100.createElement(
6118
6134
  Box21,
6119
6135
  {
6120
6136
  ref: toolbarRef,
6121
6137
  sx: {
6122
- position: "absolute",
6123
- left: 0,
6124
- top: -40,
6125
6138
  display: "inline-flex",
6126
6139
  gap: 0.5,
6127
6140
  padding: 0.5,
@@ -6129,7 +6142,8 @@ var InlineEditorToolbar = ({ editor }) => {
6129
6142
  backgroundColor: "background.paper",
6130
6143
  boxShadow: "0 2px 8px rgba(0, 0, 0, 0.2)",
6131
6144
  alignItems: "center",
6132
- visibility: popupState.isOpen ? "hidden" : "visible"
6145
+ visibility: linkPopupState.isOpen ? "hidden" : "visible",
6146
+ pointerEvents: linkPopupState.isOpen ? "none" : "all"
6133
6147
  }
6134
6148
  },
6135
6149
  /* @__PURE__ */ React100.createElement(Tooltip9, { title: clearButton.label, placement: "top", sx: { borderRadius: "8px" } }, /* @__PURE__ */ React100.createElement(IconButton8, { "aria-label": clearButton.label, onClick: () => clearButton.method(editor), size: "tiny" }, clearButton.icon)),
@@ -6161,7 +6175,14 @@ var InlineEditorToolbar = ({ editor }) => {
6161
6175
  value: button.action,
6162
6176
  "aria-label": button.label,
6163
6177
  size: "tiny",
6164
- onClick: () => button.action === "link" ? handleLinkClick() : button.method?.(editor)
6178
+ onClick: () => {
6179
+ if (button.action === "link") {
6180
+ handleLinkClick();
6181
+ } else {
6182
+ button.method?.(editor);
6183
+ }
6184
+ editor?.commands?.focus();
6185
+ }
6165
6186
  },
6166
6187
  button.icon
6167
6188
  )))
@@ -6169,7 +6190,7 @@ var InlineEditorToolbar = ({ editor }) => {
6169
6190
  /* @__PURE__ */ React100.createElement(
6170
6191
  UrlPopover,
6171
6192
  {
6172
- popupState,
6193
+ popupState: linkPopupState,
6173
6194
  anchorRef: toolbarRef,
6174
6195
  restoreValue: handleUrlSubmit,
6175
6196
  value: urlValue,
@@ -6183,8 +6204,8 @@ var InlineEditorToolbar = ({ editor }) => {
6183
6204
 
6184
6205
  // src/components/inline-editor.tsx
6185
6206
  var useOnUpdate = (callback, dependencies) => {
6186
- const hasMounted = useRef26(false);
6187
- useEffect10(() => {
6207
+ const hasMounted = useRef27(false);
6208
+ useEffect11(() => {
6188
6209
  if (hasMounted.current) {
6189
6210
  callback();
6190
6211
  } else {
@@ -6193,22 +6214,67 @@ var useOnUpdate = (callback, dependencies) => {
6193
6214
  }, dependencies);
6194
6215
  };
6195
6216
  var InlineEditor = React101.forwardRef(
6196
- ({ value, setValue, attributes = {}, showToolbar = false, sx, ...props }, ref) => {
6217
+ ({
6218
+ value,
6219
+ setValue,
6220
+ attributes = {},
6221
+ showToolbar = false,
6222
+ autofocus = false,
6223
+ sx = {},
6224
+ onBlur = void 0,
6225
+ getInitialPopoverPosition = void 0,
6226
+ expectedTag = null
6227
+ }, ref) => {
6228
+ const containerRef = React101.useRef(null);
6229
+ const popupState = usePopupState9({ variant: "popover", disableAutoFocus: true });
6230
+ const [hasSelectedContent, setHasSelectedContent] = React101.useState(false);
6231
+ const documentContentSettings = !!expectedTag ? "block+" : "inline*";
6232
+ const onSelectionEnd = (view) => {
6233
+ setHasSelectedContent(() => !view.state.selection.empty);
6234
+ queueMicrotask(() => view.focus());
6235
+ };
6236
+ const onKeyDown = (_, event) => {
6237
+ if (event.key === "Escape") {
6238
+ onBlur?.(event);
6239
+ }
6240
+ };
6241
+ const toolbarRelatedListeners = showToolbar ? {
6242
+ mouseup: onSelectionEnd,
6243
+ keyup: onSelectionEnd,
6244
+ keydown: onKeyDown
6245
+ } : void 0;
6197
6246
  const editor = useEditor({
6198
6247
  extensions: [
6199
6248
  Document.extend({
6200
- content: "inline*"
6249
+ content: documentContentSettings
6250
+ }),
6251
+ Paragraph.extend({
6252
+ renderHTML({ HTMLAttributes }) {
6253
+ const tag = expectedTag ?? "p";
6254
+ return [tag, { ...HTMLAttributes, style: "margin:0;padding:0;" }, 0];
6255
+ }
6256
+ }),
6257
+ Heading.extend({
6258
+ renderHTML({ node, HTMLAttributes }) {
6259
+ if (expectedTag) {
6260
+ return [expectedTag, { ...HTMLAttributes, style: "margin:0;padding:0;" }, 0];
6261
+ }
6262
+ const level = this.options.levels.includes(node.attrs.level) ? node.attrs.level : this.options.levels[0];
6263
+ return [`h${level}`, { ...HTMLAttributes, style: "margin:0;padding:0;" }, 0];
6264
+ }
6265
+ }).configure({
6266
+ levels: [1, 2, 3, 4, 5, 6]
6267
+ }),
6268
+ Link3.configure({
6269
+ openOnClick: false
6201
6270
  }),
6202
6271
  Text,
6203
6272
  Bold,
6204
6273
  Italic,
6205
6274
  Strike,
6206
- Underline,
6207
6275
  Superscript,
6208
6276
  Subscript,
6209
- Link3.configure({
6210
- openOnClick: false
6211
- }),
6277
+ Underline,
6212
6278
  HardBreak.extend({
6213
6279
  addKeyboardShortcuts() {
6214
6280
  return {
@@ -6218,7 +6284,19 @@ var InlineEditor = React101.forwardRef(
6218
6284
  })
6219
6285
  ],
6220
6286
  content: value,
6221
- onUpdate: ({ editor: updatedEditor }) => setValue(updatedEditor.getHTML())
6287
+ onUpdate: ({ editor: updatedEditor }) => {
6288
+ const newValue = updatedEditor.getHTML();
6289
+ setValue(isEmpty(newValue) ? null : newValue);
6290
+ },
6291
+ autofocus,
6292
+ editorProps: {
6293
+ attributes: {
6294
+ ...attributes,
6295
+ class: attributes.class ?? "",
6296
+ role: "textbox"
6297
+ },
6298
+ handleDOMEvents: toolbarRelatedListeners
6299
+ }
6222
6300
  });
6223
6301
  useOnUpdate(() => {
6224
6302
  if (!editor) {
@@ -6229,10 +6307,64 @@ var InlineEditor = React101.forwardRef(
6229
6307
  editor.commands.setContent(value, { emitUpdate: false });
6230
6308
  }
6231
6309
  }, [editor, value]);
6232
- return /* @__PURE__ */ React101.createElement(
6233
- Box22,
6310
+ const computePopupPosition = () => {
6311
+ const positionFallback = { left: 0, top: 0 };
6312
+ const { left, top } = containerRef.current?.getBoundingClientRect() ?? positionFallback;
6313
+ const initial = getInitialPopoverPosition?.() ?? positionFallback;
6314
+ return {
6315
+ left: left + initial.left,
6316
+ top: top + initial.top
6317
+ };
6318
+ };
6319
+ const Wrapper = ({ children }) => {
6320
+ const wrappedChildren = /* @__PURE__ */ React101.createElement(Box22, { ref: containerRef, ...sx }, children);
6321
+ return onBlur ? /* @__PURE__ */ React101.createElement(
6322
+ ClickAwayListener,
6323
+ {
6324
+ onClickAway: (event) => {
6325
+ if (containerRef.current?.contains(event.target) || editor.view.dom.contains(event.target)) {
6326
+ return;
6327
+ }
6328
+ onBlur?.(event);
6329
+ }
6330
+ },
6331
+ wrappedChildren
6332
+ ) : /* @__PURE__ */ React101.createElement(React101.Fragment, null, wrappedChildren);
6333
+ };
6334
+ return /* @__PURE__ */ React101.createElement(React101.Fragment, null, /* @__PURE__ */ React101.createElement(Wrapper, null, /* @__PURE__ */ React101.createElement(EditorContent, { ref, editor })), showToolbar && containerRef.current && /* @__PURE__ */ React101.createElement(
6335
+ Popover8,
6336
+ {
6337
+ slotProps: {
6338
+ root: {
6339
+ sx: {
6340
+ pointerEvents: "none"
6341
+ }
6342
+ }
6343
+ },
6344
+ ...bindPopover8(popupState),
6345
+ open: hasSelectedContent,
6346
+ anchorReference: "anchorPosition",
6347
+ anchorPosition: computePopupPosition(),
6348
+ anchorOrigin: { vertical: "top", horizontal: "left" },
6349
+ transformOrigin: { vertical: "bottom", horizontal: "left" }
6350
+ },
6351
+ /* @__PURE__ */ React101.createElement(InlineEditorToolbar, { editor })
6352
+ ));
6353
+ }
6354
+ );
6355
+
6356
+ // src/controls/inline-editing-control.tsx
6357
+ var InlineEditingControl = createControl(
6358
+ ({
6359
+ sx,
6360
+ attributes,
6361
+ props
6362
+ }) => {
6363
+ const { value, setValue } = useBoundProp(htmlPropTypeUtil);
6364
+ const handleChange = (newValue) => setValue(newValue);
6365
+ return /* @__PURE__ */ React102.createElement(ControlActions, null, /* @__PURE__ */ React102.createElement(
6366
+ Box23,
6234
6367
  {
6235
- ref,
6236
6368
  sx: {
6237
6369
  p: 0.8,
6238
6370
  border: "1px solid",
@@ -6256,24 +6388,19 @@ var InlineEditor = React101.forwardRef(
6256
6388
  color: "inherit"
6257
6389
  }
6258
6390
  },
6391
+ ".strip-styles *": {
6392
+ all: "unset"
6393
+ },
6259
6394
  ...sx
6260
6395
  },
6261
6396
  ...attributes,
6262
6397
  ...props
6263
6398
  },
6264
- showToolbar && /* @__PURE__ */ React101.createElement(InlineEditorToolbar, { editor }),
6265
- /* @__PURE__ */ React101.createElement(EditorContent, { editor })
6266
- );
6399
+ /* @__PURE__ */ React102.createElement(InlineEditor, { value: value || "", setValue: handleChange })
6400
+ ));
6267
6401
  }
6268
6402
  );
6269
6403
 
6270
- // src/controls/inline-editing-control.tsx
6271
- var InlineEditingControl = createControl(() => {
6272
- const { value, setValue } = useBoundProp(htmlPropTypeUtil);
6273
- const handleChange = (newValue) => setValue(newValue);
6274
- return /* @__PURE__ */ React102.createElement(ControlActions, null, /* @__PURE__ */ React102.createElement(InlineEditor, { value: value || "", setValue: handleChange }));
6275
- });
6276
-
6277
6404
  // src/components/icon-buttons/clear-icon-button.tsx
6278
6405
  import * as React103 from "react";
6279
6406
  import { BrushBigIcon } from "@elementor/icons";
@@ -6286,16 +6413,16 @@ var ClearIconButton = ({ tooltipText, onClick, disabled, size = "tiny" }) => /*
6286
6413
 
6287
6414
  // src/components/repeater/repeater.tsx
6288
6415
  import * as React104 from "react";
6289
- import { useEffect as useEffect11, useState as useState18 } from "react";
6416
+ import { useEffect as useEffect12, useState as useState19 } from "react";
6290
6417
  import { CopyIcon as CopyIcon2, EyeIcon as EyeIcon2, EyeOffIcon as EyeOffIcon2, PlusIcon as PlusIcon3, XIcon as XIcon4 } from "@elementor/icons";
6291
6418
  import {
6292
- bindPopover as bindPopover8,
6419
+ bindPopover as bindPopover9,
6293
6420
  bindTrigger as bindTrigger6,
6294
- Box as Box23,
6421
+ Box as Box24,
6295
6422
  IconButton as IconButton10,
6296
6423
  Infotip as Infotip4,
6297
6424
  Tooltip as Tooltip11,
6298
- usePopupState as usePopupState9
6425
+ usePopupState as usePopupState10
6299
6426
  } from "@elementor/ui";
6300
6427
  import { __ as __52 } from "@wordpress/i18n";
6301
6428
  var SIZE9 = "tiny";
@@ -6315,7 +6442,7 @@ var Repeater3 = ({
6315
6442
  openItem: initialOpenItem = EMPTY_OPEN_ITEM2,
6316
6443
  isSortable = true
6317
6444
  }) => {
6318
- const [openItem, setOpenItem] = useState18(initialOpenItem);
6445
+ const [openItem, setOpenItem] = useState19(initialOpenItem);
6319
6446
  const uniqueKeys = items2.map(
6320
6447
  (item, index) => isSortable && "getId" in itemSettings ? itemSettings.getId({ item, index }) : String(index)
6321
6448
  );
@@ -6399,7 +6526,7 @@ var Repeater3 = ({
6399
6526
  color: "secondary",
6400
6527
  slotProps: { popper: { sx: { width: 300 } } }
6401
6528
  },
6402
- /* @__PURE__ */ React104.createElement(Box23, { sx: { ...isButtonDisabled ? { cursor: "not-allowed" } : {} } }, addButton)
6529
+ /* @__PURE__ */ React104.createElement(Box24, { sx: { ...isButtonDisabled ? { cursor: "not-allowed" } : {} } }, addButton)
6403
6530
  ) : addButton), 0 < uniqueKeys.length && /* @__PURE__ */ React104.createElement(SortableProvider, { value: uniqueKeys, onChange: onChangeOrder }, uniqueKeys.map((key) => {
6404
6531
  const index = uniqueKeys.indexOf(key);
6405
6532
  const value = items2[index];
@@ -6468,13 +6595,13 @@ var RepeaterItem = ({
6468
6595
  startIcon,
6469
6596
  actions: /* @__PURE__ */ React104.createElement(React104.Fragment, null, showDuplicate && /* @__PURE__ */ React104.createElement(Tooltip11, { title: duplicateLabel, placement: "top" }, /* @__PURE__ */ React104.createElement(IconButton10, { size: SIZE9, onClick: duplicateItem, "aria-label": duplicateLabel }, /* @__PURE__ */ React104.createElement(CopyIcon2, { fontSize: SIZE9 }))), showToggle && /* @__PURE__ */ React104.createElement(Tooltip11, { title: toggleLabel, placement: "top" }, /* @__PURE__ */ React104.createElement(IconButton10, { size: SIZE9, onClick: toggleDisableItem, "aria-label": toggleLabel }, propDisabled ? /* @__PURE__ */ React104.createElement(EyeOffIcon2, { fontSize: SIZE9 }) : /* @__PURE__ */ React104.createElement(EyeIcon2, { fontSize: SIZE9 }))), actions?.(value), showRemove && /* @__PURE__ */ React104.createElement(Tooltip11, { title: removeLabel, placement: "top" }, /* @__PURE__ */ React104.createElement(IconButton10, { size: SIZE9, onClick: removeItem, "aria-label": removeLabel }, /* @__PURE__ */ React104.createElement(XIcon4, { fontSize: SIZE9 }))))
6470
6597
  }
6471
- ), /* @__PURE__ */ React104.createElement(RepeaterPopover, { width: ref?.getBoundingClientRect().width, ...popoverProps, anchorEl: ref }, /* @__PURE__ */ React104.createElement(Box23, null, children({ anchorEl: ref }))));
6598
+ ), /* @__PURE__ */ React104.createElement(RepeaterPopover, { width: ref?.getBoundingClientRect().width, ...popoverProps, anchorEl: ref }, /* @__PURE__ */ React104.createElement(Box24, null, children({ anchorEl: ref }))));
6472
6599
  };
6473
6600
  var usePopover = (openOnMount, onOpen) => {
6474
- const [ref, setRef] = useState18(null);
6475
- const popoverState = usePopupState9({ variant: "popover" });
6476
- const popoverProps = bindPopover8(popoverState);
6477
- useEffect11(() => {
6601
+ const [ref, setRef] = useState19(null);
6602
+ const popoverState = usePopupState10({ variant: "popover" });
6603
+ const popoverProps = bindPopover9(popoverState);
6604
+ useEffect12(() => {
6478
6605
  if (openOnMount && ref) {
6479
6606
  popoverState.open(ref);
6480
6607
  onOpen?.();