@rws-framework/client 2.21.5 → 2.22.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/package.json +1 -1
- package/src/components/_component.ts +30 -59
- package/src/index.ts +6 -8
- package/src/services/ApiService.ts +1 -1
- package/src/services/DOMService.ts +1 -1
- package/src/types/IBackendCore.ts +12 -0
- package/src/types/IRWSResource.ts +5 -0
- package/src/types/IRWSViewComponent.ts +2 -2
- package/src/types/IReFormerField.ts +5 -0
- package/src/events.ts +0 -3
package/package.json
CHANGED
|
@@ -13,7 +13,6 @@ import TheRWSService from '../services/_service';
|
|
|
13
13
|
import { handleExternalChange } from './_attrs/_external_handler';
|
|
14
14
|
import { IFastDefinition, isDefined, defineComponent, getDefinition } from './_definitions';
|
|
15
15
|
import { on, $emitDown, observe, sendEventToOutside } from './_event_handling';
|
|
16
|
-
import { domEvents } from '../events';
|
|
17
16
|
|
|
18
17
|
type ComposeMethodType<
|
|
19
18
|
T extends FoundationElementDefinition,
|
|
@@ -22,8 +21,6 @@ type ComposeMethodType<
|
|
|
22
21
|
|
|
23
22
|
type CSSInjectMode = 'adopted' | 'legacy' | 'both';
|
|
24
23
|
|
|
25
|
-
const _DEFAULT_INJECT_CSS_CACHE_LIMIT_DAYS = 1;
|
|
26
|
-
|
|
27
24
|
export interface IWithCompose<T extends RWSViewComponent> {
|
|
28
25
|
[key: string]: any
|
|
29
26
|
new(...args: any[]): T;
|
|
@@ -253,81 +250,55 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
|
|
|
253
250
|
return RWSViewComponent.instances;
|
|
254
251
|
}
|
|
255
252
|
|
|
256
|
-
protected async injectStyles(styleLinks: string[], mode: CSSInjectMode = 'adopted'
|
|
253
|
+
protected async injectStyles(styleLinks: string[], mode: CSSInjectMode = 'adopted') {
|
|
257
254
|
const dbName = 'css-cache';
|
|
258
255
|
const storeName = 'styles';
|
|
259
256
|
const db = await this.indexedDBService.openDB(dbName, storeName);
|
|
260
|
-
const maxAgeMs = 1000 * 60 * 60 * 24; // 24h
|
|
261
|
-
const maxDaysAge = maxDaysExp ? maxDaysExp : _DEFAULT_INJECT_CSS_CACHE_LIMIT_DAYS;
|
|
262
|
-
const maxAgeDays = maxAgeMs * maxDaysAge;
|
|
263
257
|
|
|
264
258
|
let adoptedSheets: CSSStyleSheet[] = [];
|
|
265
259
|
|
|
266
|
-
let doneAdded = false;
|
|
267
|
-
|
|
268
260
|
for (const styleLink of styleLinks) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
link.onload = () => {
|
|
277
|
-
doneAdded = true;
|
|
278
|
-
|
|
279
|
-
if(mode === 'legacy'){
|
|
280
|
-
resolve();
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
}
|
|
261
|
+
if (mode === 'legacy' || mode === 'both') {
|
|
262
|
+
const link = document.createElement('link');
|
|
263
|
+
link.rel = 'stylesheet';
|
|
264
|
+
link.href = styleLink;
|
|
265
|
+
this.getShadowRoot().appendChild(link);
|
|
266
|
+
}
|
|
284
267
|
|
|
285
|
-
|
|
286
|
-
|
|
268
|
+
if (mode === 'adopted' || mode === 'both') {
|
|
269
|
+
const entry = await this.indexedDBService.getFromDB(db, storeName, styleLink);
|
|
270
|
+
const maxAgeMs = 1000 * 60 * 60 * 24; // 24h
|
|
287
271
|
|
|
288
|
-
|
|
272
|
+
let cssText: string | null = null;
|
|
289
273
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
274
|
+
if (entry && typeof entry === 'object' && 'css' in entry && 'timestamp' in entry) {
|
|
275
|
+
const expired = Date.now() - entry.timestamp > maxAgeMs;
|
|
276
|
+
if (!expired) {
|
|
277
|
+
cssText = entry.css;
|
|
295
278
|
}
|
|
279
|
+
}
|
|
296
280
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const sheet = new CSSStyleSheet();
|
|
307
|
-
await sheet.replace(cssText);
|
|
308
|
-
|
|
309
|
-
adoptedSheets.push(sheet);
|
|
310
|
-
|
|
311
|
-
if(mode === 'adopted' || mode === 'both'){
|
|
312
|
-
resolve();
|
|
313
|
-
}
|
|
281
|
+
if (!cssText) {
|
|
282
|
+
cssText = await fetch(styleLink).then(res => res.text());
|
|
283
|
+
await this.indexedDBService.saveToDB(db, storeName, styleLink, {
|
|
284
|
+
css: cssText,
|
|
285
|
+
timestamp: Date.now()
|
|
286
|
+
});
|
|
287
|
+
console.log(`System saved stylesheet: ${styleLink} to IndexedDB`)
|
|
314
288
|
}
|
|
315
|
-
});
|
|
316
289
|
|
|
317
|
-
|
|
290
|
+
const sheet = new CSSStyleSheet();
|
|
291
|
+
await sheet.replace(cssText);
|
|
292
|
+
|
|
293
|
+
adoptedSheets.push(sheet);
|
|
294
|
+
}
|
|
318
295
|
}
|
|
319
296
|
|
|
320
|
-
if
|
|
321
|
-
this.getShadowRoot().adoptedStyleSheets = [
|
|
297
|
+
if(adoptedSheets.length){
|
|
298
|
+
this.getShadowRoot().adoptedStyleSheets = [
|
|
322
299
|
...adoptedSheets,
|
|
323
300
|
...this.getShadowRoot().adoptedStyleSheets,
|
|
324
301
|
];
|
|
325
|
-
|
|
326
|
-
doneAdded = true;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (doneAdded) {
|
|
330
|
-
this.$emit(domEvents.loadedLinkedStyles);
|
|
331
302
|
}
|
|
332
303
|
}
|
|
333
304
|
}
|
package/src/index.ts
CHANGED
|
@@ -22,14 +22,14 @@ import { RWSIgnore, RWSInject, RWSView } from './components/_decorator';
|
|
|
22
22
|
import type { DefaultRWSPluginOptionsType } from './plugins/_plugin';
|
|
23
23
|
import type { IRWSPlugin, IStaticRWSPlugin, IPluginSpawnOption } from './types/IRWSPlugin';
|
|
24
24
|
import type IRWSUser from './types/IRWSUser';
|
|
25
|
-
import type { IAssetShowOptions
|
|
25
|
+
import type { IAssetShowOptions } from './components/_component';
|
|
26
26
|
import type { RWSDecoratorOptions } from './components/_decorator';
|
|
27
|
+
import type { IKDBTypeInfo, IKDBTypesResponse } from './types/IBackendCore';
|
|
27
28
|
import type { DOMOutputType, TagsProcessorType } from './services/DOMService';
|
|
28
29
|
import type { IBackendRoute, IHTTProute, IPrefixedHTTProutes } from './services/ApiService';
|
|
29
30
|
import type IRWSConfig from './types/IRWSConfig';
|
|
30
31
|
import type RWSNotify from './types/RWSNotify';
|
|
31
32
|
import type { NotifyUiType, NotifyLogType } from './types/RWSNotify';
|
|
32
|
-
import * as RWSEvents from './events';
|
|
33
33
|
|
|
34
34
|
export default RWSClient;
|
|
35
35
|
|
|
@@ -70,12 +70,11 @@ export {
|
|
|
70
70
|
RWSService,
|
|
71
71
|
RWSViewComponent,
|
|
72
72
|
|
|
73
|
-
RWSContainer
|
|
74
|
-
|
|
75
|
-
RWSEvents
|
|
73
|
+
RWSContainer
|
|
76
74
|
};
|
|
77
75
|
|
|
78
|
-
export type {
|
|
76
|
+
export type {
|
|
77
|
+
IKDBTypeInfo, IKDBTypesResponse,
|
|
79
78
|
NotifyUiType,
|
|
80
79
|
NotifyLogType,
|
|
81
80
|
IBackendRoute as IRWSBackendRoute,
|
|
@@ -85,6 +84,5 @@ export type {
|
|
|
85
84
|
IAssetShowOptions as IRWSAssetShowOptions,
|
|
86
85
|
IRWSConfig,
|
|
87
86
|
IRWSUser,
|
|
88
|
-
TagsProcessorType
|
|
89
|
-
IRWSViewComponent
|
|
87
|
+
TagsProcessorType
|
|
90
88
|
}
|
|
@@ -83,7 +83,7 @@ class DOMService extends RWSService {
|
|
|
83
83
|
sanitizeOptions: DOMPurify.Config = { })
|
|
84
84
|
{
|
|
85
85
|
const output: string = line.trim();
|
|
86
|
-
const sanitized = DOMPurify.sanitize(output, { USE_PROFILES: { html: true }, ...sanitizeOptions})
|
|
86
|
+
const sanitized = DOMPurify.sanitize(output, { USE_PROFILES: { html: true }, ...sanitizeOptions});
|
|
87
87
|
return sanitized;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ViewTemplate } from '@microsoft/fast-element';
|
|
2
2
|
import { DOMOutputType } from '../services/DOMService';
|
|
3
3
|
|
|
4
4
|
type IAssetShowOptions = Record<string, any>;
|
|
5
5
|
|
|
6
|
-
interface IRWSViewComponent extends
|
|
6
|
+
interface IRWSViewComponent extends Node {
|
|
7
7
|
__isLoading: boolean;
|
|
8
8
|
routeParams: Record<string, string>;
|
|
9
9
|
trashIterator: number;
|
package/src/events.ts
DELETED