@pie-element/match-list 7.1.2-next.2 → 7.1.2-next.20
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/browser/controller/index.js +5 -5
- package/dist/browser/controller/index.js.map +1 -1
- package/dist/browser/delivery/index.js +2899 -2553
- package/dist/browser/delivery/index.js.map +1 -1
- package/dist/browser/{dist-BT3FUErB.js → dist-Cn8gDne6.js} +6 -2
- package/dist/browser/{dist-BT3FUErB.js.map → dist-Cn8gDne6.js.map} +1 -1
- package/dist/delivery/answer-area.d.ts +3 -0
- package/dist/delivery/answer-area.js +37 -28
- package/dist/delivery/answer.d.ts +9 -0
- package/dist/delivery/answer.js +154 -116
- package/dist/delivery/arrow.js +14 -13
- package/dist/delivery/choices-list.d.ts +3 -0
- package/dist/delivery/choices-list.js +11 -5
- package/dist/delivery/droppable-placeholder.d.ts +3 -1
- package/dist/delivery/droppable-placeholder.js +11 -7
- package/dist/delivery/index.js +2 -2
- package/dist/delivery/keyboard-coordinates.d.ts +24 -0
- package/dist/delivery/keyboard-coordinates.js +63 -0
- package/dist/delivery/main.d.ts +13 -0
- package/dist/delivery/main.js +165 -82
- package/dist/index.iife.js +35 -35
- package/package.json +22 -20
package/dist/delivery/main.js
CHANGED
|
@@ -1,42 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import t from "./answer
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
1
|
+
import { closestDroppableKeyboardCoordinates as e } from "./keyboard-coordinates.js";
|
|
2
|
+
import { Answer as t, buildDragId as n } from "./answer.js";
|
|
3
|
+
import { AnswerArea as r } from "./answer-area.js";
|
|
4
|
+
import { ChoicesList as i } from "./choices-list.js";
|
|
5
|
+
import a from "react";
|
|
6
|
+
import o from "prop-types";
|
|
7
|
+
import { swap as s } from "@pie-lib/drag";
|
|
8
|
+
import { DndContext as c, DragOverlay as l, KeyboardCode as u, KeyboardSensor as d, PointerSensor as f, rectIntersection as p } from "@dnd-kit/core";
|
|
9
|
+
import { restrictToFirstScrollableAncestor as m } from "@dnd-kit/modifiers";
|
|
10
|
+
import h from "@pie-lib/correct-answer-toggle";
|
|
11
|
+
import * as g from "@pie-lib/render-ui";
|
|
12
|
+
import { Feedback as _, PreviewPrompt as v, color as y } from "@pie-lib/render-ui";
|
|
13
|
+
import { jsx as b, jsxs as x } from "react/jsx-runtime";
|
|
14
|
+
import { styled as S } from "@mui/material/styles";
|
|
15
|
+
import { findKey as C, isUndefined as w, uniqueId as T } from "@pie-element/shared-lodash";
|
|
15
16
|
//#region src/delivery/main.tsx
|
|
16
|
-
function
|
|
17
|
+
function E(e) {
|
|
17
18
|
return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
return !e ||
|
|
20
|
+
function D(e, t) {
|
|
21
|
+
return !e || E(e) ? e : E(e.default) ? e.default : t && E(e[t]) ? e[t] : t && E(e[t]?.default) ? e[t].default : e;
|
|
21
22
|
}
|
|
22
|
-
var
|
|
23
|
+
var O = D(v, "PreviewPrompt") || D(M.PreviewPrompt, "PreviewPrompt"), k = D(_, "Feedback") || D(M.Feedback, "Feedback"), A = g, j = A.default, M = j && typeof j == "object" ? j : A, N = 250, P = [{
|
|
24
|
+
sensor: f,
|
|
25
|
+
options: { activationConstraint: { distance: 8 } }
|
|
26
|
+
}, {
|
|
27
|
+
sensor: d,
|
|
28
|
+
options: {
|
|
29
|
+
coordinateGetter: e,
|
|
30
|
+
keyboardCodes: {
|
|
31
|
+
start: [u.Space, u.Enter],
|
|
32
|
+
cancel: [u.Esc],
|
|
33
|
+
end: [u.Space, u.Enter]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}], F = S("div")({
|
|
23
37
|
display: "flex",
|
|
24
38
|
flexDirection: "column",
|
|
25
39
|
justifyContent: "center",
|
|
26
|
-
color:
|
|
27
|
-
backgroundColor:
|
|
28
|
-
}),
|
|
40
|
+
color: y.text(),
|
|
41
|
+
backgroundColor: y.background()
|
|
42
|
+
}), I = S("div")({
|
|
43
|
+
width: "100%",
|
|
44
|
+
overflowX: "auto",
|
|
45
|
+
overflowY: "hidden"
|
|
46
|
+
}), L = S("div")({
|
|
47
|
+
display: "flex",
|
|
48
|
+
flexDirection: "column",
|
|
49
|
+
minWidth: "min-content"
|
|
50
|
+
}), R = class extends a.Component {
|
|
29
51
|
static propTypes = {
|
|
30
|
-
session:
|
|
31
|
-
onSessionChange:
|
|
32
|
-
model:
|
|
33
|
-
prompt:
|
|
52
|
+
session: o.object.isRequired,
|
|
53
|
+
onSessionChange: o.func,
|
|
54
|
+
model: o.object.isRequired,
|
|
55
|
+
prompt: o.string
|
|
34
56
|
};
|
|
35
57
|
constructor(e) {
|
|
36
|
-
super(e), this.instanceId =
|
|
58
|
+
super(e), this.instanceId = T(), this.state = {
|
|
37
59
|
showCorrectAnswer: !1,
|
|
38
|
-
draggingElement: null
|
|
39
|
-
|
|
60
|
+
draggingElement: null,
|
|
61
|
+
selectedAnswer: null
|
|
62
|
+
}, this.lastDragEndAt = 0;
|
|
40
63
|
}
|
|
41
64
|
onRemoveAnswer(e) {
|
|
42
65
|
let { session: t, onSessionChange: n } = this.props;
|
|
@@ -56,7 +79,30 @@ var S = x(f, "PreviewPrompt") || x(E.PreviewPrompt, "PreviewPrompt"), C = x(d, "
|
|
|
56
79
|
this.setState({ draggingElement: {
|
|
57
80
|
...t.data.current,
|
|
58
81
|
rect: e
|
|
59
|
-
} });
|
|
82
|
+
} }), this.selectAnswer(t.data.current);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
onDragCancel = () => {
|
|
86
|
+
this.setState({ draggingElement: null }), this.cancelSelection(), this.lastDragEndAt = Date.now();
|
|
87
|
+
};
|
|
88
|
+
placeAnswer = (e, t) => {
|
|
89
|
+
if (!e || !t) return;
|
|
90
|
+
let { session: n, onSessionChange: r, model: i } = this.props, { config: { duplicates: a } } = i;
|
|
91
|
+
if (w(n.value) && (n.value = {}), t.type === "choices-pool" && e.promptId !== void 0) {
|
|
92
|
+
n.value[e.promptId] = void 0, r(n);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
let o = e.id, c = e.promptId;
|
|
96
|
+
if (t.type === "drop-zone" && t.promptId != null) {
|
|
97
|
+
let i = t.promptId;
|
|
98
|
+
if (e.type === "choice" && i !== void 0) {
|
|
99
|
+
let e = C(n.value, (e) => e === o);
|
|
100
|
+
e && !a ? n.value = s(n.value, e, i) : n.value[i] = o;
|
|
101
|
+
} else if (e.type === "target" && c != null && c !== i) if (n.value[i] != null && !a) {
|
|
102
|
+
let e = n.value[i];
|
|
103
|
+
n.value[i] = o, n.value[c] = e;
|
|
104
|
+
} else n.value[i] = o, delete n.value[c];
|
|
105
|
+
r(n);
|
|
60
106
|
}
|
|
61
107
|
};
|
|
62
108
|
onPlaceAnswer = (e) => {
|
|
@@ -65,83 +111,120 @@ var S = x(f, "PreviewPrompt") || x(E.PreviewPrompt, "PreviewPrompt"), C = x(d, "
|
|
|
65
111
|
if (!t) return;
|
|
66
112
|
let r = t.data.current, i = n?.data.current;
|
|
67
113
|
if (!r) return;
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
let a = this.getDestinationDragId(r, i);
|
|
115
|
+
this.placeAnswer(r, i), this.cancelSelection(), this.lastDragEndAt = Date.now(), this.focusTile(a);
|
|
116
|
+
};
|
|
117
|
+
getDestinationDragId = (e, t) => !e || !t ? null : t.type === "choices-pool" && e.promptId !== void 0 ? n({
|
|
118
|
+
type: "choice",
|
|
119
|
+
id: e.id
|
|
120
|
+
}) : t.type === "drop-zone" && t.promptId != null ? n({
|
|
121
|
+
type: "target",
|
|
122
|
+
promptId: t.promptId
|
|
123
|
+
}) : null;
|
|
124
|
+
focusTile = (e) => {
|
|
125
|
+
if (!e) return;
|
|
126
|
+
let t = `[data-tile-id="${this.instanceId}:${e}"]`;
|
|
127
|
+
requestAnimationFrame(() => {
|
|
128
|
+
requestAnimationFrame(() => {
|
|
129
|
+
document.querySelector(t)?.focus();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
isSameAnswer = (e, t) => !!e && !!t && e.type === t.type && e.id === t.id && e.promptId === t.promptId;
|
|
134
|
+
selectAnswer = (e) => {
|
|
135
|
+
this.setState({ selectedAnswer: e });
|
|
136
|
+
};
|
|
137
|
+
toggleAnswerSelection = (e) => {
|
|
138
|
+
this.setState((t) => ({ selectedAnswer: this.isSameAnswer(t.selectedAnswer, e) ? null : e }));
|
|
139
|
+
};
|
|
140
|
+
cancelSelection = () => {
|
|
141
|
+
this.setState({ selectedAnswer: null });
|
|
142
|
+
};
|
|
143
|
+
endAnyLiveKeyboardDrag = () => {
|
|
144
|
+
document.dispatchEvent(new KeyboardEvent("keydown", {
|
|
145
|
+
code: "Escape",
|
|
146
|
+
bubbles: !0,
|
|
147
|
+
cancelable: !0
|
|
148
|
+
}));
|
|
149
|
+
};
|
|
150
|
+
placeSelectedAnswer = (e) => {
|
|
151
|
+
let { selectedAnswer: t } = this.state;
|
|
152
|
+
if (!t) return;
|
|
153
|
+
let n = this.getDestinationDragId(t, e);
|
|
154
|
+
this.placeAnswer(t, e), this.cancelSelection(), this.endAnyLiveKeyboardDrag(), this.lastDragEndAt = Date.now(), this.focusTile(n);
|
|
155
|
+
};
|
|
156
|
+
isClickSoonAfterDragEnd = () => Date.now() - this.lastDragEndAt < N;
|
|
157
|
+
onChoiceClick = (e) => {
|
|
158
|
+
this.isClickSoonAfterDragEnd() || this.toggleAnswerSelection(e);
|
|
159
|
+
};
|
|
160
|
+
onPlacementClick = (e) => {
|
|
161
|
+
this.isClickSoonAfterDragEnd() || this.placeSelectedAnswer(e);
|
|
88
162
|
};
|
|
89
163
|
toggleShowCorrect = () => {
|
|
90
164
|
this.setState({ showCorrectAnswer: !this.state.showCorrectAnswer });
|
|
91
165
|
};
|
|
92
166
|
renderDragOverlay = () => {
|
|
93
|
-
let { draggingElement:
|
|
94
|
-
return
|
|
95
|
-
id:
|
|
96
|
-
title:
|
|
167
|
+
let { draggingElement: e } = this.state;
|
|
168
|
+
return e ? /* @__PURE__ */ b(t, {
|
|
169
|
+
id: e.id,
|
|
170
|
+
title: e.value,
|
|
97
171
|
disabled: !1,
|
|
98
172
|
isDragging: !1,
|
|
99
|
-
style:
|
|
100
|
-
width:
|
|
101
|
-
height:
|
|
173
|
+
style: e.rect ? {
|
|
174
|
+
width: e.rect.width,
|
|
175
|
+
height: e.rect.height,
|
|
102
176
|
boxSizing: "border-box"
|
|
103
177
|
} : {}
|
|
104
178
|
}) : null;
|
|
105
179
|
};
|
|
106
180
|
render() {
|
|
107
|
-
let { showCorrectAnswer: e } = this.state, { model:
|
|
108
|
-
return /* @__PURE__ */
|
|
181
|
+
let { showCorrectAnswer: e } = this.state, { model: t, session: n } = this.props, { config: a, mode: o } = t, { prompt: s, language: u } = a;
|
|
182
|
+
return /* @__PURE__ */ x(c, {
|
|
183
|
+
sensors: P,
|
|
184
|
+
collisionDetection: p,
|
|
109
185
|
onDragStart: this.onDragStart,
|
|
110
186
|
onDragEnd: this.onPlaceAnswer,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
187
|
+
onDragCancel: this.onDragCancel,
|
|
188
|
+
modifiers: [m],
|
|
189
|
+
accessibility: { screenReaderInstructions: { draggable: "Press Space or Enter to pick up this answer choice. Once picked up, use Tab or Shift+Tab to cycle through response areas, or use arrow keys to move it freely. Press Space or Enter to drop, or Escape to cancel. You can also click an answer choice to select it, then click a response area to place it there." } },
|
|
190
|
+
children: [/* @__PURE__ */ x(F, { children: [
|
|
191
|
+
/* @__PURE__ */ b(O, {
|
|
114
192
|
className: "prompt",
|
|
115
|
-
prompt:
|
|
193
|
+
prompt: s
|
|
116
194
|
}),
|
|
117
|
-
/* @__PURE__ */
|
|
118
|
-
show:
|
|
195
|
+
/* @__PURE__ */ b(h, {
|
|
196
|
+
show: o === "evaluate",
|
|
119
197
|
toggled: e,
|
|
120
198
|
onToggle: this.toggleShowCorrect,
|
|
121
|
-
language:
|
|
199
|
+
language: u
|
|
122
200
|
}),
|
|
123
|
-
/* @__PURE__ */
|
|
201
|
+
/* @__PURE__ */ b(I, { children: /* @__PURE__ */ x(L, { children: [/* @__PURE__ */ b(r, {
|
|
124
202
|
instanceId: this.instanceId,
|
|
125
|
-
model:
|
|
126
|
-
session:
|
|
203
|
+
model: t,
|
|
204
|
+
session: n,
|
|
127
205
|
onRemoveAnswer: (e) => this.onRemoveAnswer(e),
|
|
128
|
-
disabled:
|
|
129
|
-
showCorrect: e
|
|
130
|
-
|
|
131
|
-
|
|
206
|
+
disabled: o !== "gather",
|
|
207
|
+
showCorrect: e,
|
|
208
|
+
selectedAnswer: this.state.selectedAnswer,
|
|
209
|
+
onChoiceClick: this.onChoiceClick,
|
|
210
|
+
onPlacementClick: this.onPlacementClick
|
|
211
|
+
}), /* @__PURE__ */ b(i, {
|
|
132
212
|
instanceId: this.instanceId,
|
|
133
|
-
model:
|
|
134
|
-
session:
|
|
135
|
-
disabled:
|
|
136
|
-
onRemoveAnswer: (e) => this.onRemoveAnswer(e)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
213
|
+
model: t,
|
|
214
|
+
session: n,
|
|
215
|
+
disabled: o !== "gather",
|
|
216
|
+
onRemoveAnswer: (e) => this.onRemoveAnswer(e),
|
|
217
|
+
selectedAnswer: this.state.selectedAnswer,
|
|
218
|
+
onChoiceClick: this.onChoiceClick,
|
|
219
|
+
onPlacementClick: this.onPlacementClick
|
|
220
|
+
})] }) }),
|
|
221
|
+
t.correctness && t.feedback && !e && /* @__PURE__ */ b(k, {
|
|
222
|
+
correctness: t.correctness.correctness,
|
|
223
|
+
feedback: t.feedback
|
|
141
224
|
})
|
|
142
|
-
] }), /* @__PURE__ */
|
|
225
|
+
] }), /* @__PURE__ */ b(l, { children: this.renderDragOverlay() })]
|
|
143
226
|
});
|
|
144
227
|
}
|
|
145
228
|
};
|
|
146
229
|
//#endregion
|
|
147
|
-
export {
|
|
230
|
+
export { R as Main, R as default };
|