@etsoo/react 1.8.22 → 1.8.24

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.
Files changed (132) hide show
  1. package/lib/cjs/app/CoreConstants.js +17 -0
  2. package/lib/cjs/app/EventWatcher.js +45 -0
  3. package/lib/cjs/app/InputDialogProps.js +2 -0
  4. package/lib/cjs/app/ReactUtils.js +173 -0
  5. package/lib/cjs/components/DnDList.js +136 -0
  6. package/lib/cjs/components/DynamicRouter.js +39 -0
  7. package/lib/cjs/components/GridColumn.js +46 -0
  8. package/lib/cjs/components/GridLoader.js +49 -0
  9. package/lib/cjs/components/GridMethodRef.js +2 -0
  10. package/lib/cjs/components/ListItemReact.js +2 -0
  11. package/lib/cjs/components/ScrollRestoration.js +37 -0
  12. package/lib/cjs/components/ScrollerGrid.js +254 -0
  13. package/lib/cjs/components/ScrollerList.js +205 -0
  14. package/lib/cjs/custom/CustomFieldReact.js +2 -0
  15. package/lib/cjs/index.js +54 -0
  16. package/lib/cjs/notifier/Notifier.js +82 -0
  17. package/lib/cjs/states/CultureState.js +46 -0
  18. package/lib/cjs/states/IState.js +2 -0
  19. package/lib/cjs/states/PageState.js +46 -0
  20. package/lib/cjs/states/State.js +48 -0
  21. package/lib/cjs/states/UserState.js +80 -0
  22. package/lib/cjs/uses/useAsyncState.js +39 -0
  23. package/lib/cjs/uses/useCombinedRefs.js +29 -0
  24. package/lib/cjs/uses/useDelayedExecutor.js +17 -0
  25. package/lib/cjs/uses/useDimensions.js +98 -0
  26. package/lib/cjs/uses/useParamsEx.js +15 -0
  27. package/lib/cjs/uses/useRefs.js +17 -0
  28. package/lib/cjs/uses/useRequiredContext.js +19 -0
  29. package/lib/cjs/uses/useSearchParamsEx.js +19 -0
  30. package/lib/cjs/uses/useTimeout.js +29 -0
  31. package/lib/cjs/uses/useWindowScroll.js +53 -0
  32. package/lib/cjs/uses/useWindowSize.js +53 -0
  33. package/lib/mjs/app/CoreConstants.d.ts +13 -0
  34. package/lib/mjs/app/EventWatcher.d.ts +35 -0
  35. package/lib/mjs/app/InputDialogProps.d.ts +19 -0
  36. package/lib/mjs/app/ReactUtils.d.ts +41 -0
  37. package/lib/mjs/components/DnDList.d.ts +74 -0
  38. package/lib/mjs/components/DynamicRouter.d.ts +24 -0
  39. package/lib/mjs/components/GridColumn.d.ts +193 -0
  40. package/lib/mjs/components/GridLoader.d.ts +155 -0
  41. package/lib/mjs/components/GridMethodRef.d.ts +31 -0
  42. package/lib/mjs/components/ListItemReact.d.ts +6 -0
  43. package/lib/mjs/components/ScrollRestoration.d.ts +4 -0
  44. package/lib/mjs/components/ScrollerGrid.d.ts +112 -0
  45. package/lib/mjs/components/ScrollerList.d.ts +66 -0
  46. package/lib/mjs/custom/CustomFieldReact.d.ts +22 -0
  47. package/lib/mjs/index.d.ts +33 -0
  48. package/lib/mjs/notifier/Notifier.d.ts +143 -0
  49. package/lib/mjs/states/CultureState.d.ts +41 -0
  50. package/lib/mjs/states/IState.d.ts +49 -0
  51. package/lib/mjs/states/PageState.d.ts +61 -0
  52. package/lib/mjs/states/State.d.ts +18 -0
  53. package/lib/mjs/states/UserState.d.ts +56 -0
  54. package/lib/mjs/uses/useAsyncState.d.ts +11 -0
  55. package/lib/mjs/uses/useCombinedRefs.d.ts +6 -0
  56. package/lib/mjs/uses/useDelayedExecutor.d.ts +5 -0
  57. package/lib/mjs/uses/useDimensions.d.ts +17 -0
  58. package/lib/mjs/uses/useParamsEx.d.ts +6 -0
  59. package/lib/mjs/uses/useRefs.d.ts +8 -0
  60. package/lib/mjs/uses/useRequiredContext.d.ts +7 -0
  61. package/lib/mjs/uses/useSearchParamsEx.d.ts +6 -0
  62. package/lib/mjs/uses/useTimeout.d.ts +8 -0
  63. package/lib/mjs/uses/useWindowScroll.d.ts +12 -0
  64. package/lib/mjs/uses/useWindowSize.d.ts +10 -0
  65. package/package.json +14 -9
  66. package/tsconfig.cjs.json +20 -0
  67. package/tsconfig.json +2 -2
  68. /package/lib/{app → cjs/app}/CoreConstants.d.ts +0 -0
  69. /package/lib/{app → cjs/app}/EventWatcher.d.ts +0 -0
  70. /package/lib/{app → cjs/app}/InputDialogProps.d.ts +0 -0
  71. /package/lib/{app → cjs/app}/ReactUtils.d.ts +0 -0
  72. /package/lib/{components → cjs/components}/DnDList.d.ts +0 -0
  73. /package/lib/{components → cjs/components}/DynamicRouter.d.ts +0 -0
  74. /package/lib/{components → cjs/components}/GridColumn.d.ts +0 -0
  75. /package/lib/{components → cjs/components}/GridLoader.d.ts +0 -0
  76. /package/lib/{components → cjs/components}/GridMethodRef.d.ts +0 -0
  77. /package/lib/{components → cjs/components}/ListItemReact.d.ts +0 -0
  78. /package/lib/{components → cjs/components}/ScrollRestoration.d.ts +0 -0
  79. /package/lib/{components → cjs/components}/ScrollerGrid.d.ts +0 -0
  80. /package/lib/{components → cjs/components}/ScrollerList.d.ts +0 -0
  81. /package/lib/{custom → cjs/custom}/CustomFieldReact.d.ts +0 -0
  82. /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
  83. /package/lib/{notifier → cjs/notifier}/Notifier.d.ts +0 -0
  84. /package/lib/{states → cjs/states}/CultureState.d.ts +0 -0
  85. /package/lib/{states → cjs/states}/IState.d.ts +0 -0
  86. /package/lib/{states → cjs/states}/PageState.d.ts +0 -0
  87. /package/lib/{states → cjs/states}/State.d.ts +0 -0
  88. /package/lib/{states → cjs/states}/UserState.d.ts +0 -0
  89. /package/lib/{uses → cjs/uses}/useAsyncState.d.ts +0 -0
  90. /package/lib/{uses → cjs/uses}/useCombinedRefs.d.ts +0 -0
  91. /package/lib/{uses → cjs/uses}/useDelayedExecutor.d.ts +0 -0
  92. /package/lib/{uses → cjs/uses}/useDimensions.d.ts +0 -0
  93. /package/lib/{uses → cjs/uses}/useParamsEx.d.ts +0 -0
  94. /package/lib/{uses → cjs/uses}/useRefs.d.ts +0 -0
  95. /package/lib/{uses → cjs/uses}/useRequiredContext.d.ts +0 -0
  96. /package/lib/{uses → cjs/uses}/useSearchParamsEx.d.ts +0 -0
  97. /package/lib/{uses → cjs/uses}/useTimeout.d.ts +0 -0
  98. /package/lib/{uses → cjs/uses}/useWindowScroll.d.ts +0 -0
  99. /package/lib/{uses → cjs/uses}/useWindowSize.d.ts +0 -0
  100. /package/lib/{app → mjs/app}/CoreConstants.js +0 -0
  101. /package/lib/{app → mjs/app}/EventWatcher.js +0 -0
  102. /package/lib/{app → mjs/app}/InputDialogProps.js +0 -0
  103. /package/lib/{app → mjs/app}/ReactUtils.js +0 -0
  104. /package/lib/{components → mjs/components}/DnDList.js +0 -0
  105. /package/lib/{components → mjs/components}/DynamicRouter.js +0 -0
  106. /package/lib/{components → mjs/components}/GridColumn.js +0 -0
  107. /package/lib/{components → mjs/components}/GridLoader.js +0 -0
  108. /package/lib/{components → mjs/components}/GridMethodRef.js +0 -0
  109. /package/lib/{components → mjs/components}/ListItemReact.js +0 -0
  110. /package/lib/{components → mjs/components}/ScrollRestoration.js +0 -0
  111. /package/lib/{components → mjs/components}/ScrollerGrid.js +0 -0
  112. /package/lib/{components → mjs/components}/ScrollerList.js +0 -0
  113. /package/lib/{custom → mjs/custom}/CustomFieldReact.js +0 -0
  114. /package/lib/{index.js → mjs/index.js} +0 -0
  115. /package/lib/{notifier → mjs/notifier}/Notifier.js +0 -0
  116. /package/lib/{states → mjs/states}/CultureState.js +0 -0
  117. /package/lib/{states → mjs/states}/IState.js +0 -0
  118. /package/lib/{states → mjs/states}/PageState.js +0 -0
  119. /package/lib/{states → mjs/states}/State.js +0 -0
  120. /package/lib/{states → mjs/states}/UserState.js +0 -0
  121. /package/lib/{uses → mjs/uses}/useAsyncState.js +0 -0
  122. /package/lib/{uses → mjs/uses}/useCombinedRefs.js +0 -0
  123. /package/lib/{uses → mjs/uses}/useDelayedExecutor.js +0 -0
  124. /package/lib/{uses → mjs/uses}/useDimensions.js +0 -0
  125. /package/lib/{uses → mjs/uses}/useParamsEx.js +0 -0
  126. /package/lib/{uses → mjs/uses}/useRefs.js +0 -0
  127. /package/lib/{uses → mjs/uses}/useRequiredContext.js +0 -0
  128. /package/lib/{uses → mjs/uses}/useSearchParamsEx.js +0 -0
  129. /package/lib/{uses → mjs/uses}/useTimeout.js +0 -0
  130. /package/lib/{uses → mjs/uses}/useWindowScroll.js +0 -0
  131. /package/lib/{uses → mjs/uses}/useWindowSize.js +0 -0
  132. /package/{vite.config.ts → vite.config.mts} +0 -0
