@elementor/editor-canvas 4.3.0-991 → 4.3.0-992

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.
@@ -1,110 +0,0 @@
1
- import { type V1ElementConfig } from '@elementor/editor-elements';
2
- import { type Props, type PropValue } from '@elementor/editor-props';
3
-
4
- import { getRequiredDefaultChildTypes } from '../../composition-builder/utils/required-default-child-tags';
5
-
6
- const DEFAULT_STYLES_INSTRUCTION = 'These are the default styles applied to the widget. Override only when necessary.';
7
-
8
- const DEFAULT_SETTINGS_INSTRUCTION =
9
- 'These are the default settings applied to the widget. Omit them from elementConfig unless the user explicitly asks to change them.';
10
-
11
- const BASE_SETTING_PROP_HINT =
12
- 'Has a widget default — omit unless user explicitly requests a change. See llm_guidance.default_settings.';
13
-
14
- export type LlmGuidance = Record< string, unknown >;
15
-
16
- export type JsonSchemaProperty = {
17
- description?: string;
18
- [ key: string ]: unknown;
19
- };
20
-
21
- export function mergeInstructions( existing: unknown, additional: string ): string {
22
- if ( typeof existing === 'string' && existing.length > 0 ) {
23
- return `${ existing } ${ additional }`;
24
- }
25
-
26
- return additional;
27
- }
28
-
29
- export function enrichPropertiesWithBaseSettingsHints(
30
- properties: Record< string, JsonSchemaProperty >,
31
- baseSettingsKeys: string[]
32
- ): Record< string, JsonSchemaProperty > {
33
- if ( ! baseSettingsKeys.length ) {
34
- return properties;
35
- }
36
-
37
- const enriched: Record< string, JsonSchemaProperty > = { ...properties };
38
-
39
- for ( const key of baseSettingsKeys ) {
40
- const propSchema = enriched[ key ];
41
-
42
- if ( ! propSchema ) {
43
- continue;
44
- }
45
-
46
- enriched[ key ] = {
47
- ...propSchema,
48
- description: propSchema.description
49
- ? `${ propSchema.description } ${ BASE_SETTING_PROP_HINT }`
50
- : BASE_SETTING_PROP_HINT,
51
- };
52
- }
53
-
54
- return enriched;
55
- }
56
-
57
- export function buildLlmGuidance(
58
- widgetData: V1ElementConfig,
59
- widgetType: string,
60
- allWidgets: Record< string, V1ElementConfig >
61
- ): LlmGuidance {
62
- const defaultStyles: Record< string, Props > = {};
63
- const baseStyleSchema = widgetData?.base_styles;
64
-
65
- if ( baseStyleSchema ) {
66
- Object.values( baseStyleSchema ).forEach( ( stylePropType ) => {
67
- stylePropType.variants.forEach( ( variant ) => {
68
- Object.assign( defaultStyles, variant.props );
69
- } );
70
- } );
71
- }
72
-
73
- const baseSettings = ( widgetData?.base_settings ?? {} ) as Record< string, PropValue >;
74
- const hasDefaultStyles = Object.keys( defaultStyles ).length > 0;
75
- const hasDefaultSettings = Object.keys( baseSettings ).length > 0;
76
-
77
- const llmGuidance: LlmGuidance = {
78
- can_have_children: !! widgetData?.meta?.is_container,
79
- };
80
-
81
- if ( hasDefaultStyles ) {
82
- llmGuidance.instructions = DEFAULT_STYLES_INSTRUCTION;
83
- llmGuidance.default_styles = defaultStyles;
84
- }
85
-
86
- if ( hasDefaultSettings ) {
87
- llmGuidance.instructions = mergeInstructions( llmGuidance.instructions, DEFAULT_SETTINGS_INSTRUCTION );
88
- llmGuidance.default_settings = baseSettings;
89
- }
90
-
91
- const allowedChildTypes = widgetData.allowed_child_types;
92
- const allowedParents = Object.entries( allWidgets )
93
- .filter( ( [ , parentConfig ] ) => parentConfig.allowed_child_types?.includes( widgetType ) )
94
- .map( ( [ parentType ] ) => parentType );
95
-
96
- if ( allowedChildTypes?.length || allowedParents.length ) {
97
- llmGuidance.nesting = {
98
- ...( allowedChildTypes?.length ? { allowed_child_types: allowedChildTypes } : {} ),
99
- ...( allowedParents.length ? { allowed_parents: allowedParents } : {} ),
100
- };
101
- }
102
-
103
- const requiredDirectChildTags = getRequiredDefaultChildTypes( widgetData );
104
-
105
- if ( requiredDirectChildTags.length ) {
106
- llmGuidance.required_direct_children = requiredDirectChildTags;
107
- }
108
-
109
- return llmGuidance;
110
- }