@elementor/editor-variables 4.0.0-552 → 4.0.0-564
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 +742 -683
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +613 -556
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- 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-table.tsx +17 -188
- package/src/hooks/use-quota-permissions.ts +2 -2
|
@@ -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,10 +15,9 @@ 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
23
|
menuActions: ( variableId: string ) => VariableManagerMenuAction[];
|
|
@@ -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( row.id ) }
|
|
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,7 @@
|
|
|
1
1
|
export const useQuotaPermissions = ( variableType: string ) => {
|
|
2
2
|
const quotaConfig = {
|
|
3
|
-
...( window.ElementorVariablesQuotaConfig
|
|
4
|
-
...( window.ElementorVariablesQuotaConfigExtended
|
|
3
|
+
...( window.ElementorVariablesQuotaConfig ?? {} ),
|
|
4
|
+
...( window.ElementorVariablesQuotaConfigExtended ?? {} ),
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// BC: Remove when 4.01 is released
|