@@ -0,0 +1,41 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import React from "react";
3
+ /**
4
+ * React utils
5
+ */
6
+ export declare namespace ReactUtils {
7
+ /**
8
+ * Format input value
9
+ * @param value Input value
10
+ * @returns Formatted value
11
+ */
12
+ function formatInputValue(value: unknown): string | number | any[] | undefined;
13
+ /**
14
+ * Is safe click
15
+ * @param event Mouse event
16
+ * @returns Result
17
+ */
18
+ function isSafeClick(event: React.MouseEvent<HTMLElement>): boolean;
19
+ /**
20
+ * Trigger input change event
21
+ * @param input Form input
22
+ * @param value New value
23
+ * @param cancelable Cancelable
24
+ */
25
+ function triggerChange(input: HTMLInputElement, value: string, cancelable?: boolean): void;
26
+ /**
27
+ * Update refs
28
+ * @param refs Refs
29
+ * @param data Data
30
+ * @param callback Callback to update refs' value, return false continue to process
31
+ */
32
+ function updateRefs<D extends object, T = HTMLInputElement>(refs: Partial<DataTypes.DI<ReadonlyArray<keyof D & string>, React.MutableRefObject<T | null>>>, data: D, callback?: ((item: T, value: D[keyof D & string]) => void | boolean) | keyof T): void;
33
+ /**
34
+ * Update data with refs
35
+ * @param refs Refs
36
+ * @param data Data
37
+ * @param callback Callback to return new value
38
+ * @param ignoreEmpty Ignore empty string or not, default true
39
+ */
40
+ function updateRefValues<D extends object, T = HTMLInputElement>(refs: Partial<DataTypes.DI<ReadonlyArray<keyof D & string>, React.MutableRefObject<T | null>>>, data: D, callback?: ((item: T) => any) | keyof T, ignoreEmpty?: boolean): void;
41
+ }
@@ -0,0 +1,74 @@
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>> {
34
+ /**
35
+ * Get list item style callback
36
+ */
37
+ getItemStyle: (index: number, isDragging: boolean) => CSSProperties;
38
+ /**
39
+ * Item renderer
40
+ */
41
+ itemRenderer: (item: D, index: number, nodeRef: React.ComponentProps<any>, actionNodeRef: React.ComponentProps<any>) => React.ReactElement;
42
+ /**
43
+ * List items
44
+ */
45
+ items: D[];
46
+ /**
47
+ * Unique key field
48
+ */
49
+ keyField: K;
50
+ /**
51
+ * Label field
52
+ */
53
+ labelField: K;
54
+ /**
55
+ * Methods ref
56
+ */
57
+ mRef?: React.Ref<DnDListRef<D>>;
58
+ /**
59
+ * Data change handler
60
+ */
61
+ onChange?: (items: D[]) => void;
62
+ /**
63
+ * Drag end handler
64
+ */
65
+ onDragEnd?: (items: D[]) => void;
66
+ }
67
+ /**
68
+ * DnD (Drag and Drop) sortable list
69
+ * @param props Props
70
+ * @returns Component
71
+ */
72
+ export declare function DnDList<D extends {
73
+ id: UniqueIdentifier;
74
+ }, K extends DataTypes.Keys<D, UniqueIdentifier> = DataTypes.Keys<D, UniqueIdentifier>>(props: DnDListPros<D, K>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import { RouteObject } from "react-router";
3
+ /**
4
+ * Dynamic router props
5
+ */
6
+ export type DynamicRouterProps = {
7
+ /**
8
+ * basename of the router
9
+ */
10
+ basename?: string;
11
+ };
12
+ /**
13
+ * Dynamic router
14
+ * @param props Props
15
+ * @returns Component
16
+ */
17
+ export declare function DynamicRouter(props: React.PropsWithChildren<DynamicRouterProps>): import("react/jsx-runtime").JSX.Element;
18
+ /**
19
+ * Create dynamic router
20
+ * @param routes Routes
21
+ * @param opts Options
22
+ * @returns Router
23
+ */
24
+ export declare function createDynamicRouter(routes: RouteObject[], opts?: DynamicRouterProps): import("react-router").DataRouter;
@@ -0,0 +1,193 @@
1
+ import { EntityStatus } from "@etsoo/appscript";
2
+ import { DataTypes } from "@etsoo/shared";
3
+ import React from "react";
4
+ import { GridLoaderStates } from "./GridLoader";
5
+ import { ScrollerGridForwardRef } from "./ScrollerGrid";
6
+ /**
7
+ * Grid data type
8
+ */
9
+ import GridDataType = DataTypes.CombinedEnum;
10
+ export { GridDataType };
11
+ /**
12
+ * Grid align
13
+ */
14
+ export type GridAlign = "center" | "inherit" | "justify" | "left" | "right";
15
+ /**
16
+ * Data align get
17
+ * @param align Align
18
+ * @param type Data type
19
+ */
20
+ export declare const GridAlignGet: (align?: GridAlign, type?: GridDataType) => GridAlign | undefined;
21
+ /**
22
+ * Grid deleted cell box style
23
+ * @param data Data
24
+ * @returns Result
25
+ */
26
+ export declare const GridDeletedCellBoxStyle: (data: undefined | {
27
+ status: EntityStatus;
28
+ } | {
29
+ entityStatus: EntityStatus;
30
+ }) => React.CSSProperties;
31
+ /**
32
+ * Grid cell value type
33
+ */
34
+ export type GridCellValueType = string | number | Date | boolean | undefined;
35
+ /**
36
+ * Grid cell formatter props
37
+ */
38
+ export type GridCellFormatterProps<T> = {
39
+ /**
40
+ * Current data
41
+ */
42
+ data?: T;
43
+ /**
44
+ * Data field
45
+ */
46
+ field?: string;
47
+ /**
48
+ * Row index
49
+ */
50
+ rowIndex: number;
51
+ /**
52
+ * Column index
53
+ */
54
+ columnIndex: number;
55
+ };
56
+ /**
57
+ * Grid cell renderer props
58
+ */
59
+ export type GridCellRendererProps<T, P = any> = GridCellFormatterProps<T> & {
60
+ /**
61
+ * Cell props
62
+ */
63
+ cellProps: P;
64
+ /**
65
+ * Formatted value
66
+ */
67
+ formattedValue?: GridCellValueType;
68
+ /**
69
+ * Item selected
70
+ */
71
+ selected: boolean;
72
+ /**
73
+ * Data type
74
+ */
75
+ type?: GridDataType;
76
+ /**
77
+ * Render props
78
+ */
79
+ renderProps?: GridColumnRenderProps;
80
+ /**
81
+ * Set items for rerenderer
82
+ * @param callback Callback
83
+ */
84
+ setItems: (callback: (items: T[], ref?: ScrollerGridForwardRef<T>) => T[] | undefined | void) => void;
85
+ };
86
+ /**
87
+ * Grid header cell renderer props
88
+ */
89
+ export type GridHeaderCellRendererProps<T, P = any> = {
90
+ /**
91
+ * Cell props
92
+ */
93
+ cellProps: P;
94
+ /**
95
+ * Column
96
+ */
97
+ column: GridColumn<T>;
98
+ /**
99
+ * Column index
100
+ */
101
+ columnIndex: number;
102
+ /**
103
+ * States
104
+ */
105
+ states: GridLoaderStates<T>;
106
+ };
107
+ /**
108
+ * Grid column render props
109
+ */
110
+ export type GridColumnRenderProps = {
111
+ /**
112
+ * Culture, like zh-CN
113
+ */
114
+ readonly culture?: string;
115
+ /**
116
+ * Time zone
117
+ */
118
+ readonly timeZone?: string;
119
+ /**
120
+ * Currency, like USD for US dollar
121
+ */
122
+ readonly currency?: string;
123
+ /**
124
+ * Number format options
125
+ */
126
+ readonly numberFormatOptions?: Intl.NumberFormatOptions;
127
+ /**
128
+ * Near days to show alert
129
+ */
130
+ readonly nearDays?: number;
131
+ /**
132
+ * Additional data
133
+ */
134
+ readonly data?: Readonly<Record<string, any>>;
135
+ };
136
+ /**
137
+ * Grid column
138
+ */
139
+ export type GridColumn<T> = {
140
+ /**
141
+ * The column identifier. It's used to map with row data
142
+ */
143
+ field?: string & keyof T;
144
+ /**
145
+ * The title of the column rendered in the column header cell
146
+ */
147
+ header?: string;
148
+ /**
149
+ * Set the width of the column
150
+ */
151
+ width?: number;
152
+ /**
153
+ * Sets the minimum width of a column
154
+ */
155
+ minWidth?: number;
156
+ /**
157
+ * Align
158
+ */
159
+ align?: GridAlign;
160
+ /**
161
+ * If `true`, the column is sortable
162
+ * @default true
163
+ */
164
+ sortable?: boolean;
165
+ /**
166
+ * Sort ascending or descending
167
+ */
168
+ sortAsc?: boolean;
169
+ /**
170
+ * Data type
171
+ */
172
+ type?: GridDataType;
173
+ /**
174
+ * Cell value formatter
175
+ */
176
+ valueFormatter?: (props: GridCellFormatterProps<T>) => GridCellValueType;
177
+ /**
178
+ * Cell renderer
179
+ */
180
+ cellRenderer?: (props: GridCellRendererProps<T>) => React.ReactNode;
181
+ /**
182
+ * Cell box style
183
+ */
184
+ cellBoxStyle?: ((data: T | undefined) => React.CSSProperties) | React.CSSProperties;
185
+ /**
186
+ * Render props
187
+ */
188
+ renderProps?: GridColumnRenderProps | ((data: T | undefined) => GridColumnRenderProps);
189
+ /**
190
+ * Header cell renderer
191
+ */
192
+ headerCellRenderer?: (props: GridHeaderCellRendererProps<T>) => React.ReactNode;
193
+ };
@@ -0,0 +1,155 @@
1
+ import { QueryPagingData, QueryPagingOrder } from "@etsoo/appscript";
2
+ import { DataTypes } from "@etsoo/shared";
3
+ /**
4
+ * Grid size
5
+ */
6
+ export type GridSize = number | ((input: number) => number);
7
+ /**
8
+ * Grid size calculation
9
+ * @param size Size
10
+ * @param input Input
11
+ */
12
+ export declare const GridSizeGet: (size: GridSize, input: number) => number;
13
+ /**
14
+ * Grid data type
15
+ */
16
+ export type GridData = FormData | DataTypes.StringRecord;
17
+ /**
18
+ * Grid template type
19
+ */
20
+ export type GridTemplateType<T> = DataTypes.BasicTemplateType<{
21
+ [k in keyof T]: T[k] extends "date" ? "date" | "string" : T[k] extends DataTypes.BasicNames ? T[k] : never;
22
+ }>;
23
+ /**
24
+ * Grid data get with format
25
+ * @param data Data
26
+ * @param template Template
27
+ * @param keepSource Keep source data
28
+ * @returns Json data
29
+ */
30
+ export declare function GridDataGet<const T>(props: GridLoadDataProps, template?: T, keepSource?: boolean): GridJsonData & GridTemplateType<T>;
31
+ /**
32
+ * Grid data get with format
33
+ * @param data Data
34
+ * @param template Template
35
+ * @param keepSource Keep source data
36
+ * @returns Json data
37
+ */
38
+ export declare function GridDataGetData<const T>(data?: GridData, template?: T, keepSource?: boolean): GridTemplateType<T>;
39
+ /**
40
+ * Grid Json data
41
+ */
42
+ export type GridJsonData = {
43
+ /**
44
+ * Query paging data
45
+ */
46
+ queryPaging: QueryPagingData;
47
+ };
48
+ /**
49
+ * Grid data load props
50
+ */
51
+ export type GridLoadDataProps = GridJsonData & {
52
+ /**
53
+ * Data related
54
+ */
55
+ data?: GridData;
56
+ };
57
+ /**
58
+ * Grid data load partial props
59
+ */
60
+ export type GridLoadDataPartialProps = {
61
+ /**
62
+ * Query paging data
63
+ */
64
+ queryPaging?: Partial<QueryPagingData>;
65
+ /**
66
+ * Data related
67
+ */
68
+ data?: GridData;
69
+ };
70
+ /**
71
+ * Grid data loader
72
+ */
73
+ export type GridLoader<T extends object, P extends GridJsonData = GridLoadDataProps> = {
74
+ /**
75
+ * Auto load data, otherwise call reset
76
+ * @default true
77
+ */
78
+ autoLoad?: boolean;
79
+ /**
80
+ * Default order by
81
+ */
82
+ defaultOrderBy?: QueryPagingOrder[];
83
+ /**
84
+ * Batch size when load data, default will be calcuated with height and itemSize
85
+ */
86
+ loadBatchSize?: GridSize;
87
+ /**
88
+ * Load data
89
+ */
90
+ loadData: (props: P, lastItem?: T) => PromiseLike<T[] | null | undefined>;
91
+ /**
92
+ * Handler for init load
93
+ * @param ref Ref
94
+ * @returns Result
95
+ */
96
+ onInitLoad?: (ref: any) => [T[], GridLoaderPartialStates<T>?] | null | undefined;
97
+ /**
98
+ * Handler for updating rows
99
+ * @param rows Rows
100
+ * @param state State
101
+ */
102
+ onUpdateRows?: (rows: T[], state: GridLoaderStates<T>) => void;
103
+ /**
104
+ * Threshold at which to pre-fetch data; default is half of loadBatchSize
105
+ */
106
+ threshold?: number | undefined;
107
+ };
108
+ type GridLoaderProps<T> = {
109
+ /**
110
+ * Auto load data, otherwise call reset
111
+ * @default true
112
+ */
113
+ autoLoad: boolean;
114
+ /**
115
+ * Last loaded item
116
+ */
117
+ lastItem?: T;
118
+ /**
119
+ * Last loaded items
120
+ */
121
+ lastLoadedItems?: number;
122
+ /**
123
+ * All loaded items count
124
+ */
125
+ loadedItems: number;
126
+ /**
127
+ * Has next page?
128
+ */
129
+ hasNextPage: boolean;
130
+ /**
131
+ * Is next page loading?
132
+ */
133
+ isNextPageLoading: boolean;
134
+ /**
135
+ * Is mounted
136
+ */
137
+ isMounted?: boolean;
138
+ /**
139
+ * Selected items of id
140
+ */
141
+ selectedItems: T[];
142
+ /**
143
+ * Id cache
144
+ */
145
+ idCache: Record<any, null>;
146
+ };
147
+ /**
148
+ * Grid loader states
149
+ */
150
+ export type GridLoaderStates<T> = GridLoadDataProps & GridLoaderProps<T>;
151
+ /**
152
+ * Grid loader states
153
+ */
154
+ export type GridLoaderPartialStates<T> = GridLoadDataPartialProps & Partial<GridLoaderProps<T>>;
155
+ export {};
@@ -0,0 +1,31 @@
1
+ import { Align } from "react-window";
2
+ import { GridLoaderPartialStates } from "./GridLoader";
3
+ /**
4
+ * Grid method ref
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;
18
+ /**
19
+ * Reset
20
+ * @param add Additional data
21
+ */
22
+ reset(add?: GridLoaderPartialStates<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;
31
+ }
@@ -0,0 +1,6 @@
1
+ import { ListItem } from "@etsoo/appscript";
2
+ import React from "react";
3
+ /**
4
+ * React list item
5
+ */
6
+ export type ListItemReact = ListItem<React.ReactNode, React.MouseEvent>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Scroll restoration
3
+ */
4
+ export declare function ScrollRestoration(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,112 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import React from "react";
3
+ import { Align, GridChildComponentProps, VariableSizeGridProps } from "react-window";
4
+ import { GridJsonData, GridLoadDataProps, GridLoader, GridLoaderStates } from "./GridLoader";
5
+ import { GridMethodRef } from "./GridMethodRef";
6
+ export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>, "data"> & {
7
+ /**
8
+ * Selected items
9
+ */
10
+ selectedItems: T[];
11
+ /**
12
+ * Set items for rerenderer
13
+ * @param callback Callback
14
+ */
15
+ setItems: (callback: (items: T[], ref: ScrollerGridForwardRef<T>) => T[] | undefined | void) => void;
16
+ /**
17
+ * Data
18
+ */
19
+ data?: T;
20
+ };
21
+ /**
22
+ * Scroller vertical grid props
23
+ */
24
+ export type ScrollerGridProps<T extends object, P extends GridJsonData = GridLoadDataProps> = GridLoader<T, P> & Omit<VariableSizeGridProps<T>, "children" | "rowCount" | "rowHeight"> & {
25
+ /**
26
+ * Footer renderer
27
+ */
28
+ footerRenderer?: (rows: T[], states: GridLoaderStates<T>) => React.ReactNode;
29
+ /**
30
+ * Header renderer
31
+ */
32
+ headerRenderer?: (states: GridLoaderStates<T>) => React.ReactNode;
33
+ /**
34
+ * Id field
35
+ */
36
+ idField?: DataTypes.Keys<T>;
37
+ /**
38
+ * Item renderer
39
+ */
40
+ itemRenderer: (props: ScrollerGridItemRendererProps<T>) => React.ReactElement;
41
+ /**
42
+ * Methods
43
+ */
44
+ mRef?: React.Ref<ScrollerGridForwardRef<T>>;
45
+ /**
46
+ * On items select change
47
+ */
48
+ onSelectChange?: (selectedItems: T[]) => void;
49
+ /**
50
+ * Returns the height of the specified row.
51
+ */
52
+ rowHeight?: ((index: number) => number) | number;
53
+ };
54
+ /**
55
+ * Scroller grid forward ref
56
+ */
57
+ export interface ScrollerGridForwardRef<T> extends GridMethodRef<T> {
58
+ /**
59
+ * Scroll to the specified offsets
60
+ */
61
+ scrollTo(params: {
62
+ scrollLeft: number;
63
+ scrollTop: number;
64
+ }): void;
65
+ scrollToItem(params: {
66
+ align?: Align | undefined;
67
+ columnIndex?: number | undefined;
68
+ rowIndex?: number | undefined;
69
+ }): void;
70
+ /**
71
+ * Scroll to the specified item
72
+ */
73
+ scrollToItem(params: {
74
+ align?: Align | undefined;
75
+ columnIndex?: number | undefined;
76
+ rowIndex?: number | undefined;
77
+ }): void;
78
+ /**
79
+ * Select the item
80
+ * @param rowIndex Row index
81
+ */
82
+ select(rowIndex: number): void;
83
+ /**
84
+ * Select or unselect all items
85
+ * @param checked Checked
86
+ */
87
+ selectAll(checked: boolean): void;
88
+ /**
89
+ * Select item
90
+ * @param item Item
91
+ * @param checked Checked
92
+ */
93
+ selectItem(item: any, checked: boolean): void;
94
+ /**
95
+ *
96
+ * @param index
97
+ * @param shouldForceUpdate
98
+ */
99
+ resetAfterColumnIndex(index: number, shouldForceUpdate?: boolean): void;
100
+ resetAfterIndices(params: {
101
+ columnIndex: number;
102
+ rowIndex: number;
103
+ shouldForceUpdate?: boolean | undefined;
104
+ }): void;
105
+ resetAfterRowIndex(index: number, shouldForceUpdate?: boolean): void;
106
+ }
107
+ /**
108
+ * Scroller vertical grid
109
+ * @param props Props
110
+ * @returns Component
111
+ */
112
+ export declare const ScrollerGrid: <T extends object>(props: ScrollerGridProps<T>) => import("react/jsx-runtime").JSX.Element;