@pie-element/select-text 13.4.0-beta.7 → 14.0.0-next.20261002094057

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.
Files changed (106) hide show
  1. package/README.md +29 -3
  2. package/author.js +2 -0
  3. package/configure.js +2 -0
  4. package/controller.js +1 -0
  5. package/dist/author/defaultConfiguration.d.ts +179 -0
  6. package/dist/author/defaultConfiguration.js +141 -0
  7. package/dist/author/design.d.ts +38 -0
  8. package/dist/author/design.js +263 -0
  9. package/dist/author/index.d.ts +27 -0
  10. package/dist/author/index.js +74 -0
  11. package/dist/author/utils.d.ts +10 -0
  12. package/dist/author/utils.js +50 -0
  13. package/dist/browser/Check-Ci4LDjFB.js +9399 -0
  14. package/dist/browser/Check-Ci4LDjFB.js.map +1 -0
  15. package/dist/browser/assets/Symbola-4c507403.woff2 +0 -0
  16. package/dist/browser/author/index.js +36509 -0
  17. package/dist/browser/author/index.js.map +1 -0
  18. package/dist/browser/controller/index.js +194 -0
  19. package/dist/browser/controller/index.js.map +1 -0
  20. package/dist/browser/delivery/index.js +89 -0
  21. package/dist/browser/delivery/index.js.map +1 -0
  22. package/dist/browser/dist-BamN0-DG.js +323 -0
  23. package/dist/browser/dist-BamN0-DG.js.map +1 -0
  24. package/dist/browser/editor-runtime/Check-YttKR25j.js +9399 -0
  25. package/dist/browser/editor-runtime/Check-YttKR25j.js.map +1 -0
  26. package/dist/browser/editor-runtime/assets/Symbola-4c507403.woff2 +0 -0
  27. package/dist/browser/editor-runtime/author/index.js +20100 -0
  28. package/dist/browser/editor-runtime/author/index.js.map +1 -0
  29. package/dist/browser/editor-runtime/controller/index.js +194 -0
  30. package/dist/browser/editor-runtime/controller/index.js.map +1 -0
  31. package/dist/browser/editor-runtime/delivery/index.js +89 -0
  32. package/dist/browser/editor-runtime/delivery/index.js.map +1 -0
  33. package/dist/browser/editor-runtime/dist-CMfXI_t0.js +323 -0
  34. package/dist/browser/editor-runtime/dist-CMfXI_t0.js.map +1 -0
  35. package/dist/browser/editor-runtime/main-DkSwljhi.js +4914 -0
  36. package/dist/browser/editor-runtime/main-DkSwljhi.js.map +1 -0
  37. package/dist/browser/editor-runtime/print/index.js +43 -0
  38. package/dist/browser/editor-runtime/print/index.js.map +1 -0
  39. package/dist/browser/main-KepLpD8x.js +4914 -0
  40. package/dist/browser/main-KepLpD8x.js.map +1 -0
  41. package/dist/browser/print/index.js +43 -0
  42. package/dist/browser/print/index.js.map +1 -0
  43. package/dist/controller/defaults.d.ts +27 -0
  44. package/dist/controller/defaults.js +21 -0
  45. package/dist/controller/index.d.ts +25 -0
  46. package/dist/controller/index.js +121 -0
  47. package/dist/delivery/index.d.ts +19 -0
  48. package/dist/delivery/index.js +60 -0
  49. package/dist/delivery/main.d.ts +36 -0
  50. package/dist/delivery/main.js +145 -0
  51. package/dist/delivery/utils.d.ts +10 -0
  52. package/dist/delivery/utils.js +47 -0
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.iife.d.ts +8 -0
  55. package/dist/index.iife.js +167 -0
  56. package/dist/index.js +2 -0
  57. package/dist/print/index.d.ts +15 -0
  58. package/dist/print/index.js +43 -0
  59. package/dist/runtime-support.d.ts +12 -0
  60. package/dist/runtime-support.js +12 -0
  61. package/module/print.js +20364 -0
  62. package/module/print.js.map +1 -0
  63. package/package.json +108 -22
  64. package/print.js +2 -0
  65. package/CHANGELOG.json +0 -1422
  66. package/CHANGELOG.md +0 -2332
  67. package/LICENSE.md +0 -5
  68. package/configure/CHANGELOG.json +0 -1032
  69. package/configure/CHANGELOG.md +0 -2066
  70. package/configure/lib/__tests__/design.test.js +0 -173
  71. package/configure/lib/defaultConfiguration.js +0 -177
  72. package/configure/lib/defaultConfiguration.js.map +0 -1
  73. package/configure/lib/design.js +0 -406
  74. package/configure/lib/design.js.map +0 -1
  75. package/configure/lib/index.js +0 -129
  76. package/configure/lib/index.js.map +0 -1
  77. package/configure/lib/utils.js +0 -92
  78. package/configure/lib/utils.js.map +0 -1
  79. package/configure/package.json +0 -25
  80. package/controller/CHANGELOG.json +0 -442
  81. package/controller/CHANGELOG.md +0 -1510
  82. package/controller/lib/__tests__/index.test.js +0 -627
  83. package/controller/lib/defaults.js +0 -25
  84. package/controller/lib/defaults.js.map +0 -1
  85. package/controller/lib/index.js +0 -258
  86. package/controller/lib/index.js.map +0 -1
  87. package/controller/package.json +0 -16
  88. package/docs/config-schema.json +0 -2135
  89. package/docs/config-schema.json.md +0 -1579
  90. package/docs/demo/config.js +0 -8
  91. package/docs/demo/generate.js +0 -823
  92. package/docs/demo/index.html +0 -1
  93. package/docs/demo/pie.manifest.json +0 -11
  94. package/docs/demo/session.js +0 -24
  95. package/docs/pie-schema.json +0 -1248
  96. package/docs/pie-schema.json.md +0 -711
  97. package/lib/__tests__/index.test.js +0 -86
  98. package/lib/__tests__/main.test.js +0 -89
  99. package/lib/index.js +0 -104
  100. package/lib/index.js.map +0 -1
  101. package/lib/main.js +0 -203
  102. package/lib/main.js.map +0 -1
  103. package/lib/print.js +0 -87
  104. package/lib/print.js.map +0 -1
  105. package/lib/utils.js +0 -80
  106. package/lib/utils.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { b as e, c as t, g as n } from "../dist-BamN0-DG.js";
