@etsoo/react 1.7.93 → 1.7.95
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.
- package/README.md +2 -1
- package/__tests__/EventWatcher.tsx +21 -21
- package/__tests__/ReactUtils.ts +4 -4
- package/__tests__/tsconfig.json +17 -17
- package/babel.config.json +8 -8
- package/lib/app/CoreConstants.js +2 -2
- package/lib/app/EventWatcher.d.ts +1 -1
- package/lib/app/EventWatcher.js +3 -5
- package/lib/app/InputDialogProps.d.ts +2 -2
- package/lib/app/ReactUtils.d.ts +2 -2
- package/lib/app/ReactUtils.js +20 -19
- package/lib/components/DnDList.d.ts +3 -3
- package/lib/components/DnDList.js +4 -4
- package/lib/components/DynamicRouter.d.ts +9 -1
- package/lib/components/DynamicRouter.js +18 -2
- package/lib/components/GridColumn.d.ts +6 -6
- package/lib/components/GridColumn.js +7 -7
- package/lib/components/GridLoader.d.ts +4 -4
- package/lib/components/GridLoader.js +2 -2
- package/lib/components/GridMethodRef.d.ts +2 -2
- package/lib/components/ListItemReact.d.ts +2 -2
- package/lib/components/ScrollRestoration.js +3 -3
- package/lib/components/ScrollerGrid.d.ts +7 -12
- package/lib/components/ScrollerGrid.js +13 -17
- package/lib/components/ScrollerList.d.ts +6 -10
- package/lib/components/ScrollerList.js +15 -14
- package/lib/custom/CustomFieldReact.d.ts +1 -1
- package/lib/index.d.ts +32 -32
- package/lib/index.js +31 -31
- package/lib/notifier/Notifier.d.ts +5 -5
- package/lib/notifier/Notifier.js +7 -7
- package/lib/states/CultureState.d.ts +3 -3
- package/lib/states/CultureState.js +3 -3
- package/lib/states/IState.d.ts +2 -2
- package/lib/states/PageState.d.ts +2 -2
- package/lib/states/PageState.js +2 -3
- package/lib/states/State.d.ts +3 -3
- package/lib/states/State.js +2 -2
- package/lib/states/UserState.d.ts +2 -2
- package/lib/states/UserState.js +5 -5
- package/lib/uses/useAsyncState.d.ts +1 -1
- package/lib/uses/useAsyncState.js +1 -1
- package/lib/uses/useCombinedRefs.js +2 -2
- package/lib/uses/useDelayedExecutor.d.ts +1 -1
- package/lib/uses/useDelayedExecutor.js +2 -2
- package/lib/uses/useDimensions.d.ts +1 -1
- package/lib/uses/useDimensions.js +3 -3
- package/lib/uses/useParamsEx.d.ts +1 -1
- package/lib/uses/useParamsEx.js +2 -2
- package/lib/uses/useRefs.d.ts +2 -2
- package/lib/uses/useRefs.js +1 -1
- package/lib/uses/useSearchParamsEx.d.ts +1 -1
- package/lib/uses/useSearchParamsEx.js +3 -3
- package/lib/uses/useTimeout.js +2 -2
- package/lib/uses/useWindowScroll.js +3 -3
- package/lib/uses/useWindowSize.js +4 -5
- package/package.json +72 -74
- package/src/app/CoreConstants.ts +8 -8
- package/src/app/EventWatcher.ts +50 -52
- package/src/app/InputDialogProps.ts +16 -16
- package/src/app/ReactUtils.ts +206 -208
- package/src/components/DnDList.tsx +268 -283
- package/src/components/DynamicRouter.tsx +46 -21
- package/src/components/GridColumn.ts +201 -201
- package/src/components/GridLoader.ts +121 -121
- package/src/components/GridMethodRef.ts +26 -26
- package/src/components/ListItemReact.ts +2 -2
- package/src/components/ScrollRestoration.tsx +24 -24
- package/src/components/ScrollerGrid.tsx +428 -448
- package/src/components/ScrollerList.tsx +320 -332
- package/src/custom/CustomFieldReact.ts +12 -12
- package/src/index.ts +35 -35
- package/src/notifier/Notifier.ts +229 -240
- package/src/states/CultureState.ts +51 -52
- package/src/states/IState.ts +19 -19
- package/src/states/PageState.ts +63 -66
- package/src/states/State.tsx +47 -51
- package/src/states/UserState.ts +98 -98
- package/src/uses/useAsyncState.ts +37 -39
- package/src/uses/useCombinedRefs.ts +16 -16
- package/src/uses/useDelayedExecutor.ts +8 -8
- package/src/uses/useDimensions.ts +102 -103
- package/src/uses/useParamsEx.ts +6 -6
- package/src/uses/useRefs.ts +6 -6
- package/src/uses/useSearchParamsEx.ts +13 -13
- package/src/uses/useTimeout.ts +17 -17
- package/src/uses/useWindowScroll.ts +43 -43
- package/src/uses/useWindowSize.ts +46 -49
- package/tsconfig.json +17 -17
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -38
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
package/README.md
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { render, screen } from
|
|
2
|
-
import React from
|
|
3
|
-
import { EventWatcher } from
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { EventWatcher } from "../src/app/EventWatcher";
|
|
4
4
|
|
|
5
5
|
function App(props: { callback: () => void }) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const { callback } = props;
|
|
7
|
+
const watcher = new EventWatcher();
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
React.useEffect(() => {
|
|
10
|
+
watcher.add({
|
|
11
|
+
type: "click",
|
|
12
|
+
action: (_event) => callback(),
|
|
13
|
+
once: true
|
|
14
|
+
});
|
|
15
|
+
}, []);
|
|
16
|
+
return <button onClick={(event) => watcher.do(event)}></button>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
test(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
test("Tests for EventWatcher", () => {
|
|
20
|
+
const callback = jest.fn();
|
|
21
|
+
render(<App callback={callback} />);
|
|
22
|
+
const button = screen.getByRole<HTMLButtonElement>("button");
|
|
23
|
+
button.click();
|
|
24
|
+
expect(callback).toHaveBeenCalled();
|
|
25
|
+
button.click();
|
|
26
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
27
27
|
});
|
package/__tests__/ReactUtils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ReactUtils } from
|
|
1
|
+
import { ReactUtils } from "../src/app/ReactUtils";
|
|
2
2
|
|
|
3
|
-
test(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
test("Tests for ReactUtils.formatInputValue", () => {
|
|
4
|
+
expect(ReactUtils.formatInputValue([1, "a"])).toEqual([1, "a"]);
|
|
5
|
+
expect(ReactUtils.formatInputValue(true)).toEqual("true");
|
|
6
6
|
});
|
package/__tests__/tsconfig.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node10",
|
|
6
|
+
"allowJs": false,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"jsx": "react",
|
|
16
|
+
"declaration": true
|
|
17
|
+
},
|
|
18
|
+
"include": [".."]
|
|
19
19
|
}
|
package/babel.config.json
CHANGED
package/lib/app/CoreConstants.js
CHANGED
|
@@ -6,9 +6,9 @@ export var CoreConstants;
|
|
|
6
6
|
/**
|
|
7
7
|
* User id saved field
|
|
8
8
|
*/
|
|
9
|
-
CoreConstants.FieldUserIdSaved =
|
|
9
|
+
CoreConstants.FieldUserIdSaved = "UserIdSaved";
|
|
10
10
|
/**
|
|
11
11
|
* Rresh token cache field
|
|
12
12
|
*/
|
|
13
|
-
CoreConstants.FieldRefreshToken =
|
|
13
|
+
CoreConstants.FieldRefreshToken = "RefreshToken";
|
|
14
14
|
})(CoreConstants || (CoreConstants = {}));
|
package/lib/app/EventWatcher.js
CHANGED
|
@@ -18,7 +18,7 @@ export class EventWatcher {
|
|
|
18
18
|
*/
|
|
19
19
|
do(event) {
|
|
20
20
|
// Type
|
|
21
|
-
const type = typeof event ===
|
|
21
|
+
const type = typeof event === "string" ? event : event.type;
|
|
22
22
|
// Execute
|
|
23
23
|
const removeIndices = [];
|
|
24
24
|
this.actions.forEach((item, index) => {
|
|
@@ -29,14 +29,12 @@ export class EventWatcher {
|
|
|
29
29
|
removeIndices.push(index);
|
|
30
30
|
});
|
|
31
31
|
// Remove all once actions
|
|
32
|
-
removeIndices
|
|
33
|
-
.reverse()
|
|
34
|
-
.forEach((index) => this.actions.splice(index, 1));
|
|
32
|
+
removeIndices.reverse().forEach((index) => this.actions.splice(index, 1));
|
|
35
33
|
}
|
|
36
34
|
isMatch(action, type) {
|
|
37
35
|
if (action.type == null)
|
|
38
36
|
return true;
|
|
39
|
-
if (typeof action.type ===
|
|
37
|
+
if (typeof action.type === "string")
|
|
40
38
|
return action.type === type;
|
|
41
39
|
return action.type.includes(type);
|
|
42
40
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NotificationContent, NotificationReturn } from
|
|
2
|
-
import { NotificationReactCallProps } from
|
|
1
|
+
import { NotificationContent, NotificationReturn } from "@etsoo/notificationbase";
|
|
2
|
+
import { NotificationReactCallProps } from "../notifier/Notifier";
|
|
3
3
|
/**
|
|
4
4
|
* Input dialog props
|
|
5
5
|
*/
|
package/lib/app/ReactUtils.d.ts
CHANGED
package/lib/app/ReactUtils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateUtils, DomUtils, Utils } from
|
|
1
|
+
import { DateUtils, DomUtils, Utils } from "@etsoo/shared";
|
|
2
2
|
/**
|
|
3
3
|
* React utils
|
|
4
4
|
*/
|
|
@@ -12,9 +12,9 @@ export var ReactUtils;
|
|
|
12
12
|
function formatInputValue(value) {
|
|
13
13
|
if (value === null)
|
|
14
14
|
return undefined;
|
|
15
|
-
if (typeof value ===
|
|
15
|
+
if (typeof value === "number")
|
|
16
16
|
return value;
|
|
17
|
-
if (typeof value ===
|
|
17
|
+
if (typeof value === "string")
|
|
18
18
|
return value;
|
|
19
19
|
if (Array.isArray(value))
|
|
20
20
|
return value;
|
|
@@ -37,10 +37,10 @@ export var ReactUtils;
|
|
|
37
37
|
return false;
|
|
38
38
|
while (target != null && target != event.currentTarget) {
|
|
39
39
|
const nodeName = target.nodeName.toUpperCase();
|
|
40
|
-
if (nodeName ===
|
|
41
|
-
nodeName ===
|
|
42
|
-
nodeName ===
|
|
43
|
-
target.hasAttribute(
|
|
40
|
+
if (nodeName === "INPUT" ||
|
|
41
|
+
nodeName === "BUTTON" ||
|
|
42
|
+
nodeName === "A" ||
|
|
43
|
+
target.hasAttribute("onClick"))
|
|
44
44
|
return false;
|
|
45
45
|
target = target.parentElement;
|
|
46
46
|
}
|
|
@@ -55,12 +55,12 @@ export var ReactUtils;
|
|
|
55
55
|
*/
|
|
56
56
|
function triggerChange(input, value, cancelable = false) {
|
|
57
57
|
// Radio type not supported
|
|
58
|
-
if (input.type ===
|
|
58
|
+
if (input.type === "radio")
|
|
59
59
|
return;
|
|
60
60
|
// checked?
|
|
61
|
-
const checked = input.type ===
|
|
61
|
+
const checked = input.type === "checkbox";
|
|
62
62
|
// Property name
|
|
63
|
-
const property = checked ?
|
|
63
|
+
const property = checked ? "checked" : "value";
|
|
64
64
|
// input.value = newValue will not trigger the change event
|
|
65
65
|
// input type = 'hidden' will also not trigger the event
|
|
66
66
|
// https://coryrylan.com/blog/trigger-input-updates-with-react-controlled-inputs
|
|
@@ -68,7 +68,7 @@ export var ReactUtils;
|
|
|
68
68
|
if (checked) {
|
|
69
69
|
const checkedValue = input.value == value;
|
|
70
70
|
nativeInputValueSetter?.call(input, checkedValue);
|
|
71
|
-
const clickEvent = new Event(
|
|
71
|
+
const clickEvent = new Event("click", {
|
|
72
72
|
bubbles: true,
|
|
73
73
|
cancelable
|
|
74
74
|
});
|
|
@@ -76,7 +76,7 @@ export var ReactUtils;
|
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
78
|
nativeInputValueSetter?.call(input, value);
|
|
79
|
-
const inputEvent = new Event(
|
|
79
|
+
const inputEvent = new Event("change", {
|
|
80
80
|
bubbles: true,
|
|
81
81
|
cancelable
|
|
82
82
|
});
|
|
@@ -93,7 +93,7 @@ export var ReactUtils;
|
|
|
93
93
|
function updateRefs(refs, data, callback) {
|
|
94
94
|
const local = callback == null
|
|
95
95
|
? undefined
|
|
96
|
-
: typeof callback ===
|
|
96
|
+
: typeof callback === "function"
|
|
97
97
|
? callback
|
|
98
98
|
: (item, value) => {
|
|
99
99
|
item[callback] = value;
|
|
@@ -111,13 +111,14 @@ export var ReactUtils;
|
|
|
111
111
|
item instanceof HTMLTextAreaElement ||
|
|
112
112
|
item instanceof HTMLSelectElement) {
|
|
113
113
|
const value = Utils.getNestedValue(data, item.name || k);
|
|
114
|
-
const isDateTime = item.type ===
|
|
115
|
-
if (isDateTime || item.type ===
|
|
114
|
+
const isDateTime = item.type === "datetime-local";
|
|
115
|
+
if (isDateTime || item.type === "date") {
|
|
116
116
|
item.value =
|
|
117
|
-
DateUtils.formatForInput(value, isDateTime ? false : undefined) ??
|
|
117
|
+
DateUtils.formatForInput(value, isDateTime ? false : undefined) ??
|
|
118
|
+
"";
|
|
118
119
|
}
|
|
119
120
|
else {
|
|
120
|
-
item.value = `${value ??
|
|
121
|
+
item.value = `${value ?? ""}`;
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
else {
|
|
@@ -136,11 +137,11 @@ export var ReactUtils;
|
|
|
136
137
|
function updateRefValues(refs, data, callback, ignoreEmpty = true) {
|
|
137
138
|
const local = callback == null
|
|
138
139
|
? undefined
|
|
139
|
-
: typeof callback ===
|
|
140
|
+
: typeof callback === "function"
|
|
140
141
|
? callback
|
|
141
142
|
: (item) => item[callback];
|
|
142
143
|
const formatValue = (value) => {
|
|
143
|
-
if (ignoreEmpty && value ===
|
|
144
|
+
if (ignoreEmpty && value === "")
|
|
144
145
|
return null;
|
|
145
146
|
return value;
|
|
146
147
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { UniqueIdentifier } from
|
|
2
|
-
import { DataTypes } from
|
|
3
|
-
import React, { CSSProperties } from
|
|
1
|
+
import { UniqueIdentifier } from "@dnd-kit/core";
|
|
2
|
+
import { DataTypes } from "@etsoo/shared";
|
|
3
|
+
import React, { CSSProperties } from "react";
|
|
4
4
|
/**
|
|
5
5
|
* DnD list forward ref
|
|
6
6
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { DndContext } from
|
|
3
|
-
import { SortableContext, useSortable, verticalListSortingStrategy } from
|
|
4
|
-
import { CSS } from
|
|
5
|
-
import React from
|
|
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
6
|
function SortableItem(props) {
|
|
7
7
|
// Destruct
|
|
8
8
|
const { id, itemRenderer, style = {} } = props;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { RouteObject } from "react-router-dom";
|
|
2
3
|
/**
|
|
3
4
|
* Dynamic router props
|
|
4
5
|
*/
|
|
@@ -14,3 +15,10 @@ export type DynamicRouterProps = {
|
|
|
14
15
|
* @returns Component
|
|
15
16
|
*/
|
|
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("@remix-run/router").Router;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { BridgeUtils } from
|
|
3
|
-
import { BrowserRouter, MemoryRouter } from
|
|
2
|
+
import { BridgeUtils } from "@etsoo/appscript";
|
|
3
|
+
import { BrowserRouter, createBrowserRouter, createMemoryRouter, MemoryRouter } from "react-router-dom";
|
|
4
4
|
function getEntries(host) {
|
|
5
5
|
const startUrl = host.getStartUrl();
|
|
6
6
|
return startUrl == null ? undefined : [startUrl];
|
|
@@ -17,3 +17,19 @@ export function DynamicRouter(props) {
|
|
|
17
17
|
const host = BridgeUtils.host;
|
|
18
18
|
return host == null ? (_jsx(BrowserRouter, { basename: basename, children: children })) : (_jsx(MemoryRouter, { basename: basename, initialEntries: getEntries(host), children: children }));
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Create dynamic router
|
|
22
|
+
* @param routes Routes
|
|
23
|
+
* @param opts Options
|
|
24
|
+
* @returns Router
|
|
25
|
+
*/
|
|
26
|
+
export function createDynamicRouter(routes, opts) {
|
|
27
|
+
// Is host?
|
|
28
|
+
const host = BridgeUtils.host;
|
|
29
|
+
if (host == null) {
|
|
30
|
+
return createBrowserRouter(routes, opts);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return createMemoryRouter(routes, opts);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EntityStatus } from
|
|
2
|
-
import { DataTypes } from
|
|
3
|
-
import React from
|
|
4
|
-
import { GridLoaderStates } from
|
|
5
|
-
import { ScrollerGridForwardRef } from
|
|
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
6
|
/**
|
|
7
7
|
* Grid data type
|
|
8
8
|
*/
|
|
@@ -11,7 +11,7 @@ export { GridDataType };
|
|
|
11
11
|
/**
|
|
12
12
|
* Grid align
|
|
13
13
|
*/
|
|
14
|
-
export type GridAlign =
|
|
14
|
+
export type GridAlign = "center" | "inherit" | "justify" | "left" | "right";
|
|
15
15
|
/**
|
|
16
16
|
* Data align get
|
|
17
17
|
* @param align Align
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EntityStatus } from
|
|
2
|
-
import { DataTypes } from
|
|
1
|
+
import { EntityStatus } from "@etsoo/appscript";
|
|
2
|
+
import { DataTypes } from "@etsoo/shared";
|
|
3
3
|
/**
|
|
4
4
|
* Grid data type
|
|
5
5
|
*/
|
|
@@ -16,9 +16,9 @@ export const GridAlignGet = (align, type) => {
|
|
|
16
16
|
type === GridDataType.IntMoney ||
|
|
17
17
|
type === GridDataType.Int ||
|
|
18
18
|
type === GridDataType.Number)
|
|
19
|
-
return
|
|
19
|
+
return "right";
|
|
20
20
|
else if (type === GridDataType.Boolean)
|
|
21
|
-
return
|
|
21
|
+
return "center";
|
|
22
22
|
}
|
|
23
23
|
return align;
|
|
24
24
|
};
|
|
@@ -30,12 +30,12 @@ export const GridAlignGet = (align, type) => {
|
|
|
30
30
|
export const GridDeletedCellBoxStyle = (data) => {
|
|
31
31
|
if (data == null)
|
|
32
32
|
return {};
|
|
33
|
-
const status =
|
|
33
|
+
const status = "status" in data
|
|
34
34
|
? data.status
|
|
35
|
-
:
|
|
35
|
+
: "entityStatus" in data
|
|
36
36
|
? data.entityStatus
|
|
37
37
|
: EntityStatus.Normal;
|
|
38
38
|
if (status === EntityStatus.Inactivated || status === EntityStatus.Deleted)
|
|
39
|
-
return { textDecoration:
|
|
39
|
+
return { textDecoration: "line-through" };
|
|
40
40
|
return {};
|
|
41
41
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { QueryPagingData } from
|
|
2
|
-
import { DataTypes } from
|
|
1
|
+
import { QueryPagingData } from "@etsoo/appscript";
|
|
2
|
+
import { DataTypes } from "@etsoo/shared";
|
|
3
3
|
/**
|
|
4
4
|
* Grid size
|
|
5
5
|
*/
|
|
@@ -29,7 +29,7 @@ export declare function GridDataGetData<F extends DataTypes.BasicTemplate>(data?
|
|
|
29
29
|
/**
|
|
30
30
|
* Grid Json data
|
|
31
31
|
*/
|
|
32
|
-
export type GridJsonData = Omit<GridLoadDataProps,
|
|
32
|
+
export type GridJsonData = Omit<GridLoadDataProps, "data">;
|
|
33
33
|
/**
|
|
34
34
|
* Grid data load props
|
|
35
35
|
*/
|
|
@@ -68,7 +68,7 @@ export interface GridLoader<T extends object> {
|
|
|
68
68
|
/**
|
|
69
69
|
* Default order by
|
|
70
70
|
*/
|
|
71
|
-
defaultOrderBy?: string
|
|
71
|
+
defaultOrderBy?: Record<string, boolean>;
|
|
72
72
|
/**
|
|
73
73
|
* Batch size when load data, default will be calcuated with height and itemSize
|
|
74
74
|
*/
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { DomUtils } from
|
|
1
|
+
import { DomUtils } from "@etsoo/shared";
|
|
2
2
|
/**
|
|
3
3
|
* Grid size calculation
|
|
4
4
|
* @param size Size
|
|
5
5
|
* @param input Input
|
|
6
6
|
*/
|
|
7
7
|
export const GridSizeGet = (size, input) => {
|
|
8
|
-
if (typeof size ===
|
|
8
|
+
if (typeof size === "function")
|
|
9
9
|
return size(input);
|
|
10
10
|
return size;
|
|
11
11
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React from
|
|
3
|
-
import { useLocation } from
|
|
4
|
-
import { useWindowScroll } from
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useLocation } from "react-router-dom";
|
|
4
|
+
import { useWindowScroll } from "../uses/useWindowScroll";
|
|
5
5
|
const urls = {};
|
|
6
6
|
/**
|
|
7
7
|
* Scroll restoration
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { DataTypes } from
|
|
2
|
-
import React from
|
|
3
|
-
import { Align, GridChildComponentProps, VariableSizeGridProps } from
|
|
4
|
-
import { GridLoader, GridLoaderStates } from
|
|
5
|
-
import { GridMethodRef } from
|
|
6
|
-
export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>,
|
|
1
|
+
import { DataTypes } from "@etsoo/shared";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Align, GridChildComponentProps, VariableSizeGridProps } from "react-window";
|
|
4
|
+
import { GridLoader, GridLoaderStates } from "./GridLoader";
|
|
5
|
+
import { GridMethodRef } from "./GridMethodRef";
|
|
6
|
+
export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>, "data"> & {
|
|
7
7
|
/**
|
|
8
8
|
* Selected items
|
|
9
9
|
*/
|
|
@@ -21,12 +21,7 @@ export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>,
|
|
|
21
21
|
/**
|
|
22
22
|
* Scroller vertical grid props
|
|
23
23
|
*/
|
|
24
|
-
export interface ScrollerGridProps<T extends object> extends GridLoader<T>, Omit<VariableSizeGridProps<T>,
|
|
25
|
-
/**
|
|
26
|
-
* Default order by asc
|
|
27
|
-
* @default true
|
|
28
|
-
*/
|
|
29
|
-
defaultOrderByAsc?: boolean;
|
|
24
|
+
export interface ScrollerGridProps<T extends object> extends GridLoader<T>, Omit<VariableSizeGridProps<T>, "children" | "rowCount" | "rowHeight"> {
|
|
30
25
|
/**
|
|
31
26
|
* Footer renderer
|
|
32
27
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React from
|
|
3
|
-
import { VariableSizeGrid } from
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { VariableSizeGrid } from "react-window";
|
|
4
4
|
/**
|
|
5
5
|
* Scroller vertical grid
|
|
6
6
|
* @param props Props
|
|
@@ -8,7 +8,7 @@ import { VariableSizeGrid } from 'react-window';
|
|
|
8
8
|
*/
|
|
9
9
|
export const ScrollerGrid = (props) => {
|
|
10
10
|
// Destruct
|
|
11
|
-
const { autoLoad = true, defaultOrderBy,
|
|
11
|
+
const { autoLoad = true, defaultOrderBy, footerRenderer, headerRenderer, itemRenderer, idField = "id", loadBatchSize, loadData, mRef, onItemsRendered, onSelectChange, rowHeight = 53, threshold = 6, width, onInitLoad, onUpdateRows, ...rest } = props;
|
|
12
12
|
// Rows
|
|
13
13
|
const [rows, updateRows] = React.useState([]);
|
|
14
14
|
const setRows = (rows, reset = false) => {
|
|
@@ -22,7 +22,6 @@ export const ScrollerGrid = (props) => {
|
|
|
22
22
|
queryPaging: {
|
|
23
23
|
currentPage: 0,
|
|
24
24
|
orderBy: defaultOrderBy,
|
|
25
|
-
orderByAsc: defaultOrderByAsc,
|
|
26
25
|
batchSize: 10
|
|
27
26
|
},
|
|
28
27
|
autoLoad,
|
|
@@ -54,8 +53,7 @@ export const ScrollerGrid = (props) => {
|
|
|
54
53
|
const newItems = result.length;
|
|
55
54
|
refs.current.lastLoadedItems = newItems;
|
|
56
55
|
refs.current.isNextPageLoading = false;
|
|
57
|
-
refs.current.hasNextPage =
|
|
58
|
-
newItems >= refs.current.queryPaging.batchSize;
|
|
56
|
+
refs.current.hasNextPage = newItems >= refs.current.queryPaging.batchSize;
|
|
59
57
|
if (pageAdd === 0) {
|
|
60
58
|
// New items
|
|
61
59
|
const newRows = refs.current.lastLoadedItems
|
|
@@ -73,7 +71,10 @@ export const ScrollerGrid = (props) => {
|
|
|
73
71
|
}
|
|
74
72
|
else {
|
|
75
73
|
// Set current page
|
|
76
|
-
refs.current.queryPaging.currentPage
|
|
74
|
+
if (refs.current.queryPaging.currentPage == null)
|
|
75
|
+
refs.current.queryPaging.currentPage = pageAdd;
|
|
76
|
+
else
|
|
77
|
+
refs.current.queryPaging.currentPage += pageAdd;
|
|
77
78
|
// Update rows, avoid duplicate items
|
|
78
79
|
const newRows = [...rows];
|
|
79
80
|
for (const item of result) {
|
|
@@ -89,9 +90,7 @@ export const ScrollerGrid = (props) => {
|
|
|
89
90
|
// Item renderer
|
|
90
91
|
const itemRendererLocal = (itemProps, state) => {
|
|
91
92
|
// Custom render
|
|
92
|
-
const data = itemProps.rowIndex < rows.length
|
|
93
|
-
? rows[itemProps.rowIndex]
|
|
94
|
-
: undefined;
|
|
93
|
+
const data = itemProps.rowIndex < rows.length ? rows[itemProps.rowIndex] : undefined;
|
|
95
94
|
return itemRenderer({
|
|
96
95
|
...itemProps,
|
|
97
96
|
data,
|
|
@@ -108,8 +107,7 @@ export const ScrollerGrid = (props) => {
|
|
|
108
107
|
const onItemsRenderedLocal = (props) => {
|
|
109
108
|
// No items, means no necessary to load more data during reset
|
|
110
109
|
const itemCount = rows.length;
|
|
111
|
-
if (itemCount > 0 &&
|
|
112
|
-
props.visibleRowStopIndex + threshold > itemCount) {
|
|
110
|
+
if (itemCount > 0 && props.visibleRowStopIndex + threshold > itemCount) {
|
|
113
111
|
// Auto load next page
|
|
114
112
|
loadDataLocal();
|
|
115
113
|
}
|
|
@@ -240,10 +238,8 @@ export const ScrollerGrid = (props) => {
|
|
|
240
238
|
// Layout
|
|
241
239
|
return (_jsxs(React.Fragment, { children: [headerRenderer && headerRenderer(refs.current), _jsx(VariableSizeGrid, { itemKey: ({ columnIndex, rowIndex, data }) => {
|
|
242
240
|
if (data == null)
|
|
243
|
-
return [rowIndex, columnIndex].join(
|
|
241
|
+
return [rowIndex, columnIndex].join(",");
|
|
244
242
|
// ${data[idField]}-${rowIndex} always unique but no cache for the same item
|
|
245
|
-
return [`${data[idField]}`, columnIndex].join(
|
|
246
|
-
}, onItemsRendered: onItemsRenderedLocal, ref: ref, rowCount: rowCount, rowHeight: typeof rowHeight ===
|
|
247
|
-
? rowHeight
|
|
248
|
-
: () => rowHeight, style: { overflowX: 'hidden' }, width: width, ...rest, children: (props) => itemRendererLocal(props, refs.current) }), footerRenderer && footerRenderer(rows, refs.current)] }));
|
|
243
|
+
return [`${data[idField]}`, columnIndex].join(",");
|
|
244
|
+
}, onItemsRendered: onItemsRenderedLocal, ref: ref, rowCount: rowCount, rowHeight: typeof rowHeight === "function" ? rowHeight : () => rowHeight, style: { overflowX: "hidden" }, width: width, ...rest, children: (props) => itemRendererLocal(props, refs.current) }), footerRenderer && footerRenderer(rows, refs.current)] }));
|
|
249
245
|
};
|