@payloadcms/plugin-search 4.0.0-internal.4c792ad → 4.0.0-internal.4e1f822

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018-2025 Payload CMS, Inc. <info@payloadcms.com>
3
+ Copyright (c) 2018-2026 Payload CMS, LLC <info@payloadcms.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Search/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAM9D,eAAO,MAAM,wBAAwB,GACnC,cAAc,2BAA2B,KACxC,gBA0GF,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Search/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAM9D,eAAO,MAAM,wBAAwB,iBACrB,2BAA2B,KACxC,gBA0GF,CAAA"}
@@ -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"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAMpD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAqI5D,CAAA"}
1
+ {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAMpD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAsI5D,CAAA"}
@@ -10,6 +10,7 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
10
10
  const { config } = useConfig();
11
11
  const { i18n: { t } } = useTranslation();
12
12
  const locale = useLocale();
13
+ const localeCode = locale?.code;
13
14
  const router = useRouter();
14
15
  const [reindexCollections, setReindexCollections] = useState([]);
15
16
  const openConfirmModal = useCallback(()=>openModal(confirmReindexModalSlug), [
@@ -22,7 +23,7 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
22
23
  try {
23
24
  const res = await fetch(formatAdminURL({
24
25
  apiRoute: config.routes.api,
25
- path: `/${searchSlug}/reindex?locale=${locale.code}`
26
+ path: `/${searchSlug}/reindex${localeCode ? `?locale=${localeCode}` : ''}`
26
27
  }), {
27
28
  body: JSON.stringify({
28
29
  collections: reindexCollections
@@ -45,7 +46,7 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
45
46
  reindexCollections,
46
47
  router,
47
48
  searchSlug,
48
- locale,
49
+ localeCode,
49
50
  config
50
51
  ]);
51
52
  const handleShowConfirmModal = useCallback((collections = searchCollections)=>{
@@ -68,11 +69,11 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
68
69
  if (typeof label === 'string') {
69
70
  return label;
70
71
  } else {
71
- return label && Object.hasOwn(label, locale.code) ? label[locale.code] : slug;
72
+ return label && localeCode && Object.hasOwn(label, localeCode) ? label[localeCode] : slug;
72
73
  }
73
74
  }, [
74
75
  collectionLabels,
75
- locale.code
76
+ localeCode
76
77
  ]);
77
78
  const pluralizedLabels = useMemo(()=>{
78
79
  return searchCollections.reduce((acc, slug)=>{
@@ -97,7 +98,6 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
97
98
  return /*#__PURE__*/ _jsxs("div", {
98
99
  children: [
99
100
  /*#__PURE__*/ _jsx(Popup, {
100
- button: /*#__PURE__*/ _jsx(ReindexButtonLabel, {}),
101
101
  render: ({ close })=>/*#__PURE__*/ _jsxs(PopupList.ButtonGroup, {
102
102
  children: [
103
103
  searchCollections.map((collectionSlug)=>/*#__PURE__*/ _jsx(PopupList.Button, {
@@ -110,6 +110,9 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
110
110
  })
111
111
  ]
112
112
  }),
113
+ renderButton: (buttonProps)=>/*#__PURE__*/ _jsx(ReindexButtonLabel, {
114
+ ...buttonProps
115
+ }),
113
116
  showScrollbar: true,
114
117
  size: "large",
115
118
  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,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,GAA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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 localeCode = locale?.code\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${localeCode ? `?locale=${localeCode}` : ''}`,\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, localeCode, 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 && localeCode && Object.hasOwn(label, localeCode) ? label[localeCode] : slug\n }\n },\n [collectionLabels, localeCode],\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","localeCode","code","router","reindexCollections","setReindexCollections","openConfirmModal","handleReindexSubmit","length","res","fetch","apiRoute","routes","api","path","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,aAAaD,QAAQE;IAC3B,MAAMC,SAASpB;IAEf,MAAM,CAACqB,oBAAoBC,sBAAsB,GAAGhB,SAAmB,EAAE;IAEzE,MAAMiB,mBAAmBnB,YAAY,IAAMS,UAAUL,0BAA0B;QAACK;KAAU;IAE1F,MAAMW,sBAAsBpB,YAAY;QACtC,IAAI,CAACiB,mBAAmBI,MAAM,EAAE;YAC9B;QACF;QAEA,IAAI;YACF,MAAMC,MAAM,MAAMC,MAChBzB,eAAe;gBACb0B,UAAUd,OAAOe,MAAM,CAACC,GAAG;gBAC3BC,MAAM,CAAC,CAAC,EAAEnB,WAAW,QAAQ,EAAEM,aAAa,CAAC,QAAQ,EAAEA,YAAY,GAAG,IA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BAAkBc,MAAM;IAC1E,MAAM+B,iBAAiBnC,mBAAmBoC,GAAG,CAAC,CAACV,OAASK,gBAAgB,CAACL,KAAK,EAAEW,IAAI,CAAC;IAErF,MAAMC,aAAaJ,cACfvC,EAAE,+BACFA,EAAE,0BAA0B;QAAEmB,aAAaqB;IAAe;IAC9D,MAAMI,mBAAmBL,cACrBvC,EAAE,0CACFA,EAAE,qCAAqC;QAAEmB,aAAaqB;IAAe;IAEzE,qBACE,MAACK;;0BACC,KAACnE;gBACCoE,QAAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,MAACpE,UAAUqE,WAAW;;4BACnBrD,kBAAkB8C,GAAG,CAAC,CAACQ,+BACtB,KAACtE,UAAUuE,MAAM;oCAEfC,SAAS,IAAMtB,uBAAuBkB,OAAOE;8CAE5Cb,gBAAgB,CAACa,eAAe;mCAH5BA;0CAMT,KAACtE,UAAUuE,MAAM;gCAACC,SAAS,IAAMtB,uBAAuBkB;0CACrD/C,EAAE;;;;gBAIToD,cAAc,CAACC,4BAAgB,KAAC9D;wBAAoB,GAAG8D,WAAW;;gBAClEC,aAAa;gBACbC,MAAK;gBACLC,eAAc;;0BAEhB,KAAC/E;gBACCuC,MAAM4B;gBACNa,SAASd;gBACTe,WAAWlE;gBACXmE,WAAWnD;;;;AAInB,EAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { Config } from 'payload';
2
1
  import type { SearchPluginConfig } from './types.js';
3
- export declare const searchPlugin: <ConfigTypes = unknown>(incomingPluginConfig: SearchPluginConfig<ConfigTypes>) => (config: Config) => Config;
2
+ export declare const searchPlugin: (options: SearchPluginConfig) => import("payload").Plugin;
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA6B,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhE,OAAO,KAAK,EAA+B,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAQjF,eAAO,MAAM,YAAY,GACtB,WAAW,GAAG,OAAO,EAAE,sBAAsB,kBAAkB,CAAC,WAAW,CAAC,MAC5E,QAAQ,MAAM,KAAG,MA2EjB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA+B,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAQjF,eAAO,MAAM,YAAY,2DA8EvB,CAAA"}
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { definePlugin } from 'payload';
1
2
  import { deleteFromSearch } from './Search/hooks/deleteFromSearch.js';
2
3
  import { syncWithSearch } from './Search/hooks/syncWithSearch.js';
3
4
  import { generateSearchCollection } from './Search/index.js';
4
- export const searchPlugin = (incomingPluginConfig)=>(config)=>{
5
+ export const searchPlugin = definePlugin({
6
+ slug: '@payloadcms/plugin-search',
7
+ plugin: ({ config, options: incomingPluginConfig })=>{
5
8
  const { collections } = config;
6
9
  // If the user defines `localize` to either true or false, use that
7
10
  // Otherwise, set it based on if their config has localization enabled or disabled
@@ -62,6 +65,7 @@ export const searchPlugin = (incomingPluginConfig)=>(config)=>{
62
65
  };
63
66
  }
64
67
  return config;
65
- };
68
+ }
69
+ });
66
70
 
67
71
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, Config } from 'payload'\n\nimport type { SanitizedSearchPluginConfig, SearchPluginConfig } from './types.js'\n\nimport { deleteFromSearch } from './Search/hooks/deleteFromSearch.js'\nimport { syncWithSearch } from './Search/hooks/syncWithSearch.js'\nimport { generateSearchCollection } from './Search/index.js'\n\ntype CollectionAfterChangeHookArgs = Parameters<CollectionAfterChangeHook>[0]\n\nexport const searchPlugin =\n <ConfigTypes = unknown>(incomingPluginConfig: SearchPluginConfig<ConfigTypes>) =>\n (config: Config): Config => {\n const { collections } = config\n\n // If the user defines `localize` to either true or false, use that\n // Otherwise, set it based on if their config has localization enabled or disabled\n const shouldLocalize =\n typeof incomingPluginConfig.localize === 'boolean'\n ? incomingPluginConfig.localize\n : Boolean(config.localization)\n incomingPluginConfig.localize = shouldLocalize\n\n if (collections) {\n // O(1) slug lookup for enabled-collection checks; replaces an Array.indexOf in the\n // hook-attachment pass that was O(M) per collection.\n const enabledSlugSet = new Set(incomingPluginConfig.collections ?? [])\n\n const labels: Record<string, (typeof collections)[number]['labels']> = {}\n for (const collection of collections) {\n if (enabledSlugSet.has(collection.slug)) {\n labels[collection.slug] = collection.labels\n }\n }\n\n const pluginConfig: SanitizedSearchPluginConfig<ConfigTypes> = {\n // write any config defaults here\n deleteDrafts: true,\n labels,\n reindexBatchSize: incomingPluginConfig?.reindexBatchSize || 50,\n syncDrafts: false,\n ...incomingPluginConfig,\n }\n\n // add afterChange and afterDelete hooks to every search-enabled collection\n const collectionsWithSearchHooks = config?.collections\n ?.map((collection) => {\n const { hooks: existingHooks } = collection\n\n const isEnabled = enabledSlugSet.has(collection.slug)\n if (isEnabled) {\n return {\n ...collection,\n hooks: {\n ...collection.hooks,\n afterChange: [\n ...(existingHooks?.afterChange || []),\n async (args: CollectionAfterChangeHookArgs) => {\n await syncWithSearch({\n ...args,\n collection: collection.slug,\n pluginConfig,\n })\n },\n ],\n beforeDelete: [\n ...(existingHooks?.beforeDelete || []),\n deleteFromSearch(pluginConfig),\n ],\n },\n }\n }\n\n return collection\n })\n .filter(Boolean)\n\n return {\n ...config,\n collections: [\n ...(collectionsWithSearchHooks || []),\n generateSearchCollection(pluginConfig),\n ],\n }\n }\n\n return config\n }\n"],"names":["deleteFromSearch","syncWithSearch","generateSearchCollection","searchPlugin","incomingPluginConfig","config","collections","shouldLocalize","localize","Boolean","localization","enabledSlugSet","Set","labels","collection","has","slug","pluginConfig","deleteDrafts","reindexBatchSize","syncDrafts","collectionsWithSearchHooks","map","hooks","existingHooks","isEn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ACD;4BACDW,cAAc;mCACRJ,eAAeI,gBAAgB,EAAE;gCACrC5B,iBAAiBiB;6BAClB;wBACH;oBACF;gBACF;gBAEA,OAAOH;YACT,GACCe,OAAOpB;YAEV,OAAO;gBACL,GAAGJ,MAAM;gBACTC,aAAa;uBACPe,8BAA8B,EAAE;oBACpCnB,yBAAyBe;iBAC1B;YACH;QACF;QAEA,OAAOZ;IACT,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionAfterChangeHook } from 'payload'\n\nimport { definePlugin } from 'payload'\n\nimport type { SanitizedSearchPluginConfig, SearchPluginConfig } from './types.js'\n\nimport { deleteFromSearch } from './Search/hooks/deleteFromSearch.js'\nimport { syncWithSearch } from './Search/hooks/syncWithSearch.js'\nimport { generateSearchCollection } from './Search/index.js'\n\ntype CollectionAfterChangeHookArgs = Parameters<CollectionAfterChangeHook>[0]\n\nexport const searchPlugin = definePlugin<SearchPluginConfig>({\n slug: '@payloadcms/plugin-search',\n plugin: ({ config, options: incomingPluginConfig }) => {\n const { collections } = config\n\n // If the user defines `localize` to either true or false, use that\n // Otherwise, set it based on if their config has localization enabled or disabled\n const shouldLocalize =\n typeof incomingPluginConfig.localize === 'boolean'\n ? incomingPluginConfig.localize\n : Boolean(config.localization)\n incomingPluginConfig.localize = shouldLocalize\n\n if (collections) {\n // O(1) slug lookup for enabled-collection checks; replaces an Array.indexOf in the\n // hook-attachment pass that was O(M) per collection.\n const enabledSlugSet = new Set(incomingPluginConfig.collections ?? [])\n\n const labels: Record<string, (typeof collections)[number]['labels']> = {}\n for (const collection of collections) {\n if (enabledSlugSet.has(collection.slug)) {\n labels[collection.slug] = collection.labels\n }\n }\n\n const pluginConfig: SanitizedSearchPluginConfig = {\n // write any config defaults here\n deleteDrafts: true,\n labels,\n reindexBatchSize: incomingPluginConfig?.reindexBatchSize || 50,\n syncDrafts: false,\n ...incomingPluginConfig,\n }\n\n // add afterChange and afterDelete hooks to every search-enabled collection\n const collectionsWithSearchHooks = config?.collections\n ?.map((collection) => {\n const { hooks: existingHooks } = collection\n\n const isEnabled = enabledSlugSet.has(collection.slug)\n if (isEnabled) {\n return {\n ...collection,\n hooks: {\n ...collection.hooks,\n afterChange: [\n ...(existingHooks?.afterChange || []),\n async (args: CollectionAfterChangeHookArgs) => {\n await syncWithSearch({\n ...args,\n collection: collection.slug,\n pluginConfig,\n })\n },\n ],\n beforeDelete: [\n ...(existingHooks?.beforeDelete || []),\n deleteFromSearch(pluginConfig),\n ],\n },\n }\n }\n\n return collection\n })\n .filter(Boolean)\n\n return {\n ...config,\n collections: [\n ...(collectionsWithSearchHooks || []),\n generateSearchCollection(pluginConfig),\n ],\n }\n }\n\n return config\n },\n})\n"],"names":["definePlugin","deleteFromSearch","syncWithSearch","generateSearchCollection","searchPlugin","slug","plugin","config","options","incomingPluginConfig","collections","shouldLocalize","localize","Boolean","localization","enabledSlugSet","Set","labels","collection","has","pluginConfig","deleteDrafts","reindexBatchSize","syncDrafts","collectionsWithSearchHooks","map","hooks","existingHooks","isEnabled","afterChange","args","beforeDelete","filter"],"mappings":"AAEA,SAASA,YAAY,QAAQ,UAAS;AAItC,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,wBAAwB,QAAQ,oBAAmB;AAI5D,OAAO,MAAMC,eAAeJ,aAAiC;IAC3DK,MAAM;IACNC,QAAQ,CAAC,EAAEC,MAAM,EAAEC,SAASC,oBAAoB,EAAE;QAChD,MAAM,EAAEC,WAAW,EAAE,GAAGH;QAExB,mEAAmE;QACnE,kFAAkF;QAClF,MAAMI,iBACJ,OAAOF,qBAAqBG,QAAQ,KAAK,YACrCH,qBAAqBG,QAAQ,GAC7BC,QAAQN,OAAOO,YAAY;QACjCL,qBAAqBG,QAAQ,GAAGD;QAEhC,IAAID,aAAa;YACf,mFAAmF;YACnF,qDAAqD;YACrD,MAAMK,iBAAiB,IAAIC,IAAIP,qBAAqBC,WAAW,IAAI,EAAE;YAErE,MAAMO,SAAiE,CAAC;YACxE,KAAK,MAAMC,cAAcR,YAAa;gBACpC,IAAIK,eAAeI,GAAG,CAACD,WAAWb,IAAI,GAAG;oBACvCY,MAAM,CAACC,WAAWb,IAAI,CAAC,GAAGa,WAAWD,MAAM;gBAC7C;YACF;YAEA,MAAMG,eAA4C;gBAChD,iCAAiC;gBACjCC,cAAc;gBACdJ;gBACAK,kBAAkBb,sBAAsBa,oBAAoB;gBAC5DC,YAAY;gBACZ,GAAGd,oBAAoB;YACzB;YAEA,2EAA2E;YAC3E,MAAMe,6BAA6BjB,QAAQG,aACvCe,IAAI,CAACP;gBACL,MAAM,EAAEQ,OAAOC,aAAa,EAAE,GAAGT;gBAEjC,MAAMU,YAAYb,eAAeI,GAAG,CAACD,WAAWb,IAAI;gBACpD,IAAIuB,WAAW;oBACb,OAAO;wBACL,GAAGV,UAAU;wBACbQ,OAAO;4BACL,GAAGR,WAAWQ,KAAK;4BACnBG,aAAa;mCACPF,eAAeE,eAAe,EAAE;gCACpC,OAAOC;oCACL,MAAM5B,eAAe;wCACnB,GAAG4B,IAAI;wCACPZ,YAAYA,WAAWb,IAAI;wCAC3Be;oCACF;gCACF;6BACD;4BACDW,cAAc;mCACRJ,eAAeI,gBAAgB,EAAE;gCACrC9B,iBAAiBmB;6BAClB;wBACH;oBACF;gBACF;gBAEA,OAAOF;YACT,GACCc,OAAOnB;YAEV,OAAO;gBACL,GAAGN,MAAM;gBACTG,aAAa;uBACPc,8BAA8B,EAAE;oBACpCrB,yBAAyBiB;iBAC1B;YACH;QACF;QAEA,OAAOb;IACT;AACF,GAAE"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CollectionAfterChangeHook, CollectionBeforeDeleteHook, CollectionConfig, Field, Locale, Payload, PayloadRequest, StaticLabel } from 'payload';
1
+ import type { CollectionAfterChangeHook, CollectionBeforeDeleteHook, CollectionConfig, Field, Locale, Payload, PayloadRequest, StaticLabel, TypedLocale } from 'payload';
2
2
  export type DocToSync = {
3
3
  [key: string]: any;
4
4
  doc: {
@@ -19,15 +19,13 @@ export type BeforeSync = (args: {
19
19
  export type FieldsOverride = (args: {
20
20
  defaultFields: Field[];
21
21
  }) => Field[];
22
- export type SkipSyncFunction<ConfigTypes = unknown> = (args: {
22
+ export type SkipSyncFunction = (args: {
23
23
  collectionSlug: string;
24
24
  doc: any;
25
- locale: ConfigTypes extends {
26
- locale: unknown;
27
- } ? ConfigTypes['locale'] : string | undefined;
25
+ locale: TypedLocale | undefined;
28
26
  req: PayloadRequest;
29
27
  }) => boolean | Promise<boolean>;
30
- export type SearchPluginConfig<ConfigTypes = unknown> = {
28
+ export type SearchPluginConfig = {
31
29
  beforeSync?: BeforeSync;
32
30
  collections?: string[];
33
31
  defaultPriorities?: {
@@ -69,7 +67,7 @@ export type SearchPluginConfig<ConfigTypes = unknown> = {
69
67
  * return !tenant.allowedLocales.includes(locale)
70
68
  * }
71
69
  */
72
- skipSync?: SkipSyncFunction<ConfigTypes>;
70
+ skipSync?: SkipSyncFunction;
73
71
  /**
74
72
  * Controls whether drafts are synced to the search index
75
73
  *
@@ -83,13 +81,13 @@ export type CollectionLabels = {
83
81
  export type ResolvedCollectionLabels = {
84
82
  [collection: string]: StaticLabel;
85
83
  };
86
- export type SearchPluginConfigWithLocales<ConfigTypes = unknown> = {
84
+ export type SearchPluginConfigWithLocales = {
87
85
  labels?: CollectionLabels;
88
- } & SearchPluginConfig<ConfigTypes>;
89
- export type SanitizedSearchPluginConfig<ConfigTypes = unknown> = {
86
+ } & SearchPluginConfig;
87
+ export type SanitizedSearchPluginConfig = {
90
88
  reindexBatchSize: number;
91
89
  syncDrafts: boolean;
92
- } & SearchPluginConfigWithLocales<ConfigTypes>;
90
+ } & SearchPluginConfigWithLocales;
93
91
  export type SyncWithSearchArgs = {
94
92
  collection: string;
95
93
  pluginConfig: SanitizedSearchPluginConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["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AED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,CAAC,EAAE,gBAAgB,CAAA;CAC1B,GAAG,kBAAkB,CAAA;AAEtB,MAAM,MAAM,2BAA2B,GAAG;IACxC,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,OAAO,CAAA;CACpB,GAAG,6BAA6B,CAAA;AAEjC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,2BAA2B,CAAA;CAC1C,GAAG,IAAI,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;AAEhE,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;CACzB,GAAG,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,aAAa,CAAC,CAAA;AAIvD,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,kBAAkB,KAAK,UAAU,CAAC,yBAAyB,CAAC,CAAA;AAEhG,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,kBAAkB,KAAK,0BAA0B,CAAA"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeDeleteHook,\n CollectionConfig,\n Field,\n Locale,\n Payload,\n PayloadRequest,\n StaticLabel,\n} from 'payload'\n\nexport type DocToSync = {\n [key: string]: any\n doc: {\n relationTo: string\n value: string\n }\n title: string\n}\n\nexport type BeforeSync = (args: {\n collectionSlug: string\n originalDoc: {\n [key: string]: any\n }\n payload: Payload\n req: PayloadRequest\n searchDoc: DocToSync\n}) => DocToSync | Promise<DocToSync>\n\nexport type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]\n\nexport type SkipSyncFunction<ConfigTypes = unknown> = (args: {\n collectionSlug: string\n doc: any\n locale: ConfigTypes extends { locale: unknown } ? ConfigTypes['locale'] : string | undefined\n req: PayloadRequest\n}) => boolean | Promise<boolean>\n\nexport type SearchPluginConfig<ConfigTypes = unknown> = {\n beforeSync?: BeforeSync\n collections?: string[]\n defaultPriorities?: {\n [collection: string]: ((doc: any) => number | Promise<number>) | number\n }\n /**\n * Controls whether drafts are deleted from the search index\n *\n * @default true\n */\n deleteDrafts?: boolean\n localize?: boolean\n /**\n * We use batching when re-indexing large collections. You can control the amount of items per batch, lower numbers should help with memory.\n *\n * @default 50\n */\n reindexBatchSize?: number\n searchOverrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>\n /**\n * Determine whether to skip syncing a document for a specific locale.\n * Useful for multi-tenant applications, conditional indexing, or any scenario where\n * sync behavior should vary by locale, document, or other factors.\n *\n * @default undefined - All configured locales will be synced\n *\n * @example\n * // Skip syncing based on document's tenant settings\n * skipSync: async ({ locale, req, doc, collectionSlug }) => {\n * // For non-localized collections, locale will be undefined\n * if (!locale) return false\n *\n * const tenant = await req.payload.findByID({\n * collection: 'tenants',\n * id: doc.tenant.id\n * })\n * return !tenant.allowedLocales.includes(locale)\n * }\n */\n skipSync?: SkipSyncFunction<ConfigTypes>\n /**\n * Controls whether drafts are synced to the search index\n *\n * @default false\n */\n syncDrafts?: boolean\n}\n\nexport type CollectionLabels = {\n [collection: string]: CollectionConfig['labels']\n}\n\nexport type ResolvedCollectionLabels = {\n [collection: string]: StaticLabel\n}\n\nexport type SearchPluginConfigWithLocales<ConfigTypes = unknown> = {\n labels?: CollectionLabels\n} & SearchPluginConfig<ConfigTypes>\n\nexport type SanitizedSearchPluginConfig<ConfigTypes = unknown> = {\n reindexBatchSize: number\n syncDrafts: boolean\n} & SearchPluginConfigWithLocales<ConfigTypes>\n\nexport type SyncWithSearchArgs = {\n collection: string\n pluginConfig: SanitizedSearchPluginConfig\n} & Omit<Parameters<CollectionAfterChangeHook>[0], 'collection'>\n\nexport type SyncDocArgs = {\n locale?: Locale['code']\n onSyncError?: () => void\n} & Omit<SyncWithSearchArgs, 'context' | 'previousDoc'>\n\n// Extend the `CollectionAfterChangeHook` with more function args\n// Convert the `collection` arg from `SanitizedCollectionConfig` to a string\nexport type SyncWithSearch = (Args: SyncWithSearchArgs) => ReturnType<CollectionAfterChangeHook>\n\nexport type DeleteFromSearch = (args: SearchPluginConfig) => CollectionBeforeDeleteHook\n"],"names":[],"mappings":"AAuHA,WAAuF"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionBeforeDeleteHook,\n CollectionConfig,\n Field,\n Locale,\n Payload,\n PayloadRequest,\n StaticLabel,\n TypedLocale,\n} from 'payload'\n\nexport type DocToSync = {\n [key: string]: any\n doc: {\n relationTo: string\n value: string\n }\n title: string\n}\n\nexport type BeforeSync = (args: {\n collectionSlug: string\n originalDoc: {\n [key: string]: any\n }\n payload: Payload\n req: PayloadRequest\n searchDoc: DocToSync\n}) => DocToSync | Promise<DocToSync>\n\nexport type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]\n\nexport type SkipSyncFunction = (args: {\n collectionSlug: string\n doc: any\n locale: TypedLocale | undefined\n req: PayloadRequest\n}) => boolean | Promise<boolean>\n\nexport type SearchPluginConfig = {\n beforeSync?: BeforeSync\n collections?: string[]\n defaultPriorities?: {\n [collection: string]: ((doc: any) => number | Promise<number>) | number\n }\n /**\n * Controls whether drafts are deleted from the search index\n *\n * @default true\n */\n deleteDrafts?: boolean\n localize?: boolean\n /**\n * We use batching when re-indexing large collections. You can control the amount of items per batch, lower numbers should help with memory.\n *\n * @default 50\n */\n reindexBatchSize?: number\n searchOverrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>\n /**\n * Determine whether to skip syncing a document for a specific locale.\n * Useful for multi-tenant applications, conditional indexing, or any scenario where\n * sync behavior should vary by locale, document, or other factors.\n *\n * @default undefined - All configured locales will be synced\n *\n * @example\n * // Skip syncing based on document's tenant settings\n * skipSync: async ({ locale, req, doc, collectionSlug }) => {\n * // For non-localized collections, locale will be undefined\n * if (!locale) return false\n *\n * const tenant = await req.payload.findByID({\n * collection: 'tenants',\n * id: doc.tenant.id\n * })\n * return !tenant.allowedLocales.includes(locale)\n * }\n */\n skipSync?: SkipSyncFunction\n /**\n * Controls whether drafts are synced to the search index\n *\n * @default false\n */\n syncDrafts?: boolean\n}\n\nexport type CollectionLabels = {\n [collection: string]: CollectionConfig['labels']\n}\n\nexport type ResolvedCollectionLabels = {\n [collection: string]: StaticLabel\n}\n\nexport type SearchPluginConfigWithLocales = {\n labels?: CollectionLabels\n} & SearchPluginConfig\n\nexport type SanitizedSearchPluginConfig = {\n reindexBatchSize: number\n syncDrafts: boolean\n} & SearchPluginConfigWithLocales\n\nexport type SyncWithSearchArgs = {\n collection: string\n pluginConfig: SanitizedSearchPluginConfig\n} & Omit<Parameters<CollectionAfterChangeHook>[0], 'collection'>\n\nexport type SyncDocArgs = {\n locale?: Locale['code']\n onSyncError?: () => void\n} & Omit<SyncWithSearchArgs, 'context' | 'previousDoc'>\n\n// Extend the `CollectionAfterChangeHook` with more function args\n// Convert the `collection` arg from `SanitizedCollectionConfig` to a string\nexport type SyncWithSearch = (Args: SyncWithSearchArgs) => ReturnType<CollectionAfterChangeHook>\n\nexport type DeleteFromSearch = (args: SearchPluginConfig) => CollectionBeforeDeleteHook\n"],"names":[],"mappings":"AAwHA,WAAuF"}
@@ -1 +1 @@
1
- {"version":3,"file":"generateReindexHandler.d.ts","sourceRoot":"","sources":["../../src/utilities/generateReindexHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,SAAS,CAAA;AAWpD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAS9D,eAAO,MAAM,sBAAsB,GAChC,cAAc,2BAA2B,KAAG,cAyN5C,CAAA"}
1
+ {"version":3,"file":"generateReindexHandler.d.ts","sourceRoot":"","sources":["../../src/utilities/generateReindexHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,SAAS,CAAA;AAWpD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAS9D,eAAO,MAAM,sBAAsB,iBAClB,2BAA2B,KAAG,cAyN5C,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"syncDocAsSearchIndex.d.ts","sourceRoot":"","sources":["../../src/utilities/syncDocAsSearchIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,oBAAoB,GAAU,2FASxC,WAAW,iBAgRb,CAAA"}
1
+ {"version":3,"file":"syncDocAsSearchIndex.d.ts","sourceRoot":"","sources":["../../src/utilities/syncDocAsSearchIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,oBAAoB,8FAS9B,WAAW,iBAgRb,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-search",
3
- "version": "4.0.0-internal.4c792ad",
3
+ "version": "4.0.0-internal.4e1f822",
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/next": "4.0.0-internal.4c792ad",
54
- "@payloadcms/ui": "4.0.0-internal.4c792ad"
53
+ "@payloadcms/next": "4.0.0-internal.4e1f822",
54
+ "@payloadcms/ui": "4.0.0-internal.4e1f822"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/react": "19.2.14",
58
58
  "@types/react-dom": "19.2.3",
59
- "payload": "4.0.0-internal.4c792ad",
60
- "@payloadcms/eslint-config": "3.28.0"
59
+ "@payloadcms/eslint-config": "3.28.0",
60
+ "payload": "4.0.0-internal.4e1f822"
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-internal.4c792ad"
65
+ "payload": "4.0.0-internal.4e1f822"
66
66
  },
67
67
  "publishConfig": {
68
68
  "registry": "https://registry.npmjs.org/"