catchup-library-web 1.11.1 → 1.11.3

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.
@@ -4,6 +4,43 @@ import { useEffect, useRef } from "react";
4
4
  import { IInputGroupProps } from "../../properties/GroupProperties";
5
5
  import BaseImage from "../images/BaseImage";
6
6
  import { IOptionProps } from "../../properties/CommonProperties";
7
+ import { MathfieldElement } from "mathlive";
8
+
9
+ declare global {
10
+ namespace JSX {
11
+ interface IntrinsicElements {
12
+ "math-field": React.DetailedHTMLProps<
13
+ React.HTMLAttributes<MathfieldElement>,
14
+ MathfieldElement
15
+ > & {
16
+ value?: string;
17
+ disabled?: boolean;
18
+ readonly?: boolean;
19
+ "virtual-keyboard-mode"?: "manual" | "onfocus" | "off";
20
+ "virtual-keyboard-theme"?: "material" | "apple";
21
+ "math-mode-space"?: string;
22
+ "letter-shape-style"?: "tex" | "french" | "iso" | "upright" | "auto";
23
+ "min-font-scale"?: number;
24
+ "max-font-scale"?: number;
25
+ "smart-fence"?: boolean;
26
+ "smart-mode"?: boolean;
27
+ "smart-superscript"?: boolean;
28
+ "inline-shortcut-timeout"?: number;
29
+ "keybinding-mode"?: "default" | "vim" | "emacs";
30
+ "speech-engine"?: "local" | "amazon" | "google";
31
+ "speech-engine-voice"?: string;
32
+ "speech-engine-rate"?: string;
33
+ "read-only"?: boolean;
34
+ "remove-extraneous-parentheses"?: boolean;
35
+ "script-depth"?: number;
36
+ placeholder?: string;
37
+ "default-mode"?: "math" | "text";
38
+ "fonts-directory"?: string;
39
+ "sounds-directory"?: string;
40
+ };
41
+ }
42
+ }
43
+ }
7
44
 
8
45
  const InputGroup = ({
9
46
  type,
@@ -23,8 +60,10 @@ const InputGroup = ({
23
60
  useMinHeight,
24
61
  disabled,
25
62
  limit,
63
+ useMath,
26
64
  }: IInputGroupProps) => {
27
65
  const textAreaRef = useRef<HTMLTextAreaElement>(null);
66
+ const mathFieldRef = useRef<MathfieldElement>(null);
28
67
 
29
68
  useEffect(() => {
30
69
  if (!textAreaRef) return;
@@ -36,6 +75,15 @@ const InputGroup = ({
36
75
  }
37
76
  }, [textAreaRef, value]);
38
77
 
78
+ useEffect(() => {
79
+ if (!useMath) return;
80
+ import("mathlive").then(({ MathfieldElement }) => {
81
+ if (!customElements.get("math-field")) {
82
+ customElements.define("math-field", MathfieldElement);
83
+ }
84
+ });
85
+ }, [useMath, type, placeholder, title]);
86
+
39
87
  const retrieveNullableOptionList = () => {
40
88
  if (!optionList) return [];
41
89
  const currentOptionList = {
@@ -66,6 +114,24 @@ const InputGroup = ({
66
114
  }
67
115
  };
68
116
 
117
+ const handleMathFieldChange = (event: React.FormEvent<MathfieldElement>) => {
118
+ const mathField = event.currentTarget;
119
+ const syntheticEvent = {
120
+ target: {
121
+ value: mathField.value,
122
+ type: "text",
123
+ },
124
+ };
125
+ onChange && onChange(syntheticEvent);
126
+ };
127
+
128
+ const handleMathFieldFocus = (event: React.FocusEvent<MathfieldElement>) => {
129
+ const syntheticEvent = {
130
+ target: event.currentTarget,
131
+ };
132
+ onFocus && onFocus(syntheticEvent);
133
+ };
134
+
69
135
  const CheckboxInputGroup = () => {
70
136
  return (
71
137
  <div
@@ -270,6 +336,52 @@ const InputGroup = ({
270
336
  };
271
337
 
272
338
  const TextInputGroup = () => {
339
+ if (useMath) {
340
+ return (
341
+ <div className="my-1 relative">
342
+ {title ? (
343
+ <p className="text-md font-semibold pl-2 py-1 text-catchup-gray-400">
344
+ {title}
345
+ </p>
346
+ ) : null}
347
+ <div
348
+ className={`w-full border ${
349
+ errorText
350
+ ? "border-catchup-red shadow-error"
351
+ : "border-catchup-gray-100"
352
+ } rounded-catchup-large focus-within:border-catchup-blue-400 focus-within:shadow-input ${
353
+ disabled ? "bg-catchup-lighter-gray" : "bg-white"
354
+ }`}
355
+ >
356
+ <math-field
357
+ ref={mathFieldRef}
358
+ value={value || ""}
359
+ onInput={handleMathFieldChange}
360
+ onFocus={handleMathFieldFocus}
361
+ placeholder={errorText ? errorText : placeholder}
362
+ disabled={disabled}
363
+ virtual-keyboard-mode="onfocus"
364
+ smart-fence={true}
365
+ smart-mode={true}
366
+ smart-superscript={true}
367
+ style={{
368
+ fontSize: "16px",
369
+ padding: "8px 16px",
370
+ border: "none",
371
+ outline: "none",
372
+ width: "100%",
373
+ minHeight: "44px",
374
+ backgroundColor: disabled ? "#f5f5f5" : "transparent",
375
+ borderRadius: "16px",
376
+ fontFamily: "inherit",
377
+ color: disabled ? "#9ca3af" : "#000000",
378
+ }}
379
+ />
380
+ </div>
381
+ </div>
382
+ );
383
+ }
384
+
273
385
  return (
274
386
  <div className="my-1 relative">
275
387
  {title ? (
package/src/index.ts CHANGED
@@ -26,6 +26,7 @@ export { default as TrueFalseActivityContent } from "./components/activities/Tru
26
26
  export { default as ActivitySolutionContent } from "./components/activities/solution-content/ActivitySolutionContent";
27
27
  export { default as ActivityEvaluationRubricContent } from "./components/activities/evaluation-rubric-content/ActivityEvaluationRubricContent";
28
28
  export { default as ActivityPreviewByData } from "./components/activities/ActivityPreviewByData";
29
+ export { default as ActivityPreviewByAnswerData } from "./components/activities/ActivityPreviewByAnswerData";
29
30
 
30
31
  export { default as BlueVerticalDividerLine } from "./components/dividers/BlueVerticalDividerLine";
31
32
  export { default as DividerLine } from "./components/dividers/DividerLine";
@@ -16,6 +16,7 @@ export interface IInputGroupProps {
16
16
  useMinHeight?: boolean;
17
17
  disabled?: boolean;
18
18
  limit?: number;
19
+ useMath?: boolean;
19
20
  }
20
21
 
21
22
  export interface ILeftTextRightInputGroupProps {