@elementor/editor-controls 4.3.0-1058 → 4.3.0-1060
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 +30 -24
- package/dist/index.d.ts +30 -24
- package/dist/index.js +826 -666
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +811 -641
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/components/inline-editor-toolbar.tsx +34 -3
- package/src/components/inline-editor.tsx +3 -0
- package/src/controls/inline-editing-control.tsx +53 -29
- 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-1060",
|
|
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-1060",
|
|
44
|
+
"@elementor/editor-elements": "4.3.0-1060",
|
|
45
|
+
"@elementor/editor-props": "4.3.0-1060",
|
|
46
|
+
"@elementor/editor-responsive": "4.3.0-1060",
|
|
47
|
+
"@elementor/editor-ui": "4.3.0-1060",
|
|
48
|
+
"@elementor/editor-v1-adapters": "4.3.0-1060",
|
|
49
|
+
"@elementor/env": "4.3.0-1060",
|
|
50
|
+
"@elementor/events": "4.3.0-1060",
|
|
51
|
+
"@elementor/http-client": "4.3.0-1060",
|
|
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-1060",
|
|
54
|
+
"@elementor/query": "4.3.0-1060",
|
|
55
|
+
"@elementor/schema": "4.3.0-1060",
|
|
56
|
+
"@elementor/session": "4.3.0-1060",
|
|
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-1060",
|
|
59
|
+
"@elementor/wp-media": "4.3.0-1060",
|
|
60
60
|
"@monaco-editor/react": "^4.7.0",
|
|
61
61
|
"@tiptap/extension-bold": "^3.11.1",
|
|
62
62
|
"@tiptap/extension-document": "^3.11.1",
|
|
@@ -32,13 +32,19 @@ export type InlineEditorToolbarProps = {
|
|
|
32
32
|
editor: Editor;
|
|
33
33
|
elementId?: ElementID;
|
|
34
34
|
sx?: SxProps< Theme >;
|
|
35
|
+
inControlPanel?: boolean;
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
type ToolbarButtonKeys = keyof typeof toolbarButtons;
|
|
38
39
|
|
|
39
40
|
type FormatAction = Omit< ToolbarButtonKeys, 'clear' >;
|
|
40
41
|
|
|
41
|
-
export const InlineEditorToolbar = ( {
|
|
42
|
+
export const InlineEditorToolbar = ( {
|
|
43
|
+
editor,
|
|
44
|
+
elementId,
|
|
45
|
+
sx = {},
|
|
46
|
+
inControlPanel = false,
|
|
47
|
+
}: InlineEditorToolbarProps ) => {
|
|
42
48
|
const [ urlValue, setUrlValue ] = useState( '' );
|
|
43
49
|
const [ openInNewTab, setOpenInNewTab ] = useState( false );
|
|
44
50
|
const toolbarRef = useRef< HTMLDivElement >( null );
|
|
@@ -101,8 +107,10 @@ export const InlineEditorToolbar = ( { editor, elementId, sx = {} }: InlineEdito
|
|
|
101
107
|
};
|
|
102
108
|
|
|
103
109
|
useEffect( () => {
|
|
104
|
-
|
|
105
|
-
|
|
110
|
+
if ( ! inControlPanel ) {
|
|
111
|
+
editor?.commands?.focus();
|
|
112
|
+
}
|
|
113
|
+
}, [ editor, inControlPanel ] );
|
|
106
114
|
|
|
107
115
|
return (
|
|
108
116
|
<Box
|
|
@@ -118,6 +126,20 @@ export const InlineEditorToolbar = ( { editor, elementId, sx = {} }: InlineEdito
|
|
|
118
126
|
visibility: linkPopupState.isOpen ? 'hidden' : 'visible',
|
|
119
127
|
pointerEvents: linkPopupState.isOpen ? 'none' : 'all',
|
|
120
128
|
...sx,
|
|
129
|
+
...( inControlPanel && {
|
|
130
|
+
width: '100%',
|
|
131
|
+
justifyContent: 'center',
|
|
132
|
+
flexDirection: 'row',
|
|
133
|
+
backgroundColor: 'transparent',
|
|
134
|
+
boxShadow: 'none',
|
|
135
|
+
borderWidth: '0',
|
|
136
|
+
borderBottom: '1px solid',
|
|
137
|
+
borderBottomColor: 'grey.200',
|
|
138
|
+
borderRadius: '0',
|
|
139
|
+
position: 'absolute',
|
|
140
|
+
top: '0',
|
|
141
|
+
left: '0',
|
|
142
|
+
} ),
|
|
121
143
|
} }
|
|
122
144
|
>
|
|
123
145
|
<Tooltip title={ clearButton.label } placement="top" sx={ { borderRadius: '8px' } }>
|
|
@@ -144,6 +166,15 @@ export const InlineEditorToolbar = ( { editor, elementId, sx = {} }: InlineEdito
|
|
|
144
166
|
marginLeft: 0,
|
|
145
167
|
},
|
|
146
168
|
},
|
|
169
|
+
...( inControlPanel && {
|
|
170
|
+
justifyContent: 'space-between',
|
|
171
|
+
width: '100%',
|
|
172
|
+
'& svg': {
|
|
173
|
+
width: '0.7rem',
|
|
174
|
+
height: '0.7rem',
|
|
175
|
+
fill: 'black',
|
|
176
|
+
},
|
|
177
|
+
} ),
|
|
147
178
|
} }
|
|
148
179
|
>
|
|
149
180
|
{ formatButtonsList.map( ( button ) => (
|
|
@@ -33,6 +33,7 @@ type InlineEditorProps = {
|
|
|
33
33
|
autofocus?: boolean;
|
|
34
34
|
expectedTag?: string | null;
|
|
35
35
|
onEditorCreate?: Dispatch< SetStateAction< Editor | null > >;
|
|
36
|
+
onEditorDestroy?: () => void;
|
|
36
37
|
wrapperClassName?: string;
|
|
37
38
|
onSelectionEnd?: ( view: EditorView ) => void;
|
|
38
39
|
mountElement?: HTMLElement | null;
|
|
@@ -50,6 +51,7 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
|
|
|
50
51
|
onBlur = undefined,
|
|
51
52
|
expectedTag = null,
|
|
52
53
|
onEditorCreate,
|
|
54
|
+
onEditorDestroy,
|
|
53
55
|
wrapperClassName,
|
|
54
56
|
onSelectionEnd,
|
|
55
57
|
mountElement = null,
|
|
@@ -146,6 +148,7 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
|
|
|
146
148
|
},
|
|
147
149
|
},
|
|
148
150
|
onCreate: onEditorCreate ? ( { editor: mountedEditor } ) => onEditorCreate( mountedEditor ) : undefined,
|
|
151
|
+
onDestroy: onEditorDestroy ? () => onEditorDestroy() : undefined,
|
|
149
152
|
onBlur: mountElement ? undefined : () => onBlurRef.current?.(),
|
|
150
153
|
onSelectionUpdate: onSelectionEnd
|
|
151
154
|
? ( { editor: updatedEditor } ) => onSelectionEnd( updatedEditor.view )
|
|
@@ -1,39 +1,54 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { type ComponentProps, useCallback } from 'react';
|
|
2
|
+
import { type ComponentProps, useCallback, useState } from 'react';
|
|
3
3
|
import { escapedHtmlPropTypeUtil } from '@elementor/editor-props';
|
|
4
4
|
import { Box, type SxProps, type Theme } from '@elementor/ui';
|
|
5
|
+
import { type Editor } from '@tiptap/react';
|
|
5
6
|
|
|
6
7
|
import { useBoundProp, usePropKeyContext } from '../bound-prop-context';
|
|
7
8
|
import { InlineEditor } from '../components/inline-editor';
|
|
9
|
+
import { InlineEditorToolbar } from '../components/inline-editor-toolbar';
|
|
8
10
|
import ControlActions from '../control-actions/control-actions';
|
|
9
11
|
import { createControl } from '../create-control';
|
|
10
12
|
import { extractInlineHtmlContent } from '../utils/inline-editing';
|
|
13
|
+
import { type ControlProps } from '../utils/types';
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}: {
|
|
18
|
-
sx?: SxProps< Theme >;
|
|
19
|
-
attributes?: Record< string, string >;
|
|
20
|
-
props?: ComponentProps< 'div' >;
|
|
21
|
-
} ) => {
|
|
22
|
-
const { setValue, placeholder, value } = useBoundProp( escapedHtmlPropTypeUtil );
|
|
23
|
-
const { value: rawValue } = usePropKeyContext();
|
|
24
|
-
const content = value ?? extractInlineHtmlContent( rawValue );
|
|
15
|
+
type Props = ControlProps< {
|
|
16
|
+
sx?: SxProps< Theme >;
|
|
17
|
+
attributes?: Record< string, string >;
|
|
18
|
+
props?: ComponentProps< 'div' >;
|
|
19
|
+
} >;
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
export const InlineEditingControl = createControl( ( { sx, attributes, props, context: { elementId } }: Props ) => {
|
|
22
|
+
const { setValue, placeholder, value } = useBoundProp( escapedHtmlPropTypeUtil );
|
|
23
|
+
const { value: rawValue } = usePropKeyContext();
|
|
24
|
+
const content = value ?? extractInlineHtmlContent( rawValue );
|
|
25
|
+
const [ editor, setEditor ] = useState< Editor | null >( null );
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
27
|
+
const handleChange = useCallback(
|
|
28
|
+
( newValue: unknown ) => {
|
|
29
|
+
const html = ( newValue ?? '' ) as string;
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
setValue( html );
|
|
32
|
+
},
|
|
33
|
+
[ setValue ]
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<ControlActions>
|
|
38
|
+
<Box sx={ { position: 'relative' } }>
|
|
39
|
+
{ editor && editor.isEditable && (
|
|
40
|
+
<InlineEditorToolbar
|
|
41
|
+
editor={ editor }
|
|
42
|
+
elementId={ elementId }
|
|
43
|
+
sx={ {
|
|
44
|
+
boxShadow: 'none',
|
|
45
|
+
border: '1px solid',
|
|
46
|
+
borderColor: 'grey.200',
|
|
47
|
+
mb: 0.5,
|
|
48
|
+
} }
|
|
49
|
+
inControlPanel={ true }
|
|
50
|
+
/>
|
|
51
|
+
) }
|
|
37
52
|
<Box
|
|
38
53
|
sx={ {
|
|
39
54
|
p: 0.8,
|
|
@@ -52,7 +67,7 @@ export const InlineEditingControl = createControl(
|
|
|
52
67
|
outline: 'none',
|
|
53
68
|
},
|
|
54
69
|
'& .ProseMirror': {
|
|
55
|
-
minHeight: '
|
|
70
|
+
minHeight: '100px',
|
|
56
71
|
fontSize: '12px',
|
|
57
72
|
'& a': {
|
|
58
73
|
color: 'inherit',
|
|
@@ -77,9 +92,18 @@ export const InlineEditingControl = createControl(
|
|
|
77
92
|
{ ...attributes }
|
|
78
93
|
{ ...props }
|
|
79
94
|
>
|
|
80
|
-
<InlineEditor
|
|
95
|
+
<InlineEditor
|
|
96
|
+
value={ content }
|
|
97
|
+
setValue={ handleChange }
|
|
98
|
+
placeholder={ placeholder ?? null }
|
|
99
|
+
onEditorCreate={ setEditor }
|
|
100
|
+
onEditorDestroy={ () => setEditor( null ) }
|
|
101
|
+
sx={ {
|
|
102
|
+
paddingBlockStart: 5,
|
|
103
|
+
} }
|
|
104
|
+
/>
|
|
81
105
|
</Box>
|
|
82
|
-
</
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
106
|
+
</Box>
|
|
107
|
+
</ControlActions>
|
|
108
|
+
);
|
|
109
|
+
} );
|
|
@@ -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
|
+
}
|