@elementor/editor-props 3.35.0-340 → 3.35.0-341
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.d.mts +25 -15
- package/dist/index.d.ts +25 -15
- package/dist/index.js +190 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +190 -91
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +2 -0
- package/src/prop-types/size.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/adjust-llm-prop-value-schema.ts +66 -66
- package/src/utils/props-to-llm-schema.ts +89 -45
- package/src/utils/test-utils/stubs.ts +970 -0
- package/src/utils/transformers/global-color-variable-tx.ts +0 -0
- package/src/utils/transformers/prop-value-transformer.ts +3 -0
- package/src/utils/validate-prop-value.ts +150 -0
|
@@ -10,10 +10,13 @@ export function propTypeToJsonSchema( propType: PropType ): JsonSchema7 {
|
|
|
10
10
|
schema.description = description;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// Add example from initial_value if it exists
|
|
14
|
+
if ( propType.initial_value !== null && propType.initial_value !== undefined ) {
|
|
15
|
+
schema.examples = [ propType.initial_value ];
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
// Handle different kinds of prop types
|
|
14
19
|
switch ( propType.kind ) {
|
|
15
|
-
case 'plain':
|
|
16
|
-
return convertPlainPropType( propType, schema );
|
|
17
20
|
case 'union':
|
|
18
21
|
return convertUnionPropType( propType, schema );
|
|
19
22
|
case 'object':
|
|
@@ -23,33 +26,50 @@ export function propTypeToJsonSchema( propType: PropType ): JsonSchema7 {
|
|
|
23
26
|
default:
|
|
24
27
|
return convertPlainPropType( propType, schema );
|
|
25
28
|
}
|
|
26
|
-
|
|
27
|
-
return schema;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
function convertPlainPropType(
|
|
31
|
+
function convertPlainPropType(
|
|
32
|
+
propType: PropType & { key: string; kind: string },
|
|
33
|
+
baseSchema: JsonSchema7
|
|
34
|
+
): JsonSchema7 {
|
|
31
35
|
const schema = { ...baseSchema };
|
|
32
36
|
|
|
33
|
-
//
|
|
34
|
-
|
|
37
|
+
// This could happen when data is malformed due to a bug, added this as a safeguard.
|
|
38
|
+
if ( ! Object.hasOwn( propType, 'kind' ) ) {
|
|
39
|
+
throw new Error( `PropType kind is undefined for propType with key: ${ propType.key ?? '[unknown key]' }` );
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const enumValues = ( propType.settings?.enum || [] ) as string[] | number[];
|
|
35
43
|
|
|
36
|
-
switch (
|
|
44
|
+
switch ( propType.kind ) {
|
|
45
|
+
case 'string':
|
|
37
46
|
case 'number':
|
|
38
|
-
schema.type = 'number';
|
|
39
|
-
break;
|
|
40
47
|
case 'boolean':
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
return {
|
|
49
|
+
...schema,
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
$$type: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
const: propType.key ?? propType.kind,
|
|
55
|
+
},
|
|
56
|
+
value: {
|
|
57
|
+
type: propType.kind,
|
|
58
|
+
...( enumValues.length > 0 ? { enum: enumValues } : {} ),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
required: [ '$$type', 'value' ],
|
|
62
|
+
};
|
|
43
63
|
default:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
64
|
+
return {
|
|
65
|
+
...schema,
|
|
66
|
+
type: 'object',
|
|
67
|
+
$$type: propType.kind,
|
|
68
|
+
value: {
|
|
69
|
+
type: propType.kind,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
50
72
|
}
|
|
51
|
-
|
|
52
|
-
return schema;
|
|
53
73
|
}
|
|
54
74
|
|
|
55
75
|
/**
|
|
@@ -66,21 +86,11 @@ function convertUnionPropType( propType: PropType & { kind: 'union' }, baseSchem
|
|
|
66
86
|
|
|
67
87
|
// Convert each prop type in the union
|
|
68
88
|
for ( const [ typeKey, subPropType ] of Object.entries( propTypes ) ) {
|
|
89
|
+
if ( typeKey === 'dynamic' || typeKey === 'overridable' ) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
69
92
|
const subSchema = convertPropTypeToJsonSchema( subPropType );
|
|
70
|
-
|
|
71
|
-
schemas.push( {
|
|
72
|
-
type: 'object',
|
|
73
|
-
required: [ '$$type', 'value' ],
|
|
74
|
-
properties: {
|
|
75
|
-
$$type: {
|
|
76
|
-
type: 'string',
|
|
77
|
-
const: typeKey,
|
|
78
|
-
description: subPropType.meta?.description,
|
|
79
|
-
$comment: `Discriminator for union type variant: ${ typeKey }`,
|
|
80
|
-
},
|
|
81
|
-
value: subSchema,
|
|
82
|
-
},
|
|
83
|
-
} );
|
|
93
|
+
schemas.push( subSchema );
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
if ( schemas.length > 0 ) {
|
|
@@ -98,43 +108,77 @@ function convertObjectPropType( propType: PropType & { kind: 'object' }, baseSch
|
|
|
98
108
|
const schema = structuredClone( baseSchema );
|
|
99
109
|
|
|
100
110
|
schema.type = 'object';
|
|
101
|
-
|
|
111
|
+
const internalStructure: {
|
|
112
|
+
properties: {
|
|
113
|
+
$$type: JsonSchema7;
|
|
114
|
+
value: JsonSchema7;
|
|
115
|
+
};
|
|
116
|
+
} = {
|
|
117
|
+
properties: {
|
|
118
|
+
$$type: {
|
|
119
|
+
type: 'string',
|
|
120
|
+
const: propType.key,
|
|
121
|
+
},
|
|
122
|
+
value: {
|
|
123
|
+
type: 'object',
|
|
124
|
+
properties: {} as Record< string, JsonSchema7 >,
|
|
125
|
+
additionalProperties: false,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
102
129
|
|
|
103
|
-
const required: string[] = [];
|
|
130
|
+
const required: string[] = [ '$$type', 'value' ];
|
|
131
|
+
const valueRequired: string[] = [];
|
|
104
132
|
|
|
105
133
|
const shape = propType.shape || {};
|
|
106
134
|
|
|
107
135
|
// Convert each property in the object shape
|
|
108
136
|
for ( const [ key, subPropType ] of Object.entries( shape ) ) {
|
|
109
|
-
const propSchema =
|
|
137
|
+
const propSchema = propTypeToJsonSchema( subPropType );
|
|
110
138
|
|
|
111
139
|
// Check if this property is required
|
|
112
140
|
if ( subPropType.settings?.required === true ) {
|
|
113
|
-
|
|
141
|
+
valueRequired.push( key );
|
|
114
142
|
}
|
|
115
143
|
|
|
116
|
-
|
|
144
|
+
if ( internalStructure.properties.value.properties ) {
|
|
145
|
+
internalStructure.properties.value.properties[ key ] = propSchema;
|
|
146
|
+
}
|
|
117
147
|
}
|
|
118
148
|
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
|
|
149
|
+
schema.required = required;
|
|
150
|
+
if ( valueRequired.length > 0 ) {
|
|
151
|
+
internalStructure.properties.value.required = valueRequired;
|
|
122
152
|
}
|
|
123
153
|
|
|
124
|
-
return
|
|
154
|
+
return {
|
|
155
|
+
...schema,
|
|
156
|
+
...internalStructure,
|
|
157
|
+
};
|
|
125
158
|
}
|
|
126
159
|
|
|
127
160
|
function convertArrayPropType( propType: PropType & { kind: 'array' }, baseSchema: JsonSchema7 ): JsonSchema7 {
|
|
128
161
|
const schema = structuredClone( baseSchema );
|
|
129
162
|
|
|
130
|
-
schema.type = '
|
|
163
|
+
schema.type = 'object';
|
|
164
|
+
let items: unknown;
|
|
131
165
|
|
|
132
166
|
const itemPropType = propType.item_prop_type;
|
|
133
167
|
|
|
134
168
|
if ( itemPropType ) {
|
|
135
|
-
|
|
169
|
+
items = convertPropTypeToJsonSchema( itemPropType );
|
|
136
170
|
}
|
|
137
171
|
|
|
172
|
+
schema.properties = {
|
|
173
|
+
$$type: {
|
|
174
|
+
type: 'string',
|
|
175
|
+
const: propType.key,
|
|
176
|
+
},
|
|
177
|
+
value: {
|
|
178
|
+
type: 'array',
|
|
179
|
+
...( items ? { items } : {} ),
|
|
180
|
+
} as JsonSchema7,
|
|
181
|
+
};
|
|
138
182
|
return schema;
|
|
139
183
|
}
|
|
140
184
|
|