@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.
@@ -34660,12 +34660,15 @@ function createPicobotIframe(picobotOrigin, {
34660
34660
  setLoadedPath(iframePath || "");
34661
34661
  }, [iframePath]);
34662
34662
  // A one-way channel for sending messages to picobot. Topbar just
34663
- // forwards the envelope to the iframe and holds no message semantics of
34664
- // its own—the consumer decides what to send and when.
34663
+ // forwards the envelope to the iframe—the consumer decides what to send
34664
+ // and when. The one exception is PANE_VISIBLE: Safari ignores focus()
34665
+ // from inside a cross-origin iframe, so the host has to focus the iframe
34666
+ // before picobot can focus its composer.
34665
34667
  React__default.useImperativeHandle(ref, () => ({
34666
34668
  postMessage(message) {
34667
- var _a, _b;
34668
- (_b = (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage(message, picobotOrigin);
34669
+ var _a, _b, _c;
34670
+ if (message.type === "PANE_VISIBLE") (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.focus();
34671
+ (_c = (_b = iframeRef.current) === null || _b === void 0 ? void 0 : _b.contentWindow) === null || _c === void 0 ? void 0 : _c.postMessage(message, picobotOrigin);
34669
34672
  }
34670
34673
  }), []);
34671
34674
  const iframeSrc = buildPicobotSrc(picobotOrigin, loadedPath, {
@@ -35408,6 +35411,7 @@ function PicobotComponent({
35408
35411
  closeDrawer,
35409
35412
  currentPath,
35410
35413
  env,
35414
+ isOpen,
35411
35415
  onChangePath,
35412
35416
  openTool,
35413
35417
  pending
@@ -35452,6 +35456,17 @@ function PicobotComponent({
35452
35456
  }
35453
35457
  clearPending();
35454
35458
  }, [pending, isPicobotReady, clearPending]);
35459
+ // The drawer keeps the iframe mounted while it's closed, so picobot's
35460
+ // autofocus is spent by the time the panel reopens. READY gates the signal
35461
+ // because picobot has no listener before it.
35462
+ React__default.useEffect(function tellPicobotThePanelIsVisible() {
35463
+ var _a;
35464
+ if (isOpen && isPicobotReady) {
35465
+ (_a = picobotRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
35466
+ type: "PANE_VISIBLE"
35467
+ });
35468
+ }
35469
+ }, [isOpen, isPicobotReady]);
35455
35470
  const [iframeErrored, setIframeErrored] = React__default.useState(false);
35456
35471
  const [mountKey, setMountKey] = React__default.useState(0);
35457
35472
  const handleRetry = React__default.useCallback(() => {
@@ -35968,6 +35983,11 @@ const Profile = {
35968
35983
  };
35969
35984
 
35970
35985
  const DURATION = 100;
35986
+ const TOOLBAR_DRAWER_CHANGE_EVENT = "topbar:toolbar-drawer-change";
35987
+ const CLOSED_TOOLBAR_DRAWER = {
35988
+ open: false,
35989
+ tool: null
35990
+ };
35971
35991
  // Exempt paths match regardless of query, so `email?conversationId=…` is
35972
35992
  // exempt along with `email`.
35973
35993
  function isToolPathExemptFromStorage(toolName, path) {
@@ -36081,6 +36101,27 @@ function Toolbar({
36081
36101
  delete window.openHelpdesk; /* TODO: Remove when products have migrated to window.topbar.openHelpdesk */
36082
36102
  };
36083
36103
  }, [Profile, openHelpdeskAtRoot]);
36104
+ const toolbarDrawerTool = open && currentContent ? currentContent.name.toLowerCase() : null;
36105
+ const lastToolbarDrawer = React__default.useRef(CLOSED_TOOLBAR_DRAWER);
36106
+ React__default.useEffect(() => {
36107
+ const toolbarDrawer = {
36108
+ open,
36109
+ tool: toolbarDrawerTool
36110
+ };
36111
+ window.topbar = window.topbar || {};
36112
+ window.topbar.toolbarDrawer = toolbarDrawer;
36113
+ const last = lastToolbarDrawer.current;
36114
+ if (last.open !== toolbarDrawer.open || last.tool !== toolbarDrawer.tool) {
36115
+ lastToolbarDrawer.current = toolbarDrawer;
36116
+ window.dispatchEvent(new CustomEvent(TOOLBAR_DRAWER_CHANGE_EVENT, {
36117
+ detail: toolbarDrawer
36118
+ }));
36119
+ }
36120
+ return () => {
36121
+ var _a;
36122
+ (_a = window.topbar) === null || _a === void 0 ? true : delete _a.toolbarDrawer;
36123
+ };
36124
+ }, [open, toolbarDrawerTool]);
36084
36125
  const loginSettingsUrl = getLoginProfilePath({
36085
36126
  appName: appName.replace(/[\s-]/, ""),
36086
36127
  env: env,