@rws-framework/client 2.9.4 → 2.9.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.
- package/package.json +1 -1
- package/src/client.ts +2 -1
- package/src/components/_attrs/_default_observable_accessor.ts +2 -2
- package/src/components/_attrs/_extended_accessor.ts +9 -3
- package/src/components/_attrs/_external_handler.ts +8 -0
- package/src/components/_attrs/_external_observable_accessor.ts +2 -2
- package/src/components/_attrs/angular-attr.ts +33 -66
- package/src/components/_attrs/external-attr.ts +60 -3
- package/src/components/_attrs/external-observable.ts +5 -1
- package/src/components/_component.ts +36 -21
- package/src/components/_decorator.ts +21 -3
- package/src/components/_decorators/RWSInject.ts +2 -1
- package/src/index.ts +2 -0
- package/src/plugins/_plugin.ts +2 -1
- package/src/types/IRWSConfig.ts +3 -3
- package/src/types/IRWSPlugin.ts +19 -0
- package/webpack/loaders/rws_fast_ts_loader.js +1 -1
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -23,6 +23,7 @@ import ComponentHelper, { ComponentHelperStatic, RWSInfoType } from './client/co
|
|
|
23
23
|
import ServicesHelper from './client/services';
|
|
24
24
|
import ConfigHelper from './client/config';
|
|
25
25
|
import { DefaultRWSPluginOptionsType, RWSPlugin } from './plugins/_plugin';
|
|
26
|
+
import { IStaticRWSPlugin } from './types/IRWSPlugin'
|
|
26
27
|
|
|
27
28
|
interface IHotModule extends NodeModule {
|
|
28
29
|
hot?: {
|
|
@@ -73,7 +74,7 @@ class RWSClient {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
addPlugin<T extends DefaultRWSPluginOptionsType>(pluginEntry:
|
|
77
|
+
addPlugin<T extends DefaultRWSPluginOptionsType>(pluginEntry: IStaticRWSPlugin)
|
|
77
78
|
{
|
|
78
79
|
this.config.plugins.push(pluginEntry);
|
|
79
80
|
}
|
|
@@ -3,7 +3,7 @@ import { ExtendedObservableAccessor } from "./_extended_accessor";
|
|
|
3
3
|
|
|
4
4
|
export class DefaultObservableAccessor extends ExtendedObservableAccessor {
|
|
5
5
|
|
|
6
|
-
constructor(public name: string, protected watcher: any = void 0) {
|
|
7
|
-
super(name, watcher);
|
|
6
|
+
constructor(public name: string, protected customGet: (source: any, field: string) => any = null, protected customSet: (source: any, field: string, newVal: any) => boolean | void = null, protected watcher: any = void 0, suffix: string = 'Changed') {
|
|
7
|
+
super(name, customGet, customSet, watcher, suffix);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -2,9 +2,9 @@ import { Observable, Accessor } from "@microsoft/fast-element";
|
|
|
2
2
|
|
|
3
3
|
export abstract class ExtendedObservableAccessor implements Accessor {
|
|
4
4
|
protected field: string;
|
|
5
|
-
protected callback: string;
|
|
5
|
+
protected callback: string;
|
|
6
6
|
|
|
7
|
-
constructor(public name: string, protected watcher: any = void 0, suffix: string = 'Changed') {
|
|
7
|
+
constructor(public name: string, protected customGet: (source: any, field: string) => any = null, protected customSet: (source: any, field: string, newVal: any) => boolean | void = null, protected watcher: any = void 0, suffix: string = 'Changed') {
|
|
8
8
|
this.field = `_${name}`;
|
|
9
9
|
this.callback = `${name}${suffix}`;
|
|
10
10
|
}
|
|
@@ -12,10 +12,16 @@ export abstract class ExtendedObservableAccessor implements Accessor {
|
|
|
12
12
|
getValue(source: any): any {
|
|
13
13
|
Observable.track(source, this.name);
|
|
14
14
|
|
|
15
|
-
return source[this.field];
|
|
15
|
+
return this.customGet ? this.customGet(source, this.field) : source[this.field];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
setValue(source: any, newValue: any): void {
|
|
19
|
+
if(this.customSet){
|
|
20
|
+
if(this.customSet(source, this.field, newValue) === false){
|
|
21
|
+
return;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
const field = this.field;
|
|
20
26
|
const oldValue = source[field];
|
|
21
27
|
|
|
@@ -3,7 +3,7 @@ import { ExtendedObservableAccessor } from "./_extended_accessor";
|
|
|
3
3
|
|
|
4
4
|
export class ExternalObservableAccessor extends ExtendedObservableAccessor {
|
|
5
5
|
|
|
6
|
-
constructor(public name: string, protected watcher: any = void 0) {
|
|
7
|
-
super(name,
|
|
6
|
+
constructor(public name: string, protected customGet: (source: any, field: string) => any = null, protected customSet: (source: any, field: string, newVal: any) => boolean | void = null, protected watcher: any = void 0) {
|
|
7
|
+
super(name, customGet, customSet, watcher, '');
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,67 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Observable.track(target, propertyKey);
|
|
36
|
-
|
|
37
|
-
Object.defineProperty(target, privatePropName, {
|
|
38
|
-
writable: true,
|
|
39
|
-
value: target[propertyKey],
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
Object.defineProperty(target, propertyKey, {
|
|
43
|
-
get() {
|
|
44
|
-
const value: string = this[privatePropName];
|
|
45
|
-
|
|
46
|
-
return isNgValue(value) ? null : value;
|
|
47
|
-
},
|
|
48
|
-
set(value: any) {
|
|
49
|
-
if (typeof value === 'string' && isNgValue(value)) {
|
|
50
|
-
this[privatePropName] = null; // Set to null if condition is met
|
|
51
|
-
} else {
|
|
52
|
-
this[privatePropName] = value;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
DecoratorAttributeConfiguration,
|
|
3
|
+
AttributeConfiguration,
|
|
4
|
+
Observable,
|
|
5
|
+
} from "@microsoft/fast-element";
|
|
6
|
+
import { handleExternalChange } from "./_external_handler";
|
|
7
|
+
import RWSViewComponent, { IWithCompose } from "../_component";
|
|
8
|
+
import { externalAttr } from "./external-attr";
|
|
9
|
+
|
|
10
|
+
export function ngAttr(
|
|
11
|
+
config?: DecoratorAttributeConfiguration
|
|
12
|
+
): (target: {}, property: string) => void;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Decorator: Specifies an HTML attribute.
|
|
16
|
+
* @param target - The class to define the attribute on.
|
|
17
|
+
* @param prop - The property name to be associated with the attribute.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export function ngAttr(target: {}, prop: string): void;
|
|
21
|
+
export function ngAttr(
|
|
22
|
+
configOrTarget?: DecoratorAttributeConfiguration | {},
|
|
23
|
+
prop?: string
|
|
24
|
+
): void | ((target: {}, property: string) => void) {
|
|
25
|
+
return externalAttr(configOrTarget, prop, {
|
|
26
|
+
converter: (val: any) => {
|
|
27
|
+
if(val && val.indexOf('{{') > -1){
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return val;
|
|
32
|
+
}
|
|
33
|
+
})
|
|
56
34
|
}
|
|
57
|
-
|
|
58
|
-
function isNgValue(input: string): boolean {
|
|
59
|
-
// Regular expression to match AngularJS template variable notation
|
|
60
|
-
const angularJsVariablePattern = /\{\{([^}]+)\}\}/;
|
|
61
|
-
|
|
62
|
-
// Test the input string for the pattern and return the result
|
|
63
|
-
return angularJsVariablePattern.test(input);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export { ngAttr };
|
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
DecoratorAttributeConfiguration,
|
|
3
|
+
AttributeConfiguration,
|
|
4
|
+
Observable,
|
|
5
|
+
} from "@microsoft/fast-element";
|
|
6
|
+
import { handleExternalChange } from "./_external_handler";
|
|
7
|
+
import RWSViewComponent, { IWithCompose } from "../_component";
|
|
8
|
+
|
|
9
|
+
type ExAttrOpts = { converter?: (val: any) => string }
|
|
10
|
+
const _default_opts = {
|
|
11
|
+
converter: (val: any) => {
|
|
12
|
+
return val;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function externalAttr(
|
|
17
|
+
config?: DecoratorAttributeConfiguration,
|
|
18
|
+
): (target: {}, property: string) => void;
|
|
19
|
+
|
|
20
|
+
export function externalAttr(target: {}, property: string, opts?: ExAttrOpts): void;
|
|
21
|
+
export function externalAttr(
|
|
22
|
+
configOrTarget?: DecoratorAttributeConfiguration | {},
|
|
23
|
+
property?: string,
|
|
24
|
+
opts: ExAttrOpts = _default_opts
|
|
25
|
+
): void | ((target: {}, property: string) => void) {
|
|
26
|
+
let config: AttributeConfiguration;
|
|
27
|
+
|
|
28
|
+
function decorator($target: {}, $prop: string): void {
|
|
29
|
+
if (arguments.length > 1) {
|
|
30
|
+
// Non invocation:
|
|
31
|
+
// - @attr
|
|
32
|
+
// Invocation with or w/o opts:
|
|
33
|
+
// - @attr()
|
|
34
|
+
// - @attr({...opts})
|
|
35
|
+
config.property = $prop;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
config.mode = 'fromView';
|
|
39
|
+
config.converter = { fromView: opts.converter, toView: null };
|
|
40
|
+
|
|
41
|
+
const attrs = AttributeConfiguration.locate($target.constructor);
|
|
42
|
+
RWSViewComponent.setExternalAttr(($target.constructor as IWithCompose<any>).name, $prop);
|
|
43
|
+
|
|
44
|
+
attrs.push(config);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (arguments.length > 1) {
|
|
48
|
+
// Non invocation:
|
|
49
|
+
// - @attr
|
|
50
|
+
config = {} as any;
|
|
51
|
+
decorator(configOrTarget!, property!);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Invocation with or w/o opts:
|
|
56
|
+
// - @attr()
|
|
57
|
+
// - @attr({...opts})
|
|
58
|
+
config = configOrTarget === void 0 ? ({} as any) : configOrTarget;
|
|
59
|
+
return decorator;
|
|
60
|
+
}
|
|
@@ -38,8 +38,12 @@ function externalObservable(targetComponent: RWSViewComponent | unknown, nameOrA
|
|
|
38
38
|
get(this: any) {
|
|
39
39
|
return accessor.getValue(this);
|
|
40
40
|
},
|
|
41
|
-
set(this: any, newValue: any) {
|
|
41
|
+
set(this: any, newValue: any) {
|
|
42
|
+
const oldVal = accessor.getValue(this);
|
|
42
43
|
accessor.setValue(this, newValue);
|
|
44
|
+
if(!!this['externalChanged']){
|
|
45
|
+
this['externalChanged'].call(accessor.name, oldVal, newValue);
|
|
46
|
+
}
|
|
43
47
|
},
|
|
44
48
|
});
|
|
45
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ViewTemplate, ElementStyles, observable, html, Constructable, PartialFASTElementDefinition, attr } from '@microsoft/fast-element';
|
|
1
|
+
import { ViewTemplate, ElementStyles, observable, html, Constructable, PartialFASTElementDefinition, attr, Observable } from '@microsoft/fast-element';
|
|
2
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';
|
|
@@ -9,6 +9,7 @@ import { IRWSViewComponent, IAssetShowOptions } from '../types/IRWSViewComponent
|
|
|
9
9
|
import RWSWindow, { RWSWindowComponentInterface, loadRWSRichWindow } from '../types/RWSWindow';
|
|
10
10
|
import { applyConstructor, RWSInject } from './_decorator';
|
|
11
11
|
import TheRWSService from '../services/_service';
|
|
12
|
+
import { handleExternalChange } from './_attrs/_external_handler';
|
|
12
13
|
|
|
13
14
|
interface IFastDefinition {
|
|
14
15
|
name: string;
|
|
@@ -32,10 +33,13 @@ export interface IWithCompose<T extends RWSViewComponent> {
|
|
|
32
33
|
_verbose: boolean;
|
|
33
34
|
_toInject: {[key: string]: TheRWSService};
|
|
34
35
|
_depKeys: {[key: string]: string[]};
|
|
36
|
+
_externalAttrs: { [key:string]: string[] };
|
|
37
|
+
setExternalAttr: (componentName: string, key: string) => void
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
abstract class RWSViewComponent extends FoundationElement implements IRWSViewComponent {
|
|
38
41
|
__isLoading: boolean = true;
|
|
42
|
+
__exAttrLoaded: string[] = [];
|
|
39
43
|
private static instances: RWSViewComponent[] = [];
|
|
40
44
|
static fileList: string[] = [];
|
|
41
45
|
|
|
@@ -45,6 +49,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
|
|
|
45
49
|
static _defined: { [key: string]: boolean } = {};
|
|
46
50
|
static _toInject: {[key: string]: TheRWSService} = {};
|
|
47
51
|
static _depKeys: {[key: string]: string[]} = {_all: []};
|
|
52
|
+
static _externalAttrs: { [key: string]: string[] } = {};
|
|
48
53
|
static _verbose: boolean = false;
|
|
49
54
|
|
|
50
55
|
@RWSInject(ConfigService, true) protected config: ConfigServiceInstance;
|
|
@@ -60,34 +65,18 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
|
|
|
60
65
|
|
|
61
66
|
constructor() {
|
|
62
67
|
super();
|
|
63
|
-
applyConstructor(this);
|
|
64
|
-
|
|
68
|
+
applyConstructor(this);
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
connectedCallback() {
|
|
68
72
|
super.connectedCallback();
|
|
69
|
-
applyConstructor(this);
|
|
70
|
-
|
|
71
|
-
// console.trace(this.config);
|
|
72
|
-
// console.log(this.routingService);
|
|
73
|
+
applyConstructor(this);
|
|
74
|
+
|
|
73
75
|
if (!(this.constructor as IWithCompose<this>).definition && (this.constructor as IWithCompose<this>).autoLoadFastElement) {
|
|
74
76
|
throw new Error('RWS component is not named. Add `static definition = {name, template};`');
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
(this.constructor as IWithCompose<this>).fileList.forEach((file: string) => {
|
|
79
|
-
if (this.fileAssets[file]) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this.apiService.pureGet(this.config.get('pubUrlFilePrefix') + file).then((response: string) => {
|
|
83
|
-
this.fileAssets = { ...this.fileAssets, [file]: html`${response}` };
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
} catch (e: Error | any) {
|
|
88
|
-
console.error('Error loading file content:', e.message);
|
|
89
|
-
console.error(e.stack);
|
|
90
|
-
}
|
|
79
|
+
this.applyFileList();
|
|
91
80
|
|
|
92
81
|
RWSViewComponent.instances.push(this);
|
|
93
82
|
}
|
|
@@ -214,6 +203,32 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
|
|
|
214
203
|
this.$emit(eventName, event);
|
|
215
204
|
}
|
|
216
205
|
|
|
206
|
+
private applyFileList(): void
|
|
207
|
+
{
|
|
208
|
+
try {
|
|
209
|
+
(this.constructor as IWithCompose<this>).fileList.forEach((file: string) => {
|
|
210
|
+
if (this.fileAssets[file]) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
this.apiService.pureGet(this.config.get('pubUrlFilePrefix') + file).then((response: string) => {
|
|
214
|
+
this.fileAssets = { ...this.fileAssets, [file]: html`${response}` };
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
} catch (e: Error | any) {
|
|
219
|
+
console.error('Error loading file content:', e.message);
|
|
220
|
+
console.error(e.stack);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static setExternalAttr(componentName: string, key: string)
|
|
225
|
+
{
|
|
226
|
+
if(!Object.keys(RWSViewComponent._externalAttrs).includes(componentName)){
|
|
227
|
+
RWSViewComponent._externalAttrs[componentName] = [];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
RWSViewComponent._externalAttrs[componentName].push(key);
|
|
231
|
+
}
|
|
217
232
|
|
|
218
233
|
static hotReplacedCallback() {
|
|
219
234
|
this.getInstances().forEach(instance => instance.forceReload());
|
|
@@ -5,7 +5,8 @@ import { loadRWSRichWindow } from '../types/RWSWindow';
|
|
|
5
5
|
import RWSViewComponent, { IWithCompose } from './_component';
|
|
6
6
|
import { InterfaceSymbol } from './_container';
|
|
7
7
|
import { RWSInject } from './_decorators/RWSInject';
|
|
8
|
-
import { ElementStyles, ViewTemplate } from '@microsoft/fast-element';
|
|
8
|
+
import { ElementStyles, Observable, ViewTemplate } from '@microsoft/fast-element';
|
|
9
|
+
import { handleExternalChange } from './_attrs/_external_handler';
|
|
9
10
|
|
|
10
11
|
interface RWSDecoratorOptions {
|
|
11
12
|
template?: string,
|
|
@@ -36,7 +37,7 @@ function RWSView<Component extends RWSViewComponent>(name: string, data?: RWSDec
|
|
|
36
37
|
if(override.options){
|
|
37
38
|
(theComponent.definition as any).options = override.options;
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
+
}
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -77,10 +78,12 @@ const applyConstructor = (component: RWSViewComponent, x: boolean = false): void
|
|
|
77
78
|
|
|
78
79
|
type KeyType = {[key: string]: TheRWSService | string };
|
|
79
80
|
|
|
81
|
+
const _target = (component as any);
|
|
82
|
+
|
|
80
83
|
function inject(services: KeyType){
|
|
81
84
|
for (const prop in services) {
|
|
82
85
|
const service = (typeof services[prop] === 'string' ? existingInjectedDependencies[prop] : services[prop]) as TheRWSService;
|
|
83
|
-
|
|
86
|
+
_target[prop] = service;
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
|
|
@@ -100,6 +103,21 @@ const applyConstructor = (component: RWSViewComponent, x: boolean = false): void
|
|
|
100
103
|
inject({
|
|
101
104
|
config: RWSContainer().get(ConfigService)
|
|
102
105
|
})
|
|
106
|
+
|
|
107
|
+
if(Object.keys(RWSViewComponent._externalAttrs).includes((_target.constructor as IWithCompose<any>).name)){
|
|
108
|
+
for(const exAttrKey in RWSViewComponent._externalAttrs[(_target.constructor as IWithCompose<any>).name]){
|
|
109
|
+
const exAttr = RWSViewComponent._externalAttrs[(_target.constructor as IWithCompose<any>).name][exAttrKey];
|
|
110
|
+
const notifier = Observable.getNotifier(_target);
|
|
111
|
+
notifier.subscribe({
|
|
112
|
+
handleChange(source, key) {
|
|
113
|
+
if (key === exAttr && !_target.__exAttrLoaded.includes(exAttr)) {
|
|
114
|
+
handleExternalChange(source, key);
|
|
115
|
+
_target.__exAttrLoaded.push(key);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}, exAttr);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
103
121
|
};
|
|
104
122
|
|
|
105
123
|
export { RWSView, RWSDecoratorOptions, RWSIgnore, RWSInject, applyConstructor };
|
|
@@ -2,6 +2,7 @@ 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';
|
|
5
|
+
import { handleExternalChange } from '../_attrs/_external_handler';
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
type InjectDecoratorReturnType = (target: any, key?: string | number | undefined, parameterIndex?: number) => void;
|
|
@@ -40,7 +41,7 @@ function RWSInject<T extends RWSViewComponent>(dependencyClass: Key, defaultServ
|
|
|
40
41
|
const depKey = paramNames[parameterIndex];
|
|
41
42
|
|
|
42
43
|
addToComponentInjection(targetConstructor.name, targetConstructor, depKey, dependencyClass, defaultService);
|
|
43
|
-
}
|
|
44
|
+
}
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { ngAttr } from './components/_attrs/angular-attr';
|
|
|
14
14
|
import { externalObservable } from './components/_attrs/external-observable';
|
|
15
15
|
import { externalAttr } from './components/_attrs/external-attr';
|
|
16
16
|
import { RWSPlugin, DefaultRWSPluginOptionsType } from './plugins/_plugin';
|
|
17
|
+
import { IRWSPlugin, IStaticRWSPlugin } from './types/IRWSPlugin';
|
|
17
18
|
import RWSClient, { RWSClientInstance } from './client';
|
|
18
19
|
import { RWSPluginEntry } from './types/IRWSConfig';
|
|
19
20
|
import IRWSUser from './types/IRWSUser';
|
|
@@ -33,6 +34,7 @@ export {
|
|
|
33
34
|
|
|
34
35
|
RWSPlugin,
|
|
35
36
|
RWSPluginEntry,
|
|
37
|
+
IRWSPlugin, IStaticRWSPlugin,
|
|
36
38
|
DefaultRWSPluginOptionsType,
|
|
37
39
|
|
|
38
40
|
NotifyUiType,
|
package/src/plugins/_plugin.ts
CHANGED
|
@@ -3,11 +3,12 @@ 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";
|
|
6
|
+
import { IRWSPlugin } from "../types/IRWSPlugin";
|
|
6
7
|
|
|
7
8
|
type DefaultRWSPluginOptionsType = { enabled: boolean };
|
|
8
9
|
type PluginInfoType = { name: string }
|
|
9
10
|
type PluginConstructor<T extends DefaultRWSPluginOptionsType> = new (options: T) => RWSPlugin<T>;
|
|
10
|
-
abstract class RWSPlugin<PluginOptions extends DefaultRWSPluginOptionsType> {
|
|
11
|
+
abstract class RWSPlugin<PluginOptions extends DefaultRWSPluginOptionsType> implements IRWSPlugin{
|
|
11
12
|
protected isLoaded: boolean = false;
|
|
12
13
|
protected options: PluginOptions;
|
|
13
14
|
protected container: Container;
|
package/src/types/IRWSConfig.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import RWSViewComponent from '../components/_component';
|
|
2
2
|
import { RWSPlugin, DefaultRWSPluginOptionsType } from '../plugins/_plugin';
|
|
3
|
+
import { IStaticRWSPlugin } from '../types/IRWSPlugin';
|
|
3
4
|
|
|
4
5
|
export type IFrontRoutes = Record<string, unknown>;
|
|
5
|
-
export type
|
|
6
|
-
export type RWSPluginEntry<T extends DefaultRWSPluginOptionsType> = PluginConstructor<T> | [PluginConstructor<T>, T];
|
|
6
|
+
export type RWSPluginEntry<T extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType> = new (...args: any[]) => RWSPlugin<T>;
|
|
7
7
|
|
|
8
8
|
export default interface IRWSConfig {
|
|
9
9
|
dev?: boolean
|
|
@@ -23,7 +23,7 @@ export default interface IRWSConfig {
|
|
|
23
23
|
parted?: boolean
|
|
24
24
|
partedFileDir?: string
|
|
25
25
|
partedPrefix?: string
|
|
26
|
-
plugins?:
|
|
26
|
+
plugins?: IStaticRWSPlugin[]
|
|
27
27
|
routing_enabled?: boolean
|
|
28
28
|
_noLoad?: boolean
|
|
29
29
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DefaultRWSPluginOptionsType } from "../plugins/_plugin";
|
|
2
|
+
import IRWSUser from "./IRWSUser";
|
|
3
|
+
import { Container } from "../components/_container";
|
|
4
|
+
import RWSWindow from "../types/RWSWindow";
|
|
5
|
+
import { RWSInfoType } from "../client/components";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export interface IRWSPlugin {
|
|
9
|
+
onClientStart(): Promise<void>
|
|
10
|
+
onPartedComponentsLoad(componentParts: RWSInfoType): Promise<void>
|
|
11
|
+
onComponentsDeclare(): Promise<void>
|
|
12
|
+
onSetUser(user: IRWSUser): Promise<void>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IStaticRWSPlugin<PluginOptions extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType> {
|
|
16
|
+
new (...args: any[]): IRWSPlugin;
|
|
17
|
+
container: Container;
|
|
18
|
+
window: RWSWindow;
|
|
19
|
+
}
|
|
@@ -95,7 +95,7 @@ module.exports = async function(content) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
if(templateExists){
|
|
98
|
-
const templateContent = fs.readFileSync(templatePath, 'utf-8');
|
|
98
|
+
const templateContent = fs.readFileSync(templatePath, 'utf-8').replace(/<!--[\s\S]*?-->/g, '');
|
|
99
99
|
htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport './${templateName}.html';\n`;
|
|
100
100
|
template = `
|
|
101
101
|
//@ts-ignore
|