@trackunit/react-core-hooks 0.2.64 → 0.2.65
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/index.cjs +562 -388
- package/index.js +563 -389
- package/package.json +5 -5
- package/src/analytics/AnalyticsProvider.d.ts +23 -23
- package/src/assetSorting/AssetSortingProvider.d.ts +36 -36
- package/src/environment/EnvironmentContextProvider.d.ts +23 -23
- package/src/global-selection/GlobalSelectionProvider.d.ts +26 -26
- package/src/index.d.ts +16 -16
- package/src/irisOemApp/IrisOemAppContextProvider.d.ts +24 -24
- package/src/runtimes/navigation/index.d.ts +1 -1
- package/src/runtimes/navigation/useDeeplink.d.ts +4 -4
- package/src/runtimes/navigation/useNavigationRuntime.d.ts +17 -17
- package/src/runtimes/navigation/useURLSynchronization.d.ts +4 -4
- package/src/runtimes/useAssetRuntime.d.ts +22 -22
- package/src/runtimes/useCustomFieldRuntime.d.ts +9 -9
- package/src/runtimes/useCustomFieldRuntimeForEntity.d.ts +23 -23
- package/src/runtimes/useRestRuntime.d.ts +10 -10
- package/src/runtimes/useSiteRuntime.d.ts +23 -23
- package/src/subscription/UserSubscriptionProvider.d.ts +24 -24
- package/src/toast/ToastProvider.d.ts +29 -29
- package/src/token/TokenProvider.d.ts +22 -22
- package/src/user/CurrentUserProvider.d.ts +27 -27
package/index.cjs
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
8
|
-
var reactRouterDom = require('react-router-dom');
|
|
9
8
|
|
|
10
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
10
|
|
|
@@ -30,187 +29,362 @@ function _interopNamespace(e) {
|
|
|
30
29
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
31
30
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
32
31
|
|
|
33
|
-
const AnalyticsContext = React.createContext(null);
|
|
34
|
-
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
35
|
-
/**
|
|
36
|
-
* Hook to get the analytics context.
|
|
37
|
-
*
|
|
38
|
-
* @requires AnalyticsProvider
|
|
39
|
-
* @example
|
|
40
|
-
* import { useAnalytics, useEnvironment } from "@trackunit/react-core-hooks";
|
|
41
|
-
* const { logPageView, logEvent } = useAnalytics(AllEvents);
|
|
42
|
-
*
|
|
43
|
-
* // log page view event
|
|
44
|
-
* useEffect(() => {
|
|
45
|
-
* logPageView({ pageName: "login" });
|
|
46
|
-
* }, [logPageView]);
|
|
47
|
-
*
|
|
48
|
-
* // log event when appropriate
|
|
49
|
-
* logEvent("Login", { loginPage: "New Manager" });
|
|
50
|
-
*
|
|
51
|
-
* @see {@link IAnalyticsContext}
|
|
52
|
-
*/
|
|
53
|
-
const useAnalytics = (type) => {
|
|
54
|
-
const context = React.useContext(AnalyticsContext);
|
|
55
|
-
if (!context) {
|
|
56
|
-
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
57
|
-
}
|
|
58
|
-
return context;
|
|
32
|
+
const AnalyticsContext = React.createContext(null);
|
|
33
|
+
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
34
|
+
/**
|
|
35
|
+
* Hook to get the analytics context.
|
|
36
|
+
*
|
|
37
|
+
* @requires AnalyticsProvider
|
|
38
|
+
* @example
|
|
39
|
+
* import { useAnalytics, useEnvironment } from "@trackunit/react-core-hooks";
|
|
40
|
+
* const { logPageView, logEvent } = useAnalytics(AllEvents);
|
|
41
|
+
*
|
|
42
|
+
* // log page view event
|
|
43
|
+
* useEffect(() => {
|
|
44
|
+
* logPageView({ pageName: "login" });
|
|
45
|
+
* }, [logPageView]);
|
|
46
|
+
*
|
|
47
|
+
* // log event when appropriate
|
|
48
|
+
* logEvent("Login", { loginPage: "New Manager" });
|
|
49
|
+
*
|
|
50
|
+
* @see {@link IAnalyticsContext}
|
|
51
|
+
*/
|
|
52
|
+
const useAnalytics = (type) => {
|
|
53
|
+
const context = React.useContext(AnalyticsContext);
|
|
54
|
+
if (!context) {
|
|
55
|
+
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
56
|
+
}
|
|
57
|
+
return context;
|
|
59
58
|
};
|
|
60
59
|
|
|
61
|
-
const AssetSortingContext = React.createContext(null);
|
|
62
|
-
/**
|
|
63
|
-
* This is a provider for the AssetSortingContext.
|
|
64
|
-
*/
|
|
65
|
-
const AssetSortingProvider = AssetSortingContext.Provider;
|
|
66
|
-
/**
|
|
67
|
-
* This is a hook to use the AssetSortingContext.
|
|
68
|
-
*
|
|
69
|
-
* @requires AssetSortingProvider
|
|
70
|
-
* @example
|
|
71
|
-
* import { useAssetSorting } from "@trackunit/react-core-hooks";
|
|
72
|
-
* const { sortingState, setSortBy } = useAssetSorting();
|
|
73
|
-
*
|
|
74
|
-
* const initialSort = useMemo(
|
|
75
|
-
* () => ({
|
|
76
|
-
* property: {
|
|
77
|
-
* label: sortingState.sortBy,
|
|
78
|
-
* value: sortingState.sortBy,
|
|
79
|
-
* },
|
|
80
|
-
* order: sortingState.order,
|
|
81
|
-
* }),
|
|
82
|
-
* [sortingState]
|
|
83
|
-
* );
|
|
84
|
-
*
|
|
85
|
-
* return (
|
|
86
|
-
* <Table
|
|
87
|
-
* ...
|
|
88
|
-
* headerOnSort={setSortBy}
|
|
89
|
-
* headerInitialSort={initialSort}
|
|
90
|
-
* />
|
|
91
|
-
* );
|
|
92
|
-
*
|
|
93
|
-
* @see {@link IAssetSortingContext}
|
|
94
|
-
*/
|
|
95
|
-
const useAssetSorting = () => {
|
|
96
|
-
const context = React.useContext(AssetSortingContext);
|
|
97
|
-
if (!context) {
|
|
98
|
-
throw new Error("useAssetSorting must be used within a AssetSortingProvider");
|
|
99
|
-
}
|
|
100
|
-
return context;
|
|
60
|
+
const AssetSortingContext = React.createContext(null);
|
|
61
|
+
/**
|
|
62
|
+
* This is a provider for the AssetSortingContext.
|
|
63
|
+
*/
|
|
64
|
+
const AssetSortingProvider = AssetSortingContext.Provider;
|
|
65
|
+
/**
|
|
66
|
+
* This is a hook to use the AssetSortingContext.
|
|
67
|
+
*
|
|
68
|
+
* @requires AssetSortingProvider
|
|
69
|
+
* @example
|
|
70
|
+
* import { useAssetSorting } from "@trackunit/react-core-hooks";
|
|
71
|
+
* const { sortingState, setSortBy } = useAssetSorting();
|
|
72
|
+
*
|
|
73
|
+
* const initialSort = useMemo(
|
|
74
|
+
* () => ({
|
|
75
|
+
* property: {
|
|
76
|
+
* label: sortingState.sortBy,
|
|
77
|
+
* value: sortingState.sortBy,
|
|
78
|
+
* },
|
|
79
|
+
* order: sortingState.order,
|
|
80
|
+
* }),
|
|
81
|
+
* [sortingState]
|
|
82
|
+
* );
|
|
83
|
+
*
|
|
84
|
+
* return (
|
|
85
|
+
* <Table
|
|
86
|
+
* ...
|
|
87
|
+
* headerOnSort={setSortBy}
|
|
88
|
+
* headerInitialSort={initialSort}
|
|
89
|
+
* />
|
|
90
|
+
* );
|
|
91
|
+
*
|
|
92
|
+
* @see {@link IAssetSortingContext}
|
|
93
|
+
*/
|
|
94
|
+
const useAssetSorting = () => {
|
|
95
|
+
const context = React.useContext(AssetSortingContext);
|
|
96
|
+
if (!context) {
|
|
97
|
+
throw new Error("useAssetSorting must be used within a AssetSortingProvider");
|
|
98
|
+
}
|
|
99
|
+
return context;
|
|
101
100
|
};
|
|
102
101
|
|
|
103
|
-
const EnvironmentContext = React.createContext(null);
|
|
104
|
-
/**
|
|
105
|
-
* This is a provider for the EnvironmentContext.
|
|
106
|
-
*/
|
|
107
|
-
const EnvironmentContextProvider = (props) => {
|
|
108
|
-
return jsxRuntime.jsx(EnvironmentContext.Provider, Object.assign({}, props));
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* This is a hook to use the EnvironmentContext.
|
|
112
|
-
*
|
|
113
|
-
* @requires EnvironmentContext
|
|
114
|
-
* @example
|
|
115
|
-
* import { useEnvironment } from "@trackunit/react-core-hooks";
|
|
116
|
-
* const { googleMapsApiKey } = useEnvironment();
|
|
117
|
-
* // use api key for something...
|
|
118
|
-
*
|
|
119
|
-
* @see (@link IEnvironmentContext)
|
|
120
|
-
*/
|
|
121
|
-
const useEnvironment = () => {
|
|
122
|
-
const context = React.useContext(EnvironmentContext);
|
|
123
|
-
if (!context) {
|
|
124
|
-
throw new Error("useEnvironment must be used within an EnvironmentContext");
|
|
125
|
-
}
|
|
126
|
-
return context;
|
|
102
|
+
const EnvironmentContext = React.createContext(null);
|
|
103
|
+
/**
|
|
104
|
+
* This is a provider for the EnvironmentContext.
|
|
105
|
+
*/
|
|
106
|
+
const EnvironmentContextProvider = (props) => {
|
|
107
|
+
return jsxRuntime.jsx(EnvironmentContext.Provider, Object.assign({}, props));
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* This is a hook to use the EnvironmentContext.
|
|
111
|
+
*
|
|
112
|
+
* @requires EnvironmentContext
|
|
113
|
+
* @example
|
|
114
|
+
* import { useEnvironment } from "@trackunit/react-core-hooks";
|
|
115
|
+
* const { googleMapsApiKey } = useEnvironment();
|
|
116
|
+
* // use api key for something...
|
|
117
|
+
*
|
|
118
|
+
* @see (@link IEnvironmentContext)
|
|
119
|
+
*/
|
|
120
|
+
const useEnvironment = () => {
|
|
121
|
+
const context = React.useContext(EnvironmentContext);
|
|
122
|
+
if (!context) {
|
|
123
|
+
throw new Error("useEnvironment must be used within an EnvironmentContext");
|
|
124
|
+
}
|
|
125
|
+
return context;
|
|
127
126
|
};
|
|
128
127
|
|
|
129
|
-
const GlobalSelectionContext = React__namespace.createContext(null);
|
|
130
|
-
/**
|
|
131
|
-
* This is a hook to use the GlobalSelectionContext.
|
|
132
|
-
*
|
|
133
|
-
* @requires GlobalSelectionProvider
|
|
134
|
-
* @example
|
|
135
|
-
* import { useGlobalSelection } from "@trackunit/react-core-hooks";
|
|
136
|
-
*
|
|
137
|
-
* export const useActiveGlobalGroupIdFilter = () => {
|
|
138
|
-
* const { selection } = useGlobalSelection();
|
|
139
|
-
* return (selection?.type === "group") ? selection.groupId : undefined;
|
|
140
|
-
* };
|
|
141
|
-
*
|
|
142
|
-
* @see {@link IGlobalSelectionContext}
|
|
143
|
-
*/
|
|
144
|
-
const useGlobalSelection = () => {
|
|
145
|
-
const context = React__namespace.useContext(GlobalSelectionContext);
|
|
146
|
-
if (!context) {
|
|
147
|
-
throw new Error("useGlobalSelection must be used within the GlobalSelectionContext");
|
|
148
|
-
}
|
|
149
|
-
return context;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* This is a provider for the GlobalSelectionContext.
|
|
153
|
-
*/
|
|
128
|
+
const GlobalSelectionContext = React__namespace.createContext(null);
|
|
129
|
+
/**
|
|
130
|
+
* This is a hook to use the GlobalSelectionContext.
|
|
131
|
+
*
|
|
132
|
+
* @requires GlobalSelectionProvider
|
|
133
|
+
* @example
|
|
134
|
+
* import { useGlobalSelection } from "@trackunit/react-core-hooks";
|
|
135
|
+
*
|
|
136
|
+
* export const useActiveGlobalGroupIdFilter = () => {
|
|
137
|
+
* const { selection } = useGlobalSelection();
|
|
138
|
+
* return (selection?.type === "group") ? selection.groupId : undefined;
|
|
139
|
+
* };
|
|
140
|
+
*
|
|
141
|
+
* @see {@link IGlobalSelectionContext}
|
|
142
|
+
*/
|
|
143
|
+
const useGlobalSelection = () => {
|
|
144
|
+
const context = React__namespace.useContext(GlobalSelectionContext);
|
|
145
|
+
if (!context) {
|
|
146
|
+
throw new Error("useGlobalSelection must be used within the GlobalSelectionContext");
|
|
147
|
+
}
|
|
148
|
+
return context;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* This is a provider for the GlobalSelectionContext.
|
|
152
|
+
*/
|
|
154
153
|
const GlobalSelectionProvider = (props) => jsxRuntime.jsx(GlobalSelectionContext.Provider, Object.assign({}, props));
|
|
155
154
|
|
|
156
|
-
const OemBrandingContext = React.createContext(null);
|
|
157
|
-
/**
|
|
158
|
-
* This is a hook to use the IOemBrandingContext.
|
|
159
|
-
*
|
|
160
|
-
* @requires OemBrandingContextProvider
|
|
161
|
-
* @example
|
|
162
|
-
* import { useOemBrandingContext } from "@trackunit/react-core-hooks";
|
|
163
|
-
* const { getOemBranding, getImageByBrand } = useOemBrandingContext();
|
|
164
|
-
* // use oem branding
|
|
165
|
-
* const branding = getOemBranding("some brand")
|
|
166
|
-
*
|
|
167
|
-
* @see {@link IOemBrandingContext}
|
|
168
|
-
*/
|
|
169
|
-
const useOemBrandingContext = () => {
|
|
170
|
-
const context = React.useContext(OemBrandingContext);
|
|
171
|
-
if (!context) {
|
|
172
|
-
throw new Error("useOemBranding must be used within an OemBrandingContextProvider");
|
|
173
|
-
}
|
|
174
|
-
return context;
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
177
|
-
* This is a provider for the IOemBrandingContext.
|
|
178
|
-
*/
|
|
179
|
-
const OemBrandingContextProvider = (props) => {
|
|
180
|
-
return jsxRuntime.jsx(OemBrandingContext.Provider, Object.assign({}, props));
|
|
155
|
+
const OemBrandingContext = React.createContext(null);
|
|
156
|
+
/**
|
|
157
|
+
* This is a hook to use the IOemBrandingContext.
|
|
158
|
+
*
|
|
159
|
+
* @requires OemBrandingContextProvider
|
|
160
|
+
* @example
|
|
161
|
+
* import { useOemBrandingContext } from "@trackunit/react-core-hooks";
|
|
162
|
+
* const { getOemBranding, getImageByBrand } = useOemBrandingContext();
|
|
163
|
+
* // use oem branding
|
|
164
|
+
* const branding = getOemBranding("some brand")
|
|
165
|
+
*
|
|
166
|
+
* @see {@link IOemBrandingContext}
|
|
167
|
+
*/
|
|
168
|
+
const useOemBrandingContext = () => {
|
|
169
|
+
const context = React.useContext(OemBrandingContext);
|
|
170
|
+
if (!context) {
|
|
171
|
+
throw new Error("useOemBranding must be used within an OemBrandingContextProvider");
|
|
172
|
+
}
|
|
173
|
+
return context;
|
|
181
174
|
};
|
|
175
|
+
/**
|
|
176
|
+
* This is a provider for the IOemBrandingContext.
|
|
177
|
+
*/
|
|
178
|
+
const OemBrandingContextProvider = (props) => {
|
|
179
|
+
return jsxRuntime.jsx(OemBrandingContext.Provider, Object.assign({}, props));
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @remix-run/router v1.6.2
|
|
184
|
+
*
|
|
185
|
+
* Copyright (c) Remix Software Inc.
|
|
186
|
+
*
|
|
187
|
+
* This source code is licensed under the MIT license found in the
|
|
188
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
189
|
+
*
|
|
190
|
+
* @license MIT
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
194
|
+
//#region Types and Constants
|
|
195
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Actions represent the type of change to a location value.
|
|
199
|
+
*/
|
|
200
|
+
var Action;
|
|
201
|
+
|
|
202
|
+
(function (Action) {
|
|
203
|
+
/**
|
|
204
|
+
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
205
|
+
* as a back or forward navigation. It does not describe the direction of the
|
|
206
|
+
* navigation, only that the current index changed.
|
|
207
|
+
*
|
|
208
|
+
* Note: This is the default action for newly created history objects.
|
|
209
|
+
*/
|
|
210
|
+
Action["Pop"] = "POP";
|
|
211
|
+
/**
|
|
212
|
+
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
213
|
+
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
214
|
+
* entries in the stack are lost.
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
Action["Push"] = "PUSH";
|
|
218
|
+
/**
|
|
219
|
+
* A REPLACE indicates the entry at the current index in the history stack
|
|
220
|
+
* being replaced by a new one.
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
Action["Replace"] = "REPLACE";
|
|
224
|
+
})(Action || (Action = {}));
|
|
225
|
+
function invariant(value, message) {
|
|
226
|
+
if (value === false || value === null || typeof value === "undefined") {
|
|
227
|
+
throw new Error(message);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
var ResultType;
|
|
232
|
+
|
|
233
|
+
(function (ResultType) {
|
|
234
|
+
ResultType["data"] = "data";
|
|
235
|
+
ResultType["deferred"] = "deferred";
|
|
236
|
+
ResultType["redirect"] = "redirect";
|
|
237
|
+
ResultType["error"] = "error";
|
|
238
|
+
})(ResultType || (ResultType = {}));
|
|
239
|
+
|
|
240
|
+
const validMutationMethodsArr = ["post", "put", "patch", "delete"];
|
|
241
|
+
["get", ...validMutationMethodsArr];
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* React Router v6.11.2
|
|
245
|
+
*
|
|
246
|
+
* Copyright (c) Remix Software Inc.
|
|
247
|
+
*
|
|
248
|
+
* This source code is licensed under the MIT license found in the
|
|
249
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
250
|
+
*
|
|
251
|
+
* @license MIT
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
const DataRouterContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
255
|
+
|
|
256
|
+
if (process.env.NODE_ENV !== "production") {
|
|
257
|
+
DataRouterContext.displayName = "DataRouter";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const DataRouterStateContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
261
|
+
|
|
262
|
+
if (process.env.NODE_ENV !== "production") {
|
|
263
|
+
DataRouterStateContext.displayName = "DataRouterState";
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const AwaitContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
267
|
+
|
|
268
|
+
if (process.env.NODE_ENV !== "production") {
|
|
269
|
+
AwaitContext.displayName = "Await";
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const NavigationContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
273
|
+
|
|
274
|
+
if (process.env.NODE_ENV !== "production") {
|
|
275
|
+
NavigationContext.displayName = "Navigation";
|
|
276
|
+
}
|
|
182
277
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
278
|
+
const LocationContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
279
|
+
|
|
280
|
+
if (process.env.NODE_ENV !== "production") {
|
|
281
|
+
LocationContext.displayName = "Location";
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const RouteContext = /*#__PURE__*/React__namespace.createContext({
|
|
285
|
+
outlet: null,
|
|
286
|
+
matches: [],
|
|
287
|
+
isDataRoute: false
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
if (process.env.NODE_ENV !== "production") {
|
|
291
|
+
RouteContext.displayName = "Route";
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const RouteErrorContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
295
|
+
|
|
296
|
+
if (process.env.NODE_ENV !== "production") {
|
|
297
|
+
RouteErrorContext.displayName = "RouteError";
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Returns true if this component is a descendant of a <Router>.
|
|
301
|
+
*
|
|
302
|
+
* @see https://reactrouter.com/hooks/use-in-router-context
|
|
303
|
+
*/
|
|
304
|
+
|
|
305
|
+
function useInRouterContext() {
|
|
306
|
+
return React__namespace.useContext(LocationContext) != null;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Returns the current location object, which represents the current URL in web
|
|
310
|
+
* browsers.
|
|
311
|
+
*
|
|
312
|
+
* Note: If you're using this it may mean you're doing some of your own
|
|
313
|
+
* "routing" in your app, and we'd like to know what your use case is. We may
|
|
314
|
+
* be able to provide something higher-level to better suit your needs.
|
|
315
|
+
*
|
|
316
|
+
* @see https://reactrouter.com/hooks/use-location
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
function useLocation() {
|
|
320
|
+
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
321
|
+
// router loaded. We can help them understand how to avoid that.
|
|
322
|
+
"useLocation() may be used only in the context of a <Router> component.") : invariant(false) : void 0;
|
|
323
|
+
return React__namespace.useContext(LocationContext).location;
|
|
324
|
+
}
|
|
325
|
+
var DataRouterHook;
|
|
326
|
+
|
|
327
|
+
(function (DataRouterHook) {
|
|
328
|
+
DataRouterHook["UseBlocker"] = "useBlocker";
|
|
329
|
+
DataRouterHook["UseRevalidator"] = "useRevalidator";
|
|
330
|
+
DataRouterHook["UseNavigateStable"] = "useNavigate";
|
|
331
|
+
})(DataRouterHook || (DataRouterHook = {}));
|
|
332
|
+
|
|
333
|
+
var DataRouterStateHook;
|
|
334
|
+
|
|
335
|
+
(function (DataRouterStateHook) {
|
|
336
|
+
DataRouterStateHook["UseBlocker"] = "useBlocker";
|
|
337
|
+
DataRouterStateHook["UseLoaderData"] = "useLoaderData";
|
|
338
|
+
DataRouterStateHook["UseActionData"] = "useActionData";
|
|
339
|
+
DataRouterStateHook["UseRouteError"] = "useRouteError";
|
|
340
|
+
DataRouterStateHook["UseNavigation"] = "useNavigation";
|
|
341
|
+
DataRouterStateHook["UseRouteLoaderData"] = "useRouteLoaderData";
|
|
342
|
+
DataRouterStateHook["UseMatches"] = "useMatches";
|
|
343
|
+
DataRouterStateHook["UseRevalidator"] = "useRevalidator";
|
|
344
|
+
DataRouterStateHook["UseNavigateStable"] = "useNavigate";
|
|
345
|
+
DataRouterStateHook["UseRouteId"] = "useRouteId";
|
|
346
|
+
})(DataRouterStateHook || (DataRouterStateHook = {}));
|
|
347
|
+
var AwaitRenderStatus;
|
|
348
|
+
|
|
349
|
+
(function (AwaitRenderStatus) {
|
|
350
|
+
AwaitRenderStatus[AwaitRenderStatus["pending"] = 0] = "pending";
|
|
351
|
+
AwaitRenderStatus[AwaitRenderStatus["success"] = 1] = "success";
|
|
352
|
+
AwaitRenderStatus[AwaitRenderStatus["error"] = 2] = "error";
|
|
353
|
+
})(AwaitRenderStatus || (AwaitRenderStatus = {}));
|
|
354
|
+
|
|
355
|
+
new Promise(() => {});
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* A react hook for notifying host about location changes
|
|
359
|
+
*/
|
|
360
|
+
const useURLSynchronization = () => {
|
|
361
|
+
const location = useLocation();
|
|
362
|
+
React__default["default"].useEffect(() => {
|
|
363
|
+
const deepLink = {
|
|
364
|
+
path: location.pathname,
|
|
365
|
+
search: location.search,
|
|
366
|
+
hash: location.hash,
|
|
367
|
+
pathname: "",
|
|
368
|
+
};
|
|
369
|
+
irisAppRuntimeCore.NavigationRuntime.setDeepLink(deepLink);
|
|
370
|
+
}, [location]);
|
|
197
371
|
};
|
|
198
372
|
|
|
199
|
-
/**
|
|
200
|
-
* A hook to expose navigation runtime for React components
|
|
201
|
-
*
|
|
202
|
-
* @requires NavigationRuntime
|
|
203
|
-
* @returns {UseNavigationRuntime} navigationRuntime
|
|
204
|
-
* @example
|
|
205
|
-
* import { useNavigationRuntime } from "@trackunit/react-core-hooks";
|
|
206
|
-
* const { navigateTo } = useNavigationRuntime();
|
|
207
|
-
* // ...
|
|
208
|
-
* <Link onClick={() => gotoAssetHome(asset.id)} to="">
|
|
209
|
-
* {asset.name}
|
|
210
|
-
* </Link>
|
|
211
|
-
*/
|
|
212
|
-
const useNavigationRuntime = () => {
|
|
213
|
-
return irisAppRuntimeCore.NavigationRuntime;
|
|
373
|
+
/**
|
|
374
|
+
* A hook to expose navigation runtime for React components
|
|
375
|
+
*
|
|
376
|
+
* @requires NavigationRuntime
|
|
377
|
+
* @returns {UseNavigationRuntime} navigationRuntime
|
|
378
|
+
* @example
|
|
379
|
+
* import { useNavigationRuntime } from "@trackunit/react-core-hooks";
|
|
380
|
+
* const { navigateTo } = useNavigationRuntime();
|
|
381
|
+
* // ...
|
|
382
|
+
* <Link onClick={() => gotoAssetHome(asset.id)} to="">
|
|
383
|
+
* {asset.name}
|
|
384
|
+
* </Link>
|
|
385
|
+
*/
|
|
386
|
+
const useNavigationRuntime = () => {
|
|
387
|
+
return irisAppRuntimeCore.NavigationRuntime;
|
|
214
388
|
};
|
|
215
389
|
|
|
216
390
|
/******************************************************************************
|
|
@@ -238,240 +412,240 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
238
412
|
});
|
|
239
413
|
}
|
|
240
414
|
|
|
241
|
-
/**
|
|
242
|
-
* A hook to expose asset runtime for React components
|
|
243
|
-
*
|
|
244
|
-
* @requires AssetRuntime
|
|
245
|
-
* @returns {UseAssetRuntime} assetRuntime
|
|
246
|
-
* @example
|
|
247
|
-
* import { useAssetRuntime } from "@trackunit/react-core-hooks";
|
|
248
|
-
* const { assetInfo } = useAssetRuntime();
|
|
249
|
-
* useEffect(() => {
|
|
250
|
-
* (async () => {
|
|
251
|
-
* if (assetInfo) {
|
|
252
|
-
* getAssetLocation({ variables: { id: assetInfo.assetId } });
|
|
253
|
-
* }
|
|
254
|
-
* })();
|
|
255
|
-
* }, [assetInfo, getAssetLocation]);
|
|
256
|
-
*
|
|
257
|
-
*/
|
|
258
|
-
const useAssetRuntime = () => {
|
|
259
|
-
const [assetInfo, setAssetInfo] = React.useState();
|
|
260
|
-
React.useEffect(() => {
|
|
261
|
-
const getAssetInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
-
const updatedAssetInfo = yield irisAppRuntimeCore.AssetRuntime.getAssetInfo();
|
|
263
|
-
setAssetInfo(updatedAssetInfo);
|
|
264
|
-
});
|
|
265
|
-
getAssetInfo();
|
|
266
|
-
}, []);
|
|
267
|
-
return { assetInfo };
|
|
415
|
+
/**
|
|
416
|
+
* A hook to expose asset runtime for React components
|
|
417
|
+
*
|
|
418
|
+
* @requires AssetRuntime
|
|
419
|
+
* @returns {UseAssetRuntime} assetRuntime
|
|
420
|
+
* @example
|
|
421
|
+
* import { useAssetRuntime } from "@trackunit/react-core-hooks";
|
|
422
|
+
* const { assetInfo } = useAssetRuntime();
|
|
423
|
+
* useEffect(() => {
|
|
424
|
+
* (async () => {
|
|
425
|
+
* if (assetInfo) {
|
|
426
|
+
* getAssetLocation({ variables: { id: assetInfo.assetId } });
|
|
427
|
+
* }
|
|
428
|
+
* })();
|
|
429
|
+
* }, [assetInfo, getAssetLocation]);
|
|
430
|
+
*
|
|
431
|
+
*/
|
|
432
|
+
const useAssetRuntime = () => {
|
|
433
|
+
const [assetInfo, setAssetInfo] = React.useState();
|
|
434
|
+
React.useEffect(() => {
|
|
435
|
+
const getAssetInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
436
|
+
const updatedAssetInfo = yield irisAppRuntimeCore.AssetRuntime.getAssetInfo();
|
|
437
|
+
setAssetInfo(updatedAssetInfo);
|
|
438
|
+
});
|
|
439
|
+
getAssetInfo();
|
|
440
|
+
}, []);
|
|
441
|
+
return { assetInfo };
|
|
268
442
|
};
|
|
269
443
|
|
|
270
|
-
/**
|
|
271
|
-
* A hook to expose custom field runtime methods
|
|
272
|
-
*
|
|
273
|
-
* @returns {UseCustomFieldRuntime} CustomFieldRuntime
|
|
274
|
-
*/
|
|
275
|
-
const useCustomFieldRuntime = () => {
|
|
276
|
-
return irisAppRuntimeCore.CustomFieldRuntime;
|
|
444
|
+
/**
|
|
445
|
+
* A hook to expose custom field runtime methods
|
|
446
|
+
*
|
|
447
|
+
* @returns {UseCustomFieldRuntime} CustomFieldRuntime
|
|
448
|
+
*/
|
|
449
|
+
const useCustomFieldRuntime = () => {
|
|
450
|
+
return irisAppRuntimeCore.CustomFieldRuntime;
|
|
277
451
|
};
|
|
278
452
|
|
|
279
|
-
/**
|
|
280
|
-
* This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
|
|
281
|
-
*
|
|
282
|
-
* @param entity The entity to fetch and set custom fields for.
|
|
283
|
-
* @returns The custom fields for the entity, and functions to set custom fields for the entity.
|
|
284
|
-
* @example
|
|
285
|
-
* import { useAssetRuntime, useCustomFieldRuntimeForEntity } from '@trackunit/react-core-hooks';
|
|
286
|
-
* const { assetInfo } = useAssetRuntime();
|
|
287
|
-
* const { customFields, setCustomFieldsForEntity } = useCustomFieldRuntimeForEntity( {
|
|
288
|
-
* id: assetInfo?.assetId || '',
|
|
289
|
-
* type: 'ASSET'
|
|
290
|
-
* });
|
|
291
|
-
*
|
|
292
|
-
* // set custom field data
|
|
293
|
-
* setCustomFieldsForEntity({"key": "value"});
|
|
294
|
-
*/
|
|
295
|
-
const useCustomFieldRuntimeForEntity = (entity) => {
|
|
296
|
-
const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
|
|
297
|
-
const [customFields, setCustomFields] = React.useState();
|
|
298
|
-
React.useEffect(() => {
|
|
299
|
-
if (entity.id) {
|
|
300
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
-
setCustomFields(yield getCustomFieldsFor(entity));
|
|
302
|
-
}))();
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
setCustomFields([]);
|
|
306
|
-
}
|
|
307
|
-
}, [entity, getCustomFieldsFor]);
|
|
308
|
-
const setCustomFieldsForEntity = (values) => __awaiter(void 0, void 0, void 0, function* () {
|
|
309
|
-
if (entity.id) {
|
|
310
|
-
yield setCustomFieldsFor(entity, values);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
const setCustomFieldsFromFormDataForEntity = (formData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
314
|
-
if (entity.id) {
|
|
315
|
-
yield setCustomFieldsFromFormData(entity, formData, customFields || []);
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
return {
|
|
319
|
-
customFields,
|
|
320
|
-
setCustomFieldsFromFormDataForEntity,
|
|
321
|
-
setCustomFieldsForEntity,
|
|
322
|
-
};
|
|
453
|
+
/**
|
|
454
|
+
* This hook is a wrapper around useCustomFieldRuntime that automatically fetches and sets custom fields for a given entity.
|
|
455
|
+
*
|
|
456
|
+
* @param entity The entity to fetch and set custom fields for.
|
|
457
|
+
* @returns The custom fields for the entity, and functions to set custom fields for the entity.
|
|
458
|
+
* @example
|
|
459
|
+
* import { useAssetRuntime, useCustomFieldRuntimeForEntity } from '@trackunit/react-core-hooks';
|
|
460
|
+
* const { assetInfo } = useAssetRuntime();
|
|
461
|
+
* const { customFields, setCustomFieldsForEntity } = useCustomFieldRuntimeForEntity( {
|
|
462
|
+
* id: assetInfo?.assetId || '',
|
|
463
|
+
* type: 'ASSET'
|
|
464
|
+
* });
|
|
465
|
+
*
|
|
466
|
+
* // set custom field data
|
|
467
|
+
* setCustomFieldsForEntity({"key": "value"});
|
|
468
|
+
*/
|
|
469
|
+
const useCustomFieldRuntimeForEntity = (entity) => {
|
|
470
|
+
const { getCustomFieldsFor, setCustomFieldsFromFormData, setCustomFieldsFor } = useCustomFieldRuntime();
|
|
471
|
+
const [customFields, setCustomFields] = React.useState();
|
|
472
|
+
React.useEffect(() => {
|
|
473
|
+
if (entity.id) {
|
|
474
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
475
|
+
setCustomFields(yield getCustomFieldsFor(entity));
|
|
476
|
+
}))();
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
setCustomFields([]);
|
|
480
|
+
}
|
|
481
|
+
}, [entity, getCustomFieldsFor]);
|
|
482
|
+
const setCustomFieldsForEntity = (values) => __awaiter(void 0, void 0, void 0, function* () {
|
|
483
|
+
if (entity.id) {
|
|
484
|
+
yield setCustomFieldsFor(entity, values);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
const setCustomFieldsFromFormDataForEntity = (formData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
488
|
+
if (entity.id) {
|
|
489
|
+
yield setCustomFieldsFromFormData(entity, formData, customFields || []);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
return {
|
|
493
|
+
customFields,
|
|
494
|
+
setCustomFieldsFromFormDataForEntity,
|
|
495
|
+
setCustomFieldsForEntity,
|
|
496
|
+
};
|
|
323
497
|
};
|
|
324
498
|
|
|
325
|
-
/**
|
|
326
|
-
* A hook to expose rest runtime to be used in React components
|
|
327
|
-
*
|
|
328
|
-
* @returns {UseRestRuntime} a RestRuntime
|
|
329
|
-
*/
|
|
330
|
-
const useRestRuntime = () => {
|
|
331
|
-
return irisAppRuntimeCore.RestRuntime;
|
|
499
|
+
/**
|
|
500
|
+
* A hook to expose rest runtime to be used in React components
|
|
501
|
+
*
|
|
502
|
+
* @returns {UseRestRuntime} a RestRuntime
|
|
503
|
+
*/
|
|
504
|
+
const useRestRuntime = () => {
|
|
505
|
+
return irisAppRuntimeCore.RestRuntime;
|
|
332
506
|
};
|
|
333
507
|
|
|
334
|
-
/**
|
|
335
|
-
* A hook to expose site runtime for React components
|
|
336
|
-
*
|
|
337
|
-
* @requires SiteRuntime
|
|
338
|
-
* @returns {UseSiteRuntime} siteRuntime
|
|
339
|
-
* @example
|
|
340
|
-
* import { useSiteRuntime } from "@trackunit/react-core-hooks";
|
|
341
|
-
* const { siteInfo } = useSiteRuntime();
|
|
342
|
-
* // use siteInfo to get assets for instance.
|
|
343
|
-
* useEffect(() => {
|
|
344
|
-
* (async () => {
|
|
345
|
-
* if (siteInfo?.siteId) {
|
|
346
|
-
* getSiteAssets({ variables: { siteId: siteInfo?.siteId, siteIdStr: siteInfo?.siteId } });
|
|
347
|
-
* }
|
|
348
|
-
* })();
|
|
349
|
-
* }, [getSiteAssets, siteInfo]);
|
|
350
|
-
*
|
|
351
|
-
*/
|
|
352
|
-
const useSiteRuntime = () => {
|
|
353
|
-
const [siteInfo, setSiteInfo] = React.useState();
|
|
354
|
-
React.useEffect(() => {
|
|
355
|
-
const getSiteInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
356
|
-
const updatedSiteInfo = yield irisAppRuntimeCore.SiteRuntime.getSiteInfo();
|
|
357
|
-
setSiteInfo(updatedSiteInfo);
|
|
358
|
-
});
|
|
359
|
-
getSiteInfo();
|
|
360
|
-
}, []);
|
|
361
|
-
return { siteInfo };
|
|
508
|
+
/**
|
|
509
|
+
* A hook to expose site runtime for React components
|
|
510
|
+
*
|
|
511
|
+
* @requires SiteRuntime
|
|
512
|
+
* @returns {UseSiteRuntime} siteRuntime
|
|
513
|
+
* @example
|
|
514
|
+
* import { useSiteRuntime } from "@trackunit/react-core-hooks";
|
|
515
|
+
* const { siteInfo } = useSiteRuntime();
|
|
516
|
+
* // use siteInfo to get assets for instance.
|
|
517
|
+
* useEffect(() => {
|
|
518
|
+
* (async () => {
|
|
519
|
+
* if (siteInfo?.siteId) {
|
|
520
|
+
* getSiteAssets({ variables: { siteId: siteInfo?.siteId, siteIdStr: siteInfo?.siteId } });
|
|
521
|
+
* }
|
|
522
|
+
* })();
|
|
523
|
+
* }, [getSiteAssets, siteInfo]);
|
|
524
|
+
*
|
|
525
|
+
*/
|
|
526
|
+
const useSiteRuntime = () => {
|
|
527
|
+
const [siteInfo, setSiteInfo] = React.useState();
|
|
528
|
+
React.useEffect(() => {
|
|
529
|
+
const getSiteInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
530
|
+
const updatedSiteInfo = yield irisAppRuntimeCore.SiteRuntime.getSiteInfo();
|
|
531
|
+
setSiteInfo(updatedSiteInfo);
|
|
532
|
+
});
|
|
533
|
+
getSiteInfo();
|
|
534
|
+
}, []);
|
|
535
|
+
return { siteInfo };
|
|
362
536
|
};
|
|
363
537
|
|
|
364
|
-
const UserSubscriptionContext = React__namespace.createContext(null);
|
|
365
|
-
/**
|
|
366
|
-
* This is a provider for the UserSubscriptionContext.
|
|
367
|
-
*/
|
|
368
|
-
const UserSubscriptionProvider = (props) => {
|
|
369
|
-
return jsxRuntime.jsx(UserSubscriptionContext.Provider, Object.assign({}, props));
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* This is a hook to use the UserSubscriptionContext.
|
|
373
|
-
*
|
|
374
|
-
* @requires UserSubscriptionProvider
|
|
375
|
-
* @example
|
|
376
|
-
* import { useUserSubscription } from "@trackunit/react-core-hooks";
|
|
377
|
-
* const { numberOfDaysWithAccessToHistoricalData, packageType } = useUserSubscription();
|
|
378
|
-
* // use it for something
|
|
379
|
-
* const data = fetchData(numberOfDaysWithAccessToHistoricalData)
|
|
380
|
-
*
|
|
381
|
-
* @see {@link IUserSubscriptionContext}
|
|
382
|
-
*/
|
|
383
|
-
const useUserSubscription = () => {
|
|
384
|
-
const context = React__namespace.useContext(UserSubscriptionContext);
|
|
385
|
-
if (!context) {
|
|
386
|
-
throw new Error("Cannot use useUserSubscription outside UserSubscriptionProvider");
|
|
387
|
-
}
|
|
388
|
-
return context;
|
|
538
|
+
const UserSubscriptionContext = React__namespace.createContext(null);
|
|
539
|
+
/**
|
|
540
|
+
* This is a provider for the UserSubscriptionContext.
|
|
541
|
+
*/
|
|
542
|
+
const UserSubscriptionProvider = (props) => {
|
|
543
|
+
return jsxRuntime.jsx(UserSubscriptionContext.Provider, Object.assign({}, props));
|
|
544
|
+
};
|
|
545
|
+
/**
|
|
546
|
+
* This is a hook to use the UserSubscriptionContext.
|
|
547
|
+
*
|
|
548
|
+
* @requires UserSubscriptionProvider
|
|
549
|
+
* @example
|
|
550
|
+
* import { useUserSubscription } from "@trackunit/react-core-hooks";
|
|
551
|
+
* const { numberOfDaysWithAccessToHistoricalData, packageType } = useUserSubscription();
|
|
552
|
+
* // use it for something
|
|
553
|
+
* const data = fetchData(numberOfDaysWithAccessToHistoricalData)
|
|
554
|
+
*
|
|
555
|
+
* @see {@link IUserSubscriptionContext}
|
|
556
|
+
*/
|
|
557
|
+
const useUserSubscription = () => {
|
|
558
|
+
const context = React__namespace.useContext(UserSubscriptionContext);
|
|
559
|
+
if (!context) {
|
|
560
|
+
throw new Error("Cannot use useUserSubscription outside UserSubscriptionProvider");
|
|
561
|
+
}
|
|
562
|
+
return context;
|
|
389
563
|
};
|
|
390
564
|
|
|
391
|
-
const ToastContext = React__namespace.createContext(null);
|
|
392
|
-
/**
|
|
393
|
-
* This is a provider for the ToastContext.
|
|
394
|
-
*/
|
|
395
|
-
const ToastProvider = (props) => jsxRuntime.jsx(ToastContext.Provider, Object.assign({}, props));
|
|
396
|
-
/**
|
|
397
|
-
* This is a hook to use the ToastContext.
|
|
398
|
-
*
|
|
399
|
-
* @requires ToastProvider
|
|
400
|
-
* @example
|
|
401
|
-
* import { useToast } from "@trackunit/react-core-hooks";
|
|
402
|
-
* const { addToast } = useToast();
|
|
403
|
-
* // use the toast
|
|
404
|
-
* error &&
|
|
405
|
-
* addToast({
|
|
406
|
-
* intent: "warning",
|
|
407
|
-
* title: t("assetHome.specification.failedToSave"),
|
|
408
|
-
* description: error?.message,
|
|
409
|
-
* duration: 3000,
|
|
410
|
-
* });
|
|
411
|
-
*
|
|
412
|
-
* @see {@link IToastContext}
|
|
413
|
-
*/
|
|
414
|
-
const useToast = () => {
|
|
415
|
-
const toastContext = React__namespace.useContext(ToastContext);
|
|
416
|
-
if (!toastContext) {
|
|
417
|
-
throw new Error("useToast must be used within the ToastProvider");
|
|
418
|
-
}
|
|
419
|
-
return toastContext;
|
|
565
|
+
const ToastContext = React__namespace.createContext(null);
|
|
566
|
+
/**
|
|
567
|
+
* This is a provider for the ToastContext.
|
|
568
|
+
*/
|
|
569
|
+
const ToastProvider = (props) => jsxRuntime.jsx(ToastContext.Provider, Object.assign({}, props));
|
|
570
|
+
/**
|
|
571
|
+
* This is a hook to use the ToastContext.
|
|
572
|
+
*
|
|
573
|
+
* @requires ToastProvider
|
|
574
|
+
* @example
|
|
575
|
+
* import { useToast } from "@trackunit/react-core-hooks";
|
|
576
|
+
* const { addToast } = useToast();
|
|
577
|
+
* // use the toast
|
|
578
|
+
* error &&
|
|
579
|
+
* addToast({
|
|
580
|
+
* intent: "warning",
|
|
581
|
+
* title: t("assetHome.specification.failedToSave"),
|
|
582
|
+
* description: error?.message,
|
|
583
|
+
* duration: 3000,
|
|
584
|
+
* });
|
|
585
|
+
*
|
|
586
|
+
* @see {@link IToastContext}
|
|
587
|
+
*/
|
|
588
|
+
const useToast = () => {
|
|
589
|
+
const toastContext = React__namespace.useContext(ToastContext);
|
|
590
|
+
if (!toastContext) {
|
|
591
|
+
throw new Error("useToast must be used within the ToastProvider");
|
|
592
|
+
}
|
|
593
|
+
return toastContext;
|
|
420
594
|
};
|
|
421
595
|
|
|
422
|
-
const TokenContext = React__namespace.createContext(null);
|
|
423
|
-
/**
|
|
424
|
-
* This is a hook to use the TokenContext.
|
|
425
|
-
*
|
|
426
|
-
* @requires TokenProvider
|
|
427
|
-
* @example
|
|
428
|
-
* import { useToken } from "@trackunit/react-core-hooks";
|
|
429
|
-
* const { token } = useToken();
|
|
430
|
-
*
|
|
431
|
-
* @see {@link ITokenContext}
|
|
432
|
-
*/
|
|
433
|
-
const useToken = () => {
|
|
434
|
-
const context = React__namespace.useContext(TokenContext);
|
|
435
|
-
if (!context) {
|
|
436
|
-
throw new Error("useToken must be used within the TokenContext");
|
|
437
|
-
}
|
|
438
|
-
return context;
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* This is a provider for the TokenContext.
|
|
442
|
-
*/
|
|
443
|
-
const TokenProvider = (props) => {
|
|
444
|
-
return jsxRuntime.jsx(TokenContext.Provider, Object.assign({}, props));
|
|
596
|
+
const TokenContext = React__namespace.createContext(null);
|
|
597
|
+
/**
|
|
598
|
+
* This is a hook to use the TokenContext.
|
|
599
|
+
*
|
|
600
|
+
* @requires TokenProvider
|
|
601
|
+
* @example
|
|
602
|
+
* import { useToken } from "@trackunit/react-core-hooks";
|
|
603
|
+
* const { token } = useToken();
|
|
604
|
+
*
|
|
605
|
+
* @see {@link ITokenContext}
|
|
606
|
+
*/
|
|
607
|
+
const useToken = () => {
|
|
608
|
+
const context = React__namespace.useContext(TokenContext);
|
|
609
|
+
if (!context) {
|
|
610
|
+
throw new Error("useToken must be used within the TokenContext");
|
|
611
|
+
}
|
|
612
|
+
return context;
|
|
613
|
+
};
|
|
614
|
+
/**
|
|
615
|
+
* This is a provider for the TokenContext.
|
|
616
|
+
*/
|
|
617
|
+
const TokenProvider = (props) => {
|
|
618
|
+
return jsxRuntime.jsx(TokenContext.Provider, Object.assign({}, props));
|
|
445
619
|
};
|
|
446
620
|
|
|
447
|
-
const CurrentUserContext = React__namespace.createContext(null);
|
|
448
|
-
/**
|
|
449
|
-
* This is a provider for the CurrentUserContext.
|
|
450
|
-
*/
|
|
451
|
-
const CurrentUserProvider = (props) => {
|
|
452
|
-
return jsxRuntime.jsx(CurrentUserContext.Provider, Object.assign({}, props));
|
|
453
|
-
};
|
|
454
|
-
/**
|
|
455
|
-
* This is a hook providing the CurrentUserContext.
|
|
456
|
-
*
|
|
457
|
-
* @requires CurrentUserProvider
|
|
458
|
-
* @example
|
|
459
|
-
* import { useCurrentUser } from "@trackunit/react-core-hooks";
|
|
460
|
-
* const { assumedUser, accountId } = useCurrentUser();
|
|
461
|
-
*
|
|
462
|
-
* //use it for something
|
|
463
|
-
* const { data, loading } = useGetAccountByIdQuery({
|
|
464
|
-
* variables: { accountId: assumedUser?.accountId || accountId || "" },
|
|
465
|
-
* });
|
|
466
|
-
*
|
|
467
|
-
* @see {@link ICurrentUserContext}
|
|
468
|
-
*/
|
|
469
|
-
const useCurrentUser = () => {
|
|
470
|
-
const context = React__namespace.useContext(CurrentUserContext);
|
|
471
|
-
if (!context) {
|
|
472
|
-
throw new Error("useCurrentUser must be used within the CurrentUserProvider");
|
|
473
|
-
}
|
|
474
|
-
return context;
|
|
621
|
+
const CurrentUserContext = React__namespace.createContext(null);
|
|
622
|
+
/**
|
|
623
|
+
* This is a provider for the CurrentUserContext.
|
|
624
|
+
*/
|
|
625
|
+
const CurrentUserProvider = (props) => {
|
|
626
|
+
return jsxRuntime.jsx(CurrentUserContext.Provider, Object.assign({}, props));
|
|
627
|
+
};
|
|
628
|
+
/**
|
|
629
|
+
* This is a hook providing the CurrentUserContext.
|
|
630
|
+
*
|
|
631
|
+
* @requires CurrentUserProvider
|
|
632
|
+
* @example
|
|
633
|
+
* import { useCurrentUser } from "@trackunit/react-core-hooks";
|
|
634
|
+
* const { assumedUser, accountId } = useCurrentUser();
|
|
635
|
+
*
|
|
636
|
+
* //use it for something
|
|
637
|
+
* const { data, loading } = useGetAccountByIdQuery({
|
|
638
|
+
* variables: { accountId: assumedUser?.accountId || accountId || "" },
|
|
639
|
+
* });
|
|
640
|
+
*
|
|
641
|
+
* @see {@link ICurrentUserContext}
|
|
642
|
+
*/
|
|
643
|
+
const useCurrentUser = () => {
|
|
644
|
+
const context = React__namespace.useContext(CurrentUserContext);
|
|
645
|
+
if (!context) {
|
|
646
|
+
throw new Error("useCurrentUser must be used within the CurrentUserProvider");
|
|
647
|
+
}
|
|
648
|
+
return context;
|
|
475
649
|
};
|
|
476
650
|
|
|
477
651
|
exports.AnalyticsContext = AnalyticsContext;
|