@evoke-platform/context 1.7.0 → 1.8.0-dev.1

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.
@@ -52,9 +52,23 @@ export type AppExtended = App & {
52
52
  * @returns {Promise<string | undefined>} The default page slug, or `undefined` if no default page is found.
53
53
  */
54
54
  findDefaultPageSlugFor: (objectId: string) => Promise<string | undefined>;
55
+ /**
56
+ * `true` when the current browser reports network connectivity.
57
+ *
58
+ * Note: this is a browser signal (`navigator.onLine` + online/offline events), not a guarantee that APIs are reachable.
59
+ */
60
+ isOnline: boolean;
61
+ /**
62
+ * `true` when this device is trusted to store offline private data for the current app.
63
+ */
64
+ isTrustedDevice: boolean;
55
65
  };
56
66
  export type AppProviderProps = {
57
67
  app: App;
68
+ /**
69
+ * `true` when this device is trusted to store offline private data for the current app.
70
+ */
71
+ isTrustedDevice?: boolean;
58
72
  children?: ReactNode;
59
73
  };
60
74
  declare function AppProvider(props: AppProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
- import { createContext, useCallback, useContext } from 'react';
11
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
12
12
  import { useApiServices } from '../api/index.js';
13
13
  const defaultApp = {
14
14
  id: '_evoke',
@@ -16,45 +16,60 @@ const defaultApp = {
16
16
  type: 'public',
17
17
  offlineEnabled: false,
18
18
  };
19
- const defaultAppExtended = Object.assign(Object.assign({}, defaultApp), { findDefaultPageSlugFor: (objectId) => Promise.resolve(undefined) });
19
+ const defaultAppExtended = Object.assign(Object.assign({}, defaultApp), { findDefaultPageSlugFor: (objectId) => Promise.resolve(undefined), isOnline: typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true, isTrustedDevice: false });
20
20
  const AppContext = createContext(defaultAppExtended);
21
21
  AppContext.displayName = 'AppContext';
22
22
  function AppProvider(props) {
23
- const { app, children } = props;
23
+ const { app, children, isTrustedDevice } = props;
24
24
  const apiServices = useApiServices();
25
- const appExtended = Object.assign(Object.assign({}, app), { findDefaultPageSlugFor: useCallback((objectId) => __awaiter(this, void 0, void 0, function* () {
26
- var _a, _b, _c, _d;
27
- let defaultPageId;
28
- let currentObjectId = objectId;
29
- while (currentObjectId !== undefined) {
30
- if ((_a = app.defaultPages) === null || _a === void 0 ? void 0 : _a[currentObjectId]) {
31
- defaultPageId = app.defaultPages[currentObjectId];
32
- break;
33
- }
34
- const effectiveObject = yield apiServices.get(`data/objects/${currentObjectId}/effective`, {
35
- params: { filter: { fields: ['baseObject'] } },
36
- });
37
- currentObjectId = (_c = (_b = effectiveObject === null || effectiveObject === void 0 ? void 0 : effectiveObject.baseObject) === null || _b === void 0 ? void 0 : _b.objectId) !== null && _c !== void 0 ? _c : undefined;
25
+ const [isOnline, setIsOnline] = useState(() => typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true);
26
+ useEffect(() => {
27
+ if (typeof window === 'undefined')
28
+ return;
29
+ const onOnline = () => setIsOnline(true);
30
+ const onOffline = () => setIsOnline(false);
31
+ window.addEventListener('online', onOnline);
32
+ window.addEventListener('offline', onOffline);
33
+ return () => {
34
+ window.removeEventListener('online', onOnline);
35
+ window.removeEventListener('offline', onOffline);
36
+ };
37
+ }, []);
38
+ const findDefaultPageSlugFor = useCallback((objectId) => __awaiter(this, void 0, void 0, function* () {
39
+ var _a, _b, _c, _d;
40
+ let defaultPageId;
41
+ let currentObjectId = objectId;
42
+ while (currentObjectId !== undefined) {
43
+ if ((_a = app.defaultPages) === null || _a === void 0 ? void 0 : _a[currentObjectId]) {
44
+ defaultPageId = app.defaultPages[currentObjectId];
45
+ break;
38
46
  }
39
- let defaultPage;
40
- if (defaultPageId) {
41
- const pageId = defaultPageId.includes('/')
42
- ? defaultPageId.split('/').slice(2).join('/')
43
- : defaultPageId;
44
- try {
45
- defaultPage = yield apiServices.get(`/webContent/apps/${app.id}/pages/${encodeURIComponent(encodeURIComponent(pageId))}`);
46
- }
47
- catch (error) {
48
- const err = error;
49
- if (((_d = err.response) === null || _d === void 0 ? void 0 : _d.status) === 404) {
50
- defaultPage = undefined;
51
- }
52
- }
47
+ const effectiveObject = yield apiServices.get(`data/objects/${currentObjectId}/effective`, {
48
+ params: { filter: { fields: ['baseObject'] } },
49
+ });
50
+ currentObjectId = (_c = (_b = effectiveObject === null || effectiveObject === void 0 ? void 0 : effectiveObject.baseObject) === null || _b === void 0 ? void 0 : _b.objectId) !== null && _c !== void 0 ? _c : undefined;
51
+ }
52
+ let defaultPage;
53
+ if (defaultPageId) {
54
+ const pageId = defaultPageId.includes('/')
55
+ ? defaultPageId.split('/').slice(2).join('/')
56
+ : defaultPageId;
57
+ try {
58
+ defaultPage = yield apiServices.get(`/webContent/apps/${app.id}/pages/${encodeURIComponent(encodeURIComponent(pageId))}`);
53
59
  }
54
- if (defaultPage === null || defaultPage === void 0 ? void 0 : defaultPage.slug) {
55
- return `/${app.id}/${defaultPage.slug}`;
60
+ catch (error) {
61
+ const err = error;
62
+ if (((_d = err.response) === null || _d === void 0 ? void 0 : _d.status) === 404) {
63
+ defaultPage = undefined;
64
+ }
56
65
  }
57
- }), [app]) });
66
+ }
67
+ if (defaultPage === null || defaultPage === void 0 ? void 0 : defaultPage.slug) {
68
+ return `/${app.id}/${defaultPage.slug}`;
69
+ }
70
+ }), [apiServices, app]);
71
+ const appExtended = useMemo(() => (Object.assign(Object.assign({}, app), { findDefaultPageSlugFor,
72
+ isOnline, isTrustedDevice: Boolean(isTrustedDevice) })), [app, findDefaultPageSlugFor, isOnline, isTrustedDevice]);
58
73
  return _jsx(AppContext.Provider, { value: appExtended, children: children });
59
74
  }
60
75
  export function useApp() {
@@ -225,6 +225,11 @@ export type DisplayConfiguration = {
225
225
  * this specifies which object it relates to when the field entry is rendered.
226
226
  */
227
227
  relatedObjectId?: string;
228
+ /**
229
+ * The ID of the file object for parameters of type 'file'.
230
+ * This can be either the system File object or one of its subtypes.
231
+ */
232
+ fileObjectId?: string;
228
233
  visibility?: VisibilityConfiguration | JsonLogic;
229
234
  viewLayout?: ViewLayoutEntityReference;
230
235
  choicesDisplay?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/context",
3
- "version": "1.7.0",
3
+ "version": "1.8.0-dev.1",
4
4
  "description": "Utilities that provide context to Evoke platform widgets",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",