@trackunit/react-core-hooks 0.2.31 → 0.2.33-alpha-0b53b6cf53.0
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 +261 -0
- package/package.json +4 -4
package/index.cjs
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
8
|
+
var reactRouterDom = require('react-router-dom');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
function _interopNamespace(e) {
|
|
13
|
+
if (e && e.__esModule) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n["default"] = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
31
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
32
|
+
|
|
33
|
+
const AssetSortingContext = React.createContext(null);
|
|
34
|
+
const AssetSortingProvider = (props) => jsxRuntime.jsx(AssetSortingContext.Provider, Object.assign({}, props));
|
|
35
|
+
const useAssetSorting = () => {
|
|
36
|
+
const context = React.useContext(AssetSortingContext);
|
|
37
|
+
if (!context) {
|
|
38
|
+
throw new Error("useAssetSorting must be used within a AssetSortingProvider");
|
|
39
|
+
}
|
|
40
|
+
return context;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const DeveloperSettingsContext = React__namespace.createContext({
|
|
44
|
+
localFeatureFlagsEnabled: false,
|
|
45
|
+
});
|
|
46
|
+
const useDeveloperSettings = () => {
|
|
47
|
+
const context = React__namespace.useContext(DeveloperSettingsContext);
|
|
48
|
+
if (!context) {
|
|
49
|
+
throw new Error("useDeveloperSettingsContext must be used within DeveloperSettingsProvider");
|
|
50
|
+
}
|
|
51
|
+
return context;
|
|
52
|
+
};
|
|
53
|
+
const DeveloperSettingsProvider = ({ value, children }) => {
|
|
54
|
+
const [localFeatureFlagsEnabled, setLocalFeatureFlagsEnabled] = React__namespace.useState(false);
|
|
55
|
+
const [localFeatureFlags, setLocalFeatureFlags] = React__namespace.useState();
|
|
56
|
+
React__namespace.useEffect(() => {
|
|
57
|
+
if (!localFeatureFlagsEnabled) {
|
|
58
|
+
setLocalFeatureFlags({});
|
|
59
|
+
}
|
|
60
|
+
}, [localFeatureFlagsEnabled]);
|
|
61
|
+
return (jsxRuntime.jsx(DeveloperSettingsContext.Provider, Object.assign({ value: value !== null && value !== void 0 ? value : {
|
|
62
|
+
localFeatureFlagsEnabled,
|
|
63
|
+
enableLocalFeatureFlags: setLocalFeatureFlagsEnabled,
|
|
64
|
+
localFeatureFlags,
|
|
65
|
+
setFlags: setLocalFeatureFlags,
|
|
66
|
+
} }, { children: children })));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const EnvironmentContext = React.createContext(null);
|
|
70
|
+
const EnvironmentContextProvider = (props) => {
|
|
71
|
+
return jsxRuntime.jsx(EnvironmentContext.Provider, Object.assign({}, props));
|
|
72
|
+
};
|
|
73
|
+
const useEnvironment = () => {
|
|
74
|
+
const context = React.useContext(EnvironmentContext);
|
|
75
|
+
if (!context) {
|
|
76
|
+
throw new Error("useEnvironment must be used within an EnvironmentContext");
|
|
77
|
+
}
|
|
78
|
+
return context;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const GlobalSelectionContext = React__namespace.createContext(null);
|
|
82
|
+
const useGlobalSelection = () => {
|
|
83
|
+
const context = React__namespace.useContext(GlobalSelectionContext);
|
|
84
|
+
if (!context) {
|
|
85
|
+
throw new Error("useGlobalSelection must be used within the GlobalSelectionContext");
|
|
86
|
+
}
|
|
87
|
+
return context;
|
|
88
|
+
};
|
|
89
|
+
const GlobalSelectionProvider = (props) => jsxRuntime.jsx(GlobalSelectionContext.Provider, Object.assign({}, props));
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A react hook for notifying host about location changes
|
|
93
|
+
*/
|
|
94
|
+
const useURLSynchronization = () => {
|
|
95
|
+
const location = reactRouterDom.useLocation();
|
|
96
|
+
React__default["default"].useEffect(() => {
|
|
97
|
+
const deepLink = {
|
|
98
|
+
path: location.pathname,
|
|
99
|
+
search: location.search,
|
|
100
|
+
hash: location.hash,
|
|
101
|
+
pathname: "",
|
|
102
|
+
};
|
|
103
|
+
irisAppRuntimeCore.NavigationRuntime.setDeepLink(deepLink);
|
|
104
|
+
}, [location]);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A hook to expose navigation runtime for React components
|
|
109
|
+
*
|
|
110
|
+
* @returns {UseNavigationRuntime} navigationRuntime
|
|
111
|
+
*/
|
|
112
|
+
const useNavigationRuntime = () => {
|
|
113
|
+
return irisAppRuntimeCore.NavigationRuntime;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/******************************************************************************
|
|
117
|
+
Copyright (c) Microsoft Corporation.
|
|
118
|
+
|
|
119
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
120
|
+
purpose with or without fee is hereby granted.
|
|
121
|
+
|
|
122
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
123
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
124
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
125
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
126
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
127
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
128
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
129
|
+
***************************************************************************** */
|
|
130
|
+
|
|
131
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
132
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
133
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
134
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
135
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
136
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
137
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A hook to expose asset runtime for React components
|
|
143
|
+
*
|
|
144
|
+
* @returns {UseAssetRuntime} assetRuntime
|
|
145
|
+
*/
|
|
146
|
+
const useAssetRuntime = () => {
|
|
147
|
+
const [assetInfo, setAssetInfo] = React.useState();
|
|
148
|
+
React.useEffect(() => {
|
|
149
|
+
const getAssetInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
+
const updatedAssetInfo = yield irisAppRuntimeCore.AssetRuntime.getAssetInfo();
|
|
151
|
+
setAssetInfo(updatedAssetInfo);
|
|
152
|
+
});
|
|
153
|
+
getAssetInfo();
|
|
154
|
+
}, []);
|
|
155
|
+
return { assetInfo };
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A hook to expose custom field runtime methods
|
|
160
|
+
*
|
|
161
|
+
* @returns {UseCustomFieldRuntime} CustomFieldRuntime
|
|
162
|
+
*/
|
|
163
|
+
const useCustomFieldRuntime = () => {
|
|
164
|
+
return irisAppRuntimeCore.CustomFieldRuntime;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A hook to expose rest runtime to be used in React components
|
|
169
|
+
*
|
|
170
|
+
* @returns {UseRestRuntime} a RestRuntime
|
|
171
|
+
*/
|
|
172
|
+
const useRestRuntime = () => {
|
|
173
|
+
return irisAppRuntimeCore.RestRuntime;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A hook to expose site runtime for React components
|
|
178
|
+
*
|
|
179
|
+
* @returns {UseSiteRuntime} siteRuntime
|
|
180
|
+
*/
|
|
181
|
+
const useSiteRuntime = () => {
|
|
182
|
+
const [siteInfo, setSiteInfo] = React.useState();
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
const getSiteInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
+
const updatedSiteInfo = yield irisAppRuntimeCore.SiteRuntime.getSiteInfo();
|
|
186
|
+
setSiteInfo(updatedSiteInfo);
|
|
187
|
+
});
|
|
188
|
+
getSiteInfo();
|
|
189
|
+
}, []);
|
|
190
|
+
return { siteInfo };
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const UserSubscriptionContext = React__namespace.createContext(null);
|
|
194
|
+
const UserSubscriptionProvider = (props) => {
|
|
195
|
+
return jsxRuntime.jsx(UserSubscriptionContext.Provider, Object.assign({}, props));
|
|
196
|
+
};
|
|
197
|
+
const useUserSubscription = () => {
|
|
198
|
+
const context = React__namespace.useContext(UserSubscriptionContext);
|
|
199
|
+
if (!context) {
|
|
200
|
+
throw new Error("Cannot use useUserSubscription outside UserSubscriptionProvider");
|
|
201
|
+
}
|
|
202
|
+
return context;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const ToastContext = React__namespace.createContext(null);
|
|
206
|
+
const ToastProvider = (props) => jsxRuntime.jsx(ToastContext.Provider, Object.assign({}, props));
|
|
207
|
+
const useToast = () => {
|
|
208
|
+
const toastContext = React__namespace.useContext(ToastContext);
|
|
209
|
+
if (!toastContext) {
|
|
210
|
+
throw new Error("useToast must be used within the ToastProvider");
|
|
211
|
+
}
|
|
212
|
+
return toastContext;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const TokenContext = React__namespace.createContext(null);
|
|
216
|
+
const useToken = () => {
|
|
217
|
+
const context = React__namespace.useContext(TokenContext);
|
|
218
|
+
if (!context) {
|
|
219
|
+
throw new Error("useToken must be used within the TokenContext");
|
|
220
|
+
}
|
|
221
|
+
return context;
|
|
222
|
+
};
|
|
223
|
+
const TokenProvider = (props) => {
|
|
224
|
+
return jsxRuntime.jsx(TokenContext.Provider, Object.assign({}, props));
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const CurrentUserContext = React__namespace.createContext(null);
|
|
228
|
+
const CurrentUserProvider = (props) => {
|
|
229
|
+
return jsxRuntime.jsx(CurrentUserContext.Provider, Object.assign({}, props));
|
|
230
|
+
};
|
|
231
|
+
const useCurrentUser = () => {
|
|
232
|
+
const context = React__namespace.useContext(CurrentUserContext);
|
|
233
|
+
if (!context) {
|
|
234
|
+
throw new Error("useCurrentUser must be used within the CurrentUserProvider");
|
|
235
|
+
}
|
|
236
|
+
return context;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
exports.AssetSortingProvider = AssetSortingProvider;
|
|
240
|
+
exports.CurrentUserProvider = CurrentUserProvider;
|
|
241
|
+
exports.DeveloperSettingsContext = DeveloperSettingsContext;
|
|
242
|
+
exports.DeveloperSettingsProvider = DeveloperSettingsProvider;
|
|
243
|
+
exports.EnvironmentContextProvider = EnvironmentContextProvider;
|
|
244
|
+
exports.GlobalSelectionProvider = GlobalSelectionProvider;
|
|
245
|
+
exports.ToastProvider = ToastProvider;
|
|
246
|
+
exports.TokenProvider = TokenProvider;
|
|
247
|
+
exports.UserSubscriptionProvider = UserSubscriptionProvider;
|
|
248
|
+
exports.useAssetRuntime = useAssetRuntime;
|
|
249
|
+
exports.useAssetSorting = useAssetSorting;
|
|
250
|
+
exports.useCurrentUser = useCurrentUser;
|
|
251
|
+
exports.useCustomFieldRuntime = useCustomFieldRuntime;
|
|
252
|
+
exports.useDeveloperSettings = useDeveloperSettings;
|
|
253
|
+
exports.useEnvironment = useEnvironment;
|
|
254
|
+
exports.useGlobalSelection = useGlobalSelection;
|
|
255
|
+
exports.useNavigationRuntime = useNavigationRuntime;
|
|
256
|
+
exports.useRestRuntime = useRestRuntime;
|
|
257
|
+
exports.useSiteRuntime = useSiteRuntime;
|
|
258
|
+
exports.useToast = useToast;
|
|
259
|
+
exports.useToken = useToken;
|
|
260
|
+
exports.useURLSynchronization = useURLSynchronization;
|
|
261
|
+
exports.useUserSubscription = useUserSubscription;
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-hooks",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33-alpha-0b53b6cf53.0",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"module": "./index.js",
|
|
7
|
-
"main": "./index.
|
|
7
|
+
"main": "./index.cjs",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"types": "./src/index.d.ts",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@trackunit/react-core-contexts-api": "0.2.
|
|
11
|
+
"@trackunit/react-core-contexts-api": "0.2.20-alpha-0b53b6cf53.0",
|
|
12
12
|
"react": "18.2.0",
|
|
13
|
-
"@trackunit/iris-app-runtime-core": "0.3.
|
|
13
|
+
"@trackunit/iris-app-runtime-core": "0.3.23-alpha-0b53b6cf53.0",
|
|
14
14
|
"react-router-dom": "6.4.5"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {}
|