@elementor/editor-editing-panel 4.2.0-847 → 4.2.0-849

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-847",
3
+ "version": "4.2.0-849",
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-847",
43
- "@elementor/editor-canvas": "4.2.0-847",
44
- "@elementor/editor-controls": "4.2.0-847",
45
- "@elementor/editor-documents": "4.2.0-847",
46
- "@elementor/editor-elements": "4.2.0-847",
47
- "@elementor/editor-interactions": "4.2.0-847",
48
- "@elementor/editor-notifications": "4.2.0-847",
49
- "@elementor/editor-panels": "4.2.0-847",
50
- "@elementor/editor-props": "4.2.0-847",
51
- "@elementor/editor-responsive": "4.2.0-847",
52
- "@elementor/editor-styles": "4.2.0-847",
53
- "@elementor/editor-styles-repository": "4.2.0-847",
54
- "@elementor/editor-ui": "4.2.0-847",
55
- "@elementor/editor-v1-adapters": "4.2.0-847",
56
- "@elementor/http-client": "4.2.0-847",
42
+ "@elementor/editor": "4.2.0-849",
43
+ "@elementor/editor-canvas": "4.2.0-849",
44
+ "@elementor/editor-controls": "4.2.0-849",
45
+ "@elementor/editor-documents": "4.2.0-849",
46
+ "@elementor/editor-elements": "4.2.0-849",
47
+ "@elementor/editor-interactions": "4.2.0-849",
48
+ "@elementor/editor-notifications": "4.2.0-849",
49
+ "@elementor/editor-panels": "4.2.0-849",
50
+ "@elementor/editor-props": "4.2.0-849",
51
+ "@elementor/editor-responsive": "4.2.0-849",
52
+ "@elementor/editor-styles": "4.2.0-849",
53
+ "@elementor/editor-styles-repository": "4.2.0-849",
54
+ "@elementor/editor-ui": "4.2.0-849",
55
+ "@elementor/editor-v1-adapters": "4.2.0-849",
56
+ "@elementor/http-client": "4.2.0-849",
57
57
  "@elementor/icons": "~1.75.1",
58
- "@elementor/editor-variables": "4.2.0-847",
59
- "@elementor/locations": "4.2.0-847",
60
- "@elementor/menus": "4.2.0-847",
61
- "@elementor/query": "4.2.0-847",
62
- "@elementor/schema": "4.2.0-847",
63
- "@elementor/session": "4.2.0-847",
58
+ "@elementor/editor-variables": "4.2.0-849",
59
+ "@elementor/locations": "4.2.0-849",
60
+ "@elementor/menus": "4.2.0-849",
61
+ "@elementor/query": "4.2.0-849",
62
+ "@elementor/schema": "4.2.0-849",
63
+ "@elementor/session": "4.2.0-849",
64
64
  "@elementor/ui": "1.37.5",
65
- "@elementor/utils": "4.2.0-847",
66
- "@elementor/wp-media": "4.2.0-847",
65
+ "@elementor/utils": "4.2.0-849",
66
+ "@elementor/wp-media": "4.2.0-849",
67
67
  "@wordpress/i18n": "^5.13.0"
68
68
  },
69
69
  "peerDependencies": {
@@ -2,6 +2,7 @@ import { setDocumentModifiedStatus } from '@elementor/editor-documents';
2
2
  import { getElementSetting, updateElementSettings } from '@elementor/editor-elements';
3
3
  import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';
4
4
  import { type StyleDefinitionID } from '@elementor/editor-styles';
5
+ import { stylesRepository } from '@elementor/editor-styles-repository';
5
6
 
6
7
  // Externalized for use outside of Hooks
7
8
 
@@ -16,6 +17,21 @@ export function doApplyClasses( elementId: string, classIds: StyleDefinitionID[]
16
17
  withHistory: false,
17
18
  } );
18
19
  setDocumentModifiedStatus( true );
20
+
21
+ ensureClassesAreLoaded( classIds );
22
+ }
23
+
24
+ function ensureClassesAreLoaded( classIds: StyleDefinitionID[] ) {
25
+ const providers = stylesRepository.getProviders();
26
+
27
+ classIds.forEach( ( classId ) => {
28
+ stylesRepository.getProviderByKey( classId )?.actions.get( classId );
29
+ const owningProvider = providers.find( ( provider ) =>
30
+ provider.actions.all().some( ( style ) => style.id === classId )
31
+ );
32
+
33
+ owningProvider?.actions.get( classId );
34
+ } );
19
35
  }
20
36
 
21
37
  export function doUnapplyClass( elementId: string, classId: StyleDefinitionID, classesPropType = 'classes' ) {
@@ -24,7 +40,7 @@ export function doUnapplyClass( elementId: string, classId: StyleDefinitionID, c
24
40
  return false;
25
41
  }
26
42
 
27
- const updatedClassIds = appliedClasses.filter( ( id ) => id !== classId );
43
+ const updatedClassIds = appliedClasses.filter( ( id: StyleDefinitionID ) => id !== classId );
28
44
  doApplyClasses( elementId, updatedClassIds, classesPropType );
29
45
  return true;
30
46
  }
@@ -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
- type GridTrackValue = { size: number | string; unit: GridTrackUnit };
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 cssToTrackValue = ( css: string | null ): GridTrackValue | null => {
25
+ const parseCss = ( css: string | null ): GridTrackValue => {
22
26
  if ( ! css ) {
23
- return null;
27
+ return EMPTY;
24
28
  }
25
29
  const match = css.match( REPEAT_FR_PATTERN );
26
30
  if ( match ) {
27
- return { size: parseInt( match[ 1 ], 10 ), unit: FR };
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
- return { size: css, unit: CUSTOM };
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 trackValueToCss = ( trackValue: GridTrackValue | null ): string | null => {
33
- if ( ! trackValue || trackValue.size === '' || trackValue.size === null ) {
34
- return null;
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
- if ( trackValue.unit === FR ) {
37
- return `repeat(${ trackValue.size }, 1fr)`;
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
- return String( trackValue.size );
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
- <StylesField bind={ cssProp } propDisplayName={ label }>
51
- <GridTrackFieldContent cssProp={ cssProp } label={ label } />
52
- </StylesField>
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 handleChange = ( newValue: GridTrackValue ) => {
64
- const css = trackValueToCss( newValue );
65
- setValue( css ? { $$type: 'string', value: css } : null );
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
- ( trackValue ?? { size: NaN, unit: FR } ) as Parameters< typeof SizeComponent >[ 0 ][ 'value' ]
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={ () => {} }