@etsoo/react 1.8.47 → 1.8.48

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.
@@ -2,7 +2,6 @@ export * from "./app/CoreConstants";
2
2
  export * from "./app/EventWatcher";
3
3
  export * from "./app/InputDialogProps";
4
4
  export * from "./app/ReactUtils";
5
- export * from "./components/DnDList";
6
5
  export * from "./components/DynamicRouter";
7
6
  export * from "./components/GridColumn";
8
7
  export * from "./components/GridLoader";
package/lib/cjs/index.js CHANGED
@@ -20,7 +20,6 @@ __exportStar(require("./app/EventWatcher"), exports);
20
20
  __exportStar(require("./app/InputDialogProps"), exports);
21
21
  __exportStar(require("./app/ReactUtils"), exports);
22
22
  // components
23
- __exportStar(require("./components/DnDList"), exports);
24
23
  __exportStar(require("./components/DynamicRouter"), exports);
25
24
  __exportStar(require("./components/GridColumn"), exports);
26
25
  __exportStar(require("./components/GridLoader"), exports);
@@ -2,7 +2,6 @@ export * from "./app/CoreConstants";
2
2
  export * from "./app/EventWatcher";
3
3
  export * from "./app/InputDialogProps";
4
4
  export * from "./app/ReactUtils";
5
- export * from "./components/DnDList";
6
5
  export * from "./components/DynamicRouter";
7
6
  export * from "./components/GridColumn";
8
7
  export * from "./components/GridLoader";
package/lib/mjs/index.js CHANGED
@@ -4,7 +4,6 @@ export * from "./app/EventWatcher";
4
4
  export * from "./app/InputDialogProps";
5
5
  export * from "./app/ReactUtils";
6
6
  // components
7
- export * from "./components/DnDList";
8
7
  export * from "./components/DynamicRouter";
9
8
  export * from "./components/GridColumn";
10
9
  export * from "./components/GridLoader";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.8.47",
3
+ "version": "1.8.48",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -35,8 +35,6 @@
35
35
  },
36
36
  "homepage": "https://github.com/ETSOO/AppReact#readme",
