@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,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PageState = exports.PageActionType = void 0;
4
+ const State_1 = require("./State");
5
+ /**
6
+ * Page action type
7
+ */
8
+ var PageActionType;
9
+ (function (PageActionType) {
10
+ // Update data
11
+ PageActionType["Data"] = "DATA";
12
+ // Update title
13
+ PageActionType["Title"] = "TITLE";
14
+ })(PageActionType || (exports.PageActionType = PageActionType = {}));
15
+ /**
16
+ * User state
17
+ */
18
+ class PageState {
19
+ /**
20
+ * Constructor
21
+ */
22
+ constructor() {
23
+ // Act
24
+ const { context, provider } = State_1.State.create((state, { type, data }) => {
25
+ switch (type) {
26
+ case PageActionType.Data:
27
+ // Set page data
28
+ return { ...state, ...data };
29
+ case PageActionType.Title:
30
+ // Same title
31
+ if (state.title === data.title && state.subtitle === data.subtitle)
32
+ return state;
33
+ // Set page title
34
+ return {
35
+ ...state,
36
+ ...data
37
+ };
38
+ default:
39
+ return state;
40
+ }
41
+ }, {}, {});
42
+ this.context = context;
43
+ this.provider = provider;
44
+ }
45
+ }
46
+ exports.PageState = PageState;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.State = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = __importDefault(require("react"));
9
+ /**
10
+ * State
11
+ */
12
+ class State {
13
+ /**
14
+ * Generic to create state context and provider
15
+ * @param reducer Reduce function
16
+ * @param initState Init state
17
+ * @param uiCreator Additional UI creator
18
+ */
19
+ static create(reducer, initState, calls, uiCreator) {
20
+ // State context
21
+ const context = react_1.default.createContext(calls);
22
+ // State context provider
23
+ const provider = (props) => {
24
+ // Destruct
25
+ const { children, update } = props;
26
+ // Update reducer
27
+ const [state, dispatch] = react_1.default.useReducer(reducer, initState);
28
+ // Callback
29
+ if (update != null)
30
+ update(dispatch);
31
+ if (uiCreator) {
32
+ // Custom renderer
33
+ return uiCreator(state, dispatch, props);
34
+ }
35
+ else {
36
+ // Context new value
37
+ const value = { ...calls, state, dispatch };
38
+ return (0, jsx_runtime_1.jsx)(context.Provider, { value: value, children: children });
39
+ }
40
+ };
41
+ // Return
42
+ return {
43
+ context,
44
+ provider
45
+ };
46
+ }
47
+ }
48
+ exports.State = State;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserState = exports.UserActionType = void 0;
4
+ const shared_1 = require("@etsoo/shared");
5
+ const State_1 = require("./State");
6
+ /**
7
+ * User action type
8
+ * Style like 'const enum' will remove definition of the enum and cause module errors
9
+ */
10
+ var UserActionType;
11
+ (function (UserActionType) {
12
+ // Login
13
+ UserActionType["Login"] = "LOGIN";
14
+ // Logout
15
+ UserActionType["Logout"] = "LOGOUT";
16
+ // Update
17
+ UserActionType["Update"] = "UPDATE";
18
+ // Unauthorized
19
+ UserActionType["Unauthorized"] = "UNAUTHORIZED";
20
+ })(UserActionType || (exports.UserActionType = UserActionType = {}));
21
+ /**
22
+ * User state
23
+ */
24
+ class UserState {
25
+ /**
26
+ * Constructor
27
+ */
28
+ constructor() {
29
+ const { context, provider } = State_1.State.create((state, action) => {
30
+ // User reducer
31
+ switch (action.type) {
32
+ case UserActionType.Login:
33
+ const lastChangedFields = state.authorized && action.user
34
+ ? this.getChangedFields(action.user, state)
35
+ : undefined;
36
+ return {
37
+ ...action.user,
38
+ authorized: true,
39
+ lastChangedFields
40
+ };
41
+ case UserActionType.Logout:
42
+ return {
43
+ ...state, // Keep other user data
44
+ lastChangedFields: undefined,
45
+ token: undefined, // Remove token
46
+ authorized: false // Flag as unauthorized
47
+ };
48
+ case UserActionType.Update:
49
+ if (action.update) {
50
+ var newState = { ...state };
51
+ action.update(newState);
52
+ newState.lastChangedFields = this.getChangedFields(newState, state);
53
+ return newState;
54
+ }
55
+ return state;
56
+ case UserActionType.Unauthorized:
57
+ // Avoid multiple updates (For example, multiple API calls failed with 405)
58
+ if (state.authorized === false)
59
+ return state;
60
+ return {
61
+ ...state, // Keep other user data and token for refresh
62
+ lastChangedFields: undefined,
63
+ authorized: false // Flag as unauthorized
64
+ };
65
+ default:
66
+ return state;
67
+ }
68
+ }, {}, {});
69
+ this.context = context;
70
+ this.provider = provider;
71
+ }
72
+ getChangedFields(input, init) {
73
+ return shared_1.Utils.objectUpdated(input, init, [
74
+ "authorized",
75
+ "seconds",
76
+ "lastChangedFields"
77
+ ]);
78
+ }
79
+ }
80
+ exports.UserState = UserState;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useAsyncState = useAsyncState;
7
+ const react_1 = __importDefault(require("react"));
8
+ /**
9
+ * Returns a stateful value, and a async function to update it.
10
+ * @param initialState initial stat
11
+ * @returns Current state and update action
12
+ */
13
+ function useAsyncState(initialState) {
14
+ // State
15
+ const [state, setState] = react_1.default.useState(initialState);
16
+ // Resolve sate
17
+ const resolveState = react_1.default.useRef();
18
+ // Is mounted or not
19
+ const isMounted = react_1.default.useRef(false);
20
+ react_1.default.useEffect(() => {
21
+ isMounted.current = true;
22
+ return () => {
23
+ isMounted.current = false;
24
+ };
25
+ }, []);
26
+ // When state update
27
+ react_1.default.useEffect(() => {
28
+ if (resolveState.current) {
29
+ resolveState.current(state);
30
+ }
31
+ }, [state]);
32
+ const setAsyncState = react_1.default.useCallback((newState) => new Promise((resolve) => {
33
+ if (isMounted.current) {
34
+ resolveState.current = resolve;
35
+ setState(newState);
36
+ }
37
+ }), []);
38
+ return [state, setAsyncState];
39
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCombinedRefs = useCombinedRefs;
4
+ /**
5
+ * Combined refs
6
+ * @param refs Refs
7
+ * @returns Callback
8
+ */
9
+ function useCombinedRefs(...refs) {
10
+ return (target) => {
11
+ // Ignore null reference
12
+ if (target == null)
13
+ return;
14
+ // Update all refs
15
+ refs.forEach((ref) => {
16
+ // Null ref
17
+ if (!ref)
18
+ return;
19
+ // Callback function
20
+ if (typeof ref === "function") {
21
+ ref(target);
22
+ }
23
+ else {
24
+ // as any to update readonly property
25
+ Reflect.set(ref, "current", target);
26
+ }
27
+ });
28
+ };
29
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useDelayedExecutor = useDelayedExecutor;
7
+ const shared_1 = require("@etsoo/shared");
8
+ const react_1 = __importDefault(require("react"));
9
+ /**
10
+ * Create delayed executor
11
+ */
12
+ function useDelayedExecutor(func, delayMiliseconcs) {
13
+ const ref = react_1.default.useRef();
14
+ if (ref.current == null)
15
+ ref.current = shared_1.ExtendUtils.delayedExecutor(func, delayMiliseconcs);
16
+ return ref.current;
17
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useDimensions = useDimensions;
7
+ const shared_1 = require("@etsoo/shared");
8
+ const react_1 = __importDefault(require("react"));
9
+ const useDelayedExecutor_1 = require("./useDelayedExecutor");
10
+ /**
11
+ * Calculate element(s) dimensions
12
+ * @param elements Observed elments count
13
+ * @param updateCallback Update callback
14
+ * @param miliseconds Miliseconds to wait before update
15
+ * @param equalCallback Equall callback
16
+ */
17
+ function useDimensions(elements, updateCallback, miliseconds = 50, equalCallback = shared_1.DomUtils.dimensionEqual) {
18
+ // State
19
+ const [state, setState] = react_1.default.useState({
20
+ count: 0,
21
+ indices: []
22
+ });
23
+ // Dimentions
24
+ const dimensions = react_1.default.useRef();
25
+ if (dimensions.current == null) {
26
+ // Init
27
+ const init = [];
28
+ for (let e = 0; e < elements; e++) {
29
+ init.push(((index) => {
30
+ return [
31
+ (instance) => {
32
+ if (instance != null) {
33
+ // Current element
34
+ const currentElement = init[index][1];
35
+ if (currentElement != null) {
36
+ // Same target, return
37
+ if (currentElement == instance)
38
+ return;
39
+ // Cancel observation
40
+ resizeObserver.unobserve(currentElement);
41
+ }
42
+ // Update element
43
+ init[index][1] = instance;
44
+ // Start observe
45
+ resizeObserver.observe(instance);
46
+ }
47
+ }
48
+ ];
49
+ })(e));
50
+ }
51
+ dimensions.current = init;
52
+ }
53
+ const delayed = (0, useDelayedExecutor_1.useDelayedExecutor)(setState, miliseconds);
54
+ // Observer
55
+ const resizeObserver = new ResizeObserver((entries) => {
56
+ // Update Rect
57
+ const indices = [];
58
+ const init = dimensions.current;
59
+ entries.forEach((entry) => {
60
+ const index = init.findIndex((item) => item[1] === entry.target);
61
+ if (index !== -1) {
62
+ // Previous rect
63
+ const pre = init[index][2];
64
+ // New rect
65
+ const rect = entry.target.getBoundingClientRect();
66
+ // Check equal
67
+ if (!equalCallback(pre, rect)) {
68
+ // Update callback
69
+ if (updateCallback) {
70
+ // Return false means no further push
71
+ if (updateCallback(entry.target, rect) === false)
72
+ return;
73
+ }
74
+ // Update rect
75
+ init[index][2] = rect;
76
+ // Push for update
77
+ indices.push(index);
78
+ }
79
+ }
80
+ });
81
+ // Update state
82
+ if (indices.length > 0) {
83
+ // Count only for unique update
84
+ const update = { count: state.count + 1, indices };
85
+ delayed.call(undefined, update);
86
+ }
87
+ });
88
+ // Layout ready
89
+ react_1.default.useEffect(() => {
90
+ return () => {
91
+ // Clear the observer
92
+ resizeObserver.disconnect();
93
+ delayed.clear();
94
+ };
95
+ }, []);
96
+ // Return
97
+ return { dimensions: dimensions.current, state };
98
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useParamsEx = useParamsEx;
4
+ const shared_1 = require("@etsoo/shared");
5
+ const react_router_1 = require("react-router");
6
+ /**
7
+ * Extended useParams of react-router-dom
8
+ * Provide exact type data
9
+ */
10
+ function useParamsEx(template) {
11
+ // Get parameters
12
+ const params = (0, react_router_1.useParams)();
13
+ // Return
14
+ return shared_1.DomUtils.dataAs(params, template, false);
15
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useRefs = useRefs;
7
+ const react_1 = __importDefault(require("react"));
8
+ /**
9
+ * Create multiple refs
10
+ * @param fields Fields
11
+ * @returns Result
12
+ */
13
+ function useRefs(fields) {
14
+ const refs = {};
15
+ fields.forEach((field) => (refs[field] = react_1.default.useRef(null)));
16
+ return refs;
17
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useRequiredContext = useRequiredContext;
7
+ const react_1 = __importDefault(require("react"));
8
+ /**
9
+ * Required context
10
+ * @param context Context
11
+ * @returns Value
12
+ */
13
+ function useRequiredContext(context) {
14
+ const value = react_1.default.useContext(context);
15
+ if (value == null) {
16
+ throw new Error(`useRequiredContext: ${context.displayName} is required`);
17
+ }
18
+ return value;
19
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearchParamsEx = useSearchParamsEx;
4
+ const shared_1 = require("@etsoo/shared");
5
+ const react_router_1 = require("react-router");
6
+ /**
7
+ * Extended useSearchParams of react-router-dom
8
+ * Provide exact type data
9
+ */
10
+ function useSearchParamsEx(template) {
11
+ // Get parameters
12
+ const [sp] = (0, react_router_1.useSearchParams)();
13
+ const paras = Object.fromEntries(Object.keys(template).map((key) => {
14
+ const type = template[key];
15
+ return [key, type.endsWith("[]") ? sp.getAll(key) : sp.get(key)];
16
+ }));
17
+ // Return
18
+ return shared_1.DomUtils.dataAs(paras, template, false);
19
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useTimeout = void 0;
7
+ const shared_1 = require("@etsoo/shared");
8
+ const react_1 = __importDefault(require("react"));
9
+ /**
10
+ * For setTimeout to merge actions
11
+ * @param action Action function
12
+ * @param milliseconds Interval of milliseconds
13
+ */
14
+ const useTimeout = (action, milliseconds) => {
15
+ // Delayed
16
+ const d = shared_1.ExtendUtils.delayedExecutor(action, milliseconds);
17
+ // Merge into the life cycle
18
+ react_1.default.useEffect(() => {
19
+ d.call();
20
+ return () => {
21
+ d.clear();
22
+ };
23
+ }, []);
24
+ // Return cancel method
25
+ return {
26
+ cancel: d.clear
27
+ };
28
+ };
29
+ exports.useTimeout = useTimeout;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useWindowScroll = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ /**
9
+ * Detect window scroll
10
+ * @returns Scroll location
11
+ */
12
+ const useWindowScroll = () => {
13
+ // State
14
+ const [pos, setPos] = react_1.default.useState({
15
+ x: window.scrollX,
16
+ y: window.scrollY
17
+ });
18
+ react_1.default.useEffect(() => {
19
+ let ticking = false;
20
+ let lastPos;
21
+ let requestAnimationFrameSeed = 0;
22
+ const scrollHandler = () => {
23
+ lastPos = {
24
+ x: window.scrollX,
25
+ y: window.scrollY
26
+ };
27
+ if (!ticking) {
28
+ requestAnimationFrameSeed = window.requestAnimationFrame(() => {
29
+ ticking = false;
30
+ requestAnimationFrameSeed = 0;
31
+ if (lastPos.x != pos.x || lastPos.y != pos.y) {
32
+ setPos(lastPos);
33
+ }
34
+ });
35
+ ticking = true;
36
+ }
37
+ };
38
+ window.addEventListener("scroll", scrollHandler, {
39
+ passive: true,
40
+ capture: false
41
+ });
42
+ return () => {
43
+ // Cancel animation frame
44
+ if (requestAnimationFrameSeed > 0)
45
+ window.cancelAnimationFrame(requestAnimationFrameSeed);
46
+ // Remove scroll event
47
+ window.removeEventListener("scroll", scrollHandler);
48
+ };
49
+ }, []);
50
+ // Return
51
+ return pos;
52
+ };
53
+ exports.useWindowScroll = useWindowScroll;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useWindowSize = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ /**
9
+ * Detect window size
10
+ * @returns Window size
11
+ */
12
+ const useWindowSize = () => {
13
+ // State
14
+ const [size, setSize] = react_1.default.useState({
15
+ width: 0,
16
+ height: 0
17
+ });
18
+ react_1.default.useEffect(() => {
19
+ let ticking = false;
20
+ let lastSize;
21
+ let requestAnimationFrameSeed = 0;
22
+ const resizeHandler = () => {
23
+ lastSize = {
24
+ width: document.documentElement.clientWidth,
25
+ height: document.documentElement.clientHeight
26
+ };
27
+ if (!ticking) {
28
+ requestAnimationFrameSeed = window.requestAnimationFrame(() => {
29
+ ticking = false;
30
+ requestAnimationFrameSeed = 0;
31
+ if (lastSize.width != size.width || lastSize.height != size.height) {
32
+ setSize(lastSize);
33
+ }
34
+ });
35
+ ticking = true;
36
+ }
37
+ };
38
+ window.addEventListener("resize", resizeHandler, {
39
+ passive: true,
40
+ capture: false
41
+ });
42
+ return () => {
43
+ // Cancel animation frame
44
+ if (requestAnimationFrameSeed > 0)
45
+ window.cancelAnimationFrame(requestAnimationFrameSeed);
46
+ // Remove resize event
47
+ window.removeEventListener("resize", resizeHandler);
48
+ };
49
+ }, []);
50
+ // Return
51
+ return size;
52
+ };
53
+ exports.useWindowSize = useWindowSize;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Core constants
3
+ */
4
+ export declare namespace CoreConstants {
5
+ /**
6
+ * User id saved field
7
+ */
8
+ const FieldUserIdSaved = "UserIdSaved";
9
+ /**
10
+ * Rresh token cache field
11
+ */
12
+ const FieldRefreshToken = "RefreshToken";
13
+ }
@@ -0,0 +1,35 @@
1
+ import React from "react";
2
+ /**
3
+ * Event watcher action
4
+ */
5
+ export interface EventWatcherAction {
6
+ /**
7
+ * Event type
8
+ */
9
+ type?: string | string[];
10
+ /**
11
+ * Once action or not
12
+ */
13
+ once?: boolean;
14
+ /**
15
+ * Action
16
+ */
17
+ action: (event: React.BaseSyntheticEvent | string) => any;
18
+ }
19
+ /**
20
+ * Event watcher
21
+ */
22
+ export declare class EventWatcher {
23
+ private actions;
24
+ /**
25
+ * Add action
26
+ * @param action Action
27
+ */
28
+ add(action: EventWatcherAction): void;
29
+ /**
30
+ * Do the event
31
+ * @param event Event
32
+ */
33
+ do(event: React.BaseSyntheticEvent | string): void;
34
+ private isMatch;
35
+ }
@@ -0,0 +1,19 @@
1
+ import { NotificationContent, NotificationReturn } from "@etsoo/notificationbase";
2
+ import { NotificationReactCallProps } from "../notifier/Notifier";
3
+ /**
4
+ * Input dialog props
5
+ */
6
+ export type InputDialogProps = NotificationReactCallProps & {
7
+ /**
8
+ * Title
9
+ */
10
+ title: NotificationContent<React.ReactNode>;
11
+ /**
12
+ * Message
13
+ */
14
+ message: NotificationContent<React.ReactNode>;
15
+ /**
16
+ * Callback
17
+ */
18
+ callback: NotificationReturn<HTMLFormElement | undefined>;
19
+ };