@elementor/editor-controls 3.32.0-41 → 3.32.0-42
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 +26 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -14
- package/src/components/unstable-repeater/context/repeater-context.tsx +26 -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": "3.32.0-
|
|
4
|
+
"version": "3.32.0-42",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,21 +40,21 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-current-user": "3.32.0-
|
|
44
|
-
"@elementor/editor-elements": "3.32.0-
|
|
45
|
-
"@elementor/editor-props": "3.32.0-
|
|
46
|
-
"@elementor/editor-responsive": "3.32.0-
|
|
47
|
-
"@elementor/editor-ui": "3.32.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "3.32.0-
|
|
49
|
-
"@elementor/env": "3.32.0-
|
|
50
|
-
"@elementor/http-client": "3.32.0-
|
|
43
|
+
"@elementor/editor-current-user": "3.32.0-42",
|
|
44
|
+
"@elementor/editor-elements": "3.32.0-42",
|
|
45
|
+
"@elementor/editor-props": "3.32.0-42",
|
|
46
|
+
"@elementor/editor-responsive": "3.32.0-42",
|
|
47
|
+
"@elementor/editor-ui": "3.32.0-42",
|
|
48
|
+
"@elementor/editor-v1-adapters": "3.32.0-42",
|
|
49
|
+
"@elementor/env": "3.32.0-42",
|
|
50
|
+
"@elementor/http-client": "3.32.0-42",
|
|
51
51
|
"@elementor/icons": "^1.51.1",
|
|
52
|
-
"@elementor/locations": "3.32.0-
|
|
53
|
-
"@elementor/query": "3.32.0-
|
|
54
|
-
"@elementor/session": "3.32.0-
|
|
52
|
+
"@elementor/locations": "3.32.0-42",
|
|
53
|
+
"@elementor/query": "3.32.0-42",
|
|
54
|
+
"@elementor/session": "3.32.0-42",
|
|
55
55
|
"@elementor/ui": "1.36.8",
|
|
56
|
-
"@elementor/utils": "3.32.0-
|
|
57
|
-
"@elementor/wp-media": "3.32.0-
|
|
56
|
+
"@elementor/utils": "3.32.0-42",
|
|
57
|
+
"@elementor/wp-media": "3.32.0-42",
|
|
58
58
|
"@wordpress/i18n": "^5.13.0",
|
|
59
59
|
"@monaco-editor/react": "^4.7.0"
|
|
60
60
|
},
|
|
@@ -56,14 +56,24 @@ export const RepeaterContextProvider = < T extends RepeatablePropValue = Repeata
|
|
|
56
56
|
persistWhen: () => true,
|
|
57
57
|
} );
|
|
58
58
|
|
|
59
|
-
const
|
|
60
|
-
items?.map( ( item
|
|
61
|
-
);
|
|
59
|
+
const [ itemsWithKeys, setItemsWithKeys ] = useState< ItemWithKey< T >[] >( () => {
|
|
60
|
+
return items?.map( ( item ) => ( { key: generateUniqueKey(), item } ) ) ?? [];
|
|
61
|
+
} );
|
|
62
|
+
|
|
63
|
+
React.useEffect( () => {
|
|
64
|
+
setItemsWithKeys( ( prevItemsWithKeys ) => {
|
|
65
|
+
const newItemsWithKeys =
|
|
66
|
+
items?.map( ( item ) => {
|
|
67
|
+
const existingItem = prevItemsWithKeys.find( ( i ) => i.item === item );
|
|
68
|
+
return existingItem || { key: generateUniqueKey(), item };
|
|
69
|
+
} ) ?? [];
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
return newItemsWithKeys;
|
|
72
|
+
} );
|
|
73
|
+
}, [ items ] );
|
|
74
|
+
|
|
75
|
+
const handleSetItems = ( newItemsWithKeys: ItemWithKey< T >[] ) => {
|
|
76
|
+
setItems( newItemsWithKeys.map( ( { item } ) => item ) );
|
|
67
77
|
};
|
|
68
78
|
|
|
69
79
|
const [ openItemIndex, setOpenItemIndex ] = useState( EMPTY_OPEN_ITEM );
|
|
@@ -75,24 +85,22 @@ export const RepeaterContextProvider = < T extends RepeatablePropValue = Repeata
|
|
|
75
85
|
const addItem = ( ev: React.MouseEvent, config?: AddItem< T > ) => {
|
|
76
86
|
const item = config?.item ?? initial;
|
|
77
87
|
const newIndex = config?.index ?? items.length;
|
|
78
|
-
const
|
|
79
|
-
const newItemsWithKeys = [ ...itemsWithKeys ];
|
|
88
|
+
const newItems = [ ...items ];
|
|
80
89
|
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
newItems.splice( newIndex, 0, item );
|
|
91
|
+
setItems( newItems );
|
|
83
92
|
|
|
84
93
|
setOpenItemIndex( newIndex );
|
|
85
94
|
popoverState.open( rowRef ?? ev );
|
|
86
95
|
};
|
|
87
96
|
|
|
88
97
|
const removeItem = ( index: number ) => {
|
|
89
|
-
|
|
98
|
+
setItems( items.filter( ( _, pos ) => pos !== index ) );
|
|
90
99
|
};
|
|
91
100
|
|
|
92
101
|
const updateItem = ( updatedItem: T, index: number ) => {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
setItemsWithKeys( itemsWithKeys.toSpliced( index, 1, { ...item, item: updatedItem } ) );
|
|
102
|
+
const newItems = [ ...items.slice( 0, index ), updatedItem, ...items.slice( index + 1 ) ];
|
|
103
|
+
setItems( newItems );
|
|
96
104
|
};
|
|
97
105
|
|
|
98
106
|
return (
|
|
@@ -102,7 +110,7 @@ export const RepeaterContextProvider = < T extends RepeatablePropValue = Repeata
|
|
|
102
110
|
openItemIndex,
|
|
103
111
|
setOpenItemIndex,
|
|
104
112
|
items: ( itemsWithKeys ?? [] ) as RepeaterContextType< T >[ 'items' ],
|
|
105
|
-
setItems:
|
|
113
|
+
setItems: handleSetItems as RepeaterContextType< RepeatablePropValue >[ 'setItems' ],
|
|
106
114
|
popoverState,
|
|
107
115
|
initial,
|
|
108
116
|
updateItem: updateItem as RepeaterContextType< RepeatablePropValue >[ 'updateItem' ],
|
|
@@ -117,6 +125,6 @@ export const RepeaterContextProvider = < T extends RepeatablePropValue = Repeata
|
|
|
117
125
|
);
|
|
118
126
|
};
|
|
119
127
|
|
|
120
|
-
const
|
|
121
|
-
return
|
|
128
|
+
const generateUniqueKey = () => {
|
|
129
|
+
return Date.now() + Math.floor( Math.random() * 1000000 );
|
|
122
130
|
};
|