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