37
37
  "dependencies": {
38
- "@dnd-kit/core": "^6.3.1",
39
- "@dnd-kit/sortable": "^10.0.0",
40
38
  "@emotion/css": "^11.13.5",
41
39
  "@emotion/react": "^11.14.0",
42
40
  "@emotion/styled": "^11.14.0",
package/src/index.ts CHANGED
@@ -5,7 +5,6 @@ export * from "./app/InputDialogProps";
5
5
  export * from "./app/ReactUtils";
6
6
 
7
7
  // components
8
- export * from "./components/DnDList";
9
8
  export * from "./components/DynamicRouter";
10
9
  export * from "./components/GridColumn";
11
10
  export * from "./components/GridLoader";
@@ -1,85 +0,0 @@
1
- import { UniqueIdentifier } from "@dnd-kit/core";
2
- import { DataTypes } from "@etsoo/shared";
3
- import React, { CSSProperties } from "react";
4
- /**
5
- * DnD list forward ref
6
- */
7
- export interface DnDListRef<D extends object> {
8
- /**
9
- * Add item
10
- * @param item New item
11
- */
12
- addItem(item: D): void;
13
- /**
14
- * Add items
15
- * @param items items
16
- */
17
- addItems(items: D[]): void;
18
- /**
19
- * Delete item
20
- * @param index Item index
21
- */
22
- deleteItem(index: number): void;
23
- /**
24
- * Edit item
25
- * @param newItem New item
26
- * @param index Index
27
- */
28
- editItem(newItem: D, index: number): boolean;
29
- }
30
- /**
31
- * DnD sortable list properties
32
- */
33
- export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>, E extends React.ExoticComponent<{
34
- children?: React.ReactNode | undefined;
35
- }> = typeof React.Fragment> {
36
- /**
37
- * Component type to render the list into
38
- * Default is React.Fragment
39
- */
40
- component?: E;
41
- /**
42
- * Component props
43
- */
44
- componentProps?: React.ComponentProps<E>;
45
- /**
46
- * Get list item style callback
47
- */
48
- getItemStyle: (index: number, isDragging: boolean) => CSSProperties;
49
- /**
50
- * Item renderer
51
- */
52
- itemRenderer: (item: D, index: number, nodeRef: React.ComponentProps<any>, actionNodeRef: React.ComponentProps<any>) => React.ReactElement;
53
- /**
54
- * List items
55
- */
56
- items: D[];
57
- /**
58
- * Unique key field
59
- */
60
- keyField: K;
61
- /**
62
- * Label field
63
- */
64
- labelField: K;
65
- /**
66
- * Methods ref
67
- */
68
- mRef?: React.Ref<DnDListRef<D>>;
69
- /**
70
- * Data change handler
71
- */
72
- onChange?: (items: D[]) => void;
73
- /**
74
- * Drag end handler
75
- */
76
- onDragEnd?: (items: D[]) => void;
77
- }
78
- /**
79
- * DnD (Drag and Drop) sortable list
80
- * @param props Props
81
- * @returns Component
82
- */
83
- export declare function DnDList<D extends {
84
- id: UniqueIdentifier;
85
- }, K extends DataTypes.Keys<D, UniqueIdentifier> = DataTypes.Keys<D, UniqueIdentifier>>(props: DnDListPros<D, K>): import("react/jsx-runtime").JSX.Element;
@@ -1,137 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DnDList = DnDList;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- const core_1 = require("@dnd-kit/core");
9
- const sortable_1 = require("@dnd-kit/sortable");
10
- const utilities_1 = require("@dnd-kit/utilities");
11
- const react_1 = __importDefault(require("react"));
12
- function SortableItem(props) {
13
- // Destruct
14
- const { id, itemRenderer, style = {} } = props;
15
- // Use sortable
16
- const { attributes, listeners, setNodeRef, transform, transition, setActivatorNodeRef } = (0, sortable_1.useSortable)({ id });
17
- const allStyle = {
18
- ...style,
19
- transform: utilities_1.CSS.Transform.toString(transform),
20
- transition
21
- };
22
- const nodeRef = {
23
- style: allStyle,
24
- ref: setNodeRef,
25
- ...attributes
26
- };
27
- const actionNodeRef = {
28
- ...listeners,
29
- ref: setActivatorNodeRef
30
- };
31
- return itemRenderer(nodeRef, actionNodeRef);
32
- }
33
- /**
34
- * DnD (Drag and Drop) sortable list
35
- * @param props Props
36
- * @returns Component
37
- */
38
- function DnDList(props) {
39
- // Destruct
40
- const { componentProps, getItemStyle, keyField, itemRenderer, labelField, mRef, onChange, onDragEnd } = props;
41
- const Component = props.component || react_1.default.Fragment;
42
- // States
43
- const [items, setItems] = react_1.default.useState([]);
44
- const [activeId, setActiveId] = react_1.default.useState();
45
- const changeItems = (newItems) => {
46
- // Possible to alter items with the handler
47
- if (onChange)
48
- onChange(newItems);
49
- // Update state
50
- setItems(newItems);
51
- };
52
- // Drag event handlers
53
- function handleDragStart(event) {
54
- const { active } = event;
55
- setActiveId(active.id);
56
- }
57
- function handleDragEnd(event) {
58
- const { active, over } = event;
59
- if (over && active.id !== over.id) {
60
- // Indices
61
- const oldIndex = items.findIndex((item) => item.id === active.id);
62
- const newIndex = items.findIndex((item) => item.id === over.id);
63
- // Clone
64
- const newItems = [...items];
65
- // Removed item
66
- const [removed] = newItems.splice(oldIndex, 1);
67
- // Insert to the destination index
68
- newItems.splice(newIndex, 0, removed);
69
- changeItems(newItems);
70
- // Drag end handler
71
- if (onDragEnd)
72
- onDragEnd(newItems);
73
- }
74
- setActiveId(undefined);
75
- }
76
- // Methods
77
- react_1.default.useImperativeHandle(mRef, () => {
78
- return {
79
- addItem(newItem) {
80
- // Existence check
81
- if (items.some((item) => item[labelField] === newItem[labelField])) {
82
- return false;
83
- }
84
- // Clone
85
- const newItems = [newItem, ...items];
86
- // Update the state
87
- changeItems(newItems);
88
- return true;
89
- },
90
- addItems(inputItems) {
91
- // Clone
92
- const newItems = [...items];
93
- // Insert items
94
- inputItems.forEach((newItem) => {
95
- // Existence check
96
- if (newItems.some((item) => item[labelField] === newItem[labelField])) {
97
- return;
98
- }
99
- newItems.push(newItem);
100
- });
101
- // Update the state
102
- changeItems(newItems);
103
- return newItems.length - items.length;
104
- },
105
- editItem(newItem, index) {
106
- // Existence check
107
- const newIndex = items.findIndex((item) => item[labelField] === newItem[labelField]);
108
- if (newIndex >= 0 && newIndex !== index) {
109
- // Label field is the same with a different item
110
- return false;
111
- }
112
- // Clone
113
- const newItems = [...items];
114
- // Remove the item
115
- newItems.splice(index, 1, newItem);
116
- // Update the state
117
- changeItems(newItems);
118
- return true;
119
- },
120
- deleteItem(index) {
121
- // Clone
122
- const newItems = [...items];
123
- // Remove the item
124
- newItems.splice(index, 1);
125
- // Update the state
126
- changeItems(newItems);
127
- }
128
- };
129
- }, [items]);
130
- react_1.default.useEffect(() => {
131
- setItems(props.items);
132
- }, [props.items]);
133
- return ((0, jsx_runtime_1.jsx)(core_1.DndContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: (0, jsx_runtime_1.jsx)(sortable_1.SortableContext, { items: items, strategy: sortable_1.verticalListSortingStrategy, children: (0, jsx_runtime_1.jsx)(Component, { ...componentProps, children: items.map((item, index) => {
134
- const id = item[keyField];
135
- return ((0, jsx_runtime_1.jsx)(SortableItem, { id: id, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }, id));
136
- }) }) }) }));
137
- }
@@ -1,85 +0,0 @@
1
- import { UniqueIdentifier } from "@dnd-kit/core";
2
- import { DataTypes } from "@etsoo/shared";
3
- import React, { CSSProperties } from "react";
4
- /**
5
- * DnD list forward ref
6
- */
7
- export interface DnDListRef<D extends object> {
8
- /**
9
- * Add item
10
- * @param item New item
11
- */
12
- addItem(item: D): void;
13
- /**
14
- * Add items
15
- * @param items items
16
- */
17
- addItems(items: D[]): void;
18
- /**
19
- * Delete item
20
- * @param index Item index
21
- */
22
- deleteItem(index: number): void;
23
- /**
24
- * Edit item
25
- * @param newItem New item
26
- * @param index Index
27
- */
28
- editItem(newItem: D, index: number): boolean;
29
- }
30
- /**
31
- * DnD sortable list properties
32
- */
33
- export interface DnDListPros<D extends object, K extends DataTypes.Keys<D>, E extends React.ExoticComponent<{
34
- children?: React.ReactNode | undefined;
35
- }> = typeof React.Fragment> {
36
- /**
37
- * Component type to render the list into
38
- * Default is React.Fragment
39
- */
40
- component?: E;
41
- /**
42
- * Component props
43
- */
44
- componentProps?: React.ComponentProps<E>;
45
- /**
46
- * Get list item style callback
47
- */
48
- getItemStyle: (index: number, isDragging: boolean) => CSSProperties;
49
- /**
50
- * Item renderer
51
- */
52
- itemRenderer: (item: D, index: number, nodeRef: React.ComponentProps<any>, actionNodeRef: React.ComponentProps<any>) => React.ReactElement;
53
- /**
54
- * List items
55
- */
56
- items: D[];
57
- /**
58
- * Unique key field
59
- */
60
- keyField: K;
61
- /**
62
- * Label field
63
- */
64
- labelField: K;
65
- /**
66
- * Methods ref
67
- */
68
- mRef?: React.Ref<DnDListRef<D>>;
69
- /**
70
- * Data change handler
71
- */
72
- onChange?: (items: D[]) => void;
73
- /**
74
- * Drag end handler
75
- */
76
- onDragEnd?: (items: D[]) => void;
77
- }
78
- /**
79
- * DnD (Drag and Drop) sortable list
80
- * @param props Props
81
- * @returns Component
82
- */
83
- export declare function DnDList<D extends {
84
- id: UniqueIdentifier;
85
- }, K extends DataTypes.Keys<D, UniqueIdentifier> = DataTypes.Keys<D, UniqueIdentifier>>(props: DnDListPros<D, K>): import("react/jsx-runtime").JSX.Element;
@@ -1,131 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { DndContext } from "@dnd-kit/core";
3
- import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
4
- import { CSS } from "@dnd-kit/utilities";
5
- import React from "react";
6
- function SortableItem(props) {
7
- // Destruct
8
- const { id, itemRenderer, style = {} } = props;
9
- // Use sortable
10
- const { attributes, listeners, setNodeRef, transform, transition, setActivatorNodeRef } = useSortable({ id });
11
- const allStyle = {
12
- ...style,
13
- transform: CSS.Transform.toString(transform),
14
- transition
15
- };
16
- const nodeRef = {
17
- style: allStyle,
18
- ref: setNodeRef,
19
- ...attributes
20
- };
21
- const actionNodeRef = {
22
- ...listeners,
23
- ref: setActivatorNodeRef
24
- };
25
- return itemRenderer(nodeRef, actionNodeRef);
26
- }
27
- /**
28
- * DnD (Drag and Drop) sortable list
29
- * @param props Props
30
- * @returns Component
31
- */
32
- export function DnDList(props) {
33
- // Destruct
34
- const { componentProps, getItemStyle, keyField, itemRenderer, labelField, mRef, onChange, onDragEnd } = props;
35
- const Component = props.component || React.Fragment;
36
- // States
37
- const [items, setItems] = React.useState([]);
38
- const [activeId, setActiveId] = React.useState();
39
- const changeItems = (newItems) => {
40
- // Possible to alter items with the handler
41
- if (onChange)
42
- onChange(newItems);
43
- // Update state
44
- setItems(newItems);
45
- };
46
- // Drag event handlers
47
- function handleDragStart(event) {
48
- const { active } = event;
49
- setActiveId(active.id);
50
- }
51
- function handleDragEnd(event) {
52
- const { active, over } = event;
53
- if (over && active.id !== over.id) {
54
- // Indices
55
- const oldIndex = items.findIndex((item) => item.id === active.id);
56
- const newIndex = items.findIndex((item) => item.id === over.id);
57
- // Clone
58
- const newItems = [...items];
59
- // Removed item
60
- const [removed] = newItems.splice(oldIndex, 1);
61
- // Insert to the destination index
62
- newItems.splice(newIndex, 0, removed);
63
- changeItems(newItems);
64
- // Drag end handler
65
- if (onDragEnd)
66
- onDragEnd(newItems);
67
- }
68
- setActiveId(undefined);
69
- }
70
- // Methods
71
- React.useImperativeHandle(mRef, () => {
72
- return {
73
- addItem(newItem) {
74
- // Existence check
75
- if (items.some((item) => item[labelField] === newItem[labelField])) {
76
- return false;
77
- }
78
- // Clone
79
- const newItems = [newItem, ...items];
80
- // Update the state
81
- changeItems(newItems);
82
- return true;
83
- },
84
- addItems(inputItems) {
85
- // Clone
86
- const newItems = [...items];
87
- // Insert items
88
- inputItems.forEach((newItem) => {
89
- // Existence check
90
- if (newItems.some((item) => item[labelField] === newItem[labelField])) {
91
- return;
92
- }
93
- newItems.push(newItem);
94
- });
95
- // Update the state
96
- changeItems(newItems);
97
- return newItems.length - items.length;
98
- },
99
- editItem(newItem, index) {
100
- // Existence check
101
- const newIndex = items.findIndex((item) => item[labelField] === newItem[labelField]);
102
- if (newIndex >= 0 && newIndex !== index) {
103
- // Label field is the same with a different item
104
- return false;
105
- }
106
- // Clone
107
- const newItems = [...items];
108
- // Remove the item
109
- newItems.splice(index, 1, newItem);
110
- // Update the state
111
- changeItems(newItems);
112
- return true;
113
- },
114
- deleteItem(index) {
115
- // Clone
116
- const newItems = [...items];
117
- // Remove the item
118
- newItems.splice(index, 1);
119
- // Update the state
120
- changeItems(newItems);
121
- }
122
- };
123
- }, [items]);
124
- React.useEffect(() => {
125
- setItems(props.items);
126
- }, [props.items]);
127
- return (_jsx(DndContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: _jsx(SortableContext, { items: items, strategy: verticalListSortingStrategy, children: _jsx(Component, { ...componentProps, children: items.map((item, index) => {
128
- const id = item[keyField];
129
- return (_jsx(SortableItem, { id: id, style: getItemStyle(index, id === activeId), itemRenderer: (nodeRef, actionNodeRef) => itemRenderer(item, index, nodeRef, actionNodeRef) }, id));
130
- }) }) }) }));
131
- }
@@ -1,328 +0,0 @@
1
- import {
2
- DndContext,
3
- DragEndEvent,
4
- DragStartEvent,
5
- UniqueIdentifier
6
- } from "@dnd-kit/core";
7
- import {
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
-
16
- function SortableItem(props: {
17
- id: UniqueIdentifier;
18
- itemRenderer: (
19
- nodeRef: React.ComponentProps<any>,
20
- actionNodeRef: React.ComponentProps<any>
21
- ) => React.ReactElement;
22
- style?: React.CSSProperties;
23
- }) {
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
- }
56
-
57
- /**
58
- * DnD list forward ref
59
- */
60
- export interface DnDListRef<D extends object> {
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
- }
86
-
87
- /**
88
- * DnD sortable list properties
89
- */
90
- export interface DnDListPros<
91
- D extends object,
92
- K extends DataTypes.Keys<D>,
93
- E extends React.ExoticComponent<{
94
- children?: React.ReactNode | undefined;
95
- }> = typeof React.Fragment
96
- > {
97
- /**
98
- * Component type to render the list into
99
- * Default is React.Fragment
100
- */
101
- component?: E;
102
-
103
- /**
104
- * Component props
105
- */
106
- componentProps?: React.ComponentProps<E>;
107
-
108
- /**
109
- * Get list item style callback
110
- */
111
- getItemStyle: (index: number, isDragging: boolean) => CSSProperties;
112
-
113
- /**
114
- * Item renderer
115
- */
116
- itemRenderer: (
117
- item: D,
118
- index: number,
119
- nodeRef: React.ComponentProps<any>,
120
- actionNodeRef: React.ComponentProps<any>
121
- ) => React.ReactElement;
122
-
123
- /**
124
- * List items
125
- */
126
- items: D[];
127
-
128
- /**
129
- * Unique key field
130
- */
131
- keyField: K;
132
-
133
- /**
134
- * Label field
135
- */
136
- labelField: K;
137
-
138
- /**
139
- * Methods ref
140
- */
141
- mRef?: React.Ref<DnDListRef<D>>;
142
-
143
- /**
144
- * Data change handler
145
- */
146
- onChange?: (items: D[]) => void;
147
-
148
- /**
149
- * Drag end handler
150
- */
151
- onDragEnd?: (items: D[]) => void;
152
- }
153
-
154
- /**
155
- * DnD (Drag and Drop) sortable list
156
- * @param props Props
157
- * @returns Component
158
- */
159
- export function DnDList<
160
- D extends { id: UniqueIdentifier },
161
- K extends DataTypes.Keys<D, UniqueIdentifier> = DataTypes.Keys<
162
- D,
163
- UniqueIdentifier
164
- >
165
- >(props: DnDListPros<D, K>) {
166
- // Destruct
167
- const {
168
- componentProps,
169
- getItemStyle,
170
- keyField,
171
- itemRenderer,
172
- labelField,
173
- mRef,
174
- onChange,
175
- onDragEnd
176
- } = props;
177
-
178
- const Component = props.component || React.Fragment;
179
-
180
- // States
181
- const [items, setItems] = React.useState<D[]>([]);
182
- const [activeId, setActiveId] = React.useState<UniqueIdentifier>();
183
-
184
- const changeItems = (newItems: D[]) => {
185
- // Possible to alter items with the handler
186
- if (onChange) onChange(newItems);
187
-
188
- // Update state
189
- setItems(newItems);
190
- };
191
-
192
- // Drag event handlers
193
- function handleDragStart(event: DragStartEvent) {
194
- const { active } = event;
195
- setActiveId(active.id);
196
- }
197
-
198
- function handleDragEnd(event: DragEndEvent) {
199
- const { active, over } = event;
200
-
201
- if (over && active.id !== over.id) {
202
- // Indices
203
- const oldIndex = items.findIndex((item) => item.id === active.id);
204
- const newIndex = items.findIndex((item) => item.id === over.id);
205
-
206
- // Clone
207
- const newItems = [...items];
208
-
209
- // Removed item
210
- const [removed] = newItems.splice(oldIndex, 1);
211
-
212
- // Insert to the destination index
213
- newItems.splice(newIndex, 0, removed);
214
-
215
- changeItems(newItems);
216
-
217
- // Drag end handler
218
- if (onDragEnd) onDragEnd(newItems);
219
- }
220
-
221
- setActiveId(undefined);
222
- }
223
-
224
- // Methods
225
- React.useImperativeHandle(
226
- mRef,
227
- () => {
228
- return {
229
- addItem(newItem: D) {
230
- // Existence check
231
- if (items.some((item) => item[labelField] === newItem[labelField])) {
232
- return false;
233
- }
234
-
235
- // Clone
236
- const newItems = [newItem, ...items];
237
-
238
- // Update the state
239
- changeItems(newItems);
240
-
241
- return true;
242
- },
243
-
244
- addItems(inputItems: D[]) {
245
- // Clone
246
- const newItems = [...items];
247
-
248
- // Insert items
249
- inputItems.forEach((newItem) => {
250
- // Existence check
251
- if (
252
- newItems.some((item) => item[labelField] === newItem[labelField])
253
- ) {
254
- return;
255
- }
256
-
257
- newItems.push(newItem);
258
- });
259
-
260
- // Update the state
261
- changeItems(newItems);
262
-
263
- return newItems.length - items.length;
264
- },
265
-
266
- editItem(newItem: D, index: number) {
267
- // Existence check
268
- const newIndex = items.findIndex(
269
- (item) => item[labelField] === newItem[labelField]
270
- );
271
- if (newIndex >= 0 && newIndex !== index) {
272
- // Label field is the same with a different item
273
- return false;
274
- }
275
-
276
- // Clone
277
- const newItems = [...items];
278
-
279
- // Remove the item
280
- newItems.splice(index, 1, newItem);
281
-
282
- // Update the state
283
- changeItems(newItems);
284
-
285
- return true;
286
- },
287
-
288
- deleteItem(index: number) {
289
- // Clone
290
- const newItems = [...items];
291
-
292
- // Remove the item
293
- newItems.splice(index, 1);
294
-
295
- // Update the state
296
- changeItems(newItems);
297
- }
298
- };
299
- },
300
- [items]
301
- );
302
-
303
- React.useEffect(() => {
304
- setItems(props.items);
305
- }, [props.items]);
306
-
307
- return (
308
- <DndContext onDragStart={handleDragStart} onDragEnd={handleDragEnd}>
309
- <SortableContext items={items} strategy={verticalListSortingStrategy}>
310
- <Component {...componentProps}>
311
- {items.map((item, index) => {
312
- const id = item[keyField] as unknown as UniqueIdentifier;
313
- return (
314
- <SortableItem
315
- id={id}
316
- key={id}
317
- style={getItemStyle(index, id === activeId)}
318
- itemRenderer={(nodeRef, actionNodeRef) =>
319
- itemRenderer(item, index, nodeRef, actionNodeRef)
320
- }
321
- />
322
- );
323
- })}
324
- </Component>
325
- </SortableContext>
326
- </DndContext>
327
- );
328
- }