@planningcenter/topbar 12.6.0-rc.0 → 12.6.0

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,4 +1,4 @@
1
- import { Link, Button, Popover, PopoverTrigger, PopoverContent, Flex, Select, IconButton, Modal } from '@planningcenter/tapestry';
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
3
  import React__default, { useState, useEffect, useMemo, useLayoutEffect, useContext, createContext, useCallback, useRef } from 'react';
4
4
  import pcoUrl$1, { pcoUrl as pcoUrl$2, pcoApiUrl } from '@planningcenter/url';
@@ -10,7 +10,7 @@ import * as toolbar from '@planningcenter/icons/paths/toolbar';
10
10
  import datetimeFmt from '@planningcenter/datetime-fmt';
11
11
  import pluralize from 'pluralize';
12
12
  import * as logomarks from '@planningcenter/icons/paths/logomark';
13
- import { ThemeProvider, Divider, Button as Button$1, StackView as StackView$2, Text, Icon as Icon$1, designSystem, Box, Heading, GridView, Avatar as Avatar$1, Link as Link$1, HeadingUppercase, List, Combobox, Logo, Dropdown, Spinner, Badge } from '@planningcenter/tapestry-react';
13
+ import { ThemeProvider, Divider, Button as Button$1, StackView as StackView$2, Text, Icon as Icon$1, designSystem, Box, Heading, GridView, Avatar as Avatar$1, Link as Link$1, HeadingUppercase, List, Combobox, Logo, Dropdown as Dropdown$1, Spinner, Badge } from '@planningcenter/tapestry-react';
14
14
  import { components, UiExtensionFirstPartyComponent, UiExtensionDataContext } from '@planningcenter/add-ons';
15
15
  import * as churchCenter from '@planningcenter/icons/paths/church-center';
16
16
  import * as people from '@planningcenter/icons/paths/people';
@@ -3544,6 +3544,23 @@ function groupByType({
3544
3544
  };
3545
3545
  return [...groups.values()].sort((a, b) => rank(a.type) - rank(b.type));
3546
3546
  }
3547
+ const isBlankStateAction = action => typeof action === "object" && action !== null && "label" in action && "url" in action && typeof action.label === "string" && typeof action.url === "string" && (!("query_param" in action) || typeof action.query_param === "string");
3548
+ function blankStateActions({
3549
+ meta
3550
+ }) {
3551
+ const actions = meta === null || meta === void 0 ? void 0 : meta.blank_state_actions;
3552
+ return Array.isArray(actions) ? actions.filter(isBlankStateAction) : [];
3553
+ }
3554
+ // The product reads the search box's text from the action's `query_param`, to
3555
+ // fill in whatever it opens.
3556
+ function blankStateActionUrl({
3557
+ query_param = "search_term",
3558
+ url
3559
+ }, term) {
3560
+ const actionUrl = new URL(url);
3561
+ actionUrl.searchParams.set(query_param, term.trim());
3562
+ return actionUrl.toString();
3563
+ }
3547
3564
 
