@etsoo/react 1.7.94 → 1.7.96
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/README.md +2 -1
- package/__tests__/EventWatcher.tsx +21 -21
- package/__tests__/ReactUtils.ts +4 -4
- package/__tests__/tsconfig.json +17 -17
- package/babel.config.json +8 -8
- package/lib/app/CoreConstants.js +2 -2
- package/lib/app/EventWatcher.d.ts +1 -1
- package/lib/app/EventWatcher.js +3 -5
- package/lib/app/InputDialogProps.d.ts +2 -2
- package/lib/app/ReactUtils.d.ts +2 -2
- package/lib/app/ReactUtils.js +20 -19
- package/lib/components/DnDList.d.ts +3 -3
- package/lib/components/DnDList.js +4 -4
- package/lib/components/DynamicRouter.d.ts +2 -2
- package/lib/components/DynamicRouter.js +2 -2
- package/lib/components/GridColumn.d.ts +6 -6
- package/lib/components/GridColumn.js +7 -7
- package/lib/components/GridLoader.d.ts +4 -4
- package/lib/components/GridLoader.js +2 -2
- package/lib/components/GridMethodRef.d.ts +2 -2
- package/lib/components/ListItemReact.d.ts +2 -2
- package/lib/components/ScrollRestoration.js +3 -3
- package/lib/components/ScrollerGrid.d.ts +7 -12
- package/lib/components/ScrollerGrid.js +13 -17
- package/lib/components/ScrollerList.d.ts +6 -10
- package/lib/components/ScrollerList.js +15 -14
- package/lib/custom/CustomFieldReact.d.ts +1 -1
- package/lib/index.d.ts +32 -32
- package/lib/index.js +31 -31
- package/lib/notifier/Notifier.d.ts +5 -5
- package/lib/notifier/Notifier.js +7 -7
- package/lib/states/CultureState.d.ts +3 -3
- package/lib/states/CultureState.js +3 -3
- package/lib/states/IState.d.ts +2 -2
- package/lib/states/PageState.d.ts +2 -2
- package/lib/states/PageState.js +2 -3
- package/lib/states/State.d.ts +3 -3
- package/lib/states/State.js +2 -2
- package/lib/states/UserState.d.ts +2 -2
- package/lib/states/UserState.js +5 -5
- package/lib/uses/useAsyncState.d.ts +1 -1
- package/lib/uses/useAsyncState.js +1 -1
- package/lib/uses/useCombinedRefs.js +2 -2
- package/lib/uses/useDelayedExecutor.d.ts +1 -1
- package/lib/uses/useDelayedExecutor.js +2 -2
- package/lib/uses/useDimensions.d.ts +1 -1
- package/lib/uses/useDimensions.js +3 -3
- package/lib/uses/useParamsEx.d.ts +1 -1
- package/lib/uses/useParamsEx.js +2 -2
- package/lib/uses/useRefs.d.ts +2 -2
- package/lib/uses/useRefs.js +1 -1
- package/lib/uses/useSearchParamsEx.d.ts +1 -1
- package/lib/uses/useSearchParamsEx.js +3 -3
- package/lib/uses/useTimeout.js +2 -2
- package/lib/uses/useWindowScroll.js +3 -3
- package/lib/uses/useWindowSize.js +4 -5
- package/package.json +72 -74
- package/src/app/CoreConstants.ts +8 -8
- package/src/app/EventWatcher.ts +50 -52
- package/src/app/InputDialogProps.ts +16 -16
- package/src/app/ReactUtils.ts +206 -208
- package/src/components/DnDList.tsx +268 -283
- package/src/components/DynamicRouter.tsx +35 -35
- package/src/components/GridColumn.ts +201 -201
- package/src/components/GridLoader.ts +121 -121
- package/src/components/GridMethodRef.ts +26 -26
- package/src/components/ListItemReact.ts +2 -2
- package/src/components/ScrollRestoration.tsx +24 -24
- package/src/components/ScrollerGrid.tsx +428 -448
- package/src/components/ScrollerList.tsx +320 -332
- package/src/custom/CustomFieldReact.ts +12 -12
- package/src/index.ts +35 -35
- package/src/notifier/Notifier.ts +229 -240
- package/src/states/CultureState.ts +51 -52
- package/src/states/IState.ts +19 -19
- package/src/states/PageState.ts +63 -66
- package/src/states/State.tsx +47 -51
- package/src/states/UserState.ts +98 -98
- package/src/uses/useAsyncState.ts +37 -39
- package/src/uses/useCombinedRefs.ts +16 -16
- package/src/uses/useDelayedExecutor.ts +8 -8
- package/src/uses/useDimensions.ts +102 -103
- package/src/uses/useParamsEx.ts +6 -6
- package/src/uses/useRefs.ts +6 -6
- package/src/uses/useSearchParamsEx.ts +13 -13
- package/src/uses/useTimeout.ts +17 -17
- package/src/uses/useWindowScroll.ts +43 -43
- package/src/uses/useWindowSize.ts +46 -49
- package/tsconfig.json +17 -17
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -38
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
|
@@ -1,137 +1,137 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
2
|
+
DndContext,
|
|
3
|
+
DragEndEvent,
|
|
4
|
+
DragStartEvent,
|
|
5
|
+
UniqueIdentifier
|
|
6
|
+
} from "@dnd-kit/core";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from
|
|
12
|
-
import { CSS } from
|
|
13
|
-
import { DataTypes } from
|
|
14
|
-
import React, { CSSProperties } from
|
|
8
|
+
SortableContext,
|
|
9
|
+
useSortable,
|
|
10
|
+
verticalListSortingStrategy
|
|
11
|
+
} from "@dnd-kit/sortable";
|
|
12
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
13
|
+
import { DataTypes } from "@etsoo/shared";
|
|
14
|
+
import React, { CSSProperties } from "react";
|
|
15
15
|
|
|
16
16
|
function SortableItem(props: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
id: UniqueIdentifier;
|
|
18
|
+
itemRenderer: (
|
|
19
|
+
nodeRef: React.ComponentProps<any>,
|
|
20
|
+
actionNodeRef: React.ComponentProps<any>
|
|
21
|
+
) => React.ReactElement;
|
|
22
|
+
style?: React.CSSProperties;
|
|
23
23
|
}) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
24
|
+
// Destruct
|
|
25
|
+
const { id, itemRenderer, style = {} } = props;
|
|
26
|
+
|
|
27
|
+
// Use sortable
|
|
28
|
+
const {
|
|
29
|
+
attributes,
|
|
30
|
+
listeners,
|
|
31
|
+
setNodeRef,
|
|
32
|
+
transform,
|
|
33
|
+
transition,
|
|
34
|
+
setActivatorNodeRef
|
|
35
|
+
} = useSortable({ id });
|
|
36
|
+
|
|
37
|
+
const allStyle = {
|
|
38
|
+
...style,
|
|
39
|
+
transform: CSS.Transform.toString(transform),
|
|
40
|
+
transition
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const nodeRef = {
|
|
44
|
+
style: allStyle,
|
|
45
|
+
ref: setNodeRef,
|
|
46
|
+
...attributes
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const actionNodeRef = {
|
|
50
|
+
...listeners,
|
|
51
|
+
ref: setActivatorNodeRef
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return itemRenderer(nodeRef, actionNodeRef);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* DnD list forward ref
|
|
59
59
|
*/
|
|
60
60
|
export interface DnDListRef<D extends object> {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Add item
|
|
63
|
+
* @param item New item
|
|
64
|
+
*/
|
|
65
|
+
addItem(item: D): void;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Add items
|
|
69
|
+
* @param items items
|
|
70
|
+
*/
|
|
71
|
+
addItems(items: D[]): void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Delete item
|
|
75
|
+
* @param index Item index
|
|
76
|
+
*/
|
|
77
|
+
deleteItem(index: number): void;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Edit item
|
|
81
|
+
* @param newItem New item
|
|
82
|
+
* @param index Index
|
|
83
|
+
*/
|
|
84
|
+
editItem(newItem: D, index: number): boolean;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* DnD sortable list properties
|
|
89
89
|
*/
|
|
90
90
|
export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>> {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Get list item style callback
|
|
93
|
+
*/
|
|
94
|
+
getItemStyle: (index: number, isDragging: boolean) => CSSProperties;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Item renderer
|
|
98
|
+
*/
|
|
99
|
+
itemRenderer: (
|
|
100
|
+
item: D,
|
|
101
|
+
index: number,
|
|
102
|
+
nodeRef: React.ComponentProps<any>,
|
|
103
|
+
actionNodeRef: React.ComponentProps<any>
|
|
104
|
+
) => React.ReactElement;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* List items
|
|
108
|
+
*/
|
|
109
|
+
items: D[];
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Unique key field
|
|
113
|
+
*/
|
|
114
|
+
keyField: K;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Label field
|
|
118
|
+
*/
|
|
119
|
+
labelField: K;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Methods ref
|
|
123
|
+
*/
|
|
124
|
+
mRef?: React.Ref<DnDListRef<D>>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Data change handler
|
|
128
|
+
*/
|
|
129
|
+
onChange?: (items: D[]) => void;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Drag end handler
|
|
133
|
+
*/
|
|
134
|
+
onDragEnd?: (items: D[]) => void;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/**
|
|
@@ -140,182 +140,167 @@ export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>> {
|
|
|
140
140
|
* @returns Component
|
|
141
141
|
*/
|
|
142
142
|
export function DnDList<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
D extends { id: UniqueIdentifier },
|
|
144
|
+
K extends DataTypes.Keys<D, UniqueIdentifier> = DataTypes.Keys<
|
|
145
|
+
D,
|
|
146
|
+
UniqueIdentifier
|
|
147
|
+
>
|
|
148
148
|
>(props: DnDListPros<D, K>) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
149
|
+
// Destruct
|
|
150
|
+
const {
|
|
151
|
+
getItemStyle,
|
|
152
|
+
keyField,
|
|
153
|
+
itemRenderer,
|
|
154
|
+
labelField,
|
|
155
|
+
mRef,
|
|
156
|
+
onChange,
|
|
157
|
+
onDragEnd
|
|
158
|
+
} = props;
|
|
159
|
+
|
|
160
|
+
// States
|
|
161
|
+
const [items, setItems] = React.useState<D[]>([]);
|
|
162
|
+
const [activeId, setActiveId] = React.useState<UniqueIdentifier>();
|
|
163
|
+
|
|
164
|
+
const changeItems = (newItems: D[]) => {
|
|
165
|
+
// Possible to alter items with the handler
|
|
166
|
+
if (onChange) onChange(newItems);
|
|
167
|
+
|
|
168
|
+
// Update state
|
|
169
|
+
setItems(newItems);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// Drag event handlers
|
|
173
|
+
function handleDragStart(event: DragStartEvent) {
|
|
174
|
+
const { active } = event;
|
|
175
|
+
setActiveId(active.id);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function handleDragEnd(event: DragEndEvent) {
|
|
179
|
+
const { active, over } = event;
|
|
180
|
+
|
|
181
|
+
if (over && active.id !== over.id) {
|
|
182
|
+
// Indices
|
|
183
|
+
const oldIndex = items.findIndex((item) => item.id === active.id);
|
|
184
|
+
const newIndex = items.findIndex((item) => item.id === over.id);
|
|
185
|
+
|
|
186
|
+
// Clone
|
|
187
|
+
const newItems = [...items];
|
|
188
|
+
|
|
189
|
+
// Removed item
|
|
190
|
+
const [removed] = newItems.splice(oldIndex, 1);
|
|
191
|
+
|
|
192
|
+
// Insert to the destination index
|
|
193
|
+
newItems.splice(newIndex, 0, removed);
|
|
194
|
+
|
|
195
|
+
changeItems(newItems);
|
|
196
|
+
|
|
197
|
+
// Drag end handler
|
|
198
|
+
if (onDragEnd) onDragEnd(newItems);
|
|
176
199
|
}
|
|
177
200
|
|
|
178
|
-
|
|
179
|
-
|
|
201
|
+
setActiveId(undefined);
|
|
202
|
+
}
|
|
180
203
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
204
|
+
// Methods
|
|
205
|
+
React.useImperativeHandle(
|
|
206
|
+
mRef,
|
|
207
|
+
() => {
|
|
208
|
+
return {
|
|
209
|
+
addItem(newItem: D) {
|
|
210
|
+
// Existence check
|
|
211
|
+
if (items.some((item) => item[labelField] === newItem[labelField])) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
185
214
|
|
|
186
|
-
|
|
187
|
-
|
|
215
|
+
// Clone
|
|
216
|
+
const newItems = [newItem, ...items];
|
|
188
217
|
|
|
189
|
-
|
|
190
|
-
|
|
218
|
+
// Update the state
|
|
219
|
+
changeItems(newItems);
|
|
191
220
|
|
|
192
|
-
|
|
193
|
-
|
|
221
|
+
return true;
|
|
222
|
+
},
|
|
194
223
|
|
|
195
|
-
|
|
224
|
+
addItems(inputItems: D[]) {
|
|
225
|
+
// Clone
|
|
226
|
+
const newItems = [...items];
|
|
196
227
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
228
|
+
// Insert items
|
|
229
|
+
inputItems.forEach((newItem) => {
|
|
230
|
+
// Existence check
|
|
231
|
+
if (
|
|
232
|
+
newItems.some((item) => item[labelField] === newItem[labelField])
|
|
233
|
+
) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
200
236
|
|
|
201
|
-
|
|
202
|
-
|
|
237
|
+
newItems.push(newItem);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Update the state
|
|
241
|
+
changeItems(newItems);
|
|
242
|
+
|
|
243
|
+
return newItems.length - items.length;
|
|
244
|
+
},
|
|
203
245
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return true;
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
addItems(inputItems: D[]) {
|
|
229
|
-
// Clone
|
|
230
|
-
const newItems = [...items];
|
|
231
|
-
|
|
232
|
-
// Insert items
|
|
233
|
-
inputItems.forEach((newItem) => {
|
|
234
|
-
// Existence check
|
|
235
|
-
if (
|
|
236
|
-
newItems.some(
|
|
237
|
-
(item) =>
|
|
238
|
-
item[labelField] === newItem[labelField]
|
|
239
|
-
)
|
|
240
|
-
) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
newItems.push(newItem);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// Update the state
|
|
248
|
-
changeItems(newItems);
|
|
249
|
-
|
|
250
|
-
return newItems.length - items.length;
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
editItem(newItem: D, index: number) {
|
|
254
|
-
// Existence check
|
|
255
|
-
const newIndex = items.findIndex(
|
|
256
|
-
(item) => item[labelField] === newItem[labelField]
|
|
257
|
-
);
|
|
258
|
-
if (newIndex >= 0 && newIndex !== index) {
|
|
259
|
-
// Label field is the same with a different item
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Clone
|
|
264
|
-
const newItems = [...items];
|
|
265
|
-
|
|
266
|
-
// Remove the item
|
|
267
|
-
newItems.splice(index, 1, newItem);
|
|
268
|
-
|
|
269
|
-
// Update the state
|
|
270
|
-
changeItems(newItems);
|
|
271
|
-
|
|
272
|
-
return true;
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
deleteItem(index: number) {
|
|
276
|
-
// Clone
|
|
277
|
-
const newItems = [...items];
|
|
278
|
-
|
|
279
|
-
// Remove the item
|
|
280
|
-
newItems.splice(index, 1);
|
|
281
|
-
|
|
282
|
-
// Update the state
|
|
283
|
-
changeItems(newItems);
|
|
284
|
-
}
|
|
285
|
-
};
|
|
246
|
+
editItem(newItem: D, index: number) {
|
|
247
|
+
// Existence check
|
|
248
|
+
const newIndex = items.findIndex(
|
|
249
|
+
(item) => item[labelField] === newItem[labelField]
|
|
250
|
+
);
|
|
251
|
+
if (newIndex >= 0 && newIndex !== index) {
|
|
252
|
+
// Label field is the same with a different item
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Clone
|
|
257
|
+
const newItems = [...items];
|
|
258
|
+
|
|
259
|
+
// Remove the item
|
|
260
|
+
newItems.splice(index, 1, newItem);
|
|
261
|
+
|
|
262
|
+
// Update the state
|
|
263
|
+
changeItems(newItems);
|
|
264
|
+
|
|
265
|
+
return true;
|
|
286
266
|
},
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
267
|
+
|
|
268
|
+
deleteItem(index: number) {
|
|
269
|
+
// Clone
|
|
270
|
+
const newItems = [...items];
|
|
271
|
+
|
|
272
|
+
// Remove the item
|
|
273
|
+
newItems.splice(index, 1);
|
|
274
|
+
|
|
275
|
+
// Update the state
|
|
276
|
+
changeItems(newItems);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
[items]
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
React.useEffect(() => {
|
|
284
|
+
setItems(props.items);
|
|
285
|
+
}, [props.items]);
|
|
286
|
+
|
|
287
|
+
return (
|
|
288
|
+
<DndContext onDragStart={handleDragStart} onDragEnd={handleDragEnd}>
|
|
289
|
+
<SortableContext items={items} strategy={verticalListSortingStrategy}>
|
|
290
|
+
{items.map((item, index) => {
|
|
291
|
+
const id = item[keyField] as unknown as UniqueIdentifier;
|
|
292
|
+
return (
|
|
293
|
+
<SortableItem
|
|
294
|
+
id={id}
|
|
295
|
+
key={id}
|
|
296
|
+
style={getItemStyle(index, id === activeId)}
|
|
297
|
+
itemRenderer={(nodeRef, actionNodeRef) =>
|
|
298
|
+
itemRenderer(item, index, nodeRef, actionNodeRef)
|
|
299
|
+
}
|
|
300
|
+
/>
|
|
301
|
+
);
|
|
302
|
+
})}
|
|
303
|
+
</SortableContext>
|
|
304
|
+
</DndContext>
|
|
305
|
+
);
|
|
321
306
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { BridgeUtils, IBridgeHost } from
|
|
2
|
-
import React from
|
|
1
|
+
import { BridgeUtils, IBridgeHost } from "@etsoo/appscript";
|
|
2
|
+
import React from "react";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
4
|
+
BrowserRouter,
|
|
5
|
+
createBrowserRouter,
|
|
6
|
+
createMemoryRouter,
|
|
7
|
+
MemoryRouter,
|
|
8
|
+
RouteObject
|
|
9
|
+
} from "react-router-dom";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Dynamic router props
|
|
13
13
|
*/
|
|
14
14
|
export type DynamicRouterProps = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
/**
|
|
16
|
+
* basename of the router
|
|
17
|
+
*/
|
|
18
|
+
basename?: string;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
function getEntries(host: IBridgeHost) {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const startUrl = host.getStartUrl();
|
|
23
|
+
return startUrl == null ? undefined : [startUrl];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -29,20 +29,20 @@ function getEntries(host: IBridgeHost) {
|
|
|
29
29
|
* @returns Component
|
|
30
30
|
*/
|
|
31
31
|
export function DynamicRouter(
|
|
32
|
-
|
|
32
|
+
props: React.PropsWithChildren<DynamicRouterProps>
|
|
33
33
|
) {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// Destruct
|
|
35
|
+
const { basename, children } = props;
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
// Layout
|
|
38
|
+
const host = BridgeUtils.host;
|
|
39
|
+
return host == null ? (
|
|
40
|
+
<BrowserRouter basename={basename}>{children}</BrowserRouter>
|
|
41
|
+
) : (
|
|
42
|
+
<MemoryRouter basename={basename} initialEntries={getEntries(host)}>
|
|
43
|
+
{children}
|
|
44
|
+
</MemoryRouter>
|
|
45
|
+
);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -52,14 +52,14 @@ export function DynamicRouter(
|
|
|
52
52
|
* @returns Router
|
|
53
53
|
*/
|
|
54
54
|
export function createDynamicRouter(
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
routes: RouteObject[],
|
|
56
|
+
opts?: DynamicRouterProps
|
|
57
57
|
) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
// Is host?
|
|
59
|
+
const host = BridgeUtils.host;
|
|
60
|
+
if (host == null) {
|
|
61
|
+
return createBrowserRouter(routes, opts);
|
|
62
|
+
} else {
|
|
63
|
+
return createMemoryRouter(routes, opts);
|
|
64
|
+
}
|
|
65
65
|
}
|