@elementor/editor-controls 4.4.0-1142 → 4.4.0-1143

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-1142",
4
+ "version": "4.4.0-1143",
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-1142",
44
- "@elementor/editor-elements": "4.4.0-1142",
45
- "@elementor/editor-props": "4.4.0-1142",
46
- "@elementor/editor-responsive": "4.4.0-1142",
47
- "@elementor/editor-ui": "4.4.0-1142",
48
- "@elementor/editor-v1-adapters": "4.4.0-1142",
49
- "@elementor/env": "4.4.0-1142",
50
- "@elementor/events": "4.4.0-1142",
51
- "@elementor/http-client": "4.4.0-1142",
43
+ "@elementor/editor-current-user": "4.4.0-1143",
44
+ "@elementor/editor-elements": "4.4.0-1143",
45
+ "@elementor/editor-props": "4.4.0-1143",
46
+ "@elementor/editor-responsive": "4.4.0-1143",
47
+ "@elementor/editor-ui": "4.4.0-1143",
48
+ "@elementor/editor-v1-adapters": "4.4.0-1143",
49
+ "@elementor/env": "4.4.0-1143",
50
+ "@elementor/events": "4.4.0-1143",
51
+ "@elementor/http-client": "4.4.0-1143",
52
52
  "@elementor/icons": "~1.78.1",
53
- "@elementor/locations": "4.4.0-1142",
54
- "@elementor/query": "4.4.0-1142",
55
- "@elementor/schema": "4.4.0-1142",
56
- "@elementor/session": "4.4.0-1142",
53
+ "@elementor/locations": "4.4.0-1143",
54
+ "@elementor/query": "4.4.0-1143",
55
+ "@elementor/schema": "4.4.0-1143",
56
+ "@elementor/session": "4.4.0-1143",
57
57
  "@elementor/ui": "1.41.4",
58
- "@elementor/utils": "4.4.0-1142",
59
- "@elementor/wp-media": "4.4.0-1142",
58
+ "@elementor/utils": "4.4.0-1143",
59
+ "@elementor/wp-media": "4.4.0-1143",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "@tanstack/react-virtual": "^3.13.3",
62
62
  "@tiptap/extension-bold": "^3.11.1",
@@ -1,4 +1,5 @@
1
1
  import { useState } from 'react';
2
+ import { useQuery } from '@elementor/query';
2
3
 
3
4
  import { type FontAwesome7Icon } from './font-awesome-7-catalog';
4
5
 
@@ -13,6 +14,8 @@ export type IconLibraryProvider = {
13
14
  resolveSvg?: ( library: string, iconValue: string, signal?: AbortSignal ) => Promise< string | null >;
14
15
  };
15
16
 
17
+ const PROVIDER_ICON_SVG_QUERY_KEY = 'icon-library-provider-svg';
18
+
16
19
  const providers = new Map< string, IconLibraryProvider >();
17
20
 
18
21
  /**
@@ -59,3 +62,12 @@ export async function resolveProviderIconSvg(
59
62
 
60
63
  return null;
61
64
  }
65
+
66
+ export function useProviderIconSvg( library: string | null, iconValue: string | null, enabled: boolean ) {
67
+ return useQuery< string | null >( {
68
+ queryKey: [ PROVIDER_ICON_SVG_QUERY_KEY, library, iconValue ],
69
+ queryFn: ( { signal } ) => resolveProviderIconSvg( library as string, iconValue as string, signal ),
70
+ enabled: enabled && Boolean( library && iconValue ),
71
+ staleTime: Infinity,
72
+ } );
73
+ }
@@ -4,7 +4,7 @@ import { __ } from '@wordpress/i18n';
4
4
 
5
5
  import { findFontAwesome7Icon, type FontAwesome7Icon } from './icon-library/font-awesome-7-catalog';
6
6
  import { FontAwesomeGlyph } from './icon-library/font-awesome-glyph';
7
- import { useIconLibraryProviderIcons } from './icon-library/icon-library-providers';
7
+ import { useIconLibraryProviderIcons, useProviderIconSvg } 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;
@@ -26,8 +26,13 @@ export const SvgMediaPreview = ( { isFetching, src, iconClassName, iconLibrary }
26
26
  const icons = [ ...fontAwesomeIcons, ...providerIcons ];
27
27
  const selectedIcon = findFontAwesome7Icon( icons, iconClassName, iconLibrary );
28
28
  const isLoadingCatalog = shouldLoadIconCatalog && ( isFontAwesomeLoading || isProviderLoading );
29
+ const { data: savedIconSvg, isLoading: isSavedIconLoading } = useProviderIconSvg(
30
+ iconLibrary,
31
+ iconClassName,
32
+ shouldLoadIconCatalog && ! isLoadingCatalog && ! selectedIcon
33
+ );
29
34
 
30
- if ( isFetching || isLoadingCatalog ) {
35
+ if ( isFetching || isLoadingCatalog || isSavedIconLoading ) {
31
36
  return <CircularProgress role="progressbar" />;
32
37
  }
33
38
 
@@ -35,6 +40,10 @@ export const SvgMediaPreview = ( { isFetching, src, iconClassName, iconLibrary }
35
40
  return <IconPreview icon={ selectedIcon } />;
36
41
  }
37
42
 
43
+ if ( savedIconSvg ) {
44
+ return <IconPreview icon={ toSvgMarkupIcon( savedIconSvg, iconLibrary, iconClassName ) } />;
45
+ }
46
+
38
47
  if ( shouldLoadIconCatalog ) {
39
48
  return <IconPreviewPlaceholder />;
40
49
  }
@@ -42,6 +51,19 @@ export const SvgMediaPreview = ( { isFetching, src, iconClassName, iconLibrary }
42
51
  return <SvgPreview src={ src } />;
43
52
  };
44
53
 
54
+ const toSvgMarkupIcon = ( svgMarkup: string, library: string | null, value: string | null ): FontAwesome7Icon => ( {
55
+ id: `${ library }:${ value }`,
56
+ label: value ?? '',
57
+ library: library ?? '',
58
+ value: value ?? '',
59
+ name: value ?? '',
60
+ aliases: [],
61
+ width: 0,
62
+ height: 0,
63
+ paths: [],
64
+ svgMarkup,
65
+ } );
66
+
45
67
  const IconPreview = ( { icon }: { icon: FontAwesome7Icon } ) => (
46
68
  <Box sx={ { color: ICON_PREVIEW_COLOR } }>
47
69
  <FontAwesomeGlyph