viewkitjs 0.30.1 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/MIGRATION.md +40 -6
  3. package/README.md +1 -1
  4. package/fields/dist/query/index.d.ts +2 -0
  5. package/fields/dist/query/index.js +2 -0
  6. package/fields/dist/query/list-request.d.ts +148 -0
  7. package/fields/dist/query/list-request.js +125 -0
  8. package/fields/dist/query/saved-view.d.ts +15 -0
  9. package/fields/dist/query/saved-view.js +11 -0
  10. package/fields/dist/query/settings.d.ts +9 -0
  11. package/fields/dist/query/settings.js +9 -0
  12. package/fields/docs/reference/query.md +66 -0
  13. package/package.json +8 -2
  14. package/postgres/README.md +1 -0
  15. package/postgres/dist/handler.d.ts +53 -0
  16. package/postgres/dist/handler.js +211 -0
  17. package/postgres/dist/ids.d.ts +1 -1
  18. package/postgres/dist/ids.js +19 -1
  19. package/postgres/dist/index.d.ts +1 -0
  20. package/postgres/dist/index.js +1 -0
  21. package/postgres/dist/limits.d.ts +3 -1
  22. package/postgres/dist/limits.js +1 -1
  23. package/postgres/dist/list-fields.d.ts +10 -0
  24. package/postgres/dist/list-fields.js +36 -0
  25. package/postgres/dist/readable.d.ts +4 -0
  26. package/postgres/dist/readable.js +4 -0
  27. package/postgres/dist/refusals.d.ts +9 -2
  28. package/postgres/dist/refusals.js +6 -0
  29. package/postgres/docs/guides/field-map.md +2 -2
  30. package/postgres/docs/guides/list-handler.md +99 -0
  31. package/postgres/docs/index.md +1 -0
  32. package/postgres/docs/reference/postgres.md +11 -3
  33. package/views/README.md +2 -2
  34. package/views/dist/atoms/RowMenu.d.ts +7 -0
  35. package/views/dist/atoms/RowMenu.js +18 -16
  36. package/views/dist/atoms/carried.d.ts +5 -0
  37. package/views/dist/atoms/carried.js +7 -0
  38. package/views/dist/atoms/types.d.ts +3 -0
  39. package/views/dist/contract.d.ts +26 -6
  40. package/views/dist/contract.js +25 -0
  41. package/views/dist/controls/alert-dialog/alert-dialog.js +2 -1
  42. package/views/dist/controls/atoms.d.ts +2 -0
  43. package/views/dist/controls/atoms.js +2 -0
  44. package/views/dist/controls/avatar/avatar.d.ts +10 -4
  45. package/views/dist/controls/avatar/avatar.js +5 -3
  46. package/views/dist/controls/avatar/tokens.d.ts +104 -0
  47. package/views/dist/controls/avatar/tokens.js +26 -0
  48. package/views/dist/controls/avatar.css +46 -15
  49. package/views/dist/controls/choice/tokens.d.ts +0 -4
  50. package/views/dist/controls/choice/tokens.js +0 -1
  51. package/views/dist/controls/choice.css +3 -3
  52. package/views/dist/controls/controls.d.ts +6 -0
  53. package/views/dist/controls/controls.js +10 -2
  54. package/views/dist/controls/customize/map-customize-body.js +1 -1
  55. package/views/dist/controls/field/field.d.ts +19 -4
  56. package/views/dist/controls/field/field.js +63 -5
  57. package/views/dist/controls/field/tokens.d.ts +4 -0
  58. package/views/dist/controls/field/tokens.js +1 -0
  59. package/views/dist/controls/field.css +41 -16
  60. package/views/dist/controls/glyphs/glyphs.d.ts +10 -0
  61. package/views/dist/controls/glyphs/glyphs.js +173 -0
  62. package/views/dist/controls/index.d.ts +4 -2
  63. package/views/dist/controls/index.js +3 -1
  64. package/views/dist/controls/input/input.d.ts +12 -1
  65. package/views/dist/controls/input/input.js +10 -6
  66. package/views/dist/controls/input/save-mark.d.ts +8 -0
  67. package/views/dist/controls/input/save-mark.js +26 -0
  68. package/views/dist/controls/input/tokens.d.ts +20 -0
  69. package/views/dist/controls/input/tokens.js +5 -0
  70. package/views/dist/controls/input.css +49 -3
  71. package/views/dist/controls/internal/icons.js +10 -0
  72. package/views/dist/controls/internal/keep-focus.d.ts +2 -0
  73. package/views/dist/controls/internal/keep-focus.js +17 -0
  74. package/views/dist/controls/internal/watch-frame.d.ts +2 -0
  75. package/views/dist/controls/internal/watch-frame.js +33 -0
  76. package/views/dist/controls/markdown/map-markdown.d.ts +4 -0
  77. package/views/dist/controls/markdown/map-markdown.js +5 -0
  78. package/views/dist/controls/menu/map-menu.js +2 -2
  79. package/views/dist/controls/menu-list/menu-list.d.ts +3 -0
  80. package/views/dist/controls/menu-list/menu-list.js +5 -4
  81. package/views/dist/controls/modal/modal.js +5 -1
  82. package/views/dist/controls/pane/pane.js +2 -1
  83. package/views/dist/controls/phone-header/header-bar.d.ts +5 -1
  84. package/views/dist/controls/phone-header/header-bar.js +2 -2
  85. package/views/dist/controls/phone-header.css +11 -1
  86. package/views/dist/controls/picker/map-picker.js +3 -0
  87. package/views/dist/controls/picker/picker.d.ts +14 -0
  88. package/views/dist/controls/picker/picker.js +30 -10
  89. package/views/dist/controls/picker.css +2 -0
  90. package/views/dist/controls/popover/popover.js +2 -1
  91. package/views/dist/controls/radio/radio.d.ts +12 -3
  92. package/views/dist/controls/radio/radio.js +25 -5
  93. package/views/dist/controls/radio/tokens.d.ts +84 -0
  94. package/views/dist/controls/radio/tokens.js +21 -0
  95. package/views/dist/controls/radio.css +130 -3
  96. package/views/dist/controls/select/select.d.ts +12 -2
  97. package/views/dist/controls/select/select.js +15 -7
  98. package/views/dist/controls/select/tokens.d.ts +8 -0
  99. package/views/dist/controls/select/tokens.js +2 -0
  100. package/views/dist/controls/select.css +17 -0
  101. package/views/dist/controls/setting-row/looks.d.ts +10 -0
  102. package/views/dist/controls/setting-row/looks.js +22 -0
  103. package/views/dist/controls/setting-row/setting-row.d.ts +100 -0
  104. package/views/dist/controls/setting-row/setting-row.js +133 -0
  105. package/views/dist/controls/setting-row/tokens.d.ts +156 -0
  106. package/views/dist/controls/setting-row/tokens.js +41 -0
  107. package/views/dist/controls/setting-row.css +215 -0
  108. package/views/dist/controls/sheet/bottom-sheet.d.ts +10 -2
  109. package/views/dist/controls/sheet/bottom-sheet.js +6 -3
  110. package/views/dist/controls/sheet.css +4 -1
  111. package/views/dist/controls/sort-editor/sort-editor.js +3 -2
  112. package/views/dist/controls/sort-editor.css +8 -2
  113. package/views/dist/controls/switch-row/switch-row.d.ts +1 -15
  114. package/views/dist/controls/switch-row/switch-row.js +1 -9
  115. package/views/dist/controls/switch-row/tokens.d.ts +0 -12
  116. package/views/dist/controls/switch-row/tokens.js +0 -3
  117. package/views/dist/controls/switch-row.css +3 -7
  118. package/views/dist/controls/switch.css +17 -7
  119. package/views/dist/controls/tag/tag.d.ts +3 -1
  120. package/views/dist/controls/tag/tag.js +2 -2
  121. package/views/dist/controls/tag/tokens.d.ts +4 -0
  122. package/views/dist/controls/tag/tokens.js +1 -0
  123. package/views/dist/controls/tag-field/tag-field.d.ts +5 -1
  124. package/views/dist/controls/tag-field/tag-field.js +11 -5
  125. package/views/dist/controls/tag-field/tokens.d.ts +16 -0
  126. package/views/dist/controls/tag-field/tokens.js +4 -0
  127. package/views/dist/controls/tag-field.css +19 -0
  128. package/views/dist/controls/tag.css +2 -0
  129. package/views/dist/controls/tokens.js +2 -0
  130. package/views/dist/controls/toolbar/toolbar.d.ts +15 -3
  131. package/views/dist/controls/toolbar/toolbar.js +22 -15
  132. package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +14 -0
  133. package/views/dist/controls/toolbar-button/atom-toolbar-button.js +51 -0
  134. package/views/dist/controls/toolbar-button/toolbar-button.d.ts +1 -1
  135. package/views/dist/controls/toolbar-button/toolbar-button.js +2 -3
  136. package/views/dist/controls/toolbar-button.css +4 -0
  137. package/views/dist/controls/toolbar.css +5 -0
  138. package/views/dist/controls/views-list/map-view-menu.d.ts +3 -0
  139. package/views/dist/controls/views-list/map-view-menu.js +25 -0
  140. package/views/dist/controls/views-list/map-views-list-body.d.ts +28 -1
  141. package/views/dist/controls/views-list/map-views-list-body.js +39 -21
  142. package/views/dist/controls/views-list/rules.d.ts +2 -0
  143. package/views/dist/controls/views-list/view-menu.d.ts +7 -0
  144. package/views/dist/controls/views-list/view-menu.js +28 -24
  145. package/views/dist/controls/views-list/words.d.ts +2 -0
  146. package/views/dist/controls/views-list/words.js +1 -1
  147. package/views/dist/editors/EditorPanel.js +2 -1
  148. package/views/dist/editors/edit-session.js +2 -5
  149. package/views/dist/field-row/FieldRow.d.ts +4 -2
  150. package/views/dist/field-row/FieldRow.js +67 -20
  151. package/views/dist/field-row/FieldRowLane.d.ts +7 -2
  152. package/views/dist/field-row/FieldRowLane.js +4 -3
  153. package/views/dist/field-row/editors/RowEditor.d.ts +12 -0
  154. package/views/dist/field-row/editors/RowEditor.js +31 -1
  155. package/views/dist/field-row/editors/RowValueListEditor.d.ts +5 -1
  156. package/views/dist/field-row/editors/RowValueListEditor.js +4 -1
  157. package/views/dist/field-row/field-row-button.d.ts +5 -0
  158. package/views/dist/field-row/field-row-button.js +2 -0
  159. package/views/dist/fields/binding.d.ts +3 -2
  160. package/views/dist/fields/binding.js +38 -5
  161. package/views/dist/grid/chrome/GridColumnMenu.d.ts +4 -2
  162. package/views/dist/grid/chrome/GridColumnMenu.js +3 -2
  163. package/views/dist/grid/chrome/GridGroupMenu.d.ts +4 -1
  164. package/views/dist/grid/chrome/GridGroupMenu.js +4 -3
  165. package/views/dist/grid/chrome/GridHeader.d.ts +4 -1
  166. package/views/dist/grid/chrome/GridHeader.js +2 -2
  167. package/views/dist/grid/chrome/GridRow.js +6 -5
  168. package/views/dist/grid/chrome/GridRowCells.js +6 -9
  169. package/views/dist/grid/chrome/GridStructure.d.ts +4 -1
  170. package/views/dist/grid/chrome/GridStructure.js +4 -4
  171. package/views/dist/grid/chrome/GridTable.js +5 -2
  172. package/views/dist/grid/chrome/grid-column-menu-items.js +1 -1
  173. package/views/dist/grid/chrome/grid-row-menu-items.d.ts +27 -3
  174. package/views/dist/grid/chrome/grid-row-menu-items.js +92 -6
  175. package/views/dist/grid/chrome/grid-row-props.d.ts +7 -2
  176. package/views/dist/grid/chrome/grid-rows-menu.js +34 -6
  177. package/views/dist/grid/chrome/grid-table-props.d.ts +38 -7
  178. package/views/dist/grid/chrome/useGridBatchApi.d.ts +3 -1
  179. package/views/dist/grid/chrome/useGridBatchApi.js +4 -2
  180. package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -2
  181. package/views/dist/grid/chrome/useGridKeyboard.js +15 -9
  182. package/views/dist/grid/chrome/useGridPendingReconciliation.js +1 -2
  183. package/views/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -1
  184. package/views/dist/grid/chrome/useGridTableInteractionModel.js +11 -5
  185. package/views/dist/grid/core/commit-model.d.ts +20 -2
  186. package/views/dist/grid/core/editing-controller.d.ts +18 -0
  187. package/views/dist/grid/core/editing-controller.js +188 -42
  188. package/views/dist/grid/core/editing-model.d.ts +3 -0
  189. package/views/dist/grid/core/editing-model.js +3 -0
  190. package/views/dist/grid/core/save-path.d.ts +24 -0
  191. package/views/dist/grid/core/save-path.js +122 -0
  192. package/views/dist/grid/core/spreadsheet-operations.d.ts +3 -0
  193. package/views/dist/grid/core/spreadsheet-operations.js +23 -0
  194. package/views/dist/grid/index.d.ts +3 -2
  195. package/views/dist/grid/index.js +1 -0
  196. package/views/dist/internal/field-rows.d.ts +26 -0
  197. package/views/dist/internal/field-rows.js +8 -0
  198. package/views/dist/internal/page-close.d.ts +7 -0
  199. package/views/dist/internal/page-close.js +43 -0
  200. package/views/dist/list/browser-views-store.d.ts +10 -0
  201. package/views/dist/list/browser-views-store.js +182 -0
  202. package/views/dist/list/index.d.ts +23 -0
  203. package/views/dist/list/index.js +8 -0
  204. package/views/dist/list/menu.d.ts +31 -0
  205. package/views/dist/list/menu.js +76 -0
  206. package/views/dist/list/parts.d.ts +6 -0
  207. package/views/dist/list/parts.js +59 -0
  208. package/views/dist/list/registry.d.ts +11 -0
  209. package/views/dist/list/registry.js +31 -0
  210. package/views/dist/list/root.d.ts +40 -0
  211. package/views/dist/list/root.js +128 -0
  212. package/views/dist/list/slot.d.ts +14 -0
  213. package/views/dist/list/slot.js +22 -0
  214. package/views/dist/list/source.d.ts +11 -0
  215. package/views/dist/list/source.js +31 -0
  216. package/views/dist/list/store.d.ts +87 -0
  217. package/views/dist/list/store.js +115 -0
  218. package/views/dist/list/toolbar.d.ts +6 -0
  219. package/views/dist/list/toolbar.js +359 -0
  220. package/views/dist/list/views-axis.d.ts +5 -0
  221. package/views/dist/list/views-axis.js +96 -0
  222. package/views/dist/list/views-store.d.ts +41 -0
  223. package/views/dist/list/views-store.js +1 -0
  224. package/views/dist/list/views.d.ts +67 -0
  225. package/views/dist/list/views.js +400 -0
  226. package/views/dist/looks/index.d.ts +1 -0
  227. package/views/dist/looks/index.js +1 -0
  228. package/views/dist/looks/pieces.js +2 -0
  229. package/views/dist/model/preferences.js +1 -1
  230. package/views/dist/model/prefs-buckets.js +1 -1
  231. package/views/dist/panels/index.d.ts +3 -1
  232. package/views/dist/panels/index.js +1 -0
  233. package/views/dist/panels/react/customize-body.js +1 -0
  234. package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +41 -4
  235. package/views/dist/panels/react/toolbar/ReadyToolbar.js +6 -326
  236. package/views/dist/panels/react/toolbar/Toolbar.d.ts +9 -1
  237. package/views/dist/panels/react/toolbar/Toolbar.js +34 -23
  238. package/views/dist/panels/react/toolbar/ToolbarButton.js +4 -1
  239. package/views/dist/panels/react/toolbar/ToolbarNew.js +1 -1
  240. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +2 -2
  241. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +3 -1
  242. package/views/dist/panels/react/toolbar/ToolbarSearch.js +1 -1
  243. package/views/dist/panels/react/toolbar/context.d.ts +10 -2
  244. package/views/dist/panels/react/toolbar/context.js +3 -1
  245. package/views/dist/panels/react/views-row/FoldingViewRow.d.ts +1 -1
  246. package/views/dist/panels/react/views-row/FoldingViewRow.js +15 -4
  247. package/views/dist/panels/react/views-row/PillGroup.d.ts +5 -2
  248. package/views/dist/panels/react/views-row/PillGroup.js +16 -7
  249. package/views/dist/panels/react/views-row/ViewPicker.js +2 -12
  250. package/views/dist/panels/react/views-row/ViewPickerRow.d.ts +4 -2
  251. package/views/dist/panels/react/views-row/ViewPickerRow.js +9 -5
  252. package/views/dist/panels/react.d.ts +2 -2
  253. package/views/dist/panels/toolbar/edit-view.d.ts +7 -1
  254. package/views/dist/panels/toolbar/edit-view.js +14 -0
  255. package/views/dist/panels/toolbar/model.d.ts +5 -0
  256. package/views/dist/panels/toolbar/model.js +7 -3
  257. package/views/dist/panels/view-state.d.ts +5 -3
  258. package/views/dist/panels/views-row/model.d.ts +19 -2
  259. package/views/dist/panels/views-row/model.js +14 -0
  260. package/views/dist/provider/ViewsProvider.d.ts +16 -7
  261. package/views/dist/provider/ViewsProvider.js +23 -5
  262. package/views/dist/provider/components.d.ts +43 -2
  263. package/views/dist/provider/context.d.ts +2 -1
  264. package/views/dist/provider/context.js +1 -1
  265. package/views/dist/provider/ports.d.ts +19 -12
  266. package/views/dist/provider/ports.js +69 -1
  267. package/views/dist/react.d.ts +1 -1
  268. package/views/dist/styles.css +583 -61
  269. package/views/dist/styles.unlayered.css +583 -61
  270. package/views/docs/contract.md +42 -31
  271. package/views/docs/controls/avatar.md +26 -0
  272. package/views/docs/controls/choice.md +0 -1
  273. package/views/docs/controls/field.md +3 -0
  274. package/views/docs/controls/input.md +9 -0
  275. package/views/docs/controls/radio.md +33 -0
  276. package/views/docs/controls/select.md +6 -0
  277. package/views/docs/controls/setting-row.md +44 -0
  278. package/views/docs/controls/switch-row.md +0 -3
  279. package/views/docs/controls/tag-field.md +4 -0
  280. package/views/docs/controls/tag.md +1 -0
  281. package/views/docs/getting-started.md +2 -2
  282. package/views/docs/guides/atoms.md +2 -2
  283. package/views/docs/guides/columns.md +1 -1
  284. package/views/docs/guides/ports.md +1 -1
  285. package/views/docs/guides/the-grid.md +34 -7
  286. package/views/docs/guides/the-provider.md +4 -2
  287. package/views/docs/index.md +1 -0
  288. package/views/docs/reference/controls.md +54 -27
  289. package/views/docs/reference/editors-session.md +1 -1
  290. package/views/docs/reference/field-row.md +9 -1
  291. package/views/docs/reference/grid.md +14 -8
  292. package/views/docs/reference/list.md +227 -0
  293. package/views/docs/reference/looks.md +3 -0
  294. package/views/docs/reference/panels-react.md +17 -12
  295. package/views/docs/reference/panels.md +8 -5
  296. package/views/docs/reference/react.md +11 -9
  297. package/views/docs/reference/views.md +2 -2
  298. package/views/skills/views/SKILL.md +9 -6
