@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.
@@ -8224,6 +8224,291 @@ true;
8224
8224
  name: "DeveloperTools"
8225
8225
  };
8226
8226
 
8227
+ const DEFAULT_READY_TIMEOUT_MS = 8000;
8228
+ // The route rides in the fragment (`/topbar/helpdesk#email`), not the path, so
8229
+ // changing it is a same-document navigation that doesn't reload the iframe.
8230
+ function buildToolIframeSrc(origin, basePath, route, params = {}) {
8231
+ const [rawPath, queryPart] = route.replace(/^\/+/, "").split("?", 2);
8232
+ const safePath = rawPath.split("/").filter(segment => segment && segment !== "." && segment !== "..").join("/");
8233
+ const fragment = queryPart !== undefined ? `${safePath}?${queryPart}` : safePath;
8234
+ const url = new URL(basePath, origin);
8235
+ for (const [key, value] of Object.entries(params)) {
8236
+ if (value) url.searchParams.set(key, value);
8237
+ }
8238
+ // Always end in `#`, even for an empty route: going from `…#tasks/new` to a
8239
+ // URL with no fragment at all is a new document, which reloads the iframe.
8240
+ return `${url.toString()}#${fragment}`;
8241
+ }
8242
+ /**
8243
+ * An iframe for a toolbar tool served by another app. Shared by every tool
8244
+ * that has moved off add-ons: the page reports READY once it has painted,
8245
+ * NEW_ROUTE_RENDERED when its route changes, and anything else is handed to
8246
+ * `onMessage`. Messages from any other origin or window are ignored.
8247
+ */
8248
+ const ToolIframe = /*#__PURE__*/React.forwardRef(function ToolIframe({
8249
+ basePath,
8250
+ currentPath,
8251
+ isVisible = true,
8252
+ onChangePath,
8253
+ onMessage,
8254
+ origin,
8255
+ params,
8256
+ readyTimeoutMs = DEFAULT_READY_TIMEOUT_MS,
8257
+ title
8258
+ }, ref) {
8259
+ const iframeRef = React.useRef(null);
8260
+ const [loadedPath, setLoadedPath] = React.useState(currentPath || "");
8261
+ // Hidden until the page paints, so its blank first frame doesn't flash
8262
+ // white against the drawer in dark mode.
8263
+ const [isReady, setIsReady] = React.useState(false);
8264
+ const hasReportedErrorRef = React.useRef(false);
8265
+ const readyTimeoutRef = React.useRef();
8266
+ const onMessageRef = React.useRef(onMessage);
8267
+ onMessageRef.current = onMessage;
8268
+ const onChangePathRef = React.useRef(onChangePath);
8269
+ onChangePathRef.current = onChangePath;
8270
+ // Query params are read once at load: changing them would reload the
8271
+ // page. Context that changes later goes over HOST_CONTEXT_CHANGED.
8272
+ const [initialParams] = React.useState(params);
8273
+ React.useEffect(function reportLoadErrorIfNeverReady() {
8274
+ const timeout = setTimeout(() => {
8275
+ var _a;
8276
+ if (hasReportedErrorRef.current) return;
8277
+ hasReportedErrorRef.current = true;
8278
+ (_a = onMessageRef.current) === null || _a === void 0 ? void 0 : _a.call(onMessageRef, {
8279
+ type: "IFRAME_LOAD_ERROR"
8280
+ });
8281
+ }, readyTimeoutMs);
8282
+ readyTimeoutRef.current = timeout;
8283
+ return () => clearTimeout(timeout);
8284
+ }, [readyTimeoutMs]);
8285
+ React.useEffect(function subscribeToGuestMessages() {
8286
+ function handleGuestMessage(e) {
8287
+ var _a, _b, _c, _d;
8288
+ if (e.origin !== origin) return;
8289
+ if (!e.source || !iframeRef.current) return;
8290
+ if (e.source !== iframeRef.current.contentWindow) return;
8291
+ if (typeof ((_a = e.data) === null || _a === void 0 ? void 0 : _a.type) !== "string") return;
8292
+ const message = e.data;
8293
+ if (message.type === "READY") {
8294
+ clearTimeout(readyTimeoutRef.current);
8295
+ setIsReady(true);
8296
+ }
8297
+ if (message.type === "NEW_ROUTE_RENDERED") {
8298
+ const reportedPath = String((_b = message.payload) !== null && _b !== void 0 ? _b : "");
8299
+ setLoadedPath(reportedPath);
8300
+ (_c = onChangePathRef.current) === null || _c === void 0 ? void 0 : _c.call(onChangePathRef, reportedPath);
8301
+ }
8302
+ (_d = onMessageRef.current) === null || _d === void 0 ? void 0 : _d.call(onMessageRef, message);
8303
+ }
8304
+ window.addEventListener("message", handleGuestMessage);
8305
+ return () => window.removeEventListener("message", handleGuestMessage);
8306
+ }, [origin]);
8307
+ React.useEffect(function followRouteChangesFromTopbar() {
8308
+ setLoadedPath(currentPath || "");
8309
+ }, [currentPath]);
8310
+ React.useImperativeHandle(ref, () => ({
8311
+ postMessage(message) {
8312
+ var _a, _b, _c;
8313
+ // Safari ignores focus() from inside a cross-origin iframe, so the
8314
+ // host focuses the iframe before the page focuses its own input.
8315
+ if (message.type === "PANE_VISIBLE") (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.focus();
8316
+ (_c = (_b = iframeRef.current) === null || _b === void 0 ? void 0 : _b.contentWindow) === null || _c === void 0 ? void 0 : _c.postMessage(message, origin);
8317
+ }
8318
+ }), [origin]);
8319
+ return /*#__PURE__*/React.createElement("iframe", {
8320
+ ref: iframeRef,
8321
+ src: buildToolIframeSrc(origin, basePath, loadedPath, initialParams),
8322
+ allow: "clipboard-write",
8323
+ style: {
8324
+ border: 0,
8325
+ display: isVisible ? undefined : "none",
8326
+ flex: 1,
8327
+ height: "100%",
8328
+ visibility: isReady ? undefined : "hidden",
8329
+ width: "100%"
8330
+ },
8331
+ title: title
8332
+ });
8333
+ });
8334
+
8335
+ function hostContext(appName, pcoMeta) {
8336
+ return {
8337
+ appName,
8338
+ host: window.location.host,
8339
+ pathname: window.location.pathname,
8340
+ pcoMeta,
8341
+ search: window.location.search
8342
+ };
8343
+ }
8344
+ function trackPendo(payload) {
8345
+ const {
8346
+ event,
8347
+ properties = {}
8348
+ } = payload !== null && payload !== void 0 ? payload : {};
8349
+ if (!event) return;
8350
+ if (!(window === null || window === void 0 ? void 0 : window.pendo)) return console.warn("`window.pendo` is undefined");
8351
+ window.pendo.track(event, properties);
8352
+ }
8353
+ /**
8354
+ * A toolbar tool whose drawer is a page served by another app in an iframe.
8355
+ * Topbar only relays: the page decides what it shows and when it's ready.
8356
+ *
8357
+ * Page → topbar: READY, NEW_ROUTE_RENDERED, CLOSE_DRAWER, OPEN_DRAWER,
8358
+ * OPEN_TOOL { tool, path }, OPEN_PICOBOT { conversationId?, draft?,
8359
+ * ticketExternalId? }, TRACK_PENDO { event, properties }.
8360
+ *
8361
+ * Topbar → page: PANE_VISIBLE, PANE_HIDDEN, HOST_CONTEXT_CHANGED { appName,
8362
+ * host, pathname, pcoMeta, search }, TOOL_STATE_CHANGED { ...config.state }.
8363
+ */
8364
+ function IframeTool({
8365
+ appName,
8366
+ closeDrawer,
8367
+ config,
8368
+ currentPath,
8369
+ env,
8370
+ isOpen,
8371
+ onChangePath,
8372
+ openDrawer,
8373
+ openPicobot,
8374
+ openTool
8375
+ }) {
8376
+ const pcoMeta = usePcoMeta();
8377
+ const origin = React.useMemo(() => pcoUrl(env)(config.app), [env, config.app]);
8378
+ const iframeRef = React.useRef(null);
8379
+ const [isReady, setIsReady] = React.useState(false);
8380
+ const [errored, setErrored] = React.useState(false);
8381
+ const [mountKey, setMountKey] = React.useState(0);
8382
+ const [params] = React.useState(() => {
8383
+ const {
8384
+ host,
8385
+ pathname,
8386
+ search
8387
+ } = hostContext(appName, pcoMeta);
8388
+ return {
8389
+ app_name: appName,
8390
+ host,
8391
+ pathname,
8392
+ resource: pcoMeta.resource,
8393
+ search,
8394
+ ...config.params
8395
+ };
8396
+ });
8397
+ // The drawer keeps the page mounted while it's closed, and single-page apps
8398
+ // can navigate meanwhile, so the page hears where the user is on each open
8399
+ // and whenever the host page's pco: meta tags change.
8400
+ React.useEffect(function tellThePageWhereTheUserIs() {
8401
+ var _a;
8402
+ if (!isReady || !isOpen) return;
8403
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8404
+ payload: hostContext(appName, pcoMeta),
8405
+ type: "HOST_CONTEXT_CHANGED"
8406
+ });
8407
+ }, [isOpen, isReady, appName, pcoMeta]);
8408
+ React.useEffect(function tellThePageWhetherItIsVisible() {
8409
+ var _a;
8410
+ if (!isReady) return;
8411
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8412
+ type: isOpen ? "PANE_VISIBLE" : "PANE_HIDDEN"
8413
+ });
8414
+ }, [isOpen, isReady]);
8415
+ React.useEffect(function tellThePageAboutStateChanges() {
8416
+ var _a;
8417
+ if (!isReady || !config.state) return;
8418
+ (_a = iframeRef.current) === null || _a === void 0 ? void 0 : _a.postMessage({
8419
+ payload: config.state,
8420
+ type: "TOOL_STATE_CHANGED"
8421
+ });
8422
+ }, [isReady, config.state]);
8423
+ const handleMessage = React.useCallback(message => {
8424
+ var _a;
8425
+ switch (message.type) {
8426
+ case "READY":
8427
+ return setIsReady(true);
8428
+ case "CLOSE_DRAWER":
8429
+ return closeDrawer();
8430
+ case "OPEN_DRAWER":
8431
+ return openDrawer();
8432
+ case "OPEN_TOOL":
8433
+ {
8434
+ const {
8435
+ path = "",
8436
+ tool
8437
+ } = (_a = message.payload) !== null && _a !== void 0 ? _a : {};
8438
+ if (tool) openTool(tool, path);
8439
+ return;
8440
+ }
8441
+ case "OPEN_PICOBOT":
8442
+ // Without the Picobot panel there's nowhere to send it.
8443
+ return openPicobot === null || openPicobot === void 0 ? void 0 : openPicobot(message.payload);
8444
+ case "TRACK_PENDO":
8445
+ return trackPendo(message.payload);
8446
+ case "IFRAME_LOAD_ERROR":
8447
+ console.warn(`topbar: ${config.title} iframe failed to load`);
8448
+ return setErrored(true);
8449
+ }
8450
+ }, [closeDrawer, config.title, openDrawer, openPicobot, openTool]);
8451
+ const handleRetry = React.useCallback(() => {
8452
+ setErrored(false);
8453
+ setIsReady(false);
8454
+ setMountKey(key => key + 1);
8455
+ }, []);
8456
+ if (errored) {
8457
+ return /*#__PURE__*/React.createElement(LoadError$1, {
8458
+ closeDrawer: closeDrawer,
8459
+ heading: config.heading,
8460
+ onRetry: handleRetry
8461
+ });
8462
+ }
8463
+ return /*#__PURE__*/React.createElement(tapestryReact.StackView, {
8464
+ flex: 1,
8465
+ axis: "vertical"
8466
+ }, !isReady && (/*#__PURE__*/React.createElement(DrawerHeader, {
8467
+ closeDrawer: closeDrawer
8468
+ }, /*#__PURE__*/React.createElement(DrawerHeading, null, config.heading))), /*#__PURE__*/React.createElement(ToolIframe, {
8469
+ key: mountKey,
8470
+ ref: iframeRef,
8471
+ basePath: config.basePath,
8472
+ currentPath: currentPath,
8473
+ isVisible: isOpen,
8474
+ onChangePath: onChangePath,
8475
+ onMessage: handleMessage,
8476
+ origin: origin,
8477
+ params: params,
8478
+ title: config.title
8479
+ }));
8480
+ }
8481
+ function LoadError$1({
8482
+ closeDrawer,
8483
+ heading,
8484
+ onRetry
8485
+ }) {
8486
+ return /*#__PURE__*/React.createElement(tapestryReact.StackView, {
8487
+ flex: 1,
8488
+ axis: "vertical"
8489
+ }, /*#__PURE__*/React.createElement(DrawerHeader, {
8490
+ closeDrawer: closeDrawer
8491
+ }, /*#__PURE__*/React.createElement(DrawerHeading, null, heading)), /*#__PURE__*/React.createElement(tapestryReact.StackView, {
8492
+ axis: "vertical",
8493
+ flex: 1,
8494
+ alignment: "center",
8495
+ distribution: "center",
8496
+ padding: 3,
8497
+ spacing: 1
8498
+ }, /*#__PURE__*/React.createElement(tapestryReact.Text, {
8499
+ size: 5,
8500
+ color: "var(--t-text-color-secondary)"
8501
+ }, "This couldn't load. Try again in a moment."), /*#__PURE__*/React.createElement(tapestryReact.Box, {
8502
+ paddingTop: 2
8503
+ }, /*#__PURE__*/React.createElement(tapestryReact.Button, {
8504
+ onClick: onRetry,
8505
+ iconLeft: "general.refresh",
8506
+ theme: "primary",
8507
+ variant: "fill",
8508
+ title: "Retry"
8509
+ }))));
8510
+ }
8511
+
8227
8512
  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"};
