@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.
- package/LICENSE.txt +172 -0
- package/lib/Application.d.ts +124 -0
- package/lib/Application.js +489 -0
- package/lib/MockApplication.d.ts +16 -0
- package/lib/MockApplication.js +96 -0
- package/lib/Plugin.d.ts +33 -0
- package/lib/Plugin.js +89 -0
- package/lib/PluginManager.d.ts +46 -0
- package/lib/PluginManager.js +114 -0
- package/lib/PluginSettingsManager.d.ts +67 -0
- package/lib/PluginSettingsManager.js +148 -0
- package/lib/RouterManager.d.ts +61 -0
- package/lib/RouterManager.js +198 -0
- package/lib/WebSocketClient.d.ts +45 -0
- package/lib/WebSocketClient.js +217 -0
- package/lib/components/BlankComponent.d.ts +12 -0
- package/lib/components/BlankComponent.js +48 -0
- package/lib/components/MainComponent.d.ts +10 -0
- package/lib/components/MainComponent.js +54 -0
- package/lib/components/RouterBridge.d.ts +13 -0
- package/lib/components/RouterBridge.js +66 -0
- package/lib/components/RouterContextCleaner.d.ts +12 -0
- package/lib/components/RouterContextCleaner.js +61 -0
- package/lib/components/index.d.ts +10 -0
- package/lib/components/index.js +32 -0
- package/lib/context.d.ts +11 -0
- package/lib/context.js +38 -0
- package/lib/hooks/index.d.ts +11 -0
- package/lib/hooks/index.js +34 -0
- package/lib/hooks/useApp.d.ts +10 -0
- package/lib/hooks/useApp.js +41 -0
- package/lib/hooks/usePlugin.d.ts +11 -0
- package/lib/hooks/usePlugin.js +42 -0
- package/lib/hooks/useRouter.d.ts +9 -0
- package/lib/hooks/useRouter.js +41 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +40 -0
- package/lib/utils/index.d.ts +11 -0
- package/lib/utils/index.js +79 -0
- package/lib/utils/remotePlugins.d.ts +44 -0
- package/lib/utils/remotePlugins.js +131 -0
- package/lib/utils/requirejs.d.ts +18 -0
- package/lib/utils/requirejs.js +1361 -0
- package/lib/utils/types.d.ts +330 -0
- package/lib/utils/types.js +28 -0
- package/package.json +16 -0
- package/src/Application.tsx +539 -0
- package/src/MockApplication.tsx +53 -0
- package/src/Plugin.ts +78 -0
- package/src/PluginManager.ts +114 -0
- package/src/PluginSettingsManager.ts +182 -0
- package/src/RouterManager.tsx +239 -0
- package/src/WebSocketClient.ts +220 -0
- package/src/__tests__/app.test.tsx +141 -0
- package/src/components/BlankComponent.tsx +12 -0
- package/src/components/MainComponent.tsx +20 -0
- package/src/components/RouterBridge.tsx +38 -0
- package/src/components/RouterContextCleaner.tsx +26 -0
- package/src/components/index.ts +11 -0
- package/src/context.ts +14 -0
- package/src/hooks/index.ts +12 -0
- package/src/hooks/useApp.ts +16 -0
- package/src/hooks/usePlugin.ts +17 -0
- package/src/hooks/useRouter.ts +15 -0
- package/src/index.ts +15 -0
- package/src/utils/index.tsx +48 -0
- package/src/utils/remotePlugins.ts +140 -0
- package/src/utils/requirejs.ts +2164 -0
- package/src/utils/types.ts +375 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,131 @@
|
|
|
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 remotePlugins_exports = {};
|
|
29
|
+
__export(remotePlugins_exports, {
|
|
30
|
+
configRequirejs: () => configRequirejs,
|
|
31
|
+
defineDevPlugins: () => defineDevPlugins,
|
|
32
|
+
definePluginClient: () => definePluginClient,
|
|
33
|
+
getPlugins: () => getPlugins,
|
|
34
|
+
getRemotePlugins: () => getRemotePlugins,
|
|
35
|
+
processRemotePlugins: () => processRemotePlugins
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(remotePlugins_exports);
|
|
38
|
+
function defineDevPlugins(plugins) {
|
|
39
|
+
Object.entries(plugins).forEach(([packageName, plugin]) => {
|
|
40
|
+
window.define(`${packageName}/client`, () => plugin);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
__name(defineDevPlugins, "defineDevPlugins");
|
|
44
|
+
function definePluginClient(packageName) {
|
|
45
|
+
window.define(`${packageName}/client`, ["exports", packageName], function(_exports, _pluginExports) {
|
|
46
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
47
|
+
value: true
|
|
48
|
+
});
|
|
49
|
+
Object.keys(_pluginExports).forEach(function(key) {
|
|
50
|
+
if (key === "__esModule") return;
|
|
51
|
+
if (key in _exports && _exports[key] === _pluginExports[key]) return;
|
|
52
|
+
Object.defineProperty(_exports, key, {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: /* @__PURE__ */ __name(function() {
|
|
55
|
+
return _pluginExports[key];
|
|
56
|
+
}, "get")
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
__name(definePluginClient, "definePluginClient");
|
|
62
|
+
function configRequirejs(requirejs, pluginData) {
|
|
63
|
+
requirejs.requirejs.config({
|
|
64
|
+
waitSeconds: 120,
|
|
65
|
+
paths: pluginData.reduce((acc, cur) => {
|
|
66
|
+
acc[cur.packageName] = cur.url;
|
|
67
|
+
return acc;
|
|
68
|
+
}, {})
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
__name(configRequirejs, "configRequirejs");
|
|
72
|
+
function processRemotePlugins(pluginData, resolve) {
|
|
73
|
+
return (...pluginModules) => {
|
|
74
|
+
const res = pluginModules.map((item, index) => [pluginData[index].name, (item == null ? void 0 : item.default) || item]).filter((item) => item[1]);
|
|
75
|
+
resolve(res);
|
|
76
|
+
const emptyPlugins = pluginModules.map((item, index) => !item ? index : null).filter((i) => i !== null).map((i) => pluginData[i].packageName);
|
|
77
|
+
if (emptyPlugins.length > 0) {
|
|
78
|
+
console.error(
|
|
79
|
+
"[nocobase load plugin error]: These plugins do not have an `export.default` exported content or there is an error in the plugins. error plugins: \r\n%s",
|
|
80
|
+
emptyPlugins.join(", \r\n")
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
__name(processRemotePlugins, "processRemotePlugins");
|
|
86
|
+
function getRemotePlugins(requirejs, pluginData = []) {
|
|
87
|
+
configRequirejs(requirejs, pluginData);
|
|
88
|
+
const packageNames = pluginData.map((item) => item.packageName);
|
|
89
|
+
packageNames.forEach((packageName) => {
|
|
90
|
+
definePluginClient(packageName);
|
|
91
|
+
});
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
requirejs.requirejs(packageNames, processRemotePlugins(pluginData, resolve), reject);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
__name(getRemotePlugins, "getRemotePlugins");
|
|
97
|
+
async function getPlugins(options) {
|
|
98
|
+
const { requirejs, pluginData, devDynamicImport } = options;
|
|
99
|
+
if (pluginData.length === 0) return [];
|
|
100
|
+
const res = [];
|
|
101
|
+
const resolveDevPlugins = {};
|
|
102
|
+
if (devDynamicImport) {
|
|
103
|
+
for await (const plugin of pluginData) {
|
|
104
|
+
const pluginModule = await devDynamicImport(plugin.packageName);
|
|
105
|
+
if (pluginModule) {
|
|
106
|
+
res.push([plugin.name, pluginModule.default]);
|
|
107
|
+
resolveDevPlugins[plugin.packageName] = pluginModule.default;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
defineDevPlugins(resolveDevPlugins);
|
|
111
|
+
}
|
|
112
|
+
const remotePlugins = pluginData.filter((item) => !resolveDevPlugins[item.packageName]);
|
|
113
|
+
if (remotePlugins.length === 0) {
|
|
114
|
+
return res;
|
|
115
|
+
}
|
|
116
|
+
if (res.length === 0) {
|
|
117
|
+
const remotePluginList = await getRemotePlugins(requirejs, remotePlugins);
|
|
118
|
+
res.push(...remotePluginList);
|
|
119
|
+
}
|
|
120
|
+
return res;
|
|
121
|
+
}
|
|
122
|
+
__name(getPlugins, "getPlugins");
|
|
123
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
124
|
+
0 && (module.exports = {
|
|
125
|
+
configRequirejs,
|
|
126
|
+
defineDevPlugins,
|
|
127
|
+
definePluginClient,
|
|
128
|
+
getPlugins,
|
|
129
|
+
getRemotePlugins,
|
|
130
|
+
processRemotePlugins
|
|
131
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { Require, RequireDefine } from './types';
|
|
10
|
+
export interface RequireJS {
|
|
11
|
+
require: Require;
|
|
12
|
+
requirejs: Require;
|
|
13
|
+
define: RequireDefine;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare function getRequireJs(): RequireJS;
|