@planningcenter/topbar 12.7.0-rc.0 → 12.7.0-rc.2

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.
@@ -1,6 +1,6 @@
1
1
  import { Link, Button, Popover, PopoverTrigger, PopoverContent, ButtonGroup, Dropdown, DropdownTrigger, DropdownIconButton, DropdownMenu, DropdownLink, Flex, Select, IconButton, Modal } from '@planningcenter/tapestry';
2
2
  import * as React from 'react';
3
- import React__default, { useState, useEffect, useMemo, useLayoutEffect, useContext, createContext, useCallback, useRef } from 'react';
3
+ import React__default, { useEffect, useState, useMemo, useLayoutEffect, useContext, createContext, useCallback, useRef } from 'react';
4
4
  import pcoUrl$1, { pcoUrl as pcoUrl$2, pcoApiUrl } from '@planningcenter/url';
5
5
  import * as general from '@planningcenter/icons/paths/general';
6
6
  import Jolt from '@planningcenter/jolt-client';
@@ -8216,6 +8216,291 @@ const DeveloperTools = {
8216
8216
  name: "DeveloperTools"
8217
8217
  };
8218
8218
 
8219
+ const DEFAULT_READY_TIMEOUT_MS = 8000;
8220
+ // The route rides in the fragment (`/topbar/helpdesk#email`), not the path, so
8221
+ // changing it is a same-document navigation that doesn't reload the iframe.
8222
+ function buildToolIframeSrc(origin, basePath, route, params = {}) {
8223
+ const [rawPath, queryPart] = route.replace(/^\/+/, "").split("?", 2);
8224
+ const safePath = rawPath.split("/").filter(segment => segment && segment !== "." && segment !== "..").join("/");
8225
+ const fragment = queryPart !== undefined ? `${safePath}?${queryPart}` : safePath;
8226
+ const url = new URL(basePath, origin);
8227
+ for (const [key, value] of Object.entries(params)) {
8228
+ if (value) url.searchParams.set(key, value);
8229
+ }
8230
+ // Always end in `#`, even for an empty route: going from `…#tasks/new` to a
8231
+ // URL with no fragment at all is a new document, which reloads the iframe.
8232
+ return `${url.toString()}#${fragment}`;
8233
+ }
8234
+ /**
8235
+ * An iframe for a toolbar tool served by another app. Shared by every tool
8236
+ * that has moved off add-ons: the page reports READY once it has painted,
8237
+ * NEW_ROUTE_RENDERED when its route changes, and anything else is handed to
8238
+ * `onMessage`. Messages from any other origin or window are ignored.
8239
+ */
8240
+ const ToolIframe = /*#__PURE__*/React__default.forwardRef(function ToolIframe({
8241
+ basePath,
8242
+ currentPath,
8243
+ isVisible = true,
8244
+ onChangePath,
8245
+ onMessage,
8246
+ origin,
8247
+ params,
8248
+ readyTimeoutMs = DEFAULT_READY_TIMEOUT_MS,
8249
+ title
8250
+ }, ref) {
8251
+ const iframeRef = React__default.useRef(null);
8252
+ const [loadedPath, setLoadedPath] = React__default.useState(currentPath || "");
8253
+ // Hidden until the page paints, so its blank first frame doesn't flash
8254
+ // white against the drawer in dark mode.
8255
+ const [isReady, setIsReady] = React__default.useState(false);
8256
+ const hasReportedErrorRef = React__default.useRef(false);
8257
+ const readyTimeoutRef = React__default.useRef();
8258
+ const onMessageRef = React__default.useRef(onMessage);
8259
+ onMessageRef.current = onMessage;
8260
+ const onChangePathRef = React__default.useRef(onChangePath);
8261
+ onChangePathRef.current = onChangePath;
8262
+ // Query params are read once at load: changing them would reload the
8263
+ // page. Context that changes later goes over HOST_CONTEXT_CHANGED.
8264
+ const [initialParams] = React__default.useState(params);
8265
+ React__default.useEffect(function reportLoadErrorIfNeverReady() {
8266
+ const timeout = setTimeout(() => {
8267
+ var _a;
8268
+ if (hasReportedErrorRef.current) return;
8269
+ hasReportedErrorRef.current = true;
8270
+ (_a = onMessageRef.current) === null || _a === void 0 ? void 0 : _a.call(onMessageRef, {
8271
+ type: "IFRAME_LOAD_ERROR"
8272
+ });
8273
+ }, readyTimeoutMs);
8274
+ readyTimeoutRef.current = timeout;
8275
+ return () => clearTimeout(timeout);
8276
+ }, [readyTimeoutMs]);
8277
+ React__default.useEffect(function subscribeToGuestMessages() {
8278
+ function handleGuestMessage(e) {
8279
+ var _a, _b, _c, _d;
8280
+ if (e.origin !== origin) return;
8281
+ if (!e.source || !iframeRef.current) return;
8282
+ if (e.source !== iframeRef.current.contentWindow) return;
8283
+ if (typeof ((_a = e.data) === null || _a === void 0 ? void 0 : _a.type) !== "string") return;
8284
+ const message = e.data;
8285
+ if (message.type === "READY") {
8286
+ clearTimeout(readyTimeoutRef.current);
8287
+ setIsReady(true);
8288
+ }
8289
+ if (message.type === "NEW_ROUTE_RENDERED") {
8290
+ const reportedPath = String((_b = message.payload) !== null && _b !== void 0 ? _b : "");
8291
+ setLoadedPath(reportedPath);
8292
+ (_c = onChangePathRef.current) === null || _c === void 0 ? void 0 : _c.call(onChangePathRef, reportedPath);
8293
+ }
8294
+ (_d = onMessageRef.current) === null || _d === void 0 ? void 0 : _d.call(onMessageRef, message);
8295
+ }
8296
+ window.addEventListener("message", handleGuestMessage);
8297
+ return () => window.removeEventListener("message", handleGuestMessage);
8298
+ }, [origin]);
8299
+ React__default.useEffect(function followRouteChangesFromTopbar() {
8300
+ setLoadedPath(currentPath || "");
8301
+ }, [currentPath]);
8302
+ React__default.useImperativeHandle(ref, () => ({
8303
+ postMessage(message) {
8304
+ var _a, _b, _c;
8305
+ // Safari ignores focus() from inside a cross-origin iframe, so the
8306
+ // host focuses the iframe before the page focuses its own input.
8307
+ if (message.type === "PANE_VISIBLE") (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.focus();
8308
+ (_c = (_b = iframeRef.current) === null || _b === void 0 ? void 0 : _b.contentWindow) === null || _c === void 0 ? void 0 : _c.postMessage(message, origin);
8309
+ }
8310
+ }), [origin]);
8311
+ return /*#__PURE__*/React__default.createElement("iframe", {
8312
+ ref: iframeRef,
8313
+ src: buildToolIframeSrc(origin, basePath, loadedPath, initialParams),
8314
+ allow: "clipboard-write",
8315
+ style: {
8316
+ border: 0,
8317
+ display: isVisible ? undefined : "none",
8318
+ flex: 1,
8319
+ height: "100%",
8320
+ visibility: isReady ? undefined : "hidden",
8321
+ width: "100%"
8322
+ },
8323
+ title: title
8324
+ });
8325
+ });
8326
+
8327
+ function hostContext(appName, pcoMeta) {
8328
+ return {
8329
+ appName,
8330
+ host: window.location.host,
8331
+ pathname: window.location.pathname,
8332
+ pcoMeta,
8333
+ search: window.location.search
8334
+ };
8335
+ }
8336
+ function trackPendo(payload) {
8337
+ const {
8338
+ event,
8339
+ properties = {}
8340
+ } = payload !== null && payload !== void 0 ? payload : {};
8341
+ if (!event) return;
8342
+ if (!(window === null || window === void 0 ? void 0 : window.pendo)) return console.warn("`window.pendo` is undefined");
8343
+ window.pendo.track(event, properties);
8344
+ }
8345
+ /**
8346
+ * A toolbar tool whose drawer is a page served by another app in an iframe.
8347
+ * Topbar only relays: the page decides what it shows and when it's ready.
8348
+ *
8349
+ * Page → topbar: READY, NEW_ROUTE_RENDERED, CLOSE_DRAWER, OPEN_DRAWER,
8350
+ * OPEN_TOOL { tool, path }, OPEN_PICOBOT { conversationId?, draft?,
8351
+ * ticketExternalId? }, TRACK_PENDO { event, properties }.
8352
+ *
8353
+ * Topbar → page: PANE_VISIBLE, PANE_HIDDEN, HOST_CONTEXT_CHANGED { appName,
8354
+ * host, pathname, pcoMeta, search }, TOOL_STATE_CHANGED { ...config.state }.
8355
+ */
8356
+ function IframeTool({
8357
+ appName,
8358
+ closeDrawer,
8359
+ config,
8360
+ currentPath,
8361
+ env,
8362
+ isOpen,
8363
+ onChangePath,
8364
+ openDrawer,
8365
+ openPicobot,
8366
+ openTool
8367
+ }) {
8368
+ const pcoMeta = usePcoMeta();
8369
+ const origin = React__default.useMemo(() => pcoUrl(env)(config.app), [env, config.app]);
8370
+ const iframeRef = React__default.useRef(null);
8371
+ const [isReady, setIsReady] = React__default.useState(false);
8372
+ const [errored, setErrored] = React__default.useState(false);
8373
+ const [mountKey, setMountKey] = React__default.useState(0);
8374
+ const [params] = React__default.useState(() => {
8375
+ const {
8376
+ host,
8377
+ pathname,
8378
+ search
8379
+ } = hostContext(appName, pcoMeta);
8380
+ return {
8381
+ app_name: appName,
8382
+ host,
8383
+ pathname,
8384
+ resource: pcoMeta.resource,
8385
+ search,
8386
+ ...config.params
8387
+ };
8388
+ });
8389
+ // The drawer keeps the page mounted while it's closed, and single-page apps
8390
+ // can navigate meanwhile, so the page hears where the user is on each open
8391
+ // and whenever the host page's pco: meta tags change.
8392
+ React__default.useEffect(function tellThePageWhereTheUserIs() {
8393
+ var _a;
8394
+ if (!isReady || !isOpen) return;
8395
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8396
+ payload: hostContext(appName, pcoMeta),
8397
+ type: "HOST_CONTEXT_CHANGED"
8398
+ });
8399
+ }, [isOpen, isReady, appName, pcoMeta]);
8400
+ React__default.useEffect(function tellThePageWhetherItIsVisible() {
8401
+ var _a;
8402
+ if (!isReady) return;
8403
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8404
+ type: isOpen ? "PANE_VISIBLE" : "PANE_HIDDEN"
8405
+ });
8406
+ }, [isOpen, isReady]);
8407
+ React__default.useEffect(function tellThePageAboutStateChanges() {
8408
+ var _a;
8409
+ if (!isReady || !config.state) return;
8410
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8411
+ payload: config.state,
8412
+ type: "TOOL_STATE_CHANGED"
8413
+ });
8414
+ }, [isReady, config.state]);
8415
+ const handleMessage = React__default.useCallback(message => {
8416
+ var _a;
8417
+ switch (message.type) {
8418
+ case "READY":
8419
+ return setIsReady(true);
8420
+ case "CLOSE_DRAWER":
8421
+ return closeDrawer();
8422
+ case "OPEN_DRAWER":
8423
+ return openDrawer();
8424
+ case "OPEN_TOOL":
8425
+ {
8426
+ const {
8427
+ path = "",
8428
+ tool
8429
+ } = (_a = message.payload) !== null && _a !== void 0 ? _a : {};
8430
+ if (tool) openTool(tool, path);
8431
+ return;
8432
+ }
8433
+ case "OPEN_PICOBOT":
8434
+ // Without the Picobot panel there's nowhere to send it.
8435
+ return openPicobot === null || openPicobot === void 0 ? void 0 : openPicobot(message.payload);
8436
+ case "TRACK_PENDO":
8437
+ return trackPendo(message.payload);
8438
+ case "IFRAME_LOAD_ERROR":
8439
+ console.warn(`topbar: ${config.title} iframe failed to load`);
8440
+ return setErrored(true);
8441
+ }
8442
+ }, [closeDrawer, config.title, openDrawer, openPicobot, openTool]);
8443
+ const handleRetry = React__default.useCallback(() => {
8444
+ setErrored(false);
8445
+ setIsReady(false);
8446
+ setMountKey(key => key + 1);
8447
+ }, []);
8448
+ if (errored) {
8449
+ return /*#__PURE__*/React__default.createElement(LoadError$1, {
8450
+ closeDrawer: closeDrawer,
8451
+ heading: config.heading,
8452
+ onRetry: handleRetry
8453
+ });
8454
+ }
8455
+ return /*#__PURE__*/React__default.createElement(StackView$2, {
8456
+ flex: 1,
8457
+ axis: "vertical"
8458
+ }, !isReady && (/*#__PURE__*/React__default.createElement(DrawerHeader, {
8459
+ closeDrawer: closeDrawer
8460
+ }, /*#__PURE__*/React__default.createElement(DrawerHeading, null, config.heading))), /*#__PURE__*/React__default.createElement(ToolIframe, {
8461
+ key: mountKey,
8462
+ ref: iframeRef,
8463
+ basePath: config.basePath,
8464
+ currentPath: currentPath,
8465
+ isVisible: isOpen,
8466
+ onChangePath: onChangePath,
8467
+ onMessage: handleMessage,
8468
+ origin: origin,
8469
+ params: params,
8470
+ title: config.title
8471
+ }));
8472
+ }
8473
+ function LoadError$1({
8474
+ closeDrawer,
8475
+ heading,
8476
+ onRetry
8477
+ }) {
8478
+ return /*#__PURE__*/React__default.createElement(StackView$2, {
8479
+ flex: 1,
8480
+ axis: "vertical"
8481
+ }, /*#__PURE__*/React__default.createElement(DrawerHeader, {
8482
+ closeDrawer: closeDrawer
8483
+ }, /*#__PURE__*/React__default.createElement(DrawerHeading, null, heading)), /*#__PURE__*/React__default.createElement(StackView$2, {
8484
+ axis: "vertical",
8485
+ flex: 1,
8486
+ alignment: "center",
8487
+ distribution: "center",
8488
+ padding: 3,
8489
+ spacing: 1
8490
+ }, /*#__PURE__*/React__default.createElement(Text, {
8491
+ size: 5,
8492
+ color: "var(--t-text-color-secondary)"
8493
+ }, "This couldn't load. Try again in a moment."), /*#__PURE__*/React__default.createElement(Box, {
8494
+ paddingTop: 2
8495
+ }, /*#__PURE__*/React__default.createElement(Button$1, {
8496
+ onClick: onRetry,
8497
+ iconLeft: "general.refresh",
8498
+ theme: "primary",
8499
+ variant: "fill",
8500
+ title: "Retry"
8501
+ }))));
8502
+ }
8503
+
8219
8504
  var styles$1 = {"banner":"banner-YfQ37","stacked":"stacked-EwLRh","content":"content-lNjWf","icon":"icon-abz7q","iconShape":"iconShape-6uyot","iconSparkle":"iconSparkle-t0OzK","text":"text--Vlhl","title":"title-zOEOR","subtitle":"subtitle-ufLnk","chevron":"chevron-oOUA-","inlineContent":"inlineContent-h5sVl","sparkle":"sparkle-uuMBp","inlineTitle":"inlineTitle-ru2Rk","action":"action-fSY3n","actionLabel":"actionLabel-MRBjb","actionChevron":"actionChevron-DghlN"};
