@alfalab/bridge-to-native 1.3.2-beta.0828f8f → 1.3.2-beta.16c7b6a
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint max-lines: ["error", {"max":
|
|
2
|
+
/* eslint max-lines: ["error", {"max": 400, "skipComments": true}] */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.NativeNavigationAndTitleService = void 0;
|
|
5
5
|
const query_and_headers_keys_1 = require("../../query-and-headers-keys");
|
|
@@ -148,22 +148,38 @@ class NativeNavigationAndTitleService {
|
|
|
148
148
|
initializeNativeHistoryStack() {
|
|
149
149
|
const { nextPageId, title } = this.nativeParamsService;
|
|
150
150
|
const hasSS = this.hasSavedHistoryStack();
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
151
|
+
console.log('⬇️⬇️⬇️⬇️⬇️');
|
|
152
|
+
console.log('Инициализируюсь');
|
|
153
|
+
try {
|
|
154
|
+
if (nextPageId && !hasSS) {
|
|
155
|
+
console.log(`Есть nextPageId (${nextPageId}) + нет SS → на этом origin ранее не были.`);
|
|
156
|
+
this.nativeHistoryStack = this.initializeForNewOrigin(nextPageId, title);
|
|
157
|
+
}
|
|
158
|
+
else if (nextPageId && hasSS) {
|
|
159
|
+
const savedStack = this.readSavedHistoryStack();
|
|
160
|
+
if (savedStack.length > nextPageId) {
|
|
161
|
+
console.log(`Есть nextPageId (${nextPageId}) + есть SS длиннее nextPageId → back навигация.`);
|
|
162
|
+
this.nativeHistoryStack = this.initializeFromBackwardOrReload(title);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
console.log(`Есть nextPageId (${nextPageId}) + есть SS равный или короче nextPageId → forward навигация.`);
|
|
166
|
+
this.nativeHistoryStack = this.initializeForForward(nextPageId, title);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (!nextPageId && hasSS) {
|
|
170
|
+
console.log('Нет nextPageId + есть SS → back-навигация или reload.');
|
|
171
|
+
this.nativeHistoryStack = this.initializeFromBackwardOrReload(title);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.log('Нет nextPageId + нет SS → старт нового WV, назад идти некуда.');
|
|
175
|
+
this.nativeHistoryStack = [title];
|
|
176
|
+
}
|
|
162
177
|
}
|
|
163
|
-
|
|
164
|
-
// нет nextPageId + нет SS → старт нового WV, назад идти некуда.
|
|
178
|
+
catch (_a) {
|
|
165
179
|
this.nativeHistoryStack = [title];
|
|
166
180
|
}
|
|
181
|
+
console.log('this.nativeHistoryStack', '➡️', this.nativeHistoryStack);
|
|
182
|
+
console.log('⬆️⬆️⬆️⬆️⬆️');
|
|
167
183
|
this.saveNativeHistoryStack();
|
|
168
184
|
this.syncHistoryWithNative();
|
|
169
185
|
}
|
|
@@ -174,51 +190,33 @@ class NativeNavigationAndTitleService {
|
|
|
174
190
|
return stack;
|
|
175
191
|
}
|
|
176
192
|
initializeForForward(nextPageId, title) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
stack[i] = savedStack[i];
|
|
185
|
-
}
|
|
186
|
-
stack[stack.length - 1] = title;
|
|
187
|
-
return stack;
|
|
193
|
+
const savedStack = this.readSavedHistoryStack();
|
|
194
|
+
const lastSaved = savedStack[savedStack.length - 1];
|
|
195
|
+
if (lastSaved === 2 /* NativeHistoryStackSpecialValues.ServerSideNavigationNextOrigin */ &&
|
|
196
|
+
savedStack.length < nextPageId) {
|
|
197
|
+
const stack = new Array(nextPageId).fill(0 /* NativeHistoryStackSpecialValues.ServerSideNavigationStub */);
|
|
198
|
+
for (let i = 0; i < savedStack.length; i++) {
|
|
199
|
+
stack[i] = savedStack[i];
|
|
188
200
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return savedStack;
|
|
192
|
-
}
|
|
193
|
-
return this.initializeForNewOrigin(nextPageId, title);
|
|
201
|
+
stack[stack.length - 1] = title;
|
|
202
|
+
return stack;
|
|
194
203
|
}
|
|
195
|
-
|
|
196
|
-
|
|
204
|
+
if (savedStack.length === nextPageId) {
|
|
205
|
+
savedStack[savedStack.length - 1] = title;
|
|
206
|
+
return savedStack;
|
|
197
207
|
}
|
|
208
|
+
return this.initializeForNewOrigin(nextPageId, title);
|
|
198
209
|
}
|
|
199
210
|
initializeFromBackwardOrReload(title) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (lastEntry === 1 /* NativeHistoryStackSpecialValues.TemporaryReloadStub */) {
|
|
204
|
-
savedStack.pop();
|
|
205
|
-
if (savedStack.length === 0) {
|
|
206
|
-
return [title];
|
|
207
|
-
}
|
|
208
|
-
return savedStack;
|
|
209
|
-
}
|
|
210
|
-
if (this.stackContainsCrossOriginMarker(savedStack)) {
|
|
211
|
-
return this.truncateToLastCrossOriginMarker(savedStack);
|
|
212
|
-
}
|
|
213
|
-
savedStack.pop();
|
|
214
|
-
if (savedStack.length === 0) {
|
|
215
|
-
return [title];
|
|
216
|
-
}
|
|
217
|
-
return savedStack;
|
|
218
|
-
}
|
|
219
|
-
catch (_a) {
|
|
211
|
+
const savedStack = this.readSavedHistoryStack();
|
|
212
|
+
savedStack.pop();
|
|
213
|
+
if (savedStack.length === 0) {
|
|
220
214
|
return [title];
|
|
221
215
|
}
|
|
216
|
+
if (typeof savedStack[savedStack.length - 1] !== 'string') {
|
|
217
|
+
return this.truncateToLastCrossOriginMarker(savedStack);
|
|
218
|
+
}
|
|
219
|
+
return savedStack;
|
|
222
220
|
}
|
|
223
221
|
// eslint-disable-next-line class-methods-use-this -- удобней использовать метод в контексте экземпляра.
|
|
224
222
|
stackContainsCrossOriginMarker(stack) {
|
|
@@ -239,6 +237,10 @@ class NativeNavigationAndTitleService {
|
|
|
239
237
|
*/
|
|
240
238
|
readSavedHistoryStack() {
|
|
241
239
|
const serialized = sessionStorage.getItem(query_and_headers_keys_1.SS_KEY_BRIDGE_TO_NATIVE_HISTORY_STACK);
|
|
240
|
+
console.log('⬇️⬇️⬇️⬇️⬇️');
|
|
241
|
+
console.log('Читаю стек из SessionStorage');
|
|
242
|
+
console.log('SessionStorage', '➡️', serialized);
|
|
243
|
+
console.log('⬆️⬆️⬆️⬆️⬆️');
|
|
242
244
|
try {
|
|
243
245
|
if (!serialized) {
|
|
244
246
|
throw new Error(`${query_and_headers_keys_1.SS_KEY_BRIDGE_TO_NATIVE_HISTORY_STACK} sessionStorage expected not to be null`);
|
|
@@ -282,6 +284,10 @@ class NativeNavigationAndTitleService {
|
|
|
282
284
|
*/
|
|
283
285
|
saveNativeHistoryStack() {
|
|
284
286
|
const serializedNativeHistoryStack = JSON.stringify(this.nativeHistoryStack);
|
|
287
|
+
console.log('⬇️⬇️⬇️⬇️⬇️');
|
|
288
|
+
console.log('Сохраняю стек в SessionStorage');
|
|
289
|
+
console.log(this.nativeHistoryStack, '➡️', serializedNativeHistoryStack);
|
|
290
|
+
console.log('⬆️⬆️⬆️⬆️⬆️');
|
|
285
291
|
sessionStorage.setItem(query_and_headers_keys_1.SS_KEY_BRIDGE_TO_NATIVE_HISTORY_STACK, serializedNativeHistoryStack);
|
|
286
292
|
}
|
|
287
293
|
/**
|
package/package.json
CHANGED