@etsoo/react 1.8.21 → 1.8.23

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 (135) hide show
  1. package/__tests__/EventWatcher.tsx +2 -1
  2. package/__tests__/States.tsx +27 -29
  3. package/__tests__/tsconfig.json +5 -4
  4. package/lib/cjs/app/CoreConstants.js +17 -0
  5. package/lib/cjs/app/EventWatcher.js +45 -0
  6. package/lib/cjs/app/InputDialogProps.js +2 -0
  7. package/lib/cjs/app/ReactUtils.js +173 -0
  8. package/lib/cjs/components/DnDList.js +136 -0
  9. package/lib/cjs/components/DynamicRouter.js +39 -0
  10. package/lib/cjs/components/GridColumn.js +46 -0
  11. package/lib/cjs/components/GridLoader.js +49 -0
  12. package/lib/cjs/components/GridMethodRef.js +2 -0
  13. package/lib/cjs/components/ListItemReact.js +2 -0
  14. package/lib/cjs/components/ScrollRestoration.js +37 -0
  15. package/lib/cjs/components/ScrollerGrid.js +254 -0
  16. package/lib/cjs/components/ScrollerList.js +205 -0
  17. package/lib/cjs/custom/CustomFieldReact.js +2 -0
  18. package/lib/cjs/index.js +54 -0
  19. package/lib/cjs/notifier/Notifier.js +82 -0
  20. package/lib/cjs/states/CultureState.js +46 -0
  21. package/lib/cjs/states/IState.js +2 -0
  22. package/lib/cjs/states/PageState.js +46 -0
  23. package/lib/cjs/states/State.js +48 -0
  24. package/lib/cjs/states/UserState.js +80 -0
  25. package/lib/cjs/uses/useAsyncState.js +39 -0
  26. package/lib/cjs/uses/useCombinedRefs.js +29 -0
  27. package/lib/cjs/uses/useDelayedExecutor.js +17 -0
  28. package/lib/cjs/uses/useDimensions.js +98 -0
  29. package/lib/cjs/uses/useParamsEx.js +15 -0
  30. package/lib/cjs/uses/useRefs.js +17 -0
  31. package/lib/cjs/uses/useRequiredContext.js +19 -0
  32. package/lib/cjs/uses/useSearchParamsEx.js +19 -0
  33. package/lib/cjs/uses/useTimeout.js +29 -0
  34. package/lib/cjs/uses/useWindowScroll.js +53 -0
  35. package/lib/cjs/uses/useWindowSize.js +53 -0
  36. package/lib/mjs/app/CoreConstants.d.ts +13 -0
  37. package/lib/mjs/app/EventWatcher.d.ts +35 -0
  38. package/lib/mjs/app/InputDialogProps.d.ts +19 -0
  39. package/lib/mjs/app/ReactUtils.d.ts +41 -0
  40. package/lib/mjs/components/DnDList.d.ts +74 -0
  41. package/lib/mjs/components/DynamicRouter.d.ts +24 -0
  42. package/lib/mjs/components/GridColumn.d.ts +193 -0
  43. package/lib/mjs/components/GridLoader.d.ts +155 -0
  44. package/lib/mjs/components/GridMethodRef.d.ts +31 -0
  45. package/lib/mjs/components/ListItemReact.d.ts +6 -0
  46. package/lib/mjs/components/ScrollRestoration.d.ts +4 -0
  47. package/lib/mjs/components/ScrollerGrid.d.ts +112 -0
  48. package/lib/mjs/components/ScrollerList.d.ts +66 -0
  49. package/lib/mjs/custom/CustomFieldReact.d.ts +22 -0
  50. package/lib/mjs/index.d.ts +33 -0
  51. package/lib/mjs/notifier/Notifier.d.ts +143 -0
  52. package/lib/mjs/states/CultureState.d.ts +41 -0
  53. package/lib/mjs/states/IState.d.ts +49 -0
  54. package/lib/mjs/states/PageState.d.ts +61 -0
  55. package/lib/mjs/states/State.d.ts +18 -0
  56. package/lib/mjs/states/UserState.d.ts +56 -0
  57. package/lib/mjs/uses/useAsyncState.d.ts +11 -0
  58. package/lib/mjs/uses/useCombinedRefs.d.ts +6 -0
  59. package/lib/mjs/uses/useDelayedExecutor.d.ts +5 -0
  60. package/lib/mjs/uses/useDimensions.d.ts +17 -0
  61. package/lib/mjs/uses/useParamsEx.d.ts +6 -0
  62. package/lib/mjs/uses/useRefs.d.ts +8 -0
  63. package/lib/mjs/uses/useRequiredContext.d.ts +7 -0
  64. package/lib/mjs/uses/useSearchParamsEx.d.ts +6 -0
  65. package/lib/mjs/uses/useTimeout.d.ts +8 -0
  66. package/lib/mjs/uses/useWindowScroll.d.ts +12 -0
  67. package/lib/mjs/uses/useWindowSize.d.ts +10 -0
  68. package/package.json +21 -24
  69. package/tsconfig.cjs.json +20 -0
  70. package/tsconfig.json +3 -3
  71. package/vite.config.ts +11 -0
  72. /package/lib/{app → cjs/app}/CoreConstants.d.ts +0 -0
  73. /package/lib/{app → cjs/app}/EventWatcher.d.ts +0 -0
  74. /package/lib/{app → cjs/app}/InputDialogProps.d.ts +0 -0
  75. /package/lib/{app → cjs/app}/ReactUtils.d.ts +0 -0
  76. /package/lib/{components → cjs/components}/DnDList.d.ts +0 -0
  77. /package/lib/{components → cjs/components}/DynamicRouter.d.ts +0 -0
  78. /package/lib/{components → cjs/components}/GridColumn.d.ts +0 -0
  79. /package/lib/{components → cjs/components}/GridLoader.d.ts +0 -0
  80. /package/lib/{components → cjs/components}/GridMethodRef.d.ts +0 -0
  81. /package/lib/{components → cjs/components}/ListItemReact.d.ts +0 -0
  82. /package/lib/{components → cjs/components}/ScrollRestoration.d.ts +0 -0
  83. /package/lib/{components → cjs/components}/ScrollerGrid.d.ts +0 -0
  84. /package/lib/{components → cjs/components}/ScrollerList.d.ts +0 -0
  85. /package/lib/{custom → cjs/custom}/CustomFieldReact.d.ts +0 -0
  86. /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
  87. /package/lib/{notifier → cjs/notifier}/Notifier.d.ts +0 -0
  88. /package/lib/{states → cjs/states}/CultureState.d.ts +0 -0
  89. /package/lib/{states → cjs/states}/IState.d.ts +0 -0
  90. /package/lib/{states → cjs/states}/PageState.d.ts +0 -0
  91. /package/lib/{states → cjs/states}/State.d.ts +0 -0
  92. /package/lib/{states → cjs/states}/UserState.d.ts +0 -0
  93. /package/lib/{uses → cjs/uses}/useAsyncState.d.ts +0 -0
  94. /package/lib/{uses → cjs/uses}/useCombinedRefs.d.ts +0 -0
  95. /package/lib/{uses → cjs/uses}/useDelayedExecutor.d.ts +0 -0
  96. /package/lib/{uses → cjs/uses}/useDimensions.d.ts +0 -0
  97. /package/lib/{uses → cjs/uses}/useParamsEx.d.ts +0 -0
  98. /package/lib/{uses → cjs/uses}/useRefs.d.ts +0 -0
  99. /package/lib/{uses → cjs/uses}/useRequiredContext.d.ts +0 -0
  100. /package/lib/{uses → cjs/uses}/useSearchParamsEx.d.ts +0 -0
  101. /package/lib/{uses → cjs/uses}/useTimeout.d.ts +0 -0
  102. /package/lib/{uses → cjs/uses}/useWindowScroll.d.ts +0 -0
  103. /package/lib/{uses → cjs/uses}/useWindowSize.d.ts +0 -0
  104. /package/lib/{app → mjs/app}/CoreConstants.js +0 -0
  105. /package/lib/{app → mjs/app}/EventWatcher.js +0 -0
  106. /package/lib/{app → mjs/app}/InputDialogProps.js +0 -0
  107. /package/lib/{app → mjs/app}/ReactUtils.js +0 -0
  108. /package/lib/{components → mjs/components}/DnDList.js +0 -0
  109. /package/lib/{components → mjs/components}/DynamicRouter.js +0 -0
  110. /package/lib/{components → mjs/components}/GridColumn.js +0 -0
  111. /package/lib/{components → mjs/components}/GridLoader.js +0 -0
  112. /package/lib/{components → mjs/components}/GridMethodRef.js +0 -0
  113. /package/lib/{components → mjs/components}/ListItemReact.js +0 -0
  114. /package/lib/{components → mjs/components}/ScrollRestoration.js +0 -0
  115. /package/lib/{components → mjs/components}/ScrollerGrid.js +0 -0
  116. /package/lib/{components → mjs/components}/ScrollerList.js +0 -0
  117. /package/lib/{custom → mjs/custom}/CustomFieldReact.js +0 -0
  118. /package/lib/{index.js → mjs/index.js} +0 -0
  119. /package/lib/{notifier → mjs/notifier}/Notifier.js +0 -0
  120. /package/lib/{states → mjs/states}/CultureState.js +0 -0
  121. /package/lib/{states → mjs/states}/IState.js +0 -0
  122. /package/lib/{states → mjs/states}/PageState.js +0 -0
  123. /package/lib/{states → mjs/states}/State.js +0 -0
  124. /package/lib/{states → mjs/states}/UserState.js +0 -0
  125. /package/lib/{uses → mjs/uses}/useAsyncState.js +0 -0
  126. /package/lib/{uses → mjs/uses}/useCombinedRefs.js +0 -0
  127. /package/lib/{uses → mjs/uses}/useDelayedExecutor.js +0 -0
  128. /package/lib/{uses → mjs/uses}/useDimensions.js +0 -0
  129. /package/lib/{uses → mjs/uses}/useParamsEx.js +0 -0
  130. /package/lib/{uses → mjs/uses}/useRefs.js +0 -0
  131. /package/lib/{uses → mjs/uses}/useRequiredContext.js +0 -0
  132. /package/lib/{uses → mjs/uses}/useSearchParamsEx.js +0 -0
  133. /package/lib/{uses → mjs/uses}/useTimeout.js +0 -0
  134. /package/lib/{uses → mjs/uses}/useWindowScroll.js +0 -0
  135. /package/lib/{uses → mjs/uses}/useWindowSize.js +0 -0
