@nualang/nualang-ui-components 0.1.1244 → 0.1.1246

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.
@@ -10,7 +10,8 @@ var _Box = _interopRequireDefault(require("@mui/material/Box"));
10
10
  var _Message = _interopRequireDefault(require("./Message"));
11
11
  var _Question = _interopRequireDefault(require("./Question"));
12
12
  var _material = require("@mui/material");
13
- var _reactBeautifulDnd = require("react-beautiful-dnd");
13
+ var _dragAndDrop = require("../../utils/dragAndDrop/dragAndDrop");
14
+ var _core = require("@dnd-kit/core");
14
15
  var _jsxRuntime = require("react/jsx-runtime");
15
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
17
  const useStyles = (0, _mui.makeStyles)()(theme => ({
@@ -83,7 +84,19 @@ function Messages({
83
84
  }
84
85
  }, [disableScroll, messages.length, currentMessage, isTimeUp]);
85
86
  const onDragEnd = result => {
86
- result.destination && moveScriptItem(result.source.index, result.destination.index);
87
+ const {
88
+ active,
89
+ over
90
+ } = result;
91
+ if (!over) {
92
+ return;
93
+ }
94
+ if (active.id !== over.id) {
95
+ const oldIndex = messages.findIndex((item, index) => `${index}-${item.text}` === active.id);
96
+ const newIndex = messages.findIndex((item, index) => `${index}-${item.text}` === over.id);
97
+ moveScriptItem(oldIndex, newIndex);
98
+ return;
99
+ }
87
100
  };
88
101
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
89
102
  id: "messages",
@@ -95,158 +108,143 @@ function Messages({
95
108
  maxWidth: 800,
96
109
  mx: "auto"
97
110
  },
98
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBeautifulDnd.DragDropContext, {
111
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_dragAndDrop.SortableDndContextWrapper, {
112
+ items: messages.map((m, i) => `${i}-${m.text}`),
99
113
  onDragEnd: onDragEnd,
100
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBeautifulDnd.Droppable, {
101
- droppableId: "droppableMessages",
102
- children: provided => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
103
- ...provided.droppableProps,
104
- ref: provided.innerRef,
105
- children: [isLiveGame && isLivePlayer && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
106
- sx: {
107
- display: "flex",
108
- flexDirection: "column"
109
- },
110
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
111
- sx: {
112
- textAlign: "center"
113
- },
114
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
115
- src: roleplayImage,
116
- width: 250,
117
- alt: "",
118
- style: {
119
- borderRadius: "5%"
120
- }
121
- })
122
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
123
- align: "center",
124
- variant: "h6",
125
- component: "h2",
126
- gutterBottom: true,
127
- sx: {
128
- fontWeight: 600
129
- },
130
- children: t("listen_to_story")
131
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
132
- align: "center",
133
- variant: "subtitle",
134
- color: "textSecondary",
135
- sx: {
136
- pb: 5
137
- },
138
- children: t("story_description")
139
- })]
140
- }), messages.map((m, i) => {
141
- let isCurrentMessage = m === currentMessage;
142
- return moveScriptItem ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBeautifulDnd.Draggable, {
143
- draggableId: `message-${i}`,
144
- index: i,
145
- children: (provided, snapshot) => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
146
- ref: provided.innerRef,
147
- ...provided.draggableProps,
148
- style: {
149
- ...provided.draggableProps.style,
150
- opacity: snapshot.isDragging ? 0.8 : 1
151
- },
152
- children: m?.question && !isLivePlayer ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Question.default, {
153
- t: t,
154
- languageTag: languageTag,
155
- messageIndex: i,
156
- messageCount: messages.length,
157
- answerAttempts: answerAttempts,
158
- isLiveGame: isLiveGame,
159
- isLivePlayer: isLivePlayer,
160
- isTimeUp: isCurrentMessage ? isTimeUp : true,
161
- time: time,
162
- handleTimeUp: handleTimeUp,
163
- setCurrentAnswer: setCurrentAnswer,
164
- setIsAnswered: setIsAnswered,
165
- isAnswered: isAnswered,
166
- handleContinue: handleContinue,
167
- isCurrentMessage: isCurrentMessage,
168
- answerCounts: answerCounts,
169
- noAnswerCounts: noAnswerCounts,
170
- messages: messages,
171
- moveScriptItem: moveScriptItem,
172
- provided: provided,
173
- ...m,
174
- ...otherProps
175
- }, `messx_${i}`) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Message.default, {
176
- t: t,
177
- languageTag: languageTag,
178
- disableTranslation: disableTranslation,
179
- messageIndex: i,
180
- voiceSpeed: voiceSpeed,
181
- voice: voice,
182
- messageCount: messages.length,
183
- isSpeaking: isSpeaking,
184
- isSpeakingTextContainer: isSpeakingTextContainer,
185
- muteSound: muteSound,
186
- exercise: exercise,
187
- setCheckedDefault: setCheckedDefault,
188
- index: i,
189
- setBotMessages: setBotMessages,
190
- messages: messages,
191
- gameId: gameId,
192
- speak: speak,
193
- isLivePlayer: isLivePlayer,
194
- siteLanguage: siteLanguage,
195
- moveScriptItem: moveScriptItem,
196
- provided: provided,
197
- ...m,
198
- ...otherProps
199
- }, `messy_${i}`)
200
- })
201
- }, i) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
202
- children: [m?.question && !isLivePlayer && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Question.default, {
203
- t: t,
204
- languageTag: languageTag,
205
- messageIndex: i,
206
- messageCount: messages.length,
207
- answerAttempts: answerAttempts,
208
- isLiveGame: isLiveGame,
209
- isLivePlayer: isLivePlayer,
210
- isTimeUp: isCurrentMessage ? isTimeUp : true,
211
- time: time,
212
- handleTimeUp: handleTimeUp,
213
- setCurrentAnswer: setCurrentAnswer,
214
- setIsAnswered: setIsAnswered,
215
- isAnswered: isAnswered,
216
- handleContinue: handleContinue,
217
- isCurrentMessage: isCurrentMessage,
218
- answerCounts: answerCounts,
219
- noAnswerCounts: noAnswerCounts,
220
- messages: messages,
221
- ...m,
222
- ...otherProps
223
- }, `messx_${i}`), !m?.question && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Message.default, {
224
- t: t,
225
- languageTag: languageTag,
226
- disableTranslation: disableTranslation,
227
- messageIndex: i,
228
- voiceSpeed: voiceSpeed,
229
- voice: voice,
230
- messageCount: messages.length,
231
- isSpeaking: isSpeaking,
232
- isSpeakingTextContainer: isSpeakingTextContainer,
233
- muteSound: muteSound,
234
- exercise: exercise,
235
- setCheckedDefault: setCheckedDefault,
236
- index: i,
237
- setBotMessages: setBotMessages,
238
- messages: messages,
239
- gameId: gameId,
240
- speak: speak,
241
- isLivePlayer: isLivePlayer,
242
- siteLanguage: siteLanguage,
243
- ...m,
244
- ...otherProps
245
- }, `messy_${i}`)]
246
- });
247
- }), provided.placeholder]
248
- })
249
- })
114
+ collisionOverride: _core.rectIntersection,
115
+ children: [isLiveGame && isLivePlayer && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
116
+ sx: {
117
+ display: "flex",
118
+ flexDirection: "column"
119
+ },
120
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
121
+ sx: {
122
+ textAlign: "center"
123
+ },
124
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
125
+ src: roleplayImage,
126
+ width: 250,
127
+ alt: "",
128
+ style: {
129
+ borderRadius: "5%"
130
+ }
131
+ })
132
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
133
+ align: "center",
134
+ variant: "h6",
135
+ component: "h2",
136
+ gutterBottom: true,
137
+ sx: {
138
+ fontWeight: 600
139
+ },
140
+ children: t("listen_to_story")
141
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
142
+ align: "center",
143
+ variant: "subtitle",
144
+ color: "textSecondary",
145
+ sx: {
146
+ pb: 5
147
+ },
148
+ children: t("story_description")
149
+ })]
150
+ }), messages.map((m, i) => {
151
+ let isCurrentMessage = m === currentMessage;
152
+ return moveScriptItem ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_dragAndDrop.Sortable, {
153
+ sortId: `${i}-${m.text}`,
154
+ index: i,
155
+ children: m?.question && !isLivePlayer ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Question.default, {
156
+ t: t,
157
+ languageTag: languageTag,
158
+ messageIndex: i,
159
+ messageCount: messages.length,
160
+ answerAttempts: answerAttempts,
161
+ isLiveGame: isLiveGame,
162
+ isLivePlayer: isLivePlayer,
163
+ isTimeUp: isCurrentMessage ? isTimeUp : true,
164
+ time: time,
165
+ handleTimeUp: handleTimeUp,
166
+ setCurrentAnswer: setCurrentAnswer,
167
+ setIsAnswered: setIsAnswered,
168
+ isAnswered: isAnswered,
169
+ handleContinue: handleContinue,
170
+ isCurrentMessage: isCurrentMessage,
171
+ answerCounts: answerCounts,
172
+ noAnswerCounts: noAnswerCounts,
173
+ messages: messages,
174
+ moveScriptItem: moveScriptItem,
175
+ ...m,
176
+ ...otherProps
177
+ }, `messx_${i}`) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Message.default, {
178
+ t: t,
179
+ languageTag: languageTag,
180
+ disableTranslation: disableTranslation,
181
+ messageIndex: i,
182
+ voiceSpeed: voiceSpeed,
183
+ voice: voice,
184
+ messageCount: messages.length,
185
+ isSpeaking: isSpeaking,
186
+ isSpeakingTextContainer: isSpeakingTextContainer,
187
+ muteSound: muteSound,
188
+ exercise: exercise,
189
+ setCheckedDefault: setCheckedDefault,
190
+ index: i,
191
+ setBotMessages: setBotMessages,
192
+ messages: messages,
193
+ gameId: gameId,
194
+ speak: speak,
195
+ isLivePlayer: isLivePlayer,
196
+ siteLanguage: siteLanguage,
197
+ moveScriptItem: moveScriptItem,
198
+ ...m,
199
+ ...otherProps
200
+ }, `messy_${i}`)
201
+ }, `${i}-${m.text}`) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
202
+ children: [m?.question && !isLivePlayer && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Question.default, {
203
+ t: t,
204
+ languageTag: languageTag,
205
+ messageIndex: i,
206
+ messageCount: messages.length,
207
+ answerAttempts: answerAttempts,
208
+ isLiveGame: isLiveGame,
209
+ isLivePlayer: isLivePlayer,
210
+ isTimeUp: isCurrentMessage ? isTimeUp : true,
211
+ time: time,
212
+ handleTimeUp: handleTimeUp,
213
+ setCurrentAnswer: setCurrentAnswer,
214
+ setIsAnswered: setIsAnswered,
215
+ isAnswered: isAnswered,
216
+ handleContinue: handleContinue,
217
+ isCurrentMessage: isCurrentMessage,
218
+ answerCounts: answerCounts,
219
+ noAnswerCounts: noAnswerCounts,
220
+ messages: messages,
221
+ ...m,
222
+ ...otherProps
223
+ }, `messx_${i}`), !m?.question && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Message.default, {
224
+ t: t,
225
+ languageTag: languageTag,
226
+ disableTranslation: disableTranslation,
227
+ messageIndex: i,
228
+ voiceSpeed: voiceSpeed,
229
+ voice: voice,
230
+ messageCount: messages.length,
231
+ isSpeaking: isSpeaking,
232
+ isSpeakingTextContainer: isSpeakingTextContainer,
233
+ muteSound: muteSound,
234
+ exercise: exercise,
235
+ setCheckedDefault: setCheckedDefault,
236
+ index: i,
237
+ setBotMessages: setBotMessages,
238
+ messages: messages,
239
+ gameId: gameId,
240
+ speak: speak,
241
+ isLivePlayer: isLivePlayer,
242
+ siteLanguage: siteLanguage,
243
+ ...m,
244
+ ...otherProps
245
+ }, `messy_${i}`)]
246
+ });
247
+ })]
250
248
  })
