chayns-api 3.0.0 → 3.1.0-beta.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.
Files changed (139) hide show
  1. package/dist/cjs/calls/index.js +4 -1
  2. package/dist/cjs/calls/visibilityChangeListener.js +4 -4
  3. package/dist/cjs/components/ChaynsProvider.js +34 -6
  4. package/dist/cjs/components/withHydrationBoundary.js +2 -2
  5. package/dist/cjs/constants/index.js +0 -22
  6. package/dist/cjs/contexts/HistoryLayerContext.js +89 -0
  7. package/dist/cjs/contexts/index.js +38 -0
  8. package/dist/cjs/handler/history/FrameHistoryLayer.js +100 -0
  9. package/dist/cjs/handler/history/HistoryLayer.js +321 -0
  10. package/dist/cjs/handler/history/index.js +19 -0
  11. package/dist/cjs/hooks/history.js +454 -0
  12. package/dist/cjs/hooks/index.js +62 -1
  13. package/dist/cjs/host/ChaynsHost.js +113 -54
  14. package/dist/cjs/host/iframe/HostIframe.js +70 -5
  15. package/dist/cjs/host/module/ModuleHost.js +50 -44
  16. package/dist/cjs/index.js +139 -6
  17. package/dist/cjs/types/history.js +1 -0
  18. package/dist/cjs/umd.index.js +2 -2
  19. package/dist/cjs/utils/EventBus.js +33 -0
  20. package/dist/cjs/{util → utils}/appStorage.js +2 -2
  21. package/dist/cjs/utils/equality.js +19 -0
  22. package/dist/cjs/utils/history/BlockRegistry.js +110 -0
  23. package/dist/cjs/utils/history/NavigationQueue.js +388 -0
  24. package/dist/cjs/utils/history/layerTree.js +32 -0
  25. package/dist/cjs/utils/history/navigationIndex.js +42 -0
  26. package/dist/cjs/utils/history/rootLayer.js +175 -0
  27. package/dist/cjs/utils/history/segments.js +15 -0
  28. package/dist/cjs/utils/history/stateProjector.js +156 -0
  29. package/dist/cjs/utils/history/url.js +47 -0
  30. package/dist/cjs/utils/history/window.js +9 -0
  31. package/dist/cjs/wrapper/AppWrapper.js +23 -23
  32. package/dist/cjs/wrapper/FrameWrapper.js +35 -2
  33. package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -0
  34. package/dist/cjs/wrapper/StaticChaynsApi.js +1 -1
  35. package/dist/esm/calls/index.js +2 -0
  36. package/dist/esm/calls/visibilityChangeListener.js +1 -1
  37. package/dist/esm/components/ChaynsProvider.js +34 -6
  38. package/dist/esm/components/withHydrationBoundary.js +1 -1
  39. package/dist/esm/constants/index.js +1 -3
  40. package/dist/esm/contexts/HistoryLayerContext.js +76 -0
  41. package/dist/esm/contexts/index.js +3 -0
  42. package/dist/esm/handler/history/FrameHistoryLayer.js +105 -0
  43. package/dist/esm/handler/history/HistoryLayer.js +321 -0
  44. package/dist/esm/handler/history/index.js +2 -0
  45. package/dist/esm/hooks/history.js +428 -0
  46. package/dist/esm/hooks/index.js +2 -1
  47. package/dist/esm/host/ChaynsHost.js +113 -54
  48. package/dist/esm/host/iframe/HostIframe.js +70 -5
  49. package/dist/esm/host/module/ModuleHost.js +50 -44
  50. package/dist/esm/index.js +15 -6
  51. package/dist/esm/types/history.js +1 -0
  52. package/dist/esm/umd.index.js +2 -2
  53. package/dist/esm/utils/EventBus.js +31 -0
  54. package/dist/esm/{util → utils}/appStorage.js +1 -1
  55. package/dist/esm/utils/equality.js +12 -0
  56. package/dist/esm/utils/history/BlockRegistry.js +108 -0
  57. package/dist/esm/utils/history/NavigationQueue.js +385 -0
  58. package/dist/esm/utils/history/layerTree.js +24 -0
  59. package/dist/esm/utils/history/navigationIndex.js +33 -0
  60. package/dist/esm/utils/history/rootLayer.js +167 -0
  61. package/dist/esm/utils/history/segments.js +7 -0
  62. package/dist/esm/utils/history/stateProjector.js +147 -0
  63. package/dist/esm/utils/history/url.js +40 -0
  64. package/dist/esm/utils/history/window.js +3 -0
  65. package/dist/esm/wrapper/AppWrapper.js +5 -5
  66. package/dist/esm/wrapper/FrameWrapper.js +35 -2
  67. package/dist/esm/wrapper/ModuleFederationWrapper.js +2 -0
  68. package/dist/esm/wrapper/StaticChaynsApi.js +2 -1
  69. package/dist/types/calls/index.d.ts +5 -0
  70. package/dist/types/components/ChaynsProvider.d.ts +21 -0
  71. package/dist/types/constants/index.d.ts +0 -2
  72. package/dist/types/contexts/HistoryLayerContext.d.ts +33 -0
  73. package/dist/types/contexts/index.d.ts +3 -0
  74. package/dist/types/handler/history/FrameHistoryLayer.d.ts +99 -0
  75. package/dist/types/handler/history/HistoryLayer.d.ts +117 -0
  76. package/dist/types/handler/history/index.d.ts +2 -0
  77. package/dist/types/hooks/history.d.ts +89 -0
  78. package/dist/types/hooks/index.d.ts +1 -0
  79. package/dist/types/host/ChaynsHost.d.ts +12 -0
  80. package/dist/types/host/iframe/HostIframe.d.ts +4 -0
  81. package/dist/types/host/module/ModuleHost.d.ts +4 -0
  82. package/dist/types/index.d.ts +15 -6
  83. package/dist/types/types/IChaynsReact.d.ts +3 -0
  84. package/dist/types/types/history.d.ts +74 -0
  85. package/dist/types/umd.index.d.ts +2 -2
  86. package/dist/types/utils/EventBus.d.ts +10 -0
  87. package/dist/types/{util → utils}/collectCssChunks.d.ts +1 -1
  88. package/dist/types/utils/equality.d.ts +2 -0
  89. package/dist/types/utils/history/BlockRegistry.d.ts +38 -0
  90. package/dist/types/utils/history/NavigationQueue.d.ts +109 -0
  91. package/dist/types/utils/history/layerTree.d.ts +10 -0
  92. package/dist/types/utils/history/navigationIndex.d.ts +14 -0
  93. package/dist/types/utils/history/rootLayer.d.ts +42 -0
  94. package/dist/types/utils/history/segments.d.ts +2 -0
  95. package/dist/types/utils/history/stateProjector.d.ts +24 -0
  96. package/dist/types/utils/history/url.d.ts +17 -0
  97. package/dist/types/utils/history/window.d.ts +1 -0
  98. package/dist/types/wrapper/FrameWrapper.d.ts +1 -0
  99. package/dist/types/wrapper/StaticChaynsApi.d.ts +1 -0
  100. package/package.json +2 -1
  101. /package/dist/cjs/{constants → contexts}/hydrationContext.js +0 -0
  102. /package/dist/cjs/{constants → contexts}/moduleContext.js +0 -0
  103. /package/dist/cjs/{helper/apiListenerHelper.js → utils/apiListener.js} +0 -0
  104. /package/dist/cjs/{util → utils}/appCall.js +0 -0
  105. /package/dist/cjs/{util → utils}/bindChaynsApi.js +0 -0
  106. /package/dist/cjs/{util → utils}/collectCssChunks.js +0 -0
  107. /package/dist/cjs/{util → utils}/deviceHelper.js +0 -0
  108. /package/dist/cjs/{util → utils}/heightHelper.js +0 -0
  109. /package/dist/cjs/{util → utils}/initModuleFederationSharing.js +0 -0
  110. /package/dist/cjs/{util → utils}/is.js +0 -0
  111. /package/dist/cjs/{util → utils}/postIframeForm.js +0 -0
  112. /package/dist/cjs/{util → utils}/transferNestedFunctions.js +0 -0
  113. /package/dist/cjs/{util → utils}/url.js +0 -0
  114. /package/dist/esm/{constants → contexts}/hydrationContext.js +0 -0
  115. /package/dist/esm/{constants → contexts}/moduleContext.js +0 -0
  116. /package/dist/esm/{helper/apiListenerHelper.js → utils/apiListener.js} +0 -0
  117. /package/dist/esm/{util → utils}/appCall.js +0 -0
  118. /package/dist/esm/{util → utils}/bindChaynsApi.js +0 -0
  119. /package/dist/esm/{util → utils}/collectCssChunks.js +0 -0
  120. /package/dist/esm/{util → utils}/deviceHelper.js +0 -0
  121. /package/dist/esm/{util → utils}/heightHelper.js +0 -0
  122. /package/dist/esm/{util → utils}/initModuleFederationSharing.js +0 -0
  123. /package/dist/esm/{util → utils}/is.js +0 -0
  124. /package/dist/esm/{util → utils}/postIframeForm.js +0 -0
  125. /package/dist/esm/{util → utils}/transferNestedFunctions.js +0 -0
  126. /package/dist/esm/{util → utils}/url.js +0 -0
  127. /package/dist/types/{constants → contexts}/hydrationContext.d.ts +0 -0
  128. /package/dist/types/{constants → contexts}/moduleContext.d.ts +0 -0
  129. /package/dist/types/{helper/apiListenerHelper.d.ts → utils/apiListener.d.ts} +0 -0
  130. /package/dist/types/{util → utils}/appCall.d.ts +0 -0
  131. /package/dist/types/{util → utils}/appStorage.d.ts +0 -0
  132. /package/dist/types/{util → utils}/bindChaynsApi.d.ts +0 -0
  133. /package/dist/types/{util → utils}/deviceHelper.d.ts +0 -0
  134. /package/dist/types/{util → utils}/heightHelper.d.ts +0 -0
  135. /package/dist/types/{util → utils}/initModuleFederationSharing.d.ts +0 -0
  136. /package/dist/types/{util → utils}/is.d.ts +0 -0
  137. /package/dist/types/{util → utils}/postIframeForm.d.ts +0 -0
  138. /package/dist/types/{util → utils}/transferNestedFunctions.d.ts +0 -0
  139. /package/dist/types/{util → utils}/url.d.ts +0 -0
