@elementor/editor-controls 4.0.0-682 → 4.0.0-beta5

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.
Files changed (28) hide show
  1. package/dist/index.d.mts +138 -74
  2. package/dist/index.d.ts +138 -74
  3. package/dist/index.js +822 -203
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +799 -185
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +15 -15
  8. package/src/components/inline-editor.tsx +16 -57
  9. package/src/controls/email-form-action-control.tsx +5 -5
  10. package/src/controls/size-control/hooks/use-size-unit-keyboard.tsx +12 -1
  11. package/src/controls/size-control/hooks/use-size-value.ts +12 -16
  12. package/src/controls/size-control/size-component.tsx +38 -17
  13. package/src/controls/size-control/size-field.tsx +37 -13
  14. package/src/controls/size-control/sync/get-units.ts +15 -1
  15. package/src/controls/size-control/types.ts +8 -0
  16. package/src/controls/size-control/unstable-size-control.tsx +86 -0
  17. package/src/controls/size-control/utils/has-size-value.ts +5 -0
  18. package/src/controls/size-control/utils/resolve-bound-prop-value.ts +72 -0
  19. package/src/controls/size-control/utils/resolve-size-value.ts +4 -3
  20. package/src/controls/size-control/utils/settings/get-default-unit.ts +7 -0
  21. package/src/controls/size-control/utils/settings/get-prop-type-settings.ts +12 -0
  22. package/src/controls/size-control/utils/settings/get-size-units.ts +23 -0
  23. package/src/controls/size-control/utils/should-nullify-value.ts +15 -0
  24. package/src/controls/svg-media-control.tsx +5 -4
  25. package/src/controls/transition-control/data.ts +3 -3
  26. package/src/controls/transition-control/transition-repeater-control.tsx +8 -2
  27. package/src/index.ts +2 -0
  28. package/src/controls/size-control/utils/is-numeric-value.ts +0 -11
@@ -0,0 +1,72 @@
1
+ import { sizePropTypeUtil, type SizePropValue } from '@elementor/editor-props';
2
+
3
+ import { hasSizeValue } from './has-size-value';
4
+ import { EXTENDED_UNITS } from './resolve-size-value';
5
+
6
+ type SizeValue = SizePropValue[ 'value' ] | null;
7
+
8
+ export type ResolvedBoundProp = {
9
+ sizeValue: SizeValue;
10
+ isUnitHighlighted: boolean;
11
+ placeholder: string | undefined;
12
+ };
13
+
14
+ export const resolveBoundPropValue = < T extends SizeValue >(
15
+ value?: T | null,
16
+ boundPropPlaceholder?: T | null,
17
+ propPlaceholder?: string
18
+ ): ResolvedBoundProp => {
19
+ let sizeValue: T | null = null;
20
+
21
+ if ( validateSizeValue( value ) ) {
22
+ sizeValue = value;
23
+ } else if ( validateSizeValue( boundPropPlaceholder ) ) {
24
+ sizeValue = { size: '', unit: boundPropPlaceholder?.unit } as T;
25
+ }
26
+
27
+ return {
28
+ sizeValue,
29
+ isUnitHighlighted: shouldHighlightUnit( value ),
30
+ placeholder: resolvePlaceholder( propPlaceholder, boundPropPlaceholder ),
31
+ };
32
+ };
33
+
34
+ const validateSizeValue = ( value?: SizeValue | null ): value is SizeValue => {
35
+ if ( ! value ) {
36
+ return false;
37
+ }
38
+
39
+ const sizePropValue = sizePropTypeUtil.create( value );
40
+
41
+ return sizePropTypeUtil.isValid( sizePropValue );
42
+ };
43
+
44
+ const resolvePlaceholder = ( propPlaceholder?: string, boundPropPlaceholder?: SizeValue ): string | undefined => {
45
+ if ( propPlaceholder ) {
46
+ return propPlaceholder;
47
+ }
48
+
49
+ const size = boundPropPlaceholder?.size;
50
+
51
+ if ( size === undefined ) {
52
+ return undefined;
53
+ }
54
+
55
+ if ( typeof size === 'number' ) {
56
+ return size.toString();
57
+ }
58
+
59
+ return size;
60
+ };
61
+
62
+ const shouldHighlightUnit = ( value?: SizePropValue[ 'value' ] | null ) => {
63
+ if ( ! value ) {
64
+ return false;
65
+ }
66
+
67
+ if ( value.unit === EXTENDED_UNITS.auto ) {
68
+ return true;
69
+ }
70
+
71
+ return hasSizeValue( value.size );
72
+ };
@@ -51,10 +51,10 @@ export const resolveSizeOnUnitChange = (
51
51
  };
52
52
 
