@rws-framework/client 2.8.5 → 2.9.0
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/cfg/build_steps/webpack/_aliases.js +10 -0
- package/cfg/build_steps/webpack/_info.js +19 -0
- package/cfg/build_steps/webpack/_loaders.js +40 -0
- package/cfg/build_steps/webpack/_rws_externals.js +66 -0
- package/cfg/tsconfigSetup.js +30 -10
- package/foundation/index.js +1 -0
- package/foundation/rws-foundation.d.ts +8 -0
- package/foundation/rws-foundation.js +8 -0
- package/package.json +5 -4
- package/rws.webpack.config.js +139 -145
- package/service_worker/src/_service_worker.ts +1 -1
- package/src/client/config.ts +10 -3
- package/src/client.ts +2 -2
- package/src/components/_attrs/external-observable.ts +72 -0
- package/src/components/_component.ts +4 -5
- package/src/components/_container.ts +4 -4
- package/src/components/_decorator.ts +39 -9
- package/src/components/_decorators/RWSFillBuild.ts +0 -1
- package/src/components/_decorators/RWSInject.ts +3 -3
- package/src/components/_decorators/_di.ts +2 -2
- package/src/index.d.ts +1 -0
- package/src/index.ts +5 -5
- package/src/plugins/_plugin.ts +1 -1
- package/src/services/ConfigService.ts +3 -1
- package/src/services/_service.ts +10 -7
- package/src/types/RWSWindow.ts +2 -1
- package/tsconfig.json +5 -1
- package/webpack/loaders/rws_fast_scss_loader.js +20 -3
- package/webpack/loaders/rws_fast_ts_loader.js +3 -2
- package/webpack/rws_after_plugin.js +26 -23
- package/webpack/rws_scss_plugin.js +7 -8
- package/_rws_externals.js +0 -39
- package/src/components/_design_system.ts +0 -6
- package/webpack/loaders/rws_fast_html_loader.js +0 -8
- package/webpack/loaders/rws_uncomments_loader.js +0 -35
package/src/client/config.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { RWSClientInstance } from "../client";
|
|
|
3
3
|
|
|
4
4
|
import { RWSPlugin, DefaultRWSPluginOptionsType } from "../plugins/_plugin";
|
|
5
5
|
import RWSWindow, {loadRWSRichWindow } from '../types/RWSWindow';
|
|
6
|
+
import deepmerge from 'deepmerge';
|
|
6
7
|
|
|
7
8
|
type RWSInfoType = { components: string[] };
|
|
8
9
|
|
|
@@ -89,12 +90,17 @@ function addPlugin<T extends DefaultRWSPluginOptionsType>(this: RWSClientInstan
|
|
|
89
90
|
async function setup(this: RWSClientInstance, config: IRWSConfig = {}): Promise<IRWSConfig> {
|
|
90
91
|
if (this.isSetup) {
|
|
91
92
|
return this.config;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if(this.config){
|
|
96
|
+
this.config = deepmerge(this.config, config);
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
|
|
99
|
+
console.log(config, this.config.plugins)
|
|
100
|
+
|
|
95
101
|
this.appConfig.mergeConfig(this.config);
|
|
96
102
|
|
|
97
|
-
if(this.config.plugins){
|
|
103
|
+
if(this.config.plugins){
|
|
98
104
|
for (const pluginEntry of this.config.plugins){
|
|
99
105
|
addPlugin.bind(this)(pluginEntry);
|
|
100
106
|
}
|
|
@@ -130,7 +136,8 @@ async function start(this: RWSClientInstance, config: IRWSConfig = {}): Promise<
|
|
|
130
136
|
await this.initCallback();
|
|
131
137
|
|
|
132
138
|
for (const plugin of RWSPlugin.getAllPlugins()){
|
|
133
|
-
|
|
139
|
+
console.log('plugin', plugin)
|
|
140
|
+
await plugin.onClientStart();
|
|
134
141
|
}
|
|
135
142
|
|
|
136
143
|
return this;
|
package/src/client.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { IBackendRoute } from './services/ApiService';
|
|
|
13
13
|
import IRWSUser from './types/IRWSUser';
|
|
14
14
|
import RWSWindow, { RWSWindowComponentRegister, loadRWSRichWindow } from './types/RWSWindow';
|
|
15
15
|
|
|
16
|
-
import { DI, Container, Registration } from '
|
|
16
|
+
import { DI, Container, Registration } from './components/_container';
|
|
17
17
|
|
|
18
18
|
import RWSViewComponent, { IWithCompose } from './components/_component';
|
|
19
19
|
import RWSContainer from './components/_container';
|
|
@@ -74,7 +74,7 @@ class RWSClient {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
addPlugin(pluginEntry: RWSPluginEntry<any>)
|
|
77
|
-
{
|
|
77
|
+
{
|
|
78
78
|
this.config.plugins.push(pluginEntry);
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Observable } from '@microsoft/fast-element';
|
|
2
|
+
import RWSViewComponent from '../_component';
|
|
3
|
+
import DOMService from '../../services/DOMService';
|
|
4
|
+
import RWSContainer from '../_container';
|
|
5
|
+
import { IOptions } from 'sanitize-html';
|
|
6
|
+
|
|
7
|
+
import * as he from 'he';
|
|
8
|
+
|
|
9
|
+
type SanitizeOptions = IOptions & { fullEncode?: boolean };
|
|
10
|
+
|
|
11
|
+
const heOpt: he.EncodeOptions = {
|
|
12
|
+
useNamedReferences: false,
|
|
13
|
+
encodeEverything: true,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function enc(html: string): string
|
|
17
|
+
{
|
|
18
|
+
return he.encode(html, heOpt);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const transformAnyTag = (tagName: string, attribs: { [key: string]: string }) => {
|
|
23
|
+
// Example: Wrap the original tag with `span` and indicate the original tag name in a data attribute
|
|
24
|
+
return {
|
|
25
|
+
tagName: 'span', // Change this to any tag you want to transform to
|
|
26
|
+
attribs: {
|
|
27
|
+
...attribs,
|
|
28
|
+
'data-original-tag': tagName
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function applyDecorator(target: RWSViewComponent, prop: string, config: SanitizeOptions = null): void
|
|
34
|
+
{
|
|
35
|
+
modifyPropertyDescriptor(target, prop, config as IOptions);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function modifyPropertyDescriptor(target: any, propertyKey: string, config: IOptions = null): void {
|
|
39
|
+
const privatePropName = `_${String(propertyKey)}`;
|
|
40
|
+
Object.defineProperty(target, privatePropName, {
|
|
41
|
+
writable: true,
|
|
42
|
+
value: target[propertyKey],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
Object.defineProperty(target, propertyKey, {
|
|
46
|
+
get() {
|
|
47
|
+
return this[privatePropName];
|
|
48
|
+
},
|
|
49
|
+
set(value: any) {
|
|
50
|
+
console.log('[DEBUG] external changed', propertyKey);
|
|
51
|
+
this[privatePropName] = value;
|
|
52
|
+
Observable.notify(this, propertyKey);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function externalAttr(configOrTarget?: SanitizeOptions | RWSViewComponent, prop?: string): void | any
|
|
58
|
+
{
|
|
59
|
+
if (arguments.length > 1) {
|
|
60
|
+
// Decorator used directly without factory invocation
|
|
61
|
+
// Apply the decorator immediately without returning anything
|
|
62
|
+
applyDecorator(configOrTarget as RWSViewComponent, prop!);
|
|
63
|
+
} else {
|
|
64
|
+
// Decorator factory invocation
|
|
65
|
+
const config = configOrTarget as SanitizeOptions;
|
|
66
|
+
// Return a function that applies the decorator, conforming to TypeScript's expectations for decorator factories
|
|
67
|
+
return (target: RWSViewComponent, property: string) => applyDecorator(target, property, config);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
export { externalAttr };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ViewTemplate, ElementStyles, observable, html, Constructable, PartialFASTElementDefinition, attr } from '@microsoft/fast-element';
|
|
2
|
-
import { FoundationElement, FoundationElementDefinition, FoundationElementRegistry, OverrideFoundationElementDefinition } from '
|
|
2
|
+
import { FoundationElement, FoundationElementDefinition, FoundationElementRegistry, OverrideFoundationElementDefinition } from '../../foundation/rws-foundation';
|
|
3
3
|
import ConfigService, { ConfigServiceInstance } from '../services/ConfigService';
|
|
4
4
|
import UtilsService, { UtilsServiceInstance } from '../services/UtilsService';
|
|
5
5
|
import DOMService, { DOMServiceInstance, DOMOutputType } from '../services/DOMService';
|
|
@@ -8,8 +8,7 @@ import NotifyService, { NotifyServiceInstance } from '../services/NotifyService'
|
|
|
8
8
|
import { IRWSViewComponent, IAssetShowOptions } from '../types/IRWSViewComponent';
|
|
9
9
|
import RWSWindow, { RWSWindowComponentInterface, loadRWSRichWindow } from '../types/RWSWindow';
|
|
10
10
|
import { applyConstructor, RWSInject } from './_decorator';
|
|
11
|
-
|
|
12
|
-
import 'reflect-metadata';
|
|
11
|
+
import TheRWSService from '../services/_service';
|
|
13
12
|
|
|
14
13
|
interface IFastDefinition {
|
|
15
14
|
name: string;
|
|
@@ -31,7 +30,7 @@ export interface IWithCompose<T extends RWSViewComponent> {
|
|
|
31
30
|
compose: ComposeMethodType<FoundationElementDefinition, Constructable<T>>;
|
|
32
31
|
define<TType extends (...params: any[]) => any>(type: TType, nameOrDef?: string | PartialFASTElementDefinition | undefined): TType;
|
|
33
32
|
_verbose: boolean;
|
|
34
|
-
_toInject: {[key: string]:
|
|
33
|
+
_toInject: {[key: string]: TheRWSService};
|
|
35
34
|
_depKeys: {[key: string]: string[]};
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -44,7 +43,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
|
|
|
44
43
|
|
|
45
44
|
static autoLoadFastElement = true;
|
|
46
45
|
static _defined: { [key: string]: boolean } = {};
|
|
47
|
-
static _toInject:
|
|
46
|
+
static _toInject: {[key: string]: TheRWSService} = {};
|
|
48
47
|
static _depKeys: {[key: string]: string[]} = {_all: []};
|
|
49
48
|
static _verbose: boolean = false;
|
|
50
49
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {DI, Container, Key, Registration , InterfaceSymbol} from '@microsoft/fast-foundation';
|
|
2
2
|
import {loadRWSRichWindow} from '../types/RWSWindow';
|
|
3
3
|
|
|
4
|
-
import 'reflect-metadata';
|
|
5
|
-
|
|
6
4
|
export default () => {
|
|
7
5
|
const richWindow = loadRWSRichWindow();
|
|
8
6
|
|
|
@@ -13,4 +11,6 @@ export default () => {
|
|
|
13
11
|
richWindow.RWS.container = DI.getOrCreateDOMContainer(richWindow.RWS.container_node);
|
|
14
12
|
|
|
15
13
|
return richWindow.RWS.container;
|
|
16
|
-
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { DI, Container, Key, Registration, InterfaceSymbol }
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import RWSContainer from './_container';
|
|
2
|
+
import TheRWSService from '../services/_service';
|
|
3
|
+
import ConfigService from '../services/ConfigService';
|
|
4
|
+
import { loadRWSRichWindow } from '../types/RWSWindow';
|
|
1
5
|
import RWSViewComponent, { IWithCompose } from './_component';
|
|
6
|
+
import { InterfaceSymbol } from './_container';
|
|
2
7
|
import { RWSInject } from './_decorators/RWSInject';
|
|
3
8
|
import { ElementStyles, ViewTemplate } from '@microsoft/fast-element';
|
|
4
|
-
import 'reflect-metadata';
|
|
5
9
|
|
|
6
10
|
interface RWSDecoratorOptions {
|
|
7
11
|
template?: string,
|
|
@@ -50,26 +54,52 @@ function getParentConstructor(instance: any): any {
|
|
|
50
54
|
return null;
|
|
51
55
|
}
|
|
52
56
|
|
|
57
|
+
|
|
53
58
|
const applyConstructor = (component: RWSViewComponent, x: boolean = false): void => {
|
|
54
59
|
const mainConstructor: any = component.constructor;
|
|
55
60
|
const parent = getParentConstructor(component);
|
|
61
|
+
|
|
56
62
|
|
|
57
63
|
if (parent.name !== 'RWSViewComponent' ) {
|
|
58
64
|
return;
|
|
59
65
|
}
|
|
66
|
+
|
|
60
67
|
|
|
61
68
|
const existingInjectedDependencies = (mainConstructor as IWithCompose<RWSViewComponent>)._toInject;
|
|
62
|
-
const defaultDeps = (mainConstructor as IWithCompose<RWSViewComponent>)._depKeys['_all'] || [];
|
|
63
|
-
const depsToInject = (mainConstructor as IWithCompose<RWSViewComponent>)._depKeys[mainConstructor.name] || [];
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
const regServices = loadRWSRichWindow().RWS._registered;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
const depsToInject: string[] = (mainConstructor as IWithCompose<RWSViewComponent>)._depKeys[mainConstructor.name] || [];
|
|
74
|
+
const depsInInjector: string[] = Object.keys(existingInjectedDependencies);
|
|
75
|
+
|
|
76
|
+
const toInject: string[] = [...depsToInject]
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
type KeyType = {[key: string]: TheRWSService | string };
|
|
79
|
+
|
|
80
|
+
function inject(services: KeyType){
|
|
81
|
+
for (const prop in services) {
|
|
82
|
+
const service = (typeof services[prop] === 'string' ? existingInjectedDependencies[prop] : services[prop]) as TheRWSService;
|
|
83
|
+
(component as any)[prop] = service;
|
|
71
84
|
}
|
|
72
|
-
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
inject(toInject.reduce((acc: KeyType, cur) => {
|
|
88
|
+
acc[cur] = cur;
|
|
89
|
+
return acc;
|
|
90
|
+
}, {}));
|
|
91
|
+
|
|
92
|
+
const defaultDeps: [string, TheRWSService][] = Object.keys(existingInjectedDependencies)
|
|
93
|
+
.filter((depKey: string) => existingInjectedDependencies[depKey].isDefault()).map((depKey => [depKey, existingInjectedDependencies[depKey]]));
|
|
94
|
+
|
|
95
|
+
inject(defaultDeps.reduce((acc: KeyType, cur: [string, TheRWSService]) => {
|
|
96
|
+
acc[cur[0]] = cur[1];
|
|
97
|
+
return acc;
|
|
98
|
+
}, {}));
|
|
99
|
+
|
|
100
|
+
inject({
|
|
101
|
+
config: RWSContainer().get(ConfigService)
|
|
102
|
+
})
|
|
73
103
|
};
|
|
74
104
|
|
|
75
105
|
export { RWSView, RWSDecoratorOptions, RWSIgnore, RWSInject, applyConstructor };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Key } from '
|
|
1
|
+
import { Key } from '../_container';
|
|
2
2
|
import RWSViewComponent, { IWithCompose } from '../_component';
|
|
3
3
|
import { loadDep, getFunctionParamNames } from './_di';
|
|
4
4
|
import TheRWSService from '../../services/_service';
|
|
@@ -24,7 +24,7 @@ function addToComponentInjection(targetComponentName: string, constructor: any,
|
|
|
24
24
|
if(!Object.keys(constructor._toInject).includes(depKey)){
|
|
25
25
|
const loadedDependency = loadDep<TheRWSService>(dependencyClass);
|
|
26
26
|
constructor._toInject[depKey] = loadedDependency;
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function RWSInject<T extends RWSViewComponent>(dependencyClass: Key, defaultService: boolean = false): InjectDecoratorReturnType {
|
|
@@ -40,7 +40,7 @@ function RWSInject<T extends RWSViewComponent>(dependencyClass: Key, defaultServ
|
|
|
40
40
|
const depKey = paramNames[parameterIndex];
|
|
41
41
|
|
|
42
42
|
addToComponentInjection(targetConstructor.name, targetConstructor, depKey, dependencyClass, defaultService);
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import RWSContainer from '../_container';
|
|
1
|
+
|
|
2
|
+
import RWSContainer, { Key } from '../_container';
|
|
3
3
|
|
|
4
4
|
function getFunctionParamNames(func: () => any): string[] {
|
|
5
5
|
const constructorMatch = func.toString().match(/constructor\s*\(([^)]*)\)/);
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../types/declarations"
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Transformer as HTMLTagTransformerType, Tag as HTMLTag, Attributes as HT
|
|
|
2
2
|
import { observable, attr } from '@microsoft/fast-element';
|
|
3
3
|
import IRWSConfig from './types/IRWSConfig';
|
|
4
4
|
import RWSNotify, { NotifyUiType, NotifyLogType } from './types/RWSNotify';
|
|
5
|
-
import { provideRWSDesignSystem } from './components/_design_system';
|
|
6
5
|
import RWSService from './services/_service';
|
|
7
6
|
import ConfigService, { ConfigServiceInstance } from './services/ConfigService';
|
|
8
7
|
import NotifyService, {NotifyServiceInstance} from './services/NotifyService';
|
|
@@ -12,6 +11,7 @@ import UtilsService, {UtilsServiceInstance} from './services/UtilsService';
|
|
|
12
11
|
import ServiceWorkerService, { ServiceWorkerServiceInstance } from './services/ServiceWorkerService';
|
|
13
12
|
import { sanitizedAttr } from './components/_attrs/sanitize-html';
|
|
14
13
|
import { ngAttr } from './components/_attrs/angular-attr';
|
|
14
|
+
import { externalAttr } from './components/_attrs/external-observable';
|
|
15
15
|
import { RWSPlugin, DefaultRWSPluginOptionsType } from './plugins/_plugin';
|
|
16
16
|
import RWSClient, { RWSClientInstance } from './client';
|
|
17
17
|
import { RWSPluginEntry } from './types/IRWSConfig';
|
|
@@ -67,14 +67,14 @@ export {
|
|
|
67
67
|
RWSView,
|
|
68
68
|
sanitizedAttr,
|
|
69
69
|
RWSIgnore,
|
|
70
|
-
RWSInject,
|
|
71
|
-
ngAttr,
|
|
70
|
+
RWSInject,
|
|
72
71
|
observable,
|
|
72
|
+
externalAttr,
|
|
73
73
|
attr,
|
|
74
|
+
ngAttr,
|
|
74
75
|
|
|
75
76
|
RWSService,
|
|
76
|
-
RWSViewComponent,
|
|
77
|
-
provideRWSDesignSystem,
|
|
77
|
+
RWSViewComponent,
|
|
78
78
|
declareRWSComponents,
|
|
79
79
|
|
|
80
80
|
RWSContainer
|
package/src/plugins/_plugin.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import RWSContainer from "../components/_container";
|
|
2
|
-
import { Container } from "
|
|
2
|
+
import { Container } from "../components/_container";
|
|
3
3
|
import RWSWindow, {loadRWSRichWindow } from '../types/RWSWindow';
|
|
4
4
|
import IRWSUser from "../types/IRWSUser";
|
|
5
5
|
import { RWSInfoType } from "../client/components";
|
|
@@ -124,6 +124,8 @@ class ConfigService extends TheService {
|
|
|
124
124
|
if(unloaded){
|
|
125
125
|
ConfigService.isLoaded = true;
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
return this.data;
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
getData(): IRWSConfig
|
|
@@ -132,6 +134,6 @@ class ConfigService extends TheService {
|
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
export default ConfigService.getSingleton();
|
|
137
|
+
export default ConfigService.getSingleton('ConfigService');
|
|
136
138
|
|
|
137
139
|
export { ConfigService as ConfigServiceInstance };
|
package/src/services/_service.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DI, InterfaceSymbol, Key, Registration } from '
|
|
2
|
-
import RWSContainer from '../components/_container';
|
|
1
|
+
import RWSContainer, { DI, InterfaceSymbol, Key, Registration } from '../components/_container';
|
|
3
2
|
import { loadRWSRichWindow } from '../types/RWSWindow';
|
|
4
3
|
|
|
5
4
|
export interface IWithDI<T> {
|
|
@@ -31,21 +30,25 @@ export default abstract class TheRWSService {
|
|
|
31
30
|
this.getSingleton();
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
public static getSingleton<T extends Key>(this: IWithDI<T
|
|
33
|
+
public static getSingleton<T extends Key>(this: IWithDI<T>, serviceName: string = null): InterfaceSymbol<T>
|
|
35
34
|
{
|
|
36
35
|
const richWindow = loadRWSRichWindow();
|
|
37
36
|
|
|
38
|
-
if(
|
|
39
|
-
|
|
37
|
+
if(!serviceName){
|
|
38
|
+
serviceName = this.name;
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
if(Object.keys(richWindow.RWS._registered).includes(serviceName)){
|
|
42
|
+
return richWindow.RWS._registered[serviceName];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const interf = DI.createInterface<T>(serviceName);
|
|
43
46
|
|
|
44
47
|
RWSContainer().register(
|
|
45
48
|
Registration.singleton(interf, this)
|
|
46
49
|
);
|
|
47
50
|
|
|
48
|
-
richWindow.RWS._registered[
|
|
51
|
+
richWindow.RWS._registered[serviceName] = interf;
|
|
49
52
|
|
|
50
53
|
return interf;
|
|
51
54
|
}
|
package/src/types/RWSWindow.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RWSClientInstance } from '../client';
|
|
2
|
-
import { Container, InterfaceSymbol } from '
|
|
2
|
+
import { Container, InterfaceSymbol } from '../components/_container';
|
|
3
|
+
|
|
3
4
|
import { RWSPlugin, DefaultRWSPluginOptionsType } from '../plugins/_plugin';
|
|
4
5
|
import { v1 as uuid} from 'uuid';
|
|
5
6
|
export type RWSWindowComponentInterface = (params?: any) => void;
|
package/tsconfig.json
CHANGED
|
@@ -18,10 +18,14 @@
|
|
|
18
18
|
"lib": ["DOM", "ESNext"],
|
|
19
19
|
},
|
|
20
20
|
"paths": {
|
|
21
|
-
"@rws-framework/client": ["src"]
|
|
21
|
+
"@rws-framework/client": ["src"],
|
|
22
|
+
"@rws-framework/foundation": ["foundation"]
|
|
22
23
|
},
|
|
23
24
|
"include": [
|
|
24
25
|
"src",
|
|
25
26
|
"types/docs-typings.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"exclude": [
|
|
29
|
+
"node_modules"
|
|
26
30
|
]
|
|
27
31
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
const RWSCssPlugin = require("../rws_scss_plugin");
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const cssLoader = require('css-loader');
|
|
4
|
+
// const { css } = require('@microsoft/fast-element')
|
|
5
|
+
|
|
6
|
+
// function makeFastResource(context, code){
|
|
7
|
+
// return function(){ return css`${code}`; }.bind(context)();
|
|
8
|
+
// }
|
|
4
9
|
|
|
5
10
|
module.exports = function(content) {
|
|
6
|
-
const callback = this.async();
|
|
7
11
|
const plugin = new RWSCssPlugin();
|
|
8
12
|
const filePath = this.resourcePath;
|
|
9
13
|
|
|
@@ -19,13 +23,26 @@ module.exports = function(content) {
|
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
try {
|
|
22
|
-
const
|
|
26
|
+
const codeData = plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
|
|
27
|
+
|
|
28
|
+
const code = codeData.code;
|
|
29
|
+
const deps = codeData.dependencies;
|
|
30
|
+
|
|
31
|
+
for (const dependency of deps){
|
|
32
|
+
this.addDependency(dependency);
|
|
33
|
+
}
|
|
23
34
|
|
|
24
35
|
if (fromTs && saveFile && code) {
|
|
25
36
|
plugin.writeCssFile(filePath, code);
|
|
26
37
|
}
|
|
27
38
|
|
|
39
|
+
// if(!fromTs){
|
|
40
|
+
// return (context) => makeFastResource(context, code);
|
|
41
|
+
// }
|
|
42
|
+
|
|
28
43
|
// Properly setup the context for css-loader
|
|
44
|
+
|
|
45
|
+
const callback = this.async();
|
|
29
46
|
const loaderContext = {
|
|
30
47
|
...this,
|
|
31
48
|
query: { sourceMap: isDev },
|
|
@@ -39,7 +56,7 @@ module.exports = function(content) {
|
|
|
39
56
|
};
|
|
40
57
|
|
|
41
58
|
// Execute css-loader with the generated CSS code
|
|
42
|
-
cssLoader.call(loaderContext, code);
|
|
59
|
+
cssLoader.call(loaderContext, code);
|
|
43
60
|
|
|
44
61
|
} catch (e) {
|
|
45
62
|
console.error(e);
|
|
@@ -84,10 +84,11 @@ module.exports = async function(content) {
|
|
|
84
84
|
let template = 'const rwsTemplate: null = null;';
|
|
85
85
|
|
|
86
86
|
if(templateExists){
|
|
87
|
+
const templateContent = fs.readFileSync(templatePath);
|
|
87
88
|
htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport RWSTemplateHTML from './${templateName}.html';`;
|
|
88
89
|
this.addDependency(templatePath);
|
|
89
|
-
template = `
|
|
90
|
-
let rwsTemplate: any = T.html
|
|
90
|
+
template = `
|
|
91
|
+
let rwsTemplate: any = T.html\`${templateContent}\`;
|
|
91
92
|
`;
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const rwsAfterCopy = require('./after/copy');
|
|
2
2
|
const rwsAfterSW = require('./after/sw');
|
|
3
|
+
const deepmerge = require('deepmerge');
|
|
3
4
|
|
|
4
5
|
|
|
5
|
-
const _DEFAULT_CONFIG = {actions: [], executionDir: process.cwd(), packageDir: process.cwd()}
|
|
6
|
+
const _DEFAULT_CONFIG = {actions: [], executionDir: process.cwd(), packageDir: process.cwd(), dev: false}
|
|
6
7
|
|
|
7
8
|
const _DEFAULT_ACTION = {
|
|
8
9
|
type: 'copy',
|
|
@@ -20,7 +21,7 @@ class RWSAfterPlugin {
|
|
|
20
21
|
_allowedActionTypes = ['copy', 'custom', 'service_worker'];
|
|
21
22
|
|
|
22
23
|
constructor(config = {}){
|
|
23
|
-
this.config =
|
|
24
|
+
this.config = deepmerge(this.config, config);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
apply(compiler) {
|
|
@@ -34,29 +35,31 @@ class RWSAfterPlugin {
|
|
|
34
35
|
|
|
35
36
|
return await Promise.all(proms);
|
|
36
37
|
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
compiler.hooks.emit.tapAsync('RWSAfterPlugin', (compilation, callback) => {
|
|
40
|
-
Object.keys(compilation.assets).forEach((filename) => {
|
|
41
|
-
|
|
42
|
-
if (filename.endsWith('.js')) {
|
|
43
|
-
const asset = compilation.assets[filename];
|
|
44
|
-
let source = asset.source();
|
|
45
|
-
if(source.indexOf('css`') > -1 || source.indexOf('html`') > -1){
|
|
46
|
-
console.log('replacing', filename);
|
|
47
|
-
const updatedSource = source.replace(/\n/g, '');
|
|
38
|
+
});
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
if(!this.config.dev){
|
|
41
|
+
compiler.hooks.emit.tapAsync('RWSAfterPlugin', (compilation, callback) => {
|
|
42
|
+
Object.keys(compilation.assets).forEach((filename) => {
|
|
43
|
+
|
|
44
|
+
if (filename.endsWith('.js')) {
|
|
45
|
+
const asset = compilation.assets[filename];
|
|
46
|
+
let source = asset.source();
|
|
47
|
+
|
|
48
|
+
if((source.indexOf('css`') > -1 || source.indexOf('html`') > -1)){
|
|
49
|
+
const updatedSource = source.replace(/\n/g, '');
|
|
50
|
+
|
|
51
|
+
// Update the asset with the new content
|
|
52
|
+
compilation.assets[filename] = {
|
|
53
|
+
source: () => updatedSource,
|
|
54
|
+
size: () => updatedSource.length
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
callback();
|
|
56
61
|
});
|
|
57
|
-
|
|
58
|
-
callback();
|
|
59
|
-
});
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
async _runActionType(actionType, action){
|
|
@@ -48,7 +48,9 @@ class RWSScssPlugin {
|
|
|
48
48
|
importRootPath = path.dirname(importRootPath);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
const processedImportPath = this.processImportPath(importPath, importRootPath);
|
|
52
|
+
|
|
53
|
+
imports.push([processedImportPath, importLine, path.resolve(processedImportPath)]);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
return [imports, fileContent];
|
|
@@ -251,9 +253,6 @@ class RWSScssPlugin {
|
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
replaceFontUrlWithBase64(cssContent) {
|
|
254
|
-
const urlRegex = /url\(([^)]+)\)/g;
|
|
255
|
-
let match;
|
|
256
|
-
|
|
257
256
|
const fontFaceRegex = /@font-face\s*\{[^}]*\}/g;
|
|
258
257
|
let fontFaces = [...cssContent.matchAll(fontFaceRegex)];
|
|
259
258
|
|
|
@@ -350,6 +349,8 @@ class RWSScssPlugin {
|
|
|
350
349
|
const _self = this;
|
|
351
350
|
const [scssImports] = this.extractScssImports(scssCode, fileRootDir);
|
|
352
351
|
|
|
352
|
+
const dependencies = scssImports.map((item) => item[2]);
|
|
353
|
+
|
|
353
354
|
if (scssImports && scssImports.length) {
|
|
354
355
|
scssCode = this.replaceImports(this.processImports(scssImports, fileRootDir), scssCode);
|
|
355
356
|
}
|
|
@@ -372,11 +373,9 @@ class RWSScssPlugin {
|
|
|
372
373
|
scssCode = scssUses + scssCode;
|
|
373
374
|
|
|
374
375
|
try {
|
|
376
|
+
const result = sass.compileString(scssCode, { loadPaths: [fileRootDir]});
|
|
375
377
|
|
|
376
|
-
|
|
377
|
-
let finalCss = result.css.toString();
|
|
378
|
-
|
|
379
|
-
return this.replaceFontUrlWithBase64(finalCss);
|
|
378
|
+
return { code: this.replaceFontUrlWithBase64(result.css.toString()), dependencies};
|
|
380
379
|
} catch (err) {
|
|
381
380
|
console.error('SASS Error in', fileRootDir);
|
|
382
381
|
|
package/_rws_externals.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const tools = require('./_tools');
|
|
5
|
-
|
|
6
|
-
const _defaultOpts = {
|
|
7
|
-
inc_list_context: [],
|
|
8
|
-
inc_list: [],
|
|
9
|
-
not_inc_list: [],
|
|
10
|
-
not_inc_list_context: ['@rws-framework/client', 'node_modules'],
|
|
11
|
-
exceptions: [],
|
|
12
|
-
exceptions_context: [],
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const moduleDir = path.resolve(path.dirname(module.id));
|
|
16
|
-
const nodeModules = path.resolve(tools.findRootWorkspacePath(process.cwd()), '/node_modules');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const externals = (declaredCodeBase, nodeModules, externalOptions = _defaultOpts) => ({context, request}, callback) => {
|
|
20
|
-
let theOptions = _defaultOpts;
|
|
21
|
-
|
|
22
|
-
if(externalOptions !== null){
|
|
23
|
-
theOptions = Object.assign(theOptions, externalOptions);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const codeBase = path.resolve(declaredCodeBase);
|
|
27
|
-
|
|
28
|
-
let mergeTarget = true;
|
|
29
|
-
|
|
30
|
-
if (mergeTarget) {
|
|
31
|
-
//merging to output
|
|
32
|
-
return callback();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//using require from node_modules
|
|
36
|
-
callback(null, 'commonjs ' + request);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = {rwsExternals: externals, _externalsDefaults: _defaultOpts};
|