@pie-element/math-templated 7.1.1-next.21 → 7.1.1-next.23

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.
@@ -1,9 +1,58 @@
1
- import { u as e } from "../browser-_ggI30Zt.js";
2
- import { t } from "../main-D8ntXLaZ.js";
3
- import n from "react";
4
- import { createRoot as r } from "react-dom/client";
1
+ import { t as e } from "../main-ou3Tfrcf.js";
2
+ import t from "react";
3
+ import { createRoot as n } from "react-dom/client";
5
4
  //#region ../../shared/player-events/dist/index.js
6
- var i = class e extends CustomEvent {
5
+ var r = "commitPendingSession", i = /* @__PURE__ */ new WeakMap();
6
+ function a(e, t) {
7
+ let n = i.get(e);
8
+ n || (n = /* @__PURE__ */ new Set(), i.set(e, n)), n.add(t);
9
+ }
10
+ function o(e) {
11
+ return Object.getOwnPropertyDescriptor(e, r) !== void 0;
12
+ }
13
+ function s(e) {
14
+ if (o(e)) return;
15
+ let t = e[r];
16
+ Object.defineProperty(e, r, {
17
+ value: () => {
18
+ if (typeof t == "function") try {
19
+ t.call(e);
20
+ } catch {}
21
+ l(e);
22
+ },
23
+ configurable: !0,
24
+ enumerable: !1,
25
+ writable: !0
26
+ });
27
+ }
28
+ function c(e, t, n = {}) {
29
+ let r = n.delayMs, i = typeof r == "function" ? r : () => r ?? 0, o = n.maxWaitMs, c = null, l = null, u = !1, d = () => {
30
+ c !== null && (clearTimeout(c), c = null), l !== null && (clearTimeout(l), l = null);
31
+ }, f = () => {
32
+ d(), u && (u = !1, t());
33
+ }, p = {
34
+ notify() {
35
+ u = !0, c !== null && clearTimeout(c), c = setTimeout(f, Math.max(0, i())), o !== void 0 && l === null && (l = setTimeout(f, Math.max(0, o)));
36
+ },
37
+ flush() {
38
+ if (!u) {
39
+ d();
40
+ return;
41
+ }
42
+ try {
43
+ f();
44
+ } catch (e) {
45
+ console.warn("[session-notifier] a committed session-changed dispatch threw", e);
46
+ }
47
+ }
48
+ };
49
+ return a(e, p), s(e), p;
50
+ }
51
+ function l(e) {
52
+ let t = i.get(e);
53
+ if (t) for (let e of [...t]) e.flush();
54
+ }
55
+ var u = class e extends CustomEvent {
7
56
  static {
8
57
  this.TYPE = "model-set";
9
58
  }
@@ -18,7 +67,7 @@ var i = class e extends CustomEvent {
18
67
  }
19
68
  }), this.component = t, this.complete = n;
20
69
  }
21
- }, a = class e extends CustomEvent {
70
+ }, d = class e extends CustomEvent {
22
71
  static {
23
72
  this.TYPE = "session-changed";
24
73
  }
@@ -32,14 +81,14 @@ var i = class e extends CustomEvent {
32
81
  }
33
82
  }), this.component = t, this.complete = n;
34
83
  }
