@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,331 @@
|
|
|
1
|
+
const validateUrl = (value, { siblingData })=>{
|
|
2
|
+
const type = siblingData?.type;
|
|
3
|
+
if (!value) {
|
|
4
|
+
if ([
|
|
5
|
+
'anchor',
|
|
6
|
+
'custom',
|
|
7
|
+
'external',
|
|
8
|
+
'internal',
|
|
9
|
+
'mailto',
|
|
10
|
+
'tel'
|
|
11
|
+
].includes(type)) {
|
|
12
|
+
return 'URL is required for this link type';
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
switch(type){
|
|
17
|
+
case 'anchor':
|
|
18
|
+
{
|
|
19
|
+
if (!/^#[\w-]+$/.test(value)) {
|
|
20
|
+
return 'Please enter a valid anchor (e.g. #section-name)';
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
case 'external':
|
|
25
|
+
{
|
|
26
|
+
try {
|
|
27
|
+
new URL(value);
|
|
28
|
+
} catch {
|
|
29
|
+
return 'Please enter a valid URL (e.g. https://example.co.uk)';
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case 'internal':
|
|
34
|
+
{
|
|
35
|
+
const path = value.replace(/^https?:\/\/[^/]+/, '');
|
|
36
|
+
if (!path.startsWith('/')) {
|
|
37
|
+
return 'Internal paths must start with /';
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 'mailto':
|
|
42
|
+
{
|
|
43
|
+
const email = value.replace(/^mailto:/, '');
|
|
44
|
+
const [local, domain] = email.split('@');
|
|
45
|
+
if (!local || !domain || domain.indexOf('.') < 1 || email.split('@').length !== 2) {
|
|
46
|
+
return 'Please enter a valid email address';
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case 'tel':
|
|
51
|
+
{
|
|
52
|
+
const raw = value.replace(/^tel:/, '');
|
|
53
|
+
if (!/^\+?\d[\d\s\-()]{4,}$/.test(raw)) {
|
|
54
|
+
return 'Please enter a valid phone number';
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
export const createMenuItemFields = (options, currentDepth = 0)=>{
|
|
62
|
+
const baseUrl = options?.baseUrl ?? '';
|
|
63
|
+
const maxDepth = options?.maxDepth ?? 2;
|
|
64
|
+
const relationTo = options?.relationTo ?? 'pages';
|
|
65
|
+
const basicFields = [
|
|
66
|
+
{
|
|
67
|
+
type: 'row',
|
|
68
|
+
fields: [
|
|
69
|
+
{
|
|
70
|
+
name: 'advancedOptions',
|
|
71
|
+
type: 'radio',
|
|
72
|
+
admin: {
|
|
73
|
+
width: '33%'
|
|
74
|
+
},
|
|
75
|
+
defaultValue: 'default',
|
|
76
|
+
options: [
|
|
77
|
+
{
|
|
78
|
+
label: 'Default',
|
|
79
|
+
value: 'default'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
label: 'Advanced',
|
|
83
|
+
value: 'advanced'
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
required: true
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'target',
|
|
90
|
+
type: 'radio',
|
|
91
|
+
admin: {
|
|
92
|
+
width: '33%'
|
|
93
|
+
},
|
|
94
|
+
defaultValue: '_self',
|
|
95
|
+
label: 'Open in new tab',
|
|
96
|
+
options: [
|
|
97
|
+
{
|
|
98
|
+
label: 'Same Tab',
|
|
99
|
+
value: '_self'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
label: 'New Tab',
|
|
103
|
+
value: '_blank'
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'visibility',
|
|
109
|
+
type: 'radio',
|
|
110
|
+
admin: {
|
|
111
|
+
condition: (_data, siblingData)=>{
|
|
112
|
+
return siblingData?.advancedOptions !== 'default';
|
|
113
|
+
},
|
|
114
|
+
width: '33%'
|
|
115
|
+
},
|
|
116
|
+
defaultValue: 'visible',
|
|
117
|
+
options: [
|
|
118
|
+
{
|
|
119
|
+
label: 'Visible',
|
|
120
|
+
value: 'visible'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
label: 'Invisible',
|
|
124
|
+
value: 'invisible'
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'type',
|
|
132
|
+
type: 'select',
|
|
133
|
+
admin: {
|
|
134
|
+
description: 'Select the type of link for this menu item.'
|
|
135
|
+
},
|
|
136
|
+
defaultValue: 'reference',
|
|
137
|
+
options: [
|
|
138
|
+
{
|
|
139
|
+
label: 'Internal',
|
|
140
|
+
value: 'internal'
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
label: 'External',
|
|
144
|
+
value: 'external'
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
label: 'Reference',
|
|
148
|
+
value: 'reference'
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
label: 'Anchor',
|
|
152
|
+
value: 'anchor'
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
label: 'Mail To',
|
|
156
|
+
value: 'mailto'
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
label: 'TEL',
|
|
160
|
+
value: 'tel'
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
label: 'Custom',
|
|
164
|
+
value: 'custom'
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
required: true
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
type: 'row',
|
|
171
|
+
fields: [
|
|
172
|
+
{
|
|
173
|
+
name: 'label',
|
|
174
|
+
type: 'text',
|
|
175
|
+
admin: {
|
|
176
|
+
width: '50%'
|
|
177
|
+
},
|
|
178
|
+
required: true
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: 'url',
|
|
182
|
+
type: 'text',
|
|
183
|
+
admin: {
|
|
184
|
+
components: {
|
|
185
|
+
Field: 'menu-plugin/client#UrlField'
|
|
186
|
+
},
|
|
187
|
+
condition: (_data, siblingData)=>{
|
|
188
|
+
return siblingData?.type !== 'reference';
|
|
189
|
+
},
|
|
190
|
+
custom: {
|
|
191
|
+
baseUrl
|
|
192
|
+
},
|
|
193
|
+
width: '50%'
|
|
194
|
+
},
|
|
195
|
+
label: 'URL',
|
|
196
|
+
validate: validateUrl
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
name: 'reference',
|
|
200
|
+
type: 'relationship',
|
|
201
|
+
admin: {
|
|
202
|
+
condition: (_data, siblingData)=>{
|
|
203
|
+
return siblingData?.type === 'reference';
|
|
204
|
+
},
|
|
205
|
+
width: '50%'
|
|
206
|
+
},
|
|
207
|
+
...Array.isArray(relationTo) ? {
|
|
208
|
+
hasMany: false,
|
|
209
|
+
relationTo
|
|
210
|
+
} : {
|
|
211
|
+
relationTo
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: 'rel',
|
|
218
|
+
type: 'text',
|
|
219
|
+
admin: {
|
|
220
|
+
condition: (_data, siblingData)=>{
|
|
221
|
+
return siblingData?.advancedOptions !== 'default';
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: 'roles',
|
|
227
|
+
type: 'array',
|
|
228
|
+
admin: {
|
|
229
|
+
condition: (_data, siblingData)=>{
|
|
230
|
+
return siblingData?.advancedOptions !== 'default';
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
fields: [
|
|
234
|
+
{
|
|
235
|
+
name: 'role',
|
|
236
|
+
type: 'text'
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'attrs',
|
|
242
|
+
type: 'textarea',
|
|
243
|
+
admin: {
|
|
244
|
+
condition: (_data, siblingData)=>{
|
|
245
|
+
return siblingData?.advancedOptions !== 'default';
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
];
|
|
250
|
+
const isLink = (_data, siblingData)=>siblingData?.itemType !== 'dropdown';
|
|
251
|
+
// Wrap link-specific fields so they hide when itemType is 'dropdown'.
|
|
252
|
+
// Label is kept visible for both types (it sits in the url row but url hides for dropdown).
|
|
253
|
+
const linkFields = basicFields.map((f)=>{
|
|
254
|
+
// For row fields, add condition to each child field (except label, which is always visible)
|
|
255
|
+
if ('type' in f && f.type === 'row') {
|
|
256
|
+
return {
|
|
257
|
+
...f,
|
|
258
|
+
fields: f.fields.map((child)=>{
|
|
259
|
+
// Label is always visible for both link and dropdown
|
|
260
|
+
if ('name' in child && child.name === 'label') return child;
|
|
261
|
+
return {
|
|
262
|
+
...child,
|
|
263
|
+
admin: {
|
|
264
|
+
...child.admin,
|
|
265
|
+
condition: (_data, siblingData, extra)=>{
|
|
266
|
+
const existingCondition = child.admin?.condition;
|
|
267
|
+
const linkVisible = isLink(_data, siblingData);
|
|
268
|
+
if (!linkVisible) return false;
|
|
269
|
+
return existingCondition ? existingCondition(_data, siblingData, extra) : true;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
})
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
// For named fields, add condition directly
|
|
277
|
+
if ('admin' in f || 'name' in f) {
|
|
278
|
+
return {
|
|
279
|
+
...f,
|
|
280
|
+
admin: {
|
|
281
|
+
...f.admin,
|
|
282
|
+
condition: (_data, siblingData, extra)=>{
|
|
283
|
+
const existingCondition = f.admin?.condition;
|
|
284
|
+
const linkVisible = isLink(_data, siblingData);
|
|
285
|
+
if (!linkVisible) return false;
|
|
286
|
+
return existingCondition ? existingCondition(_data, siblingData, extra) : true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return f;
|
|
292
|
+
});
|
|
293
|
+
const canNest = currentDepth < maxDepth;
|
|
294
|
+
const fields = canNest ? [
|
|
295
|
+
{
|
|
296
|
+
name: 'itemType',
|
|
297
|
+
type: 'select',
|
|
298
|
+
defaultValue: 'link',
|
|
299
|
+
options: [
|
|
300
|
+
{
|
|
301
|
+
label: 'Link',
|
|
302
|
+
value: 'link'
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
label: 'Dropdown',
|
|
306
|
+
value: 'dropdown'
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
required: true
|
|
310
|
+
},
|
|
311
|
+
...linkFields,
|
|
312
|
+
{
|
|
313
|
+
name: 'children',
|
|
314
|
+
type: 'array',
|
|
315
|
+
admin: {
|
|
316
|
+
components: {
|
|
317
|
+
RowLabel: 'menu-plugin/client#SubMenuItemRowLabel'
|
|
318
|
+
},
|
|
319
|
+
condition: (_data, siblingData)=>{
|
|
320
|
+
return siblingData?.itemType === 'dropdown';
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
fields: createMenuItemFields(options, currentDepth + 1)
|
|
324
|
+
}
|
|
325
|
+
] : basicFields;
|
|
326
|
+
return fields;
|
|
327
|
+
};
|
|
328
|
+
export const menuItemFields = createMenuItemFields();
|
|
329
|
+
export default menuItemFields;
|
|
330
|
+
|
|
331
|
+
//# sourceMappingURL=MenuItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/fields/MenuItem.ts"],"sourcesContent":["import type { CollectionSlug, Field, Validate } from 'payload'\n\nexport type MenuItemFieldOptions = {\n baseUrl?: string\n maxDepth?: number\n relationTo?: CollectionSlug | CollectionSlug[]\n}\n\nconst validateUrl: Validate = (value, { siblingData }) => {\n const type = (siblingData as any)?.type\n if (!value) {\n if (['anchor', 'custom', 'external', 'internal', 'mailto', 'tel'].includes(type)) {\n return 'URL is required for this link type'\n }\n return true\n }\n\n switch (type) {\n case 'anchor': {\n if (!/^#[\\w-]+$/.test(value as string)) {\n return 'Please enter a valid anchor (e.g. #section-name)'\n }\n break\n }\n case 'external': {\n try {\n new URL(value as string)\n } catch {\n return 'Please enter a valid URL (e.g. https://example.co.uk)'\n }\n break\n }\n case 'internal': {\n const path = (value as string).replace(/^https?:\\/\\/[^/]+/, '')\n if (!path.startsWith('/')) {\n return 'Internal paths must start with /'\n }\n break\n }\n case 'mailto': {\n const email = (value as string).replace(/^mailto:/, '')\n const [local, domain] = email.split('@')\n if (!local || !domain || domain.indexOf('.') < 1 || email.split('@').length !== 2) {\n return 'Please enter a valid email address'\n }\n break\n }\n case 'tel': {\n const raw = (value as string).replace(/^tel:/, '')\n if (!/^\\+?\\d[\\d\\s\\-()]{4,}$/.test(raw)) {\n return 'Please enter a valid phone number'\n }\n break\n }\n }\n\n return true\n}\n\nexport const createMenuItemFields = (options?: MenuItemFieldOptions, currentDepth = 0): Field[] => {\n const baseUrl = options?.baseUrl ?? ''\n const maxDepth = options?.maxDepth ?? 2\n const relationTo = options?.relationTo ?? ('pages' as CollectionSlug)\n const basicFields: Field[] = [\n {\n type: 'row',\n fields: [\n {\n name: 'advancedOptions',\n type: 'radio',\n admin: {\n width: '33%',\n },\n defaultValue: 'default',\n options: [\n { label: 'Default', value: 'default' },\n { label: 'Advanced', value: 'advanced' },\n ],\n required: true,\n },\n {\n name: 'target',\n type: 'radio',\n admin: {\n width: '33%',\n },\n defaultValue: '_self',\n label: 'Open in new tab',\n options: [\n { label: 'Same Tab', value: '_self' },\n { label: 'New Tab', value: '_blank' },\n ],\n },\n {\n name: 'visibility',\n type: 'radio',\n admin: {\n condition: (_data, siblingData) => {\n return siblingData?.advancedOptions !== 'default'\n },\n width: '33%',\n },\n defaultValue: 'visible',\n options: [\n { label: 'Visible', value: 'visible' },\n { label: 'Invisible', value: 'invisible' },\n ],\n },\n ],\n },\n {\n name: 'type',\n type: 'select',\n admin: {\n description: 'Select the type of link for this menu item.',\n },\n defaultValue: 'reference',\n options: [\n { label: 'Internal', value: 'internal' },\n { label: 'External', value: 'external' },\n { label: 'Reference', value: 'reference' },\n { label: 'Anchor', value: 'anchor' },\n { label: 'Mail To', value: 'mailto' },\n { label: 'TEL', value: 'tel' },\n { label: 'Custom', value: 'custom' },\n ],\n required: true,\n },\n {\n type: 'row',\n fields: [\n {\n name: 'label',\n type: 'text',\n admin: {\n width: '50%',\n },\n required: true,\n },\n {\n name: 'url',\n type: 'text',\n admin: {\n components: {\n Field: 'menu-plugin/client#UrlField',\n },\n condition: (_data, siblingData) => {\n return siblingData?.type !== 'reference'\n },\n custom: { baseUrl },\n width: '50%',\n },\n label: 'URL',\n validate: validateUrl,\n },\n {\n name: 'reference',\n type: 'relationship',\n admin: {\n condition: (_data, siblingData) => {\n return siblingData?.type === 'reference'\n },\n width: '50%',\n },\n ...(Array.isArray(relationTo) ? { hasMany: false, relationTo } : { relationTo }),\n } as Field,\n ],\n },\n {\n name: 'rel',\n type: 'text',\n admin: {\n condition: (_data, siblingData) => {\n return siblingData?.advancedOptions !== 'default'\n },\n },\n },\n {\n name: 'roles',\n type: 'array',\n admin: {\n condition: (_data, siblingData) => {\n return siblingData?.advancedOptions !== 'default'\n },\n },\n fields: [{ name: 'role', type: 'text' }],\n },\n {\n name: 'attrs',\n type: 'textarea',\n admin: {\n condition: (_data, siblingData) => {\n return siblingData?.advancedOptions !== 'default'\n },\n },\n },\n ]\n\n const isLink = (_data: any, siblingData: any) => siblingData?.itemType !== 'dropdown'\n\n // Wrap link-specific fields so they hide when itemType is 'dropdown'.\n // Label is kept visible for both types (it sits in the url row but url hides for dropdown).\n const linkFields: Field[] = basicFields.map((f) => {\n // For row fields, add condition to each child field (except label, which is always visible)\n if ('type' in f && f.type === 'row') {\n return {\n ...f,\n fields: f.fields.map((child) => {\n // Label is always visible for both link and dropdown\n if ('name' in child && child.name === 'label') return child\n return {\n ...child,\n admin: {\n ...child.admin,\n condition: (_data: any, siblingData: any, extra: any) => {\n const existingCondition = child.admin?.condition\n const linkVisible = isLink(_data, siblingData)\n if (!linkVisible) return false\n return existingCondition ? existingCondition(_data, siblingData, extra) : true\n },\n },\n }\n }),\n } as Field\n }\n\n // For named fields, add condition directly\n if ('admin' in f || 'name' in f) {\n return {\n ...f,\n admin: {\n ...(f as any).admin,\n condition: (_data: any, siblingData: any, extra: any) => {\n const existingCondition = (f as any).admin?.condition\n const linkVisible = isLink(_data, siblingData)\n if (!linkVisible) return false\n return existingCondition ? existingCondition(_data, siblingData, extra) : true\n },\n },\n } as Field\n }\n\n return f\n })\n\n const canNest = currentDepth < maxDepth\n\n const fields: Field[] = canNest\n ? [\n {\n name: 'itemType',\n type: 'select',\n defaultValue: 'link',\n options: [\n { label: 'Link', value: 'link' },\n { label: 'Dropdown', value: 'dropdown' },\n ],\n required: true,\n },\n ...linkFields,\n {\n name: 'children',\n type: 'array',\n admin: {\n components: {\n RowLabel: 'menu-plugin/client#SubMenuItemRowLabel',\n },\n condition: (_data, siblingData) => {\n return siblingData?.itemType === 'dropdown'\n },\n },\n fields: createMenuItemFields(options, currentDepth + 1),\n },\n ]\n : basicFields\n\n return fields\n}\n\nexport const menuItemFields = createMenuItemFields()\n\nexport default menuItemFields\n"],"names":["validateUrl","value","siblingData","type","includes","test","URL","path","replace","startsWith","email","local","domain","split","indexOf","length","raw","createMenuItemFields","options","currentDepth","baseUrl","maxDepth","relationTo","basicFields","fields","name","admin","width","defaultValue","label","required","condition","_data","advancedOptions","description","components","Field","custom","validate","Array","isArray","hasMany","isLink","itemType","linkFields","map","f","child","extra","existingCondition","linkVisible","canNest","RowLabel","menuItemFields"],"mappings":"AAQA,MAAMA,cAAwB,CAACC,OAAO,EAAEC,WAAW,EAAE;IACnD,MAAMC,OAAQD,aAAqBC;IACnC,IAAI,CAACF,OAAO;QACV,IAAI;YAAC;YAAU;YAAU;YAAY;YAAY;YAAU;SAAM,CAACG,QAAQ,CAACD,OAAO;YAChF,OAAO;QACT;QACA,OAAO;IACT;IAEA,OAAQA;QACN,KAAK;YAAU;gBACb,IAAI,CAAC,YAAYE,IAAI,CAACJ,QAAkB;oBACtC,OAAO;gBACT;gBACA;YACF;QACA,KAAK;YAAY;gBACf,IAAI;oBACF,IAAIK,IAAIL;gBACV,EAAE,OAAM;oBACN,OAAO;gBACT;gBACA;YACF;QACA,KAAK;YAAY;gBACf,MAAMM,OAAO,AAACN,MAAiBO,OAAO,CAAC,qBAAqB;gBAC5D,IAAI,CAACD,KAAKE,UAAU,CAAC,MAAM;oBACzB,OAAO;gBACT;gBACA;YACF;QACA,KAAK;YAAU;gBACb,MAAMC,QAAQ,AAACT,MAAiBO,OAAO,CAAC,YAAY;gBACpD,MAAM,CAACG,OAAOC,OAAO,GAAGF,MAAMG,KAAK,CAAC;gBACpC,IAAI,CAACF,SAAS,CAACC,UAAUA,OAAOE,OAAO,CAAC,OAAO,KAAKJ,MAAMG,KAAK,CAAC,KAAKE,MAAM,KAAK,GAAG;oBACjF,OAAO;gBACT;gBACA;YACF;QACA,KAAK;YAAO;gBACV,MAAMC,MAAM,AAACf,MAAiBO,OAAO,CAAC,SAAS;gBAC/C,IAAI,CAAC,wBAAwBH,IAAI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/B;oBAAE4B,OAAO;oBAAY5B,OAAO;gBAAW;aACxC;YACD6B,UAAU;QACZ;WACGc;QACH;YACEnB,MAAM;YACNtB,MAAM;YACNuB,OAAO;gBACLS,YAAY;oBACViB,UAAU;gBACZ;gBACArB,WAAW,CAACC,OAAO9B;oBACjB,OAAOA,aAAayC,aAAa;gBACnC;YACF;YACAnB,QAAQP,qBAAqBC,SAASC,eAAe;QACvD;KACD,GACDI;IAEJ,OAAOC;AACT,EAAC;AAED,OAAO,MAAM6B,iBAAiBpC,uBAAsB;AAEpD,eAAeoC,eAAc"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type UseMenuOptions = {
|
|
2
|
+
depth?: number;
|
|
3
|
+
locale?: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
};
|
|
6
|
+
type UseMenuResult = {
|
|
7
|
+
error: null | string;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
menu: any | null;
|
|
10
|
+
refetch: () => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const useMenu: ({ slug, depth, locale }: UseMenuOptions) => UseMenuResult;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useConfig } from '@payloadcms/ui';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
const clientCache = new Map();
|
|
5
|
+
const CACHE_TTL = 30_000;
|
|
6
|
+
export const useMenu = ({ slug, depth = 0, locale })=>{
|
|
7
|
+
const { config } = useConfig();
|
|
8
|
+
const [menu, setMenu] = useState(null);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
11
|
+
const abortRef = useRef(null);
|
|
12
|
+
const cacheKey = `${slug}:${locale || ''}:${depth}`;
|
|
13
|
+
const fetchMenu = useCallback(async ()=>{
|
|
14
|
+
// Check client-side cache
|
|
15
|
+
const cached = clientCache.get(cacheKey);
|
|
16
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
|
|
17
|
+
setMenu(cached.data);
|
|
18
|
+
setIsLoading(false);
|
|
19
|
+
setError(null);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
abortRef.current?.abort();
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
abortRef.current = controller;
|
|
25
|
+
setIsLoading(true);
|
|
26
|
+
setError(null);
|
|
27
|
+
try {
|
|
28
|
+
const params = new URLSearchParams();
|
|
29
|
+
if (locale) params.set('locale', locale);
|
|
30
|
+
if (depth) params.set('depth', String(depth));
|
|
31
|
+
const query = params.toString();
|
|
32
|
+
const apiRoute = config.routes?.api || '/api';
|
|
33
|
+
const url = `${apiRoute}/menus/${slug}${query ? `?${query}` : ''}`;
|
|
34
|
+
const response = await fetch(url, {
|
|
35
|
+
signal: controller.signal
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
const body = await response.json().catch(()=>({}));
|
|
39
|
+
throw new Error(body.error || `Failed to fetch menu: ${response.status}`);
|
|
40
|
+
}
|
|
41
|
+
const data = await response.json();
|
|
42
|
+
clientCache.set(cacheKey, {
|
|
43
|
+
data,
|
|
44
|
+
timestamp: Date.now()
|
|
45
|
+
});
|
|
46
|
+
setMenu(data);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
if (err.name !== 'AbortError') {
|
|
49
|
+
setError(err.message);
|
|
50
|
+
}
|
|
51
|
+
} finally{
|
|
52
|
+
setIsLoading(false);
|
|
53
|
+
}
|
|
54
|
+
}, [
|
|
55
|
+
cacheKey,
|
|
56
|
+
config.routes?.api,
|
|
57
|
+
depth,
|
|
58
|
+
locale,
|
|
59
|
+
slug
|
|
60
|
+
]);
|
|
61
|
+
useEffect(()=>{
|
|
62
|
+
void fetchMenu();
|
|
63
|
+
return ()=>{
|
|
64
|
+
abortRef.current?.abort();
|
|
65
|
+
};
|
|
66
|
+
}, [
|
|
67
|
+
fetchMenu
|
|
68
|
+
]);
|
|
69
|
+
return {
|
|
70
|
+
error,
|
|
71
|
+
isLoading,
|
|
72
|
+
menu,
|
|
73
|
+
refetch: fetchMenu
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=useMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useMenu.ts"],"sourcesContent":["'use client'\n\nimport { useConfig } from '@payloadcms/ui'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\ntype UseMenuOptions = {\n depth?: number\n locale?: string\n slug: string\n}\n\ntype UseMenuResult = {\n error: null | string\n isLoading: boolean\n menu: any | null\n refetch: () => Promise<void>\n}\n\nconst clientCache = new Map<string, { data: any; timestamp: number }>()\nconst CACHE_TTL = 30_000\n\nexport const useMenu = ({ slug, depth = 0, locale }: UseMenuOptions): UseMenuResult => {\n const { config } = useConfig()\n const [menu, setMenu] = useState<any | null>(null)\n const [error, setError] = useState<null | string>(null)\n const [isLoading, setIsLoading] = useState(true)\n const abortRef = useRef<AbortController | null>(null)\n\n const cacheKey = `${slug}:${locale || ''}:${depth}`\n\n const fetchMenu = useCallback(async () => {\n // Check client-side cache\n const cached = clientCache.get(cacheKey)\n if (cached && Date.now() - cached.timestamp < CACHE_TTL) {\n setMenu(cached.data)\n setIsLoading(false)\n setError(null)\n return\n }\n\n abortRef.current?.abort()\n const controller = new AbortController()\n abortRef.current = controller\n\n setIsLoading(true)\n setError(null)\n\n try {\n const params = new URLSearchParams()\n if (locale) params.set('locale', locale)\n if (depth) params.set('depth', String(depth))\n const query = params.toString()\n\n const apiRoute = config.routes?.api || '/api'\n const url = `${apiRoute}/menus/${slug}${query ? `?${query}` : ''}`\n\n const response = await fetch(url, { signal: controller.signal })\n\n if (!response.ok) {\n const body = await response.json().catch(() => ({}))\n throw new Error(body.error || `Failed to fetch menu: ${response.status}`)\n }\n\n const data = await response.json()\n clientCache.set(cacheKey, { data, timestamp: Date.now() })\n setMenu(data)\n } catch (err: any) {\n if (err.name !== 'AbortError') {\n setError(err.message)\n }\n } finally {\n setIsLoading(false)\n }\n }, [cacheKey, config.routes?.api, depth, locale, slug])\n\n useEffect(() => {\n void fetchMenu()\n return () => {\n abortRef.current?.abort()\n }\n }, [fetchMenu])\n\n return { error, isLoading, menu, refetch: fetchMenu }\n}\n"],"names":["useConfig","useCallback","useEffect","useRef","useState","clientCache","Map","CACHE_TTL","useMenu","slug","depth","locale","config","menu","setMenu","error","setError","isLoading","setIsLoading","abortRef","cacheKey","fetchMenu","cached","get","Date","now","timestamp","data","current","abort","controller","AbortController","params","URLSearchParams","set","String","query","toString","apiRoute","routes","api","url","response","fetch","signal","ok","body","json","catch","Error","status","err","name","message","refetch"],"mappings":"AAAA;AAEA,SAASA,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAehE,MAAMC,cAAc,IAAIC;AACxB,MAAMC,YAAY;AAElB,OAAO,MAAMC,UAAU,CAAC,EAAEC,IAAI,EAAEC,QAAQ,CAAC,EAAEC,MAAM,EAAkB;IACjE,MAAM,EAAEC,MAAM,EAAE,GAAGZ;IACnB,MAAM,CAACa,MAAMC,QAAQ,GAAGV,SAAqB;IAC7C,MAAM,CAACW,OAAOC,SAAS,GAAGZ,SAAwB;IAClD,MAAM,CAACa,WAAWC,aAAa,GAAGd,SAAS;IAC3C,MAAMe,WAAWhB,OAA+B;IAEhD,MAAMiB,WAAW,GAAGX,KAAK,CAAC,EAAEE,UAAU,GAAG,CAAC,EAAED,OAAO;IAEnD,MAAMW,YAAYpB,YAAY;QAC5B,0BAA0B;QAC1B,MAAMqB,SAASjB,YAAYkB,GAAG,CAACH;QAC/B,IAAIE,UAAUE,KAAKC,GAAG,KAAKH,OAAOI,SAAS,GAAGnB,WAAW;YACvDO,QAAQQ,OAAOK,IAAI;YACnBT,aAAa;YACbF,SAAS;YACT;QACF;QAEAG,SAASS,OAAO,EAAEC;QAClB,MAA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,8 @@
|
|
|
1
|
+
import type { CollectionSlug, Config } from 'payload';
|
|
2
|
+
export type MenuPluginConfig = {
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
maxDepth?: number;
|
|
6
|
+
relationTo?: CollectionSlug | CollectionSlug[];
|
|
7
|
+
};
|
|
8
|
+
export declare const menuPlugin: (pluginOptions: MenuPluginConfig) => (config: Config) => Config;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createMenusCollection } from './collections/Menus.js';
|
|
2
|
+
import { exportMenusHandler } from './endpoints/exportMenusHandler.js';
|
|
3
|
+
import { getMenuHandler } from './endpoints/getMenuHandler.js';
|
|
4
|
+
import { importMenusHandler } from './endpoints/importMenusHandler.js';
|
|
5
|
+
export const menuPlugin = (pluginOptions)=>(config)=>{
|
|
6
|
+
if (!config.collections) {
|
|
7
|
+
config.collections = [];
|
|
8
|
+
}
|
|
9
|
+
config.collections.push(createMenusCollection({
|
|
10
|
+
baseUrl: pluginOptions.baseUrl,
|
|
11
|
+
maxDepth: pluginOptions.maxDepth,
|
|
12
|
+
relationTo: pluginOptions.relationTo
|
|
13
|
+
}));
|
|
14
|
+
if (pluginOptions.disabled) {
|
|
15
|
+
return config;
|
|
16
|
+
}
|
|
17
|
+
if (!config.endpoints) {
|
|
18
|
+
config.endpoints = [];
|
|
19
|
+
}
|
|
20
|
+
config.endpoints.push({
|
|
21
|
+
handler: getMenuHandler,
|
|
22
|
+
method: 'get',
|
|
23
|
+
path: '/api/menus/:slug'
|
|
24
|
+
});
|
|
25
|
+
config.endpoints.push({
|
|
26
|
+
handler: exportMenusHandler,
|
|
27
|
+
method: 'get',
|
|
28
|
+
path: '/api/menus-export'
|
|
29
|
+
});
|
|
30
|
+
config.endpoints.push({
|
|
31
|
+
handler: importMenusHandler,
|
|
32
|
+
method: 'post',
|
|
33
|
+
path: '/api/menus-import'
|
|
34
|
+
});
|
|
35
|
+
return config;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionSlug, Config } from 'payload'\n\nimport { createMenusCollection } from './collections/Menus.js'\nimport { exportMenusHandler } from './endpoints/exportMenusHandler.js'\nimport { getMenuHandler } from './endpoints/getMenuHandler.js'\nimport { importMenusHandler } from './endpoints/importMenusHandler.js'\n\nexport type MenuPluginConfig = {\n baseUrl?: string\n disabled?: boolean\n maxDepth?: number\n relationTo?: CollectionSlug | CollectionSlug[]\n}\n\nexport const menuPlugin =\n (pluginOptions: MenuPluginConfig) =>\n (config: Config): Config => {\n if (!config.collections) {\n config.collections = []\n }\n\n config.collections.push(\n createMenusCollection({\n baseUrl: pluginOptions.baseUrl,\n maxDepth: pluginOptions.maxDepth,\n relationTo: pluginOptions.relationTo,\n }),\n )\n\n if (pluginOptions.disabled) {\n return config\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n\n config.endpoints.push({\n handler: getMenuHandler,\n method: 'get',\n path: '/api/menus/:slug',\n })\n\n config.endpoints.push({\n handler: exportMenusHandler,\n method: 'get',\n path: '/api/menus-export',\n })\n\n config.endpoints.push({\n handler: importMenusHandler,\n method: 'post',\n path: '/api/menus-import',\n })\n\n return config\n }\n"],"names":["createMenusCollection","exportMenusHandler","getMenuHandler","importMenusHandler","menuPlugin","pluginOptions","config","collections","push","baseUrl","maxDepth","relationTo","disabled","endpoints","handler","method","path"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,yBAAwB;AAC9D,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,kBAAkB,QAAQ,oCAAmC;AAStE,OAAO,MAAMC,aACX,CAACC,gBACD,CAACC;QACC,IAAI,CAACA,OAAOC,WAAW,EAAE;YACvBD,OAAOC,WAAW,GAAG,EAAE;QACzB;QAEAD,OAAOC,WAAW,CAACC,IAAI,CACrBR,sBAAsB;YACpBS,SAASJ,cAAcI,OAAO;YAC9BC,UAAUL,cAAcK,QAAQ;YAChCC,YAAYN,cAAcM,UAAU;QACtC;QAGF,IAAIN,cAAcO,QAAQ,EAAE;YAC1B,OAAON;QACT;QAEA,IAAI,CAACA,OAAOO,SAAS,EAAE;YACrBP,OAAOO,SAAS,GAAG,EAAE;QACvB;QAEAP,OAAOO,SAAS,CAACL,IAAI,CAAC;YACpBM,SAASZ;YACTa,QAAQ;YACRC,MAAM;QACR;QAEAV,OAAOO,SAAS,CAACL,IAAI,CAAC;YACpBM,SAASb;YACTc,QAAQ;YACRC,MAAM;QACR;QAEAV,OAAOO,SAAS,CAACL,IAAI,CAAC;YACpBM,SAASX;YACTY,QAAQ;YACRC,MAAM;QACR;QAEA,OAAOV;IACT,EAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@foundrykit/menu-plugin",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A plugin for Payload CMS that provides a flexible and customisable menu system.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Isaac SJ",
|
|
9
|
+
"email": "isaac@umidigital.co.uk"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"payload",
|
|
13
|
+
"payloadcms",
|
|
14
|
+
"plugin",
|
|
15
|
+
"menu",
|
|
16
|
+
"navigation"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./src/index.ts",
|
|
21
|
+
"types": "./src/index.ts",
|
|
22
|
+
"default": "./src/index.ts"
|
|
23
|
+
},
|
|
24
|
+
"./client": {
|
|
25
|
+
"import": "./src/exports/client.ts",
|
|
26
|
+
"types": "./src/exports/client.ts",
|
|
27
|
+
"default": "./src/exports/client.ts"
|
|
28
|
+
},
|
|
29
|
+
"./rsc": {
|
|
30
|
+
"import": "./src/exports/rsc.ts",
|
|
31
|
+
"types": "./src/exports/rsc.ts",
|
|
32
|
+
"default": "./src/exports/rsc.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "./src/index.ts",
|
|
36
|
+
"types": "./src/index.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
|
|
42
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
43
|
+
"build:types": "tsc --outDir dist --rootDir ./src",
|
|
44
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
45
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
46
|
+
"dev": "next dev dev --turbo",
|
|
47
|
+
"dev:db:up": "docker-compose -f dev/docker-compose.yml up -d",
|
|
48
|
+
"dev:db:down": "docker-compose -f dev/docker-compose.yml down",
|
|
49
|
+
"dev:with-db": "docker-compose -f dev/docker-compose.yml up -d && pnpm dev && docker-compose -f dev/docker-compose.yml down",
|
|
50
|
+
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
51
|
+
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
52
|
+
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
53
|
+
"generate:importmap": "pnpm dev:generate-importmap",
|
|
54
|
+
"generate:types": "pnpm dev:generate-types",
|
|
55
|
+
"lint": "eslint",
|
|
56
|
+
"lint:fix": "eslint ./src --fix",
|
|
57
|
+
"test": "pnpm test:int && pnpm test:e2e",
|
|
58
|
+
"test:e2e": "playwright test",
|
|
59
|
+
"test:int": "vitest"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
63
|
+
"@payloadcms/db-mongodb": "3.37.0",
|
|
64
|
+
"@payloadcms/db-postgres": "3.37.0",
|
|
65
|
+
"@payloadcms/db-sqlite": "3.37.0",
|
|
66
|
+
"@payloadcms/eslint-config": "3.9.0",
|
|
67
|
+
"@payloadcms/next": "3.37.0",
|
|
68
|
+
"@payloadcms/richtext-lexical": "3.37.0",
|
|
69
|
+
"@payloadcms/ui": "3.37.0",
|
|
70
|
+
"@playwright/test": "1.56.1",
|
|
71
|
+
"@swc-node/register": "1.10.9",
|
|
72
|
+
"@swc/cli": "0.6.0",
|
|
73
|
+
"@types/node": "22.19.9",
|
|
74
|
+
"@types/react": "19.2.9",
|
|
75
|
+
"@types/react-dom": "19.2.3",
|
|
76
|
+
"copyfiles": "2.4.1",
|
|
77
|
+
"cross-env": "^7.0.3",
|
|
78
|
+
"eslint": "^9.23.0",
|
|
79
|
+
"eslint-config-next": "15.4.11",
|
|
80
|
+
"graphql": "^16.8.1",
|
|
81
|
+
"mongodb-memory-server": "10.1.4",
|
|
82
|
+
"next": "15.4.11",
|
|
83
|
+
"open": "^10.1.0",
|
|
84
|
+
"payload": "3.37.0",
|
|
85
|
+
"prettier": "^3.4.2",
|
|
86
|
+
"qs-esm": "7.0.2",
|
|
87
|
+
"react": "19.2.1",
|
|
88
|
+
"react-dom": "19.2.1",
|
|
89
|
+
"rimraf": "3.0.2",
|
|
90
|
+
"sharp": "0.34.2",
|
|
91
|
+
"sort-package-json": "^2.10.0",
|
|
92
|
+
"typescript": "5.7.3",
|
|
93
|
+
"vite-tsconfig-paths": "6.0.5",
|
|
94
|
+
"vitest": "4.0.18"
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"payload": "^3.37.0"
|
|
98
|
+
},
|
|
99
|
+
"engines": {
|
|
100
|
+
"node": "^18.20.2 || >=20.9.0",
|
|
101
|
+
"pnpm": "^9 || ^10"
|
|
102
|
+
},
|
|
103
|
+
"publishConfig": {
|
|
104
|
+
"access": "public",
|
|
105
|
+
"exports": {
|
|
106
|
+
".": {
|
|
107
|
+
"import": "./dist/index.js",
|
|
108
|
+
"types": "./dist/index.d.ts",
|
|
109
|
+
"default": "./dist/index.js"
|
|
110
|
+
},
|
|
111
|
+
"./client": {
|
|
112
|
+
"import": "./dist/exports/client.js",
|
|
113
|
+
"types": "./dist/exports/client.d.ts",
|
|
114
|
+
"default": "./dist/exports/client.js"
|
|
115
|
+
},
|
|
116
|
+
"./rsc": {
|
|
117
|
+
"import": "./dist/exports/rsc.js",
|
|
118
|
+
"types": "./dist/exports/rsc.d.ts",
|
|
119
|
+
"default": "./dist/exports/rsc.js"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"main": "./dist/index.js",
|
|
123
|
+
"types": "./dist/index.d.ts"
|
|
124
|
+
},
|
|
125
|
+
"pnpm": {
|
|
126
|
+
"onlyBuiltDependencies": [
|
|
127
|
+
"sharp",
|
|
128
|
+
"esbuild",
|
|
129
|
+
"unrs-resolver"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"repository": {
|
|
133
|
+
"type": "git",
|
|
134
|
+
"url": "https://github.com/umi-labs/menu-plugin"
|
|
135
|
+
},
|
|
136
|
+
"bugs": {
|
|
137
|
+
"url": "https://github.com/umi-labs/menu-plugin/issues"
|
|
138
|
+
},
|
|
139
|
+
"homepage": "https://github.com/umi-labs/menu-plugin#readme"
|
|
140
|
+
}
|