@pie-players/pie-section-player 0.3.5 → 0.3.7
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/README.md +56 -0
- package/dist/controllers/SectionController.d.ts +9 -8
- package/dist/controllers/SectionController.d.ts.map +1 -1
- package/dist/controllers/toolkit-section-contracts.d.ts +1 -1
- package/dist/controllers/toolkit-section-contracts.d.ts.map +1 -1
- package/dist/pie-section-player.js +966 -901
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -148,6 +148,62 @@ function canAdvance() {
|
|
|
148
148
|
}
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
+
If you already have a `ToolkitCoordinator` from `toolkit-ready`, prefer helper subscriptions for host logic:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
const unsubscribeItem = coordinator.subscribeItemEvents({
|
|
155
|
+
sectionId,
|
|
156
|
+
attemptId,
|
|
157
|
+
listener: (event: any) => {
|
|
158
|
+
// item-scoped stream
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const unsubscribeSection = coordinator.subscribeSectionLifecycleEvents({
|
|
163
|
+
sectionId,
|
|
164
|
+
attemptId,
|
|
165
|
+
listener: (event: any) => {
|
|
166
|
+
// section-loading-complete / section-items-complete-changed / section-error / section-navigation-change
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Use `subscribeSectionEvents(...)` only for advanced mixed filtering requirements.
|
|
172
|
+
|
|
173
|
+
### Item session management
|
|
174
|
+
|
|
175
|
+
Section session data can be managed either through persistence hooks or directly through the controller API.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
const host = document.querySelector("pie-section-player-splitpane") as any;
|
|
179
|
+
const controller = await host.waitForSectionController?.(5000);
|
|
180
|
+
|
|
181
|
+
// Read current section session snapshot.
|
|
182
|
+
const currentSession = controller?.getSession?.();
|
|
183
|
+
|
|
184
|
+
// Replace section session state (resume from backend snapshot).
|
|
185
|
+
await controller?.applySession?.({
|
|
186
|
+
currentItemIndex: 0,
|
|
187
|
+
visitedItemIdentifiers: ["q1"],
|
|
188
|
+
itemSessions: {
|
|
189
|
+
q1: {
|
|
190
|
+
itemIdentifier: "q1",
|
|
191
|
+
pieSessionId: "q1-session",
|
|
192
|
+
session: { id: "q1-session", data: [{ id: "choice", value: "a" }] }
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}, { mode: "replace" });
|
|
196
|
+
|
|
197
|
+
// Update a single item session directly.
|
|
198
|
+
await controller?.updateItemSession?.("q1", {
|
|
199
|
+
session: { id: "q1-session", data: [{ id: "choice", value: "b" }] },
|
|
200
|
+
complete: true,
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The same controller snapshot is what the persistence strategy saves/loads.
|
|
205
|
+
When a controller is reused for the same `sectionId`/`attemptId`, `updateInput()` refreshes composition input while preserving in-memory section session data.
|
|
206
|
+
|
|
151
207
|
## Exports
|
|
152
208
|
|
|
153
209
|
Published exports are intentionally minimal:
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { TestAttemptSession } from '@pie-players/pie-assessment-toolkit';
|
|
2
|
-
import {
|
|
2
|
+
import { SectionControllerHandle, SectionSessionPersistenceConfig, SectionControllerRuntimeState, SectionControllerSessionState } from './toolkit-section-contracts.js';
|
|
3
3
|
import { ItemEntity } from '@pie-players/pie-players-shared';
|
|
4
4
|
import { NavigationResult, SectionControllerChangeListener, SectionCompositionModel, SectionNavigationState, SectionViewModel, SessionChangedResult } from './types.js';
|
|
5
5
|
export declare class SectionController implements SectionControllerHandle {
|
|
6
6
|
private readonly contentService;
|
|
7
7
|
private readonly sessionService;
|
|
8
8
|
private readonly itemNavigationService;
|
|
9
|
-
private
|
|
10
|
-
private persistenceContext;
|
|
9
|
+
private sessionPersistence;
|
|
11
10
|
private state;
|
|
12
11
|
private readonly listeners;
|
|
13
12
|
private readonly trackedRenderables;
|
|
@@ -23,8 +22,7 @@ export declare class SectionController implements SectionControllerHandle {
|
|
|
23
22
|
subscribe(listener: SectionControllerChangeListener): () => void;
|
|
24
23
|
initialize(input?: unknown): Promise<void>;
|
|
25
24
|
updateInput(input?: unknown): Promise<void>;
|
|
26
|
-
|
|
27
|
-
setPersistenceContext(context: SectionControllerContext): void;
|
|
25
|
+
configureSessionPersistence(config: SectionSessionPersistenceConfig): void;
|
|
28
26
|
hydrate(): Promise<void>;
|
|
29
27
|
persist(): Promise<void>;
|
|
30
28
|
dispose(): void;
|
|
@@ -47,18 +45,21 @@ export declare class SectionController implements SectionControllerHandle {
|
|
|
47
45
|
* Use this for serializing/restoring section session state across reloads.
|
|
48
46
|
* This is intentionally compact and not a full runtime diagnostics view.
|
|
49
47
|
*/
|
|
50
|
-
|
|
48
|
+
getSession(): SectionControllerSessionState | null;
|
|
51
49
|
private getSectionItemIdentifiers;
|
|
52
50
|
/**
|
|
53
51
|
* Runtime/debugger shape scoped to the current section.
|
|
54
52
|
* Use this for widgets that need a section-scoped live snapshot (debug panels, diagnostics).
|
|
55
|
-
* Unlike
|
|
53
|
+
* Unlike getSession(), this is optimized for runtime introspection, not host persistence.
|
|
56
54
|
*/
|
|
57
55
|
getRuntimeState(): SectionControllerRuntimeState | null;
|
|
58
56
|
getCurrentItem(): ItemEntity | null;
|
|
59
57
|
getCurrentItemSession(): unknown;
|
|
60
58
|
getNavigationState(isLoading?: boolean): SectionNavigationState;
|
|
61
|
-
|
|
59
|
+
updateItemSession(itemId: string, sessionDetail: any): SessionChangedResult | null;
|
|
60
|
+
applySession(session: SectionControllerSessionState | null, options?: {
|
|
61
|
+
mode?: "replace" | "merge";
|
|
62
|
+
}): Promise<void>;
|
|
62
63
|
/**
|
|
63
64
|
* Move between items inside the current section only.
|
|
64
65
|
* Cross-section navigation belongs to the higher-level assessment player.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SectionController.d.ts","sourceRoot":"","sources":["../../src/controllers/SectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,OAAO,KAAK,EACX,
|
|
1
|
+
{"version":3,"file":"SectionController.d.ts","sourceRoot":"","sources":["../../src/controllers/SectionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,OAAO,KAAK,EACX,uBAAuB,EACvB,+BAA+B,EAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAIlE,OAAO,KAAK,EAOX,gBAAgB,EAIhB,+BAA+B,EAC/B,uBAAuB,EAIvB,sBAAsB,EAItB,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACX,6BAA6B,EAC7B,6BAA6B,EAC7B,MAAM,gCAAgC,CAAC;AAcxC,qBAAa,iBAAkB,YAAW,uBAAuB;IAGhE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA+B;IAC9D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA+B;IAC9D,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAsC;IAC5E,OAAO,CAAC,kBAAkB,CAAgD;IAC1E,OAAO,CAAC,KAAK,CAaX;IACF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8C;IACxE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAwC;IAC3E,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAqB;IAC1D,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAA8B;IAC1E,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,UAAU,CAAK;IAEvB,OAAO,CAAC,UAAU;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AAC,sBAAsB;IAY9B,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,uBAAuB;IAM/B,OAAO,CAAC,+BAA+B;IAavC,OAAO,CAAC,uBAAuB;IA0B/B,OAAO,CAAC,iCAAiC;IAmCzC,OAAO,CAAC,2BAA2B;IAmBnC,OAAO,CAAC,YAAY;CAYpB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ToolkitCoordinator, SectionControllerHandle } from '@pie-players/pie-assessment-toolkit';
|
|
2
|
-
export type { SectionControllerContext, SectionControllerEvent, SectionControllerEventType, SectionControllerHandle, SectionControllerKey,
|
|
2
|
+
export type { SectionControllerContext, SectionControllerEvent, SectionControllerEventType, SectionControllerHandle, SectionControllerKey, SectionSessionPersistenceConfig, SectionSessionPersistenceStrategy, SectionControllerRuntimeState, SectionControllerSessionState, } from '@pie-players/pie-assessment-toolkit';
|
|
3
3
|
export type CoordinatorWithSectionControllers = ToolkitCoordinator & {
|
|
4
4
|
getOrCreateSectionController(args: {
|
|
5
5
|
sectionId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolkit-section-contracts.d.ts","sourceRoot":"","sources":["../../src/controllers/toolkit-section-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,YAAY,EACX,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"toolkit-section-contracts.d.ts","sourceRoot":"","sources":["../../src/controllers/toolkit-section-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,YAAY,EACX,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,+BAA+B,EAC/B,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,GAC7B,MAAM,qCAAqC,CAAC;AAE7C,MAAM,MAAM,iCAAiC,GAAG,kBAAkB,GAAG;IACpE,4BAA4B,CAAC,IAAI,EAAE;QAClC,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,uBAAuB,EAAE,MACtB,uBAAuB,GACvB,OAAO,CAAC,uBAAuB,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACrC,wBAAwB,CAAC,IAAI,EAAE;QAC9B,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,oBAAoB,CAAC,EAAE,OAAO,CAAC;QAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB,CAAC"}
|