@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
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldError, FieldLabel, useAllFormFields, useForm, useFormSubmitted } from '@payloadcms/ui';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
const months = [
|
|
6
|
+
{
|
|
7
|
+
label: 'Jan',
|
|
8
|
+
value: 'jan'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
label: 'Feb',
|
|
12
|
+
value: 'feb'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: 'Mar',
|
|
16
|
+
value: 'mar'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
label: 'Apr',
|
|
20
|
+
value: 'apr'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: 'May',
|
|
24
|
+
value: 'may'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: 'Jun',
|
|
28
|
+
value: 'jun'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: 'Jul',
|
|
32
|
+
value: 'jul'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: 'Aug',
|
|
36
|
+
value: 'aug'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
label: 'Sep',
|
|
40
|
+
value: 'sep'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: 'Oct',
|
|
44
|
+
value: 'oct'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
label: 'Nov',
|
|
48
|
+
value: 'nov'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
label: 'Dec',
|
|
52
|
+
value: 'dec'
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
// Brand-neutral defaults; override the CSS custom properties
|
|
56
|
+
// (--btv-best / --btv-good / --btv-ok) in your admin CSS to rebrand.
|
|
57
|
+
const ratings = [
|
|
58
|
+
{
|
|
59
|
+
label: 'Best',
|
|
60
|
+
value: 'best',
|
|
61
|
+
colour: 'var(--btv-best, #0ea5b7)'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
label: 'Good',
|
|
65
|
+
value: 'good',
|
|
66
|
+
colour: 'var(--btv-good, #7dd3e8)'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
label: 'OK',
|
|
70
|
+
value: 'ok',
|
|
71
|
+
colour: 'var(--btv-ok, #dbeef5)'
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
export const MonthRatingField = ({ field, path, readOnly })=>{
|
|
75
|
+
const { label, required } = field;
|
|
76
|
+
const [fields, dispatchFields] = useAllFormFields();
|
|
77
|
+
const submitted = useFormSubmitted();
|
|
78
|
+
const { setModified } = useForm();
|
|
79
|
+
const arrayField = fields?.[path];
|
|
80
|
+
const rows = arrayField?.rows || [];
|
|
81
|
+
const showError = arrayField?.valid === false && submitted;
|
|
82
|
+
const monthData = months.map(({ value: month, label: monthLabel })=>{
|
|
83
|
+
const rowIndex = rows.findIndex((_, i)=>fields?.[`${path}.${i}.month`]?.value === month);
|
|
84
|
+
const rating = rowIndex >= 0 ? fields?.[`${path}.${rowIndex}.rating`]?.value ?? 'ok' : 'ok';
|
|
85
|
+
return {
|
|
86
|
+
month,
|
|
87
|
+
label: monthLabel,
|
|
88
|
+
rating,
|
|
89
|
+
rowIndex
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
const updateRating = useCallback((month, rating)=>{
|
|
93
|
+
if (readOnly) return;
|
|
94
|
+
const item = monthData.find((d)=>d.month === month);
|
|
95
|
+
if (!item || item.rowIndex < 0) return;
|
|
96
|
+
dispatchFields({
|
|
97
|
+
type: 'UPDATE',
|
|
98
|
+
path: `${path}.${item.rowIndex}.rating`,
|
|
99
|
+
value: rating
|
|
100
|
+
});
|
|
101
|
+
setModified(true);
|
|
102
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
103
|
+
[
|
|
104
|
+
dispatchFields,
|
|
105
|
+
path,
|
|
106
|
+
readOnly,
|
|
107
|
+
setModified,
|
|
108
|
+
JSON.stringify(monthData)
|
|
109
|
+
]);
|
|
110
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
111
|
+
className: [
|
|
112
|
+
'field-type',
|
|
113
|
+
'array',
|
|
114
|
+
showError && 'error',
|
|
115
|
+
readOnly && 'read-only'
|
|
116
|
+
].filter(Boolean).join(' '),
|
|
117
|
+
children: [
|
|
118
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
119
|
+
label: label,
|
|
120
|
+
path: path,
|
|
121
|
+
required: required
|
|
122
|
+
}),
|
|
123
|
+
/*#__PURE__*/ _jsx(FieldError, {
|
|
124
|
+
path: path,
|
|
125
|
+
showError: showError
|
|
126
|
+
}),
|
|
127
|
+
/*#__PURE__*/ _jsx("div", {
|
|
128
|
+
style: {
|
|
129
|
+
display: 'grid',
|
|
130
|
+
gap: '0.75rem',
|
|
131
|
+
gridTemplateColumns: 'repeat(auto-fit, minmax(9rem, 1fr))',
|
|
132
|
+
marginTop: '0.75rem'
|
|
133
|
+
},
|
|
134
|
+
children: monthData.map((item)=>{
|
|
135
|
+
const activeRating = ratings.find((r)=>r.value === item.rating) ?? ratings[2];
|
|
136
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
137
|
+
style: {
|
|
138
|
+
background: 'var(--theme-elevation-50)',
|
|
139
|
+
border: '1px solid var(--theme-elevation-150)',
|
|
140
|
+
borderRadius: '0.375rem',
|
|
141
|
+
padding: '0.75rem'
|
|
142
|
+
},
|
|
143
|
+
children: [
|
|
144
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
145
|
+
style: {
|
|
146
|
+
alignItems: 'center',
|
|
147
|
+
display: 'flex',
|
|
148
|
+
gap: '0.5rem',
|
|
149
|
+
justifyContent: 'space-between',
|
|
150
|
+
marginBottom: '0.625rem'
|
|
151
|
+
},
|
|
152
|
+
children: [
|
|
153
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
154
|
+
style: {
|
|
155
|
+
fontSize: '0.875rem',
|
|
156
|
+
textTransform: 'uppercase'
|
|
157
|
+
},
|
|
158
|
+
children: item.label
|
|
159
|
+
}),
|
|
160
|
+
/*#__PURE__*/ _jsx("span", {
|
|
161
|
+
"aria-hidden": "true",
|
|
162
|
+
style: {
|
|
163
|
+
background: activeRating.colour,
|
|
164
|
+
border: '1px solid var(--theme-elevation-150)',
|
|
165
|
+
borderRadius: '999px',
|
|
166
|
+
display: 'block',
|
|
167
|
+
height: '1rem',
|
|
168
|
+
width: '1rem'
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
]
|
|
172
|
+
}),
|
|
173
|
+
/*#__PURE__*/ _jsx("div", {
|
|
174
|
+
style: {
|
|
175
|
+
display: 'grid',
|
|
176
|
+
gridTemplateColumns: 'repeat(3, 1fr)'
|
|
177
|
+
},
|
|
178
|
+
children: ratings.map((rating)=>{
|
|
179
|
+
const isActive = item.rating === rating.value;
|
|
180
|
+
return /*#__PURE__*/ _jsx("button", {
|
|
181
|
+
disabled: readOnly,
|
|
182
|
+
onClick: (event)=>{
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
updateRating(item.month, rating.value);
|
|
185
|
+
},
|
|
186
|
+
type: "button",
|
|
187
|
+
style: {
|
|
188
|
+
background: isActive ? rating.colour : 'var(--theme-elevation-0)',
|
|
189
|
+
border: isActive ? '1px solid var(--theme-text)' : '1px solid var(--theme-elevation-200)',
|
|
190
|
+
color: isActive && rating.value !== 'ok' ? '#ffffff' : 'var(--theme-text)',
|
|
191
|
+
fontSize: '0.75rem',
|
|
192
|
+
padding: '0.4rem 0.3rem'
|
|
193
|
+
},
|
|
194
|
+
children: rating.label
|
|
195
|
+
}, rating.value);
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
]
|
|
199
|
+
}, item.month);
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
]
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
//# sourceMappingURL=MonthRatingField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/bestTimeToVisit/MonthRatingField.tsx"],"sourcesContent":["'use client';\n\nimport {\n FieldError,\n FieldLabel,\n useAllFormFields,\n useForm,\n useFormSubmitted,\n} from '@payloadcms/ui';\nimport type { ArrayFieldClientProps } from 'payload';\nimport type React from 'react';\nimport { useCallback } from 'react';\n\ntype MonthValue =\n | 'jan'\n | 'feb'\n | 'mar'\n | 'apr'\n | 'may'\n | 'jun'\n | 'jul'\n | 'aug'\n | 'sep'\n | 'oct'\n | 'nov'\n | 'dec';\ntype RatingValue = 'best' | 'good' | 'ok';\n\nconst months: { label: string; value: MonthValue }[] = [\n { label: 'Jan', value: 'jan' },\n { label: 'Feb', value: 'feb' },\n { label: 'Mar', value: 'mar' },\n { label: 'Apr', value: 'apr' },\n { label: 'May', value: 'may' },\n { label: 'Jun', value: 'jun' },\n { label: 'Jul', value: 'jul' },\n { label: 'Aug', value: 'aug' },\n { label: 'Sep', value: 'sep' },\n { label: 'Oct', value: 'oct' },\n { label: 'Nov', value: 'nov' },\n { label: 'Dec', value: 'dec' },\n];\n\n// Brand-neutral defaults; override the CSS custom properties\n// (--btv-best / --btv-good / --btv-ok) in your admin CSS to rebrand.\nconst ratings: { label: string; value: RatingValue; colour: string }[] = [\n { label: 'Best', value: 'best', colour: 'var(--btv-best, #0ea5b7)' },\n { label: 'Good', value: 'good', colour: 'var(--btv-good, #7dd3e8)' },\n { label: 'OK', value: 'ok', colour: 'var(--btv-ok, #dbeef5)' },\n];\n\nexport const MonthRatingField: React.FC<ArrayFieldClientProps> = ({\n field,\n path,\n readOnly,\n}) => {\n const { label, required } = field;\n const [fields, dispatchFields] = useAllFormFields();\n const submitted = useFormSubmitted();\n const { setModified } = useForm();\n\n const arrayField = fields?.[path];\n const rows = (arrayField?.rows as Array<{ id: string }> | undefined) || [];\n const showError = arrayField?.valid === false && submitted;\n\n const monthData = months.map(({ value: month, label: monthLabel }) => {\n const rowIndex = rows.findIndex(\n (_, i) => fields?.[`${path}.${i}.month`]?.value === month\n );\n const rating: RatingValue =\n rowIndex >= 0\n ? ((fields?.[`${path}.${rowIndex}.rating`]?.value as RatingValue) ??\n 'ok')\n : 'ok';\n return { month, label: monthLabel, rating, rowIndex };\n });\n\n const updateRating = useCallback(\n (month: MonthValue, rating: RatingValue) => {\n if (readOnly) return;\n const item = monthData.find(d => d.month === month);\n if (!item || item.rowIndex < 0) return;\n dispatchFields({\n type: 'UPDATE',\n path: `${path}.${item.rowIndex}.rating`,\n value: rating,\n });\n setModified(true);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [dispatchFields, path, readOnly, setModified, JSON.stringify(monthData)]\n );\n\n return (\n <div\n className={[\n 'field-type',\n 'array',\n showError && 'error',\n readOnly && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <FieldLabel label={label} path={path} required={required} />\n <FieldError path={path} showError={showError} />\n <div\n style={{\n display: 'grid',\n gap: '0.75rem',\n gridTemplateColumns: 'repeat(auto-fit, minmax(9rem, 1fr))',\n marginTop: '0.75rem',\n }}\n >\n {monthData.map(item => {\n const activeRating =\n ratings.find(r => r.value === item.rating) ?? ratings[2];\n return (\n <div\n key={item.month}\n style={{\n background: 'var(--theme-elevation-50)',\n border: '1px solid var(--theme-elevation-150)',\n borderRadius: '0.375rem',\n padding: '0.75rem',\n }}\n >\n <div\n style={{\n alignItems: 'center',\n display: 'flex',\n gap: '0.5rem',\n justifyContent: 'space-between',\n marginBottom: '0.625rem',\n }}\n >\n <strong\n style={{ fontSize: '0.875rem', textTransform: 'uppercase' }}\n >\n {item.label}\n </strong>\n <span\n aria-hidden='true'\n style={{\n background: activeRating.colour,\n border: '1px solid var(--theme-elevation-150)',\n borderRadius: '999px',\n display: 'block',\n height: '1rem',\n width: '1rem',\n }}\n />\n </div>\n <div\n style={{\n display: 'grid',\n gridTemplateColumns: 'repeat(3, 1fr)',\n }}\n >\n {ratings.map(rating => {\n const isActive = item.rating === rating.value;\n return (\n <button\n key={rating.value}\n disabled={readOnly}\n onClick={event => {\n event.preventDefault();\n updateRating(item.month, rating.value);\n }}\n type='button'\n style={{\n background: isActive\n ? rating.colour\n : 'var(--theme-elevation-0)',\n border: isActive\n ? '1px solid var(--theme-text)'\n : '1px solid var(--theme-elevation-200)',\n color:\n isActive && rating.value !== 'ok'\n ? '#ffffff'\n : 'var(--theme-text)',\n fontSize: '0.75rem',\n padding: '0.4rem 0.3rem',\n }}\n >\n {rating.label}\n </button>\n );\n })}\n </div>\n </div>\n );\n })}\n </div>\n </div>\n );\n};\n"],"names":["FieldError","FieldLabel","useAllFormFields","useForm","useFormSubmitted","useCallback","months","label","value","ratings","colour","MonthRatingField","field","path","readOnly","required","fields","dispatchFields","submitted","setModified","arrayField","rows","showError","valid","monthData","map","month","monthLabel","rowIndex","findIndex","_","i","rating","updateRating","item","find","d","type","JSON","stringify","div","className","filter","Boolean","join","style","display","gap","gridTemplateColumns","marginTop","activeRating","r","background","border","borderRadius","padding","alignItems","justifyContent","marginBottom","strong","fontSize","textTransform","span","aria-hidden","height","width","isActive","button","disabled","onClick","event","preventDefault","color"],"mappings":"AAAA;;AAEA,SACEA,UAAU,EACVC,UAAU,EACVC,gBAAgB,EAChBC,OAAO,EACPC,gBAAgB,QACX,iBAAiB;AAGxB,SAASC,WAAW,QAAQ,QAAQ;AAiBpC,MAAMC,SAAiD;IACrD;QAAEC,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;IAC7B;QAAED,OAAO;QAAOC,OAAO;IAAM;CAC9B;AAED,6DAA6D;AAC7D,qEAAq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;oCAC7C,qBACE,KAAC2D;wCAECC,UAAUtD;wCACVuD,SAASC,CAAAA;4CACPA,MAAMC,cAAc;4CACpBtC,aAAaC,KAAKR,KAAK,EAAEM,OAAOxB,KAAK;wCACvC;wCACA6B,MAAK;wCACLQ,OAAO;4CACLO,YAAYc,WACRlC,OAAOtB,MAAM,GACb;4CACJ2C,QAAQa,WACJ,gCACA;4CACJM,OACEN,YAAYlC,OAAOxB,KAAK,KAAK,OACzB,YACA;4CACNoD,UAAU;4CACVL,SAAS;wCACX;kDAECvB,OAAOzB,KAAK;uCAtBRyB,OAAOxB,KAAK;gCAyBvB;;;uBArEG0B,KAAKR,KAAK;gBAyErB;;;;AAIR,EAAE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ArrayField } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* A fixed 12-row array rating each month best/good/ok — rendered as a compact
|
|
4
|
+
* month grid with a custom Field component (not the default array UI).
|
|
5
|
+
*/
|
|
6
|
+
export declare const bestTimeToVisitMonths: (name?: string) => ArrayField;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const MONTHS = [
|
|
2
|
+
'jan',
|
|
3
|
+
'feb',
|
|
4
|
+
'mar',
|
|
5
|
+
'apr',
|
|
6
|
+
'may',
|
|
7
|
+
'jun',
|
|
8
|
+
'jul',
|
|
9
|
+
'aug',
|
|
10
|
+
'sep',
|
|
11
|
+
'oct',
|
|
12
|
+
'nov',
|
|
13
|
+
'dec'
|
|
14
|
+
];
|
|
15
|
+
const MONTH_LABELS = {
|
|
16
|
+
jan: 'January',
|
|
17
|
+
feb: 'February',
|
|
18
|
+
mar: 'March',
|
|
19
|
+
apr: 'April',
|
|
20
|
+
may: 'May',
|
|
21
|
+
jun: 'June',
|
|
22
|
+
jul: 'July',
|
|
23
|
+
aug: 'August',
|
|
24
|
+
sep: 'September',
|
|
25
|
+
oct: 'October',
|
|
26
|
+
nov: 'November',
|
|
27
|
+
dec: 'December'
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A fixed 12-row array rating each month best/good/ok — rendered as a compact
|
|
31
|
+
* month grid with a custom Field component (not the default array UI).
|
|
32
|
+
*/ export const bestTimeToVisitMonths = (name = 'months')=>({
|
|
33
|
+
name,
|
|
34
|
+
label: 'Monthly Ratings',
|
|
35
|
+
type: 'array',
|
|
36
|
+
minRows: 12,
|
|
37
|
+
maxRows: 12,
|
|
38
|
+
defaultValue: MONTHS.map((month)=>({
|
|
39
|
+
month,
|
|
40
|
+
rating: 'ok'
|
|
41
|
+
})),
|
|
42
|
+
admin: {
|
|
43
|
+
description: 'Choose whether each month is best, good, or OK for visiting.',
|
|
44
|
+
initCollapsed: true,
|
|
45
|
+
components: {
|
|
46
|
+
Field: '@foundrykit/payload-fields/client#MonthRatingField'
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
fields: [
|
|
50
|
+
{
|
|
51
|
+
name: 'month',
|
|
52
|
+
type: 'select',
|
|
53
|
+
required: true,
|
|
54
|
+
options: MONTHS.map((value)=>({
|
|
55
|
+
label: MONTH_LABELS[value],
|
|
56
|
+
value
|
|
57
|
+
}))
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'rating',
|
|
61
|
+
type: 'select',
|
|
62
|
+
required: true,
|
|
63
|
+
defaultValue: 'ok',
|
|
64
|
+
options: [
|
|
65
|
+
{
|
|
66
|
+
label: 'Best Time to Visit',
|
|
67
|
+
value: 'best'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: 'Good Time to Visit',
|
|
71
|
+
value: 'good'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
label: 'OK Time to Visit',
|
|
75
|
+
value: 'ok'
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/bestTimeToVisit/index.ts"],"sourcesContent":["import type { ArrayField } from 'payload';\n\nconst MONTHS = [\n 'jan',\n 'feb',\n 'mar',\n 'apr',\n 'may',\n 'jun',\n 'jul',\n 'aug',\n 'sep',\n 'oct',\n 'nov',\n 'dec',\n] as const;\n\nconst MONTH_LABELS: Record<string, string> = {\n jan: 'January',\n feb: 'February',\n mar: 'March',\n apr: 'April',\n may: 'May',\n jun: 'June',\n jul: 'July',\n aug: 'August',\n sep: 'September',\n oct: 'October',\n nov: 'November',\n dec: 'December',\n};\n\n/**\n * A fixed 12-row array rating each month best/good/ok — rendered as a compact\n * month grid with a custom Field component (not the default array UI).\n */\nexport const bestTimeToVisitMonths = (name = 'months'): ArrayField => ({\n name,\n label: 'Monthly Ratings',\n type: 'array',\n minRows: 12,\n maxRows: 12,\n defaultValue: MONTHS.map(month => ({ month, rating: 'ok' })),\n admin: {\n description: 'Choose whether each month is best, good, or OK for visiting.',\n initCollapsed: true,\n components: { Field: '@foundrykit/payload-fields/client#MonthRatingField' },\n },\n fields: [\n {\n name: 'month',\n type: 'select',\n required: true,\n options: MONTHS.map(value => ({ label: MONTH_LABELS[value], value })),\n },\n {\n name: 'rating',\n type: 'select',\n required: true,\n defaultValue: 'ok',\n options: [\n { label: 'Best Time to Visit', value: 'best' },\n { label: 'Good Time to Visit', value: 'good' },\n { label: 'OK Time to Visit', value: 'ok' },\n ],\n },\n ],\n});\n"],"names":["MONTHS","MONTH_LABELS","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec","bestTimeToVisitMonths","name","label","type","minRows","maxRows","defaultValue","map","month","rating","admin","description","initCollapsed","components","Field","fields","required","options","value"],"mappings":"AAEA,MAAMA,SAAS;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,eAAuC;IAC3CC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;IACLC,KAAK;AACP;AAEA;;;CAGC,GACD,OAAO,MAAMC,wBAAwB,CAACC,OAAO,QAAQ,GAAkB,CAAA;QACrEA;QACAC,OAAO;QACPC,MAAM;QACNC,SAAS;QACTC,SAAS;QACTC,cAAcpB,OAAOqB,GAAG,CAACC,CAAAA,QAAU,CAAA;gBAAEA;gBAAOC,QAAQ;YAAK,CAAA;QACzDC,OAAO;YACLC,aAAa;YACbC,eAAe;YACfC,YAAY;gBAAEC,OAAO;YAAqD;QAC5E;QACAC,QAAQ;YACN;gBACEd,MAAM;gBACNE,MAAM;gBACNa,UAAU;gBACVC,SAAS/B,OAAOqB,GAAG,CAACW,CAAAA,QAAU,CAAA;wBAAEhB,OAAOf,YAAY,CAAC+B,MAAM;wBAAEA;oBAAM,CAAA;YACpE;YACA;gBACEjB,MAAM;gBACNE,MAAM;gBACNa,UAAU;gBACVV,cAAc;gBACdW,SAAS;oBACP;wBAAEf,OAAO;wBAAsBgB,OAAO;oBAAO;oBAC7C;wBAAEhB,OAAO;wBAAsBgB,OAAO;oBAAO;oBAC7C;wBAAEhB,OAAO;wBAAoBgB,OAAO;oBAAK;iBAC1C;YACH;SACD;IACH,CAAA,EAAG"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldError, FieldLabel, useField } from '@payloadcms/ui';
|
|
4
|
+
import { useCallback, useState } from 'react';
|
|
5
|
+
const formatPrice = (value)=>value.toLocaleString('en-GB', {
|
|
6
|
+
minimumFractionDigits: 2,
|
|
7
|
+
maximumFractionDigits: 2
|
|
8
|
+
});
|
|
9
|
+
export const PriceInput = ({ field, path, readOnly })=>{
|
|
10
|
+
const { label, required, admin: { placeholder } = {} } = field;
|
|
11
|
+
const { value, setValue, showError } = useField({
|
|
12
|
+
path
|
|
13
|
+
});
|
|
14
|
+
const [focused, setFocused] = useState(false);
|
|
15
|
+
const handleChange = useCallback((e)=>{
|
|
16
|
+
const raw = parseFloat(e.target.value);
|
|
17
|
+
setValue(isNaN(raw) ? null : raw);
|
|
18
|
+
}, [
|
|
19
|
+
setValue
|
|
20
|
+
]);
|
|
21
|
+
const displayValue = focused ? typeof value === 'number' ? value : '' : typeof value === 'number' ? formatPrice(value) : '';
|
|
22
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
23
|
+
className: [
|
|
24
|
+
'field-type',
|
|
25
|
+
'number',
|
|
26
|
+
showError && 'error',
|
|
27
|
+
readOnly && 'read-only'
|
|
28
|
+
].filter(Boolean).join(' '),
|
|
29
|
+
style: field.admin?.style,
|
|
30
|
+
children: [
|
|
31
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
32
|
+
label: label,
|
|
33
|
+
path: path,
|
|
34
|
+
required: required
|
|
35
|
+
}),
|
|
36
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
37
|
+
className: "field-type__wrap",
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ _jsx(FieldError, {
|
|
40
|
+
path: path,
|
|
41
|
+
showError: showError
|
|
42
|
+
}),
|
|
43
|
+
/*#__PURE__*/ _jsx("input", {
|
|
44
|
+
disabled: readOnly,
|
|
45
|
+
id: `field-${path.replace(/\./g, '__')}`,
|
|
46
|
+
min: 0,
|
|
47
|
+
name: path,
|
|
48
|
+
onBlur: ()=>setFocused(false),
|
|
49
|
+
onChange: handleChange,
|
|
50
|
+
onFocus: ()=>setFocused(true),
|
|
51
|
+
placeholder: placeholder,
|
|
52
|
+
step: "0.01",
|
|
53
|
+
type: focused ? 'number' : 'text',
|
|
54
|
+
value: displayValue,
|
|
55
|
+
style: {
|
|
56
|
+
width: '100%'
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=PriceInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/budget/PriceInput.tsx"],"sourcesContent":["'use client';\nimport { FieldError, FieldLabel, useField } from '@payloadcms/ui';\nimport type { NumberFieldClientProps } from 'payload';\nimport type React from 'react';\nimport { useCallback, useState } from 'react';\n\nconst formatPrice = (value: number): string =>\n value.toLocaleString('en-GB', {\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n });\n\nexport const PriceInput: React.FC<NumberFieldClientProps> = ({\n field,\n path,\n readOnly,\n}) => {\n const { label, required, admin: { placeholder } = {} } = field;\n const { value, setValue, showError } = useField<number>({ path });\n const [focused, setFocused] = useState(false);\n\n const handleChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const raw = parseFloat(e.target.value);\n setValue(isNaN(raw) ? null : raw);\n },\n [setValue]\n );\n\n const displayValue = focused\n ? typeof value === 'number'\n ? value\n : ''\n : typeof value === 'number'\n ? formatPrice(value)\n : '';\n\n return (\n <div\n className={[\n 'field-type',\n 'number',\n showError && 'error',\n readOnly && 'read-only',\n ]\n .filter(Boolean)\n .join(' ')}\n style={\n (field.admin as Record<string, unknown>)?.style as React.CSSProperties\n }\n >\n <FieldLabel label={label} path={path} required={required} />\n <div className='field-type__wrap'>\n <FieldError path={path} showError={showError} />\n <input\n disabled={readOnly}\n id={`field-${path.replace(/\\./g, '__')}`}\n min={0}\n name={path}\n onBlur={() => setFocused(false)}\n onChange={handleChange}\n onFocus={() => setFocused(true)}\n placeholder={placeholder as string | undefined}\n step='0.01'\n type={focused ? 'number' : 'text'}\n value={displayValue}\n style={{ width: '100%' }}\n />\n </div>\n </div>\n );\n};\n"],"names":["FieldError","FieldLabel","useField","useCallback","useState","formatPrice","value","toLocaleString","minimumFractionDigits","maximumFractionDigits","PriceInput","field","path","readOnly","label","required","admin","placeholder","setValue","showError","focused","setFocused","handleChange","e","raw","parseFloat","target","isNaN","displayValue","div","className","filter","Boolean","join","style","input","disabled","id","replace","min","name","onBlur","onChange","onFocus","step","type","width"],"mappings":"AAAA;;AACA,SAASA,UAAU,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,iBAAiB;AAGlE,SAASC,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAE9C,MAAMC,cAAc,CAACC,QACnBA,MAAMC,cAAc,CAAC,SAAS;QAC5BC,uBAAuB;QACvBC,uBAAuB;IACzB;AAEF,OAAO,MAAMC,aAA+C,CAAC,EAC3DC,KAAK,EACLC,IAAI,EACJC,QAAQ,EACT;IACC,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,WAAW,EAAE,GAAG,CAAC,CAAC,EAAE,GAAGN;IACzD,MAAM,EAAEL,KAAK,EAAEY,QAAQ,EAAEC,SAAS,EAAE,GAAGjB,SAAiB;QAAEU;IAAK;IAC/D,MAAM,CAACQ,SAASC,WAAW,GAAGjB,SAAS;IAEvC,MAAMkB,eAAenB,YACnB,CAACoB;QACC,MAAMC,MAAMC,WAAWF,EAAEG,MAAM,CAACpB,KAAK;QACrCY,SAASS,MAAMH,OAAO,OAAOA;IAC/B,GACA;QAACN;KAAS;IAGZ,MAAMU,eAAeR,UACjB,OAAOd,UAAU,WACfA,QACA,KACF,OAAOA,UAAU,WACfD,YAAYC,SACZ;IAEN,qBACE,MAACuB;QACCC,WAAW;YACT;YACA;YACAX,aAAa;YACbN,YAAY;SACb,CACEkB,MAAM,CAACC,SACPC,IAAI,CAAC;QACRC,OACGvB,MAAMK,KAAK,EAA8BkB;;0BAG5C,KAACjC;gBAAWa,OAAOA;gBAAOF,MAAMA;gBAAMG,UAAUA;;0BAChD,MAACc;gBAAIC,WAAU;;kCACb,KAAC9B;wBAAWY,MAAMA;wBAAMO,WAAWA;;kCACnC,KAACgB;wBACCC,UAAUvB;wBACVwB,IAAI,CAAC,MAAM,EAAEzB,KAAK0B,OAAO,CAAC,OAAO,OAAO;wBACxCC,KAAK;wBACLC,MAAM5B;wBACN6B,QAAQ,IAAMpB,WAAW;wBACzBqB,UAAUpB;wBACVqB,SAAS,IAAMtB,WAAW;wBAC1BJ,aAAaA;wBACb2B,MAAK;wBACLC,MAAMzB,UAAU,WAAW;wBAC3Bd,OAAOsB;wBACPM,OAAO;4BAAEY,OAAO;wBAAO;;;;;;AAKjC,EAAE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRowLabel } from '@payloadcms/ui';
|
|
4
|
+
export const BudgetRowLabel = ()=>{
|
|
5
|
+
const { data, rowNumber } = useRowLabel();
|
|
6
|
+
const fallback = `Budget ${(rowNumber ?? 0) + 1}`;
|
|
7
|
+
if (!data?.durationValue || !data?.price) return /*#__PURE__*/ _jsx("div", {
|
|
8
|
+
children: fallback
|
|
9
|
+
});
|
|
10
|
+
const duration = `${data.durationValue} ${data.durationUnit ?? ''}`;
|
|
11
|
+
const price = `£${Number(data.price).toLocaleString('en-GB')}`;
|
|
12
|
+
const per = data.per ? `per ${data.per}` : '';
|
|
13
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
14
|
+
children: [
|
|
15
|
+
duration,
|
|
16
|
+
price,
|
|
17
|
+
per
|
|
18
|
+
].filter(Boolean).join(' · ')
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=RowLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/budget/RowLabel.tsx"],"sourcesContent":["'use client';\nimport { type RowLabelProps, useRowLabel } from '@payloadcms/ui';\nimport type React from 'react';\n\ntype BudgetRow = {\n durationValue: number;\n durationUnit: 'nights' | 'days' | 'weeks';\n price: number;\n per: 'person' | 'couple' | 'group' | 'family';\n};\n\nexport const BudgetRowLabel: React.FC<RowLabelProps> = () => {\n const { data, rowNumber } = useRowLabel<BudgetRow>();\n const fallback = `Budget ${(rowNumber ?? 0) + 1}`;\n if (!data?.durationValue || !data?.price) return <div>{fallback}</div>;\n const duration = `${data.durationValue} ${data.durationUnit ?? ''}`;\n const price = `£${Number(data.price).toLocaleString('en-GB')}`;\n const per = data.per ? `per ${data.per}` : '';\n return <div>{[duration, price, per].filter(Boolean).join(' · ')}</div>;\n};\n"],"names":["useRowLabel","BudgetRowLabel","data","rowNumber","fallback","durationValue","price","div","duration","durationUnit","Number","toLocaleString","per","filter","Boolean","join"],"mappings":"AAAA;;AACA,SAA6BA,WAAW,QAAQ,iBAAiB;AAUjE,OAAO,MAAMC,iBAA0C;IACrD,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGH;IAC5B,MAAMI,WAAW,CAAC,OAAO,EAAE,AAACD,CAAAA,aAAa,CAAA,IAAK,GAAG;IACjD,IAAI,CAACD,MAAMG,iBAAiB,CAACH,MAAMI,OAAO,qBAAO,KAACC;kBAAKH;;IACvD,MAAMI,WAAW,GAAGN,KAAKG,aAAa,CAAC,CAAC,EAAEH,KAAKO,YAAY,IAAI,IAAI;IACnE,MAAMH,QAAQ,CAAC,CAAC,EAAEI,OAAOR,KAAKI,KAAK,EAAEK,cAAc,CAAC,UAAU;IAC9D,MAAMC,MAAMV,KAAKU,GAAG,GAAG,CAAC,IAAI,EAAEV,KAAKU,GAAG,EAAE,GAAG;IAC3C,qBAAO,KAACL;kBAAK;YAACC;YAAUF;YAAOM;SAAI,CAACC,MAAM,CAACC,SAASC,IAAI,CAAC;;AAC3D,EAAE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ArrayField } from 'payload';
|
|
2
|
+
type BudgetFieldOptions = {
|
|
3
|
+
name?: string;
|
|
4
|
+
admin?: Partial<ArrayField['admin']>;
|
|
5
|
+
};
|
|
6
|
+
/** Repeatable pricing rows: duration + price + per-unit, with conditional clarifications. */
|
|
7
|
+
export declare const budgetField: ({ name, admin, }?: BudgetFieldOptions) => ArrayField;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/** Repeatable pricing rows: duration + price + per-unit, with conditional clarifications. */ export const budgetField = ({ name = 'budget', admin = {} } = {})=>({
|
|
2
|
+
name,
|
|
3
|
+
type: 'array',
|
|
4
|
+
minRows: 1,
|
|
5
|
+
admin: {
|
|
6
|
+
...admin,
|
|
7
|
+
components: {
|
|
8
|
+
RowLabel: '@foundrykit/payload-fields/client#BudgetRowLabel'
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
fields: [
|
|
12
|
+
{
|
|
13
|
+
type: 'row',
|
|
14
|
+
fields: [
|
|
15
|
+
{
|
|
16
|
+
name: 'durationValue',
|
|
17
|
+
type: 'number',
|
|
18
|
+
label: 'Duration',
|
|
19
|
+
required: true,
|
|
20
|
+
min: 1,
|
|
21
|
+
admin: {
|
|
22
|
+
width: '25%',
|
|
23
|
+
placeholder: 'e.g. 10'
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'durationUnit',
|
|
28
|
+
type: 'select',
|
|
29
|
+
label: 'Unit',
|
|
30
|
+
required: true,
|
|
31
|
+
defaultValue: 'nights',
|
|
32
|
+
admin: {
|
|
33
|
+
width: '35%'
|
|
34
|
+
},
|
|
35
|
+
options: [
|
|
36
|
+
{
|
|
37
|
+
label: 'Nights',
|
|
38
|
+
value: 'nights'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: 'Days',
|
|
42
|
+
value: 'days'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: 'Weeks',
|
|
46
|
+
value: 'weeks'
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'price',
|
|
52
|
+
type: 'number',
|
|
53
|
+
label: 'Price (£)',
|
|
54
|
+
required: true,
|
|
55
|
+
min: 0,
|
|
56
|
+
admin: {
|
|
57
|
+
width: '40%',
|
|
58
|
+
placeholder: 'e.g. 12,352.00',
|
|
59
|
+
components: {
|
|
60
|
+
Field: '@foundrykit/payload-fields/client#PriceInput'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'per',
|
|
68
|
+
type: 'select',
|
|
69
|
+
label: 'Per',
|
|
70
|
+
required: true,
|
|
71
|
+
options: [
|
|
72
|
+
{
|
|
73
|
+
label: 'Person',
|
|
74
|
+
value: 'person'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
label: 'Couple',
|
|
78
|
+
value: 'couple'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: 'Group',
|
|
82
|
+
value: 'group'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
label: 'Family',
|
|
86
|
+
value: 'family'
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'groupDescription',
|
|
92
|
+
type: 'text',
|
|
93
|
+
label: 'Group clarification',
|
|
94
|
+
admin: {
|
|
95
|
+
placeholder: 'e.g. Groups of 6 or more',
|
|
96
|
+
condition: (_, siblingData)=>siblingData?.per === 'group'
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'familyDescription',
|
|
101
|
+
type: 'text',
|
|
102
|
+
label: 'Family clarification',
|
|
103
|
+
admin: {
|
|
104
|
+
placeholder: 'e.g. 2 adults and up to 3 children under 12',
|
|
105
|
+
condition: (_, siblingData)=>siblingData?.per === 'family'
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/budget/index.ts"],"sourcesContent":["import type { ArrayField } from 'payload';\n\ntype BudgetFieldOptions = {\n name?: string;\n admin?: Partial<ArrayField['admin']>;\n};\n\n/** Repeatable pricing rows: duration + price + per-unit, with conditional clarifications. */\nexport const budgetField = ({\n name = 'budget',\n admin = {},\n}: BudgetFieldOptions = {}): ArrayField => ({\n name,\n type: 'array',\n minRows: 1,\n admin: {\n ...admin,\n components: {\n RowLabel: '@foundrykit/payload-fields/client#BudgetRowLabel',\n },\n },\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'durationValue',\n type: 'number',\n label: 'Duration',\n required: true,\n min: 1,\n admin: { width: '25%', placeholder: 'e.g. 10' },\n },\n {\n name: 'durationUnit',\n type: 'select',\n label: 'Unit',\n required: true,\n defaultValue: 'nights',\n admin: { width: '35%' },\n options: [\n { label: 'Nights', value: 'nights' },\n { label: 'Days', value: 'days' },\n { label: 'Weeks', value: 'weeks' },\n ],\n },\n {\n name: 'price',\n type: 'number',\n label: 'Price (£)',\n required: true,\n min: 0,\n admin: {\n width: '40%',\n placeholder: 'e.g. 12,352.00',\n components: {\n Field: '@foundrykit/payload-fields/client#PriceInput',\n },\n },\n },\n ],\n },\n {\n name: 'per',\n type: 'select',\n label: 'Per',\n required: true,\n options: [\n { label: 'Person', value: 'person' },\n { label: 'Couple', value: 'couple' },\n { label: 'Group', value: 'group' },\n { label: 'Family', value: 'family' },\n ],\n },\n {\n name: 'groupDescription',\n type: 'text',\n label: 'Group clarification',\n admin: {\n placeholder: 'e.g. Groups of 6 or more',\n condition: (_, siblingData) => siblingData?.per === 'group',\n },\n },\n {\n name: 'familyDescription',\n type: 'text',\n label: 'Family clarification',\n admin: {\n placeholder: 'e.g. 2 adults and up to 3 children under 12',\n condition: (_, siblingData) => siblingData?.per === 'family',\n },\n },\n ],\n});\n"],"names":["budgetField","name","admin","type","minRows","components","RowLabel","fields","label","required","min","width","placeholder","defaultValue","options","value","Field","condition","_","siblingData","per"],"mappings":"AAOA,2FAA2F,GAC3F,OAAO,MAAMA,cAAc,CAAC,EAC1BC,OAAO,QAAQ,EACfC,QAAQ,CAAC,CAAC,EACS,GAAG,CAAC,CAAC,GAAkB,CAAA;QAC1C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A,EAAG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RelationshipField } from 'payload';
|
|
2
|
+
type ChangedByOptions = {
|
|
3
|
+
usersCollection?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* `createdBy` + `updatedBy` relationship fields (read-only), populated by
|
|
7
|
+
* `populateChangedBy`. Because versions snapshot the whole document, this gives
|
|
8
|
+
* per-version authorship for free.
|
|
9
|
+
*/
|
|
10
|
+
export declare const changedByFields: ({ usersCollection, }?: ChangedByOptions) => [RelationshipField, RelationshipField];
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createdBy` + `updatedBy` relationship fields (read-only), populated by
|
|
3
|
+
* `populateChangedBy`. Because versions snapshot the whole document, this gives
|
|
4
|
+
* per-version authorship for free.
|
|
5
|
+
*/ export const changedByFields = ({ usersCollection = 'users' } = {})=>{
|
|
6
|
+
const createdBy = {
|
|
7
|
+
name: 'createdBy',
|
|
8
|
+
type: 'relationship',
|
|
9
|
+
relationTo: usersCollection,
|
|
10
|
+
admin: {
|
|
11
|
+
readOnly: true,
|
|
12
|
+
position: 'sidebar'
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const updatedBy = {
|
|
16
|
+
name: 'updatedBy',
|
|
17
|
+
type: 'relationship',
|
|
18
|
+
relationTo: usersCollection,
|
|
19
|
+
admin: {
|
|
20
|
+
readOnly: true,
|
|
21
|
+
position: 'sidebar'
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return [
|
|
25
|
+
createdBy,
|
|
26
|
+
updatedBy
|
|
27
|
+
];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/changedBy/index.ts"],"sourcesContent":["import type { RelationshipField } from 'payload';\n\ntype ChangedByOptions = { usersCollection?: string };\n\n/**\n * `createdBy` + `updatedBy` relationship fields (read-only), populated by\n * `populateChangedBy`. Because versions snapshot the whole document, this gives\n * per-version authorship for free.\n */\nexport const changedByFields = ({\n usersCollection = 'users',\n}: ChangedByOptions = {}): [RelationshipField, RelationshipField] => {\n const createdBy: RelationshipField = {\n name: 'createdBy',\n type: 'relationship',\n relationTo: usersCollection,\n admin: { readOnly: true, position: 'sidebar' },\n };\n const updatedBy: RelationshipField = {\n name: 'updatedBy',\n type: 'relationship',\n relationTo: usersCollection,\n admin: { readOnly: true, position: 'sidebar' },\n };\n return [createdBy, updatedBy];\n};\n"],"names":["changedByFields","usersCollection","createdBy","name","type","relationTo","admin","readOnly","position","updatedBy"],"mappings":"AAIA;;;;CAIC,GACD,OAAO,MAAMA,kBAAkB,CAAC,EAC9BC,kBAAkB,OAAO,EACR,GAAG,CAAC,CAAC;IACtB,MAAMC,YAA+B;QACnCC,MAAM;QACNC,MAAM;QACNC,YAAYJ;QACZK,OAAO;YAAEC,UAAU;YAAMC,UAAU;QAAU;IAC/C;IACA,MAAMC,YAA+B;QACnCN,MAAM;QACNC,MAAM;QACNC,YAAYJ;QACZK,OAAO;YAAEC,UAAU;YAAMC,UAAU;QAAU;IAC/C;IACA,OAAO;QAACN;QAAWO;KAAU;AAC/B,EAAE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Stamps `req.user` onto `createdBy` (create) and `updatedBy` (every write). Pairs with `changedByFields()`. */ export const populateChangedBy = ({ data, operation, req })=>{
|
|
2
|
+
if (!req.user) return data;
|
|
3
|
+
return {
|
|
4
|
+
...data,
|
|
5
|
+
...operation === 'create' ? {
|
|
6
|
+
createdBy: req.user.id
|
|
7
|
+
} : {},
|
|
8
|
+
updatedBy: req.user.id
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=populateChangedBy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/changedBy/populateChangedBy.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload';\n\n/** Stamps `req.user` onto `createdBy` (create) and `updatedBy` (every write). Pairs with `changedByFields()`. */\nexport const populateChangedBy: CollectionBeforeChangeHook = ({\n data,\n operation,\n req,\n}) => {\n if (!req.user) return data;\n return {\n ...data,\n ...(operation === 'create' ? { createdBy: req.user.id } : {}),\n updatedBy: req.user.id,\n };\n};\n"],"names":["populateChangedBy","data","operation","req","user","createdBy","id","updatedBy"],"mappings":"AAEA,+GAA+G,GAC/G,OAAO,MAAMA,oBAAgD,CAAC,EAC5DC,IAAI,EACJC,SAAS,EACTC,GAAG,EACJ;IACC,IAAI,CAACA,IAAIC,IAAI,EAAE,OAAOH;IACtB,OAAO;QACL,GAAGA,IAAI;QACP,GAAIC,cAAc,WAAW;YAAEG,WAAWF,IAAIC,IAAI,CAACE,EAAE;QAAC,IAAI,CAAC,CAAC;QAC5DC,WAAWJ,IAAIC,IAAI,CAACE,EAAE;IACxB;AACF,EAAE"}
|