@pilotiq/pilotiq 0.24.1 → 0.24.3

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 (518) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/boost/guidelines.md +571 -0
  3. package/boost/skills/pilotiq-actions/SKILL.md +49 -0
  4. package/boost/skills/pilotiq-actions/rules/dispatch-modes.md +177 -0
  5. package/boost/skills/pilotiq-actions/rules/factories.md +130 -0
  6. package/boost/skills/pilotiq-actions/rules/visibility-and-authorization.md +125 -0
  7. package/boost/skills/pilotiq-fields/SKILL.md +47 -0
  8. package/boost/skills/pilotiq-fields/rules/field-catalog.md +288 -0
  9. package/boost/skills/pilotiq-fields/rules/reactive-fields.md +199 -0
  10. package/boost/skills/pilotiq-fields/rules/validation.md +198 -0
  11. package/boost/skills/pilotiq-relations/SKILL.md +47 -0
  12. package/boost/skills/pilotiq-relations/rules/relation-managers.md +256 -0
  13. package/boost/skills/pilotiq-relations/rules/repeater-relationship.md +177 -0
  14. package/boost/skills/pilotiq-resource/SKILL.md +61 -0
  15. package/boost/skills/pilotiq-resource/rules/authorization.md +242 -0
  16. package/boost/skills/pilotiq-resource/rules/defining-resources.md +228 -0
  17. package/boost/skills/pilotiq-resource/rules/page-overrides.md +296 -0
  18. package/dist/Pilotiq.d.ts +31 -0
  19. package/dist/Pilotiq.d.ts.map +1 -1
  20. package/dist/Pilotiq.js +3 -1
  21. package/dist/Pilotiq.js.map +1 -1
  22. package/dist/PilotiqRegistry.d.ts +13 -0
  23. package/dist/PilotiqRegistry.d.ts.map +1 -1
  24. package/dist/PilotiqRegistry.js +15 -0
  25. package/dist/PilotiqRegistry.js.map +1 -1
  26. package/dist/pageData/misc.d.ts.map +1 -1
  27. package/dist/pageData/misc.js +6 -0
  28. package/dist/pageData/misc.js.map +1 -1
  29. package/dist/pageData/navigation.d.ts +1 -0
  30. package/dist/pageData/navigation.d.ts.map +1 -1
  31. package/dist/pageData/navigation.js +3 -0
  32. package/dist/pageData/navigation.js.map +1 -1
  33. package/dist/pageData/relationPages.d.ts.map +1 -1
  34. package/dist/pageData/relationPages.js +3 -0
  35. package/dist/pageData/relationPages.js.map +1 -1
  36. package/dist/pageData/resourcePages.d.ts.map +1 -1
  37. package/dist/pageData/resourcePages.js +8 -0
  38. package/dist/pageData/resourcePages.js.map +1 -1
  39. package/dist/react/AppShell.d.ts +8 -0
  40. package/dist/react/AppShell.d.ts.map +1 -1
  41. package/dist/react/AppShell.js.map +1 -1
  42. package/dist/react/layouts/SidebarLayout.d.ts.map +1 -1
  43. package/dist/react/layouts/SidebarLayout.js +10 -2
  44. package/dist/react/layouts/SidebarLayout.js.map +1 -1
  45. package/dist/react/widgets/StatsOverviewRenderer.d.ts.map +1 -1
  46. package/dist/react/widgets/StatsOverviewRenderer.js +32 -18
  47. package/dist/react/widgets/StatsOverviewRenderer.js.map +1 -1
  48. package/dist/routes/relations.d.ts.map +1 -1
  49. package/dist/routes/relations.js +25 -18
  50. package/dist/routes/relations.js.map +1 -1
  51. package/dist/routes/resources.js.map +1 -1
  52. package/package.json +10 -5
  53. package/.turbo/turbo-build.log +0 -8
  54. package/CLAUDE.md +0 -265
  55. package/src/Cluster.test.ts +0 -283
  56. package/src/Cluster.ts +0 -83
  57. package/src/Column.test.ts +0 -199
  58. package/src/Column.ts +0 -710
  59. package/src/Global.test.ts +0 -367
  60. package/src/Global.ts +0 -169
  61. package/src/Page.test.ts +0 -114
  62. package/src/Page.ts +0 -208
  63. package/src/Pilotiq.perf.test.ts +0 -252
  64. package/src/Pilotiq.test.ts +0 -129
  65. package/src/Pilotiq.ts +0 -1158
  66. package/src/PilotiqRegistry.ts +0 -36
  67. package/src/PilotiqServiceProvider.ts +0 -121
  68. package/src/RelationManager.test.ts +0 -400
  69. package/src/RelationManager.ts +0 -527
  70. package/src/RenderHook.test.ts +0 -252
  71. package/src/RenderHook.ts +0 -242
  72. package/src/Resource.test.ts +0 -284
  73. package/src/Resource.ts +0 -526
  74. package/src/RightPanel.test.ts +0 -202
  75. package/src/RightPanel.ts +0 -132
  76. package/src/Tab.test.ts +0 -91
  77. package/src/Tab.ts +0 -156
  78. package/src/UserMenuItem.ts +0 -145
  79. package/src/actions/Action.test.ts +0 -2526
  80. package/src/actions/Action.ts +0 -1515
  81. package/src/actions/ActionGroup.test.ts +0 -112
  82. package/src/actions/ActionGroup.ts +0 -173
  83. package/src/actions/attachFactory.ts +0 -172
  84. package/src/actions/bulkFactories.ts +0 -168
  85. package/src/actions/crudFactories.ts +0 -220
  86. package/src/actions/exportFactory.ts +0 -225
  87. package/src/actions/factoryHelpers.ts +0 -177
  88. package/src/actions/importFactory.ts +0 -243
  89. package/src/actions/index.ts +0 -17
  90. package/src/actions/m2mFactories.ts +0 -193
  91. package/src/actions/relationFactories.ts +0 -372
  92. package/src/applyPageHooks.test.ts +0 -463
  93. package/src/applyPageHooks.ts +0 -330
  94. package/src/authorization.test.ts +0 -483
  95. package/src/breadcrumbs.test.ts +0 -238
  96. package/src/cells/coerce.test.ts +0 -85
  97. package/src/cells/coerce.ts +0 -84
  98. package/src/clusterPaths.ts +0 -35
  99. package/src/columns/BadgeColumn.test.ts +0 -54
  100. package/src/columns/BadgeColumn.ts +0 -32
  101. package/src/columns/BooleanColumn.test.ts +0 -41
  102. package/src/columns/BooleanColumn.ts +0 -18
  103. package/src/columns/ColorColumn.test.ts +0 -37
  104. package/src/columns/ColorColumn.ts +0 -38
  105. package/src/columns/IconColumn.test.ts +0 -54
  106. package/src/columns/IconColumn.ts +0 -37
  107. package/src/columns/ImageColumn.test.ts +0 -41
  108. package/src/columns/ImageColumn.ts +0 -28
  109. package/src/columns/SelectColumn.ts +0 -98
  110. package/src/columns/TextColumn.test.ts +0 -190
  111. package/src/columns/TextColumn.ts +0 -20
  112. package/src/columns/TextInputColumn.ts +0 -68
  113. package/src/columns/ToggleColumn.ts +0 -46
  114. package/src/columns/editableColumns.test.ts +0 -238
  115. package/src/columns/index.ts +0 -9
  116. package/src/defaultGlobalPages.ts +0 -95
  117. package/src/defaultPages.test.ts +0 -634
  118. package/src/defaultPages.ts +0 -617
  119. package/src/defaultViewPage.test.ts +0 -147
  120. package/src/elements/Form.test.ts +0 -223
  121. package/src/elements/Form.ts +0 -416
  122. package/src/elements/ListTabs.ts +0 -28
  123. package/src/elements/Table.test.ts +0 -422
  124. package/src/elements/Table.ts +0 -850
  125. package/src/elements/TableGroup.test.ts +0 -260
  126. package/src/elements/TableGroup.ts +0 -334
  127. package/src/elements/dispatchAction.test.ts +0 -463
  128. package/src/elements/dispatchAction.ts +0 -355
  129. package/src/elements/dispatchForm.test.ts +0 -477
  130. package/src/elements/dispatchForm.ts +0 -1993
  131. package/src/elements/dispatchTable.test.ts +0 -1514
  132. package/src/elements/dispatchTable.ts +0 -745
  133. package/src/elements/index.ts +0 -21
  134. package/src/entries/BadgeEntry.ts +0 -39
  135. package/src/entries/CodeEntry.test.ts +0 -40
  136. package/src/entries/CodeEntry.ts +0 -52
  137. package/src/entries/ColorEntry.ts +0 -63
  138. package/src/entries/ComponentEntry.test.ts +0 -173
  139. package/src/entries/ComponentEntry.ts +0 -95
  140. package/src/entries/Entry.ts +0 -304
  141. package/src/entries/IconEntry.ts +0 -49
  142. package/src/entries/ImageEntry.ts +0 -61
  143. package/src/entries/KeyValueEntry.ts +0 -47
  144. package/src/entries/RepeatableEntry.test.ts +0 -239
  145. package/src/entries/RepeatableEntry.ts +0 -173
  146. package/src/entries/TextEntry.test.ts +0 -394
  147. package/src/entries/TextEntry.ts +0 -60
  148. package/src/entries/index.ts +0 -12
  149. package/src/entries/leaves.test.ts +0 -306
  150. package/src/entries/registry.ts +0 -54
  151. package/src/fields/BuilderField.test.ts +0 -1188
  152. package/src/fields/BuilderField.ts +0 -605
  153. package/src/fields/BuilderRelationship.test.ts +0 -811
  154. package/src/fields/CheckboxField.test.ts +0 -44
  155. package/src/fields/CheckboxField.ts +0 -27
  156. package/src/fields/CheckboxListField.test.ts +0 -99
  157. package/src/fields/CheckboxListField.ts +0 -66
  158. package/src/fields/ColorPickerField.test.ts +0 -33
  159. package/src/fields/ColorPickerField.ts +0 -25
  160. package/src/fields/DateField.ts +0 -54
  161. package/src/fields/DateTimeField.test.ts +0 -55
  162. package/src/fields/EmailField.ts +0 -16
  163. package/src/fields/Field.test.ts +0 -654
  164. package/src/fields/Field.ts +0 -817
  165. package/src/fields/FileUploadField.test.ts +0 -143
  166. package/src/fields/FileUploadField.ts +0 -159
  167. package/src/fields/HiddenField.test.ts +0 -27
  168. package/src/fields/HiddenField.ts +0 -28
  169. package/src/fields/KeyValueField.test.ts +0 -105
  170. package/src/fields/KeyValueField.ts +0 -55
  171. package/src/fields/MarkdownField.test.ts +0 -167
  172. package/src/fields/MarkdownField.ts +0 -162
  173. package/src/fields/NumberField.ts +0 -33
  174. package/src/fields/RadioField.test.ts +0 -94
  175. package/src/fields/RadioField.ts +0 -67
  176. package/src/fields/RepeaterField.test.ts +0 -1806
  177. package/src/fields/RepeaterField.ts +0 -939
  178. package/src/fields/RepeaterRelationship.test.ts +0 -1923
  179. package/src/fields/RepeaterSimple.test.ts +0 -248
  180. package/src/fields/RowButton.test.ts +0 -219
  181. package/src/fields/RowButton.ts +0 -135
  182. package/src/fields/SelectField.test.ts +0 -192
  183. package/src/fields/SelectField.ts +0 -235
  184. package/src/fields/SliderField.test.ts +0 -50
  185. package/src/fields/SliderField.ts +0 -53
  186. package/src/fields/SlugField.ts +0 -24
  187. package/src/fields/TagsInputField.test.ts +0 -154
  188. package/src/fields/TagsInputField.ts +0 -133
  189. package/src/fields/TextField.test.ts +0 -213
  190. package/src/fields/TextField.ts +0 -177
  191. package/src/fields/TextareaField.test.ts +0 -58
  192. package/src/fields/TextareaField.ts +0 -59
  193. package/src/fields/ToggleButtonsField.test.ts +0 -106
  194. package/src/fields/ToggleButtonsField.ts +0 -59
  195. package/src/fields/ToggleField.ts +0 -16
  196. package/src/fields/disableOptionsWhenSelectedInSiblingRepeaterItems.test.ts +0 -319
  197. package/src/fields/optionsResolver.ts +0 -95
  198. package/src/fields/resolveField.ts +0 -28
  199. package/src/filters/BooleanFilter.ts +0 -35
  200. package/src/filters/DateRangeFilter.test.ts +0 -194
  201. package/src/filters/DateRangeFilter.ts +0 -148
  202. package/src/filters/Filter.test.ts +0 -268
  203. package/src/filters/Filter.ts +0 -184
  204. package/src/filters/FormFilter.test.ts +0 -238
  205. package/src/filters/FormFilter.ts +0 -215
  206. package/src/filters/MultiSelectFilter.test.ts +0 -119
  207. package/src/filters/MultiSelectFilter.ts +0 -78
  208. package/src/filters/QueryBuilderFilter.test.ts +0 -662
  209. package/src/filters/QueryBuilderFilter.ts +0 -398
  210. package/src/filters/SelectFilter.ts +0 -46
  211. package/src/filters/TernaryFilter.test.ts +0 -160
  212. package/src/filters/TernaryFilter.ts +0 -72
  213. package/src/filters/TrashedFilter.test.ts +0 -149
  214. package/src/filters/TrashedFilter.ts +0 -55
  215. package/src/filters/queryBuilder/BooleanConstraint.ts +0 -31
  216. package/src/filters/queryBuilder/Constraint.ts +0 -115
  217. package/src/filters/queryBuilder/DateConstraint.ts +0 -69
  218. package/src/filters/queryBuilder/NumberConstraint.ts +0 -66
  219. package/src/filters/queryBuilder/SelectConstraint.ts +0 -72
  220. package/src/filters/queryBuilder/TextConstraint.ts +0 -64
  221. package/src/filters/queryBuilder/index.ts +0 -12
  222. package/src/icons/index.ts +0 -2
  223. package/src/icons/lucide.ts +0 -204
  224. package/src/icons/registry.test.ts +0 -56
  225. package/src/icons/registry.ts +0 -41
  226. package/src/icons/types.ts +0 -47
  227. package/src/index.ts +0 -525
  228. package/src/io/csv.test.ts +0 -142
  229. package/src/io/csv.ts +0 -170
  230. package/src/nestedRelationManagerData.test.ts +0 -547
  231. package/src/notifications/Notification.test.ts +0 -210
  232. package/src/notifications/Notification.ts +0 -354
  233. package/src/notifications/broadcast.test.ts +0 -110
  234. package/src/notifications/broadcast.ts +0 -95
  235. package/src/notifications/database.test.ts +0 -383
  236. package/src/notifications/database.ts +0 -398
  237. package/src/notifications/databaseNotifications.test.ts +0 -187
  238. package/src/notifications/dispatchNotificationAction.test.ts +0 -341
  239. package/src/notifications/dispatchNotificationAction.ts +0 -142
  240. package/src/notifications/flash.test.ts +0 -89
  241. package/src/notifications/flash.ts +0 -71
  242. package/src/notifications/index.ts +0 -45
  243. package/src/notifications/registerBroadcastAuth.test.ts +0 -134
  244. package/src/notifications/registerBroadcastAuth.ts +0 -100
  245. package/src/notifications/resolveSavedNotification.test.ts +0 -82
  246. package/src/notifications/resolveSavedNotification.ts +0 -59
  247. package/src/notifications/types.ts +0 -93
  248. package/src/orm/m2mAccessor.ts +0 -66
  249. package/src/orm/modelDefaults.test.ts +0 -633
  250. package/src/orm/modelDefaults.ts +0 -666
  251. package/src/pageData/breadcrumbs.ts +0 -288
  252. package/src/pageData/forms.ts +0 -578
  253. package/src/pageData/helpers.ts +0 -857
  254. package/src/pageData/misc.ts +0 -347
  255. package/src/pageData/navigation.ts +0 -842
  256. package/src/pageData/relationPages.ts +0 -1248
  257. package/src/pageData/relationTabs.ts +0 -286
  258. package/src/pageData/resourcePages.ts +0 -609
  259. package/src/pageData.test.ts +0 -1545
  260. package/src/pageData.ts +0 -341
  261. package/src/plugins/index.ts +0 -8
  262. package/src/plugins/themeEditor.test.ts +0 -36
  263. package/src/plugins/themeEditor.ts +0 -45
  264. package/src/react/AppShell.tsx +0 -251
  265. package/src/react/CollabExtensionFactoryRegistry.ts +0 -55
  266. package/src/react/CollabRoomContext.ts +0 -98
  267. package/src/react/CollabTextRendererRegistry.ts +0 -102
  268. package/src/react/CommandPalette.tsx +0 -375
  269. package/src/react/CurrentUserContext.tsx +0 -50
  270. package/src/react/CustomPageWrapperGate.tsx +0 -69
  271. package/src/react/CustomPageWrapperRegistry.ts +0 -45
  272. package/src/react/FieldFocusReporterRegistry.ts +0 -37
  273. package/src/react/FieldLabelSlotRegistry.ts +0 -30
  274. package/src/react/FieldPresenceRegistry.ts +0 -46
  275. package/src/react/FormCollabBindingRegistry.ts +0 -242
  276. package/src/react/FormStateContext.tsx +0 -591
  277. package/src/react/HeadHooks.tsx +0 -126
  278. package/src/react/MarkdownEditorRegistry.test.ts +0 -38
  279. package/src/react/MarkdownEditorRegistry.ts +0 -107
  280. package/src/react/NotificationActionStrip.tsx +0 -263
  281. package/src/react/NotificationBell.tsx +0 -426
  282. package/src/react/PendingSuggestionApplierRegistry.test.ts +0 -97
  283. package/src/react/PendingSuggestionApplierRegistry.ts +0 -98
  284. package/src/react/PendingSuggestionOverlayRegistry.ts +0 -54
  285. package/src/react/PendingSuggestionsContext.tsx +0 -172
  286. package/src/react/RecordWrapperGate.tsx +0 -58
  287. package/src/react/RecordWrapperRegistry.ts +0 -39
  288. package/src/react/RenderHookSlot.tsx +0 -32
  289. package/src/react/RightSidebar.tsx +0 -257
  290. package/src/react/RightSidebarContext.tsx +0 -234
  291. package/src/react/RightSidebarTrigger.tsx +0 -53
  292. package/src/react/RowCoordsContext.tsx +0 -23
  293. package/src/react/SchemaRenderer.tsx +0 -549
  294. package/src/react/SearchTrigger.tsx +0 -46
  295. package/src/react/ThemeProvider.tsx +0 -93
  296. package/src/react/ThemeSettingsPage.tsx +0 -579
  297. package/src/react/ThemeToggle.tsx +0 -20
  298. package/src/react/Toaster.tsx +0 -158
  299. package/src/react/UserMenu.tsx +0 -196
  300. package/src/react/WidgetDataContext.tsx +0 -157
  301. package/src/react/cells/EditableCell.tsx +0 -389
  302. package/src/react/component-slots.test.ts +0 -103
  303. package/src/react/component-slots.ts +0 -116
  304. package/src/react/fieldJsHandler.test.ts +0 -166
  305. package/src/react/fieldJsHandler.ts +0 -79
  306. package/src/react/fields/BuilderInput.tsx +0 -1078
  307. package/src/react/fields/CheckboxInput.tsx +0 -39
  308. package/src/react/fields/CheckboxListInput.tsx +0 -102
  309. package/src/react/fields/ColorInput.tsx +0 -71
  310. package/src/react/fields/DateFieldInput.tsx +0 -70
  311. package/src/react/fields/DateTimeInput.tsx +0 -62
  312. package/src/react/fields/FieldShell.tsx +0 -348
  313. package/src/react/fields/FileUploadInput.tsx +0 -639
  314. package/src/react/fields/HiddenInput.tsx +0 -17
  315. package/src/react/fields/KeyValueInput.tsx +0 -230
  316. package/src/react/fields/MarkdownInput.tsx +0 -560
  317. package/src/react/fields/RadioInput.tsx +0 -81
  318. package/src/react/fields/RepeaterInput.test.ts +0 -116
  319. package/src/react/fields/RepeaterInput.tsx +0 -1420
  320. package/src/react/fields/SelectFieldInput.tsx +0 -280
  321. package/src/react/fields/SliderInput.tsx +0 -81
  322. package/src/react/fields/TagsInput.tsx +0 -283
  323. package/src/react/fields/TextLikeInput.tsx +0 -256
  324. package/src/react/fields/ToggleButtonsInput.tsx +0 -60
  325. package/src/react/fields/ToggleFieldInput.tsx +0 -56
  326. package/src/react/fields/relationshipRenameDispatch.test.ts +0 -106
  327. package/src/react/fields/relationshipRenameDispatch.ts +0 -97
  328. package/src/react/fields/repeaterReconcile.test.ts +0 -114
  329. package/src/react/fields/repeaterReconcile.ts +0 -104
  330. package/src/react/fields/rowChromeButton.tsx +0 -336
  331. package/src/react/fields/rowState.ts +0 -106
  332. package/src/react/fields/syncRowGates.test.ts +0 -202
  333. package/src/react/fields/syncRowGates.ts +0 -66
  334. package/src/react/fields/textInputControls.tsx +0 -238
  335. package/src/react/fields/useRowReorderDnd.ts +0 -78
  336. package/src/react/formStateHelpers.test.ts +0 -508
  337. package/src/react/formStateHelpers.ts +0 -381
  338. package/src/react/hooks/use-mobile.ts +0 -19
  339. package/src/react/icon-context.tsx +0 -60
  340. package/src/react/index.ts +0 -194
  341. package/src/react/layouts/SidebarLayout.tsx +0 -250
  342. package/src/react/layouts/TopbarLayout.tsx +0 -258
  343. package/src/react/navigate.tsx +0 -37
  344. package/src/react/onProviderSynced.test.ts +0 -90
  345. package/src/react/parseRecordEditUrl.test.ts +0 -122
  346. package/src/react/parseRecordEditUrl.ts +0 -94
  347. package/src/react/persistedState.ts +0 -40
  348. package/src/react/registry.ts +0 -48
  349. package/src/react/right-panel-registry.tsx +0 -47
  350. package/src/react/schemaRenderer/AlertRenderer.tsx +0 -112
  351. package/src/react/schemaRenderer/EntryRenderer.tsx +0 -501
  352. package/src/react/schemaRenderer/SectionRenderer.tsx +0 -120
  353. package/src/react/schemaRenderer/SimpleElements.tsx +0 -306
  354. package/src/react/schemaRenderer/TabsRenderer.tsx +0 -62
  355. package/src/react/schemaRenderer/WizardRenderer.tsx +0 -338
  356. package/src/react/schemaRenderer/action/ActionGroupTrigger.tsx +0 -177
  357. package/src/react/schemaRenderer/action/ActionModalDialog.tsx +0 -273
  358. package/src/react/schemaRenderer/action/ConfirmActionDialog.tsx +0 -61
  359. package/src/react/schemaRenderer/action/HandlerActionButton.tsx +0 -43
  360. package/src/react/schemaRenderer/action/MethodActionButton.tsx +0 -64
  361. package/src/react/schemaRenderer/action/buttons.tsx +0 -99
  362. package/src/react/schemaRenderer/action/helpers.ts +0 -140
  363. package/src/react/schemaRenderer/action/renderAction.tsx +0 -245
  364. package/src/react/schemaRenderer/columnFormat.ts +0 -65
  365. package/src/react/schemaRenderer/constants.ts +0 -50
  366. package/src/react/schemaRenderer/form/FormRenderer.tsx +0 -274
  367. package/src/react/schemaRenderer/form/renderField.tsx +0 -511
  368. package/src/react/schemaRenderer/helpers.tsx +0 -81
  369. package/src/react/schemaRenderer/table/CardsLayoutBody.tsx +0 -308
  370. package/src/react/schemaRenderer/table/TableRenderer.tsx +0 -123
  371. package/src/react/schemaRenderer/table/TableRendererBody.tsx +0 -974
  372. package/src/react/schemaRenderer/table/filters.tsx +0 -1233
  373. package/src/react/schemaRenderer/table/formatCell.tsx +0 -264
  374. package/src/react/schemaRenderer/table/links.tsx +0 -112
  375. package/src/react/schemaRenderer/table/renderRowActions.tsx +0 -52
  376. package/src/react/schemaRenderer/table/url.tsx +0 -143
  377. package/src/react/theme-preview/apply.ts +0 -99
  378. package/src/react/theme-preview/build-html.ts +0 -436
  379. package/src/react/ui/button.tsx +0 -51
  380. package/src/react/ui/calendar.tsx +0 -67
  381. package/src/react/ui/checkbox.tsx +0 -29
  382. package/src/react/ui/dialog.tsx +0 -108
  383. package/src/react/ui/dropdown-menu.tsx +0 -97
  384. package/src/react/ui/input.tsx +0 -20
  385. package/src/react/ui/label.tsx +0 -21
  386. package/src/react/ui/popover.tsx +0 -50
  387. package/src/react/ui/select.tsx +0 -169
  388. package/src/react/ui/separator.tsx +0 -25
  389. package/src/react/ui/sheet.tsx +0 -136
  390. package/src/react/ui/sidebar.tsx +0 -723
  391. package/src/react/ui/skeleton.tsx +0 -13
  392. package/src/react/ui/slider.tsx +0 -34
  393. package/src/react/ui/switch.tsx +0 -28
  394. package/src/react/ui/table.tsx +0 -105
  395. package/src/react/ui/tabs.tsx +0 -63
  396. package/src/react/ui/textarea.tsx +0 -18
  397. package/src/react/ui/tooltip.tsx +0 -64
  398. package/src/react/useResizableWidth.ts +0 -139
  399. package/src/react/utils.ts +0 -6
  400. package/src/react/widgetRegistry.test.ts +0 -43
  401. package/src/react/widgetRegistry.ts +0 -50
  402. package/src/react/widgets/StatsOverviewRenderer.tsx +0 -232
  403. package/src/react/widgets/TableWidgetRenderer.tsx +0 -231
  404. package/src/react/widgets/ViewRenderer.tsx +0 -71
  405. package/src/relationManagerData.test.ts +0 -1595
  406. package/src/richtext/index.ts +0 -8
  407. package/src/richtext/registry.ts +0 -89
  408. package/src/routes/globals.ts +0 -148
  409. package/src/routes/guard.test.ts +0 -325
  410. package/src/routes/helpers.ts +0 -704
  411. package/src/routes/pages.ts +0 -175
  412. package/src/routes/panel.ts +0 -204
  413. package/src/routes/relations.ts +0 -1243
  414. package/src/routes/resources.ts +0 -781
  415. package/src/routes/theme.ts +0 -91
  416. package/src/routes-nested-relations.test.ts +0 -676
  417. package/src/routes-relations.test.ts +0 -972
  418. package/src/routes.test.ts +0 -2027
  419. package/src/routes.ts +0 -303
  420. package/src/schema/Alert.test.ts +0 -109
  421. package/src/schema/Alert.ts +0 -131
  422. package/src/schema/Block.ts +0 -169
  423. package/src/schema/Breadcrumbs.ts +0 -40
  424. package/src/schema/Card.ts +0 -35
  425. package/src/schema/Divider.ts +0 -20
  426. package/src/schema/Element.ts +0 -219
  427. package/src/schema/EmptyState.test.ts +0 -37
  428. package/src/schema/EmptyState.ts +0 -63
  429. package/src/schema/Fieldset.ts +0 -43
  430. package/src/schema/Grid.ts +0 -43
  431. package/src/schema/Group.ts +0 -30
  432. package/src/schema/Heading.ts +0 -39
  433. package/src/schema/Html.ts +0 -67
  434. package/src/schema/Icon.ts +0 -54
  435. package/src/schema/Image.ts +0 -57
  436. package/src/schema/LinkTag.ts +0 -41
  437. package/src/schema/Markdown.ts +0 -85
  438. package/src/schema/MetaTag.ts +0 -41
  439. package/src/schema/RelationTabs.ts +0 -71
  440. package/src/schema/ScriptTag.ts +0 -55
  441. package/src/schema/Section.ts +0 -160
  442. package/src/schema/ServerDataElement.test.ts +0 -140
  443. package/src/schema/ServerDataElement.ts +0 -156
  444. package/src/schema/SlotComponent.test.ts +0 -77
  445. package/src/schema/SlotComponent.ts +0 -71
  446. package/src/schema/Split.ts +0 -50
  447. package/src/schema/Stat.test.ts +0 -118
  448. package/src/schema/Stat.ts +0 -154
  449. package/src/schema/StatsOverview.test.ts +0 -141
  450. package/src/schema/StatsOverview.ts +0 -119
  451. package/src/schema/StyleTag.ts +0 -35
  452. package/src/schema/TableWidget.test.ts +0 -297
  453. package/src/schema/TableWidget.ts +0 -289
  454. package/src/schema/Tabs.ts +0 -79
  455. package/src/schema/Text.ts +0 -58
  456. package/src/schema/UnorderedList.ts +0 -49
  457. package/src/schema/View.test.ts +0 -111
  458. package/src/schema/View.ts +0 -127
  459. package/src/schema/Wizard.ts +0 -220
  460. package/src/schema/containers.test.ts +0 -564
  461. package/src/schema/headTags.test.ts +0 -134
  462. package/src/schema/index.ts +0 -40
  463. package/src/schema/primes.test.ts +0 -269
  464. package/src/schema/resolveSchema.test.ts +0 -379
  465. package/src/schema/resolveSchema.ts +0 -917
  466. package/src/schema/sanitize.ts +0 -58
  467. package/src/search.test.ts +0 -446
  468. package/src/search.ts +0 -178
  469. package/src/sessionFilters.test.ts +0 -375
  470. package/src/sessionFilters.ts +0 -143
  471. package/src/slot-components/index.ts +0 -10
  472. package/src/slot-components/registry.ts +0 -56
  473. package/src/styles/file-upload.css +0 -13
  474. package/src/summarizers/Summarizer.test.ts +0 -84
  475. package/src/summarizers/Summarizer.ts +0 -123
  476. package/src/summarizers/index.ts +0 -11
  477. package/src/theme/base-colors.ts +0 -68
  478. package/src/theme/chart-colors.ts +0 -50
  479. package/src/theme/colors.ts +0 -447
  480. package/src/theme/generate-css.test.ts +0 -139
  481. package/src/theme/generate-css.ts +0 -44
  482. package/src/theme/generate-scale.test.ts +0 -106
  483. package/src/theme/generate-scale.ts +0 -97
  484. package/src/theme/icon-map.ts +0 -42
  485. package/src/theme/index.ts +0 -34
  486. package/src/theme/migrate.test.ts +0 -178
  487. package/src/theme/migrate.ts +0 -81
  488. package/src/theme/presets.ts +0 -135
  489. package/src/theme/radius.ts +0 -18
  490. package/src/theme/resolve.test.ts +0 -238
  491. package/src/theme/resolve.ts +0 -96
  492. package/src/theme/spacing.ts +0 -18
  493. package/src/theme/storage.test.ts +0 -126
  494. package/src/theme/storage.ts +0 -106
  495. package/src/theme/theme-colors.ts +0 -88
  496. package/src/theme/types.ts +0 -125
  497. package/src/uploads/UploadAdapter.ts +0 -35
  498. package/src/uploads/index.ts +0 -2
  499. package/src/uploads/localUpload.test.ts +0 -70
  500. package/src/uploads/localUpload.ts +0 -84
  501. package/src/validation/Validator.ts +0 -49
  502. package/src/validation/index.ts +0 -28
  503. package/src/validation/rules.ts +0 -78
  504. package/src/validation/runValidators.ts +0 -435
  505. package/src/validation/uniqueValidator.test.ts +0 -196
  506. package/src/validation/uniqueValidator.ts +0 -133
  507. package/src/validation/validators.test.ts +0 -268
  508. package/src/vite.test.ts +0 -184
  509. package/src/vite.ts +0 -787
  510. package/src/widgets/index.ts +0 -10
  511. package/src/widgets/registry.ts +0 -45
  512. package/src/widgets.test.ts +0 -592
  513. package/tsconfig.build.json +0 -11
  514. package/tsconfig.json +0 -4
  515. package/tsconfig.test.json +0 -10
  516. package/views/react/Dashboard.tsx +0 -27
  517. package/views/react/Resources/Form.tsx +0 -102
  518. 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
- })