viewkitjs 0.31.0 → 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 (289) hide show
  1. package/CHANGELOG.md +129 -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 +5 -1
  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 +3 -3
  45. package/views/dist/controls/avatar/avatar.js +1 -1
  46. package/views/dist/controls/avatar/tokens.d.ts +44 -0
  47. package/views/dist/controls/avatar/tokens.js +11 -0
  48. package/views/dist/controls/avatar.css +22 -5
  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 +2 -1
  63. package/views/dist/controls/index.js +2 -1
  64. package/views/dist/controls/input/input.js +5 -2
  65. package/views/dist/controls/input/tokens.d.ts +4 -0
  66. package/views/dist/controls/input/tokens.js +1 -0
  67. package/views/dist/controls/input.css +31 -3
  68. package/views/dist/controls/internal/icons.js +10 -0
  69. package/views/dist/controls/internal/keep-focus.d.ts +2 -0
  70. package/views/dist/controls/internal/keep-focus.js +17 -0
  71. package/views/dist/controls/internal/watch-frame.d.ts +2 -0
  72. package/views/dist/controls/internal/watch-frame.js +33 -0
  73. package/views/dist/controls/markdown/map-markdown.d.ts +4 -0
  74. package/views/dist/controls/markdown/map-markdown.js +5 -0
  75. package/views/dist/controls/menu/map-menu.js +2 -2
  76. package/views/dist/controls/menu-list/menu-list.d.ts +3 -0
  77. package/views/dist/controls/menu-list/menu-list.js +5 -4
  78. package/views/dist/controls/modal/modal.js +5 -1
  79. package/views/dist/controls/pane/pane.js +2 -1
  80. package/views/dist/controls/phone-header/header-bar.d.ts +5 -1
  81. package/views/dist/controls/phone-header/header-bar.js +2 -2
  82. package/views/dist/controls/phone-header.css +11 -1
  83. package/views/dist/controls/picker/map-picker.js +3 -0
  84. package/views/dist/controls/picker/picker.d.ts +14 -0
  85. package/views/dist/controls/picker/picker.js +30 -10
  86. package/views/dist/controls/picker.css +2 -0
  87. package/views/dist/controls/popover/popover.js +2 -1
  88. package/views/dist/controls/radio/radio.d.ts +5 -3
  89. package/views/dist/controls/radio/radio.js +18 -2
  90. package/views/dist/controls/radio/tokens.d.ts +44 -0
  91. package/views/dist/controls/radio/tokens.js +11 -0
  92. package/views/dist/controls/radio.css +79 -1
  93. package/views/dist/controls/select/select.d.ts +4 -0
  94. package/views/dist/controls/select/select.js +11 -5
  95. package/views/dist/controls/select/tokens.d.ts +8 -0
  96. package/views/dist/controls/select/tokens.js +2 -0
  97. package/views/dist/controls/select.css +17 -0
  98. package/views/dist/controls/setting-row/looks.d.ts +1 -1
  99. package/views/dist/controls/setting-row/looks.js +9 -4
  100. package/views/dist/controls/setting-row/setting-row.d.ts +45 -10
  101. package/views/dist/controls/setting-row/setting-row.js +82 -15
  102. package/views/dist/controls/setting-row/tokens.d.ts +74 -2
  103. package/views/dist/controls/setting-row/tokens.js +19 -1
  104. package/views/dist/controls/setting-row.css +135 -14
  105. package/views/dist/controls/sheet/bottom-sheet.d.ts +10 -2
  106. package/views/dist/controls/sheet/bottom-sheet.js +6 -3
  107. package/views/dist/controls/sheet.css +4 -1
  108. package/views/dist/controls/sort-editor/sort-editor.js +3 -2
  109. package/views/dist/controls/sort-editor.css +8 -2
  110. package/views/dist/controls/switch-row/tokens.d.ts +0 -12
  111. package/views/dist/controls/switch-row/tokens.js +0 -3
  112. package/views/dist/controls/switch-row.css +3 -7
  113. package/views/dist/controls/switch.css +17 -7
  114. package/views/dist/controls/tag/tag.d.ts +3 -1
  115. package/views/dist/controls/tag/tag.js +2 -2
  116. package/views/dist/controls/tag/tokens.d.ts +4 -0
  117. package/views/dist/controls/tag/tokens.js +1 -0
  118. package/views/dist/controls/tag-field/tag-field.d.ts +5 -1
  119. package/views/dist/controls/tag-field/tag-field.js +11 -5
  120. package/views/dist/controls/tag-field/tokens.d.ts +16 -0
  121. package/views/dist/controls/tag-field/tokens.js +4 -0
  122. package/views/dist/controls/tag-field.css +19 -0
  123. package/views/dist/controls/tag.css +2 -0
  124. package/views/dist/controls/toolbar/toolbar.d.ts +15 -3
  125. package/views/dist/controls/toolbar/toolbar.js +22 -15
  126. package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +14 -0
  127. package/views/dist/controls/toolbar-button/atom-toolbar-button.js +51 -0
  128. package/views/dist/controls/toolbar-button/toolbar-button.d.ts +1 -1
  129. package/views/dist/controls/toolbar-button/toolbar-button.js +2 -3
  130. package/views/dist/controls/toolbar-button.css +4 -0
  131. package/views/dist/controls/toolbar.css +5 -0
  132. package/views/dist/controls/views-list/map-view-menu.d.ts +3 -0
  133. package/views/dist/controls/views-list/map-view-menu.js +25 -0
  134. package/views/dist/controls/views-list/map-views-list-body.d.ts +28 -1
  135. package/views/dist/controls/views-list/map-views-list-body.js +39 -21
  136. package/views/dist/controls/views-list/rules.d.ts +2 -0
  137. package/views/dist/controls/views-list/view-menu.d.ts +7 -0
  138. package/views/dist/controls/views-list/view-menu.js +28 -24
  139. package/views/dist/controls/views-list/words.d.ts +2 -0
  140. package/views/dist/controls/views-list/words.js +1 -1
  141. package/views/dist/editors/EditorPanel.js +2 -1
  142. package/views/dist/editors/edit-session.js +2 -5
  143. package/views/dist/field-row/FieldRow.d.ts +4 -2
  144. package/views/dist/field-row/FieldRow.js +67 -20
  145. package/views/dist/field-row/FieldRowLane.d.ts +7 -2
  146. package/views/dist/field-row/FieldRowLane.js +4 -3
  147. package/views/dist/field-row/editors/RowEditor.d.ts +12 -0
  148. package/views/dist/field-row/editors/RowEditor.js +31 -1
  149. package/views/dist/field-row/editors/RowValueListEditor.d.ts +5 -1
  150. package/views/dist/field-row/editors/RowValueListEditor.js +4 -1
  151. package/views/dist/field-row/field-row-button.d.ts +5 -0
  152. package/views/dist/field-row/field-row-button.js +2 -0
  153. package/views/dist/fields/binding.d.ts +3 -2
  154. package/views/dist/fields/binding.js +38 -5
  155. package/views/dist/grid/chrome/GridColumnMenu.d.ts +4 -2
  156. package/views/dist/grid/chrome/GridColumnMenu.js +3 -2
  157. package/views/dist/grid/chrome/GridGroupMenu.d.ts +4 -1
  158. package/views/dist/grid/chrome/GridGroupMenu.js +4 -3
  159. package/views/dist/grid/chrome/GridHeader.d.ts +4 -1
  160. package/views/dist/grid/chrome/GridHeader.js +2 -2
  161. package/views/dist/grid/chrome/GridRow.js +6 -5
  162. package/views/dist/grid/chrome/GridRowCells.js +6 -9
  163. package/views/dist/grid/chrome/GridStructure.d.ts +4 -1
  164. package/views/dist/grid/chrome/GridStructure.js +4 -4
  165. package/views/dist/grid/chrome/GridTable.js +5 -2
  166. package/views/dist/grid/chrome/grid-column-menu-items.js +1 -1
  167. package/views/dist/grid/chrome/grid-row-menu-items.d.ts +27 -3
  168. package/views/dist/grid/chrome/grid-row-menu-items.js +92 -6
  169. package/views/dist/grid/chrome/grid-row-props.d.ts +7 -2
  170. package/views/dist/grid/chrome/grid-rows-menu.js +34 -6
  171. package/views/dist/grid/chrome/grid-table-props.d.ts +38 -7
  172. package/views/dist/grid/chrome/useGridBatchApi.d.ts +3 -1
  173. package/views/dist/grid/chrome/useGridBatchApi.js +4 -2
  174. package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -2
  175. package/views/dist/grid/chrome/useGridKeyboard.js +15 -9
  176. package/views/dist/grid/chrome/useGridPendingReconciliation.js +1 -2
  177. package/views/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -1
  178. package/views/dist/grid/chrome/useGridTableInteractionModel.js +11 -5
  179. package/views/dist/grid/core/commit-model.d.ts +20 -2
  180. package/views/dist/grid/core/editing-controller.d.ts +18 -0
  181. package/views/dist/grid/core/editing-controller.js +188 -42
  182. package/views/dist/grid/core/editing-model.d.ts +3 -0
  183. package/views/dist/grid/core/editing-model.js +3 -0
  184. package/views/dist/grid/core/save-path.d.ts +24 -0
  185. package/views/dist/grid/core/save-path.js +122 -0
  186. package/views/dist/grid/core/spreadsheet-operations.d.ts +3 -0
  187. package/views/dist/grid/core/spreadsheet-operations.js +23 -0
  188. package/views/dist/grid/index.d.ts +3 -2
  189. package/views/dist/grid/index.js +1 -0
  190. package/views/dist/internal/field-rows.d.ts +26 -0
  191. package/views/dist/internal/field-rows.js +8 -0
  192. package/views/dist/internal/page-close.d.ts +7 -0
  193. package/views/dist/internal/page-close.js +43 -0
  194. package/views/dist/list/browser-views-store.d.ts +10 -0
  195. package/views/dist/list/browser-views-store.js +182 -0
  196. package/views/dist/list/index.d.ts +23 -0
  197. package/views/dist/list/index.js +8 -0
  198. package/views/dist/list/menu.d.ts +31 -0
  199. package/views/dist/list/menu.js +76 -0
  200. package/views/dist/list/parts.d.ts +6 -0
  201. package/views/dist/list/parts.js +59 -0
  202. package/views/dist/list/registry.d.ts +11 -0
  203. package/views/dist/list/registry.js +31 -0
  204. package/views/dist/list/root.d.ts +40 -0
  205. package/views/dist/list/root.js +128 -0
  206. package/views/dist/list/slot.d.ts +14 -0
  207. package/views/dist/list/slot.js +22 -0
  208. package/views/dist/list/source.d.ts +11 -0
  209. package/views/dist/list/source.js +31 -0
  210. package/views/dist/list/store.d.ts +87 -0
  211. package/views/dist/list/store.js +115 -0
  212. package/views/dist/list/toolbar.d.ts +6 -0
  213. package/views/dist/list/toolbar.js +359 -0
  214. package/views/dist/list/views-axis.d.ts +5 -0
  215. package/views/dist/list/views-axis.js +96 -0
  216. package/views/dist/list/views-store.d.ts +41 -0
  217. package/views/dist/list/views-store.js +1 -0
  218. package/views/dist/list/views.d.ts +67 -0
  219. package/views/dist/list/views.js +400 -0
  220. package/views/dist/model/preferences.js +1 -1
  221. package/views/dist/model/prefs-buckets.js +1 -1
  222. package/views/dist/panels/index.d.ts +3 -1
  223. package/views/dist/panels/index.js +1 -0
  224. package/views/dist/panels/react/customize-body.js +1 -0
  225. package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +41 -4
  226. package/views/dist/panels/react/toolbar/ReadyToolbar.js +6 -326
  227. package/views/dist/panels/react/toolbar/Toolbar.d.ts +9 -1
  228. package/views/dist/panels/react/toolbar/Toolbar.js +34 -23
  229. package/views/dist/panels/react/toolbar/ToolbarButton.js +4 -1
  230. package/views/dist/panels/react/toolbar/ToolbarNew.js +1 -1
  231. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +2 -2
  232. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +3 -1
  233. package/views/dist/panels/react/toolbar/ToolbarSearch.js +1 -1
  234. package/views/dist/panels/react/toolbar/context.d.ts +10 -2
  235. package/views/dist/panels/react/toolbar/context.js +3 -1
  236. package/views/dist/panels/react/views-row/FoldingViewRow.d.ts +1 -1
  237. package/views/dist/panels/react/views-row/FoldingViewRow.js +15 -4
  238. package/views/dist/panels/react/views-row/PillGroup.d.ts +5 -2
  239. package/views/dist/panels/react/views-row/PillGroup.js +16 -7
  240. package/views/dist/panels/react/views-row/ViewPicker.js +2 -12
  241. package/views/dist/panels/react/views-row/ViewPickerRow.d.ts +4 -2
  242. package/views/dist/panels/react/views-row/ViewPickerRow.js +9 -5
  243. package/views/dist/panels/react.d.ts +2 -2
  244. package/views/dist/panels/toolbar/edit-view.d.ts +7 -1
  245. package/views/dist/panels/toolbar/edit-view.js +14 -0
  246. package/views/dist/panels/toolbar/model.d.ts +5 -0
  247. package/views/dist/panels/toolbar/model.js +7 -3
  248. package/views/dist/panels/view-state.d.ts +5 -3
  249. package/views/dist/panels/views-row/model.d.ts +19 -2
  250. package/views/dist/panels/views-row/model.js +14 -0
  251. package/views/dist/provider/ViewsProvider.d.ts +16 -7
  252. package/views/dist/provider/ViewsProvider.js +23 -5
  253. package/views/dist/provider/components.d.ts +43 -2
  254. package/views/dist/provider/context.d.ts +2 -1
  255. package/views/dist/provider/context.js +1 -1
  256. package/views/dist/provider/ports.d.ts +19 -12
  257. package/views/dist/provider/ports.js +69 -1
  258. package/views/dist/react.d.ts +1 -1
  259. package/views/dist/styles.css +418 -59
  260. package/views/dist/styles.unlayered.css +418 -59
  261. package/views/docs/contract.md +42 -31
  262. package/views/docs/controls/avatar.md +11 -0
  263. package/views/docs/controls/choice.md +0 -1
  264. package/views/docs/controls/field.md +3 -0
  265. package/views/docs/controls/input.md +1 -0
  266. package/views/docs/controls/radio.md +16 -1
  267. package/views/docs/controls/select.md +2 -0
  268. package/views/docs/controls/setting-row.md +18 -0
  269. package/views/docs/controls/switch-row.md +0 -3
  270. package/views/docs/controls/tag-field.md +4 -0
  271. package/views/docs/controls/tag.md +1 -0
  272. package/views/docs/getting-started.md +2 -2
  273. package/views/docs/guides/atoms.md +2 -2
  274. package/views/docs/guides/columns.md +1 -1
  275. package/views/docs/guides/ports.md +1 -1
  276. package/views/docs/guides/the-grid.md +34 -7
  277. package/views/docs/guides/the-provider.md +4 -2
  278. package/views/docs/index.md +1 -0
  279. package/views/docs/reference/controls.md +35 -25
  280. package/views/docs/reference/editors-session.md +1 -1
  281. package/views/docs/reference/field-row.md +9 -1
  282. package/views/docs/reference/grid.md +14 -8
  283. package/views/docs/reference/list.md +227 -0
  284. package/views/docs/reference/looks.md +1 -1
  285. package/views/docs/reference/panels-react.md +17 -12
  286. package/views/docs/reference/panels.md +8 -5
  287. package/views/docs/reference/react.md +11 -9
  288. package/views/docs/reference/views.md +2 -2
  289. package/views/skills/views/SKILL.md +9 -6
