@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.
Files changed (69) hide show
  1. package/README.md +17 -2
  2. package/dist/_types/ui-kit/index.d.ts +4 -0
  3. package/dist/_types/ui-kit/lens/action.d.ts +76 -0
  4. package/dist/_types/ui-kit/lens/cell.d.ts +79 -0
  5. package/dist/_types/ui-kit/lens/diagnostic.d.ts +49 -0
  6. package/dist/_types/ui-kit/lens/format.d.ts +32 -0
  7. package/dist/_types/ui-kit/lens/index.d.ts +12 -0
  8. package/dist/_types/ui-kit/lens/list.d.ts +223 -0
  9. package/dist/_types/ui-kit/lens/milestone.d.ts +112 -0
  10. package/dist/_types/ui-kit/lens/pattern.d.ts +38 -0
  11. package/dist/_types/ui-kit/lens/queue.d.ts +30 -0
  12. package/dist/_types/ui-kit/lens/record.d.ts +110 -0
  13. package/dist/_types/ui-kit/lens/registry.d.ts +9 -0
  14. package/dist/_types/ui-kit/lens/shape.d.ts +27 -0
  15. package/dist/_types/ui-kit/lens/timeline.d.ts +36 -0
  16. package/dist/_types/ui-kit/primitives/action.d.ts +263 -0
  17. package/dist/_types/ui-kit/primitives/index.d.ts +2 -0
  18. package/dist/_types/ui-kit/primitives/state.d.ts +148 -0
  19. package/dist/_types/ui-kit/shell/index.d.ts +2 -0
  20. package/dist/_types/ui-kit/shell/nav.d.ts +142 -0
  21. package/dist/_types/ui-kit/shell/trail.d.ts +85 -0
  22. package/dist/_types/ui-kit/tokens/index.d.ts +1 -0
  23. package/dist/_types/ui-kit/tokens/types.d.ts +252 -0
  24. package/dist/_types/ui-react/elements/action-bar.d.ts +32 -0
  25. package/dist/_types/ui-react/elements/action-scope.d.ts +9 -0
  26. package/dist/_types/ui-react/elements/button.d.ts +42 -0
  27. package/dist/_types/ui-react/elements/choice.d.ts +40 -0
  28. package/dist/_types/ui-react/elements/columns.d.ts +82 -0
  29. package/dist/_types/ui-react/elements/dialog-scope.d.ts +15 -0
  30. package/dist/_types/ui-react/elements/dialog.d.ts +67 -0
  31. package/dist/_types/ui-react/elements/disclosure.d.ts +305 -0
  32. package/dist/_types/ui-react/elements/field-attributes.d.ts +39 -0
  33. package/dist/_types/ui-react/elements/field.d.ts +628 -0
  34. package/dist/_types/ui-react/elements/file.d.ts +82 -0
  35. package/dist/_types/ui-react/elements/filter.d.ts +61 -0
  36. package/dist/_types/ui-react/elements/link.d.ts +38 -0
  37. package/dist/_types/ui-react/elements/menu.d.ts +56 -0
  38. package/dist/_types/ui-react/elements/milestone.d.ts +119 -0
  39. package/dist/_types/ui-react/elements/nav.d.ts +73 -0
  40. package/dist/_types/ui-react/elements/pop.d.ts +14 -0
  41. package/dist/_types/ui-react/elements/record.d.ts +174 -0
  42. package/dist/_types/ui-react/elements/segmented.d.ts +59 -0
  43. package/dist/_types/ui-react/elements/suggest.d.ts +11 -0
  44. package/dist/_types/ui-react/elements/surface.d.ts +354 -0
  45. package/dist/_types/ui-react/elements/table.d.ts +72 -0
  46. package/dist/_types/ui-react/elements/toast.d.ts +69 -0
  47. package/dist/_types/ui-react/index.d.ts +22 -0
  48. package/dist/_types/ui-react/prefix/index.d.ts +8 -0
  49. package/dist/chunks/chunk-4LX2HZJU.js +0 -0
  50. package/dist/chunks/chunk-7WHYHIUX.js +1 -0
  51. package/dist/chunks/chunk-VS5FCRGY.js +3 -0
  52. package/dist/chunks/chunk-X6SR5UHK.js +1 -0
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.js +1 -0
  55. package/dist/lens.d.ts +1 -0
  56. package/dist/lens.js +1 -0
  57. package/dist/primitives.d.ts +1 -0
  58. package/dist/primitives.js +1 -0
  59. package/dist/react.d.ts +1 -0
  60. package/dist/react.js +1 -0
  61. package/dist/shell.d.ts +1 -0
  62. package/dist/shell.js +1 -0
  63. package/dist/tokens.css +160 -0
  64. package/dist/tokens.d.ts +1 -0
  65. package/dist/tokens.dark.css +98 -0
  66. package/dist/tokens.generated.css +98 -0
  67. package/dist/tokens.high.css +98 -0
  68. package/dist/tokens.js +1 -0
  69. package/package.json +60 -4
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # @dqa-ai-solutions/ui-runtime
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The screen layer of the DQA runtime. The root is the kit — what a screen element must be: design
4
+ tokens, primitives, the lens over a view contract, the shell — with no framework in it. `./react`
5
+ draws it in React. Stands on `@dqa-ai-solutions/core-runtime` alone (the view contract, the value
6
+ checks), never on a server package, so a browser bundle never meets a database driver.
7
+
8
+ ```bash
9
+ npm i @dqa-ai-solutions/core-runtime @dqa-ai-solutions/ui-runtime
10
+ ```
11
+
12
+ | Import | What |
13
+ |---|---|
14
+ | `@dqa-ai-solutions/ui-runtime` (`/tokens`, `/primitives`, `/lens`, `/shell`) | what a screen element must be, decided from the `ViewContract` the server resolved |
15
+ | `@dqa-ai-solutions/ui-runtime/tokens.css` (`.generated`, `.dark`, `.high`) | theme stylesheets |
16
+ | `@dqa-ai-solutions/ui-runtime/react` | the React renderer (`react` is an optional peer) |
17
+
18
+ Every entry loads in a browser. ES modules only.
@@ -0,0 +1,4 @@
1
+ export * from './tokens/index.js';
2
+ export * from './primitives/index.js';
3
+ export * from './lens/index.js';
4
+ export * from './shell/index.js';
@@ -0,0 +1,76 @@
1
+ import type { ResolvedAction, ResolvedField, ViewContract } from '@dqa-ai-solutions/core-runtime/view';
2
+ import { type ActionFacts, type ActionView } from '../primitives/index.js';
3
+ import type { BlockRegistry } from './registry.js';
4
+ import type { LensDiagnostic } from './diagnostic.js';
5
+ export type Control = 'text' | 'textarea' | 'number' | 'date' | 'datetime' | 'select' | 'tags' | 'ref' | 'refs' | 'file' | 'unrenderable';
6
+ export interface FormField {
7
+ field: ResolvedField;
8
+ control: Control;
9
+ required: boolean;
10
+ /** Which entity a picker should be filled from. */
11
+ refEntity?: string;
12
+ /**
13
+ * `suggested` — the software proposes a value, the person confirms or changes it. Present only
14
+ * when the step declares `task.filledBy`; absent means nobody said, not "typed".
15
+ */
16
+ entry?: 'interaction' | 'suggested';
17
+ }
18
+ export interface ActionForm {
19
+ action: string;
20
+ label: string;
21
+ /** Set when the step wants a hand-written form instead of a generated one. */
22
+ widget?: string;
23
+ fields: FormField[];
24
+ /**
25
+ * Values the declaration already settled — the form must NOT ask for them.
26
+ *
27
+ * ⭐ A step that names the only authority who may sign, or the single citation
28
+ * that makes its paper valid, has already answered. Asking an operator to
29
+ * retype a written-down fact buys nothing and costs a class of typo that
30
+ * surfaces later, in somebody else's step.
31
+ */
32
+ settled: {
33
+ field: ResolvedField;
34
+ value: string;
35
+ }[];
36
+ /**
37
+ * Parameters the declaration says THE SOFTWARE fills (`task.filledBy: system`) — not asked.
38
+ *
39
+ * ⚠️ Not `settled`: no value is written down, so the app supplies it when the step is taken.
40
+ * A form that asked for it anyway would put a person in charge of a value nobody meant them
41
+ * to decide. Present only when non-empty.
42
+ */
43
+ bySoftware?: ResolvedField[];
44
+ diagnostics: LensDiagnostic[];
45
+ }
46
+ export declare function actionForm(action: ResolvedAction, blocks: BlockRegistry): ActionForm;
47
+ /** Steps this record can actually take from where it stands. */
48
+ export declare const availableActions: (contract: ViewContract, state: string | null) => ResolvedAction[];
49
+ /**
50
+ * The two facts about a step that NO declaration states.
51
+ *
52
+ * ⭐ `outcome` USED TO BE HERE AND IS GONE — the contract carries it now
53
+ * (`@dqa-ai-solutions/ontology-view` ≥ 0.24.0). What remains is genuinely outside the
54
+ * workflow's vocabulary:
55
+ *
56
+ * exits — leaves without writing. A workflow has no word for "cancel",
57
+ * because cancelling is not a step: nothing happens.
58
+ * destroys — irreversible. `to` says where the record goes, never whether
59
+ * the journey can be walked back.
60
+ *
61
+ * ⚠️ Passing `outcome` here still works and still wins, so an app on an older
62
+ * contract keeps running. But it is no longer the way — the workflow already
63
+ * knows, and two places knowing is two places to drift.
64
+ */
65
+ export interface ActionHints {
66
+ [action: string]: {
67
+ outcome?: 'approve' | 'reject';
68
+ exits?: boolean;
69
+ destroys?: boolean;
70
+ };
71
+ }
72
+ export declare function actionFacts(actions: ResolvedAction[], hints?: ActionHints): {
73
+ facts: ActionFacts[];
74
+ diagnostics: LensDiagnostic[];
75
+ };
76
+ export declare const actionButtons: (facts: ActionFacts[]) => ActionView[];
@@ -0,0 +1,79 @@
1
+ import type { ResolvedField, Tone } from '@dqa-ai-solutions/core-runtime/view';
2
+ import { type Formatter } from './format.js';
3
+ import type { BlockRegistry } from './registry.js';
4
+ export type Cell = {
5
+ kind: 'text';
6
+ field: ResolvedField;
7
+ text: string;
8
+ numeric: boolean;
9
+ long: boolean;
10
+ }
11
+ /** An enum value with the weight the ontology gave it. */
12
+ | {
13
+ kind: 'tone';
14
+ field: ResolvedField;
15
+ value: string;
16
+ label: string;
17
+ tone: Tone;
18
+ }
19
+ /** Present and null — the record legitimately has nothing here. */
20
+ | {
21
+ kind: 'blank';
22
+ field: ResolvedField;
23
+ }
24
+ /** The read layer never produced the key. Not a value; a defect. */
25
+ | {
26
+ kind: 'unwired';
27
+ field: ResolvedField;
28
+ message: string;
29
+ }
30
+ /**
31
+ * A value that also NAMES another record, and can open it.
32
+ *
33
+ * ⛔ `to` IS `{ entity, id }`, NEVER A STRING — and the type is the guard.
34
+ * An edge points at an identity, not at a display name: names are typed by
35
+ * people, get renamed, and repeat. A link built from one works until two
36
+ * units share a name, and then it opens the wrong record silently.
37
+ *
38
+ * Measured: 70 cross-record links hand-written across one application, each
39
+ * one composing its own path.
40
+ */
41
+ | {
42
+ kind: 'link';
43
+ field: ResolvedField;
44
+ text: string;
45
+ to: {
46
+ entity: string;
47
+ id: string;
48
+ };
49
+ }
50
+ /** A named component draws this, and receives the whole record. */
51
+ | {
52
+ kind: 'block';
53
+ field: ResolvedField;
54
+ widget: string;
55
+ }
56
+ /** A block was named that the renderer does not publish. */
57
+ | {
58
+ kind: 'missing-block';
59
+ field: ResolvedField;
60
+ widget: string;
61
+ message: string;
62
+ };
63
+ export interface CellContext {
64
+ format: Formatter;
65
+ blocks: BlockRegistry;
66
+ /**
67
+ * Draw an enum as plain words rather than as a badge.
68
+ *
69
+ * ⚠️ Not an aesthetic switch. The same enum means different things in
70
+ * different places: in a COLUMN it is a status the eye should catch, so a
71
+ * badge; on the SECOND LINE under a name it is an aside, so words. Draw
72
+ * badges in both and every row has two chips competing, and the eye has
73
+ * nowhere to land.
74
+ */
75
+ plain?: boolean;
76
+ }
77
+ export declare function cellOf(row: Record<string, unknown>, field: ResolvedField, ctx: CellContext): Cell;
78
+ /** Every cell that is a defect rather than a value. */
79
+ export declare const defectsOf: (cells: Cell[]) => Cell[];
@@ -0,0 +1,49 @@
1
+ export interface LensDiagnostic {
2
+ severity: 'error' | 'warn';
3
+ code:
4
+ /** A layout names a fact the contract does not carry. */
5
+ 'UNKNOWN_FACT'
6
+ /** Facts the contract declares that no section claimed — they would vanish. */
7
+ | 'ORPHAN_FACTS'
8
+ /** A block was named that the renderer does not publish. */
9
+ | 'UNKNOWN_BLOCK'
10
+ /** No property says what this record is CALLED to a person. */
11
+ | 'NO_TITLE'
12
+ /** A step's form cannot be built for a declared parameter type. */
13
+ | 'UNRENDERABLE_FIELD'
14
+ /** An event turned up with no wording — the machine code would be printed. */
15
+ | 'UNLABELLED_EVENT'
16
+ /** The contract does not yet carry something the lens needs. */
17
+ | 'CONTRACT_GAP'
18
+ /**
19
+ * A step names a state its line does not declare — usually the wrong line.
20
+ *
21
+ * ⚠️ An error even when only one step is affected. A route drawn with the
22
+ * record standing nowhere on it reads as "not started yet", which is a
23
+ * confident lie about a record that may be nearly finished.
24
+ */
25
+ | 'UNKNOWN_STATE'
26
+ /**
27
+ * Steps wait on a gate that no step declares itself the opener of.
28
+ *
29
+ * A warning, not an error: the wait is real and still reaches the screen
30
+ * through `waitsOn`. What cannot be done is NAME it — a gate borrows its
31
+ * label from the step that opens it, and this one has none to borrow.
32
+ */
33
+ | 'UNPLACED_GATE'
34
+ /** An entity runs several lines and nobody said which one this record is on. */
35
+ | 'AMBIGUOUS_LINE'
36
+ /**
37
+ * A related list is declared and the app supplied no rows for it.
38
+ *
39
+ * ⚠️ An error, not a warning, and drawn nowhere. A section rendered as an
40
+ * empty table is indistinguishable from one that genuinely has nothing —
41
+ * so a wiring mistake would read to a user as "this record has no
42
+ * decisions", which is a lie the screen tells confidently.
43
+ */
44
+ | 'MISSING_ROWS';
45
+ where: string;
46
+ message: string;
47
+ }
48
+ export declare const errorsIn: (list: LensDiagnostic[]) => LensDiagnostic[];
49
+ export declare function formatLensDiagnostics(list: LensDiagnostic[]): string;
@@ -0,0 +1,32 @@
1
+ import type { ResolvedField } from '@dqa-ai-solutions/core-runtime/view';
2
+ export interface FormatDecl {
3
+ /** BCP-47. No default: a wrong locale is worse than a missing one. */
4
+ locale: string;
5
+ /** ISO-4217, for fields the ontology marks `meaning: currency`. */
6
+ currency: string;
7
+ timeZone?: string;
8
+ }
9
+ export interface Formatter {
10
+ number(value: number): string;
11
+ currency(value: number): string;
12
+ percent(value: number): string;
13
+ date(value: string | number | Date): string;
14
+ datetime(value: string | number | Date): string;
15
+ decl: FormatDecl;
16
+ }
17
+ /**
18
+ * ⚠️ Built once and reused. `Intl` constructors are expensive enough that
19
+ * building one per cell is measurable on a table of a few hundred rows, and
20
+ * a list lens draws exactly that.
21
+ */
22
+ export declare function formatter(decl: FormatDecl): Formatter;
23
+ /** Anything longer than this is a paragraph wearing a cell. */
24
+ export declare const LONG_TEXT = 120;
25
+ /**
26
+ * One value, written out.
27
+ *
28
+ * ⚠️ `meaning` outranks `kind`, because meaning is the rarer and stronger claim:
29
+ * a currency is stored as a number, and the ontology went to the trouble of
30
+ * saying it is money.
31
+ */
32
+ export declare function writeValue(f: Formatter, field: ResolvedField, value: unknown): string;
@@ -0,0 +1,12 @@
1
+ export { formatter, writeValue, LONG_TEXT, type FormatDecl, type Formatter } from './format.js';
2
+ export { readValue, fieldsOf, ABSENT } from './shape.js';
3
+ export { registryOf, NO_BLOCKS, type BlockRegistry } from './registry.js';
4
+ export { cellOf, defectsOf, type Cell, type CellContext } from './cell.js';
5
+ export { type LensDiagnostic, errorsIn, formatLensDiagnostics, } from './diagnostic.js';
6
+ export { listModel, planColumns, subjectOf, type ListInput, type ListModel, type ListBody, type ListRow, type ColumnPlan, type ColumnChoice, type ColumnVisibility, type PlanColumnsOptions, } from './list.js';
7
+ export { recordModel, type RecordInput, type RecordModel, type RecordBody, type RecordPart, type RecordSection, type RecordLayout, type RecordTab, } from './record.js';
8
+ export { queueModel, type QueueInput, type QueueModel, type QueueItem } from './queue.js';
9
+ export { milestoneModel, type MilestoneInput, type MilestoneModel, type Milestone, type MilestoneReturn, type MilestoneStanding, } from './milestone.js';
10
+ export { timelineModel, type TimelineInput, type TimelineModel, type TimelineEntry, type RawEvent, type EventVocabulary, } from './timeline.js';
11
+ export { actionForm, availableActions, actionFacts, actionButtons, type ActionForm, type FormField, type Control, type ActionHints, } from './action.js';
12
+ export { presentationOf, readersOf, undeterminedIn, type Presentation, type Determined, } from './pattern.js';
@@ -0,0 +1,223 @@
1
+ import type { ViewContract, ResolvedField } from '@dqa-ai-solutions/core-runtime/view';
2
+ import { type Fault, type SurfaceState, type EmptyCopy } from '../primitives/index.js';
3
+ import { type Cell, type CellContext } from './cell.js';
4
+ export interface ListRow {
5
+ id: string;
6
+ /** The identity cell — the contract said which property IS the name. */
7
+ main: Cell | null;
8
+ /** A second line under it. Words, never a badge — see `CellContext.plain`. */
9
+ sub: Cell | null;
10
+ cells: Cell[];
11
+ }
12
+ export interface ListBody {
13
+ /** Columns to draw now. */
14
+ columns: ResolvedField[];
15
+ /**
16
+ * Columns held back — draw them behind one "more columns" control.
17
+ *
18
+ * ⛔ THE NUMBER THAT PROMPTED THIS WAS A UNIT ERROR, MINE AS WELL AS THE
19
+ * REPORTER'S. "679 columns across 56 screens, one table with 31" divides
20
+ * `<th>` by SCREEN, and a screen holds several tables. Counted per
21
+ * `<table>`: 126 tables, mean 5.4 columns, two above eight.
22
+ *
23
+ * Enterprise guidance does converge on six-to-eight-then-hide, and this
24
+ * implements it — but the application it was built for was already inside
25
+ * that range. This is a fence for contracts that grow, not a fix for a
26
+ * table that is too wide today.
27
+ *
28
+ * ⚠️ HELD BACK, NEVER DROPPED. A column the contract declares and the renderer
29
+ * silently loses is the failure this package exists to remove.
30
+ */
31
+ /**
32
+ * Held back because the table ran out of room, in the contract's own order of
33
+ * importance.
34
+ *
35
+ * ⭐ NOT A LEFTOVER — SOMETHING TO OFFER BACK. A column that vanishes
36
+ * silently leaves the reader unable to know what they are not shown; but
37
+ * merely SAYING so ("2 columns not shown") was the next mistake — the
38
+ * reader could read the names and do nothing. `choices` is what a column
39
+ * picker on the table draws; the wording is the app's, as wording always is.
40
+ */
41
+ extraColumns: ResolvedField[];
42
+ /** See `ColumnPlan.choices`. */
43
+ choices: ColumnChoice[];
44
+ customised: boolean;
45
+ rows: ListRow[];
46
+ /**
47
+ * The column that names the row — it must carry `scope="row"`.
48
+ *
49
+ * ⭐ The lens already knew which column this is (`list.main`); it simply never
50
+ * said so, and every app had to remember. Measured on the first adopter:
51
+ * `scope` on 0 of 56 screens with tables, `aria-sort` on 0. GOV.UK and USWDS
52
+ * both require `scope` — without it a screen reader cannot work out which
53
+ * header belongs to which cell. For a government system it is also the kind
54
+ * of thing an assessor checks with an automated tool in seconds.
55
+ */
56
+ rowHeaderKey: string | null;
57
+ /** Per column: what a header should announce as `aria-sort`. */
58
+ sortState: Record<string, 'ascending' | 'descending' | 'none'>;
59
+ /** Property names the contract says are searchable. */
60
+ search: string[];
61
+ sort: ViewContract['list'] extends {
62
+ sort: infer S;
63
+ } ? S : never;
64
+ }
65
+ export interface ListInput {
66
+ contract: ViewContract;
67
+ rows: Record<string, unknown>[] | null;
68
+ loading: boolean;
69
+ error?: string | null;
70
+ forbidden?: string | false;
71
+ /** True while a search term or a filter is narrowing the result. */
72
+ narrowed?: boolean;
73
+ empty: EmptyCopy;
74
+ /**
75
+ * Total across all pages, when the server paginates. Falls back to `rows`.
76
+ *
77
+ * ⛔ `total: rows.length` IS NOT PAGINATION, AND IT HIDES THAT IT ISN'T.
78
+ *
79
+ * Measured in the reference app: one screen drew **23,706 rows** into the
80
+ * DOM and its API call took **14,520ms**. Nothing threw, every render check
81
+ * passed, and no pager appeared — because a pager with no offset draws
82
+ * nothing, so the screen looked like a screen that simply had no pages.
83
+ * The promise concealed its own absence. Fifteen more screens were the same.
84
+ *
85
+ * ⚠️ AND PAGING THE SCREEN ONLY MOVES THE COST — IT DOES NOT REMOVE IT.
86
+ * The same screen's server was aggregating headcount across all 23,706
87
+ * units and then taking twenty rows. Cutting the page FIRST and aggregating
88
+ * for those twenty: 14,520ms → 78ms.
89
+ *
90
+ * This package receives `total` from outside and cannot tell a real one
91
+ * from `rows.length`. That is the correct boundary — the read layer is not
92
+ * ours — so this is stated here, where the person passing the number is
93
+ * looking, and it is the only place it can be said.
94
+ */
95
+ total?: number;
96
+ /**
97
+ * How many columns to draw before holding the rest back. Default 7.
98
+ *
99
+ * ⚠️ A default, not a law — a two-column reference table should not be padded
100
+ * to seven. But it is the SAME default everywhere until an app has a reason,
101
+ * which is the opposite of where this started.
102
+ */
103
+ maxColumns?: number;
104
+ /** The reader's column overrides — passed straight to `planColumns`. */
105
+ visibility?: PlanColumnsOptions['visibility'];
106
+ hiddenByDefault?: PlanColumnsOptions['hiddenByDefault'];
107
+ }
108
+ export interface ListModel {
109
+ state: SurfaceState<ListBody>;
110
+ /** Everything provably wrong, whatever state the surface ended in. */
111
+ faults: Fault[];
112
+ }
113
+ /**
114
+ * One column as the READER can choose it — on or off, and whether it may be
115
+ * turned off at all.
116
+ *
117
+ * ⭐ SHAPE BORROWED WHOLE FROM THE GRIDS PEOPLE ALREADY USE. MUI DataGrid keeps
118
+ * a `columnVisibilityModel` of `{ field: false }`; AG Grid, Airtable
119
+ * ("Hide fields") and GitHub Projects ("Fields") draw the same thing: a list
120
+ * of every column with a toggle each, the name column fixed.
121
+ */
122
+ export interface ColumnChoice {
123
+ key: string;
124
+ label: string;
125
+ shown: boolean;
126
+ /** The column that names the row. It cannot be turned off. */
127
+ locked: boolean;
128
+ /** Hidden by the plan's own default — not by the reader. */
129
+ hiddenByDefault: boolean;
130
+ }
131
+ /**
132
+ * The reader's overrides, and ONLY the overrides: `{ key: true | false }`.
133
+ *
134
+ * ⚠️ NOT THE LIST OF SHOWN KEYS. Storing "these six are shown" freezes the table
135
+ * on the day it was saved — a column the contract gains next month never
136
+ * appears for that reader, silently. Storing only what the reader changed
137
+ * lets every untouched column follow the contract.
138
+ */
139
+ export type ColumnVisibility = Record<string, boolean>;
140
+ /** What `planColumns` decides — no rows, no formatter, no blocks. */
141
+ export interface ColumnPlan {
142
+ columns: ResolvedField[];
143
+ extraColumns: ResolvedField[];
144
+ /**
145
+ * Every column in draw order, each with whether it is shown now — what a
146
+ * column picker lists.
147
+ *
148
+ * ⛔ HELD-BACK COLUMNS ARE NOT SOMETHING TO ANNOUNCE, THEY ARE SOMETHING TO
149
+ * OFFER. The first adopter printed "2 columns not shown in this table" in
150
+ * a disclosure above the header: the reader could learn which ones and do
151
+ * nothing about it. Its user called that plainly bad UX, and every mature
152
+ * grid agrees — the choice sits ON the table.
153
+ */
154
+ choices: ColumnChoice[];
155
+ /** True when a stored override actually changes what is shown. */
156
+ customised: boolean;
157
+ rowHeaderKey: string | null;
158
+ sortState: Record<string, 'ascending' | 'descending' | 'none'>;
159
+ }
160
+ export interface PlanColumnsOptions {
161
+ /** How many columns an untouched table draws. Default 7. */
162
+ maxColumns?: number;
163
+ /** The reader's overrides — see `ColumnVisibility`. */
164
+ visibility?: ColumnVisibility;
165
+ /**
166
+ * Columns the APP hides until asked — e.g. empty on every row in view.
167
+ *
168
+ * ⚠️ HIDDEN BY DEFAULT, STILL OFFERED. Removing them from the contract before
169
+ * planning — what the first adopter did — also removes them from the
170
+ * picker, and a reader who needs one has no way back to it.
171
+ */
172
+ hiddenByDefault?: readonly string[];
173
+ }
174
+ /**
175
+ * Which columns a table shows, and what its headers must announce.
176
+ *
177
+ * ⭐ SPLIT OUT ON REQUEST FROM THE FIRST ADOPTER, AND THE BOUNDARY IS RIGHT.
178
+ * A renderer that already draws its own cells and already sits inside its own
179
+ * state wrapper needs the DECISION and nothing else; making it call
180
+ * `listModel` meant handing over a formatter and a block registry in order to
181
+ * receive rows it would throw away.
182
+ *
183
+ * Decision separated from data assembly — the same seam as `tokens` apart
184
+ * from `lens`.
185
+ */
186
+ export declare function planColumns(contract: ViewContract, options?: PlanColumnsOptions): ColumnPlan;
187
+ /**
188
+ * What NAMES this record to a person.
189
+ *
190
+ * ⭐ WRITTEN BY THE FIRST ADOPTER BEFORE IT EXISTED HERE, WHICH IS THE ARGUMENT
191
+ * FOR IT BEING HERE.
192
+ *
193
+ * Their work queue stored a STEP LABEL in its title column, so a screen
194
+ * officers open first every morning showed thirteen bare verbs — "Add
195
+ * target", "Edit target" — and not one line said which record it was about.
196
+ * The fix needs the record's own name, and the contract already says which
197
+ * property that is (`list.main.key`). They had to reach for it by hand.
198
+ *
199
+ * ⚠️ ASKS THE CONTRACT, NEVER GUESSES BY FIELD NAME. A hand-written
200
+ * `['fullName', 'unitName', 'title']` is right on the day it is written and
201
+ * wrong on the day an entity is added — and wrong silently, because a
202
+ * missing name looks like a record with no name.
203
+ *
204
+ * ⚠️ And it reads the record through the same two-shape lookup as every cell,
205
+ * so an envelope beside top-level store columns behaves identically here and
206
+ * in a table. Two readers of one record shape is how they drift.
207
+ */
208
+ export declare function subjectOf(contract: ViewContract, row: Record<string, unknown>, options?: {
209
+ /**
210
+ * Which surface is asking.
211
+ *
212
+ * ⚠️ The contract resolves TWO names — `list.main` and `row.main` — and
213
+ * both fall back to the property the ontology marks `title`, so they
214
+ * agree unless an app deliberately declared different ones. When it did,
215
+ * the caller has to say which surface it is drawing; guessing picks the
216
+ * wrong one exactly on the app that took the trouble to distinguish them.
217
+ */
218
+ as?: 'record' | 'queue';
219
+ }): {
220
+ key: string;
221
+ text: string;
222
+ } | null;
223
+ export declare function listModel(input: ListInput, ctx: CellContext): ListModel;
@@ -0,0 +1,112 @@
1
+ import type { ViewContract } from '@dqa-ai-solutions/core-runtime/view';
2
+ import type { LensDiagnostic } from './diagnostic.js';
3
+ type StateDecl = NonNullable<ViewContract['states']>[number];
4
+ /**
5
+ * Where a milestone sits relative to the record — POSITION, not truth.
6
+ *
7
+ * ⚠️ A gate is never `current`. A record is always in a state; it is never "in"
8
+ * a gate. Whether the gate has been settled is `verdict`, and whether it is
9
+ * the thing holding the record up is `awaiting`. Folding those into
10
+ * `standing` would let one field say a record is somewhere it cannot be.
11
+ */
12
+ export type MilestoneStanding = 'past' | 'current' | 'ahead';
13
+ export interface Milestone {
14
+ kind: 'state' | 'gate';
15
+ /** A state name, or the gate's `via`. Machine key — never printed. */
16
+ key: string;
17
+ /**
18
+ * THE WORK THAT REACHES THIS POINT, not the state it leaves behind.
19
+ *
20
+ * ⛔ A ROUTE IS A LIST OF THINGS TO DO, AND A STATE LABEL IS THE WRONG
21
+ * GRAMMAR FOR ONE. States are named for a record that has already got
22
+ * there — "submitted", "invited", "in progress" — so a strip built from
23
+ * them tells the reader that work they have not done is already done.
24
+ * Reported by the user looking at their own route:
25
+ *
26
+ * *"sao nó luôn có từ 'Đã' hoặc 'Đang' nhỉ? mấy cái từ đó thực tế
27
+ * không đúng"* — why is every one of these "already" or "currently"?
28
+ * Those words are not true.
29
+ *
30
+ * They were right, and the fix was already half-built: a GATE has always
31
+ * been named by the step that opens it. This applies the same rule to the
32
+ * other kind of milestone, so the whole strip reads in one grammar.
33
+ *
34
+ * ⚠️ FALLS BACK TO THE STATE'S OWN LABEL when the work cannot be named without
35
+ * picking sides — see `stateLabel`. Measured on the reference app: 225 of
36
+ * 253 states are reached by exactly one step and take its name; the other
37
+ * 28 keep theirs.
38
+ */
39
+ label: string;
40
+ /**
41
+ * The state's own declared label, always — "Đã trình cấp trên".
42
+ *
43
+ * ⭐ STILL CARRIED, because it is still the right word in other places: the
44
+ * badge at the top of a record says what the record IS, and that is a
45
+ * state, not a task. Two questions, two words, and the contract has both.
46
+ */
47
+ stateLabel?: string;
48
+ hint?: string;
49
+ tone?: StateDecl['tone'];
50
+ standing: MilestoneStanding;
51
+ /**
52
+ * Roles that act here — identifiers, not words.
53
+ *
54
+ * ⚠️ Naming a role is the application's job: a role code means a job title,
55
+ * a rank and a level of command, and none of those are this package's to
56
+ * know. It carries the identifier so the app can look up its own word.
57
+ */
58
+ roles: string[];
59
+ /** For a gate the app reported settled: the verdict it was settled with. */
60
+ verdict?: string;
61
+ /** True when this gate, and nothing else, stands between the record and moving on. */
62
+ awaiting?: boolean;
63
+ }
64
+ /**
65
+ * A step that walks the record BACKWARD — a refusal, a hand-back for revision.
66
+ *
67
+ * ⛔ REPORTED APART FROM THE SPINE, deliberately. Twenty-two of the reference
68
+ * app's 54 processes have one, so they are normal, not exceptional. But a
69
+ * return laid out as another chip in the row asserts a direction the record
70
+ * does not travel — the strip would read as though "sent back to draft" comes
71
+ * after "submitted", when it goes back to a milestone already drawn.
72
+ */
73
+ export interface MilestoneReturn {
74
+ action: string;
75
+ label: string;
76
+ role: string;
77
+ from: string[];
78
+ to: string;
79
+ }
80
+ export interface MilestoneInput {
81
+ contract: ViewContract;
82
+ /** Where the record stands. `null` before it exists. */
83
+ state: string | null;
84
+ /**
85
+ * Which line the record runs on.
86
+ *
87
+ * ⚠️ REQUIRED once an entity declares more than one, and not guessed. Four
88
+ * lines drawn end to end are not a longer route; they are four routes drawn
89
+ * as one, which is a picture of nothing. See the `AMBIGUOUS_LINE` branch.
90
+ */
91
+ process?: string;
92
+ /**
93
+ * Gates the application knows are settled: `via` → the verdict.
94
+ *
95
+ * ⚠️ THE LENS NEVER RESOLVES A GATE. Whether an approval exists is a fact in
96
+ * the domain's store, reached by a query this package does not make and
97
+ * must not learn to make. Absent simply means unsettled.
98
+ */
99
+ settled?: Record<string, string>;
100
+ }
101
+ export interface MilestoneModel {
102
+ milestones: Milestone[];
103
+ returns: MilestoneReturn[];
104
+ diagnostics: LensDiagnostic[];
105
+ }
106
+ /**
107
+ * The route, and where on it the record stands.
108
+ *
109
+ * @param input.settled which gates the application has already resolved.
110
+ */
111
+ export declare function milestoneModel(input: MilestoneInput): MilestoneModel;
112
+ export {};
@@ -0,0 +1,38 @@
1
+ import type { ResolvedAction, ViewContract } from '@dqa-ai-solutions/core-runtime/view';
2
+ export type Presentation = {
3
+ readonly surface: 'none';
4
+ } | {
5
+ readonly surface: 'action';
6
+ /** What the person must see before acting — empty means nothing beyond the record. */
7
+ readonly review: readonly string[];
8
+ readonly input: 'none' | 'fields' | 'document';
9
+ /** Fields the person types · fields the software proposes and the person confirms. */
10
+ readonly typed: readonly string[];
11
+ readonly suggested: readonly string[];
12
+ readonly over: 'single' | 'records' | {
13
+ readonly rows: string;
14
+ };
15
+ };
16
+ export type Determined<T> = {
17
+ readonly determined: true;
18
+ readonly value: T;
19
+ } | {
20
+ readonly determined: false;
21
+ readonly why: string;
22
+ };
23
+ export declare function presentationOf(action: ResolvedAction): Determined<Presentation>;
24
+ /**
25
+ * Who else may see a record at a state, on one line — REAL role codes.
26
+ *
27
+ * ⚠️ Intent, not enforcement. Row-level security in the host's store decides what a person can
28
+ * actually read; this says what the screen should show a reader who is not acting.
29
+ */
30
+ export declare function readersOf(contract: ViewContract, process: string, state: string): Determined<readonly string[]>;
31
+ /**
32
+ * Every step and state of a contract the selector could not decide — the coverage question a
33
+ * build can ask before anyone opens a screen. Empty means every step has exactly one pattern.
34
+ */
35
+ export declare function undeterminedIn(contract: ViewContract): {
36
+ at: string;
37
+ why: string;
38
+ }[];