@elementor/editor-editing-panel 4.2.0-878 → 4.2.0-879

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-editing-panel",
3
- "version": "4.2.0-878",
3
+ "version": "4.2.0-879",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,31 +39,31 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "4.2.0-878",
43
- "@elementor/editor-canvas": "4.2.0-878",
44
- "@elementor/editor-controls": "4.2.0-878",
45
- "@elementor/editor-documents": "4.2.0-878",
46
- "@elementor/editor-elements": "4.2.0-878",
47
- "@elementor/editor-interactions": "4.2.0-878",
48
- "@elementor/editor-notifications": "4.2.0-878",
49
- "@elementor/editor-panels": "4.2.0-878",
50
- "@elementor/editor-props": "4.2.0-878",
51
- "@elementor/editor-responsive": "4.2.0-878",
52
- "@elementor/editor-styles": "4.2.0-878",
53
- "@elementor/editor-styles-repository": "4.2.0-878",
54
- "@elementor/editor-ui": "4.2.0-878",
55
- "@elementor/editor-v1-adapters": "4.2.0-878",
56
- "@elementor/http-client": "4.2.0-878",
42
+ "@elementor/editor": "4.2.0-879",
43
+ "@elementor/editor-canvas": "4.2.0-879",
44
+ "@elementor/editor-controls": "4.2.0-879",
45
+ "@elementor/editor-documents": "4.2.0-879",
46
+ "@elementor/editor-elements": "4.2.0-879",
47
+ "@elementor/editor-interactions": "4.2.0-879",
48
+ "@elementor/editor-notifications": "4.2.0-879",
49
+ "@elementor/editor-panels": "4.2.0-879",
50
+ "@elementor/editor-props": "4.2.0-879",
51
+ "@elementor/editor-responsive": "4.2.0-879",
52
+ "@elementor/editor-styles": "4.2.0-879",
53
+ "@elementor/editor-styles-repository": "4.2.0-879",
54
+ "@elementor/editor-ui": "4.2.0-879",
55
+ "@elementor/editor-v1-adapters": "4.2.0-879",
56
+ "@elementor/http-client": "4.2.0-879",
57
57
  "@elementor/icons": "~1.75.1",
58
- "@elementor/editor-variables": "4.2.0-878",
59
- "@elementor/locations": "4.2.0-878",
60
- "@elementor/menus": "4.2.0-878",
61
- "@elementor/query": "4.2.0-878",
62
- "@elementor/schema": "4.2.0-878",
63
- "@elementor/session": "4.2.0-878",
58
+ "@elementor/editor-variables": "4.2.0-879",
59
+ "@elementor/locations": "4.2.0-879",
60
+ "@elementor/menus": "4.2.0-879",
61
+ "@elementor/query": "4.2.0-879",
62
+ "@elementor/schema": "4.2.0-879",
63
+ "@elementor/session": "4.2.0-879",
64
64
  "@elementor/ui": "1.37.5",
65
- "@elementor/utils": "4.2.0-878",
66
- "@elementor/wp-media": "4.2.0-878",
65
+ "@elementor/utils": "4.2.0-879",
66
+ "@elementor/wp-media": "4.2.0-879",
67
67
  "@wordpress/i18n": "^5.13.0"
68
68
  },
69
69
  "peerDependencies": {
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useRef } from 'react';
3
- import { SizeComponent, useBoundProp } from '@elementor/editor-controls';
4
- import { stringPropTypeUtil, type StringPropValue } from '@elementor/editor-props';
3
+ import { ControlActions, createControl, SizeComponent, useBoundProp } from '@elementor/editor-controls';
4
+ import { type PropValue } from '@elementor/editor-props';
5
5
  import { Grid } from '@elementor/ui';
6
6
  import { __ } from '@wordpress/i18n';
7
7
 
@@ -9,87 +9,18 @@ import { StylesField } from '../../../controls-registry/styles-field';
9
9
  import { useStylesField } from '../../../hooks/use-styles-field';
10
10
  import { UiProviders } from '../../../styles-inheritance/components/ui-providers';
11
11
  import { StylesFieldLayout } from '../../styles-field-layout';
