@10x-media/form-builder 0.1.0-beta.8 → 4.0.0-alpha.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.
Files changed (365) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/README.md +11 -3
  3. package/dist/actions/assertNoBlockCollision.js +18 -0
  4. package/dist/actions/assertNoBlockCollision.js.map +1 -0
  5. package/dist/actions/body/serializeBody.d.ts +16 -14
  6. package/dist/actions/body/serializeBody.js +5 -8
  7. package/dist/actions/body/serializeBody.js.map +1 -1
  8. package/dist/actions/builtin/confirmation.js +2 -1
  9. package/dist/actions/builtin/confirmation.js.map +1 -1
  10. package/dist/actions/builtin/emailAction.d.ts +15 -3
  11. package/dist/actions/builtin/emailAction.js +72 -20
  12. package/dist/actions/builtin/emailAction.js.map +1 -1
  13. package/dist/actions/builtin/emailTeam.js +11 -5
  14. package/dist/actions/builtin/emailTeam.js.map +1 -1
  15. package/dist/actions/defineAction.d.ts +37 -6
  16. package/dist/actions/defineAction.js +14 -1
  17. package/dist/actions/defineAction.js.map +1 -1
  18. package/dist/actions/dispatch.d.ts +12 -0
  19. package/dist/actions/dispatch.js +103 -30
  20. package/dist/actions/dispatch.js.map +1 -1
  21. package/dist/actions/dispatchContext.js +19 -0
  22. package/dist/actions/dispatchContext.js.map +1 -0
  23. package/dist/actions/emailRecipients.js +38 -8
  24. package/dist/actions/emailRecipients.js.map +1 -1
  25. package/dist/actions/emailRender.d.ts +27 -0
  26. package/dist/actions/fromAddresses.d.ts +19 -1
  27. package/dist/actions/fromAddresses.js +66 -9
  28. package/dist/actions/fromAddresses.js.map +1 -1
  29. package/dist/actions/recipientSources.d.ts +23 -0
  30. package/dist/actions/recipientSources.js +11 -0
  31. package/dist/actions/recipientSources.js.map +1 -0
  32. package/dist/actions/registry.js +3 -1
  33. package/dist/actions/registry.js.map +1 -1
  34. package/dist/actions/runActions.d.ts +2 -0
  35. package/dist/actions/runActions.js +13 -8
  36. package/dist/actions/runActions.js.map +1 -1
  37. package/dist/actions/sign.js.map +1 -1
  38. package/dist/actions/submissionContext.d.ts +34 -0
  39. package/dist/actions/task.js +43 -16
  40. package/dist/actions/task.js.map +1 -1
  41. package/dist/aggregation/aggregateResponses.js +3 -4
  42. package/dist/aggregation/aggregateResponses.js.map +1 -1
  43. package/dist/aggregation/resolveResultsRequest.d.ts +6 -0
  44. package/dist/aggregation/resolveResultsRequest.js +69 -26
  45. package/dist/aggregation/resolveResultsRequest.js.map +1 -1
  46. package/dist/calc/computeCalcFields.d.ts +5 -3
  47. package/dist/calc/computeCalcFields.js +4 -3
  48. package/dist/calc/computeCalcFields.js.map +1 -1
  49. package/dist/calc/evaluate.d.ts +26 -3
  50. package/dist/calc/evaluate.js +33 -11
  51. package/dist/calc/evaluate.js.map +1 -1
  52. package/dist/calc/formatCalc.d.ts +11 -0
  53. package/dist/calc/formatCalc.js +35 -0
  54. package/dist/calc/formatCalc.js.map +1 -0
  55. package/dist/calc/formatCalcValue.d.ts +17 -0
  56. package/dist/calc/formatCalcValue.js +17 -0
  57. package/dist/calc/formatCalcValue.js.map +1 -0
  58. package/dist/calc/normalizeCalc.d.ts +17 -3
  59. package/dist/calc/normalizeCalc.js +39 -17
  60. package/dist/calc/normalizeCalc.js.map +1 -1
  61. package/dist/calc/registry.d.ts +43 -0
  62. package/dist/calc/registry.js +27 -0
  63. package/dist/calc/registry.js.map +1 -0
  64. package/dist/calc/resolveCalcContext.d.ts +36 -0
  65. package/dist/calc/resolveCalcContext.js +87 -0
  66. package/dist/calc/resolveCalcContext.js.map +1 -0
  67. package/dist/calc/types.d.ts +19 -4
  68. package/dist/calc/types.js +3 -2
  69. package/dist/calc/types.js.map +1 -1
  70. package/dist/client/ByteSizeField.js +11 -8
  71. package/dist/client/ByteSizeField.js.map +1 -1
  72. package/dist/client/CalcExpressionBuilder.d.ts +20 -0
  73. package/dist/client/CalcExpressionBuilder.js +888 -0
  74. package/dist/client/CalcExpressionBuilder.js.map +1 -0
  75. package/dist/client/ClosePollButton.js +3 -3
  76. package/dist/client/ClosePollButton.js.map +1 -1
  77. package/dist/client/CondensedArray.d.ts +2 -2
  78. package/dist/client/CondensedArray.js +5 -7
  79. package/dist/client/CondensedArray.js.map +1 -1
  80. package/dist/client/ConditionBuilder.js +5 -7
  81. package/dist/client/ConditionBuilder.js.map +1 -1
  82. package/dist/client/ConditionRow.js +3 -3
  83. package/dist/client/ConditionRow.js.map +1 -1
  84. package/dist/client/ConsentBlockLabel.js +2 -2
  85. package/dist/client/ConsentBlockLabel.js.map +1 -1
  86. package/dist/client/ConsentRetentionNotice.d.ts +11 -0
  87. package/dist/client/ConsentRetentionNotice.js +23 -0
  88. package/dist/client/ConsentRetentionNotice.js.map +1 -0
  89. package/dist/client/EndpointOptionsSelect.d.ts +17 -7
  90. package/dist/client/EndpointOptionsSelect.js +18 -14
  91. package/dist/client/EndpointOptionsSelect.js.map +1 -1
  92. package/dist/client/FieldBlockLabel.js +2 -2
  93. package/dist/client/FieldBlockLabel.js.map +1 -1
  94. package/dist/client/FieldNameSelect.d.ts +1 -0
  95. package/dist/client/FieldNameSelect.js +2 -4
  96. package/dist/client/FieldNameSelect.js.map +1 -1
  97. package/dist/client/FlowBuilder.js +31 -23
  98. package/dist/client/FlowBuilder.js.map +1 -1
  99. package/dist/client/FormConditionField.js +0 -1
  100. package/dist/client/FormConditionField.js.map +1 -1
  101. package/dist/client/RecipientsSelect.d.ts +9 -2
  102. package/dist/client/RecipientsSelect.js +31 -10
  103. package/dist/client/RecipientsSelect.js.map +1 -1
  104. package/dist/client/admin.css +345 -72
  105. package/dist/client/endpointOptions.d.ts +11 -0
  106. package/dist/client/endpointOptions.js +17 -8
  107. package/dist/client/endpointOptions.js.map +1 -1
  108. package/dist/collections/formSubmissions.js +145 -51
  109. package/dist/collections/formSubmissions.js.map +1 -1
  110. package/dist/collections/forms.js +170 -65
  111. package/dist/collections/forms.js.map +1 -1
  112. package/dist/collections/formsEndpoints.js +31 -26
  113. package/dist/collections/formsEndpoints.js.map +1 -1
  114. package/dist/collections/settingsFields.d.ts +32 -0
  115. package/dist/collections/settingsFields.js +55 -0
  116. package/dist/collections/settingsFields.js.map +1 -0
  117. package/dist/consent/captureConsent.d.ts +2 -1
  118. package/dist/consent/captureConsent.js +4 -1
  119. package/dist/consent/captureConsent.js.map +1 -1
  120. package/dist/consent/consentSourcesField.d.ts +7 -1
  121. package/dist/consent/consentSourcesField.js +15 -1
  122. package/dist/consent/consentSourcesField.js.map +1 -1
  123. package/dist/consent/effectiveStatement.js +16 -0
  124. package/dist/consent/effectiveStatement.js.map +1 -0
  125. package/dist/consent/resolveConsentSourcesRequest.js +2 -2
  126. package/dist/consent/resolveConsentSourcesRequest.js.map +1 -1
  127. package/dist/consent/resolveConsentStatements.js +3 -1
  128. package/dist/consent/resolveConsentStatements.js.map +1 -1
  129. package/dist/consent/resolvePublishedVersionRef.js +1 -0
  130. package/dist/consent/resolvePublishedVersionRef.js.map +1 -1
  131. package/dist/consent/types.d.ts +8 -0
  132. package/dist/context/formContext.d.ts +30 -0
  133. package/dist/context/formContext.js +54 -0
  134. package/dist/context/formContext.js.map +1 -0
  135. package/dist/email/departmentsField.d.ts +6 -1
  136. package/dist/email/departmentsField.js +6 -1
  137. package/dist/email/departmentsField.js.map +1 -1
  138. package/dist/exports/client.d.ts +3 -1
  139. package/dist/exports/client.js +3 -1
  140. package/dist/exports/i18n.d.ts +14 -2
  141. package/dist/exports/i18n.js +14 -2
  142. package/dist/exports/react.d.ts +23 -5
  143. package/dist/exports/react.js +17 -1
  144. package/dist/exports/rsc.d.ts +4 -1
  145. package/dist/exports/rsc.js +7 -4
  146. package/dist/exports/types.d.ts +4 -3
  147. package/dist/fields/buildFieldBlocks.js +2 -1
  148. package/dist/fields/buildFieldBlocks.js.map +1 -1
  149. package/dist/fields/builtin/calculation.d.ts +17 -0
  150. package/dist/fields/builtin/calculation.js +70 -127
  151. package/dist/fields/builtin/calculation.js.map +1 -1
  152. package/dist/fields/builtin/checkbox.js +15 -0
  153. package/dist/fields/builtin/checkbox.js.map +1 -1
  154. package/dist/fields/builtin/consent.js +21 -1
  155. package/dist/fields/builtin/consent.js.map +1 -1
  156. package/dist/fields/builtin/email.js +7 -0
  157. package/dist/fields/builtin/email.js.map +1 -1
  158. package/dist/fields/builtin/index.d.ts +6 -2
  159. package/dist/fields/builtin/index.js +9 -4
  160. package/dist/fields/builtin/index.js.map +1 -1
  161. package/dist/fields/builtin/select.js +20 -1
  162. package/dist/fields/builtin/select.js.map +1 -1
  163. package/dist/fields/builtin/text.js +7 -0
  164. package/dist/fields/builtin/text.js.map +1 -1
  165. package/dist/fields/instanceOptions.js +1 -1
  166. package/dist/fields/instanceOptions.js.map +1 -1
  167. package/dist/fields/sharedConfig.js +15 -11
  168. package/dist/fields/sharedConfig.js.map +1 -1
  169. package/dist/fields/types.d.ts +8 -2
  170. package/dist/form/findFormAtLocale.d.ts +30 -0
  171. package/dist/form/findFormAtLocale.js +88 -0
  172. package/dist/form/findFormAtLocale.js.map +1 -0
  173. package/dist/form/pollState.d.ts +2 -1
  174. package/dist/form/pollState.js.map +1 -1
  175. package/dist/form/toFormDocument.d.ts +8 -0
  176. package/dist/form/toFormDocument.js +3 -1
  177. package/dist/form/toFormDocument.js.map +1 -1
  178. package/dist/form/types.d.ts +9 -1
  179. package/dist/index.d.ts +22 -6
  180. package/dist/index.js +63 -17
  181. package/dist/index.js.map +1 -1
  182. package/dist/options.d.ts +113 -4
  183. package/dist/plugin/collectionSlugs.d.ts +28 -0
  184. package/dist/plugin/collectionSlugs.js +65 -0
  185. package/dist/plugin/collectionSlugs.js.map +1 -0
  186. package/dist/plugin/customState.js +1 -1
  187. package/dist/plugin/customState.js.map +1 -1
  188. package/dist/plugin/registerCollections.js +38 -21
  189. package/dist/plugin/registerCollections.js.map +1 -1
  190. package/dist/poll/closeJob.d.ts +4 -3
  191. package/dist/poll/closeJob.js +13 -10
  192. package/dist/poll/closeJob.js.map +1 -1
  193. package/dist/poll/outcomeBeforeChange.js +2 -2
  194. package/dist/poll/outcomeBeforeChange.js.map +1 -1
  195. package/dist/poll/pollTypeRegistry.js +1 -1
  196. package/dist/poll/resolvePollCloseRequest.js +5 -4
  197. package/dist/poll/resolvePollCloseRequest.js.map +1 -1
  198. package/dist/poll/resolvePollOptionsRequest.js +2 -2
  199. package/dist/poll/resolvePollOptionsRequest.js.map +1 -1
  200. package/dist/poll/resolvePollOutcome.d.ts +6 -0
  201. package/dist/poll/resolvePollOutcome.js +20 -6
  202. package/dist/poll/resolvePollOutcome.js.map +1 -1
  203. package/dist/poll/votes/aggregateFromVotes.d.ts +27 -0
  204. package/dist/poll/votes/aggregateFromVotes.js +55 -0
  205. package/dist/poll/votes/aggregateFromVotes.js.map +1 -0
  206. package/dist/poll/votes/answerValues.js +16 -0
  207. package/dist/poll/votes/answerValues.js.map +1 -0
  208. package/dist/poll/votes/bumpPollVote.js +91 -0
  209. package/dist/poll/votes/bumpPollVote.js.map +1 -0
  210. package/dist/poll/votes/recountPollVotes.d.ts +20 -0
  211. package/dist/poll/votes/recountPollVotes.js +63 -0
  212. package/dist/poll/votes/recountPollVotes.js.map +1 -0
  213. package/dist/poll/votes/voteTallyHook.js +76 -0
  214. package/dist/poll/votes/voteTallyHook.js.map +1 -0
  215. package/dist/poll/votes/votesCollection.d.ts +23 -0
  216. package/dist/poll/votes/votesCollection.js +96 -0
  217. package/dist/poll/votes/votesCollection.js.map +1 -0
  218. package/dist/react/Form.d.ts +49 -7
  219. package/dist/react/Form.js +183 -37
  220. package/dist/react/Form.js.map +1 -1
  221. package/dist/react/FormContext.d.ts +10 -2
  222. package/dist/react/FormContext.js.map +1 -1
  223. package/dist/react/FormResults.d.ts +4 -2
  224. package/dist/react/FormResults.js +21 -8
  225. package/dist/react/FormResults.js.map +1 -1
  226. package/dist/react/Poll.d.ts +25 -2
  227. package/dist/react/Poll.js +76 -25
  228. package/dist/react/Poll.js.map +1 -1
  229. package/dist/react/adapters.d.ts +35 -0
  230. package/dist/react/adapters.js +11 -0
  231. package/dist/react/adapters.js.map +1 -0
  232. package/dist/react/captcha/HcaptchaCaptcha.d.ts +4 -1
  233. package/dist/react/captcha/HcaptchaCaptcha.js +2 -2
  234. package/dist/react/captcha/HcaptchaCaptcha.js.map +1 -1
  235. package/dist/react/captcha/RecaptchaCaptcha.d.ts +4 -1
  236. package/dist/react/captcha/RecaptchaCaptcha.js +2 -2
  237. package/dist/react/captcha/RecaptchaCaptcha.js.map +1 -1
  238. package/dist/react/captcha/TurnstileCaptcha.d.ts +4 -1
  239. package/dist/react/captcha/TurnstileCaptcha.js +2 -2
  240. package/dist/react/captcha/TurnstileCaptcha.js.map +1 -1
  241. package/dist/react/captcha/useCaptchaScript.js +23 -5
  242. package/dist/react/captcha/useCaptchaScript.js.map +1 -1
  243. package/dist/react/fetchResults.d.ts +6 -3
  244. package/dist/react/fetchResults.js +10 -5
  245. package/dist/react/fetchResults.js.map +1 -1
  246. package/dist/react/primitives/Checkbox.d.ts +4 -2
  247. package/dist/react/primitives/Checkbox.js +3 -2
  248. package/dist/react/primitives/Checkbox.js.map +1 -1
  249. package/dist/react/primitives/ChoiceGroup.d.ts +40 -0
  250. package/dist/react/primitives/ChoiceGroup.js +33 -0
  251. package/dist/react/primitives/ChoiceGroup.js.map +1 -0
  252. package/dist/react/primitives/FieldShell.d.ts +11 -1
  253. package/dist/react/primitives/FieldShell.js +43 -33
  254. package/dist/react/primitives/FieldShell.js.map +1 -1
  255. package/dist/react/primitives/Input.d.ts +3 -1
  256. package/dist/react/primitives/Input.js +2 -1
  257. package/dist/react/primitives/Input.js.map +1 -1
  258. package/dist/react/renderers/calculation.js +6 -1
  259. package/dist/react/renderers/calculation.js.map +1 -1
  260. package/dist/react/renderers/checkbox.js +2 -1
  261. package/dist/react/renderers/checkbox.js.map +1 -1
  262. package/dist/react/renderers/consent.js +8 -3
  263. package/dist/react/renderers/consent.js.map +1 -1
  264. package/dist/react/renderers/email.js +3 -1
  265. package/dist/react/renderers/email.js.map +1 -1
  266. package/dist/react/renderers/repeater.js +5 -0
  267. package/dist/react/renderers/repeater.js.map +1 -1
  268. package/dist/react/renderers/select.js +20 -2
  269. package/dist/react/renderers/select.js.map +1 -1
  270. package/dist/react/renderers/text.js +3 -1
  271. package/dist/react/renderers/text.js.map +1 -1
  272. package/dist/react/state.d.ts +20 -1
  273. package/dist/react/state.js +57 -4
  274. package/dist/react/state.js.map +1 -1
  275. package/dist/react/submitForm.d.ts +20 -3
  276. package/dist/react/submitForm.js +8 -4
  277. package/dist/react/submitForm.js.map +1 -1
  278. package/dist/react/useCalcValues.d.ts +10 -0
  279. package/dist/react/useCalcValues.js +13 -0
  280. package/dist/react/useCalcValues.js.map +1 -0
  281. package/dist/react/useField.js +7 -5
  282. package/dist/react/useField.js.map +1 -1
  283. package/dist/recall/resolver.js +1 -1
  284. package/dist/recall/resolver.js.map +1 -1
  285. package/dist/spam/constants.js +7 -1
  286. package/dist/spam/constants.js.map +1 -1
  287. package/dist/spam/spamGuard.js +2 -1
  288. package/dist/spam/spamGuard.js.map +1 -1
  289. package/dist/submissions/SubmissionAnswersClient.js +14 -14
  290. package/dist/submissions/SubmissionAnswersClient.js.map +1 -1
  291. package/dist/submissions/createSubmission.d.ts +7 -1
  292. package/dist/submissions/createSubmission.js +10 -5
  293. package/dist/submissions/createSubmission.js.map +1 -1
  294. package/dist/submissions/formIdOf.js +13 -0
  295. package/dist/submissions/formIdOf.js.map +1 -0
  296. package/dist/submissions/resolveVotedSubmission.d.ts +27 -0
  297. package/dist/submissions/resolveVotedSubmission.js +51 -0
  298. package/dist/submissions/resolveVotedSubmission.js.map +1 -0
  299. package/dist/submissions/runSubmission.js +6 -5
  300. package/dist/submissions/runSubmission.js.map +1 -1
  301. package/dist/submissions/submissionLocale.js +39 -0
  302. package/dist/submissions/submissionLocale.js.map +1 -0
  303. package/dist/submissions/validateSubmission.js +125 -79
  304. package/dist/submissions/validateSubmission.js.map +1 -1
  305. package/dist/submissions/verifyContext.js +35 -0
  306. package/dist/submissions/verifyContext.js.map +1 -0
  307. package/dist/submissions/voteChange.js +21 -0
  308. package/dist/submissions/voteChange.js.map +1 -0
  309. package/dist/submissions/voteChangeEndpoint.js +110 -0
  310. package/dist/submissions/voteChangeEndpoint.js.map +1 -0
  311. package/dist/submissions/votedCookie.d.ts +10 -4
  312. package/dist/submissions/votedCookie.js +49 -11
  313. package/dist/submissions/votedCookie.js.map +1 -1
  314. package/dist/translations/ar.d.ts +7 -0
  315. package/dist/translations/ar.js +379 -0
  316. package/dist/translations/ar.js.map +1 -0
  317. package/dist/translations/clientRuntimeKeys.d.ts +17 -0
  318. package/dist/translations/clientRuntimeKeys.js +48 -0
  319. package/dist/translations/clientRuntimeKeys.js.map +1 -0
  320. package/dist/translations/de.d.ts +12 -0
  321. package/dist/translations/de.js +80 -3
  322. package/dist/translations/de.js.map +1 -1
  323. package/dist/translations/en.js +80 -3
  324. package/dist/translations/en.js.map +1 -1
  325. package/dist/translations/es.d.ts +7 -0
  326. package/dist/translations/es.js +379 -0
  327. package/dist/translations/es.js.map +1 -0
  328. package/dist/translations/fr.d.ts +7 -0
  329. package/dist/translations/fr.js +379 -0
  330. package/dist/translations/fr.js.map +1 -0
  331. package/dist/translations/id.d.ts +7 -0
  332. package/dist/translations/id.js +379 -0
  333. package/dist/translations/id.js.map +1 -0
  334. package/dist/translations/index.d.ts +23 -6
  335. package/dist/translations/index.js +31 -6
  336. package/dist/translations/index.js.map +1 -1
  337. package/dist/translations/keys.d.ts +78 -1
  338. package/dist/translations/keys.js +78 -1
  339. package/dist/translations/keys.js.map +1 -1
  340. package/dist/translations/ko.d.ts +7 -0
  341. package/dist/translations/ko.js +379 -0
  342. package/dist/translations/ko.js.map +1 -0
  343. package/dist/translations/makeTranslate.d.ts +7 -3
  344. package/dist/translations/makeTranslate.js +12 -3
  345. package/dist/translations/makeTranslate.js.map +1 -1
  346. package/dist/translations/pt.d.ts +7 -0
  347. package/dist/translations/pt.js +379 -0
  348. package/dist/translations/pt.js.map +1 -0
  349. package/dist/translations/ru.d.ts +7 -0
  350. package/dist/translations/ru.js +379 -0
  351. package/dist/translations/ru.js.map +1 -0
  352. package/dist/translations/uk.d.ts +7 -0
  353. package/dist/translations/uk.js +379 -0
  354. package/dist/translations/uk.js.map +1 -0
  355. package/dist/translations/zh.d.ts +7 -0
  356. package/dist/translations/zh.js +379 -0
  357. package/dist/translations/zh.js.map +1 -0
  358. package/dist/validation/builtin/index.js +2 -0
  359. package/dist/validation/builtin/index.js.map +1 -1
  360. package/dist/validation/builtin/integer.js +15 -0
  361. package/dist/validation/builtin/integer.js.map +1 -0
  362. package/dist/validation/builtin/notAlreadySubmitted.js +5 -3
  363. package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -1
  364. package/package.json +23 -15
  365. package/styles/form-builder.css +84 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,190 @@
