samagotchi 0.170.0 → 0.172.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -1
- data/bin/chi +6 -4
- data/docs/architecture.md +26 -9
- data/docs/bundles.md +4 -21
- data/docs/cli.md +81 -97
- data/docs/configuration.md +12 -14
- data/docs/context.md +5 -6
- data/docs/guardrails.md +57 -96
- data/docs/hooks.md +3 -4
- data/docs/internals/attached-context.md +6 -7
- data/docs/internals/background-tasks.md +4 -3
- data/docs/internals/block-renderers.md +2 -2
- data/docs/internals/bridge.md +34 -7
- data/docs/internals/context-telemetry.md +13 -1
- data/docs/internals/engine.md +25 -13
- data/docs/internals/inline-widgets.md +1 -1
- data/docs/internals/objectives.md +4 -6
- data/docs/internals/participants.md +340 -249
- data/docs/internals/prompt-caching.md +4 -5
- data/docs/internals/web-frontend.md +185 -35
- data/docs/internals/working-set.md +71 -5
- data/docs/memory.md +1 -1
- data/docs/plugins.md +2 -16
- data/docs/releasing.md +2 -1
- data/docs/scheduling.md +1 -1
- data/docs/sessions.md +17 -48
- data/docs/sub-agent.md +2 -2
- data/docs/system-one.md +2 -2
- data/docs/testing.md +56 -7
- data/lib/samagotchi/bridge/card_store.rb +1 -0
- data/lib/samagotchi/bridge/sse_writer.rb +1 -0
- data/lib/samagotchi/bridge/turn_accumulator.rb +8 -5
- data/lib/samagotchi/bridge.rb +64 -20
- data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
- data/lib/samagotchi/bundle_command/test_run.rb +1 -0
- data/lib/samagotchi/bundle_command/try/run.rb +1 -0
- data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
- data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
- data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
- data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
- data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
- data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
- data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +126 -67
- data/lib/samagotchi/command_intake.rb +15 -3
- data/lib/samagotchi/compat.rb +6 -1
- data/lib/samagotchi/context_candidate_choice.rb +1 -3
- data/lib/samagotchi/context_candidates.rb +3 -4
- data/lib/samagotchi/continue_offer.rb +9 -2
- data/lib/samagotchi/delivery.rb +36 -12
- data/lib/samagotchi/empty_answer_error.rb +5 -0
- data/lib/samagotchi/engine/cards.rb +3 -0
- data/lib/samagotchi/engine/context_judge.rb +5 -3
- data/lib/samagotchi/engine/events.rb +4 -0
- data/lib/samagotchi/engine/hooks.rb +3 -0
- data/lib/samagotchi/engine/messages.rb +5 -0
- data/lib/samagotchi/engine/model_settings.rb +2 -0
- data/lib/samagotchi/engine/models.rb +10 -0
- data/lib/samagotchi/engine/objectives.rb +6 -0
- data/lib/samagotchi/engine/participants.rb +18 -14
- data/lib/samagotchi/engine/plugins.rb +8 -0
- data/lib/samagotchi/engine/questions.rb +3 -0
- data/lib/samagotchi/engine/recap.rb +1 -0
- data/lib/samagotchi/engine/session.rb +4 -0
- data/lib/samagotchi/engine/side_requests.rb +9 -0
- data/lib/samagotchi/engine/steering.rb +2 -0
- data/lib/samagotchi/engine/toolkit.rb +5 -0
- data/lib/samagotchi/engine/turn_end.rb +7 -0
- data/lib/samagotchi/engine/turn_helpers.rb +8 -0
- data/lib/samagotchi/engine/verify.rb +2 -0
- data/lib/samagotchi/engine.rb +8 -3
- data/lib/samagotchi/event_fanout.rb +22 -1
- data/lib/samagotchi/grants.rb +33 -22
- data/lib/samagotchi/guardrail_wiring.rb +23 -18
- data/lib/samagotchi/guardrails/approval_use.rb +59 -0
- data/lib/samagotchi/guardrails/approvals.rb +9 -11
- data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
- data/lib/samagotchi/guardrails/gate.rb +10 -5
- data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
- data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
- data/lib/samagotchi/guardrails/review_paths.rb +2 -3
- data/lib/samagotchi/guardrails.rb +1 -1
- data/lib/samagotchi/image_store.rb +51 -12
- data/lib/samagotchi/kernel_loop.rb +7 -1
- data/lib/samagotchi/llm/stray_tool_call.rb +7 -4
- data/lib/samagotchi/llm_context_stale.rb +4 -1
- data/lib/samagotchi/llm_context_strategy.rb +2 -0
- data/lib/samagotchi/objectives.rb +1 -4
- data/lib/samagotchi/objectives_audit.rb +1 -1
- data/lib/samagotchi/objectives_track.rb +1 -1
- data/lib/samagotchi/owner_prompt.rb +3 -6
- data/lib/samagotchi/parent_report.rb +1 -0
- data/lib/samagotchi/participant_messages.rb +48 -4
- data/lib/samagotchi/participant_revise.rb +61 -0
- data/lib/samagotchi/participant_turn_mode.rb +50 -0
- data/lib/samagotchi/participant_uploads.rb +98 -0
- data/lib/samagotchi/participants.rb +21 -12
- data/lib/samagotchi/participants_watch.rb +2 -2
- data/lib/samagotchi/plugin/api.rb +2 -2
- data/lib/samagotchi/plugin/attached_context.rb +1 -1
- data/lib/samagotchi/plugin/context.rb +0 -4
- data/lib/samagotchi/plugin/sessions.rb +1 -25
- data/lib/samagotchi/reply_wait/poll.rb +5 -1
- data/lib/samagotchi/revise_anchor.rb +9 -0
- data/lib/samagotchi/run_options.rb +2 -3
- data/lib/samagotchi/send_command.rb +15 -10
- data/lib/samagotchi/session.rb +0 -3
- data/lib/samagotchi/session_access/contract.rb +1 -10
- data/lib/samagotchi/session_access/local.rb +10 -23
- data/lib/samagotchi/session_access/remote.rb +9 -20
- data/lib/samagotchi/session_access.rb +12 -16
- data/lib/samagotchi/session_chain.rb +4 -6
- data/lib/samagotchi/session_commands.rb +6 -3
- data/lib/samagotchi/session_continue.rb +1 -2
- data/lib/samagotchi/session_inbox.rb +20 -12
- data/lib/samagotchi/session_manager/delivery.rb +32 -5
- data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
- data/lib/samagotchi/session_manager/listing.rb +5 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/session_manager/worker_command.rb +9 -0
- data/lib/samagotchi/session_participants.rb +12 -8
- data/lib/samagotchi/session_review.rb +5 -7
- data/lib/samagotchi/session_stores.rb +3 -1
- data/lib/samagotchi/share_command.rb +10 -12
- data/lib/samagotchi/share_terms.rb +41 -0
- data/lib/samagotchi/steer.rb +8 -14
- data/lib/samagotchi/system_prompt.rb +16 -25
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
- data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
- data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
- data/lib/samagotchi/terminal_ui.rb +1 -2
- data/lib/samagotchi/testing/sessions.rb +2 -10
- data/lib/samagotchi/tool_runner.rb +42 -9
- data/lib/samagotchi/toolkit.rb +4 -22
- data/lib/samagotchi/toolkit_suggest.rb +3 -3
- data/lib/samagotchi/tools/deferred_tools.rb +1 -0
- data/lib/samagotchi/tools/execute.rb +11 -45
- data/lib/samagotchi/tools/leftovers.rb +122 -0
- data/lib/samagotchi/tools/memory.rb +88 -25
- data/lib/samagotchi/tools/task_get.rb +1 -0
- data/lib/samagotchi/tools/task_list.rb +3 -2
- data/lib/samagotchi/tools/task_record.rb +6 -4
- data/lib/samagotchi/tools/task_runtime.rb +199 -20
- data/lib/samagotchi/tools/task_wait.rb +4 -3
- data/lib/samagotchi/turn_anchors.rb +0 -3
- data/lib/samagotchi/turn_context.rb +1 -1
- data/lib/samagotchi/turn_origin.rb +1 -1
- data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
- data/lib/samagotchi/turn_stages/objectives.rb +2 -2
- data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
- data/lib/samagotchi/turn_stages/verify_anchors.rb +13 -1
- data/lib/samagotchi/update_hint.rb +3 -1
- data/lib/samagotchi/verify_anchor.rb +6 -0
- data/lib/samagotchi/verify_fresh.rb +1 -1
- data/lib/samagotchi/verify_fresh_origin.rb +13 -11
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +45 -82
- data/lib/samagotchi/web/participant_access.rb +139 -40
- data/lib/samagotchi/web/participant_images.rb +185 -0
- data/lib/samagotchi/web/participant_review.rb +22 -142
- data/lib/samagotchi/web/participant_show.rb +241 -0
- data/lib/samagotchi/web/participant_stream_filter.rb +25 -2
- data/lib/samagotchi/web/participant_view.rb +334 -27
- data/lib/samagotchi/web/participants_admin.rb +21 -40
- data/lib/samagotchi/web/public/annotate_bar.css +1 -2
- data/lib/samagotchi/web/public/annotate_bar.js +1 -2
- data/lib/samagotchi/web/public/app.js +126 -132
- data/lib/samagotchi/web/public/block_host.js +7 -4
- data/lib/samagotchi/web/public/bubbles.js +9 -1
- data/lib/samagotchi/web/public/cards_offscreen.js +69 -0
- data/lib/samagotchi/web/public/chip_popover.js +5 -4
- data/lib/samagotchi/web/public/claim_link.js +4 -4
- data/lib/samagotchi/web/public/composer.css +4 -6
- data/lib/samagotchi/web/public/composer_mode.js +11 -6
- data/lib/samagotchi/web/public/composer_mount.js +4 -4
- data/lib/samagotchi/web/public/ctx.js +12 -3
- data/lib/samagotchi/web/public/data.js +2 -10
- data/lib/samagotchi/web/public/delivery_line.js +49 -63
- data/lib/samagotchi/web/public/history_shape.js +5 -1
- data/lib/samagotchi/web/public/images.js +7 -1
- data/lib/samagotchi/web/public/index.html +50 -34
- data/lib/samagotchi/web/public/info_bar_model.js +2 -1
- data/lib/samagotchi/web/public/live_turn.js +1 -1
- data/lib/samagotchi/web/public/markdown_place.js +5 -4
- data/lib/samagotchi/web/public/owner_claim.js +5 -5
- data/lib/samagotchi/web/public/owner_verify.js +0 -2
- data/lib/samagotchi/web/public/participant_bar.js +107 -0
- data/lib/samagotchi/web/public/participant_main.js +289 -0
- data/lib/samagotchi/web/public/participant_model.js +5 -292
- data/lib/samagotchi/web/public/participant_names.js +17 -8
- data/lib/samagotchi/web/public/participant_revise.js +66 -0
- data/lib/samagotchi/web/public/participants_panel.js +32 -74
- data/lib/samagotchi/web/public/question_cards.js +14 -3
- data/lib/samagotchi/web/public/refs.js +53 -36
- data/lib/samagotchi/web/public/reload_check.js +70 -14
- data/lib/samagotchi/web/public/revise_stack.js +21 -10
- data/lib/samagotchi/web/public/send_turn.js +28 -29
- data/lib/samagotchi/web/public/session_actions.js +4 -45
- data/lib/samagotchi/web/public/session_fields.js +1 -2
- data/lib/samagotchi/web/public/session_state.js +12 -7
- data/lib/samagotchi/web/public/session_sync.js +9 -2
- data/lib/samagotchi/web/public/session_view.js +14 -5
- data/lib/samagotchi/web/public/settings_panel.js +4 -18
- data/lib/samagotchi/web/public/stage_answer.js +56 -0
- data/lib/samagotchi/web/public/stage_asking.js +7 -5
- data/lib/samagotchi/web/public/stage_cloud.js +93 -0
- data/lib/samagotchi/web/public/stage_dom.js +100 -0
- data/lib/samagotchi/web/public/stage_handoff.js +154 -0
- data/lib/samagotchi/web/public/stage_owner_wait.js +35 -0
- data/lib/samagotchi/web/public/stage_pager.js +59 -0
- data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
- data/lib/samagotchi/web/public/stage_view.js +103 -410
- data/lib/samagotchi/web/public/stage_waiting.js +74 -6
- data/lib/samagotchi/web/public/start_page.js +12 -33
- data/lib/samagotchi/web/public/start_settings.js +24 -78
- data/lib/samagotchi/web/public/start_toolkit.js +6 -10
- data/lib/samagotchi/web/public/storage.js +22 -0
- data/lib/samagotchi/web/public/stream_handlers.js +3 -10
- data/lib/samagotchi/web/public/tokens.css +1 -1
- data/lib/samagotchi/web/public/turn_block.js +2 -5
- data/lib/samagotchi/web/public/turn_events.js +30 -12
- data/lib/samagotchi/web/public/turn_html.js +9 -2
- data/lib/samagotchi/web/public/turn_pieces.js +3 -4
- data/lib/samagotchi/web/public/turn_range.js +1 -2
- data/lib/samagotchi/web/public/verify_target.js +2 -4
- data/lib/samagotchi/web/public/viewer.js +59 -0
- data/lib/samagotchi/web/public/viewer_self.js +59 -0
- data/lib/samagotchi/web/public/working_set.js +11 -5
- data/lib/samagotchi/web/public/working_set_view.js +53 -8
- data/lib/samagotchi/web/public/ws_cards.js +89 -0
- data/lib/samagotchi/web/public/ws_peek.js +106 -0
- data/lib/samagotchi/web/public/ws_preview.css +126 -0
- data/lib/samagotchi/web/public/ws_reader.js +319 -0
- data/lib/samagotchi/web/public/ws_timeline.js +200 -0
- data/lib/samagotchi/web/public/ws_way_in.js +25 -0
- data/lib/samagotchi/web/qr.rb +1 -1
- data/lib/samagotchi/web/session_control.rb +42 -15
- data/lib/samagotchi/web/session_create.rb +6 -72
- data/lib/samagotchi/web/session_show.rb +75 -28
- data/lib/samagotchi/web/session_summary.rb +1 -4
- data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
- data/lib/samagotchi/web/viewer.rb +70 -0
- data/lib/samagotchi/web/working_set_routes.rb +132 -0
- data/lib/samagotchi/worker.rb +35 -28
- data/lib/samagotchi/worker_inbound.rb +4 -3
- data/lib/samagotchi/worker_link.rb +17 -0
- data/lib/samagotchi/working_set.rb +322 -11
- metadata +32 -13
- data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
- data/lib/samagotchi/participant_mode.rb +0 -86
- data/lib/samagotchi/review_apply.rb +0 -131
- data/lib/samagotchi/review_command.rb +0 -123
- data/lib/samagotchi/review_start.rb +0 -196
- data/lib/samagotchi/web/public/participant.html +0 -218
- data/lib/samagotchi/web/public/participant.js +0 -719
- data/lib/samagotchi/web/public/participant_annotate.js +0 -76
- data/lib/samagotchi/web/public/review_apply.js +0 -34
- data/lib/samagotchi/web/public/review_history.js +0 -72
- data/lib/samagotchi/web/public/review_start.js +0 -55
- data/lib/samagotchi/web/public/tools_overview.js +0 -42
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// The stage's answer reading (stage_view.js): the answer read from its top
|
|
2
|
+
// at the end, an answered card's line kept in sight, and the prompt's first
|
|
3
|
+
// words. Its own module: new exports go in new modules (web-frontend.md).
|
|
4
|
+
// No state of its own: nothing to reset at emptySlots.
|
|
5
|
+
|
|
6
|
+
// The answer reads from its top: at the end it is scrolled to unless this
|
|
7
|
+
// much of it (about three lines) shows already.
|
|
8
|
+
const ANSWER_SEEN = 72;
|
|
9
|
+
// A short answer cut by less than this at its foot isn't scrolled to.
|
|
10
|
+
const ANSWER_CUT = 12;
|
|
11
|
+
// An answered card's one line.
|
|
12
|
+
const ANSWERED_LINE = 40;
|
|
13
|
+
// That line brought back sits this far under the scroller's edge.
|
|
14
|
+
const ANSWERED_GAP = 8;
|
|
15
|
+
|
|
16
|
+
// +stage+, +scroller+ and the +answer+, +extras+ and +tail+ slots
|
|
17
|
+
// (stage_dom.js); +frame+() the stage's frame (stage_frame.js); +promptEl+()
|
|
18
|
+
// the turn's prompt bubble, or null.
|
|
19
|
+
export function createStageAnswer({ stage, scroller, answer, extras, tail, frame, promptEl }) {
|
|
20
|
+
// The answer reads from its top (no tail pin in the stage): scrolled to
|
|
21
|
+
// (eased, once the stage has grown for it) when its top is out of sight
|
|
22
|
+
// or only its first line shows.
|
|
23
|
+
function showAnswerTop() {
|
|
24
|
+
frame().afterGrowth(() => {
|
|
25
|
+
if (!answer.firstChild || answer.hidden || stage.hidden) return;
|
|
26
|
+
const top = answer.offsetTop;
|
|
27
|
+
const seen = scroller.scrollTop + scroller.clientHeight - top;
|
|
28
|
+
if (top < scroller.scrollTop || seen < Math.min(answer.offsetHeight - ANSWER_CUT, ANSWER_SEEN)) frame().easeStage(Math.max(0, top - 8));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// A card stopped waiting and its slot has its cap and own scroll again: the
|
|
33
|
+
// slot's end shows (the answered card's line). The stage's scroll stays, so
|
|
34
|
+
// nothing moves at the tap (the frame holds, and the blank goes at the next
|
|
35
|
+
// step), unless the reader had scrolled down the tall card past its line:
|
|
36
|
+
// then the line comes back, to the view's top and no further.
|
|
37
|
+
function settleAnsweredCard() {
|
|
38
|
+
const slot = tail.firstChild ? tail : extras;
|
|
39
|
+
if (!slot.firstChild) return;
|
|
40
|
+
slot.scrollTop = slot.scrollHeight;
|
|
41
|
+
const end = slot.offsetTop + slot.offsetHeight;
|
|
42
|
+
// Strictly below: offsetTop/offsetHeight are rounded, so a scroll exactly
|
|
43
|
+
// at the line's edge can leave it a fraction of a pixel above the view.
|
|
44
|
+
if (scroller.scrollTop < end - ANSWERED_LINE) return;
|
|
45
|
+
scroller.scrollTop = Math.max(0, Math.min(slot.lastElementChild.offsetTop, end - ANSWERED_LINE) - ANSWERED_GAP);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The prompt's first words (the working set's session tags say whose
|
|
49
|
+
// turn a step was).
|
|
50
|
+
function promptWords() {
|
|
51
|
+
const text = (promptEl()?.querySelector(".user-message")?.textContent || "").replace(/\s+/g, " ").trim();
|
|
52
|
+
return text.length > 60 ? `${text.slice(0, 59)}…` : text;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { showAnswerTop, settleAnsweredCard, promptWords };
|
|
56
|
+
}
|
|
@@ -43,10 +43,12 @@ export function createStageAsking({
|
|
|
43
43
|
// A ref's "show in turn" opened a collapsed stage (not kept).
|
|
44
44
|
let revealed = false;
|
|
45
45
|
// The docked card's fold is +waiting+'s (fold, trackFold): the waiting
|
|
46
|
-
// card the user folded, by its key
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
46
|
+
// card the user folded, by its key — kept for this tab (stage_waiting.js,
|
|
47
|
+
// chi_asking_fold:<session>), so a reload or a resync mid-turn folds that
|
|
48
|
+
// card again. For that card only: the next one arrives open, and when the
|
|
49
|
+
// docked card goes the stage is as the choice and +revealed+ say. One more
|
|
50
|
+
// card waiting since the fold (an approval, a relayed or hook question)
|
|
51
|
+
// drops it, so the stage opens on it.
|
|
50
52
|
|
|
51
53
|
// ── the docked card ──────────────────────────────────────────────────────
|
|
52
54
|
|
|
@@ -137,7 +139,7 @@ export function createStageAsking({
|
|
|
137
139
|
if (!isOpened()) return;
|
|
138
140
|
for (const el of [...extras.children]) {
|
|
139
141
|
if (waitsInStage(el)) continue;
|
|
140
|
-
// Out of the stage it waits behind nothing (
|
|
142
|
+
// Out of the stage it waits behind nothing (stage_pager.js drawDocked).
|
|
141
143
|
el.classList.remove("ts-behind");
|
|
142
144
|
const key = waitingKey(el);
|
|
143
145
|
if (opener.has(key)) opener.settle(key, el);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// The stage's cloud (stage_view.js): the turn block's steps opened above
|
|
2
|
+
// the chip, newest first while the turn runs. The chip's toggle and its
|
|
3
|
+
// ticks, the headline's peek at the live step's reasoning, and a ref's "show
|
|
4
|
+
// in turn" (refs.js ref:reveal) open it. Its own module: new exports go in
|
|
5
|
+
// new modules (web-frontend.md).
|
|
6
|
+
|
|
7
|
+
// +stage+, +cloud+, +cloudBody+, +chip+, +headline+: stage_dom.js's nodes;
|
|
8
|
+
// +view+: the turn block (turn_block.js); +opener+: the turn opened in the
|
|
9
|
+
// history (stage_opened.js); +frame+(): the stage's frame (stage_frame.js);
|
|
10
|
+
// +isOpened+(): the turn is opened in the history; +isCollapsed+(),
|
|
11
|
+
// +setCollapsed+(on), +reveal+(): the stage's fold (stage_asking.js);
|
|
12
|
+
// +isHolding+(): the stage holds a turn; +isFolding+(), +finishFold+(): a
|
|
13
|
+
// turn sliding away (stage_view.js handOff).
|
|
14
|
+
export function createStageCloud({
|
|
15
|
+
stage, cloud, cloudBody, chip, headline, view, opener, frame, isOpened, isCollapsed, setCollapsed, reveal,
|
|
16
|
+
isHolding, isFolding, finishFold,
|
|
17
|
+
}) {
|
|
18
|
+
let open = false;
|
|
19
|
+
|
|
20
|
+
function setCloud(value) {
|
|
21
|
+
open = value;
|
|
22
|
+
cloudBody.hidden = !value || cloud.hidden;
|
|
23
|
+
// Closed by hand: its room isn't held (the stage shrinks back to what
|
|
24
|
+
// shows).
|
|
25
|
+
if (!value) frame().forgetContent();
|
|
26
|
+
cloud.classList.toggle("open", value);
|
|
27
|
+
stage.classList.toggle("cloud-open", value);
|
|
28
|
+
chip.setAttribute("aria-expanded", String(value));
|
|
29
|
+
frame().fitCap();
|
|
30
|
+
// The steps open right above the chip: in sight (the answer and the
|
|
31
|
+
// cards above them scroll up), once the stage has grown for them.
|
|
32
|
+
if (value) frame().afterGrowth(() => frame().reveal(cloudBody));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Open the cloud at step +i+ (a hand toggle, as a click on its row), its
|
|
36
|
+
// reasoning too with +thinking+.
|
|
37
|
+
function openStep(i, { thinking = false } = {}) {
|
|
38
|
+
const step = view.step(i);
|
|
39
|
+
if (!step) return;
|
|
40
|
+
// An opened turn's step is in the history: shown there.
|
|
41
|
+
if (isOpened()) {
|
|
42
|
+
if (!step.el.open) step.summary.click();
|
|
43
|
+
opener.reveal(step.el);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (isCollapsed()) setCollapsed(false);
|
|
47
|
+
setCloud(true);
|
|
48
|
+
if (!step.el.open) step.summary.click();
|
|
49
|
+
const wrap = step.thinkingWrap;
|
|
50
|
+
if (thinking && wrap && !wrap.open) wrap.querySelector(":scope > summary")?.click();
|
|
51
|
+
requestAnimationFrame(() => step.el.scrollIntoView({ block: "nearest" }));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function peek() {
|
|
55
|
+
const { turn } = view.current();
|
|
56
|
+
if (turn?.gens.length) openStep(turn.gens.length - 1, { thinking: true });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
chip.addEventListener("click", (e) => {
|
|
60
|
+
const tick = e.target.closest(".ts-tick");
|
|
61
|
+
if (tick) openStep(Number(tick.dataset.step));
|
|
62
|
+
else setCloud(!open);
|
|
63
|
+
});
|
|
64
|
+
headline.addEventListener("click", peek);
|
|
65
|
+
// A ref's "show in turn" (refs.js) names a row in the cloud: open the
|
|
66
|
+
// stage and the cloud to it, as a hand toggle would.
|
|
67
|
+
// A collapsed stage opens for this turn only: the kept choice
|
|
68
|
+
// (chi_stage_collapsed) is left alone and comes back at the release.
|
|
69
|
+
// The row's scroll into view (refs.js) waits for the stage's growth.
|
|
70
|
+
// A row of a turn sliding away is no longer the stage's: it goes into the
|
|
71
|
+
// history first (finishFold), and refs.js finds it there.
|
|
72
|
+
stage.addEventListener("ref:reveal", (e) => {
|
|
73
|
+
if (!cloudBody.contains(e.target)) return;
|
|
74
|
+
if (isFolding()) return finishFold();
|
|
75
|
+
if (!isHolding()) return;
|
|
76
|
+
if (isCollapsed()) reveal();
|
|
77
|
+
setCloud(true);
|
|
78
|
+
if (e.detail) e.detail.until = new Promise((resolve) => frame().afterGrowth(resolve));
|
|
79
|
+
});
|
|
80
|
+
headline.addEventListener("keydown", (e) => {
|
|
81
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
peek();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// The turn left the stage: the cloud closes.
|
|
88
|
+
function reset() {
|
|
89
|
+
setCloud(false);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { setCloud, isOpen: () => open, reset };
|
|
93
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// The stage's nodes (stage_view.js): the dock made a clear column (the
|
|
2
|
+
// stage's card, then the composer's: its rows moved into .dock-card, which
|
|
3
|
+
// wears the glass and the focus ring) and every slot of the stage, built
|
|
4
|
+
// once. Plain nodes, no behaviour: the listeners and the drawing are the
|
|
5
|
+
// stage's modules'. Its own module: new exports go in new modules
|
|
6
|
+
// (web-frontend.md).
|
|
7
|
+
import { node } from "./stage_slots.js";
|
|
8
|
+
|
|
9
|
+
// +dockEl+: the page's dock. Returns the nodes by name.
|
|
10
|
+
export function createStageDom(dockEl) {
|
|
11
|
+
document.body.classList.add("stage-view");
|
|
12
|
+
const card = node("div", "dock-card composer-card");
|
|
13
|
+
card.append(...dockEl.children);
|
|
14
|
+
dockEl.appendChild(card);
|
|
15
|
+
const stage = node("section", "turn-stage");
|
|
16
|
+
stage.id = "turnStage";
|
|
17
|
+
stage.hidden = true;
|
|
18
|
+
stage.setAttribute("aria-label", "Running turn");
|
|
19
|
+
dockEl.prepend(stage);
|
|
20
|
+
|
|
21
|
+
const status = node("div", "ts-status", stage);
|
|
22
|
+
const mark = node("span", "ts-mark", status);
|
|
23
|
+
const phaseEl = node("span", "ts-phase", status);
|
|
24
|
+
// Two cards docked: one at a time, "‹ 1 of 2 ›" (stage_pager.js).
|
|
25
|
+
const pager = node("span", "ts-pager", status);
|
|
26
|
+
pager.hidden = true;
|
|
27
|
+
const pagePrev = node("button", "ts-page", pager);
|
|
28
|
+
pagePrev.type = "button";
|
|
29
|
+
pagePrev.textContent = "‹";
|
|
30
|
+
pagePrev.setAttribute("aria-label", "The card before");
|
|
31
|
+
const pageLabel = node("span", "ts-page-label", pager);
|
|
32
|
+
const pageNext = node("button", "ts-page", pager);
|
|
33
|
+
pageNext.type = "button";
|
|
34
|
+
pageNext.textContent = "›";
|
|
35
|
+
pageNext.setAttribute("aria-label", "The next card");
|
|
36
|
+
const stepEl = node("span", "ts-step", status);
|
|
37
|
+
const timingSlot = node("span", "ts-timing", status);
|
|
38
|
+
const miniTool = node("span", "ts-mini", status);
|
|
39
|
+
const defer = node("span", "ts-defer", status);
|
|
40
|
+
defer.textContent = "moves up when you leave";
|
|
41
|
+
// Stop turn, at the row's right edge beside the fold: while the turn
|
|
42
|
+
// hasn't ended (refresh), in a collapsed stage too (the row stays).
|
|
43
|
+
const cancel = node("button", "ts-cancel", status);
|
|
44
|
+
cancel.type = "button";
|
|
45
|
+
cancel.title = "Cancel the running turn, whoever sent it";
|
|
46
|
+
cancel.textContent = "Stop turn";
|
|
47
|
+
cancel.hidden = true;
|
|
48
|
+
const fold = node("button", "ts-fold", status);
|
|
49
|
+
fold.type = "button";
|
|
50
|
+
|
|
51
|
+
const scroller = node("div", "ts-scroll", stage);
|
|
52
|
+
const promptSlot = node("div", "ts-prompt", scroller);
|
|
53
|
+
promptSlot.title = "Show the whole prompt";
|
|
54
|
+
const live = node("div", "ts-live", scroller);
|
|
55
|
+
const headline = node("div", "ts-headline", live);
|
|
56
|
+
headline.tabIndex = 0;
|
|
57
|
+
headline.setAttribute("role", "button");
|
|
58
|
+
headline.title = "Show this step's reasoning";
|
|
59
|
+
// A participant's turn waiting for the owner: one line under the headline,
|
|
60
|
+
// no card (stage_owner_wait.js).
|
|
61
|
+
const ownerWaitLine = node("div", "ts-owner-wait", live);
|
|
62
|
+
const now = node("div", "ts-now", live);
|
|
63
|
+
const trail = node("div", "ts-trail", live);
|
|
64
|
+
// (The working set's rail joins the live slots after the trail:
|
|
65
|
+
// working_set_rail.js.)
|
|
66
|
+
const extras = node("div", "ts-extras", scroller);
|
|
67
|
+
// While check-in's card is docked: the live step's text, streamed under
|
|
68
|
+
// the card (the steps are in the history then). The answer's own slot
|
|
69
|
+
// takes it over at the turn's end (placeAnswer, in one task).
|
|
70
|
+
const asksText = node("div", "ts-asks-text", scroller);
|
|
71
|
+
asksText.hidden = true;
|
|
72
|
+
const answer = node("div", "ts-answer", scroller);
|
|
73
|
+
const tail = node("div", "ts-tail", scroller);
|
|
74
|
+
// The cloud's steps, the scroller's last slot, right above the chip.
|
|
75
|
+
const cloudBody = node("div", "ts-cloud-body", scroller);
|
|
76
|
+
cloudBody.hidden = true;
|
|
77
|
+
// A 1 px mark at the tallest content's end (absolute: out of the flow),
|
|
78
|
+
// so the scroll extent never drops while the turn runs: content that
|
|
79
|
+
// shrinks never lowers a scrolled reader's scrollTop (the browser would
|
|
80
|
+
// clamp it, moving everything in sight), even in the layout before
|
|
81
|
+
// fitFrame runs.
|
|
82
|
+
const holdEl = node("div", "ts-hold", scroller);
|
|
83
|
+
holdEl.setAttribute("aria-hidden", "true");
|
|
84
|
+
// The footer: the chip, pinned to the stage's bottom edge as the status
|
|
85
|
+
// row is to its top.
|
|
86
|
+
const cloud = node("div", "ts-foot", stage);
|
|
87
|
+
const chip = node("button", "ts-chip", cloud);
|
|
88
|
+
chip.type = "button";
|
|
89
|
+
const chipLabel = node("span", "ts-chip-label", chip);
|
|
90
|
+
const ticks = node("span", "ts-ticks", chip);
|
|
91
|
+
// Below the turn's card: the lines queued for after it (placeKind
|
|
92
|
+
// "queued"), each to run as a turn of its own; they hand off last.
|
|
93
|
+
const queuedSlot = node("div", "ts-queued", stage);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
stage, status, mark, phaseEl, pager, pagePrev, pageLabel, pageNext, stepEl, timingSlot, miniTool, cancel, fold,
|
|
97
|
+
scroller, promptSlot, live, headline, ownerWaitLine, now, trail, extras, asksText, answer, tail, cloudBody, holdEl,
|
|
98
|
+
cloud, chip, chipLabel, ticks, queuedSlot,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// The stage's hand-off (stage_view.js): an ended turn's pieces go into the
|
|
2
|
+
// history's end in the turn block's order, the stage sliding away under the
|
|
3
|
+
// composer meanwhile (the fold). Its own module: new exports go in new
|
|
4
|
+
// modules (web-frontend.md). Its state (the turn sliding away) outlives
|
|
5
|
+
// emptySlots on purpose: the fold runs after the turn's release, and
|
|
6
|
+
// finishFold clears the stage; reset() (the view's reset) drops it.
|
|
7
|
+
import { openAfterEnd } from "./block_open.js";
|
|
8
|
+
import { handOffOrder } from "./stage_model.js";
|
|
9
|
+
import { reducedMotion } from "./stage_frame.js";
|
|
10
|
+
import { easeScrollTo } from "./scroll.js";
|
|
11
|
+
import { moveToHistoryEnd } from "./history_end.js";
|
|
12
|
+
import { turnElements } from "./turn_range.js";
|
|
13
|
+
|
|
14
|
+
// How long the stage slides away (dock_reserve.js eases the history's
|
|
15
|
+
// bottom reserve as long).
|
|
16
|
+
export const FOLD_MS = 420;
|
|
17
|
+
// What opens a turn in the history: its prompt (data-turn-id), else a
|
|
18
|
+
// wake's or a reminder's note or /continue no's line (data-opening-id).
|
|
19
|
+
// reload_check.js reads it too.
|
|
20
|
+
export const OPENING = "[data-turn-id], [data-opening-id]";
|
|
21
|
+
|
|
22
|
+
// +stage+ and the slots the pieces leave (stage_dom.js: +promptSlot+,
|
|
23
|
+
// +extras+, +answer+, +timingSlot+, +tail+, +queuedSlot+); +historyEl+ and
|
|
24
|
+
// +historyNearBottom+(): the history and its follow check; +view+: the turn
|
|
25
|
+
// block (turn_block.js); +opener+: the turn opened in the history
|
|
26
|
+
// (stage_opened.js); +waiting+: the waiting cards (stage_waiting.js);
|
|
27
|
+
// +workingSet+: the page's working set or null; +isHolding+(), +ended+()
|
|
28
|
+
// (the end's kind, null: running), +isOpened+(), +promptEl+(): the stage's
|
|
29
|
+
// turn; +blockPlace+(el), +promptWords+(), +isCollapsed+(): the stage's
|
|
30
|
+
// reads; +releaseTurn+(), +clearStage+(): its lifecycle; +onHandedOff+:
|
|
31
|
+
// createStageView's.
|
|
32
|
+
export function createStageHandoff({
|
|
33
|
+
stage, promptSlot, extras, answer, timingSlot, tail, queuedSlot, historyEl, historyNearBottom, view, opener, waiting,
|
|
34
|
+
workingSet, isHolding, ended, isOpened, promptEl, blockPlace, promptWords, isCollapsed, releaseTurn, clearStage,
|
|
35
|
+
onHandedOff,
|
|
36
|
+
}) {
|
|
37
|
+
let folding = null; // { pieces, block, endKind, wasAtEnd, animate, immediate, opened, prompt } while it slides
|
|
38
|
+
let foldTimer = null;
|
|
39
|
+
|
|
40
|
+
// A fold cut short (the stage shows again): the slide's class goes.
|
|
41
|
+
function cancelFold() {
|
|
42
|
+
clearTimeout(foldTimer);
|
|
43
|
+
foldTimer = null;
|
|
44
|
+
stage.classList.remove("leaving");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The hand-off: everything the stage holds goes into the history's end in
|
|
48
|
+
// the turn block's order (prompt, block (chronological; its outline open,
|
|
49
|
+
// else collapsed), extras, answer, timing line, then the end line and
|
|
50
|
+
// what came after the end). The turn is released at once; the stage
|
|
51
|
+
// slides away under the composer still drawn (a transform: nothing on the
|
|
52
|
+
// page moves; app.js eases the history's bottom reserve meanwhile), then
|
|
53
|
+
// the pieces arrive in the history and it follows a reader who was at its
|
|
54
|
+
// end. Not with +immediate+ (another turn takes the stage at once), a
|
|
55
|
+
// reduced motion, a hidden page or a collapsed stage: all at once.
|
|
56
|
+
function handOff({ immediate = false } = {}) {
|
|
57
|
+
if (folding && immediate) finishFold();
|
|
58
|
+
if (!isHolding() || !ended()) return;
|
|
59
|
+
const { blockEl } = view.current();
|
|
60
|
+
view.chronological();
|
|
61
|
+
const place = blockPlace(blockEl);
|
|
62
|
+
// A finished turn's block draws as a reload draws it.
|
|
63
|
+
if (blockEl) delete blockEl.dataset.openedTurn;
|
|
64
|
+
// The block moves with the pieces from the cloud; an opened turn's is
|
|
65
|
+
// in the history already.
|
|
66
|
+
const block = place === "cloud" ? blockEl : null;
|
|
67
|
+
// The turn's set joins the page's turns (a plain one's too: the turns
|
|
68
|
+
// keep their places); its footprint takes the block's summary line,
|
|
69
|
+
// wherever the block is.
|
|
70
|
+
const footprint = workingSet ? workingSet.handOff(view.current().turn, promptWords()) : null;
|
|
71
|
+
if ((place === "cloud" || place === "history") && footprint) blockEl.querySelector(":scope > summary > .tw-sum")?.prepend(footprint);
|
|
72
|
+
const opened = isOpened();
|
|
73
|
+
const prompt = promptEl();
|
|
74
|
+
const pieces = handOffOrder({
|
|
75
|
+
// The prompt still in its slot (an opened turn's is in the history).
|
|
76
|
+
prompt: !opened && prompt?.parentNode === promptSlot ? prompt : null,
|
|
77
|
+
block,
|
|
78
|
+
extras: [...extras.children].map((el) => { el.classList.remove("ts-behind"); return el; }),
|
|
79
|
+
answer: [...answer.children],
|
|
80
|
+
timing: timingSlot.firstElementChild,
|
|
81
|
+
kept: [...tail.children],
|
|
82
|
+
queued: [...queuedSlot.children],
|
|
83
|
+
});
|
|
84
|
+
const animate = !immediate && !reducedMotion() && !document.hidden && !isCollapsed();
|
|
85
|
+
folding = { pieces, block: blockEl, endKind: ended(), wasAtEnd: historyNearBottom(), animate, immediate, opened, prompt };
|
|
86
|
+
releaseTurn();
|
|
87
|
+
if (!animate) return finishFold();
|
|
88
|
+
stage.classList.add("leaving");
|
|
89
|
+
foldTimer = setTimeout(finishFold, FOLD_MS);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The fold's end (or a cut-short fold): the original pieces (their ref
|
|
93
|
+
// bindings, selection and late updates with them) move into the history.
|
|
94
|
+
function finishFold() {
|
|
95
|
+
const fold = folding;
|
|
96
|
+
if (!fold) return;
|
|
97
|
+
folding = null;
|
|
98
|
+
// The stage held it open; here it takes its place in the history:
|
|
99
|
+
// closed, unless the turn was cut short with an outline (block_open.js).
|
|
100
|
+
if (fold.block) fold.block.open = openAfterEnd(fold.endKind, fold.block.classList.contains("outline"));
|
|
101
|
+
// A piece removed while it slid (the old continue card the step-limit
|
|
102
|
+
// question replaces) stays gone.
|
|
103
|
+
fold.pieces = fold.pieces.filter((el) => el.isConnected);
|
|
104
|
+
moveToHistoryEnd(historyEl, fold.pieces, { animate: fold.animate });
|
|
105
|
+
// An opened turn's reasons go in the pieces' task (after them: the
|
|
106
|
+
// history is as tall as it gets, room to keep the reader's rows in
|
|
107
|
+
// place): each answered card's clamp says it now, as the turn reloads.
|
|
108
|
+
opener.end();
|
|
109
|
+
// The asking card's fold is this turn's: with the turn handed off, there
|
|
110
|
+
// is nothing for a reload to bring back.
|
|
111
|
+
waiting.clearFold();
|
|
112
|
+
clearStage();
|
|
113
|
+
if (fold.wasAtEnd) easeScrollTo(historyEl, () => historyEl.scrollHeight - historyEl.clientHeight, { reduce: !fold.animate || reducedMotion() });
|
|
114
|
+
// The turn's pieces are in the history now (the opt-in reload check,
|
|
115
|
+
// reload_check.js), the whole turn from its opening: an opened turn's
|
|
116
|
+
// earlier pieces went before, and a wake's or a reminder's turn has no
|
|
117
|
+
// prompt (its note opens it); +immediate+: another turn took the stage.
|
|
118
|
+
onHandedOff?.({ pieces: wholeTurn(fold), immediate: fold.immediate });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// A handed-off turn from its opening: its prompt, else the wake's note
|
|
122
|
+
// (data-opening-id) right before its first piece; the pieces as they are
|
|
123
|
+
// when the first is its opening, or nothing opens it.
|
|
124
|
+
function wholeTurn(fold) {
|
|
125
|
+
const first = fold.pieces[0];
|
|
126
|
+
if (first?.matches?.(OPENING) && !fold.opened) return fold.pieces;
|
|
127
|
+
let opening = fold.prompt?.isConnected && fold.prompt.parentElement === historyEl ? fold.prompt : null;
|
|
128
|
+
for (let el = (fold.block || first)?.previousElementSibling; !opening && el; el = el.previousElementSibling) {
|
|
129
|
+
if (el.matches("[data-turn-id]")) break;
|
|
130
|
+
if (el.matches("[data-opening-id]")) opening = el;
|
|
131
|
+
}
|
|
132
|
+
if (!opening) return fold.pieces;
|
|
133
|
+
// Its rows, notes too (a note that reached the history mid-turn is the turn's).
|
|
134
|
+
return [opening, ...turnElements(opening, { container: historyEl, boundary: null })];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
handOff,
|
|
139
|
+
finishFold,
|
|
140
|
+
cancelFold,
|
|
141
|
+
// A turn still sliding away gets into the history first.
|
|
142
|
+
settle() {
|
|
143
|
+
if (folding) finishFold();
|
|
144
|
+
},
|
|
145
|
+
isFolding: () => !!folding,
|
|
146
|
+
// Another session opens, or this one renders again: a turn still
|
|
147
|
+
// sliding away is dropped, never moved into whatever history shows now.
|
|
148
|
+
reset() {
|
|
149
|
+
folding = null;
|
|
150
|
+
clearTimeout(foldTimer);
|
|
151
|
+
foldTimer = null;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The stage's look while a participant's view of the running turn waits for
|
|
2
|
+
// the owner (the participant main page, scene 3): the status row says
|
|
3
|
+
// "waiting for the owner" and one line under the live slots names what
|
|
4
|
+
// kind of thing they are asked (an approval, a question, a continue
|
|
5
|
+
// offer), never its content; no card. chi web sends the kind alone
|
|
6
|
+
// (ParticipantView.waiting_kind: question_requested / continue_offered's
|
|
7
|
+
// `kind`, the show's current_turn and viewer.waiting_for_owner).
|
|
8
|
+
// stage_view.js draws it at each refresh from its +ownerWait+ hook; the
|
|
9
|
+
// owner's page passes none (its cards are the waiting look).
|
|
10
|
+
|
|
11
|
+
export const OWNER_WAIT_STATUS = "waiting for the owner";
|
|
12
|
+
|
|
13
|
+
// The line per kind; a kind the page doesn't know reads as a question.
|
|
14
|
+
export const OWNER_WAIT_TEXT = Object.freeze({
|
|
15
|
+
approval: "chi wants to run a command that needs the owner's approval. The turn continues when they answer.",
|
|
16
|
+
question: "chi asked the owner a question. The turn continues when they answer.",
|
|
17
|
+
continue: "chi asks the owner whether to go on. The turn continues when they answer.",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const ownerWaitText = (kind) => OWNER_WAIT_TEXT[kind] || OWNER_WAIT_TEXT.question;
|
|
21
|
+
|
|
22
|
+
// +stage+ the stage's root, +line+ the line's node (stage_view.js makes it
|
|
23
|
+
// after the live slots), +phaseEl+ the status row's phase.
|
|
24
|
+
// @return draw(kind): kind null (not waiting) puts the stage back
|
|
25
|
+
export function createOwnerWait({ stage, line, phaseEl }) {
|
|
26
|
+
line.hidden = true;
|
|
27
|
+
return function draw(kind) {
|
|
28
|
+
stage.classList.toggle("owner-wait", !!kind);
|
|
29
|
+
line.hidden = !kind;
|
|
30
|
+
if (!kind) return;
|
|
31
|
+
phaseEl.textContent = OWNER_WAIT_STATUS;
|
|
32
|
+
const text = ownerWaitText(kind);
|
|
33
|
+
if (line.textContent !== text) line.textContent = text;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The stage's pager (stage_view.js): one docked card at a time, the others
|
|
2
|
+
// wait behind it (.ts-behind), and "‹ 1 of 2 ›" in the status row says where
|
|
3
|
+
// the shown one is (stage_waiting.js shown, page). Its own module: new
|
|
4
|
+
// exports go in new modules (web-frontend.md).
|
|
5
|
+
import { waitingKey } from "./stage_waiting.js";
|
|
6
|
+
|
|
7
|
+
// +card+'s first control takes the focus (its summary is out of the tab
|
|
8
|
+
// order while it waits), else the card.
|
|
9
|
+
function focusIn(card) {
|
|
10
|
+
const control = card.querySelector('input:not([type="hidden"]), textarea, select, button:not([disabled]), a[href]');
|
|
11
|
+
if (control) control.focus();
|
|
12
|
+
else {
|
|
13
|
+
if (!card.hasAttribute("tabindex")) card.tabIndex = -1;
|
|
14
|
+
card.focus();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// +pager+, +pagePrev+, +pageLabel+, +pageNext+, +extras+: stage_dom.js's
|
|
19
|
+
// nodes; +waiting+: the stage's waiting cards (stage_waiting.js); +cardOf+(key)
|
|
20
|
+
// and +askingCard+(): stage_asking.js's; +refresh+(): the stage's redraw;
|
|
21
|
+
// +frame+(): the stage's frame (stage_frame.js).
|
|
22
|
+
export function createStagePager({ pager, pagePrev, pageLabel, pageNext, extras, waiting, cardOf, askingCard, refresh, frame }) {
|
|
23
|
+
// +shownCard+ (null: none docked) in front, the others behind it.
|
|
24
|
+
function drawDocked(shownCard) {
|
|
25
|
+
const keys = waiting.docked();
|
|
26
|
+
for (const key of keys) cardOf(key)?.classList.toggle("ts-behind", !!shownCard && cardOf(key) !== shownCard);
|
|
27
|
+
for (const el of extras.querySelectorAll(":scope > .ts-behind")) if (!keys.includes(waitingKey(el))) el.classList.remove("ts-behind");
|
|
28
|
+
// Focus in a card that went behind (a new card came in front of it):
|
|
29
|
+
// to the card that shows now.
|
|
30
|
+
const focused = document.activeElement;
|
|
31
|
+
if (shownCard && focused && [...extras.querySelectorAll(":scope > .ts-behind")].some((el) => el.contains(focused))) focusIn(shownCard);
|
|
32
|
+
const at = shownCard ? keys.indexOf(waitingKey(shownCard)) : -1;
|
|
33
|
+
pager.hidden = keys.length < 2 || at < 0;
|
|
34
|
+
if (pager.hidden) return;
|
|
35
|
+
const label = `${at + 1} of ${keys.length}`;
|
|
36
|
+
if (pageLabel.textContent !== label) pageLabel.textContent = label;
|
|
37
|
+
pagePrev.disabled = at === 0;
|
|
38
|
+
pageNext.disabled = at === keys.length - 1;
|
|
39
|
+
// A pager button the page just disabled keeps no focus: the other one has it.
|
|
40
|
+
if (document.activeElement === pagePrev && pagePrev.disabled) pageNext.focus();
|
|
41
|
+
else if (document.activeElement === pageNext && pageNext.disabled) pagePrev.focus();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const [button, by] of [[pagePrev, -1], [pageNext, 1]]) {
|
|
45
|
+
button.addEventListener("click", (e) => {
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
waiting.page(by);
|
|
48
|
+
refresh();
|
|
49
|
+
const shown = askingCard();
|
|
50
|
+
if (shown) frame().afterGrowth(() => frame().reveal(shown.parentElement));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function reset() {
|
|
55
|
+
pager.hidden = true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return { drawDocked, reset };
|
|
59
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// The quiet signal's clocks (stage_view.js; stage_stall.js draws the
|
|
2
|
+
// signal): the turn's last event, since when the stream isn't live, the
|
|
3
|
+
// grace after the page shows again. Its own module: new exports go in new
|
|
4
|
+
// modules, and an existing module's factory keeps its signature
|
|
5
|
+
// (web-frontend.md).
|
|
6
|
+
import { GRACE_MS, stallState } from "./stage_stall.js";
|
|
7
|
+
|
|
8
|
+
// +stall+: the drawer (stage_stall.js createStageStall). Its inputs
|
|
9
|
+
// (stage_view.js's): +clock+() the page's time, +streamLive+() the
|
|
10
|
+
// session's stream is open, +timingNote+() what the turn waits on
|
|
11
|
+
// (live_timing.js note), +serverGen+() a joiner's generation; +held+() the
|
|
12
|
+
// turn the stage holds (null: none), +ended+() it has ended, +pending+() a
|
|
13
|
+
// card blocks it.
|
|
14
|
+
export function createStageQuietClock({
|
|
15
|
+
stall, clock = () => Date.now(), streamLive = () => true, timingNote = () => "", serverGen = () => null,
|
|
16
|
+
held = () => null, ended = () => false, pending = () => false,
|
|
17
|
+
}) {
|
|
18
|
+
let lastEventAt = 0;
|
|
19
|
+
let downSince = null; // null: the stream is live
|
|
20
|
+
let graceUntil = 0;
|
|
21
|
+
|
|
22
|
+
// At +nowMs+ (the tick's, a refresh's): what the held turn's silence says.
|
|
23
|
+
function tick(nowMs, blocked = pending()) {
|
|
24
|
+
const turn = held();
|
|
25
|
+
if (!turn) return;
|
|
26
|
+
if (streamLive()) downSince = null;
|
|
27
|
+
else downSince ??= nowMs;
|
|
28
|
+
stall.draw(stallState({
|
|
29
|
+
turn, lastEventAt, nowMs, blocked, note: timingNote() || "", ended: ended(), graceUntil, serverGen: serverGen(),
|
|
30
|
+
streamDownMs: downSince === null ? null : nowMs - downSince,
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A turn event arrived (a replay's too), or a turn started: the silence
|
|
35
|
+
// starts over, and a stall shown clears at once.
|
|
36
|
+
function alive() {
|
|
37
|
+
lastEventAt = clock();
|
|
38
|
+
if (stall.level()) tick(lastEventAt);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
document.addEventListener("visibilitychange", () => {
|
|
42
|
+
if (!document.hidden) graceUntil = clock() + GRACE_MS;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// The turn left the stage: the signal goes, the stream's clock too.
|
|
46
|
+
function reset() {
|
|
47
|
+
stall.reset();
|
|
48
|
+
downSince = null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return { tick, alive, reset };
|
|
52
|
+
}
|