@uiw/react-md-editor 4.1.3 → 4.1.4
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/mdeditor.js
CHANGED
|
@@ -1270,8 +1270,12 @@ function looksLikeANode(value) {
|
|
|
1270
1270
|
|
|
1271
1271
|
;// ../node_modules/unist-util-visit-parents/lib/color.js
|
|
1272
1272
|
/**
|
|
1273
|
+
* Color a string.
|
|
1274
|
+
*
|
|
1273
1275
|
* @param {string} d
|
|
1276
|
+
* Value.
|
|
1274
1277
|
* @returns {string}
|
|
1278
|
+
* Colored value.
|
|
1275
1279
|
*/
|
|
1276
1280
|
function color(d) {
|
|
1277
1281
|
return d
|
|
@@ -1447,44 +1451,96 @@ function color(d) {
|
|
|
1447
1451
|
* List with one or two values, the first an action, the second an index.
|
|
1448
1452
|
*
|
|
1449
1453
|
* @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult
|
|
1450
|
-
* Any value that can be returned from
|
|
1454
|
+
* Any value that can be returned from an enter visitor.
|
|
1455
|
+
*
|
|
1456
|
+
* Like `VisitorResultExit`,
|
|
1457
|
+
* but `SKIP` can also be returned,
|
|
1458
|
+
* to not walk the children of the node,
|
|
1459
|
+
* and `ActionTuple` can be used to combine an action with an index.
|
|
1460
|
+
*
|
|
1461
|
+
* @typedef {Index | boolean | null | undefined | void} VisitorResultExit
|
|
1462
|
+
* Any value that can be returned from an exit visitor.
|
|
1451
1463
|
*/
|
|
1452
1464
|
|
|
1453
1465
|
/**
|
|
1454
1466
|
* @callback Visitor
|
|
1455
|
-
* Handle a node (matching `test`, if given).
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1461
|
-
*
|
|
1462
|
-
*
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1465
|
-
* sibling to traverse after `node` is traversed.
|
|
1466
|
-
* Adding or removing next siblings of `node` (or previous siblings, in case
|
|
1467
|
-
* of reverse) is handled as expected without needing to return a new `Index`.
|
|
1468
|
-
*
|
|
1469
|
-
* Removing the children property of an ancestor still results in them being
|
|
1470
|
-
* traversed.
|
|
1467
|
+
* Handle a node (matching `test`, if given) before its children.
|
|
1468
|
+
*
|
|
1469
|
+
* Changes inside `node` are walked next.
|
|
1470
|
+
* Replacing or removing it is easier in `exit`.
|
|
1471
|
+
* When replacing or removing it here,
|
|
1472
|
+
* return `SKIP` (as otherwise its old children are walked),
|
|
1473
|
+
* or `[SKIP, index]` to continue with the node now at `index`.
|
|
1474
|
+
* Changing next siblings (in walk order) is fine;
|
|
1475
|
+
* changing previous siblings needs a new `Index`.
|
|
1476
|
+
* Removing an ancestor or changing its previous siblings is not supported.
|
|
1471
1477
|
* @param {Visited} node
|
|
1472
1478
|
* Found node.
|
|
1473
1479
|
* @param {Array<VisitedParents>} ancestors
|
|
1474
1480
|
* Ancestors of `node`.
|
|
1481
|
+
* @param {number | undefined} index
|
|
1482
|
+
* Index of `node` in its parent (the last of `ancestors`),
|
|
1483
|
+
* or `undefined` for the tree itself.
|
|
1475
1484
|
* @returns {VisitorResult}
|
|
1476
1485
|
* What to do next.
|
|
1477
1486
|
*
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1487
|
+
* Like `VisitorExit`,
|
|
1488
|
+
* but `SKIP` can also be returned,
|
|
1489
|
+
* to not walk the children of `node`.
|
|
1490
|
+
* Passing a tuple back (`ActionTuple`) only makes sense as `[SKIP, Index]`.
|
|
1491
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
1492
|
+
* Visited node type.
|
|
1493
|
+
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
1494
|
+
* Ancestor type.
|
|
1495
|
+
*/
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
* @callback VisitorExit
|
|
1499
|
+
* Handle a node (matching `test`, if given) after its children.
|
|
1480
1500
|
*
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1483
|
-
*
|
|
1501
|
+
* Changes inside `node` are not walked,
|
|
1502
|
+
* which makes this a good place to change `node` based on its children,
|
|
1503
|
+
* or to replace or remove it.
|
|
1504
|
+
* When removing `node` or changing previous siblings (in walk order),
|
|
1505
|
+
* return a new `Index`.
|
|
1506
|
+
* Removing an ancestor or changing its previous siblings is not supported.
|
|
1507
|
+
* @param {Visited} node
|
|
1508
|
+
* Found node.
|
|
1509
|
+
* @param {Array<VisitedParents>} ancestors
|
|
1510
|
+
* Ancestors of `node`.
|
|
1511
|
+
* @param {number | undefined} index
|
|
1512
|
+
* Index of `node` in its parent (the last of `ancestors`),
|
|
1513
|
+
* or `undefined` for the tree itself.
|
|
1514
|
+
* @returns {VisitorResultExit}
|
|
1515
|
+
* What to do next.
|
|
1516
|
+
*
|
|
1517
|
+
* `CONTINUE` (`true`, nothing) continues as normal,
|
|
1518
|
+
* `EXIT` (`false`) stops traversing,
|
|
1519
|
+
* and `Index` continues at that sibling.
|
|
1520
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
1521
|
+
* Visited node type.
|
|
1522
|
+
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
1523
|
+
* Ancestor type.
|
|
1524
|
+
*/
|
|
1525
|
+
|
|
1526
|
+
/**
|
|
1484
1527
|
* @template {UnistNode} [Visited=UnistNode]
|
|
1485
1528
|
* Visited node type.
|
|
1486
1529
|
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
1487
1530
|
* Ancestor type.
|
|
1531
|
+
* @typedef Visitors
|
|
1532
|
+
* Handle nodes when entering and exiting them.
|
|
1533
|
+
* The `enter` visitor is optional while `exit` is required.
|
|
1534
|
+
*
|
|
1535
|
+
* Pass an `enter` visitor directly to only handle nodes when entering them.
|
|
1536
|
+
*
|
|
1537
|
+
* `enter` is called before children (if any) are walked and `exit` after that.
|
|
1538
|
+
* `exit` is still called when `enter` returns `SKIP`.
|
|
1539
|
+
* Both `enter` and `exit` are only called for nodes that match an optional `test`.
|
|
1540
|
+
* @property {Visitor<Visited, VisitedParents> | null | undefined} [enter]
|
|
1541
|
+
* Handle a node before its children (optional).
|
|
1542
|
+
* @property {VisitorExit<Visited, VisitedParents>} exit
|
|
1543
|
+
* Handle a node after its children.
|
|
1488
1544
|
*/
|
|
1489
1545
|
|
|
1490
1546
|
/**
|
|
@@ -1498,6 +1554,17 @@ function color(d) {
|
|
|
1498
1554
|
* Test type.
|
|
1499
1555
|
*/
|
|
1500
1556
|
|
|
1557
|
+
/**
|
|
1558
|
+
* @typedef {Visitors<Matches<InclusiveDescendant<Tree>, Check>, Ancestor<Tree, Matches<InclusiveDescendant<Tree>, Check>>>} BuildVisitors
|
|
1559
|
+
* Build typed `Visitors` from a tree and a test.
|
|
1560
|
+
*
|
|
1561
|
+
* It will infer which values are passed as `node` and which as `parents`.
|
|
1562
|
+
* @template {UnistNode} [Tree=UnistNode]
|
|
1563
|
+
* Tree type.
|
|
1564
|
+
* @template {Test} [Check=Test]
|
|
1565
|
+
* Test type.
|
|
1566
|
+
*/
|
|
1567
|
+
|
|
1501
1568
|
|
|
1502
1569
|
|
|
1503
1570
|
|
|
@@ -1516,6 +1583,7 @@ const EXIT = false
|
|
|
1516
1583
|
|
|
1517
1584
|
/**
|
|
1518
1585
|
* Do not traverse this node’s children.
|
|
1586
|
+
* Only works when entering a node.
|
|
1519
1587
|
*/
|
|
1520
1588
|
const SKIP = 'skip'
|
|
1521
1589
|
|
|
@@ -1523,10 +1591,13 @@ const SKIP = 'skip'
|
|
|
1523
1591
|
* Visit nodes, with ancestral information.
|
|
1524
1592
|
*
|
|
1525
1593
|
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
|
1526
|
-
* (**NLR**) or if `reverse` is given,
|
|
1594
|
+
* (**NLR**) or if `reverse` is given,
|
|
1595
|
+
* in *reverse preorder* (**NRL**).
|
|
1596
|
+
* An `exit` visitor is called in *postorder* (**LRN**)
|
|
1597
|
+
* or if `reverse` is given, in *reverse postorder* (**RLN**).
|
|
1527
1598
|
*
|
|
1528
|
-
* You can choose
|
|
1529
|
-
* For complex tests, you should test yourself in
|
|
1599
|
+
* You can choose which nodes are visited by passing a `test`.
|
|
1600
|
+
* For complex tests, you should test yourself in a visitor, as it will be
|
|
1530
1601
|
* faster and will have improved type information.
|
|
1531
1602
|
*
|
|
1532
1603
|
* Walking the tree is an intensive task.
|
|
@@ -1535,29 +1606,72 @@ const SKIP = 'skip'
|
|
|
1535
1606
|
* to check if a node matches, and then perform different operations.
|
|
1536
1607
|
*
|
|
1537
1608
|
* You can change the tree.
|
|
1538
|
-
*
|
|
1609
|
+
* Changes inside a node made when entering it are walked,
|
|
1610
|
+
* changes made when exiting it are not.
|
|
1611
|
+
* See `Visitor` and `VisitorExit` for more info.
|
|
1539
1612
|
*
|
|
1540
1613
|
* @overload
|
|
1541
1614
|
* @param {Tree} tree
|
|
1615
|
+
* Tree to traverse.
|
|
1542
1616
|
* @param {Check} check
|
|
1543
|
-
*
|
|
1617
|
+
* `unist-util-is`-compatible test.
|
|
1618
|
+
* @param {BuildVisitor<Tree, Check>} enter
|
|
1619
|
+
* Handle each node when entering it.
|
|
1544
1620
|
* @param {boolean | null | undefined} [reverse]
|
|
1621
|
+
* Walk children from last to first;
|
|
1622
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
1623
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
1545
1624
|
* @returns {undefined}
|
|
1625
|
+
* Nothing.
|
|
1546
1626
|
*
|
|
1547
1627
|
* @overload
|
|
1548
1628
|
* @param {Tree} tree
|
|
1549
|
-
*
|
|
1629
|
+
* Tree to traverse.
|
|
1630
|
+
* @param {Check} check
|
|
1631
|
+
* `unist-util-is`-compatible test.
|
|
1632
|
+
* @param {BuildVisitors<Tree, Check>} visitors
|
|
1633
|
+
* Handle each node when exiting it, and optionally when entering it.
|
|
1550
1634
|
* @param {boolean | null | undefined} [reverse]
|
|
1635
|
+
* Walk children from last to first;
|
|
1636
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
1637
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
1551
1638
|
* @returns {undefined}
|
|
1639
|
+
* Nothing.
|
|
1640
|
+
*
|
|
1641
|
+
* @overload
|
|
1642
|
+
* @param {Tree} tree
|
|
1643
|
+
* Tree to traverse.
|
|
1644
|
+
* @param {BuildVisitor<Tree>} enter
|
|
1645
|
+
* Handle each node when entering it.
|
|
1646
|
+
* @param {boolean | null | undefined} [reverse]
|
|
1647
|
+
* Walk children from last to first;
|
|
1648
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
1649
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
1650
|
+
* @returns {undefined}
|
|
1651
|
+
* Nothing.
|
|
1652
|
+
*
|
|
1653
|
+
* @overload
|
|
1654
|
+
* @param {Tree} tree
|
|
1655
|
+
* Tree to traverse.
|
|
1656
|
+
* @param {BuildVisitors<Tree>} visitors
|
|
1657
|
+
* Handle each node when exiting it, and optionally when entering it.
|
|
1658
|
+
* @param {boolean | null | undefined} [reverse]
|
|
1659
|
+
* Walk children from last to first;
|
|
1660
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
1661
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
1662
|
+
* @returns {undefined}
|
|
1663
|
+
* Nothing.
|
|
1552
1664
|
*
|
|
1553
1665
|
* @param {UnistNode} tree
|
|
1554
1666
|
* Tree to traverse.
|
|
1555
|
-
* @param {Visitor | Test}
|
|
1556
|
-
* `unist-util-is`-compatible test
|
|
1557
|
-
* @param {Visitor | boolean | null | undefined} [
|
|
1558
|
-
*
|
|
1667
|
+
* @param {Visitor | Visitors | Test} testOrEnterOrVisitors
|
|
1668
|
+
* `unist-util-is`-compatible test, `enter`, or `visitors`.
|
|
1669
|
+
* @param {Visitor | Visitors | boolean | null | undefined} [enterOrVisitorsOrReverse]
|
|
1670
|
+
* `enter`, `visitors`, or `reverse` after a test.
|
|
1559
1671
|
* @param {boolean | null | undefined} [reverse]
|
|
1560
|
-
*
|
|
1672
|
+
* Walk children from last to first;
|
|
1673
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
1674
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
1561
1675
|
* @returns {undefined}
|
|
1562
1676
|
* Nothing.
|
|
1563
1677
|
*
|
|
@@ -1566,28 +1680,89 @@ const SKIP = 'skip'
|
|
|
1566
1680
|
* @template {Test} Check
|
|
1567
1681
|
* `unist-util-is`-compatible test.
|
|
1568
1682
|
*/
|
|
1569
|
-
function visitParents(
|
|
1683
|
+
function visitParents(
|
|
1684
|
+
tree,
|
|
1685
|
+
testOrEnterOrVisitors,
|
|
1686
|
+
enterOrVisitorsOrReverse,
|
|
1687
|
+
reverse
|
|
1688
|
+
) {
|
|
1689
|
+
if (!tree || typeof tree !== 'object') {
|
|
1690
|
+
throw new Error('Unexpected value `' + tree + '` for `tree`, expected node')
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
let preorder = true
|
|
1570
1694
|
/** @type {Test} */
|
|
1571
1695
|
let check
|
|
1696
|
+
/** @type {Visitors | Visitor} */
|
|
1697
|
+
let visitors
|
|
1698
|
+
/** @type {Visitor | null | undefined} */
|
|
1699
|
+
let enter
|
|
1700
|
+
/** @type {VisitorExit | null | undefined} */
|
|
1701
|
+
let exit
|
|
1702
|
+
|
|
1703
|
+
// Third parameter is an enter visitor or a visitors object, so expect a `test` too.
|
|
1704
|
+
if (
|
|
1705
|
+
typeof enterOrVisitorsOrReverse === 'function' ||
|
|
1706
|
+
(enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === 'object')
|
|
1707
|
+
) {
|
|
1708
|
+
check = /** @type {Test} */ (testOrEnterOrVisitors)
|
|
1709
|
+
visitors = enterOrVisitorsOrReverse
|
|
1710
|
+
if (reverse) preorder = false
|
|
1711
|
+
}
|
|
1712
|
+
// Assume no test.
|
|
1713
|
+
else {
|
|
1714
|
+
visitors = /** @type {Visitors | Visitor} */ (testOrEnterOrVisitors)
|
|
1715
|
+
if (enterOrVisitorsOrReverse) preorder = false
|
|
1716
|
+
}
|
|
1572
1717
|
|
|
1573
|
-
if (typeof
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1718
|
+
if (typeof visitors === 'function') {
|
|
1719
|
+
enter = visitors
|
|
1720
|
+
} else if (visitors && typeof visitors === 'object') {
|
|
1721
|
+
if (visitors.enter === null || visitors.enter === undefined) {
|
|
1722
|
+
// Empty.
|
|
1723
|
+
} else if (typeof visitors.enter === 'function') {
|
|
1724
|
+
enter = visitors.enter
|
|
1725
|
+
} else {
|
|
1726
|
+
throw new Error(
|
|
1727
|
+
'Unexpected value `' +
|
|
1728
|
+
visitors.enter +
|
|
1729
|
+
'` for `visitors.enter`, expected optional visitor'
|
|
1730
|
+
)
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
if (typeof visitors.exit === 'function') {
|
|
1734
|
+
exit = visitors.exit
|
|
1735
|
+
} else {
|
|
1736
|
+
throw new Error(
|
|
1737
|
+
'Unexpected value `' +
|
|
1738
|
+
visitors.exit +
|
|
1739
|
+
'` for `visitors.exit`, expected visitor (pass a visitor directly if you only want an enter visitor)'
|
|
1740
|
+
)
|
|
1741
|
+
}
|
|
1577
1742
|
} else {
|
|
1578
|
-
|
|
1579
|
-
|
|
1743
|
+
throw new Error(
|
|
1744
|
+
'Unexpected value `' +
|
|
1745
|
+
visitors +
|
|
1746
|
+
'` for `enter` or `visitors`, expected visitor or object with visitors'
|
|
1747
|
+
)
|
|
1580
1748
|
}
|
|
1581
1749
|
|
|
1582
1750
|
const is = convert(check)
|
|
1583
|
-
const step =
|
|
1751
|
+
const step = preorder ? 1 : -1
|
|
1584
1752
|
|
|
1585
1753
|
factory(tree, undefined, [])()
|
|
1586
1754
|
|
|
1587
1755
|
/**
|
|
1756
|
+
* Create a function to visit a node.
|
|
1757
|
+
*
|
|
1588
1758
|
* @param {UnistNode} node
|
|
1759
|
+
* Node to visit.
|
|
1589
1760
|
* @param {number | undefined} index
|
|
1761
|
+
* Index of `node` in its parent.
|
|
1590
1762
|
* @param {Array<UnistParent>} parents
|
|
1763
|
+
* Ancestors of `node`.
|
|
1764
|
+
* @returns {() => Readonly<ActionTuple>}
|
|
1765
|
+
* Visit `node`.
|
|
1591
1766
|
*/
|
|
1592
1767
|
function factory(node, index, parents) {
|
|
1593
1768
|
const value = /** @type {Record<string, unknown>} */ (
|
|
@@ -1613,18 +1788,13 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
1613
1788
|
return visit
|
|
1614
1789
|
|
|
1615
1790
|
function visit() {
|
|
1791
|
+
const matches =
|
|
1792
|
+
!check || is(node, index, parents[parents.length - 1] || undefined)
|
|
1616
1793
|
/** @type {Readonly<ActionTuple>} */
|
|
1617
1794
|
let result = empty
|
|
1618
|
-
/** @type {Readonly<ActionTuple>} */
|
|
1619
|
-
let subresult
|
|
1620
|
-
/** @type {number} */
|
|
1621
|
-
let offset
|
|
1622
|
-
/** @type {Array<UnistParent>} */
|
|
1623
|
-
let grandparents
|
|
1624
1795
|
|
|
1625
|
-
if (
|
|
1626
|
-
|
|
1627
|
-
result = toResult(visitor(node, parents))
|
|
1796
|
+
if (enter && matches) {
|
|
1797
|
+
result = toResult(enter(node, parents, index))
|
|
1628
1798
|
|
|
1629
1799
|
if (result[0] === EXIT) {
|
|
1630
1800
|
return result
|
|
@@ -1635,13 +1805,13 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
1635
1805
|
const nodeAsParent = /** @type {UnistParent} */ (node)
|
|
1636
1806
|
|
|
1637
1807
|
if (nodeAsParent.children && result[0] !== SKIP) {
|
|
1638
|
-
offset = (
|
|
1639
|
-
grandparents = parents
|
|
1808
|
+
let offset = (preorder ? -1 : nodeAsParent.children.length) + step
|
|
1809
|
+
const grandparents = [...parents, nodeAsParent]
|
|
1640
1810
|
|
|
1641
1811
|
while (offset > -1 && offset < nodeAsParent.children.length) {
|
|
1642
1812
|
const child = nodeAsParent.children[offset]
|
|
1643
1813
|
|
|
1644
|
-
subresult = factory(child, offset, grandparents)()
|
|
1814
|
+
const subresult = factory(child, offset, grandparents)()
|
|
1645
1815
|
|
|
1646
1816
|
if (subresult[0] === EXIT) {
|
|
1647
1817
|
return subresult
|
|
@@ -1653,6 +1823,23 @@ function visitParents(tree, test, visitor, reverse) {
|
|
|
1653
1823
|
}
|
|
1654
1824
|
}
|
|
1655
1825
|
|
|
1826
|
+
if (exit && matches) {
|
|
1827
|
+
const exitResult = toResult(exit(node, parents, index))
|
|
1828
|
+
|
|
1829
|
+
if (exitResult[0] === SKIP) {
|
|
1830
|
+
throw new Error(
|
|
1831
|
+
'Unexpected value `' +
|
|
1832
|
+
exitResult[0] +
|
|
1833
|
+
'` from `exit`, expected `CONTINUE`, `EXIT`, index, or nothing'
|
|
1834
|
+
)
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
// Prefer a result from `exit` over `enter`.
|
|
1838
|
+
if (exitResult[0] === EXIT || typeof exitResult[1] === 'number') {
|
|
1839
|
+
return exitResult
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1656
1843
|
return result
|
|
1657
1844
|
}
|
|
1658
1845
|
}
|
|
@@ -1681,7 +1868,13 @@ function toResult(value) {
|
|
|
1681
1868
|
;// ../node_modules/unist-util-visit/lib/index.js
|
|
1682
1869
|
/**
|
|
1683
1870
|
* @import {Node as UnistNode, Parent as UnistParent} from 'unist'
|
|
1684
|
-
* @import {
|
|
1871
|
+
* @import {
|
|
1872
|
+
* InclusiveDescendant,
|
|
1873
|
+
* Matches,
|
|
1874
|
+
* Visitors as ParentsVisitors,
|
|
1875
|
+
* VisitorResult,
|
|
1876
|
+
* VisitorResultExit
|
|
1877
|
+
* } from 'unist-util-visit-parents'
|
|
1685
1878
|
*/
|
|
1686
1879
|
|
|
1687
1880
|
/**
|
|
@@ -1693,67 +1886,6 @@ function toResult(value) {
|
|
|
1693
1886
|
* which doesn’t work when publishing on npm.
|
|
1694
1887
|
*/
|
|
1695
1888
|
|
|
1696
|
-
// To do: use types from `unist-util-visit-parents` when it’s released.
|
|
1697
|
-
|
|
1698
|
-
/**
|
|
1699
|
-
* @typedef {(
|
|
1700
|
-
* Fn extends (value: any) => value is infer Thing
|
|
1701
|
-
* ? Thing
|
|
1702
|
-
* : Fallback
|
|
1703
|
-
* )} Predicate
|
|
1704
|
-
* Get the value of a type guard `Fn`.
|
|
1705
|
-
* @template Fn
|
|
1706
|
-
* Value; typically function that is a type guard (such as `(x): x is Y`).
|
|
1707
|
-
* @template Fallback
|
|
1708
|
-
* Value to yield if `Fn` is not a type guard.
|
|
1709
|
-
*/
|
|
1710
|
-
|
|
1711
|
-
/**
|
|
1712
|
-
* @typedef {(
|
|
1713
|
-
* Check extends null | undefined // No test.
|
|
1714
|
-
* ? Value
|
|
1715
|
-
* : Value extends {type: Check} // String (type) test.
|
|
1716
|
-
* ? Value
|
|
1717
|
-
* : Value extends Check // Partial test.
|
|
1718
|
-
* ? Value
|
|
1719
|
-
* : Check extends Function // Function test.
|
|
1720
|
-
* ? Predicate<Check, Value> extends Value
|
|
1721
|
-
* ? Predicate<Check, Value>
|
|
1722
|
-
* : never
|
|
1723
|
-
* : never // Some other test?
|
|
1724
|
-
* )} MatchesOne
|
|
1725
|
-
* Check whether a node matches a primitive check in the type system.
|
|
1726
|
-
* @template Value
|
|
1727
|
-
* Value; typically unist `Node`.
|
|
1728
|
-
* @template Check
|
|
1729
|
-
* Value; typically `unist-util-is`-compatible test, but not arrays.
|
|
1730
|
-
*/
|
|
1731
|
-
|
|
1732
|
-
/**
|
|
1733
|
-
* @typedef {(
|
|
1734
|
-
* Check extends ReadonlyArray<any>
|
|
1735
|
-
* ? MatchesOne<Value, Check[number]>
|
|
1736
|
-
* : MatchesOne<Value, Check>
|
|
1737
|
-
* )} Matches
|
|
1738
|
-
* Check whether a node matches a check in the type system.
|
|
1739
|
-
* @template Value
|
|
1740
|
-
* Value; typically unist `Node`.
|
|
1741
|
-
* @template Check
|
|
1742
|
-
* Value; typically `unist-util-is`-compatible test.
|
|
1743
|
-
*/
|
|
1744
|
-
|
|
1745
|
-
/**
|
|
1746
|
-
* @typedef {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} Uint
|
|
1747
|
-
* Number; capped reasonably.
|
|
1748
|
-
*/
|
|
1749
|
-
|
|
1750
|
-
/**
|
|
1751
|
-
* @typedef {I extends 0 ? 1 : I extends 1 ? 2 : I extends 2 ? 3 : I extends 3 ? 4 : I extends 4 ? 5 : I extends 5 ? 6 : I extends 6 ? 7 : I extends 7 ? 8 : I extends 8 ? 9 : 10} Increment
|
|
1752
|
-
* Increment a number in the type system.
|
|
1753
|
-
* @template {Uint} [I=0]
|
|
1754
|
-
* Index.
|
|
1755
|
-
*/
|
|
1756
|
-
|
|
1757
1889
|
/**
|
|
1758
1890
|
* @typedef {(
|
|
1759
1891
|
* Node extends UnistParent
|
|
@@ -1779,89 +1911,64 @@ function toResult(value) {
|
|
|
1779
1911
|
*/
|
|
1780
1912
|
|
|
1781
1913
|
/**
|
|
1782
|
-
* @
|
|
1783
|
-
*
|
|
1784
|
-
* ? never
|
|
1785
|
-
* :
|
|
1786
|
-
* | InternalParent<Node, Child>
|
|
1787
|
-
* | InternalAncestor<Node, InternalParent<Node, Child>, Max, Increment<Depth>>
|
|
1788
|
-
* )} InternalAncestor
|
|
1789
|
-
* Collect nodes in `Tree` that can be ancestors of `Child`.
|
|
1790
|
-
* @template {UnistNode} Node
|
|
1791
|
-
* All node types in a tree.
|
|
1792
|
-
* @template {UnistNode} Child
|
|
1793
|
-
* Node to search for.
|
|
1794
|
-
* @template {Uint} [Max=10]
|
|
1795
|
-
* Max; searches up to this depth.
|
|
1796
|
-
* @template {Uint} [Depth=0]
|
|
1797
|
-
* Current depth.
|
|
1798
|
-
*/
|
|
1799
|
-
|
|
1800
|
-
/**
|
|
1801
|
-
* @typedef {(
|
|
1802
|
-
* Tree extends UnistParent
|
|
1803
|
-
* ? Depth extends Max
|
|
1804
|
-
* ? Tree
|
|
1805
|
-
* : Tree | InclusiveDescendant<Tree['children'][number], Max, Increment<Depth>>
|
|
1806
|
-
* : Tree
|
|
1807
|
-
* )} InclusiveDescendant
|
|
1808
|
-
* Collect all (inclusive) descendants of `Tree`.
|
|
1914
|
+
* @callback Visitor
|
|
1915
|
+
* Handle a node (matching `test`, if given) before its children.
|
|
1809
1916
|
*
|
|
1810
|
-
*
|
|
1811
|
-
*
|
|
1812
|
-
*
|
|
1813
|
-
*
|
|
1814
|
-
*
|
|
1815
|
-
*
|
|
1816
|
-
*
|
|
1817
|
-
*
|
|
1818
|
-
*
|
|
1819
|
-
*
|
|
1820
|
-
* @
|
|
1821
|
-
*
|
|
1822
|
-
* @template {
|
|
1823
|
-
*
|
|
1917
|
+
* Like `Visitor` in `unist-util-visit-parents`,
|
|
1918
|
+
* but with `index` and `parent` instead of `parents`.
|
|
1919
|
+
* @param {Visited} node
|
|
1920
|
+
* Found node.
|
|
1921
|
+
* @param {Visited extends UnistNode ? number | undefined : never} index
|
|
1922
|
+
* Index of `node` in `parent`,
|
|
1923
|
+
* or `undefined` for the tree itself.
|
|
1924
|
+
* @param {Ancestor extends UnistParent ? Ancestor | undefined : never} parent
|
|
1925
|
+
* Parent of `node`,
|
|
1926
|
+
* or `undefined` for the tree itself.
|
|
1927
|
+
* @returns {VisitorResult}
|
|
1928
|
+
* What to do next.
|
|
1929
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
1930
|
+
* Visited node type.
|
|
1931
|
+
* @template {UnistParent} [Ancestor=UnistParent]
|
|
1932
|
+
* Ancestor type.
|
|
1824
1933
|
*/
|
|
1825
1934
|
|
|
1826
1935
|
/**
|
|
1827
|
-
* @callback
|
|
1828
|
-
* Handle a node (matching `test`, if given).
|
|
1829
|
-
*
|
|
1830
|
-
* Visitors are free to transform `node`.
|
|
1831
|
-
* They can also transform `parent`.
|
|
1936
|
+
* @callback VisitorExit
|
|
1937
|
+
* Handle a node (matching `test`, if given) after its children.
|
|
1832
1938
|
*
|
|
1833
|
-
*
|
|
1834
|
-
*
|
|
1835
|
-
*
|
|
1836
|
-
* When adding or removing previous siblings of `node` (or next siblings, in
|
|
1837
|
-
* case of reverse), the `Visitor` should return a new `Index` to specify the
|
|
1838
|
-
* sibling to traverse after `node` is traversed.
|
|
1839
|
-
* Adding or removing next siblings of `node` (or previous siblings, in case
|
|
1840
|
-
* of reverse) is handled as expected without needing to return a new `Index`.
|
|
1841
|
-
*
|
|
1842
|
-
* Removing the children property of `parent` still results in them being
|
|
1843
|
-
* traversed.
|
|
1939
|
+
* Like `VisitorExit` in `unist-util-visit-parents`,
|
|
1940
|
+
* but with `index` and `parent` instead of `parents`.
|
|
1844
1941
|
* @param {Visited} node
|
|
1845
1942
|
* Found node.
|
|
1846
1943
|
* @param {Visited extends UnistNode ? number | undefined : never} index
|
|
1847
|
-
* Index of `node` in `parent
|
|
1944
|
+
* Index of `node` in `parent`,
|
|
1945
|
+
* or `undefined` for the tree itself.
|
|
1848
1946
|
* @param {Ancestor extends UnistParent ? Ancestor | undefined : never} parent
|
|
1849
|
-
* Parent of `node
|
|
1850
|
-
*
|
|
1947
|
+
* Parent of `node`,
|
|
1948
|
+
* or `undefined` for the tree itself.
|
|
1949
|
+
* @returns {VisitorResultExit}
|
|
1851
1950
|
* What to do next.
|
|
1852
|
-
*
|
|
1853
|
-
* An `Index` is treated as a tuple of `[CONTINUE, Index]`.
|
|
1854
|
-
* An `Action` is treated as a tuple of `[Action]`.
|
|
1855
|
-
*
|
|
1856
|
-
* Passing a tuple back only makes sense if the `Action` is `SKIP`.
|
|
1857
|
-
* When the `Action` is `EXIT`, that action can be returned.
|
|
1858
|
-
* When the `Action` is `CONTINUE`, `Index` can be returned.
|
|
1859
1951
|
* @template {UnistNode} [Visited=UnistNode]
|
|
1860
1952
|
* Visited node type.
|
|
1861
1953
|
* @template {UnistParent} [Ancestor=UnistParent]
|
|
1862
1954
|
* Ancestor type.
|
|
1863
1955
|
*/
|
|
1864
1956
|
|
|
1957
|
+
/**
|
|
1958
|
+
* @template {UnistNode} [Visited=UnistNode]
|
|
1959
|
+
* Visited node type.
|
|
1960
|
+
* @template {UnistParent} [Ancestor=UnistParent]
|
|
1961
|
+
* Ancestor type.
|
|
1962
|
+
* @typedef Visitors
|
|
1963
|
+
* Handle nodes when entering and exiting them.
|
|
1964
|
+
*
|
|
1965
|
+
* Like `Visitors` in `unist-util-visit-parents`.
|
|
1966
|
+
* @property {Visitor<Visited, Ancestor> | null | undefined} [enter]
|
|
1967
|
+
* Handle a node before its children (optional).
|
|
1968
|
+
* @property {VisitorExit<Visited, Ancestor>} exit
|
|
1969
|
+
* Handle a node after its children.
|
|
1970
|
+
*/
|
|
1971
|
+
|
|
1865
1972
|
/**
|
|
1866
1973
|
* @typedef {Visitor<Visited, Parent<Ancestor, Visited>>} BuildVisitorFromMatch
|
|
1867
1974
|
* Build a typed `Visitor` function from a node and all possible parents.
|
|
@@ -1905,6 +2012,25 @@ function toResult(value) {
|
|
|
1905
2012
|
* Test type.
|
|
1906
2013
|
*/
|
|
1907
2014
|
|
|
2015
|
+
/**
|
|
2016
|
+
* @typedef {(
|
|
2017
|
+
* Visitors<
|
|
2018
|
+
* Matches<InclusiveDescendant<Tree>, Check>,
|
|
2019
|
+
* Parent<
|
|
2020
|
+
* Extract<InclusiveDescendant<Tree>, UnistParent>,
|
|
2021
|
+
* Matches<InclusiveDescendant<Tree>, Check>
|
|
2022
|
+
* >
|
|
2023
|
+
* >
|
|
2024
|
+
* )} BuildVisitors
|
|
2025
|
+
* Build typed `Visitors` from a tree and a test.
|
|
2026
|
+
*
|
|
2027
|
+
* It will infer which values are passed as `node` and which as `parent`.
|
|
2028
|
+
* @template {UnistNode} [Tree=UnistNode]
|
|
2029
|
+
* Node type.
|
|
2030
|
+
* @template {Test} [Check=Test]
|
|
2031
|
+
* Test type.
|
|
2032
|
+
*/
|
|
2033
|
+
|
|
1908
2034
|
|
|
1909
2035
|
|
|
1910
2036
|
|
|
@@ -1913,10 +2039,13 @@ function toResult(value) {
|
|
|
1913
2039
|
* Visit nodes.
|
|
1914
2040
|
*
|
|
1915
2041
|
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
|
1916
|
-
* (**NLR**) or if `reverse` is given,
|
|
2042
|
+
* (**NLR**) or if `reverse` is given,
|
|
2043
|
+
* in *reverse preorder* (**NRL**).
|
|
2044
|
+
* An `exit` visitor is called in *postorder* (**LRN**)
|
|
2045
|
+
* or if `reverse` is given, in *reverse postorder* (**RLN**).
|
|
1917
2046
|
*
|
|
1918
|
-
* You can choose
|
|
1919
|
-
* For complex tests, you should test yourself in
|
|
2047
|
+
* You can choose which nodes are visited by passing a `test`.
|
|
2048
|
+
* For complex tests, you should test yourself in a visitor, as it will be
|
|
1920
2049
|
* faster and will have improved type information.
|
|
1921
2050
|
*
|
|
1922
2051
|
* Walking the tree is an intensive task.
|
|
@@ -1925,29 +2054,48 @@ function toResult(value) {
|
|
|
1925
2054
|
* to check if a node matches, and then perform different operations.
|
|
1926
2055
|
*
|
|
1927
2056
|
* You can change the tree.
|
|
1928
|
-
*
|
|
2057
|
+
* Changes inside a node made when entering it are walked,
|
|
2058
|
+
* changes made when exiting it are not.
|
|
2059
|
+
* See `Visitor` and `VisitorExit` for more info.
|
|
1929
2060
|
*
|
|
1930
2061
|
* @overload
|
|
1931
2062
|
* @param {Tree} tree
|
|
2063
|
+
* Tree to traverse.
|
|
1932
2064
|
* @param {Check} check
|
|
1933
|
-
*
|
|
2065
|
+
* `unist-util-is`-compatible test.
|
|
2066
|
+
* @param {BuildVisitor<Tree, Check> | BuildVisitors<Tree, Check>} visitors
|
|
2067
|
+
* Handle each node when entering it,
|
|
2068
|
+
* or `{enter, exit}` to also handle it when exiting it.
|
|
1934
2069
|
* @param {boolean | null | undefined} [reverse]
|
|
2070
|
+
* Walk children from last to first;
|
|
2071
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
2072
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
1935
2073
|
* @returns {undefined}
|
|
2074
|
+
* Nothing.
|
|
1936
2075
|
*
|
|
1937
2076
|
* @overload
|
|
1938
2077
|
* @param {Tree} tree
|
|
1939
|
-
*
|
|
2078
|
+
* Tree to traverse.
|
|
2079
|
+
* @param {BuildVisitor<Tree> | BuildVisitors<Tree>} visitors
|
|
2080
|
+
* Handle each node when entering it,
|
|
2081
|
+
* or `{enter, exit}` to also handle it when exiting it.
|
|
1940
2082
|
* @param {boolean | null | undefined} [reverse]
|
|
2083
|
+
* Walk children from last to first;
|
|
2084
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
2085
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
1941
2086
|
* @returns {undefined}
|
|
2087
|
+
* Nothing.
|
|
1942
2088
|
*
|
|
1943
2089
|
* @param {UnistNode} tree
|
|
1944
2090
|
* Tree to traverse.
|
|
1945
|
-
* @param {Visitor | Test}
|
|
1946
|
-
* `unist-util-is`-compatible test
|
|
1947
|
-
* @param {Visitor | boolean | null | undefined} [
|
|
1948
|
-
*
|
|
1949
|
-
* @param {boolean | null | undefined} [maybeReverse
|
|
1950
|
-
*
|
|
2091
|
+
* @param {Visitor | Visitors | Test} testOrEnterOrVisitors
|
|
2092
|
+
* `unist-util-is`-compatible test, `enter`, or `visitors`.
|
|
2093
|
+
* @param {Visitor | Visitors | boolean | null | undefined} [enterOrVisitorsOrReverse]
|
|
2094
|
+
* `enter`, `visitors`, or `reverse` after a test.
|
|
2095
|
+
* @param {boolean | null | undefined} [maybeReverse]
|
|
2096
|
+
* Walk children from last to first;
|
|
2097
|
+
* for `enter`, reverse preorder (NRL) instead of preorder (NLR);
|
|
2098
|
+
* for `exit`, reverse postorder (RLN) instead of postorder (LRN).
|
|
1951
2099
|
* @returns {undefined}
|
|
1952
2100
|
* Nothing.
|
|
1953
2101
|
*
|
|
@@ -1956,39 +2104,90 @@ function toResult(value) {
|
|
|
1956
2104
|
* @template {Test} Check
|
|
1957
2105
|
* `unist-util-is`-compatible test.
|
|
1958
2106
|
*/
|
|
1959
|
-
function visit(
|
|
2107
|
+
function visit(
|
|
2108
|
+
tree,
|
|
2109
|
+
testOrEnterOrVisitors,
|
|
2110
|
+
enterOrVisitorsOrReverse,
|
|
2111
|
+
maybeReverse
|
|
2112
|
+
) {
|
|
2113
|
+
/** @type {Test} */
|
|
2114
|
+
let check
|
|
2115
|
+
/** @type {Visitor | Visitors} */
|
|
2116
|
+
let visitors
|
|
1960
2117
|
/** @type {boolean | null | undefined} */
|
|
1961
2118
|
let reverse
|
|
1962
|
-
/** @type {Test} */
|
|
1963
|
-
let test
|
|
1964
|
-
/** @type {Visitor} */
|
|
1965
|
-
let visitor
|
|
1966
2119
|
|
|
2120
|
+
// Third parameter is an enter visitor or a visitors object, so expect a `test` too.
|
|
1967
2121
|
if (
|
|
1968
|
-
typeof
|
|
1969
|
-
typeof
|
|
2122
|
+
typeof enterOrVisitorsOrReverse === 'function' ||
|
|
2123
|
+
(enterOrVisitorsOrReverse && typeof enterOrVisitorsOrReverse === 'object')
|
|
1970
2124
|
) {
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
reverse = visitorOrReverse
|
|
1974
|
-
} else {
|
|
1975
|
-
// @ts-expect-error: assume the overload with test was given.
|
|
1976
|
-
test = testOrVisitor
|
|
1977
|
-
// @ts-expect-error: assume the overload with test was given.
|
|
1978
|
-
visitor = visitorOrReverse
|
|
2125
|
+
check = /** @type {Test} */ (testOrEnterOrVisitors)
|
|
2126
|
+
visitors = enterOrVisitorsOrReverse
|
|
1979
2127
|
reverse = maybeReverse
|
|
1980
2128
|
}
|
|
2129
|
+
// Assume no test.
|
|
2130
|
+
else {
|
|
2131
|
+
visitors = /** @type {Visitor | Visitors} */ (testOrEnterOrVisitors)
|
|
2132
|
+
reverse = enterOrVisitorsOrReverse
|
|
2133
|
+
}
|
|
1981
2134
|
|
|
1982
|
-
|
|
2135
|
+
if (typeof visitors === 'function') {
|
|
2136
|
+
visitParents(tree, check, wrap(visitors), reverse)
|
|
2137
|
+
} else {
|
|
2138
|
+
visitParents(tree, check, wrapVisitors(visitors), reverse)
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2142
|
+
/**
|
|
2143
|
+
* Turn `visit` visitors into `visitParents` visitors.
|
|
2144
|
+
*
|
|
2145
|
+
* @param {Visitors} visitors
|
|
2146
|
+
* Visitors for `visit`.
|
|
2147
|
+
* @returns {ParentsVisitors}
|
|
2148
|
+
* Visitors for `visitParents`.
|
|
2149
|
+
*/
|
|
2150
|
+
function wrapVisitors(visitors) {
|
|
2151
|
+
// Pass anything else straight to `visitParents` to get its errors.
|
|
2152
|
+
if (!visitors || typeof visitors !== 'object') return visitors
|
|
2153
|
+
|
|
2154
|
+
return {
|
|
2155
|
+
enter:
|
|
2156
|
+
typeof visitors.enter === 'function'
|
|
2157
|
+
? wrap(visitors.enter)
|
|
2158
|
+
: visitors.enter,
|
|
2159
|
+
exit:
|
|
2160
|
+
typeof visitors.exit === 'function' ? wrap(visitors.exit) : visitors.exit
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
/**
|
|
2165
|
+
* Turn a `visit` visitor into a `visitParents` one.
|
|
2166
|
+
*
|
|
2167
|
+
* @template {VisitorResult} Result
|
|
2168
|
+
* Result type.
|
|
2169
|
+
* @param {(node: UnistNode, index: number | undefined, parent: UnistParent | undefined) => Result} visitor
|
|
2170
|
+
* Visitor for `visit`.
|
|
2171
|
+
* @returns {(node: UnistNode, parents: Array<UnistParent>, index: number | undefined) => Result}
|
|
2172
|
+
* Visitor for `visitParents`.
|
|
2173
|
+
*/
|
|
2174
|
+
function wrap(visitor) {
|
|
2175
|
+
return overload
|
|
1983
2176
|
|
|
1984
2177
|
/**
|
|
2178
|
+
* Call `visitor` with `index` and `parent` instead of `parents`.
|
|
2179
|
+
*
|
|
1985
2180
|
* @param {UnistNode} node
|
|
2181
|
+
* Visited node.
|
|
1986
2182
|
* @param {Array<UnistParent>} parents
|
|
2183
|
+
* Ancestors of `node`.
|
|
2184
|
+
* @param {number | undefined} index
|
|
2185
|
+
* Index of `node` in its parent.
|
|
2186
|
+
* @returns {Result}
|
|
2187
|
+
* What to do next.
|
|
1987
2188
|
*/
|
|
1988
|
-
function overload(node, parents) {
|
|
1989
|
-
|
|
1990
|
-
const index = parent ? parent.children.indexOf(node) : undefined
|
|
1991
|
-
return visitor(node, index, parent)
|
|
2189
|
+
function overload(node, parents, index) {
|
|
2190
|
+
return visitor(node, index, parents[parents.length - 1])
|
|
1992
2191
|
}
|
|
1993
2192
|
}
|
|
1994
2193
|
|
|
@@ -60673,7 +60872,7 @@ function state_createState(tree, options) {
|
|
|
60673
60872
|
one,
|
|
60674
60873
|
options: settings,
|
|
60675
60874
|
patch: state_patch,
|
|
60676
|
-
wrap
|
|
60875
|
+
wrap: state_wrap
|
|
60677
60876
|
}
|
|
60678
60877
|
|
|
60679
60878
|
visit(tree, function (node) {
|
|
@@ -60887,7 +61086,7 @@ function defaultUnknownHandler(state, node) {
|
|
|
60887
61086
|
* @returns {Array<HastText | Type>}
|
|
60888
61087
|
* Wrapped nodes.
|
|
60889
61088
|
*/
|
|
60890
|
-
function
|
|
61089
|
+
function state_wrap(nodes, loose) {
|
|
60891
61090
|
/** @type {Array<HastText | Type>} */
|
|
60892
61091
|
const result = []
|
|
60893
61092
|
let index = -1
|
|
@@ -64824,7 +65023,7 @@ function escapeStringRegexp(string) {
|
|
|
64824
65023
|
* @param {FindAndReplaceList | FindAndReplaceTuple} list
|
|
64825
65024
|
* Patterns to find.
|
|
64826
65025
|
* @param {Options | null | undefined} [options]
|
|
64827
|
-
* Configuration (
|
|
65026
|
+
* Configuration (optional).
|
|
64828
65027
|
* @returns {undefined}
|
|
64829
65028
|
* Nothing.
|
|
64830
65029
|
*/
|
|
@@ -64835,40 +65034,20 @@ function findAndReplace(tree, list, options) {
|
|
|
64835
65034
|
let pairIndex = -1
|
|
64836
65035
|
|
|
64837
65036
|
while (++pairIndex < pairs.length) {
|
|
64838
|
-
visitParents(tree,
|
|
65037
|
+
visitParents(tree, visitor)
|
|
64839
65038
|
}
|
|
64840
65039
|
|
|
64841
65040
|
/**
|
|
64842
|
-
*
|
|
65041
|
+
* Handle text nodes and skip ignored nodes.
|
|
64843
65042
|
*
|
|
64844
|
-
* @type {BuildVisitor<Root
|
|
65043
|
+
* @type {BuildVisitor<Root>}
|
|
64845
65044
|
*/
|
|
64846
|
-
function visitor(node, parents) {
|
|
64847
|
-
|
|
64848
|
-
|
|
64849
|
-
let grandparent
|
|
64850
|
-
|
|
64851
|
-
while (++index < parents.length) {
|
|
64852
|
-
const parent = parents[index]
|
|
64853
|
-
/** @type {Array<Nodes> | undefined} */
|
|
64854
|
-
const siblings = grandparent ? grandparent.children : undefined
|
|
64855
|
-
|
|
64856
|
-
if (
|
|
64857
|
-
ignored(
|
|
64858
|
-
parent,
|
|
64859
|
-
siblings ? siblings.indexOf(parent) : undefined,
|
|
64860
|
-
grandparent
|
|
64861
|
-
)
|
|
64862
|
-
) {
|
|
64863
|
-
return
|
|
64864
|
-
}
|
|
64865
|
-
|
|
64866
|
-
grandparent = parent
|
|
65045
|
+
function visitor(node, parents, index) {
|
|
65046
|
+
if (node.type === 'text' && typeof index === 'number') {
|
|
65047
|
+
return handler(node, parents, index)
|
|
64867
65048
|
}
|
|
64868
65049
|
|
|
64869
|
-
if (
|
|
64870
|
-
return handler(node, parents)
|
|
64871
|
-
}
|
|
65050
|
+
if (ignored(node, index, parents[parents.length - 1])) return (/* inlined export .SKIP */"skip")
|
|
64872
65051
|
}
|
|
64873
65052
|
|
|
64874
65053
|
/**
|
|
@@ -64878,17 +65057,16 @@ function findAndReplace(tree, list, options) {
|
|
|
64878
65057
|
* Text node to search in.
|
|
64879
65058
|
* @param {Array<Parents>} parents
|
|
64880
65059
|
* Ancestors of `node`.
|
|
65060
|
+
* @param {number} index
|
|
65061
|
+
* Index of `node` in its parent.
|
|
64881
65062
|
* @returns {VisitorResult}
|
|
64882
65063
|
* Where to continue visiting.
|
|
64883
65064
|
*/
|
|
64884
|
-
function handler(node, parents) {
|
|
65065
|
+
function handler(node, parents, index) {
|
|
64885
65066
|
const parent = parents[parents.length - 1]
|
|
64886
65067
|
const find = pairs[pairIndex][0]
|
|
64887
65068
|
const replace = pairs[pairIndex][1]
|
|
64888
65069
|
let start = 0
|
|
64889
|
-
/** @type {Array<Nodes>} */
|
|
64890
|
-
const siblings = parent.children
|
|
64891
|
-
const index = siblings.indexOf(node)
|
|
64892
65070
|
let change = false
|
|
64893
65071
|
/** @type {Array<PhrasingContent>} */
|
|
64894
65072
|
let nodes = []
|
|
@@ -64987,12 +65165,10 @@ function toPairs(tupleOrList) {
|
|
|
64987
65165
|
/** @type {Pairs} */
|
|
64988
65166
|
const result = []
|
|
64989
65167
|
|
|
64990
|
-
/** @type {FindAndReplaceList} */
|
|
64991
|
-
// @ts-expect-error: correct.
|
|
64992
65168
|
const list =
|
|
64993
65169
|
!tupleOrList[0] || Array.isArray(tupleOrList[0])
|
|
64994
|
-
? tupleOrList
|
|
64995
|
-
: [tupleOrList]
|
|
65170
|
+
? /** @type {FindAndReplaceList} */ (tupleOrList)
|
|
65171
|
+
: [/** @type {FindAndReplaceTuple} */ (tupleOrList)]
|
|
64996
65172
|
|
|
64997
65173
|
let index = -1
|
|
64998
65174
|
|
|
@@ -77626,7 +77802,7 @@ var commands_getCommands=function getCommands(){return[bold,italic,strikeThrough
|
|
|
77626
77802
|
* `9` - `Tab`
|
|
77627
77803
|
*/if(!defaultTabEnable&&e.code&&e.code.toLowerCase()==='tab'){stopPropagation(e);var space=new Array(tabSize+1).join(' ');if(target.selectionStart!==target.selectionEnd){var _star=target.value.substring(0,target.selectionStart).split('\n');var _end=target.value.substring(0,target.selectionEnd).split('\n');var modifiedTextLine=[];_end.forEach(function(item,idx){if(item!==_star[idx]){modifiedTextLine.push(item);}});var modifiedText=modifiedTextLine.join('\n');var oldSelectText=target.value.substring(target.selectionStart,target.selectionEnd);var newStarNum=target.value.substring(0,target.selectionStart).length;textArea.setSelectionRange({start:target.value.indexOf(modifiedText),end:target.selectionEnd});var modifiedTextObj=insertBeforeEachLine(modifiedText,e.shiftKey?'':space);var text=modifiedTextObj.modifiedText;if(e.shiftKey){text=text.split('\n').map(function(item){return item.replace(new RegExp("^".concat(space)),'');}).join('\n');}textArea.replaceSelection(text);var startTabSize=e.shiftKey?-tabSize:tabSize;var endTabSize=e.shiftKey?-modifiedTextLine.length*tabSize:modifiedTextLine.length*tabSize;textArea.setSelectionRange({start:newStarNum+startTabSize,end:newStarNum+oldSelectText.length+endTabSize});}else{return insertTextAtPosition(target,space);}}else if(e.keyCode===13&&e.code.toLowerCase()==='enter'&&(/^(-|\*)\s/.test(currentLineStr)||/^\d+\.\s/.test(currentLineStr))&&!e.shiftKey){/**
|
|
77628
77804
|
* `13` - `Enter`
|
|
77629
|
-
*/stopPropagation(e);var startStr='\n- ';if(currentLineStr.startsWith('*')){startStr='\n* ';}if(currentLineStr.startsWith('- [ ]')||currentLineStr.startsWith('- [X]')||currentLineStr.startsWith('- [x]')){startStr='\n- [ ] ';}if(/^\d+\.\s/.test(currentLineStr)){startStr="\n".concat(parseInt(currentLineStr)+1,". ");}return insertTextAtPosition(target,startStr);}else if(e.code&&e.code.toLowerCase()==='keyd'&&e.ctrlKey){// Duplicate lines
|
|
77805
|
+
*/stopPropagation(e);var atEndOfLine=target.selectionEnd===target.value.length||target.value[target.selectionEnd]==='\n';var emptyListItem=/^(?:[-*]|\d+\.)\s+$/.test(currentLineStr)||/^- \[[ xX]\]\s*$/.test(currentLineStr);if(target.selectionStart===target.selectionEnd&&atEndOfLine&&emptyListItem){textArea.setSelectionRange({start:target.selectionStart-currentLineStr.length,end:target.selectionEnd});return insertTextAtPosition(target,'');}var startStr='\n- ';if(currentLineStr.startsWith('*')){startStr='\n* ';}if(currentLineStr.startsWith('- [ ]')||currentLineStr.startsWith('- [X]')||currentLineStr.startsWith('- [x]')){startStr='\n- [ ] ';}if(/^\d+\.\s/.test(currentLineStr)){startStr="\n".concat(parseInt(currentLineStr)+1,". ");}return insertTextAtPosition(target,startStr);}else if(e.code&&e.code.toLowerCase()==='keyd'&&e.ctrlKey){// Duplicate lines
|
|
77630
77806
|
stopPropagation(e);var selection={start:target.selectionStart,end:target.selectionEnd};var savedSelection=selection;selection=selectLine({text:target.value,selection:selection});var textToDuplicate=target.value.slice(selection.start,selection.end);textArea.setSelectionRange({start:selection.end,end:selection.end});insertTextAtPosition(target,"\n".concat(textToDuplicate));textArea.setSelectionRange({start:savedSelection.start,end:savedSelection.end});}else if(e.code&&e.code.toLowerCase()==='arrowup'&&e.altKey){handleLineMove(e,-1);}else if(e.code&&e.code.toLowerCase()==='arrowdown'&&e.altKey){handleLineMove(e,1);}}
|
|
77631
77807
|
;// ./src/components/TextArea/index.less
|
|
77632
77808
|
// extracted by mini-css-extract-plugin
|