@10x-media/form-builder 0.1.0-beta.1 → 0.1.0-beta.10

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 (546) hide show
  1. package/CHANGELOG.md +293 -0
  2. package/README.md +6 -4
  3. package/dist/actions/body/converters.d.ts +20 -0
  4. package/dist/actions/body/converters.js +57 -0
  5. package/dist/actions/body/converters.js.map +1 -0
  6. package/dist/actions/body/escapeHtml.d.ts +6 -0
  7. package/dist/actions/body/escapeHtml.js +14 -0
  8. package/dist/actions/body/escapeHtml.js.map +1 -0
  9. package/dist/actions/body/serializeBody.d.ts +55 -0
  10. package/dist/actions/body/serializeBody.js +78 -0
  11. package/dist/actions/body/serializeBody.js.map +1 -0
  12. package/dist/actions/body/serializeSlate.js +31 -0
  13. package/dist/actions/body/serializeSlate.js.map +1 -0
  14. package/dist/actions/body/textOfBody.d.ts +13 -0
  15. package/dist/actions/body/textOfBody.js +35 -0
  16. package/dist/actions/body/textOfBody.js.map +1 -0
  17. package/dist/actions/body/wildcards.d.ts +10 -0
  18. package/dist/actions/body/wildcards.js +33 -0
  19. package/dist/actions/body/wildcards.js.map +1 -0
  20. package/dist/actions/buildActionBlocks.js +12 -9
  21. package/dist/actions/buildActionBlocks.js.map +1 -1
  22. package/dist/actions/builtin/confirmation.js +46 -43
  23. package/dist/actions/builtin/confirmation.js.map +1 -1
  24. package/dist/actions/builtin/emailAction.d.ts +17 -0
  25. package/dist/actions/builtin/emailAction.js +83 -0
  26. package/dist/actions/builtin/emailAction.js.map +1 -0
  27. package/dist/actions/builtin/emailTeam.js +14 -38
  28. package/dist/actions/builtin/emailTeam.js.map +1 -1
  29. package/dist/actions/builtin/index.d.ts +16 -1
  30. package/dist/actions/builtin/index.js +21 -7
  31. package/dist/actions/builtin/index.js.map +1 -1
  32. package/dist/actions/builtin/signedWebhook.js +6 -2
  33. package/dist/actions/builtin/signedWebhook.js.map +1 -1
  34. package/dist/actions/defineAction.d.ts +5 -4
  35. package/dist/actions/defineAction.js.map +1 -1
  36. package/dist/actions/dispatch.js +2 -1
  37. package/dist/actions/dispatch.js.map +1 -1
  38. package/dist/actions/emailRecipients.d.ts +12 -0
  39. package/dist/actions/emailRecipients.js +116 -0
  40. package/dist/actions/emailRecipients.js.map +1 -0
  41. package/dist/actions/fromAddresses.d.ts +21 -0
  42. package/dist/actions/fromAddresses.js +74 -0
  43. package/dist/actions/fromAddresses.js.map +1 -0
  44. package/dist/actions/registry.d.ts +2 -1
  45. package/dist/actions/registry.js +2 -6
  46. package/dist/actions/registry.js.map +1 -1
  47. package/dist/actions/runActions.js +10 -1
  48. package/dist/actions/runActions.js.map +1 -1
  49. package/dist/actions/task.js +20 -15
  50. package/dist/actions/task.js.map +1 -1
  51. package/dist/aggregation/aggregateResponses.d.ts +9 -0
  52. package/dist/aggregation/aggregateResponses.js +8 -14
  53. package/dist/aggregation/aggregateResponses.js.map +1 -1
  54. package/dist/aggregation/resolveResultsRequest.d.ts +35 -6
  55. package/dist/aggregation/resolveResultsRequest.js +68 -11
  56. package/dist/aggregation/resolveResultsRequest.js.map +1 -1
  57. package/dist/calc/computeCalcFields.js +2 -1
  58. package/dist/calc/computeCalcFields.js.map +1 -1
  59. package/dist/calc/evaluate.js +1 -2
  60. package/dist/calc/evaluate.js.map +1 -1
  61. package/dist/calc/normalizeCalc.js +6 -19
  62. package/dist/calc/normalizeCalc.js.map +1 -1
  63. package/dist/calc/types.d.ts +8 -2
  64. package/dist/calc/types.js +22 -0
  65. package/dist/calc/types.js.map +1 -0
  66. package/dist/client/ByteSizeField.d.ts +29 -0
  67. package/dist/client/ByteSizeField.js +58 -0
  68. package/dist/client/ByteSizeField.js.map +1 -0
  69. package/dist/client/ClosePollButton.d.ts +15 -0
  70. package/dist/client/ClosePollButton.js +80 -0
  71. package/dist/client/ClosePollButton.js.map +1 -0
  72. package/dist/client/CondensedArray.d.ts +15 -0
  73. package/dist/client/CondensedArray.js +97 -0
  74. package/dist/client/CondensedArray.js.map +1 -0
  75. package/dist/client/ConditionBuilder.js +2 -1
  76. package/dist/client/ConditionBuilder.js.map +1 -1
  77. package/dist/client/ConsentBlockLabel.d.ts +15 -0
  78. package/dist/client/ConsentBlockLabel.js +71 -0
  79. package/dist/client/ConsentBlockLabel.js.map +1 -0
  80. package/dist/client/ConsentSourceRowLabel.d.ts +9 -0
  81. package/dist/client/ConsentSourceRowLabel.js +21 -0
  82. package/dist/client/ConsentSourceRowLabel.js.map +1 -0
  83. package/dist/client/EndpointOptionsSelect.d.ts +46 -0
  84. package/dist/client/EndpointOptionsSelect.js +106 -0
  85. package/dist/client/EndpointOptionsSelect.js.map +1 -0
  86. package/dist/client/FieldBlockLabel.d.ts +18 -0
  87. package/dist/client/FieldBlockLabel.js +34 -0
  88. package/dist/client/FieldBlockLabel.js.map +1 -0
  89. package/dist/client/FieldNameSelect.d.ts +37 -0
  90. package/dist/client/FieldNameSelect.js +72 -0
  91. package/dist/client/FieldNameSelect.js.map +1 -0
  92. package/dist/client/FlowBuilder.d.ts +2 -2
  93. package/dist/client/FlowBuilder.js +137 -88
  94. package/dist/client/FlowBuilder.js.map +1 -1
  95. package/dist/client/FormConditionField.js +1 -4
  96. package/dist/client/FormConditionField.js.map +1 -1
  97. package/dist/client/RecipientsSelect.d.ts +31 -0
  98. package/dist/client/RecipientsSelect.js +174 -0
  99. package/dist/client/RecipientsSelect.js.map +1 -0
  100. package/dist/client/RuleDescription.d.ts +21 -0
  101. package/dist/client/RuleDescription.js +19 -0
  102. package/dist/client/RuleDescription.js.map +1 -0
  103. package/dist/client/admin.css +275 -0
  104. package/dist/client/endpointOptions.js +29 -0
  105. package/dist/client/endpointOptions.js.map +1 -0
  106. package/dist/client/flowAuthoring.js +142 -0
  107. package/dist/client/flowAuthoring.js.map +1 -0
  108. package/dist/client/synthesizeClientField.js +21 -10
  109. package/dist/client/synthesizeClientField.js.map +1 -1
  110. package/dist/client/toStaticLabel.js +13 -0
  111. package/dist/client/toStaticLabel.js.map +1 -0
  112. package/dist/collections/buttonFields.d.ts +34 -0
  113. package/dist/collections/buttonFields.js +35 -0
  114. package/dist/collections/buttonFields.js.map +1 -0
  115. package/dist/collections/cells/FieldCountCell.d.ts +15 -0
  116. package/dist/collections/cells/FieldCountCell.js +18 -0
  117. package/dist/collections/cells/FieldCountCell.js.map +1 -0
  118. package/dist/collections/cells/FlowStepsCell.d.ts +14 -0
  119. package/dist/collections/cells/FlowStepsCell.js +17 -0
  120. package/dist/collections/cells/FlowStepsCell.js.map +1 -0
  121. package/dist/collections/formSubmissions.js +108 -42
  122. package/dist/collections/formSubmissions.js.map +1 -1
  123. package/dist/collections/forms.js +409 -114
  124. package/dist/collections/forms.js.map +1 -1
  125. package/dist/collections/formsEndpoints.js +101 -0
  126. package/dist/collections/formsEndpoints.js.map +1 -0
  127. package/dist/collections/redirectFields.d.ts +29 -0
  128. package/dist/conditions/conditionType.js +9 -2
  129. package/dist/conditions/conditionType.js.map +1 -1
  130. package/dist/conditions/evaluate.js +1 -1
  131. package/dist/conditions/evaluate.js.map +1 -1
  132. package/dist/conditions/fieldTypes.d.ts +3 -1
  133. package/dist/conditions/fieldTypes.js +4 -1
  134. package/dist/conditions/fieldTypes.js.map +1 -1
  135. package/dist/conditions/normalizeConditions.js +20 -6
  136. package/dist/conditions/normalizeConditions.js.map +1 -1
  137. package/dist/consent/applyConsentStatements.d.ts +14 -0
  138. package/dist/consent/applyConsentStatements.js +17 -0
  139. package/dist/consent/applyConsentStatements.js.map +1 -0
  140. package/dist/consent/captureConsent.d.ts +38 -11
  141. package/dist/consent/captureConsent.js +60 -13
  142. package/dist/consent/captureConsent.js.map +1 -1
  143. package/dist/consent/consentSourcesField.d.ts +66 -0
  144. package/dist/consent/consentSourcesField.js +90 -0
  145. package/dist/consent/consentSourcesField.js.map +1 -0
  146. package/dist/consent/resolveConsentEntries.d.ts +24 -0
  147. package/dist/consent/resolveConsentEntries.js +40 -0
  148. package/dist/consent/resolveConsentEntries.js.map +1 -0
  149. package/dist/consent/resolveConsentSourcesRequest.d.ts +37 -0
  150. package/dist/consent/resolveConsentSourcesRequest.js +54 -0
  151. package/dist/consent/resolveConsentSourcesRequest.js.map +1 -0
  152. package/dist/consent/resolveConsentStatements.d.ts +45 -0
  153. package/dist/consent/resolveConsentStatements.js +44 -0
  154. package/dist/consent/resolveConsentStatements.js.map +1 -0
  155. package/dist/consent/resolvePublishedVersionRef.d.ts +17 -11
  156. package/dist/consent/resolvePublishedVersionRef.js +13 -10
  157. package/dist/consent/resolvePublishedVersionRef.js.map +1 -1
  158. package/dist/consent/types.d.ts +61 -0
  159. package/dist/email/departments.d.ts +59 -0
  160. package/dist/email/departments.js +87 -0
  161. package/dist/email/departments.js.map +1 -0
  162. package/dist/email/departmentsField.d.ts +53 -0
  163. package/dist/email/departmentsField.js +73 -0
  164. package/dist/email/departmentsField.js.map +1 -0
  165. package/dist/exports/client.d.ts +13 -1
  166. package/dist/exports/client.js +13 -1
  167. package/dist/exports/i18n.d.ts +5 -2
  168. package/dist/exports/i18n.js +5 -2
  169. package/dist/exports/react.d.ts +26 -8
  170. package/dist/exports/react.js +19 -3
  171. package/dist/exports/rsc.d.ts +8 -1
  172. package/dist/exports/rsc.js +8 -1
  173. package/dist/exports/types.d.ts +19 -10
  174. package/dist/fields/buildFieldBlocks.js +53 -19
  175. package/dist/fields/buildFieldBlocks.js.map +1 -1
  176. package/dist/fields/builtin/calculation.js +122 -2
  177. package/dist/fields/builtin/calculation.js.map +1 -1
  178. package/dist/fields/builtin/checkbox.js +8 -0
  179. package/dist/fields/builtin/checkbox.js.map +1 -1
  180. package/dist/fields/builtin/consent.js +30 -15
  181. package/dist/fields/builtin/consent.js.map +1 -1
  182. package/dist/fields/builtin/country.d.ts +13 -0
  183. package/dist/fields/builtin/country.js +30 -0
  184. package/dist/fields/builtin/country.js.map +1 -0
  185. package/dist/fields/builtin/date.js +31 -0
  186. package/dist/fields/builtin/date.js.map +1 -0
  187. package/dist/fields/builtin/email.js +1 -1
  188. package/dist/fields/builtin/email.js.map +1 -1
  189. package/dist/fields/builtin/file.d.ts +15 -0
  190. package/dist/fields/builtin/file.js +95 -8
  191. package/dist/fields/builtin/file.js.map +1 -1
  192. package/dist/fields/builtin/index.d.ts +26 -0
  193. package/dist/fields/builtin/index.js +30 -6
  194. package/dist/fields/builtin/index.js.map +1 -1
  195. package/dist/fields/builtin/message.js +30 -0
  196. package/dist/fields/builtin/message.js.map +1 -0
  197. package/dist/fields/builtin/repeater.js +49 -0
  198. package/dist/fields/builtin/repeater.js.map +1 -0
  199. package/dist/fields/builtin/select.js +8 -3
  200. package/dist/fields/builtin/select.js.map +1 -1
  201. package/dist/fields/builtin/state.d.ts +13 -0
  202. package/dist/fields/builtin/state.js +30 -0
  203. package/dist/fields/builtin/state.js.map +1 -0
  204. package/dist/fields/data/regions.d.ts +21 -0
  205. package/dist/fields/data/regions.js +1238 -0
  206. package/dist/fields/data/regions.js.map +1 -0
  207. package/dist/fields/fieldKey.d.ts +15 -0
  208. package/dist/fields/fieldKey.js +16 -0
  209. package/dist/fields/fieldKey.js.map +1 -0
  210. package/dist/fields/fieldNamesOfType.js +30 -0
  211. package/dist/fields/fieldNamesOfType.js.map +1 -0
  212. package/dist/fields/instanceOptions.js +20 -0
  213. package/dist/fields/instanceOptions.js.map +1 -0
  214. package/dist/fields/localizedIf.d.ts +13 -0
  215. package/dist/fields/localizedIf.js +12 -0
  216. package/dist/fields/localizedIf.js.map +1 -0
  217. package/dist/fields/registry.d.ts +3 -1
  218. package/dist/fields/registry.js +23 -8
  219. package/dist/fields/registry.js.map +1 -1
  220. package/dist/fields/sharedConfig.js +120 -58
  221. package/dist/fields/sharedConfig.js.map +1 -1
  222. package/dist/fields/types.d.ts +71 -7
  223. package/dist/flow/engine.d.ts +6 -4
  224. package/dist/flow/engine.js +11 -6
  225. package/dist/flow/engine.js.map +1 -1
  226. package/dist/flow/normalizeFlow.js +28 -9
  227. package/dist/flow/normalizeFlow.js.map +1 -1
  228. package/dist/flow/stepLabel.js +15 -0
  229. package/dist/flow/stepLabel.js.map +1 -0
  230. package/dist/flow/types.d.ts +12 -3
  231. package/dist/flow/types.js +11 -0
  232. package/dist/flow/types.js.map +1 -0
  233. package/dist/form/pollState.d.ts +22 -0
  234. package/dist/form/pollState.js +17 -0
  235. package/dist/form/pollState.js.map +1 -0
  236. package/dist/form/toFormDocument.d.ts +102 -0
  237. package/dist/form/toFormDocument.js +87 -0
  238. package/dist/form/toFormDocument.js.map +1 -0
  239. package/dist/form/types.d.ts +65 -0
  240. package/dist/index.d.ts +53 -39
  241. package/dist/index.js +85 -23
  242. package/dist/index.js.map +1 -1
  243. package/dist/options.d.ts +229 -0
  244. package/dist/plugin/applyRegistryConfig.d.ts +11 -0
  245. package/dist/plugin/applyRegistryConfig.js +20 -0
  246. package/dist/plugin/applyRegistryConfig.js.map +1 -0
  247. package/dist/plugin/collectionOverrides.d.ts +22 -0
  248. package/dist/plugin/customState.js +26 -0
  249. package/dist/plugin/customState.js.map +1 -0
  250. package/dist/plugin/registerCollections.js +40 -20
  251. package/dist/plugin/registerCollections.js.map +1 -1
  252. package/dist/plugin/uploadsCollection.d.ts +16 -0
  253. package/dist/plugin/uploadsCollection.js +53 -0
  254. package/dist/plugin/uploadsCollection.js.map +1 -0
  255. package/dist/poll/applyPollOptions.js +18 -0
  256. package/dist/poll/applyPollOptions.js.map +1 -0
  257. package/dist/poll/buildPollOptionSourceFields.js +50 -0
  258. package/dist/poll/buildPollOptionSourceFields.js.map +1 -0
  259. package/dist/poll/closeJob.d.ts +52 -0
  260. package/dist/poll/closeJob.js +119 -0
  261. package/dist/poll/closeJob.js.map +1 -0
  262. package/dist/poll/definePollOptionSource.d.ts +44 -0
  263. package/dist/poll/definePollOptionSource.js +6 -0
  264. package/dist/poll/definePollOptionSource.js.map +1 -0
  265. package/dist/poll/definePollType.d.ts +34 -0
  266. package/dist/poll/definePollType.js +6 -0
  267. package/dist/poll/definePollType.js.map +1 -0
  268. package/dist/poll/effectivePollOptions.d.ts +38 -0
  269. package/dist/poll/effectivePollOptions.js +64 -0
  270. package/dist/poll/effectivePollOptions.js.map +1 -0
  271. package/dist/poll/mostVoted.d.ts +21 -0
  272. package/dist/poll/mostVoted.js +32 -0
  273. package/dist/poll/mostVoted.js.map +1 -0
  274. package/dist/poll/outcomeBeforeChange.js +91 -0
  275. package/dist/poll/outcomeBeforeChange.js.map +1 -0
  276. package/dist/poll/outcomeFields.d.ts +38 -0
  277. package/dist/poll/outcomeFields.js +52 -0
  278. package/dist/poll/outcomeFields.js.map +1 -0
  279. package/dist/poll/pollTypeRegistry.d.ts +34 -0
  280. package/dist/poll/pollTypeRegistry.js +69 -0
  281. package/dist/poll/pollTypeRegistry.js.map +1 -0
  282. package/dist/poll/registry.d.ts +17 -0
  283. package/dist/poll/registry.js +12 -0
  284. package/dist/poll/registry.js.map +1 -0
  285. package/dist/poll/resolvePollCloseRequest.js +105 -0
  286. package/dist/poll/resolvePollCloseRequest.js.map +1 -0
  287. package/dist/poll/resolvePollOptions.d.ts +29 -0
  288. package/dist/poll/resolvePollOptions.js +52 -0
  289. package/dist/poll/resolvePollOptions.js.map +1 -0
  290. package/dist/poll/resolvePollOptionsRequest.js +50 -0
  291. package/dist/poll/resolvePollOptionsRequest.js.map +1 -0
  292. package/dist/poll/resolvePollOutcome.d.ts +34 -0
  293. package/dist/poll/resolvePollOutcome.js +76 -0
  294. package/dist/poll/resolvePollOutcome.js.map +1 -0
  295. package/dist/poll/resultsField.js +21 -0
  296. package/dist/poll/resultsField.js.map +1 -0
  297. package/dist/prefill/valuesFromSearchParams.js +5 -9
  298. package/dist/prefill/valuesFromSearchParams.js.map +1 -1
  299. package/dist/presentations/types.d.ts +3 -2
  300. package/dist/react/Form.d.ts +66 -19
  301. package/dist/react/Form.js +342 -180
  302. package/dist/react/Form.js.map +1 -1
  303. package/dist/react/FormContext.d.ts +44 -1
  304. package/dist/react/FormContext.js.map +1 -1
  305. package/dist/react/FormControls.d.ts +55 -0
  306. package/dist/react/FormControls.js +56 -0
  307. package/dist/react/FormControls.js.map +1 -0
  308. package/dist/react/FormFields.d.ts +18 -0
  309. package/dist/react/FormFields.js +114 -0
  310. package/dist/react/FormFields.js.map +1 -0
  311. package/dist/react/FormLayout.d.ts +4 -2
  312. package/dist/react/FormLayout.js +3 -2
  313. package/dist/react/FormLayout.js.map +1 -1
  314. package/dist/react/FormResults.d.ts +6 -3
  315. package/dist/react/FormResults.js +37 -29
  316. package/dist/react/FormResults.js.map +1 -1
  317. package/dist/react/FormSteps.d.ts +17 -0
  318. package/dist/react/FormSteps.js +35 -0
  319. package/dist/react/FormSteps.js.map +1 -0
  320. package/dist/react/Poll.d.ts +17 -6
  321. package/dist/react/Poll.js +79 -21
  322. package/dist/react/Poll.js.map +1 -1
  323. package/dist/react/captcha/HcaptchaCaptcha.d.ts +28 -0
  324. package/dist/react/captcha/HcaptchaCaptcha.js +53 -0
  325. package/dist/react/captcha/HcaptchaCaptcha.js.map +1 -0
  326. package/dist/react/captcha/RecaptchaCaptcha.d.ts +41 -0
  327. package/dist/react/captcha/RecaptchaCaptcha.js +93 -0
  328. package/dist/react/captcha/RecaptchaCaptcha.js.map +1 -0
  329. package/dist/react/captcha/TurnstileCaptcha.d.ts +28 -0
  330. package/dist/react/captcha/TurnstileCaptcha.js +53 -0
  331. package/dist/react/captcha/TurnstileCaptcha.js.map +1 -0
  332. package/dist/react/captcha/types.d.ts +8 -0
  333. package/dist/react/captcha/useCaptchaScript.js +45 -0
  334. package/dist/react/captcha/useCaptchaScript.js.map +1 -0
  335. package/dist/react/captcha/vendors.js +8 -0
  336. package/dist/react/captcha/vendors.js.map +1 -0
  337. package/dist/react/contract.d.ts +2 -3
  338. package/dist/react/contract.js.map +1 -1
  339. package/dist/react/fetchResults.d.ts +1 -1
  340. package/dist/react/fetchResults.js +1 -1
  341. package/dist/react/fetchResults.js.map +1 -1
  342. package/dist/react/presentation/DialogSurface.js +1 -4
  343. package/dist/react/presentation/DialogSurface.js.map +1 -1
  344. package/dist/react/primitives/Checkbox.d.ts +4 -2
  345. package/dist/react/primitives/Checkbox.js +2 -1
  346. package/dist/react/primitives/Checkbox.js.map +1 -1
  347. package/dist/react/primitives/FieldShell.d.ts +2 -4
  348. package/dist/react/primitives/FieldShell.js +12 -19
  349. package/dist/react/primitives/FieldShell.js.map +1 -1
  350. package/dist/react/primitives/Input.d.ts +1 -1
  351. package/dist/react/primitives/Input.js.map +1 -1
  352. package/dist/react/renderers/calculation.js +1 -4
  353. package/dist/react/renderers/calculation.js.map +1 -1
  354. package/dist/react/renderers/checkbox.js +1 -4
  355. package/dist/react/renderers/checkbox.js.map +1 -1
  356. package/dist/react/renderers/consent.js +78 -35
  357. package/dist/react/renderers/consent.js.map +1 -1
  358. package/dist/react/renderers/date.js +33 -0
  359. package/dist/react/renderers/date.js.map +1 -0
  360. package/dist/react/renderers/email.js +1 -4
  361. package/dist/react/renderers/email.js.map +1 -1
  362. package/dist/react/renderers/file.js +29 -14
  363. package/dist/react/renderers/file.js.map +1 -1
  364. package/dist/react/renderers/index.js +9 -0
  365. package/dist/react/renderers/index.js.map +1 -1
  366. package/dist/react/renderers/message.js +41 -0
  367. package/dist/react/renderers/message.js.map +1 -0
  368. package/dist/react/renderers/number.js +1 -4
  369. package/dist/react/renderers/number.js.map +1 -1
  370. package/dist/react/renderers/region.js +43 -0
  371. package/dist/react/renderers/region.js.map +1 -0
  372. package/dist/react/renderers/repeater.js +131 -0
  373. package/dist/react/renderers/repeater.js.map +1 -0
  374. package/dist/react/renderers/select.js +1 -4
  375. package/dist/react/renderers/select.js.map +1 -1
  376. package/dist/react/renderers/text.js +1 -4
  377. package/dist/react/renderers/text.js.map +1 -1
  378. package/dist/react/renderers/textarea.js +1 -4
  379. package/dist/react/renderers/textarea.js.map +1 -1
  380. package/dist/react/state.d.ts +40 -3
  381. package/dist/react/state.js +64 -9
  382. package/dist/react/state.js.map +1 -1
  383. package/dist/react/uploadFile.d.ts +2 -2
  384. package/dist/react/uploadFile.js +1 -1
  385. package/dist/react/uploadFile.js.map +1 -1
  386. package/dist/react/useField.d.ts +0 -1
  387. package/dist/react/useField.js +6 -6
  388. package/dist/react/useField.js.map +1 -1
  389. package/dist/react/useFormState.d.ts +1 -1
  390. package/dist/react/useFormState.js +1 -1
  391. package/dist/react/useFormState.js.map +1 -1
  392. package/dist/react/validateField.js +3 -6
  393. package/dist/react/validateField.js.map +1 -1
  394. package/dist/recall/interpolate.d.ts +4 -3
  395. package/dist/recall/interpolate.js +5 -4
  396. package/dist/recall/interpolate.js.map +1 -1
  397. package/dist/recall/resolver.d.ts +1 -1
  398. package/dist/recall/resolver.js +14 -2
  399. package/dist/recall/resolver.js.map +1 -1
  400. package/dist/spam/captcha.d.ts +4 -3
  401. package/dist/spam/captcha.js +4 -3
  402. package/dist/spam/captcha.js.map +1 -1
  403. package/dist/spam/clientIp.js +9 -0
  404. package/dist/spam/clientIp.js.map +1 -0
  405. package/dist/spam/constants.js +7 -1
  406. package/dist/spam/constants.js.map +1 -1
  407. package/dist/spam/identify.js +3 -6
  408. package/dist/spam/identify.js.map +1 -1
  409. package/dist/spam/providers/hcaptcha.d.ts +17 -0
  410. package/dist/spam/providers/hcaptcha.js +18 -0
  411. package/dist/spam/providers/hcaptcha.js.map +1 -0
  412. package/dist/spam/providers/recaptcha.d.ts +23 -0
  413. package/dist/spam/providers/recaptcha.js +23 -0
  414. package/dist/spam/providers/recaptcha.js.map +1 -0
  415. package/dist/spam/providers/siteverify.js +34 -0
  416. package/dist/spam/providers/siteverify.js.map +1 -0
  417. package/dist/spam/providers/turnstile.d.ts +17 -0
  418. package/dist/spam/providers/turnstile.js +18 -0
  419. package/dist/spam/providers/turnstile.js.map +1 -0
  420. package/dist/spam/resolveSpam.js +2 -1
  421. package/dist/spam/resolveSpam.js.map +1 -1
  422. package/dist/spam/spamGuard.js +23 -10
  423. package/dist/spam/spamGuard.js.map +1 -1
  424. package/dist/spam/types.d.ts +19 -4
  425. package/dist/submissions/SubmissionAnswers.d.ts +2 -4
  426. package/dist/submissions/SubmissionAnswers.js +114 -34
  427. package/dist/submissions/SubmissionAnswers.js.map +1 -1
  428. package/dist/submissions/SubmissionAnswersClient.js +178 -0
  429. package/dist/submissions/SubmissionAnswersClient.js.map +1 -0
  430. package/dist/submissions/coerceBoolean.js +14 -0
  431. package/dist/submissions/coerceBoolean.js.map +1 -0
  432. package/dist/submissions/createSubmission.d.ts +36 -0
  433. package/dist/submissions/createSubmission.js +26 -0
  434. package/dist/submissions/createSubmission.js.map +1 -0
  435. package/dist/submissions/runSubmission.d.ts +10 -0
  436. package/dist/submissions/runSubmission.js +128 -27
  437. package/dist/submissions/runSubmission.js.map +1 -1
  438. package/dist/submissions/types.d.ts +12 -4
  439. package/dist/submissions/validateSubmission.js +62 -11
  440. package/dist/submissions/validateSubmission.js.map +1 -1
  441. package/dist/submissions/votedCookie.d.ts +13 -0
  442. package/dist/submissions/votedCookie.js +27 -0
  443. package/dist/submissions/votedCookie.js.map +1 -0
  444. package/dist/translations/clientRuntimeKeys.d.ts +17 -0
  445. package/dist/translations/clientRuntimeKeys.js +46 -0
  446. package/dist/translations/clientRuntimeKeys.js.map +1 -0
  447. package/dist/translations/de.d.ts +12 -0
  448. package/dist/translations/de.js +309 -0
  449. package/dist/translations/de.js.map +1 -0
  450. package/dist/translations/en.js +203 -27
  451. package/dist/translations/en.js.map +1 -1
  452. package/dist/translations/index.d.ts +14 -5
  453. package/dist/translations/index.js +14 -3
  454. package/dist/translations/index.js.map +1 -1
  455. package/dist/translations/keys.d.ts +199 -23
  456. package/dist/translations/keys.js +200 -24
  457. package/dist/translations/keys.js.map +1 -1
  458. package/dist/translations/makeTranslate.d.ts +7 -3
  459. package/dist/translations/makeTranslate.js +12 -3
  460. package/dist/translations/makeTranslate.js.map +1 -1
  461. package/dist/translations/server.js +8 -1
  462. package/dist/translations/server.js.map +1 -1
  463. package/dist/uploads/captureFileRef.d.ts +10 -3
  464. package/dist/uploads/captureFileRef.js +18 -9
  465. package/dist/uploads/captureFileRef.js.map +1 -1
  466. package/dist/uploads/formatBytes.d.ts +9 -0
  467. package/dist/uploads/formatBytes.js +25 -0
  468. package/dist/uploads/formatBytes.js.map +1 -0
  469. package/dist/uploads/resolveFileRef.js +3 -2
  470. package/dist/uploads/resolveFileRef.js.map +1 -1
  471. package/dist/uploads/types.d.ts +1 -2
  472. package/dist/validation/buildRuleBlocks.js +18 -17
  473. package/dist/validation/buildRuleBlocks.js.map +1 -1
  474. package/dist/validation/builtin/email.js +2 -1
  475. package/dist/validation/builtin/email.js.map +1 -1
  476. package/dist/validation/builtin/index.d.ts +14 -0
  477. package/dist/validation/builtin/index.js +12 -1
  478. package/dist/validation/builtin/index.js.map +1 -1
  479. package/dist/validation/builtin/matchesField.js +3 -7
  480. package/dist/validation/builtin/matchesField.js.map +1 -1
  481. package/dist/validation/builtin/max.js +1 -0
  482. package/dist/validation/builtin/max.js.map +1 -1
  483. package/dist/validation/builtin/maxDate.js +24 -0
  484. package/dist/validation/builtin/maxDate.js.map +1 -0
  485. package/dist/validation/builtin/maxLength.js +1 -0
  486. package/dist/validation/builtin/maxLength.js.map +1 -1
  487. package/dist/validation/builtin/min.js +1 -0
  488. package/dist/validation/builtin/min.js.map +1 -1
  489. package/dist/validation/builtin/minDate.js +24 -0
  490. package/dist/validation/builtin/minDate.js.map +1 -0
  491. package/dist/validation/builtin/minLength.js +1 -0
  492. package/dist/validation/builtin/minLength.js.map +1 -1
  493. package/dist/validation/builtin/notAlreadySubmitted.js +2 -0
  494. package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -1
  495. package/dist/validation/builtin/oneOf.js +1 -0
  496. package/dist/validation/builtin/oneOf.js.map +1 -1
  497. package/dist/validation/builtin/pattern.js +11 -2
  498. package/dist/validation/builtin/pattern.js.map +1 -1
  499. package/dist/validation/builtin/url.js +1 -0
  500. package/dist/validation/builtin/url.js.map +1 -1
  501. package/dist/validation/builtin/validateDateBound.js +18 -0
  502. package/dist/validation/builtin/validateDateBound.js.map +1 -0
  503. package/dist/validation/builtin/validateRegexParams.js +44 -0
  504. package/dist/validation/builtin/validateRegexParams.js.map +1 -0
  505. package/dist/validation/emailPattern.js +10 -0
  506. package/dist/validation/emailPattern.js.map +1 -0
  507. package/dist/validation/fieldTargetParam.d.ts +22 -0
  508. package/dist/validation/fieldTargetParam.js +38 -0
  509. package/dist/validation/fieldTargetParam.js.map +1 -0
  510. package/dist/validation/registry.d.ts +2 -1
  511. package/dist/validation/registry.js +2 -9
  512. package/dist/validation/registry.js.map +1 -1
  513. package/dist/validation/runValidation.js +9 -30
  514. package/dist/validation/runValidation.js.map +1 -1
  515. package/dist/validation/types.d.ts +5 -11
  516. package/dist/validation/validateUrl.js +22 -0
  517. package/dist/validation/validateUrl.js.map +1 -0
  518. package/package.json +7 -5
  519. package/styles/form-builder.css +10 -190
  520. package/dist/collections/uploads.d.ts +0 -29
  521. package/dist/collections/uploads.js +0 -46
  522. package/dist/collections/uploads.js.map +0 -1
  523. package/dist/consent/buildConsentSourceConfig.js +0 -49
  524. package/dist/consent/buildConsentSourceConfig.js.map +0 -1
  525. package/dist/consent/builtin/index.d.ts +0 -7
  526. package/dist/consent/builtin/index.js +0 -11
  527. package/dist/consent/builtin/index.js.map +0 -1
  528. package/dist/consent/builtin/pageReference.js +0 -75
  529. package/dist/consent/builtin/pageReference.js.map +0 -1
  530. package/dist/consent/builtin/static.js +0 -44
  531. package/dist/consent/builtin/static.js.map +0 -1
  532. package/dist/consent/defineConsentSource.d.ts +0 -35
  533. package/dist/consent/defineConsentSource.js +0 -6
  534. package/dist/consent/defineConsentSource.js.map +0 -1
  535. package/dist/consent/registry.d.ts +0 -16
  536. package/dist/consent/registry.js +0 -16
  537. package/dist/consent/registry.js.map +0 -1
  538. package/dist/consent/resolveConsentLinks.d.ts +0 -19
  539. package/dist/consent/resolveConsentLinks.js +0 -26
  540. package/dist/consent/resolveConsentLinks.js.map +0 -1
  541. package/dist/presentations/registry.d.ts +0 -15
  542. package/dist/presentations/registry.js +0 -15
  543. package/dist/presentations/registry.js.map +0 -1
  544. package/dist/react/toFormDocument.d.ts +0 -24
  545. package/dist/react/toFormDocument.js +0 -22
  546. package/dist/react/toFormDocument.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"formSubmissions.js","names":[],"sources":["../../src/collections/formSubmissions.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig } from 'payload'\nimport { dispatchActions } from '../actions/dispatch'\nimport type { ActionRegistry } from '../actions/registry'\nimport type { ActionInstance } from '../actions/runActions'\nimport type { ConsentSourceRegistry } from '../consent/registry'\nimport { resolveEventSink } from '../events/resolveEventSink'\nimport type { FormEventSink } from '../events/types'\nimport type { FieldTypeRegistry } from '../fields/registry'\nimport { isLoggedIn } from '../plugin/access'\nimport { buildSpamGuard } from '../spam/spamGuard'\nimport type { ResolvedSpamConfig } from '../spam/types'\nimport { validateSubmission } from '../submissions/validateSubmission'\nimport type { ValidationRuleRegistry } from '../validation/registry'\nimport { FORMS_SLUG } from './forms'\n\nexport const FORM_SUBMISSIONS_SLUG = 'form-submissions'\n\ntype BuildSubmissionsCollectionArgs = {\n\tregistry: FieldTypeRegistry\n\truleRegistry: ValidationRuleRegistry\n\tconsentRegistry: ConsentSourceRegistry\n\tactionRegistry?: ActionRegistry\n\tevents?: FormEventSink\n\t/** Whether a job runner is likely present; gates the queued vs bounded-inline dispatch path. */\n\thasRunner?: boolean\n\t/** Upload collection slug for file fields without an explicit `relationTo`. */\n\tuploadSlug?: string\n\t/** Resolved spam config; when active, prepends the spam guard before validation. `false` disables it. */\n\tspam?: ResolvedSpamConfig | false\n}\n\nconst formIdOf = (form: unknown): number | string | undefined => {\n\tif (typeof form === 'number' || typeof form === 'string') {\n\t\treturn form\n\t}\n\tif (form && typeof form === 'object' && 'id' in form) {\n\t\tconst id = (form as { id: unknown }).id\n\t\tif (typeof id === 'number' || typeof id === 'string') {\n\t\t\treturn id\n\t\t}\n\t}\n\treturn undefined\n}\n\n/**\n * On a completed submission create, dispatch the form's post-submit actions and emit `submission.created`.\n * Both are side effects on an already-written row, so the whole body is wrapped: nothing it does can throw\n * past the hook (a failed action or sink must never fail the submission write). Dispatch is itself bounded\n * and non-throwing; the inline fallback is awaited so the bound caps the added latency, while the queued\n * path returns immediately. The form's `actions` are null-guarded for legacy rows created before the field\n * existed.\n */\nconst makeAfterChange =\n\t(args: {\n\t\tactionRegistry: ActionRegistry\n\t\tevents?: FormEventSink\n\t\thasRunner: boolean\n\t}): CollectionAfterChangeHook =>\n\tasync ({ doc, operation, req }) => {\n\t\tif (operation !== 'create' || (doc.status != null && doc.status !== 'complete')) {\n\t\t\treturn doc\n\t\t}\n\t\tconst { payload } = req\n\t\ttry {\n\t\t\tconst formId = formIdOf(doc.form)\n\t\t\tif (formId == null) {\n\t\t\t\treturn doc\n\t\t\t}\n\t\t\tconst form = await payload\n\t\t\t\t.findByID({ collection: FORMS_SLUG, id: formId, depth: 0, overrideAccess: true, req })\n\t\t\t\t.catch(() => null)\n\n\t\t\tawait dispatchActions({\n\t\t\t\tactions: (form?.actions ?? null) as ActionInstance[] | null,\n\t\t\t\tformId,\n\t\t\t\tsubmissionId: doc.id as number | string,\n\t\t\t\tregistry: args.actionRegistry,\n\t\t\t\tpayload,\n\t\t\t\treq,\n\t\t\t\thasRunner: args.hasRunner,\n\t\t\t})\n\n\t\t\ttry {\n\t\t\t\tawait resolveEventSink(args.events).emit({\n\t\t\t\t\ttype: 'submission.created',\n\t\t\t\t\tformId: String(formId),\n\t\t\t\t\tsubmissionId: String(doc.id),\n\t\t\t\t\tat: new Date().toISOString(),\n\t\t\t\t})\n\t\t\t} catch (error) {\n\t\t\t\tpayload.logger?.error(\n\t\t\t\t\t`@10x-media/form-builder: submission.created sink threw: ${\n\t\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t\t}`\n\t\t\t\t)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tpayload.logger?.error(\n\t\t\t\t`@10x-media/form-builder: afterChange dispatch failed for submission ${String(doc.id)}: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`\n\t\t\t)\n\t\t}\n\t\treturn doc\n\t}\n\nexport const buildSubmissionsCollection = ({\n\tregistry,\n\truleRegistry,\n\tconsentRegistry,\n\tactionRegistry = new Map(),\n\tevents,\n\thasRunner = false,\n\tuploadSlug,\n\tspam,\n}: BuildSubmissionsCollectionArgs): CollectionConfig => ({\n\tslug: FORM_SUBMISSIONS_SLUG,\n\tlabels: { singular: 'Submission', plural: 'Submissions' },\n\tadmin: { group: 'Forms' },\n\taccess: {\n\t\tcreate: () => true,\n\t\tread: isLoggedIn,\n\t\tupdate: () => false,\n\t},\n\thooks: {\n\t\tbeforeValidate: [\n\t\t\t...(spam ? [buildSpamGuard(spam)] : []),\n\t\t\tvalidateSubmission({ registry, ruleRegistry, consentRegistry, uploadSlug }),\n\t\t],\n\t\tafterChange: [makeAfterChange({ actionRegistry, events, hasRunner })],\n\t},\n\tfields: [\n\t\t{ name: 'form', type: 'relationship', relationTo: FORMS_SLUG, required: true },\n\t\t{\n\t\t\tname: 'status',\n\t\t\ttype: 'select',\n\t\t\tdefaultValue: 'complete',\n\t\t\toptions: [\n\t\t\t\t{ label: 'Complete', value: 'complete' },\n\t\t\t\t{ label: 'Partial', value: 'partial' },\n\t\t\t],\n\t\t\t// Defense-in-depth at the REST layer: anonymous clients cannot set status via the API.\n\t\t\t// The validateSubmission hook also forces 'complete' server-side, so this covers both paths.\n\t\t\taccess: { create: isLoggedIn, update: isLoggedIn },\n\t\t},\n\t\t{ name: 'locale', type: 'text' },\n\t\t{ name: 'values', type: 'json' },\n\t\t{ name: 'descriptors', type: 'json' },\n\t\t{ name: 'consent', type: 'json' },\n\t\t{ name: 'meta', type: 'json' },\n\t\t{\n\t\t\tname: 'answers',\n\t\t\ttype: 'ui',\n\t\t\tadmin: {\n\t\t\t\tcomponents: { Field: '@10x-media/form-builder/rsc#SubmissionAnswers' },\n\t\t\t},\n\t\t},\n\t],\n})\n"],"mappings":";;;;;;;AAeA,MAAa,wBAAwB;AAgBrC,MAAM,YAAY,SAA+C;CAChE,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAC/C,OAAO;CAER,IAAI,QAAQ,OAAO,SAAS,YAAY,QAAQ,MAAM;EACrD,MAAM,KAAM,KAAyB;EACrC,IAAI,OAAO,OAAO,YAAY,OAAO,OAAO,UAC3C,OAAO;CAET;AAED;;;;;;;;;AAUA,MAAM,mBACJ,SAKD,OAAO,EAAE,KAAK,WAAW,UAAU;CAClC,IAAI,cAAc,YAAa,IAAI,UAAU,QAAQ,IAAI,WAAW,YACnE,OAAO;CAER,MAAM,EAAE,YAAY;CACpB,IAAI;EACH,MAAM,SAAS,SAAS,IAAI,IAAI;EAChC,IAAI,UAAU,MACb,OAAO;EAMR,MAAM,gBAAgB;GACrB,UAAU,MALQ,QACjB,SAAS;IAAE,YAAA;IAAwB,IAAI;IAAQ,OAAO;IAAG,gBAAgB;IAAM;GAAI,CAAC,EACpF,YAAY,IAAI,IAGD,WAAW;GAC3B;GACA,cAAc,IAAI;GAClB,UAAU,KAAK;GACf;GACA;GACA,WAAW,KAAK;EACjB,CAAC;EAED,IAAI;GACH,MAAM,iBAAiB,KAAK,MAAM,EAAE,KAAK;IACxC,MAAM;IACN,QAAQ,OAAO,MAAM;IACrB,cAAc,OAAO,IAAI,EAAE;IAC3B,qBAAI,IAAI,KAAK,GAAE,YAAY;GAC5B,CAAC;EACF,SAAS,OAAO;GACf,QAAQ,QAAQ,MACf,2DACC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAEvD;EACD;CACD,SAAS,OAAO;EACf,QAAQ,QAAQ,MACf,uEAAuE,OAAO,IAAI,EAAE,EAAE,IACrF,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAEvD;CACD;CACA,OAAO;AACR;AAED,MAAa,8BAA8B,EAC1C,UACA,cACA,iBACA,iCAAiB,IAAI,IAAI,GACzB,QACA,YAAY,OACZ,YACA,YACwD;CACxD,MAAM;CACN,QAAQ;EAAE,UAAU;EAAc,QAAQ;CAAc;CACxD,OAAO,EAAE,OAAO,QAAQ;CACxB,QAAQ;EACP,cAAc;EACd,MAAM;EACN,cAAc;CACf;CACA,OAAO;EACN,gBAAgB,CACf,GAAI,OAAO,CAAC,eAAe,IAAI,CAAC,IAAI,CAAC,GACrC,mBAAmB;GAAE;GAAU;GAAc;GAAiB;EAAW,CAAC,CAC3E;EACA,aAAa,CAAC,gBAAgB;GAAE;GAAgB;GAAQ;EAAU,CAAC,CAAC;CACrE;CACA,QAAQ;EACP;GAAE,MAAM;GAAQ,MAAM;GAAgB,YAAY;GAAY,UAAU;EAAK;EAC7E;GACC,MAAM;GACN,MAAM;GACN,cAAc;GACd,SAAS,CACR;IAAE,OAAO;IAAY,OAAO;GAAW,GACvC;IAAE,OAAO;IAAW,OAAO;GAAU,CACtC;GAGA,QAAQ;IAAE,QAAQ;IAAY,QAAQ;GAAW;EAClD;EACA;GAAE,MAAM;GAAU,MAAM;EAAO;EAC/B;GAAE,MAAM;GAAU,MAAM;EAAO;EAC/B;GAAE,MAAM;GAAe,MAAM;EAAO;EACpC;GAAE,MAAM;GAAW,MAAM;EAAO;EAChC;GAAE,MAAM;GAAQ,MAAM;EAAO;EAC7B;GACC,MAAM;GACN,MAAM;GACN,OAAO,EACN,YAAY,EAAE,OAAO,gDAAgD,EACtE;EACD;CACD;AACD"}
