@base-framework/base 3.9.23 → 3.9.25

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.
@@ -10,13 +10,6 @@
10
10
  * @class
11
11
  */
12
12
  export class DataTracker {
13
- /**
14
- * @private
15
- * @static
16
- * @type {Map} trackers This is an object that stores all tracker
17
- * objects by tracking id.
18
- */
19
- private static trackers;
20
13
  /**
21
14
  * @private
22
15
  * @static
@@ -42,7 +35,8 @@ export class DataTracker {
42
35
  static removeType(type: string): void;
43
36
  /**
44
37
  * This will get the object tracking id or set it if
45
- * not set.
38
+ * not set. Trackers no longer need it; it is kept for code that
39
+ * uses the id as a key of its own.
46
40
  *
47
41
  * @param {object} obj
48
42
  * @returns {string}
@@ -67,7 +61,8 @@ export class DataTracker {
67
61
  */
68
62
  static get(obj: object, type?: string): any;
69
63
  /**
70
- * This will check if an object has a specific type.
64
+ * This will check if an object has a specific type. It only
65
+ * reads: nothing is created for an object that is not tracked.
71
66
  *
72
67
  * @param {object} obj
73
68
  * @param {string} type
@@ -75,13 +70,12 @@ export class DataTracker {
75
70
  */
76
71
  static has(obj: object, type: string): boolean;
77
72
  /**
78
- * This will get the tracker or create a new tracker
79
- * if no tracker is set.
73
+ * This will get the tracker of an object or create one.
80
74
  *
81
- * @param {string} id
82
- * @returns {object} The tracker.
75
+ * @param {object} obj
76
+ * @returns {Tracker} The tracker.
83
77
  */
84
- static find(id: string): object;
78
+ static find(obj: object): Tracker;
85
79
  /**
86
80
  * This will check if an object is empty.
87
81
  *
@@ -99,3 +93,4 @@ export class DataTracker {
99
93
  */
100
94
  static remove(obj: object, type?: string): void;
101
95
  }
