@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.
package/dist/topbar.js CHANGED
@@ -8241,6 +8241,291 @@ const DeveloperTools = {
8241
8241
  name: "DeveloperTools"
8242
8242
  };
8243
8243
 
8244
+ const DEFAULT_READY_TIMEOUT_MS = 8000;
8245
+ // The route rides in the fragment (`/topbar/helpdesk#email`), not the path, so
8246
+ // changing it is a same-document navigation that doesn't reload the iframe.
8247
+ function buildToolIframeSrc(origin, basePath, route, params = {}) {
8248
+ const [rawPath, queryPart] = route.replace(/^\/+/, "").split("?", 2);
8249
+ const safePath = rawPath.split("/").filter(segment => segment && segment !== "." && segment !== "..").join("/");
8250
+ const fragment = queryPart !== undefined ? `${safePath}?${queryPart}` : safePath;
8251
+ const url = new URL(basePath, origin);
8252
+ for (const [key, value] of Object.entries(params)) {
8253
+ if (value) url.searchParams.set(key, value);
8254
+ }
8255
+ // Always end in `#`, even for an empty route: going from `…#tasks/new` to a
8256
+ // URL with no fragment at all is a new document, which reloads the iframe.
8257
+ return `${url.toString()}#${fragment}`;
8258
+ }
8259
+ /**
8260
+ * An iframe for a toolbar tool served by another app. Shared by every tool
8261
+ * that has moved off add-ons: the page reports READY once it has painted,
8262
+ * NEW_ROUTE_RENDERED when its route changes, and anything else is handed to
8263
+ * `onMessage`. Messages from any other origin or window are ignored.
8264
+ */
8265
+ const ToolIframe = /*#__PURE__*/React.forwardRef(function ToolIframe({
8266
+ basePath,
8267
+ currentPath,
8268
+ isVisible = true,
8269
+ onChangePath,
8270
+ onMessage,
8271
+ origin,
8272
+ params,
8273
+ readyTimeoutMs = DEFAULT_READY_TIMEOUT_MS,
8274
+ title
8275
+ }, ref) {
8276
+ const iframeRef = React.useRef(null);
8277
+ const [loadedPath, setLoadedPath] = React.useState(currentPath || "");
8278
+ // Hidden until the page paints, so its blank first frame doesn't flash
8279
+ // white against the drawer in dark mode.
8280
+ const [isReady, setIsReady] = React.useState(false);
8281
+ const hasReportedErrorRef = React.useRef(false);
8282
+ const readyTimeoutRef = React.useRef();
8283
+ const onMessageRef = React.useRef(onMessage);
8284
+ onMessageRef.current = onMessage;
8285
+ const onChangePathRef = React.useRef(onChangePath);
8286
+ onChangePathRef.current = onChangePath;
8287
+ // Query params are read once at load: changing them would reload the
8288
+ // page. Context that changes later goes over HOST_CONTEXT_CHANGED.
8289
+ const [initialParams] = React.useState(params);
8290
+ React.useEffect(function reportLoadErrorIfNeverReady() {
8291
+ const timeout = setTimeout(() => {
8292
+ var _a;
8293
+ if (hasReportedErrorRef.current) return;
8294
+ hasReportedErrorRef.current = true;
8295
+ (_a = onMessageRef.current) === null || _a === void 0 ? void 0 : _a.call(onMessageRef, {
8296
+ type: "IFRAME_LOAD_ERROR"
8297
+ });
8298
+ }, readyTimeoutMs);
8299
+ readyTimeoutRef.current = timeout;
8300
+ return () => clearTimeout(timeout);
8301
+ }, [readyTimeoutMs]);
8302
+ React.useEffect(function subscribeToGuestMessages() {
8303
+ function handleGuestMessage(e) {
8304
+ var _a, _b, _c, _d;
8305
+ if (e.origin !== origin) return;
8306
+ if (!e.source || !iframeRef.current) return;
8307
+ if (e.source !== iframeRef.current.contentWindow) return;
8308
+ if (typeof ((_a = e.data) === null || _a === void 0 ? void 0 : _a.type) !== "string") return;
8309
+ const message = e.data;
8310
+ if (message.type === "READY") {
8311
+ clearTimeout(readyTimeoutRef.current);
8312
+ setIsReady(true);
8313
+ }
8314
+ if (message.type === "NEW_ROUTE_RENDERED") {
8315
+ const reportedPath = String((_b = message.payload) !== null && _b !== void 0 ? _b : "");
8316
+ setLoadedPath(reportedPath);
8317
+ (_c = onChangePathRef.current) === null || _c === void 0 ? void 0 : _c.call(onChangePathRef, reportedPath);
8318
+ }
8319
+ (_d = onMessageRef.current) === null || _d === void 0 ? void 0 : _d.call(onMessageRef, message);
8320
+ }
8321
+ window.addEventListener("message", handleGuestMessage);
8322
+ return () => window.removeEventListener("message", handleGuestMessage);
8323
+ }, [origin]);
8324
+ React.useEffect(function followRouteChangesFromTopbar() {
8325
+ setLoadedPath(currentPath || "");
8326
+ }, [currentPath]);
8327
+ React.useImperativeHandle(ref, () => ({
8328
+ postMessage(message) {
8329
+ var _a, _b, _c;
8330
+ // Safari ignores focus() from inside a cross-origin iframe, so the
8331
+ // host focuses the iframe before the page focuses its own input.
8332
+ if (message.type === "PANE_VISIBLE") (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.focus();
8333
+ (_c = (_b = iframeRef.current) === null || _b === void 0 ? void 0 : _b.contentWindow) === null || _c === void 0 ? void 0 : _c.postMessage(message, origin);
8334
+ }
8335
+ }), [origin]);
8336
+ return /*#__PURE__*/React.createElement("iframe", {
8337
+ ref: iframeRef,
8338
+ src: buildToolIframeSrc(origin, basePath, loadedPath, initialParams),
8339
+ allow: "clipboard-write",
8340
+ style: {
8341
+ border: 0,
8342
+ display: isVisible ? undefined : "none",
8343
+ flex: 1,
8344
+ height: "100%",
8345
+ visibility: isReady ? undefined : "hidden",
8346
+ width: "100%"
8347
+ },
8348
+ title: title
8349
+ });
8350
+ });
8351
+
8352
+ function hostContext(appName, pcoMeta) {
8353
+ return {
8354
+ appName,
8355
+ host: window.location.host,
8356
+ pathname: window.location.pathname,
8357
+ pcoMeta,
8358
+ search: window.location.search
8359
+ };
8360
+ }
8361
+ function trackPendo(payload) {
8362
+ const {
8363
+ event,
8364
+ properties = {}
8365
+ } = payload !== null && payload !== void 0 ? payload : {};
8366
+ if (!event) return;
8367
+ if (!(window === null || window === void 0 ? void 0 : window.pendo)) return console.warn("`window.pendo` is undefined");
8368
+ window.pendo.track(event, properties);
8369
+ }
8370
+ /**
8371
+ * A toolbar tool whose drawer is a page served by another app in an iframe.
8372
+ * Topbar only relays: the page decides what it shows and when it's ready.
8373
+ *
8374
+ * Page → topbar: READY, NEW_ROUTE_RENDERED, CLOSE_DRAWER, OPEN_DRAWER,
8375
+ * OPEN_TOOL { tool, path }, OPEN_PICOBOT { conversationId?, draft?,
8376
+ * ticketExternalId? }, TRACK_PENDO { event, properties }.
8377
+ *
8378
+ * Topbar → page: PANE_VISIBLE, PANE_HIDDEN, HOST_CONTEXT_CHANGED { appName,
8379
+ * host, pathname, pcoMeta, search }, TOOL_STATE_CHANGED { ...config.state }.
8380
+ */
8381
+ function IframeTool({
8382
+ appName,
8383
+ closeDrawer,
8384
+ config,
8385
+ currentPath,
8386
+ env,
8387
+ isOpen,
8388
+ onChangePath,
8389
+ openDrawer,
8390
+ openPicobot,
8391
+ openTool
8392
+ }) {
8393
+ const pcoMeta = usePcoMeta();
8394
+ const origin = React.useMemo(() => pcoUrl(env)(config.app), [env, config.app]);
8395
+ const iframeRef = React.useRef(null);
8396
+ const [isReady, setIsReady] = React.useState(false);
8397
+ const [errored, setErrored] = React.useState(false);
8398
+ const [mountKey, setMountKey] = React.useState(0);
8399
+ const [params] = React.useState(() => {
8400
+ const {
8401
+ host,
8402
+ pathname,
8403
+ search
8404
+ } = hostContext(appName, pcoMeta);
8405
+ return {
8406
+ app_name: appName,
8407
+ host,
8408
+ pathname,
8409
+ resource: pcoMeta.resource,
8410
+ search,
8411
+ ...config.params
8412
+ };
8413
+ });
8414
+ // The drawer keeps the page mounted while it's closed, and single-page apps
8415
+ // can navigate meanwhile, so the page hears where the user is on each open
8416
+ // and whenever the host page's pco: meta tags change.
8417
+ React.useEffect(function tellThePageWhereTheUserIs() {
8418
+ var _a;
8419
+ if (!isReady || !isOpen) return;
8420
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8421
+ payload: hostContext(appName, pcoMeta),
8422
+ type: "HOST_CONTEXT_CHANGED"
8423
+ });
8424
+ }, [isOpen, isReady, appName, pcoMeta]);
8425
+ React.useEffect(function tellThePageWhetherItIsVisible() {
8426
+ var _a;
8427
+ if (!isReady) return;
8428
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8429
+ type: isOpen ? "PANE_VISIBLE" : "PANE_HIDDEN"
8430
+ });
8431
+ }, [isOpen, isReady]);
8432
+ React.useEffect(function tellThePageAboutStateChanges() {
8433
+ var _a;
8434
+ if (!isReady || !config.state) return;
8435
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8436
+ payload: config.state,
8437
+ type: "TOOL_STATE_CHANGED"
8438
+ });
8439
+ }, [isReady, config.state]);
8440
+ const handleMessage = React.useCallback(message => {
8441
+ var _a;
8442
+ switch (message.type) {
8443
+ case "READY":
8444
+ return setIsReady(true);
8445
+ case "CLOSE_DRAWER":
8446
+ return closeDrawer();
8447
+ case "OPEN_DRAWER":
8448
+ return openDrawer();
8449
+ case "OPEN_TOOL":
8450
+ {
8451
+ const {
8452
+ path = "",
8453
+ tool
8454
+ } = (_a = message.payload) !== null && _a !== void 0 ? _a : {};
8455
+ if (tool) openTool(tool, path);
8456
+ return;
8457
+ }
8458
+ case "OPEN_PICOBOT":
8459
+ // Without the Picobot panel there's nowhere to send it.
8460
+ return openPicobot === null || openPicobot === void 0 ? void 0 : openPicobot(message.payload);
8461
+ case "TRACK_PENDO":
8462
+ return trackPendo(message.payload);
8463
+ case "IFRAME_LOAD_ERROR":
8464
+ console.warn(`topbar: ${config.title} iframe failed to load`);
8465
+ return setErrored(true);
8466
+ }
8467
+ }, [closeDrawer, config.title, openDrawer, openPicobot, openTool]);
8468
+ const handleRetry = React.useCallback(() => {
8469
+ setErrored(false);
8470
+ setIsReady(false);
8471
+ setMountKey(key => key + 1);
8472
+ }, []);
8473
+ if (errored) {
8474
+ return /*#__PURE__*/React.createElement(LoadError$1, {
8475
+ closeDrawer: closeDrawer,
8476
+ heading: config.heading,
8477
+ onRetry: handleRetry
8478
+ });
8479
+ }
8480
+ return /*#__PURE__*/React.createElement(tapestryReact.StackView, {
8481
+ flex: 1,
8482
+ axis: "vertical"
8483
+ }, !isReady && (/*#__PURE__*/React.createElement(DrawerHeader, {
8484
+ closeDrawer: closeDrawer
8485
+ }, /*#__PURE__*/React.createElement(DrawerHeading, null, config.heading))), /*#__PURE__*/React.createElement(ToolIframe, {
8486
+ key: mountKey,
8487
+ ref: iframeRef,
8488
+ basePath: config.basePath,
8489
+ currentPath: currentPath,
8490
+ isVisible: isOpen,
8491
+ onChangePath: onChangePath,
8492
+ onMessage: handleMessage,
8493
+ origin: origin,
8494
+ params: params,
8495
+ title: config.title
8496
+ }));
8497
+ }
8498
+ function LoadError$1({
8499
+ closeDrawer,
8500
+ heading,
8501
+ onRetry
8502
+ }) {
8503
+ return /*#__PURE__*/React.createElement(tapestryReact.StackView, {
8504
+ flex: 1,
8505
+ axis: "vertical"
8506
+ }, /*#__PURE__*/React.createElement(DrawerHeader, {
8507
+ closeDrawer: closeDrawer
8508
+ }, /*#__PURE__*/React.createElement(DrawerHeading, null, heading)), /*#__PURE__*/React.createElement(tapestryReact.StackView, {
8509
+ axis: "vertical",
8510
+ flex: 1,
8511
+ alignment: "center",
8512
+ distribution: "center",
8513
+ padding: 3,
8514
+ spacing: 1
8515
+ }, /*#__PURE__*/React.createElement(tapestryReact.Text, {
8516
+ size: 5,
8517
+ color: "var(--t-text-color-secondary)"
8518
+ }, "This couldn't load. Try again in a moment."), /*#__PURE__*/React.createElement(tapestryReact.Box, {
8519
+ paddingTop: 2
8520
+ }, /*#__PURE__*/React.createElement(tapestryReact.Button, {
8521
+ onClick: onRetry,
8522
+ iconLeft: "general.refresh",
8523
+ theme: "primary",
8524
+ variant: "fill",
8525
+ title: "Retry"
8526
+ }))));
8527
+ }
8528
+
8244
8529
  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"};
