@azx-pbc/axiom-builder 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +648 -2
- package/dist/cards/selectors.d.ts +70 -0
- package/dist/cards/selectors.d.ts.map +1 -0
- package/dist/cards/selectors.js +194 -0
- package/dist/cards/selectors.js.map +1 -0
- package/dist/definition.d.ts +36 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +48 -0
- package/dist/definition.js.map +1 -0
- package/dist/evidence/cases.d.ts +44 -0
- package/dist/evidence/cases.d.ts.map +1 -0
- package/dist/evidence/cases.js +578 -0
- package/dist/evidence/cases.js.map +1 -0
- package/dist/evidence/repairs.d.ts +99 -0
- package/dist/evidence/repairs.d.ts.map +1 -0
- package/dist/evidence/repairs.js +181 -0
- package/dist/evidence/repairs.js.map +1 -0
- package/dist/evidence/summary.d.ts +35 -0
- package/dist/evidence/summary.d.ts.map +1 -0
- package/dist/evidence/summary.js +38 -0
- package/dist/evidence/summary.js.map +1 -0
- package/dist/i18n/gaps.d.ts +3 -0
- package/dist/i18n/gaps.d.ts.map +1 -0
- package/dist/i18n/gaps.js +2 -0
- package/dist/i18n/gaps.js.map +1 -0
- package/dist/i18n/message-slots.d.ts +19 -0
- package/dist/i18n/message-slots.d.ts.map +1 -0
- package/dist/i18n/message-slots.js +101 -0
- package/dist/i18n/message-slots.js.map +1 -0
- package/dist/i18n/text-locale.d.ts +13 -0
- package/dist/i18n/text-locale.d.ts.map +1 -0
- package/dist/i18n/text-locale.js +14 -0
- package/dist/i18n/text-locale.js.map +1 -0
- package/dist/i18n/translations.d.ts +56 -0
- package/dist/i18n/translations.d.ts.map +1 -0
- package/dist/i18n/translations.js +103 -0
- package/dist/i18n/translations.js.map +1 -0
- package/dist/impact/references.d.ts +143 -0
- package/dist/impact/references.d.ts.map +1 -0
- package/dist/impact/references.js +429 -0
- package/dist/impact/references.js.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.js.map +1 -0
- package/dist/preview/compile-preview.d.ts +67 -0
- package/dist/preview/compile-preview.d.ts.map +1 -0
- package/dist/preview/compile-preview.js +286 -0
- package/dist/preview/compile-preview.js.map +1 -0
- package/dist/preview/handle.d.ts +119 -0
- package/dist/preview/handle.d.ts.map +1 -0
- package/dist/preview/handle.js +2 -0
- package/dist/preview/handle.js.map +1 -0
- package/dist/preview/held.d.ts +39 -0
- package/dist/preview/held.d.ts.map +1 -0
- package/dist/preview/held.js +15 -0
- package/dist/preview/held.js.map +1 -0
- package/dist/preview/measurement.d.ts +5 -0
- package/dist/preview/measurement.d.ts.map +1 -0
- package/dist/preview/measurement.js +18 -0
- package/dist/preview/measurement.js.map +1 -0
- package/dist/publish/build.d.ts +33 -0
- package/dist/publish/build.d.ts.map +1 -0
- package/dist/publish/build.js +15 -0
- package/dist/publish/build.js.map +1 -0
- package/dist/publish/diff.d.ts +208 -0
- package/dist/publish/diff.d.ts.map +1 -0
- package/dist/publish/diff.js +227 -0
- package/dist/publish/diff.js.map +1 -0
- package/dist/publish/review.d.ts +41 -0
- package/dist/publish/review.d.ts.map +1 -0
- package/dist/publish/review.js +22 -0
- package/dist/publish/review.js.map +1 -0
- package/dist/schema/dataset-input.d.ts +30 -0
- package/dist/schema/dataset-input.d.ts.map +1 -0
- package/dist/schema/dataset-input.js +58 -0
- package/dist/schema/dataset-input.js.map +1 -0
- package/dist/schema/dataset.d.ts +166 -0
- package/dist/schema/dataset.d.ts.map +1 -0
- package/dist/schema/dataset.js +281 -0
- package/dist/schema/dataset.js.map +1 -0
- package/dist/schema/declarations.d.ts +15 -0
- package/dist/schema/declarations.d.ts.map +1 -0
- package/dist/schema/declarations.js +47 -0
- package/dist/schema/declarations.js.map +1 -0
- package/dist/schema/document.d.ts +504 -0
- package/dist/schema/document.d.ts.map +1 -0
- package/dist/schema/document.js +337 -0
- package/dist/schema/document.js.map +1 -0
- package/dist/schema/error.d.ts +15 -0
- package/dist/schema/error.d.ts.map +1 -0
- package/dist/schema/error.js +18 -0
- package/dist/schema/error.js.map +1 -0
- package/dist/schema/field-id.d.ts +8 -0
- package/dist/schema/field-id.d.ts.map +1 -0
- package/dist/schema/field-id.js +47 -0
- package/dist/schema/field-id.js.map +1 -0
- package/dist/schema/layout.d.ts +118 -0
- package/dist/schema/layout.d.ts.map +1 -0
- package/dist/schema/layout.js +101 -0
- package/dist/schema/layout.js.map +1 -0
- package/dist/schema/palette.d.ts +103 -0
- package/dist/schema/palette.d.ts.map +1 -0
- package/dist/schema/palette.js +140 -0
- package/dist/schema/palette.js.map +1 -0
- package/dist/schema/read.d.ts +49 -0
- package/dist/schema/read.d.ts.map +1 -0
- package/dist/schema/read.js +942 -0
- package/dist/schema/read.js.map +1 -0
- package/dist/store/apply-dataset.d.ts +14 -0
- package/dist/store/apply-dataset.d.ts.map +1 -0
- package/dist/store/apply-dataset.js +513 -0
- package/dist/store/apply-dataset.js.map +1 -0
- package/dist/store/apply.d.ts +37 -0
- package/dist/store/apply.d.ts.map +1 -0
- package/dist/store/apply.js +2269 -0
- package/dist/store/apply.js.map +1 -0
- package/dist/store/candidate.d.ts +37 -0
- package/dist/store/candidate.d.ts.map +1 -0
- package/dist/store/candidate.js +178 -0
- package/dist/store/candidate.js.map +1 -0
- package/dist/store/commands/coverage.d.ts +58 -0
- package/dist/store/commands/coverage.d.ts.map +1 -0
- package/dist/store/commands/coverage.js +354 -0
- package/dist/store/commands/coverage.js.map +1 -0
- package/dist/store/commands/dataset.d.ts +26 -0
- package/dist/store/commands/dataset.d.ts.map +1 -0
- package/dist/store/commands/dataset.js +368 -0
- package/dist/store/commands/dataset.js.map +1 -0
- package/dist/store/commands/document.d.ts +21 -0
- package/dist/store/commands/document.d.ts.map +1 -0
- package/dist/store/commands/document.js +160 -0
- package/dist/store/commands/document.js.map +1 -0
- package/dist/store/commands/field.d.ts +32 -0
- package/dist/store/commands/field.d.ts.map +1 -0
- package/dist/store/commands/field.js +572 -0
- package/dist/store/commands/field.js.map +1 -0
- package/dist/store/commands/layout.d.ts +16 -0
- package/dist/store/commands/layout.d.ts.map +1 -0
- package/dist/store/commands/layout.js +70 -0
- package/dist/store/commands/layout.js.map +1 -0
- package/dist/store/commands/parse.d.ts +19 -0
- package/dist/store/commands/parse.d.ts.map +1 -0
- package/dist/store/commands/parse.js +328 -0
- package/dist/store/commands/parse.js.map +1 -0
- package/dist/store/commands/readers.d.ts +198 -0
- package/dist/store/commands/readers.d.ts.map +1 -0
- package/dist/store/commands/readers.js +711 -0
- package/dist/store/commands/readers.js.map +1 -0
- package/dist/store/commands/rule.d.ts +24 -0
- package/dist/store/commands/rule.d.ts.map +1 -0
- package/dist/store/commands/rule.js +379 -0
- package/dist/store/commands/rule.js.map +1 -0
- package/dist/store/commands/shapes.d.ts +900 -0
- package/dist/store/commands/shapes.d.ts.map +1 -0
- package/dist/store/commands/shapes.js +166 -0
- package/dist/store/commands/shapes.js.map +1 -0
- package/dist/store/commands/suggestions.d.ts +37 -0
- package/dist/store/commands/suggestions.d.ts.map +1 -0
- package/dist/store/commands/suggestions.js +177 -0
- package/dist/store/commands/suggestions.js.map +1 -0
- package/dist/store/commands.d.ts +16 -0
- package/dist/store/commands.d.ts.map +1 -0
- package/dist/store/commands.js +13 -0
- package/dist/store/commands.js.map +1 -0
- package/dist/store/dataset-candidate.d.ts +33 -0
- package/dist/store/dataset-candidate.d.ts.map +1 -0
- package/dist/store/dataset-candidate.js +31 -0
- package/dist/store/dataset-candidate.js.map +1 -0
- package/dist/store/dataset-pin.d.ts +93 -0
- package/dist/store/dataset-pin.d.ts.map +1 -0
- package/dist/store/dataset-pin.js +86 -0
- package/dist/store/dataset-pin.js.map +1 -0
- package/dist/store/dataset-store.d.ts +96 -0
- package/dist/store/dataset-store.d.ts.map +1 -0
- package/dist/store/dataset-store.js +112 -0
- package/dist/store/dataset-store.js.map +1 -0
- package/dist/store/history.d.ts +149 -0
- package/dist/store/history.d.ts.map +1 -0
- package/dist/store/history.js +173 -0
- package/dist/store/history.js.map +1 -0
- package/dist/store/measurement.d.ts +5 -0
- package/dist/store/measurement.d.ts.map +1 -0
- package/dist/store/measurement.js +20 -0
- package/dist/store/measurement.js.map +1 -0
- package/dist/store/notify.d.ts +11 -0
- package/dist/store/notify.d.ts.map +1 -0
- package/dist/store/notify.js +26 -0
- package/dist/store/notify.js.map +1 -0
- package/dist/store/published.d.ts +50 -0
- package/dist/store/published.d.ts.map +1 -0
- package/dist/store/published.js +27 -0
- package/dist/store/published.js.map +1 -0
- package/dist/store/refusals.d.ts +175 -0
- package/dist/store/refusals.d.ts.map +1 -0
- package/dist/store/refusals.js +160 -0
- package/dist/store/refusals.js.map +1 -0
- package/dist/store/steps.d.ts +14 -0
- package/dist/store/steps.d.ts.map +1 -0
- package/dist/store/steps.js +124 -0
- package/dist/store/steps.js.map +1 -0
- package/dist/store/store.d.ts +142 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +136 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store/unchanged.d.ts +12 -0
- package/dist/store/unchanged.d.ts.map +1 -0
- package/dist/store/unchanged.js +35 -0
- package/dist/store/unchanged.js.map +1 -0
- package/dist/visual/emit.d.ts +21 -0
- package/dist/visual/emit.d.ts.map +1 -0
- package/dist/visual/emit.js +133 -0
- package/dist/visual/emit.js.map +1 -0
- package/dist/visual/parse.d.ts +32 -0
- package/dist/visual/parse.d.ts.map +1 -0
- package/dist/visual/parse.js +330 -0
- package/dist/visual/parse.js.map +1 -0
- package/dist/visual/project.d.ts +40 -0
- package/dist/visual/project.d.ts.map +1 -0
- package/dist/visual/project.js +349 -0
- package/dist/visual/project.js.map +1 -0
- package/dist/visual/represent.d.ts +50 -0
- package/dist/visual/represent.d.ts.map +1 -0
- package/dist/visual/represent.js +66 -0
- package/dist/visual/represent.js.map +1 -0
- package/dist/visual/vocabulary.d.ts +121 -0
- package/dist/visual/vocabulary.d.ts.map +1 -0
- package/dist/visual/vocabulary.js +32 -0
- package/dist/visual/vocabulary.js.map +1 -0
- package/package.json +52 -3
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { SchemaDiagnostic } from '@azx-pbc/axiom-compiler';
|
|
2
|
+
import type { AuthoringDocument } from '../schema/document.js';
|
|
3
|
+
/**
|
|
4
|
+
* The content of one authoring state: the document and the diagnostics a compile of it reports.
|
|
5
|
+
*
|
|
6
|
+
* The document is immutable, so a snapshot is a node in a chain of structurally shared documents
|
|
7
|
+
* — an edit rebuilds the declaration it touched and shares every other subtree with the state
|
|
8
|
+
* before it. There is no second "current document": the chain's head at the cursor *is* the
|
|
9
|
+
* document the store returns, which is what makes a stale copy impossible.
|
|
10
|
+
*
|
|
11
|
+
* The two parameters are the document and the diagnostic a store holds. The schema store states
|
|
12
|
+
* the defaults; the dataset store states its table and the dataset compiler's diagnostics, and
|
|
13
|
+
* neither needs a second chain implementation.
|
|
14
|
+
*/
|
|
15
|
+
export interface AuthoringSnapshot<TDocument = AuthoringDocument, TDiagnostic = SchemaDiagnostic> {
|
|
16
|
+
readonly document: TDocument;
|
|
17
|
+
/** Every diagnostic a compile of this document reports, excluding the hard refusals. */
|
|
18
|
+
readonly diagnostics: readonly TDiagnostic[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One authoring state, as a host subscribes to it: the content at the cursor, and the history
|
|
22
|
+
* position that cursor states.
|
|
23
|
+
*
|
|
24
|
+
* The flags belong here rather than only on the store's methods because they are what a host
|
|
25
|
+
* renders (`disabled={!state.canUndo}`) and a subscription has to carry them: `canUndo()` read
|
|
26
|
+
* during render is a value `useSyncExternalStore` never compares, so a render attempt can observe
|
|
27
|
+
* a cursor that has since moved. One snapshot answers the document and the position together.
|
|
28
|
+
* Two cursor positions with the same content are still different states (undo to the document
|
|
29
|
+
* the store opened re-enables redo), so the flags are part of the snapshot's identity.
|
|
30
|
+
*/
|
|
31
|
+
export interface AuthoringState<TDocument = AuthoringDocument, TDiagnostic = SchemaDiagnostic> extends AuthoringSnapshot<TDocument, TDiagnostic> {
|
|
32
|
+
/** Whether a previous retained state exists behind the cursor. */
|
|
33
|
+
readonly canUndo: boolean;
|
|
34
|
+
/** Whether a retained state the cursor moved back over is still ahead of it. */
|
|
35
|
+
readonly canRedo: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** One retained state, with the coalescing identity of the command that produced it. */
|
|
38
|
+
interface HistoryNode<TDocument, TDiagnostic> {
|
|
39
|
+
readonly snapshot: AuthoringSnapshot<TDocument, TDiagnostic>;
|
|
40
|
+
/** The command's coalescing key, when consecutive commands with this key merge into one step. */
|
|
41
|
+
readonly coalesceKey: string | undefined;
|
|
42
|
+
/** What the step changed, as the host stated it; absent on the document the store opened. */
|
|
43
|
+
readonly step: HistoryStep | undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One command the store applied, as the audit trail keeps it.
|
|
47
|
+
*
|
|
48
|
+
* The store is pure: it reads no clock and invents no identity, so `actor` and `at` are exactly
|
|
49
|
+
* what the host stated when it dispatched. A host that supplies neither gets a step that records
|
|
50
|
+
* the change and says nothing about who made it, rather than an invented attribution.
|
|
51
|
+
*
|
|
52
|
+
* A coalesced run of commands is one undo step and therefore one entry: the entry states the last
|
|
53
|
+
* command of the run, because that is the command whose result the step's document holds.
|
|
54
|
+
*/
|
|
55
|
+
export interface HistoryStep {
|
|
56
|
+
/** The command's `kind`, so a reviewer can group the trail by operation. */
|
|
57
|
+
readonly kind: string;
|
|
58
|
+
/** A short sentence naming what changed, from `describeCommand`. */
|
|
59
|
+
readonly summary: string;
|
|
60
|
+
/** The identity the host attributed the change to. */
|
|
61
|
+
readonly actor?: string;
|
|
62
|
+
/** The clock reading the host supplied for the change, in the host's own spelling. */
|
|
63
|
+
readonly at?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* `next` with the objects `previous` already holds for the same diagnostic.
|
|
67
|
+
*
|
|
68
|
+
* A step must not retain a second copy of every reason the command did nothing to. A two-locale
|
|
69
|
+
* draft reports one gap per catalogue key, so 200 steps of a 500-field form held 200 copies of
|
|
70
|
+
* 1,200 diagnostics — the retention, not the documents, was the history's cost. The values are
|
|
71
|
+
* immutable, so an equal diagnostic is the same reason and the previous object states it; when
|
|
72
|
+
* nothing moved, the previous list is returned too, so the state's `diagnostics` keeps its identity
|
|
73
|
+
* as well as its objects.
|
|
74
|
+
*/
|
|
75
|
+
export declare function shareDiagnostics<TDiagnostic extends object>(previous: readonly TDiagnostic[], next: readonly TDiagnostic[]): readonly TDiagnostic[];
|
|
76
|
+
/**
|
|
77
|
+
* The snapshot chain and the cursor into it.
|
|
78
|
+
*
|
|
79
|
+
* `nodes` is oldest-first and never mutated; a commit builds a new chain that shares the retained
|
|
80
|
+
* nodes. The cursor is a position in that list, so undo and redo are cursor moves over states that
|
|
81
|
+
* already exist — there are no inverse commands, and a state cannot be reconstructed differently
|
|
82
|
+
* on the way back.
|
|
83
|
+
*/
|
|
84
|
+
export interface AuthoringHistory<TDocument = AuthoringDocument, TDiagnostic = SchemaDiagnostic> {
|
|
85
|
+
readonly nodes: readonly HistoryNode<TDocument, TDiagnostic>[];
|
|
86
|
+
readonly index: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The number of undo steps retained. One more state than this is kept, because the oldest state
|
|
90
|
+
* is the document a full undo run reaches.
|
|
91
|
+
*/
|
|
92
|
+
export declare const HISTORY_LIMIT = 200;
|
|
93
|
+
/** A fresh chain holding one state, with nothing to undo and nothing to redo. */
|
|
94
|
+
export declare function createHistory<TDocument, TDiagnostic>(snapshot: AuthoringSnapshot<TDocument, TDiagnostic>): AuthoringHistory<TDocument, TDiagnostic>;
|
|
95
|
+
/** The state at the cursor: the node's content and the position the cursor states. */
|
|
96
|
+
export declare function historyState<TDocument, TDiagnostic>(history: AuthoringHistory<TDocument, TDiagnostic>): AuthoringState<TDocument, TDiagnostic>;
|
|
97
|
+
/** Why an undo or redo moved nothing. */
|
|
98
|
+
export type HistoryRefusal = 'nothing_to_undo' | 'nothing_to_redo';
|
|
99
|
+
/** The chain after moving the cursor back one state, or `undefined` when there is none. */
|
|
100
|
+
export declare function undoHistory<TDocument, TDiagnostic>(history: AuthoringHistory<TDocument, TDiagnostic>): AuthoringHistory<TDocument, TDiagnostic> | undefined;
|
|
101
|
+
/** The chain after moving the cursor forward one state, or `undefined` when there is none. */
|
|
102
|
+
export declare function redoHistory<TDocument, TDiagnostic>(history: AuthoringHistory<TDocument, TDiagnostic>): AuthoringHistory<TDocument, TDiagnostic> | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* The chain with the cursor's coalescing run closed.
|
|
105
|
+
*
|
|
106
|
+
* Coalescing exists so typing one message is one undo step however many keystrokes arrive. It
|
|
107
|
+
* also merges two *separate* commits of the same message when nothing else was dispatched
|
|
108
|
+
* between them — two visits to one field, with a selection change in between, look identical to
|
|
109
|
+
* the store. A host that knows the author left the edit calls this to end the run, so the next
|
|
110
|
+
* dispatch appends a step instead of replacing this one. Nothing visible moves, so the cursor and
|
|
111
|
+
* the state keep their identity.
|
|
112
|
+
*/
|
|
113
|
+
export declare function sealHistory<TDocument, TDiagnostic>(history: AuthoringHistory<TDocument, TDiagnostic>): AuthoringHistory<TDocument, TDiagnostic>;
|
|
114
|
+
/** What a commit did: the new chain, whether it merged into the step before it, and whether it
|
|
115
|
+
* dropped the oldest state to stay inside the retained depth. */
|
|
116
|
+
export interface CommitResult<TDocument = unknown, TDiagnostic = unknown> {
|
|
117
|
+
readonly history: AuthoringHistory<TDocument, TDiagnostic>;
|
|
118
|
+
readonly coalesced: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Whether this commit dropped the oldest retained state.
|
|
121
|
+
*
|
|
122
|
+
* The chain keeps `HISTORY_LIMIT` undo steps and the state they undo to, so a commit past that
|
|
123
|
+
* depth is the one that forgets where the draft started. A dispatch states the fact rather than
|
|
124
|
+
* letting a full undo run land on a state the author never chose silently.
|
|
125
|
+
*/
|
|
126
|
+
readonly truncated: boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The commands that produced the state at the cursor, oldest first.
|
|
130
|
+
*
|
|
131
|
+
* The chain before the cursor is the applied history; the states ahead of it are a redo tail of
|
|
132
|
+
* commands whose result the cursor moved back over, so they are not part of what the current
|
|
133
|
+
* document is made of. The node the store opened has no command and contributes no entry, but
|
|
134
|
+
* once `HISTORY_LIMIT` truncation has dropped it, the oldest retained node carries a real step
|
|
135
|
+
* that `canUndo` still reaches, so every node up to the cursor that states a step is reported.
|
|
136
|
+
*/
|
|
137
|
+
export declare function historySteps<TDocument, TDiagnostic>(history: AuthoringHistory<TDocument, TDiagnostic>): readonly HistoryStep[];
|
|
138
|
+
/**
|
|
139
|
+
* The chain after committing `state`.
|
|
140
|
+
*
|
|
141
|
+
* A command that states no `coalesceKey`, or one that differs from the step it would merge into,
|
|
142
|
+
* appends a node and drops the redo tail. A command with a matching key replaces the current node
|
|
143
|
+
* in place, so typing one field's text is one undo step however many keystrokes arrive. The
|
|
144
|
+
* oldest nodes are dropped once the retained undo depth exceeds `HISTORY_LIMIT`, and the result
|
|
145
|
+
* says so (`truncated`).
|
|
146
|
+
*/
|
|
147
|
+
export declare function commitHistory<TDocument, TDiagnostic>(history: AuthoringHistory<TDocument, TDiagnostic>, snapshot: AuthoringSnapshot<TDocument, TDiagnostic>, coalesceKey: string | undefined, step: HistoryStep | undefined): CommitResult<TDocument, TDiagnostic>;
|
|
148
|
+
export {};
|
|
149
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/store/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB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,SAAS,GAAG,OAAO,EAAE,WAAW,GAAG,OAAO;IACtE,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC3D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,WAAW,EACjD,OAAO,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,GAChD,SAAS,WAAW,EAAE,CAMxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,EAClD,OAAO,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,EACjD,QAAQ,EAAE,iBAAiB,CAAC,SAAS,EAAE,WAAW,CAAC,EACnD,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,IAAI,EAAE,WAAW,GAAG,SAAS,GAC5B,YAAY,CAAC,SAAS,EAAE,WAAW,CAAC,CAWtC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The identity of one diagnostic's value.
|
|
3
|
+
*
|
|
4
|
+
* A diagnostic is plain data and immutable, so two diagnostics that serialise identically state
|
|
5
|
+
* the same reason. Both lists a step compares came from the same compiler path, which is what makes
|
|
6
|
+
* the serialisation a faithful identity: an unkeyed member could not be missed, and member order is
|
|
7
|
+
* the construction order of one function.
|
|
8
|
+
*
|
|
9
|
+
* The key is remembered against the object, not recomputed per dispatch. A reason the chain has
|
|
10
|
+
* held for two hundred steps is one value, and serialising it again on every step made the sharing
|
|
11
|
+
* cost grow with the history it exists to keep small.
|
|
12
|
+
*/
|
|
13
|
+
const diagnosticKeys = new WeakMap();
|
|
14
|
+
/** Freezes the plain data a diagnostic's cached identity covers, nested metadata included. */
|
|
15
|
+
function freezeDiagnosticValue(value) {
|
|
16
|
+
if (typeof value !== 'object' || value === null)
|
|
17
|
+
return;
|
|
18
|
+
// Read descriptors rather than values: freezing must not evaluate a diagnostic's accessors
|
|
19
|
+
// before the one serialisation whose cost this cache exists to bound.
|
|
20
|
+
for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(value))) {
|
|
21
|
+
if ('value' in descriptor)
|
|
22
|
+
freezeDiagnosticValue(descriptor.value);
|
|
23
|
+
}
|
|
24
|
+
Object.freeze(value);
|
|
25
|
+
}
|
|
26
|
+
function diagnosticKey(diagnostic) {
|
|
27
|
+
const held = diagnosticKeys.get(diagnostic);
|
|
28
|
+
if (held !== undefined)
|
|
29
|
+
return held;
|
|
30
|
+
// A cached key is sound only while the value it read cannot move. The store exposes these
|
|
31
|
+
// objects to JavaScript hosts, so enforce the immutability the identity optimisation relies on.
|
|
32
|
+
freezeDiagnosticValue(diagnostic);
|
|
33
|
+
const key = JSON.stringify(diagnostic);
|
|
34
|
+
diagnosticKeys.set(diagnostic, key);
|
|
35
|
+
return key;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* `next` with the objects `previous` already holds for the same diagnostic.
|
|
39
|
+
*
|
|
40
|
+
* A step must not retain a second copy of every reason the command did nothing to. A two-locale
|
|
41
|
+
* draft reports one gap per catalogue key, so 200 steps of a 500-field form held 200 copies of
|
|
42
|
+
* 1,200 diagnostics — the retention, not the documents, was the history's cost. The values are
|
|
43
|
+
* immutable, so an equal diagnostic is the same reason and the previous object states it; when
|
|
44
|
+
* nothing moved, the previous list is returned too, so the state's `diagnostics` keeps its identity
|
|
45
|
+
* as well as its objects.
|
|
46
|
+
*/
|
|
47
|
+
export function shareDiagnostics(previous, next) {
|
|
48
|
+
if (next.length === 0)
|
|
49
|
+
return previous.length === 0 ? previous : next;
|
|
50
|
+
if (previous.length === 0)
|
|
51
|
+
return next;
|
|
52
|
+
const held = new Map();
|
|
53
|
+
for (const diagnostic of previous)
|
|
54
|
+
held.set(diagnosticKey(diagnostic), diagnostic);
|
|
55
|
+
let fresh = false;
|
|
56
|
+
const shared = next.map((diagnostic) => {
|
|
57
|
+
const prior = held.get(diagnosticKey(diagnostic));
|
|
58
|
+
if (prior === undefined) {
|
|
59
|
+
fresh = true;
|
|
60
|
+
return diagnostic;
|
|
61
|
+
}
|
|
62
|
+
return prior;
|
|
63
|
+
});
|
|
64
|
+
if (fresh)
|
|
65
|
+
return shared;
|
|
66
|
+
return shared.length === previous.length &&
|
|
67
|
+
shared.every((entry, index) => entry === previous[index])
|
|
68
|
+
? previous
|
|
69
|
+
: shared;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The number of undo steps retained. One more state than this is kept, because the oldest state
|
|
73
|
+
* is the document a full undo run reaches.
|
|
74
|
+
*/
|
|
75
|
+
export const HISTORY_LIMIT = 200;
|
|
76
|
+
/** A fresh chain holding one state, with nothing to undo and nothing to redo. */
|
|
77
|
+
export function createHistory(snapshot) {
|
|
78
|
+
return { nodes: [{ snapshot, coalesceKey: undefined, step: undefined }], index: 0 };
|
|
79
|
+
}
|
|
80
|
+
/** The content at the cursor. A chain always holds at least one node. */
|
|
81
|
+
function historySnapshot(history) {
|
|
82
|
+
const node = history.nodes[history.index];
|
|
83
|
+
if (node === undefined)
|
|
84
|
+
throw new Error('the authoring history has no state at its cursor');
|
|
85
|
+
return node.snapshot;
|
|
86
|
+
}
|
|
87
|
+
/** The state at the cursor: the node's content and the position the cursor states. */
|
|
88
|
+
export function historyState(history) {
|
|
89
|
+
const snapshot = historySnapshot(history);
|
|
90
|
+
return {
|
|
91
|
+
document: snapshot.document,
|
|
92
|
+
diagnostics: snapshot.diagnostics,
|
|
93
|
+
canUndo: canUndo(history),
|
|
94
|
+
canRedo: canRedo(history),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Whether an undo step exists. Internal: the public answer is `AuthoringState.canUndo`. */
|
|
98
|
+
function canUndo(history) {
|
|
99
|
+
return history.index > 0;
|
|
100
|
+
}
|
|
101
|
+
/** Whether a redo step exists. Internal: the public answer is `AuthoringState.canRedo`. */
|
|
102
|
+
function canRedo(history) {
|
|
103
|
+
return history.index < history.nodes.length - 1;
|
|
104
|
+
}
|
|
105
|
+
/** The chain after moving the cursor back one state, or `undefined` when there is none. */
|
|
106
|
+
export function undoHistory(history) {
|
|
107
|
+
if (!canUndo(history))
|
|
108
|
+
return undefined;
|
|
109
|
+
return { nodes: history.nodes, index: history.index - 1 };
|
|
110
|
+
}
|
|
111
|
+
/** The chain after moving the cursor forward one state, or `undefined` when there is none. */
|
|
112
|
+
export function redoHistory(history) {
|
|
113
|
+
if (!canRedo(history))
|
|
114
|
+
return undefined;
|
|
115
|
+
return { nodes: history.nodes, index: history.index + 1 };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The chain with the cursor's coalescing run closed.
|
|
119
|
+
*
|
|
120
|
+
* Coalescing exists so typing one message is one undo step however many keystrokes arrive. It
|
|
121
|
+
* also merges two *separate* commits of the same message when nothing else was dispatched
|
|
122
|
+
* between them — two visits to one field, with a selection change in between, look identical to
|
|
123
|
+
* the store. A host that knows the author left the edit calls this to end the run, so the next
|
|
124
|
+
* dispatch appends a step instead of replacing this one. Nothing visible moves, so the cursor and
|
|
125
|
+
* the state keep their identity.
|
|
126
|
+
*/
|
|
127
|
+
export function sealHistory(history) {
|
|
128
|
+
const node = history.nodes[history.index];
|
|
129
|
+
if (node === undefined || node.coalesceKey === undefined)
|
|
130
|
+
return history;
|
|
131
|
+
const nodes = [...history.nodes];
|
|
132
|
+
nodes[history.index] = { ...node, coalesceKey: undefined };
|
|
133
|
+
return { nodes, index: history.index };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The commands that produced the state at the cursor, oldest first.
|
|
137
|
+
*
|
|
138
|
+
* The chain before the cursor is the applied history; the states ahead of it are a redo tail of
|
|
139
|
+
* commands whose result the cursor moved back over, so they are not part of what the current
|
|
140
|
+
* document is made of. The node the store opened has no command and contributes no entry, but
|
|
141
|
+
* once `HISTORY_LIMIT` truncation has dropped it, the oldest retained node carries a real step
|
|
142
|
+
* that `canUndo` still reaches, so every node up to the cursor that states a step is reported.
|
|
143
|
+
*/
|
|
144
|
+
export function historySteps(history) {
|
|
145
|
+
const steps = [];
|
|
146
|
+
for (const node of history.nodes.slice(0, history.index + 1)) {
|
|
147
|
+
if (node.step !== undefined)
|
|
148
|
+
steps.push(node.step);
|
|
149
|
+
}
|
|
150
|
+
return steps;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The chain after committing `state`.
|
|
154
|
+
*
|
|
155
|
+
* A command that states no `coalesceKey`, or one that differs from the step it would merge into,
|
|
156
|
+
* appends a node and drops the redo tail. A command with a matching key replaces the current node
|
|
157
|
+
* in place, so typing one field's text is one undo step however many keystrokes arrive. The
|
|
158
|
+
* oldest nodes are dropped once the retained undo depth exceeds `HISTORY_LIMIT`, and the result
|
|
159
|
+
* says so (`truncated`).
|
|
160
|
+
*/
|
|
161
|
+
export function commitHistory(history, snapshot, coalesceKey, step) {
|
|
162
|
+
const retained = history.nodes.slice(0, history.index + 1);
|
|
163
|
+
const current = retained[retained.length - 1];
|
|
164
|
+
if (coalesceKey !== undefined && current !== undefined && current.coalesceKey === coalesceKey) {
|
|
165
|
+
const nodes = [...retained.slice(0, -1), { snapshot, coalesceKey, step }];
|
|
166
|
+
return { history: { nodes, index: nodes.length - 1 }, coalesced: true, truncated: false };
|
|
167
|
+
}
|
|
168
|
+
const appended = [...retained, { snapshot, coalesceKey, step }];
|
|
169
|
+
const truncated = appended.length > HISTORY_LIMIT + 1;
|
|
170
|
+
const nodes = truncated ? appended.slice(appended.length - HISTORY_LIMIT - 1) : appended;
|
|
171
|
+
return { history: { nodes, index: nodes.length - 1 }, coalesced: false, truncated };
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/store/history.ts"],"names":[],"mappings":"AAsEA;;;;;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,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC5F,CAAC;IACD,MAAM,QAAQ,GAAG,CAAC,GAAG,QAAQ,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAChE,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,GAAG,aAAa,GAAG,CAAC,CAAC;IACtD,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACzF,OAAO,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACtF,CAAC","sourcesContent":["import type { SchemaDiagnostic } from '@azx-pbc/axiom-compiler';\nimport type { AuthoringDocument } from '../schema/document.js';\n\n/**\n * The content of one authoring state: the document and the diagnostics a compile of it reports.\n *\n * The document is immutable, so a snapshot is a node in a chain of structurally shared documents\n * — an edit rebuilds the declaration it touched and shares every other subtree with the state\n * before it. There is no second \"current document\": the chain's head at the cursor *is* the\n * document the store returns, which is what makes a stale copy impossible.\n *\n * The two parameters are the document and the diagnostic a store holds. The schema store states\n * the defaults; the dataset store states its table and the dataset compiler's diagnostics, and\n * neither needs a second chain implementation.\n */\nexport interface AuthoringSnapshot<TDocument = AuthoringDocument, TDiagnostic = SchemaDiagnostic> {\n readonly document: TDocument;\n /** Every diagnostic a compile of this document reports, excluding the hard refusals. */\n readonly diagnostics: readonly TDiagnostic[];\n}\n\n/**\n * One authoring state, as a host subscribes to it: the content at the cursor, and the history\n * position that cursor states.\n *\n * The flags belong here rather than only on the store's methods because they are what a host\n * renders (`disabled={!state.canUndo}`) and a subscription has to carry them: `canUndo()` read\n * during render is a value `useSyncExternalStore` never compares, so a render attempt can observe\n * a cursor that has since moved. One snapshot answers the document and the position together.\n * Two cursor positions with the same content are still different states (undo to the document\n * the store opened re-enables redo), so the flags are part of the snapshot's identity.\n */\nexport interface AuthoringState<TDocument = AuthoringDocument, TDiagnostic = SchemaDiagnostic>\n extends AuthoringSnapshot<TDocument, TDiagnostic> {\n /** Whether a previous retained state exists behind the cursor. */\n readonly canUndo: boolean;\n /** Whether a retained state the cursor moved back over is still ahead of it. */\n readonly canRedo: boolean;\n}\n\n/** One retained state, with the coalescing identity of the command that produced it. */\ninterface HistoryNode<TDocument, TDiagnostic> {\n readonly snapshot: AuthoringSnapshot<TDocument, TDiagnostic>;\n /** The command's coalescing key, when consecutive commands with this key merge into one step. */\n readonly coalesceKey: string | undefined;\n /** What the step changed, as the host stated it; absent on the document the store opened. */\n readonly step: HistoryStep | undefined;\n}\n\n/**\n * One command the store applied, as the audit trail keeps it.\n *\n * The store is pure: it reads no clock and invents no identity, so `actor` and `at` are exactly\n * what the host stated when it dispatched. A host that supplies neither gets a step that records\n * the change and says nothing about who made it, rather than an invented attribution.\n *\n * A coalesced run of commands is one undo step and therefore one entry: the entry states the last\n * command of the run, because that is the command whose result the step's document holds.\n */\nexport interface HistoryStep {\n /** The command's `kind`, so a reviewer can group the trail by operation. */\n readonly kind: string;\n /** A short sentence naming what changed, from `describeCommand`. */\n readonly summary: string;\n /** The identity the host attributed the change to. */\n readonly actor?: string;\n /** The clock reading the host supplied for the change, in the host's own spelling. */\n readonly at?: string;\n}\n\n/**\n * The identity of one diagnostic's value.\n *\n * A diagnostic is plain data and immutable, so two diagnostics that serialise identically state\n * the same reason. Both lists a step compares came from the same compiler path, which is what makes\n * the serialisation a faithful identity: an unkeyed member could not be missed, and member order is\n * the construction order of one function.\n *\n * The key is remembered against the object, not recomputed per dispatch. A reason the chain has\n * held for two hundred steps is one value, and serialising it again on every step made the sharing\n * cost grow with the history it exists to keep small.\n */\nconst diagnosticKeys = new WeakMap<object, string>();\n\n/** Freezes the plain data a diagnostic's cached identity covers, nested metadata included. */\nfunction freezeDiagnosticValue(value: unknown): void {\n if (typeof value !== 'object' || value === null) return;\n // Read descriptors rather than values: freezing must not evaluate a diagnostic's accessors\n // before the one serialisation whose cost this cache exists to bound.\n for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(value))) {\n if ('value' in descriptor) freezeDiagnosticValue(descriptor.value);\n }\n Object.freeze(value);\n}\n\nfunction diagnosticKey(diagnostic: object): string {\n const held = diagnosticKeys.get(diagnostic);\n if (held !== undefined) return held;\n // A cached key is sound only while the value it read cannot move. The store exposes these\n // objects to JavaScript hosts, so enforce the immutability the identity optimisation relies on.\n freezeDiagnosticValue(diagnostic);\n const key = JSON.stringify(diagnostic);\n diagnosticKeys.set(diagnostic, key);\n return key;\n}\n\n/**\n * `next` with the objects `previous` already holds for the same diagnostic.\n *\n * A step must not retain a second copy of every reason the command did nothing to. A two-locale\n * draft reports one gap per catalogue key, so 200 steps of a 500-field form held 200 copies of\n * 1,200 diagnostics — the retention, not the documents, was the history's cost. The values are\n * immutable, so an equal diagnostic is the same reason and the previous object states it; when\n * nothing moved, the previous list is returned too, so the state's `diagnostics` keeps its identity\n * as well as its objects.\n */\nexport function shareDiagnostics<TDiagnostic extends object>(\n previous: readonly TDiagnostic[],\n next: readonly TDiagnostic[],\n): readonly TDiagnostic[] {\n if (next.length === 0) return previous.length === 0 ? previous : next;\n if (previous.length === 0) return next;\n const held = new Map<string, TDiagnostic>();\n for (const diagnostic of previous) held.set(diagnosticKey(diagnostic), diagnostic);\n let fresh = false;\n const shared = next.map((diagnostic) => {\n const prior = held.get(diagnosticKey(diagnostic));\n if (prior === undefined) {\n fresh = true;\n return diagnostic;\n }\n return prior;\n });\n if (fresh) return shared;\n return shared.length === previous.length &&\n shared.every((entry, index) => entry === previous[index])\n ? previous\n : shared;\n}\n\n/**\n * The snapshot chain and the cursor into it.\n *\n * `nodes` is oldest-first and never mutated; a commit builds a new chain that shares the retained\n * nodes. The cursor is a position in that list, so undo and redo are cursor moves over states that\n * already exist — there are no inverse commands, and a state cannot be reconstructed differently\n * on the way back.\n */\nexport interface AuthoringHistory<TDocument = AuthoringDocument, TDiagnostic = SchemaDiagnostic> {\n readonly nodes: readonly HistoryNode<TDocument, TDiagnostic>[];\n readonly index: number;\n}\n\n/**\n * The number of undo steps retained. One more state than this is kept, because the oldest state\n * is the document a full undo run reaches.\n */\nexport const HISTORY_LIMIT = 200;\n\n/** A fresh chain holding one state, with nothing to undo and nothing to redo. */\nexport function createHistory<TDocument, TDiagnostic>(\n snapshot: AuthoringSnapshot<TDocument, TDiagnostic>,\n): AuthoringHistory<TDocument, TDiagnostic> {\n return { nodes: [{ snapshot, coalesceKey: undefined, step: undefined }], index: 0 };\n}\n\n/** The content at the cursor. A chain always holds at least one node. */\nfunction historySnapshot<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n): AuthoringSnapshot<TDocument, TDiagnostic> {\n const node = history.nodes[history.index];\n if (node === undefined) throw new Error('the authoring history has no state at its cursor');\n return node.snapshot;\n}\n\n/** The state at the cursor: the node's content and the position the cursor states. */\nexport function historyState<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n): AuthoringState<TDocument, TDiagnostic> {\n const snapshot = historySnapshot(history);\n return {\n document: snapshot.document,\n diagnostics: snapshot.diagnostics,\n canUndo: canUndo(history),\n canRedo: canRedo(history),\n };\n}\n\n/** Why an undo or redo moved nothing. */\nexport type HistoryRefusal = 'nothing_to_undo' | 'nothing_to_redo';\n\n/** Whether an undo step exists. Internal: the public answer is `AuthoringState.canUndo`. */\nfunction canUndo<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n): boolean {\n return history.index > 0;\n}\n\n/** Whether a redo step exists. Internal: the public answer is `AuthoringState.canRedo`. */\nfunction canRedo<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n): boolean {\n return history.index < history.nodes.length - 1;\n}\n\n/** The chain after moving the cursor back one state, or `undefined` when there is none. */\nexport function undoHistory<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n): AuthoringHistory<TDocument, TDiagnostic> | undefined {\n if (!canUndo(history)) return undefined;\n return { nodes: history.nodes, index: history.index - 1 };\n}\n\n/** The chain after moving the cursor forward one state, or `undefined` when there is none. */\nexport function redoHistory<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n): AuthoringHistory<TDocument, TDiagnostic> | undefined {\n if (!canRedo(history)) return undefined;\n return { nodes: history.nodes, index: history.index + 1 };\n}\n\n/**\n * The chain with the cursor's coalescing run closed.\n *\n * Coalescing exists so typing one message is one undo step however many keystrokes arrive. It\n * also merges two *separate* commits of the same message when nothing else was dispatched\n * between them — two visits to one field, with a selection change in between, look identical to\n * the store. A host that knows the author left the edit calls this to end the run, so the next\n * dispatch appends a step instead of replacing this one. Nothing visible moves, so the cursor and\n * the state keep their identity.\n */\nexport function sealHistory<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n): AuthoringHistory<TDocument, TDiagnostic> {\n const node = history.nodes[history.index];\n if (node === undefined || node.coalesceKey === undefined) return history;\n const nodes = [...history.nodes];\n nodes[history.index] = { ...node, coalesceKey: undefined };\n return { nodes, index: history.index };\n}\n\n/** What a commit did: the new chain, whether it merged into the step before it, and whether it\n * dropped the oldest state to stay inside the retained depth. */\nexport interface CommitResult<TDocument = unknown, TDiagnostic = unknown> {\n readonly history: AuthoringHistory<TDocument, TDiagnostic>;\n readonly coalesced: boolean;\n /**\n * Whether this commit dropped the oldest retained state.\n *\n * The chain keeps `HISTORY_LIMIT` undo steps and the state they undo to, so a commit past that\n * depth is the one that forgets where the draft started. A dispatch states the fact rather than\n * letting a full undo run land on a state the author never chose silently.\n */\n readonly truncated: boolean;\n}\n\n/**\n * The commands that produced the state at the cursor, oldest first.\n *\n * The chain before the cursor is the applied history; the states ahead of it are a redo tail of\n * commands whose result the cursor moved back over, so they are not part of what the current\n * document is made of. The node the store opened has no command and contributes no entry, but\n * once `HISTORY_LIMIT` truncation has dropped it, the oldest retained node carries a real step\n * that `canUndo` still reaches, so every node up to the cursor that states a step is reported.\n */\nexport function historySteps<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n): readonly HistoryStep[] {\n const steps: HistoryStep[] = [];\n for (const node of history.nodes.slice(0, history.index + 1)) {\n if (node.step !== undefined) steps.push(node.step);\n }\n return steps;\n}\n\n/**\n * The chain after committing `state`.\n *\n * A command that states no `coalesceKey`, or one that differs from the step it would merge into,\n * appends a node and drops the redo tail. A command with a matching key replaces the current node\n * in place, so typing one field's text is one undo step however many keystrokes arrive. The\n * oldest nodes are dropped once the retained undo depth exceeds `HISTORY_LIMIT`, and the result\n * says so (`truncated`).\n */\nexport function commitHistory<TDocument, TDiagnostic>(\n history: AuthoringHistory<TDocument, TDiagnostic>,\n snapshot: AuthoringSnapshot<TDocument, TDiagnostic>,\n coalesceKey: string | undefined,\n step: HistoryStep | undefined,\n): CommitResult<TDocument, TDiagnostic> {\n const retained = history.nodes.slice(0, history.index + 1);\n const current = retained[retained.length - 1];\n if (coalesceKey !== undefined && current !== undefined && current.coalesceKey === coalesceKey) {\n const nodes = [...retained.slice(0, -1), { snapshot, coalesceKey, step }];\n return { history: { nodes, index: nodes.length - 1 }, coalesced: true, truncated: false };\n }\n const appended = [...retained, { snapshot, coalesceKey, step }];\n const truncated = appended.length > HISTORY_LIMIT + 1;\n const nodes = truncated ? appended.slice(appended.length - HISTORY_LIMIT - 1) : appended;\n return { history: { nodes, index: nodes.length - 1 }, coalesced: false, truncated };\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Records the one compile a candidate check performs. */
|
|
2
|
+
export declare function noteCandidateCompile(): void;
|
|
3
|
+
/** The candidate checks this process has compiled since it started. */
|
|
4
|
+
export declare function candidateCompiles(): number;
|
|
5
|
+
//# sourceMappingURL=measurement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measurement.d.ts","sourceRoot":"","sources":["../../src/store/measurement.ts"],"names":[],"mappings":"AAYA,0DAA0D;AAC1D,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The candidate gate's compile count.
|
|
3
|
+
*
|
|
4
|
+
* A committed dispatch compiles its candidate at most once: a candidate whose inspection already
|
|
5
|
+
* names a reason stops before the compile stage, and one that reaches it keeps the artifact so a
|
|
6
|
+
* preview of the state the dispatch produced evaluates it rather than compiling again. The two
|
|
7
|
+
* together therefore cost one compile; the count states that as a number rather than a stopwatch,
|
|
8
|
+
* in the spelling the preview's own counter uses. It is a measurement hook, never an input: no
|
|
9
|
+
* decision reads it.
|
|
10
|
+
*/
|
|
11
|
+
let compiles = 0;
|
|
12
|
+
/** Records the one compile a candidate check performs. */
|
|
13
|
+
export function noteCandidateCompile() {
|
|
14
|
+
compiles += 1;
|
|
15
|
+
}
|
|
16
|
+
/** The candidate checks this process has compiled since it started. */
|
|
17
|
+
export function candidateCompiles() {
|
|
18
|
+
return compiles;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=measurement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measurement.js","sourceRoot":"","sources":["../../src/store/measurement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB,0DAA0D;AAC1D,MAAM,UAAU,oBAAoB;IAClC,QAAQ,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,iBAAiB;IAC/B,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * The candidate gate's compile count.\n *\n * A committed dispatch compiles its candidate at most once: a candidate whose inspection already\n * names a reason stops before the compile stage, and one that reaches it keeps the artifact so a\n * preview of the state the dispatch produced evaluates it rather than compiling again. The two\n * together therefore cost one compile; the count states that as a number rather than a stopwatch,\n * in the spelling the preview's own counter uses. It is a measurement hook, never an input: no\n * decision reads it.\n */\nlet compiles = 0;\n\n/** Records the one compile a candidate check performs. */\nexport function noteCandidateCompile(): void {\n compiles += 1;\n}\n\n/** The candidate checks this process has compiled since it started. */\nexport function candidateCompiles(): number {\n return compiles;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tells every listener that a committed state moved, then reports the listeners that threw.
|
|
3
|
+
*
|
|
4
|
+
* A commit has already landed when this runs, so stopping at the first throw would leave every
|
|
5
|
+
* later subscriber rendering a stale draft it has no way to notice: the store's whole notification
|
|
6
|
+
* surface is `subscribe`, and a host's render exception is reachable input rather than a reason to
|
|
7
|
+
* starve its siblings. The errors are not swallowed either: one listener's throw is rethrown as
|
|
8
|
+
* itself, several are one `AggregateError`, so the host can report what its own listeners did.
|
|
9
|
+
*/
|
|
10
|
+
export declare function notifyAll(listeners: Iterable<() => void>): void;
|
|
11
|
+
//# sourceMappingURL=notify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify.d.ts","sourceRoot":"","sources":["../../src/store/notify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAa/D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tells every listener that a committed state moved, then reports the listeners that threw.
|
|
3
|
+
*
|
|
4
|
+
* A commit has already landed when this runs, so stopping at the first throw would leave every
|
|
5
|
+
* later subscriber rendering a stale draft it has no way to notice: the store's whole notification
|
|
6
|
+
* surface is `subscribe`, and a host's render exception is reachable input rather than a reason to
|
|
7
|
+
* starve its siblings. The errors are not swallowed either: one listener's throw is rethrown as
|
|
8
|
+
* itself, several are one `AggregateError`, so the host can report what its own listeners did.
|
|
9
|
+
*/
|
|
10
|
+
export function notifyAll(listeners) {
|
|
11
|
+
const failures = [];
|
|
12
|
+
for (const listener of [...listeners]) {
|
|
13
|
+
try {
|
|
14
|
+
listener();
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
failures.push(error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (failures.length === 0)
|
|
21
|
+
return;
|
|
22
|
+
throw failures.length === 1
|
|
23
|
+
? failures[0]
|
|
24
|
+
: new AggregateError(failures, `${String(failures.length)} subscribers threw`);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=notify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify.js","sourceRoot":"","sources":["../../src/store/notify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,SAA+B;IACvD,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC;YACH,QAAQ,EAAE,CAAC;QACb,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAClC,MAAM,QAAQ,CAAC,MAAM,KAAK,CAAC;QACzB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACb,CAAC,CAAC,IAAI,cAAc,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACnF,CAAC","sourcesContent":["/**\n * Tells every listener that a committed state moved, then reports the listeners that threw.\n *\n * A commit has already landed when this runs, so stopping at the first throw would leave every\n * later subscriber rendering a stale draft it has no way to notice: the store's whole notification\n * surface is `subscribe`, and a host's render exception is reachable input rather than a reason to\n * starve its siblings. The errors are not swallowed either: one listener's throw is rethrown as\n * itself, several are one `AggregateError`, so the host can report what its own listeners did.\n */\nexport function notifyAll(listeners: Iterable<() => void>): void {\n const failures: unknown[] = [];\n for (const listener of [...listeners]) {\n try {\n listener();\n } catch (error) {\n failures.push(error);\n }\n }\n if (failures.length === 0) return;\n throw failures.length === 1\n ? failures[0]\n : new AggregateError(failures, `${String(failures.length)} subscribers threw`);\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AuthoringDocument } from '../schema/document.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a field's published-ness is derived from.
|
|
4
|
+
*
|
|
5
|
+
* A published document is a commitment to its declarations: a form a device already ships reads
|
|
6
|
+
* a field by its `fieldId`, and renaming or deleting one would silently change what a rendered
|
|
7
|
+
* control means. The baseline is the host's record of the version it published and the field ids
|
|
8
|
+
* that version declared — the only facts the store cannot derive from the draft in front of it.
|
|
9
|
+
*
|
|
10
|
+
* Published-ness itself is **not** stored. It is computed per dispatch as the intersection of
|
|
11
|
+
* the baseline's ids and the draft's own declarations, so there is no set that can drift from
|
|
12
|
+
* either. A field the draft no longer declares is a bug the store already refuses, not a state
|
|
13
|
+
* the store has to remember.
|
|
14
|
+
*/
|
|
15
|
+
export interface PublishedBaseline {
|
|
16
|
+
/** The `schemaVersion` the host published. */
|
|
17
|
+
readonly schemaVersion: number;
|
|
18
|
+
/** Every `fieldId` that version declared, at any nesting level. */
|
|
19
|
+
readonly fields: readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* Every `ruleId` that version declared.
|
|
22
|
+
*
|
|
23
|
+
* A host whose baseline predates this member states none, and the store then treats no rule as
|
|
24
|
+
* published: a rule id the caller did not name is one the store has no evidence about. The
|
|
25
|
+
* publish diff still refuses a revision that would drop behaviour.
|
|
26
|
+
*/
|
|
27
|
+
readonly rules?: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/** What the draft shares with the published baseline, as the store reads it per dispatch. */
|
|
30
|
+
export interface PublishedDeclarations {
|
|
31
|
+
/** The draft's fields the baseline published; deprecation does not remove one. */
|
|
32
|
+
readonly fields: ReadonlySet<string>;
|
|
33
|
+
/** The draft's rules the baseline published; a published rule id is permanent. */
|
|
34
|
+
readonly rules: ReadonlySet<string>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The fields of this draft that the baseline published.
|
|
38
|
+
*
|
|
39
|
+
* Deprecation does not remove a field from this set: a retired field is still one a device reads.
|
|
40
|
+
*/
|
|
41
|
+
export declare function publishedFields(document: AuthoringDocument, baseline: PublishedBaseline | undefined): ReadonlySet<string>;
|
|
42
|
+
/**
|
|
43
|
+
* The draft's declarations the baseline published, computed once per dispatch.
|
|
44
|
+
*
|
|
45
|
+
* One walk feeds both questions the store asks — may this field be rewritten, may this rule be
|
|
46
|
+
* removed — so a host cannot pass a field guard and fail the rule one against a baseline that
|
|
47
|
+
* moved between the two reads.
|
|
48
|
+
*/
|
|
49
|
+
export declare function publishedDeclarations(document: AuthoringDocument, baseline: PublishedBaseline | undefined): PublishedDeclarations;
|
|
50
|
+
//# sourceMappingURL=published.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"published.d.ts","sourceRoot":"","sources":["../../src/store/published.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,iBAAiB;IAChC,8CAA8C;IAC9C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,6FAA6F;AAC7F,MAAM,WAAW,qBAAqB;IACpC,kFAAkF;IAClF,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACrC,kFAAkF;IAClF,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,iBAAiB,GAAG,SAAS,GACtC,WAAW,CAAC,MAAM,CAAC,CAErB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,iBAAiB,GAAG,SAAS,GACtC,qBAAqB,CAQvB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { authoredFields } from '../schema/document.js';
|
|
2
|
+
/**
|
|
3
|
+
* The fields of this draft that the baseline published.
|
|
4
|
+
*
|
|
5
|
+
* Deprecation does not remove a field from this set: a retired field is still one a device reads.
|
|
6
|
+
*/
|
|
7
|
+
export function publishedFields(document, baseline) {
|
|
8
|
+
return publishedDeclarations(document, baseline).fields;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The draft's declarations the baseline published, computed once per dispatch.
|
|
12
|
+
*
|
|
13
|
+
* One walk feeds both questions the store asks — may this field be rewritten, may this rule be
|
|
14
|
+
* removed — so a host cannot pass a field guard and fail the rule one against a baseline that
|
|
15
|
+
* moved between the two reads.
|
|
16
|
+
*/
|
|
17
|
+
export function publishedDeclarations(document, baseline) {
|
|
18
|
+
if (baseline === undefined)
|
|
19
|
+
return { fields: new Set(), rules: new Set() };
|
|
20
|
+
const declaredFields = new Set(authoredFields(document).map((entry) => entry.field.fieldId));
|
|
21
|
+
const declaredRules = new Set((document.rules ?? []).map((rule) => rule.ruleId));
|
|
22
|
+
return {
|
|
23
|
+
fields: new Set(baseline.fields.filter((fieldId) => declaredFields.has(fieldId))),
|
|
24
|
+
rules: new Set((baseline.rules ?? []).filter((ruleId) => declaredRules.has(ruleId))),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=published.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"published.js","sourceRoot":"","sources":["../../src/store/published.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAuCvD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,QAA2B,EAC3B,QAAuC;IAEvC,OAAO,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAA2B,EAC3B,QAAuC;IAEvC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;IAC3E,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7F,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACjF,OAAO;QACL,MAAM,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;QACjF,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;KACrF,CAAC;AACJ,CAAC","sourcesContent":["import { authoredFields } from '../schema/document.js';\nimport type { AuthoringDocument } from '../schema/document.js';\n\n/**\n * What a field's published-ness is derived from.\n *\n * A published document is a commitment to its declarations: a form a device already ships reads\n * a field by its `fieldId`, and renaming or deleting one would silently change what a rendered\n * control means. The baseline is the host's record of the version it published and the field ids\n * that version declared — the only facts the store cannot derive from the draft in front of it.\n *\n * Published-ness itself is **not** stored. It is computed per dispatch as the intersection of\n * the baseline's ids and the draft's own declarations, so there is no set that can drift from\n * either. A field the draft no longer declares is a bug the store already refuses, not a state\n * the store has to remember.\n */\nexport interface PublishedBaseline {\n /** The `schemaVersion` the host published. */\n readonly schemaVersion: number;\n /** Every `fieldId` that version declared, at any nesting level. */\n readonly fields: readonly string[];\n /**\n * Every `ruleId` that version declared.\n *\n * A host whose baseline predates this member states none, and the store then treats no rule as\n * published: a rule id the caller did not name is one the store has no evidence about. The\n * publish diff still refuses a revision that would drop behaviour.\n */\n readonly rules?: readonly string[];\n}\n\n/** What the draft shares with the published baseline, as the store reads it per dispatch. */\nexport interface PublishedDeclarations {\n /** The draft's fields the baseline published; deprecation does not remove one. */\n readonly fields: ReadonlySet<string>;\n /** The draft's rules the baseline published; a published rule id is permanent. */\n readonly rules: ReadonlySet<string>;\n}\n\n/**\n * The fields of this draft that the baseline published.\n *\n * Deprecation does not remove a field from this set: a retired field is still one a device reads.\n */\nexport function publishedFields(\n document: AuthoringDocument,\n baseline: PublishedBaseline | undefined,\n): ReadonlySet<string> {\n return publishedDeclarations(document, baseline).fields;\n}\n\n/**\n * The draft's declarations the baseline published, computed once per dispatch.\n *\n * One walk feeds both questions the store asks — may this field be rewritten, may this rule be\n * removed — so a host cannot pass a field guard and fail the rule one against a baseline that\n * moved between the two reads.\n */\nexport function publishedDeclarations(\n document: AuthoringDocument,\n baseline: PublishedBaseline | undefined,\n): PublishedDeclarations {\n if (baseline === undefined) return { fields: new Set(), rules: new Set() };\n const declaredFields = new Set(authoredFields(document).map((entry) => entry.field.fieldId));\n const declaredRules = new Set((document.rules ?? []).map((rule) => rule.ruleId));\n return {\n fields: new Set(baseline.fields.filter((fieldId) => declaredFields.has(fieldId))),\n rules: new Set((baseline.rules ?? []).filter((ruleId) => declaredRules.has(ruleId))),\n };\n}\n"]}
|