@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 UMI Digital
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# @foundrykit/menu-plugin
|
|
2
|
+
|
|
3
|
+
A [Payload CMS](https://payloadcms.com) v3 plugin that adds a flexible, configurable menu management system to your admin panel. Build navigation menus with support for internal links, external URLs, document references, dropdowns, phone numbers, email links, and more.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Multiple link types: internal, external, reference, anchor, mailto, tel, custom
|
|
8
|
+
- Nested dropdown menus with configurable max depth
|
|
9
|
+
- Smart URL input that adapts its UI per link type (baseUrl prefix, country code selector, etc.)
|
|
10
|
+
- REST API endpoint to fetch menus by slug
|
|
11
|
+
- Built-in server-side caching with automatic invalidation
|
|
12
|
+
- `useMenu` React hook for client-side fetching
|
|
13
|
+
- Menu export/import endpoints for migration between environments
|
|
14
|
+
- Per-item visibility, target, rel, roles, and custom attributes
|
|
15
|
+
- Sidebar preview of the menu tree structure
|
|
16
|
+
- Field-level validation per link type
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @foundrykit/menu-plugin
|
|
22
|
+
# or
|
|
23
|
+
npm install @foundrykit/menu-plugin
|
|
24
|
+
# or
|
|
25
|
+
yarn add @foundrykit/menu-plugin
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
Add the plugin to your Payload config:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { buildConfig } from 'payload'
|
|
34
|
+
import { menuPlugin } from '@foundrykit/menu-plugin'
|
|
35
|
+
|
|
36
|
+
export default buildConfig({
|
|
37
|
+
// ...your config
|
|
38
|
+
plugins: [
|
|
39
|
+
menuPlugin({
|
|
40
|
+
baseUrl: 'https://example.com',
|
|
41
|
+
relationTo: ['pages', 'posts'],
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This adds a `menus` collection to your admin panel where you can create and manage navigation menus.
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
| Option | Type | Default | Description |
|
|
52
|
+
|---|---|---|---|
|
|
53
|
+
| `baseUrl` | `string` | `''` | Base URL shown as a prefix for internal links |
|
|
54
|
+
| `relationTo` | `string \| string[]` | `'pages'` | Collection(s) available for reference-type links |
|
|
55
|
+
| `maxDepth` | `number` | `2` | Maximum nesting depth for dropdown menus |
|
|
56
|
+
| `disabled` | `boolean` | `false` | Disable the plugin's endpoints and runtime behaviour while keeping the collection in the database schema |
|
|
57
|
+
|
|
58
|
+
### Example
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
menuPlugin({
|
|
62
|
+
baseUrl: 'https://mysite.com',
|
|
63
|
+
relationTo: ['pages', 'posts', 'products'],
|
|
64
|
+
maxDepth: 3,
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Menu Item Types
|
|
69
|
+
|
|
70
|
+
Each menu item has a `type` that determines the URL input behaviour:
|
|
71
|
+
|
|
72
|
+
| Type | Description | Stored value |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| `reference` | Relationship to a Payload document | Relationship field (no URL) |
|
|
75
|
+
| `internal` | Internal path with baseUrl prefix | Full URL (e.g. `https://example.com/about`) |
|
|
76
|
+
| `external` | External URL | Full URL (e.g. `https://other-site.com`) |
|
|
77
|
+
| `anchor` | Anchor link on the current page | `#section-name` |
|
|
78
|
+
| `mailto` | Email link | `mailto:user@example.com` |
|
|
79
|
+
| `tel` | Phone link with country code selector | `tel:+441234567890` |
|
|
80
|
+
| `custom` | Plain text, any value | As entered |
|
|
81
|
+
|
|
82
|
+
## Dropdown Menus
|
|
83
|
+
|
|
84
|
+
Menu items can be either a **link** or a **dropdown**. Dropdowns contain a nested array of child items, which can themselves be links or dropdowns (up to `maxDepth` levels).
|
|
85
|
+
|
|
86
|
+
## Advanced Options
|
|
87
|
+
|
|
88
|
+
Each menu item has an "Advanced" toggle that reveals additional fields:
|
|
89
|
+
|
|
90
|
+
- **Target** — Open in same tab (`_self`) or new tab (`_blank`)
|
|
91
|
+
- **Visibility** — Show or hide the item
|
|
92
|
+
- **Rel** — Custom `rel` attribute (e.g. `noopener noreferrer`)
|
|
93
|
+
- **Roles** — Array of role strings for role-based visibility
|
|
94
|
+
- **Attrs** — Custom HTML attributes as text
|
|
95
|
+
|
|
96
|
+
## REST API
|
|
97
|
+
|
|
98
|
+
### Get a menu by slug
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
GET /api/menus/:slug
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Query parameters:
|
|
105
|
+
- `locale` — Filter by locale field
|
|
106
|
+
- `depth` — Payload relationship depth (default: `0`)
|
|
107
|
+
|
|
108
|
+
Response: The full menu document as JSON.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
curl https://example.com/api/menus/main-menu?depth=1&locale=en
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Export all menus
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
GET /api/menus-export
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Returns all menus as a JSON file download.
|
|
121
|
+
|
|
122
|
+
### Import menus
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
POST /api/menus-import
|
|
126
|
+
Content-Type: application/json
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Accepts a JSON array of menu documents (or `{ menus: [...] }`). Upserts by slug — existing menus are updated, new ones are created.
|
|
130
|
+
|
|
131
|
+
Response:
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"created": 1,
|
|
135
|
+
"updated": 2,
|
|
136
|
+
"errors": []
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Client-Side Usage
|
|
141
|
+
|
|
142
|
+
### `useMenu` Hook
|
|
143
|
+
|
|
144
|
+
A React hook for fetching menus on the client:
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
'use client'
|
|
148
|
+
|
|
149
|
+
import { useMenu } from '@foundrykit/menu-plugin/client'
|
|
150
|
+
|
|
151
|
+
export function Navigation() {
|
|
152
|
+
const { menu, isLoading, error, refetch } = useMenu({
|
|
153
|
+
slug: 'main-menu',
|
|
154
|
+
locale: 'en',
|
|
155
|
+
depth: 1,
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
if (isLoading) return <div>Loading...</div>
|
|
159
|
+
if (error) return <div>Error: {error}</div>
|
|
160
|
+
if (!menu) return null
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<nav>
|
|
164
|
+
{menu.items?.map((item: any) => (
|
|
165
|
+
<a key={item.id} href={item.url} target={item.target}>
|
|
166
|
+
{item.label}
|
|
167
|
+
</a>
|
|
168
|
+
))}
|
|
169
|
+
</nav>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The hook includes a 30-second client-side cache and supports abort on unmount.
|
|
175
|
+
|
|
176
|
+
### Options
|
|
177
|
+
|
|
178
|
+
| Option | Type | Required | Description |
|
|
179
|
+
|---|---|---|---|
|
|
180
|
+
| `slug` | `string` | Yes | The menu slug to fetch |
|
|
181
|
+
| `locale` | `string` | No | Locale filter |
|
|
182
|
+
| `depth` | `number` | No | Relationship population depth (default: `0`) |
|
|
183
|
+
|
|
184
|
+
### Return Value
|
|
185
|
+
|
|
186
|
+
| Property | Type | Description |
|
|
187
|
+
|---|---|---|
|
|
188
|
+
| `menu` | `object \| null` | The fetched menu document |
|
|
189
|
+
| `isLoading` | `boolean` | Whether the request is in progress |
|
|
190
|
+
| `error` | `string \| null` | Error message if the request failed |
|
|
191
|
+
| `refetch` | `() => Promise<void>` | Manually re-fetch the menu |
|
|
192
|
+
|
|
193
|
+
## Server-Side Usage
|
|
194
|
+
|
|
195
|
+
You can also query menus using the Payload Local API:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const menu = await payload.find({
|
|
199
|
+
collection: 'menus',
|
|
200
|
+
where: { slug: { equals: 'main-menu' } },
|
|
201
|
+
depth: 1,
|
|
202
|
+
})
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Caching
|
|
206
|
+
|
|
207
|
+
The plugin includes automatic server-side caching:
|
|
208
|
+
|
|
209
|
+
- Menus are cached after the first API request
|
|
210
|
+
- Cache is automatically invalidated when a menu is created, updated, or deleted
|
|
211
|
+
- Default TTL is 5 minutes
|
|
212
|
+
|
|
213
|
+
## Requirements
|
|
214
|
+
|
|
215
|
+
- Payload CMS v3
|
|
216
|
+
- Node.js 18.20.2+ or 20.9.0+
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
MIT
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class MenuCache {
|
|
2
|
+
private cache;
|
|
3
|
+
private ttl;
|
|
4
|
+
constructor(ttlMs?: number);
|
|
5
|
+
private buildKey;
|
|
6
|
+
clear(): void;
|
|
7
|
+
get(slug: string, locale?: string): any | undefined;
|
|
8
|
+
invalidate(slug: string, locale?: string): void;
|
|
9
|
+
set(slug: string, data: any, locale?: string): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const menuCache: MenuCache;
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class MenuCache {
|
|
2
|
+
cache = new Map();
|
|
3
|
+
ttl;
|
|
4
|
+
constructor(ttlMs = 60_000){
|
|
5
|
+
this.ttl = ttlMs;
|
|
6
|
+
}
|
|
7
|
+
buildKey(slug, locale) {
|
|
8
|
+
return locale ? `${slug}:${locale}` : slug;
|
|
9
|
+
}
|
|
10
|
+
clear() {
|
|
11
|
+
this.cache.clear();
|
|
12
|
+
}
|
|
13
|
+
get(slug, locale) {
|
|
14
|
+
const key = this.buildKey(slug, locale);
|
|
15
|
+
const entry = this.cache.get(key);
|
|
16
|
+
if (!entry) return undefined;
|
|
17
|
+
if (Date.now() > entry.expiresAt) {
|
|
18
|
+
this.cache.delete(key);
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return entry.data;
|
|
22
|
+
}
|
|
23
|
+
invalidate(slug, locale) {
|
|
24
|
+
if (locale) {
|
|
25
|
+
this.cache.delete(this.buildKey(slug, locale));
|
|
26
|
+
} else {
|
|
27
|
+
// Invalidate all locales for this slug
|
|
28
|
+
for (const key of this.cache.keys()){
|
|
29
|
+
if (key === slug || key.startsWith(`${slug}:`)) {
|
|
30
|
+
this.cache.delete(key);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
set(slug, data, locale) {
|
|
36
|
+
const key = this.buildKey(slug, locale);
|
|
37
|
+
this.cache.set(key, {
|
|
38
|
+
data,
|
|
39
|
+
expiresAt: Date.now() + this.ttl
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export const menuCache = new MenuCache();
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cache.ts"],"sourcesContent":["type CacheEntry = {\n data: any\n expiresAt: number\n}\n\nexport class MenuCache {\n private cache = new Map<string, CacheEntry>()\n private ttl: number\n\n constructor(ttlMs = 60_000) {\n this.ttl = ttlMs\n }\n\n private buildKey(slug: string, locale?: string): string {\n return locale ? `${slug}:${locale}` : slug\n }\n\n clear(): void {\n this.cache.clear()\n }\n\n get(slug: string, locale?: string): any | undefined {\n const key = this.buildKey(slug, locale)\n const entry = this.cache.get(key)\n if (!entry) return undefined\n if (Date.now() > entry.expiresAt) {\n this.cache.delete(key)\n return undefined\n }\n return entry.data\n }\n\n invalidate(slug: string, locale?: string): void {\n if (locale) {\n this.cache.delete(this.buildKey(slug, locale))\n } else {\n // Invalidate all locales for this slug\n for (const key of this.cache.keys()) {\n if (key === slug || key.startsWith(`${slug}:`)) {\n this.cache.delete(key)\n }\n }\n }\n }\n\n set(slug: string, data: any, locale?: string): void {\n const key = this.buildKey(slug, locale)\n this.cache.set(key, {\n data,\n expiresAt: Date.now() + this.ttl,\n })\n }\n}\n\nexport const menuCache = new MenuCache()\n"],"names":["MenuCache","cache","Map","ttl","ttlMs","buildKey","slug","locale","clear","get","key","entry","undefined","Date","now","expiresAt","delete","data","invalidate","keys","startsWith","set","menuCache"],"mappings":"AAKA,OAAO,MAAMA;IACHC,QAAQ,IAAIC,MAAyB;IACrCC,IAAW;IAEnB,YAAYC,QAAQ,MAAM,CAAE;QAC1B,IAAI,CAACD,GAAG,GAAGC;IACb;IAEQC,SAASC,IAAY,EAAEC,MAAe,EAAU;QACtD,OAAOA,SAAS,GAAGD,KAAK,CAAC,EAAEC,QAAQ,GAAGD;IACxC;IAEAE,QAAc;QACZ,IAAI,CAACP,KAAK,CAACO,KAAK;IAClB;IAEAC,IAAIH,IAAY,EAAEC,MAAe,EAAmB;QAClD,MAAMG,MAAM,IAAI,CAACL,QAAQ,CAACC,MAAMC;QAChC,MAAMI,QAAQ,IAAI,CAACV,KAAK,CAACQ,GAAG,CAACC;QAC7B,IAAI,CAACC,OAAO,OAAOC;QACnB,IAAIC,KAAKC,GAAG,KAAKH,MAAMI,SAAS,EAAE;YAChC,IAAI,CAACd,KAAK,CAACe,MAAM,CAACN;YAClB,OAAOE;QACT;QACA,OAAOD,MAAMM,IAAI;IACnB;IAEAC,WAAWZ,IAAY,EAAEC,MAAe,EAAQ;QAC9C,IAAIA,QAAQ;YACV,IAAI,CAACN,KAAK,CAACe,MAAM,CAAC,IAAI,CAACX,QAAQ,CAACC,MAAMC;QACxC,OAAO;YACL,uCAAuC;YACvC,KAAK,MAAMG,OAAO,IAAI,CAACT,KAAK,CAACkB,IAAI,GAAI;gBACnC,IAAIT,QAAQJ,QAAQI,IAAIU,UAAU,CAAC,GAAGd,KAAK,CAAC,CAAC,GAAG;oBAC9C,IAAI,CAACL,KAAK,CAACe,MAAM,CAACN;gBACpB;YACF;QACF;IACF;IAEAW,IAAIf,IAAY,EAAEW,IAAS,EAAEV,MAAe,EAAQ;QAClD,MAAMG,MAAM,IAAI,CAACL,QAAQ,CAACC,MAAMC;QAChC,IAAI,CAACN,KAAK,CAACoB,GAAG,CAACX,KAAK;YAClBO;YACAF,WAAWF,KAAKC,GAAG,KAAK,IAAI,CAACX,GAAG;QAClC;IACF;AACF;AAEA,OAAO,MAAMmB,YAAY,IAAItB,YAAW"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import { type MenuItemFieldOptions } from '../fields/MenuItem.js';
|
|
3
|
+
export type MenusCollectionOptions = MenuItemFieldOptions;
|
|
4
|
+
export declare const createMenusCollection: (options?: MenusCollectionOptions) => CollectionConfig;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { menuCache } from '../cache.js';
|
|
2
|
+
import { createMenuItemFields } from '../fields/MenuItem.js';
|
|
3
|
+
export const createMenusCollection = (options)=>({
|
|
4
|
+
slug: 'menus',
|
|
5
|
+
access: {
|
|
6
|
+
read: ()=>true
|
|
7
|
+
},
|
|
8
|
+
admin: {
|
|
9
|
+
defaultColumns: [
|
|
10
|
+
'title',
|
|
11
|
+
'slug',
|
|
12
|
+
'locale',
|
|
13
|
+
'items'
|
|
14
|
+
],
|
|
15
|
+
useAsTitle: 'title'
|
|
16
|
+
},
|
|
17
|
+
fields: [
|
|
18
|
+
{
|
|
19
|
+
name: 'title',
|
|
20
|
+
type: 'text',
|
|
21
|
+
admin: {
|
|
22
|
+
description: 'The name of the menu. E.g. "Main Menu", "Footer Menu", etc.'
|
|
23
|
+
},
|
|
24
|
+
required: true
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'slug',
|
|
28
|
+
type: 'text',
|
|
29
|
+
admin: {
|
|
30
|
+
description: 'Unique identifier for the menu, used in API requests. E.g. "main-menu", "footer-menu", etc.'
|
|
31
|
+
},
|
|
32
|
+
index: true,
|
|
33
|
+
required: true,
|
|
34
|
+
unique: true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'description',
|
|
38
|
+
type: 'textarea',
|
|
39
|
+
admin: {
|
|
40
|
+
description: 'Optional description for the menu.',
|
|
41
|
+
position: 'sidebar'
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'locale',
|
|
46
|
+
type: 'text',
|
|
47
|
+
admin: {
|
|
48
|
+
description: 'Used for localisation. E.g. "en", "fr", etc.',
|
|
49
|
+
position: 'sidebar'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'menuPreview',
|
|
54
|
+
type: 'ui',
|
|
55
|
+
admin: {
|
|
56
|
+
components: {
|
|
57
|
+
Field: 'menu-plugin/client#MenuPreview'
|
|
58
|
+
},
|
|
59
|
+
position: 'sidebar'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'items',
|
|
64
|
+
type: 'array',
|
|
65
|
+
admin: {
|
|
66
|
+
components: {
|
|
67
|
+
RowLabel: 'menu-plugin/client#MenuItemRowLabel'
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
fields: createMenuItemFields(options)
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
hooks: {
|
|
74
|
+
afterChange: [
|
|
75
|
+
({ doc })=>{
|
|
76
|
+
if (doc.slug) {
|
|
77
|
+
menuCache.invalidate(doc.slug, doc.locale);
|
|
78
|
+
}
|
|
79
|
+
return doc;
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
afterDelete: [
|
|
83
|
+
({ doc })=>{
|
|
84
|
+
if (doc.slug) {
|
|
85
|
+
menuCache.invalidate(doc.slug, doc.locale);
|
|
86
|
+
}
|
|
87
|
+
return doc;
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
labels: {
|
|
92
|
+
plural: 'Menus',
|
|
93
|
+
singular: 'Menu'
|
|
94
|
+
},
|
|
95
|
+
timestamps: true
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=Menus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/collections/Menus.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport { menuCache } from '../cache.js'\nimport { createMenuItemFields, type MenuItemFieldOptions } from '../fields/MenuItem.js'\n\nexport type MenusCollectionOptions = MenuItemFieldOptions\n\nexport const createMenusCollection = (options?: MenusCollectionOptions): CollectionConfig => ({\n slug: 'menus',\n access: {\n read: () => true,\n },\n admin: {\n defaultColumns: ['title', 'slug', 'locale', 'items'],\n useAsTitle: 'title',\n },\n fields: [\n {\n name: 'title',\n type: 'text',\n admin: {\n description: 'The name of the menu. E.g. \"Main Menu\", \"Footer Menu\", etc.',\n },\n required: true,\n },\n {\n name: 'slug',\n type: 'text',\n admin: {\n description:\n 'Unique identifier for the menu, used in API requests. E.g. \"main-menu\", \"footer-menu\", etc.',\n },\n index: true,\n required: true,\n unique: true,\n },\n {\n name: 'description',\n type: 'textarea',\n admin: {\n description: 'Optional description for the menu.',\n position: 'sidebar',\n },\n },\n {\n name: 'locale',\n type: 'text',\n admin: {\n description: 'Used for localisation. E.g. \"en\", \"fr\", etc.',\n position: 'sidebar',\n },\n },\n {\n name: 'menuPreview',\n type: 'ui',\n admin: {\n components: {\n Field: 'menu-plugin/client#MenuPreview',\n },\n position: 'sidebar',\n },\n },\n {\n name: 'items',\n type: 'array',\n admin: {\n components: {\n RowLabel: 'menu-plugin/client#MenuItemRowLabel',\n },\n },\n fields: createMenuItemFields(options),\n },\n ],\n hooks: {\n afterChange: [\n ({ doc }) => {\n if (doc.slug) {\n menuCache.invalidate(doc.slug, doc.locale)\n }\n return doc\n },\n ],\n afterDelete: [\n ({ doc }) => {\n if (doc.slug) {\n menuCache.invalidate(doc.slug, doc.locale)\n }\n return doc\n },\n ],\n },\n labels: {\n plural: 'Menus',\n singular: 'Menu',\n },\n timestamps: true,\n})\n"],"names":["menuCache","createMenuItemFields","createMenusCollection","options","slug","access","read","admin","defaultColumns","useAsTitle","fields","name","type","description","required","index","unique","position","components","Field","RowLabel","hooks","afterChange","doc","invalidate","locale","afterDelete","labels","plural","singular","timestamps"],"mappings":"AAEA,SAASA,SAAS,QAAQ,cAAa;AACvC,SAASC,oBAAoB,QAAmC,wBAAuB;AAIvF,OAAO,MAAMC,wBAAwB,CAACC,UAAwD,CAAA;QAC5FC,MAAM;QACNC,QAAQ;YACNC,MAAM,IAAM;QACd;QACAC,OAAO;YACLC,gBAAgB;gBAAC;gBAAS;gBAAQ;gBAAU;aAAQ;YACpDC,YAAY;QACd;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNL,OAAO;oBACLM,aAAa;gBACf;gBACAC,UAAU;YACZ;YACA;gBACEH,MAAM;gBACNC,MAAM;gBACNL,OAAO;oBACLM,aACE;gBACJ;gBACAE,OAAO;gBACPD,UAAU;gBACVE,QAAQ;YACV;YACA;gBACEL,MAAM;gBACNC,MAAM;gBACNL,OAAO;oBACLM,aAAa;oBACbI,UAAU;gBACZ;YACF;YACA;gBACEN,MAAM;gBACNC,MAAM;gBACNL,OAAO;oBACLM,aAAa;oBACbI,UAAU;gBACZ;YACF;YACA;gBACEN,MAAM;gBACNC,MAAM;gBACNL,OAAO;oBACLW,YAAY;wBACVC,OAAO;oBACT;oBACAF,UAAU;gBACZ;YACF;YACA;gBACEN,MAAM;gBACNC,MAAM;gBACNL,OAAO;oBACLW,YAAY;wBACVE,UAAU;oBACZ;gBACF;gBACAV,QAAQT,qBAAqBE;YAC/B;SACD;QACDkB,OAAO;YACLC,aAAa;gBACX,CAAC,EAAEC,GAAG,EAAE;oBACN,IAAIA,IAAInB,IAAI,EAAE;wBACZJ,UAAUwB,UAAU,CAACD,IAAInB,IAAI,EAAEmB,IAAIE,MAAM;oBAC3C;oBACA,OAAOF;gBACT;aACD;YACDG,aAAa;gBACX,CAAC,EAAEH,GAAG,EAAE;oBACN,IAAIA,IAAInB,IAAI,EAAE;wBACZJ,UAAUwB,UAAU,CAACD,IAAInB,IAAI,EAAEmB,IAAIE,MAAM;oBAC3C;oBACA,OAAOF;gBACT;aACD;QACH;QACAI,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;QACAC,YAAY;IACd,CAAA,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BeforeDashboardClient: () => import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useConfig } from '@payloadcms/ui';
|
|
4
|
+
import { formatAdminURL } from 'payload/shared';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
export const BeforeDashboardClient = ()=>{
|
|
7
|
+
const { config } = useConfig();
|
|
8
|
+
const [message, setMessage] = useState('');
|
|
9
|
+
useEffect(()=>{
|
|
10
|
+
const fetchMessage = async ()=>{
|
|
11
|
+
const response = await fetch(formatAdminURL({
|
|
12
|
+
apiRoute: config.routes.api,
|
|
13
|
+
path: '/my-plugin-endpoint'
|
|
14
|
+
}));
|
|
15
|
+
const result = await response.json();
|
|
16
|
+
setMessage(result.message);
|
|
17
|
+
};
|
|
18
|
+
void fetchMessage();
|
|
19
|
+
}, [
|
|
20
|
+
config.serverURL,
|
|
21
|
+
config.routes.api
|
|
22
|
+
]);
|
|
23
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
24
|
+
children: [
|
|
25
|
+
/*#__PURE__*/ _jsx("h1", {
|
|
26
|
+
children: "Added by the plugin: Before Dashboard Client"
|
|
27
|
+
}),
|
|
28
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
29
|
+
children: [
|
|
30
|
+
"Message from the endpoint:",
|
|
31
|
+
/*#__PURE__*/ _jsx("div", {
|
|
32
|
+
children: message || 'Loading...'
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
})
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=BeforeDashboardClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/BeforeDashboardClient.tsx"],"sourcesContent":["'use client'\nimport { useConfig } from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport { useEffect, useState } from 'react'\n\nexport const BeforeDashboardClient = () => {\n const { config } = useConfig()\n\n const [message, setMessage] = useState('')\n\n useEffect(() => {\n const fetchMessage = async () => {\n const response = await fetch(\n formatAdminURL({\n apiRoute: config.routes.api,\n path: '/my-plugin-endpoint',\n } as any),\n )\n const result = await response.json()\n setMessage(result.message)\n }\n\n void fetchMessage()\n }, [config.serverURL, config.routes.api])\n\n return (\n <div>\n <h1>Added by the plugin: Before Dashboard Client</h1>\n <div>\n Message from the endpoint:\n <div>{message || 'Loading...'}</div>\n </div>\n </div>\n )\n}\n"],"names":["useConfig","formatAdminURL","useEffect","useState","BeforeDashboardClient","config","message","setMessage","fetchMessage","response","fetch","apiRoute","routes","api","path","result","json","serverURL","div","h1"],"mappings":"AAAA;;AACA,SAASA,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAE3C,OAAO,MAAMC,wBAAwB;IACnC,MAAM,EAAEC,MAAM,EAAE,GAAGL;IAEnB,MAAM,CAACM,SAASC,WAAW,GAAGJ,SAAS;IAEvCD,UAAU;QACR,MAAMM,eAAe;YACnB,MAAMC,WAAW,MAAMC,MACrBT,eAAe;gBACbU,UAAUN,OAAOO,MAAM,CAACC,GAAG;gBAC3BC,MAAM;YACR;YAEF,MAAMC,SAAS,MAAMN,SAASO,IAAI;YAClCT,WAAWQ,OAAOT,OAAO;QAC3B;QAEA,KAAKE;IACP,GAAG;QAACH,OAAOY,SAAS;QAAEZ,OAAOO,MAAM,CAACC,GAAG;KAAC;IAExC,qBACE,MAACK;;0BACC,KAACC;0BAAG;;0BACJ,MAACD;;oBAAI;kCAEH,KAACA;kCAAKZ,WAAW;;;;;;AAIzB,EAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import styles from './BeforeDashboardServer.module.css';
|
|
3
|
+
export const BeforeDashboardServer = async (props)=>{
|
|
4
|
+
const { payload } = props;
|
|
5
|
+
const { docs } = await payload.find({
|
|
6
|
+
collection: 'plugin-collection'
|
|
7
|
+
});
|
|
8
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
9
|
+
className: styles.wrapper,
|
|
10
|
+
children: [
|
|
11
|
+
/*#__PURE__*/ _jsx("h1", {
|
|
12
|
+
children: "Added by the plugin: Before Dashboard Server"
|
|
13
|
+
}),
|
|
14
|
+
"Docs from Local API:",
|
|
15
|
+
docs.map((doc)=>/*#__PURE__*/ _jsx("div", {
|
|
16
|
+
children: doc.id
|
|
17
|
+
}, doc.id))
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=BeforeDashboardServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/BeforeDashboardServer.tsx"],"sourcesContent":["import type { ServerComponentProps } from 'payload'\n\nimport styles from './BeforeDashboardServer.module.css'\n\nexport const BeforeDashboardServer = async (props: ServerComponentProps) => {\n const { payload } = props\n\n const { docs } = await payload.find({ collection: 'plugin-collection' })\n\n return (\n <div className={styles.wrapper}>\n <h1>Added by the plugin: Before Dashboard Server</h1>\n Docs from Local API:\n {docs.map((doc) => (\n <div key={doc.id}>{doc.id}</div>\n ))}\n </div>\n )\n}\n"],"names":["styles","BeforeDashboardServer","props","payload","docs","find","collection","div","className","wrapper","h1","map","doc","id"],"mappings":";AAEA,OAAOA,YAAY,qCAAoC;AAEvD,OAAO,MAAMC,wBAAwB,OAAOC;IAC1C,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAM,EAAEE,IAAI,EAAE,GAAG,MAAMD,QAAQE,IAAI,CAAC;QAAEC,YAAY;IAAoB;IAEtE,qBACE,MAACC;QAAIC,WAAWR,OAAOS,OAAO;;0BAC5B,KAACC;0BAAG;;YAAiD;YAEpDN,KAAKO,GAAG,CAAC,CAACC,oBACT,KAACL;8BAAkBK,IAAIC,EAAE;mBAAfD,IAAIC,EAAE;;;AAIxB,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MenuItemRowLabel: () => import("react").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRowLabel } from '@payloadcms/ui';
|
|
4
|
+
export const MenuItemRowLabel = ()=>{
|
|
5
|
+
const { data, rowNumber } = useRowLabel();
|
|
6
|
+
const customLabel = `Menu Item: ${data.label || String(rowNumber).padStart(2, '0')}`;
|
|
7
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
8
|
+
children: customLabel
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=MenuItemRowLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/MenuItemRowLabel.tsx"],"sourcesContent":["'use client'\n\nimport { useRowLabel } from '@payloadcms/ui'\n\nexport const MenuItemRowLabel = () => {\n const { data, rowNumber } = useRowLabel<{ label?: string }>()\n\n const customLabel = `Menu Item: ${data.label || String(rowNumber).padStart(2, '0')}`\n\n return <div>{customLabel}</div>\n}\n"],"names":["useRowLabel","MenuItemRowLabel","data","rowNumber","customLabel","label","String","padStart","div"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,iBAAgB;AAE5C,OAAO,MAAMC,mBAAmB;IAC9B,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGH;IAE5B,MAAMI,cAAc,CAAC,WAAW,EAAEF,KAAKG,KAAK,IAAIC,OAAOH,WAAWI,QAAQ,CAAC,GAAG,MAAM;IAEpF,qBAAO,KAACC;kBAAKJ;;AACf,EAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useAllFormFields, useWatchForm } from '@payloadcms/ui';
|
|
4
|
+
import React, { useMemo } from 'react';
|
|
5
|
+
const TreeItem = ({ depth = 0, item })=>{
|
|
6
|
+
const indent = depth * 16;
|
|
7
|
+
const isDropdown = item.itemType === 'dropdown';
|
|
8
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
9
|
+
style: {
|
|
10
|
+
paddingLeft: `${indent}px`
|
|
11
|
+
},
|
|
12
|
+
children: [
|
|
13
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
14
|
+
style: {
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
borderBottom: '1px solid var(--theme-elevation-100)',
|
|
17
|
+
display: 'flex',
|
|
18
|
+
gap: '6px',
|
|
19
|
+
padding: '4px 0'
|
|
20
|
+
},
|
|
21
|
+
children: [
|
|
22
|
+
/*#__PURE__*/ _jsx("span", {
|
|
23
|
+
style: {
|
|
24
|
+
fontSize: '12px',
|
|
25
|
+
opacity: 0.5
|
|
26
|
+
},
|
|
27
|
+
children: isDropdown ? '\u25BC' : '\u2192'
|
|
28
|
+
}),
|
|
29
|
+
/*#__PURE__*/ _jsx("span", {
|
|
30
|
+
style: {
|
|
31
|
+
fontSize: '13px',
|
|
32
|
+
fontWeight: isDropdown ? 600 : 400
|
|
33
|
+
},
|
|
34
|
+
children: item.label || 'Untitled'
|
|
35
|
+
}),
|
|
36
|
+
!isDropdown && item.type && /*#__PURE__*/ _jsx("span", {
|
|
37
|
+
style: {
|
|
38
|
+
background: 'var(--theme-elevation-100)',
|
|
39
|
+
borderRadius: '3px',
|
|
40
|
+
fontSize: '10px',
|
|
41
|
+
padding: '1px 5px'
|
|
42
|
+
},
|
|
43
|
+
children: item.type
|
|
44
|
+
})
|
|
45
|
+
]
|
|
46
|
+
}),
|
|
47
|
+
isDropdown && item.children?.map((child, i)=>/*#__PURE__*/ _jsx(TreeItem, {
|
|
48
|
+
depth: depth + 1,
|
|
49
|
+
item: child
|
|
50
|
+
}, i))
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
export const MenuPreview = ()=>{
|
|
55
|
+
const { getData } = useWatchForm();
|
|
56
|
+
// Subscribe to all form fields so the component re-renders on any change
|
|
57
|
+
const [fields] = useAllFormFields();
|
|
58
|
+
const items = useMemo(()=>{
|
|
59
|
+
const data = getData();
|
|
60
|
+
return data?.items || [];
|
|
61
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
|
+
}, [
|
|
63
|
+
getData,
|
|
64
|
+
fields
|
|
65
|
+
]);
|
|
66
|
+
if (!items.length) {
|
|
67
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
68
|
+
style: {
|
|
69
|
+
color: 'var(--theme-elevation-500)',
|
|
70
|
+
fontSize: '13px',
|
|
71
|
+
padding: '12px 0'
|
|
72
|
+
},
|
|
73
|
+
children: "Add items to see a preview."
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
77
|
+
style: {
|
|
78
|
+
padding: '8px 0'
|
|
79
|
+
},
|
|
80
|
+
children: [
|
|
81
|
+
/*#__PURE__*/ _jsx("div", {
|
|
82
|
+
style: {
|
|
83
|
+
borderBottom: '1px solid var(--theme-elevation-150)',
|
|
84
|
+
fontSize: '13px',
|
|
85
|
+
fontWeight: 600,
|
|
86
|
+
marginBottom: '8px',
|
|
87
|
+
paddingBottom: '6px'
|
|
88
|
+
},
|
|
89
|
+
children: "Menu Structure"
|
|
90
|
+
}),
|
|
91
|
+
items.map((item, i)=>/*#__PURE__*/ _jsx(TreeItem, {
|
|
92
|
+
item: item
|
|
93
|
+
}, i))
|
|
94
|
+
]
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=MenuPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/MenuPreview.tsx"],"sourcesContent":["'use client'\n\nimport { useAllFormFields, useWatchForm } from '@payloadcms/ui'\nimport React, { useMemo } from 'react'\n\ntype MenuItem = {\n children?: MenuItem[]\n itemType?: string\n label?: string\n type?: string\n url?: string\n}\n\nconst TreeItem: React.FC<{ depth?: number; item: MenuItem }> = ({ depth = 0, item }) => {\n const indent = depth * 16\n const isDropdown = item.itemType === 'dropdown'\n\n return (\n <div style={{ paddingLeft: `${indent}px` }}>\n <div\n style={{\n alignItems: 'center',\n borderBottom: '1px solid var(--theme-elevation-100)',\n display: 'flex',\n gap: '6px',\n padding: '4px 0',\n }}\n >\n <span style={{ fontSize: '12px', opacity: 0.5 }}>{isDropdown ? '\\u25BC' : '\\u2192'}</span>\n <span style={{ fontSize: '13px', fontWeight: isDropdown ? 600 : 400 }}>\n {item.label || 'Untitled'}\n </span>\n {!isDropdown && item.type && (\n <span\n style={{\n background: 'var(--theme-elevation-100)',\n borderRadius: '3px',\n fontSize: '10px',\n padding: '1px 5px',\n }}\n >\n {item.type}\n </span>\n )}\n </div>\n {isDropdown &&\n item.children?.map((child, i) => <TreeItem depth={depth + 1} item={child} key={i} />)}\n </div>\n )\n}\n\nexport const MenuPreview: React.FC = () => {\n const { getData } = useWatchForm()\n // Subscribe to all form fields so the component re-renders on any change\n const [fields] = useAllFormFields()\n\n const items = useMemo(() => {\n const data = getData()\n return (data?.items as MenuItem[]) || []\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [getData, fields])\n\n if (!items.length) {\n return (\n <div\n style={{\n color: 'var(--theme-elevation-500)',\n fontSize: '13px',\n padding: '12px 0',\n }}\n >\n Add items to see a preview.\n </div>\n )\n }\n\n return (\n <div style={{ padding: '8px 0' }}>\n <div\n style={{\n borderBottom: '1px solid var(--theme-elevation-150)',\n fontSize: '13px',\n fontWeight: 600,\n marginBottom: '8px',\n paddingBottom: '6px',\n }}\n >\n Menu Structure\n </div>\n {items.map((item, i) => (\n <TreeItem item={item} key={i} />\n ))}\n </div>\n )\n}\n"],"names":["useAllFormFields","useWatchForm","React","useMemo","TreeItem","depth","item","indent","isDropdown","itemType","div","style","paddingLeft","alignItems","borderBottom","display","gap","padding","span","fontSize","opacity","fontWeight","label","type","background","borderRadius","children","map","child","i","MenuPreview","getData","fields","items","data","length","color","marginBottom","paddingBottom"],"mappings":"AAAA;;AAEA,SAASA,gBAAgB,EAAEC,YAAY,QAAQ,iBAAgB;AAC/D,OAAOC,SAASC,OAAO,QAAQ,QAAO;AAUtC,MAAMC,WAAyD,CAAC,EAAEC,QAAQ,CAAC,EAAEC,IAAI,EAAE;IACjF,MAAMC,SAASF,QAAQ;IACvB,MAAMG,aAAaF,KAAKG,QAAQ,KAAK;IAErC,qBACE,MAACC;QAAIC,OAAO;YAAEC,aAAa,GAAGL,OAAO,EAAE,CAAC;QAAC;;0BACvC,MAACG;gBACCC,OAAO;oBACLE,YAAY;oBACZC,cAAc;oBACdC,SAAS;oBACTC,KAAK;oBACLC,SAAS;gBACX;;kCAEA,KAACC;wBAAKP,OAAO;4BAAEQ,UAAU;4BAAQC,SAAS;wBAAI;kCAAIZ,aAAa,WAAW;;kCAC1E,KAACU;wBAAKP,OAAO;4BAAEQ,UAAU;4BAAQE,YAAYb,aAAa,MAAM;wBAAI;kCACjEF,KAAKgB,KAAK,IAAI;;oBAEhB,CAACd,cAAcF,KAAKiB,IAAI,kBACvB,KAACL;wBACCP,OAAO;4BACLa,YAAY;4BACZC,cAAc;4BACdN,UAAU;4BACVF,SAAS;wBACX;kCAECX,KAAKiB,IAAI;;;;YAIff,cACCF,KAAKoB,QAAQ,EAAEC,IAAI,CAACC,OAAOC,kBAAM,KAACzB;oBAASC,OAAOA,QAAQ;oBAAGC,MAAMsB;mBAAYC;;;AAGvF;AAEA,OAAO,MAAMC,cAAwB;IACnC,MAAM,EAAEC,OAAO,EAAE,GAAG9B;IACpB,yEAAyE;IACzE,MAAM,CAAC+B,OAAO,GAAGhC;IAEjB,MAAMiC,QAAQ9B,QAAQ;QACpB,MAAM+B,OAAOH;QACb,OAAO,AAACG,MAAMD,SAAwB,EAAE;IACxC,uDAAuD;IACzD,GAAG;QAACF;QAASC;KAAO;IAEpB,IAAI,CAACC,MAAME,MAAM,EAAE;QACjB,qBACE,KAACzB;YACCC,OAAO;gBACLyB,OAAO;gBACPjB,UAAU;gBACVF,SAAS;YACX;sBACD;;IAIL;IAEA,qBACE,MAACP;QAAIC,OAAO;YAAEM,SAAS;QAAQ;;0BAC7B,KAACP;gBACCC,OAAO;oBACLG,cAAc;oBACdK,UAAU;oBACVE,YAAY;oBACZgB,cAAc;oBACdC,eAAe;gBACjB;0BACD;;YAGAL,MAAMN,GAAG,CAAC,CAACrB,MAAMuB,kBAChB,KAACzB;oBAASE,MAAMA;mBAAWuB;;;AAInC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SubMenuItemRowLabel: () => import("react").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRowLabel } from '@payloadcms/ui';
|
|
4
|
+
export const SubMenuItemRowLabel = ()=>{
|
|
5
|
+
const { data, rowNumber } = useRowLabel();
|
|
6
|
+
const customLabel = `Sub Menu Item: ${data.label || String(rowNumber).padStart(2, '0')}`;
|
|
7
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
8
|
+
children: customLabel
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=SubMenuItemRowLabel.js.map
|