@hussmartinez/ui 0.11.0 → 0.12.0
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/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +151 -3
- package/dist/react.js +557 -100
- package/dist/react.js.map +1 -1
- package/dist/styles.css +161 -0
- package/dist/ui.d.ts +151 -3
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -9,7 +9,7 @@ var REGISTRY = /* @__PURE__ */ Symbol.for("@hussmartinez/ui");
|
|
|
9
9
|
var THIS_COPY = {};
|
|
10
10
|
var checked = false;
|
|
11
11
|
function ownVersion() {
|
|
12
|
-
return "0.
|
|
12
|
+
return "0.12.0";
|
|
13
13
|
}
|
|
14
14
|
function checkSingleCopy() {
|
|
15
15
|
if (checked || !(typeof process !== "undefined" && process.env.NODE_ENV !== "production")) return;
|
|
@@ -1283,10 +1283,25 @@ var TextField = /* @__PURE__ */ forwardRef(function TextField({ type = "text", o
|
|
|
1283
1283
|
onChange: handleChange
|
|
1284
1284
|
});
|
|
1285
1285
|
});
|
|
1286
|
+
// src/components/timeline/set-style.ts
|
|
1287
|
+
var written = /* @__PURE__ */ new WeakMap();
|
|
1288
|
+
function setStyle(element, property, value) {
|
|
1289
|
+
let last = written.get(element);
|
|
1290
|
+
if (!last) {
|
|
1291
|
+
last = /* @__PURE__ */ new Map();
|
|
1292
|
+
written.set(element, last);
|
|
1293
|
+
}
|
|
1294
|
+
if ((last.get(property) ?? "") === value) return;
|
|
1295
|
+
last.set(property, value);
|
|
1296
|
+
if (value === "") element.style.removeProperty(property);
|
|
1297
|
+
else element.style.setProperty(property, value);
|
|
1298
|
+
}
|
|
1286
1299
|
// src/components/timeline/Timeline.tsx
|
|
1287
1300
|
var SNAP_PIXELS = 8;
|
|
1288
1301
|
var MAX_TRACK_PIXELS = 8e6;
|
|
1302
|
+
var TimelineLaneContext = /* @__PURE__ */ createContext(void 0);
|
|
1289
1303
|
var TimelineContext = /* @__PURE__ */ createContext(void 0);
|
|
1304
|
+
var HEADERS_BESIDE = 720;
|
|
1290
1305
|
function useTimelineContext(part) {
|
|
1291
1306
|
checkSingleCopy();
|
|
1292
1307
|
const context = useContext(TimelineContext);
|
|
@@ -1297,6 +1312,7 @@ function useTimelineContext(part) {
|
|
|
1297
1312
|
}
|
|
1298
1313
|
var NO_SCALE = {
|
|
1299
1314
|
length: 0,
|
|
1315
|
+
extent: 0,
|
|
1300
1316
|
pixelsPerUnit: 0,
|
|
1301
1317
|
toPixels: () => 0,
|
|
1302
1318
|
unitAt: () => 0,
|
|
@@ -1310,30 +1326,62 @@ function useTimelineScale() {
|
|
|
1310
1326
|
return useTimelineContext("useTimelineScale")?.scale ?? NO_SCALE;
|
|
1311
1327
|
}
|
|
1312
1328
|
var isRtl = (element) => getComputedStyle(element).direction === "rtl";
|
|
1313
|
-
var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: rawLength, zoom = 1, maxPixelsPerUnit = 48, onMaxZoomChange, snapping = true, snapTargets, onVisibleRangeChange, className, classNames, unstyled, children, ...props }, ref) {
|
|
1329
|
+
var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: rawLength, extent: rawExtent, zoom = 1, maxPixelsPerUnit = 48, onMaxZoomChange, snapping = true, snapTargets, onVisibleRangeChange, className, classNames, unstyled, children, ...props }, ref) {
|
|
1314
1330
|
const length = Number.isSafeInteger(rawLength) && rawLength > 0 ? rawLength : 0;
|
|
1331
|
+
const extent = rawExtent !== void 0 && Number.isSafeInteger(rawExtent) ? Math.max(rawExtent, length) : length;
|
|
1315
1332
|
const viewport = useRef(null);
|
|
1316
1333
|
const track = useRef(null);
|
|
1317
1334
|
const [room, setRoom] = useState(0);
|
|
1318
1335
|
const lead = useRef(0);
|
|
1319
1336
|
const targets = useRef(/* @__PURE__ */ new Set());
|
|
1337
|
+
const laneParts = useRef(/* @__PURE__ */ new Map());
|
|
1338
|
+
const laneClips = useRef(/* @__PURE__ */ new Map());
|
|
1339
|
+
const [lanes, setLanes] = useState([]);
|
|
1340
|
+
const [headerWidth, setHeaderWidth] = useState(0);
|
|
1341
|
+
const [trail, setTrail] = useState(0);
|
|
1342
|
+
const [beside, setBeside] = useState(true);
|
|
1320
1343
|
const measure = (element) => {
|
|
1344
|
+
if (laneParts.current.size > 0 || order.current.length > 0) measureLanes(element);
|
|
1321
1345
|
const style = getComputedStyle(element);
|
|
1322
1346
|
const padding = Number.parseFloat(style.paddingLeft) + Number.parseFloat(style.paddingRight);
|
|
1323
1347
|
lead.current = Number.parseFloat(style.paddingInlineStart) || 0;
|
|
1324
1348
|
setRoom(Math.max(0, element.clientWidth - padding));
|
|
1325
1349
|
};
|
|
1350
|
+
const measureLanes = (element) => {
|
|
1351
|
+
const order = [...laneParts.current.entries()].sort(([, a], [, b]) => a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
1352
|
+
const ids = order.map(([id]) => id);
|
|
1353
|
+
setLanes((current) => current.length === ids.length && current.every((id, index) => id === ids[index]) ? current : ids);
|
|
1354
|
+
const wide = element.offsetWidth >= HEADERS_BESIDE;
|
|
1355
|
+
setBeside(wide);
|
|
1356
|
+
const widest = Math.max(0, ...order.map(([, lane]) => lane.toolbar?.offsetWidth ?? 0));
|
|
1357
|
+
const column = wide ? Math.ceil(widest) : 0;
|
|
1358
|
+
setHeaderWidth(column);
|
|
1359
|
+
const after = Number.parseFloat(getComputedStyle(element).paddingInlineEnd) || 0;
|
|
1360
|
+
setTrail(after);
|
|
1361
|
+
setStyle(element, "padding-inline-start", column > 0 ? `${column + after}px` : "");
|
|
1362
|
+
};
|
|
1326
1363
|
const remeasure = useRef(measure);
|
|
1327
1364
|
remeasure.current = measure;
|
|
1365
|
+
const resized = useRef(null);
|
|
1328
1366
|
useEffect(() => {
|
|
1329
1367
|
const element = viewport.current;
|
|
1330
1368
|
if (!element) return;
|
|
1331
|
-
|
|
1369
|
+
let frame = 0;
|
|
1370
|
+
const observer = new ResizeObserver(() => {
|
|
1371
|
+
cancelAnimationFrame(frame);
|
|
1372
|
+
frame = requestAnimationFrame(() => remeasure.current(element));
|
|
1373
|
+
});
|
|
1332
1374
|
observer.observe(element);
|
|
1333
|
-
|
|
1375
|
+
resized.current = observer;
|
|
1376
|
+
for (const lane of laneParts.current.values()) if (lane.toolbar) observer.observe(lane.toolbar);
|
|
1377
|
+
return () => {
|
|
1378
|
+
resized.current = null;
|
|
1379
|
+
cancelAnimationFrame(frame);
|
|
1380
|
+
observer.disconnect();
|
|
1381
|
+
};
|
|
1334
1382
|
}, []);
|
|
1335
|
-
const fit =
|
|
1336
|
-
const closest = Math.max(fit, Math.min(maxPixelsPerUnit, MAX_TRACK_PIXELS / Math.max(
|
|
1383
|
+
const fit = extent > 0 && room > 0 ? room / extent : 0;
|
|
1384
|
+
const closest = Math.max(fit, Math.min(maxPixelsPerUnit, MAX_TRACK_PIXELS / Math.max(extent, 1)));
|
|
1337
1385
|
const pixelsPerUnit = Math.min(Math.max(fit * zoom, fit), closest);
|
|
1338
1386
|
const maxZoom = fit > 0 ? closest / fit : 1;
|
|
1339
1387
|
const notifyMaxZoom = useRef(onMaxZoomChange);
|
|
@@ -1342,8 +1390,10 @@ var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: raw
|
|
|
1342
1390
|
if (fit > 0) notifyMaxZoom.current?.(maxZoom);
|
|
1343
1391
|
}, [fit, maxZoom]);
|
|
1344
1392
|
const sizeTrack = (element) => {
|
|
1345
|
-
element
|
|
1393
|
+
setStyle(element, "inline-size", pixelsPerUnit > 0 ? `${extent * pixelsPerUnit}px` : "");
|
|
1346
1394
|
};
|
|
1395
|
+
const headerColumn = useRef(headerWidth);
|
|
1396
|
+
headerColumn.current = headerWidth;
|
|
1347
1397
|
const settings = useRef({
|
|
1348
1398
|
snapping,
|
|
1349
1399
|
snapTargets
|
|
@@ -1352,16 +1402,19 @@ var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: raw
|
|
|
1352
1402
|
snapping,
|
|
1353
1403
|
snapTargets
|
|
1354
1404
|
};
|
|
1405
|
+
const snapExceptRef = useRef((unit) => unit);
|
|
1355
1406
|
const scale = useMemo(() => {
|
|
1356
|
-
const snap$2 = (unit) => {
|
|
1407
|
+
const snap$2 = (unit, except = []) => {
|
|
1357
1408
|
if (!settings.current.snapping || pixelsPerUnit <= 0) return unit;
|
|
1358
1409
|
const all = [...settings.current.snapTargets ?? []];
|
|
1359
1410
|
for (const read of targets.current) all.push(...read());
|
|
1360
|
-
const valid = all.filter((target) => Number.isSafeInteger(target) && target >= 0);
|
|
1411
|
+
const valid = all.filter((target) => Number.isSafeInteger(target) && target >= 0 && !except.includes(target));
|
|
1361
1412
|
return snap(unit, valid, Math.round(SNAP_PIXELS / pixelsPerUnit));
|
|
1362
1413
|
};
|
|
1414
|
+
snapExceptRef.current = snap$2;
|
|
1363
1415
|
return {
|
|
1364
1416
|
length,
|
|
1417
|
+
extent,
|
|
1365
1418
|
pixelsPerUnit,
|
|
1366
1419
|
toPixels: (unit) => unit * pixelsPerUnit,
|
|
1367
1420
|
unitAt: (clientX, options) => {
|
|
@@ -1369,24 +1422,30 @@ var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: raw
|
|
|
1369
1422
|
if (!element || pixelsPerUnit <= 0) return 0;
|
|
1370
1423
|
const box = element.getBoundingClientRect();
|
|
1371
1424
|
const offset = isRtl(element) ? box.right - clientX : clientX - box.left;
|
|
1372
|
-
const unit = Math.min(Math.max(Math.round(offset / pixelsPerUnit), 0),
|
|
1373
|
-
return options?.snap ? Math.min(snap$2(unit),
|
|
1425
|
+
const unit = Math.min(Math.max(Math.round(offset / pixelsPerUnit), 0), extent);
|
|
1426
|
+
return options?.snap ? Math.min(snap$2(unit), extent) : unit;
|
|
1374
1427
|
},
|
|
1375
|
-
snap: snap$2,
|
|
1428
|
+
snap: (unit) => snap$2(unit),
|
|
1376
1429
|
visibleRange: () => {
|
|
1377
1430
|
const element = viewport.current;
|
|
1378
1431
|
if (!element || pixelsPerUnit <= 0) return {
|
|
1379
1432
|
start: 0,
|
|
1380
|
-
end:
|
|
1433
|
+
end: extent
|
|
1381
1434
|
};
|
|
1382
|
-
const
|
|
1435
|
+
const scrolled = Math.abs(element.scrollLeft) - lead.current;
|
|
1436
|
+
const start = (scrolled + headerColumn.current) / pixelsPerUnit;
|
|
1437
|
+
const end = (scrolled + element.clientWidth) / pixelsPerUnit;
|
|
1383
1438
|
return {
|
|
1384
|
-
start: Math.min(Math.max(Math.floor(start), 0),
|
|
1385
|
-
end: Math.min(Math.max(Math.ceil(
|
|
1439
|
+
start: Math.min(Math.max(Math.floor(start), 0), extent),
|
|
1440
|
+
end: Math.min(Math.max(Math.ceil(end), 0), extent)
|
|
1386
1441
|
};
|
|
1387
1442
|
}
|
|
1388
1443
|
};
|
|
1389
|
-
}, [
|
|
1444
|
+
}, [
|
|
1445
|
+
length,
|
|
1446
|
+
extent,
|
|
1447
|
+
pixelsPerUnit
|
|
1448
|
+
]);
|
|
1390
1449
|
const addTargets = useCallback((read) => {
|
|
1391
1450
|
targets.current.add(read);
|
|
1392
1451
|
return () => {
|
|
@@ -1405,18 +1464,69 @@ var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: raw
|
|
|
1405
1464
|
}
|
|
1406
1465
|
}, [scale]);
|
|
1407
1466
|
useEffect(reportRange, [reportRange, room]);
|
|
1467
|
+
const setLane = useCallback((id, lane) => {
|
|
1468
|
+
const before = laneParts.current.get(id);
|
|
1469
|
+
if (lane) {
|
|
1470
|
+
if (before?.element === lane.element && before.toolbar === lane.toolbar) return;
|
|
1471
|
+
laneParts.current.set(id, lane);
|
|
1472
|
+
if (lane.toolbar) resized.current?.observe(lane.toolbar);
|
|
1473
|
+
} else if (before) {
|
|
1474
|
+
laneParts.current.delete(id);
|
|
1475
|
+
if (before.toolbar) resized.current?.unobserve(before.toolbar);
|
|
1476
|
+
}
|
|
1477
|
+
if (viewport.current) remeasure.current(viewport.current);
|
|
1478
|
+
}, []);
|
|
1479
|
+
const setLaneClips = useCallback((id, clips) => {
|
|
1480
|
+
if (clips) laneClips.current.set(id, clips);
|
|
1481
|
+
else laneClips.current.delete(id);
|
|
1482
|
+
}, []);
|
|
1483
|
+
const order = useRef(lanes);
|
|
1484
|
+
order.current = lanes;
|
|
1485
|
+
const nextLaneClips = useCallback((id, direction) => {
|
|
1486
|
+
const ids = order.current;
|
|
1487
|
+
for (let at = ids.indexOf(id) + direction; at >= 0 && at < ids.length; at += direction) {
|
|
1488
|
+
const clips = laneClips.current.get(ids[at]);
|
|
1489
|
+
if (clips?.any()) return clips;
|
|
1490
|
+
}
|
|
1491
|
+
}, []);
|
|
1492
|
+
const focusOnAnotherLane = useCallback((from, key) => {
|
|
1493
|
+
for (const [id, clips] of laneClips.current) if (id !== from && clips.focus(key)) return true;
|
|
1494
|
+
return false;
|
|
1495
|
+
}, []);
|
|
1496
|
+
const snapExcept = useCallback((unit, except) => snapExceptRef.current(unit, except), []);
|
|
1408
1497
|
const context = useMemo(() => ({
|
|
1409
1498
|
scale,
|
|
1410
1499
|
viewport,
|
|
1411
1500
|
track,
|
|
1412
|
-
addTargets
|
|
1413
|
-
|
|
1501
|
+
addTargets,
|
|
1502
|
+
lanes,
|
|
1503
|
+
headerWidth,
|
|
1504
|
+
trail,
|
|
1505
|
+
setLane,
|
|
1506
|
+
setLaneClips,
|
|
1507
|
+
nextLaneClips,
|
|
1508
|
+
focusOnAnotherLane,
|
|
1509
|
+
snapExcept
|
|
1510
|
+
}), [
|
|
1511
|
+
scale,
|
|
1512
|
+
addTargets,
|
|
1513
|
+
lanes,
|
|
1514
|
+
headerWidth,
|
|
1515
|
+
trail,
|
|
1516
|
+
setLane,
|
|
1517
|
+
setLaneClips,
|
|
1518
|
+
nextLaneClips,
|
|
1519
|
+
focusOnAnotherLane,
|
|
1520
|
+
snapExcept
|
|
1521
|
+
]);
|
|
1522
|
+
const laned = lanes.length > 0;
|
|
1414
1523
|
return /* @__PURE__ */ jsx("section", {
|
|
1415
1524
|
...props,
|
|
1416
1525
|
ref,
|
|
1417
1526
|
"aria-label": label,
|
|
1418
1527
|
className: cx("hm-timeline", classNames?.root, className),
|
|
1419
1528
|
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1529
|
+
"data-hm-lanes": laned ? beside ? "beside" : "above" : void 0,
|
|
1420
1530
|
children: /* @__PURE__ */ jsx("div", {
|
|
1421
1531
|
ref: (node) => {
|
|
1422
1532
|
viewport.current = node;
|
|
@@ -1424,30 +1534,75 @@ var Timeline = /* @__PURE__ */ forwardRef(function Timeline({ label, length: raw
|
|
|
1424
1534
|
},
|
|
1425
1535
|
className: cx("hm-timeline-viewport", classNames?.viewport),
|
|
1426
1536
|
onScroll: reportRange,
|
|
1427
|
-
children: /* @__PURE__ */
|
|
1537
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1428
1538
|
ref: (node) => {
|
|
1429
1539
|
track.current = node;
|
|
1430
1540
|
if (node) sizeTrack(node);
|
|
1431
1541
|
},
|
|
1432
1542
|
className: cx("hm-timeline-track", classNames?.track),
|
|
1433
|
-
children:
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1543
|
+
children: [
|
|
1544
|
+
laned ? /* @__PURE__ */ jsx("div", {
|
|
1545
|
+
className: "hm-timeline-bar",
|
|
1546
|
+
"aria-hidden": "true",
|
|
1547
|
+
ref: (node) => {
|
|
1548
|
+
if (node) setStyle(node, "margin-inline-start", headerWidth > 0 ? `${-(headerWidth + trail)}px` : "");
|
|
1549
|
+
}
|
|
1550
|
+
}) : null,
|
|
1551
|
+
laned && headerWidth > 0 ? /* @__PURE__ */ jsx("div", {
|
|
1552
|
+
className: "hm-timeline-corner",
|
|
1553
|
+
"aria-hidden": "true",
|
|
1554
|
+
ref: (node) => {
|
|
1555
|
+
if (node) {
|
|
1556
|
+
setStyle(node, "margin-inline-start", `${-(headerWidth + trail)}px`);
|
|
1557
|
+
const cover = node.firstElementChild;
|
|
1558
|
+
setStyle(cover, "inline-size", `${headerWidth}px`);
|
|
1559
|
+
setStyle(cover, "inset-inline-start", `${-(headerWidth + trail)}px`);
|
|
1560
|
+
}
|
|
1561
|
+
},
|
|
1562
|
+
children: /* @__PURE__ */ jsx("div", { className: "hm-timeline-corner-cover" })
|
|
1563
|
+
}) : null,
|
|
1564
|
+
/* @__PURE__ */ jsx(TimelineContext.Provider, {
|
|
1565
|
+
value: context,
|
|
1566
|
+
children
|
|
1567
|
+
})
|
|
1568
|
+
]
|
|
1437
1569
|
})
|
|
1438
1570
|
})
|
|
1439
1571
|
});
|
|
1440
1572
|
});
|
|
1441
1573
|
var TimelineLayer = /* @__PURE__ */ forwardRef(function TimelineLayer({ className, children, ...props }, ref) {
|
|
1574
|
+
const lanes = useContext(TimelineContext)?.lanes.length ?? 0;
|
|
1575
|
+
const rows = useContext(TimelineLaneContext) !== void 0 ? 0 : lanes;
|
|
1442
1576
|
return /* @__PURE__ */ jsx("div", {
|
|
1443
1577
|
...props,
|
|
1444
|
-
ref
|
|
1578
|
+
ref: (node) => {
|
|
1579
|
+
if (node) setStyle(node, "grid-row", rows > 0 ? `2 / span ${rows}` : "");
|
|
1580
|
+
if (typeof ref === "function") ref(node);
|
|
1581
|
+
else if (ref) ref.current = node;
|
|
1582
|
+
},
|
|
1445
1583
|
className: cx("hm-timeline-layer", className),
|
|
1446
1584
|
children
|
|
1447
1585
|
});
|
|
1448
1586
|
});
|
|
1587
|
+
function useTimelineLanes() {
|
|
1588
|
+
const context = useTimelineContext("useTimelineLanes");
|
|
1589
|
+
const lanes = context?.lanes;
|
|
1590
|
+
const track = context?.track;
|
|
1591
|
+
return useMemo(() => ({
|
|
1592
|
+
lanes: lanes ?? [],
|
|
1593
|
+
laneAt: (clientY) => {
|
|
1594
|
+
for (const element of track?.current?.querySelectorAll(":scope > [data-hm-lane]") ?? []) {
|
|
1595
|
+
const box = element.getBoundingClientRect();
|
|
1596
|
+
if (clientY >= box.top && clientY < box.bottom) return element.dataset["hmLane"];
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}), [lanes, track]);
|
|
1600
|
+
}
|
|
1449
1601
|
// src/components/timeline/TimelineClips.tsx
|
|
1450
|
-
var
|
|
1602
|
+
var DRAG_AFTER = 4;
|
|
1603
|
+
var EDGE = 32;
|
|
1604
|
+
var SCROLL = 12;
|
|
1605
|
+
var Clip = /* @__PURE__ */ memo(function Clip({ clip, selected, tabStop, clipClass, contentClass, edges, dragging, pastEnd, moving }) {
|
|
1451
1606
|
return /* @__PURE__ */ jsxs("div", {
|
|
1452
1607
|
...clip.attributes,
|
|
1453
1608
|
role: "option",
|
|
@@ -1456,6 +1611,8 @@ var Clip = /* @__PURE__ */ memo(function Clip({ clip, selected, tabStop, clipCla
|
|
|
1456
1611
|
tabIndex: tabStop ? 0 : -1,
|
|
1457
1612
|
"data-hm-key": clip.key,
|
|
1458
1613
|
"data-hm-dragging": dragging,
|
|
1614
|
+
"data-hm-past-end": pastEnd ? "" : void 0,
|
|
1615
|
+
"data-hm-moving": moving,
|
|
1459
1616
|
className: clipClass,
|
|
1460
1617
|
children: [clip.content == null ? null : /* @__PURE__ */ jsx("span", {
|
|
1461
1618
|
className: contentClass,
|
|
@@ -1471,9 +1628,10 @@ var Clip = /* @__PURE__ */ memo(function Clip({ clip, selected, tabStop, clipCla
|
|
|
1471
1628
|
})] }) : null]
|
|
1472
1629
|
});
|
|
1473
1630
|
});
|
|
1474
|
-
var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, clips: given, selectionMode = "single", selectedKeys, onSelectedKeysChange, onMove, onTrim, onTrimToPlayhead, trimStep = 1, trimLimits, className, classNames, unstyled }, ref) {
|
|
1631
|
+
var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, clips: given, selectionMode = "single", selectedKeys, onSelectedKeysChange, onMove, onTrim, onTrimToPlayhead, trimStep = 1, trimLimits, onMoveLane, onDrop, canDrop, moveHandle = "clip", className, classNames, unstyled }, ref) {
|
|
1475
1632
|
const context = useTimelineContext("TimelineClips");
|
|
1476
1633
|
const pixelsPerUnit = context?.scale.pixelsPerUnit ?? 0;
|
|
1634
|
+
const timelineLength = context?.scale.length ?? Number.POSITIVE_INFINITY;
|
|
1477
1635
|
const multiple = selectionMode === "multiple";
|
|
1478
1636
|
const clips = useMemo(() => {
|
|
1479
1637
|
const valid = given.filter((clip) => Number.isSafeInteger(clip.length) && clip.length > 0);
|
|
@@ -1482,7 +1640,26 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1482
1640
|
}
|
|
1483
1641
|
return valid;
|
|
1484
1642
|
}, [given]);
|
|
1485
|
-
const
|
|
1643
|
+
const starts = useMemo(() => {
|
|
1644
|
+
const placed = clips.filter((clip) => clip.at !== void 0).length;
|
|
1645
|
+
if (placed === 0) return sequenceOffsets(clips.map((clip) => clip.length)).slice(0, clips.length);
|
|
1646
|
+
let end = 0;
|
|
1647
|
+
let mistake;
|
|
1648
|
+
if (placed !== clips.length) mistake = "gives some clips `at` and not others: give it to every clip, or to none";
|
|
1649
|
+
const result = clips.map((clip) => {
|
|
1650
|
+
const valid = clip.at !== void 0 && Number.isSafeInteger(clip.at) && clip.at >= 0;
|
|
1651
|
+
const start = valid ? clip.at : end;
|
|
1652
|
+
if (clip.at !== void 0 && !valid) mistake ??= "has a clip whose `at` isn't a whole number of at least 0";
|
|
1653
|
+
else if (start < end) mistake ??= "has clips that overlap or aren't in time order";
|
|
1654
|
+
end = Math.max(end, start + clip.length);
|
|
1655
|
+
return start;
|
|
1656
|
+
});
|
|
1657
|
+
if (mistake) {
|
|
1658
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment(`TimelineClips ${mistake}.`);
|
|
1659
|
+
}
|
|
1660
|
+
return result;
|
|
1661
|
+
}, [clips]);
|
|
1662
|
+
const positioned = clips.some((clip) => clip.at !== void 0);
|
|
1486
1663
|
const list = useRef(null);
|
|
1487
1664
|
const [focusKey, setFocusKey] = useState(null);
|
|
1488
1665
|
const anchor = useRef(null);
|
|
@@ -1502,31 +1679,90 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1502
1679
|
const viewport = context?.viewport.current;
|
|
1503
1680
|
if (viewport) {
|
|
1504
1681
|
const box = element.getBoundingClientRect();
|
|
1505
|
-
const
|
|
1682
|
+
const bounds = viewport.getBoundingClientRect();
|
|
1683
|
+
const header = context?.headerWidth ?? 0;
|
|
1684
|
+
const rtl = getComputedStyle(viewport).direction === "rtl";
|
|
1685
|
+
const view = {
|
|
1686
|
+
left: bounds.left + (rtl ? 0 : header),
|
|
1687
|
+
right: bounds.right - (rtl ? header : 0)
|
|
1688
|
+
};
|
|
1506
1689
|
if (box.left < view.left) viewport.scrollLeft -= view.left - box.left;
|
|
1507
1690
|
else if (box.right > view.right) viewport.scrollLeft += Math.min(box.right - view.right, box.left - view.left);
|
|
1508
1691
|
}
|
|
1509
1692
|
return true;
|
|
1510
1693
|
};
|
|
1511
1694
|
useImperativeHandle(ref, () => ({ focusClip }));
|
|
1695
|
+
const laneId = useContext(TimelineLaneContext);
|
|
1696
|
+
const forLanes = useRef({
|
|
1697
|
+
any: () => false,
|
|
1698
|
+
focus: () => false,
|
|
1699
|
+
focusNearest: () => void 0
|
|
1700
|
+
});
|
|
1701
|
+
forLanes.current = {
|
|
1702
|
+
any: () => clips.length > 0,
|
|
1703
|
+
focus: (key) => clips.some((clip) => clip.key === key) && focusClip(key),
|
|
1704
|
+
focusNearest: (unit, andSelect) => {
|
|
1705
|
+
let nearest;
|
|
1706
|
+
let distance = Number.POSITIVE_INFINITY;
|
|
1707
|
+
clips.forEach((clip, index) => {
|
|
1708
|
+
const start = starts[index] ?? 0;
|
|
1709
|
+
const end = start + clip.length;
|
|
1710
|
+
const away = unit < start ? start - unit : unit >= end ? unit - end + 1 : 0;
|
|
1711
|
+
if (away < distance) {
|
|
1712
|
+
nearest = clip;
|
|
1713
|
+
distance = away;
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
if (nearest && focusClip(nearest.key) && andSelect) {
|
|
1717
|
+
anchor.current = nearest.key;
|
|
1718
|
+
select([nearest.key]);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
const setLaneClips = context?.setLaneClips;
|
|
1723
|
+
useEffect(() => {
|
|
1724
|
+
if (laneId === void 0 || !setLaneClips) return;
|
|
1725
|
+
setLaneClips(laneId, {
|
|
1726
|
+
any: () => forLanes.current.any(),
|
|
1727
|
+
focus: (key) => forLanes.current.focus(key),
|
|
1728
|
+
focusNearest: (unit, andSelect) => forLanes.current.focusNearest(unit, andSelect)
|
|
1729
|
+
});
|
|
1730
|
+
return () => setLaneClips(laneId, null);
|
|
1731
|
+
}, [laneId, setLaneClips]);
|
|
1512
1732
|
const addTargets = context?.addTargets;
|
|
1513
|
-
const
|
|
1514
|
-
boundaries
|
|
1733
|
+
const edges = useMemo(() => [...new Set(clips.flatMap((clip, index) => [starts[index] ?? 0, (starts[index] ?? 0) + clip.length]))], [clips, starts]);
|
|
1734
|
+
const boundaries = useRef(edges);
|
|
1735
|
+
boundaries.current = edges;
|
|
1515
1736
|
useEffect(() => addTargets?.(() => boundaries.current), [addTargets]);
|
|
1516
1737
|
const [drag, setDrag] = useState(null);
|
|
1738
|
+
const [move, setMove] = useState(null);
|
|
1517
1739
|
const sized = useRef(null);
|
|
1518
1740
|
const sizeClips = (element) => {
|
|
1519
|
-
if (sized.current?.clips === clips && sized.current.scale === pixelsPerUnit && sized.current.drag === drag) return;
|
|
1741
|
+
if (sized.current?.clips === clips && sized.current.scale === pixelsPerUnit && sized.current.drag === drag && sized.current.move === move) return;
|
|
1520
1742
|
sized.current = {
|
|
1521
1743
|
clips,
|
|
1522
1744
|
scale: pixelsPerUnit,
|
|
1523
|
-
drag
|
|
1745
|
+
drag,
|
|
1746
|
+
move
|
|
1524
1747
|
};
|
|
1748
|
+
const rtl = move ? getComputedStyle(element).direction === "rtl" : false;
|
|
1525
1749
|
const elements = element.children;
|
|
1750
|
+
let end = 0;
|
|
1526
1751
|
for (let index = 0; index < elements.length; index++) {
|
|
1527
1752
|
const clip = clips[index];
|
|
1528
|
-
const
|
|
1529
|
-
|
|
1753
|
+
const node = elements[index];
|
|
1754
|
+
let start = starts[index] ?? end;
|
|
1755
|
+
let length = clip?.length ?? 0;
|
|
1756
|
+
if (clip && drag?.key === clip.key) {
|
|
1757
|
+
length += drag.delta;
|
|
1758
|
+
if (drag.edge === "start" && positioned) start -= drag.delta;
|
|
1759
|
+
}
|
|
1760
|
+
if (!positioned) start = end;
|
|
1761
|
+
const measured = pixelsPerUnit > 0;
|
|
1762
|
+
setStyle(node, "inline-size", measured ? `${length * pixelsPerUnit}px` : "");
|
|
1763
|
+
setStyle(node, "margin-inline-start", measured && start !== end ? `${(start - end) * pixelsPerUnit}px` : "");
|
|
1764
|
+
setStyle(node, "translate", clip && move?.key === clip.key ? `${move.by * pixelsPerUnit * (rtl ? -1 : 1)}px ${move.down}px` : "");
|
|
1765
|
+
end = start + length;
|
|
1530
1766
|
}
|
|
1531
1767
|
};
|
|
1532
1768
|
useEffect(() => {
|
|
@@ -1542,12 +1778,120 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1542
1778
|
held.current = null;
|
|
1543
1779
|
const active = document.activeElement;
|
|
1544
1780
|
if (active && active !== document.body) return;
|
|
1781
|
+
if (laneId !== void 0 && context?.focusOnAnotherLane(laneId, was.key)) return;
|
|
1545
1782
|
const next = clips[Math.min(was.index, clips.length - 1)];
|
|
1546
1783
|
if (next) focusClip(next.key);
|
|
1547
1784
|
else context?.track.current?.querySelector(".hm-timeline-playhead-slider")?.focus();
|
|
1548
1785
|
});
|
|
1549
1786
|
const dragging = useRef(null);
|
|
1787
|
+
const movingWith = (key) => {
|
|
1788
|
+
if (!selected.has(key)) return [key];
|
|
1789
|
+
const own = new Set(clips.map((clip) => clip.key));
|
|
1790
|
+
return [...clips.filter((clip) => selected.has(clip.key)).map((clip) => clip.key), ...selectedKeys.filter((other) => !own.has(other))];
|
|
1791
|
+
};
|
|
1792
|
+
const moving = useRef(null);
|
|
1793
|
+
const dragged = useRef(false);
|
|
1794
|
+
const follow = () => {
|
|
1795
|
+
const at = moving.current;
|
|
1796
|
+
const scale = context?.scale;
|
|
1797
|
+
if (!at || !scale || !list.current) return;
|
|
1798
|
+
let start = Math.max(0, at.start + scale.unitAt(at.lastX) - at.unit);
|
|
1799
|
+
if (!at.alt) {
|
|
1800
|
+
const own = [at.start, at.start + at.length];
|
|
1801
|
+
const byStart = (context?.snapExcept(start, own) ?? start) - start;
|
|
1802
|
+
const end = start + at.length;
|
|
1803
|
+
const byEnd = (context?.snapExcept(end, own) ?? end) - end;
|
|
1804
|
+
start = Math.max(0, start + (byStart !== 0 && (byEnd === 0 || Math.abs(byStart) <= Math.abs(byEnd)) ? byStart : byEnd));
|
|
1805
|
+
}
|
|
1806
|
+
const by = start - at.start;
|
|
1807
|
+
let lane;
|
|
1808
|
+
let down = 0;
|
|
1809
|
+
const ownLane = list.current.closest("[data-hm-lane]");
|
|
1810
|
+
if (ownLane) for (const other of context?.track.current?.querySelectorAll(":scope > [data-hm-lane]") ?? []) {
|
|
1811
|
+
const box = other.getBoundingClientRect();
|
|
1812
|
+
if (at.lastY >= box.top && at.lastY < box.bottom && other !== ownLane) {
|
|
1813
|
+
lane = other.dataset["hmLane"];
|
|
1814
|
+
down = box.top - ownLane.getBoundingClientRect().top;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
const refused = canDrop ? !canDrop(at.keys, {
|
|
1818
|
+
by,
|
|
1819
|
+
lane
|
|
1820
|
+
}) : false;
|
|
1821
|
+
at.by = by;
|
|
1822
|
+
at.lane = lane;
|
|
1823
|
+
at.refused = refused;
|
|
1824
|
+
setMove((current) => current && current.by === by && current.lane === lane && current.down === down && current.refused === refused ? current : {
|
|
1825
|
+
key: at.key,
|
|
1826
|
+
by,
|
|
1827
|
+
lane,
|
|
1828
|
+
down,
|
|
1829
|
+
refused
|
|
1830
|
+
});
|
|
1831
|
+
};
|
|
1832
|
+
const scrollAtEdges = () => {
|
|
1833
|
+
const at = moving.current;
|
|
1834
|
+
const viewport = context?.viewport.current;
|
|
1835
|
+
if (!at?.started || !viewport) return;
|
|
1836
|
+
const box = viewport.getBoundingClientRect();
|
|
1837
|
+
const header = context?.headerWidth ?? 0;
|
|
1838
|
+
const rtl = getComputedStyle(viewport).direction === "rtl";
|
|
1839
|
+
const left = box.left + (rtl ? 0 : header);
|
|
1840
|
+
const right = box.right - (rtl ? header : 0);
|
|
1841
|
+
const step = at.lastX < left + EDGE ? -12 : at.lastX > right - EDGE ? SCROLL : 0;
|
|
1842
|
+
if (step !== 0) {
|
|
1843
|
+
const before = viewport.scrollLeft;
|
|
1844
|
+
viewport.scrollLeft += step;
|
|
1845
|
+
if (viewport.scrollLeft !== before) follow();
|
|
1846
|
+
}
|
|
1847
|
+
at.frame = requestAnimationFrame(scrollAtEdges);
|
|
1848
|
+
};
|
|
1849
|
+
const endMove = (commit) => {
|
|
1850
|
+
const at = moving.current;
|
|
1851
|
+
moving.current = null;
|
|
1852
|
+
if (!at) return;
|
|
1853
|
+
cancelAnimationFrame(at.frame);
|
|
1854
|
+
if (!at.started) return;
|
|
1855
|
+
dragged.current = true;
|
|
1856
|
+
setMove(null);
|
|
1857
|
+
if (commit && !at.refused && (at.by !== 0 || at.lane !== void 0)) {
|
|
1858
|
+
held.current ??= {
|
|
1859
|
+
key: at.key,
|
|
1860
|
+
index: clips.findIndex((clip) => clip.key === at.key)
|
|
1861
|
+
};
|
|
1862
|
+
moved.current = true;
|
|
1863
|
+
onDrop?.(at.keys, {
|
|
1864
|
+
by: at.by,
|
|
1865
|
+
lane: at.lane
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1550
1869
|
const handlePointerDown = (event) => {
|
|
1870
|
+
const pressed = event.target.closest("[data-hm-key]");
|
|
1871
|
+
const pressedClip = clips.find((clip) => clip.key === pressed?.dataset["hmKey"]);
|
|
1872
|
+
if (onDrop && pressed && pressedClip && event.button === 0 && event.pointerType !== "touch" && pixelsPerUnit > 0 && !event.target.closest("[data-hm-edge]") && (moveHandle === "clip" || event.target.closest(".hm-timeline-clip-content") !== null)) {
|
|
1873
|
+
const index = clips.indexOf(pressedClip);
|
|
1874
|
+
moving.current = {
|
|
1875
|
+
pointerId: event.pointerId,
|
|
1876
|
+
element: pressed,
|
|
1877
|
+
key: pressedClip.key,
|
|
1878
|
+
keys: movingWith(pressedClip.key),
|
|
1879
|
+
x: event.clientX,
|
|
1880
|
+
y: event.clientY,
|
|
1881
|
+
unit: context?.scale.unitAt(event.clientX) ?? 0,
|
|
1882
|
+
start: starts[index] ?? 0,
|
|
1883
|
+
length: pressedClip.length,
|
|
1884
|
+
started: false,
|
|
1885
|
+
lastX: event.clientX,
|
|
1886
|
+
lastY: event.clientY,
|
|
1887
|
+
alt: event.altKey,
|
|
1888
|
+
by: 0,
|
|
1889
|
+
lane: void 0,
|
|
1890
|
+
refused: false,
|
|
1891
|
+
frame: 0
|
|
1892
|
+
};
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1551
1895
|
const handle = event.target.closest("[data-hm-edge]");
|
|
1552
1896
|
const key = handle?.closest("[data-hm-key]")?.dataset["hmKey"];
|
|
1553
1897
|
const index = clips.findIndex((clip) => clip.key === key);
|
|
@@ -1560,7 +1904,7 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1560
1904
|
x: event.clientX,
|
|
1561
1905
|
key: clip.key,
|
|
1562
1906
|
edge,
|
|
1563
|
-
boundary:
|
|
1907
|
+
boundary: (starts[index] ?? 0) + (edge === "start" ? 0 : clip.length),
|
|
1564
1908
|
min: Math.max(limits?.min ?? Number.NEGATIVE_INFINITY, 1 - clip.length),
|
|
1565
1909
|
max: limits?.max ?? Number.POSITIVE_INFINITY,
|
|
1566
1910
|
delta: 0
|
|
@@ -1575,6 +1919,22 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1575
1919
|
});
|
|
1576
1920
|
};
|
|
1577
1921
|
const handlePointerMove = (event) => {
|
|
1922
|
+
const at = moving.current;
|
|
1923
|
+
if (at && event.pointerId === at.pointerId) {
|
|
1924
|
+
at.lastX = event.clientX;
|
|
1925
|
+
at.lastY = event.clientY;
|
|
1926
|
+
at.alt = event.altKey;
|
|
1927
|
+
if (!at.started) {
|
|
1928
|
+
if (Math.hypot(event.clientX - at.x, event.clientY - at.y) < DRAG_AFTER) return;
|
|
1929
|
+
at.started = true;
|
|
1930
|
+
try {
|
|
1931
|
+
at.element.setPointerCapture(event.pointerId);
|
|
1932
|
+
} catch {}
|
|
1933
|
+
at.frame = requestAnimationFrame(scrollAtEdges);
|
|
1934
|
+
}
|
|
1935
|
+
follow();
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1578
1938
|
const start = dragging.current;
|
|
1579
1939
|
if (!start || event.pointerId !== start.pointerId || pixelsPerUnit <= 0) return;
|
|
1580
1940
|
const along = getComputedStyle(event.currentTarget).direction === "rtl" ? start.x - event.clientX : event.clientX - start.x;
|
|
@@ -1594,7 +1954,7 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1594
1954
|
setDrag(null);
|
|
1595
1955
|
if (commit && start && start.delta !== 0) onTrim?.(start.key, start.edge, start.delta);
|
|
1596
1956
|
};
|
|
1597
|
-
const isDragging = drag !== null;
|
|
1957
|
+
const isDragging = drag !== null || move !== null;
|
|
1598
1958
|
useEffect(() => {
|
|
1599
1959
|
if (!isDragging) return;
|
|
1600
1960
|
const onKeyDown = (event) => {
|
|
@@ -1602,14 +1962,22 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1602
1962
|
event.preventDefault();
|
|
1603
1963
|
dragging.current = null;
|
|
1604
1964
|
setDrag(null);
|
|
1965
|
+
if (moving.current) {
|
|
1966
|
+
cancelAnimationFrame(moving.current.frame);
|
|
1967
|
+
moving.current = null;
|
|
1968
|
+
dragged.current = true;
|
|
1969
|
+
setMove(null);
|
|
1970
|
+
}
|
|
1605
1971
|
}
|
|
1606
1972
|
};
|
|
1607
1973
|
document.addEventListener("keydown", onKeyDown, true);
|
|
1608
1974
|
return () => document.removeEventListener("keydown", onKeyDown, true);
|
|
1609
1975
|
}, [isDragging]);
|
|
1610
|
-
const select = (keys) => {
|
|
1976
|
+
const select = (keys, keepOthers = false) => {
|
|
1611
1977
|
const wanted = new Set(keys);
|
|
1978
|
+
const own = new Set(clips.map((clip) => clip.key));
|
|
1612
1979
|
const next = clips.filter((clip) => wanted.has(clip.key)).map((clip) => clip.key);
|
|
1980
|
+
if (keepOthers) next.push(...selectedKeys.filter((key) => !own.has(key)));
|
|
1613
1981
|
if (next.length !== selectedKeys.length || next.some((key, i) => key !== selectedKeys[i])) onSelectedKeysChange(next);
|
|
1614
1982
|
};
|
|
1615
1983
|
const range = (to) => {
|
|
@@ -1620,7 +1988,7 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1620
1988
|
const next = new Set(selected);
|
|
1621
1989
|
if (!next.delete(key)) next.add(key);
|
|
1622
1990
|
anchor.current = key;
|
|
1623
|
-
select(next);
|
|
1991
|
+
select(next, true);
|
|
1624
1992
|
};
|
|
1625
1993
|
const handleKeyDown = (event) => {
|
|
1626
1994
|
if (event.defaultPrevented || event.nativeEvent.isComposing) return;
|
|
@@ -1639,7 +2007,13 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1639
2007
|
event.preventDefault();
|
|
1640
2008
|
if (onMove) {
|
|
1641
2009
|
moved.current = true;
|
|
1642
|
-
onMove(
|
|
2010
|
+
onMove(movingWith(current.key), event.key === forward ? 1 : -1);
|
|
2011
|
+
}
|
|
2012
|
+
} else if ((event.key === "ArrowUp" || event.key === "ArrowDown") && !event.shiftKey && laneId !== void 0) {
|
|
2013
|
+
event.preventDefault();
|
|
2014
|
+
if (onMoveLane) {
|
|
2015
|
+
moved.current = true;
|
|
2016
|
+
onMoveLane(movingWith(current.key), event.key === "ArrowDown" ? 1 : -1);
|
|
1643
2017
|
}
|
|
1644
2018
|
} else if (edge && onTrim) {
|
|
1645
2019
|
event.preventDefault();
|
|
@@ -1654,6 +2028,13 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1654
2028
|
}
|
|
1655
2029
|
return;
|
|
1656
2030
|
}
|
|
2031
|
+
if ((event.key === "ArrowUp" || event.key === "ArrowDown") && laneId !== void 0) {
|
|
2032
|
+
if (event.shiftKey || (context?.lanes.length ?? 0) < 2) return;
|
|
2033
|
+
event.preventDefault();
|
|
2034
|
+
const middle = (starts[index] ?? 0) + current.length / 2;
|
|
2035
|
+
context?.nextLaneClips(laneId, event.key === "ArrowDown" ? 1 : -1)?.focusNearest(middle, !mod);
|
|
2036
|
+
return;
|
|
2037
|
+
}
|
|
1657
2038
|
let to;
|
|
1658
2039
|
if (event.key === forward) to = Math.min(index + 1, clips.length - 1);
|
|
1659
2040
|
else if (event.key === backward) to = Math.max(index - 1, 0);
|
|
@@ -1664,7 +2045,7 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1664
2045
|
if (event.shiftKey && (mod || !multiple)) return;
|
|
1665
2046
|
event.preventDefault();
|
|
1666
2047
|
focusClip(target.key);
|
|
1667
|
-
if (event.shiftKey) select(range(to));
|
|
2048
|
+
if (event.shiftKey) select(range(to), true);
|
|
1668
2049
|
else if (!mod) {
|
|
1669
2050
|
anchor.current = target.key;
|
|
1670
2051
|
select([target.key]);
|
|
@@ -1674,7 +2055,7 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1674
2055
|
if (event.key === " " || event.key === "Enter" && !mod && !event.shiftKey) {
|
|
1675
2056
|
event.preventDefault();
|
|
1676
2057
|
if (!multiple) select([current.key]);
|
|
1677
|
-
else if (event.shiftKey) select(range(index));
|
|
2058
|
+
else if (event.shiftKey) select(range(index), true);
|
|
1678
2059
|
else if (event.key === " ") toggle(current.key);
|
|
1679
2060
|
else {
|
|
1680
2061
|
anchor.current = current.key;
|
|
@@ -1682,15 +2063,19 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1682
2063
|
}
|
|
1683
2064
|
} else if (multiple && mod && !event.shiftKey && event.key.toLowerCase() === "a") {
|
|
1684
2065
|
event.preventDefault();
|
|
1685
|
-
select(clips.map((clip) => clip.key));
|
|
2066
|
+
select(clips.map((clip) => clip.key), true);
|
|
1686
2067
|
}
|
|
1687
2068
|
};
|
|
1688
2069
|
const handleClick = (event) => {
|
|
1689
2070
|
const key = event.target.closest("[data-hm-key]")?.dataset["hmKey"];
|
|
1690
2071
|
const index = clips.findIndex((clip) => clip.key === key);
|
|
1691
2072
|
if (key === void 0 || index === -1 || event.defaultPrevented) return;
|
|
2073
|
+
if (dragged.current) {
|
|
2074
|
+
dragged.current = false;
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
1692
2077
|
setFocusKey(key);
|
|
1693
|
-
if (multiple && event.shiftKey) select(range(index));
|
|
2078
|
+
if (multiple && event.shiftKey) select(range(index), true);
|
|
1694
2079
|
else if (multiple && (event.ctrlKey || event.metaKey)) toggle(key);
|
|
1695
2080
|
else {
|
|
1696
2081
|
anchor.current = key;
|
|
@@ -1733,25 +2118,133 @@ var TimelineClips = /* @__PURE__ */ forwardRef(function TimelineClips({ label, c
|
|
|
1733
2118
|
className: cx("hm-timeline-clips", classNames?.root, className),
|
|
1734
2119
|
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1735
2120
|
"data-hm-measured": pixelsPerUnit > 0 ? "" : void 0,
|
|
2121
|
+
"data-hm-move-handle": onDrop ? moveHandle : void 0,
|
|
1736
2122
|
onKeyDown: handleKeyDown,
|
|
1737
2123
|
onClick: handleClick,
|
|
1738
2124
|
onPointerDown: handlePointerDown,
|
|
1739
2125
|
onPointerMove: handlePointerMove,
|
|
1740
|
-
onPointerUp: () =>
|
|
1741
|
-
|
|
2126
|
+
onPointerUp: () => {
|
|
2127
|
+
endDrag(true);
|
|
2128
|
+
endMove(true);
|
|
2129
|
+
},
|
|
2130
|
+
onPointerCancel: () => {
|
|
2131
|
+
endDrag(false);
|
|
2132
|
+
endMove(false);
|
|
2133
|
+
},
|
|
1742
2134
|
onFocus: handleFocus,
|
|
1743
2135
|
onBlur: handleBlur,
|
|
1744
|
-
children: clips.map((clip) => /* @__PURE__ */ jsx(Clip, {
|
|
2136
|
+
children: clips.map((clip, index) => /* @__PURE__ */ jsx(Clip, {
|
|
1745
2137
|
clip,
|
|
1746
2138
|
selected: selected.has(clip.key),
|
|
1747
2139
|
tabStop: clip === tabStop,
|
|
1748
2140
|
clipClass,
|
|
1749
2141
|
contentClass,
|
|
1750
2142
|
edges: onTrim !== void 0,
|
|
1751
|
-
dragging: drag?.key === clip.key ? drag.edge : void 0
|
|
2143
|
+
dragging: drag?.key === clip.key ? drag.edge : void 0,
|
|
2144
|
+
pastEnd: (starts[index] ?? 0) + clip.length > timelineLength,
|
|
2145
|
+
moving: move?.key === clip.key ? move.refused ? "refused" : "allowed" : void 0
|
|
1752
2146
|
}, clip.key))
|
|
1753
2147
|
});
|
|
1754
2148
|
});
|
|
2149
|
+
// src/components/toolbar/Toolbar.tsx
|
|
2150
|
+
function useMergedRef(forwarded) {
|
|
2151
|
+
const local = useRef(null);
|
|
2152
|
+
return [local, useCallback((node) => {
|
|
2153
|
+
local.current = node;
|
|
2154
|
+
if (typeof forwarded === "function") forwarded(node);
|
|
2155
|
+
else if (forwarded) forwarded.current = node;
|
|
2156
|
+
}, [forwarded])];
|
|
2157
|
+
}
|
|
2158
|
+
var Toolbar = /* @__PURE__ */ forwardRef(function Toolbar({ label, orientation = "horizontal", className, classNames, unstyled, onKeyDown, onFocus, children, ...props }, forwardedRef) {
|
|
2159
|
+
const [ref, setRef] = useMergedRef(forwardedRef);
|
|
2160
|
+
useEffect(() => {
|
|
2161
|
+
const toolbar = ref.current;
|
|
2162
|
+
if (!toolbar) return;
|
|
2163
|
+
syncTabStop$1(toolbar);
|
|
2164
|
+
const observer = new MutationObserver(() => syncTabStop$1(toolbar, document.activeElement));
|
|
2165
|
+
observer.observe(toolbar, {
|
|
2166
|
+
childList: true,
|
|
2167
|
+
subtree: true,
|
|
2168
|
+
attributes: true,
|
|
2169
|
+
attributeFilter: ["disabled", "hidden"]
|
|
2170
|
+
});
|
|
2171
|
+
return () => observer.disconnect();
|
|
2172
|
+
}, [ref]);
|
|
2173
|
+
const handleKeyDown = (event) => {
|
|
2174
|
+
onKeyDown?.(event);
|
|
2175
|
+
if (!event.defaultPrevented && ref.current && moveFocus(ref.current, event, orientation)) event.preventDefault();
|
|
2176
|
+
};
|
|
2177
|
+
const handleFocus = (event) => {
|
|
2178
|
+
onFocus?.(event);
|
|
2179
|
+
if (ref.current && event.target !== ref.current) syncTabStop$1(ref.current, event.target);
|
|
2180
|
+
};
|
|
2181
|
+
return /* @__PURE__ */ jsx(ToolbarContext.Provider, {
|
|
2182
|
+
value: { orientation },
|
|
2183
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
2184
|
+
...props,
|
|
2185
|
+
ref: setRef,
|
|
2186
|
+
role: "toolbar",
|
|
2187
|
+
"aria-label": label,
|
|
2188
|
+
"aria-orientation": orientation,
|
|
2189
|
+
className: cx("hm-toolbar", orientation === "vertical" && "hm-toolbar--vertical", classNames?.root, className),
|
|
2190
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
2191
|
+
onKeyDown: handleKeyDown,
|
|
2192
|
+
onFocus: handleFocus,
|
|
2193
|
+
children
|
|
2194
|
+
})
|
|
2195
|
+
});
|
|
2196
|
+
});
|
|
2197
|
+
// src/components/timeline/TimelineLane.tsx
|
|
2198
|
+
var TimelineLane = /* @__PURE__ */ forwardRef(function TimelineLane({ id, label, header, className, classNames, unstyled, children, ...props }, ref) {
|
|
2199
|
+
const context = useTimelineContext("TimelineLane");
|
|
2200
|
+
useContext(TimelineLaneContext);
|
|
2201
|
+
const toolbar = useRef(null);
|
|
2202
|
+
const index = context?.lanes.indexOf(id) ?? -1;
|
|
2203
|
+
const column = context?.headerWidth ?? 0;
|
|
2204
|
+
const trail = context?.trail ?? 0;
|
|
2205
|
+
const setLane = context?.setLane;
|
|
2206
|
+
const hasHeader = header != null && header !== false;
|
|
2207
|
+
useEffect(() => () => setLane?.(id, null), [id, setLane]);
|
|
2208
|
+
return /* @__PURE__ */ jsx("div", {
|
|
2209
|
+
...props,
|
|
2210
|
+
ref: (node) => {
|
|
2211
|
+
if (node) {
|
|
2212
|
+
setStyle(node, "grid-row", index >= 0 ? String(index + 2) : "");
|
|
2213
|
+
setStyle(node, "margin-inline-start", column > 0 ? `${-(column + trail)}px` : "");
|
|
2214
|
+
setLane?.(id, {
|
|
2215
|
+
element: node,
|
|
2216
|
+
toolbar: toolbar.current
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
if (typeof ref === "function") ref(node);
|
|
2220
|
+
else if (ref) ref.current = node;
|
|
2221
|
+
},
|
|
2222
|
+
role: "group",
|
|
2223
|
+
"aria-label": label,
|
|
2224
|
+
"data-hm-lane": id,
|
|
2225
|
+
className: cx("hm-timeline-lane", classNames?.root, className),
|
|
2226
|
+
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
2227
|
+
children: /* @__PURE__ */ jsxs(TimelineLaneContext.Provider, {
|
|
2228
|
+
value: id,
|
|
2229
|
+
children: [hasHeader ? /* @__PURE__ */ jsx("div", {
|
|
2230
|
+
className: cx("hm-timeline-lane-header", classNames?.header),
|
|
2231
|
+
ref: (node) => {
|
|
2232
|
+
if (node) {
|
|
2233
|
+
setStyle(node, "inline-size", column > 0 ? `${column}px` : "");
|
|
2234
|
+
setStyle(node, "margin-inline-end", column > 0 ? `${trail}px` : "");
|
|
2235
|
+
setStyle(node, "inset-inline-start", column > 0 ? `${-(column + trail)}px` : "");
|
|
2236
|
+
}
|
|
2237
|
+
},
|
|
2238
|
+
children: /* @__PURE__ */ jsx(Toolbar, {
|
|
2239
|
+
ref: toolbar,
|
|
2240
|
+
label,
|
|
2241
|
+
className: "hm-timeline-lane-toolbar",
|
|
2242
|
+
children: header
|
|
2243
|
+
})
|
|
2244
|
+
}) : null, children]
|
|
2245
|
+
})
|
|
2246
|
+
});
|
|
2247
|
+
});
|
|
1755
2248
|
// src/components/timeline/TimelinePlayhead.tsx
|
|
1756
2249
|
var OWN_PRESS = "input, button, a[href], select, textarea, [role=\"option\"], [tabindex]";
|
|
1757
2250
|
var TimelinePlayhead = /* @__PURE__ */ forwardRef(function TimelinePlayhead({ label, position: rawPosition, onPositionChange, step = 1, largeStep, formatValue, seekOnPress = true, following = false, className, classNames, unstyled }, ref) {
|
|
@@ -1759,6 +2252,7 @@ var TimelinePlayhead = /* @__PURE__ */ forwardRef(function TimelinePlayhead({ la
|
|
|
1759
2252
|
const scale = context?.scale;
|
|
1760
2253
|
const length = scale?.length ?? 0;
|
|
1761
2254
|
const pixelsPerUnit = scale?.pixelsPerUnit ?? 0;
|
|
2255
|
+
const extent = scale?.extent ?? 0;
|
|
1762
2256
|
const position = Math.min(Math.max(Math.round(rawPosition) || 0, 0), length);
|
|
1763
2257
|
const latest = useRef({
|
|
1764
2258
|
position,
|
|
@@ -1771,9 +2265,11 @@ var TimelinePlayhead = /* @__PURE__ */ forwardRef(function TimelinePlayhead({ la
|
|
|
1771
2265
|
const addTargets = context?.addTargets;
|
|
1772
2266
|
useEffect(() => addTargets?.(() => [latest.current.position]), [addTargets]);
|
|
1773
2267
|
const placeLine = (element) => {
|
|
1774
|
-
element
|
|
2268
|
+
setStyle(element, "inset-inline-start", `${position * pixelsPerUnit}px`);
|
|
1775
2269
|
};
|
|
1776
2270
|
const viewport = context?.viewport;
|
|
2271
|
+
const header = context?.headerWidth ?? 0;
|
|
2272
|
+
const lanes = context?.lanes.length ?? 0;
|
|
1777
2273
|
const lastScale = useRef(0);
|
|
1778
2274
|
useEffect(() => {
|
|
1779
2275
|
const element = viewport?.current;
|
|
@@ -1783,7 +2279,7 @@ var TimelinePlayhead = /* @__PURE__ */ forwardRef(function TimelinePlayhead({ la
|
|
|
1783
2279
|
if (!element || pixelsPerUnit <= 0 || !(following || zoomed || first)) return;
|
|
1784
2280
|
const at = position * pixelsPerUnit;
|
|
1785
2281
|
const start = Math.abs(element.scrollLeft);
|
|
1786
|
-
const width = element.clientWidth;
|
|
2282
|
+
const width = element.clientWidth - header;
|
|
1787
2283
|
if (zoomed || at < start || at > start + width) {
|
|
1788
2284
|
const to = Math.max(0, at - (zoomed || first ? width / 2 : width / 10));
|
|
1789
2285
|
element.scrollLeft = getComputedStyle(element).direction === "rtl" ? -to : to;
|
|
@@ -1792,7 +2288,8 @@ var TimelinePlayhead = /* @__PURE__ */ forwardRef(function TimelinePlayhead({ la
|
|
|
1792
2288
|
viewport,
|
|
1793
2289
|
position,
|
|
1794
2290
|
pixelsPerUnit,
|
|
1795
|
-
following
|
|
2291
|
+
following,
|
|
2292
|
+
header
|
|
1796
2293
|
]);
|
|
1797
2294
|
const track = context?.track;
|
|
1798
2295
|
useEffect(() => {
|
|
@@ -1811,6 +2308,14 @@ var TimelinePlayhead = /* @__PURE__ */ forwardRef(function TimelinePlayhead({ la
|
|
|
1811
2308
|
seekOnPress
|
|
1812
2309
|
]);
|
|
1813
2310
|
return /* @__PURE__ */ jsxs("div", {
|
|
2311
|
+
ref: (node) => {
|
|
2312
|
+
if (node) {
|
|
2313
|
+
setStyle(node, "grid-row", lanes > 0 ? `1 / span ${lanes + 1}` : "");
|
|
2314
|
+
const shorter = extent > length && pixelsPerUnit > 0;
|
|
2315
|
+
setStyle(node, "justify-self", shorter ? "start" : "");
|
|
2316
|
+
setStyle(node, "inline-size", shorter ? `${length * pixelsPerUnit}px` : "");
|
|
2317
|
+
}
|
|
2318
|
+
},
|
|
1814
2319
|
className: cx("hm-timeline-playhead", classNames?.root, className),
|
|
1815
2320
|
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1816
2321
|
children: [/* @__PURE__ */ jsx(Slider, {
|
|
@@ -1860,54 +2365,6 @@ var ToggleButton = /* @__PURE__ */ forwardRef(function ToggleButton({ pressed: c
|
|
|
1860
2365
|
onClick: handleClick
|
|
1861
2366
|
});
|
|
1862
2367
|
});
|
|
1863
|
-
// src/components/toolbar/Toolbar.tsx
|
|
1864
|
-
function useMergedRef(forwarded) {
|
|
1865
|
-
const local = useRef(null);
|
|
1866
|
-
return [local, useCallback((node) => {
|
|
1867
|
-
local.current = node;
|
|
1868
|
-
if (typeof forwarded === "function") forwarded(node);
|
|
1869
|
-
else if (forwarded) forwarded.current = node;
|
|
1870
|
-
}, [forwarded])];
|
|
1871
|
-
}
|
|
1872
|
-
var Toolbar = /* @__PURE__ */ forwardRef(function Toolbar({ label, orientation = "horizontal", className, classNames, unstyled, onKeyDown, onFocus, children, ...props }, forwardedRef) {
|
|
1873
|
-
const [ref, setRef] = useMergedRef(forwardedRef);
|
|
1874
|
-
useEffect(() => {
|
|
1875
|
-
const toolbar = ref.current;
|
|
1876
|
-
if (!toolbar) return;
|
|
1877
|
-
syncTabStop$1(toolbar);
|
|
1878
|
-
const observer = new MutationObserver(() => syncTabStop$1(toolbar, document.activeElement));
|
|
1879
|
-
observer.observe(toolbar, {
|
|
1880
|
-
childList: true,
|
|
1881
|
-
subtree: true,
|
|
1882
|
-
attributes: true,
|
|
1883
|
-
attributeFilter: ["disabled", "hidden"]
|
|
1884
|
-
});
|
|
1885
|
-
return () => observer.disconnect();
|
|
1886
|
-
}, [ref]);
|
|
1887
|
-
const handleKeyDown = (event) => {
|
|
1888
|
-
onKeyDown?.(event);
|
|
1889
|
-
if (!event.defaultPrevented && ref.current && moveFocus(ref.current, event, orientation)) event.preventDefault();
|
|
1890
|
-
};
|
|
1891
|
-
const handleFocus = (event) => {
|
|
1892
|
-
onFocus?.(event);
|
|
1893
|
-
if (ref.current && event.target !== ref.current) syncTabStop$1(ref.current, event.target);
|
|
1894
|
-
};
|
|
1895
|
-
return /* @__PURE__ */ jsx(ToolbarContext.Provider, {
|
|
1896
|
-
value: { orientation },
|
|
1897
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
1898
|
-
...props,
|
|
1899
|
-
ref: setRef,
|
|
1900
|
-
role: "toolbar",
|
|
1901
|
-
"aria-label": label,
|
|
1902
|
-
"aria-orientation": orientation,
|
|
1903
|
-
className: cx("hm-toolbar", orientation === "vertical" && "hm-toolbar--vertical", classNames?.root, className),
|
|
1904
|
-
"data-hm-unstyled": unstyledAttribute(unstyled),
|
|
1905
|
-
onKeyDown: handleKeyDown,
|
|
1906
|
-
onFocus: handleFocus,
|
|
1907
|
-
children
|
|
1908
|
-
})
|
|
1909
|
-
});
|
|
1910
|
-
});
|
|
1911
2368
|
// src/components/toolbar/ToolbarGroup.tsx
|
|
1912
2369
|
var ToolbarGroup = /* @__PURE__ */ forwardRef(function ToolbarGroup({ label, className, ...props }, ref) {
|
|
1913
2370
|
return /* @__PURE__ */ jsx("div", {
|
|
@@ -2580,6 +3037,6 @@ function ThemeProvider(props) {
|
|
|
2580
3037
|
}), children]
|
|
2581
3038
|
});
|
|
2582
3039
|
}
|
|
2583
|
-
export { AddIcon, AnnouncerProvider, ArrowIcon, Button, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, HighlighterIcon, IconButton, ImageIcon, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, ReorderableList, ReorderableListItem, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, SelectIcon, SkipBackIcon, SkipForwardIcon, Slider, SnapIcon, Spinner, SplitIcon, StopIcon, TextArea, TextField, TextIcon, ThemeProvider, Timeline, TimelineClips, TimelineLayer, TimelinePlayhead, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useTimelineScale, useUiMessages };
|
|
3040
|
+
export { AddIcon, AnnouncerProvider, ArrowIcon, Button, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CloseIcon, ColorField, CropIcon, DeleteIcon, Dialog, DownloadIcon, DuplicateIcon, EllipseIcon, FadeInIcon, FadeOutIcon, Field, FileDropZone, FitIcon, FlipHorizontalIcon, FlipVerticalIcon, HiddenIcon, HighlighterIcon, IconButton, ImageIcon, InfoIcon, LayersIcon, LoopIcon, MenuIcon, MoreIcon, MoveDownIcon, MoveUpIcon, MutedIcon, NumberField, OpenIcon, PageAddIcon, PageGridIcon, PageSingleIcon, PanIcon, PauseIcon, PenIcon, PlayIcon, ProgressBar, RectangleIcon, RedactIcon, RedoIcon, RemoveIcon, ReorderableList, ReorderableListItem, RotateLeftIcon, RotateRightIcon, SearchIcon, SegmentedControl, SelectIcon, SkipBackIcon, SkipForwardIcon, Slider, SnapIcon, Spinner, SplitIcon, StopIcon, TextArea, TextField, TextIcon, ThemeProvider, Timeline, TimelineClips, TimelineLane, TimelineLayer, TimelinePlayhead, ToggleButton, Toolbar, ToolbarGroup, ToolbarSeparator, Tooltip, TrimEndIcon, TrimStartIcon, UiMessagesProvider, UndoIcon, UploadIcon, VisibleIcon, VisuallyHidden, VolumeIcon, WarningIcon, ZoomInIcon, ZoomOutIcon, uiMessages, useAnnounce, usePlatform, useTimelineLanes, useTimelineScale, useUiMessages };
|
|
2584
3041
|
|
|
2585
3042
|
//# sourceMappingURL=react.js.map
|