@elementor/editor-controls 4.4.0-1136 → 4.4.0-1137

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.4.0-1136",
4
+ "version": "4.4.0-1137",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,23 +40,23 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-current-user": "4.4.0-1136",
44
- "@elementor/editor-elements": "4.4.0-1136",
45
- "@elementor/editor-props": "4.4.0-1136",
46
- "@elementor/editor-responsive": "4.4.0-1136",
47
- "@elementor/editor-ui": "4.4.0-1136",
48
- "@elementor/editor-v1-adapters": "4.4.0-1136",
49
- "@elementor/env": "4.4.0-1136",
50
- "@elementor/events": "4.4.0-1136",
51
- "@elementor/http-client": "4.4.0-1136",
43
+ "@elementor/editor-current-user": "4.4.0-1137",
44
+ "@elementor/editor-elements": "4.4.0-1137",
45
+ "@elementor/editor-props": "4.4.0-1137",
46
+ "@elementor/editor-responsive": "4.4.0-1137",
47
+ "@elementor/editor-ui": "4.4.0-1137",
48
+ "@elementor/editor-v1-adapters": "4.4.0-1137",
49
+ "@elementor/env": "4.4.0-1137",
50
+ "@elementor/events": "4.4.0-1137",
51
+ "@elementor/http-client": "4.4.0-1137",
52
52
  "@elementor/icons": "~1.78.1",
53
- "@elementor/locations": "4.4.0-1136",
54
- "@elementor/query": "4.4.0-1136",
55
- "@elementor/schema": "4.4.0-1136",
56
- "@elementor/session": "4.4.0-1136",
53
+ "@elementor/locations": "4.4.0-1137",
54
+ "@elementor/query": "4.4.0-1137",
55
+ "@elementor/schema": "4.4.0-1137",
56
+ "@elementor/session": "4.4.0-1137",
57
57
  "@elementor/ui": "1.41.3",
58
- "@elementor/utils": "4.4.0-1136",
59
- "@elementor/wp-media": "4.4.0-1136",
58
+ "@elementor/utils": "4.4.0-1137",
59
+ "@elementor/wp-media": "4.4.0-1137",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "@tanstack/react-virtual": "^3.13.3",
62
62
  "@tiptap/extension-bold": "^3.11.1",
@@ -14,7 +14,6 @@ import { Box, CircularProgress, Divider, Link, Stack, styled, Typography } from
14
14
  import { useDebounceState } from '@elementor/utils';
15
15
  import { __ } from '@wordpress/i18n';
16
16
 
