@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,177 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { FilterRelationRule } from "@viewkitjs/fields/query";
|
|
3
|
+
import { type TextFilterRule } from "./text-filter.js";
|
|
4
|
+
import { type NumberFilterRule } from "./number-filter.js";
|
|
5
|
+
import { type DateFilterRule } from "./date-filter.js";
|
|
6
|
+
import { type RangeFilterRule } from "./range-filter.js";
|
|
7
|
+
/**
|
|
8
|
+
* The filter dimension contracts — one variant per editor.
|
|
9
|
+
*
|
|
10
|
+
* Split out of `model.ts` because the union grew a member per column type
|
|
11
|
+
* (options, text, number, date) and kept growing; the rest of the view-control
|
|
12
|
+
* contracts have nothing to do with it. Server-safe, like its parent: no
|
|
13
|
+
* `"use client"`, no hooks, no JSX.
|
|
14
|
+
*/
|
|
15
|
+
export type FilterOption<T extends string = string> = {
|
|
16
|
+
value: T;
|
|
17
|
+
label: string;
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
export type FilterKind = "status" | "category" | "metric" | "entity";
|
|
21
|
+
export type FilterConfigBase = {
|
|
22
|
+
key: string;
|
|
23
|
+
label: string;
|
|
24
|
+
icon?: ReactNode;
|
|
25
|
+
/** Drives the default row icon via the shared kind-to-icon map. */
|
|
26
|
+
kind?: FilterKind;
|
|
27
|
+
countsAsFilter?: boolean;
|
|
28
|
+
renderAs?: "filter" | "timeScope";
|
|
29
|
+
/**
|
|
30
|
+
* The dimension is LISTED but not openable — it has no editor on this
|
|
31
|
+
* surface yet. Used by the column-derived filter list so a table's full set
|
|
32
|
+
* of columns reads as one inventory (the way Notion lists every property)
|
|
33
|
+
* instead of silently hiding the ones whose type has no filter editor.
|
|
34
|
+
* A disabled row is never active, never counted, never cleared.
|
|
35
|
+
*/
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Renders the row under its own labelled section instead of the plain list.
|
|
39
|
+
* Same shape and intent as `ToggleConfig.section`. Rows sharing a section
|
|
40
|
+
* string group together; unsectioned rows always render first.
|
|
41
|
+
*/
|
|
42
|
+
section?: string;
|
|
43
|
+
/** Overrides the derived right-hand summary ("All types", "3 selected"). */
|
|
44
|
+
valueLabel?: string;
|
|
45
|
+
/** The row's detail opened (POR-845): a host may ask for what it offers — an open field's values, read from
|
|
46
|
+
* the database rather than the rows on screen. Called once per opening. */
|
|
47
|
+
onOpen?: () => void;
|
|
48
|
+
};
|
|
49
|
+
export type FilterConfigSingle<T extends string = string> = FilterConfigBase & {
|
|
50
|
+
/** Declared absent so `editor` discriminates the union — without it, a filter
|
|
51
|
+
* literal that omits `editor` is ambiguous and its `onChange` parameter
|
|
52
|
+
* silently loses its type. */
|
|
53
|
+
editor?: undefined;
|
|
54
|
+
multi?: false;
|
|
55
|
+
value: T;
|
|
56
|
+
onChange: (value: T) => void;
|
|
57
|
+
options: FilterOption<T>[];
|
|
58
|
+
allValue?: T;
|
|
59
|
+
allLabel?: string;
|
|
60
|
+
hideAllOption?: boolean;
|
|
61
|
+
renderOption?: (option: FilterOption<T>) => ReactNode;
|
|
62
|
+
renderLeading?: (option: FilterOption<T>) => ReactNode;
|
|
63
|
+
renderTrailing?: (option: FilterOption<T>) => ReactNode;
|
|
64
|
+
contentClassName?: string;
|
|
65
|
+
};
|
|
66
|
+
export type FilterConfigMulti<T extends string = string> = FilterConfigBase & {
|
|
67
|
+
editor?: undefined;
|
|
68
|
+
multi: true;
|
|
69
|
+
value: T[];
|
|
70
|
+
onChange: (value: T[]) => void;
|
|
71
|
+
options: FilterOption<T>[];
|
|
72
|
+
emptyLabel?: string;
|
|
73
|
+
renderOption?: (option: FilterOption<T>) => ReactNode;
|
|
74
|
+
renderLeading?: (option: FilterOption<T>) => ReactNode;
|
|
75
|
+
renderTrailing?: (option: FilterOption<T>) => ReactNode;
|
|
76
|
+
contentClassName?: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* A free-text dimension: one operator + one query, against one text column.
|
|
80
|
+
* Its `value` is a RULE rather than a chosen option, which is why it can't be
|
|
81
|
+
* expressed as an option filter — see `text-filter.ts` for why that rule is
|
|
82
|
+
* data and not a predicate.
|
|
83
|
+
*/
|
|
84
|
+
export type FilterConfigText = FilterConfigBase & {
|
|
85
|
+
editor: "text";
|
|
86
|
+
/** Absent on the option variants, so `editor` discriminates the union. */
|
|
87
|
+
multi?: undefined;
|
|
88
|
+
value: TextFilterRule | null;
|
|
89
|
+
onChange: (next: TextFilterRule | null) => void;
|
|
90
|
+
};
|
|
91
|
+
/** A numeric dimension: an operator plus one bound, or two for a range. */
|
|
92
|
+
export type FilterConfigNumber = FilterConfigBase & {
|
|
93
|
+
editor: "number";
|
|
94
|
+
multi?: undefined;
|
|
95
|
+
value: NumberFilterRule | null;
|
|
96
|
+
onChange: (next: NumberFilterRule | null) => void;
|
|
97
|
+
/** Displayed decimals, so equality rounds the way the cell does. */
|
|
98
|
+
decimals?: number;
|
|
99
|
+
/** Shown inside the box: a currency code, "%", "s", nothing. */
|
|
100
|
+
unit?: string;
|
|
101
|
+
/**
|
|
102
|
+
* How the box READS and WRITES its bound. Names only what actually differs —
|
|
103
|
+
* `duration` parses `2m 30s` into the milliseconds the rule stores and prints
|
|
104
|
+
* them back the same way — rather than restating the column's whole style
|
|
105
|
+
* union, which this layer sits below and must not import.
|
|
106
|
+
*/
|
|
107
|
+
numberStyle?: "plain" | "duration";
|
|
108
|
+
/**
|
|
109
|
+
* `duration` only: the unit the RULE is kept in — the column's stored unit
|
|
110
|
+
* (spec §8.4), `ms` unless the field says `s`. The box still reads and writes
|
|
111
|
+
* `2m 30s`; this is what it converts to, so the rule compares against what
|
|
112
|
+
* the cell holds.
|
|
113
|
+
*/
|
|
114
|
+
durationUnit?: "ms" | "s";
|
|
115
|
+
};
|
|
116
|
+
/** A date dimension: absolute operators, a range, or a relative window. */
|
|
117
|
+
export type FilterConfigDate = FilterConfigBase & {
|
|
118
|
+
editor: "date";
|
|
119
|
+
multi?: undefined;
|
|
120
|
+
value: DateFilterRule | null;
|
|
121
|
+
onChange: (next: DateFilterRule | null) => void;
|
|
122
|
+
};
|
|
123
|
+
/** A deliberate refusal. A stale persisted rule keeps this row active only so
|
|
124
|
+
* the user can see and clear it; it is never evaluated as a predicate. */
|
|
125
|
+
export type FilterConfigUnavailable = FilterConfigBase & {
|
|
126
|
+
editor: "unavailable";
|
|
127
|
+
multi?: undefined;
|
|
128
|
+
reason: string;
|
|
129
|
+
stale: boolean;
|
|
130
|
+
onClear: () => void;
|
|
131
|
+
};
|
|
132
|
+
/** A range dimension: an operator and up to two bounds, and the presets as quick picks. */
|
|
133
|
+
export type FilterConfigRange = FilterConfigBase & {
|
|
134
|
+
editor: "range";
|
|
135
|
+
multi?: undefined;
|
|
136
|
+
value: RangeFilterRule | null;
|
|
137
|
+
onChange: (next: RangeFilterRule | null) => void;
|
|
138
|
+
/** Shown beside the boxes: "%", a currency code, nothing. */
|
|
139
|
+
unit?: string;
|
|
140
|
+
presets?: readonly {
|
|
141
|
+
key: string;
|
|
142
|
+
label: string;
|
|
143
|
+
low: number | null;
|
|
144
|
+
high: number | null;
|
|
145
|
+
}[];
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* A relation's dimension (POR-704): which far records must match — any, none or every — and the far fields'
|
|
149
|
+
* own rows as its Where. Its `value` is the saved view's relation rule itself; each Where row edits one rule
|
|
150
|
+
* inside `value.where`.
|
|
151
|
+
*/
|
|
152
|
+
export type FilterConfigRelation = FilterConfigBase & {
|
|
153
|
+
editor: "relation";
|
|
154
|
+
multi?: undefined;
|
|
155
|
+
value: FilterRelationRule | null;
|
|
156
|
+
onChange: (next: FilterRelationRule | null) => void;
|
|
157
|
+
/** The far record, one and many: "campaign" / "campaigns". */
|
|
158
|
+
noun: {
|
|
159
|
+
one: string;
|
|
160
|
+
many: string;
|
|
161
|
+
};
|
|
162
|
+
/** What the list's rows are, plural and lower case: "clients". */
|
|
163
|
+
subject: string;
|
|
164
|
+
/** The far fields' rows, each editing one rule inside `value.where`. */
|
|
165
|
+
where: FilterConfig<string>[];
|
|
166
|
+
/** Whether Every may be chosen: Where holds a rule. */
|
|
167
|
+
canEvery: boolean;
|
|
168
|
+
};
|
|
169
|
+
export type FilterConfig<T extends string = string> = FilterConfigSingle<T> | FilterConfigMulti<T> | FilterConfigText | FilterConfigNumber | FilterConfigDate | FilterConfigRange | FilterConfigUnavailable | FilterConfigRelation;
|
|
170
|
+
export declare function isUnavailableFilter<T extends string>(filter: FilterConfig<T>): filter is FilterConfigUnavailable;
|
|
171
|
+
/** Narrow before touching `.multi` / `.options` — a text filter has neither. */
|
|
172
|
+
export declare function isTextFilter<T extends string>(filter: FilterConfig<T>): filter is FilterConfigText;
|
|
173
|
+
export declare function isNumberFilter<T extends string>(filter: FilterConfig<T>): filter is FilterConfigNumber;
|
|
174
|
+
export declare function isDateFilter<T extends string>(filter: FilterConfig<T>): filter is FilterConfigDate;
|
|
175
|
+
export declare function isRangeFilter<T extends string>(filter: FilterConfig<T>): filter is FilterConfigRange;
|
|
176
|
+
export declare function isRelationFilter<T extends string>(filter: FilterConfig<T>): filter is FilterConfigRelation;
|
|
177
|
+
export declare function isFilterActive<T extends string>(filter: FilterConfig<T>): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isTextRuleActive } from "./text-filter.js";
|
|
2
|
+
import { isNumberRuleActive } from "./number-filter.js";
|
|
3
|
+
import { isDateRuleActive } from "./date-filter.js";
|
|
4
|
+
import { isRangeRuleActive } from "./range-filter.js";
|
|
5
|
+
export function isUnavailableFilter(filter) {
|
|
6
|
+
return filter.editor === "unavailable";
|
|
7
|
+
}
|
|
8
|
+
export function isTextFilter(filter) {
|
|
9
|
+
return filter.editor === "text";
|
|
10
|
+
}
|
|
11
|
+
export function isNumberFilter(filter) {
|
|
12
|
+
return filter.editor === "number";
|
|
13
|
+
}
|
|
14
|
+
export function isDateFilter(filter) {
|
|
15
|
+
return filter.editor === "date";
|
|
16
|
+
}
|
|
17
|
+
export function isRangeFilter(filter) {
|
|
18
|
+
return filter.editor === "range";
|
|
19
|
+
}
|
|
20
|
+
export function isRelationFilter(filter) {
|
|
21
|
+
return filter.editor === "relation";
|
|
22
|
+
}
|
|
23
|
+
export function isFilterActive(filter) {
|
|
24
|
+
if (filter.disabled)
|
|
25
|
+
return false;
|
|
26
|
+
if (isUnavailableFilter(filter))
|
|
27
|
+
return filter.stale;
|
|
28
|
+
if (isRelationFilter(filter))
|
|
29
|
+
return filter.value !== null;
|
|
30
|
+
if (isTextFilter(filter))
|
|
31
|
+
return isTextRuleActive(filter.value);
|
|
32
|
+
if (isNumberFilter(filter))
|
|
33
|
+
return isNumberRuleActive(filter.value);
|
|
34
|
+
if (isRangeFilter(filter))
|
|
35
|
+
return isRangeRuleActive(filter.value);
|
|
36
|
+
if (isDateFilter(filter))
|
|
37
|
+
return isDateRuleActive(filter.value);
|
|
38
|
+
if (filter.multi)
|
|
39
|
+
return filter.value.length > 0;
|
|
40
|
+
return filter.value !== (filter.allValue ?? "all");
|
|
41
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { DEFAULT_NUMBER_FILTER_RULE, NUMBER_FILTER_OPERATORS, durationUnitToMs, formatDurationInput, isNumberRuleActive, matchesNumberRule, msToDurationUnit, numberFilterInputs, numberFilterOperatorLabel, numberRuleLabel, parseDurationInput, parseNumber, } from "@viewkitjs/fields/query";
|
|
2
|
+
export type { DurationUnit, NumberFilterOperator, NumberFilterRule } from "@viewkitjs/fields/query";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_NUMBER_FILTER_RULE, NUMBER_FILTER_OPERATORS, durationUnitToMs, formatDurationInput, isNumberRuleActive, matchesNumberRule, msToDurationUnit, numberFilterInputs, numberFilterOperatorLabel, numberRuleLabel, parseDurationInput, parseNumber, } from "@viewkitjs/fields/query";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { DEFAULT_RANGE_FILTER_RULE, RANGE_FILTER_OPERATORS, isRangeRuleActive, matchesRangeRule, rangeFilterInputs, rangeFilterOperatorLabel, rangeRuleLabel, } from "@viewkitjs/fields/query";
|
|
2
|
+
export type { RangeFilterOperator, RangeFilterRule } from "@viewkitjs/fields/query";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_RANGE_FILTER_RULE, RANGE_FILTER_OPERATORS, isRangeRuleActive, matchesRangeRule, rangeFilterInputs, rangeFilterOperatorLabel, rangeRuleLabel, } from "@viewkitjs/fields/query";
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a list is willing to filter AT THE SOURCE — the one fact the grid cannot
|
|
3
|
+
* work out for itself.
|
|
4
|
+
*
|
|
5
|
+
* The grid knows a column is called `cost` and holds a number. It cannot know
|
|
6
|
+
* that `cost` is `total_cost_usd` on `automations.executions`, and it must not:
|
|
7
|
+
* a component that knew database column names could not be lifted into another
|
|
8
|
+
* application, which is a standing constraint on this subsystem. So the mapping
|
|
9
|
+
* lives with the HOST, in a plain data object, and this file gives that object a
|
|
10
|
+
* shape and a name.
|
|
11
|
+
*
|
|
12
|
+
* ## Why this is a standard rather than a per-list pattern
|
|
13
|
+
*
|
|
14
|
+
* Filtering server-side is the difference between "a page of 50" meaning 50 rows
|
|
15
|
+
* and meaning "50 candidates, some of which you'll see". Every paginated list
|
|
16
|
+
* needs it eventually, so the cost of adopting it has to be near zero:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* export const MY_FILTERS = defineGridFilters({
|
|
20
|
+
* outcome: "outcome",
|
|
21
|
+
* cost: "total_cost_usd",
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* That is the whole declaration. Everything else follows from what the rule
|
|
26
|
+
* already carries — a rule knows whether it is text, a number, a date or a set
|
|
27
|
+
* of options, so nothing restates the column's type.
|
|
28
|
+
*
|
|
29
|
+
* ## The two defaults, and why they are the right way round
|
|
30
|
+
*
|
|
31
|
+
* **A column not named here filters in the BROWSER.** Absence is the opt-out, so
|
|
32
|
+
* there is no flag to forget and no way to accidentally promise a pushdown that
|
|
33
|
+
* doesn't happen. A column whose value is derived after the fetch (a label
|
|
34
|
+
* resolved across three tables) simply isn't in the object and keeps working
|
|
35
|
+
* exactly as it does today.
|
|
36
|
+
*
|
|
37
|
+
* **A column IS assumed nullable.** Getting this wrong in the safe direction
|
|
38
|
+
* costs one redundant `is.null` leg in a query; getting it wrong the other way
|
|
39
|
+
* silently drops every row where the value is absent.
|
|
40
|
+
*/
|
|
41
|
+
/** A date column's storage, because the two are filtered differently: a real
|
|
42
|
+
* `date` compares against calendar days, a `timestamptz` against instants. */
|
|
43
|
+
export type GridFilterColumnType = "auto" | "date" | "timestamptz";
|
|
44
|
+
export type GridFilterEntry = {
|
|
45
|
+
/** The physical column, or a PostgREST json path (`entity_refs->>niche`).
|
|
46
|
+
* Absent only for a `resolved` entry, which has no column to name. */
|
|
47
|
+
column?: string;
|
|
48
|
+
/**
|
|
49
|
+
* This column IS filtered at the source, but by the host's own code rather
|
|
50
|
+
* than by the generic translator — because the value the cell shows isn't a
|
|
51
|
+
* column on the queried table at all.
|
|
52
|
+
*
|
|
53
|
+
* The worked case: a grid shows `workflow_name`, joined from another table,
|
|
54
|
+
* while the queried table holds only `workflow_id`. The host resolves the rule
|
|
55
|
+
* against the (small) set of workflow names and narrows the id constraint
|
|
56
|
+
* itself. There is no predicate this file could emit for that.
|
|
57
|
+
*
|
|
58
|
+
* Declaring it here rather than leaving the column out is what makes the rest
|
|
59
|
+
* work: the rule survives the boundary parse (the registry is the allowlist),
|
|
60
|
+
* it is counted as server-handled, so the browser does not filter it a second
|
|
61
|
+
* time.
|
|
62
|
+
*/
|
|
63
|
+
resolved?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Only worth setting for a genuine `date` column. Everything else is decided
|
|
66
|
+
* by the rule that arrives — a text rule filters text, a number rule filters
|
|
67
|
+
* numbers — so there is no type to keep in step here.
|
|
68
|
+
*/
|
|
69
|
+
type?: GridFilterColumnType;
|
|
70
|
+
/** Set false ONLY for a NOT NULL column. It removes the null-handling legs a
|
|
71
|
+
* negative text operator needs, which is a query-shape saving and nothing
|
|
72
|
+
* more. Wrong here means missing rows. */
|
|
73
|
+
nullable?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The column is an ARRAY (a multiselect's codes). The translator then
|
|
76
|
+
* compiles `is_any_of` as `ov` (overlaps) and `is_none_of` as `not.ov`,
|
|
77
|
+
* never `in`, which tests the whole array against one value.
|
|
78
|
+
*/
|
|
79
|
+
array?: boolean;
|
|
80
|
+
};
|
|
81
|
+
/** Keyed by GRID column id, never by database column. */
|
|
82
|
+
export type ListFilterRegistry = Record<string, GridFilterEntry>;
|
|
83
|
+
/** One explicit answer per column for hosts that opt into complete filtering
|
|
84
|
+
* coverage. Legacy hosts omit the map and keep the existing local/source split. */
|
|
85
|
+
export type ListFilterCapability = {
|
|
86
|
+
mode: "server";
|
|
87
|
+
} | {
|
|
88
|
+
mode: "local";
|
|
89
|
+
} | {
|
|
90
|
+
mode: "unavailable";
|
|
91
|
+
reason: string;
|
|
92
|
+
};
|
|
93
|
+
export type ListFilterCapabilities = Record<string, ListFilterCapability>;
|
|
94
|
+
export declare class ListFilterCapabilityError extends Error {
|
|
95
|
+
constructor(message: string);
|
|
96
|
+
}
|
|
97
|
+
/** Complete coverage and exact agreement with the source registry. */
|
|
98
|
+
export declare function validateFilterCapabilities(columnIds: readonly string[], capabilities: ListFilterCapabilities, serverFilters?: ListFilterRegistry): ListFilterCapabilities;
|
|
99
|
+
/** The shorthand a list actually writes: a bare string when the grid's column id
|
|
100
|
+
* and the database column differ only in name, an object when they don't. */
|
|
101
|
+
export type GridFilterRegistryInput = Record<string, string | GridFilterEntry>;
|
|
102
|
+
/** Declare a column the HOST filters at the source itself — see `resolved`. */
|
|
103
|
+
export declare const RESOLVED_AT_SOURCE: GridFilterEntry;
|
|
104
|
+
/**
|
|
105
|
+
* Normalise a list's declaration into the registry every other piece consumes.
|
|
106
|
+
*
|
|
107
|
+
* A function rather than a bare object literal so the shorthand can exist and so
|
|
108
|
+
* there is one obvious thing to search for when asking "which lists filter at
|
|
109
|
+
* the source".
|
|
110
|
+
*/
|
|
111
|
+
export declare function defineGridFilters(input: GridFilterRegistryInput): ListFilterRegistry;
|
|
112
|
+
/** The column ids this list can filter at the source — what the client needs in
|
|
113
|
+
* order to split its rules, and all it needs. It never sees the mapping. */
|
|
114
|
+
export declare function gridFilterSupport(registry: ListFilterRegistry): string[];
|
|
115
|
+
/**
|
|
116
|
+
* The drift check, for a one-line test per list.
|
|
117
|
+
*
|
|
118
|
+
* Two failures it exists to catch, both silent in production:
|
|
119
|
+
* - a registry naming a column id that no longer exists (renamed, removed) —
|
|
120
|
+
* the rule then never pushes down and the page quietly under-fills again;
|
|
121
|
+
* - a NEW column landing client-side because nobody decided either way.
|
|
122
|
+
*
|
|
123
|
+
* The second is why `expectedLocal` is required rather than optional: a list
|
|
124
|
+
* states which of its columns are deliberately browser-only, so adding a column
|
|
125
|
+
* forces a decision instead of defaulting to one.
|
|
126
|
+
*/
|
|
127
|
+
export declare function auditGridFilters({ columnIds, registry, expectedLocal, }: {
|
|
128
|
+
columnIds: readonly string[];
|
|
129
|
+
registry: ListFilterRegistry;
|
|
130
|
+
/** Column ids that filter in the browser ON PURPOSE — a derived value, a
|
|
131
|
+
* joined label, anything the query can't reach. */
|
|
132
|
+
expectedLocal: readonly string[];
|
|
133
|
+
}): {
|
|
134
|
+
unknown: string[];
|
|
135
|
+
undecided: string[];
|
|
136
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class ListFilterCapabilityError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "ListFilterCapabilityError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function validateFilterCapabilities(columnIds, capabilities, serverFilters) {
|
|
8
|
+
const columns = new Set(columnIds);
|
|
9
|
+
const unknown = Object.keys(capabilities).filter((id) => !columns.has(id));
|
|
10
|
+
const missing = columnIds.filter((id) => !capabilities[id]);
|
|
11
|
+
if (unknown.length || missing.length) {
|
|
12
|
+
throw new ListFilterCapabilityError(`filter capability coverage mismatch (missing: ${missing.join(", ") || "none"}; unknown: ${unknown.join(", ") || "none"})`);
|
|
13
|
+
}
|
|
14
|
+
const registryIds = new Set(Object.keys(serverFilters ?? {}));
|
|
15
|
+
const missingSource = columnIds.filter((id) => capabilities[id]?.mode === "server" && !registryIds.has(id));
|
|
16
|
+
const unexpectedSource = [...registryIds].filter((id) => !columns.has(id) || capabilities[id]?.mode !== "server");
|
|
17
|
+
if (missingSource.length || unexpectedSource.length) {
|
|
18
|
+
throw new ListFilterCapabilityError(`server filter registry mismatch (missing: ${missingSource.join(", ") || "none"}; unexpected: ${unexpectedSource.join(", ") || "none"})`);
|
|
19
|
+
}
|
|
20
|
+
for (const [id, capability] of Object.entries(capabilities)) {
|
|
21
|
+
if (capability.mode === "unavailable" && !capability.reason.trim()) {
|
|
22
|
+
throw new ListFilterCapabilityError(`unavailable filter capability "${id}" needs a reason`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return capabilities;
|
|
26
|
+
}
|
|
27
|
+
export const RESOLVED_AT_SOURCE = { resolved: true };
|
|
28
|
+
export function defineGridFilters(input) {
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const [columnId, entry] of Object.entries(input)) {
|
|
31
|
+
out[columnId] = typeof entry === "string" ? { column: entry } : entry;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
export function gridFilterSupport(registry) {
|
|
36
|
+
return Object.keys(registry);
|
|
37
|
+
}
|
|
38
|
+
export function auditGridFilters({ columnIds, registry, expectedLocal, }) {
|
|
39
|
+
const known = new Set(columnIds);
|
|
40
|
+
const declared = new Set(Object.keys(registry));
|
|
41
|
+
const intended = new Set(expectedLocal);
|
|
42
|
+
return {
|
|
43
|
+
unknown: Object.keys(registry).filter((id) => !known.has(id)),
|
|
44
|
+
undecided: columnIds.filter((id) => !declared.has(id) && !intended.has(id)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type FieldDef } from "@viewkitjs/fields";
|
|
2
|
+
import { type FilterRelationRule } from "@viewkitjs/fields/query";
|
|
3
|
+
import type { ListFilterRule, ListFilterRuleState } from "../model/preferences.js";
|
|
4
|
+
export type RelationQuantifier = FilterRelationRule["quantifier"];
|
|
5
|
+
/** "Every campaign" with no condition matches every row: no filter. Offered only once Where holds a rule
|
|
6
|
+
* that constrains something. */
|
|
7
|
+
export declare function canChooseEvery(rule: FilterRelationRule | null, farFields?: Readonly<Record<string, FieldDef>>): boolean;
|
|
8
|
+
/** Pick a quantifier. The chosen one again clears the rule; Every with no Where rule is refused (the rule stays). */
|
|
9
|
+
export declare function chooseQuantifier(fieldKey: string, rule: FilterRelationRule | null, quantifier: RelationQuantifier): FilterRelationRule | null;
|
|
10
|
+
/** The Where rules the panel edits, by far field key. */
|
|
11
|
+
export declare function whereRulesOf(rule: FilterRelationRule | null, farFields: Readonly<Record<string, FieldDef>>): ListFilterRuleState;
|
|
12
|
+
/** Replace (or drop, on null) the Where rule on one far field. No rule yet: an Any rule starts. The last
|
|
13
|
+
* Where rule of an Every rule gone (or left unfilled, given the far fields): the rule goes. */
|
|
14
|
+
export declare function withWhereRule(fieldKey: string, rule: FilterRelationRule | null, farField: FieldDef, listRule: ListFilterRule | null, farFields?: Readonly<Record<string, FieldDef>>): FilterRelationRule | null;
|
|
15
|
+
/** The set of relation rules with one replaced, or dropped on null. */
|
|
16
|
+
export declare function setRelationRule(rules: Readonly<Record<string, FilterRelationRule>>, fieldKey: string, rule: FilterRelationRule | null): Record<string, FilterRelationRule>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { valueTypeOf } from "@viewkitjs/fields";
|
|
2
|
+
import { isFilterGroup, isRelationRule, ruleIsActive, } from "@viewkitjs/fields/query";
|
|
3
|
+
import { fromListFilterRule, toListFilterRule } from "../model/view-rules.js";
|
|
4
|
+
const empty = () => ({ op: "and", items: [] });
|
|
5
|
+
function heldRules(items, farFields) {
|
|
6
|
+
if (!farFields)
|
|
7
|
+
return items.length;
|
|
8
|
+
return items.filter((item) => {
|
|
9
|
+
if (isFilterGroup(item) || isRelationRule(item))
|
|
10
|
+
return true;
|
|
11
|
+
const def = farFields[item.fieldKey];
|
|
12
|
+
return !def || ruleIsActive(valueTypeOf(def), item);
|
|
13
|
+
}).length;
|
|
14
|
+
}
|
|
15
|
+
export function canChooseEvery(rule, farFields) {
|
|
16
|
+
return !!rule && heldRules(rule.where.items, farFields) > 0;
|
|
17
|
+
}
|
|
18
|
+
export function chooseQuantifier(fieldKey, rule, quantifier) {
|
|
19
|
+
if (rule?.quantifier === quantifier)
|
|
20
|
+
return null;
|
|
21
|
+
if (quantifier === "every" && !canChooseEvery(rule))
|
|
22
|
+
return rule;
|
|
23
|
+
return { fieldKey, quantifier, where: rule?.where ?? empty() };
|
|
24
|
+
}
|
|
25
|
+
export function whereRulesOf(rule, farFields) {
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const item of rule?.where.items ?? []) {
|
|
28
|
+
if (isFilterGroup(item) || isRelationRule(item))
|
|
29
|
+
continue;
|
|
30
|
+
const def = farFields[item.fieldKey];
|
|
31
|
+
if (!def)
|
|
32
|
+
continue;
|
|
33
|
+
const listRule = toListFilterRule(valueTypeOf(def), item);
|
|
34
|
+
if (listRule)
|
|
35
|
+
out[item.fieldKey] = listRule;
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
export function withWhereRule(fieldKey, rule, farField, listRule, farFields) {
|
|
40
|
+
const where = rule?.where ?? empty();
|
|
41
|
+
const kept = where.items.filter((item) => isFilterGroup(item) || isRelationRule(item) || item.fieldKey !== farField.key);
|
|
42
|
+
const next = listRule ? fromListFilterRule(farField.key, valueTypeOf(farField), listRule) : null;
|
|
43
|
+
const items = next ? [...kept, next] : kept;
|
|
44
|
+
if (!rule)
|
|
45
|
+
return next ? { fieldKey, quantifier: "any", where: { op: where.op, items } } : null;
|
|
46
|
+
if (rule.quantifier === "every" && heldRules(items, farFields) === 0)
|
|
47
|
+
return null;
|
|
48
|
+
return { ...rule, where: { op: where.op, items } };
|
|
49
|
+
}
|
|
50
|
+
export function setRelationRule(rules, fieldKey, rule) {
|
|
51
|
+
const { [fieldKey]: _gone, ...rest } = rules;
|
|
52
|
+
return rule ? { ...rest, [fieldKey]: rule } : rest;
|
|
53
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { DEFAULT_TEXT_FILTER_RULE, TEXT_FILTER_OPERATORS, isTextRuleActive, matchesTextRule, nextTextRule, textFilterNeedsQuery, textFilterOperatorLabel, textRuleLabel, } from "@viewkitjs/fields/query";
|
|
2
|
+
export type { TextFilterOperator, TextFilterRule } from "@viewkitjs/fields/query";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DEFAULT_TEXT_FILTER_RULE, TEXT_FILTER_OPERATORS, isTextRuleActive, matchesTextRule, nextTextRule, textFilterNeedsQuery, textFilterOperatorLabel, textRuleLabel, } from "@viewkitjs/fields/query";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Runtime-neutral wire contract shared by the list serializer and server parser/translator. */
|
|
2
|
+
export declare const GRID_FILTER_PARAM_MAX_BYTES = 4096;
|
|
3
|
+
export type ListWireRule = {
|
|
4
|
+
editor: "text";
|
|
5
|
+
operator: "is" | "is_not" | "contains" | "not_contains" | "starts_with" | "ends_with" | "is_empty" | "is_not_empty";
|
|
6
|
+
query: string;
|
|
7
|
+
} | {
|
|
8
|
+
editor: "options";
|
|
9
|
+
values: string[];
|
|
10
|
+
} | {
|
|
11
|
+
editor: "number";
|
|
12
|
+
operator: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "between" | "is_empty" | "is_not_empty";
|
|
13
|
+
value: number | null;
|
|
14
|
+
value2?: number | null;
|
|
15
|
+
decimals: number;
|
|
16
|
+
} | {
|
|
17
|
+
editor: "date";
|
|
18
|
+
operator: "in_range";
|
|
19
|
+
fromDay: string | null;
|
|
20
|
+
toDayExclusive: string | null;
|
|
21
|
+
fromInstant: string | null;
|
|
22
|
+
toInstantExclusive: string | null;
|
|
23
|
+
} | {
|
|
24
|
+
editor: "date";
|
|
25
|
+
operator: "is_empty" | "is_not_empty";
|
|
26
|
+
};
|
|
27
|
+
export type ListWireRuleState = Record<string, ListWireRule>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const GRID_FILTER_PARAM_MAX_BYTES = 4096;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** `manual`: the reader's own order, by stored positions (POR-498). Only the
|
|
2
|
+
* source list orders by it; `sortGroupEntries` below treats it as `name`. */
|
|
3
|
+
export type OrderMode = "lifecycle" | "count" | "name" | "manual";
|
|
4
|
+
export type OrderDir = "asc" | "desc";
|
|
5
|
+
export type OrderChoice = {
|
|
6
|
+
mode: OrderMode;
|
|
7
|
+
dir: OrderDir;
|
|
8
|
+
};
|
|
9
|
+
/** The natural direction for a mode. Used to seed dir when a user picks a new mode. */
|
|
10
|
+
export declare function defaultDirFor(mode: OrderMode): OrderDir;
|
|
11
|
+
type Entry<K extends string> = [key: K, items: unknown[]];
|
|
12
|
+
export declare function sortGroupEntries<K extends string>(entries: Entry<K>[], opts: {
|
|
13
|
+
order: OrderChoice;
|
|
14
|
+
lifecycleIndex?: Partial<Record<K, number>>;
|
|
15
|
+
label?: (key: K) => string;
|
|
16
|
+
uncategorizedKey?: K;
|
|
17
|
+
}): Entry<K>[];
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function defaultDirFor(mode) {
|
|
2
|
+
return mode === "count" ? "desc" : "asc";
|
|
3
|
+
}
|
|
4
|
+
export function sortGroupEntries(entries, opts) {
|
|
5
|
+
const { order, lifecycleIndex, label, uncategorizedKey } = opts;
|
|
6
|
+
const labelOf = label ?? ((k) => String(k));
|
|
7
|
+
const reverse = order.dir !== defaultDirFor(order.mode) ? -1 : 1;
|
|
8
|
+
const arr = [...entries];
|
|
9
|
+
arr.sort(([a, aItems], [b, bItems]) => {
|
|
10
|
+
if (uncategorizedKey !== undefined) {
|
|
11
|
+
if (a === uncategorizedKey)
|
|
12
|
+
return 1;
|
|
13
|
+
if (b === uncategorizedKey)
|
|
14
|
+
return -1;
|
|
15
|
+
}
|
|
16
|
+
let base = 0;
|
|
17
|
+
if (order.mode === "count") {
|
|
18
|
+
base = bItems.length - aItems.length;
|
|
19
|
+
}
|
|
20
|
+
else if (order.mode === "lifecycle") {
|
|
21
|
+
const ai = lifecycleIndex?.[a] ?? 99;
|
|
22
|
+
const bi = lifecycleIndex?.[b] ?? 99;
|
|
23
|
+
base = ai - bi;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
base = labelOf(a).localeCompare(labelOf(b));
|
|
27
|
+
}
|
|
28
|
+
if (base !== 0)
|
|
29
|
+
return base * reverse;
|
|
30
|
+
return labelOf(a).localeCompare(labelOf(b));
|
|
31
|
+
});
|
|
32
|
+
return arr;
|
|
33
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GroupFigures } from "../figures.js";
|
|
2
|
+
/** A group of rows, already filtered/sorted/grouped by the caller's controller. */
|
|
3
|
+
export type ListGroup<Row> = {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string | null;
|
|
6
|
+
items: Row[];
|
|
7
|
+
/** The database's figures over the WHOLE group, when a source list answered
|
|
8
|
+
* them (POR-470). Absent where the rows in hand are the group. */
|
|
9
|
+
figures?: GroupFigures;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * from "./contract.js";
|
|
2
|
+
export * from "./model/index.js";
|
|
3
|
+
export * from "./model/card-density.js";
|
|
4
|
+
export * from "./model/card-layout.js";
|
|
5
|
+
export * from "./model/column-format.js";
|
|
6
|
+
export * from "./model/column-inspect.js";
|
|
7
|
+
export * from "./model/column-money.js";
|
|
8
|
+
export * from "./filters/registry.js";
|
|
9
|
+
export * from "./filters/types.js";
|
|
10
|
+
export * from "./filters/text-filter.js";
|
|
11
|
+
export * from "./filters/number-filter.js";
|
|
12
|
+
export * from "./filters/range-filter.js";
|
|
13
|
+
export * from "./filters/date-filter.js";
|
|
14
|
+
export * from "./filters/filter-model.js";
|
|
15
|
+
export * from "./filters/relation-filter.js";
|
|
16
|
+
export * from "./model/relation-filters.js";
|
|
17
|
+
export * from "./figures.js";
|
|
18
|
+
export * from "./grouping/types.js";
|
|
19
|
+
export * from "./grouping/sort-groups.js";
|
|
20
|
+
export * from "./fields/binding.js";
|
|
21
|
+
export * from "./fields/money.js";
|
|
22
|
+
export * from "./fields/currency.js";
|
|
23
|
+
export * from "./fields/denomination.js";
|
|
24
|
+
export * from "./fields/prepare-write.js";
|
|
25
|
+
export * from "./fields/edit-core-types.js";
|
|
26
|
+
export * from "./fields/number-edit.js";
|
|
27
|
+
export * from "./fields/format-knobs.js";
|
|
28
|
+
export * from "./fields/relation-source-types.js";
|
|
29
|
+
export * from "./fields/menus.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * from "./contract.js";
|
|
2
|
+
export * from "./model/index.js";
|
|
3
|
+
export * from "./model/card-density.js";
|
|
4
|
+
export * from "./model/card-layout.js";
|
|
5
|
+
export * from "./model/column-format.js";
|
|
6
|
+
export * from "./model/column-inspect.js";
|
|
7
|
+
export * from "./model/column-money.js";
|
|
8
|
+
export * from "./filters/registry.js";
|
|
9
|
+
export * from "./filters/types.js";
|
|
10
|
+
export * from "./filters/text-filter.js";
|
|
11
|
+
export * from "./filters/number-filter.js";
|
|
12
|
+
export * from "./filters/range-filter.js";
|
|
13
|
+
export * from "./filters/date-filter.js";
|
|
14
|
+
export * from "./filters/filter-model.js";
|
|
15
|
+
export * from "./filters/relation-filter.js";
|
|
16
|
+
export * from "./model/relation-filters.js";
|
|
17
|
+
export * from "./figures.js";
|
|
18
|
+
export * from "./grouping/types.js";
|
|
19
|
+
export * from "./grouping/sort-groups.js";
|
|
20
|
+
export * from "./fields/binding.js";
|
|
21
|
+
export * from "./fields/money.js";
|
|
22
|
+
export * from "./fields/currency.js";
|
|
23
|
+
export * from "./fields/denomination.js";
|
|
24
|
+
export * from "./fields/prepare-write.js";
|
|
25
|
+
export * from "./fields/edit-core-types.js";
|
|
26
|
+
export * from "./fields/number-edit.js";
|
|
27
|
+
export * from "./fields/format-knobs.js";
|
|
28
|
+
export * from "./fields/relation-source-types.js";
|
|
29
|
+
export * from "./fields/menus.js";
|