@elementor/editor-controls 0.1.0 → 0.1.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @elementor/editor-controls
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 1926fe1: Update dependencies
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentType, ReactNode, PropsWithChildren } from 'react';
3
3
  import { PropValue, TransformablePropValue, SizePropValue, PropKey } from '@elementor/editor-props';
4
- import { UnstableColorFieldProps, ToggleButtonProps } from '@elementor/ui';
4
+ import { UnstableColorFieldProps, ToggleButtonProps, StackProps } from '@elementor/ui';
5
5
 
6
6
  type AnyComponentType = ComponentType<any>;
7
7
  declare const brandSymbol: unique symbol;
@@ -21,10 +21,10 @@ declare const TextControl: ControlComponent<({ placeholder }: {
21
21
  placeholder?: string;
22
22
  }) => React.JSX.Element>;
23
23
 
24
- type Props$2 = {
24
+ type Props$3 = {
25
25
  placeholder?: string;
26
26
  };
27
- declare const TextAreaControl: ControlComponent<({ placeholder }: Props$2) => React.JSX.Element>;
27
+ declare const TextAreaControl: ControlComponent<({ placeholder }: Props$3) => React.JSX.Element>;
28
28
 
29
29
  type Unit = 'px' | '%' | 'em' | 'rem' | 'vw' | 'vh';
30
30
  type SizeControlProps = {
@@ -40,14 +40,14 @@ declare const BoxShadowRepeaterControl: ControlComponent<() => React.JSX.Element
40
40
 
41
41
  declare const BackgroundOverlayRepeaterControl: ControlComponent<() => React.JSX.Element>;
42
42
 
43
- type Props$1<T> = {
43
+ type Props$2<T> = {
44
44
  options: Array<{
45
45
  label: string;
46
46
  value: T;
47
47
  disabled?: boolean;
48
48
  }>;
49
49
  };
50
- declare const SelectControl: ControlComponent<(<T extends PropValue>({ options }: Props$1<T>) => React.JSX.Element)>;
50
+ declare const SelectControl: ControlComponent<(<T extends PropValue>({ options }: Props$2<T>) => React.JSX.Element)>;
51
51
 
52
52
  declare const ColorControl: ControlComponent<(props: Partial<Omit<UnstableColorFieldProps, "value" | "onChange">>) => React.JSX.Element>;
53
53
 
@@ -60,6 +60,23 @@ type ToggleButtonGroupItem<TValue> = {
60
60
  renderContent: ({ size }: RenderContentProps) => React.ReactNode;
61
61
  showTooltip?: boolean;
62
62
  };
63
+ type ExclusiveValue<TValue> = TValue | null;
64
+ type NonExclusiveValue<TValue> = TValue[];
65
+ type Props$1<TValue> = {
66
+ justify?: StackProps['justifyContent'];
67
+ size?: ToggleButtonProps['size'];
68
+ items: ToggleButtonGroupItem<TValue>[];
69
+ fullWidth?: boolean;
70
+ } & ({
71
+ exclusive?: false;
72
+ value: NonExclusiveValue<TValue>;
73
+ onChange: (value: NonExclusiveValue<TValue>) => void;
74
+ } | {
75
+ exclusive: true;
76
+ value: ExclusiveValue<TValue>;
77
+ onChange: (value: ExclusiveValue<TValue>) => void;
78
+ });
79
+ declare const ControlToggleButtonGroup: <TValue>({ justify, size, value, onChange, items, exclusive, fullWidth, }: Props$1<TValue>) => React.JSX.Element;
63
80
 
64
81
  type ToggleControlProps<T extends PropValue> = {
65
82
  options: ToggleButtonGroupItem<T>[];
@@ -68,8 +85,12 @@ type ToggleControlProps<T extends PropValue> = {
68
85
  };
69
86
  declare const ToggleControl: ControlComponent<(<T extends PropValue>({ options, fullWidth, size }: ToggleControlProps<T>) => React.JSX.Element)>;
70
87
 
71
- declare const NumberControl: ControlComponent<({ placeholder }: {
88
+ declare const NumberControl: ControlComponent<({ placeholder, max, min, step, shouldForceInt, }: {
72
89
  placeholder?: string;
90
+ max?: number;
91
+ min?: number;
92
+ step?: number;
93
+ shouldForceInt?: boolean;
73
94
  }) => React.JSX.Element>;
74
95
 
75
96
  type MultiSizePropValue<TMultiPropType extends string> = TransformablePropValue<TMultiPropType, Record<string, SizePropValue>>;
@@ -145,4 +166,4 @@ type UseInternalStateOptions<TValue> = {
145
166
  };
146
167
  declare const useSyncExternalState: <TValue>({ external, setExternal, persistWhen, fallback, }: UseInternalStateOptions<TValue>) => readonly [TValue, (setter: ((value: TValue) => TValue) | TValue) => void];
147
168
 
148
- export { BackgroundOverlayRepeaterControl, BoundPropProvider, BoxShadowRepeaterControl, ColorControl, ControlActionsProvider, type ControlComponent, ControlLabel, ControlReplacementProvider, type EqualUnequalItems, EqualUnequalSizesControl, FontFamilyControl, ImageControl, LinkedDimensionsControl, NumberControl, SelectControl, SizeControl, StrokeControl, TextAreaControl, TextControl, type ToggleButtonGroupItem, ToggleControl, createControlReplacement, useBoundProp, useControlActions, useSyncExternalState };
169
+ export { BackgroundOverlayRepeaterControl, BoundPropProvider, BoxShadowRepeaterControl, ColorControl, ControlActionsProvider, type ControlComponent, ControlLabel, ControlReplacementProvider, ControlToggleButtonGroup, type EqualUnequalItems, EqualUnequalSizesControl, FontFamilyControl, ImageControl, LinkedDimensionsControl, NumberControl, SelectControl, SizeControl, StrokeControl, TextAreaControl, TextControl, type ToggleButtonGroupItem, ToggleControl, createControlReplacement, useBoundProp, useControlActions, useSyncExternalState };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentType, ReactNode, PropsWithChildren } from 'react';
3
3
  import { PropValue, TransformablePropValue, SizePropValue, PropKey } from '@elementor/editor-props';
4
- import { UnstableColorFieldProps, ToggleButtonProps } from '@elementor/ui';
4
+ import { UnstableColorFieldProps, ToggleButtonProps, StackProps } from '@elementor/ui';
5
5
 
6
6
  type AnyComponentType = ComponentType<any>;
7
7
  declare const brandSymbol: unique symbol;
@@ -21,10 +21,10 @@ declare const TextControl: ControlComponent<({ placeholder }: {
21
21
  placeholder?: string;
22
22
  }) => React.JSX.Element>;
23
23
 
24
- type Props$2 = {
24
+ type Props$3 = {
25
25
  placeholder?: string;
26
26
  };
27
- declare const TextAreaControl: ControlComponent<({ placeholder }: Props$2) => React.JSX.Element>;
27
+ declare const TextAreaControl: ControlComponent<({ placeholder }: Props$3) => React.JSX.Element>;
28
28
 
29
29
  type Unit = 'px' | '%' | 'em' | 'rem' | 'vw' | 'vh';
30
30
  type SizeControlProps = {
@@ -40,14 +40,14 @@ declare const BoxShadowRepeaterControl: ControlComponent<() => React.JSX.Element
40
40
 
41
41
  declare const BackgroundOverlayRepeaterControl: ControlComponent<() => React.JSX.Element>;
42
42
 
43
- type Props$1<T> = {
43
+ type Props$2<T> = {
44
44
  options: Array<{
45
45
  label: string;
46
46
  value: T;
47
47
  disabled?: boolean;
48
48
  }>;
49
49
  };
50
- declare const SelectControl: ControlComponent<(<T extends PropValue>({ options }: Props$1<T>) => React.JSX.Element)>;
50
+ declare const SelectControl: ControlComponent<(<T extends PropValue>({ options }: Props$2<T>) => React.JSX.Element)>;
51
51
 
52
52
  declare const ColorControl: ControlComponent<(props: Partial<Omit<UnstableColorFieldProps, "value" | "onChange">>) => React.JSX.Element>;
53
53
 
@@ -60,6 +60,23 @@ type ToggleButtonGroupItem<TValue> = {
60
60
  renderContent: ({ size }: RenderContentProps) => React.ReactNode;
61
61
  showTooltip?: boolean;
62
62
  };
63
+ type ExclusiveValue<TValue> = TValue | null;
64
+ type NonExclusiveValue<TValue> = TValue[];
65
+ type Props$1<TValue> = {
66
+ justify?: StackProps['justifyContent'];
67
+ size?: ToggleButtonProps['size'];
68
+ items: ToggleButtonGroupItem<TValue>[];
69
+ fullWidth?: boolean;
70
+ } & ({
71
+ exclusive?: false;
72
+ value: NonExclusiveValue<TValue>;
73
+ onChange: (value: NonExclusiveValue<TValue>) => void;
74
+ } | {
75
+ exclusive: true;
76
+ value: ExclusiveValue<TValue>;
77
+ onChange: (value: ExclusiveValue<TValue>) => void;
78
+ });
79
+ declare const ControlToggleButtonGroup: <TValue>({ justify, size, value, onChange, items, exclusive, fullWidth, }: Props$1<TValue>) => React.JSX.Element;
63
80
 
64
81
  type ToggleControlProps<T extends PropValue> = {
65
82
  options: ToggleButtonGroupItem<T>[];
@@ -68,8 +85,12 @@ type ToggleControlProps<T extends PropValue> = {
68
85
  };
69
86
  declare const ToggleControl: ControlComponent<(<T extends PropValue>({ options, fullWidth, size }: ToggleControlProps<T>) => React.JSX.Element)>;
70
87
 
71
- declare const NumberControl: ControlComponent<({ placeholder }: {
88
+ declare const NumberControl: ControlComponent<({ placeholder, max, min, step, shouldForceInt, }: {
72
89
  placeholder?: string;
90
+ max?: number;
91
+ min?: number;
92
+ step?: number;
93
+ shouldForceInt?: boolean;
73
94
  }) => React.JSX.Element>;
74
95
 
75
96
  type MultiSizePropValue<TMultiPropType extends string> = TransformablePropValue<TMultiPropType, Record<string, SizePropValue>>;
@@ -145,4 +166,4 @@ type UseInternalStateOptions<TValue> = {
145
166
  };
146
167
  declare const useSyncExternalState: <TValue>({ external, setExternal, persistWhen, fallback, }: UseInternalStateOptions<TValue>) => readonly [TValue, (setter: ((value: TValue) => TValue) | TValue) => void];
147
168
 
148
- export { BackgroundOverlayRepeaterControl, BoundPropProvider, BoxShadowRepeaterControl, ColorControl, ControlActionsProvider, type ControlComponent, ControlLabel, ControlReplacementProvider, type EqualUnequalItems, EqualUnequalSizesControl, FontFamilyControl, ImageControl, LinkedDimensionsControl, NumberControl, SelectControl, SizeControl, StrokeControl, TextAreaControl, TextControl, type ToggleButtonGroupItem, ToggleControl, createControlReplacement, useBoundProp, useControlActions, useSyncExternalState };
169
+ export { BackgroundOverlayRepeaterControl, BoundPropProvider, BoxShadowRepeaterControl, ColorControl, ControlActionsProvider, type ControlComponent, ControlLabel, ControlReplacementProvider, ControlToggleButtonGroup, type EqualUnequalItems, EqualUnequalSizesControl, FontFamilyControl, ImageControl, LinkedDimensionsControl, NumberControl, SelectControl, SizeControl, StrokeControl, TextAreaControl, TextControl, type ToggleButtonGroupItem, ToggleControl, createControlReplacement, useBoundProp, useControlActions, useSyncExternalState };
package/dist/index.js CHANGED
@@ -37,6 +37,7 @@ __export(src_exports, {
37
37
  ControlActionsProvider: () => ControlActionsProvider,
38
38
  ControlLabel: () => ControlLabel,
39
39
  ControlReplacementProvider: () => ControlReplacementProvider,
40
+ ControlToggleButtonGroup: () => ControlToggleButtonGroup,
40
41
  EqualUnequalSizesControl: () => EqualUnequalSizesControl,
41
42
  FontFamilyControl: () => FontFamilyControl,
42
43
  ImageControl: () => ImageControl,
@@ -454,28 +455,12 @@ var ColorControl = createControl(
454
455
  );
455
456
 
456
457
  // src/controls/stroke-control.tsx
457
- var defaultStrokeControlValue = {
458
- $$type: "stroke",
459
- value: {
460
- color: {
461
- $$type: "color",
462
- value: "#000000"
463
- },
464
- width: {
465
- $$type: "size",
466
- value: {
467
- unit: "px",
468
- size: NaN
469
- }
470
- }
471
- }
472
- };
473
458
  var units = ["px", "em", "rem"];
474
459
  var StrokeControl = createControl(() => {
475
- const { value, setValue } = useBoundProp(defaultStrokeControlValue);
460
+ const { value, setValue } = useBoundProp();
476
461
  const setStrokeWidth = (newValue) => {
477
462
  const updatedValue = {
478
- ...value?.value ?? defaultStrokeControlValue.value,
463
+ ...value?.value,
479
464
  width: newValue
480
465
  };
481
466
  setValue({
@@ -485,7 +470,7 @@ var StrokeControl = createControl(() => {
485
470
  };
486
471
  const setStrokeColor = (newValue) => {
487
472
  const updatedValue = {
488
- ...value?.value ?? defaultStrokeControlValue.value,
473
+ ...value?.value,
489
474
  color: newValue
490
475
  };
491
476
  setValue({
@@ -498,7 +483,7 @@ var StrokeControl = createControl(() => {
498
483
  {
499
484
  bind: "width",
500
485
  label: (0, import_i18n3.__)("Stroke Width", "elementor"),
501
- value: value?.value.width ?? defaultStrokeControlValue.value.width,
486
+ value: value?.value.width,
502
487
  setValue: setStrokeWidth
503
488
  },
504
489
  /* @__PURE__ */ React15.createElement(SizeControl, { units })
@@ -507,19 +492,13 @@ var StrokeControl = createControl(() => {
507
492
  {
508
493
  bind: "color",
509
494
  label: (0, import_i18n3.__)("Stroke Color", "elementor"),
510
- value: value?.value.color ?? defaultStrokeControlValue.value.color,
495
+ value: value?.value.color,
511
496
  setValue: setStrokeColor
512
497
  },
513
498
  /* @__PURE__ */ React15.createElement(ColorControl, null)
514
499
  ));
515
500
  });
516
- var Control = ({
517
- bind,
518
- value,
519
- setValue,
520
- label,
521
- children
522
- }) => /* @__PURE__ */ React15.createElement(BoundPropProvider, { bind, value, setValue }, /* @__PURE__ */ React15.createElement(import_ui12.Grid, { container: true, gap: 2, alignItems: "center", flexWrap: "nowrap" }, /* @__PURE__ */ React15.createElement(import_ui12.Grid, { item: true, xs: 6 }, /* @__PURE__ */ React15.createElement(ControlLabel, null, label)), /* @__PURE__ */ React15.createElement(import_ui12.Grid, { item: true, xs: 6 }, children)));
501
+ var Control = ({ bind, value, setValue, label, children }) => /* @__PURE__ */ React15.createElement(BoundPropProvider, { bind, value, setValue }, /* @__PURE__ */ React15.createElement(import_ui12.Grid, { container: true, gap: 2, alignItems: "center", flexWrap: "nowrap" }, /* @__PURE__ */ React15.createElement(import_ui12.Grid, { item: true, xs: 6 }, /* @__PURE__ */ React15.createElement(ControlLabel, null, label)), /* @__PURE__ */ React15.createElement(import_ui12.Grid, { item: true, xs: 6 }, children)));
523
502
 
524
503
  // src/controls/box-shadow-repeater-control.tsx
525
504
  var React17 = __toESM(require("react"));
@@ -909,22 +888,35 @@ var ControlToggleButtonGroup = ({
909
888
  exclusive = false,
910
889
  fullWidth = false
911
890
  }) => {
891
+ const isRtl = "rtl" === (0, import_ui16.useTheme)().direction;
912
892
  const handleChange = (_, newValue) => {
913
893
  onChange(newValue);
914
894
  };
915
- return /* @__PURE__ */ React19.createElement(StyledToggleButtonGroup, { justify, value, onChange: handleChange, exclusive }, items.map(
916
- ({ label, value: buttonValue, renderContent: Content, showTooltip }) => showTooltip ? /* @__PURE__ */ React19.createElement(import_ui16.Tooltip, { key: buttonValue, title: label, disableFocusListener: true, placement: "top" }, /* @__PURE__ */ React19.createElement(import_ui16.ToggleButton, { value: buttonValue, "aria-label": label, size, fullWidth }, /* @__PURE__ */ React19.createElement(Content, { size }))) : /* @__PURE__ */ React19.createElement(
917
- import_ui16.ToggleButton,
918
- {
919
- key: buttonValue,
920
- value: buttonValue,
921
- "aria-label": label,
922
- size,
923
- fullWidth
924
- },
925
- /* @__PURE__ */ React19.createElement(Content, { size })
895
+ return /* @__PURE__ */ React19.createElement(
896
+ StyledToggleButtonGroup,
897
+ {
898
+ justify,
899
+ value,
900
+ onChange: handleChange,
901
+ exclusive,
902
+ sx: {
903
+ direction: isRtl ? "rtl /* @noflip */" : "ltr /* @noflip */"
904
+ }
905
+ },
906
+ items.map(
907
+ ({ label, value: buttonValue, renderContent: Content, showTooltip }) => showTooltip ? /* @__PURE__ */ React19.createElement(import_ui16.Tooltip, { key: buttonValue, title: label, disableFocusListener: true, placement: "top" }, /* @__PURE__ */ React19.createElement(import_ui16.ToggleButton, { value: buttonValue, "aria-label": label, size, fullWidth }, /* @__PURE__ */ React19.createElement(Content, { size }))) : /* @__PURE__ */ React19.createElement(
908
+ import_ui16.ToggleButton,
909
+ {
910
+ key: buttonValue,
911
+ value: buttonValue,
912
+ "aria-label": label,
913
+ size,
914
+ fullWidth
915
+ },
916
+ /* @__PURE__ */ React19.createElement(Content, { size })
917
+ )
926
918
  )
927
- ));
919
+ );
928
920
  };
929
921
 
930
922
  // src/controls/toggle-control.tsx
@@ -952,24 +944,38 @@ var ToggleControl = createControl(
952
944
  var React21 = __toESM(require("react"));
953
945
  var import_ui17 = require("@elementor/ui");
954
946
  var isEmptyOrNaN = (value) => value === void 0 || value === "" || Number.isNaN(Number(value));
955
- var NumberControl = createControl(({ placeholder }) => {
956
- const { value, setValue } = useBoundProp();
957
- const handleChange = (event) => {
958
- const eventValue = event.target.value;
959
- setValue(isEmptyOrNaN(eventValue) ? void 0 : Number(eventValue));
960
- };
961
- return /* @__PURE__ */ React21.createElement(ControlActions, null, /* @__PURE__ */ React21.createElement(
962
- import_ui17.TextField,
963
- {
964
- size: "tiny",
965
- type: "number",
966
- fullWidth: true,
967
- value: isEmptyOrNaN(value) ? "" : value,
968
- onChange: handleChange,
969
- placeholder
970
- }
971
- ));
972
- });
947
+ var NumberControl = createControl(
948
+ ({
949
+ placeholder,
950
+ max = Number.MAX_VALUE,
951
+ min = -Number.MAX_VALUE,
952
+ step = 1,
953
+ shouldForceInt = false
954
+ }) => {
955
+ const { value, setValue } = useBoundProp();
956
+ const handleChange = (event) => {
957
+ const eventValue = event.target.value;
958
+ if (isEmptyOrNaN(eventValue)) {
959
+ setValue(void 0);
960
+ return;
961
+ }
962
+ const formattedValue = shouldForceInt ? +parseFloat(eventValue) : Number(eventValue);
963
+ setValue(Math.min(Math.max(formattedValue, min), max));
964
+ };
965
+ return /* @__PURE__ */ React21.createElement(ControlActions, null, /* @__PURE__ */ React21.createElement(
966
+ import_ui17.TextField,
967
+ {
968
+ size: "tiny",
969
+ type: "number",
970
+ fullWidth: true,
971
+ value: isEmptyOrNaN(value) ? "" : value,
972
+ onChange: handleChange,
973
+ placeholder,
974
+ inputProps: { step }
975
+ }
976
+ ));
977
+ }
978
+ );
973
979
 
974
980
  // src/controls/equal-unequal-sizes-control.tsx
975
981
  var React22 = __toESM(require("react"));
@@ -1327,6 +1333,7 @@ var FontFamilyControl = createControl(({ fontFamilies }) => {
1327
1333
  ControlActionsProvider,
1328
1334
  ControlLabel,
1329
1335
  ControlReplacementProvider,
1336
+ ControlToggleButtonGroup,
1330
1337
  EqualUnequalSizesControl,
1331
1338
  FontFamilyControl,
1332
1339
  ImageControl,