@elice/material-quiz 1.230818.0 → 1.230825.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.
@@ -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 reactUse = require('react-use');
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
- reactUse.useDeepCompareEffect(function () {
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
- reactUse.useDeepCompareEffect(function () {
55
- return onChange(editValue.restoreValue(watchedMaterialQuizEditValue));
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: 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
@@ -169,9 +170,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
169
170
  return removeOptionInfo(index);
170
171
  }
171
172
  })))
172
- }, field, {
173
- ref: null
174
- }));
173
+ }, field));
175
174
  }
176
175
  });
177
176
  })), React__default["default"].createElement(blocks.Vspace, {
@@ -173,9 +173,7 @@ var OptionSelectMultipleOrder = function OptionSelectMultipleOrder() {
173
173
  readOnly: disabled,
174
174
  invalid: fieldState.invalid,
175
175
  invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
176
- }, field, {
177
- ref: null
178
- }));
176
+ }, field));
179
177
  }
180
178
  });
181
179
  })), React__default["default"].createElement(blocks.Vspace, {
@@ -164,9 +164,7 @@ var OptionSelectOne = function OptionSelectOne() {
164
164
  return removeOptionInfo(index);
165
165
  }
166
166
  })))
167
- }, field, {
168
- ref: null
169
- }));
167
+ }, field));
170
168
  }
171
169
  });
172
170
  })), React__default["default"].createElement(blocks.Vspace, {
@@ -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 { useDeepCompareEffect } from 'react-use';
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
- useDeepCompareEffect(function () {
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
- useDeepCompareEffect(function () {
48
- return onChange(restoreValue(watchedMaterialQuizEditValue));
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: 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
@@ -160,9 +161,7 @@ var OptionSelectMultiple = function OptionSelectMultiple() {
160
161
  return removeOptionInfo(index);
161
162
  }
162
163
  })))
163
- }, field, {
164
- ref: null
165
- }));
164
+ }, field));
166
165
  }
167
166
  });
168
167
  })), React.createElement(Vspace, {
@@ -164,9 +164,7 @@ var OptionSelectMultipleOrder = function OptionSelectMultipleOrder() {
164
164
  readOnly: disabled,
165
165
  invalid: fieldState.invalid,
166
166
  invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message
167
- }, field, {
168
- ref: null
169
- }));
167
+ }, field));
170
168
  }
171
169
  });
172
170
  })), React.createElement(Vspace, {
@@ -155,9 +155,7 @@ var OptionSelectOne = function OptionSelectOne() {
155
155
  return removeOptionInfo(index);
156
156
  }
157
157
  })))
158
- }, field, {
159
- ref: null
160
- }));
158
+ }, field));
161
159
  }
162
160
  });
163
161
  })), React.createElement(Vspace, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elice/material-quiz",
3
- "version": "1.230818.0",
3
+ "version": "1.230825.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.230818.0",
58
- "@elice/material-shared-utils": "1.230818.0",
57
+ "@elice/material-shared-types": "1.230825.0",
58
+ "@elice/material-shared-utils": "1.230825.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": "7f0e6d7d15c59c7eccf2180f16ba134dab4194e8"
72
+ "gitHead": "5859affd33ce2d07bb176bad73bc5cf4ed1c4138"
73
73
  }