@homebound/beam 2.299.0 → 2.300.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.
@@ -0,0 +1,24 @@
1
+ import React, { PropsWithChildren } from "react";
2
+ export declare enum AutoSaveStatus {
3
+ IDLE = "idle",
4
+ SAVING = "saving",
5
+ DONE = "done",
6
+ ERROR = "error"
7
+ }
8
+ export interface AutoSaveStatusContextType {
9
+ status: AutoSaveStatus;
10
+ /** Resets status to IDLE, particularly useful if "Error" or "Done" is stale */
11
+ resetStatus: VoidFunction;
12
+ errors: unknown[];
13
+ /** Notifies AutoSaveContext that a request is in-flight */
14
+ triggerAutoSave: VoidFunction;
15
+ /** Notifies AutoSaveContext that a request has settled, optionally taking an error */
16
+ resolveAutoSave: (error?: unknown) => void;
17
+ }
18
+ export declare const AutoSaveStatusContext: React.Context<AutoSaveStatusContextType>;
19
+ type AutoSaveStatusProviderProps = PropsWithChildren<{
20
+ /** After a successful save, reset Status back to `Idle` after this many milliseconds */
21
+ resetToIdleTimeout?: number;
22
+ }>;
23
+ export declare function AutoSaveStatusProvider({ children, resetToIdleTimeout }: AutoSaveStatusProviderProps): import("@emotion/react/jsx-runtime").JSX.Element;
24
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AutoSaveStatusProvider = exports.AutoSaveStatusContext = exports.AutoSaveStatus = void 0;
27
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
28
+ const react_1 = __importStar(require("react"));
29
+ var AutoSaveStatus;
30
+ (function (AutoSaveStatus) {
31
+ AutoSaveStatus["IDLE"] = "idle";
32
+ AutoSaveStatus["SAVING"] = "saving";
33
+ AutoSaveStatus["DONE"] = "done";
34
+ AutoSaveStatus["ERROR"] = "error";
35
+ })(AutoSaveStatus = exports.AutoSaveStatus || (exports.AutoSaveStatus = {}));
36
+ exports.AutoSaveStatusContext = react_1.default.createContext({
37
+ status: AutoSaveStatus.IDLE,
38
+ resetStatus() { },
39
+ errors: [],
40
+ triggerAutoSave() { },
41
+ resolveAutoSave() { },
42
+ });
43
+ function AutoSaveStatusProvider({ children, resetToIdleTimeout = 6000 }) {
44
+ const [status, setStatus] = (0, react_1.useState)(AutoSaveStatus.IDLE);
45
+ const [errors, setErrors] = (0, react_1.useState)([]);
46
+ const [inFlight, setInFlight] = (0, react_1.useState)(0);
47
+ const resetToIdleTimeoutRef = (0, react_1.useRef)(null);
48
+ /** Handles setting Status */
49
+ (0, react_1.useEffect)(() => {
50
+ if (inFlight > 0)
51
+ return setStatus(AutoSaveStatus.SAVING);
52
+ if (status === AutoSaveStatus.IDLE)
53
+ return;
54
+ if (errors.length)
55
+ return setStatus(AutoSaveStatus.ERROR);
56
+ return setStatus(AutoSaveStatus.DONE);
57
+ }, [errors.length, inFlight, status]);
58
+ const triggerAutoSave = (0, react_1.useCallback)(() => {
59
+ setInFlight((c) => c + 1);
60
+ setErrors([]);
61
+ }, []);
62
+ const resolveAutoSave = (0, react_1.useCallback)((error) => {
63
+ setInFlight((c) => Math.max(0, c - 1));
64
+ if (error)
65
+ setErrors((errs) => errs.concat(error));
66
+ }, []);
67
+ const resetStatus = (0, react_1.useCallback)(() => {
68
+ setStatus(AutoSaveStatus.IDLE);
69
+ setErrors([]);
70
+ }, []);
71
+ /** Resets AutoSaveStatus from "Done" to "Idle" after a timeout, if one is provided */
72
+ (0, react_1.useEffect)(() => {
73
+ if (resetToIdleTimeout === undefined)
74
+ return;
75
+ // Specifically avoid auto-reset if Errors are present
76
+ if (status !== AutoSaveStatus.DONE)
77
+ return;
78
+ // Only run the latest Timeout
79
+ if (resetToIdleTimeoutRef.current)
80
+ clearTimeout(resetToIdleTimeoutRef.current);
81
+ resetToIdleTimeoutRef.current = window.setTimeout(() => {
82
+ resetStatus();
83
+ resetToIdleTimeoutRef.current = null;
84
+ }, resetToIdleTimeout);
85
+ }, [resetStatus, resetToIdleTimeout, status]);
86
+ const value = (0, react_1.useMemo)(() => ({ status, resetStatus, errors, triggerAutoSave, resolveAutoSave }), [errors, resetStatus, resolveAutoSave, status, triggerAutoSave]);
87
+ return (0, jsx_runtime_1.jsx)(exports.AutoSaveStatusContext.Provider, { value: value, children: children });
88
+ }
89
+ exports.AutoSaveStatusProvider = AutoSaveStatusProvider;
@@ -0,0 +1,2 @@
1
+ export { AutoSaveStatus, AutoSaveStatusContext, AutoSaveStatusProvider } from "./AutoSaveStatusProvider";
2
+ export { useAutoSaveStatus } from "./useAutoSaveStatus";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAutoSaveStatus = exports.AutoSaveStatusProvider = exports.AutoSaveStatusContext = exports.AutoSaveStatus = void 0;
4
+ var AutoSaveStatusProvider_1 = require("./AutoSaveStatusProvider");
5
+ Object.defineProperty(exports, "AutoSaveStatus", { enumerable: true, get: function () { return AutoSaveStatusProvider_1.AutoSaveStatus; } });
6
+ Object.defineProperty(exports, "AutoSaveStatusContext", { enumerable: true, get: function () { return AutoSaveStatusProvider_1.AutoSaveStatusContext; } });
7
+ Object.defineProperty(exports, "AutoSaveStatusProvider", { enumerable: true, get: function () { return AutoSaveStatusProvider_1.AutoSaveStatusProvider; } });
8
+ var useAutoSaveStatus_1 = require("./useAutoSaveStatus");
9
+ Object.defineProperty(exports, "useAutoSaveStatus", { enumerable: true, get: function () { return useAutoSaveStatus_1.useAutoSaveStatus; } });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Provides access to the current auto-save status, i.e. idle/saving/done.
3
+ *
4
+ * Applications should generally instrument their network layer, i.e. GraphQL
5
+ * mutations, to automatically update the auto-save status on any wire call,
6
+ * and then just use this `useAutoSaveStatus` to "show spinners" in appropriate
7
+ * places.
8
+ *
9
+ * See the `apolloHooks.ts` file in `internal-frontend` for an example.
10
+ */
11
+ export declare function useAutoSaveStatus(): import("./AutoSaveStatusProvider").AutoSaveStatusContextType;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAutoSaveStatus = void 0;
4
+ const react_1 = require("react");
5
+ const AutoSaveStatusProvider_1 = require("./AutoSaveStatusProvider");
6
+ /**
7
+ * Provides access to the current auto-save status, i.e. idle/saving/done.
8
+ *
9
+ * Applications should generally instrument their network layer, i.e. GraphQL
10
+ * mutations, to automatically update the auto-save status on any wire call,
11
+ * and then just use this `useAutoSaveStatus` to "show spinners" in appropriate
12
+ * places.
13
+ *
14
+ * See the `apolloHooks.ts` file in `internal-frontend` for an example.
15
+ */
16
+ function useAutoSaveStatus() {
17
+ return (0, react_1.useContext)(AutoSaveStatusProvider_1.AutoSaveStatusContext);
18
+ }
19
+ exports.useAutoSaveStatus = useAutoSaveStatus;
@@ -2,26 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useBeamContext = exports.BeamProvider = exports.BeamContext = void 0;
4
4
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
- const form_state_1 = require("@homebound/form-state");
6
5
  const react_1 = require("react");
