@elementor/editor-editing-panel 4.2.0-846 → 4.2.0-848
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.js +86 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +24 -24
- package/src/components/style-sections/layout-section/grid-size-field.tsx +88 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-editing-panel",
|
|
3
|
-
"version": "4.2.0-
|
|
3
|
+
"version": "4.2.0-848",
|
|
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-
|
|
43
|
-
"@elementor/editor-canvas": "4.2.0-
|
|
44
|
-
"@elementor/editor-controls": "4.2.0-
|
|
45
|
-
"@elementor/editor-documents": "4.2.0-
|
|
46
|
-
"@elementor/editor-elements": "4.2.0-
|
|
47
|
-
"@elementor/editor-interactions": "4.2.0-
|
|
48
|
-
"@elementor/editor-notifications": "4.2.0-
|
|
49
|
-
"@elementor/editor-panels": "4.2.0-
|
|
50
|
-
"@elementor/editor-props": "4.2.0-
|
|
51
|
-
"@elementor/editor-responsive": "4.2.0-
|
|
52
|
-
"@elementor/editor-styles": "4.2.0-
|
|
53
|
-
"@elementor/editor-styles-repository": "4.2.0-
|
|
54
|
-
"@elementor/editor-ui": "4.2.0-
|
|
55
|
-
"@elementor/editor-v1-adapters": "4.2.0-
|
|
56
|
-
"@elementor/http-client": "4.2.0-
|
|
42
|
+
"@elementor/editor": "4.2.0-848",
|
|
43
|
+
"@elementor/editor-canvas": "4.2.0-848",
|
|
44
|
+
"@elementor/editor-controls": "4.2.0-848",
|
|
45
|
+
"@elementor/editor-documents": "4.2.0-848",
|
|
46
|
+
"@elementor/editor-elements": "4.2.0-848",
|
|
47
|
+
"@elementor/editor-interactions": "4.2.0-848",
|
|
48
|
+
"@elementor/editor-notifications": "4.2.0-848",
|
|
49
|
+
"@elementor/editor-panels": "4.2.0-848",
|
|
50
|
+
"@elementor/editor-props": "4.2.0-848",
|
|
51
|
+
"@elementor/editor-responsive": "4.2.0-848",
|
|
52
|
+
"@elementor/editor-styles": "4.2.0-848",
|
|
53
|
+
"@elementor/editor-styles-repository": "4.2.0-848",
|
|
54
|
+
"@elementor/editor-ui": "4.2.0-848",
|
|
55
|
+
"@elementor/editor-v1-adapters": "4.2.0-848",
|
|
56
|
+
"@elementor/http-client": "4.2.0-848",
|
|
57
57
|
"@elementor/icons": "~1.75.1",
|
|
58
|
-
"@elementor/editor-variables": "4.2.0-
|
|
59
|
-
"@elementor/locations": "4.2.0-
|
|
60
|
-
"@elementor/menus": "4.2.0-
|
|
61
|
-
"@elementor/query": "4.2.0-
|
|
62
|
-
"@elementor/schema": "4.2.0-
|
|
63
|
-
"@elementor/session": "4.2.0-
|
|
58
|
+
"@elementor/editor-variables": "4.2.0-848",
|
|
59
|
+
"@elementor/locations": "4.2.0-848",
|
|
60
|
+
"@elementor/menus": "4.2.0-848",
|
|
61
|
+
"@elementor/query": "4.2.0-848",
|
|
62
|
+
"@elementor/schema": "4.2.0-848",
|
|
63
|
+
"@elementor/session": "4.2.0-848",
|
|
64
64
|
"@elementor/ui": "1.37.5",
|
|
65
|
-
"@elementor/utils": "4.2.0-
|
|
66
|
-
"@elementor/wp-media": "4.2.0-
|
|
65
|
+
"@elementor/utils": "4.2.0-848",
|
|
66
|
+
"@elementor/wp-media": "4.2.0-848",
|
|
67
67
|
"@wordpress/i18n": "^5.13.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
@@ -1,42 +1,94 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useRef } from 'react';
|
|
3
|
-
import { SizeComponent } from '@elementor/editor-controls';
|
|
4
|
-
import { type StringPropValue } from '@elementor/editor-props';
|
|
3
|
+
import { SizeComponent, useBoundProp } from '@elementor/editor-controls';
|
|
4
|
+
import { stringPropTypeUtil, type StringPropValue } from '@elementor/editor-props';
|
|
5
5
|
import { Grid } from '@elementor/ui';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
|
|
8
8
|
import { StylesField } from '../../../controls-registry/styles-field';
|
|
9
9
|
import { useStylesField } from '../../../hooks/use-styles-field';
|
|
10
|
+
import { UiProviders } from '../../../styles-inheritance/components/ui-providers';
|
|
10
11
|
import { StylesFieldLayout } from '../../styles-field-layout';
|
|
11
12
|
|
|
12
13
|
type GridTrackUnit = 'fr' | 'custom';
|
|
13
|
-
|
|
14
|
+
|
|
15
|
+
type GridTrackValue = { kind: 'empty' } | { kind: 'fr'; count: number } | { kind: 'custom'; raw: string };
|
|
14
16
|
|
|
15
17
|
const FR = 'fr' as const;
|
|
16
18
|
const CUSTOM = 'custom' as const;
|
|
17
19
|
const UNITS: GridTrackUnit[] = [ FR, CUSTOM ];
|
|
18
20
|
|
|
21
|
+
const EMPTY: GridTrackValue = { kind: 'empty' };
|
|
22
|
+
|
|
19
23
|
const REPEAT_FR_PATTERN = /^repeat\(\s*(\d+)\s*,\s*1fr\s*\)$/;
|
|
20
24
|
|
|
21
|
-
const
|
|
25
|
+
const parseCss = ( css: string | null ): GridTrackValue => {
|
|
22
26
|
if ( ! css ) {
|
|
23
|
-
return
|
|
27
|
+
return EMPTY;
|
|
24
28
|
}
|
|
25
29
|
const match = css.match( REPEAT_FR_PATTERN );
|
|
26
30
|
if ( match ) {
|
|
27
|
-
|
|
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;
|
|
28
40
|
}
|
|
29
|
-
|
|
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 ) };
|
|
30
46
|
};
|
|
31
47
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
35
56
|
}
|
|
36
|
-
|
|
37
|
-
|
|
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 };
|
|
38
70
|
}
|
|
39
|
-
|
|
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;
|
|
40
92
|
};
|
|
41
93
|
|
|
42
94
|
type GridTrackCssProp = 'grid-template-rows' | 'grid-template-columns';
|
|
@@ -47,9 +99,11 @@ type GridTrackFieldProps = {
|
|
|
47
99
|
};
|
|
48
100
|
|
|
49
101
|
const GridTrackField = ( { cssProp, label }: GridTrackFieldProps ) => (
|
|
50
|
-
<
|
|
51
|
-
<
|
|
52
|
-
|
|
102
|
+
<UiProviders>
|
|
103
|
+
<StylesField bind={ cssProp } propDisplayName={ label }>
|
|
104
|
+
<GridTrackFieldContent cssProp={ cssProp } label={ label } />
|
|
105
|
+
</StylesField>
|
|
106
|
+
</UiProviders>
|
|
53
107
|
);
|
|
54
108
|
|
|
55
109
|
const GridTrackFieldContent = ( { cssProp, label }: GridTrackFieldProps ) => {
|
|
@@ -57,12 +111,24 @@ const GridTrackFieldContent = ( { cssProp, label }: GridTrackFieldProps ) => {
|
|
|
57
111
|
history: { propDisplayName: label },
|
|
58
112
|
} );
|
|
59
113
|
|
|
114
|
+
const { placeholder: inheritedPlaceholder } = useBoundProp();
|
|
60
115
|
const anchorRef = useRef< HTMLDivElement >( null );
|
|
61
|
-
const trackValue = cssToTrackValue( value?.value ?? null );
|
|
62
116
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
117
|
+
const local = parseCss( value?.value ?? null );
|
|
118
|
+
const inherited = parseCss( stringPropTypeUtil.extract( inheritedPlaceholder ) );
|
|
119
|
+
|
|
120
|
+
const displayValue = local.kind !== 'empty' ? toSizeInput( local ) : toSizeInput( EMPTY, unitOf( inherited ) );
|
|
121
|
+
const placeholder = toPlaceholder( inherited );
|
|
122
|
+
|
|
123
|
+
const handleChange = ( raw: { size: number | string; unit: GridTrackUnit } ) => {
|
|
124
|
+
const next = fromSizeInput( raw );
|
|
125
|
+
|
|
126
|
+
if ( next.kind === 'empty' && local.kind !== 'empty' && raw.unit !== unitOf( local ) ) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const css = toCss( next );
|
|
131
|
+
setValue( css === null ? null : { $$type: 'string', value: css } );
|
|
66
132
|
};
|
|
67
133
|
|
|
68
134
|
return (
|
|
@@ -70,9 +136,8 @@ const GridTrackFieldContent = ( { cssProp, label }: GridTrackFieldProps ) => {
|
|
|
70
136
|
<div ref={ anchorRef }>
|
|
71
137
|
<SizeComponent
|
|
72
138
|
units={ UNITS as unknown as Parameters< typeof SizeComponent >[ 0 ][ 'units' ] }
|
|
73
|
-
value={
|
|
74
|
-
|
|
75
|
-
}
|
|
139
|
+
value={ displayValue as Parameters< typeof SizeComponent >[ 0 ][ 'value' ] }
|
|
140
|
+
placeholder={ placeholder }
|
|
76
141
|
defaultUnit={ FR as Parameters< typeof SizeComponent >[ 0 ][ 'defaultUnit' ] }
|
|
77
142
|
setValue={ handleChange as Parameters< typeof SizeComponent >[ 0 ][ 'setValue' ] }
|
|
78
143
|
onBlur={ () => {} }
|