3548
3565
  function useDebouncedValue(value, delay) {
3549
3566
  const [debounced, setDebounced] = React__default.useState(value);
@@ -3566,6 +3583,7 @@ function useProductSearch(product, term) {
3566
3583
  // Services tab.
3567
3584
  const visibleResponse = request.status === "done" || settledProduct === product ? response : undefined;
3568
3585
  const groups = React__default.useMemo(() => visibleResponse && groupByType(visibleResponse), [visibleResponse]);
3586
+ const actions = React__default.useMemo(() => response ? blankStateActions(response) : [], [response]);
3569
3587
  if (!query) {
3570
3588
  return {
3571
3589
  status: "idle"
@@ -3577,6 +3595,7 @@ function useProductSearch(product, term) {
3577
3595
  };
3578
3596
  } else if (request.status === "done") {
3579
3597
  return {
3598
+ blankStateActions: actions,
3580
3599
  groups: groups !== null && groups !== void 0 ? groups : [],
3581
3600
  status: "done"
3582
3601
  };
@@ -4679,6 +4698,39 @@ function capitalize(word) {
4679
4698
  return word.charAt(0).toUpperCase() + word.slice(1);
4680
4699
  }
4681
4700
 
4701
+ // The first action is the button, and any others wait behind its caret.
4702
+ function BlankStateActions({
4703
+ actions,
4704
+ onOpen,
4705
+ term
4706
+ }) {
4707
+ const [primary, ...others] = actions;
4708
+ if (!primary) return null;
4709
+ const primaryLink = /*#__PURE__*/React__default.createElement(Link, {
4710
+ href: blankStateActionUrl(primary, term),
4711
+ kind: "neutral",
4712
+ label: primary.label,
4713
+ onClick: onOpen,
4714
+ prefix: /*#__PURE__*/React__default.createElement(Icon, {
4715
+ name: "general.plus"
4716
+ })
4717
+ });
4718
+ if (others.length === 0) return primaryLink;
4719
+ return /*#__PURE__*/React__default.createElement(ButtonGroup, {
4720
+ "aria-label": "Create"
4721
+ }, primaryLink, /*#__PURE__*/React__default.createElement(Dropdown, null, /*#__PURE__*/React__default.createElement(DropdownTrigger, null, /*#__PURE__*/React__default.createElement(DropdownIconButton, {
4722
+ "aria-label": "More to create",
4723
+ icon: null,
4724
+ kind: "neutral"
4725
+ })), /*#__PURE__*/React__default.createElement(DropdownMenu, {
4726
+ placement: "bottom start"
4727
+ }, others.map(action => (/*#__PURE__*/React__default.createElement(DropdownLink, {
4728
+ href: blankStateActionUrl(action, term),
4729
+ id: action.url,
4730
+ key: action.url
4731
+ }, action.label))))));
4732
+ }
4733
+
4682
4734
  var styles$j = {"container":"container-YDdM1","hint":"hint-017Rd","keycap":"keycap-ENJM2","labels":"labels-GHPqL","copied":"copied-DUFa1"};
4683
4735
 
4684
4736
  const SYMBOLS = {
@@ -5361,6 +5413,7 @@ function BlankStateRecentlyVisited(props) {
5361
5413
  var styles$f = {"blank_state":"blank_state-wMOWN","image":"image-uy0Fd"};
5362
5414
 
5363
5415
  function BlankState$1({
5416
+ action,
5364
5417
  image,
5365
5418
  role,
5366
5419
  subtitle,
@@ -5378,7 +5431,7 @@ function BlankState$1({
5378
5431
  direction: "column",
5379
5432
  align: "center",
5380
5433
  gap: 1
5381
- }, /*#__PURE__*/React__default.createElement("h2", null, title), /*#__PURE__*/React__default.createElement("p", null, subtitle)));
5434
+ }, /*#__PURE__*/React__default.createElement("h2", null, title), /*#__PURE__*/React__default.createElement("p", null, subtitle)), action);
5382
5435
  }
5383
5436
 
5384
5437
  function EndOfResultsObserver({
@@ -6059,6 +6112,7 @@ function LoadingSpinner({
6059
6112
 
6060
6113
  function SearchResults({
6061
6114
  label,
6115
+ noResultsAction,
6062
6116
  sections,
6063
6117
  status,
6064
6118
  term,
@@ -6102,6 +6156,7 @@ function SearchResults({
6102
6156
  if (sections.length === 0) {
6103
6157
  // The panel's result count announces this, so it isn't read twice.
6104
6158
  return /*#__PURE__*/React__default.createElement(BlankState$1, {
6159
+ action: noResultsAction,
6105
6160
  image: /*#__PURE__*/React__default.createElement(BlankStateNoResults, null),
6106
6161
  subtitle: "Clear search and try again.",
6107
6162
  title: `No results for “${term.trim()}”`
@@ -6158,6 +6213,20 @@ function SearchPanel({
6158
6213
  const inputRef = React__default.useRef(null);
6159
6214
  const resultCount = useAnnouncement(hasTerm && search.status === "done" ? `${items.length === 0 ? "No results" : `${items.length} ${items.length === 1 ? "result" : "results"}`} for “${term.trim()}” in ${product.appName}` : null);
6160
6215
  const [announceHighlight, setAnnounceHighlight] = React__default.useState(false);
6216
+ const blankStateActions = hasTerm && search.status === "done" && items.length === 0 ? search.blankStateActions : [];
6217
+ // With nothing to highlight, Enter takes the first thing the product offers
6218
+ // to create instead, the way the old People search added the person.
6219
+ const handleKeyDown = event => {
6220
+ const [action] = blankStateActions;
6221
+ if (event.key === "Enter" && action && !event.nativeEvent.isComposing) {
6222
+ event.preventDefault();
6223
+ open(blankStateActionUrl(action, term), {
6224
+ newTab: hasCommandKey(event)
6225
+ });
6226
+ } else {
6227
+ navigation.handleKeyDown(event);
6228
+ }
6229
+ };
6161
6230
  // The tabs keep focus while arrowing through results, but only the focused
6162
6231
  // input can point screen readers at the highlight, so from the tabs it's
6163
6232
  // announced instead. Typing goes back to the input, keystroke and all.
@@ -6167,15 +6236,20 @@ function SearchPanel({
6167
6236
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
6168
6237
  } else if (verticalStep(event.key)) {
6169
6238
  setAnnounceHighlight(true);
6170
- navigation.handleKeyDown(event);
6239
+ handleKeyDown(event);
6171
6240
  } else {
6172
- navigation.handleKeyDown(event);
6241
+ handleKeyDown(event);
6173
6242
  }
6174
6243
  };
6175
6244
  const results = hasTerm ? (/*#__PURE__*/React__default.createElement(SearchResults, {
6176
6245
  highlightedIndex: highlightedIndex,
6177
6246
  id: listboxId,
6178
6247
  label: `Results from Planning Center ${product.appName}`,
6248
+ noResultsAction: /*#__PURE__*/React__default.createElement(BlankStateActions, {
6249
+ actions: blankStateActions,
6250
+ onOpen: onOpenResult,
6251
+ term: term
6252
+ }),
6179
6253
  onHighlight: navigation.highlightIndex,
6180
6254
  onOpen: onOpenResult,
6181
6255
  sections: sections,
@@ -6197,7 +6271,7 @@ function SearchPanel({
6197
6271
  onChange: setTerm,
6198
6272
  onClose: onClose,
6199
6273
  onFocus: () => setAnnounceHighlight(false),
6200
- onKeyDown: navigation.handleKeyDown,
6274
+ onKeyDown: handleKeyDown,
6201
6275
  value: term
6202
6276
  }), mobile ? (/*#__PURE__*/React__default.createElement(ProductSelect, {
6203
6277
  onSelect: setSelectedSlug,
@@ -36706,7 +36780,7 @@ const NotificationItem = ({
36706
36780
  margin: 0,
36707
36781
  userSelect: "none"
36708
36782
  }
36709
- }, title)), !mobile && (/*#__PURE__*/React__default.createElement(Dropdown, {
36783
+ }, title)), !mobile && (/*#__PURE__*/React__default.createElement(Dropdown$1, {
36710
36784
  icon: {
36711
36785
  name: "general.threeDots"
36712
36786
  },
@@ -36717,19 +36791,19 @@ const NotificationItem = ({
36717
36791
  onClick: e => {
36718
36792
  e.stopPropagation();
36719
36793
  }
36720
- }, /*#__PURE__*/React__default.createElement(Dropdown.Item, {
36794
+ }, /*#__PURE__*/React__default.createElement(Dropdown$1.Item, {
36721
36795
  onClick: e => {
36722
36796
  e.preventDefault();
36723
36797
  e.stopPropagation();
36724
36798
  onToggleRead();
36725
36799
  }
36726
- }, "Mark ", isRead ? "unread" : "as read"), notification.taskUrl ? (/*#__PURE__*/React__default.createElement(Dropdown.Item, {
36800
+ }, "Mark ", isRead ? "unread" : "as read"), notification.taskUrl ? (/*#__PURE__*/React__default.createElement(Dropdown$1.Item, {
36727
36801
  onClick: e => {
36728
36802
  e.preventDefault();
36729
36803
  e.stopPropagation();
36730
36804
  window.location.href = notification.taskUrl;
36731
36805
  }
36732
- }, "Open task")) : (/*#__PURE__*/React__default.createElement(Dropdown.Item, {
36806
+ }, "Open task")) : (/*#__PURE__*/React__default.createElement(Dropdown$1.Item, {
36733
36807
  onClick: e => {
36734
36808
  e.preventDefault();
36735
36809
  e.stopPropagation();