@pie-element/math-inline 13.0.2-next.20261007003844 → 13.0.2

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.
@@ -13,14 +13,15 @@ import { styled as w } from "@mui/material/styles";
13
13
  import T from "@mui/material/Tooltip";
14
14
  import { isEmpty as ee, isEqual as E } from "@pie-element/shared-lodash";
15
15
  import D from "react-dom";
16
+ import { sanitizeModelHtml as O } from "@pie-element/shared-utils";
16
17
  //#region src/delivery/main.tsx
17
- function O(e) {
18
+ function k(e) {
18
19
  return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
19
20
  }
20
- function k(e, t) {
21
- return !e || O(e) ? e : O(e.default) ? e.default : t && O(e[t]) ? e[t] : t && O(e[t]?.default) ? e[t].default : e;
21
+ function A(e, t) {
22
+ return !e || k(e) ? e : k(e.default) ? e.default : t && k(e[t]) ? e[t] : t && k(e[t]?.default) ? e[t].default : e;
22
23
  }
23
- var A = k(g, "UiLayout") || k(F.UiLayout, "UiLayout"), j = k(m, "PreviewPrompt") || k(F.PreviewPrompt, "PreviewPrompt"), te = k(h, "Readable") || k(F.Readable, "Readable"), M = k(f, "Collapsible") || k(F.Collapsible, "Collapsible"), ne = k(p, "Feedback") || k(F.Feedback, "Feedback"), N = d, P = N.default, F = P && typeof P == "object" ? P : N, { translator: I } = r, L = !1, R = /\\newline/g, z = /{{response}}/gm, re = 6, B = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
24
+ var j = A(g, "UiLayout") || A(I.UiLayout, "UiLayout"), M = A(m, "PreviewPrompt") || A(I.PreviewPrompt, "PreviewPrompt"), te = A(h, "Readable") || A(I.Readable, "Readable"), N = A(f, "Collapsible") || A(I.Collapsible, "Collapsible"), ne = A(p, "Feedback") || A(I.Feedback, "Feedback"), P = d, F = P.default, I = F && typeof F == "object" ? F : P, { translator: L } = r, R = !1, z = /\\newline/g, B = /{{response}}/gm, re = 6, V = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
24
25
  function ie(e = []) {
25
26
  return e.map((e) => ({
26
27
  name: e,
@@ -29,7 +30,7 @@ function ie(e = []) {
29
30
  label: e
30
31
  }));
31
32
  }
32
- function V(e, t) {
33
+ function H(e, t) {
33
34
  let n = e;
34
35
  for (; n !== null;) {
35
36
  if (t && n === t) return !0;
@@ -46,27 +47,27 @@ function oe(e, t) {
46
47
  let e = i;
47
48
  if (t.showCorrect) return a && a.length && a[0].answer;
48
49
  let n = 1;
49
- return (e || "").replace(z, function() {
50
+ return (e || "").replace(B, function() {
50
51
  let e = t.session.answers[`r${n}`];
51
52
  if (o && !s) {
52
53
  let e = "\\ \\ ".repeat(30) + "\\newline ";
53
54
  return `\\MathQuillMathField[r${n++}]{${e.repeat(3)}}`;
54
55
  }
55
56
  return r ? `\\embed{answerBlock}[r${n++}]` : `\\MathQuillMathField[r${n++}]{${e && e.value || ""}}`;
56
- }).replace(R, "\\embed{newLine}[]");
57
+ }).replace(z, "\\embed{newLine}[]");
57
58
  }
58
59
  }
59
- function H(e, t) {
60
+ function U(e, t) {
60
61
  let n = {};
61
62
  if (t.config && t.config.expression) {
62
63
  let r = 1;
63
- (t.config.expression || "").replace(z, () => {
64
+ (t.config.expression || "").replace(B, () => {
64
65
  n[`r${r}`] = { value: e && e.answers && e.answers[`r${r}`] && e.answers[`r${r}`].value || "" }, r += 1;
65
66
  });
66
67
  }
67
68
  return n;
68
69
  }
69
- var U = class extends n.Component {
70
+ var W = class extends n.Component {
70
71
  static propTypes = {
71
72
  session: i.object.isRequired,
72
73
  onSessionChange: i.func,
@@ -74,7 +75,7 @@ var U = class extends n.Component {
74
75
  };
75
76
  constructor(e) {
76
77
  super(e);
77
- let { model: t, session: r } = e, i = H(r, t);
78
+ let { model: t, session: r } = e, i = U(r, t);
78
79
  this.state = {
79
80
  session: {
80
81
  ...e.session,
@@ -86,8 +87,8 @@ var U = class extends n.Component {
86
87
  }, this.instructionsIdPrefix = v("math-inline-instructions");
87
88
  }
88
89
  UNSAFE_componentWillMount() {
89
- typeof window < "u" && (L ||= (l("answerBlock", (e) => {
90
- let t = W();
90
+ typeof window < "u" && (R ||= (l("answerBlock", (e) => {
91
+ let t = G();
91
92
  return {
92
93
  htmlString: `<div class="${t.blockContainer}">
93
94
  <div class="${t.blockResponse}" data-answer-block-index="${e}">R</div>
@@ -118,13 +119,13 @@ var U = class extends n.Component {
118
119
  let { config: t } = this.props.model, { config: n = {} } = e.model || {}, { session: r } = this.props, { session: i = {} } = e || {};
119
120
  if (r && i && !E(r.answers, i.answers) && this.setState({ session: {
120
121
  ...i,
121
- answers: H(i, this.props.model)
122
- } }), t.note && t.language && t.language !== n.language && t.note === I.t("mathInline.primaryCorrectWithAlternates", { lng: t.language }) && (t.note = I.t("mathInline.primaryCorrectWithAlternates", { lng: n.language })), (t.env && t.env.mode !== "evaluate" || n.env && n.env.mode !== "evaluate") && this.setState({
122
+ answers: U(i, this.props.model)
123
+ } }), t.note && t.language && t.language !== n.language && t.note === L.t("mathInline.primaryCorrectWithAlternates", { lng: t.language }) && (t.note = L.t("mathInline.primaryCorrectWithAlternates", { lng: n.language })), (t.env && t.env.mode !== "evaluate" || n.env && n.env.mode !== "evaluate") && this.setState({
123
124
  ...this.state.session,
124
125
  showCorrect: !1
125
126
  }), n.alwaysShowCorrect && this.setState({ showCorrect: !0 }), this.countResponseOccurrences(t.expression) < this.countResponseOccurrences(n.expression) && setTimeout(() => this.updateAria(), 100), t && t.responses && t.responses.length !== n.responses.length || !t && n && n.responses || t && n && t.expression !== n.expression) {
126
127
  let e = {}, t = this.state.session.answers, r = 1;
127
- (n.expression || "").replace(z, () => {
128
+ (n.expression || "").replace(B, () => {
128
129
  e[`r${r}`] = { value: t && t[`r${r}`] && t[`r${r}`].value || "" }, r++;
129
130
  }), this.setState((t) => ({ session: {
130
131
  ...t.session,
@@ -146,7 +147,7 @@ var U = class extends n.Component {
146
147
  updateAria = () => {
147
148
  if (this.root) {
148
149
  this.root.querySelectorAll(".mq-selectable").forEach((e) => e.setAttribute("aria-hidden", "true"));
149
- let e = I.t("mathInline.keypadInstructions", { lng: this.props.model?.language });
150
+ let e = L.t("mathInline.keypadInstructions", { lng: this.props.model?.language });
150
151
  this.root.querySelectorAll("textarea").forEach((t, n) => {
151
152
  let r = `${this.instructionsIdPrefix}-${n}`, i = t.closest(".mq-textarea");
152
153
  if (i) {
@@ -166,7 +167,7 @@ var U = class extends n.Component {
166
167
  }, 0);
167
168
  };
168
169
  handleKeyDown = (e, t) => {
169
- let n = V(e.target, this.root), r = this.mqStatic && this.mqStatic.inputRef?.current ? this.mqStatic.inputRef?.current.contains(document.activeElement) : !!document.activeElement?.closest(".mq-editable-field"), { key: i, type: a } = e;
170
+ let n = H(e.target, this.root), r = this.mqStatic && this.mqStatic.inputRef?.current ? this.mqStatic.inputRef?.current.contains(document.activeElement) : !!document.activeElement?.closest(".mq-editable-field"), { key: i, type: a } = e;
170
171
  r && (i === "ArrowDown" || a === "click" || a === "touchstart") ? this.state.activeAnswerBlock !== t && n && (this.cleanupKeyDownListener(), this.setState({ activeAnswerBlock: t }, () => {
171
172
  this.onSubFieldFocus(t), i === "ArrowDown" && this.focusFirstKeypadElement();
172
173
  })) : e.key === "Escape" && this.setState({ activeAnswerBlock: "" });
@@ -259,7 +260,7 @@ var U = class extends n.Component {
259
260
  };
260
261
  setTooltipRef(e) {
261
262
  setTimeout(() => {
262
- if (e && B) {
263
+ if (e && V) {
263
264
  let e = document.querySelector("[role='tooltip']");
264
265
  e && e.firstChild.setAttribute("tabindex", "-1");
265
266
  }
@@ -268,45 +269,45 @@ var U = class extends n.Component {
268
269
  render() {
269
270
  let { model: n } = this.props, { activeAnswerBlock: r, showCorrect: i, session: a, tooltipContainerRef: s } = this.state, { config: l, correctness: u, disabled: d, extraCSSRules: f, view: p, teacherInstructions: m, rationale: h, feedback: g, animationsDisabled: v, printMode: C, alwaysShowCorrect: w, language: E } = n || {};
270
271
  if (!l) return null;
271
- let { showNote: O, note: k, prompt: A, responses: N, responseType: P, equationEditor: F, customKeys: L, env: { mode: R, role: z } = {} } = l || {}, B = (i || R === "view" && z === "instructor") && O && k, V = ee(N), H = !V && u && u.correctness !== "correct", U = d && u, W = ie(L), J = u && u.correct, Y = oe(n, this.state) || "", X = d && !u, ge = C && !w, Z = h && (b(h) || y(h)), Q = m && (b(m) || y(m)), _e = /* @__PURE__ */ x(pe, { children: /* @__PURE__ */ x(c.Static, {
272
+ let { showNote: k, note: A, prompt: j, responses: P, responseType: F, equationEditor: I, customKeys: R, env: { mode: z, role: B } = {} } = l || {}, V = (i || z === "view" && B === "instructor") && k && A, H = ee(P), U = !H && u && u.correctness !== "correct", W = d && u, G = ie(R), Y = u && u.correct, X = oe(n, this.state) || "", Z = d && !u, ge = C && !w, Q = h && (b(h) || y(h)), $ = m && (b(m) || y(m)), _e = /* @__PURE__ */ x(pe, { children: /* @__PURE__ */ x(c.Static, {
272
273
  className: "static-math",
273
274
  ref: (e) => {
274
275
  e && (this.mqStatic = e);
275
276
  },
276
- latex: Y,
277
+ latex: X,
277
278
  language: E,
278
279
  onSubFieldChange: this.subFieldChanged,
279
280
  getFieldName: this.getFieldName,
280
281
  setInput: this.setInput,
281
282
  onSubFieldFocus: this.onSubFieldFocus,
282
283
  onBlur: this.onBlur
283
- }) }), $ = /* @__PURE__ */ S(K, { children: [
284
- R === "gather" && /* @__PURE__ */ x(me, { children: I.t("mathInline.mathEquationResponseQuestion", { lng: E }) }),
285
- X && Q && (v ? /* @__PURE__ */ x("div", { dangerouslySetInnerHTML: { __html: m } }) : /* @__PURE__ */ x(q, {
284
+ }) }), ve = /* @__PURE__ */ S(q, { children: [
285
+ z === "gather" && /* @__PURE__ */ x(me, { children: L.t("mathInline.mathEquationResponseQuestion", { lng: E }) }),
286
+ Z && $ && (v ? /* @__PURE__ */ x("div", { dangerouslySetInnerHTML: { __html: O(m) } }) : /* @__PURE__ */ x(J, {
286
287
  labels: {
287
- hidden: I.t("common:showTeacherInstructions", { lng: E }),
288
- visible: I.t("common:hideTeacherInstructions", { lng: E })
288
+ hidden: L.t("common:showTeacherInstructions", { lng: E }),
289
+ visible: L.t("common:hideTeacherInstructions", { lng: E })
289
290
  },
290
- children: /* @__PURE__ */ x("div", { dangerouslySetInnerHTML: { __html: m } })
291
+ children: /* @__PURE__ */ x("div", { dangerouslySetInnerHTML: { __html: O(m) } })
291
292
  })),
292
- A && /* @__PURE__ */ x(ce, { children: /* @__PURE__ */ x(j, { prompt: A }) }),
293
+ j && /* @__PURE__ */ x(ce, { children: /* @__PURE__ */ x(M, { prompt: j }) }),
293
294
  ge ? _e : /* @__PURE__ */ x(te, {
294
295
  false: !0,
295
296
  children: /* @__PURE__ */ S(fe, {
296
297
  tabIndex: 0,
297
- children: [P === e.simple && /* @__PURE__ */ x(t, {
298
+ children: [F === e.simple && /* @__PURE__ */ x(t, {
298
299
  onSimpleResponseChange: this.onSimpleResponseChange,
299
300
  showCorrect: i,
300
- emptyResponse: V,
301
+ emptyResponse: H,
301
302
  model: n,
302
303
  session: a,
303
304
  onSubFieldFocus: this.onSubFieldFocus,
304
305
  showKeypad: !!r
305
- }), P === e.advanced && /* @__PURE__ */ x(de, {
306
+ }), F === e.advanced && /* @__PURE__ */ x(de, {
306
307
  ref: s,
307
- isIncorrect: !V && !J && !i,
308
- isCorrect: !V && (J || i),
309
- showCorrectness: !V && d && u && !p,
308
+ isIncorrect: !H && !Y && !i,
309
+ isCorrect: !H && (Y || i),
310
+ showCorrectness: !H && d && u && !p,
310
311
  correctAnswerShown: i,
311
312
  printCorrect: C && w,
312
313
  children: /* @__PURE__ */ x(T, {
@@ -361,10 +362,10 @@ var U = class extends n.Component {
361
362
  },
362
363
  title: Object.keys(a.answers).map((e) => e === r && !(i || d) && /* @__PURE__ */ x(ue, {
363
364
  "data-keypad": !0,
364
- style: { width: ae(W, F) },
365
+ style: { width: ae(G, I) },
365
366
  children: /* @__PURE__ */ x(o, {
366
- additionalKeys: W,
367
- mode: F || re,
367
+ additionalKeys: G,
368
+ mode: I || re,
368
369
  onClick: this.onClick
369
370
  })
370
371
  }, e) || null),
@@ -373,7 +374,7 @@ var U = class extends n.Component {
373
374
  ref: (e) => {
374
375
  e && (this.mqStatic = e);
375
376
  },
376
- latex: Y,
377
+ latex: X,
377
378
  language: E,
378
379
  onSubFieldChange: this.subFieldChanged,
379
380
  getFieldName: this.getFieldName,
@@ -385,16 +386,16 @@ var U = class extends n.Component {
385
386
  })]
386
387
  })
387
388
  }),
388
- X && B && /* @__PURE__ */ x(le, { dangerouslySetInnerHTML: { __html: `<strong>Note:</strong> ${k}` } }),
389
- X && Z && (v ? /* @__PURE__ */ x("div", { dangerouslySetInnerHTML: { __html: h } }) : /* @__PURE__ */ x(M, {
389
+ Z && V && /* @__PURE__ */ x(le, { dangerouslySetInnerHTML: { __html: `<strong>Note:</strong> ${O(A)}` } }),
390
+ Z && Q && (v ? /* @__PURE__ */ x("div", { dangerouslySetInnerHTML: { __html: O(h) } }) : /* @__PURE__ */ x(N, {
390
391
  labels: {
391
- hidden: I.t("common:showRationale", { lng: E }),
392
- visible: I.t("common:hideRationale", { lng: E })
392
+ hidden: L.t("common:showRationale", { lng: E }),
393
+ visible: L.t("common:hideRationale", { lng: E })
393
394
  },
394
- children: /* @__PURE__ */ x("div", { dangerouslySetInnerHTML: { __html: h } })
395
+ children: /* @__PURE__ */ x("div", { dangerouslySetInnerHTML: { __html: O(h) } })
395
396
  }))
396
397
  ] });
397
- return U && (H || Q || Z || g) ? /* @__PURE__ */ x(G, {
398
+ return W && (U || $ || Q || g) ? /* @__PURE__ */ x(K, {
398
399
  extraCSSRules: f,
399
400
  ref: (e) => {
400
401
  let t = D.findDOMNode(e);
@@ -422,50 +423,50 @@ var U = class extends n.Component {
422
423
  }
423
424
  },
424
425
  title: /* @__PURE__ */ S("div", { children: [
425
- /* @__PURE__ */ x(K, { children: H && /* @__PURE__ */ x(he, {
426
+ /* @__PURE__ */ x(q, { children: U && /* @__PURE__ */ x(he, {
426
427
  language: E,
427
428
  show: !0,
428
429
  toggled: i,
429
430
  onToggle: this.toggleShowCorrect
430
431
  }) }),
431
- Q && /* @__PURE__ */ x(q, {
432
+ $ && /* @__PURE__ */ x(J, {
432
433
  labels: {
433
- hidden: I.t("common:showTeacherInstructions", { lng: E }),
434
- visible: I.t("common:hideTeacherInstructions", { lng: E })
434
+ hidden: L.t("common:showTeacherInstructions", { lng: E }),
435
+ visible: L.t("common:hideTeacherInstructions", { lng: E })
435
436
  },
436
- children: /* @__PURE__ */ x(j, { prompt: m })
437
+ children: /* @__PURE__ */ x(M, { prompt: m })
437
438
  }, "collapsible-teacher-instructions"),
438
- B && b(k) && /* @__PURE__ */ x(q, {
439
+ V && b(A) && /* @__PURE__ */ x(J, {
439
440
  labels: {
440
- hidden: I.t("common:showNote", { lng: E }),
441
- visible: I.t("common:hideNote", { lng: E })
441
+ hidden: L.t("common:showNote", { lng: E }),
442
+ visible: L.t("common:hideNote", { lng: E })
442
443
  },
443
- children: /* @__PURE__ */ x(j, { prompt: k })
444
+ children: /* @__PURE__ */ x(M, { prompt: A })
444
445
  }, "collapsible-note"),
445
- Z && /* @__PURE__ */ x(q, {
446
+ Q && /* @__PURE__ */ x(J, {
446
447
  labels: {
447
- hidden: I.t("common:showRationale", { lng: E }),
448
- visible: I.t("common:hideRationale", { lng: E })
448
+ hidden: L.t("common:showRationale", { lng: E }),
449
+ visible: L.t("common:hideRationale", { lng: E })
449
450
  },
450
- children: /* @__PURE__ */ x(j, { prompt: h })
451
+ children: /* @__PURE__ */ x(M, { prompt: h })
451
452
  }, "collapsible-rationale"),
452
453
  g && /* @__PURE__ */ x(ne, {
453
454
  correctness: u.correctness,
454
455
  feedback: g
455
456
  })
456
457
  ] }),
457
- children: $
458
+ children: ve
458
459
  })
459
- }) : /* @__PURE__ */ x(G, {
460
+ }) : /* @__PURE__ */ x(K, {
460
461
  extraCSSRules: f,
461
462
  ref: (e) => {
462
463
  let t = D.findDOMNode(e);
463
464
  this.root = t || this.root;
464
465
  },
465
- children: $
466
+ children: ve
466
467
  });
467
468
  }
468
- }, W = () => ({
469
+ }, G = () => ({
469
470
  blockContainer: "block-container",
470
471
  blockResponse: "block-response",
471
472
  blockMath: "block-math"
@@ -519,16 +520,16 @@ if (typeof document < "u") {
519
520
  `, document.head.appendChild(t);
520
521
  }
521
522
  }
522
- var G = w(A)(() => ({
523
+ var K = w(j)(() => ({
523
524
  color: _.text(),
524
525
  backgroundColor: _.background(),
525
526
  display: "inline-block"
526
- })), se = w(T)({}), ce = w("div")(({ theme: e }) => ({ marginBottom: e.spacing(2) })), K = w("div")({
527
+ })), se = w(T)({}), ce = w("div")(({ theme: e }) => ({ marginBottom: e.spacing(2) })), q = w("div")({
527
528
  width: "100%",
528
529
  position: "relative",
529
530
  backgroundColor: _.background(),
530
531
  color: _.text()
531
- }), le = w("div")(({ theme: e }) => ({ paddingBottom: e.spacing(2) })), q = w(M)(({ theme: e }) => ({ marginBottom: e.spacing(2) })), ue = w("div")(({ theme: e }) => ({
532
+ }), le = w("div")(({ theme: e }) => ({ paddingBottom: e.spacing(2) })), J = w(N)(({ theme: e }) => ({ marginBottom: e.spacing(2) })), ue = w("div")(({ theme: e }) => ({
532
533
  zIndex: 10,
533
534
  minWidth: "400px",
534
535
  marginTop: e.spacing(2)
@@ -607,4 +608,4 @@ var G = w(A)(() => ({
607
608
  marginBottom: e.spacing(2)
608
609
  }));
609
610
  //#endregion
610
- export { U as Main, U as default };
611
+ export { W as Main, W as default };