@@ -0,0 +1,105 @@
1
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ import { EventBus } from '../../utils/EventBus';
5
+ import { shallowEqualArr } from '../../utils/equality';
6
+ import { normalizeHistoryRouteInput, normalizeHistorySegments } from '../../utils/history/segments';
7
+ export class FrameHistoryLayer {
8
+ constructor(bridge, initial) {
9
+ _defineProperty(this, "id", void 0);
10
+ _defineProperty(this, "depth", void 0);
11
+ _defineProperty(this, "_segments", void 0);
12
+ _defineProperty(this, "_params", void 0);
13
+ _defineProperty(this, "_hash", void 0);
14
+ _defineProperty(this, "_state", void 0);
15
+ _defineProperty(this, "_activeChildId", void 0);
16
+ _defineProperty(this, "_segmentCount", void 0);
17
+ _defineProperty(this, "bus", new EventBus());
18
+ _defineProperty(this, "bridge", void 0);
19
+ this.id = initial.id;
20
+ this.depth = initial.depth;
21
+ this._segments = normalizeHistorySegments(initial.segments);
22
+ this._params = initial.params;
23
+ this._hash = initial.hash;
24
+ this._state = initial.state;
25
+ this._activeChildId = initial.activeChildId;
26
+ this._segmentCount = initial.segmentCount;
27
+ this.bridge = bridge;
28
+ }
29
+ getSegmentCount() {
30
+ return this._segmentCount;
31
+ }
32
+ setSegmentCount(n) {
33
+ if (n === this._segmentCount) {
34
+ return;
35
+ }
36
+ this._segmentCount = n;
37
+ void this.bridge.setSegmentCount(n);
38
+ }
39
+ createChildLayer(_id) {
40
+ throw new Error('[chaynsHistory] FrameHistoryLayer does not support createChildLayer. ' + 'Manage sub-routing within the iframe with a local initRootChaynsHistoryLayer.');
41
+ }
42
+ destroyChildLayer(_id) {}
43
+ setActiveChild(id, init) {
44
+ return this.bridge.setActiveChild(id, init);
45
+ }
46
+ getActiveChildId() {
47
+ return this._activeChildId;
48
+ }
49
+ getChildLayer(_id) {
50
+ return undefined;
51
+ }
52
+ getRoute() {
53
+ return [...this._segments];
54
+ }
55
+ setRoute(route, opts) {
56
+ const normalizedRoute = normalizeHistoryRouteInput(route);
57
+ if (shallowEqualArr(this._segments, normalizedRoute)) {
58
+ return;
59
+ }
60
+ void this.bridge.setRoute(normalizedRoute, opts);
61
+ }
62
+ getParams() {
63
+ return {
64
+ ...this._params
65
+ };
66
+ }
67
+ setParams(params, opts) {
68
+ void this.bridge.setParams(params, opts);
69
+ }
70
+ getHash() {
71
+ return this._hash;
72
+ }
73
+ setHash(hash, opts) {
74
+ void this.bridge.setHash(hash, opts);
75
+ }
76
+ getState() {
77
+ return this._state;
78
+ }
79
+ setState(state, opts) {
80
+ void this.bridge.setState(state, opts);
81
+ }
82
+ navigate(opts) {
83
+ return this.bridge.navigate(opts);
84
+ }
85
+ addBlock(callback, opts) {
86
+ let removeFn = null;
87
+ void this.bridge.addBlock(callback, opts).then(fn => {
88
+ removeFn = fn;
89
+ });
90
+ return () => {
91
+ var _removeFn;
92
+ return (_removeFn = removeFn) === null || _removeFn === void 0 ? void 0 : _removeFn();
93
+ };
94
+ }
95
+ addEventListener(type, handler) {
96
+ return this.bus.on(type, handler);
97
+ }
98
+ _applyAndEmit(e) {
99
+ this._segments = normalizeHistorySegments(e.segments);
100
+ this._params = e.params;
101
+ this._hash = e.hash;
102
+ this._state = e.state;
103
+ this.bus.emit(e.type, e);
104
+ }
105
+ }
@@ -0,0 +1,321 @@
1
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ import { EventBus } from '../../utils/EventBus';
5
+ import { resolveSegmentsFrom } from '../../utils/history/rootLayer';
6
+ import { normalizeHistoryRouteInput, normalizeHistorySegments } from '../../utils/history/segments';
7
+ const RESERVED_STATE_KEYS = ['activeChild', 'childState', '__params', '__hash'];
8
+ export class ChaynsHistoryLayer {
9
+ constructor(init) {
10
+ var _init$segmentCount, _init$segments;
11
+ _defineProperty(this, "id", void 0);
12
+ _defineProperty(this, "depth", void 0);
13
+ _defineProperty(this, "parent", void 0);
14
+ _defineProperty(this, "children", new Map());
15
+ _defineProperty(this, "activeChildId", null);
16
+ _defineProperty(this, "segmentCount", 0);
17
+ _defineProperty(this, "segments", []);
18
+ _defineProperty(this, "ownState", {});
19
+ _defineProperty(this, "_params", {});
20
+ _defineProperty(this, "_hash", undefined);
21
+ _defineProperty(this, "bus", new EventBus());
22
+ _defineProperty(this, "deps", void 0);
23
+ _defineProperty(this, "_bootstrapPool", null);
24
+ _defineProperty(this, "_bootstrapUrlResolver", null);
25
+ _defineProperty(this, "isDestroyed", false);
26
+ this.id = init.id;
27
+ this.parent = init.parent;
28
+ this.depth = init.parent ? init.parent.depth + 1 : 0;
29
+ this.deps = init.deps;
30
+ this.segmentCount = (_init$segmentCount = init.segmentCount) !== null && _init$segmentCount !== void 0 ? _init$segmentCount : 0;
31
+ this.segments = normalizeHistorySegments((_init$segments = init.segments) !== null && _init$segments !== void 0 ? _init$segments : []);
32
+ }
33
+ getSegmentCount() {
34
+ return this.segmentCount;
35
+ }
36
+ setSegmentCount(n) {
37
+ if (n < 0 || !Number.isInteger(n)) {
38
+ return;
39
+ }
40
+ const prev = this.segmentCount;
41
+ if (n === prev) {
42
+ return;
43
+ }
44
+ this.segmentCount = n;
45
+ if (this._isInActiveChain()) {
46
+ if (n < prev) {
47
+ const excess = this.segments.splice(n);
48
+ if (excess.length > 0 && this.activeChildId) {
49
+ const child = this.children.get(this.activeChildId);
50
+ if (child) {
51
+ child._setOwnSegmentsSilent([...excess, ...child._getOwnSegments()]);
52
+ }
53
+ }
54
+ } else if (n > prev && this.segments.length === 0) {
55
+ const root = this.deps.getRoot();
56
+ const bootstrapSegs = root._consumeBootstrapSegments(n);
57
+ if (bootstrapSegs) {
58
+ this.segments = normalizeHistorySegments(bootstrapSegs);
59
+ }
60
+ }
61
+ void this.deps.getQueue().enqueue({
62
+ kind: 'setRoute',
63
+ layerId: this.id,
64
+ segments: [...this.segments],
65
+ opts: {},
66
+ _notifyEvenIfUnchanged: true,
67
+ _skipCommit: true
68
+ });
69
+ }
70
+ }
71
+ createChildLayer(id) {
72
+ if (this.children.has(id)) {
73
+ throw new Error(`[chaynsHistory] Child layer with id "${id}" already exists on layer "${this.id}".`);
74
+ }
75
+ const segments = resolveSegmentsFrom(undefined, this.getCumulativeSegmentCount());
76
+ const child = new ChaynsHistoryLayer({
77
+ id,
78
+ parent: this,
79
+ deps: this.deps,
80
+ segments,
81
+ segmentCount: segments.length
82
+ });
83
+ this.children.set(id, child);
84
+ return child;
85
+ }
86
+ destroyChildLayer(id) {
87
+ const child = this.children.get(id);
88
+ if (!child) return;
89
+ child.markDestroyed();
90
+ this.children.delete(id);
91
+ if (this.activeChildId === id) {
92
+ void this.deps.getQueue().enqueue({
93
+ kind: 'setActiveChild',
94
+ layerId: this.id,
95
+ childId: null
96
+ });
97
+ }
98
+ }
99
+ getChildLayer(id) {
100
+ return this.children.get(id);
101
+ }
102
+ getActiveChildId() {
103
+ return this.activeChildId;
104
+ }
105
+ setActiveChild(id, init) {
106
+ if (this.isDestroyed) return Promise.resolve({
107
+ isOk: false,
108
+ reason: 'destroyed'
109
+ });
110
+ return this.deps.getQueue().enqueue({
111
+ kind: 'setActiveChild',
112
+ layerId: this.id,
113
+ childId: id,
114
+ init: init ? {
115
+ ...init,
116
+ route: init.route !== undefined ? ChaynsHistoryLayer.normalizeRoute(init.route) : undefined
117
+ } : undefined
118
+ });
119
+ }
120
+ getRoute() {
121
+ return [...this.segments];
122
+ }
123
+ setRoute(route, opts) {
124
+ if (this.isDestroyed) return;
125
+ void this.deps.getQueue().enqueue({
126
+ kind: 'setRoute',
127
+ layerId: this.id,
128
+ segments: ChaynsHistoryLayer.normalizeRoute(route),
129
+ opts: opts !== null && opts !== void 0 ? opts : {}
130
+ });
131
+ }
132
+ getParams() {
133
+ return {
134
+ ...this._params
135
+ };
136
+ }
137
+ setParams(params, opts) {
138
+ if (this.isDestroyed) return;
139
+ void this.deps.getQueue().enqueue({
140
+ kind: 'setParams',
141
+ layerId: this.id,
142
+ params: {
143
+ ...params
144
+ },
145
+ opts: opts !== null && opts !== void 0 ? opts : {}
146
+ });
147
+ }
148
+ getHash() {
149
+ var _this$_hash;
150
+ return (_this$_hash = this._hash) !== null && _this$_hash !== void 0 ? _this$_hash : '';
151
+ }
152
+ setHash(hash, opts) {
153
+ if (this.isDestroyed) return;
154
+ const normalized = hash.startsWith('#') ? hash.slice(1) : hash;
155
+ void this.deps.getQueue().enqueue({
156
+ kind: 'setHash',
157
+ layerId: this.id,
158
+ hash: normalized,
159
+ opts: opts !== null && opts !== void 0 ? opts : {}
160
+ });
161
+ }
162
+ getState() {
163
+ return {
164
+ ...this.ownState
165
+ };
166
+ }
167
+ setState(state, opts) {
168
+ if (this.isDestroyed) return;
169
+ const filtered = ChaynsHistoryLayer.filterReservedKeys(state);
170
+ void this.deps.getQueue().enqueue({
171
+ kind: 'setState',
172
+ layerId: this.id,
173
+ state: filtered,
174
+ opts: opts !== null && opts !== void 0 ? opts : {}
175
+ });
176
+ }
177
+ navigate(opts) {
178
+ if (this.isDestroyed) return Promise.resolve({
179
+ isOk: false,
180
+ reason: 'destroyed'
181
+ });
182
+ const {
183
+ route,
184
+ state,
185
+ params,
186
+ hash,
187
+ activeChild,
188
+ activeChildInit,
189
+ ...rest
190
+ } = opts;
191
+ return this.deps.getQueue().enqueue({
192
+ kind: 'navigate',
193
+ layerId: this.id,
194
+ route: route !== undefined ? ChaynsHistoryLayer.normalizeRoute(route) : undefined,
195
+ state: state ? ChaynsHistoryLayer.filterReservedKeys(state) : undefined,
196
+ params,
197
+ hash: hash !== undefined ? hash.startsWith('#') ? hash.slice(1) : hash : undefined,
198
+ activeChild,
199
+ activeChildInit: activeChildInit ? {
200
+ ...activeChildInit,
201
+ route: activeChildInit.route !== undefined ? ChaynsHistoryLayer.normalizeRoute(activeChildInit.route) : undefined
202
+ } : undefined,
203
+ opts: rest
204
+ });
205
+ }
206
+ addBlock(callback, opts = {}) {
207
+ return this.deps.getBlockRegistry().add(this, callback, opts);
208
+ }
209
+ addEventListener(type, handler) {
210
+ return this.bus.on(type, handler);
211
+ }
212
+ _getOwnState() {
213
+ return this.ownState;
214
+ }
215
+ _getOwnSegments() {
216
+ return this.segments;
217
+ }
218
+ _getChildren() {
219
+ return this.children;
220
+ }
221
+ _setOwnStateSilent(next) {
222
+ this.ownState = ChaynsHistoryLayer.filterReservedKeys(next);
223
+ }
224
+ _setOwnSegmentsSilent(next) {
225
+ this.segments = normalizeHistorySegments(next);
226
+ }
227
+ _getOwnParams() {
228
+ return this._params;
229
+ }
230
+ _setOwnParamsSilent(params) {
231
+ this._params = {
232
+ ...params
233
+ };
234
+ }
235
+ _getOwnHash() {
236
+ return this._hash;
237
+ }
238
+ _setOwnHashSilent(hash) {
239
+ this._hash = hash;
240
+ }
241
+ _setActiveChildSilent(id) {
242
+ this.activeChildId = id;
243
+ }
244
+ _emit(type) {
245
+ var _this$_hash2;
246
+ const event = {
247
+ type,
248
+ layerId: this.id,
249
+ segments: [...this.segments],
250
+ state: {
251
+ ...this.ownState
252
+ },
253
+ params: {
254
+ ...this._params
255
+ },
256
+ hash: (_this$_hash2 = this._hash) !== null && _this$_hash2 !== void 0 ? _this$_hash2 : ''
257
+ };
258
+ this.bus.emit(type, event);
259
+ }
260
+ _isInActiveChain() {
261
+ let node = this;
262
+ while (node && node.parent) {
263
+ if (node.parent.activeChildId !== node.id) return false;
264
+ node = node.parent;
265
+ }
266
+ return true;
267
+ }
268
+ _setBootstrapUrlResolver(resolver) {
269
+ this._bootstrapUrlResolver = resolver;
270
+ }
271
+ _setBootstrapPool(segs) {
272
+ this._bootstrapPool = [...segs];
273
+ }
274
+ _consumeBootstrapSegments(n) {
275
+ if (this._bootstrapPool === null && this._bootstrapUrlResolver) {
276
+ const pathname = this._bootstrapUrlResolver();
277
+ this._bootstrapPool = pathname.replace(/^\//, '').split('/').filter(Boolean);
278
+ this._bootstrapUrlResolver = null;
279
+ }
280
+ if (!this._bootstrapPool || this._bootstrapPool.length === 0 || n === 0) return null;
281
+ const taken = this._bootstrapPool.splice(0, n);
282
+ while (taken.length < n) taken.push('');
283
+ return taken;
284
+ }
285
+ _isDestroyed() {
286
+ return this.isDestroyed;
287
+ }
288
+ markDestroyed() {
289
+ this.isDestroyed = true;
290
+ try {
291
+ this.deps.getBlockRegistry().removeAllForLayer(this.id);
292
+ } catch {}
293
+ for (const child of this.children.values()) {
294
+ child.markDestroyed();
295
+ }
296
+ this.children.clear();
297
+ this.bus.clear();
298
+ }
299
+ getCumulativeSegmentCount() {
300
+ let count = this.segmentCount;
301
+ let node = this.parent;
302
+ while (node) {
303
+ count += node.segmentCount;
304
+ node = node.parent;
305
+ }
306
+ return count;
307
+ }
308
+ static normalizeRoute(route) {
309
+ return normalizeHistoryRouteInput(route);
310
+ }
311
+ static filterReservedKeys(input) {
312
+ const out = {};
313
+ for (const key of Object.keys(input)) {
314
+ if (RESERVED_STATE_KEYS.includes(key)) {
315
+ continue;
316
+ }
317
+ out[key] = input[key];
318
+ }
319
+ return out;
320
+ }
321
+ }
@@ -0,0 +1,2 @@
1
+ export { ChaynsHistoryLayer as ChaynsHistoryLayerClass } from './HistoryLayer';
2
+ export { FrameHistoryLayer } from './FrameHistoryLayer';