@elice/material-quiz 1.230817.1 → 1.230821.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/cjs/components/material-quiz-edit/MaterialQuizEdit.js +4 -4
- package/cjs/components/material-quiz-edit/options/OptionEditor.d.ts +4 -1
- package/cjs/components/material-quiz-edit/options/OptionEditor.js +13 -1
- package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +3 -2
- package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +2 -2
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +3 -1
- package/es/components/material-quiz-edit/MaterialQuizEdit.js +4 -4
- package/es/components/material-quiz-edit/options/OptionEditor.d.ts +4 -1
- package/es/components/material-quiz-edit/options/OptionEditor.js +13 -1
- package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +3 -2
- package/es/components/material-quiz-edit/options/OptionSelectOne.js +2 -2
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +3 -1
- package/package.json +4 -4
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var reactHookForm = require('react-hook-form');
|
|
7
7
|
var reactIntl = require('react-intl');
|
|
8
|
-
var
|
|
8
|
+
var materialSharedUtils = require('@elice/material-shared-utils');
|
|
9
9
|
var editValue = require('./utils/editValue.js');
|
|
10
10
|
var context = require('./context.js');
|
|
11
11
|
var locales = require('./locales.js');
|
|
@@ -37,7 +37,7 @@ var MaterialQuizEdit = React.forwardRef(function (_ref, ref) {
|
|
|
37
37
|
// Reset from value, when `value` changes.
|
|
38
38
|
// TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
|
|
39
39
|
//
|
|
40
|
-
|
|
40
|
+
materialSharedUtils.useDeepClonedCompareEffect(function () {
|
|
41
41
|
useFormMethods.reset(editValue.manipulateValue(value), {
|
|
42
42
|
keepDirty: true,
|
|
43
43
|
keepErrors: true,
|
|
@@ -51,8 +51,8 @@ var MaterialQuizEdit = React.forwardRef(function (_ref, ref) {
|
|
|
51
51
|
// Emit `onChange` handler when form value changed.
|
|
52
52
|
// TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
|
|
53
53
|
//
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
materialSharedUtils.useDeepClonedCompareEffect(function () {
|
|
55
|
+
onChange(editValue.restoreValue(watchedMaterialQuizEditValue));
|
|
56
56
|
}, [watchedMaterialQuizEditValue]);
|
|
57
57
|
//
|
|
58
58
|
// Emit `onFormStateChange` handler when form state change.
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
interface OptionTextareaProps extends Omit<React.HTMLAttributes<HTMLTextAreaElement>, 'prefix'> {
|
|
2
|
+
interface OptionTextareaProps extends Omit<React.HTMLAttributes<HTMLTextAreaElement>, 'prefix' | 'onChange'> {
|
|
3
3
|
prefix?: React.ReactNode;
|
|
4
4
|
suffix?: React.ReactNode;
|
|
5
5
|
invalid?: boolean;
|
|
6
6
|
invalidText?: string;
|
|
7
7
|
readOnly?: boolean;
|
|
8
8
|
disabled?: boolean;
|
|
9
|
+
value?: string;
|
|
10
|
+
onChange?: (value: string) => void;
|
|
11
|
+
onBlur?: () => void;
|
|
9
12
|
}
|
|
10
13
|
declare const OptionEditor: React.ForwardRefExoticComponent<OptionTextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
11
14
|
export default OptionEditor;
|
|
@@ -44,6 +44,17 @@ var OptionEditor = React__default["default"].forwardRef(function (_a, ref) {
|
|
|
44
44
|
invalidText = _a.invalidText,
|
|
45
45
|
readOnly = _a.readOnly,
|
|
46
46
|
props = tslib.__rest(_a, ["suffix", "prefix", "invalid", "invalidText", "readOnly"]);
|
|
47
|
+
/**
|
|
48
|
+
* Extract textarea element from legacy TextArea ref prop.
|
|
49
|
+
*/
|
|
50
|
+
var handleTextAreaApi = React__default["default"].useCallback(function (textAreaApi) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (!ref) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
var textAreaInput = (_a = textAreaApi === null || textAreaApi === void 0 ? void 0 : textAreaApi.input) !== null && _a !== void 0 ? _a : null;
|
|
56
|
+
typeof ref === 'function' ? ref(textAreaInput) : ref.current = textAreaInput;
|
|
57
|
+
}, [ref]);
|
|
47
58
|
return React__default["default"].createElement("div", {
|
|
48
59
|
className: classNames__default["default"](PREFIX, props.className)
|
|
49
60
|
}, React__default["default"].createElement(StyledTextareaWrap, {
|
|
@@ -51,9 +62,10 @@ var OptionEditor = React__default["default"].forwardRef(function (_a, ref) {
|
|
|
51
62
|
}, prefix ? React__default["default"].createElement("div", {
|
|
52
63
|
className: "".concat(PREFIX, "-adornment prefix")
|
|
53
64
|
}, prefix) : null, React__default["default"].createElement(StyledTextarea, Object.assign({}, props, {
|
|
54
|
-
ref:
|
|
65
|
+
ref: handleTextAreaApi,
|
|
55
66
|
invalid: invalid,
|
|
56
67
|
readOnly: readOnly,
|
|
68
|
+
resetFocus: props.onBlur,
|
|
57
69
|
"aria-disabled": props.disabled
|
|
58
70
|
})), suffix ? React__default["default"].createElement("div", {
|
|
59
71
|
className: "".concat(PREFIX, "-adornment suffix")
|
|
@@ -37,6 +37,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
37
37
|
setValue = _useFormContext.setValue,
|
|
38
38
|
watch = _useFormContext.watch;
|
|
39
39
|
var _useFieldArray = reactHookForm.useFieldArray({
|
|
40
|
+
control: control,
|
|
40
41
|
name: 'options',
|
|
41
42
|
keyName: 'id',
|
|
42
43
|
shouldUnregister: true
|
|
@@ -139,7 +140,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
139
140
|
var field = _ref3.field,
|
|
140
141
|
fieldState = _ref3.fieldState;
|
|
141
142
|
var _a;
|
|
142
|
-
return React__default["default"].createElement(OptionEditor["default"], Object.assign({
|
|
143
|
+
return React__default["default"].createElement(OptionEditor["default"], Object.assign({
|
|
143
144
|
invalid: fieldState.invalid,
|
|
144
145
|
invalidText: (_a = fieldState === null || fieldState === void 0 ? void 0 : fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
145
146
|
readOnly: disabled,
|
|
@@ -169,7 +170,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
169
170
|
return removeOptionInfo(index);
|
|
170
171
|
}
|
|
171
172
|
})))
|
|
172
|
-
}));
|
|
173
|
+
}, field));
|
|
173
174
|
}
|
|
174
175
|
});
|
|
175
176
|
})), React__default["default"].createElement(blocks.Vspace, {
|
|
@@ -134,7 +134,7 @@ var OptionSelectOne = function OptionSelectOne() {
|
|
|
134
134
|
var field = _ref3.field,
|
|
135
135
|
fieldState = _ref3.fieldState;
|
|
136
136
|
var _a;
|
|
137
|
-
return React__default["default"].createElement(OptionEditor["default"], Object.assign({
|
|
137
|
+
return React__default["default"].createElement(OptionEditor["default"], Object.assign({
|
|
138
138
|
invalid: fieldState.invalid,
|
|
139
139
|
invalidText: (_a = fieldState === null || fieldState === void 0 ? void 0 : fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
140
140
|
placeholder: intl.formatMessage({
|
|
@@ -164,7 +164,7 @@ var OptionSelectOne = function OptionSelectOne() {
|
|
|
164
164
|
return removeOptionInfo(index);
|
|
165
165
|
}
|
|
166
166
|
})))
|
|
167
|
-
}));
|
|
167
|
+
}, field));
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
170
|
})), React__default["default"].createElement(blocks.Vspace, {
|
|
@@ -77,9 +77,11 @@ var OptionGroupGroupListItem = function OptionGroupGroupListItem(_ref2) {
|
|
|
77
77
|
render: function render(_ref3) {
|
|
78
78
|
var field = _ref3.field,
|
|
79
79
|
fieldState = _ref3.fieldState;
|
|
80
|
-
return React__default["default"].createElement(StyledInputGroup, Object.assign({
|
|
80
|
+
return React__default["default"].createElement(StyledInputGroup, Object.assign({
|
|
81
81
|
invalid: fieldState.invalid || !isGroupChildAnswer,
|
|
82
82
|
width: "full"
|
|
83
|
+
}, field, {
|
|
84
|
+
ref: null
|
|
83
85
|
}));
|
|
84
86
|
}
|
|
85
87
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import { useForm, FormProvider } from 'react-hook-form';
|
|
3
3
|
import { IntlProvider } from 'react-intl';
|
|
4
|
-
import {
|
|
4
|
+
import { useDeepClonedCompareEffect } from '@elice/material-shared-utils';
|
|
5
5
|
import { manipulateValue, restoreValue } from './utils/editValue.js';
|
|
6
6
|
import MaterialQuizEditContext from './context.js';
|
|
7
7
|
import * as locales from './locales.js';
|
|
@@ -30,7 +30,7 @@ var MaterialQuizEdit = forwardRef(function (_ref, ref) {
|
|
|
30
30
|
// Reset from value, when `value` changes.
|
|
31
31
|
// TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
|
|
32
32
|
//
|
|
33
|
-
|
|
33
|
+
useDeepClonedCompareEffect(function () {
|
|
34
34
|
useFormMethods.reset(manipulateValue(value), {
|
|
35
35
|
keepDirty: true,
|
|
36
36
|
keepErrors: true,
|
|
@@ -44,8 +44,8 @@ var MaterialQuizEdit = forwardRef(function (_ref, ref) {
|
|
|
44
44
|
// Emit `onChange` handler when form value changed.
|
|
45
45
|
// TODO: will be removed, since `CourseLecturesMaterialTemplate` removed at `elice-web`.
|
|
46
46
|
//
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
useDeepClonedCompareEffect(function () {
|
|
48
|
+
onChange(restoreValue(watchedMaterialQuizEditValue));
|
|
49
49
|
}, [watchedMaterialQuizEditValue]);
|
|
50
50
|
//
|
|
51
51
|
// Emit `onFormStateChange` handler when form state change.
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
interface OptionTextareaProps extends Omit<React.HTMLAttributes<HTMLTextAreaElement>, 'prefix'> {
|
|
2
|
+
interface OptionTextareaProps extends Omit<React.HTMLAttributes<HTMLTextAreaElement>, 'prefix' | 'onChange'> {
|
|
3
3
|
prefix?: React.ReactNode;
|
|
4
4
|
suffix?: React.ReactNode;
|
|
5
5
|
invalid?: boolean;
|
|
6
6
|
invalidText?: string;
|
|
7
7
|
readOnly?: boolean;
|
|
8
8
|
disabled?: boolean;
|
|
9
|
+
value?: string;
|
|
10
|
+
onChange?: (value: string) => void;
|
|
11
|
+
onBlur?: () => void;
|
|
9
12
|
}
|
|
10
13
|
declare const OptionEditor: React.ForwardRefExoticComponent<OptionTextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
11
14
|
export default OptionEditor;
|
|
@@ -34,6 +34,17 @@ var OptionEditor = React.forwardRef(function (_a, ref) {
|
|
|
34
34
|
invalidText = _a.invalidText,
|
|
35
35
|
readOnly = _a.readOnly,
|
|
36
36
|
props = __rest(_a, ["suffix", "prefix", "invalid", "invalidText", "readOnly"]);
|
|
37
|
+
/**
|
|
38
|
+
* Extract textarea element from legacy TextArea ref prop.
|
|
39
|
+
*/
|
|
40
|
+
var handleTextAreaApi = React.useCallback(function (textAreaApi) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!ref) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var textAreaInput = (_a = textAreaApi === null || textAreaApi === void 0 ? void 0 : textAreaApi.input) !== null && _a !== void 0 ? _a : null;
|
|
46
|
+
typeof ref === 'function' ? ref(textAreaInput) : ref.current = textAreaInput;
|
|
47
|
+
}, [ref]);
|
|
37
48
|
return React.createElement("div", {
|
|
38
49
|
className: classNames(PREFIX, props.className)
|
|
39
50
|
}, React.createElement(StyledTextareaWrap, {
|
|
@@ -41,9 +52,10 @@ var OptionEditor = React.forwardRef(function (_a, ref) {
|
|
|
41
52
|
}, prefix ? React.createElement("div", {
|
|
42
53
|
className: "".concat(PREFIX, "-adornment prefix")
|
|
43
54
|
}, prefix) : null, React.createElement(StyledTextarea, Object.assign({}, props, {
|
|
44
|
-
ref:
|
|
55
|
+
ref: handleTextAreaApi,
|
|
45
56
|
invalid: invalid,
|
|
46
57
|
readOnly: readOnly,
|
|
58
|
+
resetFocus: props.onBlur,
|
|
47
59
|
"aria-disabled": props.disabled
|
|
48
60
|
})), suffix ? React.createElement("div", {
|
|
49
61
|
className: "".concat(PREFIX, "-adornment suffix")
|
|
@@ -28,6 +28,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
28
28
|
setValue = _useFormContext.setValue,
|
|
29
29
|
watch = _useFormContext.watch;
|
|
30
30
|
var _useFieldArray = useFieldArray({
|
|
31
|
+
control: control,
|
|
31
32
|
name: 'options',
|
|
32
33
|
keyName: 'id',
|
|
33
34
|
shouldUnregister: true
|
|
@@ -130,7 +131,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
130
131
|
var field = _ref3.field,
|
|
131
132
|
fieldState = _ref3.fieldState;
|
|
132
133
|
var _a;
|
|
133
|
-
return React.createElement(OptionEditor, Object.assign({
|
|
134
|
+
return React.createElement(OptionEditor, Object.assign({
|
|
134
135
|
invalid: fieldState.invalid,
|
|
135
136
|
invalidText: (_a = fieldState === null || fieldState === void 0 ? void 0 : fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
136
137
|
readOnly: disabled,
|
|
@@ -160,7 +161,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
|
|
|
160
161
|
return removeOptionInfo(index);
|
|
161
162
|
}
|
|
162
163
|
})))
|
|
163
|
-
}));
|
|
164
|
+
}, field));
|
|
164
165
|
}
|
|
165
166
|
});
|
|
166
167
|
})), React.createElement(Vspace, {
|
|
@@ -125,7 +125,7 @@ var OptionSelectOne = function OptionSelectOne() {
|
|
|
125
125
|
var field = _ref3.field,
|
|
126
126
|
fieldState = _ref3.fieldState;
|
|
127
127
|
var _a;
|
|
128
|
-
return React.createElement(OptionEditor, Object.assign({
|
|
128
|
+
return React.createElement(OptionEditor, Object.assign({
|
|
129
129
|
invalid: fieldState.invalid,
|
|
130
130
|
invalidText: (_a = fieldState === null || fieldState === void 0 ? void 0 : fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
131
131
|
placeholder: intl.formatMessage({
|
|
@@ -155,7 +155,7 @@ var OptionSelectOne = function OptionSelectOne() {
|
|
|
155
155
|
return removeOptionInfo(index);
|
|
156
156
|
}
|
|
157
157
|
})))
|
|
158
|
-
}));
|
|
158
|
+
}, field));
|
|
159
159
|
}
|
|
160
160
|
});
|
|
161
161
|
})), React.createElement(Vspace, {
|
|
@@ -67,9 +67,11 @@ var OptionGroupGroupListItem = function OptionGroupGroupListItem(_ref2) {
|
|
|
67
67
|
render: function render(_ref3) {
|
|
68
68
|
var field = _ref3.field,
|
|
69
69
|
fieldState = _ref3.fieldState;
|
|
70
|
-
return React.createElement(StyledInputGroup, Object.assign({
|
|
70
|
+
return React.createElement(StyledInputGroup, Object.assign({
|
|
71
71
|
invalid: fieldState.invalid || !isGroupChildAnswer,
|
|
72
72
|
width: "full"
|
|
73
|
+
}, field, {
|
|
74
|
+
ref: null
|
|
73
75
|
}));
|
|
74
76
|
}
|
|
75
77
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elice/material-quiz",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.230821.0",
|
|
4
4
|
"description": "User view and editing components of Elice material quiz",
|
|
5
5
|
"repository": "https://git.elicer.io/elice/frontend/library/elice-material",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@elice/icons": "^1.230814.0",
|
|
55
55
|
"@elice/icons-legacy": "npm:@elice/icons@0.230814.0",
|
|
56
56
|
"@elice/markdown": "^1.220815.0",
|
|
57
|
-
"@elice/material-shared-types": "1.
|
|
58
|
-
"@elice/material-shared-utils": "1.
|
|
57
|
+
"@elice/material-shared-types": "1.230821.0",
|
|
58
|
+
"@elice/material-shared-utils": "1.230821.0",
|
|
59
59
|
"@elice/types": "^1.230815.0",
|
|
60
60
|
"@types/classnames": "^2.3.1",
|
|
61
61
|
"@types/jquery": "^3.5.13",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"react-use": "^17.2.4",
|
|
70
70
|
"styled-components": "^5.3.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "4f85930b4b7eb23121650c5c95b14620ea2fb198"
|
|
73
73
|
}
|