@pie-element/placement-ordering 14.1.2-next.1 → 14.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/author/choice-editor.js +2 -2
- package/dist/author/choice-tile.js +3 -2
- package/dist/author/design.js +1 -1
- package/dist/author/index.d.ts +1 -0
- package/dist/author/index.js +5 -2
- package/dist/browser/author/index.js +23488 -20640
- package/dist/browser/author/index.js.map +1 -1
- package/dist/browser/{browser-Dbw2uHQ7.js → browser-Bd36Xf5z.js} +6 -2
- package/dist/browser/browser-Bd36Xf5z.js.map +1 -0
- package/dist/browser/controller/index.js +3 -3
- package/dist/browser/controller/index.js.map +1 -1
- package/dist/browser/delivery/index.js +441 -304
- package/dist/browser/delivery/index.js.map +1 -1
- package/dist/browser/{dist-D9ARZhQk.js → dist-DiGNNRzu.js} +2 -2
- package/dist/browser/{dist-D9ARZhQk.js.map → dist-DiGNNRzu.js.map} +1 -1
- package/dist/browser/{drag-provider-DSf9QLEN.js → drag-provider-B5wazJHM.js} +2465 -2511
- package/dist/browser/drag-provider-B5wazJHM.js.map +1 -0
- package/dist/controller/scoring.js +1 -1
- package/dist/delivery/index.js +2 -2
- package/dist/delivery/keyboard-coordinates.d.ts +47 -0
- package/dist/delivery/keyboard-coordinates.js +51 -0
- package/dist/delivery/main.js +1 -1
- package/dist/delivery/ordering.js +2 -1
- package/dist/delivery/placement-ordering.d.ts +11 -0
- package/dist/delivery/placement-ordering.js +153 -81
- package/dist/delivery/tile.d.ts +3 -0
- package/dist/delivery/tile.js +66 -57
- package/dist/delivery/tiler.d.ts +6 -0
- package/dist/delivery/tiler.js +6 -3
- package/dist/index.iife.js +35 -35
- package/package.json +18 -18
- package/dist/browser/browser-Dbw2uHQ7.js.map +0 -1
- package/dist/browser/drag-provider-DSf9QLEN.js.map +0 -1
|
@@ -27,4 +27,4 @@ var a = r("pie-elements:placement-ordering:controller"), o = (e) => /* @__PURE__
|
|
|
27
27
|
}), a;
|
|
28
28
|
};
|
|
29
29
|
//#endregion
|
|
30
|
-
export { c as flattenCorrect, l as getAllCorrectResponses, u as score };
|
|
30
|
+
export { c as flattenCorrect, l as getAllCorrectResponses, o as illegalArgumentError, s as pairwiseCombinationScore, u as score };
|
package/dist/delivery/index.js
CHANGED
|
@@ -60,10 +60,10 @@ var s = i("pie-elements:placement-ordering"), c = ({ model: e, session: t }) =>
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
connectedCallback() {
|
|
63
|
-
this._initMathObserver();
|
|
63
|
+
this._initMathObserver(), this.render();
|
|
64
64
|
}
|
|
65
65
|
disconnectedCallback() {
|
|
66
|
-
this._disconnectMathObserver(), this._root
|
|
66
|
+
this._disconnectMathObserver(), this._root &&= (this._root.unmount(), null);
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
//#endregion
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-elements/packages/placement-ordering/src/keyboard-coordinates.js
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Custom keyboard coordinate getter for placement-ordering's Tab-based placement mode
|
|
11
|
+
* (enabled only when the item is configured with `placementArea` / `includeTargets`).
|
|
12
|
+
*
|
|
13
|
+
* Tab/Shift+Tab cycle the dragged choice through the target column's response areas
|
|
14
|
+
* in on-screen order (first target, then the rest in sequence), followed by exactly
|
|
15
|
+
* one source-column stop as a fixed last step before the cycle wraps back to the first
|
|
16
|
+
* target — so picking up a choice always starts the cycle at the first target,
|
|
17
|
+
* regardless of where that choice's own source-column slot happens to sit on screen.
|
|
18
|
+
*
|
|
19
|
+
* Arrow keys are delegated to dnd-kit's own `defaultKeyboardCoordinateGetter` so the
|
|
20
|
+
* pre-existing free-form arrow-key dragging behavior is left completely unchanged.
|
|
21
|
+
*
|
|
22
|
+
* Whichever slot a drag started from — a target the choice was already placed in, or
|
|
23
|
+
* (see below) the choice's own pool slot — stays reachable by Tab as a no-op "drop it
|
|
24
|
+
* back where it came from": tile.tsx disables a droppable for the whole duration of
|
|
25
|
+
* its own drag (a self-collision guard for pointer drags), which would otherwise make
|
|
26
|
+
* that exact slot unreachable; that guard is bypassed here specifically for the one
|
|
27
|
+
* droppable matching the active drag's own id. A target slot picked up this way stays
|
|
28
|
+
* in its normal position in the target sequence (it's just another target); nothing
|
|
29
|
+
* special is needed there beyond the bypass itself.
|
|
30
|
+
*
|
|
31
|
+
* The choices column isn't a place a student can choose to relocate an answer within —
|
|
32
|
+
* there's exactly one meaningful "source" stop for whichever choice is currently being
|
|
33
|
+
* dragged: its own fixed slot, whether that's the vacated gap left behind (if the
|
|
34
|
+
* choice is already placed in a target — landing back on it returns the choice to the
|
|
35
|
+
* pool, undoing the placement) or the very tile being dragged (if the choice is still
|
|
36
|
+
* sitting there, unplaced — landing back on it is a no-op that effectively cancels the
|
|
37
|
+
* pick-up; the same disabled-droppable bypass applies here too). Every *other*
|
|
38
|
+
* choice-column tile — filled or an empty gap — is excluded from the cycle:
|
|
39
|
+
* `ordering.ts`'s `updateResponse` has no `choice -> choice` case, so they'd be no-op
|
|
40
|
+
* drop targets anyway. Matching is by id (the vacated gap carries its original choice's
|
|
41
|
+
* id specifically so this comparison works), not by type alone.
|
|
42
|
+
*/
|
|
43
|
+
export declare const closestDroppableKeyboardCoordinates: (event: any, { active, context, currentCoordinates }: {
|
|
44
|
+
active: any;
|
|
45
|
+
context: any;
|
|
46
|
+
currentCoordinates: any;
|
|
47
|
+
}) => any;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { KeyboardCode as e, defaultKeyboardCoordinateGetter as t } from "@dnd-kit/core";
|
|
2
|
+
//#region src/delivery/keyboard-coordinates.ts
|
|
3
|
+
var n = (n, { active: i, context: a, currentCoordinates: o }) => {
|
|
4
|
+
let { code: s } = n, c = s === "Tab", l = s === e.Down || s === e.Up || s === e.Left || s === e.Right;
|
|
5
|
+
if (!c && !l) return;
|
|
6
|
+
if (l) return t(n, {
|
|
7
|
+
context: a,
|
|
8
|
+
currentCoordinates: o
|
|
9
|
+
});
|
|
10
|
+
n.preventDefault();
|
|
11
|
+
let { droppableRects: u, droppableContainers: d, collisionRect: f, draggableNodes: p, active: m } = a;
|
|
12
|
+
if (!u || u.size === 0) return o;
|
|
13
|
+
let h = {
|
|
14
|
+
x: (f?.width || 0) / 2,
|
|
15
|
+
y: (f?.height || 0) / 2
|
|
16
|
+
}, g = {
|
|
17
|
+
x: o.x + h.x,
|
|
18
|
+
y: o.y + h.y
|
|
19
|
+
}, _ = p?.get(i)?.data?.current?.id, v = m?.rect?.current?.initial, y = typeof i == "string" ? i.replace(/^tile-/, "drop-") : void 0, b = [], x;
|
|
20
|
+
for (let [e, t] of d) {
|
|
21
|
+
let n = t?.data?.current, r = e === y;
|
|
22
|
+
if (t?.disabled && !r) continue;
|
|
23
|
+
let i = n?.type === "choice" && n?.id === _;
|
|
24
|
+
if (n?.type === "choice" && !i) continue;
|
|
25
|
+
let a = (r ? v : null) || u.get(e);
|
|
26
|
+
if (!a) continue;
|
|
27
|
+
let o = {
|
|
28
|
+
x: a.left + a.width / 2,
|
|
29
|
+
y: a.top + a.height / 2
|
|
30
|
+
}, s = {
|
|
31
|
+
id: e,
|
|
32
|
+
dropPosition: {
|
|
33
|
+
x: a.left,
|
|
34
|
+
y: a.top + a.height / 2 - h.y
|
|
35
|
+
},
|
|
36
|
+
center: o
|
|
37
|
+
};
|
|
38
|
+
i ? x = s : b.push(s);
|
|
39
|
+
}
|
|
40
|
+
if (b.length === 0 && !x) return o;
|
|
41
|
+
let S = n.shiftKey;
|
|
42
|
+
b.sort((e, t) => Math.abs(e.center.y - t.center.y) > 10 ? e.center.y - t.center.y : e.center.x - t.center.x), x && b.push(x);
|
|
43
|
+
let C = 0, w = Infinity;
|
|
44
|
+
for (let e = 0; e < b.length; e++) {
|
|
45
|
+
let t = r(g, b[e].center);
|
|
46
|
+
t < w && (w = t, C = e);
|
|
47
|
+
}
|
|
48
|
+
return b[S ? (C - 1 + b.length) % b.length : (C + 1) % b.length].dropPosition;
|
|
49
|
+
}, r = (e, t) => Math.sqrt((e.x - t.x) ** 2 + (e.y - t.y) ** 2);
|
|
50
|
+
//#endregion
|
|
51
|
+
export { n as closestDroppableKeyboardCoordinates };
|
package/dist/delivery/main.js
CHANGED
|
@@ -40,6 +40,7 @@ function u(e, t, n, r) {
|
|
|
40
40
|
}
|
|
41
41
|
return e.map((e) => t.indexOf(e.id) !== -1 && !r.allowSameChoiceInTargets ? {
|
|
42
42
|
type: "choice",
|
|
43
|
+
id: e.id,
|
|
43
44
|
empty: !0,
|
|
44
45
|
droppable: !0,
|
|
45
46
|
draggable: !1
|
|
@@ -90,4 +91,4 @@ function f(e, t) {
|
|
|
90
91
|
return t;
|
|
91
92
|
}
|
|
92
93
|
//#endregion
|
|
93
|
-
export { d as buildState, f as reducer };
|
|
94
|
+
export { d as buildState, o as push, f as reducer, s as swap };
|
|
@@ -23,6 +23,17 @@ export declare class PlacementOrdering extends React.Component {
|
|
|
23
23
|
onRemoveChoice: any;
|
|
24
24
|
createOrdering: any;
|
|
25
25
|
onDragEnd: any;
|
|
26
|
+
onDragStart: any;
|
|
27
|
+
onDragCancel: any;
|
|
28
|
+
isSameChoice: (a: any, b: any) => boolean;
|
|
29
|
+
selectChoice: any;
|
|
30
|
+
toggleChoiceSelection: any;
|
|
31
|
+
cancelSelection: any;
|
|
32
|
+
endAnyLiveKeyboardDrag: any;
|
|
33
|
+
placeSelectedChoice: any;
|
|
34
|
+
isClickSoonAfterDragEnd: () => boolean;
|
|
35
|
+
onChoiceClick: any;
|
|
36
|
+
onPlacementClick: any;
|
|
26
37
|
render(): React.JSX.Element;
|
|
27
38
|
}
|
|
28
39
|
export default PlacementOrdering;
|
|
@@ -1,62 +1,88 @@
|
|
|
1
1
|
import { HorizontalTiler as e, VerticalTiler as t } from "./tiler.js";
|
|
2
2
|
import { buildState as n, reducer as r } from "./ordering.js";
|
|
3
3
|
import { haveSameValuesButDifferentOrder as i } from "./utils.js";
|
|
4
|
-
import a from "
|
|
5
|
-
import
|
|
6
|
-
import l from "
|
|
7
|
-
import
|
|
8
|
-
import d from "
|
|
9
|
-
import f from "
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import E from "
|
|
17
|
-
import
|
|
4
|
+
import { closestDroppableKeyboardCoordinates as a } from "./keyboard-coordinates.js";
|
|
5
|
+
import o from "react";
|
|
6
|
+
import { difference as s, isEqual as c, uniqueId as l } from "@pie-element/shared-lodash";
|
|
7
|
+
import u from "debug";
|
|
8
|
+
import { renderMath as d } from "@pie-element/shared-math-rendering-mathjax";
|
|
9
|
+
import f from "prop-types";
|
|
10
|
+
import p from "react-dom";
|
|
11
|
+
import { styled as m } from "@mui/material/styles";
|
|
12
|
+
import { rectIntersection as h } from "@dnd-kit/core";
|
|
13
|
+
import { restrictToParentElement as g } from "@dnd-kit/modifiers";
|
|
14
|
+
import * as _ from "@pie-lib/render-ui";
|
|
15
|
+
import { Collapsible as v, Feedback as y, PreviewPrompt as b, UiLayout as x, color as S, hasMedia as C, hasText as w } from "@pie-lib/render-ui";
|
|
16
|
+
import { jsx as T, jsxs as E } from "react/jsx-runtime";
|
|
17
|
+
import D from "@pie-lib/translator";
|
|
18
|
+
import O from "@pie-lib/correct-answer-toggle";
|
|
19
|
+
import { DragProvider as k } from "@pie-lib/drag";
|
|
18
20
|
//#region src/delivery/placement-ordering.tsx
|
|
19
|
-
function
|
|
21
|
+
function A(e) {
|
|
20
22
|
return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
|
|
21
23
|
}
|
|
22
|
-
function
|
|
23
|
-
return !e ||
|
|
24
|
+
function j(e, t) {
|
|
25
|
+
return !e || A(e) ? e : A(e.default) ? e.default : t && A(e[t]) ? e[t] : t && A(e[t]?.default) ? e[t].default : e;
|
|
24
26
|
}
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
var M = j(x, "UiLayout") || j(R.UiLayout, "UiLayout"), N = j(b, "PreviewPrompt") || j(R.PreviewPrompt, "PreviewPrompt"), P = j(y, "Feedback") || j(R.Feedback, "Feedback"), F = j(v, "Collapsible") || j(R.Collapsible, "Collapsible"), I = _, L = I.default, R = L && typeof L == "object" ? L : I, z = 250, B = (e, t) => {
|
|
28
|
+
if (!e || !t) return !1;
|
|
29
|
+
let n = t.left + t.width / 2, r = t.top + t.height / 2;
|
|
30
|
+
return n >= e.left && n <= e.right && r >= e.top && r <= e.bottom;
|
|
31
|
+
}, V = (e) => e ? {
|
|
32
|
+
keyboardCoordinateGetter: a,
|
|
33
|
+
keyboardCodes: {
|
|
34
|
+
start: ["Space", "Enter"],
|
|
35
|
+
cancel: ["Escape"],
|
|
36
|
+
end: ["Space", "Enter"]
|
|
37
|
+
},
|
|
38
|
+
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." } }
|
|
39
|
+
} : {}, { translator: H } = D, U = u("pie-elements:placement-ordering"), W = m("div")({
|
|
40
|
+
color: S.text(),
|
|
41
|
+
backgroundColor: S.background(),
|
|
28
42
|
display: "flex",
|
|
29
43
|
flexDirection: "column",
|
|
30
44
|
alignItems: "center",
|
|
31
45
|
boxSizing: "border-box"
|
|
32
|
-
}),
|
|
46
|
+
}), G = m("div")({
|
|
47
|
+
alignSelf: "stretch",
|
|
48
|
+
maxWidth: "100%",
|
|
49
|
+
overflowX: "auto",
|
|
50
|
+
overflowY: "hidden"
|
|
51
|
+
}), K = m("div")({
|
|
52
|
+
display: "flex",
|
|
53
|
+
justifyContent: "center",
|
|
54
|
+
minWidth: "min-content"
|
|
55
|
+
}), q = m("div")(({ theme: e }) => ({ paddingBottom: e.spacing(1) })), J = m("div")(({ theme: e }) => ({ paddingBottom: e.spacing(2) })), Y = m(O)(({ theme: e }) => ({ paddingBottom: e.spacing(1) })), X = m(F)(({ theme: e }) => ({
|
|
33
56
|
marginBottom: e.spacing(2),
|
|
34
57
|
alignSelf: "flex-start"
|
|
35
|
-
})),
|
|
58
|
+
})), Z = (e) => {
|
|
36
59
|
let { tiler: t, ordering: n, onDropChoice: r, onRemoveChoice: i, ...a } = e;
|
|
37
|
-
return /* @__PURE__ */
|
|
60
|
+
return /* @__PURE__ */ T(t, {
|
|
38
61
|
...a,
|
|
39
62
|
tiles: n.tiles,
|
|
40
63
|
onDropChoice: (e, t) => r(e, t, n),
|
|
41
64
|
onRemoveChoice: (e) => i(e, n)
|
|
42
65
|
});
|
|
43
66
|
};
|
|
44
|
-
|
|
45
|
-
tiler:
|
|
46
|
-
ordering:
|
|
47
|
-
onDropChoice:
|
|
48
|
-
onRemoveChoice:
|
|
67
|
+
Z.propTypes = {
|
|
68
|
+
tiler: f.func,
|
|
69
|
+
ordering: f.any,
|
|
70
|
+
onDropChoice: f.func,
|
|
71
|
+
onRemoveChoice: f.func
|
|
49
72
|
};
|
|
50
|
-
var
|
|
73
|
+
var Q = class extends o.Component {
|
|
51
74
|
static propTypes = {
|
|
52
|
-
onSessionChange:
|
|
53
|
-
model:
|
|
54
|
-
session:
|
|
75
|
+
onSessionChange: f.func.isRequired,
|
|
76
|
+
model: f.object.isRequired,
|
|
77
|
+
session: f.oneOfType([f.array.isRequired, f.object.isRequired])
|
|
55
78
|
};
|
|
56
79
|
constructor(e) {
|
|
57
|
-
super(e), this.instanceId =
|
|
80
|
+
super(e), this.instanceId = l();
|
|
58
81
|
let { value: t, needsReset: n } = this.validateSession(e);
|
|
59
|
-
this.state = {
|
|
82
|
+
this.state = {
|
|
83
|
+
showingCorrect: !1,
|
|
84
|
+
selectedChoice: null
|
|
85
|
+
}, this.lastDragEndAt = 0;
|
|
60
86
|
let { model: r } = e || {}, { env: i } = r || {}, { mode: a } = i || {};
|
|
61
87
|
n && a === "gather" && this.props.onSessionChange({
|
|
62
88
|
...e.session,
|
|
@@ -65,18 +91,18 @@ var G = class extends a.Component {
|
|
|
65
91
|
}
|
|
66
92
|
toggleCorrect = (e) => this.setState({ showingCorrect: e });
|
|
67
93
|
componentDidUpdate() {
|
|
68
|
-
|
|
94
|
+
d(p.findDOMNode(this));
|
|
69
95
|
}
|
|
70
96
|
validateSession = ({ model: e, session: t }, n = !1) => {
|
|
71
|
-
let { config: r, choices: i } = e || {}, { includeTargets: a } = r || {},
|
|
72
|
-
if (a) l && l.length !==
|
|
97
|
+
let { config: r, choices: i } = e || {}, { includeTargets: a } = r || {}, o = i.map((e) => e.id), { value: l } = t || {}, u;
|
|
98
|
+
if (a) l && l.length !== o.length && (u = !0, l = l.length < o.length ? l.concat(Array(o.length - l.length)) : l.filter((e) => o.includes(e)));
|
|
73
99
|
else {
|
|
74
|
-
if (!l || !l.length || n) l =
|
|
100
|
+
if (!l || !l.length || n) l = o;
|
|
75
101
|
else {
|
|
76
|
-
let e = o
|
|
77
|
-
(e.length || t.length) && (l =
|
|
102
|
+
let e = s(o, l), t = s(l, o);
|
|
103
|
+
(e.length || t.length) && (l = o);
|
|
78
104
|
}
|
|
79
|
-
u = !
|
|
105
|
+
u = !c(t.value, l);
|
|
80
106
|
}
|
|
81
107
|
return u && console.warn("This session is not valid anymore. It will be reset."), {
|
|
82
108
|
value: l,
|
|
@@ -84,8 +110,8 @@ var G = class extends a.Component {
|
|
|
84
110
|
};
|
|
85
111
|
};
|
|
86
112
|
UNSAFE_componentWillReceiveProps(e) {
|
|
87
|
-
let { model: t = {} } = e || {}, { model: n = {} } = this.props || {}, { correctResponse: r, config: a, choices: o = [], env: s } = t, { includeTargets: c } = a || {}, l = {}, u = n.language && n.language !== t.language, d = n.note && n.note ===
|
|
88
|
-
u && d && (n.note =
|
|
113
|
+
let { model: t = {} } = e || {}, { model: n = {} } = this.props || {}, { correctResponse: r, config: a, choices: o = [], env: s } = t, { includeTargets: c } = a || {}, l = {}, u = n.language && n.language !== t.language, d = n.note && n.note === H.t("common:commonCorrectAnswerWithAlternates", { lng: n.language });
|
|
114
|
+
u && d && (n.note = H.t("common:commonCorrectAnswerWithAlternates", { lng: t.language })), r || (l.showingCorrect = !1);
|
|
89
115
|
let f = i(o, n.choices), { value: p, needsReset: m } = this.validateSession(e, f), h = {
|
|
90
116
|
...e.session,
|
|
91
117
|
value: p
|
|
@@ -97,7 +123,7 @@ var G = class extends a.Component {
|
|
|
97
123
|
}
|
|
98
124
|
onDropChoice = (e, t, n) => {
|
|
99
125
|
let { onSessionChange: i, session: a } = this.props, o = n.tiles.find((e) => e.id === t.id && e.type === t.type && e.index === t.index), s = e;
|
|
100
|
-
|
|
126
|
+
U("[onDropChoice] ", o, s);
|
|
101
127
|
let c = r({
|
|
102
128
|
type: "move",
|
|
103
129
|
from: o,
|
|
@@ -107,7 +133,7 @@ var G = class extends a.Component {
|
|
|
107
133
|
};
|
|
108
134
|
onRemoveChoice = (e, t) => {
|
|
109
135
|
let { onSessionChange: n, session: i } = this.props;
|
|
110
|
-
|
|
136
|
+
U("[onRemoveChoice]", e);
|
|
111
137
|
let a = r({
|
|
112
138
|
type: "remove",
|
|
113
139
|
target: e
|
|
@@ -132,7 +158,7 @@ var G = class extends a.Component {
|
|
|
132
158
|
};
|
|
133
159
|
onDragEnd = (e) => {
|
|
134
160
|
let { over: t, active: n } = e, r = this.createOrdering();
|
|
135
|
-
if (t && n) {
|
|
161
|
+
if (this.cancelSelection(), this.lastDragEndAt = Date.now(), t && n) {
|
|
136
162
|
let e = n.data.current, i = t.data.current;
|
|
137
163
|
if (e && i && i.type === "target") {
|
|
138
164
|
this.onDropChoice(i, e, r);
|
|
@@ -140,67 +166,113 @@ var G = class extends a.Component {
|
|
|
140
166
|
}
|
|
141
167
|
e && i && this.onDropChoice(i, e, r);
|
|
142
168
|
} else if (!t && n) {
|
|
143
|
-
let e = n.data.current;
|
|
144
|
-
e && e.type === "target" && this.onRemoveChoice(e, r);
|
|
169
|
+
let e = n.data.current, t = B(n.rect?.current?.initial, n.rect?.current?.translated);
|
|
170
|
+
e && e.type === "target" && !t && this.onRemoveChoice(e, r);
|
|
145
171
|
}
|
|
146
172
|
};
|
|
173
|
+
onDragStart = (e) => {
|
|
174
|
+
let { active: t } = e;
|
|
175
|
+
t?.data?.current && this.selectChoice(t.data.current);
|
|
176
|
+
};
|
|
177
|
+
onDragCancel = () => {
|
|
178
|
+
this.cancelSelection(), this.lastDragEndAt = Date.now();
|
|
179
|
+
};
|
|
180
|
+
isSameChoice = (e, t) => !!e && !!t && e.type === t.type && e.id === t.id && e.index === t.index;
|
|
181
|
+
selectChoice = (e) => {
|
|
182
|
+
this.setState({ selectedChoice: e });
|
|
183
|
+
};
|
|
184
|
+
toggleChoiceSelection = (e) => {
|
|
185
|
+
this.setState((t) => ({ selectedChoice: this.isSameChoice(t.selectedChoice, e) ? null : e }));
|
|
186
|
+
};
|
|
187
|
+
cancelSelection = () => {
|
|
188
|
+
this.setState({ selectedChoice: null });
|
|
189
|
+
};
|
|
190
|
+
endAnyLiveKeyboardDrag = () => {
|
|
191
|
+
document.dispatchEvent(new KeyboardEvent("keydown", {
|
|
192
|
+
code: "Escape",
|
|
193
|
+
bubbles: !0,
|
|
194
|
+
cancelable: !0
|
|
195
|
+
}));
|
|
196
|
+
};
|
|
197
|
+
placeSelectedChoice = (e) => {
|
|
198
|
+
let { selectedChoice: t } = this.state;
|
|
199
|
+
if (!t) return;
|
|
200
|
+
let n = this.createOrdering();
|
|
201
|
+
this.onDropChoice(e, t, n), this.cancelSelection(), this.endAnyLiveKeyboardDrag(), this.lastDragEndAt = Date.now();
|
|
202
|
+
};
|
|
203
|
+
isClickSoonAfterDragEnd = () => Date.now() - this.lastDragEndAt < z;
|
|
204
|
+
onChoiceClick = (e) => {
|
|
205
|
+
this.isClickSoonAfterDragEnd() || this.toggleChoiceSelection(e);
|
|
206
|
+
};
|
|
207
|
+
onPlacementClick = (e) => {
|
|
208
|
+
this.isClickSoonAfterDragEnd() || this.placeSelectedChoice(e);
|
|
209
|
+
};
|
|
147
210
|
render() {
|
|
148
|
-
let { model: n } = this.props, { correctResponse: r, correctness: i, extraCSSRules: a, prompt: o, rationale: s, feedback: c, config: l, note: u, showNote: d, env: f, disabled: p, teacherInstructions:
|
|
211
|
+
let { model: n } = this.props, { correctResponse: r, correctness: i, extraCSSRules: a, prompt: o, rationale: s, feedback: c, config: l, note: u, showNote: d, env: f, disabled: p, teacherInstructions: m, language: _ } = n, v = r && r.length > 0, { showingCorrect: y } = this.state, b = l || {
|
|
149
212
|
orientation: "vertical",
|
|
150
213
|
includeTargets: !0
|
|
151
|
-
}, { orientation:
|
|
152
|
-
color:
|
|
153
|
-
backgroundColor:
|
|
214
|
+
}, { orientation: x, includeTargets: D } = b, O = x === "vertical", A = this.createOrdering(), { mode: j, role: F } = f || {}, I = O ? t : e, L = (y || j === "view" && F === "instructor") && d && u, R = s && (w(s) || C(s)), z = m && (w(m) || C(m)), B = {
|
|
215
|
+
color: S.text(),
|
|
216
|
+
backgroundColor: S.background(),
|
|
154
217
|
display: "flex",
|
|
155
218
|
flexDirection: "column",
|
|
156
219
|
alignItems: "center",
|
|
157
|
-
boxSizing: "border-box"
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
220
|
+
boxSizing: "border-box",
|
|
221
|
+
width: "100%"
|
|
222
|
+
}, H = D ? {
|
|
223
|
+
selectedChoice: this.state.selectedChoice,
|
|
224
|
+
onChoiceClick: this.onChoiceClick,
|
|
225
|
+
onPlacementClick: this.onPlacementClick
|
|
226
|
+
} : {};
|
|
227
|
+
return /* @__PURE__ */ T(k, {
|
|
228
|
+
onDragStart: this.onDragStart,
|
|
161
229
|
onDragEnd: this.onDragEnd,
|
|
162
|
-
|
|
163
|
-
|
|
230
|
+
onDragCancel: this.onDragCancel,
|
|
231
|
+
collisionDetection: h,
|
|
232
|
+
modifiers: [g],
|
|
233
|
+
...V(D),
|
|
234
|
+
children: /* @__PURE__ */ T(W, { children: /* @__PURE__ */ E(M, {
|
|
164
235
|
extraCSSRules: a,
|
|
165
|
-
style:
|
|
236
|
+
style: B,
|
|
166
237
|
children: [
|
|
167
|
-
|
|
238
|
+
z && /* @__PURE__ */ T(X, {
|
|
168
239
|
labels: {
|
|
169
240
|
hidden: "Show Teacher Instructions",
|
|
170
241
|
visible: "Hide Teacher Instructions"
|
|
171
242
|
},
|
|
172
243
|
className: "collapsible",
|
|
173
|
-
children: /* @__PURE__ */
|
|
244
|
+
children: /* @__PURE__ */ T(N, { prompt: m })
|
|
174
245
|
}),
|
|
175
|
-
/* @__PURE__ */
|
|
176
|
-
/* @__PURE__ */
|
|
177
|
-
show:
|
|
178
|
-
toggled:
|
|
246
|
+
/* @__PURE__ */ T(q, { children: /* @__PURE__ */ T(N, { prompt: o }) }),
|
|
247
|
+
/* @__PURE__ */ T(Y, {
|
|
248
|
+
show: v,
|
|
249
|
+
toggled: y,
|
|
179
250
|
onToggle: this.toggleCorrect,
|
|
180
|
-
language:
|
|
251
|
+
language: _
|
|
181
252
|
}),
|
|
182
|
-
/* @__PURE__ */
|
|
253
|
+
/* @__PURE__ */ T(G, { children: /* @__PURE__ */ T(K, { children: /* @__PURE__ */ T(Z, {
|
|
183
254
|
instanceId: this.instanceId,
|
|
184
|
-
choiceLabel:
|
|
185
|
-
targetLabel:
|
|
186
|
-
ordering:
|
|
187
|
-
tiler:
|
|
255
|
+
choiceLabel: b.choiceLabel,
|
|
256
|
+
targetLabel: b.targetLabel,
|
|
257
|
+
ordering: A,
|
|
258
|
+
tiler: I,
|
|
188
259
|
disabled: p,
|
|
189
|
-
addGuide:
|
|
190
|
-
tileSize:
|
|
191
|
-
includeTargets:
|
|
192
|
-
choiceLabelEnabled: n.config && n.config.choiceLabelEnabled
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
L && /* @__PURE__ */
|
|
260
|
+
addGuide: b.showOrdering,
|
|
261
|
+
tileSize: b.tileSize,
|
|
262
|
+
includeTargets: D,
|
|
263
|
+
choiceLabelEnabled: n.config && n.config.choiceLabelEnabled,
|
|
264
|
+
...H
|
|
265
|
+
}) }) }),
|
|
266
|
+
L && /* @__PURE__ */ T(J, { dangerouslySetInnerHTML: { __html: u } }),
|
|
267
|
+
R && /* @__PURE__ */ T(X, {
|
|
196
268
|
labels: {
|
|
197
269
|
hidden: "Show Rationale",
|
|
198
270
|
visible: "Hide Rationale"
|
|
199
271
|
},
|
|
200
272
|
className: "collapsible",
|
|
201
|
-
children: /* @__PURE__ */
|
|
273
|
+
children: /* @__PURE__ */ T(N, { prompt: s })
|
|
202
274
|
}),
|
|
203
|
-
!
|
|
275
|
+
!y && /* @__PURE__ */ T(P, {
|
|
204
276
|
correctness: i,
|
|
205
277
|
feedback: c
|
|
206
278
|
})
|
|
@@ -210,4 +282,4 @@ var G = class extends a.Component {
|
|
|
210
282
|
}
|
|
211
283
|
};
|
|
212
284
|
//#endregion
|
|
213
|
-
export {
|
|
285
|
+
export { Q as PlacementOrdering, Q as default };
|
package/dist/delivery/tile.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ export declare const Tile: {
|
|
|
23
23
|
instanceId: PropTypes.Requireable<any>;
|
|
24
24
|
draggable: PropTypes.Requireable<boolean>;
|
|
25
25
|
tileIndex: PropTypes.Requireable<number>;
|
|
26
|
+
selectedChoice: PropTypes.Requireable<object>;
|
|
27
|
+
onChoiceClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
28
|
+
onPlacementClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
26
29
|
};
|
|
27
30
|
};
|
|
28
31
|
export default Tile;
|