@elementor/editor-elements 4.5.0-1172 → 4.5.0-1174
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 +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +72 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +2 -0
- package/src/sync/get-element-widget-markers.ts +33 -0
- package/src/sync/regenerate-local-style-ids.ts +55 -0
- package/src/sync/types.ts +8 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from '@elementor/schema';
|
|
2
|
+
|
|
3
|
+
import { type ElementID } from '../types';
|
|
4
|
+
import { getContainer } from './get-container';
|
|
5
|
+
import { type V1ElementWidgetMarker } from './types';
|
|
6
|
+
|
|
7
|
+
const WIDGET_ID_PATTERN = /^[a-z0-9-]+\/[a-z0-9-]+$/;
|
|
8
|
+
const PART_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
9
|
+
const MIN_VERSION = 1;
|
|
10
|
+
|
|
11
|
+
const widgetMarkerSchema = z.object( {
|
|
12
|
+
id: z.string().regex( WIDGET_ID_PATTERN ),
|
|
13
|
+
version: z.number().int().min( MIN_VERSION ),
|
|
14
|
+
values: z.record( z.unknown() ).optional(),
|
|
15
|
+
} );
|
|
16
|
+
|
|
17
|
+
const partSchema = z.string().regex( PART_PATTERN );
|
|
18
|
+
|
|
19
|
+
export function getElementWidgetMarker( elementId: ElementID ): Required< V1ElementWidgetMarker > | null {
|
|
20
|
+
const result = widgetMarkerSchema.safeParse( getContainer( elementId )?.model.get( 'widget' ) );
|
|
21
|
+
|
|
22
|
+
if ( ! result.success ) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { ...result.data, values: result.data.values ?? {} };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getElementPart( elementId: ElementID ): string | null {
|
|
30
|
+
const result = partSchema.safeParse( getContainer( elementId )?.model.get( 'part' ) );
|
|
31
|
+
|
|
32
|
+
return result.success ? result.data : null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { classesPropTypeUtil, type ClassesPropValue, type PropValue } from '@elementor/editor-props';
|
|
2
|
+
import { type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';
|
|
3
|
+
|
|
4
|
+
import { generateElementId } from './generate-element-id';
|
|
5
|
+
import { type V1ElementData, type V1ElementSettingsProps } from './types';
|
|
6
|
+
|
|
7
|
+
// Ts version for atomic-widgets/assets/js/editor/utils/regenerate-local-style-ids.js
|
|
8
|
+
export function regenerateLocalStyleIds( element: V1ElementData ): {
|
|
9
|
+
styles: Record< StyleDefinitionID, StyleDefinition > | undefined;
|
|
10
|
+
settings: V1ElementSettingsProps | undefined;
|
|
11
|
+
} {
|
|
12
|
+
const originalStyles = element.styles;
|
|
13
|
+
|
|
14
|
+
if ( ! originalStyles || Object.keys( originalStyles ).length === 0 ) {
|
|
15
|
+
return { styles: undefined, settings: undefined };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const newStyles: Record< string, StyleDefinition > = {};
|
|
19
|
+
const styleIdMapping: Record< string, string > = {};
|
|
20
|
+
|
|
21
|
+
for ( const [ originalStyleId, style ] of Object.entries( originalStyles ) ) {
|
|
22
|
+
const newStyleId = generateLocalStyleId( element.id );
|
|
23
|
+
|
|
24
|
+
newStyles[ newStyleId ] = { ...style, id: newStyleId };
|
|
25
|
+
styleIdMapping[ originalStyleId ] = newStyleId;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const settings = element.settings;
|
|
29
|
+
if ( ! settings || Object.keys( settings ).length === 0 ) {
|
|
30
|
+
return { styles: newStyles, settings: undefined };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const updatedSettings = { ...settings };
|
|
34
|
+
|
|
35
|
+
for ( const [ propKey, propValue ] of Object.entries( updatedSettings ) ) {
|
|
36
|
+
if ( isClassesProp( propValue ) && propValue.value.length > 0 ) {
|
|
37
|
+
const updatedClasses = propValue.value.map( ( classId ) => styleIdMapping[ classId ] ?? classId );
|
|
38
|
+
|
|
39
|
+
updatedSettings[ propKey ] = classesPropTypeUtil.create( updatedClasses );
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
styles: newStyles,
|
|
45
|
+
settings: updatedSettings,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isClassesProp( prop: PropValue ): prop is ClassesPropValue {
|
|
50
|
+
return classesPropTypeUtil.isValid( prop );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function generateLocalStyleId( elementId: string ): string {
|
|
54
|
+
return `e-${ elementId }-${ generateElementId() }`;
|
|
55
|
+
}
|
package/src/sync/types.ts
CHANGED
|
@@ -174,6 +174,14 @@ export type V1ElementModelProps = {
|
|
|
174
174
|
isGlobal?: boolean;
|
|
175
175
|
skipDefaultChildren?: boolean;
|
|
176
176
|
hydrateDefaultChildren?: boolean;
|
|
177
|
+
widget?: V1ElementWidgetMarker;
|
|
178
|
+
part?: string;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export type V1ElementWidgetMarker = {
|
|
182
|
+
id: string;
|
|
183
|
+
version: number;
|
|
184
|
+
values?: Record< string, unknown >;
|
|
177
185
|
};
|
|
178
186
|
|
|
179
187
|
export type V1ElementData = Omit< V1ElementModelProps, 'elements' > & {
|