@pie-lib/drag 4.0.7-next.58 → 4.1.0-next.40

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 (69) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist/drag-in-the-blank-dp.d.ts +29 -0
  3. package/dist/drag-in-the-blank-dp.js +44 -0
  4. package/dist/drag-provider.d.ts +41 -0
  5. package/dist/drag-provider.js +46 -0
  6. package/dist/drag-type.d.ts +16 -0
  7. package/dist/draggable-choice.d.ts +43 -0
  8. package/dist/draggable-choice.js +63 -0
  9. package/dist/droppable-placeholder.d.ts +29 -0
  10. package/dist/droppable-placeholder.js +36 -0
  11. package/dist/ica-dp.d.ts +24 -0
  12. package/dist/ica-dp.js +20 -0
  13. package/dist/index.d.ts +17 -0
  14. package/dist/index.js +9 -0
  15. package/dist/match-list-dp.d.ts +26 -0
  16. package/dist/match-list-dp.js +21 -0
  17. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  18. package/dist/placeholder.d.ts +31 -0
  19. package/dist/placeholder.js +97 -0
  20. package/dist/preview-component.d.ts +11 -0
  21. package/dist/swap.d.ts +10 -0
  22. package/dist/swap.js +9 -0
  23. package/dist/uid-context.d.ts +13 -0
  24. package/dist/uid-context.js +15 -0
  25. package/package.json +38 -15
  26. package/CHANGELOG.json +0 -1
  27. package/CHANGELOG.md +0 -822
  28. package/LICENSE.md +0 -5
  29. package/lib/drag-in-the-blank-dp.js +0 -66
  30. package/lib/drag-in-the-blank-dp.js.map +0 -1
  31. package/lib/drag-provider.js +0 -95
  32. package/lib/drag-provider.js.map +0 -1
  33. package/lib/drag-type.js +0 -14
  34. package/lib/drag-type.js.map +0 -1
  35. package/lib/draggable-choice.js +0 -95
  36. package/lib/draggable-choice.js.map +0 -1
  37. package/lib/droppable-placeholder.js +0 -50
  38. package/lib/droppable-placeholder.js.map +0 -1
  39. package/lib/ica-dp.js +0 -37
  40. package/lib/ica-dp.js.map +0 -1
  41. package/lib/index.js +0 -61
  42. package/lib/index.js.map +0 -1
  43. package/lib/match-list-dp.js +0 -49
  44. package/lib/match-list-dp.js.map +0 -1
  45. package/lib/placeholder.js +0 -131
  46. package/lib/placeholder.js.map +0 -1
  47. package/lib/preview-component.js +0 -154
  48. package/lib/preview-component.js.map +0 -1
  49. package/lib/swap.js +0 -18
  50. package/lib/swap.js.map +0 -1
  51. package/lib/uid-context.js +0 -26
  52. package/lib/uid-context.js.map +0 -1
  53. package/src/__tests__/drag-provider.test.jsx +0 -395
  54. package/src/__tests__/placeholder.test.jsx +0 -107
  55. package/src/__tests__/preview-component.test.jsx +0 -537
  56. package/src/__tests__/swap.test.js +0 -161
  57. package/src/__tests__/uid-context.test.jsx +0 -54
  58. package/src/drag-in-the-blank-dp.jsx +0 -65
  59. package/src/drag-provider.jsx +0 -90
  60. package/src/drag-type.js +0 -7
  61. package/src/draggable-choice.jsx +0 -83
  62. package/src/droppable-placeholder.jsx +0 -41
  63. package/src/ica-dp.jsx +0 -25
  64. package/src/index.js +0 -19
  65. package/src/match-list-dp.jsx +0 -36
  66. package/src/placeholder.jsx +0 -138
  67. package/src/preview-component.jsx +0 -145
  68. package/src/swap.js +0 -14
  69. package/src/uid-context.js +0 -13
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { Provider as UidProvider, withUid } from '../uid-context';
4
-
5
- describe('uid-context', () => {
6
- describe('withUid', () => {
7
- it('provides uid to wrapped component', () => {
8
- const TestComponent = ({ uid }) => <div data-testid="test-uid">{uid}</div>;
9
- const WrappedComponent = withUid(TestComponent);
10
-
11
- render(
12
- <UidProvider value="test-uid-123">
13
- <WrappedComponent />
14
- </UidProvider>,
15
- );
16
-
17
- expect(screen.getByTestId('test-uid')).toHaveTextContent('test-uid-123');
18
- });
19
-
20
- it('passes through other props to wrapped component', () => {
21
- const TestComponent = ({ uid, customProp }) => (
22
- <div>
23
- <span data-testid="uid">{uid}</span>
24
- <span data-testid="custom">{customProp}</span>
25
- </div>
26
- );
27
- const WrappedComponent = withUid(TestComponent);
28
-
29
- render(
30
- <UidProvider value="test-uid">
31
- <WrappedComponent customProp="custom-value" />
32
- </UidProvider>,
33
- );
34
-
35
- expect(screen.getByTestId('uid')).toHaveTextContent('test-uid');
36
- expect(screen.getByTestId('custom')).toHaveTextContent('custom-value');
37
- });
38
- });
39
-
40
- describe('UidProvider', () => {
41
- it('provides uid context to children', () => {
42
- const TestComponent = ({ uid }) => <div data-testid="uid-value">{uid}</div>;
43
- const WrappedComponent = withUid(TestComponent);
44
-
45
- render(
46
- <UidProvider value="provider-uid">
47
- <WrappedComponent />
48
- </UidProvider>,
49
- );
50
-
51
- expect(screen.getByTestId('uid-value')).toHaveTextContent('provider-uid');
52
- });
53
- });
54
- });
@@ -1,65 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import PlaceHolder from './placeholder';
4
- import { useDroppable } from '@dnd-kit/core';
5
- import { styled } from '@mui/material/styles';
6
-
7
- // With @dnd-kit, the drop logic is handled in the DragProvider's onDragEnd callback
8
- // This component now just wraps DroppablePlaceholder with drag-in-the-blank specific logic
9
-
10
- const DroppablePlaceholderContainer = styled('div')({
11
- minHeight: '100px',
12
- });
13
-
14
- export function DragInTheBlankDroppable({
15
- children,
16
- disabled,
17
- classes,
18
- isVerticalPool,
19
- minHeight,
20
- instanceId,
21
- ...rest
22
- }) {
23
- // The actual drop handling will be managed by the parent component
24
- // through the DragProvider's onDragEnd callback
25
- const { setNodeRef, isOver } = useDroppable({
26
- id: 'drag-in-the-blank-droppable',
27
- data: {
28
- type: 'MaskBlank',
29
- accepts: ['MaskBlank'],
30
- id: 'drag-in-the-blank-droppable',
31
- toChoiceBoard: true,
32
- instanceId,
33
- },
34
- });
35
-
36
- return (
37
- <div ref={setNodeRef}>
38
- <DroppablePlaceholderContainer>
39
- <PlaceHolder
40
- isOver={isOver}
41
- choiceBoard={true}
42
- className={classes}
43
- isVerticalPool={isVerticalPool}
44
- extraStyles={{
45
- width: '100%',
46
- minHeight: minHeight || 100,
47
- height: 'auto',
48
- }}
49
- >
50
- {children}
51
- </PlaceHolder>
52
- </DroppablePlaceholderContainer>
53
- </div>
54
- );
55
- }
56
-
57
- DragInTheBlankDroppable.propTypes = {
58
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
59
- children: PropTypes.node,
60
- disabled: PropTypes.bool,
61
- onDrop: PropTypes.func,
62
- instanceId: PropTypes.string,
63
- };
64
-
65
- export default DragInTheBlankDroppable;
@@ -1,90 +0,0 @@
1
- import React, { useState } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
4
-
5
- export function DragProvider({
6
- children,
7
- onDragEnd,
8
- onDragStart,
9
- onDragCancel,
10
- collisionDetection,
11
- modifiers,
12
- autoScroll,
13
- keyboardCoordinateGetter,
14
- keyboardCodes,
15
- accessibility,
16
- }) {
17
- const [activeId, setActiveId] = useState(null);
18
-
19
- // Only build a keyboard sensor options object when a consumer actually customizes
20
- // it, so consumers that don't pass these props get dnd-kit's own defaults exactly
21
- // as before (arrow-key nudging, Tab ends the drag, etc.).
22
- const keyboardSensorOptions =
23
- keyboardCoordinateGetter || keyboardCodes ? { coordinateGetter: keyboardCoordinateGetter, keyboardCodes } : undefined;
24
-
25
- const sensors = useSensors(
26
- useSensor(PointerSensor, { activationConstraint: { distance: 8 } }),
27
- useSensor(KeyboardSensor, keyboardSensorOptions),
28
- );
29
-
30
- const handleDragStart = (event) => {
31
- setActiveId(event.active.id);
32
- if (onDragStart) {
33
- onDragStart(event);
34
- }
35
- };
36
-
37
- const handleDragEnd = (event) => {
38
- setActiveId(null);
39
- if (onDragEnd) {
40
- onDragEnd(event);
41
- }
42
- };
43
-
44
- const handleDragCancel = (event) => {
45
- setActiveId(null);
46
- if (onDragCancel) {
47
- onDragCancel(event);
48
- }
49
- };
50
-
51
- return (
52
- <DndContext
53
- sensors={sensors}
54
- onDragStart={handleDragStart}
55
- onDragEnd={handleDragEnd}
56
- onDragCancel={handleDragCancel}
57
- collisionDetection={collisionDetection}
58
- modifiers={modifiers}
59
- autoScroll={autoScroll}
60
- accessibility={accessibility}
61
- >
62
- {children}
63
- </DndContext>
64
- );
65
- }
66
-
67
- DragProvider.propTypes = {
68
- children: PropTypes.node.isRequired,
69
- onDragEnd: PropTypes.func,
70
- onDragStart: PropTypes.func,
71
- onDragCancel: PropTypes.func,
72
- collisionDetection: PropTypes.func,
73
- modifiers: PropTypes.arrayOf(PropTypes.func),
74
- autoScroll: PropTypes.object,
75
- // Custom dnd-kit KeyboardSensor coordinateGetter (e.g. for Tab/Shift+Tab-based placement).
76
- // Omit to keep dnd-kit's default keyboard-dragging behavior.
77
- keyboardCoordinateGetter: PropTypes.func,
78
- // Overrides for dnd-kit's KeyboardSensor keyboardCodes (start/cancel/end).
79
- // Omit to keep dnd-kit's defaults.
80
- keyboardCodes: PropTypes.shape({
81
- start: PropTypes.arrayOf(PropTypes.string),
82
- cancel: PropTypes.arrayOf(PropTypes.string),
83
- end: PropTypes.arrayOf(PropTypes.string),
84
- }),
85
- // Passed straight through to dnd-kit's DndContext (screenReaderInstructions,
86
- // announcements, container). Omit to keep dnd-kit's defaults.
87
- accessibility: PropTypes.object,
88
- };
89
-
90
- export default DragProvider;
package/src/drag-type.js DELETED
@@ -1,7 +0,0 @@
1
- export default {
2
- types: {
3
- ica: 'dnd-kit-response',
4
- ml: 'Answer',
5
- db: 'MaskBlank',
6
- },
7
- };
@@ -1,83 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { styled } from '@mui/material/styles';
4
- import { useDraggable } from '@dnd-kit/core';
5
- import { grey } from '@mui/material/colors';
6
-
7
- export const DRAG_TYPE = 'CHOICE';
8
-
9
- const StyledChoice = styled('div')(({ theme }) => ({
10
- backgroundColor: theme.palette.background.paper,
11
- border: `solid 1px ${grey[400]}`,
12
- padding: theme.spacing(1),
13
- minHeight: '30px',
14
- minWidth: theme.spacing(20),
15
- maxWidth: theme.spacing(75),
16
- cursor: 'grab',
17
- '& p': {
18
- margin: 0,
19
- },
20
- '& p *': {
21
- margin: 0,
22
- },
23
- '&:active': {
24
- cursor: 'grabbing',
25
- },
26
- }));
27
-
28
- export function DraggableChoice({
29
- choice,
30
- children,
31
- className,
32
- disabled,
33
- category,
34
- alternateResponseIndex,
35
- choiceIndex,
36
- onRemoveChoice,
37
- type,
38
- id,
39
- }) {
40
- const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
41
- id: id || choice.id, // id to be used for dnd-kit
42
- disabled: disabled,
43
- categoryId: category?.id,
44
- alternateResponseIndex,
45
- data: {
46
- id: choice.id,
47
- value: choice.value,
48
- choiceId: choice.id,
49
- from: category?.id,
50
- categoryId: category?.id,
51
- alternateResponseIndex,
52
- choiceIndex,
53
- onRemoveChoice,
54
- type,
55
- },
56
- });
57
-
58
- return (
59
- <StyledChoice ref={setNodeRef} className={className} isDragging={isDragging} {...attributes} {...listeners}>
60
- {children}
61
- </StyledChoice>
62
- );
63
- }
64
-
65
- DraggableChoice.propTypes = {
66
- choice: PropTypes.shape({
67
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
68
- value: PropTypes.any,
69
- }).isRequired,
70
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
71
- className: PropTypes.string,
72
- disabled: PropTypes.bool,
73
- category: PropTypes.shape({
74
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
75
- }),
76
- alternateResponseIndex: PropTypes.number,
77
- choiceIndex: PropTypes.number,
78
- onRemoveChoice: PropTypes.func,
79
- type: PropTypes.string,
80
- id: PropTypes.string,
81
- };
82
-
83
- export default DraggableChoice;
@@ -1,41 +0,0 @@
1
- import React from 'react';
2
- import PlaceHolder from './placeholder';
3
- import PropTypes from 'prop-types';
4
- import { useDroppable } from '@dnd-kit/core';
5
-
6
- const preventInteractionStyle = {
7
- flex: 1,
8
- };
9
-
10
- export function DroppablePlaceholder({ id, children, disabled, classes, isVerticalPool, minHeight }) {
11
- const { setNodeRef, isOver } = useDroppable({
12
- id,
13
- disabled,
14
- });
15
-
16
- return (
17
- <div ref={setNodeRef} style={preventInteractionStyle}>
18
- <PlaceHolder
19
- disabled={disabled}
20
- isOver={isOver}
21
- choiceBoard={true}
22
- className={classes}
23
- isVerticalPool={isVerticalPool}
24
- minHeight={minHeight}
25
- >
26
- {children}
27
- </PlaceHolder>
28
- </div>
29
- );
30
- }
31
-
32
- DroppablePlaceholder.propTypes = {
33
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
34
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
35
- disabled: PropTypes.bool,
36
- classes: PropTypes.object,
37
- isVerticalPool: PropTypes.bool,
38
- minHeight: PropTypes.number,
39
- };
40
-
41
- export default DroppablePlaceholder;
package/src/ica-dp.jsx DELETED
@@ -1,25 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { DroppablePlaceholder } from './droppable-placeholder';
4
-
5
- // With @dnd-kit, the drop logic is handled in the DragProvider's onDragEnd callback
6
- // This component now just wraps DroppablePlaceholder with ICA specific logic
7
-
8
- export function ICADroppable({ id, children, disabled, ...rest }) {
9
- // The actual drop handling will be managed by the parent component
10
- // through the DragProvider's onDragEnd callback
11
-
12
- return (
13
- <DroppablePlaceholder id={id} disabled={disabled} {...rest}>
14
- {children}
15
- </DroppablePlaceholder>
16
- );
17
- }
18
-
19
- ICADroppable.propTypes = {
20
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
21
- children: PropTypes.node,
22
- disabled: PropTypes.bool,
23
- };
24
-
25
- export default ICADroppable;
package/src/index.js DELETED
@@ -1,19 +0,0 @@
1
- import PlaceHolder from './placeholder';
2
- import DraggableChoice from './draggable-choice';
3
- import DragProvider from './drag-provider';
4
- import swap from './swap';
5
- import * as uid from './uid-context';
6
- import MatchDroppablePlaceholder from './match-list-dp';
7
- import DragDroppablePlaceholder from './drag-in-the-blank-dp';
8
- import ICADroppablePlaceholder from './ica-dp';
9
-
10
- export {
11
- PlaceHolder,
12
- MatchDroppablePlaceholder,
13
- DragDroppablePlaceholder,
14
- ICADroppablePlaceholder,
15
- DragProvider,
16
- DraggableChoice,
17
- swap,
18
- uid,
19
- };
@@ -1,36 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { DroppablePlaceholder } from './droppable-placeholder';
4
-
5
- // With @dnd-kit, the drop logic is handled in the DragProvider's onDragEnd callback
6
- // This component now just wraps DroppablePlaceholder with match-list specific logic
7
-
8
- export function MatchListDroppable({ id, children, disabled, onRemoveAnswer, ...rest }) {
9
- // The actual drop handling will be managed by the parent component
10
- // through the DragProvider's onDragEnd callback
11
- // The onRemoveAnswer logic should be handled in the parent's onDragEnd:
12
- //
13
- // const handleDragEnd = (event) => {
14
- // if (event.over && event.active) {
15
- // const item = event.active.data.current;
16
- // if (onRemoveAnswer) {
17
- // onRemoveAnswer(item.promptId);
18
- // }
19
- // }
20
- // };
21
-
22
- return (
23
- <DroppablePlaceholder id={id} disabled={disabled} {...rest}>
24
- {children}
25
- </DroppablePlaceholder>
26
- );
27
- }
28
-
29
- MatchListDroppable.propTypes = {
30
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
31
- children: PropTypes.node,
32
- disabled: PropTypes.bool,
33
- onRemoveAnswer: PropTypes.func,
34
- };
35
-
36
- export default MatchListDroppable;
@@ -1,138 +0,0 @@
1
- import React from 'react';
2
- import { styled } from '@mui/material/styles';
3
- import classNames from 'classnames';
4
- import PropTypes from 'prop-types';
5
- import { color } from '@pie-lib/render-ui';
6
- import { grey } from '@mui/material/colors';
7
-
8
- const StyledPlaceholder = styled('div')(({ theme }) => ({
9
- '&.placeholder': {
10
- WebkitTouchCallout: 'none',
11
- WebkitUserSelect: 'none',
12
- KhtmlUserSelect: 'none',
13
- MozUserSelect: 'none',
14
- MsUserSelect: 'none',
15
- userSelect: 'none',
16
- width: '100%',
17
- height: '100%',
18
- background: color.white(),
19
- transition: 'background-color 200ms linear, border-color 200ms linear',
20
- boxSizing: 'border-box',
21
- display: 'grid',
22
- gridRowGap: theme.spacing(1),
23
- gridColumnGap: theme.spacing(1),
24
- padding: theme.spacing(1),
25
- border: `2px dashed ${color.black()}`,
26
- },
27
- '&.placeholderDisabled': {
28
- boxShadow: 'none',
29
- background: theme.palette.background.paper,
30
- },
31
- '&.over': {
32
- border: `1px solid ${grey[500]}`,
33
- backgroundColor: `${grey[300]}`,
34
- },
35
- '&.board': {
36
- padding: theme.spacing(1),
37
- display: 'flex',
38
- flexWrap: 'wrap',
39
- alignItems: 'center',
40
- minHeight: '100px',
41
- justifyContent: 'center',
42
- overflow: 'hidden',
43
- touchAction: 'none',
44
- backgroundColor: color.backgroundDark(),
45
- },
46
- '&.categorizeBoard': {
47
- padding: theme.spacing(0.5),
48
- display: 'flex',
49
- flexWrap: 'wrap',
50
- alignItems: 'center',
51
- minHeight: '100px',
52
- justifyContent: 'center',
53
- overflow: 'hidden',
54
- touchAction: 'none',
55
- backgroundColor: color.backgroundDark(),
56
- },
57
- '&.verticalPool': {
58
- display: 'flex',
59
- flexFlow: 'column wrap',
60
- },
61
- }));
62
-
63
- export const PlaceHolder = (props) => {
64
- const {
65
- children,
66
- className,
67
- isOver,
68
- type,
69
- grid,
70
- disabled,
71
- choiceBoard,
72
- isCategorize,
73
- isVerticalPool,
74
- minHeight,
75
- extraStyles,
76
- } = props;
77
-
78
- const names = classNames(
79
- 'placeholder',
80
- disabled && 'placeholderDisabled',
81
- isOver && 'over',
82
- type,
83
- className,
84
- );
85
-
86
- const style = {};
87
-
88
- if (grid && grid.columns) {
89
- style.gridTemplateColumns = `repeat(${grid.columns}, 1fr)`;
90
- }
91
-
92
- if (grid && grid.rows) {
93
- const repeatValue = grid.rowsRepeatValue || '1fr';
94
-
95
- style.gridTemplateRows = `repeat(${grid.rows}, ${repeatValue})`;
96
- }
97
-
98
- // The "type" is only sent through placement-ordering / placeholder
99
- // It can be "choice" or "target"
100
- // We apply a different style for the "choice" type
101
- // For any other type, use a dashed black border and a white fill
102
- if (type === 'choice') {
103
- style.border = `1px solid ${color.borderLight()}`;
104
- style.background = color.backgroundDark();
105
- }
106
-
107
- const boardStyle = isCategorize ? 'categorizeBoard' : 'board';
108
-
109
- return (
110
- <StyledPlaceholder
111
- style={{ ...style, minHeight: minHeight, ...extraStyles }}
112
- className={classNames(choiceBoard ? boardStyle : names, isVerticalPool && 'verticalPool')}
113
- >
114
- {children}
115
- </StyledPlaceholder>
116
- );
117
- };
118
-
119
- PlaceHolder.propTypes = {
120
- choiceBoard: PropTypes.bool,
121
- grid: PropTypes.shape({
122
- columns: PropTypes.number,
123
- rows: PropTypes.number,
124
- // if a different value then 1fr is wanted
125
- rowsRepeatValue: PropTypes.string,
126
- }),
127
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
128
- className: PropTypes.string,
129
- isOver: PropTypes.bool,
130
- index: PropTypes.number,
131
- type: PropTypes.string,
132
- disabled: PropTypes.bool,
133
- isCategorize: PropTypes.bool,
134
- isVerticalPool: PropTypes.bool,
135
- minHeight: PropTypes.number,
136
- };
137
-
138
- export default PlaceHolder;