7
6
  const react_aria_1 = require("react-aria");
7
+ const index_1 = require("./AutoSaveStatus/index");
8
8
  const Modal_1 = require("./Modal/Modal");
9
9
  const PresentationContext_1 = require("./PresentationContext");
10
10
  const SnackbarContext_1 = require("./Snackbar/SnackbarContext");
11
11
  const SuperDrawer_1 = require("./SuperDrawer/SuperDrawer");
12
- const index_1 = require("../utils/index");
12
+ const index_2 = require("../utils/index");
13
13
  const Layout_1 = require("./Layout");
14
14
  const ToastContext_1 = require("./Toast/ToastContext");
15
15
  /** This is only exported internally, for useModal and useSuperDrawer, it's not a public API. */
16
16
  exports.BeamContext = (0, react_1.createContext)({
17
- modalState: new index_1.EmptyRef(),
18
- modalCanCloseChecks: new index_1.EmptyRef(),
17
+ modalState: new index_2.EmptyRef(),
18
+ modalCanCloseChecks: new index_2.EmptyRef(),
19
19
  modalHeaderDiv: undefined,
20
20
  modalBodyDiv: undefined,
21
21
  modalFooterDiv: undefined,
22
- drawerContentStack: new index_1.EmptyRef(),
23
- drawerCanCloseChecks: new index_1.EmptyRef(),
24
- drawerCanCloseDetailsChecks: new index_1.EmptyRef(),
22
+ drawerContentStack: new index_2.EmptyRef(),
23
+ drawerCanCloseChecks: new index_2.EmptyRef(),
24
+ drawerCanCloseDetailsChecks: new index_2.EmptyRef(),
25
25
  sdHeaderDiv: undefined,
26
26
  });
