@pie-element/categorize 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 (215) hide show
  1. package/author.js +2 -0
  2. package/configure.js +2 -0
  3. package/controller.js +1 -0
  4. package/dist/author/defaults.d.ts +222 -0
  5. package/dist/author/defaults.js +168 -0
  6. package/dist/author/design/builder.d.ts +10 -0
  7. package/dist/author/design/builder.js +24 -0
  8. package/dist/author/design/buttons.d.ts +28 -0
  9. package/dist/author/design/buttons.js +36 -0
  10. package/dist/author/design/categories/RowLabel.d.ts +23 -0
  11. package/dist/author/design/categories/RowLabel.js +47 -0
  12. package/dist/author/design/categories/alternateResponses.d.ts +31 -0
  13. package/dist/author/design/categories/alternateResponses.js +62 -0
  14. package/dist/author/design/categories/category.d.ts +44 -0
  15. package/dist/author/design/categories/category.js +98 -0
  16. package/dist/author/design/categories/choice-preview.d.ts +25 -0
  17. package/dist/author/design/categories/choice-preview.js +60 -0
  18. package/dist/author/design/categories/droppable-placeholder.d.ts +11 -0
  19. package/dist/author/design/categories/droppable-placeholder.js +71 -0
  20. package/dist/author/design/categories/index.d.ts +41 -0
  21. package/dist/author/design/categories/index.js +146 -0
  22. package/dist/author/design/choices/choice.d.ts +11 -0
  23. package/dist/author/design/choices/choice.js +129 -0
  24. package/dist/author/design/choices/config.d.ts +21 -0
  25. package/dist/author/design/choices/config.js +33 -0
  26. package/dist/author/design/choices/index.d.ts +41 -0
  27. package/dist/author/design/choices/index.js +110 -0
  28. package/dist/author/design/header.d.ts +24 -0
  29. package/dist/author/design/header.js +49 -0
  30. package/dist/author/design/index.d.ts +52 -0
  31. package/dist/author/design/index.js +427 -0
  32. package/dist/author/design/input-header.d.ts +39 -0
  33. package/dist/author/design/input-header.js +69 -0
  34. package/dist/author/design/utils.d.ts +9 -0
  35. package/dist/author/design/utils.js +7 -0
  36. package/dist/author/index.d.ts +50 -0
  37. package/dist/author/index.js +87 -0
  38. package/dist/author/main.d.ts +23 -0
  39. package/dist/author/main.js +30 -0
  40. package/dist/author/utils.d.ts +16 -0
  41. package/dist/author/utils.js +17 -0
  42. package/dist/browser/alert-dialog-DjezK_ch.js +11690 -0
  43. package/dist/browser/alert-dialog-DjezK_ch.js.map +1 -0
  44. package/dist/browser/assets/Symbola-4c507403.woff2 +0 -0
  45. package/dist/browser/author/index.js +35706 -0
  46. package/dist/browser/author/index.js.map +1 -0
  47. package/dist/browser/controller/index.js +372 -0
  48. package/dist/browser/controller/index.js.map +1 -0
  49. package/dist/browser/delivery/index.js +1220 -0
  50. package/dist/browser/delivery/index.js.map +1 -0
  51. package/dist/browser/dist-Denz71xw.js +1973 -0
  52. package/dist/browser/dist-Denz71xw.js.map +1 -0
  53. package/dist/browser/editor-runtime/alert-dialog-DegUZr32.js +11690 -0
  54. package/dist/browser/editor-runtime/alert-dialog-DegUZr32.js.map +1 -0
  55. package/dist/browser/editor-runtime/assets/Symbola-4c507403.woff2 +0 -0
  56. package/dist/browser/editor-runtime/author/index.js +19297 -0
  57. package/dist/browser/editor-runtime/author/index.js.map +1 -0
  58. package/dist/browser/editor-runtime/controller/index.js +372 -0
  59. package/dist/browser/editor-runtime/controller/index.js.map +1 -0
  60. package/dist/browser/editor-runtime/delivery/index.js +1220 -0
  61. package/dist/browser/editor-runtime/delivery/index.js.map +1 -0
  62. package/dist/browser/editor-runtime/dist-BiRlv37L.js +1973 -0
  63. package/dist/browser/editor-runtime/dist-BiRlv37L.js.map +1 -0
  64. package/dist/browser/editor-runtime/rolldown-runtime-CHQKHQ89.js +32 -0
  65. package/dist/browser/rolldown-runtime-CWhphoD1.js +32 -0
  66. package/dist/controller/defaults.d.ts +33 -0
  67. package/dist/controller/defaults.js +27 -0
  68. package/dist/controller/index.d.ts +62 -0
  69. package/dist/controller/index.js +168 -0
  70. package/dist/controller/utils.d.ts +20 -0
  71. package/dist/controller/utils.js +35 -0
  72. package/dist/delivery/categorize/__tests__/categories.test.d.ts +1 -0
  73. package/dist/delivery/categorize/__tests__/category.test.d.ts +1 -0
  74. package/dist/delivery/categorize/__tests__/choice.test.d.ts +1 -0
  75. package/dist/delivery/categorize/__tests__/choices.test.d.ts +1 -0
  76. package/dist/delivery/categorize/__tests__/droppable-placeholder.test.d.ts +1 -0
  77. package/dist/delivery/categorize/__tests__/grid-content.test.d.ts +1 -0
  78. package/dist/delivery/categorize/__tests__/index.test.d.ts +1 -0
  79. package/dist/delivery/categorize/__tests__/keyboard-coordinates.test.d.ts +1 -0
  80. package/dist/delivery/categorize/categories.d.ts +37 -0
  81. package/dist/delivery/categorize/categories.js +72 -0
  82. package/dist/delivery/categorize/category.d.ts +31 -0
  83. package/dist/delivery/categorize/category.js +55 -0
  84. package/dist/delivery/categorize/choice.d.ts +28 -0
  85. package/dist/delivery/categorize/choice.js +114 -0
  86. package/dist/delivery/categorize/choices.d.ts +42 -0
  87. package/dist/delivery/categorize/choices.js +58 -0
  88. package/dist/delivery/categorize/droppable-placeholder.d.ts +36 -0
  89. package/dist/delivery/categorize/droppable-placeholder.js +77 -0
  90. package/dist/delivery/categorize/grid-content.d.ts +25 -0
  91. package/dist/delivery/categorize/grid-content.js +39 -0
  92. package/dist/delivery/categorize/index.d.ts +70 -0
  93. package/dist/delivery/categorize/index.js +323 -0
  94. package/dist/delivery/categorize/keyboard-coordinates.d.ts +22 -0
  95. package/dist/delivery/categorize/keyboard-coordinates.js +49 -0
  96. package/dist/delivery/index.d.ts +27 -0
  97. package/dist/delivery/index.js +154 -0
  98. package/dist/index.d.ts +1 -0
  99. package/dist/index.iife.d.ts +8 -0
  100. package/dist/index.iife.js +152 -0
  101. package/dist/index.js +2 -0
  102. package/dist/runtime-support.d.ts +12 -0
  103. package/dist/runtime-support.js +12 -0
  104. package/package.json +96 -23
  105. package/CHANGELOG.json +0 -1637
  106. package/CHANGELOG.md +0 -2591
  107. package/LICENSE.md +0 -5
  108. package/README.md +0 -5
  109. package/configure/CHANGELOG.json +0 -1202
  110. package/configure/CHANGELOG.md +0 -2170
  111. package/configure/lib/__tests__/main.test.js +0 -100
  112. package/configure/lib/__tests__/utils.js +0 -39
  113. package/configure/lib/defaults.js +0 -220
  114. package/configure/lib/defaults.js.map +0 -1
  115. package/configure/lib/design/__tests__/builder.test.js +0 -34
  116. package/configure/lib/design/__tests__/buttons.test.js +0 -36
  117. package/configure/lib/design/__tests__/header.test.js +0 -37
  118. package/configure/lib/design/__tests__/index.test.js +0 -269
  119. package/configure/lib/design/__tests__/input-header.test.js +0 -41
  120. package/configure/lib/design/builder.js +0 -55
  121. package/configure/lib/design/builder.js.map +0 -1
  122. package/configure/lib/design/buttons.js +0 -59
  123. package/configure/lib/design/buttons.js.map +0 -1
  124. package/configure/lib/design/categories/RowLabel.js +0 -66
  125. package/configure/lib/design/categories/RowLabel.js.map +0 -1
  126. package/configure/lib/design/categories/__tests__/alternateResponses.test.js +0 -93
  127. package/configure/lib/design/categories/__tests__/category.test.js +0 -65
  128. package/configure/lib/design/categories/__tests__/choice-preview.test.js +0 -52
  129. package/configure/lib/design/categories/__tests__/droppable-placeholder.test.js +0 -63
  130. package/configure/lib/design/categories/__tests__/index.test.js +0 -91
  131. package/configure/lib/design/categories/alternateResponses.js +0 -116
  132. package/configure/lib/design/categories/alternateResponses.js.map +0 -1
  133. package/configure/lib/design/categories/category.js +0 -153
  134. package/configure/lib/design/categories/category.js.map +0 -1
  135. package/configure/lib/design/categories/choice-preview.js +0 -79
  136. package/configure/lib/design/categories/choice-preview.js.map +0 -1
  137. package/configure/lib/design/categories/droppable-placeholder.js +0 -93
  138. package/configure/lib/design/categories/droppable-placeholder.js.map +0 -1
  139. package/configure/lib/design/categories/index.js +0 -256
  140. package/configure/lib/design/categories/index.js.map +0 -1
  141. package/configure/lib/design/choices/__tests__/choice.test.js +0 -62
  142. package/configure/lib/design/choices/__tests__/config.test.js +0 -66
  143. package/configure/lib/design/choices/__tests__/index.test.js +0 -70
  144. package/configure/lib/design/choices/choice.js +0 -187
  145. package/configure/lib/design/choices/choice.js.map +0 -1
  146. package/configure/lib/design/choices/config.js +0 -58
  147. package/configure/lib/design/choices/config.js.map +0 -1
  148. package/configure/lib/design/choices/index.js +0 -197
  149. package/configure/lib/design/choices/index.js.map +0 -1
  150. package/configure/lib/design/header.js +0 -71
  151. package/configure/lib/design/header.js.map +0 -1
  152. package/configure/lib/design/index.js +0 -741
  153. package/configure/lib/design/index.js.map +0 -1
  154. package/configure/lib/design/input-header.js +0 -105
  155. package/configure/lib/design/input-header.js.map +0 -1
  156. package/configure/lib/design/utils.js +0 -12
  157. package/configure/lib/design/utils.js.map +0 -1
  158. package/configure/lib/index.js +0 -148
  159. package/configure/lib/index.js.map +0 -1
  160. package/configure/lib/main.js +0 -44
  161. package/configure/lib/main.js.map +0 -1
  162. package/configure/lib/utils.js +0 -43
  163. package/configure/lib/utils.js.map +0 -1
  164. package/configure/package.json +0 -32
  165. package/controller/CHANGELOG.json +0 -452
  166. package/controller/CHANGELOG.md +0 -1424
  167. package/controller/lib/__tests__/index.test.js +0 -526
  168. package/controller/lib/defaults.js +0 -31
  169. package/controller/lib/defaults.js.map +0 -1
  170. package/controller/lib/index.js +0 -506
  171. package/controller/lib/index.js.map +0 -1
  172. package/controller/lib/utils.js +0 -69
  173. package/controller/lib/utils.js.map +0 -1
  174. package/controller/package.json +0 -18
  175. package/docs/config-schema.json +0 -2897
  176. package/docs/config-schema.json.md +0 -2138
  177. package/docs/demo/.pie/.configure/package.json +0 -10
  178. package/docs/demo/.pie/.configure/yarn.lock +0 -2122
  179. package/docs/demo/.pie/.controllers/package.json +0 -10
  180. package/docs/demo/.pie/.controllers/yarn.lock +0 -110
  181. package/docs/demo/.pie/info.entry.js +0 -89
  182. package/docs/demo/.pie/info.webpack.config.js +0 -119
  183. package/docs/demo/.pie/package.json +0 -10
  184. package/docs/demo/.pie/yarn.lock +0 -2137
  185. package/docs/demo/config.js +0 -8
  186. package/docs/demo/generate.js +0 -357
  187. package/docs/demo/index.html +0 -1
  188. package/docs/demo/pie.manifest.json +0 -11
  189. package/docs/demo/session.js +0 -12
  190. package/docs/pie-schema.json +0 -1784
  191. package/docs/pie-schema.json.md +0 -1046
  192. package/lib/__tests__/index.test.js +0 -197
  193. package/lib/categorize/__tests__/categories.test.js +0 -138
  194. package/lib/categorize/__tests__/category.test.js +0 -137
  195. package/lib/categorize/__tests__/choice.test.js +0 -88
  196. package/lib/categorize/__tests__/choices.test.js +0 -118
  197. package/lib/categorize/__tests__/droppable-placeholder.test.js +0 -96
  198. package/lib/categorize/__tests__/grid-content.test.js +0 -48
  199. package/lib/categorize/__tests__/index.test.js +0 -250
  200. package/lib/categorize/categories.js +0 -135
  201. package/lib/categorize/categories.js.map +0 -1
  202. package/lib/categorize/category.js +0 -67
  203. package/lib/categorize/category.js.map +0 -1
  204. package/lib/categorize/choice.js +0 -140
  205. package/lib/categorize/choice.js.map +0 -1
  206. package/lib/categorize/choices.js +0 -99
  207. package/lib/categorize/choices.js.map +0 -1
  208. package/lib/categorize/droppable-placeholder.js +0 -84
  209. package/lib/categorize/droppable-placeholder.js.map +0 -1
  210. package/lib/categorize/grid-content.js +0 -55
  211. package/lib/categorize/grid-content.js.map +0 -1
  212. package/lib/categorize/index.js +0 -450
  213. package/lib/categorize/index.js.map +0 -1
  214. package/lib/index.js +0 -316
  215. package/lib/index.js.map +0 -1
