@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
@@ -0,0 +1,198 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var RouterManager_exports = {};
39
+ __export(RouterManager_exports, {
40
+ RouterManager: () => RouterManager,
41
+ createRouterManager: () => createRouterManager
42
+ });
43
+ module.exports = __toCommonJS(RouterManager_exports);
44
+ var import_lodash = require("lodash");
45
+ var import_react = __toESM(require("react"));
46
+ var import_react_router = require("react-router");
47
+ var import_react_router_dom = require("react-router-dom");
48
+ var import_components = require("./components");
49
+ var import_RouterBridge = require("./components/RouterBridge");
50
+ const _RouterManager = class _RouterManager {
51
+ routes = {};
52
+ options;
53
+ app;
54
+ router;
55
+ get basename() {
56
+ return this.router.basename;
57
+ }
58
+ get state() {
59
+ return this.router.state;
60
+ }
61
+ get navigate() {
62
+ return this.router.navigate;
63
+ }
64
+ constructor(options = {}, app) {
65
+ this.options = options;
66
+ this.app = app;
67
+ this.routes = options.routes || {};
68
+ }
69
+ /**
70
+ * @internal
71
+ */
72
+ getRoutesTree() {
73
+ const routes = {};
74
+ for (const [name, route] of Object.entries(this.routes)) {
75
+ (0, import_lodash.set)(routes, name.split(".").join(".children."), { ...(0, import_lodash.get)(routes, name.split(".").join(".children.")), ...route });
76
+ }
77
+ const buildRoutesTree = /* @__PURE__ */ __name((routes2) => {
78
+ return Object.values(routes2).reduce((acc, item) => {
79
+ if (Object.keys(item).length === 1 && item.children) {
80
+ acc.push(...buildRoutesTree(item.children));
81
+ } else {
82
+ const { Component, element, children, ...reset } = item;
83
+ let ele = element;
84
+ if (Component) {
85
+ if (typeof Component === "string") {
86
+ ele = this.app.renderComponent(Component);
87
+ } else {
88
+ ele = import_react.default.createElement(Component);
89
+ }
90
+ }
91
+ const res = {
92
+ ...reset,
93
+ element: ele,
94
+ children: children ? buildRoutesTree(children) : void 0
95
+ };
96
+ acc.push(res);
97
+ }
98
+ return acc;
99
+ }, []);
100
+ }, "buildRoutesTree");
101
+ return buildRoutesTree(routes);
102
+ }
103
+ getRoutes() {
104
+ return this.routes;
105
+ }
106
+ setType(type) {
107
+ this.options.type = type;
108
+ }
109
+ getBasename() {
110
+ return this.options.basename;
111
+ }
112
+ setBasename(basename) {
113
+ this.options.basename = basename;
114
+ }
115
+ matchRoutes(pathname) {
116
+ const routes = Object.values(this.routes);
117
+ return (0, import_react_router.matchRoutes)(routes, pathname, this.basename);
118
+ }
119
+ isSkippedAuthCheckRoute(pathname) {
120
+ const matchedRoutes = this.matchRoutes(pathname);
121
+ return matchedRoutes.some((match) => {
122
+ var _a;
123
+ return ((_a = match == null ? void 0 : match.route) == null ? void 0 : _a.skipAuthCheck) === true;
124
+ });
125
+ }
126
+ /**
127
+ * @internal
128
+ */
129
+ getRouterComponent(children) {
130
+ const { type = "browser", ...opts } = this.options;
131
+ const routerCreators = {
132
+ hash: import_react_router_dom.createHashRouter,
133
+ browser: import_react_router_dom.createBrowserRouter,
134
+ memory: import_react_router_dom.createMemoryRouter
135
+ };
136
+ const routes = this.getRoutesTree();
137
+ const BaseLayoutContext = (0, import_react.createContext)(null);
138
+ const Provider = /* @__PURE__ */ __name(() => {
139
+ const BaseLayout = (0, import_react.useContext)(BaseLayoutContext);
140
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_RouterBridge.RouterBridge, { app: this.app }), /* @__PURE__ */ import_react.default.createElement(BaseLayout, null, /* @__PURE__ */ import_react.default.createElement(import_react_router_dom.Outlet, null), children));
141
+ }, "Provider");
142
+ const ErrorElement = /* @__PURE__ */ __name(() => {
143
+ const error = (0, import_react_router_dom.useRouteError)();
144
+ throw error;
145
+ }, "ErrorElement");
146
+ this.router = routerCreators[type](
147
+ [
148
+ {
149
+ element: /* @__PURE__ */ import_react.default.createElement(Provider, null),
150
+ errorElement: /* @__PURE__ */ import_react.default.createElement(ErrorElement, null),
151
+ children: routes
152
+ }
153
+ ],
154
+ opts
155
+ );
156
+ const RenderRouter = /* @__PURE__ */ __name(({ BaseLayout = import_components.BlankComponent }) => {
157
+ return /* @__PURE__ */ import_react.default.createElement(BaseLayoutContext.Provider, { value: BaseLayout }, /* @__PURE__ */ import_react.default.createElement(import_components.RouterContextCleaner, null, /* @__PURE__ */ import_react.default.createElement(
158
+ import_react_router_dom.RouterProvider,
159
+ {
160
+ future: {
161
+ v7_startTransition: true
162
+ },
163
+ router: this.router
164
+ }
165
+ )));
166
+ }, "RenderRouter");
167
+ return RenderRouter;
168
+ }
169
+ add(name, route) {
170
+ this.routes[name] = {
171
+ id: name,
172
+ ...route,
173
+ handle: {
174
+ path: route.path
175
+ }
176
+ };
177
+ }
178
+ get(name) {
179
+ return this.routes[name];
180
+ }
181
+ has(name) {
182
+ return !!this.get(name);
183
+ }
184
+ remove(name) {
185
+ delete this.routes[name];
186
+ }
187
+ };
188
+ __name(_RouterManager, "RouterManager");
189
+ let RouterManager = _RouterManager;
190
+ function createRouterManager(options, app) {
191
+ return new RouterManager(options, app);
192
+ }
193
+ __name(createRouterManager, "createRouterManager");
194
+ // Annotate the CommonJS export names for ESM import in node:
195
+ 0 && (module.exports = {
196
+ RouterManager,
197
+ createRouterManager
198
+ });
@@ -0,0 +1,45 @@
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 { Application } from './Application';
10
+ export type WebSocketClientOptions = {
11
+ reconnectInterval?: number;
12
+ reconnectAttempts?: number;
13
+ pingInterval?: number;
14
+ url?: string;
15
+ basename?: string;
16
+ protocols?: string | string[];
17
+ onServerDown?: any;
18
+ };
19
+ export declare class WebSocketClient {
20
+ protected _ws: WebSocket;
21
+ protected _reconnectTimes: number;
22
+ protected events: any[];
23
+ protected options: WebSocketClientOptions;
24
+ app: Application;
25
+ enabled: boolean;
26
+ connected: boolean;
27
+ serverDown: boolean;
28
+ lastMessage: {};
29
+ constructor(options: WebSocketClientOptions | boolean);
30
+ getSubAppName: (app: Application) => string;
31
+ getURL(): string;
32
+ get reconnectAttempts(): number;
33
+ get reconnectInterval(): number;
34
+ get pingInterval(): number;
35
+ get readyState(): number;
36
+ createWebSocket(): WebSocket;
37
+ connect(): void;
38
+ reconnect(): void;
39
+ close(): void;
40
+ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
41
+ on(type: string, listener: any, options?: boolean | AddEventListenerOptions): void;
42
+ emit(type: string, args: any): void;
43
+ off(type: string, listener: any, options?: boolean | EventListenerOptions): void;
44
+ removeAllListeners(): void;
45
+ }
@@ -0,0 +1,217 @@
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 WebSocketClient_exports = {};
29
+ __export(WebSocketClient_exports, {
30
+ WebSocketClient: () => WebSocketClient
31
+ });
32
+ module.exports = __toCommonJS(WebSocketClient_exports);
33
+ var import_reactive = require("@formily/reactive");
34
+ var import_sdk = require("@nocobase/sdk");
35
+ const _WebSocketClient = class _WebSocketClient {
36
+ _ws;
37
+ _reconnectTimes = 0;
38
+ events = [];
39
+ options;
40
+ app;
41
+ enabled;
42
+ connected = false;
43
+ serverDown = false;
44
+ lastMessage = {};
45
+ constructor(options) {
46
+ if (!options) {
47
+ this.enabled = false;
48
+ return;
49
+ }
50
+ this.options = options === true ? {} : options;
51
+ this.enabled = true;
52
+ (0, import_reactive.define)(this, {
53
+ serverDown: import_reactive.observable.ref,
54
+ connected: import_reactive.observable.ref,
55
+ lastMessage: import_reactive.observable.ref
56
+ });
57
+ }
58
+ // TODO for plugin-multi-app
59
+ getSubAppName = /* @__PURE__ */ __name((app) => {
60
+ const publicPath = app.getPublicPath();
61
+ const pattern = `^${publicPath}${"_app"}/([^/]*)/`;
62
+ const match = location.pathname.match(new RegExp(pattern));
63
+ return match ? match[1] : null;
64
+ }, "getSubAppName");
65
+ getURL() {
66
+ if (!this.app) {
67
+ return;
68
+ }
69
+ const apiBaseURL = this.app.getApiUrl();
70
+ if (!apiBaseURL) {
71
+ return;
72
+ }
73
+ let queryString = "";
74
+ if (this.getSubAppName(this.app)) {
75
+ queryString = `?_app=${this.getSubAppName(this.app)}`;
76
+ } else {
77
+ const subApp = (0, import_sdk.getSubAppName)(this.app.getPublicPath());
78
+ queryString = subApp ? `?__appName=${subApp}` : "";
79
+ }
80
+ const wsPath = this.options.basename || "/ws";
81
+ if (this.options.url) {
82
+ const url = new URL(this.options.url);
83
+ if (url.hostname === "localhost") {
84
+ const protocol = location.protocol === "https:" ? "wss" : "ws";
85
+ return `${protocol}://${location.hostname}:${url.port}${wsPath}${queryString}`;
86
+ }
87
+ return `${this.options.url}${queryString}`;
88
+ }
89
+ try {
90
+ const url = new URL(apiBaseURL);
91
+ return `${url.protocol === "https:" ? "wss" : "ws"}://${url.host}${wsPath}${queryString}`;
92
+ } catch (error) {
93
+ return `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}${wsPath}${queryString}`;
94
+ }
95
+ }
96
+ get reconnectAttempts() {
97
+ var _a;
98
+ return ((_a = this.options) == null ? void 0 : _a.reconnectAttempts) || 30;
99
+ }
100
+ get reconnectInterval() {
101
+ var _a;
102
+ return ((_a = this.options) == null ? void 0 : _a.reconnectInterval) || 1e3;
103
+ }
104
+ get pingInterval() {
105
+ var _a;
106
+ return ((_a = this.options) == null ? void 0 : _a.pingInterval) || 3e4;
107
+ }
108
+ get readyState() {
109
+ if (!this._ws) {
110
+ return -1;
111
+ }
112
+ return this._ws.readyState;
113
+ }
114
+ createWebSocket() {
115
+ return new WebSocket(this.getURL(), this.options.protocols);
116
+ }
117
+ connect() {
118
+ if (!this.enabled) {
119
+ return;
120
+ }
121
+ if (this._reconnectTimes === 0) {
122
+ console.log("[nocobase-ws]: connecting...");
123
+ }
124
+ if (this._reconnectTimes >= this.reconnectAttempts) {
125
+ return;
126
+ }
127
+ if (this.readyState === WebSocket.OPEN) {
128
+ return;
129
+ }
130
+ this._reconnectTimes++;
131
+ const ws = this.createWebSocket();
132
+ let pingIntervalTimer;
133
+ ws.onopen = () => {
134
+ console.log("[nocobase-ws]: connected.");
135
+ this.serverDown = false;
136
+ if (this._ws) {
137
+ this.removeAllListeners();
138
+ }
139
+ this._reconnectTimes = 0;
140
+ this._ws = ws;
141
+ for (const { type, listener, options } of this.events) {
142
+ this._ws.addEventListener(type, listener, options);
143
+ }
144
+ pingIntervalTimer = setInterval(() => this.send("ping"), this.pingInterval);
145
+ this.connected = true;
146
+ this.emit("open", {});
147
+ };
148
+ ws.onerror = async () => {
149
+ console.log("onerror", this.readyState, this._reconnectTimes);
150
+ };
151
+ ws.onclose = async (event) => {
152
+ setTimeout(() => this.connect(), this.reconnectInterval);
153
+ console.log("onclose", this.readyState, this._reconnectTimes, this.serverDown);
154
+ this.connected = false;
155
+ clearInterval(pingIntervalTimer);
156
+ };
157
+ }
158
+ reconnect() {
159
+ this._reconnectTimes = 0;
160
+ this.connect();
161
+ }
162
+ close() {
163
+ if (!this._ws) {
164
+ return;
165
+ }
166
+ this._reconnectTimes = this.reconnectAttempts;
167
+ return this._ws.close();
168
+ }
169
+ send(data) {
170
+ if (!this._ws) {
171
+ return;
172
+ }
173
+ return this._ws.send(data);
174
+ }
175
+ on(type, listener, options) {
176
+ this.events.push({ type, listener, options });
177
+ if (!this._ws) {
178
+ return;
179
+ }
180
+ this._ws.addEventListener(type, listener, options);
181
+ }
182
+ emit(type, args) {
183
+ for (const event of this.events) {
184
+ if (event.type === type) {
185
+ event.listener(args);
186
+ }
187
+ }
188
+ }
189
+ off(type, listener, options) {
190
+ let index = 0;
191
+ for (const event of this.events) {
192
+ if (event.type === type && event.listener === listener) {
193
+ this.events.splice(index, 1);
194
+ break;
195
+ }
196
+ index++;
197
+ }
198
+ if (!this._ws) {
199
+ return;
200
+ }
201
+ this._ws.removeEventListener(type, listener, options);
202
+ }
203
+ removeAllListeners() {
204
+ if (!this._ws) {
205
+ return;
206
+ }
207
+ for (const { type, listener, options } of this.events) {
208
+ this._ws.removeEventListener(type, listener, options);
209
+ }
210
+ }
211
+ };
212
+ __name(_WebSocketClient, "WebSocketClient");
213
+ let WebSocketClient = _WebSocketClient;
214
+ // Annotate the CommonJS export names for ESM import in node:
215
+ 0 && (module.exports = {
216
+ WebSocketClient
217
+ });
@@ -0,0 +1,12 @@
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 { FC, ReactNode } from 'react';
10
+ export declare const BlankComponent: FC<{
11
+ children?: ReactNode;
12
+ }>;
@@ -0,0 +1,48 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var BlankComponent_exports = {};
39
+ __export(BlankComponent_exports, {
40
+ BlankComponent: () => BlankComponent
41
+ });
42
+ module.exports = __toCommonJS(BlankComponent_exports);
43
+ var import_react = __toESM(require("react"));
44
+ const BlankComponent = /* @__PURE__ */ __name(({ children }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children), "BlankComponent");
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ BlankComponent
48
+ });
@@ -0,0 +1,10 @@
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
+ export declare const MainComponent: React.NamedExoticComponent<object>;
@@ -0,0 +1,54 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var MainComponent_exports = {};
38
+ __export(MainComponent_exports, {
39
+ MainComponent: () => MainComponent
40
+ });
41
+ module.exports = __toCommonJS(MainComponent_exports);
42
+ var import_react = __toESM(require("react"));
43
+ var import_hooks = require("../hooks");
44
+ const MainComponent = import_react.default.memo(({ children }) => {
45
+ const app = (0, import_hooks.useApp)();
46
+ const Router = (0, import_react.useMemo)(() => app.router.getRouterComponent(children), [app]);
47
+ const Providers = (0, import_react.useMemo)(() => app.getComposeProviders(), [app]);
48
+ return /* @__PURE__ */ import_react.default.createElement(Router, { BaseLayout: Providers });
49
+ });
50
+ MainComponent.displayName = "MainComponent";
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ MainComponent
54
+ });
@@ -0,0 +1,13 @@
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 { Application } from '../Application';
10
+ export declare function useRouterSync(app: Application): void;
11
+ export declare function RouterBridge({ app }: {
12
+ app: any;
13
+ }): any;
@@ -0,0 +1,66 @@
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 RouterBridge_exports = {};
29
+ __export(RouterBridge_exports, {
30
+ RouterBridge: () => RouterBridge,
31
+ useRouterSync: () => useRouterSync
32
+ });
33
+ module.exports = __toCommonJS(RouterBridge_exports);
34
+ var import_react = require("react");
35
+ var import_react_router_dom = require("react-router-dom");
36
+ function useRouterSync(app) {
37
+ const params = (0, import_react_router_dom.useParams)();
38
+ const location = (0, import_react_router_dom.useLocation)();
39
+ const matches = (0, import_react_router_dom.useMatches)();
40
+ const engine = app.flowEngine;
41
+ (0, import_react.useEffect)(() => {
42
+ var _a;
43
+ const last = matches[matches.length - 1];
44
+ if (!last) return;
45
+ engine.context["_observableCache"]["route"] = {
46
+ name: last.id,
47
+ pathname: last.pathname,
48
+ path: ((_a = last.handle) == null ? void 0 : _a["path"]) || null,
49
+ params
50
+ };
51
+ }, [engine.context, params, matches]);
52
+ (0, import_react.useEffect)(() => {
53
+ engine.context["_observableCache"]["location"] = location;
54
+ }, [engine.context, location]);
55
+ }
56
+ __name(useRouterSync, "useRouterSync");
57
+ function RouterBridge({ app }) {
58
+ useRouterSync(app);
59
+ return null;
60
+ }
61
+ __name(RouterBridge, "RouterBridge");
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ RouterBridge,
65
+ useRouterSync
66
+ });
@@ -0,0 +1,12 @@
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 { FC, ReactNode } from 'react';
10
+ export declare const RouterContextCleaner: FC<{
11
+ children?: ReactNode;
12
+ }>;