@elice/material-quiz 1.220803.0

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 (160) hide show
  1. package/README.md +3 -0
  2. package/cjs/components/eb-sortable/EbDraggable.d.ts +18 -0
  3. package/cjs/components/eb-sortable/EbDraggable.js +112 -0
  4. package/cjs/components/eb-sortable/EbDroppable.d.ts +13 -0
  5. package/cjs/components/eb-sortable/EbDroppable.js +60 -0
  6. package/cjs/components/eb-sortable/EbSortable.d.ts +17 -0
  7. package/cjs/components/material-quiz/MaterialQuiz.d.ts +4 -0
  8. package/cjs/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
  9. package/cjs/components/material-quiz/MaterialQuiz.i18n.js +55 -0
  10. package/cjs/components/material-quiz/MaterialQuiz.js +114 -0
  11. package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
  12. package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +55 -0
  13. package/cjs/components/material-quiz/MaterialQuizError.d.ts +3 -0
  14. package/cjs/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
  15. package/cjs/components/material-quiz/MaterialQuizInfo.js +74 -0
  16. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
  17. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +203 -0
  18. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
  19. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +468 -0
  20. package/cjs/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
  21. package/cjs/components/material-quiz/MaterialQuizSelectOne.js +191 -0
  22. package/cjs/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
  23. package/cjs/components/material-quiz/MaterialQuizShimmer.js +61 -0
  24. package/cjs/components/material-quiz/MaterialQuizText.d.ts +3 -0
  25. package/cjs/components/material-quiz/MaterialQuizText.js +181 -0
  26. package/cjs/components/material-quiz/QuizResultBadge.d.ts +7 -0
  27. package/cjs/components/material-quiz/QuizResultBadge.js +48 -0
  28. package/cjs/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
  29. package/cjs/components/material-quiz/QuizSubmitStatusText.js +38 -0
  30. package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
  31. package/cjs/components/material-quiz/context/MaterialQuizContext.js +134 -0
  32. package/cjs/components/material-quiz/index.d.ts +3 -0
  33. package/cjs/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
  34. package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +91 -0
  35. package/cjs/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
  36. package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +463 -0
  37. package/cjs/components/material-quiz-edit/context.d.ts +6 -0
  38. package/cjs/components/material-quiz-edit/context.js +15 -0
  39. package/cjs/components/material-quiz-edit/index.d.ts +2 -0
  40. package/cjs/components/material-quiz-edit/locales.d.ts +34 -0
  41. package/cjs/components/material-quiz-edit/locales.js +73 -0
  42. package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
  43. package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +204 -0
  44. package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
  45. package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +205 -0
  46. package/cjs/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
  47. package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +207 -0
  48. package/cjs/components/material-quiz-edit/options/OptionText.d.ts +3 -0
  49. package/cjs/components/material-quiz-edit/options/OptionText.js +99 -0
  50. package/cjs/components/material-quiz-edit/utils/editValue.d.ts +15 -0
  51. package/cjs/components/material-quiz-edit/utils/editValue.js +37 -0
  52. package/cjs/components/material-quiz-edit/utils/randomId.d.ts +4 -0
  53. package/cjs/components/material-quiz-edit/utils/randomId.js +12 -0
  54. package/cjs/components/shared/QuestionBox.d.ts +16 -0
  55. package/cjs/components/shared/QuestionBox.js +111 -0
  56. package/cjs/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
  57. package/cjs/components/shared/QuizDraggbleDroppedOption.js +31 -0
  58. package/cjs/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
  59. package/cjs/components/shared/QuizDraggbleDummyOption.js +36 -0
  60. package/cjs/components/shared/QuizDraggbleOption.d.ts +14 -0
  61. package/cjs/components/shared/QuizDraggbleOption.js +191 -0
  62. package/cjs/components/shared/StyledMarkdown.d.ts +3 -0
  63. package/cjs/components/shared/StyledMarkdown.js +14 -0
  64. package/cjs/components/shared/index.d.ts +7 -0
  65. package/cjs/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
  66. package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +26 -0
  67. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
  68. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +42 -0
  69. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
  70. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +188 -0
  71. package/cjs/components/shared/question-radio/QuestionRadio.d.ts +8 -0
  72. package/cjs/components/shared/question-radio/QuestionRadio.js +26 -0
  73. package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
  74. package/cjs/components/shared/question-radio/QuestionRadioContext.js +42 -0
  75. package/cjs/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
  76. package/cjs/components/shared/question-radio/QuestionRadioOption.js +156 -0
  77. package/cjs/helpers/index.d.ts +50 -0
  78. package/cjs/helpers/index.js +86 -0
  79. package/cjs/index.d.ts +3 -0
  80. package/cjs/index.js +27 -0
  81. package/es/components/eb-sortable/EbDraggable.d.ts +18 -0
  82. package/es/components/eb-sortable/EbDraggable.js +105 -0
  83. package/es/components/eb-sortable/EbDroppable.d.ts +13 -0
  84. package/es/components/eb-sortable/EbDroppable.js +53 -0
  85. package/es/components/eb-sortable/EbSortable.d.ts +17 -0
  86. package/es/components/material-quiz/MaterialQuiz.d.ts +4 -0
  87. package/es/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
  88. package/es/components/material-quiz/MaterialQuiz.i18n.js +50 -0
  89. package/es/components/material-quiz/MaterialQuiz.js +106 -0
  90. package/es/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
  91. package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +48 -0
  92. package/es/components/material-quiz/MaterialQuizError.d.ts +3 -0
  93. package/es/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
  94. package/es/components/material-quiz/MaterialQuizInfo.js +68 -0
  95. package/es/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
  96. package/es/components/material-quiz/MaterialQuizSelectMultiple.js +197 -0
  97. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
  98. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +461 -0
  99. package/es/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
  100. package/es/components/material-quiz/MaterialQuizSelectOne.js +185 -0
  101. package/es/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
  102. package/es/components/material-quiz/MaterialQuizShimmer.js +54 -0
  103. package/es/components/material-quiz/MaterialQuizText.d.ts +3 -0
  104. package/es/components/material-quiz/MaterialQuizText.js +174 -0
  105. package/es/components/material-quiz/QuizResultBadge.d.ts +7 -0
  106. package/es/components/material-quiz/QuizResultBadge.js +42 -0
  107. package/es/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
  108. package/es/components/material-quiz/QuizSubmitStatusText.js +32 -0
  109. package/es/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
  110. package/es/components/material-quiz/context/MaterialQuizContext.js +124 -0
  111. package/es/components/material-quiz/index.d.ts +3 -0
  112. package/es/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
  113. package/es/components/material-quiz-edit/MaterialQuizEdit.js +86 -0
  114. package/es/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
  115. package/es/components/material-quiz-edit/MaterialQuizEditContent.js +456 -0
  116. package/es/components/material-quiz-edit/context.d.ts +6 -0
  117. package/es/components/material-quiz-edit/context.js +6 -0
  118. package/es/components/material-quiz-edit/index.d.ts +2 -0
  119. package/es/components/material-quiz-edit/locales.d.ts +34 -0
  120. package/es/components/material-quiz-edit/locales.js +68 -0
  121. package/es/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
  122. package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +197 -0
  123. package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
  124. package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +198 -0
  125. package/es/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
  126. package/es/components/material-quiz-edit/options/OptionSelectOne.js +200 -0
  127. package/es/components/material-quiz-edit/options/OptionText.d.ts +3 -0
  128. package/es/components/material-quiz-edit/options/OptionText.js +93 -0
  129. package/es/components/material-quiz-edit/utils/editValue.d.ts +15 -0
  130. package/es/components/material-quiz-edit/utils/editValue.js +32 -0
  131. package/es/components/material-quiz-edit/utils/randomId.d.ts +4 -0
  132. package/es/components/material-quiz-edit/utils/randomId.js +8 -0
  133. package/es/components/shared/QuestionBox.d.ts +16 -0
  134. package/es/components/shared/QuestionBox.js +101 -0
  135. package/es/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
  136. package/es/components/shared/QuizDraggbleDroppedOption.js +25 -0
  137. package/es/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
  138. package/es/components/shared/QuizDraggbleDummyOption.js +29 -0
  139. package/es/components/shared/QuizDraggbleOption.d.ts +14 -0
  140. package/es/components/shared/QuizDraggbleOption.js +184 -0
  141. package/es/components/shared/StyledMarkdown.d.ts +3 -0
  142. package/es/components/shared/StyledMarkdown.js +8 -0
  143. package/es/components/shared/index.d.ts +7 -0
  144. package/es/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
  145. package/es/components/shared/question-checkbox/QuestionCheckbox.js +19 -0
  146. package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
  147. package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +33 -0
  148. package/es/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
  149. package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +181 -0
  150. package/es/components/shared/question-radio/QuestionRadio.d.ts +8 -0
  151. package/es/components/shared/question-radio/QuestionRadio.js +19 -0
  152. package/es/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
  153. package/es/components/shared/question-radio/QuestionRadioContext.js +33 -0
  154. package/es/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
  155. package/es/components/shared/question-radio/QuestionRadioOption.js +149 -0
  156. package/es/helpers/index.d.ts +50 -0
  157. package/es/helpers/index.js +78 -0
  158. package/es/index.d.ts +3 -0
  159. package/es/index.js +10 -0
  160. package/package.json +75 -0
