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