Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ viewers still mount lazily but stay live once booted.
To cut the per-document core cost further, `useSharedCoreWorker` serves all
documents' cores from a shared worker pool instead of one dedicated ~100 MB
worker per document (default off; see `@doenet/doenetml-iframe`).

## Virtual keyboard

Each document's viewer offers the Doenet virtual keyboard for its math
inputs, and all of them share one keyboard tray along the bottom of the
page. The tray's styles come from `@doenet/doenetml-iframe`, so the page
must import them once:

```tsx
import "@doenet/doenetml-iframe/style.css";
```

Without that stylesheet the tray's keys appear unstyled at the end of the
page. Pass `addVirtualKeyboard={false}` to leave the keyboard out.
1 change: 1 addition & 0 deletions dev/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import "@doenet/doenetml-iframe/style.css";
import "./index.css";
import App from "./App";

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@doenet/assignment-viewer",
"private": false,
"description": "View assignments from questions written in DoenetML",
"version": "0.1.0-alpha-18",
"version": "0.1.0-alpha-19",
"license": "AGPL-3.0-or-later",
"homepage": "https://github.com/Doenet/assignment-viewer#readme",
"type": "module",
Expand Down
5 changes: 5 additions & 0 deletions src/Activity/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export type ActivityCommonProps = {
doenetmlVersion?: string;
fetchExternalDoenetML?: (arg: string) => Promise<string>;
darkMode?: "dark" | "light";
/**
* Whether each document's viewer offers the Doenet virtual keyboard. The
* viewers share a single keyboard tray on the page.
*/
addVirtualKeyboard?: boolean;
showAnswerResponseMenu?: boolean;
answerResponseCountsByItem?: Record<string, number>[];
doenetStates: unknown[];
Expand Down
3 changes: 2 additions & 1 deletion src/Activity/SingleDocActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const SingleDocActivity = memo(function SingleDocActivity({
doenetmlVersion,
fetchExternalDoenetML,
darkMode = "light",
addVirtualKeyboard = true,
showAnswerResponseMenu = false,
answerResponseCounts,
state,
Expand Down Expand Up @@ -136,7 +137,7 @@ export const SingleDocActivity = memo(function SingleDocActivity({
darkMode={darkMode}
showAnswerResponseMenu={showAnswerResponseMenu}
answerResponseCounts={answerResponseCounts}
addVirtualKeyboard={false}
addVirtualKeyboard={addVirtualKeyboard}
initialState={initialDoenetState}
initializeCounters={initialCounters}
mountPolicy={mountPolicy}
Expand Down
3 changes: 2 additions & 1 deletion src/Viewer/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function Viewer({
forceShowCorrectness = false,
forceShowSolution = false,
forceUnsuppressCheckwork = false,
addVirtualKeyboard: _addVirtualKeyboard = true,
addVirtualKeyboard = true,
externalVirtualKeyboardProvided: _externalVirtualKeyboardProvided = false,
doenetViewerUrl,
doenetImagesUrl,
Expand Down Expand Up @@ -615,6 +615,7 @@ export function Viewer({
doenetmlVersion={doenetmlVersion}
fetchExternalDoenetML={fetchExternalDoenetML}
darkMode={darkMode}
addVirtualKeyboard={addVirtualKeyboard}
showAnswerResponseMenu={showAnswerResponseMenu}
answerResponseCountsByItem={answerResponseCountsByItem}
state={activityState}
Expand Down
81 changes: 81 additions & 0 deletions test/cypress/component/ActivityViewer.virtualKeyboard.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from "react";
import { ActivityViewer } from "../../../src/activity-viewer";
import type { ActivitySource } from "../../../src/Activity/activityState";
import type { SingleDocSource } from "../../../src/Activity/singleDocState";
import {
STANDALONE_URL,
STANDALONE_CSS_URL,
IFRAME_READY_TIMEOUT,
} from "./helpers";

// `addVirtualKeyboard` must reach each document's embedded `<DoenetViewer>`,
// whose iframe wrapper draws the virtual keyboard tray in this page. Every
// viewer on a page shares one tray, so an activity of several documents still
// shows a single keyboard.

function mkDoc(id: string): SingleDocSource {
return {
id,
type: "singleDoc",
isDescription: false,
doenetML: `<p><mathInput name="mi" /></p>`,
version: "0.7.24",
numVariants: 1,
};
}

const SOURCE = {
type: "sequence",
id: "seq",
title: "keyboard",
shuffle: false,
items: [mkDoc("doc1"), mkDoc("doc2")],
} as ActivitySource;

function waitForDocuments() {
cy.get("iframe", { timeout: IFRAME_READY_TIMEOUT }).should(
"have.length",
2,
);
cy.get("iframe").each(($iframe) => {
cy.wrap($iframe)
.its("0.contentDocument.body", { timeout: IFRAME_READY_TIMEOUT })
.find("#mi", { timeout: IFRAME_READY_TIMEOUT })
.should("exist");
});
}

describe("ActivityViewer — virtual keyboard", () => {
it("offers one virtual keyboard for all its documents by default", () => {
cy.mount(
<ActivityViewer
source={SOURCE}
activityId="keyboard"
paginate={false}
standaloneUrl={STANDALONE_URL}
cssUrl={STANDALONE_CSS_URL}
/>,
);

waitForDocuments();
cy.get("#virtual-keyboard-tray").should("have.length", 1);
cy.get(".open-keyboard-button").should("have.length", 1);
});

it("leaves the keyboard out when addVirtualKeyboard is false", () => {
cy.mount(
<ActivityViewer
source={SOURCE}
activityId="keyboard"
paginate={false}
addVirtualKeyboard={false}
standaloneUrl={STANDALONE_URL}
cssUrl={STANDALONE_CSS_URL}
/>,
);

waitForDocuments();
cy.get("#virtual-keyboard-tray").should("not.exist");
cy.get(".open-keyboard-button").should("not.exist");
});
});
Loading