@antscorp/antsomi-ui 2.0.45 → 2.0.47
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.
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// Libraries
|
|
3
|
-
import {
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
4
|
// Atoms
|
|
5
5
|
import { Spin, Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
6
|
+
// Hooks
|
|
7
|
+
import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
|
|
6
8
|
// Molecules
|
|
7
9
|
import { ModalV2 } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
8
10
|
import { ProcessLoadingContent } from './styled';
|
|
@@ -17,7 +19,10 @@ export const ProcessLoading = ({ ...restProps }) => {
|
|
|
17
19
|
const { second = 7, message: timeOutMessage = (_jsxs("div", { children: ["This might take a little longer than usual. ", _jsx("br", {}), "Thank you for waiting!"] })), show: showTimeOutMessage = true, } = timeout || {};
|
|
18
20
|
// Effects
|
|
19
21
|
/* Base timeout second to show timeout message */
|
|
20
|
-
|
|
22
|
+
useDeepCompareEffect(() => {
|
|
23
|
+
if (timeoutShowAlert && timeoutShowAlert.current) {
|
|
24
|
+
clearTimeout(timeoutShowAlert.current);
|
|
25
|
+
}
|
|
21
26
|
if (open) {
|
|
22
27
|
timeoutShowAlert.current = setTimeout(() => {
|
|
23
28
|
setShowAlert(true);
|
|
@@ -84,7 +84,8 @@ const TagifyInput = forwardRef((props, ref) => {
|
|
|
84
84
|
throw new Error('Tagify instance is not initialized');
|
|
85
85
|
}
|
|
86
86
|
const { scope } = tagifyRef.current?.DOM;
|
|
87
|
-
const
|
|
87
|
+
const anchorNodeInstance = _.get(tagifyRef.current, 'state.selection.anchorNode', null);
|
|
88
|
+
const isValidSelection = isAnchorNodeChildOfElement(scope, anchorNodeInstance);
|
|
88
89
|
if (isValidSelection) {
|
|
89
90
|
const selection = window.getSelection();
|
|
90
91
|
if (!selection?.rangeCount)
|
|
@@ -113,17 +114,20 @@ const TagifyInput = forwardRef((props, ref) => {
|
|
|
113
114
|
}
|
|
114
115
|
const { settings, DOM } = tagifyRef.current;
|
|
115
116
|
const rangeInstance = _.get(tagifyRef.current, 'state.selection.range', null);
|
|
117
|
+
const anchorNodeInstance = _.get(tagifyRef.current, 'state.selection.anchorNode', null);
|
|
116
118
|
const { empty } = settings.classNames;
|
|
117
|
-
const
|
|
119
|
+
const isValidAnchor = isAnchorNodeChildOfElement(DOM.scope, anchorNodeInstance);
|
|
118
120
|
const selection = window.getSelection();
|
|
121
|
+
const isValidRange = selection?.rangeCount && rangeInstance;
|
|
122
|
+
const hasValidSelection = isValidRange && isValidAnchor;
|
|
119
123
|
// In case not have the selection yet or lost the selection,
|
|
120
|
-
if (!
|
|
124
|
+
if (!hasValidSelection) {
|
|
121
125
|
// need to restore the last range before inject a new tag if the last range exists
|
|
122
126
|
if (lastRange.current) {
|
|
123
127
|
selection?.removeAllRanges();
|
|
124
128
|
selection?.addRange(lastRange.current);
|
|
125
129
|
}
|
|
126
|
-
else {
|
|
130
|
+
else if (!isValidRange) {
|
|
127
131
|
// If the last range is lost, need to select the last text node of the input
|
|
128
132
|
const { input: inputElement } = tagifyRef.current.DOM;
|
|
129
133
|
if (inputElement) {
|
|
@@ -179,6 +179,7 @@ export declare const getAttributesString: (map: Map<string, string | boolean | n
|
|
|
179
179
|
* is a child of a specific DOM element.
|
|
180
180
|
*
|
|
181
181
|
* @param {HTMLElement} element - The parent element to check against
|
|
182
|
+
* @param {HTMLElement} anchorNodeInstance - The anchor node of the Tagify instance
|
|
182
183
|
* @returns {boolean} True if the anchor node is a child of the element, false otherwise
|
|
183
184
|
*/
|
|
184
|
-
export declare const isAnchorNodeChildOfElement: (element: Node) => boolean;
|
|
185
|
+
export declare const isAnchorNodeChildOfElement: (element: Node, anchorNodeInstance: Node | null) => boolean;
|
|
@@ -434,7 +434,7 @@ export const generateTagContent = (params) => {
|
|
|
434
434
|
* unescapeString('Hello "world" with spaces');
|
|
435
435
|
* // returns 'Hello "world" with spaces'
|
|
436
436
|
*/
|
|
437
|
-
export const unescapeString = (str) => str.replace(/"| |nbsp;|'/gm, (match) => {
|
|
437
|
+
export const unescapeString = (str) => str.replace(/"| |nbsp;|'|&/gm, (match) => {
|
|
438
438
|
switch (match) {
|
|
439
439
|
case ''':
|
|
440
440
|
return "'";
|
|
@@ -443,6 +443,8 @@ export const unescapeString = (str) => str.replace(/"| |nbsp;|'/g
|
|
|
443
443
|
case ' ':
|
|
444
444
|
case 'nbsp;':
|
|
445
445
|
return ' ';
|
|
446
|
+
case '&':
|
|
447
|
+
return '&';
|
|
446
448
|
default:
|
|
447
449
|
return match;
|
|
448
450
|
}
|
|
@@ -622,9 +624,10 @@ export const getAttributesString = (map) => Array.from(map.entries())
|
|
|
622
624
|
* is a child of a specific DOM element.
|
|
623
625
|
*
|
|
624
626
|
* @param {HTMLElement} element - The parent element to check against
|
|
627
|
+
* @param {HTMLElement} anchorNodeInstance - The anchor node of the Tagify instance
|
|
625
628
|
* @returns {boolean} True if the anchor node is a child of the element, false otherwise
|
|
626
629
|
*/
|
|
627
|
-
export const isAnchorNodeChildOfElement = (element) => {
|
|
630
|
+
export const isAnchorNodeChildOfElement = (element, anchorNodeInstance) => {
|
|
628
631
|
// Get the current selection
|
|
629
632
|
const selection = window.getSelection();
|
|
630
633
|
// Check if there's an active selection
|
|
@@ -638,5 +641,5 @@ export const isAnchorNodeChildOfElement = (element) => {
|
|
|
638
641
|
return false;
|
|
639
642
|
}
|
|
640
643
|
// Use Node.contains() to check if the element contains the anchor node
|
|
641
|
-
return element.contains(anchorNode);
|
|
644
|
+
return element.contains(anchorNode) && element.contains(anchorNodeInstance);
|
|
642
645
|
};
|