@motifx-community/ui 0.1.0-beta.14 → 0.1.0-beta.16

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 (330) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +2 -2
  3. package/dist/components/diagram/Diagram.d.ts +607 -0
  4. package/dist/components/diagram/DiagramAutoPan.d.ts +17 -0
  5. package/dist/components/diagram/DiagramBends.d.ts +70 -0
  6. package/dist/components/diagram/DiagramDragging.d.ts +66 -0
  7. package/dist/components/diagram/DiagramEdgeView.d.ts +78 -0
  8. package/dist/components/diagram/DiagramGrid.d.ts +13 -0
  9. package/dist/components/diagram/DiagramHistory.d.ts +16 -0
  10. package/dist/components/diagram/DiagramLinks.d.ts +177 -0
  11. package/dist/components/diagram/DiagramMap.d.ts +62 -0
  12. package/dist/components/diagram/DiagramNodeView.d.ts +143 -0
  13. package/dist/components/diagram/DiagramOverview.d.ts +20 -0
  14. package/dist/components/diagram/DiagramPanning.d.ts +34 -0
  15. package/dist/components/diagram/diagram-alignment.d.ts +2 -0
  16. package/dist/components/diagram/diagram-auto-pan-host.d.ts +8 -0
  17. package/dist/components/diagram/diagram-background.d.ts +2 -0
  18. package/dist/components/diagram/diagram-bends-host.d.ts +17 -0
  19. package/dist/components/diagram/diagram-card-kind.d.ts +42 -0
  20. package/dist/components/diagram/diagram-card-node.d.ts +11 -0
  21. package/dist/components/diagram/diagram-center-options.d.ts +6 -0
  22. package/dist/components/diagram/diagram-change.d.ts +11 -0
  23. package/dist/components/diagram/diagram-class-member.d.ts +13 -0
  24. package/dist/components/diagram/diagram-class-node.d.ts +12 -0
  25. package/dist/components/diagram/diagram-column-checked-event-args.d.ts +9 -0
  26. package/dist/components/diagram/diagram-connected-event-args.d.ts +6 -0
  27. package/dist/components/diagram/diagram-connecting-event-args.d.ts +9 -0
  28. package/dist/components/diagram/diagram-connection.d.ts +7 -0
  29. package/dist/components/diagram/diagram-data.d.ts +12 -0
  30. package/dist/components/diagram/diagram-deleted-event-args.d.ts +8 -0
  31. package/dist/components/diagram/diagram-deleting-event-args.d.ts +9 -0
  32. package/dist/components/diagram/diagram-dragging-host.d.ts +47 -0
  33. package/dist/components/diagram/diagram-drawn-node.d.ts +10 -0
  34. package/dist/components/diagram/diagram-edge-end.d.ts +2 -0
  35. package/dist/components/diagram/diagram-edge-path.d.ts +5 -0
  36. package/dist/components/diagram/diagram-edge-reshaped-event-args.d.ts +8 -0
  37. package/dist/components/diagram/diagram-edge-reshaping-event-args.d.ts +6 -0
  38. package/dist/components/diagram/diagram-edge.d.ts +49 -0
  39. package/dist/components/diagram/diagram-edit.d.ts +10 -0
  40. package/dist/components/diagram/diagram-export-options.d.ts +14 -0
  41. package/dist/components/diagram/diagram-export.d.ts +28 -0
  42. package/dist/components/diagram/diagram-fit-options.d.ts +12 -0
  43. package/dist/components/diagram/diagram-history-changed-event-args.d.ts +14 -0
  44. package/dist/components/diagram/diagram-history-step.d.ts +9 -0
  45. package/dist/components/diagram/diagram-kinds.d.ts +9 -0
  46. package/dist/components/diagram/diagram-layered.d.ts +39 -0
  47. package/dist/components/diagram/diagram-layout-direction.d.ts +2 -0
  48. package/dist/components/diagram/diagram-layout-options.d.ts +24 -0
  49. package/dist/components/diagram/diagram-layout-type.d.ts +5 -0
  50. package/dist/components/diagram/diagram-layout.d.ts +33 -0
  51. package/dist/components/diagram/diagram-line-look.d.ts +6 -0
  52. package/dist/components/diagram/diagram-line.d.ts +11 -0
  53. package/dist/components/diagram/diagram-links-host.d.ts +45 -0
  54. package/dist/components/diagram/diagram-links-options.d.ts +7 -0
  55. package/dist/components/diagram/diagram-map-props.d.ts +10 -0
  56. package/dist/components/diagram/diagram-map-target.d.ts +27 -0
  57. package/dist/components/diagram/diagram-marker.d.ts +6 -0
  58. package/dist/components/diagram/diagram-mini-map-options.d.ts +13 -0
  59. package/dist/components/diagram/diagram-mini-map-position.d.ts +2 -0
  60. package/dist/components/diagram/diagram-node-context.d.ts +26 -0
  61. package/dist/components/diagram/diagram-node-host.d.ts +23 -0
  62. package/dist/components/diagram/diagram-node-kind.d.ts +43 -0
  63. package/dist/components/diagram/diagram-node-move.d.ts +11 -0
  64. package/dist/components/diagram/diagram-node-resized-event-args.d.ts +8 -0
  65. package/dist/components/diagram/diagram-node-resizing-event-args.d.ts +6 -0
  66. package/dist/components/diagram/diagram-node-size.d.ts +8 -0
  67. package/dist/components/diagram/diagram-node-status.d.ts +2 -0
  68. package/dist/components/diagram/diagram-node-toggled-event-args.d.ts +7 -0
  69. package/dist/components/diagram/diagram-node.d.ts +56 -0
  70. package/dist/components/diagram/diagram-nodes-moved-event-args.d.ts +6 -0
  71. package/dist/components/diagram/diagram-nodes-moving-event-args.d.ts +6 -0
  72. package/dist/components/diagram/diagram-panning-host.d.ts +19 -0
  73. package/dist/components/diagram/diagram-pasted-event-args.d.ts +7 -0
  74. package/dist/components/diagram/diagram-pasting-event-args.d.ts +11 -0
  75. package/dist/components/diagram/diagram-path-ends.d.ts +11 -0
  76. package/dist/components/diagram/diagram-path-result.d.ts +6 -0
  77. package/dist/components/diagram/diagram-paths.d.ts +35 -0
  78. package/dist/components/diagram/diagram-point.d.ts +5 -0
  79. package/dist/components/diagram/diagram-port-place.d.ts +9 -0
  80. package/dist/components/diagram/diagram-port.d.ts +27 -0
  81. package/dist/components/diagram/diagram-props.d.ts +159 -0
  82. package/dist/components/diagram/diagram-reconnected-event-args.d.ts +10 -0
  83. package/dist/components/diagram/diagram-reconnecting-event-args.d.ts +11 -0
  84. package/dist/components/diagram/diagram-rect.d.ts +7 -0
  85. package/dist/components/diagram/diagram-resize-side.d.ts +2 -0
  86. package/dist/components/diagram/diagram-route.d.ts +10 -0
  87. package/dist/components/diagram/diagram-selection-changed-event-args.d.ts +9 -0
  88. package/dist/components/diagram/diagram-selection.d.ts +5 -0
  89. package/dist/components/diagram/diagram-side.d.ts +2 -0
  90. package/dist/components/diagram/diagram-table-column.d.ts +13 -0
  91. package/dist/components/diagram/diagram-table-node.d.ts +12 -0
  92. package/dist/components/diagram/diagram-tree.d.ts +14 -0
  93. package/dist/components/diagram/diagram-viewport-changed-event-args.d.ts +8 -0
  94. package/dist/components/diagram/diagram-viewport-options.d.ts +5 -0
  95. package/dist/components/diagram/diagram-viewport.d.ts +6 -0
  96. package/dist/components/diagram/index.d.ts +65 -0
  97. package/dist/components/diagram/swallow-next-click.d.ts +5 -0
  98. package/dist/components/expressioneditor/ExpressionEditor.d.ts +111 -0
  99. package/dist/components/expressioneditor/expression-editor-props.d.ts +24 -0
  100. package/dist/components/expressioneditor/index.d.ts +2 -0
  101. package/dist/components/formlayout/FormLayout.d.ts +10 -3
  102. package/dist/components/formlayout/form-editor-type.d.ts +1 -1
  103. package/dist/components/formlayout/form-item.d.ts +4 -1
  104. package/dist/components/formlayout/form-layout-props.d.ts +1 -1
  105. package/dist/components/formlayout/index.d.ts +1 -0
  106. package/dist/components/formlayout/schema-items.d.ts +26 -0
  107. package/dist/components/pivotgrid/model/PivotAxisWindow.d.ts +53 -1
  108. package/dist/components/pivotgrid/model/PivotCellWindow.d.ts +2 -0
  109. package/dist/components/pivotgrid/model/PivotWindows.d.ts +3 -6
  110. package/dist/components/toolbar/Toolbar.d.ts +5 -3
  111. package/dist/core/control.d.ts +2 -0
  112. package/dist/core/keyboard.d.ts +5 -0
  113. package/dist/core/measure/index.d.ts +2 -0
  114. package/dist/core/measure/picture.d.ts +27 -0
  115. package/dist/core/shortcut-options.d.ts +5 -2
  116. package/dist/core/ui-strings.d.ts +191 -0
  117. package/dist/generated/tokens.d.ts +1615 -0
  118. package/dist/index.d.ts +2 -0
  119. package/dist/index.js +11501 -705
  120. package/dist/index.js.map +1 -1
  121. package/dist/locales/en.json +180 -1
  122. package/dist/locales/tr.json +180 -1
  123. package/dist/styles.css +2262 -3
  124. package/dist/tokens/index.d.ts +1615 -0
  125. package/dist/tokens/index.js +1615 -0
  126. package/dist/tokens/index.js.map +1 -1
  127. package/dist/{tr-BGbF9uCs.js → tr-4GNbFdQh.js} +361 -3
  128. package/dist/{tr-BGbF9uCs.js.map → tr-4GNbFdQh.js.map} +1 -1
  129. package/docs/accordion.md +1 -1
  130. package/docs/actionsheet.md +1 -1
  131. package/docs/appbar.md +1 -1
  132. package/docs/appmenu-api.md +1 -1
  133. package/docs/appmenu-programmatic.md +1 -1
  134. package/docs/appmenu-search.md +1 -1
  135. package/docs/appmenu.md +1 -1
  136. package/docs/avatar.md +1 -1
  137. package/docs/badge.md +1 -1
  138. package/docs/bar-gauge-angles.md +1 -1
  139. package/docs/bar-gauge-data.md +1 -1
  140. package/docs/bar-gauge-labels.md +1 -1
  141. package/docs/bar-gauge.md +1 -1
  142. package/docs/barcode.md +1 -1
  143. package/docs/bottomnavigation.md +1 -1
  144. package/docs/bottomsheet.md +1 -1
  145. package/docs/breadcrumb.md +1 -1
  146. package/docs/button.md +1 -1
  147. package/docs/buttongroup.md +1 -1
  148. package/docs/buttons.md +1 -1
  149. package/docs/calendar.md +1 -1
  150. package/docs/card.md +1 -1
  151. package/docs/chart-bars.md +1 -1
  152. package/docs/chart-candles.md +1 -1
  153. package/docs/chart-funnel.md +1 -1
  154. package/docs/chart-heatmap.md +1 -1
  155. package/docs/chart-lines.md +1 -1
  156. package/docs/chart-live.md +1 -1
  157. package/docs/chart-pie.md +1 -1
  158. package/docs/chart-radar.md +1 -1
  159. package/docs/chart-ranges.md +1 -1
  160. package/docs/chart-references.md +1 -1
  161. package/docs/chart-scatter.md +1 -1
  162. package/docs/chart-waterfall.md +1 -1
  163. package/docs/chart-zoom.md +1 -1
  164. package/docs/chart.md +1 -1
  165. package/docs/chat.md +1 -1
  166. package/docs/checkbox.md +1 -1
  167. package/docs/chip.md +1 -1
  168. package/docs/choice.md +1 -1
  169. package/docs/colorbox.md +1 -1
  170. package/docs/combobox.md +1 -1
  171. package/docs/commands.md +1 -1
  172. package/docs/control.md +1 -1
  173. package/docs/data.md +2 -2
  174. package/docs/datagrid-api.md +1 -1
  175. package/docs/datagrid-bands.md +1 -1
  176. package/docs/datagrid-drag-select.md +1 -1
  177. package/docs/datagrid-drag.md +1 -1
  178. package/docs/datagrid-editing.md +1 -1
  179. package/docs/datagrid-filtering.md +1 -1
  180. package/docs/datagrid-forms.md +1 -1
  181. package/docs/datagrid-grouping.md +1 -1
  182. package/docs/datagrid-layout.md +1 -1
  183. package/docs/datagrid-lookups.md +1 -1
  184. package/docs/datagrid-master-detail.md +1 -1
  185. package/docs/datagrid-scrolling.md +1 -1
  186. package/docs/datagrid-selection.md +1 -1
  187. package/docs/datagrid.md +1 -1
  188. package/docs/datalayer-api.md +491 -0
  189. package/docs/datalayer-changes.md +501 -0
  190. package/docs/datalayer-odata.md +998 -0
  191. package/docs/datalayer-pivot.md +850 -0
  192. package/docs/datalayer-queries.md +516 -0
  193. package/docs/datalayer-rest.md +529 -0
  194. package/docs/datalayer-soap.md +576 -0
  195. package/docs/datalayer-source.md +464 -0
  196. package/docs/datalayer.md +264 -0
  197. package/docs/datebox.md +1 -1
  198. package/docs/daterangebox.md +1 -1
  199. package/docs/diagram-api.md +200 -0
  200. package/docs/diagram-commands.md +79 -0
  201. package/docs/diagram-connections.md +157 -0
  202. package/docs/diagram-custom-nodes.md +325 -0
  203. package/docs/diagram-designer.md +816 -0
  204. package/docs/diagram-editing.md +62 -0
  205. package/docs/diagram-flow.md +157 -0
  206. package/docs/diagram-keyboard.md +58 -0
  207. package/docs/diagram-layout.md +354 -0
  208. package/docs/diagram-nodes.md +206 -0
  209. package/docs/diagram-tables.md +212 -0
  210. package/docs/diagram.md +217 -0
  211. package/docs/display.md +1 -1
  212. package/docs/draggable.md +1 -1
  213. package/docs/drawer.md +1 -1
  214. package/docs/dropdown.md +1 -1
  215. package/docs/editors.md +1 -1
  216. package/docs/expressioneditor.md +469 -0
  217. package/docs/expressions.md +431 -0
  218. package/docs/feedback.md +1 -1
  219. package/docs/fileuploader.md +1 -1
  220. package/docs/filterbuilder.md +1 -1
  221. package/docs/formlayout-schema.md +143 -0
  222. package/docs/formlayout.md +16 -4
  223. package/docs/foundations.md +1 -1
  224. package/docs/gallery.md +1 -1
  225. package/docs/gauge-base.md +1 -1
  226. package/docs/gauge-circular.md +1 -1
  227. package/docs/gauge-dashboards.md +1 -1
  228. package/docs/gauge-linear.md +1 -1
  229. package/docs/gauge-markers.md +1 -1
  230. package/docs/gauge-marks.md +1 -1
  231. package/docs/gauge-ranges.md +1 -1
  232. package/docs/gauge-scales.md +1 -1
  233. package/docs/gauge.md +1 -1
  234. package/docs/home.md +1 -1
  235. package/docs/keyboard.md +2 -2
  236. package/docs/language.md +1 -1
  237. package/docs/layout.md +1 -1
  238. package/docs/listbox.md +1 -1
  239. package/docs/loadpanel.md +1 -1
  240. package/docs/lookup.md +1 -1
  241. package/docs/markdown.md +1 -1
  242. package/docs/menus-api.md +1 -1
  243. package/docs/menus-context.md +1 -1
  244. package/docs/menus-customization.md +1 -1
  245. package/docs/menus-merging.md +1 -1
  246. package/docs/menus-programmatic.md +1 -1
  247. package/docs/menus.md +1 -1
  248. package/docs/multiview.md +1 -1
  249. package/docs/navigation.md +1 -1
  250. package/docs/numberbox.md +1 -1
  251. package/docs/otpinput.md +1 -1
  252. package/docs/pagination.md +1 -1
  253. package/docs/pivotgrid-api.md +1 -1
  254. package/docs/pivotgrid-chart.md +1 -1
  255. package/docs/pivotgrid-drilldown.md +1 -1
  256. package/docs/pivotgrid-export.md +1 -1
  257. package/docs/pivotgrid-fields.md +1 -1
  258. package/docs/pivotgrid-keyboard.md +1 -1
  259. package/docs/pivotgrid-layout.md +1 -1
  260. package/docs/pivotgrid-panel.md +1 -1
  261. package/docs/pivotgrid-remote.md +122 -44
  262. package/docs/pivotgrid-sorting.md +3 -3
  263. package/docs/pivotgrid-state.md +1 -1
  264. package/docs/pivotgrid-summaries.md +1 -1
  265. package/docs/pivotgrid.md +1 -1
  266. package/docs/popover.md +1 -1
  267. package/docs/progress.md +1 -1
  268. package/docs/qrcode.md +1 -1
  269. package/docs/radiogroup.md +1 -1
  270. package/docs/rating.md +1 -1
  271. package/docs/resizable.md +1 -1
  272. package/docs/ribbonmenu-api.md +1 -1
  273. package/docs/ribbonmenu-commands.md +1 -1
  274. package/docs/ribbonmenu-customization.md +1 -1
  275. package/docs/ribbonmenu-display.md +1 -1
  276. package/docs/ribbonmenu-layouts.md +1 -1
  277. package/docs/ribbonmenu-programmatic.md +1 -1
  278. package/docs/ribbonmenu.md +1 -1
  279. package/docs/scheduler-agenda.md +1 -1
  280. package/docs/scheduler-big-data.md +1 -1
  281. package/docs/scheduler-editing.md +1 -1
  282. package/docs/scheduler-form.md +1 -1
  283. package/docs/scheduler-icalendar.md +1 -1
  284. package/docs/scheduler-mobile.md +1 -1
  285. package/docs/scheduler-recurrence.md +1 -1
  286. package/docs/scheduler-resources.md +1 -1
  287. package/docs/scheduler-timeline.md +1 -1
  288. package/docs/scheduler.md +1 -1
  289. package/docs/scrollview.md +1 -1
  290. package/docs/shortcuteditor.md +1 -1
  291. package/docs/showcase-flowstudio.md +61 -0
  292. package/docs/showcase-home.md +1 -1
  293. package/docs/showcase-mail.md +1 -1
  294. package/docs/showcase.md +1 -1
  295. package/docs/signature.md +1 -1
  296. package/docs/skeleton.md +1 -1
  297. package/docs/slider.md +1 -1
  298. package/docs/sortable.md +1 -1
  299. package/docs/sparkline.md +1 -1
  300. package/docs/speeddial.md +1 -1
  301. package/docs/splitter.md +1 -1
  302. package/docs/stepper.md +1 -1
  303. package/docs/switch.md +1 -1
  304. package/docs/tabdocs-dock.md +1 -1
  305. package/docs/tabdocs-drag.md +1 -1
  306. package/docs/tabdocs-menus.md +1 -1
  307. package/docs/tabdocs-mobile.md +1 -1
  308. package/docs/tabdocs-tabs.md +1 -1
  309. package/docs/tabdocs-windows.md +1 -1
  310. package/docs/tabdocs-workspace.md +1 -1
  311. package/docs/tabdocs.md +1 -1
  312. package/docs/tabs.md +1 -1
  313. package/docs/tagbox.md +1 -1
  314. package/docs/textarea.md +1 -1
  315. package/docs/textbox.md +1 -1
  316. package/docs/tileview.md +1 -1
  317. package/docs/timeline.md +1 -1
  318. package/docs/toast.md +1 -1
  319. package/docs/tokens.md +324 -1
  320. package/docs/toolbar-api.md +1 -1
  321. package/docs/toolbar-customization.md +1 -1
  322. package/docs/toolbar.md +1 -1
  323. package/docs/tooltip.md +1 -1
  324. package/docs/treeview.md +1 -1
  325. package/docs/validationsummary.md +1 -1
  326. package/docs/window.md +1 -1
  327. package/docs/wizard.md +1 -1
  328. package/llms-full.txt +10142 -462
  329. package/llms.txt +32 -1
  330. package/package.json +2 -2
