@pie-lib/mask-markup 3.1.3 → 4.0.0-next.37
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 +28 -0
- package/dist/choices/choice.js +92 -0
- package/dist/choices/index.d.ts +29 -0
- package/dist/choices/index.js +59 -0
- package/dist/componentize.d.ts +12 -0
- package/dist/componentize.js +4 -0
- package/dist/components/blank.d.ts +45 -0
- package/dist/components/blank.js +273 -0
- package/dist/components/correct-input.d.ts +11 -0
- package/dist/components/dropdown.d.ts +37 -0
- package/dist/components/dropdown.js +311 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/constructed-response.d.ts +44 -0
- package/dist/constructed-response.js +56 -0
- package/dist/customizable.d.ts +43 -0
- package/dist/customizable.js +8 -0
- package/dist/drag-in-the-blank.d.ts +47 -0
- package/dist/drag-in-the-blank.js +220 -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/keyboard-coordinates.d.ts +25 -0
- package/dist/keyboard-coordinates.js +49 -0
- package/dist/mask.d.ts +30 -0
- package/dist/mask.js +95 -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 +35 -19
- package/CHANGELOG.json +0 -17
- package/CHANGELOG.md +0 -1353
- package/LICENSE.md +0 -5
- package/lib/choices/choice.js +0 -138
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -126
- 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 -489
- 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 -480
- 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 -363
- 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/keyboard-coordinates.js +0 -156
- package/lib/keyboard-coordinates.js.map +0 -1
- package/lib/mask.js +0 -203
- 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 -256
- package/src/__tests__/index.test.js +0 -38
- package/src/__tests__/keyboard-coordinates.test.js +0 -202
- package/src/__tests__/mask.test.js +0 -479
- 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 -212
- package/src/choices/choice.jsx +0 -113
- package/src/choices/index.jsx +0 -88
- package/src/componentize.js +0 -13
- package/src/components/__tests__/blank.test.js +0 -413
- 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 -504
- package/src/components/correct-input.jsx +0 -82
- package/src/components/dropdown.jsx +0 -421
- 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 -351
- package/src/index.js +0 -16
- package/src/inline-dropdown.jsx +0 -29
- package/src/keyboard-coordinates.js +0 -147
- package/src/mask.jsx +0 -174
- package/src/serialization.js +0 -260
- package/src/with-mask.jsx +0 -75
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
-
import Choice from '../choice';
|
|
4
|
-
import { choice } from '../../__tests__/utils';
|
|
5
|
-
import Choices from '../index';
|
|
6
|
-
|
|
7
|
-
// Collect the CSS rules emotion/MUI injected into the document (jsdom uses insertRule).
|
|
8
|
-
const collectEmotionRules = () => {
|
|
9
|
-
const rules = [];
|
|
10
|
-
for (const sheet of Array.from(document.styleSheets)) {
|
|
11
|
-
try {
|
|
12
|
-
for (const rule of Array.from(sheet.cssRules)) {
|
|
13
|
-
rules.push(rule.cssText);
|
|
14
|
-
}
|
|
15
|
-
} catch (e) {
|
|
16
|
-
/* inaccessible stylesheet */
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return rules;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// Mock @dnd-kit hooks to avoid DndContext requirement
|
|
23
|
-
jest.mock('@dnd-kit/core', () => ({
|
|
24
|
-
useDraggable: jest.fn(() => ({
|
|
25
|
-
attributes: {},
|
|
26
|
-
listeners: {},
|
|
27
|
-
setNodeRef: jest.fn(),
|
|
28
|
-
isDragging: false,
|
|
29
|
-
})),
|
|
30
|
-
useDroppable: jest.fn(() => ({
|
|
31
|
-
setNodeRef: jest.fn(),
|
|
32
|
-
isOver: false,
|
|
33
|
-
active: null,
|
|
34
|
-
})),
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
describe('index', () => {
|
|
38
|
-
describe('Choices', () => {
|
|
39
|
-
const defaultProps = {
|
|
40
|
-
disabled: false,
|
|
41
|
-
choices: [choice('Jumped', '0'), choice('Laughed', '1'), choice('Spoon', '2')],
|
|
42
|
-
choicePosition: 'below',
|
|
43
|
-
instanceId: 'test-instance',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
it('renders correctly with default props', () => {
|
|
47
|
-
const { container } = render(<Choices {...defaultProps} />);
|
|
48
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
49
|
-
expect(screen.getByText('Jumped')).toBeInTheDocument();
|
|
50
|
-
expect(screen.getByText('Laughed')).toBeInTheDocument();
|
|
51
|
-
expect(screen.getByText('Spoon')).toBeInTheDocument();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('renders correctly with disabled prop as true', () => {
|
|
55
|
-
const { container } = render(<Choices {...defaultProps} disabled={true} />);
|
|
56
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('renders without duplicates', () => {
|
|
60
|
-
const { container } = render(<Choices {...defaultProps} duplicates={undefined} value={{ 0: '0', 1: '1' }} />);
|
|
61
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('renders with duplicates', () => {
|
|
65
|
-
const { container } = render(<Choices {...defaultProps} duplicates={true} value={{ 0: '0', 1: '1' }} />);
|
|
66
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('click-to-place into the pool', () => {
|
|
70
|
-
it('places the selection into the pool when clicking the pool background', () => {
|
|
71
|
-
const onPlacementClick = jest.fn();
|
|
72
|
-
const selectedItem = { id: 'some-blank', fromChoice: false, type: 'MaskBlank' };
|
|
73
|
-
const { container } = render(
|
|
74
|
-
<Choices {...defaultProps} selectedItem={selectedItem} onPlacementClick={onPlacementClick} />,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
fireEvent.click(container.firstChild);
|
|
78
|
-
|
|
79
|
-
expect(onPlacementClick).toHaveBeenCalledWith(undefined);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('does nothing when clicking the pool background with nothing selected', () => {
|
|
83
|
-
const onPlacementClick = jest.fn();
|
|
84
|
-
const { container } = render(<Choices {...defaultProps} onPlacementClick={onPlacementClick} />);
|
|
85
|
-
|
|
86
|
-
fireEvent.click(container.firstChild);
|
|
87
|
-
|
|
88
|
-
expect(onPlacementClick).not.toHaveBeenCalled();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('clicking a specific choice selects it, not the pool background handler', () => {
|
|
92
|
-
const onPlacementClick = jest.fn();
|
|
93
|
-
const onSelectClick = jest.fn();
|
|
94
|
-
const selectedItem = { id: 'some-blank', fromChoice: false, type: 'MaskBlank' };
|
|
95
|
-
render(
|
|
96
|
-
<Choices
|
|
97
|
-
{...defaultProps}
|
|
98
|
-
selectedItem={selectedItem}
|
|
99
|
-
onSelectClick={onSelectClick}
|
|
100
|
-
onPlacementClick={onPlacementClick}
|
|
101
|
-
/>,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
fireEvent.click(screen.getByText('Jumped'));
|
|
105
|
-
|
|
106
|
-
expect(onSelectClick).toHaveBeenCalled();
|
|
107
|
-
expect(onPlacementClick).not.toHaveBeenCalled();
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe('Choice', () => {
|
|
113
|
-
const defaultProps = {
|
|
114
|
-
disabled: false,
|
|
115
|
-
choice: choice('Label', '1'),
|
|
116
|
-
instanceId: 'test-instance',
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
describe('render', () => {
|
|
120
|
-
it('renders correctly with default props', () => {
|
|
121
|
-
const { container } = render(<Choice {...defaultProps} />);
|
|
122
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
123
|
-
expect(screen.getByText('Label')).toBeInTheDocument();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('renders correctly with disabled prop as true', () => {
|
|
127
|
-
const { container } = render(<Choice {...defaultProps} disabled={true} />);
|
|
128
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('fraction math styling', () => {
|
|
133
|
-
it('enlarges numerator/denominator digits adjacent to a fraction to 120%', () => {
|
|
134
|
-
render(<Choice {...defaultProps} />);
|
|
135
|
-
// The new rule targets mjx-mn digits that sit next to an mjx-mfrac.
|
|
136
|
-
const rule = collectEmotionRules().find((r) => r.includes('mjx-mn') && r.includes('mjx-mfrac'));
|
|
137
|
-
expect(rule).toBeDefined();
|
|
138
|
-
expect(rule).toMatch(/mjx-mn:has\(~\s*mjx-mfrac\)/);
|
|
139
|
-
expect(rule).toMatch(/mjx-mfrac\s*~\s*mjx-mn/);
|
|
140
|
-
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('keeps the existing mjx-frac 120% rule', () => {
|
|
144
|
-
render(<Choice {...defaultProps} />);
|
|
145
|
-
const rule = collectEmotionRules().find((r) => /(^|[^-])mjx-frac/.test(r) && !r.includes('mjx-mfrac'));
|
|
146
|
-
expect(rule).toBeDefined();
|
|
147
|
-
expect(rule).toMatch(/font-size:\s*120%\s*!important/i);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('click-to-select', () => {
|
|
152
|
-
it('selects this choice on click when nothing else is selected', () => {
|
|
153
|
-
const onSelectClick = jest.fn();
|
|
154
|
-
const { container } = render(<Choice {...defaultProps} selectedItem={null} onSelectClick={onSelectClick} />);
|
|
155
|
-
|
|
156
|
-
fireEvent.click(container.firstChild);
|
|
157
|
-
|
|
158
|
-
expect(onSelectClick).toHaveBeenCalledWith({
|
|
159
|
-
choice: defaultProps.choice,
|
|
160
|
-
instanceId: defaultProps.instanceId,
|
|
161
|
-
fromChoice: true,
|
|
162
|
-
type: 'MaskBlank',
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('toggles off (calls onSelectClick again) when clicking the already-selected choice', () => {
|
|
167
|
-
const onSelectClick = jest.fn();
|
|
168
|
-
const selectedItem = { choice: defaultProps.choice, instanceId: defaultProps.instanceId, fromChoice: true, type: 'MaskBlank' };
|
|
169
|
-
const { container } = render(
|
|
170
|
-
<Choice {...defaultProps} selectedItem={selectedItem} onSelectClick={onSelectClick} />,
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
fireEvent.click(container.firstChild);
|
|
174
|
-
|
|
175
|
-
expect(onSelectClick).toHaveBeenCalledWith({
|
|
176
|
-
choice: defaultProps.choice,
|
|
177
|
-
instanceId: defaultProps.instanceId,
|
|
178
|
-
fromChoice: true,
|
|
179
|
-
type: 'MaskBlank',
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('selects this choice even while a different item is already selected (pool items are never placement targets)', () => {
|
|
184
|
-
const onSelectClick = jest.fn();
|
|
185
|
-
const selectedItem = { id: 'some-blank', fromChoice: false, type: 'MaskBlank' };
|
|
186
|
-
const { container } = render(
|
|
187
|
-
<Choice {...defaultProps} selectedItem={selectedItem} onSelectClick={onSelectClick} />,
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
fireEvent.click(container.firstChild);
|
|
191
|
-
|
|
192
|
-
expect(onSelectClick).toHaveBeenCalledWith({
|
|
193
|
-
choice: defaultProps.choice,
|
|
194
|
-
instanceId: defaultProps.instanceId,
|
|
195
|
-
fromChoice: true,
|
|
196
|
-
type: 'MaskBlank',
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('does nothing on click when disabled', () => {
|
|
201
|
-
const onSelectClick = jest.fn();
|
|
202
|
-
const { container } = render(
|
|
203
|
-
<Choice {...defaultProps} disabled={true} selectedItem={null} onSelectClick={onSelectClick} />,
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
fireEvent.click(container.firstChild);
|
|
207
|
-
|
|
208
|
-
expect(onSelectClick).not.toHaveBeenCalled();
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
});
|
package/src/choices/choice.jsx
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { useDraggable } from '@dnd-kit/core';
|
|
4
|
-
import { styled } from '@mui/material/styles';
|
|
5
|
-
import Chip from '@mui/material/Chip';
|
|
6
|
-
import { renderMath } from '@pie-lib/math-rendering';
|
|
7
|
-
import { color } from '@pie-lib/render-ui';
|
|
8
|
-
|
|
9
|
-
export const DRAG_TYPE = 'MaskBlank';
|
|
10
|
-
|
|
11
|
-
const StyledChoice = styled('span')(({ theme, disabled, selected }) => ({
|
|
12
|
-
border: `solid 0px ${theme.palette.primary.main}`,
|
|
13
|
-
margin: theme.spacing(0.5),
|
|
14
|
-
transform: 'translate(0, 0)',
|
|
15
|
-
display: 'inline-flex',
|
|
16
|
-
opacity: selected ? 0.7 : 1,
|
|
17
|
-
...(disabled && {}),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
const StyledChip = styled(Chip)(() => ({
|
|
21
|
-
backgroundColor: color.white(),
|
|
22
|
-
border: `1px solid ${color.text()}`,
|
|
23
|
-
color: color.text(),
|
|
24
|
-
alignItems: 'center',
|
|
25
|
-
display: 'inline-flex',
|
|
26
|
-
height: 'initial',
|
|
27
|
-
minHeight: '32px',
|
|
28
|
-
fontSize: 'inherit',
|
|
29
|
-
whiteSpace: 'pre-wrap',
|
|
30
|
-
maxWidth: '374px',
|
|
31
|
-
// Added for touch devices, for image content.
|
|
32
|
-
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
33
|
-
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
34
|
-
pointerEvents: 'none',
|
|
35
|
-
borderRadius: '3px',
|
|
36
|
-
paddingTop: '12px',
|
|
37
|
-
paddingBottom: '12px',
|
|
38
|
-
|
|
39
|
-
'&.Mui-disabled': {
|
|
40
|
-
opacity: 1,
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
const StyledChipLabel = styled('span')(() => ({
|
|
45
|
-
whiteSpace: 'normal',
|
|
46
|
-
'& img': {
|
|
47
|
-
display: 'block',
|
|
48
|
-
padding: '2px 0',
|
|
49
|
-
},
|
|
50
|
-
'& mjx-frac': {
|
|
51
|
-
fontSize: '120% !important',
|
|
52
|
-
},
|
|
53
|
-
'& mjx-mn:has(~ mjx-mfrac), mjx-mfrac ~ mjx-mn': {
|
|
54
|
-
fontSize: '120% !important',
|
|
55
|
-
},
|
|
56
|
-
}));
|
|
57
|
-
|
|
58
|
-
export default function Choice({ choice, disabled, instanceId, selectedItem, onSelectClick }) {
|
|
59
|
-
const rootRef = useRef(null);
|
|
60
|
-
|
|
61
|
-
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
|
62
|
-
id: `choice-${choice.id}`,
|
|
63
|
-
data: { choice, instanceId, fromChoice: true, type: DRAG_TYPE },
|
|
64
|
-
disabled,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
renderMath(rootRef.current);
|
|
69
|
-
}, [choice.value]);
|
|
70
|
-
|
|
71
|
-
const isSelected = !!selectedItem && selectedItem.fromChoice === true && selectedItem.choice.id === choice.id;
|
|
72
|
-
|
|
73
|
-
const handleClick = (e) => {
|
|
74
|
-
if (disabled) return;
|
|
75
|
-
|
|
76
|
-
e.stopPropagation();
|
|
77
|
-
onSelectClick?.({ choice, instanceId, fromChoice: true, type: DRAG_TYPE });
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
return (
|
|
81
|
-
<StyledChoice
|
|
82
|
-
ref={setNodeRef}
|
|
83
|
-
style={
|
|
84
|
-
isDragging
|
|
85
|
-
? {
|
|
86
|
-
width: rootRef.current?.offsetWidth || 90, // min-width of chip is 90px, so if we don't have the width, we can use 90px as a fallback
|
|
87
|
-
height: rootRef.current?.offsetHeight || 32, // min-height of chip is 32px, so if we don't have the height, we can use 32px as a fallback
|
|
88
|
-
}
|
|
89
|
-
: {}
|
|
90
|
-
}
|
|
91
|
-
disabled={disabled}
|
|
92
|
-
selected={isSelected}
|
|
93
|
-
onClick={handleClick}
|
|
94
|
-
{...listeners}
|
|
95
|
-
{...attributes}
|
|
96
|
-
>
|
|
97
|
-
<StyledChip
|
|
98
|
-
clickable={false}
|
|
99
|
-
disabled={disabled}
|
|
100
|
-
ref={rootRef}
|
|
101
|
-
label={<StyledChipLabel dangerouslySetInnerHTML={{ __html: choice.value }} />}
|
|
102
|
-
/>
|
|
103
|
-
</StyledChoice>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
Choice.propTypes = {
|
|
108
|
-
choice: PropTypes.object.isRequired,
|
|
109
|
-
disabled: PropTypes.bool,
|
|
110
|
-
instanceId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
111
|
-
selectedItem: PropTypes.object,
|
|
112
|
-
onSelectClick: PropTypes.func,
|
|
113
|
-
};
|
package/src/choices/index.jsx
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { findKey } from 'lodash-es';
|
|
4
|
-
import Choice from './choice';
|
|
5
|
-
import { DragDroppablePlaceholder } from '@pie-lib/drag';
|
|
6
|
-
|
|
7
|
-
export default class Choices extends React.Component {
|
|
8
|
-
static propTypes = {
|
|
9
|
-
disabled: PropTypes.bool,
|
|
10
|
-
duplicates: PropTypes.bool,
|
|
11
|
-
choices: PropTypes.arrayOf(PropTypes.shape({ label: PropTypes.string, value: PropTypes.string })),
|
|
12
|
-
value: PropTypes.object,
|
|
13
|
-
choicePosition: PropTypes.string.isRequired,
|
|
14
|
-
instanceId: PropTypes.string, // Added for drag isolation
|
|
15
|
-
selectedItem: PropTypes.object,
|
|
16
|
-
onSelectClick: PropTypes.func,
|
|
17
|
-
onPlacementClick: PropTypes.func,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
getStyleForWrapper = () => {
|
|
21
|
-
const { choicePosition } = this.props;
|
|
22
|
-
|
|
23
|
-
switch (choicePosition) {
|
|
24
|
-
case 'above':
|
|
25
|
-
return {
|
|
26
|
-
margin: '0 0 40px 0',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
case 'below':
|
|
30
|
-
return {
|
|
31
|
-
margin: '40px 0 0 0',
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
case 'right':
|
|
35
|
-
return {
|
|
36
|
-
margin: '0 0 0 40px',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
default:
|
|
40
|
-
return {
|
|
41
|
-
margin: '0 40px 0 0',
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
handlePoolClick = () => {
|
|
47
|
-
const { disabled, selectedItem, onPlacementClick } = this.props;
|
|
48
|
-
|
|
49
|
-
if (disabled) return;
|
|
50
|
-
|
|
51
|
-
if (selectedItem) {
|
|
52
|
-
// `undefined` targetId means "the choice board" — drag-in-the-blank.jsx's
|
|
53
|
-
// commitPlacement routes it to removing the item from wherever it currently is.
|
|
54
|
-
onPlacementClick?.(undefined);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Pool background clicked with nothing selected: nothing to place.
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
render() {
|
|
61
|
-
const { disabled, duplicates, choices, value, instanceId, selectedItem, onSelectClick } = this.props;
|
|
62
|
-
const filteredChoices = choices.filter((c) => {
|
|
63
|
-
if (duplicates === true) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
const foundChoice = findKey(value, (v) => v === c.id);
|
|
67
|
-
return foundChoice === undefined;
|
|
68
|
-
});
|
|
69
|
-
const elementStyle = { ...this.getStyleForWrapper(), minWidth: '100px' };
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<div style={elementStyle} onClick={this.handlePoolClick}>
|
|
73
|
-
<DragDroppablePlaceholder disabled={disabled} instanceId={instanceId}>
|
|
74
|
-
{filteredChoices.map((c, index) => (
|
|
75
|
-
<Choice
|
|
76
|
-
key={`${c.value}-${index}`}
|
|
77
|
-
disabled={disabled}
|
|
78
|
-
choice={c}
|
|
79
|
-
instanceId={instanceId}
|
|
80
|
-
selectedItem={selectedItem}
|
|
81
|
-
onSelectClick={onSelectClick}
|
|
82
|
-
/>
|
|
83
|
-
))}
|
|
84
|
-
</DragDroppablePlaceholder>
|
|
85
|
-
</div>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/componentize.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const REGEX = /\{\{(\d+)\}\}/g;
|
|
2
|
-
|
|
3
|
-
export default (s, t) => {
|
|
4
|
-
if (!s) {
|
|
5
|
-
return { markup: '' };
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const markup = s.replace(REGEX, (match, g) => {
|
|
9
|
-
return `<span data-component="${t}" data-id="${g}"></span>`;
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
return { markup };
|
|
13
|
-
};
|