react-vant-nova 1.0.7 → 1.0.9

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.
Files changed (41) hide show
  1. package/README.md +2 -2
  2. package/bundle/index.css +149 -0
  3. package/bundle/index.min.css +1 -1
  4. package/bundle/react-vant-nova.es.js +949 -728
  5. package/bundle/react-vant-nova.js +868 -646
  6. package/bundle/react-vant-nova.min.js +2 -2
  7. package/es/empty/Network.d.ts +1 -0
  8. package/es/index.d.ts +1 -0
  9. package/es/index.js +2 -1
  10. package/es/radio/Radio.d.ts +1 -0
  11. package/es/radio/RadioGroup.d.ts +1 -0
  12. package/es/treeSelect/PropsType.d.ts +85 -0
  13. package/es/treeSelect/PropsType.js +1 -0
  14. package/es/treeSelect/TreeSelect.d.ts +4 -0
  15. package/es/treeSelect/TreeSelect.js +259 -0
  16. package/es/treeSelect/index.d.ts +5 -0
  17. package/es/treeSelect/index.js +4 -0
  18. package/es/treeSelect/style/index.css +149 -0
  19. package/es/treeSelect/style/var.css +0 -0
  20. package/es/utils/dom/render.js +12 -30
  21. package/es/utils/dom/render1.d.ts +9 -0
  22. package/es/utils/dom/render1.js +85 -0
  23. package/lib/empty/Network.d.ts +1 -0
  24. package/lib/index.css +149 -0
  25. package/lib/index.d.ts +1 -0
  26. package/lib/index.js +12 -0
  27. package/lib/index.min.css +1 -1
  28. package/lib/radio/Radio.d.ts +1 -0
  29. package/lib/radio/RadioGroup.d.ts +1 -0
  30. package/lib/treeSelect/PropsType.d.ts +85 -0
  31. package/lib/treeSelect/PropsType.js +6 -0
  32. package/lib/treeSelect/TreeSelect.d.ts +4 -0
  33. package/lib/treeSelect/TreeSelect.js +291 -0
  34. package/lib/treeSelect/index.d.ts +5 -0
  35. package/lib/treeSelect/index.js +16 -0
  36. package/lib/treeSelect/style/index.css +149 -0
  37. package/lib/treeSelect/style/var.css +0 -0
  38. package/lib/utils/dom/render.js +20 -32
  39. package/lib/utils/dom/render1.d.ts +9 -0
  40. package/lib/utils/dom/render1.js +106 -0
  41. package/package.json +1 -1
@@ -1 +1,2 @@
1
+ /// <reference types="react" />
1
2
  export declare const Network: JSX.Element;
package/es/index.d.ts CHANGED
@@ -72,3 +72,4 @@ export * from './floating-ball';
72
72
  export * from './water-mark';
73
73
  export * from './floating-panel';
74
74
  export * from './table';
75
+ export * from './treeSelect';
package/es/index.js CHANGED
@@ -71,4 +71,5 @@ export * from './swiper';
71
71
  export * from './floating-ball';
72
72
  export * from './water-mark';
73
73
  export * from './floating-panel';
74
- export * from './table';
74
+ export * from './table';
75
+ export * from './treeSelect';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { RadioProps, RadioValueType } from './PropsType';
2
3
  declare function Radio<T = RadioValueType>(props: RadioProps<T>): JSX.Element;
3
4
  export default Radio;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { RadioGroupProps, RadioValueType } from './PropsType';
2
3
  declare function RadioGroup<T = RadioValueType>(props: RadioGroupProps<T>): JSX.Element;
