@delmaredigital/payload-puck 0.1.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/LICENSE +73 -0
- package/README.md +1580 -0
- package/dist/AccordionClient.d.mts +24 -0
- package/dist/AccordionClient.d.ts +24 -0
- package/dist/AccordionClient.js +786 -0
- package/dist/AccordionClient.js.map +1 -0
- package/dist/AccordionClient.mjs +784 -0
- package/dist/AccordionClient.mjs.map +1 -0
- package/dist/AnimatedWrapper.d.mts +30 -0
- package/dist/AnimatedWrapper.d.ts +30 -0
- package/dist/AnimatedWrapper.js +379 -0
- package/dist/AnimatedWrapper.js.map +1 -0
- package/dist/AnimatedWrapper.mjs +377 -0
- package/dist/AnimatedWrapper.mjs.map +1 -0
- package/dist/admin/client.d.mts +108 -0
- package/dist/admin/client.d.ts +108 -0
- package/dist/admin/client.js +177 -0
- package/dist/admin/client.js.map +1 -0
- package/dist/admin/client.mjs +173 -0
- package/dist/admin/client.mjs.map +1 -0
- package/dist/admin/index.d.mts +157 -0
- package/dist/admin/index.d.ts +157 -0
- package/dist/admin/index.js +31 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/index.mjs +29 -0
- package/dist/admin/index.mjs.map +1 -0
- package/dist/api/index.d.mts +460 -0
- package/dist/api/index.d.ts +460 -0
- package/dist/api/index.js +588 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/index.mjs +578 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/components/index.css +339 -0
- package/dist/components/index.css.map +1 -0
- package/dist/components/index.d.mts +222 -0
- package/dist/components/index.d.ts +222 -0
- package/dist/components/index.js +9177 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +9130 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/config/config.editor.css +339 -0
- package/dist/config/config.editor.css.map +1 -0
- package/dist/config/config.editor.d.mts +153 -0
- package/dist/config/config.editor.d.ts +153 -0
- package/dist/config/config.editor.js +9400 -0
- package/dist/config/config.editor.js.map +1 -0
- package/dist/config/config.editor.mjs +9368 -0
- package/dist/config/config.editor.mjs.map +1 -0
- package/dist/config/index.d.mts +68 -0
- package/dist/config/index.d.ts +68 -0
- package/dist/config/index.js +2017 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.mjs +1991 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/editor/index.d.mts +784 -0
- package/dist/editor/index.d.ts +784 -0
- package/dist/editor/index.js +4517 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/index.mjs +4483 -0
- package/dist/editor/index.mjs.map +1 -0
- package/dist/fields/index.css +339 -0
- package/dist/fields/index.css.map +1 -0
- package/dist/fields/index.d.mts +600 -0
- package/dist/fields/index.d.ts +600 -0
- package/dist/fields/index.js +7739 -0
- package/dist/fields/index.js.map +1 -0
- package/dist/fields/index.mjs +7590 -0
- package/dist/fields/index.mjs.map +1 -0
- package/dist/index-CQu6SzDg.d.mts +327 -0
- package/dist/index-CoUQnyC3.d.ts +327 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +569 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +555 -0
- package/dist/index.mjs.map +1 -0
- package/dist/layouts/index.d.mts +96 -0
- package/dist/layouts/index.d.ts +96 -0
- package/dist/layouts/index.js +394 -0
- package/dist/layouts/index.js.map +1 -0
- package/dist/layouts/index.mjs +378 -0
- package/dist/layouts/index.mjs.map +1 -0
- package/dist/plugin/index.d.mts +289 -0
- package/dist/plugin/index.d.ts +289 -0
- package/dist/plugin/index.js +569 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/index.mjs +555 -0
- package/dist/plugin/index.mjs.map +1 -0
- package/dist/render/index.d.mts +109 -0
- package/dist/render/index.d.ts +109 -0
- package/dist/render/index.js +2146 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/index.mjs +2123 -0
- package/dist/render/index.mjs.map +1 -0
- package/dist/shared-DMAF1AcH.d.mts +545 -0
- package/dist/shared-DMAF1AcH.d.ts +545 -0
- package/dist/theme/index.d.mts +155 -0
- package/dist/theme/index.d.ts +155 -0
- package/dist/theme/index.js +201 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/index.mjs +186 -0
- package/dist/theme/index.mjs.map +1 -0
- package/dist/types-D7D3rZ1J.d.mts +116 -0
- package/dist/types-D7D3rZ1J.d.ts +116 -0
- package/dist/types-_6MvjyKv.d.mts +104 -0
- package/dist/types-_6MvjyKv.d.ts +104 -0
- package/dist/utils/index.d.mts +267 -0
- package/dist/utils/index.d.ts +267 -0
- package/dist/utils/index.js +426 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +412 -0
- package/dist/utils/index.mjs.map +1 -0
- package/dist/utils-DaRs9t0J.d.mts +85 -0
- package/dist/utils-gAvt0Vhw.d.ts +85 -0
- package/examples/README.md +240 -0
- package/examples/api/puck/pages/[id]/route.ts +64 -0
- package/examples/api/puck/pages/[id]/versions/route.ts +47 -0
- package/examples/api/puck/pages/route.ts +45 -0
- package/examples/app/(frontend)/page.tsx +94 -0
- package/examples/app/[...slug]/page.tsx +101 -0
- package/examples/app/pages/[id]/edit/page.tsx +148 -0
- package/examples/components/CustomBanner.tsx +368 -0
- package/examples/config/custom-config.ts +223 -0
- package/examples/config/payload.config.example.ts +64 -0
- package/examples/lib/puck-layouts.ts +258 -0
- package/examples/lib/puck-theme.ts +94 -0
- package/examples/styles/puck-theme.css +171 -0
- package/package.json +157 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Config, Plugin, Data } from '@measured/puck';
|
|
2
|
+
import { Field } from 'payload';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Props for the PuckEditorView component
|
|
6
|
+
*/
|
|
7
|
+
interface PuckEditorViewProps {
|
|
8
|
+
/**
|
|
9
|
+
* Puck configuration with components and settings
|
|
10
|
+
*/
|
|
11
|
+
config: Config;
|
|
12
|
+
/**
|
|
13
|
+
* Collection slug for API endpoints
|
|
14
|
+
* @default 'pages'
|
|
15
|
+
*/
|
|
16
|
+
collectionSlug?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Base API path for Puck operations
|
|
19
|
+
* @default '/api/puck'
|
|
20
|
+
*/
|
|
21
|
+
apiBasePath?: string;
|
|
22
|
+
/**
|
|
23
|
+
* URL to navigate to when back button is clicked
|
|
24
|
+
* Falls back to /admin/collections/{collectionSlug}
|
|
25
|
+
*/
|
|
26
|
+
backUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Preview URL or function to generate preview URL from slug
|
|
29
|
+
*/
|
|
30
|
+
previewUrl?: string | ((slug: string) => string);
|
|
31
|
+
/**
|
|
32
|
+
* Layout styles for theme-aware preview
|
|
33
|
+
*/
|
|
34
|
+
layoutStyles?: Record<string, {
|
|
35
|
+
background: string;
|
|
36
|
+
isDark: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Key in root.props to read layout value from
|
|
40
|
+
* @default 'pageLayout'
|
|
41
|
+
*/
|
|
42
|
+
layoutKey?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Additional Puck plugins to use.
|
|
45
|
+
* The headingAnalyzer plugin is included by default.
|
|
46
|
+
* Set to `false` to disable all default plugins.
|
|
47
|
+
*/
|
|
48
|
+
plugins?: Plugin[] | false;
|
|
49
|
+
/**
|
|
50
|
+
* Callback on successful save
|
|
51
|
+
*/
|
|
52
|
+
onSaveSuccess?: (data: Data) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Callback on save error
|
|
55
|
+
*/
|
|
56
|
+
onSaveError?: (error: Error) => void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Props for EditWithPuckButton when used standalone
|
|
61
|
+
*/
|
|
62
|
+
interface EditWithPuckButtonProps {
|
|
63
|
+
/**
|
|
64
|
+
* Document ID to edit
|
|
65
|
+
*/
|
|
66
|
+
id?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Collection slug
|
|
69
|
+
* @default 'pages'
|
|
70
|
+
*/
|
|
71
|
+
collectionSlug?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Custom path pattern for the Puck editor
|
|
74
|
+
* Use {id} as placeholder for the document ID
|
|
75
|
+
* @default '/pages/{id}/edit'
|
|
76
|
+
*/
|
|
77
|
+
editorPathPattern?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Button label
|
|
80
|
+
* @default 'Edit with Puck'
|
|
81
|
+
*/
|
|
82
|
+
label?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to show as icon only
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
iconOnly?: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Props for configuring the EditWithPuckCell component
|
|
92
|
+
*/
|
|
93
|
+
interface EditWithPuckCellConfig {
|
|
94
|
+
/**
|
|
95
|
+
* Collection slug for building the editor URL
|
|
96
|
+
* @default 'pages'
|
|
97
|
+
*/
|
|
98
|
+
collectionSlug?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Custom editor path pattern
|
|
101
|
+
* Use {id} as placeholder for the document ID
|
|
102
|
+
* @default '/admin/puck/{collectionSlug}/{id}/edit'
|
|
103
|
+
*/
|
|
104
|
+
editorPathPattern?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Configuration for generating the edit button field
|
|
109
|
+
*/
|
|
110
|
+
interface AdminComponentsConfig {
|
|
111
|
+
/**
|
|
112
|
+
* Collection slug for the pages collection
|
|
113
|
+
* @default 'pages'
|
|
114
|
+
*/
|
|
115
|
+
collectionSlug?: string;
|
|
116
|
+
/**
|
|
117
|
+
* URL pattern for the Puck editor page
|
|
118
|
+
* Use {id} as placeholder for document ID
|
|
119
|
+
* @default '/pages/{id}/edit'
|
|
120
|
+
*/
|
|
121
|
+
editorPathPattern?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Button label text
|
|
124
|
+
* @default 'Edit with Puck'
|
|
125
|
+
*/
|
|
126
|
+
buttonLabel?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Position of the edit button in admin
|
|
129
|
+
* @default 'sidebar'
|
|
130
|
+
*/
|
|
131
|
+
buttonPosition?: 'sidebar' | 'main';
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Generates the UI field configuration for the Edit with Puck button
|
|
135
|
+
*
|
|
136
|
+
* Use this if you want to manually add the edit button field to your
|
|
137
|
+
* collection instead of using the plugin's auto-generation.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* import { generatePuckEditField } from '@delmaredigital/payload-puck/admin'
|
|
142
|
+
*
|
|
143
|
+
* const Pages: CollectionConfig = {
|
|
144
|
+
* slug: 'pages',
|
|
145
|
+
* fields: [
|
|
146
|
+
* // ... other fields
|
|
147
|
+
* generatePuckEditField({
|
|
148
|
+
* editorPathPattern: '/pages/{id}/edit',
|
|
149
|
+
* buttonLabel: 'Visual Editor',
|
|
150
|
+
* }),
|
|
151
|
+
* ],
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
declare function generatePuckEditField(config?: AdminComponentsConfig): Field;
|
|
156
|
+
|
|
157
|
+
export { type AdminComponentsConfig, type EditWithPuckButtonProps, type EditWithPuckCellConfig, type PuckEditorViewProps, generatePuckEditField };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Config, Plugin, Data } from '@measured/puck';
|
|
2
|
+
import { Field } from 'payload';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Props for the PuckEditorView component
|
|
6
|
+
*/
|
|
7
|
+
interface PuckEditorViewProps {
|
|
8
|
+
/**
|
|
9
|
+
* Puck configuration with components and settings
|
|
10
|
+
*/
|
|
11
|
+
config: Config;
|
|
12
|
+
/**
|
|
13
|
+
* Collection slug for API endpoints
|
|
14
|
+
* @default 'pages'
|
|
15
|
+
*/
|
|
16
|
+
collectionSlug?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Base API path for Puck operations
|
|
19
|
+
* @default '/api/puck'
|
|
20
|
+
*/
|
|
21
|
+
apiBasePath?: string;
|
|
22
|
+
/**
|
|
23
|
+
* URL to navigate to when back button is clicked
|
|
24
|
+
* Falls back to /admin/collections/{collectionSlug}
|
|
25
|
+
*/
|
|
26
|
+
backUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Preview URL or function to generate preview URL from slug
|
|
29
|
+
*/
|
|
30
|
+
previewUrl?: string | ((slug: string) => string);
|
|
31
|
+
/**
|
|
32
|
+
* Layout styles for theme-aware preview
|
|
33
|
+
*/
|
|
34
|
+
layoutStyles?: Record<string, {
|
|
35
|
+
background: string;
|
|
36
|
+
isDark: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Key in root.props to read layout value from
|
|
40
|
+
* @default 'pageLayout'
|
|
41
|
+
*/
|
|
42
|
+
layoutKey?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Additional Puck plugins to use.
|
|
45
|
+
* The headingAnalyzer plugin is included by default.
|
|
46
|
+
* Set to `false` to disable all default plugins.
|
|
47
|
+
*/
|
|
48
|
+
plugins?: Plugin[] | false;
|
|
49
|
+
/**
|
|
50
|
+
* Callback on successful save
|
|
51
|
+
*/
|
|
52
|
+
onSaveSuccess?: (data: Data) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Callback on save error
|
|
55
|
+
*/
|
|
56
|
+
onSaveError?: (error: Error) => void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Props for EditWithPuckButton when used standalone
|
|
61
|
+
*/
|
|
62
|
+
interface EditWithPuckButtonProps {
|
|
63
|
+
/**
|
|
64
|
+
* Document ID to edit
|
|
65
|
+
*/
|
|
66
|
+
id?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Collection slug
|
|
69
|
+
* @default 'pages'
|
|
70
|
+
*/
|
|
71
|
+
collectionSlug?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Custom path pattern for the Puck editor
|
|
74
|
+
* Use {id} as placeholder for the document ID
|
|
75
|
+
* @default '/pages/{id}/edit'
|
|
76
|
+
*/
|
|
77
|
+
editorPathPattern?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Button label
|
|
80
|
+
* @default 'Edit with Puck'
|
|
81
|
+
*/
|
|
82
|
+
label?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to show as icon only
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
87
|
+
iconOnly?: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Props for configuring the EditWithPuckCell component
|
|
92
|
+
*/
|
|
93
|
+
interface EditWithPuckCellConfig {
|
|
94
|
+
/**
|
|
95
|
+
* Collection slug for building the editor URL
|
|
96
|
+
* @default 'pages'
|
|
97
|
+
*/
|
|
98
|
+
collectionSlug?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Custom editor path pattern
|
|
101
|
+
* Use {id} as placeholder for the document ID
|
|
102
|
+
* @default '/admin/puck/{collectionSlug}/{id}/edit'
|
|
103
|
+
*/
|
|
104
|
+
editorPathPattern?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Configuration for generating the edit button field
|
|
109
|
+
*/
|
|
110
|
+
interface AdminComponentsConfig {
|
|
111
|
+
/**
|
|
112
|
+
* Collection slug for the pages collection
|
|
113
|
+
* @default 'pages'
|
|
114
|
+
*/
|
|
115
|
+
collectionSlug?: string;
|
|
116
|
+
/**
|
|
117
|
+
* URL pattern for the Puck editor page
|
|
118
|
+
* Use {id} as placeholder for document ID
|
|
119
|
+
* @default '/pages/{id}/edit'
|
|
120
|
+
*/
|
|
121
|
+
editorPathPattern?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Button label text
|
|
124
|
+
* @default 'Edit with Puck'
|
|
125
|
+
*/
|
|
126
|
+
buttonLabel?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Position of the edit button in admin
|
|
129
|
+
* @default 'sidebar'
|
|
130
|
+
*/
|
|
131
|
+
buttonPosition?: 'sidebar' | 'main';
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Generates the UI field configuration for the Edit with Puck button
|
|
135
|
+
*
|
|
136
|
+
* Use this if you want to manually add the edit button field to your
|
|
137
|
+
* collection instead of using the plugin's auto-generation.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* import { generatePuckEditField } from '@delmaredigital/payload-puck/admin'
|
|
142
|
+
*
|
|
143
|
+
* const Pages: CollectionConfig = {
|
|
144
|
+
* slug: 'pages',
|
|
145
|
+
* fields: [
|
|
146
|
+
* // ... other fields
|
|
147
|
+
* generatePuckEditField({
|
|
148
|
+
* editorPathPattern: '/pages/{id}/edit',
|
|
149
|
+
* buttonLabel: 'Visual Editor',
|
|
150
|
+
* }),
|
|
151
|
+
* ],
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
declare function generatePuckEditField(config?: AdminComponentsConfig): Field;
|
|
156
|
+
|
|
157
|
+
export { type AdminComponentsConfig, type EditWithPuckButtonProps, type EditWithPuckCellConfig, type PuckEditorViewProps, generatePuckEditField };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/admin/generateAdminComponents.ts
|
|
4
|
+
function generatePuckEditField(config = {}) {
|
|
5
|
+
const {
|
|
6
|
+
collectionSlug = "pages",
|
|
7
|
+
editorPathPattern = "/pages/{id}/edit",
|
|
8
|
+
buttonLabel = "Edit with Puck",
|
|
9
|
+
buttonPosition = "sidebar"
|
|
10
|
+
} = config;
|
|
11
|
+
return {
|
|
12
|
+
name: "puckEdit",
|
|
13
|
+
type: "ui",
|
|
14
|
+
admin: {
|
|
15
|
+
position: buttonPosition,
|
|
16
|
+
components: {
|
|
17
|
+
Field: "@delmaredigital/payload-puck/admin/client#EditWithPuckButton",
|
|
18
|
+
Cell: "@delmaredigital/payload-puck/admin/client#EditWithPuckCell"
|
|
19
|
+
},
|
|
20
|
+
custom: {
|
|
21
|
+
collectionSlug,
|
|
22
|
+
editorPathPattern,
|
|
23
|
+
label: buttonLabel
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.generatePuckEditField = generatePuckEditField;
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/generateAdminComponents.ts"],"names":[],"mappings":";;;AAmDO,SAAS,qBAAA,CAAsB,MAAA,GAAgC,EAAC,EAAU;AAC/E,EAAA,MAAM;AAAA,IACJ,cAAA,GAAiB,OAAA;AAAA,IACjB,iBAAA,GAAoB,kBAAA;AAAA,IACpB,WAAA,GAAc,gBAAA;AAAA,IACd,cAAA,GAAiB;AAAA,GACnB,GAAI,MAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,IAAA,EAAM,IAAA;AAAA,IACN,KAAA,EAAO;AAAA,MACL,QAAA,EAAU,cAAA;AAAA,MACV,UAAA,EAAY;AAAA,QACV,KAAA,EAAO,8DAAA;AAAA,QACP,IAAA,EAAM;AAAA,OACR;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,cAAA;AAAA,QACA,iBAAA;AAAA,QACA,KAAA,EAAO;AAAA;AACT;AACF,GACF;AACF","file":"index.js","sourcesContent":["import type { Field } from 'payload'\n\n/**\n * Configuration for generating the edit button field\n */\nexport interface AdminComponentsConfig {\n /**\n * Collection slug for the pages collection\n * @default 'pages'\n */\n collectionSlug?: string\n /**\n * URL pattern for the Puck editor page\n * Use {id} as placeholder for document ID\n * @default '/pages/{id}/edit'\n */\n editorPathPattern?: string\n /**\n * Button label text\n * @default 'Edit with Puck'\n */\n buttonLabel?: string\n /**\n * Position of the edit button in admin\n * @default 'sidebar'\n */\n buttonPosition?: 'sidebar' | 'main'\n}\n\n/**\n * Generates the UI field configuration for the Edit with Puck button\n *\n * Use this if you want to manually add the edit button field to your\n * collection instead of using the plugin's auto-generation.\n *\n * @example\n * ```ts\n * import { generatePuckEditField } from '@delmaredigital/payload-puck/admin'\n *\n * const Pages: CollectionConfig = {\n * slug: 'pages',\n * fields: [\n * // ... other fields\n * generatePuckEditField({\n * editorPathPattern: '/pages/{id}/edit',\n * buttonLabel: 'Visual Editor',\n * }),\n * ],\n * }\n * ```\n */\nexport function generatePuckEditField(config: AdminComponentsConfig = {}): Field {\n const {\n collectionSlug = 'pages',\n editorPathPattern = '/pages/{id}/edit',\n buttonLabel = 'Edit with Puck',\n buttonPosition = 'sidebar',\n } = config\n\n return {\n name: 'puckEdit',\n type: 'ui',\n admin: {\n position: buttonPosition,\n components: {\n Field: '@delmaredigital/payload-puck/admin/client#EditWithPuckButton',\n Cell: '@delmaredigital/payload-puck/admin/client#EditWithPuckCell',\n },\n custom: {\n collectionSlug,\n editorPathPattern,\n label: buttonLabel,\n },\n },\n }\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/admin/generateAdminComponents.ts
|
|
2
|
+
function generatePuckEditField(config = {}) {
|
|
3
|
+
const {
|
|
4
|
+
collectionSlug = "pages",
|
|
5
|
+
editorPathPattern = "/pages/{id}/edit",
|
|
6
|
+
buttonLabel = "Edit with Puck",
|
|
7
|
+
buttonPosition = "sidebar"
|
|
8
|
+
} = config;
|
|
9
|
+
return {
|
|
10
|
+
name: "puckEdit",
|
|
11
|
+
type: "ui",
|
|
12
|
+
admin: {
|
|
13
|
+
position: buttonPosition,
|
|
14
|
+
components: {
|
|
15
|
+
Field: "@delmaredigital/payload-puck/admin/client#EditWithPuckButton",
|
|
16
|
+
Cell: "@delmaredigital/payload-puck/admin/client#EditWithPuckCell"
|
|
17
|
+
},
|
|
18
|
+
custom: {
|
|
19
|
+
collectionSlug,
|
|
20
|
+
editorPathPattern,
|
|
21
|
+
label: buttonLabel
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { generatePuckEditField };
|
|
28
|
+
//# sourceMappingURL=index.mjs.map
|
|
29
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/generateAdminComponents.ts"],"names":[],"mappings":";AAmDO,SAAS,qBAAA,CAAsB,MAAA,GAAgC,EAAC,EAAU;AAC/E,EAAA,MAAM;AAAA,IACJ,cAAA,GAAiB,OAAA;AAAA,IACjB,iBAAA,GAAoB,kBAAA;AAAA,IACpB,WAAA,GAAc,gBAAA;AAAA,IACd,cAAA,GAAiB;AAAA,GACnB,GAAI,MAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,IAAA,EAAM,IAAA;AAAA,IACN,KAAA,EAAO;AAAA,MACL,QAAA,EAAU,cAAA;AAAA,MACV,UAAA,EAAY;AAAA,QACV,KAAA,EAAO,8DAAA;AAAA,QACP,IAAA,EAAM;AAAA,OACR;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,cAAA;AAAA,QACA,iBAAA;AAAA,QACA,KAAA,EAAO;AAAA;AACT;AACF,GACF;AACF","file":"index.mjs","sourcesContent":["import type { Field } from 'payload'\n\n/**\n * Configuration for generating the edit button field\n */\nexport interface AdminComponentsConfig {\n /**\n * Collection slug for the pages collection\n * @default 'pages'\n */\n collectionSlug?: string\n /**\n * URL pattern for the Puck editor page\n * Use {id} as placeholder for document ID\n * @default '/pages/{id}/edit'\n */\n editorPathPattern?: string\n /**\n * Button label text\n * @default 'Edit with Puck'\n */\n buttonLabel?: string\n /**\n * Position of the edit button in admin\n * @default 'sidebar'\n */\n buttonPosition?: 'sidebar' | 'main'\n}\n\n/**\n * Generates the UI field configuration for the Edit with Puck button\n *\n * Use this if you want to manually add the edit button field to your\n * collection instead of using the plugin's auto-generation.\n *\n * @example\n * ```ts\n * import { generatePuckEditField } from '@delmaredigital/payload-puck/admin'\n *\n * const Pages: CollectionConfig = {\n * slug: 'pages',\n * fields: [\n * // ... other fields\n * generatePuckEditField({\n * editorPathPattern: '/pages/{id}/edit',\n * buttonLabel: 'Visual Editor',\n * }),\n * ],\n * }\n * ```\n */\nexport function generatePuckEditField(config: AdminComponentsConfig = {}): Field {\n const {\n collectionSlug = 'pages',\n editorPathPattern = '/pages/{id}/edit',\n buttonLabel = 'Edit with Puck',\n buttonPosition = 'sidebar',\n } = config\n\n return {\n name: 'puckEdit',\n type: 'ui',\n admin: {\n position: buttonPosition,\n components: {\n Field: '@delmaredigital/payload-puck/admin/client#EditWithPuckButton',\n Cell: '@delmaredigital/payload-puck/admin/client#EditWithPuckCell',\n },\n custom: {\n collectionSlug,\n editorPathPattern,\n label: buttonLabel,\n },\n },\n }\n}\n"]}
|