@elementor/editor-elements 0.4.2 → 0.5.1
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/CHANGELOG.md +26 -0
- package/dist/index.d.mts +30 -26
- package/dist/index.d.ts +30 -26
- package/dist/index.js +153 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +159 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/src/hooks/use-element-styles.ts +3 -6
- package/src/index.ts +5 -3
- package/src/styles/consts.ts +9 -0
- package/src/styles/create-element-style.ts +51 -0
- package/src/styles/errors.ts +11 -0
- package/src/styles/mutate-element-styles.ts +89 -0
- package/src/styles/update-element-style.ts +33 -0
- package/src/sync/types.ts +4 -1
- package/src/sync/update-element-settings.ts +26 -0
- package/src/hooks/use-element-style-props.ts +0 -54
- package/src/sync/update-settings.ts +0 -16
- package/src/sync/update-styles.ts +0 -28
package/src/sync/types.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type ExtendedWindow = Window & {
|
|
|
14
14
|
atomic_controls?: ControlItem[];
|
|
15
15
|
atomic_props_schema?: PropsSchema;
|
|
16
16
|
controls: object;
|
|
17
|
+
base_styles?: StyleDefinition[];
|
|
17
18
|
title: string;
|
|
18
19
|
}
|
|
19
20
|
>;
|
|
@@ -31,7 +32,7 @@ export type ExtendedWindow = Window & {
|
|
|
31
32
|
export type V1Element = {
|
|
32
33
|
id: string;
|
|
33
34
|
model: V1Model< V1ElementModelProps >;
|
|
34
|
-
settings
|
|
35
|
+
settings: V1Model< V1ElementSettingsProps >;
|
|
35
36
|
children?: V1Element[];
|
|
36
37
|
view?: {
|
|
37
38
|
el: HTMLElement;
|
|
@@ -50,4 +51,6 @@ export type V1ElementSettingsProps = Record< string, PropValue >;
|
|
|
50
51
|
|
|
51
52
|
type V1Model< T > = {
|
|
52
53
|
get: < K extends keyof T >( key: K ) => T[ K ];
|
|
54
|
+
set: < K extends keyof T >( key: K, value: T[ K ] ) => void;
|
|
55
|
+
toJSON: () => T;
|
|
53
56
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Props } from '@elementor/editor-props';
|
|
2
|
+
import { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';
|
|
3
|
+
|
|
4
|
+
import { type ElementID } from '../types';
|
|
5
|
+
import getContainer from './get-container';
|
|
6
|
+
|
|
7
|
+
export type UpdateElementSettingsArgs = {
|
|
8
|
+
id: ElementID;
|
|
9
|
+
props: Props;
|
|
10
|
+
withHistory?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const updateElementSettings = ( { id, props, withHistory = true }: UpdateElementSettingsArgs ) => {
|
|
14
|
+
const container = getContainer( id );
|
|
15
|
+
|
|
16
|
+
const args = {
|
|
17
|
+
container,
|
|
18
|
+
settings: { ...props },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
if ( withHistory ) {
|
|
22
|
+
runCommandSync( 'document/elements/settings', args );
|
|
23
|
+
} else {
|
|
24
|
+
runCommandSync( 'document/elements/set-settings', args, { internal: true } );
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { type Props } from '@elementor/editor-props';
|
|
2
|
-
import { type StyleDefinition, type StyleDefinitionID, type StyleVariant } from '@elementor/editor-styles';
|
|
3
|
-
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
4
|
-
|
|
5
|
-
import { getElementStyles } from '../sync/get-element-styles';
|
|
6
|
-
import { type ElementID } from '../types';
|
|
7
|
-
|
|
8
|
-
export type UseElementStylePropsArgs< T extends Props > = {
|
|
9
|
-
elementID: ElementID;
|
|
10
|
-
styleDefID: StyleDefinitionID | null;
|
|
11
|
-
meta: StyleVariant[ 'meta' ];
|
|
12
|
-
propNames: Array< keyof T & string >;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type NullableObjectValues< T extends Props > = {
|
|
16
|
-
[ K in keyof T ]: T[ K ] | null;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function useElementStyleProps< T extends Props >( {
|
|
20
|
-
elementID,
|
|
21
|
-
styleDefID,
|
|
22
|
-
meta,
|
|
23
|
-
propNames,
|
|
24
|
-
}: UseElementStylePropsArgs< T > ): NullableObjectValues< T > | null {
|
|
25
|
-
return useListenTo(
|
|
26
|
-
commandEndEvent( 'document/atomic-widgets/styles' ),
|
|
27
|
-
() => {
|
|
28
|
-
if ( ! styleDefID ) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const styleDef = getElementStyles( elementID )?.[ styleDefID ];
|
|
33
|
-
|
|
34
|
-
if ( ! styleDef ) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const variant = getVariantByMeta( styleDef, meta );
|
|
39
|
-
|
|
40
|
-
return propNames.reduce< Record< string, unknown > >( ( acc, key ) => {
|
|
41
|
-
acc[ key ] = variant?.props[ key ] ?? null;
|
|
42
|
-
|
|
43
|
-
return acc;
|
|
44
|
-
}, {} ) as NullableObjectValues< T >;
|
|
45
|
-
},
|
|
46
|
-
[ elementID, styleDefID, JSON.stringify( propNames ), meta ]
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getVariantByMeta( styleDef: StyleDefinition, meta: StyleVariant[ 'meta' ] ) {
|
|
51
|
-
return styleDef.variants.find( ( variant ) => {
|
|
52
|
-
return variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;
|
|
53
|
-
} );
|
|
54
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type Props } from '@elementor/editor-props';
|
|
2
|
-
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
3
|
-
|
|
4
|
-
import { type ElementID } from '../types';
|
|
5
|
-
import getContainer from './get-container';
|
|
6
|
-
|
|
7
|
-
export const updateSettings = ( { id, props }: { id: ElementID; props: Props } ) => {
|
|
8
|
-
const container = getContainer( id );
|
|
9
|
-
|
|
10
|
-
runCommand( 'document/elements/settings', {
|
|
11
|
-
container,
|
|
12
|
-
settings: {
|
|
13
|
-
...props,
|
|
14
|
-
},
|
|
15
|
-
} );
|
|
16
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type PropKey, type Props } from '@elementor/editor-props';
|
|
2
|
-
import { type StyleDefinitionID, type StyleVariant } from '@elementor/editor-styles';
|
|
3
|
-
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
4
|
-
|
|
5
|
-
import { type ElementID } from '../types';
|
|
6
|
-
import getContainer from './get-container';
|
|
7
|
-
|
|
8
|
-
export type UpdateStyleProps = {
|
|
9
|
-
elementID: ElementID;
|
|
10
|
-
styleDefID: StyleDefinitionID | null;
|
|
11
|
-
meta: StyleVariant[ 'meta' ];
|
|
12
|
-
props: Props;
|
|
13
|
-
bind: PropKey;
|
|
14
|
-
label?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const updateStyle = async ( { elementID, styleDefID, meta, props, bind, label }: UpdateStyleProps ) => {
|
|
18
|
-
const container = getContainer( elementID );
|
|
19
|
-
|
|
20
|
-
await runCommand( 'document/atomic-widgets/styles', {
|
|
21
|
-
container,
|
|
22
|
-
styleDefID,
|
|
23
|
-
bind,
|
|
24
|
-
meta,
|
|
25
|
-
props,
|
|
26
|
-
label,
|
|
27
|
-
} );
|
|
28
|
-
};
|