@rws-framework/client 2.9.13 → 2.9.15

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/README.md CHANGED
@@ -8,7 +8,6 @@ Realtime Web Suit is a web-component powered, MS FAST powered fullstack-oriented
8
8
  2. [Getting Started](#getting-started)
9
9
  3. [Key Components: RWSClient & RoutingService](#key-components-rwsclient--routingservice)
10
10
  4. [Component Initialization](#component-initialization)
11
- 4. [RWS Decorators](#rws-decorators)
12
11
  5. [DI](#dependency-injection)
13
12
  6. [Frontend routes](#frontend-routes)
14
13
  7. [Backend Imports](#backend-imports)
@@ -389,16 +388,7 @@ class WebChat extends RWSViewComponent {
389
388
  }
390
389
  ```
391
390
 
392
- **external decorators + @ngAttr fire externalChanged function after changes**
393
-
394
- ```typescript
395
- externalChanged(name: string, oldValue: string | undefined, newValue: string): void
396
- {
397
- this.callApi();
398
- }
399
- ```
400
-
401
- The RWSView decorator options type:
391
+ The decorator options type:
402
392
 
403
393
  ```typescript
404
394
  interface RWSDecoratorOptions{
@@ -1,8 +1,6 @@
1
1
  const path = require('path');
2
2
 
3
3
  function getRWSLoaders(packageDir, nodeModulesPath, tsConfigPath){
4
- console.log(packageDir, nodeModulesPath, tsConfigPath);
5
-
6
4
  const scssLoader = packageDir + '/webpack/loaders/rws_fast_scss_loader.js';
7
5
  const tsLoader = packageDir + '/webpack/loaders/rws_fast_ts_loader.js';
8
6
  const htmlLoader = packageDir + '/webpack/loaders/rws_fast_html_loader.js';
@@ -0,0 +1,38 @@
1
+ const TerserPlugin = require('terser-webpack-plugin');
2
+ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
3
+
4
+
5
+ function getRWSProductionSetup(optimConfig){
6
+
7
+ return {
8
+ ...optimConfig,
9
+ minimize: true,
10
+ minimizer: [
11
+ new TerserPlugin({
12
+ terserOptions: {
13
+ keep_classnames: true, // Prevent mangling of class names
14
+ mangle: false, //@error breaks FAST view stuff if enabled for all assets
15
+ compress: {
16
+ dead_code: true,
17
+ pure_funcs: ['console.log', 'console.info', 'console.warn']
18
+ },
19
+ output: {
20
+ comments: false,
21
+ beautify: false
22
+ },
23
+ },
24
+ extractComments: false,
25
+ parallel: true,
26
+ }),
27
+ new CssMinimizerPlugin({
28
+ minimizerOptions: {
29
+ preset: ['default', {
30
+ discardComments: { removeAll: false },
31
+ }],
32
+ },
33
+ })
34
+ ]
35
+ };
36
+ }
37
+
38
+ module.exports = { getRWSProductionSetup }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.9.13",
4
+ "version": "2.9.15",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -47,19 +47,11 @@
47
47
  "socket.io-client": "^4.7.2",
48
48
  "source-map": "^0.7.4",
49
49
  "source-map-support": "^0.5.21",
50
- "stacktrace-gps": "^3.1.2",
51
- "style-loader": "^3.3.3",
52
- "terser-webpack-plugin": "^5.3.9",
53
- "ts-loader": "^9.4.4",
54
- "ts-transformer-keys": "^0.4.4",
55
- "tsc-watch": "^6.0.4",
56
- "tslib": "^2.6.2",
57
- "uglify-js": "^3.17.4",
50
+ "stacktrace-gps": "^3.1.2",
58
51
  "upload": "^1.3.2",
59
52
  "url-router": "^13.0.0",
60
53
  "uuid": "^9.0.1",
61
- "v4": "^0.0.1",
62
- "webpack": "^5.89.0"
54
+ "v4": "^0.0.1"
63
55
  },
64
56
  "devDependencies": {
65
57
  "@types/dragula": "^3.7.4",
@@ -97,6 +89,11 @@
97
89
  "typedoc-theme-hierarchy": "^4.1.2",
98
90
  "typescript": "^5.1.6",
99
91
  "url-loader": "^4.1.1",
92
+ "emoji-regex": "^10.3.0",
93
+ "ts-transformer-keys": "^0.4.4",
94
+ "tsc-watch": "^6.0.4",
95
+ "tslib": "^2.6.2",
96
+ "uglify-js": "^3.17.4",
100
97
  "webpack": "^5.75.0",
101
98
  "webpack-bundle-analyzer": "^4.10.1",
102
99
  "webpack-cli": "^5.1.4",
@@ -5,10 +5,10 @@ const webpack = require('webpack');
5
5
  const { rwsPath, RWSConfigBuilder } = require('@rws-framework/console');
6
6
 
7
7
  const HtmlWebpackPlugin = require('html-webpack-plugin');
8
+ const { ESBuildPlugin } = require('esbuild-loader');
8
9
 
9
10
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
10
- const TerserPlugin = require('terser-webpack-plugin');
11
- const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
11
+
12
12
 
13
13
  const RWSAfterPlugin = require('./webpack/rws_after_plugin');
14
14
 
@@ -19,6 +19,7 @@ const tools = require('./_tools');
19
19
  const buildInfo = require('./cfg/build_steps/webpack/_info');
20
20
  const { loadAliases } = require('./cfg/build_steps/webpack/_aliases');
21
21
  const { getRWSLoaders } = require('./cfg/build_steps/webpack/_loaders');
22
+ const { getRWSProductionSetup } = require('./cfg/build_steps/webpack/_production');
22
23
  const { rwsExternals } = require('./cfg/build_steps/webpack/_rws_externals');
23
24
 
24
25
  const { _DEFAULT_CONFIG } = require('./cfg/_default.cfg');
@@ -79,7 +80,11 @@ const RWSWebpackWrapper = async (config) => {
79
80
  new webpack.IgnorePlugin({
80
81
  resourceRegExp: /.*\.es6\.js$/,
81
82
  contextRegExp: /node_modules/
82
- })
83
+ }),
84
+ // new ESBuildPlugin({
85
+ // 'process.env._RWS_DEFAULTS': JSON.stringify(BuildConfigurator.exportDefaultConfig()),
86
+ // 'process.env._RWS_BUILD_OVERRIDE': JSON.stringify(BuildConfigurator.exportBuildConfig())
87
+ // })
83
88
  ];
84
89
 
85
90
  const WEBPACK_AFTER_ACTIONS = config.actions || [];
@@ -208,35 +213,9 @@ const RWSWebpackWrapper = async (config) => {
208
213
  optimConfig = {};
209
214
  }
210
215
 
211
- optimConfig = {
212
- ...optimConfig,
213
- minimize: true,
214
- minimizer: [
215
- new TerserPlugin({
216
- terserOptions: {
217
- keep_classnames: true, // Prevent mangling of class names
218
- mangle: false, //@error breaks FAST view stuff if enabled for all assets
219
- compress: !isDev ? {
220
- dead_code: true,
221
- pure_funcs: ['console.log', 'console.info', 'console.warn']
222
- } : null,
223
- output: {
224
- comments: false,
225
- beautify: isDev
226
- },
227
- },
228
- extractComments: false,
229
- parallel: true,
230
- }),
231
- new CssMinimizerPlugin({
232
- minimizerOptions: {
233
- preset: ['default', {
234
- discardComments: { removeAll: false },
235
- }],
236
- },
237
- })
238
- ]
239
- };
216
+ optimConfig = getRWSProductionSetup(optimConfig, tsConfigPath);
217
+
218
+ // WEBPACK_PLUGINS.push(new ESBuildPlugin());
240
219
  }
241
220
 
242
221
  const devExternalsVars = {
@@ -8,6 +8,13 @@ import deepmerge from 'deepmerge';
8
8
  type RWSInfoType = { components: string[] };
9
9
 
10
10
  function getUser(this: RWSClientInstance): IRWSUser {
11
+
12
+ const localSaved = localStorage.getItem('the_rws_user');
13
+
14
+ if (localSaved) {
15
+ this.setUser(JSON.parse(localSaved) as IRWSUser);
16
+ }
17
+
11
18
  return this.user;
12
19
  }
13
20
 
@@ -21,6 +28,8 @@ function setUser(this: RWSClientInstance, user: IRWSUser): RWSClientInstance {
21
28
 
22
29
  this.apiService.setToken(this.user.jwt_token);
23
30
 
31
+ localStorage.setItem('the_rws_user', JSON.stringify(this.user));
32
+
24
33
  for(const plugin of RWSPlugin.getAllPlugins()){
25
34
  plugin.onSetUser(user);
26
35
  }
@@ -89,8 +98,6 @@ async function setup(this: RWSClientInstance, config: IRWSConfig = {}): Promise<
89
98
 
90
99
  this.appConfig.mergeConfig(this.config);
91
100
 
92
- console.log(this.config);
93
-
94
101
  if(this.config.plugins){
95
102
  for (const pluginEntry of this.config.plugins){
96
103
  addPlugin.bind(this)(pluginEntry);
@@ -103,11 +110,7 @@ async function setup(this: RWSClientInstance, config: IRWSConfig = {}): Promise<
103
110
  for (const plugin of RWSPlugin.getAllPlugins()){
104
111
  plugin.onPartedComponentsLoad(componentParts);
105
112
  }
106
- }
107
-
108
- if(config?.user){
109
- this.setUser(config.user);
110
- }
113
+ }
111
114
 
112
115
  this.isSetup = true;
113
116
  return this.config;
@@ -124,16 +127,13 @@ async function start(this: RWSClientInstance, config: IRWSConfig = {}): Promise<
124
127
  this.appConfig.mergeConfig(this.config);
125
128
  }
126
129
 
127
- if(!this.user && config?.user){
128
- this.setUser(config.user);
129
- }
130
-
131
130
  if (this.config.user && !this.config.dontPushToSW) {
132
131
  this.pushUserToServiceWorker(this.user);
133
132
  }
134
133
 
135
134
  await this.initCallback();
136
- for (const plugin of RWSPlugin.getAllPlugins()){
135
+
136
+ for (const plugin of RWSPlugin.getAllPlugins()){
137
137
  await plugin.onClientStart();
138
138
  }
139
139
 
File without changes
@@ -10,12 +10,8 @@ import RWSWindow, { RWSWindowComponentInterface, loadRWSRichWindow } from '../ty
10
10
  import { applyConstructor, RWSInject } from './_decorator';
11
11
  import TheRWSService from '../services/_service';
12
12
  import { handleExternalChange } from './_attrs/_external_handler';
13
-
14
- interface IFastDefinition {
15
- name: string;
16
- template: ViewTemplate;
17
- styles?: ElementStyles;
18
- }
13
+ import { IFastDefinition, isDefined, defineComponent, getDefinition } from './_definitions';
14
+ import { on, $emitDown, observe } from './_event_handling';
19
15
 
20
16
  type ComposeMethodType<
21
17
  T extends FoundationElementDefinition,
@@ -79,27 +75,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
79
75
  this.applyFileList();
80
76
 
81
77
  RWSViewComponent.instances.push(this);
82
- }
83
-
84
- observe(callback: (component: this, node: Node, observer: MutationObserver) => Promise<void>, condition: (component: this, node: Node) => boolean = null, observeRemoved: boolean = false)
85
- {
86
- const observer = new MutationObserver((mutationsList, observer) => {
87
- for(const mutation of mutationsList) {
88
- if (mutation.type === 'childList') {
89
- const mutationObserveType: NodeList = observeRemoved ? mutation.removedNodes : mutation.addedNodes;
90
- mutationObserveType.forEach(node => {
91
- if ((condition !== null && condition(this, node))) {
92
- callback(this, node, observer);
93
- }else if(condition === null){
94
- callback(this, node, observer);
95
- }
96
- });
97
- }
98
- }
99
- });
100
-
101
- observer.observe(this.getShadowRoot(), { childList: true, subtree: true });
102
- }
78
+ }
103
79
 
104
80
  passRouteParams(routeParams: Record<string, string> = null) {
105
81
  if (routeParams) {
@@ -118,16 +94,16 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
118
94
  }
119
95
 
120
96
  on<T>(type: string, listener: (event: CustomEvent<T>) => any) {
121
- this.addEventListener(type, (baseEvent: Event) => {
122
- listener(baseEvent as CustomEvent<T>);
123
- });
97
+ return on.bind(this)(type, listener);
124
98
  }
125
99
 
126
100
  $emitDown<T>(eventName: string, payload: T) {
127
- this.$emit(eventName, payload, {
128
- bubbles: true,
129
- composed: true
130
- });
101
+ return $emitDown.bind(this)(eventName, payload);
102
+ }
103
+
104
+ observe(callback: (component: RWSViewComponent, node: Node, observer: MutationObserver) => Promise<void>, condition: (component: RWSViewComponent, node: Node) => boolean = null, observeRemoved: boolean = false)
105
+ {
106
+ return observe.bind(this)(callback, condition, observeRemoved);
131
107
  }
132
108
 
133
109
  parse$<T extends Element>(input: NodeListOf<T>, directReturn: boolean = false): DOMOutputType<T> {
@@ -236,58 +212,17 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
236
212
 
237
213
  static isDefined<T extends RWSViewComponent>(this: IWithCompose<T>): boolean
238
214
  {
239
- const richWindow: RWSWindow = loadRWSRichWindow();
240
-
241
- if(!this.definition){
242
- return false;
243
- }
244
-
245
- return Object.keys(richWindow.RWS.components).includes(this.definition.name);
215
+ return isDefined<T>(this);
246
216
  }
247
217
 
248
218
  static defineComponent<T extends RWSViewComponent>(this: IWithCompose<T>): void
249
219
  {
250
- if(this.isDefined()){
251
- if(this._verbose){
252
- console.warn(`Component ${this.name} is already declared`);
253
- }
254
-
255
- return;
256
- }
257
-
258
- const richWindow = loadRWSRichWindow();
259
-
260
- if (!this.definition) {
261
- throw new Error('RWS component is not named. Add `static definition = {name, template};`');
262
- }
263
-
264
- const composedComp = this.compose({
265
- baseName: this.definition.name,
266
- template: this.definition.template,
267
- styles: this.definition.styles
268
- }) as RWSWindowComponentInterface;
269
-
270
- if (!richWindow.RWS) {
271
- throw new Error('RWS client not initialized');
272
- }
273
-
274
- richWindow.RWS.components[this.definition.name] = {
275
- interface: composedComp,
276
- component: this
277
- };
220
+ return defineComponent<T>(this);
278
221
  }
279
222
 
280
- static getDefinition(tagName: string, htmlTemplate: ViewTemplate, styles: ElementStyles = null) {
281
- const def: IFastDefinition = {
282
- name: tagName,
283
- template: htmlTemplate
284
- };
285
-
286
- if (styles) {
287
- def.styles = styles;
288
- }
289
-
290
- return def;
223
+ static getDefinition(tagName: string, htmlTemplate: ViewTemplate, styles: ElementStyles = null)
224
+ {
225
+ return getDefinition(tagName, htmlTemplate, styles);
291
226
  }
292
227
 
293
228
  private static getInstances(): RWSViewComponent[] {
@@ -0,0 +1,63 @@
1
+ import RWSViewComponent, { IWithCompose } from './_component';
2
+ import RWSWindow, { RWSWindowComponentInterface, loadRWSRichWindow } from '../types/RWSWindow';
3
+ import { ElementStyles, ViewTemplate } from '@microsoft/fast-element';
4
+
5
+ export interface IFastDefinition {
6
+ name: string;
7
+ template: ViewTemplate;
8
+ styles?: ElementStyles;
9
+ }
10
+
11
+ export function isDefined<T extends RWSViewComponent>(element: IWithCompose<T>): boolean {
12
+ const richWindow: RWSWindow = loadRWSRichWindow();
13
+
14
+ if (!element.definition) {
15
+ return false;
16
+ }
17
+
18
+ return Object.keys(richWindow.RWS.components).includes(element.definition.name);
19
+ }
20
+
21
+ export function defineComponent<T extends RWSViewComponent>(element: IWithCompose<T>): void {
22
+ if (element.isDefined()) {
23
+ if (element._verbose) {
24
+ console.warn(`Component ${element.name} is already declared`);
25
+ }
26
+
27
+ return;
28
+ }
29
+
30
+ const richWindow = loadRWSRichWindow();
31
+
32
+ if (!element.definition) {
33
+ throw new Error('RWS component is not named. Add `static definition = {name, template};`');
34
+ }
35
+
36
+ const composedComp = element.compose({
37
+ baseName: element.definition.name,
38
+ template: element.definition.template,
39
+ styles: element.definition.styles
40
+ }) as RWSWindowComponentInterface;
41
+
42
+ if (!richWindow.RWS) {
43
+ throw new Error('RWS client not initialized');
44
+ }
45
+
46
+ richWindow.RWS.components[element.definition.name] = {
47
+ interface: composedComp,
48
+ component: element
49
+ };
50
+ }
51
+
52
+ export function getDefinition(tagName: string, htmlTemplate: ViewTemplate, styles: ElementStyles = null) {
53
+ const def: IFastDefinition = {
54
+ name: tagName,
55
+ template: htmlTemplate
56
+ };
57
+
58
+ if (styles) {
59
+ def.styles = styles;
60
+ }
61
+
62
+ return def;
63
+ }
@@ -0,0 +1,34 @@
1
+ import RWSViewComponent from "@rws-framework/client/src/components/_component";
2
+
3
+ export function on<T>(this: RWSViewComponent, type: string, listener: (event: CustomEvent<any>) => any) {
4
+ this.addEventListener(type, (baseEvent: Event) => {
5
+ listener(baseEvent as CustomEvent<T>);
6
+ });
7
+ }
8
+
9
+ export function $emitDown<T>(this: RWSViewComponent, eventName: string, payload: T) {
10
+ this.$emit(eventName, payload, {
11
+ bubbles: true,
12
+ composed: true
13
+ });
14
+ }
15
+
16
+ export function observe(this: RWSViewComponent, callback: (component: RWSViewComponent, node: Node, observer: MutationObserver) => Promise<void>, condition: (component: RWSViewComponent, node: Node) => boolean = null, observeRemoved: boolean = false)
17
+ {
18
+ const observer = new MutationObserver((mutationsList, observer) => {
19
+ for(const mutation of mutationsList) {
20
+ if (mutation.type === 'childList') {
21
+ const mutationObserveType: NodeList = observeRemoved ? mutation.removedNodes : mutation.addedNodes;
22
+ mutationObserveType.forEach(node => {
23
+ if ((condition !== null && condition(this, node))) {
24
+ callback(this, node, observer);
25
+ }else if(condition === null){
26
+ callback(this, node, observer);
27
+ }
28
+ });
29
+ }
30
+ }
31
+ });
32
+
33
+ observer.observe(this.getShadowRoot(), { childList: true, subtree: true });
34
+ }
File without changes
File without changes
@@ -2,18 +2,18 @@ const path = require('path');
2
2
  const fs = require('fs');
3
3
  const RWSScssPlugin = require('../rws_scss_plugin');
4
4
 
5
- module.exports = function(content) {
5
+ module.exports = async function(content) {
6
6
  const filePath = this.resourcePath;
7
7
  const componentDir = path.resolve(path.dirname(filePath), '..');
8
8
  const componentPath = path.resolve(componentDir, 'component.ts');
9
9
  const isDev = this._compiler.options.mode === 'development';
10
10
  const saveFile = content.indexOf('@save') > -1;
11
11
  const plugin = new RWSScssPlugin();
12
- let fromTs = false;
12
+ let fromTs = false;
13
13
 
14
14
  if(saveFile){
15
15
  try {
16
- const codeData = plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
16
+ const codeData = await plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
17
17
 
18
18
  const code = codeData.code;
19
19
  const deps = codeData.dependencies;
@@ -82,10 +82,10 @@ module.exports = async function(content) {
82
82
 
83
83
  if(fs.existsSync(path.dirname(filePath) + '/styles')){
84
84
  const scsscontent = fs.readFileSync(path.dirname(filePath) + '/' + stylesPath, 'utf-8');
85
- const codeData = plugin.compileScssCode(scsscontent, path.dirname(filePath) + '/styles', null, filePath, !isDev);
85
+ const codeData = await plugin.compileScssCode(scsscontent, path.dirname(filePath) + '/styles', null, filePath, !isDev);
86
86
  const cssCode = codeData.code;
87
87
 
88
- styles = `import './${stylesPath}';\n`;
88
+ styles = isDev ? `import './${stylesPath}';\n` : '';
89
89
  if(!templateExists){
90
90
  styles += `import { css } from '@microsoft/fast-element';\n`;
91
91
  }