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