@pie-element/explicit-constructed-response 11.1.2-next.19 → 11.1.2-next.20

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.
@@ -0,0 +1,156 @@
1
+ import { at as e } from "../dist-B9hsEnNL.js";
2
+ import { t } from "../main-Ot6cxLkg.js";
3
+ import n from "react";
4
+ import { createRoot as r } from "react-dom/client";
5
+ //#region ../../shared/player-events/dist/index.js
6
+ var i = "commitPendingSession", a = /* @__PURE__ */ new WeakMap();
7
+ function o(e, t) {
8
+ let n = a.get(e);
9
+ n || (n = /* @__PURE__ */ new Set(), a.set(e, n)), n.add(t);
10
+ }
11
+ function s(e) {
12
+ return Object.getOwnPropertyDescriptor(e, i) !== void 0;
13
+ }
14
+ function c(e) {
15
+ if (s(e)) return;
16
+ let t = e[i];
17
+ Object.defineProperty(e, i, {
18
+ value: () => {
19
+ if (typeof t == "function") try {
20
+ t.call(e);
21
+ } catch {}
22
+ u(e);
23
+ },
24
+ configurable: !0,
25
+ enumerable: !1,
26
+ writable: !0
27
+ });
28
+ }
29
+ function l(e, t, n = {}) {
30
+ let r = n.delayMs, i = typeof r == "function" ? r : () => r ?? 0, a = n.maxWaitMs, s = null, l = null, u = !1, d = () => {
31
+ s !== null && (clearTimeout(s), s = null), l !== null && (clearTimeout(l), l = null);
32
+ }, f = () => {
33
+ d(), u && (u = !1, t());
34
+ }, p = {
35
+ notify() {
36
+ u = !0, s !== null && clearTimeout(s), s = setTimeout(f, Math.max(0, i())), a !== void 0 && l === null && (l = setTimeout(f, Math.max(0, a)));
37
+ },
38
+ flush() {
39
+ if (!u) {
40
+ d();
41
+ return;
42
+ }
43
+ try {
44
+ f();
45
+ } catch (e) {
46
+ console.warn("[session-notifier] a committed session-changed dispatch threw", e);
47
+ }
48
+ }
49
+ };
50
+ return o(e, p), c(e), p;
51
+ }
52
+ function u(e) {
53
+ let t = a.get(e);
54
+ if (t) for (let e of [...t]) e.flush();
55
+ }
56
+ var d = class e extends CustomEvent {
57
+ static {
58
+ this.TYPE = "model-set";
59
+ }
60
+ constructor(t, n, r) {
61
+ super(e.TYPE, {
62
+ bubbles: !0,
63
+ composed: !0,
64
+ detail: {
65
+ complete: n,
66
+ component: t,
67
+ hasModel: r
68
+ }
69
+ }), this.component = t, this.complete = n;
70
+ }
71
+ }, f = class e extends CustomEvent {
72
+ static {
73
+ this.TYPE = "session-changed";
74
+ }
75
+ constructor(t, n) {
76
+ super(e.TYPE, {
77
+ bubbles: !0,
78
+ composed: !0,
79
+ detail: {
80
+ complete: n,
81
+ component: t
82
+ }
83
+ }), this.component = t, this.complete = n;
84
+ }
85
+ }, p = 200;
86
+ function m(e) {
87
+ let t = e && e.maxLengthPerChoice;
88
+ return Array.isArray(t) && t.length > 0 && t.every((e) => e === 1) ? 0 : p;
89
+ }
90
+ var h = class extends HTMLElement {
91
+ constructor() {
92
+ super(), this._model = null, this._session = null, this._root = null, this._sessionNotifier = l(this, () => {
93
+ this.dispatchChangedEvent(), this._render();
94
+ }, {
95
+ delayMs: () => m(this._model),
96
+ maxWaitMs: p
97
+ });
98
+ }
99
+ setLangAttribute() {
100
+ let e = this._model && typeof this._model.language ? this._model.language : "", t = e ? e.slice(0, 2) : "en";
101
+ this.setAttribute("lang", t);
102
+ }
103
+ set model(e) {
104
+ this._model = e, this.dispatchEvent(new d(this.tagName.toLowerCase(), this.session && !!this.session.value, !!this._model)), this.setLangAttribute(), this._render();
105
+ }
106
+ set session(e) {
107
+ this._session = e, this._render();
108
+ }
109
+ get session() {
110
+ return this._session;
111
+ }
112
+ _render = () => {
113
+ if (this._model && this._session) {
114
+ let i = n.createElement(t, {
115
+ choices: this._model.choices,
116
+ disabled: this._model.disabled,
117
+ displayType: this._model.displayType,
118
+ feedback: this._model.feedback,
119
+ language: this._model.language,
120
+ markup: this._model.markup,
121
+ maxLengthPerChoice: this._model.maxLengthPerChoice,
122
+ maxLengthPerChoiceEnabled: this._model.maxLengthPerChoiceEnabled,
123
+ mode: this._model.mode,
124
+ note: this._model.note,
125
+ onChange: this.changeSession,
126
+ playerSpellCheckEnabled: this._model.playerSpellCheckEnabled,
127
+ prompt: this._model.prompt,
128
+ rationale: this._model.rationale,
129
+ role: this._model.role,
130
+ showNote: this._model.showNote,
131
+ teacherInstructions: this._model.teacherInstructions,
132
+ value: this._session.value,
133
+ responseAreaInputConfiguration: this._model.responseAreaInputConfiguration
134
+ });
135
+ this._root ||= r(this), this._root.render(i), queueMicrotask(() => {
136
+ e(this);
137
+ });
138
+ }
139
+ };
140
+ dispatchChangedEvent = () => {
141
+ this.dispatchEvent(new f(this.tagName.toLowerCase(), this.session && !!this.session.value));
142
+ };
143
+ changeSession = (e) => {
144
+ this.session.value = e, this._sessionNotifier.notify();
145
+ };
146
+ connectedCallback() {
147
+ this.setAttribute("aria-label", "Fill in the Blank Question"), this.setAttribute("role", "region"), this._render();
148
+ }
149
+ disconnectedCallback() {
150
+ u(this), this._root &&= (this._root.unmount(), null);
151
+ }
152
+ };
153
+ //#endregion
154
+ export { h as default };
155
+
156
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../shared/player-events/dist/index.js","../../../../src/delivery/index.ts"],"sourcesContent":["//#region src/session-notifier.ts\nvar e = \"commitPendingSession\", t = /* @__PURE__ */ new WeakMap();\nfunction n(e, n) {\n\tlet r = t.get(e);\n\tr || (r = /* @__PURE__ */ new Set(), t.set(e, r)), r.add(n);\n}\nfunction r(t) {\n\treturn Object.getOwnPropertyDescriptor(t, e) !== void 0;\n}\nfunction i(t) {\n\tif (r(t)) return;\n\tlet n = t[e];\n\tObject.defineProperty(t, e, {\n\t\tvalue: () => {\n\t\t\tif (typeof n == \"function\") try {\n\t\t\t\tn.call(t);\n\t\t\t} catch {}\n\t\t\to(t);\n\t\t},\n\t\tconfigurable: !0,\n\t\tenumerable: !1,\n\t\twritable: !0\n\t});\n}\nfunction a(e, t, r = {}) {\n\tlet a = r.delayMs, o = typeof a == \"function\" ? a : () => a ?? 0, s = r.maxWaitMs, c = null, l = null, u = !1, d = () => {\n\t\tc !== null && (clearTimeout(c), c = null), l !== null && (clearTimeout(l), l = null);\n\t}, f = () => {\n\t\td(), u && (u = !1, t());\n\t}, p = {\n\t\tnotify() {\n\t\t\tu = !0, c !== null && clearTimeout(c), c = setTimeout(f, Math.max(0, o())), s !== void 0 && l === null && (l = setTimeout(f, Math.max(0, s)));\n\t\t},\n\t\tflush() {\n\t\t\tif (!u) {\n\t\t\t\td();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tf();\n\t\t\t} catch (e) {\n\t\t\t\tconsole.warn(\"[session-notifier] a committed session-changed dispatch threw\", e);\n\t\t\t}\n\t\t}\n\t};\n\treturn n(e, p), i(e), p;\n}\nfunction o(e) {\n\tlet n = t.get(e);\n\tif (n) for (let e of [...n]) e.flush();\n}\n//#endregion\n//#region src/index.ts\nvar s = class e extends CustomEvent {\n\tstatic {\n\t\tthis.TYPE = \"model-set\";\n\t}\n\tconstructor(t, n, r) {\n\t\tsuper(e.TYPE, {\n\t\t\tbubbles: !0,\n\t\t\tcomposed: !0,\n\t\t\tdetail: {\n\t\t\t\tcomplete: n,\n\t\t\t\tcomponent: t,\n\t\t\t\thasModel: r\n\t\t\t}\n\t\t}), this.component = t, this.complete = n;\n\t}\n}, c = class e extends CustomEvent {\n\tstatic {\n\t\tthis.TYPE = \"session-changed\";\n\t}\n\tconstructor(t, n) {\n\t\tsuper(e.TYPE, {\n\t\t\tbubbles: !0,\n\t\t\tcomposed: !0,\n\t\t\tdetail: {\n\t\t\t\tcomplete: n,\n\t\t\t\tcomponent: t\n\t\t\t}\n\t\t}), this.component = t, this.complete = n;\n\t}\n};\n//#endregion\nexport { s as ModelSetEvent, e as SESSION_COMMIT_METHOD, c as SessionChangedEvent, a as createSessionNotifier, o as flushSessionNotifiers };\n","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/explicit-constructed-response/src/index.js\n * @auto-generated\n *\n * This file is automatically synced from pie-elements and converted to TypeScript.\n * Manual edits will be overwritten on next sync.\n * To make changes, edit the upstream JavaScript file and run sync again.\n */\n\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport {\n ModelSetEvent,\n SessionChangedEvent,\n createSessionNotifier,\n flushSessionNotifiers,\n} from '@pie-element/shared-player-events';\nimport { renderMath } from '@pie-element/shared-math-rendering-mathjax';\n\nimport Main from './main.js';\n\nconst SESSION_NOTIFY_DELAY_MS = 200;\n\n// Every blank capped at one character means each keystroke is a whole response,\n// so there is nothing to coalesce and the dispatch goes out on the next tick.\nfunction notifyDelayForModel(model) {\n const lengths = model && model.maxLengthPerChoice;\n const singleCharacterBlanks =\n Array.isArray(lengths) && lengths.length > 0 && lengths.every((length) => length === 1);\n return singleCharacterBlanks ? 0 : SESSION_NOTIFY_DELAY_MS;\n}\n\nexport default class InlineDropdown extends HTMLElement {\n constructor() {\n super();\n this._model = null;\n this._session = null;\n this._root = null;\n\n // The session is written synchronously on commit; the dispatch and the\n // re-render are what get coalesced, which keeps the render cadence the\n // value-path debounce used to set while leaving `.session` readable at any\n // point. `disconnectedCallback` flushes what is still pending.\n this._sessionNotifier = createSessionNotifier(\n this,\n () => {\n this.dispatchChangedEvent();\n this._render();\n },\n { delayMs: () => notifyDelayForModel(this._model), maxWaitMs: SESSION_NOTIFY_DELAY_MS },\n );\n }\n\n setLangAttribute() {\n const language = this._model && typeof this._model.language ? this._model.language : '';\n const lang = language ? language.slice(0, 2) : 'en';\n this.setAttribute('lang', lang);\n }\n\n set model(m) {\n this._model = m;\n this.dispatchEvent(\n new ModelSetEvent(this.tagName.toLowerCase(), this.session && !!this.session.value, !!this._model),\n );\n this.setLangAttribute();\n\n this._render();\n }\n\n set session(s) {\n this._session = s;\n this._render();\n }\n\n get session() {\n return this._session;\n }\n\n _render: any = () => {\n if (this._model && this._session) {\n let elem = React.createElement(Main, {\n choices: this._model.choices,\n disabled: this._model.disabled,\n displayType: this._model.displayType,\n feedback: this._model.feedback,\n language: this._model.language,\n markup: this._model.markup,\n maxLengthPerChoice: this._model.maxLengthPerChoice,\n maxLengthPerChoiceEnabled: this._model.maxLengthPerChoiceEnabled,\n mode: this._model.mode,\n note: this._model.note,\n onChange: this.changeSession,\n playerSpellCheckEnabled: this._model.playerSpellCheckEnabled,\n prompt: this._model.prompt,\n rationale: this._model.rationale,\n role: this._model.role,\n showNote: this._model.showNote,\n teacherInstructions: this._model.teacherInstructions,\n value: this._session.value,\n responseAreaInputConfiguration: this._model.responseAreaInputConfiguration,\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(elem);\n queueMicrotask(() => {\n renderMath(this);\n });\n }\n };\n\n dispatchChangedEvent: any = () => {\n this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), this.session && !!this.session.value));\n };\n\n changeSession: any = (value) => {\n this.session.value = value;\n this._sessionNotifier.notify();\n };\n\n connectedCallback() {\n this.setAttribute('aria-label', 'Fill in the Blank Question');\n this.setAttribute('role', 'region');\n\n this._render();\n }\n\n disconnectedCallback() {\n flushSessionNotifiers(this);\n\n if (this._root) {\n this._root.unmount();\n this._root = null;\n }\n }\n}\n"],"mappings":";;;;;AACA,IAAI,IAAI,wBAAwB,oBAAoB,IAAI,QAAQ;AAChE,SAAS,EAAE,GAAG,GAAG;CAChB,IAAI,IAAI,EAAE,IAAI,CAAC;CACf,MAAM,oBAAoB,IAAI,IAAI,GAAG,EAAE,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;AAC3D;AACA,SAAS,EAAE,GAAG;CACb,OAAO,OAAO,yBAAyB,GAAG,CAAC,MAAM,KAAK;AACvD;AACA,SAAS,EAAE,GAAG;CACb,IAAI,EAAE,CAAC,GAAG;CACV,IAAI,IAAI,EAAE;CACV,OAAO,eAAe,GAAG,GAAG;EAC3B,aAAa;GACZ,IAAI,OAAO,KAAK,YAAY,IAAI;IAC/B,EAAE,KAAK,CAAC;GACT,QAAQ,CAA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