@pie-element/placement-ordering 14.1.2-next.11 → 14.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.
@@ -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) => {
@@ -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
- return e.useEffect(() => {
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
- }, []), l("[render], props: ", t), /* @__PURE__ */ s("div", {
116
- ref: (e) => {
117
- z.current = e, E(e), k(e);
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