53
53
  export const createDefaultSizeValue = < T extends SizeValue >( units: SizeUnit[], defaultUnit?: SizeUnit ): T => {
54
- let unit = units[ 0 ];
54
+ let [ unit ] = units;
55
55
 
56
56
  if ( defaultUnit !== undefined ) {
57
- unit = resolveFallbackUnit( defaultUnit, units ) as SizeUnit;
57
+ unit = resolveFallbackUnit( defaultUnit, units );
58
58
  }
59
59
 
60
60
  return { size: DEFAULT_SIZE, unit } as T;
@@ -64,7 +64,7 @@ const resolveFallbackUnit = < TUnit extends SizeUnit >(
64
64
  unit: TUnit,
65
65
  units: readonly TUnit[],
66
66
  defaultUnit?: TUnit
67
- ): TUnit | string => {
67
+ ): TUnit => {
68
68
  if ( units.includes( unit ) ) {
69
69
  return unit;
70
70
  }
@@ -80,5 +80,6 @@ const sanitizeSize = ( size: SizeValue[ 'size' ] ): SizeValue[ 'size' ] => {
80
80
  if ( typeof size === 'number' && isNaN( size ) ) {
81
81
  return DEFAULT_SIZE;
82
82
  }
83
+
83
84
  return size;
84
85
  };
@@ -0,0 +1,7 @@
1
+ import type { PropType } from '@elementor/editor-props';
2
+
3
+ import { getPropTypeSettings } from './get-prop-type-settings';
4
+
5
+ export const getDefaultUnit = ( propType: PropType ) => {
6
+ return getPropTypeSettings( propType )?.default_unit;
7
+ };
@@ -0,0 +1,12 @@
1
+ import { type PropType } from '@elementor/editor-props';
2
+
3
+ import { type SizeUnit } from '../../types';
4
+
5
+ type Settings = {
6
+ units?: SizeUnit[];
7
+ default_unit?: SizeUnit;
8
+ };
9
+
10
+ export const getPropTypeSettings = ( propType: PropType ) => {
11
+ return propType.settings as Settings;
12
+ };
@@ -0,0 +1,23 @@
1
+ import { type PropType } from '@elementor/editor-props';
2
+
3
+ import { getAngleUnits, getLengthUnits, getTimeUnits } from '../../sync/get-units';
4
+ import { type SizeUnit, type SizeVariant } from '../../types';
5
+ import { getPropTypeSettings } from './get-prop-type-settings';
6
+
7
+ const getVariantUnits = ( variant: SizeVariant ): SizeUnit[] => {
8
+ const map: Record< SizeVariant, () => SizeUnit[] > = {
9
+ length: getLengthUnits,
10
+ angle: getAngleUnits,
11
+ time: getTimeUnits,
12
+ };
13
+
14
+ return map[ variant ]();
15
+ };
16
+
17
+ const getSettingsUnits = ( propType: PropType ) => {
18
+ return getPropTypeSettings( propType )?.units;
19
+ };
20
+
21
+ export const getSizeUnits = ( propType: PropType, variant: SizeVariant ): SizeUnit[] => {
22
+ return getSettingsUnits( propType ) ?? getVariantUnits( variant );
23
+ };
@@ -0,0 +1,15 @@
1
+ import { type SizePropValue } from '@elementor/editor-props';
2
+
3
+ import { EXTENDED_UNITS } from './resolve-size-value';
4
+
5
+ type SizeValue = SizePropValue[ 'value' ] | null;
6
+
7
+ const conditions: Array< ( value: SizeValue ) => boolean > = [
8
+ ( value ) => value?.size === null || value?.size === undefined || value?.size === '',
9
+ ( value ) => value?.unit !== EXTENDED_UNITS.auto,
10
+ ( value ) => value?.unit !== EXTENDED_UNITS.custom,
11
+ ];
12
+
13
+ export const shouldNullifyValue = ( value: SizeValue ): boolean => {
14
+ return conditions.every( ( condition ) => condition( value ) );
15
+ };
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useState } from 'react';
3
3
  import { useCurrentUserCapabilities } from '@elementor/editor-current-user';
4
- import { imageSrcPropTypeUtil } from '@elementor/editor-props';
4
+ import { svgSrcPropTypeUtil, urlPropTypeUtil } from '@elementor/editor-props';
5
5
  import { UploadIcon } from '@elementor/icons';
6
6
  import { Button, Card, CardMedia, CardOverlay, CircularProgress, Stack, styled, ThemeProvider } from '@elementor/ui';
7
7
  import { type OpenOptions, useWpMediaAttachment, useWpMediaFrame } from '@elementor/wp-media';
@@ -43,8 +43,9 @@ const MODE_BROWSE: OpenOptions = { mode: 'browse' };
43
43
  const MODE_UPLOAD: OpenOptions = { mode: 'upload' };
44
44
 
45
45
  export const SvgMediaControl = createControl( () => {
46
- const { value, setValue } = useBoundProp( imageSrcPropTypeUtil );
47
- const { id, url } = value ?? {};
46
+ const { value, setValue } = useBoundProp( svgSrcPropTypeUtil );
47
+ const id = value?.id;
48
+ const url = value?.url;
48
49
  const { data: attachment, isFetching } = useWpMediaAttachment( id?.value || null );
49
50
  const src = attachment?.url ?? url?.value ?? null;
50
51
  const { data: allowSvgUpload } = useUnfilteredFilesUpload();
@@ -61,7 +62,7 @@ export const SvgMediaControl = createControl( () => {
61
62
  $$type: 'image-attachment-id',
62
63
  value: selectedAttachment.id,
63
64
  },
64
- url: null,
65
+ url: urlPropTypeUtil.create( selectedAttachment.url ),
65
66
  } );
66
67
  },
67
68
  } );
