@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.
Files changed (116) hide show
  1. package/.bin/add-v.sh +10 -0
  2. package/.eslintrc.json +53 -0
  3. package/.setup/.eslintrc.json +11 -0
  4. package/.setup/tsconfig.json +29 -0
  5. package/README.md +691 -0
  6. package/_rws_externals.js +40 -0
  7. package/_tools.js +317 -0
  8. package/console.js +87 -0
  9. package/declarations.d.ts +9 -0
  10. package/docs/.nojekyll +1 -0
  11. package/docs/assets/26e93147f10415a0ed4a.svg +6 -0
  12. package/docs/assets/75c9471662e97ee24f29.svg +7 -0
  13. package/docs/assets/db90e4df2373980c497d.svg +9 -0
  14. package/docs/assets/hierarchy.css +1 -0
  15. package/docs/assets/hierarchy.js +1 -0
  16. package/docs/assets/highlight.css +120 -0
  17. package/docs/assets/main.js +59 -0
  18. package/docs/assets/navigation.js +1 -0
  19. package/docs/assets/search.js +1 -0
  20. package/docs/assets/style.css +1414 -0
  21. package/docs/classes/ApiServiceInstance.html +20 -0
  22. package/docs/classes/DOMServiceInstance.html +10 -0
  23. package/docs/classes/NotifyServiceInstance.html +12 -0
  24. package/docs/classes/RWSClient.html +11 -0
  25. package/docs/classes/RWSRouter.html +9 -0
  26. package/docs/classes/RWSService.html +7 -0
  27. package/docs/classes/RWSUploader.html +35 -0
  28. package/docs/classes/RWSViewComponent.html +24 -0
  29. package/docs/classes/RouterComponent.html +31 -0
  30. package/docs/classes/RoutingServiceInstance.html +13 -0
  31. package/docs/classes/UtilsServiceInstance.html +11 -0
  32. package/docs/classes/WSServiceInstance.html +32 -0
  33. package/docs/functions/RWSView.html +1 -0
  34. package/docs/functions/ngAttr.html +1 -0
  35. package/docs/functions/registerRWSComponents.html +1 -0
  36. package/docs/functions/renderRouteComponent.html +1 -0
  37. package/docs/hierarchy.html +1 -0
  38. package/docs/index.html +53 -0
  39. package/docs/interfaces/IRWSAssetShowOptions.html +1 -0
  40. package/docs/interfaces/IRWSConfig.html +11 -0
  41. package/docs/interfaces/IRWSDecoratorOptions.html +4 -0
  42. package/docs/interfaces/IRWSHttpRoute.html +3 -0
  43. package/docs/interfaces/IRWSPrefixedHTTProutes.html +3 -0
  44. package/docs/interfaces/IRoutingEvent.html +3 -0
  45. package/docs/modules.html +39 -0
  46. package/docs/types/DOMOutputType.html +1 -0
  47. package/docs/types/IRWSBackendRoute.html +1 -0
  48. package/docs/types/IRWSFrontRoutes.html +1 -0
  49. package/docs/types/IRWSRouteResult.html +1 -0
  50. package/docs/types/IRWSWebsocketStatus.html +1 -0
  51. package/docs/types/NotifyLogType.html +1 -0
  52. package/docs/types/NotifyUiType.html +1 -0
  53. package/docs/types/RWSNotify.html +1 -0
  54. package/docs/types/RouteReturn.html +1 -0
  55. package/docs/variables/ApiService.html +1 -0
  56. package/docs/variables/DOMService.html +1 -0
  57. package/docs/variables/NotifyService.html +1 -0
  58. package/docs/variables/RoutingService.html +1 -0
  59. package/docs/variables/UtilsService.html +1 -0
  60. package/docs/variables/WSService.html +1 -0
  61. package/docs/variables/_ROUTING_EVENT_NAME.html +1 -0
  62. package/package.json +93 -0
  63. package/package.webpack.config.js +17 -0
  64. package/rws.webpack.config.js +260 -0
  65. package/src/client.ts +304 -0
  66. package/src/components/_attrs/angular-attr.ts +64 -0
  67. package/src/components/_attrs/sanitize-html.ts +81 -0
  68. package/src/components/_component.ts +290 -0
  69. package/src/components/_container.ts +16 -0
  70. package/src/components/_decorator.ts +112 -0
  71. package/src/components/_design_system.ts +6 -0
  72. package/src/components/index.ts +9 -0
  73. package/src/components/progress/component.ts +55 -0
  74. package/src/components/progress/styles/layout.scss +91 -0
  75. package/src/components/progress/template.html +25 -0
  76. package/src/components/router/component.ts +67 -0
  77. package/src/components/uploader/component.ts +75 -0
  78. package/src/components/uploader/styles/layout.scss +105 -0
  79. package/src/components/uploader/template.html +17 -0
  80. package/src/hmr.ts +19 -0
  81. package/src/index.ts +98 -0
  82. package/src/interfaces/IRWSConfig.ts +24 -0
  83. package/src/interfaces/IRWSUser.ts +7 -0
  84. package/src/interfaces/IRWSViewComponent.ts +37 -0
  85. package/src/interfaces/RWSWindow.ts +39 -0
  86. package/src/routing/_router.ts +59 -0
  87. package/src/routing/index.ts +7 -0
  88. package/src/run.ts +35 -0
  89. package/src/service_worker/src/_service_worker.ts +88 -0
  90. package/src/service_worker/tsconfig.json +21 -0
  91. package/src/service_worker/webpack.config.js +67 -0
  92. package/src/services/ApiService.ts +241 -0
  93. package/src/services/ConfigService.ts +107 -0
  94. package/src/services/DOMService.ts +91 -0
  95. package/src/services/NotifyService.ts +49 -0
  96. package/src/services/RoutingService.ts +46 -0
  97. package/src/services/ServiceWorkerService.ts +60 -0
  98. package/src/services/UtilsService.ts +103 -0
  99. package/src/services/WSService.ts +218 -0
  100. package/src/services/_service.ts +50 -0
  101. package/src/services/_ws_handlers/ConnectionHandler.ts +52 -0
  102. package/src/services/_ws_handlers/EventHandler.ts +28 -0
  103. package/src/services/_ws_handlers/MessageHandler.ts +49 -0
  104. package/src/styles/includes.scss +102 -0
  105. package/src/types/RWSNotify.ts +7 -0
  106. package/tsconfig.json +27 -0
  107. package/typedoc.json +13 -0
  108. package/webpack/after/copy.js +73 -0
  109. package/webpack/after/sw.js +14 -0
  110. package/webpack/index.js +11 -0
  111. package/webpack/rws_after_plugin.js +80 -0
  112. package/webpack/rws_fast_css_loader.js +16 -0
  113. package/webpack/rws_fast_html_loader.js +4 -0
  114. package/webpack/rws_fast_scss_loader.js +50 -0
  115. package/webpack/rws_fast_ts_loader.js +134 -0
  116. package/webpack/rws_plugin.js +337 -0
