@pie-lib/drag 2.19.6-esmbeta.2 → 2.20.0-mui-update.0
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/CHANGELOG.md +37 -0
- package/lib/drag-in-the-blank-dp.js +28 -24
- package/lib/drag-in-the-blank-dp.js.map +1 -1
- package/lib/drag-provider.js +47 -0
- package/lib/drag-provider.js.map +1 -0
- package/lib/drag-type.js +2 -3
- package/lib/drag-type.js.map +1 -1
- package/lib/draggable-choice.js +87 -0
- package/lib/draggable-choice.js.map +1 -0
- package/lib/droppable-placeholder.js +33 -65
- package/lib/droppable-placeholder.js.map +1 -1
- package/lib/ica-dp.js +38 -26
- package/lib/ica-dp.js.map +1 -1
- package/lib/index.js +7 -35
- package/lib/index.js.map +1 -1
- package/lib/match-list-dp.js +38 -26
- package/lib/match-list-dp.js.map +1 -1
- package/lib/placeholder.js +77 -102
- package/lib/placeholder.js.map +1 -1
- package/lib/preview-component.js +67 -107
- package/lib/preview-component.js.map +1 -1
- package/lib/swap.js +1 -7
- package/lib/swap.js.map +1 -1
- package/lib/uid-context.js +4 -18
- package/lib/uid-context.js.map +1 -1
- package/package.json +12 -17
- package/src/drag-in-the-blank-dp.jsx +32 -15
- package/src/drag-provider.jsx +40 -0
- package/src/drag-type.js +1 -1
- package/src/draggable-choice.jsx +87 -0
- package/src/droppable-placeholder.jsx +38 -28
- package/src/ica-dp.jsx +41 -18
- package/src/index.js +4 -8
- package/src/match-list-dp.jsx +41 -18
- package/src/placeholder.jsx +64 -71
- package/src/preview-component.jsx +62 -70
- package/esm/index.js +0 -47146
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -1
- package/lib/choice.js +0 -129
- package/lib/choice.js.map +0 -1
- package/lib/with-drag-context.js +0 -59
- package/lib/with-drag-context.js.map +0 -1
- package/src/choice.jsx +0 -76
- package/src/with-drag-context.js +0 -32
package/src/placeholder.jsx
CHANGED
|
@@ -1,14 +1,66 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { styled } from '@mui/material/styles';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
|
-
import grey from '@material-ui/core/colors/grey';
|
|
6
5
|
import { color } from '@pie-lib/render-ui';
|
|
6
|
+
import { grey } from '@mui/material/colors';
|
|
7
|
+
|
|
8
|
+
const StyledPlaceholder = styled('div')(({ theme }) => ({
|
|
9
|
+
WebkitTouchCallout: 'none',
|
|
10
|
+
WebkitUserSelect: 'none',
|
|
11
|
+
KhtmlUserSelect: 'none',
|
|
12
|
+
MozUserSelect: 'none',
|
|
13
|
+
MsUserSelect: 'none',
|
|
14
|
+
userSelect: 'none',
|
|
15
|
+
width: '100%',
|
|
16
|
+
height: '100%',
|
|
17
|
+
background: color.white(),
|
|
18
|
+
transition: 'background-color 200ms linear, border-color 200ms linear',
|
|
19
|
+
boxSizing: 'border-box',
|
|
20
|
+
display: 'grid',
|
|
21
|
+
gridRowGap: `${theme.spacing(1)}px`,
|
|
22
|
+
gridColumnGap: `${theme.spacing(1)}px`,
|
|
23
|
+
padding: theme.spacing(1),
|
|
24
|
+
border: `2px dashed ${color.black()}`,
|
|
25
|
+
'&.disabled': {
|
|
26
|
+
boxShadow: 'none',
|
|
27
|
+
background: theme.palette.background.paper,
|
|
28
|
+
},
|
|
29
|
+
'&.over': {
|
|
30
|
+
border: `1px solid ${grey[500]}`,
|
|
31
|
+
backgroundColor: `${grey[300]}`,
|
|
32
|
+
},
|
|
33
|
+
'&.board': {
|
|
34
|
+
padding: theme.spacing(1),
|
|
35
|
+
display: 'flex',
|
|
36
|
+
flexWrap: 'wrap',
|
|
37
|
+
alignItems: 'center',
|
|
38
|
+
minHeight: '100px',
|
|
39
|
+
justifyContent: 'center',
|
|
40
|
+
overflow: 'hidden',
|
|
41
|
+
touchAction: 'none',
|
|
42
|
+
backgroundColor: color.backgroundDark(),
|
|
43
|
+
},
|
|
44
|
+
'&.categorizeBoard': {
|
|
45
|
+
padding: theme.spacing(0.5),
|
|
46
|
+
display: 'flex',
|
|
47
|
+
flexWrap: 'wrap',
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
minHeight: '100px',
|
|
50
|
+
justifyContent: 'center',
|
|
51
|
+
overflow: 'hidden',
|
|
52
|
+
touchAction: 'none',
|
|
53
|
+
backgroundColor: color.backgroundDark(),
|
|
54
|
+
},
|
|
55
|
+
'&.verticalPool': {
|
|
56
|
+
display: 'flex',
|
|
57
|
+
flexFlow: 'column wrap',
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
7
60
|
|
|
8
61
|
export const PlaceHolder = (props) => {
|
|
9
62
|
const {
|
|
10
63
|
children,
|
|
11
|
-
classes,
|
|
12
64
|
className,
|
|
13
65
|
isOver,
|
|
14
66
|
type,
|
|
@@ -21,10 +73,10 @@ export const PlaceHolder = (props) => {
|
|
|
21
73
|
} = props;
|
|
22
74
|
|
|
23
75
|
const names = classNames(
|
|
24
|
-
|
|
25
|
-
disabled &&
|
|
26
|
-
isOver &&
|
|
27
|
-
|
|
76
|
+
'placeholder',
|
|
77
|
+
disabled && 'disabled',
|
|
78
|
+
isOver && 'over',
|
|
79
|
+
type,
|
|
28
80
|
className,
|
|
29
81
|
);
|
|
30
82
|
|
|
@@ -49,24 +101,22 @@ export const PlaceHolder = (props) => {
|
|
|
49
101
|
style.background = color.backgroundDark();
|
|
50
102
|
}
|
|
51
103
|
|
|
52
|
-
const boardStyle = isCategorize ?
|
|
104
|
+
const boardStyle = isCategorize ? 'categorizeBoard' : 'board';
|
|
53
105
|
|
|
54
106
|
return (
|
|
55
|
-
<
|
|
107
|
+
<StyledPlaceholder
|
|
56
108
|
style={{ ...style, minHeight: minHeight }}
|
|
57
109
|
className={classNames(
|
|
58
|
-
classes.noSelectStyles,
|
|
59
110
|
choiceBoard ? boardStyle : names,
|
|
60
|
-
isVerticalPool &&
|
|
111
|
+
isVerticalPool && 'verticalPool',
|
|
61
112
|
)}
|
|
62
113
|
>
|
|
63
114
|
{children}
|
|
64
|
-
</
|
|
115
|
+
</StyledPlaceholder>
|
|
65
116
|
);
|
|
66
117
|
};
|
|
67
118
|
|
|
68
119
|
PlaceHolder.propTypes = {
|
|
69
|
-
classes: PropTypes.object.isRequired,
|
|
70
120
|
choiceBoard: PropTypes.bool,
|
|
71
121
|
grid: PropTypes.shape({
|
|
72
122
|
columns: PropTypes.number,
|
|
@@ -85,61 +135,4 @@ PlaceHolder.propTypes = {
|
|
|
85
135
|
minHeight: PropTypes.number,
|
|
86
136
|
};
|
|
87
137
|
|
|
88
|
-
|
|
89
|
-
noSelectStyles: {
|
|
90
|
-
WebkitTouchCallout: 'none',
|
|
91
|
-
WebkitUserSelect: 'none',
|
|
92
|
-
KhtmlUserSelect: 'none',
|
|
93
|
-
MozUserSelect: 'none',
|
|
94
|
-
MsUserSelect: 'none',
|
|
95
|
-
userSelect: 'none',
|
|
96
|
-
},
|
|
97
|
-
placeholder: {
|
|
98
|
-
width: '100%',
|
|
99
|
-
height: '100%',
|
|
100
|
-
background: color.white(),
|
|
101
|
-
transition: 'background-color 200ms linear, border-color 200ms linear',
|
|
102
|
-
boxSizing: 'border-box',
|
|
103
|
-
display: 'grid',
|
|
104
|
-
gridRowGap: `${theme.spacing.unit}px`,
|
|
105
|
-
gridColumnGap: `${theme.spacing.unit}px`,
|
|
106
|
-
padding: theme.spacing.unit * 1,
|
|
107
|
-
border: `2px dashed ${color.black()}`,
|
|
108
|
-
},
|
|
109
|
-
disabled: {
|
|
110
|
-
boxShadow: 'none',
|
|
111
|
-
background: theme.palette.background.paper,
|
|
112
|
-
},
|
|
113
|
-
over: {
|
|
114
|
-
border: `1px solid ${grey[500]}`,
|
|
115
|
-
backgroundColor: `${grey[300]}`,
|
|
116
|
-
},
|
|
117
|
-
board: {
|
|
118
|
-
padding: theme.spacing.unit,
|
|
119
|
-
display: 'flex',
|
|
120
|
-
flexWrap: 'wrap',
|
|
121
|
-
alignItems: 'center',
|
|
122
|
-
minHeight: '100px',
|
|
123
|
-
justifyContent: 'center',
|
|
124
|
-
overflow: 'hidden',
|
|
125
|
-
touchAction: 'none',
|
|
126
|
-
backgroundColor: color.backgroundDark(),
|
|
127
|
-
},
|
|
128
|
-
categorizeBoard: {
|
|
129
|
-
padding: theme.spacing.unit / 2,
|
|
130
|
-
display: 'flex',
|
|
131
|
-
flexWrap: 'wrap',
|
|
132
|
-
alignItems: 'center',
|
|
133
|
-
minHeight: '100px',
|
|
134
|
-
justifyContent: 'center',
|
|
135
|
-
overflow: 'hidden',
|
|
136
|
-
touchAction: 'none',
|
|
137
|
-
backgroundColor: color.backgroundDark(),
|
|
138
|
-
},
|
|
139
|
-
verticalPool: {
|
|
140
|
-
display: 'flex',
|
|
141
|
-
flexFlow: 'column wrap',
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
export default withStyles(styles)(PlaceHolder);
|
|
138
|
+
export default PlaceHolder;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState
|
|
2
|
-
import {
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { DragOverlay, useDndContext } from '@dnd-kit/core';
|
|
3
3
|
import { PreviewPrompt, color } from '@pie-lib/render-ui';
|
|
4
4
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
5
5
|
|
|
@@ -54,99 +54,91 @@ const styles = {
|
|
|
54
54
|
},
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
const getPrompt = (
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const getPrompt = (dragData) => {
|
|
58
|
+
if (!dragData) return undefined;
|
|
59
|
+
|
|
60
|
+
// Handle different drag data structures based on the component type
|
|
61
|
+
if (dragData.choiceId) {
|
|
62
|
+
// DraggableChoice format
|
|
63
|
+
return dragData.value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Legacy format support
|
|
67
|
+
switch (dragData.itemType) {
|
|
60
68
|
case 'MaskBlank':
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return item?.value;
|
|
65
|
-
// MATCH-LIST
|
|
69
|
+
return dragData.choice?.value;
|
|
70
|
+
case 'dnd-kit-response':
|
|
71
|
+
return dragData.value;
|
|
66
72
|
case 'Answer':
|
|
67
|
-
return
|
|
68
|
-
// PLACEMENT-ORDERING
|
|
73
|
+
return dragData.value;
|
|
69
74
|
case 'Tile':
|
|
70
|
-
return
|
|
75
|
+
return dragData.value;
|
|
76
|
+
case 'categorize':
|
|
77
|
+
return dragData.value;
|
|
71
78
|
default:
|
|
72
|
-
return
|
|
79
|
+
return dragData.value;
|
|
73
80
|
}
|
|
74
81
|
};
|
|
75
82
|
|
|
76
|
-
const getCustomStyle = (
|
|
77
|
-
|
|
78
|
-
const top = style?.top || 0;
|
|
79
|
-
const left = style?.left || 0;
|
|
80
|
-
const position = style?.position || 'fixed';
|
|
83
|
+
const getCustomStyle = (dragData) => {
|
|
84
|
+
if (!dragData) return {};
|
|
81
85
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
transform,
|
|
87
|
-
...(itemType === 'MaskBlank' ? styles.maskBlank : {}),
|
|
88
|
-
...(item?.itemType === 'categorize' ? styles.categorize : {}),
|
|
89
|
-
...(itemType === 'Answer' ? styles.matchList : {}),
|
|
90
|
-
...(itemType === 'Tile' ? styles.placementOrdering : {}),
|
|
91
|
-
...(itemType === 'react-dnd-response' ? styles.ica : {}),
|
|
86
|
+
const baseStyle = {
|
|
87
|
+
cursor: 'grabbing',
|
|
88
|
+
opacity: 0.8,
|
|
89
|
+
transform: 'rotate(5deg)', // Slight rotation for visual feedback
|
|
92
90
|
};
|
|
91
|
+
|
|
92
|
+
// Apply specific styles based on item type
|
|
93
|
+
if (dragData.itemType === 'MaskBlank') {
|
|
94
|
+
return { ...baseStyle, ...styles.maskBlank };
|
|
95
|
+
}
|
|
96
|
+
if (dragData.itemType === 'categorize') {
|
|
97
|
+
return { ...baseStyle, ...styles.categorize };
|
|
98
|
+
}
|
|
99
|
+
if (dragData.itemType === 'Answer') {
|
|
100
|
+
return { ...baseStyle, ...styles.matchList };
|
|
101
|
+
}
|
|
102
|
+
if (dragData.itemType === 'Tile') {
|
|
103
|
+
return { ...baseStyle, ...styles.placementOrdering };
|
|
104
|
+
}
|
|
105
|
+
if (dragData.itemType === 'dnd-kit-response') {
|
|
106
|
+
return { ...baseStyle, ...styles.ica };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Default style for choice items
|
|
110
|
+
return { ...baseStyle, ...styles.categorize };
|
|
93
111
|
};
|
|
94
112
|
|
|
95
113
|
const PreviewComponent = () => {
|
|
96
|
-
const
|
|
97
|
-
const { itemType, item, style, display } = preview;
|
|
98
|
-
const [touchPosition, setTouchPosition] = useState({ x: 0, y: 0 });
|
|
114
|
+
const { active } = useDndContext();
|
|
99
115
|
const [zoomLevel, setZoomLevel] = useState(1);
|
|
100
|
-
|
|
101
|
-
const handleTouchMove = useCallback(
|
|
102
|
-
(event) => {
|
|
103
|
-
if (event.touches.length > 0) {
|
|
104
|
-
const touch = event.touches[0];
|
|
105
|
-
const touchOffset = 1;
|
|
106
|
-
setTouchPosition({
|
|
107
|
-
x: (touch.clientX + touchOffset) / zoomLevel,
|
|
108
|
-
y: (touch.clientY + touchOffset) / zoomLevel,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
[zoomLevel],
|
|
113
|
-
);
|
|
114
|
-
|
|
115
116
|
const root = useRef(null);
|
|
116
117
|
|
|
118
|
+
const dragData = active?.data?.current;
|
|
119
|
+
const isActive = !!active;
|
|
120
|
+
|
|
117
121
|
useEffect(() => {
|
|
118
|
-
if (
|
|
122
|
+
if (isActive && root.current) {
|
|
119
123
|
renderMath(root.current);
|
|
120
124
|
|
|
121
125
|
// Adjusted for precise zoom level calculation in Online Testing, targeting the specific class pattern .asmt-zoomable.asmt-zoom-NR .asmt-question .padding
|
|
122
126
|
const zoomAffectedElement = document.querySelector('.padding') || document.body;
|
|
123
|
-
|
|
124
127
|
setZoomLevel(parseFloat(getComputedStyle(zoomAffectedElement).zoom) || 1);
|
|
125
128
|
}
|
|
126
|
-
}, [
|
|
127
|
-
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
const touchMoveListener = (event) => handleTouchMove(event);
|
|
130
|
-
if (display) {
|
|
131
|
-
window.addEventListener('touchmove', touchMoveListener);
|
|
132
|
-
}
|
|
133
|
-
return () => {
|
|
134
|
-
window.removeEventListener('touchmove', touchMoveListener);
|
|
135
|
-
};
|
|
136
|
-
}, [display, handleTouchMove]);
|
|
137
|
-
|
|
138
|
-
if (!display) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const customStyle = getCustomStyle(itemType, item, touchPosition, style);
|
|
129
|
+
}, [isActive, dragData]);
|
|
143
130
|
|
|
144
|
-
const
|
|
131
|
+
const customStyle = getCustomStyle(dragData);
|
|
132
|
+
const prompt = getPrompt(dragData);
|
|
145
133
|
|
|
146
134
|
return (
|
|
147
|
-
<
|
|
148
|
-
|
|
149
|
-
|
|
135
|
+
<DragOverlay>
|
|
136
|
+
{isActive && prompt && (
|
|
137
|
+
<div ref={root} style={customStyle}>
|
|
138
|
+
<PreviewPrompt className="label" prompt={prompt} tagName="span" />
|
|
139
|
+
</div>
|
|
140
|
+
)}
|
|
141
|
+
</DragOverlay>
|
|
150
142
|
);
|
|
151
143
|
};
|
|
152
144
|
|