@doenet/doenetml-iframe 0.7.0-beta1 → 0.7.0-beta10

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.d.ts CHANGED
@@ -87,7 +87,7 @@ export declare type DoenetViewerIframeProps = DoenetViewerProps & {
87
87
  autodetectVersion?: boolean;
88
88
  };
89
89
 
90
- declare type DoenetViewerProps = Omit<React.ComponentProps<typeof DoenetViewer_2>, "doenetML" | "scrollableContainer" | "externalVirtualKeyboardProvided">;
90
+ declare type DoenetViewerProps = Omit<React.ComponentProps<typeof DoenetViewer_2>, "doenetML" | "externalVirtualKeyboardProvided">;
91
91
 
92
92
  export { ErrorRecord }
93
93
 
package/index.js CHANGED
@@ -30,6 +30,338 @@ function watchForResize(ref, getHeight, setHeight) {
30
30
  clearInterval(interval);
31
31
  };
32
32
  }
33
+ /**
34
+ * @license
35
+ * Copyright 2019 Google LLC
36
+ * SPDX-License-Identifier: Apache-2.0
37
+ */
38
+ const proxyMarker = Symbol("Comlink.proxy");
39
+ const createEndpoint = Symbol("Comlink.endpoint");
40
+ const releaseProxy = Symbol("Comlink.releaseProxy");
41
+ const finalizer = Symbol("Comlink.finalizer");
42
+ const throwMarker = Symbol("Comlink.thrown");
43
+ const isObject$2 = (val) => typeof val === "object" && val !== null || typeof val === "function";
44
+ const proxyTransferHandler = {
45
+ canHandle: (val) => isObject$2(val) && val[proxyMarker],
46
+ serialize(obj) {
47
+ const { port1, port2 } = new MessageChannel();
48
+ expose(obj, port1);
49
+ return [port2, [port2]];
50
+ },
51
+ deserialize(port) {
52
+ port.start();
53
+ return wrap$2(port);
54
+ }
55
+ };
56
+ const throwTransferHandler = {
57
+ canHandle: (value) => isObject$2(value) && throwMarker in value,
58
+ serialize({ value }) {
59
+ let serialized;
60
+ if (value instanceof Error) {
61
+ serialized = {
62
+ isError: true,
63
+ value: {
64
+ message: value.message,
65
+ name: value.name,
66
+ stack: value.stack
67
+ }
68
+ };
69
+ } else {
70
+ serialized = { isError: false, value };
71
+ }
72
+ return [serialized, []];
73
+ },
74
+ deserialize(serialized) {
75
+ if (serialized.isError) {
76
+ throw Object.assign(new Error(serialized.value.message), serialized.value);
77
+ }
78
+ throw serialized.value;
79
+ }
80
+ };
81
+ const transferHandlers = /* @__PURE__ */ new Map([
82
+ ["proxy", proxyTransferHandler],
83
+ ["throw", throwTransferHandler]
84
+ ]);
85
+ function isAllowedOrigin(allowedOrigins, origin) {
86
+ for (const allowedOrigin of allowedOrigins) {
87
+ if (origin === allowedOrigin || allowedOrigin === "*") {
88
+ return true;
89
+ }
90
+ if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {
91
+ return true;
92
+ }
93
+ }
94
+ return false;
95
+ }
96
+ function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {
97
+ ep.addEventListener("message", function callback(ev) {
98
+ if (!ev || !ev.data) {
99
+ return;
100
+ }
101
+ if (!isAllowedOrigin(allowedOrigins, ev.origin)) {
102
+ console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);
103
+ return;
104
+ }
105
+ const { id: id2, type, path: path2 } = Object.assign({ path: [] }, ev.data);
106
+ const argumentList = (ev.data.argumentList || []).map(fromWireValue);
107
+ let returnValue;
108
+ try {
109
+ const parent = path2.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);
110
+ const rawValue = path2.reduce((obj2, prop) => obj2[prop], obj);
111
+ switch (type) {
112
+ case "GET":
113
+ {
114
+ returnValue = rawValue;
115
+ }
116
+ break;
117
+ case "SET":
118
+ {
119
+ parent[path2.slice(-1)[0]] = fromWireValue(ev.data.value);
120
+ returnValue = true;
121
+ }
122
+ break;
123
+ case "APPLY":
124
+ {
125
+ returnValue = rawValue.apply(parent, argumentList);
126
+ }
127
+ break;
128
+ case "CONSTRUCT":
129
+ {
130
+ const value = new rawValue(...argumentList);
131
+ returnValue = proxy(value);
132
+ }
133
+ break;
134
+ case "ENDPOINT":
135
+ {
136
+ const { port1, port2 } = new MessageChannel();
137
+ expose(obj, port2);
138
+ returnValue = transfer(port1, [port1]);
139
+ }
140
+ break;
141
+ case "RELEASE":
142
+ {
143
+ returnValue = void 0;
144
+ }
145
+ break;
146
+ default:
147
+ return;
148
+ }
149
+ } catch (value) {
150
+ returnValue = { value, [throwMarker]: 0 };
151
+ }
152
+ Promise.resolve(returnValue).catch((value) => {
153
+ return { value, [throwMarker]: 0 };
154
+ }).then((returnValue2) => {
155
+ const [wireValue, transferables] = toWireValue(returnValue2);
156
+ ep.postMessage(Object.assign(Object.assign({}, wireValue), { id: id2 }), transferables);
157
+ if (type === "RELEASE") {
158
+ ep.removeEventListener("message", callback);
159
+ closeEndPoint(ep);
160
+ if (finalizer in obj && typeof obj[finalizer] === "function") {
161
+ obj[finalizer]();
162
+ }
163
+ }
164
+ }).catch((error) => {
165
+ const [wireValue, transferables] = toWireValue({
166
+ value: new TypeError("Unserializable return value"),
167
+ [throwMarker]: 0
168
+ });
169
+ ep.postMessage(Object.assign(Object.assign({}, wireValue), { id: id2 }), transferables);
170
+ });
171
+ });
172
+ if (ep.start) {
173
+ ep.start();
174
+ }
175
+ }
176
+ function isMessagePort(endpoint) {
177
+ return endpoint.constructor.name === "MessagePort";
178
+ }
179
+ function closeEndPoint(endpoint) {
180
+ if (isMessagePort(endpoint))
181
+ endpoint.close();
182
+ }
183
+ function wrap$2(ep, target) {
184
+ const pendingListeners = /* @__PURE__ */ new Map();
185
+ ep.addEventListener("message", function handleMessage(ev) {
186
+ const { data } = ev;
187
+ if (!data || !data.id) {
188
+ return;
189
+ }
190
+ const resolver = pendingListeners.get(data.id);
191
+ if (!resolver) {
192
+ return;
193
+ }
194
+ try {
195
+ resolver(data);
196
+ } finally {
197
+ pendingListeners.delete(data.id);
198
+ }
199
+ });
200
+ return createProxy(ep, pendingListeners, [], target);
201
+ }
202
+ function throwIfProxyReleased(isReleased) {
203
+ if (isReleased) {
204
+ throw new Error("Proxy has been released and is not useable");
205
+ }
206
+ }
207
+ function releaseEndpoint(ep) {
208
+ return requestResponseMessage(ep, /* @__PURE__ */ new Map(), {
209
+ type: "RELEASE"
210
+ }).then(() => {
211
+ closeEndPoint(ep);
212
+ });
213
+ }
214
+ const proxyCounter = /* @__PURE__ */ new WeakMap();
215
+ const proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {
216
+ const newCount = (proxyCounter.get(ep) || 0) - 1;
217
+ proxyCounter.set(ep, newCount);
218
+ if (newCount === 0) {
219
+ releaseEndpoint(ep);
220
+ }
221
+ });
222
+ function registerProxy(proxy2, ep) {
223
+ const newCount = (proxyCounter.get(ep) || 0) + 1;
224
+ proxyCounter.set(ep, newCount);
225
+ if (proxyFinalizers) {
226
+ proxyFinalizers.register(proxy2, ep, proxy2);
227
+ }
228
+ }
229
+ function unregisterProxy(proxy2) {
230
+ if (proxyFinalizers) {
231
+ proxyFinalizers.unregister(proxy2);
232
+ }
233
+ }
234
+ function createProxy(ep, pendingListeners, path2 = [], target = function() {
235
+ }) {
236
+ let isProxyReleased = false;
237
+ const proxy2 = new Proxy(target, {
238
+ get(_target, prop) {
239
+ throwIfProxyReleased(isProxyReleased);
240
+ if (prop === releaseProxy) {
241
+ return () => {
242
+ unregisterProxy(proxy2);
243
+ releaseEndpoint(ep);
244
+ pendingListeners.clear();
245
+ isProxyReleased = true;
246
+ };
247
+ }
248
+ if (prop === "then") {
249
+ if (path2.length === 0) {
250
+ return { then: () => proxy2 };
251
+ }
252
+ const r = requestResponseMessage(ep, pendingListeners, {
253
+ type: "GET",
254
+ path: path2.map((p) => p.toString())
255
+ }).then(fromWireValue);
256
+ return r.then.bind(r);
257
+ }
258
+ return createProxy(ep, pendingListeners, [...path2, prop]);
259
+ },
260
+ set(_target, prop, rawValue) {
261
+ throwIfProxyReleased(isProxyReleased);
262
+ const [value, transferables] = toWireValue(rawValue);
263
+ return requestResponseMessage(ep, pendingListeners, {
264
+ type: "SET",
265
+ path: [...path2, prop].map((p) => p.toString()),
266
+ value
267
+ }, transferables).then(fromWireValue);
268
+ },
269
+ apply(_target, _thisArg, rawArgumentList) {
270
+ throwIfProxyReleased(isProxyReleased);
271
+ const last2 = path2[path2.length - 1];
272
+ if (last2 === createEndpoint) {
273
+ return requestResponseMessage(ep, pendingListeners, {
274
+ type: "ENDPOINT"
275
+ }).then(fromWireValue);
276
+ }
277
+ if (last2 === "bind") {
278
+ return createProxy(ep, pendingListeners, path2.slice(0, -1));
279
+ }
280
+ const [argumentList, transferables] = processArguments(rawArgumentList);
281
+ return requestResponseMessage(ep, pendingListeners, {
282
+ type: "APPLY",
283
+ path: path2.map((p) => p.toString()),
284
+ argumentList
285
+ }, transferables).then(fromWireValue);
286
+ },
287
+ construct(_target, rawArgumentList) {
288
+ throwIfProxyReleased(isProxyReleased);
289
+ const [argumentList, transferables] = processArguments(rawArgumentList);
290
+ return requestResponseMessage(ep, pendingListeners, {
291
+ type: "CONSTRUCT",
292
+ path: path2.map((p) => p.toString()),
293
+ argumentList
294
+ }, transferables).then(fromWireValue);
295
+ }
296
+ });
297
+ registerProxy(proxy2, ep);
298
+ return proxy2;
299
+ }
300
+ function myFlat(arr) {
301
+ return Array.prototype.concat.apply([], arr);
302
+ }
303
+ function processArguments(argumentList) {
304
+ const processed = argumentList.map(toWireValue);
305
+ return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];
306
+ }
307
+ const transferCache = /* @__PURE__ */ new WeakMap();
308
+ function transfer(obj, transfers) {
309
+ transferCache.set(obj, transfers);
310
+ return obj;
311
+ }
312
+ function proxy(obj) {
313
+ return Object.assign(obj, { [proxyMarker]: true });
314
+ }
315
+ function windowEndpoint(w, context = globalThis, targetOrigin = "*") {
316
+ return {
317
+ postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),
318
+ addEventListener: context.addEventListener.bind(context),
319
+ removeEventListener: context.removeEventListener.bind(context)
320
+ };
321
+ }
322
+ function toWireValue(value) {
323
+ for (const [name2, handler] of transferHandlers) {
324
+ if (handler.canHandle(value)) {
325
+ const [serializedValue, transferables] = handler.serialize(value);
326
+ return [
327
+ {
328
+ type: "HANDLER",
329
+ name: name2,
330
+ value: serializedValue
331
+ },
332
+ transferables
333
+ ];
334
+ }
335
+ }
336
+ return [
337
+ {
338
+ type: "RAW",
339
+ value
340
+ },
341
+ transferCache.get(value) || []
342
+ ];
343
+ }
344
+ function fromWireValue(value) {
345
+ switch (value.type) {
346
+ case "HANDLER":
347
+ return transferHandlers.get(value.name).deserialize(value.value);
348
+ case "RAW":
349
+ return value.value;
350
+ }
351
+ }
352
+ function requestResponseMessage(ep, pendingListeners, msg, transfers) {
353
+ return new Promise((resolve) => {
354
+ const id2 = generateUUID();
355
+ pendingListeners.set(id2, resolve);
356
+ if (ep.start) {
357
+ ep.start();
358
+ }
359
+ ep.postMessage(Object.assign({ id: id2 }, msg), transfers);
360
+ });
361
+ }
362
+ function generateUUID() {
363
+ return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
364
+ }
33
365
  var DefaultContext = {
34
366
  color: void 0,
35
367
  size: void 0,
@@ -23276,9 +23608,13 @@ const mathjaxConfig = {
23276
23608
  amp: "&",
23277
23609
  var: ["\\mathrm{#1}", 1],
23278
23610
  csch: "\\operatorname{csch}",
23279
- sech: "\\operatorname{sech}"
23611
+ sech: "\\operatorname{sech}",
23612
+ erf: "\\operatorname{erf}"
23280
23613
  },
23281
23614
  displayMath: [["\\[", "\\]"]]
23615
+ },
23616
+ output: {
23617
+ displayOverflow: "linebreak"
23282
23618
  }
