@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.
Files changed (127) hide show
  1. package/cjs/components/eb-sortable/EbDraggable.js +33 -42
  2. package/cjs/components/eb-sortable/EbDroppable.js +20 -27
  3. package/cjs/components/markdown-editor/index.d.ts +2 -1
  4. package/cjs/components/markdown-editor/index.js +10 -19
  5. package/cjs/components/material-quiz/MaterialQuiz.js +83 -114
  6. package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +29 -36
  7. package/cjs/components/material-quiz/MaterialQuizInfo.js +149 -151
  8. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +127 -175
  9. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +286 -360
  10. package/cjs/components/material-quiz/MaterialQuizSelectOne.js +126 -172
  11. package/cjs/components/material-quiz/MaterialQuizShimmer.js +39 -46
  12. package/cjs/components/material-quiz/MaterialQuizText.js +115 -163
  13. package/cjs/components/material-quiz/QuizResultBadge.js +22 -32
  14. package/cjs/components/material-quiz/QuizSubmitStatusText.js +16 -21
  15. package/cjs/components/material-quiz/constants/color.js +5 -5
  16. package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +1 -1
  17. package/cjs/components/material-quiz/context/MaterialQuizContext.js +93 -156
  18. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +161 -259
  19. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +100 -134
  20. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +101 -130
  21. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +52 -64
  22. package/cjs/components/material-quiz/material-quiz-group/context/context.js +1 -5
  23. package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +36 -47
  24. package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +232 -280
  25. package/cjs/components/material-quiz-edit/context.js +2 -8
  26. package/cjs/components/material-quiz-edit/options/OptionEditor.js +46 -70
  27. package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +148 -174
  28. package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +149 -175
  29. package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +144 -164
  30. package/cjs/components/material-quiz-edit/options/OptionText.js +82 -90
  31. package/cjs/components/material-quiz-edit/options/options-group/OptionGroup.js +8 -9
  32. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +112 -156
  33. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +196 -288
  34. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +75 -88
  35. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +92 -108
  36. package/cjs/components/material-quiz-edit/utils/checkTwoDimensionArray.js +1 -5
  37. package/cjs/components/material-quiz-edit/utils/editValue.js +12 -21
  38. package/cjs/components/shared/QuestionBox.js +165 -198
  39. package/cjs/components/shared/QuizDraggbleDroppedOption.js +12 -11
  40. package/cjs/components/shared/QuizDraggbleDummyOption.js +16 -23
  41. package/cjs/components/shared/QuizDraggbleOption.js +59 -65
  42. package/cjs/components/shared/StyledMarkdown.js +1 -5
  43. package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +7 -13
  44. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
  45. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -24
  46. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +68 -59
  47. package/cjs/components/shared/question-radio/QuestionRadio.js +7 -13
  48. package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
  49. package/cjs/components/shared/question-radio/QuestionRadioContext.js +17 -24
  50. package/cjs/components/shared/question-radio/QuestionRadioOption.js +59 -52
  51. package/cjs/components/shared/utils/getQuestionStatusStyle.js +9 -7
  52. package/cjs/components/shared/utils/mergeRefs.js +6 -15
  53. package/cjs/constant/element.js +3 -3
  54. package/cjs/helpers/index.js +10 -8
  55. package/cjs/hooks/useCaculatePassage.js +20 -21
  56. package/es/components/eb-sortable/EbDraggable.js +33 -37
  57. package/es/components/eb-sortable/EbDroppable.js +20 -22
  58. package/es/components/markdown-editor/index.d.ts +2 -1
  59. package/es/components/markdown-editor/index.js +10 -15
  60. package/es/components/material-quiz/MaterialQuiz.js +83 -109
  61. package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +29 -32
  62. package/es/components/material-quiz/MaterialQuizInfo.js +150 -148
  63. package/es/components/material-quiz/MaterialQuizSelectMultiple.js +127 -171
  64. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +287 -356
  65. package/es/components/material-quiz/MaterialQuizSelectOne.js +126 -168
  66. package/es/components/material-quiz/MaterialQuizShimmer.js +39 -42
  67. package/es/components/material-quiz/MaterialQuizText.js +115 -158
  68. package/es/components/material-quiz/QuizResultBadge.js +22 -27
  69. package/es/components/material-quiz/QuizSubmitStatusText.js +16 -17
  70. package/es/components/material-quiz/constants/color.js +5 -5
  71. package/es/components/material-quiz/context/MaterialQuizContext.d.ts +1 -1
  72. package/es/components/material-quiz/context/MaterialQuizContext.js +94 -153
  73. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +161 -253
  74. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +100 -129
  75. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +101 -125
  76. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +52 -60
  77. package/es/components/material-quiz/material-quiz-group/context/context.js +1 -1
  78. package/es/components/material-quiz-edit/MaterialQuizEdit.js +36 -43
  79. package/es/components/material-quiz-edit/MaterialQuizEditContent.js +229 -272
  80. package/es/components/material-quiz-edit/context.js +2 -4
  81. package/es/components/material-quiz-edit/options/OptionEditor.js +46 -64
  82. package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +148 -170
  83. package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +149 -171
  84. package/es/components/material-quiz-edit/options/OptionSelectOne.js +144 -159
  85. package/es/components/material-quiz-edit/options/OptionText.js +82 -86
  86. package/es/components/material-quiz-edit/options/options-group/OptionGroup.js +8 -9
  87. package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +112 -151
  88. package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +197 -283
  89. package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +75 -83
  90. package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +92 -103
  91. package/es/components/material-quiz-edit/utils/checkTwoDimensionArray.js +1 -5
  92. package/es/components/material-quiz-edit/utils/editValue.js +12 -17
  93. package/es/components/shared/QuestionBox.js +165 -192
  94. package/es/components/shared/QuizDraggbleDroppedOption.js +12 -11
  95. package/es/components/shared/QuizDraggbleDummyOption.js +16 -19
  96. package/es/components/shared/QuizDraggbleOption.js +59 -61
  97. package/es/components/shared/StyledMarkdown.js +1 -1
  98. package/es/components/shared/question-checkbox/QuestionCheckbox.js +7 -9
  99. package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
  100. package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -20
  101. package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +68 -54
  102. package/es/components/shared/question-radio/QuestionRadio.js +7 -9
  103. package/es/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
  104. package/es/components/shared/question-radio/QuestionRadioContext.js +17 -20
  105. package/es/components/shared/question-radio/QuestionRadioOption.js +59 -47
  106. package/es/components/shared/utils/getQuestionStatusStyle.js +9 -7
  107. package/es/components/shared/utils/mergeRefs.js +6 -15
  108. package/es/constant/element.js +3 -3
  109. package/es/helpers/index.js +10 -8
  110. package/es/hooks/useCaculatePassage.js +20 -21
  111. package/package.json +15 -12
  112. package/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -423
  113. package/cjs/components/material-quiz/index.js +0 -9
  114. package/cjs/components/material-quiz/locales/index.js +0 -13
  115. package/cjs/components/material-quiz-edit/index.js +0 -7
  116. package/cjs/components/material-quiz-edit/locales/index.js +0 -13
  117. package/cjs/components/shared/index.js +0 -19
  118. package/cjs/constant/index.js +0 -9
  119. package/cjs/hooks/index.js +0 -7
  120. package/es/_virtual/_rollupPluginBabelHelpers.js +0 -408
  121. package/es/components/material-quiz/index.js +0 -2
  122. package/es/components/material-quiz/locales/index.js +0 -4
  123. package/es/components/material-quiz-edit/index.js +0 -1
  124. package/es/components/material-quiz-edit/locales/index.js +0 -4
  125. package/es/components/shared/index.js +0 -7
  126. package/es/constant/index.js +0 -1
  127. 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
