@viewkitjs/views 0.0.0-stage → 0.1.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 +420 -0
- package/LICENSE.md +7 -0
- package/README.md +50 -2
- package/dist/atoms/CommandMenu.d.ts +2 -0
- package/dist/atoms/CommandMenu.js +20 -0
- package/dist/atoms/List.d.ts +2 -0
- package/dist/atoms/List.js +6 -0
- package/dist/atoms/LoadMore.d.ts +2 -0
- package/dist/atoms/LoadMore.js +25 -0
- package/dist/atoms/Loading.d.ts +2 -0
- package/dist/atoms/Loading.js +7 -0
- package/dist/atoms/PlatformMark.d.ts +2 -0
- package/dist/atoms/PlatformMark.js +4 -0
- package/dist/atoms/RelationLink.d.ts +2 -0
- package/dist/atoms/RelationLink.js +6 -0
- package/dist/atoms/Row.d.ts +3 -0
- package/dist/atoms/Row.js +30 -0
- package/dist/atoms/RowMenu.d.ts +2 -0
- package/dist/atoms/RowMenu.js +101 -0
- package/dist/atoms/StatusBadge.d.ts +2 -0
- package/dist/atoms/StatusBadge.js +7 -0
- package/dist/atoms/StatusMarker.d.ts +2 -0
- package/dist/atoms/StatusMarker.js +19 -0
- package/dist/atoms/Tag.d.ts +2 -0
- package/dist/atoms/Tag.js +13 -0
- package/dist/atoms/TickBox.d.ts +2 -0
- package/dist/atoms/TickBox.js +8 -0
- package/dist/atoms/defaults.d.ts +2 -0
- package/dist/atoms/defaults.js +27 -0
- package/dist/atoms/tones.d.ts +5 -0
- package/dist/atoms/tones.js +28 -0
- package/dist/atoms/types.d.ts +178 -0
- package/dist/atoms/types.js +3 -0
- package/dist/cells/cell-format.d.ts +138 -0
- package/dist/cells/cell-format.js +16 -0
- package/dist/cells/cell-title.d.ts +17 -0
- package/dist/cells/cell-title.js +8 -0
- package/dist/cells/cell-values.d.ts +28 -0
- package/dist/cells/cell-values.js +87 -0
- package/dist/cells/index.d.ts +4 -0
- package/dist/cells/index.js +4 -0
- package/dist/cells/legacy-field.d.ts +52 -0
- package/dist/cells/legacy-field.js +164 -0
- package/dist/cells/relation-wrap.d.ts +3 -0
- package/dist/cells/relation-wrap.js +24 -0
- package/dist/cells/use-cell-format.d.ts +5 -0
- package/dist/cells/use-cell-format.js +10 -0
- package/dist/contract.d.ts +431 -0
- package/dist/contract.js +663 -0
- package/dist/display/actor.d.ts +4 -0
- package/dist/display/actor.js +26 -0
- package/dist/display/boolean.d.ts +18 -0
- package/dist/display/boolean.js +43 -0
- package/dist/display/breakdown.d.ts +15 -0
- package/dist/display/breakdown.js +32 -0
- package/dist/display/currency.d.ts +9 -0
- package/dist/display/currency.js +29 -0
- package/dist/display/date.d.ts +12 -0
- package/dist/display/date.js +26 -0
- package/dist/display/display-cores.d.ts +31 -0
- package/dist/display/display-cores.js +57 -0
- package/dist/display/entity-chip.d.ts +26 -0
- package/dist/display/entity-chip.js +9 -0
- package/dist/display/format.d.ts +51 -0
- package/dist/display/format.js +181 -0
- package/dist/display/index.d.ts +8 -0
- package/dist/display/index.js +7 -0
- package/dist/display/link.d.ts +29 -0
- package/dist/display/link.js +48 -0
- package/dist/display/location.d.ts +7 -0
- package/dist/display/location.js +15 -0
- package/dist/display/multi-value.d.ts +18 -0
- package/dist/display/multi-value.js +28 -0
- package/dist/display/name.d.ts +6 -0
- package/dist/display/name.js +14 -0
- package/dist/display/number.d.ts +11 -0
- package/dist/display/number.js +27 -0
- package/dist/display/options.d.ts +153 -0
- package/dist/display/options.js +1 -0
- package/dist/display/percent.d.ts +4 -0
- package/dist/display/percent.js +33 -0
- package/dist/display/phone.d.ts +10 -0
- package/dist/display/phone.js +38 -0
- package/dist/display/range.d.ts +6 -0
- package/dist/display/range.js +29 -0
- package/dist/display/relation.d.ts +4 -0
- package/dist/display/relation.js +29 -0
- package/dist/display/rich-text.d.ts +10 -0
- package/dist/display/rich-text.js +34 -0
- package/dist/display/select.d.ts +6 -0
- package/dist/display/select.js +38 -0
- package/dist/display/text-class.d.ts +23 -0
- package/dist/display/text-class.js +5 -0
- package/dist/display/text.d.ts +19 -0
- package/dist/display/text.js +8 -0
- package/dist/display/use-display-options.d.ts +2 -0
- package/dist/display/use-display-options.js +14 -0
- package/dist/display/user.d.ts +11 -0
- package/dist/display/user.js +10 -0
- package/dist/display/value-list.d.ts +10 -0
- package/dist/display/value-list.js +12 -0
- package/dist/display/viewer.d.ts +4 -0
- package/dist/display/viewer.js +11 -0
- package/dist/display/web-href.d.ts +8 -0
- package/dist/display/web-href.js +12 -0
- package/dist/editors/ChipsEditor.d.ts +59 -0
- package/dist/editors/ChipsEditor.js +73 -0
- package/dist/editors/DateEditor.d.ts +25 -0
- package/dist/editors/DateEditor.js +122 -0
- package/dist/editors/LocationEditor.d.ts +22 -0
- package/dist/editors/LocationEditor.js +229 -0
- package/dist/editors/NameEditor.d.ts +22 -0
- package/dist/editors/NameEditor.js +91 -0
- package/dist/editors/NumberEditor.d.ts +67 -0
- package/dist/editors/NumberEditor.js +86 -0
- package/dist/editors/RangeEditor.d.ts +22 -0
- package/dist/editors/RangeEditor.js +70 -0
- package/dist/editors/RelationEditor.d.ts +65 -0
- package/dist/editors/RelationEditor.js +64 -0
- package/dist/editors/SelectEditor.d.ts +72 -0
- package/dist/editors/SelectEditor.js +59 -0
- package/dist/editors/ValueListEditor.d.ts +38 -0
- package/dist/editors/ValueListEditor.js +217 -0
- package/dist/editors/edit-cores.d.ts +83 -0
- package/dist/editors/edit-cores.js +38 -0
- package/dist/editors/edit-session.d.ts +74 -0
- package/dist/editors/edit-session.js +35 -0
- package/dist/editors/open-values.d.ts +28 -0
- package/dist/editors/open-values.js +26 -0
- package/dist/editors/relation-source.d.ts +66 -0
- package/dist/editors/relation-source.js +102 -0
- package/dist/fields/binding.d.ts +87 -0
- package/dist/fields/binding.js +117 -0
- package/dist/fields/currency.d.ts +92 -0
- package/dist/fields/currency.js +55 -0
- package/dist/fields/denomination.d.ts +42 -0
- package/dist/fields/denomination.js +11 -0
- package/dist/fields/edit-core-types.d.ts +40 -0
- package/dist/fields/edit-core-types.js +29 -0
- package/dist/fields/format-knobs.d.ts +34 -0
- package/dist/fields/format-knobs.js +36 -0
- package/dist/fields/menus.d.ts +28 -0
- package/dist/fields/menus.js +1 -0
- package/dist/fields/money.d.ts +59 -0
- package/dist/fields/money.js +77 -0
- package/dist/fields/number-edit.d.ts +11 -0
- package/dist/fields/number-edit.js +17 -0
- package/dist/fields/prepare-write.d.ts +55 -0
- package/dist/fields/prepare-write.js +67 -0
- package/dist/fields/relation-source-types.d.ts +54 -0
- package/dist/fields/relation-source-types.js +1 -0
- package/dist/figures.d.ts +52 -0
- package/dist/figures.js +63 -0
- package/dist/filters/date-filter.d.ts +2 -0
- package/dist/filters/date-filter.js +1 -0
- package/dist/filters/filter-model.d.ts +177 -0
- package/dist/filters/filter-model.js +41 -0
- package/dist/filters/number-filter.d.ts +2 -0
- package/dist/filters/number-filter.js +1 -0
- package/dist/filters/range-filter.d.ts +2 -0
- package/dist/filters/range-filter.js +1 -0
- package/dist/filters/registry.d.ts +136 -0
- package/dist/filters/registry.js +46 -0
- package/dist/filters/relation-filter.d.ts +16 -0
- package/dist/filters/relation-filter.js +53 -0
- package/dist/filters/text-filter.d.ts +2 -0
- package/dist/filters/text-filter.js +1 -0
- package/dist/filters/types.d.ts +27 -0
- package/dist/filters/types.js +1 -0
- package/dist/grouping/sort-groups.d.ts +18 -0
- package/dist/grouping/sort-groups.js +33 -0
- package/dist/grouping/types.d.ts +10 -0
- package/dist/grouping/types.js +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +29 -0
- package/dist/internal/chip.d.ts +4 -0
- package/dist/internal/chip.js +3 -0
- package/dist/internal/cx.d.ts +3 -0
- package/dist/internal/cx.js +3 -0
- package/dist/model/aggregates.d.ts +59 -0
- package/dist/model/aggregates.js +186 -0
- package/dist/model/card-density.d.ts +8 -0
- package/dist/model/card-density.js +10 -0
- package/dist/model/card-layout.d.ts +85 -0
- package/dist/model/card-layout.js +90 -0
- package/dist/model/column-capabilities.d.ts +162 -0
- package/dist/model/column-capabilities.js +233 -0
- package/dist/model/column-filters.d.ts +106 -0
- package/dist/model/column-filters.js +321 -0
- package/dist/model/column-format.d.ts +103 -0
- package/dist/model/column-format.js +1 -0
- package/dist/model/column-from.d.ts +28 -0
- package/dist/model/column-from.js +160 -0
- package/dist/model/column-inspect.d.ts +18 -0
- package/dist/model/column-inspect.js +6 -0
- package/dist/model/column-knobs.d.ts +20 -0
- package/dist/model/column-knobs.js +16 -0
- package/dist/model/column-money.d.ts +13 -0
- package/dist/model/column-money.js +27 -0
- package/dist/model/column-order.d.ts +36 -0
- package/dist/model/column-order.js +68 -0
- package/dist/model/column-schema.d.ts +335 -0
- package/dist/model/column-schema.js +1 -0
- package/dist/model/column-sort.d.ts +17 -0
- package/dist/model/column-sort.js +11 -0
- package/dist/model/column-state.d.ts +77 -0
- package/dist/model/column-state.js +95 -0
- package/dist/model/column-types.d.ts +109 -0
- package/dist/model/column-types.js +50 -0
- package/dist/model/column-warnings.d.ts +44 -0
- package/dist/model/column-warnings.js +24 -0
- package/dist/model/density.d.ts +3 -0
- package/dist/model/density.js +13 -0
- package/dist/model/field-type-of.d.ts +21 -0
- package/dist/model/field-type-of.js +11 -0
- package/dist/model/filter-capabilities.d.ts +1 -0
- package/dist/model/filter-capabilities.js +1 -0
- package/dist/model/filter-pushdown.d.ts +106 -0
- package/dist/model/filter-pushdown.js +147 -0
- package/dist/model/index.d.ts +40 -0
- package/dist/model/index.js +21 -0
- package/dist/model/part-rows.d.ts +28 -0
- package/dist/model/part-rows.js +40 -0
- package/dist/model/preferences.d.ts +151 -0
- package/dist/model/preferences.js +84 -0
- package/dist/model/prefs-buckets.d.ts +173 -0
- package/dist/model/prefs-buckets.js +71 -0
- package/dist/model/relation-filters.d.ts +45 -0
- package/dist/model/relation-filters.js +78 -0
- package/dist/model/render-count.d.ts +2 -0
- package/dist/model/render-count.js +24 -0
- package/dist/model/row-icon.d.ts +23 -0
- package/dist/model/row-icon.js +5 -0
- package/dist/model/view-rules.d.ts +73 -0
- package/dist/model/view-rules.js +216 -0
- package/dist/provider/ViewsProvider.d.ts +26 -0
- package/dist/provider/ViewsProvider.js +12 -0
- package/dist/provider/components.d.ts +222 -0
- package/dist/provider/components.js +3 -0
- package/dist/provider/context.d.ts +19 -0
- package/dist/provider/context.js +10 -0
- package/dist/provider/icons.d.ts +6 -0
- package/dist/provider/icons.js +1 -0
- package/dist/provider/ports.d.ts +35 -0
- package/dist/provider/ports.js +8 -0
- package/dist/react.d.ts +9 -0
- package/dist/react.js +4 -0
- package/dist/selection/SelectCheckbox.d.ts +17 -0
- package/dist/selection/SelectCheckbox.js +11 -0
- package/dist/selection/index.d.ts +7 -0
- package/dist/selection/index.js +6 -0
- package/dist/selection/model.d.ts +55 -0
- package/dist/selection/model.js +86 -0
- package/dist/selection/row-click.d.ts +35 -0
- package/dist/selection/row-click.js +20 -0
- package/dist/selection/types.d.ts +17 -0
- package/dist/selection/types.js +1 -0
- package/dist/selection/useCheckDragSelect.d.ts +61 -0
- package/dist/selection/useCheckDragSelect.js +165 -0
- package/dist/selection/useListSelection.d.ts +39 -0
- package/dist/selection/useListSelection.js +48 -0
- package/dist/selection/useListSelectionShortcuts.d.ts +6 -0
- package/dist/selection/useListSelectionShortcuts.js +14 -0
- package/dist/selection/useRestIntent.d.ts +18 -0
- package/dist/selection/useRestIntent.js +35 -0
- package/docs/contract.md +453 -0
- package/docs/install.md +105 -0
- package/docs/reshaping.md +19 -0
- package/package.json +114 -3
- package/skills/views/SKILL.md +87 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { ListAggregateKind, ListDateStyle, ListDateStyleOverrides, ListDurationStyle, ListDurationStyleOverrides, ListOptionColorOverrides, ListPercentDisplayOverrides, ListSelectColor, ListShowTimeOverrides } from "./column-schema.js";
|
|
2
|
+
import type { PercentDisplay } from "@viewkitjs/fields";
|
|
3
|
+
import type { BoardLaneSpec, FilterRelationRule } from "@viewkitjs/fields/query";
|
|
4
|
+
import type { MoneyReading } from "../fields/currency.js";
|
|
5
|
+
import type { ListColumnState, ListDensity } from "./column-state.js";
|
|
6
|
+
import type { TextFilterRule } from "../filters/text-filter.js";
|
|
7
|
+
import type { NumberFilterRule } from "../filters/number-filter.js";
|
|
8
|
+
import type { DateFilterRule } from "../filters/date-filter.js";
|
|
9
|
+
import type { RangeFilterRule } from "../filters/range-filter.js";
|
|
10
|
+
/**
|
|
11
|
+
* One column's filter rule. Tagged with its editor so the persisted blob stays
|
|
12
|
+
* readable as number / date / boolean rules land beside these — a stored rule
|
|
13
|
+
* always says what kind of rule it is.
|
|
14
|
+
*/
|
|
15
|
+
export type ListFilterRule = ({
|
|
16
|
+
editor: "text";
|
|
17
|
+
} & TextFilterRule)
|
|
18
|
+
/** Status / select / multiselect: the picked values, ORed. Empty = no rule
|
|
19
|
+
* (every value passes), which is what "nothing ticked" has always meant in
|
|
20
|
+
* the option checklist. */
|
|
21
|
+
| {
|
|
22
|
+
editor: "options";
|
|
23
|
+
values: string[];
|
|
24
|
+
}
|
|
25
|
+
/** Bounds are in whatever the column DISPLAYS — on a converted money column
|
|
26
|
+
* that follows the display-currency pref, which is the only reading that
|
|
27
|
+
* agrees with the numbers on screen. */
|
|
28
|
+
| ({
|
|
29
|
+
editor: "number";
|
|
30
|
+
} & NumberFilterRule)
|
|
31
|
+
/** Relative rules keep their INTENT (`past` × `week`), so the window they
|
|
32
|
+
* mean moves with the clock instead of freezing on the day it was set. */
|
|
33
|
+
| ({
|
|
34
|
+
editor: "date";
|
|
35
|
+
} & DateFilterRule)
|
|
36
|
+
/** A range: an operator and up to two bounds, an open end null. */
|
|
37
|
+
| ({
|
|
38
|
+
editor: "range";
|
|
39
|
+
} & RangeFilterRule);
|
|
40
|
+
export type ListFilterRuleState = Record<string, ListFilterRule>;
|
|
41
|
+
/**
|
|
42
|
+
* The persisted view-style token. Two legacy values predate the view registry —
|
|
43
|
+
* `"rows"` names the list view and `"grid"` the table — and they stay written
|
|
44
|
+
* forever so a stored pref round-trips through old sessions. Views added since
|
|
45
|
+
* store their canonical registry id. The bridge in both directions lives in
|
|
46
|
+
* `binding/view-registry.ts` (`viewIdFromStored` / `storedFromViewId`).
|
|
47
|
+
*/
|
|
48
|
+
export type StoredListViewStyle = "rows" | "grid" | "board" | "calendar";
|
|
49
|
+
/** Persisted keys are load-bearing and must remain backward compatible. */
|
|
50
|
+
export type ListViewPrefs = {
|
|
51
|
+
viewStyle: StoredListViewStyle;
|
|
52
|
+
viewStyleMobile: StoredListViewStyle;
|
|
53
|
+
gridVerticalBorders: boolean;
|
|
54
|
+
/** Show the host's leading row ICON (a bare glyph) inside the title cell. */
|
|
55
|
+
gridRowIcon: boolean;
|
|
56
|
+
/** Pin the identity columns (everything through the title) to the left edge
|
|
57
|
+
* while the rest of the table scrolls under them. */
|
|
58
|
+
gridFreezeIdentity: boolean;
|
|
59
|
+
/** Cells wrap to at most 3 lines instead of truncating to one, and rows grow
|
|
60
|
+
* to fit their tallest cell. Off by default: one line per row is what makes
|
|
61
|
+
* a grid scannable, and wrapping is the deliberate trade against it. */
|
|
62
|
+
gridWrapCells: boolean;
|
|
63
|
+
/** Keep every row's checkbox on screen instead of revealing it on hover.
|
|
64
|
+
* Off by default: the rail is chrome, and a permanent column of empty boxes
|
|
65
|
+
* is a cost every row pays for a gesture used occasionally. On for anyone
|
|
66
|
+
* who selects often enough that hunting for the box is the annoyance. */
|
|
67
|
+
gridAlwaysCheckboxes: boolean;
|
|
68
|
+
gridOptionColors: ListOptionColorOverrides;
|
|
69
|
+
gridDateStyles: ListDateStyleOverrides;
|
|
70
|
+
/** Per-column duration rendering, chosen by the reader. Sparse: an absent
|
|
71
|
+
* column means the column's own `format.durationStyle` stands. */
|
|
72
|
+
gridDurationStyles: ListDurationStyleOverrides;
|
|
73
|
+
gridShowTime: ListShowTimeOverrides;
|
|
74
|
+
/** Per-field percent drawing (text, bar, ring). Sparse, like the others. */
|
|
75
|
+
gridPercentDisplays: ListPercentDisplayOverrides;
|
|
76
|
+
gridDecimals: Record<string, number>;
|
|
77
|
+
/** How each convertible money column is read — Original or one currency —
|
|
78
|
+
* keyed by FIELD key like `gridDecimals`, but the READER's own: the
|
|
79
|
+
* field-settings model says display currency stays personal, so this is
|
|
80
|
+
* neither a layout key nor a format key and rides the reader's list blob.
|
|
81
|
+
* Absent = the column's own default. */
|
|
82
|
+
gridCurrencies: Record<string, MoneyReading>;
|
|
83
|
+
gridAggregates: Record<string, ListAggregateKind>;
|
|
84
|
+
gridColumns: ListColumnState;
|
|
85
|
+
/**
|
|
86
|
+
* CALENDAR only — which date column positions the events, chosen by the
|
|
87
|
+
* reader from the list's own date columns. `null` = follow the host's
|
|
88
|
+
* declared default, and that is the resting state: the host names the axis
|
|
89
|
+
* a list opens on, and this only ever records a deliberate override.
|
|
90
|
+
*
|
|
91
|
+
* Lives in the LAYOUT bucket (the calendar view's own slot), so one answer
|
|
92
|
+
* serves every surface of a list — the ledger, a tab, an embed — the way
|
|
93
|
+
* column widths do. `useListPrefs` routes it to the `calendar` slot by name
|
|
94
|
+
* rather than to whichever view the desktop happens to be showing.
|
|
95
|
+
*/
|
|
96
|
+
calendarDateColumnId: string | null;
|
|
97
|
+
/**
|
|
98
|
+
* BOARD only — which column the board is laid out by, when the reader picked
|
|
99
|
+
* one. `null` = the list's default (`resolveBoardColumn`). Like the
|
|
100
|
+
* calendar's axis it lives in the board view's own layout slot, routed there
|
|
101
|
+
* by name whatever view the desktop shows.
|
|
102
|
+
*/
|
|
103
|
+
boardFieldId: string | null;
|
|
104
|
+
/** BOARD only — the board's hidden and placed columns, per field. */
|
|
105
|
+
boardLanes: BoardLaneSpec[];
|
|
106
|
+
/** Per-column filter rules, keyed by column id. Sparse: a column with no
|
|
107
|
+
* rule is absent, so an untouched list persists `{}`. */
|
|
108
|
+
gridFilterRules: ListFilterRuleState;
|
|
109
|
+
/** The relation rules the Filter panel's Related records rows edit, by relation field key (POR-704).
|
|
110
|
+
* Sparse. */
|
|
111
|
+
relationFilterRules: Record<string, FilterRelationRule>;
|
|
112
|
+
gridScale: ListDensity;
|
|
113
|
+
/** WHICH figures ride beside a group's name. A set, not a pick-one: the count
|
|
114
|
+
* says how many rows a group holds and the total says what they add up to,
|
|
115
|
+
* and on a spend list those are two different questions you ask at the same
|
|
116
|
+
* time. Empty = a bare group name, which is a legitimate choice. */
|
|
117
|
+
groupSummary: ListGroupSummaryPart[];
|
|
118
|
+
};
|
|
119
|
+
/** A figure after the list's first: the total under one column, named by its id (POR-1393). */
|
|
120
|
+
export type ListGroupFigurePart = `total:${string}`;
|
|
121
|
+
/** The figures a group header can carry: its count, and its totals. `total` is the list's FIRST figure, named after
|
|
122
|
+
* its own column in the menu; each later one is `total:<columnId>`. The first stays a position, not a column, so
|
|
123
|
+
* every view stored before the header offered more than one figure keeps the one it showed. */
|
|
124
|
+
export type ListGroupSummaryPart = "count" | "total" | ListGroupFigurePart;
|
|
125
|
+
/** The part that shows one figure: `total` for the list's first, `total:<columnId>` for every other. */
|
|
126
|
+
export declare function groupFigurePart(columnId: string, first: boolean): ListGroupSummaryPart;
|
|
127
|
+
/** Whether a stored value is a part a group header knows: `count`, `total`, or `total:` and a column id of 1–120
|
|
128
|
+
* characters. */
|
|
129
|
+
export declare function isGroupSummaryPart(value: unknown): value is ListGroupSummaryPart;
|
|
130
|
+
/**
|
|
131
|
+
* Reads a stored `groupSummary` back as a set.
|
|
132
|
+
*
|
|
133
|
+
* It was a single `"count" | "total"` before, so every persisted blob out there
|
|
134
|
+
* still holds a bare string — parsed here rather than migrated, because a view
|
|
135
|
+
* pref is not worth a migration and an unrecognised value should degrade to the
|
|
136
|
+
* default instead of rendering nothing.
|
|
137
|
+
*/
|
|
138
|
+
export declare function normalizeGroupSummary(value: unknown): ListGroupSummaryPart[];
|
|
139
|
+
export declare const LIST_VIEW_PREF_DEFAULTS: ListViewPrefs;
|
|
140
|
+
/** Set or drop one column's rule, keeping the map sparse (null = no rule). */
|
|
141
|
+
export declare function setFilterRule(current: ListFilterRuleState, columnId: string, rule: ListFilterRule | null): ListFilterRuleState;
|
|
142
|
+
export declare function setOptionColor(current: ListOptionColorOverrides, columnId: string, value: string, color: ListSelectColor | null): ListOptionColorOverrides;
|
|
143
|
+
export declare function setDateStyle(current: ListDateStyleOverrides, columnId: string, style: ListDateStyle): ListDateStyleOverrides;
|
|
144
|
+
/** Set one column's duration rendering, keeping the map sparse. */
|
|
145
|
+
export declare function setDurationStyle(current: ListDurationStyleOverrides, columnId: string, style: ListDurationStyle): ListDurationStyleOverrides;
|
|
146
|
+
export declare function setShowTime(current: ListShowTimeOverrides, columnId: string, show: boolean): ListShowTimeOverrides;
|
|
147
|
+
export declare function setPercentDisplay(current: ListPercentDisplayOverrides, key: string, display: PercentDisplay): ListPercentDisplayOverrides;
|
|
148
|
+
export declare function setAggregate(current: Record<string, ListAggregateKind>, columnId: string, kind: ListAggregateKind): Record<string, ListAggregateKind>;
|
|
149
|
+
export declare function setDecimals(current: Record<string, number>, columnId: string, decimals: number): Record<string, number>;
|
|
150
|
+
/** One field's reading, the others untouched — keyed by FIELD key. */
|
|
151
|
+
export declare function setCurrency(current: Record<string, MoneyReading>, fieldKey: string, reading: MoneyReading): Record<string, MoneyReading>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const FIGURE_PREFIX = "total:";
|
|
2
|
+
const FIGURE_KEY_MAX = 120;
|
|
3
|
+
export function groupFigurePart(columnId, first) {
|
|
4
|
+
return first ? "total" : `${FIGURE_PREFIX}${columnId}`;
|
|
5
|
+
}
|
|
6
|
+
export function isGroupSummaryPart(value) {
|
|
7
|
+
if (value === "count" || value === "total")
|
|
8
|
+
return true;
|
|
9
|
+
if (typeof value !== "string" || !value.startsWith(FIGURE_PREFIX))
|
|
10
|
+
return false;
|
|
11
|
+
const key = value.length - FIGURE_PREFIX.length;
|
|
12
|
+
return key >= 1 && key <= FIGURE_KEY_MAX;
|
|
13
|
+
}
|
|
14
|
+
export function normalizeGroupSummary(value) {
|
|
15
|
+
const parts = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
|
|
16
|
+
return Array.from(new Set(parts.filter(isGroupSummaryPart)));
|
|
17
|
+
}
|
|
18
|
+
export const LIST_VIEW_PREF_DEFAULTS = {
|
|
19
|
+
viewStyle: "grid",
|
|
20
|
+
viewStyleMobile: "rows",
|
|
21
|
+
gridVerticalBorders: false,
|
|
22
|
+
gridRowIcon: true,
|
|
23
|
+
gridFreezeIdentity: false,
|
|
24
|
+
gridWrapCells: false,
|
|
25
|
+
gridAlwaysCheckboxes: false,
|
|
26
|
+
gridOptionColors: {},
|
|
27
|
+
gridDateStyles: {},
|
|
28
|
+
gridDurationStyles: {},
|
|
29
|
+
gridShowTime: {},
|
|
30
|
+
gridPercentDisplays: {},
|
|
31
|
+
gridDecimals: {},
|
|
32
|
+
gridCurrencies: {},
|
|
33
|
+
gridAggregates: {},
|
|
34
|
+
gridColumns: {},
|
|
35
|
+
calendarDateColumnId: null,
|
|
36
|
+
boardFieldId: null,
|
|
37
|
+
boardLanes: [],
|
|
38
|
+
gridFilterRules: {},
|
|
39
|
+
relationFilterRules: {},
|
|
40
|
+
gridScale: "default",
|
|
41
|
+
groupSummary: ["count"],
|
|
42
|
+
};
|
|
43
|
+
export function setFilterRule(current, columnId, rule) {
|
|
44
|
+
const next = { ...current };
|
|
45
|
+
if (rule == null)
|
|
46
|
+
delete next[columnId];
|
|
47
|
+
else
|
|
48
|
+
next[columnId] = rule;
|
|
49
|
+
return next;
|
|
50
|
+
}
|
|
51
|
+
export function setOptionColor(current, columnId, value, color) {
|
|
52
|
+
const column = { ...(current[columnId] ?? {}) };
|
|
53
|
+
if (color == null)
|
|
54
|
+
delete column[value];
|
|
55
|
+
else
|
|
56
|
+
column[value] = color;
|
|
57
|
+
const next = { ...current };
|
|
58
|
+
if (Object.keys(column).length === 0)
|
|
59
|
+
delete next[columnId];
|
|
60
|
+
else
|
|
61
|
+
next[columnId] = column;
|
|
62
|
+
return next;
|
|
63
|
+
}
|
|
64
|
+
export function setDateStyle(current, columnId, style) {
|
|
65
|
+
return { ...current, [columnId]: style };
|
|
66
|
+
}
|
|
67
|
+
export function setDurationStyle(current, columnId, style) {
|
|
68
|
+
return { ...current, [columnId]: style };
|
|
69
|
+
}
|
|
70
|
+
export function setShowTime(current, columnId, show) {
|
|
71
|
+
return { ...current, [columnId]: show };
|
|
72
|
+
}
|
|
73
|
+
export function setPercentDisplay(current, key, display) {
|
|
74
|
+
return { ...current, [key]: display };
|
|
75
|
+
}
|
|
76
|
+
export function setAggregate(current, columnId, kind) {
|
|
77
|
+
return { ...current, [columnId]: kind };
|
|
78
|
+
}
|
|
79
|
+
export function setDecimals(current, columnId, decimals) {
|
|
80
|
+
return { ...current, [columnId]: decimals };
|
|
81
|
+
}
|
|
82
|
+
export function setCurrency(current, fieldKey, reading) {
|
|
83
|
+
return { ...current, [fieldKey]: reading };
|
|
84
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { ListColumnState, ListDensity } from "./column-state.js";
|
|
2
|
+
import type { ListDateStyle, ListDurationStyle, ListSelectColor } from "./column-schema.js";
|
|
3
|
+
import type { PercentDisplay } from "@viewkitjs/fields";
|
|
4
|
+
import type { BoardLaneSpec } from "@viewkitjs/fields/query";
|
|
5
|
+
import type { MoneyReading } from "../fields/currency.js";
|
|
6
|
+
/**
|
|
7
|
+
* WHAT A LIST PERSISTS, AND WHERE.
|
|
8
|
+
*
|
|
9
|
+
* It used to be ONE flat object of ~28 keys, stored per SURFACE. Executions
|
|
10
|
+
* alone has five surfaces ("executions", "executions:campaign", ":lead",
|
|
11
|
+
* ":search", ":workflow"), so it had five private copies of the same column
|
|
12
|
+
* widths — widen Cost on the campaign tab and the standalone page never heard
|
|
13
|
+
* about it. The blob was per-surface *because of the filters* in it, and the
|
|
14
|
+
* layout was along for the ride.
|
|
15
|
+
*
|
|
16
|
+
* Separated by what each thing actually follows:
|
|
17
|
+
*
|
|
18
|
+
* LAYOUT → (list, view) — widths, order, visibility, density. One answer
|
|
19
|
+
* per view, shared by every surface of that list.
|
|
20
|
+
* Hiding a column in the grid leaves the table's
|
|
21
|
+
* columns alone, which is the point.
|
|
22
|
+
* FORMAT → the workspace's field settings (`system.field_settings`) — not
|
|
23
|
+
* a pref bucket at all, since 2026-09-16. How a
|
|
24
|
+
* FIELD reads is the same in every view, on every
|
|
25
|
+
* surface, for every member; the address is
|
|
26
|
+
* (entity, field key).
|
|
27
|
+
* FILTERS → (surface) — statuses, ranges, which campaign. Unchanged, and
|
|
28
|
+
* genuinely a property of the surface.
|
|
29
|
+
*
|
|
30
|
+
* No database migration for the layout bucket: it is a `page_key` in the
|
|
31
|
+
* existing `user_view_prefs` table.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* The reader's own defaults — today, one knob: whether a table draws rules
|
|
35
|
+
* between its columns. A view that stores no `verticalBorders` of its own
|
|
36
|
+
* follows this; a view that stores one differs from it on purpose.
|
|
37
|
+
*/
|
|
38
|
+
export type ListDefaults = {
|
|
39
|
+
verticalBorders?: boolean;
|
|
40
|
+
};
|
|
41
|
+
/** One view's layout. The grid-only chrome is optional; the rows views ignore it. */
|
|
42
|
+
export type ListViewLayout = {
|
|
43
|
+
columns: ListColumnState;
|
|
44
|
+
density: ListDensity;
|
|
45
|
+
verticalBorders?: boolean;
|
|
46
|
+
rowIcon?: boolean;
|
|
47
|
+
freezeIdentity?: boolean;
|
|
48
|
+
wrapCells?: boolean;
|
|
49
|
+
alwaysCheckboxes?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* CALENDAR only — which date column positions the events, when the reader has
|
|
52
|
+
* picked one. Absent = follow the host's declared default, which is the whole
|
|
53
|
+
* meaning of absence here: a stored id would freeze a choice nobody made.
|
|
54
|
+
*
|
|
55
|
+
* The one key `readViewLayout` below does NOT resolve to a non-undefined
|
|
56
|
+
* value, because "unset" is a real state rather than a missing default. The
|
|
57
|
+
* flat shape spells it `null` (`ListViewPrefs.calendarDateColumnId`).
|
|
58
|
+
*/
|
|
59
|
+
dateColumnId?: string;
|
|
60
|
+
/** BOARD only — carried, never defaulted, like `dateColumnId`: the column the
|
|
61
|
+
* board is laid out by, when the reader picked one. */
|
|
62
|
+
boardFieldId?: string;
|
|
63
|
+
/** BOARD only — carried, never defaulted, like `dateColumnId`: the board's
|
|
64
|
+
* hidden and placed columns, per field. */
|
|
65
|
+
boardLanes?: BoardLaneSpec[];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* What is actually STORED for a view — only the keys someone set.
|
|
69
|
+
*
|
|
70
|
+
* Partial on purpose, and the distinction from `ListViewLayout` (the resolved
|
|
71
|
+
* shape every consumer reads) is the whole inheritance model: an absent key
|
|
72
|
+
* follows the reader's default, so a key is written only when this view is
|
|
73
|
+
* meant to differ from it.
|
|
74
|
+
*/
|
|
75
|
+
export type StoredViewLayout = Partial<ListViewLayout>;
|
|
76
|
+
/** Wrapped in `views` rather than being a bare map so the bucket can grow a
|
|
77
|
+
* sibling key (a preset pointer, say) without colliding with a view id. */
|
|
78
|
+
export type ListLayoutBucket = {
|
|
79
|
+
views: Record<string, StoredViewLayout>;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The reader's defaults, stored under their own `page_key` in
|
|
83
|
+
* `user_view_prefs` — the same per-user, cross-device store every list layout
|
|
84
|
+
* already uses, and one the shell seeds server-side in a single blob, so
|
|
85
|
+
* reading them costs no request of their own.
|
|
86
|
+
*/
|
|
87
|
+
export declare const LIST_DEFAULTS_KEY = "list:defaults";
|
|
88
|
+
/**
|
|
89
|
+
* The reader's per-column MONEY READINGS for one list — Original or one
|
|
90
|
+
* currency per convertible column, keyed by FIELD key. The reader's own (the
|
|
91
|
+
* field-settings model keeps display currency personal), and one blob per
|
|
92
|
+
* LIST under its own `page_key`, whichever hook a mount reads prefs through:
|
|
93
|
+
* `useListPrefs` and `useListViews` both read and write this key, so a pick in
|
|
94
|
+
* the Amount header menu means the same thing on every view of the list.
|
|
95
|
+
*/
|
|
96
|
+
export type ListMoneyBucket = {
|
|
97
|
+
gridCurrencies: Record<string, MoneyReading>;
|
|
98
|
+
};
|
|
99
|
+
export declare const EMPTY_MONEY_BUCKET: ListMoneyBucket;
|
|
100
|
+
export declare function moneyKey(listKey: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* How a FIELD reads — the workspace's shared answer (system.field_settings),
|
|
103
|
+
* identical in every view and on every surface. The flat maps in
|
|
104
|
+
* `ListViewPrefs` are this shape spread per key, keyed by FIELD KEY.
|
|
105
|
+
*/
|
|
106
|
+
export type ListFieldFormatPrefs = {
|
|
107
|
+
decimals?: number;
|
|
108
|
+
currency?: string;
|
|
109
|
+
dateStyle?: ListDateStyle;
|
|
110
|
+
durationStyle?: ListDurationStyle;
|
|
111
|
+
withTime?: boolean;
|
|
112
|
+
optionColors?: Record<string, ListSelectColor>;
|
|
113
|
+
percentDisplay?: PercentDisplay;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* One view's layout, fully resolved — every key this bucket can carry has a
|
|
117
|
+
* value here.
|
|
118
|
+
*
|
|
119
|
+
* Completeness is load-bearing, not tidiness. `layoutToFlat` emits all seven
|
|
120
|
+
* keys unconditionally and spreads them over the surface blob, so a key absent
|
|
121
|
+
* here arrived as `undefined` and silently beat the flat default it was meant
|
|
122
|
+
* to inherit. Two partial sources made the effective default depend on which
|
|
123
|
+
* view id a list had written under and whether the legacy hoist had run.
|
|
124
|
+
*/
|
|
125
|
+
export declare const LIST_LAYOUT_DEFAULTS: ListViewLayout;
|
|
126
|
+
/** What vertical borders resolve to for a view that has no answer of its own:
|
|
127
|
+
* the reader's default, or the shipped one when they never set it. */
|
|
128
|
+
export declare function verticalBordersDefault(defaults?: ListDefaults): boolean;
|
|
129
|
+
export declare const EMPTY_LAYOUT_BUCKET: ListLayoutBucket;
|
|
130
|
+
export declare function layoutKey(listKey: string): string;
|
|
131
|
+
/**
|
|
132
|
+
* One view's layout with every optional key resolved.
|
|
133
|
+
*
|
|
134
|
+
* Coalesces PER KEY rather than spreading the stored partial: `hoistLegacyPrefs`
|
|
135
|
+
* writes an explicit `undefined` for any boolean the legacy blob lacked, and a
|
|
136
|
+
* spread lets that undefined win over the default. A stored `false` still wins,
|
|
137
|
+
* which is the distinction `??` gets right and `||` would not.
|
|
138
|
+
*/
|
|
139
|
+
export declare function readViewLayout(bucket: ListLayoutBucket, viewId: string, defaults?: ListDefaults): ListViewLayout;
|
|
140
|
+
/**
|
|
141
|
+
* Patch one view's layout, leaving every other view's untouched.
|
|
142
|
+
*
|
|
143
|
+
* The patch lands on what is STORED, never on the resolved layout. Merging
|
|
144
|
+
* onto the resolved one wrote every knob the first time anyone dragged a
|
|
145
|
+
* column, so one edit opted the view out of the reader's default for good.
|
|
146
|
+
*
|
|
147
|
+
* Vertical borders written back to the effective default clear the key
|
|
148
|
+
* instead of storing it: setting the switch to what the default says IS
|
|
149
|
+
* "follow the default again" — the switch stays a switch, and the row's reset
|
|
150
|
+
* is the same write. A key set to `undefined` is dropped for the same reason.
|
|
151
|
+
*/
|
|
152
|
+
export declare function writeViewLayout(bucket: ListLayoutBucket, viewId: string, patch: StoredViewLayout, defaults?: ListDefaults): ListLayoutBucket;
|
|
153
|
+
type LegacyBlob = Record<string, unknown>;
|
|
154
|
+
/**
|
|
155
|
+
* Read-time promotion of a pre-bucket blob.
|
|
156
|
+
*
|
|
157
|
+
* Existing users have their tables configured in the old shape; the buckets
|
|
158
|
+
* start empty, so without this every configured grid would silently reset to
|
|
159
|
+
* defaults on first load. Whichever surface is opened first wins, and the other
|
|
160
|
+
* four copies are simply left behind — they described the same list.
|
|
161
|
+
*
|
|
162
|
+
* Idempotent and side-effect free: a blob with no legacy keys yields the
|
|
163
|
+
* defaults, so a caller may run it on every read and only persist once the user
|
|
164
|
+
* actually changes something.
|
|
165
|
+
*
|
|
166
|
+
* Everything it does NOT touch is deliberate: filters, sort and grouping stay
|
|
167
|
+
* in the surface blob where they belong, and format choices live in the
|
|
168
|
+
* workspace's field settings — there is nothing of theirs to hoist.
|
|
169
|
+
*/
|
|
170
|
+
export declare function hoistLegacyPrefs(legacy: LegacyBlob): {
|
|
171
|
+
layout: ListLayoutBucket;
|
|
172
|
+
};
|
|
173
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const LIST_DEFAULTS_KEY = "list:defaults";
|
|
2
|
+
export const EMPTY_MONEY_BUCKET = Object.freeze({
|
|
3
|
+
gridCurrencies: Object.freeze({}),
|
|
4
|
+
});
|
|
5
|
+
export function moneyKey(listKey) {
|
|
6
|
+
return `list:${listKey}:money`;
|
|
7
|
+
}
|
|
8
|
+
export const LIST_LAYOUT_DEFAULTS = {
|
|
9
|
+
columns: {},
|
|
10
|
+
density: "default",
|
|
11
|
+
verticalBorders: false,
|
|
12
|
+
rowIcon: true,
|
|
13
|
+
freezeIdentity: false,
|
|
14
|
+
wrapCells: false,
|
|
15
|
+
alwaysCheckboxes: false,
|
|
16
|
+
};
|
|
17
|
+
export function verticalBordersDefault(defaults) {
|
|
18
|
+
return defaults?.verticalBorders ?? LIST_LAYOUT_DEFAULTS.verticalBorders;
|
|
19
|
+
}
|
|
20
|
+
export const EMPTY_LAYOUT_BUCKET = { views: {} };
|
|
21
|
+
export function layoutKey(listKey) {
|
|
22
|
+
return `list:${listKey}:layout`;
|
|
23
|
+
}
|
|
24
|
+
export function readViewLayout(bucket, viewId, defaults) {
|
|
25
|
+
const stored = bucket.views?.[viewId];
|
|
26
|
+
return {
|
|
27
|
+
columns: stored?.columns ?? LIST_LAYOUT_DEFAULTS.columns,
|
|
28
|
+
density: stored?.density ?? LIST_LAYOUT_DEFAULTS.density,
|
|
29
|
+
verticalBorders: stored?.verticalBorders ?? verticalBordersDefault(defaults),
|
|
30
|
+
rowIcon: stored?.rowIcon ?? LIST_LAYOUT_DEFAULTS.rowIcon,
|
|
31
|
+
freezeIdentity: stored?.freezeIdentity ?? LIST_LAYOUT_DEFAULTS.freezeIdentity,
|
|
32
|
+
wrapCells: stored?.wrapCells ?? LIST_LAYOUT_DEFAULTS.wrapCells,
|
|
33
|
+
alwaysCheckboxes: stored?.alwaysCheckboxes ?? LIST_LAYOUT_DEFAULTS.alwaysCheckboxes,
|
|
34
|
+
...(stored?.dateColumnId ? { dateColumnId: stored.dateColumnId } : {}),
|
|
35
|
+
...(stored?.boardFieldId ? { boardFieldId: stored.boardFieldId } : {}),
|
|
36
|
+
...(stored?.boardLanes?.length ? { boardLanes: stored.boardLanes } : {}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function writeViewLayout(bucket, viewId, patch, defaults) {
|
|
40
|
+
const next = { ...bucket.views?.[viewId], ...patch };
|
|
41
|
+
if (next.verticalBorders === verticalBordersDefault(defaults))
|
|
42
|
+
delete next.verticalBorders;
|
|
43
|
+
for (const key of Object.keys(next)) {
|
|
44
|
+
if (next[key] === undefined)
|
|
45
|
+
delete next[key];
|
|
46
|
+
}
|
|
47
|
+
return { ...bucket, views: { ...bucket.views, [viewId]: next } };
|
|
48
|
+
}
|
|
49
|
+
function pick(blob, key) {
|
|
50
|
+
return blob[key];
|
|
51
|
+
}
|
|
52
|
+
function present(slot) {
|
|
53
|
+
return Object.fromEntries(Object.entries(slot).filter(([, value]) => value !== undefined));
|
|
54
|
+
}
|
|
55
|
+
export function hoistLegacyPrefs(legacy) {
|
|
56
|
+
const layout = {
|
|
57
|
+
views: {
|
|
58
|
+
table: present({
|
|
59
|
+
columns: pick(legacy, "gridColumns") ?? {},
|
|
60
|
+
density: pick(legacy, "gridScale"),
|
|
61
|
+
verticalBorders: pick(legacy, "gridVerticalBorders"),
|
|
62
|
+
rowIcon: pick(legacy, "gridRowIcon"),
|
|
63
|
+
freezeIdentity: pick(legacy, "gridFreezeIdentity"),
|
|
64
|
+
wrapCells: pick(legacy, "gridWrapCells"),
|
|
65
|
+
alwaysCheckboxes: pick(legacy, "gridAlwaysCheckboxes"),
|
|
66
|
+
}),
|
|
67
|
+
list: {},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
return { layout };
|
|
71
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type FieldDef } from "@viewkitjs/fields";
|
|
3
|
+
import type { FilterRelationRule } from "@viewkitjs/fields/query";
|
|
4
|
+
import type { FilterConfigRelation } from "../filters/filter-model.js";
|
|
5
|
+
import type { ListColumn } from "./column-schema.js";
|
|
6
|
+
export type RelationFilterTarget = {
|
|
7
|
+
/** The far entity's kind: "campaign". */
|
|
8
|
+
kind: string;
|
|
9
|
+
/** The relation's own label on the list's entity: "Campaigns". */
|
|
10
|
+
label: string;
|
|
11
|
+
/** The far fields a Where rule may name. */
|
|
12
|
+
fields: Readonly<Record<string, FieldDef>>;
|
|
13
|
+
/** The far fields whose values the list's route answers by name (POR-1548): a far relation, user or actor the
|
|
14
|
+
* builder can name. A far field left out stays greyed. */
|
|
15
|
+
named?: readonly string[];
|
|
16
|
+
};
|
|
17
|
+
/** What separates a far path's hops and its far field (POR-1548): `executions.campaign`. A field key never holds one. */
|
|
18
|
+
export declare const FAR_PATH_SEPARATOR = ".";
|
|
19
|
+
/** A far field's path, as the list's route answers its values: the relation's key (itself a two-hop path, `a.b`, for
|
|
20
|
+
* a rollup's second hop) and the far field's. */
|
|
21
|
+
export declare function farPathOf(relationKey: string, farKey: string): string;
|
|
22
|
+
export declare const RELATED_RECORDS_SECTION = "Related records";
|
|
23
|
+
/** A Related records row's key, from the relation's field key. */
|
|
24
|
+
export declare function relationFilterKey(fieldKey: string): string;
|
|
25
|
+
/** The relation's field key, back from a Related records row's key. */
|
|
26
|
+
export declare function relationFieldKeyOf(filterKey: string): string;
|
|
27
|
+
type FarRow = Record<string, unknown>;
|
|
28
|
+
/** The far values a host answers by path (POR-1548): the list's `openValues`, keyed by `farPathOf`. */
|
|
29
|
+
export type FarValues = {
|
|
30
|
+
values: Readonly<Record<string, readonly string[]>>;
|
|
31
|
+
labels?: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
32
|
+
onWanted: (path: string) => void;
|
|
33
|
+
};
|
|
34
|
+
export declare function buildRelationFilters({ targets, rules, onRuleChange, subject, icon, fieldIcon, farValues, }: {
|
|
35
|
+
targets: Readonly<Record<string, RelationFilterTarget>>;
|
|
36
|
+
rules: Readonly<Record<string, FilterRelationRule>>;
|
|
37
|
+
onRuleChange: (fieldKey: string, rule: FilterRelationRule | null) => void;
|
|
38
|
+
/** What the list's rows are, plural and lower case: "clients". */
|
|
39
|
+
subject: string;
|
|
40
|
+
icon?: ReactNode;
|
|
41
|
+
fieldIcon?: (col: ListColumn<FarRow>) => ReactNode;
|
|
42
|
+
/** The far values the host answers by path (POR-1548). Absent: every far relation, user or actor stays greyed. */
|
|
43
|
+
farValues?: FarValues;
|
|
44
|
+
}): FilterConfigRelation[];
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { presentedDef, valueTypeOf } from "@viewkitjs/fields";
|
|
2
|
+
import { canChooseEvery, whereRulesOf, withWhereRule } from "../filters/relation-filter.js";
|
|
3
|
+
import { buildColumnFilters } from "./column-filters.js";
|
|
4
|
+
export const FAR_PATH_SEPARATOR = ".";
|
|
5
|
+
export function farPathOf(relationKey, farKey) {
|
|
6
|
+
return `${relationKey}${FAR_PATH_SEPARATOR}${farKey}`;
|
|
7
|
+
}
|
|
8
|
+
export const RELATED_RECORDS_SECTION = "Related records";
|
|
9
|
+
const RELATION_KEY_PREFIX = "relation:";
|
|
10
|
+
export function relationFilterKey(fieldKey) {
|
|
11
|
+
return `${RELATION_KEY_PREFIX}${fieldKey}`;
|
|
12
|
+
}
|
|
13
|
+
export function relationFieldKeyOf(filterKey) {
|
|
14
|
+
return filterKey.startsWith(RELATION_KEY_PREFIX) ? filterKey.slice(RELATION_KEY_PREFIX.length) : filterKey;
|
|
15
|
+
}
|
|
16
|
+
const NAMED_TYPES = new Set(["relation", "user", "actor"]);
|
|
17
|
+
const GREYED = new Set(["relation", "user", "actor", "location"]);
|
|
18
|
+
const OPTION_TYPES = new Set(["select", "status", "multiselect"]);
|
|
19
|
+
function farColumn(key, def, named) {
|
|
20
|
+
const type = valueTypeOf(def);
|
|
21
|
+
const presented = presentedDef(def);
|
|
22
|
+
const greyed = (GREYED.has(type) && !(named && NAMED_TYPES.has(type))) || (OPTION_TYPES.has(type) && !presented.options?.length);
|
|
23
|
+
return {
|
|
24
|
+
id: key,
|
|
25
|
+
header: def.label,
|
|
26
|
+
width: 0,
|
|
27
|
+
...(type === "location"
|
|
28
|
+
? {}
|
|
29
|
+
: { type: (def.identity && type === "text" ? "title" : type) }),
|
|
30
|
+
field: def,
|
|
31
|
+
...(presented.options ? { options: presented.options.map(({ value, label }) => ({ value, label })) } : {}),
|
|
32
|
+
...(greyed ? {} : { accessor: (row) => row[def.key] }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function buildRelationFilters({ targets, rules, onRuleChange, subject, icon, fieldIcon, farValues, }) {
|
|
36
|
+
return Object.entries(targets).map(([key, target]) => {
|
|
37
|
+
const rule = rules[key] ?? null;
|
|
38
|
+
const named = new Set(farValues ? (target.named ?? []) : []);
|
|
39
|
+
const byFarKey = (read) => {
|
|
40
|
+
const out = {};
|
|
41
|
+
for (const farKey of named) {
|
|
42
|
+
const value = read(farPathOf(key, farKey));
|
|
43
|
+
if (value !== undefined)
|
|
44
|
+
out[farKey] = value;
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
};
|
|
48
|
+
const where = buildColumnFilters({
|
|
49
|
+
columns: Object.entries(target.fields).map(([farKey, def]) => farColumn(farKey, def, named.has(farKey))),
|
|
50
|
+
rules: whereRulesOf(rule, target.fields),
|
|
51
|
+
onRuleChange: (farKey, listRule) => onRuleChange(key, withWhereRule(key, rule, target.fields[farKey], listRule, target.fields)),
|
|
52
|
+
icon: fieldIcon,
|
|
53
|
+
...(farValues && named.size
|
|
54
|
+
? {
|
|
55
|
+
knownValues: byFarKey((path) => farValues.values[path]),
|
|
56
|
+
knownLabels: byFarKey((path) => farValues.labels?.[path]),
|
|
57
|
+
onValuesWanted: (farKey) => {
|
|
58
|
+
if (named.has(farKey))
|
|
59
|
+
farValues.onWanted(farPathOf(key, farKey));
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
: {}),
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
key: relationFilterKey(key),
|
|
66
|
+
label: target.label,
|
|
67
|
+
icon,
|
|
68
|
+
section: RELATED_RECORDS_SECTION,
|
|
69
|
+
editor: "relation",
|
|
70
|
+
value: rule,
|
|
71
|
+
onChange: (next) => onRuleChange(key, next),
|
|
72
|
+
noun: { one: target.kind.replaceAll("-", " "), many: target.label.toLowerCase() },
|
|
73
|
+
subject,
|
|
74
|
+
where,
|
|
75
|
+
canEvery: canChooseEvery(rule, target.fields),
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
let on = null;
|
|
2
|
+
let rendered = 0;
|
|
3
|
+
function counting() {
|
|
4
|
+
if (typeof window === "undefined")
|
|
5
|
+
return false;
|
|
6
|
+
if (on === null) {
|
|
7
|
+
try {
|
|
8
|
+
on = window.localStorage.getItem("perf") === "1";
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
on = false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return on;
|
|
15
|
+
}
|
|
16
|
+
export function countRowRender() {
|
|
17
|
+
if (counting())
|
|
18
|
+
rendered += 1;
|
|
19
|
+
}
|
|
20
|
+
export function takeRowRenders() {
|
|
21
|
+
const count = rendered;
|
|
22
|
+
rendered = 0;
|
|
23
|
+
return count;
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StatusSlot } from "@viewkitjs/fields/design/status-slots";
|
|
2
|
+
/**
|
|
3
|
+
* The glyph's tint. Semantic slots only — a row icon that carries color is
|
|
4
|
+
* saying something about STATE, which is the one thing worth spending color on
|
|
5
|
+
* here. Omit it (the overwhelmingly common case) and the chassis draws the
|
|
6
|
+
* glyph in its secondary text colour.
|
|
7
|
+
*/
|
|
8
|
+
export type ListRowIconTone = StatusSlot;
|
|
9
|
+
/** A bare glyph, optionally tinted. Bare on purpose: the row is ~37px, which an
|
|
10
|
+
* avatar component dwarfs. */
|
|
11
|
+
export type ListRowIcon = {
|
|
12
|
+
icon: string;
|
|
13
|
+
tone?: ListRowIconTone;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* What a list declares. Return the icon alone for the neutral default, or the
|
|
17
|
+
* descriptor object to tint it. `null` skips the glyph for that row.
|
|
18
|
+
*/
|
|
19
|
+
export type ListRowIconAccessor<Row> = (row: Row) => string | ListRowIcon | null;
|
|
20
|
+
/** Collapses both accepted return shapes into the descriptor form. A bare glyph
|
|
21
|
+
* is a vocabulary name — a string — and the descriptor is an object, so the two
|
|
22
|
+
* shapes no longer need a discriminating key to tell them apart. */
|
|
23
|
+
export declare function normalizeRowIcon(value: string | ListRowIcon | null): ListRowIcon | null;
|