@etsoo/materialui 1.5.57 → 1.5.59
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 +33 -18
- package/lib/mjs/ButtonPopupCheckbox.js +6 -2
- package/lib/mjs/DnDList.js +33 -18
- package/package.json +1 -1
- package/src/ButtonPopupCheckbox.tsx +6 -1
- package/src/DnDList.tsx +46 -29
|
@@ -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,38 @@ function DnDList(props) {
|
|
|
152
152
|
]);
|
|
153
153
|
});
|
|
154
154
|
}, []);
|
|
155
|
+
const doChange = react_1.default.useCallback(() => doFormChange(), []);
|
|
156
|
+
const setupDiv = (div, clearup = false) => {
|
|
157
|
+
// Inputs
|
|
158
|
+
div
|
|
159
|
+
.querySelectorAll("input")
|
|
160
|
+
.forEach((input) => clearup
|
|
161
|
+
? input.removeEventListener("change", doChange)
|
|
162
|
+
: input.addEventListener("change", doChange));
|
|
163
|
+
// Textareas
|
|
164
|
+
div
|
|
165
|
+
.querySelectorAll("textarea")
|
|
166
|
+
.forEach((input) => clearup
|
|
167
|
+
? input.removeEventListener("change", doChange)
|
|
168
|
+
: input.addEventListener("change", doChange));
|
|
169
|
+
// Select
|
|
170
|
+
div
|
|
171
|
+
.querySelectorAll("select")
|
|
172
|
+
.forEach((input) => clearup
|
|
173
|
+
? input.removeEventListener("change", doChange)
|
|
174
|
+
: input.addEventListener("change", doChange));
|
|
175
|
+
};
|
|
176
|
+
const divRef = react_1.default.useRef(null);
|
|
177
|
+
react_1.default.useEffect(() => {
|
|
178
|
+
if (divRef.current) {
|
|
179
|
+
setupDiv(divRef.current);
|
|
180
|
+
}
|
|
181
|
+
return () => {
|
|
182
|
+
if (divRef.current) {
|
|
183
|
+
setupDiv(divRef.current, true);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}, []);
|
|
155
187
|
if (dnd == null) {
|
|
156
188
|
return (0, jsx_runtime_1.jsx)(Skeleton_1.default, { variant: "rectangular", width: "100%", height: height });
|
|
157
189
|
}
|
|
@@ -195,29 +227,12 @@ function DnDList(props) {
|
|
|
195
227
|
}
|
|
196
228
|
setActiveId(undefined);
|
|
197
229
|
}
|
|
198
|
-
const setupDiv = (div) => {
|
|
199
|
-
// Inputs
|
|
200
|
-
div
|
|
201
|
-
.querySelectorAll("input")
|
|
202
|
-
.forEach((input) => input.addEventListener("change", () => doFormChange()));
|
|
203
|
-
// Textareas
|
|
204
|
-
div
|
|
205
|
-
.querySelectorAll("textarea")
|
|
206
|
-
.forEach((input) => input.addEventListener("change", () => doFormChange()));
|
|
207
|
-
// Select
|
|
208
|
-
div
|
|
209
|
-
.querySelectorAll("select")
|
|
210
|
-
.forEach((input) => input.addEventListener("change", () => doFormChange()));
|
|
211
|
-
};
|
|
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,38 @@ export function DnDList(props) {
|
|
|
144
144
|
]);
|
|
145
145
|
});
|
|
146
146
|
}, []);
|
|
147
|
+
const doChange = React.useCallback(() => doFormChange(), []);
|
|
148
|
+
const setupDiv = (div, clearup = false) => {
|
|
149
|
+
// Inputs
|
|
150
|
+
div
|
|
151
|
+
.querySelectorAll("input")
|
|
152
|
+
.forEach((input) => clearup
|
|
153
|
+
? input.removeEventListener("change", doChange)
|
|
154
|
+
: input.addEventListener("change", doChange));
|
|
155
|
+
// Textareas
|
|
156
|
+
div
|
|
157
|
+
.querySelectorAll("textarea")
|
|
158
|
+
.forEach((input) => clearup
|
|
159
|
+
? input.removeEventListener("change", doChange)
|
|
160
|
+
: input.addEventListener("change", doChange));
|
|
161
|
+
// Select
|
|
162
|
+
div
|
|
163
|
+
.querySelectorAll("select")
|
|
164
|
+
.forEach((input) => clearup
|
|
165
|
+
? input.removeEventListener("change", doChange)
|
|
166
|
+
: input.addEventListener("change", doChange));
|
|
167
|
+
};
|
|
168
|
+
const divRef = React.useRef(null);
|
|
169
|
+
React.useEffect(() => {
|
|
170
|
+
if (divRef.current) {
|
|
171
|
+
setupDiv(divRef.current);
|
|
172
|
+
}
|
|
173
|
+
return () => {
|
|
174
|
+
if (divRef.current) {
|
|
175
|
+
setupDiv(divRef.current, true);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}, []);
|
|
147
179
|
if (dnd == null) {
|
|
148
180
|
return _jsx(Skeleton, { variant: "rectangular", width: "100%", height: height });
|
|
149
181
|
}
|
|
@@ -187,29 +219,12 @@ export function DnDList(props) {
|
|
|
187
219
|
}
|
|
188
220
|
setActiveId(undefined);
|
|
189
221
|
}
|
|
190
|
-
const setupDiv = (div) => {
|
|
191
|
-
// Inputs
|
|
192
|
-
div
|
|
193
|
-
.querySelectorAll("input")
|
|
194
|
-
.forEach((input) => input.addEventListener("change", () => doFormChange()));
|
|
195
|
-
// Textareas
|
|
196
|
-
div
|
|
197
|
-
.querySelectorAll("textarea")
|
|
198
|
-
.forEach((input) => input.addEventListener("change", () => doFormChange()));
|
|
199
|
-
// Select
|
|
200
|
-
div
|
|
201
|
-
.querySelectorAll("select")
|
|
202
|
-
.forEach((input) => input.addEventListener("change", () => doFormChange()));
|
|
203
|
-
};
|
|
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,51 @@ export function DnDList<D extends { id: UniqueIdentifier }>(
|
|
|
362
362
|
);
|
|
363
363
|
}, []);
|
|
364
364
|
|
|
365
|
+
const doChange = React.useCallback(() => doFormChange(), []);
|
|
366
|
+
|
|
367
|
+
const setupDiv = (div: HTMLDivElement, clearup: boolean = false) => {
|
|
368
|
+
// Inputs
|
|
369
|
+
div
|
|
370
|
+
.querySelectorAll("input")
|
|
371
|
+
.forEach((input) =>
|
|
372
|
+
clearup
|
|
373
|
+
? input.removeEventListener("change", doChange)
|
|
374
|
+
: input.addEventListener("change", doChange)
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
// Textareas
|
|
378
|
+
div
|
|
379
|
+
.querySelectorAll("textarea")
|
|
380
|
+
.forEach((input) =>
|
|
381
|
+
clearup
|
|
382
|
+
? input.removeEventListener("change", doChange)
|
|
383
|
+
: input.addEventListener("change", doChange)
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
// Select
|
|
387
|
+
div
|
|
388
|
+
.querySelectorAll("select")
|
|
389
|
+
.forEach((input) =>
|
|
390
|
+
clearup
|
|
391
|
+
? input.removeEventListener("change", doChange)
|
|
392
|
+
: input.addEventListener("change", doChange)
|
|
393
|
+
);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
const divRef = React.useRef<HTMLDivElement>(null);
|
|
397
|
+
|
|
398
|
+
React.useEffect(() => {
|
|
399
|
+
if (divRef.current) {
|
|
400
|
+
setupDiv(divRef.current);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return () => {
|
|
404
|
+
if (divRef.current) {
|
|
405
|
+
setupDiv(divRef.current, true);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}, []);
|
|
409
|
+
|
|
365
410
|
if (dnd == null) {
|
|
366
411
|
return <Skeleton variant="rectangular" width="100%" height={height} />;
|
|
367
412
|
}
|
|
@@ -428,29 +473,6 @@ export function DnDList<D extends { id: UniqueIdentifier }>(
|
|
|
428
473
|
setActiveId(undefined);
|
|
429
474
|
}
|
|
430
475
|
|
|
431
|
-
const setupDiv = (div: HTMLDivElement) => {
|
|
432
|
-
// Inputs
|
|
433
|
-
div
|
|
434
|
-
.querySelectorAll("input")
|
|
435
|
-
.forEach((input) =>
|
|
436
|
-
input.addEventListener("change", () => doFormChange())
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
// Textareas
|
|
440
|
-
div
|
|
441
|
-
.querySelectorAll("textarea")
|
|
442
|
-
.forEach((input) =>
|
|
443
|
-
input.addEventListener("change", () => doFormChange())
|
|
444
|
-
);
|
|
445
|
-
|
|
446
|
-
// Select
|
|
447
|
-
div
|
|
448
|
-
.querySelectorAll("select")
|
|
449
|
-
.forEach((input) =>
|
|
450
|
-
input.addEventListener("change", () => doFormChange())
|
|
451
|
-
);
|
|
452
|
-
};
|
|
453
|
-
|
|
454
476
|
const children = (
|
|
455
477
|
<DndContextType onDragStart={handleDragStart} onDragEnd={handleDragEnd}>
|
|
456
478
|
<SortableContextType items={items} strategy={strategy}>
|
|
@@ -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
|
);
|