react-native-fxview 1.0.0 → 1.0.2
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/FXCategoryController.d.ts +100 -0
- package/FXCategoryController.js +270 -0
- package/{FXViewCategoryController.ts → FXCategoryController.ts} +14 -11
- package/FXView.d.ts +20 -0
- package/FXView.js +103 -0
- package/FXView.tsx +3 -3
- package/FXViewController.d.ts +115 -0
- package/FXViewController.js +289 -0
- package/FXViewController.ts +14 -11
- package/FXViewManager.d.ts +146 -0
- package/FXViewManager.js +354 -0
- package/FXViewManager.ts +39 -19
- package/README.md +209 -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 +39 -0
- package/types.js +2 -0
- package/types.ts +7 -2
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FXComponentController, FXComponentItem } 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): FXComponentController;
|
|
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): FXComponentController;
|
|
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): FXComponentItem[];
|
|
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
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FXViewController = void 0;
|
|
4
|
+
const FXCategoryController_1 = require("./FXCategoryController");
|
|
5
|
+
class FXViewController {
|
|
6
|
+
constructor(fxViewId) {
|
|
7
|
+
// 存储各分类的控制器
|
|
8
|
+
this.categoryControllerMap = new Map();
|
|
9
|
+
this.fxViewId = fxViewId;
|
|
10
|
+
}
|
|
11
|
+
//#region ========== 主要 API 方法 ==========
|
|
12
|
+
/**
|
|
13
|
+
* 创建并显示组件
|
|
14
|
+
* @param component 组件内容
|
|
15
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
16
|
+
* @param componentId 组件 ID(可选,自动生成)
|
|
17
|
+
* @returns 组件控制器
|
|
18
|
+
*/
|
|
19
|
+
add(component, categoryId, componentId) {
|
|
20
|
+
console.log("FXViewController.add", `[${this.fxViewId}]`, {
|
|
21
|
+
categoryId,
|
|
22
|
+
componentId,
|
|
23
|
+
});
|
|
24
|
+
const categoryController = this.getCategoryControllerOrCreate(categoryId);
|
|
25
|
+
return categoryController.add(component, componentId);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 创建但不显示组件
|
|
29
|
+
* @param component 组件内容
|
|
30
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
31
|
+
* @param componentId 组件 ID(可选,自动生成)
|
|
32
|
+
* @returns 组件控制器
|
|
33
|
+
*/
|
|
34
|
+
build(component, categoryId, componentId) {
|
|
35
|
+
console.log("FXViewController.build", `[${this.fxViewId}]`, {
|
|
36
|
+
categoryId,
|
|
37
|
+
componentId,
|
|
38
|
+
});
|
|
39
|
+
const categoryController = this.getCategoryControllerOrCreate(categoryId);
|
|
40
|
+
return categoryController.build(component, componentId);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 显示已存在的组件
|
|
44
|
+
* @param componentId 组件 ID
|
|
45
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
46
|
+
*/
|
|
47
|
+
show(componentId, categoryId) {
|
|
48
|
+
console.log("FXViewController.show", `[${this.fxViewId}]`, {
|
|
49
|
+
categoryId,
|
|
50
|
+
componentId,
|
|
51
|
+
});
|
|
52
|
+
const categoryController = this.getCategoryController(categoryId);
|
|
53
|
+
if (!categoryController) {
|
|
54
|
+
console.warn(`CategoryController ${categoryId || "default"} not found in view ${this.fxViewId}`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
categoryController.show(componentId);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 隐藏但不删除组件
|
|
61
|
+
* @param componentId 组件 ID
|
|
62
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
63
|
+
*/
|
|
64
|
+
hide(componentId, categoryId) {
|
|
65
|
+
console.log("FXViewController.hide", `[${this.fxViewId}]`, {
|
|
66
|
+
categoryId,
|
|
67
|
+
componentId,
|
|
68
|
+
});
|
|
69
|
+
const categoryController = this.getCategoryController(categoryId);
|
|
70
|
+
if (!categoryController) {
|
|
71
|
+
console.warn(`CategoryController ${categoryId || "default"} not found in view ${this.fxViewId}`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
categoryController.hide(componentId);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 更新组件内容
|
|
78
|
+
* @param componentId 组件 ID
|
|
79
|
+
* @param component 新的组件内容
|
|
80
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
81
|
+
*/
|
|
82
|
+
update(componentId, component, categoryId) {
|
|
83
|
+
console.log("FXViewController.update", `[${this.fxViewId}]`, {
|
|
84
|
+
categoryId,
|
|
85
|
+
componentId,
|
|
86
|
+
});
|
|
87
|
+
const categoryController = this.getCategoryController(categoryId);
|
|
88
|
+
if (!categoryController) {
|
|
89
|
+
console.warn(`CategoryController ${categoryId || "default"} not found in view ${this.fxViewId}`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
categoryController.update(componentId, component);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 彻底删除组件
|
|
96
|
+
* @param componentId 组件 ID
|
|
97
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
98
|
+
*/
|
|
99
|
+
remove(componentId, categoryId) {
|
|
100
|
+
console.log("FXViewController.remove", `[${this.fxViewId}]`, {
|
|
101
|
+
categoryId,
|
|
102
|
+
componentId,
|
|
103
|
+
});
|
|
104
|
+
const categoryController = this.getCategoryController(categoryId);
|
|
105
|
+
if (!categoryController) {
|
|
106
|
+
console.warn(`CategoryController ${categoryId || "default"} not found in view ${this.fxViewId}`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
categoryController.remove(componentId);
|
|
110
|
+
// 如果该分类没有组件了,删除整个分类控制器
|
|
111
|
+
if (categoryController.getComponentCount() === 0) {
|
|
112
|
+
this.removeCategory(categoryId);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 移除最后一个组件(向后兼容)
|
|
117
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
118
|
+
*/
|
|
119
|
+
removeLast(categoryId) {
|
|
120
|
+
console.log("FXViewController.removeLast", `[${this.fxViewId}]`, {
|
|
121
|
+
categoryId,
|
|
122
|
+
});
|
|
123
|
+
const categoryController = this.getCategoryController(categoryId);
|
|
124
|
+
if (!categoryController) {
|
|
125
|
+
console.warn(`CategoryController ${categoryId || "default"} not found in view ${this.fxViewId}`);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
categoryController.removeLast();
|
|
129
|
+
// 如果该分类没有组件了,删除整个分类控制器
|
|
130
|
+
if (categoryController.getComponentCount() === 0) {
|
|
131
|
+
this.removeCategory(categoryId);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 清空所有分类的所有组件
|
|
136
|
+
*/
|
|
137
|
+
clearAll() {
|
|
138
|
+
console.log("FXViewController.clearAll", `[${this.fxViewId}]`);
|
|
139
|
+
this.categoryControllerMap.forEach((controller) => {
|
|
140
|
+
controller.clearAll();
|
|
141
|
+
});
|
|
142
|
+
this.categoryControllerMap.clear();
|
|
143
|
+
console.log("FXViewController.clearAll done", this.categoryControllerMap.size);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 清空指定分类的所有组件
|
|
147
|
+
* @param categoryId 分类 ID
|
|
148
|
+
*/
|
|
149
|
+
clearCategory(categoryId) {
|
|
150
|
+
const finalCategoryId = categoryId || "default";
|
|
151
|
+
console.log("FXViewController.clearCategory", `[${this.fxViewId}]`, {
|
|
152
|
+
categoryId: finalCategoryId,
|
|
153
|
+
});
|
|
154
|
+
const categoryController = this.getCategoryController(categoryId);
|
|
155
|
+
if (!categoryController) {
|
|
156
|
+
console.warn(`CategoryController ${finalCategoryId} not found in view ${this.fxViewId}`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
categoryController.clearAll();
|
|
160
|
+
this.categoryControllerMap.delete(finalCategoryId);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 注册更新回调
|
|
164
|
+
* @param callback 更新回调函数
|
|
165
|
+
*/
|
|
166
|
+
registerUpdateCallback(callback) {
|
|
167
|
+
this.updateCallback = callback;
|
|
168
|
+
// 将回调传递给所有已存在的分类控制器
|
|
169
|
+
this.categoryControllerMap.forEach((controller) => {
|
|
170
|
+
controller.registerUpdateCallback(callback);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* 获取组件列表
|
|
175
|
+
* @param filterOptions 过滤选项
|
|
176
|
+
* @returns 组件列表
|
|
177
|
+
*/
|
|
178
|
+
getComponents(categoryId) {
|
|
179
|
+
const result = [];
|
|
180
|
+
this.categoryControllerMap.forEach((categoryController, category) => {
|
|
181
|
+
// 如果指定了类别,只处理指定类别
|
|
182
|
+
if (categoryId && categoryId !== category) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const categoryComponents = categoryController.getComponents();
|
|
186
|
+
result.push(...categoryComponents);
|
|
187
|
+
});
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 获取总组件数量
|
|
192
|
+
* @returns 组件数量
|
|
193
|
+
*/
|
|
194
|
+
getComponentCount() {
|
|
195
|
+
let count = 0;
|
|
196
|
+
this.categoryControllerMap.forEach((controller) => {
|
|
197
|
+
count += controller.getComponentCount();
|
|
198
|
+
});
|
|
199
|
+
return count;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 获取可见组件数量
|
|
203
|
+
* @returns 可见组件数量
|
|
204
|
+
*/
|
|
205
|
+
getVisibleComponentCount() {
|
|
206
|
+
let count = 0;
|
|
207
|
+
this.categoryControllerMap.forEach((controller) => {
|
|
208
|
+
count += controller.getVisibleComponentCount();
|
|
209
|
+
});
|
|
210
|
+
return count;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* 检查组件是否存在
|
|
214
|
+
* @param componentId 组件 ID
|
|
215
|
+
* @param categoryId 分类 ID(可选)
|
|
216
|
+
* @returns 是否存在
|
|
217
|
+
*/
|
|
218
|
+
hasComponent(componentId, categoryId) {
|
|
219
|
+
var _a;
|
|
220
|
+
if (categoryId) {
|
|
221
|
+
const controller = this.getCategoryController(categoryId);
|
|
222
|
+
return (_a = controller === null || controller === void 0 ? void 0 : controller.hasComponent(componentId)) !== null && _a !== void 0 ? _a : false;
|
|
223
|
+
}
|
|
224
|
+
// 如果没有指定分类,搜索所有分类
|
|
225
|
+
for (const controller of this.categoryControllerMap.values()) {
|
|
226
|
+
if (controller.hasComponent(componentId)) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* 检查组件是否可见
|
|
234
|
+
* @param componentId 组件 ID
|
|
235
|
+
* @param categoryId 分类 ID(可选)
|
|
236
|
+
* @returns 是否可见
|
|
237
|
+
*/
|
|
238
|
+
isComponentVisible(componentId, categoryId) {
|
|
239
|
+
var _a;
|
|
240
|
+
if (categoryId) {
|
|
241
|
+
const controller = this.getCategoryController(categoryId);
|
|
242
|
+
return (_a = controller === null || controller === void 0 ? void 0 : controller.isVisible(componentId)) !== null && _a !== void 0 ? _a : false;
|
|
243
|
+
}
|
|
244
|
+
// 如果没有指定分类,搜索所有分类
|
|
245
|
+
for (const controller of this.categoryControllerMap.values()) {
|
|
246
|
+
if (controller.hasComponent(componentId)) {
|
|
247
|
+
return controller.isVisible(componentId);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region ========== 私有方法 ==========
|
|
254
|
+
/**
|
|
255
|
+
* 获取分类控制器
|
|
256
|
+
* @param categoryId 分类 ID
|
|
257
|
+
* @returns 分类控制器或 null
|
|
258
|
+
*/
|
|
259
|
+
getCategoryController(categoryId) {
|
|
260
|
+
const finalCategoryId = categoryId || "default";
|
|
261
|
+
return this.categoryControllerMap.get(finalCategoryId) || null;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 获取或创建分类控制器
|
|
265
|
+
* @param categoryId 分类 ID
|
|
266
|
+
* @returns 分类控制器
|
|
267
|
+
*/
|
|
268
|
+
getCategoryControllerOrCreate(categoryId) {
|
|
269
|
+
const finalCategoryId = categoryId || "default";
|
|
270
|
+
let categoryController = this.categoryControllerMap.get(finalCategoryId);
|
|
271
|
+
if (!categoryController) {
|
|
272
|
+
categoryController = new FXCategoryController_1.FXCategoryController(this.fxViewId, finalCategoryId, this.updateCallback);
|
|
273
|
+
this.categoryControllerMap.set(finalCategoryId, categoryController);
|
|
274
|
+
}
|
|
275
|
+
return categoryController;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* 删除分类控制器
|
|
279
|
+
* @param categoryId 分类 ID
|
|
280
|
+
*/
|
|
281
|
+
removeCategory(categoryId) {
|
|
282
|
+
const finalCategoryId = categoryId || "default";
|
|
283
|
+
console.log("FXViewController.removeCategory", `[${this.fxViewId}]`, {
|
|
284
|
+
categoryId: finalCategoryId,
|
|
285
|
+
});
|
|
286
|
+
this.categoryControllerMap.delete(finalCategoryId);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
exports.FXViewController = FXViewController;
|
package/FXViewController.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { FXComponentController, FXComponentItem } from "./types";
|
|
3
|
+
import { FXCategoryController } from "./FXCategoryController";
|
|
4
4
|
|
|
5
5
|
export class FXViewController {
|
|
6
6
|
public fxViewId: string;
|
|
7
7
|
public updateCallback?: () => void;
|
|
8
8
|
|
|
9
9
|
// 存储各分类的控制器
|
|
10
|
-
private categoryControllerMap: Map<string,
|
|
11
|
-
new Map();
|
|
10
|
+
private categoryControllerMap: Map<string, FXCategoryController> = new Map();
|
|
12
11
|
|
|
13
12
|
constructor(fxViewId: string) {
|
|
14
13
|
this.fxViewId = fxViewId;
|
|
@@ -27,7 +26,7 @@ export class FXViewController {
|
|
|
27
26
|
component: React.ReactNode,
|
|
28
27
|
categoryId?: string,
|
|
29
28
|
componentId?: string,
|
|
30
|
-
):
|
|
29
|
+
): FXComponentController {
|
|
31
30
|
console.log("FXViewController.add", `[${this.fxViewId}]`, {
|
|
32
31
|
categoryId,
|
|
33
32
|
componentId,
|
|
@@ -48,7 +47,7 @@ export class FXViewController {
|
|
|
48
47
|
component: React.ReactNode,
|
|
49
48
|
categoryId?: string,
|
|
50
49
|
componentId?: string,
|
|
51
|
-
):
|
|
50
|
+
): FXComponentController {
|
|
52
51
|
console.log("FXViewController.build", `[${this.fxViewId}]`, {
|
|
53
52
|
categoryId,
|
|
54
53
|
componentId,
|
|
@@ -191,6 +190,10 @@ export class FXViewController {
|
|
|
191
190
|
controller.clearAll();
|
|
192
191
|
});
|
|
193
192
|
this.categoryControllerMap.clear();
|
|
193
|
+
console.log(
|
|
194
|
+
"FXViewController.clearAll done",
|
|
195
|
+
this.categoryControllerMap.size,
|
|
196
|
+
);
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
/**
|
|
@@ -233,8 +236,8 @@ export class FXViewController {
|
|
|
233
236
|
* @param filterOptions 过滤选项
|
|
234
237
|
* @returns 组件列表
|
|
235
238
|
*/
|
|
236
|
-
getComponents(categoryId?: string):
|
|
237
|
-
const result:
|
|
239
|
+
getComponents(categoryId?: string): FXComponentItem[] {
|
|
240
|
+
const result: FXComponentItem[] = [];
|
|
238
241
|
|
|
239
242
|
this.categoryControllerMap.forEach((categoryController, category) => {
|
|
240
243
|
// 如果指定了类别,只处理指定类别
|
|
@@ -325,7 +328,7 @@ export class FXViewController {
|
|
|
325
328
|
*/
|
|
326
329
|
private getCategoryController(
|
|
327
330
|
categoryId?: string,
|
|
328
|
-
):
|
|
331
|
+
): FXCategoryController | null {
|
|
329
332
|
const finalCategoryId = categoryId || "default";
|
|
330
333
|
return this.categoryControllerMap.get(finalCategoryId) || null;
|
|
331
334
|
}
|
|
@@ -337,13 +340,13 @@ export class FXViewController {
|
|
|
337
340
|
*/
|
|
338
341
|
private getCategoryControllerOrCreate(
|
|
339
342
|
categoryId?: string,
|
|
340
|
-
):
|
|
343
|
+
): FXCategoryController {
|
|
341
344
|
const finalCategoryId = categoryId || "default";
|
|
342
345
|
|
|
343
346
|
let categoryController = this.categoryControllerMap.get(finalCategoryId);
|
|
344
347
|
|
|
345
348
|
if (!categoryController) {
|
|
346
|
-
categoryController = new
|
|
349
|
+
categoryController = new FXCategoryController(
|
|
347
350
|
this.fxViewId,
|
|
348
351
|
finalCategoryId,
|
|
349
352
|
this.updateCallback,
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FXComponentController, FXComponentItem, FXLifecycleCallbacks } from "./types";
|
|
3
|
+
import { FXViewController } from "./FXViewController";
|
|
4
|
+
export declare class FXViewManager {
|
|
5
|
+
private static instance;
|
|
6
|
+
private viewControllerMap;
|
|
7
|
+
private fxViewIdQueue;
|
|
8
|
+
private viewLifecycleCallbacks;
|
|
9
|
+
static getInstance(): FXViewManager;
|
|
10
|
+
/**
|
|
11
|
+
* 创建并显示组件
|
|
12
|
+
* @param component 组件内容
|
|
13
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
14
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
15
|
+
* @param componentId 组件 ID(可选,自动生成)
|
|
16
|
+
* @returns 组件控制器
|
|
17
|
+
*/
|
|
18
|
+
add(component: React.ReactNode, fxViewId?: string, categoryId?: string, componentId?: string): FXComponentController;
|
|
19
|
+
/**
|
|
20
|
+
* 创建但不显示组件
|
|
21
|
+
* @param component 组件内容
|
|
22
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
23
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
24
|
+
* @param componentId 组件 ID(可选,自动生成)
|
|
25
|
+
* @returns 组件控制器
|
|
26
|
+
*/
|
|
27
|
+
build(component: React.ReactNode, fxViewId?: string, categoryId?: string, componentId?: string): FXComponentController;
|
|
28
|
+
/**
|
|
29
|
+
* 显示已存在的组件
|
|
30
|
+
* @param componentId 组件 ID
|
|
31
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
32
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
33
|
+
*/
|
|
34
|
+
show(componentId: string, fxViewId?: string, categoryId?: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* 隐藏但不删除组件
|
|
37
|
+
* @param componentId 组件 ID
|
|
38
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
39
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
40
|
+
*/
|
|
41
|
+
hide(componentId: string, fxViewId?: string, categoryId?: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* 更新组件内容
|
|
44
|
+
* @param componentId 组件 ID
|
|
45
|
+
* @param component 新的组件内容
|
|
46
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
47
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
48
|
+
*/
|
|
49
|
+
update(componentId: string, component: React.ReactNode, fxViewId?: string, categoryId?: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* 彻底删除组件
|
|
52
|
+
* @param componentId 组件 ID
|
|
53
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
54
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
55
|
+
*/
|
|
56
|
+
remove(componentId: string, fxViewId?: string, categoryId?: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* 移除最后一个组件(向后兼容)
|
|
59
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
60
|
+
* @param categoryId 分类 ID(可选,默认 "default")
|
|
61
|
+
*/
|
|
62
|
+
removeLast(fxViewId?: string, categoryId?: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* 清空指定视图的所有组件
|
|
65
|
+
* @param fxViewId 视图 ID(可选,清空所有视图)
|
|
66
|
+
*/
|
|
67
|
+
clearAll(fxViewId?: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* 清空指定分类的所有组件
|
|
70
|
+
* @param categoryId 分类 ID
|
|
71
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
72
|
+
*/
|
|
73
|
+
clearCategory(categoryId: string, fxViewId?: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* 注册视图(FXView 挂载时调用)
|
|
76
|
+
* @param fxViewId 视图 ID
|
|
77
|
+
* @param updateCallback 更新回调函数
|
|
78
|
+
* @returns 视图控制器
|
|
79
|
+
*/
|
|
80
|
+
registerView(fxViewId: string, updateCallback: () => void): FXViewController;
|
|
81
|
+
/**
|
|
82
|
+
* 注销视图(FXView 卸载时调用)
|
|
83
|
+
* @param fxViewId 视图 ID
|
|
84
|
+
* @returns 是否成功注销
|
|
85
|
+
*/
|
|
86
|
+
unregisterView(fxViewId: string): boolean;
|
|
87
|
+
registerLifecycleCallbacks(callbacks: FXLifecycleCallbacks): void;
|
|
88
|
+
unregisterLifecycleCallbacks(callbacks: FXLifecycleCallbacks): void;
|
|
89
|
+
/**
|
|
90
|
+
* 获取最近使用的视图 ID(栈顶)
|
|
91
|
+
* @returns 最近的视图 ID 或 null
|
|
92
|
+
*/
|
|
93
|
+
getLatestFXViewId(): string | null;
|
|
94
|
+
/**
|
|
95
|
+
* 获取组件列表
|
|
96
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
97
|
+
* @param categoryId 分类 ID(可选)
|
|
98
|
+
* @returns 组件列表
|
|
99
|
+
*/
|
|
100
|
+
getComponents(fxViewId?: string, categoryId?: string): FXComponentItem[];
|
|
101
|
+
/**
|
|
102
|
+
* 获取组件数量
|
|
103
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
104
|
+
* @returns 组件数量
|
|
105
|
+
*/
|
|
106
|
+
getComponentCount(fxViewId?: string): number;
|
|
107
|
+
/**
|
|
108
|
+
* 获取可见组件数量
|
|
109
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
110
|
+
* @returns 可见组件数量
|
|
111
|
+
*/
|
|
112
|
+
getVisibleComponentCount(fxViewId?: string): number;
|
|
113
|
+
/**
|
|
114
|
+
* 检查组件是否存在
|
|
115
|
+
* @param componentId 组件 ID
|
|
116
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
117
|
+
* @param categoryId 分类 ID(可选)
|
|
118
|
+
* @returns 是否存在
|
|
119
|
+
*/
|
|
120
|
+
hasComponent(componentId: string, fxViewId?: string, categoryId?: string): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* 检查组件是否可见
|
|
123
|
+
* @param componentId 组件 ID
|
|
124
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
125
|
+
* @param categoryId 分类 ID(可选)
|
|
126
|
+
* @returns 是否可见
|
|
127
|
+
*/
|
|
128
|
+
isComponentVisible(componentId: string, fxViewId?: string, categoryId?: string): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* 获取视图控制器
|
|
131
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图)
|
|
132
|
+
* @returns 视图控制器或 null
|
|
133
|
+
*/
|
|
134
|
+
private getViewController;
|
|
135
|
+
/**
|
|
136
|
+
* 获取或创建视图控制器
|
|
137
|
+
* @param fxViewId 视图 ID(可选,使用最近的视图或创建新的)
|
|
138
|
+
* @returns 视图控制器
|
|
139
|
+
*/
|
|
140
|
+
private getViewControllerOrCreate;
|
|
141
|
+
/**
|
|
142
|
+
* 自动生成 fxViewId
|
|
143
|
+
* @returns 生成的 fxViewId
|
|
144
|
+
*/
|
|
145
|
+
private autoFXViewId;
|
|
146
|
+
}
|