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