bloom-player 2.21.0 → 2.21.1-alpha.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/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A library for displaying Bloom books in iframes or WebViews",
|
|
4
4
|
"author": "SIL Global",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "2.21.
|
|
6
|
+
"version": "2.21.1-alpha.1",
|
|
7
7
|
"packageManager": "pnpm@11.1.2",
|
|
8
8
|
"private": false,
|
|
9
9
|
"// sideeffects might need to be ['*.css'] to avoid 'shaking' our CSS, if we ever get tree shaking working": "",
|
|
@@ -39,26 +39,37 @@ let currentPage: HTMLElement | undefined;
|
|
|
39
39
|
// Our latest templates don't have their own change page buttons, just encourage the user
|
|
40
40
|
// to leave room for the player to add them.
|
|
41
41
|
let currentChangePageAction: (next: boolean) => void | undefined;
|
|
42
|
-
|
|
42
|
+
// Where each draggable was when play began, keyed by its draggable id rather than by the element
|
|
43
|
+
// itself. The id is what lets us put a COPY of the page back to its starting state as well as the
|
|
44
|
+
// page we prepared -- see restorePositions.
|
|
45
|
+
let positionsToRestore = new Map<string, { x: string; y: string }>();
|
|
43
46
|
|
|
44
47
|
// Save the current positions of all draggables (when entering Play tab, so we can restore them when leaving).
|
|
45
48
|
const savePositions = (page: HTMLElement) => {
|
|
46
|
-
positionsToRestore =
|
|
49
|
+
positionsToRestore = new Map();
|
|
47
50
|
page.querySelectorAll<HTMLElement>("[data-draggable-id]").forEach((elt) => {
|
|
48
|
-
positionsToRestore.
|
|
51
|
+
positionsToRestore.set(elt.getAttribute("data-draggable-id")!, {
|
|
49
52
|
x: elt.style.left,
|
|
50
53
|
y: elt.style.top,
|
|
51
|
-
elt,
|
|
52
54
|
});
|
|
53
55
|
});
|
|
54
56
|
};
|
|
55
57
|
// Restore the positions saved by savePositions (when leaving the Play tab, or leaving this page altogether
|
|
56
58
|
// after being in that tab or when clicking the retry button during play).
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
// Walk the page's draggables once and ask what we recorded for each, rather than searching the page
|
|
60
|
+
// once per recorded id: one pass instead of one per draggable, and no selector built out of an id.
|
|
61
|
+
// (That last is worth little on its own -- getTarget and others still interpolate the same ids, so
|
|
62
|
+
// an id needing escaping would break the activity well before it got here -- but there is no reason
|
|
63
|
+
// to add another.)
|
|
64
|
+
const restorePositions = (page: HTMLElement) => {
|
|
65
|
+
page.querySelectorAll<HTMLElement>("[data-draggable-id]").forEach((elt) => {
|
|
66
|
+
const saved = positionsToRestore.get(
|
|
67
|
+
elt.getAttribute("data-draggable-id")!,
|
|
68
|
+
);
|
|
69
|
+
if (!saved) return;
|
|
70
|
+
elt.style.left = saved.x;
|
|
71
|
+
elt.style.top = saved.y;
|
|
72
|
+
elt.classList.remove("bloom-draggedToTarget");
|
|
62
73
|
});
|
|
63
74
|
};
|
|
64
75
|
|
|
@@ -305,12 +316,27 @@ const playVideo = (e: MouseEvent) => {
|
|
|
305
316
|
// Cleans up whatever prepareActivity() did, especially when switching to another tab.
|
|
306
317
|
// May also be useful to do when switching pages in player. If not, we may want to move
|
|
307
318
|
// this out of this runtime file; but it's nice to keep it with prepareActivity.
|
|
319
|
+
//
|
|
320
|
+
// Everything here happens to the page you pass, and only to it -- including putting the draggables
|
|
321
|
+
// back where play found them. That matters because the page you pass is not always the page we
|
|
322
|
+
// prepared: Bloom desktop hands us a detached COPY, because that is how a toolbox tool takes its
|
|
323
|
+
// markup off the copy of the page being saved, while the user goes on playing. Such a copy needs
|
|
324
|
+
// the same treatment -- a book should record where the author put the draggables, not where a
|
|
325
|
+
// tester dragged them -- and the live page must be left alone.
|
|
308
326
|
export function undoPrepareActivity(page: HTMLElement) {
|
|
309
|
-
|
|
310
|
-
|
|
327
|
+
// Only when we are really ending the session, not cleaning a copy of a page still in play.
|
|
328
|
+
if (page === currentPage) {
|
|
329
|
+
stopPlayAllVideoPlayback();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
restorePositions(page);
|
|
333
|
+
|
|
311
334
|
// In case we do more editing after leaving the Play tab, we don't want to restore the same positions again
|
|
312
|
-
// if we leave the page completely.
|
|
313
|
-
|
|
335
|
+
// if we leave the page completely. Only when the session is over, though: forgetting them
|
|
336
|
+
// because someone cleaned a copy would leave the live page stuck wherever it was dragged.
|
|
337
|
+
if (page === currentPage) {
|
|
338
|
+
positionsToRestore.clear();
|
|
339
|
+
}
|
|
314
340
|
|
|
315
341
|
const changePageButtons = Array.from(
|
|
316
342
|
page.getElementsByClassName(
|
|
@@ -636,7 +662,7 @@ const showCorrect = (e: MouseEvent) => {
|
|
|
636
662
|
if (!currentPage) {
|
|
637
663
|
return; // huh?? but makes TS happy
|
|
638
664
|
}
|
|
639
|
-
restorePositions(); // any distractors return to start positions.
|
|
665
|
+
restorePositions(currentPage); // any distractors return to start positions.
|
|
640
666
|
currentPage
|
|
641
667
|
.querySelectorAll<HTMLElement>("[data-draggable-id]")
|
|
642
668
|
.forEach((elt: HTMLElement) => {
|
|
@@ -858,7 +884,7 @@ export const performTryAgain = (e: MouseEvent) => {
|
|
|
858
884
|
//currently I don't think it could be set here, but make sure.
|
|
859
885
|
classSetter(page, "drag-activity-solution", false);
|
|
860
886
|
// Restore everything to the starting positions. BL-14482.
|
|
861
|
-
restorePositions();
|
|
887
|
+
restorePositions(page);
|
|
862
888
|
// If we're still playing video, e.g. a 'wrong' video, stop it.
|
|
863
889
|
stopPlayAllVideoPlayback();
|
|
864
890
|
};
|