@pie-element/categorize 13.2.0-beta.0 → 13.2.0-next.10

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 (202) 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 +43167 -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 +85 -22
  92. package/CHANGELOG.json +0 -1637
  93. package/CHANGELOG.md +0 -2551
  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 -2130
  98. package/configure/lib/__tests__/main.test.js +0 -100
  99. package/configure/lib/__tests__/utils.js +0 -39
  100. package/configure/lib/defaults.js +0 -220
  101. package/configure/lib/defaults.js.map +0 -1
  102. package/configure/lib/design/__tests__/builder.test.js +0 -34
  103. package/configure/lib/design/__tests__/buttons.test.js +0 -36
  104. package/configure/lib/design/__tests__/header.test.js +0 -37
  105. package/configure/lib/design/__tests__/index.test.js +0 -269
  106. package/configure/lib/design/__tests__/input-header.test.js +0 -41
  107. package/configure/lib/design/builder.js +0 -55
  108. package/configure/lib/design/builder.js.map +0 -1
  109. package/configure/lib/design/buttons.js +0 -59
  110. package/configure/lib/design/buttons.js.map +0 -1
  111. package/configure/lib/design/categories/RowLabel.js +0 -66
  112. package/configure/lib/design/categories/RowLabel.js.map +0 -1
  113. package/configure/lib/design/categories/__tests__/alternateResponses.test.js +0 -93
  114. package/configure/lib/design/categories/__tests__/category.test.js +0 -65
  115. package/configure/lib/design/categories/__tests__/choice-preview.test.js +0 -52
  116. package/configure/lib/design/categories/__tests__/droppable-placeholder.test.js +0 -63
  117. package/configure/lib/design/categories/__tests__/index.test.js +0 -91
  118. package/configure/lib/design/categories/alternateResponses.js +0 -116
  119. package/configure/lib/design/categories/alternateResponses.js.map +0 -1
  120. package/configure/lib/design/categories/category.js +0 -153
  121. package/configure/lib/design/categories/category.js.map +0 -1
  122. package/configure/lib/design/categories/choice-preview.js +0 -79
  123. package/configure/lib/design/categories/choice-preview.js.map +0 -1
  124. package/configure/lib/design/categories/droppable-placeholder.js +0 -93
  125. package/configure/lib/design/categories/droppable-placeholder.js.map +0 -1
  126. package/configure/lib/design/categories/index.js +0 -256
  127. package/configure/lib/design/categories/index.js.map +0 -1
  128. package/configure/lib/design/choices/__tests__/choice.test.js +0 -62
  129. package/configure/lib/design/choices/__tests__/config.test.js +0 -66
  130. package/configure/lib/design/choices/__tests__/index.test.js +0 -70
  131. package/configure/lib/design/choices/choice.js +0 -187
  132. package/configure/lib/design/choices/choice.js.map +0 -1
  133. package/configure/lib/design/choices/config.js +0 -58
  134. package/configure/lib/design/choices/config.js.map +0 -1
  135. package/configure/lib/design/choices/index.js +0 -197
  136. package/configure/lib/design/choices/index.js.map +0 -1
  137. package/configure/lib/design/header.js +0 -71
  138. package/configure/lib/design/header.js.map +0 -1
  139. package/configure/lib/design/index.js +0 -741
  140. package/configure/lib/design/index.js.map +0 -1
  141. package/configure/lib/design/input-header.js +0 -105
  142. package/configure/lib/design/input-header.js.map +0 -1
  143. package/configure/lib/design/utils.js +0 -12
  144. package/configure/lib/design/utils.js.map +0 -1
  145. package/configure/lib/index.js +0 -148
  146. package/configure/lib/index.js.map +0 -1
  147. package/configure/lib/main.js +0 -44
  148. package/configure/lib/main.js.map +0 -1
  149. package/configure/lib/utils.js +0 -43
  150. package/configure/lib/utils.js.map +0 -1
  151. package/configure/package.json +0 -32
  152. package/controller/CHANGELOG.json +0 -452
  153. package/controller/CHANGELOG.md +0 -1384
  154. package/controller/lib/__tests__/index.test.js +0 -526
  155. package/controller/lib/defaults.js +0 -31
  156. package/controller/lib/defaults.js.map +0 -1
  157. package/controller/lib/index.js +0 -506
  158. package/controller/lib/index.js.map +0 -1
  159. package/controller/lib/utils.js +0 -69
  160. package/controller/lib/utils.js.map +0 -1
  161. package/controller/package.json +0 -18
  162. package/docs/config-schema.json +0 -2897
  163. package/docs/config-schema.json.md +0 -2138
  164. package/docs/demo/.pie/.configure/package.json +0 -10
  165. package/docs/demo/.pie/.configure/yarn.lock +0 -2122
  166. package/docs/demo/.pie/.controllers/package.json +0 -10
  167. package/docs/demo/.pie/.controllers/yarn.lock +0 -110
  168. package/docs/demo/.pie/info.entry.js +0 -89
  169. package/docs/demo/.pie/info.webpack.config.js +0 -119
  170. package/docs/demo/.pie/package.json +0 -10
  171. package/docs/demo/.pie/yarn.lock +0 -2137
  172. package/docs/demo/config.js +0 -8
  173. package/docs/demo/generate.js +0 -357
  174. package/docs/demo/index.html +0 -1
  175. package/docs/demo/pie.manifest.json +0 -11
  176. package/docs/demo/session.js +0 -12
  177. package/docs/pie-schema.json +0 -1784
  178. package/docs/pie-schema.json.md +0 -1046
  179. package/lib/__tests__/index.test.js +0 -197
  180. package/lib/categorize/__tests__/categories.test.js +0 -138
  181. package/lib/categorize/__tests__/category.test.js +0 -137
  182. package/lib/categorize/__tests__/choice.test.js +0 -88
  183. package/lib/categorize/__tests__/choices.test.js +0 -118
  184. package/lib/categorize/__tests__/droppable-placeholder.test.js +0 -96
  185. package/lib/categorize/__tests__/grid-content.test.js +0 -48
  186. package/lib/categorize/__tests__/index.test.js +0 -250
  187. package/lib/categorize/categories.js +0 -135
  188. package/lib/categorize/categories.js.map +0 -1
  189. package/lib/categorize/category.js +0 -67
  190. package/lib/categorize/category.js.map +0 -1
  191. package/lib/categorize/choice.js +0 -140
  192. package/lib/categorize/choice.js.map +0 -1
  193. package/lib/categorize/choices.js +0 -99
  194. package/lib/categorize/choices.js.map +0 -1
  195. package/lib/categorize/droppable-placeholder.js +0 -84
  196. package/lib/categorize/droppable-placeholder.js.map +0 -1
  197. package/lib/categorize/grid-content.js +0 -55
  198. package/lib/categorize/grid-content.js.map +0 -1
  199. package/lib/categorize/index.js +0 -450
  200. package/lib/categorize/index.js.map +0 -1
  201. package/lib/index.js +0 -316
  202. package/lib/index.js.map +0 -1
