Keep exactly one part of the admin screen bright
This page follows who holds the focus among the admin windows and the page. Every observed event leaves a valid screen, gives the focus to the right holder, and keeps exactly one part bright.
The bad outcome it rules out
Two parts of the screen are bright at once, the page stays dim after a press on it, or a press on the page moves a window.
The cast
| Word | Meaning |
|---|---|
| modal | An admin window that leaves the rest of the page usable. |
| key | One window identity. The examples use a, b, and c. |
| rank | The place of a window in the stack, bottom first. Zero means the window is absent. |
| focus | Who holds the focus. Focus 0 means the page holds it. Focus 1 means the top window holds it. With no window, the page holds it. |
| dim | A part of the screen that is dimmed. The page is dim while a window holds the focus. A window is dim unless it is the top window with the focus. |
| event | One input to the pure reducer: open, raise, or close of one key, or a press on the page. |
| screen | One observed reducer output. The model gives each distinct screen a model-only id. |
The walkthrough
Step 1: Start with no window
The model starts before the first open. Blank is the row with id 0, every rank at zero, and the page holding the focus. Keys names a, b, and c. ScreenIds holds every declared screen id. DomainOK checks that row 1 is Blank, that every row id matches its tuple position, and that every screen has one target for each event.
| Value | This step |
|---|---|
screen |
0 |
safe |
TRUE |
focus |
0 |
pageDim |
0 |
screen rows |
31 |
input rows |
10 |
observed transitions |
310 |
Model rule: Init
Init == /\ screen := 0 /\ safe := TRUE
Model rule: Blank
Blank == [id |-> 0, aRank |-> 0, aDim |-> 0, bRank |-> 0, bDim |-> 0,
cRank |-> 0, cDim |-> 0, focus |-> 0, pageDim |-> 0]
Model rule: Keys
Keys == {"a", "b", "c"}
Model rule: ScreenIds
ScreenIds == RowIds(Snapshots)
Model rule: DomainOK
DomainOK ==
/\ TablesWellFormed(Snapshots, Targets, Events)
/\ Snapshots[1] = Blank
/\ \A index \in DOMAIN Snapshots :
/\ ValidScreen(Snapshots[index])
/\ DimLaw(Snapshots[index])
Production code: scripts/verify-models/modal-focus.ts#focusFacts
export const focusFacts = (
transition: typeof transitionScreen = transitionScreen,
): FocusFacts => { ... }
Source fingerprint: sha256:7c37b6ad36fd7cc9
Production code: src/ui/client/admin/modal-focus.ts#transitionScreen
export const transitionScreen = (
screen: ModalScreen,
event: ScreenEvent,
): ModalScreen => { ... }
Source fingerprint: sha256:e5d8501475901383
Step 2: Open a and take the focus
An open of a live or absent key puts that window at the top. The window takes the focus from the page. TopLaw requires the opened window to hold the top rank. FocusLaw requires focus 1 after the event. RankOf reads the new place of the key, and OpenWindows counts the open windows. TakesFocus names an open or a raise that leaves its key as a live window. Snapshot reads the source and target rows from the observed screen table.
| Value | This step |
|---|---|
before |
no window, focus 0. |
after |
aRank 1, focus 1, pageDim 1, aDim 0. |
Model rule: Transition
Transition ==
\E input \in Events :
LET result == Targets[screen + 1][input.event + 1]
IN /\ screen' := result
/\ safe' := ChecksStillPass(safe, LegalMove(screen, result, input))
Model rule: LegalMove
LegalMove(origin, result, input) ==
LET before == Snapshot(origin)
after == Snapshot(result)
IN /\ ValidScreen(after)
/\ DimLaw(after)
/\ FocusLaw(before, after, input)
/\ TopLaw(after, input)
/\ PressLaw(before, after, input)
Model rule: FocusLaw
FocusLaw(before, after, e) ==
after.focus =
IF OpenWindows(after) = 0 THEN 0
ELSE IF e.kind = "focus-page" THEN 0
ELSE IF TakesFocus(after, e) THEN 1
ELSE before.focus
Model rule: TopLaw
TopLaw(after, e) ==
TakesFocus(after, e) => RankOf(after, e.key) = OpenWindows(after)
Model rule: TakesFocus
TakesFocus(after, e) ==
e.kind \in {"open", "raise"} /\ RankOf(after, e.key) > 0
Model rule: RankOf
RankOf(s, key) ==
IF key = "a" THEN s.aRank ELSE IF key = "b" THEN s.bRank ELSE s.cRank
Model rule: OpenWindows
OpenWindows(s) == (IF s.aRank > 0 THEN 1 ELSE 0) +
(IF s.bRank > 0 THEN 1 ELSE 0) + (IF s.cRank > 0 THEN 1 ELSE 0)
Model rule: Snapshot
Snapshot(id) == RowAt(Snapshots, id)
Production code: src/ui/client/admin/modal.ts#openAdminModal
export const openAdminModal = (
settings: unknown,
content: HTMLElement,
{ canClose = ALWAYS_CLOSABLE, onClose = NOTHING_TO_DO }: ModalHooks = {},
): HTMLElement => { ... }
Source fingerprint: sha256:2b6e572abc01def1
Production code: src/ui/client/admin/modal-focus.ts#transitionScreen
export const transitionScreen = (
screen: ModalScreen,
event: ScreenEvent,
): ModalScreen => { ... }
Source fingerprint: sha256:e5d8501475901383
Step 3: Press the page and press a window
A press on the page gives the focus to the page and moves no window. PressLaw requires every rank to stay. FocusLaw requires focus 0 after the press. The page is then bright, and every window is dim. A raise of a window gives it the focus again. Dim reads the dim flag of one window. ExpectedDim and ExpectedPageDim state which parts are dim. BrightCount adds the parts that are not dim, and DimLaw requires exactly one. ValidScreen keeps the flags and the ranks valid.
| Value | This step |
|---|---|
after a press on the page |
focus 0, pageDim 0. |
windows |
Every window keeps its rank and turns dim. |
after a raise of a |
focus 1, pageDim 1, aDim 0. |
bright parts |
Exactly one, in every screen. |
Model rule: FocusLaw
FocusLaw(before, after, e) ==
after.focus =
IF OpenWindows(after) = 0 THEN 0
ELSE IF e.kind = "focus-page" THEN 0
ELSE IF TakesFocus(after, e) THEN 1
ELSE before.focus
Model rule: PressLaw
PressLaw(before, after, e) ==
e.kind = "focus-page" => \A key \in Keys : RankOf(after, key) = RankOf(before, key)
Model rule: DimLaw
DimLaw(s) ==
/\ s.pageDim = ExpectedPageDim(s)
/\ \A key \in Keys : Dim(s, key) = ExpectedDim(s, key)
/\ BrightCount(s) = 1
Model rule: ExpectedDim
ExpectedDim(s, key) ==
IF RankOf(s, key) > 0 /\ (s.focus = 0 \/ RankOf(s, key) < OpenWindows(s)) THEN 1 ELSE 0
Model rule: ExpectedPageDim
ExpectedPageDim(s) == IF OpenWindows(s) > 0 /\ s.focus = 1 THEN 1 ELSE 0
Model rule: BrightCount
BrightCount(s) ==
(1 - s.pageDim)
+ (IF RankOf(s, "a") > 0 THEN 1 - s.aDim ELSE 0)
+ (IF RankOf(s, "b") > 0 THEN 1 - s.bDim ELSE 0)
+ (IF RankOf(s, "c") > 0 THEN 1 - s.cDim ELSE 0)
Model rule: Dim
Dim(s, key) ==
IF key = "a" THEN s.aDim ELSE IF key = "b" THEN s.bDim ELSE s.cDim
Model rule: ValidScreen
ValidScreen(s) ==
/\ RanksInRange(s)
/\ \A key \in Keys :
/\ Dim(s, key) \in {0, 1}
/\ (RankOf(s, key) = 0 => Dim(s, key) = 0)
/\ \A first, second \in Keys :
(first # second /\ RankOf(s, first) = RankOf(s, second)) =>
RankOf(s, first) = 0
/\ s.focus \in {0, 1} /\ s.pageDim \in {0, 1}
/\ (OpenWindows(s) = 0 => s.focus = 0)
Production code: src/ui/client/admin/modal.ts#initAdminModalShell
export const initAdminModalShell = (): void => { ... }
Source fingerprint: sha256:c7a994a99b5730db
Production code: src/ui/client/admin/modal-focus.ts#dimmingFor
export const dimmingFor = ({ focus, windows }: ModalScreen): ModalDimming => ...
Source fingerprint: sha256:e73444992978c87c
Step 4: Close the last window
A close removes its key and keeps the focus where it was, until the last window closes. The last close gives the focus to the page, because no window can hold it. OpenWindows reads that no window is open. FocusLaw requires focus 0 for that screen, and ValidScreen requires the same for every screen with no window.
| Value | This step |
|---|---|
before |
aRank 1, focus 1. |
after |
no window, focus 0. |
Model rule: Transition
Transition ==
\E input \in Events :
LET result == Targets[screen + 1][input.event + 1]
IN /\ screen' := result
/\ safe' := ChecksStillPass(safe, LegalMove(screen, result, input))
Model rule: FocusLaw
FocusLaw(before, after, e) ==
after.focus =
IF OpenWindows(after) = 0 THEN 0
ELSE IF e.kind = "focus-page" THEN 0
ELSE IF TakesFocus(after, e) THEN 1
ELSE before.focus
Model rule: OpenWindows
OpenWindows(s) == (IF s.aRank > 0 THEN 1 ELSE 0) +
(IF s.bRank > 0 THEN 1 ELSE 0) + (IF s.cRank > 0 THEN 1 ELSE 0)
Model rule: ValidScreen
ValidScreen(s) ==
/\ RanksInRange(s)
/\ \A key \in Keys :
/\ Dim(s, key) \in {0, 1}
/\ (RankOf(s, key) = 0 => Dim(s, key) = 0)
/\ \A first, second \in Keys :
(first # second /\ RankOf(s, first) = RankOf(s, second)) =>
RankOf(s, first) = 0
/\ s.focus \in {0, 1} /\ s.pageDim \in {0, 1}
/\ (OpenWindows(s) = 0 => s.focus = 0)
Production code: src/ui/client/admin/modal.ts#closeAdminModal
export const closeAdminModal = (key: string): void => { ... }
Source fingerprint: sha256:783c8953b152ed24
Production code: src/ui/client/admin/modal-focus.ts#transitionScreen
export const transitionScreen = (
screen: ModalScreen,
event: ScreenEvent,
): ModalScreen => { ... }
Source fingerprint: sha256:e5d8501475901383
Step 5: Every selected event fits the laws
The producer runs transitionScreen at every declared screen for every selected event. The matrix stores the observed target id. LegalMove checks the stack, the dim, the focus, the top window, and the press for each edge. DomainOK checks the screen and event tables. Safety checks the current id, the retained verdict, and the domain. Next permits any transition or a pause. Safety does not prove that a press on the page eventually happens.
| Value | This step |
|---|---|
screen rows |
31 |
input rows |
10 |
observed transitions |
310 |
target |
One observed reducer screen id for each source and event. |
safe |
TRUE |
Model rule: Next
Next == Transition \/ UNCHANGED <<screen, safe>>
Model rule: Safety
Safety ==
/\ screen \in ScreenIds
/\ safe = TRUE
/\ DomainOK
Model rule: LegalMove
LegalMove(origin, result, input) ==
LET before == Snapshot(origin)
after == Snapshot(result)
IN /\ ValidScreen(after)
/\ DimLaw(after)
/\ FocusLaw(before, after, input)
/\ TopLaw(after, input)
/\ PressLaw(before, after, input)
Model rule: DomainOK
DomainOK ==
/\ TablesWellFormed(Snapshots, Targets, Events)
/\ Snapshots[1] = Blank
/\ \A index \in DOMAIN Snapshots :
/\ ValidScreen(Snapshots[index])
/\ DimLaw(Snapshots[index])
Production code: scripts/verify-models/modal-lifecycle-matrix.ts#modalTargets
export const modalTargets = (
facts: TargetFacts,
): readonly (readonly number[])[] => { ... }
Source fingerprint: sha256:5a1d312add04d70f
Production code: scripts/verify-models/modal-focus.ts#modalFocusModelData
export const modalFocusModelData = focusDataWith((facts) => facts);
Source fingerprint: sha256:86c09da3381c2f1f
The safety claim
Every current screen has a valid stack. The page or the top window holds the focus, the dim matches the focus, and exactly one part of the screen is bright. The initial screen is empty and the retained verdict is true.
The model checks two things:
- The first state satisfies the claim.
- Every allowed step from a state that satisfies the claim keeps it.
Together, these checks cover every finite run of the model.
What this model does not prove
- The examples use three keys and every order of every subset of them. They do not prove other stacks.
- The model does not move a window. The ModalLifecycle model checks the order and the position of each window.
- The model checks a pure reducer. It does not prove browser focus events, pointer delivery, CSS dimming, or rendered content.
- No fairness rule is present. Safety does not prove that a press on the page eventually happens.
How to read the model text
| Symbol | Meaning |
|---|---|
== |
This line defines a rule. It does not assign a value. |
x' |
The value of x after the step. |
/\ |
Both conditions must hold. |
\/ |
One of the conditions must hold. |
\A |
Every supplied value must satisfy the rule. |
\E |
At least one supplied value must satisfy the rule. |
\in |
The value belongs to the set. |
=> |
If the left condition holds, the right condition must hold. |
Read the model verification guide for the method and its limits.