@chayns-components/emoji-input 5.0.0-beta.98 → 5.0.0-beta.982
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 +4 -15
- package/lib/{api → cjs/api}/item-storage/get.js +4 -5
- package/lib/cjs/api/item-storage/get.js.map +1 -0
- package/lib/{api → cjs/api}/item-storage/put.js +5 -6
- package/lib/cjs/api/item-storage/put.js.map +1 -0
- package/lib/cjs/components/emoji-input/EmojiInput.js +510 -0
- package/lib/cjs/components/emoji-input/EmojiInput.js.map +1 -0
- package/lib/cjs/components/emoji-input/EmojiInput.styles.js +132 -0
- package/lib/cjs/components/emoji-input/EmojiInput.styles.js.map +1 -0
- package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.js +45 -0
- package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.js.map +1 -0
- package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.styles.js +65 -0
- package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.styles.js.map +1 -0
- package/lib/{components → cjs/components}/emoji-picker/EmojiPicker.js +9 -11
- package/lib/cjs/components/emoji-picker/EmojiPicker.js.map +1 -0
- package/lib/{components → cjs/components}/emoji-picker/EmojiPicker.styles.js +3 -5
- package/lib/cjs/components/emoji-picker/EmojiPicker.styles.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +102 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +1 -0
- package/lib/{components → cjs/components}/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js +5 -6
- package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +240 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +69 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +1 -0
- package/lib/{components → cjs/components}/emoji-picker/emoji-picker-emojis/emoji/Emoji.js +49 -21
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +24 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +130 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +99 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +1 -0
- package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.js +52 -0
- package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.js.map +1 -0
- package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.styles.js +15 -0
- package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +1 -0
- package/lib/{constants → cjs/constants}/alignment.js +6 -8
- package/lib/cjs/constants/alignment.js.map +1 -0
- package/lib/{constants → cjs/constants}/categories.js +1 -2
- package/lib/cjs/constants/categories.js.map +1 -0
- package/lib/{constants → cjs/constants}/emoji.js +4 -8
- package/lib/cjs/constants/emoji.js.map +1 -0
- package/lib/cjs/constants/externalServerUrl.js +8 -0
- package/lib/cjs/constants/externalServerUrl.js.map +1 -0
- package/lib/cjs/constants/regex.js +15 -0
- package/lib/cjs/constants/regex.js.map +1 -0
- package/lib/{hooks → cjs/hooks}/emojiHistory.js +13 -15
- package/lib/cjs/hooks/emojiHistory.js.map +1 -0
- package/lib/{index.js → cjs/index.js} +1 -1
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/types/api.js +2 -0
- package/lib/cjs/types/api.js.map +1 -0
- package/lib/cjs/types/category.js +2 -0
- package/lib/cjs/types/category.js.map +1 -0
- package/lib/{utils → cjs/utils}/emoji.js +14 -6
- package/lib/cjs/utils/emoji.js.map +1 -0
- package/lib/{utils → cjs/utils}/environment.js +6 -4
- package/lib/cjs/utils/environment.js.map +1 -0
- package/lib/cjs/utils/font.js +17 -0
- package/lib/cjs/utils/font.js.map +1 -0
- package/lib/cjs/utils/insert.js +110 -0
- package/lib/cjs/utils/insert.js.map +1 -0
- package/lib/cjs/utils/number.js +17 -0
- package/lib/cjs/utils/number.js.map +1 -0
- package/lib/cjs/utils/selection.js +255 -0
- package/lib/cjs/utils/selection.js.map +1 -0
- package/lib/cjs/utils/text.js +57 -0
- package/lib/cjs/utils/text.js.map +1 -0
- package/lib/esm/api/item-storage/get.js +30 -0
- package/lib/esm/api/item-storage/get.js.map +1 -0
- package/lib/esm/api/item-storage/put.js +35 -0
- package/lib/esm/api/item-storage/put.js.map +1 -0
- package/lib/esm/components/emoji-input/EmojiInput.js +497 -0
- package/lib/esm/components/emoji-input/EmojiInput.js.map +1 -0
- package/lib/esm/components/emoji-input/EmojiInput.styles.js +151 -0
- package/lib/esm/components/emoji-input/EmojiInput.styles.js.map +1 -0
- package/lib/esm/components/emoji-input/prefix-element/PrefixElement.js +38 -0
- package/lib/esm/components/emoji-input/prefix-element/PrefixElement.js.map +1 -0
- package/lib/esm/components/emoji-input/prefix-element/PrefixElement.styles.js +69 -0
- package/lib/esm/components/emoji-input/prefix-element/PrefixElement.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/EmojiPicker.js +40 -0
- package/lib/esm/components/emoji-picker/EmojiPicker.js.map +1 -0
- package/lib/esm/components/emoji-picker/EmojiPicker.styles.js +16 -0
- package/lib/esm/components/emoji-picker/EmojiPicker.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +96 -0
- package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js +18 -0
- package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +240 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +76 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js +136 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +20 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +121 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +98 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.js +43 -0
- package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.js.map +1 -0
- package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.styles.js +8 -0
- package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +1 -0
- package/lib/esm/constants/alignment.js +13 -0
- package/lib/esm/constants/alignment.js.map +1 -0
- package/lib/esm/constants/categories.js +13 -0
- package/lib/esm/constants/categories.js.map +1 -0
- package/lib/esm/constants/emoji-de-DE.json +3827 -0
- package/lib/esm/constants/emoji.js +3798 -0
- package/lib/esm/constants/emoji.js.map +1 -0
- package/lib/esm/constants/externalServerUrl.js +2 -0
- package/lib/esm/constants/externalServerUrl.js.map +1 -0
- package/lib/esm/constants/regex.js +9 -0
- package/lib/esm/constants/regex.js.map +1 -0
- package/lib/esm/hooks/emojiHistory.js +83 -0
- package/lib/esm/hooks/emojiHistory.js.map +1 -0
- package/lib/{index.d.ts → esm/index.js} +1 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/types/api.js +2 -0
- package/lib/esm/types/api.js.map +1 -0
- package/lib/esm/types/category.js +2 -0
- package/lib/esm/types/category.js.map +1 -0
- package/lib/esm/utils/emoji.js +92 -0
- package/lib/esm/utils/emoji.js.map +1 -0
- package/lib/esm/utils/environment.js +24 -0
- package/lib/esm/utils/environment.js.map +1 -0
- package/lib/esm/utils/font.js +10 -0
- package/lib/esm/utils/font.js.map +1 -0
- package/lib/esm/utils/insert.js +104 -0
- package/lib/esm/utils/insert.js.map +1 -0
- package/lib/esm/utils/number.js +10 -0
- package/lib/esm/utils/number.js.map +1 -0
- package/lib/esm/utils/selection.js +237 -0
- package/lib/esm/utils/selection.js.map +1 -0
- package/lib/esm/utils/text.js +48 -0
- package/lib/esm/utils/text.js.map +1 -0
- package/lib/types/components/emoji-input/EmojiInput.d.ts +94 -0
- package/lib/types/components/emoji-input/EmojiInput.styles.d.ts +549 -0
- package/lib/types/components/emoji-input/prefix-element/PrefixElement.d.ts +8 -0
- package/lib/types/components/emoji-input/prefix-element/PrefixElement.styles.d.ts +12 -0
- package/lib/types/components/emoji-picker/EmojiPicker.styles.d.ts +5 -0
- package/lib/types/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.d.ts +267 -0
- package/lib/types/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.d.ts +10 -0
- package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/emoji/Emoji.d.ts +5 -0
- package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.d.ts +6 -0
- package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.d.ts +283 -0
- package/lib/{components → types/components}/emoji-picker-popup/EmojiPickerPopup.d.ts +0 -13
- package/lib/types/components/emoji-picker-popup/EmojiPickerPopup.styles.d.ts +1 -0
- package/lib/types/constants/regex.d.ts +8 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/{utils → types/utils}/emoji.d.ts +2 -0
- package/lib/{utils → types/utils}/environment.d.ts +1 -0
- package/lib/types/utils/font.d.ts +1 -0
- package/lib/{utils → types/utils}/insert.d.ts +8 -1
- package/lib/types/utils/number.d.ts +1 -0
- package/lib/types/utils/selection.d.ts +23 -0
- package/lib/types/utils/text.d.ts +3 -0
- package/package.json +48 -30
- package/lib/api/item-storage/get.js.map +0 -1
- package/lib/api/item-storage/put.js.map +0 -1
- package/lib/components/emoji-input/EmojiInput.d.ts +0 -49
- package/lib/components/emoji-input/EmojiInput.js +0 -161
- package/lib/components/emoji-input/EmojiInput.js.map +0 -1
- package/lib/components/emoji-input/EmojiInput.styles.d.ts +0 -16
- package/lib/components/emoji-input/EmojiInput.styles.js +0 -158
- package/lib/components/emoji-input/EmojiInput.styles.js.map +0 -1
- package/lib/components/emoji-picker/EmojiPicker.js.map +0 -1
- package/lib/components/emoji-picker/EmojiPicker.styles.d.ts +0 -5
- package/lib/components/emoji-picker/EmojiPicker.styles.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +0 -51
- package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.d.ts +0 -2
- package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +0 -131
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.d.ts +0 -7
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +0 -99
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.d.ts +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +0 -20
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +0 -74
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.d.ts +0 -11
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +0 -104
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +0 -1
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.js +0 -150
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.js.map +0 -1
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.d.ts +0 -7
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.js +0 -97
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +0 -1
- package/lib/constants/alignment.js.map +0 -1
- package/lib/constants/categories.js.map +0 -1
- package/lib/constants/emoji.js.map +0 -1
- package/lib/constants/externalServerUrl.js +0 -9
- package/lib/constants/externalServerUrl.js.map +0 -1
- package/lib/hooks/emojiHistory.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/api.js +0 -6
- package/lib/types/api.js.map +0 -1
- package/lib/types/category.js +0 -6
- package/lib/types/category.js.map +0 -1
- package/lib/utils/emoji.js.map +0 -1
- package/lib/utils/environment.js.map +0 -1
- package/lib/utils/font.d.ts +0 -1
- package/lib/utils/font.js +0 -15
- package/lib/utils/font.js.map +0 -1
- package/lib/utils/insert.js +0 -50
- package/lib/utils/insert.js.map +0 -1
- package/lib/utils/selection.d.ts +0 -2
- package/lib/utils/selection.js +0 -43
- package/lib/utils/selection.js.map +0 -1
- /package/lib/{constants → cjs/constants}/emoji-de-DE.json +0 -0
- /package/lib/{api → types/api}/item-storage/get.d.ts +0 -0
- /package/lib/{api → types/api}/item-storage/put.d.ts +0 -0
- /package/lib/{components → types/components}/emoji-picker/EmojiPicker.d.ts +0 -0
- /package/lib/{components → types/components}/emoji-picker/emoji-picker-categories/EmojiPickerCategories.d.ts +0 -0
- /package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.d.ts +0 -0
- /package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.d.ts +0 -0
- /package/lib/{constants → types/constants}/alignment.d.ts +0 -0
- /package/lib/{constants → types/constants}/categories.d.ts +0 -0
- /package/lib/{constants → types/constants}/emoji.d.ts +0 -0
- /package/lib/{constants → types/constants}/externalServerUrl.d.ts +0 -0
- /package/lib/{hooks → types/hooks}/emojiHistory.d.ts +0 -0
- /package/lib/types/{api.d.ts → types/api.d.ts} +0 -0
- /package/lib/types/{category.d.ts → types/category.d.ts} +0 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { clamp } from './number';
|
|
2
|
+
import { getElementTextLength } from './text';
|
|
3
|
+
let childIndex = -1;
|
|
4
|
+
let endOffset = -1;
|
|
5
|
+
let startOffset = -1;
|
|
6
|
+
export const saveSelection = function (element) {
|
|
7
|
+
let {
|
|
8
|
+
shouldIgnoreEmptyTextNodes
|
|
9
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
10
|
+
const selection = window.getSelection();
|
|
11
|
+
if (!selection) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
anchorNode
|
|
16
|
+
} = selection;
|
|
17
|
+
if (!anchorNode) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const range = selection.getRangeAt(0);
|
|
21
|
+
let childNodesArray = Array.from(element.childNodes);
|
|
22
|
+
if (shouldIgnoreEmptyTextNodes) {
|
|
23
|
+
childNodesArray = childNodesArray.filter(_ref => {
|
|
24
|
+
let {
|
|
25
|
+
nodeType,
|
|
26
|
+
nodeValue
|
|
27
|
+
} = _ref;
|
|
28
|
+
return nodeType !== Node.TEXT_NODE || nodeValue !== '' && nodeValue !== '\u200B';
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
childIndex = childNodesArray.indexOf(anchorNode);
|
|
32
|
+
endOffset = range.endOffset;
|
|
33
|
+
startOffset = range.startOffset;
|
|
34
|
+
};
|
|
35
|
+
export const restoreSelection = element => {
|
|
36
|
+
let childNode = element.childNodes[childIndex];
|
|
37
|
+
const selection = window.getSelection();
|
|
38
|
+
if (!childNode || !element || !selection) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// noinspection SuspiciousTypeOfGuard
|
|
43
|
+
if (typeof childNode.nodeValue !== 'string') {
|
|
44
|
+
const elementTextLength = getElementTextLength(childNode);
|
|
45
|
+
if (childNode.nextSibling) {
|
|
46
|
+
childNode = childNode.nextSibling;
|
|
47
|
+
if (childNode.nodeType === Node.TEXT_NODE && childNode.nodeValue) {
|
|
48
|
+
endOffset -= elementTextLength;
|
|
49
|
+
startOffset -= elementTextLength;
|
|
50
|
+
if (childNode.nodeValue.charCodeAt(endOffset) === 8203) {
|
|
51
|
+
endOffset += 1;
|
|
52
|
+
startOffset += 1;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
const textNode = document.createTextNode('\u200B');
|
|
56
|
+
childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);
|
|
57
|
+
childNode = textNode;
|
|
58
|
+
endOffset = textNode.length;
|
|
59
|
+
startOffset = textNode.length;
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
const textNode = document.createTextNode('\u200B');
|
|
63
|
+
childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);
|
|
64
|
+
childNode = textNode;
|
|
65
|
+
endOffset = textNode.length;
|
|
66
|
+
startOffset = textNode.length;
|
|
67
|
+
}
|
|
68
|
+
} else if (childNode.nodeValue && endOffset > childNode.nodeValue.length) {
|
|
69
|
+
if (childNode.nextSibling?.nodeValue) {
|
|
70
|
+
let elementTextLength = childNode.nodeValue.length;
|
|
71
|
+
childNode = childNode.nextSibling;
|
|
72
|
+
|
|
73
|
+
// noinspection SuspiciousTypeOfGuard
|
|
74
|
+
if (typeof childNode.nodeValue !== 'string') {
|
|
75
|
+
elementTextLength += getElementTextLength(childNode);
|
|
76
|
+
if (childNode.nextSibling?.nodeValue) {
|
|
77
|
+
childNode = childNode.nextSibling;
|
|
78
|
+
if (childNode.nodeType === Node.TEXT_NODE && childNode.nodeValue) {
|
|
79
|
+
endOffset -= elementTextLength;
|
|
80
|
+
startOffset -= elementTextLength;
|
|
81
|
+
if (childNode.nodeValue.charCodeAt(endOffset) === 8203) {
|
|
82
|
+
endOffset += 1;
|
|
83
|
+
startOffset += 1;
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
const textNode = document.createTextNode('\u200B');
|
|
87
|
+
childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);
|
|
88
|
+
childNode = textNode;
|
|
89
|
+
endOffset = textNode.length;
|
|
90
|
+
startOffset = textNode.length;
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
const textNode = document.createTextNode('\u200B');
|
|
94
|
+
childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);
|
|
95
|
+
childNode = textNode;
|
|
96
|
+
endOffset = textNode.length;
|
|
97
|
+
startOffset = textNode.length;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
endOffset = childNode.nodeValue.length;
|
|
102
|
+
startOffset = childNode.nodeValue.length;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const range = document.createRange();
|
|
106
|
+
|
|
107
|
+
// noinspection SuspiciousTypeOfGuard
|
|
108
|
+
if (typeof childNode.nodeValue === 'string') {
|
|
109
|
+
startOffset = clamp(startOffset, 0, childNode.nodeValue.length);
|
|
110
|
+
endOffset = clamp(endOffset, 0, childNode.nodeValue.length);
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
range.setStart(childNode, startOffset);
|
|
114
|
+
range.setEnd(childNode, endOffset);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
// Do nothing
|
|
117
|
+
}
|
|
118
|
+
selection.removeAllRanges();
|
|
119
|
+
selection.addRange(range);
|
|
120
|
+
range.collapse(true);
|
|
121
|
+
};
|
|
122
|
+
export const insertInvisibleCursorMarker = () => {
|
|
123
|
+
const selection = window.getSelection();
|
|
124
|
+
if (!selection || selection.rangeCount === 0) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const range = selection.getRangeAt(0);
|
|
128
|
+
const textNode = range.startContainer;
|
|
129
|
+
const offset = range.startOffset;
|
|
130
|
+
|
|
131
|
+
// noinspection JSDeprecatedSymbols
|
|
132
|
+
document.execCommand('delete', false);
|
|
133
|
+
const span = document.createElement('span');
|
|
134
|
+
span.style.display = 'inline-block';
|
|
135
|
+
span.style.width = '0';
|
|
136
|
+
span.style.height = '0';
|
|
137
|
+
span.className = 'invisible-cursor-marker';
|
|
138
|
+
const parent = textNode.parentNode;
|
|
139
|
+
if (parent) {
|
|
140
|
+
if (textNode.nodeType === Node.TEXT_NODE) {
|
|
141
|
+
const textContent = textNode.textContent || '';
|
|
142
|
+
const beforeText = textContent.slice(0, offset);
|
|
143
|
+
const afterText = textContent.slice(offset);
|
|
144
|
+
textNode.textContent = beforeText;
|
|
145
|
+
parent.insertBefore(span, textNode.nextSibling);
|
|
146
|
+
const afterTextNode = document.createTextNode(afterText);
|
|
147
|
+
parent.insertBefore(afterTextNode, span.nextSibling);
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
// Set cursor to cursor element
|
|
150
|
+
const newRange = document.createRange();
|
|
151
|
+
newRange.setStartAfter(span);
|
|
152
|
+
newRange.setEndAfter(span);
|
|
153
|
+
selection.removeAllRanges();
|
|
154
|
+
selection.addRange(newRange);
|
|
155
|
+
|
|
156
|
+
// Remove cursor element
|
|
157
|
+
span.remove();
|
|
158
|
+
}, 10);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
export const moveSelectionOffset = distance => {
|
|
163
|
+
endOffset += distance;
|
|
164
|
+
startOffset += distance;
|
|
165
|
+
};
|
|
166
|
+
export const setChildIndex = index => {
|
|
167
|
+
childIndex = index;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* This function returns the code of the character that will be removed by the KeyDown event in the
|
|
172
|
+
* next step, if the "Backspace" or "Delete" key was pressed and there is no selection of multiple
|
|
173
|
+
* characters.
|
|
174
|
+
*
|
|
175
|
+
* @param event - Keyboard event from "onKeyDown"
|
|
176
|
+
*/
|
|
177
|
+
export const getCharCodeThatWillBeDeleted = event => {
|
|
178
|
+
const range = window.getSelection()?.getRangeAt(0);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* At this point the function is aborted if there is no selection range, several characters have
|
|
182
|
+
* been selected and therefore no single letter is removed or neither the "Backspace" nor the
|
|
183
|
+
* "Delete" key has been pressed.
|
|
184
|
+
*/
|
|
185
|
+
if (!range || range.endOffset !== range.startOffset || event.key !== 'Backspace' && event.key !== 'Delete' && event.key !== 'Unidentified') {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
if (event.key === 'Backspace' || event.key === 'Unidentified') {
|
|
189
|
+
const {
|
|
190
|
+
nodeValue,
|
|
191
|
+
previousSibling
|
|
192
|
+
} = range.startContainer;
|
|
193
|
+
if (range.startOffset > 0) {
|
|
194
|
+
return nodeValue?.charCodeAt(range.startOffset - 1);
|
|
195
|
+
}
|
|
196
|
+
return previousSibling?.nodeValue?.charCodeAt(previousSibling.nodeValue.length - 1);
|
|
197
|
+
}
|
|
198
|
+
const {
|
|
199
|
+
nextSibling,
|
|
200
|
+
nodeValue
|
|
201
|
+
} = range.endContainer;
|
|
202
|
+
if (range.endOffset < (nodeValue?.length ?? 0)) {
|
|
203
|
+
return nodeValue?.charCodeAt(range.endOffset);
|
|
204
|
+
}
|
|
205
|
+
return nextSibling?.nodeValue?.charCodeAt(0);
|
|
206
|
+
};
|
|
207
|
+
export const findAndSelectText = _ref2 => {
|
|
208
|
+
let {
|
|
209
|
+
editorElement,
|
|
210
|
+
searchText
|
|
211
|
+
} = _ref2;
|
|
212
|
+
if (!editorElement.textContent?.includes(searchText)) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const range = document.createRange();
|
|
216
|
+
let startNode = null;
|
|
217
|
+
let offset = -1;
|
|
218
|
+
const searchNodesForText = node => {
|
|
219
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
220
|
+
const index = node.textContent?.indexOf(searchText);
|
|
221
|
+
if (typeof index === 'number' && index !== -1) {
|
|
222
|
+
startNode = node;
|
|
223
|
+
offset = index;
|
|
224
|
+
range.setStart(node, index);
|
|
225
|
+
range.setEnd(node, index + searchText.length);
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
} else if (node.nodeName !== 'LC_MENTION') {
|
|
229
|
+
return Array.from(node.childNodes).some(searchNodesForText);
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
};
|
|
233
|
+
searchNodesForText(editorElement);
|
|
234
|
+
if (startNode && offset !== -1) return range;
|
|
235
|
+
return null;
|
|
236
|
+
};
|
|
237
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.js","names":["clamp","getElementTextLength","childIndex","endOffset","startOffset","saveSelection","element","shouldIgnoreEmptyTextNodes","arguments","length","undefined","selection","window","getSelection","anchorNode","range","getRangeAt","childNodesArray","Array","from","childNodes","filter","_ref","nodeType","nodeValue","Node","TEXT_NODE","indexOf","restoreSelection","childNode","elementTextLength","nextSibling","charCodeAt","textNode","document","createTextNode","parentNode","insertBefore","createRange","setStart","setEnd","error","removeAllRanges","addRange","collapse","insertInvisibleCursorMarker","rangeCount","startContainer","offset","execCommand","span","createElement","style","display","width","height","className","parent","textContent","beforeText","slice","afterText","afterTextNode","setTimeout","newRange","setStartAfter","setEndAfter","remove","moveSelectionOffset","distance","setChildIndex","index","getCharCodeThatWillBeDeleted","event","key","previousSibling","endContainer","findAndSelectText","_ref2","editorElement","searchText","includes","startNode","searchNodesForText","node","nodeName","some"],"sources":["../../../src/utils/selection.ts"],"sourcesContent":["import type { KeyboardEvent } from 'react';\nimport { clamp } from './number';\nimport { getElementTextLength } from './text';\n\nlet childIndex = -1;\nlet endOffset = -1;\nlet startOffset = -1;\n\ninterface SaveSelectionOptions {\n shouldIgnoreEmptyTextNodes?: boolean;\n}\n\nexport const saveSelection = (\n element: HTMLDivElement,\n { shouldIgnoreEmptyTextNodes }: SaveSelectionOptions = {},\n) => {\n const selection = window.getSelection();\n\n if (!selection) {\n return;\n }\n\n const { anchorNode } = selection;\n\n if (!anchorNode) {\n return;\n }\n\n const range = selection.getRangeAt(0);\n\n let childNodesArray = Array.from(element.childNodes);\n\n if (shouldIgnoreEmptyTextNodes) {\n childNodesArray = childNodesArray.filter(\n ({ nodeType, nodeValue }) =>\n nodeType !== Node.TEXT_NODE || (nodeValue !== '' && nodeValue !== '\\u200B'),\n );\n }\n\n childIndex = childNodesArray.indexOf(anchorNode as ChildNode);\n\n endOffset = range.endOffset;\n startOffset = range.startOffset;\n};\n\nexport const restoreSelection = (element: HTMLDivElement) => {\n let childNode = element.childNodes[childIndex];\n\n const selection = window.getSelection();\n\n if (!childNode || !element || !selection) {\n return;\n }\n\n // noinspection SuspiciousTypeOfGuard\n if (typeof childNode.nodeValue !== 'string') {\n const elementTextLength = getElementTextLength(childNode as Element);\n\n if (childNode.nextSibling) {\n childNode = childNode.nextSibling;\n\n if (childNode.nodeType === Node.TEXT_NODE && childNode.nodeValue) {\n endOffset -= elementTextLength;\n startOffset -= elementTextLength;\n\n if (childNode.nodeValue.charCodeAt(endOffset) === 8203) {\n endOffset += 1;\n startOffset += 1;\n }\n } else {\n const textNode = document.createTextNode('\\u200B');\n\n childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);\n\n childNode = textNode;\n\n endOffset = textNode.length;\n startOffset = textNode.length;\n }\n } else {\n const textNode = document.createTextNode('\\u200B');\n\n childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);\n\n childNode = textNode;\n\n endOffset = textNode.length;\n startOffset = textNode.length;\n }\n } else if (childNode.nodeValue && endOffset > childNode.nodeValue.length) {\n if (childNode.nextSibling?.nodeValue) {\n let elementTextLength = childNode.nodeValue.length;\n\n childNode = childNode.nextSibling;\n\n // noinspection SuspiciousTypeOfGuard\n if (typeof childNode.nodeValue !== 'string') {\n elementTextLength += getElementTextLength(childNode as Element);\n\n if (childNode.nextSibling?.nodeValue) {\n childNode = childNode.nextSibling;\n\n if (childNode.nodeType === Node.TEXT_NODE && childNode.nodeValue) {\n endOffset -= elementTextLength;\n startOffset -= elementTextLength;\n\n if (childNode.nodeValue.charCodeAt(endOffset) === 8203) {\n endOffset += 1;\n startOffset += 1;\n }\n } else {\n const textNode = document.createTextNode('\\u200B');\n\n childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);\n\n childNode = textNode;\n\n endOffset = textNode.length;\n startOffset = textNode.length;\n }\n } else {\n const textNode = document.createTextNode('\\u200B');\n\n childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);\n\n childNode = textNode;\n\n endOffset = textNode.length;\n startOffset = textNode.length;\n }\n }\n } else {\n endOffset = childNode.nodeValue.length;\n startOffset = childNode.nodeValue.length;\n }\n }\n\n const range = document.createRange();\n\n // noinspection SuspiciousTypeOfGuard\n if (typeof childNode.nodeValue === 'string') {\n startOffset = clamp(startOffset, 0, childNode.nodeValue.length);\n endOffset = clamp(endOffset, 0, childNode.nodeValue.length);\n }\n\n try {\n range.setStart(childNode, startOffset);\n range.setEnd(childNode, endOffset);\n } catch (error) {\n // Do nothing\n }\n\n selection.removeAllRanges();\n selection.addRange(range);\n\n range.collapse(true);\n};\n\nexport const insertInvisibleCursorMarker = (): void => {\n const selection = window.getSelection();\n\n if (!selection || selection.rangeCount === 0) {\n return;\n }\n\n const range = selection.getRangeAt(0);\n const textNode = range.startContainer;\n const offset = range.startOffset;\n\n // noinspection JSDeprecatedSymbols\n document.execCommand('delete', false);\n\n const span = document.createElement('span');\n span.style.display = 'inline-block';\n span.style.width = '0';\n span.style.height = '0';\n span.className = 'invisible-cursor-marker';\n\n const parent = textNode.parentNode;\n\n if (parent) {\n if (textNode.nodeType === Node.TEXT_NODE) {\n const textContent = textNode.textContent || '';\n const beforeText = textContent.slice(0, offset);\n const afterText = textContent.slice(offset);\n\n textNode.textContent = beforeText;\n\n parent.insertBefore(span, textNode.nextSibling);\n const afterTextNode = document.createTextNode(afterText);\n parent.insertBefore(afterTextNode, span.nextSibling);\n\n setTimeout(() => {\n // Set cursor to cursor element\n const newRange = document.createRange();\n newRange.setStartAfter(span);\n newRange.setEndAfter(span);\n selection.removeAllRanges();\n selection.addRange(newRange);\n\n // Remove cursor element\n span.remove();\n }, 10);\n }\n }\n};\n\nexport const moveSelectionOffset = (distance: number) => {\n endOffset += distance;\n startOffset += distance;\n};\n\nexport const setChildIndex = (index: number) => {\n childIndex = index;\n};\n\n/**\n * This function returns the code of the character that will be removed by the KeyDown event in the\n * next step, if the \"Backspace\" or \"Delete\" key was pressed and there is no selection of multiple\n * characters.\n *\n * @param event - Keyboard event from \"onKeyDown\"\n */\nexport const getCharCodeThatWillBeDeleted = (event: KeyboardEvent<HTMLDivElement>) => {\n const range = window.getSelection()?.getRangeAt(0);\n\n /**\n * At this point the function is aborted if there is no selection range, several characters have\n * been selected and therefore no single letter is removed or neither the \"Backspace\" nor the\n * \"Delete\" key has been pressed.\n */\n if (\n !range ||\n range.endOffset !== range.startOffset ||\n (event.key !== 'Backspace' && event.key !== 'Delete' && event.key !== 'Unidentified')\n ) {\n return null;\n }\n\n if (event.key === 'Backspace' || event.key === 'Unidentified') {\n const { nodeValue, previousSibling } = range.startContainer;\n\n if (range.startOffset > 0) {\n return nodeValue?.charCodeAt(range.startOffset - 1);\n }\n\n return previousSibling?.nodeValue?.charCodeAt(previousSibling.nodeValue.length - 1);\n }\n\n const { nextSibling, nodeValue } = range.endContainer;\n\n if (range.endOffset < (nodeValue?.length ?? 0)) {\n return nodeValue?.charCodeAt(range.endOffset);\n }\n\n return nextSibling?.nodeValue?.charCodeAt(0);\n};\n\ninterface FindAndSelectTextOptions {\n editorElement: HTMLDivElement;\n searchText: string;\n}\n\nexport const findAndSelectText = ({\n editorElement,\n searchText,\n}: FindAndSelectTextOptions): Range | null => {\n if (!editorElement.textContent?.includes(searchText)) {\n return null;\n }\n\n const range = document.createRange();\n\n let startNode: Node | null = null;\n let offset = -1;\n\n const searchNodesForText = (node: Node) => {\n if (node.nodeType === Node.TEXT_NODE) {\n const index = node.textContent?.indexOf(searchText);\n\n if (typeof index === 'number' && index !== -1) {\n startNode = node;\n offset = index;\n\n range.setStart(node, index);\n range.setEnd(node, index + searchText.length);\n\n return true;\n }\n } else if (node.nodeName !== 'LC_MENTION') {\n return Array.from(node.childNodes).some(searchNodesForText);\n }\n\n return false;\n };\n\n searchNodesForText(editorElement);\n\n if (startNode && offset !== -1) return range;\n\n return null;\n};\n"],"mappings":"AACA,SAASA,KAAK,QAAQ,UAAU;AAChC,SAASC,oBAAoB,QAA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AE,OAAOjC,KAAK;EAE5C,OAAO,IAAI;AACf,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BB_LC_MENTION_REGEX, BB_NER_IGNORE_REGEX, BB_NER_REPLACE_REGEX, HTML_A_TAG_REGEX, HTML_BOLD_REGEX, HTML_LC_MENTION_REGEX, HTML_NER_IGNORE_REGEX, HTML_NER_REPLACE_REGEX } from '../constants/regex';
|
|
2
|
+
import { escapeHTML, unescapeHTML } from './emoji';
|
|
3
|
+
export const convertTextToHTML = text => {
|
|
4
|
+
const element = document.createElement('div');
|
|
5
|
+
element.style.position = 'absolute';
|
|
6
|
+
element.style.opacity = '0';
|
|
7
|
+
element.contentEditable = 'true';
|
|
8
|
+
element.innerText = text;
|
|
9
|
+
document.body.appendChild(element);
|
|
10
|
+
let result = element.innerHTML;
|
|
11
|
+
document.body.removeChild(element);
|
|
12
|
+
result = unescapeHTML(result);
|
|
13
|
+
result = result.replace(HTML_A_TAG_REGEX, '$1').replace(BB_LC_MENTION_REGEX, '<lc_mention contenteditable="false" id="$1"><span>@</span>$2</lc_mention>').replace(BB_NER_IGNORE_REGEX, '<nerIgnore contenteditable="false">$1</nerIgnore>').replace(BB_NER_REPLACE_REGEX, (_, prefix, type, value, entity) => {
|
|
14
|
+
const prefixAttr = prefix ? `prefix="${prefix}" ` : '';
|
|
15
|
+
return `<nerReplace contenteditable="false" ${prefixAttr}type="${type}" value="${value}">${entity}</nerReplace>`;
|
|
16
|
+
});
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
export const convertHTMLToText = text => {
|
|
20
|
+
let result = text;
|
|
21
|
+
result = result.replace(HTML_A_TAG_REGEX, '$1').replace(HTML_BOLD_REGEX, '[b]$1[/b]').replace(HTML_LC_MENTION_REGEX, '[lc_mention id="$1"]$2[/lc_mention]').replace(HTML_NER_IGNORE_REGEX, '[nerIgnore]$1[/nerIgnore]').replace(HTML_NER_REPLACE_REGEX, (_, prefix, type, value, entity) => {
|
|
22
|
+
const prefixAttr = prefix ? `prefix="${prefix}" ` : '';
|
|
23
|
+
return `[nerReplace ${prefixAttr}type="${type}" value="${value}"]${entity}[/nerReplace]`;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
27
|
+
result = result.replace(//g, '');
|
|
28
|
+
result = escapeHTML(result);
|
|
29
|
+
const element = document.createElement('div');
|
|
30
|
+
element.style.position = 'absolute';
|
|
31
|
+
element.style.opacity = '0';
|
|
32
|
+
element.contentEditable = 'true';
|
|
33
|
+
element.innerHTML = result;
|
|
34
|
+
document.body.appendChild(element);
|
|
35
|
+
result = element.innerText;
|
|
36
|
+
document.body.removeChild(element);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
export const getElementTextLength = element => {
|
|
40
|
+
let textLength = 0;
|
|
41
|
+
try {
|
|
42
|
+
textLength = convertHTMLToText(element.outerHTML).length;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// Do nothing
|
|
45
|
+
}
|
|
46
|
+
return textLength;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","names":["BB_LC_MENTION_REGEX","BB_NER_IGNORE_REGEX","BB_NER_REPLACE_REGEX","HTML_A_TAG_REGEX","HTML_BOLD_REGEX","HTML_LC_MENTION_REGEX","HTML_NER_IGNORE_REGEX","HTML_NER_REPLACE_REGEX","escapeHTML","unescapeHTML","convertTextToHTML","text","element","document","createElement","style","position","opacity","contentEditable","innerText","body","appendChild","result","innerHTML","removeChild","replace","_","prefix","type","value","entity","prefixAttr","convertHTMLToText","getElementTextLength","textLength","outerHTML","length","e"],"sources":["../../../src/utils/text.ts"],"sourcesContent":["import {\n BB_LC_MENTION_REGEX,\n BB_NER_IGNORE_REGEX,\n BB_NER_REPLACE_REGEX,\n HTML_A_TAG_REGEX,\n HTML_BOLD_REGEX,\n HTML_LC_MENTION_REGEX,\n HTML_NER_IGNORE_REGEX,\n HTML_NER_REPLACE_REGEX,\n} from '../constants/regex';\nimport { escapeHTML, unescapeHTML } from './emoji';\n\nexport const convertTextToHTML = (text: string) => {\n const element = document.createElement('div');\n\n element.style.position = 'absolute';\n element.style.opacity = '0';\n\n element.contentEditable = 'true';\n element.innerText = text;\n\n document.body.appendChild(element);\n\n let result = element.innerHTML;\n\n document.body.removeChild(element);\n\n result = unescapeHTML(result);\n\n result = result\n .replace(HTML_A_TAG_REGEX, '$1')\n .replace(\n BB_LC_MENTION_REGEX,\n '<lc_mention contenteditable=\"false\" id=\"$1\"><span>@</span>$2</lc_mention>',\n )\n .replace(BB_NER_IGNORE_REGEX, '<nerIgnore contenteditable=\"false\">$1</nerIgnore>')\n .replace(\n BB_NER_REPLACE_REGEX,\n (_, prefix: string | undefined, type: string, value: string, entity: string) => {\n const prefixAttr = prefix ? `prefix=\"${prefix}\" ` : '';\n\n return `<nerReplace contenteditable=\"false\" ${prefixAttr}type=\"${type}\" value=\"${value}\">${entity}</nerReplace>`;\n },\n );\n\n return result;\n};\n\nexport const convertHTMLToText = (text: string) => {\n let result = text;\n\n result = result\n .replace(HTML_A_TAG_REGEX, '$1')\n .replace(HTML_BOLD_REGEX, '[b]$1[/b]')\n .replace(HTML_LC_MENTION_REGEX, '[lc_mention id=\"$1\"]$2[/lc_mention]')\n .replace(HTML_NER_IGNORE_REGEX, '[nerIgnore]$1[/nerIgnore]')\n .replace(\n HTML_NER_REPLACE_REGEX,\n (_, prefix: string | undefined, type: string, value: string, entity: string) => {\n const prefixAttr = prefix ? `prefix=\"${prefix}\" ` : '';\n\n return `[nerReplace ${prefixAttr}type=\"${type}\" value=\"${value}\"]${entity}[/nerReplace]`;\n },\n );\n\n // eslint-disable-next-line no-irregular-whitespace\n result = result.replace(//g, '');\n\n result = escapeHTML(result);\n\n const element = document.createElement('div');\n\n element.style.position = 'absolute';\n element.style.opacity = '0';\n\n element.contentEditable = 'true';\n element.innerHTML = result;\n\n document.body.appendChild(element);\n\n result = element.innerText;\n\n document.body.removeChild(element);\n\n return result;\n};\n\nexport const getElementTextLength = (element: Element) => {\n let textLength = 0;\n\n try {\n textLength = convertHTMLToText(element.outerHTML).length;\n } catch (e) {\n // Do nothing\n }\n\n return textLength;\n};\n"],"mappings":"AAAA,SACIA,mBAAmB,EACnBC,mBAAmB,EACnBC,oBAAoB,EACpBC,gBAAgB,EAChBC,eAAe,EACfC,qBAAqB,EACrBC,qBAAqB,EACrBC,sBAAsB,QACnB,oBAAoB;AAC3B,SAASC,UAAU,EAAEC,YAAY,QAAQ,SAAS;AAElD,OAAO,MAAMC,iBAAiB,GAAIC,IAAY,IAAK;EAC/C,MAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAE7CF,OAAO,CAACG,KAAK,CAACC,QAAQ,GAAG,UAAU;EACnCJ,OAAO,CAACG,KAAK,CAACE,OAAO,GAAG,GAAG;EAE3BL,OAAO,CAACM,eAAe,GAAG,MAAM;EAChCN,OAAO,CAACO,SAAS,GAAGR,IAAI;EAExBE,QAAQ,CAACO,IAAI,CAACC,WAAW,CAACT,OAAO,CAAC;EAElC,IAAIU,MAAM,GAAGV,OAAO,CAACW,SAAS;EAE9BV,QAAQ,CAACO,IAAI,CAACI,WAAW,CAACZ,OAAO,CAAC;EAElCU,MAAM,GAAGb,YAAY,CAACa,MAAM,CAAC;EAE7BA,MAAM,GAAGA,MAAM,CACVG,OAAO,CAACtB,gBAAgB,EAAE,IAAI,CAAC,CAC/BsB,OAAO,CACJzB,mBAAmB,EACnB,4EACJ,CAAC,CACAyB,OAAO,CAACxB,mBAAmB,EAAE,mDAAmD,CAAC,CACjFwB,OAAO,CACJvB,oBAAoB,EACpB,CAACwB,CAAC,EAAEC,MAA0B,EAAEC,IAAY,EAAEC,KAAa,EAAEC,MAAc,KAAK;IAC5E,MAAMC,UAAU,GAAGJ,MAAM,GAAG,WAAWA,MAAM,IAAI,GAAG,EAAE;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AAM;AACjB,CAAC;AAED,OAAO,MAAMW,oBAAoB,GAAIrB,OAAgB,IAAK;EACtD,IAAIsB,UAAU,GAAG,CAAC;EAElB,IAAI;IACAA,UAAU,GAAGF,iBAAiB,CAACpB,OAAO,CAACuB,SAAS,CAAC,CAACC,MAAM;EAC5D,CAAC,CAAC,OAAOC,CAAC,EAAE;IACR;EAAA;EAGJ,OAAOH,UAAU;AACrB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React, { ChangeEvent, CSSProperties, FocusEventHandler, KeyboardEventHandler, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { PopupAlignment } from '../../constants/alignment';
|
|
3
|
+
export type EmojiInputProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Access token of the logged-in user. Is needed to load and save the history of the emojis.
|
|
6
|
+
*/
|
|
7
|
+
accessToken?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Sets the height of the input field to a fixed value. If this value is not set, the component will use the needed height until the maximum height is reached.
|
|
10
|
+
*/
|
|
11
|
+
height?: CSSProperties['height'];
|
|
12
|
+
/**
|
|
13
|
+
* HTML id of the input element
|
|
14
|
+
*/
|
|
15
|
+
inputId?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Disables the input so that it cannot be changed anymore
|
|
18
|
+
*/
|
|
19
|
+
isDisabled?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Sets the maximum height of the input field.
|
|
22
|
+
*/
|
|
23
|
+
maxHeight?: CSSProperties['maxHeight'];
|
|
24
|
+
/**
|
|
25
|
+
* Function that is executed when the input field loses focus.
|
|
26
|
+
*/
|
|
27
|
+
onBlur?: FocusEventHandler<HTMLDivElement>;
|
|
28
|
+
/**
|
|
29
|
+
* Function that is executed when the input field gets the focus.
|
|
30
|
+
*/
|
|
31
|
+
onFocus?: FocusEventHandler<HTMLDivElement>;
|
|
32
|
+
/**
|
|
33
|
+
* Function that is executed when the text of the input changes. In addition to the original
|
|
34
|
+
* event, the original text is returned as second parameter, in which the internally used HTML
|
|
35
|
+
* elements have been converted back to BB codes.
|
|
36
|
+
*/
|
|
37
|
+
onInput?: (event: ChangeEvent<HTMLDivElement>, originalText: string) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Function that is executed when a key is pressed down.
|
|
40
|
+
*/
|
|
41
|
+
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
|
|
42
|
+
/**
|
|
43
|
+
* Function to be executed if the prefixElement is removed.
|
|
44
|
+
*/
|
|
45
|
+
onPrefixElementRemove?: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Function that is executed when the visibility of the popup changes.
|
|
48
|
+
* @param {boolean} isVisible - Whether the popup is visible or not
|
|
49
|
+
*/
|
|
50
|
+
onPopupVisibilityChange?: (isVisible: boolean) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Person id of the logged-in user. Is needed to load and save the history of the emojis.
|
|
53
|
+
*/
|
|
54
|
+
personId?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Placeholder for the input field
|
|
57
|
+
*/
|
|
58
|
+
placeholder?: string | ReactElement;
|
|
59
|
+
/**
|
|
60
|
+
* Sets the alignment of the popup to a fixed value. If this value is not set, the component
|
|
61
|
+
* calculates the best position on its own. Use the imported 'PopupAlignment' enum to set this
|
|
62
|
+
* value.
|
|
63
|
+
*/
|
|
64
|
+
popupAlignment?: PopupAlignment;
|
|
65
|
+
/**
|
|
66
|
+
* Element that is rendered before the input field but the placeholder is still visible.
|
|
67
|
+
*/
|
|
68
|
+
prefixElement?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Element that is rendered inside the EmojiInput on the right side.
|
|
71
|
+
*/
|
|
72
|
+
rightElement?: ReactNode;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the placeholder should be shown after the input has focus.
|
|
75
|
+
*/
|
|
76
|
+
shouldHidePlaceholderOnFocus?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Prevents the EmojiPickerPopup icon from being displayed
|
|
79
|
+
*/
|
|
80
|
+
shouldPreventEmojiPicker?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The plain text value of the input field. Instead of HTML elements BB codes must be used at
|
|
83
|
+
* this point. These are then converted by the input field into corresponding HTML elements.
|
|
84
|
+
*/
|
|
85
|
+
value: string;
|
|
86
|
+
};
|
|
87
|
+
export type EmojiInputRef = {
|
|
88
|
+
insertTextAtCursorPosition: (text: string) => void;
|
|
89
|
+
replaceText: (searchText: string, replaceText: string) => void;
|
|
90
|
+
startProgress: (durationInSeconds: number) => void;
|
|
91
|
+
stopProgress: () => void;
|
|
92
|
+
};
|
|
93
|
+
declare const EmojiInput: React.ForwardRefExoticComponent<EmojiInputProps & React.RefAttributes<EmojiInputRef>>;
|
|
94
|
+
export default EmojiInput;
|