8220
8505
 
8221
8506
  const SPARKLE_PATH$1 = "M3.809 10.1332C3.87511 9.95596 4.12579 9.95588 4.19181 10.1332L4.63712 11.3363C4.64169 11.3487 4.65116 11.359 4.66349 11.3637L5.86661 11.809C6.04452 11.8749 6.04455 12.126 5.86661 12.1918L4.66349 12.6371C4.65134 12.6417 4.64173 12.6513 4.63712 12.6635L4.19181 13.8666C4.12597 14.0445 3.87486 14.0445 3.809 13.8666L3.36368 12.6635C3.35905 12.6512 3.3487 12.6417 3.33634 12.6371L2.13321 12.1918C1.95588 12.1258 1.95596 11.8751 2.13321 11.809L3.33634 11.3637C3.34877 11.3591 3.35908 11.3488 3.36368 11.3363L3.809 10.1332ZM8.52091 3.33341C8.68571 2.88899 9.31518 2.88891 9.47989 3.33341L10.5922 6.34122C10.6037 6.37226 10.6285 6.39712 10.6596 6.4086L13.6664 7.52091C14.1113 7.68553 14.1113 8.31528 13.6664 8.47989L10.6596 9.5922C10.6285 9.6037 10.6037 9.6285 10.5922 9.65958L9.47989 12.6664C9.31528 13.1113 8.68553 13.1113 8.52091 12.6664L7.4086 9.65958C7.39712 9.62853 7.37226 9.60371 7.34122 9.5922L4.33341 8.47989C3.88891 8.31518 3.88899 7.68571 4.33341 7.52091L7.34122 6.4086C7.3723 6.3971 7.3971 6.3723 7.4086 6.34122L8.52091 3.33341ZM3.809 2.13321C3.87511 1.95596 4.12579 1.95588 4.19181 2.13321L4.63712 3.33634C4.64169 3.3487 4.65116 3.35905 4.66349 3.36368L5.86661 3.809C6.04452 3.87486 6.04455 4.12597 5.86661 4.19181L4.66349 4.63712C4.65134 4.64173 4.64173 4.65134 4.63712 4.66349L4.19181 5.86661C4.12597 6.04455 3.87486 6.04452 3.809 5.86661L3.36368 4.66349C3.35905 4.65116 3.3487 4.64169 3.33634 4.63712L2.13321 4.19181C1.95588 4.12579 1.95596 3.87511 2.13321 3.809L3.33634 3.36368C3.34877 3.35908 3.35908 3.34877 3.36368 3.33634L3.809 2.13321Z";