@@ -1,741 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.Design = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _utils = require("./utils");
10
- var _react = _interopRequireDefault(require("react"));
11
- var _propTypes = _interopRequireDefault(require("prop-types"));
12
- var _styles = require("@mui/material/styles");
13
- var _core = require("@dnd-kit/core");
14
- var _configUi = require("@pie-lib/config-ui");
15
- var _categorize = require("@pie-lib/categorize");
16
- var _editableHtmlTipTap = _interopRequireDefault(require("@pie-lib/editable-html-tip-tap"));
17
- var _drag = require("@pie-lib/drag");
18
- var _mathRendering = require("@pie-lib/math-rendering");
19
- var _categories = _interopRequireDefault(require("./categories"));
20
- var _alternateResponses = _interopRequireDefault(require("./categories/alternateResponses"));
21
- var _choices = _interopRequireDefault(require("./choices"));
22
- var _choice = _interopRequireDefault(require("./choices/choice"));
23
- var _choicePreview = _interopRequireDefault(require("./categories/choice-preview"));
24
- var _builder = require("./builder");
25
- var _header = _interopRequireDefault(require("./header"));
26
- var _utils2 = require("../utils");
27
- var _translator = _interopRequireDefault(require("@pie-lib/translator"));
28
- const {
29
- translator
30
- } = _translator.default;
31
- const {
32
- dropdown,
33
- Panel,
34
- toggle,
35
- radio,
36
- numberField
37
- } = _configUi.settings;
38
- const {
39
- Provider: IdProvider
40
- } = _drag.uid;
41
-
42
- // Simple wrapper to render math in DragOverlay portal
43
- class DragPreviewWrapper extends _react.default.Component {
44
- constructor(...args) {
45
- super(...args);
46
- (0, _defineProperty2.default)(this, "containerRef", /*#__PURE__*/_react.default.createRef());
47
- }
48
- componentDidMount() {
49
- if (this.containerRef.current) {
50
- setTimeout(() => (0, _mathRendering.renderMath)(this.containerRef.current), 0);
51
- }
52
- }
53
- render() {
54
- return /*#__PURE__*/_react.default.createElement("div", {
55
- ref: this.containerRef
56
- }, this.props.children);
57
- }
58
- }
59
- const StyledHeader = (0, _styles.styled)(_header.default)(({
60
- theme
61
- }) => ({
62
- marginBottom: theme.spacing(2)
63
- }));
64
- const StyledInputContainer = (0, _styles.styled)(_configUi.InputContainer)(({
65
- theme
66
- }) => ({
67
- width: '100%',
68
- paddingTop: theme.spacing(1),
69
- marginTop: theme.spacing(1),
70
- marginBottom: theme.spacing(2)
71
- }));
72
- const ErrorText = (0, _styles.styled)('div')(({
73
- theme
74
- }) => ({
75
- fontSize: theme.typography.fontSize - 2,
76
- color: theme.palette.error.main,
77
- paddingTop: theme.spacing(1)
78
- }));
79
- class Design extends _react.default.Component {
80
- constructor(_props) {
81
- super(_props);
82
- (0, _defineProperty2.default)(this, "updateModel", props => {
83
- const {
84
- model,
85
- onChange
86
- } = this.props;
87
- const updatedModel = {
88
- ...model,
89
- ...props
90
- };
91
- updatedModel.choices = updatedModel.choices.map(c => ({
92
- ...c,
93
- categoryCount: this.checkAllowMultiplePlacements(updatedModel.allowMultiplePlacementsEnabled, c)
94
- }));
95
-
96
- //Ensure that there are no extra choices in correctResponse, if the user has decided that only one choice may be used.
97
- updatedModel.correctResponse = (0, _categorize.ensureNoExtraChoicesInAnswer)(updatedModel.correctResponse || [], updatedModel.choices);
98
-
99
- //Ensure that there are no extra choices in alternate responses, if the user has decided that only one choice may be used.
100
- updatedModel.correctResponse = (0, _categorize.ensureNoExtraChoicesInAlternate)(updatedModel.correctResponse || [], updatedModel.choices);
101
-
102
- //clean categories
103
- updatedModel.categories = updatedModel.categories.map(c => ({
104
- id: c.id,
105
- label: c.label
106
- }));
107
- updatedModel.choices = updatedModel.choices.map(h => ({
108
- id: h.id,
109
- content: h.content,
110
- categoryCount: h.categoryCount
111
- }));
112
-
113
- // ensure that maxChoicesPerCategory is reset if author switch back the corresponding switch (allowMaxChoicesPerCategory)
114
- updatedModel.maxChoicesPerCategory = updatedModel.allowMaxChoicesPerCategory ? updatedModel.maxChoicesPerCategory : 0;
115
- onChange(updatedModel);
116
- });
117
- (0, _defineProperty2.default)(this, "changeRationale", rationale => {
118
- const {
119
- model,
120
- onChange
121
- } = this.props;
122
- onChange({
123
- ...model,
124
- rationale
125
- });
126
- });
127
- (0, _defineProperty2.default)(this, "changeTeacherInstructions", teacherInstructions => {
128
- const {
129
- model,
130
- onChange
131
- } = this.props;
132
- onChange({
133
- ...model,
134
- teacherInstructions
135
- });
136
- });
137
- (0, _defineProperty2.default)(this, "changeFeedback", feedback => {
138
- this.updateModel({
139
- feedback
140
- });
141
- });
142
- (0, _defineProperty2.default)(this, "onAddAlternateResponse", () => {
143
- const {
144
- model: {
145
- correctResponse
146
- }
147
- } = this.props;
148
- this.updateModel({
149
- correctResponse: (correctResponse || []).map(cr => ({
150
- ...cr,
151
- alternateResponses: [...(cr.alternateResponses || []), []]
152
- }))
153
- });
154
- });
155
- (0, _defineProperty2.default)(this, "onPromptChanged", prompt => this.updateModel({
156
- prompt
157
- }));
158
- (0, _defineProperty2.default)(this, "onRemoveAlternateResponse", index => {
159
- const {
160
- model: {
161
- correctResponse
162
- }
163
- } = this.props;
164
- this.updateModel({
165
- correctResponse: (correctResponse || []).map(cr => ({
166
- ...cr,
167
- alternateResponses: (cr.alternateResponses || []).filter((alt, altIndex) => altIndex !== index)
168
- }))
169
- });
170
- });
171
- (0, _defineProperty2.default)(this, "countChoiceInCorrectResponse", choice => {
172
- const {
173
- model
174
- } = this.props;
175
- return (0, _categorize.countInAnswer)(choice.id, model.correctResponse);
176
- });
177
- (0, _defineProperty2.default)(this, "checkAllowMultiplePlacements", (allowMultiplePlacements, c) => {
178
- if (allowMultiplePlacements === _utils2.multiplePlacements.enabled) {
179
- return 0;
180
- }
181
- if (allowMultiplePlacements === _utils2.multiplePlacements.disabled) {
182
- return 1;
183
- }
184
- return c.categoryCount || 0;
185
- });
186
- (0, _defineProperty2.default)(this, "isAlertModalOpened", () => {
187
- const {
188
- model
189
- } = this.props;
190
- const {
191
- maxChoicesPerCategory = 0
192
- } = model || {};
193
- const maxChoices = (0, _utils2.getMaxCategoryChoices)(model);
194
- // when maxChoicesPerCategory is set to 0, there is no limit so modal should not be opened
195
- return maxChoicesPerCategory !== 0 ? maxChoices > maxChoicesPerCategory : false;
196
- });
197
- (0, _defineProperty2.default)(this, "onAlertModalCancel", () => {
198
- const {
199
- model
200
- } = this.props;
201
- const maxChoices = (0, _utils2.getMaxCategoryChoices)(model);
202
- this.updateModel({
203
- maxChoicesPerCategory: maxChoices
204
- });
205
- });
206
- (0, _defineProperty2.default)(this, "onDragStart", event => {
207
- const {
208
- active
209
- } = event;
210
- const draggedItem = active.data.current;
211
- this.setState({
212
- activeDragItem: draggedItem
213
- });
214
- });
215
- (0, _defineProperty2.default)(this, "onDragEnd", ({
216
- active,
217
- over
218
- }) => {
219
- // scrolls back to the original draggable element (scrollIntoViewIfNeeded).
220
- const scrollX = window.scrollX;
221
- const scrollY = window.scrollY;
222
- this.setState({
223
- activeDragItem: null
224
- });
225
- if (!active) {
226
- return;
227
- }
228
-
229
- // Restore scroll position after dnd-kit's drop animation fires scrollIntoViewIfNeeded.
230
- // Two rAF frames are needed: dnd-kit uses one rAF internally for focus/scroll restoration.
231
- requestAnimationFrame(() => {
232
- requestAnimationFrame(() => {
233
- window.scrollTo(scrollX, scrollY);
234
- });
235
- });
236
- const {
237
- model
238
- } = this.props;
239
- const {
240
- allowAlternateEnabled,
241
- categories = [],
242
- choices = []
243
- } = model;
244
- const activeData = active?.data?.current;
245
- const overData = over?.data?.current;
246
- if (!activeData) return;
247
- const choiceIndex = activeData.choiceIndex || 0;
248
- const overType = overData?.type;
249
- const isPreview = activeData.type === 'choice-preview';
250
- const isNewChoice = activeData.type === 'choice';
251
- const choiceId = activeData.choice?.id || (typeof activeData.id === 'string' ? activeData.id.split('-')[0] : activeData.id);
252
- if (isPreview && (!overData || overType === 'choice')) {
253
- this.removeChoiceFromSource(activeData, choiceIndex, {
254
- allowAlternateEnabled,
255
- categories,
256
- choices
257
- });
258
- return;
259
- }
260
- if (isPreview && overType === 'category') {
261
- return this.moveChoice(choiceId, activeData.categoryId, overData.id, choiceIndex);
262
- }
263
- if (isNewChoice && overType === 'category') {
264
- return this.addChoiceToCategory({
265
- id: activeData.id
266
- }, overData.id);
267
- }
268
- if (isPreview && overType === 'category-alternate') {
269
- return this.moveChoiceInAlternate(choiceId, activeData.categoryId, overData.id, choiceIndex, overData.alternateResponseIndex);
270
- }
271
- if (allowAlternateEnabled && isNewChoice && overType === 'category-alternate') {
272
- return this.addChoiceToAlternateCategory({
273
- id: activeData.id
274
- }, overData.id, overData.alternateResponseIndex);
275
- }
276
- });
277
- (0, _defineProperty2.default)(this, "removeChoiceFromSource", (activeData, choiceIndex, {
278
- allowAlternateEnabled,
279
- categories,
280
- choices
281
- }) => {
282
- const isAlternateSource = activeData.alternateResponseIndex !== undefined;
283
- if (!isAlternateSource) {
284
- this.deleteChoiceFromCategory(activeData.categoryId, activeData.choiceId, choiceIndex);
285
- return;
286
- }
287
- if (!allowAlternateEnabled) return;
288
- const category = categories?.find(c => c.id === activeData.categoryId);
289
- const choice = choices?.find(c => c.id === activeData.choiceId);
290
- if (category && choice) {
291
- this.deleteChoiceFromAlternateCategory(category, choice, choiceIndex, activeData.alternateResponseIndex);
292
- }
293
- });
294
- (0, _defineProperty2.default)(this, "addChoiceToCategory", (addedChoice, categoryId) => {
295
- const {
296
- model
297
- } = this.props;
298
- let {
299
- choices = [],
300
- correctResponse = [],
301
- maxChoicesPerCategory = 0
302
- } = model || {};
303
- const choice = (choices || []).find(choice => choice.id === addedChoice.id);
304
- let newCorrectResponse = (0, _categorize.moveChoiceToCategory)(addedChoice.id, undefined, categoryId, 0, correctResponse);
305
- if (choice.categoryCount !== 0) {
306
- newCorrectResponse = (0, _categorize.verifyAllowMultiplePlacements)(addedChoice, categoryId, newCorrectResponse);
307
- }
308
- const maxCategoryChoices = (0, _utils2.getMaxCategoryChoices)(model);
309
- this.updateModel({
310
- correctResponse: newCorrectResponse,
311
- maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
312
- });
313
- });
314
- (0, _defineProperty2.default)(this, "deleteChoiceFromCategory", (categoryId, choiceId, choiceIndex) => {
315
- const {
316
- model
317
- } = this.props;
318
- const correctResponse = (0, _categorize.removeChoiceFromCategory)(choiceId, categoryId, choiceIndex, model.correctResponse);
319
- this.updateModel({
320
- correctResponse
321
- });
322
- });
323
- (0, _defineProperty2.default)(this, "moveChoice", (choiceId, from, to, choiceIndex) => {
324
- const {
325
- model
326
- } = this.props;
327
- let {
328
- choices,
329
- correctResponse = [],
330
- maxChoicesPerCategory = 0
331
- } = model || {};
332
- const choice = (choices || []).find(choice => choice.id === choiceId);
333
- if (to === from || !choice) {
334
- return;
335
- }
336
- if (choice.categoryCount !== 0) {
337
- correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, from, to, choiceIndex, correctResponse);
338
- correctResponse = (0, _categorize.verifyAllowMultiplePlacements)(choice, to, correctResponse);
339
- } else if (choice.categoryCount === 0) {
340
- correctResponse = (0, _categorize.moveChoiceToCategory)(choice.id, undefined, to, 0, correctResponse);
341
- }
342
- const maxCategoryChoices = (0, _utils2.getMaxCategoryChoices)(model);
343
- // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
344
- this.updateModel({
345
- correctResponse,
346
- maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
347
- });
348
- });
349
- // methods for alternate responses
350
- (0, _defineProperty2.default)(this, "addChoiceToAlternateCategory", (addedChoice, categoryId, altIndex) => {
351
- const {
352
- model
353
- } = this.props;
354
- const {
355
- correctResponse,
356
- choices,
357
- maxChoicesPerCategory = 0
358
- } = model;
359
- const choice = choices.find(c => c.id === addedChoice.id);
360
- correctResponse.forEach(a => {
361
- if (a.category === categoryId) {
362
- a.alternateResponses = a.alternateResponses || [];
363
- if (a.alternateResponses[altIndex] === undefined) {
364
- a.alternateResponses[altIndex] = [];
365
- }
366
- a.alternateResponses[altIndex].push(addedChoice.id);
367
- if (choice.categoryCount && choice.categoryCount !== 0) {
368
- a.alternateResponses[altIndex] = a.alternateResponses[altIndex].reduce((acc, currentValue) => {
369
- if (currentValue === choice.id) {
370
- const foundIndex = acc.findIndex(c => c === choice.id);
371
- if (foundIndex === -1) {
372
- acc.push(currentValue);
373
- }
374
- } else {
375
- acc.push(currentValue);
376
- }
377
- return acc;
378
- }, []);
379
- }
380
- return a;
381
- } else {
382
- if (a.alternateResponses[altIndex] && choice.categoryCount !== 0) {
383
- a.alternateResponses[altIndex] = a.alternateResponses[altIndex].filter(c => c !== addedChoice.id);
384
- return a;
385
- }
386
- }
387
- return a;
388
- });
389
- const maxCategoryChoices = (0, _utils2.getMaxCategoryChoices)(model);
390
- // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
391
- this.updateModel({
392
- correctResponse,
393
- maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
394
- });
395
- });
396
- (0, _defineProperty2.default)(this, "moveChoiceInAlternate", (choiceId, from, to, choiceIndex, alternateIndex) => {
397
- const {
398
- model
399
- } = this.props;
400
- let {
401
- choices,
402
- correctResponse = [],
403
- maxChoicesPerCategory = 0
404
- } = model || {};
405
- const choice = (choices || []).find(choice => choice.id === choiceId);
406
- correctResponse = (0, _categorize.moveChoiceToAlternate)(choiceId, from, to, choiceIndex, correctResponse, alternateIndex, choice?.categoryCount);
407
- const maxCategoryChoices = (0, _utils2.getMaxCategoryChoices)(model);
408
- // when maxChoicesPerCategory is set to 0, there is no limit so it should not be updated
409
- this.updateModel({
410
- correctResponse,
411
- maxChoicesPerCategory: maxChoicesPerCategory !== 0 && maxChoicesPerCategory < maxCategoryChoices ? maxChoicesPerCategory + 1 : maxChoicesPerCategory
412
- });
413
- });
414
- (0, _defineProperty2.default)(this, "deleteChoiceFromAlternateCategory", (category, choice, choiceIndex, altIndex) => {
415
- const {
416
- model
417
- } = this.props;
418
- const correctResponse = (0, _categorize.removeChoiceFromAlternate)(choice.id, category.id, choiceIndex, altIndex, model.correctResponse);
419
- this.updateModel({
420
- correctResponse
421
- });
422
- });
423
- (0, _defineProperty2.default)(this, "renderDragOverlay", () => {
424
- const {
425
- activeDragItem
426
- } = this.state;
427
- const {
428
- model,
429
- configuration
430
- } = this.props;
431
- if (!activeDragItem) return null;
432
- if (activeDragItem.type === 'choice') {
433
- const choice = model.choices?.find(c => c.id === activeDragItem.id);
434
- if (!choice) return null;
435
- return /*#__PURE__*/_react.default.createElement(_choice.default, {
436
- choice: choice,
437
- configuration: configuration
438
- });
439
- } else if (activeDragItem.type === 'choice-preview' && activeDragItem.alternateResponseIndex === undefined) {
440
- const choice = model.choices?.find(c => c.id === activeDragItem.id);
441
- if (!choice) return null;
442
- return /*#__PURE__*/_react.default.createElement(_choicePreview.default, {
443
- choice: choice
444
- });
445
- } else if (activeDragItem.type === 'choice-preview' && activeDragItem.alternateResponseIndex !== undefined) {
446
- const choice = model.choices?.find(c => c.id === activeDragItem.id);
447
- if (!choice) return null;
448
- return /*#__PURE__*/_react.default.createElement(_choicePreview.default, {
449
- choice: choice,
450
- alternateResponseIndex: activeDragItem.alternateResponseIndex
451
- });
452
- }
453
- return null;
454
- });
455
- this.uid = _props.uid || _drag.uid.generateId();
456
- this.state = {
457
- activeDragItem: null
458
- };
459
- }
460
- render() {
461
- const {
462
- configuration,
463
- imageSupport,
464
- model,
465
- uploadSoundSupport,
466
- onConfigurationChanged
467
- } = this.props;
468
- const {
469
- allowAlternate = {},
470
- allowMultiplePlacements = {},
471
- baseInputConfiguration = {},
472
- categoriesPerRow = {},
473
- choicesPosition = {},
474
- contentDimensions = {},
475
- feedback = {},
476
- lockChoiceOrder = {},
477
- maxImageHeight = {},
478
- maxImageWidth = {},
479
- maxPlacements = {},
480
- minCategoriesPerRow = 1,
481
- partialScoring = {},
482
- prompt = {},
483
- rationale = {},
484
- scoringType = {},
485
- settingsPanelDisabled,
486
- spellCheck = {},
487
- studentInstructions = {},
488
- teacherInstructions = {},
489
- withRubric = {},
490
- mathMlOptions = {},
491
- language = {},
492
- languageChoices = {},
493
- allowMaxAnswerChoices = {}
494
- } = configuration || {};
495
- const {
496
- allowAlternateEnabled,
497
- allowMaxChoicesPerCategory,
498
- errors,
499
- feedbackEnabled,
500
- maxChoicesPerCategory,
501
- promptEnabled,
502
- rationaleEnabled,
503
- spellCheckEnabled,
504
- teacherInstructionsEnabled,
505
- toolbarEditorPosition,
506
- extraCSSRules
507
- } = model || {};
508
- const {
509
- prompt: promptError,
510
- rationale: rationaleError,
511
- teacherInstructions: teacherInstructionsError
512
- } = errors || {};
513
- const toolbarOpts = {
514
- position: toolbarEditorPosition === 'top' ? 'top' : 'bottom'
515
- };
516
- const config = model.config || {};
517
- config.choices = config.choices || {
518
- label: '',
519
- columns: 2
520
- };
521
- const categories = (0, _builder.buildCategories)(model.categories || [], model.choices || [], model.correctResponse || []);
522
- const alternateResponses = (0, _builder.buildAlternateResponses)(model.categories || [], model.choices || [], model.correctResponse || []);
523
- const resolvedAllowMultiplePlacements = (() => {
524
- if (model.allowMultiplePlacementsEnabled != null) {
525
- return model.allowMultiplePlacementsEnabled;
526
- }
527
- const allChoiceIds = (model.correctResponse || []).flatMap(cr => cr.choices || []);
528
- const isExclusive = allChoiceIds.length === new Set(allChoiceIds).size;
529
- return isExclusive ? _utils2.multiplePlacements.disabled : _utils2.multiplePlacements.enabled;
530
- })();
531
- const choices = model.choices.map(c => {
532
- c.correctResponseCount = this.countChoiceInCorrectResponse(c);
533
- // ensure categoryCount is set even though updatedModel hasn't been called
534
- c.categoryCount = this.checkAllowMultiplePlacements(resolvedAllowMultiplePlacements, c);
535
- return c;
536
- });
537
- const defaultImageMaxWidth = maxImageWidth && maxImageWidth.prompt;
538
- const defaultImageMaxHeight = maxImageHeight && maxImageHeight.prompt;
539
- const panelSettings = {
540
- partialScoring: partialScoring.settings && toggle(partialScoring.label),
541
- lockChoiceOrder: lockChoiceOrder.settings && toggle(lockChoiceOrder.label),
542
- categoriesPerRow: categoriesPerRow.settings && numberField(categoriesPerRow.label, {
543
- label: categoriesPerRow.label,
544
- min: minCategoriesPerRow,
545
- max: 6
546
- }),
547
- choicesPosition: choicesPosition.settings && radio(choicesPosition.label, ['below', 'above', 'left', 'right']),
548
- allowMultiplePlacementsEnabled: allowMultiplePlacements.settings && dropdown(allowMultiplePlacements.label, [_utils2.multiplePlacements.enabled, _utils2.multiplePlacements.disabled, _utils2.multiplePlacements.perChoice]),
549
- maxAnswerChoices: allowMaxAnswerChoices.settings && numberField(allowMaxAnswerChoices.label, {
550
- label: '',
551
- min: choices?.length || 0,
552
- max: 30
553
- }),
554
- allowMaxChoicesPerCategory: maxPlacements.settings && toggle(maxPlacements.label),
555
- maxChoicesPerCategory: allowMaxChoicesPerCategory === true && numberField(maxPlacements.label, {
556
- label: '',
557
- min: 0,
558
- max: 30
559
- }),
560
- promptEnabled: prompt.settings && toggle(prompt.label),
561
- feedbackEnabled: feedback.settings && toggle(feedback.label),
562
- allowAlternateEnabled: allowAlternate.settings && toggle(allowAlternate.label),
563
- 'language.enabled': language.settings && toggle(language.label, true),
564
- language: language.settings && language.enabled && dropdown(languageChoices.label, languageChoices.options)
565
- };
566
- const panelProperties = {
567
- teacherInstructionsEnabled: teacherInstructions.settings && toggle(teacherInstructions.label),
568
- studentInstructionsEnabled: studentInstructions.settings && toggle(studentInstructions.label),
569
- rationaleEnabled: rationale.settings && toggle(rationale.label),
570
- spellCheckEnabled: spellCheck.settings && toggle(spellCheck.label),
571
- scoringType: scoringType.settings && radio(scoringType.label, ['auto', 'rubric']),
572
- rubricEnabled: withRubric?.settings && toggle(withRubric?.label)
573
- };
574
- const isOpened = this.isAlertModalOpened();
575
- const alertMaxChoicesMsg = translator.t('translation:categorize:maxChoicesPerCategoryRestriction', {
576
- lng: model.language,
577
- maxChoicesPerCategory
578
- });
579
- return /*#__PURE__*/_react.default.createElement(_drag.DragProvider, {
580
- onDragStart: this.onDragStart,
581
- onDragEnd: this.onDragEnd
582
- }, /*#__PURE__*/_react.default.createElement(IdProvider, {
583
- value: this.uid
584
- }, /*#__PURE__*/_react.default.createElement(_configUi.layout.ConfigLayout, {
585
- extraCSSRules: extraCSSRules,
586
- dimensions: contentDimensions,
587
- hideSettings: settingsPanelDisabled,
588
- settings: /*#__PURE__*/_react.default.createElement(Panel, {
589
- model: {
590
- ...model,
591
- allowMultiplePlacementsEnabled: resolvedAllowMultiplePlacements
592
- },
593
- onChangeModel: this.updateModel,
594
- configuration: configuration,
595
- onChangeConfiguration: onConfigurationChanged,
596
- groups: {
597
- Settings: panelSettings,
598
- Properties: panelProperties
599
- },
600
- modal: /*#__PURE__*/_react.default.createElement(_configUi.AlertDialog, {
601
- title: 'Warning',
602
- text: alertMaxChoicesMsg,
603
- open: isOpened,
604
- onClose: this.onAlertModalCancel
605
- })
606
- })
607
- }, teacherInstructionsEnabled && /*#__PURE__*/_react.default.createElement(StyledInputContainer, {
608
- label: teacherInstructions.label
609
- }, /*#__PURE__*/_react.default.createElement(_editableHtmlTipTap.default, {
610
- markup: model.teacherInstructions || '',
611
- onChange: this.changeTeacherInstructions,
612
- imageSupport: imageSupport,
613
- error: teacherInstructionsError,
614
- nonEmpty: false,
615
- toolbarOpts: toolbarOpts,
616
- pluginProps: (0, _utils.getPluginProps)(teacherInstructions?.inputConfiguration, baseInputConfiguration),
617
- spellCheck: spellCheckEnabled,
618
- maxImageWidth: maxImageWidth && maxImageWidth.teacherInstructions || defaultImageMaxWidth,
619
- maxImageHeight: maxImageHeight && maxImageHeight.teacherInstructions || defaultImageMaxHeight,
620
- uploadSoundSupport: uploadSoundSupport,
621
- languageCharactersProps: [{
622
- language: 'spanish'
623
- }, {
624
- language: 'special'
625
- }],
626
- mathMlOptions: mathMlOptions
627
- }), teacherInstructionsError && /*#__PURE__*/_react.default.createElement(ErrorText, null, teacherInstructionsError)), promptEnabled && /*#__PURE__*/_react.default.createElement(StyledInputContainer, {
628
- label: prompt.label
629
- }, /*#__PURE__*/_react.default.createElement(_editableHtmlTipTap.default, {
630
- markup: model.prompt || '',
631
- onChange: this.onPromptChanged,
632
- imageSupport: imageSupport,
633
- error: promptError,
634
- nonEmpty: false,
635
- disableUnderline: true,
636
- toolbarOpts: toolbarOpts,
637
- pluginProps: (0, _utils.getPluginProps)(prompt?.inputConfiguration, baseInputConfiguration),
638
- spellCheck: spellCheckEnabled,
639
- maxImageWidth: maxImageWidth && maxImageWidth.prompt,
640
- maxImageHeight: maxImageHeight && maxImageHeight.prompt,
641
- uploadSoundSupport: uploadSoundSupport,
642
- languageCharactersProps: [{
643
- language: 'spanish'
644
- }, {
645
- language: 'special'
646
- }],
647
- mathMlOptions: mathMlOptions
648
- }), promptError && /*#__PURE__*/_react.default.createElement(ErrorText, null, promptError)), /*#__PURE__*/_react.default.createElement(_categories.default, {
649
- imageSupport: imageSupport,
650
- uploadSoundSupport: uploadSoundSupport,
651
- model: model,
652
- categories: categories || [],
653
- onModelChanged: this.updateModel,
654
- toolbarOpts: toolbarOpts,
655
- spellCheck: spellCheckEnabled,
656
- configuration: configuration,
657
- defaultImageMaxWidth: defaultImageMaxWidth,
658
- defaultImageMaxHeight: defaultImageMaxHeight,
659
- mathMlOptions: mathMlOptions
660
- }), /*#__PURE__*/_react.default.createElement(_choices.default, {
661
- imageSupport: imageSupport,
662
- uploadSoundSupport: uploadSoundSupport,
663
- choices: choices,
664
- model: {
665
- ...model,
666
- allowMultiplePlacementsEnabled: resolvedAllowMultiplePlacements
667
- },
668
- onModelChanged: this.updateModel,
669
- toolbarOpts: toolbarOpts,
670
- spellCheck: spellCheckEnabled,
671
- configuration: configuration,
672
- defaultImageMaxWidth: defaultImageMaxWidth,
673
- defaultImageMaxHeight: defaultImageMaxHeight
674
- }), allowAlternateEnabled && /*#__PURE__*/_react.default.createElement(StyledHeader, {
675
- label: "Alternate Responses",
676
- buttonLabel: "ADD AN ALTERNATE RESPONSE",
677
- onAdd: this.onAddAlternateResponse
678
- }), allowAlternateEnabled && alternateResponses.map((categoriesList, index) => {
679
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
680
- key: index
681
- }, /*#__PURE__*/_react.default.createElement(StyledHeader, {
682
- variant: 'subtitle1',
683
- label: "Alternate Response",
684
- buttonLabel: "REMOVE ALTERNATE RESPONSE",
685
- onAdd: () => this.onRemoveAlternateResponse(index)
686
- }), /*#__PURE__*/_react.default.createElement(_alternateResponses.default, {
687
- altIndex: index,
688
- imageSupport: imageSupport,
689
- model: model,
690
- configuration: configuration,
691
- categories: categoriesList,
692
- onModelChanged: this.updateModel,
693
- uploadSoundSupport: uploadSoundSupport,
694
- mathMlOptions: mathMlOptions
695
- }));
696
- }), rationaleEnabled && /*#__PURE__*/_react.default.createElement(StyledInputContainer, {
697
- label: rationale.label
698
- }, /*#__PURE__*/_react.default.createElement(_editableHtmlTipTap.default, {
699
- markup: model.rationale || '',
700
- onChange: this.changeRationale,
701
- imageSupport: imageSupport,
702
- error: rationaleError,
703
- nonEmpty: false,
704
- toolbarOpts: toolbarOpts,
705
- pluginProps: (0, _utils.getPluginProps)(prompt?.inputConfiguration, baseInputConfiguration),
706
- spellCheck: spellCheckEnabled,
707
- maxImageWidth: maxImageWidth && maxImageWidth.rationale || defaultImageMaxWidth,
708
- maxImageHeight: maxImageHeight && maxImageHeight.rationale || defaultImageMaxHeight,
709
- uploadSoundSupport: uploadSoundSupport,
710
- languageCharactersProps: [{
711
- language: 'spanish'
712
- }, {
713
- language: 'special'
714
- }],
715
- mathMlOptions: mathMlOptions
716
- }), rationaleError && /*#__PURE__*/_react.default.createElement(ErrorText, null, rationaleError)), feedbackEnabled && /*#__PURE__*/_react.default.createElement(_configUi.FeedbackConfig, {
717
- feedback: model.feedback,
718
- onChange: this.changeFeedback,
719
- toolbarOpts: toolbarOpts
720
- })), /*#__PURE__*/_react.default.createElement(_core.DragOverlay, null, /*#__PURE__*/_react.default.createElement(DragPreviewWrapper, null, this.renderDragOverlay()))));
721
- }
722
- }
723
- exports.Design = Design;
724
- (0, _defineProperty2.default)(Design, "propTypes", {
725
- configuration: _propTypes.default.object,
726
- className: _propTypes.default.string,
727
- onConfigurationChanged: _propTypes.default.func,
728
- model: _propTypes.default.object.isRequired,
729
- onChange: _propTypes.default.func.isRequired,
730
- uid: _propTypes.default.string,
731
- imageSupport: _propTypes.default.shape({
732
- add: _propTypes.default.func.isRequired,
733
- delete: _propTypes.default.func.isRequired
734
- }),
735
- uploadSoundSupport: _propTypes.default.shape({
736
- add: _propTypes.default.func.isRequired,
737
- delete: _propTypes.default.func.isRequired
738
- })
739
- });
740
- var _default = exports.default = Design;
741
- //# sourceMappingURL=index.js.map