@pie-lib/mask-markup 1.41.0-mui-update.0 → 1.43.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 +13 -54
- package/lib/choices/choice.js +30 -5
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +2 -1
- package/lib/choices/index.js.map +1 -1
- package/lib/components/blank.js +43 -44
- package/lib/components/blank.js.map +1 -1
- package/lib/drag-in-the-blank.js +67 -42
- package/lib/drag-in-the-blank.js.map +1 -1
- package/package.json +6 -6
- package/src/choices/choice.jsx +35 -6
- package/src/choices/index.jsx +1 -1
- package/src/components/blank.jsx +47 -56
- package/src/drag-in-the-blank.jsx +70 -30
|
@@ -2,7 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
4
4
|
import { DragProvider } from '@pie-lib/drag';
|
|
5
|
+
import { DragOverlay, closestCenter } from '@dnd-kit/core';
|
|
6
|
+
|
|
5
7
|
import Choices from './choices';
|
|
8
|
+
import Choice from './choices/choice';
|
|
6
9
|
import Blank from './components/blank';
|
|
7
10
|
import { withMask } from './with-mask';
|
|
8
11
|
|
|
@@ -19,6 +22,7 @@ const Masked = withMask('blank', (props) => (node, data, onChange) => {
|
|
|
19
22
|
emptyResponseAreaWidth,
|
|
20
23
|
emptyResponseAreaHeight,
|
|
21
24
|
instanceId,
|
|
25
|
+
isDragging
|
|
22
26
|
} = props;
|
|
23
27
|
const choiceId = showCorrectAnswer ? correctResponse[dataset.id] : data[dataset.id];
|
|
24
28
|
// eslint-disable-next-line react/prop-types
|
|
@@ -44,12 +48,20 @@ const Masked = withMask('blank', (props) => (node, data, onChange) => {
|
|
|
44
48
|
onChange(newData);
|
|
45
49
|
}}
|
|
46
50
|
instanceId={instanceId}
|
|
51
|
+
isDragging={isDragging}
|
|
47
52
|
/>
|
|
48
53
|
);
|
|
49
54
|
}
|
|
50
55
|
});
|
|
51
56
|
|
|
52
57
|
export default class DragInTheBlank extends React.Component {
|
|
58
|
+
constructor(props) {
|
|
59
|
+
super(props);
|
|
60
|
+
this.state = {
|
|
61
|
+
activeDragItem: null,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
53
65
|
static propTypes = {
|
|
54
66
|
markup: PropTypes.string,
|
|
55
67
|
layout: PropTypes.object,
|
|
@@ -71,54 +83,74 @@ export default class DragInTheBlank extends React.Component {
|
|
|
71
83
|
instanceId: 'drag-in-the-blank',
|
|
72
84
|
};
|
|
73
85
|
|
|
86
|
+
handleDragStart = (event) => {
|
|
87
|
+
const { active } = event;
|
|
88
|
+
|
|
89
|
+
if (active?.data?.current) {
|
|
90
|
+
this.setState({
|
|
91
|
+
activeDragItem: active.data.current,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
renderDragOverlay = () => {
|
|
97
|
+
const { activeDragItem } = this.state;
|
|
98
|
+
if (!activeDragItem) return null;
|
|
99
|
+
|
|
100
|
+
if (activeDragItem.type === 'MaskBlank') {
|
|
101
|
+
return (
|
|
102
|
+
<Choice
|
|
103
|
+
disabled={activeDragItem.disabled}
|
|
104
|
+
choice={activeDragItem.choice}
|
|
105
|
+
instanceId={activeDragItem.instanceId}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return null;
|
|
111
|
+
};
|
|
112
|
+
|
|
74
113
|
handleDragEnd = (event) => {
|
|
75
|
-
console.log('Drag End Event:', event);
|
|
76
114
|
const { active, over } = event;
|
|
77
115
|
const { onChange, value } = this.props;
|
|
78
116
|
|
|
79
117
|
if (!over || !active || !onChange) {
|
|
80
|
-
console.log('Early return - missing data:', { over: !!over, active: !!active, onChange: !!onChange });
|
|
81
118
|
return;
|
|
82
119
|
}
|
|
83
120
|
|
|
84
121
|
const draggedData = active.data.current;
|
|
85
122
|
const dropData = over.data.current;
|
|
86
123
|
|
|
87
|
-
console.log('Drag data:', draggedData);
|
|
88
|
-
console.log('Drop data:', dropData);
|
|
89
|
-
|
|
90
|
-
// Handle drop from choice to blank or blank to blank
|
|
91
124
|
if (draggedData?.type === 'MaskBlank' && dropData?.accepts?.includes('MaskBlank')) {
|
|
92
|
-
console.log('Valid drag/drop types');
|
|
93
125
|
const draggedItem = draggedData;
|
|
94
126
|
const targetId = dropData.id;
|
|
95
127
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
console.log('Instance ID mismatch:', draggedItem.instanceId, 'vs', dropData.instanceId);
|
|
128
|
+
// drop from choice to blank (placing choice into response)
|
|
129
|
+
if (draggedItem.fromChoice === true) {
|
|
130
|
+
const newValue = { ...value };
|
|
131
|
+
newValue[targetId] = draggedItem.choice.id;
|
|
132
|
+
onChange(newValue);
|
|
133
|
+
} else if (dropData.toChoiceBoard === true) {
|
|
134
|
+
// handle drop from blank to choice board (removal from blank)
|
|
135
|
+
const newValue = { ...value };
|
|
136
|
+
delete newValue[draggedItem.id];
|
|
137
|
+
onChange(newValue);
|
|
138
|
+
}
|
|
139
|
+
// handle drop from blank to blank (changing position)
|
|
140
|
+
else if (draggedItem.id !== targetId) {
|
|
141
|
+
const newValue = { ...value };
|
|
142
|
+
newValue[targetId] = draggedItem.choice.id;
|
|
143
|
+
delete newValue[draggedItem.id];
|
|
144
|
+
onChange(newValue);
|
|
116
145
|
}
|
|
117
|
-
} else {
|
|
118
|
-
console.log('Invalid drag/drop types:', draggedData?.type, dropData?.accepts);
|
|
119
146
|
}
|
|
147
|
+
this.setState({ activeDragItem: null });
|
|
120
148
|
};
|
|
121
149
|
|
|
150
|
+
componentDidMount() {
|
|
151
|
+
if (this.rootRef) renderMath(this.rootRef);
|
|
152
|
+
}
|
|
153
|
+
|
|
122
154
|
componentDidUpdate() {
|
|
123
155
|
if (this.rootRef) renderMath(this.rootRef);
|
|
124
156
|
}
|
|
@@ -172,7 +204,11 @@ export default class DragInTheBlank extends React.Component {
|
|
|
172
204
|
const style = { display: 'flex', minWidth: '100px', ...this.getPositionDirection(choicePosition) };
|
|
173
205
|
|
|
174
206
|
return (
|
|
175
|
-
<DragProvider
|
|
207
|
+
<DragProvider
|
|
208
|
+
onDragStart={this.handleDragStart}
|
|
209
|
+
onDragEnd={this.handleDragEnd}
|
|
210
|
+
collisionDetection={closestCenter}
|
|
211
|
+
>
|
|
176
212
|
<div ref={(ref) => (this.rootRef = ref)} style={style}>
|
|
177
213
|
<Choices
|
|
178
214
|
choicePosition={choicePosition}
|
|
@@ -197,7 +233,11 @@ export default class DragInTheBlank extends React.Component {
|
|
|
197
233
|
emptyResponseAreaWidth={emptyResponseAreaWidth}
|
|
198
234
|
emptyResponseAreaHeight={emptyResponseAreaHeight}
|
|
199
235
|
instanceId={instanceId}
|
|
236
|
+
isDragging={!!this.state.activeDragItem}
|
|
200
237
|
/>
|
|
238
|
+
<DragOverlay style={{ pointerEvents: "none" }}>
|
|
239
|
+
{this.renderDragOverlay()}
|
|
240
|
+
</DragOverlay>
|
|
201
241
|
</div>
|
|
202
242
|
</DragProvider>
|
|
203
243
|
);
|