@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,351 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { DragProvider } from '@pie-lib/drag';
|
|
4
|
-
import { DragOverlay, rectIntersection } from '@dnd-kit/core';
|
|
5
|
-
import Choices from './choices';
|
|
6
|
-
import Choice from './choices/choice';
|
|
7
|
-
import Blank from './components/blank';
|
|
8
|
-
import { withMask } from './with-mask';
|
|
9
|
-
import { closestDroppableKeyboardCoordinates } from './keyboard-coordinates';
|
|
10
|
-
|
|
11
|
-
// A click that lands right after a real drag gesture ends (pointer drag-and-drop, or
|
|
12
|
-
// the browser's own synthetic click for a keyboard Space/Enter) must be ignored by the
|
|
13
|
-
// click-to-select/click-to-place handlers below, or it would immediately reopen or
|
|
14
|
-
// re-trigger a selection for a drag that just completed.
|
|
15
|
-
const CLICK_AFTER_DRAG_GUARD_MS = 250;
|
|
16
|
-
|
|
17
|
-
const Masked = withMask('blank', (props) => (node, data, onChange) => {
|
|
18
|
-
const dataset = node.data?.dataset || {};
|
|
19
|
-
if (dataset.component === 'blank') {
|
|
20
|
-
// eslint-disable-next-line react/prop-types
|
|
21
|
-
const {
|
|
22
|
-
disabled,
|
|
23
|
-
duplicates,
|
|
24
|
-
correctResponse,
|
|
25
|
-
feedback,
|
|
26
|
-
showCorrectAnswer,
|
|
27
|
-
emptyResponseAreaWidth,
|
|
28
|
-
emptyResponseAreaHeight,
|
|
29
|
-
instanceId,
|
|
30
|
-
isDragging,
|
|
31
|
-
selectedItem,
|
|
32
|
-
onSelectClick,
|
|
33
|
-
onPlacementClick,
|
|
34
|
-
} = props;
|
|
35
|
-
const choiceId = showCorrectAnswer ? correctResponse[dataset.id] : data[dataset.id];
|
|
36
|
-
// eslint-disable-next-line react/prop-types
|
|
37
|
-
const choice = choiceId && props.choices.find((c) => c.id === choiceId);
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<Blank
|
|
41
|
-
key={`${node.type}-${dataset.id}`}
|
|
42
|
-
correct={showCorrectAnswer || (feedback && feedback[dataset.id])}
|
|
43
|
-
disabled={disabled}
|
|
44
|
-
duplicates={duplicates}
|
|
45
|
-
choice={choice}
|
|
46
|
-
id={dataset.id}
|
|
47
|
-
emptyResponseAreaWidth={emptyResponseAreaWidth}
|
|
48
|
-
emptyResponseAreaHeight={emptyResponseAreaHeight}
|
|
49
|
-
onChange={(id, choiceId) => {
|
|
50
|
-
const newData = { ...data };
|
|
51
|
-
if (choiceId === undefined) {
|
|
52
|
-
delete newData[id];
|
|
53
|
-
} else {
|
|
54
|
-
newData[id] = choiceId;
|
|
55
|
-
}
|
|
56
|
-
onChange(newData);
|
|
57
|
-
}}
|
|
58
|
-
instanceId={instanceId}
|
|
59
|
-
isDragging={isDragging}
|
|
60
|
-
selectedItem={selectedItem}
|
|
61
|
-
onSelectClick={onSelectClick}
|
|
62
|
-
onPlacementClick={onPlacementClick}
|
|
63
|
-
/>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
export default class DragInTheBlank extends React.Component {
|
|
69
|
-
constructor(props) {
|
|
70
|
-
super(props);
|
|
71
|
-
this.state = {
|
|
72
|
-
activeDragItem: null,
|
|
73
|
-
dropAnimation: undefined,
|
|
74
|
-
selectedItem: null,
|
|
75
|
-
};
|
|
76
|
-
this.lastDragEndAt = 0;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static propTypes = {
|
|
80
|
-
markup: PropTypes.string,
|
|
81
|
-
layout: PropTypes.object,
|
|
82
|
-
choicesPosition: PropTypes.string,
|
|
83
|
-
choices: PropTypes.array,
|
|
84
|
-
value: PropTypes.object,
|
|
85
|
-
onChange: PropTypes.func,
|
|
86
|
-
duplicates: PropTypes.bool,
|
|
87
|
-
disabled: PropTypes.bool,
|
|
88
|
-
feedback: PropTypes.object,
|
|
89
|
-
correctResponse: PropTypes.object,
|
|
90
|
-
showCorrectAnswer: PropTypes.bool,
|
|
91
|
-
emptyResponseAreaWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
92
|
-
emptyResponseAreaHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
93
|
-
instanceId: PropTypes.string,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
static defaultProps = {
|
|
97
|
-
instanceId: 'drag-in-the-blank',
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
handleDragStart = (event) => {
|
|
101
|
-
const { active } = event;
|
|
102
|
-
|
|
103
|
-
if (active?.data?.current) {
|
|
104
|
-
this.setState({
|
|
105
|
-
activeDragItem: active.data.current,
|
|
106
|
-
dropAnimation: undefined, // default during drag
|
|
107
|
-
selectedItem: active.data.current,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
renderDragOverlay = () => {
|
|
113
|
-
const { activeDragItem } = this.state;
|
|
114
|
-
if (!activeDragItem) return null;
|
|
115
|
-
|
|
116
|
-
if (activeDragItem.type === 'MaskBlank') {
|
|
117
|
-
return (
|
|
118
|
-
<Choice
|
|
119
|
-
disabled={activeDragItem.disabled}
|
|
120
|
-
choice={activeDragItem.choice}
|
|
121
|
-
instanceId={activeDragItem.instanceId}
|
|
122
|
-
/>
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return null;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// Shared placement logic for both the drag-end path and the click-to-place path, so
|
|
130
|
-
// neither reimplements the other's mutation rules.
|
|
131
|
-
//
|
|
132
|
-
// `targetId === undefined` means "the choice board" — placing there removes the item
|
|
133
|
-
// from wherever it currently is (mirroring image-cloze-association's
|
|
134
|
-
// `containerIndex === undefined` convention for its own choices pool).
|
|
135
|
-
commitPlacement = (draggedItem, targetId) => {
|
|
136
|
-
const { onChange, value } = this.props;
|
|
137
|
-
|
|
138
|
-
if (!onChange) return;
|
|
139
|
-
|
|
140
|
-
if (targetId === undefined) {
|
|
141
|
-
if (!draggedItem.fromChoice && draggedItem.id) {
|
|
142
|
-
const newValue = { ...value };
|
|
143
|
-
delete newValue[draggedItem.id];
|
|
144
|
-
onChange(newValue);
|
|
145
|
-
}
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (draggedItem.fromChoice === true) {
|
|
150
|
-
const newValue = { ...value };
|
|
151
|
-
newValue[targetId] = draggedItem.choice.id;
|
|
152
|
-
onChange(newValue);
|
|
153
|
-
} else if (draggedItem.id && draggedItem.id !== targetId) {
|
|
154
|
-
const newValue = { ...value };
|
|
155
|
-
newValue[targetId] = draggedItem.choice.id;
|
|
156
|
-
delete newValue[draggedItem.id];
|
|
157
|
-
onChange(newValue);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
handleDragEnd = (event) => {
|
|
162
|
-
const { active, over } = event;
|
|
163
|
-
|
|
164
|
-
const draggedData = active?.data?.current;
|
|
165
|
-
const dropData = over?.data?.current;
|
|
166
|
-
|
|
167
|
-
const isValidDrop =
|
|
168
|
-
!!active && !!over && draggedData?.type === 'MaskBlank' && dropData?.accepts?.includes('MaskBlank');
|
|
169
|
-
|
|
170
|
-
// Only animate back when drop is invalid
|
|
171
|
-
this.setState({
|
|
172
|
-
activeDragItem: null,
|
|
173
|
-
dropAnimation: isValidDrop ? null : undefined,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
this.cancelSelection();
|
|
177
|
-
this.lastDragEndAt = Date.now();
|
|
178
|
-
|
|
179
|
-
if (!isValidDrop) return;
|
|
180
|
-
|
|
181
|
-
const targetId = dropData.toChoiceBoard === true ? undefined : dropData.id;
|
|
182
|
-
|
|
183
|
-
this.commitPlacement(draggedData, targetId);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
onDragCancel = () => {
|
|
187
|
-
this.setState({ activeDragItem: null, dropAnimation: undefined });
|
|
188
|
-
this.cancelSelection();
|
|
189
|
-
this.lastDragEndAt = Date.now();
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
isSameItem = (a, b) => {
|
|
193
|
-
if (!a || !b || a.fromChoice !== b.fromChoice) return false;
|
|
194
|
-
return a.fromChoice ? a.choice.id === b.choice.id : a.id === b.id;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
// Click-to-select semantics: selecting the currently-selected item again clears the
|
|
198
|
-
// selection instead of re-selecting it.
|
|
199
|
-
toggleItemSelection = (data) => {
|
|
200
|
-
this.setState((state) => ({
|
|
201
|
-
selectedItem: this.isSameItem(state.selectedItem, data) ? null : data,
|
|
202
|
-
}));
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
cancelSelection = () => {
|
|
206
|
-
this.setState({ selectedItem: null });
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// If a real dnd-kit drag (started via keyboard Space/Enter) is still live when a
|
|
210
|
-
// click completes the placement below, it needs to be cleanly ended — otherwise
|
|
211
|
-
// dnd-kit would still think a drag is in progress. Escape is already configured as
|
|
212
|
-
// this sensor's cancel key (see the keyboardCodes passed to DragProvider below), and
|
|
213
|
-
// dispatching it as a real DOM KeyboardEvent is how dnd-kit's own document-level
|
|
214
|
-
// listener is reached from outside its sensor.
|
|
215
|
-
//
|
|
216
|
-
// Only dispatch when a drag is actually live — this is a synthetic Escape keydown on
|
|
217
|
-
// `document`, so an unconditional dispatch would also be observed by any other
|
|
218
|
-
// document-level Escape listener (host player modals/dialogs, or another mounted
|
|
219
|
-
// instance of this same component) even when nothing here actually needed cancelling.
|
|
220
|
-
endAnyLiveKeyboardDrag = () => {
|
|
221
|
-
if (!this.state.activeDragItem) return;
|
|
222
|
-
|
|
223
|
-
document.dispatchEvent(new KeyboardEvent('keydown', { code: 'Escape', bubbles: true, cancelable: true }));
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
placeSelectedItem = (targetId) => {
|
|
227
|
-
const { selectedItem } = this.state;
|
|
228
|
-
|
|
229
|
-
if (!selectedItem) return;
|
|
230
|
-
|
|
231
|
-
this.commitPlacement(selectedItem, targetId);
|
|
232
|
-
this.cancelSelection();
|
|
233
|
-
this.endAnyLiveKeyboardDrag();
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
isClickSoonAfterDragEnd = () => Date.now() - this.lastDragEndAt < CLICK_AFTER_DRAG_GUARD_MS;
|
|
237
|
-
|
|
238
|
-
onItemClick = (data) => {
|
|
239
|
-
if (this.isClickSoonAfterDragEnd()) return;
|
|
240
|
-
|
|
241
|
-
// End any still-live keyboard drag BEFORE toggling the new selection: ending it
|
|
242
|
-
// also cancels the current selection as a side effect (see onDragCancel above), so
|
|
243
|
-
// doing it before — not after — lets this click's own selection be the one that
|
|
244
|
-
// sticks.
|
|
245
|
-
this.endAnyLiveKeyboardDrag();
|
|
246
|
-
this.toggleItemSelection(data);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
onPlacementClick = (targetId) => {
|
|
250
|
-
if (this.isClickSoonAfterDragEnd()) return;
|
|
251
|
-
|
|
252
|
-
this.placeSelectedItem(targetId);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
getPositionDirection = (choicePosition) => {
|
|
256
|
-
let flexDirection;
|
|
257
|
-
let justifyContent;
|
|
258
|
-
let alignItems;
|
|
259
|
-
|
|
260
|
-
switch (choicePosition) {
|
|
261
|
-
case 'left':
|
|
262
|
-
flexDirection = 'row';
|
|
263
|
-
alignItems = 'center';
|
|
264
|
-
break;
|
|
265
|
-
case 'right':
|
|
266
|
-
flexDirection = 'row-reverse';
|
|
267
|
-
justifyContent = 'flex-end';
|
|
268
|
-
alignItems = 'center';
|
|
269
|
-
break;
|
|
270
|
-
case 'below':
|
|
271
|
-
flexDirection = 'column-reverse';
|
|
272
|
-
break;
|
|
273
|
-
default:
|
|
274
|
-
// above
|
|
275
|
-
flexDirection = 'column';
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return { flexDirection, justifyContent, alignItems };
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
render() {
|
|
283
|
-
const {
|
|
284
|
-
markup,
|
|
285
|
-
duplicates,
|
|
286
|
-
value,
|
|
287
|
-
onChange,
|
|
288
|
-
choicesPosition,
|
|
289
|
-
choices,
|
|
290
|
-
correctResponse,
|
|
291
|
-
disabled,
|
|
292
|
-
feedback,
|
|
293
|
-
showCorrectAnswer,
|
|
294
|
-
emptyResponseAreaWidth,
|
|
295
|
-
emptyResponseAreaHeight,
|
|
296
|
-
layout,
|
|
297
|
-
instanceId,
|
|
298
|
-
} = this.props;
|
|
299
|
-
|
|
300
|
-
const choicePosition = choicesPosition || 'below';
|
|
301
|
-
const style = { display: 'flex', minWidth: '100px', ...this.getPositionDirection(choicePosition) };
|
|
302
|
-
|
|
303
|
-
return (
|
|
304
|
-
<DragProvider
|
|
305
|
-
onDragStart={this.handleDragStart}
|
|
306
|
-
onDragEnd={this.handleDragEnd}
|
|
307
|
-
onDragCancel={this.onDragCancel}
|
|
308
|
-
collisionDetection={rectIntersection}
|
|
309
|
-
keyboardCoordinateGetter={closestDroppableKeyboardCoordinates}
|
|
310
|
-
keyboardCodes={{ start: ['Space', 'Enter'], cancel: ['Escape'], end: ['Space', 'Enter'] }}
|
|
311
|
-
>
|
|
312
|
-
<div ref={(ref) => (this.rootRef = ref)} style={style}>
|
|
313
|
-
<Choices
|
|
314
|
-
choicePosition={choicePosition}
|
|
315
|
-
choices={choices}
|
|
316
|
-
value={value}
|
|
317
|
-
duplicates={duplicates}
|
|
318
|
-
disabled={disabled}
|
|
319
|
-
instanceId={instanceId}
|
|
320
|
-
selectedItem={this.state.selectedItem}
|
|
321
|
-
onSelectClick={this.onItemClick}
|
|
322
|
-
onPlacementClick={this.onPlacementClick}
|
|
323
|
-
/>
|
|
324
|
-
<Masked
|
|
325
|
-
elementType="drag-in-the-blank"
|
|
326
|
-
markup={markup}
|
|
327
|
-
layout={layout}
|
|
328
|
-
value={value}
|
|
329
|
-
choices={choices}
|
|
330
|
-
onChange={onChange}
|
|
331
|
-
disabled={disabled}
|
|
332
|
-
duplicates={duplicates}
|
|
333
|
-
feedback={feedback}
|
|
334
|
-
correctResponse={correctResponse}
|
|
335
|
-
showCorrectAnswer={showCorrectAnswer}
|
|
336
|
-
emptyResponseAreaWidth={emptyResponseAreaWidth}
|
|
337
|
-
emptyResponseAreaHeight={emptyResponseAreaHeight}
|
|
338
|
-
instanceId={instanceId}
|
|
339
|
-
isDragging={!!this.state.activeDragItem}
|
|
340
|
-
selectedItem={this.state.selectedItem}
|
|
341
|
-
onSelectClick={this.onItemClick}
|
|
342
|
-
onPlacementClick={this.onPlacementClick}
|
|
343
|
-
/>
|
|
344
|
-
<DragOverlay style={{ pointerEvents: 'none' }} dropAnimation={this.state.dropAnimation}>
|
|
345
|
-
{this.renderDragOverlay()}
|
|
346
|
-
</DragOverlay>
|
|
347
|
-
</div>
|
|
348
|
-
</DragProvider>
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { buildLayoutFromMarkup, withMask } from './with-mask';
|
|
2
|
-
import DragInTheBlank from './drag-in-the-blank';
|
|
3
|
-
import ConstructedResponse from './constructed-response';
|
|
4
|
-
import Customizable from './customizable';
|
|
5
|
-
import InlineDropdown from './inline-dropdown';
|
|
6
|
-
import componentize from './componentize';
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
withMask,
|
|
10
|
-
buildLayoutFromMarkup,
|
|
11
|
-
DragInTheBlank,
|
|
12
|
-
ConstructedResponse,
|
|
13
|
-
InlineDropdown,
|
|
14
|
-
componentize,
|
|
15
|
-
Customizable,
|
|
16
|
-
};
|
package/src/inline-dropdown.jsx
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Dropdown from './components/dropdown';
|
|
3
|
-
import { withMask } from './with-mask';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line react/display-name
|
|
6
|
-
export default withMask('dropdown', (props) => (node, data, onChange) => {
|
|
7
|
-
const dataset = node.data ? node.data.dataset || {} : {};
|
|
8
|
-
if (dataset.component === 'dropdown') {
|
|
9
|
-
// eslint-disable-next-line react/prop-types
|
|
10
|
-
const { choices, disabled, feedback, showCorrectAnswer } = props;
|
|
11
|
-
const correctAnswer = choices && choices[dataset.id] && choices[dataset.id].find((c) => c.correct);
|
|
12
|
-
const finalChoice = showCorrectAnswer ? correctAnswer && correctAnswer.value : data[dataset.id];
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<Dropdown
|
|
16
|
-
key={`${node.type}-dropdown-${dataset.id}`}
|
|
17
|
-
correct={feedback && feedback[dataset.id] && feedback[dataset.id] === 'correct'}
|
|
18
|
-
disabled={disabled || showCorrectAnswer}
|
|
19
|
-
value={finalChoice}
|
|
20
|
-
correctValue={showCorrectAnswer ? correctAnswer && correctAnswer.label : undefined}
|
|
21
|
-
id={dataset.id}
|
|
22
|
-
onChange={onChange}
|
|
23
|
-
choices={choices[dataset.id]}
|
|
24
|
-
showCorrectAnswer={showCorrectAnswer}
|
|
25
|
-
singleQuery={Object.keys(choices).length == 1}
|
|
26
|
-
/>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { defaultKeyboardCoordinateGetter, KeyboardCode } from '@dnd-kit/core';
|
|
2
|
-
|
|
3
|
-
// Matches the id `drag-in-the-blank-dp.jsx` registers for the choice board's droppable.
|
|
4
|
-
const CHOICE_BOARD_ID = 'drag-in-the-blank-droppable';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Custom keyboard coordinate getter for drag-in-the-blank's Tab-based placement.
|
|
8
|
-
*
|
|
9
|
-
* Tab/Shift+Tab cycle the dragged item directly onto the next/previous enabled
|
|
10
|
-
* droppable — a blank (`mask-blank-drop-{id}`), sorted by on-screen position
|
|
11
|
-
* (top-to-bottom, then left-to-right, since blanks sit inline in flowing text rather
|
|
12
|
-
* than a simple list) — followed by the choice board as a fixed last stop (see below
|
|
13
|
-
* for why the board isn't sorted alongside the blanks).
|
|
14
|
-
*
|
|
15
|
-
* Arrow keys are delegated to dnd-kit's own `defaultKeyboardCoordinateGetter`, leaving
|
|
16
|
-
* the existing free-form arrow-key dragging behavior completely unchanged.
|
|
17
|
-
*/
|
|
18
|
-
export const closestDroppableKeyboardCoordinates = (event, { active, context, currentCoordinates }) => {
|
|
19
|
-
const { code } = event;
|
|
20
|
-
const isTab = code === KeyboardCode.Tab;
|
|
21
|
-
const isArrow =
|
|
22
|
-
code === KeyboardCode.Down || code === KeyboardCode.Up || code === KeyboardCode.Left || code === KeyboardCode.Right;
|
|
23
|
-
|
|
24
|
-
if (!isTab && !isArrow) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (isArrow) {
|
|
29
|
-
return defaultKeyboardCoordinateGetter(event, { context, currentCoordinates });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
event.preventDefault();
|
|
33
|
-
|
|
34
|
-
const { droppableRects, droppableContainers, collisionRect } = context;
|
|
35
|
-
|
|
36
|
-
if (!droppableRects || droppableRects.size === 0) {
|
|
37
|
-
return currentCoordinates;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// A blank is itself a droppable for its own slot ("mask-blank-drop-{id}"), and
|
|
41
|
-
// simultaneously draggable from that same slot — the same shape as match-list's
|
|
42
|
-
// placed "target" tiles. That self drop-zone must never be treated as a navigable
|
|
43
|
-
// target: exclude it outright rather than relying on a distance threshold.
|
|
44
|
-
const draggedData = active?.data?.current;
|
|
45
|
-
const ownDropId =
|
|
46
|
-
draggedData && draggedData.fromChoice === false && draggedData.id != null
|
|
47
|
-
? `mask-blank-drop-${draggedData.id}`
|
|
48
|
-
: undefined;
|
|
49
|
-
|
|
50
|
-
const targets = [];
|
|
51
|
-
let boardTarget;
|
|
52
|
-
|
|
53
|
-
for (const [id, container] of droppableContainers) {
|
|
54
|
-
if (container?.disabled) continue;
|
|
55
|
-
if (id === ownDropId) continue;
|
|
56
|
-
|
|
57
|
-
const rect = droppableRects.get(id);
|
|
58
|
-
if (!rect) continue;
|
|
59
|
-
|
|
60
|
-
const center = {
|
|
61
|
-
x: rect.left + rect.width / 2,
|
|
62
|
-
y: rect.top + rect.height / 2,
|
|
63
|
-
};
|
|
64
|
-
// Land the dragged item's own top-left corner at the target's center-left point,
|
|
65
|
-
// rather than at the target's own top-left corner (avoids overshooting into a
|
|
66
|
-
// neighboring droppable when the target is much wider than the dragged item).
|
|
67
|
-
const dropPosition = {
|
|
68
|
-
x: rect.left,
|
|
69
|
-
y: rect.top + rect.height / 2,
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const target = { id, rect, dropPosition, center };
|
|
73
|
-
|
|
74
|
-
if (id === CHOICE_BOARD_ID) {
|
|
75
|
-
boardTarget = target;
|
|
76
|
-
} else {
|
|
77
|
-
targets.push(target);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (targets.length === 0 && !boardTarget) {
|
|
82
|
-
return currentCoordinates;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const reverse = event.shiftKey;
|
|
86
|
-
|
|
87
|
-
targets.sort((a, b) => {
|
|
88
|
-
if (Math.abs(a.center.y - b.center.y) > 10) return a.center.y - b.center.y;
|
|
89
|
-
return a.center.x - b.center.x;
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// The choice board can be an arbitrarily large container — e.g. several choices
|
|
93
|
-
// stacked beside the markup (`choicePosition: 'right'`/`'left'`) — so its own center
|
|
94
|
-
// can land anywhere relative to the blanks it sits beside, including numerically
|
|
95
|
-
// between two of them. Sorting it by position the same way as a blank would then
|
|
96
|
-
// interleave it into the middle of the cycle, making a single Tab press jump over
|
|
97
|
-
// more than one blank (confirmed live: with 3 stacked choices beside wrapped text,
|
|
98
|
-
// the board's center fell between blank 2 and blank 3, so the very first Tab press
|
|
99
|
-
// from the pool landed on blank 3, skipping blanks 1 and 2 entirely). Anchor it as a
|
|
100
|
-
// fixed stop after every blank, in every layout, instead of trusting its own bounds.
|
|
101
|
-
if (boardTarget) {
|
|
102
|
-
targets.push(boardTarget);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Find the current target: whichever target's rect actually contains the dragged
|
|
106
|
-
// item's own center. This holds regardless of how the dragged item's size compares
|
|
107
|
-
// to the target's — a compact chip landed (per `dropPosition` above) at a much wider
|
|
108
|
-
// target's left edge is still contained within that target's rect. Comparing
|
|
109
|
-
// distances between reconstructed centers instead breaks down for exactly that shape
|
|
110
|
-
// (a small item in a much wider target): the reconstructed center can end up closer
|
|
111
|
-
// to a completely different droppable than to the one the item is actually sitting
|
|
112
|
-
// on, so the *next* press re-matches the wrong target and looks like it does nothing.
|
|
113
|
-
const draggedCenter = collisionRect
|
|
114
|
-
? { x: collisionRect.left + collisionRect.width / 2, y: collisionRect.top + collisionRect.height / 2 }
|
|
115
|
-
: currentCoordinates;
|
|
116
|
-
|
|
117
|
-
let currentIndex = targets.findIndex(
|
|
118
|
-
(t) =>
|
|
119
|
-
draggedCenter.x >= t.rect.left &&
|
|
120
|
-
draggedCenter.x <= t.rect.right &&
|
|
121
|
-
draggedCenter.y >= t.rect.top &&
|
|
122
|
-
draggedCenter.y <= t.rect.bottom,
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
// Fall back to nearest-by-dropPosition if the dragged item's center isn't strictly
|
|
126
|
-
// inside any target (e.g. mid-flight after a free arrow-key move).
|
|
127
|
-
if (currentIndex === -1) {
|
|
128
|
-
let minDist = Infinity;
|
|
129
|
-
|
|
130
|
-
for (let i = 0; i < targets.length; i++) {
|
|
131
|
-
const dist = distance(currentCoordinates, targets[i].dropPosition);
|
|
132
|
-
|
|
133
|
-
if (dist < minDist) {
|
|
134
|
-
minDist = dist;
|
|
135
|
-
currentIndex = i;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const nextIndex = reverse
|
|
141
|
-
? (currentIndex - 1 + targets.length) % targets.length
|
|
142
|
-
: (currentIndex + 1) % targets.length;
|
|
143
|
-
|
|
144
|
-
return targets[nextIndex].dropPosition;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const distance = (a, b) => Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
|