@doenet/doenetml-iframe 0.7.23-dev.472 → 0.7.23-dev.475
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/index.js +127 -23
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/style.css +7 -0
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import React__default, { createContext, useMemo, useCallback, useLayoutEffect, useEffect, useRef, useState, useContext, isValidElement } from "react";
|
|
3
3
|
import { MathJaxBaseContext, MathJax } from "better-react-mathjax";
|
|
4
|
-
import { createRoot } from "react-dom/client";
|
|
5
4
|
import { createPortal } from "react-dom";
|
|
5
|
+
import { createRoot } from "react-dom/client";
|
|
6
6
|
const proxyMarker = /* @__PURE__ */ Symbol("Comlink.proxy");
|
|
7
7
|
const createEndpoint = /* @__PURE__ */ Symbol("Comlink.endpoint");
|
|
8
8
|
const releaseProxy = /* @__PURE__ */ Symbol("Comlink.releaseProxy");
|
|
@@ -41880,6 +41880,13 @@ function requireClassnames() {
|
|
|
41880
41880
|
var classnamesExports = requireClassnames();
|
|
41881
41881
|
const classNames = /* @__PURE__ */ getDefaultExportFromCjs$1(classnamesExports);
|
|
41882
41882
|
const untranslated = (key, _args, fallback) => fallback ?? key;
|
|
41883
|
+
const VIRTUAL_KEYBOARD_TRAY_ID = "virtual-keyboard-tray";
|
|
41884
|
+
function getVirtualKeyboardTrayElement() {
|
|
41885
|
+
return document.getElementById(VIRTUAL_KEYBOARD_TRAY_ID);
|
|
41886
|
+
}
|
|
41887
|
+
function isInVirtualKeyboardTray(node) {
|
|
41888
|
+
return node instanceof Node && (getVirtualKeyboardTrayElement()?.contains(node) ?? false);
|
|
41889
|
+
}
|
|
41883
41890
|
const KeyboardIcon = () => /* @__PURE__ */ React__default.createElement(
|
|
41884
41891
|
"svg",
|
|
41885
41892
|
{
|
|
@@ -41897,11 +41904,12 @@ const KeyboardIcon = () => /* @__PURE__ */ React__default.createElement(
|
|
|
41897
41904
|
);
|
|
41898
41905
|
function KeyboardTray({
|
|
41899
41906
|
onClick,
|
|
41907
|
+
open,
|
|
41908
|
+
onOpenChange,
|
|
41900
41909
|
theme,
|
|
41901
41910
|
translate,
|
|
41902
41911
|
direction
|
|
41903
41912
|
}) {
|
|
41904
|
-
const [open, setOpen] = React__default.useState(false);
|
|
41905
41913
|
const t4 = translate ?? untranslated;
|
|
41906
41914
|
const openLabel = t4("keyboard-open", void 0, "Open Keyboard");
|
|
41907
41915
|
const closeLabel = t4("keyboard-close", void 0, "Close Keyboard");
|
|
@@ -41909,26 +41917,18 @@ function KeyboardTray({
|
|
|
41909
41917
|
/* @__PURE__ */ React__default.createElement(
|
|
41910
41918
|
"div",
|
|
41911
41919
|
{
|
|
41912
|
-
id:
|
|
41920
|
+
id: VIRTUAL_KEYBOARD_TRAY_ID,
|
|
41913
41921
|
"data-theme": theme,
|
|
41914
41922
|
dir: direction,
|
|
41915
41923
|
className: classNames({ open }),
|
|
41916
|
-
|
|
41917
|
-
|
|
41918
|
-
{ type: "accessed", command: "", timestamp: +/* @__PURE__ */ new Date() }
|
|
41919
|
-
]);
|
|
41920
|
-
},
|
|
41921
|
-
onClick: () => {
|
|
41922
|
-
onClick([
|
|
41923
|
-
{ type: "accessed", command: "", timestamp: +/* @__PURE__ */ new Date() }
|
|
41924
|
-
]);
|
|
41925
|
-
}
|
|
41924
|
+
onPointerDown: (e2) => e2.preventDefault(),
|
|
41925
|
+
onMouseDown: (e2) => e2.preventDefault()
|
|
41926
41926
|
},
|
|
41927
41927
|
/* @__PURE__ */ React__default.createElement(
|
|
41928
41928
|
"button",
|
|
41929
41929
|
{
|
|
41930
41930
|
className: "open-keyboard-button",
|
|
41931
|
-
onClick: () =>
|
|
41931
|
+
onClick: () => onOpenChange(!open),
|
|
41932
41932
|
title: open ? closeLabel : openLabel,
|
|
41933
41933
|
"aria-label": open ? closeLabel : openLabel
|
|
41934
41934
|
},
|
|
@@ -41938,7 +41938,7 @@ function KeyboardTray({
|
|
|
41938
41938
|
"button",
|
|
41939
41939
|
{
|
|
41940
41940
|
className: "close-keyboard-button",
|
|
41941
|
-
onClick: () =>
|
|
41941
|
+
onClick: () => onOpenChange(false),
|
|
41942
41942
|
title: closeLabel,
|
|
41943
41943
|
"aria-label": closeLabel
|
|
41944
41944
|
},
|
|
@@ -67624,6 +67624,17 @@ function flatten_array(t4, n2) {
|
|
|
67624
67624
|
for (var r2 = 0; r2 < t4.length; r2++) Array.isArray(t4[r2]) ? flatten_array(t4[r2], n2) : n2.push(t4[r2]);
|
|
67625
67625
|
return n2;
|
|
67626
67626
|
}
|
|
67627
|
+
const COARSE_POINTER_QUERY = "(pointer: coarse)";
|
|
67628
|
+
function getCoarsePointerQueryList() {
|
|
67629
|
+
const matchMedia = globalThis.matchMedia;
|
|
67630
|
+
if (typeof matchMedia !== "function") {
|
|
67631
|
+
return null;
|
|
67632
|
+
}
|
|
67633
|
+
return matchMedia(COARSE_POINTER_QUERY);
|
|
67634
|
+
}
|
|
67635
|
+
function hasCoarsePrimaryPointer() {
|
|
67636
|
+
return getCoarsePointerQueryList()?.matches ?? false;
|
|
67637
|
+
}
|
|
67627
67638
|
var base32$1 = { exports: {} };
|
|
67628
67639
|
var hasRequiredBase32;
|
|
67629
67640
|
function requireBase32() {
|
|
@@ -68213,6 +68224,10 @@ requireCssesc();
|
|
|
68213
68224
|
const globalThis$1 = Function("return this")() || {};
|
|
68214
68225
|
const virtualKeyboardState = globalThis$1?.virtualKeyboardState || {
|
|
68215
68226
|
count: 0,
|
|
68227
|
+
open: false,
|
|
68228
|
+
userClosedTray: false,
|
|
68229
|
+
openListeners: /* @__PURE__ */ new Set(),
|
|
68230
|
+
focusedMathInputSources: /* @__PURE__ */ new Set(),
|
|
68216
68231
|
keyboardDomNode: null,
|
|
68217
68232
|
keyboardReactRoot: null,
|
|
68218
68233
|
registrations: [],
|
|
@@ -68228,9 +68243,6 @@ function getRegistrationById(id2) {
|
|
|
68228
68243
|
(registration) => registration.id === id2
|
|
68229
68244
|
) ?? null;
|
|
68230
68245
|
}
|
|
68231
|
-
function getTrayElement() {
|
|
68232
|
-
return document.getElementById("virtual-keyboard-tray");
|
|
68233
|
-
}
|
|
68234
68246
|
function getActiveRegistration() {
|
|
68235
68247
|
const activeElement = document.activeElement;
|
|
68236
68248
|
for (let i2 = virtualKeyboardState.registrations.length - 1; i2 >= 0; i2 -= 1) {
|
|
@@ -68241,7 +68253,7 @@ function getActiveRegistration() {
|
|
|
68241
68253
|
return registration;
|
|
68242
68254
|
}
|
|
68243
68255
|
}
|
|
68244
|
-
if (
|
|
68256
|
+
if (isInVirtualKeyboardTray(activeElement)) {
|
|
68245
68257
|
return getRegistrationById(
|
|
68246
68258
|
virtualKeyboardState.lastActiveRegistrationId
|
|
68247
68259
|
);
|
|
@@ -68262,12 +68274,63 @@ function getTrayRegistration() {
|
|
|
68262
68274
|
const registrations = virtualKeyboardState.registrations;
|
|
68263
68275
|
return registrations[registrations.length - 1];
|
|
68264
68276
|
}
|
|
68277
|
+
function broadcastKeyboardChoice(open) {
|
|
68278
|
+
const choice = [
|
|
68279
|
+
{ type: "keyboardChoice", command: open ? "virtual" : "system" }
|
|
68280
|
+
];
|
|
68281
|
+
for (const registration of virtualKeyboardState.registrations) {
|
|
68282
|
+
registration.onClick(choice);
|
|
68283
|
+
}
|
|
68284
|
+
}
|
|
68285
|
+
function getTrayOpen() {
|
|
68286
|
+
return virtualKeyboardState.open;
|
|
68287
|
+
}
|
|
68288
|
+
function subscribeToTrayOpen(listener) {
|
|
68289
|
+
virtualKeyboardState.openListeners.add(listener);
|
|
68290
|
+
return () => {
|
|
68291
|
+
virtualKeyboardState.openListeners.delete(listener);
|
|
68292
|
+
};
|
|
68293
|
+
}
|
|
68294
|
+
function setTrayOpen(open, { byUser }) {
|
|
68295
|
+
if (byUser) {
|
|
68296
|
+
virtualKeyboardState.userClosedTray = !open;
|
|
68297
|
+
broadcastKeyboardChoice(open);
|
|
68298
|
+
}
|
|
68299
|
+
if (virtualKeyboardState.open === open) {
|
|
68300
|
+
return;
|
|
68301
|
+
}
|
|
68302
|
+
virtualKeyboardState.open = open;
|
|
68303
|
+
for (const listener of virtualKeyboardState.openListeners) {
|
|
68304
|
+
listener();
|
|
68305
|
+
}
|
|
68306
|
+
}
|
|
68307
|
+
function reportMathInputFocus(source, mathInputFocused) {
|
|
68308
|
+
if (!hasCoarsePrimaryPointer()) {
|
|
68309
|
+
return;
|
|
68310
|
+
}
|
|
68311
|
+
const focusedSources = virtualKeyboardState.focusedMathInputSources;
|
|
68312
|
+
if (mathInputFocused) {
|
|
68313
|
+
focusedSources.add(source);
|
|
68314
|
+
if (!virtualKeyboardState.userClosedTray) {
|
|
68315
|
+
setTrayOpen(true, { byUser: false });
|
|
68316
|
+
}
|
|
68317
|
+
return;
|
|
68318
|
+
}
|
|
68319
|
+
if (isInVirtualKeyboardTray(document.activeElement)) {
|
|
68320
|
+
return;
|
|
68321
|
+
}
|
|
68322
|
+
focusedSources.delete(source);
|
|
68323
|
+
if (focusedSources.size > 0) {
|
|
68324
|
+
return;
|
|
68325
|
+
}
|
|
68326
|
+
setTrayOpen(false, { byUser: false });
|
|
68327
|
+
}
|
|
68265
68328
|
function rerenderTray() {
|
|
68266
68329
|
const registration = getTrayRegistration();
|
|
68267
68330
|
const theme = registration?.theme;
|
|
68268
68331
|
const translate = registration?.translate;
|
|
68269
68332
|
const direction = registration?.direction;
|
|
68270
|
-
const trayEl =
|
|
68333
|
+
const trayEl = getVirtualKeyboardTrayElement();
|
|
68271
68334
|
if (trayEl) {
|
|
68272
68335
|
const currentTheme = trayEl.getAttribute("data-theme") ?? void 0;
|
|
68273
68336
|
const currentDirection = trayEl.getAttribute("dir") ?? void 0;
|
|
@@ -68280,17 +68343,38 @@ function rerenderTray() {
|
|
|
68280
68343
|
renderTray(theme, translate, direction)
|
|
68281
68344
|
);
|
|
68282
68345
|
}
|
|
68283
|
-
function
|
|
68284
|
-
|
|
68346
|
+
function TrayWithSharedOpenState({
|
|
68347
|
+
theme,
|
|
68348
|
+
translate,
|
|
68349
|
+
direction
|
|
68350
|
+
}) {
|
|
68351
|
+
const open = React__default.useSyncExternalStore(
|
|
68352
|
+
subscribeToTrayOpen,
|
|
68353
|
+
getTrayOpen,
|
|
68354
|
+
getTrayOpen
|
|
68355
|
+
);
|
|
68356
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
68285
68357
|
KeyboardTray,
|
|
68286
68358
|
{
|
|
68287
68359
|
theme,
|
|
68288
68360
|
translate,
|
|
68289
68361
|
direction,
|
|
68362
|
+
open,
|
|
68363
|
+
onOpenChange: (nextOpen) => setTrayOpen(nextOpen, { byUser: true }),
|
|
68290
68364
|
onClick: (e2) => {
|
|
68291
68365
|
getActiveRegistration()?.onClick(e2);
|
|
68292
68366
|
}
|
|
68293
68367
|
}
|
|
68368
|
+
);
|
|
68369
|
+
}
|
|
68370
|
+
function renderTray(theme, translate, direction) {
|
|
68371
|
+
return /* @__PURE__ */ React__default.createElement(MathJaxContext, { config: mathjaxConfig, version: 4 }, /* @__PURE__ */ React__default.createElement(
|
|
68372
|
+
TrayWithSharedOpenState,
|
|
68373
|
+
{
|
|
68374
|
+
theme,
|
|
68375
|
+
translate,
|
|
68376
|
+
direction
|
|
68377
|
+
}
|
|
68294
68378
|
));
|
|
68295
68379
|
}
|
|
68296
68380
|
function UniqueKeyboardTray({
|
|
@@ -68361,6 +68445,9 @@ function UniqueKeyboardTray({
|
|
|
68361
68445
|
);
|
|
68362
68446
|
virtualKeyboardState.keyboardDomNode = null;
|
|
68363
68447
|
}
|
|
68448
|
+
virtualKeyboardState.open = false;
|
|
68449
|
+
virtualKeyboardState.userClosedTray = false;
|
|
68450
|
+
virtualKeyboardState.focusedMathInputSources.clear();
|
|
68364
68451
|
} else {
|
|
68365
68452
|
rerenderTray();
|
|
68366
68453
|
}
|
|
@@ -68383,6 +68470,23 @@ function ExternalVirtualKeyboard({
|
|
|
68383
68470
|
theme,
|
|
68384
68471
|
ownerRef
|
|
68385
68472
|
}) {
|
|
68473
|
+
React__default.useEffect(() => {
|
|
68474
|
+
let reportedFocused = false;
|
|
68475
|
+
function listener(event) {
|
|
68476
|
+
if (event.source !== ownerRef.current?.contentWindow || event.data?.subject !== "keyboard-focus") {
|
|
68477
|
+
return;
|
|
68478
|
+
}
|
|
68479
|
+
reportedFocused = event.data.mathInputFocused;
|
|
68480
|
+
reportMathInputFocus(ownerRef, reportedFocused);
|
|
68481
|
+
}
|
|
68482
|
+
window.addEventListener("message", listener);
|
|
68483
|
+
return () => {
|
|
68484
|
+
window.removeEventListener("message", listener);
|
|
68485
|
+
if (reportedFocused) {
|
|
68486
|
+
reportMathInputFocus(ownerRef, false);
|
|
68487
|
+
}
|
|
68488
|
+
};
|
|
68489
|
+
}, [ownerRef]);
|
|
68386
68490
|
return /* @__PURE__ */ React__default.createElement(
|
|
68387
68491
|
UniqueKeyboardTray,
|
|
68388
68492
|
{
|
|
@@ -68408,7 +68512,7 @@ function ExternalVirtualKeyboard({
|
|
|
68408
68512
|
}
|
|
68409
68513
|
);
|
|
68410
68514
|
}
|
|
68411
|
-
const version = "0.7.23-dev.
|
|
68515
|
+
const version = "0.7.23-dev.475";
|
|
68412
68516
|
const latestDoenetmlVersion = version;
|
|
68413
68517
|
function subscribeToPinnedTheme() {
|
|
68414
68518
|
return () => {
|