@payloadcms/plugin-search 3.21.0-canary.c6481e1 → 3.21.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 +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,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAKhE,eAAO,MAAM,wBAAwB,iBACrB,6BAA6B,KAC1C,gBAuGF,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,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAMhE,eAAO,MAAM,wBAAwB,iBACrB,6BAA6B,KAC1C,gBAqGF,CAAA"}
@@ -1,7 +1,6 @@
1
1
  import { generateReindexHandler } from '../utilities/generateReindexHandler.js';
2
2
  // all settings can be overridden by the config
3
3
  export const generateSearchCollection = (pluginConfig)=>{
4
- const apiBasePath = pluginConfig?.apiBasePath || '/api';
5
4
  const searchSlug = pluginConfig?.searchOverrides?.slug || 'search';
6
5
  const searchCollections = pluginConfig?.collections || [];
7
6
  const collectionLabels = pluginConfig?.labels;
@@ -62,7 +61,6 @@ export const generateSearchCollection = (pluginConfig)=>{
62
61
  {
63
62
  path: '@payloadcms/plugin-search/client#ReindexButton',
64
63
  serverProps: {
65
- apiBasePath,
66
64
  collectionLabels,
67
65
  searchCollections,
68
66
  searchSlug
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Search/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { SearchPluginConfigWithLocales } from '../types.js'\n\nimport { generateReindexHandler } from '../utilities/generateReindexHandler.js'\n\n// all settings can be overridden by the config\nexport const generateSearchCollection = (\n pluginConfig: SearchPluginConfigWithLocales,\n): CollectionConfig => {\n const apiBasePath = pluginConfig?.apiBasePath || '/api'\n const searchSlug = pluginConfig?.searchOverrides?.slug || 'search'\n const searchCollections = pluginConfig?.collections || []\n const collectionLabels = pluginConfig?.labels\n\n const defaultFields: Field[] = [\n {\n name: 'title',\n type: 'text',\n admin: {\n readOnly: true,\n },\n localized: pluginConfig.localize,\n },\n {\n name: 'priority',\n type: 'number',\n admin: {\n position: 'sidebar',\n },\n },\n {\n name: 'doc',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n readOnly: true,\n },\n index: true,\n maxDepth: 0,\n relationTo: searchCollections,\n required: true,\n },\n {\n name: 'docUrl',\n type: 'ui',\n admin: {\n components: {\n Field: {\n path: '@payloadcms/plugin-search/client#LinkToDoc',\n },\n },\n position: 'sidebar',\n },\n },\n ]\n\n const newConfig: CollectionConfig = {\n ...(pluginConfig?.searchOverrides || {}),\n slug: searchSlug,\n access: {\n create: (): boolean => false,\n read: (): boolean => true,\n ...(pluginConfig?.searchOverrides?.access || {}),\n },\n admin: {\n components: {\n views: {\n list: {\n actions: [\n {\n path: '@payloadcms/plugin-search/client#ReindexButton',\n serverProps: {\n apiBasePath,\n collectionLabels,\n searchCollections,\n searchSlug,\n },\n },\n ],\n },\n },\n },\n defaultColumns: ['title'],\n description:\n 'This is a collection of automatically created search results. These results are used by the global site search and will be updated automatically as documents in the CMS are created or updated.',\n enableRichTextRelationship: false,\n useAsTitle: 'title',\n ...(pluginConfig?.searchOverrides?.admin || {}),\n },\n endpoints: [\n ...(pluginConfig?.searchOverrides?.endpoints || []),\n {\n handler: generateReindexHandler(pluginConfig),\n method: 'post',\n path: '/reindex',\n },\n ],\n fields:\n pluginConfig?.searchOverrides?.fields &&\n typeof pluginConfig?.searchOverrides?.fields === 'function'\n ? pluginConfig?.searchOverrides.fields({ defaultFields })\n : defaultFields,\n labels: {\n ...(pluginConfig?.searchOverrides?.labels || {\n plural: 'Search Results',\n singular: 'Search Result',\n }),\n },\n }\n\n return newConfig\n}\n"],"names":["generateReindexHandler","generateSearchCollection","pluginConfig","apiBasePath","searchSlug","searchOverrides","slug","searchCollections","collections","collectionLabels","labels","defaultFields","name","type","admin","readOnly","localized","localize","position","index","maxDepth","relationTo","required","components","Field","path","newConfig","access","create","read","views","list","actions","serverProps","defaultColumns","description","enableRichTextRelationship","useAsTitle","endpoints","handler","method","fields","plural","singular"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,yCAAwC;AAE/E,+CAA+C;AAC/C,OAAO,MAAMC,2BAA2B,CACtCC;IAEA,MAAMC,cAAcD,cAAcC,eAAe;IACjD,MAAMC,aAAaF,cAAcG,iBAAiBC,QAAQ;IAC1D,MAAMC,oBAAoBL,cAAcM,eAAe,EAAE;IACzD,MAAMC,mBAAmBP,cAAcQ;IAEvC,MAAMC,gBAAyB;QAC7B;YACEC,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,UAAU;YACZ;YACAC,WAAWd,aAAae,QAAQ;QAClC;QACA;YACEL,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLI,UAAU;YACZ;QACF;QACA;YACEN,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLI,UAAU;gBACVH,UAAU;YACZ;YACAI,OAAO;YACPC,UAAU;YACVC,YAAYd;YACZe,UAAU;QACZ;QACA;YACEV,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLS,YAAY;oBACVC,OAAO;wBACLC,MAAM;oBACR;gBACF;gBACAP,UAAU;YACZ;QACF;KACD;IAED,MAAMQ,YAA8B;QAClC,GAAIxB,cAAcG,mBAAmB,CAAC,CAAC;QACvCC,MAAMF;QACNuB,QAAQ;YACNC,QAAQ,IAAe;YACvBC,MAAM,IAAe;YACrB,GAAI3B,cAAcG,iBAAiBsB,UAAU,CAAC,CAAC;QACjD;QACAb,OAAO;YACLS,YAAY;gBACVO,OAAO;oBACLC,MAAM;wBACJC,SAAS;4BACP;gCACEP,MAAM;gCACNQ,aAAa;oCACX9B;oCACAM;oCACAF;oCACAH;gCACF;4BACF;yBACD;oBACH;gBACF;YACF;YACA8B,gBAAgB;gBAAC;aAAQ;YACzBC,aACE;YACFC,4BAA4B;YAC5BC,YAAY;YACZ,GAAInC,cAAcG,iBAAiBS,SAAS,CAAC,CAAC;QAChD;QACAwB,WAAW;eACLpC,cAAcG,iBAAiBiC,aAAa,EAAE;YAClD;gBACEC,SAASvC,uBAAuBE;gBAChCsC,QAAQ;gBACRf,MAAM;YACR;SACD;QACDgB,QACEvC,cAAcG,iBAAiBoC,UAC/B,OAAOvC,cAAcG,iBAAiBoC,WAAW,aAC7CvC,cAAcG,gBAAgBoC,OAAO;YAAE9B;QAAc,KACrDA;QACND,QAAQ;YACN,GAAIR,cAAcG,iBAAiBK,UAAU;gBAC3CgC,QAAQ;gBACRC,UAAU;YACZ,CAAC;QACH;IACF;IAEA,OAAOjB;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/Search/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { SearchPluginConfigWithLocales } from '../types.js'\nimport type { ReindexButtonServerProps } from './ui/ReindexButton/types.js'\n\nimport { generateReindexHandler } from '../utilities/generateReindexHandler.js'\n\n// all settings can be overridden by the config\nexport const generateSearchCollection = (\n pluginConfig: SearchPluginConfigWithLocales,\n): CollectionConfig => {\n const searchSlug = pluginConfig?.searchOverrides?.slug || 'search'\n const searchCollections = pluginConfig?.collections || []\n const collectionLabels = pluginConfig?.labels\n\n const defaultFields: Field[] = [\n {\n name: 'title',\n type: 'text',\n admin: {\n readOnly: true,\n },\n localized: pluginConfig.localize,\n },\n {\n name: 'priority',\n type: 'number',\n admin: {\n position: 'sidebar',\n },\n },\n {\n name: 'doc',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n readOnly: true,\n },\n index: true,\n maxDepth: 0,\n relationTo: searchCollections,\n required: true,\n },\n {\n name: 'docUrl',\n type: 'ui',\n admin: {\n components: {\n Field: {\n path: '@payloadcms/plugin-search/client#LinkToDoc',\n },\n },\n position: 'sidebar',\n },\n },\n ]\n\n const newConfig: CollectionConfig = {\n ...(pluginConfig?.searchOverrides || {}),\n slug: searchSlug,\n access: {\n create: (): boolean => false,\n read: (): boolean => true,\n ...(pluginConfig?.searchOverrides?.access || {}),\n },\n admin: {\n components: {\n views: {\n list: {\n actions: [\n {\n path: '@payloadcms/plugin-search/client#ReindexButton',\n serverProps: {\n collectionLabels,\n searchCollections,\n searchSlug,\n } satisfies ReindexButtonServerProps,\n },\n ],\n },\n },\n },\n defaultColumns: ['title'],\n description:\n 'This is a collection of automatically created search results. These results are used by the global site search and will be updated automatically as documents in the CMS are created or updated.',\n enableRichTextRelationship: false,\n useAsTitle: 'title',\n ...(pluginConfig?.searchOverrides?.admin || {}),\n },\n endpoints: [\n ...(pluginConfig?.searchOverrides?.endpoints || []),\n {\n handler: generateReindexHandler(pluginConfig),\n method: 'post',\n path: '/reindex',\n },\n ],\n fields:\n pluginConfig?.searchOverrides?.fields &&\n typeof pluginConfig?.searchOverrides?.fields === 'function'\n ? pluginConfig?.searchOverrides.fields({ defaultFields })\n : defaultFields,\n labels: {\n ...(pluginConfig?.searchOverrides?.labels || {\n plural: 'Search Results',\n singular: 'Search Result',\n }),\n },\n }\n\n return newConfig\n}\n"],"names":["generateReindexHandler","generateSearchCollection","pluginConfig","searchSlug","searchOverrides","slug","searchCollections","collections","collectionLabels","labels","defaultFields","name","type","admin","readOnly","localized","localize","position","index","maxDepth","relationTo","required","components","Field","path","newConfig","access","create","read","views","list","actions","serverProps","defaultColumns","description","enableRichTextRelationship","useAsTitle","endpoints","handler","method","fields","plural","singular"],"mappings":"AAKA,SAASA,sBAAsB,QAAQ,yCAAwC;AAE/E,+CAA+C;AAC/C,OAAO,MAAMC,2BAA2B,CACtCC;IAEA,MAAMC,aAAaD,cAAcE,iBAAiBC,QAAQ;IAC1D,MAAMC,oBAAoBJ,cAAcK,eAAe,EAAE;IACzD,MAAMC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gBACRC,UAAU;YACZ,CAAC;QACH;IACF;IAEA,OAAOjB;AACT,EAAC"}
@@ -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;AAIzB,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EA+CnC,CAAA"}
1
+ {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAiDnC,CAAA"}
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useConfig, useField } from '@payloadcms/ui';
3
+ import { CopyToClipboard, useConfig, useField } from '@payloadcms/ui';
4
4
  import { formatAdminURL } from '@payloadcms/ui/shared';
5
+ import LinkImport from 'next/link.js';
5
6
  import React from 'react';
6
- // TODO: fix this import to work in dev mode within the monorepo in a way that is backwards compatible with 1.x
7
- // import CopyToClipboard from 'payload/dist/admin/components/elements/CopyToClipboard'
7
+ const Link = LinkImport.default || LinkImport;
8
8
  export const LinkToDocClient = ()=>{
9
9
  const { config } = useConfig();
10
10
  const { routes: { admin: adminRoute }, serverURL } = config;
@@ -18,19 +18,25 @@ export const LinkToDocClient = ()=>{
18
18
  adminRoute,
19
19
  path: `/collections/${value.relationTo || ''}/${value.value || ''}`
20
20
  })}`;
21
+ const hrefToDisplay = `${process.env.NEXT_BASE_PATH || ''}${href}`;
21
22
  return /*#__PURE__*/ _jsxs("div", {
22
23
  style: {
23
24
  marginBottom: 'var(--spacing-field, 1rem)'
24
25
  },
25
26
  children: [
26
- /*#__PURE__*/ _jsx("div", {
27
- children: /*#__PURE__*/ _jsx("span", {
28
- className: "label",
29
- style: {
30
- color: '#9A9A9A'
31
- },
32
- children: "Doc URL"
33
- })
27
+ /*#__PURE__*/ _jsxs("div", {
28
+ children: [
29
+ /*#__PURE__*/ _jsx("span", {
30
+ className: "label",
31
+ style: {
32
+ color: '#9A9A9A'
33
+ },
34
+ children: "Doc URL"
35
+ }),
36
+ /*#__PURE__*/ _jsx(CopyToClipboard, {
37
+ value: hrefToDisplay
38
+ })
39
+ ]
34
40
  }),
35
41
  /*#__PURE__*/ _jsx("div", {
36
42
  style: {
@@ -38,10 +44,12 @@ export const LinkToDocClient = ()=>{
38
44
  overflow: 'hidden',
39
45
  textOverflow: 'ellipsis'
40
46
  },
41
- children: /*#__PURE__*/ _jsx("a", {
47
+ children: /*#__PURE__*/ _jsx(Link, {
42
48
  href: href,
43
- target: "_blank",
44
- children: href
49
+ passHref: true,
50
+ rel: 'noopener noreferrer',
51
+ target: '_blank',
52
+ children: hrefToDisplay
45
53
  })
46
54
  })
47
55
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"sourcesContent":["'use client'\n\nimport { useConfig, useField } from '@payloadcms/ui'\nimport { formatAdminURL } from '@payloadcms/ui/shared'\nimport React from 'react'\n// TODO: fix this import to work in dev mode within the monorepo in a way that is backwards compatible with 1.x\n// import CopyToClipboard from 'payload/dist/admin/components/elements/CopyToClipboard'\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 = `${serverURL}${formatAdminURL({\n adminRoute,\n path: `/collections/${value.relationTo || ''}/${value.value || ''}`,\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 <a href={href} target=\"_blank\">\n {href}\n </a>\n </div>\n </div>\n )\n}\n"],"names":["useConfig","useField","formatAdminURL","React","LinkToDocClient","config","routes","admin","adminRoute","serverURL","value","path","relationTo","href","div","style","marginBottom","span","className","color","fontWeight","overflow","textOverflow","a","target"],"mappings":"AAAA;;AAEA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,iBAAgB;AACpD,SAASC,cAAc,QAAQ,wBAAuB;AACtD,OAAOC,WAAW,QAAO;AACzB,+GAA+G;AAC/G,uFAAuF;AAEvF,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,OAAO,GAAGJ,YAAYP,eAAe;QACzCM;QACAG,MAAM,CAAC,aAAa,EAAED,MAAME,UAAU,IAAI,GAAG,CAAC,EAAEF,MAAMA,KAAK,IAAI,IAAI;IACrE,IAAI;IAEJ,qBACE,MAACI;QAAIC,OAAO;YAAEC,cAAc;QAA6B;;0BACvD,KAACF;0BACC,cAAA,KAACG;oBACCC,WAAU;oBACVH,OAAO;wBACLI,OAAO;oBACT;8BACD;;;0BAKH,KAACL;gBACCC,OAAO;oBACLK,YAAY;oBACZC,UAAU;oBACVC,cAAc;gBAChB;0BAEA,cAAA,KAACC;oBAAEV,MAAMA;oBAAMW,QAAO;8BACnBX;;;;;AAKX,EAAC"}
1
+ {"version":3,"sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"sourcesContent":["'use client'\n\nimport { CopyToClipboard, useConfig, useField } from '@payloadcms/ui'\nimport { formatAdminURL } from '@payloadcms/ui/shared'\nimport LinkImport from 'next/link.js'\nimport React from 'react'\n\nconst Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default\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 = `${serverURL}${formatAdminURL({\n adminRoute,\n path: `/collections/${value.relationTo || ''}/${value.value || ''}`,\n })}`\n\n const hrefToDisplay = `${process.env.NEXT_BASE_PATH || ''}${href}`\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={hrefToDisplay} />\n </div>\n <div\n style={{\n fontWeight: '600',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n <Link href={href} passHref {...{ rel: 'noopener noreferrer', target: '_blank' }}>\n {hrefToDisplay}\n </Link>\n </div>\n </div>\n )\n}\n"],"names":["CopyToClipboard","useConfig","useField","formatAdminURL","LinkImport","React","Link","default","LinkToDocClient","config","routes","admin","adminRoute","serverURL","value","path","relationTo","href","hrefToDisplay","process","env","NEXT_BASE_PATH","div","style","marginBottom","span","className","color","fontWeight","overflow","textOverflow","passHref","rel","target"],"mappings":"AAAA;;AAEA,SAASA,eAAe,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,iBAAgB;AACrE,SAASC,cAAc,QAAQ,wBAAuB;AACtD,OAAOC,gBAAgB,eAAc;AACrC,OAAOC,WAAW,QAAO;AAEzB,MAAMC,OAAQF,WAAWG,OAAO,IAAIH;AAEpC,OAAO,MAAMI,kBAA4B;IACvC,MAAM,EAAEC,MAAM,EAAE,GAAGR;IAEnB,MAAM,EACJS,QAAQ,EACNC,OAAOC,UAAU,EAClB,EACDC,SAAS,EACV,GAAGJ;IAEJ,MAAM,EAAEK,KAAK,EAAE,GAAGZ,SAAkD;QAAEa,MAAM;IAAM;IAElF,IAAI,CAACD,OAAOE,cAAc,CAACF,OAAOA,OAAO;QACvC,OAAO;IACT;IAEA,MAAMG,OAAO,GAAGJ,YAAYV,eAAe;QACzCS;QACAG,MAAM,CAAC,aAAa,EAAED,MAAME,UAAU,IAAI,GAAG,CAAC,EAAEF,MAAMA,KAAK,IAAI,IAAI;IACrE,IAAI;IAEJ,MAAMI,gBAAgB,GAAGC,QAAQC,GAAG,CAACC,cAAc,IAAI,KAAKJ,MAAM;IAElE,qBACE,MAACK;QAAIC,OAAO;YAAEC,cAAc;QAA6B;;0BACvD,MAACF;;kCACC,KAACG;wBACCC,WAAU;wBACVH,OAAO;4BACLI,OAAO;wBACT;kCACD;;kCAGD,KAAC3B;wBAAgBc,OAAOI;;;;0BAE1B,KAACI;gBACCC,OAAO;oBACLK,YAAY;oBACZC,UAAU;oBACVC,cAAc;gBAChB;0BAEA,cAAA,KAACxB;oBAAKW,MAAMA;oBAAMc,QAAQ;oBAAOC,KAAK;oBAAuBC,QAAQ;8BAClEf;;;;;AAKX,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAOpD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAsI5D,CAAA"}
1
+ {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAOpD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA0I5D,CAAA"}
@@ -1,13 +1,14 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { LoadingOverlay, Popup, PopupList, toast, useLocale, useModal, useTranslation } from '@payloadcms/ui';
3
+ import { LoadingOverlay, Popup, PopupList, toast, useConfig, useLocale, useModal, useTranslation } from '@payloadcms/ui';
4
4
  import { useRouter } from 'next/navigation.js';
5
5
  import React, { useCallback, useMemo, useState } from 'react';
6
6
  import { ReindexButtonLabel } from './ReindexButtonLabel/index.js';
7
7
  import { ReindexConfirmModal } from './ReindexConfirmModal/index.js';
8
8
  const confirmReindexModalSlug = 'confirm-reindex-modal';
9
- export const ReindexButtonClient = ({ apiBasePath, collectionLabels, searchCollections, searchSlug })=>{
9
+ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searchSlug })=>{
10
10
  const { closeModal, openModal } = useModal();
11
+ const { config } = useConfig();
11
12
  const { i18n: { t } } = useTranslation();
12
13
  const locale = useLocale();
13
14
  const router = useRouter();
@@ -25,9 +26,8 @@ export const ReindexButtonClient = ({ apiBasePath, collectionLabels, searchColle
25
26
  }
26
27
  closeConfirmModal();
27
28
  setLoading(true);
28
- const basePath = apiBasePath.endsWith('/') ? apiBasePath.slice(0, -1) : apiBasePath;
29
29
  try {
30
- const endpointRes = await fetch(`${basePath}/${searchSlug}/reindex?locale=${locale.code}`, {
30
+ const endpointRes = await fetch(`${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`, {
31
31
  body: JSON.stringify({
32
32
  collections: reindexCollections
33
33
  }),
@@ -40,7 +40,7 @@ export const ReindexButtonClient = ({ apiBasePath, collectionLabels, searchColle
40
40
  toast.success(message);
41
41
  router.refresh();
42
42
  }
43
- } catch (err) {
43
+ } catch (_err) {
44
44
  // swallow error, toast shown above
45
45
  } finally{
46
46
  setReindexCollections([]);
@@ -53,7 +53,7 @@ export const ReindexButtonClient = ({ apiBasePath, collectionLabels, searchColle
53
53
  router,
54
54
  searchSlug,
55
55
  locale,
56
- apiBasePath
56
+ config
57
57
  ]);
58
58
  const handleShowConfirmModal = useCallback((collections = searchCollections)=>{
59
59
  setReindexCollections(typeof collections === 'string' ? [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n LoadingOverlay,\n Popup,\n PopupList,\n toast,\n useLocale,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport { useRouter } from 'next/navigation.js'\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { ReindexButtonProps } from './types.js'\n\nimport { ReindexButtonLabel } from './ReindexButtonLabel/index.js'\nimport { ReindexConfirmModal } from './ReindexConfirmModal/index.js'\n\nconst confirmReindexModalSlug = 'confirm-reindex-modal'\n\nexport const ReindexButtonClient: React.FC<ReindexButtonProps> = ({\n apiBasePath,\n collectionLabels,\n searchCollections,\n searchSlug,\n}) => {\n const { closeModal, openModal } = useModal()\n const {\n i18n: { t },\n } = useTranslation()\n const locale = useLocale()\n const router = useRouter()\n\n const [reindexCollections, setReindexCollections] = useState<string[]>([])\n const [isLoading, setLoading] = useState<boolean>(false)\n\n const openConfirmModal = useCallback(() => openModal(confirmReindexModalSlug), [openModal])\n const closeConfirmModal = useCallback(() => closeModal(confirmReindexModalSlug), [closeModal])\n\n const handleReindexSubmit = useCallback(async () => {\n if (isLoading || !reindexCollections.length) {\n return\n }\n\n closeConfirmModal()\n setLoading(true)\n\n const basePath = apiBasePath.endsWith('/') ? apiBasePath.slice(0, -1) : apiBasePath\n\n try {\n const endpointRes = await fetch(`${basePath}/${searchSlug}/reindex?locale=${locale.code}`, {\n body: JSON.stringify({\n collections: reindexCollections,\n }),\n method: 'POST',\n })\n\n const { message } = (await endpointRes.json()) as { message: string }\n\n if (!endpointRes.ok) {\n toast.error(message)\n } else {\n toast.success(message)\n router.refresh()\n }\n } catch (err: unknown) {\n // swallow error, toast shown above\n } finally {\n setReindexCollections([])\n setLoading(false)\n }\n }, [closeConfirmModal, isLoading, reindexCollections, router, searchSlug, locale, apiBasePath])\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 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 acc[slug] = getPluralizedLabel(slug)\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 const loadingText = selectedAll\n ? t('general:reindexingAll', { collections: t('general:collections') })\n : t('general:reindexingAll', { 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 <ReindexConfirmModal\n description={modalDescription}\n onCancel={closeConfirmModal}\n onConfirm={handleReindexSubmit}\n slug={confirmReindexModalSlug}\n title={modalTitle}\n />\n {isLoading && <LoadingOverlay loadingText={loadingText} />}\n </div>\n )\n}\n"],"names":["LoadingOverlay","Popup","PopupList","toast","useLocale","useModal","useTranslation","useRouter","React","useCallback","useMemo","useState","ReindexButtonLabel","ReindexConfirmModal","confirmReindexModalSlug","ReindexButtonClient","apiBasePath","collectionLabels","searchCollections","searchSlug","closeModal","openModal","i18n","t","locale","router","reindexCollections","setReindexCollections","isLoading","setLoading","openConfirmModal","closeConfirmModal","handleReindexSubmit","length","basePath","endsWith","slice","endpointRes","fetch","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","loadingText","div","button","render","close","ButtonGroup","collectionSlug","Button","onClick","showScrollbar","size","verticalAlign","description","onCancel","onConfirm","title"],"mappings":"AAAA;;AAEA,SACEA,cAAc,EACdC,KAAK,EACLC,SAAS,EACTC,KAAK,EACLC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAgB;AACvB,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,OAAOC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAI7D,SAASC,kBAAkB,QAAQ,gCAA+B;AAClE,SAASC,mBAAmB,QAAQ,iCAAgC;AAEpE,MAAMC,0BAA0B;AAEhC,OAAO,MAAMC,sBAAoD,CAAC,EAChEC,WAAW,EACXC,gBAAgB,EAChBC,iBAAiB,EACjBC,UAAU,EACX;IACC,MAAM,EAAEC,UAAU,EAAEC,SAAS,EAAE,GAAGhB;IAClC,MAAM,EACJiB,MAAM,EAAEC,CAAC,EAAE,EACZ,GAAGjB;IACJ,MAAMkB,SAASpB;IACf,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H5BA;0CAMT,KAACzE,UAAU0E,MAAM;gCAACC,SAAS,IAAMxB,uBAAuBoB;0CACrDlD,EAAE;;;;gBAITuD,aAAa;gBACbC,MAAK;gBACLC,eAAc;;0BAEhB,KAACnE;gBACCoE,aAAab;gBACbc,UAAUnD;gBACVoD,WAAWnD;gBACXuB,MAAMzC;gBACNsE,OAAOjB;;YAERvC,2BAAa,KAAC5B;gBAAeqE,aAAaA;;;;AAGjD,EAAC"}
1
+ {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n LoadingOverlay,\n Popup,\n PopupList,\n toast,\n useConfig,\n useLocale,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport { useRouter } from 'next/navigation.js'\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { ReindexButtonProps } from './types.js'\n\nimport { ReindexButtonLabel } from './ReindexButtonLabel/index.js'\nimport { ReindexConfirmModal } from './ReindexConfirmModal/index.js'\n\nconst confirmReindexModalSlug = 'confirm-reindex-modal'\n\nexport const ReindexButtonClient: React.FC<ReindexButtonProps> = ({\n collectionLabels,\n searchCollections,\n searchSlug,\n}) => {\n const { closeModal, 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 const [isLoading, setLoading] = useState<boolean>(false)\n\n const openConfirmModal = useCallback(() => openModal(confirmReindexModalSlug), [openModal])\n const closeConfirmModal = useCallback(() => closeModal(confirmReindexModalSlug), [closeModal])\n\n const handleReindexSubmit = useCallback(async () => {\n if (isLoading || !reindexCollections.length) {\n return\n }\n\n closeConfirmModal()\n setLoading(true)\n\n try {\n const endpointRes = await fetch(\n `${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`,\n {\n body: JSON.stringify({\n collections: reindexCollections,\n }),\n method: 'POST',\n },\n )\n\n const { message } = (await endpointRes.json()) as { message: string }\n\n if (!endpointRes.ok) {\n toast.error(message)\n } else {\n toast.success(message)\n router.refresh()\n }\n } catch (_err: unknown) {\n // swallow error, toast shown above\n } finally {\n setReindexCollections([])\n setLoading(false)\n }\n }, [closeConfirmModal, isLoading, 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 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 acc[slug] = getPluralizedLabel(slug)\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 const loadingText = selectedAll\n ? t('general:reindexingAll', { collections: t('general:collections') })\n : t('general:reindexingAll', { 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 <ReindexConfirmModal\n description={modalDescription}\n onCancel={closeConfirmModal}\n onConfirm={handleReindexSubmit}\n slug={confirmReindexModalSlug}\n title={modalTitle}\n />\n {isLoading && <LoadingOverlay loadingText={loadingText} />}\n </div>\n )\n}\n"],"names":["LoadingOverlay","Popup","PopupList","toast","useConfig","useLocale","useModal","useTranslation","useRouter","React","useCallback","useMemo","useState","ReindexButtonLabel","ReindexConfirmModal","confirmReindexModalSlug","ReindexButtonClient","collectionLabels","searchCollections","searchSlug","closeModal","openModal","config","i18n","t","locale","router","reindexCollections","setReindexCollections","isLoading","setLoading","openConfirmModal","closeConfirmModal","handleReindexSubmit","length","endpointRes","fetch","routes","api","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","loadingText","div","button","render","close","ButtonGroup","collectionSlug","Button","onClick","showScrollbar","size","verticalAlign","description","onCancel","onConfirm","title"],"mappings":"AAAA;;AAEA,SACEA,cAAc,EACdC,KAAK,EACLC,SAAS,EACTC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAgB;AACvB,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,OAAOC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAI7D,SAASC,kBAAkB,QAAQ,gCAA+B;AAClE,SAASC,mBAAmB,QAAQ,iCAAgC;AAEpE,MAAMC,0BAA0B;AAEhC,OAAO,MAAMC,sBAAoD,CAAC,EAChEC,gBAAgB,EAChBC,iBAAiB,EACjBC,UAAU,EACX;IACC,MAAM,EAAEC,UAAU,EAAEC,SAAS,EAAE,GAAGf;IAElC,MAAM,EAAEg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OAAOE;8CAE5Cf,gBAAgB,CAACe,eAAe;mCAH5BA;0CAMT,KAACzE,UAAU0E,MAAM;gCAACC,SAAS,IAAMxB,uBAAuBoB;0CACrDjD,EAAE;;;;gBAITsD,aAAa;gBACbC,MAAK;gBACLC,eAAc;;0BAEhB,KAAClE;gBACCmE,aAAab;gBACbc,UAAUlD;gBACVmD,WAAWlD;gBACXsB,MAAMxC;gBACNqE,OAAOjB;;YAERtC,2BAAa,KAAC7B;gBAAeqE,aAAaA;;;;AAGjD,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AAIpE,eAAO,MAAM,aAAa,EAAE,kCA8B3B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AAIpE,eAAO,MAAM,aAAa,EAAE,kCA2B3B,CAAA"}
@@ -1,34 +1,31 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { ReindexButtonClient } from './index.client.js';
3
3
  export const ReindexButton = (props)=>{
4
- const { apiBasePath, collectionLabels, i18n, searchCollections, searchSlug } = props;
5
- const getStaticLocalizedPluralLabels = ()=>{
6
- return Object.fromEntries(searchCollections.map((collection)=>{
7
- const labels = collectionLabels[collection];
8
- const pluralLabel = labels?.plural;
9
- if (typeof pluralLabel === 'function') {
10
- return [
11
- collection,
12
- pluralLabel({
13
- t: i18n.t
14
- })
15
- ];
16
- }
17
- if (pluralLabel) {
18
- return [
19
- collection,
20
- pluralLabel
21
- ];
22
- }
4
+ const { collectionLabels, i18n, searchCollections, searchSlug } = props;
5
+ const resolvedCollectionLabels = Object.fromEntries(searchCollections.map((collection)=>{
6
+ const labels = collectionLabels[collection];
7
+ const pluralLabel = labels?.plural;
8
+ if (typeof pluralLabel === 'function') {
23
9
  return [
24
10
  collection,
25
- collection
11
+ pluralLabel({
12
+ t: i18n.t
13
+ })
26
14
  ];
27
- }));
28
- };
15
+ }
16
+ if (pluralLabel) {
17
+ return [
18
+ collection,
19
+ pluralLabel
20
+ ];
21
+ }
22
+ return [
23
+ collection,
24
+ collection
25
+ ];
26
+ }));
29
27
  return /*#__PURE__*/ _jsx(ReindexButtonClient, {
30
- apiBasePath: apiBasePath,
31
- collectionLabels: getStaticLocalizedPluralLabels(),
28
+ collectionLabels: resolvedCollectionLabels,
32
29
  searchCollections: searchCollections,
33
30
  searchSlug: searchSlug
34
31
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/index.tsx"],"sourcesContent":["import type { SearchReindexButtonServerComponent } from './types.js'\n\nimport { ReindexButtonClient } from './index.client.js'\n\nexport const ReindexButton: SearchReindexButtonServerComponent = (props) => {\n const { apiBasePath, collectionLabels, i18n, searchCollections, searchSlug } = props\n\n const getStaticLocalizedPluralLabels = () => {\n return Object.fromEntries(\n searchCollections.map((collection) => {\n const labels = collectionLabels[collection]\n const pluralLabel = labels?.plural\n\n if (typeof pluralLabel === 'function') {\n return [collection, pluralLabel({ t: i18n.t })]\n }\n\n if (pluralLabel) {\n return [collection, pluralLabel]\n }\n\n return [collection, collection]\n }),\n )\n }\n\n return (\n <ReindexButtonClient\n apiBasePath={apiBasePath}\n collectionLabels={getStaticLocalizedPluralLabels()}\n searchCollections={searchCollections}\n searchSlug={searchSlug}\n />\n )\n}\n"],"names":["ReindexButtonClient","ReindexButton","props","apiBasePath","collectionLabels","i18n","searchCollections","searchSlug","getStaticLocalizedPluralLabels","Object","fromEntries","map","collection","labels","pluralLabel","plural","t"],"mappings":";AAEA,SAASA,mBAAmB,QAAQ,oBAAmB;AAEvD,OAAO,MAAMC,gBAAoD,CAACC;IAChE,MAAM,EAAEC,WAAW,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,iBAAiB,EAAEC,UAAU,EAAE,GAAGL;IAE/E,MAAMM,iCAAiC;QACrC,OAAOC,OAAOC,WAAW,CACvBJ,kBAAkBK,GAAG,CAAC,CAACC;YACrB,MAAMC,SAAST,gBAAgB,CAACQ,WAAW;YAC3C,MAAME,cAAcD,QAAQE;YAE5B,IAAI,OAAOD,gBAAgB,YAAY;gBACrC,OAAO;oBAACF;oBAAYE,YAAY;wBAAEE,GAAGX,KAAKW,CAAC;oBAAC;iBAAG;YACjD;YAEA,IAAIF,aAAa;gBACf,OAAO;oBAACF;oBAAYE;iBAAY;YAClC;YAEA,OAAO;gBAACF;gBAAYA;aAAW;QACjC;IAEJ;IAEA,qBACE,KAACZ;QACCG,aAAaA;QACbC,kBAAkBI;QAClBF,mBAAmBA;QACnBC,YAAYA;;AAGlB,EAAC"}
1
+ {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/index.tsx"],"sourcesContent":["import type { ResolvedCollectionLabels } from '../../../types.js'\nimport type { SearchReindexButtonServerComponent } from './types.js'\n\nimport { ReindexButtonClient } from './index.client.js'\n\nexport const ReindexButton: SearchReindexButtonServerComponent = (props) => {\n const { collectionLabels, i18n, searchCollections, searchSlug } = props\n\n const resolvedCollectionLabels: ResolvedCollectionLabels = Object.fromEntries(\n searchCollections.map((collection) => {\n const labels = collectionLabels[collection]\n const pluralLabel = labels?.plural\n\n if (typeof pluralLabel === 'function') {\n return [collection, pluralLabel({ t: i18n.t })]\n }\n\n if (pluralLabel) {\n return [collection, pluralLabel]\n }\n\n return [collection, collection]\n }),\n )\n\n return (\n <ReindexButtonClient\n collectionLabels={resolvedCollectionLabels}\n searchCollections={searchCollections}\n searchSlug={searchSlug}\n />\n )\n}\n"],"names":["ReindexButtonClient","ReindexButton","props","collectionLabels","i18n","searchCollections","searchSlug","resolvedCollectionLabels","Object","fromEntries","map","collection","labels","pluralLabel","plural","t"],"mappings":";AAGA,SAASA,mBAAmB,QAAQ,oBAAmB;AAEvD,OAAO,MAAMC,gBAAoD,CAACC;IAChE,MAAM,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,iBAAiB,EAAEC,UAAU,EAAE,GAAGJ;IAElE,MAAMK,2BAAqDC,OAAOC,WAAW,CAC3EJ,kBAAkBK,GAAG,CAAC,CAACC;QACrB,MAAMC,SAAST,gBAAgB,CAACQ,WAAW;QAC3C,MAAME,cAAcD,QAAQE;QAE5B,IAAI,OAAOD,gBAAgB,YAAY;YACrC,OAAO;gBAACF;gBAAYE,YAAY;oBAAEE,GAAGX,KAAKW,CAAC;gBAAC;aAAG;QACjD;QAEA,IAAIF,aAAa;YACf,OAAO;gBAACF;gBAAYE;aAAY;QAClC;QAEA,OAAO;YAACF;YAAYA;SAAW;IACjC;IAGF,qBACE,KAACX;QACCG,kBAAkBI;QAClBF,mBAAmBA;QACnBC,YAAYA;;AAGlB,EAAC"}
@@ -1,15 +1,13 @@
1
- import type { CustomComponent, PayloadServerReactComponent, StaticLabel } from 'payload';
2
- import type { CollectionLabels } from '../../../types.js';
1
+ import type { CustomComponent, PayloadServerReactComponent } from 'payload';
2
+ import type { CollectionLabels, ResolvedCollectionLabels } from '../../../types.js';
3
3
  export type ReindexButtonProps = {
4
- apiBasePath: string;
5
- collectionLabels: Record<string, StaticLabel>;
4
+ collectionLabels: ResolvedCollectionLabels;
6
5
  searchCollections: string[];
7
6
  searchSlug: string;
8
7
  };
9
- type ReindexButtonServerProps = {
8
+ export type ReindexButtonServerProps = {
10
9
  collectionLabels: CollectionLabels;
11
- } & ReindexButtonProps;
10
+ } & Omit<ReindexButtonProps, 'collectionLabels'>;
12
11
  export type SearchReindexButtonClientComponent = ReindexButtonProps;
13
12
  export type SearchReindexButtonServerComponent = PayloadServerReactComponent<CustomComponent<ReindexButtonServerProps>>;
14
- export {};
15
13
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/types.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AAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/types.ts"],"sourcesContent":["import type { CustomComponent, PayloadServerReactComponent, StaticLabel } from 'payload'\n\nimport type { CollectionLabels } from '../../../types.js'\n\nexport type ReindexButtonProps = {\n apiBasePath: string\n collectionLabels: Record<string, StaticLabel>\n searchCollections: string[]\n searchSlug: string\n}\n\ntype ReindexButtonServerProps = {\n collectionLabels: CollectionLabels\n} & ReindexButtonProps\n\nexport type SearchReindexButtonClientComponent = ReindexButtonProps\nexport type SearchReindexButtonServerComponent = PayloadServerReactComponent<\n CustomComponent<ReindexButtonServerProps>\n>\n"],"names":[],"mappings":"AAgBA,WAEC"}
1
+ {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/types.ts"],"sourcesContent":["import type { CustomComponent, PayloadServerReactComponent } from 'payload'\n\nimport type { CollectionLabels, ResolvedCollectionLabels } from '../../../types.js'\n\nexport type ReindexButtonProps = {\n collectionLabels: ResolvedCollectionLabels\n searchCollections: string[]\n searchSlug: string\n}\n\nexport type ReindexButtonServerProps = {\n collectionLabels: CollectionLabels\n} & Omit<ReindexButtonProps, 'collectionLabels'>\n\nexport type SearchReindexButtonClientComponent = ReindexButtonProps\n\nexport type SearchReindexButtonServerComponent = PayloadServerReactComponent<\n CustomComponent<ReindexButtonServerProps>\n>\n"],"names":[],"mappings":"AAgBA,WAEC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwD,MAAM,EAAE,MAAM,SAAS,CAAA;AAE3F,OAAO,KAAK,EAAE,kBAAkB,EAAiC,MAAM,YAAY,CAAA;AASnF,eAAO,MAAM,YAAY,yBACA,kBAAkB,cAChC,MAAM,KAAG,MAoFjB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwD,MAAM,EAAE,MAAM,SAAS,CAAA;AAE3F,OAAO,KAAK,EAAE,kBAAkB,EAAiC,MAAM,YAAY,CAAA;AASnF,eAAO,MAAM,YAAY,yBACA,kBAAkB,cAChC,MAAM,KAAG,MAmFjB,CAAA"}
package/dist/index.js CHANGED
@@ -15,7 +15,6 @@ export const searchPlugin = (incomingPluginConfig)=>(config)=>{
15
15
  ]));
16
16
  const pluginConfig = {
17
17
  // write any config defaults here
18
- apiBasePath: config.routes?.api,
19
18
  deleteDrafts: true,
20
19
  labels,
21
20
  locales,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionAfterDeleteHook, Config } from 'payload'\n\nimport type { SearchPluginConfig, SearchPluginConfigWithLocales } 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]\ntype CollectionAfterDeleteHookArgs = Parameters<CollectionAfterDeleteHook>[0]\n\nexport const searchPlugin =\n (incomingPluginConfig: SearchPluginConfig) =>\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 const locales = config.localization\n ? config.localization.locales.map((localeConfig) =>\n typeof localeConfig === 'string' ? localeConfig : localeConfig.code,\n )\n : []\n\n const labels = Object.fromEntries(\n collections\n .filter(({ slug }) => incomingPluginConfig.collections?.includes(slug))\n .map((collection) => [collection.slug, collection.labels]),\n )\n\n const pluginConfig: SearchPluginConfigWithLocales = {\n // write any config defaults here\n apiBasePath: config.routes?.api,\n deleteDrafts: true,\n labels,\n locales,\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 enabledCollections = pluginConfig.collections || []\n const isEnabled = enabledCollections.indexOf(collection.slug) > -1\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 afterDelete: [\n ...(existingHooks?.afterDelete || []),\n async (args: CollectionAfterDeleteHookArgs) => {\n await deleteFromSearch({\n ...args,\n pluginConfig,\n })\n },\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","locales","map","localeConfig","code","labels","Object","fromEntries","filter","slug","includes","collection","pluginConfig","apiBasePath","routes","api","deleteDrafts","reindexBatchSize","syncDrafts","collectionsWithSearchHooks","hooks","existingHooks","enabledCollections","isEnabled","indexOf","afterChange","args","afterDelete"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,wBAAwB,QAAQ,oBAAmB;AAK5D,OAAO,MAAMC,eACX,CAACC,uBACD,CAACC;QACC,MAAM,EAAEC,WAAW,EAAE,GAAGD;QAExB,mEAAmE;QACnE,kFAAkF;QAClF,MAAME,iBACJ,OAAOH,qBAAqBI,QAAQ,KAAK,YACrCJ,qBAAqBI,QAAQ,GAC7BC,QAAQJ,OAAOK,YAAY;QACjCN,qBAAqBI,QAA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,OAAO;gBACL,GAAGJ,MAAM;gBACTC,aAAa;uBACPuB,8BAA8B,EAAE;oBACpC3B,yBAAyBoB;iBAC1B;YACH;QACF;QAEA,OAAOjB;IACT,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionAfterDeleteHook, Config } from 'payload'\n\nimport type { SearchPluginConfig, SearchPluginConfigWithLocales } 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]\ntype CollectionAfterDeleteHookArgs = Parameters<CollectionAfterDeleteHook>[0]\n\nexport const searchPlugin =\n (incomingPluginConfig: SearchPluginConfig) =>\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 const locales = config.localization\n ? config.localization.locales.map((localeConfig) =>\n typeof localeConfig === 'string' ? localeConfig : localeConfig.code,\n )\n : []\n\n const labels = Object.fromEntries(\n collections\n .filter(({ slug }) => incomingPluginConfig.collections?.includes(slug))\n .map((collection) => [collection.slug, collection.labels]),\n )\n\n const pluginConfig: SearchPluginConfigWithLocales = {\n // write any config defaults here\n deleteDrafts: true,\n labels,\n locales,\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 enabledCollections = pluginConfig.collections || []\n const isEnabled = enabledCollections.indexOf(collection.slug) > -1\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 afterDelete: [\n ...(existingHooks?.afterDelete || []),\n async (args: CollectionAfterDeleteHookArgs) => {\n await deleteFromSearch({\n ...args,\n pluginConfig,\n })\n },\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","locales","map","localeConfig","code","labels","Object","fromEntries","filter","slug","includes","collection","pluginConfig","deleteDrafts","reindexBatchSize","syncDrafts","collectionsWithSearchHooks","hooks","existingHooks","enabledCollections","isEnabled","indexOf","afterChange","args","afterDelete"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,wBAAwB,QAAQ,oBAAmB;AAK5D,OAAO,MAAMC,eACX,CAACC,uBACD,CAACC;QACC,MAAM,EAAEC,WAAW,EAAE,GAAGD;QAExB,mEAAmE;QACnE,kFAAkF;QAClF,MAAME,iBACJ,OAAOH,qBAAqBI,QAAQ,KAAK,YACrCJ,qBAAqBI,QAAQ,GAC7BC,QAAQJ,OAAOK,YAAY;QACjCN,qBAAqBI,QAAQ,GAAGD;QAEhC,IAAID,aAAa;YACf,MAAMK,UAAUN,OAAOK,YAAY,GAC/BL,OAAOK,YAAY,CAACC,OAAO,CAACC,GAAG,CAAC,CAACC,eAC/B,OAAOA,iBAAiB,WAAWA,eAAeA,aAAaC,IAAI,IAErE,EAAE;YAEN,MAAMC,SAASC,OAAOC,WAAW,CAC/BX,YACGY,MAAM,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKf,qBAAqBE,WAAW,EAAEc,SAASD,OAChEP,GAAG,CAAC,CAACS,aAAe;oBAACA,WAAWF,IAAI;oBAAEE,WAAWN,MAAM;iBAAC;YAG7D,MAAMO,eAA8C;gBAClD,iCAAiC;gBACjCC,cAAc;gBACdR;gBACAJ;gBACAa,kBAAkBpB,sBAAsBoB,oBAAoB;gBAC5DC,YAAY;gBACZ,GAAGrB,oBAAoB;YACzB;YAEA,2EAA2E;YAC3E,MAAMsB,6BAA6BrB,QAAQC,aACvCM,IAAI,CAACS;gBACL,MAAM,EAAEM,OAAOC,aAAa,EAAE,GAAGP;gBAEjC,MAAMQ,qBAAqBP,aAAahB,WAAW,IAAI,EAAE;gBACzD,MAAMwB,YAAYD,mBAAmBE,OAAO,CAACV,WAAWF,IAAI,IAAI,CAAC;gBACjE,IAAIW,WAAW;oBACb,OAAO;wBACL,GAAGT,UAAU;wBACbM,OAAO;4BACL,GAAGN,WAAWM,KAAK;4BACnBK,aAAa;mCACPJ,eAAeI,eAAe,EAAE;gCACpC,OAAOC;oCACL,MAAMhC,eAAe;wCACnB,GAAGgC,IAAI;wCACPZ,YAAYA,WAAWF,IAAI;wCAC3BG;oCACF;gCACF;6BACD;4BACDY,aAAa;mCACPN,eAAeM,eAAe,EAAE;gCACpC,OAAOD;oCACL,MAAMjC,iBAAiB;wCACrB,GAAGiC,IAAI;wCACPX;oCACF;gCACF;6BACD;wBACH;oBACF;gBACF;gBAEA,OAAOD;YACT,GACCH,OAAOT;YAEV,OAAO;gBACL,GAAGJ,MAAM;gBACTC,aAAa;uBACPoB,8BAA8B,EAAE;oBACpCxB,yBAAyBoB;iBAC1B;YACH;QACF;QAEA,OAAOjB;IACT,EAAC"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CollectionAfterChangeHook, CollectionAfterDeleteHook, CollectionConfig, Field, LabelFunction, Payload, PayloadRequest, StaticLabel } from 'payload';
1
+ import type { CollectionAfterChangeHook, CollectionAfterDeleteHook, CollectionConfig, Field, Locale, Payload, PayloadRequest, StaticLabel } from 'payload';
2
2
  export type DocToSync = {
3
3
  [key: string]: any;
4
4
  doc: {
@@ -19,25 +19,46 @@ export type FieldsOverride = (args: {
19
19
  defaultFields: Field[];
20
20
  }) => Field[];
21
21
  export type SearchPluginConfig = {
22
+ /**
23
+ * @deprecated
24
+ * This plugin gets the api route from the config directly and does not need to be passed in.
25
+ * As long as you have `routes.api` set in your Payload config, the plugin will use that.
26
+ * This property will be removed in the next major version.
27
+ */
22
28
  apiBasePath?: string;
23
29
  beforeSync?: BeforeSync;
24
30
  collections?: string[];
25
31
  defaultPriorities?: {
26
32
  [collection: string]: ((doc: any) => number | Promise<number>) | number;
27
33
  };
34
+ /**
35
+ * Controls whether drafts are deleted from the search index
36
+ *
37
+ * @default true
38
+ */
28
39
  deleteDrafts?: boolean;
29
40
  localize?: boolean;
41
+ /**
42
+ * We use batching when re-indexing large collections. You can control the amount of items per batch, lower numbers should help with memory.
43
+ *
44
+ * @default 50
45
+ */
30
46
  reindexBatchSize?: number;
31
47
  searchOverrides?: {
32
48
  fields?: FieldsOverride;
33
49
  } & Partial<Omit<CollectionConfig, 'fields'>>;
50
+ /**
51
+ * Controls whether drafts are synced to the search index
52
+ *
53
+ * @default false
54
+ */
34
55
  syncDrafts?: boolean;
35
56
  };
36
57
  export type CollectionLabels = {
37
- [collection: string]: {
38
- plural?: LabelFunction | StaticLabel;
39
- singular?: LabelFunction | StaticLabel;
40
- };
58
+ [collection: string]: CollectionConfig['labels'];
59
+ };
60
+ export type ResolvedCollectionLabels = {
61
+ [collection: string]: StaticLabel;
41
62
  };
42
63
  export type SearchPluginConfigWithLocales = {
43
64
  labels?: CollectionLabels;
@@ -48,7 +69,7 @@ export type SyncWithSearchArgs = {
48
69
  pluginConfig: SearchPluginConfig;
49
70
  } & Omit<Parameters<CollectionAfterChangeHook>[0], 'collection'>;
50
71
  export type SyncDocArgs = {
51
- locale?: string;
72
+ locale?: Locale['code'];
52
73
  onSyncError?: () => void;
53
74
  } & Omit<SyncWithSearchArgs, 'context' | 'previousDoc'>;
54
75
  export type SyncWithSearch = (Args: SyncWithSearchArgs) => ReturnType<CollectionAfterChangeHook>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EAChB,KAAK,EACL,aAAa,EAEb,OAAO,EACP,cAAc,EACd,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IAClB,GAAG,EAAE;QACH,UAAU,EAAE,MAAM,CAAA;QAClB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE;IAC9B,WAAW,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACnB,CAAA;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;IACnB,SAAS,EAAE,SAAS,CAAA;CACrB,KAAK,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAEpC,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE;IAAE,aAAa,EAAE,KAAK,EAAE,CAAA;CAAE,KAAK,KAAK,EAAE,CAAA;AAE1E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,iBAAiB,CAAC,EAAE;QAClB,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,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AAyB,CAAC,CAAC,CAAC,CAAC,KACzC,UAAU,CAAC,yBAAyB,CAAC,CAAA"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionAfterDeleteHook,\n CollectionConfig,\n Field,\n LabelFunction,\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 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 SearchPluginConfig = {\n apiBasePath?: string\n beforeSync?: BeforeSync\n collections?: string[]\n defaultPriorities?: {\n [collection: string]: ((doc: any) => number | Promise<number>) | number\n }\n deleteDrafts?: boolean\n localize?: boolean\n reindexBatchSize?: number\n searchOverrides?: { fields?: FieldsOverride } & Partial<Omit<CollectionConfig, 'fields'>>\n syncDrafts?: boolean\n}\n\nexport type CollectionLabels = {\n [collection: string]: {\n plural?: LabelFunction | StaticLabel\n singular?: LabelFunction | StaticLabel\n }\n}\n\nexport type SearchPluginConfigWithLocales = {\n labels?: CollectionLabels\n locales?: string[]\n} & SearchPluginConfig\n\nexport type SyncWithSearchArgs = {\n collection: string\n pluginConfig: SearchPluginConfig\n} & Omit<Parameters<CollectionAfterChangeHook>[0], 'collection'>\n\nexport type SyncDocArgs = {\n locale?: string\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 = (\n Args: {\n pluginConfig: SearchPluginConfig\n } & Parameters<CollectionAfterDeleteHook>[0],\n) => ReturnType<CollectionAfterDeleteHook>\n"],"names":[],"mappings":"AAwEA,WAI0C"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionAfterChangeHook,\n CollectionAfterDeleteHook,\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 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 SearchPluginConfig = {\n /**\n * @deprecated\n * This plugin gets the api route from the config directly and does not need to be passed in.\n * As long as you have `routes.api` set in your Payload config, the plugin will use that.\n * This property will be removed in the next major version.\n */\n apiBasePath?: string\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 * 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 locales?: string[]\n} & SearchPluginConfig\n\nexport type SyncWithSearchArgs = {\n collection: string\n pluginConfig: SearchPluginConfig\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 = (\n Args: {\n pluginConfig: SearchPluginConfig\n } & Parameters<CollectionAfterDeleteHook>[0],\n) => ReturnType<CollectionAfterDeleteHook>\n"],"names":[],"mappings":"AA6FA,WAI0C"}
@@ -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,8FAS9B,WAAW,iBA+Kb,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,iBA0Mb,CAAA"}
@@ -119,18 +119,42 @@ export const syncDocAsSearchIndex = async ({ collection, doc, locale, onSyncErro
119
119
  }
120
120
  }
121
121
  if (deleteDrafts && status === 'draft') {
122
- // do not include draft docs in search results, so delete the record
123
- try {
124
- await payload.delete({
125
- id: searchDocID,
126
- collection: searchSlug,
127
- req
128
- });
129
- } catch (err) {
130
- payload.logger.error({
131
- err,
132
- msg: `Error deleting ${searchSlug} document.`
133
- });
122
+ // Check to see if there's a published version of the doc
123
+ // We don't want to remove the search doc if there is a published version but a new draft has been created
124
+ const { docs: [docWithPublish] } = await payload.find({
125
+ collection,
126
+ draft: false,
127
+ locale: syncLocale,
128
+ req,
129
+ where: {
130
+ and: [
131
+ {
132
+ _status: {
133
+ equals: 'published'
134
+ }
135
+ },
136
+ {
137
+ id: {
138
+ equals: id
139
+ }
140
+ }
141
+ ]
142
+ }
143
+ });
144
+ if (!docWithPublish) {
145
+ // do not include draft docs in search results, so delete the record
146
+ try {
147
+ await payload.delete({
148
+ id: searchDocID,
149
+ collection: searchSlug,
150
+ req
151
+ });
152
+ } catch (err) {
153
+ payload.logger.error({
154
+ err,
155
+ msg: `Error deleting ${searchSlug} document.`
156
+ });
157
+ }
134
158
  }
135
159
  }
136
160
  } else if (doSync) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/syncDocAsSearchIndex.ts"],"sourcesContent":["import type { DocToSync, SyncDocArgs } from '../types.js'\n\nexport const syncDocAsSearchIndex = async ({\n collection,\n doc,\n locale,\n onSyncError,\n operation,\n pluginConfig,\n req: { payload },\n req,\n}: SyncDocArgs) => {\n const { id, _status: status, title } = doc || {}\n\n const { beforeSync, defaultPriorities, deleteDrafts, searchOverrides, syncDrafts } = pluginConfig\n\n const searchSlug = searchOverrides?.slug || 'search'\n const syncLocale = locale || req.locale\n\n let dataToSave: DocToSync = {\n doc: {\n relationTo: collection,\n value: id,\n },\n title,\n }\n\n if (typeof beforeSync === 'function') {\n let docToSyncWith = doc\n if (payload.config?.localization) {\n docToSyncWith = await payload.findByID({\n id,\n collection,\n locale: syncLocale,\n req,\n })\n }\n dataToSave = await beforeSync({\n originalDoc: docToSyncWith,\n payload,\n req,\n searchDoc: dataToSave,\n })\n }\n\n let defaultPriority = 0\n if (defaultPriorities) {\n const { [collection]: priority } = defaultPriorities\n\n if (typeof priority === 'function') {\n try {\n defaultPriority = await priority(doc)\n } catch (err: unknown) {\n payload.logger.error(err)\n payload.logger.error(\n `Error gathering default priority for ${searchSlug} documents related to ${collection}`,\n )\n }\n } else {\n defaultPriority = priority\n }\n }\n\n const doSync = syncDrafts || (!syncDrafts && status !== 'draft')\n\n try {\n if (operation === 'create') {\n if (doSync) {\n await payload.create({\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n }\n }\n\n if (operation === 'update') {\n try {\n // find the correct doc to sync with\n const searchDocQuery = await payload.find({\n collection: searchSlug,\n depth: 0,\n locale: syncLocale,\n req,\n where: {\n 'doc.relationTo': {\n equals: collection,\n },\n 'doc.value': {\n equals: id,\n },\n },\n })\n\n const docs: Array<{\n id: number | string\n priority?: number\n }> = searchDocQuery?.docs || []\n\n const [foundDoc, ...duplicativeDocs] = docs\n\n // delete all duplicative search docs (docs that reference the same page)\n // to ensure the same, out-of-date result does not appear twice (where only syncing the first found doc)\n if (duplicativeDocs.length > 0) {\n try {\n const duplicativeDocIDs = duplicativeDocs.map(({ id }) => id)\n await payload.delete({\n collection: searchSlug,\n req,\n where: { id: { in: duplicativeDocIDs } },\n })\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error deleting duplicative ${searchSlug} documents.`,\n })\n }\n }\n\n if (foundDoc) {\n const { id: searchDocID } = foundDoc\n\n if (doSync) {\n // update the doc normally\n try {\n await payload.update({\n id: searchDocID,\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: foundDoc.priority || defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error updating ${searchSlug} document.` })\n }\n }\n if (deleteDrafts && status === 'draft') {\n // do not include draft docs in search results, so delete the record\n try {\n await payload.delete({\n id: searchDocID,\n collection: searchSlug,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error deleting ${searchSlug} document.` })\n }\n }\n } else if (doSync) {\n try {\n await payload.create({\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error creating ${searchSlug} document.` })\n }\n }\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error finding ${searchSlug} document.` })\n }\n }\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error syncing ${searchSlug} document related to ${collection} with id: '${id}'.`,\n })\n\n if (onSyncError) {\n onSyncError()\n }\n }\n\n return doc\n}\n"],"names":["syncDocAsSearchIndex","collection","doc","locale","onSyncError","operation","pluginConfig","req","payload","id","_status","status","title","beforeSync","defaultPriorities","deleteDrafts","searchOverrides","syncDrafts","searchSlug","slug","syncLocale","dataToSave","relationTo","value","docToSyncWith","config","localization","findByID","originalDoc","searchDoc","defaultPriority","priority","err","logger","error","doSync","create","data","searchDocQuery","find","depth","where","equals","docs","foundDoc","duplicativeDocs","length","duplicativeDocIDs","map","delete","in","msg","searchDocID","update"],"mappings":"AAEA,OAAO,MAAMA,uBAAuB,OAAO,EACzCC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,YAAY,EACZC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACS;IACZ,MAAM,EAAEE,EAAE,EAAEC,SAASC,MAAM,EAAEC,KAAK,EAAE,GAAGV,OAAO,CAAC;IAE/C,MAAM,EAAEW,UAAU,EAAEC,iBAAiB,EAAEC,YAAY,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAGX;IAErF,MAAMY,aAAaF,iBAAiBG,QAAQ;IAC5C,MAAMC,aAAajB,UAAUI,IAAIJ,MAAM;IAEvC,IAAIkB,aAAwB;QAC1BnB,KAAK;YACHoB,YAAYrB;YACZsB,OAAOd;QACT;QACAG;IACF;IAEA,IAAI,OAAOC,eAAe,YAAY;QACpC,IAAIW,gBAAgBtB;QACpB,IAAIM,QAAQiB,MAAM,EAAEC,cAAc;YAChCF,gBAAgB,MAAMhB,QAAQmB,QAAQ,CAAC;gBACrClB;gBACAR;gBACAE,QAAQiB;gBACRb;YACF;QACF;QACAc,aAAa,MAAMR,WAAW;YAC5Be,aAAaJ;YACbhB;YACAD;YACAsB,WAAWR;QACb;IACF;IAEA,IAAIS,kBAAkB;IACtB,IAAIhB,mBAAmB;QACrB,MAAM,EAAE,CAACb,WAAW,EAAE8B,QAA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E,OAAOc,KAAc;gBACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAAC;oBAAEF;oBAAKmB,KAAK,CAAC,cAAc,EAAEjC,WAAW,UAAU,CAAC;gBAAC;YAC3E;QACF;IACF,EAAE,OAAOc,KAAc;QACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAAC;YACnBF;YACAmB,KAAK,CAAC,cAAc,EAAEjC,WAAW,qBAAqB,EAAEjB,WAAW,WAAW,EAAEQ,GAAG,EAAE,CAAC;QACxF;QAEA,IAAIL,aAAa;YACfA;QACF;IACF;IAEA,OAAOF;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/syncDocAsSearchIndex.ts"],"sourcesContent":["import type { DocToSync, SyncDocArgs } from '../types.js'\n\nexport const syncDocAsSearchIndex = async ({\n collection,\n doc,\n locale,\n onSyncError,\n operation,\n pluginConfig,\n req: { payload },\n req,\n}: SyncDocArgs) => {\n const { id, _status: status, title } = doc || {}\n\n const { beforeSync, defaultPriorities, deleteDrafts, searchOverrides, syncDrafts } = pluginConfig\n\n const searchSlug = searchOverrides?.slug || 'search'\n const syncLocale = locale || req.locale\n\n let dataToSave: DocToSync = {\n doc: {\n relationTo: collection,\n value: id,\n },\n title,\n }\n\n if (typeof beforeSync === 'function') {\n let docToSyncWith = doc\n if (payload.config?.localization) {\n docToSyncWith = await payload.findByID({\n id,\n collection,\n locale: syncLocale,\n req,\n })\n }\n dataToSave = await beforeSync({\n originalDoc: docToSyncWith,\n payload,\n req,\n searchDoc: dataToSave,\n })\n }\n\n let defaultPriority = 0\n if (defaultPriorities) {\n const { [collection]: priority } = defaultPriorities\n\n if (typeof priority === 'function') {\n try {\n defaultPriority = await priority(doc)\n } catch (err: unknown) {\n payload.logger.error(err)\n payload.logger.error(\n `Error gathering default priority for ${searchSlug} documents related to ${collection}`,\n )\n }\n } else {\n defaultPriority = priority\n }\n }\n\n const doSync = syncDrafts || (!syncDrafts && status !== 'draft')\n\n try {\n if (operation === 'create') {\n if (doSync) {\n await payload.create({\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n }\n }\n\n if (operation === 'update') {\n try {\n // find the correct doc to sync with\n const searchDocQuery = await payload.find({\n collection: searchSlug,\n depth: 0,\n locale: syncLocale,\n req,\n where: {\n 'doc.relationTo': {\n equals: collection,\n },\n 'doc.value': {\n equals: id,\n },\n },\n })\n\n const docs: Array<{\n id: number | string\n priority?: number\n }> = searchDocQuery?.docs || []\n\n const [foundDoc, ...duplicativeDocs] = docs\n\n // delete all duplicative search docs (docs that reference the same page)\n // to ensure the same, out-of-date result does not appear twice (where only syncing the first found doc)\n if (duplicativeDocs.length > 0) {\n try {\n const duplicativeDocIDs = duplicativeDocs.map(({ id }) => id)\n await payload.delete({\n collection: searchSlug,\n req,\n where: { id: { in: duplicativeDocIDs } },\n })\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error deleting duplicative ${searchSlug} documents.`,\n })\n }\n }\n\n if (foundDoc) {\n const { id: searchDocID } = foundDoc\n\n if (doSync) {\n // update the doc normally\n try {\n await payload.update({\n id: searchDocID,\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: foundDoc.priority || defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error updating ${searchSlug} document.` })\n }\n }\n if (deleteDrafts && status === 'draft') {\n // Check to see if there's a published version of the doc\n // We don't want to remove the search doc if there is a published version but a new draft has been created\n const {\n docs: [docWithPublish],\n } = await payload.find({\n collection,\n draft: false,\n locale: syncLocale,\n req,\n where: {\n and: [\n {\n _status: {\n equals: 'published',\n },\n },\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n\n if (!docWithPublish) {\n // do not include draft docs in search results, so delete the record\n try {\n await payload.delete({\n id: searchDocID,\n collection: searchSlug,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error deleting ${searchSlug} document.` })\n }\n }\n }\n } else if (doSync) {\n try {\n await payload.create({\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error creating ${searchSlug} document.` })\n }\n }\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error finding ${searchSlug} document.` })\n }\n }\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error syncing ${searchSlug} document related to ${collection} with id: '${id}'.`,\n })\n\n if (onSyncError) {\n onSyncError()\n }\n }\n\n return doc\n}\n"],"names":["syncDocAsSearchIndex","collection","doc","locale","onSyncError","operation","pluginConfig","req","payload","id","_status","status","title","beforeSync","defaultPriorities","deleteDrafts","searchOverrides","syncDrafts","searchSlug","slug","syncLocale","dataToSave","relationTo","value","docToSyncWith","config","localization","findByID","originalDoc","searchDoc","defaultPriority","priority","err","logger","error","doSync","create","data","searchDocQuery","find","depth","where","equals","docs","foundDoc","duplicativeDocs","length","duplicativeDocIDs","map","delete","in","msg","searchDocID","update","docWithPublish","draft","and"],"mappings":"AAEA,OAAO,MAAMA,uBAAuB,OAAO,EACzCC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,YAAY,EACZC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACS;IACZ,MAAM,EAAEE,EAAE,EAAEC,SAASC,MAAM,EAAEC,KAAK,EAAE,GAAGV,OAAO,CAAC;IAE/C,MAAM,EAAEW,UAAU,EAAEC,iBAAiB,EAAEC,YAAY,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAGX;IAErF,MAAMY,aAAaF,iBAAiBG,QAAQ;IAC5C,MAAMC,aAAajB,UAAUI,IAAIJ,MAAM;IAEvC,IAAIkB,aAAwB;QAC1BnB,KAAK;YACHoB,YAAYrB;YACZsB,OAAOd;QACT;QACAG;IACF;IAEA,IAAI,OAAOC,eAAe,YAAY;QACpC,IAAIW,gBAAgBtB;QACpB,IAAIM,QAAQ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,gBAAgB;4BACnB,oEAAoE;4BACpE,IAAI;gCACF,MAAM9C,QAAQyC,MAAM,CAAC;oCACnBxC,IAAI2C;oCACJnD,YAAYiB;oCACZX;gCACF;4BACF,EAAE,OAAOyB,KAAc;gCACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAAC;oCAAEF;oCAAKmB,KAAK,CAAC,eAAe,EAAEjC,WAAW,UAAU,CAAC;gCAAC;4BAC5E;wBACF;oBACF;gBACF,OAAO,IAAIiB,QAAQ;oBACjB,IAAI;wBACF,MAAM3B,QAAQ4B,MAAM,CAAC;4BACnBnC,YAAYiB;4BACZmB,MAAM;gCACJ,GAAGhB,UAAU;gCACbU,UAAUD;4BACZ;4BACA3B,QAAQiB;4BACRb;wBACF;oBACF,EAAE,OAAOyB,KAAc;wBACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAAC;4BAAEF;4BAAKmB,KAAK,CAAC,eAAe,EAAEjC,WAAW,UAAU,CAAC;wBAAC;oBAC5E;gBACF;YACF,EAAE,OAAOc,KAAc;gBACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAAC;oBAAEF;oBAAKmB,KAAK,CAAC,cAAc,EAAEjC,WAAW,UAAU,CAAC;gBAAC;YAC3E;QACF;IACF,EAAE,OAAOc,KAAc;QACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAAC;YACnBF;YACAmB,KAAK,CAAC,cAAc,EAAEjC,WAAW,qBAAqB,EAAEjB,WAAW,WAAW,EAAEQ,GAAG,EAAE,CAAC;QACxF;QAEA,IAAIL,aAAa;YACfA;QACF;IACF;IAEA,OAAOF;AACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-search",
3
- "version": "3.21.0-canary.c6481e1",
3
+ "version": "3.21.0",
4
4
  "description": "Search plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -49,19 +49,19 @@
49
49
  "dist"
50
50
  ],
51
51
  "dependencies": {
52
- "@payloadcms/next": "3.21.0-canary.c6481e1",
53
- "@payloadcms/ui": "3.21.0-canary.c6481e1"
52
+ "@payloadcms/next": "3.21.0",
53
+ "@payloadcms/ui": "3.21.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "19.0.1",
57
57
  "@types/react-dom": "19.0.1",
58
- "payload": "3.21.0-canary.c6481e1",
59
- "@payloadcms/eslint-config": "3.9.0"
58
+ "@payloadcms/eslint-config": "3.9.0",
59
+ "payload": "3.21.0"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
63
63
  "react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
64
- "payload": "3.21.0-canary.c6481e1"
64
+ "payload": "3.21.0"
65
65
  },
66
66
  "publishConfig": {
67
67
  "registry": "https://registry.npmjs.org/"