@pie-lib/mask-markup 3.1.5 → 3.1.6-beta.2

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +0 -105
  2. package/lib/choices/choice.js +6 -24
  3. package/lib/choices/choice.js.map +1 -1
  4. package/lib/choices/index.js +9 -32
  5. package/lib/choices/index.js.map +1 -1
  6. package/lib/components/blank.js +29 -106
  7. package/lib/components/blank.js.map +1 -1
  8. package/lib/components/dropdown.js +9 -6
  9. package/lib/components/dropdown.js.map +1 -1
  10. package/lib/drag-in-the-blank.js +30 -139
  11. package/lib/drag-in-the-blank.js.map +1 -1
  12. package/lib/keyboard-coordinates.js +1 -1
  13. package/lib/mask.js +15 -20
  14. package/lib/mask.js.map +1 -1
  15. package/package.json +6 -6
  16. package/src/choices/choice.jsx +3 -16
  17. package/src/choices/index.jsx +3 -27
  18. package/src/components/blank.jsx +35 -108
  19. package/src/components/dropdown.jsx +9 -7
  20. package/src/drag-in-the-blank.jsx +22 -132
  21. package/src/mask.jsx +11 -13
  22. package/LICENSE.md +0 -5
  23. package/lib/keyboard-coordinates.js.map +0 -1
  24. package/src/__tests__/drag-in-the-blank.test.js +0 -256
  25. package/src/__tests__/index.test.js +0 -38
  26. package/src/__tests__/keyboard-coordinates.test.js +0 -202
  27. package/src/__tests__/mask.test.js +0 -479
  28. package/src/__tests__/serialization.test.js +0 -54
  29. package/src/__tests__/utils.js +0 -1
  30. package/src/__tests__/with-mask.test.js +0 -76
  31. package/src/choices/__tests__/index.test.js +0 -212
  32. package/src/components/__tests__/blank.test.js +0 -413
  33. package/src/components/__tests__/correct-input.test.js +0 -90
  34. package/src/components/__tests__/dropdown.test.js +0 -129
  35. package/src/components/__tests__/input.test.js +0 -102
  36. package/src/keyboard-coordinates.js +0 -147
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import { renderMath } from '@pie-lib/math-rendering';
4
4
  import debug from 'debug';
5
5
  import { useDraggable, useDroppable } from '@dnd-kit/core';
6
+ import { CSS } from '@dnd-kit/utilities';
6
7
  import { styled } from '@mui/material/styles';
7
8
  import Chip from '@mui/material/Chip';
8
9
  import classnames from 'classnames';
@@ -11,32 +12,22 @@ import { grey } from '@mui/material/colors';
11
12
 
12
13
  const log = debug('pie-lib:mask-markup:blank');
13
14
 
