@elementor/editor-controls 4.3.0-1059 → 4.3.0-1061
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 +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +243 -135
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -83
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/controls/open-icon-library.ts +82 -0
- package/src/controls/svg-media-control.tsx +124 -18
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.3.0-
|
|
4
|
+
"version": "4.3.0-1061",
|
|
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.3.0-
|
|
44
|
-
"@elementor/editor-elements": "4.3.0-
|
|
45
|
-
"@elementor/editor-props": "4.3.0-
|
|
46
|
-
"@elementor/editor-responsive": "4.3.0-
|
|
47
|
-
"@elementor/editor-ui": "4.3.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "4.3.0-
|
|
49
|
-
"@elementor/env": "4.3.0-
|
|
50
|
-
"@elementor/events": "4.3.0-
|
|
51
|
-
"@elementor/http-client": "4.3.0-
|
|
43
|
+
"@elementor/editor-current-user": "4.3.0-1061",
|
|
44
|
+
"@elementor/editor-elements": "4.3.0-1061",
|
|
45
|
+
"@elementor/editor-props": "4.3.0-1061",
|
|
46
|
+
"@elementor/editor-responsive": "4.3.0-1061",
|
|
47
|
+
"@elementor/editor-ui": "4.3.0-1061",
|
|
48
|
+
"@elementor/editor-v1-adapters": "4.3.0-1061",
|
|
49
|
+
"@elementor/env": "4.3.0-1061",
|
|
50
|
+
"@elementor/events": "4.3.0-1061",
|
|
51
|
+
"@elementor/http-client": "4.3.0-1061",
|
|
52
52
|
"@elementor/icons": "~1.75.1",
|
|
53
|
-
"@elementor/locations": "4.3.0-
|
|
54
|
-
"@elementor/query": "4.3.0-
|
|
55
|
-
"@elementor/schema": "4.3.0-
|
|
56
|
-
"@elementor/session": "4.3.0-
|
|
53
|
+
"@elementor/locations": "4.3.0-1061",
|
|
54
|
+
"@elementor/query": "4.3.0-1061",
|
|
55
|
+
"@elementor/schema": "4.3.0-1061",
|
|
56
|
+
"@elementor/session": "4.3.0-1061",
|
|
57
57
|
"@elementor/ui": "1.37.5",
|
|
58
|
-
"@elementor/utils": "4.3.0-
|
|
59
|
-
"@elementor/wp-media": "4.3.0-
|
|
58
|
+
"@elementor/utils": "4.3.0-1061",
|
|
59
|
+
"@elementor/wp-media": "4.3.0-1061",
|
|
60
60
|
"@monaco-editor/react": "^4.7.0",
|
|
61
61
|
"@tiptap/extension-bold": "^3.11.1",
|
|
62
62
|
"@tiptap/extension-document": "^3.11.1",
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { stringPropTypeUtil } from '@elementor/editor-props';
|
|
2
|
+
|
|
3
|
+
export const SVG_ICON_LIBRARY = 'svg';
|
|
4
|
+
|
|
5
|
+
export type IconLibraryMediaValue = {
|
|
6
|
+
id?: number;
|
|
7
|
+
url?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type IconLibrarySelection = {
|
|
11
|
+
value: string | IconLibraryMediaValue;
|
|
12
|
+
library: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type IconManagerControlView = {
|
|
16
|
+
model: {
|
|
17
|
+
get: ( key: string ) => unknown;
|
|
18
|
+
};
|
|
19
|
+
getControlValue: () => IconLibrarySelection;
|
|
20
|
+
setValue: ( icon: IconLibrarySelection ) => void;
|
|
21
|
+
applySavedValue: () => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type IconManager = {
|
|
25
|
+
loadIconLibraries: () => void;
|
|
26
|
+
show: ( options: { view: IconManagerControlView } ) => void;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type ElementorWithIconManager = {
|
|
30
|
+
iconManager?: IconManager;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type OpenIconLibraryOptions = {
|
|
34
|
+
selected?: IconLibrarySelection;
|
|
35
|
+
onSelect?: ( icon: IconLibrarySelection ) => void;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export function isSvgLibrarySelection(
|
|
39
|
+
icon: IconLibrarySelection
|
|
40
|
+
): icon is IconLibrarySelection & { value: IconLibraryMediaValue } {
|
|
41
|
+
return icon.library === SVG_ICON_LIBRARY && typeof icon.value === 'object' && icon.value !== null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function openIconLibrary( { selected, onSelect }: OpenIconLibraryOptions = {} ) {
|
|
45
|
+
const iconManager = ( window.elementor as ElementorWithIconManager | undefined )?.iconManager;
|
|
46
|
+
|
|
47
|
+
if ( ! iconManager ) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
iconManager.loadIconLibraries();
|
|
52
|
+
iconManager.show( {
|
|
53
|
+
view: createIconManagerControlView( selected, onSelect ),
|
|
54
|
+
} );
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function enqueueIconFonts( library: string ) {
|
|
58
|
+
window.elementor?.helpers?.enqueueIconFonts?.( library );
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createIconManagerControlView(
|
|
62
|
+
selected?: IconLibrarySelection,
|
|
63
|
+
onSelect?: ( icon: IconLibrarySelection ) => void
|
|
64
|
+
): IconManagerControlView {
|
|
65
|
+
return {
|
|
66
|
+
model: {
|
|
67
|
+
get: () => false,
|
|
68
|
+
},
|
|
69
|
+
getControlValue: () => selected ?? { value: '', library: '' },
|
|
70
|
+
setValue: ( icon ) => {
|
|
71
|
+
onSelect?.( icon );
|
|
72
|
+
},
|
|
73
|
+
applySavedValue: () => undefined,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function createIconPropValue( icon: Extract< IconLibrarySelection[ 'value' ], string >, library: string ) {
|
|
78
|
+
return {
|
|
79
|
+
value: stringPropTypeUtil.create( icon ),
|
|
80
|
+
library: stringPropTypeUtil.create( library ),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useState } from 'react';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
3
|
import { useCurrentUserCapabilities } from '@elementor/editor-current-user';
|
|
4
|
-
import { svgSrcPropTypeUtil, urlPropTypeUtil } from '@elementor/editor-props';
|
|
4
|
+
import { iconPropTypeUtil, svgSrcPropTypeUtil, urlPropTypeUtil } from '@elementor/editor-props';
|
|
5
5
|
import { UploadIcon } from '@elementor/icons';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
Box,
|
|
8
|
+
Button,
|
|
9
|
+
Card,
|
|
10
|
+
CardMedia,
|
|
11
|
+
CardOverlay,
|
|
12
|
+
CircularProgress,
|
|
13
|
+
Stack,
|
|
14
|
+
styled,
|
|
15
|
+
ThemeProvider,
|
|
16
|
+
} from '@elementor/ui';
|
|
7
17
|
import { type OpenOptions, useWpMediaAttachment, useWpMediaFrame } from '@elementor/wp-media';
|
|
8
18
|
import { __ } from '@wordpress/i18n';
|
|
9
19
|
|
|
@@ -13,10 +23,18 @@ import { EnableUnfilteredModal } from '../components/enable-unfiltered-modal';
|
|
|
13
23
|
import ControlActions from '../control-actions/control-actions';
|
|
14
24
|
import { createControl } from '../create-control';
|
|
15
25
|
import { useUnfilteredFilesUpload } from '../hooks/use-unfiltered-files-upload';
|
|
26
|
+
import {
|
|
27
|
+
createIconPropValue,
|
|
28
|
+
enqueueIconFonts,
|
|
29
|
+
type IconLibrarySelection,
|
|
30
|
+
isSvgLibrarySelection,
|
|
31
|
+
openIconLibrary,
|
|
32
|
+
} from './open-icon-library';
|
|
16
33
|
|
|
17
34
|
const TILE_SIZE = 8;
|
|
18
35
|
const TILE_WHITE = 'transparent';
|
|
19
36
|
const TILE_BLACK = '#c1c1c1';
|
|
37
|
+
const ICON_PREVIEW_FONT_SIZE = 50;
|
|
20
38
|
export const TILES_GRADIENT_FORMULA = `linear-gradient(45deg, ${ TILE_BLACK } 25%, ${ TILE_WHITE } 0, ${ TILE_WHITE } 75%, ${ TILE_BLACK } 0, ${ TILE_BLACK })`;
|
|
21
39
|
|
|
22
40
|
const StyledCard = styled( Card )`
|
|
@@ -42,22 +60,31 @@ const StyledCardMediaContainer = styled( Stack )`
|
|
|
42
60
|
const MODE_BROWSE: OpenOptions = { mode: 'browse' };
|
|
43
61
|
const MODE_UPLOAD: OpenOptions = { mode: 'upload' };
|
|
44
62
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
type SvgMediaControlProps = {
|
|
64
|
+
showIconLibrary?: boolean;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const SvgMediaControl = createControl( ( { showIconLibrary = false }: SvgMediaControlProps ) => {
|
|
68
|
+
const { value: svgValue, setValue: setSvgValue } = useBoundProp( svgSrcPropTypeUtil );
|
|
69
|
+
const { value: iconValue, setValue: setIconValue } = useBoundProp( iconPropTypeUtil );
|
|
70
|
+
const id = svgValue?.id;
|
|
71
|
+
const url = svgValue?.url;
|
|
49
72
|
const { data: attachment, isFetching } = useWpMediaAttachment( id?.value || null );
|
|
50
73
|
const src = attachment?.url ?? url?.value ?? null;
|
|
51
74
|
const { data: allowSvgUpload } = useUnfilteredFilesUpload();
|
|
52
75
|
const [ unfilteredModalOpenState, setUnfilteredModalOpenState ] = useState( false );
|
|
53
76
|
const { isAdmin } = useCurrentUserCapabilities();
|
|
77
|
+
const selectedIconClass =
|
|
78
|
+
showIconLibrary && typeof iconValue?.value?.value === 'string' ? iconValue.value.value : null;
|
|
79
|
+
const selectedIconLibrary =
|
|
80
|
+
showIconLibrary && typeof iconValue?.library?.value === 'string' ? iconValue.library.value : null;
|
|
54
81
|
|
|
55
82
|
const { open } = useWpMediaFrame( {
|
|
56
83
|
mediaTypes: [ 'svg' ],
|
|
57
84
|
multiple: false,
|
|
58
85
|
selected: id?.value || null,
|
|
59
86
|
onSelect: ( selectedAttachment ) => {
|
|
60
|
-
|
|
87
|
+
setSvgValue( {
|
|
61
88
|
id: {
|
|
62
89
|
$$type: 'image-attachment-id',
|
|
63
90
|
value: selectedAttachment.id,
|
|
@@ -83,6 +110,28 @@ export const SvgMediaControl = createControl( () => {
|
|
|
83
110
|
}
|
|
84
111
|
};
|
|
85
112
|
|
|
113
|
+
const handleIconLibrarySelect = ( icon: IconLibrarySelection ) => {
|
|
114
|
+
if ( ! showIconLibrary ) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if ( isSvgLibrarySelection( icon ) ) {
|
|
118
|
+
setSvgValue( {
|
|
119
|
+
id: icon.value.id
|
|
120
|
+
? {
|
|
121
|
+
$$type: 'image-attachment-id',
|
|
122
|
+
value: icon.value.id,
|
|
123
|
+
}
|
|
124
|
+
: null,
|
|
125
|
+
url: icon.value.url ? urlPropTypeUtil.create( icon.value.url ) : null,
|
|
126
|
+
} );
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if ( typeof icon.value === 'string' ) {
|
|
131
|
+
setIconValue( createIconPropValue( icon.value, icon.library ) );
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
86
135
|
const infotipProps = {
|
|
87
136
|
title: __( "Sorry, you can't upload that file yet.", 'elementor' ),
|
|
88
137
|
description: (
|
|
@@ -101,16 +150,12 @@ export const SvgMediaControl = createControl( () => {
|
|
|
101
150
|
<ControlActions>
|
|
102
151
|
<StyledCard variant="outlined">
|
|
103
152
|
<StyledCardMediaContainer>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
alt={ __( 'Preview SVG', 'elementor' ) }
|
|
111
|
-
sx={ { maxHeight: '140px', width: '50px' } }
|
|
112
|
-
/>
|
|
113
|
-
) }
|
|
153
|
+
<SvgMediaPreview
|
|
154
|
+
isFetching={ isFetching }
|
|
155
|
+
src={ src }
|
|
156
|
+
iconClassName={ selectedIconClass }
|
|
157
|
+
iconLibrary={ selectedIconLibrary }
|
|
158
|
+
/>
|
|
114
159
|
</StyledCardMediaContainer>
|
|
115
160
|
<CardOverlay
|
|
116
161
|
sx={ {
|
|
@@ -129,6 +174,25 @@ export const SvgMediaControl = createControl( () => {
|
|
|
129
174
|
>
|
|
130
175
|
{ __( 'Select SVG', 'elementor' ) }
|
|
131
176
|
</Button>
|
|
177
|
+
{ showIconLibrary ? (
|
|
178
|
+
<Button
|
|
179
|
+
size="tiny"
|
|
180
|
+
variant="text"
|
|
181
|
+
color="inherit"
|
|
182
|
+
onClick={ () =>
|
|
183
|
+
openIconLibrary( {
|
|
184
|
+
selected:
|
|
185
|
+
selectedIconClass && selectedIconLibrary
|
|
186
|
+
? { value: selectedIconClass, library: selectedIconLibrary }
|
|
187
|
+
: undefined,
|
|
188
|
+
onSelect: handleIconLibrarySelect,
|
|
189
|
+
} )
|
|
190
|
+
}
|
|
191
|
+
aria-label={ __( 'Icon library', 'elementor' ) }
|
|
192
|
+
>
|
|
193
|
+
{ __( 'Icon library', 'elementor' ) }
|
|
194
|
+
</Button>
|
|
195
|
+
) : null }
|
|
132
196
|
<ConditionalControlInfotip { ...infotipProps }>
|
|
133
197
|
<span>
|
|
134
198
|
<ThemeProvider colorScheme={ isAdmin ? 'light' : 'dark' }>
|
|
@@ -153,3 +217,45 @@ export const SvgMediaControl = createControl( () => {
|
|
|
153
217
|
</Stack>
|
|
154
218
|
);
|
|
155
219
|
} );
|
|
220
|
+
|
|
221
|
+
function SvgMediaPreview( {
|
|
222
|
+
isFetching,
|
|
223
|
+
src,
|
|
224
|
+
iconClassName,
|
|
225
|
+
iconLibrary,
|
|
226
|
+
}: {
|
|
227
|
+
isFetching: boolean;
|
|
228
|
+
src: string | null;
|
|
229
|
+
iconClassName: string | null;
|
|
230
|
+
iconLibrary: string | null;
|
|
231
|
+
} ) {
|
|
232
|
+
useEffect( () => {
|
|
233
|
+
if ( iconLibrary ) {
|
|
234
|
+
enqueueIconFonts( iconLibrary );
|
|
235
|
+
}
|
|
236
|
+
}, [ iconLibrary ] );
|
|
237
|
+
|
|
238
|
+
if ( isFetching ) {
|
|
239
|
+
return <CircularProgress role="progressbar" />;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if ( iconClassName ) {
|
|
243
|
+
return (
|
|
244
|
+
<Box
|
|
245
|
+
component="i"
|
|
246
|
+
className={ iconClassName }
|
|
247
|
+
aria-label={ __( 'Preview icon', 'elementor' ) }
|
|
248
|
+
sx={ { fontSize: ICON_PREVIEW_FONT_SIZE } }
|
|
249
|
+
/>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<CardMedia
|
|
255
|
+
component="img"
|
|
256
|
+
image={ src }
|
|
257
|
+
alt={ __( 'Preview SVG', 'elementor' ) }
|
|
258
|
+
sx={ { maxHeight: '140px', width: `${ ICON_PREVIEW_FONT_SIZE }px` } }
|
|
259
|
+
/>
|
|
260
|
+
);
|
|
261
|
+
}
|