96
+ import { Tracker } from './tracker.js';
@@ -114,6 +114,36 @@ export class BasicData {
114
114
  * @type {object} stage
115
115
  */
116
116
  stage: object;
117
+ /**
118
+ * This will create the local event sub.
119
+ *
120
+ * @protected
121
+ * @returns {DataPubSub}
122
+ */
123
+ protected createEventSub(): DataPubSub;
124
+ /**
125
+ * This will check if the constructor values can be written
126
+ * without publishing: true unless a subclass changed how values
127
+ * are set or published.
128
+ *
129
+ * @protected
130
+ * @returns {boolean}
131
+ */
132
+ protected _canSilentInit(): boolean;
133
+ /**
134
+ * This will write the constructor values.
135
+ *
136
+ * A new data object has a new id, so nothing can be subscribed to
137
+ * it yet, locally or in the data binder. Publishing every value
138
+ * was pure overhead (most of the cost of creating a scoped row).
139
+ * The values are written the way set() would write them: a value
140
+ * equal to the current one (undefined) is skipped.
141
+ *
142
+ * @protected
143
+ * @param {object} attributes
144
+ * @returns {void}
145
+ */
146
+ protected _initAttributes(attributes: object): void;
117
147
  /**
118
148
  * This will setup the number and unique id of the data object.
119
149
  *
@@ -38,6 +38,26 @@ export class Data extends BasicData {
38
38
  * @returns {object}
39
39
  */
40
40
  scope(attr: string, constructor?: object): object;
41
+ /**
42
+ * This will link a scoped data source to a parent attr.
43
+ *
44
+ * linkAttr makes two subscriptions per key: the parent path to
45
+ * the child key, and the child key back to the parent path. A
46
+ * scoped for-each row only needs the first. The child sends its
47
+ * writes to those keys back to the parent directly (see
48
+ * _setAttr), which also lands them on the parent in the same
49
+ * tick instead of after the next flush.
50
+ *
51
+ * @param {object} data The parent data.
52
+ * @param {string} attr The parent attr ('items[3]').
53
+ * @returns {void}
54
+ */
55
+ linkScope(data: object, attr: string): void;
56
+ _upstream: {
57
+ data: any;
58
+ prefix: string;
59
+ keys: Set<string>;
60
+ };
41
61
  /**
42
62
  * This will splice a value from an array and set
43
63
  * the result.
@@ -1,3 +1,4 @@
1
+ export function getRootKey(msg: string): string;
1
2
  /**
2
3
  * DataPubSub
3
4
  *
@@ -15,8 +16,13 @@ export class DataPubSub {
15
16
  * subscribed messages grouped by their `prefix:` segment. Used by
16
17
  * the data binder so deep data can publish only to subscribed
17
18
  * paths instead of walking every node of a value.
19
+ * @param {boolean} [indexRoots=false] Maintain an index of
20
+ * subscribed messages grouped by their root key ('items' for
21
+ * 'items[0].name:change'). Used by deep data so setting an object
22
+ * only looks at the paths under that key instead of every
23
+ * subscription on the data.
18
24
  */
19
- constructor(indexPrefixes?: boolean);
25
+ constructor(indexPrefixes?: boolean, indexRoots?: boolean);
20
26
  /**
21
27
  * @type {Map} callBacks
22
28
  * @protected
@@ -30,6 +36,14 @@ export class DataPubSub {
30
36
  * @protected
31
37
  */
32
38
  protected prefixIndex: Map<string, Set<string>> | null;
39
+ /**
40
+ * Index of subscribed messages keyed by root key. Null when
41
+ * disabled.
42
+ *
43
+ * @type {Map<string, Set<string>>|null}
44
+ * @protected
45
+ */
46
+ protected rootIndex: Map<string, Set<string>> | null;
33
47
  /**
34
48
  * Queue for batching publish calls
35
49
  * @type {Map<string, Array>}
@@ -149,6 +163,30 @@ export class DataPubSub {
149
163
  * @returns {void}
150
164
  */
151
165
  protected _unindexMessage(msg: string): void;
166
+ /**
167
+ * This will add a message to the root index.
168
+ *
169
+ * @protected
170
+ * @param {string} msg
171
+ * @returns {void}
172
+ */
173
+ protected _indexRoot(msg: string): void;
174
+ /**
175
+ * This will remove a message from the root index.
176
+ *
177
+ * @protected
178
+ * @param {string} msg
179
+ * @returns {void}
180
+ */
181
+ protected _unindexRoot(msg: string): void;
182
+ /**
183
+ * This will get the subscribed messages under a root key. When
184
+ * root indexing is disabled every message is returned.
185
+ *
186
+ * @param {string} root
187
+ * @returns {Iterable<string>|null}
188
+ */
189
+ getRootMessages(root: string): Iterable<string> | null;
152
190
  /**
153
191
  * This will get the subscribed messages for a prefix
154
192
  * (e.g. 'dt-3:'). Returns null when prefix indexing is
@@ -82,6 +82,15 @@ export class Router {
82
82
  * @type {number} keepAliveMax
83
83
  */
84
84
  keepAliveMax: number;
85
+ /**
86
+ * How keep-alive pages are cached: 'detach' removes them from
87
+ * the document, 'hide' leaves them in place with
88
+ * `content-visibility: hidden`, which keeps their style and
89
+ * layout so showing them again is far cheaper. Routes and
90
+ * components can set `keepAliveMode` themselves.
91
+ * @type {string} keepAliveMode
92
+ */
93
+ keepAliveMode: string;
85
94
  /**
86
95
  * This will track the detached keep-alive pages.
87
96
  * @type {PageCache} pageCache
@@ -130,6 +139,9 @@ export class Router {
130
139
  * @param {object} [options]
131
140
  * @param {number} [options.max] The max detached pages kept across
132
141
  * the router (default 5). The least recently used is destroyed.
142
+ * @param {string} [options.mode] 'detach' (default) removes cached
143
+ * pages from the document; 'hide' keeps them in place, hidden, so
144
+ * they come back without a full restyle.
133
145
  * @returns {this} a reference to the router object.
134
146
  *
135
147
  * @example
@@ -137,6 +149,7 @@ export class Router {
137
149
  */
138
150
  setKeepAlive(enabled: boolean, options?: {
139
151
  max?: number;
152
+ mode?: string;
140
153
  }): this;
141
154
  /**
142
155
  * This will add a new route to the router.
@@ -351,6 +364,22 @@ export class Router {
351
364
  * route scroll intent is applied.
352
365
  */
353
366
  protected checkActiveRoutes(path?: string, restoreScroll?: boolean): void;
367
+ /**
368
+ * This will have every active route page read its element scroll
369
+ * before the navigation adds or removes any page.
370
+ *
371
+ * @protected
372
+ * @returns {Array<object>} the routes that captured.
373
+ */
374
+ protected captureActiveScroll(): Array<object>;
375
+ /**
376
+ * This will drop the captured page scroll of routes that stayed
377
+ * active, so a later removal reads it fresh.
378
+ *
379
+ * @param {Array<object>} captured
380
+ * @returns {void}
381
+ */
382
+ releaseCapturedScroll(captured: Array<object>): void;
354
383
  /**
355
384
  * Checks all switch groups against the given path.
356
385
  * Activates the first matching route or falls back to the first route in the group if none match.
@@ -1,3 +1,10 @@
1
+ /**
2
+ * The attribute set on the roots of a keep-alive page that is hidden
3
+ * in place. Routes inside it are dormant (see Route.isDormant).
4
+ *
5
+ * @type {string}
6
+ */
7
+ export const DORMANT_ATTR: string;
1
8
  /**
2
9
  * ComponentHelper
3
10
  *
@@ -41,6 +48,38 @@ export class ComponentHelper {
41
48
  * @type {boolean|null} keepAlive
42
49
  */
43
50
  keepAlive: boolean | null;
51
+ /**
52
+ * The route keep-alive mode: 'detach' removes the page from the
53
+ * document, 'hide' leaves it in place hidden. Null uses the
54
+ * component `keepAliveMode` or the router default.
55
+ *
56
+ * @type {string|null} keepAliveMode
57
+ */
58
+ keepAliveMode: string | null;
59
+ /**
60
+ * True while the cached page is hidden in place instead of
61
+ * detached.
62
+ *
63
+ * @type {boolean} hiddenInPlace
64
+ */
65
+ hiddenInPlace: boolean;
66
+ /**
67
+ * The inline values each root had before it was hidden.
68
+ *
69
+ * @type {WeakMap<object, Array<Array<string>>>|null} hiddenStyles
70
+ */
71
+ hiddenStyles: WeakMap<object, Array<Array<string>>> | null;
72
+ /**
73
+ * The element scroll offsets read at the start of a navigation,
74
+ * before any page was added or removed. Reading them later, once
75
+ * the incoming page is in the document, forces the browser to
76
+ * style and lay out that whole page in the click.
77
+ *
78
+ * @type {{ value: object|null }|null} capturedScroll
79
+ */
80
+ capturedScroll: {
81
+ value: object | null;
82
+ } | null;
44
83
  /**
45
84
  * The router page cache that tracks detached keep-alive
46
85
  * pages and element scroll memory.
@@ -97,12 +136,45 @@ export class ComponentHelper {
97
136
  * @returns {boolean}
98
137
  */
99
138
  isKeepAlive(component?: object | null): boolean;
139
+ /**
140
+ * This will get the keep-alive mode. The route setting wins, then
141
+ * the component `keepAliveMode` property, then the router default.
142
+ *
143
+ * @param {object|null} [component]
144
+ * @returns {string} 'detach' or 'hide'
145
+ */
146
+ getKeepAliveMode(component?: object | null): string;
100
147
  /**
101
148
  * This will check if the page is detached and cached.
102
149
  *
103
150
  * @returns {boolean}
104
151
  */
105
152
  isDetached(): boolean;
153
+ /**
154
+ * This will read the element scroll of the page now, while the
155
+ * document still only holds the current pages. The router calls it
156
+ * at the start of a navigation. The page uses it if it is removed
157
+ * during that navigation.
158
+ *
159
+ * @returns {void}
160
+ */
161
+ captureScroll(): void;
162
+ /**
163
+ * This will drop a captured element scroll that was not used.
164
+ *
165
+ * @returns {void}
166
+ */
167
+ releaseCapturedScroll(): void;
168
+ /**
169
+ * This will get the element scroll to save when the page is
170
+ * removed: the captured offsets when the router captured them,
171
+ * else the offsets read now.
172
+ *
173
+ * @protected
174
+ * @param {object} component
175
+ * @returns {object|null}
176
+ */
177
+ protected takeScroll(component: object): object | null;
106
178
  /**
107
179
  * This will create the component.
108
180
  *
@@ -209,8 +281,12 @@ export class ComponentHelper {
209
281
  protected restoreHistoryScroll(): void;
210
282
  /**
211
283
  * This will restore the element scroll of a re-inserted page.
212
- * The page keeps its content, so this is done synchronously
213
- * before the next paint.
284
+ *
285
+ * Setting scrollTop makes the browser lay out the document, and
286
+ * the navigation is still changing it (the outgoing page has not
287
+ * been removed yet), so writing it in the click would pay for a
288
+ * layout that is thrown away. It is written in the next animation
289
+ * frame instead, which still runs before that frame is painted.
214
290
  *
215
291
  * @protected
216
292
  * @returns {void}
@@ -225,6 +301,35 @@ export class ComponentHelper {
225
301
  * @returns {boolean} false when the page can not be detached.
226
302
  */
227
303
  protected detach(component: object): boolean;
304
+ /**
305
+ * This will remove the page roots from the document. They are
306
+ * removed directly so the data tracker cleanup does not run, and
307
+ * their parents are kept so they go back where they were.
308
+ *
309
+ * @protected
310
+ * @param {Array<object>} nodes
311
+ * @returns {void}
312
+ */
313
+ protected removeNodes(nodes: Array<object>): void;
314
+ /**
315
+ * This will hide the page roots where they are. Element roots are
316
+ * hidden; comment and text roots render nothing on their own.
317
+ *
318
+ * @protected
319
+ * @param {Array<object>} nodes
320
+ * @returns {void}
321
+ */
322
+ protected hideInPlace(nodes: Array<object>): void;
323
+ /**
324
+ * This will show the roots of a page hidden in place. A root that
325
+ * left the document while hidden goes into the route container.
326
+ *
327
+ * @protected
328
+ * @param {Array<object>} nodes
329
+ * @param {object} container
330
+ * @returns {void}
331
+ */
332
+ protected showInPlace(nodes: Array<object>, container: object): void;
228
333
  /**
229
334
  * This will re-insert a detached keep-alive page.
230
335
  *
@@ -54,6 +54,12 @@ export class PageCache {
54
54
  * @returns {boolean}
55
55
  */
56
56
  isEnabled(): boolean;
57
+ /**
58
+ * This will get the router default keep-alive mode.
59
+ *
60
+ * @returns {string} 'detach' or 'hide'
61
+ */
62
+ getMode(): string;
57
63
  /**
58
64
  * This will get the max detached pages.
59
65
  *
@@ -63,6 +63,19 @@ export class Route extends BasicData {
63
63
  * @returns {void}
64
64
  */
65
65
  deactivate(destroy?: boolean): void;
66
+ /**
67
+ * This will read the page element scroll before a navigation
68
+ * changes the document (see ComponentHelper.captureScroll).
69
+ *
70
+ * @returns {void}
71
+ */
72
+ captureScroll(): void;
73
+ /**
74
+ * This will drop an unused captured page scroll.
75
+ *
76
+ * @returns {void}
77
+ */
78
+ releaseCapturedScroll(): void;
66
79
  /**
67
80
  * This will check if the route page is detached from the
68
81
  * document because it is kept alive, or because the route
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base-framework/base",
3
- "version": "3.9.23",
3
+ "version": "3.9.25",
4
4
  "description": "This is a javascript framework.",
5
5
  "main": "./dist/base.js",
6
6
  "module": "./dist/base.js",