@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.
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
@@ -4,14 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
 
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
- };
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
- var SHEET_Z_INDEX = 982; // prevent override blocks components.
24
- var PREFIX = 'em-option-editor';
16
+ const SHEET_Z_INDEX = 982; // prevent override blocks components.
17
+ const PREFIX = 'em-option-editor';
25
18
  //
26
19
  //
27
20
  //
28
- var StyledSortedListItem = styled__default.default(blocks.SortableListItem).withConfig({
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
- var StyledTextarea = styled__default.default(blocks.Textarea).withConfig({
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, 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({
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
- 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,
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
- var handleTextAreaApi = React__default.default.useCallback(function (textAreaApi) {
46
+ const handleTextAreaApi = React.useCallback(textAreaApi => {
58
47
  var _a;
59
48
  if (!ref) {
60
49
  return;
61
50
  }
62
- var textAreaInput = (_a = textAreaApi === null || textAreaApi === void 0 ? void 0 : textAreaApi.input) !== null && _a !== void 0 ? _a : null;
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 jsxRuntime.jsx(StyledSortedListItem, {
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
- 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
- });
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 _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
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
- 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({
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
- var StyledInputGroup = styled__default.default(blocks.SortableListGroup).withConfig({
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
- 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,
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
- var watchedOptions = reactHookForm.useWatch({
54
- control: control,
51
+ const watchedOptions = reactHookForm.useWatch({
52
+ control,
55
53
  name: 'optionsDefault'
56
54
  });
57
55
  /**
58
56
  * Update answer info.
59
57
  */
60
- var updateAnswerInfo = function updateAnswerInfo(option) {
61
- var prevAnswerInfo = getValues('answerInfoDefault');
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(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]), {
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
- var appendOptionInfo = function appendOptionInfo() {
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
- var removeOptionInfo = function removeOptionInfo(index) {
85
+ const removeOptionInfo = index => {
92
86
  updateAnswerInfo({
93
- index: 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
- 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
- });
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 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;
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
- }), 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,
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;