react-native-fxview 1.0.0 → 1.0.1
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/FXView.d.ts +20 -0
- package/FXView.js +102 -0
- package/FXViewCategoryController.d.ts +100 -0
- package/FXViewCategoryController.js +270 -0
- package/FXViewCategoryController.ts +1 -1
- package/FXViewController.d.ts +115 -0
- package/FXViewController.js +288 -0
- package/FXViewManager.d.ts +143 -0
- package/FXViewManager.js +342 -0
- package/FXViewManager.ts +1 -1
- package/README.md +61 -0
- package/index.d.ts +5 -0
- package/index.js +30 -0
- package/index.ts +6 -0
- package/package.json +47 -6
- package/types.d.ts +35 -0
- package/types.js +2 -0
package/FXView.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import { ViewProps } from "react-native";
|
|
3
|
+
import { ComponentItem } from "./types";
|
|
4
|
+
interface FXViewProps extends ViewProps {
|
|
5
|
+
fxViewId?: string;
|
|
6
|
+
}
|
|
7
|
+
interface FXViewState {
|
|
8
|
+
components: ComponentItem[];
|
|
9
|
+
}
|
|
10
|
+
export default class FXView extends Component<FXViewProps, FXViewState> {
|
|
11
|
+
state: FXViewState;
|
|
12
|
+
private viewId;
|
|
13
|
+
constructor(props: FXViewProps);
|
|
14
|
+
componentDidMount(): void;
|
|
15
|
+
componentDidUpdate(_prevProps: FXViewProps): void;
|
|
16
|
+
componentWillUnmount(): void;
|
|
17
|
+
updateComponents: () => void;
|
|
18
|
+
render(): React.JSX.Element;
|
|
19
|
+
}
|
|
20
|
+
export type { FXViewProps };
|
package/FXView.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
36
|
+
var t = {};
|
|
37
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
+
t[p] = s[p];
|
|
39
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
+
t[p[i]] = s[p[i]];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
const react_1 = __importStar(require("react"));
|
|
48
|
+
const react_native_1 = require("react-native");
|
|
49
|
+
const FXViewManager_1 = require("./FXViewManager");
|
|
50
|
+
class FXView extends react_1.Component {
|
|
51
|
+
constructor(props) {
|
|
52
|
+
super(props);
|
|
53
|
+
this.state = {
|
|
54
|
+
components: [],
|
|
55
|
+
};
|
|
56
|
+
this.updateComponents = () => {
|
|
57
|
+
const components = FXViewManager_1.FXViewManager.getInstance().getComponents(this.viewId);
|
|
58
|
+
this.setState({ components: components });
|
|
59
|
+
};
|
|
60
|
+
// 使用 fxViewId,如果没有则生成一个唯一 ID
|
|
61
|
+
this.viewId =
|
|
62
|
+
props.fxViewId ||
|
|
63
|
+
`auto_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
64
|
+
}
|
|
65
|
+
componentDidMount() {
|
|
66
|
+
console.log("FXView mounted with viewId:", this.viewId);
|
|
67
|
+
// 注册到视图管理器
|
|
68
|
+
FXViewManager_1.FXViewManager.getInstance().registerView(this.viewId, this.updateComponents);
|
|
69
|
+
// 初始更新
|
|
70
|
+
this.updateComponents();
|
|
71
|
+
}
|
|
72
|
+
componentDidUpdate(_prevProps) {
|
|
73
|
+
console.log("FXView updated", this.viewId);
|
|
74
|
+
const newViewId = this.props.fxViewId || this.viewId;
|
|
75
|
+
if (newViewId !== this.viewId) {
|
|
76
|
+
// ID 变化时重新注册
|
|
77
|
+
FXViewManager_1.FXViewManager.getInstance().unregisterView(this.viewId);
|
|
78
|
+
this.viewId = newViewId;
|
|
79
|
+
FXViewManager_1.FXViewManager.getInstance().registerView(this.viewId, this.updateComponents);
|
|
80
|
+
this.updateComponents();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
componentWillUnmount() {
|
|
84
|
+
console.log("FXView unmounted", this.viewId);
|
|
85
|
+
// 注销视图(会自动清理所有组件和回调)
|
|
86
|
+
FXViewManager_1.FXViewManager.getInstance().unregisterView(this.viewId);
|
|
87
|
+
}
|
|
88
|
+
render() {
|
|
89
|
+
const { children } = this.props;
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
|
+
const _a = this.props, { fxViewId } = _a, restProps = __rest(_a, ["fxViewId"]);
|
|
92
|
+
const { components } = this.state;
|
|
93
|
+
console.log("rendering fxView components", components.length);
|
|
94
|
+
return (<react_native_1.View {...restProps}>
|
|
95
|
+
{children}
|
|
96
|
+
{components.map((item) => item.visible ? (<react_1.default.Fragment key={item.componentId}>
|
|
97
|
+
{item.component}
|
|
98
|
+
</react_1.default.Fragment>) : null)}
|
|
99
|
+
</react_native_1.View>);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.default = FXView;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ComponentItem, ComponentController } from "./types";
|
|
3
|
+
export declare class FXViewCategoryController {
|
|
4
|
+
fxViewId: string;
|
|
5
|
+
categoryId: string;
|
|
6
|
+
private updateCallback?;
|
|
7
|
+
private componentMap;
|
|
8
|
+
private componentQueue;
|
|
9
|
+
constructor(fxViewId: string, categoryId: string, triggerUpdate?: () => void);
|
|
10
|
+
/**
|
|
11
|
+
* 创建并展示组件
|
|
12
|
+
* @param component 要显示的组件
|
|
13
|
+
* @param componentId 可选的组件 ID
|
|
14
|
+
* @returns 组件控制器
|
|
15
|
+
*/
|
|
16
|
+
add(component: React.ReactNode, componentId?: string): ComponentController;
|
|
17
|
+
/**
|
|
18
|
+
* 创建但不显示组件
|
|
19
|
+
* @param component 要创建的组件
|
|
20
|
+
* @param componentId 可选的组件 ID
|
|
21
|
+
* @returns 组件控制器
|
|
22
|
+
*/
|
|
23
|
+
build(component: React.ReactNode, componentId?: string): ComponentController;
|
|
24
|
+
/**
|
|
25
|
+
* 显示已存在的组件
|
|
26
|
+
* @param componentId 组件 ID
|
|
27
|
+
*/
|
|
28
|
+
show(componentId: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* 隐藏但不删除组件
|
|
31
|
+
* @param componentId 组件 ID
|
|
32
|
+
*/
|
|
33
|
+
hide(componentId: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* 更新组件内容
|
|
36
|
+
* @param componentId 组件 ID
|
|
37
|
+
* @param component 新的组件内容
|
|
38
|
+
*/
|
|
39
|
+
update(componentId: string, component: React.ReactNode): void;
|
|
40
|
+
/**
|
|
41
|
+
* 彻底删除组件
|
|
42
|
+
* @param componentId 组件 ID(必需)
|
|
43
|
+
*/
|
|
44
|
+
remove(componentId: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* 移除最后一个组件(可选:用于向后兼容)
|
|
47
|
+
*/
|
|
48
|
+
removeLast(): void;
|
|
49
|
+
/**
|
|
50
|
+
* 清空所有组件
|
|
51
|
+
*/
|
|
52
|
+
clearAll(): void;
|
|
53
|
+
/**
|
|
54
|
+
* 注册更新回调
|
|
55
|
+
* @param updateCallback 更新回调函数
|
|
56
|
+
*/
|
|
57
|
+
registerUpdateCallback(updateCallback?: () => void): void;
|
|
58
|
+
/**
|
|
59
|
+
* 获取组件列表
|
|
60
|
+
* @returns 组件列表
|
|
61
|
+
*/
|
|
62
|
+
getComponents(): ComponentItem[];
|
|
63
|
+
/**
|
|
64
|
+
* 获取组件数量
|
|
65
|
+
* @returns 组件数量
|
|
66
|
+
*/
|
|
67
|
+
getComponentCount(): number;
|
|
68
|
+
/**
|
|
69
|
+
* 获取可见组件数量
|
|
70
|
+
* @returns 可见组件数量
|
|
71
|
+
*/
|
|
72
|
+
getVisibleComponentCount(): number;
|
|
73
|
+
/**
|
|
74
|
+
* 检查组件是否存在
|
|
75
|
+
* @param componentId 组件 ID
|
|
76
|
+
* @returns 是否存在
|
|
77
|
+
*/
|
|
78
|
+
hasComponent(componentId: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* 检查组件是否可见
|
|
81
|
+
* @param componentId 组件 ID
|
|
82
|
+
* @returns 是否可见
|
|
83
|
+
*/
|
|
84
|
+
isVisible(componentId: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* 触发更新
|
|
87
|
+
*/
|
|
88
|
+
private triggerUpdate;
|
|
89
|
+
/**
|
|
90
|
+
* 创建组件控制器
|
|
91
|
+
* @param componentId 组件 ID
|
|
92
|
+
* @returns 组件控制器
|
|
93
|
+
*/
|
|
94
|
+
private createController;
|
|
95
|
+
/**
|
|
96
|
+
* 自动生成 componentId
|
|
97
|
+
* @returns 生成的 componentId
|
|
98
|
+
*/
|
|
99
|
+
private autoComponentId;
|
|
100
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FXViewCategoryController = void 0;
|
|
4
|
+
const PriorityQueue_1 = require("./queue/PriorityQueue");
|
|
5
|
+
class FXViewCategoryController {
|
|
6
|
+
constructor(fxViewId, categoryId, triggerUpdate) {
|
|
7
|
+
// 存储组件的 Map 和优先队列
|
|
8
|
+
this.componentMap = new Map();
|
|
9
|
+
this.componentQueue = new PriorityQueue_1.PriorityQueue(PriorityQueue_1.HeapType.MAX_HEAP, PriorityQueue_1.PriorityOrder.FIFO);
|
|
10
|
+
this.fxViewId = fxViewId;
|
|
11
|
+
this.categoryId = categoryId;
|
|
12
|
+
this.updateCallback = triggerUpdate;
|
|
13
|
+
}
|
|
14
|
+
// ========== 主要 API 方法 ==========
|
|
15
|
+
/**
|
|
16
|
+
* 创建并展示组件
|
|
17
|
+
* @param component 要显示的组件
|
|
18
|
+
* @param componentId 可选的组件 ID
|
|
19
|
+
* @returns 组件控制器
|
|
20
|
+
*/
|
|
21
|
+
add(component, componentId) {
|
|
22
|
+
console.log(`FXViewCategoryController.add`, `[${this.categoryId}]`, componentId);
|
|
23
|
+
const finalComponentId = componentId || this.autoComponentId();
|
|
24
|
+
// 如果组件已存在,先移除旧的
|
|
25
|
+
if (this.componentMap.has(finalComponentId)) {
|
|
26
|
+
console.warn(`Component ${finalComponentId} already exists, removing old one`);
|
|
27
|
+
this.remove(finalComponentId);
|
|
28
|
+
}
|
|
29
|
+
const componentItem = {
|
|
30
|
+
componentId: finalComponentId,
|
|
31
|
+
component,
|
|
32
|
+
visible: true, // add 方法默认可见
|
|
33
|
+
};
|
|
34
|
+
this.componentMap.set(finalComponentId, componentItem);
|
|
35
|
+
this.componentQueue.enqueue(componentItem);
|
|
36
|
+
this.triggerUpdate();
|
|
37
|
+
return this.createController(finalComponentId);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 创建但不显示组件
|
|
41
|
+
* @param component 要创建的组件
|
|
42
|
+
* @param componentId 可选的组件 ID
|
|
43
|
+
* @returns 组件控制器
|
|
44
|
+
*/
|
|
45
|
+
build(component, componentId) {
|
|
46
|
+
console.log(`FXViewCategoryController.build`, `[${this.categoryId}]`, componentId);
|
|
47
|
+
const finalComponentId = componentId || this.autoComponentId();
|
|
48
|
+
// 如果组件已存在,先移除旧的
|
|
49
|
+
if (this.componentMap.has(finalComponentId)) {
|
|
50
|
+
console.warn(`Component ${finalComponentId} already exists, removing old one`);
|
|
51
|
+
this.remove(finalComponentId);
|
|
52
|
+
}
|
|
53
|
+
const componentItem = {
|
|
54
|
+
componentId: finalComponentId,
|
|
55
|
+
component,
|
|
56
|
+
visible: false, // build 方法默认不可见
|
|
57
|
+
};
|
|
58
|
+
this.componentMap.set(finalComponentId, componentItem);
|
|
59
|
+
this.componentQueue.enqueue(componentItem);
|
|
60
|
+
// build 不触发更新,因为组件不可见
|
|
61
|
+
// this.triggerUpdate();
|
|
62
|
+
return this.createController(finalComponentId);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 显示已存在的组件
|
|
66
|
+
* @param componentId 组件 ID
|
|
67
|
+
*/
|
|
68
|
+
show(componentId) {
|
|
69
|
+
console.log(`FXViewCategoryController.show`, `[${this.categoryId}]`, componentId);
|
|
70
|
+
const componentItem = this.componentMap.get(componentId);
|
|
71
|
+
if (!componentItem) {
|
|
72
|
+
console.warn(`Component ${componentId} not found in category ${this.categoryId}`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// 如果已经可见,不需要重复操作
|
|
76
|
+
if (componentItem.visible) {
|
|
77
|
+
console.log(`Component ${componentId} is already visible`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
componentItem.visible = true;
|
|
81
|
+
this.triggerUpdate();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 隐藏但不删除组件
|
|
85
|
+
* @param componentId 组件 ID
|
|
86
|
+
*/
|
|
87
|
+
hide(componentId) {
|
|
88
|
+
console.log(`FXViewCategoryController.hide`, `[${this.categoryId}]`, componentId);
|
|
89
|
+
const componentItem = this.componentMap.get(componentId);
|
|
90
|
+
if (!componentItem) {
|
|
91
|
+
console.warn(`Component ${componentId} not found in category ${this.categoryId}`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// 如果已经隐藏,不需要重复操作
|
|
95
|
+
if (!componentItem.visible) {
|
|
96
|
+
console.log(`Component ${componentId} is already hidden`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
componentItem.visible = false;
|
|
100
|
+
this.triggerUpdate();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 更新组件内容
|
|
104
|
+
* @param componentId 组件 ID
|
|
105
|
+
* @param component 新的组件内容
|
|
106
|
+
*/
|
|
107
|
+
update(componentId, component) {
|
|
108
|
+
console.log(`FXViewCategoryController.update`, `[${this.categoryId}]`, componentId);
|
|
109
|
+
const componentItem = this.componentMap.get(componentId);
|
|
110
|
+
if (!componentItem) {
|
|
111
|
+
console.warn(`Component ${componentId} not found in category ${this.categoryId}`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// 更新组件内容
|
|
115
|
+
componentItem.component = component;
|
|
116
|
+
// 只有在组件可见时才触发更新
|
|
117
|
+
if (componentItem.visible) {
|
|
118
|
+
this.triggerUpdate();
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.log(`Component ${componentId} is hidden, update without re-render`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 彻底删除组件
|
|
126
|
+
* @param componentId 组件 ID(必需)
|
|
127
|
+
*/
|
|
128
|
+
remove(componentId) {
|
|
129
|
+
console.log(`FXViewCategoryController.remove`, `[${this.categoryId}]`, componentId);
|
|
130
|
+
const componentItem = this.componentMap.get(componentId);
|
|
131
|
+
if (!componentItem) {
|
|
132
|
+
console.warn(`Component ${componentId} not found in category ${this.categoryId}`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// 从 Map 中删除
|
|
136
|
+
this.componentMap.delete(componentId);
|
|
137
|
+
// 从优先队列中删除
|
|
138
|
+
this.componentQueue.remove(componentItem);
|
|
139
|
+
this.triggerUpdate();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 移除最后一个组件(可选:用于向后兼容)
|
|
143
|
+
*/
|
|
144
|
+
removeLast() {
|
|
145
|
+
console.log(`FXViewCategoryController.removeLast`, `[${this.categoryId}]`);
|
|
146
|
+
const lastComponent = this.componentQueue.peek();
|
|
147
|
+
if (!lastComponent) {
|
|
148
|
+
console.warn(`No component to remove in category ${this.categoryId}`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
this.remove(lastComponent.componentId);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 清空所有组件
|
|
155
|
+
*/
|
|
156
|
+
clearAll() {
|
|
157
|
+
console.log(`FXViewCategoryController.clearAll`, `[${this.categoryId}]`);
|
|
158
|
+
const hadVisibleComponents = Array.from(this.componentMap.values()).some((item) => item.visible);
|
|
159
|
+
this.componentMap.clear();
|
|
160
|
+
this.componentQueue.clear();
|
|
161
|
+
// 只有在有可见组件时才触发更新
|
|
162
|
+
if (hadVisibleComponents) {
|
|
163
|
+
this.triggerUpdate();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 注册更新回调
|
|
168
|
+
* @param updateCallback 更新回调函数
|
|
169
|
+
*/
|
|
170
|
+
registerUpdateCallback(updateCallback) {
|
|
171
|
+
this.updateCallback = updateCallback;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 获取组件列表
|
|
175
|
+
* @returns 组件列表
|
|
176
|
+
*/
|
|
177
|
+
getComponents() {
|
|
178
|
+
return this.componentQueue.getAll();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* 获取组件数量
|
|
182
|
+
* @returns 组件数量
|
|
183
|
+
*/
|
|
184
|
+
getComponentCount() {
|
|
185
|
+
return this.componentMap.size;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 获取可见组件数量
|
|
189
|
+
* @returns 可见组件数量
|
|
190
|
+
*/
|
|
191
|
+
getVisibleComponentCount() {
|
|
192
|
+
return Array.from(this.componentMap.values()).filter((item) => item.visible)
|
|
193
|
+
.length;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 检查组件是否存在
|
|
197
|
+
* @param componentId 组件 ID
|
|
198
|
+
* @returns 是否存在
|
|
199
|
+
*/
|
|
200
|
+
hasComponent(componentId) {
|
|
201
|
+
return this.componentMap.has(componentId);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 检查组件是否可见
|
|
205
|
+
* @param componentId 组件 ID
|
|
206
|
+
* @returns 是否可见
|
|
207
|
+
*/
|
|
208
|
+
isVisible(componentId) {
|
|
209
|
+
var _a;
|
|
210
|
+
const component = this.componentMap.get(componentId);
|
|
211
|
+
return (_a = component === null || component === void 0 ? void 0 : component.visible) !== null && _a !== void 0 ? _a : false;
|
|
212
|
+
}
|
|
213
|
+
// ========== 私有方法 ==========
|
|
214
|
+
/**
|
|
215
|
+
* 触发更新
|
|
216
|
+
*/
|
|
217
|
+
triggerUpdate() {
|
|
218
|
+
console.log(`FXViewCategoryController.triggerUpdate`, `[${this.categoryId}]`);
|
|
219
|
+
if (this.updateCallback) {
|
|
220
|
+
this.updateCallback();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 创建组件控制器
|
|
225
|
+
* @param componentId 组件 ID
|
|
226
|
+
* @returns 组件控制器
|
|
227
|
+
*/
|
|
228
|
+
createController(componentId) {
|
|
229
|
+
console.log(`FXViewCategoryController.createController`, `[${this.categoryId}]`, componentId);
|
|
230
|
+
// ✅ 修复:不在闭包中捕获 componentItem,每次都从 Map 获取最新引用
|
|
231
|
+
return {
|
|
232
|
+
show: () => {
|
|
233
|
+
this.show(componentId);
|
|
234
|
+
},
|
|
235
|
+
hide: () => {
|
|
236
|
+
this.hide(componentId);
|
|
237
|
+
},
|
|
238
|
+
remove: () => {
|
|
239
|
+
this.remove(componentId);
|
|
240
|
+
},
|
|
241
|
+
update: (component) => {
|
|
242
|
+
this.update(componentId, component);
|
|
243
|
+
},
|
|
244
|
+
getFxViewId: () => this.fxViewId,
|
|
245
|
+
getCategoryId: () => this.categoryId,
|
|
246
|
+
getComponentId: () => componentId,
|
|
247
|
+
getComponent: () => {
|
|
248
|
+
var _a;
|
|
249
|
+
// ✅ 每次都从 Map 获取最新的组件引用
|
|
250
|
+
return (_a = this.componentMap.get(componentId)) === null || _a === void 0 ? void 0 : _a.component;
|
|
251
|
+
},
|
|
252
|
+
isVisible: () => {
|
|
253
|
+
return this.isVisible(componentId);
|
|
254
|
+
},
|
|
255
|
+
exists: () => {
|
|
256
|
+
return this.hasComponent(componentId);
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* 自动生成 componentId
|
|
262
|
+
* @returns 生成的 componentId
|
|
263
|
+
*/
|
|
264
|
+
autoComponentId() {
|
|
265
|
+
return `component_${Date.now()}_${Math.random()
|
|
266
|
+
.toString(36)
|
|
267
|
+
.substring(2, 9)}`;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.FXViewCategoryController = FXViewCategoryController;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ComponentItem, ComponentController } from "./types";
|
|
3
|
-
import { HeapType, PriorityOrder, PriorityQueue } from "
|
|
3
|
+
import { HeapType, PriorityOrder, PriorityQueue } from "./queue/PriorityQueue";
|
|
4
4
|
|
|
5
5
|
export class FXViewCategoryController {
|
|
6
6
|
public fxViewId: string;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ComponentController, ComponentItem } from "./types";
|
|
3
|
+
export declare class FXViewController {
|
|
4
|
+
fxViewId: string;
|
|
5
|
+
updateCallback?: () => void;
|
|
6
|
+
private categoryControllerMap;
|
|
7
|
+
constructor(fxViewId: string);
|
|
8
|
+
/**
|
|
9
|
+
* 创建并显示组件
|
|
10
|
+
* @param component 组件内容
|
|
11
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
12
|
+
* @param componentId 组件 ID(可选,自动生成)
|
|
13
|
+
* @returns 组件控制器
|
|
14
|
+
*/
|
|
15
|
+
add(component: React.ReactNode, categoryId?: string, componentId?: string): ComponentController;
|
|
16
|
+
/**
|
|
17
|
+
* 创建但不显示组件
|
|
18
|
+
* @param component 组件内容
|
|
19
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
20
|
+
* @param componentId 组件 ID(可选,自动生成)
|
|
21
|
+
* @returns 组件控制器
|
|
22
|
+
*/
|
|
23
|
+
build(component: React.ReactNode, categoryId?: string, componentId?: string): ComponentController;
|
|
24
|
+
/**
|
|
25
|
+
* 显示已存在的组件
|
|
26
|
+
* @param componentId 组件 ID
|
|
27
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
28
|
+
*/
|
|
29
|
+
show(componentId: string, categoryId?: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* 隐藏但不删除组件
|
|
32
|
+
* @param componentId 组件 ID
|
|
33
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
34
|
+
*/
|
|
35
|
+
hide(componentId: string, categoryId?: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* 更新组件内容
|
|
38
|
+
* @param componentId 组件 ID
|
|
39
|
+
* @param component 新的组件内容
|
|
40
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
41
|
+
*/
|
|
42
|
+
update(componentId: string, component: React.ReactNode, categoryId?: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* 彻底删除组件
|
|
45
|
+
* @param componentId 组件 ID
|
|
46
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
47
|
+
*/
|
|
48
|
+
remove(componentId: string, categoryId?: string): void;
|
|
49
|
+
/**
|
|
50
|
+
* 移除最后一个组件(向后兼容)
|
|
51
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
52
|
+
*/
|
|
53
|
+
removeLast(categoryId?: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* 清空所有分类的所有组件
|
|
56
|
+
*/
|
|
57
|
+
clearAll(): void;
|
|
58
|
+
/**
|
|
59
|
+
* 清空指定分类的所有组件
|
|
60
|
+
* @param categoryId 分类 ID
|
|
61
|
+
*/
|
|
62
|
+
clearCategory(categoryId?: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* 注册更新回调
|
|
65
|
+
* @param callback 更新回调函数
|
|
66
|
+
*/
|
|
67
|
+
registerUpdateCallback(callback?: () => void): void;
|
|
68
|
+
/**
|
|
69
|
+
* 获取组件列表
|
|
70
|
+
* @param filterOptions 过滤选项
|
|
71
|
+
* @returns 组件列表
|
|
72
|
+
*/
|
|
73
|
+
getComponents(categoryId?: string): ComponentItem[];
|
|
74
|
+
/**
|
|
75
|
+
* 获取总组件数量
|
|
76
|
+
* @returns 组件数量
|
|
77
|
+
*/
|
|
78
|
+
getComponentCount(): number;
|
|
79
|
+
/**
|
|
80
|
+
* 获取可见组件数量
|
|
81
|
+
* @returns 可见组件数量
|
|
82
|
+
*/
|
|
83
|
+
getVisibleComponentCount(): number;
|
|
84
|
+
/**
|
|
85
|
+
* 检查组件是否存在
|
|
86
|
+
* @param componentId 组件 ID
|
|
87
|
+
* @param categoryId 分类 ID(可选)
|
|
88
|
+
* @returns 是否存在
|
|
89
|
+
*/
|
|
90
|
+
hasComponent(componentId: string, categoryId?: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* 检查组件是否可见
|
|
93
|
+
* @param componentId 组件 ID
|
|
94
|
+
* @param categoryId 分类 ID(可选)
|
|
95
|
+
* @returns 是否可见
|
|
96
|
+
*/
|
|
97
|
+
isComponentVisible(componentId: string, categoryId?: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* 获取分类控制器
|
|
100
|
+
* @param categoryId 分类 ID
|
|
101
|
+
* @returns 分类控制器或 null
|
|
102
|
+
*/
|
|
103
|
+
private getCategoryController;
|
|
104
|
+
/**
|
|
105
|
+
* 获取或创建分类控制器
|
|
106
|
+
* @param categoryId 分类 ID
|
|
107
|
+
* @returns 分类控制器
|
|
108
|
+
*/
|
|
109
|
+
private getCategoryControllerOrCreate;
|
|
110
|
+
/**
|
|
111
|
+
* 删除分类控制器
|
|
112
|
+
* @param categoryId 分类 ID
|
|
113
|
+
*/
|
|
114
|
+
private removeCategory;
|
|
115
|
+
}
|