17
- import { useCustomIconLibraries } from './custom-icon-libraries';
18
17
  import {
19
18
  createIconSelectionValue,
20
19
  filterFontAwesome7Icons,
@@ -25,6 +24,7 @@ import {
25
24
  import { FontAwesomeGlyph } from './font-awesome-glyph';
26
25
  import { IconLibraryFilter } from './icon-library-filter';
27
26
  import { IconLibraryGrid } from './icon-library-grid';
27
+ import { useIconLibraryProviderIcons } from './icon-library-providers';
28
28
  import { type IconLibraryView, IconLibraryViewToggle } from './icon-library-view-toggle';
29
29
  import { SvgElementIcon } from './svg-element-icon';
30
30
  import { useFontAwesome7Catalog } from './use-font-awesome-7-catalog';
@@ -85,9 +85,9 @@ export const IconLibraryPopover = ( {
85
85
  );
86
86
  const view = isIconLibraryView( storedView ) ? storedView : DEFAULT_ICON_LIBRARY_VIEW;
87
87
  const { data: fontAwesomeIcons = [], isLoading: isFontAwesomeLoading } = useFontAwesome7Catalog( open );
88
- const { data: customIcons = [], isLoading: isCustomLoading } = useCustomIconLibraries( open );
89
- const isLoading = isFontAwesomeLoading || isCustomLoading;
90
- const icons = useMemo( () => [ ...fontAwesomeIcons, ...customIcons ], [ customIcons, fontAwesomeIcons ] );
88
+ const { data: providerIcons = [], isLoading: isProviderLoading } = useIconLibraryProviderIcons( open );
89
+ const isLoading = isFontAwesomeLoading || isProviderLoading;
90
+ const icons = useMemo( () => [ ...fontAwesomeIcons, ...providerIcons ], [ providerIcons, fontAwesomeIcons ] );
91
91
 
92
92
  const items = useMemo(
93
93
  () => createIconLibraryItems( icons, searchValue, activeLibraries ),
@@ -0,0 +1,61 @@
1
+ import { useState } from 'react';
2
+
3
+ import { type FontAwesome7Icon } from './font-awesome-7-catalog';
4
+
5
+ export type IconLibraryProviderState = {
6
+ data?: FontAwesome7Icon[];
7
+ isLoading: boolean;
8
+ };
9
+
10
+ export type IconLibraryProvider = {
11
+ id: string;
12
+ useIcons: ( enabled: boolean ) => IconLibraryProviderState;
13
+ resolveSvg?: ( library: string, iconValue: string, signal?: AbortSignal ) => Promise< string | null >;
14
+ };
15
+
16
+ const providers = new Map< string, IconLibraryProvider >();
17
+
18
+ /**
19
+ * Register before the icon picker mounts. Each picker instance snapshots the providers on mount,
20
+ * so its hook count stays constant; a provider registered later appears on the next mount.
21
+ * @param provider
22
+ */
23
+ export function registerIconLibraryProvider( provider: IconLibraryProvider ) {
24
+ providers.set( provider.id, provider );
25
+ }
26
+
27
+ export function unregisterIconLibraryProvider( id: string ) {
28
+ providers.delete( id );
29
+ }
30
+
31
+ export function useIconLibraryProviderIcons( enabled: boolean ): Required< IconLibraryProviderState > {
32
+ const [ snapshot ] = useState( () => [ ...providers.values() ] );
33
+ const states = snapshot.map( ( provider ) => provider.useIcons( enabled ) );
34
+
35
+ return {
36
+ data: states.flatMap( ( state ) => state.data ?? [] ),
37
+ isLoading: states.some( ( state ) => state.isLoading ),
38
+ };
39
+ }
40
+
41
+ export async function resolveProviderIconSvg(
42
+ library: string,
43
+ iconValue: string,
44
+ signal?: AbortSignal
45
+ ): Promise< string | null > {
46
+ for ( const provider of providers.values() ) {
47
+ try {
48
+ const markup = await provider.resolveSvg?.( library, iconValue, signal );
49
+
50
+ if ( markup ) {
51
+ return markup;
52
+ }
53
+ } catch ( error ) {
54
+ if ( signal?.aborted ) {
55
+ throw error;
56
+ }
57
+ }
58
+ }
59
+
60
+ return null;
61
+ }
@@ -2,9 +2,9 @@ import * as React from 'react';
2
2
  import { Box, CardMedia, CircularProgress } from '@elementor/ui';
3
3
  import { __ } from '@wordpress/i18n';
4
4
 
5
- import { useCustomIconLibraries } from './icon-library/custom-icon-libraries';
6
5
  import { findFontAwesome7Icon, type FontAwesome7Icon } from './icon-library/font-awesome-7-catalog';
7
6
  import { FontAwesomeGlyph } from './icon-library/font-awesome-glyph';
7
+ import { useIconLibraryProviderIcons } from './icon-library/icon-library-providers';
8
8
  import { useFontAwesome7Catalog } from './icon-library/use-font-awesome-7-catalog';
9
9
 
10
10
  const ICON_PREVIEW_SIZE = 50;
@@ -21,10 +21,11 @@ export const SvgMediaPreview = ( { isFetching, src, iconClassName, iconLibrary }
21
21
  const shouldLoadIconCatalog = Boolean( iconClassName && iconLibrary );
22
22
  const { data: fontAwesomeIcons = [], isLoading: isFontAwesomeLoading } =
23
23
  useFontAwesome7Catalog( shouldLoadIconCatalog );
24
- const { data: customIcons = [], isLoading: isCustomLoading } = useCustomIconLibraries( shouldLoadIconCatalog );
25
- const icons = [ ...fontAwesomeIcons, ...customIcons ];
24
+ const { data: providerIcons = [], isLoading: isProviderLoading } =
25
+ useIconLibraryProviderIcons( shouldLoadIconCatalog );
26
+ const icons = [ ...fontAwesomeIcons, ...providerIcons ];
26
27
  const selectedIcon = findFontAwesome7Icon( icons, iconClassName, iconLibrary );
27
- const isLoadingCatalog = shouldLoadIconCatalog && ( isFontAwesomeLoading || isCustomLoading );
28
+ const isLoadingCatalog = shouldLoadIconCatalog && ( isFontAwesomeLoading || isProviderLoading );
28
29
 
29
30
  if ( isFetching || isLoadingCatalog ) {
30
31
  return <CircularProgress role="progressbar" />;
package/src/index.ts CHANGED
@@ -37,7 +37,14 @@ export { TransformSettingsControl } from './controls/transform-control/transform
37
37
  export { TransitionRepeaterControl } from './controls/transition-control/transition-repeater-control';
38
38
  export { PopoverContent } from './components/popover-content';
39
39
  export { enqueueFont } from './controls/font-family-control/enqueue-font';
40
- export { isDeletedCustomIconLibrary, resolveCustomIconSvg } from './controls/icon-library/custom-icon-libraries';
40
+ export {
41
+ registerIconLibraryProvider,
42
+ resolveProviderIconSvg,
43
+ unregisterIconLibraryProvider,
44
+ type IconLibraryProvider,
45
+ } from './controls/icon-library/icon-library-providers';
46
+ export { enqueueIconFonts } from './controls/open-icon-library';
47
+ export { type FontAwesome7Icon } from './controls/icon-library/font-awesome-7-catalog';
41
48
  export {
42
49
  getFontAwesome7IconName,
43
50
  resetFontAwesome7IconsCache,