@etsoo/react 1.7.20 → 1.7.22

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.
@@ -1,11 +1,31 @@
1
+ import { Align } from 'react-window';
1
2
  import { GridLoaderStates } from './GridLoader';
2
3
  /**
3
4
  * Grid method ref
4
5
  */
5
6
  export interface GridMethodRef<T> {
7
+ /**
8
+ * Delete item at the index
9
+ * @param index Index
10
+ */
11
+ delete(index: number): T | undefined;
12
+ /**
13
+ * Insert the item at start
14
+ * @param item Item
15
+ * @param start Start position
16
+ */
17
+ insert(item: T, start: number): void;
6
18
  /**
7
19
  * Reset
8
20
  * @param add Additional data
9
21
  */
10
22
  reset(add?: Partial<GridLoaderStates<T>>): void;
23
+ /**
24
+ * Scroll to the specified offset (scrollTop or scrollLeft, depending on the direction prop).
25
+ */
26
+ scrollToRef(scrollOffset: number): void;
27
+ /**
28
+ * Scroll to the specified item.
29
+ */
30
+ scrollToItemRef(index: number, align?: Align): void;
11
31
  }
@@ -134,6 +134,20 @@ export const ScrollerGrid = (props) => {
134
134
  setRows(items, true);
135
135
  };