3
4
  export default RadioGroup;
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import { BaseTypeProps } from '../utils';
3
+ export declare type TreeSelectNode = {
4
+ /** 节点标题 */
5
+ title?: React.ReactNode;
6
+ /** 节点值 */
7
+ value?: string | number;
8
+ /** 节点键值 */
9
+ key?: string | number;
10
+ /** 子节点列表 */
11
+ children?: TreeSelectNode[];
12
+ /** 是否禁用节点 */
13
+ disabled?: boolean;
14
+ /** 是否为叶子节点 */
15
+ isLeaf?: boolean;
16
+ /** 自定义图标 */
17
+ icon?: React.ReactNode;
18
+ /** 节点的自定义类名 */
19
+ className?: string;
20
+ /** 节点的自定义样式 */
21
+ style?: React.CSSProperties;
22
+ /** 扩展字段 */
23
+ [key: string]: any;
24
+ };
25
+ export declare type TreeSelectFieldNames = {
26
+ title?: string;
27
+ value?: string;
28
+ key?: string;
29
+ children?: string;
30
+ };
31
+ export interface TreeSelectProps extends Omit<BaseTypeProps, 'children'> {
32
+ /** 当前选中的值 */
33
+ value?: string | number | Array<string | number>;
34
+ /** 默认选中的值 */
35
+ defaultValue?: string | number | Array<string | number>;
36
+ /** 树形数据 */
37
+ treeData?: TreeSelectNode[];
38
+ /** 自定义树节点的字段 */
39
+ fieldNames?: TreeSelectFieldNames;
40
+ /** 选择框默认文字 */
41
+ placeholder?: string;
42
+ /** 是否支持多选 */
43
+ multiple?: boolean;
44
+ /** 是否可以清除 */
45
+ allowClear?: boolean;
46
+ /** 是否禁用 */
47
+ disabled?: boolean;
48
+ /** 高度,默认 272px */
49
+ height?: number | string;
50
+ /** 左侧导航宽度 */
51
+ navWidth?: number | string;
52
+ /** 自定义右侧区域内容 */
53
+ contentRender?: (item: TreeSelectNode) => React.ReactNode;
54
+ /** 选中项改变时触发 */
55
+ onChange?: (value: string | number | Array<string | number>, selectedNodes: TreeSelectNode[]) => void;
56
+ /** 点击左侧导航时触发 */
57
+ onNavClick?: (index: number) => void;
58
+ /** 左侧导航当前选中项的索引 */
59
+ activeIndex?: number;
60
+ /** 默认选中的左侧导航索引 */
61
+ defaultActiveIndex?: number;
62
+ /** 左侧导航样式 */
63
+ navStyle?: React.CSSProperties;
64
+ /** 右侧内容样式 */
65
+ contentStyle?: React.CSSProperties;
66
+ /** 左侧导航类名 */
67
+ navClassName?: string;
68
+ /** 右侧内容类名 */
69
+ contentClassName?: string;
70
+ children?: React.ReactNode;
71
+ }
72
+ export interface TreeSelectItemProps {
73
+ /** 节点数据 */
74
+ node: TreeSelectNode;
75
+ /** 是否选中 */
76
+ selected: boolean;
77
+ /** 是否多选模式 */
78
+ multiple?: boolean;
79
+ /** 层级 */
80
+ level?: number;
81
+ /** 点击回调 */
82
+ onClick?: (node: TreeSelectNode) => void;
83
+ /** 字段映射 */
84
+ fieldNames?: TreeSelectFieldNames;
85
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { TreeSelectProps } from './PropsType';
3
+ declare const TreeSelect: React.FC<TreeSelectProps>;
4
+ export default TreeSelect;
@@ -0,0 +1,259 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import cls from 'clsx';
4
+ import { Success } from '@react-vant/icons';
5
+ import { createNamespace, extend } from '../utils';
6
+ import { useMemoizedFn } from '../hooks';
7
+ import useMergedState from '../hooks/use-merged-state';
8
+ import { mergeProps } from '../utils/get-default-props';
9
+ const [bem] = createNamespace('tree-select');
10
+ // TreeSelect 子项组件
11
+ const TreeSelectItem = ({
12
+ node,
13
+ selected,
14
+ multiple,
15
+ level = 0,
16
+ onClick,
17
+ fieldNames
18
+ }) => {
19
+ const {
20
+ title: titleKey = 'title',
21
+ value: valueKey = 'value',
22
+ children: childrenKey = 'children'
23
+ } = fieldNames || {};
24
+ const title = node[titleKey];
25
+ const children = node[childrenKey];
26
+ const hasChildren = children && children.length > 0;
27
+ const handleClick = () => {
28
+ if (!node.disabled) {
29
+ onClick === null || onClick === void 0 ? void 0 : onClick(node);
30
+ }
31
+ };
32
+ return _jsxs("div", Object.assign({
33
+ className: cls(bem('item-wrapper'))
34
+ }, {
35
+ children: [_jsxs("div", Object.assign({
36
+ className: cls(bem('item', {
37
+ active: selected,
38
+ disabled: node.disabled,
39
+ level: `level-${level}`
40
+ }), node.className),
41
+ style: node.style,
42
+ onClick: handleClick
43
+ }, {
44
+ children: [_jsxs("div", Object.assign({
45
+ className: cls(bem('item-content'))
46
+ }, {
47
+ children: [node.icon && _jsx("span", Object.assign({
48
+ className: cls(bem('item-icon'))
49
+ }, {
50
+ children: node.icon
51
+ })), _jsx("span", Object.assign({
52
+ className: cls(bem('item-title'))
53
+ }, {
54
+ children: title
55
+ }))]
56
+ })), selected && !multiple && _jsx(Success, {
57
+ className: cls(bem('item-selected-icon'))
58
+ }), multiple && _jsx("input", {
59
+ type: 'checkbox',
60
+ checked: selected,
61
+ disabled: node.disabled,
62
+ className: cls(bem('item-checkbox')),
63
+ readOnly: true
64
+ })]
65
+ })), hasChildren && _jsx("div", Object.assign({
66
+ className: cls(bem('item-children'))
67
+ }, {
68
+ children: children.map((child, index) => _jsx(TreeSelectItem, {
69
+ node: child,
70
+ selected: false,
71
+ multiple: multiple,
72
+ level: level + 1,
73
+ onClick: onClick,
74
+ fieldNames: fieldNames
75
+ }, child[valueKey] || index))
76
+ }))]
77
+ }));
78
+ };
79
+ const TreeSelect = p => {
80
+ const props = mergeProps(p, {
81
+ treeData: [],
82
+ height: 272,
83
+ navWidth: 80,
84
+ defaultActiveIndex: 0,
85
+ fieldNames: {
86
+ title: 'title',
87
+ value: 'value',
88
+ key: 'key',
89
+ children: 'children'
90
+ }
91
+ });
92
+ const {
93
+ title: titleKey,
94
+ value: valueKey,
95
+ key: keyKey,
96
+ children: childrenKey
97
+ } = extend({
98
+ title: 'title',
99
+ value: 'value',
100
+ key: 'key',
101
+ children: 'children'
102
+ }, props.fieldNames);
103
+ // 当前选中的值
104
+ const [selectedValue, setSelectedValue] = useMergedState({
105
+ value: props.value,
106
+ defaultValue: props.defaultValue
107
+ });
108
+ // 左侧导航当前选中的索引
109
+ const [activeIndex, setActiveIndex] = useMergedState({
110
+ value: props.activeIndex,
111
+ defaultValue: props.defaultActiveIndex
112
+ });
113
+ // 获取所有顶级节点(左侧导航)
114
+ const navItems = useMemo(() => {
115
+ return props.treeData || [];
116
+ }, [props.treeData]);
117
+ // 获取当前激活项的子节点(右侧内容)
118
+ const contentItems = useMemo(() => {
119
+ const currentNav = navItems[activeIndex];
120
+ return (currentNav === null || currentNav === void 0 ? void 0 : currentNav[childrenKey]) || [];
121
+ }, [navItems, activeIndex, childrenKey]);
122
+ // 判断值是否选中
123
+ const isValueSelected = useMemoizedFn(value => {
124
+ if (props.multiple) {
125
+ return Array.isArray(selectedValue) && selectedValue.includes(value);
126
+ }
127
+ return selectedValue === value;
128
+ });
129
+ // 查找节点
130
+ const findNode = useMemoizedFn((nodes, value) => {
131
+ for (const node of nodes) {
132
+ if (node[valueKey] === value) {
133
+ return node;
134
+ }
135
+ if (node[childrenKey]) {
136
+ const found = findNode(node[childrenKey], value);
137
+ if (found) return found;
138
+ }
139
+ }
140
+ return null;
141
+ });
142
+ // 获取所有选中的节点
143
+ const getSelectedNodes = useMemoizedFn(value => {
144
+ const values = Array.isArray(value) ? value : [value];
145
+ const nodes = [];
146
+ values.forEach(val => {
147
+ const node = findNode(props.treeData || [], val);
148
+ if (node) nodes.push(node);
149
+ });
150
+ return nodes;
151
+ });
152
+ // 左侧导航点击
153
+ const handleNavClick = useMemoizedFn(index => {
154
+ var _a;
155
+ setActiveIndex(index);
156
+ (_a = props.onNavClick) === null || _a === void 0 ? void 0 : _a.call(props, index);
157
+ });
158
+ // 右侧内容项点击
159
+ const handleItemClick = useMemoizedFn(node => {
160
+ var _a;
161
+ const value = node[valueKey];
162
+ let newValue;
163
+ if (props.multiple) {
164
+ const currentValues = Array.isArray(selectedValue) ? selectedValue : [];
165
+ if (currentValues.includes(value)) {
166
+ newValue = currentValues.filter(v => v !== value);
167
+ } else {
168
+ newValue = [...currentValues, value];
169
+ }
170
+ } else {
171
+ newValue = value;
172
+ }
173
+ setSelectedValue(newValue);
174
+ const selectedNodes = getSelectedNodes(newValue);
175
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, newValue, selectedNodes);
176
+ });
177
+ // 渲染左侧导航
178
+ const renderNav = () => _jsx("div", Object.assign({
179
+ className: cls(bem('nav'), props.navClassName),
180
+ style: Object.assign({
181
+ width: props.navWidth,
182
+ height: props.height
183
+ }, props.navStyle)
184
+ }, {
185
+ children: navItems.map((item, index) => {
186
+ const isActive = index === activeIndex;
187
+ const title = item[titleKey];
188
+ return _jsxs("div", Object.assign({
189
+ className: cls(bem('nav-item', {
190
+ active: isActive,
191
+ disabled: item.disabled
192
+ }), item.className),
193
+ style: item.style,
194
+ onClick: () => !item.disabled && handleNavClick(index)
195
+ }, {
196
+ children: [item.icon && _jsx("span", Object.assign({
197
+ className: cls(bem('nav-icon'))
198
+ }, {
199
+ children: item.icon
200
+ })), _jsx("span", Object.assign({
201
+ className: cls(bem('nav-text'))
202
+ }, {
203
+ children: title
204
+ })), item.badge && _jsx("span", Object.assign({
205
+ className: cls(bem('nav-badge'))
206
+ }, {
207
+ children: item.badge
208
+ }))]
209
+ }), item[keyKey] || item[valueKey] || index);
210
+ })
211
+ }));
212
+ // 渲染右侧内容
213
+ const renderContent = () => {
214
+ const currentNav = navItems[activeIndex];
215
+ if (props.contentRender && currentNav) {
216
+ return _jsx("div", Object.assign({
217
+ className: cls(bem('content'), props.contentClassName),
218
+ style: Object.assign({
219
+ height: props.height
220
+ }, props.contentStyle)
221
+ }, {
222
+ children: props.contentRender(currentNav)
223
+ }));
224
+ }
225
+ return _jsx("div", Object.assign({
226
+ className: cls(bem('content'), props.contentClassName),
227
+ style: Object.assign({
228
+ height: props.height
229
+ }, props.contentStyle)
230
+ }, {
231
+ children: contentItems.length > 0 ? _jsx("div", Object.assign({
232
+ className: cls(bem('items'))
233
+ }, {
234
+ children: contentItems.map((item, index) => {
235
+ const value = item[valueKey];
236
+ const selected = isValueSelected(value);
237
+ return _jsx(TreeSelectItem, {
238
+ node: item,
239
+ selected: selected,
240
+ multiple: props.multiple,
241
+ onClick: handleItemClick,
242
+ fieldNames: props.fieldNames
243
+ }, item[keyKey] || value || index);
244
+ })
245
+ })) : _jsx("div", Object.assign({
246
+ className: cls(bem('content-empty'))
247
+ }, {
248
+ children: props.placeholder || '暂无数据'
249
+ }))
250
+ }));
251
+ };
252
+ return _jsxs("div", Object.assign({
253
+ className: cls(props.className, bem()),
254
+ style: props.style
255
+ }, {
256
+ children: [renderNav(), renderContent()]
257
+ }));
258
+ };
259
+ export default TreeSelect;
@@ -0,0 +1,5 @@
1
+ import './style/index.less';
2
+ import TreeSelect from './TreeSelect';
3
+ export default TreeSelect;
4
+ export { TreeSelect };
5
+ export type { TreeSelectProps, TreeSelectNode, TreeSelectFieldNames, } from './PropsType';
@@ -0,0 +1,4 @@
1
+ import "./style/index.css";
2
+ import TreeSelect from './TreeSelect';
3
+ export default TreeSelect;
4
+ export { TreeSelect };
@@ -0,0 +1,149 @@
1
+ :root {
2
+ --rv-tree-select-font-size: 14px;
3
+ --rv-tree-select-nav-width: 80px;
4
+ --rv-tree-select-nav-background-color: var(--rv-gray-1);
5
+ --rv-tree-select-content-background-color: #fff;
6
+ --rv-tree-select-nav-item-padding: 14px 12px;
7
+ --rv-tree-select-item-height: 48px;
8
+ --rv-tree-select-item-active-color: #f44336;
9
+ --rv-tree-select-item-disabled-color: #c8c9cc;
10
+ --rv-tree-select-item-selected-size: 16px;
11
+ --rv-tree-select-height: 300px;
12
+ }
13
+ .rv-tree-select {
14
+ display: flex;
15
+ font-size: var(--rv-tree-select-font-size);
16
+ user-select: none;
17
+ }
18
+ .rv-tree-select__nav {
19
+ flex: none;
20
+ overflow-y: auto;
21
+ background-color: var(--rv-tree-select-nav-background-color);
22
+ -webkit-overflow-scrolling: touch;
23
+ }
24
+ .rv-tree-select__nav-item {
25
+ position: relative;
26
+ display: flex;
27
+ align-items: center;
28
+ padding: var(--rv-tree-select-nav-item-padding);
29
+ cursor: pointer;
30
+ transition: background-color 0.2s;
31
+ }
32
+ .rv-tree-select__nav-item:active {
33
+ opacity: 0.7;
34
+ }
35
+ .rv-tree-select__nav-item--active {
36
+ color: var(--rv-tree-select-item-active-color);
37
+ font-weight: 600;
38
+ background-color: var(--rv-tree-select-content-background-color);
39
+ }
40
+ .rv-tree-select__nav-item--active::before {
41
+ position: absolute;
42
+ top: 50%;
43
+ left: 0;
44
+ width: 3px;
45
+ height: 16px;
46
+ background-color: var(--rv-tree-select-item-active-color);
47
+ transform: translateY(-50%);
48
+ content: '';
49
+ }
50
+ .rv-tree-select__nav-item--disabled {
51
+ color: var(--rv-tree-select-item-disabled-color);
52
+ cursor: not-allowed;
53
+ }
54
+ .rv-tree-select__nav-item--disabled:active {
55
+ opacity: 1;
56
+ }
57
+ .rv-tree-select__nav-icon {
58
+ margin-right: 4px;
59
+ }
60
+ .rv-tree-select__nav-text {
61
+ flex: 1;
62
+ word-break: break-all;
63
+ }
64
+ .rv-tree-select__nav-badge {
65
+ margin-left: 4px;
66
+ padding: 0 6px;
67
+ font-size: 12px;
68
+ color: #fff;
69
+ background-color: var(--rv-tree-select-item-active-color);
70
+ border-radius: 10px;
71
+ }
72
+ .rv-tree-select__content {
73
+ flex: 1;
74
+ overflow-y: auto;
75
+ background-color: var(--rv-tree-select-content-background-color);
76
+ -webkit-overflow-scrolling: touch;
77
+ }
78
+ .rv-tree-select__items {
79
+ padding: 12px 16px;
80
+ }
81
+ .rv-tree-select__content-empty {
82
+ display: flex;
83
+ align-items: center;
84
+ justify-content: center;
85
+ height: 100%;
86
+ color: var(--rv-tree-select-item-disabled-color);
87
+ }
88
+ .rv-tree-select__item-wrapper {
89
+ margin-bottom: 12px;
90
+ }
91
+ .rv-tree-select__item-wrapper:last-child {
92
+ margin-bottom: 0;
93
+ }
94
+ .rv-tree-select__item {
95
+ position: relative;
96
+ display: flex;
97
+ align-items: center;
98
+ justify-content: space-between;
99
+ min-height: var(--rv-tree-select-item-height);
100
+ padding: 10px 12px;
101
+ background-color: var(--rv-tree-select-nav-background-color);
102
+ border-radius: 8px;
103
+ cursor: pointer;
104
+ transition: all 0.2s;
105
+ }
106
+ .rv-tree-select__item:active {
107
+ opacity: 0.7;
108
+ }
109
+ .rv-tree-select__item--active {
110
+ color: var(--rv-tree-select-item-active-color);
111
+ background-color: rgba(238, 10, 36, 0.08);
112
+ font-weight: 500;
113
+ }
114
+ .rv-tree-select__item--disabled {
115
+ color: var(--rv-tree-select-item-disabled-color);
116
+ cursor: not-allowed;
117
+ }
118
+ .rv-tree-select__item--disabled:active {
119
+ opacity: 1;
120
+ }
121
+ .rv-tree-select__item-content {
122
+ display: flex;
123
+ align-items: center;
124
+ flex: 1;
125
+ }
126
+ .rv-tree-select__item-icon {
127
+ margin-right: 8px;
128
+ display: flex;
129
+ align-items: center;
130
+ }
131
+ .rv-tree-select__item-title {
132
+ flex: 1;
133
+ }
134
+ .rv-tree-select__item-selected-icon {
135
+ margin-left: 8px;
136
+ font-size: var(--rv-tree-select-item-selected-size);
137
+ color: var(--rv-tree-select-item-active-color);
138
+ }
139
+ .rv-tree-select__item-checkbox {
140
+ margin-left: 8px;
141
+ width: 18px;
142
+ height: 18px;
143
+ cursor: pointer;
144
+ }
145
+ .rv-tree-select__item-children {
146
+ margin-top: 8px;
147
+ padding-left: 20px;
148
+ border-left: 2px solid var(--rv-tree-select-nav-background-color);
149
+ }
File without changes
@@ -1,23 +1,13 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import * as ReactDOM from 'react-dom';
3
- // Let compiler not to search module usage
3
+ import { createRoot } from 'react-dom/client';
4
+ // Copy from rc-util to fix React 19 support
5
+ // https://github.com/react-component/util/blob/master/src/React/render.ts
4
6
  const fullClone = Object.assign({}, ReactDOM);
