@elementor/editor-controls 4.2.0-895 → 4.2.0-897
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 +42 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/hooks/use-form-field-suggestions.ts +58 -15
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-
|
|
4
|
+
"version": "4.2.0-897",
|
|
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-
|
|
44
|
-
"@elementor/editor-elements": "4.2.0-
|
|
45
|
-
"@elementor/editor-props": "4.2.0-
|
|
46
|
-
"@elementor/editor-responsive": "4.2.0-
|
|
47
|
-
"@elementor/editor-ui": "4.2.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "4.2.0-
|
|
49
|
-
"@elementor/env": "4.2.0-
|
|
50
|
-
"@elementor/events": "4.2.0-
|
|
51
|
-
"@elementor/http-client": "4.2.0-
|
|
43
|
+
"@elementor/editor-current-user": "4.2.0-897",
|
|
44
|
+
"@elementor/editor-elements": "4.2.0-897",
|
|
45
|
+
"@elementor/editor-props": "4.2.0-897",
|
|
46
|
+
"@elementor/editor-responsive": "4.2.0-897",
|
|
47
|
+
"@elementor/editor-ui": "4.2.0-897",
|
|
48
|
+
"@elementor/editor-v1-adapters": "4.2.0-897",
|
|
49
|
+
"@elementor/env": "4.2.0-897",
|
|
50
|
+
"@elementor/events": "4.2.0-897",
|
|
51
|
+
"@elementor/http-client": "4.2.0-897",
|
|
52
52
|
"@elementor/icons": "~1.75.1",
|
|
53
|
-
"@elementor/locations": "4.2.0-
|
|
54
|
-
"@elementor/query": "4.2.0-
|
|
55
|
-
"@elementor/schema": "4.2.0-
|
|
56
|
-
"@elementor/session": "4.2.0-
|
|
53
|
+
"@elementor/locations": "4.2.0-897",
|
|
54
|
+
"@elementor/query": "4.2.0-897",
|
|
55
|
+
"@elementor/schema": "4.2.0-897",
|
|
56
|
+
"@elementor/session": "4.2.0-897",
|
|
57
57
|
"@elementor/ui": "1.37.5",
|
|
58
|
-
"@elementor/utils": "4.2.0-
|
|
59
|
-
"@elementor/wp-media": "4.2.0-
|
|
58
|
+
"@elementor/utils": "4.2.0-897",
|
|
59
|
+
"@elementor/wp-media": "4.2.0-897",
|
|
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 {
|
|
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
|
|
75
|
+
const selectedElement = selectedElements[ 0 ];
|
|
35
76
|
|
|
36
|
-
if ( !
|
|
77
|
+
if ( ! selectedElement ) {
|
|
37
78
|
return [];
|
|
38
79
|
}
|
|
39
80
|
|
|
40
|
-
const
|
|
81
|
+
const formContainer = getFormContainer( selectedElement.id );
|
|
41
82
|
|
|
42
|
-
if ( !
|
|
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
|
-
|
|
90
|
+
formContainer.children.forEachRecursive?.( ( child ) => {
|
|
49
91
|
const widgetType = child.model.get( 'widgetType' ) as string | undefined;
|
|
50
92
|
|
|
51
|
-
if ( ! widgetType || !
|
|
93
|
+
if ( ! widgetType || ! isFormFieldWidgetType( widgetType ) ) {
|
|
52
94
|
return;
|
|
53
95
|
}
|
|
54
96
|
|
|
55
97
|
if ( options?.inputType ) {
|
|
56
|
-
const
|
|
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
|
|
65
|
-
const fieldId = isTransformable( cssIdProp ) ? cssIdProp.value : cssIdProp;
|
|
105
|
+
const cssId = getFieldCssId( child, widgetType );
|
|
66
106
|
|
|
67
|
-
if (
|
|
68
|
-
|
|
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;
|