136
136
  const instance = {
137
+ delete(index) {
138
+ const item = rows.at(index);
139
+ if (item) {
140
+ const newRows = [...rows];
141
+ newRows.splice(index, 1);
142
+ setRows(newRows);
143
+ }
144
+ return item;
145
+ },
146
+ insert(item, start) {
147
+ const newRows = [...rows];
148
+ newRows.splice(start, 0, item);
149
+ setRows(newRows);
150
+ },
137
151
  scrollTo(params) {
138
152
  var _a;
139
153
  (_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollTo(params);
@@ -142,6 +156,14 @@ export const ScrollerGrid = (props) => {
142
156
  var _a;
143
157
  (_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollToItem(params);
144
158
  },
159
+ scrollToRef(scrollOffset) {
160
+ var _a;
161
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollTo({ scrollLeft: 0, scrollTop: scrollOffset });
162
+ },
163
+ scrollToItemRef(index, align) {
164
+ var _a;
165
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollToItem({ rowIndex: index, align });
166
+ },
145
167
  select(rowIndex) {
146
168
  // Select only one item
147
169
  const selectedItems = state.selectedItems;
@@ -56,7 +56,7 @@ export interface ScrollerListRef {
56
56
  /**
57
57
  * Scroller list forward ref
58
58
  */
59
- export interface ScrollerListForwardRef<T> extends GridMethodRef<T>, ScrollerListRef {
59
+ export interface ScrollerListForwardRef<T> extends GridMethodRef<T> {
60
60
  /**
61
61
  * Refresh latest page data
62
62
  */
@@ -129,14 +129,28 @@ export const ScrollerList = (props) => {
129
129
  React.useImperativeHandle(mRef, () => {
130
130
  const refMethods = listRef.current;
131
131
  return {
132
+ delete(index) {
133
+ const item = rows.at(index);
134
+ if (item) {
135
+ const newRows = [...rows];
136
+ newRows.splice(index, 1);
137
+ setRows(newRows);
138
+ }
139
+ return item;
140
+ },
141
+ insert(item, start) {
142
+ const newRows = [...rows];
143
+ newRows.splice(start, 0, item);
144
+ setRows(newRows);
145
+ },
132
146
  refresh() {
133
147
  loadDataLocal(0);
134
148
  },
135
149
  reset,
136
- scrollTo(scrollOffset) {
150
+ scrollToRef(scrollOffset) {
137
151
  refMethods.scrollTo(scrollOffset);
138
152
  },
139
- scrollToItem(index, align) {
153
+ scrollToItemRef(index, align) {
140
154
  refMethods.scrollToItem(index, align);
141
155
  }
142
156
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.7.20",
3
+ "version": "1.7.22",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,15 +50,15 @@
50
50
  "@emotion/css": "^11.11.2",
51
51
  "@emotion/react": "^11.11.1",
52
52
  "@emotion/styled": "^11.11.0",
53
- "@etsoo/appscript": "^1.4.62",
53
+ "@etsoo/appscript": "^1.4.66",
54
54
  "@etsoo/notificationbase": "^1.1.30",
55
55
  "@etsoo/shared": "^1.2.18",
56
- "@types/react": "^18.2.33",
56
+ "@types/react": "^18.2.34",
57
57
  "@types/react-dom": "^18.2.14",
58
58
  "@types/react-window": "^1.8.7",
59
59
  "react": "^18.2.0",
60
60
  "react-dom": "^18.2.0",
61
- "react-router-dom": "^6.17.0",
61
+ "react-router-dom": "^6.18.0",
62
62
  "react-window": "^1.8.9"
63
63
  },
64
64
  "devDependencies": {
@@ -1,12 +1,36 @@
1
+ import { Align } from 'react-window';
1
2
  import { GridLoaderStates } from './GridLoader';
2
3
 
3
4
  /**
4
5
  * Grid method ref
5
6
  */
6
7
  export interface GridMethodRef<T> {
8
+ /**
9
+ * Delete item at the index
10
+ * @param index Index
11
+ */
12
+ delete(index: number): T | undefined;
13
+
14
+ /**
15
+ * Insert the item at start
16
+ * @param item Item
17
+ * @param start Start position
18
+ */
19
+ insert(item: T, start: number): void;
20
+
7
21
  /**
8
22
  * Reset
9
23
  * @param add Additional data
10
24
  */
11
25
  reset(add?: Partial<GridLoaderStates<T>>): void;
26
+
27
+ /**
28
+ * Scroll to the specified offset (scrollTop or scrollLeft, depending on the direction prop).
29
+ */
30
+ scrollToRef(scrollOffset: number): void;
31
+
32
+ /**
33
+ * Scroll to the specified item.
34
+ */
35
+ scrollToItemRef(index: number, align?: Align): void;
12
36
  }
@@ -341,6 +341,20 @@ export const ScrollerGrid = <
341
341
  };
342
342
 
343
343
  const instance: ScrollerGridForwardRef<T> = {
344
+ delete(index) {
345
+ const item = rows.at(index);
346
+ if (item) {
347
+ const newRows = [...rows];
348
+ newRows.splice(index, 1);
349
+ setRows(newRows);
350
+ }
351
+ return item;
352
+ },
353
+ insert(item, start) {
354
+ const newRows = [...rows];
355
+ newRows.splice(start, 0, item);
356
+ setRows(newRows);
357
+ },
344
358
  scrollTo(params: { scrollLeft: number; scrollTop: number }) {
345
359
  ref.current?.scrollTo(params);
346
360
  },
@@ -351,6 +365,13 @@ export const ScrollerGrid = <
351
365
  }) {
352
366
  ref.current?.scrollToItem(params);
353
367
  },
368
+ scrollToRef(scrollOffset: number): void {
369
+ ref.current?.scrollTo({ scrollLeft: 0, scrollTop: scrollOffset });
370
+ },
371
+
372
+ scrollToItemRef(index: number, align?: Align): void {
373
+ ref.current?.scrollToItem({ rowIndex: index, align });
374
+ },
354
375
  select(rowIndex: number) {
355
376
  // Select only one item
356
377
  const selectedItems = state.selectedItems;
@@ -87,9 +87,7 @@ export interface ScrollerListRef {
87
87
  /**
88
88
  * Scroller list forward ref
89
89
  */
90
- export interface ScrollerListForwardRef<T>
91
- extends GridMethodRef<T>,
92
- ScrollerListRef {
90
+ export interface ScrollerListForwardRef<T> extends GridMethodRef<T> {
93
91
  /**
94
92
  * Refresh latest page data
95
93
  */
@@ -274,17 +272,31 @@ export const ScrollerList = <
274
272
  const refMethods = listRef.current as ScrollerListRef;
275
273
 
276
274
  return {
275
+ delete(index) {
276
+ const item = rows.at(index);
277
+ if (item) {
278
+ const newRows = [...rows];
279
+ newRows.splice(index, 1);
280
+ setRows(newRows);
281
+ }
282
+ return item;
283
+ },
284
+ insert(item, start) {
285
+ const newRows = [...rows];
286
+ newRows.splice(start, 0, item);
287
+ setRows(newRows);
288
+ },
277
289
  refresh(): void {
278
290
  loadDataLocal(0);
279
291
  },
280
292
 
281
293
  reset,
282
294
 
283
- scrollTo(scrollOffset: number): void {
295
+ scrollToRef(scrollOffset: number): void {
284
296
  refMethods.scrollTo(scrollOffset);
285
297
  },
286
298
 
287
- scrollToItem(index: number, align?: Align): void {
299
+ scrollToItemRef(index: number, align?: Align): void {
288
300
  refMethods.scrollToItem(index, align);
289
301
  }
290
302
  };