@rws-framework/client 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,11 +2,13 @@ declare const _DEFAULT_CONFIG: any;
2
2
 
3
3
  declare function readConfigFile(filePath: string): any;
4
4
  declare function get(key: string): any;
5
- declare function exportConfig(): any;
5
+ declare function exportDefaultConfig(): any;
6
+ declare function exportBuildConfig(): any;
6
7
 
7
8
  export {
8
9
  readConfigFile,
9
10
  get,
10
- exportConfig,
11
+ exportDefaultConfig,
12
+ exportBuildConfig,
11
13
  _DEFAULT_CONFIG
12
14
  };
@@ -12,8 +12,7 @@ function readConfigFile(filePath){
12
12
 
13
13
  const fileConfig = json5.parse(fs.readFileSync(filePath, 'utf-8'));
14
14
 
15
- return {
16
- ..._DEFAULT_CONFIG,
15
+ return {
17
16
  ...fileConfig
18
17
  }
19
18
  }
@@ -24,7 +23,11 @@ function get(key){
24
23
  return STORAGE.get(key);
25
24
  }
26
25
 
27
- function exportConfig(){
26
+ function exportDefaultConfig(){
27
+ return _DEFAULT_CONFIG;
28
+ }
29
+
30
+ function exportBuildConfig(){
28
31
  _init();
29
32
 
30
33
  return STORAGE.getAll();
@@ -38,7 +41,8 @@ function _init(){
38
41
 
39
42
  module.exports = {
40
43
  readConfigFile,
41
- exportConfig,
44
+ exportDefaultConfig,
45
+ exportBuildConfig,
42
46
  get,
43
47
  _DEFAULT_CONFIG
44
48
  };
@@ -6,7 +6,7 @@ const _DEFAULT_CONFIG_VARS = {
6
6
  publicDir: './public',
7
7
  publicIndex: 'index.html',
8
8
  outputFileName: 'client.rws.js',
9
- outputDir: './build',
9
+ outputDir: process.cwd() + '/build',
10
10
  //Frontend RWS client configs
11
11
  backendUrl: null,
12
12
  wsUrl: null,
@@ -15,7 +15,7 @@ const _DEFAULT_CONFIG_VARS = {
15
15
  pubUrlFilePrefix: '/',
16
16
  //Universal configs
17
17
  transports: ['websocket'],
18
- parted: true,
18
+ parted: false,
19
19
  }
20
20
 
21
21
  const _DEFAULT_CONFIG = Object.freeze(_DEFAULT_CONFIG_VARS);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.3.0",
4
+ "version": "2.3.1",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -52,7 +52,7 @@
52
52
  "@open-wc/dev-server-hmr": "^0.1.2-next.0",
53
53
  "@types/dragula": "^3.7.4",
54
54
  "@types/express-fileupload": "^1.4.4",
55
- "@types/he": "^1.2.3",
55
+ "@types/he": "^1.2.3",
56
56
  "@types/json5": "^2.2.0",
57
57
  "@types/sanitize-html": "^2.11.0",
58
58
  "@types/socket.io-client": "^3.0.0",
@@ -67,7 +67,7 @@
67
67
  "eslint-plugin-unused-imports": "^3.1.0",
68
68
  "file-loader": "^6.2.0",
69
69
  "html-webpack-plugin": "^5.5.3",
70
- "loader-utils": "^3.2.1",
70
+ "loader-utils": "^3.2.1",
71
71
  "mini-css-extract-plugin": "^2.7.6",
72
72
  "node-sass": "^9.0.0",
73
73
  "sass-loader": "^13.3.2",
@@ -40,22 +40,29 @@ const publicIndex = BuildConfigurator.get('publicIndex') || config.publicIndex;
40
40
 
41
41
  let WEBPACK_PLUGINS = [
42
42
  new webpack.DefinePlugin({
43
- 'process.env._RWS_DEFAULTS': JSON.stringify(BuildConfigurator.exportConfig())
44
- }),
45
- new webpack.BannerPlugin({
46
- banner: `if(!window.RWS){
47
- const script = document.createElement('script');
48
- script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
49
- script.type = 'text/javascript';
50
- document.body.appendChild(script);
51
- }`.replace('\n', ''),
52
- raw: true,
53
- entryOnly: true,
54
- // include: 'client'
43
+ 'process.env._RWS_DEFAULTS': JSON.stringify(BuildConfigurator.exportDefaultConfig()),
44
+ 'process.env._RWS_BUILD_OVERRIDE': JSON.stringify(BuildConfigurator.exportBuildConfig())
55
45
  }),
56
46
  new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/)
57
47
  ];
58
48
 
49
+ console.log('PARTED', isParted);
50
+
51
+ // if(isParted){
52
+ // WEBPACK_PLUGINS.push(new webpack.BannerPlugin({
53
+ // banner: `if(!window.RWS_PARTS_LOADED){
54
+ // const script = document.createElement('script');
55
+ // script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
56
+ // script.type = 'text/javascript';
57
+ // document.body.appendChild(script);
58
+ // window.RWS_PARTS_LOADED = true;
59
+ // }`.replace('\n', ''),
60
+ // raw: true,
61
+ // entryOnly: true,
62
+ // // include: 'client'
63
+ // }));
64
+ // }
65
+
59
66
  const WEBPACK_AFTER_ACTIONS = config.actions || [];
60
67
 
61
68
  const aliases = config.aliases = {};
@@ -125,7 +132,18 @@ const publicIndex = BuildConfigurator.get('publicIndex') || config.publicIndex;
125
132
 
126
133
  const optimConfig = {
127
134
  minimize: true,
128
- minimizer: isDev ? [] : [
135
+ minimizer: isDev ? [
136
+ new TerserPlugin({
137
+ terserOptions: {
138
+ mangle: false, //@error breaks FAST view stuff if enabled for all assets
139
+ output: {
140
+ comments: false
141
+ },
142
+ },
143
+ extractComments: false,
144
+ parallel: true,
145
+ })
146
+ ] : [
129
147
  new TerserPlugin({
130
148
  terserOptions: {
131
149
  keep_classnames: true, // Prevent mangling of class names
package/src/client.ts CHANGED
@@ -39,7 +39,7 @@ class RWSClient {
39
39
  private _container: Container;
40
40
  private user: IRWSUser = null;
41
41
 
42
- private config: IRWSConfig = { backendUrl: '', routes: {}, partedFileDir: '/', partedPrefix: 'rws' };
42
+ private config: IRWSConfig = {};
43
43
  protected initCallback: () => Promise<void> = async () => { };
44
44
 
45
45
  private isSetup = false;
@@ -112,11 +112,9 @@ class RWSClient {
112
112
  this.pushUserToServiceWorker(this.user);
113
113
  }
114
114
 
115
- await startClient(this.appConfig, this.wsService, this.notifyService, this.routingService);
115
+ await startClient(this.appConfig, this.wsService, this.notifyService, this.routingService);
116
116
 
117
- RWSClient.defineAllComponents();
118
-
119
- await this.initCallback();
117
+ await this.initCallback();
120
118
 
121
119
  return this;
122
120
  }
@@ -226,13 +224,15 @@ class RWSClient {
226
224
  const componentParts: string[] = await this.apiService.get<string[]>(this.appConfig.get('partedDirUrlPrefix') + '/rws_chunks_info.json');
227
225
 
228
226
  componentParts.forEach((componentName: string, key: number) => {
227
+ const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
228
+
229
229
  const script: HTMLScriptElement = document.createElement('script');
230
- script.src = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
230
+ script.src = partUrl;
231
231
  script.async = true;
232
232
  script.type = 'text/javascript';
233
233
  document.body.appendChild(script);
234
234
 
235
- console.log(`Appended ${componentParts[key]} component`);
235
+ console.log(`Appended ${componentParts[key]} component (${partUrl})`);
236
236
  });
237
237
  }
238
238
 
@@ -272,7 +272,18 @@ class RWSClient {
272
272
 
273
273
  static defineAllComponents() {
274
274
  const richWindowComponents: RWSWindowComponentRegister = (window as Window & RWSWindow).RWS.components;
275
-
275
+ console.log('defining', richWindowComponents)
276
+
277
+ Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
278
+ el.define(el as any, el.definition);
279
+ });
280
+ }
281
+
282
+
283
+ defineComponents(){
284
+ const richWindowComponents: RWSWindowComponentRegister = (window as Window & RWSWindow).RWS.components;
285
+ console.log('defining', richWindowComponents)
286
+
276
287
  Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
277
288
  el.define(el as any, el.definition);
278
289
  });
@@ -63,7 +63,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
63
63
  @RWSInject(NotifyService) protected notifyService: NotifyServiceInstance
64
64
  ) {
65
65
  super();
66
- applyConstructor(this);
66
+ applyConstructor(this);
67
67
  }
68
68
 
69
69
  connectedCallback() {
@@ -71,7 +71,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
71
71
  applyConstructor(this);
72
72
 
73
73
  // console.trace(this.config);
74
-
74
+ // console.log(this.routingService);
75
75
  if (!(this.constructor as IWithCompose<this>).definition && (this.constructor as IWithCompose<this>).autoLoadFastElement) {
76
76
  throw new Error('RWS component is not named. Add `static definition = {name, template};`');
77
77
  }
@@ -17,7 +17,7 @@ type InjectDecoratorReturnType = (target: any, key?: string | number | undefined
17
17
  function RWSInject<T extends RWSViewComponent>(dependencyClass: Key): InjectDecoratorReturnType {
18
18
  return (target: IWithCompose<T>, key?: keyof IWithCompose<T>, parameterIndex?: number) => {
19
19
  const loadedDependency = RWSContainer().get(dependencyClass);
20
- const paramNames = getFunctionParamNames(target.prototype.constructor);
20
+ const paramNames = getFunctionParamNames(target.prototype.constructor);
21
21
  target.prototype.constructor._toInject[paramNames[parameterIndex]] = loadedDependency;
22
22
  };
23
23
  }
@@ -63,8 +63,8 @@ const applyConstructor = (component: RWSViewComponent): void => {
63
63
  }
64
64
 
65
65
  const existingInjectedDependencies = (topConstructor as IWithCompose<RWSViewComponent>)._toInject;
66
-
67
66
  Object.keys(existingInjectedDependencies).forEach((depKey: string) => {
67
+
68
68
  const loadedDependency = existingInjectedDependencies[depKey];
69
69
  if(!(component as any)[depKey]){
70
70
  (component as any)[depKey] = loadedDependency;
@@ -1,40 +1,53 @@
1
1
  import 'reflect-metadata';
2
2
  import IRWSConfig from '../../interfaces/IRWSConfig.js';
3
3
 
4
+ function extractEnvVar(envVar: string){
5
+ const extractedVars = JSON.parse(JSON.stringify(envVar));
4
6
 
5
- function RWSFillBuild(config?: Partial<IRWSConfig>) {
7
+ const {
8
+ backendUrl,
9
+ wsUrl,
10
+ partedDirUrlPrefix,
11
+ partedPrefix,
12
+ pubUrlFilePrefix,
13
+ transports,
14
+ parted
15
+ } = extractedVars;
16
+
17
+ const extractedFrontendVars = {
18
+ backendUrl,
19
+ wsUrl,
20
+ partedDirUrlPrefix,
21
+ partedPrefix,
22
+ pubUrlFilePrefix,
23
+ transports,
24
+ parted
25
+ };
26
+
27
+ return {
28
+ extractedVars,
29
+ extractedFrontendVars
30
+ }
31
+ }
32
+
33
+ function RWSFillBuild(config: Partial<IRWSConfig> = {}) {
6
34
  return function <T extends { new(...args: any[]): {} }>(constructor: T) {
7
35
  return class extends constructor {
8
36
  _DEFAULTS: IRWSConfig;
37
+ _BUILD_OVERRIDE: IRWSConfig;
9
38
  constructor(...args: any[]) {
10
39
  super(...args);
11
40
 
12
- const extractedDefaults = JSON.parse(JSON.stringify(process.env._RWS_DEFAULTS));
13
-
14
- const {
15
- backendUrl,
16
- wsUrl,
17
- partedDirUrlPrefix,
18
- partedPrefix,
19
- pubUrlFilePrefix,
20
- transports,
21
- parted
22
- } = extractedDefaults;
23
-
24
- const extractedFrontendDefaults = {
25
- backendUrl,
26
- wsUrl,
27
- partedDirUrlPrefix,
28
- partedPrefix,
29
- pubUrlFilePrefix,
30
- transports,
31
- parted
32
- };
41
+ const extractedFrontendDefaults = extractEnvVar(process.env._RWS_DEFAULTS).extractedFrontendVars;
33
42
 
34
43
  this._DEFAULTS = {
35
44
  ...config,
36
45
  ...extractedFrontendDefaults
37
- };
46
+ } as IRWSConfig;
47
+
48
+ const extractedFrontendBuildVars = extractEnvVar(process.env._RWS_BUILD_OVERRIDE).extractedFrontendVars;;
49
+
50
+ this._BUILD_OVERRIDE = extractedFrontendBuildVars as IRWSConfig;
38
51
  }
39
52
  };
40
53
  };
@@ -3,7 +3,7 @@ import { RWSRouter, _ROUTING_EVENT_NAME, RouteReturn } from '../../services/Rout
3
3
  import RWSViewComponent, { IRWSViewComponent } from '../_component';
4
4
  import {RWSView} from '../_decorator';
5
5
 
6
- @RWSView('rws-router', { ignorePackaging: true })
6
+ @RWSView('rws-router')
7
7
  export class RouterComponent extends RWSViewComponent {
8
8
  static autoLoadFastElement = false;
9
9
  private routing: RWSRouter;
@@ -15,19 +15,24 @@ export class RouterComponent extends RWSViewComponent {
15
15
 
16
16
  connectedCallback() {
17
17
  super.connectedCallback();
18
+
19
+
20
+
18
21
  this.routing = this.routingService.apply(this);
19
22
 
20
- if(this.currentUrl){
23
+ if(this.currentUrl){
21
24
  this.handleRoute(this.routing.handleRoute(this.currentUrl));
22
25
  }
23
26
  }
24
27
 
25
- currentUrlChanged(oldValue: string, newValue: string){
26
- if(!this.routing){
27
- this.routing = this.routingService.apply(this);
28
+ currentUrlChanged(oldValue: string, newValue: string){
29
+ if(newValue){
30
+ if(!this.routing){
31
+ this.routing = this.routingService.apply(this);
28
32
 
29
- }
30
- this.handleRoute(this.routing.handleRoute(newValue));
33
+ }
34
+ this.handleRoute(this.routing.handleRoute(newValue));
35
+ }
31
36
  }
32
37
 
33
38
  private handleRoute(route: RouteReturn){
@@ -0,0 +1 @@
1
+ <div class="router"></div>
@@ -28,13 +28,15 @@ class RWSRouter {
28
28
  }
29
29
 
30
30
  public fireHandler(route: IRWSRouteResult): RouteReturn
31
- { const handler = route.handler();
31
+ {
32
+ const handler = route.handler();
32
33
  return [handler[0], handler[1], this.utilsService.mergeDeep(route.params, handler[2])];
33
34
  }
34
35
 
35
36
  public handleRoute(url: string): RouteReturn
36
37
  {
37
38
  const currentRoute = this.find(url);
39
+ console.log('CR', currentRoute);
38
40
 
39
41
  if (history.pushState) {
40
42
  window.history.pushState({ path: url }, '', url);
@@ -7,15 +7,13 @@ import { RWSFillBuild } from '../components/_decorators/RWSFillBuild';
7
7
 
8
8
  const __SENT_TO_COMPONENTS: string[] = [];
9
9
 
10
- @RWSFillBuild({
11
- pubUrlFilePrefix: '/',
12
- pubUrl: window.origin,
13
- partedFileDir: '/',
14
- partedPrefix: 'rws',
15
- })
10
+ @RWSFillBuild()
16
11
  class ConfigService extends TheService {
17
12
  static isLoaded: boolean = false;
18
- _DEFAULTS: any = null;
13
+
14
+ _DEFAULTS: Partial<IRWSConfig> = {};
15
+ _BUILD_OVERRIDE: IRWSConfig = {};
16
+
19
17
  private data: IRWSConfig = {};
20
18
 
21
19
  constructor() {
@@ -23,24 +21,32 @@ class ConfigService extends TheService {
23
21
  }
24
22
 
25
23
  public get(key: keyof IRWSConfig): any
26
- {
24
+ {
25
+
27
26
  if(!this._DEFAULTS){
28
27
  throw new Error('No _DEFAULTS loaded!')
29
28
  }
30
29
 
31
- const isInData: boolean = Object.keys(this.data).includes(key);
30
+
32
31
  const isInDefaults: boolean = Object.keys(this._DEFAULTS).includes(key);
32
+ const isInData: boolean = Object.keys(this.data).includes(key);
33
+ const isInBuildVars: boolean = Object.keys(this._BUILD_OVERRIDE).includes(key);
34
+
35
+ if(!isInData){
36
+ let defaultVal = null;
33
37
 
34
- if(!isInData && isInDefaults){
35
- let defaultVal = this._DEFAULTS[key];
36
- console.log(key, 'kk')
38
+ if(isInDefaults){
39
+ defaultVal = this._DEFAULTS[key];
40
+ }
41
+
42
+ if(isInBuildVars && !!this._BUILD_OVERRIDE[key]){
43
+ defaultVal = this._BUILD_OVERRIDE[key];
44
+ }
45
+
37
46
  if(defaultVal && defaultVal[0] === '@'){
38
47
  defaultVal = this.data[((defaultVal as string).slice(1)) as keyof IRWSConfig];
39
48
  }
40
-
41
49
  return defaultVal;
42
- } else if(!isInData && !isInDefaults) {
43
- return null;
44
50
  }
45
51
 
46
52