@pie-element/match-list 7.1.2-next.10 → 7.1.2-next.12

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.
@@ -139,7 +139,7 @@ function y(e) {
139
139
  if (h) {
140
140
  let t = () => {
141
141
  l || (N ? f?.(g) : d ? p?.(y) : s && f?.(g));
142
- }, n = !s && !l;
142
+ }, n = !s && !l && j;
143
143
  return /* @__PURE__ */ c("div", {
144
144
  ref: D,
145
145
  role: "button",
@@ -160,6 +160,7 @@ function y(e) {
160
160
  ref: S,
161
161
  ...x,
162
162
  ...b,
163
+ "data-tile-id": `${r}:${m}`,
163
164
  style: {
164
165
  transform: P,
165
166
  transition: w
@@ -180,6 +181,7 @@ function y(e) {
180
181
  ref: S,
181
182
  ...x,
182
183
  ...b,
184
+ "data-tile-id": `${r}:${m}`,
183
185
  onClick: F,
184
186
  style: {
185
187
  transform: P,
@@ -21,6 +21,8 @@ export declare class Main extends React.Component {
21
21
  onDragCancel: any;
22
22
  placeAnswer: any;
23
23
  onPlaceAnswer: any;
24
+ getDestinationDragId: any;
25
+ focusTile: any;
24
26
  isSameAnswer: (a: any, b: any) => boolean;
25
27
  selectAnswer: any;
26
28
  toggleAnswerSelection: any;
@@ -1,61 +1,61 @@
1
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";
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";
16
16
  //#region src/delivery/main.tsx
17
- function T(e) {
17
+ function E(e) {
18
18
  return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
19
19
  }
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;
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;
22
22
  }
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,
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
25
  options: { activationConstraint: { distance: 8 } }
26
26
  }, {
27
- sensor: u,
27
+ sensor: d,
28
28
  options: {
29
29
  coordinateGetter: e,
30
30
  keyboardCodes: {
31
- start: [l.Space, l.Enter],
32
- cancel: [l.Esc],
33
- end: [l.Space, l.Enter]
31
+ start: [u.Space, u.Enter],
32
+ cancel: [u.Esc],
33
+ end: [u.Space, u.Enter]
34
34
  }
35
35
  }
36
- }], P = x("div")({
36
+ }], F = S("div")({
37
37
  display: "flex",
38
38
  flexDirection: "column",
39
39
  justifyContent: "center",
40
- color: v.text(),
41
- backgroundColor: v.background()
42
- }), F = x("div")({
40
+ color: y.text(),
41
+ backgroundColor: y.background()
42
+ }), I = S("div")({
43
43
  width: "100%",
44
44
  overflowX: "auto",
45
45
  overflowY: "hidden"
46
- }), I = x("div")({
46
+ }), L = S("div")({
47
47
  display: "flex",
48
48
  flexDirection: "column",
49
49
  minWidth: "min-content"
50
- }), L = class extends i.Component {
50
+ }), R = class extends a.Component {
51
51
  static propTypes = {
52
- session: a.object.isRequired,
53
- onSessionChange: a.func,
54
- model: a.object.isRequired,
55
- prompt: a.string
52
+ session: o.object.isRequired,
53
+ onSessionChange: o.func,
54
+ model: o.object.isRequired,
55
+ prompt: o.string
56
56
  };
57
57
  constructor(e) {
58
- super(e), this.instanceId = w(), this.state = {
58
+ super(e), this.instanceId = T(), this.state = {
59
59
  showCorrectAnswer: !1,
60
60
  draggingElement: null,
61
61
  selectedAnswer: null
@@ -88,20 +88,20 @@ var D = E(_, "PreviewPrompt") || E(j.PreviewPrompt, "PreviewPrompt"), O = E(g, "
88
88
  placeAnswer = (e, t) => {
89
89
  if (!e || !t) return;
90
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) {
91
+ if (w(n.value) && (n.value = {}), t.type === "choices-pool" && e.promptId !== void 0) {
92
92
  n.value[e.promptId] = void 0, r(n);
93
93
  return;
94
94
  }
95
- let s = e.id, c = e.promptId;
95
+ let o = e.id, c = e.promptId;
96
96
  if (t.type === "drop-zone" && t.promptId != null) {
97
97
  let i = t.promptId;
98
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;
99
+ let e = C(n.value, (e) => e === o);
100
+ e && !a ? n.value = s(n.value, e, i) : n.value[i] = o;
101
101
  } else if (e.type === "target" && c != null && c !== i) if (n.value[i] != null && !a) {
102
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];
103
+ n.value[i] = o, n.value[c] = e;
104
+ } else n.value[i] = o, delete n.value[c];
105
105
  r(n);
106
106
  }
107
107
  };
@@ -110,7 +110,25 @@ var D = E(_, "PreviewPrompt") || E(j.PreviewPrompt, "PreviewPrompt"), O = E(g, "
110
110
  let { active: t, over: n } = e;
111
111
  if (!t) return;
112
112
  let r = t.data.current, i = n?.data.current;
113
- r && (this.placeAnswer(r, i), this.cancelSelection(), this.lastDragEndAt = Date.now());
113
+ if (!r) return;
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
+ });
114
132
  };
115
133
  isSameAnswer = (e, t) => !!e && !!t && e.type === t.type && e.id === t.id && e.promptId === t.promptId;
116
134
  selectAnswer = (e) => {
@@ -131,9 +149,11 @@ var D = E(_, "PreviewPrompt") || E(j.PreviewPrompt, "PreviewPrompt"), O = E(g, "
131
149
  };
132
150
  placeSelectedAnswer = (e) => {
133
151
  let { selectedAnswer: t } = this.state;
134
- t && (this.placeAnswer(t, e), this.cancelSelection(), this.endAnyLiveKeyboardDrag(), this.lastDragEndAt = Date.now());
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);
135
155
  };
136
- isClickSoonAfterDragEnd = () => Date.now() - this.lastDragEndAt < M;
156
+ isClickSoonAfterDragEnd = () => Date.now() - this.lastDragEndAt < N;
137
157
  onChoiceClick = (e) => {
138
158
  this.isClickSoonAfterDragEnd() || this.toggleAnswerSelection(e);
139
159
  };
@@ -145,7 +165,7 @@ var D = E(_, "PreviewPrompt") || E(j.PreviewPrompt, "PreviewPrompt"), O = E(g, "
145
165
  };
146
166
  renderDragOverlay = () => {
147
167
  let { draggingElement: e } = this.state;
148
- return e ? /* @__PURE__ */ y(t, {
168
+ return e ? /* @__PURE__ */ b(t, {
149
169
  id: e.id,
150
170
  title: e.value,
151
171
  disabled: !1,
@@ -158,53 +178,53 @@ var D = E(_, "PreviewPrompt") || E(j.PreviewPrompt, "PreviewPrompt"), O = E(g, "
158
178
  }) : null;
159
179
  };
160
180
  render() {
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,
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,
165
185
  onDragStart: this.onDragStart,
166
186
  onDragEnd: this.onPlaceAnswer,
167
187
  onDragCancel: this.onDragCancel,
168
- modifiers: [p],
188
+ modifiers: [m],
169
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." } },
170
- children: [/* @__PURE__ */ b(P, { children: [
171
- /* @__PURE__ */ y(D, {
190
+ children: [/* @__PURE__ */ x(F, { children: [
191
+ /* @__PURE__ */ b(O, {
172
192
  className: "prompt",
173
- prompt: l
193
+ prompt: s
174
194
  }),
175
- /* @__PURE__ */ y(m, {
195
+ /* @__PURE__ */ b(h, {
176
196
  show: o === "evaluate",
177
197
  toggled: e,
178
198
  onToggle: this.toggleShowCorrect,
179
199
  language: u
180
200
  }),
181
- /* @__PURE__ */ y(F, { children: /* @__PURE__ */ b(I, { children: [/* @__PURE__ */ y(n, {
201
+ /* @__PURE__ */ b(I, { children: /* @__PURE__ */ x(L, { children: [/* @__PURE__ */ b(r, {
182
202
  instanceId: this.instanceId,
183
203
  model: t,
184
- session: i,
204
+ session: n,
185
205
  onRemoveAnswer: (e) => this.onRemoveAnswer(e),
186
206
  disabled: o !== "gather",
187
207
  showCorrect: e,
188
208
  selectedAnswer: this.state.selectedAnswer,
189
209
  onChoiceClick: this.onChoiceClick,
190
210
  onPlacementClick: this.onPlacementClick
191
- }), /* @__PURE__ */ y(r, {
211
+ }), /* @__PURE__ */ b(i, {
192
212
  instanceId: this.instanceId,
193
213
  model: t,
194
- session: i,
214
+ session: n,
195
215
  disabled: o !== "gather",
196
216
  onRemoveAnswer: (e) => this.onRemoveAnswer(e),
197
217
  selectedAnswer: this.state.selectedAnswer,
198
218
  onChoiceClick: this.onChoiceClick,
199
219
  onPlacementClick: this.onPlacementClick
200
220
  })] }) }),
201
- t.correctness && t.feedback && !e && /* @__PURE__ */ y(O, {
221
+ t.correctness && t.feedback && !e && /* @__PURE__ */ b(k, {
202
222
  correctness: t.correctness.correctness,
203
223
  feedback: t.feedback
204
224
  })
205
- ] }), /* @__PURE__ */ y(c, { children: this.renderDragOverlay() })]
225
+ ] }), /* @__PURE__ */ b(l, { children: this.renderDragOverlay() })]
206
226
  });
207
227
  }
208
228
  };
209
229
  //#endregion
210
- export { L as Main, L as default };
230
+ export { R as Main, R as default };