@elice/material-quiz 1.240718.0-trasncript.2 → 1.240718.2
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.
- package/cjs/components/eb-sortable/EbDraggable.js +33 -42
- package/cjs/components/eb-sortable/EbDroppable.js +20 -27
- package/cjs/components/markdown-editor/index.d.ts +2 -1
- package/cjs/components/markdown-editor/index.js +10 -19
- package/cjs/components/material-quiz/MaterialQuiz.js +83 -114
- package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +29 -36
- package/cjs/components/material-quiz/MaterialQuizInfo.js +149 -151
- package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +127 -175
- package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +286 -360
- package/cjs/components/material-quiz/MaterialQuizSelectOne.js +126 -172
- package/cjs/components/material-quiz/MaterialQuizShimmer.js +39 -46
- package/cjs/components/material-quiz/MaterialQuizText.js +115 -163
- package/cjs/components/material-quiz/QuizResultBadge.js +22 -32
- package/cjs/components/material-quiz/QuizSubmitStatusText.js +16 -21
- package/cjs/components/material-quiz/constants/color.js +5 -5
- package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +1 -1
- package/cjs/components/material-quiz/context/MaterialQuizContext.js +93 -156
- package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +161 -259
- package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +100 -134
- package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +101 -130
- package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +52 -64
- package/cjs/components/material-quiz/material-quiz-group/context/context.js +1 -5
- package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +36 -47
- package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +232 -280
- package/cjs/components/material-quiz-edit/context.js +2 -8
- package/cjs/components/material-quiz-edit/options/OptionEditor.js +46 -70
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +148 -174
- package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +149 -175
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +144 -164
- package/cjs/components/material-quiz-edit/options/OptionText.js +82 -90
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroup.js +8 -9
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +112 -156
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +196 -288
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +75 -88
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +92 -108
- package/cjs/components/material-quiz-edit/utils/checkTwoDimensionArray.js +1 -5
- package/cjs/components/material-quiz-edit/utils/editValue.js +12 -21
- package/cjs/components/shared/QuestionBox.js +165 -198
- package/cjs/components/shared/QuizDraggbleDroppedOption.js +12 -11
- package/cjs/components/shared/QuizDraggbleDummyOption.js +16 -23
- package/cjs/components/shared/QuizDraggbleOption.js +59 -65
- package/cjs/components/shared/StyledMarkdown.js +1 -5
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +7 -13
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -24
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +68 -59
- package/cjs/components/shared/question-radio/QuestionRadio.js +7 -13
- package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
- package/cjs/components/shared/question-radio/QuestionRadioContext.js +17 -24
- package/cjs/components/shared/question-radio/QuestionRadioOption.js +59 -52
- package/cjs/components/shared/utils/getQuestionStatusStyle.js +9 -7
- package/cjs/components/shared/utils/mergeRefs.js +6 -15
- package/cjs/constant/element.js +3 -3
- package/cjs/helpers/index.js +10 -8
- package/cjs/hooks/useCaculatePassage.js +20 -21
- package/es/components/eb-sortable/EbDraggable.js +33 -37
- package/es/components/eb-sortable/EbDroppable.js +20 -22
- package/es/components/markdown-editor/index.d.ts +2 -1
- package/es/components/markdown-editor/index.js +10 -15
- package/es/components/material-quiz/MaterialQuiz.js +83 -109
- package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +29 -32
- package/es/components/material-quiz/MaterialQuizInfo.js +150 -148
- package/es/components/material-quiz/MaterialQuizSelectMultiple.js +127 -171
- package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +287 -356
- package/es/components/material-quiz/MaterialQuizSelectOne.js +126 -168
- package/es/components/material-quiz/MaterialQuizShimmer.js +39 -42
- package/es/components/material-quiz/MaterialQuizText.js +115 -158
- package/es/components/material-quiz/QuizResultBadge.js +22 -27
- package/es/components/material-quiz/QuizSubmitStatusText.js +16 -17
- package/es/components/material-quiz/constants/color.js +5 -5
- package/es/components/material-quiz/context/MaterialQuizContext.d.ts +1 -1
- package/es/components/material-quiz/context/MaterialQuizContext.js +94 -153
- package/es/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +161 -253
- package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +100 -129
- package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +101 -125
- package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +52 -60
- package/es/components/material-quiz/material-quiz-group/context/context.js +1 -1
- package/es/components/material-quiz-edit/MaterialQuizEdit.js +36 -43
- package/es/components/material-quiz-edit/MaterialQuizEditContent.js +229 -272
- package/es/components/material-quiz-edit/context.js +2 -4
- package/es/components/material-quiz-edit/options/OptionEditor.js +46 -64
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +148 -170
- package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +149 -171
- package/es/components/material-quiz-edit/options/OptionSelectOne.js +144 -159
- package/es/components/material-quiz-edit/options/OptionText.js +82 -86
- package/es/components/material-quiz-edit/options/options-group/OptionGroup.js +8 -9
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +112 -151
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +197 -283
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +75 -83
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +92 -103
- package/es/components/material-quiz-edit/utils/checkTwoDimensionArray.js +1 -5
- package/es/components/material-quiz-edit/utils/editValue.js +12 -17
- package/es/components/shared/QuestionBox.js +165 -192
- package/es/components/shared/QuizDraggbleDroppedOption.js +12 -11
- package/es/components/shared/QuizDraggbleDummyOption.js +16 -19
- package/es/components/shared/QuizDraggbleOption.js +59 -61
- package/es/components/shared/StyledMarkdown.js +1 -1
- package/es/components/shared/question-checkbox/QuestionCheckbox.js +7 -9
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -20
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +68 -54
- package/es/components/shared/question-radio/QuestionRadio.js +7 -9
- package/es/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
- package/es/components/shared/question-radio/QuestionRadioContext.js +17 -20
- package/es/components/shared/question-radio/QuestionRadioOption.js +59 -47
- package/es/components/shared/utils/getQuestionStatusStyle.js +9 -7
- package/es/components/shared/utils/mergeRefs.js +6 -15
- package/es/constant/element.js +3 -3
- package/es/helpers/index.js +10 -8
- package/es/hooks/useCaculatePassage.js +20 -21
- package/package.json +15 -12
- package/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -423
- package/cjs/components/material-quiz/index.js +0 -9
- package/cjs/components/material-quiz/locales/index.js +0 -13
- package/cjs/components/material-quiz-edit/index.js +0 -7
- package/cjs/components/material-quiz-edit/locales/index.js +0 -13
- package/cjs/components/shared/index.js +0 -19
- package/cjs/constant/index.js +0 -9
- package/cjs/hooks/index.js +0 -7
- package/es/_virtual/_rollupPluginBabelHelpers.js +0 -408
- package/es/components/material-quiz/index.js +0 -2
- package/es/components/material-quiz/locales/index.js +0 -4
- package/es/components/material-quiz-edit/index.js +0 -1
- package/es/components/material-quiz-edit/locales/index.js +0 -4
- package/es/components/shared/index.js +0 -7
- package/es/constant/index.js +0 -1
- package/es/hooks/index.js +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { __rest } from 'tslib';
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import { SortableListItem, Textarea, Text } from '@elice/blocks';
|
|
5
4
|
import { base } from '@elice/design-tokens';
|
|
@@ -10,92 +9,75 @@ import styled, { css } from 'styled-components';
|
|
|
10
9
|
//
|
|
11
10
|
//
|
|
12
11
|
//
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const SHEET_Z_INDEX = 982; // prevent override blocks components.
|
|
13
|
+
const PREFIX = 'em-option-editor';
|
|
15
14
|
//
|
|
16
15
|
//
|
|
17
16
|
//
|
|
18
|
-
|
|
17
|
+
const StyledSortedListItem = styled(SortableListItem).withConfig({
|
|
19
18
|
componentId: "sc-50ghuz-0"
|
|
20
19
|
})(["display:flex;padding:0;flex:1;z-index:", ";padding:0;background:transparent;box-shadow:none;margin:0;"], SHEET_Z_INDEX + 1);
|
|
21
|
-
|
|
20
|
+
const StyledTextarea = styled(Textarea).withConfig({
|
|
22
21
|
componentId: "sc-50ghuz-1"
|
|
23
|
-
})(["padding:0.75rem 3rem;&.focus{border:1px solid ", ";}", ";", ";", ";"], base.color.primary6,
|
|
24
|
-
|
|
25
|
-
}, function (props) {
|
|
26
|
-
return props.disabled ? css(["background-color:", ";cursor:not-allowed;"], base.color.gray2) : null;
|
|
27
|
-
}, function (props) {
|
|
28
|
-
return props.readOnly ? css(["background-color:", ";"], base.color.gray1) : null;
|
|
29
|
-
});
|
|
30
|
-
var StyledTextareaWrap = styled.div.withConfig({
|
|
22
|
+
})(["padding:0.75rem 3rem;&.focus{border:1px solid ", ";}", ";", ";", ";"], base.color.primary6, props => props.invalid ? css(["border:1px solid ", " !important;"], base.color.red8) : null, props => props.disabled ? css(["background-color:", ";cursor:not-allowed;"], base.color.gray2) : null, props => props.readOnly ? css(["background-color:", ";"], base.color.gray1) : null);
|
|
23
|
+
const StyledTextareaWrap = styled.div.withConfig({
|
|
31
24
|
componentId: "sc-50ghuz-2"
|
|
32
25
|
})(["display:flex;position:relative;.em-option-editor-adornment{position:absolute;top:50%;transform:translateY(-50%);z-index:1;&.prefix{left:1rem;}&.suffix{right:1rem;}}"]);
|
|
33
26
|
//
|
|
34
27
|
//
|
|
35
28
|
//
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
const OptionEditor = React.forwardRef((_a, ref) => {
|
|
30
|
+
var {
|
|
31
|
+
suffix,
|
|
32
|
+
prefix,
|
|
33
|
+
invalid,
|
|
34
|
+
invalidText,
|
|
35
|
+
readOnly,
|
|
36
|
+
index
|
|
37
|
+
} = _a,
|
|
43
38
|
props = __rest(_a, ["suffix", "prefix", "invalid", "invalidText", "readOnly", "index"]);
|
|
44
39
|
/**
|
|
45
40
|
* Extract textarea element from legacy TextArea ref prop.
|
|
46
41
|
*/
|
|
47
|
-
|
|
42
|
+
const handleTextAreaApi = React.useCallback(textAreaApi => {
|
|
48
43
|
var _a;
|
|
49
44
|
if (!ref) {
|
|
50
45
|
return;
|
|
51
46
|
}
|
|
52
|
-
|
|
47
|
+
const textAreaInput = (_a = textAreaApi === null || textAreaApi === void 0 ? void 0 : textAreaApi.input) !== null && _a !== void 0 ? _a : null;
|
|
53
48
|
typeof ref === 'function' ? ref(textAreaInput) : ref.current = textAreaInput;
|
|
54
49
|
}, [ref]);
|
|
55
|
-
return
|
|
50
|
+
return React.createElement(StyledSortedListItem, {
|
|
56
51
|
index: index,
|
|
52
|
+
disabled: readOnly
|
|
53
|
+
}, React.createElement(Box, {
|
|
54
|
+
className: classNames(PREFIX, props.className),
|
|
55
|
+
flex: 1
|
|
56
|
+
}, React.createElement(StyledTextareaWrap, {
|
|
57
|
+
className: `${PREFIX}-textarea-wrapper`
|
|
58
|
+
}, prefix ? React.createElement("div", {
|
|
59
|
+
className: `${PREFIX}-adornment prefix`
|
|
60
|
+
}, prefix) : null, React.createElement(StyledTextarea, Object.assign({}, props, {
|
|
61
|
+
ref: handleTextAreaApi,
|
|
62
|
+
invalid: invalid,
|
|
63
|
+
readOnly: readOnly,
|
|
64
|
+
resetFocus: props.onBlur,
|
|
57
65
|
disabled: readOnly,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})), suffix ? jsx("div", {
|
|
74
|
-
className: "".concat(PREFIX, "-adornment suffix"),
|
|
75
|
-
onDragStart: function onDragStart(e) {
|
|
76
|
-
return e.stopPropagation();
|
|
77
|
-
},
|
|
78
|
-
onDragCapture: function onDragCapture(e) {
|
|
79
|
-
return e.stopPropagation();
|
|
80
|
-
},
|
|
81
|
-
onTouchStart: function onTouchStart(e) {
|
|
82
|
-
return e.stopPropagation();
|
|
83
|
-
},
|
|
84
|
-
children: suffix
|
|
85
|
-
}) : null]
|
|
86
|
-
}), invalid ? jsx(Box, {
|
|
87
|
-
padding: "0 0.75rem",
|
|
88
|
-
marginTop: "0.25rem",
|
|
89
|
-
className: "".concat(PREFIX, "-helperText-wrap"),
|
|
90
|
-
children: jsx(Text, {
|
|
91
|
-
role: "red",
|
|
92
|
-
size: "tiny",
|
|
93
|
-
className: "".concat(PREFIX, "-helperText"),
|
|
94
|
-
children: invalidText !== null && invalidText !== void 0 ? invalidText : ''
|
|
95
|
-
})
|
|
96
|
-
}) : null]
|
|
97
|
-
})
|
|
98
|
-
});
|
|
66
|
+
"aria-disabled": props.disabled
|
|
67
|
+
})), suffix ? React.createElement("div", {
|
|
68
|
+
className: `${PREFIX}-adornment suffix`,
|
|
69
|
+
onDragStart: e => e.stopPropagation(),
|
|
70
|
+
onDragCapture: e => e.stopPropagation(),
|
|
71
|
+
onTouchStart: e => e.stopPropagation()
|
|
72
|
+
}, suffix) : null), invalid ? React.createElement(Box, {
|
|
73
|
+
padding: "0 0.75rem",
|
|
74
|
+
marginTop: "0.25rem",
|
|
75
|
+
className: `${PREFIX}-helperText-wrap`
|
|
76
|
+
}, React.createElement(Text, {
|
|
77
|
+
role: "red",
|
|
78
|
+
size: "tiny",
|
|
79
|
+
className: `${PREFIX}-helperText`
|
|
80
|
+
}, invalidText !== null && invalidText !== void 0 ? invalidText : '')) : null));
|
|
99
81
|
});
|
|
100
82
|
|
|
101
83
|
export { OptionEditor as default };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
1
|
+
import React from 'react';
|
|
3
2
|
import { useFormContext, useFieldArray, useWatch, Controller } from 'react-hook-form';
|
|
4
3
|
import { arrayMove } from 'react-sortable-hoc';
|
|
5
4
|
import { Transition } from 'react-transition-group';
|
|
@@ -12,57 +11,56 @@ import { useMaterialQuizEditContext } from '../context.js';
|
|
|
12
11
|
import { createRandomId } from '../utils/randomId.js';
|
|
13
12
|
import OptionEditor from './OptionEditor.js';
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const MIN_OPTION_INFO_COUNT = 2;
|
|
15
|
+
const MAX_OPTION_INFO_COUNT = 20;
|
|
16
|
+
const StyledWrap = styled.div.withConfig({
|
|
18
17
|
componentId: "sc-1nbx9b8-0"
|
|
19
18
|
})(["& > ul{display:flex;flex-direction:column;gap:0.75rem;}"]);
|
|
20
|
-
|
|
19
|
+
const StyledInputGroup = styled(SortableListGroup).withConfig({
|
|
21
20
|
componentId: "sc-1nbx9b8-1"
|
|
22
21
|
})(["width:100%;.em-option-editor{margin-bottom:0.5rem;&:last-of-type{margin-bottom:0;}}"]);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
disabled
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
const OptionSelectMultiple = () => {
|
|
23
|
+
const intl = useRawEliceIntl();
|
|
24
|
+
const {
|
|
25
|
+
disabled
|
|
26
|
+
} = useMaterialQuizEditContext();
|
|
27
|
+
const {
|
|
28
|
+
control,
|
|
29
|
+
getValues,
|
|
30
|
+
setValue
|
|
31
|
+
} = useFormContext();
|
|
32
|
+
const {
|
|
33
|
+
fields: optionInfoFields,
|
|
34
|
+
append: appendOptionInfoFieldItem,
|
|
35
|
+
remove: removeOptionInfoFieldItem,
|
|
36
|
+
move: moveOptionInfoFieldItem
|
|
37
|
+
} = useFieldArray({
|
|
38
|
+
control,
|
|
39
|
+
name: 'optionsDefault',
|
|
40
|
+
keyName: 'id',
|
|
41
|
+
shouldUnregister: true
|
|
42
|
+
});
|
|
43
|
+
const watchedAnswerInfo = useWatch({
|
|
44
|
+
control,
|
|
43
45
|
name: 'answerInfoDefault'
|
|
44
46
|
});
|
|
45
|
-
|
|
46
|
-
control
|
|
47
|
+
const watchedOptions = useWatch({
|
|
48
|
+
control,
|
|
47
49
|
name: 'optionsDefault'
|
|
48
50
|
});
|
|
49
51
|
/**
|
|
50
52
|
* Update answer info.
|
|
51
53
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
const updateAnswerInfo = option => {
|
|
55
|
+
const prevAnswerInfo = getValues('answerInfoDefault');
|
|
54
56
|
if (!Array.isArray(prevAnswerInfo)) {
|
|
55
57
|
return;
|
|
56
58
|
}
|
|
57
|
-
setValue('answerInfoDefault', !option.checked ? prevAnswerInfo.filter(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
answerIndex < option.index ? answerIndex : answerIndex - 1 :
|
|
63
|
-
// or maintain current answer index
|
|
64
|
-
answerIndex;
|
|
65
|
-
}) : [].concat(_toConsumableArray(prevAnswerInfo), [option.index]), {
|
|
59
|
+
setValue('answerInfoDefault', !option.checked ? prevAnswerInfo.filter(answerIndex => answerIndex !== option.index).map(answerIndex => option.removed ?
|
|
60
|
+
// if answer removed, re-calculate answer index
|
|
61
|
+
answerIndex < option.index ? answerIndex : answerIndex - 1 :
|
|
62
|
+
// or maintain current answer index
|
|
63
|
+
answerIndex) : [...prevAnswerInfo, option.index], {
|
|
66
64
|
shouldDirty: true,
|
|
67
65
|
shouldValidate: true
|
|
68
66
|
});
|
|
@@ -70,7 +68,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
70
68
|
/**
|
|
71
69
|
* Append option info.
|
|
72
70
|
*/
|
|
73
|
-
|
|
71
|
+
const appendOptionInfo = () => {
|
|
74
72
|
appendOptionInfoFieldItem({
|
|
75
73
|
id: createRandomId(),
|
|
76
74
|
title: '',
|
|
@@ -80,9 +78,9 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
80
78
|
/**
|
|
81
79
|
* Remove item from option info at index.
|
|
82
80
|
*/
|
|
83
|
-
|
|
81
|
+
const removeOptionInfo = index => {
|
|
84
82
|
updateAnswerInfo({
|
|
85
|
-
index
|
|
83
|
+
index,
|
|
86
84
|
checked: false,
|
|
87
85
|
removed: true
|
|
88
86
|
});
|
|
@@ -91,21 +89,16 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
91
89
|
/**
|
|
92
90
|
* Sort options based on the old and new index.
|
|
93
91
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var updatedAnswerInfo = updatedOptions.map(function (option, index) {
|
|
105
|
-
return option.isAnswer ? index : null;
|
|
106
|
-
}).filter(function (option) {
|
|
107
|
-
return option !== null;
|
|
108
|
-
});
|
|
92
|
+
const handleSortEnd = ({
|
|
93
|
+
oldIndex,
|
|
94
|
+
newIndex
|
|
95
|
+
}) => {
|
|
96
|
+
const prevAnswerInfo = cloneDeep(watchedAnswerInfo);
|
|
97
|
+
const prevOptions = cloneDeep(watchedOptions).map((option, index) => Object.assign(Object.assign({}, option), {
|
|
98
|
+
isAnswer: prevAnswerInfo.includes(index)
|
|
99
|
+
}));
|
|
100
|
+
const updatedOptions = arrayMove(prevOptions, oldIndex, newIndex);
|
|
101
|
+
const updatedAnswerInfo = updatedOptions.map((option, index) => option.isAnswer ? index : null).filter(option => option !== null);
|
|
109
102
|
setValue('answerInfoDefault', updatedAnswerInfo);
|
|
110
103
|
moveOptionInfoFieldItem(oldIndex, newIndex);
|
|
111
104
|
};
|
|
@@ -115,122 +108,107 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
115
108
|
if (!Array.isArray(watchedAnswerInfo)) {
|
|
116
109
|
return null;
|
|
117
110
|
}
|
|
118
|
-
return
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
return true;
|
|
111
|
+
return React.createElement(StyledWrap, null, React.createElement(Controller, {
|
|
112
|
+
name: "answerInfoDefault",
|
|
113
|
+
control: control,
|
|
114
|
+
rules: {
|
|
115
|
+
validate: v => {
|
|
116
|
+
if (Array.isArray(v) && v.length < 1) {
|
|
117
|
+
return intl.formatMessage({
|
|
118
|
+
id: 'content.option.errorMessage.required'
|
|
119
|
+
});
|
|
130
120
|
}
|
|
131
|
-
|
|
132
|
-
render: function render(_ref2) {
|
|
133
|
-
var fieldState = _ref2.fieldState;
|
|
134
|
-
var _a;
|
|
135
|
-
return jsx(Transition, {
|
|
136
|
-
in: fieldState.invalid,
|
|
137
|
-
timeout: 0,
|
|
138
|
-
mountOnEnter: true,
|
|
139
|
-
unmountOnExit: true,
|
|
140
|
-
children: jsxs(Fragment, {
|
|
141
|
-
children: [jsx(StatusText, {
|
|
142
|
-
children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
143
|
-
role: "danger"
|
|
144
|
-
}), jsx(Vspace, {
|
|
145
|
-
height: 0.5
|
|
146
|
-
})]
|
|
147
|
-
})
|
|
148
|
-
});
|
|
121
|
+
return true;
|
|
149
122
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
checked: checked
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}),
|
|
186
|
-
suffix: jsx(Tooltip, {
|
|
187
|
-
title: optionInfoFields.length <= MIN_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
188
|
-
id: 'option.common.select.tooltip.minOptionInfoItem'
|
|
189
|
-
}) : undefined,
|
|
190
|
-
placement: "top-start",
|
|
191
|
-
children: jsx("span", {
|
|
192
|
-
children: jsx(IconButton, {
|
|
193
|
-
icon: eilMathsignMultiplyBasic,
|
|
194
|
-
size: "tiny",
|
|
195
|
-
role: "grey9",
|
|
196
|
-
border: false,
|
|
197
|
-
transparent: true,
|
|
198
|
-
disabled: optionInfoFields.length <= MIN_OPTION_INFO_COUNT || disabled,
|
|
199
|
-
onClick: function onClick() {
|
|
200
|
-
return removeOptionInfo(index);
|
|
201
|
-
}
|
|
202
|
-
})
|
|
203
|
-
})
|
|
204
|
-
})
|
|
205
|
-
}, field));
|
|
206
|
-
}
|
|
207
|
-
}, id);
|
|
208
|
-
})
|
|
209
|
-
}), jsx(Vspace, {
|
|
210
|
-
height: 0.5
|
|
211
|
-
}), jsx(Tooltip, {
|
|
212
|
-
title: optionInfoFields.length >= MAX_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
213
|
-
id: 'option.common.select.tooltip.maxOptionInfoItem'
|
|
214
|
-
}) : undefined,
|
|
215
|
-
placement: "bottom",
|
|
216
|
-
children: jsx("span", {
|
|
217
|
-
children: jsx(Button, {
|
|
218
|
-
block: true,
|
|
219
|
-
size: "micro",
|
|
220
|
-
borderDashed: true,
|
|
221
|
-
transparent: true,
|
|
222
|
-
icon: jsx(Icon, {
|
|
223
|
-
icon: eilMathsignAddCircle
|
|
224
|
-
}),
|
|
225
|
-
disabled: optionInfoFields.length >= MAX_OPTION_INFO_COUNT || disabled,
|
|
226
|
-
onClick: appendOptionInfo,
|
|
227
|
-
children: intl.formatMessage({
|
|
228
|
-
id: 'option.common.select.addButton'
|
|
229
|
-
})
|
|
123
|
+
},
|
|
124
|
+
render: ({
|
|
125
|
+
fieldState
|
|
126
|
+
}) => {
|
|
127
|
+
var _a;
|
|
128
|
+
return React.createElement(Transition, {
|
|
129
|
+
in: fieldState.invalid,
|
|
130
|
+
timeout: 0,
|
|
131
|
+
mountOnEnter: true,
|
|
132
|
+
unmountOnExit: true
|
|
133
|
+
}, React.createElement(React.Fragment, null, React.createElement(StatusText, {
|
|
134
|
+
children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
135
|
+
role: "danger"
|
|
136
|
+
}), React.createElement(Vspace, {
|
|
137
|
+
height: 0.5
|
|
138
|
+
})));
|
|
139
|
+
}
|
|
140
|
+
}), React.createElement(StyledInputGroup, {
|
|
141
|
+
pressDelay: 100,
|
|
142
|
+
useDragHandle: true,
|
|
143
|
+
onSortEnd: handleSortEnd
|
|
144
|
+
}, optionInfoFields.map(({
|
|
145
|
+
id
|
|
146
|
+
}, index) => React.createElement(Controller, {
|
|
147
|
+
key: id,
|
|
148
|
+
control: control,
|
|
149
|
+
name: `optionsDefault.${index}.content`,
|
|
150
|
+
rules: {
|
|
151
|
+
required: {
|
|
152
|
+
value: true,
|
|
153
|
+
message: intl.formatMessage({
|
|
154
|
+
id: 'option.common.select.errorMessage.required'
|
|
230
155
|
})
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
render: ({
|
|
159
|
+
field,
|
|
160
|
+
fieldState
|
|
161
|
+
}) => {
|
|
162
|
+
var _a;
|
|
163
|
+
return React.createElement(OptionEditor, Object.assign({
|
|
164
|
+
index: index,
|
|
165
|
+
invalid: fieldState.invalid,
|
|
166
|
+
invalidText: (_a = fieldState === null || fieldState === void 0 ? void 0 : fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
167
|
+
readOnly: disabled,
|
|
168
|
+
prefix: React.createElement(Checkbox, {
|
|
169
|
+
checked: watchedAnswerInfo.includes(index),
|
|
170
|
+
disabled: disabled,
|
|
171
|
+
onChange: checked => updateAnswerInfo({
|
|
172
|
+
index,
|
|
173
|
+
checked
|
|
174
|
+
})
|
|
175
|
+
}),
|
|
176
|
+
suffix: React.createElement(Tooltip, {
|
|
177
|
+
title: optionInfoFields.length <= MIN_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
178
|
+
id: 'option.common.select.tooltip.minOptionInfoItem'
|
|
179
|
+
}) : undefined,
|
|
180
|
+
placement: "top-start"
|
|
181
|
+
}, React.createElement("span", null, React.createElement(IconButton, {
|
|
182
|
+
icon: eilMathsignMultiplyBasic,
|
|
183
|
+
size: "tiny",
|
|
184
|
+
role: "grey9",
|
|
185
|
+
border: false,
|
|
186
|
+
transparent: true,
|
|
187
|
+
disabled: optionInfoFields.length <= MIN_OPTION_INFO_COUNT || disabled,
|
|
188
|
+
onClick: () => removeOptionInfo(index)
|
|
189
|
+
})))
|
|
190
|
+
}, field));
|
|
191
|
+
}
|
|
192
|
+
}))), React.createElement(Vspace, {
|
|
193
|
+
height: 0.5
|
|
194
|
+
}), React.createElement(Tooltip, {
|
|
195
|
+
title: optionInfoFields.length >= MAX_OPTION_INFO_COUNT ? intl.formatMessage({
|
|
196
|
+
id: 'option.common.select.tooltip.maxOptionInfoItem'
|
|
197
|
+
}) : undefined,
|
|
198
|
+
placement: "bottom"
|
|
199
|
+
}, React.createElement("span", null, React.createElement(Button, {
|
|
200
|
+
block: true,
|
|
201
|
+
size: "micro",
|
|
202
|
+
borderDashed: true,
|
|
203
|
+
transparent: true,
|
|
204
|
+
icon: React.createElement(Icon, {
|
|
205
|
+
icon: eilMathsignAddCircle
|
|
206
|
+
}),
|
|
207
|
+
disabled: optionInfoFields.length >= MAX_OPTION_INFO_COUNT || disabled,
|
|
208
|
+
onClick: appendOptionInfo
|
|
209
|
+
}, intl.formatMessage({
|
|
210
|
+
id: 'option.common.select.addButton'
|
|
211
|
+
})))));
|
|
234
212
|
};
|
|
235
213
|
|
|
236
214
|
export { OptionSelectMultiple as default };
|