payload-canvas 0.5.2 → 0.7.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (325) hide show
  1. package/README.md +350 -45
  2. package/dist/admin/AiKeyField.d.ts +4 -3
  3. package/dist/admin/AiKeyField.js +3 -3
  4. package/dist/admin/ArrayRowLabel.d.ts +12 -0
  5. package/dist/admin/ArrayRowLabel.js +21 -0
  6. package/dist/admin/BuilderTab.js +1 -1
  7. package/dist/admin/DocumentEditView.d.ts +1 -1
  8. package/dist/admin/DocumentEditView.js +2 -3
  9. package/dist/admin/LayoutField.d.ts +1 -1
  10. package/dist/admin/LayoutField.js +2 -2
  11. package/dist/admin/TemplateConditionsField.d.ts +2 -2
  12. package/dist/admin/TemplateConditionsField.js +2 -2
  13. package/dist/admin/aiKeyField.css +58 -0
  14. package/dist/admin/client.d.ts +1 -0
  15. package/dist/admin/client.js +2 -0
  16. package/dist/admin/diff/LayoutDiff.js +3 -3
  17. package/dist/admin/diff/LayoutJsonDiff.d.ts +1 -1
  18. package/dist/admin/diff/LayoutJsonDiff.js +1 -1
  19. package/dist/admin/diff/layoutDiff.css +180 -0
  20. package/dist/admin/editor/Editor.d.ts +2 -2
  21. package/dist/admin/editor/Editor.js +10 -3
  22. package/dist/admin/editor/Inspector.js +23 -17
  23. package/dist/admin/editor/Library.d.ts +2 -2
  24. package/dist/admin/editor/Library.js +8 -7
  25. package/dist/admin/editor/Outline.js +20 -12
  26. package/dist/admin/editor/Overlay.js +6 -4
  27. package/dist/admin/editor/actions.d.ts +7 -2
  28. package/dist/admin/editor/actions.js +44 -12
  29. package/dist/admin/editor/assistant/AssistantPanel.d.ts +1 -1
  30. package/dist/admin/editor/assistant/AssistantPanel.js +33 -21
  31. package/dist/admin/editor/assistant/{assistant.scss → assistant.css} +322 -315
  32. package/dist/admin/editor/classes/ClassManager.d.ts +1 -1
  33. package/dist/admin/editor/classes/ClassManager.js +1 -1
  34. package/dist/admin/editor/classes/manager.css +258 -0
  35. package/dist/admin/editor/comments/CommentLayer.d.ts +1 -1
  36. package/dist/admin/editor/comments/CommentLayer.js +1 -1
  37. package/dist/admin/editor/comments/CommentsPanel.d.ts +1 -1
  38. package/dist/admin/editor/comments/CommentsPanel.js +1 -1
  39. package/dist/admin/editor/comments/{comments.scss → comments.css} +121 -140
  40. package/dist/admin/editor/comments/controller.d.ts +7 -0
  41. package/dist/admin/editor/comments/controller.js +12 -0
  42. package/dist/admin/editor/comments/useCommentFromURL.d.ts +2 -0
  43. package/dist/admin/editor/comments/useCommentFromURL.js +36 -0
  44. package/dist/admin/editor/dnd/{dnd.scss → dnd.css} +78 -80
  45. package/dist/admin/editor/dnd/smooth.js +1 -1
  46. package/dist/admin/editor/{editor.scss → editor.css} +798 -751
  47. package/dist/admin/editor/empty/EmptyStart.d.ts +1 -1
  48. package/dist/admin/editor/empty/EmptyStart.js +3 -3
  49. package/dist/admin/editor/empty/{empty.scss → empty.css} +12 -13
  50. package/dist/admin/editor/fields/ArrayField.js +3 -3
  51. package/dist/admin/editor/fields/FormBlock.d.ts +20 -0
  52. package/dist/admin/editor/fields/FormBlock.js +167 -0
  53. package/dist/admin/editor/fields/FormFieldName.d.ts +25 -0
  54. package/dist/admin/editor/fields/FormFieldName.js +58 -0
  55. package/dist/admin/editor/fields/GroupField.d.ts +22 -2
  56. package/dist/admin/editor/fields/GroupField.js +30 -1
  57. package/dist/admin/editor/fields/MergeTags.d.ts +8 -0
  58. package/dist/admin/editor/fields/MergeTags.js +62 -0
  59. package/dist/admin/editor/fields/arrayRows.d.ts +0 -2
  60. package/dist/admin/editor/fields/arrayRows.js +0 -4
  61. package/dist/admin/editor/fields/fields.css +786 -0
  62. package/dist/admin/editor/fields/values.d.ts +0 -2
  63. package/dist/admin/editor/fields/values.js +0 -14
  64. package/dist/admin/editor/generate/GenerateImage.d.ts +1 -1
  65. package/dist/admin/editor/generate/GenerateImage.js +1 -1
  66. package/dist/admin/editor/generate/{generate.scss → generate.css} +83 -82
  67. package/dist/admin/editor/icons.d.ts +3 -0
  68. package/dist/admin/editor/icons.js +3 -0
  69. package/dist/admin/editor/insert/InsertHandle.js +1 -1
  70. package/dist/admin/editor/insert/picker.d.ts +3 -2
  71. package/dist/admin/editor/insert/picker.js +9 -3
  72. package/dist/admin/editor/layout/LeftPanel.js +5 -3
  73. package/dist/admin/editor/layout/layout.css +243 -0
  74. package/dist/admin/editor/layout/leftTabs.d.ts +15 -0
  75. package/dist/admin/editor/layout/leftTabs.js +18 -0
  76. package/dist/admin/editor/layout/panels.js +1 -1
  77. package/dist/admin/editor/live/PresenceUI.d.ts +1 -1
  78. package/dist/admin/editor/live/PresenceUI.js +2 -2
  79. package/dist/admin/editor/live/{presence.scss → presence.css} +5 -4
  80. package/dist/admin/editor/locale/LocaleField.d.ts +1 -1
  81. package/dist/admin/editor/locale/LocaleField.js +1 -1
  82. package/dist/admin/editor/locale/LocaleSwitcher.d.ts +1 -1
  83. package/dist/admin/editor/locale/LocaleSwitcher.js +1 -1
  84. package/dist/admin/editor/locale/locale.css +153 -0
  85. package/dist/admin/editor/media/ImageEditor.d.ts +9 -3
  86. package/dist/admin/editor/media/ImageEditor.js +17 -11
  87. package/dist/admin/editor/media/{media.scss → media.css} +70 -60
  88. package/dist/admin/editor/media/model.d.ts +10 -1
  89. package/dist/admin/editor/media/model.js +19 -0
  90. package/dist/admin/editor/menu/Menu.d.ts +1 -1
  91. package/dist/admin/editor/menu/Menu.js +1 -1
  92. package/dist/admin/editor/menu/blockMenu.js +3 -3
  93. package/dist/admin/editor/menu/menu.css +132 -0
  94. package/dist/admin/editor/motion/MotionPanel.d.ts +2 -2
  95. package/dist/admin/editor/motion/MotionPanel.js +2 -2
  96. package/dist/admin/editor/motion/{motion.scss → motion.css} +24 -21
  97. package/dist/admin/editor/names.d.ts +9 -0
  98. package/dist/admin/editor/names.js +18 -0
  99. package/dist/admin/editor/regions/RegionFields.d.ts +6 -0
  100. package/dist/admin/editor/regions/RegionFields.js +122 -0
  101. package/dist/admin/editor/regions/RegionPane.js +5 -3
  102. package/dist/admin/editor/regions/RegionRows.js +2 -2
  103. package/dist/admin/editor/regions/required.d.ts +16 -0
  104. package/dist/admin/editor/regions/required.js +43 -0
  105. package/dist/admin/editor/renderField.d.ts +10 -3
  106. package/dist/admin/editor/renderField.js +87 -33
  107. package/dist/admin/editor/runtime.d.ts +3 -2
  108. package/dist/admin/editor/runtime.js +12 -18
  109. package/dist/admin/editor/sections/ComponentFields.d.ts +1 -1
  110. package/dist/admin/editor/sections/ComponentFields.js +2 -3
  111. package/dist/admin/editor/sections/PropertyControls.d.ts +1 -1
  112. package/dist/admin/editor/sections/PropertyControls.js +1 -1
  113. package/dist/admin/editor/sections/components.css +244 -0
  114. package/dist/admin/editor/sections/variants.css +93 -0
  115. package/dist/admin/editor/sections/variants.d.ts +1 -1
  116. package/dist/admin/editor/sections/variants.js +1 -1
  117. package/dist/admin/editor/styles/ClassBar.d.ts +1 -1
  118. package/dist/admin/editor/styles/ClassBar.js +1 -1
  119. package/dist/admin/editor/styles/StylesPanel.d.ts +1 -1
  120. package/dist/admin/editor/styles/StylesPanel.js +5 -3
  121. package/dist/admin/editor/styles/{classes.scss → classes.css} +128 -125
  122. package/dist/admin/editor/styles/context.js +9 -4
  123. package/dist/admin/editor/styles/{styles.scss → styles.css} +368 -370
  124. package/dist/admin/editor/templates/Bindable.d.ts +1 -1
  125. package/dist/admin/editor/templates/Bindable.js +1 -1
  126. package/dist/admin/editor/templates/binding.js +4 -1
  127. package/dist/admin/editor/templates/{templates.scss → templates.css} +207 -206
  128. package/dist/admin/editor/tooltip/Tooltips.d.ts +1 -1
  129. package/dist/admin/editor/tooltip/Tooltips.js +1 -1
  130. package/dist/admin/editor/tooltip/{tooltip.scss → tooltip.css} +11 -10
  131. package/dist/admin/editor/topbar/ContentModeToggle.d.ts +1 -1
  132. package/dist/admin/editor/topbar/ContentModeToggle.js +2 -2
  133. package/dist/admin/editor/topbar/DocumentActions.js +5 -5
  134. package/dist/admin/editor/topbar/TopBar.d.ts +1 -1
  135. package/dist/admin/editor/topbar/TopBar.js +2 -3
  136. package/dist/admin/editor/topbar/contentMode.css +25 -0
  137. package/dist/admin/editor/topbar/screens/DrawerRouter.d.ts +1 -1
  138. package/dist/admin/editor/topbar/screens/DrawerRouter.js +52 -40
  139. package/dist/admin/editor/topbar/screens/ScreenDrawer.d.ts +1 -1
  140. package/dist/admin/editor/topbar/screens/ScreenDrawer.js +4 -5
  141. package/dist/admin/editor/topbar/screens/drawerRouterSupport.d.ts +5 -5
  142. package/dist/admin/editor/topbar/screens/drawerRouterSupport.js +7 -7
  143. package/dist/admin/editor/topbar/screens/screens.css +139 -0
  144. package/dist/admin/editor/topbar/settingsDrawer.css +33 -0
  145. package/dist/admin/editor/topbar/settingsDrawer.d.ts +1 -1
  146. package/dist/admin/editor/topbar/settingsDrawer.js +3 -3
  147. package/dist/admin/editor/topbar/{topbar.scss → topbar.css} +189 -231
  148. package/dist/admin/editor/ui/Select.d.ts +1 -1
  149. package/dist/admin/editor/ui/Select.js +1 -1
  150. package/dist/admin/editor/ui/Slider.d.ts +1 -1
  151. package/dist/admin/editor/ui/Slider.js +1 -1
  152. package/dist/admin/editor/ui/Tabs.d.ts +17 -0
  153. package/dist/admin/editor/ui/Tabs.js +17 -0
  154. package/dist/admin/editor/ui/controls.css +301 -0
  155. package/dist/admin/forms/SubmissionCells.d.ts +6 -0
  156. package/dist/admin/forms/SubmissionCells.js +31 -0
  157. package/dist/admin/forms/SubmissionView.d.ts +5 -0
  158. package/dist/admin/forms/SubmissionView.js +106 -0
  159. package/dist/admin/forms/submissionData.d.ts +32 -0
  160. package/dist/admin/forms/submissionData.js +63 -0
  161. package/dist/admin/forms/submissions.css +200 -0
  162. package/dist/admin/layoutField.css +70 -0
  163. package/dist/admin/rsc.d.ts +2 -0
  164. package/dist/admin/rsc.js +5 -0
  165. package/dist/admin/screen/BuilderScreen.d.ts +1 -1
  166. package/dist/admin/screen/BuilderScreen.js +1 -1
  167. package/dist/admin/templateConditions.css +25 -0
  168. package/dist/ai/endpoint.d.ts +5 -0
  169. package/dist/ai/endpoint.js +18 -8
  170. package/dist/ai/images/service.js +2 -2
  171. package/dist/ai/prompt.d.ts +8 -0
  172. package/dist/ai/prompt.js +30 -0
  173. package/dist/ai/settings/index.js +3 -0
  174. package/dist/ai/tools.d.ts +6 -1
  175. package/dist/ai/tools.js +90 -6
  176. package/dist/blocks/builtins/carousel.js +10 -1
  177. package/dist/blocks/index.d.ts +1 -1
  178. package/dist/blocks/index.js +1 -1
  179. package/dist/blocks/payload.d.ts +7 -0
  180. package/dist/blocks/payload.js +16 -2
  181. package/dist/classes/collection.js +1 -0
  182. package/dist/classes/sheet.js +2 -0
  183. package/dist/comments/collection.js +3 -0
  184. package/dist/comments/shared.d.ts +5 -0
  185. package/dist/comments/shared.js +5 -0
  186. package/dist/core/blocks.d.ts +17 -3
  187. package/dist/core/blocks.js +92 -10
  188. package/dist/core/classes.d.ts +5 -0
  189. package/dist/core/classes.js +26 -1
  190. package/dist/core/conditions.d.ts +7 -0
  191. package/dist/core/conditions.js +22 -0
  192. package/dist/core/dropTarget.d.ts +3 -2
  193. package/dist/core/dropTarget.js +7 -1
  194. package/dist/core/fieldHooks.d.ts +1 -1
  195. package/dist/core/index.d.ts +6 -3
  196. package/dist/core/index.js +6 -3
  197. package/dist/core/payloadBlocks.js +25 -3
  198. package/dist/core/references.d.ts +7 -0
  199. package/dist/core/references.js +29 -11
  200. package/dist/core/regions.d.ts +14 -0
  201. package/dist/core/regions.js +17 -1
  202. package/dist/core/rowLabel.d.ts +8 -0
  203. package/dist/core/rowLabel.js +98 -0
  204. package/dist/core/starter.d.ts +10 -0
  205. package/dist/core/starter.js +40 -0
  206. package/dist/core/tree.js +4 -0
  207. package/dist/core/types.d.ts +96 -0
  208. package/dist/core/uniqueProps.d.ts +40 -0
  209. package/dist/core/uniqueProps.js +156 -0
  210. package/dist/core/validate.js +43 -3
  211. package/dist/forms/answers.d.ts +21 -0
  212. package/dist/forms/answers.js +82 -0
  213. package/dist/forms/blocks.d.ts +33 -0
  214. package/dist/forms/blocks.js +178 -0
  215. package/dist/forms/conditions.d.ts +78 -0
  216. package/dist/forms/conditions.js +184 -0
  217. package/dist/forms/emails.d.ts +23 -0
  218. package/dist/forms/emails.js +64 -0
  219. package/dist/forms/fieldConfigs.d.ts +35 -0
  220. package/dist/forms/fieldConfigs.js +167 -0
  221. package/dist/forms/fieldOps.d.ts +78 -0
  222. package/dist/forms/fieldOps.js +378 -0
  223. package/dist/forms/fieldSettings.d.ts +81 -0
  224. package/dist/forms/fieldSettings.js +239 -0
  225. package/dist/forms/files.d.ts +54 -0
  226. package/dist/forms/files.js +128 -0
  227. package/dist/forms/index.d.ts +16 -0
  228. package/dist/forms/index.js +18 -0
  229. package/dist/forms/mergeTags.d.ts +103 -0
  230. package/dist/forms/mergeTags.js +150 -0
  231. package/dist/forms/noScript.d.ts +60 -0
  232. package/dist/forms/noScript.js +109 -0
  233. package/dist/forms/pageForms.d.ts +99 -0
  234. package/dist/forms/pageForms.js +294 -0
  235. package/dist/forms/pageSync.d.ts +91 -0
  236. package/dist/forms/pageSync.js +325 -0
  237. package/dist/forms/rateLimit.d.ts +21 -0
  238. package/dist/forms/rateLimit.js +50 -0
  239. package/dist/forms/settings.d.ts +13 -0
  240. package/dist/forms/settings.js +92 -0
  241. package/dist/forms/spam.d.ts +100 -0
  242. package/dist/forms/spam.js +218 -0
  243. package/dist/forms/spamSettings.d.ts +43 -0
  244. package/dist/forms/spamSettings.js +25 -0
  245. package/dist/forms/submission.d.ts +34 -0
  246. package/dist/forms/submission.js +89 -0
  247. package/dist/forms/submissionsAdmin.d.ts +26 -0
  248. package/dist/forms/submissionsAdmin.js +108 -0
  249. package/dist/forms/summary.d.ts +60 -0
  250. package/dist/forms/summary.js +113 -0
  251. package/dist/forms/uploads.d.ts +41 -0
  252. package/dist/forms/uploads.js +132 -0
  253. package/dist/index.d.ts +8 -2
  254. package/dist/index.js +8 -2
  255. package/dist/live/document.d.ts +12 -0
  256. package/dist/live/document.js +8 -1
  257. package/dist/live/draftAccess.js +1 -1
  258. package/dist/live/endpoints.d.ts +1 -0
  259. package/dist/live/session.js +3 -1
  260. package/dist/live/storage.d.ts +13 -2
  261. package/dist/live/storage.js +18 -7
  262. package/dist/mcp/forms.d.ts +26 -0
  263. package/dist/mcp/forms.js +280 -0
  264. package/dist/mcp/index.d.ts +7 -0
  265. package/dist/mcp/index.js +29 -10
  266. package/dist/mcp/shared.d.ts +1 -0
  267. package/dist/mcp/shared.js +1 -0
  268. package/dist/plugin/forms.d.ts +30 -0
  269. package/dist/plugin/forms.js +63 -0
  270. package/dist/plugin/formsSync.d.ts +138 -0
  271. package/dist/plugin/formsSync.js +345 -0
  272. package/dist/plugin/hook.d.ts +22 -0
  273. package/dist/plugin/hook.js +19 -7
  274. package/dist/plugin/index.d.ts +14 -0
  275. package/dist/plugin/index.js +101 -30
  276. package/dist/plugin/links.d.ts +7 -2
  277. package/dist/plugin/links.js +9 -3
  278. package/dist/plugin/references.d.ts +6 -0
  279. package/dist/plugin/references.js +12 -0
  280. package/dist/plugin/sections.js +3 -0
  281. package/dist/plugin/templates.js +5 -1
  282. package/dist/react/canvas/BuilderCanvas.d.ts +2 -0
  283. package/dist/react/canvas/BuilderCanvas.js +29 -6
  284. package/dist/react/canvas/inline/candidates.js +2 -2
  285. package/dist/react/canvas/inline/mapper.d.ts +6 -1
  286. package/dist/react/canvas/inline/mapper.js +35 -4
  287. package/dist/react/canvas/inline/rich/editor.js +9 -1
  288. package/dist/react/components/Image.d.ts +1 -1
  289. package/dist/react/components/Image.js +2 -2
  290. package/dist/react/render/LayoutOutlet.d.ts +7 -3
  291. package/dist/react/render/LayoutOutlet.js +9 -4
  292. package/dist/react/render/RenderLayout.js +13 -7
  293. package/dist/react/render/resolve.d.ts +1 -0
  294. package/dist/react/render/resolve.js +7 -1
  295. package/dist/react/render/templates.js +3 -1
  296. package/dist/react/server.js +19 -0
  297. package/dist/react/theme/ThemeStyle.js +1 -1
  298. package/dist/theme/admin/ColorField.d.ts +4 -3
  299. package/dist/theme/admin/ColorField.js +1 -1
  300. package/dist/theme/admin/FontField.d.ts +4 -3
  301. package/dist/theme/admin/FontField.js +1 -1
  302. package/dist/theme/admin/SaveSignal.js +1 -1
  303. package/dist/theme/admin/SliderField.d.ts +1 -1
  304. package/dist/theme/admin/SliderField.js +1 -1
  305. package/dist/theme/admin/Variables.d.ts +4 -3
  306. package/dist/theme/admin/Variables.js +2 -2
  307. package/dist/theme/admin/fields.css +327 -0
  308. package/dist/theme/global.js +2 -0
  309. package/package.json +29 -24
  310. package/dist/admin/aiKeyField.scss +0 -58
  311. package/dist/admin/diff/layoutDiff.scss +0 -181
  312. package/dist/admin/editor/classes/manager.scss +0 -262
  313. package/dist/admin/editor/fields/fields.scss +0 -628
  314. package/dist/admin/editor/layout/layout.scss +0 -240
  315. package/dist/admin/editor/locale/locale.scss +0 -154
  316. package/dist/admin/editor/menu/menu.scss +0 -132
  317. package/dist/admin/editor/sections/components.scss +0 -238
  318. package/dist/admin/editor/sections/variants.scss +0 -90
  319. package/dist/admin/editor/topbar/contentMode.scss +0 -35
  320. package/dist/admin/editor/topbar/screens/screens.scss +0 -134
  321. package/dist/admin/editor/topbar/settingsDrawer.scss +0 -32
  322. package/dist/admin/editor/ui/controls.scss +0 -320
  323. package/dist/admin/layoutField.scss +0 -69
  324. package/dist/admin/templateConditions.scss +0 -24
  325. package/dist/theme/admin/fields.scss +0 -363
