@alifd/chat 0.1.6 → 0.1.7
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.
|
@@ -181,10 +181,6 @@ export interface FloatButtonProps extends CommonProps {
|
|
|
181
181
|
* 触发节点
|
|
182
182
|
*/
|
|
183
183
|
trigger: NonNullable<BalloonProps['trigger']>;
|
|
184
|
-
/**
|
|
185
|
-
* 隐藏时的触发节点,默认为 trigger
|
|
186
|
-
*/
|
|
187
|
-
hiddenTrigger?: BalloonProps['trigger'];
|
|
188
184
|
/**
|
|
189
185
|
* 触发方式
|
|
190
186
|
* @defaultValue 'click'
|
|
@@ -22,7 +22,7 @@ function getMountTarget(prefix, target) {
|
|
|
22
22
|
parent = document.createElement('div');
|
|
23
23
|
parent.classList.add(`${prefix}outer`);
|
|
24
24
|
parent.dataset.chat = 'drawer';
|
|
25
|
-
oldParent.
|
|
25
|
+
oldParent.insertBefore(parent, dom);
|
|
26
26
|
parent.appendChild(dom);
|
|
27
27
|
}
|
|
28
28
|
let mountTarget = parent.childNodes[1];
|
|
@@ -35,11 +35,27 @@ function getMountTarget(prefix, target) {
|
|
|
35
35
|
parent.appendChild(mountTarget);
|
|
36
36
|
}
|
|
37
37
|
dom.classList.add(`${prefix}inner-start`);
|
|
38
|
-
return
|
|
38
|
+
return {
|
|
39
|
+
mountTarget,
|
|
40
|
+
unmount() {
|
|
41
|
+
// 这里直接根据 mountTarget 的 dom 结构来卸载,防止 dom 结构发生变化导致报错
|
|
42
|
+
if (!document.body.contains(mountTarget)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const outer = mountTarget.parentElement;
|
|
46
|
+
if (!outer.dataset.chat) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const dom = outer.childNodes[0];
|
|
50
|
+
dom.classList.remove(`${prefix}inner-start`);
|
|
51
|
+
outer.parentElement.replaceChild(dom, outer);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
39
54
|
}
|
|
40
55
|
export function InnerDrawer({ className, prefix, target, children, trigger, triggerType, visible, onVisibleChange, closable = true, title, cache = false, width = 400, beforeOpen, beforeClose, afterOpen, afterClose, }) {
|
|
41
56
|
const cls = `${prefix}inner-drawer`;
|
|
42
57
|
const [mountTarget, setMountTarget] = useState(null);
|
|
58
|
+
const effectsRef = useRef(new Map());
|
|
43
59
|
const [showPane, setShowPane] = useState(!!visible);
|
|
44
60
|
const propsRef = useRef({ visible, afterOpen, afterClose });
|
|
45
61
|
propsRef.current = {
|
|
@@ -54,10 +70,29 @@ export function InnerDrawer({ className, prefix, target, children, trigger, trig
|
|
|
54
70
|
};
|
|
55
71
|
useEffect(() => {
|
|
56
72
|
if (visible) {
|
|
57
|
-
|
|
73
|
+
const prefix = `${cls}-`;
|
|
74
|
+
const results = getMountTarget(prefix, target);
|
|
75
|
+
if (!results) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
setMountTarget(pre => {
|
|
79
|
+
var _a;
|
|
80
|
+
if (pre !== results.mountTarget) {
|
|
81
|
+
// 当挂载节点发生变化时,清除上一次的副作用,保存本次的副作用清除函数
|
|
82
|
+
(_a = effectsRef.current.get('mount')) === null || _a === void 0 ? void 0 : _a();
|
|
83
|
+
effectsRef.current.set('mount', results.unmount);
|
|
84
|
+
}
|
|
85
|
+
return results.mountTarget;
|
|
86
|
+
});
|
|
58
87
|
setShowPane(true);
|
|
59
88
|
}
|
|
60
89
|
}, [visible]);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
return () => {
|
|
92
|
+
// 组件卸载,清除副作用
|
|
93
|
+
effectsRef.current.forEach(f => f());
|
|
94
|
+
};
|
|
95
|
+
}, []);
|
|
61
96
|
const handleVisibleChange = (nextVisible, type) => {
|
|
62
97
|
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(nextVisible, type);
|
|
63
98
|
};
|
package/es/index.js
CHANGED
|
@@ -181,10 +181,6 @@ export interface FloatButtonProps extends CommonProps {
|
|
|
181
181
|
* 触发节点
|
|
182
182
|
*/
|
|
183
183
|
trigger: NonNullable<BalloonProps['trigger']>;
|
|
184
|
-
/**
|
|
185
|
-
* 隐藏时的触发节点,默认为 trigger
|
|
186
|
-
*/
|
|
187
|
-
hiddenTrigger?: BalloonProps['trigger'];
|
|
188
184
|
/**
|
|
189
185
|
* 触发方式
|
|
190
186
|
* @defaultValue 'click'
|
|
@@ -25,7 +25,7 @@ function getMountTarget(prefix, target) {
|
|
|
25
25
|
parent = document.createElement('div');
|
|
26
26
|
parent.classList.add(`${prefix}outer`);
|
|
27
27
|
parent.dataset.chat = 'drawer';
|
|
28
|
-
oldParent.
|
|
28
|
+
oldParent.insertBefore(parent, dom);
|
|
29
29
|
parent.appendChild(dom);
|
|
30
30
|
}
|
|
31
31
|
let mountTarget = parent.childNodes[1];
|
|
@@ -38,11 +38,27 @@ function getMountTarget(prefix, target) {
|
|
|
38
38
|
parent.appendChild(mountTarget);
|
|
39
39
|
}
|
|
40
40
|
dom.classList.add(`${prefix}inner-start`);
|
|
41
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
mountTarget,
|
|
43
|
+
unmount() {
|
|
44
|
+
// 这里直接根据 mountTarget 的 dom 结构来卸载,防止 dom 结构发生变化导致报错
|
|
45
|
+
if (!document.body.contains(mountTarget)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const outer = mountTarget.parentElement;
|
|
49
|
+
if (!outer.dataset.chat) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const dom = outer.childNodes[0];
|
|
53
|
+
dom.classList.remove(`${prefix}inner-start`);
|
|
54
|
+
outer.parentElement.replaceChild(dom, outer);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
42
57
|
}
|
|
43
58
|
function InnerDrawer({ className, prefix, target, children, trigger, triggerType, visible, onVisibleChange, closable = true, title, cache = false, width = 400, beforeOpen, beforeClose, afterOpen, afterClose, }) {
|
|
44
59
|
const cls = `${prefix}inner-drawer`;
|
|
45
60
|
const [mountTarget, setMountTarget] = (0, react_1.useState)(null);
|
|
61
|
+
const effectsRef = (0, react_1.useRef)(new Map());
|
|
46
62
|
const [showPane, setShowPane] = (0, react_1.useState)(!!visible);
|
|
47
63
|
const propsRef = (0, react_1.useRef)({ visible, afterOpen, afterClose });
|
|
48
64
|
propsRef.current = {
|
|
@@ -57,10 +73,29 @@ function InnerDrawer({ className, prefix, target, children, trigger, triggerType
|
|
|
57
73
|
};
|
|
58
74
|
(0, react_1.useEffect)(() => {
|
|
59
75
|
if (visible) {
|
|
60
|
-
|
|
76
|
+
const prefix = `${cls}-`;
|
|
77
|
+
const results = getMountTarget(prefix, target);
|
|
78
|
+
if (!results) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
setMountTarget(pre => {
|
|
82
|
+
var _a;
|
|
83
|
+
if (pre !== results.mountTarget) {
|
|
84
|
+
// 当挂载节点发生变化时,清除上一次的副作用,保存本次的副作用清除函数
|
|
85
|
+
(_a = effectsRef.current.get('mount')) === null || _a === void 0 ? void 0 : _a();
|
|
86
|
+
effectsRef.current.set('mount', results.unmount);
|
|
87
|
+
}
|
|
88
|
+
return results.mountTarget;
|
|
89
|
+
});
|
|
61
90
|
setShowPane(true);
|
|
62
91
|
}
|
|
63
92
|
}, [visible]);
|
|
93
|
+
(0, react_1.useEffect)(() => {
|
|
94
|
+
return () => {
|
|
95
|
+
// 组件卸载,清除副作用
|
|
96
|
+
effectsRef.current.forEach(f => f());
|
|
97
|
+
};
|
|
98
|
+
}, []);
|
|
64
99
|
const handleVisibleChange = (nextVisible, type) => {
|
|
65
100
|
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(nextVisible, type);
|
|
66
101
|
};
|
package/lib/index.js
CHANGED
|
@@ -18,4 +18,4 @@ var tag_1 = require("./tag");
|
|
|
18
18
|
Object.defineProperty(exports, "Tag", { enumerable: true, get: function () { return __importDefault(tag_1).default; } });
|
|
19
19
|
var tab_1 = require("./tab");
|
|
20
20
|
Object.defineProperty(exports, "Tab", { enumerable: true, get: function () { return __importDefault(tab_1).default; } });
|
|
21
|
-
exports.version = '0.1.
|
|
21
|
+
exports.version = '0.1.7';
|