@elementor/editor-variables 3.35.3 → 3.35.5
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.js +776 -703
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +650 -579
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/components/ui/menu-item-content.tsx +12 -6
- package/src/components/ui/styled-menu-list.tsx +7 -5
- package/src/components/ui/variable-promotion-chip.tsx +63 -0
- package/src/components/variables-manager/ui/variable-edit-menu.tsx +14 -3
- package/src/components/variables-manager/ui/variable-table-row.tsx +210 -0
- package/src/components/variables-manager/variable-editable-cell.tsx +12 -4
- package/src/components/variables-manager/variables-manager-create-menu.tsx +11 -38
- package/src/components/variables-manager/variables-manager-panel.tsx +18 -15
- package/src/components/variables-manager/variables-manager-table.tsx +18 -189
- package/src/components/variables-selection.tsx +28 -12
- package/src/hooks/use-quota-permissions.ts +10 -11
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { EllipsisWithTooltip } from '@elementor/editor-ui';
|
|
4
|
-
import { GripVerticalIcon } from '@elementor/icons';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
5
3
|
import {
|
|
6
|
-
IconButton,
|
|
7
|
-
Stack,
|
|
8
4
|
type SxProps,
|
|
9
5
|
Table,
|
|
10
6
|
TableBody,
|
|
@@ -19,13 +15,12 @@ import { __ } from '@wordpress/i18n';
|
|
|
19
15
|
|
|
20
16
|
import { type TVariablesList } from '../../storage';
|
|
21
17
|
import { getVariableType } from '../../variables-registry/variable-type-registry';
|
|
22
|
-
import {
|
|
23
|
-
import { VariableEditMenu, type VariableManagerMenuAction } from './ui/variable-edit-menu';
|
|
18
|
+
import { type VariableManagerMenuAction } from './ui/variable-edit-menu';
|
|
24
19
|
import { VariableTableCell } from './ui/variable-table-cell';
|
|
25
|
-
import {
|
|
20
|
+
import { type Row, VariableRow } from './ui/variable-table-row';
|
|
26
21
|
|
|
27
22
|
type Props = {
|
|
28
|
-
menuActions: VariableManagerMenuAction[];
|
|
23
|
+
menuActions: ( variableId: string ) => VariableManagerMenuAction[];
|
|
29
24
|
variables: TVariablesList;
|
|
30
25
|
onChange: ( variables: TVariablesList ) => void;
|
|
31
26
|
autoEditVariableId?: string;
|
|
@@ -33,13 +28,6 @@ type Props = {
|
|
|
33
28
|
onFieldError?: ( hasError: boolean ) => void;
|
|
34
29
|
};
|
|
35
30
|
|
|
36
|
-
type Row = ReturnType< typeof getVariableType > & {
|
|
37
|
-
id: string;
|
|
38
|
-
type: string;
|
|
39
|
-
name: string;
|
|
40
|
-
value: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
31
|
export const VariablesManagerTable = ( {
|
|
44
32
|
menuActions,
|
|
45
33
|
variables,
|
|
@@ -142,179 +130,19 @@ export const VariablesManagerTable = ( {
|
|
|
142
130
|
<UnstableSortableItem
|
|
143
131
|
key={ row.id }
|
|
144
132
|
id={ row.id }
|
|
145
|
-
render={ (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return (
|
|
160
|
-
<TableRow
|
|
161
|
-
{ ...itemProps }
|
|
162
|
-
ref={ itemProps.ref }
|
|
163
|
-
selected={ isDragged }
|
|
164
|
-
sx={ {
|
|
165
|
-
...( showIndicationBefore && {
|
|
166
|
-
'& td, & th': {
|
|
167
|
-
borderTop: '2px solid',
|
|
168
|
-
borderTopColor: 'primary.main',
|
|
169
|
-
},
|
|
170
|
-
} ),
|
|
171
|
-
...( showIndicationAfter && {
|
|
172
|
-
'& td, & th': {
|
|
173
|
-
borderBottom: '2px solid',
|
|
174
|
-
borderBottomColor: 'primary.main',
|
|
175
|
-
},
|
|
176
|
-
} ),
|
|
177
|
-
'& [role="toolbar"], & [draggable]': {
|
|
178
|
-
opacity: 0,
|
|
179
|
-
},
|
|
180
|
-
'&:hover, &:focus-within': {
|
|
181
|
-
backgroundColor: 'action.hover',
|
|
182
|
-
'& [role="toolbar"], & [draggable]': {
|
|
183
|
-
opacity: 1,
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
} }
|
|
187
|
-
style={ { ...itemStyle, ...triggerStyle } }
|
|
188
|
-
>
|
|
189
|
-
<VariableTableCell noPadding width={ 10 } maxWidth={ 10 }>
|
|
190
|
-
<IconButton
|
|
191
|
-
size="small"
|
|
192
|
-
ref={ setTriggerRef }
|
|
193
|
-
{ ...triggerProps }
|
|
194
|
-
disabled={ isSorting }
|
|
195
|
-
draggable
|
|
196
|
-
>
|
|
197
|
-
<GripVerticalIcon fontSize="inherit" />
|
|
198
|
-
</IconButton>
|
|
199
|
-
</VariableTableCell>
|
|
200
|
-
<VariableTableCell>
|
|
201
|
-
<VariableEditableCell
|
|
202
|
-
initialValue={ row.name }
|
|
203
|
-
onChange={ ( value ) => {
|
|
204
|
-
if ( value !== row.name ) {
|
|
205
|
-
handleOnChange( {
|
|
206
|
-
...variables,
|
|
207
|
-
[ row.id ]: { ...variables[ row.id ], label: value },
|
|
208
|
-
} );
|
|
209
|
-
}
|
|
210
|
-
} }
|
|
211
|
-
prefixElement={ createElement( row.icon, { fontSize: 'inherit' } ) }
|
|
212
|
-
editableElement={ ( {
|
|
213
|
-
value,
|
|
214
|
-
onChange,
|
|
215
|
-
onValidationChange,
|
|
216
|
-
error,
|
|
217
|
-
} ) => (
|
|
218
|
-
<LabelField
|
|
219
|
-
id={ 'variable-label-' + row.id }
|
|
220
|
-
size="tiny"
|
|
221
|
-
value={ value }
|
|
222
|
-
onChange={ onChange }
|
|
223
|
-
onErrorChange={ ( errorMsg ) => {
|
|
224
|
-
onValidationChange?.( errorMsg );
|
|
225
|
-
onFieldError?.( !! errorMsg );
|
|
226
|
-
} }
|
|
227
|
-
error={ error }
|
|
228
|
-
focusOnShow
|
|
229
|
-
selectOnShow={ autoEditVariableId === row.id }
|
|
230
|
-
showWarningInfotip={ true }
|
|
231
|
-
variables={ variables }
|
|
232
|
-
/>
|
|
233
|
-
) }
|
|
234
|
-
autoEdit={ autoEditVariableId === row.id }
|
|
235
|
-
onRowRef={ handleRowRef( row.id ) }
|
|
236
|
-
onAutoEditComplete={
|
|
237
|
-
autoEditVariableId === row.id ? onAutoEditComplete : undefined
|
|
238
|
-
}
|
|
239
|
-
fieldType="label"
|
|
240
|
-
>
|
|
241
|
-
<EllipsisWithTooltip
|
|
242
|
-
title={ row.name }
|
|
243
|
-
sx={ { border: '4px solid transparent' } }
|
|
244
|
-
>
|
|
245
|
-
{ row.name }
|
|
246
|
-
</EllipsisWithTooltip>
|
|
247
|
-
</VariableEditableCell>
|
|
248
|
-
</VariableTableCell>
|
|
249
|
-
<VariableTableCell>
|
|
250
|
-
<VariableEditableCell
|
|
251
|
-
initialValue={ row.value }
|
|
252
|
-
onChange={ ( value ) => {
|
|
253
|
-
if ( value !== row.value ) {
|
|
254
|
-
handleOnChange( {
|
|
255
|
-
...variables,
|
|
256
|
-
[ row.id ]: { ...variables[ row.id ], value },
|
|
257
|
-
} );
|
|
258
|
-
}
|
|
259
|
-
} }
|
|
260
|
-
editableElement={ ( {
|
|
261
|
-
value,
|
|
262
|
-
onChange,
|
|
263
|
-
onValidationChange,
|
|
264
|
-
error,
|
|
265
|
-
} ) =>
|
|
266
|
-
row.valueField?.( {
|
|
267
|
-
value,
|
|
268
|
-
onChange,
|
|
269
|
-
onPropTypeKeyChange: ( type ) => {
|
|
270
|
-
handleOnChange( {
|
|
271
|
-
...variables,
|
|
272
|
-
[ row.id ]: { ...variables[ row.id ], type },
|
|
273
|
-
} );
|
|
274
|
-
},
|
|
275
|
-
propTypeKey: row.type,
|
|
276
|
-
onValidationChange: ( errorMsg ) => {
|
|
277
|
-
onValidationChange?.( errorMsg );
|
|
278
|
-
onFieldError?.( !! errorMsg );
|
|
279
|
-
},
|
|
280
|
-
error,
|
|
281
|
-
} ) ?? <></>
|
|
282
|
-
}
|
|
283
|
-
onRowRef={ handleRowRef( row.id ) }
|
|
284
|
-
gap={ 0.25 }
|
|
285
|
-
fieldType="value"
|
|
286
|
-
>
|
|
287
|
-
{ row.startIcon && row.startIcon( { value: row.value } ) }
|
|
288
|
-
<EllipsisWithTooltip
|
|
289
|
-
title={ row.value }
|
|
290
|
-
sx={ {
|
|
291
|
-
border: '4px solid transparent',
|
|
292
|
-
lineHeight: '1',
|
|
293
|
-
pt: 0.25,
|
|
294
|
-
} }
|
|
295
|
-
>
|
|
296
|
-
{ row.value }
|
|
297
|
-
</EllipsisWithTooltip>
|
|
298
|
-
</VariableEditableCell>
|
|
299
|
-
</VariableTableCell>
|
|
300
|
-
<VariableTableCell
|
|
301
|
-
align="right"
|
|
302
|
-
noPadding
|
|
303
|
-
width={ 16 }
|
|
304
|
-
maxWidth={ 16 }
|
|
305
|
-
sx={ { paddingInlineEnd: 1 } }
|
|
306
|
-
>
|
|
307
|
-
<Stack role="toolbar" direction="row" justifyContent="flex-end">
|
|
308
|
-
<VariableEditMenu
|
|
309
|
-
menuActions={ menuActions }
|
|
310
|
-
disabled={ isSorting }
|
|
311
|
-
itemId={ row.id }
|
|
312
|
-
/>
|
|
313
|
-
</Stack>
|
|
314
|
-
</VariableTableCell>
|
|
315
|
-
</TableRow>
|
|
316
|
-
);
|
|
317
|
-
} }
|
|
133
|
+
render={ ( props: UnstableSortableItemRenderProps ) => (
|
|
134
|
+
<VariableRow
|
|
135
|
+
{ ...props }
|
|
136
|
+
row={ row }
|
|
137
|
+
variables={ variables }
|
|
138
|
+
handleOnChange={ handleOnChange }
|
|
139
|
+
autoEditVariableId={ autoEditVariableId }
|
|
140
|
+
onAutoEditComplete={ onAutoEditComplete }
|
|
141
|
+
onFieldError={ onFieldError }
|
|
142
|
+
menuActions={ menuActions }
|
|
143
|
+
handleRowRef={ handleRowRef }
|
|
144
|
+
/>
|
|
145
|
+
) }
|
|
318
146
|
/>
|
|
319
147
|
) ) }
|
|
320
148
|
</UnstableSortableProvider>
|
|
@@ -323,6 +151,7 @@ export const VariablesManagerTable = ( {
|
|
|
323
151
|
</TableContainer>
|
|
324
152
|
);
|
|
325
153
|
};
|
|
154
|
+
|
|
326
155
|
function sortVariablesOrder( variables: TVariablesList ): ( a: string, b: string ) => number {
|
|
327
156
|
return ( a, b ) => {
|
|
328
157
|
const orderA = variables[ a ]?.order ?? Number.MAX_SAFE_INTEGER;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { useState } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
import { PopoverBody } from '@elementor/editor-editing-panel';
|
|
4
4
|
import { PopoverHeader, PopoverMenuList, SearchField, type VirtualizedItem } from '@elementor/editor-ui';
|
|
5
|
+
import { PromotionAlert } from '@elementor/editor-ui';
|
|
5
6
|
import { ColorFilterIcon, PlusIcon, SettingsIcon } from '@elementor/icons';
|
|
6
7
|
import { Divider, IconButton, Tooltip } from '@elementor/ui';
|
|
7
8
|
import { __, sprintf } from '@wordpress/i18n';
|
|
@@ -20,6 +21,9 @@ const SIZE = 'tiny';
|
|
|
20
21
|
const CREATE_LABEL = __( 'Create variable', 'elementor' );
|
|
21
22
|
const MANAGER_LABEL = __( 'Variables Manager', 'elementor' );
|
|
22
23
|
|
|
24
|
+
const getProUpgradeUrl = ( variableType: string ) =>
|
|
25
|
+
`https://go.elementor.com/renew-license-panel-${ variableType }-variable`;
|
|
26
|
+
|
|
23
27
|
type Props = {
|
|
24
28
|
closePopover: () => void;
|
|
25
29
|
onAdd?: () => void;
|
|
@@ -143,17 +147,29 @@ export const VariablesSelection = ( { closePopover, onAdd, onEdit, onSettings, d
|
|
|
143
147
|
<Divider />
|
|
144
148
|
|
|
145
149
|
{ hasVariables && hasSearchResults && (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
<>
|
|
151
|
+
<PopoverMenuList
|
|
152
|
+
items={ items }
|
|
153
|
+
onSelect={ disabled ? () => {} : handleSetVariable }
|
|
154
|
+
onClose={ () => {} }
|
|
155
|
+
selectedValue={ variable }
|
|
156
|
+
data-testid={ `${ variableType }-variables-list` }
|
|
157
|
+
menuListTemplate={ ( props ) => <VariablesStyledMenuList { ...props } disabled={ disabled } /> }
|
|
158
|
+
menuItemContentTemplate={ ( item: VirtualizedItem< 'item', string > ) => (
|
|
159
|
+
<MenuItemContent item={ item } disabled={ disabled } />
|
|
160
|
+
) }
|
|
161
|
+
/>
|
|
162
|
+
{ disabled && (
|
|
163
|
+
<PromotionAlert
|
|
164
|
+
message={ sprintf(
|
|
165
|
+
/* translators: %s: Variable Type. */
|
|
166
|
+
__( 'Upgrade to continue creating and editing %s variables.', 'elementor' ),
|
|
167
|
+
variableType
|
|
168
|
+
) }
|
|
169
|
+
upgradeUrl={ getProUpgradeUrl( variableType ) }
|
|
170
|
+
/>
|
|
155
171
|
) }
|
|
156
|
-
|
|
172
|
+
</>
|
|
157
173
|
) }
|
|
158
174
|
|
|
159
175
|
{ ! hasSearchResults && hasVariables && (
|
|
@@ -164,7 +180,7 @@ export const VariablesSelection = ( { closePopover, onAdd, onEdit, onSettings, d
|
|
|
164
180
|
/>
|
|
165
181
|
) }
|
|
166
182
|
|
|
167
|
-
{ disabled && (
|
|
183
|
+
{ disabled && ! hasVariables && (
|
|
168
184
|
<EmptyState
|
|
169
185
|
title={ sprintf(
|
|
170
186
|
/* translators: %s: Variable Type. */
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
export const useQuotaPermissions = ( variableType: string ) => {
|
|
2
|
+
const quotaConfig = {
|
|
3
|
+
...( window.ElementorVariablesQuotaConfig ?? {} ),
|
|
4
|
+
...( window.ElementorVariablesQuotaConfigExtended ?? {} ),
|
|
5
|
+
};
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ElementorVariablesQuotaConfig: Record< string, number >;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
7
|
+
// BC: Remove when 4.01 is released
|
|
8
|
+
const hasLegacySupport = quotaConfig[ variableType ] === undefined && window.elementorPro;
|
|
8
9
|
|
|
9
|
-
export const useQuotaPermissions = ( variableType: string ) => {
|
|
10
|
-
const quotaConfig = window.ElementorVariablesQuotaConfig || {};
|
|
11
10
|
const limit = quotaConfig[ variableType ] || 0;
|
|
12
|
-
const
|
|
11
|
+
const hasPermission = hasLegacySupport || limit > 0;
|
|
13
12
|
|
|
14
13
|
return {
|
|
15
|
-
canAdd: () =>
|
|
16
|
-
canEdit: () =>
|
|
14
|
+
canAdd: () => hasPermission,
|
|
15
|
+
canEdit: () => hasPermission,
|
|
17
16
|
};
|
|
18
17
|
};
|