@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,134 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var apiClient = require('@elice/api-client');
7
+ var materialSharedUtils = require('@elice/material-shared-utils');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
+
13
+ const StateContext = React__default["default"].createContext(undefined);
14
+ const DispatchContext = React__default["default"].createContext(undefined);
15
+ StateContext.displayName = 'MaterialQuizStateContext';
16
+ DispatchContext.displayName = 'MaterialQuizDispatchContext';
17
+
18
+ function MaterialQuizProvider({
19
+ materialQuizId,
20
+ userId,
21
+ onSubmit = () => void 0,
22
+ onNext,
23
+ children
24
+ }) {
25
+ const [course, setCourse] = React__default["default"].useState();
26
+ const [lecture, setLecture] = React__default["default"].useState();
27
+ const [materialQuiz, setMaterialQuiz] = React__default["default"].useState();
28
+ const [initStatus, setInitStatus] = React__default["default"].useState('idle');
29
+ const [vertical, setVertical] = React__default["default"].useState(false);
30
+ const canInit = materialSharedUtils.useMaterialConfigApiClientUpdate(apiClient.config.init);
31
+ const init = React__default["default"].useCallback(async () => {
32
+ const controller = new AbortController();
33
+ const {
34
+ signal
35
+ } = controller;
36
+
37
+ try {
38
+ setInitStatus('pending'); // fetch materialQuiz
39
+
40
+ const {
41
+ materialQuiz
42
+ } = await apiClient.getOrgMaterialQuizGet({
43
+ materialQuizId
44
+ }, {
45
+ signal
46
+ }); // fetch course
47
+
48
+ const {
49
+ course
50
+ } = await apiClient.getOrgCourseGet({
51
+ courseId: materialQuiz.courseId
52
+ }, {
53
+ signal
54
+ }); // fetch lecture
55
+
56
+ const {
57
+ lecture
58
+ } = await apiClient.getOrgLectureGet({
59
+ lectureId: materialQuiz.lectureId
60
+ }, {
61
+ signal
62
+ });
63
+ setMaterialQuiz(materialQuiz);
64
+ setCourse(course);
65
+ setLecture(lecture);
66
+ setInitStatus('resolved');
67
+ } catch (error) {
68
+ console.error(error);
69
+ setInitStatus('rejected');
70
+ }
71
+
72
+ return () => controller.abort();
73
+ }, [materialQuizId]);
74
+ React__default["default"].useEffect(() => {
75
+ if (canInit) {
76
+ void init();
77
+ }
78
+ }, [canInit, init]); //
79
+ //
80
+ // materialQuiz refresher
81
+
82
+ const refreshOrgMaterialQuiz = React__default["default"].useCallback(signal => {
83
+ return apiClient.getOrgMaterialQuizGet({
84
+ materialQuizId
85
+ }, {
86
+ signal
87
+ }).then(response => {
88
+ setMaterialQuiz(response.materialQuiz);
89
+ }).catch(error => {
90
+ console.error(error);
91
+ });
92
+ }, [materialQuizId]);
93
+ return React__default["default"].createElement(StateContext.Provider, {
94
+ value: {
95
+ course,
96
+ lecture,
97
+ materialQuiz,
98
+ userId,
99
+ vertical,
100
+ initStatus
101
+ }
102
+ }, React__default["default"].createElement(DispatchContext.Provider, {
103
+ value: {
104
+ onSubmit,
105
+ onNext,
106
+ refreshOrgMaterialQuiz,
107
+ setVertical
108
+ }
109
+ }, children));
110
+ }
111
+
112
+ function useMaterialQuizState() {
113
+ const context = React__default["default"].useContext(StateContext);
114
+
115
+ if (context === undefined) {
116
+ throw new Error('useMaterialQuizState must be used within a MaterialQuizProvider');
117
+ }
118
+
119
+ return context;
120
+ }
121
+
122
+ function useMaterialQuizDispatch() {
123
+ const context = React__default["default"].useContext(DispatchContext);
124
+
125
+ if (context === undefined) {
126
+ throw new Error('useMaterialQuizDispatch must be used within a MaterialQuizProvider');
127
+ }
128
+
129
+ return context;
130
+ }
131
+
132
+ exports.MaterialQuizProvider = MaterialQuizProvider;
133
+ exports.useMaterialQuizDispatch = useMaterialQuizDispatch;
134
+ exports.useMaterialQuizState = useMaterialQuizState;
@@ -0,0 +1,3 @@
1
+ export { default as MaterialQuiz } from './MaterialQuiz';
2
+ export { default as MaterialQuizInfo } from './MaterialQuizInfo';
3
+ export type { MaterialQuizProps } from './context/MaterialQuizContext';
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import type { MarkdownEditorFileUploadReqFn } from '@elice/markdown';
3
+ import type { GetOrgMaterialQuizGetResponses } from '@elice/types';
4
+ import type { FormState } from 'react-hook-form';
5
+ export declare type MaterialQuizEditValue = Pick<GetOrgMaterialQuizGetResponses['materialQuiz'], 'id' | 'questionTitle' | 'questionDescription' | 'optionType' | 'optionInfo' | 'answerInfo' | 'answerHint' | 'isAutoGrade' | 'explanationInfo'>;
6
+ export declare type MaterialQuizEditFormState = Pick<FormState<Record<string, any>>, 'isDirty' | 'isValid'>;
7
+ export interface MaterialQuizEditProps {
8
+ /** Value of material quiz edit form. */
9
+ value: MaterialQuizEditValue;
10
+ /**
11
+ * Is editing disabled?
12
+ * When true, cannot change `optionType`, `optionInfo` and `answerInfo`.
13
+ */
14
+ disabled?: boolean;
15
+ /** Locale of edit form. */
16
+ locale: string;
17
+ /** Handle form change event. */
18
+ onChange: (value: MaterialQuizEditValue) => void;
19
+ /** Handle form state changes. (`FormState` from react-hook-form) */
20
+ onFormStateChange?: (state: MaterialQuizEditFormState) => void;
21
+ /** Handle file upload. */
22
+ onFileUploadRequest: MarkdownEditorFileUploadReqFn;
23
+ }
24
+ declare const MaterialQuizEdit: React.ForwardRefExoticComponent<MaterialQuizEditProps & React.RefAttributes<HTMLFormElement>>;
25
+ export default MaterialQuizEdit;
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var reactHookForm = require('react-hook-form');
5
+ var reactIntl = require('react-intl');
6
+ var reactUse = require('react-use');
7
+ var editValue = require('./utils/editValue.js');
8
+ var context = require('./context.js');
9
+ var locales = require('./locales.js');
10
+ var MaterialQuizEditContent = require('./MaterialQuizEditContent.js');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
15
+
16
+ const MaterialQuizEdit = React.forwardRef(({
17
+ value,
18
+ disabled = false,
19
+ locale = 'en',
20
+ onChange,
21
+ onFormStateChange,
22
+ onFileUploadRequest
23
+ }, ref) => {
24
+ const formElRef = React__default["default"].useRef(null);
25
+ const useFormMethods = reactHookForm.useForm({
26
+ defaultValues: editValue.manipulateValue(value),
27
+ mode: 'onBlur'
28
+ });
29
+ const watchedMaterialQuizEditValue = useFormMethods.watch();
30
+ const {
31
+ isDirty,
32
+ isValid
33
+ } = useFormMethods.formState; //
34
+ // Reset from value, when `value` changes.
35
+ // TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
36
+ //
37
+
38
+ reactUse.useDeepCompareEffect(() => {
39
+ useFormMethods.reset(editValue.manipulateValue(value), {
40
+ keepDirty: true,
41
+ keepErrors: true,
42
+ keepIsValid: true,
43
+ keepTouched: true,
44
+ keepValues: true
45
+ });
46
+ void useFormMethods.trigger();
47
+ }, [value]); //
48
+ // Emit `onChange` handler when form value changed.
49
+ // TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
50
+ //
51
+
52
+ reactUse.useDeepCompareEffect(() => onChange(editValue.restoreValue(watchedMaterialQuizEditValue)), [watchedMaterialQuizEditValue]); //
53
+ // Emit `onFormStateChange` handler when form state change.
54
+ //
55
+
56
+ React__default["default"].useEffect(() => {
57
+ if (typeof onFormStateChange === 'function') {
58
+ onFormStateChange({
59
+ isDirty,
60
+ isValid
61
+ });
62
+ }
63
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ [isDirty, isValid]); //
65
+ // Set ref.
66
+ //
67
+
68
+ React__default["default"].useImperativeHandle(ref, () => Object.assign(Object.assign({}, formElRef.current), {
69
+ reset: () => {
70
+ useFormMethods.reset(editValue.manipulateValue(value));
71
+ void useFormMethods.trigger();
72
+ }
73
+ }), [useFormMethods, value]); //
74
+ //
75
+ //
76
+
77
+ return React__default["default"].createElement("form", {
78
+ ref: formElRef
79
+ }, React__default["default"].createElement(context["default"].Provider, {
80
+ value: {
81
+ disabled,
82
+ onFileUploadRequest
83
+ }
84
+ }, React__default["default"].createElement(reactIntl.IntlProvider, {
85
+ locale: locale,
86
+ defaultLocale: "en",
87
+ messages: locale in locales ? locales[locale] : locales.en
88
+ }, React__default["default"].createElement(reactHookForm.FormProvider, Object.assign({}, useFormMethods), React__default["default"].createElement(MaterialQuizEditContent, null)))));
89
+ });
90
+
91
+ module.exports = MaterialQuizEdit;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const MaterialQuizEditContent: React.FC;
3
+ export default MaterialQuizEditContent;