@chayns-components/emoji-input 5.0.0-beta.135 → 5.0.0-beta.137
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/lib/utils/selection.js
CHANGED
|
@@ -29,7 +29,7 @@ const saveSelection = function (element) {
|
|
|
29
29
|
nodeType,
|
|
30
30
|
nodeValue
|
|
31
31
|
} = _ref;
|
|
32
|
-
return nodeType !== Node.TEXT_NODE || nodeValue !== '';
|
|
32
|
+
return nodeType !== Node.TEXT_NODE || nodeValue !== '' && nodeValue !== '\u200B';
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
childIndex = childNodesArray.indexOf(anchorNode);
|
|
@@ -38,23 +38,24 @@ const saveSelection = function (element) {
|
|
|
38
38
|
};
|
|
39
39
|
exports.saveSelection = saveSelection;
|
|
40
40
|
const restoreSelection = element => {
|
|
41
|
+
var _childNode;
|
|
41
42
|
let childNode = element.childNodes[childIndex];
|
|
42
43
|
const selection = window.getSelection();
|
|
43
44
|
console.debug('restoreSelection', {
|
|
44
|
-
childIndex,
|
|
45
45
|
childNode,
|
|
46
46
|
childNodes: element.childNodes,
|
|
47
|
+
childIndex,
|
|
47
48
|
element,
|
|
48
49
|
endOffset,
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
typeOfNodeValue: typeof ((_childNode = childNode) === null || _childNode === void 0 ? void 0 : _childNode.nodeValue),
|
|
51
|
+
selection
|
|
51
52
|
});
|
|
52
53
|
if (!childNode || !element || !selection) {
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
if (typeof childNode.nodeValue !== 'string') {
|
|
56
57
|
var _childNode$parentNode;
|
|
57
|
-
const textNode = document.createTextNode('');
|
|
58
|
+
const textNode = document.createTextNode('\u200B');
|
|
58
59
|
(_childNode$parentNode = childNode.parentNode) === null || _childNode$parentNode === void 0 ? void 0 : _childNode$parentNode.insertBefore(textNode, childNode.nextSibling);
|
|
59
60
|
childNode = textNode;
|
|
60
61
|
endOffset = 0;
|
|
@@ -67,7 +68,7 @@ const restoreSelection = element => {
|
|
|
67
68
|
startOffset = childNode.nodeValue.length;
|
|
68
69
|
} else {
|
|
69
70
|
var _childNode$parentNode2;
|
|
70
|
-
const textNode = document.createTextNode('');
|
|
71
|
+
const textNode = document.createTextNode('\u200B');
|
|
71
72
|
(_childNode$parentNode2 = childNode.parentNode) === null || _childNode$parentNode2 === void 0 ? void 0 : _childNode$parentNode2.insertBefore(textNode, childNode.nextSibling);
|
|
72
73
|
childNode = textNode;
|
|
73
74
|
endOffset = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.js","names":["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","exports","restoreSelection","childNode","console","debug","_childNode$parentNode","textNode","document","createTextNode","parentNode","insertBefore","nextSibling","_childNode$parentNode2","createRange","setStart","setEnd","removeAllRanges","addRange","collapse","moveSelectionOffset","distance","setChildIndex","index"],"sources":["../../src/utils/selection.ts"],"sourcesContent":["let 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 })
|
|
1
|
+
{"version":3,"file":"selection.js","names":["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","exports","restoreSelection","_childNode","childNode","console","debug","typeOfNodeValue","_childNode$parentNode","textNode","document","createTextNode","parentNode","insertBefore","nextSibling","_childNode$parentNode2","createRange","setStart","setEnd","removeAllRanges","addRange","collapse","moveSelectionOffset","distance","setChildIndex","index"],"sources":["../../src/utils/selection.ts"],"sourcesContent":["let 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 console.debug('restoreSelection', {\n childNode,\n childNodes: element.childNodes,\n childIndex,\n element,\n endOffset,\n typeOfNodeValue: typeof childNode?.nodeValue,\n selection,\n });\n\n if (!childNode || !element || !selection) {\n return;\n }\n\n if (typeof childNode.nodeValue !== 'string') {\n const textNode = document.createTextNode('\\u200B');\n\n childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);\n\n childNode = textNode;\n\n endOffset = 0;\n startOffset = 0;\n } else if (childNode.nodeValue && endOffset > childNode.nodeValue.length) {\n if (childNode.nextSibling) {\n childNode = childNode.nextSibling;\n\n if (childNode.nodeType === Node.TEXT_NODE && childNode.nodeValue) {\n endOffset = childNode.nodeValue.length;\n startOffset = childNode.nodeValue.length;\n } else {\n const textNode = document.createTextNode('\\u200B');\n\n childNode.parentNode?.insertBefore(textNode, childNode.nextSibling);\n\n childNode = textNode;\n\n endOffset = 0;\n startOffset = 0;\n }\n } else {\n endOffset = childNode.nodeValue.length;\n startOffset = childNode.nodeValue.length;\n }\n }\n\n const range = document.createRange();\n\n range.setStart(childNode, startOffset);\n range.setEnd(childNode, endOffset);\n\n selection.removeAllRanges();\n selection.addRange(range);\n\n range.collapse(true);\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"],"mappings":";;;;;;AAAA,IAAIA,UAAU,GAAG,CAAC,CAAC;AACnB,IAAIC,SAAS,GAAG,CAAC,CAAC;AAClB,IAAIC,WAAW,GAAG,CAAC,CAAC;AAMb,MAAMC,aAAa,GAAG,SAAAA,CACzBC,OAAuB,EAEtB;EAAA,IADD;IAAEC;EAAiD,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEzD,MAAMG,SAAS,GAAGC,MAAM,CAACC,YAAY,EAAE;EAEvC,IAAI,CAACF,SAAS,EAAE;IACZ;EACJ;EAEA,MAAM;IAAEG;EAAW,CAAC,GAAGH,SAAS;EAEhC,IAAI,CAACG,UAAU,EAAE;IACb;EACJ;EAEA,MAAMC,KAAK,GAAGJ,SAAS,CAACK,UAAU,CAAC,CAAC,CAAC;EAErC,IAAIC,eAAe,GAAGC,KAAK,CAACC,IAAI,CAACb,OAAO,CAACc,UAAU,CAAC;EAEpD,IAAIb,0BAA0B,EAAE;IAC5BU,eAAe,GAAGA,eAAe,CAACI,MAAM,CACpCC,IAAA;MAAA,IAAC;QAAEC,QAAQ;QAAEC;MAAU,CAAC,GAAAF,IAAA;M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C,WAAW,IAAI8C,QAAQ;AAC3B,CAAC;AAACtB,OAAA,CAAAqB,mBAAA,GAAAA,mBAAA;AAEK,MAAME,aAAa,GAAIC,KAAa,IAAK;EAC5ClD,UAAU,GAAGkD,KAAK;AACtB,CAAC;AAACxB,OAAA,CAAAuB,aAAA,GAAAA,aAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/emoji-input",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.137",
|
|
4
4
|
"description": "Input field that supports HTML elements and emojis",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "a5fe11f4ae57362726b46828a47ae15af90a512c"
|
|
72
72
|
}
|