@pie-element/placement-ordering 14.1.2-next.11 → 14.1.2-next.13
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/author/index.js +23433 -30942
- package/dist/browser/author/index.js.map +1 -1
- package/dist/browser/delivery/index.js +181 -169
- package/dist/browser/delivery/index.js.map +1 -1
- package/dist/browser/{drag-provider-B5wazJHM.js → drag-provider-CfLLSbf2.js} +781 -779
- package/dist/browser/drag-provider-CfLLSbf2.js.map +1 -0
- package/dist/delivery/ordering.js +13 -19
- package/dist/delivery/placement-ordering.d.ts +2 -0
- package/dist/delivery/placement-ordering.js +18 -5
- package/dist/delivery/tile.js +11 -6
- package/dist/index.iife.js +21 -21
- package/package.json +6 -6
- package/dist/browser/drag-provider-B5wazJHM.js.map +0 -1
|
@@ -8,26 +8,20 @@ var a = i("pie-elements:placement-ordering:ordering"), o = (e, t, n) => {
|
|
|
8
8
|
r,
|
|
9
9
|
...i.slice(n)
|
|
10
10
|
];
|
|
11
|
-
}, s = (e, n, r) => {
|
|
12
|
-
if (a("[swap]", e, n, r), !e || e.length <= 1 || n === void 0 || r === void 0) throw Error(`swap requires a non-empty array, fromIndex, toIndex: ${e}, ${n} ${r}`);
|
|
13
|
-
let i = t(e), o = e[r];
|
|
14
|
-
return i[r] = i[n], i[n] = o, i;
|
|
15
11
|
};
|
|
16
|
-
function
|
|
12
|
+
function s(e, n) {
|
|
17
13
|
let r = t(e.response);
|
|
18
14
|
if (r[n.index] === n.id) r[n.index] = void 0;
|
|
19
15
|
else throw Error(`Tried to remove from index: ${n.index}, but the id doesn't match: array: ${r}, target: ${n.id}`);
|
|
20
16
|
return r;
|
|
21
17
|
}
|
|
22
|
-
function
|
|
23
|
-
let { response: i, opts:
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return a("fromIndex: ", t, "toIndex:", i), o(e.response, t, i);
|
|
28
|
-
}
|
|
18
|
+
function c(e, n, r) {
|
|
19
|
+
let { response: i, opts: s } = e, c = t(i);
|
|
20
|
+
if (s.includeTargets) return n.type === "choice" && r.type === "target" ? (c[r.index] = n.id, c) : n.type === "target" && r.type === "choice" ? (c[n.index] = void 0, c) : n.type === "target" && r.type === "target" ? (c[r.index] = n.id, c[n.index] = void 0, c) : (a("do nothing to the response"), i);
|
|
21
|
+
let l = e.response.findIndex((e) => e !== void 0 && e === n.id), u = e.response.findIndex((e) => e !== void 0 && e === r.id);
|
|
22
|
+
return a("fromIndex: ", l, "toIndex:", u), o(e.response, l, u);
|
|
29
23
|
}
|
|
30
|
-
function
|
|
24
|
+
function l(e, t, n, r) {
|
|
31
25
|
if (r.includeTargets) {
|
|
32
26
|
let i = [];
|
|
33
27
|
for (let r = 0; r < t.length; r++) {
|
|
@@ -62,26 +56,26 @@ function u(e, t, n, r) {
|
|
|
62
56
|
return i === 0 && t.push(a), t.push(o, a), t;
|
|
63
57
|
}, []);
|
|
64
58
|
}
|
|
65
|
-
function
|
|
59
|
+
function u(t, i, a, o) {
|
|
66
60
|
return o = e({ includeTargets: !0 }, o), a ||= [], i = !i || n(i) ? o.includeTargets ? Array(t.length) : r(t, (e) => e.id) : i, {
|
|
67
61
|
choices: t,
|
|
68
62
|
response: i,
|
|
69
63
|
opts: o,
|
|
70
64
|
outcomes: a,
|
|
71
|
-
tiles:
|
|
65
|
+
tiles: l(t, i, a, o)
|
|
72
66
|
};
|
|
73
67
|
}
|
|
74
|
-
function
|
|
68
|
+
function d(e, t) {
|
|
75
69
|
switch (e.type) {
|
|
76
70
|
case "move": {
|
|
77
|
-
let { from: n, to: r } = e, i =
|
|
71
|
+
let { from: n, to: r } = e, i = c(t, n, r), a = l(t.choices, i, t.outcomes, t.opts);
|
|
78
72
|
return Object.assign({}, t, {
|
|
79
73
|
response: i,
|
|
80
74
|
tiles: a
|
|
81
75
|
});
|
|
82
76
|
}
|
|
83
77
|
case "remove": {
|
|
84
|
-
let { target: n } = e, r =
|
|
78
|
+
let { target: n } = e, r = s(t, n), i = l(t.choices, r, t.outcomes, t.opts);
|
|
85
79
|
return Object.assign({}, t, {
|
|
86
80
|
response: r,
|
|
87
81
|
tiles: i
|
|
@@ -91,4 +85,4 @@ function f(e, t) {
|
|
|
91
85
|
return t;
|
|
92
86
|
}
|
|
93
87
|
//#endregion
|
|
94
|
-
export {
|
|
88
|
+
export { u as buildState, o as push, d as reducer };
|
|
@@ -31,6 +31,8 @@ export declare class PlacementOrdering extends React.Component {
|
|
|
31
31
|
cancelSelection: any;
|
|
32
32
|
endAnyLiveKeyboardDrag: any;
|
|
33
33
|
placeSelectedChoice: any;
|
|
34
|
+
getDestinationSlotId: any;
|
|
35
|
+
focusTile: any;
|
|
34
36
|
isClickSoonAfterDragEnd: () => boolean;
|
|
35
37
|
onChoiceClick: any;
|
|
36
38
|
onPlacementClick: any;
|
|
@@ -161,13 +161,16 @@ var Q = class extends o.Component {
|
|
|
161
161
|
if (this.cancelSelection(), this.lastDragEndAt = Date.now(), t && n) {
|
|
162
162
|
let e = n.data.current, i = t.data.current;
|
|
163
163
|
if (e && i && i.type === "target") {
|
|
164
|
-
this.onDropChoice(i, e, r);
|
|
164
|
+
this.onDropChoice(i, e, r), this.focusTile(this.getDestinationSlotId(i));
|
|
165
165
|
return;
|
|
166
166
|
}
|
|
167
|
-
e && i && this.onDropChoice(i, e, r);
|
|
167
|
+
e && i && (this.onDropChoice(i, e, r), this.focusTile(this.getDestinationSlotId(i)));
|
|
168
168
|
} else if (!t && n) {
|
|
169
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)
|
|
170
|
+
e && e.type === "target" && !t && (this.onRemoveChoice(e, r), this.focusTile(this.getDestinationSlotId({
|
|
171
|
+
type: "choice",
|
|
172
|
+
id: e.id
|
|
173
|
+
})));
|
|
171
174
|
}
|
|
172
175
|
};
|
|
173
176
|
onDragStart = (e) => {
|
|
@@ -197,8 +200,18 @@ var Q = class extends o.Component {
|
|
|
197
200
|
placeSelectedChoice = (e) => {
|
|
198
201
|
let { selectedChoice: t } = this.state;
|
|
199
202
|
if (!t) return;
|
|
200
|
-
let n = this.createOrdering();
|
|
201
|
-
this.onDropChoice(e, t, n), this.cancelSelection(), this.endAnyLiveKeyboardDrag(), this.lastDragEndAt = Date.now();
|
|
203
|
+
let n = this.createOrdering(), r = this.getDestinationSlotId(e);
|
|
204
|
+
this.onDropChoice(e, t, n), this.cancelSelection(), this.endAnyLiveKeyboardDrag(), this.lastDragEndAt = Date.now(), this.focusTile(r);
|
|
205
|
+
};
|
|
206
|
+
getDestinationSlotId = (e) => e ? e.type === "target" ? `target-${e.index}` : e.type === "choice" ? `choice-${e.id}` : null : null;
|
|
207
|
+
focusTile = (e) => {
|
|
208
|
+
if (!e) return;
|
|
209
|
+
let t = `[data-tile-id="${this.instanceId}:${e}"]`;
|
|
210
|
+
requestAnimationFrame(() => {
|
|
211
|
+
requestAnimationFrame(() => {
|
|
212
|
+
document.querySelector(t)?.focus();
|
|
213
|
+
});
|
|
214
|
+
});
|
|
202
215
|
};
|
|
203
216
|
isClickSoonAfterDragEnd = () => Date.now() - this.lastDragEndAt < z;
|
|
204
217
|
onChoiceClick = (e) => {
|
package/dist/delivery/tile.js
CHANGED
|
@@ -102,20 +102,24 @@ var f = r("div")(({ theme: e, isDragging: t, isSelected: n, isOver: r, disabled:
|
|
|
102
102
|
disabled: O
|
|
103
103
|
}), j = !!v && v.type === C.type && v.id === C.id && v.index === C.index, [M, N] = e.useState(!1), P = !!v && !u, F = A || r === "target" && P && M, I = () => {
|
|
104
104
|
u || (r === "choice" ? v?.type === "target" ? b?.(C) : g && y?.(C) : r === "target" && (j ? y?.(C) : v ? b?.(C) : g && y?.(C)));
|
|
105
|
-
}, L = !(g && !u) && !u, R = (e) => {
|
|
105
|
+
}, L = !(g && !u) && !u && P, R = (e) => {
|
|
106
106
|
(e.code === "Space" || e.code === "Enter") && (e.preventDefault(), I());
|
|
107
107
|
}, z = e.useRef(null);
|
|
108
|
-
|
|
108
|
+
e.useEffect(() => {
|
|
109
109
|
let e = z.current, t = (e) => {
|
|
110
110
|
e.preventDefault();
|
|
111
111
|
};
|
|
112
112
|
return e && e.addEventListener("touchstart", t, { passive: !1 }), () => {
|
|
113
113
|
e && e.removeEventListener("touchstart", t);
|
|
114
114
|
};
|
|
115
|
-
}, [])
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
}, []);
|
|
116
|
+
let B = (e) => {
|
|
117
|
+
z.current = e, E(e), k(e);
|
|
118
|
+
};
|
|
119
|
+
l("[render], props: ", t);
|
|
120
|
+
let V = r === "target" ? `target-${f}` : r === "choice" ? `choice-${o}` : null, H = V ? `${h}:${V}` : void 0;
|
|
121
|
+
return /* @__PURE__ */ s("div", {
|
|
122
|
+
ref: B,
|
|
119
123
|
style: {
|
|
120
124
|
transform: D ? `translate3d(${D.x}px, ${D.y}px, 0)` : void 0,
|
|
121
125
|
boxSizing: "border-box",
|
|
@@ -134,6 +138,7 @@ var f = r("div")(({ theme: e, isDragging: t, isSelected: n, isOver: r, disabled:
|
|
|
134
138
|
onClick: I,
|
|
135
139
|
onMouseEnter: () => N(!0),
|
|
136
140
|
onMouseLeave: () => N(!1),
|
|
141
|
+
"data-tile-id": H,
|
|
137
142
|
...g && !u ? {
|
|
138
143
|
...T,
|
|
139
144
|
...w
|