@elementor/editor-controls 4.0.0-669 → 4.0.0-671

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/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-669",
4
+ "version": "4.0.0-671",
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-669",
44
- "@elementor/editor-elements": "4.0.0-669",
45
- "@elementor/editor-props": "4.0.0-669",
46
- "@elementor/editor-responsive": "4.0.0-669",
47
- "@elementor/editor-ui": "4.0.0-669",
48
- "@elementor/editor-v1-adapters": "4.0.0-669",
49
- "@elementor/env": "4.0.0-669",
50
- "@elementor/http-client": "4.0.0-669",
43
+ "@elementor/editor-current-user": "4.0.0-671",
44
+ "@elementor/editor-elements": "4.0.0-671",
45
+ "@elementor/editor-props": "4.0.0-671",
46
+ "@elementor/editor-responsive": "4.0.0-671",
47
+ "@elementor/editor-ui": "4.0.0-671",
48
+ "@elementor/editor-v1-adapters": "4.0.0-671",
49
+ "@elementor/env": "4.0.0-671",
50
+ "@elementor/http-client": "4.0.0-671",
51
51
  "@elementor/icons": "^1.68.0",
52
- "@elementor/locations": "4.0.0-669",
53
- "@elementor/events": "4.0.0-669",
54
- "@elementor/query": "4.0.0-669",
55
- "@elementor/session": "4.0.0-669",
52
+ "@elementor/locations": "4.0.0-671",
53
+ "@elementor/events": "4.0.0-671",
54
+ "@elementor/query": "4.0.0-671",
55
+ "@elementor/session": "4.0.0-671",
56
56
  "@elementor/ui": "1.36.17",
57
- "@elementor/utils": "4.0.0-669",
58
- "@elementor/wp-media": "4.0.0-669",
57
+ "@elementor/utils": "4.0.0-671",
58
+ "@elementor/wp-media": "4.0.0-671",
59
59
  "@wordpress/i18n": "^5.13.0",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "dayjs": "^1.11.18",
@@ -1,52 +1,49 @@
1
1
  import { useMemo } from 'react';
2
- import { getElementorConfig, type SupportedFonts } from '@elementor/editor-v1-adapters';
3
- import { __ } from '@wordpress/i18n';
2
+ import { getElementorConfig } from '@elementor/editor-v1-adapters';
4
3
 
5
4
  import { type FontCategory } from '../controls/font-family-control/font-family-control';
6
5
 
7
- const supportedCategories: Record< SupportedFonts, string > = {
8
- system: __( 'System', 'elementor' ),
9
- custom: __( 'Custom Fonts', 'elementor' ),
10
- googlefonts: __( 'Google Fonts', 'elementor' ),
6
+ type FontControlConfig = {
7
+ groups?: Record< string, string >;
8
+ options?: Record< string, string >;
11
9
  };
12
10
 
13
- const getFontFamilies = () => {
11
+ const getFontControlConfig = (): FontControlConfig => {
14
12
  const { controls } = getElementorConfig();
15
13
 
16
- const options = controls?.font?.options;
17
-
18
- if ( ! options ) {
19
- return null;
20
- }
21
-
22
- return options;
14
+ return controls?.font ?? {};
23
15
  };
24
16
 
25
17
  export const useFontFamilies = () => {
26
- const fontFamilies = getFontFamilies();
18
+ const { groups, options } = getFontControlConfig();
27
19
 
28
20
  return useMemo( () => {
29
- const categoriesOrder: SupportedFonts[] = [ 'system', 'custom', 'googlefonts' ];
21
+ if ( ! groups || ! options ) {
22
+ return [];
23
+ }
24
+
25
+ const groupKeys = Object.keys( groups );
26
+ const groupIndexMap = new Map( groupKeys.map( ( key, index ) => [ key, index ] ) );
30
27
 
31
- return Object.entries( fontFamilies || {} )
28
+ return Object.entries( options )
32
29
  .reduce< FontCategory[] >( ( acc, [ font, category ] ) => {
33
- if ( ! supportedCategories[ category as SupportedFonts ] ) {
30
+ const groupIndex = groupIndexMap.get( category );
31
+
32
+ if ( groupIndex === undefined ) {
34
33
  return acc;
35
34
  }
36
35
 
37
- const categoryIndex = categoriesOrder.indexOf( category );
38
-
39
- if ( ! acc[ categoryIndex ] ) {
40
- acc[ categoryIndex ] = {
41
- label: supportedCategories[ category as SupportedFonts ],
36
+ if ( ! acc[ groupIndex ] ) {
37
+ acc[ groupIndex ] = {
38
+ label: groups[ category ],
42
39
  fonts: [],
43
40
  };
44
41
  }
45
42
 
46
- acc[ categoryIndex ].fonts.push( font );
43
+ acc[ groupIndex ].fonts.push( font );
47
44
 
48
45
  return acc;
49
46
  }, [] )
50
47
  .filter( Boolean );
51
- }, [ fontFamilies ] );
48
+ }, [ groups, options ] );
52
49
  };