@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
@@ -4,8 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
 
7
- const MaterialQuizEditContext = React.createContext(null);
8
- const useMaterialQuizEditContext = () => React.useContext(MaterialQuizEditContext);
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,7 @@
1
+ 'use strict';
2
+
3
+ var MaterialQuizEdit = require('./MaterialQuizEdit.js');
4
+
5
+
6
+
7
+ exports.MaterialQuizEdit = MaterialQuizEdit.default;
@@ -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
- const SHEET_Z_INDEX = 982; // prevent override blocks components.
17
- const PREFIX = 'em-option-editor';
23
+ var SHEET_Z_INDEX = 982; // prevent override blocks components.
24
+ var PREFIX = 'em-option-editor';
18
25
  //
19
26
  //
20
27
  //
21
- const StyledSortedListItem = styled(blocks.SortableListItem).withConfig({
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
- const StyledTextarea = styled(blocks.Textarea).withConfig({
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, 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({
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
- const OptionEditor = React.forwardRef((_a, ref) => {
34
- var {
35
- suffix,
36
- prefix,
37
- invalid,
38
- invalidText,
39
- readOnly,
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
- const handleTextAreaApi = React.useCallback(textAreaApi => {
57
+ var handleTextAreaApi = React__default.default.useCallback(function (textAreaApi) {
47
58
  var _a;
48
59
  if (!ref) {
49
60
  return;
50
61
  }
51
- const textAreaInput = (_a = textAreaApi === null || textAreaApi === void 0 ? void 0 : textAreaApi.input) !== null && _a !== void 0 ? _a : null;
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 React.createElement(StyledSortedListItem, {
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
- "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));
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 React = require('react');
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
- const MIN_OPTION_INFO_COUNT = 2;
19
- const MAX_OPTION_INFO_COUNT = 20;
20
- const StyledWrap = styled.div.withConfig({
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
- const StyledInputGroup = styled(blocks.SortableListGroup).withConfig({
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
- 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,
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
- const watchedOptions = reactHookForm.useWatch({
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
- const updateAnswerInfo = option => {
59
- const prevAnswerInfo = getValues('answerInfoDefault');
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(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], {
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
- const appendOptionInfo = () => {
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
- const removeOptionInfo = index => {
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
- 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);
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 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
- });
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
- return true;
126
- }
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'
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
- 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,
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
- 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
- })))));
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;