payload-plugin-newsletter 0.14.3 → 0.15.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/dist/fields.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,156 +17,349 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/exports/fields.ts
21
31
  var fields_exports = {};
22
32
  __export(fields_exports, {
33
+ createBroadcastInlinePreviewField: () => createBroadcastInlinePreviewField,
23
34
  createEmailContentField: () => createEmailContentField,
24
- emailSafeFeatures: () => emailSafeFeatures
35
+ createEmailLexicalEditor: () => createEmailLexicalEditor,
36
+ createEmailSafeBlocks: () => createEmailSafeBlocks,
37
+ createEmailSafeFeatures: () => createEmailSafeFeatures,
38
+ createNewsletterSchedulingFields: () => createNewsletterSchedulingFields,
39
+ emailSafeFeatures: () => emailSafeFeatures,
40
+ validateEmailBlocks: () => validateEmailBlocks
25
41
  });
26
42
  module.exports = __toCommonJS(fields_exports);
27
43
 
28
44
  // src/fields/emailContent.ts
29
45
  var import_richtext_lexical = require("@payloadcms/richtext-lexical");
30
- var emailSafeFeatures = [
31
- // Toolbars
32
- (0, import_richtext_lexical.FixedToolbarFeature)(),
33
- // Fixed toolbar at the top
34
- (0, import_richtext_lexical.InlineToolbarFeature)(),
35
- // Floating toolbar when text is selected
36
- // Basic text formatting
37
- (0, import_richtext_lexical.BoldFeature)(),
38
- (0, import_richtext_lexical.ItalicFeature)(),
39
- (0, import_richtext_lexical.UnderlineFeature)(),
40
- (0, import_richtext_lexical.StrikethroughFeature)(),
41
- // Links with enhanced configuration
42
- (0, import_richtext_lexical.LinkFeature)({
43
- fields: [
44
- {
45
- name: "url",
46
- type: "text",
47
- required: true,
48
- admin: {
49
- description: "Enter the full URL (including https://)"
46
+
47
+ // src/utils/blockValidation.ts
48
+ var EMAIL_INCOMPATIBLE_TYPES = [
49
+ "chart",
50
+ "dataTable",
51
+ "interactive",
52
+ "streamable",
53
+ "video",
54
+ "iframe",
55
+ "form",
56
+ "carousel",
57
+ "tabs",
58
+ "accordion",
59
+ "map"
60
+ ];
61
+ var validateEmailBlocks = (blocks) => {
62
+ blocks.forEach((block) => {
63
+ if (EMAIL_INCOMPATIBLE_TYPES.includes(block.slug)) {
64
+ console.warn(`\u26A0\uFE0F Block "${block.slug}" may not be email-compatible. Consider creating an email-specific version.`);
65
+ }
66
+ const hasComplexFields = block.fields?.some((field) => {
67
+ const complexTypes = ["code", "json", "richText", "blocks", "array"];
68
+ return complexTypes.includes(field.type);
69
+ });
70
+ if (hasComplexFields) {
71
+ console.warn(`\u26A0\uFE0F Block "${block.slug}" contains complex field types that may not render consistently in email clients.`);
72
+ }
73
+ });
74
+ };
75
+ var createEmailSafeBlocks = (customBlocks = []) => {
76
+ validateEmailBlocks(customBlocks);
77
+ const baseBlocks = [
78
+ {
79
+ slug: "button",
80
+ fields: [
81
+ {
82
+ name: "text",
83
+ type: "text",
84
+ label: "Button Text",
85
+ required: true
86
+ },
87
+ {
88
+ name: "url",
89
+ type: "text",
90
+ label: "Button URL",
91
+ required: true,
92
+ admin: {
93
+ description: "Enter the full URL (including https://)"
94
+ }
95
+ },
96
+ {
97
+ name: "style",
98
+ type: "select",
99
+ label: "Button Style",
100
+ defaultValue: "primary",
101
+ options: [
102
+ { label: "Primary", value: "primary" },
103
+ { label: "Secondary", value: "secondary" },
104
+ { label: "Outline", value: "outline" }
105
+ ]
50
106
  }
51
- },
52
- {
53
- name: "newTab",
54
- type: "checkbox",
55
- label: "Open in new tab",
56
- defaultValue: false
107
+ ],
108
+ interfaceName: "EmailButton",
109
+ labels: {
110
+ singular: "Button",
111
+ plural: "Buttons"
57
112
  }
58
- ]
59
- }),
60
- // Lists
61
- (0, import_richtext_lexical.OrderedListFeature)(),
62
- (0, import_richtext_lexical.UnorderedListFeature)(),
63
- // Headings - limited to h1, h2, h3 for email compatibility
64
- (0, import_richtext_lexical.HeadingFeature)({
65
- enabledHeadingSizes: ["h1", "h2", "h3"]
66
- }),
67
- // Basic paragraph and alignment
68
- (0, import_richtext_lexical.ParagraphFeature)(),
69
- (0, import_richtext_lexical.AlignFeature)(),
70
- // Blockquotes
71
- (0, import_richtext_lexical.BlockquoteFeature)(),
72
- // Upload feature for images
73
- (0, import_richtext_lexical.UploadFeature)({
74
- collections: {
75
- media: {
76
- fields: [
77
- {
78
- name: "caption",
79
- type: "text",
80
- admin: {
81
- description: "Optional caption for the image"
82
- }
83
- },
84
- {
85
- name: "altText",
86
- type: "text",
87
- label: "Alt Text",
88
- required: true,
89
- admin: {
90
- description: "Alternative text for accessibility and when image cannot be displayed"
91
- }
113
+ },
114
+ {
115
+ slug: "divider",
116
+ fields: [
117
+ {
118
+ name: "style",
119
+ type: "select",
120
+ label: "Divider Style",
121
+ defaultValue: "solid",
122
+ options: [
123
+ { label: "Solid", value: "solid" },
124
+ { label: "Dashed", value: "dashed" },
125
+ { label: "Dotted", value: "dotted" }
126
+ ]
127
+ }
128
+ ],
129
+ interfaceName: "EmailDivider",
130
+ labels: {
131
+ singular: "Divider",
132
+ plural: "Dividers"
133
+ }
134
+ }
135
+ ];
136
+ return [
137
+ ...baseBlocks,
138
+ ...customBlocks
139
+ ];
140
+ };
141
+
142
+ // src/fields/emailContent.ts
143
+ var createEmailSafeFeatures = (additionalBlocks) => {
144
+ const baseBlocks = [
145
+ {
146
+ slug: "button",
147
+ fields: [
148
+ {
149
+ name: "text",
150
+ type: "text",
151
+ label: "Button Text",
152
+ required: true
153
+ },
154
+ {
155
+ name: "url",
156
+ type: "text",
157
+ label: "Button URL",
158
+ required: true,
159
+ admin: {
160
+ description: "Enter the full URL (including https://)"
92
161
  }
93
- ]
162
+ },
163
+ {
164
+ name: "style",
165
+ type: "select",
166
+ label: "Button Style",
167
+ defaultValue: "primary",
168
+ options: [
169
+ { label: "Primary", value: "primary" },
170
+ { label: "Secondary", value: "secondary" },
171
+ { label: "Outline", value: "outline" }
172
+ ]
173
+ }
174
+ ],
175
+ interfaceName: "EmailButton",
176
+ labels: {
177
+ singular: "Button",
178
+ plural: "Buttons"
179
+ }
180
+ },
181
+ {
182
+ slug: "divider",
183
+ fields: [
184
+ {
185
+ name: "style",
186
+ type: "select",
187
+ label: "Divider Style",
188
+ defaultValue: "solid",
189
+ options: [
190
+ { label: "Solid", value: "solid" },
191
+ { label: "Dashed", value: "dashed" },
192
+ { label: "Dotted", value: "dotted" }
193
+ ]
194
+ }
195
+ ],
196
+ interfaceName: "EmailDivider",
197
+ labels: {
198
+ singular: "Divider",
199
+ plural: "Dividers"
94
200
  }
95
201
  }
96
- }),
97
- // Custom blocks for email-specific content
98
- (0, import_richtext_lexical.BlocksFeature)({
99
- blocks: [
100
- {
101
- slug: "button",
202
+ ];
203
+ const allBlocks = [
204
+ ...baseBlocks,
205
+ ...additionalBlocks || []
206
+ ];
207
+ return [
208
+ // Toolbars
209
+ (0, import_richtext_lexical.FixedToolbarFeature)(),
210
+ // Fixed toolbar at the top
211
+ (0, import_richtext_lexical.InlineToolbarFeature)(),
212
+ // Floating toolbar when text is selected
213
+ // Basic text formatting
214
+ (0, import_richtext_lexical.BoldFeature)(),
215
+ (0, import_richtext_lexical.ItalicFeature)(),
216
+ (0, import_richtext_lexical.UnderlineFeature)(),
217
+ (0, import_richtext_lexical.StrikethroughFeature)(),
218
+ // Links with enhanced configuration
219
+ (0, import_richtext_lexical.LinkFeature)({
220
+ fields: [
221
+ {
222
+ name: "url",
223
+ type: "text",
224
+ required: true,
225
+ admin: {
226
+ description: "Enter the full URL (including https://)"
227
+ }
228
+ },
229
+ {
230
+ name: "newTab",
231
+ type: "checkbox",
232
+ label: "Open in new tab",
233
+ defaultValue: false
234
+ }
235
+ ]
236
+ }),
237
+ // Lists
238
+ (0, import_richtext_lexical.OrderedListFeature)(),
239
+ (0, import_richtext_lexical.UnorderedListFeature)(),
240
+ // Headings - limited to h1, h2, h3 for email compatibility
241
+ (0, import_richtext_lexical.HeadingFeature)({
242
+ enabledHeadingSizes: ["h1", "h2", "h3"]
243
+ }),
244
+ // Basic paragraph and alignment
245
+ (0, import_richtext_lexical.ParagraphFeature)(),
246
+ (0, import_richtext_lexical.AlignFeature)(),
247
+ // Blockquotes
248
+ (0, import_richtext_lexical.BlockquoteFeature)(),
249
+ // Upload feature for images
250
+ (0, import_richtext_lexical.UploadFeature)({
251
+ collections: {
252
+ media: {
253
+ fields: [
254
+ {
255
+ name: "caption",
256
+ type: "text",
257
+ admin: {
258
+ description: "Optional caption for the image"
259
+ }
260
+ },
261
+ {
262
+ name: "altText",
263
+ type: "text",
264
+ label: "Alt Text",
265
+ required: true,
266
+ admin: {
267
+ description: "Alternative text for accessibility and when image cannot be displayed"
268
+ }
269
+ }
270
+ ]
271
+ }
272
+ }
273
+ }),
274
+ // Custom blocks for email-specific content
275
+ (0, import_richtext_lexical.BlocksFeature)({
276
+ blocks: allBlocks
277
+ })
278
+ ];
279
+ };
280
+ var createEmailLexicalEditor = (customBlocks = []) => {
281
+ const emailSafeBlocks = createEmailSafeBlocks(customBlocks);
282
+ return (0, import_richtext_lexical.lexicalEditor)({
283
+ features: [
284
+ // Toolbars
285
+ (0, import_richtext_lexical.FixedToolbarFeature)(),
286
+ (0, import_richtext_lexical.InlineToolbarFeature)(),
287
+ // Basic text formatting
288
+ (0, import_richtext_lexical.BoldFeature)(),
289
+ (0, import_richtext_lexical.ItalicFeature)(),
290
+ (0, import_richtext_lexical.UnderlineFeature)(),
291
+ (0, import_richtext_lexical.StrikethroughFeature)(),
292
+ // Links with enhanced configuration
293
+ (0, import_richtext_lexical.LinkFeature)({
102
294
  fields: [
103
- {
104
- name: "text",
105
- type: "text",
106
- label: "Button Text",
107
- required: true
108
- },
109
295
  {
110
296
  name: "url",
111
297
  type: "text",
112
- label: "Button URL",
113
298
  required: true,
114
299
  admin: {
115
300
  description: "Enter the full URL (including https://)"
116
301
  }
117
302
  },
118
303
  {
119
- name: "style",
120
- type: "select",
121
- label: "Button Style",
122
- defaultValue: "primary",
123
- options: [
124
- { label: "Primary", value: "primary" },
125
- { label: "Secondary", value: "secondary" },
126
- { label: "Outline", value: "outline" }
127
- ]
304
+ name: "newTab",
305
+ type: "checkbox",
306
+ label: "Open in new tab",
307
+ defaultValue: false
128
308
  }
129
- ],
130
- interfaceName: "EmailButton",
131
- labels: {
132
- singular: "Button",
133
- plural: "Buttons"
134
- }
135
- },
136
- {
137
- slug: "divider",
138
- fields: [
139
- {
140
- name: "style",
141
- type: "select",
142
- label: "Divider Style",
143
- defaultValue: "solid",
144
- options: [
145
- { label: "Solid", value: "solid" },
146
- { label: "Dashed", value: "dashed" },
147
- { label: "Dotted", value: "dotted" }
309
+ ]
310
+ }),
311
+ // Lists
312
+ (0, import_richtext_lexical.OrderedListFeature)(),
313
+ (0, import_richtext_lexical.UnorderedListFeature)(),
314
+ // Headings - limited to h1, h2, h3 for email compatibility
315
+ (0, import_richtext_lexical.HeadingFeature)({
316
+ enabledHeadingSizes: ["h1", "h2", "h3"]
317
+ }),
318
+ // Basic paragraph and alignment
319
+ (0, import_richtext_lexical.ParagraphFeature)(),
320
+ (0, import_richtext_lexical.AlignFeature)(),
321
+ // Blockquotes
322
+ (0, import_richtext_lexical.BlockquoteFeature)(),
323
+ // Upload feature for images
324
+ (0, import_richtext_lexical.UploadFeature)({
325
+ collections: {
326
+ media: {
327
+ fields: [
328
+ {
329
+ name: "caption",
330
+ type: "text",
331
+ admin: {
332
+ description: "Optional caption for the image"
333
+ }
334
+ },
335
+ {
336
+ name: "altText",
337
+ type: "text",
338
+ label: "Alt Text",
339
+ required: true,
340
+ admin: {
341
+ description: "Alternative text for accessibility and when image cannot be displayed"
342
+ }
343
+ }
148
344
  ]
149
345
  }
150
- ],
151
- interfaceName: "EmailDivider",
152
- labels: {
153
- singular: "Divider",
154
- plural: "Dividers"
155
346
  }
156
- }
347
+ }),
348
+ // Email-safe blocks (processed server-side)
349
+ (0, import_richtext_lexical.BlocksFeature)({
350
+ blocks: emailSafeBlocks
351
+ })
157
352
  ]
158
- })
159
- ];
353
+ });
354
+ };
355
+ var emailSafeFeatures = createEmailSafeFeatures();
160
356
  var createEmailContentField = (overrides) => {
357
+ const editor = overrides?.editor || createEmailLexicalEditor(overrides?.additionalBlocks);
161
358
  return {
162
359
  name: "content",
163
360
  type: "richText",
164
361
  required: true,
165
- editor: (0, import_richtext_lexical.lexicalEditor)({
166
- features: emailSafeFeatures
167
- }),
362
+ editor,
168
363
  admin: {
169
364
  description: "Email content with limited formatting for compatibility",
170
365
  ...overrides?.admin
@@ -172,9 +367,197 @@ var createEmailContentField = (overrides) => {
172
367
  ...overrides
173
368
  };
174
369
  };
370
+
371
+ // src/fields/broadcastInlinePreview.ts
372
+ var createBroadcastInlinePreviewField = () => {
373
+ return {
374
+ name: "broadcastInlinePreview",
375
+ type: "ui",
376
+ admin: {
377
+ components: {
378
+ Field: "payload-plugin-newsletter/components#BroadcastInlinePreview"
379
+ }
380
+ }
381
+ };
382
+ };
383
+
384
+ // src/fields/newsletterScheduling.ts
385
+ function createNewsletterSchedulingFields(config) {
386
+ const groupName = config.features?.newsletterScheduling?.fields?.groupName || "newsletterScheduling";
387
+ const contentField = config.features?.newsletterScheduling?.fields?.contentField || "content";
388
+ const createMarkdownField = config.features?.newsletterScheduling?.fields?.createMarkdownField !== false;
389
+ const fields = [
390
+ {
391
+ name: groupName,
392
+ type: "group",
393
+ label: "Newsletter Scheduling",
394
+ admin: {
395
+ condition: (data, { user }) => user?.collection === "users"
396
+ // Only show for admin users
397
+ },
398
+ fields: [
399
+ {
400
+ name: "scheduled",
401
+ type: "checkbox",
402
+ label: "Schedule for Newsletter",
403
+ defaultValue: false,
404
+ admin: {
405
+ description: "Schedule this content to be sent as a newsletter"
406
+ }
407
+ },
408
+ {
409
+ name: "scheduledDate",
410
+ type: "date",
411
+ label: "Send Date",
412
+ required: true,
413
+ admin: {
414
+ date: {
415
+ pickerAppearance: "dayAndTime"
416
+ },
417
+ condition: (data) => data?.[groupName]?.scheduled,
418
+ description: "When to send this newsletter"
419
+ }
420
+ },
421
+ {
422
+ name: "sentDate",
423
+ type: "date",
424
+ label: "Sent Date",
425
+ admin: {
426
+ readOnly: true,
427
+ condition: (data) => data?.[groupName]?.sendStatus === "sent",
428
+ description: "When this newsletter was sent"
429
+ }
430
+ },
431
+ {
432
+ name: "sendStatus",
433
+ type: "select",
434
+ label: "Status",
435
+ options: [
436
+ { label: "Draft", value: "draft" },
437
+ { label: "Scheduled", value: "scheduled" },
438
+ { label: "Sending", value: "sending" },
439
+ { label: "Sent", value: "sent" },
440
+ { label: "Failed", value: "failed" }
441
+ ],
442
+ defaultValue: "draft",
443
+ admin: {
444
+ readOnly: true,
445
+ description: "Current send status"
446
+ }
447
+ },
448
+ {
449
+ name: "emailSubject",
450
+ type: "text",
451
+ label: "Email Subject",
452
+ required: true,
453
+ admin: {
454
+ condition: (data) => data?.[groupName]?.scheduled,
455
+ description: "Subject line for the newsletter email"
456
+ }
457
+ },
458
+ {
459
+ name: "preheader",
460
+ type: "text",
461
+ label: "Email Preheader",
462
+ admin: {
463
+ condition: (data) => data?.[groupName]?.scheduled,
464
+ description: "Preview text that appears after the subject line"
465
+ }
466
+ },
467
+ {
468
+ name: "segments",
469
+ type: "select",
470
+ label: "Target Segments",
471
+ hasMany: true,
472
+ options: [
473
+ { label: "All Subscribers", value: "all" },
474
+ ...config.i18n?.locales?.map((locale) => ({
475
+ label: `${locale.toUpperCase()} Subscribers`,
476
+ value: locale
477
+ })) || []
478
+ ],
479
+ defaultValue: ["all"],
480
+ admin: {
481
+ condition: (data) => data?.[groupName]?.scheduled,
482
+ description: "Which subscriber segments to send to"
483
+ }
484
+ },
485
+ {
486
+ name: "testEmails",
487
+ type: "array",
488
+ label: "Test Email Recipients",
489
+ admin: {
490
+ condition: (data) => data?.[groupName]?.scheduled && data?.[groupName]?.sendStatus === "draft",
491
+ description: "Send test emails before scheduling"
492
+ },
493
+ fields: [
494
+ {
495
+ name: "email",
496
+ type: "email",
497
+ required: true
498
+ }
499
+ ]
500
+ }
501
+ ]
502
+ }
503
+ ];
504
+ if (createMarkdownField) {
505
+ fields.push(createMarkdownFieldInternal({
506
+ name: `${contentField}Markdown`,
507
+ richTextField: contentField,
508
+ label: "Email Content (Markdown)",
509
+ admin: {
510
+ position: "sidebar",
511
+ condition: (data) => Boolean(data?.[contentField] && data?.[groupName]?.scheduled),
512
+ description: "Markdown version for email rendering",
513
+ readOnly: true
514
+ }
515
+ }));
516
+ }
517
+ return fields;
518
+ }
519
+ function createMarkdownFieldInternal(config) {
520
+ return {
521
+ name: config.name,
522
+ type: "textarea",
523
+ label: config.label || "Markdown",
524
+ admin: {
525
+ ...config.admin,
526
+ description: config.admin?.description || "Auto-generated from rich text content"
527
+ },
528
+ hooks: {
529
+ afterRead: [
530
+ async ({ data }) => {
531
+ if (data?.[config.richTextField]) {
532
+ try {
533
+ const { convertLexicalToMarkdown } = await import("@payloadcms/richtext-lexical");
534
+ return convertLexicalToMarkdown({
535
+ data: data[config.richTextField]
536
+ });
537
+ } catch {
538
+ return "";
539
+ }
540
+ }
541
+ return "";
542
+ }
543
+ ],
544
+ beforeChange: [
545
+ () => {
546
+ return null;
547
+ }
548
+ ]
549
+ }
550
+ };
551
+ }
175
552
  // Annotate the CommonJS export names for ESM import in node:
176
553
  0 && (module.exports = {
554
+ createBroadcastInlinePreviewField,
177
555
  createEmailContentField,
178
- emailSafeFeatures
556
+ createEmailLexicalEditor,
557
+ createEmailSafeBlocks,
558
+ createEmailSafeFeatures,
559
+ createNewsletterSchedulingFields,
560
+ emailSafeFeatures,
561
+ validateEmailBlocks
179
562
  });
180
563
  //# sourceMappingURL=fields.cjs.map