1
1
  # @10x-media/form-builder
2
2
 
3
+ ## 4.0.0-alpha.1
4
+
5
+ ### Major Changes
6
+
7
+ - Payload 4 support, on Next.js and TanStack Start. The plugin's own Local API calls (the form read at submit time, published consent versions, queued action and poll-close jobs) pass `overrideAccess: true`, as Payload 4's Local API applies access by default; resolvers you pass the plugin (`consent.sources`, `email.departments`, `email.fromAddresses`, calculation sources, poll option and outcome resolvers) need the same. `forms`, `form-submissions` and the poll votes collection opt out of Payload 4's default versions, and submissions and votes out of its core authorship, so they stay as on Payload 3; `forms` keeps Payload's `createdBy` / `updatedBy`. The poll-close job skips leased jobs through Payload 4's `processingUntil`. The flow and calculation JSON fields describe their generated types through `jsonSchema`. The admin takes the Payload 4 look: add and remove controls are Payload's ghost buttons with its icons, the flow builder moves steps with chevron buttons and uses Payload's blocks header, the calculation builder, condensed arrays, byte-size input and submission answers use Payload 4's tokens and `.form-input`, and the consent retention notice is a default banner. `@payloadcms/*` peers are `^4.0.0-beta.7`. See Upgrading to Payload 4 in the docs.
8
+
9
+ ## 0.1.0-beta.27
10
+
11
+ ### Minor Changes
12
+
13
+ - Collection slugs are now overridable. `overrides.forms.slug`, `overrides.formSubmissions.slug`, and `poll.votes.overrides.slug` rename the plugin's collections, and every internal path follows: the submissions relationship, the actions job and pruning, the vote tally's raw Mongo and Postgres writes, results and outcomes, `notAlreadySubmitted`, and the signed voted cookie. Two plugin collections sharing a slug is a boot error.
14
+
15
+ - `poll.cookiePrefix` renames the `fb-voted-{formId}` cookie (validated as a cookie-name token at boot). `hasVotedCookie` and `votedCookieName` take an optional `payload` to read it.
16
+ - `<Form collections={{ forms, formSubmissions }}>` points the browser transports at renamed collections; it reaches `<Poll>` and the registry form, and a custom `onSubmit` receives it as `input.collection`. `submitForm` and `fetchFormResults` accept `collection`.
17
+ - `collectionSlugsOf(payload)` returns the live slugs for host server code; `DEFAULT_COLLECTION_SLUGS` and the `FormBuilderCollectionSlugs` / `FormCollections` types are exported.
18
+
19
+ Behavioral change: a `slug` set on any of those overrides was previously accepted by the type and silently ignored. It is now honored, so a config that already carries one renames the collection on upgrade. Remove it to keep the default slug.
20
+
21
+ ### Patch Changes
22
+
23
+ - Fix a multi-step focus race: submitting right after a step change could leave focus on the previous step's region, or nowhere, instead of on the first invalid field the form routed back to. React can run a render's effect late, just before the next render, and the late effect was acting on the newer request against DOM that did not contain its target. Each focus request is now handled only by the render it triggered.
24
+
25
+ ## 0.1.0-beta.26
26
+
27
+ ### Minor Changes
28
+
29
+ - A per-form fallback locale, shared recipient lists by default, and no more blank emails.
30
+
31
+ - **Breaking: the email recipient lists are no longer localized by default.** `to`, `cc`, `bcc`, and `replyTo` on `emailTeam` and `confirmation` used to hold a separate list per locale, so a locale the editor never filled in had no recipient and failed `emailTeam` outright. They are now shared across locales. To keep per-locale routing, set `email.localizeRecipients: true` and nothing changes. To adopt the shared default, migrate the stored lists to a single value (typically the default locale's) the way you would for any Payload field that stops being localized.
32
+ - **`fallbackLocale`** chooses the fallback locale per form for every server-side read of it (validating a submission, running its actions, serving poll results), e.g. a tenant's own default locale instead of the config-wide one, or a forced fallback on a host with `localization.fallback: false`. Without it those reads fall back exactly like any Payload read, as your config says. It receives the form as already read, so a non-localized owner such as `form.tenant` needs no read of your own, and the form is read again only when the result differs from the fallback already applied.
33
+ - An email whose subject and body are both empty now fails its action with `empty subject and body` instead of being sent blank.
34
+ - The recipient fields, and the plugin's other custom selects, show Payload's localized badge when they are localized.
35
+
36
+ - Send-time hooks receive the whole form document. Recipient sources, from sources, `richText.serialize`, `email.render`, and a custom action's `run` used to get `form` as `{ id, title }` only, so a host needing any other field (a multi-tenant host's `tenant`) read the same form again in every hook. `form` is now the document the plugin already loaded for the run, at depth 0 (relationships are ids) and in the submission's locale, typed as the exported `SubmissionForm` (`{ id, title? } & Record<string, unknown>`). `id` and `title` are unchanged, so existing hooks keep working; drop the re-reads and read the field off `form` instead.
37
+
38
+ - The submission locale gets its own `submissionLocale` prop.
39
+
40
+ - **Breaking (behavioral): `<Form>`'s `locale` prop is no longer sent with the submission.** The previous beta sent it as `?locale=`, so every host passing `locale` (as the i18n docs teach) had its submissions and emails switch to the visitor's language on upgrade, and a formatting tag like `en-US` silently fell back to the default locale because it is not a content locale code. `locale` is back to formatting and renderer strings only. To store the submission in the visitor's content locale and render its emails in it, pass `submissionLocale` (one of your `localization` codes); a custom `onSubmit` receives it as `locale`. `<Poll>` also sends it with the results request, so option labels in the results match the form.
41
+ - **`createSubmission` takes `locale`**, the server-side counterpart of `submissionLocale`, clamped the same way.
42
+ - **`fetchFormResults` takes `locale`**, and the results endpoint serves option labels in the clamped `?locale=`.
43
+ - Fixed: without localization, a visitor-supplied `?locale=zh_Hant` was stored as is, and `Intl` throws on the underscore, so a field type's `format` could break the submission's admin view. The locale is now stored as a canonical tag (`zh-Hant`), and anything that is not a valid tag becomes `en`.
44
+ - Fixed: creating a submission with your own `req` (`payload.create` or `createSubmission`) no longer rewrites that request's `locale` or `fallbackLocale`. Without localization it stays unset rather than becoming `en`.
45
+ - `email.render`'s `EmailRenderArgs` and a recipient source's `RecipientResolveArgs` now both extend a shared, exported `SubmissionContextArgs`, so a field added for one hook no longer joins the other's API.
46
+
47
+ ## 0.1.0-beta.25
48
+
49
+ ### Minor Changes
50
+
51
+ - Emails follow the visitor's locale. `<Form>` now sends an explicit `locale` prop with the submission as `?locale=` (and hands it to a custom `onSubmit` as `locale`), so the submission stores the visitor's locale instead of the host's default, and the post-submit actions, the confirmation email included, render its subject and body in it. Without the prop nothing changes. The server clamps the visitor-controlled locale before anything reads it: a localized host keeps only its configured locale codes (`all`, `*`, and unknown codes become the default locale), a host without localization keeps any plain language tag and otherwise stores `en`. A custom `richText.serialize` also receives that `locale` and the `actionType` rendering the body (`emailTeam`, `confirmation`, or a custom action's type), so an email wrapper can localize its own strings and give the visitor's confirmation a different layout than the team notification.
52
+
53
+ - Add `email.render`, a hook producing the final html of every `emailTeam` and `confirmation` email from the already serialized body, so a host can wrap emails in a branded, localized layout without re-implementing the rich text pipeline. It receives the serialized `html`, the raw `body`, the interpolated `subject`, the `actionType`, and the submission context (`locale`, `form`, `submissionId`, `values`, `descriptors`, `context`, `payload`, `req`). It runs after `richText.serialize`, so the two compose.
54
+
55
+ ## 0.1.0-beta.24
56
+
57
+ ### Patch Changes
58
+
59
+ - The `./react` client entry no longer imports `node:crypto`. The built-in `notAlreadySubmitted` rule read the vote-change key from `votedCookie`, which signs cookies with `node:crypto`, so every host app shipped a browser crypto polyfill (and its `eval`-based `vm` shim) with the form renderer. The key and `voteChangeTargetOf` now live in a crypto-free module; `votedCookie` re-exports both, so existing imports keep working.
60
+
61
+ ## 0.1.0-beta.23
62
+
63
+ ### Minor Changes
64
+
65
+ - Essential action dispatch, opened up for hosts running real providers behind it.
66
+
67
+ - New `dispatch: { deadlineMs }` plugin option bounds the inline action passes (essential and no-runner fallback); the 5s default is exported as `INLINE_DISPATCH_DEADLINE_MS` so an action can size its own HTTP timeouts under the bound it runs under.
68
+ - A deadline breach is no longer reported as a definite failure: the visitor gets a 504 with an "outcome unknown" message (a definite refusal keeps the 502), and the kept row is stamped `actionUncertain` instead of `actionFailed`. Behavioral change to note: timed-out essential passes previously stamped `actionFailed`; operator filters keyed on that flag should treat `actionUncertain` as "still in flight".
69
+ - Breached essential work is watched to settlement instead of dropped: a late success clears the stamp, runs the skipped rest actions and prune, and emits `submission.created`; a late failure upgrades the stamp to `actionFailed`.
70
+ - `validateConfig` on `ActionDefinition`: a save-time, cross-field check over one stored action instance, with the message attached to the action block (`actions.<index>`) rather than to a single config field.
71
+ - `ActionResult.detail` plus an exported `ActionError(message, detail)` let an action report structured failure context (status code, provider response) without concatenating it into the message; the plugin logs it as a structured field.
72
+
73
+ - More built-in locales for the `formBuilder:` strings.
74
+
75
+ - Added: `es`, `fr`, `id`, `pt`, `ru`, `zh`, `uk`, `ar`, `ko`. Every key is covered in each.
76
+ - Each locale is a complete bundle, so `makeTranslate(locale)` resolves the visitor-facing strings too, not just the admin authoring UI. Every bundle is exported by name from `/i18n` and `/react` beside `bundles`.
77
+
78
+ ## 0.1.0-beta.22
79
+
80
+ ### Minor Changes
81
+
82
+ - Two retention gaps made visible. A non-persisting form that carries a consent field now shows an admin sidebar notice saying the consent proof is discarded with the pruned row, since that combination is only right when the consent record lives elsewhere (a double opt-in provider); it stays a notice, not a save error, because that setup is legitimate. And submissions kept after an essential action failed are now stamped `actionFailed: true` (indexed, read-only), so an operator can filter the accumulated rows, replay the addresses once the provider recovers, and clear them.
83
+
84
+ ## 0.1.0-beta.21
85
+
86
+ ### Minor Changes
87
+
88
+ - Two submit/validate fixes. Actions can declare `essential: true` on `defineAction`: an essential action runs inline before the response (never queued, bounded by the dispatch deadline), its failure or timeout turns the submit into an error the visitor sees with a translated plugin message, the remaining actions are skipped, and the submission is kept even on a `persistSubmissions: false` form so a failed provider handoff never loses what the visitor sent. Fire-and-forget actions are unchanged. And blurring a pristine field no longer reveals its required error: reveal now needs the field to be dirty (changed since mount or the last reset) or its step submitted, which also stops a freshly reset form from showing errors when clicked.
89
+
90
+ ## 0.1.0-beta.20
91
+
92
+ ### Minor Changes
93
+
94
+ - Consent fields gain a Display setting: `checkbox` (the default, unchanged) or `notice`, which renders the statement as passive prose with no control, for flows where submitting is the opt-in ("By subscribing, you agree to our privacy policy"). The server records `agreed: true` on a notice proof regardless of the client payload, `required` is ignored for notices, and the proof carries `display: 'notice'` so audits distinguish the two. `consentSourcesField` rows gain a `noticeStatement` rich text beside `statement`, so one source phrases each presentation naturally while keeping one policy, one version, and one id in every proof; a notice field falls back to `statement` when it is empty. Whichever wording renders is exactly what the proof snapshots, selected through one shared function on both paths.
95
+
96
+ ## 0.1.0-beta.19
97
+
98
+ ### Minor Changes
99
+
100
+ - The from-address and department selects now load their options while a form is still being created, instead of sitting empty until the first save. Both option sets are request-scoped (they depend on who is asking, not on the form document), so their endpoints now live at id-less paths (`GET /api/forms/from-addresses`, `GET /api/forms/departments`); the old `/:id/`-prefixed routes still answer on the same handlers for anything that hardcoded them. `EndpointOptionsSelect` and `RecipientsSelect` gain a `scope: 'document' | 'request'` clientProp (default `'document'`, unchanged behaviour) so a host field backed by its own request-scoped endpoint can opt into the same create-mode loading. Document-scoped selects (poll options, consent sources) are unaffected.
101
+
102
+ ## 0.1.0-beta.18
103
+
104
+ ### Minor Changes
105
+
106
+ - Add `email.fromSources`: senders resolved at send time, for hosts where the from-address is tenant identity rather than per-form configuration. A source stores a stable namespaced value (e.g. `tenant:default`) on the action and re-resolves the actual address on every send with the same run-time arguments a recipient source gets, so a tenant that changes its from-address changes it for every saved form at once. Sources appear in the existing From select ahead of the `fromAddresses` literals; literals keep today's behaviour exactly, including never touching a source at send.
107
+
108
+ ## 0.1.0-beta.17
109
+
110
+ ### Minor Changes
111
+
112
+ - Add `renderResults` to `<Poll>`: a render prop that replaces the built-in `<FormResults>` wherever the poll shows results (after voting, when closed, and for a recorded outcome). It receives the exact `FormResultsProps` the default rendering gets, so hosts can draw result rows from their own data, keyed by each bucket's option value, or wrap `<FormResults>` in their own layout. Omitting the prop changes nothing.
113
+
114
+ ## 0.1.0-beta.16
115
+
116
+ ### Patch Changes
117
+
118
+ - Fix every REST submission returning 500 on beta.15. The vote-change endpoint delegates ordinary creates to Payload's stock create handler, which re-parses the request body the endpoint had already consumed; a consumed fetch body stays non-null, so the second read threw "Body is unusable". The endpoint now hides the spent stream before delegating (the parsed `data`/`file` are already on the request), and finds the stock handler by its own endpoint tag instead of handler identity, so a host-wrapped handler can no longer recurse. Local API submissions were never affected.
119
+
120
+ ## 0.1.0-beta.15
121
+
122
+ ### Minor Changes
123
+
124
+ - Changeable votes for polls via a new `poll.allowChange` checkbox (default off; existing polls are unaffected). With it on, the voted cookie carries the voter's signed submission id, a repeat submit from the same browser updates that submission in place instead of creating another, and the vote tally moves with the changed answer (old value decrements, new one increments, respondents unchanged). Changes run the full create pipeline (validation, spam controls, consent recapture) and are rejected once the poll closes. New `resolveVotedSubmission` (root and `/rsc`) resolves the voter's current pick server-side from the httpOnly cookie; `<Poll currentVote>` highlights it in results ("Your vote" badge, also via `<FormResults currentValues>`) and offers a "Change vote" button that reopens the form prefilled. `onSuccess` now also receives the submitted answer values on its result object.
125
+
126
+ ## 0.1.0-beta.14
127
+
128
+ ### Minor Changes
129
+
130
+ - Add an `adapters` prop for host-owned effects on `<Form>`, `<Poll>`, and the captcha widgets. `adapters.navigate` replaces the post-submit `window.location` redirect so router-based hosts (Next.js App Router, TanStack Router, React Router) can transition in place; the plugin passes its intent (`{ replace: false }`) and never falls back to a hard navigation when the adapter is set. `adapters.voteStorage` overrides the poll voted-flag persistence (or disables it with `false` for hosts on the server-side `poll.votedCookie`). `adapters.loadScript` replaces the captcha vendor script injection for consent-gated or CSP-nonced loading, keeping the per-src cache and evict-on-failure retry. Every member is optional and defaults to the current behavior, so existing consumers are unaffected.
131
+
132
+ ## 0.1.0-beta.13
133
+
134
+ ### Patch Changes
135
+
136
+ - Make the poll tally writer's Postgres import opaque to bundlers.
137
+
138
+ The optional `@payloadcms/db-postgres` peer was loaded via a literal dynamic import, which bundlers resolve at build time: a Mongo host on Turbopack failed `next build` with "Module not found" even though the Postgres branch never runs there (and `serverExternalPackages` does not help, since it governs bundling, not resolution). The specifier is now built at runtime, so no bundler resolves it and the package is only touched when the adapter is actually Postgres. Mongo hosts that worked around this with a resolve alias or stub can remove it.
139
+
140
+ Two upgrade notes from the same integrator round: hosts that had extended the select field block with their own `display` field must remove it on the beta.12 bump (the plugin ships one with identical values, and Payload refuses to boot with two same-name fields); and custom renderers replace the built-ins wholesale, so per-instance settings added in minor releases (`display` variants, `autocomplete`, calculation formatting) must be read by your renderer or an author's choice is silently ignored, now documented in the rendering guide.
141
+
142
+ ## 0.1.0-beta.12
143
+
144
+ ### Minor Changes
145
+
146
+ - Authoring UX round: a visual calculation builder, display variants, an optional-by-default field config surface, and a poll vote tally store.
147
+
148
+ - **Visual calculation builder.** The calculation field's expression is authored in a native left-to-right chain editor: start with a value (Field, Number, Weighted field, Function, or a registered source), add operation steps, optionally finish with a function, with a live readable preview and honest remove affordances throughout. The stored expression tree is unchanged and any API-written expression loads as the equivalent chain; read-only and error states are wired, and field pickers only offer numeric fields (calculations restricted to earlier ones, matching evaluation order).
149
+ - **Calculation extensibility.** A new `calc` option opens the expression engine to host data: `calc.sources` registers named value resolvers (`resolve` returns one number per render/submission, e.g. a tax rate or member discount; `resolveWeights` returns per-option numbers for a chosen field, e.g. each selectable product's live price) that resolve server-side, ride the form document for the client preview, and re-resolve authoritatively at submit; `calc.functions` registers custom calculation functions (client previews additionally accept the same map via `<Form calcFunctions>`). The calculation field also gains display formatting (`decimals`, localized `prefix`/`suffix`) applied in the renderer, admin answers, and email output. New utilities: `defineCalcSource`, `defineCalcFunction`, `resolveCalcContext`, `formatCalc`, `formatCalcValue`, and a `useCalcValues()` hook for composed frontends reading live computed values.
150
+ - **Display variants.** Select fields gain an optional `display` setting (`dropdown` default, `radio`, `buttons`) rendered as an accessible radio group with the invalid-state focus routing intact; checkbox fields gain `checkbox` or `switch`. The `ChoiceGroup` primitive is exported for custom renderers.
151
+ - **Optional field settings.** Field width and select option labels are no longer required: width defaults to full (the renderer already falls back), and a missing or blank option label falls back to the value everywhere (renderer, admin answers, aggregation, recall). Width option labels are localized.
152
+ - **Sidebar form flags with a compose seam.** `multistep`, `pollEnabled`, and `persistSubmissions` are stacked sidebar checkboxes, composed through the new `settings.fields` option so a host can relocate, wrap, extend, or drop them. Forms now registers before form-submissions in the admin nav.
153
+ - **Advanced tab seam.** Field types can append settings to the Advanced tab via `advancedConfig`; text and email use it for an `autocomplete` autofill hint. The `hidden` flag documents that hidden fields are still validated. New `integer` validation rule for number fields; flow validation messages are localized.
154
+ - **Poll vote store (default on).** Votes are counted into a hidden append-only tally collection (`form-poll-votes`) when a submission completes: results reads and `mostVoted` resolution become one indexed find (no scan, no 10k truncation), tallies survive `persistSubmissions: false` and admin deletions (votes are permanent), rows are pure aggregate so a persist-off poll retains zero per-visitor data, and writes are atomic, transaction-joined, and sharded against concurrent write conflicts. `poll.votes: false` restores scan-based results and rejects persist-off polls at save. Exported: `recountPollVotes`, `aggregateFromVotes`, `POLL_VOTES_SLUG`, `RESPONDENTS_VALUE`, `VOTE_SHARDS`. Postgres hosts create the new `form_poll_votes` table with their next migration; `@10x-media/form-builder` declares `@payloadcms/db-postgres` as an optional peer for the tally write path.
155
+
156
+ ## 0.1.0-beta.11
157
+
158
+ ### Minor Changes
159
+
160
+ - Server-resolved recipients with a signed form context, opt-out submission storage, and an action-block collision guard.
161
+
162
+ - **Recipient sources.** A new `email.recipientSources` option registers recipients the plugin resolves server-side at send time, offered in every recipient field (**To**/**Cc**/**Bcc**/**Reply-To**) as their own option group. A source's namespaced `value` cannot collide with an address, its `resolve` returns zero or more addresses (each sanitized to one, so a source cannot inject headers), an empty resolve is dropped, and a send with every recipient empty is skipped rather than sent with an empty **To**. This lets one reusable form email "the person this page is about" without an address ever reaching the browser.
163
+ - **Signed form context.** `signFormContext({ payload, relationTo, value })` (exported from `/rsc` and root) mints a signed, expiring reference to the document a form was rendered for; `<Form context={token} />` carries it, the plugin verifies it on submit (rejecting a tampered or expired one rather than dropping it), stores the verified `{ relationTo, value }` on the submission, and hands it to each source's `resolve`. The reference is signed, not encrypted (the id is already public); it never appears in the answers, the admin answers view, or `{{*}}` body output.
164
+ - **`persistSubmissions`.** A per-form "Store submissions" flag (default on). Unchecked, the plugin deletes the submission after its actions run, for a pure signup form that only POSTs to a provider. Deletion is once, after the whole action pass, regardless of individual action success; pruning does not cascade to uploaded files (documented).
165
+ - **Action-block collision guard.** The plugin now throws a clear error at boot if a registered action `type` collides with a host Payload block slug (which Payload would otherwise silently merge), instead of corrupting the stored action shape. Action block slugs are unchanged, so existing actions keep working.
166
+
167
+ ## 0.1.0-beta.10
168
+
169
+ ### Minor Changes
170
+
171
+ - Locale-correct i18n bundles for host fallbacks, and repeater error re-indexing on row removal.
172
+
173
+ - **Locale bundles are exported for host translators.** `@10x-media/form-builder/react` and `/i18n` now export `de`, `bundles` (`Record<string, TranslationBundle>`), the `TranslationBundle` type, and `clientRuntimeKeys`. `makeTranslate` also accepts a locale code (`makeTranslate('de')`) in addition to a map, so a host bridging its own translator can fall back with `makeTranslate(locale)` (or `makeTranslate(bundles[locale] ?? en)`) and a visitor's locale no longer silently resolves to English for a key the host did not mirror. `clientRuntimeKeys` lists the keys the visitor runtime resolves, for asserting mirror coverage in a test.
174
+ - **Removing a repeater row re-indexes its sub-field errors.** Deleting a row now clears that row's composite validation errors and shifts the surviving rows' errors down, so a server-side error (for example `crew[2].paddlerName`) no longer mis-attributes to a shifted row or lingers unreachably after a delete.
175
+
176
+ ## 0.1.0-beta.9
177
+
178
+ ### Minor Changes
179
+
180
+ - Multi-step keyboard, per-step validation reveal, and focus/accessibility fixes for the `<Form>` runtime.
181
+
182
+ - **Enter advances a multi-step form.** On a non-terminal step, Enter in a single-line field now validates and advances the step (exactly like the Next control), or keeps the visitor on the step and reveals its errors when a field is invalid, instead of doing nothing. On the terminal step Enter submits once (native submit, still behind the existing re-entrancy guard). Textareas (newline), selects (confirm), and buttons stay exempt, and single-step forms keep native Enter-to-submit.
183
+ - **Validation errors reveal per step, not globally.** A field's error now shows only once it is touched or a submit/advance attempt was made for the step it belongs to. Previously any submit attempt flipped one global flag, so navigating forward to a later step surfaced errors on fields the visitor had never reached. Internally `FormState.submitAttempted` becomes `attemptedSteps`, and reveal is keyed to each field's step.
184
+ - **A terminal Submit routes to the first invalid step.** When an earlier step is invalid at submit time (for example a field that becomes required only after a later answer), the form navigates back to the first step that owns an invalid field and focuses it, rather than failing in place on the terminal step.
185
+ - **Focus moves with the step.** Every step change (forward or back) moves focus into the new step, and a blocked advance or submit moves focus to the first invalid field, so keyboard and screen-reader users travel with the form.
186
+ - **Step changes and validation failures are announced.** A polite `aria-live` region announces "Step X of Y" on each change, and a `role="alert"` summary appears when an advance or submit is blocked. New translation keys `form.stepStatus` and `form.stepInvalid` (English and German), overridable through the `translations` option.
187
+
3
188
  ## 0.1.0-beta.8
4
189
 
5
190
  ### Minor Changes
package/README.md CHANGED
@@ -1,10 +1,17 @@
1
+ ![Banner](./assets/banner.jpg)
2
+
1
3
  # @10x-media/form-builder
2
4
 
3
- An end-to-end forms platform for Payload v3: author forms in the admin, validate server-side, render headless on your frontend, collect typed submissions, aggregate results, and act on them. Simple by default for editors, with a definition seam (`defineFormField`, `defineValidationRule`, `defineAction`, and friends) wherever developers need depth, and 100% native to Payload.
5
+ > [!IMPORTANT]
6
+ > **This is the Payload v4 branch.** It targets Payload `4.0.0-beta` on Next.js and TanStack Start and is released under the `alpha` tag (`pnpm add @10x-media/form-builder@alpha`). The Payload v3 version lives on [`main`](https://github.com/10x-media/payload-plugins/tree/main/packages/form-builder) and is released as `beta`.
7
+ >
8
+ > Found a problem with the v4 version? Please [open an issue](https://github.com/10x-media/payload-plugins/issues/new?labels=v4) with the **`v4`** label.
9
+
10
+ An end-to-end forms platform for Payload: author forms in the admin, validate server-side, render headless on your frontend, collect typed submissions, aggregate results, and act on them. Simple by default for editors, with a definition seam (`defineFormField`, `defineValidationRule`, `defineAction`, and friends) wherever developers need depth, and 100% native to Payload.
4
11
 
5
12
  [![npm](https://img.shields.io/npm/v/@10x-media/form-builder?style=flat-square)](https://www.npmjs.com/package/@10x-media/form-builder)
6
13
 
7
- Part of the [@10x-media Payload plugins](https://github.com/10x-media/payload-plugins) collection. In beta: published under the `beta` dist-tag until a stable 1.0.
14
+ Part of the [@10x-media Payload plugins](https://github.com/10x-media/payload-plugins) collection. In alpha on this branch: published under the `alpha` dist-tag until Payload 4 is stable.
8
15
 
9
16
  ## Features
10
17
 
@@ -25,7 +32,7 @@ Part of the [@10x-media Payload plugins](https://github.com/10x-media/payload-pl
25
32
  ## Quick start
26
33
 
27
34
  ```bash
28
- pnpm add @10x-media/form-builder
35
+ pnpm add @10x-media/form-builder@alpha
29
36
  ```
30
37
 
31
38
  ```ts
@@ -71,6 +78,7 @@ Full documentation at [docs.10xmedia.de](https://docs.10xmedia.de/form-builder):
71
78
  - [Spam protection](https://docs.10xmedia.de/form-builder/spam)
72
79
  - [i18n](https://docs.10xmedia.de/form-builder/i18n)
73
80
  - [Collection overrides](https://docs.10xmedia.de/form-builder/customization)
81
+ - [Upgrading to Payload 4](https://docs.10xmedia.de/form-builder/upgrading)
74
82
 
75
83
  ## License
76
84
 
@@ -0,0 +1,18 @@
1
+ //#region src/actions/assertNoBlockCollision.ts
2
+ /**
3
+ * Fail fast at boot when a registered action type collides with a host block slug. Payload resolves
4
+ * blocks globally by slug, so a shared slug makes a saved action document read back with the content
5
+ * block's fields merged in, silently polluting the stored shape and admin tabs. Rather than let that
6
+ * happen quietly, throw a clear error naming the collision so the author renames one side. Action block
7
+ * slugs stay the raw type (renaming them would break every already-stored action), so this detection is
8
+ * the non-breaking guard.
9
+ */
10
+ const assertNoActionBlockCollision = (config, registry) => {
11
+ const hostSlugs = /* @__PURE__ */ new Set();
12
+ for (const block of Array.isArray(config.blocks) ? config.blocks : []) if (block && typeof block === "object" && typeof block.slug === "string") hostSlugs.add(block.slug);
13
+ for (const type of registry.keys()) if (hostSlugs.has(type)) throw new Error(`@10x-media/form-builder: action type "${type}" collides with an existing Payload block slug "${type}". Rename the action type or the block.`);
14
+ };
15
+ //#endregion
16
+ export { assertNoActionBlockCollision };
17
+
18
+ //# sourceMappingURL=assertNoBlockCollision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertNoBlockCollision.js","names":[],"sources":["../../src/actions/assertNoBlockCollision.ts"],"sourcesContent":["import type { Config } from 'payload'\nimport type { ActionRegistry } from './registry'\n\n/**\n * Fail fast at boot when a registered action type collides with a host block slug. Payload resolves\n * blocks globally by slug, so a shared slug makes a saved action document read back with the content\n * block's fields merged in, silently polluting the stored shape and admin tabs. Rather than let that\n * happen quietly, throw a clear error naming the collision so the author renames one side. Action block\n * slugs stay the raw type (renaming them would break every already-stored action), so this detection is\n * the non-breaking guard.\n */\nexport const assertNoActionBlockCollision = (config: Config, registry: ActionRegistry): void => {\n\tconst hostSlugs = new Set<string>()\n\tfor (const block of Array.isArray(config.blocks) ? config.blocks : []) {\n\t\tif (block && typeof block === 'object' && typeof block.slug === 'string') {\n\t\t\thostSlugs.add(block.slug)\n\t\t}\n\t}\n\tfor (const type of registry.keys()) {\n\t\tif (hostSlugs.has(type)) {\n\t\t\tthrow new Error(\n\t\t\t\t`@10x-media/form-builder: action type \"${type}\" collides with an existing Payload block slug \"${type}\". Rename the action type or the block.`\n\t\t\t)\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,gCAAgC,QAAgB,aAAmC;CAC/F,MAAM,4BAAY,IAAI,IAAY;CAClC,KAAK,MAAM,SAAS,MAAM,QAAQ,OAAO,MAAM,IAAI,OAAO,SAAS,CAAC,GACnE,IAAI,SAAS,OAAO,UAAU,YAAY,OAAO,MAAM,SAAS,UAC/D,UAAU,IAAI,MAAM,IAAI;CAG1B,KAAK,MAAM,QAAQ,SAAS,KAAK,GAChC,IAAI,UAAU,IAAI,IAAI,GACrB,MAAM,IAAI,MACT,yCAAyC,KAAK,kDAAkD,KAAK,wCACtG;AAGH"}
@@ -1,13 +1,9 @@
1
1
  import { SubmissionDescriptor, SubmissionValue } from "../../submissions/types.js";
2
2
  import { BodyConverter } from "./converters.js";
3
+ import { SubmissionForm } from "../submissionContext.js";
3
4
  import { PayloadRequest, RichTextField } from "payload";
4
5
 
5
6
  //#region src/actions/body/serializeBody.d.ts
6
- /** Minimal form identity threaded alongside a rendered body (e.g. per-tenant template lookups). */
7
- type SerializeBodyForm = {
8
- id: number | string;
9
- title?: string;
10
- };
11
7
  /** Submission data plus optional converter overrides available while serializing a body. */
12
8
  type BodyContext = {
13
9
  values: SubmissionValue[];
@@ -16,25 +12,31 @@ type BodyContext = {
16
12
  };
17
13
  /**
18
14
  * Args a custom `richText.serialize` replacement receives per rendered body. Always populated by
19
- * `makeRenderBody` (the action-body pipeline): `form` and `req` enable per-tenant template
20
- * lookups or handing the body off to a renderer like react-email.
15
+ * `makeRenderBody` (the action-body pipeline): `form` (the whole document) and `req` enable
16
+ * per-tenant template lookups or handing the body off to a renderer like react-email.
21
17
  */
22
18
  type SerializeBodyArgs = {
23
19
  body: unknown;
24
20
  values: SubmissionValue[];
25
- descriptors: SubmissionDescriptor[];
26
- form: SerializeBodyForm;
21
+ descriptors: SubmissionDescriptor[]; /** The whole form document at depth 0, in the submission's locale; see `SubmissionForm`. */
22
+ form: SubmissionForm;
27
23
  req?: PayloadRequest;
24
+ /**
25
+ * The submission's own stored locale, the one the form (and so `body`) was loaded at. Use it for
26
+ * a wrapper's own strings rather than `req.locale`, which on the queued path is the job runner's.
27
+ */
28
+ locale: string; /** The `blockType` of the action rendering this body (e.g. `emailTeam`, `confirmation`). */
29
+ actionType: string;
28
30
  };
29
31
  /**
30
32
  * Customizes how the plugin's rich text is authored and rendered. `converters` spread over the
31
33
  * default Lexical node converters; `serialize` replaces the whole action-body pipeline (for
32
34
  * non-HTML channels like chat or plain text, or to hand the body plus the submitted `form`/`req`
33
- * off to a renderer like react-email). `editor` is the default Lexical/richText editor for every
34
- * plugin-authored richText field: message content, consent statement, the response message, and
35
- * the action body fields. `bodyEditor` overrides the action body fields specifically (emailTeam
36
- * and confirmation), and `responseEditor` overrides the success `response` message field; both fall
37
- * back to `editor` when absent.
35
+ * off to a renderer like react-email). Wrapping emails in a layout is `email.render`'s job.
36
+ * `editor` is the default Lexical/richText editor for every plugin-authored richText field: message
37
+ * content, consent statement, the response message, and the action body fields. `bodyEditor`
38
+ * overrides the action body fields specifically (emailTeam and confirmation), and `responseEditor`
39
+ * overrides the success `response` message field; both fall back to `editor` when absent.
38
40
  */
39
41
  type RichTextBodyOption = {
40
42
  converters?: Record<string, BodyConverter>;
@@ -58,18 +58,15 @@ const serializeBody = (body, ctx) => {
58
58
  return "";
59
59
  };
60
60
  /** Build the `renderBody` passed to actions, honoring a plugin-level `richText` customization. */
61
- const makeRenderBody = (args) => async (body) => {
62
- if (args.richText?.serialize) return await args.richText.serialize({
63
- body,
64
- values: args.values,
65
- descriptors: args.descriptors,
66
- form: args.form,
67
- req: args.req
61
+ const makeRenderBody = ({ richText, ...args }) => async (body) => {
62
+ if (richText?.serialize) return await richText.serialize({
63
+ ...args,
64
+ body
68
65
  });
69
66
  return serializeBody(body, {
70
67
  values: args.values,
71
68
  descriptors: args.descriptors,
72
- converters: args.richText?.converters
69
+ converters: richText?.converters
73
70
  });
74
71
  };
75
72
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"serializeBody.js","names":[],"sources":["../../../src/actions/body/serializeBody.ts"],"sourcesContent":["import type { PayloadRequest, RichTextField } from 'payload'\nimport { interpolate } from '../../recall/interpolate'\nimport type { SubmissionDescriptor, SubmissionValue } from '../../submissions/types'\nimport type { BodyConverter, BodyRender } from './converters'\nimport { defaultBodyConverters } from './converters'\nimport { escapeHtml } from './escapeHtml'\nimport { serializeSlate } from './serializeSlate'\nimport { renderAllValues, renderAllValuesTable } from './wildcards'\n\n/** Minimal form identity threaded alongside a rendered body (e.g. per-tenant template lookups). */\ntype SerializeBodyForm = { id: number | string; title?: string }\n\n/** Submission data plus optional converter overrides available while serializing a body. */\nexport type BodyContext = {\n\tvalues: SubmissionValue[]\n\tdescriptors: SubmissionDescriptor[]\n\tconverters?: Record<string, BodyConverter>\n}\n\n/**\n * Args a custom `richText.serialize` replacement receives per rendered body. Always populated by\n * `makeRenderBody` (the action-body pipeline): `form` and `req` enable per-tenant template\n * lookups or handing the body off to a renderer like react-email.\n */\nexport type SerializeBodyArgs = {\n\tbody: unknown\n\tvalues: SubmissionValue[]\n\tdescriptors: SubmissionDescriptor[]\n\tform: SerializeBodyForm\n\treq?: PayloadRequest\n}\n\n/**\n * Customizes how the plugin's rich text is authored and rendered. `converters` spread over the\n * default Lexical node converters; `serialize` replaces the whole action-body pipeline (for\n * non-HTML channels like chat or plain text, or to hand the body plus the submitted `form`/`req`\n * off to a renderer like react-email). `editor` is the default Lexical/richText editor for every\n * plugin-authored richText field: message content, consent statement, the response message, and\n * the action body fields. `bodyEditor` overrides the action body fields specifically (emailTeam\n * and confirmation), and `responseEditor` overrides the success `response` message field; both fall\n * back to `editor` when absent.\n */\nexport type RichTextBodyOption = {\n\tconverters?: Record<string, BodyConverter>\n\tserialize?: (args: SerializeBodyArgs) => Promise<string> | string\n\teditor?: RichTextField['editor']\n\tbodyEditor?: RichTextField['editor']\n\tresponseEditor?: RichTextField['editor']\n}\n\n/** Recall resolver over submission values: field name to stringified value, `''` when absent. */\nexport const resolverFor =\n\t(values: SubmissionValue[]) =>\n\t(name: string): string => {\n\t\tconst entry = values.find((value) => value.field === name)\n\t\treturn entry == null ? '' : String(entry.value ?? '')\n\t}\n\nconst renderFor = (ctx: BodyContext): BodyRender => {\n\tconst resolve = resolverFor(ctx.values)\n\tconst htmlResolve = (name: string): string => {\n\t\tif (name === '*') {\n\t\t\treturn renderAllValues(ctx.values, ctx.descriptors)\n\t\t}\n\t\tif (name === '*:table') {\n\t\t\treturn renderAllValuesTable(ctx.values, ctx.descriptors)\n\t\t}\n\t\treturn escapeHtml(resolve(name))\n\t}\n\treturn {\n\t\ttext: (raw) => interpolate(escapeHtml(raw), htmlResolve),\n\t\tinterpolate: (raw) => interpolate(raw, resolve),\n\t}\n}\n\nconst serializeNodes = (\n\tnodes: unknown[],\n\tconverters: Record<string, BodyConverter>,\n\trender: BodyRender\n): string =>\n\tnodes\n\t\t.map((node) => {\n\t\t\tif (node == null || typeof node !== 'object') {\n\t\t\t\treturn ''\n\t\t\t}\n\t\t\tconst lexicalNode = node as Record<string, unknown>\n\t\t\tconst children = Array.isArray(lexicalNode.children)\n\t\t\t\t? serializeNodes(lexicalNode.children, converters, render)\n\t\t\t\t: ''\n\t\t\tconst converter =\n\t\t\t\ttypeof lexicalNode.type === 'string' ? converters[lexicalNode.type] : undefined\n\t\t\treturn converter ? converter({ node: lexicalNode, children, render }) : children\n\t\t})\n\t\t.join('')\n\nconst lexicalRootOf = (body: unknown): Record<string, unknown> | null => {\n\tif (body == null || typeof body !== 'object' || Array.isArray(body)) {\n\t\treturn null\n\t}\n\tconst root = (body as { root?: unknown }).root\n\treturn root != null && typeof root === 'object' ? (root as Record<string, unknown>) : null\n}\n\n/**\n * Serialize an action's `body` config into HTML. A legacy string body is interpolated as-is\n * (pre-richText behavior, no escaping); a Lexical state walks the converter registry; a Slate\n * array uses the minimal legacy serializer; anything else yields `''`. Rendered text is\n * HTML-escaped and supports `{{ name|fallback }}`, `{{*}}`, and `{{*:table}}` tokens.\n */\nexport const serializeBody = (body: unknown, ctx: BodyContext): string => {\n\tif (typeof body === 'string') {\n\t\treturn interpolate(body, resolverFor(ctx.values))\n\t}\n\tconst render = renderFor(ctx)\n\tif (Array.isArray(body)) {\n\t\treturn serializeSlate(body, render)\n\t}\n\tconst root = lexicalRootOf(body)\n\tif (root) {\n\t\tconst converters = { ...defaultBodyConverters, ...(ctx.converters ?? {}) }\n\t\treturn serializeNodes(Array.isArray(root.children) ? root.children : [], converters, render)\n\t}\n\treturn ''\n}\n\n/** Build the `renderBody` passed to actions, honoring a plugin-level `richText` customization. */\nexport const makeRenderBody =\n\t(args: {\n\t\tvalues: SubmissionValue[]\n\t\tdescriptors: SubmissionDescriptor[]\n\t\tform: SerializeBodyForm\n\t\treq?: PayloadRequest\n\t\trichText?: RichTextBodyOption\n\t}) =>\n\tasync (body: unknown): Promise<string> => {\n\t\tif (args.richText?.serialize) {\n\t\t\treturn await args.richText.serialize({\n\t\t\t\tbody,\n\t\t\t\tvalues: args.values,\n\t\t\t\tdescriptors: args.descriptors,\n\t\t\t\tform: args.form,\n\t\t\t\treq: args.req,\n\t\t\t})\n\t\t}\n\t\treturn serializeBody(body, {\n\t\t\tvalues: args.values,\n\t\t\tdescriptors: args.descriptors,\n\t\t\tconverters: args.richText?.converters,\n\t\t})\n\t}\n"],"mappings":";;;;;;;AAmDA,MAAa,eACX,YACA,SAAyB;CACzB,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI;CACzD,OAAO,SAAS,OAAO,KAAK,OAAO,MAAM,SAAS,EAAE;AACrD;AAED,MAAM,aAAa,QAAiC;CACnD,MAAM,UAAU,YAAY,IAAI,MAAM;CACtC,MAAM,eAAe,SAAyB;EAC7C,IAAI,SAAS,KACZ,OAAO,gBAAgB,IAAI,QAAQ,IAAI,WAAW;EAEnD,IAAI,SAAS,WACZ,OAAO,qBAAqB,IAAI,QAAQ,IAAI,WAAW;EAExD,OAAO,WAAW,QAAQ,IAAI,CAAC;CAChC;CACA,OAAO;EACN,OAAO,QAAQ,YAAY,WAAW,GAAG,GAAG,WAAW;EACvD,cAAc,QAAQ,YAAY,KAAK,OAAO;CAC/C;AACD;AAEA,MAAM,kBACL,OACA,YACA,WAEA,MACE,KAAK,SAAS;CACd,IAAI,QAAQ,QAAQ,OAAO,SAAS,UACnC,OAAO;CAER,MAAM,cAAc;CACpB,MAAM,WAAW,MAAM,QAAQ,YAAY,QAAQ,IAChD,eAAe,YAAY,UAAU,YAAY,MAAM,IACvD;CACH,MAAM,YACL,OAAO,YAAY,SAAS,WAAW,WAAW,YAAY,QAAQ,KAAA;CACvE,OAAO,YAAY,UAAU;EAAE,MAAM;EAAa;EAAU;CAAO,CAAC,IAAI;AACzE,CAAC,EACA,KAAK,EAAE;AAEV,MAAM,iBAAiB,SAAkD;CACxE,IAAI,QAAQ,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACjE,OAAO;CAER,MAAM,OAAQ,KAA4B;CAC1C,OAAO,QAAQ,QAAQ,OAAO,SAAS,WAAY,OAAmC;AACvF;;;;;;;AAQA,MAAa,iBAAiB,MAAe,QAA6B;CACzE,IAAI,OAAO,SAAS,UACnB,OAAO,YAAY,MAAM,YAAY,IAAI,MAAM,CAAC;CAEjD,MAAM,SAAS,UAAU,GAAG;CAC5B,IAAI,MAAM,QAAQ,IAAI,GACrB,OAAO,eAAe,MAAM,MAAM;CAEnC,MAAM,OAAO,cAAc,IAAI;CAC/B,IAAI,MAAM;EACT,MAAM,aAAa;GAAE,GAAG;GAAuB,GAAI,IAAI,cAAc,CAAC;EAAG;EACzE,OAAO,eAAe,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAK,WAAW,CAAC,GAAG,YAAY,MAAM;CAC5F;CACA,OAAO;AACR;;AAGA,MAAa,kBACX,SAOD,OAAO,SAAmC;CACzC,IAAI,KAAK,UAAU,WAClB,OAAO,MAAM,KAAK,SAAS,UAAU;EACpC;EACA,QAAQ,KAAK;EACb,aAAa,KAAK;EAClB,MAAM,KAAK;EACX,KAAK,KAAK;CACX,CAAC;CAEF,OAAO,cAAc,MAAM;EAC1B,QAAQ,KAAK;EACb,aAAa,KAAK;EAClB,YAAY,KAAK,UAAU;CAC5B,CAAC;AACF"}
1
+ {"version":3,"file":"serializeBody.js","names":[],"sources":["../../../src/actions/body/serializeBody.ts"],"sourcesContent":["import type { PayloadRequest, RichTextField } from 'payload'\nimport { interpolate } from '../../recall/interpolate'\nimport type { SubmissionDescriptor, SubmissionValue } from '../../submissions/types'\nimport type { SubmissionForm } from '../submissionContext'\nimport type { BodyConverter, BodyRender } from './converters'\nimport { defaultBodyConverters } from './converters'\nimport { escapeHtml } from './escapeHtml'\nimport { serializeSlate } from './serializeSlate'\nimport { renderAllValues, renderAllValuesTable } from './wildcards'\n\n/** Submission data plus optional converter overrides available while serializing a body. */\nexport type BodyContext = {\n\tvalues: SubmissionValue[]\n\tdescriptors: SubmissionDescriptor[]\n\tconverters?: Record<string, BodyConverter>\n}\n\n/**\n * Args a custom `richText.serialize` replacement receives per rendered body. Always populated by\n * `makeRenderBody` (the action-body pipeline): `form` (the whole document) and `req` enable\n * per-tenant template lookups or handing the body off to a renderer like react-email.\n */\nexport type SerializeBodyArgs = {\n\tbody: unknown\n\tvalues: SubmissionValue[]\n\tdescriptors: SubmissionDescriptor[]\n\t/** The whole form document at depth 0, in the submission's locale; see `SubmissionForm`. */\n\tform: SubmissionForm\n\treq?: PayloadRequest\n\t/**\n\t * The submission's own stored locale, the one the form (and so `body`) was loaded at. Use it for\n\t * a wrapper's own strings rather than `req.locale`, which on the queued path is the job runner's.\n\t */\n\tlocale: string\n\t/** The `blockType` of the action rendering this body (e.g. `emailTeam`, `confirmation`). */\n\tactionType: string\n}\n\n/**\n * Customizes how the plugin's rich text is authored and rendered. `converters` spread over the\n * default Lexical node converters; `serialize` replaces the whole action-body pipeline (for\n * non-HTML channels like chat or plain text, or to hand the body plus the submitted `form`/`req`\n * off to a renderer like react-email). Wrapping emails in a layout is `email.render`'s job.\n * `editor` is the default Lexical/richText editor for every plugin-authored richText field: message\n * content, consent statement, the response message, and the action body fields. `bodyEditor`\n * overrides the action body fields specifically (emailTeam and confirmation), and `responseEditor`\n * overrides the success `response` message field; both fall back to `editor` when absent.\n */\nexport type RichTextBodyOption = {\n\tconverters?: Record<string, BodyConverter>\n\tserialize?: (args: SerializeBodyArgs) => Promise<string> | string\n\teditor?: RichTextField['editor']\n\tbodyEditor?: RichTextField['editor']\n\tresponseEditor?: RichTextField['editor']\n}\n\n/** Recall resolver over submission values: field name to stringified value, `''` when absent. */\nexport const resolverFor =\n\t(values: SubmissionValue[]) =>\n\t(name: string): string => {\n\t\tconst entry = values.find((value) => value.field === name)\n\t\treturn entry == null ? '' : String(entry.value ?? '')\n\t}\n\nconst renderFor = (ctx: BodyContext): BodyRender => {\n\tconst resolve = resolverFor(ctx.values)\n\tconst htmlResolve = (name: string): string => {\n\t\tif (name === '*') {\n\t\t\treturn renderAllValues(ctx.values, ctx.descriptors)\n\t\t}\n\t\tif (name === '*:table') {\n\t\t\treturn renderAllValuesTable(ctx.values, ctx.descriptors)\n\t\t}\n\t\treturn escapeHtml(resolve(name))\n\t}\n\treturn {\n\t\ttext: (raw) => interpolate(escapeHtml(raw), htmlResolve),\n\t\tinterpolate: (raw) => interpolate(raw, resolve),\n\t}\n}\n\nconst serializeNodes = (\n\tnodes: unknown[],\n\tconverters: Record<string, BodyConverter>,\n\trender: BodyRender\n): string =>\n\tnodes\n\t\t.map((node) => {\n\t\t\tif (node == null || typeof node !== 'object') {\n\t\t\t\treturn ''\n\t\t\t}\n\t\t\tconst lexicalNode = node as Record<string, unknown>\n\t\t\tconst children = Array.isArray(lexicalNode.children)\n\t\t\t\t? serializeNodes(lexicalNode.children, converters, render)\n\t\t\t\t: ''\n\t\t\tconst converter =\n\t\t\t\ttypeof lexicalNode.type === 'string' ? converters[lexicalNode.type] : undefined\n\t\t\treturn converter ? converter({ node: lexicalNode, children, render }) : children\n\t\t})\n\t\t.join('')\n\nconst lexicalRootOf = (body: unknown): Record<string, unknown> | null => {\n\tif (body == null || typeof body !== 'object' || Array.isArray(body)) {\n\t\treturn null\n\t}\n\tconst root = (body as { root?: unknown }).root\n\treturn root != null && typeof root === 'object' ? (root as Record<string, unknown>) : null\n}\n\n/**\n * Serialize an action's `body` config into HTML. A legacy string body is interpolated as-is\n * (pre-richText behavior, no escaping); a Lexical state walks the converter registry; a Slate\n * array uses the minimal legacy serializer; anything else yields `''`. Rendered text is\n * HTML-escaped and supports `{{ name|fallback }}`, `{{*}}`, and `{{*:table}}` tokens.\n */\nexport const serializeBody = (body: unknown, ctx: BodyContext): string => {\n\tif (typeof body === 'string') {\n\t\treturn interpolate(body, resolverFor(ctx.values))\n\t}\n\tconst render = renderFor(ctx)\n\tif (Array.isArray(body)) {\n\t\treturn serializeSlate(body, render)\n\t}\n\tconst root = lexicalRootOf(body)\n\tif (root) {\n\t\tconst converters = { ...defaultBodyConverters, ...(ctx.converters ?? {}) }\n\t\treturn serializeNodes(Array.isArray(root.children) ? root.children : [], converters, render)\n\t}\n\treturn ''\n}\n\n/** Build the `renderBody` passed to actions, honoring a plugin-level `richText` customization. */\nexport const makeRenderBody =\n\t({ richText, ...args }: Omit<SerializeBodyArgs, 'body'> & { richText?: RichTextBodyOption }) =>\n\tasync (body: unknown): Promise<string> => {\n\t\tif (richText?.serialize) {\n\t\t\treturn await richText.serialize({ ...args, body })\n\t\t}\n\t\treturn serializeBody(body, {\n\t\t\tvalues: args.values,\n\t\t\tdescriptors: args.descriptors,\n\t\t\tconverters: richText?.converters,\n\t\t})\n\t}\n"],"mappings":";;;;;;;AAyDA,MAAa,eACX,YACA,SAAyB;CACzB,MAAM,QAAQ,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI;CACzD,OAAO,SAAS,OAAO,KAAK,OAAO,MAAM,SAAS,EAAE;AACrD;AAED,MAAM,aAAa,QAAiC;CACnD,MAAM,UAAU,YAAY,IAAI,MAAM;CACtC,MAAM,eAAe,SAAyB;EAC7C,IAAI,SAAS,KACZ,OAAO,gBAAgB,IAAI,QAAQ,IAAI,WAAW;EAEnD,IAAI,SAAS,WACZ,OAAO,qBAAqB,IAAI,QAAQ,IAAI,WAAW;EAExD,OAAO,WAAW,QAAQ,IAAI,CAAC;CAChC;CACA,OAAO;EACN,OAAO,QAAQ,YAAY,WAAW,GAAG,GAAG,WAAW;EACvD,cAAc,QAAQ,YAAY,KAAK,OAAO;CAC/C;AACD;AAEA,MAAM,kBACL,OACA,YACA,WAEA,MACE,KAAK,SAAS;CACd,IAAI,QAAQ,QAAQ,OAAO,SAAS,UACnC,OAAO;CAER,MAAM,cAAc;CACpB,MAAM,WAAW,MAAM,QAAQ,YAAY,QAAQ,IAChD,eAAe,YAAY,UAAU,YAAY,MAAM,IACvD;CACH,MAAM,YACL,OAAO,YAAY,SAAS,WAAW,WAAW,YAAY,QAAQ,KAAA;CACvE,OAAO,YAAY,UAAU;EAAE,MAAM;EAAa;EAAU;CAAO,CAAC,IAAI;AACzE,CAAC,EACA,KAAK,EAAE;AAEV,MAAM,iBAAiB,SAAkD;CACxE,IAAI,QAAQ,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACjE,OAAO;CAER,MAAM,OAAQ,KAA4B;CAC1C,OAAO,QAAQ,QAAQ,OAAO,SAAS,WAAY,OAAmC;AACvF;;;;;;;AAQA,MAAa,iBAAiB,MAAe,QAA6B;CACzE,IAAI,OAAO,SAAS,UACnB,OAAO,YAAY,MAAM,YAAY,IAAI,MAAM,CAAC;CAEjD,MAAM,SAAS,UAAU,GAAG;CAC5B,IAAI,MAAM,QAAQ,IAAI,GACrB,OAAO,eAAe,MAAM,MAAM;CAEnC,MAAM,OAAO,cAAc,IAAI;CAC/B,IAAI,MAAM;EACT,MAAM,aAAa;GAAE,GAAG;GAAuB,GAAI,IAAI,cAAc,CAAC;EAAG;EACzE,OAAO,eAAe,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAK,WAAW,CAAC,GAAG,YAAY,MAAM;CAC5F;CACA,OAAO;AACR;;AAGA,MAAa,kBACX,EAAE,UAAU,GAAG,WAChB,OAAO,SAAmC;CACzC,IAAI,UAAU,WACb,OAAO,MAAM,SAAS,UAAU;EAAE,GAAG;EAAM;CAAK,CAAC;CAElD,OAAO,cAAc,MAAM;EAC1B,QAAQ,KAAK;EACb,aAAa,KAAK;EAClB,YAAY,UAAU;CACvB,CAAC;AACF"}
@@ -41,7 +41,8 @@ const buildConfirmation = (options) => {
41
41
  type: "confirmation",
42
42
  label: keys.actionConfirmation,
43
43
  target: () => toField,
44
- resolveTo: (config, resolve) => config.toField ? firstAddress(resolve(config.toField)) : void 0,
44
+ resolveTo: ({ config, resolve }) => config.toField ? firstAddress(resolve(config.toField)) : "",
45
+ hasTarget: (config) => Boolean(config.toField),
45
46
  onMissingTo: "skip"
46
47
  });
47
48
  };
@@ -1 +1 @@
1
- {"version":3,"file":"confirmation.js","names":[],"sources":["../../../src/actions/builtin/confirmation.ts"],"sourcesContent":["import type { Field, PayloadRequest } from 'payload'\nimport { fieldNamesOfType } from '../../fields/fieldNamesOfType'\nimport { keys } from '../../translations/keys'\nimport { asTranslate, labelFor } from '../../translations/server'\nimport { firstAddress } from '../emailRecipients'\nimport { buildEmailAction, type EmailActionConfig, type EmailActionOptions } from './emailAction'\n\ntype ConfirmationConfig = EmailActionConfig & { toField?: string }\n\nconst TO_FIELD_REF = '@10x-media/form-builder/client#FieldNameSelect'\n\n/**\n * Validates the confirmation action's `toField`: unset is fine, otherwise it must name an\n * existing `email`-type field on the form. Exported for unit testing.\n */\nexport const validateToField = (\n\tvalue: unknown,\n\t{ data, req }: { data?: unknown; req: PayloadRequest }\n): string | true => {\n\tif (typeof value !== 'string' || value.length === 0) {\n\t\treturn true\n\t}\n\tconst fields =\n\t\tdata && typeof data === 'object' ? (data as Record<string, unknown>).fields : undefined\n\treturn fieldNamesOfType(fields, ['email']).includes(value)\n\t\t? true\n\t\t: asTranslate(req.t)(keys.validationEmailFieldUnknown)\n}\n\n/**\n * The `confirmation` action: its target is `toField`, naming the form's own email field the\n * confirmation is sent to (a `FieldNameSelect`, not a recipient list). The resolved address is\n * sanitized to a single one (dropping CR/LF header injection and any smuggled extra addresses); an\n * unset field or an unresolvable value is a silent skip. Everything else (from/cc/bcc/replyTo,\n * subject, body, localization) is the shared email-action skeleton.\n */\nexport const buildConfirmation = (options: EmailActionOptions) => {\n\tconst toField: Field = {\n\t\tname: 'toField',\n\t\ttype: 'text',\n\t\tlabel: labelFor(keys.actionConfigToField),\n\t\tadmin: {\n\t\t\twidth: '50%',\n\t\t\tcomponents: {\n\t\t\t\tField: {\n\t\t\t\t\tpath: TO_FIELD_REF,\n\t\t\t\t\tclientProps: { types: ['email'], descriptionKey: keys.actionConfigToFieldDescription },\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tvalidate: validateToField,\n\t}\n\treturn buildEmailAction<ConfirmationConfig>(options, {\n\t\ttype: 'confirmation',\n\t\tlabel: keys.actionConfirmation,\n\t\ttarget: () => toField,\n\t\tresolveTo: (config, resolve) =>\n\t\t\tconfig.toField ? firstAddress(resolve(config.toField)) : undefined,\n\t\tonMissingTo: 'skip',\n\t})\n}\n\nexport const confirmation = buildConfirmation({ localize: true })\n"],"mappings":";;;;;;AASA,MAAM,eAAe;;;;;AAMrB,MAAa,mBACZ,OACA,EAAE,MAAM,UACW;CACnB,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GACjD,OAAO;CAIR,OAAO,iBADN,QAAQ,OAAO,SAAS,WAAY,KAAiC,SAAS,KAAA,GAC/C,CAAC,OAAO,CAAC,EAAE,SAAS,KAAK,IACtD,OACA,YAAY,IAAI,CAAC,EAAE,KAAK,2BAA2B;AACvD;;;;;;;;AASA,MAAa,qBAAqB,YAAgC;CACjE,MAAM,UAAiB;EACtB,MAAM;EACN,MAAM;EACN,OAAO,SAAS,KAAK,mBAAmB;EACxC,OAAO;GACN,OAAO;GACP,YAAY,EACX,OAAO;IACN,MAAM;IACN,aAAa;KAAE,OAAO,CAAC,OAAO;KAAG,gBAAgB,KAAK;IAA+B;GACtF,EACD;EACD;EACA,UAAU;CACX;CACA,OAAO,iBAAqC,SAAS;EACpD,MAAM;EACN,OAAO,KAAK;EACZ,cAAc;EACd,YAAY,QAAQ,YACnB,OAAO,UAAU,aAAa,QAAQ,OAAO,OAAO,CAAC,IAAI,KAAA;EAC1D,aAAa;CACd,CAAC;AACF;AAE4B,kBAAkB,EAAE,UAAU,KAAK,CAAC"}
1
+ {"version":3,"file":"confirmation.js","names":[],"sources":["../../../src/actions/builtin/confirmation.ts"],"sourcesContent":["import type { Field, PayloadRequest } from 'payload'\nimport { fieldNamesOfType } from '../../fields/fieldNamesOfType'\nimport { keys } from '../../translations/keys'\nimport { asTranslate, labelFor } from '../../translations/server'\nimport { firstAddress } from '../emailRecipients'\nimport { buildEmailAction, type EmailActionConfig, type EmailActionOptions } from './emailAction'\n\ntype ConfirmationConfig = EmailActionConfig & { toField?: string }\n\nconst TO_FIELD_REF = '@10x-media/form-builder/client#FieldNameSelect'\n\n/**\n * Validates the confirmation action's `toField`: unset is fine, otherwise it must name an\n * existing `email`-type field on the form. Exported for unit testing.\n */\nexport const validateToField = (\n\tvalue: unknown,\n\t{ data, req }: { data?: unknown; req: PayloadRequest }\n): string | true => {\n\tif (typeof value !== 'string' || value.length === 0) {\n\t\treturn true\n\t}\n\tconst fields =\n\t\tdata && typeof data === 'object' ? (data as Record<string, unknown>).fields : undefined\n\treturn fieldNamesOfType(fields, ['email']).includes(value)\n\t\t? true\n\t\t: asTranslate(req.t)(keys.validationEmailFieldUnknown)\n}\n\n/**\n * The `confirmation` action: its target is `toField`, naming the form's own email field the\n * confirmation is sent to (a `FieldNameSelect`, not a recipient list). The resolved address is\n * sanitized to a single one (dropping CR/LF header injection and any smuggled extra addresses); an\n * unset field or an unresolvable value is a silent skip. Everything else (from/cc/bcc/replyTo,\n * subject, body, localization) is the shared email-action skeleton.\n */\nexport const buildConfirmation = (options: EmailActionOptions) => {\n\tconst toField: Field = {\n\t\tname: 'toField',\n\t\ttype: 'text',\n\t\tlabel: labelFor(keys.actionConfigToField),\n\t\tadmin: {\n\t\t\twidth: '50%',\n\t\t\tcomponents: {\n\t\t\t\tField: {\n\t\t\t\t\tpath: TO_FIELD_REF,\n\t\t\t\t\tclientProps: { types: ['email'], descriptionKey: keys.actionConfigToFieldDescription },\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tvalidate: validateToField,\n\t}\n\treturn buildEmailAction<ConfirmationConfig>(options, {\n\t\ttype: 'confirmation',\n\t\tlabel: keys.actionConfirmation,\n\t\ttarget: () => toField,\n\t\tresolveTo: ({ config, resolve }) =>\n\t\t\tconfig.toField ? firstAddress(resolve(config.toField)) : '',\n\t\thasTarget: (config) => Boolean(config.toField),\n\t\tonMissingTo: 'skip',\n\t})\n}\n\nexport const confirmation = buildConfirmation({ localize: true })\n"],"mappings":";;;;;;AASA,MAAM,eAAe;;;;;AAMrB,MAAa,mBACZ,OACA,EAAE,MAAM,UACW;CACnB,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GACjD,OAAO;CAIR,OAAO,iBADN,QAAQ,OAAO,SAAS,WAAY,KAAiC,SAAS,KAAA,GAC/C,CAAC,OAAO,CAAC,EAAE,SAAS,KAAK,IACtD,OACA,YAAY,IAAI,CAAC,EAAE,KAAK,2BAA2B;AACvD;;;;;;;;AASA,MAAa,qBAAqB,YAAgC;CACjE,MAAM,UAAiB;EACtB,MAAM;EACN,MAAM;EACN,OAAO,SAAS,KAAK,mBAAmB;EACxC,OAAO;GACN,OAAO;GACP,YAAY,EACX,OAAO;IACN,MAAM;IACN,aAAa;KAAE,OAAO,CAAC,OAAO;KAAG,gBAAgB,KAAK;IAA+B;GACtF,EACD;EACD;EACA,UAAU;CACX;CACA,OAAO,iBAAqC,SAAS;EACpD,MAAM;EACN,OAAO,KAAK;EACZ,cAAc;EACd,YAAY,EAAE,QAAQ,cACrB,OAAO,UAAU,aAAa,QAAQ,OAAO,OAAO,CAAC,IAAI;EAC1D,YAAY,WAAW,QAAQ,OAAO,OAAO;EAC7C,aAAa;CACd,CAAC;AACF;AAE4B,kBAAkB,EAAE,UAAU,KAAK,CAAC"}
@@ -1,16 +1,28 @@
1
- import { FromAddressesResolver } from "../fromAddresses.js";
1
+ import { RecipientSourceRegistry } from "../recipientSources.js";
2
+ import { FromAddressSourceRegistry, FromAddressesResolver } from "../fromAddresses.js";
2
3
  import { DepartmentEmailsResolver } from "../../email/departments.js";
3
4
  import { RecipientsConfig } from "../emailRecipients.js";
5
+ import { EmailRender } from "../emailRender.js";
4
6
  import { Field, RichTextField } from "payload";
5
7
 
6
8
  //#region src/actions/builtin/emailAction.d.ts
7
9
  /** The plugin-derived options every built-in email action is built from (was five positional args). */
8
10
  type EmailActionOptions = {
9
11
  localize: boolean;
12
+ /**
13
+ * Localize the recipient lists (`to`, `cc`, `bcc`, `replyTo`) too, so each locale routes to its
14
+ * own addresses (plugin option `email.localizeRecipients`). Off by default: routing is usually
15
+ * the same in every locale, and a list left empty in a locale that does not fall back fails
16
+ * `emailTeam` there. Only applies while `localize` is on.
17
+ */
18
+ localizeRecipients?: boolean;
10
19
  editor?: RichTextField['editor'];
11
- fromAddresses?: FromAddressesResolver;
20
+ fromAddresses?: FromAddressesResolver; /** Send-time-resolved senders offered in the from select (plugin option `email.fromSources`). */
21
+ fromSources?: FromAddressSourceRegistry;
12
22
  departments?: DepartmentEmailsResolver;
13
- recipients?: RecipientsConfig;
23
+ recipients?: RecipientsConfig; /** Server-resolved recipient sources offered in every recipient list (plugin option `email.recipientSources`). */
24
+ recipientSources?: RecipientSourceRegistry; /** Produces the final html from the serialized body (plugin option `email.render`). */
25
+ render?: EmailRender;
14
26
  };
15
27
  //#endregion
16
28
  export { EmailActionOptions };
@@ -2,27 +2,37 @@ import { keys } from "../../translations/keys.js";
2
2
  import { labelFor } from "../../translations/server.js";
3
3
  import { localizedIf } from "../../fields/localizedIf.js";
4
4
  import { interpolate } from "../../recall/interpolate.js";
5
- import { buildRecipientField, resolveRecipients } from "../emailRecipients.js";
5
+ import { buildRecipientField, resolveRecipientEntries } from "../emailRecipients.js";
6
6
  import { resolverFor } from "../body/serializeBody.js";
7
7
  import { defineAction } from "../defineAction.js";
8
- import { buildFromField } from "../fromAddresses.js";
8
+ import { buildFromField, resolveSendFrom } from "../fromAddresses.js";
9
+ import { sourcesByValue } from "../recipientSources.js";
9
10
  //#region src/actions/builtin/emailAction.ts
10
11
  /**
12
+ * Whether serialized body html carries anything beyond markup and whitespace: an empty editor
13
+ * serializes to bare tags, while a lone image or rule is content even without text.
14
+ */
15
+ const hasVisibleContent = (html) => /<(img|hr|table|iframe|video|svg)\b/i.test(html) || html.replace(/<[^>]*>|&nbsp;/g, "").trim() !== "";
16
+ /**
11
17
  * The shared skeleton of the built-in email actions (`emailTeam`, `confirmation`): an identical
12
18
  * config (a first row pairing the action's target with `replyTo`, an optional `from` select, a
13
- * cc/bcc row, a subject, and a rich text body, content and recipient fields carrying `localized`
14
- * when `localize`) and an identical send (interpolate the subject, render the body, resolve
15
- * cc/bcc/replyTo, and hand a single comma-joined string per list to `payload.sendEmail`). Only the
16
- * primary `to` target and its missing-value behavior differ, threaded through `spec`.
19
+ * cc/bcc row, a subject, and a rich text body, content fields carrying `localized` when `localize`
20
+ * and recipient fields only when `localizeRecipients` too) and an identical send (interpolate the
21
+ * subject, render the body, fail on an email with neither, resolve cc/bcc/replyTo, pass the html
22
+ * through `options.render` when set, and hand a single comma-joined string per list to
23
+ * `payload.sendEmail`). Only the primary `to` target and its missing-value behavior differ,
24
+ * threaded through `spec`.
17
25
  */
18
26
  const buildEmailAction = (options, spec) => {
19
- const { localize, editor, fromAddresses, departments, recipients } = options;
27
+ const { localize, localizeRecipients, editor, fromAddresses, fromSources, departments, recipients, recipientSources, render } = options;
28
+ const fromSourcesByValue = sourcesByValue(fromSources);
20
29
  const endpoint = departments ? "departments" : void 0;
21
- const recip = (name, labelKey) => buildRecipientField(name, labelKey, localize, {
30
+ const recip = (name, labelKey) => buildRecipientField(name, labelKey, localize && localizeRecipients === true, {
22
31
  endpoint,
23
32
  recipients,
24
33
  width: "50%",
25
- departments
34
+ departments,
35
+ sources: recipientSources
26
36
  });
27
37
  return defineAction({
28
38
  type: spec.type,
@@ -32,7 +42,7 @@ const buildEmailAction = (options, spec) => {
32
42
  type: "row",
33
43
  fields: [spec.target(recip), recip("replyTo", keys.actionConfigReplyTo)]
34
44
  },
35
- ...fromAddresses ? [buildFromField(fromAddresses)] : [],
45
+ ...fromAddresses || fromSources ? [buildFromField(fromAddresses, fromSources)] : [],
36
46
  {
37
47
  type: "row",
38
48
  fields: [recip("cc", keys.actionConfigCc), recip("bcc", keys.actionConfigBcc)]
@@ -52,24 +62,66 @@ const buildEmailAction = (options, spec) => {
52
62
  ...editor ? { editor } : {}
53
63
  }
54
64
  ],
55
- run: async ({ config, values, payload, renderBody }) => {
65
+ run: async (args) => {
66
+ const { config, values } = args;
56
67
  const resolve = resolverFor(values);
57
- const to = spec.resolveTo(config, resolve);
68
+ const sources = sourcesByValue(recipientSources);
69
+ const sourceArgs = {
70
+ context: args.context,
71
+ values,
72
+ descriptors: args.descriptors,
73
+ form: args.form,
74
+ submissionId: args.submissionId,
75
+ payload: args.payload,
76
+ req: args.req,
77
+ locale: args.locale
78
+ };
79
+ const to = await spec.resolveTo({
80
+ config,
81
+ resolve,
82
+ sources,
83
+ sourceArgs
84
+ });
58
85
  if (!to) {
59
- if (spec.onMissingTo === "throw") throw new Error(`${spec.type}: missing "to" address`);
86
+ if (!spec.hasTarget(config) && spec.onMissingTo === "throw") throw new Error(`${spec.type}: missing "to" address`);
60
87
  return;
61
88
  }
62
- if (typeof payload.sendEmail !== "function") throw new Error(`${spec.type}: no email adapter configured`);
89
+ if (typeof args.payload.sendEmail !== "function") throw new Error(`${spec.type}: no email adapter configured`);
63
90
  const subject = interpolate(config.subject ?? "", resolve);
64
- const html = await renderBody(config.body);
65
- const cc = resolveRecipients(config.cc, resolve);
66
- const bcc = resolveRecipients(config.bcc, resolve);
67
- const replyTo = resolveRecipients(config.replyTo, resolve);
68
- await payload.sendEmail({
91
+ const serialized = await args.renderBody(config.body);
92
+ if (!subject.trim() && !hasVisibleContent(serialized)) throw new Error(`${spec.type}: empty subject and body`);
93
+ const html = render ? await render({
94
+ ...sourceArgs,
95
+ html: serialized,
96
+ body: config.body,
97
+ subject,
98
+ actionType: spec.type
99
+ }) : serialized;
100
+ const cc = (await resolveRecipientEntries(config.cc, {
101
+ resolve,
102
+ sources,
103
+ sourceArgs
104
+ })).join(", ");
105
+ const bcc = (await resolveRecipientEntries(config.bcc, {
106
+ resolve,
107
+ sources,
108
+ sourceArgs
109
+ })).join(", ");
110
+ const replyTo = (await resolveRecipientEntries(config.replyTo, {
111
+ resolve,
112
+ sources,
113
+ sourceArgs
114
+ })).join(", ");
115
+ const from = await resolveSendFrom({
116
+ configured: config.from,
117
+ sources: fromSourcesByValue,
118
+ sourceArgs
119
+ });
120
+ await args.payload.sendEmail({
69
121
  to,
70
122
  subject,
71
123
  html,
72
- ...config.from ? { from: config.from } : {},
124
+ ...from ? { from } : {},
73
125
  ...cc ? { cc } : {},
74
126
  ...bcc ? { bcc } : {},
75
127
  ...replyTo ? { replyTo } : {}