@@ -0,0 +1,337 @@
1
+ const sass = require('sass');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const { getTokenSourceMapRange } = require('typescript');
5
+ const _tools = require('../_tools');
6
+ const _COMPILE_DIR_NAME = 'compiled';
7
+
8
+ const FONT_REGEX = /url\(['"]?(.+?\.(woff|woff2|eot|ttf|otf))['"]?\)/g;
9
+
10
+ const _DEV = true;
11
+
12
+ const log = (args) => {
13
+ if(_DEV){
14
+ console.log(args);
15
+ }
16
+ }
17
+ class RWSPlugin {
18
+ autoCompile = [];
19
+
20
+ constructor(params){
21
+ this.node_modules_dir = (fileDir) => path.relative(fileDir, _tools.findRootWorkspacePath(process.cwd())) + '/node_modules/'
22
+
23
+ if(!params){
24
+ params = {};
25
+ }
26
+
27
+ if(!!params.autoCompile && params.autoCompile.length > 0){
28
+ this.autoCompile = params.autoCompile;
29
+ }
30
+
31
+ for (let index in this.autoCompile){
32
+ const sassFile = this.autoCompile[index];
33
+ this.compileFile(sassFile, true);
34
+ }
35
+ }
36
+
37
+ extractCssImports(fileContent) {
38
+ const regex = /@import\s+['"](.+?\.css)['"];?/g;
39
+ let match;
40
+ const imports = [];
41
+
42
+ while ((match = regex.exec(fileContent)) !== null) {
43
+ let importPath = match[1];
44
+ // Convert to absolute path or handle it as required
45
+ imports.push(importPath);
46
+ }
47
+
48
+ fileContent = fileContent.replace(regex, '');
49
+
50
+ return [imports, fileContent];
51
+ }
52
+
53
+ extractScssImports(fileContent) {
54
+ const regex = /@import\s+['"](.+?\.scss)['"];?/g;
55
+ let match;
56
+ const imports = [];
57
+
58
+ while ((match = regex.exec(fileContent)) !== null) {
59
+ let importPath = match[1];
60
+
61
+ imports.push(importPath);
62
+ }
63
+
64
+ fileContent = fileContent.replace(regex, '');
65
+
66
+ return [imports, fileContent];
67
+ }
68
+
69
+ replaceNodeModulesImport(fileContent, fileDir) {
70
+ const regex = /@import\s+['"](.+?\.scss)['"];?/g;
71
+
72
+ const resultCode = fileContent.replace(regex, (match, importPath) => {
73
+ return `@import "${path.join(this.node_modules_dir(fileDir), importPath)}";`;
74
+ });
75
+
76
+ return resultCode;
77
+ }
78
+
79
+ detectImports(code){
80
+ const regex = /@import\s+['"](.+?\.(css|scss))['"];?/g;
81
+ return regex.test(code);
82
+ }
83
+
84
+ writeCssFile(scssFilePath, cssContent) {
85
+ const cssFilePath = scssFilePath.replace('.scss', '.css');
86
+ let endCssFilePath = cssFilePath.split('/');
87
+ let endCssDir = [...endCssFilePath];
88
+ endCssDir[endCssDir.length - 1] = `${_COMPILE_DIR_NAME}`;
89
+ endCssDir = endCssDir.join('/');
90
+
91
+ if (!fs.existsSync(endCssDir)) {
92
+ fs.mkdirSync(endCssDir);
93
+ }
94
+
95
+ endCssFilePath[endCssFilePath.length - 1] = `${_COMPILE_DIR_NAME}/` + endCssFilePath[endCssFilePath.length - 1];
96
+ endCssFilePath = endCssFilePath.join('/');
97
+
98
+ fs.writeFileSync(endCssFilePath, cssContent);
99
+ log('Saved CSS file: ' + endCssFilePath);
100
+ }
101
+
102
+ hasFontEmbeds(css){
103
+ return FONT_REGEX.test()
104
+ }
105
+
106
+ embedFontsInCss(css, cssFilePath) {
107
+ let match;
108
+
109
+ while ((match = FONT_REGEX.exec(css)) !== null) {
110
+ const fontPath = match[1];
111
+ const absoluteFontPath = path.resolve(path.dirname(cssFilePath), fontPath);
112
+
113
+ if (fs.existsSync(absoluteFontPath)) {
114
+ const fontData = fs.readFileSync(absoluteFontPath);
115
+ const base64Font = fontData.toString('base64');
116
+ const fontMimeType = this.getFontMimeType(path.extname(absoluteFontPath));
117
+ const fontDataURL = `data:${fontMimeType};base64,${base64Font}`;
118
+
119
+ css = css.replace(new RegExp(match[0], 'g'), `url(${fontDataURL})`);
120
+ }
121
+ }
122
+
123
+ return css;
124
+ }
125
+
126
+ getFontMimeType(extension) {
127
+ switch (extension) {
128
+ case '.woff': return 'font/woff';
129
+ case '.woff2': return 'font/woff2';
130
+ case '.eot': return 'application/vnd.ms-fontobject';
131
+ case '.ttf': return 'font/ttf';
132
+ case '.otf': return 'font/otf';
133
+ default: return 'application/octet-stream';
134
+ }
135
+ }
136
+
137
+ apply(compiler) {
138
+ const _self = this;
139
+
140
+ return;
141
+
142
+ compiler.hooks.thisCompilation.tap('RWSSassPlugin', (compilation) => {
143
+ compilation.hooks.buildModule.tap('RWSSassPlugin', (module) => {
144
+ if (module.resource && /\.scss$/.test(module.resource)) {
145
+
146
+ let scssPath = module.resource;
147
+
148
+ this.compileFile(scssPath, true).catch((e) => {
149
+ throw e;
150
+ })
151
+ }
152
+ });
153
+ });
154
+ }
155
+
156
+ getCodeFromFile(filePath){
157
+ return fs.readFileSync(filePath, 'utf-8');
158
+ }
159
+
160
+ replaceWithNodeModules(input, fileDir, absolute = false, token = '~'){
161
+ return input.replace(token, absolute ? `${path.resolve(_tools.findRootWorkspacePath(process.cwd()), 'node_modules')}/` : this.node_modules_dir(fileDir));
162
+ }
163
+
164
+ compileFile(scssPath){
165
+ if(scssPath.split('')[0] === '~'){
166
+ scssPath = _self.replaceWithNodeModules(scssPath, path.dirname(scssPath));
167
+ }
168
+
169
+ const cwdRequest = scssPath.indexOf('@cwd');
170
+
171
+ if( cwdRequest > -1){
172
+ scssPath = process.cwd() + '/' + scssPath.slice(cwdRequest+1);
173
+ }
174
+
175
+ let scssCode = this.getCodeFromFile(scssPath);
176
+ return this.compileScssCode(scssCode, path.dirname(scssPath));
177
+ }
178
+
179
+ processImports(imports, fileRootDir, importStorage = {}, sub = false){
180
+ let finalCode = '';
181
+
182
+ const getStorage = (sourceComponentPath, importedFileContent) => {
183
+ const sourceComponentPathFormatted = sourceComponentPath.replace('/','_');
184
+
185
+ if(!(sourceComponentPathFormatted in importStorage)){
186
+ importStorage[sourceComponentPathFormatted] = importedFileContent;
187
+
188
+ return importedFileContent;
189
+ }
190
+
191
+ return '';
192
+ }
193
+
194
+ imports.forEach(originalImportPath => {
195
+ let importPath = originalImportPath;
196
+
197
+ // log(`Processing '${importPath}' import in: ` + fileRootDir);
198
+
199
+ if(originalImportPath.split('')[0] === '~'){
200
+ importPath = this.replaceWithNodeModules(importPath, path.dirname(fileRootDir), true);
201
+ }
202
+
203
+ const cwdRequest = originalImportPath.indexOf('@cwd');
204
+
205
+ if( cwdRequest > -1){
206
+ importPath = process.cwd() + '/' + originalImportPath.slice(cwdRequest+4);
207
+ }
208
+
209
+ // log(`Procesed '${importPath}' import to: ` + importPath);
210
+ importPath = path.resolve(fileRootDir, importPath);
211
+
212
+ const replacedScssContent = getStorage(importPath, this.getCodeFromFile(importPath).replace(/\/\*[\s\S]*?\*\//g, ''));
213
+
214
+
215
+ finalCode = replacedScssContent;
216
+
217
+ let recursiveCode = '';
218
+
219
+ if(this.detectImports(finalCode)){
220
+ recursiveCode = this.processImports(this.extractScssImports(finalCode)[0], fileRootDir, importStorage, true);
221
+
222
+
223
+ }
224
+
225
+
226
+ finalCode = recursiveCode + '\n' + finalCode;
227
+ finalCode = this.deleteImports(finalCode);
228
+
229
+ });
230
+
231
+ return finalCode;
232
+ }
233
+
234
+ deleteImports(code = '')
235
+ {
236
+ const delregex = /@import\s+['"].+\.(scss|css)['"];\s*/g;
237
+ return code.replace(delregex, '');
238
+ }
239
+
240
+ compileScssCode(scssCode, fileRootDir, createFile = false){
241
+ const _self = this;
242
+
243
+ // scssCode = this.replaceNodeModulesImport(scssCode, fileRootDir);
244
+
245
+
246
+ const [scssImports] = this.extractScssImports(scssCode);
247
+
248
+ let dotest = false;
249
+
250
+ if(fileRootDir.indexOf('chat-message') > -1){
251
+ dotest = true;
252
+ }
253
+
254
+ if(scssImports && scssImports.length){
255
+ scssCode = this.deleteImports(scssCode);
256
+ scssCode = this.processImports(scssImports, fileRootDir) + scssCode;
257
+ }
258
+
259
+ try {
260
+
261
+ // if(fileRootDir.indexOf('chat-message') > -1){
262
+ // log(`Processing 0 cnt '${fileRootDir}' import : \n`);
263
+
264
+ // console.log(scssCode);
265
+ // }
266
+
267
+ const result = sass.compileString(scssCode, { loadPaths: [fileRootDir] })
268
+
269
+
270
+ // if(fileRootDir.indexOf('chat-message') > -1){
271
+ // log(`Processing cnt '${fileRootDir}' import : \n` + result.css);
272
+ // }
273
+
274
+ let finalCss = result.css;
275
+
276
+ // Check for CSS imports
277
+ const [cssImports] = this.extractCssImports(scssCode);
278
+
279
+ if(cssImports && cssImports.length){
280
+ // finalCss = this.processImports(cssImports, fileRootDir);
281
+ }
282
+
283
+ cssImports.forEach(originalImportPath => {
284
+
285
+ let importPath = originalImportPath;
286
+
287
+ if(originalImportPath.split('')[0] === '~'){
288
+ //console.warn(`RWS Sass compiler did not find '${importPath}' from '${module.resource}' looking inside node_modules...`);
289
+ importPath = _self.replaceWithNodeModules(importPath, path.dirname(fileRootDir), true);
290
+
291
+ if(!fs.existsSync(importPath)){
292
+ throw new Error(`No ${importPath} found.`)
293
+ }
294
+ }
295
+
296
+ finalCss = finalCss.replace(/@import\s+['"](.+?)['"]\s*;/g, '');
297
+
298
+ const cssContent = _self.getCodeFromFile(importPath).replace(/\/\*[\s\S]*?\*\//g, '');
299
+
300
+ finalCss = cssContent + finalCss;
301
+
302
+ if(_self.hasFontEmbeds()){
303
+ finalCss = _self.embedFontsInCss(finalCss);
304
+ }
305
+ });
306
+
307
+ // if(createFile){
308
+ // this.writeCssFile(scssPath, finalCss);
309
+ // }
310
+
311
+ return finalCss;
312
+ } catch(err) {
313
+ console.error('SASS Error in', fileRootDir);
314
+ // console.log(err);
315
+ console.error(err);
316
+ throw err;
317
+ return '';
318
+ };
319
+ }
320
+
321
+ checkForImporterType(_module, checkTypeExt){
322
+ let importingFileExtension = '';
323
+
324
+ if (_module && _module.issuer && _module.issuer.resource) {
325
+ importingFileExtension = path.extname(_module.issuer.resource);
326
+ if(importingFileExtension === ('.' + checkTypeExt)){
327
+ return true;
328
+ }
329
+ }else{
330
+ return false;
331
+ }
332
+
333
+ return false
334
+ }
335
+ }
336
+
337
+ module.exports = RWSPlugin;