@dqa-ai-solutions/ui-runtime 0.0.0-stage → 0.2.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/README.md +17 -2
- package/dist/_types/ui-kit/index.d.ts +4 -0
- package/dist/_types/ui-kit/lens/action.d.ts +76 -0
- package/dist/_types/ui-kit/lens/cell.d.ts +79 -0
- package/dist/_types/ui-kit/lens/diagnostic.d.ts +49 -0
- package/dist/_types/ui-kit/lens/format.d.ts +32 -0
- package/dist/_types/ui-kit/lens/index.d.ts +12 -0
- package/dist/_types/ui-kit/lens/list.d.ts +223 -0
- package/dist/_types/ui-kit/lens/milestone.d.ts +112 -0
- package/dist/_types/ui-kit/lens/pattern.d.ts +38 -0
- package/dist/_types/ui-kit/lens/queue.d.ts +30 -0
- package/dist/_types/ui-kit/lens/record.d.ts +110 -0
- package/dist/_types/ui-kit/lens/registry.d.ts +9 -0
- package/dist/_types/ui-kit/lens/shape.d.ts +27 -0
- package/dist/_types/ui-kit/lens/timeline.d.ts +36 -0
- package/dist/_types/ui-kit/primitives/action.d.ts +263 -0
- package/dist/_types/ui-kit/primitives/index.d.ts +2 -0
- package/dist/_types/ui-kit/primitives/state.d.ts +148 -0
- package/dist/_types/ui-kit/shell/index.d.ts +2 -0
- package/dist/_types/ui-kit/shell/nav.d.ts +142 -0
- package/dist/_types/ui-kit/shell/trail.d.ts +85 -0
- package/dist/_types/ui-kit/tokens/index.d.ts +1 -0
- package/dist/_types/ui-kit/tokens/types.d.ts +252 -0
- package/dist/_types/ui-react/elements/action-bar.d.ts +32 -0
- package/dist/_types/ui-react/elements/action-scope.d.ts +9 -0
- package/dist/_types/ui-react/elements/button.d.ts +42 -0
- package/dist/_types/ui-react/elements/choice.d.ts +40 -0
- package/dist/_types/ui-react/elements/columns.d.ts +82 -0
- package/dist/_types/ui-react/elements/dialog-scope.d.ts +15 -0
- package/dist/_types/ui-react/elements/dialog.d.ts +67 -0
- package/dist/_types/ui-react/elements/disclosure.d.ts +305 -0
- package/dist/_types/ui-react/elements/field-attributes.d.ts +39 -0
- package/dist/_types/ui-react/elements/field.d.ts +628 -0
- package/dist/_types/ui-react/elements/file.d.ts +82 -0
- package/dist/_types/ui-react/elements/filter.d.ts +61 -0
- package/dist/_types/ui-react/elements/link.d.ts +38 -0
- package/dist/_types/ui-react/elements/menu.d.ts +56 -0
- package/dist/_types/ui-react/elements/milestone.d.ts +119 -0
- package/dist/_types/ui-react/elements/nav.d.ts +73 -0
- package/dist/_types/ui-react/elements/pop.d.ts +14 -0
- package/dist/_types/ui-react/elements/record.d.ts +174 -0
- package/dist/_types/ui-react/elements/segmented.d.ts +59 -0
- package/dist/_types/ui-react/elements/suggest.d.ts +11 -0
- package/dist/_types/ui-react/elements/surface.d.ts +354 -0
- package/dist/_types/ui-react/elements/table.d.ts +72 -0
- package/dist/_types/ui-react/elements/toast.d.ts +69 -0
- package/dist/_types/ui-react/index.d.ts +22 -0
- package/dist/_types/ui-react/prefix/index.d.ts +8 -0
- package/dist/chunks/chunk-4LX2HZJU.js +0 -0
- package/dist/chunks/chunk-7WHYHIUX.js +1 -0
- package/dist/chunks/chunk-VS5FCRGY.js +3 -0
- package/dist/chunks/chunk-X6SR5UHK.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lens.d.ts +1 -0
- package/dist/lens.js +1 -0
- package/dist/primitives.d.ts +1 -0
- package/dist/primitives.js +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +1 -0
- package/dist/shell.d.ts +1 -0
- package/dist/shell.js +1 -0
- package/dist/tokens.css +160 -0
- package/dist/tokens.d.ts +1 -0
- package/dist/tokens.dark.css +98 -0
- package/dist/tokens.generated.css +98 -0
- package/dist/tokens.high.css +98 -0
- package/dist/tokens.js +1 -0
- package/package.json +60 -4
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ViewContract } from '@dqa-ai-solutions/core-runtime/view';
|
|
2
|
+
import { type SurfaceState, type EmptyCopy, type Fault } from '../primitives/index.js';
|
|
3
|
+
import { type Cell, type CellContext } from './cell.js';
|
|
4
|
+
import type { LensDiagnostic } from './diagnostic.js';
|
|
5
|
+
export interface QueueItem {
|
|
6
|
+
id: string;
|
|
7
|
+
entity: string;
|
|
8
|
+
main: Cell;
|
|
9
|
+
sub: Cell | null;
|
|
10
|
+
badge: Cell | null;
|
|
11
|
+
}
|
|
12
|
+
export interface QueueInput {
|
|
13
|
+
/** A queue mixes entities, so contracts arrive keyed by entity name. */
|
|
14
|
+
contracts: Record<string, ViewContract>;
|
|
15
|
+
items: {
|
|
16
|
+
entity: string;
|
|
17
|
+
record: Record<string, unknown>;
|
|
18
|
+
}[] | null;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
error?: string | null;
|
|
21
|
+
forbidden?: string | false;
|
|
22
|
+
narrowed?: boolean;
|
|
23
|
+
empty: EmptyCopy;
|
|
24
|
+
}
|
|
25
|
+
export interface QueueModel {
|
|
26
|
+
state: SurfaceState<QueueItem[]>;
|
|
27
|
+
diagnostics: LensDiagnostic[];
|
|
28
|
+
faults: Fault[];
|
|
29
|
+
}
|
|
30
|
+
export declare function queueModel(input: QueueInput, ctx: CellContext): QueueModel;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { ViewContract, ResolvedField } from '@dqa-ai-solutions/core-runtime/view';
|
|
2
|
+
import { type SurfaceState, type EmptyCopy, type Fault, type ActionView } from '../primitives/index.js';
|
|
3
|
+
import { type Cell, type CellContext } from './cell.js';
|
|
4
|
+
import { type ActionHints } from './action.js';
|
|
5
|
+
import type { LensDiagnostic } from './diagnostic.js';
|
|
6
|
+
export interface RecordSection {
|
|
7
|
+
name: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
/** Which tab this belongs on. Omitted, it sits on the first tab. */
|
|
10
|
+
tab?: string;
|
|
11
|
+
/** Property names, from those the contract carries. */
|
|
12
|
+
facts?: string[];
|
|
13
|
+
/** A named component instead of facts. The two are exclusive. */
|
|
14
|
+
block?: string;
|
|
15
|
+
/** Visible only while the record is in one of these states. */
|
|
16
|
+
when?: string[];
|
|
17
|
+
}
|
|
18
|
+
export interface RecordLayout {
|
|
19
|
+
/** Optional — see the header. Without it, one section holding every fact. */
|
|
20
|
+
sections?: RecordSection[];
|
|
21
|
+
tabs?: {
|
|
22
|
+
name: string;
|
|
23
|
+
label: string;
|
|
24
|
+
}[];
|
|
25
|
+
}
|
|
26
|
+
export type RecordPart = {
|
|
27
|
+
kind: 'facts';
|
|
28
|
+
name: string;
|
|
29
|
+
label?: string;
|
|
30
|
+
facts: {
|
|
31
|
+
field: ResolvedField;
|
|
32
|
+
cell: Cell;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The records hanging off this one — most of a record page.
|
|
37
|
+
*
|
|
38
|
+
* ⚠️ Rows arrive from the app under `related[name]`; this package never
|
|
39
|
+
* queries. Absent rows are reported, never drawn as an empty table: a
|
|
40
|
+
* section that silently shows nothing looks identical to one that has
|
|
41
|
+
* nothing to show.
|
|
42
|
+
*/
|
|
43
|
+
| {
|
|
44
|
+
kind: 'related';
|
|
45
|
+
name: string;
|
|
46
|
+
label: string;
|
|
47
|
+
entity: string;
|
|
48
|
+
columns: ResolvedField[];
|
|
49
|
+
rows: {
|
|
50
|
+
id: string;
|
|
51
|
+
cells: Cell[];
|
|
52
|
+
}[];
|
|
53
|
+
rowHeaderKey: string | null;
|
|
54
|
+
} | {
|
|
55
|
+
kind: 'block';
|
|
56
|
+
name: string;
|
|
57
|
+
label?: string;
|
|
58
|
+
widget: string;
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'missing-block';
|
|
61
|
+
name: string;
|
|
62
|
+
widget: string;
|
|
63
|
+
message: string;
|
|
64
|
+
};
|
|
65
|
+
export interface RecordTab {
|
|
66
|
+
name: string;
|
|
67
|
+
label: string;
|
|
68
|
+
parts: RecordPart[];
|
|
69
|
+
}
|
|
70
|
+
export interface RecordBody {
|
|
71
|
+
/** What this record is CALLED to a person. */
|
|
72
|
+
title: string | null;
|
|
73
|
+
/** The state badge, with the weight the ontology gave it. */
|
|
74
|
+
badge: Cell | null;
|
|
75
|
+
/** One clause saying what the current state MEANS operationally. */
|
|
76
|
+
hint?: string;
|
|
77
|
+
/**
|
|
78
|
+
* The state the record is IN, as the ontology spells it.
|
|
79
|
+
*
|
|
80
|
+
* ⭐ Load-bearing inside this model already — it filters sections, related
|
|
81
|
+
* rows and available actions — and it was invisible on the way out, so a
|
|
82
|
+
* renderer wanting to draw it had to re-derive it from the record. That is
|
|
83
|
+
* the same shape as an app hand-writing `subjectOf`: the contract knows,
|
|
84
|
+
* and the package did not hand it over.
|
|
85
|
+
*
|
|
86
|
+
* ⚠️ The raw name, not wording. `badge` carries what a person reads.
|
|
87
|
+
*/
|
|
88
|
+
state: string | null;
|
|
89
|
+
tabs: RecordTab[];
|
|
90
|
+
actions: ActionView[];
|
|
91
|
+
}
|
|
92
|
+
export interface RecordInput {
|
|
93
|
+
contract: ViewContract;
|
|
94
|
+
record: Record<string, unknown> | null;
|
|
95
|
+
loading: boolean;
|
|
96
|
+
error?: string | null;
|
|
97
|
+
forbidden?: string | false;
|
|
98
|
+
layout?: RecordLayout;
|
|
99
|
+
hints?: ActionHints;
|
|
100
|
+
/** Rows for each declared related list, keyed by its `name`. */
|
|
101
|
+
related?: Record<string, Record<string, unknown>[]>;
|
|
102
|
+
/** Shown when the id resolves to nothing. */
|
|
103
|
+
empty: EmptyCopy;
|
|
104
|
+
}
|
|
105
|
+
export interface RecordModel {
|
|
106
|
+
state: SurfaceState<RecordBody>;
|
|
107
|
+
diagnostics: LensDiagnostic[];
|
|
108
|
+
faults: Fault[];
|
|
109
|
+
}
|
|
110
|
+
export declare function recordModel(input: RecordInput, ctx: CellContext): RecordModel;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface BlockRegistry {
|
|
2
|
+
/** True when the renderer can draw a block by this name. */
|
|
3
|
+
has(name: string): boolean;
|
|
4
|
+
/** Every name, for diagnostics that need to suggest one. */
|
|
5
|
+
names(): string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const registryOf: (names: readonly string[]) => BlockRegistry;
|
|
8
|
+
/** A registry that accepts nothing — the correct default for a print renderer. */
|
|
9
|
+
export declare const NO_BLOCKS: BlockRegistry;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** The read layer never produced this key — not a value, a wiring fault. */
|
|
2
|
+
export declare const ABSENT: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* One property of one record, wherever the store chose to put it.
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ THE ENVELOPE WINS A COLLISION, deliberately. It holds the ontology's own
|
|
7
|
+
* properties; a store column that happens to share a name is the one that
|
|
8
|
+
* should give way — otherwise a soft-delete flag called `status` quietly
|
|
9
|
+
* replaces the workflow state called `status`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readValue(row: Record<string, unknown>, key: string): unknown | typeof ABSENT;
|
|
12
|
+
/**
|
|
13
|
+
* The record flattened: envelope over top-level, in one object.
|
|
14
|
+
*
|
|
15
|
+
* ⭐ FOR THE CALLER READING SEVERAL FIELDS AT ONCE, which is what every copy of
|
|
16
|
+
* `x.data ?? x` in the wild was actually doing — a filter testing three
|
|
17
|
+
* properties of a signed decision, a row builder reading four columns.
|
|
18
|
+
* Offering only `readValue` would have left those sites writing the merge
|
|
19
|
+
* themselves, which is the thing being removed.
|
|
20
|
+
*
|
|
21
|
+
* ⚠️ `data` itself is dropped from the result. A flattened view with a nested
|
|
22
|
+
* `data` key still in it invites exactly the two-shape confusion this exists
|
|
23
|
+
* to end.
|
|
24
|
+
*
|
|
25
|
+
* ⚠️ Same collision rule as `readValue`: the envelope wins.
|
|
26
|
+
*/
|
|
27
|
+
export declare function fieldsOf(row: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type SurfaceState, type EmptyCopy } from '../primitives/index.js';
|
|
2
|
+
import type { Formatter } from './format.js';
|
|
3
|
+
import type { LensDiagnostic } from './diagnostic.js';
|
|
4
|
+
/** `"<entity>.<event>" → the sentence a person reads.` */
|
|
5
|
+
export type EventVocabulary = Record<string, string>;
|
|
6
|
+
export interface RawEvent {
|
|
7
|
+
/** `staffMember.selected` — machine name, never shown. */
|
|
8
|
+
event: string;
|
|
9
|
+
at: string;
|
|
10
|
+
actor?: string;
|
|
11
|
+
/** Anything the renderer may want; the lens does not read it. */
|
|
12
|
+
detail?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export interface TimelineEntry {
|
|
15
|
+
event: string;
|
|
16
|
+
label: string;
|
|
17
|
+
at: string;
|
|
18
|
+
/** Written with the app's locale — never a raw ISO stamp. */
|
|
19
|
+
when: string;
|
|
20
|
+
actor?: string;
|
|
21
|
+
detail?: Record<string, unknown>;
|
|
22
|
+
/** True when no wording existed and the machine name is standing in. */
|
|
23
|
+
unlabelled: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface TimelineInput {
|
|
26
|
+
events: RawEvent[] | null;
|
|
27
|
+
vocabulary: EventVocabulary;
|
|
28
|
+
loading: boolean;
|
|
29
|
+
error?: string | null;
|
|
30
|
+
empty: EmptyCopy;
|
|
31
|
+
}
|
|
32
|
+
export interface TimelineModel {
|
|
33
|
+
state: SurfaceState<TimelineEntry[]>;
|
|
34
|
+
diagnostics: LensDiagnostic[];
|
|
35
|
+
}
|
|
36
|
+
export declare function timelineModel(input: TimelineInput, format: Formatter): TimelineModel;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/** Four, because measurement found the app really had two and needed four. */
|
|
2
|
+
export type ActionTier = 'key' | 'normal' | 'quiet' | 'danger';
|
|
3
|
+
/**
|
|
4
|
+
* What the action does. Every field is a fact the workflow already states —
|
|
5
|
+
* `to`, `decision.outcome` — not a presentation choice someone makes here.
|
|
6
|
+
*/
|
|
7
|
+
export interface ActionFacts {
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
/** The step has a `to`: it moves the record onward. */
|
|
11
|
+
advances?: boolean;
|
|
12
|
+
/** A decision step's verdict. */
|
|
13
|
+
outcome?: 'approve' | 'reject';
|
|
14
|
+
/** Leaves the surface without writing anything — cancel, close, back. */
|
|
15
|
+
exits?: boolean;
|
|
16
|
+
/** Irreversible, or removes a record from the roll. */
|
|
17
|
+
destroys?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* THIS is the one action the surface exists for — said out loud.
|
|
20
|
+
*
|
|
21
|
+
* ⭐ Only needed when the facts above leave it open: two steps that both
|
|
22
|
+
* advance, and no `decision.outcome` to tell them apart. The user ruled on
|
|
23
|
+
* 26/9/2026 that a flat screen is not an answer: *"trên 1 màn hình luôn
|
|
24
|
+
* phải define button nào là chính, button còn lại nằm trong …"* — so where
|
|
25
|
+
* the workflow cannot decide, the screen's author decides, here.
|
|
26
|
+
*
|
|
27
|
+
* ⛔ At most one per surface. Two `primary` is the same non-answer as none.
|
|
28
|
+
*/
|
|
29
|
+
primary?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Icon the renderer resolves. ⛔ NOT optional in practice — see `actionBar`.
|
|
32
|
+
*
|
|
33
|
+
* The package cannot ship icons: they are an application's own drawings. What
|
|
34
|
+
* it can do is refuse to pretend a button without one is finished.
|
|
35
|
+
*/
|
|
36
|
+
icon?: string;
|
|
37
|
+
busy?: boolean;
|
|
38
|
+
disabled?: DisabledReason | false;
|
|
39
|
+
/**
|
|
40
|
+
* What this step still lacks a basis for.
|
|
41
|
+
*
|
|
42
|
+
* ⭐ Not a defect and not a reason to disable — the step is takeable, and
|
|
43
|
+
* somebody decided it should be. It is a caveat the person pressing the
|
|
44
|
+
* button deserves to read, and it travels with the button rather than
|
|
45
|
+
* sitting in a YAML file nobody opens.
|
|
46
|
+
*/
|
|
47
|
+
provisional?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* ⛔ A CONTROL MAY NOT BE DISABLED WITHOUT SAYING WHY.
|
|
51
|
+
*
|
|
52
|
+
* There is deliberately no `disabled: true`. A greyed-out button with no
|
|
53
|
+
* explanation is the worst thing a workflow app can show: the user's job is
|
|
54
|
+
* right there, it will not respond, and nothing on screen says whether they
|
|
55
|
+
* are too early, lack the role, or are looking at a bug. They ask a colleague,
|
|
56
|
+
* and the colleague does not know either.
|
|
57
|
+
*/
|
|
58
|
+
export interface DisabledReason {
|
|
59
|
+
because: string;
|
|
60
|
+
/** What would make it available — a state to reach, a role to hold. */
|
|
61
|
+
hint?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* What a renderer receives.
|
|
65
|
+
*
|
|
66
|
+
* ⛔ ONE `label`, AND THERE IS NO SECOND ONE. The pattern this forbids —
|
|
67
|
+
* `{busy ? 'Đang ghi…' : 'Lưu quyết toán'}` — was found at 62 call sites in
|
|
68
|
+
* the reference app on the day after a shared busy-button component was
|
|
69
|
+
* built. It changes the button's width under the finger that just pressed it,
|
|
70
|
+
* which reads as the button moving away. `busy` is a flag; the word stays put.
|
|
71
|
+
*/
|
|
72
|
+
export interface ActionView {
|
|
73
|
+
key: string;
|
|
74
|
+
/**
|
|
75
|
+
* ALWAYS present, even when it is not drawn.
|
|
76
|
+
*
|
|
77
|
+
* ⛔ When `showLabel` is false the label does not disappear — it becomes the
|
|
78
|
+
* accessible name and the tooltip. An icon-only control with no name is
|
|
79
|
+
* invisible to a screen reader and a guess for everyone else; the label is
|
|
80
|
+
* the thing that stops that, so it is never optional.
|
|
81
|
+
*/
|
|
82
|
+
label: string;
|
|
83
|
+
tier: ActionTier;
|
|
84
|
+
/**
|
|
85
|
+
* The action this surface exists for. Its PLACE, not its paint: a primary
|
|
86
|
+
* that destroys (*"Đóng đợt khám"* in its own confirm dialog) is still the
|
|
87
|
+
* primary, but its tier stays `danger` — a solid colour on an irreversible
|
|
88
|
+
* step would be the one thing the eye trusts without reading.
|
|
89
|
+
*/
|
|
90
|
+
primary: boolean;
|
|
91
|
+
icon?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Draw the word, or carry it as `aria-label` + `title`.
|
|
94
|
+
*
|
|
95
|
+
* ⭐ Words everywhere except a table row, where the data owns the words and an
|
|
96
|
+
* action is an icon with its word as name and tooltip (see `actionBar` ④).
|
|
97
|
+
*/
|
|
98
|
+
showLabel: boolean;
|
|
99
|
+
busy: boolean;
|
|
100
|
+
disabled: false | DisabledReason;
|
|
101
|
+
/** A caveat to show beside the button — see `ActionFacts.provisional`. */
|
|
102
|
+
provisional?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Which action a surface exists for — or `null` when the facts cannot say.
|
|
106
|
+
*
|
|
107
|
+
* The ladder, in order, among the actions that do not merely leave (`exits`):
|
|
108
|
+
* ⓪ exactly one `primary` → that one (the author said so)
|
|
109
|
+
* ① exactly one `approve` decision → that one
|
|
110
|
+
* ② exactly one advancing step → that one (a `reject` does not count)
|
|
111
|
+
* ③ exactly one action at all → that one (a lone step IS the point)
|
|
112
|
+
* ④ otherwise → `null`, and `actionBar` reports it
|
|
113
|
+
*
|
|
114
|
+
* ⛔ CHANGED 26/9/2026. This used to end in "otherwise none — flat beats wrong".
|
|
115
|
+
* The user ruled the other way: every screen defines its primary, the rest
|
|
116
|
+
* go behind one trigger. ④ is therefore not a quiet outcome any more; it is
|
|
117
|
+
* `missingPrimary`, and `<ActionBar>` refuses to render it in development.
|
|
118
|
+
*/
|
|
119
|
+
export declare function primaryOf(actions: ActionFacts[]): ActionFacts | null;
|
|
120
|
+
/**
|
|
121
|
+
* Resolve a surface's actions: **exactly one** primary where there is anything
|
|
122
|
+
* to do, and a tier for every action from what it does.
|
|
123
|
+
*
|
|
124
|
+
* ⭐ The primary is `key` — unless it destroys, then it stays `danger` (outlined,
|
|
125
|
+
* never filled; see `TIER_PAINT`). Nothing else is ever `key`.
|
|
126
|
+
*/
|
|
127
|
+
export declare function actionViews(actions: ActionFacts[]): ActionView[];
|
|
128
|
+
/**
|
|
129
|
+
* A row of actions, arranged for the surface it stands on.
|
|
130
|
+
*
|
|
131
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
132
|
+
* ⭐ EVERY RULE HAS A SCOPE — the user, 27/9/2026: *"quy tắc trên nó còn phải
|
|
133
|
+
* có phạm vi nữa, ví dụ là trên toàn 1 màn hình hay trên 1 thẻ, section hay
|
|
134
|
+
* 1 table"*.
|
|
135
|
+
*
|
|
136
|
+
* | scope | primary (`key`) | secondaries |
|
|
137
|
+
* |-----------------------------------------|--------------------------|-------------------|
|
|
138
|
+
* | SCREEN — a page, or an open dialog | EXACTLY ONE, outside cards | — |
|
|
139
|
+
* | BAR — `page` head, `dialog`, `form` | must hold the screen's | ② and ③ below |
|
|
140
|
+
* | SCOPE — `card` (a card or a section) | its OWN one, or none | ② and ③ below |
|
|
141
|
+
* | REPEATED — `table` row, `item` card | NEVER | ③, ④ below |
|
|
142
|
+
*
|
|
143
|
+
* A card or a section is a SCOPE of its own: its primary is the point of
|
|
144
|
+
* that card, and does not compete with the screen's. The user, 27/9/2026,
|
|
145
|
+
* shown room cards with only `normal` buttons: *"theo thiết kế của ta thì
|
|
146
|
+
* cái card hay section vẫn có thể có button với style primary"*.
|
|
147
|
+
*
|
|
148
|
+
* The SCREEN rule is counted across bars by `<ActionBar>` (development
|
|
149
|
+
* only): more than one primary among the bars that are not cards, or a
|
|
150
|
+
* card with work and no primary anywhere on its screen, throws. The BAR
|
|
151
|
+
* and REPEATED rules are decided here.
|
|
152
|
+
*
|
|
153
|
+
* ⭐ FOUR RULES — AND WHERE EACH ONE COMES FROM
|
|
154
|
+
*
|
|
155
|
+
* ① ONE PRIMARY PER SCREEN, HELD BY EMPHASIS. A page, a card, a rail, a form
|
|
156
|
+
* or a dialog paints exactly one action `key`; every other action is drawn
|
|
157
|
+
* at a lower tier. The user, 26/9/2026: *"trên 1 màn hình chỉ có 1 action
|
|
158
|
+
* chính"*. The same rule stands in Carbon, Material and Polaris.
|
|
159
|
+
*
|
|
160
|
+
* ② ONE SECONDARY IN SIGHT, WITH ITS WORD. One-primary is kept by EMPHASIS,
|
|
161
|
+
* not by hiding everything else. Beside the primary stands ONE secondary
|
|
162
|
+
* action, drawn at its own lower tier. The screen's author decides which
|
|
163
|
+
* one by the order of the actions.
|
|
164
|
+
*
|
|
165
|
+
* ⛔ CHANGED 27/9/2026. From 26/9 to 27/9 the rule was "the rest go behind
|
|
166
|
+
* ⋯". Room cards ended up showing only a "⋯" that held "Mở hàng chờ"
|
|
167
|
+
* and "Rời phòng", and the card with a result being entered hid "Lưu".
|
|
168
|
+
* The user: *"chỗ hiển thị button và ... thực sự có vấn đề thật"*, and
|
|
169
|
+
* asked what the rest of the world has proven:
|
|
170
|
+
* · NN/g, contextual menus: menus hold SECONDARY, non-critical
|
|
171
|
+
* actions only, and "do not use contextual menus when there are
|
|
172
|
+
* only one or two possible actions", because hiding them "saves
|
|
173
|
+
* no space, increases effort, and reduces discoverability".
|
|
174
|
+
* · Material 3, cards: supplemental actions are shown; use an
|
|
175
|
+
* overflow menu for more than two.
|
|
176
|
+
* · Shopify Polaris, page actions: a primary plus at most two
|
|
177
|
+
* secondaries in sight; the rest roll up into "More actions".
|
|
178
|
+
* · GOV.UK summary card: the card's actions are short words in its
|
|
179
|
+
* header, two to three, never hidden.
|
|
180
|
+
* The user picked the stricter end of that range after seeing both on
|
|
181
|
+
* a design canvas, *"nếu keep tối đa 2 button, 1 chính 1 phụ"*, and
|
|
182
|
+
* approved it: *"ok, nhìn hợp lý đấy"*.
|
|
183
|
+
*
|
|
184
|
+
* ③ NEVER A MENU OF ONE. Exactly two secondaries: both stand in sight,
|
|
185
|
+
* because a menu holding the one left over is a click spent on nothing
|
|
186
|
+
* (NN/g). Three or more: one stands in sight and the rest, always two or
|
|
187
|
+
* more, go behind the trigger. Actions that destroy are the first to go
|
|
188
|
+
* into the menu, where the word is read before the press. The trigger
|
|
189
|
+
* shows a word (`moreLabel`, e.g. "Thêm"), not a bare "⋯". NN/g: the icon
|
|
190
|
+
* "lacks inherent meaning; include descriptions as visible labels".
|
|
191
|
+
* THE WAY OUT (`exits`: Huỷ, Đóng) never makes a fourth button:
|
|
192
|
+
* · in a DIALOG it is not in the foot at all — it is the ✕ of the
|
|
193
|
+
* dialog's head (`DialogHead` in @dqa-ai-solutions/ui-react), and an `<ActionBar>`
|
|
194
|
+
* inside a dialog refuses an exit. The foot counts like a page.
|
|
195
|
+
* · in a FORM on a page (no head to go to) it COUNTS as a secondary and
|
|
196
|
+
* is the one kept in sight, drawn `quiet`, never put in a menu: exit +
|
|
197
|
+
* one more stand side by side; exit + two or more leaves the exit in
|
|
198
|
+
* sight and the rest behind the trigger.
|
|
199
|
+
* ⛔ Until 27/9/2026 the exit was not counted, and a dialog showed
|
|
200
|
+
* "Đóng · Lưu tiền sử · Cấp lại mật khẩu · Tiếp đón" — four in a row. The
|
|
201
|
+
* user: *"lối ra chính cũng nên được tính là 1 nút phụ, để nó không bao
|
|
202
|
+
* giờ show đến 4 buttons"*, *"hoặc … đưa lối ra chính lên trên … header
|
|
203
|
+
* của dialog"* — and, shown both, chose the head: *"dùng style loại B"*.
|
|
204
|
+
*
|
|
205
|
+
* ④ ROWS AND LIST ITEMS HAVE NO PRIMARY. Forty rows, each painting one `key`,
|
|
206
|
+
* would be forty primaries on one screen. A card that is a place of its
|
|
207
|
+
* own (a room you hold, a section) is a `card`, and keeps its primary.
|
|
208
|
+
* · `table` (a row): data competes with words, so actions are icons,
|
|
209
|
+
* with the word as their name and tooltip.
|
|
210
|
+
* · `item` (a card repeated in a list): actions are words, drawn
|
|
211
|
+
* `normal` / `quiet`, as on a GOV.UK summary card.
|
|
212
|
+
* Both follow the counting of ③: up to two in sight; from three, one in
|
|
213
|
+
* sight and the rest behind the trigger.
|
|
214
|
+
*
|
|
215
|
+
* And EVERY ACTION HAS AN ICON: a menu item without its mark reads as
|
|
216
|
+
* unfinished, and an icon-only action without one is an unlabelled box.
|
|
217
|
+
* Reported, never guessed at.
|
|
218
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
219
|
+
*/
|
|
220
|
+
export interface ActionBar {
|
|
221
|
+
/** Drawn in place, in order. */
|
|
222
|
+
inline: ActionView[];
|
|
223
|
+
/** Behind one trigger — never exactly one item. Menu items always show their word. */
|
|
224
|
+
menu: ActionView[];
|
|
225
|
+
/** Actions with no icon to fall back on. */
|
|
226
|
+
missingIcon: string[];
|
|
227
|
+
/**
|
|
228
|
+
* The surface offers something to do and nothing says which is the point —
|
|
229
|
+
* two advancing steps, no `decision.outcome`, no `primary`. Mark one.
|
|
230
|
+
*/
|
|
231
|
+
missingPrimary: boolean;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Where a bar stands — see the scope table above. `table` and `item` repeat
|
|
235
|
+
* down the screen and have no primary. `page`, `dialog`, `form` and `rail`
|
|
236
|
+
* must name theirs. A `card` (also a section) is its own scope: it may carry
|
|
237
|
+
* its own primary, or none if another bar of its screen has one.
|
|
238
|
+
*/
|
|
239
|
+
export type ActionSurface = 'page' | 'dialog' | 'form' | 'table' | 'rail' | 'card' | 'item';
|
|
240
|
+
/** Secondary actions kept in sight beside the primary — see ②. */
|
|
241
|
+
export declare const VISIBLE_SECONDARY = 1;
|
|
242
|
+
/**
|
|
243
|
+
* How many of `n` secondary actions stay in sight: one, and both when there
|
|
244
|
+
* are exactly two, so that the menu never holds only one (③).
|
|
245
|
+
*/
|
|
246
|
+
export declare const inSightCount: (n: number) => number;
|
|
247
|
+
export declare function actionBar(facts: ActionFacts[], where: {
|
|
248
|
+
surface: ActionSurface;
|
|
249
|
+
}): ActionBar;
|
|
250
|
+
/**
|
|
251
|
+
* Which tokens paint a tier. Names only — this package emits no CSS rules.
|
|
252
|
+
*
|
|
253
|
+
* ⛔ `normal` sits on `--fos-surface`, NOT on the action colour. The reference
|
|
254
|
+
* app's stylesheet declared `.btn, button { background: var(--red) }`, so a
|
|
255
|
+
* bare `<button>` was already the loudest thing on the page; 33 screens ended
|
|
256
|
+
* up a wall of red that nobody chose, and a build check had to be written to
|
|
257
|
+
* count them. The default has to be quiet or the discipline never holds.
|
|
258
|
+
*/
|
|
259
|
+
export declare const TIER_PAINT: Record<ActionTier, {
|
|
260
|
+
background: string;
|
|
261
|
+
ink: string;
|
|
262
|
+
border: string | null;
|
|
263
|
+
}>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { type SurfaceKind, type SkeletonKind, type EmptyReason, type NextStep, type EmptyCopy, type Fault, type SurfaceState, type SurfaceInput, type StateHandlers, skeletonFor, surfaceState, matchState, assertNever, } from './state.js';
|
|
2
|
+
export { type ActionTier, type ActionFacts, type DisabledReason, type ActionView, actionViews, actionBar, primaryOf, inSightCount, VISIBLE_SECONDARY, TIER_PAINT, type ActionBar, type ActionSurface, } from './action.js';
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/** What a surface is made of. Decides whether a skeleton is even appropriate. */
|
|
2
|
+
export type SurfaceKind = 'table' | 'list' | 'card' | 'record' | 'field' | 'action';
|
|
3
|
+
/**
|
|
4
|
+
* ⚠️ Skeletons belong to surfaces that hold DATA, and to nothing else.
|
|
5
|
+
*
|
|
6
|
+
* Borrowed whole from Carbon, which states it plainly: action components —
|
|
7
|
+
* buttons, inputs, checkboxes, toggles — do not need a skeleton state. A
|
|
8
|
+
* pulsing grey rectangle where a button will be is not a loading hint, it is
|
|
9
|
+
* a control the user cannot yet see the purpose of.
|
|
10
|
+
*/
|
|
11
|
+
export type SkeletonKind = 'rows' | 'block' | null;
|
|
12
|
+
export declare const skeletonFor: (surface: SurfaceKind) => SkeletonKind;
|
|
13
|
+
/** Why there is nothing to show. The two are different screens, not one. */
|
|
14
|
+
export type EmptyReason = 'no-records' | 'no-match';
|
|
15
|
+
/** One thing the user can do from here. */
|
|
16
|
+
export interface NextStep {
|
|
17
|
+
label: string;
|
|
18
|
+
/** An action name, a route — whatever the renderer knows how to follow. */
|
|
19
|
+
go: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* What the screen says when it is empty.
|
|
23
|
+
*
|
|
24
|
+
* ⛔ `noMatch.action` IS REQUIRED, and that is the whole point of splitting the
|
|
25
|
+
* two reasons apart. A list emptied by a filter looks identical to a system
|
|
26
|
+
* with no data in it, and the user cannot tell which they are looking at —
|
|
27
|
+
* they conclude the records are gone. The way out of a filter has to be on
|
|
28
|
+
* the screen that the filter emptied, so the type will not let you ship one
|
|
29
|
+
* without it.
|
|
30
|
+
*
|
|
31
|
+
* ⚠️ `noRecords.action` is optional on purpose: plenty of lists are empty
|
|
32
|
+
* because the person looking has nothing to do yet, and inventing a button
|
|
33
|
+
* for them is worse than silence.
|
|
34
|
+
*/
|
|
35
|
+
export interface EmptyCopy {
|
|
36
|
+
noRecords: {
|
|
37
|
+
title: string;
|
|
38
|
+
body?: string;
|
|
39
|
+
action?: NextStep;
|
|
40
|
+
};
|
|
41
|
+
noMatch: {
|
|
42
|
+
title: string;
|
|
43
|
+
body?: string;
|
|
44
|
+
action: NextStep;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Something provably wrong with the data that arrived — not with the request.
|
|
49
|
+
*
|
|
50
|
+
* ⭐ `missing-key` is the one the reference app bled on: a contract promises a
|
|
51
|
+
* derived property, the read layer never produced the key, and the cell drew
|
|
52
|
+
* an em dash. Identical on screen to "this record has no link", so a broken
|
|
53
|
+
* join and an empty field looked the same for weeks.
|
|
54
|
+
*/
|
|
55
|
+
export interface Fault {
|
|
56
|
+
kind: 'missing-key' | 'stale' | 'clipped';
|
|
57
|
+
message: string;
|
|
58
|
+
}
|
|
59
|
+
export type SurfaceState<T> = {
|
|
60
|
+
kind: 'loading';
|
|
61
|
+
skeleton: SkeletonKind;
|
|
62
|
+
label: string;
|
|
63
|
+
} | {
|
|
64
|
+
kind: 'forbidden';
|
|
65
|
+
message: string;
|
|
66
|
+
} | {
|
|
67
|
+
kind: 'error';
|
|
68
|
+
message: string;
|
|
69
|
+
retry: boolean;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'empty';
|
|
72
|
+
because: EmptyReason;
|
|
73
|
+
title: string;
|
|
74
|
+
body?: string;
|
|
75
|
+
action?: NextStep;
|
|
76
|
+
}
|
|
77
|
+
/** Data arrived AND is provably incomplete. The renderer draws both. */
|
|
78
|
+
| {
|
|
79
|
+
kind: 'partial';
|
|
80
|
+
data: T;
|
|
81
|
+
faults: Fault[];
|
|
82
|
+
} | {
|
|
83
|
+
kind: 'ready';
|
|
84
|
+
data: T;
|
|
85
|
+
};
|
|
86
|
+
export interface SurfaceInput<T> {
|
|
87
|
+
/** Set to the reason when the viewer may not see this at all. */
|
|
88
|
+
forbidden?: string | false;
|
|
89
|
+
error?: string | null;
|
|
90
|
+
loading: boolean;
|
|
91
|
+
data?: T | null;
|
|
92
|
+
/** How many records `data` holds, when it is a collection. */
|
|
93
|
+
count?: number;
|
|
94
|
+
/** True while a search or filter is narrowing the result. */
|
|
95
|
+
narrowed?: boolean;
|
|
96
|
+
faults?: Fault[];
|
|
97
|
+
/** Required — see `EmptyCopy`. */
|
|
98
|
+
empty: EmptyCopy;
|
|
99
|
+
surface?: SurfaceKind;
|
|
100
|
+
/** Whether the error is worth offering a retry for. */
|
|
101
|
+
retry?: boolean;
|
|
102
|
+
loadingLabel?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* One place the order of precedence is decided, so fifty screens cannot each
|
|
106
|
+
* decide it differently.
|
|
107
|
+
*
|
|
108
|
+
* ⭐ THE TWO RULINGS WORTH READING
|
|
109
|
+
*
|
|
110
|
+
* ① Loading with data already in hand stays `ready`. Re-fetching must not
|
|
111
|
+
* blank the screen the user is reading — the reference app got this right
|
|
112
|
+
* by hand (`loading && !data ? <Loading/> : …`) on some screens and wrong
|
|
113
|
+
* on others, which is exactly what a shared decision is for.
|
|
114
|
+
*
|
|
115
|
+
* ② An error with data already in hand is a FAULT, not a state. Throwing away
|
|
116
|
+
* a page of records because a background refresh failed tells the user the
|
|
117
|
+
* data is gone when it is merely old.
|
|
118
|
+
*/
|
|
119
|
+
export declare function surfaceState<T>(input: SurfaceInput<T>): SurfaceState<T>;
|
|
120
|
+
/** Every state, answered. A missing key is a type error, not a blank screen. */
|
|
121
|
+
export interface StateHandlers<T, R> {
|
|
122
|
+
loading: (s: Extract<SurfaceState<T>, {
|
|
123
|
+
kind: 'loading';
|
|
124
|
+
}>) => R;
|
|
125
|
+
forbidden: (s: Extract<SurfaceState<T>, {
|
|
126
|
+
kind: 'forbidden';
|
|
127
|
+
}>) => R;
|
|
128
|
+
error: (s: Extract<SurfaceState<T>, {
|
|
129
|
+
kind: 'error';
|
|
130
|
+
}>) => R;
|
|
131
|
+
empty: (s: Extract<SurfaceState<T>, {
|
|
132
|
+
kind: 'empty';
|
|
133
|
+
}>) => R;
|
|
134
|
+
partial: (s: Extract<SurfaceState<T>, {
|
|
135
|
+
kind: 'partial';
|
|
136
|
+
}>) => R;
|
|
137
|
+
ready: (s: Extract<SurfaceState<T>, {
|
|
138
|
+
kind: 'ready';
|
|
139
|
+
}>) => R;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* ⭐ THE ENFORCEMENT. Generic in `R`, so the same call works for a React node, an
|
|
143
|
+
* HTML string, or a line of terminal output — the states are a fact about the
|
|
144
|
+
* data, not about the framework drawing it.
|
|
145
|
+
*/
|
|
146
|
+
export declare function matchState<T, R>(state: SurfaceState<T>, on: StateHandlers<T, R>): R;
|
|
147
|
+
/** Compile-time proof a union was handled; a loud failure if it was not. */
|
|
148
|
+
export declare function assertNever(value: never, where: string): never;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { navModel, routesOf, domainOf, type NavDecl, type NavDomain, type NavCluster, type NavItem, type ItemState, type ResolvedNavItem, type ResolvedNavCluster, type Route, type Viewer, type NavModel, } from './nav.js';
|
|
2
|
+
export { emptyTrail, moveTrail, titleTrail, backOf, returnOf, parseTrail, type Trail, type TrailEntry, type TrailMove, type TrailPlace, type TrailReturn, } from './trail.js';
|