@homebound/beam 3.70.0 → 3.72.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/dist/index.cjs CHANGED
@@ -26936,7 +26936,7 @@ function PageHeaderLayout(props) {
26936
26936
  }
26937
26937
 
26938
26938
  // src/layouts/WorkflowLayout/WorkflowLayout.tsx
26939
- var import_react155 = require("react");
26939
+ var import_react156 = require("react");
26940
26940
 
26941
26941
  // src/components/Headers/WorkflowHeader.tsx
26942
26942
  var import_jsx_runtime215 = require("react/jsx-runtime");
@@ -26946,16 +26946,67 @@ function WorkflowHeader(props) {
26946
26946
  return /* @__PURE__ */ (0, import_jsx_runtime215.jsx)(BaseHeader, { ...otherProps, bottomSlot: /* @__PURE__ */ (0, import_jsx_runtime215.jsx)(StepperTabs, { ...stepperTabs, ...tid.stepperTabs }) });
26947
26947
  }
26948
26948
 
26949
- // src/layouts/WorkflowLayout/useUnsavedChangesGuard.tsx
26949
+ // src/layouts/useScrollCollapse.ts
26950
26950
  var import_react154 = require("react");
26951
+ function useScrollCollapse(enabled, restingOffset) {
26952
+ const [collapsed, setCollapsed] = (0, import_react154.useState)(() => typeof window !== "undefined" && window.scrollY > 0);
26953
+ const collapsedRef = (0, import_react154.useRef)(collapsed);
26954
+ collapsedRef.current = collapsed;
26955
+ const restingOffsetRef = (0, import_react154.useRef)(restingOffset);
26956
+ restingOffsetRef.current = restingOffset;
26957
+ const lastScrollYRef = (0, import_react154.useRef)(Number.POSITIVE_INFINITY);
26958
+ const lastScrollHeightRef = (0, import_react154.useRef)(0);
26959
+ (0, import_react154.useLayoutEffect)(() => {
26960
+ lastScrollHeightRef.current = document.documentElement.scrollHeight;
26961
+ }, [restingOffset]);
26962
+ (0, import_react154.useLayoutEffect)(() => {
26963
+ if (!enabled) return;
26964
+ const commit = (next) => {
26965
+ if (next !== collapsedRef.current) {
26966
+ collapsedRef.current = next;
26967
+ setCollapsed(next);
26968
+ }
26969
+ };
26970
+ const updateCollapsed = () => {
26971
+ const doc = document.documentElement;
26972
+ const currentY = window.scrollY;
26973
+ if (currentY <= 0) {
26974
+ lastScrollYRef.current = 0;
26975
+ lastScrollHeightRef.current = doc.scrollHeight;
26976
+ commit(false);
26977
+ return;
26978
+ }
26979
+ const currentScrollHeight = doc.scrollHeight;
26980
+ const scrollHeightChanged = lastScrollHeightRef.current !== 0 && currentScrollHeight !== lastScrollHeightRef.current;
26981
+ const dy = currentY - lastScrollYRef.current;
26982
+ lastScrollYRef.current = currentY;
26983
+ lastScrollHeightRef.current = currentScrollHeight;
26984
+ if (currentY <= restingOffsetRef.current) return;
26985
+ if (scrollHeightChanged) {
26986
+ commit(true);
26987
+ return;
26988
+ }
26989
+ const atBottom = currentY >= doc.scrollHeight - doc.clientHeight;
26990
+ if (dy > 0) commit(true);
26991
+ else if (dy < 0 && !atBottom) commit(false);
26992
+ };
26993
+ updateCollapsed();
26994
+ window.addEventListener("scroll", updateCollapsed, { passive: true });
26995
+ return () => window.removeEventListener("scroll", updateCollapsed);
26996
+ }, [enabled]);
26997
+ return collapsed;
26998
+ }
26999
+
27000
+ // src/layouts/WorkflowLayout/useUnsavedChangesGuard.tsx
27001
+ var import_react155 = require("react");
26951
27002
  var import_react_router_dom9 = require("react-router-dom");
26952
27003
  var import_jsx_runtime216 = require("react/jsx-runtime");
