@pilotiq/pilotiq 0.24.1 → 0.24.2

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 (480) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/boost/guidelines.md +566 -0
  3. package/boost/skills/pilotiq-fields/SKILL.md +47 -0
  4. package/boost/skills/pilotiq-fields/rules/field-catalog.md +288 -0
  5. package/boost/skills/pilotiq-fields/rules/reactive-fields.md +199 -0
  6. package/boost/skills/pilotiq-fields/rules/validation.md +198 -0
  7. package/boost/skills/pilotiq-relations/SKILL.md +47 -0
  8. package/boost/skills/pilotiq-relations/rules/relation-managers.md +256 -0
  9. package/boost/skills/pilotiq-relations/rules/repeater-relationship.md +177 -0
  10. package/boost/skills/pilotiq-resource/SKILL.md +61 -0
  11. package/boost/skills/pilotiq-resource/rules/authorization.md +242 -0
  12. package/boost/skills/pilotiq-resource/rules/defining-resources.md +228 -0
  13. package/boost/skills/pilotiq-resource/rules/page-overrides.md +296 -0
  14. package/package.json +6 -1
  15. package/.turbo/turbo-build.log +0 -8
  16. package/CLAUDE.md +0 -265
  17. package/src/Cluster.test.ts +0 -283
  18. package/src/Cluster.ts +0 -83
  19. package/src/Column.test.ts +0 -199
  20. package/src/Column.ts +0 -710
  21. package/src/Global.test.ts +0 -367
  22. package/src/Global.ts +0 -169
  23. package/src/Page.test.ts +0 -114
  24. package/src/Page.ts +0 -208
  25. package/src/Pilotiq.perf.test.ts +0 -252
  26. package/src/Pilotiq.test.ts +0 -129
  27. package/src/Pilotiq.ts +0 -1158
  28. package/src/PilotiqRegistry.ts +0 -36
  29. package/src/PilotiqServiceProvider.ts +0 -121
  30. package/src/RelationManager.test.ts +0 -400
  31. package/src/RelationManager.ts +0 -527
  32. package/src/RenderHook.test.ts +0 -252
  33. package/src/RenderHook.ts +0 -242
  34. package/src/Resource.test.ts +0 -284
  35. package/src/Resource.ts +0 -526
  36. package/src/RightPanel.test.ts +0 -202
  37. package/src/RightPanel.ts +0 -132
  38. package/src/Tab.test.ts +0 -91
  39. package/src/Tab.ts +0 -156
  40. package/src/UserMenuItem.ts +0 -145
  41. package/src/actions/Action.test.ts +0 -2526
  42. package/src/actions/Action.ts +0 -1515
  43. package/src/actions/ActionGroup.test.ts +0 -112
  44. package/src/actions/ActionGroup.ts +0 -173
  45. package/src/actions/attachFactory.ts +0 -172
  46. package/src/actions/bulkFactories.ts +0 -168
  47. package/src/actions/crudFactories.ts +0 -220
  48. package/src/actions/exportFactory.ts +0 -225
  49. package/src/actions/factoryHelpers.ts +0 -177
  50. package/src/actions/importFactory.ts +0 -243
  51. package/src/actions/index.ts +0 -17
  52. package/src/actions/m2mFactories.ts +0 -193
  53. package/src/actions/relationFactories.ts +0 -372
  54. package/src/applyPageHooks.test.ts +0 -463
  55. package/src/applyPageHooks.ts +0 -330
  56. package/src/authorization.test.ts +0 -483
  57. package/src/breadcrumbs.test.ts +0 -238
  58. package/src/cells/coerce.test.ts +0 -85
  59. package/src/cells/coerce.ts +0 -84
  60. package/src/clusterPaths.ts +0 -35
  61. package/src/columns/BadgeColumn.test.ts +0 -54
  62. package/src/columns/BadgeColumn.ts +0 -32
  63. package/src/columns/BooleanColumn.test.ts +0 -41
  64. package/src/columns/BooleanColumn.ts +0 -18
  65. package/src/columns/ColorColumn.test.ts +0 -37
  66. package/src/columns/ColorColumn.ts +0 -38
  67. package/src/columns/IconColumn.test.ts +0 -54
  68. package/src/columns/IconColumn.ts +0 -37
  69. package/src/columns/ImageColumn.test.ts +0 -41
  70. package/src/columns/ImageColumn.ts +0 -28
  71. package/src/columns/SelectColumn.ts +0 -98
  72. package/src/columns/TextColumn.test.ts +0 -190
  73. package/src/columns/TextColumn.ts +0 -20
  74. package/src/columns/TextInputColumn.ts +0 -68
  75. package/src/columns/ToggleColumn.ts +0 -46
  76. package/src/columns/editableColumns.test.ts +0 -238
  77. package/src/columns/index.ts +0 -9
  78. package/src/defaultGlobalPages.ts +0 -95
  79. package/src/defaultPages.test.ts +0 -634
  80. package/src/defaultPages.ts +0 -617
  81. package/src/defaultViewPage.test.ts +0 -147
  82. package/src/elements/Form.test.ts +0 -223
  83. package/src/elements/Form.ts +0 -416
  84. package/src/elements/ListTabs.ts +0 -28
  85. package/src/elements/Table.test.ts +0 -422
  86. package/src/elements/Table.ts +0 -850
  87. package/src/elements/TableGroup.test.ts +0 -260
  88. package/src/elements/TableGroup.ts +0 -334
  89. package/src/elements/dispatchAction.test.ts +0 -463
  90. package/src/elements/dispatchAction.ts +0 -355
  91. package/src/elements/dispatchForm.test.ts +0 -477
  92. package/src/elements/dispatchForm.ts +0 -1993
  93. package/src/elements/dispatchTable.test.ts +0 -1514
  94. package/src/elements/dispatchTable.ts +0 -745
  95. package/src/elements/index.ts +0 -21
  96. package/src/entries/BadgeEntry.ts +0 -39
  97. package/src/entries/CodeEntry.test.ts +0 -40
  98. package/src/entries/CodeEntry.ts +0 -52
  99. package/src/entries/ColorEntry.ts +0 -63
  100. package/src/entries/ComponentEntry.test.ts +0 -173
  101. package/src/entries/ComponentEntry.ts +0 -95
  102. package/src/entries/Entry.ts +0 -304
  103. package/src/entries/IconEntry.ts +0 -49
  104. package/src/entries/ImageEntry.ts +0 -61
  105. package/src/entries/KeyValueEntry.ts +0 -47
  106. package/src/entries/RepeatableEntry.test.ts +0 -239
  107. package/src/entries/RepeatableEntry.ts +0 -173
  108. package/src/entries/TextEntry.test.ts +0 -394
  109. package/src/entries/TextEntry.ts +0 -60
  110. package/src/entries/index.ts +0 -12
  111. package/src/entries/leaves.test.ts +0 -306
  112. package/src/entries/registry.ts +0 -54
  113. package/src/fields/BuilderField.test.ts +0 -1188
  114. package/src/fields/BuilderField.ts +0 -605
  115. package/src/fields/BuilderRelationship.test.ts +0 -811
  116. package/src/fields/CheckboxField.test.ts +0 -44
  117. package/src/fields/CheckboxField.ts +0 -27
  118. package/src/fields/CheckboxListField.test.ts +0 -99
  119. package/src/fields/CheckboxListField.ts +0 -66
  120. package/src/fields/ColorPickerField.test.ts +0 -33
  121. package/src/fields/ColorPickerField.ts +0 -25
  122. package/src/fields/DateField.ts +0 -54
  123. package/src/fields/DateTimeField.test.ts +0 -55
  124. package/src/fields/EmailField.ts +0 -16
  125. package/src/fields/Field.test.ts +0 -654
  126. package/src/fields/Field.ts +0 -817
  127. package/src/fields/FileUploadField.test.ts +0 -143
  128. package/src/fields/FileUploadField.ts +0 -159
  129. package/src/fields/HiddenField.test.ts +0 -27
  130. package/src/fields/HiddenField.ts +0 -28
  131. package/src/fields/KeyValueField.test.ts +0 -105
  132. package/src/fields/KeyValueField.ts +0 -55
  133. package/src/fields/MarkdownField.test.ts +0 -167
  134. package/src/fields/MarkdownField.ts +0 -162
  135. package/src/fields/NumberField.ts +0 -33
  136. package/src/fields/RadioField.test.ts +0 -94
  137. package/src/fields/RadioField.ts +0 -67
  138. package/src/fields/RepeaterField.test.ts +0 -1806
  139. package/src/fields/RepeaterField.ts +0 -939
  140. package/src/fields/RepeaterRelationship.test.ts +0 -1923
  141. package/src/fields/RepeaterSimple.test.ts +0 -248
  142. package/src/fields/RowButton.test.ts +0 -219
  143. package/src/fields/RowButton.ts +0 -135
  144. package/src/fields/SelectField.test.ts +0 -192
  145. package/src/fields/SelectField.ts +0 -235
  146. package/src/fields/SliderField.test.ts +0 -50
  147. package/src/fields/SliderField.ts +0 -53
  148. package/src/fields/SlugField.ts +0 -24
  149. package/src/fields/TagsInputField.test.ts +0 -154
  150. package/src/fields/TagsInputField.ts +0 -133
  151. package/src/fields/TextField.test.ts +0 -213
  152. package/src/fields/TextField.ts +0 -177
  153. package/src/fields/TextareaField.test.ts +0 -58
  154. package/src/fields/TextareaField.ts +0 -59
  155. package/src/fields/ToggleButtonsField.test.ts +0 -106
  156. package/src/fields/ToggleButtonsField.ts +0 -59
  157. package/src/fields/ToggleField.ts +0 -16
  158. package/src/fields/disableOptionsWhenSelectedInSiblingRepeaterItems.test.ts +0 -319
  159. package/src/fields/optionsResolver.ts +0 -95
  160. package/src/fields/resolveField.ts +0 -28
  161. package/src/filters/BooleanFilter.ts +0 -35
  162. package/src/filters/DateRangeFilter.test.ts +0 -194
  163. package/src/filters/DateRangeFilter.ts +0 -148
  164. package/src/filters/Filter.test.ts +0 -268
  165. package/src/filters/Filter.ts +0 -184
  166. package/src/filters/FormFilter.test.ts +0 -238
  167. package/src/filters/FormFilter.ts +0 -215
  168. package/src/filters/MultiSelectFilter.test.ts +0 -119
  169. package/src/filters/MultiSelectFilter.ts +0 -78
  170. package/src/filters/QueryBuilderFilter.test.ts +0 -662
  171. package/src/filters/QueryBuilderFilter.ts +0 -398
  172. package/src/filters/SelectFilter.ts +0 -46
  173. package/src/filters/TernaryFilter.test.ts +0 -160
  174. package/src/filters/TernaryFilter.ts +0 -72
  175. package/src/filters/TrashedFilter.test.ts +0 -149
  176. package/src/filters/TrashedFilter.ts +0 -55
  177. package/src/filters/queryBuilder/BooleanConstraint.ts +0 -31
  178. package/src/filters/queryBuilder/Constraint.ts +0 -115
  179. package/src/filters/queryBuilder/DateConstraint.ts +0 -69
  180. package/src/filters/queryBuilder/NumberConstraint.ts +0 -66
  181. package/src/filters/queryBuilder/SelectConstraint.ts +0 -72
  182. package/src/filters/queryBuilder/TextConstraint.ts +0 -64
  183. package/src/filters/queryBuilder/index.ts +0 -12
  184. package/src/icons/index.ts +0 -2
  185. package/src/icons/lucide.ts +0 -204
  186. package/src/icons/registry.test.ts +0 -56
  187. package/src/icons/registry.ts +0 -41
  188. package/src/icons/types.ts +0 -47
  189. package/src/index.ts +0 -525
  190. package/src/io/csv.test.ts +0 -142
  191. package/src/io/csv.ts +0 -170
  192. package/src/nestedRelationManagerData.test.ts +0 -547
  193. package/src/notifications/Notification.test.ts +0 -210
  194. package/src/notifications/Notification.ts +0 -354
  195. package/src/notifications/broadcast.test.ts +0 -110
  196. package/src/notifications/broadcast.ts +0 -95
  197. package/src/notifications/database.test.ts +0 -383
  198. package/src/notifications/database.ts +0 -398
  199. package/src/notifications/databaseNotifications.test.ts +0 -187
  200. package/src/notifications/dispatchNotificationAction.test.ts +0 -341
  201. package/src/notifications/dispatchNotificationAction.ts +0 -142
  202. package/src/notifications/flash.test.ts +0 -89
  203. package/src/notifications/flash.ts +0 -71
  204. package/src/notifications/index.ts +0 -45
  205. package/src/notifications/registerBroadcastAuth.test.ts +0 -134
  206. package/src/notifications/registerBroadcastAuth.ts +0 -100
  207. package/src/notifications/resolveSavedNotification.test.ts +0 -82
  208. package/src/notifications/resolveSavedNotification.ts +0 -59
  209. package/src/notifications/types.ts +0 -93
  210. package/src/orm/m2mAccessor.ts +0 -66
  211. package/src/orm/modelDefaults.test.ts +0 -633
  212. package/src/orm/modelDefaults.ts +0 -666
  213. package/src/pageData/breadcrumbs.ts +0 -288
  214. package/src/pageData/forms.ts +0 -578
  215. package/src/pageData/helpers.ts +0 -857
  216. package/src/pageData/misc.ts +0 -347
  217. package/src/pageData/navigation.ts +0 -842
  218. package/src/pageData/relationPages.ts +0 -1248
  219. package/src/pageData/relationTabs.ts +0 -286
  220. package/src/pageData/resourcePages.ts +0 -609
  221. package/src/pageData.test.ts +0 -1545
  222. package/src/pageData.ts +0 -341
  223. package/src/plugins/index.ts +0 -8
  224. package/src/plugins/themeEditor.test.ts +0 -36
  225. package/src/plugins/themeEditor.ts +0 -45
  226. package/src/react/AppShell.tsx +0 -251
  227. package/src/react/CollabExtensionFactoryRegistry.ts +0 -55
  228. package/src/react/CollabRoomContext.ts +0 -98
  229. package/src/react/CollabTextRendererRegistry.ts +0 -102
  230. package/src/react/CommandPalette.tsx +0 -375
  231. package/src/react/CurrentUserContext.tsx +0 -50
  232. package/src/react/CustomPageWrapperGate.tsx +0 -69
  233. package/src/react/CustomPageWrapperRegistry.ts +0 -45
  234. package/src/react/FieldFocusReporterRegistry.ts +0 -37
  235. package/src/react/FieldLabelSlotRegistry.ts +0 -30
  236. package/src/react/FieldPresenceRegistry.ts +0 -46
  237. package/src/react/FormCollabBindingRegistry.ts +0 -242
  238. package/src/react/FormStateContext.tsx +0 -591
  239. package/src/react/HeadHooks.tsx +0 -126
  240. package/src/react/MarkdownEditorRegistry.test.ts +0 -38
  241. package/src/react/MarkdownEditorRegistry.ts +0 -107
  242. package/src/react/NotificationActionStrip.tsx +0 -263
  243. package/src/react/NotificationBell.tsx +0 -426
  244. package/src/react/PendingSuggestionApplierRegistry.test.ts +0 -97
  245. package/src/react/PendingSuggestionApplierRegistry.ts +0 -98
  246. package/src/react/PendingSuggestionOverlayRegistry.ts +0 -54
  247. package/src/react/PendingSuggestionsContext.tsx +0 -172
  248. package/src/react/RecordWrapperGate.tsx +0 -58
  249. package/src/react/RecordWrapperRegistry.ts +0 -39
  250. package/src/react/RenderHookSlot.tsx +0 -32
  251. package/src/react/RightSidebar.tsx +0 -257
  252. package/src/react/RightSidebarContext.tsx +0 -234
  253. package/src/react/RightSidebarTrigger.tsx +0 -53
  254. package/src/react/RowCoordsContext.tsx +0 -23
  255. package/src/react/SchemaRenderer.tsx +0 -549
  256. package/src/react/SearchTrigger.tsx +0 -46
  257. package/src/react/ThemeProvider.tsx +0 -93
  258. package/src/react/ThemeSettingsPage.tsx +0 -579
  259. package/src/react/ThemeToggle.tsx +0 -20
  260. package/src/react/Toaster.tsx +0 -158
  261. package/src/react/UserMenu.tsx +0 -196
  262. package/src/react/WidgetDataContext.tsx +0 -157
  263. package/src/react/cells/EditableCell.tsx +0 -389
  264. package/src/react/component-slots.test.ts +0 -103
  265. package/src/react/component-slots.ts +0 -116
  266. package/src/react/fieldJsHandler.test.ts +0 -166
  267. package/src/react/fieldJsHandler.ts +0 -79
  268. package/src/react/fields/BuilderInput.tsx +0 -1078
  269. package/src/react/fields/CheckboxInput.tsx +0 -39
  270. package/src/react/fields/CheckboxListInput.tsx +0 -102
  271. package/src/react/fields/ColorInput.tsx +0 -71
  272. package/src/react/fields/DateFieldInput.tsx +0 -70
  273. package/src/react/fields/DateTimeInput.tsx +0 -62
  274. package/src/react/fields/FieldShell.tsx +0 -348
  275. package/src/react/fields/FileUploadInput.tsx +0 -639
  276. package/src/react/fields/HiddenInput.tsx +0 -17
  277. package/src/react/fields/KeyValueInput.tsx +0 -230
  278. package/src/react/fields/MarkdownInput.tsx +0 -560
  279. package/src/react/fields/RadioInput.tsx +0 -81
  280. package/src/react/fields/RepeaterInput.test.ts +0 -116
  281. package/src/react/fields/RepeaterInput.tsx +0 -1420
  282. package/src/react/fields/SelectFieldInput.tsx +0 -280
  283. package/src/react/fields/SliderInput.tsx +0 -81
  284. package/src/react/fields/TagsInput.tsx +0 -283
  285. package/src/react/fields/TextLikeInput.tsx +0 -256
  286. package/src/react/fields/ToggleButtonsInput.tsx +0 -60
  287. package/src/react/fields/ToggleFieldInput.tsx +0 -56
  288. package/src/react/fields/relationshipRenameDispatch.test.ts +0 -106
  289. package/src/react/fields/relationshipRenameDispatch.ts +0 -97
  290. package/src/react/fields/repeaterReconcile.test.ts +0 -114
  291. package/src/react/fields/repeaterReconcile.ts +0 -104
  292. package/src/react/fields/rowChromeButton.tsx +0 -336
  293. package/src/react/fields/rowState.ts +0 -106
  294. package/src/react/fields/syncRowGates.test.ts +0 -202
  295. package/src/react/fields/syncRowGates.ts +0 -66
  296. package/src/react/fields/textInputControls.tsx +0 -238
  297. package/src/react/fields/useRowReorderDnd.ts +0 -78
  298. package/src/react/formStateHelpers.test.ts +0 -508
  299. package/src/react/formStateHelpers.ts +0 -381
  300. package/src/react/hooks/use-mobile.ts +0 -19
  301. package/src/react/icon-context.tsx +0 -60
  302. package/src/react/index.ts +0 -194
  303. package/src/react/layouts/SidebarLayout.tsx +0 -250
  304. package/src/react/layouts/TopbarLayout.tsx +0 -258
  305. package/src/react/navigate.tsx +0 -37
  306. package/src/react/onProviderSynced.test.ts +0 -90
  307. package/src/react/parseRecordEditUrl.test.ts +0 -122
  308. package/src/react/parseRecordEditUrl.ts +0 -94
  309. package/src/react/persistedState.ts +0 -40
  310. package/src/react/registry.ts +0 -48
  311. package/src/react/right-panel-registry.tsx +0 -47
  312. package/src/react/schemaRenderer/AlertRenderer.tsx +0 -112
  313. package/src/react/schemaRenderer/EntryRenderer.tsx +0 -501
  314. package/src/react/schemaRenderer/SectionRenderer.tsx +0 -120
  315. package/src/react/schemaRenderer/SimpleElements.tsx +0 -306
  316. package/src/react/schemaRenderer/TabsRenderer.tsx +0 -62
  317. package/src/react/schemaRenderer/WizardRenderer.tsx +0 -338
  318. package/src/react/schemaRenderer/action/ActionGroupTrigger.tsx +0 -177
  319. package/src/react/schemaRenderer/action/ActionModalDialog.tsx +0 -273
  320. package/src/react/schemaRenderer/action/ConfirmActionDialog.tsx +0 -61
  321. package/src/react/schemaRenderer/action/HandlerActionButton.tsx +0 -43
  322. package/src/react/schemaRenderer/action/MethodActionButton.tsx +0 -64
  323. package/src/react/schemaRenderer/action/buttons.tsx +0 -99
  324. package/src/react/schemaRenderer/action/helpers.ts +0 -140
  325. package/src/react/schemaRenderer/action/renderAction.tsx +0 -245
  326. package/src/react/schemaRenderer/columnFormat.ts +0 -65
  327. package/src/react/schemaRenderer/constants.ts +0 -50
  328. package/src/react/schemaRenderer/form/FormRenderer.tsx +0 -274
  329. package/src/react/schemaRenderer/form/renderField.tsx +0 -511
  330. package/src/react/schemaRenderer/helpers.tsx +0 -81
  331. package/src/react/schemaRenderer/table/CardsLayoutBody.tsx +0 -308
  332. package/src/react/schemaRenderer/table/TableRenderer.tsx +0 -123
  333. package/src/react/schemaRenderer/table/TableRendererBody.tsx +0 -974
  334. package/src/react/schemaRenderer/table/filters.tsx +0 -1233
  335. package/src/react/schemaRenderer/table/formatCell.tsx +0 -264
  336. package/src/react/schemaRenderer/table/links.tsx +0 -112
  337. package/src/react/schemaRenderer/table/renderRowActions.tsx +0 -52
  338. package/src/react/schemaRenderer/table/url.tsx +0 -143
  339. package/src/react/theme-preview/apply.ts +0 -99
  340. package/src/react/theme-preview/build-html.ts +0 -436
  341. package/src/react/ui/button.tsx +0 -51
  342. package/src/react/ui/calendar.tsx +0 -67
  343. package/src/react/ui/checkbox.tsx +0 -29
  344. package/src/react/ui/dialog.tsx +0 -108
  345. package/src/react/ui/dropdown-menu.tsx +0 -97
  346. package/src/react/ui/input.tsx +0 -20
  347. package/src/react/ui/label.tsx +0 -21
  348. package/src/react/ui/popover.tsx +0 -50
  349. package/src/react/ui/select.tsx +0 -169
  350. package/src/react/ui/separator.tsx +0 -25
  351. package/src/react/ui/sheet.tsx +0 -136
  352. package/src/react/ui/sidebar.tsx +0 -723
  353. package/src/react/ui/skeleton.tsx +0 -13
  354. package/src/react/ui/slider.tsx +0 -34
  355. package/src/react/ui/switch.tsx +0 -28
  356. package/src/react/ui/table.tsx +0 -105
  357. package/src/react/ui/tabs.tsx +0 -63
  358. package/src/react/ui/textarea.tsx +0 -18
  359. package/src/react/ui/tooltip.tsx +0 -64
  360. package/src/react/useResizableWidth.ts +0 -139
  361. package/src/react/utils.ts +0 -6
  362. package/src/react/widgetRegistry.test.ts +0 -43
  363. package/src/react/widgetRegistry.ts +0 -50
  364. package/src/react/widgets/StatsOverviewRenderer.tsx +0 -232
  365. package/src/react/widgets/TableWidgetRenderer.tsx +0 -231
  366. package/src/react/widgets/ViewRenderer.tsx +0 -71
  367. package/src/relationManagerData.test.ts +0 -1595
  368. package/src/richtext/index.ts +0 -8
  369. package/src/richtext/registry.ts +0 -89
  370. package/src/routes/globals.ts +0 -148
  371. package/src/routes/guard.test.ts +0 -325
  372. package/src/routes/helpers.ts +0 -704
  373. package/src/routes/pages.ts +0 -175
  374. package/src/routes/panel.ts +0 -204
  375. package/src/routes/relations.ts +0 -1243
  376. package/src/routes/resources.ts +0 -781
  377. package/src/routes/theme.ts +0 -91
  378. package/src/routes-nested-relations.test.ts +0 -676
  379. package/src/routes-relations.test.ts +0 -972
  380. package/src/routes.test.ts +0 -2027
  381. package/src/routes.ts +0 -303
  382. package/src/schema/Alert.test.ts +0 -109
  383. package/src/schema/Alert.ts +0 -131
  384. package/src/schema/Block.ts +0 -169
  385. package/src/schema/Breadcrumbs.ts +0 -40
  386. package/src/schema/Card.ts +0 -35
  387. package/src/schema/Divider.ts +0 -20
  388. package/src/schema/Element.ts +0 -219
  389. package/src/schema/EmptyState.test.ts +0 -37
  390. package/src/schema/EmptyState.ts +0 -63
  391. package/src/schema/Fieldset.ts +0 -43
  392. package/src/schema/Grid.ts +0 -43
  393. package/src/schema/Group.ts +0 -30
  394. package/src/schema/Heading.ts +0 -39
  395. package/src/schema/Html.ts +0 -67
  396. package/src/schema/Icon.ts +0 -54
  397. package/src/schema/Image.ts +0 -57
  398. package/src/schema/LinkTag.ts +0 -41
  399. package/src/schema/Markdown.ts +0 -85
  400. package/src/schema/MetaTag.ts +0 -41
  401. package/src/schema/RelationTabs.ts +0 -71
  402. package/src/schema/ScriptTag.ts +0 -55
  403. package/src/schema/Section.ts +0 -160
  404. package/src/schema/ServerDataElement.test.ts +0 -140
  405. package/src/schema/ServerDataElement.ts +0 -156
  406. package/src/schema/SlotComponent.test.ts +0 -77
  407. package/src/schema/SlotComponent.ts +0 -71
  408. package/src/schema/Split.ts +0 -50
  409. package/src/schema/Stat.test.ts +0 -118
  410. package/src/schema/Stat.ts +0 -154
  411. package/src/schema/StatsOverview.test.ts +0 -141
  412. package/src/schema/StatsOverview.ts +0 -119
  413. package/src/schema/StyleTag.ts +0 -35
  414. package/src/schema/TableWidget.test.ts +0 -297
  415. package/src/schema/TableWidget.ts +0 -289
  416. package/src/schema/Tabs.ts +0 -79
  417. package/src/schema/Text.ts +0 -58
  418. package/src/schema/UnorderedList.ts +0 -49
  419. package/src/schema/View.test.ts +0 -111
  420. package/src/schema/View.ts +0 -127
  421. package/src/schema/Wizard.ts +0 -220
  422. package/src/schema/containers.test.ts +0 -564
  423. package/src/schema/headTags.test.ts +0 -134
  424. package/src/schema/index.ts +0 -40
  425. package/src/schema/primes.test.ts +0 -269
  426. package/src/schema/resolveSchema.test.ts +0 -379
  427. package/src/schema/resolveSchema.ts +0 -917
  428. package/src/schema/sanitize.ts +0 -58
  429. package/src/search.test.ts +0 -446
  430. package/src/search.ts +0 -178
  431. package/src/sessionFilters.test.ts +0 -375
  432. package/src/sessionFilters.ts +0 -143
  433. package/src/slot-components/index.ts +0 -10
  434. package/src/slot-components/registry.ts +0 -56
  435. package/src/styles/file-upload.css +0 -13
  436. package/src/summarizers/Summarizer.test.ts +0 -84
  437. package/src/summarizers/Summarizer.ts +0 -123
  438. package/src/summarizers/index.ts +0 -11
  439. package/src/theme/base-colors.ts +0 -68
  440. package/src/theme/chart-colors.ts +0 -50
  441. package/src/theme/colors.ts +0 -447
  442. package/src/theme/generate-css.test.ts +0 -139
  443. package/src/theme/generate-css.ts +0 -44
  444. package/src/theme/generate-scale.test.ts +0 -106
  445. package/src/theme/generate-scale.ts +0 -97
  446. package/src/theme/icon-map.ts +0 -42
  447. package/src/theme/index.ts +0 -34
  448. package/src/theme/migrate.test.ts +0 -178
  449. package/src/theme/migrate.ts +0 -81
  450. package/src/theme/presets.ts +0 -135
  451. package/src/theme/radius.ts +0 -18
  452. package/src/theme/resolve.test.ts +0 -238
  453. package/src/theme/resolve.ts +0 -96
  454. package/src/theme/spacing.ts +0 -18
  455. package/src/theme/storage.test.ts +0 -126
  456. package/src/theme/storage.ts +0 -106
  457. package/src/theme/theme-colors.ts +0 -88
  458. package/src/theme/types.ts +0 -125
  459. package/src/uploads/UploadAdapter.ts +0 -35
  460. package/src/uploads/index.ts +0 -2
  461. package/src/uploads/localUpload.test.ts +0 -70
  462. package/src/uploads/localUpload.ts +0 -84
  463. package/src/validation/Validator.ts +0 -49
  464. package/src/validation/index.ts +0 -28
  465. package/src/validation/rules.ts +0 -78
  466. package/src/validation/runValidators.ts +0 -435
  467. package/src/validation/uniqueValidator.test.ts +0 -196
  468. package/src/validation/uniqueValidator.ts +0 -133
  469. package/src/validation/validators.test.ts +0 -268
  470. package/src/vite.test.ts +0 -184
  471. package/src/vite.ts +0 -787
  472. package/src/widgets/index.ts +0 -10
  473. package/src/widgets/registry.ts +0 -45
  474. package/src/widgets.test.ts +0 -592
  475. package/tsconfig.build.json +0 -11
  476. package/tsconfig.json +0 -4
  477. package/tsconfig.test.json +0 -10
  478. package/views/react/Dashboard.tsx +0 -27
  479. package/views/react/Resources/Form.tsx +0 -102
  480. package/views/react/Resources/Index.tsx +0 -49