27
27
  function BeamProvider({ children, ...presentationProps }) {
@@ -61,7 +61,7 @@ function BeamProvider({ children, ...presentationProps }) {
61
61
  sdHeaderDiv,
62
62
  };
63
63
  }, [modalBodyDiv, modalFooterDiv]);
64
- return ((0, jsx_runtime_1.jsx)(exports.BeamContext.Provider, { value: { ...context }, children: (0, jsx_runtime_1.jsx)(PresentationContext_1.PresentationProvider, { ...presentationProps, children: (0, jsx_runtime_1.jsx)(Layout_1.RightPaneProvider, { children: (0, jsx_runtime_1.jsx)(form_state_1.AutoSaveStatusProvider, { children: (0, jsx_runtime_1.jsx)(SnackbarContext_1.SnackbarProvider, { children: (0, jsx_runtime_1.jsxs)(ToastContext_1.ToastProvider, { children: [(0, jsx_runtime_1.jsxs)(react_aria_1.OverlayProvider, { children: [children, modalRef.current && (0, jsx_runtime_1.jsx)(Modal_1.Modal, { ...modalRef.current })] }), (0, jsx_runtime_1.jsx)(SuperDrawer_1.SuperDrawer, {})] }) }) }) }) }) }));
64
+ return ((0, jsx_runtime_1.jsx)(exports.BeamContext.Provider, { value: { ...context }, children: (0, jsx_runtime_1.jsx)(PresentationContext_1.PresentationProvider, { ...presentationProps, children: (0, jsx_runtime_1.jsx)(Layout_1.RightPaneProvider, { children: (0, jsx_runtime_1.jsx)(index_1.AutoSaveStatusProvider, { children: (0, jsx_runtime_1.jsx)(SnackbarContext_1.SnackbarProvider, { children: (0, jsx_runtime_1.jsxs)(ToastContext_1.ToastProvider, { children: [(0, jsx_runtime_1.jsxs)(react_aria_1.OverlayProvider, { children: [children, modalRef.current && (0, jsx_runtime_1.jsx)(Modal_1.Modal, { ...modalRef.current })] }), (0, jsx_runtime_1.jsx)(SuperDrawer_1.SuperDrawer, {})] }) }) }) }) }) }));
65
65
  }
66
66
  exports.BeamProvider = BeamProvider;
67
67
  /** Looks like a ref, but invokes a re-render on set (w/o changing the setter identity). */
@@ -1,3 +1,4 @@
1
+ export * from "./AutoSaveStatus";
1
2
  export * from "./Chip";
2
3
  export * from "./Chips";
3
4
  export * from "./Table/GridTable";
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.useToast = exports.TabsWithContent = exports.Tabs = exports.TabContent = exports.PresentationProvider = exports.NavLink = exports.HB_QUIPS_MISSION = exports.HB_QUIPS_FLAVOR = exports.HbSpinnerProvider = exports.HbLoadingSpinner = exports.BeamProvider = void 0;
18
+ __exportStar(require("./AutoSaveStatus"), exports);
18
19
  __exportStar(require("./Chip"), exports);
19
20
  __exportStar(require("./Chips"), exports);
20
21
  __exportStar(require("./Table/GridTable"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.299.0",
3
+ "version": "2.300.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",