12
-
13
- type GridTrackUnit = 'fr' | 'custom';
14
-
15
- type GridTrackValue = { kind: 'empty' } | { kind: 'fr'; count: number } | { kind: 'custom'; raw: string };
16
-
17
- const FR = 'fr' as const;
18
- const CUSTOM = 'custom' as const;
19
- const UNITS: GridTrackUnit[] = [ FR, CUSTOM ];
20
-
21
- const EMPTY: GridTrackValue = { kind: 'empty' };
22
-
23
- const REPEAT_FR_PATTERN = /^repeat\(\s*(\d+)\s*,\s*1fr\s*\)$/;
24
-
25
- const parseCss = ( css: string | null ): GridTrackValue => {
26
- if ( ! css ) {
27
- return EMPTY;
28
- }
29
- const match = css.match( REPEAT_FR_PATTERN );
30
- if ( match ) {
31
- const count = parseInt( match[ 1 ], 10 );
32
- return count >= 1 ? { kind: 'fr', count } : EMPTY;
33
- }
34
- return { kind: 'custom', raw: css };
35
- };
36
-
37
- const fromSizeInput = ( v: { size: number | string; unit: GridTrackUnit } ): GridTrackValue => {
38
- if ( v.size === '' || Number.isNaN( v.size ) ) {
39
- return EMPTY;
40
- }
41
- if ( v.unit === FR ) {
42
- const n = Number( v.size );
43
- return Number.isFinite( n ) && n >= 1 ? { kind: 'fr', count: Math.trunc( n ) } : EMPTY;
44
- }
45
- return { kind: 'custom', raw: String( v.size ) };
46
- };
47
-
48
- const toCss = ( v: GridTrackValue ): string | null => {
49
- switch ( v.kind ) {
50
- case 'empty':
51
- return null;
52
- case 'fr':
53
- return `repeat(${ v.count }, 1fr)`;
54
- case 'custom':
55
- return v.raw;
56
- }
57
- };
58
-
59
- const toSizeInput = (
60
- v: GridTrackValue,
61
- fallbackUnit: GridTrackUnit = FR
62
- ): { size: number | string; unit: GridTrackUnit } => {
63
- switch ( v.kind ) {
64
- case 'empty':
65
- return { size: '', unit: fallbackUnit };
66
- case 'fr':
67
- return { size: v.count, unit: FR };
68
- case 'custom':
69
- return { size: v.raw, unit: CUSTOM };
70
- }
71
- };
72
-
73
- const toPlaceholder = ( v: GridTrackValue ): string | undefined => {
74
- switch ( v.kind ) {
75
- case 'empty':
76
- return undefined;
77
- case 'fr':
78
- return String( v.count );
79
- case 'custom':
80
- return v.raw;
81
- }
82
- };
83
-
84
- const unitOf = ( v: GridTrackValue, fallback: GridTrackUnit = FR ): GridTrackUnit => {
85
- if ( v.kind === 'fr' ) {
86
- return FR;
87
- }
88
- if ( v.kind === 'custom' ) {
89
- return CUSTOM;
90
- }
91
- return fallback;
92
- };
12
+ import {
13
+ EMPTY,
14
+ FR,
15
+ fromSizeInput,
16
+ type GridTrackUnit,
17
+ parseValue,
18
+ toPlaceholder,
19
+ toPropValue,
20
+ toSizeInput,
21
+ unitOf,
22
+ UNITS,
23
+ } from './utils/grid-track-value';
93
24
 
94
25
  type GridTrackCssProp = 'grid-template-rows' | 'grid-template-columns';
95
26
 
@@ -98,24 +29,43 @@ type GridTrackFieldProps = {
98
29
  label: string;
99
30
  };
100
31
 
