@lemon-fe/components 1.3.7-alpha.0 → 1.3.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.
- package/es/data-grid/components/custom-panel/index.js +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/portal/index.d.ts +45 -15
- package/es/portal/index.js +136 -128
- package/package.json +2 -2
|
@@ -211,7 +211,7 @@ export default function CustomColumnPanel(params) {
|
|
|
211
211
|
if ((e.type === 'columnMoved' || e.type === 'columnResized') && !e.finished) {
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
214
|
-
if ((e.type === 'columnMoved' || e.type === 'columnResized' || e.type === 'columnPinned') && e.source !== 'api' && e.api.getOpenedToolPanel() !== 'columns' && enableSave) {
|
|
214
|
+
if ((e.type === 'columnMoved' || e.type === 'columnResized' || e.type === 'columnPinned' || e.type === 'columnVisible') && e.source !== 'api' && e.api.getOpenedToolPanel() !== 'columns' && enableSave) {
|
|
215
215
|
save('ui');
|
|
216
216
|
}
|
|
217
217
|
handleColumnState();
|
package/es/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export { default as DataGrid, type DataGridRef } from './data-grid';
|
|
|
32
32
|
export * from './data-grid/typings';
|
|
33
33
|
export * from './data-grid/hooks';
|
|
34
34
|
export { default as TipMark } from './tip-mark';
|
|
35
|
-
export { default as Portal } from './portal';
|
|
35
|
+
export { default as Portal, createPortal } from './portal';
|
|
36
36
|
export { default as State } from './state';
|
|
37
37
|
export { default as GreyPanel } from './grey-panel';
|
|
38
38
|
export { default as InputCompact } from './input-compact';
|
package/es/index.js
CHANGED
|
@@ -26,7 +26,7 @@ export { default as DataGrid } from "./data-grid";
|
|
|
26
26
|
export * from "./data-grid/typings";
|
|
27
27
|
export * from "./data-grid/hooks";
|
|
28
28
|
export { default as TipMark } from "./tip-mark";
|
|
29
|
-
export { default as Portal } from "./portal";
|
|
29
|
+
export { default as Portal, createPortal } from "./portal";
|
|
30
30
|
export { default as State } from "./state";
|
|
31
31
|
export { default as GreyPanel } from "./grey-panel";
|
|
32
32
|
export { default as InputCompact } from "./input-compact";
|
package/es/portal/index.d.ts
CHANGED
|
@@ -1,22 +1,52 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { type ReactElement } from 'react';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
declare type ContentType = ReactNode;
|
|
4
|
-
declare
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
slot: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
declare type Nodes = Map<string, Map<string, ContentType>>;
|
|
5
|
+
interface Observer<T> {
|
|
6
|
+
next: (state: T) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface PortalContext {
|
|
9
|
+
set: (slot: string, id: string, node: ContentType) => void;
|
|
10
|
+
delete: (slot: string, id: string) => void;
|
|
11
|
+
observable: {
|
|
12
|
+
subscribe: (observer: Observer<Nodes>) => {
|
|
13
|
+
unsubscribe: () => void;
|
|
14
|
+
};
|
|
15
|
+
get: () => Nodes;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare function createPortal(): {
|
|
19
|
+
(props: {
|
|
20
|
+
children: ContentType;
|
|
14
21
|
slot: string;
|
|
15
|
-
|
|
22
|
+
}): null;
|
|
23
|
+
Host: (props: {
|
|
24
|
+
children: ContentType;
|
|
25
|
+
}) => JSX.Element;
|
|
26
|
+
Slot: React.NamedExoticComponent<{
|
|
27
|
+
slot: string;
|
|
28
|
+
render?: ((children: ReactNode) => ReactElement | null) | undefined;
|
|
16
29
|
}>;
|
|
17
|
-
|
|
18
|
-
add: (node:
|
|
30
|
+
usePortal: (slot: string) => {
|
|
31
|
+
add: (node: ReactNode) => void;
|
|
19
32
|
remove: () => void;
|
|
20
33
|
};
|
|
21
|
-
}
|
|
34
|
+
};
|
|
35
|
+
declare const Portal: {
|
|
36
|
+
(props: {
|
|
37
|
+
children: ContentType;
|
|
38
|
+
slot: string;
|
|
39
|
+
}): null;
|
|
40
|
+
Host: (props: {
|
|
41
|
+
children: ContentType;
|
|
42
|
+
}) => JSX.Element;
|
|
43
|
+
Slot: React.NamedExoticComponent<{
|
|
44
|
+
slot: string;
|
|
45
|
+
render?: ((children: ReactNode) => ReactElement | null) | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
usePortal: (slot: string) => {
|
|
48
|
+
add: (node: ReactNode) => void;
|
|
49
|
+
remove: () => void;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
22
52
|
export default Portal;
|
package/es/portal/index.js
CHANGED
|
@@ -14,20 +14,6 @@ var Slot = /*#__PURE__*/memo(function Content(props) {
|
|
|
14
14
|
var children = props.children;
|
|
15
15
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
16
16
|
});
|
|
17
|
-
var Context = /*#__PURE__*/createContext({
|
|
18
|
-
set: function set() {},
|
|
19
|
-
delete: function _delete() {},
|
|
20
|
-
observable: {
|
|
21
|
-
subscribe: function subscribe() {
|
|
22
|
-
return {
|
|
23
|
-
unsubscribe: function unsubscribe() {}
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
get: function get() {
|
|
27
|
-
return new Map();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
17
|
function Subject(initialData) {
|
|
32
18
|
var observers = [];
|
|
33
19
|
var data = initialData;
|
|
@@ -56,124 +42,146 @@ function Subject(initialData) {
|
|
|
56
42
|
}
|
|
57
43
|
};
|
|
58
44
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
45
|
+
var defaultContext = {
|
|
46
|
+
set: function set() {},
|
|
47
|
+
delete: function _delete() {},
|
|
48
|
+
observable: {
|
|
49
|
+
subscribe: function subscribe() {
|
|
50
|
+
return {
|
|
51
|
+
unsubscribe: function unsubscribe() {}
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
get: function get() {
|
|
55
|
+
return new Map();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// 用工厂函数生成,目的是为了可以实现不同Portal上下文,从而实现挂载节点到多个上下文内
|
|
61
|
+
|
|
62
|
+
export function createPortal() {
|
|
63
|
+
var Context = /*#__PURE__*/createContext(defaultContext);
|
|
64
|
+
function PortalHost(props) {
|
|
65
|
+
var children = props.children;
|
|
66
|
+
var _useState = useState(new Map()),
|
|
67
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
68
|
+
nodes = _useState2[0],
|
|
69
|
+
setNodes = _useState2[1];
|
|
70
|
+
var observable = useMemo(function () {
|
|
71
|
+
return Subject(nodes);
|
|
72
|
+
}, []);
|
|
73
|
+
var portal = useMemo(function () {
|
|
74
|
+
return {
|
|
75
|
+
set: function set(slot, id, node) {
|
|
76
|
+
setNodes(function (prev) {
|
|
77
|
+
var next = new Map(prev);
|
|
78
|
+
var elms = new Map(next.get(slot));
|
|
79
|
+
elms.set(id, node);
|
|
80
|
+
next.set(slot, elms);
|
|
81
|
+
return next;
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
delete: function _delete(slot, id) {
|
|
85
|
+
setNodes(function (prev) {
|
|
86
|
+
var next = new Map(prev);
|
|
87
|
+
var elms = new Map(next.get(slot));
|
|
88
|
+
if (elms) {
|
|
89
|
+
elms.delete(id);
|
|
90
|
+
}
|
|
91
|
+
if (elms.size <= 0) {
|
|
92
|
+
next.delete(slot);
|
|
93
|
+
}
|
|
94
|
+
return next;
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
observable: observable
|
|
98
|
+
};
|
|
99
|
+
}, []);
|
|
100
|
+
useEffect(function () {
|
|
101
|
+
observable.next(nodes);
|
|
102
|
+
}, [nodes]);
|
|
103
|
+
return /*#__PURE__*/React.createElement(Context.Provider, {
|
|
104
|
+
value: portal
|
|
105
|
+
}, /*#__PURE__*/React.createElement(Slot, null, children));
|
|
106
|
+
}
|
|
107
|
+
var PortalSlot = /*#__PURE__*/memo(function PortalSlotContent(props) {
|
|
108
|
+
var slot = props.slot,
|
|
109
|
+
render = props.render;
|
|
110
|
+
var _useContext = useContext(Context),
|
|
111
|
+
observable = _useContext.observable;
|
|
112
|
+
var _useState3 = useState(observable.get().get(slot) || null),
|
|
113
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
114
|
+
node = _useState4[0],
|
|
115
|
+
setNode = _useState4[1];
|
|
116
|
+
useEffect(function () {
|
|
117
|
+
var _observable$subscribe = observable.subscribe({
|
|
118
|
+
next: function next(state) {
|
|
119
|
+
setNode(state.get(slot) || null);
|
|
88
120
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
109
|
-
node = _useState4[0],
|
|
110
|
-
setNode = _useState4[1];
|
|
111
|
-
useEffect(function () {
|
|
112
|
-
var _observable$subscribe = observable.subscribe({
|
|
113
|
-
next: function next(state) {
|
|
114
|
-
setNode(state.get(slot) || null);
|
|
115
|
-
}
|
|
116
|
-
}),
|
|
117
|
-
unsubscribe = _observable$subscribe.unsubscribe;
|
|
118
|
-
return unsubscribe;
|
|
119
|
-
}, [slot]);
|
|
120
|
-
var result = useMemo(function () {
|
|
121
|
-
if (node === null) {
|
|
122
|
-
return null;
|
|
121
|
+
}),
|
|
122
|
+
unsubscribe = _observable$subscribe.unsubscribe;
|
|
123
|
+
return unsubscribe;
|
|
124
|
+
}, [slot]);
|
|
125
|
+
var result = useMemo(function () {
|
|
126
|
+
if (node === null) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return _toConsumableArray(node).map(function (_ref) {
|
|
130
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
131
|
+
id = _ref2[0],
|
|
132
|
+
elm = _ref2[1];
|
|
133
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
|
134
|
+
key: id
|
|
135
|
+
}, elm);
|
|
136
|
+
});
|
|
137
|
+
}, [node]);
|
|
138
|
+
if (render) {
|
|
139
|
+
return result ? render(result) : null;
|
|
123
140
|
}
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, result);
|
|
142
|
+
});
|
|
143
|
+
function Portal(props) {
|
|
144
|
+
var slot = props.slot,
|
|
145
|
+
children = props.children;
|
|
146
|
+
var portal = useContext(Context);
|
|
147
|
+
var id = useMemo(function () {
|
|
148
|
+
return uniqueId('slot');
|
|
149
|
+
}, []);
|
|
150
|
+
useEffect(function () {
|
|
151
|
+
return function () {
|
|
152
|
+
portal.delete(slot, id);
|
|
153
|
+
};
|
|
154
|
+
}, [slot]);
|
|
155
|
+
useEffect(function () {
|
|
156
|
+
portal.set(slot, id, children);
|
|
157
|
+
}, [slot, children]);
|
|
158
|
+
return null;
|
|
135
159
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
portal.
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
useEffect(function () {
|
|
151
|
-
portal.set(slot, id, children);
|
|
152
|
-
}, [slot, children]);
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
function usePortal(slot) {
|
|
156
|
-
var portal = useContext(Context);
|
|
157
|
-
var id = useMemo(function () {
|
|
158
|
-
return uniqueId('slot');
|
|
159
|
-
}, []);
|
|
160
|
-
useEffect(function () {
|
|
161
|
-
return function () {
|
|
160
|
+
function usePortal(slot) {
|
|
161
|
+
var portal = useContext(Context);
|
|
162
|
+
var id = useMemo(function () {
|
|
163
|
+
return uniqueId('slot');
|
|
164
|
+
}, []);
|
|
165
|
+
useEffect(function () {
|
|
166
|
+
return function () {
|
|
167
|
+
portal.delete(slot, id);
|
|
168
|
+
};
|
|
169
|
+
}, [slot]);
|
|
170
|
+
var add = useCallback(function (node) {
|
|
171
|
+
portal.set(slot, id, node);
|
|
172
|
+
}, [slot]);
|
|
173
|
+
var remove = useCallback(function () {
|
|
162
174
|
portal.delete(slot, id);
|
|
175
|
+
}, [slot]);
|
|
176
|
+
return {
|
|
177
|
+
add: add,
|
|
178
|
+
remove: remove
|
|
163
179
|
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
portal.delete(slot, id);
|
|
170
|
-
}, [slot]);
|
|
171
|
-
return {
|
|
172
|
-
add: add,
|
|
173
|
-
remove: remove
|
|
174
|
-
};
|
|
180
|
+
}
|
|
181
|
+
Portal.Host = PortalHost;
|
|
182
|
+
Portal.Slot = PortalSlot;
|
|
183
|
+
Portal.usePortal = usePortal;
|
|
184
|
+
return Portal;
|
|
175
185
|
}
|
|
176
|
-
Portal
|
|
177
|
-
Portal.Slot = PortalSlot;
|
|
178
|
-
Portal.usePortal = usePortal;
|
|
186
|
+
var Portal = createPortal();
|
|
179
187
|
export default Portal;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/components",
|
|
3
|
-
"version": "1.3.7
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"registry": "https://registry.npmjs.org"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "b41f095b38f4e4d26ea4554c4c5680aa868f41d9"
|
|
62
62
|
}
|