@antscorp/antsomi-ui 1.3.5-beta.927 → 1.3.5-beta.928
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.
|
@@ -85,7 +85,8 @@ const TagifyInput = forwardRef((props, ref) => {
|
|
|
85
85
|
throw new Error('Tagify instance is not initialized');
|
|
86
86
|
}
|
|
87
87
|
const { scope } = tagifyRef.current?.DOM;
|
|
88
|
-
const
|
|
88
|
+
const anchorNodeInstance = _.get(tagifyRef.current, 'state.selection.anchorNode', null);
|
|
89
|
+
const isValidSelection = isAnchorNodeChildOfElement(scope, anchorNodeInstance);
|
|
89
90
|
if (isValidSelection) {
|
|
90
91
|
const selection = window.getSelection();
|
|
91
92
|
if (!selection?.rangeCount)
|
|
@@ -114,17 +115,20 @@ const TagifyInput = forwardRef((props, ref) => {
|
|
|
114
115
|
}
|
|
115
116
|
const { settings, DOM } = tagifyRef.current;
|
|
116
117
|
const rangeInstance = _.get(tagifyRef.current, 'state.selection.range', null);
|
|
118
|
+
const anchorNodeInstance = _.get(tagifyRef.current, 'state.selection.anchorNode', null);
|
|
117
119
|
const { empty } = settings.classNames;
|
|
118
|
-
const
|
|
120
|
+
const isValidAnchor = isAnchorNodeChildOfElement(DOM.scope, anchorNodeInstance);
|
|
119
121
|
const selection = window.getSelection();
|
|
122
|
+
const isValidRange = selection?.rangeCount && rangeInstance;
|
|
123
|
+
const hasValidSelection = isValidRange && isValidAnchor;
|
|
120
124
|
// In case not have the selection yet or lost the selection,
|
|
121
|
-
if (!
|
|
125
|
+
if (!hasValidSelection) {
|
|
122
126
|
// need to restore the last range before inject a new tag if the last range exists
|
|
123
127
|
if (lastRange.current) {
|
|
124
128
|
selection?.removeAllRanges();
|
|
125
129
|
selection?.addRange(lastRange.current);
|
|
126
130
|
}
|
|
127
|
-
else {
|
|
131
|
+
else if (!isValidRange) {
|
|
128
132
|
// If the last range is lost, need to select the last text node of the input
|
|
129
133
|
const { input: inputElement } = tagifyRef.current.DOM;
|
|
130
134
|
if (inputElement) {
|
|
@@ -180,6 +180,7 @@ export declare const getAttributesString: (map: Map<string, string | boolean | n
|
|
|
180
180
|
* is a child of a specific DOM element.
|
|
181
181
|
*
|
|
182
182
|
* @param {HTMLElement} element - The parent element to check against
|
|
183
|
+
* @param {HTMLElement} anchorNodeInstance - The anchor node of the Tagify instance
|
|
183
184
|
* @returns {boolean} True if the anchor node is a child of the element, false otherwise
|
|
184
185
|
*/
|
|
185
|
-
export declare const isAnchorNodeChildOfElement: (element: Node) => boolean;
|
|
186
|
+
export declare const isAnchorNodeChildOfElement: (element: Node, anchorNodeInstance: Node | null) => boolean;
|
|
@@ -628,9 +628,10 @@ export const getAttributesString = (map) => Array.from(map.entries())
|
|
|
628
628
|
* is a child of a specific DOM element.
|
|
629
629
|
*
|
|
630
630
|
* @param {HTMLElement} element - The parent element to check against
|
|
631
|
+
* @param {HTMLElement} anchorNodeInstance - The anchor node of the Tagify instance
|
|
631
632
|
* @returns {boolean} True if the anchor node is a child of the element, false otherwise
|
|
632
633
|
*/
|
|
633
|
-
export const isAnchorNodeChildOfElement = (element) => {
|
|
634
|
+
export const isAnchorNodeChildOfElement = (element, anchorNodeInstance) => {
|
|
634
635
|
// Get the current selection
|
|
635
636
|
const selection = window.getSelection();
|
|
636
637
|
// Check if there's an active selection
|
|
@@ -644,5 +645,5 @@ export const isAnchorNodeChildOfElement = (element) => {
|
|
|
644
645
|
return false;
|
|
645
646
|
}
|
|
646
647
|
// Use Node.contains() to check if the element contains the anchor node
|
|
647
|
-
return element.contains(anchorNode);
|
|
648
|
+
return element.contains(anchorNode) && element.contains(anchorNodeInstance);
|
|
648
649
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antscorp/antsomi-ui",
|
|
3
|
-
"version": "1.3.5-beta.
|
|
3
|
+
"version": "1.3.5-beta.928",
|
|
4
4
|
"description": "An enterprise-class UI design language and React UI library.",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"dist/*",
|
|
@@ -256,4 +256,3 @@
|
|
|
256
256
|
"react-router-dom": ">= 5.1.0"
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
-
|