@nocobase/client-v2 2.0.0-alpha.20

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 (70) hide show
  1. package/LICENSE.txt +172 -0
  2. package/lib/Application.d.ts +124 -0
  3. package/lib/Application.js +489 -0
  4. package/lib/MockApplication.d.ts +16 -0
  5. package/lib/MockApplication.js +96 -0
  6. package/lib/Plugin.d.ts +33 -0
  7. package/lib/Plugin.js +89 -0
  8. package/lib/PluginManager.d.ts +46 -0
  9. package/lib/PluginManager.js +114 -0
  10. package/lib/PluginSettingsManager.d.ts +67 -0
  11. package/lib/PluginSettingsManager.js +148 -0
  12. package/lib/RouterManager.d.ts +61 -0
  13. package/lib/RouterManager.js +198 -0
  14. package/lib/WebSocketClient.d.ts +45 -0
  15. package/lib/WebSocketClient.js +217 -0
  16. package/lib/components/BlankComponent.d.ts +12 -0
  17. package/lib/components/BlankComponent.js +48 -0
  18. package/lib/components/MainComponent.d.ts +10 -0
  19. package/lib/components/MainComponent.js +54 -0
  20. package/lib/components/RouterBridge.d.ts +13 -0
  21. package/lib/components/RouterBridge.js +66 -0
  22. package/lib/components/RouterContextCleaner.d.ts +12 -0
  23. package/lib/components/RouterContextCleaner.js +61 -0
  24. package/lib/components/index.d.ts +10 -0
  25. package/lib/components/index.js +32 -0
  26. package/lib/context.d.ts +11 -0
  27. package/lib/context.js +38 -0
  28. package/lib/hooks/index.d.ts +11 -0
  29. package/lib/hooks/index.js +34 -0
  30. package/lib/hooks/useApp.d.ts +10 -0
  31. package/lib/hooks/useApp.js +41 -0
  32. package/lib/hooks/usePlugin.d.ts +11 -0
  33. package/lib/hooks/usePlugin.js +42 -0
  34. package/lib/hooks/useRouter.d.ts +9 -0
  35. package/lib/hooks/useRouter.js +41 -0
  36. package/lib/index.d.ts +14 -0
  37. package/lib/index.js +40 -0
  38. package/lib/utils/index.d.ts +11 -0
  39. package/lib/utils/index.js +79 -0
  40. package/lib/utils/remotePlugins.d.ts +44 -0
  41. package/lib/utils/remotePlugins.js +131 -0
  42. package/lib/utils/requirejs.d.ts +18 -0
  43. package/lib/utils/requirejs.js +1361 -0
  44. package/lib/utils/types.d.ts +330 -0
  45. package/lib/utils/types.js +28 -0
  46. package/package.json +16 -0
  47. package/src/Application.tsx +539 -0
  48. package/src/MockApplication.tsx +53 -0
  49. package/src/Plugin.ts +78 -0
  50. package/src/PluginManager.ts +114 -0
  51. package/src/PluginSettingsManager.ts +182 -0
  52. package/src/RouterManager.tsx +239 -0
  53. package/src/WebSocketClient.ts +220 -0
  54. package/src/__tests__/app.test.tsx +141 -0
  55. package/src/components/BlankComponent.tsx +12 -0
  56. package/src/components/MainComponent.tsx +20 -0
  57. package/src/components/RouterBridge.tsx +38 -0
  58. package/src/components/RouterContextCleaner.tsx +26 -0
  59. package/src/components/index.ts +11 -0
  60. package/src/context.ts +14 -0
  61. package/src/hooks/index.ts +12 -0
  62. package/src/hooks/useApp.ts +16 -0
  63. package/src/hooks/usePlugin.ts +17 -0
  64. package/src/hooks/useRouter.ts +15 -0
  65. package/src/index.ts +15 -0
  66. package/src/utils/index.tsx +48 -0
  67. package/src/utils/remotePlugins.ts +140 -0
  68. package/src/utils/requirejs.ts +2164 -0
  69. package/src/utils/types.ts +375 -0
  70. package/tsconfig.json +7 -0
