@etsoo/react 1.4.1 → 1.4.2

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.
@@ -6,7 +6,7 @@ export interface DnDListProps<D extends {}, E extends React.ElementType> {
6
6
  /**
7
7
  * Item renderer
8
8
  */
9
- children: (item: D, index: number, deleteItem: (index: number) => void, editItem: (newItem: D, indexOrLabel: number | string) => void) => React.ReactNode;
9
+ children: (item: D, index: number, deleteItem: (index: number) => void, editItem: (newItem: D, index: number) => boolean) => React.ReactNode;
10
10
  /**
11
11
  * List container component
12
12
  * https://javascript.plainenglish.io/building-a-polymorphic-component-in-react-and-typescript-d9f236950af4
package/lib/mu/DnDList.js CHANGED
@@ -30,7 +30,7 @@ export function DnDList(props) {
30
30
  // Add item
31
31
  const addItem = (newItem) => {
32
32
  // Existence check
33
- if (items.some((item) => item[labelField] == newItem[labelField])) {
33
+ if (items.some((item) => item[labelField] === newItem[labelField])) {
34
34
  return false;
35
35
  }
36
36
  // Clone
@@ -40,19 +40,18 @@ export function DnDList(props) {
40
40
  return true;
41
41
  };
42
42
  // Edit item
43
- const editItem = (newItem, indexOrLabel) => {
44
- const index = typeof indexOrLabel === 'number'
45
- ? indexOrLabel
46
- : items.findIndex((item) => DataTypes.convert(item[labelField], 'string') ==
47
- indexOrLabel);
48
- if (index === -1)
49
- return;
43
+ const editItem = (newItem, index) => {
44
+ // Existence check
45
+ if (items.some((item) => item[labelField] === newItem[labelField])) {
46
+ return false;
47
+ }
50
48
  // Clone
51
49
  const newItems = [...items];
52
50
  // Remove the item
53
51
  newItems.splice(index, 1, newItem);
54
52
  // Update the state
55
53
  setItems(newItems);
54
+ return true;
56
55
  };
57
56
  // Add items
58
57
  const addItems = (inputItems) => {
@@ -176,13 +176,10 @@ export class NotificationMU extends NotificationReact {
176
176
  input === null || input === void 0 ? void 0 : input.focus();
177
177
  return;
178
178
  }
179
- if (Array.isArray(v)) {
180
- if (!v[0]) {
181
- const error = v[1];
182
- setError(error);
183
- input === null || input === void 0 ? void 0 : input.focus();
184
- return;
185
- }
179
+ if (typeof v === 'string') {
180
+ setError(v);
181
+ input === null || input === void 0 ? void 0 : input.focus();
182
+ return;
186
183
  }
187
184
  this.dismiss();
188
185
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,8 +50,8 @@
50
50
  "@emotion/react": "^11.7.1",
51
51
  "@emotion/style": "^0.8.0",
52
52
  "@emotion/styled": "^11.6.0",
53
- "@etsoo/appscript": "^1.2.12",
54
- "@etsoo/notificationbase": "^1.0.96",
53
+ "@etsoo/appscript": "^1.2.15",
54
+ "@etsoo/notificationbase": "^1.1.0",
55
55
  "@etsoo/shared": "^1.0.97",
56
56
  "@mui/icons-material": "^5.2.5",
57
57
  "@mui/material": "^5.2.6",
@@ -18,7 +18,7 @@ export interface DnDListProps<D extends {}, E extends React.ElementType> {
18
18
  item: D,
19
19
  index: number,
20
20
  deleteItem: (index: number) => void,
21
- editItem: (newItem: D, indexOrLabel: number | string) => void
21
+ editItem: (newItem: D, index: number) => boolean
22
22
  ) => React.ReactNode;
23
23
 
24
24
  /**
@@ -116,7 +116,7 @@ export function DnDList<
116
116
  // Add item
117
117
  const addItem = (newItem: D) => {
118
118
  // Existence check
119
- if (items.some((item) => item[labelField] == newItem[labelField])) {
119
+ if (items.some((item) => item[labelField] === newItem[labelField])) {
120
120
  return false;
121
121
  }
122
122
 
@@ -130,16 +130,11 @@ export function DnDList<
130
130
  };
131
131
 
132
132
  // Edit item
133
- const editItem = (newItem: D, indexOrLabel: number | string) => {
134
- const index =
135
- typeof indexOrLabel === 'number'
136
- ? indexOrLabel
137
- : items.findIndex(
138
- (item) =>
139
- DataTypes.convert(item[labelField], 'string') ==
140
- indexOrLabel
141
- );
142
- if (index === -1) return;
133
+ const editItem = (newItem: D, index: number) => {
134
+ // Existence check
135
+ if (items.some((item) => item[labelField] === newItem[labelField])) {
136
+ return false;
137
+ }
143
138
 
144
139
  // Clone
145
140
  const newItems = [...items];
@@ -149,6 +144,8 @@ export function DnDList<
149
144
 
150
145
  // Update the state
151
146
  setItems(newItems);
147
+
148
+ return true;
152
149
  };
153
150
 
154
151
  // Add items
@@ -253,10 +253,9 @@ export class NotificationMU extends NotificationReact {
253
253
  // Result
254
254
  let result:
255
255
  | boolean
256
- | [boolean, string | undefined]
256
+ | string
257
257
  | void
258
- | PromiseLike<boolean | [boolean, string | undefined] | void> =
259
- undefined;
258
+ | PromiseLike<boolean | string | void> = undefined;
260
259
 
261
260
  const input = inputRef.current;
262
261
 
@@ -302,13 +301,10 @@ export class NotificationMU extends NotificationReact {
302
301
  input?.focus();
303
302
  return;
304
303
  }
305
- if (Array.isArray(v)) {
306
- if (!v[0]) {
307
- const error = v[1];
308
- setError(error);
309
- input?.focus();
310
- return;
311
- }
304
+ if (typeof v === 'string') {
305
+ setError(v);
306
+ input?.focus();
307
+ return;
312
308
  }
313
309
 
314
310
  this.dismiss();