@chayns-components/emoji-input 5.0.0-beta.127 → 5.0.0-beta.129
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/components/emoji-input/EmojiInput.styles.js +4 -0
- package/lib/components/emoji-input/EmojiInput.styles.js.map +1 -1
- package/lib/constants/regex.d.ts +0 -1
- package/lib/constants/regex.js +3 -5
- package/lib/constants/regex.js.map +1 -1
- package/lib/utils/insert.js +11 -3
- package/lib/utils/insert.js.map +1 -1
- package/lib/utils/selection.d.ts +1 -0
- package/lib/utils/selection.js +15 -4
- package/lib/utils/selection.js.map +1 -1
- package/lib/utils/text.js +1 -10
- package/lib/utils/text.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmojiInput.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_font","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","StyledEmojiInput","styled","div","_ref","theme","_ref2","isDisabled","_ref3","exports","StyledEmojiInputContent","_ref4","isRightElementGiven","css","StyledEmojiInputEditor","_ref5","text","getFontFamily","_ref6","placeholder","_ref7","_ref8","_ref9","StyledEmojiInputRightWrapper"],"sources":["../../../src/components/emoji-input/EmojiInput.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css } from 'styled-components';\nimport { getFontFamily } from '../../utils/font';\nimport type { EmojiInputProps } from './EmojiInput';\n\ntype StyledEmojiInputProps = WithTheme<Pick<EmojiInputProps, 'isDisabled'>>;\n\nexport const StyledEmojiInput = styled.div<StyledEmojiInputProps>`\n align-items: center;\n background-color: ${({ theme }: StyledEmojiInputProps) => theme['100']};\n border-radius: 3px;\n display: flex;\n min-height: 42px;\n opacity: ${({ isDisabled }) => (isDisabled ? 0.5 : 1)};\n pointer-events: ${({ isDisabled }) => (isDisabled ? 'none' : 'initial')};\n position: relative;\n transition: opacity 0.3s ease;\n`;\n\ntype StyledEmojiInputContentProps = {\n isRightElementGiven: boolean;\n};\n\nexport const StyledEmojiInputContent = styled.div<StyledEmojiInputContentProps>`\n align-items: end;\n border: 1px solid rgba(160, 160, 160, 0.3);\n border-radius: 3px;\n display: flex;\n flex: 1 1 auto;\n gap: 10px;\n padding: 8px 10px;\n\n ${({ isRightElementGiven }) =>\n isRightElementGiven &&\n css`\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-right-width: 0;\n `}\n`;\n\ntype StyledEmojiInputEditorProps = WithTheme<Pick<EmojiInputProps, 'placeholder'>>;\n\nexport const StyledEmojiInputEditor = styled.div<StyledEmojiInputEditorProps>`\n color: ${({ theme }: StyledEmojiInputEditorProps) => theme.text};\n flex: 1 1 auto;\n font-family: ${getFontFamily};\n max-height: 210px;\n overflow-y: scroll;\n word-break: break-word;\n\n // This fixes a bug where the field is not editable in certain browsers.\n // This is for example the case on iOS 15 or older.\n -webkit-user-modify: read-write;\n -webkit-user-select: text;\n\n &:empty:not(:focus):before {\n content: '${({ placeholder }) => placeholder}';\n color: ${({ theme }: StyledEmojiInputEditorProps) => theme['006']};\n pointer-events: none;\n }\n\n lc_mention {\n font-weight: bold;\n }\n\n // Styles for custom scrollbar\n ::-webkit-scrollbar {\n width: 5px;\n }\n\n ::-webkit-scrollbar-track {\n background-color: transparent;\n }\n\n ::-webkit-scrollbar-button {\n background-color: transparent;\n height: 5px;\n }\n\n ::-webkit-scrollbar-thumb {\n background-color: rgba(\n ${({ theme }: StyledEmojiInputEditorProps) => theme['text-rgb']},\n 0.15\n );\n border-radius: 20px;\n }\n\n // Scrollbar styles for Firefox. The above styles are not supported in Firefox, these styles are\n // only supported in Firefox:\n * {\n scrollbar-color: rgba(\n ${({ theme }: StyledEmojiInputEditorProps) => theme['text-rgb']},\n 0.15\n )\n transparent;\n scrollbar-width: thin;\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AC;IAAEf;EAAmC,CAAC,GAAAe,KAAA;EAAA,OAAKf,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AAC1E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAcgB,KAAA;EAAA,IAAC;IAAEhB;EAAmC,CAAC,GAAAgB,KAAA;EAAA,OAAKhB,KAAK,CAAC,UAAU,CAAC;AAAA,CAAC;AAC5E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkBiB,KAAA;EAAA,IAAC;IAAEjB;EAAmC,CAAC,GAAAiB,KAAA;EAAA,OAAKjB,KAAK,CAAC,UAAU,CAAC;AAAA,CAAC;AAChF;AACA;AACA;AACA;AACA;AACA,CAAC;AAACI,OAAA,CAAAK,sBAAA,GAAAA,sBAAA;AAEK,MAAMS,4BAA4B,GAAGrB,yBAAM,CAACC,GAAI;AACvD;AACA;AACA;AACA;AACA;AACA,CAAC;AAACM,OAAA,CAAAc,4BAAA,GAAAA,4BAAA"}
|
|
1
|
+
{"version":3,"file":"EmojiInput.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_font","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","StyledEmojiInput","styled","div","_ref","theme","_ref2","isDisabled","_ref3","exports","StyledEmojiInputContent","_ref4","isRightElementGiven","css","StyledEmojiInputEditor","_ref5","text","getFontFamily","_ref6","placeholder","_ref7","_ref8","_ref9","StyledEmojiInputRightWrapper"],"sources":["../../../src/components/emoji-input/EmojiInput.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css } from 'styled-components';\nimport { getFontFamily } from '../../utils/font';\nimport type { EmojiInputProps } from './EmojiInput';\n\ntype StyledEmojiInputProps = WithTheme<Pick<EmojiInputProps, 'isDisabled'>>;\n\nexport const StyledEmojiInput = styled.div<StyledEmojiInputProps>`\n align-items: center;\n background-color: ${({ theme }: StyledEmojiInputProps) => theme['100']};\n border-radius: 3px;\n display: flex;\n min-height: 42px;\n opacity: ${({ isDisabled }) => (isDisabled ? 0.5 : 1)};\n pointer-events: ${({ isDisabled }) => (isDisabled ? 'none' : 'initial')};\n position: relative;\n transition: opacity 0.3s ease;\n`;\n\ntype StyledEmojiInputContentProps = {\n isRightElementGiven: boolean;\n};\n\nexport const StyledEmojiInputContent = styled.div<StyledEmojiInputContentProps>`\n align-items: end;\n border: 1px solid rgba(160, 160, 160, 0.3);\n border-radius: 3px;\n display: flex;\n flex: 1 1 auto;\n gap: 10px;\n padding: 8px 10px;\n\n ${({ isRightElementGiven }) =>\n isRightElementGiven &&\n css`\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-right-width: 0;\n `}\n`;\n\ntype StyledEmojiInputEditorProps = WithTheme<Pick<EmojiInputProps, 'placeholder'>>;\n\nexport const StyledEmojiInputEditor = styled.div<StyledEmojiInputEditorProps>`\n color: ${({ theme }: StyledEmojiInputEditorProps) => theme.text};\n flex: 1 1 auto;\n font-family: ${getFontFamily};\n max-height: 210px;\n overflow-y: scroll;\n word-break: break-word;\n\n // This fixes a bug where the field is not editable in certain browsers.\n // This is for example the case on iOS 15 or older.\n -webkit-user-modify: read-write;\n -webkit-user-select: text;\n\n &:empty:not(:focus):before {\n content: '${({ placeholder }) => placeholder}';\n color: ${({ theme }: StyledEmojiInputEditorProps) => theme['006']};\n pointer-events: none;\n }\n\n lc_mention {\n font-weight: bold;\n\n span {\n opacity: 0.5;\n }\n }\n\n // Styles for custom scrollbar\n ::-webkit-scrollbar {\n width: 5px;\n }\n\n ::-webkit-scrollbar-track {\n background-color: transparent;\n }\n\n ::-webkit-scrollbar-button {\n background-color: transparent;\n height: 5px;\n }\n\n ::-webkit-scrollbar-thumb {\n background-color: rgba(\n ${({ theme }: StyledEmojiInputEditorProps) => theme['text-rgb']},\n 0.15\n );\n border-radius: 20px;\n }\n\n // Scrollbar styles for Firefox. The above styles are not supported in Firefox, these styles are\n // only supported in Firefox:\n * {\n scrollbar-color: rgba(\n ${({ theme }: StyledEmojiInputEditorProps) => theme['text-rgb']},\n 0.15\n )\n transparent;\n scrollbar-width: thin;\n }\n`;\n\nexport const StyledEmojiInputRightWrapper = styled.div`\n align-self: stretch;\n border-bottom-right-radius: 3px;\n border-top-right-radius: 3px;\n flex: 0 0 auto;\n overflow: hidden;\n`;\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAAiD,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAA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AAK,CAACW,IAAI;AAAA,CAAC;AACpE;AACA,mBAAmBC,mBAAc;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoBC,KAAA;EAAA,IAAC;IAAEC;EAAY,CAAC,GAAAD,KAAA;EAAA,OAAKC,WAAW;AAAA,CAAC;AACrD,iBAAiBC,KAAA;EAAA,IAAC;IAAEf;EAAmC,CAAC,GAAAe,KAAA;EAAA,OAAKf,KAAK,CAAC,KAAK,CAAC;AAAA,CAAC;AAC1E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAcgB,KAAA;EAAA,IAAC;IAAEhB;EAAmC,CAAC,GAAAgB,KAAA;EAAA,OAAKhB,KAAK,CAAC,UAAU,CAAC;AAAA,CAAC;AAC5E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkBiB,KAAA;EAAA,IAAC;IAAEjB;EAAmC,CAAC,GAAAiB,KAAA;EAAA,OAAKjB,KAAK,CAAC,UAAU,CAAC;AAAA,CAAC;AAChF;AACA;AACA;AACA;AACA;AACA,CAAC;AAACI,OAAA,CAAAK,sBAAA,GAAAA,sBAAA;AAEK,MAAMS,4BAA4B,GAAGrB,yBAAM,CAACC,GAAI;AACvD;AACA;AACA;AACA;AACA;AACA,CAAC;AAACM,OAAA,CAAAc,4BAAA,GAAAA,4BAAA"}
|
package/lib/constants/regex.d.ts
CHANGED
package/lib/constants/regex.js
CHANGED
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.HTML_LC_MENTION_REGEX = exports.BB_LC_MENTION_REGEX =
|
|
7
|
-
const BB_LC_MENTION_REGEX = /\[lc_mention(
|
|
6
|
+
exports.HTML_LC_MENTION_REGEX = exports.BB_LC_MENTION_REGEX = void 0;
|
|
7
|
+
const BB_LC_MENTION_REGEX = /\[lc_mention.+?id="([^"]+?)"](.+?)\[\/lc_mention]/g;
|
|
8
8
|
exports.BB_LC_MENTION_REGEX = BB_LC_MENTION_REGEX;
|
|
9
|
-
const
|
|
10
|
-
exports.BB_LC_MENTION_ID_REGEX = BB_LC_MENTION_ID_REGEX;
|
|
11
|
-
const HTML_LC_MENTION_REGEX = /<lc_mention.+?id="([^"]+?)">([^<]+?)<\/lc_mention>/g;
|
|
9
|
+
const HTML_LC_MENTION_REGEX = /<lc_mention.+?id="([^"]+?)">(?:<span.*?<\/span>)*(.+?)<\/lc_mention>/g;
|
|
12
10
|
exports.HTML_LC_MENTION_REGEX = HTML_LC_MENTION_REGEX;
|
|
13
11
|
//# sourceMappingURL=regex.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regex.js","names":["BB_LC_MENTION_REGEX","exports","
|
|
1
|
+
{"version":3,"file":"regex.js","names":["BB_LC_MENTION_REGEX","exports","HTML_LC_MENTION_REGEX"],"sources":["../../src/constants/regex.ts"],"sourcesContent":["export const BB_LC_MENTION_REGEX = /\\[lc_mention.+?id=\"([^\"]+?)\"](.+?)\\[\\/lc_mention]/g;\n\nexport const HTML_LC_MENTION_REGEX =\n /<lc_mention.+?id=\"([^\"]+?)\">(?:<span.*?<\\/span>)*(.+?)<\\/lc_mention>/g;\n"],"mappings":";;;;;;AAAO,MAAMA,mBAAmB,GAAG,oDAAoD;AAACC,OAAA,CAAAD,mBAAA,GAAAA,mBAAA;AAEjF,MAAME,qBAAqB,GAC9B,uEAAuE;AAACD,OAAA,CAAAC,qBAAA,GAAAA,qBAAA"}
|
package/lib/utils/insert.js
CHANGED
|
@@ -31,9 +31,17 @@ const insertTextAtCursorPosition = _ref => {
|
|
|
31
31
|
const firstPart = parts.shift();
|
|
32
32
|
const textNodes = parts.map(part => document.createTextNode(part));
|
|
33
33
|
range.deleteContents();
|
|
34
|
-
if (
|
|
35
|
-
selection.anchorNode.
|
|
36
|
-
|
|
34
|
+
if (firstPart) {
|
|
35
|
+
if (selection.anchorNode.nodeType === Node.TEXT_NODE) {
|
|
36
|
+
selection.anchorNode.nodeValue += firstPart;
|
|
37
|
+
(0, _selection.moveSelectionOffset)(firstPart.length);
|
|
38
|
+
} else if (selection.anchorNode === editorElement) {
|
|
39
|
+
const textNode = document.createTextNode(firstPart);
|
|
40
|
+
editorElement.appendChild(textNode);
|
|
41
|
+
const textNodeIndex = Array.from(editorElement.childNodes).indexOf(textNode);
|
|
42
|
+
(0, _selection.moveSelectionOffset)(firstPart.length);
|
|
43
|
+
(0, _selection.setChildIndex)(textNodeIndex);
|
|
44
|
+
}
|
|
37
45
|
}
|
|
38
46
|
(0, _selection.restoreSelection)(editorElement);
|
|
39
47
|
if (textNodes.length > 0) {
|
package/lib/utils/insert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert.js","names":["_selection","require","insertTextAtCursorPosition","_ref","editorElement","text","selection","window","getSelection","saveSelection","anchorNode","contains","range","getRangeAt","parts","split","firstPart","shift","textNodes","map","part","document","createTextNode","deleteContents","nodeType","Node","TEXT_NODE","nodeValue","moveSelectionOffset","length","restoreSelection","brElement","createElement","insertNode","setEndAfter","setStartAfter","forEach","
|
|
1
|
+
{"version":3,"file":"insert.js","names":["_selection","require","insertTextAtCursorPosition","_ref","editorElement","text","selection","window","getSelection","saveSelection","anchorNode","contains","range","getRangeAt","parts","split","firstPart","shift","textNodes","map","part","document","createTextNode","deleteContents","nodeType","Node","TEXT_NODE","nodeValue","moveSelectionOffset","length","textNode","appendChild","textNodeIndex","Array","from","childNodes","indexOf","setChildIndex","restoreSelection","brElement","createElement","insertNode","setEndAfter","setStartAfter","forEach","index","collapse","removeAllRanges","addRange","innerText","exports"],"sources":["../../src/utils/insert.ts"],"sourcesContent":["import { moveSelectionOffset, restoreSelection, saveSelection, setChildIndex } from './selection';\n\ninterface InsertTextAtCursorPositionOptions {\n editorElement: HTMLDivElement;\n text: string;\n}\n\n/**\n * This function inserts the passed text at the correct position in the editor element. If the\n * element has the focus, the new emoji is inserted at the cursor position. If not, the emoji\n * will be appended to the back of the input field content.\n *\n * In addition, this function also sets the cursor to the correct position when the input field\n * has the focus. For this purpose, the current position of the cursor or a selection is read to\n * calculate the cursor position after inserting the text.\n *\n * @param {Object} options - Object with element and text to insert\n * @param {HTMLDivElement} options.editorElement - Element to insert text into\n * @param {string} options.text - Text to insert into element\n */\nexport const insertTextAtCursorPosition = ({\n editorElement,\n text,\n}: InsertTextAtCursorPositionOptions) => {\n const selection = window.getSelection();\n\n saveSelection(editorElement);\n\n if (selection?.anchorNode && editorElement.contains(selection.anchorNode)) {\n let range = selection.getRangeAt(0);\n\n const parts = text.split(/\\r\\n|\\r|\\n/);\n\n const firstPart = parts.shift();\n\n const textNodes = parts.map((part) => document.createTextNode(part));\n\n range.deleteContents();\n\n if (firstPart) {\n if (selection.anchorNode.nodeType === Node.TEXT_NODE) {\n selection.anchorNode.nodeValue += firstPart;\n\n moveSelectionOffset(firstPart.length);\n } else if (selection.anchorNode === editorElement) {\n const textNode = document.createTextNode(firstPart);\n\n editorElement.appendChild(textNode);\n\n const textNodeIndex = Array.from(editorElement.childNodes).indexOf(textNode);\n\n moveSelectionOffset(firstPart.length);\n setChildIndex(textNodeIndex);\n }\n }\n\n restoreSelection(editorElement);\n\n if (textNodes.length > 0) {\n range = selection.getRangeAt(0);\n\n let brElement = document.createElement('br');\n\n range.insertNode(brElement);\n range.setEndAfter(brElement);\n range.setStartAfter(brElement);\n\n textNodes.forEach((textNode, index) => {\n range.insertNode(textNode);\n range.setEndAfter(textNode);\n range.setStartAfter(textNode);\n\n if (index !== textNodes.length - 1) {\n brElement = document.createElement('br');\n\n range.insertNode(brElement);\n range.setEndAfter(brElement);\n range.setStartAfter(brElement);\n }\n });\n\n range.collapse(false);\n\n selection.removeAllRanges();\n selection.addRange(range);\n }\n } else {\n // eslint-disable-next-line no-param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AAC;AAAC6C,OAAA,CAAAhD,0BAAA,GAAAA,0BAAA"}
|
package/lib/utils/selection.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ interface SaveSelectionOptions {
|
|
|
4
4
|
export declare const saveSelection: (element: HTMLDivElement, { shouldIgnoreEmptyTextNodes }?: SaveSelectionOptions) => void;
|
|
5
5
|
export declare const restoreSelection: (element: HTMLDivElement) => void;
|
|
6
6
|
export declare const moveSelectionOffset: (distance: number) => void;
|
|
7
|
+
export declare const setChildIndex: (index: number) => void;
|
|
7
8
|
export {};
|
package/lib/utils/selection.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.saveSelection = exports.restoreSelection = exports.moveSelectionOffset = void 0;
|
|
6
|
+
exports.setChildIndex = exports.saveSelection = exports.restoreSelection = exports.moveSelectionOffset = void 0;
|
|
7
7
|
let childIndex = -1;
|
|
8
8
|
let endOffset = -1;
|
|
9
9
|
let startOffset = -1;
|
|
@@ -43,16 +43,23 @@ const restoreSelection = element => {
|
|
|
43
43
|
if (!childNode || !element || !selection) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
if (childNode.nodeValue
|
|
46
|
+
if (typeof childNode.nodeValue !== 'string') {
|
|
47
|
+
var _childNode$parentNode;
|
|
48
|
+
const textNode = document.createTextNode('');
|
|
49
|
+
(_childNode$parentNode = childNode.parentNode) === null || _childNode$parentNode === void 0 ? void 0 : _childNode$parentNode.insertBefore(textNode, childNode.nextSibling);
|
|
50
|
+
childNode = textNode;
|
|
51
|
+
endOffset = 0;
|
|
52
|
+
startOffset = 0;
|
|
53
|
+
} else if (childNode.nodeValue && endOffset > childNode.nodeValue.length) {
|
|
47
54
|
if (childNode.nextSibling) {
|
|
48
55
|
childNode = childNode.nextSibling;
|
|
49
56
|
if (childNode.nodeType === Node.TEXT_NODE && childNode.nodeValue) {
|
|
50
57
|
endOffset = childNode.nodeValue.length;
|
|
51
58
|
startOffset = childNode.nodeValue.length;
|
|
52
59
|
} else {
|
|
53
|
-
var _childNode$
|
|
60
|
+
var _childNode$parentNode2;
|
|
54
61
|
const textNode = document.createTextNode('');
|
|
55
|
-
(_childNode$
|
|
62
|
+
(_childNode$parentNode2 = childNode.parentNode) === null || _childNode$parentNode2 === void 0 ? void 0 : _childNode$parentNode2.insertBefore(textNode, childNode.nextSibling);
|
|
56
63
|
childNode = textNode;
|
|
57
64
|
endOffset = 0;
|
|
58
65
|
startOffset = 0;
|
|
@@ -75,4 +82,8 @@ const moveSelectionOffset = distance => {
|
|
|
75
82
|
startOffset += distance;
|
|
76
83
|
};
|
|
77
84
|
exports.moveSelectionOffset = moveSelectionOffset;
|
|
85
|
+
const setChildIndex = index => {
|
|
86
|
+
childIndex = index;
|
|
87
|
+
};
|
|
88
|
+
exports.setChildIndex = setChildIndex;
|
|
78
89
|
//# sourceMappingURL=selection.js.map
|
|
@@ -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","
|
|
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$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 }) => nodeType !== Node.TEXT_NODE || nodeValue !== ''\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 if (typeof childNode.nodeValue !== 'string') {\n const textNode = document.createTextNode('');\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('');\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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S,CAACf,MAAM;IAC5C;EACJ;EAEA,MAAMM,KAAK,GAAGkB,QAAQ,CAACM,WAAW,EAAE;EAEpCxB,KAAK,CAACyB,QAAQ,CAACV,SAAS,EAAE1B,WAAW,CAAC;EACtCW,KAAK,CAAC0B,MAAM,CAACX,SAAS,EAAE3B,SAAS,CAAC;EAElCQ,SAAS,CAAC+B,eAAe,EAAE;EAC3B/B,SAAS,CAACgC,QAAQ,CAAC5B,KAAK,CAAC;EAEzBA,KAAK,CAAC6B,QAAQ,CAAC,IAAI,CAAC;AACxB,CAAC;AAAChB,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAEK,MAAMgB,mBAAmB,GAAIC,QAAgB,IAAK;EACrD3C,SAAS,IAAI2C,QAAQ;EACrB1C,WAAW,IAAI0C,QAAQ;AAC3B,CAAC;AAAClB,OAAA,CAAAiB,mBAAA,GAAAA,mBAAA;AAEK,MAAME,aAAa,GAAIC,KAAa,IAAK;EAC5C9C,UAAU,GAAG8C,KAAK;AACtB,CAAC;AAACpB,OAAA,CAAAmB,aAAA,GAAAA,aAAA"}
|
package/lib/utils/text.js
CHANGED
|
@@ -5,18 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.convertQuotes = exports.convertHTMLToBBCodes = exports.convertBBCodesToHTML = void 0;
|
|
7
7
|
var _regex = require("../constants/regex");
|
|
8
|
-
const replaceWithLcMentionHTML = (lcMention, text) => {
|
|
9
|
-
let attributes = '';
|
|
10
|
-
const idMatches = lcMention.match(_regex.BB_LC_MENTION_ID_REGEX);
|
|
11
|
-
const match = idMatches === null || idMatches === void 0 ? void 0 : idMatches[1];
|
|
12
|
-
if (match) {
|
|
13
|
-
attributes += `id="${match}"`;
|
|
14
|
-
}
|
|
15
|
-
return `<lc_mention contenteditable="false" ${attributes}>${text}</lc_mention>`;
|
|
16
|
-
};
|
|
17
8
|
const convertBBCodesToHTML = text => {
|
|
18
9
|
let result = text;
|
|
19
|
-
result = result.replace(_regex.BB_LC_MENTION_REGEX,
|
|
10
|
+
result = result.replace(_regex.BB_LC_MENTION_REGEX, '<lc_mention contenteditable="false" id="$1"><span>@</span>$2</lc_mention>');
|
|
20
11
|
return result;
|
|
21
12
|
};
|
|
22
13
|
exports.convertBBCodesToHTML = convertBBCodesToHTML;
|
package/lib/utils/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":["_regex","require","
|
|
1
|
+
{"version":3,"file":"text.js","names":["_regex","require","convertBBCodesToHTML","text","result","replace","BB_LC_MENTION_REGEX","exports","convertHTMLToBBCodes","HTML_LC_MENTION_REGEX","convertQuotes","regexForQuotes","regexForQuoteStart","formattedQuotes","match","startsWith","String","fromCharCode"],"sources":["../../src/utils/text.ts"],"sourcesContent":["import { BB_LC_MENTION_REGEX, HTML_LC_MENTION_REGEX } from '../constants/regex';\n\nexport const convertBBCodesToHTML = (text: string) => {\n let result = text;\n\n result = result.replace(\n BB_LC_MENTION_REGEX,\n '<lc_mention contenteditable=\"false\" id=\"$1\"><span>@</span>$2</lc_mention>'\n );\n\n return result;\n};\n\nexport const convertHTMLToBBCodes = (text: string) => {\n let result = text;\n\n result = result.replace(HTML_LC_MENTION_REGEX, '[lc_mention id=\"$1\"]$2[/lc_mention]');\n\n return result;\n};\n\nexport const convertQuotes = (text: string) => {\n const regexForQuotes =\n /(?<=[\\s<>]|^)(\"(?=\\w)|(?<=\\w)\")(?=[\\s<>]|$)|(?<=[^\\w\\s\\u{1F000}-\\u{1F9FF}])(?![^<]*>)(\"(?![^<]*>[^<]*<\\/lc_mention>)(?=\\w)|(?<=[^\\w\\s\\u{1F000}-\\u{1F9FF}])(?![^<]*>)(\"(?![^<]*>[^<]*<\\/lc_mention>)(?=\\^)|(?<=[^\\w\\s\\u{1F000}-\\u{1F9FF}])(?![^<]*>)(\"(?![^<]*>[^<]*<\\/lc_mention>)(?<=[^\\w\\s\\u{1F000}-\\u{1F9FF}]))))/gu;\n\n const regexForQuoteStart = /„(\\s|$)/g;\n\n const formattedQuotes = text.replace(regexForQuotes, (match) => {\n if (match.startsWith(' ') || text.startsWith(match)) {\n return match.startsWith(' ')\n ? ` ${String.fromCharCode(8222)}`\n : String.fromCharCode(8222);\n }\n return String.fromCharCode(8220);\n });\n\n return formattedQuotes.replace(regexForQuoteStart, '\"');\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEO,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAClD,IAAIC,MAAM,GAAGD,IAAI;EAEjBC,MAAM,GAAGA,MAAM,CAACC,OAAO,CACnBC,0BAAmB,EACnB,2EAA2E,CAC9E;EAED,OAAOF,MAAM;AACjB,CAAC;AAACG,OAAA,CAAAL,oBAAA,GAAAA,oBAAA;AAEK,MAAMM,oBAAoB,GAAIL,IAAY,IAAK;EAClD,IAAIC,MAAM,GAAGD,IAAI;EAEjBC,MAAM,GAAGA,MAAM,CAACC,OAAO,CAACI,4BAAqB,EAAE,qCAAqC,CAAC;EAErF,OAAOL,MAAM;AACjB,CAAC;AAACG,OAAA,CAAAC,oBAAA,GAAAA,oBAAA;AAEK,MAAME,aAAa,GAAIP,IAAY,IAAK;EAC3C,MAAMQ,cAAc,GAChB,wTAAwT;EAE5T,MAAMC,kBAAkB,GAAG,UAAU;EAErC,MAAMC,eAAe,GAAGV,IAAI,CAACE,OAAO,CAACM,cAAc,EAAGG,KAAK,IAAK;IAC5D,IAAIA,KAAK,CAACC,UAAU,CAAC,GAAG,CAAC,IAAIZ,IAAI,CAACY,UAAU,CAACD,KAAK,CAAC,EAAE;MACjD,OAAOA,KAAK,CAACC,UAAU,CAAC,GAAG,CAAC,GACrB,IAAGC,MAAM,CAACC,YAAY,CAAC,IAAI,CAAE,EAAC,GAC/BD,MAAM,CAACC,YAAY,CAAC,IAAI,CAAC;IACnC;IACA,OAAOD,MAAM,CAACC,YAAY,CAAC,IAAI,CAAC;EACpC,CAAC,CAAC;EAEF,OAAOJ,eAAe,CAACR,OAAO,CAACO,kBAAkB,EAAE,GAAG,CAAC;AAC3D,CAAC;AAACL,OAAA,CAAAG,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.129",
|
|
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": "d2407a43bc52426e1d39341e53f6a63a76720dab"
|
|
72
72
|
}
|