@digabi/exam-engine-core 22.2.0-alpha.3 → 22.2.0-alpha.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -26,8 +26,12 @@ interface Props {
|
|
26
26
|
export default class RichTextAnswer extends React.PureComponent<Props> {
|
27
27
|
static contextType: React.Context<CommonExamContext>;
|
28
28
|
context: React.ContextType<typeof CommonExamContext>;
|
29
|
+
private editorRef;
|
30
|
+
private lastHTML;
|
31
|
+
constructor(props: Props);
|
29
32
|
handleSaveError: (err: ErrorResponse) => void;
|
30
33
|
handleChange: (answer: Answer) => void;
|
34
|
+
componentDidUpdate(): void;
|
31
35
|
render(): React.ReactNode;
|
32
36
|
}
|
33
37
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"RichTextAnswer.d.ts","sourceRoot":"","sources":["../../../src/components/exam/RichTextAnswer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAuB,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"RichTextAnswer.d.ts","sourceRoot":"","sources":["../../../src/components/exam/RichTextAnswer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAuB,EAAE,MAAM,EAAwB,MAAM,kBAAkB,CAAA;AAM/E,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,oBAAoB,GAAG,+BAA+B,GAAG,0BAA0B,CAAA;IACxF,OAAO,CAAC,EAAE,QAAQ,CAAA;CACnB;AAED,KAAK,aAAa,GAAG;IAAE,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAAG,KAAK,CAAA;AAE7D,UAAU,KAAK;IACb,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1D,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;IACzC,cAAc,EAAE,CAAC,UAAU,EAAE,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACrD,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC;IACpE,MAAM,CAAC,WAAW,mCAAoB;IAC9B,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAA;IAC5D,OAAO,CAAC,SAAS,CAAuC;IACxD,OAAO,CAAC,QAAQ,CAAQ;gBAEZ,KAAK,EAAE,KAAK;IAMxB,eAAe,QAAS,aAAa,KAAG,IAAI,CAa3C;IAED,YAAY,WAAY,MAAM,KAAG,IAAI,CAKpC;IAED,kBAAkB,IAAI,IAAI;IAY1B,MAAM,IAAI,KAAK,CAAC,SAAS;CA2C1B"}
|
@@ -7,8 +7,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
7
7
|
import { faExpandAlt } from '@fortawesome/free-solid-svg-icons';
|
8
8
|
import { useExamTranslation } from '../../i18n';
|
9
9
|
class RichTextAnswer extends React.PureComponent {
|
10
|
-
constructor() {
|
11
|
-
super(
|
10
|
+
constructor(props) {
|
11
|
+
super(props);
|
12
12
|
this.handleSaveError = (err) => {
|
13
13
|
const key = (() => {
|
14
14
|
switch (_.get(err, 'response.status')) {
|
@@ -24,13 +24,27 @@ class RichTextAnswer extends React.PureComponent {
|
|
24
24
|
};
|
25
25
|
this.handleChange = (answer) => {
|
26
26
|
const { onChange } = this.props;
|
27
|
+
this.lastHTML = answer.answerHtml;
|
27
28
|
onChange(answer.answerHtml, answer.answerText);
|
28
29
|
};
|
30
|
+
this.editorRef = React.createRef();
|
31
|
+
this.lastHTML = this.props.answer ? this.props.answer.value : '';
|
32
|
+
}
|
33
|
+
componentDidUpdate() {
|
34
|
+
/**
|
35
|
+
* Don't update element unless value has changed from last known value to prevent cursor jumping
|
36
|
+
* This implementation is _primarily_ intended to be used by AnswerToolbar's answerHistory, which
|
37
|
+
* will update the value of `answer` without the user making edits to the rich-text-editor input field
|
38
|
+
* */
|
39
|
+
if (this.editorRef.current && this.props.answer && this.props.answer.value !== this.lastHTML) {
|
40
|
+
this.lastHTML = this.props.answer.value;
|
41
|
+
this.editorRef.current.setValue(this.props.answer.value);
|
42
|
+
}
|
29
43
|
}
|
30
44
|
render() {
|
31
45
|
const { questionId, className, labelledBy, answer, lang, invalid, saveScreenshot } = this.props;
|
32
46
|
return (React.createElement(ExpandQuestionContext.Consumer, null, ({ expanded, toggleWriterMode }) => (React.createElement(React.Fragment, null,
|
33
|
-
React.createElement(RichTextEditor, { baseUrl: '', initialValue: answer === null || answer === void 0 ? void 0 : answer.value, language: this.context.language.slice(0, 2).toUpperCase(), onValueChange: this.handleChange, getPasteSource: (file) => saveScreenshot(file).catch((err) => {
|
47
|
+
React.createElement(RichTextEditor, { ref: this.editorRef, baseUrl: '', initialValue: answer === null || answer === void 0 ? void 0 : answer.value, language: this.context.language.slice(0, 2).toUpperCase(), onValueChange: this.handleChange, getPasteSource: (file) => saveScreenshot(file).catch((err) => {
|
34
48
|
this.handleSaveError(err);
|
35
49
|
throw err; // Rethrow error so rich-text-editor can handle it.
|
36
50
|
}), textAreaProps: {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"RichTextAnswer.js","sourceRoot":"","sources":["../../../src/components/exam/RichTextAnswer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,
|
1
|
+
{"version":3,"file":"RichTextAnswer.js","sourceRoot":"","sources":["../../../src/components/exam/RichTextAnswer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,cAAgD,MAAM,kBAAkB,CAAA;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAqB/C,MAAqB,cAAe,SAAQ,KAAK,CAAC,aAAoB;IAMpE,YAAY,KAAY;QACtB,KAAK,CAAC,KAAK,CAAC,CAAA;QAKd,oBAAe,GAAG,CAAC,GAAkB,EAAQ,EAAE;YAC7C,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE;gBAChB,QAAQ,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,iBAAiB,CAAC,EAAE,CAAC;oBACtC,KAAK,GAAG;wBACN,OAAO,+BAA+B,CAAA;oBACxC,KAAK,GAAG;wBACN,OAAO,oBAAoB,CAAA;oBAC7B;wBACE,OAAO,0BAA0B,CAAA;gBACrC,CAAC;YACH,CAAC,CAAC,EAAE,CAAA;YAEJ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EA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