26953
27004
  function useUnsavedChangesGuard(options) {
26954
27005
  const { isDirty, onCancel } = options;
26955
27006
  const { openModal } = useModal();
26956
- const isDirtyRef = (0, import_react154.useRef)(isDirty);
27007
+ const isDirtyRef = (0, import_react155.useRef)(isDirty);
26957
27008
  isDirtyRef.current = isDirty;
26958
- (0, import_react154.useEffect)(() => {
27009
+ (0, import_react155.useEffect)(() => {
26959
27010
  const onBeforeUnload = (e) => {
26960
27011
  if (isDirtyRef.current?.()) {
26961
27012
  e.preventDefault();
@@ -26981,7 +27032,7 @@ function useUnsavedChangesGuard(options) {
26981
27032
  function UnsavedChangesNavigationModal(props) {
26982
27033
  const { proceed, cancelNavigation } = props;
26983
27034
  const { openModal, closeModal } = useModal();
26984
- (0, import_react154.useEffect)(() => {
27035
+ (0, import_react155.useEffect)(() => {
26985
27036
  openModal({
26986
27037
  allowClosing: false,
26987
27038
  content: /* @__PURE__ */ (0, import_jsx_runtime216.jsx)(ConfirmCloseModal, { title: "Leave page?", onClose: proceed, onContinue: cancelNavigation })
@@ -27037,7 +27088,7 @@ function WorkflowLayout(props) {
27037
27088
  ...step,
27038
27089
  value: defaultTestId(step.label)
27039
27090
  }));
27040
- const [currentStep, setCurrentStep] = (0, import_react155.useState)(() => getInitialStep(tabSteps, defaultStep));
27091
+ const [currentStep, setCurrentStep] = (0, import_react156.useState)(() => getInitialStep(tabSteps, defaultStep));
27041
27092
  const tid = useTestIds(props, "workflowLayout");
27042
27093
  const {
27043
27094
  sm: isMobile
@@ -27049,9 +27100,11 @@ function WorkflowLayout(props) {
27049
27100
  isDirty,
27050
27101
  onCancel
27051
27102
  });
27052
- const headerMetricsRef = (0, import_react155.useRef)(null);
27103
+ const bannerAndNavbarHeight = useBannerAndNavbarHeight();
27104
+ const headerMetricsRef = (0, import_react156.useRef)(null);
27053
27105
  const headerHeight = useMeasuredHeight(headerMetricsRef, true);
27054
- const collapsed = isMobile;
27106
+ const scrollCollapsed = useScrollCollapse(!isMobile, bannerAndNavbarHeight + headerHeight);
27107
+ const collapsed = isMobile || scrollCollapsed;
27055
27108
  const headerWidth = documentScrollChromeWidth();
27056
27109
  const outerTop = bannerAndNavbarChromeTop();
27057
27110
  const cssVars = headerHeight > 0 ? {
@@ -27061,9 +27114,16 @@ function WorkflowLayout(props) {
27061
27114
  const isFirstStep = currentIndex <= 0;
27062
27115
  const isLastStep = currentIndex === tabSteps.length - 1;
27063
27116
  const activeStep = tabSteps[currentIndex];
27064
- const buttons = /* @__PURE__ */ (0, import_jsx_runtime218.jsx)(WorkflowActions, { isFirstStep, isLastStep, isMobile, onBack: () => setCurrentStep(tabSteps[currentIndex - 1].value), onCancel: onCancelClick, onSaveAndExit, completeLabel, onComplete, primaryDisabled: !activeStep?.completed, onContinue: () => setCurrentStep(tabSteps[currentIndex + 1].value) });
27117
+ const buttons = /* @__PURE__ */ (0, import_jsx_runtime218.jsx)(WorkflowActions, { isFirstStep, isLastStep, isMobile, onBack: () => setCurrentStep(tabSteps[currentIndex - 1].value), onCancel: onCancelClick, onSaveAndExit, completeLabel, onComplete, primaryDisabled: !activeStep?.completed, onContinue: async () => {
27118
+ const onContinue = activeStep?.onContinue;
27119
+ if (onContinue) {
27120
+ const allowed = await onContinue();
27121
+ if (allowed === false) return;
27122
+ }
27123
+ setCurrentStep(tabSteps[currentIndex + 1].value);
27124
+ } });
27065
27125
  const showFooter = isMobile;
27066
- (0, import_react155.useLayoutEffect)(() => {
27126
+ (0, import_react156.useLayoutEffect)(() => {
27067
27127
  const root = document.documentElement;
27068
27128
  const previous = root.style.getPropertyValue(beamWorkflowLayoutFooterHeightVar);
27069
27129
  root.style.setProperty(beamWorkflowLayoutFooterHeightVar, showFooter ? `${mobileFooterHeightPx}px` : "0px");