@elementor/editor-controls 4.0.0-510 → 4.0.0-512
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 +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +48 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/control-replacements.tsx +2 -0
- package/src/hooks/use-font-families.ts +52 -0
- package/src/index.ts +3 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-controls",
|
|
3
3
|
"description": "This package contains the controls model and utils for the Elementor editor",
|
|
4
|
-
"version": "4.0.0-
|
|
4
|
+
"version": "4.0.0-512",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,22 +40,22 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-current-user": "4.0.0-
|
|
44
|
-
"@elementor/editor-elements": "4.0.0-
|
|
45
|
-
"@elementor/editor-props": "4.0.0-
|
|
46
|
-
"@elementor/editor-responsive": "4.0.0-
|
|
47
|
-
"@elementor/editor-ui": "4.0.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "4.0.0-
|
|
49
|
-
"@elementor/env": "4.0.0-
|
|
50
|
-
"@elementor/http-client": "4.0.0-
|
|
43
|
+
"@elementor/editor-current-user": "4.0.0-512",
|
|
44
|
+
"@elementor/editor-elements": "4.0.0-512",
|
|
45
|
+
"@elementor/editor-props": "4.0.0-512",
|
|
46
|
+
"@elementor/editor-responsive": "4.0.0-512",
|
|
47
|
+
"@elementor/editor-ui": "4.0.0-512",
|
|
48
|
+
"@elementor/editor-v1-adapters": "4.0.0-512",
|
|
49
|
+
"@elementor/env": "4.0.0-512",
|
|
50
|
+
"@elementor/http-client": "4.0.0-512",
|
|
51
51
|
"@elementor/icons": "^1.63.0",
|
|
52
|
-
"@elementor/locations": "4.0.0-
|
|
53
|
-
"@elementor/mixpanel": "4.0.0-
|
|
54
|
-
"@elementor/query": "4.0.0-
|
|
55
|
-
"@elementor/session": "4.0.0-
|
|
52
|
+
"@elementor/locations": "4.0.0-512",
|
|
53
|
+
"@elementor/mixpanel": "4.0.0-512",
|
|
54
|
+
"@elementor/query": "4.0.0-512",
|
|
55
|
+
"@elementor/session": "4.0.0-512",
|
|
56
56
|
"@elementor/ui": "1.36.17",
|
|
57
|
-
"@elementor/utils": "4.0.0-
|
|
58
|
-
"@elementor/wp-media": "4.0.0-
|
|
57
|
+
"@elementor/utils": "4.0.0-512",
|
|
58
|
+
"@elementor/wp-media": "4.0.0-512",
|
|
59
59
|
"@wordpress/i18n": "^5.13.0",
|
|
60
60
|
"@monaco-editor/react": "^4.7.0",
|
|
61
61
|
"dayjs": "^1.11.18",
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { getElementorConfig, type SupportedFonts } from '@elementor/editor-v1-adapters';
|
|
3
|
+
import { __ } from '@wordpress/i18n';
|
|
4
|
+
|
|
5
|
+
import { type FontCategory } from '../controls/font-family-control/font-family-control';
|
|
6
|
+
|
|
7
|
+
const supportedCategories: Record< SupportedFonts, string > = {
|
|
8
|
+
system: __( 'System', 'elementor' ),
|
|
9
|
+
custom: __( 'Custom Fonts', 'elementor' ),
|
|
10
|
+
googlefonts: __( 'Google Fonts', 'elementor' ),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const getFontFamilies = () => {
|
|
14
|
+
const { controls } = getElementorConfig();
|
|
15
|
+
|
|
16
|
+
const options = controls?.font?.options;
|
|
17
|
+
|
|
18
|
+
if ( ! options ) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return options;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const useFontFamilies = () => {
|
|
26
|
+
const fontFamilies = getFontFamilies();
|
|
27
|
+
|
|
28
|
+
return useMemo( () => {
|
|
29
|
+
const categoriesOrder: SupportedFonts[] = [ 'system', 'custom', 'googlefonts' ];
|
|
30
|
+
|
|
31
|
+
return Object.entries( fontFamilies || {} )
|
|
32
|
+
.reduce< FontCategory[] >( ( acc, [ font, category ] ) => {
|
|
33
|
+
if ( ! supportedCategories[ category as SupportedFonts ] ) {
|
|
34
|
+
return acc;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const categoryIndex = categoriesOrder.indexOf( category );
|
|
38
|
+
|
|
39
|
+
if ( ! acc[ categoryIndex ] ) {
|
|
40
|
+
acc[ categoryIndex ] = {
|
|
41
|
+
label: supportedCategories[ category as SupportedFonts ],
|
|
42
|
+
fonts: [],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
acc[ categoryIndex ].fonts.push( font );
|
|
47
|
+
|
|
48
|
+
return acc;
|
|
49
|
+
}, [] )
|
|
50
|
+
.filter( Boolean );
|
|
51
|
+
}, [ fontFamilies ] );
|
|
52
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -67,6 +67,8 @@ export type { FontCategory } from './controls/font-family-control/font-family-co
|
|
|
67
67
|
// providers
|
|
68
68
|
export {
|
|
69
69
|
createControlReplacementsRegistry,
|
|
70
|
+
registerControlReplacement,
|
|
71
|
+
getControlReplacements,
|
|
70
72
|
ControlReplacementsProvider,
|
|
71
73
|
useControlReplacement,
|
|
72
74
|
type ControlReplacement,
|
|
@@ -86,3 +88,4 @@ export {
|
|
|
86
88
|
// hooks
|
|
87
89
|
export { useSyncExternalState } from './hooks/use-sync-external-state';
|
|
88
90
|
export { useElementCanHaveChildren } from './hooks/use-element-can-have-children';
|
|
91
|
+
export { useFontFamilies } from './hooks/use-font-families';
|