@rws-framework/client 2.20.1 → 2.20.2
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/.bin/emerge.sh +15 -15
- package/builder/vite/index.ts +4 -4
- package/builder/vite/rws.vite.config.ts +132 -132
- package/builder/vite/rws_scss_plugin.ts +61 -61
- package/builder/webpack/index.js +10 -10
- package/builder/webpack/rws.webpack.config.js +161 -161
- package/builder/webpack/rws_scss_plugin.js +90 -90
- package/builder/webpack/rws_webpack_plugin.js +137 -137
- package/cfg/_default.cfg.js +26 -26
- package/cfg/_storage.d.ts +22 -22
- package/cfg/_storage.js +42 -42
- package/cfg/tsconfigSetup.js +146 -146
- package/docs/assets/26e93147f10415a0ed4a.svg +6 -6
- package/docs/assets/75c9471662e97ee24f29.svg +7 -7
- package/docs/assets/db90e4df2373980c497d.svg +9 -9
- package/docs/assets/highlight.css +127 -127
- package/docs/assets/main.js +59 -59
- package/docs/assets/style.css +1414 -1414
- package/docs/classes/ApiServiceInstance.html +25 -25
- package/docs/classes/ConfigServiceInstance.html +21 -21
- package/docs/classes/DOMServiceInstance.html +17 -17
- package/docs/classes/NotifyServiceInstance.html +15 -15
- package/docs/classes/RWSClientInstance.html +45 -45
- package/docs/classes/RWSPlugin.html +13 -13
- package/docs/classes/RWSService.html +10 -10
- package/docs/classes/RWSViewComponent.html +1022 -1022
- package/docs/classes/ServiceWorkerServiceInstance.html +13 -13
- package/docs/classes/UtilsServiceInstance.html +13 -13
- package/docs/functions/attr.html +5 -5
- package/docs/functions/observable.html +3 -3
- package/docs/index.html +179 -179
- package/docs/interfaces/HTMLTag.html +3 -3
- package/docs/interfaces/IRWSConfig.html +20 -20
- package/docs/interfaces/IRWSDecoratorOptions.html +5 -5
- package/docs/interfaces/IRWSHttpRoute.html +2 -2
- package/docs/interfaces/IRWSPrefixedHTTProutes.html +2 -2
- package/docs/interfaces/IRWSUser.html +5 -5
- package/docs/modules.html +45 -45
- package/foundation/index.js +1 -1
- package/foundation/rws-foundation.d.ts +7 -7
- package/foundation/rws-foundation.js +7 -7
- package/package.json +1 -1
- package/service_worker/src/_service_worker.ts +83 -83
- package/service_worker/tsconfig.json +20 -20
- package/service_worker/webpack.config.js +66 -66
- package/src/client/components.ts +67 -67
- package/src/client/config.ts +175 -175
- package/src/client/hotReload.ts +22 -22
- package/src/client/services.ts +27 -27
- package/src/client.ts +208 -208
- package/src/components/_component.ts +247 -247
- package/src/components/_container.ts +15 -15
- package/src/components/_decorator.ts +122 -122
- package/src/components/_definitions.ts +64 -64
- package/src/components/_event_handling.ts +40 -40
- package/src/components/index.ts +25 -25
- package/src/index.ts +86 -86
- package/src/plugins/_builder.js +31 -31
- package/src/plugins/_plugin.ts +60 -60
- package/src/services/ApiService.ts +105 -105
- package/src/services/ConfigService.ts +125 -125
- package/src/services/DOMService.ts +93 -93
- package/src/services/NotifyService.ts +47 -47
- package/src/services/ServiceWorkerService.ts +60 -60
- package/src/services/UtilsService.ts +60 -60
- package/src/services/_service.ts +64 -64
- package/src/styles/README.md +157 -157
- package/src/styles/_darkreader.scss +30 -30
- package/src/styles/_grid.scss +75 -75
- package/src/styles/_grid_legacy.scss +49 -49
- package/src/styles/_misc.scss +8 -8
- package/src/styles/_scrollbars.scss +40 -40
- package/src/styles/includes.scss +6 -6
- package/src/types/IBackendCore.ts +11 -11
- package/src/types/IRWSConfig.ts +29 -29
- package/src/types/IRWSPlugin.ts +23 -23
- package/src/types/IRWSResource.ts +4 -4
- package/src/types/IRWSUser.ts +6 -6
- package/src/types/IRWSViewComponent.ts +36 -36
- package/src/types/IReFormerField.ts +4 -4
- package/src/types/RWSNotify.ts +6 -6
- package/src/types/RWSWindow.ts +41 -41
- package/types/declarations.d.ts +8 -8
- package/types/docs-typings.d.ts +15 -15
|
@@ -1,248 +1,248 @@
|
|
|
1
|
-
import { ViewTemplate, ElementStyles, observable, html, Constructable, PartialFASTElementDefinition, attr, Observable } from '@microsoft/fast-element';
|
|
2
|
-
import { FoundationElement, FoundationElementDefinition, FoundationElementRegistry, OverrideFoundationElementDefinition } from '../../foundation/rws-foundation';
|
|
3
|
-
import ConfigService, { ConfigServiceInstance } from '../services/ConfigService';
|
|
4
|
-
import UtilsService, { UtilsServiceInstance } from '../services/UtilsService';
|
|
5
|
-
import DOMService, { DOMServiceInstance, DOMOutputType } from '../services/DOMService';
|
|
6
|
-
import ApiService, { ApiServiceInstance } from '../services/ApiService';
|
|
7
|
-
import NotifyService, { NotifyServiceInstance } from '../services/NotifyService';
|
|
8
|
-
import { IRWSViewComponent, IAssetShowOptions } from '../types/IRWSViewComponent';
|
|
9
|
-
import RWSWindow, { RWSWindowComponentInterface, loadRWSRichWindow } from '../types/RWSWindow';
|
|
10
|
-
import { applyConstructor, RWSInject } from './_decorator';
|
|
11
|
-
import TheRWSService from '../services/_service';
|
|
12
|
-
import { handleExternalChange } from './_attrs/_external_handler';
|
|
13
|
-
import { IFastDefinition, isDefined, defineComponent, getDefinition } from './_definitions';
|
|
14
|
-
import { on, $emitDown, observe, sendEventToOutside } from './_event_handling';
|
|
15
|
-
|
|
16
|
-
type ComposeMethodType<
|
|
17
|
-
T extends FoundationElementDefinition,
|
|
18
|
-
K extends Constructable<RWSViewComponent>
|
|
19
|
-
> = (this: K, elementDefinition: T) => (overrideDefinition?: OverrideFoundationElementDefinition<T>) => FoundationElementRegistry<FoundationElementDefinition, T>;
|
|
20
|
-
|
|
21
|
-
export interface IWithCompose<T extends RWSViewComponent> {
|
|
22
|
-
[key: string]: any
|
|
23
|
-
new (...args: any[]): T;
|
|
24
|
-
definition?: IFastDefinition
|
|
25
|
-
defineComponent: <T extends RWSViewComponent>(this: IWithCompose<T>) => void
|
|
26
|
-
isDefined<T extends RWSViewComponent>(this: IWithCompose<T>): boolean
|
|
27
|
-
compose: ComposeMethodType<FoundationElementDefinition, Constructable<T>>;
|
|
28
|
-
define<TType extends (...params: any[]) => any>(type: TType, nameOrDef?: string | PartialFASTElementDefinition | undefined): TType;
|
|
29
|
-
_verbose: boolean;
|
|
30
|
-
_toInject: {[key: string]: TheRWSService};
|
|
31
|
-
_depKeys: {[key: string]: string[]};
|
|
32
|
-
_externalAttrs: { [key:string]: string[] };
|
|
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
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
abstract class RWSViewComponent extends FoundationElement implements IRWSViewComponent {
|
|
42
|
-
__isLoading: boolean = true;
|
|
43
|
-
__exAttrLoaded: string[] = [];
|
|
44
|
-
private static instances: RWSViewComponent[] = [];
|
|
45
|
-
static fileList: string[] = [];
|
|
46
|
-
|
|
47
|
-
@attr routeParams: Record<string, string> = {};
|
|
48
|
-
|
|
49
|
-
static autoLoadFastElement = true;
|
|
50
|
-
static _defined: { [key: string]: boolean } = {};
|
|
51
|
-
static _toInject: {[key: string]: TheRWSService} = {};
|
|
52
|
-
static _depKeys: {[key: string]: string[]} = {_all: []};
|
|
53
|
-
static _externalAttrs: { [key: string]: string[] } = {};
|
|
54
|
-
static _verbose: boolean = false;
|
|
55
|
-
|
|
56
|
-
static _EVENTS = {
|
|
57
|
-
component_define: 'rws:lifecycle:defineComponent',
|
|
58
|
-
component_parted_load: 'rws:lifecycle:loadPartedComponents',
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@RWSInject(ConfigService, true) protected config: ConfigServiceInstance;
|
|
62
|
-
@RWSInject(DOMService, true) protected domService: DOMServiceInstance;
|
|
63
|
-
@RWSInject(UtilsService, true) protected utilsService: UtilsServiceInstance;
|
|
64
|
-
@RWSInject(ApiService, true) protected apiService: ApiServiceInstance;
|
|
65
|
-
@RWSInject(NotifyService, true) protected notifyService: NotifyServiceInstance;
|
|
66
|
-
|
|
67
|
-
@observable trashIterator: number = 0;
|
|
68
|
-
@observable fileAssets: {
|
|
69
|
-
[key: string]: ViewTemplate
|
|
70
|
-
} = {};
|
|
71
|
-
|
|
72
|
-
constructor() {
|
|
73
|
-
super();
|
|
74
|
-
applyConstructor(this);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
connectedCallback() {
|
|
78
|
-
super.connectedCallback();
|
|
79
|
-
applyConstructor(this);
|
|
80
|
-
|
|
81
|
-
if (!(this.constructor as IWithCompose<this>).definition && (this.constructor as IWithCompose<this>).autoLoadFastElement) {
|
|
82
|
-
throw new Error('RWS component is not named. Add `static definition = {name, template};`');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this.applyFileList();
|
|
86
|
-
|
|
87
|
-
RWSViewComponent.instances.push(this);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
passRouteParams(routeParams: Record<string, string> = null) {
|
|
91
|
-
if (routeParams) {
|
|
92
|
-
this.routeParams = routeParams;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
showAsset(assetName: string, options: IAssetShowOptions = {}): ViewTemplate<any, any> {
|
|
97
|
-
|
|
98
|
-
if (!this.fileAssets[assetName]) {
|
|
99
|
-
return html`<span></span>`;
|
|
100
|
-
throw new Error(`File asset "${assetName}" not declared in component "${(this.constructor as IWithCompose<this>).definition.name}"`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return this.fileAssets[assetName];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
on<T>(type: string, listener: (event: CustomEvent<T>) => any) {
|
|
107
|
-
return on.bind(this)(type, listener);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
$emitDown<T>(eventName: string, payload: T) {
|
|
111
|
-
return $emitDown.bind(this)(eventName, payload);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
observe(callback: (component: RWSViewComponent, node: Node, observer: MutationObserver) => Promise<void>, condition: (component: RWSViewComponent, node: Node) => boolean = null, observeRemoved: boolean = false)
|
|
115
|
-
{
|
|
116
|
-
return observe.bind(this)(callback, condition, observeRemoved);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
parse$<T extends Element>(input: NodeListOf<T>, directReturn: boolean = false): DOMOutputType<T> {
|
|
120
|
-
return this.domService.parse$<T>(input, directReturn);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
$<T extends Element>(selectors: string, directReturn: boolean = false): DOMOutputType<T> {
|
|
124
|
-
return this.domService.$<T>(this.getShadowRoot(), selectors, directReturn);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async loadingString<T, C>(item: T, addContent: (cnt: C | { output: string }, paste?: boolean, error?: boolean) => void, shouldStop: (stopItem: T, addContent: (cnt: C | { output: string }, paste?: boolean, error?: boolean) => void) => Promise<boolean>) {
|
|
128
|
-
let dots = 1;
|
|
129
|
-
const maxDots = 3; // Maximum number of dots
|
|
130
|
-
const interval = setInterval(async () => {
|
|
131
|
-
const dotsString = '. '.repeat(dots);
|
|
132
|
-
|
|
133
|
-
const doesItStop = await shouldStop(item, addContent);
|
|
134
|
-
|
|
135
|
-
if (doesItStop) {
|
|
136
|
-
addContent({ output: '' }, true);
|
|
137
|
-
clearInterval(interval);
|
|
138
|
-
} else {
|
|
139
|
-
addContent({ output: `${dotsString}` }, true);
|
|
140
|
-
|
|
141
|
-
dots = (dots % (maxDots)) + 1;
|
|
142
|
-
}
|
|
143
|
-
}, 500);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async onDOMLoad(): Promise<void> {
|
|
147
|
-
return new Promise<void>((resolve) => {
|
|
148
|
-
if (this.getShadowRoot() !== null && this.getShadowRoot() !== undefined) {
|
|
149
|
-
resolve();
|
|
150
|
-
} else {
|
|
151
|
-
// If shadowRoot is not yet available, use MutationObserver to wait for it
|
|
152
|
-
const observer = new MutationObserver(() => {
|
|
153
|
-
if (this.getShadowRoot() !== null && this.getShadowRoot() !== undefined) {
|
|
154
|
-
observer.disconnect();
|
|
155
|
-
resolve();
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
observer.observe(this, { childList: true, subtree: true });
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
protected getShadowRoot(): ShadowRoot {
|
|
165
|
-
const shRoot: ShadowRoot | null = this.shadowRoot;
|
|
166
|
-
|
|
167
|
-
if (!shRoot) {
|
|
168
|
-
throw new Error(`Component ${(this.constructor as IWithCompose<this>).definition.name} lacks shadow root. If you wish to have component without shadow root extend your class with FASTElement`);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return shRoot;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
forceReload() {
|
|
175
|
-
this.trashIterator += 1;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
hotReplacedCallback() {
|
|
179
|
-
this.forceReload();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
sendEventToOutside<T>(eventName: string, data: T) {
|
|
183
|
-
sendEventToOutside(eventName, data);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
static sendEventToOutside<T>(eventName: string, data: T) {
|
|
187
|
-
sendEventToOutside(eventName, data);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
private applyFileList(): void
|
|
191
|
-
{
|
|
192
|
-
try {
|
|
193
|
-
(this.constructor as IWithCompose<this>).fileList.forEach((file: string) => {
|
|
194
|
-
if (this.fileAssets[file]) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
this.apiService.pureGet(this.config.get('pubUrlFilePrefix') + file).then((response: string) => {
|
|
198
|
-
this.fileAssets = { ...this.fileAssets, [file]: html`${response}` };
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
} catch (e: Error | any) {
|
|
203
|
-
console.error('Error loading file content:', e.message);
|
|
204
|
-
console.error(e.stack);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
static setExternalAttr(componentName: string, key: string)
|
|
209
|
-
{
|
|
210
|
-
if(!Object.keys(RWSViewComponent._externalAttrs).includes(componentName)){
|
|
211
|
-
RWSViewComponent._externalAttrs[componentName] = [];
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
RWSViewComponent._externalAttrs[componentName].push(key);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
static hotReplacedCallback() {
|
|
218
|
-
this.getInstances().forEach(instance => instance.forceReload());
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
static isDefined<T extends RWSViewComponent>(this: IWithCompose<T>): boolean
|
|
222
|
-
{
|
|
223
|
-
return isDefined<T>(this);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
static defineComponent<T extends RWSViewComponent>(this: IWithCompose<T>): void
|
|
227
|
-
{
|
|
228
|
-
return defineComponent<T>(this);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
static getDefinition(tagName: string, htmlTemplate: ViewTemplate, styles: ElementStyles = null)
|
|
232
|
-
{
|
|
233
|
-
return getDefinition(tagName, htmlTemplate, styles);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
private static getInstances(): RWSViewComponent[] {
|
|
237
|
-
return RWSViewComponent.instances;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export default RWSViewComponent;
|
|
242
|
-
|
|
243
|
-
export { RWSViewComponent };
|
|
244
|
-
|
|
245
|
-
export type {
|
|
246
|
-
IAssetShowOptions,
|
|
247
|
-
IRWSViewComponent
|
|
1
|
+
import { ViewTemplate, ElementStyles, observable, html, Constructable, PartialFASTElementDefinition, attr, Observable } from '@microsoft/fast-element';
|
|
2
|
+
import { FoundationElement, FoundationElementDefinition, FoundationElementRegistry, OverrideFoundationElementDefinition } from '../../foundation/rws-foundation';
|
|
3
|
+
import ConfigService, { ConfigServiceInstance } from '../services/ConfigService';
|
|
4
|
+
import UtilsService, { UtilsServiceInstance } from '../services/UtilsService';
|
|
5
|
+
import DOMService, { DOMServiceInstance, DOMOutputType } from '../services/DOMService';
|
|
6
|
+
import ApiService, { ApiServiceInstance } from '../services/ApiService';
|
|
7
|
+
import NotifyService, { NotifyServiceInstance } from '../services/NotifyService';
|
|
8
|
+
import { IRWSViewComponent, IAssetShowOptions } from '../types/IRWSViewComponent';
|
|
9
|
+
import RWSWindow, { RWSWindowComponentInterface, loadRWSRichWindow } from '../types/RWSWindow';
|
|
10
|
+
import { applyConstructor, RWSInject } from './_decorator';
|
|
11
|
+
import TheRWSService from '../services/_service';
|
|
12
|
+
import { handleExternalChange } from './_attrs/_external_handler';
|
|
13
|
+
import { IFastDefinition, isDefined, defineComponent, getDefinition } from './_definitions';
|
|
14
|
+
import { on, $emitDown, observe, sendEventToOutside } from './_event_handling';
|
|
15
|
+
|
|
16
|
+
type ComposeMethodType<
|
|
17
|
+
T extends FoundationElementDefinition,
|
|
18
|
+
K extends Constructable<RWSViewComponent>
|
|
19
|
+
> = (this: K, elementDefinition: T) => (overrideDefinition?: OverrideFoundationElementDefinition<T>) => FoundationElementRegistry<FoundationElementDefinition, T>;
|
|
20
|
+
|
|
21
|
+
export interface IWithCompose<T extends RWSViewComponent> {
|
|
22
|
+
[key: string]: any
|
|
23
|
+
new (...args: any[]): T;
|
|
24
|
+
definition?: IFastDefinition
|
|
25
|
+
defineComponent: <T extends RWSViewComponent>(this: IWithCompose<T>) => void
|
|
26
|
+
isDefined<T extends RWSViewComponent>(this: IWithCompose<T>): boolean
|
|
27
|
+
compose: ComposeMethodType<FoundationElementDefinition, Constructable<T>>;
|
|
28
|
+
define<TType extends (...params: any[]) => any>(type: TType, nameOrDef?: string | PartialFASTElementDefinition | undefined): TType;
|
|
29
|
+
_verbose: boolean;
|
|
30
|
+
_toInject: {[key: string]: TheRWSService};
|
|
31
|
+
_depKeys: {[key: string]: string[]};
|
|
32
|
+
_externalAttrs: { [key:string]: string[] };
|
|
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
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
abstract class RWSViewComponent extends FoundationElement implements IRWSViewComponent {
|
|
42
|
+
__isLoading: boolean = true;
|
|
43
|
+
__exAttrLoaded: string[] = [];
|
|
44
|
+
private static instances: RWSViewComponent[] = [];
|
|
45
|
+
static fileList: string[] = [];
|
|
46
|
+
|
|
47
|
+
@attr routeParams: Record<string, string> = {};
|
|
48
|
+
|
|
49
|
+
static autoLoadFastElement = true;
|
|
50
|
+
static _defined: { [key: string]: boolean } = {};
|
|
51
|
+
static _toInject: {[key: string]: TheRWSService} = {};
|
|
52
|
+
static _depKeys: {[key: string]: string[]} = {_all: []};
|
|
53
|
+
static _externalAttrs: { [key: string]: string[] } = {};
|
|
54
|
+
static _verbose: boolean = false;
|
|
55
|
+
|
|
56
|
+
static _EVENTS = {
|
|
57
|
+
component_define: 'rws:lifecycle:defineComponent',
|
|
58
|
+
component_parted_load: 'rws:lifecycle:loadPartedComponents',
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@RWSInject(ConfigService, true) protected config: ConfigServiceInstance;
|
|
62
|
+
@RWSInject(DOMService, true) protected domService: DOMServiceInstance;
|
|
63
|
+
@RWSInject(UtilsService, true) protected utilsService: UtilsServiceInstance;
|
|
64
|
+
@RWSInject(ApiService, true) protected apiService: ApiServiceInstance;
|
|
65
|
+
@RWSInject(NotifyService, true) protected notifyService: NotifyServiceInstance;
|
|
66
|
+
|
|
67
|
+
@observable trashIterator: number = 0;
|
|
68
|
+
@observable fileAssets: {
|
|
69
|
+
[key: string]: ViewTemplate
|
|
70
|
+
} = {};
|
|
71
|
+
|
|
72
|
+
constructor() {
|
|
73
|
+
super();
|
|
74
|
+
applyConstructor(this);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
connectedCallback() {
|
|
78
|
+
super.connectedCallback();
|
|
79
|
+
applyConstructor(this);
|
|
80
|
+
|
|
81
|
+
if (!(this.constructor as IWithCompose<this>).definition && (this.constructor as IWithCompose<this>).autoLoadFastElement) {
|
|
82
|
+
throw new Error('RWS component is not named. Add `static definition = {name, template};`');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.applyFileList();
|
|
86
|
+
|
|
87
|
+
RWSViewComponent.instances.push(this);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
passRouteParams(routeParams: Record<string, string> = null) {
|
|
91
|
+
if (routeParams) {
|
|
92
|
+
this.routeParams = routeParams;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
showAsset(assetName: string, options: IAssetShowOptions = {}): ViewTemplate<any, any> {
|
|
97
|
+
|
|
98
|
+
if (!this.fileAssets[assetName]) {
|
|
99
|
+
return html`<span></span>`;
|
|
100
|
+
throw new Error(`File asset "${assetName}" not declared in component "${(this.constructor as IWithCompose<this>).definition.name}"`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return this.fileAssets[assetName];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
on<T>(type: string, listener: (event: CustomEvent<T>) => any) {
|
|
107
|
+
return on.bind(this)(type, listener);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
$emitDown<T>(eventName: string, payload: T) {
|
|
111
|
+
return $emitDown.bind(this)(eventName, payload);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
observe(callback: (component: RWSViewComponent, node: Node, observer: MutationObserver) => Promise<void>, condition: (component: RWSViewComponent, node: Node) => boolean = null, observeRemoved: boolean = false)
|
|
115
|
+
{
|
|
116
|
+
return observe.bind(this)(callback, condition, observeRemoved);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
parse$<T extends Element>(input: NodeListOf<T>, directReturn: boolean = false): DOMOutputType<T> {
|
|
120
|
+
return this.domService.parse$<T>(input, directReturn);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
$<T extends Element>(selectors: string, directReturn: boolean = false): DOMOutputType<T> {
|
|
124
|
+
return this.domService.$<T>(this.getShadowRoot(), selectors, directReturn);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async loadingString<T, C>(item: T, addContent: (cnt: C | { output: string }, paste?: boolean, error?: boolean) => void, shouldStop: (stopItem: T, addContent: (cnt: C | { output: string }, paste?: boolean, error?: boolean) => void) => Promise<boolean>) {
|
|
128
|
+
let dots = 1;
|
|
129
|
+
const maxDots = 3; // Maximum number of dots
|
|
130
|
+
const interval = setInterval(async () => {
|
|
131
|
+
const dotsString = '. '.repeat(dots);
|
|
132
|
+
|
|
133
|
+
const doesItStop = await shouldStop(item, addContent);
|
|
134
|
+
|
|
135
|
+
if (doesItStop) {
|
|
136
|
+
addContent({ output: '' }, true);
|
|
137
|
+
clearInterval(interval);
|
|
138
|
+
} else {
|
|
139
|
+
addContent({ output: `${dotsString}` }, true);
|
|
140
|
+
|
|
141
|
+
dots = (dots % (maxDots)) + 1;
|
|
142
|
+
}
|
|
143
|
+
}, 500);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async onDOMLoad(): Promise<void> {
|
|
147
|
+
return new Promise<void>((resolve) => {
|
|
148
|
+
if (this.getShadowRoot() !== null && this.getShadowRoot() !== undefined) {
|
|
149
|
+
resolve();
|
|
150
|
+
} else {
|
|
151
|
+
// If shadowRoot is not yet available, use MutationObserver to wait for it
|
|
152
|
+
const observer = new MutationObserver(() => {
|
|
153
|
+
if (this.getShadowRoot() !== null && this.getShadowRoot() !== undefined) {
|
|
154
|
+
observer.disconnect();
|
|
155
|
+
resolve();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
observer.observe(this, { childList: true, subtree: true });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
protected getShadowRoot(): ShadowRoot {
|
|
165
|
+
const shRoot: ShadowRoot | null = this.shadowRoot;
|
|
166
|
+
|
|
167
|
+
if (!shRoot) {
|
|
168
|
+
throw new Error(`Component ${(this.constructor as IWithCompose<this>).definition.name} lacks shadow root. If you wish to have component without shadow root extend your class with FASTElement`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return shRoot;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
forceReload() {
|
|
175
|
+
this.trashIterator += 1;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
hotReplacedCallback() {
|
|
179
|
+
this.forceReload();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
sendEventToOutside<T>(eventName: string, data: T) {
|
|
183
|
+
sendEventToOutside(eventName, data);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static sendEventToOutside<T>(eventName: string, data: T) {
|
|
187
|
+
sendEventToOutside(eventName, data);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private applyFileList(): void
|
|
191
|
+
{
|
|
192
|
+
try {
|
|
193
|
+
(this.constructor as IWithCompose<this>).fileList.forEach((file: string) => {
|
|
194
|
+
if (this.fileAssets[file]) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.apiService.pureGet(this.config.get('pubUrlFilePrefix') + file).then((response: string) => {
|
|
198
|
+
this.fileAssets = { ...this.fileAssets, [file]: html`${response}` };
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
} catch (e: Error | any) {
|
|
203
|
+
console.error('Error loading file content:', e.message);
|
|
204
|
+
console.error(e.stack);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
static setExternalAttr(componentName: string, key: string)
|
|
209
|
+
{
|
|
210
|
+
if(!Object.keys(RWSViewComponent._externalAttrs).includes(componentName)){
|
|
211
|
+
RWSViewComponent._externalAttrs[componentName] = [];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
RWSViewComponent._externalAttrs[componentName].push(key);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static hotReplacedCallback() {
|
|
218
|
+
this.getInstances().forEach(instance => instance.forceReload());
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
static isDefined<T extends RWSViewComponent>(this: IWithCompose<T>): boolean
|
|
222
|
+
{
|
|
223
|
+
return isDefined<T>(this);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static defineComponent<T extends RWSViewComponent>(this: IWithCompose<T>): void
|
|
227
|
+
{
|
|
228
|
+
return defineComponent<T>(this);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static getDefinition(tagName: string, htmlTemplate: ViewTemplate, styles: ElementStyles = null)
|
|
232
|
+
{
|
|
233
|
+
return getDefinition(tagName, htmlTemplate, styles);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private static getInstances(): RWSViewComponent[] {
|
|
237
|
+
return RWSViewComponent.instances;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export default RWSViewComponent;
|
|
242
|
+
|
|
243
|
+
export { RWSViewComponent };
|
|
244
|
+
|
|
245
|
+
export type {
|
|
246
|
+
IAssetShowOptions,
|
|
247
|
+
IRWSViewComponent
|
|
248
248
|
} from '../types/IRWSViewComponent';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {DI, Container, Registration, InterfaceSymbol, Key } from '../../foundation/rws-foundation';
|
|
2
|
-
import {loadRWSRichWindow} from '../types/RWSWindow';
|
|
3
|
-
|
|
4
|
-
export default () => {
|
|
5
|
-
const richWindow = loadRWSRichWindow();
|
|
6
|
-
|
|
7
|
-
if(richWindow.RWS.container){
|
|
8
|
-
return richWindow.RWS.container;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
richWindow.RWS.container = DI.getOrCreateDOMContainer(richWindow.RWS.container_node);
|
|
12
|
-
|
|
13
|
-
return richWindow.RWS.container;
|
|
14
|
-
};
|
|
15
|
-
|
|
1
|
+
import {DI, Container, Registration, InterfaceSymbol, Key } from '../../foundation/rws-foundation';
|
|
2
|
+
import {loadRWSRichWindow} from '../types/RWSWindow';
|
|
3
|
+
|
|
4
|
+
export default () => {
|
|
5
|
+
const richWindow = loadRWSRichWindow();
|
|
6
|
+
|
|
7
|
+
if(richWindow.RWS.container){
|
|
8
|
+
return richWindow.RWS.container;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
richWindow.RWS.container = DI.getOrCreateDOMContainer(richWindow.RWS.container_node);
|
|
12
|
+
|
|
13
|
+
return richWindow.RWS.container;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
16
|
export { DI, Container, Registration, InterfaceSymbol, Key }
|