@payloadcms/plugin-search 4.0.0-canary.5 → 4.0.0-canary.6

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,3 +1,4 @@
1
1
  import React from 'react';
2
+ import './index.css';
2
3
  export declare const LinkToDocClient: React.FC;
3
4
  //# sourceMappingURL=index.client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAgDnC,CAAA"}
1
+ {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,aAAa,CAAA;AAIpB,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAmCnC,CAAA"}
@@ -1,8 +1,10 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { CopyToClipboard, Link, useConfig, useField } from '@payloadcms/ui';
3
+ import { CopyToClipboard, FieldLabel, Link, useConfig, useField } from '@payloadcms/ui';
4
4
  import { formatAdminURL } from 'payload/shared';
5
5
  import React from 'react';
6
+ import './index.css';
7
+ const baseClass = 'link-to-doc';
6
8
  export const LinkToDocClient = ()=>{
7
9
  const { config } = useConfig();
8
10
  const { routes: { admin: adminRoute }, serverURL } = config;
@@ -18,18 +20,14 @@ export const LinkToDocClient = ()=>{
18
20
  serverURL
19
21
  });
20
22
  return /*#__PURE__*/ _jsxs("div", {
21
- style: {
22
- marginBottom: 'var(--spacing-field, 1rem)'
23
- },
23
+ className: baseClass,
24
24
  children: [
25
25
  /*#__PURE__*/ _jsxs("div", {
26
+ className: `${baseClass}__header`,
26
27
  children: [
27
- /*#__PURE__*/ _jsx("span", {
28
- className: "label",
29
- style: {
30
- color: '#9A9A9A'
31
- },
32
- children: "Doc URL"
28
+ /*#__PURE__*/ _jsx(FieldLabel, {
29
+ htmlFor: baseClass,
30
+ label: "Doc URL"
33
31
  }),
34
32
  /*#__PURE__*/ _jsx(CopyToClipboard, {
35
33
  value: href
@@ -37,11 +35,7 @@ export const LinkToDocClient = ()=>{
37
35
  ]
38
36
  }),
39
37
  /*#__PURE__*/ _jsx("div", {
40
- style: {
41
- fontWeight: '600',
42
- overflow: 'hidden',
43
- textOverflow: 'ellipsis'
44
- },
38
+ className: `${baseClass}__url`,
45
39
  children: /*#__PURE__*/ _jsx(Link, {
46
40
  href: href,
47
41
  rel: "noopener noreferrer",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"sourcesContent":["'use client'\n\nimport { CopyToClipboard, Link, useConfig, useField } from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nexport const LinkToDocClient: React.FC = () => {\n const { config } = useConfig()\n\n const {\n routes: {\n admin: adminRoute, // already includes leading slash\n },\n serverURL,\n } = config\n\n const { value } = useField<{ relationTo?: string; value?: string }>({ path: 'doc' })\n\n if (!value?.relationTo || !value?.value) {\n return null\n }\n\n const href = formatAdminURL({\n adminRoute,\n path: `/collections/${value.relationTo || ''}/${value.value || ''}`,\n serverURL,\n })\n\n return (\n <div style={{ marginBottom: 'var(--spacing-field, 1rem)' }}>\n <div>\n <span\n className=\"label\"\n style={{\n color: '#9A9A9A',\n }}\n >\n Doc URL\n </span>\n <CopyToClipboard value={href} />\n </div>\n <div\n style={{\n fontWeight: '600',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n <Link href={href} rel=\"noopener noreferrer\" target=\"_blank\">\n {href}\n </Link>\n </div>\n </div>\n )\n}\n"],"names":["CopyToClipboard","Link","useConfig","useField","formatAdminURL","React","LinkToDocClient","config","routes","admin","adminRoute","serverURL","value","path","relationTo","href","div","style","marginBottom","span","className","color","fontWeight","overflow","textOverflow","rel","target"],"mappings":"AAAA;;AAEA,SAASA,eAAe,EAAEC,IAAI,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,iBAAgB;AAC3E,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,WAAW,QAAO;AAEzB,OAAO,MAAMC,kBAA4B;IACvC,MAAM,EAAEC,MAAM,EAAE,GAAGL;IAEnB,MAAM,EACJM,QAAQ,EACNC,OAAOC,UAAU,EAClB,EACDC,SAAS,EACV,GAAGJ;IAEJ,MAAM,EAAEK,KAAK,EAAE,GAAGT,SAAkD;QAAEU,MAAM;IAAM;IAElF,IAAI,CAACD,OAAOE,cAAc,CAACF,OAAOA,OAAO;QACvC,OAAO;IACT;IAEA,MAAMG,OAAOX,eAAe;QAC1BM;QACAG,MAAM,CAAC,aAAa,EAAED,MAAME,UAAU,IAAI,GAAG,CAAC,EAAEF,MAAMA,KAAK,IAAI,IAAI;QACnED;IACF;IAEA,qBACE,MAACK;QAAIC,OAAO;YAAEC,cAAc;QAA6B;;0BACvD,MAACF;;kCACC,KAACG;wBACCC,WAAU;wBACVH,OAAO;4BACLI,OAAO;wBACT;kCACD;;kCAGD,KAACrB;wBAAgBY,OAAOG;;;;0BAE1B,KAACC;gBACCC,OAAO;oBACLK,YAAY;oBACZC,UAAU;oBACVC,cAAc;gBAChB;0BAEA,cAAA,KAACvB;oBAAKc,MAAMA;oBAAMU,KAAI;oBAAsBC,QAAO;8BAChDX;;;;;AAKX,EAAC"}
1
+ {"version":3,"sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"sourcesContent":["'use client'\n\nimport { CopyToClipboard, FieldLabel, Link, useConfig, useField } from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport './index.css'\n\nconst baseClass = 'link-to-doc'\n\nexport const LinkToDocClient: React.FC = () => {\n const { config } = useConfig()\n\n const {\n routes: {\n admin: adminRoute, // already includes leading slash\n },\n serverURL,\n } = config\n\n const { value } = useField<{ relationTo?: string; value?: string }>({ path: 'doc' })\n\n if (!value?.relationTo || !value?.value) {\n return null\n }\n\n const href = formatAdminURL({\n adminRoute,\n path: `/collections/${value.relationTo || ''}/${value.value || ''}`,\n serverURL,\n })\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <FieldLabel htmlFor={baseClass} label=\"Doc URL\" />\n <CopyToClipboard value={href} />\n </div>\n <div className={`${baseClass}__url`}>\n <Link href={href} rel=\"noopener noreferrer\" target=\"_blank\">\n {href}\n </Link>\n </div>\n </div>\n )\n}\n"],"names":["CopyToClipboard","FieldLabel","Link","useConfig","useField","formatAdminURL","React","baseClass","LinkToDocClient","config","routes","admin","adminRoute","serverURL","value","path","relationTo","href","div","className","htmlFor","label","rel","target"],"mappings":"AAAA;;AAEA,SAASA,eAAe,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,iBAAgB;AACvF,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,WAAW,QAAO;AAEzB,OAAO,cAAa;AAEpB,MAAMC,YAAY;AAElB,OAAO,MAAMC,kBAA4B;IACvC,MAAM,EAAEC,MAAM,EAAE,GAAGN;IAEnB,MAAM,EACJO,QAAQ,EACNC,OAAOC,UAAU,EAClB,EACDC,SAAS,EACV,GAAGJ;IAEJ,MAAM,EAAEK,KAAK,EAAE,GAAGV,SAAkD;QAAEW,MAAM;IAAM;IAElF,IAAI,CAACD,OAAOE,cAAc,CAACF,OAAOA,OAAO;QACvC,OAAO;IACT;IAEA,MAAMG,OAAOZ,eAAe;QAC1BO;QACAG,MAAM,CAAC,aAAa,EAAED,MAAME,UAAU,IAAI,GAAG,CAAC,EAAEF,MAAMA,KAAK,IAAI,IAAI;QACnED;IACF;IAEA,qBACE,MAACK;QAAIC,WAAWZ;;0BACd,MAACW;gBAAIC,WAAW,GAAGZ,UAAU,QAAQ,CAAC;;kCACpC,KAACN;wBAAWmB,SAASb;wBAAWc,OAAM;;kCACtC,KAACrB;wBAAgBc,OAAOG;;;;0BAE1B,KAACC;gBAAIC,WAAW,GAAGZ,UAAU,KAAK,CAAC;0BACjC,cAAA,KAACL;oBAAKe,MAAMA;oBAAMK,KAAI;oBAAsBC,QAAO;8BAChDN;;;;;AAKX,EAAC"}
@@ -0,0 +1,26 @@
1
+ @layer payload-default {
2
+ .link-to-doc {
3
+ margin-bottom: var(--spacing-field);
4
+ }
5
+
6
+ .link-to-doc__header {
7
+ display: flex;
8
+ align-items: center;
9
+ width: fit-content;
10
+ gap: var(--spacer-1);
11
+ }
12
+
13
+ .link-to-doc__url {
14
+ overflow: hidden;
15
+ font-weight: 600;
16
+ text-overflow: ellipsis;
17
+ }
18
+
19
+ .link-to-doc__url a {
20
+ color: var(--color-text-secondary);
21
+
22
+ &:hover {
23
+ color: var(--color-text);
24
+ }
25
+ }
26
+ }
@@ -1,2 +1,11 @@
1
- export declare const ReindexButtonLabel: () => import("react").JSX.Element;
1
+ import React from 'react';
2
+ type ReindexButtonLabelProps = {
3
+ readonly active?: boolean;
4
+ readonly 'aria-expanded'?: boolean;
5
+ readonly 'aria-haspopup'?: true;
6
+ readonly onClick?: React.MouseEventHandler;
7
+ readonly onKeyDown?: React.KeyboardEventHandler;
8
+ };
9
+ export declare const ReindexButtonLabel: React.FC<ReindexButtonLabelProps>;
10
+ export {};
2
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/Search/ui/ReindexButton/ReindexButtonLabel/index.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,mCAS9B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/Search/ui/ReindexButton/ReindexButtonLabel/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAA;IAClC,QAAQ,CAAC,eAAe,CAAC,EAAE,IAAI,CAAA;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAA;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAA;CAChD,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAuBhE,CAAA"}
@@ -1,12 +1,22 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Button, useTranslation } from '@payloadcms/ui';
3
- export const ReindexButtonLabel = ()=>{
2
+ import { Button, ChevronIcon, useTranslation } from '@payloadcms/ui';
3
+ import React from 'react';
4
+ export const ReindexButtonLabel = ({ active, onClick, onKeyDown, ...ariaProps })=>{
4
5
  const { i18n: { t } } = useTranslation();
5
6
  return /*#__PURE__*/ _jsx(Button, {
6
- buttonStyle: "pill",
7
- icon: "chevron",
7
+ buttonStyle: "secondary",
8
+ extraButtonProps: {
9
+ onKeyDown
10
+ },
11
+ icon: /*#__PURE__*/ _jsx(ChevronIcon, {
12
+ direction: active ? 'up' : 'down',
13
+ size: 16
14
+ }),
8
15
  iconPosition: "right",
16
+ onClick: onClick,
17
+ selected: active,
9
18
  size: "medium",
19
+ ...ariaProps,
10
20
  children: t('general:reindex')
11
21
  });
12
22
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/Search/ui/ReindexButton/ReindexButtonLabel/index.tsx"],"sourcesContent":["import { Button, ChevronIcon, useTranslation } from '@payloadcms/ui'\n\nexport const ReindexButtonLabel = () => {\n const {\n i18n: { t },\n } = useTranslation()\n return (\n <Button buttonStyle=\"pill\" icon=\"chevron\" iconPosition=\"right\" size=\"medium\">\n {t('general:reindex')}\n </Button>\n )\n}\n"],"names":["Button","useTranslation","ReindexButtonLabel","i18n","t","buttonStyle","icon","iconPosition","size"],"mappings":";AAAA,SAASA,MAAM,EAAeC,cAAc,QAAQ,iBAAgB;AAEpE,OAAO,MAAMC,qBAAqB;IAChC,MAAM,EACJC,MAAM,EAAEC,CAAC,EAAE,EACZ,GAAGH;IACJ,qBACE,KAACD;QAAOK,aAAY;QAAOC,MAAK;QAAUC,cAAa;QAAQC,MAAK;kBACjEJ,EAAE;;AAGT,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/Search/ui/ReindexButton/ReindexButtonLabel/index.tsx"],"sourcesContent":["import { Button, ChevronIcon, useTranslation } from '@payloadcms/ui'\nimport React from 'react'\n\ntype ReindexButtonLabelProps = {\n readonly active?: boolean\n readonly 'aria-expanded'?: boolean\n readonly 'aria-haspopup'?: true\n readonly onClick?: React.MouseEventHandler\n readonly onKeyDown?: React.KeyboardEventHandler\n}\n\nexport const ReindexButtonLabel: React.FC<ReindexButtonLabelProps> = ({\n active,\n onClick,\n onKeyDown,\n ...ariaProps\n}) => {\n const {\n i18n: { t },\n } = useTranslation()\n return (\n <Button\n buttonStyle=\"secondary\"\n extraButtonProps={{ onKeyDown }}\n icon={<ChevronIcon direction={active ? 'up' : 'down'} size={16} />}\n iconPosition=\"right\"\n onClick={onClick}\n selected={active}\n size=\"medium\"\n {...ariaProps}\n >\n {t('general:reindex')}\n </Button>\n )\n}\n"],"names":["Button","ChevronIcon","useTranslation","React","ReindexButtonLabel","active","onClick","onKeyDown","ariaProps","i18n","t","buttonStyle","extraButtonProps","icon","direction","size","iconPosition","selected"],"mappings":";AAAA,SAASA,MAAM,EAAEC,WAAW,EAAEC,cAAc,QAAQ,iBAAgB;AACpE,OAAOC,WAAW,QAAO;AAUzB,OAAO,MAAMC,qBAAwD,CAAC,EACpEC,MAAM,EACNC,OAAO,EACPC,SAAS,EACT,GAAGC,WACJ;IACC,MAAM,EACJC,MAAM,EAAEC,CAAC,EAAE,EACZ,GAAGR;IACJ,qBACE,KAACF;QACCW,aAAY;QACZC,kBAAkB;YAAEL;QAAU;QAC9BM,oBAAM,KAACZ;YAAYa,WAAWT,SAAS,OAAO;YAAQU,MAAM;;QAC5DC,cAAa;QACbV,SAASA;QACTW,UAAUZ;QACVU,MAAK;QACJ,GAAGP,SAAS;kBAEZE,EAAE;;AAGT,EAAC"}
@@ -97,7 +97,6 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
97
97
  return /*#__PURE__*/ _jsxs("div", {
98
98
  children: [
99
99
  /*#__PURE__*/ _jsx(Popup, {
100
- button: /*#__PURE__*/ _jsx(ReindexButtonLabel, {}),
101
100
  render: ({ close })=>/*#__PURE__*/ _jsxs(PopupList.ButtonGroup, {
102
101
  children: [
103
102
  searchCollections.map((collectionSlug)=>/*#__PURE__*/ _jsx(PopupList.Button, {
@@ -110,6 +109,9 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
110
109
  })
111
110
  ]
112
111
  }),
112
+ renderButton: (buttonProps)=>/*#__PURE__*/ _jsx(ReindexButtonLabel, {
113
+ ...buttonProps
114
+ }),
113
115
  showScrollbar: true,
114
116
  size: "large",
115
117
  verticalAlign: "bottom"
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n ConfirmationModal,\n Popup,\n PopupList,\n toast,\n useConfig,\n useLocale,\n useModal,\n useRouter,\n useTranslation,\n} from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { ReindexButtonProps } from './types.js'\n\nimport { ReindexButtonLabel } from './ReindexButtonLabel/index.js'\n\nconst confirmReindexModalSlug = 'confirm-reindex-modal'\n\nexport const ReindexButtonClient: React.FC<ReindexButtonProps> = ({\n collectionLabels,\n searchCollections,\n searchSlug,\n}) => {\n const { openModal } = useModal()\n\n const { config } = useConfig()\n\n const {\n i18n: { t },\n } = useTranslation()\n\n const locale = useLocale()\n const router = useRouter()\n\n const [reindexCollections, setReindexCollections] = useState<string[]>([])\n\n const openConfirmModal = useCallback(() => openModal(confirmReindexModalSlug), [openModal])\n\n const handleReindexSubmit = useCallback(async () => {\n if (!reindexCollections.length) {\n return\n }\n\n try {\n const res = await fetch(\n formatAdminURL({\n apiRoute: config.routes.api,\n path: `/${searchSlug}/reindex?locale=${locale.code}`,\n }),\n {\n body: JSON.stringify({\n collections: reindexCollections,\n }),\n method: 'POST',\n },\n )\n\n const { message } = (await res.json()) as { message: string }\n\n if (!res.ok) {\n toast.error(message)\n } else {\n toast.success(message)\n return router.refresh()\n }\n } catch (_err: unknown) {\n // swallow error, toast shown above\n } finally {\n setReindexCollections([])\n }\n }, [reindexCollections, router, searchSlug, locale, config])\n\n const handleShowConfirmModal = useCallback(\n (collections: string | string[] = searchCollections) => {\n setReindexCollections(typeof collections === 'string' ? [collections] : collections)\n openConfirmModal()\n },\n [openConfirmModal, searchCollections],\n )\n\n const handlePopupButtonClick = useCallback(\n (closePopup: () => void, slug?: string) => {\n closePopup()\n handleShowConfirmModal(slug)\n },\n [handleShowConfirmModal],\n )\n\n const getPluralizedLabel = useCallback(\n (slug: string) => {\n const label = collectionLabels[slug]\n if (typeof label === 'string') {\n return label\n } else {\n return label && Object.hasOwn(label, locale.code) ? label[locale.code] : slug\n }\n },\n [collectionLabels, locale.code],\n )\n\n const pluralizedLabels = useMemo(() => {\n return searchCollections.reduce<Record<string, string>>((acc, slug) => {\n const label = getPluralizedLabel(slug)\n if (label) {\n acc[slug] = label\n }\n return acc\n }, {})\n }, [searchCollections, getPluralizedLabel])\n\n const selectedAll = reindexCollections.length === searchCollections.length\n const selectedLabels = reindexCollections.map((slug) => pluralizedLabels[slug]).join(', ')\n\n const modalTitle = selectedAll\n ? t('general:confirmReindexAll')\n : t('general:confirmReindex', { collections: selectedLabels })\n const modalDescription = selectedAll\n ? t('general:confirmReindexDescriptionAll')\n : t('general:confirmReindexDescription', { collections: selectedLabels })\n\n return (\n <div>\n <Popup\n button={<ReindexButtonLabel />}\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {searchCollections.map((collectionSlug) => (\n <PopupList.Button\n key={collectionSlug}\n onClick={() => handlePopupButtonClick(close, collectionSlug)}\n >\n {pluralizedLabels[collectionSlug]}\n </PopupList.Button>\n ))}\n <PopupList.Button onClick={() => handlePopupButtonClick(close)}>\n {t('general:allCollections')}\n </PopupList.Button>\n </PopupList.ButtonGroup>\n )}\n showScrollbar\n size=\"large\"\n verticalAlign=\"bottom\"\n />\n <ConfirmationModal\n body={modalDescription}\n heading={modalTitle}\n modalSlug={confirmReindexModalSlug}\n onConfirm={handleReindexSubmit}\n />\n </div>\n )\n}\n"],"names":["ConfirmationModal","Popup","PopupList","toast","useConfig","useLocale","useModal","useRouter","useTranslation","formatAdminURL","React","useCallback","useMemo","useState","ReindexButtonLabel","confirmReindexModalSlug","ReindexButtonClient","collectionLabels","searchCollections","searchSlug","openModal","config","i18n","t","locale","router","reindexCollections","setReindexCollections","openConfirmModal","handleReindexSubmit","length","res","fetch","apiRoute","routes","api","path","code","body","JSON","stringify","collections","method","message","json","ok","error","success","refresh","_err","handleShowConfirmModal","handlePopupButtonClick","closePopup","slug","getPluralizedLabel","label","Object","hasOwn","pluralizedLabels","reduce","acc","selectedAll","selectedLabels","map","join","modalTitle","modalDescription","div","button","render","close","ButtonGroup","collectionSlug","Button","onClick","showScrollbar","size","verticalAlign","heading","modalSlug","onConfirm"],"mappings":"AAAA;;AAEA,SACEA,iBAAiB,EACjBC,KAAK,EACLC,SAAS,EACTC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAI7D,SAASC,kBAAkB,QAAQ,gCAA+B;AAElE,MAAMC,0BAA0B;AAEhC,OAAO,MAAMC,sBAAoD,CAAC,EAChEC,g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uBmB;0CACrD/C,EAAE;;;;gBAIToD,aAAa;gBACbC,MAAK;gBACLC,eAAc;;0BAEhB,KAAC7E;gBACCsC,MAAM4B;gBACNY,SAASb;gBACTc,WAAWhE;gBACXiE,WAAWnD;;;;AAInB,EAAC"}
1
+ {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n ConfirmationModal,\n Popup,\n PopupList,\n toast,\n useConfig,\n useLocale,\n useModal,\n useRouter,\n useTranslation,\n} from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { ReindexButtonProps } from './types.js'\n\nimport { ReindexButtonLabel } from './ReindexButtonLabel/index.js'\n\nconst confirmReindexModalSlug = 'confirm-reindex-modal'\n\nexport const ReindexButtonClient: React.FC<ReindexButtonProps> = ({\n collectionLabels,\n searchCollections,\n searchSlug,\n}) => {\n const { openModal } = useModal()\n\n const { config } = useConfig()\n\n const {\n i18n: { t },\n } = useTranslation()\n\n const locale = useLocale()\n const router = useRouter()\n\n const [reindexCollections, setReindexCollections] = useState<string[]>([])\n\n const openConfirmModal = useCallback(() => openModal(confirmReindexModalSlug), [openModal])\n\n const handleReindexSubmit = useCallback(async () => {\n if (!reindexCollections.length) {\n return\n }\n\n try {\n const res = await fetch(\n formatAdminURL({\n apiRoute: config.routes.api,\n path: `/${searchSlug}/reindex?locale=${locale.code}`,\n }),\n {\n body: JSON.stringify({\n collections: reindexCollections,\n }),\n method: 'POST',\n },\n )\n\n const { message } = (await res.json()) as { message: string }\n\n if (!res.ok) {\n toast.error(message)\n } else {\n toast.success(message)\n return router.refresh()\n }\n } catch (_err: unknown) {\n // swallow error, toast shown above\n } finally {\n setReindexCollections([])\n }\n }, [reindexCollections, router, searchSlug, locale, config])\n\n const handleShowConfirmModal = useCallback(\n (collections: string | string[] = searchCollections) => {\n setReindexCollections(typeof collections === 'string' ? [collections] : collections)\n openConfirmModal()\n },\n [openConfirmModal, searchCollections],\n )\n\n const handlePopupButtonClick = useCallback(\n (closePopup: () => void, slug?: string) => {\n closePopup()\n handleShowConfirmModal(slug)\n },\n [handleShowConfirmModal],\n )\n\n const getPluralizedLabel = useCallback(\n (slug: string) => {\n const label = collectionLabels[slug]\n if (typeof label === 'string') {\n return label\n } else {\n return label && Object.hasOwn(label, locale.code) ? label[locale.code] : slug\n }\n },\n [collectionLabels, locale.code],\n )\n\n const pluralizedLabels = useMemo(() => {\n return searchCollections.reduce<Record<string, string>>((acc, slug) => {\n const label = getPluralizedLabel(slug)\n if (label) {\n acc[slug] = label\n }\n return acc\n }, {})\n }, [searchCollections, getPluralizedLabel])\n\n const selectedAll = reindexCollections.length === searchCollections.length\n const selectedLabels = reindexCollections.map((slug) => pluralizedLabels[slug]).join(', ')\n\n const modalTitle = selectedAll\n ? t('general:confirmReindexAll')\n : t('general:confirmReindex', { collections: selectedLabels })\n const modalDescription = selectedAll\n ? t('general:confirmReindexDescriptionAll')\n : t('general:confirmReindexDescription', { collections: selectedLabels })\n\n return (\n <div>\n <Popup\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {searchCollections.map((collectionSlug) => (\n <PopupList.Button\n key={collectionSlug}\n onClick={() => handlePopupButtonClick(close, collectionSlug)}\n >\n {pluralizedLabels[collectionSlug]}\n </PopupList.Button>\n ))}\n <PopupList.Button onClick={() => handlePopupButtonClick(close)}>\n {t('general:allCollections')}\n </PopupList.Button>\n </PopupList.ButtonGroup>\n )}\n renderButton={(buttonProps) => <ReindexButtonLabel {...buttonProps} />}\n showScrollbar\n size=\"large\"\n verticalAlign=\"bottom\"\n />\n <ConfirmationModal\n body={modalDescription}\n heading={modalTitle}\n modalSlug={confirmReindexModalSlug}\n onConfirm={handleReindexSubmit}\n />\n </div>\n )\n}\n"],"names":["ConfirmationModal","Popup","PopupList","toast","useConfig","useLocale","useModal","useRouter","useTranslation","formatAdminURL","React","useCallback","useMemo","useState","ReindexButtonLabel","confirmReindexModalSlug","ReindexButtonClient","collectionLabels","searchCollections","searchSlug","openModal","config","i18n","t","locale","router","reindexCollections","setReindexCollections","openConfirmModal","handleReindexSubmit","length","res","fetch","apiRoute","routes","api","path","code","body","JSON","stringify","collections","method","message","json","ok","error","success","refresh","_err","handleShowConfirmModal","handlePopupButtonClick","closePopup","slug","getPluralizedLabel","label","Object","hasOwn","pluralizedLabels","reduce","acc","selectedAll","selectedLabels","map","join","modalTitle","modalDescription","div","render","close","ButtonGroup","collectionSlug","Button","onClick","renderButton","buttonProps","showScrollbar","size","verticalAlign","heading","modalSlug","onConfirm"],"mappings":"AAAA;;AAEA,SACEA,iBAAiB,EACjBC,KAAK,EACLC,SAAS,EACTC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,cAAc,QACT,iBAAgB;AACvB,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAI7D,SAASC,kBAAkB,QAAQ,gCAA+B;AAElE,MAAMC,0BAA0B;AAEhC,OAAO,MAAMC,sBAAoD,CAAC,EAChEC,gBAAgB,EAChBC,iBAAiB,EACjBC,UAAU,EACX;IACC,MAAM,EAAEC,SAAS,EAAE,GAAGd;IAEtB,MAAM,EAAEe,MAAM,EAAE,GAAGjB;IAEnB,MAAM,EACJkB,MAAM,EAAEC,CAAC,EAAE,EACZ,GAAGf;IAEJ,MAAMgB,SAASnB;IACf,MAAMoB,SAASlB;IAEf,MAAM,CAACmB,oBAAoBC,sBAAsB,GAAGd,SAAmB,EAAE;IAEzE,MAAMe,mBAAmBjB,YAAY,IAAMS,UAAUL,0BAA0B;QAACK;KAAU;IAE1F,MAAMS,sBAAsBlB,YAAY;QACtC,IAAI,CAACe,mBAAmBI,MAAM,EAAE;YAC9B;QACF;QAEA,IAAI;YACF,MAAMC,MAAM,MAAMC,MAChBvB,eAAe;gBACbwB,UAAUZ,OAAOa,MAAM,CAACC,GAAG;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ACT,GAAG,CAAC;IACN,GAAG;QAAC1C;QAAmBoC;KAAmB;IAE1C,MAAMO,cAAcnC,mBAAmBI,MAAM,KAAKZ,kBAAkBY,MAAM;IAC1E,MAAMgC,iBAAiBpC,mBAAmBqC,GAAG,CAAC,CAACV,OAASK,gBAAgB,CAACL,KAAK,EAAEW,IAAI,CAAC;IAErF,MAAMC,aAAaJ,cACftC,EAAE,+BACFA,EAAE,0BAA0B;QAAEkB,aAAaqB;IAAe;IAC9D,MAAMI,mBAAmBL,cACrBtC,EAAE,0CACFA,EAAE,qCAAqC;QAAEkB,aAAaqB;IAAe;IAEzE,qBACE,MAACK;;0BACC,KAAClE;gBACCmE,QAAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,MAACnE,UAAUoE,WAAW;;4BACnBpD,kBAAkB6C,GAAG,CAAC,CAACQ,+BACtB,KAACrE,UAAUsE,MAAM;oCAEfC,SAAS,IAAMtB,uBAAuBkB,OAAOE;8CAE5Cb,gBAAgB,CAACa,eAAe;mCAH5BA;0CAMT,KAACrE,UAAUsE,MAAM;gCAACC,SAAS,IAAMtB,uBAAuBkB;0CACrD9C,EAAE;;;;gBAITmD,cAAc,CAACC,4BAAgB,KAAC7D;wBAAoB,GAAG6D,WAAW;;gBAClEC,aAAa;gBACbC,MAAK;gBACLC,eAAc;;0BAEhB,KAAC9E;gBACCsC,MAAM4B;gBACNa,SAASd;gBACTe,WAAWjE;gBACXkE,WAAWpD;;;;AAInB,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-search",
3
- "version": "4.0.0-canary.5",
3
+ "version": "4.0.0-canary.6",
4
4
  "description": "Search plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -50,19 +50,19 @@
50
50
  "dist"
51
51
  ],
52
52
  "dependencies": {
53
- "@payloadcms/ui": "4.0.0-canary.5",
54
- "@payloadcms/next": "4.0.0-canary.5"
53
+ "@payloadcms/next": "4.0.0-canary.6",
54
+ "@payloadcms/ui": "4.0.0-canary.6"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/react": "19.2.14",
58
58
  "@types/react-dom": "19.2.3",
59
59
  "@payloadcms/eslint-config": "3.28.0",
60
- "payload": "4.0.0-canary.5"
60
+ "payload": "4.0.0-canary.6"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "react": "^19.0.1 || ^19.1.2 || ^19.2.1",
64
64
  "react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1",
65
- "payload": "4.0.0-canary.5"
65
+ "payload": "4.0.0-canary.6"
66
66
  },
67
67
  "publishConfig": {
68
68
  "registry": "https://registry.npmjs.org/"