@@ -8811,7 +9096,46 @@ function CalendlyWidget({
8811
9096
  styles: styles
8812
9097
  })) : null;
8813
9098
  }
8814
- function HelpdeskComponent({
9099
+ function HelpdeskComponent(props) {
9100
+ return props.mountLegacy === false ? (/*#__PURE__*/React__default.createElement(HelpdeskIframe, {
9101
+ ...props
9102
+ })) : (/*#__PURE__*/React__default.createElement(HelpdeskAddOn, {
9103
+ ...props
9104
+ }));
9105
+ }
9106
+ function HelpdeskIframe(props) {
9107
+ var _a;
9108
+ const fetchZendeskDetails = (_a = props.helpdeskConfig) === null || _a === void 0 ? void 0 : _a.fetchZendeskDetails;
9109
+ const hasPicobotPanel = Boolean(props.openPicobot);
9110
+ const config = React__default.useMemo(() => ({
9111
+ app: "helpdesk",
9112
+ basePath: "/topbar/helpdesk",
9113
+ heading: "Help and support",
9114
+ params: {
9115
+ fetch_zendesk_details: fetchZendeskDetails ? "1" : null,
9116
+ // Tells helpdesk to send OPEN_PICOBOT rather than embed Ask AI.
9117
+ open_picobot: hasPicobotPanel ? "1" : null
9118
+ },
9119
+ // The gate can answer after the page loads, e.g. when userId arrives
9120
+ // late, so the page also hears about it here.
9121
+ state: {
9122
+ canOpenPicobot: hasPicobotPanel
9123
+ },
9124
+ title: "Help and support"
9125
+ }), [fetchZendeskDetails, hasPicobotPanel]);
9126
+ // The page reads its params once, so mounting before the gate answers
9127
+ // would leave out open_picobot for good.
9128
+ if (props.isPicobotLoading) {
9129
+ return /*#__PURE__*/React__default.createElement(DrawerHeader, {
9130
+ closeDrawer: props.closeDrawer
9131
+ }, /*#__PURE__*/React__default.createElement(DrawerHeading, null, "Help and support"));
9132
+ }
9133
+ return /*#__PURE__*/React__default.createElement(IframeTool, {
9134
+ ...props,
9135
+ config: config
9136
+ });
9137
+ }
9138
+ function HelpdeskAddOn({
8815
9139
  appName,
8816
9140
  closeDrawer,
8817
9141
  currentPath,
@@ -9689,7 +10013,25 @@ function NavLinkWithBadge({
9689
10013
  ...badge
9690
10014
  }));
9691
10015
  }
9692
- function TasksComponent({
10016
+ const TASKS_IFRAME_CONFIG = {
10017
+ app: "home",
10018
+ basePath: "/topbar/tasks",
10019
+ heading: "To do",
10020
+ title: "To do"
10021
+ };
10022
+ function TasksComponent(props) {
10023
+ return props.mountLegacy === false ? (
10024
+ /*#__PURE__*/
10025
+ // The iframe and Home's own pages share Home's origin and talk to each
10026
+ // other directly, so there's no worker to hand over.
10027
+ React__default.createElement(IframeTool, {
10028
+ ...props,
10029
+ config: TASKS_IFRAME_CONFIG
10030
+ })) : (/*#__PURE__*/React__default.createElement(TasksAddOn, {
10031
+ ...props
10032
+ }));
10033
+ }
10034
+ function TasksAddOn({
9693
10035
  closeDrawer,
9694
10036
  env,
9695
10037
  isOpen,
@@ -10130,6 +10472,8 @@ function Toolbar({
10130
10472
  env,
10131
10473
  helpdeskConfig = {},
10132
10474
  linkToProfile = true,
10475
+ mountLegacyHelpdesk = true,
10476
+ mountLegacyTasks = true,
10133
10477
  onReceiveTasksWorker,
10134
10478
  requestClearAppsCache,
10135
10479
  userAvatarPath,
@@ -10374,6 +10718,7 @@ function Toolbar({
10374
10718
  const toolSpecificProps = {
10375
10719
  Helpdesk: {
10376
10720
  isPicobotLoading: isPicobotGateLoading,
10721
+ mountLegacy: mountLegacyHelpdesk,
10377
10722
  openPicobot: displayPicobotIcon ? openPicobot : undefined
10378
10723
  },
10379
10724
  Profile: {
@@ -10389,6 +10734,7 @@ function Toolbar({
10389
10734
  userAvatarPath
10390
10735
  },
10391
10736
  Tasks: {
10737
+ mountLegacy: mountLegacyTasks,
10392
10738
  onReceiveWorker: onReceiveTasksWorker
10393
10739
  }
10394
10740
  };