@elementor/editor-props 0.2.0 → 0.4.0
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 +17 -0
- package/dist/index.d.mts +943 -1931
- package/dist/index.d.ts +943 -1931
- package/dist/index.js +160 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +143 -91
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/prop-types/background-image.ts +11 -0
- package/src/prop-types/border-radius.ts +9 -7
- package/src/prop-types/border-width.ts +9 -7
- package/src/prop-types/box-shadow.ts +4 -3
- package/src/prop-types/classes.ts +4 -3
- package/src/prop-types/color-gradient.ts +13 -0
- package/src/prop-types/color.ts +3 -2
- package/src/prop-types/image-attachment-id.ts +1 -0
- package/src/prop-types/image-src.ts +8 -8
- package/src/prop-types/image.ts +7 -7
- package/src/prop-types/index.ts +5 -0
- package/src/prop-types/link.ts +15 -0
- package/src/prop-types/linked-dimensions.ts +10 -8
- package/src/prop-types/number.ts +7 -0
- package/src/prop-types/shadow.ts +11 -11
- package/src/prop-types/size.ts +4 -3
- package/src/prop-types/string.ts +7 -0
- package/src/prop-types/stroke.ts +7 -7
- package/src/prop-types/url.ts +3 -2
- package/src/prop-types/utils.ts +3 -0
- package/src/utils/create-prop-utils.ts +42 -10
package/src/prop-types/shadow.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { z } from '@elementor/schema';
|
|
2
|
+
|
|
2
3
|
import { createPropUtils } from '../utils/create-prop-utils';
|
|
3
|
-
import {
|
|
4
|
-
import { colorPropType } from './color';
|
|
4
|
+
import { unknownChildrenSchema } from './utils';
|
|
5
5
|
|
|
6
|
-
export const
|
|
6
|
+
export const shadowPropTypeUtil = createPropUtils(
|
|
7
7
|
'shadow',
|
|
8
|
-
z.
|
|
9
|
-
position:
|
|
10
|
-
hOffset:
|
|
11
|
-
vOffset:
|
|
12
|
-
blur:
|
|
13
|
-
spread:
|
|
14
|
-
color:
|
|
8
|
+
z.strictObject( {
|
|
9
|
+
position: unknownChildrenSchema,
|
|
10
|
+
hOffset: unknownChildrenSchema,
|
|
11
|
+
vOffset: unknownChildrenSchema,
|
|
12
|
+
blur: unknownChildrenSchema,
|
|
13
|
+
spread: unknownChildrenSchema,
|
|
14
|
+
color: unknownChildrenSchema,
|
|
15
15
|
} )
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
export type ShadowPropValue = z.infer< typeof
|
|
18
|
+
export type ShadowPropValue = z.infer< typeof shadowPropTypeUtil.schema >;
|
package/src/prop-types/size.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { z } from '@elementor/schema';
|
|
2
|
+
|
|
2
3
|
import { createPropUtils } from '../utils/create-prop-utils';
|
|
3
4
|
|
|
4
|
-
export const
|
|
5
|
+
export const sizePropTypeUtil = createPropUtils(
|
|
5
6
|
'size',
|
|
6
|
-
z.
|
|
7
|
+
z.strictObject( {
|
|
7
8
|
unit: z.enum( [ 'px', 'em', 'rem', '%', 'vw', 'vh' ] ),
|
|
8
9
|
size: z.number(),
|
|
9
10
|
} )
|
|
10
11
|
);
|
|
11
12
|
|
|
12
|
-
export type SizePropValue = z.infer< typeof
|
|
13
|
+
export type SizePropValue = z.infer< typeof sizePropTypeUtil.schema >;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from '@elementor/schema';
|
|
2
|
+
|
|
3
|
+
import { createPropUtils } from '../utils/create-prop-utils';
|
|
4
|
+
|
|
5
|
+
export const stringPropTypeUtil = createPropUtils( 'string', z.string().nullable() );
|
|
6
|
+
|
|
7
|
+
export type StringPropValue = z.infer< typeof stringPropTypeUtil.schema >;
|
package/src/prop-types/stroke.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { z } from '@elementor/schema';
|
|
2
|
+
|
|
2
3
|
import { createPropUtils } from '../utils/create-prop-utils';
|
|
3
|
-
import {
|
|
4
|
-
import { sizePropType } from './size';
|
|
4
|
+
import { unknownChildrenSchema } from './utils';
|
|
5
5
|
|
|
6
|
-
export const
|
|
6
|
+
export const strokePropTypeUtil = createPropUtils(
|
|
7
7
|
'stroke',
|
|
8
|
-
z.
|
|
9
|
-
color:
|
|
10
|
-
width:
|
|
8
|
+
z.strictObject( {
|
|
9
|
+
color: unknownChildrenSchema,
|
|
10
|
+
width: unknownChildrenSchema,
|
|
11
11
|
} )
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
export type StrokePropValue = z.infer< typeof
|
|
14
|
+
export type StrokePropValue = z.infer< typeof strokePropTypeUtil.schema >;
|
package/src/prop-types/url.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from '@elementor/schema';
|
|
2
|
+
|
|
2
3
|
import { createPropUtils } from '../utils/create-prop-utils';
|
|
3
4
|
|
|
4
|
-
export const
|
|
5
|
+
export const urlPropTypeUtil = createPropUtils( 'url', z.string().url().nullable() );
|
|
5
6
|
|
|
6
|
-
export type UrlPropValue = z.infer< typeof
|
|
7
|
+
export type UrlPropValue = z.infer< typeof urlPropTypeUtil.schema >;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { z, type ZodTypeAny } from '@elementor/schema';
|
|
1
|
+
import { z, type ZodType, type ZodTypeAny } from '@elementor/schema';
|
|
2
|
+
|
|
3
|
+
import { type PropValue } from '../types';
|
|
2
4
|
|
|
3
5
|
type Updater< T > = ( prev?: T ) => T;
|
|
4
6
|
|
|
7
|
+
export type CreateOptions = {
|
|
8
|
+
base?: unknown;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
5
12
|
/**
|
|
6
13
|
* Usage example:
|
|
7
14
|
*
|
|
@@ -10,32 +17,46 @@ type Updater< T > = ( prev?: T ) => T;
|
|
|
10
17
|
*
|
|
11
18
|
* elementsPropUtils.isValid( element.props?.children );
|
|
12
19
|
* elementsPropUtils.create( [ 'a', 'b' ] );
|
|
13
|
-
* elementsPropUtils.create( ( prev = [] ) => [ ...prev, 'c' ], element.props?.children );
|
|
20
|
+
* elementsPropUtils.create( ( prev = [] ) => [ ...prev, 'c' ], { base: element.props?.children } );
|
|
21
|
+
* elementsPropUtils.create( ( prev = [] ) => [ ...prev, 'c' ], { disabled: true } );
|
|
22
|
+
* elementsPropUtils.extract( element.props?.children );
|
|
23
|
+
*
|
|
14
24
|
* ```
|
|
15
25
|
*/
|
|
16
26
|
|
|
27
|
+
export type PropTypeUtil< TKey extends string, TValue extends PropValue > = ReturnType<
|
|
28
|
+
typeof createPropUtils< TKey, ZodType< TValue > >
|
|
29
|
+
>;
|
|
30
|
+
|
|
17
31
|
export function createPropUtils< TKey extends string, TValue extends ZodTypeAny >( key: TKey, valueSchema: TValue ) {
|
|
18
|
-
const schema = z.
|
|
32
|
+
const schema = z.strictObject( {
|
|
19
33
|
$$type: z.literal( key ),
|
|
20
34
|
value: valueSchema,
|
|
35
|
+
disabled: z.boolean().optional(),
|
|
21
36
|
} );
|
|
22
37
|
|
|
23
38
|
type Prop = z.infer< typeof schema >;
|
|
24
39
|
|
|
40
|
+
type TPropValue = z.infer< typeof valueSchema >;
|
|
41
|
+
|
|
25
42
|
function isValid( prop: unknown ): prop is Prop {
|
|
26
43
|
return schema.safeParse( prop ).success;
|
|
27
44
|
}
|
|
28
45
|
|
|
29
|
-
function create( value:
|
|
30
|
-
function create( value:
|
|
31
|
-
function create( value:
|
|
32
|
-
|
|
46
|
+
function create( value: TPropValue ): Prop;
|
|
47
|
+
function create( value: TPropValue, createOptions?: CreateOptions ): Prop;
|
|
48
|
+
function create( value: Updater< TPropValue >, createOptions: CreateOptions ): Prop;
|
|
49
|
+
function create( value: TPropValue | Updater< TPropValue >, createOptions?: CreateOptions ): Prop {
|
|
50
|
+
const fn = ( typeof value === 'function' ? value : () => value ) as Updater< TPropValue >;
|
|
51
|
+
|
|
52
|
+
const { base, disabled } = createOptions || {};
|
|
33
53
|
|
|
34
54
|
if ( ! base ) {
|
|
35
55
|
return {
|
|
36
56
|
$$type: key,
|
|
37
57
|
value: fn(),
|
|
38
|
-
|
|
58
|
+
...( disabled && { disabled } ),
|
|
59
|
+
} as Prop;
|
|
39
60
|
}
|
|
40
61
|
|
|
41
62
|
if ( ! isValid( base ) ) {
|
|
@@ -45,12 +66,23 @@ export function createPropUtils< TKey extends string, TValue extends ZodTypeAny
|
|
|
45
66
|
return {
|
|
46
67
|
$$type: key,
|
|
47
68
|
value: fn( base.value ),
|
|
48
|
-
|
|
69
|
+
...( disabled && { disabled } ),
|
|
70
|
+
} as Prop;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function extract( prop: unknown ): TPropValue | null {
|
|
74
|
+
if ( ! isValid( prop ) ) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return prop.value;
|
|
49
79
|
}
|
|
50
80
|
|
|
51
81
|
return {
|
|
82
|
+
extract,
|
|
52
83
|
isValid,
|
|
53
84
|
create,
|
|
54
|
-
schema
|
|
85
|
+
// this type fails in build due to zod issue that does not recognize the schema as a ZodType.
|
|
86
|
+
schema: schema as ZodType< Prop >,
|
|
55
87
|
};
|
|
56
88
|
}
|