viewkitjs 0.37.0 → 0.39.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 (220) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/MIGRATION.md +7 -0
  3. package/fields/dist/query/figure-kinds.d.ts +2 -2
  4. package/fields/dist/query/figure-kinds.js +3 -0
  5. package/fields/dist/query/figures.d.ts +5 -3
  6. package/fields/dist/query/figures.js +13 -0
  7. package/fields/docs/reference/query.md +3 -3
  8. package/package.json +1 -1
  9. package/postgres/docs/guides/field-map.md +1 -1
  10. package/views/dist/atoms/HeaderChrome.d.ts +7 -0
  11. package/views/dist/atoms/HeaderChrome.js +15 -0
  12. package/views/dist/atoms/ToolbarButton.d.ts +1 -1
  13. package/views/dist/atoms/ToolbarButton.js +2 -2
  14. package/views/dist/atoms/defaults.js +4 -0
  15. package/views/dist/atoms/types.d.ts +39 -2
  16. package/views/dist/contract.d.ts +25 -11
  17. package/views/dist/contract.js +41 -6
  18. package/views/dist/controls/field/looks.d.ts +1 -1
  19. package/views/dist/controls/field/looks.js +9 -3
  20. package/views/dist/controls/field/tokens.d.ts +4 -0
  21. package/views/dist/controls/field/tokens.js +1 -0
  22. package/views/dist/controls/field.css +93 -1
  23. package/views/dist/controls/filter-editor/block.d.ts +3 -1
  24. package/views/dist/controls/filter-editor/block.js +4 -3
  25. package/views/dist/controls/filter-editor/filter-editor.d.ts +13 -2
  26. package/views/dist/controls/filter-editor/filter-editor.js +45 -15
  27. package/views/dist/controls/filter-editor/how.d.ts +3 -1
  28. package/views/dist/controls/filter-editor/map-filter-body.js +5 -4
  29. package/views/dist/controls/filter-editor/map-rules.d.ts +2 -1
  30. package/views/dist/controls/filter-editor/map-rules.js +3 -3
  31. package/views/dist/controls/glyphs/glyphs.js +2 -0
  32. package/views/dist/controls/inline-input.css +3 -2
  33. package/views/dist/controls/internal/menu-items.d.ts +2 -0
  34. package/views/dist/controls/internal/menu-items.js +1 -1
  35. package/views/dist/controls/internal/part-slot.d.ts +1 -1
  36. package/views/dist/controls/internal/part-slot.js +1 -1
  37. package/views/dist/controls/internal/read-token.d.ts +2 -1
  38. package/views/dist/controls/internal/read-token.js +2 -1
  39. package/views/dist/controls/internal/row-actions.d.ts +33 -0
  40. package/views/dist/controls/internal/row-actions.js +28 -0
  41. package/views/dist/controls/menu/map-menu.js +1 -1
  42. package/views/dist/controls/number-editor/tokens.d.ts +8 -0
  43. package/views/dist/controls/number-editor/tokens.js +2 -0
  44. package/views/dist/controls/number-editor.css +20 -0
  45. package/views/dist/controls/popover/map-popover.d.ts +1 -1
  46. package/views/dist/controls/popover/map-popover.js +2 -2
  47. package/views/dist/controls/sheet/map-sheet.js +9 -6
  48. package/views/dist/controls/sort-editor/map-sort-body.js +1 -0
  49. package/views/dist/controls/sort-editor/sort-editor.d.ts +5 -1
  50. package/views/dist/controls/sort-editor/sort-editor.js +41 -13
  51. package/views/dist/controls/text-editor/tokens.d.ts +8 -0
  52. package/views/dist/controls/text-editor/tokens.js +2 -0
  53. package/views/dist/controls/text-editor.css +44 -2
  54. package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +1 -1
  55. package/views/dist/controls/toolbar-button/atom-toolbar-button.js +2 -2
  56. package/views/dist/controls/tooltip/tooltip.js +2 -1
  57. package/views/dist/editors/EditorPanel.js +1 -1
  58. package/views/dist/field-row/FieldRow.js +46 -15
  59. package/views/dist/field-row/editors/RowChipsEditor.js +3 -1
  60. package/views/dist/field-row/editors/RowDateEditor.js +3 -1
  61. package/views/dist/field-row/editors/RowNameEditor.js +3 -1
  62. package/views/dist/field-row/editors/RowPlaceEditor.js +4 -2
  63. package/views/dist/field-row/editors/RowRangeEditor.js +3 -1
  64. package/views/dist/field-row/editors/RowRelationEditor.js +5 -2
  65. package/views/dist/field-row/editors/RowSelectEditor.js +3 -1
  66. package/views/dist/field-row/editors/RowTextEditor.d.ts +7 -1
  67. package/views/dist/field-row/editors/RowTextEditor.js +25 -4
  68. package/views/dist/field-row/editors/RowValueListEditor.js +4 -4
  69. package/views/dist/field-row/editors/row-place.d.ts +33 -0
  70. package/views/dist/field-row/editors/row-place.js +141 -0
  71. package/views/dist/field-row/field-row-button.d.ts +21 -6
  72. package/views/dist/field-row/field-row-button.js +8 -3
  73. package/views/dist/field-row/row-target.d.ts +4 -1
  74. package/views/dist/field-row/row-target.js +1 -1
  75. package/views/dist/fields/binding.d.ts +4 -0
  76. package/views/dist/grid/chrome/GridAggregateMenu.d.ts +12 -11
  77. package/views/dist/grid/chrome/GridAggregateMenu.js +4 -3
  78. package/views/dist/grid/chrome/GridCellEditors.d.ts +1 -1
  79. package/views/dist/grid/chrome/GridCellOutline.d.ts +13 -1
  80. package/views/dist/grid/chrome/GridCellOutline.js +17 -0
  81. package/views/dist/grid/chrome/GridFooter.d.ts +12 -4
  82. package/views/dist/grid/chrome/GridFooter.js +11 -9
  83. package/views/dist/grid/chrome/GridHeader.js +4 -3
  84. package/views/dist/grid/chrome/GridNumberEditor.js +2 -1
  85. package/views/dist/grid/chrome/GridResizeHandle.d.ts +7 -3
  86. package/views/dist/grid/chrome/GridResizeHandle.js +2 -3
  87. package/views/dist/grid/chrome/GridRowCells.js +1 -1
  88. package/views/dist/grid/chrome/GridStructure.js +3 -3
  89. package/views/dist/grid/chrome/GridTable.js +1 -1
  90. package/views/dist/grid/chrome/GridTableSurface.js +1 -1
  91. package/views/dist/grid/chrome/GridTextEditor.js +3 -1
  92. package/views/dist/grid/chrome/grid-body-place.d.ts +2 -4
  93. package/views/dist/grid/chrome/grid-body-place.js +4 -4
  94. package/views/dist/grid/chrome/grid-edit-session.d.ts +7 -3
  95. package/views/dist/grid/chrome/grid-edit-session.js +12 -3
  96. package/views/dist/grid/chrome/grid-editor-layer.d.ts +5 -4
  97. package/views/dist/grid/chrome/grid-figure-value.js +10 -4
  98. package/views/dist/grid/chrome/grid-row-props.d.ts +1 -1
  99. package/views/dist/grid/chrome/grid-table-props.d.ts +11 -3
  100. package/views/dist/grid/chrome/useGridKeyboard.d.ts +5 -1
  101. package/views/dist/grid/chrome/useGridKeyboard.js +9 -5
  102. package/views/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -1
  103. package/views/dist/grid/chrome/useGridTableInteractionModel.js +8 -3
  104. package/views/dist/grid/grid.css +7 -3
  105. package/views/dist/internal/length.d.ts +2 -0
  106. package/views/dist/internal/length.js +16 -0
  107. package/views/dist/internal/over-cell.d.ts +8 -0
  108. package/views/dist/internal/over-cell.js +5 -0
  109. package/views/dist/list/bar-keys.d.ts +5 -0
  110. package/views/dist/list/bar-keys.js +2 -0
  111. package/views/dist/list/bar-parts.d.ts +27 -0
  112. package/views/dist/list/bar-parts.js +38 -0
  113. package/views/dist/list/buttons/clear-save.d.ts +7 -0
  114. package/views/dist/list/buttons/clear-save.js +15 -0
  115. package/views/dist/list/buttons/customize.d.ts +28 -0
  116. package/views/dist/list/buttons/customize.js +31 -0
  117. package/views/dist/list/buttons/filter.d.ts +32 -0
  118. package/views/dist/list/buttons/filter.js +60 -0
  119. package/views/dist/list/buttons/new.d.ts +18 -0
  120. package/views/dist/list/buttons/new.js +9 -0
  121. package/views/dist/list/buttons/quick.d.ts +15 -0
  122. package/views/dist/list/buttons/quick.js +24 -0
  123. package/views/dist/list/buttons/search.d.ts +18 -0
  124. package/views/dist/list/buttons/search.js +17 -0
  125. package/views/dist/list/buttons/shared.d.ts +91 -0
  126. package/views/dist/list/buttons/shared.js +131 -0
  127. package/views/dist/list/buttons/sort-filter.d.ts +6 -0
  128. package/views/dist/list/buttons/sort-filter.js +16 -0
  129. package/views/dist/list/buttons/sort.d.ts +17 -0
  130. package/views/dist/list/buttons/sort.js +34 -0
  131. package/views/dist/list/buttons/views.d.ts +21 -0
  132. package/views/dist/list/buttons/views.js +36 -0
  133. package/views/dist/list/editor-menus.d.ts +13 -0
  134. package/views/dist/list/editor-menus.js +13 -0
  135. package/views/dist/list/index.d.ts +41 -0
  136. package/views/dist/list/index.js +19 -0
  137. package/views/dist/list/line.d.ts +55 -0
  138. package/views/dist/list/line.js +221 -0
  139. package/views/dist/list/pane-box.d.ts +6 -0
  140. package/views/dist/list/pane-box.js +15 -0
  141. package/views/dist/list/panels/customize.d.ts +8 -0
  142. package/views/dist/list/panels/customize.js +23 -0
  143. package/views/dist/list/panels/filter-bar.d.ts +12 -0
  144. package/views/dist/list/panels/filter-bar.js +67 -0
  145. package/views/dist/list/panels/filter.d.ts +8 -0
  146. package/views/dist/list/panels/filter.js +23 -0
  147. package/views/dist/list/panels/quick.d.ts +7 -0
  148. package/views/dist/list/panels/quick.js +16 -0
  149. package/views/dist/list/panels/shared.d.ts +25 -0
  150. package/views/dist/list/panels/shared.js +33 -0
  151. package/views/dist/list/panels/sort.d.ts +8 -0
  152. package/views/dist/list/panels/sort.js +19 -0
  153. package/views/dist/list/panels/views.d.ts +13 -0
  154. package/views/dist/list/panels/views.js +27 -0
  155. package/views/dist/list/ready.d.ts +35 -0
  156. package/views/dist/list/ready.js +7 -0
  157. package/views/dist/list/root-base.d.ts +17 -0
  158. package/views/dist/list/root-base.js +9 -1
  159. package/views/dist/list/root.js +2 -2
  160. package/views/dist/list/store.d.ts +19 -0
  161. package/views/dist/list/store.js +40 -1
  162. package/views/dist/list/toolbar-model.d.ts +95 -0
  163. package/views/dist/list/toolbar-model.js +177 -0
  164. package/views/dist/list/toolbar.js +140 -328
  165. package/views/dist/list/views-axis.js +15 -4
  166. package/views/dist/model/aggregates.d.ts +18 -8
  167. package/views/dist/model/aggregates.js +16 -22
  168. package/views/dist/panels/react/filter/FilterEditor.d.ts +3 -1
  169. package/views/dist/panels/react/filter/FilterEditor.js +2 -2
  170. package/views/dist/panels/react/filter/filter-body.d.ts +3 -1
  171. package/views/dist/panels/react/filter/filter-body.js +2 -2
  172. package/views/dist/panels/react/sort/SortEditor.d.ts +3 -1
  173. package/views/dist/panels/react/sort/SortEditor.js +4 -4
  174. package/views/dist/panels/react/toolbar/Toolbar.d.ts +80 -3
  175. package/views/dist/panels/react/toolbar/Toolbar.js +85 -52
  176. package/views/dist/panels/react/toolbar/ToolbarBarSorts.d.ts +9 -0
  177. package/views/dist/panels/react/toolbar/ToolbarBarSorts.js +57 -0
  178. package/views/dist/panels/react/toolbar/ToolbarFilterAdd.d.ts +4 -1
  179. package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +2 -2
  180. package/views/dist/panels/react/toolbar/ToolbarOptions.d.ts +30 -0
  181. package/views/dist/panels/react/toolbar/ToolbarOptions.js +6 -1
  182. package/views/dist/panels/react/toolbar/ToolbarSortPill.d.ts +5 -0
  183. package/views/dist/panels/react/toolbar/ToolbarSortPill.js +6 -4
  184. package/views/dist/panels/react/toolbar/ToolbarViews.d.ts +7 -1
  185. package/views/dist/panels/react/toolbar/ToolbarViews.js +4 -4
  186. package/views/dist/panels/react/toolbar/sheet-host.d.ts +3 -0
  187. package/views/dist/panels/react/toolbar/sheet-host.js +6 -0
  188. package/views/dist/panels/react/toolbar/use-give-way.d.ts +6 -0
  189. package/views/dist/panels/react/toolbar/use-give-way.js +8 -1
  190. package/views/dist/panels/react/views-row/ViewPicker.d.ts +8 -1
  191. package/views/dist/panels/react/views-row/ViewPicker.js +12 -7
  192. package/views/dist/panels/settings/filter-groups.js +7 -0
  193. package/views/dist/provider/components.d.ts +38 -3
  194. package/views/dist/react.d.ts +1 -1
  195. package/views/dist/selection/bar-overflow.d.ts +2 -0
  196. package/views/dist/selection/bar-overflow.js +2 -1
  197. package/views/dist/selection/bar-props.d.ts +1 -1
  198. package/views/dist/selection/verbs.d.ts +2 -2
  199. package/views/dist/styles.css +268 -5
  200. package/views/dist/styles.unlayered.css +268 -5
  201. package/views/docs/contract.md +29 -15
  202. package/views/docs/controls/field.md +1 -0
  203. package/views/docs/controls/filter-editor.md +1 -1
  204. package/views/docs/controls/menu.md +1 -1
  205. package/views/docs/controls/number-editor.md +2 -0
  206. package/views/docs/controls/sort-editor.md +1 -1
  207. package/views/docs/controls/text-editor.md +2 -0
  208. package/views/docs/guides/atoms.md +1 -0
  209. package/views/docs/guides/selection.md +1 -1
  210. package/views/docs/guides/the-grid.md +3 -3
  211. package/views/docs/reference/controls.md +3 -3
  212. package/views/docs/reference/field-row.md +1 -1
  213. package/views/docs/reference/grid.md +4 -4
  214. package/views/docs/reference/list.md +168 -6
  215. package/views/docs/reference/looks.md +1 -1
  216. package/views/docs/reference/panels-react.md +7 -7
  217. package/views/docs/reference/react.md +13 -10
  218. package/views/docs/reference/selection.md +1 -1
  219. package/views/docs/reference/views.md +9 -7
  220. package/views/skills/views/SKILL.md +2 -1
