@planningcenter/topbar 12.4.0-rc.2 → 12.4.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.
@@ -34670,12 +34670,15 @@ true;
34670
34670
  setLoadedPath(iframePath || "");
34671
34671
  }, [iframePath]);
34672
34672
  // A one-way channel for sending messages to picobot. Topbar just
34673
- // forwards the envelope to the iframe and holds no message semantics of
34674
- // its own—the consumer decides what to send and when.
34673
+ // forwards the envelope to the iframe—the consumer decides what to send
34674
+ // and when. The one exception is PANE_VISIBLE: Safari ignores focus()
34675
+ // from inside a cross-origin iframe, so the host has to focus the iframe
34676
+ // before picobot can focus its composer.
34675
34677
  React.useImperativeHandle(ref, () => ({
34676
34678
  postMessage(message) {
34677
- var _a, _b;
34678
- (_b = (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(message, picobotOrigin);
34679
+ var _a, _b, _c;
34680
+ if (message.type === "PANE_VISIBLE") (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.focus();
34681
+ (_c = (_b = iframeRef.current) === null || _b === void 0 ? void 0 : _b.contentWindow) === null || _c === void 0 ? void 0 : _c.postMessage(message, picobotOrigin);
34679
34682
  }
34680
34683
  }), []);
34681
34684
  const iframeSrc = buildPicobotSrc(picobotOrigin, loadedPath, {
@@ -35418,6 +35421,7 @@ true;
35418
35421
  closeDrawer,
35419
35422
  currentPath,
35420
35423
  env,
35424
+ isOpen,
35421
35425
  onChangePath,
35422
35426
  openTool,
35423
35427
  pending
@@ -35462,6 +35466,17 @@ true;
35462
35466
  }
35463
35467
  clearPending();
35464
35468
  }, [pending, isPicobotReady, clearPending]);
35469
+ // The drawer keeps the iframe mounted while it's closed, so picobot's
35470
+ // autofocus is spent by the time the panel reopens. READY gates the signal
35471
+ // because picobot has no listener before it.
35472
+ React.useEffect(function tellPicobotThePanelIsVisible() {
35473
+ var _a;
35474
+ if (isOpen && isPicobotReady) {
35475
+ (_a = picobotRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
35476
+ type: "PANE_VISIBLE"
35477
+ });
35478
+ }
35479
+ }, [isOpen, isPicobotReady]);
35465
35480
  const [iframeErrored, setIframeErrored] = React.useState(false);
35466
35481
  const [mountKey, setMountKey] = React.useState(0);
35467
35482
  const handleRetry = React.useCallback(() => {
@@ -35978,6 +35993,11 @@ true;
35978
35993
  };
35979
35994
 
35980
35995
  const DURATION = 100;
35996
+ const TOOLBAR_DRAWER_CHANGE_EVENT = "topbar:toolbar-drawer-change";
35997
+ const CLOSED_TOOLBAR_DRAWER = {
35998
+ open: false,
35999
+ tool: null
36000
+ };
35981
36001
  // Exempt paths match regardless of query, so `email?conversationId=…` is
35982
36002
  // exempt along with `email`.
35983
36003
  function isToolPathExemptFromStorage(toolName, path) {
@@ -36091,6 +36111,27 @@ true;
36091
36111
  delete window.openHelpdesk; /* TODO: Remove when products have migrated to window.topbar.openHelpdesk */
36092
36112
  };
36093
36113
  }, [Profile, openHelpdeskAtRoot]);
36114
+ const toolbarDrawerTool = open && currentContent ? currentContent.name.toLowerCase() : null;
36115
+ const lastToolbarDrawer = React.useRef(CLOSED_TOOLBAR_DRAWER);
36116
+ React.useEffect(() => {
36117
+ const toolbarDrawer = {
36118
+ open,
36119
+ tool: toolbarDrawerTool
36120
+ };
36121
+ window.topbar = window.topbar || {};
36122
+ window.topbar.toolbarDrawer = toolbarDrawer;
36123
+ const last = lastToolbarDrawer.current;
36124
+ if (last.open !== toolbarDrawer.open || last.tool !== toolbarDrawer.tool) {
36125
+ lastToolbarDrawer.current = toolbarDrawer;
36126
+ window.dispatchEvent(new CustomEvent(TOOLBAR_DRAWER_CHANGE_EVENT, {
36127
+ detail: toolbarDrawer
36128
+ }));
36129
+ }
36130
+ return () => {
36131
+ var _a;
36132
+ (_a = window.topbar) === null || _a === void 0 ? true : delete _a.toolbarDrawer;
36133
+ };
36134
+ }, [open, toolbarDrawerTool]);
36094
36135
  const loginSettingsUrl = getLoginProfilePath({
36095
36136
  appName: appName.replace(/[\s-]/, ""),
36096
36137
  env: env,