@@ -0,0 +1,239 @@
1
+ // Gravity Forms style settings for the field blocks of `@payloadcms/plugin-form-builder`:
2
+ // description, placeholder, default value, label visibility, the display of radio buttons, and
3
+ // several files for a file field, plus the hidden fields that store the field's classes (the
4
+ // builder's Styles panel). Only settings that change the content, the markup or the behaviour:
5
+ // looks, the width too, are classes. `withFormFieldSettings` adds the settings a block lacks and
6
+ // hides the plugin's `width`; the builder sorts them into its Field / Validation tabs. Client-safe
7
+ // and pure: the site's form renderer reads the same helpers.
8
+ import { BLOCK_KEY_MARKER } from '../blocks/payload.js';
9
+ import { FORM_CONDITIONS_FIELD } from './conditions.js';
10
+ /** The row key of a field's own classes (the box around label and input). Older forms typed them as "CSS class". */
11
+ export const FORM_FIELD_CLASS_KEY = 'cssClass';
12
+ /** The row key of a field's part classes (label, input, help text, error, options). */
13
+ export const FORM_FIELD_PARTS_KEY = 'partClasses';
14
+ /** The plugin's `width` setting: a percentage of the row. The builder sets a field's width with classes instead. */
15
+ export const FORM_FIELD_WIDTH_KEY = 'width';
16
+ /**
17
+ * The classes of the old width presets (percent of the row -> the field's width from the `sm`
18
+ * breakpoint, less its share of the 1rem gap between fields, so the fields of one row fit). Full
19
+ * width has no class. The site drew these before the field's width moved to the Styles panel.
20
+ */
21
+ export const FORM_FIELD_WIDTH_CLASSES = {
22
+ 75: 'sm:w-[calc(75%-0.25rem)]',
23
+ 67: 'sm:w-[calc(66.667%-0.333rem)]',
24
+ 50: 'sm:w-[calc(50%-0.5rem)]',
25
+ 33: 'sm:w-[calc(33.333%-0.667rem)]',
26
+ 25: 'sm:w-[calc(25%-0.75rem)]',
27
+ };
28
+ /**
29
+ * The class of a stored width: the smallest preset that holds it (40 -> the 50% class). No width,
30
+ * 0, above 75 or not a number: '' (full width).
31
+ */
32
+ export function formFieldWidthClass(width) {
33
+ const percent = typeof width === 'number' ? width : typeof width === 'string' && width.trim() ? Number(width) : Number.NaN;
34
+ if (!Number.isFinite(percent) || percent <= 0 || percent > 75)
35
+ return '';
36
+ if (percent <= 25)
37
+ return FORM_FIELD_WIDTH_CLASSES[25];
38
+ if (percent <= 34)
39
+ return FORM_FIELD_WIDTH_CLASSES[33];
40
+ if (percent <= 50)
41
+ return FORM_FIELD_WIDTH_CLASSES[50];
42
+ if (percent <= 67)
43
+ return FORM_FIELD_WIDTH_CLASSES[67];
44
+ return FORM_FIELD_WIDTH_CLASSES[75];
45
+ }
46
+ /** A class that sizes the box in a row or grid: width, size, flex basis, flex, grow, column span. */
47
+ const SIZING_CLASS = /^!?-?(w-|size-|basis-|col-span-|flex-(\d|auto|initial|\[)|grow(-|$))/;
48
+ /** True when the classes set the box's width (at any breakpoint or state). */
49
+ export function setsWidth(className) {
50
+ return (className ?? '').split(/\s+/).some((name) => SIZING_CLASS.test(name.slice(name.lastIndexOf(':') + 1)));
51
+ }
52
+ /**
53
+ * The field's classes with the class of its stored `width` added, unless they set a width
54
+ * themselves. The same classes when there is nothing to add. The site renders old fields with it,
55
+ * and `withWidthClass` stores it.
56
+ */
57
+ export function withStoredWidth(className, width) {
58
+ const own = className?.trim() ?? '';
59
+ const widthClass = formFieldWidthClass(width);
60
+ if (!widthClass || setsWidth(own))
61
+ return own;
62
+ return own ? `${own} ${widthClass}` : widthClass;
63
+ }
64
+ /**
65
+ * A form field block of the time before widths were classes: its stored `width` becomes classes
66
+ * (see `withStoredWidth`) and `width` becomes `null`, so the next save clears the plugin's value
67
+ * and only the classes decide the width. The same block when it has no width. The builder runs it
68
+ * when it opens a layout (`BlockDefinition.upgrade`).
69
+ */
70
+ export function withWidthClass(block) {
71
+ const width = block.props?.[FORM_FIELD_WIDTH_KEY];
72
+ if (width === undefined || width === null)
73
+ return block;
74
+ const next = { ...block, props: { ...block.props, [FORM_FIELD_WIDTH_KEY]: null } };
75
+ const className = withStoredWidth(block.className, width);
76
+ if (className)
77
+ next.className = className;
78
+ return next;
79
+ }
80
+ /** How radio buttons show: one per line, on one line, as joined buttons, or as cards. */
81
+ export const RADIO_DISPLAYS = ['list', 'inline', 'buttons', 'cards'];
82
+ /** The display of a radio field. Unknown or missing: "list". */
83
+ export function radioDisplay(value) {
84
+ return RADIO_DISPLAYS.includes(value) ? value : 'list';
85
+ }
86
+ /** Most files a file field takes when it allows several and sets no number. */
87
+ export const DEFAULT_MAX_FILES = 5;
88
+ /** Upper limit of `maxFiles`. */
89
+ export const MAX_FILES_LIMIT = 20;
90
+ /** How many files a file field takes: 1, or its `maxFiles` (default 5, at most 20) when it allows several. */
91
+ export function maxFileCount(field) {
92
+ if (!field.multiple)
93
+ return 1;
94
+ const own = typeof field.maxFiles === 'number' && Number.isFinite(field.maxFiles) && field.maxFiles >= 1 ? Math.floor(field.maxFiles) : DEFAULT_MAX_FILES;
95
+ return Math.min(own, MAX_FILES_LIMIT);
96
+ }
97
+ /** True when the field's label shows. "hidden" keeps it for screen readers only. */
98
+ export const isLabelShown = (field) => field.labelVisibility !== 'hidden';
99
+ /** The settings and the field types each one is for. */
100
+ const SETTING_TYPES = {
101
+ description: ['text', 'email', 'textarea', 'number', 'phone', 'url', 'select', 'radio', 'checkbox', 'consent', 'country', 'state', 'date', 'file'],
102
+ placeholder: ['text', 'email', 'textarea', 'number', 'phone', 'url', 'select', 'country', 'state'],
103
+ defaultValue: ['email', 'country', 'state'],
104
+ labelVisibility: ['text', 'email', 'textarea', 'number', 'phone', 'url', 'select', 'radio', 'country', 'state', 'date', 'file'],
105
+ display: ['radio'],
106
+ multiple: ['file'],
107
+ classes: ['text', 'email', 'textarea', 'number', 'phone', 'url', 'select', 'radio', 'checkbox', 'consent', 'country', 'state', 'date', 'file', 'message'],
108
+ };
109
+ /** A file field's "Allow several files" box and its "Most files" number. */
110
+ export function fileCountFields() {
111
+ return [
112
+ { name: 'multiple', type: 'checkbox', label: 'Allow several files' },
113
+ {
114
+ name: 'maxFiles',
115
+ type: 'number',
116
+ label: 'Most files',
117
+ min: 1,
118
+ max: MAX_FILES_LIMIT,
119
+ admin: {
120
+ placeholder: String(DEFAULT_MAX_FILES),
121
+ description: `Empty: ${DEFAULT_MAX_FILES}. At most ${MAX_FILES_LIMIT}.`,
122
+ condition: (_, siblings) => siblings?.multiple === true,
123
+ custom: { builderCondition: { field: 'multiple', truthy: true } },
124
+ },
125
+ },
126
+ ];
127
+ }
128
+ const SETTINGS = {
129
+ description: [
130
+ {
131
+ name: 'description',
132
+ type: 'textarea',
133
+ label: 'Description',
134
+ localized: true,
135
+ admin: { description: 'Help text under the field, for example what to write or why you ask.' },
136
+ },
137
+ ],
138
+ labelVisibility: [
139
+ {
140
+ name: 'labelVisibility',
141
+ type: 'select',
142
+ label: 'Label visibility',
143
+ defaultValue: 'visible',
144
+ options: [
145
+ { label: 'Visible', value: 'visible' },
146
+ { label: 'Hidden, read by screen readers', value: 'hidden' },
147
+ ],
148
+ },
149
+ ],
150
+ placeholder: [{ name: 'placeholder', type: 'text', label: 'Placeholder', localized: true, admin: { description: 'Grey text inside the empty field.' } }],
151
+ defaultValue: [{ name: 'defaultValue', type: 'text', label: 'Default value', localized: true }],
152
+ display: [
153
+ {
154
+ name: 'display',
155
+ type: 'select',
156
+ label: 'Display',
157
+ defaultValue: 'list',
158
+ options: [
159
+ { label: 'List', value: 'list' },
160
+ { label: 'Inline', value: 'inline' },
161
+ { label: 'Buttons', value: 'buttons' },
162
+ { label: 'Cards', value: 'cards' },
163
+ ],
164
+ admin: { description: 'List: one option per line. Inline: on one line. Buttons: joined buttons. Cards: a box per option.' },
165
+ },
166
+ ],
167
+ multiple: fileCountFields(),
168
+ // Edited in the builder's Styles panel (`payload.classKeys`), hidden in Payload's own form.
169
+ classes: [
170
+ { name: FORM_FIELD_CLASS_KEY, type: 'text', label: 'CSS class', admin: { hidden: true, custom: { [BLOCK_KEY_MARKER]: 'className' } } },
171
+ { name: FORM_FIELD_PARTS_KEY, type: 'json', label: 'Part classes', admin: { hidden: true, custom: { [BLOCK_KEY_MARKER]: 'partClassName' } } },
172
+ ],
173
+ };
174
+ /**
175
+ * The fields with the plugin's `width` number (also inside rows) hidden: a field's width is its
176
+ * classes now (Styles panel). The stored value stays readable (`withWidthClass`). The same list
177
+ * when there is no visible width.
178
+ */
179
+ export function withHiddenWidth(fields) {
180
+ let changed = false;
181
+ const out = fields.map((raw) => {
182
+ const field = raw;
183
+ if (Array.isArray(field.fields) && !field.name) {
184
+ const inner = withHiddenWidth(field.fields);
185
+ if (inner === field.fields)
186
+ return raw;
187
+ changed = true;
188
+ return { ...field, fields: inner };
189
+ }
190
+ const admin = (field.admin ?? {});
191
+ if (field.name !== FORM_FIELD_WIDTH_KEY || field.type !== 'number' || admin.hidden)
192
+ return raw;
193
+ changed = true;
194
+ return { ...field, admin: { ...admin, hidden: true } };
195
+ });
196
+ return changed ? out : fields;
197
+ }
198
+ /** The names of the data fields of a list, also inside rows, collapsibles and unnamed tabs. */
199
+ function fieldNames(fields) {
200
+ const out = new Set();
201
+ for (const field of fields) {
202
+ if ('name' in field && typeof field.name === 'string' && field.name)
203
+ out.add(field.name);
204
+ else if ('fields' in field && Array.isArray(field.fields))
205
+ for (const name of fieldNames(field.fields))
206
+ out.add(name);
207
+ else if (field.type === 'tabs')
208
+ for (const tab of field.tabs)
209
+ if (!('name' in tab && tab.name))
210
+ for (const name of fieldNames(tab.fields))
211
+ out.add(name);
212
+ }
213
+ return out;
214
+ }
215
+ /**
216
+ * The block with the settings it lacks for its type: description, placeholder, default value,
217
+ * label visibility, radio display, several files, and the hidden class fields (the field's classes
218
+ * and part classes, edited in the builder's Styles panel; the old "CSS class" values stay). The
219
+ * description goes right after the label; the other settings go before the display conditions.
220
+ * The plugin's `width` is hidden (`withHiddenWidth`): the width is classes. Known types only; a
221
+ * setting the block has already stays as it is. For the form-builder plugin's `fields` option:
222
+ * `withFormFieldSettings(fields.text)`. The plugin stores form fields as JSON, so no migration is needed.
223
+ */
224
+ export function withFormFieldSettings(block) {
225
+ const have = fieldNames(block.fields);
226
+ const missing = (key) => SETTING_TYPES[key].includes(block.slug) ? SETTINGS[key].filter((field) => 'name' in field && !have.has(field.name)) : [];
227
+ const description = missing('description');
228
+ const rest = Object.keys(SETTING_TYPES).filter((key) => key !== 'description').flatMap(missing);
229
+ const hidden = withHiddenWidth(block.fields);
230
+ if (description.length === 0 && rest.length === 0)
231
+ return hidden === block.fields ? block : { ...block, fields: hidden };
232
+ const labelAt = hidden.findIndex((field) => fieldNames([field]).has('label'));
233
+ const fields = [...hidden];
234
+ if (labelAt !== -1)
235
+ fields.splice(labelAt + 1, 0, ...description);
236
+ const conditionsAt = fields.findIndex((field) => 'name' in field && field.name === FORM_CONDITIONS_FIELD);
237
+ fields.splice(conditionsAt === -1 ? fields.length : conditionsAt, 0, ...(labelAt === -1 ? description : []), ...rest);
238
+ return { ...block, fields };
239
+ }
@@ -0,0 +1,54 @@
1
+ /** The file field's limits: `accept` as in `<input accept>`, `maxSize` in MB. */
2
+ export type FileRules = {
3
+ accept?: string | null;
4
+ maxSize?: number | null;
5
+ };
6
+ /** The patterns of an `accept` text: "image/*, .pdf" -> ["image/*", ".pdf"]. */
7
+ export declare const acceptPatterns: (accept: string | null | undefined) => string[];
8
+ /** The largest size in bytes: the field's own, at most `limitMb`. */
9
+ export declare function maxFileBytes(rules: FileRules, limitMb?: number): number;
10
+ /**
11
+ * The types a file field takes when its `accept` is empty: images (not SVG), PDF, common office
12
+ * documents, text and CSV. Never "any type": a stored file opens on the site's own address.
13
+ */
14
+ export declare const DEFAULT_FILE_ACCEPT = ".jpg, .jpeg, .png, .gif, .webp, .avif, .heic, .pdf, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .odt, .ods, .odp, .rtf, .txt, .csv";
15
+ /** File endings never taken, whatever `accept` says: files a browser runs as a page or a script. */
16
+ export declare const BLOCKED_FILE_ENDINGS: readonly ['html', 'htm', 'xhtml', 'shtml', 'svg', 'svgz', 'js', 'mjs', 'cjs', 'xml', 'xsl', 'xslt'];
17
+ /** MIME types never taken, whatever `accept` says (also every `…+xml` type). */
18
+ export declare const BLOCKED_MIME_TYPES: readonly ['text/html', 'application/xhtml+xml', 'image/svg+xml', 'text/javascript', 'application/javascript', 'application/x-javascript', 'application/ecmascript', 'text/ecmascript', 'application/xml', 'text/xml'];
19
+ /** True for a file that is never taken: its ending or MIME type is one a browser runs (HTML, SVG, scripts, XML). */
20
+ export declare function fileTypeBlocked(file: {
21
+ name: string;
22
+ mimetype: string;
23
+ }): boolean;
24
+ /**
25
+ * True when the field takes the file: never a blocked type (`fileTypeBlocked`); else its name ends
26
+ * with one of the endings in `accept` (".pdf"), or both its MIME type and the type of its ending
27
+ * match a MIME pattern ("image/*"), so a file never passes on the type the browser claims alone.
28
+ * An empty `accept` takes `DEFAULT_FILE_ACCEPT`.
29
+ */
30
+ export declare function fileTypeAllowed(file: {
31
+ name: string;
32
+ mimetype: string;
33
+ }, accept: string | null | undefined): boolean;
34
+ /** The message for a file, or '' when it is fine. */
35
+ export declare function fileProblem(file: {
36
+ name: string;
37
+ mimetype: string;
38
+ size: number;
39
+ }, rules: FileRules, limitMb?: number): string;
40
+ /** A file field's rules for the files it takes: required, several files, the most files. */
41
+ export type FileCountRules = FileRules & {
42
+ required?: boolean | null;
43
+ multiple?: boolean | null;
44
+ maxFiles?: number | null;
45
+ };
46
+ /**
47
+ * The message for the files of one file field, or '' when they are fine: none when it is required,
48
+ * more than it takes, then each file's type and size. With several files the message names the file.
49
+ */
50
+ export declare function filesProblem(files: ReadonlyArray<{
51
+ name: string;
52
+ mimetype: string;
53
+ size: number;
54
+ }>, rules: FileCountRules, limitMb?: number): string;
@@ -0,0 +1,128 @@
1
+ // Checks of the files of a `file` form field: their number, type (as in `<input accept>`, checked by
2
+ // the file's ending and its MIME type; HTML, SVG, scripts and XML never) and size. Pure and
3
+ // client-safe: the site's form checks a file when the visitor picks it, `formFileUploads` again.
4
+ import { FILE_FIELD_MAX_MB } from './fieldConfigs.js';
5
+ import { maxFileCount } from './fieldSettings.js';
6
+ const MB = 1024 * 1024;
7
+ /** The patterns of an `accept` text: "image/*, .pdf" -> ["image/*", ".pdf"]. */
8
+ export const acceptPatterns = (accept) => (accept ?? '')
9
+ .split(',')
10
+ .map((p) => p.trim().toLowerCase())
11
+ .filter(Boolean);
12
+ /** The largest size in bytes: the field's own, at most `limitMb`. */
13
+ export function maxFileBytes(rules, limitMb = FILE_FIELD_MAX_MB) {
14
+ const own = typeof rules.maxSize === 'number' && rules.maxSize > 0 ? rules.maxSize : limitMb;
15
+ return Math.min(own, limitMb) * MB;
16
+ }
17
+ /** The MIME type of common file endings, to check a file's ending against MIME patterns ("image/*"). */
18
+ const MIME_OF_ENDING = {
19
+ jpg: 'image/jpeg',
20
+ jpeg: 'image/jpeg',
21
+ png: 'image/png',
22
+ gif: 'image/gif',
23
+ webp: 'image/webp',
24
+ avif: 'image/avif',
25
+ heic: 'image/heic',
26
+ heif: 'image/heif',
27
+ bmp: 'image/bmp',
28
+ tif: 'image/tiff',
29
+ tiff: 'image/tiff',
30
+ pdf: 'application/pdf',
31
+ doc: 'application/msword',
32
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
33
+ xls: 'application/vnd.ms-excel',
34
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
35
+ ppt: 'application/vnd.ms-powerpoint',
36
+ pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
37
+ odt: 'application/vnd.oasis.opendocument.text',
38
+ ods: 'application/vnd.oasis.opendocument.spreadsheet',
39
+ odp: 'application/vnd.oasis.opendocument.presentation',
40
+ rtf: 'application/rtf',
41
+ txt: 'text/plain',
42
+ csv: 'text/csv',
43
+ md: 'text/markdown',
44
+ zip: 'application/zip',
45
+ mp3: 'audio/mpeg',
46
+ wav: 'audio/wav',
47
+ mp4: 'video/mp4',
48
+ mov: 'video/quicktime',
49
+ webm: 'video/webm',
50
+ };
51
+ /**
52
+ * The types a file field takes when its `accept` is empty: images (not SVG), PDF, common office
53
+ * documents, text and CSV. Never "any type": a stored file opens on the site's own address.
54
+ */
55
+ export const DEFAULT_FILE_ACCEPT = '.jpg, .jpeg, .png, .gif, .webp, .avif, .heic, .pdf, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .odt, .ods, .odp, .rtf, .txt, .csv';
56
+ /** File endings never taken, whatever `accept` says: files a browser runs as a page or a script. */
57
+ export const BLOCKED_FILE_ENDINGS = ['html', 'htm', 'xhtml', 'shtml', 'svg', 'svgz', 'js', 'mjs', 'cjs', 'xml', 'xsl', 'xslt'];
58
+ /** MIME types never taken, whatever `accept` says (also every `…+xml` type). */
59
+ export const BLOCKED_MIME_TYPES = [
60
+ 'text/html',
61
+ 'application/xhtml+xml',
62
+ 'image/svg+xml',
63
+ 'text/javascript',
64
+ 'application/javascript',
65
+ 'application/x-javascript',
66
+ 'application/ecmascript',
67
+ 'text/ecmascript',
68
+ 'application/xml',
69
+ 'text/xml',
70
+ ];
71
+ /** The ending of a file name, lower case, without the dot. Empty without one. */
72
+ const endingOf = (name) => {
73
+ const at = name.lastIndexOf('.');
74
+ return at > 0 ? name.slice(at + 1).trim().toLowerCase() : '';
75
+ };
76
+ /** The MIME type without parameters, lower case. */
77
+ const baseType = (mimetype) => mimetype.split(';')[0].trim().toLowerCase();
78
+ /** True for a file that is never taken: its ending or MIME type is one a browser runs (HTML, SVG, scripts, XML). */
79
+ export function fileTypeBlocked(file) {
80
+ const type = baseType(file.mimetype);
81
+ return BLOCKED_FILE_ENDINGS.includes(endingOf(file.name)) || BLOCKED_MIME_TYPES.includes(type) || type.endsWith('+xml');
82
+ }
83
+ /** True when a MIME type matches a pattern ("image/*", "application/pdf"). */
84
+ const mimeMatches = (type, pattern) => (pattern.endsWith('/*') ? type.startsWith(pattern.slice(0, -1)) : type === pattern);
85
+ /**
86
+ * True when the field takes the file: never a blocked type (`fileTypeBlocked`); else its name ends
87
+ * with one of the endings in `accept` (".pdf"), or both its MIME type and the type of its ending
88
+ * match a MIME pattern ("image/*"), so a file never passes on the type the browser claims alone.
89
+ * An empty `accept` takes `DEFAULT_FILE_ACCEPT`.
90
+ */
91
+ export function fileTypeAllowed(file, accept) {
92
+ if (fileTypeBlocked(file))
93
+ return false;
94
+ const own = acceptPatterns(accept);
95
+ const patterns = own.length > 0 ? own : acceptPatterns(DEFAULT_FILE_ACCEPT);
96
+ const type = baseType(file.mimetype);
97
+ const ending = endingOf(file.name);
98
+ const endingType = MIME_OF_ENDING[ending];
99
+ return patterns.some((p) => (p.startsWith('.') ? ending === p.slice(1) : endingType !== undefined && mimeMatches(type, p) && mimeMatches(endingType, p)));
100
+ }
101
+ /** The message for a file, or '' when it is fine. */
102
+ export function fileProblem(file, rules, limitMb = FILE_FIELD_MAX_MB) {
103
+ if (!fileTypeAllowed(file, rules.accept)) {
104
+ const own = acceptPatterns(rules.accept);
105
+ return `This file type is not allowed. Allowed: ${own.length > 0 ? own.join(', ') : 'images, PDF, office documents, text and CSV files'}.`;
106
+ }
107
+ const max = maxFileBytes(rules, limitMb);
108
+ if (file.size > max)
109
+ return `The file is too large. The limit is ${Math.round((max / MB) * 10) / 10} MB.`;
110
+ return '';
111
+ }
112
+ /**
113
+ * The message for the files of one file field, or '' when they are fine: none when it is required,
114
+ * more than it takes, then each file's type and size. With several files the message names the file.
115
+ */
116
+ export function filesProblem(files, rules, limitMb = FILE_FIELD_MAX_MB) {
117
+ if (files.length === 0)
118
+ return rules.required ? 'Choose a file.' : '';
119
+ const most = maxFileCount(rules);
120
+ if (files.length > most)
121
+ return most === 1 ? 'Choose one file only.' : `Choose at most ${most} files.`;
122
+ for (const file of files) {
123
+ const problem = fileProblem(file, rules, limitMb);
124
+ if (problem)
125
+ return files.length > 1 ? `${file.name}: ${problem}` : problem;
126
+ }
127
+ return '';
128
+ }
@@ -0,0 +1,16 @@
1
+ export { conditionRules, conditionsMet, describeConditions, FORM_CONDITION_OPERATORS, FORM_CONDITIONS_FIELD, formConditionsField, hiddenFormFields, isCompleteRule, isEmptyFormValue, isFormFieldShown, ruleMet, withFormConditions, type FormConditionOperator, type FormConditionRule, type FormFieldConditions, type FormFieldLike, type FormValue, } from './conditions.js';
2
+ export { FORM_FIELD_CATEGORY, FORM_SETTINGS_REGION, FORM_FIELD_PREFIX, formFieldBlocks, formFieldSlug, formFieldType } from './blocks.js';
3
+ export { formAnswerProblem, isDateText, isPhoneNumber, isWebAddress, TICK_FIELD_TYPES, type FormAnswerField } from './answers.js';
4
+ export { addressLine, ALL_ANSWERS_TAG, answersTable, formAnswers, formEmailMessage, htmlToText, mergeTag, mergeTags, tablesOutsideParagraphs, type FormAnswer, type FormEmailConfig, type FormEmailMessage, } from './mergeTags.js';
5
+ export { consentFormField, FILE_FIELD_MAX_MB, fileFormField, formEmailFields, hiddenFormField, MERGE_TAGS_MARKER, moreFormFields, phoneFormField, urlFormField, withFormEmailFields, } from './fieldConfigs.js';
6
+ export { acceptPatterns, BLOCKED_FILE_ENDINGS, BLOCKED_MIME_TYPES, DEFAULT_FILE_ACCEPT, fileProblem, filesProblem, fileTypeAllowed, fileTypeBlocked, maxFileBytes, type FileCountRules, type FileRules, } from './files.js';
7
+ export { DEFAULT_MAX_FILES, fileCountFields, FORM_FIELD_WIDTH_CLASSES, FORM_FIELD_WIDTH_KEY, formFieldWidthClass, isLabelShown, MAX_FILES_LIMIT, maxFileCount, RADIO_DISPLAYS, radioDisplay, setsWidth, withFormFieldSettings, withHiddenWidth, withStoredWidth, withWidthClass, type RadioDisplay, } from './fieldSettings.js';
8
+ export { FORM_SPAM_FIELD, FORM_SPAM_KEY, HONEYPOT_NAME, SPAM_BLOCKED_MESSAGE, SPAM_DEFAULTS, spamSettings, type FormSpamSettings, type FormSpamSettingsInput, type FormSpamValues, } from './spamSettings.js';
9
+ export { FORM_FIELDS_GUIDE, formFieldOps, formFieldsOf, formFieldTypes, nameFromLabel, type FormFieldChange, type FormFieldOpsResult, type FormFieldView, } from './fieldOps.js';
10
+ export { FORM_SETTINGS_GUIDE, formSettingsChanges, formSettingsView } from './settings.js';
11
+ export { isEmailAddress, replyMailto, safePageUrl, shortAnswer, submissionAnswers, submissionSummary, type SubmissionAnswer, type SubmissionDataRow, type SubmissionFormField, type SubmissionSummary, } from './summary.js';
12
+ export { FORM_ACTIONS_MARKER, FORM_BLOCK, FORM_FIELD_PARTS, FORM_LAYOUT_TYPES, FORM_PARTS, FORM_SETTINGS_SECTIONS, FORM_SLOT, FORM_SUBMIT_BLOCK, formBlockFields, formBlockMode, formBlocks, formFieldParts, formFieldsIn, formIdOf, formSettingNames, formSettingsFields, formSubmitBlocks, isFormFieldType, withFieldParts, withPageForms, type FormBlocksOptions, type FormFieldPartName, type FormMode, type FormPartClasses, type FormPartName, type PageFormsInput, } from './pageForms.js';
13
+ export { clearedSettings, fieldBlockOf, fieldRowOf, FORM_SOURCE_FIELD, formBlockFromDoc, withoutVirtualFields, formDataHash, formDataFromBlock, formSourceOf, isFormOf, movedFormLook, pageFormBlocks, withFormIds, withSavedFormFields, type FormDataOptions, type FormSource, } from './pageSync.js';
14
+ export { FIELD_NAME_MARKER } from './blocks.js';
15
+ export { FORM_FIELD_CLASS_KEY, FORM_FIELD_PARTS_KEY } from './fieldSettings.js';
16
+ export { FORM_RESULT_PARAM, formResultAnchor, formResultSearch, NO_SCRIPT_FORM_INPUT, NO_SCRIPT_RETURN_INPUT, noScriptSubmission, readFormResult, refusalOf, safeReturnPath, withoutFormResult, type FormResult, type PostedFile, } from './noScript.js';
@@ -0,0 +1,18 @@
1
+ // `payload-canvas/forms`: form display conditions and the form builder's block definitions.
2
+ // Client-safe. The submissions hook (`formSubmissionConditions`) is in the main entry (server).
3
+ export { conditionRules, conditionsMet, describeConditions, FORM_CONDITION_OPERATORS, FORM_CONDITIONS_FIELD, formConditionsField, hiddenFormFields, isCompleteRule, isEmptyFormValue, isFormFieldShown, ruleMet, withFormConditions, } from './conditions.js';
4
+ export { FORM_FIELD_CATEGORY, FORM_SETTINGS_REGION, FORM_FIELD_PREFIX, formFieldBlocks, formFieldSlug, formFieldType } from './blocks.js';
5
+ export { formAnswerProblem, isDateText, isPhoneNumber, isWebAddress, TICK_FIELD_TYPES } from './answers.js';
6
+ export { addressLine, ALL_ANSWERS_TAG, answersTable, formAnswers, formEmailMessage, htmlToText, mergeTag, mergeTags, tablesOutsideParagraphs, } from './mergeTags.js';
7
+ export { consentFormField, FILE_FIELD_MAX_MB, fileFormField, formEmailFields, hiddenFormField, MERGE_TAGS_MARKER, moreFormFields, phoneFormField, urlFormField, withFormEmailFields, } from './fieldConfigs.js';
8
+ export { acceptPatterns, BLOCKED_FILE_ENDINGS, BLOCKED_MIME_TYPES, DEFAULT_FILE_ACCEPT, fileProblem, filesProblem, fileTypeAllowed, fileTypeBlocked, maxFileBytes, } from './files.js';
9
+ export { DEFAULT_MAX_FILES, fileCountFields, FORM_FIELD_WIDTH_CLASSES, FORM_FIELD_WIDTH_KEY, formFieldWidthClass, isLabelShown, MAX_FILES_LIMIT, maxFileCount, RADIO_DISPLAYS, radioDisplay, setsWidth, withFormFieldSettings, withHiddenWidth, withStoredWidth, withWidthClass, } from './fieldSettings.js';
10
+ export { FORM_SPAM_FIELD, FORM_SPAM_KEY, HONEYPOT_NAME, SPAM_BLOCKED_MESSAGE, SPAM_DEFAULTS, spamSettings, } from './spamSettings.js';
11
+ export { FORM_FIELDS_GUIDE, formFieldOps, formFieldsOf, formFieldTypes, nameFromLabel, } from './fieldOps.js';
12
+ export { FORM_SETTINGS_GUIDE, formSettingsChanges, formSettingsView } from './settings.js';
13
+ export { isEmailAddress, replyMailto, safePageUrl, shortAnswer, submissionAnswers, submissionSummary, } from './summary.js';
14
+ export { FORM_ACTIONS_MARKER, FORM_BLOCK, FORM_FIELD_PARTS, FORM_LAYOUT_TYPES, FORM_PARTS, FORM_SETTINGS_SECTIONS, FORM_SLOT, FORM_SUBMIT_BLOCK, formBlockFields, formBlockMode, formBlocks, formFieldParts, formFieldsIn, formIdOf, formSettingNames, formSettingsFields, formSubmitBlocks, isFormFieldType, withFieldParts, withPageForms, } from './pageForms.js';
15
+ export { clearedSettings, fieldBlockOf, fieldRowOf, FORM_SOURCE_FIELD, formBlockFromDoc, withoutVirtualFields, formDataHash, formDataFromBlock, formSourceOf, isFormOf, movedFormLook, pageFormBlocks, withFormIds, withSavedFormFields, } from './pageSync.js';
16
+ export { FIELD_NAME_MARKER } from './blocks.js';
17
+ export { FORM_FIELD_CLASS_KEY, FORM_FIELD_PARTS_KEY } from './fieldSettings.js';
18
+ export { FORM_RESULT_PARAM, formResultAnchor, formResultSearch, NO_SCRIPT_FORM_INPUT, NO_SCRIPT_RETURN_INPUT, noScriptSubmission, readFormResult, refusalOf, safeReturnPath, withoutFormResult, } from './noScript.js';
@@ -0,0 +1,103 @@
1
+ /** One answer of a submission, for an email. `value` is display text ("Yes" for a ticked box). */
2
+ export type FormAnswer = {
3
+ name: string;
4
+ label: string;
5
+ value: string;
6
+ };
7
+ /** The tag for every answer, as a table in an HTML body and as "Label: value" lines in text. */
8
+ export declare const ALL_ANSWERS_TAG = "{{*}}";
9
+ /** The tag for one field: `{{email}}`. */
10
+ export declare const mergeTag: (name: string) => string;
11
+ export declare const escapeHtml: (text: string) => string;
12
+ /** Every answer as an HTML table: the field label, then the answer (line breaks kept). */
13
+ export declare function answersTable(answers: readonly FormAnswer[]): string;
14
+ /** Every answer as "Label: value" lines. */
15
+ export declare const answersText: (answers: readonly FormAnswer[]) => string;
16
+ export type MergeOptions = {
17
+ /** The text is HTML: answers are escaped and `{{*}}` is a table. Else plain text. */
18
+ html: boolean;
19
+ /** More tags that are not fields, for example `formSubmissionID`. */
20
+ extra?: Readonly<Record<string, string>>;
21
+ };
22
+ /**
23
+ * The template with its tags replaced. `{{*}}` (also `{{*:table}}`, the form-builder plugin's
24
+ * name) gives every answer. A field the visitor left empty or that was hidden gives ''. A tag
25
+ * that names no field of the form stays as it is, so the editor sees the typo in the email.
26
+ */
27
+ export declare function mergeTags(template: string | null | undefined, answers: readonly FormAnswer[], options: MergeOptions, known?: ReadonlySet<string>): string;
28
+ /** A header line without line breaks, so an answer cannot add headers. */
29
+ export declare const headerText: (text: string) => string;
30
+ /**
31
+ * The valid addresses of an address line (To, CC, BCC, Reply-To), separated by commas: a bare
32
+ * address or `"Name" <address>`. Anything else goes, so an answer such as
33
+ * `a@example.com Bcc: b@example.com` can never add a recipient.
34
+ */
35
+ export declare function addressLine(text: string): string;
36
+ type FieldLike = {
37
+ blockType?: string;
38
+ name?: string | null;
39
+ label?: string | null;
40
+ };
41
+ type RowLike = {
42
+ field?: string | null;
43
+ value?: unknown;
44
+ };
45
+ /**
46
+ * The answers of a submission in the form's field order, with the fields' labels. Ticked boxes
47
+ * read "Yes", unticked ones "No". Answers for names the form does not have come last.
48
+ */
49
+ export declare function formAnswers(fields: readonly FieldLike[] | null | undefined, rows: readonly RowLike[] | null | undefined, skip?: ReadonlySet<string>): FormAnswer[];
50
+ /** One email of a form, as the `emails` array stores it (`formEmailFields`). */
51
+ export type FormEmailConfig = {
52
+ emailTo?: string | null;
53
+ fromName?: string | null;
54
+ emailFrom?: string | null;
55
+ replyTo?: string | null;
56
+ cc?: string | null;
57
+ bcc?: string | null;
58
+ subject?: string | null;
59
+ /** `html`: the body is `html`. Else (`richText`, the default) the rich text `message`. */
60
+ bodyType?: 'richText' | 'html' | null;
61
+ html?: string | null;
62
+ message?: unknown;
63
+ };
64
+ export type FormEmailMessage = {
65
+ to: string;
66
+ from: string;
67
+ replyTo?: string;
68
+ cc?: string;
69
+ bcc?: string;
70
+ subject: string;
71
+ html: string;
72
+ text: string;
73
+ };
74
+ export type FormEmailContext = {
75
+ answers: readonly FormAnswer[];
76
+ /** The rich text body (`message`) as HTML, still with its tags. '' for an HTML body. */
77
+ richTextHtml?: string;
78
+ /** The site's sender (the email adapter's) and the address without a To. */
79
+ defaults: {
80
+ fromName: string;
81
+ fromAddress: string;
82
+ to?: string;
83
+ };
84
+ /** More tags, for example `{ formSubmissionID: '12' }`. */
85
+ extra?: Readonly<Record<string, string>>;
86
+ /** Names of every field of the form: their tags give '' when the visitor gave no answer. */
87
+ fieldNames?: ReadonlySet<string>;
88
+ };
89
+ /**
90
+ * Rich text HTML with every `{{*}}` moved out of its paragraph, so the answers table never sits in
91
+ * a `<p>`: "<p>Hi {{*}} bye</p>" -> "<p>Hi</p>{{*}}<p>bye</p>". Empty paragraphs go.
92
+ */
93
+ export declare function tablesOutsideParagraphs(html: string): string;
94
+ /** Plain text of an HTML body, for the text part of the email. */
95
+ export declare function htmlToText(html: string): string;
96
+ /**
97
+ * The message of one form email for a submission. Every line and the body take merge tags; the
98
+ * address lines keep only valid addresses (`addressLine`). From:
99
+ * the From name with the From email; without a From email the site's own address; without both
100
+ * the site's sender. A From email written as `"Name" <address>` (the plugin's style) stays.
101
+ */
102
+ export declare function formEmailMessage(email: FormEmailConfig, context: FormEmailContext): FormEmailMessage;
103
+ export {};