@foundrykit/menu-plugin 0.4.2 → 0.5.0
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/dist/collections/Menus.d.ts +3 -2
- package/dist/collections/Menus.js +10 -1
- package/dist/collections/Menus.js.map +1 -1
- package/dist/components/MegaEntryRowLabel.d.ts +1 -0
- package/dist/components/MegaEntryRowLabel.js +12 -0
- package/dist/components/MegaEntryRowLabel.js.map +1 -0
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/fields/MenuItem.d.ts +2 -0
- package/dist/fields/MenuItem.js +309 -219
- package/dist/fields/MenuItem.js.map +1 -1
- package/dist/hooks/resolveDynamicMenu.d.ts +13 -0
- package/dist/hooks/resolveDynamicMenu.js +221 -0
- package/dist/hooks/resolveDynamicMenu.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/migrations/megaColumnsToEntries.d.ts +19 -0
- package/dist/migrations/megaColumnsToEntries.js +142 -0
- package/dist/migrations/megaColumnsToEntries.js.map +1 -0
- package/dist/types.d.ts +34 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CollectionConfig } from 'payload';
|
|
2
2
|
import { type MenuItemFieldOptions } from '../fields/MenuItem.js';
|
|
3
|
-
export type MenusCollectionOptions =
|
|
3
|
+
export type MenusCollectionOptions = {
|
|
4
|
+
childrenDepth?: number;
|
|
4
5
|
disabled?: boolean;
|
|
5
|
-
};
|
|
6
|
+
} & MenuItemFieldOptions;
|
|
6
7
|
export declare const createMenusCollection: (options?: MenusCollectionOptions) => CollectionConfig;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { menuCache } from '../cache.js';
|
|
2
2
|
import { createMenuItemFields } from '../fields/MenuItem.js';
|
|
3
|
+
import { createResolveDynamicMenuHook } from '../hooks/resolveDynamicMenu.js';
|
|
3
4
|
import { buildMenuIdentityKey, normalizeMenuLocale } from '../utilities/menuIdentity.js';
|
|
4
5
|
export const createMenusCollection = (options)=>({
|
|
5
6
|
slug: 'menus',
|
|
@@ -86,7 +87,9 @@ export const createMenusCollection = (options)=>({
|
|
|
86
87
|
hooks: {
|
|
87
88
|
beforeValidate: [
|
|
88
89
|
({ data })=>{
|
|
89
|
-
if (!data)
|
|
90
|
+
if (!data) {
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
90
93
|
const normalizedLocale = normalizeMenuLocale(data.locale);
|
|
91
94
|
return {
|
|
92
95
|
...data,
|
|
@@ -114,6 +117,12 @@ export const createMenusCollection = (options)=>({
|
|
|
114
117
|
}
|
|
115
118
|
return doc;
|
|
116
119
|
}
|
|
120
|
+
],
|
|
121
|
+
afterRead: [
|
|
122
|
+
createResolveDynamicMenuHook({
|
|
123
|
+
childrenDepth: options?.childrenDepth,
|
|
124
|
+
dynamicSources: options?.dynamicSources
|
|
125
|
+
})
|
|
117
126
|
]
|
|
118
127
|
}
|
|
119
128
|
},
|
|
@@ -1 +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'\nimport { buildMenuIdentityKey, normalizeMenuLocale } from '../utilities/menuIdentity.js'\n\nexport type MenusCollectionOptions =
|
|
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'\nimport { createResolveDynamicMenuHook } from '../hooks/resolveDynamicMenu.js'\nimport { buildMenuIdentityKey, normalizeMenuLocale } from '../utilities/menuIdentity.js'\n\nexport type MenusCollectionOptions = {\n childrenDepth?: number\n disabled?: boolean\n} & 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 },\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 ...(options?.disabled\n ? []\n : [\n {\n name: 'menuPreview',\n type: 'ui',\n admin: {\n components: {\n Field: '@foundrykit/menu-plugin/client#MenuPreview',\n },\n position: 'sidebar',\n },\n } as const,\n ]),\n {\n name: 'slugLocaleKey',\n type: 'text',\n admin: {\n hidden: true,\n },\n index: true,\n unique: true,\n },\n {\n name: 'items',\n type: 'array',\n admin: {\n ...(options?.disabled\n ? {}\n : {\n components: {\n RowLabel: '@foundrykit/menu-plugin/client#MenuItemRowLabel',\n },\n }),\n },\n fields: createMenuItemFields(options),\n },\n ],\n hooks: {\n beforeValidate: [\n ({ data }) => {\n if (!data) {return data}\n\n const normalizedLocale = normalizeMenuLocale(data.locale)\n\n return {\n ...data,\n locale: normalizedLocale,\n slugLocaleKey: data.slug ? buildMenuIdentityKey(data.slug, normalizedLocale) : data.slugLocaleKey,\n }\n },\n ],\n ...(options?.disabled\n ? {}\n : {\n afterChange: [\n ({ doc, previousDoc }) => {\n if (previousDoc?.slug) {\n menuCache.invalidate(previousDoc.slug)\n }\n if (doc.slug) {\n menuCache.invalidate(doc.slug)\n }\n return doc\n },\n ],\n afterDelete: [\n ({ doc }) => {\n if (doc.slug) {\n menuCache.invalidate(doc.slug)\n }\n return doc\n },\n ],\n afterRead: [\n createResolveDynamicMenuHook({\n childrenDepth: options?.childrenDepth,\n dynamicSources: options?.dynamicSources,\n }),\n ],\n }),\n },\n labels: {\n plural: 'Menus',\n singular: 'Menu',\n },\n timestamps: true,\n})\n"],"names":["menuCache","createMenuItemFields","createResolveDynamicMenuHook","buildMenuIdentityKey","normalizeMenuLocale","createMenusCollection","options","slug","access","read","admin","defaultColumns","useAsTitle","fields","name","type","description","required","index","position","disabled","components","Field","hidden","unique","RowLabel","hooks","beforeValidate","data","normalizedLocale","locale","slugLocaleKey","afterChange","doc","previousDoc","invalidate","afterDelete","afterRead","childrenDepth","dynamicSources","labels","plural","singular","timestamps"],"mappings":"AAEA,SAASA,SAAS,QAAQ,cAAa;AACvC,SAASC,oBAAoB,QAAmC,wBAAuB;AACvF,SAASC,4BAA4B,QAAQ,iCAAgC;AAC7E,SAASC,oBAAoB,EAAEC,mBAAmB,QAAQ,+BAA8B;AAOxF,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;YACZ;YACA;gBACEH,MAAM;gBACNC,MAAM;gBACNL,OAAO;oBACLM,aAAa;oBACbG,UAAU;gBACZ;YACF;YACA;gBACEL,MAAM;gBACNC,MAAM;gBACNL,OAAO;oBACLM,aAAa;oBACbG,UAAU;gBACZ;YACF;eACIb,SAASc,WACT,EAAE,GACF;gBACE;o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P;QACAC,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;QACAC,YAAY;IACd,CAAA,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MegaEntryRowLabel: () => 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 MegaEntryRowLabel = ()=>{
|
|
5
|
+
const { data, rowNumber } = useRowLabel();
|
|
6
|
+
const suffix = data.source === 'dynamic' ? ' (dynamic)' : '';
|
|
7
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
8
|
+
children: `Entry: ${data.label || String(rowNumber).padStart(2, '0')}${suffix}`
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=MegaEntryRowLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/MegaEntryRowLabel.tsx"],"sourcesContent":["'use client'\n\nimport { useRowLabel } from '@payloadcms/ui'\n\nexport const MegaEntryRowLabel = () => {\n const { data, rowNumber } = useRowLabel<{ label?: string; source?: string }>()\n\n const suffix = data.source === 'dynamic' ? ' (dynamic)' : ''\n\n return <div>{`Entry: ${data.label || String(rowNumber).padStart(2, '0')}${suffix}`}</div>\n}\n"],"names":["useRowLabel","MegaEntryRowLabel","data","rowNumber","suffix","source","div","label","String","padStart"],"mappings":"AAAA;;AAEA,SAASA,WAAW,QAAQ,iBAAgB;AAE5C,OAAO,MAAMC,oBAAoB;IAC/B,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGH;IAE5B,MAAMI,SAASF,KAAKG,MAAM,KAAK,YAAY,eAAe;IAE1D,qBAAO,KAACC;kBAAK,CAAC,OAAO,EAAEJ,KAAKK,KAAK,IAAIC,OAAOL,WAAWM,QAAQ,CAAC,GAAG,OAAOL,QAAQ;;AACpF,EAAC"}
|
package/dist/exports/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ColumnLinkRowLabel } from '../components/ColumnLinkRowLabel.js';
|
|
2
|
-
export {
|
|
2
|
+
export { MegaEntryRowLabel } from '../components/MegaEntryRowLabel.js';
|
|
3
3
|
export { MenuItemRowLabel } from '../components/MenuItemRowLabel.js';
|
|
4
4
|
export { MenuPreview } from '../components/MenuPreview.js';
|
|
5
5
|
export { SubMenuItemRowLabel } from '../components/SubMenuItemRowLabel.js';
|
package/dist/exports/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ColumnLinkRowLabel } from '../components/ColumnLinkRowLabel.js';
|
|
2
|
-
export {
|
|
2
|
+
export { MegaEntryRowLabel } from '../components/MegaEntryRowLabel.js';
|
|
3
3
|
export { MenuItemRowLabel } from '../components/MenuItemRowLabel.js';
|
|
4
4
|
export { MenuPreview } from '../components/MenuPreview.js';
|
|
5
5
|
export { SubMenuItemRowLabel } from '../components/SubMenuItemRowLabel.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { ColumnLinkRowLabel } from '../components/ColumnLinkRowLabel.js'\nexport {
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { ColumnLinkRowLabel } from '../components/ColumnLinkRowLabel.js'\nexport { MegaEntryRowLabel } from '../components/MegaEntryRowLabel.js'\nexport { MenuItemRowLabel } from '../components/MenuItemRowLabel.js'\nexport { MenuPreview } from '../components/MenuPreview.js'\nexport { SubMenuItemRowLabel } from '../components/SubMenuItemRowLabel.js'\nexport { fetchMenu } from '../fetchMenu.js'\nexport { UrlField } from '../components/UrlField/index.js'\nexport { useMenu } from '../hooks/useMenu.js'\n"],"names":["ColumnLinkRowLabel","MegaEntryRowLabel","MenuItemRowLabel","MenuPreview","SubMenuItemRowLabel","fetchMenu","UrlField","useMenu"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,sCAAqC;AACxE,SAASC,iBAAiB,QAAQ,qCAAoC;AACtE,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,mBAAmB,QAAQ,uCAAsC;AAC1E,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,QAAQ,QAAQ,kCAAiC;AAC1D,SAASC,OAAO,QAAQ,sBAAqB"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { CollectionSlug, Field } from 'payload';
|
|
2
|
+
import type { DynamicSource } from '../types.js';
|
|
2
3
|
export type MenuItemFieldOptions = {
|
|
3
4
|
baseUrl?: string;
|
|
4
5
|
disabled?: boolean;
|
|
6
|
+
dynamicSources?: DynamicSource[];
|
|
5
7
|
maxDepth?: number;
|
|
6
8
|
mediaCollection?: CollectionSlug;
|
|
7
9
|
relationTo?: CollectionSlug | CollectionSlug[];
|