@foundrykit/payload-fields 0.0.0-stage → 1.0.1
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/README.md +208 -2
- package/dist/exports/client.d.ts +8 -0
- package/dist/exports/client.js +10 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +3 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/fields/address/AddressInput.d.ts +7 -0
- package/dist/fields/address/AddressInput.js +203 -0
- package/dist/fields/address/AddressInput.js.map +1 -0
- package/dist/fields/address/index.d.ts +8 -0
- package/dist/fields/address/index.js +77 -0
- package/dist/fields/address/index.js.map +1 -0
- package/dist/fields/bestTimeToVisit/MonthRatingField.d.ts +3 -0
- package/dist/fields/bestTimeToVisit/MonthRatingField.js +206 -0
- package/dist/fields/bestTimeToVisit/MonthRatingField.js.map +1 -0
- package/dist/fields/bestTimeToVisit/index.d.ts +6 -0
- package/dist/fields/bestTimeToVisit/index.js +82 -0
- package/dist/fields/bestTimeToVisit/index.js.map +1 -0
- package/dist/fields/budget/PriceInput.d.ts +3 -0
- package/dist/fields/budget/PriceInput.js +65 -0
- package/dist/fields/budget/PriceInput.js.map +1 -0
- package/dist/fields/budget/RowLabel.d.ts +3 -0
- package/dist/fields/budget/RowLabel.js +22 -0
- package/dist/fields/budget/RowLabel.js.map +1 -0
- package/dist/fields/budget/index.d.ts +8 -0
- package/dist/fields/budget/index.js +111 -0
- package/dist/fields/budget/index.js.map +1 -0
- package/dist/fields/changedBy/index.d.ts +11 -0
- package/dist/fields/changedBy/index.js +30 -0
- package/dist/fields/changedBy/index.js.map +1 -0
- package/dist/fields/changedBy/populateChangedBy.d.ts +3 -0
- package/dist/fields/changedBy/populateChangedBy.js +12 -0
- package/dist/fields/changedBy/populateChangedBy.js.map +1 -0
- package/dist/fields/countryCode/index.d.ts +11 -0
- package/dist/fields/countryCode/index.js +880 -0
- package/dist/fields/countryCode/index.js.map +1 -0
- package/dist/fields/dateRange/DateRangeComponent.d.ts +3 -0
- package/dist/fields/dateRange/DateRangeComponent.js +77 -0
- package/dist/fields/dateRange/DateRangeComponent.js.map +1 -0
- package/dist/fields/dateRange/index.d.ts +11 -0
- package/dist/fields/dateRange/index.js +26 -0
- package/dist/fields/dateRange/index.js.map +1 -0
- package/dist/fields/gallery/index.d.ts +10 -0
- package/dist/fields/gallery/index.js +23 -0
- package/dist/fields/gallery/index.js.map +1 -0
- package/dist/fields/icon/index.d.ts +8 -0
- package/dist/fields/icon/index.js +30 -0
- package/dist/fields/icon/index.js.map +1 -0
- package/dist/fields/imageMap/ImageMapField.d.ts +13 -0
- package/dist/fields/imageMap/ImageMapField.js +67 -0
- package/dist/fields/imageMap/ImageMapField.js.map +1 -0
- package/dist/fields/imageMap/MapEditor/MapEditor.d.ts +13 -0
- package/dist/fields/imageMap/MapEditor/MapEditor.js +225 -0
- package/dist/fields/imageMap/MapEditor/MapEditor.js.map +1 -0
- package/dist/fields/imageMap/MapEditor/PinContextMenu.d.ts +12 -0
- package/dist/fields/imageMap/MapEditor/PinContextMenu.js +61 -0
- package/dist/fields/imageMap/MapEditor/PinContextMenu.js.map +1 -0
- package/dist/fields/imageMap/MapEditor/WaypointPopover.d.ts +14 -0
- package/dist/fields/imageMap/MapEditor/WaypointPopover.js +103 -0
- package/dist/fields/imageMap/MapEditor/WaypointPopover.js.map +1 -0
- package/dist/fields/imageMap/MapEditor/WaypointSheet.d.ts +9 -0
- package/dist/fields/imageMap/MapEditor/WaypointSheet.js +190 -0
- package/dist/fields/imageMap/MapEditor/WaypointSheet.js.map +1 -0
- package/dist/fields/imageMap/MapEditor/WaypointSheet.scss +128 -0
- package/dist/fields/imageMap/MapEditor/map-editor.scss +556 -0
- package/dist/fields/imageMap/MapEditor/types.d.ts +20 -0
- package/dist/fields/imageMap/MapEditor/types.js +3 -0
- package/dist/fields/imageMap/MapEditor/types.js.map +1 -0
- package/dist/fields/imageMap/index.d.ts +16 -0
- package/dist/fields/imageMap/index.js +35 -0
- package/dist/fields/imageMap/index.js.map +1 -0
- package/dist/fields/link/index.d.ts +21 -0
- package/dist/fields/link/index.js +134 -0
- package/dist/fields/link/index.js.map +1 -0
- package/dist/fields/link/resolveLink.d.ts +28 -0
- package/dist/fields/link/resolveLink.js +26 -0
- package/dist/fields/link/resolveLink.js.map +1 -0
- package/dist/fields/openingTimes/RowLabel.d.ts +2 -0
- package/dist/fields/openingTimes/RowLabel.js +12 -0
- package/dist/fields/openingTimes/RowLabel.js.map +1 -0
- package/dist/fields/openingTimes/index.d.ts +8 -0
- package/dist/fields/openingTimes/index.js +22 -0
- package/dist/fields/openingTimes/index.js.map +1 -0
- package/dist/fields/openingTimes/opening-time.d.ts +6 -0
- package/dist/fields/openingTimes/opening-time.js +37 -0
- package/dist/fields/openingTimes/opening-time.js.map +1 -0
- package/dist/fields/socials/index.d.ts +7 -0
- package/dist/fields/socials/index.js +70 -0
- package/dist/fields/socials/index.js.map +1 -0
- package/dist/fields/tags/RowLabel.d.ts +2 -0
- package/dist/fields/tags/RowLabel.js +12 -0
- package/dist/fields/tags/RowLabel.js.map +1 -0
- package/dist/fields/tags/index.d.ts +10 -0
- package/dist/fields/tags/index.js +22 -0
- package/dist/fields/tags/index.js.map +1 -0
- package/dist/fields/tags/tag.d.ts +6 -0
- package/dist/fields/tags/tag.js +18 -0
- package/dist/fields/tags/tag.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/utilities/deepMerge.d.ts +4 -0
- package/dist/utilities/deepMerge.js +30 -0
- package/dist/utilities/deepMerge.js.map +1 -0
- package/package.json +118 -3
package/README.md
CHANGED
|
@@ -1,3 +1,209 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @foundrykit/payload-fields
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reusable field factories for [Payload CMS 3](https://payloadcms.com): the fields every site built from the Payload website template ends up rebuilding. Each one is a small function that returns a standard Payload field config, so import only what you use.
|
|
4
|
+
|
|
5
|
+
`link`, `linkGroup`, `socials`, `gallery` and `imageMap` replace the hand-rolled copies in Umi client sites (8 drifted `link.ts` variants, 4 `imageMap` variants). See [Migrating from a hand-rolled `link.ts`](#migrating-from-a-hand-rolled-linkts).
|
|
6
|
+
|
|
7
|
+
## What's included
|
|
8
|
+
|
|
9
|
+
| Import | Returns | What it does |
|
|
10
|
+
| ----------------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------- |
|
|
11
|
+
| `link(opts?)` | `GroupField` (`link`) | Internal reference or custom URL, new tab, label, appearance. |
|
|
12
|
+
| `linkGroup(opts?)` | `ArrayField` (`links`) | An array of `link`s. |
|
|
13
|
+
| `resolveLink(link, opts?)` | `{ href, target?, rel? } \| null` | Frontend helper: turns a stored link into anchor props. RSC-safe. |
|
|
14
|
+
| `socials(opts?)` | `ArrayField` (`socials`) | Social profiles: platform select + validated URL. |
|
|
15
|
+
| `icon(opts?)` | `SelectField` (`icon`) | An icon-name select; your frontend maps the name to an SVG. |
|
|
16
|
+
| `address(opts?)` | `GroupField` (`address`) | Structured UK address with a free **postcode lookup** (api.postcodes.io). |
|
|
17
|
+
| `openingTimes(opts?)` | `ArrayField` (`opening_times`) | Day / open / close opening-hours list. |
|
|
18
|
+
| `gallery(opts?)` | `ArrayField` (`gallery`) | Images with captions. |
|
|
19
|
+
| `tags(opts?)` | `ArrayField` (`tags`) | Repeatable free-text tags with tidy row labels. |
|
|
20
|
+
| `imageMap(opts?)` | `GroupField` (`imageMap`) | A base image plus click-to-place waypoints (pin editor in the admin). |
|
|
21
|
+
| `dateRangeField({name})` | `GroupField` | A from/to pair as two month pickers. |
|
|
22
|
+
| `budgetField()` | `ArrayField` | Pricing rows (duration + formatted price + per-unit). |
|
|
23
|
+
| `countryCodeField()` | `SelectField` | Searchable ISO 3166-1 alpha-2 country select. |
|
|
24
|
+
| `changedByFields()` + `populateChangedBy` | `[RelationshipField, RelationshipField]` + hook | `createdBy`/`updatedBy` audit fields, per version. |
|
|
25
|
+
| `bestTimeToVisitMonths()` | `ArrayField` | A 12-month best/good/ok grid with a custom editor UI. |
|
|
26
|
+
|
|
27
|
+
Every factory takes `overrides`, deep-merged into the result, so you can rename, reposition or extend a field without forking it: `link({ overrides: { name: 'cta' } })`.
|
|
28
|
+
|
|
29
|
+
## Screenshots
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
pnpm add @foundrykit/payload-fields
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Peer deps: `payload` (^3.37), plus `@payloadcms/ui` and `react` for the fields with an admin component (`address`, `imageMap`, `tags`, `openingTimes`, `dateRangeField`, `budgetField`, `bestTimeToVisitMonths`). The image-map editor's SCSS is compiled by Next, so the site needs `sass` (Payload sites already have it).
|
|
42
|
+
|
|
43
|
+
Run `payload generate:importmap` after adding a field with a custom component (Payload does this on dev and build). The components resolve from `@foundrykit/payload-fields/client`.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import {
|
|
49
|
+
address,
|
|
50
|
+
gallery,
|
|
51
|
+
icon,
|
|
52
|
+
imageMap,
|
|
53
|
+
link,
|
|
54
|
+
linkGroup,
|
|
55
|
+
openingTimes,
|
|
56
|
+
socials,
|
|
57
|
+
tags,
|
|
58
|
+
} from '@foundrykit/payload-fields';
|
|
59
|
+
import { type CollectionConfig, slugField } from 'payload';
|
|
60
|
+
|
|
61
|
+
export const Places: CollectionConfig = {
|
|
62
|
+
slug: 'places',
|
|
63
|
+
fields: [
|
|
64
|
+
{ name: 'title', type: 'text', required: true },
|
|
65
|
+
slugField({ useAsSlug: 'title' }), // Payload core, see "Removed in v1"
|
|
66
|
+
link({ relationTo: ['pages', 'posts'] }),
|
|
67
|
+
linkGroup({ appearances: false }),
|
|
68
|
+
socials(),
|
|
69
|
+
icon({ options: ['wifi', 'parking', 'pool'] }),
|
|
70
|
+
address(),
|
|
71
|
+
openingTimes(),
|
|
72
|
+
gallery(),
|
|
73
|
+
tags(),
|
|
74
|
+
imageMap(),
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `link(options?)`
|
|
80
|
+
|
|
81
|
+
Stored as `{ type: 'reference' | 'custom', newTab, reference, url, label, appearance }`.
|
|
82
|
+
|
|
83
|
+
| Option | Default | Notes |
|
|
84
|
+
| -------------- | -------------------------------------------- | -------------------------------------------------------------------------- |
|
|
85
|
+
| `relationTo` | `['pages']` | Collections an internal link can point at. |
|
|
86
|
+
| `appearances` | `Default` (`default`), `Outline` (`outline`) | Payload select options; the first is the default. `false` drops the field. |
|
|
87
|
+
| `disableLabel` | `false` | Drop the label field (e.g. icon-only links). |
|
|
88
|
+
| `required` | `true` | Applies to reference/URL and label. |
|
|
89
|
+
| `overrides` | `{}` | Deep-merged into the group. |
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
link({
|
|
93
|
+
relationTo: ['pages', 'posts', 'rooms'],
|
|
94
|
+
appearances: [
|
|
95
|
+
{ label: 'Primary', value: 'default' },
|
|
96
|
+
{ label: 'Secondary', value: 'secondary' },
|
|
97
|
+
{ label: 'Outline', value: 'outline' },
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `linkGroup(options?)`
|
|
103
|
+
|
|
104
|
+
An array named `links` of `link`s. Takes every `link` option; `overrides` applies to the array (`linkGroup({ overrides: { maxRows: 2 } })`).
|
|
105
|
+
|
|
106
|
+
### `resolveLink(link, { paths? })`
|
|
107
|
+
|
|
108
|
+
Pure, so it works in Server Components. Fetch with `depth >= 1` so references are populated; an unpopulated reference or empty link returns `null`.
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
import { type LinkValue, resolveLink } from '@foundrykit/payload-fields';
|
|
112
|
+
|
|
113
|
+
export function CMSLink({ link }: { link: LinkValue }) {
|
|
114
|
+
const props = resolveLink(link, { paths: { posts: '/blog' } });
|
|
115
|
+
if (!props) return null;
|
|
116
|
+
return <a {...props}>{link.label}</a>; // or <Link {...props}>
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Internal links resolve to `/<slug>` for `pages` and `/<collection>/<slug>` otherwise; `paths` sets a collection's prefix. `newTab` adds `target="_blank"` and `rel="noopener noreferrer"`.
|
|
121
|
+
|
|
122
|
+
### `socials({ platforms?, overrides? })`
|
|
123
|
+
|
|
124
|
+
An array named `socials` of `{ platform, url }`. `platforms` defaults to `SOCIAL_PLATFORMS` (Facebook, Instagram, X, LinkedIn, YouTube, TikTok, Pinterest, WhatsApp). URLs must be absolute.
|
|
125
|
+
|
|
126
|
+
### `icon({ options?, overrides? })`
|
|
127
|
+
|
|
128
|
+
A select named `icon` storing an icon name. `options` defaults to `ICONS` (the 20 names the client sites share); pass your own to match your icon component.
|
|
129
|
+
|
|
130
|
+
### `address({ sidebar?, overrides? })`
|
|
131
|
+
|
|
132
|
+
A group named `address`: `line1`, `line2`, `city`, `county`, `postcode`, `country` (default `United Kingdom`). The admin component adds a postcode lookup against the free, key-less `api.postcodes.io`; editors can always type the address by hand.
|
|
133
|
+
|
|
134
|
+
### `openingTimes({ sidebar?, overrides? })`
|
|
135
|
+
|
|
136
|
+
An array named `opening_times`; each row is `opening_time: { day, opening_time, closing_time }`. Same shape as the client sites' `fields/opening-times`, so switching needs no data migration.
|
|
137
|
+
|
|
138
|
+
### `gallery({ relationTo?, sidebar?, overrides? })`
|
|
139
|
+
|
|
140
|
+
An array named `gallery` of `{ image, caption }`. `relationTo` defaults to `media`.
|
|
141
|
+
|
|
142
|
+
### `tags({ name?, label?, sidebar?, overrides? })`
|
|
143
|
+
|
|
144
|
+
An array (default name `tags`); each row is `tag: { tag }`.
|
|
145
|
+
|
|
146
|
+
### `imageMap({ name?, mediaSlug?, required?, overrides? })`
|
|
147
|
+
|
|
148
|
+
A group (default name `imageMap`) of `image` (upload, `mediaSlug` defaults to `media`) and `map` (JSON `{ waypoints: Waypoint[] }`, with `x`/`y` as percentages). In the admin, click the image to drop a pin; right-click a pin to edit or delete it. The editor reads the image's `url`, `width` and `height` from `/api/<mediaSlug>/<id>`.
|
|
149
|
+
|
|
150
|
+
Same shape as the client sites' `fields/imageMap` and `@foundrykit/image-map-field`, so switching needs no data migration.
|
|
151
|
+
|
|
152
|
+
### The other fields
|
|
153
|
+
|
|
154
|
+
- **changedBy**: Payload versions snapshot the whole document, so `createdBy`/`updatedBy` give per-version authorship. Point at another users collection with `changedByFields({ usersCollection })`.
|
|
155
|
+
- **bestTimeToVisit**: month colours use `--btv-best` / `--btv-good` / `--btv-ok`; override them in your admin CSS.
|
|
156
|
+
|
|
157
|
+
## Migrating from a hand-rolled `link.ts`
|
|
158
|
+
|
|
159
|
+
Most sites carry the Payload website template's `src/fields/link.ts` and `linkGroup.ts`. To switch:
|
|
160
|
+
|
|
161
|
+
1. Replace imports of `@/fields/link` and `@/fields/linkGroup` with `@foundrykit/payload-fields`.
|
|
162
|
+
2. Move the collections from the hard-coded `relationTo` array into the option: `link({ relationTo: ['pages', 'posts'] })`.
|
|
163
|
+
3. Appearances are now Payload select options rather than keys into an `appearanceOptions` map. Pass your site's list, keeping your existing values:
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
// before: link({ appearances: ['default', 'outline'] })
|
|
167
|
+
link({ appearances: [{ label: 'Default', value: 'default' }, { label: 'Outline', value: 'outline' }] })
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The default list is `default` + `outline`, which matches crowne-plaza, landmark, mad-swans, raf and your-apartments as they are.
|
|
171
|
+
4. If your appearance field is called `look` (turquoise), rename the `look` columns to `appearance` in a migration (`payload migrate:create`, then an `ALTER TABLE … RENAME COLUMN` for each table that holds a link). A field name can't be overridden here, because `overrides` replaces the group's `fields` array as a whole.
|
|
172
|
+
5. `requiredRelationship` / `requiredUrl` / `requiredLabel` (the-resident) are now one `required` flag.
|
|
173
|
+
6. Site-specific link types (`giftListContactForm` in turquoise, `anchorSectionId` and `search` in your-apartments) aren't included. Keep those links on your own field, or extend the `type` options with `overrides`.
|
|
174
|
+
7. Replace the template's `CMSLink` href logic with `resolveLink(link, { paths })`.
|
|
175
|
+
|
|
176
|
+
Field names (`link`, `type`, `newTab`, `reference`, `url`, `label`, `appearance`) and the `links` array match the template, so apart from step 4 the database schema doesn't change and no migration is needed.
|
|
177
|
+
|
|
178
|
+
### Other fields
|
|
179
|
+
|
|
180
|
+
- **gallery**: the old hand-rolled `gallery` (and payload-fields 0.x) was a `hasMany` upload. v1 is an array of `{ image, caption }`, which changes the schema. Migrate with `gallery: oldIds.map(image => ({ image }))`, or keep the old field.
|
|
181
|
+
- **address**: the client sites' `fields/address.ts` stores `street`, `city`, `postcode`. v1 stores `line1`/`line2`/`city`/`county`/`postcode`/`country`; copy `street` into `line1`.
|
|
182
|
+
- **socials**: the client sites' `socials` is an array of `link` + `icon` group. v1 is `{ platform, url }`; map the icon type to `platform` and the link URL to `url`.
|
|
183
|
+
- **icon**: the client sites' `icon` is a group of `type` + `colour`. v1 is a single select (the name); keep colour on your own field if you use it.
|
|
184
|
+
- **imageMap**: same shape as before. Delete `src/fields/imageMap/` and swap the import.
|
|
185
|
+
|
|
186
|
+
## Removed in v1
|
|
187
|
+
|
|
188
|
+
- **`slugField`, `formatSlug`, `formatSlugHook`**: Payload core ships `slugField` (`import { slugField } from 'payload'`). Replace `...slugField('title')` with `slugField({ useAsSlug: 'title' })`. Core's version stores its checkbox as `generateSlug` (checked means "keep generating") rather than `slugLock`, and makes `slug` unique and required by default, so drop the `slugLock` column and check for duplicate slugs before migrating.
|
|
189
|
+
- **`GalleryLabel`** client component (the gallery is an array now).
|
|
190
|
+
|
|
191
|
+
## Exports
|
|
192
|
+
|
|
193
|
+
- `@foundrykit/payload-fields`: every field factory, `resolveLink`, `populateChangedBy`, `ICONS`, `SOCIAL_PLATFORMS`, `ISO_COUNTRY_OPTIONS`, `deepMerge`, and the `LinkValue`, `ResolvedLink`, `LinkOptions`, `ImageMapValue` and `Waypoint` types. Safe on the server and in Server Components.
|
|
194
|
+
- `@foundrykit/payload-fields/client`: the admin components (registered via the import map; you don't import these directly).
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
```sh
|
|
199
|
+
pnpm install
|
|
200
|
+
pnpm dev # dev admin at http://localhost:3000/admin, with a "places" collection using every field
|
|
201
|
+
pnpm test # unit + integration
|
|
202
|
+
pnpm test:unit # each factory's output shape, resolveLink
|
|
203
|
+
pnpm test:int # creates a document using every v1 field on a real Payload instance (SQLite)
|
|
204
|
+
pnpm build && pnpm verify:pack
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
MIT © Isaac SJ / Umi
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AddressInput } from '../fields/address/AddressInput.js';
|
|
2
|
+
export { MonthRatingField } from '../fields/bestTimeToVisit/MonthRatingField.js';
|
|
3
|
+
export { PriceInput } from '../fields/budget/PriceInput.js';
|
|
4
|
+
export { BudgetRowLabel } from '../fields/budget/RowLabel.js';
|
|
5
|
+
export { DateRangeComponent } from '../fields/dateRange/DateRangeComponent.js';
|
|
6
|
+
export { ImageMapField } from '../fields/imageMap/ImageMapField.js';
|
|
7
|
+
export { OpeningTimesRowLabel } from '../fields/openingTimes/RowLabel.js';
|
|
8
|
+
export { TagsRowLabel } from '../fields/tags/RowLabel.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { AddressInput } from '../fields/address/AddressInput.js';
|
|
2
|
+
export { MonthRatingField } from '../fields/bestTimeToVisit/MonthRatingField.js';
|
|
3
|
+
export { PriceInput } from '../fields/budget/PriceInput.js';
|
|
4
|
+
export { BudgetRowLabel } from '../fields/budget/RowLabel.js';
|
|
5
|
+
export { DateRangeComponent } from '../fields/dateRange/DateRangeComponent.js';
|
|
6
|
+
export { ImageMapField } from '../fields/imageMap/ImageMapField.js';
|
|
7
|
+
export { OpeningTimesRowLabel } from '../fields/openingTimes/RowLabel.js';
|
|
8
|
+
export { TagsRowLabel } from '../fields/tags/RowLabel.js';
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { AddressInput } from '../fields/address/AddressInput.js';\nexport { MonthRatingField } from '../fields/bestTimeToVisit/MonthRatingField.js';\nexport { PriceInput } from '../fields/budget/PriceInput.js';\nexport { BudgetRowLabel } from '../fields/budget/RowLabel.js';\nexport { DateRangeComponent } from '../fields/dateRange/DateRangeComponent.js';\nexport { ImageMapField } from '../fields/imageMap/ImageMapField.js';\nexport { OpeningTimesRowLabel } from '../fields/openingTimes/RowLabel.js';\nexport { TagsRowLabel } from '../fields/tags/RowLabel.js';\n"],"names":["AddressInput","MonthRatingField","PriceInput","BudgetRowLabel","DateRangeComponent","ImageMapField","OpeningTimesRowLabel","TagsRowLabel"],"mappings":"AAAA,SAASA,YAAY,QAAQ,oCAAoC;AACjE,SAASC,gBAAgB,QAAQ,gDAAgD;AACjF,SAASC,UAAU,QAAQ,iCAAiC;AAC5D,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,kBAAkB,QAAQ,4CAA4C;AAC/E,SAASC,aAAa,QAAQ,sCAAsC;AACpE,SAASC,oBAAoB,QAAQ,qCAAqC;AAC1E,SAASC,YAAY,QAAQ,6BAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export {};\n"],"names":[],"mappings":"AAAA,WAAU"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GroupFieldClientProps } from 'payload';
|
|
2
|
+
import type React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Structured address input with a free UK postcode lookup (api.postcodes.io —
|
|
5
|
+
* no API key). Falls back to fully manual entry.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AddressInput: React.FC<GroupFieldClientProps>;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button, FieldLabel, TextInput, useField } from '@payloadcms/ui';
|
|
4
|
+
import { useCallback, useState } from 'react';
|
|
5
|
+
const toTitleCase = (str)=>str.toLowerCase().replace(/\b\w/g, (c)=>c.toUpperCase());
|
|
6
|
+
/**
|
|
7
|
+
* Structured address input with a free UK postcode lookup (api.postcodes.io —
|
|
8
|
+
* no API key). Falls back to fully manual entry.
|
|
9
|
+
*/ export const AddressInput = ({ field, path })=>{
|
|
10
|
+
const { label } = field;
|
|
11
|
+
const [lookup, setLookup] = useState('');
|
|
12
|
+
const [loading, setLoading] = useState(false);
|
|
13
|
+
const [lookupError, setLookupError] = useState(null);
|
|
14
|
+
const { value: line1, setValue: setLine1 } = useField({
|
|
15
|
+
path: `${path}.line1`
|
|
16
|
+
});
|
|
17
|
+
const { value: line2, setValue: setLine2 } = useField({
|
|
18
|
+
path: `${path}.line2`
|
|
19
|
+
});
|
|
20
|
+
const { value: city, setValue: setCity } = useField({
|
|
21
|
+
path: `${path}.city`
|
|
22
|
+
});
|
|
23
|
+
const { value: county, setValue: setCounty } = useField({
|
|
24
|
+
path: `${path}.county`
|
|
25
|
+
});
|
|
26
|
+
const { value: postcode, setValue: setPostcode } = useField({
|
|
27
|
+
path: `${path}.postcode`
|
|
28
|
+
});
|
|
29
|
+
const { value: country, setValue: setCountry } = useField({
|
|
30
|
+
path: `${path}.country`
|
|
31
|
+
});
|
|
32
|
+
const hasExistingData = Boolean(line1 || line2 || city || county || postcode);
|
|
33
|
+
const [showFields, setShowFields] = useState(hasExistingData);
|
|
34
|
+
const handleLookup = useCallback(async ()=>{
|
|
35
|
+
const cleaned = lookup.trim();
|
|
36
|
+
if (!cleaned) return;
|
|
37
|
+
setLoading(true);
|
|
38
|
+
setLookupError(null);
|
|
39
|
+
try {
|
|
40
|
+
const res = await fetch(`https://api.postcodes.io/postcodes/${encodeURIComponent(cleaned)}`);
|
|
41
|
+
const data = await res.json();
|
|
42
|
+
if (data.status === 200 && data.result) {
|
|
43
|
+
const { postcode: formatted, postal_town, admin_district, admin_county, country: apiCountry } = data.result;
|
|
44
|
+
setPostcode(formatted);
|
|
45
|
+
setCity(toTitleCase(postal_town || admin_district || ''));
|
|
46
|
+
setCounty(toTitleCase(admin_county || admin_district || ''));
|
|
47
|
+
setCountry(apiCountry || 'United Kingdom');
|
|
48
|
+
setLookup('');
|
|
49
|
+
setShowFields(true);
|
|
50
|
+
} else {
|
|
51
|
+
setLookupError('Postcode not found — please check and try again.');
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
setLookupError('Lookup failed — please try again or enter the address manually.');
|
|
55
|
+
} finally{
|
|
56
|
+
setLoading(false);
|
|
57
|
+
}
|
|
58
|
+
}, [
|
|
59
|
+
lookup,
|
|
60
|
+
setPostcode,
|
|
61
|
+
setCity,
|
|
62
|
+
setCounty,
|
|
63
|
+
setCountry
|
|
64
|
+
]);
|
|
65
|
+
const handleKeyDown = useCallback((e)=>{
|
|
66
|
+
if (e.key === 'Enter') {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
void handleLookup();
|
|
69
|
+
}
|
|
70
|
+
}, [
|
|
71
|
+
handleLookup
|
|
72
|
+
]);
|
|
73
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
74
|
+
className: "field-type group address-field",
|
|
75
|
+
style: {
|
|
76
|
+
display: 'flex',
|
|
77
|
+
flexDirection: 'column',
|
|
78
|
+
gap: '0.5rem'
|
|
79
|
+
},
|
|
80
|
+
children: [
|
|
81
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
82
|
+
label: label
|
|
83
|
+
}),
|
|
84
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
85
|
+
className: "address-field__lookup",
|
|
86
|
+
style: {
|
|
87
|
+
paddingBottom: '0.5rem'
|
|
88
|
+
},
|
|
89
|
+
children: [
|
|
90
|
+
/*#__PURE__*/ _jsx("div", {
|
|
91
|
+
className: "field-type text",
|
|
92
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
93
|
+
className: "field-type__wrap",
|
|
94
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
95
|
+
style: {
|
|
96
|
+
display: 'flex',
|
|
97
|
+
alignItems: 'center',
|
|
98
|
+
gap: '1rem'
|
|
99
|
+
},
|
|
100
|
+
children: [
|
|
101
|
+
/*#__PURE__*/ _jsx("input", {
|
|
102
|
+
disabled: loading,
|
|
103
|
+
onChange: (e)=>setLookup(e.target.value),
|
|
104
|
+
onKeyDown: handleKeyDown,
|
|
105
|
+
placeholder: "Find by postcode, e.g. SW1A 1AA",
|
|
106
|
+
type: "text",
|
|
107
|
+
value: lookup,
|
|
108
|
+
style: {
|
|
109
|
+
width: '100%'
|
|
110
|
+
}
|
|
111
|
+
}),
|
|
112
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
113
|
+
buttonStyle: "primary",
|
|
114
|
+
disabled: loading,
|
|
115
|
+
onClick: ()=>void handleLookup(),
|
|
116
|
+
size: "large",
|
|
117
|
+
className: "m-0",
|
|
118
|
+
children: loading ? 'Looking up...' : 'Find'
|
|
119
|
+
}),
|
|
120
|
+
!showFields && /*#__PURE__*/ _jsx(Button, {
|
|
121
|
+
buttonStyle: "secondary",
|
|
122
|
+
onClick: ()=>setShowFields(true),
|
|
123
|
+
size: "large",
|
|
124
|
+
children: "Manual"
|
|
125
|
+
})
|
|
126
|
+
]
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
}),
|
|
130
|
+
lookupError && /*#__PURE__*/ _jsx("p", {
|
|
131
|
+
style: {
|
|
132
|
+
color: 'var(--theme-error-500)'
|
|
133
|
+
},
|
|
134
|
+
children: lookupError
|
|
135
|
+
})
|
|
136
|
+
]
|
|
137
|
+
}),
|
|
138
|
+
showFields && /*#__PURE__*/ _jsxs("div", {
|
|
139
|
+
style: {
|
|
140
|
+
display: 'flex',
|
|
141
|
+
flexDirection: 'column',
|
|
142
|
+
gap: '0.5rem'
|
|
143
|
+
},
|
|
144
|
+
children: [
|
|
145
|
+
/*#__PURE__*/ _jsx(TextInput, {
|
|
146
|
+
label: "Address Line 1",
|
|
147
|
+
onChange: (e)=>setLine1(e.target.value),
|
|
148
|
+
path: `${path}.line1`,
|
|
149
|
+
value: line1 ?? ''
|
|
150
|
+
}),
|
|
151
|
+
/*#__PURE__*/ _jsx(TextInput, {
|
|
152
|
+
label: "Address Line 2",
|
|
153
|
+
onChange: (e)=>setLine2(e.target.value),
|
|
154
|
+
path: `${path}.line2`,
|
|
155
|
+
value: line2 ?? ''
|
|
156
|
+
}),
|
|
157
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
158
|
+
style: {
|
|
159
|
+
display: 'flex',
|
|
160
|
+
gap: '1rem'
|
|
161
|
+
},
|
|
162
|
+
children: [
|
|
163
|
+
/*#__PURE__*/ _jsx(TextInput, {
|
|
164
|
+
label: "City / Town",
|
|
165
|
+
onChange: (e)=>setCity(e.target.value),
|
|
166
|
+
path: `${path}.city`,
|
|
167
|
+
value: city ?? ''
|
|
168
|
+
}),
|
|
169
|
+
/*#__PURE__*/ _jsx(TextInput, {
|
|
170
|
+
label: "County",
|
|
171
|
+
onChange: (e)=>setCounty(e.target.value),
|
|
172
|
+
path: `${path}.county`,
|
|
173
|
+
value: county ?? ''
|
|
174
|
+
})
|
|
175
|
+
]
|
|
176
|
+
}),
|
|
177
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
178
|
+
style: {
|
|
179
|
+
display: 'flex',
|
|
180
|
+
gap: '1rem'
|
|
181
|
+
},
|
|
182
|
+
children: [
|
|
183
|
+
/*#__PURE__*/ _jsx(TextInput, {
|
|
184
|
+
label: "Postcode",
|
|
185
|
+
onChange: (e)=>setPostcode(e.target.value),
|
|
186
|
+
path: `${path}.postcode`,
|
|
187
|
+
value: postcode ?? ''
|
|
188
|
+
}),
|
|
189
|
+
/*#__PURE__*/ _jsx(TextInput, {
|
|
190
|
+
label: "Country",
|
|
191
|
+
onChange: (e)=>setCountry(e.target.value),
|
|
192
|
+
path: `${path}.country`,
|
|
193
|
+
value: country ?? ''
|
|
194
|
+
})
|
|
195
|
+
]
|
|
196
|
+
})
|
|
197
|
+
]
|
|
198
|
+
})
|
|
199
|
+
]
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
//# sourceMappingURL=AddressInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/address/AddressInput.tsx"],"sourcesContent":["'use client';\nimport { Button, FieldLabel, TextInput, useField } from '@payloadcms/ui';\nimport type { GroupFieldClientProps } from 'payload';\nimport type React from 'react';\nimport { useCallback, useState } from 'react';\n\ntype PostcodesIOResult = {\n status: number;\n result: {\n postcode: string;\n postal_town: string;\n admin_district: string;\n admin_county: string;\n country: string;\n } | null;\n};\n\nconst toTitleCase = (str: string) =>\n str.toLowerCase().replace(/\\b\\w/g, c => c.toUpperCase());\n\n/**\n * Structured address input with a free UK postcode lookup (api.postcodes.io —\n * no API key). Falls back to fully manual entry.\n */\nexport const AddressInput: React.FC<GroupFieldClientProps> = ({\n field,\n path,\n}) => {\n const { label } = field;\n const [lookup, setLookup] = useState('');\n const [loading, setLoading] = useState(false);\n const [lookupError, setLookupError] = useState<string | null>(null);\n\n const { value: line1, setValue: setLine1 } = useField<string>({\n path: `${path}.line1`,\n });\n const { value: line2, setValue: setLine2 } = useField<string>({\n path: `${path}.line2`,\n });\n const { value: city, setValue: setCity } = useField<string>({\n path: `${path}.city`,\n });\n const { value: county, setValue: setCounty } = useField<string>({\n path: `${path}.county`,\n });\n const { value: postcode, setValue: setPostcode } = useField<string>({\n path: `${path}.postcode`,\n });\n const { value: country, setValue: setCountry } = useField<string>({\n path: `${path}.country`,\n });\n\n const hasExistingData = Boolean(line1 || line2 || city || county || postcode);\n const [showFields, setShowFields] = useState(hasExistingData);\n\n const handleLookup = useCallback(async () => {\n const cleaned = lookup.trim();\n if (!cleaned) return;\n setLoading(true);\n setLookupError(null);\n try {\n const res = await fetch(\n `https://api.postcodes.io/postcodes/${encodeURIComponent(cleaned)}`\n );\n const data: PostcodesIOResult = await res.json();\n if (data.status === 200 && data.result) {\n const {\n postcode: formatted,\n postal_town,\n admin_district,\n admin_county,\n country: apiCountry,\n } = data.result;\n setPostcode(formatted);\n setCity(toTitleCase(postal_town || admin_district || ''));\n setCounty(toTitleCase(admin_county || admin_district || ''));\n setCountry(apiCountry || 'United Kingdom');\n setLookup('');\n setShowFields(true);\n } else {\n setLookupError('Postcode not found — please check and try again.');\n }\n } catch {\n setLookupError(\n 'Lookup failed — please try again or enter the address manually.'\n );\n } finally {\n setLoading(false);\n }\n }, [lookup, setPostcode, setCity, setCounty, setCountry]);\n\n const handleKeyDown = useCallback(\n (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n void handleLookup();\n }\n },\n [handleLookup]\n );\n\n return (\n <div\n className='field-type group address-field'\n style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}\n >\n <FieldLabel label={label} />\n <div\n className='address-field__lookup'\n style={{ paddingBottom: '0.5rem' }}\n >\n <div className='field-type text'>\n <div className='field-type__wrap'>\n <div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>\n <input\n disabled={loading}\n onChange={e => setLookup(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder='Find by postcode, e.g. SW1A 1AA'\n type='text'\n value={lookup}\n style={{ width: '100%' }}\n />\n <Button\n buttonStyle='primary'\n disabled={loading}\n onClick={() => void handleLookup()}\n size='large'\n className='m-0'\n >\n {loading ? 'Looking up...' : 'Find'}\n </Button>\n {!showFields && (\n <Button\n buttonStyle='secondary'\n onClick={() => setShowFields(true)}\n size='large'\n >\n Manual\n </Button>\n )}\n </div>\n </div>\n </div>\n {lookupError && (\n <p style={{ color: 'var(--theme-error-500)' }}>{lookupError}</p>\n )}\n </div>\n\n {showFields && (\n <div\n style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}\n >\n <TextInput\n label='Address Line 1'\n onChange={(e: React.ChangeEvent<HTMLInputElement>) =>\n setLine1(e.target.value)\n }\n path={`${path}.line1`}\n value={line1 ?? ''}\n />\n <TextInput\n label='Address Line 2'\n onChange={(e: React.ChangeEvent<HTMLInputElement>) =>\n setLine2(e.target.value)\n }\n path={`${path}.line2`}\n value={line2 ?? ''}\n />\n <div style={{ display: 'flex', gap: '1rem' }}>\n <TextInput\n label='City / Town'\n onChange={(e: React.ChangeEvent<HTMLInputElement>) =>\n setCity(e.target.value)\n }\n path={`${path}.city`}\n value={city ?? ''}\n />\n <TextInput\n label='County'\n onChange={(e: React.ChangeEvent<HTMLInputElement>) =>\n setCounty(e.target.value)\n }\n path={`${path}.county`}\n value={county ?? ''}\n />\n </div>\n <div style={{ display: 'flex', gap: '1rem' }}>\n <TextInput\n label='Postcode'\n onChange={(e: React.ChangeEvent<HTMLInputElement>) =>\n setPostcode(e.target.value)\n }\n path={`${path}.postcode`}\n value={postcode ?? ''}\n />\n <TextInput\n label='Country'\n onChange={(e: React.ChangeEvent<HTMLInputElement>) =>\n setCountry(e.target.value)\n }\n path={`${path}.country`}\n value={country ?? ''}\n />\n </div>\n </div>\n )}\n </div>\n );\n};\n"],"names":["Button","FieldLabel","TextInput","useField","useCallback","useState","toTitleCase","str","toLowerCase","replace","c","toUpperCase","AddressInput","field","path","label","lookup","setLookup","loading","setLoading","lookupError","setLookupError","value","line1","setValue","setLine1","line2","setLine2","city","setCity","county","setCounty","postcode","setPostcode","country","setCountry","hasExistingData","Boolean","showFields","setShowFields","handleLookup","cleaned","trim","res","fetch","encodeURIComponent","data","json","status","result","formatted","postal_town","admin_district","admin_county","apiCountry","handleKeyDown","e","key","preventDefault","div","className","style","display","flexDirection","gap","paddingBottom","alignItems","input","disabled","onChange","target","onKeyDown","placeholder","type","width","buttonStyle","onClick","size","p","color"],"mappings":"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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Field, GroupField } from 'payload';
|
|
2
|
+
type AddressType = (options?: {
|
|
3
|
+
sidebar?: boolean;
|
|
4
|
+
overrides?: Partial<GroupField>;
|
|
5
|
+
}) => Field;
|
|
6
|
+
/** A structured UK address group with a postcode-lookup helper in the admin. */
|
|
7
|
+
export declare const address: AddressType;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import deepMerge from '../../utilities/deepMerge.js';
|
|
2
|
+
/** A structured UK address group with a postcode-lookup helper in the admin. */ export const address = ({ sidebar = false, overrides = {} } = {})=>{
|
|
3
|
+
const addressResult = {
|
|
4
|
+
name: 'address',
|
|
5
|
+
type: 'group',
|
|
6
|
+
fields: [
|
|
7
|
+
{
|
|
8
|
+
name: 'line1',
|
|
9
|
+
label: 'Address Line 1',
|
|
10
|
+
type: 'text',
|
|
11
|
+
admin: {
|
|
12
|
+
placeholder: 'Building name / number and street'
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'line2',
|
|
17
|
+
label: 'Address Line 2',
|
|
18
|
+
type: 'text',
|
|
19
|
+
admin: {
|
|
20
|
+
placeholder: 'Apartment, suite, unit etc. (optional)'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'row',
|
|
25
|
+
fields: [
|
|
26
|
+
{
|
|
27
|
+
name: 'city',
|
|
28
|
+
label: 'City / Town',
|
|
29
|
+
type: 'text',
|
|
30
|
+
admin: {
|
|
31
|
+
width: '50%'
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'county',
|
|
36
|
+
label: 'County',
|
|
37
|
+
type: 'text',
|
|
38
|
+
admin: {
|
|
39
|
+
width: '50%'
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'row',
|
|
46
|
+
fields: [
|
|
47
|
+
{
|
|
48
|
+
name: 'postcode',
|
|
49
|
+
label: 'Postcode',
|
|
50
|
+
type: 'text',
|
|
51
|
+
admin: {
|
|
52
|
+
width: '40%'
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'country',
|
|
57
|
+
label: 'Country',
|
|
58
|
+
type: 'text',
|
|
59
|
+
defaultValue: 'United Kingdom',
|
|
60
|
+
admin: {
|
|
61
|
+
width: '60%'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
admin: {
|
|
68
|
+
position: sidebar ? 'sidebar' : undefined,
|
|
69
|
+
components: {
|
|
70
|
+
Field: '@foundrykit/payload-fields/client#AddressInput'
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return deepMerge(addressResult, overrides);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/address/index.ts"],"sourcesContent":["import type { Field, GroupField } from 'payload';\nimport deepMerge from '../../utilities/deepMerge.js';\n\ntype AddressType = (options?: {\n sidebar?: boolean;\n overrides?: Partial<GroupField>;\n}) => Field;\n\n/** A structured UK address group with a postcode-lookup helper in the admin. */\nexport const address: AddressType = ({\n sidebar = false,\n overrides = {},\n} = {}) => {\n const addressResult: Field = {\n name: 'address',\n type: 'group',\n fields: [\n {\n name: 'line1',\n label: 'Address Line 1',\n type: 'text',\n admin: { placeholder: 'Building name / number and street' },\n },\n {\n name: 'line2',\n label: 'Address Line 2',\n type: 'text',\n admin: { placeholder: 'Apartment, suite, unit etc. (optional)' },\n },\n {\n type: 'row',\n fields: [\n {\n name: 'city',\n label: 'City / Town',\n type: 'text',\n admin: { width: '50%' },\n },\n {\n name: 'county',\n label: 'County',\n type: 'text',\n admin: { width: '50%' },\n },\n ],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'postcode',\n label: 'Postcode',\n type: 'text',\n admin: { width: '40%' },\n },\n {\n name: 'country',\n label: 'Country',\n type: 'text',\n defaultValue: 'United Kingdom',\n admin: { width: '60%' },\n },\n ],\n },\n ],\n admin: {\n position: sidebar ? 'sidebar' : undefined,\n components: { Field: '@foundrykit/payload-fields/client#AddressInput' },\n },\n };\n return deepMerge(addressResult, overrides);\n};\n"],"names":["deepMerge","address","sidebar","overrides","addressResult","name","type","fields","label","admin","placeholder","width","defaultValue","position","undefined","components","Field"],"mappings":"AACA,OAAOA,eAAe,+BAA+B;AAOrD,8EAA8E,GAC9E,OAAO,MAAMC,UAAuB,CAAC,EACnCC,UAAU,KAAK,EACfC,YAAY,CAAC,CAAC,EACf,GAAG,CAAC,CAAC;IACJ,MAAMC,gBAAuB;QAC3BC,MAAM;QACNC,MAAM;QACNC,QAAQ;YACN;gBACEF,MAAM;gBACNG,OAAO;gBACPF,MAAM;gBACNG,OAAO;oBAAEC,aAAa;gBAAoC;YAC5D;YACA;gBACEL,MAAM;gBACNG,OAAO;gBACPF,MAAM;gBACNG,OAAO;oBAAEC,aAAa;gBAAyC;YACjE;YACA;gBACEJ,MAAM;gBACNC,QAAQ;oBACN;wBACEF,MAAM;wBACNG,OAAO;wBACPF,MAAM;wBACNG,OAAO;4BAAEE,OAAO;wBAAM;oBACxB;oBACA;wBACEN,MAAM;wBACNG,OAAO;wBACPF,MAAM;wBACNG,OAAO;4BAAEE,OAAO;wBAAM;oBACxB;iBACD;YACH;YACA;gBACEL,MAAM;gBACNC,QAAQ;oBACN;wBACEF,MAAM;wBACNG,OAAO;wBACPF,MAAM;wBACNG,OAAO;4BAAEE,OAAO;wBAAM;oBACxB;oBACA;wBACEN,MAAM;wBACNG,OAAO;wBACPF,MAAM;wBACNM,cAAc;wBACdH,OAAO;4BAAEE,OAAO;wBAAM;oBACxB;iBACD;YACH;SACD;QACDF,OAAO;YACLI,UAAUX,UAAU,YAAYY;YAChCC,YAAY;gBAAEC,OAAO;YAAiD;QACxE;IACF;IACA,OAAOhB,UAAUI,eAAeD;AAClC,EAAE"}
|