slate 0.67.1 → 0.70.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/CHANGELOG.md +10 -0
- package/dist/index.es.js +71 -130
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +78 -136
- package/dist/index.js.map +1 -1
- package/dist/slate.js +78 -136
- package/dist/slate.min.js +2 -2
- package/dist/transforms/node.d.ts +1 -1
- package/dist/transforms/node.d.ts.map +1 -1
- package/dist/utils/string.d.ts +0 -3
- package/dist/utils/string.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/slate.js
CHANGED
|
@@ -1494,21 +1494,47 @@
|
|
|
1494
1494
|
* Get the distance to the end of the first character in a string of text.
|
|
1495
1495
|
*/
|
|
1496
1496
|
|
|
1497
|
+
var CodepointType;
|
|
1498
|
+
|
|
1499
|
+
(function (CodepointType) {
|
|
1500
|
+
// ZWJ sequences consist of multiple emojis separated by ZWJ character. They
|
|
1501
|
+
// are used to combine multiple emojis into one emoji.
|
|
1502
|
+
// https://en.wikipedia.org/wiki/Zero-width_joiner
|
|
1503
|
+
CodepointType[CodepointType["ZeroWidthJoiner"] = 0] = "ZeroWidthJoiner"; // Kecap sequences consit of a digit, an asterisk or a number sign followed by
|
|
1504
|
+
// the Combining Enclosing Keycap character. They are used to create emoji
|
|
1505
|
+
// with a keycap appearance. https://emojipedia.org/emoji-keycap-sequence
|
|
1506
|
+
|
|
1507
|
+
CodepointType[CodepointType["Keycap"] = 1] = "Keycap"; // Modifiers are used in ZWJ sequences to apply a skin tone to an emoji.
|
|
1508
|
+
// https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)#Emoji_modifiers
|
|
1509
|
+
|
|
1510
|
+
CodepointType[CodepointType["Modifier"] = 2] = "Modifier"; // Variation selectors are used to specify if a character should be displayed
|
|
1511
|
+
// as text or as an emoji.
|
|
1512
|
+
|
|
1513
|
+
CodepointType[CodepointType["VariationSelector"] = 3] = "VariationSelector"; // Flag sequences consist of a pair of regional indicators.
|
|
1514
|
+
// https://en.wikipedia.org/wiki/Regional_indicator_symbol
|
|
1515
|
+
|
|
1516
|
+
CodepointType[CodepointType["RegionalIndicator"] = 4] = "RegionalIndicator"; // Tag sequences consist of a Black Flag emoji followed by a series of Tag
|
|
1517
|
+
// codepoints, then the Cancel Tag codepoint.
|
|
1518
|
+
// https://en.wikipedia.org/wiki/Tags_(Unicode_block)
|
|
1519
|
+
|
|
1520
|
+
CodepointType[CodepointType["Tag"] = 5] = "Tag";
|
|
1521
|
+
CodepointType[CodepointType["Character"] = 6] = "Character";
|
|
1522
|
+
})(CodepointType || (CodepointType = {}));
|
|
1523
|
+
|
|
1497
1524
|
var getCharacterDistance = function getCharacterDistance(str) {
|
|
1498
1525
|
var isRTL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1526
|
+
var codepoints = isRTL ? codepointsIteratorRTL(str) : str;
|
|
1499
1527
|
var isLTR = !isRTL;
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
var prev = null;
|
|
1511
|
-
var codepoints = isLTR ? str : codepointsIteratorRTL(str);
|
|
1528
|
+
|
|
1529
|
+
var _ref = isLTR ? [isKeycap, isCombiningEnclosingKeycap, isBlackFlag, isCancelTag] : [isCombiningEnclosingKeycap, isKeycap, isCancelTag, isBlackFlag],
|
|
1530
|
+
_ref2 = _slicedToArray(_ref, 4),
|
|
1531
|
+
isKeycapStart = _ref2[0],
|
|
1532
|
+
isKeycapEnd = _ref2[1],
|
|
1533
|
+
isTagStart = _ref2[2],
|
|
1534
|
+
isTagEnd = _ref2[3];
|
|
1535
|
+
|
|
1536
|
+
var distance = 0;
|
|
1537
|
+
var previousType = null;
|
|
1512
1538
|
|
|
1513
1539
|
var _iterator = _createForOfIteratorHelper$6(codepoints),
|
|
1514
1540
|
_step;
|
|
@@ -1517,120 +1543,81 @@
|
|
|
1517
1543
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1518
1544
|
var codepoint = _step.value;
|
|
1519
1545
|
var code = codepoint.codePointAt(0);
|
|
1520
|
-
if (!code) break;
|
|
1546
|
+
if (!code) break;
|
|
1547
|
+
|
|
1548
|
+
if (isLTR && previousType === CodepointType.VariationSelector && !isZWJ(code) && !isKeycapEnd(code)) {
|
|
1549
|
+
break;
|
|
1550
|
+
}
|
|
1521
1551
|
|
|
1522
1552
|
if (isZWJ(code)) {
|
|
1523
|
-
|
|
1524
|
-
|
|
1553
|
+
distance += codepoint.length;
|
|
1554
|
+
previousType = CodepointType.ZeroWidthJoiner;
|
|
1525
1555
|
continue;
|
|
1526
1556
|
}
|
|
1527
1557
|
|
|
1528
|
-
var _ref = isLTR ? [isKeycap, isCombiningEnclosingKeycap] : [isCombiningEnclosingKeycap, isKeycap],
|
|
1529
|
-
_ref2 = _slicedToArray(_ref, 2),
|
|
1530
|
-
isKeycapStart = _ref2[0],
|
|
1531
|
-
isKeycapEnd = _ref2[1];
|
|
1532
|
-
|
|
1533
1558
|
if (isKeycapStart(code)) {
|
|
1534
|
-
if (
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
dist += codepoint.length;
|
|
1539
|
-
prev = 'KC';
|
|
1559
|
+
if (previousType === CodepointType.Keycap) break;
|
|
1560
|
+
distance += codepoint.length;
|
|
1561
|
+
previousType = CodepointType.Keycap;
|
|
1540
1562
|
continue;
|
|
1541
1563
|
}
|
|
1542
1564
|
|
|
1543
1565
|
if (isKeycapEnd(code)) {
|
|
1544
|
-
|
|
1566
|
+
distance += codepoint.length;
|
|
1545
1567
|
break;
|
|
1546
1568
|
}
|
|
1547
1569
|
|
|
1548
1570
|
if (isVariationSelector(code)) {
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
break;
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
prev = 'VAR';
|
|
1556
|
-
continue;
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
if (isBMPEmoji(code)) {
|
|
1560
|
-
if (isLTR && prev && prev !== 'ZWJ' && prev !== 'VAR') {
|
|
1561
|
-
break;
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
dist += codepoint.length;
|
|
1565
|
-
|
|
1566
|
-
if (isRTL && prev === 'VAR') {
|
|
1567
|
-
break;
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
prev = 'BMP';
|
|
1571
|
+
if (isRTL && previousType === CodepointType.Character) break;
|
|
1572
|
+
distance += codepoint.length;
|
|
1573
|
+
previousType = CodepointType.VariationSelector;
|
|
1571
1574
|
continue;
|
|
1572
1575
|
}
|
|
1573
1576
|
|
|
1574
1577
|
if (isModifier(code)) {
|
|
1575
|
-
|
|
1576
|
-
|
|
1578
|
+
distance += codepoint.length;
|
|
1579
|
+
previousType = CodepointType.Modifier;
|
|
1577
1580
|
continue;
|
|
1578
1581
|
}
|
|
1579
1582
|
|
|
1580
|
-
var _ref3 = isLTR ? [isBlackFlag, isCancelTag] : [isCancelTag, isBlackFlag],
|
|
1581
|
-
_ref4 = _slicedToArray(_ref3, 2),
|
|
1582
|
-
isTagStart = _ref4[0],
|
|
1583
|
-
isTagEnd = _ref4[1];
|
|
1584
|
-
|
|
1585
1583
|
if (isTagStart(code)) {
|
|
1586
|
-
if (
|
|
1587
|
-
|
|
1588
|
-
|
|
1584
|
+
if (previousType === CodepointType.Tag) break;
|
|
1585
|
+
distance += codepoint.length;
|
|
1586
|
+
previousType = CodepointType.Tag;
|
|
1589
1587
|
continue;
|
|
1590
1588
|
}
|
|
1591
1589
|
|
|
1592
|
-
if (
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
if (prev === 'TAG' && isTag(code)) {
|
|
1598
|
-
dist += codepoint.length;
|
|
1599
|
-
continue;
|
|
1600
|
-
}
|
|
1601
|
-
|
|
1602
|
-
if (isRegionalIndicator(code)) {
|
|
1603
|
-
dist += codepoint.length;
|
|
1604
|
-
|
|
1605
|
-
if (prev === 'RI') {
|
|
1590
|
+
if (previousType === CodepointType.Tag) {
|
|
1591
|
+
if (isTagEnd(code)) {
|
|
1592
|
+
distance += codepoint.length;
|
|
1606
1593
|
break;
|
|
1607
1594
|
}
|
|
1608
1595
|
|
|
1609
|
-
|
|
1610
|
-
|
|
1596
|
+
if (isTag(code)) {
|
|
1597
|
+
distance += codepoint.length;
|
|
1598
|
+
continue;
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
break;
|
|
1611
1602
|
}
|
|
1612
1603
|
|
|
1613
|
-
if (
|
|
1614
|
-
|
|
1615
|
-
// sequence.
|
|
1616
|
-
if (prev === 'NSEQ') {
|
|
1604
|
+
if (isRegionalIndicator(code)) {
|
|
1605
|
+
if (previousType && previousType !== CodepointType.RegionalIndicator) {
|
|
1617
1606
|
break;
|
|
1618
1607
|
}
|
|
1619
1608
|
|
|
1620
|
-
|
|
1621
|
-
|
|
1609
|
+
distance += codepoint.length;
|
|
1610
|
+
if (previousType === CodepointType.RegionalIndicator) break;
|
|
1611
|
+
previousType = CodepointType.RegionalIndicator;
|
|
1622
1612
|
continue;
|
|
1623
|
-
} //
|
|
1624
|
-
//
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
if (isLTR && prev === 'MOD') {
|
|
1628
|
-
dist += codepoint.length;
|
|
1629
|
-
break;
|
|
1630
|
-
} // If while loop ever gets here, we're done (e.g latin chars).
|
|
1613
|
+
} // If previous and curent codepoints are regular characters. it means we are
|
|
1614
|
+
// not in a sequence.
|
|
1631
1615
|
|
|
1632
1616
|
|
|
1633
|
-
break;
|
|
1617
|
+
if (previousType === CodepointType.Character) break;
|
|
1618
|
+
distance += codepoint.length;
|
|
1619
|
+
previousType = CodepointType.Character;
|
|
1620
|
+
continue;
|
|
1634
1621
|
}
|
|
1635
1622
|
} catch (err) {
|
|
1636
1623
|
_iterator.e(err);
|
|
@@ -1638,7 +1625,7 @@
|
|
|
1638
1625
|
_iterator.f();
|
|
1639
1626
|
}
|
|
1640
1627
|
|
|
1641
|
-
return
|
|
1628
|
+
return distance || 1;
|
|
1642
1629
|
};
|
|
1643
1630
|
/**
|
|
1644
1631
|
* Get the distance to the end of the first word in a string of text.
|
|
@@ -1759,41 +1746,6 @@
|
|
|
1759
1746
|
var isCombiningEnclosingKeycap = function isCombiningEnclosingKeycap(code) {
|
|
1760
1747
|
return code === 0x20e3;
|
|
1761
1748
|
};
|
|
1762
|
-
/**
|
|
1763
|
-
* Is `code` one of the BMP codes used in emoji sequences.
|
|
1764
|
-
*
|
|
1765
|
-
* https://emojipedia.org/emoji-zwj-sequences/
|
|
1766
|
-
*/
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
var isBMPEmoji = function isBMPEmoji(code) {
|
|
1770
|
-
// This requires tiny bit of maintanance, better ideas?
|
|
1771
|
-
// Fortunately it only happens if new Unicode Standard
|
|
1772
|
-
// is released. Fails gracefully if upkeep lags behind,
|
|
1773
|
-
// same way Slate previously behaved with all emojis.
|
|
1774
|
-
return code === 0x2764 || // heart (❤)
|
|
1775
|
-
code === 0x2642 || // male (♂)
|
|
1776
|
-
code === 0x2640 || // female (♀)
|
|
1777
|
-
code === 0x2620 || // scull (☠)
|
|
1778
|
-
code === 0x2695 || // medical (⚕)
|
|
1779
|
-
code === 0x2708 || // plane (✈️)
|
|
1780
|
-
code === 0x25ef || // large circle (◯)
|
|
1781
|
-
code === 0x2b06 || // up arrow (⬆)
|
|
1782
|
-
code === 0x2197 || // up-right arrow (↗)
|
|
1783
|
-
code === 0x27a1 || // right arrow (➡)
|
|
1784
|
-
code === 0x2198 || // down-right arrow (↘)
|
|
1785
|
-
code === 0x2b07 || // down arrow (⬇)
|
|
1786
|
-
code === 0x2199 || // down-left arrow (↙)
|
|
1787
|
-
code === 0x2b05 || // left arrow (⬅)
|
|
1788
|
-
code === 0x2196 || // up-left arrow (↖)
|
|
1789
|
-
code === 0x2195 || // up-down arrow (↕)
|
|
1790
|
-
code === 0x2194 || // left-right arrow (↔)
|
|
1791
|
-
code === 0x21a9 || // right arrow curving left (↩)
|
|
1792
|
-
code === 0x21aa || // left arrow curving right (↪)
|
|
1793
|
-
code === 0x2934 || // right arrow curving up (⤴)
|
|
1794
|
-
code === 0x2935 // right arrow curving down (⤵)
|
|
1795
|
-
;
|
|
1796
|
-
};
|
|
1797
1749
|
/**
|
|
1798
1750
|
* Is `code` a Regional Indicator.
|
|
1799
1751
|
*
|
|
@@ -1804,16 +1756,6 @@
|
|
|
1804
1756
|
var isRegionalIndicator = function isRegionalIndicator(code) {
|
|
1805
1757
|
return code >= 0x1f1e6 && code <= 0x1f1ff;
|
|
1806
1758
|
};
|
|
1807
|
-
/**
|
|
1808
|
-
* Is `code` from basic multilingual plane.
|
|
1809
|
-
*
|
|
1810
|
-
* https://codepoints.net/basic_multilingual_plane
|
|
1811
|
-
*/
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
var isBMP = function isBMP(code) {
|
|
1815
|
-
return code <= 0xffff;
|
|
1816
|
-
};
|
|
1817
1759
|
/**
|
|
1818
1760
|
* Is `code` a Zero Width Joiner.
|
|
1819
1761
|
*
|