viewkitjs 0.32.0 → 0.33.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.
- package/CHANGELOG.md +69 -0
- package/fields/dist/index.d.ts +1 -1
- package/fields/dist/index.js +1 -1
- package/fields/dist/query/evaluate.d.ts +7 -0
- package/fields/dist/query/exact-number.d.ts +8 -2
- package/fields/dist/query/exact-number.js +14 -1
- package/fields/dist/query/sort.js +13 -10
- package/fields/dist/registry.js +5 -1
- package/fields/dist/types.d.ts +4 -1
- package/fields/dist/zod.d.ts +5 -0
- package/fields/dist/zod.js +10 -1
- package/fields/docs/guides/contact-values.md +12 -0
- package/fields/docs/guides/field-types.md +1 -1
- package/fields/docs/guides/queries.md +3 -1
- package/fields/docs/reference/fields.md +1 -0
- package/package.json +1 -1
- package/postgres/dist/check.js +4 -1
- package/postgres/dist/definitions/formula-forms.js +3 -1
- package/postgres/dist/definitions/money.js +2 -1
- package/postgres/dist/page.js +6 -3
- package/postgres/dist/rules.d.ts +15 -1
- package/postgres/dist/rules.js +16 -0
- package/postgres/dist/sort.js +7 -2
- package/postgres/docs/guides/definitions.md +1 -1
- package/postgres/docs/guides/field-map.md +1 -1
- package/postgres/docs/reference/definitions.md +1 -1
- package/postgres/docs/reference/postgres.md +1 -1
- package/views/dist/atoms/ToolbarButton.d.ts +1 -1
- package/views/dist/atoms/ToolbarButton.js +4 -3
- package/views/dist/atoms/frame-parts.d.ts +6 -0
- package/views/dist/atoms/frame-parts.js +15 -0
- package/views/dist/atoms/types.d.ts +16 -7
- package/views/dist/cells/cell-title.d.ts +3 -1
- package/views/dist/cells/cell-title.js +2 -2
- package/views/dist/cells/cell-values.js +2 -2
- package/views/dist/contract.d.ts +31 -6
- package/views/dist/contract.js +123 -0
- package/views/dist/controls/button/map-button.js +2 -0
- package/views/dist/controls/checkbox/checkbox.d.ts +3 -2
- package/views/dist/controls/checkbox/checkbox.js +2 -2
- package/views/dist/controls/compound-editor/compound-editor.d.ts +1 -1
- package/views/dist/controls/compound-editor/name-parts.js +4 -4
- package/views/dist/controls/compound-editor/place-parts.js +19 -19
- package/views/dist/controls/compound-editor/range-parts.js +14 -14
- package/views/dist/controls/compound-editor/row.d.ts +3 -1
- package/views/dist/controls/compound-editor/row.js +2 -2
- package/views/dist/controls/controls.d.ts +2 -0
- package/views/dist/controls/controls.js +2 -0
- package/views/dist/controls/customize/customize.js +37 -35
- package/views/dist/controls/customize/map-customize-body.d.ts +2 -0
- package/views/dist/controls/customize/map-customize-body.js +4 -0
- package/views/dist/controls/date-editor/date-days.js +2 -2
- package/views/dist/controls/date-editor/date-editor.js +18 -18
- package/views/dist/controls/date-editor/date-parts.js +6 -6
- package/views/dist/controls/date-editor/map-calendar.js +1 -1
- package/views/dist/controls/date-editor.css +2 -2
- package/views/dist/controls/field/field.d.ts +3 -0
- package/views/dist/controls/field/field.js +6 -6
- package/views/dist/controls/filter-editor/block.d.ts +2 -2
- package/views/dist/controls/filter-editor/block.js +5 -5
- package/views/dist/controls/filter-editor/filter-editor.js +31 -33
- package/views/dist/controls/filter-editor/how.d.ts +3 -1
- package/views/dist/controls/filter-editor/map-filter-body.d.ts +1 -0
- package/views/dist/controls/filter-editor/map-filter-body.js +7 -3
- package/views/dist/controls/filter-editor/map-rules.js +1 -1
- package/views/dist/controls/filter-editor/parts.js +2 -1
- package/views/dist/controls/group-editor/group-editor.js +15 -13
- package/views/dist/controls/index.d.ts +2 -0
- package/views/dist/controls/index.js +1 -0
- package/views/dist/controls/input/input.js +2 -2
- package/views/dist/controls/input/map-input.js +2 -0
- package/views/dist/controls/internal/editor-parts.js +1 -1
- package/views/dist/controls/internal/map-panel-controls.d.ts +8 -0
- package/views/dist/controls/internal/map-panel-controls.js +20 -0
- package/views/dist/controls/internal/panel-controls.d.ts +50 -0
- package/views/dist/controls/internal/panel-controls.js +197 -0
- package/views/dist/controls/internal/part-slot.d.ts +12 -0
- package/views/dist/controls/internal/part-slot.js +5 -0
- package/views/dist/controls/links-editor/links-editor.d.ts +1 -1
- package/views/dist/controls/links-editor/links-editor.js +27 -27
- package/views/dist/controls/menu/map-menu.d.ts +2 -2
- package/views/dist/controls/menu/map-menu.js +15 -12
- package/views/dist/controls/menu/menu.d.ts +2 -0
- package/views/dist/controls/menu/menu.js +3 -3
- package/views/dist/controls/menu-list/menu-list.d.ts +14 -4
- package/views/dist/controls/menu-list/menu-list.js +23 -22
- package/views/dist/controls/notice/notice.d.ts +3 -1
- package/views/dist/controls/notice/notice.js +2 -2
- package/views/dist/controls/number-editor/number-editor.d.ts +1 -1
- package/views/dist/controls/number-editor/number-editor.js +13 -13
- package/views/dist/controls/number-field/number-field.js +5 -3
- package/views/dist/controls/pane/pane.d.ts +4 -2
- package/views/dist/controls/pane/pane.js +4 -4
- package/views/dist/controls/picker/picker.d.ts +2 -0
- package/views/dist/controls/picker/picker.js +37 -36
- package/views/dist/controls/picker/rows.d.ts +4 -0
- package/views/dist/controls/popover/map-popover.d.ts +1 -1
- package/views/dist/controls/popover/map-popover.js +4 -2
- package/views/dist/controls/quick-filters/quick-filters.js +4 -4
- package/views/dist/controls/radio/radio.d.ts +3 -0
- package/views/dist/controls/radio/radio.js +4 -3
- package/views/dist/controls/select/map-select.d.ts +3 -0
- package/views/dist/controls/select/map-select.js +8 -0
- package/views/dist/controls/select/select.d.ts +3 -0
- package/views/dist/controls/select/select.js +3 -3
- package/views/dist/controls/sheet/bottom-sheet.d.ts +5 -1
- package/views/dist/controls/sheet/bottom-sheet.js +2 -2
- package/views/dist/controls/sheet/map-sheet.js +1 -1
- package/views/dist/controls/sort-editor/map-sort-body.d.ts +1 -0
- package/views/dist/controls/sort-editor/map-sort-body.js +7 -3
- package/views/dist/controls/sort-editor/sort-editor.js +24 -26
- package/views/dist/controls/sort-editor.css +5 -0
- package/views/dist/controls/text-editor/text-editor.d.ts +1 -1
- package/views/dist/controls/text-editor/text-editor.js +8 -8
- package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +3 -3
- package/views/dist/controls/toolbar-button/atom-toolbar-button.js +7 -6
- package/views/dist/controls/values-editor/values-editor.d.ts +1 -1
- package/views/dist/controls/values-editor/values-editor.js +22 -22
- package/views/dist/controls/views-list/map-view-menu.js +1 -1
- package/views/dist/controls/views-list/view-menu.js +6 -6
- package/views/dist/controls/views-list/views-list.js +4 -4
- package/views/dist/editors/EditorPanel.js +1 -1
- package/views/dist/field-row/FieldRow.js +13 -0
- package/views/dist/fields/money.d.ts +5 -2
- package/views/dist/fields/money.js +14 -2
- package/views/dist/grid/chrome/GridTable.js +4 -1
- package/views/dist/grid/chrome/cell-clipboard.d.ts +4 -2
- package/views/dist/grid/chrome/cell-clipboard.js +2 -2
- package/views/dist/grid/chrome/cells.js +3 -1
- package/views/dist/grid/chrome/grid-row-menu-items.js +1 -1
- package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -1
- package/views/dist/grid/chrome/useGridKeyboard.js +29 -6
- package/views/dist/grid/chrome/useGridTableInteractionModel.js +9 -2
- package/views/dist/grid/core/clipboard-model.d.ts +3 -1
- package/views/dist/grid/core/clipboard-model.js +9 -8
- package/views/dist/grid/core/editing-controller.d.ts +3 -0
- package/views/dist/grid/core/editing-controller.js +6 -0
- package/views/dist/grid/core/edits-sink.d.ts +19 -0
- package/views/dist/grid/core/edits-sink.js +2 -0
- package/views/dist/grid/core/spreadsheet-operations.js +1 -1
- package/views/dist/grid/core/useGridEditing.d.ts +5 -0
- package/views/dist/grid/core/useGridEditing.js +6 -0
- package/views/dist/list/answer.d.ts +40 -0
- package/views/dist/list/answer.js +43 -0
- package/views/dist/list/bulk-bar.d.ts +7 -0
- package/views/dist/list/bulk-bar.js +10 -0
- package/views/dist/list/columns.d.ts +24 -0
- package/views/dist/list/columns.js +27 -0
- package/views/dist/list/edits.d.ts +19 -0
- package/views/dist/list/edits.js +56 -0
- package/views/dist/list/grid.d.ts +11 -0
- package/views/dist/list/grid.js +76 -0
- package/views/dist/list/index.d.ts +14 -1
- package/views/dist/list/index.js +4 -1
- package/views/dist/list/link.d.ts +8 -0
- package/views/dist/list/link.js +78 -0
- package/views/dist/list/list.d.ts +70 -0
- package/views/dist/list/list.js +14 -0
- package/views/dist/list/parts.js +10 -3
- package/views/dist/list/root-base.d.ts +46 -0
- package/views/dist/list/root-base.js +137 -0
- package/views/dist/list/root.d.ts +35 -34
- package/views/dist/list/root.js +153 -113
- package/views/dist/list/source-answers.d.ts +39 -0
- package/views/dist/list/source-answers.js +225 -0
- package/views/dist/list/store.d.ts +37 -5
- package/views/dist/list/store.js +31 -0
- package/views/dist/list/toolbar.d.ts +3 -2
- package/views/dist/list/toolbar.js +14 -2
- package/views/dist/list/views-axis.js +4 -2
- package/views/dist/list/views.d.ts +7 -2
- package/views/dist/list/views.js +16 -5
- package/views/dist/model/column-capabilities.d.ts +13 -0
- package/views/dist/model/column-capabilities.js +23 -2
- package/views/dist/model/column-schema.d.ts +11 -1
- package/views/dist/model/view-rules.js +1 -0
- package/views/dist/panels/model.d.ts +2 -0
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +8 -2
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +2 -2
- package/views/dist/panels/react/toolbar/Toolbar.d.ts +8 -1
- package/views/dist/panels/react/toolbar/Toolbar.js +12 -3
- package/views/dist/panels/react/toolbar/ToolbarAdvancedFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarAsideFilter.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +4 -4
- package/views/dist/panels/react/toolbar/ToolbarButton.js +4 -1
- package/views/dist/panels/react/toolbar/ToolbarFilter.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarNew.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarOptions.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSearch.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSort.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarSortPill.js +6 -4
- package/views/dist/panels/react/toolbar/context.d.ts +10 -1
- package/views/dist/panels/react/toolbar/panel-part.d.ts +4 -1
- package/views/dist/panels/react/toolbar/panel-part.js +5 -3
- package/views/dist/panels/settings/filter-groups.js +6 -1
- package/views/dist/provider/ViewsProvider.d.ts +6 -2
- package/views/dist/provider/ViewsProvider.js +18 -1
- package/views/dist/provider/components.d.ts +59 -0
- package/views/dist/provider/components.js +1 -1
- package/views/dist/provider/context.d.ts +4 -1
- package/views/dist/provider/own-control.d.ts +4 -0
- package/views/dist/provider/own-control.js +7 -0
- package/views/dist/provider/select-items.d.ts +3 -0
- package/views/dist/provider/select-items.js +6 -0
- package/views/dist/react.d.ts +4 -2
- package/views/dist/react.js +2 -0
- package/views/dist/styles.css +86 -78
- package/views/dist/styles.unlayered.css +86 -78
- package/views/docs/contract.md +252 -5
- package/views/docs/controls/compound-editor.md +4 -0
- package/views/docs/controls/customize.md +6 -0
- package/views/docs/controls/date-editor.md +4 -0
- package/views/docs/controls/field.md +4 -0
- package/views/docs/controls/filter-editor.md +8 -0
- package/views/docs/controls/group-editor.md +6 -0
- package/views/docs/controls/input.md +4 -0
- package/views/docs/controls/links-editor.md +4 -0
- package/views/docs/controls/menu-list.md +8 -0
- package/views/docs/controls/menu.md +4 -0
- package/views/docs/controls/notice.md +4 -0
- package/views/docs/controls/number-editor.md +4 -0
- package/views/docs/controls/pane.md +4 -0
- package/views/docs/controls/picker.md +8 -0
- package/views/docs/controls/quick-filters.md +6 -0
- package/views/docs/controls/radio.md +4 -0
- package/views/docs/controls/select.md +8 -0
- package/views/docs/controls/sheet.md +4 -0
- package/views/docs/controls/sort-editor.md +8 -0
- package/views/docs/controls/text-editor.md +4 -0
- package/views/docs/controls/values-editor.md +4 -0
- package/views/docs/controls/views-list.md +6 -0
- package/views/docs/guides/the-grid.md +2 -2
- package/views/docs/guides/the-provider.md +19 -2
- package/views/docs/reference/controls.md +7 -5
- package/views/docs/reference/field-row.md +1 -1
- package/views/docs/reference/grid.md +1 -1
- package/views/docs/reference/list.md +141 -11
- package/views/docs/reference/panels-react.md +2 -2
- package/views/docs/reference/react.md +15 -9
- package/views/docs/reference/views.md +8 -4
- package/views/docs/reshaping.md +6 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { evaluateView } from "viewkitjs/fields/query";
|
|
2
|
+
import { deriveGridSelectValues } from "../grid/core/column-values.js";
|
|
3
|
+
const NO_MORE = { rows: false, groups: {} };
|
|
4
|
+
export function answerInMemory(rows, settings, fields, columns, conventions, bindings, hold) {
|
|
5
|
+
const keys = Object.keys(fields);
|
|
6
|
+
const { rows: kept, buckets } = evaluateView(rows, {
|
|
7
|
+
filter: settings.filter,
|
|
8
|
+
search: settings.search ? { text: settings.search, fields: keys } : undefined,
|
|
9
|
+
sorts: settings.sorts,
|
|
10
|
+
group: settings.group,
|
|
11
|
+
...(hold?.length && { hold }),
|
|
12
|
+
...(settings.rowOrderMode && { rowOrderMode: settings.rowOrderMode }),
|
|
13
|
+
...(settings.itemPositions && { itemPositions: settings.itemPositions }),
|
|
14
|
+
}, {
|
|
15
|
+
fieldOf: (key) => fields[key],
|
|
16
|
+
read: (row, key) => {
|
|
17
|
+
const binding = bindings?.[key];
|
|
18
|
+
return binding ? binding.read(row) : row[key];
|
|
19
|
+
},
|
|
20
|
+
}, { ...(conventions && { conventions }), rowId: (row) => row.id });
|
|
21
|
+
const groups = buckets
|
|
22
|
+
? buckets.filter((bucket) => !bucket.hidden).map((bucket) => ({ key: bucket.key, label: bucket.label, items: bucket.items }))
|
|
23
|
+
: [{ key: "all", label: null, items: kept }];
|
|
24
|
+
return {
|
|
25
|
+
groups,
|
|
26
|
+
grouped: !!buckets,
|
|
27
|
+
groupHeads: (buckets ?? []).map((bucket) => ({
|
|
28
|
+
key: bucket.key,
|
|
29
|
+
label: bucket.label,
|
|
30
|
+
count: bucket.items.length,
|
|
31
|
+
hidden: bucket.hidden,
|
|
32
|
+
})),
|
|
33
|
+
ids: groups.flatMap((group) => group.items.map((row) => row.id)),
|
|
34
|
+
total: { count: kept.length, exact: true },
|
|
35
|
+
filterValues: { selectValues: deriveGridSelectValues(columns, rows), relationValues: {} },
|
|
36
|
+
loading: false,
|
|
37
|
+
refused: null,
|
|
38
|
+
more: NO_MORE,
|
|
39
|
+
paged: false,
|
|
40
|
+
viewCounts: null,
|
|
41
|
+
holdCounts: null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type SelectionBarProps } from "../selection/SelectionBar.js";
|
|
3
|
+
/** `SelectionBar`'s props but the count and the clear, which the root holds; `verbs` default none. */
|
|
4
|
+
export type ListBulkBarProps = Omit<SelectionBarProps, "count" | "onClear" | "verbs"> & {
|
|
5
|
+
verbs?: SelectionBarProps["verbs"];
|
|
6
|
+
};
|
|
7
|
+
export declare function ListBulkBar({ verbs, ...own }: ListBulkBarProps): ReactNode;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { SelectionBar } from "../selection/SelectionBar.js";
|
|
4
|
+
import { useList } from "./root.js";
|
|
5
|
+
const NONE = [];
|
|
6
|
+
export function ListBulkBar({ verbs = NONE, ...own }) {
|
|
7
|
+
const count = useList((s) => s.selection.count) ?? 0;
|
|
8
|
+
const select = useList((s) => s.select);
|
|
9
|
+
return _jsx(SelectionBar, { ...own, verbs: verbs, count: count, onClear: () => select([]) });
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FieldDef } from "viewkitjs/fields";
|
|
2
|
+
import { type ListRow, type ListSettings } from "viewkitjs/fields/query";
|
|
3
|
+
import { type FieldBinding, type FieldBindingSpec } from "../fields/binding.js";
|
|
4
|
+
import type { ListColumn } from "../model/column-schema.js";
|
|
5
|
+
/** A list's fields: what `defineFields` returns. */
|
|
6
|
+
export type ListFieldsRegistry = Readonly<Record<string, FieldDef>>;
|
|
7
|
+
/** One column's change over what the fields give it. `editable: false` only takes an edit away. `bind`: how the field
|
|
8
|
+
* reads and writes the row, where its key doesn't say (`bindFields`' spec); absent, bound by its key. */
|
|
9
|
+
export type ListColumnOverride<Row = ListRow> = {
|
|
10
|
+
width?: number;
|
|
11
|
+
hidden?: boolean;
|
|
12
|
+
editable?: boolean;
|
|
13
|
+
header?: string;
|
|
14
|
+
bind?: FieldBindingSpec<Row, FieldDef>;
|
|
15
|
+
};
|
|
16
|
+
/** Columns changed by their field's key. */
|
|
17
|
+
export type ListColumnsOverride<Row = ListRow> = Readonly<Record<string, ListColumnOverride<Row>>>;
|
|
18
|
+
export type ListColumnsOf<Row> = {
|
|
19
|
+
columns: ListColumn<Row>[];
|
|
20
|
+
bindings: Readonly<Record<string, FieldBinding<Row>>>;
|
|
21
|
+
/** `LIST_SETTINGS_DEFAULTS` with every field's column, in the registry's order, `visible: !hidden`. */
|
|
22
|
+
defaults: ListSettings;
|
|
23
|
+
};
|
|
24
|
+
export declare function columnsOf<Row extends ListRow>(fields: ListFieldsRegistry, overrides: ListColumnsOverride<Row> | undefined, writable: boolean): ListColumnsOf<Row>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LIST_SETTINGS_DEFAULTS } from "viewkitjs/fields/query";
|
|
2
|
+
import { bindFields } from "../fields/binding.js";
|
|
3
|
+
import { columnFrom } from "../model/column-from.js";
|
|
4
|
+
export function columnsOf(fields, overrides, writable) {
|
|
5
|
+
const keys = Object.keys(fields);
|
|
6
|
+
const specs = {};
|
|
7
|
+
for (const key of keys) {
|
|
8
|
+
const bind = overrides?.[key]?.bind;
|
|
9
|
+
if (bind)
|
|
10
|
+
specs[key] = bind;
|
|
11
|
+
}
|
|
12
|
+
const bindings = bindFields(fields, specs);
|
|
13
|
+
const columns = keys.map((key) => {
|
|
14
|
+
const own = overrides?.[key];
|
|
15
|
+
return columnFrom(bindings[key], {
|
|
16
|
+
id: key,
|
|
17
|
+
...(own?.width !== undefined && { width: own.width }),
|
|
18
|
+
...(own?.header !== undefined && { header: own.header }),
|
|
19
|
+
...((!writable || own?.editable === false) && { editable: false }),
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
const defaults = {
|
|
23
|
+
...LIST_SETTINGS_DEFAULTS,
|
|
24
|
+
columns: keys.map((key) => ({ key, visible: !overrides?.[key]?.hidden })),
|
|
25
|
+
};
|
|
26
|
+
return { columns, bindings, defaults };
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ListRow } from "viewkitjs/fields/query";
|
|
2
|
+
import type { FieldBinding } from "../fields/binding.js";
|
|
3
|
+
import type { GridCellCommitFn, GridCellsCommitFn, ListSave } from "../grid/core/commit-model.js";
|
|
4
|
+
import type { GridEditsSink } from "../grid/core/edits-sink.js";
|
|
5
|
+
import type { ListStore } from "./store.js";
|
|
6
|
+
export type ListCommits<Row> = {
|
|
7
|
+
onCellCommit: GridCellCommitFn<Row>;
|
|
8
|
+
onCellsCommit: GridCellsCommitFn<Row>;
|
|
9
|
+
};
|
|
10
|
+
/** The root's commits, for the grid under it; null where the list doesn't write. */
|
|
11
|
+
export declare const ListCommitsContext: import("react").Context<ListCommits<ListRow> | null>;
|
|
12
|
+
/** The root's sink, for the grid under it. */
|
|
13
|
+
export declare const ListEditsSinkContext: import("react").Context<GridEditsSink | null>;
|
|
14
|
+
/** `gridSave` made once over the latest `save` and the latest bindings: its queues live in what one call returns.
|
|
15
|
+
* Null when the list doesn't write (no `save`, or `can.edit` false). */
|
|
16
|
+
export declare function useListCommits<Row extends ListRow>(save: ListSave<Row> | undefined, writable: boolean, bindings: Readonly<Record<string, FieldBinding<Row>>> | null): ListCommits<Row> | null;
|
|
17
|
+
/** The sink the root hands its grid: the grid's undo and redo wired into the store, its edits' state patched in on each
|
|
18
|
+
* change, and all of it let go when the grid leaves. */
|
|
19
|
+
export declare function useListEditsSink(store: ListStore): GridEditsSink;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createContext, useMemo, useRef, useLayoutEffect, useState } from "react";
|
|
2
|
+
import { gridSave } from "../grid/core/save-path.js";
|
|
3
|
+
export const ListCommitsContext = createContext(null);
|
|
4
|
+
export const ListEditsSinkContext = createContext(null);
|
|
5
|
+
const NO_EDITS = { saving: false, canUndo: false, canRedo: false };
|
|
6
|
+
function valuesOf(bindings, row, columnId, value) {
|
|
7
|
+
const write = bindings[columnId]?.write;
|
|
8
|
+
if (!write)
|
|
9
|
+
throw new Error(`${columnId} can't be edited`);
|
|
10
|
+
const patch = write(row, value);
|
|
11
|
+
if ("skip" in patch)
|
|
12
|
+
throw new Error(patch.reason ?? "This change can't be saved.");
|
|
13
|
+
return patch.body;
|
|
14
|
+
}
|
|
15
|
+
export function useListCommits(save, writable, bindings) {
|
|
16
|
+
const latest = useRef({ save, bindings });
|
|
17
|
+
useLayoutEffect(() => {
|
|
18
|
+
latest.current = { save, bindings };
|
|
19
|
+
});
|
|
20
|
+
const [commits] = useState(() => commitsOver(latest));
|
|
21
|
+
return writable && !!save && !!bindings ? commits : null;
|
|
22
|
+
}
|
|
23
|
+
function commitsOver(latest) {
|
|
24
|
+
return gridSave((change) => latest.current.save?.(change) ?? Promise.reject(new Error("This list no longer saves.")), {
|
|
25
|
+
getRowId: (row) => row.id,
|
|
26
|
+
values: (row, columnId, value) => valuesOf(latest.current.bindings ?? {}, row, columnId, value),
|
|
27
|
+
read: (row, columnId) => {
|
|
28
|
+
const binding = latest.current.bindings?.[columnId];
|
|
29
|
+
return binding ? binding.read(row) : row[columnId];
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function useListEditsSink(store) {
|
|
34
|
+
return useMemo(() => editsSinkOf(store), [store]);
|
|
35
|
+
}
|
|
36
|
+
function editsSinkOf(store) {
|
|
37
|
+
let handle = null;
|
|
38
|
+
return {
|
|
39
|
+
attach: (next) => {
|
|
40
|
+
handle = next;
|
|
41
|
+
store.wire({ undo: () => void next.undo(), redo: () => void next.redo() });
|
|
42
|
+
store.patch({ edits: next.state() });
|
|
43
|
+
return () => {
|
|
44
|
+
if (handle !== next)
|
|
45
|
+
return;
|
|
46
|
+
handle = null;
|
|
47
|
+
store.wire({ undo: undefined, redo: undefined });
|
|
48
|
+
store.patch({ edits: NO_EDITS });
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
changed: () => {
|
|
52
|
+
if (handle)
|
|
53
|
+
store.patch({ edits: handle.state() });
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ListRow } from "viewkitjs/fields/query";
|
|
3
|
+
import type { GridTableProps } from "../grid/chrome/grid-table-props.js";
|
|
4
|
+
/** What the root draws for the grid: every `GridTable` prop is the app's to hand too, and wins over the root's. A
|
|
5
|
+
* `selection` handed is the app's own: the root's picks then stop following the grid, and the children (`ListBulkBar`)
|
|
6
|
+
* aren't drawn. */
|
|
7
|
+
export type ListGridProps<Row extends ListRow> = Partial<GridTableProps<Row>> & {
|
|
8
|
+
/** Drawn where the grid places its selection bar (`ListBulkBar`). */
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare function ListGrid<Row extends ListRow>({ children, ...own }: ListGridProps<Row>): ReactNode;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useContext, useLayoutEffect, useMemo, useState } from "react";
|
|
4
|
+
import { GridTable } from "../grid/chrome/GridTable.js";
|
|
5
|
+
import { GridEditsSinkContext } from "../grid/core/edits-sink.js";
|
|
6
|
+
import { useGridTableSettings } from "../grid/useGridTableSettings.js";
|
|
7
|
+
import { LIST_VIEW_PREF_DEFAULTS } from "../model/preferences.js";
|
|
8
|
+
import { settingsPanels } from "../panels/settings/settings-panels.js";
|
|
9
|
+
import { useViews } from "../provider/context.js";
|
|
10
|
+
import { ListCommitsContext, ListEditsSinkContext } from "./edits.js";
|
|
11
|
+
import { useList, useListStore } from "./root.js";
|
|
12
|
+
const FORMATS = {
|
|
13
|
+
gridOptionColors: LIST_VIEW_PREF_DEFAULTS.gridOptionColors,
|
|
14
|
+
gridDateStyles: LIST_VIEW_PREF_DEFAULTS.gridDateStyles,
|
|
15
|
+
gridDurationStyles: LIST_VIEW_PREF_DEFAULTS.gridDurationStyles,
|
|
16
|
+
gridShowTime: LIST_VIEW_PREF_DEFAULTS.gridShowTime,
|
|
17
|
+
gridPercentDisplays: LIST_VIEW_PREF_DEFAULTS.gridPercentDisplays,
|
|
18
|
+
gridDecimals: LIST_VIEW_PREF_DEFAULTS.gridDecimals,
|
|
19
|
+
gridCurrencies: LIST_VIEW_PREF_DEFAULTS.gridCurrencies,
|
|
20
|
+
};
|
|
21
|
+
const getRowId = (row) => row.id;
|
|
22
|
+
const noop = () => { };
|
|
23
|
+
export function ListGrid({ children, ...own }) {
|
|
24
|
+
const store = useListStore();
|
|
25
|
+
const answer = useList((s) => s.answer);
|
|
26
|
+
const rootColumns = useList((s) => s.columns);
|
|
27
|
+
const settings = useList((s) => s.view.settings);
|
|
28
|
+
const layer = useList((s) => s.view.layer);
|
|
29
|
+
const onChange = useList((s) => s.setSettings);
|
|
30
|
+
const onLayerChange = useList((s) => s.setLayer);
|
|
31
|
+
const commits = useContext(ListCommitsContext);
|
|
32
|
+
const sink = useContext(ListEditsSinkContext);
|
|
33
|
+
const handedColumns = own.columns;
|
|
34
|
+
const columns = useMemo(() => handedColumns ?? rootColumns ?? [], [handedColumns, rootColumns]);
|
|
35
|
+
const [formats, setFormatsState] = useState(FORMATS);
|
|
36
|
+
const setFormats = useCallback((patch) => setFormatsState((held) => ({ ...held, ...patch })), []);
|
|
37
|
+
const { gridProps } = useGridTableSettings({ settings, layer, columns, onChange, onLayerChange, formats, setFormats });
|
|
38
|
+
const panels = useMemo(() => settingsPanels({ settings, layer, columns, onChange, onLayerChange, severalSorts: true }), [settings, layer, columns, onChange, onLayerChange]);
|
|
39
|
+
const folded = useMemo(() => new Set(layer.folded ?? []), [layer.folded]);
|
|
40
|
+
const toggleGroup = useCallback((key) => onLayerChange({ folded: folded.has(key) ? [...folded].filter((held) => held !== key) : [...folded, key] }), [folded, onLayerChange]);
|
|
41
|
+
const resetKey = useMemo(() => JSON.stringify([settings.search ?? "", settings.filter, settings.group]), [settings.search, settings.filter, settings.group]);
|
|
42
|
+
const ids = answer?.ids;
|
|
43
|
+
const orderedIds = useMemo(() => (ids ? [...ids] : []), [ids]);
|
|
44
|
+
const selection = useMemo(() => ({
|
|
45
|
+
orderedIds,
|
|
46
|
+
resetKey,
|
|
47
|
+
...(answer?.paged && { retention: "external" }),
|
|
48
|
+
renderBar: (sel) => (_jsx(PublishSelection, { sel: sel, store: store, children: children })),
|
|
49
|
+
}), [orderedIds, resetKey, store, children, answer?.paged]);
|
|
50
|
+
const { LoadMore } = useViews().atoms;
|
|
51
|
+
const loadMore = useList((s) => s.loadMore);
|
|
52
|
+
const loadGroup = useList((s) => s.loadGroup);
|
|
53
|
+
const more = answer?.more;
|
|
54
|
+
const sourced = useMemo(() => ({
|
|
55
|
+
...(more?.rows && { loadMore: { hasMore: true, onReveal: loadMore } }),
|
|
56
|
+
...(more && Object.values(more.groups).some(Boolean) && {
|
|
57
|
+
renderGroupFooter: (group) => more.groups[group.key] && !folded.has(group.key) ? _jsx(LoadMore, { onReveal: () => loadGroup(group.key) }) : null,
|
|
58
|
+
}),
|
|
59
|
+
}), [more, loadMore, loadGroup, folded, LoadMore]);
|
|
60
|
+
if (!answer)
|
|
61
|
+
return null;
|
|
62
|
+
return (_jsx(GridEditsSinkContext.Provider, { value: sink, children: _jsx(GridTable, { ...gridProps, groups: answer.groups, grouped: answer.grouped, getRowId: getRowId, columns: columns, sort: panels.sort, groupBy: panels.groupBy, sortMark: true, isCollapsed: (key) => folded.has(key), onToggleGroup: toggleGroup, onOpenRow: noop, ...commits, selection: selection, ...sourced, ...(answer.refused !== null && { emptyState: answer.refused }), ...(answer.loading && answer.ids.length === 0 && { transitionPending: true }), ...own }) }));
|
|
63
|
+
}
|
|
64
|
+
function PublishSelection({ sel, store, children }) {
|
|
65
|
+
const ids = useMemo(() => [...sel.selectedIds], [sel.selectedIds]);
|
|
66
|
+
useLayoutEffect(() => {
|
|
67
|
+
store.patch({ selection: { ids, all: false, count: ids.length } });
|
|
68
|
+
}, [store, ids]);
|
|
69
|
+
useLayoutEffect(() => () => store.patch({ selection: { ids: [], all: false, count: 0 } }), [store]);
|
|
70
|
+
const { selectAll, setSelected } = sel;
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
store.wire({ select: (next) => (next === "all" ? selectAll() : setSelected([...next])) });
|
|
73
|
+
return () => store.wire({ select: undefined });
|
|
74
|
+
}, [store, selectAll, setSelected]);
|
|
75
|
+
return children ?? null;
|
|
76
|
+
}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
export { browserViewsStore } from "./browser-views-store.js";
|
|
2
2
|
export type { BrowserViewsStoreOptions } from "./browser-views-store.js";
|
|
3
3
|
export { fetchSource } from "./source.js";
|
|
4
|
-
export {
|
|
4
|
+
export { List } from "./list.js";
|
|
5
|
+
export type { ListAnswerState } from "./answer.js";
|
|
6
|
+
export { ListBulkBar } from "./bulk-bar.js";
|
|
7
|
+
export type { ListBulkBarProps } from "./bulk-bar.js";
|
|
8
|
+
export type { ListChange } from "../grid/core/commit-model.js";
|
|
9
|
+
export type { ListColumnOverride } from "./columns.js";
|
|
10
|
+
export type { ListColumnsOverride } from "./columns.js";
|
|
11
|
+
export type { ListData } from "./root.js";
|
|
12
|
+
export type { ListFieldsRegistry } from "./columns.js";
|
|
5
13
|
export { ListFill } from "./slot.js";
|
|
6
14
|
export type { ListFillProps } from "./slot.js";
|
|
15
|
+
export { ListGrid } from "./grid.js";
|
|
16
|
+
export type { ListGridProps } from "./grid.js";
|
|
7
17
|
export type { ListMenus } from "./menu.js";
|
|
18
|
+
export type { ListProps } from "./list.js";
|
|
19
|
+
export { ListRoot } from "./root.js";
|
|
8
20
|
export type { ListRootProps } from "./root.js";
|
|
21
|
+
export type { ListSave } from "../grid/core/commit-model.js";
|
|
9
22
|
export { ListSlot } from "./slot.js";
|
|
10
23
|
export type { ListSlotProps } from "./slot.js";
|
|
11
24
|
export type { ListSource } from "./source.js";
|
package/views/dist/list/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { browserViewsStore } from "./browser-views-store.js";
|
|
2
2
|
export { fetchSource } from "./source.js";
|
|
3
|
-
export {
|
|
3
|
+
export { List } from "./list.js";
|
|
4
|
+
export { ListBulkBar } from "./bulk-bar.js";
|
|
4
5
|
export { ListFill } from "./slot.js";
|
|
6
|
+
export { ListGrid } from "./grid.js";
|
|
7
|
+
export { ListRoot } from "./root.js";
|
|
5
8
|
export { ListSlot } from "./slot.js";
|
|
6
9
|
export { ListToolbar } from "./toolbar.js";
|
|
7
10
|
export { menu } from "./menu.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ListSettings } from "viewkitjs/fields/query";
|
|
2
|
+
import type { ListStore } from "./store.js";
|
|
3
|
+
/** The device key the open view is kept under, per list. */
|
|
4
|
+
export declare const openViewKey: (listId: string) => string;
|
|
5
|
+
/** The address follows the list (on), and the list the browser's back and forward. */
|
|
6
|
+
export declare function useListLink(store: ListStore, on: boolean, defaults: ListSettings): void;
|
|
7
|
+
/** The open view, kept on the device as it changes. */
|
|
8
|
+
export declare function useKeptView(store: ListStore, listId: string, on: boolean): void;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useContext, useEffect } from "react";
|
|
2
|
+
import { readListLink, writeListLink } from "viewkitjs/fields/query";
|
|
3
|
+
import { ViewsContext } from "../provider/context.js";
|
|
4
|
+
export const openViewKey = (listId) => `vk:list-open:${listId}`;
|
|
5
|
+
export function useListLink(store, on, defaults) {
|
|
6
|
+
const toast = useContext(ViewsContext)?.ports.toast.error;
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!on || typeof window === "undefined")
|
|
9
|
+
return;
|
|
10
|
+
let said;
|
|
11
|
+
const say = (problem) => {
|
|
12
|
+
if (!problem || problem === said)
|
|
13
|
+
return;
|
|
14
|
+
said = problem;
|
|
15
|
+
toast?.(problem);
|
|
16
|
+
};
|
|
17
|
+
say(readListLink(window.location.search).problem);
|
|
18
|
+
let written = window.location.search;
|
|
19
|
+
const listPart = (search) => {
|
|
20
|
+
const { view, change } = readListLink(search);
|
|
21
|
+
return JSON.stringify([view ?? null, change]);
|
|
22
|
+
};
|
|
23
|
+
let listSays = listPart(written);
|
|
24
|
+
const write = () => {
|
|
25
|
+
const state = store.get();
|
|
26
|
+
const views = state.views;
|
|
27
|
+
if (!views?.ready)
|
|
28
|
+
return;
|
|
29
|
+
const view = views.list.find((v) => v.id === views.open);
|
|
30
|
+
const { params, problem } = writeListLink(window.location.search, { ...(views.open !== null && { view: views.open }), base: view?.settings ?? defaults, settings: state.view.settings }, { carryChanges: true });
|
|
31
|
+
say(problem);
|
|
32
|
+
const query = params.toString();
|
|
33
|
+
const next = query ? `?${query}` : "";
|
|
34
|
+
written = next;
|
|
35
|
+
listSays = listPart(next);
|
|
36
|
+
if (next === window.location.search)
|
|
37
|
+
return;
|
|
38
|
+
window.history.replaceState(window.history.state, "", `${window.location.pathname}${next}${window.location.hash}`);
|
|
39
|
+
};
|
|
40
|
+
const off = store.subscribe(write);
|
|
41
|
+
write();
|
|
42
|
+
const onPop = () => {
|
|
43
|
+
if (window.location.search === written)
|
|
44
|
+
return;
|
|
45
|
+
written = window.location.search;
|
|
46
|
+
if (listPart(written) === listSays)
|
|
47
|
+
return;
|
|
48
|
+
listSays = listPart(written);
|
|
49
|
+
const reading = readListLink(window.location.search);
|
|
50
|
+
say(reading.problem);
|
|
51
|
+
const views = store.get().views;
|
|
52
|
+
const id = reading.view ?? views?.list[0]?.id;
|
|
53
|
+
if (id)
|
|
54
|
+
views?.openView(id, reading.change);
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener("popstate", onPop);
|
|
57
|
+
return () => {
|
|
58
|
+
off();
|
|
59
|
+
window.removeEventListener("popstate", onPop);
|
|
60
|
+
};
|
|
61
|
+
}, [store, on, defaults, toast]);
|
|
62
|
+
}
|
|
63
|
+
export function useKeptView(store, listId, on) {
|
|
64
|
+
const prefs = useContext(ViewsContext)?.ports.viewPrefs;
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!on || !prefs)
|
|
67
|
+
return;
|
|
68
|
+
let kept = store.get().views?.open;
|
|
69
|
+
return store.subscribe(() => {
|
|
70
|
+
const views = store.get().views;
|
|
71
|
+
if (!views?.ready || views.open === kept)
|
|
72
|
+
return;
|
|
73
|
+
kept = views.open;
|
|
74
|
+
if (kept)
|
|
75
|
+
prefs.set(openViewKey(listId), kept);
|
|
76
|
+
});
|
|
77
|
+
}, [store, listId, prefs, on]);
|
|
78
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ListRow, ListSettings } from "viewkitjs/fields/query";
|
|
3
|
+
import type { GridTableProps } from "../grid/chrome/grid-table-props.js";
|
|
4
|
+
import type { ListSave } from "../grid/core/commit-model.js";
|
|
5
|
+
import type { ToolbarParts } from "../panels/react/toolbar/ReadyToolbar.js";
|
|
6
|
+
import type { QuickFiltersConfig } from "../panels/quick/model.js";
|
|
7
|
+
import type { ViewsMenuItem } from "../provider/components.js";
|
|
8
|
+
import { type ListBulkBarProps } from "./bulk-bar.js";
|
|
9
|
+
import type { ListColumnsOverride, ListFieldsRegistry } from "./columns.js";
|
|
10
|
+
import { type ListGridProps } from "./grid.js";
|
|
11
|
+
import type { ListMenus } from "./menu.js";
|
|
12
|
+
import { type ListViewsOptions } from "./root.js";
|
|
13
|
+
import { type ListToolbarProps } from "./toolbar.js";
|
|
14
|
+
import type { ListSource } from "./source.js";
|
|
15
|
+
import type { ViewsStore } from "./views-store.js";
|
|
16
|
+
export type ListProps<Row extends ListRow> = ListPropsCommon<Row> & ({
|
|
17
|
+
/** The rows, the app's own flat `{ id, ...values }`; the list filters, sorts and groups them. */
|
|
18
|
+
rows: readonly Row[];
|
|
19
|
+
source?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
/** Where the rows come from: one list request in, its answer out (`fetchSource`, or a server action). */
|
|
22
|
+
source: ListSource<Row>;
|
|
23
|
+
rows?: undefined;
|
|
24
|
+
});
|
|
25
|
+
type ListPropsCommon<Row extends ListRow> = {
|
|
26
|
+
/** The list's id: its saved views, the person's draft and layer, and its open view are kept under it. */
|
|
27
|
+
id: string;
|
|
28
|
+
/** The list's fields (`defineFields`): every field a column, in its order, bound by its key. */
|
|
29
|
+
fields: ListFieldsRegistry;
|
|
30
|
+
/** A source's page: how many rows each request asks for. Default 50, held between 1 and 1000. */
|
|
31
|
+
pageSize?: number;
|
|
32
|
+
/** One save per record. None: a read-only list. */
|
|
33
|
+
save?: ListSave<Row>;
|
|
34
|
+
/** Columns changed by their field's key: width, header, hidden, `editable: false`, or the app's own `bind`. Keep it
|
|
35
|
+
* stable (a module constant, or `useMemo`): a new object re-binds the fields and re-answers the rows. */
|
|
36
|
+
columns?: ListColumnsOverride<Row>;
|
|
37
|
+
/** A store, or options: `{ seed }` (the app's own views), `{ records }` (the delete question's noun), `{ store }`.
|
|
38
|
+
* Default: the browser's store. */
|
|
39
|
+
views?: ViewsStore | ListViewsOptions;
|
|
40
|
+
/** What a list with no saved view shows; default the fields' columns over `LIST_SETTINGS_DEFAULTS`. */
|
|
41
|
+
defaults?: ListSettings;
|
|
42
|
+
/** The toolbar's form on a computer, as `ListRoot` takes them. */
|
|
43
|
+
sortFilter?: "right" | "bar";
|
|
44
|
+
bar?: "added" | "always";
|
|
45
|
+
/** Every menu as data: `column`, `row` and `group` reach the grid, `view`, `add` and `more` the toolbar. */
|
|
46
|
+
menus?: ListMenus<Row>;
|
|
47
|
+
/** Where each of the toolbar's parts stands (`ReadyToolbar`'s `toolbarParts`). */
|
|
48
|
+
toolbarParts?: ToolbarParts;
|
|
49
|
+
/** The address carries the open view and what changed. Default true; `false` leaves the address alone (a second list
|
|
50
|
+
* on the same page). */
|
|
51
|
+
link?: boolean;
|
|
52
|
+
/** `edit: false`: every cell read-only. `share: false`: no "Save for everyone". */
|
|
53
|
+
can?: {
|
|
54
|
+
edit?: boolean;
|
|
55
|
+
share?: boolean;
|
|
56
|
+
};
|
|
57
|
+
onOpenRow?: GridTableProps<Row>["onOpenRow"];
|
|
58
|
+
rowHref?: (row: Row) => string | undefined;
|
|
59
|
+
rowWritable?: (row: Row) => boolean;
|
|
60
|
+
onAdd?: () => void;
|
|
61
|
+
addItems?: ViewsMenuItem[];
|
|
62
|
+
quickFilters?: QuickFiltersConfig;
|
|
63
|
+
/** Any other prop of the toolbar, the grid or the bulk bar. */
|
|
64
|
+
toolbar?: Partial<ListToolbarProps<Row>>;
|
|
65
|
+
grid?: ListGridProps<Row>;
|
|
66
|
+
bulk?: ListBulkBarProps;
|
|
67
|
+
className?: string;
|
|
68
|
+
};
|
|
69
|
+
export declare function List<Row extends ListRow>({ id, fields, rows, source, pageSize, save, columns, views, defaults, sortFilter, bar, menus, toolbarParts, link, can, onOpenRow, rowHref, rowWritable, onAdd, addItems, quickFilters, toolbar, grid, bulk, className, }: ListProps<Row>): ReactNode;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ListBulkBar } from "./bulk-bar.js";
|
|
4
|
+
import { ListGrid } from "./grid.js";
|
|
5
|
+
import { ListRoot } from "./root.js";
|
|
6
|
+
import { ListToolbar } from "./toolbar.js";
|
|
7
|
+
function handed(from) {
|
|
8
|
+
return Object.fromEntries(Object.entries(from).filter(([, value]) => value !== undefined));
|
|
9
|
+
}
|
|
10
|
+
export function List({ id, fields, rows, source, pageSize, save, columns, views, defaults, sortFilter, bar, menus, toolbarParts, link = true, can, onOpenRow, rowHref, rowWritable, onAdd, addItems, quickFilters, toolbar, grid, bulk, className, }) {
|
|
11
|
+
const toolbarMenus = { ...toolbar?.menus, ...handed({ view: menus?.view, add: menus?.add, more: menus?.more }) };
|
|
12
|
+
const gridMenus = { ...grid?.menus, ...handed({ column: menus?.column, row: menus?.row, group: menus?.group }) };
|
|
13
|
+
return (_jsx(ListRoot, { id: id, fields: fields, ...(source ? { source, pageSize } : { rows }), quickFilters: quickFilters, save: save, columns: columns, views: views, defaults: defaults, sortFilter: sortFilter, bar: bar, can: can, link: link, children: _jsxs("div", { "data-slot": "vk-list", className: className, children: [_jsx(ListToolbar, { ...toolbar, ...handed({ toolbarParts, onAdd, addItems, quickFilters }), menus: toolbarMenus }), _jsx(ListGrid, { ...grid, ...handed({ onOpenRow, rowHref, rowWritable }), menus: gridMenus, children: grid?.children ?? _jsx(ListBulkBar, { ...bulk }) })] }) }));
|
|
14
|
+
}
|
package/views/dist/list/parts.js
CHANGED
|
@@ -21,7 +21,13 @@ export function placesOf(parts, ctx) {
|
|
|
21
21
|
return [...drawn("row", "start"), ...drawn("row", "end"), ...drawn("bar", "start"), ...drawn("bar", "end")];
|
|
22
22
|
}
|
|
23
23
|
const samePlaces = (a, b) => a.length === b.length &&
|
|
24
|
-
a.every((p, i) => p.key === b[i].key &&
|
|
24
|
+
a.every((p, i) => p.key === b[i].key &&
|
|
25
|
+
p.line === b[i].line &&
|
|
26
|
+
p.side === b[i].side &&
|
|
27
|
+
p.words === b[i].words &&
|
|
28
|
+
p.node === undefined &&
|
|
29
|
+
p.className === undefined &&
|
|
30
|
+
p.button === undefined);
|
|
25
31
|
export function applyParts(parts, place, ctx) {
|
|
26
32
|
const given = placesOf(parts, ctx);
|
|
27
33
|
const back = place(given, ctx);
|
|
@@ -36,10 +42,11 @@ export function applyParts(parts, place, ctx) {
|
|
|
36
42
|
seen.add(at.key);
|
|
37
43
|
const part = byKey.get(at.key);
|
|
38
44
|
const line = !one && at.line === "bar" ? 2 : 1;
|
|
45
|
+
const look = { ...(at.className && { className: at.className }), ...(at.button && { button: at.button }) };
|
|
39
46
|
if (!part)
|
|
40
|
-
return at.node === undefined ? [] : [{ key: at.key, line, side: at.side, words: at.words, node: at.node }];
|
|
47
|
+
return at.node === undefined ? [] : [{ key: at.key, line, side: at.side, words: at.words, node: at.node, ...look }];
|
|
41
48
|
const own = part.words ?? "both";
|
|
42
|
-
const next = { ...part };
|
|
49
|
+
const next = { ...part, ...look };
|
|
43
50
|
if (line !== (part.line ?? 1))
|
|
44
51
|
next.line = line;
|
|
45
52
|
if (at.side !== (part.side ?? "start"))
|
|
@@ -0,0 +1,46 @@
|
|
|
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 ListRootModes = ListSync | {
|
|
18
|
+
settings?: undefined;
|
|
19
|
+
/** Where the list's saved views are kept: a store, or options; default `browserViewsStore()`. */
|
|
20
|
+
views?: ViewsStore | ListViewsOptions;
|
|
21
|
+
/** What a list with no saved view shows, and a new view's start. Default `LIST_SETTINGS_DEFAULTS`. */
|
|
22
|
+
defaults?: ListSettings;
|
|
23
|
+
/** `true`: the address carries the open view and what changed: read as the list opens (its view and change win
|
|
24
|
+
* over the draft), written in place as it changes, read again on the browser's back and forward. A reading
|
|
25
|
+
* (`readListLink`): opened, never written. Absent or `false`: the address is left alone. Either way the open
|
|
26
|
+
* view is kept on the device, opened again where no link names one. */
|
|
27
|
+
link?: boolean | ListLinkReading;
|
|
28
|
+
sortFilter?: ListSync["sortFilter"];
|
|
29
|
+
bar?: ListSync["bar"];
|
|
30
|
+
};
|
|
31
|
+
/** The base root's props: its id, its mode, and `share: false` (no "Save for everyone", store mode). Not on the door. */
|
|
32
|
+
export type ListRootBaseProps = {
|
|
33
|
+
id: string;
|
|
34
|
+
children?: ReactNode;
|
|
35
|
+
share?: boolean;
|
|
36
|
+
} & ListRootModes;
|
|
37
|
+
export declare function ListRootBase({ id, children, share, ...props }: ListRootBaseProps): ReactNode;
|
|
38
|
+
/** The store of the list root around this part (not on the door). */
|
|
39
|
+
export declare function useListStore(): ListStore;
|
|
40
|
+
/** What this part selects of its list's state: it re-renders only when that changes (by `equal`, `Object.is` by
|
|
41
|
+
* default). Select an action as it stands (`useList((s) => s.openPanel)`): actions never change. Handed an `id` first,
|
|
42
|
+
* it reads the root of that id from anywhere under the `ViewsProvider` (VK-740): `undefined` while none stands. */
|
|
43
|
+
export declare function useList<T>(select: (state: ListState) => T, equal?: (a: T, b: T) => boolean): T;
|
|
44
|
+
export declare function useList<T>(id: string, select: (state: ListState) => T, equal?: (a: T, b: T) => boolean): T | undefined;
|
|
45
|
+
/** One of the root's panels as a part's open state and page, by its key (not on the door). */
|
|
46
|
+
export declare function useListPanel(key: string): ToolbarPanelState;
|