@elementor/editor-controls 0.26.0 → 0.27.0

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,17 @@
1
1
  # @elementor/editor-controls
2
2
 
3
+ ## 0.27.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 093b7ca: Add support for multiple control replacements
8
+ - 10cbbe9: update `@elementor/ui` version
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [10cbbe9]
13
+ - @elementor/editor-ui@0.8.0
14
+
3
15
  ## 0.26.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -16,10 +16,10 @@ declare const TextControl: ControlComponent<({ placeholder }: {
16
16
  placeholder?: string;
17
17
  }) => React.JSX.Element>;
18
18
 
19
- type Props$5 = {
19
+ type Props$6 = {
20
20
  placeholder?: string;
21
21
  };
22
- declare const TextAreaControl: ControlComponent<({ placeholder }: Props$5) => React.JSX.Element>;
22
+ declare const TextAreaControl: ControlComponent<({ placeholder }: Props$6) => React.JSX.Element>;
23
23
 
24
24
  type ExtendedValue = 'auto';
25
25
  type Unit = 'px' | '%' | 'em' | 'rem' | 'vw' | 'vh';
@@ -35,7 +35,7 @@ declare const StrokeControl: ControlComponent<() => React.JSX.Element>;
35
35
 
36
36
  declare const BoxShadowRepeaterControl: ControlComponent<() => React.JSX.Element>;
37
37
 
38
- type Props$4 = {
38
+ type Props$5 = {
39
39
  options: Array<{
40
40
  label: string;
41
41
  value: StringPropValue['value'];
@@ -43,12 +43,12 @@ type Props$4 = {
43
43
  }>;
44
44
  onChange?: (newValue: string | null, previousValue: string | null | undefined) => void;
45
45
  };
46
- declare const SelectControl: ControlComponent<({ options, onChange }: Props$4) => React.JSX.Element>;
46
+ declare const SelectControl: ControlComponent<({ options, onChange }: Props$5) => React.JSX.Element>;
47
47
 
48
- type Props$3 = Partial<Omit<UnstableColorFieldProps, 'value' | 'onChange'>> & {
48
+ type Props$4 = Partial<Omit<UnstableColorFieldProps, 'value' | 'onChange'>> & {
49
49
  propTypeUtil?: PropTypeUtil<string, string>;
50
50
  };
51
- declare const ColorControl: ControlComponent<({ propTypeUtil, ...props }: Props$3) => React.JSX.Element>;
51
+ declare const ColorControl: ControlComponent<({ propTypeUtil, ...props }: Props$4) => React.JSX.Element>;
52
52
 
53
53
  type RenderContentProps = {
54
54
  size: ToggleButtonProps['size'];
@@ -61,7 +61,7 @@ type ToggleButtonGroupItem<TValue> = {
61
61
  };
62
62
  type ExclusiveValue<TValue> = TValue;
63
63
  type NonExclusiveValue<TValue> = TValue[];
64
- type Props$2<TValue> = {
64
+ type Props$3<TValue> = {
65
65
  justify?: StackProps['justifyContent'];
66
66
  size?: ToggleButtonProps['size'];
67
67
  items: ToggleButtonGroupItem<TValue | null>[];
@@ -75,7 +75,7 @@ type Props$2<TValue> = {
75
75
  value: ExclusiveValue<TValue>;
76
76
  onChange: (value: ExclusiveValue<TValue>) => void;
77
77
  });
78
- declare const ControlToggleButtonGroup: <TValue>({ justify, size, value, onChange, items, exclusive, fullWidth, }: Props$2<TValue>) => React.JSX.Element;
78
+ declare const ControlToggleButtonGroup: <TValue>({ justify, size, value, onChange, items, exclusive, fullWidth, }: Props$3<TValue>) => React.JSX.Element;
79
79
 
80
80
  type ToggleControlProps<T extends PropValue> = {
81
81
  options: Array<ToggleButtonGroupItem<T> & {
@@ -102,14 +102,14 @@ type Item = {
102
102
  bind: PropKey;
103
103
  };
104
104
  type EqualUnequalItems = [Item, Item, Item, Item];
105
- type Props$1<TMultiPropType extends string, TPropValue extends MultiSizePropValue> = {
105
+ type Props$2<TMultiPropType extends string, TPropValue extends MultiSizePropValue> = {
106
106
  label: string;
107
107
  icon: ReactNode;
108
108
  tooltipLabel: string;
109
109
  items: EqualUnequalItems;
110
110
  multiSizePropTypeUtil: PropTypeUtil<TMultiPropType, TPropValue>;
111
111
  };
112
- declare function EqualUnequalSizesControl<TMultiPropType extends string, TPropValue extends MultiSizePropValue>({ label, icon, tooltipLabel, items, multiSizePropTypeUtil, }: Props$1<TMultiPropType, TPropValue>): React.JSX.Element;
112
+ declare function EqualUnequalSizesControl<TMultiPropType extends string, TPropValue extends MultiSizePropValue>({ label, icon, tooltipLabel, items, multiSizePropTypeUtil, }: Props$2<TMultiPropType, TPropValue>): React.JSX.Element;
113
113
 
114
114
  declare const LinkedDimensionsControl: ControlComponent<({ label, isSiteRtl, extendedValues, }: {
115
115
  label: string;
@@ -136,7 +136,7 @@ type ControlProps<TControlProps = unknown> = TControlProps & {
136
136
  };
137
137
  };
138
138
 
139
- type Props = ControlProps<{
139
+ type Props$1 = ControlProps<{
140
140
  queryOptions: {
141
141
  requestParams: Record<string, unknown>;
142
142
  endpoint: string;
@@ -145,7 +145,7 @@ type Props = ControlProps<{
145
145
  minInputLength?: number;
146
146
  placeholder?: string;
147
147
  }>;
148
- declare const LinkControl: ControlComponent<(props: Props) => React.JSX.Element>;
148
+ declare const LinkControl: ControlComponent<(props: Props$1) => React.JSX.Element>;
149
149
 
150
150
  declare const GapControl: ControlComponent<({ label }: {
151
151
  label: string;
@@ -215,17 +215,20 @@ type UseBoundProp<TValue extends PropValue> = {
215
215
  declare function useBoundProp<T extends PropValue = PropValue>(): PropKeyContextValue<T, PropType>;
216
216
  declare function useBoundProp<TKey extends string, TValue extends PropValue>(propTypeUtil: PropTypeUtil<TKey, TValue>): UseBoundProp<TValue>;
217
217
 
218
- type ReplaceWhenParams = {
219
- value: PropValue;
220
- };
221
- type CreateControlReplacement = {
218
+ type ControlReplacement = {
222
219
  component: ComponentType;
223
- condition: ({ value }: ReplaceWhenParams) => boolean;
220
+ condition: ({ value }: ConditionArgs) => boolean;
224
221
  };
225
- declare const ControlReplacementProvider: ({ component, condition, children, }: React.PropsWithChildren<CreateControlReplacement>) => React.JSX.Element;
226
- declare const createControlReplacement: () => {
227
- replaceControl: ({ component, condition }: CreateControlReplacement) => void;
228
- getControlReplacement: () => CreateControlReplacement;
222
+ type ConditionArgs = {
223
+ value: PropValue;
224
+ };
225
+ type Props = PropsWithChildren<{
226
+ replacements: ControlReplacement[];
227
+ }>;
228
+ declare const ControlReplacementsProvider: ({ replacements, children }: Props) => React.JSX.Element;
229
+ declare const createControlReplacementsRegistry: () => {
230
+ registerControlReplacement: (replacement: ControlReplacement) => void;
231
+ getControlReplacements: () => ControlReplacement[];
229
232
  };
230
233
 
231
234
  type ControlAdornmentsItems = Array<{
@@ -248,4 +251,4 @@ type UseInternalStateOptions<TValue> = {
248
251
  };
249
252
  declare const useSyncExternalState: <TValue>({ external, setExternal, persistWhen, fallback, }: UseInternalStateOptions<TValue>) => readonly [TValue, (setter: ((value: TValue) => TValue) | TValue) => void];
250
253
 
251
- export { BackgroundControl, BoxShadowRepeaterControl, ColorControl, type ControlActionsItems, ControlActionsProvider, ControlAdornments, ControlAdornmentsProvider, type ControlComponent, ControlFormLabel, ControlReplacementProvider, ControlToggleButtonGroup, type EqualUnequalItems, EqualUnequalSizesControl, type ExtendedValue, type FontCategory, FontFamilyControl, GapControl, ImageControl, LinkControl, LinkedDimensionsControl, NumberControl, PropKeyProvider, PropProvider, type PropProviderProps, SelectControl, type SetValue, SizeControl, StrokeControl, SvgMediaControl, TextAreaControl, TextControl, type ToggleButtonGroupItem, ToggleControl, type ToggleControlProps, UrlControl, createControlReplacement, useBoundProp, useControlActions, useSyncExternalState };
254
+ export { BackgroundControl, BoxShadowRepeaterControl, ColorControl, type ControlActionsItems, ControlActionsProvider, ControlAdornments, ControlAdornmentsProvider, type ControlComponent, ControlFormLabel, ControlReplacementsProvider, ControlToggleButtonGroup, type EqualUnequalItems, EqualUnequalSizesControl, type ExtendedValue, type FontCategory, FontFamilyControl, GapControl, ImageControl, LinkControl, LinkedDimensionsControl, NumberControl, PropKeyProvider, PropProvider, type PropProviderProps, SelectControl, type SetValue, SizeControl, StrokeControl, SvgMediaControl, TextAreaControl, TextControl, type ToggleButtonGroupItem, ToggleControl, type ToggleControlProps, UrlControl, createControlReplacementsRegistry, useBoundProp, useControlActions, useSyncExternalState };
package/dist/index.d.ts CHANGED
@@ -16,10 +16,10 @@ declare const TextControl: ControlComponent<({ placeholder }: {
16
16
  placeholder?: string;
17
17
  }) => React.JSX.Element>;
18
18
 
19
- type Props$5 = {
19
+ type Props$6 = {
20
20
  placeholder?: string;
21
21
  };
22
- declare const TextAreaControl: ControlComponent<({ placeholder }: Props$5) => React.JSX.Element>;
22
+ declare const TextAreaControl: ControlComponent<({ placeholder }: Props$6) => React.JSX.Element>;
23
23
 
24
24
  type ExtendedValue = 'auto';
25
25
  type Unit = 'px' | '%' | 'em' | 'rem' | 'vw' | 'vh';
@@ -35,7 +35,7 @@ declare const StrokeControl: ControlComponent<() => React.JSX.Element>;
35
35
 
36
36
  declare const BoxShadowRepeaterControl: ControlComponent<() => React.JSX.Element>;
37
37
 
38
- type Props$4 = {
38
+ type Props$5 = {
39
39
  options: Array<{
40
40
  label: string;
41
41
  value: StringPropValue['value'];
@@ -43,12 +43,12 @@ type Props$4 = {
43
43
  }>;
44
44
  onChange?: (newValue: string | null, previousValue: string | null | undefined) => void;
45
45
  };
46
- declare const SelectControl: ControlComponent<({ options, onChange }: Props$4) => React.JSX.Element>;
46
+ declare const SelectControl: ControlComponent<({ options, onChange }: Props$5) => React.JSX.Element>;
47
47
 
48
- type Props$3 = Partial<Omit<UnstableColorFieldProps, 'value' | 'onChange'>> & {
48
+ type Props$4 = Partial<Omit<UnstableColorFieldProps, 'value' | 'onChange'>> & {
49
49
  propTypeUtil?: PropTypeUtil<string, string>;
50
50
  };
51
- declare const ColorControl: ControlComponent<({ propTypeUtil, ...props }: Props$3) => React.JSX.Element>;
51
+ declare const ColorControl: ControlComponent<({ propTypeUtil, ...props }: Props$4) => React.JSX.Element>;
52
52
 
53
53
  type RenderContentProps = {
54
54
  size: ToggleButtonProps['size'];
@@ -61,7 +61,7 @@ type ToggleButtonGroupItem<TValue> = {
61
61
  };
62
62
  type ExclusiveValue<TValue> = TValue;
63
63
  type NonExclusiveValue<TValue> = TValue[];
64
- type Props$2<TValue> = {
64
+ type Props$3<TValue> = {
65
65
  justify?: StackProps['justifyContent'];
66
66
  size?: ToggleButtonProps['size'];
67
67
  items: ToggleButtonGroupItem<TValue | null>[];
@@ -75,7 +75,7 @@ type Props$2<TValue> = {
75
75
  value: ExclusiveValue<TValue>;
76
76
  onChange: (value: ExclusiveValue<TValue>) => void;
77
77
  });
78
- declare const ControlToggleButtonGroup: <TValue>({ justify, size, value, onChange, items, exclusive, fullWidth, }: Props$2<TValue>) => React.JSX.Element;
78
+ declare const ControlToggleButtonGroup: <TValue>({ justify, size, value, onChange, items, exclusive, fullWidth, }: Props$3<TValue>) => React.JSX.Element;
79
79
 
80
80
  type ToggleControlProps<T extends PropValue> = {
81
81
  options: Array<ToggleButtonGroupItem<T> & {
@@ -102,14 +102,14 @@ type Item = {
102
102
  bind: PropKey;
103
103
  };
104
104
  type EqualUnequalItems = [Item, Item, Item, Item];
105
- type Props$1<TMultiPropType extends string, TPropValue extends MultiSizePropValue> = {
105
+ type Props$2<TMultiPropType extends string, TPropValue extends MultiSizePropValue> = {
106
106
  label: string;
107
107
  icon: ReactNode;
108
108
  tooltipLabel: string;
109
109
  items: EqualUnequalItems;
110
110
  multiSizePropTypeUtil: PropTypeUtil<TMultiPropType, TPropValue>;
111
111
  };
112
- declare function EqualUnequalSizesControl<TMultiPropType extends string, TPropValue extends MultiSizePropValue>({ label, icon, tooltipLabel, items, multiSizePropTypeUtil, }: Props$1<TMultiPropType, TPropValue>): React.JSX.Element;
112
+ declare function EqualUnequalSizesControl<TMultiPropType extends string, TPropValue extends MultiSizePropValue>({ label, icon, tooltipLabel, items, multiSizePropTypeUtil, }: Props$2<TMultiPropType, TPropValue>): React.JSX.Element;
113
113
 
114
114
  declare const LinkedDimensionsControl: ControlComponent<({ label, isSiteRtl, extendedValues, }: {
115
115
  label: string;
@@ -136,7 +136,7 @@ type ControlProps<TControlProps = unknown> = TControlProps & {
136
136
  };
137
137
  };
138
138
 
139
- type Props = ControlProps<{
139
+ type Props$1 = ControlProps<{
140
140
  queryOptions: {
141
141
  requestParams: Record<string, unknown>;
142
142
  endpoint: string;
@@ -145,7 +145,7 @@ type Props = ControlProps<{
145
145
  minInputLength?: number;
146
146
  placeholder?: string;
147
147
  }>;
148
- declare const LinkControl: ControlComponent<(props: Props) => React.JSX.Element>;
148
+ declare const LinkControl: ControlComponent<(props: Props$1) => React.JSX.Element>;
149
149
 
150
150
  declare const GapControl: ControlComponent<({ label }: {
151
151
  label: string;
@@ -215,17 +215,20 @@ type UseBoundProp<TValue extends PropValue> = {
215
215
  declare function useBoundProp<T extends PropValue = PropValue>(): PropKeyContextValue<T, PropType>;
216
216
  declare function useBoundProp<TKey extends string, TValue extends PropValue>(propTypeUtil: PropTypeUtil<TKey, TValue>): UseBoundProp<TValue>;
217
217
 
218
- type ReplaceWhenParams = {
219
- value: PropValue;
220
- };
221
- type CreateControlReplacement = {
218
+ type ControlReplacement = {
222
219
  component: ComponentType;
223
- condition: ({ value }: ReplaceWhenParams) => boolean;
220
+ condition: ({ value }: ConditionArgs) => boolean;
224
221
  };
225
- declare const ControlReplacementProvider: ({ component, condition, children, }: React.PropsWithChildren<CreateControlReplacement>) => React.JSX.Element;
226
- declare const createControlReplacement: () => {
227
- replaceControl: ({ component, condition }: CreateControlReplacement) => void;
228
- getControlReplacement: () => CreateControlReplacement;
222
+ type ConditionArgs = {
223
+ value: PropValue;
224
+ };
225
+ type Props = PropsWithChildren<{
226
+ replacements: ControlReplacement[];
227
+ }>;
228
+ declare const ControlReplacementsProvider: ({ replacements, children }: Props) => React.JSX.Element;
229
+ declare const createControlReplacementsRegistry: () => {
230
+ registerControlReplacement: (replacement: ControlReplacement) => void;
231
+ getControlReplacements: () => ControlReplacement[];
229
232
  };
230
233
 
231
234
  type ControlAdornmentsItems = Array<{
@@ -248,4 +251,4 @@ type UseInternalStateOptions<TValue> = {
248
251
  };
249
252
  declare const useSyncExternalState: <TValue>({ external, setExternal, persistWhen, fallback, }: UseInternalStateOptions<TValue>) => readonly [TValue, (setter: ((value: TValue) => TValue) | TValue) => void];
250
253
 
251
- export { BackgroundControl, BoxShadowRepeaterControl, ColorControl, type ControlActionsItems, ControlActionsProvider, ControlAdornments, ControlAdornmentsProvider, type ControlComponent, ControlFormLabel, ControlReplacementProvider, ControlToggleButtonGroup, type EqualUnequalItems, EqualUnequalSizesControl, type ExtendedValue, type FontCategory, FontFamilyControl, GapControl, ImageControl, LinkControl, LinkedDimensionsControl, NumberControl, PropKeyProvider, PropProvider, type PropProviderProps, SelectControl, type SetValue, SizeControl, StrokeControl, SvgMediaControl, TextAreaControl, TextControl, type ToggleButtonGroupItem, ToggleControl, type ToggleControlProps, UrlControl, createControlReplacement, useBoundProp, useControlActions, useSyncExternalState };
254
+ export { BackgroundControl, BoxShadowRepeaterControl, ColorControl, type ControlActionsItems, ControlActionsProvider, ControlAdornments, ControlAdornmentsProvider, type ControlComponent, ControlFormLabel, ControlReplacementsProvider, ControlToggleButtonGroup, type EqualUnequalItems, EqualUnequalSizesControl, type ExtendedValue, type FontCategory, FontFamilyControl, GapControl, ImageControl, LinkControl, LinkedDimensionsControl, NumberControl, PropKeyProvider, PropProvider, type PropProviderProps, SelectControl, type SetValue, SizeControl, StrokeControl, SvgMediaControl, TextAreaControl, TextControl, type ToggleButtonGroupItem, ToggleControl, type ToggleControlProps, UrlControl, createControlReplacementsRegistry, useBoundProp, useControlActions, useSyncExternalState };
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ __export(index_exports, {
37
37
  ControlAdornments: () => ControlAdornments,
38
38
  ControlAdornmentsProvider: () => ControlAdornmentsProvider,
39
39
  ControlFormLabel: () => ControlFormLabel,
40
- ControlReplacementProvider: () => ControlReplacementProvider,
40
+ ControlReplacementsProvider: () => ControlReplacementsProvider,
41
41
  ControlToggleButtonGroup: () => ControlToggleButtonGroup,
42
42
  EqualUnequalSizesControl: () => EqualUnequalSizesControl,
43
43
  FontFamilyControl: () => FontFamilyControl,
@@ -56,7 +56,7 @@ __export(index_exports, {
56
56
  TextControl: () => TextControl,
57
57
  ToggleControl: () => ToggleControl,
58
58
  UrlControl: () => UrlControl,
59
- createControlReplacement: () => createControlReplacement,
59
+ createControlReplacementsRegistry: () => createControlReplacementsRegistry,
60
60
  useBoundProp: () => useBoundProp,
61
61
  useControlActions: () => useControlActions,
62
62
  useSyncExternalState: () => useSyncExternalState
@@ -258,46 +258,39 @@ var ControlFormLabel = ({ children }) => {
258
258
  var React5 = __toESM(require("react"));
259
259
  var import_ui2 = require("@elementor/ui");
260
260
 
261
- // src/create-control-replacement.tsx
261
+ // src/control-replacements.tsx
262
262
  var React4 = __toESM(require("react"));
263
263
  var import_react4 = require("react");
264
- var ControlReplacementContext = (0, import_react4.createContext)(void 0);
265
- var ControlReplacementProvider = ({
266
- component,
267
- condition,
268
- children
269
- }) => {
270
- return /* @__PURE__ */ React4.createElement(ControlReplacementContext.Provider, { value: { component, condition } }, children);
264
+ var ControlReplacementContext = (0, import_react4.createContext)([]);
265
+ var ControlReplacementsProvider = ({ replacements, children }) => {
266
+ return /* @__PURE__ */ React4.createElement(ControlReplacementContext.Provider, { value: replacements }, children);
271
267
  };
272
- var useControlReplacement = () => {
268
+ var useControlReplacement = (OriginalComponent) => {
273
269
  const { value } = useBoundProp();
274
- const controlReplacement = (0, import_react4.useContext)(ControlReplacementContext);
275
- let shouldReplace = false;
270
+ const replacements = (0, import_react4.useContext)(ControlReplacementContext);
276
271
  try {
277
- shouldReplace = !!controlReplacement?.condition({ value }) && !!controlReplacement.component;
272
+ const replacement = replacements.find((r) => r.condition({ value }));
273
+ return replacement?.component ?? OriginalComponent;
278
274
  } catch {
275
+ return OriginalComponent;
279
276
  }
280
- return shouldReplace ? controlReplacement?.component : void 0;
281
277
  };
282
- var createControlReplacement = () => {
283
- let controlReplacement;
284
- function replaceControl({ component, condition }) {
285
- controlReplacement = { component, condition };
278
+ var createControlReplacementsRegistry = () => {
279
+ const controlReplacements = [];
280
+ function registerControlReplacement(replacement) {
281
+ controlReplacements.push(replacement);
286
282
  }
287
- function getControlReplacement() {
288
- return controlReplacement;
283
+ function getControlReplacements() {
284
+ return controlReplacements;
289
285
  }
290
- return { replaceControl, getControlReplacement };
286
+ return { registerControlReplacement, getControlReplacements };
291
287
  };
292
288
 
293
289
  // src/create-control.tsx
294
290
  var brandSymbol = Symbol("control");
295
- function createControl(Component, { supportsReplacements = true } = {}) {
291
+ function createControl(Control5) {
296
292
  return (props) => {
297
- const ControlReplacement = useControlReplacement();
298
- if (ControlReplacement && supportsReplacements) {
299
- return /* @__PURE__ */ React5.createElement(import_ui2.ErrorBoundary, { fallback: null }, /* @__PURE__ */ React5.createElement(ControlReplacement, { ...props }));
300
- }
293
+ const Component = useControlReplacement(Control5);
301
294
  return /* @__PURE__ */ React5.createElement(import_ui2.ErrorBoundary, { fallback: null }, /* @__PURE__ */ React5.createElement(Component, { ...props }));
302
295
  };
303
296
  }
@@ -1369,7 +1362,6 @@ function EqualUnequalSizesControl({
1369
1362
  },
1370
1363
  ...(0, import_ui22.bindPopover)(popupState),
1371
1364
  slotProps: {
1372
- // eslint-disable-next-line react-compiler/react-compiler
1373
1365
  paper: { sx: { mt: 0.5, width: controlRef.current?.getBoundingClientRect().width } }
1374
1366
  }
1375
1367
  },
@@ -2765,7 +2757,7 @@ var BackgroundControl = createControl(() => {
2765
2757
  ControlAdornments,
2766
2758
  ControlAdornmentsProvider,
2767
2759
  ControlFormLabel,
2768
- ControlReplacementProvider,
2760
+ ControlReplacementsProvider,
2769
2761
  ControlToggleButtonGroup,
2770
2762
  EqualUnequalSizesControl,
2771
2763
  FontFamilyControl,
@@ -2784,7 +2776,7 @@ var BackgroundControl = createControl(() => {
2784
2776
  TextControl,
2785
2777
  ToggleControl,
2786
2778
  UrlControl,
2787
- createControlReplacement,
2779
+ createControlReplacementsRegistry,
2788
2780
  useBoundProp,
2789
2781
  useControlActions,
2790
2782
  useSyncExternalState