23283
23619
  };
23284
23620
  /*! https://mths.be/cssesc v3.0.0 by @mathias */
@@ -23373,23 +23709,10 @@ function requireCssesc() {
23373
23709
  return cssesc_1;
23374
23710
  }
23375
23711
  requireCssesc();
23376
- const viewerIframeJsSource = '(function() {\n "use strict";\n document.addEventListener("DOMContentLoaded", async () => {\n let pause100 = function() {\n return new Promise((resolve, _reject) => {\n setTimeout(resolve, 100);\n });\n };\n for (let i = 0; i < 10; i++) {\n if (typeof window.renderDoenetViewerToContainer === "function") {\n break;\n }\n await pause100();\n }\n if (typeof window.renderDoenetViewerToContainer !== "function") {\n return messageParentFromViewer({\n error: "Invalid DoenetML version or DoenetML package not found"\n });\n }\n const callbackOverrides = {};\n const callbackNames = [\n "reportScoreAndStateCallback",\n "setIsInErrorState",\n "generatedVariantCallback",\n "documentStructureCallback",\n "initializedCallback",\n "setErrorsAndWarningsCallback"\n ];\n for (const callback of callbackNames) {\n callbackOverrides[callback] = haveViewerCallbacks.includes(callback) ? (args) => {\n messageParentFromViewer({\n callback,\n args\n });\n } : void 0;\n }\n window.renderDoenetViewerToContainer(\n document.getElementById("root"),\n void 0,\n {\n ...doenetViewerProps,\n externalVirtualKeyboardProvided: true,\n ...callbackOverrides\n }\n );\n });\n window.addEventListener("message", (e) => {\n if (e.origin !== window.parent.location.origin) {\n return;\n }\n if (e.data.subject?.startsWith("SPLICE") && !e.data.subject?.endsWith("response")) {\n window.parent.postMessage(e.data);\n } else if (e.data.subject === "requestAnswerResponses") {\n window.parent.postMessage(e.data);\n }\n });\n function messageParentFromViewer(data) {\n window.parent.postMessage(\n {\n origin: viewerId,\n data\n },\n window.parent.origin\n );\n }\n})();\n';
23377
- const editorIframeJsSource = '(function() {\n "use strict";\n document.addEventListener("DOMContentLoaded", async () => {\n let pause100 = function() {\n return new Promise((resolve, _reject) => {\n setTimeout(resolve, 100);\n });\n };\n for (let i = 0; i < 10; i++) {\n if (typeof window.renderDoenetViewerToContainer === "function") {\n break;\n }\n await pause100();\n }\n if (typeof window.renderDoenetEditorToContainer !== "function") {\n return messageParentFromEditor({\n error: "Invalid DoenetML version or DoenetML package not found"\n });\n }\n const callbackOverrides = {};\n const callbackNames = [\n "doenetmlChangeCallback",\n "immediateDoenetmlChangeCallback",\n "documentStructureCallback"\n ];\n for (const callback of callbackNames) {\n callbackOverrides[callback] = haveEditorCallbacks.includes(callback) ? (args) => {\n messageParentFromEditor({\n callback,\n args\n });\n } : void 0;\n }\n window.renderDoenetEditorToContainer(\n document.getElementById("root"),\n void 0,\n {\n ...doenetEditorProps,\n externalVirtualKeyboardProvided: true,\n ...callbackOverrides\n }\n );\n });\n function messageParentFromEditor(data) {\n window.parent.postMessage(\n {\n origin: editorId,\n data\n },\n window.parent.origin\n );\n }\n})();\n';
23712
+ const viewerIframeJsSource = '(function() {\n "use strict";\n document.addEventListener("DOMContentLoaded", async () => {\n let pause100 = function() {\n return new Promise((resolve, _reject) => {\n setTimeout(resolve, 100);\n });\n };\n for (let i = 0; i < 10; i++) {\n if (typeof window.renderDoenetViewerToContainer === "function") {\n break;\n }\n await pause100();\n }\n if (typeof window.renderDoenetViewerToContainer !== "function") {\n return messageParentFromViewer({\n error: "Invalid DoenetML version or DoenetML package not found"\n });\n }\n });\n ComlinkViewer.expose(\n { renderViewerWithFunctionProps },\n ComlinkViewer.windowEndpoint(globalThis.parent)\n );\n function renderViewerWithFunctionProps(...args) {\n const augmentedDoenetViewerProps = { ...doenetViewerProps };\n augmentedDoenetViewerProps.externalVirtualKeyboardProvided = true;\n for (const propName of doenetViewerPropsSpecified) {\n if (!(propName in doenetViewerProps)) {\n const idx = args.indexOf(propName);\n if (idx !== -1) {\n augmentedDoenetViewerProps[propName] = args[idx + 1];\n }\n }\n }\n if (!doenetViewerPropsSpecified.includes("requestScrollTo")) {\n augmentedDoenetViewerProps.requestScrollTo = (offset) => {\n messageParentFromViewer({ type: "scrollTo", offset });\n };\n }\n window.renderDoenetViewerToContainer(\n document.getElementById("root"),\n void 0,\n augmentedDoenetViewerProps\n );\n }\n messageParentFromViewer({ iframeReady: true });\n window.addEventListener("message", (e) => {\n if (e.origin !== window.parent.location.origin) {\n return;\n }\n if (e.data.subject?.startsWith("SPLICE") && (!e.data.subject?.endsWith("response") || e.data.subject.endsWith("submitAllAnswers.response")) && !e.data.subject.endsWith("submitAllAnswers")) {\n window.parent.postMessage(e.data);\n } else if (e.data.subject === "requestAnswerResponses") {\n window.parent.postMessage(e.data);\n }\n });\n function messageParentFromViewer(data) {\n window.parent.postMessage(\n {\n origin: viewerId,\n data\n },\n window.parent.origin\n );\n }\n})();\n';
23713
+ const editorIframeJsSource = '(function() {\n "use strict";\n document.addEventListener("DOMContentLoaded", async () => {\n let pause100 = function() {\n return new Promise((resolve, _reject) => {\n setTimeout(resolve, 100);\n });\n };\n for (let i = 0; i < 10; i++) {\n if (typeof window.renderDoenetViewerToContainer === "function") {\n break;\n }\n await pause100();\n }\n if (typeof window.renderDoenetEditorToContainer !== "function") {\n return messageParentFromEditor({\n error: "Invalid DoenetML version or DoenetML package not found"\n });\n }\n });\n ComlinkEditor.expose(\n { renderEditorWithFunctionProps },\n ComlinkEditor.windowEndpoint(globalThis.parent)\n );\n function renderEditorWithFunctionProps(...args) {\n const augmentedDoenetEditorProps = { ...doenetEditorProps };\n augmentedDoenetEditorProps.externalVirtualKeyboardProvided = true;\n for (const propName of doenetEditorPropsSpecified) {\n if (!(propName in doenetEditorProps)) {\n const idx = args.indexOf(propName);\n if (idx !== -1) {\n augmentedDoenetEditorProps[propName] = args[idx + 1];\n }\n }\n }\n window.renderDoenetEditorToContainer(\n document.getElementById("root"),\n void 0,\n augmentedDoenetEditorProps\n );\n }\n messageParentFromEditor({ iframeReady: true });\n function messageParentFromEditor(data) {\n window.parent.postMessage(\n {\n origin: editorId,\n data\n },\n window.parent.origin\n );\n }\n})();\n';
23378
23714
  function createHtmlForDoenetViewer(id2, doenetML, doenetViewerProps, standaloneUrl, cssUrl) {
23379
- const haveViewerCallbacks = [];
23380
- const callbackNames = [
23381
- "reportScoreAndStateCallback",
23382
- "setIsInErrorState",
23383
- "generatedVariantCallback",
23384
- "documentStructureCallback",
23385
- "initializedCallback",
23386
- "setErrorsAndWarningsCallback"
23387
- ];
23388
- for (const callback of callbackNames) {
23389
- if (callback in doenetViewerProps) {
23390
- haveViewerCallbacks.push(callback);
23391
- }
23392
- }
23715
+ const doenetViewerPropsSpecified = Object.keys(doenetViewerProps);
23393
23716
  return `
23394
23717
  <html style="overflow:hidden">
23395
23718
  <head>
@@ -23400,10 +23723,11 @@ function createHtmlForDoenetViewer(id2, doenetML, doenetViewerProps, standaloneU
23400
23723
  <script type="module">
23401
23724
  const viewerId = "${id2}";
23402
23725
  const doenetViewerProps = ${JSON.stringify(doenetViewerProps)};
23403
- const haveViewerCallbacks = ${JSON.stringify(haveViewerCallbacks)};
23404
-
23726
+ const doenetViewerPropsSpecified = ${JSON.stringify(doenetViewerPropsSpecified)};
23727
+ import * as ComlinkViewer from "https://unpkg.com/comlink/dist/esm/comlink.mjs";
23728
+
23405
23729
  // This source code has been compiled by vite and should be directly included.
23406
- // It assumes that viewerId, doenetViewerProps, and haveViewerCallbacks are defined in the global scope.
23730
+ // It assumes that viewerId, doenetViewerProps, doenetViewerPropsSpecified, and ComlinkViewer are defined in the global scope.
23407
23731
  ${viewerIframeJsSource}
23408
23732
  <\/script>
23409
23733
  <div id="root">
@@ -23415,17 +23739,7 @@ function createHtmlForDoenetViewer(id2, doenetML, doenetViewerProps, standaloneU
23415
23739
  }
23416
23740
  function createHtmlForDoenetEditor(id2, doenetML, width, doenetEditorProps, standaloneUrl, cssUrl) {
23417
23741
  const augmentedProps = { width, height: "100vh", ...doenetEditorProps };
23418
- const haveEditorCallbacks = [];
23419
- const callbackNames = [
23420
- "doenetmlChangeCallback",
23421
- "immediateDoenetmlChangeCallback",
23422
- "documentStructureCallback"
23423
- ];
23424
- for (const callback of callbackNames) {
23425
- if (callback in doenetEditorProps) {
23426
- haveEditorCallbacks.push(callback);
23427
- }
23428
- }
23742
+ const doenetEditorPropsSpecified = Object.keys(augmentedProps);
23429
23743
  return `
23430
23744
  <html style="overflow:hidden">
23431
23745
  <head>
@@ -23436,10 +23750,11 @@ function createHtmlForDoenetEditor(id2, doenetML, width, doenetEditorProps, stan
23436
23750
  <script type="module">
23437
23751
  const editorId = "${id2}";
23438
23752
  const doenetEditorProps = ${JSON.stringify(augmentedProps)};
23439
- const haveEditorCallbacks = ${JSON.stringify(haveEditorCallbacks)};
23753
+ const doenetEditorPropsSpecified = ${JSON.stringify(doenetEditorPropsSpecified)};
23754
+ import * as ComlinkEditor from "https://unpkg.com/comlink/dist/esm/comlink.mjs";
23440
23755
 
23441
23756
  // This source code has been compiled by vite and should be directly included.
23442
- // It assumes that editorId, doenetEditorProps, and have EditorCallbacks are defined in the global scope.
23757
+ // It assumes that editorId, doenetEditorProps, doenetEditorPropsSpecified, and ComlinkEditor are defined in the global scope.
23443
23758
  ${editorIframeJsSource}
23444
23759
  <\/script>
23445
23760
  <div id="root">
@@ -46449,7 +46764,7 @@ function ExternalVirtualKeyboard() {
46449
46764
  }
46450
46765
  );
46451
46766
  }
