@sia.soul/sia-react-ui 0.1.144 → 0.1.145
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/core.css +20 -33
- package/dist/game.css +20 -33
- package/dist/index.cjs +235 -76
- package/dist/index.css +20 -33
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +235 -76
- package/package.json +1 -1
package/dist/core.css
CHANGED
|
@@ -5516,6 +5516,7 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5516
5516
|
margin-bottom: 8px;
|
|
5517
5517
|
}
|
|
5518
5518
|
.sia-sortable-list {
|
|
5519
|
+
position: relative;
|
|
5519
5520
|
display: flex;
|
|
5520
5521
|
gap: 16px;
|
|
5521
5522
|
overflow: auto;
|
|
@@ -5531,7 +5532,25 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5531
5532
|
min-width: 0;
|
|
5532
5533
|
}
|
|
5533
5534
|
.sia-sortable-list__item.is-dragging {
|
|
5534
|
-
|
|
5535
|
+
z-index: 2;
|
|
5536
|
+
filter: drop-shadow(0 6px 8px rgb(0 0 0 / 16%));
|
|
5537
|
+
}
|
|
5538
|
+
.sia-sortable-list__placeholder {
|
|
5539
|
+
position: absolute;
|
|
5540
|
+
box-sizing: border-box;
|
|
5541
|
+
border: 2px dashed var(--sia-color-primary);
|
|
5542
|
+
border-radius: var(--sia-radius-md, 6px);
|
|
5543
|
+
background: var(--sia-color-primary-light);
|
|
5544
|
+
pointer-events: none;
|
|
5545
|
+
}
|
|
5546
|
+
.sia-sortable-list.is-sorting {
|
|
5547
|
+
user-select: none;
|
|
5548
|
+
}
|
|
5549
|
+
.sia-sortable-list.is-sorting .sia-sortable-list__handle {
|
|
5550
|
+
cursor: grabbing;
|
|
5551
|
+
}
|
|
5552
|
+
.sia-sortable-list__handle {
|
|
5553
|
+
touch-action: none;
|
|
5535
5554
|
}
|
|
5536
5555
|
.sia-sortable-list__handle {
|
|
5537
5556
|
display: flex;
|
|
@@ -5560,38 +5579,6 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5560
5579
|
background: transparent;
|
|
5561
5580
|
text-align: start;
|
|
5562
5581
|
}
|
|
5563
|
-
.sia-sortable-list__item.is-drop-before::before,
|
|
5564
|
-
.sia-sortable-list__item.is-drop-after::after {
|
|
5565
|
-
content: "";
|
|
5566
|
-
position: absolute;
|
|
5567
|
-
background: var(--sia-color-primary);
|
|
5568
|
-
pointer-events: none;
|
|
5569
|
-
z-index: 1;
|
|
5570
|
-
}
|
|
5571
|
-
.sia-sortable-list--horizontal .is-drop-before::before {
|
|
5572
|
-
top: 0;
|
|
5573
|
-
bottom: 0;
|
|
5574
|
-
left: -9px;
|
|
5575
|
-
width: 2px;
|
|
5576
|
-
}
|
|
5577
|
-
.sia-sortable-list--horizontal .is-drop-after::after {
|
|
5578
|
-
top: 0;
|
|
5579
|
-
bottom: 0;
|
|
5580
|
-
right: -9px;
|
|
5581
|
-
width: 2px;
|
|
5582
|
-
}
|
|
5583
|
-
.sia-sortable-list--vertical .is-drop-before::before {
|
|
5584
|
-
left: 0;
|
|
5585
|
-
right: 0;
|
|
5586
|
-
top: -9px;
|
|
5587
|
-
height: 2px;
|
|
5588
|
-
}
|
|
5589
|
-
.sia-sortable-list--vertical .is-drop-after::after {
|
|
5590
|
-
left: 0;
|
|
5591
|
-
right: 0;
|
|
5592
|
-
bottom: -9px;
|
|
5593
|
-
height: 2px;
|
|
5594
|
-
}
|
|
5595
5582
|
.sia-popover.sia-popover--wide {
|
|
5596
5583
|
width: 760px;
|
|
5597
5584
|
max-width: calc(100vw - 32px);
|
package/dist/game.css
CHANGED
|
@@ -5567,6 +5567,7 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5567
5567
|
margin-bottom: 8px;
|
|
5568
5568
|
}
|
|
5569
5569
|
.sia-sortable-list {
|
|
5570
|
+
position: relative;
|
|
5570
5571
|
display: flex;
|
|
5571
5572
|
gap: 16px;
|
|
5572
5573
|
overflow: auto;
|
|
@@ -5582,7 +5583,25 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5582
5583
|
min-width: 0;
|
|
5583
5584
|
}
|
|
5584
5585
|
.sia-sortable-list__item.is-dragging {
|
|
5585
|
-
|
|
5586
|
+
z-index: 2;
|
|
5587
|
+
filter: drop-shadow(0 6px 8px rgb(0 0 0 / 16%));
|
|
5588
|
+
}
|
|
5589
|
+
.sia-sortable-list__placeholder {
|
|
5590
|
+
position: absolute;
|
|
5591
|
+
box-sizing: border-box;
|
|
5592
|
+
border: 2px dashed var(--sia-color-primary);
|
|
5593
|
+
border-radius: var(--sia-radius-md, 6px);
|
|
5594
|
+
background: var(--sia-color-primary-light);
|
|
5595
|
+
pointer-events: none;
|
|
5596
|
+
}
|
|
5597
|
+
.sia-sortable-list.is-sorting {
|
|
5598
|
+
user-select: none;
|
|
5599
|
+
}
|
|
5600
|
+
.sia-sortable-list.is-sorting .sia-sortable-list__handle {
|
|
5601
|
+
cursor: grabbing;
|
|
5602
|
+
}
|
|
5603
|
+
.sia-sortable-list__handle {
|
|
5604
|
+
touch-action: none;
|
|
5586
5605
|
}
|
|
5587
5606
|
.sia-sortable-list__handle {
|
|
5588
5607
|
display: flex;
|
|
@@ -5611,38 +5630,6 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5611
5630
|
background: transparent;
|
|
5612
5631
|
text-align: start;
|
|
5613
5632
|
}
|
|
5614
|
-
.sia-sortable-list__item.is-drop-before::before,
|
|
5615
|
-
.sia-sortable-list__item.is-drop-after::after {
|
|
5616
|
-
content: "";
|
|
5617
|
-
position: absolute;
|
|
5618
|
-
background: var(--sia-color-primary);
|
|
5619
|
-
pointer-events: none;
|
|
5620
|
-
z-index: 1;
|
|
5621
|
-
}
|
|
5622
|
-
.sia-sortable-list--horizontal .is-drop-before::before {
|
|
5623
|
-
top: 0;
|
|
5624
|
-
bottom: 0;
|
|
5625
|
-
left: -9px;
|
|
5626
|
-
width: 2px;
|
|
5627
|
-
}
|
|
5628
|
-
.sia-sortable-list--horizontal .is-drop-after::after {
|
|
5629
|
-
top: 0;
|
|
5630
|
-
bottom: 0;
|
|
5631
|
-
right: -9px;
|
|
5632
|
-
width: 2px;
|
|
5633
|
-
}
|
|
5634
|
-
.sia-sortable-list--vertical .is-drop-before::before {
|
|
5635
|
-
left: 0;
|
|
5636
|
-
right: 0;
|
|
5637
|
-
top: -9px;
|
|
5638
|
-
height: 2px;
|
|
5639
|
-
}
|
|
5640
|
-
.sia-sortable-list--vertical .is-drop-after::after {
|
|
5641
|
-
left: 0;
|
|
5642
|
-
right: 0;
|
|
5643
|
-
bottom: -9px;
|
|
5644
|
-
height: 2px;
|
|
5645
|
-
}
|
|
5646
5633
|
.sia-popover.sia-popover--wide {
|
|
5647
5634
|
width: 760px;
|
|
5648
5635
|
max-width: calc(100vw - 32px);
|
package/dist/index.cjs
CHANGED
|
@@ -3143,84 +3143,243 @@ function FloatingPanel({ open, title, children, placement = "bottomRight" }) {
|
|
|
3143
3143
|
] }), document.body);
|
|
3144
3144
|
}
|
|
3145
3145
|
function SortableList({ items, renderItem, onOrderChange, direction = "horizontal", disabled = false, handlePlacement = "before", handleContent }) {
|
|
3146
|
-
const
|
|
3147
|
-
const
|
|
3148
|
-
const
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
};
|
|
3152
|
-
const
|
|
3153
|
-
const from = items.indexOf(key);
|
|
3154
|
-
if (disabled || from < 0) return;
|
|
3155
|
-
const to = Math.max(0, Math.min(items.length - 1, insertion > from ? insertion - 1 : insertion));
|
|
3156
|
-
if (to === from) return;
|
|
3157
|
-
const next = [...items];
|
|
3158
|
-
next.splice(from, 1);
|
|
3159
|
-
next.splice(to, 0, key);
|
|
3160
|
-
onOrderChange(next);
|
|
3161
|
-
};
|
|
3146
|
+
const rootRef = (0, import_react12.useRef)(null);
|
|
3147
|
+
const placeholderRef = (0, import_react12.useRef)(null);
|
|
3148
|
+
const latest = (0, import_react12.useRef)({ items, onOrderChange });
|
|
3149
|
+
latest.current = { items, onOrderChange };
|
|
3150
|
+
const startRef = (0, import_react12.useRef)(() => {
|
|
3151
|
+
});
|
|
3152
|
+
const signature = JSON.stringify(items);
|
|
3162
3153
|
(0, import_react12.useEffect)(() => {
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3154
|
+
const root = rootRef.current;
|
|
3155
|
+
if (!root) return;
|
|
3156
|
+
const horizontal = direction === "horizontal";
|
|
3157
|
+
let session = null;
|
|
3158
|
+
let frame = 0;
|
|
3159
|
+
let settling = null;
|
|
3160
|
+
const reduced = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
3161
|
+
const clear = () => {
|
|
3162
|
+
cancelAnimationFrame(frame);
|
|
3163
|
+
settling?.cancel();
|
|
3164
|
+
settling = null;
|
|
3165
|
+
const previous = session;
|
|
3166
|
+
session = null;
|
|
3167
|
+
root.classList.remove("is-sorting");
|
|
3168
|
+
previous?.nodes.forEach((node) => {
|
|
3169
|
+
node.classList.remove("is-dragging");
|
|
3170
|
+
node.style.removeProperty("transform");
|
|
3171
|
+
node.style.removeProperty("transition");
|
|
3172
|
+
});
|
|
3173
|
+
if (placeholderRef.current) placeholderRef.current.hidden = true;
|
|
3174
|
+
if (previous?.handle.hasPointerCapture(previous.pointer)) previous.handle.releasePointerCapture(previous.pointer);
|
|
3175
|
+
};
|
|
3176
|
+
const displacement = (s) => {
|
|
3177
|
+
const start = (r) => horizontal ? r.left : r.top;
|
|
3178
|
+
const length = (r) => horizontal ? r.width : r.height;
|
|
3179
|
+
const indices = s.keys.map((_, index) => index);
|
|
3180
|
+
indices.splice(s.from, 1);
|
|
3181
|
+
indices.splice(s.to, 0, s.from);
|
|
3182
|
+
const gap = Number.parseFloat(getComputedStyle(root).gap) || 0;
|
|
3183
|
+
let cursor = start(s.rects[0]);
|
|
3184
|
+
const offsets = s.rects.map(() => 0);
|
|
3185
|
+
indices.forEach((index) => {
|
|
3186
|
+
offsets[index] = cursor - start(s.rects[index]);
|
|
3187
|
+
cursor += length(s.rects[index]) + gap;
|
|
3188
|
+
});
|
|
3189
|
+
return offsets;
|
|
3190
|
+
};
|
|
3191
|
+
const transform = (offset) => horizontal ? `translate3d(${offset}px, 0, 0)` : `translate3d(0, ${offset}px, 0)`;
|
|
3192
|
+
const paint = () => {
|
|
3193
|
+
const s = session;
|
|
3194
|
+
if (!s || !s.active || settling) return;
|
|
3195
|
+
const bounds = root.getBoundingClientRect();
|
|
3196
|
+
const coordinate = horizontal ? s.clientX : s.clientY;
|
|
3197
|
+
const scroll = horizontal ? root.scrollLeft : root.scrollTop;
|
|
3198
|
+
const origin = s.rects[s.from];
|
|
3199
|
+
const first = s.rects[0];
|
|
3200
|
+
const last = s.rects[s.rects.length - 1];
|
|
3201
|
+
const minimum = horizontal ? first.left - origin.left : first.top - origin.top;
|
|
3202
|
+
const maximum = horizontal ? last.right - origin.right : last.bottom - origin.bottom;
|
|
3203
|
+
const delta = Math.max(minimum, Math.min(maximum, coordinate - s.start + scroll - s.scroll));
|
|
3204
|
+
const center = (horizontal ? origin.left + origin.width / 2 : origin.top + origin.height / 2) + delta;
|
|
3205
|
+
s.to = s.rects.filter((rect, index) => index !== s.from && center > (horizontal ? rect.left + rect.width / 2 : rect.top + rect.height / 2)).length;
|
|
3206
|
+
const offsets = displacement(s);
|
|
3207
|
+
s.nodes.forEach((node, index) => {
|
|
3208
|
+
node.style.transform = transform(index === s.from ? delta : offsets[index]);
|
|
3209
|
+
});
|
|
3210
|
+
const preview = placeholderRef.current;
|
|
3211
|
+
if (preview) {
|
|
3212
|
+
preview.hidden = false;
|
|
3213
|
+
preview.style.width = `${origin.width}px`;
|
|
3214
|
+
preview.style.height = `${origin.height}px`;
|
|
3215
|
+
preview.style.left = `${origin.left - bounds.left + root.scrollLeft - (horizontal ? scroll - s.scroll : 0) + (horizontal ? offsets[s.from] : 0)}px`;
|
|
3216
|
+
preview.style.top = `${origin.top - bounds.top + root.scrollTop - (!horizontal ? scroll - s.scroll : 0) + (!horizontal ? offsets[s.from] : 0)}px`;
|
|
3196
3217
|
}
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3218
|
+
};
|
|
3219
|
+
let lastTime = 0;
|
|
3220
|
+
const tick = (time) => {
|
|
3221
|
+
const s = session;
|
|
3222
|
+
if (!s || !s.active || settling) return;
|
|
3223
|
+
const bounds = root.getBoundingClientRect();
|
|
3224
|
+
const point = horizontal ? s.clientX : s.clientY;
|
|
3225
|
+
const start = horizontal ? bounds.left : bounds.top;
|
|
3226
|
+
const end = horizontal ? bounds.right : bounds.bottom;
|
|
3227
|
+
const crossInside = horizontal ? s.clientY >= bounds.top && s.clientY <= bounds.bottom : s.clientX >= bounds.left && s.clientX <= bounds.right;
|
|
3228
|
+
const edge = 44;
|
|
3229
|
+
const speed = !crossInside || point < start || point > end ? 0 : point < start + edge ? -Math.min(1, (start + edge - point) / edge) : point > end - edge ? Math.min(1, (point - end + edge) / edge) : 0;
|
|
3230
|
+
const distance3 = speed * Math.min(32, time - (lastTime || time)) * 0.65;
|
|
3231
|
+
lastTime = time;
|
|
3232
|
+
if (horizontal) root.scrollLeft += distance3;
|
|
3233
|
+
else root.scrollTop += distance3;
|
|
3234
|
+
paint();
|
|
3235
|
+
frame = requestAnimationFrame(tick);
|
|
3236
|
+
};
|
|
3237
|
+
startRef.current = (event, key, handle) => {
|
|
3238
|
+
if (disabled || event.button !== 0 || !event.isPrimary || session || settling) return;
|
|
3239
|
+
const keys = [...latest.current.items];
|
|
3240
|
+
const from = keys.indexOf(key);
|
|
3241
|
+
if (from < 0) return;
|
|
3242
|
+
const nodes = Array.from(root.children).filter((node) => node.getAttribute("role") === "listitem");
|
|
3243
|
+
session = {
|
|
3244
|
+
key,
|
|
3245
|
+
pointer: event.pointerId,
|
|
3246
|
+
handle,
|
|
3247
|
+
keys,
|
|
3248
|
+
nodes,
|
|
3249
|
+
rects: nodes.map((node) => node.getBoundingClientRect()),
|
|
3250
|
+
from,
|
|
3251
|
+
to: from,
|
|
3252
|
+
start: horizontal ? event.clientX : event.clientY,
|
|
3253
|
+
clientX: event.clientX,
|
|
3254
|
+
clientY: event.clientY,
|
|
3255
|
+
scroll: horizontal ? root.scrollLeft : root.scrollTop,
|
|
3256
|
+
active: false
|
|
3257
|
+
};
|
|
3258
|
+
handle.setPointerCapture(event.pointerId);
|
|
3259
|
+
};
|
|
3260
|
+
const pointerMove = (event) => {
|
|
3261
|
+
const s = session;
|
|
3262
|
+
if (!s || settling || event.pointerId !== s.pointer) return;
|
|
3263
|
+
s.clientX = event.clientX;
|
|
3264
|
+
s.clientY = event.clientY;
|
|
3265
|
+
if (!s.active && Math.abs((horizontal ? event.clientX : event.clientY) - s.start) >= 4) {
|
|
3266
|
+
s.active = true;
|
|
3267
|
+
root.classList.add("is-sorting");
|
|
3268
|
+
s.nodes[s.from].classList.add("is-dragging");
|
|
3269
|
+
s.nodes.forEach((node, index) => {
|
|
3270
|
+
node.style.transition = index === s.from || reduced() ? "none" : "transform 180ms cubic-bezier(.2,.8,.2,1)";
|
|
3271
|
+
});
|
|
3272
|
+
lastTime = 0;
|
|
3273
|
+
frame = requestAnimationFrame(tick);
|
|
3274
|
+
}
|
|
3275
|
+
if (s.active) {
|
|
3276
|
+
event.preventDefault();
|
|
3277
|
+
paint();
|
|
3278
|
+
}
|
|
3279
|
+
};
|
|
3280
|
+
const pointerUp = (event) => {
|
|
3281
|
+
const s = session;
|
|
3282
|
+
if (!s || settling || event.pointerId !== s.pointer) return;
|
|
3283
|
+
const bounds = root.getBoundingClientRect();
|
|
3284
|
+
if (!s.active || event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) {
|
|
3285
|
+
clear();
|
|
3286
|
+
return;
|
|
3287
|
+
}
|
|
3288
|
+
s.clientX = event.clientX;
|
|
3289
|
+
s.clientY = event.clientY;
|
|
3290
|
+
paint();
|
|
3291
|
+
cancelAnimationFrame(frame);
|
|
3292
|
+
const finish = () => {
|
|
3293
|
+
if (session !== s) return;
|
|
3294
|
+
const next = [...s.keys];
|
|
3295
|
+
next.splice(s.from, 1);
|
|
3296
|
+
next.splice(s.to, 0, s.key);
|
|
3297
|
+
const changed = s.from !== s.to;
|
|
3298
|
+
clear();
|
|
3299
|
+
if (changed) latest.current.onOrderChange(next);
|
|
3300
|
+
};
|
|
3301
|
+
if (reduced()) {
|
|
3302
|
+
finish();
|
|
3303
|
+
return;
|
|
3304
|
+
}
|
|
3305
|
+
const node = s.nodes[s.from];
|
|
3306
|
+
settling = node.animate([{ transform: node.style.transform }, { transform: transform(displacement(s)[s.from]) }], { duration: 160, easing: "cubic-bezier(.2,.8,.2,1)", fill: "forwards" });
|
|
3307
|
+
settling.finished.then(finish, () => {
|
|
3308
|
+
});
|
|
3309
|
+
};
|
|
3310
|
+
const escape = (event) => {
|
|
3311
|
+
if (event.key === "Escape" && session) {
|
|
3312
|
+
event.preventDefault();
|
|
3313
|
+
event.stopPropagation();
|
|
3314
|
+
clear();
|
|
3315
|
+
}
|
|
3316
|
+
};
|
|
3317
|
+
const cancelPointer = (event) => {
|
|
3318
|
+
if (event.pointerId === session?.pointer && !settling) clear();
|
|
3319
|
+
};
|
|
3320
|
+
const cancelClick = (event) => {
|
|
3321
|
+
if (session?.active || settling) {
|
|
3322
|
+
event.preventDefault();
|
|
3323
|
+
event.stopPropagation();
|
|
3324
|
+
}
|
|
3325
|
+
};
|
|
3326
|
+
window.addEventListener("pointermove", pointerMove, { passive: false });
|
|
3327
|
+
window.addEventListener("pointerup", pointerUp);
|
|
3328
|
+
window.addEventListener("pointercancel", cancelPointer);
|
|
3329
|
+
window.addEventListener("keydown", escape, true);
|
|
3330
|
+
window.addEventListener("blur", clear);
|
|
3331
|
+
window.addEventListener("resize", clear);
|
|
3332
|
+
root.addEventListener("lostpointercapture", cancelPointer);
|
|
3333
|
+
root.addEventListener("click", cancelClick, true);
|
|
3334
|
+
return () => {
|
|
3335
|
+
clear();
|
|
3336
|
+
startRef.current = () => {
|
|
3337
|
+
};
|
|
3338
|
+
window.removeEventListener("pointermove", pointerMove);
|
|
3339
|
+
window.removeEventListener("pointerup", pointerUp);
|
|
3340
|
+
window.removeEventListener("pointercancel", cancelPointer);
|
|
3341
|
+
window.removeEventListener("keydown", escape, true);
|
|
3342
|
+
window.removeEventListener("blur", clear);
|
|
3343
|
+
window.removeEventListener("resize", clear);
|
|
3344
|
+
root.removeEventListener("lostpointercapture", cancelPointer);
|
|
3345
|
+
root.removeEventListener("click", cancelClick, true);
|
|
3346
|
+
};
|
|
3347
|
+
}, [disabled, direction, signature]);
|
|
3348
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { ref: rootRef, className: `sia-sortable-list sia-sortable-list--${direction}`, role: "list", children: [
|
|
3349
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { ref: placeholderRef, className: "sia-sortable-list__placeholder", "aria-hidden": "true", hidden: true }),
|
|
3350
|
+
items.map((key, index) => {
|
|
3351
|
+
const handle = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3352
|
+
"button",
|
|
3353
|
+
{
|
|
3354
|
+
type: "button",
|
|
3355
|
+
className: `sia-sortable-list__handle${handlePlacement === "custom" ? " sia-sortable-list__handle--custom" : ""}`,
|
|
3356
|
+
disabled,
|
|
3357
|
+
"aria-label": `\u8C03\u6574\u7B2C ${index + 1} \u9879\u987A\u5E8F`,
|
|
3358
|
+
title: "\u62D6\u52A8\u6392\u5E8F\uFF0C\u6216\u4F7F\u7528\u65B9\u5411\u952E\u79FB\u52A8",
|
|
3359
|
+
onPointerDown: (event) => startRef.current(event.nativeEvent, key, event.currentTarget),
|
|
3360
|
+
onDragStart: (event) => event.preventDefault(),
|
|
3361
|
+
onKeyDown: (event) => {
|
|
3362
|
+
if (rootRef.current?.classList.contains("is-sorting")) return;
|
|
3363
|
+
const previous = direction === "horizontal" ? "ArrowLeft" : "ArrowUp";
|
|
3364
|
+
const next = direction === "horizontal" ? "ArrowRight" : "ArrowDown";
|
|
3365
|
+
if (event.key !== previous && event.key !== next) return;
|
|
3366
|
+
event.preventDefault();
|
|
3367
|
+
const to = index + (event.key === previous ? -1 : 1);
|
|
3368
|
+
if (disabled || to < 0 || to >= items.length) return;
|
|
3369
|
+
const order = [...items];
|
|
3370
|
+
order.splice(index, 1);
|
|
3371
|
+
order.splice(to, 0, key);
|
|
3372
|
+
onOrderChange(order);
|
|
3373
|
+
},
|
|
3374
|
+
children: handleContent ? handleContent(key, index) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Icon, { name: "menu", size: 16 })
|
|
3375
|
+
}
|
|
3376
|
+
);
|
|
3377
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { role: "listitem", className: "sia-sortable-list__item", children: [
|
|
3378
|
+
handlePlacement === "before" ? handle : null,
|
|
3379
|
+
renderItem(key, index, handle)
|
|
3380
|
+
] }, key);
|
|
3381
|
+
})
|
|
3382
|
+
] });
|
|
3224
3383
|
}
|
|
3225
3384
|
|
|
3226
3385
|
// src/components/Toolbar.tsx
|
package/dist/index.css
CHANGED
|
@@ -5516,6 +5516,7 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5516
5516
|
margin-bottom: 8px;
|
|
5517
5517
|
}
|
|
5518
5518
|
.sia-sortable-list {
|
|
5519
|
+
position: relative;
|
|
5519
5520
|
display: flex;
|
|
5520
5521
|
gap: 16px;
|
|
5521
5522
|
overflow: auto;
|
|
@@ -5531,7 +5532,25 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5531
5532
|
min-width: 0;
|
|
5532
5533
|
}
|
|
5533
5534
|
.sia-sortable-list__item.is-dragging {
|
|
5534
|
-
|
|
5535
|
+
z-index: 2;
|
|
5536
|
+
filter: drop-shadow(0 6px 8px rgb(0 0 0 / 16%));
|
|
5537
|
+
}
|
|
5538
|
+
.sia-sortable-list__placeholder {
|
|
5539
|
+
position: absolute;
|
|
5540
|
+
box-sizing: border-box;
|
|
5541
|
+
border: 2px dashed var(--sia-color-primary);
|
|
5542
|
+
border-radius: var(--sia-radius-md, 6px);
|
|
5543
|
+
background: var(--sia-color-primary-light);
|
|
5544
|
+
pointer-events: none;
|
|
5545
|
+
}
|
|
5546
|
+
.sia-sortable-list.is-sorting {
|
|
5547
|
+
user-select: none;
|
|
5548
|
+
}
|
|
5549
|
+
.sia-sortable-list.is-sorting .sia-sortable-list__handle {
|
|
5550
|
+
cursor: grabbing;
|
|
5551
|
+
}
|
|
5552
|
+
.sia-sortable-list__handle {
|
|
5553
|
+
touch-action: none;
|
|
5535
5554
|
}
|
|
5536
5555
|
.sia-sortable-list__handle {
|
|
5537
5556
|
display: flex;
|
|
@@ -5560,38 +5579,6 @@ fieldset:disabled .sia-input-number__floating-placeholder {
|
|
|
5560
5579
|
background: transparent;
|
|
5561
5580
|
text-align: start;
|
|
5562
5581
|
}
|
|
5563
|
-
.sia-sortable-list__item.is-drop-before::before,
|
|
5564
|
-
.sia-sortable-list__item.is-drop-after::after {
|
|
5565
|
-
content: "";
|
|
5566
|
-
position: absolute;
|
|
5567
|
-
background: var(--sia-color-primary);
|
|
5568
|
-
pointer-events: none;
|
|
5569
|
-
z-index: 1;
|
|
5570
|
-
}
|
|
5571
|
-
.sia-sortable-list--horizontal .is-drop-before::before {
|
|
5572
|
-
top: 0;
|
|
5573
|
-
bottom: 0;
|
|
5574
|
-
left: -9px;
|
|
5575
|
-
width: 2px;
|
|
5576
|
-
}
|
|
5577
|
-
.sia-sortable-list--horizontal .is-drop-after::after {
|
|
5578
|
-
top: 0;
|
|
5579
|
-
bottom: 0;
|
|
5580
|
-
right: -9px;
|
|
5581
|
-
width: 2px;
|
|
5582
|
-
}
|
|
5583
|
-
.sia-sortable-list--vertical .is-drop-before::before {
|
|
5584
|
-
left: 0;
|
|
5585
|
-
right: 0;
|
|
5586
|
-
top: -9px;
|
|
5587
|
-
height: 2px;
|
|
5588
|
-
}
|
|
5589
|
-
.sia-sortable-list--vertical .is-drop-after::after {
|
|
5590
|
-
left: 0;
|
|
5591
|
-
right: 0;
|
|
5592
|
-
bottom: -9px;
|
|
5593
|
-
height: 2px;
|
|
5594
|
-
}
|
|
5595
5582
|
.sia-popover.sia-popover--wide {
|
|
5596
5583
|
width: 760px;
|
|
5597
5584
|
max-width: calc(100vw - 32px);
|
package/dist/index.d.cts
CHANGED
|
@@ -82,20 +82,20 @@ type SortableKey = string | number;
|
|
|
82
82
|
interface SortableListProps {
|
|
83
83
|
/** 按当前顺序排列的唯一稳定标识,不允许重复。 */
|
|
84
84
|
items: readonly SortableKey[];
|
|
85
|
-
/**
|
|
85
|
+
/** 根据标识和已提交索引渲染内容;第三个参数为框架手柄,custom 模式须放入标题等位置。拖动预览只移动原节点,不重挂载或提前改变索引,输入草稿保持。 */
|
|
86
86
|
renderItem: (key: SortableKey, index: number, handle: ReactNode) => ReactNode;
|
|
87
87
|
/** 手柄位置;before 在条目前独占一行,custom 由 renderItem 放置框架提供的手柄。@defaultValue "before" */
|
|
88
88
|
handlePlacement?: "before" | "custom";
|
|
89
89
|
/** 手柄的内容,接收稳定标识和当前位置;未指定时显示拖动图标,可返回卡片标题文字。 */
|
|
90
90
|
handleContent?: (key: SortableKey, index: number) => ReactNode;
|
|
91
|
-
/**
|
|
91
|
+
/** 指针在列表内松手并完成 160ms 吸附动画后,或手柄方向键移动后,返回一次新顺序,调用方须回填 items。减少动态效果时立即提交;预览、原位放下、Esc/列表外取消、禁用、外部顺序变化均不触发,不等待回调返回值。 */
|
|
92
92
|
onOrderChange: (items: SortableKey[]) => void;
|
|
93
|
-
/**
|
|
93
|
+
/** 排列及拖动轴;按轴移动至少 4px 开始预览,相邻项以 180ms 让位,靠近列表滚动边缘自动滚动。仅由手柄发起,不影响内部输入;减少动态效果时相邻项直接定位。@defaultValue "horizontal" */
|
|
94
94
|
direction?: "horizontal" | "vertical";
|
|
95
95
|
/** 禁止拖放和键盘排序,不禁用条目内部业务控件。@defaultValue false */
|
|
96
96
|
disabled?: boolean;
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
98
|
+
/** 拖放与键盘共用受控顺序;指针预览不重挂载内容,也不改变 renderItem 的业务索引。 */
|
|
99
99
|
declare function SortableList({ items, renderItem, onOrderChange, direction, disabled, handlePlacement, handleContent }: SortableListProps): react.JSX.Element;
|
|
100
100
|
|
|
101
101
|
/** 警告提示的状态类型。 */
|
package/dist/index.d.ts
CHANGED
|
@@ -82,20 +82,20 @@ type SortableKey = string | number;
|
|
|
82
82
|
interface SortableListProps {
|
|
83
83
|
/** 按当前顺序排列的唯一稳定标识,不允许重复。 */
|
|
84
84
|
items: readonly SortableKey[];
|
|
85
|
-
/**
|
|
85
|
+
/** 根据标识和已提交索引渲染内容;第三个参数为框架手柄,custom 模式须放入标题等位置。拖动预览只移动原节点,不重挂载或提前改变索引,输入草稿保持。 */
|
|
86
86
|
renderItem: (key: SortableKey, index: number, handle: ReactNode) => ReactNode;
|
|
87
87
|
/** 手柄位置;before 在条目前独占一行,custom 由 renderItem 放置框架提供的手柄。@defaultValue "before" */
|
|
88
88
|
handlePlacement?: "before" | "custom";
|
|
89
89
|
/** 手柄的内容,接收稳定标识和当前位置;未指定时显示拖动图标,可返回卡片标题文字。 */
|
|
90
90
|
handleContent?: (key: SortableKey, index: number) => ReactNode;
|
|
91
|
-
/**
|
|
91
|
+
/** 指针在列表内松手并完成 160ms 吸附动画后,或手柄方向键移动后,返回一次新顺序,调用方须回填 items。减少动态效果时立即提交;预览、原位放下、Esc/列表外取消、禁用、外部顺序变化均不触发,不等待回调返回值。 */
|
|
92
92
|
onOrderChange: (items: SortableKey[]) => void;
|
|
93
|
-
/**
|
|
93
|
+
/** 排列及拖动轴;按轴移动至少 4px 开始预览,相邻项以 180ms 让位,靠近列表滚动边缘自动滚动。仅由手柄发起,不影响内部输入;减少动态效果时相邻项直接定位。@defaultValue "horizontal" */
|
|
94
94
|
direction?: "horizontal" | "vertical";
|
|
95
95
|
/** 禁止拖放和键盘排序,不禁用条目内部业务控件。@defaultValue false */
|
|
96
96
|
disabled?: boolean;
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
98
|
+
/** 拖放与键盘共用受控顺序;指针预览不重挂载内容,也不改变 renderItem 的业务索引。 */
|
|
99
99
|
declare function SortableList({ items, renderItem, onOrderChange, direction, disabled, handlePlacement, handleContent }: SortableListProps): react.JSX.Element;
|
|
100
100
|
|
|
101
101
|
/** 警告提示的状态类型。 */
|
package/dist/index.js
CHANGED
|
@@ -310,84 +310,243 @@ function FloatingPanel({ open, title, children, placement = "bottomRight" }) {
|
|
|
310
310
|
] }), document.body);
|
|
311
311
|
}
|
|
312
312
|
function SortableList({ items, renderItem, onOrderChange, direction = "horizontal", disabled = false, handlePlacement = "before", handleContent }) {
|
|
313
|
-
const
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
};
|
|
319
|
-
const
|
|
320
|
-
const from = items.indexOf(key);
|
|
321
|
-
if (disabled || from < 0) return;
|
|
322
|
-
const to = Math.max(0, Math.min(items.length - 1, insertion > from ? insertion - 1 : insertion));
|
|
323
|
-
if (to === from) return;
|
|
324
|
-
const next = [...items];
|
|
325
|
-
next.splice(from, 1);
|
|
326
|
-
next.splice(to, 0, key);
|
|
327
|
-
onOrderChange(next);
|
|
328
|
-
};
|
|
313
|
+
const rootRef = useRef2(null);
|
|
314
|
+
const placeholderRef = useRef2(null);
|
|
315
|
+
const latest = useRef2({ items, onOrderChange });
|
|
316
|
+
latest.current = { items, onOrderChange };
|
|
317
|
+
const startRef = useRef2(() => {
|
|
318
|
+
});
|
|
319
|
+
const signature = JSON.stringify(items);
|
|
329
320
|
useEffect2(() => {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
321
|
+
const root = rootRef.current;
|
|
322
|
+
if (!root) return;
|
|
323
|
+
const horizontal = direction === "horizontal";
|
|
324
|
+
let session = null;
|
|
325
|
+
let frame = 0;
|
|
326
|
+
let settling = null;
|
|
327
|
+
const reduced = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
328
|
+
const clear = () => {
|
|
329
|
+
cancelAnimationFrame(frame);
|
|
330
|
+
settling?.cancel();
|
|
331
|
+
settling = null;
|
|
332
|
+
const previous = session;
|
|
333
|
+
session = null;
|
|
334
|
+
root.classList.remove("is-sorting");
|
|
335
|
+
previous?.nodes.forEach((node) => {
|
|
336
|
+
node.classList.remove("is-dragging");
|
|
337
|
+
node.style.removeProperty("transform");
|
|
338
|
+
node.style.removeProperty("transition");
|
|
339
|
+
});
|
|
340
|
+
if (placeholderRef.current) placeholderRef.current.hidden = true;
|
|
341
|
+
if (previous?.handle.hasPointerCapture(previous.pointer)) previous.handle.releasePointerCapture(previous.pointer);
|
|
342
|
+
};
|
|
343
|
+
const displacement = (s) => {
|
|
344
|
+
const start = (r) => horizontal ? r.left : r.top;
|
|
345
|
+
const length = (r) => horizontal ? r.width : r.height;
|
|
346
|
+
const indices = s.keys.map((_, index) => index);
|
|
347
|
+
indices.splice(s.from, 1);
|
|
348
|
+
indices.splice(s.to, 0, s.from);
|
|
349
|
+
const gap = Number.parseFloat(getComputedStyle(root).gap) || 0;
|
|
350
|
+
let cursor = start(s.rects[0]);
|
|
351
|
+
const offsets = s.rects.map(() => 0);
|
|
352
|
+
indices.forEach((index) => {
|
|
353
|
+
offsets[index] = cursor - start(s.rects[index]);
|
|
354
|
+
cursor += length(s.rects[index]) + gap;
|
|
355
|
+
});
|
|
356
|
+
return offsets;
|
|
357
|
+
};
|
|
358
|
+
const transform = (offset) => horizontal ? `translate3d(${offset}px, 0, 0)` : `translate3d(0, ${offset}px, 0)`;
|
|
359
|
+
const paint = () => {
|
|
360
|
+
const s = session;
|
|
361
|
+
if (!s || !s.active || settling) return;
|
|
362
|
+
const bounds = root.getBoundingClientRect();
|
|
363
|
+
const coordinate = horizontal ? s.clientX : s.clientY;
|
|
364
|
+
const scroll = horizontal ? root.scrollLeft : root.scrollTop;
|
|
365
|
+
const origin = s.rects[s.from];
|
|
366
|
+
const first = s.rects[0];
|
|
367
|
+
const last = s.rects[s.rects.length - 1];
|
|
368
|
+
const minimum = horizontal ? first.left - origin.left : first.top - origin.top;
|
|
369
|
+
const maximum = horizontal ? last.right - origin.right : last.bottom - origin.bottom;
|
|
370
|
+
const delta = Math.max(minimum, Math.min(maximum, coordinate - s.start + scroll - s.scroll));
|
|
371
|
+
const center = (horizontal ? origin.left + origin.width / 2 : origin.top + origin.height / 2) + delta;
|
|
372
|
+
s.to = s.rects.filter((rect, index) => index !== s.from && center > (horizontal ? rect.left + rect.width / 2 : rect.top + rect.height / 2)).length;
|
|
373
|
+
const offsets = displacement(s);
|
|
374
|
+
s.nodes.forEach((node, index) => {
|
|
375
|
+
node.style.transform = transform(index === s.from ? delta : offsets[index]);
|
|
376
|
+
});
|
|
377
|
+
const preview = placeholderRef.current;
|
|
378
|
+
if (preview) {
|
|
379
|
+
preview.hidden = false;
|
|
380
|
+
preview.style.width = `${origin.width}px`;
|
|
381
|
+
preview.style.height = `${origin.height}px`;
|
|
382
|
+
preview.style.left = `${origin.left - bounds.left + root.scrollLeft - (horizontal ? scroll - s.scroll : 0) + (horizontal ? offsets[s.from] : 0)}px`;
|
|
383
|
+
preview.style.top = `${origin.top - bounds.top + root.scrollTop - (!horizontal ? scroll - s.scroll : 0) + (!horizontal ? offsets[s.from] : 0)}px`;
|
|
363
384
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
385
|
+
};
|
|
386
|
+
let lastTime = 0;
|
|
387
|
+
const tick = (time) => {
|
|
388
|
+
const s = session;
|
|
389
|
+
if (!s || !s.active || settling) return;
|
|
390
|
+
const bounds = root.getBoundingClientRect();
|
|
391
|
+
const point = horizontal ? s.clientX : s.clientY;
|
|
392
|
+
const start = horizontal ? bounds.left : bounds.top;
|
|
393
|
+
const end = horizontal ? bounds.right : bounds.bottom;
|
|
394
|
+
const crossInside = horizontal ? s.clientY >= bounds.top && s.clientY <= bounds.bottom : s.clientX >= bounds.left && s.clientX <= bounds.right;
|
|
395
|
+
const edge = 44;
|
|
396
|
+
const speed = !crossInside || point < start || point > end ? 0 : point < start + edge ? -Math.min(1, (start + edge - point) / edge) : point > end - edge ? Math.min(1, (point - end + edge) / edge) : 0;
|
|
397
|
+
const distance = speed * Math.min(32, time - (lastTime || time)) * 0.65;
|
|
398
|
+
lastTime = time;
|
|
399
|
+
if (horizontal) root.scrollLeft += distance;
|
|
400
|
+
else root.scrollTop += distance;
|
|
401
|
+
paint();
|
|
402
|
+
frame = requestAnimationFrame(tick);
|
|
403
|
+
};
|
|
404
|
+
startRef.current = (event, key, handle) => {
|
|
405
|
+
if (disabled || event.button !== 0 || !event.isPrimary || session || settling) return;
|
|
406
|
+
const keys = [...latest.current.items];
|
|
407
|
+
const from = keys.indexOf(key);
|
|
408
|
+
if (from < 0) return;
|
|
409
|
+
const nodes = Array.from(root.children).filter((node) => node.getAttribute("role") === "listitem");
|
|
410
|
+
session = {
|
|
411
|
+
key,
|
|
412
|
+
pointer: event.pointerId,
|
|
413
|
+
handle,
|
|
414
|
+
keys,
|
|
415
|
+
nodes,
|
|
416
|
+
rects: nodes.map((node) => node.getBoundingClientRect()),
|
|
417
|
+
from,
|
|
418
|
+
to: from,
|
|
419
|
+
start: horizontal ? event.clientX : event.clientY,
|
|
420
|
+
clientX: event.clientX,
|
|
421
|
+
clientY: event.clientY,
|
|
422
|
+
scroll: horizontal ? root.scrollLeft : root.scrollTop,
|
|
423
|
+
active: false
|
|
424
|
+
};
|
|
425
|
+
handle.setPointerCapture(event.pointerId);
|
|
426
|
+
};
|
|
427
|
+
const pointerMove = (event) => {
|
|
428
|
+
const s = session;
|
|
429
|
+
if (!s || settling || event.pointerId !== s.pointer) return;
|
|
430
|
+
s.clientX = event.clientX;
|
|
431
|
+
s.clientY = event.clientY;
|
|
432
|
+
if (!s.active && Math.abs((horizontal ? event.clientX : event.clientY) - s.start) >= 4) {
|
|
433
|
+
s.active = true;
|
|
434
|
+
root.classList.add("is-sorting");
|
|
435
|
+
s.nodes[s.from].classList.add("is-dragging");
|
|
436
|
+
s.nodes.forEach((node, index) => {
|
|
437
|
+
node.style.transition = index === s.from || reduced() ? "none" : "transform 180ms cubic-bezier(.2,.8,.2,1)";
|
|
438
|
+
});
|
|
439
|
+
lastTime = 0;
|
|
440
|
+
frame = requestAnimationFrame(tick);
|
|
441
|
+
}
|
|
442
|
+
if (s.active) {
|
|
443
|
+
event.preventDefault();
|
|
444
|
+
paint();
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
const pointerUp = (event) => {
|
|
448
|
+
const s = session;
|
|
449
|
+
if (!s || settling || event.pointerId !== s.pointer) return;
|
|
450
|
+
const bounds = root.getBoundingClientRect();
|
|
451
|
+
if (!s.active || event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) {
|
|
452
|
+
clear();
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
s.clientX = event.clientX;
|
|
456
|
+
s.clientY = event.clientY;
|
|
457
|
+
paint();
|
|
458
|
+
cancelAnimationFrame(frame);
|
|
459
|
+
const finish = () => {
|
|
460
|
+
if (session !== s) return;
|
|
461
|
+
const next = [...s.keys];
|
|
462
|
+
next.splice(s.from, 1);
|
|
463
|
+
next.splice(s.to, 0, s.key);
|
|
464
|
+
const changed = s.from !== s.to;
|
|
465
|
+
clear();
|
|
466
|
+
if (changed) latest.current.onOrderChange(next);
|
|
467
|
+
};
|
|
468
|
+
if (reduced()) {
|
|
469
|
+
finish();
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
const node = s.nodes[s.from];
|
|
473
|
+
settling = node.animate([{ transform: node.style.transform }, { transform: transform(displacement(s)[s.from]) }], { duration: 160, easing: "cubic-bezier(.2,.8,.2,1)", fill: "forwards" });
|
|
474
|
+
settling.finished.then(finish, () => {
|
|
475
|
+
});
|
|
476
|
+
};
|
|
477
|
+
const escape = (event) => {
|
|
478
|
+
if (event.key === "Escape" && session) {
|
|
479
|
+
event.preventDefault();
|
|
480
|
+
event.stopPropagation();
|
|
481
|
+
clear();
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
const cancelPointer = (event) => {
|
|
485
|
+
if (event.pointerId === session?.pointer && !settling) clear();
|
|
486
|
+
};
|
|
487
|
+
const cancelClick = (event) => {
|
|
488
|
+
if (session?.active || settling) {
|
|
489
|
+
event.preventDefault();
|
|
490
|
+
event.stopPropagation();
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
window.addEventListener("pointermove", pointerMove, { passive: false });
|
|
494
|
+
window.addEventListener("pointerup", pointerUp);
|
|
495
|
+
window.addEventListener("pointercancel", cancelPointer);
|
|
496
|
+
window.addEventListener("keydown", escape, true);
|
|
497
|
+
window.addEventListener("blur", clear);
|
|
498
|
+
window.addEventListener("resize", clear);
|
|
499
|
+
root.addEventListener("lostpointercapture", cancelPointer);
|
|
500
|
+
root.addEventListener("click", cancelClick, true);
|
|
501
|
+
return () => {
|
|
502
|
+
clear();
|
|
503
|
+
startRef.current = () => {
|
|
504
|
+
};
|
|
505
|
+
window.removeEventListener("pointermove", pointerMove);
|
|
506
|
+
window.removeEventListener("pointerup", pointerUp);
|
|
507
|
+
window.removeEventListener("pointercancel", cancelPointer);
|
|
508
|
+
window.removeEventListener("keydown", escape, true);
|
|
509
|
+
window.removeEventListener("blur", clear);
|
|
510
|
+
window.removeEventListener("resize", clear);
|
|
511
|
+
root.removeEventListener("lostpointercapture", cancelPointer);
|
|
512
|
+
root.removeEventListener("click", cancelClick, true);
|
|
513
|
+
};
|
|
514
|
+
}, [disabled, direction, signature]);
|
|
515
|
+
return /* @__PURE__ */ jsxs2("div", { ref: rootRef, className: `sia-sortable-list sia-sortable-list--${direction}`, role: "list", children: [
|
|
516
|
+
/* @__PURE__ */ jsx2("div", { ref: placeholderRef, className: "sia-sortable-list__placeholder", "aria-hidden": "true", hidden: true }),
|
|
517
|
+
items.map((key, index) => {
|
|
518
|
+
const handle = /* @__PURE__ */ jsx2(
|
|
519
|
+
"button",
|
|
520
|
+
{
|
|
521
|
+
type: "button",
|
|
522
|
+
className: `sia-sortable-list__handle${handlePlacement === "custom" ? " sia-sortable-list__handle--custom" : ""}`,
|
|
523
|
+
disabled,
|
|
524
|
+
"aria-label": `\u8C03\u6574\u7B2C ${index + 1} \u9879\u987A\u5E8F`,
|
|
525
|
+
title: "\u62D6\u52A8\u6392\u5E8F\uFF0C\u6216\u4F7F\u7528\u65B9\u5411\u952E\u79FB\u52A8",
|
|
526
|
+
onPointerDown: (event) => startRef.current(event.nativeEvent, key, event.currentTarget),
|
|
527
|
+
onDragStart: (event) => event.preventDefault(),
|
|
528
|
+
onKeyDown: (event) => {
|
|
529
|
+
if (rootRef.current?.classList.contains("is-sorting")) return;
|
|
530
|
+
const previous = direction === "horizontal" ? "ArrowLeft" : "ArrowUp";
|
|
531
|
+
const next = direction === "horizontal" ? "ArrowRight" : "ArrowDown";
|
|
532
|
+
if (event.key !== previous && event.key !== next) return;
|
|
533
|
+
event.preventDefault();
|
|
534
|
+
const to = index + (event.key === previous ? -1 : 1);
|
|
535
|
+
if (disabled || to < 0 || to >= items.length) return;
|
|
536
|
+
const order = [...items];
|
|
537
|
+
order.splice(index, 1);
|
|
538
|
+
order.splice(to, 0, key);
|
|
539
|
+
onOrderChange(order);
|
|
540
|
+
},
|
|
541
|
+
children: handleContent ? handleContent(key, index) : /* @__PURE__ */ jsx2(Icon, { name: "menu", size: 16 })
|
|
542
|
+
}
|
|
543
|
+
);
|
|
544
|
+
return /* @__PURE__ */ jsxs2("div", { role: "listitem", className: "sia-sortable-list__item", children: [
|
|
545
|
+
handlePlacement === "before" ? handle : null,
|
|
546
|
+
renderItem(key, index, handle)
|
|
547
|
+
] }, key);
|
|
548
|
+
})
|
|
549
|
+
] });
|
|
391
550
|
}
|
|
392
551
|
|
|
393
552
|
// src/components/Alert.tsx
|