1
+ {"version":3,"file":"formSubmissions.js","names":[],"sources":["../../src/collections/formSubmissions.ts"],"sourcesContent":["import type { CollectionAfterChangeHook, CollectionConfig, Field } from 'payload'\nimport type { RichTextBodyOption } from '../actions/body/serializeBody'\nimport { dispatchActions } from '../actions/dispatch'\nimport type { ActionRegistry } from '../actions/registry'\nimport type { ActionInstance } from '../actions/runActions'\nimport type { ConsentSnapshotMode } from '../consent/captureConsent'\nimport type { ConsentSourcesResolver } from '../consent/types'\nimport { resolveEventSink } from '../events/resolveEventSink'\nimport type { FormEventSink } from '../events/types'\nimport type { FieldTypeRegistry } from '../fields/registry'\nimport { isLoggedIn } from '../plugin/access'\nimport type { CollectionOverrides } from '../plugin/collectionOverrides'\nimport type { PollOptionSourceRegistry } from '../poll/registry'\nimport { buildSpamGuard } from '../spam/spamGuard'\nimport type { ResolvedSpamConfig } from '../spam/types'\nimport { validateSubmission } from '../submissions/validateSubmission'\nimport { POLL_CONTEXT_KEY, votedCookieName } from '../submissions/votedCookie'\nimport { keys } from '../translations/keys'\nimport { labelForKey } from '../translations/server'\nimport type { ValidationRuleRegistry } from '../validation/registry'\nimport { FORMS_SLUG } from './forms'\n\nexport const FORM_SUBMISSIONS_SLUG = 'form-submissions'\n\ntype BuildSubmissionsCollectionArgs = {\n\tregistry: FieldTypeRegistry\n\truleRegistry: ValidationRuleRegistry\n\t/** The host's consent sources resolver (plugin option `consent.sources`); absent when no sources are configured. */\n\tconsentSources?: ConsentSourcesResolver\n\t/** What each consent proof snapshots of the agreed wording (plugin option `consent.snapshot`). */\n\tconsentSnapshot?: ConsentSnapshotMode\n\tactionRegistry?: ActionRegistry\n\tevents?: FormEventSink\n\t/** Whether a job runner is likely present; gates the queued vs bounded-inline dispatch path. */\n\thasRunner?: boolean\n\t/** Body serialization customization forwarded to the inline action dispatch path. */\n\trichText?: RichTextBodyOption\n\t/** The plugin-configured uploads collection slug; absent when uploads are disabled. */\n\tuploadSlug?: string\n\t/** Resolved spam config; when active, prepends the spam guard before validation. `false` disables it. */\n\tspam?: ResolvedSpamConfig | false\n\t/** Opt-in (`poll.votedCookie`): set an httpOnly `fb-voted-{formId}` cookie on poll submission creates. */\n\tvotedCookie?: boolean\n\t/** Registered poll option sources; submission validation resolves allowed values through them. */\n\tpollSourceRegistry?: PollOptionSourceRegistry\n\t/**\n\t * When `true`, reveals the standalone `locale`, `values`, `descriptors`, `consent`, and `meta`\n\t * fields in the admin UI. Default `false`, because the `SubmissionAnswers` UI component already\n\t * represents them fully (locale and meta are folded into its Submission-details section).\n\t */\n\tshowRawFields?: boolean\n\toverrides?: CollectionOverrides\n}\n\nconst formIdOf = (form: unknown): number | string | undefined => {\n\tif (typeof form === 'number' || typeof form === 'string') {\n\t\treturn form\n\t}\n\tif (form && typeof form === 'object' && 'id' in form) {\n\t\tconst id = (form as { id: unknown }).id\n\t\tif (typeof id === 'number' || typeof id === 'string') {\n\t\t\treturn id\n\t\t}\n\t}\n\treturn undefined\n}\n\n/**\n * On a completed submission create, dispatch the form's post-submit actions and emit `submission.created`.\n * Both are side effects on an already-written row, so the whole body is wrapped: nothing it does can throw\n * past the hook (a failed action or sink must never fail the submission write). Dispatch is itself bounded\n * and non-throwing; the inline fallback is awaited so the bound caps the added latency, while the queued\n * path returns immediately. The form's `actions` are null-guarded for legacy rows created before the field\n * existed.\n */\nconst makeAfterChange =\n\t(args: {\n\t\tactionRegistry: ActionRegistry\n\t\tevents?: FormEventSink\n\t\thasRunner: boolean\n\t\trichText?: RichTextBodyOption\n\t}): CollectionAfterChangeHook =>\n\tasync ({ doc, operation, req }) => {\n\t\tif (operation !== 'create' || (doc.status != null && doc.status !== 'complete')) {\n\t\t\treturn doc\n\t\t}\n\t\tconst { payload } = req\n\t\ttry {\n\t\t\tconst formId = formIdOf(doc.form)\n\t\t\tif (formId == null) {\n\t\t\t\treturn doc\n\t\t\t}\n\t\t\tconst form = await payload\n\t\t\t\t.findByID({ collection: FORMS_SLUG, id: formId, depth: 0, overrideAccess: true, req })\n\t\t\t\t.catch(() => null)\n\n\t\t\tawait dispatchActions({\n\t\t\t\tactions: (form?.actions ?? null) as ActionInstance[] | null,\n\t\t\t\tformId,\n\t\t\t\tsubmissionId: doc.id as number | string,\n\t\t\t\tregistry: args.actionRegistry,\n\t\t\t\tpayload,\n\t\t\t\treq,\n\t\t\t\thasRunner: args.hasRunner,\n\t\t\t\trichText: args.richText,\n\t\t\t})\n\n\t\t\ttry {\n\t\t\t\tawait resolveEventSink(args.events).emit({\n\t\t\t\t\ttype: 'submission.created',\n\t\t\t\t\tformId: String(formId),\n\t\t\t\t\tsubmissionId: String(doc.id),\n\t\t\t\t\tat: new Date().toISOString(),\n\t\t\t\t})\n\t\t\t} catch (error) {\n\t\t\t\tpayload.logger?.error(\n\t\t\t\t\t`@10x-media/form-builder: submission.created sink threw: ${\n\t\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t\t}`\n\t\t\t\t)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tpayload.logger?.error(\n\t\t\t\t`@10x-media/form-builder: afterChange dispatch failed for submission ${String(doc.id)}: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`\n\t\t\t)\n\t\t}\n\t\treturn doc\n\t}\n\n/**\n * Opt-in (`poll.votedCookie`) hook: after a submission to a poll-enabled form is created, appends\n * an httpOnly `fb-voted-{formId}=1` cookie via `req.responseHeaders`, Payload's supported channel\n * for hook-set response headers (its own auth strategies use it; `handleEndpoints` merges it into\n * every REST response). Reads the poll config `validateSubmission` stashed on `req.context`,\n * falling back to a form fetch when absent. httpOnly keeps the marker readable only server-side\n * (`hasVotedCookie`); the client `<Poll>` keeps its localStorage guard.\n */\nconst makeVotedCookieHook = (): CollectionAfterChangeHook => {\n\treturn async ({ doc, operation, req }) => {\n\t\tif (operation !== 'create') {\n\t\t\treturn doc\n\t\t}\n\t\tconst formId = formIdOf(doc.form)\n\t\tif (formId == null) {\n\t\t\treturn doc\n\t\t}\n\t\tconst stashed = req.context?.[POLL_CONTEXT_KEY]\n\t\tlet pollEnabled = typeof stashed === 'boolean' ? stashed : undefined\n\t\tif (pollEnabled === undefined) {\n\t\t\tconst form = await req.payload\n\t\t\t\t.findByID({ collection: FORMS_SLUG, id: formId, depth: 0, overrideAccess: true, req })\n\t\t\t\t.catch(() => null)\n\t\t\tpollEnabled = form?.pollEnabled === true\n\t\t}\n\t\tif (!pollEnabled) {\n\t\t\treturn doc\n\t\t}\n\t\treq.responseHeaders ??= new Headers()\n\t\treq.responseHeaders.append(\n\t\t\t'Set-Cookie',\n\t\t\t`${votedCookieName(formId)}=1; Path=/; Max-Age=31536000; HttpOnly; SameSite=Lax`\n\t\t)\n\t\treturn doc\n\t}\n}\n\nexport const buildSubmissionsCollection = ({\n\tregistry,\n\truleRegistry,\n\tconsentSources,\n\tconsentSnapshot,\n\tactionRegistry = new Map(),\n\tevents,\n\thasRunner = false,\n\trichText,\n\tuploadSlug,\n\tspam,\n\tvotedCookie = false,\n\tpollSourceRegistry,\n\tshowRawFields = false,\n\toverrides,\n}: BuildSubmissionsCollectionArgs): CollectionConfig => {\n\tconst defaultFields: Field[] = [\n\t\t{ name: 'form', type: 'relationship', relationTo: FORMS_SLUG, required: true },\n\t\t{\n\t\t\tname: 'status',\n\t\t\ttype: 'select',\n\t\t\tdefaultValue: 'complete',\n\t\t\toptions: [\n\t\t\t\t{ label: labelForKey(keys.statusComplete), value: 'complete' },\n\t\t\t\t{ label: labelForKey(keys.statusPartial), value: 'partial' },\n\t\t\t],\n\t\t\t// Not clearable: aggregation counts `status: complete` submissions, so a cleared status\n\t\t\t// would drop the submission out of every poll result with nothing in the UI saying so.\n\t\t\tadmin: { isClearable: false },\n\t\t\t// Defense-in-depth at the REST layer: anonymous clients cannot set status via the API.\n\t\t\t// The validateSubmission hook also forces 'complete' server-side, so this covers both paths.\n\t\t\taccess: { create: isLoggedIn, update: isLoggedIn },\n\t\t},\n\t\t// answers UI appears first so it is the dominant view when opening a submission document.\n\t\t{\n\t\t\tname: 'answers',\n\t\t\ttype: 'ui',\n\t\t\tadmin: {\n\t\t\t\tcomponents: { Field: '@10x-media/form-builder/rsc#SubmissionAnswers' },\n\t\t\t},\n\t\t},\n\t\t{ name: 'locale', type: 'text', admin: { hidden: !showRawFields } },\n\t\t{ name: 'values', type: 'json', admin: { hidden: !showRawFields } },\n\t\t{ name: 'descriptors', type: 'json', admin: { hidden: !showRawFields } },\n\t\t{ name: 'consent', type: 'json', admin: { hidden: !showRawFields } },\n\t\t{ name: 'meta', type: 'json', admin: { hidden: !showRawFields } },\n\t]\n\n\treturn {\n\t\t...(overrides ?? {}),\n\t\tslug: FORM_SUBMISSIONS_SLUG,\n\t\tlabels: {\n\t\t\tsingular: labelForKey(keys.collectionSubmissionSingular),\n\t\t\tplural: labelForKey(keys.collectionSubmissionPlural),\n\t\t\t...(overrides?.labels ?? {}),\n\t\t},\n\t\tadmin: {\n\t\t\tgroup: 'Forms',\n\t\t\tdefaultColumns: ['form', 'status', 'locale', 'createdAt'],\n\t\t\t...(overrides?.admin ?? {}),\n\t\t},\n\t\taccess: {\n\t\t\tcreate: () => true,\n\t\t\tread: isLoggedIn,\n\t\t\tupdate: () => false,\n\t\t\t...(overrides?.access ?? {}),\n\t\t},\n\t\thooks: {\n\t\t\t...(overrides?.hooks ?? {}),\n\t\t\t// Spam guard + validateSubmission must remain first: they enforce the security invariant\n\t\t\t// that anonymous callers cannot bypass post-submit actions or supply a forged status.\n\t\t\t// Consumer beforeValidate hooks are appended after so they run on already-validated data.\n\t\t\tbeforeValidate: [\n\t\t\t\t...(spam ? [buildSpamGuard(spam)] : []),\n\t\t\t\tvalidateSubmission({\n\t\t\t\t\tregistry,\n\t\t\t\t\truleRegistry,\n\t\t\t\t\tconsentSources,\n\t\t\t\t\tconsentSnapshot,\n\t\t\t\t\tuploadSlug,\n\t\t\t\t\tpollSourceRegistry,\n\t\t\t\t\tstrictUploadOwnership: spam ? spam.uploadOwnership === 'strict' : false,\n\t\t\t\t}),\n\t\t\t\t...(overrides?.hooks?.beforeValidate ?? []),\n\t\t\t],\n\t\t\tafterChange: [\n\t\t\t\tmakeAfterChange({ actionRegistry, events, hasRunner, richText }),\n\t\t\t\t...(votedCookie ? [makeVotedCookieHook()] : []),\n\t\t\t\t...(overrides?.hooks?.afterChange ?? []),\n\t\t\t],\n\t\t},\n\t\tfields: overrides?.fields ? overrides.fields({ defaultFields }) : defaultFields,\n\t}\n}\n"],"mappings":"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"}
@@ -1,23 +1,58 @@
1
+ import { fieldNamesOfType } from "../fields/fieldNamesOfType.js";
1
2
  import { keys } from "../translations/keys.js";
