diff --git a/README.md b/README.md index e6583a4..67b5015 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/dev/main.tsx b/dev/main.tsx index 7ba47bf..c5305c6 100644 --- a/dev/main.tsx +++ b/dev/main.tsx @@ -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"; diff --git a/package-lock.json b/package-lock.json index 4dd9218..a1935aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@doenet/assignment-viewer", - "version": "0.1.0-alpha-17", + "version": "0.1.0-alpha-19", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@doenet/assignment-viewer", - "version": "0.1.0-alpha-17", + "version": "0.1.0-alpha-19", "license": "AGPL-3.0-or-later", "dependencies": { "nanoid": "^5.1.6", diff --git a/package.json b/package.json index 336faa3..3c83dd5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Activity/Activity.tsx b/src/Activity/Activity.tsx index 83405fb..a53f1eb 100644 --- a/src/Activity/Activity.tsx +++ b/src/Activity/Activity.tsx @@ -23,6 +23,11 @@ export type ActivityCommonProps = { doenetmlVersion?: string; fetchExternalDoenetML?: (arg: string) => Promise; 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[]; doenetStates: unknown[]; diff --git a/src/Activity/SingleDocActivity.tsx b/src/Activity/SingleDocActivity.tsx index a62d33f..4e017d9 100644 --- a/src/Activity/SingleDocActivity.tsx +++ b/src/Activity/SingleDocActivity.tsx @@ -35,6 +35,7 @@ export const SingleDocActivity = memo(function SingleDocActivity({ doenetmlVersion, fetchExternalDoenetML, darkMode = "light", + addVirtualKeyboard = true, showAnswerResponseMenu = false, answerResponseCounts, state, @@ -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} diff --git a/src/Viewer/Viewer.tsx b/src/Viewer/Viewer.tsx index 82f564c..c2c4cdd 100644 --- a/src/Viewer/Viewer.tsx +++ b/src/Viewer/Viewer.tsx @@ -45,7 +45,7 @@ export function Viewer({ forceShowCorrectness = false, forceShowSolution = false, forceUnsuppressCheckwork = false, - addVirtualKeyboard: _addVirtualKeyboard = true, + addVirtualKeyboard = true, externalVirtualKeyboardProvided: _externalVirtualKeyboardProvided = false, doenetViewerUrl, doenetImagesUrl, @@ -615,6 +615,7 @@ export function Viewer({ doenetmlVersion={doenetmlVersion} fetchExternalDoenetML={fetchExternalDoenetML} darkMode={darkMode} + addVirtualKeyboard={addVirtualKeyboard} showAnswerResponseMenu={showAnswerResponseMenu} answerResponseCountsByItem={answerResponseCountsByItem} state={activityState} diff --git a/test/cypress/component/ActivityViewer.virtualKeyboard.cy.tsx b/test/cypress/component/ActivityViewer.virtualKeyboard.cy.tsx new file mode 100644 index 0000000..6f46d2f --- /dev/null +++ b/test/cypress/component/ActivityViewer.virtualKeyboard.cy.tsx @@ -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 ``, +// 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: `

`, + 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( + , + ); + + 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( + , + ); + + waitForDocuments(); + cy.get("#virtual-keyboard-tray").should("not.exist"); + cy.get(".open-keyboard-button").should("not.exist"); + }); +});