@whatworks/payload-select-search-field 1.0.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.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Payload Search Select Field
2
+
3
+ Server-backed search select field and plugin for Payload. The client component queries a shared endpoint
4
+ and passes the current search query plus any currently selected values.
5
+
6
+ ## Usage
7
+
8
+ Add the plugin:
9
+
10
+ ```ts
11
+ import { selectSearchPlugin } from '@whatworks/payload-select-search-field'
12
+
13
+ export default buildConfig({
14
+ plugins: [selectSearchPlugin()],
15
+ })
16
+ ```
17
+
18
+ Add a field with `selectSearch` (recommended):c
19
+
20
+ ```ts
21
+ import { selectSearch } from '@whatworks/payload-select-search-field'
22
+
23
+ selectSearch({
24
+ name: 'stripeCustomer',
25
+ hasMany: true,
26
+ searchFunction: async ({ query, selectedValues }) => {
27
+ return [
28
+ { value: 'cus_123', label: `Result for ${query}` },
29
+ ...selectedValues.map((value) => ({
30
+ value,
31
+ label: `Selected: ${value}`,
32
+ })),
33
+ ]
34
+ },
35
+ admin: {
36
+ components: {
37
+ Field: '@whatworks/payload-select-search-field/client#SelectSearchField',
38
+ },
39
+ },
40
+ })
41
+ ```
42
+
43
+ `searchFunction` receives:
44
+ - `query`: the current input text.
45
+ - `selectedValues`: an array of currently selected values (empty array when nothing is selected).
46
+ - `req`, `field`, and `collection`/`global` context.
47
+
48
+ The client component calls the shared endpoint path from `selectSearchEndpoint`.
@@ -0,0 +1,2 @@
1
+ import type { Endpoint } from 'payload';
2
+ export declare const selectSearchEndpointHandler: () => Endpoint;
@@ -0,0 +1 @@
1
+ export declare const selectSearchEndpoint = "/select-search";
@@ -0,0 +1 @@
1
+ export { SelectSearchField } from '../ui/SelectSearchField.js';
@@ -0,0 +1,5 @@
1
+ export { selectSearchPlugin as selectSearchPlugin } from './plugin.js';
2
+ export { selectSearchEndpoint } from './endpointName.js';
3
+ export { selectSearchEndpointHandler } from './endpoint.js';
4
+ export { selectSearchField } from './selectSearchField.js';
5
+ export type { SelectSearchFunction, SelectSearchFunctionArgs, SelectSearchOption, SelectSearchRequest, SelectSearchResponse, } from './types.js';
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'payload';
2
+ export declare const selectSearchPlugin: () => Plugin;
@@ -0,0 +1,10 @@
1
+ import type { Field, TextField } from 'payload';
2
+ import type { SelectSearchFunction } from './types.js';
3
+ export type SelectSearchFieldArgs = Omit<TextField, 'admin' | 'custom' | 'type' | 'hasMany'> & {
4
+ hasMany?: boolean;
5
+ type?: 'text';
6
+ searchFunction: SelectSearchFunction;
7
+ custom?: Record<string, unknown>;
8
+ admin?: TextField['admin'];
9
+ };
10
+ export declare const selectSearchField: (args: SelectSearchFieldArgs) => Field;
@@ -0,0 +1,25 @@
1
+ import type { FlattenedField, PayloadRequest, SanitizedCollectionConfig, SanitizedGlobalConfig } from 'payload';
2
+ export type SelectSearchOption = {
3
+ label: string;
4
+ value: string;
5
+ [key: string]: unknown;
6
+ };
7
+ export type SelectSearchFunctionArgs = {
8
+ req: PayloadRequest;
9
+ query: string;
10
+ selectedValues: string[];
11
+ field: FlattenedField;
12
+ collection?: SanitizedCollectionConfig;
13
+ global?: SanitizedGlobalConfig;
14
+ };
15
+ export type SelectSearchFunction = (args: SelectSearchFunctionArgs) => Promise<SelectSearchOption[]> | SelectSearchOption[];
16
+ export type SelectSearchRequest = {
17
+ entityType: 'collection' | 'global';
18
+ slug: string;
19
+ schemaPath: string;
20
+ query?: string;
21
+ selectedValues?: string[];
22
+ };
23
+ export type SelectSearchResponse = {
24
+ options: SelectSearchOption[];
25
+ };
@@ -0,0 +1,2 @@
1
+ import type { TextFieldClientComponent } from 'payload';
2
+ export declare const SelectSearchField: TextFieldClientComponent;