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/index.js
CHANGED
|
@@ -704,21 +704,47 @@ var CHAMELEON = /['\u2018\u2019]/;
|
|
|
704
704
|
* Get the distance to the end of the first character in a string of text.
|
|
705
705
|
*/
|
|
706
706
|
|
|
707
|
+
var CodepointType;
|
|
708
|
+
|
|
709
|
+
(function (CodepointType) {
|
|
710
|
+
// ZWJ sequences consist of multiple emojis separated by ZWJ character. They
|
|
711
|
+
// are used to combine multiple emojis into one emoji.
|
|
712
|
+
// https://en.wikipedia.org/wiki/Zero-width_joiner
|
|
713
|
+
CodepointType[CodepointType["ZeroWidthJoiner"] = 0] = "ZeroWidthJoiner"; // Kecap sequences consit of a digit, an asterisk or a number sign followed by
|
|
714
|
+
// the Combining Enclosing Keycap character. They are used to create emoji
|
|
715
|
+
// with a keycap appearance. https://emojipedia.org/emoji-keycap-sequence
|
|
716
|
+
|
|
717
|
+
CodepointType[CodepointType["Keycap"] = 1] = "Keycap"; // Modifiers are used in ZWJ sequences to apply a skin tone to an emoji.
|
|
718
|
+
// https://en.wikipedia.org/wiki/Emoticons_(Unicode_block)#Emoji_modifiers
|
|
719
|
+
|
|
720
|
+
CodepointType[CodepointType["Modifier"] = 2] = "Modifier"; // Variation selectors are used to specify if a character should be displayed
|
|
721
|
+
// as text or as an emoji.
|
|
722
|
+
|
|
723
|
+
CodepointType[CodepointType["VariationSelector"] = 3] = "VariationSelector"; // Flag sequences consist of a pair of regional indicators.
|
|
724
|
+
// https://en.wikipedia.org/wiki/Regional_indicator_symbol
|
|
725
|
+
|
|
726
|
+
CodepointType[CodepointType["RegionalIndicator"] = 4] = "RegionalIndicator"; // Tag sequences consist of a Black Flag emoji followed by a series of Tag
|
|
727
|
+
// codepoints, then the Cancel Tag codepoint.
|
|
728
|
+
// https://en.wikipedia.org/wiki/Tags_(Unicode_block)
|
|
729
|
+
|
|
730
|
+
CodepointType[CodepointType["Tag"] = 5] = "Tag";
|
|
731
|
+
CodepointType[CodepointType["Character"] = 6] = "Character";
|
|
732
|
+
})(CodepointType || (CodepointType = {}));
|
|
733
|
+
|
|
707
734
|
var getCharacterDistance = function getCharacterDistance(str) {
|
|
708
735
|
var isRTL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
736
|
+
var codepoints = isRTL ? codepointsIteratorRTL(str) : str;
|
|
709
737
|
var isLTR = !isRTL;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
var prev = null;
|
|
721
|
-
var codepoints = isLTR ? str : codepointsIteratorRTL(str);
|
|
738
|
+
|
|
739
|
+
var _ref = isLTR ? [isKeycap, isCombiningEnclosingKeycap, isBlackFlag, isCancelTag] : [isCombiningEnclosingKeycap, isKeycap, isCancelTag, isBlackFlag],
|
|
740
|
+
_ref2 = _slicedToArray(_ref, 4),
|
|
741
|
+
isKeycapStart = _ref2[0],
|
|
742
|
+
isKeycapEnd = _ref2[1],
|
|
743
|
+
isTagStart = _ref2[2],
|
|
744
|
+
isTagEnd = _ref2[3];
|
|
745
|
+
|
|
746
|
+
var distance = 0;
|
|
747
|
+
var previousType = null;
|
|
722
748
|
|
|
723
749
|
var _iterator = _createForOfIteratorHelper$6(codepoints),
|
|
724
750
|
_step;
|
|
@@ -727,120 +753,81 @@ var getCharacterDistance = function getCharacterDistance(str) {
|
|
|
727
753
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
728
754
|
var codepoint = _step.value;
|
|
729
755
|
var code = codepoint.codePointAt(0);
|
|
730
|
-
if (!code) break;
|
|
756
|
+
if (!code) break;
|
|
757
|
+
|
|
758
|
+
if (isLTR && previousType === CodepointType.VariationSelector && !isZWJ(code) && !isKeycapEnd(code)) {
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
731
761
|
|
|
732
762
|
if (isZWJ(code)) {
|
|
733
|
-
|
|
734
|
-
|
|
763
|
+
distance += codepoint.length;
|
|
764
|
+
previousType = CodepointType.ZeroWidthJoiner;
|
|
735
765
|
continue;
|
|
736
766
|
}
|
|
737
767
|
|
|
738
|
-
var _ref = isLTR ? [isKeycap, isCombiningEnclosingKeycap] : [isCombiningEnclosingKeycap, isKeycap],
|
|
739
|
-
_ref2 = _slicedToArray(_ref, 2),
|
|
740
|
-
isKeycapStart = _ref2[0],
|
|
741
|
-
isKeycapEnd = _ref2[1];
|
|
742
|
-
|
|
743
768
|
if (isKeycapStart(code)) {
|
|
744
|
-
if (
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
dist += codepoint.length;
|
|
749
|
-
prev = 'KC';
|
|
769
|
+
if (previousType === CodepointType.Keycap) break;
|
|
770
|
+
distance += codepoint.length;
|
|
771
|
+
previousType = CodepointType.Keycap;
|
|
750
772
|
continue;
|
|
751
773
|
}
|
|
752
774
|
|
|
753
775
|
if (isKeycapEnd(code)) {
|
|
754
|
-
|
|
776
|
+
distance += codepoint.length;
|
|
755
777
|
break;
|
|
756
778
|
}
|
|
757
779
|
|
|
758
780
|
if (isVariationSelector(code)) {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
break;
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
prev = 'VAR';
|
|
766
|
-
continue;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
if (isBMPEmoji(code)) {
|
|
770
|
-
if (isLTR && prev && prev !== 'ZWJ' && prev !== 'VAR') {
|
|
771
|
-
break;
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
dist += codepoint.length;
|
|
775
|
-
|
|
776
|
-
if (isRTL && prev === 'VAR') {
|
|
777
|
-
break;
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
prev = 'BMP';
|
|
781
|
+
if (isRTL && previousType === CodepointType.Character) break;
|
|
782
|
+
distance += codepoint.length;
|
|
783
|
+
previousType = CodepointType.VariationSelector;
|
|
781
784
|
continue;
|
|
782
785
|
}
|
|
783
786
|
|
|
784
787
|
if (isModifier(code)) {
|
|
785
|
-
|
|
786
|
-
|
|
788
|
+
distance += codepoint.length;
|
|
789
|
+
previousType = CodepointType.Modifier;
|
|
787
790
|
continue;
|
|
788
791
|
}
|
|
789
792
|
|
|
790
|
-
var _ref3 = isLTR ? [isBlackFlag, isCancelTag] : [isCancelTag, isBlackFlag],
|
|
791
|
-
_ref4 = _slicedToArray(_ref3, 2),
|
|
792
|
-
isTagStart = _ref4[0],
|
|
793
|
-
isTagEnd = _ref4[1];
|
|
794
|
-
|
|
795
793
|
if (isTagStart(code)) {
|
|
796
|
-
if (
|
|
797
|
-
|
|
798
|
-
|
|
794
|
+
if (previousType === CodepointType.Tag) break;
|
|
795
|
+
distance += codepoint.length;
|
|
796
|
+
previousType = CodepointType.Tag;
|
|
799
797
|
continue;
|
|
800
798
|
}
|
|
801
799
|
|
|
802
|
-
if (
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
if (prev === 'TAG' && isTag(code)) {
|
|
808
|
-
dist += codepoint.length;
|
|
809
|
-
continue;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
if (isRegionalIndicator(code)) {
|
|
813
|
-
dist += codepoint.length;
|
|
814
|
-
|
|
815
|
-
if (prev === 'RI') {
|
|
800
|
+
if (previousType === CodepointType.Tag) {
|
|
801
|
+
if (isTagEnd(code)) {
|
|
802
|
+
distance += codepoint.length;
|
|
816
803
|
break;
|
|
817
804
|
}
|
|
818
805
|
|
|
819
|
-
|
|
820
|
-
|
|
806
|
+
if (isTag(code)) {
|
|
807
|
+
distance += codepoint.length;
|
|
808
|
+
continue;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
break;
|
|
821
812
|
}
|
|
822
813
|
|
|
823
|
-
if (
|
|
824
|
-
|
|
825
|
-
// sequence.
|
|
826
|
-
if (prev === 'NSEQ') {
|
|
814
|
+
if (isRegionalIndicator(code)) {
|
|
815
|
+
if (previousType && previousType !== CodepointType.RegionalIndicator) {
|
|
827
816
|
break;
|
|
828
817
|
}
|
|
829
818
|
|
|
830
|
-
|
|
831
|
-
|
|
819
|
+
distance += codepoint.length;
|
|
820
|
+
if (previousType === CodepointType.RegionalIndicator) break;
|
|
821
|
+
previousType = CodepointType.RegionalIndicator;
|
|
832
822
|
continue;
|
|
833
|
-
} //
|
|
834
|
-
//
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
if (isLTR && prev === 'MOD') {
|
|
838
|
-
dist += codepoint.length;
|
|
839
|
-
break;
|
|
840
|
-
} // If while loop ever gets here, we're done (e.g latin chars).
|
|
823
|
+
} // If previous and curent codepoints are regular characters. it means we are
|
|
824
|
+
// not in a sequence.
|
|
841
825
|
|
|
842
826
|
|
|
843
|
-
break;
|
|
827
|
+
if (previousType === CodepointType.Character) break;
|
|
828
|
+
distance += codepoint.length;
|
|
829
|
+
previousType = CodepointType.Character;
|
|
830
|
+
continue;
|
|
844
831
|
}
|
|
845
832
|
} catch (err) {
|
|
846
833
|
_iterator.e(err);
|
|
@@ -848,7 +835,7 @@ var getCharacterDistance = function getCharacterDistance(str) {
|
|
|
848
835
|
_iterator.f();
|
|
849
836
|
}
|
|
850
837
|
|
|
851
|
-
return
|
|
838
|
+
return distance || 1;
|
|
852
839
|
};
|
|
853
840
|
/**
|
|
854
841
|
* Get the distance to the end of the first word in a string of text.
|
|
@@ -969,41 +956,6 @@ var isKeycap = function isKeycap(code) {
|
|
|
969
956
|
var isCombiningEnclosingKeycap = function isCombiningEnclosingKeycap(code) {
|
|
970
957
|
return code === 0x20e3;
|
|
971
958
|
};
|
|
972
|
-
/**
|
|
973
|
-
* Is `code` one of the BMP codes used in emoji sequences.
|
|
974
|
-
*
|
|
975
|
-
* https://emojipedia.org/emoji-zwj-sequences/
|
|
976
|
-
*/
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
var isBMPEmoji = function isBMPEmoji(code) {
|
|
980
|
-
// This requires tiny bit of maintanance, better ideas?
|
|
981
|
-
// Fortunately it only happens if new Unicode Standard
|
|
982
|
-
// is released. Fails gracefully if upkeep lags behind,
|
|
983
|
-
// same way Slate previously behaved with all emojis.
|
|
984
|
-
return code === 0x2764 || // heart (❤)
|
|
985
|
-
code === 0x2642 || // male (♂)
|
|
986
|
-
code === 0x2640 || // female (♀)
|
|
987
|
-
code === 0x2620 || // scull (☠)
|
|
988
|
-
code === 0x2695 || // medical (⚕)
|
|
989
|
-
code === 0x2708 || // plane (✈️)
|
|
990
|
-
code === 0x25ef || // large circle (◯)
|
|
991
|
-
code === 0x2b06 || // up arrow (⬆)
|
|
992
|
-
code === 0x2197 || // up-right arrow (↗)
|
|
993
|
-
code === 0x27a1 || // right arrow (➡)
|
|
994
|
-
code === 0x2198 || // down-right arrow (↘)
|
|
995
|
-
code === 0x2b07 || // down arrow (⬇)
|
|
996
|
-
code === 0x2199 || // down-left arrow (↙)
|
|
997
|
-
code === 0x2b05 || // left arrow (⬅)
|
|
998
|
-
code === 0x2196 || // up-left arrow (↖)
|
|
999
|
-
code === 0x2195 || // up-down arrow (↕)
|
|
1000
|
-
code === 0x2194 || // left-right arrow (↔)
|
|
1001
|
-
code === 0x21a9 || // right arrow curving left (↩)
|
|
1002
|
-
code === 0x21aa || // left arrow curving right (↪)
|
|
1003
|
-
code === 0x2934 || // right arrow curving up (⤴)
|
|
1004
|
-
code === 0x2935 // right arrow curving down (⤵)
|
|
1005
|
-
;
|
|
1006
|
-
};
|
|
1007
959
|
/**
|
|
1008
960
|
* Is `code` a Regional Indicator.
|
|
1009
961
|
*
|
|
@@ -1014,16 +966,6 @@ var isBMPEmoji = function isBMPEmoji(code) {
|
|
|
1014
966
|
var isRegionalIndicator = function isRegionalIndicator(code) {
|
|
1015
967
|
return code >= 0x1f1e6 && code <= 0x1f1ff;
|
|
1016
968
|
};
|
|
1017
|
-
/**
|
|
1018
|
-
* Is `code` from basic multilingual plane.
|
|
1019
|
-
*
|
|
1020
|
-
* https://codepoints.net/basic_multilingual_plane
|
|
1021
|
-
*/
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
var isBMP = function isBMP(code) {
|
|
1025
|
-
return code <= 0xffff;
|
|
1026
|
-
};
|
|
1027
969
|
/**
|
|
1028
970
|
* Is `code` a Zero Width Joiner.
|
|
1029
971
|
*
|