@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.
- package/dist/_virtual/_rolldown/runtime.js +11 -0
- package/dist/drag-in-the-blank-dp.d.ts +29 -0
- package/dist/drag-in-the-blank-dp.js +44 -0
- package/dist/drag-provider.d.ts +41 -0
- package/dist/drag-provider.js +46 -0
- package/dist/drag-type.d.ts +16 -0
- package/dist/draggable-choice.d.ts +43 -0
- package/dist/draggable-choice.js +63 -0
- package/dist/droppable-placeholder.d.ts +29 -0
- package/dist/droppable-placeholder.js +36 -0
- package/dist/ica-dp.d.ts +24 -0
- package/dist/ica-dp.js +20 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +9 -0
- package/dist/match-list-dp.d.ts +26 -0
- package/dist/match-list-dp.js +21 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/placeholder.d.ts +31 -0
- package/dist/placeholder.js +97 -0
- package/dist/preview-component.d.ts +11 -0
- package/dist/swap.d.ts +10 -0
- package/dist/swap.js +9 -0
- package/dist/uid-context.d.ts +13 -0
- package/dist/uid-context.js +15 -0
- package/package.json +38 -15
- package/CHANGELOG.json +0 -1
- package/CHANGELOG.md +0 -822
- package/LICENSE.md +0 -5
- package/lib/drag-in-the-blank-dp.js +0 -66
- package/lib/drag-in-the-blank-dp.js.map +0 -1
- package/lib/drag-provider.js +0 -95
- package/lib/drag-provider.js.map +0 -1
- package/lib/drag-type.js +0 -14
- package/lib/drag-type.js.map +0 -1
- package/lib/draggable-choice.js +0 -95
- package/lib/draggable-choice.js.map +0 -1
- package/lib/droppable-placeholder.js +0 -50
- package/lib/droppable-placeholder.js.map +0 -1
- package/lib/ica-dp.js +0 -37
- package/lib/ica-dp.js.map +0 -1
- package/lib/index.js +0 -61
- package/lib/index.js.map +0 -1
- package/lib/match-list-dp.js +0 -49
- package/lib/match-list-dp.js.map +0 -1
- package/lib/placeholder.js +0 -131
- package/lib/placeholder.js.map +0 -1
- package/lib/preview-component.js +0 -154
- package/lib/preview-component.js.map +0 -1
- package/lib/swap.js +0 -18
- package/lib/swap.js.map +0 -1
- package/lib/uid-context.js +0 -26
- package/lib/uid-context.js.map +0 -1
- package/src/__tests__/drag-provider.test.jsx +0 -395
- package/src/__tests__/placeholder.test.jsx +0 -107
- package/src/__tests__/preview-component.test.jsx +0 -537
- package/src/__tests__/swap.test.js +0 -161
- package/src/__tests__/uid-context.test.jsx +0 -54
- package/src/drag-in-the-blank-dp.jsx +0 -65
- package/src/drag-provider.jsx +0 -90
- package/src/drag-type.js +0 -7
- package/src/draggable-choice.jsx +0 -83
- package/src/droppable-placeholder.jsx +0 -41
- package/src/ica-dp.jsx +0 -25
- package/src/index.js +0 -19
- package/src/match-list-dp.jsx +0 -36
- package/src/placeholder.jsx +0 -138
- package/src/preview-component.jsx +0 -145
- package/src/swap.js +0 -14
- package/src/uid-context.js +0 -13
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { DragOverlay, useDndContext } from '@dnd-kit/core';
|
|
3
|
-
import { color, PreviewPrompt } from '@pie-lib/render-ui';
|
|
4
|
-
import { renderMath } from '@pie-lib/math-rendering';
|
|
5
|
-
|
|
6
|
-
const styles = {
|
|
7
|
-
maskBlank: {
|
|
8
|
-
// this style is applied only on small screens and for touch devices when dragging, for drag-in-the-blank.
|
|
9
|
-
// It is styled to be identical to the drag-in-the-blank chip
|
|
10
|
-
backgroundColor: color.white(),
|
|
11
|
-
border: `1px solid ${color.text()}`,
|
|
12
|
-
color: color.text(),
|
|
13
|
-
alignItems: 'center',
|
|
14
|
-
display: 'inline-flex',
|
|
15
|
-
height: 'initial',
|
|
16
|
-
minHeight: '32px',
|
|
17
|
-
fontSize: 'inherit',
|
|
18
|
-
whiteSpace: 'pre-wrap',
|
|
19
|
-
maxWidth: '374px',
|
|
20
|
-
borderRadius: '3px',
|
|
21
|
-
padding: '12px',
|
|
22
|
-
},
|
|
23
|
-
ica: {
|
|
24
|
-
backgroundColor: color.background(),
|
|
25
|
-
border: `1px solid ${color.borderDark()}`,
|
|
26
|
-
display: 'flex',
|
|
27
|
-
alignItems: 'center',
|
|
28
|
-
justifyContent: 'center',
|
|
29
|
-
minHeight: '28px',
|
|
30
|
-
padding: '0 3px',
|
|
31
|
-
marginLeft: 2,
|
|
32
|
-
marginTop: 2,
|
|
33
|
-
width: 'fit-content',
|
|
34
|
-
},
|
|
35
|
-
categorize: {
|
|
36
|
-
color: color.text(),
|
|
37
|
-
backgroundColor: color.background(),
|
|
38
|
-
padding: '16px',
|
|
39
|
-
borderRadius: '4px',
|
|
40
|
-
border: '1px solid',
|
|
41
|
-
},
|
|
42
|
-
matchList: {
|
|
43
|
-
color: color.text(),
|
|
44
|
-
backgroundColor: color.background(),
|
|
45
|
-
padding: '10px',
|
|
46
|
-
boxSizing: 'border-box',
|
|
47
|
-
border: '1px solid #D1D1D1',
|
|
48
|
-
},
|
|
49
|
-
placementOrdering: {
|
|
50
|
-
padding: '10px',
|
|
51
|
-
boxSizing: 'border-box',
|
|
52
|
-
border: '1px solid #D1D1D1',
|
|
53
|
-
backgroundColor: color.background(),
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
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) {
|
|
68
|
-
case 'MaskBlank':
|
|
69
|
-
return dragData.choice?.value;
|
|
70
|
-
case 'dnd-kit-response':
|
|
71
|
-
return dragData.value;
|
|
72
|
-
case 'Answer':
|
|
73
|
-
return dragData.value;
|
|
74
|
-
case 'Tile':
|
|
75
|
-
return dragData.value;
|
|
76
|
-
case 'categorize':
|
|
77
|
-
return dragData.value;
|
|
78
|
-
default:
|
|
79
|
-
return dragData.value;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const getCustomStyle = (dragData) => {
|
|
84
|
-
if (!dragData) return {};
|
|
85
|
-
|
|
86
|
-
const baseStyle = {
|
|
87
|
-
cursor: 'grabbing',
|
|
88
|
-
opacity: 0.8,
|
|
89
|
-
transform: 'rotate(5deg)', // Slight rotation for visual feedback
|
|
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 };
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const PreviewComponent = () => {
|
|
114
|
-
const { active } = useDndContext();
|
|
115
|
-
const [zoomLevel, setZoomLevel] = useState(1);
|
|
116
|
-
const root = useRef(null);
|
|
117
|
-
|
|
118
|
-
const dragData = active?.data?.current;
|
|
119
|
-
const isActive = !!active;
|
|
120
|
-
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (isActive && root.current) {
|
|
123
|
-
renderMath(root.current);
|
|
124
|
-
|
|
125
|
-
// Adjusted for precise zoom level calculation in Online Testing, targeting the specific class pattern .asmt-zoomable.asmt-zoom-NR .asmt-question .padding
|
|
126
|
-
const zoomAffectedElement = document.querySelector('.padding') || document.body;
|
|
127
|
-
setZoomLevel(parseFloat(getComputedStyle(zoomAffectedElement).zoom) || 1);
|
|
128
|
-
}
|
|
129
|
-
}, [isActive, dragData]);
|
|
130
|
-
|
|
131
|
-
const customStyle = getCustomStyle(dragData);
|
|
132
|
-
const prompt = getPrompt(dragData);
|
|
133
|
-
|
|
134
|
-
return (
|
|
135
|
-
<DragOverlay>
|
|
136
|
-
{isActive && prompt && (
|
|
137
|
-
<div ref={root} style={customStyle}>
|
|
138
|
-
<PreviewPrompt className="prompt-label" prompt={prompt} tagName="span" />
|
|
139
|
-
</div>
|
|
140
|
-
)}
|
|
141
|
-
</DragOverlay>
|
|
142
|
-
);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export default PreviewComponent;
|
package/src/swap.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { cloneDeep } from 'lodash-es';
|
|
2
|
-
|
|
3
|
-
export default (arr, fromIndex, toIndex) => {
|
|
4
|
-
if (!arr || arr.length <= 1 || fromIndex === undefined || toIndex === undefined) {
|
|
5
|
-
throw new Error(`swap requires a non-empty array, fromIndex, toIndex: ${arr}, ${fromIndex} ${toIndex}`);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const update = cloneDeep(arr);
|
|
9
|
-
const tmp = arr[toIndex];
|
|
10
|
-
update[toIndex] = update[fromIndex];
|
|
11
|
-
update[fromIndex] = tmp;
|
|
12
|
-
|
|
13
|
-
return update;
|
|
14
|
-
};
|
package/src/uid-context.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
const { Consumer, Provider } = React.createContext(-1);
|
|
4
|
-
|
|
5
|
-
export { Provider, Consumer };
|
|
6
|
-
|
|
7
|
-
export const generateId = () => (Math.random() * 1000001).toFixed(0);
|
|
8
|
-
|
|
9
|
-
export const withUid = (Component) => {
|
|
10
|
-
const Wrapped = (props) => <Consumer>{(uid) => <Component {...props} uid={uid} />}</Consumer>;
|
|
11
|
-
|
|
12
|
-
return Wrapped;
|
|
13
|
-
};
|