@@ -0,0 +1,68 @@
1
+ const en = {
2
+ 'common.option': '옵션 {number}',
3
+ 'common.errorMessage.range': '{min} ~ {max}자 이내로 입력해주세요.',
4
+ 'content.title': '질문',
5
+ 'content.title.errorMessage.required': 'Please fill the question.',
6
+ 'content.title.placeholder': '문제의 질문을 입력해주세요.',
7
+ 'content.description.title': '문제 설명',
8
+ 'content.description.placeholder': '자세한 문제 설명이나 코드 혹은 이미지 등을 입력해주세요.',
9
+ 'content.option.title': '답안',
10
+ 'content.option.tooltip.disabled': '퀴즈가 공개된 상태이거나 문제를 제출한 학생이 존재하면\n수정이 불가능합니다.',
11
+ 'content.option.select.items.selectOne': '객관식 (단일 선택)',
12
+ 'content.option.select.items.selectMultiple': '객관식 (다중 선택)',
13
+ 'content.option.select.items.selectMultipleOrder': '드래그 앤 드롭',
14
+ 'content.option.select.items.text': '주관식',
15
+ 'content.option.statusText.dragNDrop': '보기를 입력한 후 정답 순서대로 클릭하세요.\n구성된 문제는 좌측 학습자료 탭에서 확인하실 수 있습니다.',
16
+ 'content.option.errorMessage.required': '답안을 선택해주세요.',
17
+ 'content.answerHint.title': '입력란 힌트 텍스트 지정',
18
+ 'content.answerHint.description': '답안을 입력할 입력란의 힌트 텍스트를 지정할 수 있습니다.',
19
+ 'content.answerHint.placeholder': '입력란 힌트 텍스트 입력',
20
+ 'content.explanationInfo.title': '해설 작성',
21
+ 'content.explanationInfo.description': '문제를 푼 후 해당 설명이 노출됩니다.',
22
+ 'content.explanationInfo.checkbox.label': '사용',
23
+ 'content.explanationInfo.textarea.placeholder': '해설을 입력해주세요.',
24
+ 'content.explanationInfo.textarea.errorMessage.required': '문제의 해설을 작성하세요.',
25
+ 'option.common.select.errorMessage.required': '선택지를 입력해주세요.',
26
+ 'option.common.select.placeholder': '선택지 입력',
27
+ 'option.common.select.tooltip.minOptionInfoItem': '선택지는 2개 이상 입력해야 합니다.',
28
+ 'option.common.select.tooltip.maxOptionInfoItem': '선택지는 20개 초과하여 입력할 수 없습니다.',
29
+ 'option.common.select.addButton': '보기 추가',
30
+ 'option.text.answerInfo.errorMessage.required': '정답을 입력해주세요.',
31
+ 'option.text.answerInfo.hintText': '정규표현식으로 채점됩니다. 정답에 메타 문자(^[]$()|*+?{}\\.)가 포함될 경우 해당 문자 앞에 \\를 붙여주세요.\n예) ^^ 가 정답인 경우 → \\^\\^',
32
+ 'option.text.isAutoGrade.checkbox.label': '답안을 지정하지 않고 수동으로 채점'
33
+ };
34
+ const ko = {
35
+ 'common.option': '옵션 {number}',
36
+ 'common.errorMessage.range': '{min} ~ {max}자 이내로 입력해주세요.',
37
+ 'content.title': '질문',
38
+ 'content.title.errorMessage.required': '질문을 입력해주세요.',
39
+ 'content.title.placeholder': '문제의 질문을 입력해주세요.',
40
+ 'content.description.title': '문제 설명',
41
+ 'content.description.placeholder': '자세한 문제 설명이나 코드 혹은 이미지 등을 입력해주세요.',
42
+ 'content.option.title': '답안',
43
+ 'content.option.tooltip.disabled': '퀴즈가 공개된 상태이거나 문제를 제출한 학생이 존재하면\n수정이 불가능합니다.',
44
+ 'content.option.select.items.selectOne': '객관식 (단일 선택)',
45
+ 'content.option.select.items.selectMultiple': '객관식 (다중 선택)',
46
+ 'content.option.select.items.selectMultipleOrder': '드래그 앤 드롭',
47
+ 'content.option.select.items.text': '주관식',
48
+ 'content.option.statusText.dragNDrop': '보기를 입력한 후 정답 순서대로 클릭하세요.\n구성된 문제는 좌측 학습자료 탭에서 확인하실 수 있습니다.',
49
+ 'content.option.errorMessage.required': '답안을 선택해주세요.',
50
+ 'content.answerHint.title': '입력란 힌트 텍스트 지정',
51
+ 'content.answerHint.description': '답안을 입력할 입력란의 힌트 텍스트를 지정할 수 있습니다.',
52
+ 'content.answerHint.placeholder': '입력란 힌트 텍스트 입력',
53
+ 'content.explanationInfo.title': '해설 작성',
54
+ 'content.explanationInfo.description': '문제를 푼 후 해당 설명이 노출됩니다.',
55
+ 'content.explanationInfo.checkbox.label': '사용',
56
+ 'content.explanationInfo.textarea.placeholder': '해설을 입력해주세요.',
57
+ 'content.explanationInfo.textarea.errorMessage.required': '문제의 해설을 작성하세요.',
58
+ 'option.common.select.errorMessage.required': '선택지를 입력해주세요.',
59
+ 'option.common.select.placeholder': '선택지 입력',
60
+ 'option.common.select.tooltip.minOptionInfoItem': '선택지는 2개 이상 입력해야 합니다.',
61
+ 'option.common.select.tooltip.maxOptionInfoItem': '선택지는 20개 초과하여 입력할 수 없습니다.',
62
+ 'option.common.select.addButton': '보기 추가',
63
+ 'option.text.answerInfo.errorMessage.required': '정답을 입력해주세요.',
64
+ 'option.text.answerInfo.hintText': '정규표현식으로 채점됩니다. 정답에 메타 문자(^[]$()|*+?{}\\.)가 포함될 경우 해당 문자 앞에 \\를 붙여주세요.\n예) ^^ 가 정답인 경우 → \\^\\^',
65
+ 'option.text.isAutoGrade.checkbox.label': '답안을 지정하지 않고 수동으로 채점'
66
+ };
67
+
68
+ export { en, ko };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const OptionSelectMultiple: React.FC;
3
+ export default OptionSelectMultiple;
@@ -0,0 +1,197 @@
1
+ import React from 'react';
2
+ import { useFormContext, useFieldArray, Controller } from 'react-hook-form';
3
+ import { useIntl, FormattedMessage } from 'react-intl';
4
+ import { Transition } from 'react-transition-group';
5
+ import { StatusText, Vspace, Input, Checkbox, Tooltip, IconButton, Button, Icon } from '@elice/blocks';
6
+ import { eilMathsignMultiplyBasic, eilMathsignAddCircle } from '@elice/icons';
7
+ import styled from 'styled-components';
8
+ import { useMaterialQuizEditContext } from '../context.js';
9
+ import { createRandomId } from '../utils/randomId.js';
10
+
11
+ const MIN_OPTION_INFO_COUNT = 2;
12
+ const MAX_OPTION_INFO_COUNT = 20;
13
+ const StyledWrap = styled.div.withConfig({
14
+ componentId: "sc-1nbx9b8-0"
15
+ })([""]);
16
+ const StyledInputGroup = styled.div.withConfig({
17
+ componentId: "sc-1nbx9b8-1"
18
+ })(["width:100%;.eb-input{margin-bottom:0.5rem;&:last-of-type{margin-bottom:0;}}"]);
19
+
20
+ const OptionSelectMultiple = () => {
21
+ const intl = useIntl();
22
+ const {
23
+ disabled
24
+ } = useMaterialQuizEditContext();
25
+ const {
26
+ control,
27
+ getValues,
28
+ setValue,
29
+ watch
30
+ } = useFormContext();
31
+ const {
32
+ fields: optionInfoFields,
33
+ append: appendOptionInfoFieldItem,
34
+ remove: removeOptionInfoFieldItem
35
+ } = useFieldArray({
36
+ name: 'optionInfo',
37
+ keyName: 'id',
38
+ shouldUnregister: true
39
+ });
40
+ const watchedAnswerInfo = watch('answerInfo');
41
+ /**
42
+ * Update answer info.
43
+ */
44
+
45
+ const updateAnswerInfo = option => {
46
+ const prevAnswerInfo = getValues('answerInfo');
47
+
48
+ if (!Array.isArray(prevAnswerInfo)) {
49
+ return;
50
+ }
51
+
52
+ setValue('answerInfo', !option.checked ? prevAnswerInfo.filter(answerIndex => answerIndex !== option.index).map(answerIndex => option.removed ? // if answer removed, re-calculate answer index
53
+ answerIndex < option.index ? answerIndex : answerIndex - 1 : // or maintain current answer index
54
+ answerIndex) : [...prevAnswerInfo, option.index], {
55
+ shouldDirty: true,
56
+ shouldValidate: true
57
+ });
58
+ };
59
+ /**
60
+ * Append option info.
61
+ */
62
+
63
+
64
+ const appendOptionInfo = () => {
65
+ appendOptionInfoFieldItem({
66
+ id: createRandomId(),
67
+ value: ''
68
+ });
69
+ };
70
+ /**
71
+ * Remove item from option info at index.
72
+ */
73
+
74
+
75
+ const removeOptionInfo = index => {
76
+ updateAnswerInfo({
77
+ index,
78
+ checked: false,
79
+ removed: true
80
+ });
81
+ removeOptionInfoFieldItem(index);
82
+ }; //
83
+ //
84
+ //
85
+
86
+
87
+ if (!Array.isArray(watchedAnswerInfo)) {
88
+ return null;
89
+ }
90
+
91
+ return React.createElement(StyledWrap, null, React.createElement(Controller, {
92
+ name: "answerInfo",
93
+ control: control,
94
+ rules: {
95
+ validate: v => {
96
+ if (Array.isArray(v) && v.length < 1) {
97
+ return intl.formatMessage({
98
+ id: 'content.option.errorMessage.required'
99
+ });
100
+ }
101
+
102
+ return true;
103
+ }
104
+ },
105
+ render: ({
106
+ fieldState
107
+ }) => {
108
+ var _a;
109
+
110
+ return React.createElement(Transition, {
111
+ in: fieldState.invalid,
112
+ timeout: 0,
113
+ mountOnEnter: true,
114
+ unmountOnExit: true
115
+ }, React.createElement(React.Fragment, null, React.createElement(StatusText, {
116
+ children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
117
+ role: "danger"
118
+ }), React.createElement(Vspace, {
119
+ height: 0.5
120
+ })));
121
+ }
122
+ }), React.createElement(StyledInputGroup, null, optionInfoFields.map(({
123
+ id
124
+ }, index) => React.createElement(Controller, {
125
+ key: id,
126
+ control: control,
127
+ name: `optionInfo.${index}.value`,
128
+ rules: {
129
+ required: {
130
+ value: true,
131
+ message: intl.formatMessage({
132
+ id: 'option.common.select.errorMessage.required'
133
+ })
134
+ }
135
+ },
136
+ render: ({
137
+ field,
138
+ fieldState
139
+ }) => {
140
+ var _a;
141
+
142
+ return React.createElement(Input, Object.assign({
143
+ size: "small",
144
+ width: "full",
145
+ placeholder: intl.formatMessage({
146
+ id: 'option.common.select.placeholder'
147
+ }),
148
+ prefix: React.createElement(Checkbox, {
149
+ checked: watchedAnswerInfo.includes(index),
150
+ disabled: disabled,
151
+ onChange: checked => updateAnswerInfo({
152
+ index,
153
+ checked
154
+ })
155
+ }),
156
+ suffix: React.createElement(Tooltip, {
157
+ title: optionInfoFields.length <= MIN_OPTION_INFO_COUNT ? intl.formatMessage({
158
+ id: 'option.common.select.tooltip.minOptionInfoItem'
159
+ }) : undefined,
160
+ placement: "top-start"
161
+ }, React.createElement("span", null, React.createElement(IconButton, {
162
+ icon: eilMathsignMultiplyBasic,
163
+ size: "tiny",
164
+ role: "grey9",
165
+ border: false,
166
+ transparent: true,
167
+ disabled: optionInfoFields.length <= MIN_OPTION_INFO_COUNT || disabled,
168
+ onClick: () => removeOptionInfo(index)
169
+ }))),
170
+ readOnly: disabled,
171
+ invalid: fieldState.invalid,
172
+ invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
173
+ }, field));
174
+ }
175
+ }))), React.createElement(Vspace, {
176
+ height: 0.5
177
+ }), React.createElement(Tooltip, {
178
+ title: optionInfoFields.length >= MAX_OPTION_INFO_COUNT ? intl.formatMessage({
179
+ id: 'option.common.select.tooltip.maxOptionInfoItem'
180
+ }) : undefined,
181
+ placement: "bottom"
182
+ }, React.createElement("span", null, React.createElement(Button, {
183
+ block: true,
184
+ size: "micro",
185
+ borderDashed: true,
186
+ transparent: true,
187
+ icon: React.createElement(Icon, {
188
+ icon: eilMathsignAddCircle
189
+ }),
190
+ disabled: optionInfoFields.length >= MAX_OPTION_INFO_COUNT || disabled,
191
+ onClick: appendOptionInfo
192
+ }, React.createElement(FormattedMessage, {
193
+ id: "option.common.select.addButton"
194
+ })))));
195
+ };
196
+
197
+ export { OptionSelectMultiple as default };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const OptionSelectMultipleOrder: React.FC;
3
+ export default OptionSelectMultipleOrder;
@@ -0,0 +1,198 @@
1
+ import React from 'react';
2
+ import { useFormContext, useFieldArray, Controller } from 'react-hook-form';
3
+ import { useIntl, FormattedMessage } from 'react-intl';
4
+ import { Transition } from 'react-transition-group';
5
+ import { StatusText, Vspace, Input, Checkbox, Tooltip, IconButton, Button, Icon } from '@elice/blocks';
6
+ import { eilMathsignMultiplyBasic, eilMathsignAddCircle } from '@elice/icons';
7
+ import styled from 'styled-components';
8
+ import { useMaterialQuizEditContext } from '../context.js';
9
+ import { createRandomId } from '../utils/randomId.js';
10
+
11
+ const MIN_OPTION_INFO_COUNT = 2;
12
+ const MAX_OPTION_INFO_COUNT = 20;
13
+ const StyledWrap = styled.div.withConfig({
14
+ componentId: "sc-1xufc1p-0"
15
+ })([""]);
16
+ const StyledInputGroup = styled.div.withConfig({
17
+ componentId: "sc-1xufc1p-1"
18
+ })(["width:100%;.eb-input{margin-bottom:0.5rem;&:last-of-type{margin-bottom:0;}}"]);
19
+
20
+ const OptionSelectMultipleOrder = () => {
21
+ const intl = useIntl();
22
+ const {
23
+ disabled
24
+ } = useMaterialQuizEditContext();
25
+ const {
26
+ control,
27
+ getValues,
28
+ setValue,
29
+ watch
30
+ } = useFormContext();
31
+ const {
32
+ fields: optionInfoFields,
33
+ append: appendOptionInfoFieldItem,
34
+ remove: removeOptionInfoFieldItem
35
+ } = useFieldArray({
36
+ name: 'optionInfo',
37
+ keyName: 'id',
38
+ shouldUnregister: true
39
+ });
40
+ const watchedAnswerInfo = watch('answerInfo');
41
+ /**
42
+ * Update answer info.
43
+ */
44
+
45
+ const updateAnswerInfo = option => {
46
+ const prevAnswerInfo = getValues('answerInfo');
47
+
48
+ if (!Array.isArray(prevAnswerInfo)) {
49
+ return;
50
+ }
51
+
52
+ setValue('answerInfo', !option.checked ? prevAnswerInfo.filter(answerIndex => answerIndex !== option.index).map(answerIndex => option.removed ? // if answer removed, re-calculate answer index
53
+ answerIndex < option.index ? answerIndex : answerIndex - 1 : // or maintain current answer index
54
+ answerIndex) : [...prevAnswerInfo, option.index], {
55
+ shouldDirty: true,
56
+ shouldValidate: true
57
+ });
58
+ };
59
+ /**
60
+ * Append option info.
61
+ */
62
+
63
+
64
+ const appendOptionInfo = () => {
65
+ appendOptionInfoFieldItem({
66
+ id: createRandomId(),
67
+ value: ''
68
+ });
69
+ };
70
+ /**
71
+ * Remove item from option info at index.
72
+ */
73
+
74
+
75
+ const removeOptionInfo = index => {
76
+ updateAnswerInfo({
77
+ index,
78
+ checked: false,
79
+ removed: true
80
+ });
81
+ removeOptionInfoFieldItem(index);
82
+ }; //
83
+ //
84
+ //
85
+
86
+
87
+ if (!Array.isArray(watchedAnswerInfo)) {
88
+ return null;
89
+ }
90
+
91
+ return React.createElement(StyledWrap, null, React.createElement(Controller, {
92
+ name: "answerInfo",
93
+ control: control,
94
+ rules: {
95
+ validate: v => {
96
+ if (Array.isArray(v) && v.length < 1) {
97
+ return intl.formatMessage({
98
+ id: 'content.option.errorMessage.required'
99
+ });
100
+ }
101
+
102
+ return true;
103
+ }
104
+ },
105
+ render: ({
106
+ fieldState
107
+ }) => {
108
+ var _a;
109
+
110
+ return React.createElement(Transition, {
111
+ in: fieldState.invalid,
112
+ timeout: 0,
113
+ mountOnEnter: true,
114
+ unmountOnExit: true
115
+ }, React.createElement(React.Fragment, null, React.createElement(StatusText, {
116
+ children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
117
+ role: "danger"
118
+ }), React.createElement(Vspace, {
119
+ height: 0.5
120
+ })));
121
+ }
122
+ }), React.createElement(StyledInputGroup, null, optionInfoFields.map(({
123
+ id
124
+ }, index) => React.createElement(Controller, {
125
+ key: id,
126
+ control: control,
127
+ name: `optionInfo.${index}.value`,
128
+ rules: {
129
+ required: {
130
+ value: true,
131
+ message: intl.formatMessage({
132
+ id: 'option.common.select.errorMessage.required'
133
+ })
134
+ }
135
+ },
136
+ render: ({
137
+ field,
138
+ fieldState
139
+ }) => {
140
+ var _a;
141
+
142
+ return React.createElement(Input, Object.assign({
143
+ size: "small",
144
+ width: "full",
145
+ placeholder: intl.formatMessage({
146
+ id: 'option.common.select.placeholder'
147
+ }),
148
+ prefix: React.createElement(Checkbox, {
149
+ checked: watchedAnswerInfo.includes(index),
150
+ disabled: disabled,
151
+ altChar: watchedAnswerInfo.indexOf(index) + 1,
152
+ onChange: checked => updateAnswerInfo({
153
+ index,
154
+ checked
155
+ })
156
+ }),
157
+ suffix: React.createElement(Tooltip, {
158
+ title: optionInfoFields.length <= MIN_OPTION_INFO_COUNT ? intl.formatMessage({
159
+ id: 'option.common.select.tooltip.minOptionInfoItem'
160
+ }) : undefined,
161
+ placement: "top-start"
162
+ }, React.createElement("span", null, React.createElement(IconButton, {
163
+ icon: eilMathsignMultiplyBasic,
164
+ size: "tiny",
165
+ role: "grey9",
166
+ border: false,
167
+ transparent: true,
168
+ disabled: optionInfoFields.length <= MIN_OPTION_INFO_COUNT || disabled,
169
+ onClick: () => removeOptionInfo(index)
170
+ }))),
171
+ readOnly: disabled,
172
+ invalid: fieldState.invalid,
173
+ invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
174
+ }, field));
175
+ }
176
+ }))), React.createElement(Vspace, {
177
+ height: 0.5
178
+ }), React.createElement(Tooltip, {
179
+ title: optionInfoFields.length >= MAX_OPTION_INFO_COUNT ? intl.formatMessage({
180
+ id: 'option.common.select.tooltip.maxOptionInfoItem'
181
+ }) : undefined,
182
+ placement: "bottom"
183
+ }, React.createElement("span", null, React.createElement(Button, {
184
+ block: true,
185
+ size: "micro",
186
+ borderDashed: true,
187
+ transparent: true,
188
+ icon: React.createElement(Icon, {
189
+ icon: eilMathsignAddCircle
190
+ }),
191
+ disabled: optionInfoFields.length >= MAX_OPTION_INFO_COUNT || disabled,
192
+ onClick: appendOptionInfo
193
+ }, React.createElement(FormattedMessage, {
194
+ id: "option.common.select.addButton"
195
+ })))));
196
+ };
197
+
198
+ export { OptionSelectMultipleOrder as default };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const OptionSelectOne: React.FC;
3
+ export default OptionSelectOne;
@@ -0,0 +1,200 @@
1
+ import React from 'react';
2
+ import { useFormContext, useFieldArray, Controller } from 'react-hook-form';
3
+ import { useIntl, FormattedMessage } from 'react-intl';
4
+ import { Transition } from 'react-transition-group';
5
+ import { RadioOption, StatusText, Vspace, Input, Radio, Tooltip, IconButton, Button, Icon } from '@elice/blocks';
6
+ import { eilMathsignMultiplyBasic, eilMathsignAddCircle } from '@elice/icons';
7
+ import styled from 'styled-components';
8
+ import { useMaterialQuizEditContext } from '../context.js';
9
+ import { createRandomId } from '../utils/randomId.js';
10
+
11
+ const MIN_OPTION_INFO_COUNT = 2;
12
+ const MAX_OPTION_INFO_COUNT = 20;
13
+ const StyledWrap = styled.div.withConfig({
14
+ componentId: "sc-vizer2-0"
15
+ })([""]);
16
+ const StyledInputGroup = styled.div.withConfig({
17
+ componentId: "sc-vizer2-1"
18
+ })(["width:100%;.eb-input{margin-bottom:0.5rem;&:last-of-type{margin-bottom:0;}}"]);
19
+ const StyledInputPrefixRadioOption = styled(RadioOption).withConfig({
20
+ componentId: "sc-vizer2-2"
21
+ })([".eb-radio-option__label{display:none;}"]);
22
+
23
+ const OptionSelectOne = () => {
24
+ const intl = useIntl();
25
+ const {
26
+ disabled
27
+ } = useMaterialQuizEditContext();
28
+ const {
29
+ control,
30
+ getValues,
31
+ setValue,
32
+ watch
33
+ } = useFormContext();
34
+ const {
35
+ fields: optionInfoFields,
36
+ append: appendOptionInfoFieldItem,
37
+ remove: removeOptionInfoFieldItem
38
+ } = useFieldArray({
39
+ name: 'optionInfo',
40
+ keyName: 'id',
41
+ shouldUnregister: true
42
+ });
43
+ const watchedAnswerInfo = watch('answerInfo');
44
+ /**
45
+ * Update answer info.
46
+ */
47
+
48
+ const updateAnswerInfo = index => {
49
+ const prevAnswerInfo = getValues('answerInfo');
50
+
51
+ if (!Array.isArray(prevAnswerInfo)) {
52
+ return;
53
+ }
54
+
55
+ setValue('answerInfo', [index], {
56
+ shouldDirty: true,
57
+ shouldValidate: true
58
+ });
59
+ };
60
+ /**
61
+ * Append option info.
62
+ */
63
+
64
+
65
+ const appendOptionInfo = () => {
66
+ appendOptionInfoFieldItem({
67
+ id: createRandomId(),
68
+ value: ''
69
+ });
70
+ };
71
+ /**
72
+ * Remove item from option info at index.
73
+ */
74
+
75
+
76
+ const removeOptionInfo = index => {
77
+ // set answer info to 0 index,
78
+ // if this option is selected as answer.
79
+ const curAnswerInfo = getValues('answerInfo');
80
+
81
+ if (Array.isArray(curAnswerInfo) && curAnswerInfo.includes(index)) {
82
+ updateAnswerInfo(0);
83
+ }
84
+
85
+ removeOptionInfoFieldItem(index);
86
+ }; //
87
+ //
88
+ //
89
+
90
+
91
+ if (!Array.isArray(watchedAnswerInfo)) {
92
+ return null;
93
+ }
94
+
95
+ return React.createElement(StyledWrap, null, React.createElement(Controller, {
96
+ name: "answerInfo",
97
+ control: control,
98
+ rules: {
99
+ validate: v => {
100
+ if (Array.isArray(v) && v.length < 1) {
101
+ return intl.formatMessage({
102
+ id: 'content.option.errorMessage.required'
103
+ });
104
+ }
105
+
106
+ return true;
107
+ }
108
+ },
109
+ render: ({
110
+ fieldState
111
+ }) => {
112
+ var _a;
113
+
114
+ return React.createElement(Transition, {
115
+ in: fieldState.invalid,
116
+ timeout: 0,
117
+ mountOnEnter: true,
118
+ unmountOnExit: true
119
+ }, React.createElement(React.Fragment, null, React.createElement(StatusText, {
120
+ children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
121
+ role: "danger"
122
+ }), React.createElement(Vspace, {
123
+ height: 0.5
124
+ })));
125
+ }
126
+ }), React.createElement(StyledInputGroup, null, optionInfoFields.map(({
127
+ id
128
+ }, index) => React.createElement(Controller, {
129
+ key: id,
130
+ control: control,
131
+ name: `optionInfo.${index}.value`,
132
+ rules: {
133
+ required: {
134
+ value: true,
135
+ message: intl.formatMessage({
136
+ id: 'option.common.select.errorMessage.required'
137
+ })
138
+ }
139
+ },
140
+ render: ({
141
+ field,
142
+ fieldState
143
+ }) => {
144
+ var _a;
145
+
146
+ return React.createElement(Input, Object.assign({
147
+ size: "small",
148
+ width: "full",
149
+ placeholder: intl.formatMessage({
150
+ id: 'option.common.select.placeholder'
151
+ }),
152
+ prefix: React.createElement(Radio, {
153
+ value: watchedAnswerInfo[0],
154
+ disabled: disabled,
155
+ onChange: updateAnswerInfo
156
+ }, React.createElement(StyledInputPrefixRadioOption, {
157
+ value: index
158
+ }), React.createElement(React.Fragment, null)),
159
+ suffix: React.createElement(Tooltip, {
160
+ title: optionInfoFields.length <= MIN_OPTION_INFO_COUNT ? intl.formatMessage({
161
+ id: 'option.common.select.tooltip.minOptionInfoItem'
162
+ }) : undefined,
163
+ placement: "top-start"
164
+ }, React.createElement("span", null, React.createElement(IconButton, {
165
+ icon: eilMathsignMultiplyBasic,
166
+ size: "tiny",
167
+ role: "grey9",
168
+ border: false,
169
+ transparent: true,
170
+ disabled: optionInfoFields.length <= MIN_OPTION_INFO_COUNT || disabled,
171
+ onClick: () => removeOptionInfo(index)
172
+ }))),
173
+ readOnly: disabled,
174
+ invalid: fieldState.invalid,
175
+ invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
176
+ }, field));
177
+ }
178
+ }))), React.createElement(Vspace, {
179
+ height: 0.5
180
+ }), React.createElement(Tooltip, {
181
+ title: optionInfoFields.length >= MAX_OPTION_INFO_COUNT ? intl.formatMessage({
182
+ id: 'option.common.select.tooltip.maxOptionInfoItem'
183
+ }) : undefined,
184
+ placement: "bottom"
185
+ }, React.createElement("span", null, React.createElement(Button, {
186
+ block: true,
187
+ size: "micro",
188
+ borderDashed: true,
189
+ transparent: true,
190
+ icon: React.createElement(Icon, {
191
+ icon: eilMathsignAddCircle
192
+ }),
193
+ disabled: optionInfoFields.length >= MAX_OPTION_INFO_COUNT || disabled,
194
+ onClick: appendOptionInfo
195
+ }, React.createElement(FormattedMessage, {
196
+ id: "option.common.select.addButton"
197
+ })))));
198
+ };
199
+
200
+ export { OptionSelectOne as default };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const OptionText: React.FC;
3
+ export default OptionText;