@pie-element/categorize 13.1.11 → 13.2.0-next.9

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 (169) hide show
  1. package/configure.js +2 -0
  2. package/controller.js +1 -0
  3. package/dist/author/defaults.d.ts +222 -0
  4. package/dist/author/defaults.js +168 -0
  5. package/dist/author/design/builder.d.ts +10 -0
  6. package/dist/author/design/builder.js +24 -0
  7. package/dist/author/design/buttons.d.ts +28 -0
  8. package/dist/author/design/buttons.js +36 -0
  9. package/dist/author/design/categories/RowLabel.d.ts +23 -0
  10. package/dist/author/design/categories/RowLabel.js +47 -0
  11. package/dist/author/design/categories/alternateResponses.d.ts +31 -0
  12. package/dist/author/design/categories/alternateResponses.js +62 -0
  13. package/dist/author/design/categories/category.d.ts +44 -0
  14. package/dist/author/design/categories/category.js +98 -0
  15. package/dist/author/design/categories/choice-preview.d.ts +25 -0
  16. package/dist/author/design/categories/choice-preview.js +60 -0
  17. package/dist/author/design/categories/droppable-placeholder.d.ts +11 -0
  18. package/dist/author/design/categories/droppable-placeholder.js +71 -0
  19. package/dist/author/design/categories/index.d.ts +41 -0
  20. package/dist/author/design/categories/index.js +146 -0
  21. package/dist/author/design/choices/choice.d.ts +11 -0
  22. package/dist/author/design/choices/choice.js +129 -0
  23. package/dist/author/design/choices/config.d.ts +21 -0
  24. package/dist/author/design/choices/config.js +33 -0
  25. package/dist/author/design/choices/index.d.ts +41 -0
  26. package/dist/author/design/choices/index.js +110 -0
  27. package/dist/author/design/header.d.ts +24 -0
  28. package/dist/author/design/header.js +49 -0
  29. package/dist/author/design/index.d.ts +52 -0
  30. package/dist/author/design/index.js +427 -0
  31. package/dist/author/design/input-header.d.ts +39 -0
  32. package/dist/author/design/input-header.js +69 -0
  33. package/dist/author/design/utils.d.ts +9 -0
  34. package/dist/author/design/utils.js +7 -0
  35. package/dist/author/index.d.ts +50 -0
  36. package/dist/author/index.js +87 -0
  37. package/dist/author/main.d.ts +23 -0
  38. package/dist/author/main.js +30 -0
  39. package/dist/author/utils.d.ts +16 -0
  40. package/dist/author/utils.js +17 -0
  41. package/dist/browser/alert-dialog-BL9K_lnF.js +11511 -0
  42. package/dist/browser/alert-dialog-BL9K_lnF.js.map +1 -0
  43. package/dist/browser/author/index.js +43156 -0
  44. package/dist/browser/author/index.js.map +1 -0
  45. package/dist/browser/categorize.css +2 -0
  46. package/dist/browser/controller/index.js +372 -0
  47. package/dist/browser/controller/index.js.map +1 -0
  48. package/dist/browser/delivery/index.js +1205 -0
  49. package/dist/browser/delivery/index.js.map +1 -0
  50. package/dist/browser/dist-C11U2GIc.js +1871 -0
  51. package/dist/browser/dist-C11U2GIc.js.map +1 -0
  52. package/dist/browser/rolldown-runtime-CWhphoD1.js +32 -0
  53. package/dist/controller/defaults.d.ts +33 -0
  54. package/dist/controller/defaults.js +27 -0
  55. package/dist/controller/index.d.ts +62 -0
  56. package/dist/controller/index.js +168 -0
  57. package/dist/controller/utils.d.ts +20 -0
  58. package/dist/controller/utils.js +35 -0
  59. package/dist/delivery/categorize/__tests__/categories.test.d.ts +1 -0
  60. package/dist/delivery/categorize/__tests__/category.test.d.ts +1 -0
  61. package/dist/delivery/categorize/__tests__/choice.test.d.ts +1 -0
  62. package/dist/delivery/categorize/__tests__/choices.test.d.ts +1 -0
  63. package/dist/delivery/categorize/__tests__/droppable-placeholder.test.d.ts +1 -0
  64. package/dist/delivery/categorize/__tests__/grid-content.test.d.ts +1 -0
  65. package/dist/delivery/categorize/__tests__/index.test.d.ts +1 -0
  66. package/dist/delivery/categorize/__tests__/keyboard-coordinates.test.d.ts +1 -0
  67. package/dist/delivery/categorize/categories.d.ts +37 -0
  68. package/dist/delivery/categorize/categories.js +72 -0
  69. package/dist/delivery/categorize/category.d.ts +31 -0
  70. package/dist/delivery/categorize/category.js +55 -0
  71. package/dist/delivery/categorize/choice.d.ts +28 -0
  72. package/dist/delivery/categorize/choice.js +114 -0
  73. package/dist/delivery/categorize/choices.d.ts +42 -0
  74. package/dist/delivery/categorize/choices.js +58 -0
  75. package/dist/delivery/categorize/droppable-placeholder.d.ts +36 -0
  76. package/dist/delivery/categorize/droppable-placeholder.js +77 -0
  77. package/dist/delivery/categorize/grid-content.d.ts +25 -0
  78. package/dist/delivery/categorize/grid-content.js +39 -0
  79. package/dist/delivery/categorize/index.d.ts +70 -0
  80. package/dist/delivery/categorize/index.js +317 -0
  81. package/dist/delivery/categorize/keyboard-coordinates.d.ts +22 -0
  82. package/dist/delivery/categorize/keyboard-coordinates.js +49 -0
  83. package/dist/delivery/index.d.ts +27 -0
  84. package/dist/delivery/index.js +152 -0
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.iife.d.ts +8 -0
  87. package/dist/index.iife.js +152 -0
  88. package/dist/index.js +2 -0
  89. package/dist/runtime-support.d.ts +12 -0
  90. package/dist/runtime-support.js +12 -0
  91. package/package.json +97 -22
  92. package/CHANGELOG.json +0 -1637
  93. package/CHANGELOG.md +0 -2598
  94. package/LICENSE.md +0 -5
  95. package/README.md +0 -5
  96. package/configure/CHANGELOG.json +0 -1202
  97. package/configure/CHANGELOG.md +0 -2177
  98. package/configure/lib/defaults.js +0 -220
  99. package/configure/lib/defaults.js.map +0 -1
  100. package/configure/lib/design/builder.js +0 -55
  101. package/configure/lib/design/builder.js.map +0 -1
  102. package/configure/lib/design/buttons.js +0 -59
  103. package/configure/lib/design/buttons.js.map +0 -1
  104. package/configure/lib/design/categories/RowLabel.js +0 -66
  105. package/configure/lib/design/categories/RowLabel.js.map +0 -1
  106. package/configure/lib/design/categories/alternateResponses.js +0 -116
  107. package/configure/lib/design/categories/alternateResponses.js.map +0 -1
  108. package/configure/lib/design/categories/category.js +0 -153
  109. package/configure/lib/design/categories/category.js.map +0 -1
  110. package/configure/lib/design/categories/choice-preview.js +0 -79
  111. package/configure/lib/design/categories/choice-preview.js.map +0 -1
  112. package/configure/lib/design/categories/droppable-placeholder.js +0 -93
  113. package/configure/lib/design/categories/droppable-placeholder.js.map +0 -1
  114. package/configure/lib/design/categories/index.js +0 -256
  115. package/configure/lib/design/categories/index.js.map +0 -1
  116. package/configure/lib/design/choices/choice.js +0 -187
  117. package/configure/lib/design/choices/choice.js.map +0 -1
  118. package/configure/lib/design/choices/config.js +0 -58
  119. package/configure/lib/design/choices/config.js.map +0 -1
  120. package/configure/lib/design/choices/index.js +0 -197
  121. package/configure/lib/design/choices/index.js.map +0 -1
  122. package/configure/lib/design/header.js +0 -71
  123. package/configure/lib/design/header.js.map +0 -1
  124. package/configure/lib/design/index.js +0 -741
  125. package/configure/lib/design/index.js.map +0 -1
  126. package/configure/lib/design/input-header.js +0 -105
  127. package/configure/lib/design/input-header.js.map +0 -1
  128. package/configure/lib/design/utils.js +0 -12
  129. package/configure/lib/design/utils.js.map +0 -1
  130. package/configure/lib/index.js +0 -148
  131. package/configure/lib/index.js.map +0 -1
  132. package/configure/lib/main.js +0 -44
  133. package/configure/lib/main.js.map +0 -1
  134. package/configure/lib/utils.js +0 -43
  135. package/configure/lib/utils.js.map +0 -1
  136. package/configure/package.json +0 -32
  137. package/controller/CHANGELOG.json +0 -452
  138. package/controller/CHANGELOG.md +0 -1411
  139. package/controller/lib/defaults.js +0 -31
  140. package/controller/lib/defaults.js.map +0 -1
  141. package/controller/lib/index.js +0 -506
  142. package/controller/lib/index.js.map +0 -1
  143. package/controller/lib/utils.js +0 -69
  144. package/controller/lib/utils.js.map +0 -1
  145. package/controller/package.json +0 -18
  146. package/docs/config-schema.json +0 -2897
  147. package/docs/config-schema.json.md +0 -2138
  148. package/docs/demo/config.js +0 -8
  149. package/docs/demo/generate.js +0 -357
  150. package/docs/demo/index.html +0 -1
  151. package/docs/demo/session.js +0 -12
  152. package/docs/pie-schema.json +0 -1784
  153. package/docs/pie-schema.json.md +0 -1046
  154. package/lib/categorize/categories.js +0 -135
  155. package/lib/categorize/categories.js.map +0 -1
  156. package/lib/categorize/category.js +0 -67
  157. package/lib/categorize/category.js.map +0 -1
  158. package/lib/categorize/choice.js +0 -140
  159. package/lib/categorize/choice.js.map +0 -1
  160. package/lib/categorize/choices.js +0 -99
  161. package/lib/categorize/choices.js.map +0 -1
  162. package/lib/categorize/droppable-placeholder.js +0 -84
  163. package/lib/categorize/droppable-placeholder.js.map +0 -1
  164. package/lib/categorize/grid-content.js +0 -55
  165. package/lib/categorize/grid-content.js.map +0 -1
  166. package/lib/categorize/index.js +0 -450
  167. package/lib/categorize/index.js.map +0 -1
  168. package/lib/index.js +0 -316
  169. package/lib/index.js.map +0 -1
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/categorize/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
+ import { score } from '@pie-lib/categorize';
10
+ export { score };
11
+ export declare const getPartialScore: (correctResponse: any, builtCategories: any) => number;
12
+ export declare const getTotalScore: (question: any, session: any, env: any) => number;
13
+ export declare const getCorrectness: (question: any, session: any, env: any) => Promise<unknown>;
14
+ export declare const createDefaultModel: (model?: {}) => Promise<unknown>;
15
+ export declare const normalize: (question: any) => any;
16
+ /**
17
+ *
18
+ * @param {*} question
19
+ * @param {*} session
20
+ * @param {*} env
21
+ * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
22
+ */
23
+ export declare const model: (question: any, session: any, env: any, updateSession: any) => Promise<{
24
+ allowMultiplePlacementsEnabled?: any;
25
+ categories: any;
26
+ categoriesPerRow: any;
27
+ maxChoicesPerCategory: any;
28
+ correctness: unknown;
29
+ choices: any;
30
+ choicesLabel: any;
31
+ choicesPosition: any;
32
+ disabled: boolean;
33
+ feedback: string | undefined;
34
+ lockChoiceOrder: boolean;
35
+ prompt: any;
36
+ rowLabels: any;
37
+ note: any;
38
+ env: any;
39
+ showNote: any;
40
+ correctResponse: any;
41
+ language: any;
42
+ extraCSSRules: any;
43
+ fontSizeFactor: any;
44
+ minRowHeight: any;
45
+ autoplayAudioEnabled: any;
46
+ completeAudioEnabled: any;
47
+ customAudioButton: any;
48
+ possibleResponses: any[];
49
+ responseAreasToBeFilled: any;
50
+ hasUnplacedChoices: boolean;
51
+ }>;
52
+ /**
53
+ * Generates detailed trace log for scoring evaluation
54
+ * @param {Object} model - the question model
55
+ * @param {Object} session - the student session
56
+ * @param {Object} env - the environment
57
+ * @returns {Array} traceLog - array of trace messages
58
+ */
59
+ export declare const getLogTrace: (model: any, session: any, env: any) => string[];
60
+ export declare const outcome: (question: any, session: any, env: any) => Promise<unknown>;
61
+ export declare const createCorrectResponseSession: (question: any, env: any) => Promise<unknown>;
62
+ export declare const validate: (model?: {}, config?: {}) => {};
@@ -0,0 +1,168 @@
1
+ import e from "./defaults.js";
2
+ import { getCompleteResponseDetails as t, isAlternateDuplicated as n, isCorrectResponseDuplicated as r, multiplePlacements as i } from "./utils.js";
3
+ import { buildState as a, score as o } from "@pie-lib/categorize";
4
+ import s from "@pie-lib/translator";
5
+ import { isEmpty as c } from "@pie-element/shared-lodash";
6
+ import { getFeedbackForCorrectness as l } from "@pie-element/shared-feedback";
7
+ import { getShuffledChoices as u, lockChoices as d, partialScoring as f } from "@pie-element/shared-controller-utils";
8
+ //#region src/controller/index.ts
9
+ var { translator: p } = s, m = (e, t) => {
10
+ let { placements: n, score: r } = t.reduce((e, { choices: t = [] }) => ({
11
+ placements: e.placements + t.length,
12
+ score: e.score + t.filter((e) => e.correct).length
13
+ }), {
14
+ placements: 0,
15
+ score: 0
16
+ }), { maxScore: i } = e.reduce((e, { choices: t }) => ({ maxScore: e.maxScore + t.length }), { maxScore: 0 }), a = (r - (n > i ? n - i : 0)) / i;
17
+ return a < 0 ? 0 : parseFloat(a.toFixed(2));
18
+ }, h = (e) => e.map((e) => e.alternateResponses).filter((e) => e), g = (e, t, n) => {
19
+ if (!t || Object.keys(t).length === 0) return 0;
20
+ let { categories: r, choices: i } = e || {}, { correctResponse: o } = e || {}, { answers: s } = t || {};
21
+ s ||= [], o ||= [];
22
+ let { categories: c, correct: l } = a(r, i, s, o), u = h(o);
23
+ return f.enabled(e, n) && !u.length ? m(o, c) : +!!l;
24
+ }, _ = (e, t, n) => new Promise((r) => {
25
+ if (n.mode === "evaluate") {
26
+ let i = g(e, t, n);
27
+ r(i === 1 ? "correct" : i === 0 ? "incorrect" : "partially-correct");
28
+ } else r(void 0);
29
+ }), v = (t = {}) => new Promise((n) => {
30
+ n({
31
+ ...e,
32
+ ...t
33
+ });
34
+ }), y = (t) => ({
35
+ ...e,
36
+ ...t
37
+ }), b = async (e, n, r, a) => {
38
+ let o = y(e), s = await _(o, n, r), { mode: c, role: f } = r || {}, { categories: m, categoriesPerRow: g, choicesLabel: v, choicesPosition: b, correctResponse: x, feedback: S, feedbackEnabled: C, promptEnabled: w, prompt: T, rowLabels: E, rationaleEnabled: D, rationale: O, teacherInstructionsEnabled: k, teacherInstructions: A, language: j, maxChoicesPerCategory: M, extraCSSRules: N, minRowHeight: P, fontSizeFactor: F, autoplayAudioEnabled: I, completeAudioEnabled: L, customAudioButton: R } = o, { choices: z, note: B } = o, V, H = d(o, n, r), U = x.map((e) => {
39
+ let t = (e.choices || []).filter((e) => e !== "null");
40
+ return {
41
+ ...e,
42
+ choices: t
43
+ };
44
+ });
45
+ c === "evaluate" && C && (V = await l(s, S)), H || (z = await u(z, n, a, "id"));
46
+ let W = (() => {
47
+ if (e.allowMultiplePlacementsEnabled != null) return e.allowMultiplePlacementsEnabled;
48
+ let t = (x || []).flatMap((e) => e.choices || []);
49
+ return t.length === new Set(t).size ? i.disabled : i.enabled;
50
+ })();
51
+ z = (z || []).map((e) => {
52
+ let t;
53
+ return t = W === i.enabled ? 0 : W === i.disabled ? 1 : e.categoryCount || 0, {
54
+ ...e,
55
+ categoryCount: t
56
+ };
57
+ }), B ||= p.t("common:commonCorrectAnswerWithAlternates", { lng: j });
58
+ let G = h(U), { responseAreasToBeFilled: K, possibleResponses: q, hasUnplacedChoices: J } = t(U, o.allowAlternateEnabled ? G : [], o.choices), Y = {
59
+ categories: m || [],
60
+ categoriesPerRow: g || 2,
61
+ maxChoicesPerCategory: M,
62
+ correctness: s,
63
+ choices: z || [],
64
+ choicesLabel: v || "",
65
+ choicesPosition: b,
66
+ disabled: c !== "gather",
67
+ feedback: V,
68
+ lockChoiceOrder: H,
69
+ prompt: w ? T : null,
70
+ rowLabels: E,
71
+ note: B,
72
+ env: r,
73
+ showNote: G && G.length > 0,
74
+ correctResponse: c === "evaluate" ? U : void 0,
75
+ language: j,
76
+ extraCSSRules: N,
77
+ fontSizeFactor: F,
78
+ minRowHeight: P,
79
+ autoplayAudioEnabled: I,
80
+ completeAudioEnabled: L,
81
+ customAudioButton: R,
82
+ possibleResponses: q,
83
+ responseAreasToBeFilled: K,
84
+ hasUnplacedChoices: J,
85
+ ...e.allowMultiplePlacementsEnabled == null && { allowMultiplePlacementsEnabled: W }
86
+ };
87
+ return f === "instructor" && (c === "view" || c === "evaluate") ? (Y.rationale = D ? O : null, Y.teacherInstructions = k ? A : null) : (Y.rationale = null, Y.teacherInstructions = null), Y;
88
+ }, x = (e, t, n) => {
89
+ let r = [], { answers: i } = t || {}, { categories: o, choices: s, correctResponse: c } = e || {}, l = i.reduce((e, t) => e + (t.choices?.length || 0), 0), u = h(c).length > 0, d = f.enabled(e, n), p = (l > 0 ? a(o, s, i, c) : null)?.categories || [];
90
+ if (l > 0 ? (r.push(`Student placed ${l} choice(s) into categories.`), (o || []).forEach((e) => {
91
+ let t = e.id, n = p.find((e) => e.id === t), i = n && n.choices || [], a = (c || []).find((e) => e.category === t), o = a && a.choices || [];
92
+ if (o.length > 0) if (i.length === 0) r.push(`Category ${t}: student left empty (should contain ${o.length} choice(s)).`);
93
+ else {
94
+ let e = i.filter((e) => e.correct).length, n = i.length - e;
95
+ e > 0 && n === 0 ? r.push(`Category ${t}: student placed ${e} correct choice(s).`) : e === 0 && n > 0 ? r.push(`Category ${t}: student placed ${n} incorrect choice(s).`) : r.push(`Category ${t}: student placed ${e} correct and ${n} incorrect choice(s).`);
96
+ }
97
+ })) : r.push("Student did not place any choices into categories."), u && r.push("Alternate response combinations are accepted for this question."), u) r.push("Score calculated using all-or-nothing scoring (alternate responses disable partial scoring)."), r.push("Student must get all categories completely correct to receive full credit.");
98
+ else if (d) {
99
+ if (r.push("Score calculated using partial scoring."), r.push("Student receives credit for each correct placement, with deductions for incorrect placements beyond required amount."), l > 0) {
100
+ let e = p.reduce((e, t) => e + (t.choices || []).filter((e) => e.correct).length, 0), t = l - e, n = (c || []).reduce((e, t) => e + (t.choices || []).length, 0);
101
+ if (r.push(`Partial scoring calculation: ${e} correct placements, ${t} incorrect placements.`), l > n) {
102
+ let e = l - n;
103
+ r.push(`${e} extra placement(s) beyond required amount will be deducted from score.`);
104
+ }
105
+ }
106
+ } else r.push("Score calculated using all-or-nothing scoring."), r.push("Student must get all categories completely correct to receive full credit.");
107
+ let m = g(e, t, n);
108
+ return r.push(`Final score: ${m}.`), r;
109
+ }, S = (e, t, n) => n.mode === "evaluate" ? new Promise((r) => {
110
+ if (!t || c(t)) r({
111
+ score: 0,
112
+ empty: !0,
113
+ traceLog: ["Student did not place any choices into categories. Score is 0."]
114
+ });
115
+ else {
116
+ let i = x(e, t, n);
117
+ r({
118
+ score: g(e, t, n),
119
+ empty: !1,
120
+ traceLog: i
121
+ });
122
+ }
123
+ }) : Promise.reject(/* @__PURE__ */ Error("Can not call outcome when mode is not evaluate")), C = (e, t) => new Promise((n) => {
124
+ let { mode: r, role: i } = t || {};
125
+ if (r !== "evaluate" && i === "instructor") {
126
+ let { correctResponse: t } = e;
127
+ n({
128
+ answers: t,
129
+ id: 1
130
+ });
131
+ } else return n(null);
132
+ }), w = (e) => (e || "").replaceAll(/<[^>]*>/g, ""), T = (e) => (e || "").replace(/(<(?!img|iframe|source)([^>]+)>)/gi, ""), E = (e = {}, t = {}) => {
133
+ let { categories: i, choices: a, correctResponse: o, maxAnswerChoices: s } = e, { minChoices: l = 1, minCategories: u = 1, maxCategories: d = 12, maxLengthPerChoice: f = 300, maxLengthPerCategory: p = 150 } = t, m = [...a || []].reverse(), h = {}, g = {}, _ = {};
134
+ [
135
+ "teacherInstructions",
136
+ "prompt",
137
+ "rationale"
138
+ ].forEach((n) => {
139
+ t[n]?.required && !T(e[n]) && (h[n] = "This field is required.");
140
+ }), (i || []).forEach((e) => {
141
+ let { id: t, label: n } = e;
142
+ w(n).length > p && (_[t] = `Category labels should be no more than ${p} characters long.`);
143
+ }), (m || []).forEach((e, t) => {
144
+ let { id: n, content: r } = e;
145
+ w(r).length > f && (g[n] = `Tokens should be no more than ${f} characters long.`), T(r) ? m.slice(t + 1).some((e) => e.content === r) && (g[n] = "Tokens content should be unique.") : g[n] = "Tokens should not be empty.";
146
+ });
147
+ let v = (i || []).length, y = (a || []).length;
148
+ if (v > d ? h.categoriesError = `No more than ${d} categories should be defined.` : v < u && (h.categoriesError = `There should be at least ${u} category defined.`), y < l ? h.choicesError = `There should be at least ${l} choices defined.` : y > s && (h.choicesError = `No more than ${s} choices should be defined.`), y && v) {
149
+ let e = !1;
150
+ (o || []).forEach((t) => {
151
+ let { choices: n = [], alternateResponses: r = [] } = t;
152
+ n.length ? e = !0 : r.forEach((t) => {
153
+ (t || []).length && (e = !0);
154
+ });
155
+ });
156
+ let t = -1, i = "";
157
+ (o || []).forEach((e) => {
158
+ let { choices: a = [], alternateResponses: o = [], category: s } = e;
159
+ t === -1 && (t = r(a, o), t === -1 && (t = n(o)), i = s);
160
+ }), t > -1 && (h.duplicateAlternate = {
161
+ index: t,
162
+ category: i
163
+ }), e || (h.associationError = "At least one token should be assigned to at least one category.");
164
+ }
165
+ return c(g) || (h.choicesErrors = g), c(_) || (h.categoriesErrors = _), h;
166
+ };
167
+ //#endregion
168
+ export { C as createCorrectResponseSession, v as createDefaultModel, _ as getCorrectness, x as getLogTrace, m as getPartialScore, g as getTotalScore, b as model, y as normalize, S as outcome, o as score, E as validate };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/categorize/controller/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
+ export declare const multiplePlacements: {
10
+ enabled: string;
11
+ disabled: string;
12
+ perChoice: string;
13
+ };
14
+ export declare const isCorrectResponseDuplicated: (choices: any, alternate: any) => any;
15
+ export declare const isAlternateDuplicated: (alternate: any) => number;
16
+ export declare const getCompleteResponseDetails: (correctResponse: any, alternates: any, allChoices: any) => {
17
+ responseAreasToBeFilled: any;
18
+ possibleResponses: any[];
19
+ hasUnplacedChoices: boolean;
20
+ };
@@ -0,0 +1,35 @@
1
+ //#region src/controller/utils.ts
2
+ var e = {
3
+ enabled: "Yes",
4
+ disabled: "No",
5
+ perChoice: "Set Per Choice"
6
+ }, t = (e, t) => {
7
+ if (e.length < 1 || t.length < 1) return -1;
8
+ let n = JSON.stringify(e.sort());
9
+ return t.reduce((e, t) => t.length > 0 ? [...e, JSON.stringify(t.sort())] : e, []).findIndex((e) => e.length && e === n);
10
+ }, n = (e) => {
11
+ if (e.length <= 1) return -1;
12
+ let t = /* @__PURE__ */ new Set(), n = e.reduce((e, t) => t.length > 0 ? [...e, JSON.stringify(t.sort())] : e, []);
13
+ for (let e = 0; e < n.length; e++) {
14
+ if (t.has(n[e]) && n[e]) return e;
15
+ t.add(n[e]);
16
+ }
17
+ return -1;
18
+ }, r = (e, t, n) => {
19
+ let r = e.map((e) => e.choices), i = [r.flat()], a = r.filter((e) => e.length).length;
20
+ if (t.length) {
21
+ let e = t[0]?.length || 0;
22
+ [...Array(e).keys()].forEach((e) => {
23
+ let n = t.map((t) => t[e]), r = n.filter((e) => e?.length).length;
24
+ i.push(n.flat()), r < a && (a = r);
25
+ });
26
+ }
27
+ let o = i.some((e) => !n.every((t) => e.includes(t?.id)));
28
+ return {
29
+ responseAreasToBeFilled: a,
30
+ possibleResponses: i,
31
+ hasUnplacedChoices: o
32
+ };
33
+ };
34
+ //#endregion
35
+ export { r as getCompleteResponseDetails, n as isAlternateDuplicated, t as isCorrectResponseDuplicated, e as multiplePlacements };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/categorize/src/categorize/categories.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
+ import { CategoryType } from './category.js';
12
+ export { CategoryType };
13
+ export declare class Categories extends React.Component {
14
+ static propTypes: {
15
+ categories: PropTypes.Requireable<(PropTypes.InferProps<{
16
+ id: PropTypes.Validator<string>;
17
+ categoryId: PropTypes.Requireable<string>;
18
+ }> | null | undefined)[]>;
19
+ model: PropTypes.Requireable<PropTypes.InferProps<{
20
+ categoriesPerRow: PropTypes.Requireable<number>;
21
+ }>>;
22
+ disabled: PropTypes.Requireable<boolean>;
23
+ onDropChoice: PropTypes.Validator<(...args: any[]) => any>;
24
+ onRemoveChoice: PropTypes.Validator<(...args: any[]) => any>;
25
+ rowLabels: PropTypes.Requireable<any[]>;
26
+ selectedItem: PropTypes.Requireable<object>;
27
+ onSelectClick: PropTypes.Requireable<(...args: any[]) => any>;
28
+ onPlacementClick: PropTypes.Requireable<(...args: any[]) => any>;
29
+ };
30
+ static defaultProps: {
31
+ model: {
32
+ categoriesPerRow: number;
33
+ };
34
+ };
35
+ render(): React.JSX.Element;
36
+ }
37
+ export default Categories;
@@ -0,0 +1,72 @@
1
+ import { GridContent as e } from "./grid-content.js";
2
+ import { Category as t, CategoryType as n } from "./category.js";
3
+ import r from "react";
4
+ import { color as i } from "@pie-lib/render-ui";
5
+ import a from "prop-types";
6
+ import { styled as o } from "@mui/material/styles";
7
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
8
+ //#region src/delivery/categorize/categories.tsx
9
+ var l = class extends r.Component {
10
+ static propTypes = {
11
+ categories: a.arrayOf(a.shape(n)),
12
+ model: a.shape({ categoriesPerRow: a.number }),
13
+ disabled: a.bool,
14
+ onDropChoice: a.func.isRequired,
15
+ onRemoveChoice: a.func.isRequired,
16
+ rowLabels: a.array,
17
+ selectedItem: a.object,
18
+ onSelectClick: a.func,
19
+ onPlacementClick: a.func
20
+ };
21
+ static defaultProps = { model: { categoriesPerRow: 1 } };
22
+ render() {
23
+ let { categories: n, model: r, disabled: i, onDropChoice: a, onRemoveChoice: o, rowLabels: l, selectedItem: p, onSelectClick: m, onPlacementClick: h } = this.props, { categoriesPerRow: g, minRowHeight: _ } = r, v = [], y = n || [];
24
+ for (let e = 0; e < y.length; e += g) v.push(y.slice(e, e + g));
25
+ let b = (e) => {
26
+ let t = !1;
27
+ return (e || []).forEach((e) => {
28
+ typeof e == "string" && e.trim() !== "" && e.trim() !== "<div></div>" && (t = !0);
29
+ }), t;
30
+ };
31
+ return /* @__PURE__ */ s(e, {
32
+ columns: g,
33
+ rows: Math.ceil(n.length / g) * 2,
34
+ extraStyle: { flex: 1 },
35
+ children: v.map((e, n) => {
36
+ let r = [];
37
+ return e.forEach((e, g) => {
38
+ r.push(/* @__PURE__ */ c("div", {
39
+ style: { display: "flex" },
40
+ children: [g === 0 && b(l) ? /* @__PURE__ */ s(d, { dangerouslySetInnerHTML: { __html: l[n] || "" } }, n) : null, /* @__PURE__ */ c(f, { children: [/* @__PURE__ */ s(u, { dangerouslySetInnerHTML: { __html: e.label } }, `category-label-${n}-${g}`), /* @__PURE__ */ s(t, {
41
+ minRowHeight: _,
42
+ onDropChoice: (t) => a(e.id, t),
43
+ onRemoveChoice: o,
44
+ disabled: i,
45
+ selectedItem: p,
46
+ onSelectClick: m,
47
+ onPlacementClick: h,
48
+ ...e
49
+ }, `category-element-${n}-${g}`)] })]
50
+ }));
51
+ }), r = r.concat(Array(g - e.length).fill(/* @__PURE__ */ s("div", {})).map((e, t) => /* @__PURE__ */ s("div", {}, `fill-space-final-${t}`))), r;
52
+ })
53
+ });
54
+ }
55
+ }, u = o("div")(({ theme: e }) => ({
56
+ color: i.text(),
57
+ backgroundColor: i.background(),
58
+ textAlign: "center",
59
+ paddingTop: e.spacing(1)
60
+ })), d = o("div")({
61
+ alignItems: "center",
62
+ display: "flex",
63
+ justifyContent: "center",
64
+ flex: .5,
65
+ marginRight: "12px"
66
+ }), f = o("div")({
67
+ display: "flex",
68
+ flex: "2",
69
+ flexDirection: "column"
70
+ });
71
+ //#endregion
72
+ export { l as Categories, l as default, n as CategoryType };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/categorize/src/categorize/category.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 const CategoryType: {
12
+ id: PropTypes.Validator<string>;
13
+ categoryId: PropTypes.Requireable<string>;
14
+ };
15
+ export declare class Category extends React.Component {
16
+ static propTypes: {
17
+ className: PropTypes.Requireable<string>;
18
+ disabled: PropTypes.Requireable<boolean>;
19
+ onDropChoice: PropTypes.Requireable<(...args: any[]) => any>;
20
+ onRemoveChoice: PropTypes.Requireable<(...args: any[]) => any>;
21
+ minRowHeight: PropTypes.Requireable<string>;
22
+ selectedItem: PropTypes.Requireable<object>;
23
+ onSelectClick: PropTypes.Requireable<(...args: any[]) => any>;
24
+ onPlacementClick: PropTypes.Requireable<(...args: any[]) => any>;
25
+ id: PropTypes.Validator<string>;
26
+ categoryId: PropTypes.Requireable<string>;
27
+ };
28
+ static defaultProps: {};
29
+ render(): React.JSX.Element;
30
+ }
31
+ export default Category;
@@ -0,0 +1,55 @@
1
+ import e from "./choice.js";
2
+ import t from "./droppable-placeholder.js";
3
+ import n from "react";
4
+ import r from "prop-types";
5
+ import { styled as i } from "@mui/material/styles";
6
+ import { jsx as a } from "react/jsx-runtime";
7
+ //#region src/delivery/categorize/category.tsx
8
+ var o = {
9
+ id: r.string.isRequired,
10
+ categoryId: r.string
11
+ }, s = class extends n.Component {
12
+ static propTypes = {
13
+ ...o,
14
+ className: r.string,
15
+ disabled: r.bool,
16
+ onDropChoice: r.func,
17
+ onRemoveChoice: r.func,
18
+ minRowHeight: r.string,
19
+ selectedItem: r.object,
20
+ onSelectClick: r.func,
21
+ onPlacementClick: r.func
22
+ };
23
+ static defaultProps = {};
24
+ render() {
25
+ let { className: n, choices: r = [], disabled: i, onDropChoice: o, onRemoveChoice: s, id: l, correct: u, minRowHeight: d, selectedItem: f, onSelectClick: p, onPlacementClick: m } = this.props;
26
+ return /* @__PURE__ */ a(c, {
27
+ className: n,
28
+ id: l,
29
+ children: /* @__PURE__ */ a(t, {
30
+ id: l,
31
+ onDropChoice: o,
32
+ disabled: i,
33
+ correct: u,
34
+ minRowHeight: d,
35
+ selectedItem: f,
36
+ onPlacementClick: m,
37
+ children: r.map((t, n) => /* @__PURE__ */ a(e, {
38
+ onRemoveChoice: s,
39
+ disabled: i,
40
+ choiceIndex: n,
41
+ categoryId: l,
42
+ selectedItem: f,
43
+ onSelectClick: p,
44
+ ...t
45
+ }, n))
46
+ })
47
+ });
48
+ }
49
+ }, c = i("div")(({ theme: e }) => ({
50
+ display: "flex",
51
+ flexDirection: "column",
52
+ flex: 2
53
+ }));
54
+ //#endregion
55
+ export { s as Category, s as default, o as CategoryType };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/categorize/src/categorize/choice.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 const ChoiceType: {
12
+ content: PropTypes.Validator<string>;
13
+ id: PropTypes.Requireable<string>;
14
+ };
15
+ export declare class Layout extends React.Component {
16
+ static propTypes: {
17
+ disabled: PropTypes.Requireable<boolean>;
18
+ correct: PropTypes.Requireable<boolean>;
19
+ isDragging: PropTypes.Requireable<boolean>;
20
+ isSelected: PropTypes.Requireable<boolean>;
21
+ content: PropTypes.Validator<string>;
22
+ id: PropTypes.Requireable<string>;
23
+ };
24
+ static defaultProps: {};
25
+ render(): React.JSX.Element;
26
+ }
27
+ declare const _default: (props: any) => React.JSX.Element;
28
+ export default _default;
@@ -0,0 +1,114 @@
1
+ import e from "react";
2
+ import { color as t } from "@pie-lib/render-ui";
3
+ import n from "prop-types";
4
+ import r from "debug";
5
+ import { styled as i } from "@mui/material/styles";
6
+ import { useDraggable as a } from "@dnd-kit/core";
7
+ import { uid as o } from "@pie-lib/drag";
8
+ import { jsx as s } from "react/jsx-runtime";
9
+ import c from "@mui/material/Card";
10
+ import l from "@mui/material/CardContent";
11
+ //#region src/delivery/categorize/choice.tsx
12
+ r("@pie-ui:categorize:choice");
13
+ var u = {
14
+ content: n.string.isRequired,
15
+ id: n.string
16
+ }, d = i("div", { shouldForwardProp: (e) => ![
17
+ "isDragging",
18
+ "disabled",
19
+ "correct",
20
+ "isSelected"
21
+ ].includes(e) })(({ isDragging: e, disabled: n, correct: r, isSelected: i }) => ({
22
+ direction: "initial",
23
+ cursor: n ? "not-allowed" : e ? "move" : "pointer",
24
+ width: "100%",
25
+ borderRadius: "6px",
26
+ ...i && { border: `solid 2px ${t.buttonFocusOutline()}` },
27
+ ...r === !0 && { border: `solid 2px ${t.correct()}` },
28
+ ...r === !1 && { border: `solid 2px ${t.incorrect()}` }
29
+ })), f = i(c, { shouldForwardProp: (e) => e !== "isSelected" })(({ isSelected: e }) => ({
30
+ color: t.text(),
31
+ backgroundColor: t.background(),
32
+ width: "100%",
33
+ opacity: e ? .5 : 1
34
+ })), p = i(l)(({ theme: e }) => ({
35
+ color: t.text(),
36
+ backgroundColor: t.white(),
37
+ "&:last-child": { paddingBottom: e.spacing(2) },
38
+ borderRadius: "4px",
39
+ border: "1px solid",
40
+ "& p": { margin: "0px" }
41
+ })), m = class extends e.Component {
42
+ static propTypes = {
43
+ ...u,
44
+ disabled: n.bool,
45
+ correct: n.bool,
46
+ isDragging: n.bool,
47
+ isSelected: n.bool
48
+ };
49
+ static defaultProps = {};
50
+ render() {
51
+ let { content: e, isDragging: t, disabled: n, correct: r, isSelected: i, showsSelectionBorder: a } = this.props;
52
+ return /* @__PURE__ */ s(d, {
53
+ isDragging: t,
54
+ disabled: n,
55
+ correct: r,
56
+ isSelected: i,
57
+ children: /* @__PURE__ */ s(f, {
58
+ isSelected: i,
59
+ children: /* @__PURE__ */ s(p, { dangerouslySetInnerHTML: { __html: e } })
60
+ })
61
+ });
62
+ }
63
+ }, h = ({ id: e, content: t, disabled: n, correct: r, extraStyle: i, categoryId: o, choiceIndex: c, selectedItem: l, onSelectClick: u }) => {
64
+ let d = o === void 0 ? `choice-${e}-board` : `choice-${e}-${o}-${c}`, f = {
65
+ id: e,
66
+ categoryId: o,
67
+ choiceIndex: c,
68
+ value: t,
69
+ itemType: "categorize",
70
+ type: "choice"
71
+ }, { attributes: p, listeners: h, setNodeRef: g, isDragging: _ } = a({
72
+ id: d,
73
+ data: f,
74
+ disabled: n
75
+ }), v = !!l && l.id === e && l.categoryId === o && l.choiceIndex === c, y = (e) => {
76
+ if (!n) {
77
+ if (v) {
78
+ e.stopPropagation(), u?.(f);
79
+ return;
80
+ }
81
+ l && o !== void 0 || (e.stopPropagation(), u?.(f));
82
+ }
83
+ };
84
+ return /* @__PURE__ */ s("div", {
85
+ ref: g,
86
+ style: {
87
+ margin: "4px",
88
+ ...i
89
+ },
90
+ onClick: y,
91
+ ...h,
92
+ ...p,
93
+ children: /* @__PURE__ */ s(m, {
94
+ id: e,
95
+ content: t,
96
+ disabled: n,
97
+ correct: r,
98
+ isDragging: _,
99
+ isSelected: v
100
+ })
101
+ });
102
+ };
103
+ h.propTypes = {
104
+ ...u,
105
+ extraStyle: n.object,
106
+ categoryId: n.string,
107
+ choiceIndex: n.number,
108
+ onRemoveChoice: n.func,
109
+ selectedItem: n.object,
110
+ onSelectClick: n.func
111
+ };
112
+ var g = o.withUid(h);
113
+ //#endregion
114
+ export { u as ChoiceType, m as Layout, g as default };