gyosjs 0.4.0 → 0.5.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/README.md +3 -1
- package/dist/core/component.d.ts.map +1 -1
- package/dist/core/router/persist.d.ts.map +1 -1
- package/dist/core/router/router.d.ts +20 -2
- package/dist/core/router/router.d.ts.map +1 -1
- package/dist/gyos.auto.esm.js +228 -80
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +228 -80
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +228 -80
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +228 -80
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +229 -81
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +230 -80
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +229 -81
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +230 -80
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/public-api.d.ts +5 -3
- package/dist/public-api.d.ts.map +1 -1
- package/dist/reactivity/signal.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/gyos.csp.auto.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.
|
|
2
|
+
* GyosJS v0.5.0
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -189,10 +189,35 @@
|
|
|
189
189
|
* count.value++; // Triggers effect
|
|
190
190
|
* ```
|
|
191
191
|
*/
|
|
192
|
-
/**
|
|
193
|
-
* Current effect being tracked
|
|
194
|
-
*/
|
|
195
192
|
let currentEffect = null;
|
|
193
|
+
function track(source) {
|
|
194
|
+
if (!currentEffect)
|
|
195
|
+
return;
|
|
196
|
+
source.subscribers.add(currentEffect);
|
|
197
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
198
|
+
currentEffect.__versions?.set(source, source.version);
|
|
199
|
+
}
|
|
200
|
+
function dependenciesChanged(versions) {
|
|
201
|
+
return untrack(() => {
|
|
202
|
+
for (const [source, version] of versions) {
|
|
203
|
+
source.refresh?.();
|
|
204
|
+
if (source.version !== version)
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
211
|
+
function notifySubscribers(subscribers) {
|
|
212
|
+
for (const sub of Array.from(subscribers)) {
|
|
213
|
+
if (sub.__invalidate)
|
|
214
|
+
sub();
|
|
215
|
+
else if (isBatching)
|
|
216
|
+
batchedEffects.add(sub);
|
|
217
|
+
else
|
|
218
|
+
queueEffect(sub);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
196
221
|
// Simple counter for debug-friendly IDs
|
|
197
222
|
let signalIdCounter = 0;
|
|
198
223
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -230,6 +255,9 @@
|
|
|
230
255
|
}
|
|
231
256
|
});
|
|
232
257
|
isFlushingQueue = false;
|
|
258
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
259
|
+
if (effectQueue.size > 0)
|
|
260
|
+
queueMicrotask(flushEffectQueue);
|
|
233
261
|
}
|
|
234
262
|
/**
|
|
235
263
|
* Queue an effect for execution in next microtask
|
|
@@ -288,17 +316,14 @@
|
|
|
288
316
|
const debugId = ++signalIdCounter;
|
|
289
317
|
let value = initialValue;
|
|
290
318
|
const subscribers = new Set();
|
|
319
|
+
const source = { subscribers, version: 0 };
|
|
291
320
|
let warnedSubscribers = false;
|
|
292
321
|
const read = () => {
|
|
293
322
|
// Track dependency
|
|
294
323
|
if (currentEffect) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
299
|
-
if (currentEffect.__dependencies) {
|
|
300
|
-
currentEffect.__dependencies.add(subscribers);
|
|
301
|
-
}
|
|
324
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
325
|
+
track(source);
|
|
326
|
+
if (!wasSubscribed) {
|
|
302
327
|
if (DEBUG_VERBOSE()) {
|
|
303
328
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
304
329
|
}
|
|
@@ -317,18 +342,13 @@
|
|
|
317
342
|
// For objects/arrays, check if it's actually the same reference
|
|
318
343
|
// Deep equality is expensive, let user handle it
|
|
319
344
|
value = newValue;
|
|
345
|
+
source.version++;
|
|
320
346
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
321
347
|
notify();
|
|
322
348
|
};
|
|
323
349
|
const notify = () => {
|
|
324
350
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
325
|
-
|
|
326
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
// Always queue effects to prevent cascading updates
|
|
330
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
331
|
-
}
|
|
351
|
+
notifySubscribers(subscribers);
|
|
332
352
|
};
|
|
333
353
|
// Create callable signal (like Angular/SolidJS)
|
|
334
354
|
// Call without args = read, call with arg = write
|
|
@@ -363,8 +383,16 @@
|
|
|
363
383
|
},
|
|
364
384
|
subscribe: {
|
|
365
385
|
value: function (fn) {
|
|
366
|
-
|
|
367
|
-
|
|
386
|
+
let active = true;
|
|
387
|
+
const callback = () => { if (active)
|
|
388
|
+
untrack(fn); };
|
|
389
|
+
subscribers.add(callback);
|
|
390
|
+
return () => {
|
|
391
|
+
active = false;
|
|
392
|
+
subscribers.delete(callback);
|
|
393
|
+
effectQueue.delete(callback);
|
|
394
|
+
batchedEffects.delete(callback);
|
|
395
|
+
};
|
|
368
396
|
},
|
|
369
397
|
enumerable: true,
|
|
370
398
|
configurable: true
|
|
@@ -424,49 +452,60 @@
|
|
|
424
452
|
let value;
|
|
425
453
|
let isDirty = true;
|
|
426
454
|
let isFirstRun = true;
|
|
455
|
+
let computing = false;
|
|
427
456
|
const subscribers = new Set();
|
|
428
|
-
|
|
457
|
+
const dependencies = new Set();
|
|
458
|
+
const versions = new Map();
|
|
459
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
460
|
+
const invalidate = () => {
|
|
461
|
+
// A later batched write must also move already queued consumers into
|
|
462
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
463
|
+
if (isDirty && !isBatching)
|
|
464
|
+
return;
|
|
465
|
+
isDirty = true;
|
|
466
|
+
notifySubscribers(subscribers);
|
|
467
|
+
};
|
|
468
|
+
invalidate.__invalidate = true;
|
|
469
|
+
invalidate.__dependencies = dependencies;
|
|
470
|
+
invalidate.__versions = versions;
|
|
429
471
|
const compute = () => {
|
|
430
472
|
if (!isDirty && !isFirstRun)
|
|
431
473
|
return;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
value = newValue;
|
|
442
|
-
isFirstRun = false;
|
|
443
|
-
isDirty = false;
|
|
444
|
-
// Notify subscribers
|
|
445
|
-
if (!isBatching) {
|
|
446
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
450
|
-
}
|
|
451
|
-
}
|
|
474
|
+
if (computing)
|
|
475
|
+
throw new Error('[Computed] Circular dependency');
|
|
476
|
+
computing = true;
|
|
477
|
+
const previousEffect = currentEffect;
|
|
478
|
+
try {
|
|
479
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
480
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
481
|
+
isDirty = false;
|
|
482
|
+
return;
|
|
452
483
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
484
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
485
|
+
dependencies.clear();
|
|
486
|
+
versions.clear();
|
|
487
|
+
currentEffect = invalidate;
|
|
488
|
+
const nextValue = fn();
|
|
489
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
490
|
+
value = nextValue;
|
|
491
|
+
source.version++;
|
|
456
492
|
}
|
|
457
|
-
|
|
458
|
-
|
|
493
|
+
isFirstRun = false;
|
|
494
|
+
isDirty = false;
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
// Preserve error isolation and the last successful value.
|
|
498
|
+
console.error('[Computed] Error in computation:', error);
|
|
499
|
+
isDirty = false;
|
|
500
|
+
}
|
|
501
|
+
finally {
|
|
502
|
+
currentEffect = previousEffect;
|
|
503
|
+
computing = false;
|
|
504
|
+
}
|
|
459
505
|
};
|
|
460
506
|
const read = () => {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
// Track dependency
|
|
464
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
465
|
-
subscribers.add(currentEffect);
|
|
466
|
-
if (currentEffect.__dependencies) {
|
|
467
|
-
currentEffect.__dependencies.add(subscribers);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
507
|
+
compute();
|
|
508
|
+
track(source);
|
|
470
509
|
return value;
|
|
471
510
|
};
|
|
472
511
|
// Create callable computed (read-only)
|
|
@@ -491,8 +530,14 @@
|
|
|
491
530
|
},
|
|
492
531
|
subscribe: {
|
|
493
532
|
value: function (fn) {
|
|
494
|
-
|
|
495
|
-
|
|
533
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
534
|
+
let first = true;
|
|
535
|
+
return effect(() => {
|
|
536
|
+
read();
|
|
537
|
+
if (!first)
|
|
538
|
+
untrack(fn);
|
|
539
|
+
first = false;
|
|
540
|
+
});
|
|
496
541
|
},
|
|
497
542
|
enumerable: true,
|
|
498
543
|
configurable: true
|
|
@@ -543,11 +588,15 @@
|
|
|
543
588
|
*/
|
|
544
589
|
function effect(fn) {
|
|
545
590
|
let cleanup;
|
|
546
|
-
|
|
591
|
+
const dependencies = new Set();
|
|
592
|
+
const versions = new Map();
|
|
547
593
|
let active = true;
|
|
594
|
+
let initialized = false;
|
|
548
595
|
const execute = () => {
|
|
549
596
|
if (!active)
|
|
550
597
|
return;
|
|
598
|
+
if (initialized && !dependenciesChanged(versions))
|
|
599
|
+
return;
|
|
551
600
|
// Prevent recursive execution - if already running, skip
|
|
552
601
|
if (runningEffects.has(execute)) {
|
|
553
602
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -562,10 +611,13 @@
|
|
|
562
611
|
});
|
|
563
612
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
564
613
|
dependencies.clear();
|
|
614
|
+
versions.clear();
|
|
565
615
|
// Clean up previous run
|
|
566
616
|
if (cleanup) {
|
|
617
|
+
const previousCleanup = cleanup;
|
|
618
|
+
cleanup = undefined;
|
|
567
619
|
try {
|
|
568
|
-
|
|
620
|
+
untrack(previousCleanup);
|
|
569
621
|
}
|
|
570
622
|
catch (error) {
|
|
571
623
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -576,6 +628,7 @@
|
|
|
576
628
|
currentEffect = execute;
|
|
577
629
|
// Store dependencies for cleanup
|
|
578
630
|
execute.__dependencies = dependencies;
|
|
631
|
+
execute.__versions = versions;
|
|
579
632
|
try {
|
|
580
633
|
const nextCleanup = fn();
|
|
581
634
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -585,6 +638,7 @@
|
|
|
585
638
|
// Don't throw - allow other effects to continue
|
|
586
639
|
}
|
|
587
640
|
finally {
|
|
641
|
+
initialized = true;
|
|
588
642
|
currentEffect = prevEffect;
|
|
589
643
|
effectDepth--;
|
|
590
644
|
runningEffects.delete(execute);
|
|
@@ -601,14 +655,17 @@
|
|
|
601
655
|
if (!active)
|
|
602
656
|
return;
|
|
603
657
|
active = false;
|
|
658
|
+
effectQueue.delete(execute);
|
|
659
|
+
batchedEffects.delete(execute);
|
|
604
660
|
// Remove from all dependencies
|
|
605
661
|
dependencies.forEach(depSet => {
|
|
606
662
|
depSet.delete(execute);
|
|
607
663
|
});
|
|
608
664
|
dependencies.clear();
|
|
665
|
+
versions.clear();
|
|
609
666
|
if (cleanup) {
|
|
610
667
|
try {
|
|
611
|
-
cleanup
|
|
668
|
+
untrack(cleanup);
|
|
612
669
|
}
|
|
613
670
|
catch (error) {
|
|
614
671
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -668,6 +725,8 @@
|
|
|
668
725
|
const effects = Array.from(batchedEffects);
|
|
669
726
|
batchedEffects.clear();
|
|
670
727
|
effects.forEach(effect => {
|
|
728
|
+
// This batch also settles any earlier queued write to this observer.
|
|
729
|
+
effectQueue.delete(effect);
|
|
671
730
|
try {
|
|
672
731
|
effect();
|
|
673
732
|
}
|
|
@@ -5577,6 +5636,21 @@
|
|
|
5577
5636
|
* Registry of all scopes
|
|
5578
5637
|
*/
|
|
5579
5638
|
const scopeRegistry = new Map();
|
|
5639
|
+
const warnedReveals = new WeakSet();
|
|
5640
|
+
function diagnoseUnscopedReveals(root) {
|
|
5641
|
+
if (!DEBUG())
|
|
5642
|
+
return;
|
|
5643
|
+
const elements = [...root.querySelectorAll('[g-reveal]')];
|
|
5644
|
+
if (root instanceof Element && root.hasAttribute('g-reveal'))
|
|
5645
|
+
elements.unshift(root);
|
|
5646
|
+
for (const element of elements) {
|
|
5647
|
+
if (warnedReveals.has(element) || isInIgnoredTree(element)
|
|
5648
|
+
|| element.closest('[g-scope]') || getScopeFromElement(element))
|
|
5649
|
+
continue;
|
|
5650
|
+
warnedReveals.add(element);
|
|
5651
|
+
console.warn('[Gyos] g-reveal has no owning scope. Add g-scope to its container; global reveal CSS may otherwise hide this content.', element);
|
|
5652
|
+
}
|
|
5653
|
+
}
|
|
5580
5654
|
/**
|
|
5581
5655
|
* Register a scope
|
|
5582
5656
|
*/
|
|
@@ -5624,6 +5698,7 @@
|
|
|
5624
5698
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5625
5699
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
5626
5700
|
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
5701
|
+
diagnoseUnscopedReveals(document.body);
|
|
5627
5702
|
}
|
|
5628
5703
|
function mountTree(el) {
|
|
5629
5704
|
if (isInIgnoredTree(el) || !document.body.contains(el))
|
|
@@ -5634,6 +5709,7 @@
|
|
|
5634
5709
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
5635
5710
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5636
5711
|
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
5712
|
+
diagnoseUnscopedReveals(el);
|
|
5637
5713
|
if (getMountedScope(el))
|
|
5638
5714
|
return;
|
|
5639
5715
|
const ownerScope = getScopeFromElement(el);
|
|
@@ -5652,7 +5728,7 @@
|
|
|
5652
5728
|
return;
|
|
5653
5729
|
// Check if element removed but still has g-scope (possible in some edge cases)
|
|
5654
5730
|
getAllMountedScopes().forEach((_, mountedEl) => {
|
|
5655
|
-
if (!
|
|
5731
|
+
if (!mountedEl.isConnected) {
|
|
5656
5732
|
disposeEffects(mountedEl);
|
|
5657
5733
|
}
|
|
5658
5734
|
});
|
|
@@ -6978,7 +7054,8 @@
|
|
|
6978
7054
|
el.dataset.gyosPersistId = key;
|
|
6979
7055
|
return key;
|
|
6980
7056
|
}
|
|
6981
|
-
//
|
|
7057
|
+
// Keep the parking host outside body: body itself may be the swap target.
|
|
7058
|
+
// A disconnected parking host makes browsers pause otherwise persisted media.
|
|
6982
7059
|
const persistParking = typeof document !== 'undefined'
|
|
6983
7060
|
? (() => {
|
|
6984
7061
|
const park = document.createElement('div');
|
|
@@ -6987,12 +7064,7 @@
|
|
|
6987
7064
|
park.style.top = '-99999px';
|
|
6988
7065
|
park.style.width = '0';
|
|
6989
7066
|
park.style.height = '0';
|
|
6990
|
-
|
|
6991
|
-
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(park));
|
|
6992
|
-
}
|
|
6993
|
-
else {
|
|
6994
|
-
document.body.appendChild(park);
|
|
6995
|
-
}
|
|
7067
|
+
document.documentElement.appendChild(park);
|
|
6996
7068
|
return park;
|
|
6997
7069
|
})()
|
|
6998
7070
|
: null;
|
|
@@ -7003,8 +7075,8 @@
|
|
|
7003
7075
|
return elements;
|
|
7004
7076
|
}
|
|
7005
7077
|
function ensureParkingIsConnected() {
|
|
7006
|
-
if (persistParking &&
|
|
7007
|
-
document.
|
|
7078
|
+
if (persistParking && persistParking.parentElement !== document.documentElement) {
|
|
7079
|
+
document.documentElement.appendChild(persistParking);
|
|
7008
7080
|
}
|
|
7009
7081
|
}
|
|
7010
7082
|
function detachPersist(root = document) {
|
|
@@ -7022,12 +7094,18 @@
|
|
|
7022
7094
|
});
|
|
7023
7095
|
}
|
|
7024
7096
|
function mergePersistIntoLive(root) {
|
|
7097
|
+
// Return the host to the current body before scope mounting/cleanup inspects it.
|
|
7098
|
+
if (persistParking && persistParking.parentElement !== document.body) {
|
|
7099
|
+
document.body.appendChild(persistParking);
|
|
7100
|
+
}
|
|
7025
7101
|
if (!persistEntries.size)
|
|
7026
7102
|
return;
|
|
7027
7103
|
// If placeholders lack ids but we only have one persist entry, assign its key for convenience
|
|
7028
7104
|
if (persistEntries.size === 1) {
|
|
7029
7105
|
const loneKey = Array.from(persistEntries.keys())[0];
|
|
7030
7106
|
elementsIn(root).forEach(el => {
|
|
7107
|
+
if (persistParking?.contains(el))
|
|
7108
|
+
return;
|
|
7031
7109
|
if (!getPersistKey(el, false)) {
|
|
7032
7110
|
el.dataset.gyosPersistId = loneKey;
|
|
7033
7111
|
}
|
|
@@ -7035,6 +7113,8 @@
|
|
|
7035
7113
|
}
|
|
7036
7114
|
// Element placeholders
|
|
7037
7115
|
elementsIn(root).forEach(placeholder => {
|
|
7116
|
+
if (persistParking?.contains(placeholder))
|
|
7117
|
+
return;
|
|
7038
7118
|
const key = getPersistKey(placeholder, false);
|
|
7039
7119
|
if (!key)
|
|
7040
7120
|
return;
|
|
@@ -7052,6 +7132,8 @@
|
|
|
7052
7132
|
const toReplace = [];
|
|
7053
7133
|
while (walker.nextNode()) {
|
|
7054
7134
|
const comment = walker.currentNode;
|
|
7135
|
+
if (persistParking?.contains(comment))
|
|
7136
|
+
continue;
|
|
7055
7137
|
const match = comment.data.match(/g-persist[:=]\s*([A-Za-z0-9_\-:.]+)/);
|
|
7056
7138
|
if (match) {
|
|
7057
7139
|
toReplace.push({ node: comment, key: match[1] });
|
|
@@ -7709,6 +7791,36 @@
|
|
|
7709
7791
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
7710
7792
|
*/
|
|
7711
7793
|
const submittingForms = new WeakSet();
|
|
7794
|
+
async function visit(url, options, fresh) {
|
|
7795
|
+
const destination = new URL(url, document.baseURI);
|
|
7796
|
+
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
7797
|
+
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
7798
|
+
}
|
|
7799
|
+
if (options.target !== undefined && !(document.querySelector(options.target) instanceof HTMLElement)) {
|
|
7800
|
+
throw new TypeError('Gyos.navigate target does not exist.');
|
|
7801
|
+
}
|
|
7802
|
+
if (!document.querySelector('[g-boost]')) {
|
|
7803
|
+
throw new TypeError('Gyos.navigate requires a g-boost layout.');
|
|
7804
|
+
}
|
|
7805
|
+
startRouter();
|
|
7806
|
+
let result;
|
|
7807
|
+
await navigateRequest({
|
|
7808
|
+
url: destination.href, method: 'GET',
|
|
7809
|
+
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
7810
|
+
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
7811
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, fresh,
|
|
7812
|
+
onEnd: context => { result = context; }
|
|
7813
|
+
});
|
|
7814
|
+
return result;
|
|
7815
|
+
}
|
|
7816
|
+
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
7817
|
+
function navigate(url, options = {}) {
|
|
7818
|
+
return visit(url, options, false);
|
|
7819
|
+
}
|
|
7820
|
+
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
7821
|
+
function refresh(options = {}) {
|
|
7822
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, true);
|
|
7823
|
+
}
|
|
7712
7824
|
const snapshots = new Map();
|
|
7713
7825
|
const preloadCache = new Map();
|
|
7714
7826
|
const preloadControllers = new Map();
|
|
@@ -8095,12 +8207,27 @@
|
|
|
8095
8207
|
}
|
|
8096
8208
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8097
8209
|
}
|
|
8098
|
-
async function
|
|
8210
|
+
async function navigateRequest(opts) {
|
|
8211
|
+
const finishUnstarted = () => {
|
|
8212
|
+
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8213
|
+
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8214
|
+
signal: opts.signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8215
|
+
};
|
|
8216
|
+
if (opts.signal?.aborted) {
|
|
8217
|
+
finishUnstarted();
|
|
8218
|
+
return;
|
|
8219
|
+
}
|
|
8099
8220
|
while (activeNavigation) {
|
|
8100
8221
|
const previous = activeNavigation;
|
|
8101
8222
|
if (previous.committing) {
|
|
8102
8223
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8103
|
-
|
|
8224
|
+
try {
|
|
8225
|
+
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8226
|
+
}
|
|
8227
|
+
catch {
|
|
8228
|
+
finishUnstarted();
|
|
8229
|
+
return;
|
|
8230
|
+
}
|
|
8104
8231
|
continue;
|
|
8105
8232
|
}
|
|
8106
8233
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8119,6 +8246,10 @@
|
|
|
8119
8246
|
resolveDone
|
|
8120
8247
|
};
|
|
8121
8248
|
activeNavigation = transaction;
|
|
8249
|
+
const abort = () => cancelNavigation(transaction);
|
|
8250
|
+
opts.signal?.addEventListener('abort', abort, { once: true });
|
|
8251
|
+
if (opts.signal?.aborted)
|
|
8252
|
+
abort();
|
|
8122
8253
|
const currentBaseUrl = document.baseURI;
|
|
8123
8254
|
rememberResourceUrls(document, currentBaseUrl);
|
|
8124
8255
|
const context = {
|
|
@@ -8142,6 +8273,7 @@
|
|
|
8142
8273
|
}
|
|
8143
8274
|
};
|
|
8144
8275
|
try {
|
|
8276
|
+
assertActiveNavigation(transaction);
|
|
8145
8277
|
if (formEvent)
|
|
8146
8278
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8147
8279
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
@@ -8154,6 +8286,10 @@
|
|
|
8154
8286
|
saveScrollPosition();
|
|
8155
8287
|
// Pick target element to swap
|
|
8156
8288
|
let target = resolveTarget(opts.trigger, opts.targetSelector, opts.targetOutletIndex);
|
|
8289
|
+
if (opts.strictTarget && (!opts.targetSelector || !target?.matches(opts.targetSelector))) {
|
|
8290
|
+
context.outcome = 'invalid-response';
|
|
8291
|
+
return; // A queued explicit target disappeared; never broaden the swap.
|
|
8292
|
+
}
|
|
8157
8293
|
context.target = target;
|
|
8158
8294
|
if (!target) {
|
|
8159
8295
|
if (isActiveNavigation(transaction))
|
|
@@ -8198,7 +8334,12 @@
|
|
|
8198
8334
|
else {
|
|
8199
8335
|
// Check preload cache if GET
|
|
8200
8336
|
const preloadKey = canonicalUrl(finalUrl, true);
|
|
8201
|
-
if (opts.
|
|
8337
|
+
if (opts.fresh) {
|
|
8338
|
+
preloadControllers.get(preloadKey)?.abort();
|
|
8339
|
+
preloadControllers.delete(preloadKey);
|
|
8340
|
+
preloadCache.delete(preloadKey);
|
|
8341
|
+
}
|
|
8342
|
+
if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
|
|
8202
8343
|
log('[GyosRouter] using preload cache for', finalUrl);
|
|
8203
8344
|
try {
|
|
8204
8345
|
response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
|
|
@@ -8406,7 +8547,10 @@
|
|
|
8406
8547
|
finalizeCommit();
|
|
8407
8548
|
}
|
|
8408
8549
|
// Handle scroll after mount scopes
|
|
8409
|
-
if (
|
|
8550
|
+
if (opts.scroll === false) {
|
|
8551
|
+
// Explicit refresh/navigation policy keeps the current viewport.
|
|
8552
|
+
}
|
|
8553
|
+
else if (changesState) {
|
|
8410
8554
|
handleScroll(targetUrl, opts.trigger);
|
|
8411
8555
|
}
|
|
8412
8556
|
else if (opts.popstate) {
|
|
@@ -8471,6 +8615,7 @@
|
|
|
8471
8615
|
activeNavigation = null;
|
|
8472
8616
|
progressBar?.complete();
|
|
8473
8617
|
}
|
|
8618
|
+
opts.signal?.removeEventListener('abort', abort);
|
|
8474
8619
|
transaction.resolveDone();
|
|
8475
8620
|
if (formEvent)
|
|
8476
8621
|
submittingForms.delete(formEvent.form);
|
|
@@ -8481,6 +8626,7 @@
|
|
|
8481
8626
|
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
8482
8627
|
}));
|
|
8483
8628
|
}
|
|
8629
|
+
opts.onEnd?.({ ...context });
|
|
8484
8630
|
}
|
|
8485
8631
|
}
|
|
8486
8632
|
function shouldBoost(el) {
|
|
@@ -8511,7 +8657,7 @@
|
|
|
8511
8657
|
const scope = getScopeFromElement(element);
|
|
8512
8658
|
const jsonData = evaluateExpression(decodeURIComponent(element.getAttribute(paramsAttr) || ''), scope, false);
|
|
8513
8659
|
// The default changeState is false, as this is commonly used for: load more, infinite scroll, etc.
|
|
8514
|
-
|
|
8660
|
+
navigateRequest({
|
|
8515
8661
|
url: parsedUrl.toString(), method, trigger: element, jsonData, changeState: false
|
|
8516
8662
|
});
|
|
8517
8663
|
}
|
|
@@ -8560,7 +8706,7 @@
|
|
|
8560
8706
|
return;
|
|
8561
8707
|
event.preventDefault();
|
|
8562
8708
|
// The default changeState is true, as this is commonly used for: navigation, etc.
|
|
8563
|
-
|
|
8709
|
+
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
8564
8710
|
}
|
|
8565
8711
|
function onMouseOverCapture(event) {
|
|
8566
8712
|
const target = event.target;
|
|
@@ -8616,7 +8762,7 @@
|
|
|
8616
8762
|
return;
|
|
8617
8763
|
const formData = new FormData(form, submitter);
|
|
8618
8764
|
submittingForms.add(form);
|
|
8619
|
-
void
|
|
8765
|
+
void navigateRequest({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
8620
8766
|
}
|
|
8621
8767
|
function onPopState(event) {
|
|
8622
8768
|
const url = window.location.href;
|
|
@@ -8634,14 +8780,14 @@
|
|
|
8634
8780
|
}
|
|
8635
8781
|
event.preventDefault();
|
|
8636
8782
|
// The browser changes location before popstate fires. Stop any pending page
|
|
8637
|
-
// script immediately, then let
|
|
8783
|
+
// script immediately, then let navigateRequest() wait for its DOM finalizer.
|
|
8638
8784
|
if (activeNavigation?.committing)
|
|
8639
8785
|
cancelNavigation(activeNavigation);
|
|
8640
8786
|
// The browser has already moved to the destination history entry. Keep the
|
|
8641
8787
|
// router's entry pointer aligned before any restored page script can navigate.
|
|
8642
8788
|
currentHistoryEntryId = destinationEntryId;
|
|
8643
8789
|
// No snapshot, do a normal navigation without changing history (changeState: false)
|
|
8644
|
-
|
|
8790
|
+
navigateRequest({
|
|
8645
8791
|
url,
|
|
8646
8792
|
method: 'GET',
|
|
8647
8793
|
replace: true,
|
|
@@ -8723,10 +8869,12 @@
|
|
|
8723
8869
|
onAfterNavigate,
|
|
8724
8870
|
onBeforeSwap,
|
|
8725
8871
|
onNavigationEnd,
|
|
8872
|
+
navigate,
|
|
8873
|
+
refresh,
|
|
8726
8874
|
portalCreate,
|
|
8727
8875
|
portalDestroy,
|
|
8728
8876
|
setCspNonce,
|
|
8729
|
-
version: '0.
|
|
8877
|
+
version: '0.5.0'
|
|
8730
8878
|
};
|
|
8731
8879
|
|
|
8732
8880
|
// This file was generated. Do not modify manually!
|