@rws-framework/client 2.9.23 → 2.10.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.
package/_tools.js CHANGED
@@ -337,16 +337,37 @@ function getAllFilesInFolder(folderPath, ignoreFilenames = [], recursive = false
337
337
  return files;
338
338
  }
339
339
 
340
- function getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix) {
340
+ function getRndInteger(min, max) {
341
+ return Math.floor(Math.random() * (max - min + 1) ) + min;
342
+ }
343
+
344
+ function printAddJs(scriptFileName, partedDirUrlPrefix, partedPrefix, onload = ''){
345
+ const sriptVarName = 'script' + getRndInteger(0, 1000);
346
+ return `
347
+ const ${sriptVarName} = document.createElement('script');
348
+ ${sriptVarName}.src = '${partedDirUrlPrefix}/${partedPrefix}.${scriptFileName}.js';
349
+ ${sriptVarName}.type = 'text/javascript';
350
+
351
+ document.body.appendChild(${sriptVarName});
352
+
353
+ ${onload}
354
+ `
355
+ }
356
+
357
+ function getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix, isDev = true) {
358
+ let code = `if(!window.RWS_PARTS_LOADED){
359
+ ${printAddJs('vendors', partedDirUrlPrefix, partedPrefix, `
360
+ window.RWS_PARTS_LOADED = true;
361
+ console.log('\x1b[1m[RWS]\x1b[0m', 'vendors injected for parted mode');
362
+ `)}
363
+ }`;
364
+
365
+ if(!isDev){
366
+ code = code.replace(/\n\s+/g, '');
367
+ }
368
+
341
369
  return {
342
- banner: `if(!window.RWS_PARTS_LOADED){
343
- const script = document.createElement('script');
344
- script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
345
- script.type = 'text/javascript';
346
- document.body.appendChild(script);
347
- window.RWS_PARTS_LOADED = true;
348
- console.log('\x1b[1m[RWS]\x1b[0m', 'vendors injected for parted mode');
349
- }`.replace('\n', ''),
370
+ banner: code,
350
371
  raw: true,
351
372
  entryOnly: true,
352
373
  include: `${partedPrefix}.client.js`
@@ -12,7 +12,7 @@ const _defaultOpts = {
12
12
  }
13
13
  }
14
14
 
15
- const externals = (declaredCodeBase, nodeModules, externalOptions = _defaultOpts) => ({context, request}, callback) => {
15
+ const externals = (declaredCodeBase, nodeModules, automatedChunks, externalOptions = _defaultOpts) => ({context, request}, callback) => {
16
16
  let theOptions = _defaultOpts;
17
17
 
18
18
  if(externalOptions !== null){
@@ -36,11 +36,13 @@ const externals = (declaredCodeBase, nodeModules, externalOptions = _defaultOpts
36
36
 
37
37
  const frontendDirs = [
38
38
  codeBase,
39
- __dirname
40
- ];
39
+ path.resolve(__dirname,'..','..','..')
40
+ ];
41
41
 
42
42
  const inFrontendContext = frontendDirs.some(dir => context.startsWith(dir)) ||
43
- externalOptions._vars.frontendRequestContextCache.some(package => context.indexOf(package.request) > -1);
43
+ externalOptions._vars.frontendRequestContextCache.some(package => context.indexOf(package.request) > -1)
44
+
45
+ ;
44
46
 
45
47
  const patternInContextOrRequest = pattern => pattern.test(request) || pattern.test(context);
46
48
 
@@ -53,13 +55,14 @@ const externals = (declaredCodeBase, nodeModules, externalOptions = _defaultOpts
53
55
  }
54
56
 
55
57
  externalOptions._vars.frontendRequestContextCache.push({request, context});
56
-
57
- //merging to output
58
+
59
+ //handled as RWS async dependency
58
60
  return callback();
59
61
  }
60
62
 
61
63
  externalOptions._vars.ignored.push({request, context});
62
- //using require from node_modules
64
+
65
+ //using require from vendors
63
66
  callback(null, false);
64
67
  }
65
68
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.9.23",
4
+ "version": "2.10.1",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -106,4 +106,4 @@
106
106
  "overrides": {
107
107
  "lodash": "^4.17.21"
108
108
  }
109
- }
109
+ }
@@ -32,7 +32,9 @@ const RWSWebpackWrapper = async (config) => {
32
32
 
33
33
  const executionDir = rwsPath.relativize(BuildConfigurator.get('executionDir') || config.executionDir || process.cwd(), config.packageDir);
34
34
 
35
- const isDev = BuildConfigurator.get('dev', config.dev);
35
+ const isWatcher = process.argv.includes('--watch') || false;
36
+
37
+ const isDev = isWatcher ? true : (BuildConfigurator.get('dev', config.dev) || false);
36
38
  const isHotReload = BuildConfigurator.get('hot', config.hot);
37
39
  const isReport = BuildConfigurator.get('report', config.report);
38
40
  const isParted = BuildConfigurator.get('parted', config.parted || false);
@@ -138,7 +140,18 @@ const RWSWebpackWrapper = async (config) => {
138
140
 
139
141
  const rwsInfoJson = outputDir + '/rws_info.json'
140
142
  const automatedEntries = {};
141
- const automatedChunks = {};
143
+ let automatedChunks = {
144
+ client: config.entry,
145
+ };
146
+
147
+ // if(isParted){
148
+ // automatedChunks = {
149
+ // index: config.entry,
150
+ // client: __dirname + '/src/client.ts',
151
+ // };
152
+
153
+ // console.log({index: automatedChunks.client})
154
+ // }
142
155
 
143
156
  const foundRWSUserClasses = tools.findComponentFilesWithText(executionDir, '@RWSView', ['dist', 'node_modules', '@rws-framework/client']);
144
157
  const foundRWSClientClasses = tools.findComponentFilesWithText(__dirname, '@RWSView', ['dist', 'node_modules']);
@@ -166,39 +179,13 @@ const RWSWebpackWrapper = async (config) => {
166
179
  });
167
180
 
168
181
  if (isParted) {
169
- WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix)));
182
+ // WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix, isDev)));
170
183
 