251
249
  }), afterElements]
252
250
  });
@@ -14,8 +14,9 @@ var _Close = _interopRequireDefault(require("@mui/icons-material/Close"));
14
14
  var _mui = require("tss-react/mui");
15
15
  var _colors = require("@mui/material/colors");
16
16
  var _Checkbox = _interopRequireDefault(require("@mui/material/Checkbox"));
17
- var _reactBeautifulDnd = require("react-beautiful-dnd");
18
17
  var _DragHandle = _interopRequireDefault(require("@mui/icons-material/DragHandle"));
18
+ var _sortable = require("@dnd-kit/sortable");
19
+ var _dragAndDrop = require("../../utils/dragAndDrop/dragAndDrop");
19
20
  var _ResponsiveDialog = _interopRequireDefault(require("../ResponsiveDialog"));
20
21
  var _InputHelper = _interopRequireDefault(require("../../Forms/InputHelper"));
21
22
  var _debounce = _interopRequireDefault(require("lodash/debounce"));
@@ -127,17 +128,17 @@ function CreateQuestion({
127
128
  };
128
129
  const handleOnDragEnd = result => {
129
130
  const {
130
- source,
131
- destination
131
+ active,
132
+ over
132
133
  } = result;
133
- if (!destination) {
134
+ if (!over) {
134
135
  return;
135
136
  }
136
- if (source.droppableId === "answers" && destination.droppableId === "answers") {
137
- const items = Array.from(answerList);
138
- const [reorderedItem] = items.splice(source.index, 1);
139
- items.splice(destination.index, 0, reorderedItem);
140
- setAnswerList(items);
137
+ if (active.id !== over.id) {
138
+ const oldIndex = answerList.findIndex((item, index) => `${index}-${item.text}` === active.id);
139
+ const newIndex = answerList.findIndex((item, index) => `${index}-${item.text}` === over.id);
140
+ const updatedAnswerList = (0, _sortable.arrayMove)(answerList, oldIndex, newIndex);
141
+ setAnswerList(updatedAnswerList);
141
142
  }
142
143
  };
143
144
  const handleAddAnswerDebounced = (0, _react.useCallback)((0, _debounce.default)(handleAddAnswer, 100), [answer]);
@@ -201,77 +202,79 @@ function CreateQuestion({
201
202
  multiline: true
202
203
  })
203
204
  })]