@@ -1,1806 +0,0 @@
1
- import { describe, it } from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import { RepeaterField, Repeater, isRepeaterField, type RepeaterFieldMeta } from './RepeaterField.js'
5
- import { TextField } from './TextField.js'
6
- import { NumberField } from './NumberField.js'
7
- import { ToggleField } from './ToggleField.js'
8
- import { resolveSchema } from '../schema/resolveSchema.js'
9
- import { coerceFormValues, applyStateUpdate, findForms } from '../elements/dispatchForm.js'
10
- import { findActions } from '../elements/dispatchAction.js'
11
- import { Form } from '../elements/Form.js'
12
- import { Section } from '../schema/Section.js'
13
- import { Action } from '../actions/Action.js'
14
- import { validateSchema, isValid } from '../validation/index.js'
15
-
16
- describe('RepeaterField', () => {
17
- it('emits fieldType "repeater"', () => {
18
- const meta = RepeaterField.make('items').toMeta()
19
- assert.equal(meta.fieldType, 'repeater')
20
- })
21
-
22
- it('exports an alias `Repeater`', () => {
23
- assert.equal(Repeater, RepeaterField)
24
- })
25
-
26
- it('uses `field` as the element type discriminator', () => {
27
- const f = RepeaterField.make('items')
28
- assert.equal(f.getType(), 'field')
29
- })
30
-
31
- it('label defaults to titlecased name', () => {
32
- const meta = RepeaterField.make('lineItems').toMeta()
33
- assert.equal(meta.label, 'LineItems')
34
- })
35
-
36
- it('defaultItems defaults to 1', () => {
37
- const meta = RepeaterField.make('items').toMeta()
38
- assert.equal(meta.defaultItems, 1)
39
- assert.equal(RepeaterField.make('items').getDefaultItems(), 1)
40
- })
41
-
42
- it('rows and template default to empty arrays', () => {
43
- const meta = RepeaterField.make('items').toMeta()
44
- assert.deepEqual(meta.rows, [])
45
- assert.deepEqual(meta.template, [])
46
- })
47
-
48
- describe('builders', () => {
49
- it('schema() stores inner elements', () => {
50
- const inner = [
51
- TextField.make('product'),
52
- NumberField.make('quantity'),
53
- ]
54
- const f = RepeaterField.make('items').schema(inner)
55
- assert.deepEqual(f.getInnerSchema(), inner)
56
- assert.deepEqual(f.getChildren(), inner)
57
- })
58
-
59
- it('getChildren() returns undefined when no inner schema', () => {
60
- const f = RepeaterField.make('items')
61
- assert.equal(f.getChildren(), undefined)
62
- })
63
-
64
- it('columns() sets meta.columns', () => {
65
- assert.equal('columns' in RepeaterField.make('x').toMeta(), false)
66
- assert.equal(RepeaterField.make('x').columns(2).toMeta().columns, 2)
67
- })
68
-
69
- it('defaultItems() sets meta.defaultItems', () => {
70
- const meta = RepeaterField.make('x').defaultItems(3).toMeta()
71
- assert.equal(meta.defaultItems, 3)
72
- })
73
-
74
- it('minItems() sets meta.minItems', () => {
75
- assert.equal('minItems' in RepeaterField.make('x').toMeta(), false)
76
- assert.equal(RepeaterField.make('x').minItems(1).toMeta().minItems, 1)
77
- })
78
-
79
- it('maxItems() sets meta.maxItems', () => {
80
- assert.equal('maxItems' in RepeaterField.make('x').toMeta(), false)
81
- assert.equal(RepeaterField.make('x').maxItems(50).toMeta().maxItems, 50)
82
- })
83
-
84
- it('reorderable() emits only when set', () => {
85
- assert.equal('reorderable' in RepeaterField.make('x').toMeta(), false)
86
- assert.equal(RepeaterField.make('x').reorderable().toMeta().reorderable, true)
87
- })
88
-
89
- it('collapsible() emits only when set', () => {
90
- assert.equal('collapsible' in RepeaterField.make('x').toMeta(), false)
91
- assert.equal(RepeaterField.make('x').collapsible().toMeta().collapsible, true)
92
- })
93
-
94
- it('collapsed() emits defaultCollapsed only when set', () => {
95
- assert.equal('defaultCollapsed' in RepeaterField.make('x').toMeta(), false)
96
- assert.equal(
97
- RepeaterField.make('x').collapsible().collapsed().toMeta().defaultCollapsed,
98
- true,
99
- )
100
- })
101
-
102
- it('accordion() emits only when set', () => {
103
- assert.equal('accordion' in RepeaterField.make('x').toMeta(), false)
104
- assert.equal(RepeaterField.make('x').accordion().toMeta().accordion, true)
105
- })
106
-
107
- it('accordion() auto-arms collapsible()', () => {
108
- const meta = RepeaterField.make('x').accordion().toMeta()
109
- assert.equal(meta.collapsible, true)
110
- assert.equal(meta.accordion, true)
111
- assert.equal(RepeaterField.make('x').accordion().isCollapsible(), true)
112
- })
113
-
114
- it('accordion(false) leaves collapsible alone', () => {
115
- // Explicit opt-out shouldn't drag collapsible along — and shouldn't
116
- // turn off a separately-armed collapsible() either.
117
- const meta = RepeaterField.make('x').collapsible().accordion(false).toMeta()
118
- assert.equal(meta.collapsible, true)
119
- assert.equal('accordion' in meta, false)
120
- })
121
-
122
- it('accordion() composes with collapsed() to start all-collapsed', () => {
123
- // Pairs cleanly with collapsed() — accordion default is "first row
124
- // open"; collapsed() flips it to "all collapsed". The renderer is
125
- // the one that consults defaultCollapsed; the field just exposes
126
- // both flags.
127
- const meta = RepeaterField.make('x').accordion().collapsed().toMeta()
128
- assert.equal(meta.accordion, true)
129
- assert.equal(meta.collapsible, true)
130
- assert.equal(meta.defaultCollapsed, true)
131
- })
132
-
133
- it('isAccordion() reflects setter', () => {
134
- assert.equal(RepeaterField.make('x').isAccordion(), false)
135
- assert.equal(RepeaterField.make('x').accordion().isAccordion(), true)
136
- assert.equal(RepeaterField.make('x').accordion(false).isAccordion(), false)
137
- })
138
-
139
- it('cloneable() emits only when set', () => {
140
- assert.equal('cloneable' in RepeaterField.make('x').toMeta(), false)
141
- assert.equal(RepeaterField.make('x').cloneable().toMeta().cloneable, true)
142
- })
143
-
144
- it('grid() emits only when set with n >= 2', () => {
145
- // Default — no key on meta.
146
- assert.equal('grid' in RepeaterField.make('x').toMeta(), false)
147
- // n >= 2 lands on meta.
148
- assert.equal(RepeaterField.make('x').grid(3).toMeta().grid, 3)
149
- // n < 2 resets to undefined (so passing 1 is the documented "off"
150
- // form, mirroring how columns(1) is the no-grid sentinel).
151
- assert.equal('grid' in RepeaterField.make('x').grid(1).toMeta(), false)
152
- assert.equal('grid' in RepeaterField.make('x').grid(0).toMeta(), false)
153
- // Re-arming after a reset works.
154
- assert.equal(
155
- RepeaterField.make('x').grid(0).grid(2).toMeta().grid,
156
- 2,
157
- )
158
- })
159
-
160
- it('getGrid() reflects the setter', () => {
161
- assert.equal(RepeaterField.make('x').getGrid(), undefined)
162
- assert.equal(RepeaterField.make('x').grid(2).getGrid(), 2)
163
- assert.equal(RepeaterField.make('x').grid(2).grid(1).getGrid(), undefined)
164
- })
165
-
166
- it('grid() accepts a responsive object form', () => {
167
- const meta = RepeaterField.make('x')
168
- .grid({ default: 1, md: 2, xl: 3 })
169
- .toMeta()
170
- assert.deepEqual(meta.grid, { default: 1, md: 2, xl: 3 })
171
- })
172
-
173
- it('grid() floors floats and drops degenerate entries', () => {
174
- // `default: 0` and `sm: 1` are both dropped — non-default entries
175
- // require n >= 2 (n=1 would just fall through to the previous
176
- // rule) and `default` requires n >= 1 (and 0 is degenerate even
177
- // there). `md: 2.7` floors to 2, `lg: 3` survives.
178
- const meta = RepeaterField.make('x')
179
- .grid({ default: 0, sm: 1, md: 2.7, lg: 3 })
180
- .toMeta()
181
- assert.deepEqual(meta.grid, { md: 2, lg: 3 })
182
- })
183
-
184
- it('grid() collapses single-default responsive object to scalar', () => {
185
- // If only `default` remains after filtering, the responsive form
186
- // is no different from the scalar form — collapse to keep the
187
- // wire shape minimal.
188
- const meta = RepeaterField.make('x')
189
- .grid({ default: 3 })
190
- .toMeta()
191
- assert.equal(meta.grid, 3)
192
- })
193
-
194
- it('grid({}) with no usable entries resets to no-grid', () => {
195
- assert.equal(
196
- 'grid' in RepeaterField.make('x').grid({ md: 1 }).toMeta(),
197
- false,
198
- )
199
- assert.equal('grid' in RepeaterField.make('x').grid({}).toMeta(), false)
200
- })
201
-
202
- it('grid() composes with reorderable / collapsible / accordion', () => {
203
- // The renderer suppresses the drop indicator in grid mode but
204
- // keeps button reorder + accordion behavior. Field-level should
205
- // not gate on those flags — they're orthogonal.
206
- const meta = RepeaterField.make('x')
207
- .grid(2)
208
- .reorderable()
209
- .accordion()
210
- .toMeta()
211
- assert.equal(meta.grid, 2)
212
- assert.equal(meta.reorderable, true)
213
- assert.equal(meta.accordion, true)
214
- assert.equal(meta.collapsible, true)
215
- })
216
-
217
- it('table() emits column descriptors only when a non-empty array is set', () => {
218
- // Default — no key on meta.
219
- assert.equal('table' in RepeaterField.make('x').toMeta(), false)
220
- // Empty array is the off sentinel.
221
- assert.equal('table' in RepeaterField.make('x').table([]).toMeta(), false)
222
- // Non-empty lands the column array verbatim.
223
- const meta = RepeaterField.make('x').table([
224
- { label: 'Name' },
225
- { label: 'Role', alignment: 'right', width: '30%', required: true },
226
- ]).toMeta()
227
- assert.deepEqual(meta.table, {
228
- columns: [
229
- { label: 'Name' },
230
- { label: 'Role', alignment: 'right', width: '30%', required: true },
231
- ],
232
- })
233
- })
234
-
235
- it('table() with an empty array clears a previously-set column array', () => {
236
- // Lets users toggle table mode on/off via a config value without
237
- // a separate "untable()" branch — mirrors grid()'s sentinel form.
238
- const meta = RepeaterField.make('x')
239
- .table([{ label: 'Name' }])
240
- .table([])
241
- .toMeta()
242
- assert.equal('table' in meta, false)
243
- })
244
-
245
- it('isTable() / getTableColumns() reflect the setter', () => {
246
- const f = RepeaterField.make('x')
247
- assert.equal(f.isTable(), false)
248
- assert.equal(f.getTableColumns(), undefined)
249
- const t = f.table([{ label: 'Name' }])
250
- assert.equal(t.isTable(), true)
251
- assert.deepEqual(t.getTableColumns(), [{ label: 'Name' }])
252
- // Round-trip through the empty-array off sentinel.
253
- const off = t.table([])
254
- assert.equal(off.isTable(), false)
255
- assert.equal(off.getTableColumns(), undefined)
256
- })
257
-
258
- it('addActionLabel() emits only when set', () => {
259
- assert.equal('addActionLabel' in RepeaterField.make('x').toMeta(), false)
260
- assert.equal(
261
- RepeaterField.make('x').addActionLabel('Add line').toMeta().addActionLabel,
262
- 'Add line',
263
- )
264
- })
265
-
266
- it('relationship() — string form stores config; meta carries name only', () => {
267
- const f = RepeaterField.make('items').relationship('items')
268
- assert.deepEqual(f.getRelationship(), { name: 'items' })
269
- assert.equal(f.isRelationship(), true)
270
- // Wire shape: model + foreignKey stay server-only.
271
- const meta = f.toMeta()
272
- assert.deepEqual(meta.relationship, { name: 'items' })
273
- })
274
-
275
- it('relationship() — object form stores model + foreignKey + orderColumn but only name + orderColumn ship over the wire', () => {
276
- const FakeModel = { find: () => Promise.resolve(null), create: () => Promise.resolve({}), update: () => Promise.resolve({}), delete: () => Promise.resolve(), query: () => ({}) } as unknown as Parameters<RepeaterField['relationship']>[0] extends string ? never : { model: unknown }
277
- const f = RepeaterField.make('items').relationship({
278
- name: 'items',
279
- model: FakeModel as never,
280
- foreignKey: 'orderId',
281
- orderColumn: 'sort',
282
- })
283
- assert.equal(f.getRelationship()!.name, 'items')
284
- assert.equal(f.getRelationship()!.foreignKey, 'orderId')
285
- assert.equal(f.getRelationship()!.orderColumn, 'sort')
286
- const meta = f.toMeta()
287
- // Only `name` and `orderColumn` cross the boundary.
288
- assert.deepEqual(meta.relationship, { name: 'items', orderColumn: 'sort' })
289
- })
290
-
291
- it('relationship() emits no meta key when not configured', () => {
292
- assert.equal('relationship' in RepeaterField.make('x').toMeta(), false)
293
- })
294
-
295
- it('orderColumn() requires relationship() first', () => {
296
- assert.throws(
297
- () => RepeaterField.make('x').orderColumn('sort'),
298
- /relationship\(\) to be configured first/,
299
- )
300
- })
301
-
302
- it('orderColumn() updates the existing relationship config', () => {
303
- const f = RepeaterField.make('items').relationship('items').orderColumn('sort')
304
- assert.equal(f.getRelationship()!.orderColumn, 'sort')
305
- assert.deepEqual(f.toMeta().relationship, { name: 'items', orderColumn: 'sort' })
306
- })
307
-
308
- it('relationship() throws when simple() is already configured', () => {
309
- assert.throws(
310
- () => RepeaterField.make('x').simple(TextField.make('value')).relationship('xs'),
311
- /incompatible with simple\(\)/,
312
- )
313
- })
314
-
315
- it('simple() throws when relationship() is already configured', () => {
316
- assert.throws(
317
- () => RepeaterField.make('x').relationship('xs').simple(TextField.make('value')),
318
- /incompatible with relationship\(\)/,
319
- )
320
- })
321
-
322
- it('relationship() throws when dehydrated(false)', () => {
323
- assert.throws(
324
- () => RepeaterField.make('x').dehydrated(false).relationship('xs'),
325
- /incompatible with dehydrated\(false\)/,
326
- )
327
- })
328
-
329
- it('itemLabel() stores the function (not on meta — evaluated per row in step 2)', () => {
330
- const fn = (row: Record<string, unknown>) => String(row['title'] ?? '')
331
- const f = RepeaterField.make('x').itemLabel(fn)
332
- assert.equal(f.getItemLabel(), fn)
333
- })
334
-
335
- it('chained builders compose', () => {
336
- const meta = RepeaterField.make('items')
337
- .label('Line items')
338
- .schema([TextField.make('product'), NumberField.make('qty'), ToggleField.make('on')])
339
- .columns(2)
340
- .defaultItems(2)
341
- .minItems(1)
342
- .maxItems(20)
343
- .reorderable()
344
- .collapsible()
345
- .collapsed()
346
- .cloneable()
347
- .addActionLabel('Add item')
348
- .toMeta()
349
-
350
- assert.equal(meta.label, 'Line items')
351
- assert.equal(meta.columns, 2)
352
- assert.equal(meta.defaultItems, 2)
353
- assert.equal(meta.minItems, 1)
354
- assert.equal(meta.maxItems, 20)
355
- assert.equal(meta.reorderable, true)
356
- assert.equal(meta.collapsible, true)
357
- assert.equal(meta.defaultCollapsed, true)
358
- assert.equal(meta.cloneable, true)
359
- assert.equal(meta.addActionLabel, 'Add item')
360
- })
361
- })
362
-
363
- describe('per-row resolve (Step 2)', () => {
364
- function repeater() {
365
- return RepeaterField.make('items')
366
- .schema([
367
- TextField.make('product'),
368
- NumberField.make('quantity'),
369
- ])
370
- }
371
-
372
- function metaOf(m: unknown): RepeaterFieldMeta {
373
- return m as RepeaterFieldMeta
374
- }
375
-
376
- it('zero submitted rows + defaultItems(0) → empty rows array', async () => {
377
- const [raw] = await resolveSchema([repeater().defaultItems(0)])
378
- const m = metaOf(raw)
379
- assert.deepEqual(m.rows, [])
380
- // Template still resolves so the Add button has a blueprint
381
- assert.equal(m.template.length, 2)
382
- })
383
-
384
- it('no submitted values → defaultItems empty rows', async () => {
385
- const [raw] = await resolveSchema([repeater().defaultItems(2)])
386
- const m = metaOf(raw)
387
- assert.equal(m.rows.length, 2)
388
- assert.equal(m.rows[0]?.id, 'items-0')
389
- assert.equal(m.rows[1]?.id, 'items-1')
390
- assert.equal(m.rows[0]?.children.length, 2)
391
- })
392
-
393
- it('submitted N rows → N resolved rows', async () => {
394
- const [raw] = await resolveSchema(
395
- [repeater()],
396
- { values: { items: [{ product: 'Widget', quantity: 2 }, { product: 'Gear', quantity: 5 }] } },
397
- )
398
- const m = metaOf(raw)
399
- assert.equal(m.rows.length, 2)
400
- assert.equal(m.rows[0]?.id, 'items-0')
401
- assert.equal(m.rows[1]?.id, 'items-1')
402
- })
403
-
404
- it('preserves __id from submitted row values', async () => {
405
- const [raw] = await resolveSchema(
406
- [repeater()],
407
- { values: { items: [{ __id: 'row-abc', product: 'X' }, { __id: 'row-def', product: 'Y' }] } },
408
- )
409
- const m = metaOf(raw)
410
- assert.equal(m.rows[0]?.id, 'row-abc')
411
- assert.equal(m.rows[1]?.id, 'row-def')
412
- })
413
-
414
- it('falls back to deterministic id when __id is non-string or missing', async () => {
415
- const [raw] = await resolveSchema(
416
- [repeater()],
417
- { values: { items: [{ __id: 42 }, { __id: '' }, {}] } },
418
- )
419
- const m = metaOf(raw)
420
- assert.equal(m.rows[0]?.id, 'items-0')
421
- assert.equal(m.rows[1]?.id, 'items-1')
422
- assert.equal(m.rows[2]?.id, 'items-2')
423
- })
424
-
425
- it('row-scoped $get reads only the row\'s values (not parent)', async () => {
426
- // Gate capture on `ctx.row` — the template resolve fires the same
427
- // callback with empty values, and we only want the row pass.
428
- let captured: unknown
429
- const f = RepeaterField.make('items').schema([
430
- TextField.make('product').showWhen(({ $get, row }) => {
431
- if (row) captured = $get?.('product')
432
- return true
433
- }),
434
- ])
435
- await resolveSchema(
436
- [f],
437
- { values: { items: [{ product: 'rowOne' }], product: 'parentLevel' } },
438
- )
439
- assert.equal(captured, 'rowOne')
440
- })
441
-
442
- it('row-scoped row.$get sugar matches values $get', async () => {
443
- let viaRow: unknown
444
- let viaValues: unknown
445
- const f = RepeaterField.make('items').schema([
446
- TextField.make('product').showWhen((ctx) => {
447
- if (ctx.row) {
448
- viaRow = ctx.row.$get('product')
449
- viaValues = ctx.$get?.('product')
450
- }
451
- return true
452
- }),
453
- ])
454
- await resolveSchema(
455
- [f],
456
- { values: { items: [{ product: 'fromRow' }] } },
457
- )
458
- assert.equal(viaRow, 'fromRow')
459
- assert.equal(viaValues, 'fromRow')
460
- })
461
-
462
- it('row index is exposed via ctx.row.index', async () => {
463
- const seen: number[] = []
464
- const f = RepeaterField.make('items').schema([
465
- TextField.make('product').showWhen((ctx) => {
466
- if (ctx.row) seen.push(ctx.row.index)
467
- return true
468
- }),
469
- ])
470
- await resolveSchema(
471
- [f],
472
- { values: { items: [{}, {}, {}] } },
473
- )
474
- assert.deepEqual(seen, [0, 1, 2])
475
- })
476
-
477
- it('itemLabel() runs once per row and lands on RepeaterRowMeta.itemLabel', async () => {
478
- const f = RepeaterField.make('items')
479
- .schema([TextField.make('product')])
480
- .itemLabel(row => String(row['product'] ?? 'Untitled'))
481
- const [raw] = await resolveSchema(
482
- [f],
483
- { values: { items: [{ product: 'Widget' }, { product: 'Gear' }, {}] } },
484
- )
485
- const m = metaOf(raw)
486
- assert.equal(m.rows[0]?.itemLabel, 'Widget')
487
- assert.equal(m.rows[1]?.itemLabel, 'Gear')
488
- assert.equal(m.rows[2]?.itemLabel, 'Untitled')
489
- })
490
-
491
- it('itemLabel() throwing is swallowed (row stays without label)', async () => {
492
- const f = RepeaterField.make('items')
493
- .schema([TextField.make('product')])
494
- .itemLabel(() => { throw new Error('boom') })
495
- const [raw] = await resolveSchema(
496
- [f],
497
- { values: { items: [{ product: 'X' }] } },
498
- )
499
- const m = metaOf(raw)
500
- assert.equal(m.rows[0]?.itemLabel, undefined)
501
- })
502
-
503
- it('template is resolved with empty values (no row scoping)', async () => {
504
- const f = RepeaterField.make('items').schema([
505
- TextField.make('product').default('seeded'),
506
- ])
507
- const [raw] = await resolveSchema([f])
508
- const m = metaOf(raw)
509
- const tpl = m.template[0] as { defaultValue?: unknown } | undefined
510
- assert.equal(tpl?.defaultValue, 'seeded')
511
- })
512
-
513
- it('does not attach `meta.children` (rows replace the generic recurse)', async () => {
514
- const f = RepeaterField.make('items').schema([TextField.make('product')])
515
- const [raw] = await resolveSchema(
516
- [f],
517
- { values: { items: [{}] } },
518
- )
519
- assert.equal('children' in (raw as Record<string, unknown>), false)
520
- })
521
-
522
- it('non-array submitted values fall back to defaultItems empty rows', async () => {
523
- const f = RepeaterField.make('items').schema([TextField.make('product')]).defaultItems(2)
524
- const [raw] = await resolveSchema(
525
- [f],
526
- { values: { items: 'not-an-array' as unknown } },
527
- )
528
- const m = metaOf(raw)
529
- assert.equal(m.rows.length, 2)
530
- })
531
-
532
- it('non-object row entries are coerced to {}', async () => {
533
- const f = RepeaterField.make('items').schema([TextField.make('product')])
534
- const [raw] = await resolveSchema(
535
- [f],
536
- { values: { items: [null, 42, 'string', { product: 'real' }] } },
537
- )
538
- const m = metaOf(raw)
539
- assert.equal(m.rows.length, 4)
540
- })
541
- })
542
-
543
- describe('itemHidden (v1.2 row-level visibility)', () => {
544
- function repeater() {
545
- return RepeaterField.make('items').schema([
546
- TextField.make('product'),
547
- ToggleField.make('archived'),
548
- ])
549
- }
550
-
551
- function metaOf(m: unknown): RepeaterFieldMeta {
552
- return m as RepeaterFieldMeta
553
- }
554
-
555
- it('builder stores rule + accessor returns it', () => {
556
- const fn = (ctx: { values?: Record<string, unknown> }) => Boolean(ctx.values?.['archived'])
557
- const f = RepeaterField.make('items').itemHidden(fn)
558
- assert.equal(f.getItemHidden(), fn)
559
- })
560
-
561
- it('rule unset → no row carries hidden flag', async () => {
562
- const [raw] = await resolveSchema(
563
- [repeater()],
564
- { values: { items: [{ product: 'A' }, { product: 'B' }] } },
565
- )
566
- const m = metaOf(raw)
567
- assert.equal(m.rows[0]?.hidden, undefined)
568
- assert.equal(m.rows[1]?.hidden, undefined)
569
- })
570
-
571
- it('static `itemHidden(false)` → no row marked hidden', async () => {
572
- const [raw] = await resolveSchema(
573
- [repeater().itemHidden(false)],
574
- { values: { items: [{ product: 'A' }] } },
575
- )
576
- const m = metaOf(raw)
577
- assert.equal(m.rows[0]?.hidden, undefined)
578
- })
579
-
580
- it('static `itemHidden(true)` → every row marked hidden', async () => {
581
- const [raw] = await resolveSchema(
582
- [repeater().itemHidden(true)],
583
- { values: { items: [{ product: 'A' }, { product: 'B' }] } },
584
- )
585
- const m = metaOf(raw)
586
- assert.equal(m.rows[0]?.hidden, true)
587
- assert.equal(m.rows[1]?.hidden, true)
588
- })
589
-
590
- it('predicate sees row-scoped values + can hide selectively', async () => {
591
- const f = repeater().itemHidden(({ values }) => Boolean(values?.['archived']))
592
- const [raw] = await resolveSchema(
593
- [f],
594
- {
595
- values: {
596
- items: [
597
- { product: 'A', archived: false },
598
- { product: 'B', archived: true },
599
- { product: 'C', archived: false },
600
- ],
601
- },
602
- },
603
- )
604
- const m = metaOf(raw)
605
- assert.equal(m.rows[0]?.hidden, undefined)
606
- assert.equal(m.rows[1]?.hidden, true)
607
- assert.equal(m.rows[2]?.hidden, undefined)
608
- })
609
-
610
- it('predicate sees row.index', async () => {
611
- const seen: number[] = []
612
- const f = repeater().itemHidden(({ row }) => {
613
- if (row) seen.push(row.index)
614
- return false
615
- })
616
- await resolveSchema(
617
- [f],
618
- { values: { items: [{}, {}, {}] } },
619
- )
620
- assert.deepEqual(seen, [0, 1, 2])
621
- })
622
-
623
- it('async predicate is awaited', async () => {
624
- const f = repeater().itemHidden(async ({ values }) => {
625
- await Promise.resolve()
626
- return values?.['product'] === 'hide-me'
627
- })
628
- const [raw] = await resolveSchema(
629
- [f],
630
- { values: { items: [{ product: 'keep' }, { product: 'hide-me' }] } },
631
- )
632
- const m = metaOf(raw)
633
- assert.equal(m.rows[0]?.hidden, undefined)
634
- assert.equal(m.rows[1]?.hidden, true)
635
- })
636
-
637
- it('throwing predicate → row stays visible (fail-closed-as-visible) + warns', async () => {
638
- const original = console.warn
639
- const warnings: unknown[][] = []
640
- console.warn = (...args: unknown[]) => { warnings.push(args) }
641
- try {
642
- const f = repeater().itemHidden(() => { throw new Error('boom') })
643
- const [raw] = await resolveSchema(
644
- [f],
645
- { values: { items: [{ product: 'A' }] } },
646
- )
647
- const m = metaOf(raw)
648
- assert.equal(m.rows[0]?.hidden, undefined)
649
- assert.ok(warnings.length >= 1, 'expected at least one warning')
650
- assert.match(String(warnings[0]?.[0]), /itemHidden\(\) on Repeater "items" threw/)
651
- } finally {
652
- console.warn = original
653
- }
654
- })
655
-
656
- it('hidden rows still resolve their inner schema (so values round-trip on submit)', async () => {
657
- const f = repeater().itemHidden(({ values }) => Boolean(values?.['archived']))
658
- const [raw] = await resolveSchema(
659
- [f],
660
- { values: { items: [{ product: 'A', archived: true }] } },
661
- )
662
- const m = metaOf(raw)
663
- assert.equal(m.rows[0]?.hidden, true)
664
- // Inner schema is still resolved so the renderer can mount inputs
665
- // for FormData round-trip.
666
- assert.equal(m.rows[0]?.children.length, 2)
667
- })
668
- })
669
-
670
- describe('itemCanDelete / itemCanClone / itemCanReorder (per-row capability gates)', () => {
671
- function repeater() {
672
- return RepeaterField.make('items').schema([
673
- TextField.make('product'),
674
- ToggleField.make('archived'),
675
- ])
676
- }
677
-
678
- function metaOf(m: unknown): RepeaterFieldMeta {
679
- return m as RepeaterFieldMeta
680
- }
681
-
682
- it('builders store + return their rules', () => {
683
- const del = (_ctx: unknown) => true
684
- const clone = (_ctx: unknown) => true
685
- const reorder = (_ctx: unknown) => true
686
- const f = RepeaterField.make('items')
687
- .itemCanDelete(del as never)
688
- .itemCanClone(clone as never)
689
- .itemCanReorder(reorder as never)
690
- assert.equal(f.getItemCanDelete(), del)
691
- assert.equal(f.getItemCanClone(), clone)
692
- assert.equal(f.getItemCanReorder(), reorder)
693
- })
694
-
695
- it('rules unset → no row carries cap flags (zero serialization cost)', async () => {
696
- const [raw] = await resolveSchema(
697
- [repeater()],
698
- { values: { items: [{ product: 'A' }, { product: 'B' }] } },
699
- )
700
- const m = metaOf(raw)
701
- assert.equal(m.rows[0]?.canDelete, undefined)
702
- assert.equal(m.rows[0]?.canClone, undefined)
703
- assert.equal(m.rows[0]?.canReorder, undefined)
704
- })
705
-
706
- it('static `itemCanDelete(true)` → no row stamps canDelete', async () => {
707
- const [raw] = await resolveSchema(
708
- [repeater().itemCanDelete(true)],
709
- { values: { items: [{ product: 'A' }] } },
710
- )
711
- const m = metaOf(raw)
712
- assert.equal(m.rows[0]?.canDelete, undefined)
713
- })
714
-
715
- it('static `itemCanDelete(false)` → every row stamps canDelete: false', async () => {
716
- const [raw] = await resolveSchema(
717
- [repeater().itemCanDelete(false)],
718
- { values: { items: [{ product: 'A' }, { product: 'B' }] } },
719
- )
720
- const m = metaOf(raw)
721
- assert.equal(m.rows[0]?.canDelete, false)
722
- assert.equal(m.rows[1]?.canDelete, false)
723
- })
724
-
725
- it('predicate gates per-row independently', async () => {
726
- const f = repeater().itemCanDelete(({ values }) => !values?.['archived'])
727
- const [raw] = await resolveSchema(
728
- [f],
729
- {
730
- values: {
731
- items: [
732
- { product: 'A', archived: false },
733
- { product: 'B', archived: true },
734
- { product: 'C', archived: false },
735
- ],
736
- },
737
- },
738
- )
739
- const m = metaOf(raw)
740
- assert.equal(m.rows[0]?.canDelete, undefined)
741
- assert.equal(m.rows[1]?.canDelete, false)
742
- assert.equal(m.rows[2]?.canDelete, undefined)
743
- })
744
-
745
- it('itemCanClone gates the clone button per-row', async () => {
746
- const f = repeater()
747
- .cloneable()
748
- .itemCanClone(({ row }) => row?.index !== 1)
749
- const [raw] = await resolveSchema(
750
- [f],
751
- { values: { items: [{ product: 'A' }, { product: 'B' }, { product: 'C' }] } },
752
- )
753
- const m = metaOf(raw)
754
- assert.equal(m.rows[0]?.canClone, undefined)
755
- assert.equal(m.rows[1]?.canClone, false)
756
- assert.equal(m.rows[2]?.canClone, undefined)
757
- })
758
-
759
- it('itemCanReorder gates reorder controls per-row', async () => {
760
- const f = repeater()
761
- .reorderable()
762
- .itemCanReorder(({ values }) => values?.['product'] !== 'pinned')
763
- const [raw] = await resolveSchema(
764
- [f],
765
- {
766
- values: {
767
- items: [
768
- { product: 'A' },
769
- { product: 'pinned' },
770
- { product: 'B' },
771
- ],
772
- },
773
- },
774
- )
775
- const m = metaOf(raw)
776
- assert.equal(m.rows[0]?.canReorder, undefined)
777
- assert.equal(m.rows[1]?.canReorder, false)
778
- assert.equal(m.rows[2]?.canReorder, undefined)
779
- })
780
-
781
- it('async predicate is awaited', async () => {
782
- const f = repeater().itemCanDelete(async ({ values }) => {
783
- await Promise.resolve()
784
- return values?.['product'] !== 'locked'
785
- })
786
- const [raw] = await resolveSchema(
787
- [f],
788
- { values: { items: [{ product: 'A' }, { product: 'locked' }] } },
789
- )
790
- const m = metaOf(raw)
791
- assert.equal(m.rows[0]?.canDelete, undefined)
792
- assert.equal(m.rows[1]?.canDelete, false)
793
- })
794
-
795
- it('throwing predicate → capability stays enabled (fail-open) + warns', async () => {
796
- const original = console.warn
797
- const warnings: unknown[][] = []
798
- console.warn = (...args: unknown[]) => { warnings.push(args) }
799
- try {
800
- const f = repeater().itemCanDelete(() => { throw new Error('boom') })
801
- const [raw] = await resolveSchema(
802
- [f],
803
- { values: { items: [{ product: 'A' }] } },
804
- )
805
- const m = metaOf(raw)
806
- // Fail-open: a misbehaving rule shouldn't lock the user out.
807
- assert.equal(m.rows[0]?.canDelete, undefined)
808
- assert.ok(warnings.length >= 1, 'expected at least one warning')
809
- assert.match(String(warnings[0]?.[0]), /itemCanDelete\(\) on Repeater "items" threw/)
810
- } finally {
811
- console.warn = original
812
- }
813
- })
814
-
815
- it('all three gates compose on the same row', async () => {
816
- const f = repeater()
817
- .reorderable()
818
- .cloneable()
819
- .itemCanDelete(({ row }) => row?.index === 0)
820
- .itemCanClone(({ row }) => row?.index === 0)
821
- .itemCanReorder(({ row }) => row?.index === 0)
822
- const [raw] = await resolveSchema(
823
- [f],
824
- { values: { items: [{ product: 'A' }, { product: 'B' }] } },
825
- )
826
- const m = metaOf(raw)
827
- // Row 0 has all caps allowed (no flags stamped).
828
- assert.equal(m.rows[0]?.canDelete, undefined)
829
- assert.equal(m.rows[0]?.canClone, undefined)
830
- assert.equal(m.rows[0]?.canReorder, undefined)
831
- // Row 1 is pinned across all three caps.
832
- assert.equal(m.rows[1]?.canDelete, false)
833
- assert.equal(m.rows[1]?.canClone, false)
834
- assert.equal(m.rows[1]?.canReorder, false)
835
- })
836
- })
837
-
838
- // Live-reactive gates: when `Form.live()` re-resolves the schema after a
839
- // sibling field changes, `itemHidden / itemCan*` re-run with the fresh
840
- // values. The server-side check is "every `resolveSchema` call produces
841
- // gate flags from the current values map" — combined with `applyStateUpdate`
842
- // we round-trip a sibling-change cycle. The renderer-side sync (in
843
- // `RepeaterInput`) is unit-tested in `react/fields/syncRowGates.test.ts`.
844
- describe('reactive `itemHidden / itemCan*` (Form.live re-resolve)', () => {
845
- function repeater() {
846
- return RepeaterField.make('items').schema([
847
- TextField.make('product'),
848
- ToggleField.make('archived'),
849
- ])
850
- }
851
-
852
- function metaOf(m: unknown): RepeaterFieldMeta {
853
- return m as RepeaterFieldMeta
854
- }
855
-
856
- it('a sibling-row value flip re-evaluates the row\'s itemHidden', async () => {
857
- const f = repeater().itemHidden(({ values }) => Boolean(values?.['archived']))
858
-
859
- const before = metaOf(
860
- (await resolveSchema(
861
- [f],
862
- { values: { items: [{ product: 'A', archived: false }] } },
863
- ))[0],
864
- )
865
- assert.equal(before.rows[0]?.hidden, undefined)
866
-
867
- // Simulate the live POST: archive the row. The server's resolveSchema
868
- // call (driven by `formStateData`) sees the new value and stamps hidden.
869
- const after = metaOf(
870
- (await resolveSchema(
871
- [f],
872
- { values: { items: [{ product: 'A', archived: true }] } },
873
- ))[0],
874
- )
875
- assert.equal(after.rows[0]?.hidden, true)
876
- })
877
-
878
- it('a row-scoped value flip re-evaluates that row\'s itemCanDelete', async () => {
879
- const f = repeater().itemCanDelete(({ values }) => values?.['archived'] !== true)
880
-
881
- const before = metaOf(
882
- (await resolveSchema(
883
- [f],
884
- { values: { items: [{ product: 'A', archived: false }] } },
885
- ))[0],
886
- )
887
- assert.equal(before.rows[0]?.canDelete, undefined)
888
-
889
- const after = metaOf(
890
- (await resolveSchema(
891
- [f],
892
- { values: { items: [{ product: 'A', archived: true }] } },
893
- ))[0],
894
- )
895
- // Same row id, same product — only `archived` changed; gate stamps now.
896
- assert.equal(after.rows[0]?.canDelete, false)
897
- })
898
-
899
- it('a row-scoped value flip re-evaluates that row\'s itemLabel', async () => {
900
- const f = repeater().itemLabel(row => String(row['product'] ?? 'Untitled'))
901
-
902
- const before = metaOf(
903
- (await resolveSchema(
904
- [f],
905
- { values: { items: [{ product: 'Widget' }] } },
906
- ))[0],
907
- )
908
- assert.equal(before.rows[0]?.itemLabel, 'Widget')
909
-
910
- const after = metaOf(
911
- (await resolveSchema(
912
- [f],
913
- { values: { items: [{ product: 'Gear' }] } },
914
- ))[0],
915
- )
916
- // Same row id; the value changed so the label re-resolves.
917
- assert.equal(after.rows[0]?.itemLabel, 'Gear')
918
- })
919
-
920
- it('a row-scoped value flip re-evaluates that row\'s extraItemActions visibility', async () => {
921
- const send = Action.make('send').label('Send').visible(({ values }) => values?.['archived'] !== true)
922
- const f = repeater().extraItemActions([send])
923
-
924
- const before = metaOf(
925
- (await resolveSchema(
926
- [f],
927
- { values: { items: [{ product: 'A', archived: false }] } },
928
- ))[0],
929
- )
930
- assert.equal(before.rows[0]?.extraActions?.length, 1)
931
-
932
- const after = metaOf(
933
- (await resolveSchema(
934
- [f],
935
- { values: { items: [{ product: 'A', archived: true }] } },
936
- ))[0],
937
- )
938
- // Action's visibility predicate now returns false → action drops from
939
- // the row; row.extraActions becomes undefined (length-0 collapsed).
940
- assert.equal(after.rows[0]?.extraActions, undefined)
941
- })
942
- })
943
-
944
- describe('coerceFormValues (Step 3)', () => {
945
- function repeater() {
946
- return RepeaterField.make('items').schema([
947
- TextField.make('product'),
948
- NumberField.make('quantity'),
949
- ToggleField.make('featured'),
950
- ])
951
- }
952
-
953
- it('JSON-shape body — passes array through with per-row coercion', () => {
954
- const out = coerceFormValues(
955
- [repeater()],
956
- { items: [
957
- { product: 'Widget', quantity: '2', featured: 'true' },
958
- { product: 'Gear', quantity: '5', featured: '' },
959
- ] },
960
- )
961
- assert.deepEqual(out['items'], [
962
- { product: 'Widget', quantity: 2, featured: true },
963
- { product: 'Gear', quantity: 5, featured: false },
964
- ])
965
- })
966
-
967
- it('flat-shape body — groups by index and recurses', () => {
968
- const out = coerceFormValues(
969
- [repeater()],
970
- {
971
- 'items.0.product': 'Widget',
972
- 'items.0.quantity': '2',
973
- 'items.0.featured': 'true',
974
- 'items.1.product': 'Gear',
975
- 'items.1.quantity': '5',
976
- },
977
- )
978
- assert.deepEqual(out['items'], [
979
- { product: 'Widget', quantity: 2, featured: true },
980
- { product: 'Gear', quantity: 5, featured: false },
981
- ])
982
- })
983
-
984
- it('flat-shape body — strips flat keys from output', () => {
985
- const out = coerceFormValues(
986
- [repeater()],
987
- { 'items.0.product': 'Widget', 'items.0.quantity': '2' },
988
- )
989
- assert.equal('items.0.product' in out, false)
990
- assert.equal('items.0.quantity' in out, false)
991
- })
992
-
993
- it('flat-shape body — fills index gaps with empty rows', () => {
994
- const out = coerceFormValues(
995
- [repeater()],
996
- { 'items.0.product': 'A', 'items.2.product': 'C' },
997
- )
998
- const items = out['items'] as Array<Record<string, unknown>>
999
- assert.equal(items.length, 3)
1000
- assert.equal(items[0]?.['product'], 'A')
1001
- assert.equal(items[1]?.['product'], undefined)
1002
- assert.equal(items[2]?.['product'], 'C')
1003
- })
1004
-
1005
- it('preserves __id round-tripped from previous render', () => {
1006
- const out = coerceFormValues(
1007
- [repeater()],
1008
- { items: [{ __id: 'row-abc', product: 'Widget', quantity: '1' }] },
1009
- )
1010
- const items = out['items'] as Array<Record<string, unknown>>
1011
- assert.equal(items[0]?.['__id'], 'row-abc')
1012
- assert.equal(items[0]?.['product'], 'Widget')
1013
- })
1014
-
1015
- it('trims trailing untouched rows (no entered values)', () => {
1016
- const out = coerceFormValues(
1017
- [repeater()],
1018
- { items: [{ product: 'Widget' }, {}, { __id: 'x' }] },
1019
- )
1020
- assert.equal((out['items'] as unknown[]).length, 1)
1021
- })
1022
-
1023
- it('keeps a row with `0` or `false` even if nothing else is set', () => {
1024
- // 0 and false are real values; only undefined/null/'' count as untouched.
1025
- const out = coerceFormValues(
1026
- [repeater()],
1027
- { items: [{ quantity: '0' }, { featured: 'false' }] },
1028
- )
1029
- assert.equal((out['items'] as unknown[]).length, 2)
1030
- })
1031
-
1032
- it('preserves middle gaps (only trailing rows are trimmed)', () => {
1033
- const out = coerceFormValues(
1034
- [repeater()],
1035
- { items: [{ product: 'A' }, {}, { product: 'C' }] },
1036
- )
1037
- assert.equal((out['items'] as unknown[]).length, 3)
1038
- })
1039
-
1040
- it('non-array JSON body coerces to empty array', () => {
1041
- const out = coerceFormValues([repeater()], { items: 'not-an-array' })
1042
- assert.deepEqual(out['items'], [])
1043
- })
1044
-
1045
- it('missing body key → empty array', () => {
1046
- const out = coerceFormValues([repeater()], {})
1047
- assert.deepEqual(out['items'], [])
1048
- })
1049
-
1050
- it('Repeater inside a Section is still picked up', () => {
1051
- const out = coerceFormValues(
1052
- [Section.make('Line items').schema([repeater()])],
1053
- { items: [{ product: 'Widget', quantity: '3' }] },
1054
- )
1055
- // ToggleField('featured') coerces missing → false per standard rules; that's
1056
- // the inner schema's job, not Repeater-specific.
1057
- assert.deepEqual(out['items'], [{ product: 'Widget', quantity: 3, featured: false }])
1058
- })
1059
-
1060
- it('does not coerce inner fields against the parent body', () => {
1061
- // Parent body has `quantity: '999'` — should pass through to the parent
1062
- // out untouched (no parent-level NumberField). Inner row gets its own
1063
- // independent coercion: missing `quantity` → null per NumberField rules.
1064
- const out = coerceFormValues(
1065
- [TextField.make('parentField'), repeater()],
1066
- { parentField: 'parent', quantity: '999', items: [{ product: 'X' }] },
1067
- )
1068
- assert.equal(out['parentField'], 'parent')
1069
- assert.equal(out['quantity'], '999') // untouched — no parent-level field
1070
- const items = out['items'] as Array<Record<string, unknown>>
1071
- assert.equal(items[0]?.['quantity'], null) // inner field coerces undefined→null, NOT '999' from parent
1072
- })
1073
-
1074
- it('nested Repeater — inner row coercion runs recursively', () => {
1075
- const inner = RepeaterField.make('modifiers').schema([
1076
- TextField.make('name'),
1077
- NumberField.make('price'),
1078
- ])
1079
- const outer = RepeaterField.make('items').schema([
1080
- TextField.make('product'),
1081
- inner,
1082
- ])
1083
- const out = coerceFormValues(
1084
- [outer],
1085
- { items: [
1086
- { product: 'Burger', modifiers: [{ name: 'Cheese', price: '1.50' }] },
1087
- ] },
1088
- )
1089
- const items = out['items'] as Array<Record<string, unknown>>
1090
- const modifiers = items[0]?.['modifiers'] as Array<Record<string, unknown>>
1091
- assert.equal(modifiers[0]?.['name'], 'Cheese')
1092
- assert.equal(modifiers[0]?.['price'], 1.5)
1093
- })
1094
-
1095
- it('dehydrated(false) Repeater drops the value from the body', () => {
1096
- const f = RepeaterField.make('scratch')
1097
- .schema([TextField.make('note')])
1098
- .dehydrated(false)
1099
- const out = coerceFormValues(
1100
- [f],
1101
- { scratch: [{ note: 'temporary' }], real: 'value' },
1102
- )
1103
- assert.equal('scratch' in out, false)
1104
- assert.equal(out['real'], 'value')
1105
- })
1106
-
1107
- it('inner field with dehydrated(false) is dropped from each row', () => {
1108
- const f = RepeaterField.make('items').schema([
1109
- TextField.make('product'),
1110
- TextField.make('helper').dehydrated(false),
1111
- ])
1112
- const out = coerceFormValues(
1113
- [f],
1114
- { items: [{ product: 'Widget', helper: 'should-be-stripped' }] },
1115
- )
1116
- const items = out['items'] as Array<Record<string, unknown>>
1117
- assert.equal(items[0]?.['product'], 'Widget')
1118
- assert.equal('helper' in (items[0] ?? {}), false)
1119
- })
1120
- })
1121
-
1122
- describe('validateSchema (Step 4)', () => {
1123
- function repeater() {
1124
- return RepeaterField.make('items').schema([
1125
- TextField.make('product').required(),
1126
- NumberField.make('quantity'),
1127
- ])
1128
- }
1129
-
1130
- it('valid rows produce no errors', async () => {
1131
- const errors = await validateSchema(
1132
- [repeater()],
1133
- { items: [{ product: 'Widget', quantity: 1 }] },
1134
- )
1135
- assert.equal(isValid(errors), true)
1136
- })
1137
-
1138
- it('inner field errors are flat-keyed by row index', async () => {
1139
- const errors = await validateSchema(
1140
- [repeater()],
1141
- { items: [{ product: '' }, { product: 'OK' }, { product: '' }] },
1142
- )
1143
- assert.deepEqual(errors['items.0.product'], ['This field is required'])
1144
- assert.equal('items.1.product' in errors, false)
1145
- assert.deepEqual(errors['items.2.product'], ['This field is required'])
1146
- })
1147
-
1148
- it('minItems violation lands on the bare repeater name', async () => {
1149
- const f = RepeaterField.make('items')
1150
- .schema([TextField.make('product')])
1151
- .minItems(1)
1152
- const errors = await validateSchema([f], { items: [] })
1153
- assert.deepEqual(errors['items'], ['At least 1 item is required'])
1154
- })
1155
-
1156
- it('minItems > 1 uses plural messaging', async () => {
1157
- const f = RepeaterField.make('items')
1158
- .schema([TextField.make('product')])
1159
- .minItems(3)
1160
- const errors = await validateSchema([f], { items: [{ product: 'A' }] })
1161
- assert.deepEqual(errors['items'], ['At least 3 items are required'])
1162
- })
1163
-
1164
- it('maxItems violation lands on the bare repeater name', async () => {
1165
- const f = RepeaterField.make('items')
1166
- .schema([TextField.make('product')])
1167
- .maxItems(2)
1168
- const errors = await validateSchema(
1169
- [f],
1170
- { items: [{ product: 'A' }, { product: 'B' }, { product: 'C' }] },
1171
- )
1172
- assert.deepEqual(errors['items'], ['At most 2 items are allowed'])
1173
- })
1174
-
1175
- it('missing items field treated as empty array', async () => {
1176
- const f = RepeaterField.make('items')
1177
- .schema([TextField.make('product')])
1178
- .minItems(1)
1179
- const errors = await validateSchema([f], {})
1180
- assert.deepEqual(errors['items'], ['At least 1 item is required'])
1181
- })
1182
-
1183
- it('non-array items value treated as empty array', async () => {
1184
- const f = RepeaterField.make('items')
1185
- .schema([TextField.make('product')])
1186
- .minItems(1)
1187
- const errors = await validateSchema([f], { items: 'not-an-array' })
1188
- assert.deepEqual(errors['items'], ['At least 1 item is required'])
1189
- })
1190
-
1191
- it('does not validate inner fields against the parent values', async () => {
1192
- // Parent has `product` key, but the inner field shouldn't see it.
1193
- const errors = await validateSchema(
1194
- [TextField.make('product').required(), repeater()],
1195
- { product: 'parent', items: [{ product: '' }] },
1196
- )
1197
- assert.equal(errors['product'], undefined) // parent passed (has value)
1198
- assert.deepEqual(errors['items.0.product'], ['This field is required'])
1199
- })
1200
-
1201
- it('nested Repeater — inner row errors flat-keyed through both levels', async () => {
1202
- const inner = RepeaterField.make('modifiers').schema([
1203
- TextField.make('name').required(),
1204
- ])
1205
- const outer = RepeaterField.make('items').schema([
1206
- TextField.make('product'),
1207
- inner,
1208
- ])
1209
- const errors = await validateSchema(
1210
- [outer],
1211
- { items: [
1212
- { product: 'A', modifiers: [{ name: '' }, { name: 'Cheese' }] },
1213
- ] },
1214
- )
1215
- assert.deepEqual(errors['items.0.modifiers.0.name'], ['This field is required'])
1216
- assert.equal('items.0.modifiers.1.name' in errors, false)
1217
- })
1218
-
1219
- it('combines bare-key min violation with per-row errors', async () => {
1220
- const f = RepeaterField.make('items')
1221
- .schema([TextField.make('product').required()])
1222
- .minItems(2)
1223
- const errors = await validateSchema([f], { items: [{ product: '' }] })
1224
- assert.deepEqual(errors['items'], ['At least 2 items are required'])
1225
- assert.deepEqual(errors['items.0.product'], ['This field is required'])
1226
- })
1227
- })
1228
-
1229
- describe('distinct() — cross-row uniqueness', () => {
1230
- function distinctRepeater() {
1231
- return RepeaterField.make('items').schema([
1232
- TextField.make('product').distinct(),
1233
- NumberField.make('quantity'),
1234
- ])
1235
- }
1236
-
1237
- it('all-unique rows produce no error', async () => {
1238
- const errors = await validateSchema([distinctRepeater()], {
1239
- items: [{ product: 'A' }, { product: 'B' }, { product: 'C' }],
1240
- })
1241
- assert.equal(isValid(errors), true)
1242
- })
1243
-
1244
- it('duplicate value flags every row beyond the first occurrence', async () => {
1245
- const errors = await validateSchema([distinctRepeater()], {
1246
- items: [{ product: 'A' }, { product: 'A' }, { product: 'A' }],
1247
- })
1248
- assert.equal('items.0.product' in errors, false)
1249
- assert.deepEqual(errors['items.1.product'], ['Must be unique'])
1250
- assert.deepEqual(errors['items.2.product'], ['Must be unique'])
1251
- })
1252
-
1253
- it('first occurrence is always allowed (even at the last row)', async () => {
1254
- const errors = await validateSchema([distinctRepeater()], {
1255
- items: [{ product: 'A' }, { product: 'B' }, { product: 'A' }],
1256
- })
1257
- assert.equal('items.0.product' in errors, false)
1258
- assert.equal('items.1.product' in errors, false)
1259
- assert.deepEqual(errors['items.2.product'], ['Must be unique'])
1260
- })
1261
-
1262
- it('default ignoreNulls=true skips empty / null / undefined values', async () => {
1263
- const errors = await validateSchema([distinctRepeater()], {
1264
- items: [{ product: '' }, { product: '' }, { product: null }, {}],
1265
- })
1266
- assert.equal(isValid(errors), true)
1267
- })
1268
-
1269
- it('ignoreNulls=false flags duplicate empty rows too', async () => {
1270
- const f = RepeaterField.make('items').schema([
1271
- TextField.make('product').distinct({ ignoreNulls: false }),
1272
- ])
1273
- const errors = await validateSchema([f], {
1274
- items: [{ product: '' }, { product: '' }],
1275
- })
1276
- assert.deepEqual(errors['items.1.product'], ['Must be unique'])
1277
- })
1278
-
1279
- it('caseInsensitive folds case before comparing', async () => {
1280
- const f = RepeaterField.make('items').schema([
1281
- TextField.make('product').distinct({ caseInsensitive: true }),
1282
- ])
1283
- const errors = await validateSchema([f], {
1284
- items: [{ product: 'Foo' }, { product: 'foo' }, { product: 'FOO' }],
1285
- })
1286
- assert.equal('items.0.product' in errors, false)
1287
- assert.deepEqual(errors['items.1.product'], ['Must be unique'])
1288
- assert.deepEqual(errors['items.2.product'], ['Must be unique'])
1289
- })
1290
-
1291
- it('caseInsensitive=false (default) treats different cases as distinct', async () => {
1292
- const errors = await validateSchema([distinctRepeater()], {
1293
- items: [{ product: 'Foo' }, { product: 'foo' }],
1294
- })
1295
- assert.equal(isValid(errors), true)
1296
- })
1297
-
1298
- it('custom message overrides the default', async () => {
1299
- const f = RepeaterField.make('items').schema([
1300
- TextField.make('product').distinct({ message: 'Each product must appear once' }),
1301
- ])
1302
- const errors = await validateSchema([f], {
1303
- items: [{ product: 'A' }, { product: 'A' }],
1304
- })
1305
- assert.deepEqual(errors['items.1.product'], ['Each product must appear once'])
1306
- })
1307
-
1308
- it('runs alongside per-field validators (does not replace them)', async () => {
1309
- const f = RepeaterField.make('items').schema([
1310
- TextField.make('product').required().distinct(),
1311
- ])
1312
- const errors = await validateSchema([f], {
1313
- items: [{ product: 'A' }, { product: '' }, { product: 'A' }],
1314
- })
1315
- // Row 1 fails required (empty); row 2 fails distinct (duplicate of row 0).
1316
- assert.deepEqual(errors['items.1.product'], ['This field is required'])
1317
- assert.deepEqual(errors['items.2.product'], ['Must be unique'])
1318
- })
1319
-
1320
- it('multiple distinct fields are independent', async () => {
1321
- const f = RepeaterField.make('items').schema([
1322
- TextField.make('sku').distinct(),
1323
- TextField.make('label').distinct(),
1324
- ])
1325
- const errors = await validateSchema([f], {
1326
- items: [
1327
- { sku: 'X', label: 'red' },
1328
- { sku: 'X', label: 'blue' }, // dup sku, unique label
1329
- { sku: 'Y', label: 'red' }, // unique sku, dup label
1330
- ],
1331
- })
1332
- assert.deepEqual(errors['items.1.sku'], ['Must be unique'])
1333
- assert.deepEqual(errors['items.2.label'], ['Must be unique'])
1334
- assert.equal('items.1.label' in errors, false)
1335
- assert.equal('items.2.sku' in errors, false)
1336
- })
1337
-
1338
- it('distinct() is a no-op outside an array-row context (no top-level cross-form check)', async () => {
1339
- // A distinct flag on a regular form Field never fires through validateSchema —
1340
- // there's nothing to compare against. This locks in the no-op posture so a
1341
- // future refactor can't accidentally widen distinct() to a single-row context.
1342
- const errors = await validateSchema(
1343
- [TextField.make('product').distinct()],
1344
- { product: 'A' },
1345
- )
1346
- assert.equal(isValid(errors), true)
1347
- })
1348
-
1349
- it('distinct(false) clears a previously-set rule', async () => {
1350
- const field = TextField.make('product').distinct({ caseInsensitive: true }).distinct(false)
1351
- const f = RepeaterField.make('items').schema([field])
1352
- const errors = await validateSchema([f], {
1353
- items: [{ product: 'A' }, { product: 'A' }],
1354
- })
1355
- assert.equal(isValid(errors), true)
1356
- })
1357
-
1358
- it('compares values across non-trailing rows when later rows are empty', async () => {
1359
- const errors = await validateSchema([distinctRepeater()], {
1360
- items: [{ product: 'A' }, { product: 'A' }, {}],
1361
- })
1362
- assert.deepEqual(errors['items.1.product'], ['Must be unique'])
1363
- })
1364
- })
1365
-
1366
- describe('applyStateUpdate (Step 5 — reactive interop)', () => {
1367
- function buildForm(repeater: RepeaterField): Form {
1368
- return Form.make().schema([repeater])
1369
- }
1370
-
1371
- it('routes a top-level (no-dot) name through the existing path', async () => {
1372
- const f = buildForm(
1373
- RepeaterField.make('items').schema([TextField.make('product')]),
1374
- )
1375
- // Bare 'items' — coerces against the Repeater itself (whole-array path)
1376
- const result = await applyStateUpdate(f, { items: [{ product: 'X' }] }, 'items')
1377
- assert.notEqual(result, null)
1378
- assert.deepEqual(result?.dirty, ['items'])
1379
- })
1380
-
1381
- it('returns null (404) when dotted path doesn\'t resolve', async () => {
1382
- const f = buildForm(
1383
- RepeaterField.make('items').schema([TextField.make('product')]),
1384
- )
1385
- const result = await applyStateUpdate(f, { items: [{}] }, 'items.0.unknown')
1386
- assert.equal(result, null)
1387
- })
1388
-
1389
- it('returns null when row index isn\'t a valid integer', async () => {
1390
- const f = buildForm(
1391
- RepeaterField.make('items').schema([TextField.make('product')]),
1392
- )
1393
- const result = await applyStateUpdate(f, { items: [{}] }, 'items.notanumber.product')
1394
- assert.equal(result, null)
1395
- })
1396
-
1397
- it('returns null when path resolves to non-Repeater field followed by index', async () => {
1398
- const f = buildForm(
1399
- RepeaterField.make('items').schema([TextField.make('product')]),
1400
- )
1401
- // 'items.0.product.0' — product is a TextField, not a Repeater, so
1402
- // 'product.0' is invalid.
1403
- const result = await applyStateUpdate(f, { items: [{ product: 'X' }] }, 'items.0.product.0')
1404
- assert.equal(result, null)
1405
- })
1406
-
1407
- it('coerces only the leaf field on the right row', async () => {
1408
- const f = buildForm(
1409
- RepeaterField.make('items').schema([
1410
- TextField.make('product'),
1411
- NumberField.make('quantity'),
1412
- ]),
1413
- )
1414
- const result = await applyStateUpdate(
1415
- f,
1416
- { items: [{ product: 'A', quantity: '1' }, { product: 'B', quantity: '5' }] },
1417
- 'items.1.quantity',
1418
- )
1419
- const items = result?.values['items'] as Array<Record<string, unknown>>
1420
- assert.equal(items[0]?.['quantity'], '1') // row 0 untouched (still raw string)
1421
- assert.equal(items[1]?.['quantity'], 5) // row 1 coerced to number
1422
- assert.equal(items[0]?.['product'], 'A') // siblings untouched
1423
- assert.deepEqual(result?.dirty, ['items.1.quantity'])
1424
- })
1425
-
1426
- it('row-scoped $get reads only the row\'s siblings', async () => {
1427
- let captured: unknown
1428
- const f = buildForm(
1429
- RepeaterField.make('items').schema([
1430
- NumberField.make('quantity').live().afterStateUpdated((_v, { $get }) => {
1431
- captured = $get('product')
1432
- }),
1433
- TextField.make('product'),
1434
- ]),
1435
- )
1436
- await applyStateUpdate(
1437
- f,
1438
- { items: [{ product: 'rowZero', quantity: '0' }, { product: 'rowOne', quantity: '99' }] },
1439
- 'items.1.quantity',
1440
- )
1441
- assert.equal(captured, 'rowOne') // row 1's product, not row 0
1442
- })
1443
-
1444
- it('row-scoped $set writes to the same row and tracks dirty in dotted form', async () => {
1445
- const f = buildForm(
1446
- RepeaterField.make('items').schema([
1447
- TextField.make('product').live().afterStateUpdated((_v, { $set }) => {
1448
- $set('slug', 'derived')
1449
- }),
1450
- TextField.make('slug'),
1451
- ]),
1452
- )
1453
- const result = await applyStateUpdate(
1454
- f,
1455
- { items: [{ product: 'first' }, { product: 'second' }] },
1456
- 'items.1.product',
1457
- )
1458
- const items = result?.values['items'] as Array<Record<string, unknown>>
1459
- assert.equal(items[0]?.['slug'], undefined) // row 0 untouched
1460
- assert.equal(items[1]?.['slug'], 'derived') // row 1 mutated
1461
- assert.ok(result?.dirty.includes('items.1.product'))
1462
- assert.ok(result?.dirty.includes('items.1.slug'))
1463
- })
1464
-
1465
- it('dotted-path $get/$set reaches into other rows', async () => {
1466
- const seen: unknown[] = []
1467
- const f = buildForm(
1468
- RepeaterField.make('items').schema([
1469
- TextField.make('product').live().afterStateUpdated((_v, { $get, $set }) => {
1470
- seen.push($get('items.0.product'))
1471
- $set('items.0.notes', 'cross-row')
1472
- }),
1473
- ]),
1474
- )
1475
- const result = await applyStateUpdate(
1476
- f,
1477
- { items: [{ product: 'A' }, { product: 'B' }] },
1478
- 'items.1.product',
1479
- )
1480
- assert.deepEqual(seen, ['A'])
1481
- const items = result?.values['items'] as Array<Record<string, unknown>>
1482
- assert.equal(items[0]?.['notes'], 'cross-row')
1483
- assert.ok(result?.dirty.includes('items.0.notes'))
1484
- })
1485
-
1486
- it('exposes ctx.row.index + row.$get / row.$set sugar', async () => {
1487
- let seenIdx: number | undefined
1488
- let seenSibling: unknown
1489
- const f = buildForm(
1490
- RepeaterField.make('items').schema([
1491
- TextField.make('product').live().afterStateUpdated((_v, { row }) => {
1492
- seenIdx = row?.index
1493
- seenSibling = row?.$get('product')
1494
- }),
1495
- ]),
1496
- )
1497
- await applyStateUpdate(
1498
- f,
1499
- { items: [{}, {}, { product: 'thirdRow' }] },
1500
- 'items.2.product',
1501
- )
1502
- assert.equal(seenIdx, 2)
1503
- assert.equal(seenSibling, 'thirdRow')
1504
- })
1505
-
1506
- it('does not mutate the input values map', async () => {
1507
- const input = { items: [{ product: 'A', quantity: '1' }] }
1508
- const inputBefore = JSON.parse(JSON.stringify(input))
1509
- const f = buildForm(
1510
- RepeaterField.make('items').schema([
1511
- TextField.make('product'),
1512
- NumberField.make('quantity'),
1513
- ]),
1514
- )
1515
- await applyStateUpdate(f, input, 'items.0.quantity')
1516
- assert.deepEqual(input, inputBefore)
1517
- })
1518
-
1519
- it('handles nested Repeaters', async () => {
1520
- const inner = RepeaterField.make('modifiers').schema([
1521
- TextField.make('name').live().afterStateUpdated((_v, { $get, row }) => {
1522
- // row-scoped $get reads the modifier row's siblings
1523
- ;(globalThis as Record<string, unknown>)['__nested_seen'] = {
1524
- sibling: $get('name'),
1525
- index: row?.index,
1526
- }
1527
- }),
1528
- ])
1529
- const f = buildForm(
1530
- RepeaterField.make('items').schema([
1531
- TextField.make('product'),
1532
- inner,
1533
- ]),
1534
- )
1535
- await applyStateUpdate(
1536
- f,
1537
- { items: [
1538
- { product: 'A', modifiers: [{ name: 'Cheese' }, { name: 'Bacon' }] },
1539
- ] },
1540
- 'items.0.modifiers.1.name',
1541
- )
1542
- const seen = (globalThis as Record<string, unknown>)['__nested_seen'] as {
1543
- sibling: unknown
1544
- index: number
1545
- }
1546
- assert.equal(seen.sibling, 'Bacon')
1547
- assert.equal(seen.index, 1)
1548
- delete (globalThis as Record<string, unknown>)['__nested_seen']
1549
- })
1550
-
1551
- it('creates the row map when submitted values is missing the row', async () => {
1552
- // The client posts with `values.items` defined but the row at the
1553
- // changed index is missing — ensure the resolver fills it.
1554
- const f = buildForm(
1555
- RepeaterField.make('items').schema([TextField.make('product')]),
1556
- )
1557
- const result = await applyStateUpdate(f, { items: [] }, 'items.0.product')
1558
- assert.notEqual(result, null)
1559
- const items = result?.values['items'] as Array<Record<string, unknown>>
1560
- assert.equal(items.length, 1)
1561
- })
1562
- })
1563
-
1564
- describe('layout visibility interop (Step 6)', () => {
1565
- function metaOf(m: unknown): RepeaterFieldMeta {
1566
- return m as RepeaterFieldMeta
1567
- }
1568
-
1569
- it('inner Section.visible sees row-scoped values', async () => {
1570
- const f = RepeaterField.make('items').schema([
1571
- TextField.make('kind'),
1572
- Section.make('Advanced')
1573
- .schema([TextField.make('detail')])
1574
- .visible(({ values }) => values?.['kind'] === 'advanced'),
1575
- ])
1576
- const [raw] = await resolveSchema(
1577
- [f],
1578
- { values: { items: [{ kind: 'simple' }, { kind: 'advanced' }] } },
1579
- )
1580
- const m = metaOf(raw)
1581
-
1582
- // Row 0: kind='simple' → Section hidden → only `kind` field rendered
1583
- assert.equal(m.rows[0]?.children.length, 1)
1584
- assert.equal((m.rows[0]?.children[0] as unknown as { name: string }).name, 'kind')
1585
-
1586
- // Row 1: kind='advanced' → Section rendered with its child
1587
- assert.equal(m.rows[1]?.children.length, 2)
1588
- const section = m.rows[1]?.children[1] as unknown as { type: string; children?: unknown[] }
1589
- assert.equal(section.type, 'section')
1590
- assert.equal(section.children?.length, 1)
1591
- })
1592
-
1593
- it('inner Section.visible sees ctx.row.index when explicit row access is needed', async () => {
1594
- const seenIndices: Array<number | undefined> = []
1595
- const f = RepeaterField.make('items').schema([
1596
- Section.make('Detail')
1597
- .schema([TextField.make('x')])
1598
- .visible((ctx) => {
1599
- seenIndices.push(ctx.row?.index)
1600
- return true
1601
- }),
1602
- ])
1603
- await resolveSchema([f], { values: { items: [{}, {}, {}] } })
1604
- // 3 rows + 1 template resolve (no row) — but template only runs visibility too?
1605
- // Actually visibility runs during template too. Filter undefineds for the
1606
- // template; the 3 row resolves should give us [0, 1, 2] in some order.
1607
- const rowOnlyIndices = seenIndices.filter((i): i is number => i !== undefined).sort()
1608
- assert.deepEqual(rowOnlyIndices, [0, 1, 2])
1609
- })
1610
-
1611
- it('inner Section.visible(false) drops the section in every row', async () => {
1612
- const f = RepeaterField.make('items').schema([
1613
- TextField.make('a'),
1614
- Section.make('Hidden').schema([TextField.make('b')]).visible(false),
1615
- ])
1616
- const [raw] = await resolveSchema(
1617
- [f],
1618
- { values: { items: [{ a: 'x' }, { a: 'y' }] } },
1619
- )
1620
- const m = metaOf(raw)
1621
- for (const row of m.rows) {
1622
- assert.equal(row.children.length, 1)
1623
- assert.equal((row.children[0] as unknown as { name: string }).name, 'a')
1624
- }
1625
- })
1626
-
1627
- it('throwing visibility rule in a row falls closed (section dropped)', async () => {
1628
- const original = console.warn
1629
- const warns: unknown[][] = []
1630
- console.warn = (...args: unknown[]) => { warns.push(args) }
1631
- try {
1632
- const f = RepeaterField.make('items').schema([
1633
- TextField.make('a'),
1634
- Section.make('Wonky')
1635
- .schema([TextField.make('b')])
1636
- .visible(() => { throw new Error('boom') }),
1637
- ])
1638
- const [raw] = await resolveSchema(
1639
- [f],
1640
- { values: { items: [{}, {}] } },
1641
- )
1642
- const m = metaOf(raw)
1643
- for (const row of m.rows) {
1644
- assert.equal(row.children.length, 1)
1645
- }
1646
- } finally {
1647
- console.warn = original
1648
- }
1649
- })
1650
- })
1651
-
1652
- describe('walker registrations (Step 10)', () => {
1653
- it('isRepeaterField uses structural type discrimination', () => {
1654
- const r = RepeaterField.make('items')
1655
- assert.equal(isRepeaterField(r), true)
1656
- const t = TextField.make('product')
1657
- assert.equal(isRepeaterField(t), false)
1658
- const s = Section.make('S')
1659
- assert.equal(isRepeaterField(s), false)
1660
- })
1661
-
1662
- it('findForms does not dive into Repeater children', () => {
1663
- const innerForm = Form.make().schema([TextField.make('x')])
1664
- const outer = Form.make().schema([
1665
- TextField.make('top'),
1666
- RepeaterField.make('items').schema([
1667
- TextField.make('product'),
1668
- innerForm, // intentionally weird — should NOT be discovered
1669
- ]),
1670
- ])
1671
- const found = findForms([outer])
1672
- assert.equal(found.length, 1)
1673
- assert.strictEqual(found[0], outer)
1674
- })
1675
-
1676
- it('findActions does not dive into Repeater children', () => {
1677
- const innerAction = Action.make('rowAction').handler(() => undefined)
1678
- const outerAction = Action.make('headerAction').handler(() => undefined)
1679
- const form = Form.make().schema([
1680
- outerAction,
1681
- RepeaterField.make('items').schema([
1682
- TextField.make('product'),
1683
- innerAction, // intentionally weird — should NOT be discovered
1684
- ]),
1685
- ])
1686
- const found = findActions([form])
1687
- assert.equal(found.length, 1)
1688
- assert.strictEqual(found[0], outerAction)
1689
- })
1690
- })
1691
-
1692
- describe('inheritance from Field', () => {
1693
- it('inherits required()', () => {
1694
- const meta = RepeaterField.make('items').required().toMeta()
1695
- assert.equal(meta.required, true)
1696
- })
1697
-
1698
- it('inherits helperText()', () => {
1699
- const meta = RepeaterField.make('items').helperText('At least one row').toMeta()
1700
- assert.equal(meta.helperText, 'At least one row')
1701
- })
1702
-
1703
- it('inherits label() override', () => {
1704
- const meta = RepeaterField.make('items').label('Custom label').toMeta()
1705
- assert.equal(meta.label, 'Custom label')
1706
- })
1707
-
1708
- it('inherits live() reactive flag', () => {
1709
- const meta = RepeaterField.make('items').live().toMeta()
1710
- assert.equal(meta.live, true)
1711
- })
1712
- })
1713
-
1714
- describe('extraItemActions (per-row buttons)', () => {
1715
- it('builder stores extra actions; getter returns them', () => {
1716
- const a = Action.make('promote').handler(() => undefined)
1717
- const b = Action.make('archive').handler(() => undefined)
1718
- const f = RepeaterField.make('items').extraItemActions([a, b])
1719
- assert.deepEqual(f.getExtraItemActions(), [a, b])
1720
- })
1721
-
1722
- it('getter defaults to empty array', () => {
1723
- assert.deepEqual(RepeaterField.make('items').getExtraItemActions(), [])
1724
- })
1725
-
1726
- it('per-row resolve stamps extraActions on each row meta', async () => {
1727
- const promote = Action.make('promote').handler(() => undefined)
1728
- const f = RepeaterField.make('items')
1729
- .schema([TextField.make('title')])
1730
- .extraItemActions([promote])
1731
-
1732
- const [meta] = await resolveSchema([f], { values: { items: [{ title: 'a' }, { title: 'b' }] } })
1733
- const repeater = meta as RepeaterFieldMeta
1734
- assert.equal(repeater.rows.length, 2)
1735
- assert.equal(repeater.rows[0]!.extraActions?.length, 1)
1736
- assert.equal(repeater.rows[0]!.extraActions?.[0]?.name, 'promote')
1737
- assert.equal(repeater.rows[1]!.extraActions?.length, 1)
1738
- })
1739
-
1740
- it('absent when no extra actions registered', async () => {
1741
- const f = RepeaterField.make('items')
1742
- .schema([TextField.make('title')])
1743
- const [meta] = await resolveSchema([f], { values: { items: [{ title: 'a' }] } })
1744
- const repeater = meta as RepeaterFieldMeta
1745
- assert.equal(repeater.rows[0]!.extraActions, undefined)
1746
- })
1747
-
1748
- it('drops actions whose visible() rule resolves false for that row', async () => {
1749
- const featured = Action.make('feature')
1750
- .handler(() => undefined)
1751
- .visible(({ values }) => values?.['status'] !== 'featured')
1752
- const f = RepeaterField.make('items')
1753
- .schema([TextField.make('title')])
1754
- .extraItemActions([featured])
1755
-
1756
- const [meta] = await resolveSchema([f], { values: { items: [
1757
- { title: 'a', status: 'draft' },
1758
- { title: 'b', status: 'featured' },
1759
- ] } })
1760
- const repeater = meta as RepeaterFieldMeta
1761
- // Row 0 (draft) keeps the action; row 1 (featured) drops it.
1762
- assert.equal(repeater.rows[0]!.extraActions?.length, 1)
1763
- assert.equal(repeater.rows[1]!.extraActions, undefined)
1764
- })
1765
-
1766
- it('stamps disabled: true when disabled() rule resolves true', async () => {
1767
- const send = Action.make('sendTest')
1768
- .handler(() => undefined)
1769
- .disabled(({ values }) => !values?.['email'])
1770
- const f = RepeaterField.make('subscribers')
1771
- .schema([TextField.make('email')])
1772
- .extraItemActions([send])
1773
-
1774
- const [meta] = await resolveSchema([f], { values: { subscribers: [
1775
- { email: '' },
1776
- { email: 'x@y.io' },
1777
- ] } })
1778
- const repeater = meta as RepeaterFieldMeta
1779
- assert.equal(repeater.rows[0]!.extraActions?.[0]?.disabled, true)
1780
- assert.equal(repeater.rows[1]!.extraActions?.[0]?.disabled, undefined)
1781
- })
1782
-
1783
- it('predicate sees parent record + user', async () => {
1784
- let seenRecord: unknown
1785
- let seenUser: unknown
1786
- const a = Action.make('a')
1787
- .handler(() => undefined)
1788
- .visible(({ record, user }) => {
1789
- seenRecord = record
1790
- seenUser = user
1791
- return true
1792
- })
1793
- const f = RepeaterField.make('items')
1794
- .schema([TextField.make('title')])
1795
- .extraItemActions([a])
1796
-
1797
- await resolveSchema([f], {
1798
- values: { items: [{ title: 'x' }] },
1799
- record: { id: 'parent-1' },
1800
- user: { name: 'admin' },
1801
- })
1802
- assert.deepEqual(seenRecord, { id: 'parent-1' })
1803
- assert.deepEqual(seenUser, { name: 'admin' })
1804
- })
1805
- })
1806
- })