171
184
  for (const pluginKey of Object.keys(rwsPlugins)){
172
185
  const plugin = rwsPlugins[pluginKey];
173
186
  partedComponentsLocations = await plugin.onComponentsLocated(partedComponentsLocations);
174
187
  }
175
188
 
176
- optimConfig = { splitChunks: {
177
- cacheGroups: {
178
- vendor: {
179
- test: (module) => {
180
- let importString = module.identifier();
181
-
182
- if (importString.split('!').length > 2) {
183
- importString = importString.split('!')[2];
184
- }
185
-
186
- const inNodeModules = importString.indexOf('node_modules') > -1;
187
- const inVendorPackage = importString.indexOf(__dirname) > -1;
188
-
189
- const inExecDir = importString.indexOf(executionDir) > -1;
190
- const isNoPartedComponent = !Object.keys(automatedEntries).find(key => importString.indexOf(path.resolve(path.dirname(automatedEntries[key]))) > -1);
191
-
192
- let isAvailableForVendors = (inNodeModules || inVendorPackage) && isNoPartedComponent;
193
-
194
-
195
- return isAvailableForVendors;
196
- },
197
- name: 'vendors',
198
- chunks: 'all',
199
- }
200
- }
201
- } };
202
189
  }
203
190
 
204
191
  fs.writeFileSync(rwsInfoJson, JSON.stringify({ components: Object.keys(automatedEntries) }, null, 2));
@@ -237,11 +224,11 @@ const RWSWebpackWrapper = async (config) => {
237
224
  WEBPACK_AFTER_ACTIONS.push({
238
225
  type: 'custom',
239
226
  actionHandler: () => {
240
- fs.writeFileSync(path.join(debugDir, 'ignored.json'), JSON.stringify(devExternalsVars.ignored, null, 2));
241
- fs.writeFileSync(path.join(debugDir, 'packed.json'), JSON.stringify(devExternalsVars.packed, null, 2));
227
+ fs.writeFileSync(path.join(debugDir, 'in_vendors.json'), JSON.stringify(devExternalsVars.ignored, null, 2));
228
+ fs.writeFileSync(path.join(debugDir, 'rws_processed.json'), JSON.stringify(devExternalsVars.packed, null, 2));
242
229
  fs.writeFileSync(path.join(debugDir, 'requestcache.json'), JSON.stringify(devExternalsVars.frontendRequestContextCache, null, 2));
243
230
 
244
- console.log(chalk.yellow('[RWS BUILD] (after)'), `saved in: ${debugDir}/(ignored/packed/requestcache).json`);
231
+ console.log(chalk.yellow('[RWS BUILD] (after)'), `packaging debug saved in: ${debugDir}`);
245
232
  }
246
233
  });
247
234
  }
@@ -250,11 +237,9 @@ const RWSWebpackWrapper = async (config) => {
250
237
  WEBPACK_PLUGINS.push(new RWSAfterPlugin({ actions: WEBPACK_AFTER_ACTIONS, dev: isDev }));
251
238
  }
252
239
 