8228
8513
 
8229
8514
  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";
@@ -8819,7 +9104,46 @@ true;
8819
9104
  styles: styles
8820
9105
  })) : null;
8821
9106
  }
8822
- function HelpdeskComponent({
9107
+ function HelpdeskComponent(props) {
9108
+ return props.mountLegacy === false ? (/*#__PURE__*/React.createElement(HelpdeskIframe, {
9109
+ ...props
9110
+ })) : (/*#__PURE__*/React.createElement(HelpdeskAddOn, {
9111
+ ...props
9112
+ }));
9113
+ }
9114
+ function HelpdeskIframe(props) {
9115
+ var _a;
9116
+ const fetchZendeskDetails = (_a = props.helpdeskConfig) === null || _a === void 0 ? void 0 : _a.fetchZendeskDetails;
9117
+ const hasPicobotPanel = Boolean(props.openPicobot);
9118
+ const config = React.useMemo(() => ({
9119
+ app: "helpdesk",
9120
+ basePath: "/topbar/helpdesk",
9121
+ heading: "Help and support",
9122
+ params: {
9123
+ fetch_zendesk_details: fetchZendeskDetails ? "1" : null,
9124
+ // Tells helpdesk to send OPEN_PICOBOT rather than embed Ask AI.
9125
+ open_picobot: hasPicobotPanel ? "1" : null
9126
+ },
9127
+ // The gate can answer after the page loads, e.g. when userId arrives
9128
+ // late, so the page also hears about it here.
9129
+ state: {
9130
+ canOpenPicobot: hasPicobotPanel
9131
+ },
9132
+ title: "Help and support"
9133
+ }), [fetchZendeskDetails, hasPicobotPanel]);
9134
+ // The page reads its params once, so mounting before the gate answers
9135
+ // would leave out open_picobot for good.
9136
+ if (props.isPicobotLoading) {
9137
+ return /*#__PURE__*/React.createElement(DrawerHeader, {
9138
+ closeDrawer: props.closeDrawer
9139
+ }, /*#__PURE__*/React.createElement(DrawerHeading, null, "Help and support"));
9140
+ }
9141
+ return /*#__PURE__*/React.createElement(IframeTool, {
9142
+ ...props,
9143
+ config: config
9144
+ });
9145
+ }
9146
+ function HelpdeskAddOn({
8823
9147
  appName,
8824
9148
  closeDrawer,
8825
9149
  currentPath,
@@ -9697,7 +10021,25 @@ true;
9697
10021
  ...badge
9698
10022
  }));
9699
10023
  }
