@elementor/editor-global-classes 0.11.0 → 0.11.1
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/CHANGELOG.md +11 -0
- package/dist/index.js +99 -114
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/components/class-manager/global-classes-list.tsx +96 -98
- package/src/components/class-manager/sortable.tsx +23 -39
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
Box,
|
|
10
10
|
IconButton,
|
|
11
11
|
List,
|
|
12
|
-
ListItem,
|
|
13
12
|
ListItemButton,
|
|
13
|
+
type ListItemButtonProps,
|
|
14
14
|
ListItemText,
|
|
15
15
|
Menu,
|
|
16
16
|
MenuItem,
|
|
@@ -29,7 +29,7 @@ import { useClassesOrder } from '../../hooks/use-classes-order';
|
|
|
29
29
|
import { useOrderedClasses } from '../../hooks/use-ordered-classes';
|
|
30
30
|
import { DeleteConfirmationProvider, useDeleteConfirmation } from './delete-confirmation-dialog';
|
|
31
31
|
import { FlippedColorSwatchIcon } from './flipped-color-swatch-icon';
|
|
32
|
-
import { SortableItem,
|
|
32
|
+
import { SortableItem, SortableProvider, SortableTrigger, type SortableTriggerProps } from './sortable';
|
|
33
33
|
|
|
34
34
|
export const GlobalClassesList = () => {
|
|
35
35
|
const cssClasses = useOrderedClasses();
|
|
@@ -51,18 +51,15 @@ export const GlobalClassesList = () => {
|
|
|
51
51
|
|
|
52
52
|
return (
|
|
53
53
|
<SortableItem key={ id } id={ id }>
|
|
54
|
-
{ ( { isDragged,
|
|
54
|
+
{ ( { isDragged, isDragPlaceholder, triggerProps, triggerStyle } ) => (
|
|
55
55
|
<ClassItem
|
|
56
56
|
id={ id }
|
|
57
57
|
label={ label }
|
|
58
58
|
renameClass={ renameClass }
|
|
59
59
|
selected={ isDragged }
|
|
60
60
|
disabled={ isDragPlaceholder }
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<SortableItemIndicator style={ dropIndicationStyle } />
|
|
64
|
-
) }
|
|
65
|
-
</ClassItem>
|
|
61
|
+
sortableTriggerProps={ { ...triggerProps, style: triggerStyle } }
|
|
62
|
+
/>
|
|
66
63
|
) }
|
|
67
64
|
</SortableItem>
|
|
68
65
|
);
|
|
@@ -83,20 +80,16 @@ const useReorder = () => {
|
|
|
83
80
|
return [ order, reorder ] as const;
|
|
84
81
|
};
|
|
85
82
|
|
|
86
|
-
|
|
87
|
-
id,
|
|
88
|
-
label,
|
|
89
|
-
renameClass,
|
|
90
|
-
selected,
|
|
91
|
-
children,
|
|
92
|
-
disabled,
|
|
93
|
-
}: React.PropsWithChildren< {
|
|
83
|
+
type ClassItemProps = React.PropsWithChildren< {
|
|
94
84
|
id: string;
|
|
95
85
|
label: string;
|
|
96
86
|
renameClass: ( newLabel: string ) => void;
|
|
97
|
-
selected
|
|
98
|
-
disabled
|
|
99
|
-
|
|
87
|
+
selected?: boolean;
|
|
88
|
+
disabled?: boolean;
|
|
89
|
+
sortableTriggerProps: SortableTriggerProps;
|
|
90
|
+
} >;
|
|
91
|
+
|
|
92
|
+
const ClassItem = ( { id, label, renameClass, selected, disabled, sortableTriggerProps }: ClassItemProps ) => {
|
|
100
93
|
const {
|
|
101
94
|
ref: editableRef,
|
|
102
95
|
openEditMode,
|
|
@@ -116,99 +109,103 @@ const ClassItem = ( {
|
|
|
116
109
|
disableAutoFocus: true,
|
|
117
110
|
} );
|
|
118
111
|
|
|
112
|
+
const isSelected = ( selected || popupState.isOpen ) && ! disabled;
|
|
113
|
+
|
|
119
114
|
return (
|
|
120
|
-
|
|
121
|
-
<
|
|
122
|
-
|
|
123
|
-
disablePadding
|
|
115
|
+
<>
|
|
116
|
+
<StyledListItemButton
|
|
117
|
+
dense
|
|
124
118
|
disableGutters
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
<IconButton size="tiny" { ...bindTrigger( popupState ) } aria-label="More actions">
|
|
132
|
-
<DotsVerticalIcon fontSize="tiny" />
|
|
133
|
-
</IconButton>
|
|
134
|
-
</Tooltip>
|
|
135
|
-
}
|
|
119
|
+
showActions={ isSelected || isEditing }
|
|
120
|
+
shape="rounded"
|
|
121
|
+
onDoubleClick={ openEditMode }
|
|
122
|
+
selected={ isSelected }
|
|
123
|
+
disabled={ disabled }
|
|
124
|
+
focusVisibleClassName="visible-class-item"
|
|
136
125
|
>
|
|
137
|
-
<
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
126
|
+
<SortableTrigger { ...sortableTriggerProps } />
|
|
127
|
+
<Indicator isActive={ isEditing } isError={ !! error }>
|
|
128
|
+
{ isEditing ? (
|
|
129
|
+
<EditableField
|
|
130
|
+
ref={ editableRef }
|
|
131
|
+
error={ error }
|
|
132
|
+
as={ Typography }
|
|
133
|
+
variant="caption"
|
|
134
|
+
{ ...getEditableProps() }
|
|
135
|
+
/>
|
|
136
|
+
) : (
|
|
137
|
+
<EllipsisWithTooltip title={ label } as={ Typography } variant="caption" />
|
|
138
|
+
) }
|
|
139
|
+
</Indicator>
|
|
140
|
+
<Tooltip
|
|
141
|
+
placement="top"
|
|
142
|
+
className={ 'class-item-more-actions' }
|
|
143
|
+
title={ __( 'More actions', 'elementor' ) }
|
|
152
144
|
>
|
|
153
|
-
<
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
145
|
+
<IconButton size="tiny" { ...bindTrigger( popupState ) } aria-label="More actions">
|
|
146
|
+
<DotsVerticalIcon fontSize="tiny" />
|
|
147
|
+
</IconButton>
|
|
148
|
+
</Tooltip>
|
|
149
|
+
</StyledListItemButton>
|
|
150
|
+
<Menu
|
|
151
|
+
{ ...bindMenu( popupState ) }
|
|
152
|
+
anchorOrigin={ {
|
|
153
|
+
vertical: 'bottom',
|
|
154
|
+
horizontal: 'right',
|
|
155
|
+
} }
|
|
156
|
+
transformOrigin={ {
|
|
157
|
+
vertical: 'top',
|
|
158
|
+
horizontal: 'right',
|
|
159
|
+
} }
|
|
160
|
+
>
|
|
161
|
+
<MenuItem
|
|
162
|
+
sx={ { minWidth: '160px' } }
|
|
163
|
+
onClick={ () => {
|
|
164
|
+
popupState.close();
|
|
165
|
+
openEditMode();
|
|
173
166
|
} }
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
167
|
+
>
|
|
168
|
+
<ListItemText primary={ __( 'Rename', 'elementor' ) } />
|
|
169
|
+
</MenuItem>
|
|
170
|
+
<MenuItem
|
|
171
|
+
onClick={ () => {
|
|
172
|
+
popupState.close();
|
|
173
|
+
openDialog( { id, label } );
|
|
177
174
|
} }
|
|
178
175
|
>
|
|
179
|
-
<
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
openEditMode();
|
|
184
|
-
} }
|
|
185
|
-
>
|
|
186
|
-
<ListItemText primary={ __( 'Rename', 'elementor' ) } />
|
|
187
|
-
</MenuItem>
|
|
188
|
-
<MenuItem
|
|
189
|
-
onClick={ () => {
|
|
190
|
-
popupState.close();
|
|
191
|
-
openDialog( { id, label } );
|
|
192
|
-
} }
|
|
193
|
-
>
|
|
194
|
-
<ListItemText primary={ __( 'Delete', 'elementor' ) } sx={ { color: 'error.light' } } />
|
|
195
|
-
</MenuItem>
|
|
196
|
-
</Menu>
|
|
197
|
-
</StyledListItem>
|
|
198
|
-
</Stack>
|
|
176
|
+
<ListItemText primary={ __( 'Delete', 'elementor' ) } sx={ { color: 'error.light' } } />
|
|
177
|
+
</MenuItem>
|
|
178
|
+
</Menu>
|
|
179
|
+
</>
|
|
199
180
|
);
|
|
200
181
|
};
|
|
201
182
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
183
|
+
// Custom styles for sortable list item, until the component is available in the UI package.
|
|
184
|
+
const StyledListItemButton = styled( ListItemButton, {
|
|
185
|
+
shouldForwardProp: ( prop: string ) => ! [ 'showActions' ].includes( prop ),
|
|
186
|
+
} )< ListItemButtonProps & { showActions: boolean } >(
|
|
187
|
+
( { showActions } ) => `
|
|
188
|
+
min-height: 36px;
|
|
189
|
+
|
|
190
|
+
&.visible-class-item {
|
|
191
|
+
box-shadow: none !important;
|
|
205
192
|
}
|
|
206
|
-
|
|
207
|
-
|
|
193
|
+
|
|
194
|
+
.class-item-more-actions, .class-item-sortable-trigger {
|
|
195
|
+
visibility: ${ showActions ? 'visible' : 'hidden' };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.class-item-sortable-trigger {
|
|
199
|
+
visibility: ${ showActions ? 'visible' : 'hidden' };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
&:hover&:not(:disabled) {
|
|
203
|
+
.class-item-more-actions, .class-item-sortable-trigger {
|
|
208
204
|
visibility: visible;
|
|
209
205
|
}
|
|
210
206
|
}
|
|
211
|
-
|
|
207
|
+
`
|
|
208
|
+
);
|
|
212
209
|
|
|
213
210
|
const EmptyState = () => (
|
|
214
211
|
<Stack alignItems="center" gap={ 1.5 } pt={ 10 } px={ 0.5 } maxWidth="260px" margin="auto">
|
|
@@ -242,6 +239,7 @@ const Indicator = styled( Box, {
|
|
|
242
239
|
border: getIndicatorBorder( { isActive, isError, theme } ),
|
|
243
240
|
padding: `0 ${ theme.spacing( 1 ) }`,
|
|
244
241
|
marginLeft: isActive ? theme.spacing( 1 ) : 0,
|
|
242
|
+
minWidth: 0,
|
|
245
243
|
} ) );
|
|
246
244
|
|
|
247
245
|
const getIndicatorBorder = ( { isActive, isError, theme }: { isActive: boolean; isError: boolean; theme: Theme } ) => {
|
|
@@ -2,7 +2,6 @@ import * as React from 'react';
|
|
|
2
2
|
import { GripVerticalIcon } from '@elementor/icons';
|
|
3
3
|
import {
|
|
4
4
|
Box,
|
|
5
|
-
Paper,
|
|
6
5
|
styled,
|
|
7
6
|
UnstableSortableItem,
|
|
8
7
|
type UnstableSortableItemProps,
|
|
@@ -15,22 +14,17 @@ export const SortableProvider = < T extends string >( props: UnstableSortablePro
|
|
|
15
14
|
<UnstableSortableProvider restrictAxis variant="static" dragPlaceholderStyle={ { opacity: '1' } } { ...props } />
|
|
16
15
|
);
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export type SortableTriggerProps = React.HTMLAttributes< HTMLDivElement >;
|
|
18
|
+
|
|
19
|
+
export const SortableTrigger = ( props: SortableTriggerProps ) => (
|
|
20
|
+
<StyledSortableTrigger { ...props } role="button" className="class-item-sortable-trigger">
|
|
20
21
|
<GripVerticalIcon fontSize="tiny" />
|
|
21
|
-
</
|
|
22
|
+
</StyledSortableTrigger>
|
|
22
23
|
);
|
|
23
24
|
|
|
24
|
-
type ItemRenderProps = Record< string, unknown > & {
|
|
25
|
-
isDragged: boolean;
|
|
26
|
-
showDropIndication: boolean;
|
|
27
|
-
dropIndicationStyle: React.CSSProperties;
|
|
28
|
-
isDragPlaceholder: boolean;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
25
|
type SortableItemProps = {
|
|
32
26
|
id: UnstableSortableItemProps[ 'id' ];
|
|
33
|
-
children: ( props:
|
|
27
|
+
children: ( props: Partial< UnstableSortableItemRenderProps > ) => React.ReactNode;
|
|
34
28
|
};
|
|
35
29
|
|
|
36
30
|
export const SortableItem = ( { children, id, ...props }: SortableItemProps ) => {
|
|
@@ -50,51 +44,41 @@ export const SortableItem = ( { children, id, ...props }: SortableItemProps ) =>
|
|
|
50
44
|
isDragPlaceholder,
|
|
51
45
|
}: UnstableSortableItemRenderProps ) => {
|
|
52
46
|
return (
|
|
53
|
-
<
|
|
47
|
+
<Box
|
|
54
48
|
{ ...itemProps }
|
|
55
|
-
|
|
49
|
+
style={ itemStyle }
|
|
50
|
+
component={ 'li' }
|
|
56
51
|
role="listitem"
|
|
57
|
-
{
|
|
52
|
+
sx={ {
|
|
53
|
+
backgroundColor: isDragOverlay ? 'background.paper' : undefined,
|
|
54
|
+
} }
|
|
58
55
|
>
|
|
59
|
-
<SortableTrigger { ...triggerProps } style={ triggerStyle } />
|
|
60
56
|
{ children( {
|
|
61
57
|
itemProps,
|
|
62
58
|
isDragged,
|
|
63
59
|
triggerProps,
|
|
64
60
|
itemStyle,
|
|
65
61
|
triggerStyle,
|
|
66
|
-
dropIndicationStyle,
|
|
67
|
-
showDropIndication,
|
|
68
62
|
isDragPlaceholder,
|
|
69
63
|
} ) }
|
|
70
|
-
|
|
64
|
+
{ showDropIndication && <SortableItemIndicator style={ dropIndicationStyle } /> }
|
|
65
|
+
</Box>
|
|
71
66
|
);
|
|
72
67
|
} }
|
|
73
68
|
/>
|
|
74
69
|
);
|
|
75
70
|
};
|
|
76
71
|
|
|
77
|
-
const
|
|
78
|
-
position:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
& .class-item-sortable-trigger {
|
|
87
|
-
visibility: hidden;
|
|
88
|
-
position: absolute;
|
|
89
|
-
left: 0;
|
|
90
|
-
top: 50%;
|
|
91
|
-
transform: translate( -75%, -50% );
|
|
92
|
-
}
|
|
93
|
-
`;
|
|
72
|
+
const StyledSortableTrigger = styled( 'div' )( ( { theme } ) => ( {
|
|
73
|
+
position: 'absolute',
|
|
74
|
+
left: 0,
|
|
75
|
+
top: '50%',
|
|
76
|
+
transform: `translate( -${ theme.spacing( 1.5 ) }, -50% )`,
|
|
77
|
+
color: theme.palette.action.active,
|
|
78
|
+
} ) );
|
|
94
79
|
|
|
95
|
-
|
|
80
|
+
const SortableItemIndicator = styled( Box )`
|
|
96
81
|
width: 100%;
|
|
97
|
-
height:
|
|
98
|
-
border-radius: ${ ( { theme } ) => theme.spacing( 0.5 ) };
|
|
82
|
+
height: 1px;
|
|
99
83
|
background-color: ${ ( { theme } ) => theme.palette.text.primary };
|
|
100
84
|
`;
|