@@ -46,9 +46,9 @@ const getIsSiteRtl = () => {
46
46
  };
47
47
 
48
48
  // TODO: Remove this after version 4.01 is released
49
- const shouldExtendTransitionProperties = (): boolean => {
49
+ const shouldShowAllTransitionProperties = (): boolean => {
50
50
  if ( ! hasProInstalled() ) {
51
- return false;
51
+ return true;
52
52
  }
53
53
 
54
54
  const proVersion = window.elementorPro?.config?.version;
@@ -191,7 +191,7 @@ const createTransitionPropertiesList = (): TransitionCategory[] => {
191
191
  },
192
192
  ];
193
193
 
194
- return shouldExtendTransitionProperties() ? baseProperties : [ baseProperties[ 0 ] ];
194
+ return shouldShowAllTransitionProperties() ? baseProperties : [ baseProperties[ 0 ] ];
195
195
  };
196
196
 
197
197
  export const transitionProperties: TransitionCategory[] = createTransitionPropertiesList();
@@ -9,6 +9,7 @@ import {
9
9
  import { type StyleDefinitionState } from '@elementor/editor-styles';
10
10
  import { InfoCircleFilledIcon } from '@elementor/icons';
11
11
  import { Alert, AlertTitle, Box, Typography } from '@elementor/ui';
12
+ import { hasProInstalled } from '@elementor/utils';
12
13
  import { __ } from '@wordpress/i18n';
13
14
 
14
15
  import { useBoundProp } from '../../bound-prop-context';
@@ -181,6 +182,7 @@ export const TransitionRepeaterControl = createControl(
181
182
  } ) => {
182
183
  const currentStyleIsNormal = currentStyleState === null;
183
184
  const [ recentlyUsedList, setRecentlyUsedList ] = useState< string[] >( [] );
185
+ const proInstalled = hasProInstalled();
184
186
 
185
187
  const { value, setValue } = useBoundProp( childArrayPropTypeUtil );
186
188
  const { allDisabled: disabledItems, proDisabled: proDisabledItems } = useMemo(
@@ -191,10 +193,14 @@ export const TransitionRepeaterControl = createControl(
191
193
  const allowedTransitionSet = useMemo( () => {
192
194
  const set = new Set< string >();
193
195
  transitionProperties.forEach( ( category ) => {
194
- category.properties.forEach( ( prop ) => set.add( prop.value ) );
196
+ category.properties.forEach( ( prop ) => {
197
+ if ( ! prop.isDisabled || proInstalled ) {
198
+ set.add( prop.value );
199
+ }
200
+ } );
195
201
  } );
196
202
  return set;
197
- }, [] );
203
+ }, [ proInstalled ] );
198
204
 
199
205
  useEffect( () => {
200
206
  if ( ! value || value.length === 0 ) {
package/src/index.ts CHANGED
@@ -38,6 +38,7 @@ export { transitionProperties, transitionsItemsList } from './controls/transitio
38
38
  export { DateTimeControl } from './controls/date-time-control';
39
39
  export { InlineEditingControl } from './controls/inline-editing-control';
40
40
  export { EmailFormActionControl } from './controls/email-form-action-control';
41
+ export { UnstableSizeControl } from './controls/size-control/unstable-size-control';
41
42
 
42
43
  // components
43
44
  export { ControlFormLabel } from './components/control-form-label';
@@ -58,6 +59,7 @@ export { InlineEditor } from './components/inline-editor';
58
59
  export { InlineEditorToolbar } from './components/inline-editor-toolbar';
59
60
  export { UnstableSizeField } from './components/size/unstable-size-field';
60
61
  export { NumberInput } from './components/number-input';
62
+ export { SizeComponent } from './controls/size-control/size-component';
61
63
 
62
64
  // types
63
65
  export type { ControlComponent } from './create-control';
@@ -1,11 +0,0 @@
1
- export const isNumericValue = ( value: unknown ): boolean => {
2
- if ( typeof value === 'number' ) {
3
- return ! isNaN( value );
4
- }
5
-
6
- if ( typeof value === 'string' ) {
7
- return value.trim() !== '' && ! isNaN( Number( value ) );
8
- }
9
-
10
- return false;
11
- };