@antscorp/antsomi-ui 1.3.5-beta.321 → 1.3.5-beta.323
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.
|
@@ -11,7 +11,9 @@ import { handleError } from '@antscorp/antsomi-ui/es/utils';
|
|
|
11
11
|
const PATH = 'src/components/EditorTab/index.jsx';
|
|
12
12
|
export const EditorTab = props => {
|
|
13
13
|
var _a;
|
|
14
|
-
const { listTab = [], activeId = '', defaultActiveId, showArrow, showDropdown, editNameOnConfigure,
|
|
14
|
+
const { listTab = [], activeId = '', defaultActiveId, showArrow, showDropdown, editNameOnConfigure,
|
|
15
|
+
// disabledScroll,
|
|
16
|
+
onCloseTab, onActiveTab, onAddTab, onConfigure, onSaveName, showComposeNewQuery, className, leftBlockClassName, tabItemClassName, } = props;
|
|
15
17
|
const [activeTabId, setActiveTabId] = useState(defaultActiveId || activeId || ((_a = listTab === null || listTab === void 0 ? void 0 : listTab[0]) === null || _a === void 0 ? void 0 : _a.id));
|
|
16
18
|
const [arrTabs, setArrTabs] = useState(listTab || []);
|
|
17
19
|
const [isEditable, setIsEditable] = useState();
|
|
@@ -23,23 +25,24 @@ export const EditorTab = props => {
|
|
|
23
25
|
setActiveTabId(listTab[listTab.length - 1].id);
|
|
24
26
|
}
|
|
25
27
|
setArrTabs(listTab);
|
|
26
|
-
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
}, [listTab]);
|
|
30
|
+
// useEffect(() => {
|
|
31
|
+
// if (onActiveTab) onActiveTab(activeTabId);
|
|
32
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
// }, [activeTabId]);
|
|
27
34
|
useEffect(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const tabEl = document.getElementById(`tab-${activeTabId}`);
|
|
32
|
-
if (tabEl) {
|
|
33
|
-
tabEl.scrollIntoView({ block: 'center', inline: 'center', behavior: 'smooth' });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}, 500);
|
|
37
|
-
}, [activeTabId, disabledScroll, onActiveTab]);
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (activeId && activeTabId !== activeId) {
|
|
40
|
-
setActiveTabId(activeId);
|
|
35
|
+
const tabEl = document.getElementById(`tab-${activeTabId}`);
|
|
36
|
+
if (tabEl) {
|
|
37
|
+
tabEl.scrollIntoView({ block: 'center', inline: 'center', behavior: 'smooth' });
|
|
41
38
|
}
|
|
42
|
-
}, [
|
|
39
|
+
}, [activeTabId]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
// if (activeId && activeTabId !== activeId) {
|
|
42
|
+
// setActiveTabId(activeId);
|
|
43
|
+
// }
|
|
44
|
+
setActiveTabId(prev => (activeId && prev !== activeId ? activeId : prev));
|
|
45
|
+
}, [activeId]);
|
|
43
46
|
const handleAddNew = () => {
|
|
44
47
|
onAddTab();
|
|
45
48
|
};
|
|
@@ -51,20 +54,29 @@ export const EditorTab = props => {
|
|
|
51
54
|
if (activeTabId === tab.id) {
|
|
52
55
|
if (idx === arrTabs.length - 1) {
|
|
53
56
|
setActiveTabId(arrTabs[idx - 1].id);
|
|
57
|
+
if (onActiveTab)
|
|
58
|
+
onActiveTab(arrTabs[idx - 1].id);
|
|
54
59
|
}
|
|
55
60
|
else if (arrTabs.length > 1) {
|
|
56
61
|
setActiveTabId(arrTabs[idx + 1].id);
|
|
62
|
+
if (onActiveTab)
|
|
63
|
+
onActiveTab(arrTabs[idx - 1].id);
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
const newTabs = [...arrTabs];
|
|
67
|
+
newTabs.splice(idx, 1);
|
|
68
|
+
onCloseTab(tab, idx, newTabs);
|
|
69
|
+
// setArrTabs(prevTabs => {
|
|
70
|
+
// const newTabs = [...prevTabs];
|
|
71
|
+
// newTabs.splice(idx, 1);
|
|
72
|
+
// onCloseTab(tab, idx, newTabs);
|
|
73
|
+
// return newTabs;
|
|
74
|
+
// });
|
|
65
75
|
};
|
|
66
|
-
const handleActiveTab =
|
|
76
|
+
const handleActiveTab = tab => {
|
|
67
77
|
setActiveTabId(tab.id);
|
|
78
|
+
if (onActiveTab)
|
|
79
|
+
onActiveTab(tab.id);
|
|
68
80
|
};
|
|
69
81
|
const onWheelLeftBlock = event => {
|
|
70
82
|
try {
|
|
@@ -90,12 +102,16 @@ export const EditorTab = props => {
|
|
|
90
102
|
return;
|
|
91
103
|
}
|
|
92
104
|
setActiveTabId(arrTabs[idx - 1].id);
|
|
105
|
+
if (onActiveTab)
|
|
106
|
+
onActiveTab(arrTabs[idx - 1].id);
|
|
93
107
|
break;
|
|
94
108
|
case 'right':
|
|
95
109
|
if (idx === arrTabs.length - 1) {
|
|
96
110
|
return;
|
|
97
111
|
}
|
|
98
112
|
setActiveTabId(arrTabs[idx + 1].id);
|
|
113
|
+
if (onActiveTab)
|
|
114
|
+
onActiveTab(arrTabs[idx + 1].id);
|
|
99
115
|
break;
|
|
100
116
|
default:
|
|
101
117
|
break;
|
|
@@ -111,7 +127,7 @@ export const EditorTab = props => {
|
|
|
111
127
|
? arrTabs.map((tab, idx) => {
|
|
112
128
|
const { showIcon = true, closeable = true } = tab;
|
|
113
129
|
// const { showIcon = true, showDropdown = true, closeable = true } = tab;
|
|
114
|
-
return (React.createElement("div", { key: tab.id, id: `tab-${tab.id}`, onClick: () => handleActiveTab(tab
|
|
130
|
+
return (React.createElement("div", { key: tab.id, id: `tab-${tab.id}`, onClick: () => handleActiveTab(tab), className: classnames('tab-item', tabItemClassName, {
|
|
115
131
|
active: tab.id === activeTabId,
|
|
116
132
|
}) },
|
|
117
133
|
showIcon &&
|