@payloadcms/plugin-form-builder 3.0.0-beta.9 → 3.0.0-canary.92e4997

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 +1 @@
1
- {"version":3,"sources":["../../../../src/collections/FormSubmissions/hooks/createCharge.ts"],"sourcesContent":["import type { PluginConfig } from '../../../types.js'\n\nexport const createCharge = async (\n beforeChangeData: any,\n formConfig: PluginConfig,\n): Promise<any> => {\n const { data, operation } = beforeChangeData\n\n let dataWithPaymentDetails = data\n\n if (operation === 'create') {\n const { handlePayment } = formConfig || {}\n\n if (typeof handlePayment === 'function') {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n dataWithPaymentDetails = await handlePayment(beforeChangeData)\n }\n }\n\n return dataWithPaymentDetails\n}\n"],"names":["createCharge","beforeChangeData","formConfig","data","operation","dataWithPaymentDetails","handlePayment"],"rangeMappings":";;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,eAAe,OAC1BC,kBACAC;IAEA,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGH;IAE5B,IAAII,yBAAyBF;IAE7B,IAAIC,cAAc,UAAU;QAC1B,MAAM,EAAEE,aAAa,EAAE,GAAGJ,cAAc,CAAC;QAEzC,IAAI,OAAOI,kBAAkB,YAAY;YACvC,6DAA6D;YAC7DD,yBAAyB,MAAMC,cAAcL;QAC/C;IACF;IAEA,OAAOI;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/collections/FormSubmissions/hooks/createCharge.ts"],"sourcesContent":["import type { FormBuilderPluginConfig } from '../../../types.js'\n\nexport const createCharge = async (\n beforeChangeData: any,\n formConfig: FormBuilderPluginConfig,\n): Promise<any> => {\n const { data, operation } = beforeChangeData\n\n let dataWithPaymentDetails = data\n\n if (operation === 'create') {\n const { handlePayment } = formConfig || {}\n\n if (typeof handlePayment === 'function') {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n dataWithPaymentDetails = await handlePayment(beforeChangeData)\n }\n }\n\n return dataWithPaymentDetails\n}\n"],"names":["createCharge","beforeChangeData","formConfig","data","operation","dataWithPaymentDetails","handlePayment"],"rangeMappings":";;;;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,eAAe,OAC1BC,kBACAC;IAEA,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGH;IAE5B,IAAII,yBAAyBF;IAE7B,IAAIC,cAAc,UAAU;QAC1B,MAAM,EAAEE,aAAa,EAAE,GAAGJ,cAAc,CAAC;QAEzC,IAAI,OAAOI,kBAAkB,YAAY;YACvC,6DAA6D;YAC7DD,yBAAyB,MAAMC,cAAcL;QAC/C;IACF;IAEA,OAAOI;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/collections/FormSubmissions/hooks/sendEmail.ts"],"sourcesContent":["import type { Email, FormattedEmail, PluginConfig } from '../../../types.js'\n\nimport { serializeLexical } from '../../../utilities/lexical/serializeLexical.js'\nimport { replaceDoubleCurlys } from '../../../utilities/replaceDoubleCurlys.js'\nimport { serializeSlate } from '../../../utilities/slate/serializeSlate.js'\n\nexport const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig): Promise<any> => {\n const { data, operation, req } = beforeChangeData\n\n if (operation === 'create') {\n const {\n data: { id: formSubmissionID },\n req: { locale, payload },\n } = beforeChangeData\n\n const { form: formID, submissionData } = data || {}\n\n const { beforeEmail, formOverrides } = formConfig || {}\n\n try {\n const form = await payload.findByID({\n id: formID,\n collection: formOverrides?.slug || 'forms',\n locale,\n req,\n })\n\n const { emails } = form\n\n if (emails && emails.length) {\n const formattedEmails: FormattedEmail[] = await Promise.all(\n emails.map(async (email: Email): Promise<FormattedEmail | null> => {\n const {\n bcc: emailBCC,\n cc: emailCC,\n emailFrom,\n emailTo,\n message,\n replyTo: emailReplyTo,\n subject,\n } = email\n\n const to = replaceDoubleCurlys(emailTo, submissionData)\n const cc = emailCC ? replaceDoubleCurlys(emailCC, submissionData) : ''\n const bcc = emailBCC ? replaceDoubleCurlys(emailBCC, submissionData) : ''\n const from = replaceDoubleCurlys(emailFrom, submissionData)\n const replyTo = replaceDoubleCurlys(emailReplyTo || emailFrom, submissionData)\n\n const isLexical = message && !Array.isArray(message) && 'root' in message\n\n const serializedMessage = isLexical\n ? await serializeLexical(message, submissionData)\n : serializeSlate(message, submissionData)\n\n return {\n bcc,\n cc,\n from,\n html: `<div>${serializedMessage}</div>`,\n replyTo,\n subject: replaceDoubleCurlys(subject, submissionData),\n to,\n }\n }),\n )\n\n let emailsToSend = formattedEmails\n\n if (typeof beforeEmail === 'function') {\n emailsToSend = await beforeEmail(formattedEmails)\n }\n\n // const log = emailsToSend.map(({ html, ...rest }) => ({ ...rest }))\n\n await Promise.all(\n emailsToSend.map(async (email) => {\n const { to } = email\n try {\n const emailPromise = await payload.sendEmail(email)\n return emailPromise\n } catch (err: unknown) {\n payload.logger.error({\n err: `Error while sending email to address: ${to}. Email not sent: ${JSON.stringify(\n err,\n )}`,\n })\n }\n }),\n )\n } else {\n payload.logger.info({ msg: 'No emails to send.' })\n }\n } catch (err: unknown) {\n const msg = `Error while sending one or more emails in form submission id: ${formSubmissionID}.`\n payload.logger.error({ err: msg })\n }\n }\n\n return data\n}\n"],"names":["serializeLexical","replaceDoubleCurlys","serializeSlate","sendEmail","beforeChangeData","formConfig","data","operation","req","id","formSubmissionID","locale","payload","form","formID","submissionData","beforeEmail","formOverrides","findByID","collection","slug","emails","length","formattedEmails","Promise","all","map","email","bcc","emailBCC","cc","emailCC","emailFrom","emailTo","message","replyTo","emailReplyTo","subject","to","from","isLexical","Array","isArray","serializedMessage","html","emailsToSend","emailPromise","err","logger","error","JSON","stringify","info","msg"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,gBAAgB,QAAQ,iDAAgD;AACjF,SAASC,mBAAmB,QAAQ,4CAA2C;AAC/E,SAASC,cAAc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OAAO;wBACLa;wBACAE;wBACAS;wBACAK,MAAM,CAAC,KAAK,EAAED,kBAAkB,MAAM,CAAC;wBACvCR;wBACAE,SAASpC,oBAAoBoC,SAAStB;wBACtCuB;oBACF;gBACF;gBAGF,IAAIO,eAAetB;gBAEnB,IAAI,OAAOP,gBAAgB,YAAY;oBACrC6B,eAAe,MAAM7B,YAAYO;gBACnC;gBAEA,qEAAqE;gBAErE,MAAMC,QAAQC,GAAG,CACfoB,aAAanB,GAAG,CAAC,OAAOC;oBACtB,MAAM,EAAEW,EAAE,EAAE,GAAGX;oBACf,IAAI;wBACF,MAAMmB,eAAe,MAAMlC,QAAQT,SAAS,CAACwB;wBAC7C,OAAOmB;oBACT,EAAE,OAAOC,KAAc;wBACrBnC,QAAQoC,MAAM,CAACC,KAAK,CAAC;4BACnBF,KAAK,CAAC,sCAAsC,EAAET,GAAG,kBAAkB,EAAEY,KAAKC,SAAS,CACjFJ,KACA,CAAC;wBACL;oBACF;gBACF;YAEJ,OAAO;gBACLnC,QAAQoC,MAAM,CAACI,IAAI,CAAC;oBAAEC,KAAK;gBAAqB;YAClD;QACF,EAAE,OAAON,KAAc;YACrB,MAAMM,MAAM,CAAC,8DAA8D,EAAE3C,iBAAiB,CAAC,CAAC;YAChGE,QAAQoC,MAAM,CAACC,KAAK,CAAC;gBAAEF,KAAKM;YAAI;QAClC;IACF;IAEA,OAAO/C;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../../src/collections/FormSubmissions/hooks/sendEmail.ts"],"sourcesContent":["import type { Email, FormBuilderPluginConfig, FormattedEmail } from '../../../types.js'\n\nimport { serializeLexical } from '../../../utilities/lexical/serializeLexical.js'\nimport { replaceDoubleCurlys } from '../../../utilities/replaceDoubleCurlys.js'\nimport { serializeSlate } from '../../../utilities/slate/serializeSlate.js'\n\nexport const sendEmail = async (\n beforeChangeData: any,\n formConfig: FormBuilderPluginConfig,\n): Promise<any> => {\n const { data, operation, req } = beforeChangeData\n\n if (operation === 'create') {\n const {\n data: { id: formSubmissionID },\n req: { locale, payload },\n } = beforeChangeData\n\n const { form: formID, submissionData } = data || {}\n\n const { beforeEmail, formOverrides } = formConfig || {}\n\n try {\n const form = await payload.findByID({\n id: formID,\n collection: formOverrides?.slug || 'forms',\n locale,\n req,\n })\n\n const { emails } = form\n\n if (emails && emails.length) {\n const formattedEmails: FormattedEmail[] = await Promise.all(\n emails.map(async (email: Email): Promise<FormattedEmail | null> => {\n const {\n bcc: emailBCC,\n cc: emailCC,\n emailFrom,\n emailTo,\n message,\n replyTo: emailReplyTo,\n subject,\n } = email\n\n const to = replaceDoubleCurlys(emailTo, submissionData)\n const cc = emailCC ? replaceDoubleCurlys(emailCC, submissionData) : ''\n const bcc = emailBCC ? replaceDoubleCurlys(emailBCC, submissionData) : ''\n const from = replaceDoubleCurlys(emailFrom, submissionData)\n const replyTo = replaceDoubleCurlys(emailReplyTo || emailFrom, submissionData)\n\n const isLexical = message && !Array.isArray(message) && 'root' in message\n\n const serializedMessage = isLexical\n ? await serializeLexical(message, submissionData)\n : serializeSlate(message, submissionData)\n\n return {\n bcc,\n cc,\n from,\n html: `<div>${serializedMessage}</div>`,\n replyTo,\n subject: replaceDoubleCurlys(subject, submissionData),\n to,\n }\n }),\n )\n\n let emailsToSend = formattedEmails\n\n if (typeof beforeEmail === 'function') {\n emailsToSend = await beforeEmail(formattedEmails)\n }\n\n // const log = emailsToSend.map(({ html, ...rest }) => ({ ...rest }))\n\n await Promise.all(\n emailsToSend.map(async (email) => {\n const { to } = email\n try {\n const emailPromise = await payload.sendEmail(email)\n return emailPromise\n } catch (err: unknown) {\n payload.logger.error({\n err: `Error while sending email to address: ${to}. Email not sent: ${JSON.stringify(\n err,\n )}`,\n })\n }\n }),\n )\n } else {\n payload.logger.info({ msg: 'No emails to send.' })\n }\n } catch (err: unknown) {\n const msg = `Error while sending one or more emails in form submission id: ${formSubmissionID}.`\n payload.logger.error({ err: msg })\n }\n }\n\n return data\n}\n"],"names":["serializeLexical","replaceDoubleCurlys","serializeSlate","sendEmail","beforeChangeData","formConfig","data","operation","req","id","formSubmissionID","locale","payload","form","formID","submissionData","beforeEmail","formOverrides","findByID","collection","slug","emails","length","formattedEmails","Promise","all","map","email","bcc","emailBCC","cc","emailCC","emailFrom","emailTo","message","replyTo","emailReplyTo","subject","to","from","isLexical","Array","isArray","serializedMessage","html","emailsToSend","emailPromise","err","logger","error","JSON","stringify","info","msg"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,gBAAgB,QAAQ,iDAAgD;AACjF,SAASC,mBAAmB,QAAQ,4CAA2C;AAC/E,SAASC,cAAc,QAAQ,6CAA4C;AAE3E,OAAO,MAAMC,YAAY,OACvBC,kBACAC;IAEA,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,GAAG,EAAE,GAAGJ;IAEjC,IAAIG,cAAc,UAAU;QAC1B,MAAM,EACJD,MAAM,EAAEG,IAAIC,gBAAgB,EAAE,EAC9BF,KAAK,EAAEG,MAAM,EAAEC,OAAO,EAAE,EACzB,GAAGR;QAEJ,MAAM,EAAES,MAAMC,MAAM,EAAEC,cAAc,EAAE,GAAGT,QAAQ,CAAC;QAElD,MAAM,EAAEU,WAAW,EAAEC,aAAa,EAAE,GAAGZ,cAAc,CAAC;QAEtD,IAAI;YACF,MAAMQ,OAAO,MAAMD,QAAQM,QAAQ,CAAC;gBAClCT,IAAIK;gBACJK,YAAYF,eAAeG,QAAQ;gBACnCT;gBACAH;YACF;YAEA,MAAM,EAAEa,MAAM,EAAE,GAAGR;YAEnB,IAAIQ,UAAUA,OAAOC,MAAM,EAAE;gBAC3B,MAAMC,kBAAoC,MAAMC,QAAQC,GAAG,CACzDJ,OAAOK,GAAG,CAAC,OAAOC;oBAChB,MAAM,EACJC,KAAKC,QAAQ,EACbC,IAAIC,OAAO,EACXC,SAAS,EACTC,OAAO,EACPC,OAAO,EACPC,SAASC,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,MAAM,CAACC,KAAK,CAAC;gBAAEF,KAAKM;YAAI;QAClC;IACF;IAEA,OAAO/C;AACT,EAAC"}
@@ -77,12 +77,12 @@ export const generateSubmissionCollection = (formConfig)=>{
77
77
  ...formConfig?.formSubmissionOverrides?.fields || []
78
78
  ],
79
79
  hooks: {
80
+ ...formConfig?.formSubmissionOverrides?.hooks || {},
80
81
  beforeChange: [
81
82
  (data)=>createCharge(data, formConfig),
82
83
  (data)=>sendEmail(data, formConfig),
83
84
  ...formConfig?.formSubmissionOverrides?.hooks?.beforeChange || []
84
- ],
85
- ...formConfig?.formSubmissionOverrides?.hooks || {}
85
+ ]
86
86
  }
87
87
  };
88
88
  const paymentFieldConfig = formConfig?.fields?.payment;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/FormSubmissions/index.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { PluginConfig } from '../../types.js'\n\nimport { createCharge } from './hooks/createCharge.js'\nimport { sendEmail } from './hooks/sendEmail.js'\n\n// all settings can be overridden by the config\nexport const generateSubmissionCollection = (formConfig: PluginConfig): CollectionConfig => {\n const formSlug = formConfig?.formOverrides?.slug || 'forms'\n\n const newConfig: CollectionConfig = {\n ...(formConfig?.formSubmissionOverrides || {}),\n slug: formConfig?.formSubmissionOverrides?.slug || 'form-submissions',\n access: {\n create: () => true,\n read: ({ req: { user } }) => !!user, // logged-in users,\n update: () => false,\n ...(formConfig?.formSubmissionOverrides?.access || {}),\n },\n admin: {\n ...(formConfig?.formSubmissionOverrides?.admin || {}),\n enableRichTextRelationship: false,\n },\n fields: [\n {\n name: 'form',\n type: 'relationship',\n admin: {\n readOnly: true,\n },\n relationTo: formSlug,\n required: true,\n validate: async (value, { req: { payload }, req }) => {\n /* Don't run in the client side */\n if (!payload) return true\n\n if (payload) {\n let _existingForm\n\n try {\n _existingForm = await payload.findByID({\n id: value,\n collection: formSlug,\n req,\n })\n\n return true\n } catch (error) {\n return 'Cannot create this submission because this form does not exist.'\n }\n }\n },\n },\n {\n name: 'submissionData',\n type: 'array',\n admin: {\n readOnly: true,\n },\n fields: [\n {\n name: 'field',\n type: 'text',\n required: true,\n },\n {\n name: 'value',\n type: 'text',\n required: true,\n validate: (value: unknown) => {\n // TODO:\n // create a validation function that dynamically\n // relies on the field type and its options as configured.\n\n // How to access sibling data from this field?\n // Need the `name` of the field in order to validate it.\n\n // Might not be possible to use this validation function.\n // Instead, might need to do all validation in a `beforeValidate` collection hook.\n\n if (typeof value !== 'undefined') {\n return true\n }\n\n return 'This field is required.'\n },\n },\n ],\n },\n ...(formConfig?.formSubmissionOverrides?.fields || []),\n ],\n hooks: {\n beforeChange: [\n (data) => createCharge(data, formConfig),\n (data) => sendEmail(data, formConfig),\n ...(formConfig?.formSubmissionOverrides?.hooks?.beforeChange || []),\n ],\n ...(formConfig?.formSubmissionOverrides?.hooks || {}),\n },\n }\n\n const paymentFieldConfig = formConfig?.fields?.payment\n\n if (paymentFieldConfig) {\n newConfig.fields.push({\n name: 'payment',\n type: 'group',\n admin: {\n readOnly: true,\n },\n fields: [\n {\n name: 'field',\n type: 'text',\n label: 'Field',\n },\n {\n name: 'status',\n type: 'text',\n label: 'Status',\n },\n {\n name: 'amount',\n type: 'number',\n admin: {\n description: 'Amount in cents',\n },\n },\n {\n name: 'paymentProcessor',\n type: 'text',\n },\n {\n name: 'creditCard',\n type: 'group',\n fields: [\n {\n name: 'token',\n type: 'text',\n label: 'token',\n },\n {\n name: 'brand',\n type: 'text',\n label: 'Brand',\n },\n {\n name: 'number',\n type: 'text',\n label: 'Number',\n },\n ],\n label: 'Credit Card',\n },\n ],\n })\n }\n\n return newConfig\n}\n"],"names":["createCharge","sendEmail","generateSubmissionCollection","formConfig","formSlug","formOverrides","slug","newConfig","formSubmissionOverrides","access","create","read","req","user","update","admin","enableRichTextRelationship","fields","name","type","readOnly","relationTo","required","validate","value","payload","_existingForm","findByID","id","collection","error","hooks","beforeChange","data","paymentFieldConfig","payment","push","label","description"],"rangeMapp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,OAAO9B;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/FormSubmissions/index.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload/types'\n\nimport type { FormBuilderPluginConfig } from '../../types.js'\n\nimport { createCharge } from './hooks/createCharge.js'\nimport { sendEmail } from './hooks/sendEmail.js'\n\n// all settings can be overridden by the config\nexport const generateSubmissionCollection = (\n formConfig: FormBuilderPluginConfig,\n): CollectionConfig => {\n const formSlug = formConfig?.formOverrides?.slug || 'forms'\n\n const newConfig: CollectionConfig = {\n ...(formConfig?.formSubmissionOverrides || {}),\n slug: formConfig?.formSubmissionOverrides?.slug || 'form-submissions',\n access: {\n create: () => true,\n read: ({ req: { user } }) => !!user, // logged-in users,\n update: () => false,\n ...(formConfig?.formSubmissionOverrides?.access || {}),\n },\n admin: {\n ...(formConfig?.formSubmissionOverrides?.admin || {}),\n enableRichTextRelationship: false,\n },\n fields: [\n {\n name: 'form',\n type: 'relationship',\n admin: {\n readOnly: true,\n },\n relationTo: formSlug,\n required: true,\n validate: async (value, { req: { payload }, req }) => {\n /* Don't run in the client side */\n if (!payload) return true\n\n if (payload) {\n let _existingForm\n\n try {\n _existingForm = await payload.findByID({\n id: value,\n collection: formSlug,\n req,\n })\n\n return true\n } catch (error) {\n return 'Cannot create this submission because this form does not exist.'\n }\n }\n },\n },\n {\n name: 'submissionData',\n type: 'array',\n admin: {\n readOnly: true,\n },\n fields: [\n {\n name: 'field',\n type: 'text',\n required: true,\n },\n {\n name: 'value',\n type: 'text',\n required: true,\n validate: (value: unknown) => {\n // TODO:\n // create a validation function that dynamically\n // relies on the field type and its options as configured.\n\n // How to access sibling data from this field?\n // Need the `name` of the field in order to validate it.\n\n // Might not be possible to use this validation function.\n // Instead, might need to do all validation in a `beforeValidate` collection hook.\n\n if (typeof value !== 'undefined') {\n return true\n }\n\n return 'This field is required.'\n },\n },\n ],\n },\n ...(formConfig?.formSubmissionOverrides?.fields || []),\n ],\n hooks: {\n ...(formConfig?.formSubmissionOverrides?.hooks || {}),\n beforeChange: [\n (data) => createCharge(data, formConfig),\n (data) => sendEmail(data, formConfig),\n ...(formConfig?.formSubmissionOverrides?.hooks?.beforeChange || []),\n ],\n },\n }\n\n const paymentFieldConfig = formConfig?.fields?.payment\n\n if (paymentFieldConfig) {\n newConfig.fields.push({\n name: 'payment',\n type: 'group',\n admin: {\n readOnly: true,\n },\n fields: [\n {\n name: 'field',\n type: 'text',\n label: 'Field',\n },\n {\n name: 'status',\n type: 'text',\n label: 'Status',\n },\n {\n name: 'amount',\n type: 'number',\n admin: {\n description: 'Amount in cents',\n },\n },\n {\n name: 'paymentProcessor',\n type: 'text',\n },\n {\n name: 'creditCard',\n type: 'group',\n fields: [\n {\n name: 'token',\n type: 'text',\n label: 'token',\n },\n {\n name: 'brand',\n type: 'text',\n label: 'Brand',\n },\n {\n name: 'number',\n type: 'text',\n label: 'Number',\n },\n ],\n label: 'Credit Card',\n },\n ],\n })\n }\n\n return newConfig\n}\n"],"names":["createCharge","sendEmail","generateSubmissionCollection","formConfig","formSlug","formOverrides","slug","newConfig","formSubmissionOverrides","access","create","read","req","user","update","admin","enableRichTextRelationship","fields","name","type","readOnly","relationTo","required","validate","value","payload","_existingForm","findByID","id","collection","error","hooks","beforeChange","data","paymentFieldConfig","payment","push","label","description"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,YAAY,QAAQ,0BAAyB;AACtD,SAASC,SAAS,QAAQ,uBAAsB;AAEhD,+CAA+C;AAC/C,OAAO,MAAMC,+BAA+B,CAC1CC;IAEA,MAAMC,WAAWD,YAAYE,eAAeC,QAAQ;IAEpD,MAAMC,YAA8B;QAClC,GAAIJ,YAAYK,2BAA2B,CAAC,CAAC;QAC7CF,MAAM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AC,CAAC;YACpDC,cAAc;gBACZ,CAACC,OAASjC,aAAaiC,MAAM9B;gBAC7B,CAAC8B,OAAShC,UAAUgC,MAAM9B;mBACtBA,YAAYK,yBAAyBuB,OAAOC,gBAAgB,EAAE;aACnE;QACH;IACF;IAEA,MAAME,qBAAqB/B,YAAYc,QAAQkB;IAE/C,IAAID,oBAAoB;QACtB3B,UAAUU,MAAM,CAACmB,IAAI,CAAC;YACpBlB,MAAM;YACNC,MAAM;YACNJ,OAAO;gBACLK,UAAU;YACZ;YACAH,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;oBACNkB,OAAO;gBACT;gBACA;oBACEnB,MAAM;oBACNC,MAAM;oBACNkB,OAAO;gBACT;gBACA;oBACEnB,MAAM;oBACNC,MAAM;oBACNJ,OAAO;wBACLuB,aAAa;oBACf;gBACF;gBACA;oBACEpB,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;oBACNF,QAAQ;wBACN;4BACEC,MAAM;4BACNC,MAAM;4BACNkB,OAAO;wBACT;wBACA;4BACEnB,MAAM;4BACNC,MAAM;4BACNkB,OAAO;wBACT;wBACA;4BACEnB,MAAM;4BACNC,MAAM;4BACNkB,OAAO;wBACT;qBACD;oBACDA,OAAO;gBACT;aACD;QACH;IACF;IAEA,OAAO9B;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/Forms/index.ts"],"sourcesContent":["import type { Block, CollectionConfig, Field } from 'payload/types'\n\nimport merge from 'deepmerge'\n\nimport type { FieldConfig, PluginConfig } from '../../types.js'\n\nimport { fields } from './fields.js'\n\n// all settings can be overridden by the config\nexport const generateFormCollection = (formConfig: PluginConfig): CollectionConfig => {\n const redirect: Field = {\n name: 'redirect',\n type: 'group',\n admin: {\n condition: (_, siblingData) => siblingData?.confirmationType === 'redirect',\n hideGutter: true,\n },\n fields: [\n {\n name: 'url',\n type: 'text',\n label: 'URL to redirect to',\n required: true,\n },\n ],\n }\n\n if (formConfig.redirectRelationships) {\n redirect.fields.unshift({\n name: 'reference',\n type: 'relationship',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'reference',\n },\n label: 'Document to link to',\n maxDepth: 2,\n relationTo: formConfig.redirectRelationships,\n required: true,\n })\n\n redirect.fields.unshift({\n name: 'type',\n type: 'radio',\n admin: {\n layout: 'horizontal',\n },\n defaultValue: 'reference',\n options: [\n {\n label: 'Internal link',\n value: 'reference',\n },\n {\n label: 'Custom URL',\n value: 'custom',\n },\n ],\n })\n\n if (redirect.fields[2].type !== 'row') redirect.fields[2].label = 'Custom URL'\n\n redirect.fields[2].admin = {\n condition: (_, siblingData) => siblingData?.type === 'custom',\n }\n }\n\n const config: CollectionConfig = {\n ...(formConfig?.formOverrides || {}),\n slug: formConfig?.formOverrides?.slug || 'forms',\n access: {\n read: () => true,\n ...(formConfig?.formOverrides?.access || {}),\n },\n admin: {\n enableRichTextRelationship: false,\n useAsTitle: 'title',\n ...(formConfig?.formOverrides?.admin || {}),\n },\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n },\n {\n name: 'fields',\n type: 'blocks',\n blocks: Object.entries(formConfig?.fields || {})\n .map(([fieldKey, fieldConfig]) => {\n // let the config enable/disable fields with either boolean values or objects\n if (fieldConfig !== false) {\n const block = fields[fieldKey]\n\n if (block === undefined && typeof fieldConfig === 'object') {\n return fieldConfig\n }\n\n if (typeof block === 'object' && typeof fieldConfig === 'object') {\n return merge<FieldConfig>(block, fieldConfig, {\n arrayMerge: (_, sourceArray) => sourceArray,\n })\n }\n\n if (typeof block === 'function') {\n return block(fieldConfig)\n }\n\n return block\n }\n\n return null\n })\n .filter(Boolean) as Block[],\n },\n {\n name: 'submitButtonLabel',\n type: 'text',\n localized: true,\n },\n {\n name: 'confirmationType',\n type: 'radio',\n admin: {\n description:\n 'Choose whether to display an on-page message or redirect to a different page after they submit the form.',\n layout: 'horizontal',\n },\n defaultValue: 'message',\n options: [\n {\n label: 'Message',\n value: 'message',\n },\n {\n label: 'Redirect',\n value: 'redirect',\n },\n ],\n },\n {\n name: 'confirmationMessage',\n type: 'richText',\n admin: {\n condition: (_, siblingData) => siblingData?.confirmationType === 'message',\n },\n localized: true,\n required: true,\n },\n redirect,\n {\n name: 'emails',\n type: 'array',\n admin: {\n description:\n \"Send custom emails when the form submits. Use comma separated lists to send the same email to multiple recipients. To reference a value from this form, wrap that field's name with double curly brackets, i.e. {{firstName}}.\",\n },\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'emailTo',\n type: 'text',\n admin: {\n placeholder: '\"Email Sender\" <sender@email.com>',\n width: '100%',\n },\n label: 'Email To',\n },\n {\n name: 'cc',\n type: 'text',\n admin: {\n width: '50%',\n },\n label: 'CC',\n },\n {\n name: 'bcc',\n type: 'text',\n admin: {\n width: '50%',\n },\n label: 'BCC',\n },\n ],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'replyTo',\n type: 'text',\n admin: {\n placeholder: '\"Reply To\" <reply-to@email.com>',\n width: '50%',\n },\n label: 'Reply To',\n },\n {\n name: 'emailFrom',\n type: 'text',\n admin: {\n placeholder: '\"Email From\" <email-from@email.com>',\n width: '50%',\n },\n label: 'Email From',\n },\n ],\n },\n {\n name: 'subject',\n type: 'text',\n defaultValue: \"You've received a new message.\",\n label: 'Subject',\n localized: true,\n required: true,\n },\n {\n name: 'message',\n type: 'richText',\n admin: {\n description: 'Enter the message that should be sent in this email.',\n },\n label: 'Message',\n localized: true,\n },\n ],\n },\n ...(formConfig?.formOverrides?.fields || []),\n ],\n }\n\n return config\n}\n"],"names":["merge","fields","generateFormCollection","formConfig","redirect","name","type","admin","condition","_","siblingData","confirmationType","hideGutter","label","required","redirectRelationships","unshift","maxDepth","relationTo","layout","defaultValue","options","value","config","formOverrides","slug","access","read","enableRichTextRelationship","useAsTitle","blocks","Object","entries","map","fieldKey","fieldConfig","block","undefined","arrayMerge","sourceArray","filter","Boolean","localized","description","placeholder","width"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;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aC,qBAAqB;gBACnE;gBACA+B,WAAW;gBACX5B,UAAU;YACZ;YACAV;YACA;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;oBACLoC,aACE;gBACJ;gBACA1C,QAAQ;oBACN;wBACEK,MAAM;wBACNL,QAAQ;4BACN;gCACEI,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLqC,aAAa;oCACbC,OAAO;gCACT;gCACAhC,OAAO;4BACT;4BACA;gCACER,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLsC,OAAO;gCACT;gCACAhC,OAAO;4BACT;4BACA;gCACER,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLsC,OAAO;gCACT;gCACAhC,OAAO;4BACT;yBACD;oBACH;oBACA;wBACEP,MAAM;wBACNL,QAAQ;4BACN;gCACEI,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLqC,aAAa;oCACbC,OAAO;gCACT;gCACAhC,OAAO;4BACT;4BACA;gCACER,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLqC,aAAa;oCACbC,OAAO;gCACT;gCACAhC,OAAO;4BACT;yBACD;oBACH;oBACA;wBACER,MAAM;wBACNC,MAAM;wBACNc,cAAc;wBACdP,OAAO;wBACP6B,WAAW;wBACX5B,UAAU;oBACZ;oBACA;wBACET,MAAM;wBACNC,MAAM;wBACNC,OAAO;4BACLoC,aAAa;wBACf;wBACA9B,OAAO;wBACP6B,WAAW;oBACb;iBACD;YACH;eACIvC,YAAYqB,eAAevB,UAAU,EAAE;SAC5C;IACH;IAEA,OAAOsB;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/Forms/index.ts"],"sourcesContent":["import type { Block, CollectionConfig, Field } from 'payload/types'\n\nimport merge from 'deepmerge'\n\nimport type { FieldConfig, FormBuilderPluginConfig } from '../../types.js'\n\nimport { fields } from './fields.js'\n\n// all settings can be overridden by the config\nexport const generateFormCollection = (formConfig: FormBuilderPluginConfig): CollectionConfig => {\n const redirect: Field = {\n name: 'redirect',\n type: 'group',\n admin: {\n condition: (_, siblingData) => siblingData?.confirmationType === 'redirect',\n hideGutter: true,\n },\n fields: [\n {\n name: 'url',\n type: 'text',\n label: 'URL to redirect to',\n required: true,\n },\n ],\n }\n\n if (formConfig.redirectRelationships) {\n redirect.fields.unshift({\n name: 'reference',\n type: 'relationship',\n admin: {\n condition: (_, siblingData) => siblingData?.type === 'reference',\n },\n label: 'Document to link to',\n maxDepth: 2,\n relationTo: formConfig.redirectRelationships,\n required: true,\n })\n\n redirect.fields.unshift({\n name: 'type',\n type: 'radio',\n admin: {\n layout: 'horizontal',\n },\n defaultValue: 'reference',\n options: [\n {\n label: 'Internal link',\n value: 'reference',\n },\n {\n label: 'Custom URL',\n value: 'custom',\n },\n ],\n })\n\n if (redirect.fields[2].type !== 'row') redirect.fields[2].label = 'Custom URL'\n\n redirect.fields[2].admin = {\n condition: (_, siblingData) => siblingData?.type === 'custom',\n }\n }\n\n const config: CollectionConfig = {\n ...(formConfig?.formOverrides || {}),\n slug: formConfig?.formOverrides?.slug || 'forms',\n access: {\n read: () => true,\n ...(formConfig?.formOverrides?.access || {}),\n },\n admin: {\n enableRichTextRelationship: false,\n useAsTitle: 'title',\n ...(formConfig?.formOverrides?.admin || {}),\n },\n fields: [\n {\n name: 'title',\n type: 'text',\n required: true,\n },\n {\n name: 'fields',\n type: 'blocks',\n blocks: Object.entries(formConfig?.fields || {})\n .map(([fieldKey, fieldConfig]) => {\n // let the config enable/disable fields with either boolean values or objects\n if (fieldConfig !== false) {\n const block = fields[fieldKey]\n\n if (block === undefined && typeof fieldConfig === 'object') {\n return fieldConfig\n }\n\n if (typeof block === 'object' && typeof fieldConfig === 'object') {\n return merge<FieldConfig>(block, fieldConfig, {\n arrayMerge: (_, sourceArray) => sourceArray,\n })\n }\n\n if (typeof block === 'function') {\n return block(fieldConfig)\n }\n\n return block\n }\n\n return null\n })\n .filter(Boolean) as Block[],\n },\n {\n name: 'submitButtonLabel',\n type: 'text',\n localized: true,\n },\n {\n name: 'confirmationType',\n type: 'radio',\n admin: {\n description:\n 'Choose whether to display an on-page message or redirect to a different page after they submit the form.',\n layout: 'horizontal',\n },\n defaultValue: 'message',\n options: [\n {\n label: 'Message',\n value: 'message',\n },\n {\n label: 'Redirect',\n value: 'redirect',\n },\n ],\n },\n {\n name: 'confirmationMessage',\n type: 'richText',\n admin: {\n condition: (_, siblingData) => siblingData?.confirmationType === 'message',\n },\n localized: true,\n required: true,\n },\n redirect,\n {\n name: 'emails',\n type: 'array',\n admin: {\n description:\n \"Send custom emails when the form submits. Use comma separated lists to send the same email to multiple recipients. To reference a value from this form, wrap that field's name with double curly brackets, i.e. {{firstName}}.\",\n },\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'emailTo',\n type: 'text',\n admin: {\n placeholder: '\"Email Sender\" <sender@email.com>',\n width: '100%',\n },\n label: 'Email To',\n },\n {\n name: 'cc',\n type: 'text',\n admin: {\n width: '50%',\n },\n label: 'CC',\n },\n {\n name: 'bcc',\n type: 'text',\n admin: {\n width: '50%',\n },\n label: 'BCC',\n },\n ],\n },\n {\n type: 'row',\n fields: [\n {\n name: 'replyTo',\n type: 'text',\n admin: {\n placeholder: '\"Reply To\" <reply-to@email.com>',\n width: '50%',\n },\n label: 'Reply To',\n },\n {\n name: 'emailFrom',\n type: 'text',\n admin: {\n placeholder: '\"Email From\" <email-from@email.com>',\n width: '50%',\n },\n label: 'Email From',\n },\n ],\n },\n {\n name: 'subject',\n type: 'text',\n defaultValue: \"You've received a new message.\",\n label: 'Subject',\n localized: true,\n required: true,\n },\n {\n name: 'message',\n type: 'richText',\n admin: {\n description: 'Enter the message that should be sent in this email.',\n },\n label: 'Message',\n localized: true,\n },\n ],\n },\n ...(formConfig?.formOverrides?.fields || []),\n ],\n }\n\n return config\n}\n"],"names":["merge","fields","generateFormCollection","formConfig","redirect","name","type","admin","condition","_","siblingData","confirmationType","hideGutter","label","required","redirectRelationships","unshift","maxDepth","relationTo","layout","defaultValue","options","value","config","formOverrides","slug","access","read","enableRichTextRelationship","useAsTitle","blocks","Object","entries","map","fieldKey","fieldConfig","block","undefined","arrayMerge","sourceArray","filter","Boolean","localized","description","placeholder","width"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,WAAW,YAAW;AAI7B,SAASC,MAAM,QAAQ,cAAa;AAEpC,+CAA+C;AAC/C,OAAO,MAAMC,yBAAyB,CAACC;IACrC,MAAMC,WAAkB;QACtBC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,WAAW,CAACC,GAAGC,cAAgBA,aAAaC,qBAAqB;YACjEC,YAAY;QACd;QACAX,QAAQ;YACN;gBACEI,MAAM;gBACNC,MAAM;gBACNO,OAAO;gBACPC,UAAU;YACZ;SACD;IACH;IAEA,IAAIX,WAAWY,qBAAqB,EAAE;QACpCX,SAASH,MAAM,CAACe,OAAO,CAAC;YACtBX,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLC,WAAW,CAACC,GAAGC,cAAgBA,aAAaJ,SAAS;YACvD;YACAO,OAAO;YACPI,UAAU;YACVC,YAAYf,WAAWY,qBAAqB;YAC5CD,UAAU;QACZ;QAEAV,SAASH,MAAM,CAACe,OAAO,CAAC;YACtBX,MAAM;YACNC,MAAM;YACNC,OAAO;gBACLY,QAAQ;YACV;YACAC,cAAc;YACdC,SAAS;gBACP;oBACER,OAAO;oBACPS,OAAO;gBACT;gBACA;oBACET,OAAO;oBACPS,OAAO;gBACT;aACD;QACH;QAEA,IAAIlB,SAASH,MAAM,CAAC,EAAE,CAACK,IAAI,KAAK,OAAOF,SAASH,MAAM,CAAC,EA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PS,OAAO;oBACT;oBACA;wBACET,OAAO;wBACPS,OAAO;oBACT;iBACD;YACH;YACA;gBACEjB,MAAM;gBACNC,MAAM;gBACNC,OAAO;oBACLC,WAAW,CAACC,GAAGC,cAAgBA,aAAaC,qBAAqB;gBACnE;gBACA+B,WAAW;gBACX5B,UAAU;YACZ;YACAV;YACA;gBACEC,MAAM;gBACNC,MAAM;gBACNC,OAAO;oBACLoC,aACE;gBACJ;gBACA1C,QAAQ;oBACN;wBACEK,MAAM;wBACNL,QAAQ;4BACN;gCACEI,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLqC,aAAa;oCACbC,OAAO;gCACT;gCACAhC,OAAO;4BACT;4BACA;gCACER,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLsC,OAAO;gCACT;gCACAhC,OAAO;4BACT;4BACA;gCACER,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLsC,OAAO;gCACT;gCACAhC,OAAO;4BACT;yBACD;oBACH;oBACA;wBACEP,MAAM;wBACNL,QAAQ;4BACN;gCACEI,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLqC,aAAa;oCACbC,OAAO;gCACT;gCACAhC,OAAO;4BACT;4BACA;gCACER,MAAM;gCACNC,MAAM;gCACNC,OAAO;oCACLqC,aAAa;oCACbC,OAAO;gCACT;gCACAhC,OAAO;4BACT;yBACD;oBACH;oBACA;wBACER,MAAM;wBACNC,MAAM;wBACNc,cAAc;wBACdP,OAAO;wBACP6B,WAAW;wBACX5B,UAAU;oBACZ;oBACA;wBACET,MAAM;wBACNC,MAAM;wBACNC,OAAO;4BACLoC,aAAa;wBACf;wBACA9B,OAAO;wBACP6B,WAAW;oBACb;iBACD;YACH;eACIvC,YAAYqB,eAAevB,UAAU,EAAE;SAC5C;IACH;IAEA,OAAOsB;AACT,EAAC"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exports/types.ts"],"sourcesContent":["export type {\n BeforeEmail,\n BlockConfig,\n CheckboxField,\n CountryField,\n Email,\n EmailField,\n FieldConfig,\n FieldValues,\n FieldsConfig,\n Form,\n FormBuilderPluginConfig as PluginConfig,\n FormFieldBlock,\n FormSubmission,\n FormattedEmail,\n HandlePayment,\n MessageField,\n PaymentField,\n PaymentFieldConfig,\n PriceCondition,\n Redirect,\n SelectField,\n SelectFieldOption,\n StateField,\n SubmissionValue,\n TextAreaField,\n TextField,\n isValidBlockConfig,\n} from '../types.js'\n"],"names":[],"rangeMappings":"","mappings":"AAAA,WA4BoB"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { generateSubmissionCollection } from './collections/FormSubmissions/inde
2
2
  import { generateFormCollection } from './collections/Forms/index.js';
3
3
  export { fields } from './collections/Forms/fields.js';
4
4
  export { getPaymentTotal } from './utilities/getPaymentTotal.js';
5
- const FormBuilder = (incomingFormConfig)=>(config)=>{
5
+ export const formBuilderPlugin = (incomingFormConfig)=>(config)=>{
6
6
  const formConfig = {
7
7
  ...incomingFormConfig,
8
8
  fields: {
@@ -42,6 +42,5 @@ const FormBuilder = (incomingFormConfig)=>(config)=>{
42
42
  ]
43
43
  };
44
44
  };
45
- export default FormBuilder;
46
45
 
47
46
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload/config'\n\nimport type { PluginConfig } from './types.js'\n\nimport { generateSubmissionCollection } from './collections/FormSubmissions/index.js'\nimport { generateFormCollection } from './collections/Forms/index.js'\n\nexport { fields } from './collections/Forms/fields.js'\nexport { getPaymentTotal } from './utilities/getPaymentTotal.js'\n\nconst FormBuilder =\n (incomingFormConfig: PluginConfig) =>\n (config: Config): Config => {\n const formConfig: PluginConfig = {\n ...incomingFormConfig,\n fields: {\n checkbox: true,\n country: true,\n email: true,\n message: true,\n number: true,\n payment: false,\n select: true,\n state: true,\n text: true,\n textarea: true,\n ...incomingFormConfig.fields,\n },\n }\n\n return {\n ...config,\n // admin: {\n // ...config.admin,\n // webpack: (webpackConfig) => ({\n // ...webpackConfig,\n // resolve: {\n // ...webpackConfig.resolve,\n // alias: {\n // ...webpackConfig.resolve.alias,\n // [path.resolve(__dirname, 'collections/FormSubmissions/hooks/sendEmail.ts')]: path.resolve(__dirname, 'mocks/serverModule.js'),\n // [path.resolve(__dirname, 'collections/FormSubmissions/hooks/createCharge.ts')]: path.resolve(__dirname, 'mocks/serverModule.js'),\n // },\n // },\n // })\n // },\n collections: [\n ...(config?.collections || []),\n generateFormCollection(formConfig),\n generateSubmissionCollection(formConfig),\n ],\n }\n }\n\nexport default FormBuilder\n"],"names":["generateSubmissionCollection","generateFormCollection","fields","getPaymentTotal","FormBuilder","incomingFormConfig","config","formConfig","checkbox","country","email","message","number","payment","select","state","text","textarea","collections"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,4BAA4B,QAAQ,yCAAwC;AACrF,SAASC,sBAAsB,QAAQ,+BAA8B;AAErE,SAASC,MAAM,QAAQ,gCAA+B;AACtD,SAASC,eAAe,QAAQ,iCAAgC;AAEhE,MAAMC,cACJ,CAACC,qBACD,CAACC;QACC,MAAMC,aAA2B;YAC/B,GAAGF,kBAAkB;YACrBH,QAAQ;gBACNM,UAAU;gBACVC,SAAS;gBACTC,OAAO;gBACPC,SAAS;gBACTC,QAAQ;gBACRC,SAAS;gBACTC,QAAQ;gBACRC,OAAO;gBACPC,MAAM;gBACNC,UAAU;gBACV,GAAGZ,mBAAmBH,MAAM;YAC9B;QACF;QAEA,OAAO;YACL,GAAGI,MAAM;YACT,WAAW;YACX,qBAAqB;YACrB,mCAAmC;YACnC,wBAAwB;YACxB,iBAAiB;YACjB,kCAAkC;YAClC,iBAAiB;YACjB,0CAA0C;YAC1C,yIAAyI;YACzI,4IAA4I;YAC5I,WAAW;YACX,SAAS;YACT,OAAO;YACP,KAAK;YACLY,aAAa;mBACPZ,QAAQY,eAAe,EAAE;gBAC7BjB,uBAAuBM;gBACvBP,6BAA6BO;aAC9B;QACH;IACF;AAEF,eAAeH,YAAW"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload/config'\n\nimport type { FormBuilderPluginConfig } from './types.js'\n\nimport { generateSubmissionCollection } from './collections/FormSubmissions/index.js'\nimport { generateFormCollection } from './collections/Forms/index.js'\n\nexport { fields } from './collections/Forms/fields.js'\nexport { getPaymentTotal } from './utilities/getPaymentTotal.js'\n\nexport const formBuilderPlugin =\n (incomingFormConfig: FormBuilderPluginConfig) =>\n (config: Config): Config => {\n const formConfig: FormBuilderPluginConfig = {\n ...incomingFormConfig,\n fields: {\n checkbox: true,\n country: true,\n email: true,\n message: true,\n number: true,\n payment: false,\n select: true,\n state: true,\n text: true,\n textarea: true,\n ...incomingFormConfig.fields,\n },\n }\n\n return {\n ...config,\n // admin: {\n // ...config.admin,\n // webpack: (webpackConfig) => ({\n // ...webpackConfig,\n // resolve: {\n // ...webpackConfig.resolve,\n // alias: {\n // ...webpackConfig.resolve.alias,\n // [path.resolve(__dirname, 'collections/FormSubmissions/hooks/sendEmail.ts')]: path.resolve(__dirname, 'mocks/serverModule.js'),\n // [path.resolve(__dirname, 'collections/FormSubmissions/hooks/createCharge.ts')]: path.resolve(__dirname, 'mocks/serverModule.js'),\n // },\n // },\n // })\n // },\n collections: [\n ...(config?.collections || []),\n generateFormCollection(formConfig),\n generateSubmissionCollection(formConfig),\n ],\n }\n }\n"],"names":["generateSubmissionCollection","generateFormCollection","fields","getPaymentTotal","formBuilderPlugin","incomingFormConfig","config","formConfig","checkbox","country","email","message","number","payment","select","state","text","textarea","collections"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,4BAA4B,QAAQ,yCAAwC;AACrF,SAASC,sBAAsB,QAAQ,+BAA8B;AAErE,SAASC,MAAM,QAAQ,gCAA+B;AACtD,SAASC,eAAe,QAAQ,iCAAgC;AAEhE,OAAO,MAAMC,oBACX,CAACC,qBACD,CAACC;QACC,MAAMC,aAAsC;YAC1C,GAAGF,kBAAkB;YACrBH,QAAQ;gBACNM,UAAU;gBACVC,SAAS;gBACTC,OAAO;gBACPC,SAAS;gBACTC,QAAQ;gBACRC,SAAS;gBACTC,QAAQ;gBACRC,OAAO;gBACPC,MAAM;gBACNC,UAAU;gBACV,GAAGZ,mBAAmBH,MAAM;YAC9B;QACF;QAEA,OAAO;YACL,GAAGI,MAAM;YACT,WAAW;YACX,qBAAqB;YACrB,mCAAmC;YACnC,wBAAwB;YACxB,iBAAiB;YACjB,kCAAkC;YAClC,iBAAiB;YACjB,0CAA0C;YAC1C,yIAAyI;YACzI,4IAA4I;YAC5I,WAAW;YACX,SAAS;YACT,OAAO;YACP,KAAK;YACLY,aAAa;mBACPZ,QAAQY,eAAe,EAAE;gBAC7BjB,uBAAuBM;gBACvBP,6BAA6BO;aAC9B;QACH;IACF,EAAC"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Block, CollectionConfig, Field } from 'payload/types'\n\nexport interface BlockConfig {\n block: Block\n validate?: (value: unknown) => boolean | string\n}\n\nexport function isValidBlockConfig(blockConfig: BlockConfig | string): blockConfig is BlockConfig {\n return (\n typeof blockConfig !== 'string' &&\n typeof blockConfig?.block?.slug === 'string' &&\n Array.isArray(blockConfig?.block?.fields)\n )\n}\n\nexport interface FieldValues {\n [key: string]: boolean | null | number | string | undefined\n}\n\nexport type PaymentFieldConfig = Partial<Field> & {\n paymentProcessor: Partial<SelectField>\n}\n\nexport type FieldConfig = Partial<Field> | PaymentFieldConfig\n\nexport interface FieldsConfig {\n [key: string]: FieldConfig | boolean | undefined\n checkbox?: FieldConfig | boolean\n country?: FieldConfig | boolean\n email?: FieldConfig | boolean\n message?: FieldConfig | boolean\n number?: FieldConfig | boolean\n payment?: FieldConfig | boolean\n select?: FieldConfig | boolean\n state?: FieldConfig | boolean\n text?: FieldConfig | boolean\n textarea?: FieldConfig | boolean\n}\n\nexport type BeforeEmail = (emails: FormattedEmail[]) => FormattedEmail[] | Promise<FormattedEmail[]>\nexport type HandlePayment = (data: any) => void\n\nexport interface PluginConfig {\n beforeEmail?: BeforeEmail\n fields?: FieldsConfig\n formOverrides?: Partial<CollectionConfig>\n formSubmissionOverrides?: Partial<CollectionConfig>\n handlePayment?: HandlePayment\n redirectRelationships?: string[]\n}\n\nexport interface TextField {\n blockName?: string\n blockType: 'text'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface TextAreaField {\n blockName?: string\n blockType: 'textarea'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface SelectFieldOption {\n label: string\n value: string\n}\n\nexport interface SelectField {\n blockName?: string\n blockType: 'select'\n defaultValue?: string\n label?: string\n name: string\n options: SelectFieldOption[]\n required?: boolean\n width?: number\n}\n\nexport interface PriceCondition {\n condition: 'equals' | 'hasValue' | 'notEquals'\n fieldToUse: string\n operator: 'add' | 'divide' | 'multiply' | 'subtract'\n valueForCondition: string\n valueForOperator: number | string // TODO: make this a number, see ./collections/Forms/DynamicPriceSelector.tsx\n valueType: 'static' | 'valueOfField'\n}\n\nexport interface PaymentField {\n basePrice: number\n blockName?: string\n blockType: 'payment'\n defaultValue?: string\n label?: string\n name: string\n paymentProcessor: string\n priceConditions: PriceCondition[]\n required?: boolean\n width?: number\n}\n\nexport interface EmailField {\n blockName?: string\n blockType: 'email'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface StateField {\n blockName?: string\n blockType: 'state'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface CountryField {\n blockName?: string\n blockType: 'country'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface CheckboxField {\n blockName?: string\n blockType: 'checkbox'\n defaultValue?: boolean\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface MessageField {\n blockName?: string\n blockType: 'message'\n message: unknown\n}\n\nexport type FormFieldBlock =\n | CheckboxField\n | CountryField\n | EmailField\n | MessageField\n | PaymentField\n | SelectField\n | StateField\n | TextAreaField\n | TextField\n\nexport interface Email {\n bcc?: string\n cc?: string\n emailFrom: string\n emailTo: string\n message?: any // TODO: configure rich text type\n replyTo?: string\n subject: string\n}\n\nexport interface FormattedEmail {\n bcc?: string\n cc?: string\n from: string\n html: string\n replyTo: string\n subject: string\n to: string\n}\n\nexport interface Redirect {\n reference?: {\n relationTo: string\n value: string | unknown\n }\n type: 'custom' | 'reference'\n url: string\n}\n\nexport interface Form {\n confirmationMessage?: any // TODO: configure rich text type\n confirmationType: 'message' | 'redirect'\n emails: Email[]\n fields: FormFieldBlock[]\n id: string\n redirect?: Redirect\n submitButtonLabel?: string\n title: string\n}\n\nexport interface SubmissionValue {\n field: string\n value: unknown\n}\n\nexport interface FormSubmission {\n form: Form | string\n submissionData: SubmissionValue[]\n}\n"],"names":["isValidBlockConfig","blockConfig","block","slug","Array","isArray","fields"],"rangeMappings":";;","mappings":"AAOA,OAAO,SAASA,mBAAmBC,WAAiC;IAClE,OACE,OAAOA,gBAAgB,YACvB,OAAOA,aAAaC,OAAOC,SAAS,YACpCC,MAAMC,OAAO,CAACJ,aAAaC,OAAOI;AAEtC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Block, CollectionConfig, Field } from 'payload/types'\n\nexport interface BlockConfig {\n block: Block\n validate?: (value: unknown) => boolean | string\n}\n\nexport function isValidBlockConfig(blockConfig: BlockConfig | string): blockConfig is BlockConfig {\n return (\n typeof blockConfig !== 'string' &&\n typeof blockConfig?.block?.slug === 'string' &&\n Array.isArray(blockConfig?.block?.fields)\n )\n}\n\nexport interface FieldValues {\n [key: string]: boolean | null | number | string | undefined\n}\n\nexport type PaymentFieldConfig = Partial<Field> & {\n paymentProcessor: Partial<SelectField>\n}\n\nexport type FieldConfig = Partial<Field> | PaymentFieldConfig\n\nexport interface FieldsConfig {\n [key: string]: FieldConfig | boolean | undefined\n checkbox?: FieldConfig | boolean\n country?: FieldConfig | boolean\n email?: FieldConfig | boolean\n message?: FieldConfig | boolean\n number?: FieldConfig | boolean\n payment?: FieldConfig | boolean\n select?: FieldConfig | boolean\n state?: FieldConfig | boolean\n text?: FieldConfig | boolean\n textarea?: FieldConfig | boolean\n}\n\nexport type BeforeEmail = (emails: FormattedEmail[]) => FormattedEmail[] | Promise<FormattedEmail[]>\nexport type HandlePayment = (data: any) => void\n\nexport type FormBuilderPluginConfig = {\n beforeEmail?: BeforeEmail\n fields?: FieldsConfig\n formOverrides?: Partial<CollectionConfig>\n formSubmissionOverrides?: Partial<CollectionConfig>\n handlePayment?: HandlePayment\n redirectRelationships?: string[]\n}\n\nexport interface TextField {\n blockName?: string\n blockType: 'text'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface TextAreaField {\n blockName?: string\n blockType: 'textarea'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface SelectFieldOption {\n label: string\n value: string\n}\n\nexport interface SelectField {\n blockName?: string\n blockType: 'select'\n defaultValue?: string\n label?: string\n name: string\n options: SelectFieldOption[]\n required?: boolean\n width?: number\n}\n\nexport interface PriceCondition {\n condition: 'equals' | 'hasValue' | 'notEquals'\n fieldToUse: string\n operator: 'add' | 'divide' | 'multiply' | 'subtract'\n valueForCondition: string\n valueForOperator: number | string // TODO: make this a number, see ./collections/Forms/DynamicPriceSelector.tsx\n valueType: 'static' | 'valueOfField'\n}\n\nexport interface PaymentField {\n basePrice: number\n blockName?: string\n blockType: 'payment'\n defaultValue?: string\n label?: string\n name: string\n paymentProcessor: string\n priceConditions: PriceCondition[]\n required?: boolean\n width?: number\n}\n\nexport interface EmailField {\n blockName?: string\n blockType: 'email'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface StateField {\n blockName?: string\n blockType: 'state'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface CountryField {\n blockName?: string\n blockType: 'country'\n defaultValue?: string\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface CheckboxField {\n blockName?: string\n blockType: 'checkbox'\n defaultValue?: boolean\n label?: string\n name: string\n required?: boolean\n width?: number\n}\n\nexport interface MessageField {\n blockName?: string\n blockType: 'message'\n message: unknown\n}\n\nexport type FormFieldBlock =\n | CheckboxField\n | CountryField\n | EmailField\n | MessageField\n | PaymentField\n | SelectField\n | StateField\n | TextAreaField\n | TextField\n\nexport interface Email {\n bcc?: string\n cc?: string\n emailFrom: string\n emailTo: string\n message?: any // TODO: configure rich text type\n replyTo?: string\n subject: string\n}\n\nexport interface FormattedEmail {\n bcc?: string\n cc?: string\n from: string\n html: string\n replyTo: string\n subject: string\n to: string\n}\n\nexport interface Redirect {\n reference?: {\n relationTo: string\n value: string | unknown\n }\n type: 'custom' | 'reference'\n url: string\n}\n\nexport interface Form {\n confirmationMessage?: any // TODO: configure rich text type\n confirmationType: 'message' | 'redirect'\n emails: Email[]\n fields: FormFieldBlock[]\n id: string\n redirect?: Redirect\n submitButtonLabel?: string\n title: string\n}\n\nexport interface SubmissionValue {\n field: string\n value: unknown\n}\n\nexport interface FormSubmission {\n form: Form | string\n submissionData: SubmissionValue[]\n}\n"],"names":["isValidBlockConfig","blockConfig","block","slug","Array","isArray","fields"],"rangeMappings":";;","mappings":"AAOA,OAAO,SAASA,mBAAmBC,WAAiC;IAClE,OACE,OAAOA,gBAAgB,YACvB,OAAOA,aAAaC,OAAOC,SAAS,YACpCC,MAAMC,OAAO,CAACJ,aAAaC,OAAOI;AAEtC"}
package/package.json CHANGED
@@ -1,26 +1,47 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-form-builder",
3
+ "version": "3.0.0-canary.92e4997",
3
4
  "description": "Form builder plugin for Payload CMS",
4
- "version": "3.0.0-beta.9",
5
- "homepage:": "https://payloadcms.com",
5
+ "keywords": [
6
+ "payload",
7
+ "cms",
8
+ "plugin",
9
+ "typescript",
10
+ "react",
11
+ "forms",
12
+ "fields",
13
+ "form builder",
14
+ "payments"
15
+ ],
6
16
  "repository": {
7
17
  "type": "git",
8
18
  "url": "https://github.com/payloadcms/payload.git",
9
19
  "directory": "packages/plugin-form-builder"
10
20
  },
11
- "main": "./dist/index.js",
12
- "types": "./dist/index.d.ts",
13
21
  "license": "MIT",
14
- "author": "dev@payloadcms.com",
22
+ "author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
15
23
  "type": "module",
16
- "peerDependencies": {
17
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
18
- "payload": "3.0.0-beta.9"
24
+ "exports": {
25
+ ".": {
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.js",
28
+ "types": "./dist/index.d.ts"
29
+ },
30
+ "./*": {
31
+ "import": "./dist/exports/*.js",
32
+ "require": "./dist/exports/*.js",
33
+ "types": "./dist/exports/*.d.ts"
34
+ }
19
35
  },
36
+ "main": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "files": [
39
+ "dist"
40
+ ],
20
41
  "dependencies": {
21
42
  "deepmerge": "^4.2.2",
22
43
  "escape-html": "^1.0.3",
23
- "@payloadcms/ui": "3.0.0-beta.9"
44
+ "@payloadcms/ui": "3.0.0-canary.92e4997"
24
45
  },
25
46
  "devDependencies": {
26
47
  "@types/escape-html": "^1.0.4",
@@ -29,38 +50,22 @@
29
50
  "copyfiles": "^2.4.1",
30
51
  "cross-env": "^7.0.3",
31
52
  "nodemon": "3.0.3",
32
- "react": "^18.0.0",
33
53
  "ts-node": "10.9.1",
34
- "@payloadcms/eslint-config": "1.1.1",
35
- "payload": "3.0.0-beta.9"
54
+ "payload": "3.0.0-canary.92e4997",
55
+ "@payloadcms/eslint-config": "1.1.1"
36
56
  },
37
- "exports": {
38
- ".": {
39
- "import": "./dist/index.js",
40
- "require": "./dist/index.js",
41
- "types": "./dist/index.d.ts"
42
- }
57
+ "peerDependencies": {
58
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
59
+ "payload": "3.0.0-canary.92e4997"
43
60
  },
44
- "files": [
45
- "dist",
46
- "types.js",
47
- "types.d.ts"
48
- ],
49
- "keywords": [
50
- "payload",
51
- "cms",
52
- "plugin",
53
- "typescript",
54
- "react",
55
- "forms",
56
- "fields",
57
- "form builder",
58
- "payments"
59
- ],
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org/"
63
+ },
64
+ "homepage:": "https://payloadcms.com",
60
65
  "scripts": {
66
+ "build": "swc ./src -d ./dist --config-file .swcrc",
61
67
  "build:swc": "swc ./src -d ./dist --config-file .swcrc",
62
68
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
63
- "build": "swc ./src -d ./dist --config-file .swcrc",
64
69
  "clean": "rimraf {dist,*.tsbuildinfo}",
65
70
  "test": "echo \"No tests available.\""
66
71
  }
package/src/index.ts DELETED
@@ -1,55 +0,0 @@
1
- import type { Config } from 'payload/config'
2
-
3
- import type { PluginConfig } from './types.js'
4
-
5
- import { generateSubmissionCollection } from './collections/FormSubmissions/index.js'
6
- import { generateFormCollection } from './collections/Forms/index.js'
7
-
8
- export { fields } from './collections/Forms/fields.js'
9
- export { getPaymentTotal } from './utilities/getPaymentTotal.js'
10
-
11
- const FormBuilder =
12
- (incomingFormConfig: PluginConfig) =>
13
- (config: Config): Config => {
14
- const formConfig: PluginConfig = {
15
- ...incomingFormConfig,
16
- fields: {
17
- checkbox: true,
18
- country: true,
19
- email: true,
20
- message: true,
21
- number: true,
22
- payment: false,
23
- select: true,
24
- state: true,
25
- text: true,
26
- textarea: true,
27
- ...incomingFormConfig.fields,
28
- },
29
- }
30
-
31
- return {
32
- ...config,
33
- // admin: {
34
- // ...config.admin,
35
- // webpack: (webpackConfig) => ({
36
- // ...webpackConfig,
37
- // resolve: {
38
- // ...webpackConfig.resolve,
39
- // alias: {
40
- // ...webpackConfig.resolve.alias,
41
- // [path.resolve(__dirname, 'collections/FormSubmissions/hooks/sendEmail.ts')]: path.resolve(__dirname, 'mocks/serverModule.js'),
42
- // [path.resolve(__dirname, 'collections/FormSubmissions/hooks/createCharge.ts')]: path.resolve(__dirname, 'mocks/serverModule.js'),
43
- // },
44
- // },
45
- // })
46
- // },
47
- collections: [
48
- ...(config?.collections || []),
49
- generateFormCollection(formConfig),
50
- generateSubmissionCollection(formConfig),
51
- ],
52
- }
53
- }
54
-
55
- export default FormBuilder
package/types.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/types'
package/types.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/types')