@elementor/editor-controls 4.2.0-895 → 4.2.0-896

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-controls",
3
3
  "description": "This package contains the controls model and utils for the Elementor editor",
4
- "version": "4.2.0-895",
4
+ "version": "4.2.0-896",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,23 +40,23 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-current-user": "4.2.0-895",
44
- "@elementor/editor-elements": "4.2.0-895",
45
- "@elementor/editor-props": "4.2.0-895",
46
- "@elementor/editor-responsive": "4.2.0-895",
47
- "@elementor/editor-ui": "4.2.0-895",
48
- "@elementor/editor-v1-adapters": "4.2.0-895",
49
- "@elementor/env": "4.2.0-895",
50
- "@elementor/events": "4.2.0-895",
51
- "@elementor/http-client": "4.2.0-895",
43
+ "@elementor/editor-current-user": "4.2.0-896",
44
+ "@elementor/editor-elements": "4.2.0-896",
45
+ "@elementor/editor-props": "4.2.0-896",
46
+ "@elementor/editor-responsive": "4.2.0-896",
47
+ "@elementor/editor-ui": "4.2.0-896",
48
+ "@elementor/editor-v1-adapters": "4.2.0-896",
49
+ "@elementor/env": "4.2.0-896",
50
+ "@elementor/events": "4.2.0-896",
51
+ "@elementor/http-client": "4.2.0-896",
52
52
  "@elementor/icons": "~1.75.1",
53
- "@elementor/locations": "4.2.0-895",
54
- "@elementor/query": "4.2.0-895",
55
- "@elementor/schema": "4.2.0-895",
56
- "@elementor/session": "4.2.0-895",
53
+ "@elementor/locations": "4.2.0-896",
54
+ "@elementor/query": "4.2.0-896",
55
+ "@elementor/schema": "4.2.0-896",
56
+ "@elementor/session": "4.2.0-896",
57
57
  "@elementor/ui": "1.37.5",
58
- "@elementor/utils": "4.2.0-895",
59
- "@elementor/wp-media": "4.2.0-895",
58
+ "@elementor/utils": "4.2.0-896",
59
+ "@elementor/wp-media": "4.2.0-896",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "@tiptap/extension-bold": "^3.11.1",
62
62
  "@tiptap/extension-document": "^3.11.1",
@@ -1,5 +1,5 @@
1
- import { getContainer, getSelectedElements } from '@elementor/editor-elements';
2
- import { isTransformable } from '@elementor/editor-props';
1
+ import { getContainer, getSelectedElements, getWidgetsCache, type V1Element } from '@elementor/editor-elements';
2
+ import { type PropsSchema, stringPropTypeUtil } from '@elementor/editor-props';
3
3
  import { __privateUseListenTo as useListenTo, commandEndEvent, v1ReadyEvent } from '@elementor/editor-v1-adapters';
4
4
 
5
5
  export type Suggestion = {
@@ -15,12 +15,53 @@ const FORM_FIELD_WIDGET_TYPES = [
15
15
  'e-form-select',
16
16
  'e-form-date-picker',
17
17
  'e-form-time-picker',
18
- ];
18
+ ] as const;
19
+
20
+ const FORM_ELEMENT_TYPE = 'e-form';
21
+ const CSS_ID_PROP_KEY = '_cssid';
22
+
23
+ function isFormFieldWidgetType( widgetType: string ): boolean {
24
+ return ( FORM_FIELD_WIDGET_TYPES as readonly string[] ).includes( widgetType );
25
+ }
19
26
 
20
27
  type Options = {
21
28
  inputType?: string;
22
29
  };
23
30
 
31
+ function extractStringPropValue( value: unknown ): string | null {
32
+ return stringPropTypeUtil.extract( value );
33
+ }
34
+
35
+ function getSettingWithDefault( child: V1Element, widgetType: string, key: string ): unknown {
36
+ const fromGet = child.settings.get( key );
37
+
38
+ if ( fromGet !== null && fromGet !== undefined ) {
39
+ return fromGet;
40
+ }
41
+
42
+ const schema = getWidgetsCache()?.[ widgetType ]?.atomic_props_schema as PropsSchema | undefined;
43
+
44
+ return schema?.[ key ]?.default ?? null;
45
+ }
46
+
47
+ function getFieldCssId( child: V1Element, widgetType: string ): string | null {
48
+ return extractStringPropValue( getSettingWithDefault( child, widgetType, CSS_ID_PROP_KEY ) );
49
+ }
50
+
51
+ function getFormContainer( elementId: string ): V1Element | null {
52
+ let container = getContainer( elementId );
53
+
54
+ while ( container ) {
55
+ if ( container.model.get( 'elType' ) === FORM_ELEMENT_TYPE ) {
56
+ return container;
57
+ }
58
+
59
+ container = container.parent ?? null;
60
+ }
61
+
62
+ return null;
63
+ }
64
+
24
65
  export function useFormFieldSuggestions( options?: Options ): Suggestion[] {
25
66
  return useListenTo(
26
67
  [
@@ -31,42 +72,44 @@ export function useFormFieldSuggestions( options?: Options ): Suggestion[] {
31
72
  ],
32
73
  () => {
33
74
  const selectedElements = getSelectedElements();
34
- const formElement = selectedElements[ 0 ];
75
+ const selectedElement = selectedElements[ 0 ];
35
76
 
36
- if ( ! formElement ) {
77
+ if ( ! selectedElement ) {
37
78
  return [];
38
79
  }
39
80
 
40
- const container = getContainer( formElement.id );
81
+ const formContainer = getFormContainer( selectedElement.id );
41
82
 
42
- if ( ! container?.children ) {
83
+ if ( ! formContainer?.children ) {
43
84
  return [];
44
85
  }
45
86
 
46
87
  const suggestions: Suggestion[] = [];
88
+ const seenCssIds = new Set< string >();
47
89
 
48
- container.children.forEachRecursive?.( ( child ) => {
90
+ formContainer.children.forEachRecursive?.( ( child ) => {
49
91
  const widgetType = child.model.get( 'widgetType' ) as string | undefined;
50
92
 
51
- if ( ! widgetType || ! FORM_FIELD_WIDGET_TYPES.includes( widgetType ) ) {
93
+ if ( ! widgetType || ! isFormFieldWidgetType( widgetType ) ) {
52
94
  return;
53
95
  }
54
96
 
55
97
  if ( options?.inputType ) {
56
- const typeProp = child.settings.get( 'type' );
57
- const typeValue = isTransformable( typeProp ) ? typeProp.value : typeProp;
98
+ const typeValue = extractStringPropValue( getSettingWithDefault( child, widgetType, 'type' ) );
58
99
 
59
100
  if ( typeValue !== options.inputType ) {
60
101
  return;
61
102
  }
62
103
  }
63
104
 
64
- const cssIdProp = child.settings.get( '_cssid' );
65
- const fieldId = isTransformable( cssIdProp ) ? cssIdProp.value : cssIdProp;
105
+ const cssId = getFieldCssId( child, widgetType );
66
106
 
67
- if ( fieldId && typeof fieldId === 'string' ) {
68
- suggestions.push( { label: fieldId, value: fieldId } );
107
+ if ( ! cssId || seenCssIds.has( cssId ) ) {
108
+ return;
69
109
  }
110
+
111
+ seenCssIds.add( cssId );
112
+ suggestions.push( { label: cssId, value: cssId } );
70
113
  } );
71
114
 
72
115
  return suggestions;