@embedpdf/core-ui 3.0.0-next.15 → 3.0.0-next.16
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/index.cjs +79 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -1
- package/dist/index.d.ts +51 -1
- package/dist/index.js +79 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1576,6 +1576,84 @@ function capitalize(text) {
|
|
|
1576
1576
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
1577
1577
|
}
|
|
1578
1578
|
//#endregion
|
|
1579
|
+
//#region src/tree-keys.ts
|
|
1580
|
+
/** The row `row` sits under: the nearest one above it that is one level up, or -1 at the top. */
|
|
1581
|
+
function parentOf(rows, row) {
|
|
1582
|
+
const depth = rows[row].depth;
|
|
1583
|
+
for (let i = row - 1; i >= 0; i -= 1) if (rows[i].depth < depth) return i;
|
|
1584
|
+
return -1;
|
|
1585
|
+
}
|
|
1586
|
+
/** The rows that share `row`'s parent, `row` among them, in order. */
|
|
1587
|
+
function siblingsOf(rows, row) {
|
|
1588
|
+
const depth = rows[row].depth;
|
|
1589
|
+
const siblings = [];
|
|
1590
|
+
for (let i = parentOf(rows, row) + 1; i < rows.length; i += 1) {
|
|
1591
|
+
if (rows[i].depth < depth) break;
|
|
1592
|
+
if (rows[i].depth === depth) siblings.push(i);
|
|
1593
|
+
}
|
|
1594
|
+
return siblings;
|
|
1595
|
+
}
|
|
1596
|
+
function treeKeyAction(rows, focused, key, options = {}) {
|
|
1597
|
+
if (rows.length === 0) return null;
|
|
1598
|
+
const last = rows.length - 1;
|
|
1599
|
+
if (focused < 0 || focused > last) {
|
|
1600
|
+
if (key === "ArrowDown" || key === "Home") return {
|
|
1601
|
+
type: "focus",
|
|
1602
|
+
row: 0
|
|
1603
|
+
};
|
|
1604
|
+
if (key === "ArrowUp" || key === "End") return {
|
|
1605
|
+
type: "focus",
|
|
1606
|
+
row: last
|
|
1607
|
+
};
|
|
1608
|
+
return null;
|
|
1609
|
+
}
|
|
1610
|
+
const current = rows[focused];
|
|
1611
|
+
const focus = (row) => row === focused ? null : {
|
|
1612
|
+
type: "focus",
|
|
1613
|
+
row
|
|
1614
|
+
};
|
|
1615
|
+
switch (key) {
|
|
1616
|
+
case "ArrowDown": return focus(Math.min(focused + 1, last));
|
|
1617
|
+
case "ArrowUp": return focus(Math.max(focused - 1, 0));
|
|
1618
|
+
case "Home": return focus(0);
|
|
1619
|
+
case "End": return focus(last);
|
|
1620
|
+
case "ArrowRight":
|
|
1621
|
+
if (!current.hasChildren) return null;
|
|
1622
|
+
return current.expanded ? focus(focused + 1) : {
|
|
1623
|
+
type: "expand",
|
|
1624
|
+
rows: [focused]
|
|
1625
|
+
};
|
|
1626
|
+
case "ArrowLeft": {
|
|
1627
|
+
if (current.hasChildren && current.expanded) return {
|
|
1628
|
+
type: "collapse",
|
|
1629
|
+
row: focused
|
|
1630
|
+
};
|
|
1631
|
+
const parent = parentOf(rows, focused);
|
|
1632
|
+
return parent < 0 ? null : focus(parent);
|
|
1633
|
+
}
|
|
1634
|
+
case "*": {
|
|
1635
|
+
const collapsed = siblingsOf(rows, focused).filter((row) => rows[row].hasChildren && !rows[row].expanded);
|
|
1636
|
+
return collapsed.length > 0 ? {
|
|
1637
|
+
type: "expand",
|
|
1638
|
+
rows: collapsed
|
|
1639
|
+
} : null;
|
|
1640
|
+
}
|
|
1641
|
+
case "Enter": return {
|
|
1642
|
+
type: "activate",
|
|
1643
|
+
row: focused
|
|
1644
|
+
};
|
|
1645
|
+
case "F2": return options.editable ? {
|
|
1646
|
+
type: "rename",
|
|
1647
|
+
row: focused
|
|
1648
|
+
} : null;
|
|
1649
|
+
case "Delete": return options.editable ? {
|
|
1650
|
+
type: "delete",
|
|
1651
|
+
row: focused
|
|
1652
|
+
} : null;
|
|
1653
|
+
default: return null;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
//#endregion
|
|
1579
1657
|
exports.DEFAULT_IMPORTANCE = DEFAULT_IMPORTANCE;
|
|
1580
1658
|
exports.EXPANDED_MIN_WIDTH_PX = EXPANDED_MIN_WIDTH_PX;
|
|
1581
1659
|
exports.FLOAT_POSITIONS = FLOAT_POSITIONS;
|
|
@@ -1633,6 +1711,7 @@ exports.sizeOf = sizeOf;
|
|
|
1633
1711
|
exports.solve = solve;
|
|
1634
1712
|
exports.stripGroupsOf = stripGroupsOf;
|
|
1635
1713
|
exports.tabsOf = tabsOf;
|
|
1714
|
+
exports.treeKeyAction = treeKeyAction;
|
|
1636
1715
|
exports.validateLayout = validateLayout;
|
|
1637
1716
|
|
|
1638
1717
|
//# sourceMappingURL=index.cjs.map
|