35
- }, o = class extends HTMLElement {
84
+ }, f = class extends HTMLElement {
36
85
  constructor() {
37
- super(), this._root = null, this.sessionChangedEventCaller = e(() => {
38
- this.dispatchEvent(new a(this.tagName.toLowerCase(), !0));
39
- }, 1e3);
86
+ super(), this._root = null, this._sessionNotifier = c(this, () => {
87
+ this.dispatchEvent(new d(this.tagName.toLowerCase(), !0));
88
+ }, { delayMs: 1e3 }), this.sessionChangedEventCaller = () => this._sessionNotifier.notify();
40
89
  }
41
90
  set model(e) {
42
- this._model = e, this.render(), this.dispatchEvent(new i(this.tagName.toLowerCase(), this.isSessionComplete(), this._model !== void 0));
91
+ this._model = e, this.render(), this.dispatchEvent(new u(this.tagName.toLowerCase(), this.isSessionComplete(), this._model !== void 0));
43
92
  }
44
93
  get model() {
45
94
  return this._model;
@@ -63,19 +112,19 @@ var i = class e extends CustomEvent {
63
112
  }
64
113
  render() {
65
114
  if (!(!this._model || !this._session) && this._model && this._session) {
66
- let e = n.createElement(t, {
115
+ let r = t.createElement(e, {
67
116
  model: this._model,
68
117
  session: this._session,
69
118
  onSessionChange: this.onSessionChange.bind(this)
70
119
  });
71
- this._root ||= r(this), this._root.render(e);
120
+ this._root ||= n(this), this._root.render(r);
72
121
  }
73
122
  }
74
123
  disconnectedCallback() {
75
- this._root &&= (this._root.unmount(), null);
124
+ l(this), this._root &&= (this._root.unmount(), null);
76
125
  }
77
126
  };
78
127
  //#endregion
79
- export { o as default };
128
+ export { f as default };
80
129
 
81
130
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../shared/player-events/dist/index.js","../../../src/delivery/index.ts"],"sourcesContent":["//#region src/index.ts\nvar e = 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}, t = 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 { e as ModelSetEvent, t as SessionChangedEvent };\n","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/math-templated/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 { SessionChangedEvent, ModelSetEvent } from '@pie-element/shared-player-events';\nimport Main from './main.js';\nimport { debounce } from '@pie-element/shared-lodash';\n\nexport default class MathTemplated extends HTMLElement {\n constructor() {\n super();\n this._root = null;\n this.sessionChangedEventCaller = debounce(() => {\n this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), true));\n }, 1000);\n }\n\n set model(m) {\n this._model = m;\n\n this.render();\n this.dispatchEvent(\n new ModelSetEvent(this.tagName.toLowerCase(), this.isSessionComplete(), this._model !== undefined),\n );\n }\n\n get model() {\n return this._model;\n }\n\n set session(s) {\n this._session = s;\n\n this.render();\n }\n\n get session() {\n return this._session;\n }\n\n isSessionComplete() {\n // a method to check if student answered the question\n return true;\n }\n\n onSessionChange(session) {\n // you can add an extra step here to validate session\n Object.keys(session).map((key) => {\n this._session[key] = session[key];\n });\n\n this.sessionChangedEventCaller();\n this.render();\n }\n\n connectedCallback() {\n // TODO set accessibility labels\n\n this.render();\n }\n\n render() {\n if (!this._model || !this._session) {\n return;\n }\n\n if (this._model && this._session) {\n const el = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onSessionChange: this.onSessionChange.bind(this),\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(el);\n }\n }\n\n disconnectedCallback() {\n if (this._root) {\n this._root.unmount();\n this._root = null;\n }\n }\n}\n"],"mappings":";;;;;AACA,IAAI,IAAI,MAAM,UAAU,YAAY;CACnC;EACC,KAAK,OAAO;CACb;CACA,YAAY,GAAG,GAAG,GAAG;EACpB,MAAM,EAAE,MAAM;GACb,SAAS,CAAC;GACV,UAAU,CAAC;GACX,QAAQ;IACP,UAAU;IACV,WAAW;IACX,UAAU;GACX;EACD,CAAC,GAAG,KAAK,YAAY,GAAG,KAAK,WAAW;CACzC;AACD,GAAG,IAAI,MAAM,UAAU,YAAY;CAClC;EACC,KAAK,OAAO;CACb;CACA,YAAY,GAAG,GAAG;EACjB,MAAM,EAAE,MAAM;GACb,SAAS,CAAC;GACV,UAAU,CAAC;GACX,QAAQ;IACP,UAAU;IACV,WAAW;GACZ;EACD,CAAC,GAAG,KAAK,YAAY,GAAG,KAAK,WAAW;CACzC;AACD,GCdqB,IAArB,cAA2C,YAAY;CACrD,cAAc;EAGZ,AAFA,MAAM,GACN,KAAK,QAAQ,MACb,KAAK,4BAA4B,QAAe;GAC9C,KAAK,cAAc,IAAI,EAAoB,KAAK,QAAQ,YAAY,GAAG,EAAI,CAAC;EAC9E,GAAG,GAAI;CACT;CAEA,IAAI,MAAM,GAAG;EAIX,AAHA,KAAK,SAAS,GAEd,KAAK,OAAO,GACZ,KAAK,cACH,IAAI,EAAc,KAAK,QAAQ,YAAY,GAAG,KAAK,kBAAkB,GAAG,KAAK,WAAW,KAAA,CAAS,CACnG;CACF;CAEA,IAAI,QAAQ;EACV,OAAO,KAAK;CACd;CAEA,IAAI,QAAQ,GAAG;EAGb,AAFA,KAAK,WAAW,GAEhB,KAAK,OAAO;CACd;CAEA,IAAI,UAAU;EACZ,OAAO,KAAK;CACd;CAEA,oBAAoB;EAElB,OAAO;CACT;CAEA,gBAAgB,GAAS;EAOvB,AALA,OAAO,KAAK,CAAO,CAAC,CAAC,KAAK,MAAQ;GAChC,KAAK,SAAS,KAAO,EAAQ;EAC/B,CAAC,GAED,KAAK,0BAA0B,GAC/B,KAAK,OAAO;CACd;CAEA,oBAAoB;EAGlB,KAAK,OAAO;CACd;CAEA,SAAS;EACH,OAAC,KAAK,UAAU,CAAC,KAAK,aAItB,KAAK,UAAU,KAAK,UAAU;GAChC,IAAM,IAAK,EAAM,cAAc,GAAM;IACnC,OAAO,KAAK;IACZ,SAAS,KAAK;IACd,iBAAiB,KAAK,gBAAgB,KAAK,IAAI;GACjD,CAAC;GAKD,AAHA,AACE,KAAK,UAAQ,EAAW,IAAI,GAE9B,KAAK,MAAM,OAAO,CAAE;EACtB;CACF;CAEA,uBAAuB;EACrB,AAEE,KAAK,WADL,KAAK,MAAM,QAAQ,GACN;CAEjB;AACF"}
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/math-templated/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 SessionChangedEvent,\n ModelSetEvent,\n createSessionNotifier,\n flushSessionNotifiers,\n} from '@pie-element/shared-player-events';\nimport Main from './main.js';\n\nexport default class MathTemplated extends HTMLElement {\n constructor() {\n super();\n this._root = null;\n // Session state is already written synchronously in `onSessionChange`; only\n // this dispatch is coalesced, and `disconnectedCallback` flushes it.\n this._sessionNotifier = createSessionNotifier(\n this,\n () => {\n this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), true));\n },\n { delayMs: 1000 },\n );\n this.sessionChangedEventCaller = () => this._sessionNotifier.notify();\n }\n\n set model(m) {\n this._model = m;\n\n this.render();\n this.dispatchEvent(\n new ModelSetEvent(this.tagName.toLowerCase(), this.isSessionComplete(), this._model !== undefined),\n );\n }\n\n get model() {\n return this._model;\n }\n\n set session(s) {\n this._session = s;\n\n this.render();\n }\n\n get session() {\n return this._session;\n }\n\n isSessionComplete() {\n // a method to check if student answered the question\n return true;\n }\n\n onSessionChange(session) {\n // you can add an extra step here to validate session\n Object.keys(session).map((key) => {\n this._session[key] = session[key];\n });\n\n this.sessionChangedEventCaller();\n this.render();\n }\n\n connectedCallback() {\n // TODO set accessibility labels\n\n this.render();\n }\n\n render() {\n if (!this._model || !this._session) {\n return;\n }\n\n if (this._model && this._session) {\n const el = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onSessionChange: this.onSessionChange.bind(this),\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(el);\n }\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,CAAC;GACT,EAAE,CAAC;EACJ;EACA,cAAc,CAAC;EACf,YAAY,CAAC;EACb,UAAU,CAAC;CACZ,CAAC;AACF;AACA,SAAS,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG;CACxB,IAAI,IAAI,EAAE,SAAS,IAAI,OAAO,KAAK,aAAa,UAAU,KAAK,GAAG,IAAI,EAAE,WAAW,IAAI,MAAM,IAAI,MAAM,IAAI,CAAC,GAAG,UAAU;EACxH,MAAM,SAAS,aAAa,CAAC,GAAG,IAAI,OAAO,MAAM,SAAS,aAAa,CAAC,GAAG,IAAI;CAChF,GAAG,UAAU;EACZ,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE;CACtB,GAAG,IAAI;EACN,SAAS;GACR,IAAI,CAAC,GAAG,MAAM,QAAQ,aAAa,CAAC,GAAG,IAAI,WAAW,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC,GAAG,MAAM,KAAK,KAAK,MA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