@base-framework/base 3.9.17 → 3.9.18
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/README.md +791 -763
- package/dist/base.js +1 -1
- package/dist/chunks/chunk-6YJAZHX6.js +2 -0
- package/dist/chunks/chunk-7ZHUXJZT.js +2 -0
- package/dist/chunks/chunk-HBL2JSVL.js +2 -0
- package/dist/chunks/chunk-LY736NR2.js +2 -0
- package/dist/chunks/chunk-PIAMX2DB.js +2 -0
- package/dist/chunks/chunk-VSCHM2ZB.js +2 -0
- package/dist/modules/ajax.js +1 -1
- package/dist/modules/component.js +1 -1
- package/dist/modules/data.js +1 -1
- package/dist/modules/html.js +1 -1
- package/dist/modules/router.js +1 -1
- package/dist/modules/state.js +1 -1
- package/dist/types/base.d.ts +2 -1
- package/dist/types/entries/ajax.d.ts +1 -0
- package/dist/types/modules/ajax/resource-cache.d.ts +214 -0
- package/dist/types/modules/component/mount-queue.d.ts +6 -0
- package/dist/types/modules/component/unit.d.ts +37 -1
- package/dist/types/modules/data/types/model/model-service.d.ts +106 -8
- package/dist/types/modules/import/layout-manager.d.ts +11 -0
- package/dist/types/modules/router/history/browser-history.d.ts +23 -0
- package/dist/types/modules/router/router.d.ts +109 -3
- package/dist/types/modules/router/routes/component-helper.d.ts +163 -2
- package/dist/types/modules/router/routes/element-scroll.d.ts +18 -0
- package/dist/types/modules/router/routes/page-cache.d.ts +113 -0
- package/dist/types/modules/router/routes/route.d.ts +16 -3
- package/package.json +1 -1
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} CacheRequestOptions
|
|
3
|
+
* @property {string} [key] The cache key. Defaults to method + url + params.
|
|
4
|
+
* @property {number} [ttl] How long the response stays fresh in ms.
|
|
5
|
+
* @property {boolean} [swr] Return a stale response and refresh it in the background.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} RequestOptions
|
|
9
|
+
* @property {CacheRequestOptions|boolean} [cache] Opt-in response caching for GET requests.
|
|
10
|
+
* @property {import('../../../ajax/resource-cache.js').CacheMatch} [invalidate] Cache keys or prefixes to clear after a successful request.
|
|
11
|
+
*/
|
|
1
12
|
/**
|
|
2
13
|
* ModelService
|
|
3
14
|
*
|
|
@@ -36,6 +47,10 @@ export class ModelService {
|
|
|
36
47
|
* @type {function|null} validateCallBack
|
|
37
48
|
*/
|
|
38
49
|
validateCallBack: Function | null;
|
|
50
|
+
/**
|
|
51
|
+
* @type {RequestOptions|null} requestOptions
|
|
52
|
+
*/
|
|
53
|
+
requestOptions: RequestOptions | null;
|
|
39
54
|
/**
|
|
40
55
|
* This will initialize the model service.
|
|
41
56
|
*
|
|
@@ -174,6 +189,30 @@ export class ModelService {
|
|
|
174
189
|
* @returns {string}
|
|
175
190
|
*/
|
|
176
191
|
protected getUrl(url: string): string;
|
|
192
|
+
/**
|
|
193
|
+
* This will return a copy of the service that adds the request
|
|
194
|
+
* options to every request it makes. The original service is
|
|
195
|
+
* not changed.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* model.xhr.withOptions({ cache: { ttl: 30000, swr: true } }).all('', callBack);
|
|
199
|
+
* model.xhr.withOptions({ invalidate: '/api/users' }).add();
|
|
200
|
+
*
|
|
201
|
+
* @param {RequestOptions} options
|
|
202
|
+
* @returns {this}
|
|
203
|
+
*/
|
|
204
|
+
withOptions(options: RequestOptions): this;
|
|
205
|
+
/**
|
|
206
|
+
* This will return a copy of the service that caches its
|
|
207
|
+
* read requests.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* model.xhr.withCache({ ttl: 30000 }).get('', callBack);
|
|
211
|
+
*
|
|
212
|
+
* @param {CacheRequestOptions|boolean} [cache]
|
|
213
|
+
* @returns {this}
|
|
214
|
+
*/
|
|
215
|
+
withCache(cache?: CacheRequestOptions | boolean): this;
|
|
177
216
|
/**
|
|
178
217
|
* This will make an ajax request.
|
|
179
218
|
*
|
|
@@ -183,9 +222,37 @@ export class ModelService {
|
|
|
183
222
|
* @param {(string|object)} params
|
|
184
223
|
* @param {function} [callBack]
|
|
185
224
|
* @param {function} [requestCallBack]
|
|
225
|
+
* @param {RequestOptions} [options]
|
|
226
|
+
* @returns {XMLHttpRequest?} The xhr, or null if the request was served
|
|
227
|
+
* by the resource cache without a new network call.
|
|
228
|
+
*/
|
|
229
|
+
protected setupRequest(url: string, method: string, params: (string | object), callBack?: Function, requestCallBack?: Function, options?: RequestOptions): XMLHttpRequest | null;
|
|
230
|
+
/**
|
|
231
|
+
* This will check if a request method can read from the cache.
|
|
232
|
+
* Mutating requests never read from the cache.
|
|
233
|
+
*
|
|
234
|
+
* @protected
|
|
235
|
+
* @param {string} method
|
|
236
|
+
* @returns {boolean}
|
|
237
|
+
*/
|
|
238
|
+
protected isCacheableMethod(method: string): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* This will get the default cache key for a request.
|
|
241
|
+
*
|
|
242
|
+
* @protected
|
|
243
|
+
* @param {object} settings
|
|
244
|
+
* @returns {string}
|
|
245
|
+
*/
|
|
246
|
+
protected getCacheKey(settings: object): string;
|
|
247
|
+
/**
|
|
248
|
+
* This will make a request through the resource cache.
|
|
249
|
+
*
|
|
250
|
+
* @protected
|
|
251
|
+
* @param {object} settings
|
|
252
|
+
* @param {CacheRequestOptions} cache
|
|
186
253
|
* @returns {XMLHttpRequest?}
|
|
187
254
|
*/
|
|
188
|
-
protected
|
|
255
|
+
protected cachedRequest(settings: object, cache: CacheRequestOptions): XMLHttpRequest | null;
|
|
189
256
|
/**
|
|
190
257
|
* Set up an EventSource for real-time activity updates with auto-reconnection.
|
|
191
258
|
*
|
|
@@ -220,9 +287,10 @@ export class ModelService {
|
|
|
220
287
|
* @param {string} instanceParams
|
|
221
288
|
* @param {function} callBack
|
|
222
289
|
* @param {function} [requestCallBack]
|
|
290
|
+
* @param {RequestOptions} [options]
|
|
223
291
|
* @returns {XMLHttpRequest}
|
|
224
292
|
*/
|
|
225
|
-
protected request(params: (string | object), instanceParams: string, callBack: Function, requestCallBack?: Function): XMLHttpRequest;
|
|
293
|
+
protected request(params: (string | object), instanceParams: string, callBack: Function, requestCallBack?: Function, options?: RequestOptions): XMLHttpRequest;
|
|
226
294
|
/**
|
|
227
295
|
* This will make a GET request.
|
|
228
296
|
*
|
|
@@ -232,9 +300,10 @@ export class ModelService {
|
|
|
232
300
|
* @param {string} [instanceParams]
|
|
233
301
|
* @param {function} [callBack]
|
|
234
302
|
* @param {function} [requestCallBack]
|
|
303
|
+
* @param {RequestOptions} [options]
|
|
235
304
|
* @returns {XMLHttpRequest}
|
|
236
305
|
*/
|
|
237
|
-
protected _get(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function): XMLHttpRequest;
|
|
306
|
+
protected _get(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function, options?: RequestOptions): XMLHttpRequest;
|
|
238
307
|
/**
|
|
239
308
|
* This will make a POST request.
|
|
240
309
|
*
|
|
@@ -244,9 +313,10 @@ export class ModelService {
|
|
|
244
313
|
* @param {string} [instanceParams]
|
|
245
314
|
* @param {function} [callBack]
|
|
246
315
|
* @param {function} [requestCallBack]
|
|
316
|
+
* @param {RequestOptions} [options]
|
|
247
317
|
* @returns {XMLHttpRequest}
|
|
248
318
|
*/
|
|
249
|
-
protected _post(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function): XMLHttpRequest;
|
|
319
|
+
protected _post(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function, options?: RequestOptions): XMLHttpRequest;
|
|
250
320
|
/**
|
|
251
321
|
* This will make a PUT request.
|
|
252
322
|
*
|
|
@@ -256,9 +326,10 @@ export class ModelService {
|
|
|
256
326
|
* @param {string} [instanceParams]
|
|
257
327
|
* @param {function} [callBack]
|
|
258
328
|
* @param {function} [requestCallBack]
|
|
329
|
+
* @param {RequestOptions} [options]
|
|
259
330
|
* @returns {XMLHttpRequest}
|
|
260
331
|
*/
|
|
261
|
-
protected _put(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function): XMLHttpRequest;
|
|
332
|
+
protected _put(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function, options?: RequestOptions): XMLHttpRequest;
|
|
262
333
|
/**
|
|
263
334
|
* This will make a PATCH request.
|
|
264
335
|
*
|
|
@@ -268,9 +339,10 @@ export class ModelService {
|
|
|
268
339
|
* @param {string} [instanceParams]
|
|
269
340
|
* @param {function} [callBack]
|
|
270
341
|
* @param {function} [requestCallBack]
|
|
342
|
+
* @param {RequestOptions} [options]
|
|
271
343
|
* @returns {XMLHttpRequest}
|
|
272
344
|
*/
|
|
273
|
-
protected _patch(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function): XMLHttpRequest;
|
|
345
|
+
protected _patch(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function, options?: RequestOptions): XMLHttpRequest;
|
|
274
346
|
/**
|
|
275
347
|
* This will make a DELETE request.
|
|
276
348
|
*
|
|
@@ -280,9 +352,10 @@ export class ModelService {
|
|
|
280
352
|
* @param {string} [instanceParams]
|
|
281
353
|
* @param {function} [callBack]
|
|
282
354
|
* @param {function} [requestCallBack]
|
|
355
|
+
* @param {RequestOptions} [options]
|
|
283
356
|
* @returns {XMLHttpRequest}
|
|
284
357
|
*/
|
|
285
|
-
protected _delete(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function): XMLHttpRequest;
|
|
358
|
+
protected _delete(url: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function, options?: RequestOptions): XMLHttpRequest;
|
|
286
359
|
/**
|
|
287
360
|
* This will make an ajax request.
|
|
288
361
|
*
|
|
@@ -293,9 +366,10 @@ export class ModelService {
|
|
|
293
366
|
* @param {string} [instanceParams]
|
|
294
367
|
* @param {function} [callBack]
|
|
295
368
|
* @param {function} [requestCallBack]
|
|
369
|
+
* @param {RequestOptions} [options]
|
|
296
370
|
* @returns {XMLHttpRequest}
|
|
297
371
|
*/
|
|
298
|
-
protected _request(url: string, method: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function): XMLHttpRequest;
|
|
372
|
+
protected _request(url: string, method: string, params: (string | object), instanceParams?: string, callBack?: Function, requestCallBack?: Function, options?: RequestOptions): XMLHttpRequest;
|
|
299
373
|
/**
|
|
300
374
|
* This will get the response.
|
|
301
375
|
*
|
|
@@ -307,3 +381,27 @@ export class ModelService {
|
|
|
307
381
|
*/
|
|
308
382
|
protected getResponse(response: object, callBack?: Function, xhr?: object): void;
|
|
309
383
|
}
|
|
384
|
+
export type CacheRequestOptions = {
|
|
385
|
+
/**
|
|
386
|
+
* The cache key. Defaults to method + url + params.
|
|
387
|
+
*/
|
|
388
|
+
key?: string;
|
|
389
|
+
/**
|
|
390
|
+
* How long the response stays fresh in ms.
|
|
391
|
+
*/
|
|
392
|
+
ttl?: number;
|
|
393
|
+
/**
|
|
394
|
+
* Return a stale response and refresh it in the background.
|
|
395
|
+
*/
|
|
396
|
+
swr?: boolean;
|
|
397
|
+
};
|
|
398
|
+
export type RequestOptions = {
|
|
399
|
+
/**
|
|
400
|
+
* Opt-in response caching for GET requests.
|
|
401
|
+
*/
|
|
402
|
+
cache?: CacheRequestOptions | boolean;
|
|
403
|
+
/**
|
|
404
|
+
* Cache keys or prefixes to clear after a successful request.
|
|
405
|
+
*/
|
|
406
|
+
invalidate?: import("../../../ajax/resource-cache.js").CacheMatch;
|
|
407
|
+
};
|
|
@@ -23,4 +23,15 @@ export class LayoutManager {
|
|
|
23
23
|
* @return {object|null}
|
|
24
24
|
*/
|
|
25
25
|
static render(layout: object, element: object, parent: object): object | null;
|
|
26
|
+
/**
|
|
27
|
+
* This will render the layout to the DOM and return every
|
|
28
|
+
* root node so layouts with more than one root (arrays) can
|
|
29
|
+
* be fully removed.
|
|
30
|
+
*
|
|
31
|
+
* @param {object} layout
|
|
32
|
+
* @param {object} element
|
|
33
|
+
* @param {object} parent
|
|
34
|
+
* @return {Array<object>}
|
|
35
|
+
*/
|
|
36
|
+
static renderNodes(layout: object, element: object, parent: object): Array<object>;
|
|
26
37
|
}
|
|
@@ -6,12 +6,34 @@
|
|
|
6
6
|
* @class
|
|
7
7
|
*/
|
|
8
8
|
export class BrowserHistory extends History {
|
|
9
|
+
/**
|
|
10
|
+
* The key of the history entry that is showing.
|
|
11
|
+
*
|
|
12
|
+
* @type {string|null} currentKey
|
|
13
|
+
*/
|
|
14
|
+
currentKey: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* The last scroll position of each visited entry. Entries
|
|
17
|
+
* left by back / forward can't be updated with replaceState,
|
|
18
|
+
* so their position is kept here.
|
|
19
|
+
*
|
|
20
|
+
* @type {LRUCache} positions
|
|
21
|
+
*/
|
|
22
|
+
positions: LRUCache;
|
|
23
|
+
/**
|
|
24
|
+
* This will save the scroll position of the showing entry.
|
|
25
|
+
*
|
|
26
|
+
* @protected
|
|
27
|
+
* @returns {object}
|
|
28
|
+
*/
|
|
29
|
+
protected saveCurrentPosition(): object;
|
|
9
30
|
/**
|
|
10
31
|
* This will add the events.
|
|
11
32
|
*
|
|
12
33
|
* @returns {this} a reference to the object.
|
|
13
34
|
*/
|
|
14
35
|
addEvent(): this;
|
|
36
|
+
previousScrollRestoration: ScrollRestoration;
|
|
15
37
|
pageShowCallBack: any;
|
|
16
38
|
/**
|
|
17
39
|
* This will remove the events.
|
|
@@ -51,3 +73,4 @@ export class BrowserHistory extends History {
|
|
|
51
73
|
addState(uri: string, data: object | null, replace?: boolean): this;
|
|
52
74
|
}
|
|
53
75
|
import { History } from "./history.js";
|
|
76
|
+
import { LRUCache } from "../../../shared/lru-cache.js";
|
|
@@ -20,7 +20,9 @@ export class Router {
|
|
|
20
20
|
lastPath: any;
|
|
21
21
|
path: any;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* The last route that matched a path. This is kept for
|
|
24
|
+
* backwards compatibility only: every route is checked on
|
|
25
|
+
* each navigation so stale routes are deactivated.
|
|
24
26
|
* @type {object|null} lastMatchedRoute
|
|
25
27
|
*/
|
|
26
28
|
lastMatchedRoute: object | null;
|
|
@@ -47,6 +49,30 @@ export class Router {
|
|
|
47
49
|
* @type {number}
|
|
48
50
|
*/
|
|
49
51
|
scrollWaitToken: number;
|
|
52
|
+
/**
|
|
53
|
+
* Removes the user interaction listeners of a pending
|
|
54
|
+
* history scroll restore.
|
|
55
|
+
* @type {function|null}
|
|
56
|
+
*/
|
|
57
|
+
cancelScrollWait: Function | null;
|
|
58
|
+
/**
|
|
59
|
+
* The default keep-alive setting for routes that do not set
|
|
60
|
+
* `keepAlive` themselves. Keep-alive route pages are detached
|
|
61
|
+
* and cached instead of destroyed when the route deactivates.
|
|
62
|
+
* @type {boolean} keepAlive
|
|
63
|
+
*/
|
|
64
|
+
keepAlive: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The max detached keep-alive pages kept across the router.
|
|
67
|
+
* The least recently used page is destroyed past it.
|
|
68
|
+
* @type {number} keepAliveMax
|
|
69
|
+
*/
|
|
70
|
+
keepAliveMax: number;
|
|
71
|
+
/**
|
|
72
|
+
* This will track the detached keep-alive pages.
|
|
73
|
+
* @type {PageCache} pageCache
|
|
74
|
+
*/
|
|
75
|
+
pageCache: PageCache;
|
|
50
76
|
/**
|
|
51
77
|
* This will be used to access our history object.
|
|
52
78
|
*/
|
|
@@ -82,6 +108,22 @@ export class Router {
|
|
|
82
108
|
* @returns {object}
|
|
83
109
|
*/
|
|
84
110
|
protected createRoute(settings: object): object;
|
|
111
|
+
/**
|
|
112
|
+
* This will set the default keep-alive setting for routes that
|
|
113
|
+
* do not set `keepAlive` themselves.
|
|
114
|
+
*
|
|
115
|
+
* @param {boolean} enabled
|
|
116
|
+
* @param {object} [options]
|
|
117
|
+
* @param {number} [options.max] The max detached pages kept across
|
|
118
|
+
* the router (default 5). The least recently used is destroyed.
|
|
119
|
+
* @returns {this} a reference to the router object.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* router.setKeepAlive(true, { max: 5 });
|
|
123
|
+
*/
|
|
124
|
+
setKeepAlive(enabled: boolean, options?: {
|
|
125
|
+
max?: number;
|
|
126
|
+
}): this;
|
|
85
127
|
/**
|
|
86
128
|
* This will add a new route to the router.
|
|
87
129
|
*
|
|
@@ -216,10 +258,26 @@ export class Router {
|
|
|
216
258
|
/**
|
|
217
259
|
* This will check if a link was routed.
|
|
218
260
|
*
|
|
261
|
+
* Only plain primary clicks on same-origin links that open in the
|
|
262
|
+
* current browsing context are routed. Everything else is left to
|
|
263
|
+
* the browser (new tabs / windows, downloads, mailto:, tel:, other
|
|
264
|
+
* origins, or clicks another handler already cancelled).
|
|
265
|
+
*
|
|
219
266
|
* @protected
|
|
220
267
|
* @param {PointerEvent} evt
|
|
221
268
|
*/
|
|
222
269
|
protected checkLink(evt: PointerEvent): boolean;
|
|
270
|
+
/**
|
|
271
|
+
* This will convert a link href to a router path. Absolute and
|
|
272
|
+
* scheme relative urls are only routed when they are on the
|
|
273
|
+
* current origin. The base uri is only removed as a prefix.
|
|
274
|
+
*
|
|
275
|
+
* @protected
|
|
276
|
+
* @param {string} href
|
|
277
|
+
* @returns {string|null} the path or null if the router should
|
|
278
|
+
* not handle the link.
|
|
279
|
+
*/
|
|
280
|
+
protected getLinkPath(href: string): string | null;
|
|
223
281
|
/**
|
|
224
282
|
* This will reset the router.
|
|
225
283
|
*
|
|
@@ -259,17 +317,22 @@ export class Router {
|
|
|
259
317
|
*
|
|
260
318
|
* @protected
|
|
261
319
|
* @param {string} [path]
|
|
320
|
+
* @param {boolean} [restoreScroll] - when true (history back /
|
|
321
|
+
* forward) the caller restores the saved scroll position, so no
|
|
322
|
+
* route scroll intent is applied.
|
|
262
323
|
*/
|
|
263
|
-
protected checkActiveRoutes(path?: string): void;
|
|
324
|
+
protected checkActiveRoutes(path?: string, restoreScroll?: boolean): void;
|
|
264
325
|
/**
|
|
265
326
|
* Checks all switch groups against the given path.
|
|
266
327
|
* Activates the first matching route or falls back to the first route in the group if none match.
|
|
267
328
|
*
|
|
268
329
|
* @protected
|
|
269
330
|
* @param {string} path
|
|
331
|
+
* @param {boolean} [skipDormant] - true to skip groups whose
|
|
332
|
+
* container is inside a detached keep-alive page.
|
|
270
333
|
* @returns {void}
|
|
271
334
|
*/
|
|
272
|
-
protected checkSwitches(path: string): void;
|
|
335
|
+
protected checkSwitches(path: string, skipDormant?: boolean): void;
|
|
273
336
|
/**
|
|
274
337
|
* Checks a single group of routes against the path.
|
|
275
338
|
* Selects the first matching route if any; otherwise selects the first route.
|
|
@@ -325,6 +388,48 @@ export class Router {
|
|
|
325
388
|
* @returns {void}
|
|
326
389
|
*/
|
|
327
390
|
reassertScrollTop(): void;
|
|
391
|
+
/**
|
|
392
|
+
* This will restore a saved scroll position after the routes for
|
|
393
|
+
* a history navigation have been activated.
|
|
394
|
+
*
|
|
395
|
+
* When the page can already reach the position (e.g. a keep-alive
|
|
396
|
+
* page that was re-inserted at full height) it is restored
|
|
397
|
+
* synchronously so it lands before the next paint. Otherwise the
|
|
398
|
+
* page is still loading, so the document height is checked each
|
|
399
|
+
* frame and the position is restored once it can be reached (or
|
|
400
|
+
* after a short timeout). The wait is cancelled when the user
|
|
401
|
+
* starts interacting with the page or a newer navigation starts.
|
|
402
|
+
*
|
|
403
|
+
* @param {object} position
|
|
404
|
+
* @returns {void}
|
|
405
|
+
*/
|
|
406
|
+
restoreScrollPosition(position: object): void;
|
|
407
|
+
/**
|
|
408
|
+
* This will remove the listeners of a pending scroll restore.
|
|
409
|
+
*
|
|
410
|
+
* @protected
|
|
411
|
+
* @returns {void}
|
|
412
|
+
*/
|
|
413
|
+
protected clearScrollWait(): void;
|
|
414
|
+
/**
|
|
415
|
+
* This will check if the document is large enough to scroll the
|
|
416
|
+
* window to a position.
|
|
417
|
+
*
|
|
418
|
+
* @protected
|
|
419
|
+
* @param {number} x
|
|
420
|
+
* @param {number} y
|
|
421
|
+
* @returns {boolean}
|
|
422
|
+
*/
|
|
423
|
+
protected canReachScroll(x: number, y: number): boolean;
|
|
424
|
+
/**
|
|
425
|
+
* This will scroll the element matching a url hash into view.
|
|
426
|
+
* Lazy routes can mount their DOM after activation, so a missing
|
|
427
|
+
* element is polled for on animation frames for a short window.
|
|
428
|
+
*
|
|
429
|
+
* @param {string} hash
|
|
430
|
+
* @returns {void}
|
|
431
|
+
*/
|
|
432
|
+
scrollToHash(hash: string): void;
|
|
328
433
|
/**
|
|
329
434
|
* This will scroll to a target element by CSS selector.
|
|
330
435
|
* For sticky elements, it scrolls to the position where the
|
|
@@ -379,3 +484,4 @@ export class Router {
|
|
|
379
484
|
* @type {Router}
|
|
380
485
|
*/
|
|
381
486
|
export const router: Router;
|
|
487
|
+
import { PageCache } from './routes/page-cache.js';
|
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
* This will create a helper to create and destroy components
|
|
5
5
|
* that are added to a route.
|
|
6
6
|
*
|
|
7
|
+
* Keep-alive: when the route (or its component, or the router default)
|
|
8
|
+
* has `keepAlive` enabled, deactivating the route detaches the page
|
|
9
|
+
* root nodes from the document instead of destroying the component.
|
|
10
|
+
* Watchers, data and events stay alive, and the page is re-inserted
|
|
11
|
+
* as is when the route activates again. Keep-alive page components may
|
|
12
|
+
* define:
|
|
13
|
+
*
|
|
14
|
+
* - `onActivate(params, { restored })` called after the page is
|
|
15
|
+
* rendered (`restored: false`) or re-inserted (`restored: true`).
|
|
16
|
+
* - `onDeactivate()` called after the page is detached.
|
|
17
|
+
*
|
|
7
18
|
* @class
|
|
8
19
|
*/
|
|
9
20
|
export class ComponentHelper {
|
|
@@ -23,6 +34,60 @@ export class ComponentHelper {
|
|
|
23
34
|
container: any;
|
|
24
35
|
persist: any;
|
|
25
36
|
parent: any;
|
|
37
|
+
/**
|
|
38
|
+
* The route keep-alive setting. Null uses the component
|
|
39
|
+
* `keepAlive` or the router default.
|
|
40
|
+
*
|
|
41
|
+
* @type {boolean|null} keepAlive
|
|
42
|
+
*/
|
|
43
|
+
keepAlive: boolean | null;
|
|
44
|
+
/**
|
|
45
|
+
* The router page cache that tracks detached keep-alive
|
|
46
|
+
* pages and element scroll memory.
|
|
47
|
+
*
|
|
48
|
+
* @type {object|null} pageCache
|
|
49
|
+
*/
|
|
50
|
+
pageCache: object | null;
|
|
51
|
+
/**
|
|
52
|
+
* The root nodes of a detached keep-alive page, or null when
|
|
53
|
+
* the page is not cached.
|
|
54
|
+
*
|
|
55
|
+
* @type {Array<object>|null} detachedNodes
|
|
56
|
+
*/
|
|
57
|
+
detachedNodes: Array<object> | null;
|
|
58
|
+
/**
|
|
59
|
+
* The element scroll offsets of the detached page.
|
|
60
|
+
*
|
|
61
|
+
* @type {object|null} savedScroll
|
|
62
|
+
*/
|
|
63
|
+
savedScroll: object | null;
|
|
64
|
+
/**
|
|
65
|
+
* The last params the page was focused with.
|
|
66
|
+
*
|
|
67
|
+
* @type {object|null} params
|
|
68
|
+
*/
|
|
69
|
+
params: object | null;
|
|
70
|
+
/**
|
|
71
|
+
* Token that cancels a pending element scroll restore.
|
|
72
|
+
*
|
|
73
|
+
* @type {number} scrollToken
|
|
74
|
+
*/
|
|
75
|
+
scrollToken: number;
|
|
76
|
+
/**
|
|
77
|
+
* This will check if the route page is kept alive when the
|
|
78
|
+
* route deactivates. The route setting wins, then the component
|
|
79
|
+
* `keepAlive` property, then the router default.
|
|
80
|
+
*
|
|
81
|
+
* @param {object|null} [component]
|
|
82
|
+
* @returns {boolean}
|
|
83
|
+
*/
|
|
84
|
+
isKeepAlive(component?: object | null): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* This will check if the page is detached and cached.
|
|
87
|
+
*
|
|
88
|
+
* @returns {boolean}
|
|
89
|
+
*/
|
|
90
|
+
isDetached(): boolean;
|
|
26
91
|
/**
|
|
27
92
|
* This will create the component.
|
|
28
93
|
*
|
|
@@ -67,11 +132,107 @@ export class ComponentHelper {
|
|
|
67
132
|
*/
|
|
68
133
|
protected create(): void;
|
|
69
134
|
/**
|
|
70
|
-
* This will
|
|
135
|
+
* This will run the keep-alive and scroll memory work after the
|
|
136
|
+
* page has been rendered.
|
|
137
|
+
*
|
|
138
|
+
* @protected
|
|
139
|
+
* @param {object} params
|
|
140
|
+
* @returns {void}
|
|
141
|
+
*/
|
|
142
|
+
protected afterCreate(params: object): void;
|
|
143
|
+
/**
|
|
144
|
+
* This will be called when an imported page module rendered.
|
|
145
|
+
*
|
|
146
|
+
* @protected
|
|
147
|
+
* @param {object} component
|
|
148
|
+
* @returns {void}
|
|
149
|
+
*/
|
|
150
|
+
protected onModuleRender(component: object): void;
|
|
151
|
+
/**
|
|
152
|
+
* This will get the scroll memory key of the route page.
|
|
153
|
+
*
|
|
154
|
+
* @protected
|
|
155
|
+
* @returns {string}
|
|
156
|
+
*/
|
|
157
|
+
protected getScrollKey(): string;
|
|
158
|
+
/**
|
|
159
|
+
* This will get the root nodes of the rendered page. Imported
|
|
160
|
+
* pages render their layout next to the import placeholder, so
|
|
161
|
+
* those roots are included.
|
|
162
|
+
*
|
|
163
|
+
* @protected
|
|
164
|
+
* @param {object} component
|
|
165
|
+
* @returns {Array<object>}
|
|
166
|
+
*/
|
|
167
|
+
protected getRootNodes(component: object): Array<object>;
|
|
168
|
+
/**
|
|
169
|
+
* This will call a page lifecycle hook on the component and on
|
|
170
|
+
* an imported page component.
|
|
171
|
+
*
|
|
172
|
+
* @protected
|
|
173
|
+
* @param {string} name
|
|
174
|
+
* @param {Array<any>} args
|
|
175
|
+
* @returns {void}
|
|
176
|
+
*/
|
|
177
|
+
protected callPageHook(name: string, args: Array<any>): void;
|
|
178
|
+
/**
|
|
179
|
+
* This will restore the saved element scroll of a re-rendered
|
|
180
|
+
* page on history navigation. The content may still be loading,
|
|
181
|
+
* so it is retried each frame for a short window.
|
|
182
|
+
*
|
|
183
|
+
* @protected
|
|
184
|
+
* @returns {void}
|
|
185
|
+
*/
|
|
186
|
+
protected restoreHistoryScroll(): void;
|
|
187
|
+
/**
|
|
188
|
+
* This will restore the element scroll of a re-inserted page.
|
|
189
|
+
* The page keeps its content, so this is done synchronously
|
|
190
|
+
* before the next paint.
|
|
191
|
+
*
|
|
192
|
+
* @protected
|
|
193
|
+
* @returns {void}
|
|
194
|
+
*/
|
|
195
|
+
protected restoreDetachedScroll(): void;
|
|
196
|
+
/**
|
|
197
|
+
* This will detach a keep-alive page from the document without
|
|
198
|
+
* destroying it. Watchers, data and events stay alive.
|
|
199
|
+
*
|
|
200
|
+
* @protected
|
|
201
|
+
* @param {object} component
|
|
202
|
+
* @returns {boolean} false when the page can not be detached.
|
|
203
|
+
*/
|
|
204
|
+
protected detach(component: object): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* This will re-insert a detached keep-alive page.
|
|
207
|
+
*
|
|
208
|
+
* @protected
|
|
209
|
+
* @returns {boolean} false when the page was destroyed while
|
|
210
|
+
* it was detached.
|
|
211
|
+
*/
|
|
212
|
+
protected reattach(): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* This will destroy a detached keep-alive page. This is called
|
|
215
|
+
* by the page cache when the page is evicted.
|
|
216
|
+
*
|
|
217
|
+
* @returns {void}
|
|
218
|
+
*/
|
|
219
|
+
evict(): void;
|
|
220
|
+
/**
|
|
221
|
+
* This will destroy the component.
|
|
222
|
+
*
|
|
223
|
+
* @protected
|
|
224
|
+
* @returns {void}
|
|
225
|
+
*/
|
|
226
|
+
protected releaseComponent(): void;
|
|
227
|
+
/**
|
|
228
|
+
* This will remove the component. A keep-alive page is detached
|
|
229
|
+
* and cached instead of destroyed unless `destroy` is true.
|
|
71
230
|
*
|
|
231
|
+
* @param {boolean} [destroy] - true to always destroy the page,
|
|
232
|
+
* including a detached keep-alive page (route removal/teardown).
|
|
72
233
|
* @returns {void}
|
|
73
234
|
*/
|
|
74
|
-
remove(): void;
|
|
235
|
+
remove(destroy?: boolean): void;
|
|
75
236
|
/**
|
|
76
237
|
* This will call the component update method and pass the params.
|
|
77
238
|
*
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Element scroll memory
|
|
3
|
+
*
|
|
4
|
+
* Elements inside a route page that carry a `data-scroll-key`
|
|
5
|
+
* attribute have their scrollTop / scrollLeft saved when the route
|
|
6
|
+
* deactivates and restored when it activates again. Detaching an
|
|
7
|
+
* element from the document resets its scroll offsets, so this is
|
|
8
|
+
* required for keep-alive pages and also lets re-rendered pages restore
|
|
9
|
+
* their inner scroll panes on history navigation.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @type {string} SCROLL_KEY_ATTR
|
|
15
|
+
*/
|
|
16
|
+
export const SCROLL_KEY_ATTR: string;
|
|
17
|
+
export function saveElementScroll(nodes: Array<object>): object | null;
|
|
18
|
+
export function restoreElementScroll(nodes: Array<object>, saved: object | null): boolean;
|