@@ -0,0 +1,323 @@
1
+ import e from "./choice.js";
2
+ import { Choices as t } from "./choices.js";
3
+ import { Categories as n } from "./categories.js";
4
+ import { closestDroppableKeyboardCoordinates as r } from "./keyboard-coordinates.js";
5
+ import i from "react";
6
+ import { renderMath as a } from "@pie-element/shared-math-rendering-mathjax";
7
+ import * as o from "@pie-lib/render-ui";
8
+ import { Collapsible as s, Feedback as c, PreviewPrompt as l, UiLayout as u, color as d, hasMedia as f, hasText as p } from "@pie-lib/render-ui";
9
+ import m from "prop-types";
10
+ import h from "debug";
11
+ import { styled as g } from "@mui/material/styles";
12
+ import { DragOverlay as _ } from "@dnd-kit/core";
13
+ import { restrictToFirstScrollableAncestor as v } from "@dnd-kit/modifiers";
14
+ import y from "@pie-lib/correct-answer-toggle";
15
+ import { buildState as b, moveChoiceToCategory as x, removeChoiceFromCategory as S } from "@pie-lib/categorize";
16
+ import { DragProvider as C, uid as w } from "@pie-lib/drag";
17
+ import { jsx as T, jsxs as E } from "react/jsx-runtime";
18
+ import D from "@pie-lib/translator";
19
+ import { AlertDialog as O } from "@pie-lib/config-ui";
20
+ //#region src/delivery/categorize/index.tsx
21
+ function k(e) {
22
+ return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
23
+ }
24
+ function A(e, t) {
25
+ 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;
26
+ }
27
+ var j = A(u, "UiLayout") || A(L.UiLayout, "UiLayout"), M = A(l, "PreviewPrompt") || A(L.PreviewPrompt, "PreviewPrompt"), N = A(s, "Collapsible") || A(L.Collapsible, "Collapsible"), P = A(c, "Feedback") || A(L.Feedback, "Feedback"), F = o, I = F.default, L = I && typeof I == "object" ? I : F, { translator: R } = D, z = h("@pie-ui:categorize"), B = "choices-board", V = 250, H = class extends i.Component {
28
+ static propTypes = { children: m.node };
29
+ containerRef = i.createRef();
30
+ componentDidMount() {
31
+ this.containerRef.current && a(this.containerRef.current);
32
+ }
33
+ render() {
34
+ return /* @__PURE__ */ T("div", {
35
+ ref: this.containerRef,
36
+ children: this.props.children
37
+ });
38
+ }
39
+ }, U = class extends i.Component {
40
+ static propTypes = {
41
+ model: m.object,
42
+ session: m.shape({ answers: m.arrayOf(m.shape({
43
+ choice: m.string,
44
+ category: m.string
45
+ })) }),
46
+ onAnswersChange: m.func.isRequired,
47
+ onShowCorrectToggle: m.func.isRequired,
48
+ pauseMathObserver: m.func,
49
+ resumeMathObserver: m.func,
50
+ selectedItem: m.object,
51
+ onSelectClick: m.func,
52
+ onPlacementClick: m.func
53
+ };
54
+ static defaultProps = { disabled: !1 };
55
+ constructor(e) {
56
+ super(e), this.state = {
57
+ showCorrect: !1,
58
+ showMaxChoiceAlert: !1
59
+ };
60
+ }
61
+ removeChoice = (e) => {
62
+ z("[removeChoice]: ", e);
63
+ let { onAnswersChange: t, session: n } = this.props;
64
+ t(S(e.id, e.categoryId, e.choiceIndex, n.answers));
65
+ };
66
+ dropChoice = (e, t) => {
67
+ let { session: n, onAnswersChange: r, model: i } = this.props, { maxChoicesPerCategory: a = 0 } = i || {}, { answers: o = [] } = n || {}, s;
68
+ t ? z("[dropChoice] category: ", t.categoryId, "choice: ", t) : z("[dropChoice] category: ", void 0, "choice: ", void 0);
69
+ let c = o.find((t) => t.category === e);
70
+ t && a === 1 && c && c.choices && c.choices.length === 1 ? (s = x(t.id, t.categoryId, e, t.choiceIndex, o), s = S(c.choices[0], e, 0, s)) : t && a > 1 && c && c.choices && c.choices.length === a ? (s = t.categoryId ? x(t.id, t.categoryId, t.categoryId, t.choiceIndex, o) : S(t.id, t.categoryId, t.choiceIndex, o), this.setState({ showMaxChoiceAlert: !0 })) : a !== 0 && c && c.choices && c.choices.length > a ? (s = o, this.setState({ showMaxChoiceAlert: !0 })) : s = t ? x(t.id, t.categoryId, e, t.choiceIndex, o) : this.removeChoice(e), t && r(s);
71
+ };
72
+ UNSAFE_componentWillReceiveProps(e) {
73
+ let { model: t } = this.props, { model: n } = e;
74
+ t.note && t.language && t.language !== n.language && t.note === R.t("common:commonCorrectAnswerWithAlternates", { lng: t.language }) && (t.note = R.t("common:commonCorrectAnswerWithAlternates", { lng: n.language })), this.setState({ showCorrect: !1 });
75
+ }
76
+ toggleShowCorrect = () => this.setState({ showCorrect: !this.state.showCorrect }, () => {
77
+ this.props.onShowCorrectToggle();
78
+ });
79
+ getPositionDirection = (e) => {
80
+ let t;
81
+ switch (e) {
82
+ case "left":
83
+ t = "row-reverse";
84
+ break;
85
+ case "right":
86
+ t = "row";
87
+ break;
88
+ case "below":
89
+ t = "column";
90
+ break;
91
+ default:
92
+ t = "column-reverse";
93
+ break;
94
+ }
95
+ return t;
96
+ };
97
+ existAlternateResponse = (e) => e?.some((e) => e.alternateResponses?.length > 0);
98
+ render() {
99
+ let { model: e, session: r, selectedItem: a, onSelectClick: o, onPlacementClick: s } = this.props, { showCorrect: c, showMaxChoiceAlert: l } = this.state, { choicesPosition: u, extraCSSRules: d, note: m, showNote: h, env: g, language: _, maxChoicesPerCategory: v, autoplayAudioEnabled: x, customAudioButton: S } = e, { mode: C, role: w } = g || {}, D = u || "above", k = {
100
+ flexDirection: this.getPositionDirection(D),
101
+ gap: "8px"
102
+ }, { categories: A, choices: j, correct: N } = b(e.categories, e.choices, c ? e.correctResponse : r.answers, e.correctResponse);
103
+ z("[render] disabled: ", e.disabled);
104
+ let { rowLabels: F, categoriesPerRow: I, correctResponse: L, fontSizeFactor: B } = e, V = A && Math.ceil(A.length / I) || 0, H = this.existAlternateResponse(L) || !1, U = (c || C === "view" && w === "instructor") && h && m && H, W = R.t("translation:categorize:limitMaxChoicesPerCategory", {
105
+ lng: e.language,
106
+ maxChoicesPerCategory: v
107
+ }), X = R.t("common:warning", { lng: e.language }), Z = R.t("common:cancel", { lng: e.language }), Q = e.rationale && (p(e.rationale) || f(e.rationale));
108
+ return /* @__PURE__ */ E(G, {
109
+ extraCSSRules: d,
110
+ id: "main-container",
111
+ fontSizeFactor: B,
112
+ children: [
113
+ e.teacherInstructions && (p(e.teacherInstructions) || f(e.teacherInstructions)) && /* @__PURE__ */ T(i.Fragment, { children: /* @__PURE__ */ T(Y, {
114
+ labels: {
115
+ hidden: "Show Teacher Instructions",
116
+ visible: "Hide Teacher Instructions"
117
+ },
118
+ children: /* @__PURE__ */ T(M, { prompt: e.teacherInstructions })
119
+ }) }),
120
+ e.prompt && /* @__PURE__ */ T(M, {
121
+ prompt: e.prompt,
122
+ autoplayAudioEnabled: x,
123
+ customAudioButton: S
124
+ }),
125
+ /* @__PURE__ */ T(y, {
126
+ show: c || N === !1,
127
+ toggled: c,
128
+ onToggle: this.toggleShowCorrect,
129
+ language: _
130
+ }),
131
+ /* @__PURE__ */ T(q, { children: /* @__PURE__ */ E(J, {
132
+ style: k,
133
+ children: [/* @__PURE__ */ T("div", {
134
+ style: {
135
+ display: "flex",
136
+ flex: 1
137
+ },
138
+ children: /* @__PURE__ */ T(n, {
139
+ model: e,
140
+ disabled: e.disabled,
141
+ categories: A,
142
+ onDropChoice: this.dropChoice,
143
+ onRemoveChoice: this.removeChoice,
144
+ rowLabels: (F || []).slice(0, V),
145
+ selectedItem: a,
146
+ onSelectClick: o,
147
+ onPlacementClick: s
148
+ })
149
+ }), /* @__PURE__ */ T(t, {
150
+ disabled: e.disabled,
151
+ model: e,
152
+ choices: j,
153
+ choicePosition: D,
154
+ onDropChoice: this.dropChoice,
155
+ onRemoveChoice: this.removeChoice,
156
+ correct: N,
157
+ selectedItem: a,
158
+ onSelectClick: o,
159
+ onPlacementClick: s
160
+ })]
161
+ }) }),
162
+ U && /* @__PURE__ */ T(K, { dangerouslySetInnerHTML: { __html: m } }),
163
+ Q && /* @__PURE__ */ T(Y, {
164
+ labels: {
165
+ hidden: "Show Rationale",
166
+ visible: "Hide Rationale"
167
+ },
168
+ children: /* @__PURE__ */ T(M, { prompt: e.rationale })
169
+ }),
170
+ e.correctness && e.feedback && !c && /* @__PURE__ */ T(P, {
171
+ correctness: e.correctness,
172
+ feedback: e.feedback
173
+ }),
174
+ /* @__PURE__ */ T(O, {
175
+ title: X,
176
+ text: W,
177
+ open: l,
178
+ onCloseText: Z,
179
+ onClose: () => this.setState({ showMaxChoiceAlert: !1 })
180
+ })
181
+ ]
182
+ });
183
+ }
184
+ }, W = class extends i.Component {
185
+ static propTypes = {
186
+ model: m.object,
187
+ session: m.shape({ answers: m.arrayOf(m.shape({
188
+ choice: m.string,
189
+ category: m.string
190
+ })) }),
191
+ onAnswersChange: m.func.isRequired,
192
+ onShowCorrectToggle: m.func.isRequired,
193
+ pauseMathObserver: m.func,
194
+ resumeMathObserver: m.func
195
+ };
196
+ constructor(e) {
197
+ super(e), this.uid = w.generateId(), this.state = {
198
+ activeDragItem: null,
199
+ isValidDrop: !1,
200
+ selectedItem: null
201
+ }, this.lastDragEndAt = 0, this.isInternalDragCancel = !1;
202
+ }
203
+ onDragStart = (e) => {
204
+ let { active: t } = e, { pauseMathObserver: n } = this.props;
205
+ n && n(), t?.data?.current && this.setState({
206
+ activeDragItem: t.data.current,
207
+ isValidDrop: !1,
208
+ selectedItem: t.data.current
209
+ });
210
+ };
211
+ commitPlacement = (e, t) => {
212
+ if (this.categorizeRef) {
213
+ if (t === void 0 || t === B) {
214
+ e.categoryId && this.categorizeRef.removeChoice && this.categorizeRef.removeChoice(e);
215
+ return;
216
+ }
217
+ this.categorizeRef.dropChoice && this.categorizeRef.dropChoice(t, e);
218
+ }
219
+ };
220
+ onDragEnd = (e) => {
221
+ let { active: t, over: n } = e, { resumeMathObserver: r } = this.props, i = t?.data?.current, a = n?.data?.current, o = n && t && i && i.type === "choice" && a && a.itemType === "categorize";
222
+ if (this.setState({
223
+ activeDragItem: null,
224
+ isValidDrop: o,
225
+ selectedItem: null
226
+ }), r && r(), this.lastDragEndAt = Date.now(), !t || !i || i.type !== "choice") return;
227
+ let s = {
228
+ id: i.id,
229
+ categoryId: i.categoryId,
230
+ choiceIndex: i.choiceIndex,
231
+ value: i.value,
232
+ itemType: i.itemType
233
+ };
234
+ this.commitPlacement(s, n ? n.id : void 0);
235
+ };
236
+ onDragCancel = () => {
237
+ let { resumeMathObserver: e } = this.props;
238
+ this.setState({
239
+ activeDragItem: null,
240
+ isValidDrop: !1,
241
+ selectedItem: null
242
+ }), e && e(), this.isInternalDragCancel ? this.isInternalDragCancel = !1 : this.lastDragEndAt = Date.now();
243
+ };
244
+ isSameItem = (e, t) => !!e && !!t && e.id === t.id && e.categoryId === t.categoryId && e.choiceIndex === t.choiceIndex;
245
+ toggleItemSelection = (e) => {
246
+ this.setState((t) => ({ selectedItem: this.isSameItem(t.selectedItem, e) ? null : e }));
247
+ };
248
+ cancelSelection = () => {
249
+ this.setState({ selectedItem: null });
250
+ };
251
+ endAnyLiveKeyboardDrag = () => {
252
+ this.state.activeDragItem && (this.isInternalDragCancel = !0, document.dispatchEvent(new KeyboardEvent("keydown", {
253
+ code: "Escape",
254
+ bubbles: !0,
255
+ cancelable: !0
256
+ })), this.isInternalDragCancel = !1);
257
+ };
258
+ placeSelectedItem = (e) => {
259
+ let { selectedItem: t } = this.state;
260
+ t && (this.commitPlacement(t, e), this.cancelSelection(), this.endAnyLiveKeyboardDrag());
261
+ };
262
+ isClickSoonAfterDragEnd = () => Date.now() - this.lastDragEndAt < V;
263
+ onItemClick = (e) => {
264
+ this.isClickSoonAfterDragEnd() || (this.endAnyLiveKeyboardDrag(), this.toggleItemSelection(e));
265
+ };
266
+ onPlacementClick = (e) => {
267
+ this.isClickSoonAfterDragEnd() || this.placeSelectedItem(e);
268
+ };
269
+ renderDragOverlay = () => {
270
+ let { activeDragItem: t } = this.state, { model: n } = this.props;
271
+ if (!t) return null;
272
+ if (t.type === "choice") {
273
+ let r = n.choices?.find((e) => e.id === t.id);
274
+ if (r) return /* @__PURE__ */ T(e, {
275
+ id: r.id,
276
+ ...r
277
+ }, r.id);
278
+ }
279
+ return null;
280
+ };
281
+ render() {
282
+ let { isValidDrop: e, selectedItem: t } = this.state, n = e ? null : void 0;
283
+ return /* @__PURE__ */ T(C, {
284
+ onDragStart: this.onDragStart,
285
+ onDragEnd: this.onDragEnd,
286
+ onDragCancel: this.onDragCancel,
287
+ keyboardCoordinateGetter: r,
288
+ keyboardCodes: {
289
+ start: ["Space", "Enter"],
290
+ cancel: ["Escape"],
291
+ end: ["Space", "Enter"]
292
+ },
293
+ modifiers: [v],
294
+ children: /* @__PURE__ */ E(w.Provider, {
295
+ value: this.uid,
296
+ children: [/* @__PURE__ */ T(U, {
297
+ ref: (e) => this.categorizeRef = e,
298
+ ...this.props,
299
+ selectedItem: t,
300
+ onSelectClick: this.onItemClick,
301
+ onPlacementClick: this.onPlacementClick
302
+ }), /* @__PURE__ */ T(_, {
303
+ dropAnimation: n,
304
+ children: /* @__PURE__ */ T(H, { children: this.renderDragOverlay() })
305
+ })]
306
+ })
307
+ });
308
+ }
309
+ }, G = g(j)({
310
+ color: d.text(),
311
+ backgroundColor: d.background(),
312
+ position: "relative"
313
+ }), K = g("div")(({ theme: e }) => ({ marginBottom: e.spacing(2) })), q = g("div")(({ theme: e }) => ({
314
+ marginBottom: e.spacing(1),
315
+ maxWidth: "100%",
316
+ overflowX: "auto",
317
+ overflowY: "hidden"
318
+ })), J = g("div")(() => ({
319
+ display: "flex",
320
+ minWidth: "min-content"
321
+ })), Y = g(N)(({ theme: e }) => ({ paddingBottom: e.spacing(2) }));
322
+ //#endregion
323
+ export { U as Categorize, W as default };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/categorize/src/categorize/keyboard-coordinates.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
+ /**
10
+ * Custom keyboard coordinate getter for categorize's Tab-based placement.
11
+ *
12
+ * Tab/Shift+Tab cycle the dragged choice directly onto the next/previous enabled
13
+ * category, sorted by on-screen position (top-to-bottom, then left-to-right, matching the
14
+ * category grid's reading order), followed by the choices pool as a fixed last stop.
15
+ *
16
+ * Arrow keys are delegated to dnd-kit's own `defaultKeyboardCoordinateGetter`, leaving the
17
+ * existing free-form arrow-key dragging behavior completely unchanged.
18
+ */
19
+ export declare const closestDroppableKeyboardCoordinates: (event: any, { context, currentCoordinates }: {
20
+ context: any;
21
+ currentCoordinates: any;
22
+ }) => any;
@@ -0,0 +1,49 @@
1
+ import { KeyboardCode as e, defaultKeyboardCoordinateGetter as t } from "@dnd-kit/core";
2
+ //#region src/delivery/categorize/keyboard-coordinates.ts
3
+ var n = "choices-board", r = (r, { context: a, currentCoordinates: o }) => {
4
+ let { code: s } = r, c = s === e.Tab, l = s === e.Down || s === e.Up || s === e.Left || s === e.Right;
5
+ if (!c && !l) return;
6
+ if (l) return t(r, {
7
+ context: a,
8
+ currentCoordinates: o
9
+ });
10
+ r.preventDefault();
11
+ let { droppableRects: u, droppableContainers: d, collisionRect: f } = a;
12
+ if (!u || u.size === 0) return o;
13
+ let p = [], m;
14
+ for (let [e, t] of d) {
15
+ if (t?.disabled) continue;
16
+ let r = t?.node?.current?.getBoundingClientRect() ?? u.get(e);
17
+ if (!r) continue;
18
+ let i = {
19
+ x: r.left + r.width / 2,
20
+ y: r.top + r.height / 2
21
+ }, a = f?.height ?? 0, o = {
22
+ id: e,
23
+ rect: r,
24
+ dropPosition: {
25
+ x: r.left,
26
+ y: r.top + r.height / 2 - a / 2
27
+ },
28
+ center: i
29
+ };
30
+ e === n ? m = o : p.push(o);
31
+ }
32
+ if (p.length === 0 && !m) return o;
33
+ let h = r.shiftKey;
34
+ p.sort((e, t) => Math.abs(e.center.y - t.center.y) > 10 ? e.center.y - t.center.y : e.center.x - t.center.x), m && p.push(m);
35
+ let g = f ? {
36
+ x: f.left + f.width / 2,
37
+ y: f.top + f.height / 2
38
+ } : o, _ = p.findIndex((e) => g.x >= e.rect.left && g.x <= e.rect.right && g.y >= e.rect.top && g.y <= e.rect.bottom);
39
+ if (_ === -1) {
40
+ let e = Infinity;
41
+ for (let t = 0; t < p.length; t++) {
42
+ let n = i(o, p[t].dropPosition);
43
+ n < e && (e = n, _ = t);
44
+ }
45
+ }
46
+ return p[h ? (_ - 1 + p.length) % p.length : (_ + 1) % p.length].dropPosition;
47
+ }, i = (e, t) => Math.sqrt((e.x - t.x) ** 2 + (e.y - t.y) ** 2);
48
+ //#endregion
49
+ export { r as closestDroppableKeyboardCoordinates };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @synced-from pie-elements/packages/categorize/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 Categorize extends HTMLElement {
10
+ constructor();
11
+ _scheduleMathRender: any;
12
+ _initMathObserver(): void;
13
+ _disconnectMathObserver(): void;
14
+ pauseMathObserver: any;
15
+ resumeMathObserver: any;
16
+ set model(m: any);
17
+ isComplete(): any;
18
+ set session(s: any);
19
+ get session(): any;
20
+ eliminateBlindAnswersFromSession(): void;
21
+ changeAnswers(answers: any): void;
22
+ onShowCorrectToggle(): void;
23
+ _createAudioInfoToast(): HTMLDivElement;
24
+ connectedCallback(): void;
25
+ disconnectedCallback(): void;
26
+ render(): void;
27
+ }
@@ -0,0 +1,154 @@
1
+ import e from "./categorize/index.js";
2
+ import t from "react";
3
+ import { createRoot as n } from "react-dom/client";
4
+ import { renderMath as r } from "@pie-element/shared-math-rendering-mathjax";
5
+ import * as i from "@pie-lib/render-ui";
6
+ import { EnableAudioAutoplayImage as a } from "@pie-lib/render-ui";
7
+ import { ModelSetEvent as o, SessionChangedEvent as s } from "@pie-element/shared-player-events";
8
+ //#region src/delivery/index.ts
9
+ function c(e) {
10
+ return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
11
+ }
12
+ function l(e, t) {
13
+ return !e || c(e) ? e : c(e.default) ? e.default : t && c(e[t]) ? e[t] : t && c(e[t]?.default) ? e[t].default : e;
14
+ }
15
+ var u = l(a, "EnableAudioAutoplayImage") || l(p.EnableAudioAutoplayImage, "EnableAudioAutoplayImage"), d = i, f = d.default, p = f && typeof f == "object" ? f : d, m = class extends HTMLElement {
16
+ constructor() {
17
+ super(), this._root = null, this._mathObserver = null, this._mathRenderPending = !1;
18
+ }
19
+ _scheduleMathRender = () => {
20
+ this._mathRenderPending || (this._mathRenderPending = !0, requestAnimationFrame(() => {
21
+ this._mathObserver && !this._mathObserverPaused && this._mathObserver.disconnect(), r(this), this._mathRenderPending = !1, setTimeout(() => {
22
+ this._mathObserver && !this._mathObserverPaused && this._mathObserver.observe(this, {
23
+ childList: !0,
24
+ subtree: !0,
25
+ characterData: !1
26
+ });
27
+ }, 50);
28
+ }));
29
+ };
30
+ _initMathObserver() {
31
+ this._mathObserver || (this._mathObserver = new MutationObserver(() => {
32
+ this._scheduleMathRender();
33
+ }), this._mathObserver.observe(this, {
34
+ childList: !0,
35
+ subtree: !0,
36
+ characterData: !1
37
+ }));
38
+ }
39
+ _disconnectMathObserver() {
40
+ this._mathObserver &&= (this._mathObserver.disconnect(), null);
41
+ }
42
+ pauseMathObserver = () => {
43
+ this._mathObserver && (this._mathObserver.disconnect(), this._mathObserverPaused = !0);
44
+ };
45
+ resumeMathObserver = () => {
46
+ this._mathObserverPaused && (this._mathObserverPaused = !1, this._mathObserver && this._mathObserver.observe(this, {
47
+ childList: !0,
48
+ subtree: !0,
49
+ characterData: !1
50
+ }));
51
+ };
52
+ set model(e) {
53
+ this._model = e, this.eliminateBlindAnswersFromSession(), this.dispatchEvent(new o(this.tagName.toLowerCase(), this.isComplete(), !!this._model)), this._audioInitialized = !1, this.render();
54
+ }
55
+ isComplete() {
56
+ let { choices: e, completeAudioEnabled: t, hasUnplacedChoices: n, possibleResponses: r, responseAreasToBeFilled: i } = this._model || {}, a = this;
57
+ if (t && !this.audioComplete && a) {
58
+ let e = a.querySelector("audio"), t = e && e.closest(".preview-prompt");
59
+ if (e && t) return !1;
60
+ }
61
+ if (!this._session || !this._session.answers) return !1;
62
+ let { answers: o } = this._session;
63
+ if (!Array.isArray(o)) return !1;
64
+ let s = o.filter((e) => e.choices.length).length >= i;
65
+ if ((e || []).some((e) => e.categoryCount === 0) || n) return s;
66
+ let c = o.map((e) => e.choices).flat();
67
+ return (r || []).some((e) => e.every((e) => c.includes(e)));
68
+ }
69
+ set session(e) {
70
+ e && !e.answers && (e.answers = []), this._session = e, this.render();
71
+ }
72
+ get session() {
73
+ return this._session;
74
+ }
75
+ eliminateBlindAnswersFromSession() {
76
+ let { answers: e = [] } = this._session || {}, { choices: t = [] } = this._model || {}, n = t.map((e) => e.id) || [], r = e.map((e) => (e.choices = (e?.choices || []).filter((e) => n.includes(e)), e));
77
+ r.length > 0 && this.changeAnswers(r);
78
+ }
79
+ changeAnswers(e) {
80
+ this._session.answers = e, this._session.selector = "Mouse", this.dispatchEvent(new s(this.tagName.toLowerCase(), this.isComplete())), this.render();
81
+ }
82
+ onShowCorrectToggle() {
83
+ r(this);
84
+ }
85
+ _createAudioInfoToast() {
86
+ let e = document.createElement("div");
87
+ e.id = "play-audio-info", Object.assign(e.style, {
88
+ position: "absolute",
89
+ top: 0,
90
+ width: "100%",
91
+ height: "100%",
92
+ display: "flex",
93
+ justifyContent: "center",
94
+ alignItems: "center",
95
+ background: "white",
96
+ zIndex: "1000",
97
+ cursor: "pointer"
98
+ });
99
+ let t = document.createElement("img");
100
+ return t.src = u, t.alt = "Click anywhere to enable audio autoplay", t.width = 500, t.height = 300, e.appendChild(t), e;
101
+ }
102
+ connectedCallback() {
103
+ this._initMathObserver(), new MutationObserver((e, t) => {
104
+ e.forEach((e) => {
105
+ if (e.type === "childList") {
106
+ if (this._audioInitialized) return;
107
+ let e = this.querySelector("audio"), n = e && e.closest(".preview-prompt");
108
+ if (!this._model) return;
109
+ let { autoplayAudioEnabled: r, completeAudioEnabled: i } = this._model;
110
+ if (!r && !i || e && !n || !e) return;
111
+ let a = this._createAudioInfoToast(), o = this.querySelector("#main-container"), c = () => {
112
+ this.querySelector("#play-audio-info") && (e.play(), o.removeChild(a)), document.removeEventListener("click", c);
113
+ };
114
+ r && setTimeout(() => {
115
+ e.paused && !this.querySelector("#play-audio-info") ? (o.appendChild(a), document.addEventListener("click", c)) : document.removeEventListener("click", c);
116
+ }, 500);
117
+ let l = () => {
118
+ this._session.audioStartTime = this._session.audioStartTime || (/* @__PURE__ */ new Date()).getTime();
119
+ let t = this.querySelector("#play-audio-info");
120
+ t && o.removeChild(t), e.removeEventListener("playing", l);
121
+ };
122
+ e.addEventListener("playing", l);
123
+ let u = () => {
124
+ this._session.audioEndTime = this._session.audioEndTime || (/* @__PURE__ */ new Date()).getTime();
125
+ let { audioStartTime: t, audioEndTime: n, waitTime: r } = this._session;
126
+ !r && t && n && (this._session.waitTime = n - t), this.audioComplete = !0, this.dispatchEvent(new s(this.tagName.toLowerCase(), this.isComplete())), e.removeEventListener("ended", u);
127
+ };
128
+ e.addEventListener("ended", u), this._audio = e, this._handlePlaying = l, this._handleEnded = u, this._enableAudio = c, this._audioInitialized = !0, t.disconnect();
129
+ }
130
+ });
131
+ }).observe(this, {
132
+ childList: !0,
133
+ subtree: !0
134
+ }), this.render();
135
+ }
136
+ disconnectedCallback() {
137
+ this._disconnectMathObserver(), document.removeEventListener("click", this._enableAudio), this._audio &&= (this._audio.removeEventListener("playing", this._handlePlaying), this._audio.removeEventListener("ended", this._handleEnded), null), this._root &&= (this._root.unmount(), null);
138
+ }
139
+ render() {
140
+ if (this._model && this._session) {
141
+ let r = t.createElement(e, {
142
+ model: this._model,
143
+ session: this._session,
144
+ onAnswersChange: this.changeAnswers.bind(this),
145
+ onShowCorrectToggle: this.onShowCorrectToggle.bind(this),
146
+ pauseMathObserver: this.pauseMathObserver,
147
+ resumeMathObserver: this.resumeMathObserver
148
+ });
149
+ this._root ||= n(this), this._root.render(r);
150
+ }
151
+ }
152
+ };
153
+ //#endregion
154
+ export { m as default };
@@ -0,0 +1 @@
1
+ export { default } from './delivery/index.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * IIFE entry point for categorize 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;