46452
- const version = "0.7.0-beta1";
46767
+ const version = "0.7.0-beta10";
46453
46768
  const latestDoenetmlVersion = version;
46454
46769
  function DoenetViewer({
46455
46770
  doenetML,
@@ -46491,7 +46806,7 @@ function DoenetViewer({
46491
46806
  if (event.origin !== window.location.origin) {
46492
46807
  return;
46493
46808
  }
46494
- if (event.data.subject === "SPLICE.getState.response" || event.data.subject === "SPLICE.requestSolutionView.response") {
46809
+ if (event.data.subject === "SPLICE.getState.response" || event.data.subject === "SPLICE.requestSolutionView.response" || event.data.subject == "SPLICE.submitAllAnswers") {
46495
46810
  ref.current?.contentWindow?.postMessage(event.data);
46496
46811
  return;
46497
46812
  }
@@ -46499,34 +46814,32 @@ function DoenetViewer({
46499
46814
  return;
46500
46815
  }
46501
46816
  const data = event.data.data;
46817
+ if (ref.current && data.type === "scrollTo" && typeof data.offset === "number") {
46818
+ const iframeTop = ref.current.getBoundingClientRect().top + window.scrollY;
46819
+ const targetAbsoluteTop = iframeTop + data.offset;
46820
+ window.scrollTo({
46821
+ top: targetAbsoluteTop - 20,
46822
+ behavior: "smooth"
46823
+ });
46824
+ }
46502
46825
  if (data.error) {
46503
46826
  return setInErrorState(data.error);
46504
- }
46505
- switch (data.callback) {
46506
- case "reportScoreAndStateCallback": {
46507
- return doenetViewerProps.reportScoreAndStateCallback?.(
46508
- data.args
46827
+ } else if (data.iframeReady) {
46828
+ if (ref.current) {
46829
+ const viewerIframe = wrap$2(
46830
+ windowEndpoint(ref.current.contentWindow)
46509
46831
  );
46510
- }
46511
- case "setIsInErrorState": {
46512
- return doenetViewerProps.setIsInErrorState?.(data.args);
46513
- }
46514
- case "generatedVariantCallback": {
46515
- return doenetViewerProps.generatedVariantCallback?.(
46516
- data.args
46517
- );
46518
- }
46519
- case "documentStructureCallback": {
46520
- return doenetViewerProps.documentStructureCallback?.(
46521
- data.args
46522
- );
46523
- }
46524
- case "initializedCallback": {
46525
- return doenetViewerProps.initializedCallback?.(data.args);
46526
- }
46527
- case "setErrorsAndWarningsCallback": {
46528
- return doenetViewerProps.setErrorsAndWarningsCallback?.(
46529
- data.args
46832
+ const proxiedFunctions = [];
46833
+ for (const [key, prop] of Object.entries(
46834
+ doenetViewerProps
46835
+ )) {
46836
+ if (typeof prop === "function") {
46837
+ proxiedFunctions.push(key);
46838
+ proxiedFunctions.push(proxy(prop));
46839
+ }
46840
+ }
46841
+ viewerIframe?.renderViewerWithFunctionProps(
46842
+ ...proxiedFunctions
46530
46843
  );
46531
46844
  }
46532
46845
  }
@@ -46571,6 +46884,7 @@ function DoenetViewer({
46571
46884
  return /* @__PURE__ */ React__default__default.createElement(React__default__default.Fragment, null, addVirtualKeyboard ? /* @__PURE__ */ React__default__default.createElement(ExternalVirtualKeyboard, null) : null, /* @__PURE__ */ React__default__default.createElement(
46572
46885
  "iframe",
46573
46886
  {
46887
+ title: "Doenet document",
46574
46888
  ref,
46575
46889
  srcDoc: createHtmlForDoenetViewer(
46576
46890
  id2,
@@ -46645,21 +46959,22 @@ function DoenetEditor({
46645
46959
  const data = event.data.data;
46646
46960
  if (data.error) {
46647
46961
  return setInErrorState(data.error);
46648
- }
46649
- switch (data.callback) {
46650
- case "doenetmlChangeCallback": {
46651
- return doenetEditorProps.doenetmlChangeCallback?.(
46652
- data.args
46653
- );
46654
- }
46655
- case "immediateDoenetmlChangeCallback": {
46656
- return doenetEditorProps.immediateDoenetmlChangeCallback?.(
46657
- data.args
46962
+ } else if (data.iframeReady) {
46963
+ if (ref.current) {
46964
+ const editorIframe = wrap$2(
46965
+ windowEndpoint(ref.current.contentWindow)
46658
46966
  );
46659
- }
46660
- case "documentStructureCallback": {
46661
- return doenetEditorProps.documentStructureCallback?.(
46662
- data.args
46967
+ const proxiedFunctions = [];
46968
+ for (const [key, prop] of Object.entries(
46969
+ doenetEditorProps
46970
+ )) {
46971
+ if (typeof prop === "function") {
46972
+ proxiedFunctions.push(key);
46973
+ proxiedFunctions.push(proxy(prop));
46974
+ }
46975
+ }
46976
+ editorIframe?.renderEditorWithFunctionProps(
46977
+ ...proxiedFunctions
46663
46978
  );
46664
46979
  }
46665
46980
  }
@@ -46714,6 +47029,7 @@ function DoenetEditor({
46714
47029
  return /* @__PURE__ */ React__default__default.createElement(React__default__default.Fragment, null, addVirtualKeyboard ? /* @__PURE__ */ React__default__default.createElement(ExternalVirtualKeyboard, null) : null, /* @__PURE__ */ React__default__default.createElement(
46715
47030
  "iframe",
46716
47031
  {
47032
+ title: "Doenet Editor",
46717
47033
  ref,
46718
47034
  srcDoc: createHtmlForDoenetEditor(
46719
47035
  id2,