253
-
254
240
  let cfgExport = {
255
241
  context: executionDir,
256
- entry: {
257
- client: config.entry,
242
+ entry: {
258
243
  ...automatedChunks
259
244
  },
260
245
  mode: isDev ? 'development' : 'production',
@@ -276,7 +261,7 @@ const RWSWebpackWrapper = async (config) => {
276
261
  rules: getRWSLoaders(__dirname, path.resolve(config.packageDir, 'node_modules'), tsConfigPath),
277
262
  },
278
263
  plugins: WEBPACK_PLUGINS,
279
- externals: rwsExternals(executionDir, modules_setup, {
264
+ externals: rwsExternals(executionDir, modules_setup, automatedChunks, {
280
265
  _vars: devExternalsVars
281
266
  })
282
267
  }
@@ -5,37 +5,37 @@ import { RWSPlugin } from "../plugins/_plugin";
5
5
  type RWSInfoType = { components: string[] };
6
6
 
7
7
  async function loadPartedComponents(this: RWSClientInstance): Promise<RWSInfoType> {
8
- this.assignClientToBrowser();
9
-
10
- const componentParts: RWSInfoType = await this.apiService.get<RWSInfoType>(this.appConfig.get('partedDirUrlPrefix') + '/rws_info.json');
8
+ this.assignClientToBrowser();
9
+
10
+ return new Promise(async (resolve: (res: RWSInfoType) => void, reject: (res: Error | unknown) => void) => {
11
11
 
12
- const componentsPromises: Promise<string>[] = [];
12
+ const componentParts: RWSInfoType = await this.apiService.get<RWSInfoType>(this.appConfig.get('partedDirUrlPrefix') + '/rws_info.json');
13
+ const loadedComponents = [];
13
14
 
14
- let compList = '';
15
-
16
- componentParts.components.forEach((componentName: string, key: number) => {
17
- const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
18
- componentsPromises.push(this.apiService.pureGet(partUrl, {
19
- headers: {
20
- 'Content-Type': 'script'
21
- } as any
22
- }));
15
+ document.addEventListener(RWSViewComponent._EVENTS.component_define, (event: Event) => {
16
+ const customEvent = event as CustomEvent<string>;
23
17
 
24
- compList += ` - \x1b[1m${componentParts.components[key]}:\x1b[0m component (${partUrl}) \n`;
25
- });
18
+ loadedComponents.push(customEvent.detail);
19
+ });
26
20
 
27
- console.info(`\x1b[1m[RWS]\x1b[0m" \x1b[1mPARTED\x1b[0m" mode asynchronously added components: \n${compList}`);
21
+ let compList = '';
22
+
23
+ componentParts.components.forEach((componentName: string, key: number) => {
24
+ const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
28
25
 
29
- const downloadedComponents = await Promise.all(componentsPromises);
30
-
31
- downloadedComponents.forEach((componentCode: string, key: number) => {
32
- const script: HTMLScriptElement = document.createElement('script');
33
- script.textContent = componentCode;
34
- script.type = 'text/javascript';
35
- document.body.appendChild(script);
36
- });
26
+ compList += ` - \x1b[1m${componentParts.components[key]}:\x1b[0m component (${partUrl}) \n`;
27
+
28
+ const script: HTMLScriptElement = document.createElement('script');
29
+ script.async = true;
30
+ script.src = partUrl;
31
+ script.type = 'text/javascript';
32
+ document.body.appendChild(script);
33
+ });
34
+
35
+ console.info(`\x1b[1m[RWS]\x1b[0m" \x1b[1mPARTED\x1b[0m" mode asynchronously added components: \n${compList}`);
37
36
 
38
- return componentParts;
37
+ resolve(componentParts);
38
+ });
39
39
  }
40
40
 
41
41
  function defineAllComponents() {
@@ -11,7 +11,7 @@ import { applyConstructor, RWSInject } from './_decorator';
11
11
  import TheRWSService from '../services/_service';
12
12
  import { handleExternalChange } from './_attrs/_external_handler';
13
13
  import { IFastDefinition, isDefined, defineComponent, getDefinition } from './_definitions';
14
- import { on, $emitDown, observe } from './_event_handling';
14
+ import { on, $emitDown, observe, sendEventToOutside } from './_event_handling';
15
15
 
16
16
  type ComposeMethodType<
17
17
  T extends FoundationElementDefinition,
@@ -31,6 +31,11 @@ export interface IWithCompose<T extends RWSViewComponent> {
31
31
  _depKeys: {[key: string]: string[]};
32
32
  _externalAttrs: { [key:string]: string[] };
33
33
  setExternalAttr: (componentName: string, key: string) => void
34
+ sendEventToOutside: <T>(eventName: string, data: T) => void
35
+ _EVENTS: {
36
+ component_define: string,
37
+ component_parted_load: string,
38
+ }
34
39
  }
35
40
 
36
41
  abstract class RWSViewComponent extends FoundationElement implements IRWSViewComponent {
@@ -48,6 +53,11 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
48
53
  static _externalAttrs: { [key: string]: string[] } = {};
49
54
  static _verbose: boolean = false;
50
55
 
56
+ static _EVENTS = {
57
+ component_define: 'rws:lifecycle:defineComponent',
58
+ component_parted_load: 'rws:lifecycle:loadPartedComponents',
59
+ }
60
+
51
61
  @RWSInject(ConfigService, true) protected config: ConfigServiceInstance;
52
62
  @RWSInject(DOMService, true) protected domService: DOMServiceInstance;
53
63
  @RWSInject(UtilsService, true) protected utilsService: UtilsServiceInstance;
@@ -170,13 +180,11 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
170
180
  }
171
181
 
172
182
  sendEventToOutside<T>(eventName: string, data: T) {
173
- const event = new CustomEvent<T>(eventName, {
174
- detail: data,
175
- bubbles: true,
176
- composed: true
177
- });
183
+ sendEventToOutside(eventName, data);
184
+ }
178
185
 
179
- this.$emit(eventName, event);
186
+ static sendEventToOutside<T>(eventName: string, data: T) {
187
+ sendEventToOutside(eventName, data);
180
188
  }
181
189
 
182
190
  private applyFileList(): void
@@ -43,6 +43,8 @@ export function defineComponent<T extends RWSViewComponent>(element: IWithCompos
43
43
  throw new Error('RWS client not initialized');
44
44
  }
45
45
 
46
+ element.sendEventToOutside<string>(element._EVENTS.component_define, element.definition.name);
47
+
46
48
  richWindow.RWS.components[element.definition.name] = {
47
49
  interface: composedComp,
48
50
  component: element
@@ -31,4 +31,11 @@ export function observe(this: RWSViewComponent, callback: (component: RWSViewCom
31
31
  });
32
32
 
33
33
  observer.observe(this.getShadowRoot(), { childList: true, subtree: true });
34
+ }
35
+
36
+ export function sendEventToOutside<T>(eventName: string, data: T): void
37
+ {
38
+ document.dispatchEvent(new CustomEvent<T>(eventName, {
39
+ detail: data,
40
+ }));
34
41
  }
@@ -3,19 +3,23 @@ import { RWSView, RWSViewComponent, observable, attr } from '../../index';
3
3
  @RWSView('rws-uploader')
4
4
  class RWSUploader extends RWSViewComponent {
5
5
 
6
- @observable uploadProgress: number = 0;
6
+ @observable uploadProgress: number;
7
7
 
8
8
  @observable uploadedFile: File;
9
9
  @observable chosenFile: File;
10
10
  @observable uploadParams: any;
11
11
 
12
12
  @attr onFinish: (uploadResponse: any) => void;
13
- @attr onStart: (chosenFile: File, context: any) => void = (chosenFile: File) => null;
13
+ @attr onStart: (chosenFile: File, context: any) => Promise<unknown> = async (chosenFile: File) => chosenFile;
14
14
  @attr onProgress: (progress: number) => void = (progress: number) => null;
15
15
 
16
16
 
17
17
  async onUploadStart(): Promise<void>
18
18
  {
19
+ if(!this.uploadProgress){
20
+ this.uploadProgress = 0;
21
+ }
22
+
19
23
  const response = await this.onStart(this.chosenFile, this);
20
24
 
21
25
  if(response === null){
@@ -71,7 +75,7 @@ class RWSUploader extends RWSViewComponent {
71
75
 
72
76
  uploadProgressChanged(oldV: any, newV: any)
73
77
  {
74
- console.log('chng', this.uploadProgress);
78
+
75
79
  }
76
80
  }
77
81
 
@@ -1,8 +1,33 @@
1
1
  @import "@rws-mixins";
2
2
 
3
+ //vars
4
+ $upl_secondary: var(--rws-uploader-secondary, #CCC);
5
+ $upl_bg: var(--rws-uploader-bg, #424242);
6
+ $upl_border: var(--rws-uploader-border, #FFF);
7
+
8
+ $upl_primary: var(--rws-uploader-primary, #EE2375);
9
+
10
+ $upl_text: var(--rws-uploader-text, #000);
11
+
12
+ $upl_btn_text: var(--rws-uploader-btn-text, #000);
13
+ $upl_btn_bg: var(--rws-uploader-btn-bg, #CCC);
14
+ $upl_btn_border: var(--rws-uploader-btn-border, #000);
15
+
16
+ rws-progress {
17
+ --accent-foreground-rest: $upl_primary;
18
+ }
19
+
20
+ //styles
3
21
  .upload_area {
22
+
23
+ color: $upl_text;
24
+
4
25
  padding: 25px;
5
26
 
27
+
28
+ *{
29
+ box-sizing: border-box;
30
+ }
6
31
 
7
32
  section{
8
33
  &::after{
@@ -14,7 +39,7 @@
14
39
  display: block;
15
40
  contain: content;
16
41
  box-sizing: border-box;
17
- background: #424242;
42
+ background: $upl_bg;
18
43
  border-radius: 10px;
19
44
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
20
45
 
@@ -22,7 +47,7 @@
22
47
  @include grid-container();
23
48
  @include grid-flex-align-items(center, center);
24
49
 
25
- border: 4px dashed #FFF; // Adjust color as needed
50
+ border: 4px dashed $upl_border; // Adjust color as needed
26
51
  width: 100%; // Adjust width as needed
27
52
  height: 100%; // Adjust height as needed
28
53
  padding: 30px;
@@ -33,14 +58,14 @@
33
58
  cursor: pointer;
34
59
 
35
60
  .file-block {
36
- border: 1px solid #FFF;
61
+ border: 1px solid $upl_border;
37
62
 
38
63
  font-size: 10px;
39
64
  padding: 15px;
40
65
  border-radius: 15px;
41
66
 
42
67
  .close-btn {
43
- border: 1px solid #FFF;
68
+ border: 1px solid $upl_border;
44
69
  padding: 5px;
45
70
  font-weight: bold;
46
71
  margin-left: 10px;
@@ -53,7 +78,7 @@
53
78
 
54
79
  &:before{
55
80
  content: '';
56
- background: #CCC;
81
+ background: $upl_secondary;
57
82
  opacity: 0.4;
58
83
 
59
84
  position: absolute;
@@ -70,6 +95,7 @@
70
95
 
71
96
  h3{
72
97
  padding: 0 15px;
98
+ color: $upl_text;
73
99
  }
74
100
 
75
101
  article {
@@ -78,14 +104,14 @@
78
104
 
79
105
 
80
106
  button {
81
- background: var(--accent-fill-rest);
82
- color: var(--foreground-on-accent-rest);
107
+ background: $upl_btn_bg;
108
+ color: $upl_btn_text;
83
109
  font-size: 14px;
84
110
  padding: 10px;
85
111
  box-shadow: none;
86
112
  border-radius: 5px;
87
113
  border-style: solid;
88
- border-color: var(--accent-fill-rest);
114
+ border-color: $upl_btn_border;
89
115
  border-width: 1px;
90
116
 
91
117
  fill: currentcolor;
@@ -97,6 +123,8 @@
97
123
 
98
124
  &.next{
99
125
  float: right;
126
+ margin-right: 10px;
127
+ margin-bottom: 10px;
100
128
  }
101
129
  }
102
130
  }
@@ -1,7 +1,7 @@
1
1
  <div class="upload_area">
2
2
  <section>
3
3
  <h3>Upload file</h3>
4
- <rws-progress value="${x => x.uploadProgress}" min="1" max="100"></rws-progress>
4
+ <rws-progress :value="${x => x.uploadProgress}" min="1" max="100"></rws-progress>
5
5
  <article>
6
6
  <div class="drag-and-drop">
7
7
  <div @click="${x => !x.chosenFile ? x.onChoose() : (() => {})()}" class="upl-background"></div>
@@ -1,6 +1,7 @@
1
1
  import TheService from './_service';
2
2
  import IRWSConfig from '../types/IRWSConfig';
3
3
  import { RWSFillBuild } from '../components/_decorators/RWSFillBuild';
4
+ import { sendEventToOutside } from '../components/_event_handling';
4
5
 
5
6
 
6
7
 
@@ -85,11 +86,9 @@ class ConfigService extends TheService {
85
86
  return;
86
87
  }
87
88
 
88
- __SENT_TO_COMPONENTS.push(tagName);
89
+ __SENT_TO_COMPONENTS.push(tagName);
89
90
 
90
- document.dispatchEvent(new CustomEvent<{tagName: string}>('rws_cfg_call', {
91
- detail: {tagName},
92
- }));
91
+ sendEventToOutside<{tagName: string}>('rws_cfg_call', {tagName})
93
92
 
94
93
  return new Promise((resolve) => {
95
94
  const tick = () => {