@elementor/editor-props 4.1.0-manual → 4.2.0-839

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.
@@ -0,0 +1,7 @@
1
+ import { z } from '@elementor/schema';
2
+
3
+ import { createPropUtils } from '../utils/create-prop-utils';
4
+
5
+ export const timeStringPropTypeUtil = createPropUtils( 'time-string', z.string() );
6
+
7
+ export type TimeStringPropValue = z.infer< typeof timeStringPropTypeUtil.schema >;
@@ -0,0 +1,26 @@
1
+ import { type TransformablePropValue } from '../types';
2
+ import { isTransformable } from './is-transformable';
3
+
4
+ type OverridableInner = {
5
+ override_key: string;
6
+ origin_value: TransformablePropValue< string >;
7
+ };
8
+
9
+ export type OverridableTransformable = TransformablePropValue< 'overridable', OverridableInner >;
10
+
11
+ export function isOverridable( value: unknown ): value is OverridableTransformable {
12
+ return isTransformable( value ) && value.$$type === 'overridable';
13
+ }
14
+
15
+ export function rewrapOverridableValue(
16
+ existing: OverridableTransformable,
17
+ newInner: TransformablePropValue< string >
18
+ ): OverridableTransformable {
19
+ return {
20
+ ...existing,
21
+ value: {
22
+ ...existing.value,
23
+ origin_value: newInner,
24
+ },
25
+ };
26
+ }
@@ -5,6 +5,7 @@ import {
5
5
  type PropValue,
6
6
  type TransformablePropValue,
7
7
  } from '../types';
8
+ import { isOverridable } from './is-overridable';
8
9
  import { isTransformable } from './is-transformable';
9
10
 
10
11
  type ParsedTerm = DependencyTerm;
@@ -113,24 +114,51 @@ function getRelationMethod( relation: Relation ) {
113
114
  }
114
115
  }
115
116
 
117
+ export type ExtractValueOptions = {
118
+ unwrapOverridableLeaf?: boolean;
119
+ };
120
+
116
121
  export function extractValue(
117
122
  path: string[],
118
123
  elementValues: PropValue,
119
- nestedPath: string[] = []
120
- ): TransformablePropValue< PropKey > | null {
124
+ nestedPath: string[] = [],
125
+ options: ExtractValueOptions = {}
126
+ ) {
127
+ const { unwrapOverridableLeaf = true } = options;
128
+
121
129
  const extractedValue = path.reduce( ( acc, key, index ) => {
122
- const value = acc?.[ key as keyof typeof acc ] as PropValue | null;
130
+ const value = acc?.[ key as keyof typeof acc ] as PropValue;
131
+
132
+ if ( index === path.length - 1 ) {
133
+ return value;
134
+ }
135
+
136
+ if ( isOverridable( value ) ) {
137
+ const inner = value.value.origin_value;
138
+
139
+ return isTransformable( inner ) ? inner.value ?? null : inner;
140
+ }
141
+
142
+ if ( isTransformable( value ) ) {
143
+ return value.value ?? null;
144
+ }
123
145
 
124
- return index !== path.length - 1 && isTransformable( value ) ? value.value ?? null : value;
146
+ return value;
125
147
  }, elementValues ) as TransformablePropValue< PropKey >;
126
148
 
149
+ let resolved = extractedValue;
150
+
151
+ if ( unwrapOverridableLeaf && resolved && isOverridable( resolved ) ) {
152
+ resolved = resolved.value.origin_value ?? null;
153
+ }
154
+
127
155
  if ( ! nestedPath?.length ) {
128
- return extractedValue;
156
+ return resolved;
129
157
  }
130
158
 
131
159
  const nestedValue = nestedPath.reduce(
132
160
  ( acc: Record< string, unknown >, key ) => acc?.[ key ] as Record< string, unknown >,
133
- extractedValue?.value as Record< string, unknown >
161
+ resolved?.value as Record< string, unknown >
134
162
  );
135
163
 
136
164
  return {
@@ -186,38 +186,17 @@ function convertPropTypeToJsonSchema( propType: PropType ): JsonSchema7 {
186
186
  return propTypeToJsonSchema( propType );
187
187
  }
188
188
 
189
- export function propsSchemaToJsonSchema( schema: PropsSchema ): JsonSchema7 {
190
- const jsonSchema: JsonSchema7 = {
191
- type: 'object',
192
- properties: {},
193
- };
194
-
195
- for ( const [ key, propType ] of Object.entries( schema ) ) {
196
- // Skip internal properties
197
- if ( ! isPropKeyConfigurable( key ) ) {
198
- continue;
199
- }
200
-
201
- const propSchema = convertPropTypeToJsonSchema( propType );
202
- if ( jsonSchema.properties ) {
203
- jsonSchema.properties[ key ] = propSchema;
204
- }
205
-
206
- // Handle required fields at root level if needed
207
- // (typically props are optional unless specified)
208
- }
209
-
210
- return jsonSchema;
211
- }
212
-
213
189
  export const nonConfigurablePropKeys = [ '_cssid', 'classes', 'attributes' ] as readonly string[];
214
190
 
215
- export function isPropKeyConfigurable( propKey: string ): boolean {
216
- return ! nonConfigurablePropKeys.includes( propKey );
191
+ export function isPropKeyConfigurable( propKey: string, propType?: PropType ): boolean {
192
+ if ( ! nonConfigurablePropKeys.includes( propKey ) ) {
193
+ return true;
194
+ }
195
+ return !! ( ! Array.isArray( propType?.meta ) && propType?.meta?.llm_configurable );
217
196
  }
218
197
 
219
198
  export function configurableKeys( schema: PropsSchema ): string[] {
220
- return Object.keys( schema ).filter( isPropKeyConfigurable );
199
+ return Object.keys( schema ).filter( ( key ) => isPropKeyConfigurable( key, schema[ key ] ) );
221
200
  }
222
201
 
223
202
  export function enrichWithIntention(