@@ -0,0 +1,66 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import React from "react";
3
+ import { Align, ListChildComponentProps, ListProps } from "react-window";
4
+ import { GridLoader } from "./GridLoader";
5
+ import { GridMethodRef } from "./GridMethodRef";
6
+ /**
7
+ * Scroller vertical list props
8
+ */
9
+ export type ScrollerListProps<T extends object> = GridLoader<T> & Omit<ListProps<T>, "outerRef" | "height" | "width" | "children" | "itemCount"> & {
10
+ /**
11
+ * Methods ref
12
+ */
13
+ mRef?: React.Ref<ScrollerListForwardRef<T>>;
14
+ /**
15
+ * Outer div ref
16
+ */
17
+ oRef?: React.Ref<HTMLDivElement>;
18
+ /**
19
+ * Height of the list
20
+ */
21
+ height?: number;
22
+ /**
23
+ * Width of the list
24
+ */
25
+ width?: number | string;
26
+ /**
27
+ * Id field
28
+ */
29
+ idField?: DataTypes.Keys<T>;
30
+ /**
31
+ * Item renderer
32
+ */
33
+ itemRenderer: (props: ListChildComponentProps<T>) => React.ReactElement;
34
+ /**
35
+ * Item size, a function indicates its a variable size list
36
+ */
37
+ itemSize: ((index: number) => number) | number;
38
+ };
39
+ /**
40
+ * Scroller list ref
41
+ */
42
+ export interface ScrollerListRef {
43
+ /**
44
+ * Scroll to the specified offset (scrollTop or scrollLeft, depending on the direction prop).
45
+ */
46
+ scrollTo(scrollOffset: number): void;
47
+ /**
48
+ * Scroll to the specified item.
49
+ */
50
+ scrollToItem(index: number, align?: Align): void;
51
+ }
52
+ /**
53
+ * Scroller list forward ref
54
+ */
55
+ export interface ScrollerListForwardRef<T> extends GridMethodRef<T> {
56
+ /**
57
+ * Refresh latest page data
58
+ */
59
+ refresh(): void;
60
+ }
61
+ /**
62
+ * Scroller vertical list
63
+ * @param props Props
64
+ * @returns Component
65
+ */
66
+ export declare const ScrollerList: <T extends object>(props: ScrollerListProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { CustomFieldData, CustomFieldProps, CustomFieldRef, ICustomField } from "@etsoo/appscript";
2
+ /**
3
+ * React custom field interface
4
+ * React自定义字段接口
5
+ */
6
+ export interface ICustomFieldReact<V, D extends CustomFieldData = CustomFieldData> extends ICustomField<V, D, CustomFieldReactProps<V, D>, React.JSX.Element> {
7
+ }
8
+ /**
9
+ * React custom field props
10
+ * React自定义字段属性
11
+ */
12
+ export type CustomFieldReactProps<V, D extends CustomFieldData = CustomFieldData> = CustomFieldProps<D, V> & {
13
+ mref: React.Ref<CustomFieldRef<V>>;
14
+ };
15
+ /**
16
+ * React custom field renderer collection
17
+ * React自定义字段渲染结果集合
18
+ */
19
+ export type CustomFieldReactCollection<D extends CustomFieldData> = Record<string, [
20
+ React.RefObject<CustomFieldRef<unknown>>,
21
+ D
22
+ ]>;
@@ -0,0 +1,33 @@
1
+ export * from "./app/CoreConstants";
2
+ export * from "./app/EventWatcher";
3
+ export * from "./app/InputDialogProps";
4
+ export * from "./app/ReactUtils";
5
+ export * from "./components/DnDList";
6
+ export * from "./components/DynamicRouter";
7
+ export * from "./components/GridColumn";
8
+ export * from "./components/GridLoader";
9
+ export * from "./components/GridMethodRef";
10
+ export * from "./components/ListItemReact";
11
+ export * from "./components/ScrollerGrid";
12
+ export * from "./components/ScrollerList";
13
+ export * from "./components/ScrollRestoration";
14
+ export type { ListOnScrollProps, GridOnScrollProps, VariableSizeGrid } from "react-window";
15
+ export * from "./custom/CustomFieldReact";
16
+ export * from "./notifier/Notifier";
17
+ export * from "@etsoo/notificationbase";
18
+ export * from "./states/CultureState";
19
+ export * from "./states/IState";
20
+ export * from "./states/PageState";
21
+ export * from "./states/State";
22
+ export * from "./states/UserState";
23
+ export * from "./uses/useAsyncState";
24
+ export * from "./uses/useCombinedRefs";
25
+ export * from "./uses/useDelayedExecutor";
26
+ export * from "./uses/useDimensions";
27
+ export * from "./uses/useParamsEx";
28
+ export * from "./uses/useRefs";
29
+ export * from "./uses/useRequiredContext";
30
+ export * from "./uses/useSearchParamsEx";
31
+ export * from "./uses/useTimeout";
32
+ export * from "./uses/useWindowScroll";
33
+ export * from "./uses/useWindowSize";
@@ -0,0 +1,143 @@
1
+ import React from "react";
2
+ import { INotificaseBase, INotification, INotifier, Notification, NotificationAlign, NotificationCallProps, NotificationContainer, NotificationRenderProps } from "@etsoo/notificationbase";
3
+ import { IAction } from "@etsoo/appscript";
4
+ import { IProviderProps } from "../states/IState";
5
+ /**
6
+ * React notification call props
7
+ */
8
+ export interface NotificationReactCallProps extends NotificationCallProps {
9
+ /**
10
+ * Full width
11
+ */
12
+ fullWidth?: boolean;
13
+ /**
14
+ * Full screen
15
+ */
16
+ fullScreen?: boolean;
17
+ /**
18
+ * Inputs layout
19
+ */
20
+ inputs?: React.ReactNode;
21
+ /**
22
+ * Max width
23
+ */
24
+ maxWidth?: "xs" | "sm" | "md" | "lg" | "xl" | false;
25
+ /**
26
+ * OK label
27
+ */
28
+ okLabel?: string;
29
+ /**
30
+ * false to hide cancel button
31
+ */
32
+ cancelButton?: boolean;
33
+ /**
34
+ * Cancel label
35
+ */
36
+ cancelLabel?: string;
37
+ /**
38
+ * Window is closable
39
+ */
40
+ closable?: boolean;
41
+ /**
42
+ * Draggable
43
+ */
44
+ draggable?: boolean;
45
+ /**
46
+ * Type
47
+ */
48
+ type?: string;
49
+ /**
50
+ * false to hide primary button
51
+ */
52
+ primaryButton?: boolean;
53
+ /**
54
+ * Primary button props
55
+ */
56
+ primaryButtonProps?: {};
57
+ /**
58
+ * Buttons to override default buttons
59
+ */
60
+ buttons?: (notification: INotificationReact, callback: (event: React.MouseEvent<HTMLButtonElement>, value?: any) => Promise<boolean>) => React.ReactNode;
61
+ }
62
+ /**
63
+ * React notification interface
64
+ */
65
+ export interface INotificationReact extends INotification<React.ReactNode, NotificationReactCallProps> {
66
+ }
67
+ /**
68
+ * React notification base interface
69
+ */
70
+ export interface INotificationBaseReact extends INotificaseBase<React.ReactNode, NotificationReactCallProps> {
71
+ }
72
+ /**
73
+ * Action to manage the notifier
74
+ */
75
+ interface INotifierAction extends IAction {
76
+ /**
77
+ * Notification
78
+ */
79
+ notification: INotificationReact;
80
+ /**
81
+ * Add or dismiss
82
+ */
83
+ dismiss: boolean;
84
+ }
85
+ /**
86
+ * React notification
87
+ */
88
+ export declare abstract class NotificationReact extends Notification<React.ReactNode, NotificationReactCallProps> implements INotificationReact {
89
+ }
90
+ /**
91
+ * React notification render props
92
+ */
93
+ export interface NotificationReactRenderProps extends NotificationRenderProps, IProviderProps<INotifierAction> {
94
+ }
95
+ /**
96
+ * Notifier interface
97
+ */
98
+ export interface INotifierReact extends INotifier<React.ReactNode, NotificationReactCallProps> {
99
+ /**
100
+ * Create state provider
101
+ * @param className Style class name
102
+ * @param debug Is debug mode
103
+ * @returns Provider
104
+ */
105
+ createProvider(className?: string, debug?: boolean): React.FunctionComponent<NotificationReactRenderProps>;
106
+ }
107
+ /**
108
+ * Notifier for React
109
+ */
110
+ export declare abstract class NotifierReact extends NotificationContainer<React.ReactNode, NotificationReactCallProps> implements INotifierReact {
111
+ private static _instance;
112
+ /**
113
+ * Singleton instance
114
+ */
115
+ static get instance(): INotifierReact;
116
+ /**
117
+ * Update notifier
118
+ * @param notifier Notifier
119
+ */
120
+ protected static updateInstance(notifier: INotifierReact): void;
121
+ /**
122
+ * Constructor
123
+ */
124
+ protected constructor();
125
+ /**
126
+ * State update
127
+ */
128
+ protected stateUpdate?: React.Dispatch<INotifierAction>;
129
+ /**
130
+ * Create align container
131
+ * @param align Align
132
+ * @param children Children
133
+ * @param options Other options
134
+ */
135
+ protected abstract createContainer(align: NotificationAlign, children: React.ReactNode[]): React.ReactElement;
136
+ /**
137
+ * Create state provider
138
+ * @param className Style class name
139
+ * @returns Provider
140
+ */
141
+ createProvider(className?: string, debug?: boolean): React.FunctionComponent<React.PropsWithChildren<NotificationReactRenderProps>>;
142
+ }
143
+ export {};
@@ -0,0 +1,41 @@
1
+ import { IAction, ICulture } from "@etsoo/appscript";
2
+ import { DataTypes } from "@etsoo/shared";
3
+ import { IProviderProps, IUpdate } from "./IState";
4
+ /**
5
+ * Culture action to manage resources
6
+ */
7
+ export interface CultureAction extends ICulture, IAction {
8
+ }
9
+ /**
10
+ * Culture calls with the state
11
+ */
12
+ export interface CultureCalls extends IUpdate<ICulture, CultureAction> {
13
+ /**
14
+ * Key value
15
+ * @param key Item key
16
+ */
17
+ get<T = string>(key: string): T | undefined;
18
+ }
19
+ /**
20
+ * Culture provider props
21
+ */
22
+ export type CultureProviderProps = IProviderProps<CultureAction>;
23
+ /**
24
+ * Culture state
25
+ * Creator for culture context and provider globally, not inside a component to avoid problem:
26
+ * Cannot update a component (`provider`) while rendering a different component
27
+ */
28
+ export declare class CultureState {
29
+ /**
30
+ * Context
31
+ */
32
+ readonly context: import("react").Context<CultureCalls>;
33
+ /**
34
+ * Provider
35
+ */
36
+ readonly provider: import("react").FunctionComponent<import("react").PropsWithChildren<IProviderProps<CultureAction>>>;
37
+ /**
38
+ * Constructor
39
+ */
40
+ constructor(item?: DataTypes.CultureDefinition);
41
+ }
@@ -0,0 +1,49 @@
1
+ import { IAction, IState, UserKey } from "@etsoo/appscript";
2
+ import React from "react";
3
+ /**
4
+ * State UI creator
5
+ */
6
+ export interface IUICreator<S extends IState, A extends IAction, P = object> {
7
+ (state: S, dispatch: React.Dispatch<A>, props: P): React.ReactElement;
8
+ }
9
+ /**
10
+ * State update interface
11
+ */
12
+ export interface IUpdate<S extends IState, A extends IAction> {
13
+ state: S;
14
+ dispatch: React.Dispatch<A>;
15
+ }
16
+ /**
17
+ * State update interface
18
+ */
19
+ export interface IStateUpdate {
20
+ (authorized?: boolean, matchedFields?: string[]): PromiseLike<void> | void;
21
+ }
22
+ /**
23
+ * State update props
24
+ */
25
+ export interface IStateProps {
26
+ /**
27
+ * State last changed fields
28
+ */
29
+ targetFields?: UserKey[];
30
+ /**
31
+ * State update callback
32
+ */
33
+ update: IStateUpdate;
34
+ }
35
+ /**
36
+ * State provider update callback
37
+ */
38
+ export interface IProviderUpdate<A extends IAction> {
39
+ (dispatch: React.Dispatch<A>): void;
40
+ }
41
+ /**
42
+ * State provider props
43
+ */
44
+ export interface IProviderProps<A extends IAction> {
45
+ /**
46
+ * Update callback
47
+ */
48
+ update?: IProviderUpdate<A>;
49
+ }
@@ -0,0 +1,61 @@
1
+ import { IAction, IState } from "@etsoo/appscript";
2
+ import { IProviderProps, IUpdate } from "./IState";
3
+ /**
4
+ * Page data interface
5
+ */
6
+ export interface IPageData extends IState {
7
+ /**
8
+ * Page title
9
+ */
10
+ title?: string;
11
+ /**
12
+ * Page subtitle
13
+ */
14
+ subtitle?: string;
15
+ }
16
+ /**
17
+ * Page action type
18
+ */
19
+ export declare enum PageActionType {
20
+ Data = "DATA",
21
+ Title = "TITLE"
22
+ }
23
+ /**
24
+ * Page action
25
+ */
26
+ export interface PageAction<D extends IPageData> extends IAction {
27
+ /**
28
+ * Action type
29
+ */
30
+ type: PageActionType;
31
+ /**
32
+ * Action data
33
+ */
34
+ data: D;
35
+ }
36
+ /**
37
+ * Page provider props
38
+ */
39
+ export type PageProviderProps<D extends IPageData> = IProviderProps<PageAction<D>>;
40
+ /**
41
+ * Page calls with the state
42
+ */
43
+ export interface PageCalls<D extends IPageData> extends IUpdate<D, PageAction<D>> {
44
+ }
45
+ /**
46
+ * User state
47
+ */
48
+ export declare class PageState<D extends IPageData> {
49
+ /**
50
+ * Context
51
+ */
52
+ readonly context: import("react").Context<PageCalls<D>>;
53
+ /**
54
+ * Provider
55
+ */
56
+ readonly provider: import("react").FunctionComponent<import("react").PropsWithChildren<IProviderProps<PageAction<D>>>>;
57
+ /**
58
+ * Constructor
59
+ */
60
+ constructor();
61
+ }
@@ -0,0 +1,18 @@
1
+ import { IAction, IState } from "@etsoo/appscript";
2
+ import React from "react";
3
+ import { IProviderProps, IUICreator, IUpdate } from "./IState";
4
+ /**
5
+ * State
6
+ */
7
+ export declare class State {
8
+ /**
9
+ * Generic to create state context and provider
10
+ * @param reducer Reduce function
11
+ * @param initState Init state
12
+ * @param uiCreator Additional UI creator
13
+ */
14
+ static create<S extends IState, A extends IAction, U extends IUpdate<S, A>, P extends IProviderProps<A>>(reducer: React.Reducer<S, A>, initState: S, calls: U, uiCreator?: IUICreator<S, A, P>): {
15
+ context: React.Context<U>;
16
+ provider: React.FunctionComponent<React.PropsWithChildren<P>>;
17
+ };
18
+ }
@@ -0,0 +1,56 @@
1
+ import { IAction, IUser, IUserData } from "@etsoo/appscript";
2
+ import { IProviderProps, IUpdate } from "./IState";
3
+ /**
4
+ * User action type
5
+ * Style like 'const enum' will remove definition of the enum and cause module errors
6
+ */
7
+ export declare enum UserActionType {
8
+ Login = "LOGIN",
9
+ Logout = "LOGOUT",
10
+ Update = "UPDATE",
11
+ Unauthorized = "UNAUTHORIZED"
12
+ }
13
+ /**
14
+ * User action to manage the user
15
+ */
16
+ export interface UserAction<D extends IUser> extends IAction {
17
+ /**
18
+ * Action type
19
+ */
20
+ type: UserActionType;
21
+ /**
22
+ * User data
23
+ */
24
+ user?: IUserData;
25
+ /**
26
+ * User update callback
27
+ */
28
+ update?: (state: D) => void;
29
+ }
30
+ /**
31
+ * User provider props
32
+ */
33
+ export type UserProviderProps<D extends IUser> = IProviderProps<UserAction<D>>;
34
+ /**
35
+ * Users calls with the state
36
+ */
37
+ export interface UserCalls<D extends IUser> extends IUpdate<D, UserAction<D>> {
38
+ }
39
+ /**
40
+ * User state
41
+ */
42
+ export declare class UserState<D extends IUser> {
43
+ /**
44
+ * Context
45
+ */
46
+ readonly context: import("react").Context<UserCalls<D>>;
47
+ /**
48
+ * Provider
49
+ */
50
+ readonly provider: import("react").FunctionComponent<import("react").PropsWithChildren<UserProviderProps<D>>>;
51
+ /**
52
+ * Constructor
53
+ */
54
+ constructor();
55
+ private getChangedFields;
56
+ }
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ export declare function useAsyncState<S = undefined>(): [
3
+ S | undefined,
4
+ (newState: React.SetStateAction<S | undefined>) => Promise<S | undefined>
5
+ ];
6
+ /**
7
+ * Returns a stateful value, and a async function to update it.
8
+ * @param initialState initial stat
9
+ * @returns Current state and update action
10
+ */
11
+ export declare function useAsyncState<S>(initialState: S | (() => S)): [S, (newState: React.SetStateAction<S>) => Promise<S>];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Combined refs
3
+ * @param refs Refs
4
+ * @returns Callback
5
+ */
6
+ export declare function useCombinedRefs<T>(...refs: (React.Ref<T> | undefined)[]): (target: T | null) => void;
@@ -0,0 +1,5 @@
1
+ import { DelayedExecutorType } from "@etsoo/shared";
2
+ /**
3
+ * Create delayed executor
4
+ */
5
+ export declare function useDelayedExecutor<P extends any[]>(func: (...args: P) => void, delayMiliseconcs: number): DelayedExecutorType<P>;
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ interface states {
3
+ count: number;
4
+ indices: number[];
5
+ }
6
+ /**
7
+ * Calculate element(s) dimensions
8
+ * @param elements Observed elments count
9
+ * @param updateCallback Update callback
10
+ * @param miliseconds Miliseconds to wait before update
11
+ * @param equalCallback Equall callback
12
+ */
13
+ export declare function useDimensions(elements: number, updateCallback?: (target: Element, rect: DOMRect) => boolean | void, miliseconds?: number, equalCallback?: (d1?: DOMRect, d2?: DOMRect) => boolean): {
14
+ dimensions: [(instance: Element | null) => void | React.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof React.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES], (Element | undefined)?, (DOMRect | undefined)?][];
15
+ state: states;
16
+ };
17
+ export {};
@@ -0,0 +1,6 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ /**
3
+ * Extended useParams of react-router-dom
4
+ * Provide exact type data
5
+ */
6
+ export declare function useParamsEx<T extends DataTypes.BasicTemplate>(template: T): DataTypes.BasicTemplateType<T>;
@@ -0,0 +1,8 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import React from "react";
3
+ /**
4
+ * Create multiple refs
5
+ * @param fields Fields
6
+ * @returns Result
7
+ */
8
+ export declare function useRefs<F extends ReadonlyArray<string>, T = HTMLInputElement>(fields: F): DataTypes.DI<F, React.MutableRefObject<T | null>>;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ /**
3
+ * Required context
4
+ * @param context Context
5
+ * @returns Value
6
+ */
7
+ export declare function useRequiredContext<T>(context: React.Context<T>): NonNullable<T>;
@@ -0,0 +1,6 @@
1
+ import { DataTypes } from "@etsoo/shared";
2
+ /**
3
+ * Extended useSearchParams of react-router-dom
4
+ * Provide exact type data
5
+ */
6
+ export declare function useSearchParamsEx<T extends DataTypes.BasicTemplate>(template: T): DataTypes.BasicTemplateType<T>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * For setTimeout to merge actions
3
+ * @param action Action function
4
+ * @param milliseconds Interval of milliseconds
5
+ */
6
+ export declare const useTimeout: (action: (...args: any[]) => void, milliseconds: number) => {
7
+ cancel: () => void;
8
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Window scroll position
3
+ */
4
+ export interface IScrollPos {
5
+ x: number;
6
+ y: number;
7
+ }
8
+ /**
9
+ * Detect window scroll
10
+ * @returns Scroll location
11
+ */
12
+ export declare const useWindowScroll: () => IScrollPos;
@@ -0,0 +1,10 @@
1
+ interface ISize {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ /**
6
+ * Detect window size
7
+ * @returns Window size
8
+ */
9
+ export declare const useWindowSize: () => ISize;
10
+ export {};
package/package.json CHANGED
@@ -1,27 +1,19 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.8.21",
3
+ "version": "1.8.23",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "scripts": {
8
- "build": "tsc",
9
- "test": "jest",
10
- "test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand"
5
+ "main": "lib/cjs/index.js",
6
+ "module": "lib/mjs/index.js",
7
+ "types": "lib/mjs/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./lib/mjs/index.js",
11
+ "require": "./lib/cjs/index.js"
12
+ }
11
13
  },
12
- "jest": {
13
- "automock": false,
14
- "testMatch": [
15
- "<rootDir>/__tests__/**/*.{ts,tsx}"
16
- ],
17
- "testEnvironment": "jsdom",
18
- "transform": {
19
- ".+\\.jsx?$": "babel-jest",
20
- ".+\\.tsx?$": "ts-jest"
21
- },
22
- "transformIgnorePatterns": [
23
- "/node_modules/(?!@etsoo/).+\\.js$"
24
- ]
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
16
+ "test": "vitest"
25
17
  },
26
18
  "repository": {
27
19
  "type": "git",
@@ -56,6 +48,11 @@
56
48
  "react-router-dom": "^7.1.1",
57
49
  "react-window": "^1.8.10"
58
50
  },
51
+ "overrides": {
52
+ "react": "$react",
53
+ "react-dom": "$react-dom",
54
+ "@emotion/react": "$@emotion/react"
55
+ },
59
56
  "devDependencies": {
60
57
  "@babel/cli": "^7.25.9",
61
58
  "@babel/core": "^7.26.0",
@@ -68,9 +65,9 @@
68
65
  "@types/react": "^18.3.18",
69
66
  "@types/react-dom": "^18.3.1",
70
67
  "@types/react-window": "^1.8.8",
71
- "jest": "^29.7.0",
72
- "jest-environment-jsdom": "^29.7.0",
73
- "ts-jest": "^29.2.5",
74
- "typescript": "^5.7.3"
68
+ "@vitejs/plugin-react": "^4.3.4",
69
+ "jsdom": "^26.0.0",
70
+ "typescript": "^5.7.3",
71
+ "vitest": "^2.1.8"
75
72
  }
76
73
  }