101
- const GridTrackField = ( { cssProp, label }: GridTrackFieldProps ) => (
102
- <UiProviders>
103
- <StylesField bind={ cssProp } propDisplayName={ label }>
104
- <GridTrackFieldContent cssProp={ cssProp } label={ label } />
105
- </StylesField>
106
- </UiProviders>
32
+ type GridTrackSizeInputProps = {
33
+ value: { size: number | string; unit: GridTrackUnit };
34
+ placeholder?: string;
35
+ setValue: ( value: { size: number | string; unit: GridTrackUnit } ) => void;
36
+ anchorRef: React.RefObject< HTMLDivElement | null >;
37
+ };
38
+
39
+ type SizeComponentProps = Parameters< typeof SizeComponent >[ 0 ];
40
+
41
+ const SizeFieldWrapper = ( { children }: { children: React.ReactNode } ) => (
42
+ <ControlActions>{ children as React.ReactElement }</ControlActions>
107
43
  );
108
44
 
45
+ const GridTrackSizeInput = createControl( ( props: GridTrackSizeInputProps ) => (
46
+ <SizeComponent
47
+ units={ UNITS as unknown as SizeComponentProps[ 'units' ] }
48
+ value={ props.value as SizeComponentProps[ 'value' ] }
49
+ placeholder={ props.placeholder }
50
+ defaultUnit={ FR as SizeComponentProps[ 'defaultUnit' ] }
51
+ setValue={ props.setValue as SizeComponentProps[ 'setValue' ] }
52
+ onBlur={ () => {} }
53
+ min={ 1 }
54
+ anchorRef={ props.anchorRef }
55
+ SizeFieldWrapper={ SizeFieldWrapper }
56
+ />
57
+ ) );
58
+
109
59
  const GridTrackFieldContent = ( { cssProp, label }: GridTrackFieldProps ) => {
110
- const { value, setValue } = useStylesField< StringPropValue | null >( cssProp, {
60
+ const { value, setValue } = useStylesField< PropValue >( cssProp, {
111
61
  history: { propDisplayName: label },
112
62
  } );
113
63
 
114
64
  const { placeholder: inheritedPlaceholder } = useBoundProp();
115
65
  const anchorRef = useRef< HTMLDivElement >( null );
116
66
 
117
- const local = parseCss( value?.value ?? null );
118
- const inherited = parseCss( stringPropTypeUtil.extract( inheritedPlaceholder ) );
67
+ const local = parseValue( value );
68
+ const inherited = parseValue( inheritedPlaceholder );
119
69
 
120
70
  const displayValue = local.kind !== 'empty' ? toSizeInput( local ) : toSizeInput( EMPTY, unitOf( inherited ) );
121
71
  const placeholder = toPlaceholder( inherited );
@@ -127,21 +77,16 @@ const GridTrackFieldContent = ( { cssProp, label }: GridTrackFieldProps ) => {
127
77
  return;
128
78
  }
129
79
 
130
- const css = toCss( next );
131
- setValue( css === null ? null : { $$type: 'string', value: css } );
80
+ setValue( toPropValue( next ) );
132
81
  };
133
82
 
134
83
  return (
135
84
  <StylesFieldLayout label={ label } direction="column">
136
85
  <div ref={ anchorRef }>
137
- <SizeComponent
138
- units={ UNITS as unknown as Parameters< typeof SizeComponent >[ 0 ][ 'units' ] }
139
- value={ displayValue as Parameters< typeof SizeComponent >[ 0 ][ 'value' ] }
86
+ <GridTrackSizeInput
87
+ value={ displayValue }
140
88
  placeholder={ placeholder }
141
- defaultUnit={ FR as Parameters< typeof SizeComponent >[ 0 ][ 'defaultUnit' ] }
142
- setValue={ handleChange as Parameters< typeof SizeComponent >[ 0 ][ 'setValue' ] }
143
- onBlur={ () => {} }
144
- min={ 1 }
89
+ setValue={ handleChange }
145
90
  anchorRef={ anchorRef }
146
91
  />
147
92
  </div>
@@ -149,6 +94,14 @@ const GridTrackFieldContent = ( { cssProp, label }: GridTrackFieldProps ) => {
149
94
  );
150
95
  };
151
96
 
97
+ const GridTrackField = ( { cssProp, label }: GridTrackFieldProps ) => (
98
+ <UiProviders>
99
+ <StylesField bind={ cssProp } propDisplayName={ label }>
100
+ <GridTrackFieldContent cssProp={ cssProp } label={ label } />
101
+ </StylesField>
102
+ </UiProviders>
103
+ );
104
+
152
105
  export const GridSizeFields = () => (
153
106
  <Grid container gap={ 2 } flexWrap="nowrap">
154
107
  <Grid item xs={ 6 }>
@@ -0,0 +1,113 @@
1
+ import {
2
+ gridTrackSizePropTypeUtil,
3
+ type GridTrackSizePropValue,
4
+ type PropValue,
5
+ stringPropTypeUtil,
6
+ } from '@elementor/editor-props';
7
+
8
+ export type GridTrackUnit = 'fr' | 'custom';
9
+
10
+ export type GridTrackValue = { kind: 'empty' } | { kind: 'fr'; count: number } | { kind: 'custom'; raw: string };
11
+
12
+ export const FR = 'fr' as const;
13
+ export const CUSTOM = 'custom' as const;
14
+ export const UNITS: GridTrackUnit[] = [ FR, CUSTOM ];
15
+
16
+ export const EMPTY: GridTrackValue = { kind: 'empty' };
17
+
18
+ // Backward-compat: legacy values were stored as `{$$type:'string', value:'repeat(N, 1fr)'}`.
19
+ const REPEAT_FR_PATTERN = /^repeat\(\s*(\d+)\s*,\s*1fr\s*\)$/;
20
+
21
+ const parseString = ( css: string | null ): GridTrackValue => {
22
+ if ( ! css ) {
23
+ return EMPTY;
24
+ }
25
+ const match = css.match( REPEAT_FR_PATTERN );
26
+ if ( match ) {
27
+ const count = parseInt( match[ 1 ], 10 );
28
+ return count >= 1 ? { kind: 'fr', count } : EMPTY;
29
+ }
30
+ return { kind: 'custom', raw: css };
31
+ };
32
+
33
+ const parseGridTrackSize = ( size: GridTrackSizePropValue[ 'value' ] | null ): GridTrackValue => {
34
+ if ( ! size ) {
35
+ return EMPTY;
36
+ }
37
+ if ( size.unit === FR ) {
38
+ const n = Number( size.size );
39
+ return Number.isFinite( n ) && n >= 1 ? { kind: 'fr', count: Math.trunc( n ) } : EMPTY;
40
+ }
41
+ const raw = String( size.size ?? '' );
42
+ return raw === '' ? EMPTY : { kind: 'custom', raw };
43
+ };
44
+
45
+ export const parseValue = ( value: PropValue | undefined | null ): GridTrackValue => {
46
+ if ( ! value ) {
47
+ return EMPTY;
48
+ }
49
+ if ( gridTrackSizePropTypeUtil.isValid( value ) ) {
50
+ return parseGridTrackSize( gridTrackSizePropTypeUtil.extract( value ) );
51
+ }
52
+ if ( stringPropTypeUtil.isValid( value ) ) {
53
+ return parseString( stringPropTypeUtil.extract( value ) );
54
+ }
55
+ return EMPTY;
56
+ };
57
+
58
+ export const fromSizeInput = ( v: { size: number | string; unit: GridTrackUnit } ): GridTrackValue => {
59
+ if ( v.size === '' || Number.isNaN( v.size ) ) {
60
+ return EMPTY;
61
+ }
62
+ if ( v.unit === FR ) {
63
+ const n = Number( v.size );
64
+ return Number.isFinite( n ) && n >= 1 ? { kind: 'fr', count: Math.trunc( n ) } : EMPTY;
65
+ }
66
+ return { kind: 'custom', raw: String( v.size ) };
67
+ };
68
+
69
+ export const toPropValue = ( v: GridTrackValue ): PropValue => {
70
+ switch ( v.kind ) {
71
+ case 'empty':
72
+ return null;
73
+ case 'fr':
74
+ return gridTrackSizePropTypeUtil.create( { size: v.count, unit: FR } );
75
+ case 'custom':
76
+ return gridTrackSizePropTypeUtil.create( { size: v.raw, unit: CUSTOM } );
77
+ }
78
+ };
79
+
80
+ export const toSizeInput = (
81
+ v: GridTrackValue,
82
+ fallbackUnit: GridTrackUnit = FR
83
+ ): { size: number | string; unit: GridTrackUnit } => {
84
+ switch ( v.kind ) {
85
+ case 'empty':
86
+ return { size: '', unit: fallbackUnit };
87
+ case 'fr':
88
+ return { size: v.count, unit: FR };
89
+ case 'custom':
90
+ return { size: v.raw, unit: CUSTOM };
91
+ }
92
+ };
93
+
94
+ export const toPlaceholder = ( v: GridTrackValue ): string | undefined => {
95
+ switch ( v.kind ) {
96
+ case 'empty':
97
+ return undefined;
98
+ case 'fr':
99
+ return String( v.count );
100
+ case 'custom':
101
+ return v.raw;
102
+ }
103
+ };
104
+
105
+ export const unitOf = ( v: GridTrackValue, fallback: GridTrackUnit = FR ): GridTrackUnit => {
106
+ if ( v.kind === 'fr' ) {
107
+ return FR;
108
+ }
109
+ if ( v.kind === 'custom' ) {
110
+ return CUSTOM;
111
+ }
112
+ return fallback;
113
+ };