package/lib/Plugin.js ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var Plugin_exports = {};
29
+ __export(Plugin_exports, {
30
+ Plugin: () => Plugin
31
+ });
32
+ module.exports = __toCommonJS(Plugin_exports);
33
+ const _Plugin = class _Plugin {
34
+ constructor(options, app) {
35
+ this.options = options;
36
+ this.app = app;
37
+ this.options = options;
38
+ this.app = app;
39
+ }
40
+ get pluginManager() {
41
+ return this.app.pluginManager;
42
+ }
43
+ get context() {
44
+ return this.app.context;
45
+ }
46
+ get flowEngine() {
47
+ return this.app.flowEngine;
48
+ }
49
+ get engine() {
50
+ return this.app.flowEngine;
51
+ }
52
+ get pm() {
53
+ return this.app.pm;
54
+ }
55
+ get router() {
56
+ return this.app.router;
57
+ }
58
+ get pluginSettingsManager() {
59
+ return this.app.pluginSettingsManager;
60
+ }
61
+ get pluginSettingsRouter() {
62
+ return this.app.pluginSettingsManager;
63
+ }
64
+ get schemaInitializerManager() {
65
+ return this.app.schemaInitializerManager;
66
+ }
67
+ get schemaSettingsManager() {
68
+ return this.app.schemaSettingsManager;
69
+ }
70
+ get dataSourceManager() {
71
+ return this.app.dataSourceManager;
72
+ }
73
+ async afterAdd() {
74
+ }
75
+ async beforeLoad() {
76
+ }
77
+ async load() {
78
+ }
79
+ t(text, options = {}) {
80
+ var _a;
81
+ return this.app.i18n.t(text, { ns: (_a = this.options) == null ? void 0 : _a["packageName"], ...options });
82
+ }
83
+ };
84
+ __name(_Plugin, "Plugin");
85
+ let Plugin = _Plugin;
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ Plugin
89
+ });
@@ -0,0 +1,46 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import type { Application } from './Application';
10
+ import type { Plugin } from './Plugin';
11
+ export type PluginOptions<T = any> = {
12
+ name?: string;
13
+ packageName?: string;
14
+ config?: T;
15
+ };
16
+ export type PluginType<Opts = any> = typeof Plugin | [typeof Plugin<Opts>, PluginOptions<Opts>];
17
+ export type PluginData = {
18
+ name: string;
19
+ packageName: string;
20
+ version: string;
21
+ url: string;
22
+ type: 'local' | 'upload' | 'npm';
23
+ };
24
+ export declare class PluginManager {
25
+ protected _plugins: PluginType[];
26
+ protected loadRemotePlugins: boolean;
27
+ protected app: Application;
28
+ protected pluginInstances: Map<typeof Plugin, Plugin>;
29
+ protected pluginsAliases: Record<string, Plugin>;
30
+ private initPlugins;
31
+ constructor(_plugins: PluginType[], loadRemotePlugins: boolean, app: Application);
32
+ /**
33
+ * @internal
34
+ */
35
+ init(_plugins: PluginType[]): Promise<void>;
36
+ private initStaticPlugins;
37
+ private initRemotePlugins;
38
+ add<T = any>(plugin: typeof Plugin, opts?: PluginOptions<T>): Promise<void>;
39
+ get<T extends typeof Plugin>(PluginClass: T): InstanceType<T>;
40
+ get<T extends {}>(name: string): T;
41
+ private getInstance;
42
+ /**
43
+ * @internal
44
+ */
45
+ load(): Promise<void>;
46
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var PluginManager_exports = {};
29
+ __export(PluginManager_exports, {
30
+ PluginManager: () => PluginManager
31
+ });
32
+ module.exports = __toCommonJS(PluginManager_exports);
33
+ var import_remotePlugins = require("./utils/remotePlugins");
34
+ const _PluginManager = class _PluginManager {
35
+ constructor(_plugins, loadRemotePlugins, app) {
36
+ this._plugins = _plugins;
37
+ this.loadRemotePlugins = loadRemotePlugins;
38
+ this.app = app;
39
+ this.app = app;
40
+ this.initPlugins = this.init(_plugins);
41
+ }
42
+ pluginInstances = /* @__PURE__ */ new Map();
43
+ pluginsAliases = {};
44
+ initPlugins;
45
+ /**
46
+ * @internal
47
+ */
48
+ async init(_plugins) {
49
+ await this.initStaticPlugins(_plugins);
50
+ if (this.loadRemotePlugins) {
51
+ await this.initRemotePlugins();
52
+ }
53
+ }
54
+ async initStaticPlugins(_plugins = []) {
55
+ for await (const plugin of _plugins) {
56
+ const pluginClass = Array.isArray(plugin) ? plugin[0] : plugin;
57
+ const opts = Array.isArray(plugin) ? plugin[1] : void 0;
58
+ await this.add(pluginClass, opts);
59
+ }
60
+ }
61
+ async initRemotePlugins() {
62
+ var _a;
63
+ const res = await this.app.apiClient.request({ url: "pm:listEnabled" });
64
+ const pluginList = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.data) || [];
65
+ const plugins = await (0, import_remotePlugins.getPlugins)({
66
+ requirejs: this.app.requirejs,
67
+ pluginData: pluginList,
68
+ devDynamicImport: this.app.devDynamicImport
69
+ });
70
+ for await (const [name, pluginClass] of plugins) {
71
+ const info = pluginList.find((item) => item.name === name);
72
+ await this.add(pluginClass, info);
73
+ }
74
+ }
75
+ async add(plugin, opts = {}) {
76
+ const instance = this.getInstance(plugin, opts);
77
+ this.pluginInstances.set(plugin, instance);
78
+ if (opts.name) {
79
+ this.pluginsAliases[opts.name] = instance;
80
+ }
81
+ if (opts.packageName) {
82
+ this.pluginsAliases[opts.packageName] = instance;
83
+ }
84
+ await instance.afterAdd();
85
+ }
86
+ get(nameOrPluginClass) {
87
+ if (typeof nameOrPluginClass === "string") {
88
+ return this.pluginsAliases[nameOrPluginClass];
89
+ }
90
+ return this.pluginInstances.get(nameOrPluginClass.default || nameOrPluginClass);
91
+ }
92
+ getInstance(plugin, opts) {
93
+ return new plugin(opts, this.app);
94
+ }
95
+ /**
96
+ * @internal
97
+ */
98
+ async load() {
99
+ await this.initPlugins;
100
+ for (const plugin of this.pluginInstances.values()) {
101
+ await plugin.beforeLoad();
102
+ }
103
+ for (const plugin of this.pluginInstances.values()) {
104
+ await plugin.load();
105
+ this.app.eventBus.dispatchEvent(new CustomEvent(`plugin:${plugin.options.name}:loaded`, { detail: plugin }));
106
+ }
107
+ }
108
+ };
109
+ __name(_PluginManager, "PluginManager");
110
+ let PluginManager = _PluginManager;
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ PluginManager
114
+ });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import React from 'react';
10
+ import type { Application } from './Application';
11
+ import type { RouteType } from './RouterManager';
12
+ export declare const ADMIN_SETTINGS_KEY = "admin.settings.";
13
+ export declare const ADMIN_SETTINGS_PATH = "/admin/settings/";
14
+ export declare const SNIPPET_PREFIX = "pm.";
15
+ export interface PluginSettingOptions {
16
+ title: any;
17
+ /**
18
+ * @default Outlet
19
+ */
20
+ Component?: RouteType['Component'];
21
+ icon?: string;
22
+ /**
23
+ * sort, the smaller the number, the higher the priority
24
+ * @default 0
25
+ */
26
+ sort?: number;
27
+ aclSnippet?: string;
28
+ link?: string;
29
+ isTopLevel?: boolean;
30
+ isPinned?: boolean;
31
+ [index: string]: any;
32
+ }
33
+ export interface PluginSettingsPageType {
34
+ label?: string | React.ReactElement;
35
+ title: string | React.ReactElement;
36
+ link?: string;
37
+ key: string;
38
+ icon: any;
39
+ path: string;
40
+ sort?: number;
41
+ name?: string;
42
+ isAllow?: boolean;
43
+ topLevelName?: string;
44
+ aclSnippet: string;
45
+ children?: PluginSettingsPageType[];
46
+ [index: string]: any;
47
+ }
48
+ export declare class PluginSettingsManager {
49
+ protected settings: Record<string, PluginSettingOptions>;
50
+ protected aclSnippets: string[];
51
+ app: Application;
52
+ private cachedList;
53
+ constructor(_pluginSettings: Record<string, PluginSettingOptions>, app: Application);
54
+ clearCache(): void;
55
+ setAclSnippets(aclSnippets: string[]): void;
56
+ getAclSnippet(name: string): string;
57
+ getRouteName(name: string): string;
58
+ getRoutePath(name: string): string;
59
+ add(name: string, options: PluginSettingOptions): void;
60
+ remove(name: string): void;
61
+ hasAuth(name: string): boolean;
62
+ getSetting(name: string): PluginSettingOptions;
63
+ has(name: string): boolean;
64
+ get(name: string, filterAuth?: boolean): PluginSettingsPageType;
65
+ getList(filterAuth?: boolean): PluginSettingsPageType[];
66
+ getAclSnippets(): string[];
67
+ }
@@ -0,0 +1,148 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var PluginSettingsManager_exports = {};
29
+ __export(PluginSettingsManager_exports, {
30
+ ADMIN_SETTINGS_KEY: () => ADMIN_SETTINGS_KEY,
31
+ ADMIN_SETTINGS_PATH: () => ADMIN_SETTINGS_PATH,
32
+ PluginSettingsManager: () => PluginSettingsManager,
33
+ SNIPPET_PREFIX: () => SNIPPET_PREFIX
34
+ });
35
+ module.exports = __toCommonJS(PluginSettingsManager_exports);
36
+ var import_lodash = require("lodash");
37
+ var import_react_router_dom = require("react-router-dom");
38
+ const ADMIN_SETTINGS_KEY = "admin.settings.";
39
+ const ADMIN_SETTINGS_PATH = "/admin/settings/";
40
+ const SNIPPET_PREFIX = "pm.";
41
+ const _PluginSettingsManager = class _PluginSettingsManager {
42
+ settings = {};
43
+ aclSnippets = [];
44
+ app;
45
+ cachedList = {};
46
+ constructor(_pluginSettings, app) {
47
+ this.app = app;
48
+ Object.entries(_pluginSettings || {}).forEach(([name, pluginSettingOptions]) => {
49
+ this.add(name, pluginSettingOptions);
50
+ });
51
+ }
52
+ clearCache() {
53
+ this.cachedList = {};
54
+ }
55
+ setAclSnippets(aclSnippets) {
56
+ this.aclSnippets = aclSnippets;
57
+ }
58
+ getAclSnippet(name) {
59
+ const setting = this.settings[name];
60
+ if (setting == null ? void 0 : setting.skipAclConfigure) {
61
+ return null;
62
+ }
63
+ return (setting == null ? void 0 : setting.aclSnippet) ? setting.aclSnippet : `${SNIPPET_PREFIX}${name}`;
64
+ }
65
+ getRouteName(name) {
66
+ return `${ADMIN_SETTINGS_KEY}${name}`;
67
+ }
68
+ getRoutePath(name) {
69
+ return `${ADMIN_SETTINGS_PATH}${name.replaceAll(".", "/")}`;
70
+ }
71
+ add(name, options) {
72
+ const nameArr = name.split(".");
73
+ const topLevelName = nameArr[0];
74
+ this.settings[name] = {
75
+ ...this.settings[name],
76
+ Component: import_react_router_dom.Outlet,
77
+ ...options,
78
+ name,
79
+ topLevelName: options.topLevelName || topLevelName
80
+ };
81
+ if (nameArr.length > 1) {
82
+ (0, import_lodash.set)(this.settings, nameArr.join(".children."), this.settings[name]);
83
+ }
84
+ this.app.router.add(this.getRouteName(name), {
85
+ path: this.getRoutePath(name),
86
+ Component: this.settings[name].Component
87
+ });
88
+ }
89
+ remove(name) {
90
+ Object.keys(this.settings).forEach((key) => {
91
+ if (key.startsWith(name)) {
92
+ delete this.settings[key];
93
+ this.app.router.remove(`${ADMIN_SETTINGS_KEY}${key}`);
94
+ }
95
+ });
96
+ }
97
+ hasAuth(name) {
98
+ if (this.aclSnippets.includes(`!${this.getAclSnippet("*")}`)) return false;
99
+ return this.aclSnippets.includes(`!${this.getAclSnippet(name)}`) === false;
100
+ }
101
+ getSetting(name) {
102
+ return this.settings[name];
103
+ }
104
+ has(name) {
105
+ const hasAuth = this.hasAuth(name);
106
+ if (!hasAuth) return false;
107
+ return !!this.getSetting(name);
108
+ }
109
+ get(name, filterAuth = true) {
110
+ var _a, _b;
111
+ const isAllow = this.hasAuth(name);
112
+ const pluginSetting = this.getSetting(name);
113
+ if (filterAuth && !isAllow || !pluginSetting) return null;
114
+ const children = Object.keys(pluginSetting.children || {}).sort((a, b) => a.localeCompare(b)).map((key) => this.get(pluginSetting.children[key].name, filterAuth)).filter(Boolean).sort((a, b) => (a.sort || 0) - (b.sort || 0));
115
+ const { title, icon, aclSnippet, ...others } = pluginSetting;
116
+ return {
117
+ isTopLevel: name === pluginSetting.topLevelName,
118
+ ...others,
119
+ aclSnippet: this.getAclSnippet(name),
120
+ title,
121
+ isAllow,
122
+ label: title,
123
+ icon: (_b = (_a = this.app.flowEngine.context).renderIon) == null ? void 0 : _b.call(_a, icon),
124
+ path: this.getRoutePath(name),
125
+ key: name,
126
+ children: children.length ? children : void 0
127
+ };
128
+ }
129
+ getList(filterAuth = true) {
130
+ const cacheKey = JSON.stringify(filterAuth);
131
+ if (this.cachedList[cacheKey]) return this.cachedList[cacheKey];
132
+ return this.cachedList[cacheKey] = Array.from(
133
+ new Set(Object.values(this.settings).map((item) => item.topLevelName))
134
+ ).sort((a, b) => a.localeCompare(b)).map((name) => this.get(name, filterAuth)).filter(Boolean).sort((a, b) => (a.sort || 0) - (b.sort || 0));
135
+ }
136
+ getAclSnippets() {
137
+ return Object.keys(this.settings).map((name) => this.getAclSnippet(name)).filter(Boolean);
138
+ }
139
+ };
140
+ __name(_PluginSettingsManager, "PluginSettingsManager");
141
+ let PluginSettingsManager = _PluginSettingsManager;
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ ADMIN_SETTINGS_KEY,
145
+ ADMIN_SETTINGS_PATH,
146
+ PluginSettingsManager,
147
+ SNIPPET_PREFIX
148
+ });
@@ -0,0 +1,61 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import React, { ComponentType } from 'react';
10
+ import { type BrowserRouterProps, type HashRouterProps, type MemoryRouterProps, type RouteObject } from 'react-router-dom';
11
+ import { Application } from './Application';
12
+ export interface BrowserRouterOptions extends Omit<BrowserRouterProps, 'children'> {
13
+ type?: 'browser';
14
+ }
15
+ export interface HashRouterOptions extends Omit<HashRouterProps, 'children'> {
16
+ type?: 'hash';
17
+ }
18
+ export interface MemoryRouterOptions extends Omit<MemoryRouterProps, 'children'> {
19
+ type?: 'memory';
20
+ }
21
+ export type RouterOptions = (HashRouterOptions | BrowserRouterOptions | MemoryRouterOptions) & {
22
+ renderComponent?: RenderComponentType;
23
+ routes?: Record<string, RouteType>;
24
+ };
25
+ export type ComponentTypeAndString<T = any> = ComponentType<T> | string;
26
+ export interface RouteType extends Omit<RouteObject, 'children' | 'Component'> {
27
+ Component?: ComponentTypeAndString;
28
+ skipAuthCheck?: boolean;
29
+ }
30
+ export type RenderComponentType = (Component: ComponentTypeAndString, props?: any) => React.ReactNode;
31
+ export declare class RouterManager {
32
+ protected routes: Record<string, RouteType>;
33
+ protected options: RouterOptions;
34
+ app: Application;
35
+ router: any;
36
+ get basename(): any;
37
+ get state(): any;
38
+ get navigate(): any;
39
+ constructor(options: RouterOptions, app: Application);
40
+ /**
41
+ * @internal
42
+ */
43
+ getRoutesTree(): RouteObject[];
44
+ getRoutes(): Record<string, RouteType>;
45
+ setType(type: RouterOptions['type']): void;
46
+ getBasename(): string;
47
+ setBasename(basename: string): void;
48
+ matchRoutes(pathname: string): import("@remix-run/router").AgnosticRouteMatch<string, RouteType>[];
49
+ isSkippedAuthCheckRoute(pathname: string): boolean;
50
+ /**
51
+ * @internal
52
+ */
53
+ getRouterComponent(children?: React.ReactNode): React.FC<{
54
+ BaseLayout?: ComponentType;
55
+ }>;
56
+ add(name: string, route: RouteType): void;
57
+ get(name: string): RouteType;
58
+ has(name: string): boolean;
59
+ remove(name: string): void;
60
+ }
61
+ export declare function createRouterManager(options?: RouterOptions, app?: Application): RouterManager;