@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,40 @@
|
|
|
1
|
+
import type { FieldType } from "@viewkitjs/fields";
|
|
2
|
+
/**
|
|
3
|
+
* WHICH TYPES OPEN AN EDITOR PANEL — the fact, without the editors.
|
|
4
|
+
*
|
|
5
|
+
* `EDIT_CORES` (edit-cores.ts) binds a React component to each type, so asking
|
|
6
|
+
* it a yes/no question costs importing all five editors. The list MODEL asks
|
|
7
|
+
* exactly that question (`column-warnings.ts`) and must stay view-neutral: with
|
|
8
|
+
* the question answered from `EDIT_CORES`, every module that read a column
|
|
9
|
+
* capability loaded the date picker. `edit-cores.ts` proves at compile time
|
|
10
|
+
* that this table and its own `null`s agree, so the two cannot drift.
|
|
11
|
+
*/
|
|
12
|
+
export declare const EDIT_CORE_TYPES: {
|
|
13
|
+
readonly date: true;
|
|
14
|
+
readonly datetime: true;
|
|
15
|
+
readonly select: true;
|
|
16
|
+
readonly status: true;
|
|
17
|
+
readonly multiselect: true;
|
|
18
|
+
readonly relation: true;
|
|
19
|
+
readonly user: true;
|
|
20
|
+
readonly number: true;
|
|
21
|
+
readonly percent: true;
|
|
22
|
+
readonly currency: true;
|
|
23
|
+
readonly text: false;
|
|
24
|
+
readonly url: false;
|
|
25
|
+
readonly domain: false;
|
|
26
|
+
readonly email: false;
|
|
27
|
+
readonly phone: false;
|
|
28
|
+
readonly boolean: false;
|
|
29
|
+
readonly location: true;
|
|
30
|
+
readonly name: true;
|
|
31
|
+
readonly actor: false;
|
|
32
|
+
readonly rich_text: false;
|
|
33
|
+
readonly range: true;
|
|
34
|
+
readonly lookup: false;
|
|
35
|
+
readonly rollup: false;
|
|
36
|
+
readonly formula: false;
|
|
37
|
+
};
|
|
38
|
+
/** Whether this type opens a panel at all — the question a host asks before it
|
|
39
|
+
* wires an editor it may not need. */
|
|
40
|
+
export declare function hasEditCore(type: FieldType): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const EDIT_CORE_TYPES = {
|
|
2
|
+
date: true,
|
|
3
|
+
datetime: true,
|
|
4
|
+
select: true,
|
|
5
|
+
status: true,
|
|
6
|
+
multiselect: true,
|
|
7
|
+
relation: true,
|
|
8
|
+
user: true,
|
|
9
|
+
number: true,
|
|
10
|
+
percent: true,
|
|
11
|
+
currency: true,
|
|
12
|
+
text: false,
|
|
13
|
+
url: false,
|
|
14
|
+
domain: false,
|
|
15
|
+
email: false,
|
|
16
|
+
phone: false,
|
|
17
|
+
boolean: false,
|
|
18
|
+
location: true,
|
|
19
|
+
name: true,
|
|
20
|
+
actor: false,
|
|
21
|
+
rich_text: false,
|
|
22
|
+
range: true,
|
|
23
|
+
lookup: false,
|
|
24
|
+
rollup: false,
|
|
25
|
+
formula: false,
|
|
26
|
+
};
|
|
27
|
+
export function hasEditCore(type) {
|
|
28
|
+
return EDIT_CORE_TYPES[type];
|
|
29
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH DISPLAY SETTINGS A FIELD OFFERS ITS READER, decided by its type — the
|
|
3
|
+
* third of the three tables that make a type complete: `DISPLAY_CORES` says how
|
|
4
|
+
* it reads, `EDIT_CORES` says how it is edited, and this says what a reader may
|
|
5
|
+
* change about the reading.
|
|
6
|
+
*
|
|
7
|
+
* A mapped record over `FieldType` for the same reason as its siblings: a type
|
|
8
|
+
* added to the union with no answer here fails to COMPILE, and a workspace's
|
|
9
|
+
* custom field gets the right knobs the moment it exists rather than when
|
|
10
|
+
* somebody remembers to add a branch to a panel.
|
|
11
|
+
*
|
|
12
|
+
* These knobs write the reader's OWN format overrides (the format bucket in
|
|
13
|
+
* their prefs), never the view — how a field reads is the same in every view,
|
|
14
|
+
* so one answer per (list, field) serves all of them.
|
|
15
|
+
*
|
|
16
|
+
* OPTION COLOURS ARE DELIBERATELY ABSENT: they are per-value rather than
|
|
17
|
+
* per-field, and a pick-one has nowhere to put a palette. They stay in the grid
|
|
18
|
+
* header's column menu.
|
|
19
|
+
*/
|
|
20
|
+
import { type FieldDef, type FieldType } from "@viewkitjs/fields";
|
|
21
|
+
export type FormatKnobKind = "dateStyle" | "showTime" | "durationStyle" | "decimals" | "currency" | "percentDisplay";
|
|
22
|
+
export type FormatKnobs = {
|
|
23
|
+
/** In the order the panel draws them. */
|
|
24
|
+
knobs: readonly FormatKnobKind[];
|
|
25
|
+
};
|
|
26
|
+
export declare const FORMAT_KNOBS: {
|
|
27
|
+
[K in FieldType]: FormatKnobs;
|
|
28
|
+
};
|
|
29
|
+
export declare function formatKnobsFor(type: FieldType): ReadonlySet<FormatKnobKind>;
|
|
30
|
+
/** The knobs a FIELD offers — a rollup or formula answers with its result's,
|
|
31
|
+
* which is the one thing the type-keyed table cannot know. An integer field
|
|
32
|
+
* offers no Decimals: integer governs precision (spec §8.2), so there is
|
|
33
|
+
* nothing for a reader to argue about. */
|
|
34
|
+
export declare function formatKnobsForField(field: FieldDef): ReadonlySet<FormatKnobKind>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isIntegerField, valueTypeOf } from "@viewkitjs/fields";
|
|
2
|
+
export const FORMAT_KNOBS = {
|
|
3
|
+
number: { knobs: ["decimals", "durationStyle"] },
|
|
4
|
+
percent: { knobs: ["percentDisplay", "decimals"] },
|
|
5
|
+
currency: { knobs: ["decimals", "currency"] },
|
|
6
|
+
date: { knobs: ["dateStyle"] },
|
|
7
|
+
datetime: { knobs: ["dateStyle", "showTime"] },
|
|
8
|
+
text: { knobs: [] },
|
|
9
|
+
url: { knobs: [] },
|
|
10
|
+
domain: { knobs: [] },
|
|
11
|
+
email: { knobs: [] },
|
|
12
|
+
boolean: { knobs: [] },
|
|
13
|
+
select: { knobs: [] },
|
|
14
|
+
multiselect: { knobs: [] },
|
|
15
|
+
relation: { knobs: [] },
|
|
16
|
+
status: { knobs: [] },
|
|
17
|
+
user: { knobs: [] },
|
|
18
|
+
phone: { knobs: [] },
|
|
19
|
+
location: { knobs: [] },
|
|
20
|
+
name: { knobs: [] },
|
|
21
|
+
actor: { knobs: [] },
|
|
22
|
+
rich_text: { knobs: [] },
|
|
23
|
+
range: { knobs: [] },
|
|
24
|
+
lookup: { knobs: [] },
|
|
25
|
+
rollup: { knobs: [] },
|
|
26
|
+
formula: { knobs: [] },
|
|
27
|
+
};
|
|
28
|
+
export function formatKnobsFor(type) {
|
|
29
|
+
return new Set(FORMAT_KNOBS[type].knobs);
|
|
30
|
+
}
|
|
31
|
+
export function formatKnobsForField(field) {
|
|
32
|
+
const knobs = new Set(formatKnobsFor(valueTypeOf(field)));
|
|
33
|
+
if (isIntegerField(field))
|
|
34
|
+
knobs.delete("decimals");
|
|
35
|
+
return knobs;
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* One verb on a field's menu. Narrow on purpose — the shape `dealOutcomeItems`
|
|
4
|
+
* already hands the hero's ⋯ and a board card's kebab, so one list feeds all
|
|
5
|
+
* three surfaces without a cast.
|
|
6
|
+
*/
|
|
7
|
+
export type FieldRowMenuItem = {
|
|
8
|
+
label: string;
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
onClick: () => void;
|
|
11
|
+
destructive?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Field key → the verbs a row offers INSTEAD of an editor.
|
|
16
|
+
*
|
|
17
|
+
* Some fields cannot be a picker: their transitions carry rules of their own —
|
|
18
|
+
* a lost deal needs a reason, a cancelled subscription an end date — so the
|
|
19
|
+
* data model marks them `mutability: "command"` and the row would otherwise be
|
|
20
|
+
* a badge with a lock. The answer is the verbs, drawn on the row itself so a
|
|
21
|
+
* user asking "why can't I change this?" finds what they CAN do right there.
|
|
22
|
+
*
|
|
23
|
+
* They are the HOST's, not the layout's: each verb carries a request, a
|
|
24
|
+
* dialog and a refresh, none of which a pure sections file can hold. Resolved
|
|
25
|
+
* per row so the list follows the record's state — Mark won / Mark lost on an
|
|
26
|
+
* open deal, Reopen on a closed one.
|
|
27
|
+
*/
|
|
28
|
+
export type FieldMenus<Row> = Readonly<Partial<Record<string, (row: Row) => readonly FieldRowMenuItem[]>>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type DisplayCurrency, type MoneyReading } from "./currency.js";
|
|
2
|
+
import { type DenominatedColumn } from "./denomination.js";
|
|
3
|
+
/** What a column declares it opens on: a reading, or the reader's own default
|
|
4
|
+
* currency. */
|
|
5
|
+
export type MoneyOpensOn = MoneyReading | "default";
|
|
6
|
+
export type MoneyDeclaration<Row> = {
|
|
7
|
+
/** What the cell shows, in the ROW's OWN currency. */
|
|
8
|
+
amount: (row: Row) => unknown;
|
|
9
|
+
/** What the footer totals, in the row's own currency. Absent = `amount`. */
|
|
10
|
+
total?: (row: Row) => number | null;
|
|
11
|
+
/** The row's currency code. */
|
|
12
|
+
code: (row: Row) => string;
|
|
13
|
+
/** The row's multipliers into every readable currency, or null for a row
|
|
14
|
+
* with no currency. Structural (`binding.ts` stays free of the finance
|
|
15
|
+
* library); `finance.fx(row)` is what a portal binding hands over. */
|
|
16
|
+
rates: (row: Row) => Readonly<Record<string, number>> | null;
|
|
17
|
+
/** The reading the column declares as its default. */
|
|
18
|
+
opensOn: MoneyOpensOn;
|
|
19
|
+
};
|
|
20
|
+
/** The keys a money column carries — structural, so a grid `ListColumn` and a
|
|
21
|
+
* server `SourceColumn` both satisfy it. */
|
|
22
|
+
export type MoneyColumn<Row> = DenominatedColumn<Row> & {
|
|
23
|
+
money?: MoneyDeclaration<Row>;
|
|
24
|
+
reading?: MoneyReading;
|
|
25
|
+
accessor?: ((row: Row) => unknown) | null;
|
|
26
|
+
aggAccessor?: (row: Row) => number | null;
|
|
27
|
+
};
|
|
28
|
+
export declare function isMoneyOpensOn(value: unknown): value is MoneyOpensOn;
|
|
29
|
+
/** The reading a declaration opens on, for this reader. */
|
|
30
|
+
export declare function resolveOpensOn(opensOn: MoneyOpensOn, defaultCurrency: DisplayCurrency): MoneyReading;
|
|
31
|
+
/** A row's figure in `to` — null for no figure, or for a row the database says
|
|
32
|
+
* has no currency; the data-layer throw (`FxRateError`) for a row with a
|
|
33
|
+
* currency and no rate. Only a number converts: the portal's money fields
|
|
34
|
+
* store numbers.
|
|
35
|
+
*
|
|
36
|
+
* "No currency" is read off the RATES, not the code: a unit's `read` is the
|
|
37
|
+
* editor chip's value and coalesces an absent currency to a default (`?? "EUR"`),
|
|
38
|
+
* while `finance.fx_map` answers SQL NULL — a literal `null` map — exactly when
|
|
39
|
+
* the row's code is null. So `rates === null` is the database's own answer
|
|
40
|
+
* that there is nothing to convert FROM, and the figure stays unconverted. A
|
|
41
|
+
* row read WITHOUT its `fx` (`undefined`) is the data-layer bug and still
|
|
42
|
+
* throws: nothing here guesses a rate. */
|
|
43
|
+
export declare function convertMoney<Row>(money: MoneyDeclaration<Row>, row: Row, value: unknown, to: DisplayCurrency): number | null;
|
|
44
|
+
/** The column, read the given way. Every derivation starts from `money`, so
|
|
45
|
+
* reading a column twice is the same as reading it once. `C` keeps the
|
|
46
|
+
* caller's column type (a grid `ListColumn`, a server `SourceColumn`); the
|
|
47
|
+
* intersection is what lets `Row` be inferred from the declaration. */
|
|
48
|
+
export declare function readMoneyColumn<Row, C extends MoneyColumn<Row>>(column: C & MoneyColumn<Row>, reading: MoneyReading): C;
|
|
49
|
+
/** Every money column read the reader's way: their `gridCurrencies` by FIELD
|
|
50
|
+
* key, else a host's legacy choice (read once, never written), else what the
|
|
51
|
+
* column opens on — for this reader's default currency. */
|
|
52
|
+
export declare function readMoneyColumns<Row, C extends MoneyColumn<Row>>(columns: readonly (C & MoneyColumn<Row>)[], readings: Readonly<Record<string, MoneyReading>>, defaultCurrency: DisplayCurrency, legacy?: (column: C) => MoneyReading | undefined): C[];
|
|
53
|
+
/** The reading in force on a money column; `undefined` for a column that
|
|
54
|
+
* carries no money declaration. */
|
|
55
|
+
export declare function moneyReadingOf<Row>(column: MoneyColumn<Row>): MoneyReading | undefined;
|
|
56
|
+
/** The code the CELL draws for this row — a converted column's one code, a
|
|
57
|
+
* per-row column's row code, `undefined` for a column with no denomination.
|
|
58
|
+
* Never the `COLUMN_WIDE_CODE` sentinel. */
|
|
59
|
+
export declare function shownCodeOf<Row>(column: DenominatedColumn<Row>, row: Row): string | undefined;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { valueTypeOf } from "@viewkitjs/fields";
|
|
2
|
+
import { convertRowAmount, ORIGINAL_READING, } from "./currency.js";
|
|
3
|
+
import { COLUMN_WIDE_CODE } from "./denomination.js";
|
|
4
|
+
export function isMoneyOpensOn(value) {
|
|
5
|
+
return (value === "default" ||
|
|
6
|
+
value === ORIGINAL_READING ||
|
|
7
|
+
value === "EUR" ||
|
|
8
|
+
value === "USD" ||
|
|
9
|
+
value === "RON");
|
|
10
|
+
}
|
|
11
|
+
export function resolveOpensOn(opensOn, defaultCurrency) {
|
|
12
|
+
return opensOn === "default" ? defaultCurrency : opensOn;
|
|
13
|
+
}
|
|
14
|
+
export function convertMoney(money, row, value, to) {
|
|
15
|
+
if (typeof value !== "number")
|
|
16
|
+
return null;
|
|
17
|
+
const rates = money.rates(row);
|
|
18
|
+
if (rates === null)
|
|
19
|
+
return null;
|
|
20
|
+
return convertRowAmount({ currency: money.code(row), fx: rates }, value, to);
|
|
21
|
+
}
|
|
22
|
+
export function readMoneyColumn(column, reading) {
|
|
23
|
+
const money = column.money;
|
|
24
|
+
if (!money)
|
|
25
|
+
return column;
|
|
26
|
+
const next = { ...column, reading };
|
|
27
|
+
const format = { ...(column.format ?? {}) };
|
|
28
|
+
if (reading === ORIGINAL_READING) {
|
|
29
|
+
delete format.currency;
|
|
30
|
+
next.accessor = money.amount;
|
|
31
|
+
if (money.total)
|
|
32
|
+
next.aggAccessor = money.total;
|
|
33
|
+
else
|
|
34
|
+
delete next.aggAccessor;
|
|
35
|
+
next.currencyAccessor = money.code;
|
|
36
|
+
delete next.surfaceOwnsCurrency;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
format.currency = reading;
|
|
40
|
+
next.accessor = (row) => convertMoney(money, row, money.amount(row), reading);
|
|
41
|
+
if (money.total) {
|
|
42
|
+
const total = money.total;
|
|
43
|
+
next.aggAccessor = (row) => convertMoney(money, row, total(row), reading);
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
delete next.aggAccessor;
|
|
47
|
+
delete next.currencyAccessor;
|
|
48
|
+
next.surfaceOwnsCurrency = true;
|
|
49
|
+
}
|
|
50
|
+
next.format = format;
|
|
51
|
+
return next;
|
|
52
|
+
}
|
|
53
|
+
export function readMoneyColumns(columns, readings, defaultCurrency, legacy) {
|
|
54
|
+
return columns.map((column) => {
|
|
55
|
+
if (!column.money || !column.field)
|
|
56
|
+
return column;
|
|
57
|
+
const reading = readings[column.field.key] ??
|
|
58
|
+
legacy?.(column) ??
|
|
59
|
+
resolveOpensOn(column.money.opensOn, defaultCurrency);
|
|
60
|
+
return readMoneyColumn(column, reading);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export function moneyReadingOf(column) {
|
|
64
|
+
if (column.reading)
|
|
65
|
+
return column.reading;
|
|
66
|
+
if (!column.money)
|
|
67
|
+
return undefined;
|
|
68
|
+
return column.money.opensOn === "default" ? undefined : column.money.opensOn;
|
|
69
|
+
}
|
|
70
|
+
export function shownCodeOf(column, row) {
|
|
71
|
+
if (!column.field || valueTypeOf(column.field) !== "currency")
|
|
72
|
+
return undefined;
|
|
73
|
+
if (column.currencyAccessor)
|
|
74
|
+
return column.currencyAccessor(row);
|
|
75
|
+
const code = column.format?.currency;
|
|
76
|
+
return code && code !== COLUMN_WIDE_CODE ? code : undefined;
|
|
77
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DurationUnit, type FieldDef } from "@viewkitjs/fields";
|
|
2
|
+
/**
|
|
3
|
+
* The decimals a number-shaped field EDITS at — one answer for the grid cell,
|
|
4
|
+
* the drawer row and the card, so a percent does not open as `45.00` on one
|
|
5
|
+
* surface and `45` on another. Integer governs (spec §8.2); else the field's
|
|
6
|
+
* own `format.decimals`; else the type's default — a percent is whole (§8.1),
|
|
7
|
+
* money and plain numbers two.
|
|
8
|
+
*/
|
|
9
|
+
export declare function numberEditDecimals(field: FieldDef): number;
|
|
10
|
+
/** The unit a duration field STORES (spec §8.4) — `undefined` for anything else. */
|
|
11
|
+
export declare function durationUnitOf(field: FieldDef): DurationUnit | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isIntegerField, presentedDef, valueTypeOf, } from "@viewkitjs/fields";
|
|
2
|
+
export function numberEditDecimals(field) {
|
|
3
|
+
if (isIntegerField(field))
|
|
4
|
+
return 0;
|
|
5
|
+
const def = presentedDef(field);
|
|
6
|
+
const format = "format" in def ? def.format : undefined;
|
|
7
|
+
const declared = format && "decimals" in format ? format.decimals : undefined;
|
|
8
|
+
if (declared !== undefined)
|
|
9
|
+
return declared;
|
|
10
|
+
return valueTypeOf(field) === "percent" ? 0 : 2;
|
|
11
|
+
}
|
|
12
|
+
export function durationUnitOf(field) {
|
|
13
|
+
const def = presentedDef(field);
|
|
14
|
+
return def.type === "number" && def.format?.style === "duration"
|
|
15
|
+
? (def.format.unit ?? "ms")
|
|
16
|
+
: undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type FieldConventions, type FieldSettlement } from "@viewkitjs/fields";
|
|
2
|
+
import { type FieldBinding } from "./binding.js";
|
|
3
|
+
export type PreparedFieldWrite = {
|
|
4
|
+
ok: true;
|
|
5
|
+
body: Record<string, unknown>;
|
|
6
|
+
storedValue: unknown;
|
|
7
|
+
/** The binding's own account of what this write achieves (spec §11.2):
|
|
8
|
+
* `requested` when the body lands locally and a provider still has to
|
|
9
|
+
* accept it. The transport's result may upgrade it to `confirmed`. */
|
|
10
|
+
settlement?: FieldSettlement;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
reason: string;
|
|
14
|
+
};
|
|
15
|
+
/** What the surface around the field states: whether it is writable at all, the
|
|
16
|
+
* words it refuses in, and the host's conventions — which carry the resolver
|
|
17
|
+
* every sentence here goes through. A core takes them; it never imports them. */
|
|
18
|
+
type WriteSurface = {
|
|
19
|
+
writable?: boolean;
|
|
20
|
+
refusal?: string;
|
|
21
|
+
conventions?: FieldConventions;
|
|
22
|
+
};
|
|
23
|
+
/** Pure binding-aware preparation. Nothing returned here is serialized except `body`. */
|
|
24
|
+
export declare function prepareFieldWrite<Row>(binding: FieldBinding<Row>, row: Row, commit: unknown, surface?: WriteSurface): PreparedFieldWrite;
|
|
25
|
+
/**
|
|
26
|
+
* How a write arrived: an ordinary commit, or the restore of a history entry —
|
|
27
|
+
* which names the value it expects to find and is refused once the row moved on.
|
|
28
|
+
*/
|
|
29
|
+
export type FieldWriteContext = {
|
|
30
|
+
kind: "commit";
|
|
31
|
+
} | {
|
|
32
|
+
kind: "restore";
|
|
33
|
+
expected: unknown;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* One admitted edit of a same-row operation (a paste or fill across cells of
|
|
37
|
+
* one row). Declared here, not in a host: a module's `bindings.ts` names these
|
|
38
|
+
* shapes in its grouping adapter, and a binding never imports the list.
|
|
39
|
+
*/
|
|
40
|
+
export type PreparedRowEdit = {
|
|
41
|
+
columnId: string;
|
|
42
|
+
value: unknown;
|
|
43
|
+
context: FieldWriteContext;
|
|
44
|
+
};
|
|
45
|
+
export type GroupedRowWrite = {
|
|
46
|
+
/** One request body for every admitted edit in this same-row operation. */
|
|
47
|
+
body: Record<string, unknown>;
|
|
48
|
+
/** The cell that owns an opaque history snapshot for the whole operation.
|
|
49
|
+
* The remaining cells stay confirmed but are pruned from the history entry,
|
|
50
|
+
* so Undo dispatches exactly one restore. */
|
|
51
|
+
historyColumnId: string;
|
|
52
|
+
};
|
|
53
|
+
/** Restore an opaque companion snapshot through the same live surface gate. */
|
|
54
|
+
export declare function prepareFieldRestore<Row>(binding: FieldBinding<Row>, row: Row, snapshot: unknown, expected: unknown, surface?: WriteSurface): PreparedFieldWrite;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DEFAULT_CONVENTIONS, acceptFieldCommit, acceptStoredFieldValue, } from "@viewkitjs/fields";
|
|
2
|
+
import { bindingWritable } from "./binding.js";
|
|
3
|
+
const MAPPED_VALUE_REQUIRED = new Set(["number", "percent", "currency", "datetime"]);
|
|
4
|
+
function writableRefusal(binding, surface) {
|
|
5
|
+
const message = (surface.conventions ?? DEFAULT_CONVENTIONS).messages;
|
|
6
|
+
if (surface.writable === false) {
|
|
7
|
+
return surface.refusal ?? message({ key: "field.cannot-edit" });
|
|
8
|
+
}
|
|
9
|
+
if (!bindingWritable(binding)) {
|
|
10
|
+
return binding.field.edit?.reasons?.editable ?? message({ key: "field.cannot-edit" });
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
export function prepareFieldWrite(binding, row, commit, surface = {}) {
|
|
15
|
+
const refused = writableRefusal(binding, surface);
|
|
16
|
+
if (refused)
|
|
17
|
+
return { ok: false, reason: refused };
|
|
18
|
+
const cv = surface.conventions ?? DEFAULT_CONVENTIONS;
|
|
19
|
+
const message = cv.messages;
|
|
20
|
+
const stored = binding.field.type === "phone" ? (binding.editRead ?? binding.read)(row) : undefined;
|
|
21
|
+
const accepted = acceptFieldCommit(binding.field, commit, {
|
|
22
|
+
unitOptions: binding.unit?.options,
|
|
23
|
+
conventions: cv,
|
|
24
|
+
stored,
|
|
25
|
+
});
|
|
26
|
+
if (!accepted.ok)
|
|
27
|
+
return accepted;
|
|
28
|
+
const patch = binding.write(row, accepted.value);
|
|
29
|
+
if ("skip" in patch) {
|
|
30
|
+
return { ok: false, reason: patch.reason ?? message({ key: "field.cannot-save" }) };
|
|
31
|
+
}
|
|
32
|
+
if (MAPPED_VALUE_REQUIRED.has(binding.field.type) && !("storedValue" in patch)) {
|
|
33
|
+
return { ok: false, reason: message({ key: "field.stored-value-required" }) };
|
|
34
|
+
}
|
|
35
|
+
const storedValue = "storedValue" in patch ? patch.storedValue : accepted.value;
|
|
36
|
+
const judged = acceptStoredFieldValue(binding.field, storedValue, cv, { stored });
|
|
37
|
+
if (!judged.ok)
|
|
38
|
+
return judged;
|
|
39
|
+
return {
|
|
40
|
+
ok: true,
|
|
41
|
+
body: patch.body,
|
|
42
|
+
storedValue: judged.value,
|
|
43
|
+
...(patch.settlement ? { settlement: patch.settlement } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function prepareFieldRestore(binding, row, snapshot, expected, surface = {}) {
|
|
47
|
+
const refused = writableRefusal(binding, surface);
|
|
48
|
+
if (refused)
|
|
49
|
+
return { ok: false, reason: refused };
|
|
50
|
+
const cv = surface.conventions ?? DEFAULT_CONVENTIONS;
|
|
51
|
+
const message = cv.messages;
|
|
52
|
+
if (!binding.history)
|
|
53
|
+
return { ok: false, reason: message({ key: "field.history-unavailable" }) };
|
|
54
|
+
const patch = binding.history.restore(row, snapshot, expected);
|
|
55
|
+
if ("skip" in patch) {
|
|
56
|
+
return { ok: false, reason: patch.reason ?? message({ key: "field.restore-refused" }) };
|
|
57
|
+
}
|
|
58
|
+
if ("storedValue" in patch) {
|
|
59
|
+
const stored = acceptStoredFieldValue(binding.field, patch.storedValue, cv, {
|
|
60
|
+
stored: binding.field.type === "phone" ? patch.storedValue : undefined,
|
|
61
|
+
});
|
|
62
|
+
if (!stored.ok)
|
|
63
|
+
return stored;
|
|
64
|
+
return { ok: true, body: patch.body, storedValue: stored.value };
|
|
65
|
+
}
|
|
66
|
+
return { ok: true, body: patch.body, storedValue: snapshot };
|
|
67
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* One thing a relation can point at, already resolved by the host.
|
|
4
|
+
*
|
|
5
|
+
* It carries a `ReactNode` (type-only, nothing at runtime), which is why it
|
|
6
|
+
* lives here and not in `@viewkitjs/fields`: a glyph is a component-layer
|
|
7
|
+
* concern. `ListRelationValue` is structurally assignable to it, so a grid host
|
|
8
|
+
* passes its own array straight through.
|
|
9
|
+
*/
|
|
10
|
+
export type RelationCandidate = {
|
|
11
|
+
/** Stable key. Compared, stored and committed; never shown. */
|
|
12
|
+
id: string;
|
|
13
|
+
/** What the row shows, and what a static search matches on. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** A muted second line under the label — the disambiguator between two
|
|
16
|
+
* same-named rows: a person's email, a deal's service. Drawn only when
|
|
17
|
+
* present, so a list whose candidates carry none (the grid's) keeps its
|
|
18
|
+
* one-line rows. */
|
|
19
|
+
sublabel?: string;
|
|
20
|
+
/** A small muted chip at the row's right edge, for a MIXED list whose rows
|
|
21
|
+
* need telling apart at a glance — "Person" / "Company" in the deal anchor
|
|
22
|
+
* picker. The glyph already differs; the word makes it certain. */
|
|
23
|
+
badge?: string;
|
|
24
|
+
/** Per-value glyph, for a column whose rows point at different kinds. Wins
|
|
25
|
+
* over the host's `kindGlyph`. */
|
|
26
|
+
icon?: ReactNode;
|
|
27
|
+
avatarUrl?: string | null;
|
|
28
|
+
/** The candidate's kind, on a list of several kinds — what a pick stores with the id. */
|
|
29
|
+
kind?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The host's search. `offset` is how many rows the panel already holds for
|
|
33
|
+
* this query — zero for a fresh one, then a page at a time. The signal aborts
|
|
34
|
+
* on the next query and on unmount.
|
|
35
|
+
*/
|
|
36
|
+
export type RelationSearch = (query: string, signal: AbortSignal, offset: number) => Promise<RelationCandidate[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Where the candidates come from. `static` is a list the host already holds —
|
|
39
|
+
* whole, so there is nothing to page. `remote` is a search the host runs: with
|
|
40
|
+
* the empty query the moment the panel opens, then per typed query after the
|
|
41
|
+
* debounce, then a page at a time as the list is scrolled to its end.
|
|
42
|
+
*/
|
|
43
|
+
export type RelationSource = {
|
|
44
|
+
kind: "static";
|
|
45
|
+
items: RelationCandidate[];
|
|
46
|
+
} | {
|
|
47
|
+
kind: "remote";
|
|
48
|
+
search: RelationSearch;
|
|
49
|
+
/** How many rows a page holds. It must match what the host's search
|
|
50
|
+
* actually asks its route for: a page of exactly this size is the ONLY
|
|
51
|
+
* signal that there may be more, so a mismatch either ends the list
|
|
52
|
+
* early or asks one pointless question at the end of it. */
|
|
53
|
+
pageSize?: number;
|
|
54
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A GROUP'S FIGURES, AS THE DATABASE COUNTED THEM (POR-470).
|
|
3
|
+
*
|
|
4
|
+
* A source list holds a page, not the list, so a footer or a group header that
|
|
5
|
+
* totals the rows in hand is wrong past the first page. For every key a source
|
|
6
|
+
* totals, the engine answers four numbers over the whole group — the sum and
|
|
7
|
+
* the count of the values present, the smallest and the largest — and every
|
|
8
|
+
* footer pick the database can answer is read from them. Four, not one per
|
|
9
|
+
* pick: two parts' sums, counts, mins and maxes combine exactly, so a group
|
|
10
|
+
* folded from many discovery rows (the days of a week, a row under each of its
|
|
11
|
+
* tags) still answers an average, which a mean of the parts' means does not.
|
|
12
|
+
* Pure and free of the engine: the chassis reads it, the engine produces it.
|
|
13
|
+
*
|
|
14
|
+
* It imports NOTHING, not even a type: the source engine runs on the server,
|
|
15
|
+
* and the list model (`model/`) reaches browser modules — a type import is an
|
|
16
|
+
* edge the library ratchet follows (L004). So the footer picks are named here,
|
|
17
|
+
* and every caller hands a `ListAggregateKind`: a pick added there and not
|
|
18
|
+
* here fails the checker at the footer's call.
|
|
19
|
+
*/
|
|
20
|
+
/** The footer picks, as `model/column-schema.ts` names them (`ListAggregateKind`). */
|
|
21
|
+
export type FigureKind = "none" | "sum" | "avg" | "min" | "max" | "count" | "filled" | "unique" | "ratio";
|
|
22
|
+
export type ColumnFigure = {
|
|
23
|
+
sum: number | null;
|
|
24
|
+
count: number;
|
|
25
|
+
min: number | null;
|
|
26
|
+
max: number | null;
|
|
27
|
+
};
|
|
28
|
+
/** A group's — or the whole list's — figures: its rows, and each totalled key's figure. */
|
|
29
|
+
export type GroupFigures = {
|
|
30
|
+
rows: number;
|
|
31
|
+
fields: Record<string, ColumnFigure>;
|
|
32
|
+
};
|
|
33
|
+
export declare const EMPTY_FIGURE: ColumnFigure;
|
|
34
|
+
/** Two parts' figures as the figure of both. A null is a value absent, never a zero. */
|
|
35
|
+
export declare function combineFigure(a: ColumnFigure, b: ColumnFigure): ColumnFigure;
|
|
36
|
+
/** The figure of some values, a blank not counted. */
|
|
37
|
+
export declare function figureOf(values: readonly (number | null | undefined)[]): ColumnFigure;
|
|
38
|
+
/**
|
|
39
|
+
* The number a footer pick shows, or null for nothing to show. Follows the
|
|
40
|
+
* browser's own aggregate (`computeAggregate`): over no values, sum, avg, min
|
|
41
|
+
* and max are null; Count is the group's rows; Filled is the values present.
|
|
42
|
+
* Unique and Ratio are not the database's to answer.
|
|
43
|
+
*/
|
|
44
|
+
export declare function figureFor(kind: FigureKind, figures: GroupFigures, key: string): number | null;
|
|
45
|
+
/**
|
|
46
|
+
* A ratio formula's footer from its two parts' figures: sum over sum, as a
|
|
47
|
+
* percent (0–100), divided once — the browser's own `ratio` over the same
|
|
48
|
+
* rows. Null when either part was not totalled or the denominator is empty.
|
|
49
|
+
*/
|
|
50
|
+
export declare function ratioFigure(figures: GroupFigures, numerator: string, denominator: string): number | null;
|
|
51
|
+
/** Whether an answer's field is a `GroupFigures` — the hook hands a first page's own fields over untyped. */
|
|
52
|
+
export declare function isGroupFigures(value: unknown): value is GroupFigures;
|
package/dist/figures.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const EMPTY_FIGURE = { sum: null, count: 0, min: null, max: null };
|
|
2
|
+
function either(a, b, both) {
|
|
3
|
+
return a == null ? b : b == null ? a : both(a, b);
|
|
4
|
+
}
|
|
5
|
+
export function combineFigure(a, b) {
|
|
6
|
+
return {
|
|
7
|
+
sum: either(a.sum, b.sum, (x, y) => x + y),
|
|
8
|
+
count: a.count + b.count,
|
|
9
|
+
min: either(a.min, b.min, Math.min),
|
|
10
|
+
max: either(a.max, b.max, Math.max),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function figureOf(values) {
|
|
14
|
+
let figure = EMPTY_FIGURE;
|
|
15
|
+
for (const value of values) {
|
|
16
|
+
if (value == null || Number.isNaN(value))
|
|
17
|
+
continue;
|
|
18
|
+
figure = combineFigure(figure, { sum: value, count: 1, min: value, max: value });
|
|
19
|
+
}
|
|
20
|
+
return figure;
|
|
21
|
+
}
|
|
22
|
+
export function figureFor(kind, figures, key) {
|
|
23
|
+
if (kind === "none" || kind === "unique" || kind === "ratio")
|
|
24
|
+
return null;
|
|
25
|
+
if (kind === "count")
|
|
26
|
+
return figures.rows;
|
|
27
|
+
const figure = figures.fields[key];
|
|
28
|
+
if (!figure)
|
|
29
|
+
return null;
|
|
30
|
+
if (kind === "filled")
|
|
31
|
+
return figure.count;
|
|
32
|
+
if (figure.count === 0)
|
|
33
|
+
return null;
|
|
34
|
+
if (kind === "sum")
|
|
35
|
+
return figure.sum;
|
|
36
|
+
if (kind === "avg")
|
|
37
|
+
return figure.sum == null ? null : figure.sum / figure.count;
|
|
38
|
+
return kind === "min" ? figure.min : figure.max;
|
|
39
|
+
}
|
|
40
|
+
export function ratioFigure(figures, numerator, denominator) {
|
|
41
|
+
const num = figures.fields[numerator];
|
|
42
|
+
const den = figures.fields[denominator];
|
|
43
|
+
if (!num || !den)
|
|
44
|
+
return null;
|
|
45
|
+
const denominatorSum = den.sum ?? 0;
|
|
46
|
+
return denominatorSum > 0 ? Math.round(((num.sum ?? 0) / denominatorSum) * 100) : null;
|
|
47
|
+
}
|
|
48
|
+
const isFigure = (value) => !!value &&
|
|
49
|
+
typeof value === "object" &&
|
|
50
|
+
typeof value.count === "number" &&
|
|
51
|
+
["sum", "min", "max"].every((part) => {
|
|
52
|
+
const at = value[part];
|
|
53
|
+
return at === null || typeof at === "number";
|
|
54
|
+
});
|
|
55
|
+
export function isGroupFigures(value) {
|
|
56
|
+
if (!value || typeof value !== "object")
|
|
57
|
+
return false;
|
|
58
|
+
const { rows, fields } = value;
|
|
59
|
+
return (typeof rows === "number" &&
|
|
60
|
+
!!fields &&
|
|
61
|
+
typeof fields === "object" &&
|
|
62
|
+
Object.values(fields).every(isFigure));
|
|
63
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { DATE_FILTER_OPERATORS, DEFAULT_DATE_FILTER_RULE, RELATIVE_DIRECTIONS, RELATIVE_UNITS, dateFilterDates, dateFilterOperatorLabel, dateRuleLabel, formatDayInput, fromDayKey, isDateRuleActive, matchesDateRule, parseDateInput, resolveRelativeWindow, toDayKey, valueDayKey, } from "@viewkitjs/fields/query";
|
|
2
|
+
export type { DateFilterOperator, DateFilterRule, RelativeDirection, RelativeUnit, TemporalKind, } from "@viewkitjs/fields/query";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DATE_FILTER_OPERATORS, DEFAULT_DATE_FILTER_RULE, RELATIVE_DIRECTIONS, RELATIVE_UNITS, dateFilterDates, dateFilterOperatorLabel, dateRuleLabel, formatDayInput, fromDayKey, isDateRuleActive, matchesDateRule, parseDateInput, resolveRelativeWindow, toDayKey, valueDayKey, } from "@viewkitjs/fields/query";
|