@@ -9,6 +9,7 @@ import { openViewKey, useKeptView, useListLink } from "./link.js";
9
9
  import { createListStore } from "./store.js";
10
10
  import { createListViews } from "./views.js";
11
11
  const ListStoreContext = createContext(null);
12
+ export const ToolbarModelProvided = createContext(null);
12
13
  export function ListRootBase({ id, children, share, ...props }) {
13
14
  const mode = useStoreMode(id, props, share);
14
15
  const extra = { sortFilter: props.sortFilter, bar: props.bar };
@@ -22,8 +23,15 @@ export function ListRootBase({ id, children, share, ...props }) {
22
23
  const registry = useContext(ListRegistryContext);
23
24
  useLayoutEffect(() => registry?.addStore(store.get().id, store), [registry, store]);
24
25
  const radio = useToolbarRadioState();
25
- return createElement(ListStoreContext.Provider, { value: store }, createElement(ListRadioContext.Provider, { value: radio }, createElement(ToolbarRadioContext.Provider, { value: radio }, children)));
26
+ const [box, setBox] = useState(null);
27
+ const paneBox = useMemo(() => ({ box, setBox }), [box]);
28
+ return createElement(ListStoreContext.Provider, { value: store }, createElement(ListRadioContext.Provider, { value: radio }, createElement(ToolbarRadioContext.Provider, { value: radio }, createElement(ListPaneBoxContext.Provider, { value: paneBox }, createElement(ToolbarModelProvided.Provider, { value: null }, children)))));
26
29
  }
30
+ export const RootQuickFilters = createContext(null);
31
+ export function useRootQuickFilters() {
32
+ return useContext(RootQuickFilters);
33
+ }
34
+ export const ListPaneBoxContext = createContext(null);
27
35
  export function useListStore() {
28
36
  const store = useContext(ListStoreContext);
29
37
  if (!store)
@@ -8,7 +8,7 @@ import { createListAnswers, requestSettingsOf } from "./source-answers.js";
8
8
  import { answerInMemory } from "./answer.js";
9
9
  import { columnsOf } from "./columns.js";
10
10
  import { ListCommitsContext, ListEditsSinkContext, useListCommits, useListEditsSink } from "./edits.js";
11
- import { ListRootBase, useList, useListStore } from "./root-base.js";
11
+ import { ListRootBase, RootQuickFilters, useList, useListStore } from "./root-base.js";
12
12
  export { useList, useListPanel, useListStore } from "./root-base.js";
13
13
  export function ListRoot({ fields, rows, source, pageSize, quickFilters, columns, save, can, children, ...base }) {
14
14
  const [defaults] = useState(() => base.settings === undefined && base.defaults === undefined && fields ? columnsOf(fields, columns, false).defaults : undefined);
@@ -36,7 +36,7 @@ function RootData({ fields, rows, source, pageSize, quickFilters, columns: overr
36
36
  useLayoutEffect(() => store.flush());
37
37
  const commits = useListCommits(save, writable, bindings);
38
38
  const sink = useListEditsSink(store);
39
- return createElement(ListCommitsContext.Provider, { value: commits }, createElement(ListEditsSinkContext.Provider, { value: sink }, children));
39
+ return createElement(ListCommitsContext.Provider, { value: commits }, createElement(ListEditsSinkContext.Provider, { value: sink }, createElement(RootQuickFilters.Provider, { value: quickFilters ?? null }, children)));
40
40
  }
41
41
  function useListData(fields, rows, overrides, settings, conventions, writable, hold) {
42
42
  const of = useMemo(() => (fields ? columnsOf(fields, overrides, writable) : null), [fields, overrides, writable]);
@@ -30,6 +30,17 @@ export type ListState = {
30
30
  footHere: boolean;
31
31
  sortFilter: "right" | "bar";
32
32
  bar: "added" | "always";
33
+ /** What stands under this root, by key, counted (VK-1091): `ListToolbar` places `bar` while it draws a filter bar, so a
34
+ * placed button's `opens="bar"` knows one is there. */
35
+ placed: Readonly<Record<string, number>>;
36
+ /** Sort and filter's (VK-1091): the filter bar asked open by its button. */
37
+ barOpen: boolean;
38
+ /** A placed panel asked to stand by its button, by its key (VK-1092): apart from `open`, so a popover opening elsewhere
39
+ * leaves it standing. */
40
+ shown: Readonly<Record<string, boolean>>;
41
+ /** A placed panel standing now, by its key (VK-1092): on its own (`always`, or `filled` holding something), or only
42
+ * because its button showed it. Its button reads it to show, point to or hide it. */
43
+ standing: Readonly<Record<string, "alone" | "shown">>;
33
44
  };
34
45
  /** The picked rows: their ids, or every matching row (`all`), and how many (null: every matching row, before the
35
46
  * list knows its total). */
@@ -57,6 +68,14 @@ export type ListState = {
57
68
  /** A panel's page: the open one's, or kept for a panel until another opens. */
58
69
  setPage: (key: string, page: ActivePanel) => void;
59
70
  hold: (held: Pending | null) => void;
71
+ /** Counts one more of `key` as placed; the function it hands back takes that one back, once. */
72
+ place: (key: string) => () => void;
73
+ /** Sort and filter's: asks the filter bar open, or lets it go. */
74
+ setBarOpen: (open: boolean) => void;
75
+ /** Asks a placed panel to stand, or lets it go (VK-1092). */
76
+ setShown: (key: string, shown: boolean) => void;
77
+ /** A placed panel says whether it stands, and how; `null`, it doesn't (VK-1092). */
78
+ stand: (key: string, stands: "alone" | "shown" | null) => void;
60
79
  /** Picks these rows, or every matching row (`"all"`); `[]` picks none. */
61
80
  select: (ids: readonly string[] | "all") => void;
62
81
  /** The shared view's Save for everyone; nothing without a shared view. */
@@ -1,3 +1,4 @@
1
+ import { FILTER_BAR_BUTTON_KEY } from "./bar-keys.js";
1
2
  const NO_EDITS = { saving: false, canUndo: false, canRedo: false };
2
3
  const sameKeys = (a, b) => Object.keys(b).every((key) => Object.is(a[key], b[key]));
3
4
  const sameIds = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
@@ -38,7 +39,41 @@ export function createListStore(id, props) {
38
39
  hold: (held) => {
39
40
  if (state.panels.held === held)
40
41
  return;
41
- write({ panels: { ...state.panels, held } });
42
+ const { panels } = state;
43
+ const opens = held !== null && !panels.barOpen && (panels.placed[FILTER_BAR_BUTTON_KEY] ?? 0) > 0;
44
+ write({ panels: { ...panels, held, ...(opens && { barOpen: true }) } });
45
+ },
46
+ place: (key) => {
47
+ const count = (by) => {
48
+ const { [key]: was = 0, ...rest } = state.panels.placed;
49
+ const now = was + by;
50
+ write({ panels: { ...state.panels, placed: now > 0 ? { ...rest, [key]: now } : rest } });
51
+ };
52
+ count(1);
53
+ let placed = true;
54
+ return () => {
55
+ if (!placed)
56
+ return;
57
+ placed = false;
58
+ count(-1);
59
+ };
60
+ },
61
+ setBarOpen: (open) => {
62
+ if (state.panels.barOpen === open)
63
+ return;
64
+ write({ panels: { ...state.panels, barOpen: open } });
65
+ },
66
+ setShown: (key, shown) => {
67
+ const { [key]: was = false, ...rest } = state.panels.shown;
68
+ if (was === shown)
69
+ return;
70
+ write({ panels: { ...state.panels, shown: shown ? { ...rest, [key]: true } : rest } });
71
+ },
72
+ stand: (key, stands) => {
73
+ const { [key]: was = null, ...rest } = state.panels.standing;
74
+ if (was === stands)
75
+ return;
76
+ write({ panels: { ...state.panels, standing: stands ? { ...rest, [key]: stands } : rest } });
42
77
  },
43
78
  select: (ids) => {
44
79
  if (ids === "all" && wired.selectAll)
@@ -68,6 +103,10 @@ export function createListStore(id, props) {
68
103
  footHere: false,
69
104
  sortFilter: props.sortFilter ?? "right",
70
105
  bar: props.bar ?? "added",
106
+ placed: {},
107
+ barOpen: false,
108
+ shown: {},
109
+ standing: {},
71
110
  },
72
111
  selection: { ids: [], all: false, count: 0 },
73
112
  views: null,
@@ -0,0 +1,95 @@
1
+ import type { ListPersonalLayer, ListSettings, ListSettingsChange } from "viewkitjs/fields/query";
2
+ import type { ToggleConfig } from "../panels/model.js";
3
+ import type { Pending } from "../panels/react/filter/editor-ctx.js";
4
+ import type { QuickFiltersConfig } from "../panels/quick/model.js";
5
+ import type { SettingsPanelsInput } from "../panels/settings/input.js";
6
+ import { settingsPanels } from "../panels/settings/settings-panels.js";
7
+ import { groupShown } from "../panels/toolbar/counts.js";
8
+ import { type CustomizePage } from "../panels/toolbar/page-resets.js";
9
+ import type { CollectionViewState } from "../panels/view-state.js";
10
+ import type { CollectionViewsInput } from "../panels/views-row/model.js";
11
+ import { useViews } from "../provider/context.js";
12
+ import type { ListState } from "./store.js";
13
+ import type { ListToolbarProps } from "./toolbar.js";
14
+ /** What the model takes: `ListToolbar` hands its own props; a part hands what it has (often nothing), and `fromRoot` to read
15
+ * the root's quick filters where it is handed none. */
16
+ export type ToolbarModelProps<Row> = Partial<Omit<ListToolbarProps<Row>, "toolbarParts">> & {
17
+ phone: boolean;
18
+ fromRoot?: boolean;
19
+ };
20
+ type Panels<Row> = ReturnType<typeof settingsPanels<Row>>;
21
+ /** What Customize and the bar's buttons are handed of the builder's panels. */
22
+ export type ToolbarOptionsInputs<Row> = {
23
+ filters: Panels<Row>["filters"];
24
+ sort: Panels<Row>["sort"];
25
+ sorts: Panels<Row>["sorts"];
26
+ filterTree: Panels<Row>["filterTree"];
27
+ group: ReturnType<typeof groupShown>;
28
+ layout: Panels<Row>["layout"];
29
+ toggles: ToggleConfig[] | undefined;
30
+ };
31
+ export type ToolbarModel<Row> = {
32
+ settings: ListSettings;
33
+ layer: ListPersonalLayer;
34
+ onChange: (change: ListSettingsChange) => void;
35
+ onLayerChange: (patch: ListPersonalLayer) => void;
36
+ /** The views handed, else the root's saved views. */
37
+ views: CollectionViewsInput<string> | undefined;
38
+ /** What the builder was handed. */
39
+ input: SettingsPanelsInput<Row>;
40
+ panels: Panels<Row>;
41
+ inputs: ToolbarOptionsInputs<Row>;
42
+ /** The shared view, its Reset the first page's (`resetAll`). */
43
+ view: CollectionViewState | undefined;
44
+ resets: Partial<Record<CustomizePage, () => void>> | undefined;
45
+ /** What differs from the saved view, or with none from the list's defaults; absent with no baseline. */
46
+ differs: {
47
+ sort: boolean;
48
+ filter: boolean;
49
+ } | undefined;
50
+ /** The person's layer holds something on this screen. */
51
+ layered: boolean;
52
+ /** Something differs from the default with no shared view: the kit's Clear stands. */
53
+ clearable: boolean;
54
+ resetAll: () => void;
55
+ clear: (scope: "options" | "filters") => () => void;
56
+ /** Show counts. */
57
+ show: boolean;
58
+ held: Pending | null;
59
+ setHeld: (held: Pending | null) => void;
60
+ /** The saved view's own filter, kept off the bar. */
61
+ savedFilter: ListSettings["filter"] | undefined;
62
+ /** The quick filters, their counts following Show counts and the source's where the app hands none; null with none. */
63
+ quick: QuickFiltersConfig | null;
64
+ };
65
+ /** What the model reads from the root and the provider: built again only when one of these, or a prop, changes. */
66
+ type ModelReads = {
67
+ settings: ListSettings;
68
+ layer: ListPersonalLayer;
69
+ onChange: (change: ListSettingsChange) => void;
70
+ onLayerChange: (patch: ListPersonalLayer) => void;
71
+ shared: CollectionViewState | undefined;
72
+ held: Pending | null;
73
+ setHeld: (held: Pending | null) => void;
74
+ rootColumns: unknown;
75
+ answer: ListState["answer"];
76
+ storeViews: CollectionViewsInput<string> | undefined;
77
+ rootQuick: QuickFiltersConfig | null;
78
+ messages: ReturnType<typeof useViews>["messages"];
79
+ conventions: ReturnType<typeof useViews>["conventions"];
80
+ };
81
+ /** A built model and what it was built from (not on the door). */
82
+ export type ModelCell = {
83
+ reads: ModelReads | null;
84
+ props: object | null;
85
+ model: unknown;
86
+ };
87
+ /** The toolbar's model (VK-1091, not on the door): every part placed under one root (`fromRoot`) reads the same one, built once
88
+ * per change of what it reads (VK-1105); a `ListToolbar` keeps its own (`useOwnToolbarModel`), and a part inside what it draws
89
+ * reads that (`ToolbarModelProvided`). */
90
+ export declare function useToolbarModel<Row>(props: ToolbarModelProps<Row>): ToolbarModel<Row>;
91
+ /** A `ListToolbar`'s own model (not on the door), which it hands to what it draws through `ToolbarModelProvided`. */
92
+ export declare function useOwnToolbarModel<Row>(props: ToolbarModelProps<Row>): ToolbarModel<Row>;
93
+ /** The settings' search written back: `next` empty clears it. */
94
+ export declare function searchChange(settings: ListSettings, next: string): ListSettingsChange;
95
+ export {};
@@ -0,0 +1,177 @@
1
+ import { settingsChange } from "viewkitjs/fields/query";
2
+ import { useContext, useState } from "react";
3
+ import { settingsPanels } from "../panels/settings/settings-panels.js";
4
+ import { settingsCleared } from "../panels/toolbar/clear.js";
5
+ import { countsToggle, groupShown, showCountsChange, showCountsOf } from "../panels/toolbar/counts.js";
6
+ import { pageResets } from "../panels/toolbar/page-resets.js";
7
+ import { useViews } from "../provider/context.js";
8
+ import { EMPTY_LAYER, layerHolds } from "./layer.js";
9
+ import { ToolbarModelProvided, useList, useListStore, useRootQuickFilters } from "./root-base.js";
10
+ import { useListViewsAxis } from "./views-axis.js";
11
+ const ROOT_CELLS = new WeakMap();
12
+ const OWN_CELLS = new WeakMap();
13
+ const cellOf = (cells, by) => {
14
+ const held = cells.get(by);
15
+ if (held)
16
+ return held;
17
+ const cell = { reads: null, props: null, model: null };
18
+ cells.set(by, cell);
19
+ return cell;
20
+ };
21
+ const sameKeys = (a, b) => {
22
+ if (!a)
23
+ return false;
24
+ const x = a;
25
+ const y = b;
26
+ const keys = Object.keys(x);
27
+ return keys.length === Object.keys(y).length && keys.every((key) => Object.is(x[key], y[key]));
28
+ };
29
+ export function useToolbarModel(props) {
30
+ const reads = useModelReads(props);
31
+ const provided = useContext(ToolbarModelProvided);
32
+ const store = useListStore();
33
+ const [own] = useState(() => ({}));
34
+ if (props.fromRoot) {
35
+ if (provided)
36
+ return provided.model;
37
+ return modelIn(cellOf(ROOT_CELLS, store), reads, props);
38
+ }
39
+ return modelIn(cellOf(OWN_CELLS, own), reads, props);
40
+ }
41
+ export function useOwnToolbarModel(props) {
42
+ const reads = useModelReads(props);
43
+ const [own] = useState(() => ({}));
44
+ return modelIn(cellOf(OWN_CELLS, own), reads, props);
45
+ }
46
+ function modelIn(cell, reads, handed) {
47
+ const { toolbarParts: _places, ...props } = handed;
48
+ if (cell.model && sameKeys(cell.reads, reads) && sameKeys(cell.props, props))
49
+ return cell.model;
50
+ const model = modelOf(reads, props);
51
+ cell.reads = reads;
52
+ cell.props = props;
53
+ cell.model = model;
54
+ return model;
55
+ }
56
+ function useModelReads(props) {
57
+ const { messages, conventions } = useViews();
58
+ return {
59
+ storeViews: useListViewsAxis(props.layouts),
60
+ rootColumns: useList((s) => s.columns),
61
+ answer: useList((s) => s.answer),
62
+ settings: useList((s) => s.view.settings),
63
+ layer: useList((s) => s.view.layer),
64
+ onChange: useList((s) => s.setSettings),
65
+ onLayerChange: useList((s) => s.setLayer),
66
+ shared: useList((s) => s.view.shared) ?? undefined,
67
+ held: useList((s) => s.panels.held),
68
+ setHeld: useList((s) => s.hold),
69
+ rootQuick: useRootQuickFilters(),
70
+ messages,
71
+ conventions,
72
+ };
73
+ }
74
+ const NO_COLUMNS = [];
75
+ function modelOf(reads, props) {
76
+ const { phone } = props;
77
+ const { storeViews, rootColumns, answer, settings, layer, onChange, onLayerChange, shared, held, setHeld, rootQuick, messages, conventions } = reads;
78
+ const views = props.views ?? storeViews;
79
+ const show = showCountsOf(settings);
80
+ const setShow = (next) => {
81
+ const change = showCountsChange(settings, next);
82
+ if (Object.keys(change).length > 0)
83
+ onChange(change);
84
+ };
85
+ const { toolbarParts: _placed, phone: _phone, fromRoot: _fromRoot, ...settingsProps } = props;
86
+ const input = {
87
+ ...settingsProps,
88
+ columns: props.columns ?? rootColumns ?? NO_COLUMNS,
89
+ groupHeads: props.groupHeads ?? answer?.groupHeads,
90
+ filterData: props.filterData ?? answer?.filterValues,
91
+ settings,
92
+ layer,
93
+ onChange,
94
+ onLayerChange,
95
+ severalSorts: props.severalSorts ?? true,
96
+ filterGroups: props.filterGroups ?? true,
97
+ resolve: props.resolve ?? messages,
98
+ conventions: props.conventions ?? conventions,
99
+ };
100
+ const panels = settingsPanels(input);
101
+ const counts = countsToggle(views, props.toggles, show, setShow, messages);
102
+ const toggles = counts ? [...(props.toggles ?? []), counts] : props.toggles;
103
+ const inputs = {
104
+ filters: panels.filters,
105
+ sort: panels.sort,
106
+ sorts: panels.sorts,
107
+ filterTree: panels.filterTree,
108
+ group: groupShown(panels.group, panels.layout, phone),
109
+ layout: panels.layout,
110
+ toggles,
111
+ };
112
+ const clear = (scope) => () => {
113
+ const change = settingsCleared(input, scope, { phone });
114
+ if (change)
115
+ onChange(change);
116
+ };
117
+ const layered = layerHolds(layer, { phone });
118
+ const resetAll = () => {
119
+ if (shared) {
120
+ if (shared.changes > 0)
121
+ shared.onReset();
122
+ }
123
+ else
124
+ clear("options")();
125
+ if (layered)
126
+ onLayerChange(EMPTY_LAYER);
127
+ };
128
+ const view = shared && { ...shared, onReset: resetAll };
129
+ const resets = shared && !shared.saved ? undefined : Object.fromEntries(Object.entries(pageResets(input, shared ? shared.saved ?? null : null, { cleared: !shared, phone })).map(([page, back]) => [
130
+ page,
131
+ () => {
132
+ if (back.change)
133
+ onChange(back.change);
134
+ if (back.layer)
135
+ onLayerChange(back.layer);
136
+ },
137
+ ]));
138
+ const differs = resets && { sort: !!resets.sort, filter: !!resets.filter };
139
+ const savedFilter = shared?.saved?.filter;
140
+ const clearable = !view && (layered || settingsCleared(input, "options", { phone }) !== null);
141
+ const holdCounts = answer?.holdCounts;
142
+ const own = props.quickFilters ?? (props.fromRoot ? rootQuick ?? undefined : undefined);
143
+ const quick = own?.fields.length
144
+ ? {
145
+ ...own,
146
+ showCounts: own.showCounts ?? show,
147
+ ...(holdCounts && {
148
+ fields: own.fields.map((field) => field.counts === undefined && holdCounts[field.key] ? { ...field, counts: holdCounts[field.key] } : field),
149
+ }),
150
+ }
151
+ : null;
152
+ return {
153
+ settings,
154
+ layer,
155
+ onChange,
156
+ onLayerChange,
157
+ views,
158
+ input,
159
+ panels,
160
+ inputs,
161
+ view,
162
+ resets,
163
+ differs,
164
+ layered,
165
+ clearable,
166
+ resetAll,
167
+ clear,
168
+ show,
169
+ held,
170
+ setHeld,
171
+ savedFilter,
172
+ quick,
173
+ };
174
+ }
175
+ export function searchChange(settings, next) {
176
+ return settingsChange(settings, { ...settings, search: next === "" ? undefined : next });
177
+ }