8245
8530
 
8246
8531
  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";
@@ -8836,7 +9121,46 @@ function CalendlyWidget({
8836
9121
  styles: styles
8837
9122
  })) : null;
8838
9123
  }
8839
- function HelpdeskComponent({
9124
+ function HelpdeskComponent(props) {
9125
+ return props.mountLegacy === false ? (/*#__PURE__*/React.createElement(HelpdeskIframe, {
9126
+ ...props
9127
+ })) : (/*#__PURE__*/React.createElement(HelpdeskAddOn, {
9128
+ ...props
9129
+ }));
9130
+ }
9131
+ function HelpdeskIframe(props) {
9132
+ var _a;
9133
+ const fetchZendeskDetails = (_a = props.helpdeskConfig) === null || _a === void 0 ? void 0 : _a.fetchZendeskDetails;
9134
+ const hasPicobotPanel = Boolean(props.openPicobot);
9135
+ const config = React.useMemo(() => ({
9136
+ app: "helpdesk",
9137
+ basePath: "/topbar/helpdesk",
9138
+ heading: "Help and support",
9139
+ params: {
9140
+ fetch_zendesk_details: fetchZendeskDetails ? "1" : null,
9141
+ // Tells helpdesk to send OPEN_PICOBOT rather than embed Ask AI.
9142
+ open_picobot: hasPicobotPanel ? "1" : null
9143
+ },
9144
+ // The gate can answer after the page loads, e.g. when userId arrives
9145
+ // late, so the page also hears about it here.
9146
+ state: {
9147
+ canOpenPicobot: hasPicobotPanel
9148
+ },
9149
+ title: "Help and support"
9150
+ }), [fetchZendeskDetails, hasPicobotPanel]);
9151
+ // The page reads its params once, so mounting before the gate answers
9152
+ // would leave out open_picobot for good.
9153
+ if (props.isPicobotLoading) {
9154
+ return /*#__PURE__*/React.createElement(DrawerHeader, {
9155
+ closeDrawer: props.closeDrawer
9156
+ }, /*#__PURE__*/React.createElement(DrawerHeading, null, "Help and support"));
9157
+ }
9158
+ return /*#__PURE__*/React.createElement(IframeTool, {
9159
+ ...props,
9160
+ config: config
9161
+ });
9162
+ }
9163
+ function HelpdeskAddOn({
8840
9164
  appName,
8841
9165
  closeDrawer,
8842
9166
  currentPath,
@@ -9714,7 +10038,25 @@ function NavLinkWithBadge({
9714
10038
  ...badge
9715
10039
  }));
9716
10040
  }
9717
- function TasksComponent({
10041
+ const TASKS_IFRAME_CONFIG = {
10042
+ app: "home",
10043
+ basePath: "/topbar/tasks",
10044
+ heading: "To do",
10045
+ title: "To do"
10046
+ };
10047
+ function TasksComponent(props) {
10048
+ return props.mountLegacy === false ? (
10049
+ /*#__PURE__*/
10050
+ // The iframe and Home's own pages share Home's origin and talk to each
10051
+ // other directly, so there's no worker to hand over.
10052
+ React.createElement(IframeTool, {
10053
+ ...props,
10054
+ config: TASKS_IFRAME_CONFIG
10055
+ })) : (/*#__PURE__*/React.createElement(TasksAddOn, {
10056
+ ...props
10057
+ }));
10058
+ }
10059
+ function TasksAddOn({
9718
10060
  closeDrawer,
9719
10061
  env,
9720
10062
  isOpen,
@@ -10155,6 +10497,8 @@ function Toolbar({
10155
10497
  env,
10156
10498
  helpdeskConfig = {},
10157
10499
  linkToProfile = true,
10500
+ mountLegacyHelpdesk = true,
10501
+ mountLegacyTasks = true,
10158
10502
  onReceiveTasksWorker,
10159
10503
  requestClearAppsCache,
10160
10504
  userAvatarPath,
@@ -10399,6 +10743,7 @@ function Toolbar({
10399
10743
  const toolSpecificProps = {
10400
10744
  Helpdesk: {
10401
10745
  isPicobotLoading: isPicobotGateLoading,
10746
+ mountLegacy: mountLegacyHelpdesk,
10402
10747
  openPicobot: displayPicobotIcon ? openPicobot : undefined
10403
10748
  },
10404
10749
  Profile: {
@@ -10414,6 +10759,7 @@ function Toolbar({
10414
10759
  userAvatarPath
10415
10760
  },
10416
10761
  Tasks: {
10762
+ mountLegacy: mountLegacyTasks,
10417
10763
  onReceiveWorker: onReceiveTasksWorker
10418
10764
  }
10419
10765
  };