- var SHEET_Z_INDEX = 982; // prevent override blocks components.
14
- var PREFIX = 'em-option-editor';
12
+ const SHEET_Z_INDEX = 982; // prevent override blocks components.
13
+ const PREFIX = 'em-option-editor';
15
14
  //
16
15
  //
17
16
  //
18
- var StyledSortedListItem = styled(SortableListItem).withConfig({
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
- var StyledTextarea = styled(Textarea).withConfig({
20
+ const StyledTextarea = styled(Textarea).withConfig({
22
21
  componentId: "sc-50ghuz-1"
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({
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
- 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,
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
- var handleTextAreaApi = React.useCallback(function (textAreaApi) {
42
+ const handleTextAreaApi = React.useCallback(textAreaApi => {
48
43
  var _a;
49
44
  if (!ref) {
50
45
  return;
51
46
  }
52
- var textAreaInput = (_a = textAreaApi === null || textAreaApi === void 0 ? void 0 : textAreaApi.input) !== null && _a !== void 0 ? _a : null;
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 jsx(StyledSortedListItem, {
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
- 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
- });
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 { toConsumableArray as _toConsumableArray } from '../../../_virtual/_rollupPluginBabelHelpers.js';
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
- var MIN_OPTION_INFO_COUNT = 2;
16
- var MAX_OPTION_INFO_COUNT = 20;
17
- var StyledWrap = styled.div.withConfig({
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
- var StyledInputGroup = styled(SortableListGroup).withConfig({
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
- 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,
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
- var watchedOptions = useWatch({
46
- control: control,
47
+ const watchedOptions = useWatch({
48
+ control,
47
49
  name: 'optionsDefault'
48
50
  });
49
51
  /**
50
52
  * Update answer info.
51
53
  */
52
- var updateAnswerInfo = function updateAnswerInfo(option) {
53
- var prevAnswerInfo = getValues('answerInfoDefault');
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(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]), {
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
- var appendOptionInfo = function appendOptionInfo() {
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
- var removeOptionInfo = function removeOptionInfo(index) {
81
+ const removeOptionInfo = index => {
84
82
  updateAnswerInfo({
85
- index: 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
- 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
- });
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 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;
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
- }), 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,
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 };