2
+ import { w as r } from "../Check-Ci4LDjFB.js";
3
+ import { t as i } from "../main-KepLpD8x.js";
4
+ import a from "react";
5
+ import { createRoot as o } from "react-dom/client";
6
+ var s = (0, (/* @__PURE__ */ e(n(), 1)).default)("pie-element:select-text:print"), c = (e, t) => {
7
+ let n = t.role === "instructor";
8
+ return e.prompt = e.promptEnabled === !1 ? void 0 : e.prompt, e.teacherInstructions = n && e.teacherInstructionsEnabled !== !1 ? e.teacherInstructions : void 0, e.rationale = n && e.rationaleEnabled !== !1 ? e.rationale : void 0, e.showTeacherInstructions = n, e.alwaysShowCorrect = n, e.mode = n ? "evaluate" : e.mode, e.disabled = !0, e.animationsDisabled = !0, e.highlightChoices = !0, e.feedback = void 0, e;
9
+ }, l = class extends HTMLElement {
10
+ constructor() {
11
+ super(), this._options = null, this._model = null, this._session = {}, this._session.selectedTokens = [], this._root = null, this._rerender = t(() => {
12
+ if (this._model && this._session) {
13
+ let e = c(this._model, this._options), t = this._options && a.createElement(i, {
14
+ model: e,
15
+ session: { selectedTokens: [] },
16
+ onSelectionChange: () => {}
17
+ });
18
+ this._root ||= o(this), this._root.render(t), queueMicrotask(() => {
19
+ s("render complete - render math"), r(this);
20
+ });
21
+ } else s("skip");
22
+ }, 50, {
23
+ leading: !1,
24
+ trailing: !0
25
+ });
26
+ }
27
+ set options(e) {
28
+ this._options = e;
29
+ }
30
+ set model(e) {
31
+ this._model = e, this._rerender();
32
+ }
33
+ connectedCallback() {
34
+ this._rerender();
35
+ }
36
+ disconnectedCallback() {
37
+ this._rerender.cancel(), this._root &&= (this._root.unmount(), null);
38
+ }
39
+ };
40
+ //#endregion
41
+ export { l as default };
42
+
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/print/index.tsx"],"sourcesContent":["// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/select-text/src/print.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 { debounce } from '@pie-element/shared-lodash';\nimport Main from '../delivery/main.js';\nimport { renderMath } from '@pie-element/shared-math-rendering-mathjax';\nimport debug from 'debug';\n\nconst log = debug('pie-element:select-text:print');\n\n/**\n * Live in same package as main element - so we can access some of the shared comps!\n *\n * - update pslb to build print if src/print.js is there\n * - update demo el\n * - get configure/controller building\n */\n\nconst preparePrintModel = (model, opts) => {\n const instr = opts.role === 'instructor';\n\n model.prompt = model.promptEnabled !== false ? model.prompt : undefined;\n model.teacherInstructions =\n instr && model.teacherInstructionsEnabled !== false ? model.teacherInstructions : undefined;\n model.rationale = instr && model.rationaleEnabled !== false ? model.rationale : undefined;\n model.showTeacherInstructions = instr;\n model.alwaysShowCorrect = instr;\n model.mode = instr ? 'evaluate' : model.mode;\n\n model.disabled = true;\n model.animationsDisabled = true;\n model.highlightChoices = true;\n model.feedback = undefined;\n\n return model;\n};\n\nexport default class SelectTextPrint extends HTMLElement {\n constructor() {\n super();\n this._options = null;\n this._model = null;\n this._session = {};\n this._session.selectedTokens = [];\n this._root = null;\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n const printModel = preparePrintModel(this._model, this._options);\n\n const element =\n this._options &&\n React.createElement(Main, {\n model: printModel,\n session: { selectedTokens: [] },\n onSelectionChange: () => {},\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n queueMicrotask(() => {\n log('render complete - render math');\n renderMath(this);\n });\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n set options(o) {\n this._options = o;\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n }\n\n connectedCallback() {\n // Disconnecting unmounts the React root, so a reinserted element renders again.\n this._rerender();\n }\n\n disconnectedCallback() {\n this._rerender.cancel();\n if (this._root) {\n this._root.unmount();\n this._root = null;\n }\n }\n}\n"],"mappings":";;;;;AAiBA,IAAM,KAAA,IAAA,wBAAA,EAAA,CAAA,QAAA,CAAY,+BAA+B,GAU3C,KAAqB,GAAO,MAAS;CACzC,IAAM,IAAQ,EAAK,SAAS;CAe5B,OAbA,EAAM,SAAS,EAAM,kBAAkB,KAAuB,KAAA,IAAf,EAAM,QACrD,EAAM,sBACJ,KAAS,EAAM,+BAA+B,KAAQ,EAAM,sBAAsB,KAAA,GACpF,EAAM,YAAY,KAAS,EAAM,qBAAqB,KAAQ,EAAM,YAAY,KAAA,GAChF,EAAM,0BAA0B,GAChC,EAAM,oBAAoB,GAC1B,EAAM,OAAO,IAAQ,aAAa,EAAM,MAExC,EAAM,WAAW,IACjB,EAAM,qBAAqB,IAC3B,EAAM,mBAAmB,IACzB,EAAM,WAAW,KAAA,GAEV;AACT,GAEqB,IAArB,cAA6C,YAAY;CACvD,cAAc;EAOZ,AANA,MAAM,GACN,KAAK,WAAW,MAChB,KAAK,SAAS,MACd,KAAK,WAAW,CAAC,GACjB,KAAK,SAAS,iBAAiB,CAAC,GAChC,KAAK,QAAQ,MACb,KAAK,YAAY,QACT;GACJ,IAAI,KAAK,UAAU,KAAK,UAAU;IAChC,IAAM,IAAa,EAAkB,KAAK,QAAQ,KAAK,QAAQ,GAEzD,IACJ,KAAK,YACL,EAAM,cAAc,GAAM;KACxB,OAAO;KACP,SAAS,EAAE,gBAAgB,CAAC,EAAE;KAC9B,yBAAyB,CAAC;IAC5B,CAAC;IAMH,AAJA,AACE,KAAK,UAAQ,EAAW,IAAI,GAE9B,KAAK,MAAM,OAAO,CAAO,GACzB,qBAAqB;KAEnB,AADA,EAAI,+BAA+B,GACnC,EAAW,IAAI;IACjB,CAAC;GACH,OACE,EAAI,MAAM;EAEd,GACA,IACA;GAAE,SAAS;GAAO,UAAU;EAAK,CACnC;CACF;CACA,IAAI,QAAQ,GAAG;EACb,KAAK,WAAW;CAClB;CAEA,IAAI,MAAM,GAAG;EAEX,AADA,KAAK,SAAS,GACd,KAAK,UAAU;CACjB;CAEA,oBAAoB;EAElB,KAAK,UAAU;CACjB;CAEA,uBAAuB;EAErB,AADA,KAAK,UAAU,OAAO,GACtB,AAEE,KAAK,WADL,KAAK,MAAM,QAAQ,GACN;CAEjB;AACF"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/select-text/controller/src/defaults.js
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ declare const _default: {
10
+ feedbackEnabled: boolean;
11
+ highlightChoices: boolean;
12
+ maxSelections: number;
13
+ mode: string;
14
+ partialScoring: boolean;
15
+ prompt: string;
16
+ promptEnabled: boolean;
17
+ rationale: string;
18
+ rationaleEnabled: boolean;
19
+ scoringType: string;
20
+ studentInstructionsEnabled: boolean;
21
+ teacherInstructions: string;
22
+ teacherInstructionsEnabled: boolean;
23
+ text: string;
24
+ tokens: never[];
25
+ toolbarEditorPosition: string;
26
+ };
27
+ export default _default;
@@ -0,0 +1,21 @@
1
+ //#region src/controller/defaults.ts
2
+ var e = {
3
+ feedbackEnabled: !1,
4
+ highlightChoices: !1,
5
+ maxSelections: 0,
6
+ mode: "sentence",
7
+ partialScoring: !1,
8
+ prompt: "",
9
+ promptEnabled: !0,
10
+ rationale: "",
11
+ rationaleEnabled: !0,
12
+ scoringType: "auto",
13
+ studentInstructionsEnabled: !0,
14
+ teacherInstructions: "",
15
+ teacherInstructionsEnabled: !0,
16
+ text: "",
17
+ tokens: [],
18
+ toolbarEditorPosition: "bottom"
19
+ };
20
+ //#endregion
21
+ export { e as default };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/select-text/controller/src/index.js
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ export declare const getCorrectness: (tokens: any, selected: any) => "unknown" | "correct" | "partially-correct" | "incorrect";
10
+ export declare const getPartialScore: (question: any, session: any, totalCorrect: any) => number;
11
+ /**
12
+ * Generates detailed trace log for select-text scoring evaluation
13
+ * @param {Object} question - the question model
14
+ * @param {Object} session - the student session
15
+ * @param {Object} env - the environment
16
+ * @returns {Array<string>} traceLog
17
+ */
18
+ export declare const getLogTrace: (question: any, session: any, env: any) => string[];
19
+ export declare const outcome: (question: any, session: any, env: any) => Promise<unknown>;
20
+ export declare function createDefaultModel(model?: {}): Promise<unknown>;
21
+ export declare const normalizeSession: (session: any) => any;
22
+ export declare const normalize: (question: any) => any;
23
+ export declare const model: (question: any, session: any, env: any) => Promise<unknown>;
24
+ export declare const createCorrectResponseSession: (question: any, env: any) => Promise<unknown>;
25
+ export declare const validate: (model?: {}, config?: {}) => {};
@@ -0,0 +1,121 @@
1
+ import e from "./defaults.js";
2
+ import t from "debug";
3
+ import { isEmpty as n } from "@pie-element/shared-lodash";
4
+ import { getFeedbackForCorrectness as r } from "@pie-element/shared-feedback";
5
+ import { partialScoring as i } from "@pie-element/shared-controller-utils";
6
+ //#region src/controller/index.ts
7
+ var a = t("@pie-element:select-text:controller"), o = (e = {}, t = {}) => e?.start === t?.start && e?.end === t?.end || e?.start === t?.oldStart && e?.end === t?.oldEnd, s = (e = [], t = [], n = !1) => (e || []).map((e) => {
8
+ let r = !!e.correct, i = r && !(t || []).find((t) => o(e, t));
9
+ return {
10
+ ...e,
11
+ correct: n ? r : void 0,
12
+ isMissing: n ? i : void 0
13
+ };
14
+ }), c = (e, t) => {
15
+ let n = e.filter((e) => e.correct === !0);
16
+ if (n.length === 0) return "unknown";
17
+ let r = l(e, t);
18
+ if (r.length === t.length) {
19
+ if (r.length === n.length) return "correct";
20
+ if (r.length > 0) return "partially-correct";
21
+ }
22
+ return r.length > 0 ? "partially-correct" : "incorrect";
23
+ }, l = (e, t) => (t || []).filter((t) => e.findIndex((e) => e.correct && o(e, t)) !== -1), u = (e, t, r) => {
24
+ if (!t || n(t)) return 0;
25
+ let i = l(e.tokens, t.selectedTokens).length, a = (e.tokens || []).filter((e) => e.correct === !0), o = i - (t.selectedTokens && t.selectedTokens.length > a.length ? t.selectedTokens && t.selectedTokens.length - i : 0), s = o < 0 ? 0 : o;
26
+ return r.length ? parseFloat((s / r.length).toFixed(2)) : 0;
27
+ }, d = (e, t, n) => {
28
+ let r = [], a = t?.selectedTokens || [], s = e?.tokens || [];
29
+ if (a.length === 0) return r.push("Student did not select any token."), r;
30
+ r.push(`Student selected ${a.length} token(s).`);
31
+ let c = 0, l = 0, d = 0;
32
+ for (let e = 0; e < s.length; e++) {
33
+ let t = s[e];
34
+ t.correct && (c++, a.some((e) => o(t, e)) ? l++ : d++);
35
+ }
36
+ let f = a.length - l;
37
+ l > 0 && r.push(`${l} correct token(s) selected.`), f > 0 && r.push(`${f} incorrect token(s) selected.`), d > 0 && r.push(`${d} required correct token(s) were not selected.`);
38
+ let p = i.enabled(e, n, !0);
39
+ p ? (r.push("Score calculated using partial scoring."), r.push("Score is based on the number of correct minus incorrect selections, divided by the total number of correct tokens."), f > 0 && a.length > c && r.push("Extra selected tokens beyond the correct set reduce the score.")) : (r.push("Score calculated using all-or-nothing scoring."), r.push("Student must select all correct tokens and no incorrect tokens to receive full credit."));
40
+ let m = u(e, t, s.filter((e) => e.correct)), h = p ? m : +(m === 1);
41
+ return r.push(`Final score: ${h}.`), r;
42
+ }, f = (e, t, r) => new Promise((a) => {
43
+ if ((!t || n(t)) && a({
44
+ score: 0,
45
+ empty: !0,
46
+ logTrace: ["Student did not select any token."]
47
+ }), t = m(t), r.mode !== "evaluate") a({
48
+ score: void 0,
49
+ completed: void 0,
50
+ logTrace: []
51
+ });
52
+ else {
53
+ let n = i.enabled(e, r, !0), o = e.tokens.filter((e) => e.correct), s = u(e, t, o);
54
+ a({
55
+ score: n ? s : +(s === 1),
56
+ logTrace: d(e, t, r)
57
+ });
58
+ }
59
+ });
60
+ function p(t = {}) {
61
+ return new Promise((n) => {
62
+ n({
63
+ ...e,
64
+ ...t
65
+ });
66
+ });
67
+ }
68
+ var m = (e) => ({
69
+ selectedTokens: [],
70
+ ...e
71
+ }), h = (t) => ({
72
+ ...e,
73
+ ...t
74
+ }), g = (e, t, n) => {
75
+ t ||= { selectedToken: [] }, t.selectedTokens = t.selectedTokens || [];
76
+ let i = h(e);
77
+ return new Promise((e) => {
78
+ a("[model]", "normalizedQuestion: ", i), a("[model]", "session: ", t);
79
+ let o = s(i.tokens, t.selectedTokens, n.mode === "evaluate");
80
+ a("[model] tokens:", o);
81
+ let l = n.mode === "evaluate" ? c(i.tokens, t.selectedTokens) : void 0;
82
+ (n.mode === "evaluate" && i.feedbackEnabled ? r(l, i.feedback) : Promise.resolve(void 0)).then((t) => {
83
+ let r = {
84
+ tokens: o,
85
+ highlightChoices: i.highlightChoices,
86
+ prompt: i.promptEnabled ? i.prompt : null,
87
+ text: i.text,
88
+ disabled: n.mode !== "gather",
89
+ maxSelections: i.maxSelections,
90
+ correctness: l,
91
+ env: n,
92
+ feedback: t,
93
+ incorrect: n.mode === "evaluate" ? l !== "correct" : void 0,
94
+ language: i.language,
95
+ extraCSSRules: i.extraCSSRules
96
+ };
97
+ n.role === "instructor" && (n.mode === "view" || n.mode === "evaluate") ? (r.rationale = i.rationaleEnabled ? i.rationale : null, r.teacherInstructions = i.teacherInstructionsEnabled ? i.teacherInstructions : null) : (r.rationale = null, r.teacherInstructions = null), e(r);
98
+ });
99
+ });
100
+ }, _ = (e, t) => new Promise((n) => {
101
+ if (t.mode !== "evaluate" && t.role === "instructor") {
102
+ let { tokens: t } = e;
103
+ n({
104
+ id: "1",
105
+ selectedTokens: t.filter((e) => e.correct)
106
+ });
107
+ } else n(null);
108
+ }), v = (e) => (e || "").replace(/(<(?!img|iframe|source)([^>]+)>)/gi, ""), y = (e = {}, t = {}) => {
109
+ let { tokens: n } = e, { minTokens: r = 2, maxTokens: i, maxSelections: a } = t, o = {}, s = (n || []).length;
110
+ [
111
+ "teacherInstructions",
112
+ "prompt",
113
+ "rationale"
114
+ ].forEach((n) => {
115
+ t[n]?.required && !v(e[n]) && (o[n] = "This field is required.");
116
+ });
117
+ let c = (n || []).reduce((e, t) => t.correct ? e + 1 : e, 0);
118
+ return s < r ? o.tokensError = `There should be at least ${r} tokens defined.` : s > i && (o.tokensError = `No more than ${i} tokens should be defined.`), c < 1 ? o.selectionsError = "There should be at least 1 token selected." : c > a && (o.selectionsError = `No more than ${a} tokens should be selected.`), o;
119
+ };
120
+ //#endregion
121
+ export { _ as createCorrectResponseSession, p as createDefaultModel, c as getCorrectness, d as getLogTrace, u as getPartialScore, g as model, h as normalize, m as normalizeSession, f as outcome, y as validate };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/select-text/src/index.js
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ export default class SelectText extends HTMLElement {
10
+ constructor();
11
+ set model(m: any);
12
+ set session(s: any);
13
+ get session(): any;
14
+ isSessionComplete(): boolean;
15
+ selectionChanged(selection: any): void;
16
+ connectedCallback(): void;
17
+ render(): void;
18
+ disconnectedCallback(): void;
19
+ }
@@ -0,0 +1,60 @@
1
+ import e from "./utils.js";
2
+ import t from "./main.js";
3
+ import n from "react";
4
+ import { createRoot as r } from "react-dom/client";
5
+ import { ModelSetEvent as i, SessionChangedEvent as a } from "@pie-element/shared-player-events";
6
+ import { renderMath as o } from "@pie-element/shared-math-rendering-mathjax";
7
+ //#region src/delivery/index.ts
8
+ var s = class extends HTMLElement {
9
+ constructor() {
10
+ super(), this._root = null;
11
+ }
12
+ set model(e) {
13
+ this._model = e, this.render(), this.dispatchEvent(new i(this.tagName.toLowerCase(), this.isSessionComplete(), this._model !== void 0));
14
+ }
15
+ set session(t) {
16
+ if (this._session = t, this._model) {
17
+ let { tokens: n } = e(this._model) || {}, { selectedTokens: r } = t || {};
18
+ r ||= [];
19
+ let i = (e) => n.find(({ start: t, end: n }) => e.start === t && e.end === n);
20
+ if (!r.reduce((e, t) => e && i(t), !0)) {
21
+ let { tokens: t } = e({
22
+ ...this._model,
23
+ tokens: r
24
+ }) || {};
25
+ t && (this._session.selectedTokens = t);
26
+ }
27
+ }
28
+ Array.isArray(this._session.selectedTokens) || (this._session.selectedTokens = []), this.render();
29
+ }
30
+ get session() {
31
+ return this._session;
32
+ }
33
+ isSessionComplete() {
34
+ let { selectedTokens: e } = this._session || {};
35
+ return Array.isArray(e) && e.length > 0;
36
+ }
37
+ selectionChanged(e) {
38
+ this._session.selectedTokens = e, this.dispatchEvent(new a(this.tagName.toLowerCase(), this.isSessionComplete()));
39
+ }
40
+ connectedCallback() {
41
+ this.render();
42
+ }
43
+ render() {
44
+ if (this._model && this._session) {
45
+ let e = n.createElement(t, {
46
+ model: this._model,
47
+ session: this._session,
48
+ onSelectionChange: this.selectionChanged.bind(this)
49
+ });
50
+ this._root ||= r(this), this._root.render(e), queueMicrotask(() => {
51
+ o(this);
52
+ });
53
+ }
54
+ }
55
+ disconnectedCallback() {
56
+ this._root &&= (this._root.unmount(), null);
57
+ }
58
+ };
59
+ //#endregion
60
+ export { s as default };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/select-text/src/main.jsx
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ import React from 'react';
10
+ import PropTypes from 'prop-types';
11
+ export declare class Main extends React.Component {
12
+ static propTypes: {
13
+ model: PropTypes.Requireable<object>;
14
+ session: PropTypes.Requireable<object>;
15
+ onSelectionChange: PropTypes.Validator<(...args: any[]) => any>;
16
+ };
17
+ static defaultProps: {};
18
+ constructor(props: any);
19
+ UNSAFE_componentWillReceiveProps(nextProps: any): void;
20
+ componentDidMount(): void;
21
+ componentDidUpdate(): void;
22
+ toggleShowCorrect: any;
23
+ correctAnswer: any;
24
+ render(): React.JSX.Element;
25
+ }
26
+ export default class Stateful extends React.Component {
27
+ static propTypes: {
28
+ model: PropTypes.Requireable<object>;
29
+ session: PropTypes.Requireable<object>;
30
+ onSelectionChange: PropTypes.Validator<(...args: any[]) => any>;
31
+ };
32
+ constructor(props: any);
33
+ UNSAFE_componentWillReceiveProps(nextProps: any): void;
34
+ change: any;
35
+ render(): React.JSX.Element;
36
+ }
@@ -0,0 +1,145 @@
1
+ import e from "./utils.js";
2
+ import t from "react";
3
+ import n from "react-dom";
4
+ import r from "prop-types";
5
+ import { Legend as i, TextSelect as a } from "@pie-lib/text-select";
6
+ import o from "@pie-lib/correct-answer-toggle";
7
+ import * as s from "@pie-lib/render-ui";
8
+ import { Collapsible as c, Feedback as l, PreviewPrompt as u, UiLayout as d, color as f, hasMedia as p, hasText as m } from "@pie-lib/render-ui";
9
+ import { jsx as h, jsxs as g } from "react/jsx-runtime";
10
+ import { renderMath as _ } from "@pie-element/shared-math-rendering-mathjax";
11
+ import { styled as v } from "@mui/material/styles";
12
+ import y from "debug";
13
+ //#region src/delivery/main.tsx
14
+ function b(e) {
15
+ return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
16
+ }
17
+ function x(e, t) {
18
+ return !e || b(e) ? e : b(e.default) ? e.default : t && b(e[t]) ? e[t] : t && b(e[t]?.default) ? e[t].default : e;
19
+ }
20
+ var S = x(d, "UiLayout") || x(O.UiLayout, "UiLayout"), C = x(u, "PreviewPrompt") || x(O.PreviewPrompt, "PreviewPrompt"), w = x(c, "Collapsible") || x(O.Collapsible, "Collapsible"), T = x(l, "Feedback") || x(O.Feedback, "Feedback"), E = s, D = E.default, O = D && typeof D == "object" ? D : E, k = y("@pie-ui:select-text"), A = v(S)({
21
+ color: f.text(),
22
+ backgroundColor: f.background()
23
+ }), j = v(a)(({ theme: e }) => ({
24
+ marginBottom: e.spacing(1),
25
+ marginTop: e.spacing(2),
26
+ whiteSpace: "normal"
27
+ })), M = v("div")(({ theme: e }) => ({
28
+ verticalAlign: "middle",
29
+ marginBottom: e.spacing(1)
30
+ })), N = v(w)(({ theme: e }) => ({ marginBottom: e.spacing(2) })), P = {
31
+ model: r.object,
32
+ session: r.object,
33
+ onSelectionChange: r.func.isRequired
34
+ }, F = class extends t.Component {
35
+ static propTypes = P;
36
+ static defaultProps = {};
37
+ constructor(t) {
38
+ super(t), this.state = {
39
+ showCorrectAnswer: this.props.model.alwaysShowCorrect || !1,
40
+ model: e(t.model)
41
+ };
42
+ }
43
+ UNSAFE_componentWillReceiveProps(t) {
44
+ this.setState({
45
+ showCorrectAnswer: !!t.model.alwaysShowCorrect,
46
+ model: e(t.model)
47
+ });
48
+ }
49
+ componentDidMount() {
50
+ _(n.findDOMNode(this));
51
+ }
52
+ componentDidUpdate() {
53
+ _(n.findDOMNode(this));
54
+ }
55
+ toggleShowCorrect = () => {
56
+ this.setState({ showCorrectAnswer: !this.state.showCorrectAnswer });
57
+ };
58
+ correctAnswer = () => {
59
+ let { model: e } = this.state;
60
+ return e.tokens.filter((e) => e.correct);
61
+ };
62
+ render() {
63
+ let { session: e, onSelectionChange: t } = this.props, { showCorrectAnswer: n, model: r } = this.state, { env: a, extraCSSRules: s } = r, { mode: c } = a || {}, l = n ? this.correctAnswer() : e.selectedTokens, u = r.rationale && (m(r.rationale) || p(r.rationale)), d = r.teacherInstructions && (m(r.teacherInstructions) || p(r.teacherInstructions));
64
+ return k("[render] selectedTokens:", l), /* @__PURE__ */ g(A, {
65
+ extraCSSRules: s,
66
+ children: [
67
+ d && (r.animationsDisabled ? /* @__PURE__ */ h(M, { children: /* @__PURE__ */ h(C, { prompt: r.teacherInstructions }) }) : /* @__PURE__ */ h(N, {
68
+ labels: {
69
+ hidden: "Show Teacher Instructions",
70
+ visible: "Hide Teacher Instructions"
71
+ },
72
+ children: /* @__PURE__ */ h(C, { prompt: r.teacherInstructions })
73
+ })),
74
+ /* @__PURE__ */ h(M, { children: /* @__PURE__ */ h(C, { prompt: r.prompt }) }),
75
+ !r.alwaysShowCorrect && /* @__PURE__ */ h(o, {
76
+ show: r.disabled && r.incorrect,
77
+ toggled: n,
78
+ onToggle: this.toggleShowCorrect,
79
+ language: r.language
80
+ }),
81
+ /* @__PURE__ */ h(j, {
82
+ disabled: r.disabled,
83
+ text: r.text,
84
+ tokens: r.tokens,
85
+ selectedTokens: l,
86
+ onChange: (e) => {
87
+ let n = e.map((e) => r.tokens.find(({ start: t, end: n }) => e.start === t && e.end === n) || e);
88
+ t(n);
89
+ },
90
+ highlightChoices: r.highlightChoices,
91
+ maxNoOfSelections: r.maxSelections,
92
+ animationsDisabled: r.animationsDisabled
93
+ }),
94
+ c === "evaluate" && /* @__PURE__ */ h(i, {
95
+ language: r.language,
96
+ showOnlyCorrect: n
97
+ }),
98
+ u && (r.animationsDisabled ? /* @__PURE__ */ h(M, { children: /* @__PURE__ */ h(C, { prompt: r.rationale }) }) : /* @__PURE__ */ h(N, {
99
+ labels: {
100
+ hidden: "Show Rationale",
101
+ visible: "Hide Rationale"
102
+ },
103
+ children: /* @__PURE__ */ h(C, { prompt: r.rationale })
104
+ })),
105
+ r.correctness && r.feedback && !n && /* @__PURE__ */ h(T, {
106
+ correctness: r.correctness,
107
+ feedback: r.feedback
108
+ })
109
+ ]
110
+ });
111
+ }
112
+ }, I = class extends t.Component {
113
+ static propTypes = P;
114
+ constructor(e) {
115
+ super(e), this.state = {
116
+ model: e.model,
117
+ session: e.session
118
+ };
119
+ }
120
+ UNSAFE_componentWillReceiveProps(e) {
121
+ this.setState({
122
+ model: e.model,
123
+ session: e.session
124
+ });
125
+ }
126
+ change = (e) => {
127
+ let t = {
128
+ ...this.state.session,
129
+ selectedTokens: e
130
+ };
131
+ this.setState({ session: t }, () => {
132
+ this.props.onSelectionChange(this.state.session.selectedTokens);
133
+ });
134
+ };
135
+ render() {
136
+ let { model: e, session: t } = this.state;
137
+ return /* @__PURE__ */ h(F, {
138
+ model: e,
139
+ session: t,
140
+ onSelectionChange: this.change
141
+ });
142
+ }
143
+ };
144
+ //#endregion
145
+ export { F as Main, I as default };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/select-text/src/utils.js
3
+ * @auto-generated
4
+ *
5
+ * This file is automatically synced from pie-elements and converted to TypeScript.
6
+ * Manual edits will be overwritten on next sync.
7
+ * To make changes, edit the upstream JavaScript file and run sync again.
8
+ */
9
+ declare const _default: (model: any) => any;
10
+ export default _default;
@@ -0,0 +1,47 @@
1
+ //#region src/delivery/utils.tsx
2
+ var e = function() {
3
+ var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", t = document.createElement("div");
4
+ return t.innerHTML = e.trim(), t;
5
+ }, t = function(e, t) {
6
+ return t ? e.innerHTML : `${e.innerHTML}
7
+
8
+ `;
9
+ }, n = function(e) {
10
+ var n = e.querySelectorAll("div[separator=true]"), r = "";
11
+ return n.forEach(function(e, i) {
12
+ r += t(e, i === n.length - 1);
13
+ }), r || null;
14
+ }, r = function(t) {
15
+ var r = e(t), i = document.createElement("div");
16
+ return i.innerHTML = `<div separator='true'>${r.innerHTML}</div>`, r = i, Array.from(r.querySelectorAll("*")).length === 0 ? t : n(r);
17
+ }, i = (e) => {
18
+ if (!e) return e;
19
+ let t = r(e.text || ""), n = (e.tokens || []).reduce((n, i = {}) => {
20
+ let a = r((e.text || "").slice(i.start, i.end));
21
+ if (!a) return [...n, i];
22
+ let o = (e) => {
23
+ let n = e;
24
+ for (; n >= 0;) {
25
+ let e = t.slice(n).indexOf(a);
26
+ if (e >= 0) return e + n;
27
+ n--;
28
+ }
29
+ return 0;
30
+ }, s = n[n.length - 1], c = o(s ? s.end : i.start), l = c + a.length;
31
+ return [...n, {
32
+ ...i,
33
+ text: a,
34
+ start: c,
35
+ end: l,
36
+ oldStart: i.start,
37
+ oldEnd: i.end
38
+ }];
39
+ }, []);
40
+ return {
41
+ ...e,
42
+ tokens: n,
43
+ text: t
44
+ };
45
+ };
46
+ //#endregion
47
+ export { i as default };
@@ -0,0 +1 @@
1
+ export { default } from './delivery/index.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * IIFE entry point for select-text element
3
+ * This file is only used for IIFE builds and includes auto-registration
4
+ *
5
+ * @sync-generated - Auto-generated during sync from pie-elements
6
+ */
7
+ import Element from './index.js';
8
+ export default Element;