@etsoo/materialui 1.3.8 → 1.3.9

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.
@@ -16,6 +16,7 @@ const checkedIcon = React.createElement(CheckBoxIcon, { fontSize: "small" });
16
16
  * @returns Component
17
17
  */
18
18
  export function ComboBoxMultiple(props) {
19
+ var _a;
19
20
  // Labels
20
21
  const labels = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("noOptions", "loading");
21
22
  // Destruct
@@ -33,7 +34,7 @@ export function ComboBoxMultiple(props) {
33
34
  ? localOptions.filter((o) => o[idField] === idValue)
34
35
  : idValues != null
35
36
  ? localOptions.filter((o) => idValues === null || idValues === void 0 ? void 0 : idValues.includes(o[idField]))
36
- : defaultValue !== null && defaultValue !== void 0 ? defaultValue : value;
37
+ : (_a = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.concat()) !== null && _a !== void 0 ? _a : value === null || value === void 0 ? void 0 : value.concat();
37
38
  // State
38
39
  // null for controlled
39
40
  const [stateValue, setStateValue] = React.useState(null);
@@ -122,7 +123,7 @@ export function ComboBoxMultiple(props) {
122
123
  ? stateValue
123
124
  : [stateValue], disableCloseOnSelect: disableCloseOnSelect, getOptionLabel: getOptionLabel, multiple: true, isOptionEqualToValue: (option, value) => option[idField] === value[idField], onChange: (event, value, reason, details) => {
124
125
  // Set value
125
- setInputValue(value);
126
+ setInputValue(value.concat());
126
127
  // Custom
127
128
  if (onChange != null)
128
129
  onChange(event, value, reason, details);
package/lib/DnDList.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { UniqueIdentifier } from "@dnd-kit/core";
2
+ import { SortingStrategy } from "@dnd-kit/sortable";
2
3
  import { DataTypes } from "@etsoo/shared";
3
4
  import { Theme } from "@mui/material";
4
5
  import React, { CSSProperties } from "react";
@@ -76,6 +77,10 @@ export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>> {
76
77
  * Methods ref
77
78
  */
78
79
  mRef?: React.Ref<DnDListRef<D>>;
80
+ /**
81
+ * Sorting strategy
82
+ */
83
+ sortingStrategy?: "rect" | "vertical" | "horizontal" | "rectSwapping" | (() => SortingStrategy);
79
84
  /**
80
85
  * Data change handler
81
86
  */
package/lib/DnDList.js CHANGED
@@ -44,7 +44,7 @@ export const DnDItemStyle = (index, isDragging, theme) => ({
44
44
  */
45
45
  export function DnDList(props) {
46
46
  // Destruct
47
- const { keyField, height = 360, itemRenderer, labelField, mRef, onChange, onFormChange, onDragEnd } = props;
47
+ const { keyField, height = 360, itemRenderer, labelField, mRef, sortingStrategy, onChange, onFormChange, onDragEnd } = props;
48
48
  // Theme
49
49
  const theme = useTheme();
50
50
  // States
@@ -129,11 +129,14 @@ export function DnDList(props) {
129
129
  import("@dnd-kit/core"),
130
130
  import("@dnd-kit/sortable"),
131
131
  import("@dnd-kit/utilities")
132
- ]).then(([{ DndContext }, { SortableContext, useSortable, verticalListSortingStrategy }, { CSS }]) => {
132
+ ]).then(([{ DndContext }, { SortableContext, useSortable, rectSortingStrategy, rectSwappingStrategy, horizontalListSortingStrategy, verticalListSortingStrategy }, { CSS }]) => {
133
133
  setDnd([
134
134
  DndContext,
135
135
  SortableContext,
136
136
  useSortable,
137
+ rectSortingStrategy,
138
+ rectSwappingStrategy,
139
+ horizontalListSortingStrategy,
137
140
  verticalListSortingStrategy,
138
141
  CSS
139
142
  ]);
@@ -142,7 +145,18 @@ export function DnDList(props) {
142
145
  if (dnd == null) {
143
146
  return React.createElement(Skeleton, { variant: "rectangular", width: "100%", height: height });
144
147
  }
145
- const [DndContextType, SortableContextType, useSortableType, verticalListSortingStrategyType, CSSType] = dnd;
148
+ const [DndContextType, SortableContextType, useSortableType, rectSortingStrategyType, rectSwappingStrategyType, horizontalListSortingStrategyType, verticalListSortingStrategyType, CSSType] = dnd;
149
+ const strategy = typeof sortingStrategy === "function"
150
+ ? sortingStrategy()
151
+ : sortingStrategy === "rect"
152
+ ? rectSortingStrategyType
153
+ : sortingStrategy === "rectSwapping"
154
+ ? rectSwappingStrategyType
155
+ : sortingStrategy === "horizontal"
156
+ ? horizontalListSortingStrategyType
157
+ : sortingStrategy === "vertical"
158
+ ? verticalListSortingStrategyType
159
+ : undefined;
146
160
  let getItemStyle = props.getItemStyle;
147
161
  if (getItemStyle == null) {
148
162
  getItemStyle = (index, isDragging) => DnDItemStyle(index, isDragging, theme);
@@ -186,7 +200,7 @@ export function DnDList(props) {
186
200
  .forEach((input) => input.addEventListener("change", () => doFormChange()));
187
201
  };
188
202
  const children = (React.createElement(DndContextType, { onDragStart: handleDragStart, onDragEnd: handleDragEnd },
189
- React.createElement(SortableContextType, { items: items, strategy: verticalListSortingStrategyType }, items.map((item, index) => {
203
+ React.createElement(SortableContextType, { items: items, strategy: strategy }, items.map((item, index) => {
190
204
  const id = item[keyField];
191
205
  return (React.createElement(SortableItem, { id: id, useSortableType: useSortableType, CSSType: CSSType, key: id, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }));
192
206
  }))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -53,9 +53,9 @@
53
53
  "@etsoo/appscript": "^1.4.41",
54
54
  "@etsoo/notificationbase": "^1.1.28",
55
55
  "@etsoo/react": "^1.7.7",
56
- "@etsoo/shared": "^1.2.10",
57
- "@mui/icons-material": "^5.14.7",
58
- "@mui/material": "^5.14.7",
56
+ "@etsoo/shared": "^1.2.12",
57
+ "@mui/icons-material": "^5.14.8",
58
+ "@mui/material": "^5.14.8",
59
59
  "@mui/x-data-grid": "^6.12.1",
60
60
  "@types/pica": "^9.0.1",
61
61
  "@types/pulltorefreshjs": "^0.1.5",
@@ -82,7 +82,7 @@
82
82
  "@babel/preset-react": "^7.22.15",
83
83
  "@babel/preset-typescript": "^7.22.15",
84
84
  "@babel/runtime-corejs3": "^7.22.15",
85
- "@testing-library/jest-dom": "^6.1.2",
85
+ "@testing-library/jest-dom": "^6.1.3",
86
86
  "@testing-library/react": "^14.0.0",
87
87
  "@types/jest": "^29.5.4",
88
88
  "@typescript-eslint/eslint-plugin": "^6.6.0",
@@ -142,7 +142,7 @@ export function ComboBoxMultiple<
142
142
  ? localOptions.filter((o) => o[idField] === idValue)
143
143
  : idValues != null
144
144
  ? localOptions.filter((o) => idValues?.includes(o[idField]))
145
- : defaultValue ?? value;
145
+ : defaultValue?.concat() ?? value?.concat();
146
146
 
147
147
  // State
148
148
  // null for controlled
@@ -267,7 +267,7 @@ export function ComboBoxMultiple<
267
267
  }
268
268
  onChange={(event, value, reason, details) => {
269
269
  // Set value
270
- setInputValue(value);
270
+ setInputValue(value.concat());
271
271
 
272
272
  // Custom
273
273
  if (onChange != null) onChange(event, value, reason, details);
package/src/DnDList.tsx CHANGED
@@ -4,8 +4,12 @@ import type {
4
4
  DragStartEvent,
5
5
  UniqueIdentifier
6
6
  } from "@dnd-kit/core";
7
- import type {
7
+ import {
8
8
  SortableContext,
9
+ SortingStrategy,
10
+ horizontalListSortingStrategy,
11
+ rectSortingStrategy,
12
+ rectSwappingStrategy,
9
13
  useSortable,
10
14
  verticalListSortingStrategy
11
15
  } from "@dnd-kit/sortable";
@@ -157,6 +161,16 @@ export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>> {
157
161
  */
158
162
  mRef?: React.Ref<DnDListRef<D>>;
159
163
 
164
+ /**
165
+ * Sorting strategy
166
+ */
167
+ sortingStrategy?:
168
+ | "rect"
169
+ | "vertical"
170
+ | "horizontal"
171
+ | "rectSwapping"
172
+ | (() => SortingStrategy);
173
+
160
174
  /**
161
175
  * Data change handler
162
176
  */
@@ -192,6 +206,7 @@ export function DnDList<
192
206
  itemRenderer,
193
207
  labelField,
194
208
  mRef,
209
+ sortingStrategy,
195
210
  onChange,
196
211
  onFormChange,
197
212
  onDragEnd
@@ -318,6 +333,9 @@ export function DnDList<
318
333
  typeof DndContext,
319
334
  typeof SortableContext,
320
335
  typeof useSortable,
336
+ typeof rectSortingStrategy,
337
+ typeof rectSwappingStrategy,
338
+ typeof horizontalListSortingStrategy,
321
339
  typeof verticalListSortingStrategy,
322
340
  typeof CSS
323
341
  ]
@@ -331,13 +349,23 @@ export function DnDList<
331
349
  ]).then(
332
350
  ([
333
351
  { DndContext },
334
- { SortableContext, useSortable, verticalListSortingStrategy },
352
+ {
353
+ SortableContext,
354
+ useSortable,
355
+ rectSortingStrategy,
356
+ rectSwappingStrategy,
357
+ horizontalListSortingStrategy,
358
+ verticalListSortingStrategy
359
+ },
335
360
  { CSS }
336
361
  ]) => {
337
362
  setDnd([
338
363
  DndContext,
339
364
  SortableContext,
340
365
  useSortable,
366
+ rectSortingStrategy,
367
+ rectSwappingStrategy,
368
+ horizontalListSortingStrategy,
341
369
  verticalListSortingStrategy,
342
370
  CSS
343
371
  ]);
@@ -353,10 +381,26 @@ export function DnDList<
353
381
  DndContextType,
354
382
  SortableContextType,
355
383
  useSortableType,
384
+ rectSortingStrategyType,
385
+ rectSwappingStrategyType,
386
+ horizontalListSortingStrategyType,
356
387
  verticalListSortingStrategyType,
357
388
  CSSType
358
389
  ] = dnd;
359
390
 
391
+ const strategy: SortingStrategy | undefined =
392
+ typeof sortingStrategy === "function"
393
+ ? sortingStrategy()
394
+ : sortingStrategy === "rect"
395
+ ? rectSortingStrategyType
396
+ : sortingStrategy === "rectSwapping"
397
+ ? rectSwappingStrategyType
398
+ : sortingStrategy === "horizontal"
399
+ ? horizontalListSortingStrategyType
400
+ : sortingStrategy === "vertical"
401
+ ? verticalListSortingStrategyType
402
+ : undefined;
403
+
360
404
  let getItemStyle = props.getItemStyle;
361
405
  if (getItemStyle == null) {
362
406
  getItemStyle = (index, isDragging) =>
@@ -420,10 +464,7 @@ export function DnDList<
420
464
 
421
465
  const children = (
422
466
  <DndContextType onDragStart={handleDragStart} onDragEnd={handleDragEnd}>
423
- <SortableContextType
424
- items={items}
425
- strategy={verticalListSortingStrategyType}
426
- >
467
+ <SortableContextType items={items} strategy={strategy}>
427
468
  {items.map((item, index) => {
428
469
  const id = item[keyField] as unknown as UniqueIdentifier;
429
470
  return (