@@ -0,0 +1,464 @@
1
+ # Data layer: DataSource
2
+
3
+ > Data layer · @motifx-community/data 0.1.0-beta.3
4
+
5
+ A `DataSource` provides the rows a component shows, loaded through any adapter of the [data layer](datalayer.md), and keeps the query that chose them: the filter, the sort order, the search, the groups and the summaries.
6
+
7
+ ## The rows a component shows
8
+
9
+ A data source stands between a component and an adapter: it loads rows in one of three [load modes](#modes), holds them next to the query that chose them, applies the changes the adapter reports to them ([Finding rows](#keys)), and reports every change of its own through `onChanged`. The kit's data-bound components, [`DataGrid`](datagrid.md), [`ListBox`](listbox.md), `ComboBox`, `DropDown`, [`Lookup`](lookup.md), `TagBox`, `Chart`, `Scheduler` and [`PivotGrid`](pivotgrid.md), take one as `dataSource` and drive it themselves; a source handed over idle is loaded when it is first shown.
10
+
11
+ ```tsx
12
+ import { data } from '@motifx-community/data';
13
+
14
+ const customers = new data.DataSource({
15
+ adapter: new data.RestAdapter({ url: '/api/customers', key: 'id' }),
16
+ loadMode: 'page',
17
+ pageSize: 20,
18
+ sort: [{ field: 'name', dir: 'asc' }],
19
+ searchFields: ['name', 'city'],
20
+ });
21
+ await customers.load();
22
+ ```
23
+
24
+ `load()` loads the rows of the current query; until the first load the source is `'idle'`. Editing over a source, unsaved rows, validation and save modes, is the `ChangeTracker`'s work: see [Tracking and saving changes](datalayer-changes.md).
25
+
26
+ ## Load modes
27
+
28
+ `loadMode` specifies how the rows come and how they are read.
29
+
30
+ | Mode | Rows loaded | Read with |
31
+ | --- | --- | --- |
32
+ | `'all'` | Every matching row at once: a small list, rows in memory. | `rows`, `rowAt(i)`, `total` |
33
+ | `'page'` | One page of `pageSize` rows at a time. The default. | `rows` holds the loaded page, `rowAt(i)` reads it at whole-result indexes, `loadedPageIndex` names it; `total` |
34
+ | `'blocks'` | Blocks of `pageSize` rows where the view is, for a virtual list. | `rowAt(i)` and `forEachLoaded`; `rows` stays empty; `total` |
35
+
36
+ ## Paging
37
+
38
+ `setPage(index)` goes to a page, counted from 0, and loads it; the index is clamped to the page count once the total is known. `pageIndex` is the page requested and `loadedPageIndex` the page whose rows `rows` holds, -1 before the first arrives. While the requested page loads, `rows` keeps the loaded page and `rowAt` reads its rows at their own indexes in the whole result, so a view keeps showing what it has until the new rows arrive.
39
+
40
+ `pageCount` is the number of pages, `undefined` while the total is unknown, and `isLastPage` indicates whether the requested page is the last. By default every page asks for the total (`count`); with `count: false` the total stays unknown until a page comes back shorter than `pageSize`, which tells where the rows end. `setPageSize(size)` changes the page size and loads the first page; 0 makes one page with every row. In `'all'` the size is only kept for a view that pages the loaded rows itself, and a block size is fixed.
41
+
42
+ ```tsx
43
+ import { data } from '@motifx-community/data';
44
+
45
+ /** Rows in memory that answer a little later, the way a server does; for the examples. */
46
+ export class SlowAdapter<T extends object, K> extends data.ArrayAdapter<T, K> {
47
+ constructor(
48
+ options: data.ArrayAdapterOptions<T>,
49
+ private readonly delayMs = 300,
50
+ ) {
51
+ super(options);
52
+ }
53
+
54
+ override async load(options: data.LoadOptions = {}): Promise<data.LoadResult<T>> {
55
+ await new Promise((done) => setTimeout(done, this.delayMs));
56
+ return super.load(options);
57
+ }
58
+ }
59
+ ```
60
+
61
+ The customers above live in an adapter that answers 300 ms later, the way a server does; the service runs in the page. The search and every page turn send one request. Turning a page while one loads keeps the shown rows, and the line over the table tells the requested and the shown page apart. The search belongs to [the query](#query): it starts again from the first page.
62
+
63
+ ## Virtual lists
64
+
65
+ In `'blocks'` the view tells the source what it shows: `ensure(first, end)` declares the rows `first` to `end - 1` visible, and the blocks they fall in load unless they are in memory already. `ensureRanges` declares several runs of rows at once, for a list with collapsed parts. The kit's components in blocks mode call these themselves as they scroll; `rowAt(index)` returns the row once its block arrived and `undefined` before.
66
+
67
+ A move of more rows than `jumpRows` is a jump, a scroll bar drag rather than a step: the source waits `scrollStopMs` without movement before loading, and every further move restarts the wait, so a drag loads only where it stops and the rows passed over are never requested. A block still loading that falls further than `nearBlocks` from the view is aborted. At most `cacheBlocks` blocks stay in memory, the ones used longest ago dropped first; `pin(index)` keeps the block of `index`, the focused row, in memory until `pin(-1)` lets it go. `ensure` with `immediate` skips the wait, for a jump made in code.
68
+
69
+ The total comes with the first block of a query; with `count: false` a block shorter than the block size tells where the rows end instead. Grouping is not available in `'blocks'` (`MJD302`).
70
+
71
+ | Option | Default | Description |
72
+ | --- | --- | --- |
73
+ | `pageSize` | `50` | Rows of a block. |
74
+ | `cacheBlocks` | `40` | Blocks kept in memory, at least 4; the ones used longest ago are dropped first. |
75
+ | `scrollStopMs` | `120` | After a jump, the wait in milliseconds without movement before loading. |
76
+ | `jumpRows` | `pageSize` | A move of more rows than this is a jump, which waits for `scrollStopMs`. |
77
+ | `nearBlocks` | `1` | Blocks this many away from the view keep loading when it moves, and stay in the cache. |
78
+ | `count` | `true` | Asks the first block of a query for the total. Off, a block shorter than the block size tells where the rows end, for a backend that cannot count. |
79
+
80
+ ```tsx
81
+ import { data } from '@motifx-community/data';
82
+
83
+ /** Rows in memory that answer a little later, the way a server does; for the examples. */
84
+ export class SlowAdapter<T extends object, K> extends data.ArrayAdapter<T, K> {
85
+ constructor(
86
+ options: data.ArrayAdapterOptions<T>,
87
+ private readonly delayMs = 300,
88
+ ) {
89
+ super(options);
90
+ }
91
+
92
+ override async load(options: data.LoadOptions = {}): Promise<data.LoadResult<T>> {
93
+ await new Promise((done) => setTimeout(done, this.delayMs));
94
+ return super.load(options);
95
+ }
96
+ }
97
+ ```
98
+
99
+ The list above reads 100,000 rows in blocks of 100 through an adapter that answers 200 ms later, in the page. The first block brings the total, which gives the list its length; scrolling loads the blocks the view reaches, and dragging the scroll bar across thousands of rows requests only where it stops. The counter under the list shows both sides: the blocks requested so far, and the blocks in memory, which stays at `cacheBlocks` however far the list scrolls.
100
+
101
+ ## The query
102
+
103
+ The query is the filter, the sort order, the search text, the grouping levels and `params`. `setFilter`, `setSort`, `setGroup`, `search` and `setParams` change one part; `setQuery` changes several at once and loads once. Every one of them starts again from the first row: the page returns to 0 and a view's blocks are dropped. `reload()` loads the current query again and keeps the page or the view. Only the answer of the last query counts: a load still on its way when the query changes again is aborted.
104
+
105
+ ```tsx
106
+ await source.setQuery({
107
+ filter: data.where('city', '=', 'Ankara'),
108
+ sort: [{ field: 'name', dir: 'asc' }],
109
+ });
110
+ await source.search('an');
111
+ await source.reload();
112
+ ```
113
+
114
+ Filters are plain data, built with `data.where`, `data.and`, `data.or` and `data.not`: see [Filtering, sorting and grouping](datalayer-queries.md). `search(text)` keeps the rows where one of `searchFields` holds the text, compared with `searchOperator` (`'contains'` by default); the search is joined to the filter, an empty text keeps every row, and a search without the `searchFields` option throws `MJD302`. `params` are handed to the adapter with every load, as they are; an HTTP adapter sends them with each request.
115
+
116
+ ## Groups and summaries
117
+
118
+ `group` names the grouping levels, in `'all'` and `'page'`: `groups` holds the groups of every row or of the page, with their keys, counts and `groupSummary` values in every level, `rows` every row of them in group order, and `groupCount` the number of top-level groups. A page holds top-level groups, so `pageCount` and `setPage` count groups rather than rows. `setGroup(levels)` changes the grouping.
119
+
120
+ `summary` asks for values over every matching row, whatever page is shown; the `summary` property holds them in the order of the items. In `'all'` they come with the rows and follow every change of them; in `'page'` and `'blocks'` they load apart, once per query, so turning pages does not ask for them again, and arrive with the `summary` change.
121
+
122
+ For values other than the source's own, `loadGroups(group, { groupSummary })` resolves to the groups of the current query without rows, and `loadSummary(items)` to summary values over every matching row; neither touches the rows the source holds, and both reject when their load fails. `loadPivot` computes a pivot over the current query, and `loadPivotMembers`, `loadPivotCounts`, `loadPivotBlocks` and `loadPivotCells` load its parts: see [Pivots and loading in parts](datalayer-pivot.md).
123
+
124
+ ## When the adapter cannot do the query
125
+
126
+ An adapter names what its backend does itself in its [capabilities](datalayer-api.md); what the backend cannot do runs in memory on the rows it returns. When the backend of a `'page'` query cannot filter, sort, group or summarize the way the query asks, every page would need all matching rows. The source therefore loads them once per row set, that is, per combination of filter, search and `params`, and keeps them. Sorting, grouping, summaries and every page are then computed from the kept rows, so turning pages, sorting and grouping send no request until the row set changes or `reload()` discards the kept rows. An ungrouped first page loads separately, so that it does not wait for every row, and changes [saved or pushed](#keys) through the adapter are applied to the kept rows.
127
+
128
+ ## Status and errors
129
+
130
+ `status` is `'idle'` until the first load, then `'loading'`, `'ready'` or `'error'`. `load`, `reload`, `retry`, `setPage` and the query methods never reject: a failure sets `status` to `'error'` and `error` to a `DataError` with a stable code ([custom adapters and API](datalayer-api.md)), and reports `failed`. `retry()` loads what failed again, and the next successful load clears `error`. The loads that resolve to a result of their own, `loadRange`, `loadGroups`, `loadSummary` and the pivot loads, reject instead: their failures belong to the caller.
131
+
132
+ While a new query loads in `'all'`, the rows of the query before stay in `rows` until the new ones arrive; `keepRowsWhileLoading: false` drops them at once. In `'page'` and `'blocks'` a new query drops the rows at once (`cleared`). A query whose load fails does not keep the old rows next to its error. In `'blocks'`, a failure before the first block of a query answers is the source's: `status` becomes `'error'`. A block that fails after it leaves the source `'ready'`: the block counts in `failedBlocks`, `isFailed(index)` answers for its rows, and `retry()` loads the failed blocks again.
133
+
134
+ `onChanged` reports every change with its reason:
135
+
136
+ | Reason | Occurs when |
137
+ | --- | --- |
138
+ | `query` | A new query started: the filter, the sort order, the search text, the grouping or `params` changed. |
139
+ | `reload` | `reload()` started. |
140
+ | `loading` | A load started. |
141
+ | `loaded` | Rows arrived. |
142
+ | `failed` | A load failed; `error` holds the reason. |
143
+ | `cleared` | The rows were dropped for a new query or another page size. |
144
+ | `rows` | Loaded rows changed, or rows came or went; `rows` holds the ones whose values changed. |
145
+ | `summary` | The summary values arrived (`'page'` and `'blocks'`). |
146
+
147
+ ```tsx
148
+ import { reactive } from '@motifx/core';
149
+ import { data } from '@motifx-community/data';
150
+ import { Button, Stack } from '@motifx-community/ui';
151
+
152
+ interface Task {
153
+ id: number;
154
+ name: string;
155
+ }
156
+
157
+ /** Rows in memory whose next load can be made to fail, the way an unreachable service does. */
158
+ class FailingAdapter extends data.ArrayAdapter<Task, number> {
159
+ failNext = false;
160
+
161
+ override async load(options: data.LoadOptions = {}): Promise<data.LoadResult<Task>> {
162
+ await new Promise((done) => setTimeout(done, 300));
163
+ if (this.failNext) {
164
+ this.failNext = false;
165
+ throw new Error('The service did not answer');
166
+ }
167
+ return super.load(options);
168
+ }
169
+ }
170
+
171
+ /** A load that fails: the status, the error it leaves, and a retry. */
172
+ export default function Errors() {
173
+ const tasks: Task[] = Array.from({ length: 5 }, (_, i) => ({ id: i + 1, name: `Scheduled task ${i + 1}` }));
174
+ const service = new FailingAdapter({ data: tasks, key: 'id' });
175
+ const source = new data.DataSource<Task, number>({ adapter: service, loadMode: 'all' });
176
+ const s = reactive({ status: source.status, error: '', rows: [] as Task[] });
177
+ source.onChanged(() => {
178
+ s.status = source.status;
179
+ s.error = source.error?.message ?? '';
180
+ s.rows = [...source.rows];
181
+ });
182
+ void source.load();
183
+
184
+ const fail = () => {
185
+ service.failNext = true;
186
+ void source.reload();
187
+ };
188
+
189
+ return (
190
+ <Stack gap="sm">
191
+ <Stack orientation="horizontal" wrap align="center">
192
+ <Button text="Fail the next load" variant="outline" onclick={fail} />
193
+ <Button text="Retry" enabled={() => s.status === 'error'} onclick={() => void source.retry()} />
194
+ </Stack>
195
+ <output class="dls-errors-status" aria-live="polite">
196
+ {() => (s.status === 'error' ? s.error : `${s.status} · ${s.rows.length} tasks`)}
197
+ </output>
198
+ <ul class="dls-errors-rows">
199
+ {s.rows.map((t) => (
200
+ <li key={t.id}>{t.name}</li>
201
+ ))}
202
+ </ul>
203
+ </Stack>
204
+ );
205
+ }
206
+ ```
207
+
208
+ The first button makes the adapter fail its next load and reloads: the source reports `failed`, `status` becomes `'error'`, and `error` holds a `DataError` whose message names the cause. The rows of the failed reload stay: they belong to the same query. Retry loads the query again and clears the error.
209
+
210
+ ## Finding rows
211
+
212
+ `byKey(key)` resolves to the row with a key: it looks among the loaded rows and the rows found before, and only then asks the adapter, keeping what it finds for later lookups. A [lookup](lookup.md) shows its value this way when the row is on no loaded page. `rowByKey(key)` answers from the loaded and found rows alone, without a request, `indexOfKey(key)` gives a loaded row's index in the whole result or -1, and `forEachLoaded` walks every loaded row with its index.
213
+
214
+ Changes saved through the adapter (`insert`, `update`, `remove`, `save`), or announced to it with `push`, reach the loaded rows. An update goes into the loaded row object in place, in every mode. A new or removed row takes or leaves its place in `'all'`, in the query's order, and changes the total in `'page'`; in `'blocks'` the blocks load again, since a row coming or going moves every later row. A grouped or summarized source follows: `'all'` regroups the loaded rows in memory, `'page'` loads again. An adapter without a key cannot match rows, so the source reloads instead. When an adapter's rows are replaced as a whole ([setData](#data)), every source over it loads again from the first page and the rows found by key are dropped.
215
+
216
+ ## Reading everything
217
+
218
+ `loadRange({ skip, take, filter, sort, count, signal })` loads rows of the current query, its filter, search, sort order and `params`, from `skip`, without groups and without touching the rows the source holds: for an export or a print that goes through every page. `filter` narrows the query's own (joined with AND), `sort` reads these rows in another order, and `count` asks for the total too. Unlike `load()`, it rejects when the load fails.
219
+
220
+ ```tsx
221
+ for (let skip = 0; ; skip += 1000) {
222
+ const part = await source.loadRange({ skip, take: 1000 });
223
+ write(part.rows);
224
+ if (part.rows.length < 1000) break;
225
+ }
226
+ ```
227
+
228
+ ## Replacing and narrowing
229
+
230
+ `setData(rows)` replaces the rows of an `ArrayAdapter`: an array, or a function read on every operation. Every source over that adapter loads the new rows again from the first page, and the returned promise resolves once this source has. The rows of any other adapter are its backend's, and `setData` throws `MJD302`.
231
+
232
+ `narrow(filter, options)` returns a new data source over the same adapter, for the rows of the current query that `filter` keeps too: the current filter and search become the new source's filter, and its `params`, `select` and `expand` carry over. `options` set the rest, such as `loadMode`, `pageSize` and `sort`. A drill-down that shows the rows behind one cell or group is built this way.
233
+
234
+ ## API reference
235
+
236
+ Everything below is exported under the `data` namespace: `new data.DataSource(options)`. `LoadMode` is `'all' | 'page' | 'blocks'`, and `DataSourceStatus` is `'idle' | 'loading' | 'ready' | 'error'`. `DataSourceQuery` holds the parts `setQuery` takes (`filter`, `sort`, `group`, `searchText`, `params`), and `LoadRangeOptions` the options of `loadRange`. Every change `onChanged` reports is a `DataSourceChange`: its `reason` is listed under [Status and errors](#status), and with the `rows` reason it carries the changed rows.
237
+
238
+ ### Options of DataSourceOptions
239
+
240
+ | Option | Default | Description |
241
+ | --- | --- | --- |
242
+ | `adapter` | — | The adapter the rows load through: [REST](datalayer-rest.md), [OData](datalayer-odata.md), [SOAP](datalayer-soap.md), rows in memory (`ArrayAdapter`), or [one of your own](datalayer-api.md). Required. |
243
+ | `loadMode` | `'page'` | How the rows load: `'all'`, `'page'` or `'blocks'`. See [Load modes](#modes). |
244
+ | `pageSize` | `20` (`'blocks'`: `50`) | Rows of a page or of a block. 0 is one page with every row (`'page'`). |
245
+ | `filter` | — | The initial filter, [as data](datalayer-queries.md). |
246
+ | `sort` | — | The initial sort order: `{ field, dir }` items. |
247
+ | `group` | — | Grouping levels (`'all'` and `'page'`): `{ field, dir? }` items. See [Groups and summaries](#groups). |
248
+ | `groupSummary` | — | Summary values of each group: `{ type, field? }` items. |
249
+ | `summary` | — | Summary values over every matching row. In `'page'` and `'blocks'` they load apart, once per query. |
250
+ | `searchFields` | — | The fields `search(text)` looks in. |
251
+ | `searchOperator` | `'contains'` | How `search` compares: `'contains'`, `'startswith'`, `'endswith'` or `'='`. |
252
+ | `select` | — | The fields to load, where the adapter supports a selection. |
253
+ | `expand` | — | Related data to include, where the adapter supports it (OData `$expand`). |
254
+ | `params` | — | Values handed to the adapter with every load, as they are; an HTTP adapter sends them with each request. |
255
+ | `keepRowsWhileLoading` | `true` | `'all'`: a new query keeps the old rows in `rows` until the new ones arrive. With `false` they are dropped at once (`cleared`). |
256
+ | `count` | `true` | Asks for the total row count: with each page (`'page'`), with the first block of a query (`'blocks'`). Off, a page or block shorter than its size tells where the rows end, for a backend that cannot count. |
257
+ | `cacheBlocks` | `40` | `'blocks'`: blocks kept in memory, at least 4; the ones used longest ago are dropped first. |
258
+ | `scrollStopMs` | `120` | `'blocks'`: after a jump, the wait in milliseconds without movement before loading. |
259
+ | `jumpRows` | `pageSize` | `'blocks'`: a move of more rows than this is a jump, which waits for `scrollStopMs`. |
260
+ | `nearBlocks` | `1` | `'blocks'`: blocks this many away from the view keep loading when it moves, and stay in the cache. |
261
+
262
+ ### Properties of DataSource
263
+
264
+ | Property | Description |
265
+ | --- | --- |
266
+ | `adapter` | The adapter the source loads through. |
267
+ | `loadMode` | The load mode the source was created with. |
268
+ | `status` | `'idle'` until the first load, then `'loading'`, `'ready'` or `'error'`. |
269
+ | `error` | The `DataError` of the last failed load, or `null`. |
270
+ | `rows` | `'all'`: every row; `'page'`: the rows of the loaded page, in group order with `group`. Empty in `'blocks'`. |
271
+ | `total` | The number of rows matching the query; `undefined` until it is known. |
272
+ | `pageIndex` | `'page'`: the page requested, counted from 0. |
273
+ | `loadedPageIndex` | `'page'`: the page whose rows `rows` holds, or -1 before one arrives. |
274
+ | `pageCount` | The number of pages; `undefined` while the total is unknown. Grouped pages count top-level groups. |
275
+ | `isLastPage` | Indicates whether the requested page is the last. |
276
+ | `pageSize` | Rows of a page or of a block; 0 is one page with every row. |
277
+ | `filter, sort, group, searchText, params` | The parts of the current query. |
278
+ | `groups` | With `group`: the groups of every row (`'all'`) or of the page (`'page'`). |
279
+ | `groupCount` | With `group`: the number of top-level groups. |
280
+ | `summary` | The values of the `summary` option, in order, over every matching row. |
281
+ | `failedBlocks` | `'blocks'`: blocks that failed after the first answer; `retry()` loads them again. |
282
+ | `onChanged` | An event that reports every change with its reason. See [Status and errors](#status). |
283
+
284
+ ### Methods of DataSource
285
+
286
+ | Method | Description |
287
+ | --- | --- |
288
+ | `load()` | Loads the rows of the current query: all of them, the requested page, or the blocks the view needs. Resolves once they arrived; a failure does not reject (see [Status and errors](#status)). |
289
+ | `reload()` | Loads the rows of the current query again, keeping the page or the view. The rows kept in memory for the query and the rows found by key are dropped. |
290
+ | `retry()` | Loads what failed again: the failed blocks in `'blocks'` while the source is `'ready'`, otherwise the whole query. |
291
+ | `setPage(index)` | `'page'`: goes to a page, counted from 0 and clamped to the page count once it is known, and loads it. |
292
+ | `setPageSize(size)` | Another page size: the rows held go and the first page loads. `'all'` keeps the number for a view that pages the loaded rows itself; a block size is fixed (`MJD302`). |
293
+ | `setFilter(filter), setSort(sort), setGroup(group), setParams(params)` | Each changes one part of the query and loads from the first row. |
294
+ | `search(text)` | Keeps the rows where one of `searchFields` holds the text (`searchOperator`); an empty text keeps every row. |
295
+ | `setQuery(query)` | Changes several parts of the query at once, then loads once from the first row; the parts left out stay. |
296
+ | `rowAt(index)` | The row at `index` of the whole result, or `undefined` while it is not loaded. |
297
+ | `byKey(key)` | Resolves to the row with this key: among the loaded rows and the rows found before, otherwise from the adapter, keeping what it found. |
298
+ | `rowByKey(key)` | The row with this key among the loaded rows and the rows found before, without a request. |
299
+ | `indexOfKey(key)` | The index of the loaded row with this key in the whole result, or -1. |
300
+ | `forEachLoaded(fn)` | Calls `fn` for every loaded row with its index in the whole result. |
301
+ | `ensure(first, end, immediate?)` | `'blocks'`: the view shows rows `first` to `end - 1`; the missing blocks load. `immediate` skips the wait after a jump. |
302
+ | `ensureRanges(ranges, immediate?)` | `'blocks'`: the view shows several runs of rows, `[first, end)` each, with rows between them it does not show. |
303
+ | `pin(index)` | `'blocks'`: keeps the block of `index` (the focused row) in memory; -1 lets it go. |
304
+ | `isFailed(index)` | `'blocks'`: indicates whether the block of `index` failed. |
305
+ | `loadRange(options)` | Rows of the current query from `skip`, without groups and without touching the rows the source holds. Rejects when the load fails. See [Reading everything](#range). |
306
+ | `loadGroups(group, options?)` | Resolves to the groups of the current query by `group`, without rows: keys, counts and `groupSummary` values in every level. Rejects when the load fails. |
307
+ | `loadSummary(items, options?)` | Resolves to summary values of the current query over every matching row, for these items rather than the source's own. Rejects when the load fails. |
308
+ | `loadPivot(options)` | A pivot over the current query; `loadPivotMembers`, `loadPivotCounts`, `loadPivotBlocks` and `loadPivotCells` load its parts. See [Pivots and loading in parts](datalayer-pivot.md). |
309
+ | `narrow(filter, options?)` | A new data source over the same adapter, for the rows of the current query that `filter` keeps too. |
310
+ | `setData(rows)` | Replaces the rows of an `ArrayAdapter` and resolves once this source loaded them again; over any other adapter it throws `MJD302`. |
311
+ | `dispose()` | Aborts the loads on their way and stops listening to the adapter. |
312
+
313
+ ## Feedback
314
+
315
+ Loading issues…
316
+
317
+ ## Example files
318
+
319
+ `Paging.tsx`
320
+
321
+ ```tsx
322
+ import { reactive } from '@motifx/core';
323
+ import { data } from '@motifx-community/data';
324
+ import { Pagination, Stack, TextBox } from '@motifx-community/ui';
325
+ import { SlowAdapter } from '../../../../shared/slow-adapter';
326
+ import { makeCustomers, type Customer } from './customers';
327
+
328
+ /** A page of customers at a time from a slow service: search, page turns, and the status of the source. */
329
+ export default function Paging() {
330
+ // Answers 300 ms later, the way a server does. In an application: new data.RestAdapter({ url: '/api/customers', key: 'id' }).
331
+ const service = new SlowAdapter<Customer, number>({ data: makeCustomers(123), key: 'id' }, 300);
332
+ const source = new data.DataSource<Customer, number>({
333
+ adapter: service,
334
+ loadMode: 'page',
335
+ pageSize: 6,
336
+ sort: [{ field: 'name', dir: 'asc' }],
337
+ searchFields: ['name', 'city'],
338
+ });
339
+ const s = reactive({ status: source.status, rows: [] as Customer[], total: 0, page: 1, shown: 0 });
340
+ source.onChanged(() => {
341
+ s.status = source.status;
342
+ s.rows = [...source.rows];
343
+ s.total = source.total ?? 0;
344
+ s.page = source.pageIndex + 1;
345
+ s.shown = source.loadedPageIndex + 1;
346
+ });
347
+ void source.load();
348
+
349
+ return (
350
+ <Stack gap="sm" style="inline-size: 100%; max-inline-size: 36rem">
351
+ <Stack orientation="horizontal" wrap align="end">
352
+ <TextBox label="Search" placeholder="A name or a city" updateOn="input" onValueChanged={(e) => source.search(String(e.value ?? ''))} />
353
+ <output class="dls-paging-status">{() => `${s.status} · page ${s.page} requested, page ${s.shown || '-'} shown · ${s.total} customers`}</output>
354
+ </Stack>
355
+ <table class="dls-paging-rows">
356
+ <thead>
357
+ <tr>
358
+ <th>Customer</th>
359
+ <th>City</th>
360
+ <th>Orders</th>
361
+ </tr>
362
+ </thead>
363
+ <tbody>
364
+ {s.rows.map((c) => (
365
+ <tr key={c.id}>
366
+ <td>{c.name}</td>
367
+ <td>{c.city}</td>
368
+ <td>{c.orders}</td>
369
+ </tr>
370
+ ))}
371
+ </tbody>
372
+ </table>
373
+ <Pagination page={() => s.page} pageSize={6} total={() => s.total} onPageChanged={(e) => e.byUser && void source.setPage(e.page - 1)} />
374
+ </Stack>
375
+ );
376
+ }
377
+ ```
378
+
379
+ `customers.ts`
380
+
381
+ ```tsx
382
+ /** Invented customers for the paging example. */
383
+ export interface Customer {
384
+ id: number;
385
+ name: string;
386
+ city: string;
387
+ orders: number;
388
+ }
389
+
390
+ const FIRST = ['Ada', 'Deniz', 'Elif', 'Ivan', 'Kerem', 'Lena', 'Mert', 'Omar', 'Petra', 'Sara', 'Tomas', 'Yuki'];
391
+ const LAST = ['Aksoy', 'Demir', 'Fischer', 'Garcia', 'Johansson', 'Kaya', 'Moreau', 'Novak', 'Rossi', 'Silva', 'Tanaka', 'Weber'];
392
+ const CITIES = ['Ankara', 'Berlin', 'Lisbon', 'Madrid', 'Oslo', 'Prague', 'Rome', 'Tokyo', 'Vienna', 'Warsaw'];
393
+
394
+ /** `count` customers, the same ones on every run. */
395
+ export function makeCustomers(count: number): Customer[] {
396
+ return Array.from({ length: count }, (_, i) => ({
397
+ id: i + 1,
398
+ name: `${FIRST[i % FIRST.length]} ${LAST[(i * 5 + Math.floor(i / FIRST.length)) % LAST.length]}`,
399
+ city: CITIES[(i * 3) % CITIES.length],
400
+ orders: ((i * 37) % 90) + 1,
401
+ }));
402
+ }
403
+ ```
404
+
405
+ `slow-adapter.ts`
406
+
407
+ ```tsx
408
+ import { data } from '@motifx-community/data';
409
+
410
+ /** Rows in memory that answer a little later, the way a server does; for the examples. */
411
+ export class SlowAdapter<T extends object, K> extends data.ArrayAdapter<T, K> {
412
+ constructor(
413
+ options: data.ArrayAdapterOptions<T>,
414
+ private readonly delayMs = 300,
415
+ ) {
416
+ super(options);
417
+ }
418
+
419
+ override async load(options: data.LoadOptions = {}): Promise<data.LoadResult<T>> {
420
+ await new Promise((done) => setTimeout(done, this.delayMs));
421
+ return super.load(options);
422
+ }
423
+ }
424
+ ```
425
+
426
+ `Blocks.tsx`
427
+
428
+ ```tsx
429
+ import { reactive } from '@motifx/core';
430
+ import { data } from '@motifx-community/data';
431
+ import { ListBox } from '@motifx-community/ui';
432
+ import { SlowAdapter } from '../../../../shared/slow-adapter';
433
+
434
+ interface Reading {
435
+ id: number;
436
+ name: string;
437
+ }
438
+
439
+ /** 100,000 rows in blocks of 100: scrolling and jumping load only where the view stops. */
440
+ export default function Blocks() {
441
+ const s = reactive({ requested: 0, kept: 0, total: 0 });
442
+ const readings: Reading[] = Array.from({ length: 100_000 }, (_, i) => ({
443
+ id: i + 1,
444
+ name: `Reading #${String(i + 1).padStart(6, '0')} · sensor ${String.fromCharCode(65 + (i % 8))}`,
445
+ }));
446
+ // Answers 200 ms later, the way a server does.
447
+ const server = new SlowAdapter<Reading, number>({ data: readings, key: 'id' }, 200);
448
+ server.onLoading(() => s.requested++);
449
+ const source = new data.DataSource<Reading, number>({ adapter: server, loadMode: 'blocks', pageSize: 100 });
450
+ source.onChanged(() => {
451
+ const kept = new Set<number>();
452
+ source.forEachLoaded((_row, index) => kept.add(Math.floor(index / source.pageSize)));
453
+ s.kept = kept.size;
454
+ s.total = source.total ?? 0;
455
+ });
456
+
457
+ return (
458
+ <>
459
+ <ListBox label="100,000 readings" dataSource={source} textField="name" valueField="id" height={10} />
460
+ <output class="dls-blocks-counts">{() => `${s.total.toLocaleString('en')} rows in ${Math.ceil(s.total / 100).toLocaleString('en')} blocks · ${s.requested} requested · ${s.kept} in memory`}</output>
461
+ </>
462
+ );
463
+ }
464
+ ```