2
- import { labelFor, labelForKey } from "../translations/server.js";
3
+ import { asTranslate, labelForKey, resolveDefinitionLabel } from "../translations/server.js";
4
+ import { localizedIf } from "../fields/localizedIf.js";
5
+ import { validateUrl } from "../validation/validateUrl.js";
6
+ import { normalizeCalc } from "../calc/normalizeCalc.js";
3
7
  import { isLoggedIn } from "../plugin/access.js";
4
8
  import { buildActionBlocks } from "../actions/buildActionBlocks.js";
5
- import { resolveFormResultsRequest } from "../aggregation/resolveResultsRequest.js";
6
- import { normalizeCalc } from "../calc/normalizeCalc.js";
7
9
  import { buildConditionTypeMap } from "../conditions/conditionType.js";
8
- import { normalizeFormConditions } from "../conditions/normalizeConditions.js";
10
+ import { buildOperandTypes, normalizeFormConditions, normalizeWhere } from "../conditions/normalizeConditions.js";
11
+ import { resolveConsentStatements } from "../consent/resolveConsentStatements.js";
9
12
  import { buildFieldBlocks } from "../fields/buildFieldBlocks.js";
10
13
  import { normalizeFlow } from "../flow/normalizeFlow.js";
11
- import { DEFAULT_PRESENTATION_NAME, defaultPresentationDescriptors } from "../presentations/defaults.js";
14
+ import { END_OF_FORM } from "../flow/types.js";
15
+ import { buildPollOptionSourceFields } from "../poll/buildPollOptionSourceFields.js";
16
+ import { resolvePollTypes } from "../poll/pollTypeRegistry.js";
17
+ import { enqueuePollClose } from "../poll/closeJob.js";
18
+ import { pollOutcomeBeforeChange } from "../poll/outcomeBeforeChange.js";
19
+ import { buildDefaultOutcomeFields } from "../poll/outcomeFields.js";
20
+ import { buildValidateResultsField, pollEligibleTypes } from "../poll/resultsField.js";
21
+ import { buildDefaultButtonFields } from "./buttonFields.js";
22
+ import { buildFormsEndpoints } from "./formsEndpoints.js";
12
23
  import { ValidationError } from "payload";