9700
- function TasksComponent({
10024
+ const TASKS_IFRAME_CONFIG = {
10025
+ app: "home",
10026
+ basePath: "/topbar/tasks",
10027
+ heading: "To do",
10028
+ title: "To do"
10029
+ };
10030
+ function TasksComponent(props) {
10031
+ return props.mountLegacy === false ? (
10032
+ /*#__PURE__*/
10033
+ // The iframe and Home's own pages share Home's origin and talk to each
10034
+ // other directly, so there's no worker to hand over.
10035
+ React.createElement(IframeTool, {
10036
+ ...props,
10037
+ config: TASKS_IFRAME_CONFIG
10038
+ })) : (/*#__PURE__*/React.createElement(TasksAddOn, {
10039
+ ...props
10040
+ }));
10041
+ }
10042
+ function TasksAddOn({
9701
10043
  closeDrawer,
9702
10044
  env,
9703
10045
  isOpen,
@@ -10138,6 +10480,8 @@ true;
10138
10480
  env,
10139
10481
  helpdeskConfig = {},
10140
10482
  linkToProfile = true,
10483
+ mountLegacyHelpdesk = true,
10484
+ mountLegacyTasks = true,
10141
10485
  onReceiveTasksWorker,
10142
10486
  requestClearAppsCache,
10143
10487
  userAvatarPath,
@@ -10382,6 +10726,7 @@ true;
10382
10726
  const toolSpecificProps = {
10383
10727
  Helpdesk: {
10384
10728
  isPicobotLoading: isPicobotGateLoading,
10729
+ mountLegacy: mountLegacyHelpdesk,
10385
10730
  openPicobot: displayPicobotIcon ? openPicobot : undefined
10386
10731
  },
10387
10732
  Profile: {
@@ -10397,6 +10742,7 @@ true;
10397
10742
  userAvatarPath
10398
10743
  },
10399
10744
  Tasks: {
10745
+ mountLegacy: mountLegacyTasks,
10400
10746
  onReceiveWorker: onReceiveTasksWorker
10401
10747
  }
10402
10748
  };