@ainsleydev/payload-helper 0.0.33 → 0.0.35
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.
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Field, type GlobalConfig, type Tab } from 'payload';
|
|
2
2
|
/**
|
|
3
3
|
* Navigation Configuration for the header and footer
|
|
4
4
|
* nav links.
|
|
5
5
|
*/
|
|
6
6
|
interface NavigationConfig {
|
|
7
|
+
overrides?: Partial<Omit<GlobalConfig, 'slug' | 'fields'>>;
|
|
7
8
|
includeFooter?: boolean;
|
|
8
9
|
header?: NavigationMenuConfig;
|
|
9
10
|
footer?: NavigationMenuConfig;
|
|
@@ -22,7 +23,7 @@ interface NavigationMenuConfig {
|
|
|
22
23
|
* Additional fields will be appended to each navigation item.
|
|
23
24
|
*
|
|
24
25
|
* @constructor
|
|
25
|
-
* @param
|
|
26
|
+
* @param args
|
|
26
27
|
*/
|
|
27
|
-
export declare const Navigation: (
|
|
28
|
+
export declare const Navigation: (args?: NavigationConfig) => GlobalConfig;
|
|
28
29
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deepMerge } from 'payload';
|
|
1
2
|
/**
|
|
2
3
|
* Function to generate children structure recursively.
|
|
3
4
|
*
|
|
@@ -67,8 +68,8 @@
|
|
|
67
68
|
* Additional fields will be appended to each navigation item.
|
|
68
69
|
*
|
|
69
70
|
* @constructor
|
|
70
|
-
* @param
|
|
71
|
-
*/ export const Navigation = (
|
|
71
|
+
* @param args
|
|
72
|
+
*/ export const Navigation = (args)=>{
|
|
72
73
|
const tabs = [
|
|
73
74
|
{
|
|
74
75
|
label: 'Header',
|
|
@@ -79,7 +80,6 @@
|
|
|
79
80
|
label: 'Items',
|
|
80
81
|
type: 'array',
|
|
81
82
|
interfaceName: 'NavigationHeaderLinks',
|
|
82
|
-
maxRows: 8,
|
|
83
83
|
labels: {
|
|
84
84
|
singular: 'Link',
|
|
85
85
|
plural: 'Links'
|
|
@@ -90,14 +90,14 @@
|
|
|
90
90
|
},
|
|
91
91
|
fields: [
|
|
92
92
|
...navFields,
|
|
93
|
-
...
|
|
94
|
-
...
|
|
93
|
+
...args?.header?.maxDepth ? generateChildren(0, args.header.maxDepth, navFields) : [],
|
|
94
|
+
...args?.header?.additionalFields ? args.header.additionalFields : []
|
|
95
95
|
]
|
|
96
96
|
}
|
|
97
97
|
]
|
|
98
98
|
}
|
|
99
99
|
];
|
|
100
|
-
if (
|
|
100
|
+
if (args?.includeFooter) {
|
|
101
101
|
tabs.push({
|
|
102
102
|
label: 'Footer',
|
|
103
103
|
name: 'footer',
|
|
@@ -107,7 +107,6 @@
|
|
|
107
107
|
label: 'Items',
|
|
108
108
|
type: 'array',
|
|
109
109
|
interfaceName: 'NavigationFooterLinks',
|
|
110
|
-
maxRows: 8,
|
|
111
110
|
labels: {
|
|
112
111
|
singular: 'Link',
|
|
113
112
|
plural: 'Links'
|
|
@@ -118,14 +117,14 @@
|
|
|
118
117
|
},
|
|
119
118
|
fields: [
|
|
120
119
|
...navFields,
|
|
121
|
-
...
|
|
122
|
-
...
|
|
120
|
+
...args?.footer?.maxDepth ? generateChildren(0, args.footer.maxDepth, navFields) : [],
|
|
121
|
+
...args?.footer?.additionalFields ? args.footer.additionalFields : []
|
|
123
122
|
]
|
|
124
123
|
}
|
|
125
124
|
]
|
|
126
125
|
});
|
|
127
126
|
}
|
|
128
|
-
|
|
127
|
+
const defaultConfig = {
|
|
129
128
|
slug: 'navigation',
|
|
130
129
|
typescript: {
|
|
131
130
|
interface: 'Navigation'
|
|
@@ -141,11 +140,12 @@
|
|
|
141
140
|
type: 'tabs',
|
|
142
141
|
tabs: [
|
|
143
142
|
...tabs,
|
|
144
|
-
...
|
|
143
|
+
...args?.additionalTabs ? args.additionalTabs : []
|
|
145
144
|
]
|
|
146
145
|
}
|
|
147
146
|
]
|
|
148
147
|
};
|
|
148
|
+
return deepMerge(defaultConfig, args?.overrides || {});
|
|
149
149
|
};
|
|
150
150
|
|
|
151
151
|
//# sourceMappingURL=Navigation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/globals/Navigation.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/globals/Navigation.ts"],"sourcesContent":["import {\n\ttype ArrayField,\n\ttype Field,\n\ttype GlobalConfig,\n\ttype Tab,\n\ttype TabsField,\n\tdeepMerge,\n} from 'payload';\n\n/**\n * Navigation Configuration for the header and footer\n * nav links.\n */\ninterface NavigationConfig {\n\toverrides?: Partial<Omit<GlobalConfig, 'slug' | 'fields'>>;\n\tincludeFooter?: boolean;\n\theader?: NavigationMenuConfig;\n\tfooter?: NavigationMenuConfig;\n\tadditionalTabs?: Tab[];\n}\n\n/**\n * Navigation Menu Configuration defines the config for an\n * individual navigation menu, i.e Header or Footer.\n */\ninterface NavigationMenuConfig {\n\tmaxDepth?: number;\n\tadditionalFields?: Field[];\n}\n\n/**\n * Function to generate children structure recursively.\n *\n * @param depth Current depth\n * @param maxDepth Maximum depth to generate children\n * @param fields Fields to include at each level\n */\nconst generateChildren = (depth: number, maxDepth: number, fields: Field[]): Field[] => {\n\tif (depth >= maxDepth) {\n\t\treturn [];\n\t}\n\n\t// Only generate children if depth is less than maxDepth\n\tif (depth < maxDepth - 1) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: 'children',\n\t\t\t\ttype: 'array',\n\t\t\t\tlabel: `Children Level ${depth + 1}`,\n\t\t\t\tfields: [...fields, ...generateChildren(depth + 1, maxDepth, fields)],\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n\n/**\n * The default navigation field links.\n */\nconst navFields: Field[] = [\n\t{\n\t\ttype: 'row',\n\t\tfields: [\n\t\t\t{\n\t\t\t\tname: 'label',\n\t\t\t\tlabel: 'Label',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t\tadmin: {\n\t\t\t\t\twidth: '50%',\n\t\t\t\t\tdescription: 'Enter the text that will appear as a label for the link.',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'url',\n\t\t\t\tlabel: 'URL',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t\tadmin: {\n\t\t\t\t\twidth: '50%',\n\t\t\t\t\tdescription: 'Enter a URL where the link will direct too.',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tname: 'newTab',\n\t\tlabel: 'Open in a new tab?',\n\t\ttype: 'checkbox',\n\t\tdefaultValue: false,\n\t\tadmin: {\n\t\t\tdescription: 'Check this box if you would like the link to open in a new tab.',\n\t\t},\n\t},\n];\n\n/**\n * Navigation Global Configuration\n * Additional fields will be appended to each navigation item.\n *\n * @constructor\n * @param args\n */\nexport const Navigation = (args?: NavigationConfig): GlobalConfig => {\n\tconst tabs: Tab[] = [\n\t\t{\n\t\t\tlabel: 'Header',\n\t\t\tname: 'header',\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tname: 'items',\n\t\t\t\t\tlabel: 'Items',\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\tinterfaceName: 'NavigationHeaderLinks',\n\t\t\t\t\tlabels: {\n\t\t\t\t\t\tsingular: 'Link',\n\t\t\t\t\t\tplural: 'Links',\n\t\t\t\t\t},\n\t\t\t\t\tadmin: {\n\t\t\t\t\t\tinitCollapsed: true,\n\t\t\t\t\t\tisSortable: true,\n\t\t\t\t\t},\n\t\t\t\t\tfields: [\n\t\t\t\t\t\t...navFields,\n\t\t\t\t\t\t...(args?.header?.maxDepth\n\t\t\t\t\t\t\t? generateChildren(0, args.header.maxDepth, navFields)\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t...(args?.header?.additionalFields ? args.header.additionalFields : []),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t} as ArrayField,\n\t];\n\n\tif (args?.includeFooter) {\n\t\ttabs.push({\n\t\t\tlabel: 'Footer',\n\t\t\tname: 'footer',\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tname: 'items',\n\t\t\t\t\tlabel: 'Items',\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\tinterfaceName: 'NavigationFooterLinks',\n\t\t\t\t\tlabels: {\n\t\t\t\t\t\tsingular: 'Link',\n\t\t\t\t\t\tplural: 'Links',\n\t\t\t\t\t},\n\t\t\t\t\tadmin: {\n\t\t\t\t\t\tinitCollapsed: true,\n\t\t\t\t\t\tisSortable: true,\n\t\t\t\t\t},\n\t\t\t\t\tfields: [\n\t\t\t\t\t\t...navFields,\n\t\t\t\t\t\t...(args?.footer?.maxDepth\n\t\t\t\t\t\t\t? generateChildren(0, args.footer.maxDepth, navFields)\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t...(args?.footer?.additionalFields ? args.footer.additionalFields : []),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t} as ArrayField);\n\t}\n\n\tconst defaultConfig = {\n\t\tslug: 'navigation',\n\t\ttypescript: {\n\t\t\tinterface: 'Navigation',\n\t\t},\n\t\tgraphQL: {\n\t\t\tname: 'Navigation',\n\t\t},\n\t\taccess: {\n\t\t\tread: () => true,\n\t\t},\n\t\tfields: [\n\t\t\t{\n\t\t\t\ttype: 'tabs',\n\t\t\t\ttabs: [...tabs, ...(args?.additionalTabs ? args.additionalTabs : [])],\n\t\t\t} as TabsField,\n\t\t],\n\t};\n\n\treturn deepMerge(defaultConfig, args?.overrides || {});\n};\n"],"names":["deepMerge","generateChildren","depth","maxDepth","fields","name","type","label","navFields","required","admin","width","description","defaultValue","Navigation","args","tabs","interfaceName","labels","singular","plural","initCollapsed","isSortable","header","additionalFields","includeFooter","push","footer","defaultConfig","slug","typescript","interface","graphQL","access","read","additionalTabs","overrides"],"mappings":"AAAA,SAMCA,SAAS,QACH,UAAU;AAuBjB;;;;;;CAMC,GACD,MAAMC,mBAAmB,CAACC,OAAeC,UAAkBC;IAC1D,IAAIF,S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