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
@@ -1,5 +1,5 @@
1
1
  import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
2
- import './controls.scss';
2
+ import './controls.css';
3
3
  export type SelectOption = {
4
4
  value: string;
5
5
  label: string;
@@ -13,7 +13,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
13
13
  import { Select as BaseSelect } from '@base-ui/react/select';
14
14
  import { useEffect, useMemo, useRef, useState } from 'react';
15
15
  import { onDismissMenus } from '../menu/dismiss.js';
16
- import './controls.scss';
16
+ import './controls.css';
17
17
  const isGroup = (entry) => typeof entry === 'object' && 'group' in entry;
18
18
  function flatten(entries) {
19
19
  return entries.flatMap((entry) => (entry === 'separator' ? [] : isGroup(entry) ? entry.options : [entry]));
@@ -1,4 +1,4 @@
1
- import './controls.scss';
1
+ import './controls.css';
2
2
  export type SliderProps = {
3
3
  value: number;
4
4
  min: number;
@@ -4,7 +4,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  // accent color, a small round thumb with a larger invisible hit area. Arrow keys step,
5
5
  // Shift+arrows and Page Up/Down take large steps, Home and End jump to the ends.
6
6
  import { Slider as BaseSlider } from '@base-ui/react/slider';
7
- import './controls.scss';
7
+ import './controls.css';
8
8
  const single = (value) => (typeof value === 'number' ? value : (value[0] ?? 0));
9
9
  export function Slider({ value, min, max, step = 1, onValueChange, onValueCommitted, disabled, muted, className, 'aria-label': label }) {
10
10
  return (_jsx(BaseSlider.Root, { className: `builder-slider${className ? ` ${className}` : ''}`, "data-muted": muted || undefined, value: value, min: min, max: max, step: step, disabled: disabled, thumbAlignment: "edge", onValueChange: (next) => onValueChange(single(next)), onValueCommitted: onValueCommitted ? (next) => onValueCommitted(single(next)) : undefined, children: _jsx(BaseSlider.Control, { className: "builder-slider__control", children: _jsxs(BaseSlider.Track, { className: "builder-slider__track", children: [_jsx(BaseSlider.Indicator, { className: "builder-slider__indicator" }), _jsx(BaseSlider.Thumb, { className: "builder-slider__thumb", "aria-label": label })] }) }) }));
@@ -0,0 +1,17 @@
1
+ import { type IconName } from '../icons.js';
2
+ export type TabsProps<T extends string> = {
3
+ value: T;
4
+ options: {
5
+ id: T;
6
+ label: string;
7
+ icon?: IconName;
8
+ }[];
9
+ onChange: (id: T) => void;
10
+ /** `underline`: the inspector's main tabs. `segmented`: a switch, full width. */
11
+ variant?: 'segmented' | 'underline';
12
+ /** Names the tab list for screen readers. */
13
+ label?: string;
14
+ /** The DOM id of a tab's panel, for `aria-controls`. */
15
+ panelId?: (id: T) => string;
16
+ };
17
+ export declare function Tabs<T extends string>({ value, options, onChange, variant, label, panelId }: TabsProps<T>): import("react").JSX.Element;
@@ -0,0 +1,17 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Icon } from '../icons.js';
4
+ export function Tabs({ value, options, onChange, variant = 'underline', label, panelId }) {
5
+ const onKeyDown = (e) => {
6
+ const at = options.findIndex((o) => o.id === value);
7
+ const next = e.key === 'ArrowRight' ? (at + 1) % options.length : e.key === 'ArrowLeft' ? (at - 1 + options.length) % options.length : e.key === 'Home' ? 0 : e.key === 'End' ? options.length - 1 : -1;
8
+ if (next === -1)
9
+ return;
10
+ e.preventDefault();
11
+ onChange(options[next].id);
12
+ // The new tab takes the focus after it renders as selected.
13
+ const list = e.currentTarget.parentElement;
14
+ requestAnimationFrame(() => list?.querySelector('[aria-selected="true"]')?.focus());
15
+ };
16
+ return (_jsx("div", { "aria-label": label, className: variant === 'segmented' ? 'builder-editor__segmented builder-editor__segmented--full' : 'builder-editor__tabs', role: "tablist", children: options.map((option) => (_jsxs("button", { type: "button", role: "tab", "aria-selected": value === option.id, "aria-controls": panelId?.(option.id), tabIndex: value === option.id ? 0 : -1, className: variant === 'segmented' ? 'builder-editor__segment' : 'builder-editor__tab', onClick: () => onChange(option.id), onKeyDown: onKeyDown, children: [option.icon && _jsx(Icon, { name: option.icon, size: 13 }), option.label] }, option.id))) }));
17
+ }
@@ -0,0 +1,301 @@
1
+ /*
2
+ * Shared form controls: `Select.tsx` and `Slider.tsx`. Payload CSS variables only, no Tailwind.
3
+ * The editor variables (`--be-*`) have fallbacks, so the controls also look right outside the
4
+ * editor (the theme global's fields) and in a list rendered in `document.body`.
5
+ */
6
+ @layer payload-default {
7
+ .builder-select,
8
+ .builder-select__popup,
9
+ .builder-slider {
10
+ --bc-accent: var(--be-accent, var(--color-bg-brand));
11
+ --bc-border: var(--be-border, var(--color-border));
12
+ --bc-muted: var(--be-muted, var(--color-text-secondary));
13
+ --bc-subtle: var(--be-subtle, var(--color-text-tertiary));
14
+ --bc-hover: var(--be-hover, var(--color-bg-hover));
15
+ --bc-radius: var(--radius-medium, 4px);
16
+ --bc-ease: var(--be-ease, cubic-bezier(0.2, 0.8, 0.2, 1));
17
+ }
18
+
19
+ /* Select trigger ------------------------------------------------------------------------------ */
20
+ .builder-select {
21
+ --bc-h: calc(1.0156rem * 2);
22
+ display: inline-flex;
23
+ align-items: center;
24
+ gap: 4px;
25
+ box-sizing: border-box;
26
+ width: 100%;
27
+ min-width: 0;
28
+ height: var(--bc-h);
29
+ margin: 0;
30
+ padding: 0 8px 0 calc(1.0156rem * 0.5);
31
+ border: 1px solid var(--bc-border);
32
+ border-radius: var(--bc-radius);
33
+ background: var(--field-color-bg, var(--color-bg));
34
+ color: var(--color-text);
35
+ font: inherit;
36
+ font-size: var(--be-text-m);
37
+ line-height: 1;
38
+ text-align: left;
39
+ cursor: pointer;
40
+ user-select: none;
41
+ transition: border-color 120ms ease, box-shadow 120ms ease;
42
+ }
43
+
44
+ .builder-select:hover {
45
+ border-color: var(--color-border-control-strong);
46
+ }
47
+
48
+ .builder-select[data-popup-open] .builder-select__icon, .builder-select:hover .builder-select__icon {
49
+ color: var(--color-text);
50
+ }
51
+
52
+ .builder-select[data-disabled] {
53
+ background: var(--color-bg-secondary);
54
+ color: var(--color-text-secondary);
55
+ cursor: not-allowed;
56
+ }
57
+
58
+ .builder-select[data-disabled]:hover {
59
+ border-color: var(--bc-border);
60
+ }
61
+
62
+ /* Nothing chosen: the placeholder or the inherited value, dimmed. */
63
+ .builder-select[data-placeholder] .builder-select__value {
64
+ color: var(--bc-subtle);
65
+ }
66
+
67
+ /* The editor's general focus ring is an outline; a select shows Payload's input ring instead. */
68
+ .builder-select:focus-visible,
69
+ .builder-select[data-popup-open],
70
+ .builder-editor .builder-select:focus-visible {
71
+ border-color: var(--bc-accent);
72
+ outline: 0;
73
+ box-shadow: 0 0 0 1px var(--bc-accent);
74
+ }
75
+
76
+ .builder-select--compact {
77
+ --bc-h: var(--bs-h, 26px);
78
+ padding: 0 4px 0 6px;
79
+ font-size: var(--be-text-m);
80
+ }
81
+
82
+ .builder-select__value {
83
+ display: flex;
84
+ flex: 1;
85
+ align-items: center;
86
+ gap: 6px;
87
+ min-width: 0;
88
+ overflow: hidden;
89
+ text-overflow: ellipsis;
90
+ white-space: nowrap;
91
+ }
92
+
93
+ .builder-select__icon {
94
+ display: grid;
95
+ flex: none;
96
+ place-items: center;
97
+ color: var(--bc-muted);
98
+ transition: color 120ms ease;
99
+ }
100
+
101
+ /* A trigger with its own content (an icon): centered, no chevron. */
102
+ .builder-select--custom {
103
+ justify-content: center;
104
+ padding: 0;
105
+ color: var(--bc-muted);
106
+ }
107
+
108
+ /* Select list --------------------------------------------------------------------------------- */
109
+ /* Above Payload's drawers and modals: the list may open from inside one. */
110
+ .builder-select__positioner {
111
+ z-index: 10000;
112
+ outline: 0;
113
+ }
114
+
115
+ .builder-select__popup {
116
+ display: flex;
117
+ flex-direction: column;
118
+ box-sizing: border-box;
119
+ min-width: max(var(--anchor-width, 0px), 160px);
120
+ max-width: min(320px, var(--available-width, 320px));
121
+ max-height: min(360px, var(--available-height, 360px));
122
+ padding: 4px;
123
+ border: 1px solid var(--bc-border);
124
+ border-radius: var(--be-radius-m, var(--radius-medium, 6px));
125
+ background: var(--color-bg);
126
+ color: var(--color-text);
127
+ font-family: var(--font-body);
128
+ font-size: var(--be-text-m);
129
+ line-height: 1.3;
130
+ box-shadow: var(--be-shadow);
131
+ outline: 0;
132
+ transform-origin: var(--transform-origin);
133
+ }
134
+
135
+ @media (prefers-reduced-motion: no-preference) {
136
+ .builder-select__popup {
137
+ transition: opacity 100ms ease, transform 100ms var(--bc-ease);
138
+ }
139
+ }
140
+
141
+ .builder-select__popup[data-starting-style], .builder-select__popup[data-ending-style] {
142
+ opacity: 0;
143
+ transform: scale(0.98) translateY(-2px);
144
+ }
145
+
146
+ .builder-select__list {
147
+ min-height: 0;
148
+ overflow-y: auto;
149
+ overscroll-behavior: contain;
150
+ scroll-padding-block: 4px;
151
+ outline: 0;
152
+ }
153
+
154
+ .builder-select__item {
155
+ display: grid;
156
+ grid-template-columns: 12px minmax(0, 1fr) auto;
157
+ align-items: center;
158
+ gap: 6px;
159
+ box-sizing: border-box;
160
+ min-height: 28px;
161
+ padding: 5px 8px 5px 6px;
162
+ border-radius: var(--bc-radius);
163
+ color: var(--color-text);
164
+ cursor: default;
165
+ outline: 0;
166
+ user-select: none;
167
+ scroll-margin-block: 4px;
168
+ }
169
+
170
+ .builder-select__item[data-highlighted] {
171
+ background: var(--bc-hover);
172
+ }
173
+
174
+ .builder-select__item[data-selected] {
175
+ font-weight: var(--be-weight-medium);
176
+ }
177
+
178
+ .builder-select__item[data-disabled] {
179
+ opacity: 0.4;
180
+ }
181
+
182
+ /* Long labels wrap in the list, so the full text is always readable there. */
183
+ .builder-select__item-text {
184
+ min-width: 0;
185
+ overflow-wrap: anywhere;
186
+ }
187
+
188
+ .builder-select__check {
189
+ display: grid;
190
+ place-items: center;
191
+ width: 12px;
192
+ color: var(--bc-accent);
193
+ }
194
+
195
+ .builder-select__popup--compact {
196
+ font-size: var(--be-text-m);
197
+ }
198
+
199
+ .builder-select__popup--compact .builder-select__item {
200
+ min-height: 26px;
201
+ padding-block: 4px;
202
+ }
203
+
204
+ .builder-select__group-label {
205
+ padding: 6px 8px 2px 24px;
206
+ color: var(--bc-muted);
207
+ font-size: var(--be-text-s);
208
+ font-weight: var(--be-weight-medium);
209
+ }
210
+
211
+ .builder-select__separator {
212
+ height: 1px;
213
+ margin: 4px 0;
214
+ border: 0;
215
+ background: var(--be-border-soft, var(--color-bg-hover));
216
+ }
217
+
218
+ /* The highlight shows the keyboard position; no focus ring inside the list. */
219
+ .builder-editor .builder-select__popup:focus-visible,
220
+ .builder-editor .builder-select__item:focus-visible {
221
+ outline: 0;
222
+ }
223
+
224
+ /* Slider -------------------------------------------------------------------------------------- */
225
+ .builder-slider {
226
+ flex: 1;
227
+ min-width: 0;
228
+ touch-action: none;
229
+ }
230
+
231
+ .builder-slider[data-disabled] {
232
+ opacity: 0.45;
233
+ }
234
+
235
+ /* 20 px tall: the pointer target. The track inside is 3 px. */
236
+ .builder-slider__control {
237
+ display: flex;
238
+ align-items: center;
239
+ height: 20px;
240
+ cursor: pointer;
241
+ }
242
+
243
+ [data-disabled] > .builder-slider__control {
244
+ cursor: not-allowed;
245
+ }
246
+
247
+ .builder-slider__track {
248
+ position: relative;
249
+ width: 100%;
250
+ height: 3px;
251
+ border-radius: 999px;
252
+ background: var(--color-bg-tertiary);
253
+ }
254
+
255
+ .builder-slider__indicator {
256
+ height: 100%;
257
+ border-radius: inherit;
258
+ background: var(--bc-accent);
259
+ }
260
+
261
+ .builder-slider__thumb {
262
+ box-sizing: border-box;
263
+ width: 12px;
264
+ height: 12px;
265
+ border-radius: 50%;
266
+ /* The page color with a visible ring, so a grey (unset) slider never reads as disabled on white. */
267
+ background: var(--color-bg);
268
+ box-shadow: 0 0 0 1px var(--color-border-control-strong), 0 1px 3px rgba(0, 0, 0, 0.22);
269
+ transition: box-shadow 120ms ease, scale 120ms var(--bc-ease);
270
+ /* A larger invisible hit area around the 12 px thumb. */
271
+ }
272
+
273
+ .builder-slider__thumb::before {
274
+ content: "";
275
+ position: absolute;
276
+ inset: -6px;
277
+ border-radius: 50%;
278
+ }
279
+
280
+ .builder-slider__control:hover .builder-slider__thumb, .builder-slider__thumb[data-dragging] {
281
+ box-shadow: 0 0 0 1px var(--color-border-control-strong), 0 1px 3px rgba(0, 0, 0, 0.22), 0 0 0 4px color-mix(in srgb, var(--bc-accent) 18%, transparent);
282
+ }
283
+
284
+ .builder-slider__thumb[data-dragging] {
285
+ scale: 1.12;
286
+ }
287
+
288
+ /* Focus sits on the hidden range input inside the thumb. */
289
+ .builder-slider__thumb:has(:focus-visible) {
290
+ box-shadow: 0 0 0 1px var(--color-border-control-strong), 0 1px 3px rgba(0, 0, 0, 0.22), 0 0 0 3px color-mix(in srgb, var(--bc-accent) 45%, transparent);
291
+ }
292
+
293
+ [data-disabled] .builder-slider__thumb {
294
+ box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.14);
295
+ }
296
+
297
+ /* The value is a default or inherited: a grey fill, so it reads as "not set here". */
298
+ .builder-slider[data-muted] .builder-slider__indicator {
299
+ background: var(--color-bg-disabled);
300
+ }
301
+ }
@@ -0,0 +1,6 @@
1
+ import type { DefaultServerCellComponentProps } from 'payload';
2
+ import './submissions.css';
3
+ /** "Ada Lovelace · ada@example.com" and the start of the message below it. */
4
+ export declare function SubmissionSummaryCell(props: DefaultServerCellComponentProps): Promise<import("react").JSX.Element>;
5
+ /** "New" until someone opened the submission, then the date it was opened. */
6
+ export declare function SubmissionReadCell(props: DefaultServerCellComponentProps): import("react").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // List cells of the submissions collection (forms/submissionsAdmin.ts): the message summary and
3
+ // the "New" badge. Server components: the summary reads the form's field types and labels.
4
+ import { Link } from '@payloadcms/ui';
5
+ import { formatAdminURL } from 'payload/shared';
6
+ import { shortAnswer, submissionSummary } from '../../forms/summary.js';
7
+ import { formatDateTime, formOf, formsSlugOf } from './submissionData.js';
8
+ import './submissions.css';
9
+ /** The cell's content, linked to the document when it is the list's link column. */
10
+ function Linked({ props, children }) {
11
+ const { link, linkURL, payload, collectionConfig, rowData } = props;
12
+ if (!link || rowData?.id === undefined)
13
+ return _jsx(_Fragment, { children: children });
14
+ const href = linkURL ??
15
+ formatAdminURL({ adminRoute: payload.config.routes.admin, path: `/collections/${collectionConfig.slug}/${String(rowData.id)}`, relative: true });
16
+ return (_jsx(Link, { href: href, prefetch: false, children: children }));
17
+ }
18
+ /** "Ada Lovelace · ada@example.com" and the start of the message below it. */
19
+ export async function SubmissionSummaryCell(props) {
20
+ const { payload, collectionConfig, rowData } = props;
21
+ const form = await formOf(payload, formsSlugOf(collectionConfig), rowData?.form);
22
+ const summary = submissionSummary(rowData?.submissionData, form?.fields);
23
+ const line = summary.line ? shortAnswer(summary.line, 70) : 'Empty message';
24
+ const text = summary.text && summary.text !== summary.line ? shortAnswer(summary.text, 90) : null;
25
+ return (_jsx(Linked, { props: props, children: _jsxs("span", { className: "form-submission-cell", children: [_jsx("span", { className: "form-submission-cell__line", children: line }), text ? _jsx("span", { className: "form-submission-cell__text", children: text }) : null] }) }));
26
+ }
27
+ /** "New" until someone opened the submission, then the date it was opened. */
28
+ export function SubmissionReadCell(props) {
29
+ const opened = formatDateTime(props.cellData, props.i18n?.language);
30
+ return (_jsx(Linked, { props: props, children: opened ? _jsx("span", { className: "form-submission-cell__opened", children: opened }) : _jsx("span", { className: "form-submission-badge", children: "New" }) }));
31
+ }
@@ -0,0 +1,5 @@
1
+ import type { UIFieldServerProps } from 'payload';
2
+ import './submissions.css';
3
+ /** Context flag of the read-date update, for hooks that should ignore it. */
4
+ export declare const SUBMISSION_READ_CONTEXT = "formSubmissionRead";
5
+ export declare function SubmissionView({ id, payload, collectionSlug, field, i18n, req, user }: UIFieldServerProps): Promise<import("react").JSX.Element | null>;
@@ -0,0 +1,106 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // The detail view of a form submission (a `ui` field, see forms/submissionsAdmin.ts): the form,
3
+ // who sent it and when, the answers as a table with the form's labels, the files, and
4
+ // "Reply by email". Opening it sets `readAt` once, so the list's "New" badge goes away.
5
+ import { Button } from '@payloadcms/ui';
6
+ import { replyMailto, safePageUrl, submissionAnswers, submissionSummary } from '../../forms/summary.js';
7
+ import { SUBMISSION_PAGE_FIELD, SUBMISSION_READ_FIELD } from '../../forms/submissionsAdmin.js';
8
+ import { fileSize, formatDateTime, formOf, formsSlugOf, thumbnailOf } from './submissionData.js';
9
+ import './submissions.css';
10
+ /** A collection's config by slug. Loose: an app's generated types allow only its own slugs. */
11
+ const collectionConfigOf = (payload, slug) => payload.collections[slug]?.config;
12
+ /** Context flag of the read-date update, for hooks that should ignore it. */
13
+ export const SUBMISSION_READ_CONTEXT = 'formSubmissionRead';
14
+ /**
15
+ * Sets the read date the first time a signed-in admin user opens the submission. The plugin's
16
+ * submissions refuse updates, so this writes only that field, with access off.
17
+ */
18
+ async function markRead(payload, collection, doc, user) {
19
+ if (doc[SUBMISSION_READ_FIELD] || !user || user.collection !== payload.config.admin.user)
20
+ return null;
21
+ const config = collectionConfigOf(payload, collection);
22
+ if (!config?.flattenedFields.some((field) => field.name === SUBMISSION_READ_FIELD))
23
+ return null;
24
+ const now = new Date().toISOString();
25
+ try {
26
+ await payload.update({
27
+ collection: collection,
28
+ id: doc.id,
29
+ data: { [SUBMISSION_READ_FIELD]: now },
30
+ depth: 0,
31
+ overrideAccess: true,
32
+ context: { [SUBMISSION_READ_CONTEXT]: true },
33
+ });
34
+ return now;
35
+ }
36
+ catch (error) {
37
+ payload.logger.error({ err: error, msg: `[payload-canvas] Could not mark form submission ${String(doc.id)} as read` });
38
+ return null;
39
+ }
40
+ }
41
+ const asMedia = (value) => (value && typeof value === 'object' ? value : null);
42
+ /** The files of the submission: the attachments field and the plugin's own uploads, with the question they answer. */
43
+ function filesOf(doc, attachments, answers) {
44
+ const out = [];
45
+ const labelOf = (name) => answers.find((a) => a.name === name)?.label ?? name ?? null;
46
+ const attached = attachments ? doc[attachments] : null;
47
+ for (const [index, value] of (Array.isArray(attached) ? attached : []).entries()) {
48
+ out.push({ key: `a${index}`, label: null, media: asMedia(value), id: asMedia(value)?.id ?? value });
49
+ }
50
+ for (const [row, upload] of (doc.submissionUploads ?? []).entries()) {
51
+ const values = Array.isArray(upload?.value) ? upload.value : [upload?.value];
52
+ for (const [index, value] of values.entries()) {
53
+ if (value === null || value === undefined)
54
+ continue;
55
+ out.push({ key: `u${row}-${index}`, label: labelOf(upload?.field), media: asMedia(value), id: asMedia(value)?.id ?? value });
56
+ }
57
+ }
58
+ return out;
59
+ }
60
+ function AnswerValue({ answer }) {
61
+ if (answer.value.trim() === '')
62
+ return _jsx("span", { className: "form-submission__empty", children: "No answer" });
63
+ const mailto = replyMailto(answer.value);
64
+ if (mailto)
65
+ return _jsx("a", { href: mailto, children: answer.value.trim() });
66
+ return _jsx("span", { className: "form-submission__text", children: answer.display });
67
+ }
68
+ /** A page address for people: the path of a URL on this site, else the whole address. */
69
+ function pageLabel(url) {
70
+ try {
71
+ const parsed = new URL(url, 'http://local');
72
+ return parsed.host === 'local' ? `${parsed.pathname}${parsed.search}` : `${parsed.host}${parsed.pathname}`;
73
+ }
74
+ catch {
75
+ return url;
76
+ }
77
+ }
78
+ export async function SubmissionView({ id, payload, collectionSlug, field, i18n, req, user }) {
79
+ if (id === undefined || id === null || !collectionSlug)
80
+ return null;
81
+ const custom = (field.admin?.custom ?? {});
82
+ const viewer = (user ?? req?.user ?? null);
83
+ const doc = (await payload
84
+ .findByID({ collection: collectionSlug, id, depth: 1, overrideAccess: false, user: viewer })
85
+ .catch(() => null));
86
+ if (!doc)
87
+ return null;
88
+ const config = collectionConfigOf(payload, collectionSlug);
89
+ const form = await formOf(payload, formsSlugOf(config), doc.form);
90
+ const answers = submissionAnswers(form?.fields, doc.submissionData);
91
+ const summary = submissionSummary(doc.submissionData, form?.fields);
92
+ const formTitle = form?.title?.trim() || 'Form';
93
+ const mailto = replyMailto(summary.email, { subject: `Re: ${formTitle}` });
94
+ const page = safePageUrl(doc[SUBMISSION_PAGE_FIELD]);
95
+ const sent = formatDateTime(doc.createdAt, i18n?.language);
96
+ const files = filesOf(doc, custom.attachments ?? null, answers);
97
+ const readAt = await markRead(payload, collectionSlug, doc, viewer);
98
+ const opened = formatDateTime(doc[SUBMISSION_READ_FIELD] ?? readAt, i18n?.language);
99
+ return (_jsxs("div", { className: "form-submission", children: [_jsxs("header", { className: "form-submission__head", children: [_jsxs("div", { className: "form-submission__heading", children: [_jsx("p", { className: "form-submission__form", children: formTitle }), _jsx("h2", { className: "form-submission__title", children: summary.line ?? 'Message' }), _jsxs("p", { className: "form-submission__meta", children: [sent ? _jsxs(_Fragment, { children: ["Sent ", sent] }) : null, page ? (_jsxs(_Fragment, { children: [sent ? ' from ' : 'Sent from ', _jsx("a", { href: page, target: "_blank", rel: "noreferrer", children: pageLabel(page) })] })) : null, opened && !readAt ? _jsxs(_Fragment, { children: [" \u00B7 Opened ", opened] }) : null] })] }), mailto ? (_jsx(Button, { el: "anchor", url: mailto, buttonStyle: "primary", size: "medium", margin: false, children: "Reply by email" })) : null] }), answers.length > 0 ? (_jsx("table", { className: "form-submission__answers", children: _jsx("tbody", { children: answers.map((answer) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: answer.label }), _jsx("td", { children: _jsx(AnswerValue, { answer: answer }) })] }, answer.name))) }) })) : (_jsx("p", { className: "form-submission__empty", children: "This message has no answers." })), files.length > 0 ? (_jsxs("section", { className: "form-submission__files-section", children: [_jsx("h3", { className: "form-submission__subtitle", children: "Files" }), _jsx("ul", { className: "form-submission__files", children: files.map(({ key, label, media, id: fileId }) => {
100
+ const thumb = media ? thumbnailOf(media) : null;
101
+ const name = media?.filename ?? `File ${String(fileId)}`;
102
+ const size = fileSize(media?.filesize);
103
+ const body = (_jsxs(_Fragment, { children: [_jsx("span", { className: "form-submission__thumb", children: thumb ? _jsx("img", { src: thumb, alt: "" }) : _jsx("span", { "aria-hidden": "true", children: name.split('.').pop()?.slice(0, 4).toUpperCase() || 'FILE' }) }), _jsxs("span", { className: "form-submission__file-text", children: [_jsx("span", { className: "form-submission__file-name", children: name }), label || size ? _jsx("span", { className: "form-submission__file-meta", children: [label, size].filter(Boolean).join(' · ') }) : null] })] }));
104
+ return (_jsx("li", { children: media?.url ? (_jsx("a", { className: "form-submission__file", href: media.url, target: "_blank", rel: "noreferrer", children: body })) : (_jsx("span", { className: "form-submission__file", children: body })) }, key));
105
+ }) })] })) : null] }));
106
+ }
@@ -0,0 +1,32 @@
1
+ import type { Payload, SanitizedCollectionConfig } from 'payload';
2
+ import type { SubmissionFormField } from '../../forms/summary.js';
3
+ export type FormDoc = {
4
+ id?: string | number;
5
+ title?: string | null;
6
+ fields?: SubmissionFormField[] | null;
7
+ };
8
+ /** The id of a relationship value (an id or a populated document). */
9
+ export declare function idOf(value: unknown): string | number | null;
10
+ /** The forms collection the submissions' `form` relationship points at. */
11
+ export declare function formsSlugOf(collection: SanitizedCollectionConfig | undefined): string;
12
+ /** A form by id, once per request (a list shows many submissions of the same form). Null when it is gone. */
13
+ export declare const loadForm: (payload: Payload, slug: string, id: string | number) => Promise<FormDoc | null>;
14
+ /** The form of a submission: the populated document, else loaded by id. */
15
+ export declare function formOf(payload: Payload, slug: string, value: unknown): Promise<FormDoc | null>;
16
+ /** "9 Nov 2026, 14:05" in the admin's language. */
17
+ export declare function formatDateTime(value: unknown, language: string | undefined): string | null;
18
+ export type MediaLike = {
19
+ id?: string | number;
20
+ filename?: string | null;
21
+ url?: string | null;
22
+ mimeType?: string | null;
23
+ thumbnailURL?: string | null;
24
+ filesize?: number | null;
25
+ variants?: Record<string, {
26
+ url?: string | null;
27
+ } | undefined> | null;
28
+ };
29
+ /** A small picture of an upload: its thumbnail size, the upload's thumbnail, or the image itself. */
30
+ export declare function thumbnailOf(doc: MediaLike): string | null;
31
+ /** "12 KB", "1.4 MB". */
32
+ export declare function fileSize(bytes: unknown): string | null;
@@ -0,0 +1,63 @@
1
+ // Server helpers of the submissions admin: the form's fields (cached per request), dates and files.
2
+ import { cache } from 'react';
3
+ /** The id of a relationship value (an id or a populated document). */
4
+ export function idOf(value) {
5
+ if (typeof value === 'string' || typeof value === 'number')
6
+ return value;
7
+ if (value && typeof value === 'object' && 'id' in value)
8
+ return idOf(value.id);
9
+ return null;
10
+ }
11
+ /** The forms collection the submissions' `form` relationship points at. */
12
+ export function formsSlugOf(collection) {
13
+ const field = collection?.flattenedFields.find((f) => f.name === 'form');
14
+ return field && 'relationTo' in field && typeof field.relationTo === 'string' ? field.relationTo : 'forms';
15
+ }
16
+ /** A form by id, once per request (a list shows many submissions of the same form). Null when it is gone. */
17
+ export const loadForm = cache(async (payload, slug, id) => {
18
+ try {
19
+ return (await payload.findByID({ collection: slug, id, depth: 0, overrideAccess: true }));
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ });
25
+ /** The form of a submission: the populated document, else loaded by id. */
26
+ export async function formOf(payload, slug, value) {
27
+ if (value && typeof value === 'object' && Array.isArray(value.fields))
28
+ return value;
29
+ const id = idOf(value);
30
+ return id === null ? null : loadForm(payload, slug, id);
31
+ }
32
+ /** "9 Nov 2026, 14:05" in the admin's language. */
33
+ export function formatDateTime(value, language) {
34
+ if (typeof value !== 'string' && !(value instanceof Date))
35
+ return null;
36
+ const date = new Date(value);
37
+ if (Number.isNaN(date.getTime()))
38
+ return null;
39
+ try {
40
+ return new Intl.DateTimeFormat(language || 'en', { dateStyle: 'medium', timeStyle: 'short' }).format(date);
41
+ }
42
+ catch {
43
+ return date.toISOString();
44
+ }
45
+ }
46
+ /** A small picture of an upload: its thumbnail size, the upload's thumbnail, or the image itself. */
47
+ export function thumbnailOf(doc) {
48
+ for (const candidate of [doc.variants?.thumbnail?.url, doc.thumbnailURL]) {
49
+ if (typeof candidate === 'string' && candidate)
50
+ return candidate;
51
+ }
52
+ return doc.mimeType?.startsWith('image/') && doc.url ? doc.url : null;
53
+ }
54
+ /** "12 KB", "1.4 MB". */
55
+ export function fileSize(bytes) {
56
+ if (typeof bytes !== 'number' || !Number.isFinite(bytes) || bytes < 0)
57
+ return null;
58
+ if (bytes < 1024)
59
+ return `${bytes} B`;
60
+ if (bytes < 1024 * 1024)
61
+ return `${Math.round(bytes / 1024)} KB`;
62
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
63
+ }