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