@elementor/editor-controls 4.1.0-796 → 4.1.0-798

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.d.mts CHANGED
@@ -40,12 +40,15 @@ type Suggestion = {
40
40
  value: string;
41
41
  };
42
42
 
43
+ type TriggerPosition = 'start' | 'auto';
43
44
  type Props$b = {
44
45
  placeholder?: string;
45
46
  ariaLabel?: string;
46
47
  suggestions: Suggestion[];
48
+ rows?: number;
49
+ triggerPosition?: TriggerPosition;
47
50
  };
48
- declare const MentionTextAreaControl: ControlComponent$1<({ placeholder, ariaLabel, suggestions: allSuggestions }: Props$b) => React$1.JSX.Element>;
51
+ declare const MentionTextAreaControl: ControlComponent$1<({ placeholder, ariaLabel, suggestions: allSuggestions, rows, triggerPosition }: Props$b) => React$1.JSX.Element>;
49
52
 
50
53
  declare const lengthUnits: readonly ["px", "%", "em", "rem", "vw", "vh", "ch"];
51
54
  declare const angleUnits: readonly ["deg", "rad", "grad", "turn"];
package/dist/index.d.ts CHANGED
@@ -40,12 +40,15 @@ type Suggestion = {
40
40
  value: string;
41
41
  };
42
42
 
43
+ type TriggerPosition = 'start' | 'auto';
43
44
  type Props$b = {
44
45
  placeholder?: string;
45
46
  ariaLabel?: string;
46
47
  suggestions: Suggestion[];
48
+ rows?: number;
49
+ triggerPosition?: TriggerPosition;
47
50
  };
48
- declare const MentionTextAreaControl: ControlComponent$1<({ placeholder, ariaLabel, suggestions: allSuggestions }: Props$b) => React$1.JSX.Element>;
51
+ declare const MentionTextAreaControl: ControlComponent$1<({ placeholder, ariaLabel, suggestions: allSuggestions, rows, triggerPosition }: Props$b) => React$1.JSX.Element>;
49
52
 
50
53
  declare const lengthUnits: readonly ["px", "%", "em", "rem", "vw", "vh", "ch"];
51
54
  declare const angleUnits: readonly ["deg", "rad", "grad", "turn"];
package/dist/index.js CHANGED
@@ -748,25 +748,30 @@ var MentionWrapper = (0, import_ui9.styled)("div")(({ theme }) => ({
748
748
  "&.p-highlight": {
749
749
  backgroundColor: theme.palette.action.selected
750
750
  }
751
+ },
752
+ '&[data-single-line="true"] textarea': {
753
+ resize: "none"
751
754
  }
752
755
  }));