14
- const StyledContent = styled('span')(({ dragged, over, selected, showsPointerCursor }) => ({
15
+ const StyledContent = styled('span')(({ dragged, over }) => ({
15
16
  border: `solid 0px ${color.primary()}`,
16
17
  minWidth: '200px',
18
+ touchAction: 'none',
17
19
  overflow: 'hidden',
18
20
  whiteSpace: 'nowrap',
19
21
  opacity: 1,
20
- cursor: 'default',
21
22
  ...(over && {
22
23
  whiteSpace: 'nowrap',
23
24
  overflow: 'hidden',
24
25
  }),
25
- ...((dragged || selected) && {
26
+ ...(dragged && {
26
27
  opacity: 0.5,
27
28
  }),
28
- ...(showsPointerCursor && {
29
- '&:hover': {
30
- cursor: 'pointer',
31
- },
32
- }),
33
29
  }));
34
30
 
35
- const StyledDragHandle = styled('span')({
36
- display: 'inline-flex',
37
- touchAction: 'none',
38
- });
39
-
40
31
  const StyledChip = styled(Chip)(() => ({
41
32
  backgroundColor: color.background(),
42
33
  border: `2px dashed ${color.text()}`,
@@ -350,40 +341,23 @@ function DragDropBlank({
350
341
  emptyResponseAreaWidth,
351
342
  emptyResponseAreaHeight,
352
343
  instanceId,
353
- selectedItem,
354
- onSelectClick,
355
- onPlacementClick,
356
344
  }) {
357
- const [isHovered, setIsHovered] = useState(false);
358
-
359
- const dragData = {
360
- id,
361
- choice,
362
- instanceId,
363
- fromChoice: false, // This is from a blank, not from choices
364
- type: 'MaskBlank',
365
- };
366
-
367
345
  // Setup draggable functionality
368
346
  const {
369
347
  attributes: dragAttributes,
370
348
  listeners: dragListeners,
371
349
  setNodeRef: setDragNodeRef,
350
+ transform,
372
351
  isDragging,
373
352
  } = useDraggable({
374
353
  id: `mask-blank-drag-${id}`,
375
354
  disabled: disabled || !choice,
376
- data: dragData,
377
- // dnd-kit's own `attributes` default tabIndex to 0 unconditionally, even when
378
- // `disabled` — so a non-draggable (empty) blank stays a native Tab stop of its own.
379
- // For a drop-zone (droppable blank), that duplicates the outer wrapper's own tab stop
380
- // (see isNativeTabStop below) at the exact same position, so Tab/Shift+Tab has to
381
- // pass through both to move anywhere visibly, making every other press look like a
382
- // no-op. Drop it out of the tab order here whenever it isn't independently
383
- // reachable/interactive, leaving the outer wrapper (for an empty blank) or
384
- // nothing (for a disabled blank) as the sole stop.
385
- attributes: {
386
- tabIndex: choice && !disabled ? 0 : -1,
355
+ data: {
356
+ id: id,
357
+ choice: choice,
358
+ instanceId: instanceId,
359
+ fromChoice: false, // This is from a blank, not from choices
360
+ type: 'MaskBlank',
387
361
  },
388
362
  });
389
363
 
@@ -401,82 +375,38 @@ function DragDropBlank({
401
375
  },
402
376
  });
403
377
 
404
- const isSelected = !!selectedItem && selectedItem.fromChoice === false && selectedItem.id === id;
405
-
406
- const handleClick = () => {
407
- if (disabled) return;
408
-
409
- if (isSelected) {
410
- // Clicking this blank's already-selected content again deselects it.
411
- onSelectClick?.(dragData);
412
- } else if (selectedItem) {
413
- // Something else is selected — place it here, whether this blank is currently
414
- // empty or already filled (the same commitPlacement logic drag-and-drop uses).
415
- onPlacementClick?.(id);
416
- } else if (choice) {
417
- // Nothing selected yet, and this blank holds an answer — select it for moving
418
- // elsewhere, the same way Tab+Space/Enter does.
419
- onSelectClick?.(dragData);
420
- }
421
-
422
- // Empty blank clicked with nothing selected: nothing to place or select.
378
+ // Combine refs for both drag and drop
379
+ const setNodeRef = (node) => {
380
+ setDragNodeRef(node);
381
+ setDropNodeRef(node);
423
382
  };
424
383
 
425
- // An empty blank isn't draggable, so dnd-kit's own attributes (only applied to the
426
- // inner node, and only when draggable) never make it tabbable — this outer wrapper
427
- // needs its own focus/activation handling so "select a choice, then Tab to a blank
428
- // and press Space/Enter" works even when the blank is empty. This is independent of,
429
- // and doesn't change, the existing in-drag Tab-cycling (that's driven by an active
430
- // dnd-kit drag, not native focus).
431
- //
432
- // Only made a native Tab stop when NOT draggable (i.e. empty): when the blank is
433
- // filled, the inner node is already independently tabbable via dnd-kit's own
434
- // attributes for the existing pick-up-to-move gesture, and adding a second, outer Tab
435
- // stop for the same visual chip would add an extra stop to the existing Tab order —
436
- // the same double-tab-stop bug already found and fixed once in match-list/image-
437
- // cloze-association's equivalent code.
438
- const isNativeTabStop = !choice && !disabled;
439
- const isInnerDraggable = !!choice && !disabled;
440
-
441
- const handleKeyDown = (e) => {
442
- if (e.code === 'Space' || e.code === 'Enter') {
443
- e.preventDefault();
444
- handleClick();
445
- }
384
+ const style = {
385
+ transform: CSS.Translate.toString(transform),
446
386
  };
447
387
 
448
- const hasSelection = !!selectedItem;
449
- const showsHoverEffect = isOver || (hasSelection && isHovered && !disabled);
450
-
451
388
  return (
452
389
  <StyledContent
453
- ref={setDropNodeRef}
454
- role={isNativeTabStop ? 'button' : undefined}
455
- tabIndex={isNativeTabStop ? 0 : -1}
456
- onClick={handleClick}
457
- onKeyDown={isNativeTabStop ? handleKeyDown : undefined}
458
- onMouseEnter={() => setIsHovered(true)}
459
- onMouseLeave={() => setIsHovered(false)}
390
+ ref={setNodeRef}
391
+ style={style}
460
392
  dragged={isDragging}
461
- over={showsHoverEffect}
462
- selected={isSelected}
463
- showsPointerCursor={hasSelection && !disabled}
393
+ over={isOver}
394
+ {...dragAttributes}
395
+ {...dragListeners}
464
396
  >
465
- <StyledDragHandle ref={setDragNodeRef} {...(isInnerDraggable ? dragAttributes : {})} {...dragListeners}>
466
- <BlankContent
467
- id={id}
468
- disabled={disabled}
469
- duplicates={duplicates}
470
- choice={choice}
471
- isOver={showsHoverEffect}
472
- dragItem={dragItem?.data?.current}
473
- correct={correct}
474
- onChange={onChange}
475
- emptyResponseAreaWidth={emptyResponseAreaWidth}
476
- emptyResponseAreaHeight={emptyResponseAreaHeight}
477
- instanceId={instanceId}
478
- />
479
- </StyledDragHandle>
397
+ <BlankContent
398
+ id={id}
399
+ disabled={disabled}
400
+ duplicates={duplicates}
401
+ choice={choice}
402
+ isOver={isOver}
403
+ dragItem={dragItem?.data?.current}
404
+ correct={correct}
405
+ onChange={onChange}
406
+ emptyResponseAreaWidth={emptyResponseAreaWidth}
407
+ emptyResponseAreaHeight={emptyResponseAreaHeight}
408
+ instanceId={instanceId}
409
+ />
480
410
  </StyledContent>
481
411
  );
482
412
  }
@@ -496,9 +426,6 @@ DragDropBlank.propTypes = {
496
426
  emptyResponseAreaWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
497
427
  emptyResponseAreaHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
498
428
  instanceId: PropTypes.string,
499
- selectedItem: PropTypes.object,
500
- onSelectClick: PropTypes.func,
501
- onPlacementClick: PropTypes.func,
502
429
  };
503
430
 
504
431
  export default DragDropBlank;
@@ -13,8 +13,6 @@ import { styled } from '@mui/material/styles';
13
13
  import { color } from '@pie-lib/render-ui';
14
14
  import { renderMath } from '@pie-lib/math-rendering';
15
15
 
16
- const pieVar = color.v('pie');
17
-
18
16
  const StyledButton = styled(Button)(() => ({
19
17
  color: color.text(),
20
18
  border: `1px solid ${color.borderGray()}`,
@@ -55,11 +53,15 @@ const StyledButton = styled(Button)(() => ({
55
53
  }));
56
54
 
57
55
  const StyledMenu = styled(Menu)(() => ({
58
- '& .MuiPaper-root': {
59
- // honour the host's --pie-background, but stay opaque when it is undefined:
60
- // color.background() falls back to rgba(255,255,255,0), which makes the open
61
- // menu transparent and unreadable over the item content (PIE-1008)
62
- backgroundColor: pieVar('background', color.defaults.WHITE),
56
+ backgroundColor: color.background(),
57
+ border: `1px solid ${color.correct()} !important`,
58
+ '&:hover': {
59
+ border: `1px solid ${color.text()} `,
60
+ borderColor: 'initial',
61
+ },
62
+ '&:focus': {
63
+ border: `1px solid ${color.text()}`,
64
+ borderColor: 'initial',
63
65
  },
64
66
  // remove default padding on the inner list
65
67
  '& .MuiList-root': {
@@ -6,13 +6,6 @@ import Choices from './choices';
6
6
  import Choice from './choices/choice';
7
7
  import Blank from './components/blank';
8
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
9
 
17
10
  const Masked = withMask('blank', (props) => (node, data, onChange) => {
18
11
  const dataset = node.data?.dataset || {};
@@ -28,9 +21,6 @@ const Masked = withMask('blank', (props) => (node, data, onChange) => {
28
21
  emptyResponseAreaHeight,
29
22
  instanceId,
30
23
  isDragging,
31
- selectedItem,
32
- onSelectClick,
33
- onPlacementClick,
34
24
  } = props;
35
25
  const choiceId = showCorrectAnswer ? correctResponse[dataset.id] : data[dataset.id];
36
26
  // eslint-disable-next-line react/prop-types
@@ -57,9 +47,6 @@ const Masked = withMask('blank', (props) => (node, data, onChange) => {
57
47
  }}
58
48
  instanceId={instanceId}
59
49
  isDragging={isDragging}
60
- selectedItem={selectedItem}
61
- onSelectClick={onSelectClick}
62
- onPlacementClick={onPlacementClick}
63
50
  />
64
51
  );
65
52
  }
@@ -71,9 +58,7 @@ export default class DragInTheBlank extends React.Component {
71
58
  this.state = {
72
59
  activeDragItem: null,
73
60
  dropAnimation: undefined,
74
- selectedItem: null,
75
61
  };
76
- this.lastDragEndAt = 0;
77
62
  }
78
63
 
79
64
  static propTypes = {
@@ -104,7 +89,6 @@ export default class DragInTheBlank extends React.Component {
104
89
  this.setState({
105
90
  activeDragItem: active.data.current,
106
91
  dropAnimation: undefined, // default during drag
107
- selectedItem: active.data.current,
108
92
  });
109
93
  }
110
94
  };
@@ -126,40 +110,9 @@ export default class DragInTheBlank extends React.Component {
126
110
  return null;
127
111
  };
128
112
 
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
113
  handleDragEnd = (event) => {
162
114
  const { active, over } = event;
115
+ const { onChange, value } = this.props;
163
116
 
164
117
  const draggedData = active?.data?.current;
165
118
  const dropData = over?.data?.current;
@@ -173,83 +126,29 @@ export default class DragInTheBlank extends React.Component {
173
126
  dropAnimation: isValidDrop ? null : undefined,
174
127
  });
175
128
 
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
- };
129
+ if (!isValidDrop || !onChange) return;
248
130
 
249
- onPlacementClick = (targetId) => {
250
- if (this.isClickSoonAfterDragEnd()) return;
131
+ const draggedItem = draggedData;
132
+ const targetId = dropData.id;
251
133
 
252
- this.placeSelectedItem(targetId);
134
+ if (dropData.toChoiceBoard === true) {
135
+ if (!draggedItem.fromChoice && draggedItem.id) {
136
+ const newValue = { ...value };
137
+ delete newValue[draggedItem.id];
138
+ onChange(newValue);
139
+ }
140
+ } else if (draggedItem.fromChoice === true) {
141
+ if (targetId && targetId !== 'drag-in-the-blank-droppable') {
142
+ const newValue = { ...value };
143
+ newValue[targetId] = draggedItem.choice.id;
144
+ onChange(newValue);
145
+ }
146
+ } else if (draggedItem.id && draggedItem.id !== targetId) {
147
+ const newValue = { ...value };
148
+ newValue[targetId] = draggedItem.choice.id;
149
+ delete newValue[draggedItem.id];
150
+ onChange(newValue);
151
+ }
253
152
  };
254
153
 
255
154
  getPositionDirection = (choicePosition) => {
@@ -304,10 +203,7 @@ export default class DragInTheBlank extends React.Component {
304
203
  <DragProvider
305
204
  onDragStart={this.handleDragStart}
306
205
  onDragEnd={this.handleDragEnd}
307
- onDragCancel={this.onDragCancel}
308
206
  collisionDetection={rectIntersection}
309
- keyboardCoordinateGetter={closestDroppableKeyboardCoordinates}
310
- keyboardCodes={{ start: ['Space', 'Enter'], cancel: ['Escape'], end: ['Space', 'Enter'] }}
311
207
  >
312
208
  <div ref={(ref) => (this.rootRef = ref)} style={style}>
313
209
  <Choices
@@ -317,9 +213,6 @@ export default class DragInTheBlank extends React.Component {
317
213
  duplicates={duplicates}
318
214
  disabled={disabled}
319
215
  instanceId={instanceId}
320
- selectedItem={this.state.selectedItem}
321
- onSelectClick={this.onItemClick}
322
- onPlacementClick={this.onPlacementClick}
323
216
  />
324
217
  <Masked
325
218
  elementType="drag-in-the-blank"
@@ -337,9 +230,6 @@ export default class DragInTheBlank extends React.Component {
337
230
  emptyResponseAreaHeight={emptyResponseAreaHeight}
338
231
  instanceId={instanceId}
339
232
  isDragging={!!this.state.activeDragItem}
340
- selectedItem={this.state.selectedItem}
341
- onSelectClick={this.onItemClick}
342
- onPlacementClick={this.onPlacementClick}
343
233
  />
344
234
  <DragOverlay style={{ pointerEvents: 'none' }} dropAnimation={this.state.dropAnimation}>
345
235
  {this.renderDragOverlay()}
package/src/mask.jsx CHANGED
@@ -32,7 +32,7 @@ const getMark = (n) => {
32
32
  const mark = n.leaves.find((leave) => get(leave, 'marks', []).length);
33
33
 
34
34
  if (mark) {
35
- return mark.marks;
35
+ return mark.marks[0];
36
36
  }
37
37
 
38
38
  return null;
@@ -83,20 +83,18 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
83
83
  const extraText = addText(parentNode, t);
84
84
  return extraText ? acc + extraText : acc;
85
85
  }, '');
86
- const marks = getMark(n);
86
+ const mark = getMark(n);
87
87
 
88
- if (marks?.length > 0) {
89
- const tagsToWrap = marks
90
- .map((mark) => Object.keys(MARK_TAGS).find((markKey) => MARK_TAGS[markKey] === mark.type))
91
- .filter(Boolean);
88
+ if (mark) {
89
+ let markKey;
92
90
 
93
- if (tagsToWrap.length > 0) {
94
- // nest from the inside out so the first mark ends up as the outermost tag: <b><em>content</em></b>
95
- children.push(
96
- tagsToWrap.reduceRight((acc, Tag, tagIndex) => <Tag key={`${key}-${Tag}-${tagIndex}`}>{acc}</Tag>, content),
97
- );
98
- } else {
99
- children.push(content);
91
+ for (markKey in MARK_TAGS) {
92
+ if (MARK_TAGS[markKey] === mark.type) {
93
+ const Tag = markKey;
94
+
95
+ children.push(<Tag key={key}>{content}</Tag>);
96
+ break;
97
+ }
100
98
  }
101
99
  } else if (content.length > 0) {
102
100
  children.push(content);
package/LICENSE.md DELETED
@@ -1,5 +0,0 @@
1
- Copyright 2019 CoreSpring Inc
2
-
3
- Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
-
5
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -1 +0,0 @@
1
- {"version":3,"file":"keyboard-coordinates.js","names":["_core","require","_createForOfIteratorHelper","r","e","t","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","_n","F","s","n","done","value","f","TypeError","o","a","u","call","next","_arrayLikeToArray","toString","slice","constructor","name","from","test","CHOICE_BOARD_ID","closestDroppableKeyboardCoordinates","exports","event","_ref","_active$data","active","context","currentCoordinates","code","isTab","KeyboardCode","Tab","isArrow","Down","Up","Left","Right","undefined","defaultKeyboardCoordinateGetter","preventDefault","droppableRects","droppableContainers","collisionRect","size","draggedData","data","current","ownDropId","fromChoice","id","concat","targets","boardTarget","_iterator","_step","_step$value","_slicedToArray2","container","disabled","rect","get","center","x","left","width","y","top","height","dropPosition","target","push","err","reverse","shiftKey","sort","b","Math","abs","draggedCenter","currentIndex","findIndex","right","bottom","minDist","Infinity","i","dist","distance","nextIndex","sqrt","pow"],"sources":["../src/keyboard-coordinates.js"],"sourcesContent":["import { defaultKeyboardCoordinateGetter, KeyboardCode } from '@dnd-kit/core';\n\n// Matches the id `drag-in-the-blank-dp.jsx` registers for the choice board's droppable.\nconst CHOICE_BOARD_ID = 'drag-in-the-blank-droppable';\n\n/**\n * Custom keyboard coordinate getter for drag-in-the-blank's Tab-based placement.\n *\n * Tab/Shift+Tab cycle the dragged item directly onto the next/previous enabled\n * droppable — a blank (`mask-blank-drop-{id}`), sorted by on-screen position\n * (top-to-bottom, then left-to-right, since blanks sit inline in flowing text rather\n * than a simple list) — followed by the choice board as a fixed last stop (see below\n * for why the board isn't sorted alongside the blanks).\n *\n * Arrow keys are delegated to dnd-kit's own `defaultKeyboardCoordinateGetter`, leaving\n * the existing free-form arrow-key dragging behavior completely unchanged.\n */\nexport const closestDroppableKeyboardCoordinates = (event, { active, context, currentCoordinates }) => {\n const { code } = event;\n const isTab = code === KeyboardCode.Tab;\n const isArrow =\n code === KeyboardCode.Down || code === KeyboardCode.Up || code === KeyboardCode.Left || code === KeyboardCode.Right;\n\n if (!isTab && !isArrow) {\n return undefined;\n }\n\n if (isArrow) {\n return defaultKeyboardCoordinateGetter(event, { context, currentCoordinates });\n }\n\n event.preventDefault();\n\n const { droppableRects, droppableContainers, collisionRect } = context;\n\n if (!droppableRects || droppableRects.size === 0) {\n return currentCoordinates;\n }\n\n // A blank is itself a droppable for its own slot (\"mask-blank-drop-{id}\"), and\n // simultaneously draggable from that same slot — the same shape as match-list's\n // placed \"target\" tiles. That self drop-zone must never be treated as a navigable\n // target: exclude it outright rather than relying on a distance threshold.\n const draggedData = active?.data?.current;\n const ownDropId =\n draggedData && draggedData.fromChoice === false && draggedData.id != null\n ? `mask-blank-drop-${draggedData.id}`\n : undefined;\n\n const targets = [];\n let boardTarget;\n\n for (const [id, container] of droppableContainers) {\n if (container?.disabled) continue;\n if (id === ownDropId) continue;\n\n const rect = droppableRects.get(id);\n if (!rect) continue;\n\n const center = {\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n };\n // Land the dragged item's own top-left corner at the target's center-left point,\n // rather than at the target's own top-left corner (avoids overshooting into a\n // neighboring droppable when the target is much wider than the dragged item).\n const dropPosition = {\n x: rect.left,\n y: rect.top + rect.height / 2,\n };\n\n const target = { id, rect, dropPosition, center };\n\n if (id === CHOICE_BOARD_ID) {\n boardTarget = target;\n } else {\n targets.push(target);\n }\n }\n\n if (targets.length === 0 && !boardTarget) {\n return currentCoordinates;\n }\n\n const reverse = event.shiftKey;\n\n targets.sort((a, b) => {\n if (Math.abs(a.center.y - b.center.y) > 10) return a.center.y - b.center.y;\n return a.center.x - b.center.x;\n });\n\n // The choice board can be an arbitrarily large container — e.g. several choices\n // stacked beside the markup (`choicePosition: 'right'`/`'left'`) — so its own center\n // can land anywhere relative to the blanks it sits beside, including numerically\n // between two of them. Sorting it by position the same way as a blank would then\n // interleave it into the middle of the cycle, making a single Tab press jump over\n // more than one blank (confirmed live: with 3 stacked choices beside wrapped text,\n // the board's center fell between blank 2 and blank 3, so the very first Tab press\n // from the pool landed on blank 3, skipping blanks 1 and 2 entirely). Anchor it as a\n // fixed stop after every blank, in every layout, instead of trusting its own bounds.\n if (boardTarget) {\n targets.push(boardTarget);\n }\n\n // Find the current target: whichever target's rect actually contains the dragged\n // item's own center. This holds regardless of how the dragged item's size compares\n // to the target's — a compact chip landed (per `dropPosition` above) at a much wider\n // target's left edge is still contained within that target's rect. Comparing\n // distances between reconstructed centers instead breaks down for exactly that shape\n // (a small item in a much wider target): the reconstructed center can end up closer\n // to a completely different droppable than to the one the item is actually sitting\n // on, so the *next* press re-matches the wrong target and looks like it does nothing.\n const draggedCenter = collisionRect\n ? { x: collisionRect.left + collisionRect.width / 2, y: collisionRect.top + collisionRect.height / 2 }\n : currentCoordinates;\n\n let currentIndex = targets.findIndex(\n (t) =>\n draggedCenter.x >= t.rect.left &&\n draggedCenter.x <= t.rect.right &&\n draggedCenter.y >= t.rect.top &&\n draggedCenter.y <= t.rect.bottom,\n );\n\n // Fall back to nearest-by-dropPosition if the dragged item's center isn't strictly\n // inside any target (e.g. mid-flight after a free arrow-key move).\n if (currentIndex === -1) {\n let minDist = Infinity;\n\n for (let i = 0; i < targets.length; i++) {\n const dist = distance(currentCoordinates, targets[i].dropPosition);\n\n if (dist < minDist) {\n minDist = dist;\n currentIndex = i;\n }\n }\n }\n\n const nextIndex = reverse\n ? (currentIndex - 1 + targets.length) % targets.length\n : (currentIndex + 1) % targets.length;\n\n return targets[nextIndex].dropPosition;\n};\n\nconst distance = (a, b) => Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);\n"],"mappings":";;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAA8E,SAAAC,2B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