204
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBeautifulDnd.DragDropContext, {
205
- onDragEnd: handleOnDragEnd,
206
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBeautifulDnd.Droppable, {
207
- droppableId: "answers",
208
- children: provided => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
209
- ...provided.droppableProps,
210
- ref: provided.innerRef,
211
- children: [answerList.map((a, idx) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBeautifulDnd.Draggable, {
212
- draggableId: `answer-${idx}`,
213
- index: idx,
214
- children: provided => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
215
- ref: provided.innerRef,
216
- ...provided.draggableProps,
217
- style: provided.draggableProps.style,
218
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
219
- container: true,
220
- direction: "row",
221
- spacing: 1,
222
- alignItems: "center",
223
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
224
- size: 9.5,
225
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputHelper.default, {
226
- t: t,
227
- value: a.text,
228
- onChange: handleExistingAnswerInputChange(idx),
229
- margin: "none",
230
- id: `answer-${idx}`,
231
- name: "text",
232
- type: "text",
233
- fullWidth: true,
234
- characters: forLangCharacters ? forLangCharacters : null,
235
- multiline: true
236
- })
237
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
238
- direction: "row",
239
- size: 2.5,
240
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
241
- title: t("remove_answer"),
242
- enterDelay: 300,
243
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
244
- onClick: () => handleRemoveAnswer(idx),
245
- size: "large",
246
- "aria-label": "Remove Answer",
247
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Close.default, {})
248
- })
249
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
250
- title: t("move_answer"),
251
- enterDelay: 300,
252
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
253
- size: "large",
254
- "aria-label": "Drag Answer",
255
- ...provided.dragHandleProps,
256
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_DragHandle.default, {})
257
- })
258
- })]
259
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
260
- size: 12,
261
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormControlLabel.default, {
262
- control: /*#__PURE__*/(0, _jsxRuntime.jsx)(GreenCheckbox, {
263
- checked: a.correct,
264
- value: a.correct,
265
- onChange: handleExistingAnswerInputChange(idx),
266
- name: "correct"
267
- }),
268
- label: t("correct_answer")
269
- })
270
- })]
271
- })
205
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
206
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dragAndDrop.SortableDndContextWrapper, {
207
+ items: answerList.map((a, index) => `${index}-${a.text}`),
208
+ onDragEnd: handleOnDragEnd,
209
+ children: answerList.map((a, idx) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_dragAndDrop.SortableHandleOnly, {
210
+ sortId: `${idx}-${a.text}`,
211
+ index: idx,
212
+ renderHandle: ({
213
+ setActivatorNodeRef,
214
+ listeners
215
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
216
+ title: t("move_answer"),
217
+ enterDelay: 300,
218
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
219
+ size: "large",
220
+ "aria-label": "Drag Answer",
221
+ ref: setActivatorNodeRef,
222
+ ...listeners,
223
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_DragHandle.default, {})
272
224
  })
273
- }, idx)), provided.placeholder]
274
- })
225
+ }),
226
+ children: ({
227
+ renderHandle
228
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
229
+ container: true,
230
+ direction: "row",
231
+ spacing: 1,
232
+ alignItems: "center",
233
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
234
+ size: 9.5,
235
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputHelper.default, {
236
+ t: t,
237
+ value: a.text,
238
+ onChange: handleExistingAnswerInputChange(idx),
239
+ margin: "none",
240
+ id: `answer-${idx}`,
241
+ name: "text",
242
+ type: "text",
243
+ fullWidth: true,
244
+ characters: forLangCharacters ? forLangCharacters : null,
245
+ multiline: true
246
+ })
247
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
248
+ direction: "row",
249
+ size: 2.5,
250
+ sx: {
251
+ display: "flex",
252
+ alignItems: "center"
253
+ },
254
+ children: [renderHandle && renderHandle(), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
255
+ title: t("remove_answer"),
256
+ enterDelay: 300,
257
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
258
+ onClick: () => handleRemoveAnswer(idx),
259
+ size: "large",
260
+ "aria-label": "Remove Answer",
261
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Close.default, {})
262
+ })
263
+ })]
264
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
265
+ size: 12,
266
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormControlLabel.default, {
267
+ control: /*#__PURE__*/(0, _jsxRuntime.jsx)(GreenCheckbox, {
268
+ checked: a.correct,
269
+ value: a.correct,
270
+ onChange: handleExistingAnswerInputChange(idx),
271
+ name: "correct"
272
+ }),
273
+ label: t("correct_answer")
274
+ })
275
+ })]
276
+ })
277
+ }, `${idx}-${a.text}`))
275
278
  })
276
279
  })]
277
280
  });
@@ -111,6 +111,8 @@ function UploadPhrases({
111
111
  isRowEmpty,
112
112
  handleAppendPhrases,
113
113
  verificationStatus,
114
+ learnLang,
115
+ forLang,
114
116
  ...otherProps
115
117
  }) {
116
118
  const {
@@ -146,9 +148,10 @@ function UploadPhrases({
146
148
  setErrors(prevState => [...prevState, ...rowErrors]);
147
149
  }
148
150
  }
149
- if (data.phrase && data.translations) {
150
- setisError(false);
151
- setErrorMessage("");
151
+ if (data.phrase) {
152
+ if (learnLang === forLang && (!data.translations || data.translations.trim() === "")) {
153
+ data.translations = data.phrase;
154
+ }
152
155
  const {
153
156
  primary,
154
157
  alternatives