@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.
- package/README.md +3 -0
- package/cjs/components/eb-sortable/EbDraggable.d.ts +18 -0
- package/cjs/components/eb-sortable/EbDraggable.js +112 -0
- package/cjs/components/eb-sortable/EbDroppable.d.ts +13 -0
- package/cjs/components/eb-sortable/EbDroppable.js +60 -0
- package/cjs/components/eb-sortable/EbSortable.d.ts +17 -0
- package/cjs/components/material-quiz/MaterialQuiz.d.ts +4 -0
- package/cjs/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
- package/cjs/components/material-quiz/MaterialQuiz.i18n.js +55 -0
- package/cjs/components/material-quiz/MaterialQuiz.js +114 -0
- package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +55 -0
- package/cjs/components/material-quiz/MaterialQuizError.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizInfo.js +74 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +203 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +468 -0
- package/cjs/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizSelectOne.js +191 -0
- package/cjs/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizShimmer.js +61 -0
- package/cjs/components/material-quiz/MaterialQuizText.d.ts +3 -0
- package/cjs/components/material-quiz/MaterialQuizText.js +181 -0
- package/cjs/components/material-quiz/QuizResultBadge.d.ts +7 -0
- package/cjs/components/material-quiz/QuizResultBadge.js +48 -0
- package/cjs/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
- package/cjs/components/material-quiz/QuizSubmitStatusText.js +38 -0
- package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
- package/cjs/components/material-quiz/context/MaterialQuizContext.js +134 -0
- package/cjs/components/material-quiz/index.d.ts +3 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +91 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
- package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +463 -0
- package/cjs/components/material-quiz-edit/context.d.ts +6 -0
- package/cjs/components/material-quiz-edit/context.js +15 -0
- package/cjs/components/material-quiz-edit/index.d.ts +2 -0
- package/cjs/components/material-quiz-edit/locales.d.ts +34 -0
- package/cjs/components/material-quiz-edit/locales.js +73 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +204 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +205 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +207 -0
- package/cjs/components/material-quiz-edit/options/OptionText.d.ts +3 -0
- package/cjs/components/material-quiz-edit/options/OptionText.js +99 -0
- package/cjs/components/material-quiz-edit/utils/editValue.d.ts +15 -0
- package/cjs/components/material-quiz-edit/utils/editValue.js +37 -0
- package/cjs/components/material-quiz-edit/utils/randomId.d.ts +4 -0
- package/cjs/components/material-quiz-edit/utils/randomId.js +12 -0
- package/cjs/components/shared/QuestionBox.d.ts +16 -0
- package/cjs/components/shared/QuestionBox.js +111 -0
- package/cjs/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
- package/cjs/components/shared/QuizDraggbleDroppedOption.js +31 -0
- package/cjs/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
- package/cjs/components/shared/QuizDraggbleDummyOption.js +36 -0
- package/cjs/components/shared/QuizDraggbleOption.d.ts +14 -0
- package/cjs/components/shared/QuizDraggbleOption.js +191 -0
- package/cjs/components/shared/StyledMarkdown.d.ts +3 -0
- package/cjs/components/shared/StyledMarkdown.js +14 -0
- package/cjs/components/shared/index.d.ts +7 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +26 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +42 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
- package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +188 -0
- package/cjs/components/shared/question-radio/QuestionRadio.d.ts +8 -0
- package/cjs/components/shared/question-radio/QuestionRadio.js +26 -0
- package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
- package/cjs/components/shared/question-radio/QuestionRadioContext.js +42 -0
- package/cjs/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
- package/cjs/components/shared/question-radio/QuestionRadioOption.js +156 -0
- package/cjs/helpers/index.d.ts +50 -0
- package/cjs/helpers/index.js +86 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +27 -0
- package/es/components/eb-sortable/EbDraggable.d.ts +18 -0
- package/es/components/eb-sortable/EbDraggable.js +105 -0
- package/es/components/eb-sortable/EbDroppable.d.ts +13 -0
- package/es/components/eb-sortable/EbDroppable.js +53 -0
- package/es/components/eb-sortable/EbSortable.d.ts +17 -0
- package/es/components/material-quiz/MaterialQuiz.d.ts +4 -0
- package/es/components/material-quiz/MaterialQuiz.i18n.d.ts +25 -0
- package/es/components/material-quiz/MaterialQuiz.i18n.js +50 -0
- package/es/components/material-quiz/MaterialQuiz.js +106 -0
- package/es/components/material-quiz/MaterialQuizAnswerExplanation.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +48 -0
- package/es/components/material-quiz/MaterialQuizError.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizInfo.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizInfo.js +68 -0
- package/es/components/material-quiz/MaterialQuizSelectMultiple.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectMultiple.js +197 -0
- package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +461 -0
- package/es/components/material-quiz/MaterialQuizSelectOne.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizSelectOne.js +185 -0
- package/es/components/material-quiz/MaterialQuizShimmer.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizShimmer.js +54 -0
- package/es/components/material-quiz/MaterialQuizText.d.ts +3 -0
- package/es/components/material-quiz/MaterialQuizText.js +174 -0
- package/es/components/material-quiz/QuizResultBadge.d.ts +7 -0
- package/es/components/material-quiz/QuizResultBadge.js +42 -0
- package/es/components/material-quiz/QuizSubmitStatusText.d.ts +7 -0
- package/es/components/material-quiz/QuizSubmitStatusText.js +32 -0
- package/es/components/material-quiz/context/MaterialQuizContext.d.ts +31 -0
- package/es/components/material-quiz/context/MaterialQuizContext.js +124 -0
- package/es/components/material-quiz/index.d.ts +3 -0
- package/es/components/material-quiz-edit/MaterialQuizEdit.d.ts +25 -0
- package/es/components/material-quiz-edit/MaterialQuizEdit.js +86 -0
- package/es/components/material-quiz-edit/MaterialQuizEditContent.d.ts +3 -0
- package/es/components/material-quiz-edit/MaterialQuizEditContent.js +456 -0
- package/es/components/material-quiz-edit/context.d.ts +6 -0
- package/es/components/material-quiz-edit/context.js +6 -0
- package/es/components/material-quiz-edit/index.d.ts +2 -0
- package/es/components/material-quiz-edit/locales.d.ts +34 -0
- package/es/components/material-quiz-edit/locales.js +68 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +197 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +198 -0
- package/es/components/material-quiz-edit/options/OptionSelectOne.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionSelectOne.js +200 -0
- package/es/components/material-quiz-edit/options/OptionText.d.ts +3 -0
- package/es/components/material-quiz-edit/options/OptionText.js +93 -0
- package/es/components/material-quiz-edit/utils/editValue.d.ts +15 -0
- package/es/components/material-quiz-edit/utils/editValue.js +32 -0
- package/es/components/material-quiz-edit/utils/randomId.d.ts +4 -0
- package/es/components/material-quiz-edit/utils/randomId.js +8 -0
- package/es/components/shared/QuestionBox.d.ts +16 -0
- package/es/components/shared/QuestionBox.js +101 -0
- package/es/components/shared/QuizDraggbleDroppedOption.d.ts +12 -0
- package/es/components/shared/QuizDraggbleDroppedOption.js +25 -0
- package/es/components/shared/QuizDraggbleDummyOption.d.ts +8 -0
- package/es/components/shared/QuizDraggbleDummyOption.js +29 -0
- package/es/components/shared/QuizDraggbleOption.d.ts +14 -0
- package/es/components/shared/QuizDraggbleOption.js +184 -0
- package/es/components/shared/StyledMarkdown.d.ts +3 -0
- package/es/components/shared/StyledMarkdown.js +8 -0
- package/es/components/shared/index.d.ts +7 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.d.ts +8 -0
- package/es/components/shared/question-checkbox/QuestionCheckbox.js +19 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +9 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +33 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.d.ts +9 -0
- package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +181 -0
- package/es/components/shared/question-radio/QuestionRadio.d.ts +8 -0
- package/es/components/shared/question-radio/QuestionRadio.js +19 -0
- package/es/components/shared/question-radio/QuestionRadioContext.d.ts +9 -0
- package/es/components/shared/question-radio/QuestionRadioContext.js +33 -0
- package/es/components/shared/question-radio/QuestionRadioOption.d.ts +9 -0
- package/es/components/shared/question-radio/QuestionRadioOption.js +149 -0
- package/es/helpers/index.d.ts +50 -0
- package/es/helpers/index.js +78 -0
- package/es/index.d.ts +3 -0
- package/es/index.js +10 -0
- package/package.json +75 -0
|
@@ -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,86 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { useForm, FormProvider } from 'react-hook-form';
|
|
3
|
+
import { IntlProvider } from 'react-intl';
|
|
4
|
+
import { useDeepCompareEffect } from 'react-use';
|
|
5
|
+
import { manipulateValue, restoreValue } from './utils/editValue.js';
|
|
6
|
+
import MaterialQuizEditContext from './context.js';
|
|
7
|
+
import * as locales from './locales.js';
|
|
8
|
+
import { en } from './locales.js';
|
|
9
|
+
import MaterialQuizEditContent from './MaterialQuizEditContent.js';
|
|
10
|
+
|
|
11
|
+
const MaterialQuizEdit = forwardRef(({
|
|
12
|
+
value,
|
|
13
|
+
disabled = false,
|
|
14
|
+
locale = 'en',
|
|
15
|
+
onChange,
|
|
16
|
+
onFormStateChange,
|
|
17
|
+
onFileUploadRequest
|
|
18
|
+
}, ref) => {
|
|
19
|
+
const formElRef = React.useRef(null);
|
|
20
|
+
const useFormMethods = useForm({
|
|
21
|
+
defaultValues: manipulateValue(value),
|
|
22
|
+
mode: 'onBlur'
|
|
23
|
+
});
|
|
24
|
+
const watchedMaterialQuizEditValue = useFormMethods.watch();
|
|
25
|
+
const {
|
|
26
|
+
isDirty,
|
|
27
|
+
isValid
|
|
28
|
+
} = useFormMethods.formState; //
|
|
29
|
+
// Reset from value, when `value` changes.
|
|
30
|
+
// TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
|
|
31
|
+
//
|
|
32
|
+
|
|
33
|
+
useDeepCompareEffect(() => {
|
|
34
|
+
useFormMethods.reset(manipulateValue(value), {
|
|
35
|
+
keepDirty: true,
|
|
36
|
+
keepErrors: true,
|
|
37
|
+
keepIsValid: true,
|
|
38
|
+
keepTouched: true,
|
|
39
|
+
keepValues: true
|
|
40
|
+
});
|
|
41
|
+
void useFormMethods.trigger();
|
|
42
|
+
}, [value]); //
|
|
43
|
+
// Emit `onChange` handler when form value changed.
|
|
44
|
+
// TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
|
|
45
|
+
//
|
|
46
|
+
|
|
47
|
+
useDeepCompareEffect(() => onChange(restoreValue(watchedMaterialQuizEditValue)), [watchedMaterialQuizEditValue]); //
|
|
48
|
+
// Emit `onFormStateChange` handler when form state change.
|
|
49
|
+
//
|
|
50
|
+
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
if (typeof onFormStateChange === 'function') {
|
|
53
|
+
onFormStateChange({
|
|
54
|
+
isDirty,
|
|
55
|
+
isValid
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
+
[isDirty, isValid]); //
|
|
60
|
+
// Set ref.
|
|
61
|
+
//
|
|
62
|
+
|
|
63
|
+
React.useImperativeHandle(ref, () => Object.assign(Object.assign({}, formElRef.current), {
|
|
64
|
+
reset: () => {
|
|
65
|
+
useFormMethods.reset(manipulateValue(value));
|
|
66
|
+
void useFormMethods.trigger();
|
|
67
|
+
}
|
|
68
|
+
}), [useFormMethods, value]); //
|
|
69
|
+
//
|
|
70
|
+
//
|
|
71
|
+
|
|
72
|
+
return React.createElement("form", {
|
|
73
|
+
ref: formElRef
|
|
74
|
+
}, React.createElement(MaterialQuizEditContext.Provider, {
|
|
75
|
+
value: {
|
|
76
|
+
disabled,
|
|
77
|
+
onFileUploadRequest
|
|
78
|
+
}
|
|
79
|
+
}, React.createElement(IntlProvider, {
|
|
80
|
+
locale: locale,
|
|
81
|
+
defaultLocale: "en",
|
|
82
|
+
messages: locale in locales ? locales[locale] : en
|
|
83
|
+
}, React.createElement(FormProvider, Object.assign({}, useFormMethods), React.createElement(MaterialQuizEditContent, null)))));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export { MaterialQuizEdit as default };
|
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useFormContext, Controller } from 'react-hook-form';
|
|
3
|
+
import { useIntl, FormattedMessage } from 'react-intl';
|
|
4
|
+
import { Transition } from 'react-transition-group';
|
|
5
|
+
import { FormInputVerticalLayout, Label, Input, Tooltip, Select, StatusText, Vspace, Text, Checkbox, Flex } from '@elice/blocks';
|
|
6
|
+
import { MarkdownEditor } from '@elice/markdown';
|
|
7
|
+
import { enums } from '@elice/types';
|
|
8
|
+
import styled from 'styled-components';
|
|
9
|
+
import OptionSelectMultiple from './options/OptionSelectMultiple.js';
|
|
10
|
+
import OptionSelectMultipleOrder from './options/OptionSelectMultipleOrder.js';
|
|
11
|
+
import OptionSelectOne from './options/OptionSelectOne.js';
|
|
12
|
+
import OptionText from './options/OptionText.js';
|
|
13
|
+
import { createRandomId } from './utils/randomId.js';
|
|
14
|
+
import { useMaterialQuizEditContext } from './context.js';
|
|
15
|
+
|
|
16
|
+
const MIN_TEXT_LENGTH = 1;
|
|
17
|
+
const MAX_TEXT_LENGTH = 128;
|
|
18
|
+
const StyledQuizOptionTypeSelectWrap = styled.div.withConfig({
|
|
19
|
+
componentId: "sc-1cf4b99-0"
|
|
20
|
+
})(["display:flex;max-width:12rem;"]);
|
|
21
|
+
|
|
22
|
+
const MaterialQuizEditContent = () => {
|
|
23
|
+
const intl = useIntl();
|
|
24
|
+
const {
|
|
25
|
+
disabled,
|
|
26
|
+
onFileUploadRequest
|
|
27
|
+
} = useMaterialQuizEditContext();
|
|
28
|
+
const {
|
|
29
|
+
control,
|
|
30
|
+
watch,
|
|
31
|
+
setValue
|
|
32
|
+
} = useFormContext();
|
|
33
|
+
const [watchedOptionType, watchedOptionInfo, watchedAnswerInfo, watchedAnswerHint, watchedExplanationInfo, watchedIsAutoGrade] = watch(['optionType', 'optionInfo', 'answerInfo', 'answerHint', 'explanationInfo', 'isAutoGrade']); //
|
|
34
|
+
// Change `optionInfo` according to `optionType`.
|
|
35
|
+
//
|
|
36
|
+
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
const get = () => {
|
|
39
|
+
switch (watchedOptionType) {
|
|
40
|
+
case enums.QuizOptionType.SelectOne:
|
|
41
|
+
case enums.QuizOptionType.SelectMultiple:
|
|
42
|
+
case enums.QuizOptionType.SelectMultipleOrder:
|
|
43
|
+
return watchedOptionInfo.length > 0 ? watchedOptionInfo : // add default option info
|
|
44
|
+
[{
|
|
45
|
+
id: createRandomId(),
|
|
46
|
+
value: intl.formatMessage({
|
|
47
|
+
id: 'common.option'
|
|
48
|
+
}, {
|
|
49
|
+
number: 1
|
|
50
|
+
})
|
|
51
|
+
}, {
|
|
52
|
+
id: createRandomId(),
|
|
53
|
+
value: intl.formatMessage({
|
|
54
|
+
id: 'common.option'
|
|
55
|
+
}, {
|
|
56
|
+
number: 2
|
|
57
|
+
})
|
|
58
|
+
}];
|
|
59
|
+
|
|
60
|
+
case enums.QuizOptionType.Text:
|
|
61
|
+
return [];
|
|
62
|
+
|
|
63
|
+
default:
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
setValue('optionInfo', get());
|
|
69
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
|
+
[watchedOptionType, setValue, intl]); //
|
|
71
|
+
// Change `answerInfo` according to `optionType`.
|
|
72
|
+
//
|
|
73
|
+
|
|
74
|
+
React.useEffect(() => {
|
|
75
|
+
const get = () => {
|
|
76
|
+
switch (watchedOptionType) {
|
|
77
|
+
case enums.QuizOptionType.SelectOne:
|
|
78
|
+
return Array.isArray(watchedAnswerInfo) ? // get first option
|
|
79
|
+
watchedAnswerInfo.slice(0, 1) : [0];
|
|
80
|
+
|
|
81
|
+
case enums.QuizOptionType.SelectMultiple:
|
|
82
|
+
case enums.QuizOptionType.SelectMultipleOrder:
|
|
83
|
+
return Array.isArray(watchedAnswerInfo) ? watchedAnswerInfo : [0];
|
|
84
|
+
|
|
85
|
+
case enums.QuizOptionType.Text:
|
|
86
|
+
return typeof watchedAnswerInfo === 'string' ? watchedAnswerInfo : '';
|
|
87
|
+
|
|
88
|
+
default:
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
setValue('answerInfo', get());
|
|
94
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
|
+
[watchedOptionType, setValue, intl]); //
|
|
96
|
+
// Change `answerHint` according to `optionType`.
|
|
97
|
+
//
|
|
98
|
+
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
const get = () => {
|
|
101
|
+
switch (watchedOptionType) {
|
|
102
|
+
case enums.QuizOptionType.SelectOne:
|
|
103
|
+
case enums.QuizOptionType.SelectMultiple:
|
|
104
|
+
case enums.QuizOptionType.SelectMultipleOrder:
|
|
105
|
+
return null;
|
|
106
|
+
|
|
107
|
+
case enums.QuizOptionType.Text:
|
|
108
|
+
return watchedAnswerHint !== null && watchedAnswerHint !== void 0 ? watchedAnswerHint : '';
|
|
109
|
+
|
|
110
|
+
default:
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
setValue('answerHint', get());
|
|
116
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
|
+
[watchedOptionType, setValue, intl]); //
|
|
118
|
+
// Change `isAutoGrade` according to `optionType`.
|
|
119
|
+
//
|
|
120
|
+
|
|
121
|
+
React.useEffect(() => {
|
|
122
|
+
const get = () => {
|
|
123
|
+
switch (watchedOptionType) {
|
|
124
|
+
case enums.QuizOptionType.SelectOne:
|
|
125
|
+
case enums.QuizOptionType.SelectMultiple:
|
|
126
|
+
case enums.QuizOptionType.SelectMultipleOrder:
|
|
127
|
+
return true;
|
|
128
|
+
|
|
129
|
+
case enums.QuizOptionType.Text:
|
|
130
|
+
return typeof watchedIsAutoGrade === 'boolean' ? watchedIsAutoGrade : true;
|
|
131
|
+
|
|
132
|
+
default:
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
setValue('isAutoGrade', get());
|
|
138
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
139
|
+
[watchedOptionType, setValue, intl]);
|
|
140
|
+
/**
|
|
141
|
+
* Input of option info and answer info,
|
|
142
|
+
* according to option type.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
const Option = React.useMemo(() => {
|
|
146
|
+
switch (watchedOptionType) {
|
|
147
|
+
case enums.QuizOptionType.SelectOne:
|
|
148
|
+
return OptionSelectOne;
|
|
149
|
+
|
|
150
|
+
case enums.QuizOptionType.SelectMultiple:
|
|
151
|
+
return OptionSelectMultiple;
|
|
152
|
+
|
|
153
|
+
case enums.QuizOptionType.SelectMultipleOrder:
|
|
154
|
+
return OptionSelectMultipleOrder;
|
|
155
|
+
|
|
156
|
+
case enums.QuizOptionType.Text:
|
|
157
|
+
return OptionText;
|
|
158
|
+
|
|
159
|
+
default:
|
|
160
|
+
return React.Fragment;
|
|
161
|
+
}
|
|
162
|
+
}, [watchedOptionType]);
|
|
163
|
+
/**
|
|
164
|
+
* Render input for quiz title.
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
const renderQuestionTitleInput = () => {
|
|
168
|
+
return React.createElement(FormInputVerticalLayout, {
|
|
169
|
+
label: React.createElement(Label, {
|
|
170
|
+
size: "small",
|
|
171
|
+
required: true
|
|
172
|
+
}, React.createElement(FormattedMessage, {
|
|
173
|
+
id: "content.title"
|
|
174
|
+
})),
|
|
175
|
+
input: React.createElement(Controller, {
|
|
176
|
+
control: control,
|
|
177
|
+
name: "questionTitle",
|
|
178
|
+
rules: {
|
|
179
|
+
required: {
|
|
180
|
+
value: true,
|
|
181
|
+
message: intl.formatMessage({
|
|
182
|
+
id: 'content.title.errorMessage.required'
|
|
183
|
+
})
|
|
184
|
+
},
|
|
185
|
+
minLength: {
|
|
186
|
+
value: MIN_TEXT_LENGTH,
|
|
187
|
+
message: intl.formatMessage({
|
|
188
|
+
id: 'common.errorMessage.range'
|
|
189
|
+
}, {
|
|
190
|
+
min: MIN_TEXT_LENGTH,
|
|
191
|
+
max: MAX_TEXT_LENGTH
|
|
192
|
+
})
|
|
193
|
+
},
|
|
194
|
+
maxLength: {
|
|
195
|
+
value: MAX_TEXT_LENGTH,
|
|
196
|
+
message: intl.formatMessage({
|
|
197
|
+
id: 'common.errorMessage.range'
|
|
198
|
+
}, {
|
|
199
|
+
min: MIN_TEXT_LENGTH,
|
|
200
|
+
max: MAX_TEXT_LENGTH
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
render: ({
|
|
205
|
+
field,
|
|
206
|
+
fieldState
|
|
207
|
+
}) => {
|
|
208
|
+
var _a;
|
|
209
|
+
|
|
210
|
+
return React.createElement(Input, Object.assign({
|
|
211
|
+
size: "small",
|
|
212
|
+
width: "full",
|
|
213
|
+
minLength: MIN_TEXT_LENGTH,
|
|
214
|
+
maxLength: MAX_TEXT_LENGTH,
|
|
215
|
+
placeholder: intl.formatMessage({
|
|
216
|
+
id: 'content.title.placeholder'
|
|
217
|
+
}),
|
|
218
|
+
invalid: fieldState.invalid,
|
|
219
|
+
invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
|
|
220
|
+
}, field));
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Render input for quiz description.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
const renderQuestionDescriptionInput = () => {
|
|
231
|
+
return React.createElement(FormInputVerticalLayout, {
|
|
232
|
+
label: React.createElement(Label, {
|
|
233
|
+
size: "small"
|
|
234
|
+
}, React.createElement(FormattedMessage, {
|
|
235
|
+
id: "content.description.title"
|
|
236
|
+
})),
|
|
237
|
+
input: React.createElement(Controller, {
|
|
238
|
+
control: control,
|
|
239
|
+
name: "questionDescription",
|
|
240
|
+
render: ({
|
|
241
|
+
field
|
|
242
|
+
}) => React.createElement(MarkdownEditor, Object.assign({
|
|
243
|
+
enableFooter: true,
|
|
244
|
+
placeholder: intl.formatMessage({
|
|
245
|
+
id: 'content.description.placeholder'
|
|
246
|
+
}),
|
|
247
|
+
onFileUploadRequest: onFileUploadRequest
|
|
248
|
+
}, field))
|
|
249
|
+
})
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Render input of option type, option info and answer info.
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
const renderOptionInput = () => {
|
|
258
|
+
return React.createElement(FormInputVerticalLayout, {
|
|
259
|
+
label: React.createElement(Label, {
|
|
260
|
+
size: "small",
|
|
261
|
+
required: true
|
|
262
|
+
}, React.createElement(FormattedMessage, {
|
|
263
|
+
id: "content.option.title"
|
|
264
|
+
})),
|
|
265
|
+
input: React.createElement(React.Fragment, null, React.createElement(Controller, {
|
|
266
|
+
control: control,
|
|
267
|
+
name: "optionType",
|
|
268
|
+
render: ({
|
|
269
|
+
field
|
|
270
|
+
}) => React.createElement(Tooltip, {
|
|
271
|
+
title: disabled ? intl.formatMessage({
|
|
272
|
+
id: 'content.option.tooltip.disabled'
|
|
273
|
+
}) : undefined,
|
|
274
|
+
placement: "top-end"
|
|
275
|
+
}, React.createElement(StyledQuizOptionTypeSelectWrap, null, React.createElement(Select, Object.assign({
|
|
276
|
+
size: "small",
|
|
277
|
+
width: "small",
|
|
278
|
+
readOnly: disabled
|
|
279
|
+
}, field, {
|
|
280
|
+
onChange: v => field.onChange(Number(v))
|
|
281
|
+
}), React.createElement("option", {
|
|
282
|
+
value: enums.QuizOptionType.SelectOne,
|
|
283
|
+
children: intl.formatMessage({
|
|
284
|
+
id: 'content.option.select.items.selectOne'
|
|
285
|
+
})
|
|
286
|
+
}), React.createElement("option", {
|
|
287
|
+
value: enums.QuizOptionType.SelectMultiple,
|
|
288
|
+
children: intl.formatMessage({
|
|
289
|
+
id: 'content.option.select.items.selectMultiple'
|
|
290
|
+
})
|
|
291
|
+
}), React.createElement("option", {
|
|
292
|
+
value: enums.QuizOptionType.SelectMultipleOrder,
|
|
293
|
+
children: intl.formatMessage({
|
|
294
|
+
id: 'content.option.select.items.selectMultipleOrder'
|
|
295
|
+
})
|
|
296
|
+
}), React.createElement("option", {
|
|
297
|
+
value: enums.QuizOptionType.Text,
|
|
298
|
+
children: intl.formatMessage({
|
|
299
|
+
id: 'content.option.select.items.text'
|
|
300
|
+
})
|
|
301
|
+
}))))
|
|
302
|
+
}), React.createElement(Transition, {
|
|
303
|
+
in: watchedOptionType === enums.QuizOptionType.SelectMultipleOrder,
|
|
304
|
+
timeout: 0,
|
|
305
|
+
mountOnEnter: true,
|
|
306
|
+
unmountOnExit: true
|
|
307
|
+
}, React.createElement(StatusText, {
|
|
308
|
+
role: "description",
|
|
309
|
+
preWrap: true
|
|
310
|
+
}, React.createElement(FormattedMessage, {
|
|
311
|
+
id: "content.option.statusText.dragNDrop"
|
|
312
|
+
}))), React.createElement(Vspace, {
|
|
313
|
+
height: 0.5
|
|
314
|
+
}), React.createElement(Option, null))
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* Input of answer hint.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
const renderAnswerHintInput = () => {
|
|
323
|
+
if (watchedOptionType !== enums.QuizOptionType.Text) {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return React.createElement(FormInputVerticalLayout, {
|
|
328
|
+
label: React.createElement(Label, {
|
|
329
|
+
size: "small"
|
|
330
|
+
}, React.createElement(FormattedMessage, {
|
|
331
|
+
id: "content.answerHint.title"
|
|
332
|
+
})),
|
|
333
|
+
description: React.createElement(Text, null, React.createElement(FormattedMessage, {
|
|
334
|
+
id: "content.answerHint.description"
|
|
335
|
+
})),
|
|
336
|
+
input: React.createElement(Controller, {
|
|
337
|
+
control: control,
|
|
338
|
+
name: "answerHint",
|
|
339
|
+
rules: {
|
|
340
|
+
minLength: {
|
|
341
|
+
value: MIN_TEXT_LENGTH,
|
|
342
|
+
message: intl.formatMessage({
|
|
343
|
+
id: 'common.errorMessage.range'
|
|
344
|
+
}, {
|
|
345
|
+
min: MIN_TEXT_LENGTH,
|
|
346
|
+
max: MAX_TEXT_LENGTH
|
|
347
|
+
})
|
|
348
|
+
},
|
|
349
|
+
maxLength: {
|
|
350
|
+
value: MAX_TEXT_LENGTH,
|
|
351
|
+
message: intl.formatMessage({
|
|
352
|
+
id: 'common.errorMessage.range'
|
|
353
|
+
}, {
|
|
354
|
+
min: MIN_TEXT_LENGTH,
|
|
355
|
+
max: MAX_TEXT_LENGTH
|
|
356
|
+
})
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
render: ({
|
|
360
|
+
field,
|
|
361
|
+
fieldState
|
|
362
|
+
}) => {
|
|
363
|
+
var _a, _b;
|
|
364
|
+
|
|
365
|
+
return React.createElement(Input, Object.assign({
|
|
366
|
+
size: "small",
|
|
367
|
+
width: "full",
|
|
368
|
+
minLength: MIN_TEXT_LENGTH,
|
|
369
|
+
maxLength: MAX_TEXT_LENGTH,
|
|
370
|
+
placeholder: intl.formatMessage({
|
|
371
|
+
id: 'content.answerHint.placeholder'
|
|
372
|
+
}),
|
|
373
|
+
invalid: fieldState.invalid,
|
|
374
|
+
invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
|
|
375
|
+
}, field, {
|
|
376
|
+
value: (_b = field.value) !== null && _b !== void 0 ? _b : ''
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
})
|
|
380
|
+
});
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Input of explanation info.
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
const renderExplanationInfoInput = () => {
|
|
388
|
+
return React.createElement(FormInputVerticalLayout, {
|
|
389
|
+
label: React.createElement(Label, {
|
|
390
|
+
size: "small"
|
|
391
|
+
}, React.createElement(FormattedMessage, {
|
|
392
|
+
id: "content.explanationInfo.title"
|
|
393
|
+
})),
|
|
394
|
+
description: React.createElement(Text, null, React.createElement(FormattedMessage, {
|
|
395
|
+
id: "content.explanationInfo.description"
|
|
396
|
+
})),
|
|
397
|
+
input: React.createElement(React.Fragment, null, React.createElement(Controller, {
|
|
398
|
+
control: control,
|
|
399
|
+
name: "explanationInfo.isEnabled",
|
|
400
|
+
render: ({
|
|
401
|
+
field
|
|
402
|
+
}) => React.createElement(Checkbox, Object.assign({
|
|
403
|
+
size: "small"
|
|
404
|
+
}, field), React.createElement(FormattedMessage, {
|
|
405
|
+
id: "content.explanationInfo.checkbox.label"
|
|
406
|
+
}))
|
|
407
|
+
}), React.createElement(Transition, {
|
|
408
|
+
in: watchedExplanationInfo.isEnabled,
|
|
409
|
+
timeout: 0,
|
|
410
|
+
mountOnEnter: true,
|
|
411
|
+
unmountOnExit: true
|
|
412
|
+
}, React.createElement(React.Fragment, null, React.createElement(Vspace, {
|
|
413
|
+
height: 1
|
|
414
|
+
}), React.createElement(Controller, {
|
|
415
|
+
control: control,
|
|
416
|
+
name: "explanationInfo.value",
|
|
417
|
+
rules: {
|
|
418
|
+
required: {
|
|
419
|
+
value: true,
|
|
420
|
+
message: intl.formatMessage({
|
|
421
|
+
id: 'content.explanationInfo.textarea.placeholder'
|
|
422
|
+
})
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
render: ({
|
|
426
|
+
field,
|
|
427
|
+
fieldState
|
|
428
|
+
}) => {
|
|
429
|
+
var _a;
|
|
430
|
+
|
|
431
|
+
return React.createElement(Flex, {
|
|
432
|
+
column: true
|
|
433
|
+
}, fieldState.invalid ? React.createElement(React.Fragment, null, React.createElement(StatusText, {
|
|
434
|
+
children: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
435
|
+
role: "danger"
|
|
436
|
+
}), React.createElement(Vspace, {
|
|
437
|
+
height: 0.5
|
|
438
|
+
})) : null, React.createElement(MarkdownEditor, Object.assign({
|
|
439
|
+
enableFooter: true,
|
|
440
|
+
placeholder: intl.formatMessage({
|
|
441
|
+
id: 'content.explanationInfo.textarea.errorMessage.required'
|
|
442
|
+
}),
|
|
443
|
+
onFileUploadRequest: onFileUploadRequest
|
|
444
|
+
}, field)));
|
|
445
|
+
}
|
|
446
|
+
}))))
|
|
447
|
+
});
|
|
448
|
+
}; //
|
|
449
|
+
//
|
|
450
|
+
//
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
return React.createElement(React.Fragment, null, renderQuestionTitleInput(), renderQuestionDescriptionInput(), renderOptionInput(), renderAnswerHintInput(), renderExplanationInfoInput());
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
export { MaterialQuizEditContent as default };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { MaterialQuizEditProps } from './MaterialQuizEdit';
|
|
3
|
+
declare type MaterialQuizEditContextValue = Pick<MaterialQuizEditProps, 'disabled' | 'onFileUploadRequest'>;
|
|
4
|
+
declare const MaterialQuizEditContext: React.Context<MaterialQuizEditContextValue>;
|
|
5
|
+
export declare const useMaterialQuizEditContext: () => MaterialQuizEditContextValue;
|
|
6
|
+
export default MaterialQuizEditContext;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const en: {
|
|
2
|
+
'common.option': string;
|
|
3
|
+
'common.errorMessage.range': string;
|
|
4
|
+
'content.title': string;
|
|
5
|
+
'content.title.errorMessage.required': string;
|
|
6
|
+
'content.title.placeholder': string;
|
|
7
|
+
'content.description.title': string;
|
|
8
|
+
'content.description.placeholder': string;
|
|
9
|
+
'content.option.title': string;
|
|
10
|
+
'content.option.tooltip.disabled': string;
|
|
11
|
+
'content.option.select.items.selectOne': string;
|
|
12
|
+
'content.option.select.items.selectMultiple': string;
|
|
13
|
+
'content.option.select.items.selectMultipleOrder': string;
|
|
14
|
+
'content.option.select.items.text': string;
|
|
15
|
+
'content.option.statusText.dragNDrop': string;
|
|
16
|
+
'content.option.errorMessage.required': string;
|
|
17
|
+
'content.answerHint.title': string;
|
|
18
|
+
'content.answerHint.description': string;
|
|
19
|
+
'content.answerHint.placeholder': string;
|
|
20
|
+
'content.explanationInfo.title': string;
|
|
21
|
+
'content.explanationInfo.description': string;
|
|
22
|
+
'content.explanationInfo.checkbox.label': string;
|
|
23
|
+
'content.explanationInfo.textarea.placeholder': string;
|
|
24
|
+
'content.explanationInfo.textarea.errorMessage.required': string;
|
|
25
|
+
'option.common.select.errorMessage.required': string;
|
|
26
|
+
'option.common.select.placeholder': string;
|
|
27
|
+
'option.common.select.tooltip.minOptionInfoItem': string;
|
|
28
|
+
'option.common.select.tooltip.maxOptionInfoItem': string;
|
|
29
|
+
'option.common.select.addButton': string;
|
|
30
|
+
'option.text.answerInfo.errorMessage.required': string;
|
|
31
|
+
'option.text.answerInfo.hintText': string;
|
|
32
|
+
'option.text.isAutoGrade.checkbox.label': string;
|
|
33
|
+
};
|
|
34
|
+
export declare const ko: typeof en;
|