@rws-framework/client 2.0.6
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/.bin/add-v.sh +10 -0
- package/.eslintrc.json +53 -0
- package/.setup/.eslintrc.json +11 -0
- package/.setup/tsconfig.json +29 -0
- package/README.md +691 -0
- package/_rws_externals.js +40 -0
- package/_tools.js +317 -0
- package/console.js +87 -0
- package/declarations.d.ts +9 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/26e93147f10415a0ed4a.svg +6 -0
- package/docs/assets/75c9471662e97ee24f29.svg +7 -0
- package/docs/assets/db90e4df2373980c497d.svg +9 -0
- package/docs/assets/hierarchy.css +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +120 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1414 -0
- package/docs/classes/ApiServiceInstance.html +20 -0
- package/docs/classes/DOMServiceInstance.html +10 -0
- package/docs/classes/NotifyServiceInstance.html +12 -0
- package/docs/classes/RWSClient.html +11 -0
- package/docs/classes/RWSRouter.html +9 -0
- package/docs/classes/RWSService.html +7 -0
- package/docs/classes/RWSUploader.html +35 -0
- package/docs/classes/RWSViewComponent.html +24 -0
- package/docs/classes/RouterComponent.html +31 -0
- package/docs/classes/RoutingServiceInstance.html +13 -0
- package/docs/classes/UtilsServiceInstance.html +11 -0
- package/docs/classes/WSServiceInstance.html +32 -0
- package/docs/functions/RWSView.html +1 -0
- package/docs/functions/ngAttr.html +1 -0
- package/docs/functions/registerRWSComponents.html +1 -0
- package/docs/functions/renderRouteComponent.html +1 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +53 -0
- package/docs/interfaces/IRWSAssetShowOptions.html +1 -0
- package/docs/interfaces/IRWSConfig.html +11 -0
- package/docs/interfaces/IRWSDecoratorOptions.html +4 -0
- package/docs/interfaces/IRWSHttpRoute.html +3 -0
- package/docs/interfaces/IRWSPrefixedHTTProutes.html +3 -0
- package/docs/interfaces/IRoutingEvent.html +3 -0
- package/docs/modules.html +39 -0
- package/docs/types/DOMOutputType.html +1 -0
- package/docs/types/IRWSBackendRoute.html +1 -0
- package/docs/types/IRWSFrontRoutes.html +1 -0
- package/docs/types/IRWSRouteResult.html +1 -0
- package/docs/types/IRWSWebsocketStatus.html +1 -0
- package/docs/types/NotifyLogType.html +1 -0
- package/docs/types/NotifyUiType.html +1 -0
- package/docs/types/RWSNotify.html +1 -0
- package/docs/types/RouteReturn.html +1 -0
- package/docs/variables/ApiService.html +1 -0
- package/docs/variables/DOMService.html +1 -0
- package/docs/variables/NotifyService.html +1 -0
- package/docs/variables/RoutingService.html +1 -0
- package/docs/variables/UtilsService.html +1 -0
- package/docs/variables/WSService.html +1 -0
- package/docs/variables/_ROUTING_EVENT_NAME.html +1 -0
- package/package.json +93 -0
- package/package.webpack.config.js +17 -0
- package/rws.webpack.config.js +260 -0
- package/src/client.ts +304 -0
- package/src/components/_attrs/angular-attr.ts +64 -0
- package/src/components/_attrs/sanitize-html.ts +81 -0
- package/src/components/_component.ts +290 -0
- package/src/components/_container.ts +16 -0
- package/src/components/_decorator.ts +112 -0
- package/src/components/_design_system.ts +6 -0
- package/src/components/index.ts +9 -0
- package/src/components/progress/component.ts +55 -0
- package/src/components/progress/styles/layout.scss +91 -0
- package/src/components/progress/template.html +25 -0
- package/src/components/router/component.ts +67 -0
- package/src/components/uploader/component.ts +75 -0
- package/src/components/uploader/styles/layout.scss +105 -0
- package/src/components/uploader/template.html +17 -0
- package/src/hmr.ts +19 -0
- package/src/index.ts +98 -0
- package/src/interfaces/IRWSConfig.ts +24 -0
- package/src/interfaces/IRWSUser.ts +7 -0
- package/src/interfaces/IRWSViewComponent.ts +37 -0
- package/src/interfaces/RWSWindow.ts +39 -0
- package/src/routing/_router.ts +59 -0
- package/src/routing/index.ts +7 -0
- package/src/run.ts +35 -0
- package/src/service_worker/src/_service_worker.ts +88 -0
- package/src/service_worker/tsconfig.json +21 -0
- package/src/service_worker/webpack.config.js +67 -0
- package/src/services/ApiService.ts +241 -0
- package/src/services/ConfigService.ts +107 -0
- package/src/services/DOMService.ts +91 -0
- package/src/services/NotifyService.ts +49 -0
- package/src/services/RoutingService.ts +46 -0
- package/src/services/ServiceWorkerService.ts +60 -0
- package/src/services/UtilsService.ts +103 -0
- package/src/services/WSService.ts +218 -0
- package/src/services/_service.ts +50 -0
- package/src/services/_ws_handlers/ConnectionHandler.ts +52 -0
- package/src/services/_ws_handlers/EventHandler.ts +28 -0
- package/src/services/_ws_handlers/MessageHandler.ts +49 -0
- package/src/styles/includes.scss +102 -0
- package/src/types/RWSNotify.ts +7 -0
- package/tsconfig.json +27 -0
- package/typedoc.json +13 -0
- package/webpack/after/copy.js +73 -0
- package/webpack/after/sw.js +14 -0
- package/webpack/index.js +11 -0
- package/webpack/rws_after_plugin.js +80 -0
- package/webpack/rws_fast_css_loader.js +16 -0
- package/webpack/rws_fast_html_loader.js +4 -0
- package/webpack/rws_fast_scss_loader.js +50 -0
- package/webpack/rws_fast_ts_loader.js +134 -0
- package/webpack/rws_plugin.js +337 -0
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rws-framework/client",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "2.0.6",
|
|
5
|
+
"description": "client for RWS frontend",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"docs": "typedoc --tsconfig ./tsconfig.json"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"rws-client": "./console.js"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/papablack/rws-client.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"frontend",
|
|
19
|
+
"rws",
|
|
20
|
+
"client",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"author": "papablack",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/papablack/rws-client/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/papablack/rws-client#readme",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@microsoft/fast-foundation": "^2.46.2",
|
|
31
|
+
"@microsoft/fast-element": "^1.12.0",
|
|
32
|
+
"@types/moment": "^2.13.0",
|
|
33
|
+
"dragula": "^3.7.3",
|
|
34
|
+
"moment": "^2.29.4",
|
|
35
|
+
"he": "^1.2.0",
|
|
36
|
+
"partial-json-parser": "^1.0.0",
|
|
37
|
+
"reflect-metadata": "^0.1.13",
|
|
38
|
+
"resolve-url-loader": "^5.0.0",
|
|
39
|
+
"sass": "^1.69.7",
|
|
40
|
+
"socket.io-client": "^4.7.2",
|
|
41
|
+
"ts-loader": "^9.4.4",
|
|
42
|
+
"tsc-watch": "^6.0.4",
|
|
43
|
+
"tslib": "^2.6.2",
|
|
44
|
+
"json5": "^2.2.3",
|
|
45
|
+
"upload": "^1.3.2",
|
|
46
|
+
"url-router": "^13.0.0",
|
|
47
|
+
"uuid": "^9.0.1",
|
|
48
|
+
"v4": "^0.0.1",
|
|
49
|
+
"sanitize-html": "^2.12.1"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@open-wc/dev-server-hmr": "^0.1.2-next.0",
|
|
53
|
+
"@types/sanitize-html": "^2.11.0",
|
|
54
|
+
"@types/dragula": "^3.7.4",
|
|
55
|
+
"@types/express-fileupload": "^1.4.4",
|
|
56
|
+
"@types/socket.io-client": "^3.0.0",
|
|
57
|
+
"@types/uuid": "^9.0.7",
|
|
58
|
+
"@types/he": "^1.2.3",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
|
60
|
+
"@typescript-eslint/parser": "^7.0.1",
|
|
61
|
+
"@types/json5": "^2.2.0",
|
|
62
|
+
"css-loader": "^6.8.1",
|
|
63
|
+
"css-minimizer-webpack-plugin": "^5.0.1",
|
|
64
|
+
"dts-bundle": "^0.7.3",
|
|
65
|
+
"eslint": "^8.56.0",
|
|
66
|
+
"eslint-plugin-unused-imports": "^3.1.0",
|
|
67
|
+
"file-loader": "^6.2.0",
|
|
68
|
+
"html-webpack-plugin": "^5.5.3",
|
|
69
|
+
"loader-utils": "^3.2.1",
|
|
70
|
+
"mini-css-extract-plugin": "^2.7.6",
|
|
71
|
+
"node-sass": "^9.0.0",
|
|
72
|
+
"sass-loader": "^13.3.2",
|
|
73
|
+
"source-map": "^0.7.4",
|
|
74
|
+
"style-loader": "^3.3.3",
|
|
75
|
+
"terser-webpack-plugin": "^5.3.9",
|
|
76
|
+
"ts-node": "^10.9.1",
|
|
77
|
+
"tsconfig-paths": "^4.2.0",
|
|
78
|
+
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
|
79
|
+
"typedoc": "^0.25.4",
|
|
80
|
+
"typedoc-plugin-mermaid": "^1.10.0",
|
|
81
|
+
"typedoc-plugin-not-exported": "^0.1.6",
|
|
82
|
+
"typedoc-plugin-rename-defaults": "^0.7.0",
|
|
83
|
+
"typedoc-theme-hierarchy": "^4.1.2",
|
|
84
|
+
"typescript": "^5.1.6",
|
|
85
|
+
"url-loader": "^4.1.1",
|
|
86
|
+
"webpack": "^5.75.0",
|
|
87
|
+
"webpack-bundle-analyzer": "^4.10.1",
|
|
88
|
+
"webpack-cli": "^5.1.4",
|
|
89
|
+
"webpack-dev-server": "^4.15.1",
|
|
90
|
+
"webpack-node-externals": "^3.0.0",
|
|
91
|
+
"ts-loader": "^9.4.4"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
4
|
+
const RWSWebpackWrapper = require('./rws.webpack.config');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const executionDir = process.cwd();
|
|
8
|
+
|
|
9
|
+
module.exports = RWSWebpackWrapper({
|
|
10
|
+
dev: true,
|
|
11
|
+
hot: false,
|
|
12
|
+
entry: `./src/index.ts`,
|
|
13
|
+
tsConfigPath: './tsconfig.json',
|
|
14
|
+
executionDir: __dirname,
|
|
15
|
+
outputDir: path.resolve(__dirname, 'build'),
|
|
16
|
+
outputFileName: 'rws.client.js'
|
|
17
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const webpack = require('webpack');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
5
|
+
const JsMinimizerPlugin = require('terser-webpack-plugin');
|
|
6
|
+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
|
7
|
+
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
8
|
+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
9
|
+
const RWSAfterPlugin = require('./webpack/rws_after_plugin');
|
|
10
|
+
const { Console } = require('console');
|
|
11
|
+
const { Interface } = require('readline');
|
|
12
|
+
const ts = require('typescript');
|
|
13
|
+
const tools = require('./_tools');
|
|
14
|
+
|
|
15
|
+
let WEBPACK_PLUGINS = [];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The RWS webpack configurator.
|
|
19
|
+
*
|
|
20
|
+
* Example usage in importing file:
|
|
21
|
+
*
|
|
22
|
+
* RWSWebpackWrapper({
|
|
23
|
+
dev: true,
|
|
24
|
+
hot: false,
|
|
25
|
+
tsConfigPath: executionDir + '/tsconfig.json',
|
|
26
|
+
entry: `${executionDir}/src/index.ts`,
|
|
27
|
+
executionDir: executionDir,
|
|
28
|
+
publicDir: path.resolve(executionDir, 'public'),
|
|
29
|
+
outputDir: path.resolve(executionDir, 'build'),
|
|
30
|
+
outputFileName: 'jtrainer.client.js',
|
|
31
|
+
copyToDir: {
|
|
32
|
+
'../public/js/' : [
|
|
33
|
+
'./build/jtrainer.client.js',
|
|
34
|
+
'./build/jtrainer.client.js.map',
|
|
35
|
+
'./src/styles/compiled/main.css'
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
plugins: [
|
|
39
|
+
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
*/
|
|
43
|
+
const RWSWebpackWrapper = (config) => {
|
|
44
|
+
const executionDir = config.executionDir || process.cwd();
|
|
45
|
+
|
|
46
|
+
const isDev = config.dev;
|
|
47
|
+
const isHotReload = config.hot;
|
|
48
|
+
const isReport = config.report;
|
|
49
|
+
|
|
50
|
+
const publicDir = config.publicDir || null;
|
|
51
|
+
const serviceWorkerPath = config.serviceWorker || null;
|
|
52
|
+
|
|
53
|
+
const WEBPACK_AFTER_ACTIONS = config.actions || [];
|
|
54
|
+
|
|
55
|
+
const publicIndex = config.publicIndex || 'index.html';
|
|
56
|
+
|
|
57
|
+
const aliases = config.aliases = {};
|
|
58
|
+
|
|
59
|
+
aliases.fs = false;
|
|
60
|
+
|
|
61
|
+
const modules_setup = [path.resolve(__dirname, 'node_modules'), 'node_modules'];
|
|
62
|
+
|
|
63
|
+
const overridePlugins = config.plugins || []
|
|
64
|
+
|
|
65
|
+
if (isHotReload) {
|
|
66
|
+
if (!publicDir) {
|
|
67
|
+
throw new Error('No public dir set')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
WEBPACK_PLUGINS.push(new HtmlWebpackPlugin({
|
|
71
|
+
template: publicDir + '/' + publicIndex,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
WEBPACK_PLUGINS = [...WEBPACK_PLUGINS, new webpack.optimize.ModuleConcatenationPlugin(), ...overridePlugins];
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if (isDev && isReport) {
|
|
79
|
+
WEBPACK_PLUGINS.push(new BundleAnalyzerPlugin({
|
|
80
|
+
analyzerMode: 'static',
|
|
81
|
+
openAnalyzer: false,
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if(serviceWorkerPath){
|
|
86
|
+
WEBPACK_AFTER_ACTIONS.push({
|
|
87
|
+
type: 'service_worker',
|
|
88
|
+
actionHandler: serviceWorkerPath
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if(!!config.copyToDir){
|
|
93
|
+
WEBPACK_AFTER_ACTIONS.push({
|
|
94
|
+
type: 'copy',
|
|
95
|
+
actionHandler: config.copyToDir
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (WEBPACK_AFTER_ACTIONS.length) {
|
|
100
|
+
WEBPACK_PLUGINS.push(new RWSAfterPlugin({ actions: WEBPACK_AFTER_ACTIONS }));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const splitInfoJson = config.outputDir + '/rws_chunks_info.json'
|
|
104
|
+
const automatedEntries = {};
|
|
105
|
+
|
|
106
|
+
const foundRWSUserClasses = tools.findComponentFilesWithText(executionDir, '@RWSView', ['dist', 'node_modules', 'rws-js-client']);
|
|
107
|
+
const foundRWSClientClasses = tools.findComponentFilesWithText(__dirname, '@RWSView', ['dist', 'node_modules']);
|
|
108
|
+
let RWSComponents = [...foundRWSUserClasses, ...foundRWSClientClasses];
|
|
109
|
+
|
|
110
|
+
const servicePath = path.resolve(__dirname, 'src', 'services', '_service.ts');
|
|
111
|
+
|
|
112
|
+
const servicesLocations = [
|
|
113
|
+
path.resolve(__dirname, 'src', 'services'),
|
|
114
|
+
path.resolve(executionDir, 'src', 'services')
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
if (config.customServiceLocations) {
|
|
118
|
+
config.customServiceLocations.forEach((serviceDir) => {
|
|
119
|
+
servicesLocations.push(serviceDir);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const optimConfig = {
|
|
124
|
+
minimizer: [
|
|
125
|
+
new JsMinimizerPlugin(),
|
|
126
|
+
new CssMinimizerPlugin()
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
if (config.parted) {
|
|
131
|
+
if (config.partedComponentsLocations) {
|
|
132
|
+
config.partedComponentsLocations.forEach((componentDir) => {
|
|
133
|
+
RWSComponents = [...RWSComponents, ...(tools.findComponentFilesWithText(path.resolve(componentDir), '@RWSView', ['dist', 'node_modules', 'rws-js-client']))];
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
RWSComponents.forEach((fileInfo) => {
|
|
138
|
+
const isIgnored = fileInfo.isIgnored;
|
|
139
|
+
|
|
140
|
+
if(isIgnored === true){
|
|
141
|
+
// console.warn('Ignored: '+ fileInfo.filePath);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
automatedEntries[fileInfo.sanitName] = fileInfo.filePath;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
fs.writeFileSync(splitInfoJson, JSON.stringify(Object.keys(automatedEntries), null, 2));
|
|
149
|
+
optimConfig.splitChunks = {
|
|
150
|
+
cacheGroups: {
|
|
151
|
+
vendor: {
|
|
152
|
+
test: (module) => {
|
|
153
|
+
let importString = module.identifier();
|
|
154
|
+
|
|
155
|
+
if(importString.split('!').length > 2){
|
|
156
|
+
importString = importString.split('!')[2];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const inNodeModules = importString.indexOf('node_modules') > -1;
|
|
160
|
+
const inVendorPackage = importString.indexOf(__dirname) > -1;
|
|
161
|
+
|
|
162
|
+
const inExecDir = importString.indexOf(executionDir) > -1;
|
|
163
|
+
const isNoPartedComponent = !Object.keys(automatedEntries).find(key => importString.indexOf(path.resolve(path.dirname(automatedEntries[key]))) > -1);
|
|
164
|
+
|
|
165
|
+
let isAvailableForVendors = (inNodeModules || inVendorPackage) && isNoPartedComponent;
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
return isAvailableForVendors;
|
|
169
|
+
},
|
|
170
|
+
name: 'vendors',
|
|
171
|
+
chunks: 'all',
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}else{
|
|
176
|
+
if(fs.existsSync(splitInfoJson)){
|
|
177
|
+
fs.unlinkSync(splitInfoJson);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const cfgExport = {
|
|
182
|
+
entry: {
|
|
183
|
+
client: config.entry,
|
|
184
|
+
...automatedEntries
|
|
185
|
+
},
|
|
186
|
+
mode: isDev ? 'development' : 'production',
|
|
187
|
+
target: 'web',
|
|
188
|
+
devtool: config.devtool || 'inline-source-map',
|
|
189
|
+
output: {
|
|
190
|
+
path: config.outputDir,
|
|
191
|
+
filename: config.parted ? (config.partedPrefix || 'rws') + '.[name].js' : config.outputFileName,
|
|
192
|
+
sourceMapFilename: '[file].map',
|
|
193
|
+
},
|
|
194
|
+
resolve: {
|
|
195
|
+
extensions: ['.ts', '.js'],
|
|
196
|
+
modules: modules_setup,
|
|
197
|
+
alias: {
|
|
198
|
+
...aliases
|
|
199
|
+
},
|
|
200
|
+
plugins: [
|
|
201
|
+
// new TsconfigPathsPlugin({configFile: config.tsConfigPath})
|
|
202
|
+
]
|
|
203
|
+
},
|
|
204
|
+
module: {
|
|
205
|
+
rules: [
|
|
206
|
+
{
|
|
207
|
+
test: /\.html$/,
|
|
208
|
+
use: [
|
|
209
|
+
path.resolve(__dirname, './webpack/rws_fast_html_loader.js')
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
test: /\.css$/,
|
|
214
|
+
use: [
|
|
215
|
+
'css-loader',
|
|
216
|
+
// path.resolve(__dirname, './webpack/rws_fast_css_loader.js')
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
test: /\.scss$/,
|
|
221
|
+
use: [
|
|
222
|
+
// 'css-loader',
|
|
223
|
+
path.resolve(__dirname, './webpack/rws_fast_scss_loader.js'),
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
test: /\.(ts)$/,
|
|
228
|
+
use: [
|
|
229
|
+
{
|
|
230
|
+
loader: 'ts-loader',
|
|
231
|
+
options: {
|
|
232
|
+
allowTsInNodeModules: true,
|
|
233
|
+
configFile: path.resolve(config.tsConfigPath)
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
loader: path.resolve(__dirname, './webpack/rws_fast_ts_loader.js'),
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
exclude: /node_modules\/(?!rws-js-client)/,
|
|
241
|
+
}
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
plugins: WEBPACK_PLUGINS,
|
|
245
|
+
optimization: optimConfig,
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (isHotReload) {
|
|
249
|
+
cfgExport.devServer = {
|
|
250
|
+
hot: true,
|
|
251
|
+
static: publicDir
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return cfgExport;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
module.exports = RWSWebpackWrapper;
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import IRWSConfig from './interfaces/IRWSConfig';
|
|
2
|
+
import startClient from './run';
|
|
3
|
+
import RWSNotify from './types/RWSNotify';
|
|
4
|
+
|
|
5
|
+
import ConfigService, { ConfigServiceInstance } from './services/ConfigService';
|
|
6
|
+
import UtilsService, { UtilsServiceInstance } from './services/UtilsService';
|
|
7
|
+
import DOMService, { DOMServiceInstance, DOMOutputType } from './services/DOMService';
|
|
8
|
+
import ApiService, { ApiServiceInstance } from './services/ApiService';
|
|
9
|
+
import NotifyService, { NotifyServiceInstance } from './services/NotifyService';
|
|
10
|
+
import RoutingService, { RoutingServiceInstance } from './services/RoutingService';
|
|
11
|
+
import WSService, { WSServiceInstance } from './services/WSService';
|
|
12
|
+
import ServiceWorkerService, { ServiceWorkerServiceInstance } from './services/ServiceWorkerService';
|
|
13
|
+
import { IBackendRoute } from './services/ApiService';
|
|
14
|
+
import IRWSUser from './interfaces/IRWSUser';
|
|
15
|
+
import RWSWindow, { RWSWindowComponentEntry, RWSWindowComponentRegister, loadRWSRichWindow } from './interfaces/RWSWindow';
|
|
16
|
+
|
|
17
|
+
import { DI, Container } from "@microsoft/fast-foundation";
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
IFrontRoutes, _ROUTING_EVENT_NAME
|
|
21
|
+
} from './services/RoutingService';
|
|
22
|
+
|
|
23
|
+
import RWSViewComponent, { IWithCompose } from './components/_component';
|
|
24
|
+
import { provideRWSDesignSystem } from './components/_design_system';
|
|
25
|
+
import RWSContainer from './components/_container';
|
|
26
|
+
|
|
27
|
+
interface IHotModule extends NodeModule {
|
|
28
|
+
hot?: {
|
|
29
|
+
accept(dependencies: string[], callback?: (updatedDependencies: string[]) => void): void;
|
|
30
|
+
accept(dependency: string, callback?: () => void): void;
|
|
31
|
+
accept(errHandler?: (err: Error) => void): void;
|
|
32
|
+
dispose(callback: (data: any) => void): void;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
type RWSEventListener = (event: CustomEvent) => void;
|
|
38
|
+
|
|
39
|
+
class RWSClient {
|
|
40
|
+
private _container: Container;
|
|
41
|
+
private user: IRWSUser = null;
|
|
42
|
+
|
|
43
|
+
private config: IRWSConfig = { backendUrl: '', routes: {}, splitFileDir: '/', splitPrefix: 'rws' };
|
|
44
|
+
protected initCallback: () => Promise<void> = async () => { };
|
|
45
|
+
|
|
46
|
+
private isSetup = false;
|
|
47
|
+
protected devStorage: { [key: string]: any } = {};
|
|
48
|
+
|
|
49
|
+
private cfgSetupListener: RWSEventListener = (event: CustomEvent<{ callId: string }>) => {
|
|
50
|
+
console.log('Received custom event from web component:', event.detail);
|
|
51
|
+
// this.broadcastConfigForViewComponents();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
@ConfigService public appConfig: ConfigServiceInstance,
|
|
56
|
+
@RoutingService public routingService: RoutingServiceInstance,
|
|
57
|
+
@DOMService public domService: DOMServiceInstance,
|
|
58
|
+
@UtilsService public utilsService: UtilsServiceInstance,
|
|
59
|
+
@ApiService public apiService: ApiServiceInstance,
|
|
60
|
+
@WSService public wsService: WSServiceInstance,
|
|
61
|
+
@ServiceWorkerService public swService: ServiceWorkerServiceInstance,
|
|
62
|
+
@NotifyService public notifyService: NotifyServiceInstance
|
|
63
|
+
) {
|
|
64
|
+
this._container = RWSContainer();
|
|
65
|
+
this.user = this.getUser();
|
|
66
|
+
|
|
67
|
+
this.pushDataToServiceWorker('SET_WS_URL', { url: this.appConfig.get('wsUrl') }, 'ws_url');
|
|
68
|
+
|
|
69
|
+
if (this.user) {
|
|
70
|
+
this.pushUserToServiceWorker({ ...this.user, instructor: false });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async setup(config: IRWSConfig = {}): Promise<IRWSConfig> {
|
|
75
|
+
if (this.isSetup) {
|
|
76
|
+
return this.config;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.config = { ...this.config, ...config };
|
|
80
|
+
this.appConfig.mergeConfig(this.config);
|
|
81
|
+
|
|
82
|
+
// this.on<IRWSConfig>('rws_cfg_call', this.cfgSetupListener);
|
|
83
|
+
|
|
84
|
+
const hotModule: IHotModule = (module as IHotModule);
|
|
85
|
+
|
|
86
|
+
if (hotModule.hot) {
|
|
87
|
+
hotModule.hot.accept('./print.js', function () {
|
|
88
|
+
console.log('Accepting the updated module!');
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (this.appConfig.get('parted')) {
|
|
93
|
+
await this.loadPartedComponents();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
this.isSetup = true;
|
|
98
|
+
return this.config;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async start(config: IRWSConfig = {}): Promise<RWSClient> {
|
|
102
|
+
this.config = { ...this.config, ...config };
|
|
103
|
+
|
|
104
|
+
if (!this.isSetup) {
|
|
105
|
+
this.config = await this.setup(this.config);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (Object.keys(config).length) {
|
|
109
|
+
this.appConfig.mergeConfig(this.config);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
console.log(this.isSetup, this.config, this.appConfig);
|
|
113
|
+
|
|
114
|
+
if (this.config.user && !this.config.dontPushToSW) {
|
|
115
|
+
this.pushUserToServiceWorker(this.user);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
await startClient(this.appConfig, this.wsService, this.notifyService, this.routingService);
|
|
119
|
+
|
|
120
|
+
await this.initCallback();
|
|
121
|
+
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
addRoutes(routes: IFrontRoutes) {
|
|
126
|
+
this.config.routes = routes;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
setNotifier(notifier: RWSNotify): RWSClient {
|
|
130
|
+
this.notifyService.setNotifier(notifier);
|
|
131
|
+
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
setDefaultLayout(DefaultLayout: any): RWSClient {
|
|
136
|
+
this.config.defaultLayout = DefaultLayout;
|
|
137
|
+
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
setBackendRoutes(routes: IBackendRoute[]): RWSClient {
|
|
142
|
+
this.config.backendRoutes = routes;
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async onInit(callback: () => Promise<void>): Promise<RWSClient> {
|
|
147
|
+
this.initCallback = callback;
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
pushDataToServiceWorker(type: string, data: any, asset_type: string = 'data_push'): void {
|
|
152
|
+
let tries = 0;
|
|
153
|
+
|
|
154
|
+
const doIt: () => void = () => {
|
|
155
|
+
try {
|
|
156
|
+
this.swService.sendDataToServiceWorker(type, data, asset_type);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
if (tries < 3) {
|
|
159
|
+
setTimeout(() => { doIt(); }, 300)
|
|
160
|
+
tries++;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
doIt();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
pushUserToServiceWorker(userData: any) {
|
|
169
|
+
this.setUser(userData);
|
|
170
|
+
this.pushDataToServiceWorker('SET_USER', userData, 'logged_user');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
getUser(): IRWSUser {
|
|
174
|
+
|
|
175
|
+
const localSaved = localStorage.getItem('the_rws_user');
|
|
176
|
+
|
|
177
|
+
if (!!localSaved) {
|
|
178
|
+
this.setUser(JSON.parse(localSaved) as IRWSUser);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return this.user;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
setUser(user: IRWSUser): RWSClient {
|
|
185
|
+
if (!user || !user?.jwt_token) {
|
|
186
|
+
console.warn('[RWS Client Warning]', 'Passed user is not valid', user);
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
this.user = user;
|
|
191
|
+
|
|
192
|
+
this.apiService.setToken(this.user.jwt_token);
|
|
193
|
+
this.wsService.setUser(this.user);
|
|
194
|
+
|
|
195
|
+
localStorage.setItem('the_rws_user', JSON.stringify(this.user));
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
getConfig(): ConfigServiceInstance {
|
|
202
|
+
return this.appConfig;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
on<T>(eventName: string, listener: RWSEventListener): void {
|
|
206
|
+
document.addEventListener(eventName, (event: Event) => {
|
|
207
|
+
listener(event as CustomEvent<T>);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
setDevStorage(key: string, stuff: any): RWSClient {
|
|
212
|
+
this.devStorage[key] = stuff;
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
getDevStorage(key: string): any {
|
|
217
|
+
return this.devStorage[key];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
registerToDI(): void {
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async loadPartedComponents(): Promise<void> {
|
|
225
|
+
this.assignClientToBrowser();
|
|
226
|
+
|
|
227
|
+
const componentParts: string[] = await this.apiService.get<string[]>(this.appConfig.get('splitFileDir') + '/rws_chunks_info.json');
|
|
228
|
+
|
|
229
|
+
const _all: Promise<string>[] = [];
|
|
230
|
+
componentParts.forEach((componentName: string) => {
|
|
231
|
+
|
|
232
|
+
const scriptUrl: string = this.appConfig.get('splitFileDir') + `/${this.appConfig.get('splitPrefix')}.${componentName}.js`; // Replace with the path to your script file
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
const headers: any = {};
|
|
237
|
+
|
|
238
|
+
headers['Content-Type'] = 'application/javascript';
|
|
239
|
+
|
|
240
|
+
_all.push(this.apiService.pureGet(scriptUrl, {
|
|
241
|
+
headers
|
|
242
|
+
}));
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
(await Promise.all(_all)).forEach((scriptCnt: string, key: number) => {
|
|
246
|
+
const script: HTMLScriptElement = document.createElement('script');
|
|
247
|
+
script.textContent = scriptCnt;
|
|
248
|
+
script.async = true
|
|
249
|
+
script.type = 'text/javascript';
|
|
250
|
+
document.body.appendChild(script);
|
|
251
|
+
|
|
252
|
+
console.log(`Appended ${componentParts[key]} component`);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
RWSClient.defineAllComponents();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async onDOMLoad(): Promise<void> {
|
|
259
|
+
return new Promise<void>((resolve) => {
|
|
260
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
261
|
+
resolve();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
assignClientToBrowser(): void {
|
|
267
|
+
this.getBrowserObject().RWS.client = this;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
enableRouting(): void {
|
|
271
|
+
this.appConfig.mergeConfig({ routing_enabled: true });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
disableRouting(): void {
|
|
275
|
+
this.appConfig.mergeConfig({ routing_enabled: false });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private getBrowserObject(): RWSWindow {
|
|
279
|
+
loadRWSRichWindow();
|
|
280
|
+
return window;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
private broadcastConfigForViewComponents(): void {
|
|
285
|
+
document.dispatchEvent(new CustomEvent<{ config: IRWSConfig }>('rws_cfg_broadcast', { detail: { config: this.appConfig.getData() } }));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
static getDI(): typeof DI {
|
|
289
|
+
return DI;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
static defineAllComponents() {
|
|
293
|
+
const richWindowComponents: RWSWindowComponentRegister = (window as Window & RWSWindow).RWS.components;
|
|
294
|
+
// provideRWSDesignSystem().register(richWindowComponents[devStr].component);
|
|
295
|
+
|
|
296
|
+
console.log(richWindowComponents);
|
|
297
|
+
Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
|
|
298
|
+
el.define(el, el.definition);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export default DI.createInterface<RWSClient>(x => x.singleton(RWSClient));
|
|
304
|
+
export { IHotModule, RWSClient as RWSClientInstance }
|