@etsoo/materialui 1.5.57 → 1.5.58
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/lib/cjs/ButtonPopupCheckbox.js +6 -2
- package/lib/cjs/DnDList.js +23 -8
- package/lib/mjs/ButtonPopupCheckbox.js +6 -2
- package/lib/mjs/DnDList.js +23 -8
- package/package.json +1 -1
- package/src/ButtonPopupCheckbox.tsx +6 -1
- package/src/DnDList.tsx +27 -10
|
@@ -36,13 +36,17 @@ function ButtonPopupList(props) {
|
|
|
36
36
|
// Set selected ids
|
|
37
37
|
setSelectedIds([...value]);
|
|
38
38
|
}, [value]);
|
|
39
|
-
return ((0, jsx_runtime_1.jsxs)(FlexBox_1.VBox, { gap: 2, children: [(0, jsx_runtime_1.jsx)(FormGroup_1.default, { children: (0, jsx_runtime_1.jsx)(Grid_1.default, { container: true, spacing: 0, children: (0, jsx_runtime_1.jsx)(DnDList_1.DnDList, { items: items, labelField: labelField,
|
|
39
|
+
return ((0, jsx_runtime_1.jsxs)(FlexBox_1.VBox, { gap: 2, children: [(0, jsx_runtime_1.jsx)(FormGroup_1.default, { children: (0, jsx_runtime_1.jsx)(Grid_1.default, { container: true, spacing: 0, children: (0, jsx_runtime_1.jsx)(DnDList_1.DnDList, { items: items, labelField: labelField, onFormChange: (items) => {
|
|
40
|
+
const ids = items
|
|
41
|
+
.filter((item) => selectedIds.includes(item.id))
|
|
42
|
+
.map((item) => item.id);
|
|
43
|
+
onValueChange(ids);
|
|
44
|
+
}, itemRenderer: (item, index, nodeRef, actionNodeRef) => ((0, jsx_runtime_1.jsxs)(Grid_1.default, { size: { xs: 12, md: 6, lg: 4 }, display: "flex", justifyContent: "flex-start", alignItems: "center", gap: 1, ...nodeRef, children: [(0, jsx_runtime_1.jsx)(IconButton_1.default, { style: { cursor: "move" }, size: "small", title: labels?.dragIndicator, ...actionNodeRef, children: (0, jsx_runtime_1.jsx)(DragIndicator_1.default, {}) }), (0, jsx_runtime_1.jsx)(FormControlLabel_1.default, { control: (0, jsx_runtime_1.jsx)(Checkbox_1.default, { name: "item", value: item.id, checked: selectedIds.includes(item.id), onChange: (e) => {
|
|
40
45
|
const checked = e.target.checked;
|
|
41
46
|
const newIds = [
|
|
42
47
|
...selectedIds.toggleItem(item.id, checked)
|
|
43
48
|
];
|
|
44
49
|
setSelectedIds(newIds);
|
|
45
|
-
onValueChange(newIds);
|
|
46
50
|
} }), label: `${index + 1}. ${labelFormatter(item)}` })] })), height: 200, mRef: dndRef }) }) }), onAdd && ((0, jsx_runtime_1.jsxs)(FlexBox_1.HBox, { gap: 1, children: [(0, jsx_runtime_1.jsx)(TextField_1.default, { variant: "outlined", label: labels?.more, fullWidth: true, inputRef: inputRef }), (0, jsx_runtime_1.jsx)(Button_1.default, { sx: { width: "120px" }, variant: "contained", startIcon: (0, jsx_runtime_1.jsx)(Add_1.default, {}), size: "small", onClick: async () => {
|
|
47
51
|
if (inputRef.current == null)
|
|
48
52
|
return;
|
package/lib/cjs/DnDList.js
CHANGED
|
@@ -152,6 +152,17 @@ function DnDList(props) {
|
|
|
152
152
|
]);
|
|
153
153
|
});
|
|
154
154
|
}, []);
|
|
155
|
+
const divRef = react_1.default.useRef(null);
|
|
156
|
+
react_1.default.useEffect(() => {
|
|
157
|
+
if (divRef.current) {
|
|
158
|
+
setupDiv(divRef.current);
|
|
159
|
+
}
|
|
160
|
+
return () => {
|
|
161
|
+
if (divRef.current) {
|
|
162
|
+
setupDiv(divRef.current, true);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}, []);
|
|
155
166
|
if (dnd == null) {
|
|
156
167
|
return (0, jsx_runtime_1.jsx)(Skeleton_1.default, { variant: "rectangular", width: "100%", height: height });
|
|
157
168
|
}
|
|
@@ -195,29 +206,33 @@ function DnDList(props) {
|
|
|
195
206
|
}
|
|
196
207
|
setActiveId(undefined);
|
|
197
208
|
}
|
|
198
|
-
const
|
|
209
|
+
const doChange = react_1.default.useCallback(() => doFormChange(), []);
|
|
210
|
+
const setupDiv = (div, clearup = false) => {
|
|
199
211
|
// Inputs
|
|
200
212
|
div
|
|
201
213
|
.querySelectorAll("input")
|
|
202
|
-
.forEach((input) =>
|
|
214
|
+
.forEach((input) => clearup
|
|
215
|
+
? input.removeEventListener("change", doChange)
|
|
216
|
+
: input.addEventListener("change", doChange));
|
|
203
217
|
// Textareas
|
|
204
218
|
div
|
|
205
219
|
.querySelectorAll("textarea")
|
|
206
|
-
.forEach((input) =>
|
|
220
|
+
.forEach((input) => clearup
|
|
221
|
+
? input.removeEventListener("change", doChange)
|
|
222
|
+
: input.addEventListener("change", doChange));
|
|
207
223
|
// Select
|
|
208
224
|
div
|
|
209
225
|
.querySelectorAll("select")
|
|
210
|
-
.forEach((input) =>
|
|
226
|
+
.forEach((input) => clearup
|
|
227
|
+
? input.removeEventListener("change", doChange)
|
|
228
|
+
: input.addEventListener("change", doChange));
|
|
211
229
|
};
|
|
212
230
|
const children = ((0, jsx_runtime_1.jsx)(DndContextType, { onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: (0, jsx_runtime_1.jsx)(SortableContextType, { items: items, strategy: strategy, children: items.map((item, index) => {
|
|
213
231
|
const id = item.id;
|
|
214
232
|
return ((0, jsx_runtime_1.jsx)(SortableItem, { id: id, useSortableType: useSortableType, CSSType: CSSType, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }, id));
|
|
215
233
|
}) }) }));
|
|
216
234
|
if (onFormChange) {
|
|
217
|
-
return ((0, jsx_runtime_1.jsx)("div", { style: { width: "100%" }, ref:
|
|
218
|
-
if (div)
|
|
219
|
-
setupDiv(div);
|
|
220
|
-
}, children: children }));
|
|
235
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: { width: "100%" }, ref: divRef, children: children }));
|
|
221
236
|
}
|
|
222
237
|
return children;
|
|
223
238
|
}
|
|
@@ -30,13 +30,17 @@ function ButtonPopupList(props) {
|
|
|
30
30
|
// Set selected ids
|
|
31
31
|
setSelectedIds([...value]);
|
|
32
32
|
}, [value]);
|
|
33
|
-
return (_jsxs(VBox, { gap: 2, children: [_jsx(FormGroup, { children: _jsx(Grid, { container: true, spacing: 0, children: _jsx(DnDList, { items: items, labelField: labelField,
|
|
33
|
+
return (_jsxs(VBox, { gap: 2, children: [_jsx(FormGroup, { children: _jsx(Grid, { container: true, spacing: 0, children: _jsx(DnDList, { items: items, labelField: labelField, onFormChange: (items) => {
|
|
34
|
+
const ids = items
|
|
35
|
+
.filter((item) => selectedIds.includes(item.id))
|
|
36
|
+
.map((item) => item.id);
|
|
37
|
+
onValueChange(ids);
|
|
38
|
+
}, itemRenderer: (item, index, nodeRef, actionNodeRef) => (_jsxs(Grid, { size: { xs: 12, md: 6, lg: 4 }, display: "flex", justifyContent: "flex-start", alignItems: "center", gap: 1, ...nodeRef, children: [_jsx(IconButton, { style: { cursor: "move" }, size: "small", title: labels?.dragIndicator, ...actionNodeRef, children: _jsx(DragIndicatorIcon, {}) }), _jsx(FormControlLabel, { control: _jsx(Checkbox, { name: "item", value: item.id, checked: selectedIds.includes(item.id), onChange: (e) => {
|
|
34
39
|
const checked = e.target.checked;
|
|
35
40
|
const newIds = [
|
|
36
41
|
...selectedIds.toggleItem(item.id, checked)
|
|
37
42
|
];
|
|
38
43
|
setSelectedIds(newIds);
|
|
39
|
-
onValueChange(newIds);
|
|
40
44
|
} }), label: `${index + 1}. ${labelFormatter(item)}` })] })), height: 200, mRef: dndRef }) }) }), onAdd && (_jsxs(HBox, { gap: 1, children: [_jsx(TextField, { variant: "outlined", label: labels?.more, fullWidth: true, inputRef: inputRef }), _jsx(Button, { sx: { width: "120px" }, variant: "contained", startIcon: _jsx(AddIcon, {}), size: "small", onClick: async () => {
|
|
41
45
|
if (inputRef.current == null)
|
|
42
46
|
return;
|
package/lib/mjs/DnDList.js
CHANGED
|
@@ -144,6 +144,17 @@ export function DnDList(props) {
|
|
|
144
144
|
]);
|
|
145
145
|
});
|
|
146
146
|
}, []);
|
|
147
|
+
const divRef = React.useRef(null);
|
|
148
|
+
React.useEffect(() => {
|
|
149
|
+
if (divRef.current) {
|
|
150
|
+
setupDiv(divRef.current);
|
|
151
|
+
}
|
|
152
|
+
return () => {
|
|
153
|
+
if (divRef.current) {
|
|
154
|
+
setupDiv(divRef.current, true);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}, []);
|
|
147
158
|
if (dnd == null) {
|
|
148
159
|
return _jsx(Skeleton, { variant: "rectangular", width: "100%", height: height });
|
|
149
160
|
}
|
|
@@ -187,29 +198,33 @@ export function DnDList(props) {
|
|
|
187
198
|
}
|
|
188
199
|
setActiveId(undefined);
|
|
189
200
|
}
|
|
190
|
-
const
|
|
201
|
+
const doChange = React.useCallback(() => doFormChange(), []);
|
|
202
|
+
const setupDiv = (div, clearup = false) => {
|
|
191
203
|
// Inputs
|
|
192
204
|
div
|
|
193
205
|
.querySelectorAll("input")
|
|
194
|
-
.forEach((input) =>
|
|
206
|
+
.forEach((input) => clearup
|
|
207
|
+
? input.removeEventListener("change", doChange)
|
|
208
|
+
: input.addEventListener("change", doChange));
|
|
195
209
|
// Textareas
|
|
196
210
|
div
|
|
197
211
|
.querySelectorAll("textarea")
|
|
198
|
-
.forEach((input) =>
|
|
212
|
+
.forEach((input) => clearup
|
|
213
|
+
? input.removeEventListener("change", doChange)
|
|
214
|
+
: input.addEventListener("change", doChange));
|
|
199
215
|
// Select
|
|
200
216
|
div
|
|
201
217
|
.querySelectorAll("select")
|
|
202
|
-
.forEach((input) =>
|
|
218
|
+
.forEach((input) => clearup
|
|
219
|
+
? input.removeEventListener("change", doChange)
|
|
220
|
+
: input.addEventListener("change", doChange));
|
|
203
221
|
};
|
|
204
222
|
const children = (_jsx(DndContextType, { onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: _jsx(SortableContextType, { items: items, strategy: strategy, children: items.map((item, index) => {
|
|
205
223
|
const id = item.id;
|
|
206
224
|
return (_jsx(SortableItem, { id: id, useSortableType: useSortableType, CSSType: CSSType, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }, id));
|
|
207
225
|
}) }) }));
|
|
208
226
|
if (onFormChange) {
|
|
209
|
-
return (_jsx("div", { style: { width: "100%" }, ref:
|
|
210
|
-
if (div)
|
|
211
|
-
setupDiv(div);
|
|
212
|
-
}, children: children }));
|
|
227
|
+
return (_jsx("div", { style: { width: "100%" }, ref: divRef, children: children }));
|
|
213
228
|
}
|
|
214
229
|
return children;
|
|
215
230
|
}
|
package/package.json
CHANGED
|
@@ -158,6 +158,12 @@ function ButtonPopupList<D extends DnDItemType>(
|
|
|
158
158
|
<DnDList<D>
|
|
159
159
|
items={items}
|
|
160
160
|
labelField={labelField}
|
|
161
|
+
onFormChange={(items) => {
|
|
162
|
+
const ids = items
|
|
163
|
+
.filter((item) => selectedIds.includes(item.id))
|
|
164
|
+
.map((item) => item.id);
|
|
165
|
+
onValueChange(ids);
|
|
166
|
+
}}
|
|
161
167
|
itemRenderer={(item, index, nodeRef, actionNodeRef) => (
|
|
162
168
|
<Grid
|
|
163
169
|
size={{ xs: 12, md: 6, lg: 4 }}
|
|
@@ -187,7 +193,6 @@ function ButtonPopupList<D extends DnDItemType>(
|
|
|
187
193
|
...selectedIds.toggleItem(item.id, checked)
|
|
188
194
|
];
|
|
189
195
|
setSelectedIds(newIds);
|
|
190
|
-
onValueChange(newIds);
|
|
191
196
|
}}
|
|
192
197
|
/>
|
|
193
198
|
}
|
package/src/DnDList.tsx
CHANGED
|
@@ -362,6 +362,20 @@ export function DnDList<D extends { id: UniqueIdentifier }>(
|
|
|
362
362
|
);
|
|
363
363
|
}, []);
|
|
364
364
|
|
|
365
|
+
const divRef = React.useRef<HTMLDivElement>(null);
|
|
366
|
+
|
|
367
|
+
React.useEffect(() => {
|
|
368
|
+
if (divRef.current) {
|
|
369
|
+
setupDiv(divRef.current);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return () => {
|
|
373
|
+
if (divRef.current) {
|
|
374
|
+
setupDiv(divRef.current, true);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}, []);
|
|
378
|
+
|
|
365
379
|
if (dnd == null) {
|
|
366
380
|
return <Skeleton variant="rectangular" width="100%" height={height} />;
|
|
367
381
|
}
|
|
@@ -428,26 +442,34 @@ export function DnDList<D extends { id: UniqueIdentifier }>(
|
|
|
428
442
|
setActiveId(undefined);
|
|
429
443
|
}
|
|
430
444
|
|
|
431
|
-
const
|
|
445
|
+
const doChange = React.useCallback(() => doFormChange(), []);
|
|
446
|
+
|
|
447
|
+
const setupDiv = (div: HTMLDivElement, clearup: boolean = false) => {
|
|
432
448
|
// Inputs
|
|
433
449
|
div
|
|
434
450
|
.querySelectorAll("input")
|
|
435
451
|
.forEach((input) =>
|
|
436
|
-
|
|
452
|
+
clearup
|
|
453
|
+
? input.removeEventListener("change", doChange)
|
|
454
|
+
: input.addEventListener("change", doChange)
|
|
437
455
|
);
|
|
438
456
|
|
|
439
457
|
// Textareas
|
|
440
458
|
div
|
|
441
459
|
.querySelectorAll("textarea")
|
|
442
460
|
.forEach((input) =>
|
|
443
|
-
|
|
461
|
+
clearup
|
|
462
|
+
? input.removeEventListener("change", doChange)
|
|
463
|
+
: input.addEventListener("change", doChange)
|
|
444
464
|
);
|
|
445
465
|
|
|
446
466
|
// Select
|
|
447
467
|
div
|
|
448
468
|
.querySelectorAll("select")
|
|
449
469
|
.forEach((input) =>
|
|
450
|
-
|
|
470
|
+
clearup
|
|
471
|
+
? input.removeEventListener("change", doChange)
|
|
472
|
+
: input.addEventListener("change", doChange)
|
|
451
473
|
);
|
|
452
474
|
};
|
|
453
475
|
|
|
@@ -475,12 +497,7 @@ export function DnDList<D extends { id: UniqueIdentifier }>(
|
|
|
475
497
|
|
|
476
498
|
if (onFormChange) {
|
|
477
499
|
return (
|
|
478
|
-
<div
|
|
479
|
-
style={{ width: "100%" }}
|
|
480
|
-
ref={(div) => {
|
|
481
|
-
if (div) setupDiv(div);
|
|
482
|
-
}}
|
|
483
|
-
>
|
|
500
|
+
<div style={{ width: "100%" }} ref={divRef}>
|
|
484
501
|
{children}
|
|
485
502
|
</div>
|
|
486
503
|
);
|