@foundrykit/menu-plugin 0.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/LICENSE +21 -0
- package/README.md +220 -0
- package/dist/cache.d.ts +11 -0
- package/dist/cache.js +45 -0
- package/dist/cache.js.map +1 -0
- package/dist/collections/Menus.d.ts +4 -0
- package/dist/collections/Menus.js +98 -0
- package/dist/collections/Menus.js.map +1 -0
- package/dist/components/BeforeDashboardClient.d.ts +1 -0
- package/dist/components/BeforeDashboardClient.js +40 -0
- package/dist/components/BeforeDashboardClient.js.map +1 -0
- package/dist/components/BeforeDashboardServer.d.ts +2 -0
- package/dist/components/BeforeDashboardServer.js +22 -0
- package/dist/components/BeforeDashboardServer.js.map +1 -0
- package/dist/components/BeforeDashboardServer.module.css +5 -0
- package/dist/components/MenuItemRowLabel.d.ts +1 -0
- package/dist/components/MenuItemRowLabel.js +12 -0
- package/dist/components/MenuItemRowLabel.js.map +1 -0
- package/dist/components/MenuPreview.d.ts +2 -0
- package/dist/components/MenuPreview.js +98 -0
- package/dist/components/MenuPreview.js.map +1 -0
- package/dist/components/SubMenuItemRowLabel.d.ts +1 -0
- package/dist/components/SubMenuItemRowLabel.js +12 -0
- package/dist/components/SubMenuItemRowLabel.js.map +1 -0
- package/dist/components/UrlField/countryCodes.d.ts +4 -0
- package/dist/components/UrlField/countryCodes.js +64 -0
- package/dist/components/UrlField/countryCodes.js.map +1 -0
- package/dist/components/UrlField/index.d.ts +2 -0
- package/dist/components/UrlField/index.js +285 -0
- package/dist/components/UrlField/index.js.map +1 -0
- package/dist/endpoints/customEndpointHandler.d.ts +2 -0
- package/dist/endpoints/customEndpointHandler.js +7 -0
- package/dist/endpoints/customEndpointHandler.js.map +1 -0
- package/dist/endpoints/exportMenusHandler.d.ts +2 -0
- package/dist/endpoints/exportMenusHandler.js +16 -0
- package/dist/endpoints/exportMenusHandler.js.map +1 -0
- package/dist/endpoints/getMenuHandler.d.ts +2 -0
- package/dist/endpoints/getMenuHandler.js +48 -0
- package/dist/endpoints/getMenuHandler.js.map +1 -0
- package/dist/endpoints/importMenusHandler.d.ts +2 -0
- package/dist/endpoints/importMenusHandler.js +63 -0
- package/dist/endpoints/importMenusHandler.js.map +1 -0
- package/dist/exports/client.d.ts +5 -0
- package/dist/exports/client.js +7 -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/MenuItem.d.ts +9 -0
- package/dist/fields/MenuItem.js +331 -0
- package/dist/fields/MenuItem.js.map +1 -0
- package/dist/hooks/useMenu.d.ts +13 -0
- package/dist/hooks/useMenu.js +77 -0
- package/dist/hooks/useMenu.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/package.json +140 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/SubMenuItemRowLabel.tsx"],"sourcesContent":["'use client'\n\nimport { useRowLabel } from '@payloadcms/ui'\n\nexport const SubMenuItemRowLabel = () => {\n const { data, rowNumber } = useRowLabel<{ label?: string }>()\n\n const customLabel = `Sub Menu Item: ${data.label || String(rowNumber).padStart(2, '0')}`\n\n return <div>{customLabel}</div>\n}\n"],"names":["useRowLabel","SubMenuItemRowLabel","data","rowNumber","customLabel","label","String","padStart","div"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,iBAAgB;AAE5C,OAAO,MAAMC,sBAAsB;IACjC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGH;IAE5B,MAAMI,cAAc,CAAC,eAAe,EAAEF,KAAKG,KAAK,IAAIC,OAAOH,WAAWI,QAAQ,CAAC,GAAG,MAAM;IAExF,qBAAO,KAACC;kBAAKJ;;AACf,EAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const COUNTRY_CODES = [
|
|
2
|
+
{
|
|
3
|
+
code: '+1',
|
|
4
|
+
label: 'US/CA (+1)'
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
code: '+44',
|
|
8
|
+
label: 'UK (+44)'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
code: '+33',
|
|
12
|
+
label: 'FR (+33)'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
code: '+49',
|
|
16
|
+
label: 'DE (+49)'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
code: '+61',
|
|
20
|
+
label: 'AU (+61)'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
code: '+81',
|
|
24
|
+
label: 'JP (+81)'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
code: '+86',
|
|
28
|
+
label: 'CN (+86)'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
code: '+91',
|
|
32
|
+
label: 'IN (+91)'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
code: '+55',
|
|
36
|
+
label: 'BR (+55)'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
code: '+52',
|
|
40
|
+
label: 'MX (+52)'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
code: '+39',
|
|
44
|
+
label: 'IT (+39)'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
code: '+34',
|
|
48
|
+
label: 'ES (+34)'
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
code: '+82',
|
|
52
|
+
label: 'KR (+82)'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
code: '+31',
|
|
56
|
+
label: 'NL (+31)'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
code: '+46',
|
|
60
|
+
label: 'SE (+46)'
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=countryCodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/UrlField/countryCodes.ts"],"sourcesContent":["export const COUNTRY_CODES = [\n { code: '+1', label: 'US/CA (+1)' },\n { code: '+44', label: 'UK (+44)' },\n { code: '+33', label: 'FR (+33)' },\n { code: '+49', label: 'DE (+49)' },\n { code: '+61', label: 'AU (+61)' },\n { code: '+81', label: 'JP (+81)' },\n { code: '+86', label: 'CN (+86)' },\n { code: '+91', label: 'IN (+91)' },\n { code: '+55', label: 'BR (+55)' },\n { code: '+52', label: 'MX (+52)' },\n { code: '+39', label: 'IT (+39)' },\n { code: '+34', label: 'ES (+34)' },\n { code: '+82', label: 'KR (+82)' },\n { code: '+31', label: 'NL (+31)' },\n { code: '+46', label: 'SE (+46)' },\n]\n"],"names":["COUNTRY_CODES","code","label"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB;IAC3B;QAAEC,MAAM;QAAMC,OAAO;IAAa;IAClC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;IACjC;QAAED,MAAM;QAAOC,OAAO;IAAW;CAClC,CAAA"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FieldDescription, FieldError, FieldLabel, TextInput, useField, useFormFields } from '@payloadcms/ui';
|
|
4
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
5
|
+
import { COUNTRY_CODES } from './countryCodes.js';
|
|
6
|
+
const parseTelValue = (val)=>{
|
|
7
|
+
if (!val || !val.startsWith('tel:')) return {
|
|
8
|
+
code: '+1',
|
|
9
|
+
number: ''
|
|
10
|
+
};
|
|
11
|
+
const raw = val.slice(4) // strip "tel:"
|
|
12
|
+
;
|
|
13
|
+
const match = COUNTRY_CODES.find((c)=>raw.startsWith(c.code));
|
|
14
|
+
if (match) {
|
|
15
|
+
return {
|
|
16
|
+
code: match.code,
|
|
17
|
+
number: raw.slice(match.code.length)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
code: '+1',
|
|
22
|
+
number: raw
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export const UrlField = ({ field, path: pathFromProps })=>{
|
|
26
|
+
const fieldPath = pathFromProps ?? field.name;
|
|
27
|
+
const { setValue, showError, value } = useField({
|
|
28
|
+
path: fieldPath
|
|
29
|
+
});
|
|
30
|
+
const baseUrl = field.admin?.custom?.baseUrl || '';
|
|
31
|
+
// Compute sibling path for the 'type' field
|
|
32
|
+
const pathParts = fieldPath.split('.');
|
|
33
|
+
pathParts[pathParts.length - 1] = 'type';
|
|
34
|
+
const typePath = pathParts.join('.');
|
|
35
|
+
const menuItemType = useFormFields(([fields])=>{
|
|
36
|
+
return fields[typePath]?.value ?? 'custom';
|
|
37
|
+
});
|
|
38
|
+
const prevTypeRef = useRef(menuItemType);
|
|
39
|
+
// Clear value when type changes
|
|
40
|
+
useEffect(()=>{
|
|
41
|
+
if (prevTypeRef.current !== menuItemType) {
|
|
42
|
+
prevTypeRef.current = menuItemType;
|
|
43
|
+
setValue('');
|
|
44
|
+
}
|
|
45
|
+
}, [
|
|
46
|
+
menuItemType,
|
|
47
|
+
setValue
|
|
48
|
+
]);
|
|
49
|
+
const handleTextChange = useCallback((e)=>{
|
|
50
|
+
setValue(e.target.value);
|
|
51
|
+
}, [
|
|
52
|
+
setValue
|
|
53
|
+
]);
|
|
54
|
+
const handleInternalChange = useCallback((e)=>{
|
|
55
|
+
const path = e.target.value;
|
|
56
|
+
setValue(baseUrl + path);
|
|
57
|
+
}, [
|
|
58
|
+
setValue,
|
|
59
|
+
baseUrl
|
|
60
|
+
]);
|
|
61
|
+
const handleAnchorChange = useCallback((e)=>{
|
|
62
|
+
const anchor = e.target.value.replace(/^#/, '');
|
|
63
|
+
setValue(`#${anchor}`);
|
|
64
|
+
}, [
|
|
65
|
+
setValue
|
|
66
|
+
]);
|
|
67
|
+
const handleMailtoChange = useCallback((e)=>{
|
|
68
|
+
const email = e.target.value.replace(/^mailto:/, '');
|
|
69
|
+
setValue(`mailto:${email}`);
|
|
70
|
+
}, [
|
|
71
|
+
setValue
|
|
72
|
+
]);
|
|
73
|
+
const handleTelCodeChange = useCallback((e)=>{
|
|
74
|
+
const { number } = parseTelValue(value || '');
|
|
75
|
+
setValue(`tel:${e.target.value}${number}`);
|
|
76
|
+
}, [
|
|
77
|
+
setValue,
|
|
78
|
+
value
|
|
79
|
+
]);
|
|
80
|
+
const handleTelNumberChange = useCallback((e)=>{
|
|
81
|
+
const { code } = parseTelValue(value || '');
|
|
82
|
+
setValue(`tel:${code}${e.target.value}`);
|
|
83
|
+
}, [
|
|
84
|
+
setValue,
|
|
85
|
+
value
|
|
86
|
+
]);
|
|
87
|
+
// Parse display values from stored value
|
|
88
|
+
const getInternalPath = ()=>{
|
|
89
|
+
if (!value) return '';
|
|
90
|
+
if (baseUrl && value.startsWith(baseUrl)) return value.slice(baseUrl.length);
|
|
91
|
+
return value;
|
|
92
|
+
};
|
|
93
|
+
const getAnchorValue = ()=>{
|
|
94
|
+
if (!value) return '';
|
|
95
|
+
return value.replace(/^#/, '');
|
|
96
|
+
};
|
|
97
|
+
const getMailtoValue = ()=>{
|
|
98
|
+
if (!value) return '';
|
|
99
|
+
return value.replace(/^mailto:/, '');
|
|
100
|
+
};
|
|
101
|
+
const renderInput = ()=>{
|
|
102
|
+
switch(menuItemType){
|
|
103
|
+
case 'anchor':
|
|
104
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
105
|
+
style: {
|
|
106
|
+
display: 'flex',
|
|
107
|
+
gap: '4px',
|
|
108
|
+
width: '100%'
|
|
109
|
+
},
|
|
110
|
+
children: [
|
|
111
|
+
/*#__PURE__*/ _jsx("span", {
|
|
112
|
+
style: {
|
|
113
|
+
alignItems: 'center',
|
|
114
|
+
background: 'var(--theme-elevation-100)',
|
|
115
|
+
borderRadius: '4px',
|
|
116
|
+
display: 'flex',
|
|
117
|
+
fontSize: '13px',
|
|
118
|
+
padding: '0 8px',
|
|
119
|
+
whiteSpace: 'nowrap'
|
|
120
|
+
},
|
|
121
|
+
children: "#"
|
|
122
|
+
}),
|
|
123
|
+
/*#__PURE__*/ _jsx("div", {
|
|
124
|
+
style: {
|
|
125
|
+
flex: 1
|
|
126
|
+
},
|
|
127
|
+
children: /*#__PURE__*/ _jsx(TextInput, {
|
|
128
|
+
onChange: handleAnchorChange,
|
|
129
|
+
path: fieldPath,
|
|
130
|
+
placeholder: "section-name",
|
|
131
|
+
value: getAnchorValue()
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
case 'external':
|
|
137
|
+
return /*#__PURE__*/ _jsx(TextInput, {
|
|
138
|
+
onChange: handleTextChange,
|
|
139
|
+
path: fieldPath,
|
|
140
|
+
placeholder: "https://example.com",
|
|
141
|
+
value: value || ''
|
|
142
|
+
});
|
|
143
|
+
case 'internal':
|
|
144
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
145
|
+
style: {
|
|
146
|
+
display: 'flex',
|
|
147
|
+
gap: '4px',
|
|
148
|
+
width: '100%'
|
|
149
|
+
},
|
|
150
|
+
children: [
|
|
151
|
+
/*#__PURE__*/ _jsx("span", {
|
|
152
|
+
style: {
|
|
153
|
+
alignItems: 'center',
|
|
154
|
+
background: 'var(--theme-elevation-100)',
|
|
155
|
+
borderRadius: '4px',
|
|
156
|
+
display: 'flex',
|
|
157
|
+
fontSize: '13px',
|
|
158
|
+
padding: '0 8px',
|
|
159
|
+
whiteSpace: 'nowrap'
|
|
160
|
+
},
|
|
161
|
+
children: baseUrl || '/'
|
|
162
|
+
}),
|
|
163
|
+
/*#__PURE__*/ _jsx("div", {
|
|
164
|
+
style: {
|
|
165
|
+
flex: 1
|
|
166
|
+
},
|
|
167
|
+
children: /*#__PURE__*/ _jsx(TextInput, {
|
|
168
|
+
onChange: handleInternalChange,
|
|
169
|
+
path: fieldPath,
|
|
170
|
+
placeholder: "/page-path",
|
|
171
|
+
value: getInternalPath()
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
]
|
|
175
|
+
});
|
|
176
|
+
case 'mailto':
|
|
177
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
178
|
+
style: {
|
|
179
|
+
display: 'flex',
|
|
180
|
+
gap: '4px',
|
|
181
|
+
width: '100%'
|
|
182
|
+
},
|
|
183
|
+
children: [
|
|
184
|
+
/*#__PURE__*/ _jsx("span", {
|
|
185
|
+
style: {
|
|
186
|
+
alignItems: 'center',
|
|
187
|
+
background: 'var(--theme-elevation-100)',
|
|
188
|
+
borderRadius: '4px',
|
|
189
|
+
display: 'flex',
|
|
190
|
+
fontSize: '13px',
|
|
191
|
+
padding: '0 8px',
|
|
192
|
+
whiteSpace: 'nowrap'
|
|
193
|
+
},
|
|
194
|
+
children: "mailto:"
|
|
195
|
+
}),
|
|
196
|
+
/*#__PURE__*/ _jsx("div", {
|
|
197
|
+
style: {
|
|
198
|
+
flex: 1
|
|
199
|
+
},
|
|
200
|
+
children: /*#__PURE__*/ _jsx(TextInput, {
|
|
201
|
+
onChange: handleMailtoChange,
|
|
202
|
+
path: fieldPath,
|
|
203
|
+
placeholder: "user@example.com",
|
|
204
|
+
value: getMailtoValue()
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
]
|
|
208
|
+
});
|
|
209
|
+
case 'reference':
|
|
210
|
+
return null;
|
|
211
|
+
case 'tel':
|
|
212
|
+
{
|
|
213
|
+
const { code, number } = parseTelValue(value || '');
|
|
214
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
215
|
+
style: {
|
|
216
|
+
display: 'flex',
|
|
217
|
+
gap: '4px',
|
|
218
|
+
width: '100%'
|
|
219
|
+
},
|
|
220
|
+
children: [
|
|
221
|
+
/*#__PURE__*/ _jsx("select", {
|
|
222
|
+
onChange: handleTelCodeChange,
|
|
223
|
+
style: {
|
|
224
|
+
background: 'var(--theme-input-bg)',
|
|
225
|
+
border: '1px solid var(--theme-elevation-150)',
|
|
226
|
+
borderRadius: '4px',
|
|
227
|
+
color: 'var(--theme-text)',
|
|
228
|
+
fontSize: '13px',
|
|
229
|
+
padding: '8px'
|
|
230
|
+
},
|
|
231
|
+
value: code,
|
|
232
|
+
children: COUNTRY_CODES.map((c)=>/*#__PURE__*/ _jsx("option", {
|
|
233
|
+
value: c.code,
|
|
234
|
+
children: c.label
|
|
235
|
+
}, c.code))
|
|
236
|
+
}),
|
|
237
|
+
/*#__PURE__*/ _jsx("div", {
|
|
238
|
+
style: {
|
|
239
|
+
flex: 1
|
|
240
|
+
},
|
|
241
|
+
children: /*#__PURE__*/ _jsx(TextInput, {
|
|
242
|
+
onChange: handleTelNumberChange,
|
|
243
|
+
path: fieldPath,
|
|
244
|
+
placeholder: "555-1234",
|
|
245
|
+
value: number
|
|
246
|
+
})
|
|
247
|
+
})
|
|
248
|
+
]
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
default:
|
|
252
|
+
return /*#__PURE__*/ _jsx(TextInput, {
|
|
253
|
+
onChange: handleTextChange,
|
|
254
|
+
path: fieldPath,
|
|
255
|
+
placeholder: "Enter URL",
|
|
256
|
+
value: value || ''
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
if (menuItemType === 'reference') {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
264
|
+
style: {
|
|
265
|
+
...field.admin?.width ? {
|
|
266
|
+
'--field-width': field.admin.width
|
|
267
|
+
} : {
|
|
268
|
+
flex: '1 1 auto'
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
children: [
|
|
272
|
+
/*#__PURE__*/ _jsx(FieldLabel, {
|
|
273
|
+
label: field.label || 'URL'
|
|
274
|
+
}),
|
|
275
|
+
showError && /*#__PURE__*/ _jsx(FieldError, {}),
|
|
276
|
+
renderInput(),
|
|
277
|
+
field.admin?.description && /*#__PURE__*/ _jsx(FieldDescription, {
|
|
278
|
+
description: field.admin.description,
|
|
279
|
+
path: fieldPath
|
|
280
|
+
})
|
|
281
|
+
]
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/UrlField/index.tsx"],"sourcesContent":["'use client'\n\nimport type { TextFieldClientComponent } from 'payload'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n TextInput,\n useField,\n useFormFields,\n} from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useRef } from 'react'\n\nimport { COUNTRY_CODES } from './countryCodes.js'\n\nconst parseTelValue = (val: string): { code: string; number: string } => {\n if (!val || !val.startsWith('tel:')) return { code: '+1', number: '' }\n const raw = val.slice(4) // strip \"tel:\"\n const match = COUNTRY_CODES.find((c) => raw.startsWith(c.code))\n if (match) {\n return { code: match.code, number: raw.slice(match.code.length) }\n }\n return { code: '+1', number: raw }\n}\n\nexport const UrlField: TextFieldClientComponent = ({ field, path: pathFromProps }) => {\n const fieldPath = pathFromProps ?? field.name\n const { setValue, showError, value } = useField<string>({ path: fieldPath })\n\n const baseUrl = (field.admin?.custom?.baseUrl as string) || ''\n\n // Compute sibling path for the 'type' field\n const pathParts = fieldPath.split('.')\n pathParts[pathParts.length - 1] = 'type'\n const typePath = pathParts.join('.')\n\n const menuItemType = useFormFields(([fields]) => {\n return (fields[typePath]?.value as string) ?? 'custom'\n })\n\n const prevTypeRef = useRef(menuItemType)\n\n // Clear value when type changes\n useEffect(() => {\n if (prevTypeRef.current !== menuItemType) {\n prevTypeRef.current = menuItemType\n setValue('')\n }\n }, [menuItemType, setValue])\n\n const handleTextChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setValue(e.target.value)\n },\n [setValue],\n )\n\n const handleInternalChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const path = e.target.value\n setValue(baseUrl + path)\n },\n [setValue, baseUrl],\n )\n\n const handleAnchorChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const anchor = e.target.value.replace(/^#/, '')\n setValue(`#${anchor}`)\n },\n [setValue],\n )\n\n const handleMailtoChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const email = e.target.value.replace(/^mailto:/, '')\n setValue(`mailto:${email}`)\n },\n [setValue],\n )\n\n const handleTelCodeChange = useCallback(\n (e: React.ChangeEvent<HTMLSelectElement>) => {\n const { number } = parseTelValue(value || '')\n setValue(`tel:${e.target.value}${number}`)\n },\n [setValue, value],\n )\n\n const handleTelNumberChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const { code } = parseTelValue(value || '')\n setValue(`tel:${code}${e.target.value}`)\n },\n [setValue, value],\n )\n\n // Parse display values from stored value\n const getInternalPath = (): string => {\n if (!value) return ''\n if (baseUrl && value.startsWith(baseUrl)) return value.slice(baseUrl.length)\n return value\n }\n\n const getAnchorValue = (): string => {\n if (!value) return ''\n return value.replace(/^#/, '')\n }\n\n const getMailtoValue = (): string => {\n if (!value) return ''\n return value.replace(/^mailto:/, '')\n }\n\n const renderInput = () => {\n switch (menuItemType) {\n case 'anchor':\n return (\n <div style={{ display: 'flex', gap: '4px', width: '100%' }}>\n <span\n style={{\n alignItems: 'center',\n background: 'var(--theme-elevation-100)',\n borderRadius: '4px',\n display: 'flex',\n fontSize: '13px',\n padding: '0 8px',\n whiteSpace: 'nowrap',\n }}\n >\n #\n </span>\n <div style={{ flex: 1 }}>\n <TextInput\n onChange={handleAnchorChange}\n path={fieldPath}\n placeholder=\"section-name\"\n value={getAnchorValue()}\n />\n </div>\n </div>\n )\n\n case 'external':\n return (\n <TextInput\n onChange={handleTextChange}\n path={fieldPath}\n placeholder=\"https://example.com\"\n value={value || ''}\n />\n )\n\n case 'internal':\n return (\n <div style={{ display: 'flex', gap: '4px', width: '100%' }}>\n <span\n style={{\n alignItems: 'center',\n background: 'var(--theme-elevation-100)',\n borderRadius: '4px',\n display: 'flex',\n fontSize: '13px',\n padding: '0 8px',\n whiteSpace: 'nowrap',\n }}\n >\n {baseUrl || '/'}\n </span>\n <div style={{ flex: 1 }}>\n <TextInput\n onChange={handleInternalChange}\n path={fieldPath}\n placeholder=\"/page-path\"\n value={getInternalPath()}\n />\n </div>\n </div>\n )\n\n case 'mailto':\n return (\n <div style={{ display: 'flex', gap: '4px', width: '100%' }}>\n <span\n style={{\n alignItems: 'center',\n background: 'var(--theme-elevation-100)',\n borderRadius: '4px',\n display: 'flex',\n fontSize: '13px',\n padding: '0 8px',\n whiteSpace: 'nowrap',\n }}\n >\n mailto:\n </span>\n <div style={{ flex: 1 }}>\n <TextInput\n onChange={handleMailtoChange}\n path={fieldPath}\n placeholder=\"user@example.com\"\n value={getMailtoValue()}\n />\n </div>\n </div>\n )\n\n case 'reference':\n return null\n\n case 'tel': {\n const { code, number } = parseTelValue(value || '')\n return (\n <div style={{ display: 'flex', gap: '4px', width: '100%' }}>\n <select\n onChange={handleTelCodeChange}\n style={{\n background: 'var(--theme-input-bg)',\n border: '1px solid var(--theme-elevation-150)',\n borderRadius: '4px',\n color: 'var(--theme-text)',\n fontSize: '13px',\n padding: '8px',\n }}\n value={code}\n >\n {COUNTRY_CODES.map((c) => (\n <option key={c.code} value={c.code}>\n {c.label}\n </option>\n ))}\n </select>\n <div style={{ flex: 1 }}>\n <TextInput\n onChange={handleTelNumberChange}\n path={fieldPath}\n placeholder=\"555-1234\"\n value={number}\n />\n </div>\n </div>\n )\n }\n\n default:\n return (\n <TextInput\n onChange={handleTextChange}\n path={fieldPath}\n placeholder=\"Enter URL\"\n value={value || ''}\n />\n )\n }\n }\n\n if (menuItemType === 'reference') {\n return null\n }\n\n return (\n <div\n style={\n {\n ...(field.admin?.width ? { '--field-width': field.admin.width } : { flex: '1 1 auto' }),\n } as React.CSSProperties\n }\n >\n <FieldLabel label={field.label || 'URL'} />\n {showError && <FieldError />}\n {renderInput()}\n {field.admin?.description && (\n <FieldDescription description={field.admin.description} path={fieldPath} />\n )}\n </div>\n )\n}\n"],"names":["FieldDescription","FieldError","FieldLabel","TextInput","useField","useFormFields","React","useCallback","useEffect","useRef","COUNTRY_CODES","parseTelValue","val","startsWith","code","number","raw","slice","match","find","c","length","UrlField","field","path","pathFromProps","fieldPath","name","setValue","showError","value","baseUrl","admin","custom","pathParts","split","typePath","join","menuItemType","fields","prevTypeRef","current","handleTextChange","e","target","handleInternalChange","handleAnchorChange","anchor","replace","handleMailtoChange","email","handleTelCodeChange","handleTelNumberChange","getInternalPath","getAnchorValue","getMailtoValue","renderInput","div","style","display","gap","width","span","alignItems","background","borderRadius","fontSize","padding","whiteSpace","flex","onChange","placeholder","select","border","color","map","option","label","description"],"mappings":"AAAA;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,SAAS,EACTC,QAAQ,EACRC,aAAa,QACR,iBAAgB;AACvB,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,QAAO;AAE7D,SAASC,aAAa,QAAQ,oBAAmB;AAEjD,MAAMC,gBAAgB,CAACC;IACrB,IAAI,CAACA,OAAO,CAACA,IAAIC,UAAU,CAAC,SAAS,OAAO;QAAEC,MAAM;QAAMC,QAAQ;IAAG;IACrE,MAAMC,MAAMJ,IAAIK,KAA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GAAGJ,cAAcmB,SAAS;oBAChD,qBACE,MAAC2B;wBAAIC,OAAO;4BAAEC,SAAS;4BAAQC,KAAK;4BAAOC,OAAO;wBAAO;;0CACvD,KAACW;gCACCF,UAAUnB;gCACVO,OAAO;oCACLM,YAAY;oCACZS,QAAQ;oCACRR,cAAc;oCACdS,OAAO;oCACPR,UAAU;oCACVC,SAAS;gCACX;gCACArC,OAAOhB;0CAENJ,cAAciE,GAAG,CAAC,CAACvD,kBAClB,KAACwD;wCAAoB9C,OAAOV,EAAEN,IAAI;kDAC/BM,EAAEyD,KAAK;uCADGzD,EAAEN,IAAI;;0CAKvB,KAAC2C;gCAAIC,OAAO;oCAAEW,MAAM;gCAAE;0CACpB,cAAA,KAAClE;oCACCmE,UAAUlB;oCACV5B,MAAME;oCACN6C,aAAY;oCACZzC,OAAOf;;;;;gBAKjB;YAEA;gBACE,qBACE,KAACZ;oBACCmE,UAAU5B;oBACVlB,MAAME;oBACN6C,aAAY;oBACZzC,OAAOA,SAAS;;QAGxB;IACF;IAEA,IAAIQ,iBAAiB,aAAa;QAChC,OAAO;IACT;IAEA,qBACE,MAACmB;QACCC,OACE;YACE,GAAInC,MAAMS,KAAK,EAAE6B,QAAQ;gBAAE,iBAAiBtC,MAAMS,KAAK,CAAC6B,KAAK;YAAC,IAAI;gBAAEQ,MAAM;YAAW,CAAC;QACxF;;0BAGF,KAACnE;gBAAW2E,OAAOtD,MAAMsD,KAAK,IAAI;;YACjChD,2BAAa,KAAC5B;YACduD;YACAjC,MAAMS,KAAK,EAAE8C,6BACZ,KAAC9E;gBAAiB8E,aAAavD,MAAMS,KAAK,CAAC8C,WAAW;gBAAEtD,MAAME;;;;AAItE,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/customEndpointHandler.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nexport const customEndpointHandler: PayloadHandler = () => {\n return Response.json({ message: 'Hello from custom endpoint' })\n}\n"],"names":["customEndpointHandler","Response","json","message"],"mappings":"AAEA,OAAO,MAAMA,wBAAwC;IACnD,OAAOC,SAASC,IAAI,CAAC;QAAEC,SAAS;IAA6B;AAC/D,EAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const exportMenusHandler = async (req)=>{
|
|
2
|
+
const { payload } = req;
|
|
3
|
+
const result = await payload.find({
|
|
4
|
+
collection: 'menus',
|
|
5
|
+
limit: 0,
|
|
6
|
+
pagination: false
|
|
7
|
+
});
|
|
8
|
+
return new Response(JSON.stringify(result.docs, null, 2), {
|
|
9
|
+
headers: {
|
|
10
|
+
'Content-Disposition': 'attachment; filename="menus-export.json"',
|
|
11
|
+
'Content-Type': 'application/json'
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=exportMenusHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/exportMenusHandler.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nexport const exportMenusHandler: PayloadHandler = async (req) => {\n const { payload } = req\n\n const result = await payload.find({\n collection: 'menus',\n limit: 0,\n pagination: false,\n })\n\n return new Response(JSON.stringify(result.docs, null, 2), {\n headers: {\n 'Content-Disposition': 'attachment; filename=\"menus-export.json\"',\n 'Content-Type': 'application/json',\n },\n })\n}\n"],"names":["exportMenusHandler","req","payload","result","find","collection","limit","pagination","Response","JSON","stringify","docs","headers"],"mappings":"AAEA,OAAO,MAAMA,qBAAqC,OAAOC;IACvD,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAME,SAAS,MAAMD,QAAQE,IAAI,CAAC;QAChCC,YAAY;QACZC,OAAO;QACPC,YAAY;IACd;IAEA,OAAO,IAAIC,SAASC,KAAKC,SAAS,CAACP,OAAOQ,IAAI,EAAE,MAAM,IAAI;QACxDC,SAAS;YACP,uBAAuB;YACvB,gBAAgB;QAClB;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { menuCache } from '../cache.js';
|
|
2
|
+
export const getMenuHandler = async (req)=>{
|
|
3
|
+
const { payload, routeParams } = req;
|
|
4
|
+
const slug = routeParams?.slug;
|
|
5
|
+
if (!slug) {
|
|
6
|
+
return Response.json({
|
|
7
|
+
error: 'Menu slug is required'
|
|
8
|
+
}, {
|
|
9
|
+
status: 400
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
const url = new URL(req.url || '', 'http://localhost');
|
|
13
|
+
const locale = url.searchParams.get('locale') || undefined;
|
|
14
|
+
const depth = parseInt(url.searchParams.get('depth') || '0', 10);
|
|
15
|
+
// Check cache first
|
|
16
|
+
const cached = menuCache.get(slug, locale);
|
|
17
|
+
if (cached) {
|
|
18
|
+
return Response.json(cached);
|
|
19
|
+
}
|
|
20
|
+
const where = {
|
|
21
|
+
slug: {
|
|
22
|
+
equals: slug
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
if (locale) {
|
|
26
|
+
where.locale = {
|
|
27
|
+
equals: locale
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const result = await payload.find({
|
|
31
|
+
collection: 'menus',
|
|
32
|
+
depth,
|
|
33
|
+
limit: 1,
|
|
34
|
+
where
|
|
35
|
+
});
|
|
36
|
+
if (result.docs.length === 0) {
|
|
37
|
+
return Response.json({
|
|
38
|
+
error: `Menu '${slug}' not found`
|
|
39
|
+
}, {
|
|
40
|
+
status: 404
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const menu = result.docs[0];
|
|
44
|
+
menuCache.set(slug, menu, locale);
|
|
45
|
+
return Response.json(menu);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=getMenuHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/getMenuHandler.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nimport { menuCache } from '../cache.js'\n\nexport const getMenuHandler: PayloadHandler = async (req) => {\n const { payload, routeParams } = req\n const slug = routeParams?.slug as string | undefined\n\n if (!slug) {\n return Response.json({ error: 'Menu slug is required' }, { status: 400 })\n }\n\n const url = new URL(req.url || '', 'http://localhost')\n const locale = url.searchParams.get('locale') || undefined\n const depth = parseInt(url.searchParams.get('depth') || '0', 10)\n\n // Check cache first\n const cached = menuCache.get(slug, locale)\n if (cached) {\n return Response.json(cached)\n }\n\n const where: Record<string, any> = {\n slug: { equals: slug },\n }\n\n if (locale) {\n where.locale = { equals: locale }\n }\n\n const result = await payload.find({\n collection: 'menus',\n depth,\n limit: 1,\n where,\n })\n\n if (result.docs.length === 0) {\n return Response.json({ error: `Menu '${slug}' not found` }, { status: 404 })\n }\n\n const menu = result.docs[0]\n menuCache.set(slug, menu, locale)\n\n return Response.json(menu)\n}\n"],"names":["menuCache","getMenuHandler","req","payload","routeParams","slug","Response","json","error","status","url","URL","locale","searchParams","get","undefined","depth","parseInt","cached","where","equals","result","find","collection","limit","docs","length","menu","set"],"mappings":"AAEA,SAASA,SAAS,QAAQ,cAAa;AAEvC,OAAO,MAAMC,iBAAiC,OAAOC;IACnD,MAAM,EAAEC,OAAO,EAAEC,WAAW,EAAE,GAAGF;IACjC,MAAMG,OAAOD,aAAaC;IAE1B,IAAI,CAACA,MAAM;QACT,OAAOC,SAASC,IAAI,CAAC;YAAEC,OAAO;QAAwB,GAAG;YAAEC,QAAQ;QAAI;IACzE;IAEA,MAAMC,MAAM,IAAIC,IAAIT,IAAIQ,GAAG,IAAI,IAAI;IACnC,MAAME,SAASF,IAAIG,YAAY,CAACC,GAAG,CAAC,aAAaC;IACjD,MAAMC,QAAQC,SAASP,IAAIG,YAAY,CAACC,GAAG,CAAC,YAAY,KAAK;IAE7D,oBAAoB;IACpB,MAAMI,SAASlB,UAAUc,GAAG,CAACT,MAAMO;IACnC,IAAIM,QAAQ;QACV,OAAOZ,SAASC,IAAI,CAACW;IACvB;IAEA,MAAMC,QAA6B;QACjCd,MAAM;YAAEe,QAAQf;QAAK;IACvB;IAEA,IAAIO,QAAQ;QACVO,MAAMP,MAAM,GAAG;YAAEQ,QAAQR;QAAO;IAClC;IAEA,MAAMS,SAAS,MAAMlB,QAAQmB,IAAI,CAAC;QAChCC,YAAY;QACZP;QACAQ,OAAO;QACPL;IACF;IAEA,IAAIE,OAAOI,IAAI,CAACC,MAAM,KAAK,GAAG;QAC5B,OAAOpB,SAASC,IAAI,CAAC;YAAEC,OAAO,CAAC,MAAM,EAAEH,KAAK,WAAW,CAAC;QAAC,GAAG;YAAEI,QAAQ;QAAI;IAC5E;IAEA,MAAMkB,OAAON,OAAOI,IAAI,CAAC,EAAE;IAC3BzB,UAAU4B,GAAG,CAACvB,MAAMsB,MAAMf;IAE1B,OAAON,SAASC,IAAI,CAACoB;AACvB,EAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const importMenusHandler = async (req)=>{
|
|
2
|
+
const { payload } = req;
|
|
3
|
+
let menus;
|
|
4
|
+
try {
|
|
5
|
+
const body = await req.json?.();
|
|
6
|
+
menus = Array.isArray(body) ? body : body?.menus;
|
|
7
|
+
if (!Array.isArray(menus)) {
|
|
8
|
+
return Response.json({
|
|
9
|
+
error: 'Request body must be a JSON array of menus or { menus: [...] }'
|
|
10
|
+
}, {
|
|
11
|
+
status: 400
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
} catch {
|
|
15
|
+
return Response.json({
|
|
16
|
+
error: 'Invalid JSON body'
|
|
17
|
+
}, {
|
|
18
|
+
status: 400
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const results = {
|
|
22
|
+
created: 0,
|
|
23
|
+
errors: [],
|
|
24
|
+
updated: 0
|
|
25
|
+
};
|
|
26
|
+
for (const menu of menus){
|
|
27
|
+
try {
|
|
28
|
+
const { id: _id, createdAt: _ca, updatedAt: _ua, ...data } = menu;
|
|
29
|
+
if (!data.slug || !data.title) {
|
|
30
|
+
results.errors.push(`Skipped menu: missing slug or title`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const existing = await payload.find({
|
|
34
|
+
collection: 'menus',
|
|
35
|
+
limit: 1,
|
|
36
|
+
where: {
|
|
37
|
+
slug: {
|
|
38
|
+
equals: data.slug
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (existing.docs.length > 0) {
|
|
43
|
+
await payload.update({
|
|
44
|
+
id: existing.docs[0].id,
|
|
45
|
+
collection: 'menus',
|
|
46
|
+
data
|
|
47
|
+
});
|
|
48
|
+
results.updated++;
|
|
49
|
+
} else {
|
|
50
|
+
await payload.create({
|
|
51
|
+
collection: 'menus',
|
|
52
|
+
data
|
|
53
|
+
});
|
|
54
|
+
results.created++;
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
results.errors.push(`Failed to import menu '${menu.slug}': ${err.message}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return Response.json(results);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=importMenusHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/importMenusHandler.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nexport const importMenusHandler: PayloadHandler = async (req) => {\n const { payload } = req\n\n let menus: any[]\n try {\n const body = await req.json?.()\n menus = Array.isArray(body) ? body : body?.menus\n if (!Array.isArray(menus)) {\n return Response.json(\n { error: 'Request body must be a JSON array of menus or { menus: [...] }' },\n { status: 400 },\n )\n }\n } catch {\n return Response.json({ error: 'Invalid JSON body' }, { status: 400 })\n }\n\n const results: { created: number; errors: string[]; updated: number } = {\n created: 0,\n errors: [],\n updated: 0,\n }\n\n for (const menu of menus) {\n try {\n const { id: _id, createdAt: _ca, updatedAt: _ua, ...data } = menu\n\n if (!data.slug || !data.title) {\n results.errors.push(`Skipped menu: missing slug or title`)\n continue\n }\n\n const existing = await payload.find({\n collection: 'menus',\n limit: 1,\n where: { slug: { equals: data.slug } },\n })\n\n if (existing.docs.length > 0) {\n await payload.update({\n id: existing.docs[0].id,\n collection: 'menus',\n data,\n })\n results.updated++\n } else {\n await payload.create({\n collection: 'menus',\n data,\n })\n results.created++\n }\n } catch (err: any) {\n results.errors.push(`Failed to import menu '${menu.slug}': ${err.message}`)\n }\n }\n\n return Response.json(results)\n}\n"],"names":["importMenusHandler","req","payload","menus","body","json","Array","isArray","Response","error","status","results","created","errors","updated","menu","id","_id","createdAt","_ca","updatedAt","_ua","data","slug","title","push","existing","find","collection","limit","where","equals","docs","length","update","create","err","message"],"mappings":"AAEA,OAAO,MAAMA,qBAAqC,OAAOC;IACvD,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,IAAIE;IACJ,IAAI;QACF,MAAMC,OAAO,MAAMH,IAAII,IAAI;QAC3BF,QAAQG,MAAMC,OAAO,CAACH,QAAQA,OAAOA,MAAMD;QAC3C,IAAI,CAACG,MAAMC,OAAO,CAACJ,QAAQ;YACzB,OAAOK,SAASH,IAAI,CAClB;gBAAEI,OAAO;YAAiE,GAC1E;gBAAEC,QAAQ;YAAI;QAElB;IACF,EAAE,OAAM;QACN,OAAOF,SAASH,IAAI,CAAC;YAAEI,OAAO;QAAoB,GAAG;YAAEC,QAAQ;QAAI;IACrE;IAEA,MAAMC,UAAkE;QACtEC,SAAS;QACTC,QAAQ,EAAE;QACVC,SAAS;IACX;IAEA,KAAK,MAAMC,QAAQZ,MAAO;QACxB,IAAI;YACF,MAAM,EAAEa,IAAIC,GAAG,EAAEC,WAAWC,GAAG,EAAEC,WAAWC,GAAG,EAAE,GAAGC,MAAM,GAAGP;YAE7D,IAAI,CAACO,KAAKC,IAAI,IAAI,CAACD,KAAKE,KAAK,EAAE;gBAC7Bb,QAAQE,MAAM,CAACY,IAAI,CAAC,CAAC,mCAAmC,CAAC;gBACzD;YACF;YAEA,MAAMC,WAAW,MAAMxB,QAAQyB,IAAI,CAAC;gBAClCC,YAAY;gBACZC,OAAO;gBACPC,OAAO;oBAAEP,MAAM;wBAAEQ,QAAQT,KAAKC,IAAI;oBAAC;gBAAE;YACvC;YAEA,IAAIG,SAASM,IAAI,CAACC,MAAM,GAAG,GAAG;gBAC5B,MAAM/B,QAAQgC,MAAM,CAAC;oBACnBlB,IAAIU,SAASM,IAAI,CAAC,EAAE,CAAChB,EAAE;oBACvBY,YAAY;oBACZN;gBACF;gBACAX,QAAQG,OAAO;YACjB,OAAO;gBACL,MAAMZ,QAAQiC,MAAM,CAAC;oBACnBP,YAAY;oBACZN;gBACF;gBACAX,QAAQC,OAAO;YACjB;QACF,EAAE,OAAOwB,KAAU;YACjBzB,QAAQE,MAAM,CAACY,IAAI,CAAC,CAAC,uBAAuB,EAAEV,KAAKQ,IAAI,CAAC,GAAG,EAAEa,IAAIC,OAAO,EAAE;QAC5E;IACF;IAEA,OAAO7B,SAASH,IAAI,CAACM;AACvB,EAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MenuItemRowLabel } from '../components/MenuItemRowLabel.js';
|
|
2
|
+
export { MenuPreview } from '../components/MenuPreview.js';
|
|
3
|
+
export { SubMenuItemRowLabel } from '../components/SubMenuItemRowLabel.js';
|
|
4
|
+
export { UrlField } from '../components/UrlField/index.js';
|
|
5
|
+
export { useMenu } from '../hooks/useMenu.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { MenuItemRowLabel } from '../components/MenuItemRowLabel.js';
|
|
2
|
+
export { MenuPreview } from '../components/MenuPreview.js';
|
|
3
|
+
export { SubMenuItemRowLabel } from '../components/SubMenuItemRowLabel.js';
|
|
4
|
+
export { UrlField } from '../components/UrlField/index.js';
|
|
5
|
+
export { useMenu } from '../hooks/useMenu.js';
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { MenuItemRowLabel } from '../components/MenuItemRowLabel.js'\nexport { MenuPreview } from '../components/MenuPreview.js'\nexport { SubMenuItemRowLabel } from '../components/SubMenuItemRowLabel.js'\nexport { UrlField } from '../components/UrlField/index.js'\nexport { useMenu } from '../hooks/useMenu.js'\n"],"names":["MenuItemRowLabel","MenuPreview","SubMenuItemRowLabel","UrlField","useMenu"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,mBAAmB,QAAQ,uCAAsC;AAC1E,SAASC,QAAQ,QAAQ,kCAAiC;AAC1D,SAASC,OAAO,QAAQ,sBAAqB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["// Reserved for React Server Components\n"],"names":[],"mappings":"AAAA,uCAAuC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CollectionSlug, Field } from 'payload';
|
|
2
|
+
export type MenuItemFieldOptions = {
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
maxDepth?: number;
|
|
5
|
+
relationTo?: CollectionSlug | CollectionSlug[];
|
|
6
|
+
};
|
|
7
|
+
export declare const createMenuItemFields: (options?: MenuItemFieldOptions, currentDepth?: number) => Field[];
|
|
8
|
+
export declare const menuItemFields: Field[];
|
|
9
|
+
export default menuItemFields;
|