/** * Final session commit at a player seam. * * A delivery element coalesces its `session-changed` dispatch, so a response the * learner finished entering can still be pending when the player is about to * discard the element. Losing it produces no event, which leaves a host with * nothing to detect. * * Reach, per seam: * * - `navigate` and `page-hidden` run while the elements are still attached, so * the event reaches a `document`-level listener. Quiz Engine listens on * `document`. * - `teardown` runs from `disconnectedCallback`, after removal. The event does * not reach `document`, and Stencil has already removed the host's own * `@Listen` handlers by then, so it does not reach an ancestor either. That * is why `` decides its own save from a session signature * rather than waiting to be told. * * Two paths, per element: * * - An element that owns its notification exposes `commitPendingSession()`, so * it dispatches its own event with its own `complete` semantics. The sweep * marks that event with `detail.sessionCommitReason`, which the element * cannot do for itself and which every guard in a `session-changed`'s way * keys on. * - An older element gets a synthesized `session-changed` built from its * `session` getter. Those elements write the session synchronously and defer * only the dispatch, so the read is never older than what the host was last * told. * * Duplicated deliberately. The canonical implementation is * `commitPendingSessions` in `@pie-players/pie-players-shared`; keeping a copy * here costs a few lines and avoids adding a dependency on the go-forward * players to a package being migrated away from. Changes belong upstream first, * and this copy is kept by hand in the same order and shape as that file - apart * from the log prefix and the inlined predicate - so the two can be diffed by * eye. Nothing enforces it. * * Its behaviour is pinned upstream and in `pie-player-components`, which runs * the same suite against the same module in the same environment; a third * byte-identical copy of that suite would pin nothing new. * * This copy can stop being a copy. `pie-player-components` carries the same * module and ships its `dist/` whole, so once a release of it includes * `dist/collection/utils/session-commit.js` this file becomes an import from * there - the deep path this package already uses for `dist/types/interface` - * and divergence stops being possible. That waits on the release either way: * `` is pinned to an exact version here, so its own commit seams * only reach this component when the pin moves. Importing ahead of the release * would pin this package to a version that does not exist, which is why the * copy ships first and the import follows the bump. */ /** * Commit hook a delivery element installs when it owns a deferred * `session-changed`. Owned by `@pie-element/shared-player-events` * (`createSessionNotifier`); the name is duplicated rather than imported so the * players carry no dependency on an element-repo package. */ export declare const SESSION_COMMIT_METHOD = "commitPendingSession"; export type SessionCommitReason = "teardown" | "navigate" | "page-hidden"; export interface CommitPendingSessionsOptions { /** Recorded on a synthesized event as `detail.sessionCommitReason`. */ reason?: SessionCommitReason; } export interface CommitPendingSessionsResult { /** Elements that committed their own pending notification. */ committed: number; /** Elements for which the player synthesized a `session-changed`. */ synthesized: number; /** Candidate elements with nothing new to commit. */ skipped: number; } /** * Whether an element session holds anything the learner put there. * * Shape-agnostic by necessity: `value` is one element's answer key, and * `response`, `selectedTokens`, `answers`, `answer`, `drawables` are others. * Anything outside the non-response key set with content in it counts, so an * element this function has never heard of is handled by default. * * This is the fallback discriminant for the session commit. The primary one is * a comparison against the session the player last observed, which needs no * schema knowledge at all; see `session-commit.ts`. */ export declare function hasLearnerResponse(session: unknown): boolean; /** * Record an element's session as one the host has been told about. * * A player calls this from its `session-changed` listener, which is what makes * the commit's discriminant "has anything happened since the host last heard" * rather than a guess about an element's session schema. */ export declare function noteSessionObserved(target: EventTarget | null | undefined): void; /** * Seed the baseline for every delivery element in a subtree. * * A player calls this once its elements hold their loaded sessions, so a * restored response the learner has not touched is never announced as a change. */ export declare function noteSessionBaseline(root: ParentNode | null | undefined): void; export declare function commitPendingSessions(root: ParentNode | null | undefined, options?: CommitPendingSessionsOptions): CommitPendingSessionsResult; export interface BindPageLifecycleCommitOptions { /** * The subtree to commit, re-evaluated on every transition: a player's * container is replaced during its lifetime. */ root: () => ParentNode | null | undefined; /** * Runs after the synchronous commit, for a player that owns a backend save. * A hidden document only performs synchronous work dependably, so a save * started here needs `keepalive`. */ onHidden?: (reason: SessionCommitReason) => void; } /** * Commit on the page going away rather than on the player being removed from it. * * `visibilitychange` to `hidden` is the primary signal: it is the last event a * mobile browser reliably delivers before freezing or discarding a page. * `pagehide` backs it up for same-document navigation and back/forward cache * entry, and for iOS Safari, which can fire it without a preceding * `visibilitychange`. Both fire on an ordinary navigation; the per-element * baseline makes the second a no-op, and input arriving between them is still * committed - which a "commit once per hidden transition" guard would drop. * `beforeunload` is not used: it is unreliable on mobile and costs the * back/forward cache. * * Returns an unbind function. Safe to call outside a browser, where it binds * nothing. */ export declare function bindPageLifecycleCommit(options: BindPageLifecycleCommitOptions): () => void;