@elice/material-quiz 1.240718.0-trasncript.0 → 1.240718.0-trasncript.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/_virtual/_rollupPluginBabelHelpers.js +423 -0
- package/cjs/components/eb-sortable/EbDraggable.js +42 -33
- package/cjs/components/eb-sortable/EbDroppable.js +27 -20
- package/cjs/components/markdown-editor/index.d.ts +1 -2
- package/cjs/components/markdown-editor/index.js +19 -10
- package/cjs/components/material-quiz/MaterialQuiz.js +114 -83
- package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +36 -29
- package/cjs/components/material-quiz/MaterialQuizInfo.js +151 -149
- package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +175 -127
- package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +360 -286
- package/cjs/components/material-quiz/MaterialQuizSelectOne.js +172 -126
- package/cjs/components/material-quiz/MaterialQuizShimmer.js +46 -39
- package/cjs/components/material-quiz/MaterialQuizText.js +163 -115
- package/cjs/components/material-quiz/QuizResultBadge.js +32 -22
- package/cjs/components/material-quiz/QuizSubmitStatusText.js +21 -16
- 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 +156 -93
- package/cjs/components/material-quiz/index.js +9 -0
- package/cjs/components/material-quiz/locales/index.js +13 -0
- package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +259 -161
- package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +134 -100
- package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +130 -101
- package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +64 -52
- package/cjs/components/material-quiz/material-quiz-group/context/context.js +5 -1
- package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +47 -36
- package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +280 -232
- package/cjs/components/material-quiz-edit/context.js +8 -2
- package/cjs/components/material-quiz-edit/index.js +7 -0
- package/cjs/components/material-quiz-edit/locales/index.js +13 -0
- package/cjs/components/material-quiz-edit/options/OptionEditor.js +70 -46
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +174 -148
- package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +175 -149
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +164 -144
- package/cjs/components/material-quiz-edit/options/OptionText.js +90 -82
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroup.js +9 -8
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +156 -112
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +288 -196
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +88 -75
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +108 -92
- package/cjs/components/material-quiz-edit/utils/checkTwoDimensionArray.js +5 -1
- package/cjs/components/material-quiz-edit/utils/editValue.js +21 -12
- package/cjs/components/shared/QuestionBox.js +198 -165
- package/cjs/components/shared/QuizDraggbleDroppedOption.js +11 -12
- package/cjs/components/shared/QuizDraggbleDummyOption.js +23 -16
- package/cjs/components/shared/QuizDraggbleOption.js +65 -59
- package/cjs/components/shared/StyledMarkdown.js +5 -1
- package/cjs/components/shared/index.js +19 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +13 -7
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +24 -17
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +59 -68
- package/cjs/components/shared/question-radio/QuestionRadio.js +13 -7
- package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
- package/cjs/components/shared/question-radio/QuestionRadioContext.js +24 -17
- package/cjs/components/shared/question-radio/QuestionRadioOption.js +52 -59
- package/cjs/components/shared/utils/getQuestionStatusStyle.js +7 -9
- package/cjs/components/shared/utils/mergeRefs.js +15 -6
- package/cjs/constant/element.js +3 -3
- package/cjs/constant/index.js +9 -0
- package/cjs/helpers/index.js +8 -10
- package/cjs/hooks/index.js +7 -0
- package/cjs/hooks/useCaculatePassage.js +21 -20
- package/es/_virtual/_rollupPluginBabelHelpers.js +408 -0
- package/es/components/eb-sortable/EbDraggable.js +37 -33
- package/es/components/eb-sortable/EbDroppable.js +22 -20
- package/es/components/markdown-editor/index.d.ts +1 -2
- package/es/components/markdown-editor/index.js +15 -10
- package/es/components/material-quiz/MaterialQuiz.js +109 -83
- package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +32 -29
- package/es/components/material-quiz/MaterialQuizInfo.js +148 -150
- package/es/components/material-quiz/MaterialQuizSelectMultiple.js +171 -127
- package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +356 -287
- package/es/components/material-quiz/MaterialQuizSelectOne.js +168 -126
- package/es/components/material-quiz/MaterialQuizShimmer.js +42 -39
- package/es/components/material-quiz/MaterialQuizText.js +158 -115
- package/es/components/material-quiz/QuizResultBadge.js +27 -22
- package/es/components/material-quiz/QuizSubmitStatusText.js +17 -16
- 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 +153 -94
- package/es/components/material-quiz/index.js +2 -0
- package/es/components/material-quiz/locales/index.js +4 -0
- package/es/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +253 -161
- package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +129 -100
- package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +125 -101
- package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +60 -52
- package/es/components/material-quiz/material-quiz-group/context/context.js +1 -1
- package/es/components/material-quiz-edit/MaterialQuizEdit.js +43 -36
- package/es/components/material-quiz-edit/MaterialQuizEditContent.js +272 -229
- package/es/components/material-quiz-edit/context.js +4 -2
- package/es/components/material-quiz-edit/index.js +1 -0
- package/es/components/material-quiz-edit/locales/index.js +4 -0
- package/es/components/material-quiz-edit/options/OptionEditor.js +64 -46
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +170 -148
- package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +171 -149
- package/es/components/material-quiz-edit/options/OptionSelectOne.js +159 -144
- package/es/components/material-quiz-edit/options/OptionText.js +86 -82
- package/es/components/material-quiz-edit/options/options-group/OptionGroup.js +9 -8
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +151 -112
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +283 -197
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +83 -75
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +103 -92
- package/es/components/material-quiz-edit/utils/checkTwoDimensionArray.js +5 -1
- package/es/components/material-quiz-edit/utils/editValue.js +17 -12
- package/es/components/shared/QuestionBox.js +192 -165
- package/es/components/shared/QuizDraggbleDroppedOption.js +11 -12
- package/es/components/shared/QuizDraggbleDummyOption.js +19 -16
- package/es/components/shared/QuizDraggbleOption.js +61 -59
- package/es/components/shared/StyledMarkdown.js +1 -1
- package/es/components/shared/index.js +7 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.js +9 -7
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +20 -17
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +54 -68
- package/es/components/shared/question-radio/QuestionRadio.js +9 -7
- package/es/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
- package/es/components/shared/question-radio/QuestionRadioContext.js +20 -17
- package/es/components/shared/question-radio/QuestionRadioOption.js +47 -59
- package/es/components/shared/utils/getQuestionStatusStyle.js +7 -9
- package/es/components/shared/utils/mergeRefs.js +15 -6
- package/es/constant/element.js +3 -3
- package/es/constant/index.js +1 -0
- package/es/helpers/index.js +8 -10
- package/es/hooks/index.js +1 -0
- package/es/hooks/useCaculatePassage.js +21 -20
- package/package.json +12 -15
|
@@ -4,8 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
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
|
+
};
|
|
9
15
|
|
|
10
16
|
exports.default = MaterialQuizEditContext;
|
|
11
17
|
exports.useMaterialQuizEditContext = useMaterialQuizEditContext;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var en = require('./en.json.js');
|
|
4
|
+
var ko = require('./ko.json.js');
|
|
5
|
+
var th = require('./th.json.js');
|
|
6
|
+
var ja = require('./ja.json.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.messageEn = en.default;
|
|
11
|
+
exports.messageKo = ko.default;
|
|
12
|
+
exports.messageTh = th.default;
|
|
13
|
+
exports.messageJa = ja.default;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
7
|
var React = require('react');
|
|
7
8
|
var blocks = require('@elice/blocks');
|
|
8
9
|
var designTokens = require('@elice/design-tokens');
|
|
@@ -10,78 +11,101 @@ var material = require('@mui/material');
|
|
|
10
11
|
var classNames = require('classnames');
|
|
11
12
|
var styled = require('styled-components');
|
|
12
13
|
|
|
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
|
+
|
|
13
20
|
//
|
|
14
21
|
//
|
|
15
22
|
//
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
var SHEET_Z_INDEX = 982; // prevent override blocks components.
|
|
24
|
+
var PREFIX = 'em-option-editor';
|
|
18
25
|
//
|
|
19
26
|
//
|
|
20
27
|
//
|
|
21
|
-
|
|
28
|
+
var StyledSortedListItem = styled__default.default(blocks.SortableListItem).withConfig({
|
|
22
29
|
componentId: "sc-50ghuz-0"
|
|
23
30
|
})(["display:flex;padding:0;flex:1;z-index:", ";padding:0;background:transparent;box-shadow:none;margin:0;"], SHEET_Z_INDEX + 1);
|
|
24
|
-
|
|
31
|
+
var StyledTextarea = styled__default.default(blocks.Textarea).withConfig({
|
|
25
32
|
componentId: "sc-50ghuz-1"
|
|
26
|
-
})(["padding:0.75rem 3rem;&.focus{border:1px solid ", ";}", ";", ";", ";"], designTokens.base.color.primary6,
|
|
27
|
-
|
|
33
|
+
})(["padding:0.75rem 3rem;&.focus{border:1px solid ", ";}", ";", ";", ";"], designTokens.base.color.primary6, function (props) {
|
|
34
|
+
return props.invalid ? styled.css(["border:1px solid ", " !important;"], designTokens.base.color.red8) : null;
|
|
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({
|
|
28
41
|
componentId: "sc-50ghuz-2"
|
|
29
42
|
})(["display:flex;position:relative;.em-option-editor-adornment{position:absolute;top:50%;transform:translateY(-50%);z-index:1;&.prefix{left:1rem;}&.suffix{right:1rem;}}"]);
|
|
30
43
|
//
|
|
31
44
|
//
|
|
32
45
|
//
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
index
|
|
41
|
-
} = _a,
|
|
46
|
+
var OptionEditor = React__default.default.forwardRef(function (_a, ref) {
|
|
47
|
+
var suffix = _a.suffix,
|
|
48
|
+
prefix = _a.prefix,
|
|
49
|
+
invalid = _a.invalid,
|
|
50
|
+
invalidText = _a.invalidText,
|
|
51
|
+
readOnly = _a.readOnly,
|
|
52
|
+
index = _a.index,
|
|
42
53
|
props = tslib.__rest(_a, ["suffix", "prefix", "invalid", "invalidText", "readOnly", "index"]);
|
|
43
54
|
/**
|
|
44
55
|
* Extract textarea element from legacy TextArea ref prop.
|
|
45
56
|
*/
|
|
46
|
-
|
|
57
|
+
var handleTextAreaApi = React__default.default.useCallback(function (textAreaApi) {
|
|
47
58
|
var _a;
|
|
48
59
|
if (!ref) {
|
|
49
60
|
return;
|
|
50
61
|
}
|
|
51
|
-
|
|
62
|
+
var textAreaInput = (_a = textAreaApi === null || textAreaApi === void 0 ? void 0 : textAreaApi.input) !== null && _a !== void 0 ? _a : null;
|
|
52
63
|
typeof ref === 'function' ? ref(textAreaInput) : ref.current = textAreaInput;
|
|
53
64
|
}, [ref]);
|
|
54
|
-
return
|
|
65
|
+
return jsxRuntime.jsx(StyledSortedListItem, {
|
|
55
66
|
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,
|
|
69
67
|
disabled: readOnly,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
children: jsxRuntime.jsxs(material.Box, {
|
|
69
|
+
className: classNames__default.default(PREFIX, props.className),
|
|
70
|
+
flex: 1,
|
|
71
|
+
children: [jsxRuntime.jsxs(StyledTextareaWrap, {
|
|
72
|
+
className: "".concat(PREFIX, "-textarea-wrapper"),
|
|
73
|
+
children: [prefix ? jsxRuntime.jsx("div", {
|
|
74
|
+
className: "".concat(PREFIX, "-adornment prefix"),
|
|
75
|
+
children: prefix
|
|
76
|
+
}) : null, jsxRuntime.jsx(StyledTextarea, Object.assign({}, props, {
|
|
77
|
+
ref: handleTextAreaApi,
|
|
78
|
+
invalid: invalid,
|
|
79
|
+
readOnly: readOnly,
|
|
80
|
+
resetFocus: props.onBlur,
|
|
81
|
+
disabled: readOnly,
|
|
82
|
+
"aria-disabled": props.disabled
|
|
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
|
+
});
|
|
85
109
|
});
|
|
86
110
|
|
|
87
111
|
exports.default = OptionEditor;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
7
|
var reactHookForm = require('react-hook-form');
|
|
7
8
|
var reactSortableHoc = require('react-sortable-hoc');
|
|
8
9
|
var reactTransitionGroup = require('react-transition-group');
|
|
@@ -15,56 +16,61 @@ var context = require('../context.js');
|
|
|
15
16
|
var randomId = require('../utils/randomId.js');
|
|
16
17
|
var OptionEditor = require('./OptionEditor.js');
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
20
|
+
|
|
21
|
+
var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
|
|
22
|
+
|
|
23
|
+
var MIN_OPTION_INFO_COUNT = 2;
|
|
24
|
+
var MAX_OPTION_INFO_COUNT = 20;
|
|
25
|
+
var StyledWrap = styled__default.default.div.withConfig({
|
|
21
26
|
componentId: "sc-1nbx9b8-0"
|
|
22
27
|
})(["& > ul{display:flex;flex-direction:column;gap:0.75rem;}"]);
|
|
23
|
-
|
|
28
|
+
var StyledInputGroup = styled__default.default(blocks.SortableListGroup).withConfig({
|
|
24
29
|
componentId: "sc-1nbx9b8-1"
|
|
25
30
|
})(["width:100%;.em-option-editor{margin-bottom:0.5rem;&:last-of-type{margin-bottom:0;}}"]);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
disabled
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
const watchedAnswerInfo = reactHookForm.useWatch({
|
|
48
|
-
control,
|
|
31
|
+
var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
32
|
+
var intl$1 = intl.useRawEliceIntl();
|
|
33
|
+
var _useMaterialQuizEditC = context.useMaterialQuizEditContext(),
|
|
34
|
+
disabled = _useMaterialQuizEditC.disabled;
|
|
35
|
+
var _useFormContext = reactHookForm.useFormContext(),
|
|
36
|
+
control = _useFormContext.control,
|
|
37
|
+
getValues = _useFormContext.getValues,
|
|
38
|
+
setValue = _useFormContext.setValue;
|
|
39
|
+
var _useFieldArray = reactHookForm.useFieldArray({
|
|
40
|
+
control: control,
|
|
41
|
+
name: 'optionsDefault',
|
|
42
|
+
keyName: 'id',
|
|
43
|
+
shouldUnregister: true
|
|
44
|
+
}),
|
|
45
|
+
optionInfoFields = _useFieldArray.fields,
|
|
46
|
+
appendOptionInfoFieldItem = _useFieldArray.append,
|
|
47
|
+
removeOptionInfoFieldItem = _useFieldArray.remove,
|
|
48
|
+
moveOptionInfoFieldItem = _useFieldArray.move;
|
|
49
|
+
var watchedAnswerInfo = reactHookForm.useWatch({
|
|
50
|
+
control: control,
|
|
49
51
|
name: 'answerInfoDefault'
|
|
50
52
|
});
|
|
51
|
-
|
|
52
|
-
control,
|
|
53
|
+
var watchedOptions = reactHookForm.useWatch({
|
|
54
|
+
control: control,
|
|
53
55
|
name: 'optionsDefault'
|
|
54
56
|
});
|
|
55
57
|
/**
|
|
56
58
|
* Update answer info.
|
|
57
59
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
var updateAnswerInfo = function updateAnswerInfo(option) {
|
|
61
|
+
var prevAnswerInfo = getValues('answerInfoDefault');
|
|
60
62
|
if (!Array.isArray(prevAnswerInfo)) {
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
|
-
setValue('answerInfoDefault', !option.checked ? prevAnswerInfo.filter(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
setValue('answerInfoDefault', !option.checked ? prevAnswerInfo.filter(function (answerIndex) {
|
|
66
|
+
return answerIndex !== option.index;
|
|
67
|
+
}).map(function (answerIndex) {
|
|
68
|
+
return option.removed ?
|
|
69
|
+
// if answer removed, re-calculate answer index
|
|
70
|
+
answerIndex < option.index ? answerIndex : answerIndex - 1 :
|
|
71
|
+
// or maintain current answer index
|
|
72
|
+
answerIndex;
|
|
73
|
+
}) : [].concat(_rollupPluginBabelHelpers.toConsumableArray(prevAnswerInfo), [option.index]), {
|
|
68
74
|
shouldDirty: true,
|
|
69
75
|
shouldValidate: true
|
|
70
76
|
});
|
|
@@ -72,7 +78,7 @@ const OptionSelectMultiple = () => {
|
|
|
72
78
|
/**
|
|
73
79
|
* Append option info.
|
|
74
80
|
*/
|
|
75
|
-
|
|
81
|
+
var appendOptionInfo = function appendOptionInfo() {
|
|
76
82
|
appendOptionInfoFieldItem({
|
|
77
83
|
id: randomId.createRandomId(),
|
|
78
84
|
title: '',
|
|
@@ -82,9 +88,9 @@ const OptionSelectMultiple = () => {
|
|
|
82
88
|
/**
|
|
83
89
|
* Remove item from option info at index.
|
|
84
90
|
*/
|
|
85
|
-
|
|
91
|
+
var removeOptionInfo = function removeOptionInfo(index) {
|
|
86
92
|
updateAnswerInfo({
|
|
87
|
-
index,
|
|
93
|
+
index: index,
|
|
88
94
|
checked: false,
|
|
89
95
|
removed: true
|
|
90
96
|
});
|
|
@@ -93,16 +99,21 @@ const OptionSelectMultiple = () => {
|
|
|
93
99
|
/**
|
|
94
100
|
* Sort options based on the old and new index.
|
|
95
101
|
*/
|
|
96
|
-
|
|
97
|
-
oldIndex,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
var handleSortEnd = function handleSortEnd(_ref) {
|
|
103
|
+
var oldIndex = _ref.oldIndex,
|
|
104
|
+
newIndex = _ref.newIndex;
|
|
105
|
+
var prevAnswerInfo = lodashEs.cloneDeep(watchedAnswerInfo);
|
|
106
|
+
var prevOptions = lodashEs.cloneDeep(watchedOptions).map(function (option, index) {
|
|
107
|
+
return Object.assign(Object.assign({}, option), {
|
|
108
|
+
isAnswer: prevAnswerInfo.includes(index)
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
var updatedOptions = reactSortableHoc.arrayMove(prevOptions, oldIndex, newIndex);
|
|
112
|
+
var updatedAnswerInfo = updatedOptions.map(function (option, index) {
|
|
113
|
+
return option.isAnswer ? index : null;
|
|
114
|
+
}).filter(function (option) {
|
|
115
|
+
return option !== null;
|
|
116
|
+
});
|
|
106
117
|
setValue('answerInfoDefault', updatedAnswerInfo);
|
|
107
118
|
moveOptionInfoFieldItem(oldIndex, newIndex);
|
|
108
119
|
};
|
|
@@ -112,107 +123,122 @@ const OptionSelectMultiple = () => {
|
|
|
112
123
|
if (!Array.isArray(watchedAnswerInfo)) {
|
|
113
124
|
return null;
|
|
114
125
|
}
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
return jsxRuntime.jsxs(StyledWrap, {
|
|
127
|
+
children: [jsxRuntime.jsx(reactHookForm.Controller, {
|
|
128
|
+
name: "answerInfoDefault",
|
|
129
|
+
control: control,
|
|
130
|
+
rules: {
|
|
131
|
+
validate: function validate(v) {
|
|
132
|
+
if (Array.isArray(v) && v.length < 1) {
|
|
133
|
+
return intl$1.formatMessage({
|
|
134
|
+
id: 'content.option.errorMessage.required'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
124
138
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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'
|
|
159
|
-
})
|
|
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
|
|
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
|
+
})]
|
|
178
155
|
})
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}), jsxRuntime.jsx(StyledInputGroup, {
|
|
159
|
+
pressDelay: 100,
|
|
160
|
+
useDragHandle: true,
|
|
161
|
+
onSortEnd: handleSortEnd,
|
|
162
|
+
children: optionInfoFields.map(function (_ref3, index) {
|
|
163
|
+
var id = _ref3.id;
|
|
164
|
+
return jsxRuntime.jsx(reactHookForm.Controller, {
|
|
165
|
+
control: control,
|
|
166
|
+
name: "optionsDefault.".concat(index, ".content"),
|
|
167
|
+
rules: {
|
|
168
|
+
required: {
|
|
169
|
+
value: true,
|
|
170
|
+
message: intl$1.formatMessage({
|
|
171
|
+
id: 'option.common.select.errorMessage.required'
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
render: function render(_ref4) {
|
|
176
|
+
var field = _ref4.field,
|
|
177
|
+
fieldState = _ref4.fieldState;
|
|
178
|
+
var _a;
|
|
179
|
+
return jsxRuntime.jsx(OptionEditor.default, Object.assign({
|
|
180
|
+
index: index,
|
|
181
|
+
invalid: fieldState.invalid,
|
|
182
|
+
invalidText: (_a = fieldState === null || fieldState === void 0 ? void 0 : fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
183
|
+
readOnly: disabled,
|
|
184
|
+
prefix: jsxRuntime.jsx(blocks.Checkbox, {
|
|
185
|
+
checked: watchedAnswerInfo.includes(index),
|
|
186
|
+
disabled: disabled,
|
|
187
|
+
onChange: function onChange(checked) {
|
|
188
|
+
return updateAnswerInfo({
|
|
189
|
+
index: index,
|
|
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,
|
|
190
229
|
transparent: true,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
})
|
|
202
|
-
|
|
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
|
-
})))));
|
|
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
|
+
})
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
})]
|
|
241
|
+
});
|
|
216
242
|
};
|
|
217
243
|
|
|
218
244
|
exports.default = OptionSelectMultiple;
|