@@ -0,0 +1,43 @@
1
+ let closing = false;
2
+ let listening = false;
3
+ const flushes = { drafts: [], sends: [] };
4
+ function onHide() {
5
+ closing = true;
6
+ for (const phase of ["drafts", "sends"]) {
7
+ for (const flush of [...flushes[phase]]) {
8
+ try {
9
+ flush();
10
+ }
11
+ catch (error) {
12
+ queueMicrotask(() => {
13
+ throw error;
14
+ });
15
+ }
16
+ }
17
+ }
18
+ }
19
+ function onShow() {
20
+ closing = false;
21
+ }
22
+ function listen() {
23
+ if (listening || typeof window === "undefined")
24
+ return;
25
+ listening = true;
26
+ window.addEventListener("pagehide", onHide, { capture: true });
27
+ window.addEventListener("pageshow", onShow, { capture: true });
28
+ }
29
+ export function isPageClosing() {
30
+ listen();
31
+ return closing;
32
+ }
33
+ export function onPageClose(flush, phase = "sends") {
34
+ listen();
35
+ if (typeof window === "undefined")
36
+ return () => { };
37
+ flushes[phase].push(flush);
38
+ return () => {
39
+ const at = flushes[phase].indexOf(flush);
40
+ if (at >= 0)
41
+ flushes[phase].splice(at, 1);
42
+ };
43
+ }
@@ -0,0 +1,10 @@
1
+ import type { ViewSeed, ViewsStore } from "./views-store.js";
2
+ export type BrowserViewsStoreOptions = {
3
+ /** The entries' prefix: a list's entry is `${key}:${listId}`. Default "vk:views". */
4
+ key?: string;
5
+ /** The app's own views, by list id: listed first, shared, read-only. */
6
+ seed?: Readonly<Record<string, readonly ViewSeed[]>>;
7
+ /** Where it keeps them; default `window.localStorage` where there is one. `null`: in memory, for the page's life. */
8
+ storage?: Pick<Storage, "getItem" | "setItem"> | null;
9
+ };
10
+ export declare function browserViewsStore(options?: BrowserViewsStoreOptions): ViewsStore;
@@ -0,0 +1,182 @@
1
+ import { listPersonalLayerSchema, listSettingsChangeSchema, savedViewSchema, settingsForSaving, } from "viewkitjs/fields/query";
2
+ const EPOCH = "1970-01-01T00:00:00.000Z";
3
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
+ function readEntry(raw) {
5
+ const entry = { views: [], drafts: {}, layer: {} };
6
+ if (!raw)
7
+ return entry;
8
+ let held;
9
+ try {
10
+ held = JSON.parse(raw);
11
+ }
12
+ catch {
13
+ return entry;
14
+ }
15
+ if (!isObject(held) || held.v !== 1)
16
+ return entry;
17
+ if (Array.isArray(held.views)) {
18
+ for (const view of held.views) {
19
+ const read = savedViewSchema.safeParse(view);
20
+ if (read.success && read.data.scope === "personal" && !read.data.readOnly)
21
+ entry.views.push(read.data);
22
+ }
23
+ }
24
+ if (isObject(held.drafts)) {
25
+ for (const [id, draft] of Object.entries(held.drafts)) {
26
+ if (!isObject(draft) || typeof draft.base !== "string")
27
+ continue;
28
+ const change = listSettingsChangeSchema.safeParse(draft.change);
29
+ if (!change.success)
30
+ continue;
31
+ const { search: _search, ...kept } = change.data;
32
+ entry.drafts[id] = { change: kept, base: draft.base };
33
+ }
34
+ }
35
+ const layer = listPersonalLayerSchema.safeParse(held.layer);
36
+ if (layer.success)
37
+ entry.layer = layer.data;
38
+ return entry;
39
+ }
40
+ function refused(what, error) {
41
+ const issue = error.issues[0];
42
+ const where = issue?.path.length ? ` (${issue.path.map(String).join(".")})` : "";
43
+ return new Error(`${what}: ${issue?.message ?? "it doesn't read"}${where}`);
44
+ }
45
+ function defaultStorage() {
46
+ try {
47
+ return typeof window === "undefined" ? null : window.localStorage;
48
+ }
49
+ catch {
50
+ return null;
51
+ }
52
+ }
53
+ export function browserViewsStore(options = {}) {
54
+ const prefix = options.key ?? "vk:views";
55
+ const storage = options.storage === undefined ? defaultStorage() : options.storage;
56
+ const kept = new Map();
57
+ const readers = new Map();
58
+ const keyOf = (listId) => `${prefix}:${listId}`;
59
+ const raw = (key) => {
60
+ if (kept.has(key))
61
+ return kept.get(key);
62
+ try {
63
+ return storage?.getItem(key) ?? null;
64
+ }
65
+ catch {
66
+ return null;
67
+ }
68
+ };
69
+ const read = (listId) => readEntry(raw(keyOf(listId)));
70
+ const write = (listId, entry) => {
71
+ const key = keyOf(listId);
72
+ const text = JSON.stringify({ v: 1, ...entry });
73
+ try {
74
+ if (!storage)
75
+ throw new Error("no storage");
76
+ storage.setItem(key, text);
77
+ kept.delete(key);
78
+ }
79
+ catch {
80
+ kept.set(key, text);
81
+ }
82
+ for (const reader of [...(readers.get(listId) ?? [])])
83
+ reader();
84
+ };
85
+ const seedsOf = (listId) => (options.seed?.[listId] ?? []).map((seed, position) => ({
86
+ id: seed.id,
87
+ name: seed.name,
88
+ scope: "shared",
89
+ settings: settingsForSaving(seed.settings),
90
+ position,
91
+ updatedAt: EPOCH,
92
+ readOnly: true,
93
+ }));
94
+ const byPosition = (a, b) => a.position - b.position;
95
+ return {
96
+ list: (listId) => [...seedsOf(listId), ...read(listId).views.sort(byPosition)],
97
+ save: (listId, view) => {
98
+ if (view.scope !== "personal")
99
+ throw new Error("the browser store keeps only a person's own views");
100
+ if (view.id !== undefined && seedsOf(listId).some((seed) => seed.id === view.id)) {
101
+ throw new Error(`${view.id} is declared by the app and can't be changed`);
102
+ }
103
+ const entry = read(listId);
104
+ const was = view.id === undefined ? undefined : entry.views.find((held) => held.id === view.id);
105
+ const last = entry.views.reduce((most, held) => Math.max(most, held.position), -1);
106
+ let stamp = Date.now();
107
+ if (was && stamp <= Date.parse(was.updatedAt))
108
+ stamp = Date.parse(was.updatedAt) + 1;
109
+ const checked = savedViewSchema.safeParse({
110
+ id: view.id ?? globalThis.crypto.randomUUID(),
111
+ name: view.name,
112
+ scope: "personal",
113
+ settings: settingsForSaving(view.settings),
114
+ position: view.id !== undefined ? view.position : last + 1,
115
+ updatedAt: new Date(stamp).toISOString(),
116
+ });
117
+ if (!checked.success)
118
+ throw refused("This view can't be saved", checked.error);
119
+ const saved = checked.data;
120
+ entry.views = was ? entry.views.map((held) => (held.id === saved.id ? saved : held)) : [...entry.views, saved];
121
+ write(listId, entry);
122
+ return saved;
123
+ },
124
+ remove: (listId, id) => {
125
+ const entry = read(listId);
126
+ entry.views = entry.views.filter((held) => held.id !== id);
127
+ delete entry.drafts[id];
128
+ write(listId, entry);
129
+ },
130
+ reorder: (listId, scope, ids) => {
131
+ if (scope !== "personal")
132
+ return;
133
+ const entry = read(listId);
134
+ entry.views = entry.views.map((held) => (ids.includes(held.id) ? { ...held, position: ids.indexOf(held.id) } : held));
135
+ write(listId, entry);
136
+ },
137
+ subscribe: (listId, onChange) => {
138
+ const own = readers.get(listId) ?? new Set();
139
+ readers.set(listId, own);
140
+ own.add(onChange);
141
+ const key = keyOf(listId);
142
+ const heard = (event) => {
143
+ if (event.key === null || event.key === key)
144
+ onChange();
145
+ };
146
+ if (typeof window !== "undefined")
147
+ window.addEventListener("storage", heard);
148
+ return () => {
149
+ own.delete(onChange);
150
+ if (typeof window !== "undefined")
151
+ window.removeEventListener("storage", heard);
152
+ };
153
+ },
154
+ draft: {
155
+ get: (listId, viewId) => read(listId).drafts[viewId] ?? null,
156
+ set: (listId, viewId, draft) => {
157
+ const entry = read(listId);
158
+ if (draft) {
159
+ const checked = listSettingsChangeSchema.safeParse(draft.change);
160
+ if (!checked.success)
161
+ throw refused("This change can't be kept", checked.error);
162
+ const { search: _search, ...change } = checked.data;
163
+ entry.drafts[viewId] = { change, base: draft.base };
164
+ }
165
+ else
166
+ delete entry.drafts[viewId];
167
+ write(listId, entry);
168
+ },
169
+ },
170
+ layer: {
171
+ get: (listId) => read(listId).layer,
172
+ set: (listId, layer) => {
173
+ const checked = listPersonalLayerSchema.safeParse(layer);
174
+ if (!checked.success)
175
+ throw refused("These widths and folds can't be kept", checked.error);
176
+ const entry = read(listId);
177
+ entry.layer = checked.data;
178
+ write(listId, entry);
179
+ },
180
+ },
181
+ };
182
+ }
@@ -0,0 +1,23 @@
1
+ export { browserViewsStore } from "./browser-views-store.js";
2
+ export type { BrowserViewsStoreOptions } from "./browser-views-store.js";
3
+ export { fetchSource } from "./source.js";
4
+ export { ListRoot } from "./root.js";
5
+ export { ListFill } from "./slot.js";
6
+ export type { ListFillProps } from "./slot.js";
7
+ export type { ListMenus } from "./menu.js";
8
+ export type { ListRootProps } from "./root.js";
9
+ export { ListSlot } from "./slot.js";
10
+ export type { ListSlotProps } from "./slot.js";
11
+ export type { ListSource } from "./source.js";
12
+ export type { ListState } from "./store.js";
13
+ export { ListToolbar } from "./toolbar.js";
14
+ export type { ListToolbarProps } from "./toolbar.js";
15
+ export { menu } from "./menu.js";
16
+ export type { MenuPlace } from "./menu.js";
17
+ export type { ListViewsOptions } from "./root.js";
18
+ export type { ListViewsState } from "./views.js";
19
+ export type { SavedViewInput } from "./views-store.js";
20
+ export { useList } from "./root.js";
21
+ export type { ViewDraft } from "./views-store.js";
22
+ export type { ViewSeed } from "./views-store.js";
23
+ export type { ViewsStore } from "./views-store.js";
@@ -0,0 +1,8 @@
1
+ export { browserViewsStore } from "./browser-views-store.js";
2
+ export { fetchSource } from "./source.js";
3
+ export { ListRoot } from "./root.js";
4
+ export { ListFill } from "./slot.js";
5
+ export { ListSlot } from "./slot.js";
6
+ export { ListToolbar } from "./toolbar.js";
7
+ export { menu } from "./menu.js";
8
+ export { useList } from "./root.js";
@@ -0,0 +1,31 @@
1
+ import type { GridMenus } from "../grid/chrome/grid-table-props.js";
2
+ import type { ToolbarMenus } from "../panels/react/toolbar/ReadyToolbar.js";
3
+ import type { ViewsMenuItem } from "../provider/components.js";
4
+ /** Every menu of a list as data: the grid's (`column`, `row`, `group`, which `GridTable` takes as `menus`) and the toolbar's
5
+ * (`view`, `add`, `more`, which `ReadyToolbar` and `ListToolbar` take as `menus`). Each is handed its default items and hands
6
+ * back the items it shows; a menu with no function is as ViewKit draws it. */
7
+ export type ListMenus<Row> = GridMenus<Row> & ToolbarMenus;
8
+ /** Where a row goes: right after the row of that key, or right before it. */
9
+ export type MenuPlace = {
10
+ after: string;
11
+ } | {
12
+ before: string;
13
+ };
14
+ /** What the helpers reshape: a keyed row, perhaps opening a block, perhaps holding rows of its own. */
15
+ type Keyed<T> = {
16
+ key: string;
17
+ separatorBefore?: boolean;
18
+ children?: T[];
19
+ };
20
+ declare function drop<T extends Keyed<T>>(items: T[], ...keys: string[]): T[];
21
+ declare function rename(items: ViewsMenuItem[], key: string, label: string): ViewsMenuItem[];
22
+ declare function add<T extends Keyed<T>>(items: T[], item: T, place?: MenuPlace): T[];
23
+ declare function move<T extends Keyed<T>>(items: T[], key: string, place: MenuPlace): T[];
24
+ /** The four changes an app's menu function makes to the items it is handed. */
25
+ export declare const menu: {
26
+ drop: typeof drop;
27
+ rename: typeof rename;
28
+ add: typeof add;
29
+ move: typeof move;
30
+ };
31
+ export {};
@@ -0,0 +1,76 @@
1
+ const bare = (item) => {
2
+ if (!item.separatorBefore)
3
+ return item;
4
+ const { separatorBefore: _, ...rest } = item;
5
+ return rest;
6
+ };
7
+ const lead = (items) => (items[0]?.separatorBefore ? [bare(items[0]), ...items.slice(1)] : items);
8
+ function inList(items, key, edit) {
9
+ const at = items.findIndex((item) => item.key === key);
10
+ if (at >= 0)
11
+ return edit(items, at);
12
+ for (let i = 0; i < items.length; i++) {
13
+ const children = items[i].children;
14
+ const changed = children ? inList(children, key, edit) : null;
15
+ if (changed)
16
+ return [...items.slice(0, i), { ...items[i], children: changed }, ...items.slice(i + 1)];
17
+ }
18
+ return null;
19
+ }
20
+ const find = (items, key) => {
21
+ for (const item of items) {
22
+ if (item.key === key)
23
+ return item;
24
+ const inner = item.children && find(item.children, key);
25
+ if (inner)
26
+ return inner;
27
+ }
28
+ return undefined;
29
+ };
30
+ function drop(items, ...keys) {
31
+ const gone = new Set(keys);
32
+ const walk = (list) => {
33
+ const out = [];
34
+ let carry = false;
35
+ for (const item of list) {
36
+ if (gone.has(item.key)) {
37
+ carry ||= !!item.separatorBefore;
38
+ continue;
39
+ }
40
+ const children = item.children && walk(item.children);
41
+ if (item.children?.length && !children?.length) {
42
+ carry ||= !!item.separatorBefore;
43
+ continue;
44
+ }
45
+ let next = children ? { ...item, children } : item;
46
+ if (carry && !next.separatorBefore)
47
+ next = { ...next, separatorBefore: true };
48
+ carry = false;
49
+ out.push(next);
50
+ }
51
+ return lead(out);
52
+ };
53
+ return walk(items);
54
+ }
55
+ function rename(items, key, label) {
56
+ return inList(items, key, (list, at) => [...list.slice(0, at), { ...list[at], label }, ...list.slice(at + 1)]) ?? items;
57
+ }
58
+ function add(items, item, place) {
59
+ const placed = place &&
60
+ inList(items, "after" in place ? place.after : place.before, (list, at) => {
61
+ if ("after" in place)
62
+ return [...list.slice(0, at + 1), item, ...list.slice(at + 1)];
63
+ const anchor = list[at];
64
+ const taken = anchor.separatorBefore ? { ...item, separatorBefore: true } : bare(item);
65
+ return lead([...list.slice(0, at), taken, bare(anchor), ...list.slice(at + 1)]);
66
+ });
67
+ return placed ?? lead([...items, item]);
68
+ }
69
+ function move(items, key, place) {
70
+ const anchor = "after" in place ? place.after : place.before;
71
+ const item = find(items, key);
72
+ if (!item || anchor === key || !find(items, anchor) || find(item.children ?? [], anchor))
73
+ return items;
74
+ return add(drop(items, key), bare(item), place);
75
+ }
76
+ export const menu = { drop, rename, add, move };
@@ -0,0 +1,6 @@
1
+ import type { ToolbarPart } from "../panels/react/toolbar/Toolbar.js";
2
+ import type { ToolbarPartPlace, ToolbarParts, ToolbarPartsContext } from "../panels/react/toolbar/ReadyToolbar.js";
3
+ /** Each part's place, in the order the form draws them: the row's start and end, then the bar's (a kit phone's one line). */
4
+ export declare function placesOf(parts: readonly ToolbarPart[], ctx: ToolbarPartsContext): ToolbarPartPlace[];
5
+ /** The form's parts as the app's `toolbarParts` places them. */
6
+ export declare function applyParts(parts: readonly ToolbarPart[], place: ToolbarParts, ctx: ToolbarPartsContext): readonly ToolbarPart[];
@@ -0,0 +1,59 @@
1
+ import { arrangeToolbar } from "../panels/toolbar/model.js";
2
+ const kitPhone = (ctx) => ctx.arrangement === "kit" && ctx.phone;
3
+ const lineOf = (part) => ((part.line ?? 1) === 2 ? "bar" : "row");
4
+ export function placesOf(parts, ctx) {
5
+ const byKey = new Map(parts.map((part) => [part.key, part]));
6
+ const place = (part, line) => ({
7
+ key: part.key,
8
+ line,
9
+ side: part.side ?? "start",
10
+ words: part.words ?? "both",
11
+ });
12
+ if (kitPhone(ctx)) {
13
+ const [line] = arrangeToolbar(parts, "phone", { fold: true });
14
+ const slots = line ? [...line.start, ...line.end] : [];
15
+ return slots.flatMap((slot) => {
16
+ const part = byKey.get(slot.key);
17
+ return part ? [place(part, part.key === "new" && part.foot !== false ? "foot" : "row")] : [];
18
+ });
19
+ }
20
+ const drawn = (line, side) => parts.filter((part) => lineOf(part) === line && (part.side ?? "start") === side).map((part) => place(part, line));
21
+ return [...drawn("row", "start"), ...drawn("row", "end"), ...drawn("bar", "start"), ...drawn("bar", "end")];
22
+ }
23
+ const samePlaces = (a, b) => a.length === b.length &&
24
+ a.every((p, i) => p.key === b[i].key && p.line === b[i].line && p.side === b[i].side && p.words === b[i].words && p.node === undefined);
25
+ export function applyParts(parts, place, ctx) {
26
+ const given = placesOf(parts, ctx);
27
+ const back = place(given, ctx);
28
+ if (samePlaces(back, given))
29
+ return parts;
30
+ const byKey = new Map(parts.map((part) => [part.key, part]));
31
+ const seen = new Set();
32
+ const one = kitPhone(ctx);
33
+ return back.flatMap((at) => {
34
+ if (seen.has(at.key))
35
+ return [];
36
+ seen.add(at.key);
37
+ const part = byKey.get(at.key);
38
+ const line = !one && at.line === "bar" ? 2 : 1;
39
+ if (!part)
40
+ return at.node === undefined ? [] : [{ key: at.key, line, side: at.side, words: at.words, node: at.node }];
41
+ const own = part.words ?? "both";
42
+ const next = { ...part };
43
+ if (line !== (part.line ?? 1))
44
+ next.line = line;
45
+ if (at.side !== (part.side ?? "start"))
46
+ next.side = at.side;
47
+ if (at.words !== own)
48
+ next.words = at.words;
49
+ if (at.words === "both" && own === "icon" && !part.shed)
50
+ next.shed = true;
51
+ if (one && part.key === "new") {
52
+ if (at.line === "foot")
53
+ delete next.foot;
54
+ else
55
+ next.foot = false;
56
+ }
57
+ return [next];
58
+ });
59
+ }
@@ -0,0 +1,11 @@
1
+ import type { ListStore } from "./store.js";
2
+ export type ListRegistry = {
3
+ subscribe: (listener: () => void) => () => void;
4
+ store: (id: string) => ListStore | undefined;
5
+ addStore: (id: string, store: ListStore) => () => void;
6
+ slot: (name: string) => HTMLElement | undefined;
7
+ addSlot: (name: string, element: HTMLElement) => () => void;
8
+ };
9
+ export declare function createListRegistry(): ListRegistry;
10
+ /** The registry of the `ViewsProvider` around a part; null outside one. */
11
+ export declare const ListRegistryContext: import("react").Context<ListRegistry | null>;
@@ -0,0 +1,31 @@
1
+ import { createContext } from "react";
2
+ export function createListRegistry() {
3
+ const stores = new Map();
4
+ const slots = new Map();
5
+ const listeners = new Set();
6
+ const tell = () => {
7
+ for (const listener of [...listeners])
8
+ listener();
9
+ };
10
+ const add = (map) => (key, value) => {
11
+ map.set(key, value);
12
+ tell();
13
+ return () => {
14
+ if (map.get(key) !== value)
15
+ return;
16
+ map.delete(key);
17
+ tell();
18
+ };
19
+ };
20
+ return {
21
+ subscribe: (listener) => {
22
+ listeners.add(listener);
23
+ return () => listeners.delete(listener);
24
+ },
25
+ store: (id) => stores.get(id),
26
+ addStore: add(stores),
27
+ slot: (name) => slots.get(name),
28
+ addSlot: add(slots),
29
+ };
30
+ }
31
+ export const ListRegistryContext = createContext(null);
@@ -0,0 +1,40 @@
1
+ import { type ReactNode } from "react";
2
+ import type { ListLinkReading, ListSettings } from "viewkitjs/fields/query";
3
+ import type { ToolbarPanelState } from "../panels/react/toolbar/panel-state.js";
4
+ import { type ListState, type ListStore, type ListSync } from "./store.js";
5
+ import type { ViewSeed, ViewsStore } from "./views-store.js";
6
+ /** The root's saved views: a store, or the browser store with the app's own views for this list. */
7
+ export type ListViewsOptions = {
8
+ store?: ViewsStore;
9
+ /** The app's own views for this list, on the browser store (ignored with `store`): listed first, shared, read-only. */
10
+ seed?: readonly ViewSeed[];
11
+ /** What the list holds, in the delete question's line ("deals"). Default "records". */
12
+ records?: string;
13
+ };
14
+ /** The list root's props: its id, and either its settings and layer as the app holds them (memory mode: what
15
+ * `useListSettingsState` returns, with the shared view), or no settings, and the root keeps them through a store. A
16
+ * root keeps the mode it mounted in. Either way, the toolbar's `sortFilter` and `bar`. */
17
+ export type ListRootProps = {
18
+ id: string;
19
+ children?: ReactNode;
20
+ } & (ListSync | {
21
+ settings?: undefined;
22
+ /** Where the list's saved views are kept: a store, or options; default `browserViewsStore()`. */
23
+ views?: ViewsStore | ListViewsOptions;
24
+ /** What a list with no saved view shows, and a new view's start. Default `LIST_SETTINGS_DEFAULTS`. */
25
+ defaults?: ListSettings;
26
+ /** The address's reading (`readListLink`) as the list opened: its view and change win over the draft. */
27
+ link?: ListLinkReading;
28
+ sortFilter?: ListSync["sortFilter"];
29
+ bar?: ListSync["bar"];
30
+ });
31
+ export declare function ListRoot({ id, children, ...props }: ListRootProps): ReactNode;
32
+ /** The store of the list root around this part (not on the door). */
33
+ export declare function useListStore(): ListStore;
34
+ /** What this part selects of its list's state: it re-renders only when that changes (by `equal`, `Object.is` by
35
+ * default). Select an action as it stands (`useList((s) => s.openPanel)`): actions never change. Handed an `id` first,
36
+ * it reads the root of that id from anywhere under the `ViewsProvider` (VK-740): `undefined` while none stands. */
37
+ export declare function useList<T>(select: (state: ListState) => T, equal?: (a: T, b: T) => boolean): T;
38
+ export declare function useList<T>(id: string, select: (state: ListState) => T, equal?: (a: T, b: T) => boolean): T | undefined;
39
+ /** One of the root's panels as a part's open state and page, by its key (not on the door). */
40
+ export declare function useListPanel(key: string): ToolbarPanelState;
@@ -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
+ }