13
24
  //#region src/collections/forms.ts
14
25
  const FORMS_SLUG = "forms";
26
+ /** `req.context` key under which `consentAfterRead` tracks the form ids it is currently resolving, to break re-entrant reads. */
27
+ const CONSENT_AFTER_READ_GUARD = "formBuilderConsentAfterReadInFlight";
28
+ /**
29
+ * Require the title in the default locale (and on hosts without localization), but let it be empty in
30
+ * other locales so a localized form falls back to the default-locale title rather than forcing a
31
+ * translation for every locale. Payload's field-level `required` cannot express this: it enforces per
32
+ * write-locale, which would make a title mandatory in every locale and break the documented fallback.
33
+ */
34
+ const validateFormTitle = (value, { req }) => {
35
+ const localization = req.payload.config.localization;
36
+ const defaultLocale = localization ? localization.defaultLocale : void 0;
37
+ if ((defaultLocale === void 0 || req.locale === void 0 || req.locale === defaultLocale) && (typeof value !== "string" || value.trim().length === 0)) return req.t("validation:required");
38
+ return true;
39
+ };
40
+ /**
41
+ * Field-level validation for the raw flow JSON: step ids must be non-empty, unique, and not the
42
+ * reserved `END_OF_FORM` sentinel, and every explicit step-id reference (a string `next`, a
43
+ * transition `to`) must resolve to a known step. `next: null` (explicit end of form) and an
44
+ * absent `next` (fall through to the next step in array order) are always valid. On full-document
45
+ * saves the beforeValidate pass has already run `normalizeFlow` and laundered dangling
46
+ * references, so the unknown-target checks mainly protect partial API updates that send `flow`
47
+ * without `fields`.
48
+ */
15
49
  const validateFlow = (raw) => {
16
50
  if (raw === null || raw === void 0) return true;
17
51
  const r = raw;
18
52
  if (!Array.isArray(r.steps)) return true;
19
53
  const steps = r.steps;
20
54
  if (steps.find((s) => typeof s?.id !== "string" || s.id.length === 0)) return "Flow: every step must have a non-empty ID";
55
+ if (steps.some((s) => s.id === "__end__")) return `Flow: step ID "${END_OF_FORM}" is reserved`;
21
56
  const ids = steps.map((s) => s.id);
22
57
  if (new Set(ids).size !== ids.length) return "Flow: duplicate step IDs found";
23
58
  const idSet = new Set(ids);
@@ -36,149 +71,409 @@ const providedFlowStepCount = (raw) => {
36
71
  const steps = raw.steps;
37
72
  return Array.isArray(steps) ? steps.length : 0;
38
73
  };
39
- const buildFormsCollection = ({ registry, ruleRegistry, consentRegistry, presentationRegistry = new Map(Object.entries(defaultPresentationDescriptors)), actionRegistry = /* @__PURE__ */ new Map() }) => {
74
+ /**
75
+ * Stamp the configured uploads collection slug onto every `file` block (including repeater
76
+ * sub-fields) on each save. The block carries a hidden `uploadsCollection` field so the slug
77
+ * reaches the client renderer through the form document; the server always overwrites it from
78
+ * plugin config, so the stored value is never author- or client-controlled.
79
+ */
80
+ const stampFileCollections = (rows, slug) => {
81
+ for (const row of rows) {
82
+ if (row.blockType === "file") row.uploadsCollection = slug;
83
+ const subFields = row.subFields;
84
+ if (Array.isArray(subFields)) stampFileCollections(subFields, slug);
85
+ }
86
+ };
87
+ const buildFormsCollection = ({ overrides, registry, ruleRegistry, consentSources, consentResolveOnRead, actionRegistry = /* @__PURE__ */ new Map(), localizeContent = true, richText, uploadsCollectionSlug, resultsAccess, pollSourceRegistry, pollTypeRegistry, outcomeFields, buttons, response, fromAddresses, departments, redirectRelationships }) => {
40
88
  const conditionTypes = buildConditionTypeMap(registry);
89
+ const pollTypes = pollTypeRegistry ?? resolvePollTypes();
90
+ const pollResultsTypes = pollEligibleTypes(registry);
91
+ const bareTypes = new Set([...registry.values()].filter((d) => d.bare === true).map((d) => d.type));
92
+ const bareTypeLabels = Object.fromEntries([...registry.values()].filter((d) => d.bare === true).map((d) => [d.type, d.label]));
93
+ const responseEditor = richText?.responseEditor ?? richText?.editor;
41
94
  const FLOW_BUILDER_REF = "@10x-media/form-builder/client#FlowBuilder";
95
+ const FIELD_NAME_SELECT_REF = "@10x-media/form-builder/client#FieldNameSelect";
96
+ const FLOW_STEPS_CELL_REF = "@10x-media/form-builder/client#FlowStepsCell";
97
+ const FIELD_COUNT_CELL_REF = "@10x-media/form-builder/client#FieldCountCell";
98
+ const CLOSE_POLL_BUTTON_REF = "@10x-media/form-builder/client#ClosePollButton";
99
+ const hasOptionSources = (pollSourceRegistry?.size ?? 0) > 0;
100
+ const orderedPollTypes = [...[...pollTypes.values()].filter((strategy) => strategy.type === "mostVoted"), ...[...pollTypes.values()].filter((strategy) => strategy.type !== "mostVoted")];
42
101
  const beforeValidate = ({ data, req }) => {
43
- if (data && typeof data.defaultPresentation === "string" && !presentationRegistry.has(data.defaultPresentation)) data.defaultPresentation = DEFAULT_PRESENTATION_NAME;
44
102
  if (data && Array.isArray(data.fields)) {
45
103
  const normalized = normalizeFormConditions(data.fields, conditionTypes);
46
104
  for (const field of normalized) if ("expression" in field) field.expression = normalizeCalc(field.expression);
105
+ if (uploadsCollectionSlug) stampFileCollections(normalized, uploadsCollectionSlug);
47
106
  data.fields = normalized;
48
- const fieldNames = normalized.map((field) => typeof field.name === "string" ? field.name : void 0).filter((name) => name !== void 0);
49
- const normalizedFlow = normalizeFlow(data.flow, fieldNames);
107
+ const fieldKeys = normalized.map((field) => {
108
+ if (typeof field.name === "string" && field.name.length > 0) return field.name;
109
+ return bareTypes.has(field.blockType) && field.id != null ? String(field.id) : void 0;
110
+ }).filter((key) => key !== void 0);
111
+ const operandTypes = buildOperandTypes(normalized, conditionTypes);
112
+ const normalizedFlow = normalizeFlow(data.flow, fieldKeys, (w) => normalizeWhere(w, operandTypes));
50
113
  if (providedFlowStepCount(data.flow) > 0 && normalizedFlow === void 0) throw new ValidationError({
51
114
  collection: FORMS_SLUG,
52
115
  errors: [{
53
116
  path: "flow",
54
- message: "A flow needs at least two steps with unique, non-empty IDs. Add another step or remove the flow."
117
+ message: "A flow needs at least two steps. Add another step or remove the flow."
55
118
  }]
56
119
  }, req.t);
57
120
  data.flow = normalizedFlow;
121
+ if (data.pollEnabled === true) {
122
+ const poll = data.poll != null && typeof data.poll === "object" ? data.poll : {};
123
+ const resultsField = typeof poll.resultsField === "string" ? poll.resultsField.trim() : "";
124
+ const sourceDriven = (typeof poll.optionSource === "string" ? poll.optionSource.trim() : "").length > 0 || poll.type === "source";
125
+ if (resultsField.length === 0 && !sourceDriven) {
126
+ const eligible = fieldNamesOfType(data.fields, pollResultsTypes);
127
+ if (eligible.length === 1) data.poll = {
128
+ ...poll,
129
+ resultsField: eligible[0]
130
+ };
131
+ else {
132
+ const messageKey = eligible.length > 1 ? keys.pollVoteFieldChoose : keys.pollVoteFieldMissing;
133
+ throw new ValidationError({
134
+ collection: FORMS_SLUG,
135
+ errors: [{
136
+ path: "poll.resultsField",
137
+ message: asTranslate(req.t)(messageKey)
138
+ }]
139
+ }, req.t);
140
+ }
141
+ }
142
+ }
58
143
  }
59
144
  return data;
60
145
  };
61
- return {
62
- slug: FORMS_SLUG,
63
- labels: {
64
- singular: "Form",
65
- plural: "Forms"
66
- },
67
- admin: {
68
- group: "Forms",
69
- useAsTitle: "title"
70
- },
71
- access: { read: () => true },
72
- hooks: { beforeValidate: [beforeValidate] },
146
+ const pollCloseAfterChange = async ({ doc, req }) => {
147
+ await enqueuePollClose({
148
+ payload: req.payload,
149
+ form: doc,
150
+ req
151
+ });
152
+ return doc;
153
+ };
154
+ const fieldsField = {
155
+ name: "fields",
156
+ type: "blocks",
157
+ blocks: buildFieldBlocks({
158
+ registry,
159
+ ruleRegistry,
160
+ localize: localizeContent
161
+ }),
162
+ admin: { components: { Cell: FIELD_COUNT_CELL_REF } }
163
+ };
164
+ const flowField = {
165
+ name: "flow",
166
+ type: "json",
167
+ validate: validateFlow,
168
+ admin: { components: {
169
+ Cell: FLOW_STEPS_CELL_REF,
170
+ Field: {
171
+ path: FLOW_BUILDER_REF,
172
+ clientProps: {
173
+ conditionTypes,
174
+ bareTypeLabels
175
+ }
176
+ }
177
+ } },
178
+ typescriptSchema: [() => ({
179
+ type: "object",
180
+ required: ["steps"],
181
+ additionalProperties: false,
182
+ properties: { steps: {
183
+ type: "array",
184
+ items: {
185
+ type: "object",
186
+ required: ["id"],
187
+ additionalProperties: true,
188
+ properties: {
189
+ id: { type: "string" },
190
+ title: { type: "string" },
191
+ fields: {
192
+ type: "array",
193
+ items: { type: "string" }
194
+ },
195
+ next: { type: ["string", "null"] },
196
+ transitions: {
197
+ type: "array",
198
+ items: {
199
+ type: "object",
200
+ required: ["to"],
201
+ additionalProperties: true,
202
+ properties: {
203
+ to: { type: "string" },
204
+ when: {
205
+ type: "object",
206
+ additionalProperties: true
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ } }
214
+ })]
215
+ };
216
+ const actionsField = {
217
+ name: "actions",
218
+ type: "blocks",
219
+ blocks: buildActionBlocks(actionRegistry),
220
+ label: labelForKey(keys.configActions),
221
+ access: { read: isLoggedIn }
222
+ };
223
+ const redirectReferenceField = redirectRelationships && redirectRelationships.length > 0 ? [{
224
+ name: "reference",
225
+ type: "relationship",
226
+ relationTo: redirectRelationships,
227
+ label: labelForKey(keys.responseRedirectReference),
228
+ admin: { description: labelForKey(keys.responseRedirectReferenceDescription) }
229
+ }] : [];
230
+ const defaultRedirectFields = [{
231
+ name: "url",
232
+ type: "text",
233
+ label: labelForKey(keys.responseUrl),
234
+ validate: validateUrl
235
+ }, ...redirectReferenceField];
236
+ const redirectFields = response?.redirect?.fields ? response.redirect.fields({ defaultFields: defaultRedirectFields }) : defaultRedirectFields;
237
+ const responseField = {
238
+ name: "response",
239
+ type: "group",
73
240
  fields: [
74
241
  {
75
- name: "title",
76
- type: "text",
77
- required: true,
78
- label: labelForKey(keys.fieldTitle)
242
+ name: "type",
243
+ type: "select",
244
+ defaultValue: "message",
245
+ label: labelForKey(keys.responseType),
246
+ admin: { isClearable: false },
247
+ options: [{
248
+ label: labelForKey(keys.responseTypeMessage),
249
+ value: "message"
250
+ }, {
251
+ label: labelForKey(keys.responseTypeRedirect),
252
+ value: "redirect"
253
+ }]
79
254
  },
80
255
  {
81
- name: "fields",
82
- type: "blocks",
83
- blocks: buildFieldBlocks(registry, ruleRegistry, consentRegistry)
256
+ name: "message",
257
+ type: "richText",
258
+ label: labelForKey(keys.responseMessage),
259
+ admin: { condition: (_data, siblingData) => siblingData?.type !== "redirect" },
260
+ ...responseEditor ? { editor: responseEditor } : {},
261
+ ...localizedIf(localizeContent)
84
262
  },
85
263
  {
86
- name: "flow",
87
- type: "json",
88
- validate: validateFlow,
264
+ name: "redirect",
265
+ type: "group",
266
+ label: labelForKey(keys.responseRedirect),
267
+ admin: {
268
+ condition: (_data, siblingData) => siblingData?.type === "redirect",
269
+ hideGutter: true
270
+ },
271
+ fields: redirectFields
272
+ }
273
+ ]
274
+ };
275
+ const defaultOutcomeFields = buildDefaultOutcomeFields();
276
+ const defaultButtonFields = buildDefaultButtonFields(localizeContent);
277
+ const halfWidth = (field) => ({
278
+ ...field,
279
+ admin: {
280
+ ...field.admin,
281
+ width: "50%"
282
+ }
283
+ });
284
+ const composedButtons = buttons?.fields ? buttons.fields({ defaultFields: defaultButtonFields }) : defaultButtonFields;
285
+ const submitField = composedButtons.submit;
286
+ const prevNextRow = {
287
+ type: "row",
288
+ admin: { condition: (data) => {
289
+ const steps = data?.flow?.steps;
290
+ return Array.isArray(steps) && steps.length >= 1;
291
+ } },
292
+ fields: [halfWidth(composedButtons.prev), halfWidth(composedButtons.next)]
293
+ };
294
+ const pollGroupField = {
295
+ name: "poll",
296
+ type: "group",
297
+ label: false,
298
+ fields: [
299
+ {
300
+ name: "resultsField",
301
+ type: "text",
302
+ label: labelForKey(keys.pollResultsField),
303
+ validate: buildValidateResultsField(pollResultsTypes),
89
304
  admin: { components: { Field: {
90
- path: FLOW_BUILDER_REF,
91
- clientProps: { conditionTypes }
92
- } } },
93
- typescriptSchema: [() => ({
94
- type: "object",
95
- required: ["steps"],
96
- additionalProperties: false,
97
- properties: { steps: {
98
- type: "array",
99
- items: {
100
- type: "object",
101
- required: ["id"],
102
- additionalProperties: true,
103
- properties: {
104
- id: { type: "string" },
105
- title: { type: "string" },
106
- fields: {
107
- type: "array",
108
- items: { type: "string" }
109
- },
110
- next: { type: "string" },
111
- transitions: {
112
- type: "array",
113
- items: {
114
- type: "object",
115
- required: ["to"],
116
- additionalProperties: true,
117
- properties: {
118
- to: { type: "string" },
119
- when: {
120
- type: "object",
121
- additionalProperties: true
122
- }
123
- }
124
- }
125
- }
126
- }
127
- }
128
- } }
129
- })]
305
+ path: FIELD_NAME_SELECT_REF,
306
+ clientProps: {
307
+ types: pollResultsTypes,
308
+ descriptionKey: keys.pollResultsFieldDescription
309
+ }
310
+ } } }
130
311
  },
131
312
  {
132
- name: "actions",
133
- type: "blocks",
134
- blocks: buildActionBlocks(actionRegistry),
135
- label: labelForKey(keys.configActions),
136
- access: { read: isLoggedIn }
313
+ name: "type",
314
+ type: "select",
315
+ defaultValue: "mostVoted",
316
+ label: labelForKey(keys.pollType),
317
+ admin: {
318
+ isClearable: false,
319
+ description: labelForKey(keys.pollTypeDescription)
320
+ },
321
+ options: orderedPollTypes.filter((strategy) => strategy.type !== "source" || hasOptionSources).map((strategy) => ({
322
+ label: resolveDefinitionLabel(strategy.label),
323
+ value: strategy.type
324
+ }))
137
325
  },
138
326
  {
139
- name: "defaultPresentation",
327
+ name: "resultsVisibility",
140
328
  type: "select",
141
- defaultValue: DEFAULT_PRESENTATION_NAME,
142
- options: [...presentationRegistry.values()].map((descriptor) => ({
143
- label: labelFor(descriptor.label),
144
- value: descriptor.name
145
- })),
146
- label: labelForKey(keys.configDefaultPresentation),
147
- admin: { position: "sidebar" }
329
+ defaultValue: "afterVote",
330
+ label: labelForKey(keys.pollResultsVisibility),
331
+ admin: { isClearable: false },
332
+ options: [{
333
+ label: labelForKey(keys.pollVisibilityAfterVote),
334
+ value: "afterVote"
335
+ }, {
336
+ label: labelForKey(keys.pollVisibilityAfterClose),
337
+ value: "afterClose"
338
+ }]
148
339
  },
149
340
  {
150
- name: "showResults",
151
- type: "checkbox",
152
- defaultValue: false,
153
- label: labelForKey(keys.configShowResults),
154
- admin: { position: "sidebar" }
341
+ name: "closesAt",
342
+ type: "date",
343
+ label: labelForKey(keys.pollClosesAt),
344
+ admin: { date: { pickerAppearance: "dayAndTime" } }
155
345
  },
156
346
  {
157
- name: "resultsField",
158
- type: "text",
159
- label: labelForKey(keys.configResultsField),
160
- admin: {
161
- position: "sidebar",
162
- description: "Field whose aggregate results are public when \"Show results publicly\" is on. Use a choice field, never a free-text or PII field.",
163
- condition: (data) => Boolean(data?.showResults)
164
- }
165
- }
166
- ],
167
- endpoints: [{
168
- path: "/:id/results",
169
- method: "get",
170
- handler: async (req) => {
171
- const field = typeof req.query?.field === "string" ? req.query.field : void 0;
172
- const { status, body } = await resolveFormResultsRequest({
173
- payload: req.payload,
174
- formId: req.routeParams?.id,
175
- field,
176
- isAuthed: Boolean(req.user),
177
- req
178
- });
179
- return Response.json(body, { status });
347
+ name: "closePoll",
348
+ type: "ui",
349
+ admin: { components: { Field: CLOSE_POLL_BUTTON_REF } }
350
+ },
351
+ ...buildPollOptionSourceFields(pollSourceRegistry ?? /* @__PURE__ */ new Map()),
352
+ {
353
+ name: "outcome",
354
+ type: "group",
355
+ label: labelForKey(keys.pollOutcome),
356
+ admin: { hideGutter: true },
357
+ fields: outcomeFields ? outcomeFields({ defaultFields: defaultOutcomeFields }) : [defaultOutcomeFields.winningValues, defaultOutcomeFields.resolvedAt]
180
358
  }
181
- }]
359
+ ]
360
+ };
361
+ const defaultFields = [
362
+ {
363
+ name: "title",
364
+ type: "text",
365
+ label: labelForKey(keys.fieldTitle),
366
+ ...localizedIf(localizeContent),
367
+ validate: validateFormTitle
368
+ },
369
+ {
370
+ type: "row",
371
+ fields: [{
372
+ name: "multistep",
373
+ type: "checkbox",
374
+ defaultValue: false,
375
+ label: labelForKey(keys.formMultistep),
376
+ admin: { width: "50%" }
377
+ }, {
378
+ name: "pollEnabled",
379
+ type: "checkbox",
380
+ defaultValue: false,
381
+ label: labelForKey(keys.formPollEnabled),
382
+ admin: { width: "50%" }
383
+ }]
384
+ },
385
+ {
386
+ type: "tabs",
387
+ tabs: [
388
+ {
389
+ label: labelForKey(keys.tabFields),
390
+ fields: [fieldsField, submitField]
391
+ },
392
+ {
393
+ label: labelForKey(keys.tabFlow),
394
+ admin: { condition: (_data, siblingData) => siblingData?.multistep === true },
395
+ fields: [flowField, prevNextRow]
396
+ },
397
+ {
398
+ label: labelForKey(keys.pollGroup),
399
+ admin: { condition: (_data, siblingData) => siblingData?.pollEnabled === true },
400
+ fields: [pollGroupField]
401
+ },
402
+ {
403
+ label: labelForKey(keys.tabActions),
404
+ fields: [actionsField]
405
+ },
406
+ {
407
+ label: labelForKey(keys.tabResponse),
408
+ fields: [responseField]
409
+ }
410
+ ]
411
+ }
412
+ ];
413
+ const consentAfterRead = consentSources && consentResolveOnRead !== false ? async ({ doc, req }) => {
414
+ const id = doc.id;
415
+ const key = id == null ? void 0 : String(id);
416
+ if (key !== void 0 && req.context) {
417
+ const inFlight = req.context[CONSENT_AFTER_READ_GUARD] ?? /* @__PURE__ */ new Set();
418
+ if (inFlight.has(key)) return doc;
419
+ inFlight.add(key);
420
+ req.context[CONSENT_AFTER_READ_GUARD] = inFlight;
421
+ }
422
+ try {
423
+ const statements = await resolveConsentStatements({
424
+ payload: req.payload,
425
+ req,
426
+ form: doc,
427
+ sources: consentSources
428
+ });
429
+ if (Object.keys(statements).length > 0) doc.consentStatements = statements;
430
+ } catch (error) {
431
+ req.payload.logger?.warn(`form-builder consent afterRead: ${String(error)}`);
432
+ } finally {
433
+ if (key !== void 0 && req.context) req.context[CONSENT_AFTER_READ_GUARD]?.delete(key);
434
+ }
435
+ return doc;
436
+ } : void 0;
437
+ const defaultEndpoints = buildFormsEndpoints({
438
+ resultsAccess,
439
+ pollResultsTypes,
440
+ consentSources,
441
+ fromAddresses,
442
+ departments
443
+ });
444
+ return {
445
+ ...overrides ?? {},
446
+ slug: FORMS_SLUG,
447
+ labels: {
448
+ singular: labelForKey(keys.collectionFormSingular),
449
+ plural: labelForKey(keys.collectionFormPlural),
450
+ ...overrides?.labels ?? {}
451
+ },
452
+ admin: {
453
+ group: "Forms",
454
+ useAsTitle: "title",
455
+ defaultColumns: [
456
+ "title",
457
+ "fields",
458
+ "flow",
459
+ "pollEnabled",
460
+ "updatedAt"
461
+ ],
462
+ ...overrides?.admin ?? {}
463
+ },
464
+ access: {
465
+ read: () => true,
466
+ ...overrides?.access ?? {}
467
+ },
468
+ hooks: {
469
+ ...overrides?.hooks ?? {},
470
+ beforeValidate: [beforeValidate, ...overrides?.hooks?.beforeValidate ?? []],
471
+ beforeChange: [pollOutcomeBeforeChange, ...overrides?.hooks?.beforeChange ?? []],
472
+ afterChange: [pollCloseAfterChange, ...overrides?.hooks?.afterChange ?? []],
473
+ afterRead: [...consentAfterRead ? [consentAfterRead] : [], ...overrides?.hooks?.afterRead ?? []]
474
+ },
475
+ endpoints: [...defaultEndpoints, ...Array.isArray(overrides?.endpoints) ? overrides.endpoints : []],
476
+ fields: overrides?.fields ? overrides.fields({ defaultFields }) : defaultFields
182
477
  };
183
478
  };
184
479
  //#endregion