@pie-lib/mask-markup 3.0.4-next.31 → 3.0.4-next.32
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/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/choices/choice.d.ts +24 -0
- package/dist/choices/choice.js +77 -0
- package/dist/choices/index.d.ts +25 -0
- package/dist/choices/index.js +49 -0
- package/dist/componentize.d.ts +12 -0
- package/dist/componentize.js +4 -0
- package/dist/components/blank.d.ts +39 -0
- package/dist/components/blank.js +240 -0
- package/dist/components/correct-input.d.ts +11 -0
- package/dist/components/dropdown.d.ts +37 -0
- package/dist/components/dropdown.js +320 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/constructed-response.d.ts +44 -0
- package/dist/constructed-response.js +55 -0
- package/dist/customizable.d.ts +43 -0
- package/dist/customizable.js +8 -0
- package/dist/drag-in-the-blank.d.ts +37 -0
- package/dist/drag-in-the-blank.js +164 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7 -0
- package/dist/inline-dropdown.d.ts +44 -0
- package/dist/inline-dropdown.js +24 -0
- package/dist/mask.d.ts +30 -0
- package/dist/mask.js +99 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
- package/dist/serialization.d.ts +34 -0
- package/dist/serialization.js +132 -0
- package/dist/with-mask.d.ts +55 -0
- package/dist/with-mask.js +45 -0
- package/package.json +39 -20
- package/CHANGELOG.json +0 -17
- package/CHANGELOG.md +0 -1256
- package/LICENSE.md +0 -5
- package/lib/choices/choice.js +0 -116
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -103
- package/lib/choices/index.js.map +0 -1
- package/lib/componentize.js +0 -21
- package/lib/componentize.js.map +0 -1
- package/lib/components/blank.js +0 -371
- package/lib/components/blank.js.map +0 -1
- package/lib/components/correct-input.js +0 -94
- package/lib/components/correct-input.js.map +0 -1
- package/lib/components/dropdown.js +0 -483
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/input.js +0 -50
- package/lib/components/input.js.map +0 -1
- package/lib/constructed-response.js +0 -101
- package/lib/constructed-response.js.map +0 -1
- package/lib/customizable.js +0 -42
- package/lib/customizable.js.map +0 -1
- package/lib/drag-in-the-blank.js +0 -254
- package/lib/drag-in-the-blank.js.map +0 -1
- package/lib/index.js +0 -55
- package/lib/index.js.map +0 -1
- package/lib/inline-dropdown.js +0 -40
- package/lib/inline-dropdown.js.map +0 -1
- package/lib/mask.js +0 -198
- package/lib/mask.js.map +0 -1
- package/lib/serialization.js +0 -261
- package/lib/serialization.js.map +0 -1
- package/lib/with-mask.js +0 -97
- package/lib/with-mask.js.map +0 -1
- package/src/__tests__/drag-in-the-blank.test.js +0 -111
- package/src/__tests__/index.test.js +0 -38
- package/src/__tests__/mask.test.js +0 -381
- package/src/__tests__/serialization.test.js +0 -54
- package/src/__tests__/utils.js +0 -1
- package/src/__tests__/with-mask.test.js +0 -76
- package/src/choices/__tests__/index.test.js +0 -75
- package/src/choices/choice.jsx +0 -97
- package/src/choices/index.jsx +0 -64
- package/src/componentize.js +0 -13
- package/src/components/__tests__/blank.test.js +0 -199
- package/src/components/__tests__/correct-input.test.js +0 -90
- package/src/components/__tests__/dropdown.test.js +0 -129
- package/src/components/__tests__/input.test.js +0 -102
- package/src/components/blank.jsx +0 -386
- package/src/components/correct-input.jsx +0 -82
- package/src/components/dropdown.jsx +0 -423
- package/src/components/input.jsx +0 -48
- package/src/constructed-response.jsx +0 -87
- package/src/customizable.jsx +0 -34
- package/src/drag-in-the-blank.jsx +0 -241
- package/src/index.js +0 -16
- package/src/inline-dropdown.jsx +0 -29
- package/src/mask.jsx +0 -172
- package/src/serialization.js +0 -260
- package/src/with-mask.jsx +0 -75
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { choice } from '../../__tests__/utils';
|
|
5
|
-
import Dropdown from '../dropdown';
|
|
6
|
-
|
|
7
|
-
describe('Dropdown', () => {
|
|
8
|
-
const onChange = jest.fn();
|
|
9
|
-
const defaultProps = {
|
|
10
|
-
onChange,
|
|
11
|
-
id: '1',
|
|
12
|
-
correct: false,
|
|
13
|
-
disabled: false,
|
|
14
|
-
value: 'Jumped',
|
|
15
|
-
choices: [choice('Jumped'), choice('Laughed'), choice('Smiled')],
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
onChange.mockClear();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('rendering', () => {
|
|
23
|
-
it('renders dropdown with default props', () => {
|
|
24
|
-
render(<Dropdown {...defaultProps} />);
|
|
25
|
-
const button = screen.getByRole('combobox');
|
|
26
|
-
expect(button).toBeInTheDocument();
|
|
27
|
-
// Button displays the selected value
|
|
28
|
-
expect(button).toHaveTextContent('Jumped');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('renders with all choices as options when opened', async () => {
|
|
32
|
-
const user = userEvent.setup();
|
|
33
|
-
render(<Dropdown {...defaultProps} />);
|
|
34
|
-
|
|
35
|
-
const button = screen.getByRole('combobox');
|
|
36
|
-
await user.click(button);
|
|
37
|
-
|
|
38
|
-
// Options should now be visible - find them by role
|
|
39
|
-
const options = screen.getAllByRole('option');
|
|
40
|
-
expect(options).toHaveLength(3);
|
|
41
|
-
// Verify the text content of options using specific elements
|
|
42
|
-
expect(options[0]).toHaveTextContent('Jumped');
|
|
43
|
-
expect(options[1]).toHaveTextContent('Laughed');
|
|
44
|
-
expect(options[2]).toHaveTextContent('Smiled');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('focuses the selected option when the menu opens', async () => {
|
|
48
|
-
const user = userEvent.setup();
|
|
49
|
-
render(<Dropdown {...defaultProps} />);
|
|
50
|
-
|
|
51
|
-
const button = screen.getByRole('combobox');
|
|
52
|
-
await user.click(button);
|
|
53
|
-
|
|
54
|
-
await waitFor(() => {
|
|
55
|
-
expect(document.getElementById('dropdown-option-1-0')).toHaveFocus();
|
|
56
|
-
});
|
|
57
|
-
expect(button).toHaveAttribute('aria-activedescendant', 'dropdown-option-1-0');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('focuses a non-first selected option when the menu opens', async () => {
|
|
61
|
-
const user = userEvent.setup();
|
|
62
|
-
render(<Dropdown {...defaultProps} value="Laughed" />);
|
|
63
|
-
|
|
64
|
-
const button = screen.getByRole('combobox');
|
|
65
|
-
await user.click(button);
|
|
66
|
-
|
|
67
|
-
await waitFor(() => {
|
|
68
|
-
expect(document.getElementById('dropdown-option-1-1')).toHaveFocus();
|
|
69
|
-
});
|
|
70
|
-
expect(button).toHaveAttribute('aria-activedescendant', 'dropdown-option-1-1');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('does not highlight an option when no value is selected', async () => {
|
|
74
|
-
const user = userEvent.setup();
|
|
75
|
-
render(<Dropdown {...defaultProps} value={undefined} />);
|
|
76
|
-
|
|
77
|
-
const button = screen.getByRole('combobox');
|
|
78
|
-
await user.click(button);
|
|
79
|
-
|
|
80
|
-
expect(button).not.toHaveAttribute('aria-activedescendant');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('renders as disabled when disabled prop is true', () => {
|
|
84
|
-
render(<Dropdown {...defaultProps} disabled={true} />);
|
|
85
|
-
const button = screen.getByRole('combobox');
|
|
86
|
-
expect(button).toBeDisabled();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('shows correct state when correct is true', () => {
|
|
90
|
-
const { container } = render(<Dropdown {...defaultProps} correct={true} />);
|
|
91
|
-
const button = screen.getByRole('combobox');
|
|
92
|
-
expect(button).toBeInTheDocument();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('user interactions', () => {
|
|
97
|
-
it('calls onChange when user selects a different option', async () => {
|
|
98
|
-
const user = userEvent.setup();
|
|
99
|
-
render(<Dropdown {...defaultProps} />);
|
|
100
|
-
|
|
101
|
-
// Click button to open menu
|
|
102
|
-
const button = screen.getByRole('combobox');
|
|
103
|
-
await user.click(button);
|
|
104
|
-
|
|
105
|
-
// Find the option by getting all options and selecting the one with "Laughed" text
|
|
106
|
-
const options = screen.getAllByRole('option');
|
|
107
|
-
const laughedOption = options.find((opt) => opt.textContent.includes('Laughed'));
|
|
108
|
-
await user.click(laughedOption);
|
|
109
|
-
|
|
110
|
-
expect(onChange).toHaveBeenCalledWith('1', 'Laughed');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('calls onChange with correct value', async () => {
|
|
114
|
-
const user = userEvent.setup();
|
|
115
|
-
render(<Dropdown {...defaultProps} />);
|
|
116
|
-
|
|
117
|
-
// Click button to open menu
|
|
118
|
-
const button = screen.getByRole('combobox');
|
|
119
|
-
await user.click(button);
|
|
120
|
-
|
|
121
|
-
// Find the option by getting all options and selecting the one with "Smiled" text
|
|
122
|
-
const options = screen.getAllByRole('option');
|
|
123
|
-
const smiledOption = options.find((opt) => opt.textContent.includes('Smiled'));
|
|
124
|
-
await user.click(smiledOption);
|
|
125
|
-
|
|
126
|
-
expect(onChange).toHaveBeenCalledWith('1', 'Smiled');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import Input from '../input';
|
|
5
|
-
|
|
6
|
-
// Mock CorrectInput to simplify testing
|
|
7
|
-
jest.mock('../correct-input', () => {
|
|
8
|
-
return function CorrectInput({ value, onChange, disabled, correct, variant }) {
|
|
9
|
-
return (
|
|
10
|
-
<input
|
|
11
|
-
data-testid="correct-input"
|
|
12
|
-
value={value || ''}
|
|
13
|
-
onChange={onChange}
|
|
14
|
-
disabled={disabled}
|
|
15
|
-
data-correct={correct}
|
|
16
|
-
data-variant={variant}
|
|
17
|
-
/>
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('Input', () => {
|
|
23
|
-
const onChange = jest.fn();
|
|
24
|
-
const defaultProps = {
|
|
25
|
-
disabled: false,
|
|
26
|
-
correct: false,
|
|
27
|
-
value: 'Cow',
|
|
28
|
-
id: '1',
|
|
29
|
-
onChange,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
onChange.mockClear();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('rendering', () => {
|
|
37
|
-
it('renders with default props', () => {
|
|
38
|
-
render(<Input {...defaultProps} />);
|
|
39
|
-
const input = screen.getByTestId('correct-input');
|
|
40
|
-
|
|
41
|
-
expect(input).toBeInTheDocument();
|
|
42
|
-
expect(input).toHaveValue('Cow');
|
|
43
|
-
expect(input).not.toBeDisabled();
|
|
44
|
-
expect(input).toHaveAttribute('data-correct', 'false');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('renders as disabled when disabled prop is true', () => {
|
|
48
|
-
render(<Input {...defaultProps} disabled={true} />);
|
|
49
|
-
const input = screen.getByTestId('correct-input');
|
|
50
|
-
|
|
51
|
-
expect(input).toBeDisabled();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('renders with correct state', () => {
|
|
55
|
-
render(<Input {...defaultProps} correct={true} />);
|
|
56
|
-
const input = screen.getByTestId('correct-input');
|
|
57
|
-
|
|
58
|
-
expect(input).toHaveAttribute('data-correct', 'true');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('shows correct answer when showCorrectAnswer is true', () => {
|
|
62
|
-
render(<Input {...defaultProps} showCorrectAnswer={true} />);
|
|
63
|
-
const input = screen.getByTestId('correct-input');
|
|
64
|
-
|
|
65
|
-
expect(input).toHaveAttribute('data-correct', 'true');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('user interactions', () => {
|
|
70
|
-
it('calls onChange with id and value when user types', async () => {
|
|
71
|
-
const user = userEvent.setup();
|
|
72
|
-
render(<Input {...defaultProps} value="" />);
|
|
73
|
-
|
|
74
|
-
const input = screen.getByTestId('correct-input');
|
|
75
|
-
await user.type(input, '20');
|
|
76
|
-
|
|
77
|
-
// userEvent.type types character by character, so onChange is called for each character
|
|
78
|
-
expect(onChange).toHaveBeenCalled();
|
|
79
|
-
expect(onChange).toHaveBeenCalledTimes(2);
|
|
80
|
-
// Check the last call has both characters
|
|
81
|
-
expect(onChange).toHaveBeenLastCalledWith('1', '0');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('calls onChange with updated value', async () => {
|
|
85
|
-
const user = userEvent.setup();
|
|
86
|
-
render(<Input {...defaultProps} />);
|
|
87
|
-
|
|
88
|
-
const input = screen.getByTestId('correct-input');
|
|
89
|
-
await user.clear(input);
|
|
90
|
-
await user.type(input, 'New Value');
|
|
91
|
-
|
|
92
|
-
// userEvent.type types character by character
|
|
93
|
-
// After clear, we start with empty string, and each character is typed
|
|
94
|
-
// The last call should have the full accumulated value up to the last character
|
|
95
|
-
expect(onChange).toHaveBeenCalled();
|
|
96
|
-
// With clear + "New Value", onChange is called for clearing ("") and each typed character
|
|
97
|
-
// The value accumulated in the input element after typing will be "CowNew Value"
|
|
98
|
-
// because the component starts with value="Cow" and we clear then type
|
|
99
|
-
expect(onChange.mock.calls.length).toBeGreaterThan(0);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
package/src/components/blank.jsx
DELETED
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { renderMath } from '@pie-lib/math-rendering';
|
|
4
|
-
import debug from 'debug';
|
|
5
|
-
import { useDraggable, useDroppable } from '@dnd-kit/core';
|
|
6
|
-
import { CSS } from '@dnd-kit/utilities';
|
|
7
|
-
import { styled } from '@mui/material/styles';
|
|
8
|
-
import Chip from '@mui/material/Chip';
|
|
9
|
-
import classnames from 'classnames';
|
|
10
|
-
import { color } from '@pie-lib/render-ui';
|
|
11
|
-
import { grey } from '@mui/material/colors';
|
|
12
|
-
|
|
13
|
-
const log = debug('pie-lib:mask-markup:blank');
|
|
14
|
-
|
|
15
|
-
const StyledContent = styled('span')(({ dragged, over }) => ({
|
|
16
|
-
border: `solid 0px ${color.primary()}`,
|
|
17
|
-
minWidth: '200px',
|
|
18
|
-
touchAction: 'none',
|
|
19
|
-
overflow: 'hidden',
|
|
20
|
-
whiteSpace: 'nowrap',
|
|
21
|
-
opacity: 1,
|
|
22
|
-
...(over && {
|
|
23
|
-
whiteSpace: 'nowrap',
|
|
24
|
-
overflow: 'hidden',
|
|
25
|
-
}),
|
|
26
|
-
...(dragged && {
|
|
27
|
-
opacity: 0.5,
|
|
28
|
-
}),
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
const StyledChip = styled(Chip)(() => ({
|
|
32
|
-
backgroundColor: color.background(),
|
|
33
|
-
border: `2px dashed ${color.text()}`,
|
|
34
|
-
touchAction: 'none',
|
|
35
|
-
color: color.text(),
|
|
36
|
-
fontSize: 'inherit',
|
|
37
|
-
maxWidth: '374px',
|
|
38
|
-
position: 'relative',
|
|
39
|
-
borderRadius: '3px',
|
|
40
|
-
'&.over': {
|
|
41
|
-
whiteSpace: 'nowrap',
|
|
42
|
-
overflow: 'hidden',
|
|
43
|
-
},
|
|
44
|
-
'&.parentOver': {
|
|
45
|
-
border: `1px solid ${grey[500]}`,
|
|
46
|
-
backgroundColor: `${grey[300]}`,
|
|
47
|
-
},
|
|
48
|
-
'&.correct': {
|
|
49
|
-
border: `solid 1px ${color.correct()}`,
|
|
50
|
-
},
|
|
51
|
-
'&.incorrect': {
|
|
52
|
-
border: `solid 1px ${color.incorrect()}`,
|
|
53
|
-
},
|
|
54
|
-
'&.Mui-disabled': {
|
|
55
|
-
opacity: 1,
|
|
56
|
-
},
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
const StyledChipLabel = styled('span')(() => ({
|
|
60
|
-
whiteSpace: 'normal',
|
|
61
|
-
// Added for touch devices, for image content.
|
|
62
|
-
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
63
|
-
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
64
|
-
pointerEvents: 'none',
|
|
65
|
-
'& img': {
|
|
66
|
-
display: 'block',
|
|
67
|
-
padding: '2px 0',
|
|
68
|
-
},
|
|
69
|
-
// Remove default <p> margins to ensure consistent spacing across all wrapped content (p, span, div, math)
|
|
70
|
-
// Padding for top and bottom will instead be controlled by the container for consistent layout
|
|
71
|
-
// Ensures consistent behavior with pie-api-browser, where marginTop is already removed by a Bootstrap stylesheet
|
|
72
|
-
'& p': {
|
|
73
|
-
marginTop: '0',
|
|
74
|
-
marginBottom: '0',
|
|
75
|
-
},
|
|
76
|
-
'& mjx-frac': {
|
|
77
|
-
fontSize: '120% !important',
|
|
78
|
-
},
|
|
79
|
-
'&.over': {
|
|
80
|
-
whiteSpace: 'nowrap',
|
|
81
|
-
overflow: 'hidden',
|
|
82
|
-
},
|
|
83
|
-
'&.hidden': {
|
|
84
|
-
color: 'transparent',
|
|
85
|
-
opacity: 0,
|
|
86
|
-
},
|
|
87
|
-
'&.dragged': {
|
|
88
|
-
position: 'absolute',
|
|
89
|
-
left: 16,
|
|
90
|
-
maxWidth: '60px',
|
|
91
|
-
top: '50%',
|
|
92
|
-
transform: 'translateY(-50%)',
|
|
93
|
-
},
|
|
94
|
-
}));
|
|
95
|
-
|
|
96
|
-
function BlankContent({
|
|
97
|
-
disabled,
|
|
98
|
-
choice,
|
|
99
|
-
isOver,
|
|
100
|
-
isDragging,
|
|
101
|
-
dragItem,
|
|
102
|
-
correct,
|
|
103
|
-
emptyResponseAreaWidth,
|
|
104
|
-
emptyResponseAreaHeight,
|
|
105
|
-
}) {
|
|
106
|
-
const rootRef = useRef(null);
|
|
107
|
-
const spanRef = useRef(null);
|
|
108
|
-
const frozenRef = useRef(null); // to use during dragging to prevent flickering
|
|
109
|
-
const [dimensions, setDimensions] = useState({ height: 0, width: 0 });
|
|
110
|
-
|
|
111
|
-
const handleImageLoad = () => {
|
|
112
|
-
updateDimensions();
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const handleElements = () => {
|
|
116
|
-
const imageElement = spanRef.current?.querySelector('img');
|
|
117
|
-
if (imageElement) {
|
|
118
|
-
imageElement.onload = handleImageLoad;
|
|
119
|
-
} else {
|
|
120
|
-
setTimeout(() => {
|
|
121
|
-
updateDimensions();
|
|
122
|
-
}, 300);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const getMeasureNode = () => {
|
|
127
|
-
if (!spanRef.current) return null;
|
|
128
|
-
const mjx = spanRef.current.querySelector('mjx-container');
|
|
129
|
-
if (mjx && spanRef.current.parentElement) return spanRef.current.parentElement;
|
|
130
|
-
const img = spanRef.current.querySelector('img');
|
|
131
|
-
if (img) return img;
|
|
132
|
-
return spanRef.current;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const updateDimensions = () => {
|
|
136
|
-
if (spanRef.current && rootRef.current) {
|
|
137
|
-
// Temporarily set rootRef width to 'auto' for natural measurement
|
|
138
|
-
rootRef.current.style.width = 'auto';
|
|
139
|
-
rootRef.current.style.height = 'auto';
|
|
140
|
-
rootRef.current.offsetHeight;
|
|
141
|
-
|
|
142
|
-
const measureNode = getMeasureNode();
|
|
143
|
-
const node = measureNode || spanRef.current;
|
|
144
|
-
const rect = node.getBoundingClientRect();
|
|
145
|
-
const width = rect.width || node.offsetWidth || 0;
|
|
146
|
-
const height = Math.max(
|
|
147
|
-
rect.height || 0,
|
|
148
|
-
node.offsetHeight || 0,
|
|
149
|
-
node.scrollHeight || 0,
|
|
150
|
-
spanRef.current.scrollHeight || 0,
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
const widthWithPadding = width + 24; // 12px padding on each side
|
|
154
|
-
const heightWithPadding = height + 24; // 12px padding on top and bottom
|
|
155
|
-
|
|
156
|
-
const responseAreaWidth = parseFloat(emptyResponseAreaWidth) || 0;
|
|
157
|
-
const responseAreaHeight = parseFloat(emptyResponseAreaHeight) || 0;
|
|
158
|
-
|
|
159
|
-
const adjustedWidth = widthWithPadding <= responseAreaWidth ? responseAreaWidth : widthWithPadding;
|
|
160
|
-
const adjustedHeight = heightWithPadding <= responseAreaHeight ? responseAreaHeight : heightWithPadding;
|
|
161
|
-
|
|
162
|
-
setDimensions((prevState) => ({
|
|
163
|
-
width: adjustedWidth > responseAreaWidth ? adjustedWidth : prevState.width,
|
|
164
|
-
height: adjustedHeight > responseAreaHeight ? adjustedHeight : prevState.height,
|
|
165
|
-
}));
|
|
166
|
-
|
|
167
|
-
rootRef.current.style.width = `${adjustedWidth}px`;
|
|
168
|
-
rootRef.current.style.height = `${adjustedHeight}px`;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const getRootDimensions = () => {
|
|
173
|
-
// Handle potential non-numeric values
|
|
174
|
-
const responseAreaWidth = !isNaN(parseFloat(emptyResponseAreaWidth)) ? parseFloat(emptyResponseAreaWidth) : 0;
|
|
175
|
-
const responseAreaHeight = !isNaN(parseFloat(emptyResponseAreaHeight)) ? parseFloat(emptyResponseAreaHeight) : 0;
|
|
176
|
-
|
|
177
|
-
const rootStyle = {
|
|
178
|
-
height: dimensions.height || responseAreaHeight,
|
|
179
|
-
width: dimensions.width || responseAreaWidth,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
// add minWidth, minHeight if width and height are not defined
|
|
183
|
-
return {
|
|
184
|
-
...rootStyle,
|
|
185
|
-
...(responseAreaWidth ? {} : { minWidth: 90 }),
|
|
186
|
-
...(responseAreaHeight ? {} : { minHeight: 32 }),
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
useEffect(() => {
|
|
191
|
-
handleElements();
|
|
192
|
-
}, []);
|
|
193
|
-
|
|
194
|
-
// Render math for the placeholder/preview when dragging over
|
|
195
|
-
useEffect(() => {
|
|
196
|
-
if (rootRef.current) {
|
|
197
|
-
renderMath(rootRef.current);
|
|
198
|
-
}
|
|
199
|
-
}, [correct, isOver, dragItem?.choice?.value]);
|
|
200
|
-
|
|
201
|
-
useEffect(() => {
|
|
202
|
-
if (!choice) {
|
|
203
|
-
setDimensions({ height: 0, width: 0 });
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
handleElements();
|
|
207
|
-
}, [choice]);
|
|
208
|
-
|
|
209
|
-
useEffect(() => {
|
|
210
|
-
if (!isOver && !isDragging) {
|
|
211
|
-
frozenRef.current = {
|
|
212
|
-
width: rootRef.current.offsetWidth,
|
|
213
|
-
height: rootRef.current.offsetHeight,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
}, [choice, isOver, isDragging]);
|
|
217
|
-
|
|
218
|
-
const draggedLabel = dragItem && isOver && dragItem.choice && dragItem.choice.value;
|
|
219
|
-
const label = choice && choice.value;
|
|
220
|
-
const style =
|
|
221
|
-
isOver || isDragging
|
|
222
|
-
? {
|
|
223
|
-
width: frozenRef.current?.width,
|
|
224
|
-
height: frozenRef.current?.height,
|
|
225
|
-
}
|
|
226
|
-
: getRootDimensions();
|
|
227
|
-
|
|
228
|
-
return (
|
|
229
|
-
<StyledChip
|
|
230
|
-
clickable={false}
|
|
231
|
-
disabled={disabled}
|
|
232
|
-
ref={rootRef}
|
|
233
|
-
component="span"
|
|
234
|
-
label={
|
|
235
|
-
<React.Fragment>
|
|
236
|
-
<StyledChipLabel
|
|
237
|
-
ref={spanRef}
|
|
238
|
-
draggable={true}
|
|
239
|
-
className={classnames({
|
|
240
|
-
over: isOver,
|
|
241
|
-
hidden: draggedLabel,
|
|
242
|
-
})}
|
|
243
|
-
dangerouslySetInnerHTML={{ __html: label || '' }}
|
|
244
|
-
/>
|
|
245
|
-
{draggedLabel && (
|
|
246
|
-
<StyledChipLabel
|
|
247
|
-
draggable={true}
|
|
248
|
-
className={classnames({
|
|
249
|
-
over: isOver,
|
|
250
|
-
dragged: true,
|
|
251
|
-
})}
|
|
252
|
-
dangerouslySetInnerHTML={{ __html: draggedLabel || '' }}
|
|
253
|
-
/>
|
|
254
|
-
)}
|
|
255
|
-
</React.Fragment>
|
|
256
|
-
}
|
|
257
|
-
className={classnames({
|
|
258
|
-
over: isOver,
|
|
259
|
-
parentOver: isOver,
|
|
260
|
-
correct: correct !== undefined && correct,
|
|
261
|
-
incorrect: correct !== undefined && !correct,
|
|
262
|
-
})}
|
|
263
|
-
variant={disabled ? 'outlined' : undefined}
|
|
264
|
-
style={style}
|
|
265
|
-
/>
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
BlankContent.defaultProps = {
|
|
270
|
-
emptyResponseAreaWidth: 0,
|
|
271
|
-
emptyResponseAreaHeight: 0,
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
BlankContent.propTypes = {
|
|
275
|
-
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
276
|
-
disabled: PropTypes.bool,
|
|
277
|
-
duplicates: PropTypes.bool,
|
|
278
|
-
choice: PropTypes.object,
|
|
279
|
-
isOver: PropTypes.bool,
|
|
280
|
-
dragItem: PropTypes.object,
|
|
281
|
-
correct: PropTypes.bool,
|
|
282
|
-
onChange: PropTypes.func,
|
|
283
|
-
emptyResponseAreaWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
284
|
-
emptyResponseAreaHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
285
|
-
instanceId: PropTypes.string,
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
// New functional component using @dnd-kit hooks
|
|
289
|
-
function DragDropBlank({
|
|
290
|
-
id,
|
|
291
|
-
disabled,
|
|
292
|
-
duplicates,
|
|
293
|
-
choice,
|
|
294
|
-
correct,
|
|
295
|
-
onChange,
|
|
296
|
-
emptyResponseAreaWidth,
|
|
297
|
-
emptyResponseAreaHeight,
|
|
298
|
-
instanceId,
|
|
299
|
-
}) {
|
|
300
|
-
// Setup draggable functionality
|
|
301
|
-
const {
|
|
302
|
-
attributes: dragAttributes,
|
|
303
|
-
listeners: dragListeners,
|
|
304
|
-
setNodeRef: setDragNodeRef,
|
|
305
|
-
transform,
|
|
306
|
-
isDragging,
|
|
307
|
-
} = useDraggable({
|
|
308
|
-
id: `mask-blank-drag-${id}`,
|
|
309
|
-
disabled: disabled || !choice,
|
|
310
|
-
data: {
|
|
311
|
-
id: id,
|
|
312
|
-
choice: choice,
|
|
313
|
-
instanceId: instanceId,
|
|
314
|
-
fromChoice: false, // This is from a blank, not from choices
|
|
315
|
-
type: 'MaskBlank',
|
|
316
|
-
},
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
// Setup droppable functionality
|
|
320
|
-
const {
|
|
321
|
-
setNodeRef: setDropNodeRef,
|
|
322
|
-
isOver,
|
|
323
|
-
active: dragItem,
|
|
324
|
-
} = useDroppable({
|
|
325
|
-
id: `mask-blank-drop-${id}`,
|
|
326
|
-
data: {
|
|
327
|
-
id: id,
|
|
328
|
-
accepts: ['MaskBlank'],
|
|
329
|
-
instanceId: instanceId,
|
|
330
|
-
},
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
// Combine refs for both drag and drop
|
|
334
|
-
const setNodeRef = (node) => {
|
|
335
|
-
setDragNodeRef(node);
|
|
336
|
-
setDropNodeRef(node);
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
const style = {
|
|
340
|
-
transform: CSS.Translate.toString(transform),
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
return (
|
|
344
|
-
<StyledContent
|
|
345
|
-
ref={setNodeRef}
|
|
346
|
-
style={style}
|
|
347
|
-
dragged={isDragging}
|
|
348
|
-
over={isOver}
|
|
349
|
-
{...dragAttributes}
|
|
350
|
-
{...dragListeners}
|
|
351
|
-
>
|
|
352
|
-
<BlankContent
|
|
353
|
-
id={id}
|
|
354
|
-
disabled={disabled}
|
|
355
|
-
duplicates={duplicates}
|
|
356
|
-
choice={choice}
|
|
357
|
-
isOver={isOver}
|
|
358
|
-
dragItem={dragItem?.data?.current}
|
|
359
|
-
correct={correct}
|
|
360
|
-
onChange={onChange}
|
|
361
|
-
emptyResponseAreaWidth={emptyResponseAreaWidth}
|
|
362
|
-
emptyResponseAreaHeight={emptyResponseAreaHeight}
|
|
363
|
-
instanceId={instanceId}
|
|
364
|
-
/>
|
|
365
|
-
</StyledContent>
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
DragDropBlank.defaultProps = {
|
|
370
|
-
emptyResponseAreaWidth: 0,
|
|
371
|
-
emptyResponseAreaHeight: 0,
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
DragDropBlank.propTypes = {
|
|
375
|
-
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
376
|
-
disabled: PropTypes.bool,
|
|
377
|
-
duplicates: PropTypes.bool,
|
|
378
|
-
choice: PropTypes.object,
|
|
379
|
-
correct: PropTypes.bool,
|
|
380
|
-
onChange: PropTypes.func,
|
|
381
|
-
emptyResponseAreaWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
382
|
-
emptyResponseAreaHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
383
|
-
instanceId: PropTypes.string,
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
export default DragDropBlank;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import OutlinedInput from '@mui/material/OutlinedInput';
|
|
3
|
-
import classnames from 'classnames';
|
|
4
|
-
import { styled } from '@mui/material/styles';
|
|
5
|
-
import { color } from '@pie-lib/render-ui';
|
|
6
|
-
|
|
7
|
-
const StyledOutlinedInput = styled(OutlinedInput)(() => ({
|
|
8
|
-
padding: '2px',
|
|
9
|
-
borderRadius: '4px',
|
|
10
|
-
fontSize: 'inherit',
|
|
11
|
-
display: 'inline-block',
|
|
12
|
-
verticalAlign: 'middle',
|
|
13
|
-
'& fieldset': {
|
|
14
|
-
border: 0,
|
|
15
|
-
},
|
|
16
|
-
'& .MuiOutlinedInput-input': {
|
|
17
|
-
color: color.text(),
|
|
18
|
-
backgroundColor: color.background(),
|
|
19
|
-
borderRadius: '4px !important',
|
|
20
|
-
borderWidth: '1px',
|
|
21
|
-
borderStyle: 'solid',
|
|
22
|
-
padding: '10px 20px 10px 10px',
|
|
23
|
-
'&:disabled': {
|
|
24
|
-
opacity: 0.8,
|
|
25
|
-
cursor: 'not-allowed !important',
|
|
26
|
-
},
|
|
27
|
-
'&:hover': {
|
|
28
|
-
borderColor: color.primary(),
|
|
29
|
-
'&:disabled': {
|
|
30
|
-
borderColor: 'initial',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
'&.Mui-focused': {
|
|
34
|
-
borderColor: color.primaryDark(),
|
|
35
|
-
},
|
|
36
|
-
'&.crInput': {
|
|
37
|
-
padding: '8px !important',
|
|
38
|
-
},
|
|
39
|
-
'&.correct': {
|
|
40
|
-
borderColor: `${color.correct()} !important`,
|
|
41
|
-
},
|
|
42
|
-
'&.incorrect': {
|
|
43
|
-
borderColor: `${color.incorrect()} !important`,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
const CorrectInput = (props) => {
|
|
49
|
-
const { correct, charactersLimit, disabled, isBox, isConstructedResponse, width, spellCheck, ...rest } = props;
|
|
50
|
-
|
|
51
|
-
const label = typeof correct === 'boolean' ? (correct ? 'correct' : 'incorrect') : undefined;
|
|
52
|
-
const inputProps = charactersLimit
|
|
53
|
-
? { maxLength: charactersLimit, 'aria-label': 'Enter answer' }
|
|
54
|
-
: { 'aria-label': 'Enter answer' };
|
|
55
|
-
|
|
56
|
-
if (width) {
|
|
57
|
-
inputProps.style = {
|
|
58
|
-
width: `${width + Math.round(width / 10) + 1}ch`, // added some extra space for capital letters
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<StyledOutlinedInput
|
|
64
|
-
className={classnames({
|
|
65
|
-
disabledInput: disabled,
|
|
66
|
-
box: isBox,
|
|
67
|
-
})}
|
|
68
|
-
classes={{
|
|
69
|
-
input: classnames({
|
|
70
|
-
[label]: label,
|
|
71
|
-
crInput: isConstructedResponse,
|
|
72
|
-
}),
|
|
73
|
-
}}
|
|
74
|
-
inputProps={inputProps}
|
|
75
|
-
disabled={disabled}
|
|
76
|
-
spellCheck={spellCheck}
|
|
77
|
-
{...rest}
|
|
78
|
-
/>
|
|
79
|
-
);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export default CorrectInput;
|