756
+ function createMentionPattern(value, triggerPosition) {
757
+ const escaped = value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
758
+ const prefix = "start" === triggerPosition ? "^" : "";
759
+ return new RegExp(`${prefix}@${escaped}(?=\\s|$|[^a-zA-Z0-9_-])`, "g");
760
+ }
753
761
  var MentionTextAreaControl = createControl(
754
- ({ placeholder, ariaLabel, suggestions: allSuggestions }) => {
762
+ ({ placeholder, ariaLabel, suggestions: allSuggestions, rows = 5, triggerPosition = "auto" }) => {
755
763
  const { value, setValue, disabled } = useBoundProp(import_editor_props6.stringPropTypeUtil);
756
764
  const [filteredSuggestions, setFilteredSuggestions] = (0, import_react7.useState)([]);
757
765
  const transformMentionsToShortcodes = (0, import_react7.useCallback)(
758
766
  (text) => {
759
767
  let result = text;
760
768
  for (const suggestion of allSuggestions) {
761
- const mentionPattern = new RegExp(
762
- `@${suggestion.value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?=\\s|$|[^a-zA-Z0-9_-])`,
763
- "g"
764
- );
765
- result = result.replace(mentionPattern, `[${suggestion.value}]`);
769
+ const pattern = createMentionPattern(suggestion.value, triggerPosition);
770
+ result = result.replace(pattern, `[${suggestion.value}]`);
766
771
  }
767
772
  return result;
768
773
  },
769
- [allSuggestions]
774
+ [allSuggestions, triggerPosition]
770
775
  );
771
776
  const handleChange = (0, import_react7.useCallback)(
772
777
  (e) => {
@@ -778,15 +783,23 @@ var MentionTextAreaControl = createControl(
778
783
  );
779
784
  const handleSearch = (0, import_react7.useCallback)(
780
785
  (event) => {
786
+ if ("start" === triggerPosition) {
787
+ const target = event.originalEvent.target;
788
+ const triggerIndex = target.selectionStart - event.query.length - event.trigger.length;
789
+ if (triggerIndex !== 0) {
790
+ setFilteredSuggestions([]);
791
+ return;
792
+ }
793
+ }
781
794
  const query = event.query.toLowerCase();
782
795
  const filtered = allSuggestions.filter(
783
796
  (item) => item.label.toLowerCase().includes(query) || item.value.toLowerCase().includes(query)
784
797
  );
785
798
  setFilteredSuggestions(filtered);
786
799
  },
787
- [allSuggestions]
800
+ [allSuggestions, triggerPosition]
788
801
  );
789
- return /* @__PURE__ */ React16.createElement(ControlActions, null, /* @__PURE__ */ React16.createElement(MentionWrapper, null, /* @__PURE__ */ React16.createElement(
802
+ return /* @__PURE__ */ React16.createElement(ControlActions, null, /* @__PURE__ */ React16.createElement(MentionWrapper, { "data-single-line": rows === 1 ? "true" : void 0 }, /* @__PURE__ */ React16.createElement(
790
803
  import_mention.Mention,
791
804
  {
792
805
  value: value ?? "",
@@ -795,7 +808,7 @@ var MentionTextAreaControl = createControl(
795
808
  onSearch: handleSearch,
796
809
  field: "value",
797
810
  trigger: "@",
798
- rows: 5,
811
+ rows,
799
812
  disabled,
800
813
  placeholder,
801
814
  itemTemplate: SuggestionItem,
@@ -3413,7 +3426,7 @@ var SizeField = ({
3413
3426
  }
3414
3427
  ))
3415
3428
  },
3416
- inputProps: { min, step: "any", "arial-label": ariaLabel }
3429
+ inputProps: { min, step: "any", "aria-label": ariaLabel }
3417
3430
  }
3418
3431
  );
3419
3432
  };
@@ -7606,7 +7619,7 @@ var import_editor_elements6 = require("@elementor/editor-elements");
7606
7619
  var import_editor_props57 = require("@elementor/editor-props");
7607
7620
  var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
7608
7621
  var FORM_FIELD_WIDGET_TYPES = ["e-form-input", "e-form-textarea", "e-form-checkbox"];
7609
- function useFormFieldSuggestions() {
7622
+ function useFormFieldSuggestions(options) {
7610
7623
  return (0, import_editor_v1_adapters.__privateUseListenTo)(
7611
7624
  [
7612
7625
  (0, import_editor_v1_adapters.v1ReadyEvent)(),
@@ -7630,6 +7643,13 @@ function useFormFieldSuggestions() {
7630
7643
  if (!widgetType || !FORM_FIELD_WIDGET_TYPES.includes(widgetType)) {
7631
7644
  return;
7632
7645
  }
7646
+ if (options?.inputType) {
7647
+ const typeProp = child.settings.get("type");
7648
+ const typeValue = (0, import_editor_props57.isTransformable)(typeProp) ? typeProp.value : typeProp;
7649
+ if (typeValue !== options.inputType) {
7650
+ return;
7651
+ }
7652
+ }
7633
7653
  const cssIdProp = child.settings.get("_cssid");
7634
7654
  const fieldId = (0, import_editor_props57.isTransformable)(cssIdProp) ? cssIdProp.value : cssIdProp;
7635
7655
  if (fieldId && typeof fieldId === "string") {
@@ -7687,7 +7707,18 @@ var FromNameField = () => /* @__PURE__ */ React109.createElement(
7687
7707
  placeholder: (0, import_i18n53.__)("What name should appear as the sender?", "elementor")
7688
7708
  }
7689
7709
  );
7690
- var ReplyToField = () => /* @__PURE__ */ React109.createElement(EmailField, { bind: "reply-to", label: (0, import_i18n53.__)("Reply-to", "elementor") });
7710
+ var ReplyToField = () => {
7711
+ const emailSuggestions = useFormFieldSuggestions({ inputType: "email" });
7712
+ return /* @__PURE__ */ React109.createElement(PropKeyProvider, { bind: "reply-to" }, /* @__PURE__ */ React109.createElement(import_ui93.Grid, { container: true, direction: "column", gap: 0.5 }, /* @__PURE__ */ React109.createElement(import_ui93.Grid, { item: true }, /* @__PURE__ */ React109.createElement(ControlFormLabel, null, (0, import_i18n53.__)("Reply-to", "elementor"))), /* @__PURE__ */ React109.createElement(import_ui93.Grid, { item: true }, /* @__PURE__ */ React109.createElement(
7713
+ MentionTextAreaControl,
7714
+ {
7715
+ suggestions: emailSuggestions,
7716
+ rows: 1,
7717
+ triggerPosition: "start",
7718
+ placeholder: (0, import_i18n53.__)("You can type @ to insert an email field", "elementor")
7719
+ }
7720
+ ))));
7721
+ };
7691
7722
  var CcField = () => /* @__PURE__ */ React109.createElement(EmailField, { bind: "cc", label: (0, import_i18n53.__)("Cc", "elementor") });
7692
7723
  var BccField = () => /* @__PURE__ */ React109.createElement(EmailField, { bind: "bcc", label: (0, import_i18n53.__)("Bcc", "elementor") });
7693
7724
  var MetaDataField = () => /* @__PURE__ */ React109.createElement(PropKeyProvider, { bind: "meta-data" }, /* @__PURE__ */ React109.createElement(import_ui93.Stack, { gap: 0.5 }, /* @__PURE__ */ React109.createElement(ControlFormLabel, null, (0, import_i18n53.__)("Metadata", "elementor")), /* @__PURE__ */ React109.createElement(