@@ -0,0 +1,128 @@
1
+ "use client";
2
+ import { createContext, createElement, useCallback, useContext, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from "react";
3
+ import { LIST_SETTINGS_DEFAULTS } from "viewkitjs/fields/query";
4
+ import { ListRadioContext, ToolbarRadioContext, useToolbarRadioState } from "../panels/react/toolbar/context.js";
5
+ import { ListRegistryContext } from "./registry.js";
6
+ import { ViewsContext } from "../provider/context.js";
7
+ import { browserViewsStore } from "./browser-views-store.js";
8
+ import { createListStore } from "./store.js";
9
+ import { createListViews } from "./views.js";
10
+ const ListStoreContext = createContext(null);
11
+ export function ListRoot({ id, children, ...props }) {
12
+ const mode = useStoreMode(id, props);
13
+ const extra = { sortFilter: props.sortFilter, bar: props.bar };
14
+ const sync = mode ? mode.views.sync(extra) : props;
15
+ const [store] = useState(() => createListStore(id, sync));
16
+ store.sync(sync);
17
+ useLayoutEffect(() => store.flush());
18
+ useStoreViews(mode, store, extra);
19
+ const registry = useContext(ListRegistryContext);
20
+ useLayoutEffect(() => registry?.addStore(store.get().id, store), [registry, store]);
21
+ const radio = useToolbarRadioState();
22
+ return createElement(ListStoreContext.Provider, { value: store }, createElement(ListRadioContext.Provider, { value: radio }, createElement(ToolbarRadioContext.Provider, { value: radio }, children)));
23
+ }
24
+ export function useListStore() {
25
+ const store = useContext(ListStoreContext);
26
+ if (!store)
27
+ throw new Error("useList reads a list's state, and needs a ListRoot around it");
28
+ return store;
29
+ }
30
+ export function useList(...args) {
31
+ const byId = typeof args[0] === "string" ? args[0] : null;
32
+ const [select, equal = Object.is] = (byId === null ? args : args.slice(1));
33
+ const inside = useContext(ListStoreContext);
34
+ const registry = useContext(ListRegistryContext);
35
+ if (byId === null && !inside)
36
+ throw new Error("useList reads a list's state, and needs a ListRoot around it");
37
+ if (byId !== null && !registry)
38
+ throw new Error("useList(id, select) reads a list by its id, and needs a ViewsProvider around it");
39
+ const storeOf = () => (byId === null ? (inside ?? undefined) : registry?.store(byId));
40
+ const subscribe = useCallback((listener) => {
41
+ if (byId === null || !registry)
42
+ return inside ? inside.subscribe(listener) : () => { };
43
+ let off = registry.store(byId)?.subscribe(listener) ?? (() => { });
44
+ const offRegistry = registry.subscribe(() => {
45
+ off();
46
+ off = registry.store(byId)?.subscribe(listener) ?? (() => { });
47
+ listener();
48
+ });
49
+ return () => {
50
+ offRegistry();
51
+ off();
52
+ };
53
+ }, [byId, registry, inside]);
54
+ const memo = useRef(null);
55
+ const read = () => {
56
+ const state = storeOf()?.get();
57
+ if (!state) {
58
+ memo.current = null;
59
+ return undefined;
60
+ }
61
+ const last = memo.current;
62
+ if (last && last.state === state && last.select === select)
63
+ return last.value;
64
+ const value = select(state);
65
+ if (last && equal(last.value, value)) {
66
+ memo.current = { state, select, value: last.value };
67
+ return last.value;
68
+ }
69
+ memo.current = { state, select, value };
70
+ return value;
71
+ };
72
+ return useSyncExternalStore(subscribe, read, read);
73
+ }
74
+ export function useListPanel(key) {
75
+ const store = useListStore();
76
+ const open = useList((s) => s.panels.open === key);
77
+ const page = useList((s) => s.panels.pages[key] ?? null);
78
+ const onOpenChange = useCallback((next) => (next ? store.get().openPanel(key) : store.get().closePanel(key)), [store, key]);
79
+ const onPageChange = useCallback((next) => store.get().setPage(key, next), [store, key]);
80
+ return useMemo(() => ({ open, onOpenChange, page, onPageChange }), [open, onOpenChange, page, onPageChange]);
81
+ }
82
+ function useStoreMode(id, props) {
83
+ const [mode] = useState(() => {
84
+ if (props.settings !== undefined)
85
+ return null;
86
+ const own = props;
87
+ const given = own.views;
88
+ const options = given && "list" in given ? { store: given } : (given ?? {});
89
+ const store = options.store ?? browserViewsStore(options.seed ? { seed: { [id]: options.seed } } : undefined);
90
+ let on = { change: () => { }, error: () => { } };
91
+ const views = createListViews({
92
+ id,
93
+ store,
94
+ defaults: own.defaults ?? LIST_SETTINGS_DEFAULTS,
95
+ ...(own.link && { link: own.link }),
96
+ ...(options.records !== undefined && { records: options.records }),
97
+ onChange: () => on.change(),
98
+ onError: (message) => on.error(message),
99
+ });
100
+ return { views, wire: (next) => void (on = next) };
101
+ });
102
+ return mode;
103
+ }
104
+ function useStoreViews(mode, store, extra) {
105
+ const toast = useContext(ViewsContext)?.ports.toast.error;
106
+ useLayoutEffect(() => {
107
+ if (!mode)
108
+ return;
109
+ mode.wire({
110
+ change: () => {
111
+ store.sync(mode.views.sync(extra));
112
+ store.patch({ views: mode.views.state() });
113
+ store.flush();
114
+ },
115
+ error: (message) => toast?.(message),
116
+ });
117
+ });
118
+ const [, settle] = useState(0);
119
+ useLayoutEffect(() => {
120
+ if (!mode)
121
+ return;
122
+ store.patch({ views: mode.views.state() });
123
+ const stop = mode.views.start();
124
+ if (mode.views.state().ready)
125
+ settle((n) => n + 1);
126
+ return stop;
127
+ }, [mode, store]);
128
+ }
@@ -0,0 +1,14 @@
1
+ import { type ReactNode } from "react";
2
+ export type ListSlotProps = {
3
+ name: string;
4
+ className?: string;
5
+ };
6
+ export type ListFillProps = {
7
+ name: string;
8
+ children?: ReactNode;
9
+ };
10
+ /** Where the fills of this name draw: a `div` (`data-slot="vk-list-slot"`, `data-name`). One slot per name under a
11
+ * provider: a later one takes the fills from an earlier. */
12
+ export declare function ListSlot({ name, className }: ListSlotProps): ReactNode;
13
+ /** What it holds, drawn in the `ListSlot` of its name; nothing while none stands. */
14
+ export declare function ListFill({ name, children }: ListFillProps): ReactNode;
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useCallback, useContext, useSyncExternalStore } from "react";
4
+ import { createPortal } from "react-dom";
5
+ import { ListRegistryContext } from "./registry.js";
6
+ function useRegistry(part) {
7
+ const registry = useContext(ListRegistryContext);
8
+ if (!registry)
9
+ throw new Error(`${part} needs a ViewsProvider around it`);
10
+ return registry;
11
+ }
12
+ export function ListSlot({ name, className }) {
13
+ const registry = useRegistry("ListSlot");
14
+ const ref = useCallback((element) => (element ? registry.addSlot(name, element) : undefined), [registry, name]);
15
+ return _jsx("div", { ref: ref, "data-slot": "vk-list-slot", "data-name": name, className: className });
16
+ }
17
+ export function ListFill({ name, children }) {
18
+ const registry = useRegistry("ListFill");
19
+ const read = () => registry.slot(name) ?? null;
20
+ const element = useSyncExternalStore(registry.subscribe, read, () => null);
21
+ return element ? createPortal(children, element) : null;
22
+ }
@@ -0,0 +1,11 @@
1
+ import { type ListAnswer, type ListRequest, type ListRow } from "viewkitjs/fields/query";
2
+ /** Where a list's rows come from: one request in, its answer out. A refusal is an answer (`isRefused`), never a
3
+ * throw; a throw is a failure the list can only report. One argument, so a server action is a source as it stands. */
4
+ export type ListSource<Row extends ListRow = ListRow> = (request: ListRequest) => Promise<ListAnswer<Row>>;
5
+ /**
6
+ * A source that POSTs each request as JSON to `url` and reads the answer. `init` is handed to `fetch` (its headers
7
+ * kept, `content-type` set to JSON). A 2xx answer, or a 400 holding a refusal, is checked with `listAnswerSchema` and
8
+ * `answerFor` and handed back; any other status throws, naming it, as does an answer that is no list answer or an
9
+ * answer to another part.
10
+ */
11
+ export declare function fetchSource<Row extends ListRow = ListRow>(url: string | URL, init?: Omit<RequestInit, "method" | "body">): ListSource<Row>;
@@ -0,0 +1,31 @@
1
+ import { answerFor, listAnswerSchema } from "viewkitjs/fields/query";
2
+ export function fetchSource(url, init) {
3
+ const at = `the list source at ${String(url)}`;
4
+ return async (request) => {
5
+ const headers = new Headers(init?.headers);
6
+ headers.set("content-type", "application/json");
7
+ if (!headers.has("accept"))
8
+ headers.set("accept", "application/json");
9
+ const response = await fetch(url, { ...init, method: "POST", headers, body: JSON.stringify(request) });
10
+ if (!response.ok && response.status !== 400)
11
+ throw new Error(`${at} answered ${response.status}`);
12
+ let body;
13
+ try {
14
+ body = await response.json();
15
+ }
16
+ catch {
17
+ throw new Error(`${at} answered ${response.status} with no JSON`);
18
+ }
19
+ const read = listAnswerSchema.safeParse(body);
20
+ if (!read.success)
21
+ throw new Error(`${at} answered no list answer: ${read.error.issues[0]?.message ?? "unreadable"}`);
22
+ if (!response.ok && !("refused" in read.data))
23
+ throw new Error(`${at} answered ${response.status}`);
24
+ try {
25
+ return answerFor(request, read.data);
26
+ }
27
+ catch (error) {
28
+ throw new Error(`${at} ${error.message}`);
29
+ }
30
+ };
31
+ }
@@ -0,0 +1,87 @@
1
+ import type { ListPersonalLayer, ListSettings, ListSettingsChange } from "viewkitjs/fields/query";
2
+ import type { ActivePanel } from "../panels/model.js";
3
+ import type { Pending } from "../panels/react/filter/editor-ctx.js";
4
+ import type { CollectionViewState } from "../panels/view-state.js";
5
+ import type { ListViewsState } from "./views.js";
6
+ /** One list's state, as a part selects it (`useList((s) => …)`). */
7
+ export type ListState = {
8
+ /** The list's id (`ListRoot`'s). */
9
+ id: string;
10
+ /** The settings as the person edits them, their own layer over them, and the shared view this list shows (null:
11
+ * none). */
12
+ view: {
13
+ settings: ListSettings;
14
+ layer: ListPersonalLayer;
15
+ shared: CollectionViewState | null;
16
+ };
17
+ panels: {
18
+ /** The one panel open in this list, by its key; null, none. */
19
+ open: string | null;
20
+ /** The page each panel stands on, by its key: the open one's, or one set for a panel about to open. */
21
+ pages: Readonly<Record<string, ActivePanel>>;
22
+ /** The filter rule held until whole, shared by Filter on the row and the filter bar. */
23
+ held: Pending | null;
24
+ /** The filter bar shows (the toolbar says, as it draws). */
25
+ barShown: boolean;
26
+ /** Clear and Save stand in Customize's foot, not at the bar's end (the toolbar says, as it draws). */
27
+ footHere: boolean;
28
+ sortFilter: "right" | "bar";
29
+ bar: "added" | "always";
30
+ };
31
+ /** The picked rows: their ids, or every matching row (`all`), and how many (null: every matching row, before the
32
+ * list knows its total). */
33
+ selection: {
34
+ ids: readonly string[];
35
+ all: boolean;
36
+ count: number | null;
37
+ };
38
+ /** The list's saved views where the root keeps them through a store (VK-196); null in memory mode. */
39
+ views: ListViewsState | null;
40
+ /** A change to the settings, handed to the app. */
41
+ setSettings: (change: ListSettingsChange) => void;
42
+ /** A patch to the person's layer, handed to the app. */
43
+ setLayer: (patch: ListPersonalLayer) => void;
44
+ /** Opens a panel and closes any other; on `page` where handed, else on the page it holds. */
45
+ openPanel: (key: string, page?: ActivePanel) => void;
46
+ /** Closes a panel, if it is the one open; its page, or a page waiting for it, is forgotten. */
47
+ closePanel: (key: string) => void;
48
+ /** A panel's page: the open one's, or kept for a panel until another opens. */
49
+ setPage: (key: string, page: ActivePanel) => void;
50
+ hold: (held: Pending | null) => void;
51
+ /** Picks these rows, or every matching row (`"all"`); `[]` picks none. */
52
+ select: (ids: readonly string[] | "all") => void;
53
+ /** The shared view's Save for everyone; nothing without a shared view. */
54
+ saveView: () => void;
55
+ /** The shared view's Reset; nothing without a shared view. */
56
+ resetView: () => void;
57
+ /** Takes back the list's last edit; nothing until the list holds edits. */
58
+ undo: () => void;
59
+ };
60
+ /** What the app hands the root: synced in on every render. */
61
+ export type ListSync = {
62
+ settings: ListSettings;
63
+ layer: ListPersonalLayer;
64
+ onChange: (change: ListSettingsChange) => void;
65
+ onLayerChange: (patch: ListPersonalLayer) => void;
66
+ view?: CollectionViewState;
67
+ sortFilter?: "right" | "bar";
68
+ bar?: "added" | "always";
69
+ };
70
+ export type ListStore = {
71
+ get: () => ListState;
72
+ subscribe: (listener: () => void) => () => void;
73
+ /** Takes the app's latest props without telling anyone; `flush` tells. */
74
+ sync: (props: ListSync) => void;
75
+ flush: () => void;
76
+ /** The toolbar's published bar (`barShown`, `footHere`), and the root's saved views. The ready List widens it with its
77
+ * answer and edits. */
78
+ patch: (patch: {
79
+ panels?: Partial<Pick<ListState["panels"], "barShown" | "footHere">>;
80
+ views?: ListViewsState | null;
81
+ }) => void;
82
+ /** The ready List wires its edits' undo here. */
83
+ wire: (handlers: {
84
+ undo?: () => void;
85
+ }) => void;
86
+ };
87
+ export declare function createListStore(id: string, props: ListSync): ListStore;
@@ -0,0 +1,115 @@
1
+ const sameKeys = (a, b) => Object.keys(b).every((key) => Object.is(a[key], b[key]));
2
+ const sameIds = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
3
+ export function createListStore(id, props) {
4
+ let latest = props;
5
+ let wired = {};
6
+ const listeners = new Set();
7
+ let dirty = false;
8
+ const viewOf = (from) => ({
9
+ settings: from.settings,
10
+ layer: from.layer,
11
+ shared: from.view ?? null,
12
+ });
13
+ const actions = {
14
+ setSettings: (change) => latest.onChange(change),
15
+ setLayer: (patch) => latest.onLayerChange(patch),
16
+ openPanel: (key, page) => {
17
+ const { panels } = state;
18
+ const kept = page ?? panels.pages[key];
19
+ if (panels.open === key && panels.pages[key] === kept)
20
+ return;
21
+ write({ panels: { ...panels, open: key, pages: kept ? { [key]: kept } : {} } });
22
+ },
23
+ closePanel: (key) => {
24
+ const { panels } = state;
25
+ if (panels.open !== key && !(key in panels.pages))
26
+ return;
27
+ const { [key]: _forgotten, ...waiting } = panels.pages;
28
+ write({ panels: { ...panels, open: panels.open === key ? null : panels.open, pages: waiting } });
29
+ },
30
+ setPage: (key, page) => {
31
+ const { panels } = state;
32
+ if (panels.pages[key] === page)
33
+ return;
34
+ write({ panels: { ...panels, pages: { ...panels.pages, [key]: page } } });
35
+ },
36
+ hold: (held) => {
37
+ if (state.panels.held === held)
38
+ return;
39
+ write({ panels: { ...state.panels, held } });
40
+ },
41
+ select: (ids) => {
42
+ const { selection } = state;
43
+ if (ids === "all" ? selection.all : !selection.all && sameIds(selection.ids, ids))
44
+ return;
45
+ write({ selection: ids === "all" ? { ids: [], all: true, count: null } : { ids, all: false, count: ids.length } });
46
+ },
47
+ saveView: () => latest.view?.onPublish(),
48
+ resetView: () => latest.view?.onReset(),
49
+ undo: () => wired.undo?.(),
50
+ };
51
+ const data = {
52
+ id,
53
+ view: viewOf(props),
54
+ panels: {
55
+ open: null,
56
+ pages: {},
57
+ held: null,
58
+ barShown: false,
59
+ footHere: false,
60
+ sortFilter: props.sortFilter ?? "right",
61
+ bar: props.bar ?? "added",
62
+ },
63
+ selection: { ids: [], all: false, count: 0 },
64
+ views: null,
65
+ };
66
+ let state = { ...data, ...actions };
67
+ function swap(next) {
68
+ state = { ...state, ...next };
69
+ }
70
+ function write(next) {
71
+ swap(next);
72
+ for (const listener of [...listeners])
73
+ listener();
74
+ }
75
+ return {
76
+ get: () => state,
77
+ subscribe: (listener) => {
78
+ listeners.add(listener);
79
+ return () => listeners.delete(listener);
80
+ },
81
+ sync: (next) => {
82
+ latest = next;
83
+ const changed = {};
84
+ const view = viewOf(next);
85
+ if (!sameKeys(state.view, view))
86
+ changed.view = view;
87
+ const panels = { sortFilter: next.sortFilter ?? "right", bar: next.bar ?? "added" };
88
+ if (!sameKeys(state.panels, panels))
89
+ changed.panels = { ...state.panels, ...panels };
90
+ if (Object.keys(changed).length === 0)
91
+ return;
92
+ swap(changed);
93
+ dirty = true;
94
+ },
95
+ flush: () => {
96
+ if (!dirty)
97
+ return;
98
+ dirty = false;
99
+ for (const listener of [...listeners])
100
+ listener();
101
+ },
102
+ patch: (patch) => {
103
+ const next = {};
104
+ if (patch.panels && !sameKeys(state.panels, patch.panels))
105
+ next.panels = { ...state.panels, ...patch.panels };
106
+ if (patch.views !== undefined && !Object.is(state.views, patch.views))
107
+ next.views = patch.views;
108
+ if (Object.keys(next).length > 0)
109
+ write(next);
110
+ },
111
+ wire: (handlers) => {
112
+ wired = { ...wired, ...handlers };
113
+ },
114
+ };
115
+ }
@@ -0,0 +1,6 @@
1
+ import { type ReactNode } from "react";
2
+ import type { ReadyToolbarProps } from "../panels/react/toolbar/ReadyToolbar.js";
3
+ /** `ReadyToolbar`'s props but those the root holds: the settings and the layer with their callbacks, the shared view,
4
+ * `sortFilter` and `bar`. */
5
+ export type ListToolbarProps<Row> = Omit<ReadyToolbarProps<Row>, "settings" | "layer" | "onChange" | "onLayerChange" | "view" | "sortFilter" | "bar">;
6
+ export declare function ListToolbar<Row>(props: ListToolbarProps<Row>): ReactNode;