5
7
  const {
8
+ render: reactRender,
6
9
  unmountComponentAtNode
7
10
  } = fullClone;
8
- let createRoot;
9
- // 确保在React 18+版本中获取createRoot
10
- if (fullClone.createRoot) {
11
- createRoot = fullClone.createRoot;
12
- } else {
13
- // 如果createRoot不可用,尝试从react-dom/client导入
14
- try {
15
- // eslint-disable-next-line @typescript-eslint/no-var-requires
16
- createRoot = require('react-dom/client').createRoot;
17
- } catch (e) {
18
- // 保留原有行为以兼容旧版本
19
- }
20
- }
21
11
  function toggleWarning(skip) {
22
12
  const {
23
13
  __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
@@ -27,33 +17,24 @@ function toggleWarning(skip) {
27
17
  }
28
18
  }
29
19
  const MARK = '__react_vant_root__';
30
- /************* ✨ Windsurf Command ⭐ *************/
31
- /**
32
- * 使用ReactDOM.render的替代方案,仅用于旧版本React
33
- * 如果ReactDOM.render不可用,将降级使用createRoot(如果可用)
34
- /******* 57770e2e-0e81-41a7-aee6-9175a4a59062 *******/
35
20
  function legacyRender(node, container) {
36
- // 使用ReactDOM.render的替代方案,仅用于旧版本React
37
- // @ts-ignore
38
- if (fullClone.render) {
21
+ if (reactRender) {
22
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
39
23
  // @ts-ignore
40
- fullClone.render(node, container);
41
- } else {
42
- // 如果ReactDOM.render不可用,降级使用createRoot(如果可用)
43
- if (createRoot) {
44
- concurrentRender(node, container);
45
- }
24
+ reactRender(node, container);
46
25
  }
47
26
  }
48
27
  function concurrentRender(node, container) {
49
28
  toggleWarning(true);
50
29
  const root = container[MARK] || createRoot(container);
51
30
  toggleWarning(false);
31
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
52
32
  // @ts-ignore
53
33
  root.render(node);
54
34
  container[MARK] = root;
55
35
  }
56
36
  export function render(node, container) {
37
+ // @ts-ignore
57
38
  if (createRoot) {
58
39
  concurrentRender(node, container);
59
40
  return;
@@ -62,7 +43,7 @@ export function render(node, container) {
62
43
  }
63
44
  // ========================== Unmount =========================
64
45
  function legacyUnmount(container) {
65
- return unmountComponentAtNode(container);
46
+ return unmountComponentAtNode ? unmountComponentAtNode(container) : false;
66
47
  }
67
48
  function concurrentUnmount(container) {
68
49
  return __awaiter(this, void 0, void 0, function* () {
@@ -75,7 +56,8 @@ function concurrentUnmount(container) {
75
56
  });
76
57
  }
77
58
  export function unmount(container) {
78
- if (createRoot) {
59
+ // @ts-ignore
60
+ if (createRoot || container[MARK]) {
79
61
  return concurrentUnmount(container);
80
62
  }
81
63
  return legacyUnmount(container);
@@ -0,0 +1,9 @@
1
+ import { ReactElement } from 'react';
2
+ import type { Root } from 'react-dom/client';
3
+ declare const MARK = "__react_vant_root__";
4
+ declare type ContainerType = (Element | DocumentFragment) & {
5
+ [MARK]?: Root;
6
+ };
7
+ export declare function render(node: ReactElement, container: ContainerType): void;
8
+ export declare function unmount(container: ContainerType): boolean | Promise<void>;
9
+ export {};