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.esm.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
|
*/
|
|
@@ -229,10 +229,35 @@ function hasStructuralParent(el) {
|
|
|
229
229
|
* count.value++; // Triggers effect
|
|
230
230
|
* ```
|
|
231
231
|
*/
|
|
232
|
-
/**
|
|
233
|
-
* Current effect being tracked
|
|
234
|
-
*/
|
|
235
232
|
let currentEffect = null;
|
|
233
|
+
function track(source) {
|
|
234
|
+
if (!currentEffect)
|
|
235
|
+
return;
|
|
236
|
+
source.subscribers.add(currentEffect);
|
|
237
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
238
|
+
currentEffect.__versions?.set(source, source.version);
|
|
239
|
+
}
|
|
240
|
+
function dependenciesChanged(versions) {
|
|
241
|
+
return untrack(() => {
|
|
242
|
+
for (const [source, version] of versions) {
|
|
243
|
+
source.refresh?.();
|
|
244
|
+
if (source.version !== version)
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
251
|
+
function notifySubscribers(subscribers) {
|
|
252
|
+
for (const sub of Array.from(subscribers)) {
|
|
253
|
+
if (sub.__invalidate)
|
|
254
|
+
sub();
|
|
255
|
+
else if (isBatching)
|
|
256
|
+
batchedEffects.add(sub);
|
|
257
|
+
else
|
|
258
|
+
queueEffect(sub);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
236
261
|
// Simple counter for debug-friendly IDs
|
|
237
262
|
let signalIdCounter = 0;
|
|
238
263
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -270,6 +295,9 @@ function flushEffectQueue() {
|
|
|
270
295
|
}
|
|
271
296
|
});
|
|
272
297
|
isFlushingQueue = false;
|
|
298
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
299
|
+
if (effectQueue.size > 0)
|
|
300
|
+
queueMicrotask(flushEffectQueue);
|
|
273
301
|
}
|
|
274
302
|
/**
|
|
275
303
|
* Queue an effect for execution in next microtask
|
|
@@ -328,17 +356,14 @@ function signal(initialValue, debugOrOptions) {
|
|
|
328
356
|
const debugId = ++signalIdCounter;
|
|
329
357
|
let value = initialValue;
|
|
330
358
|
const subscribers = new Set();
|
|
359
|
+
const source = { subscribers, version: 0 };
|
|
331
360
|
let warnedSubscribers = false;
|
|
332
361
|
const read = () => {
|
|
333
362
|
// Track dependency
|
|
334
363
|
if (currentEffect) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
339
|
-
if (currentEffect.__dependencies) {
|
|
340
|
-
currentEffect.__dependencies.add(subscribers);
|
|
341
|
-
}
|
|
364
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
365
|
+
track(source);
|
|
366
|
+
if (!wasSubscribed) {
|
|
342
367
|
if (DEBUG_VERBOSE()) {
|
|
343
368
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
344
369
|
}
|
|
@@ -357,18 +382,13 @@ function signal(initialValue, debugOrOptions) {
|
|
|
357
382
|
// For objects/arrays, check if it's actually the same reference
|
|
358
383
|
// Deep equality is expensive, let user handle it
|
|
359
384
|
value = newValue;
|
|
385
|
+
source.version++;
|
|
360
386
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
361
387
|
notify();
|
|
362
388
|
};
|
|
363
389
|
const notify = () => {
|
|
364
390
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
365
|
-
|
|
366
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
// Always queue effects to prevent cascading updates
|
|
370
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
371
|
-
}
|
|
391
|
+
notifySubscribers(subscribers);
|
|
372
392
|
};
|
|
373
393
|
// Create callable signal (like Angular/SolidJS)
|
|
374
394
|
// Call without args = read, call with arg = write
|
|
@@ -403,8 +423,16 @@ function signal(initialValue, debugOrOptions) {
|
|
|
403
423
|
},
|
|
404
424
|
subscribe: {
|
|
405
425
|
value: function (fn) {
|
|
406
|
-
|
|
407
|
-
|
|
426
|
+
let active = true;
|
|
427
|
+
const callback = () => { if (active)
|
|
428
|
+
untrack(fn); };
|
|
429
|
+
subscribers.add(callback);
|
|
430
|
+
return () => {
|
|
431
|
+
active = false;
|
|
432
|
+
subscribers.delete(callback);
|
|
433
|
+
effectQueue.delete(callback);
|
|
434
|
+
batchedEffects.delete(callback);
|
|
435
|
+
};
|
|
408
436
|
},
|
|
409
437
|
enumerable: true,
|
|
410
438
|
configurable: true
|
|
@@ -464,49 +492,60 @@ function computed(fn) {
|
|
|
464
492
|
let value;
|
|
465
493
|
let isDirty = true;
|
|
466
494
|
let isFirstRun = true;
|
|
495
|
+
let computing = false;
|
|
467
496
|
const subscribers = new Set();
|
|
468
|
-
|
|
497
|
+
const dependencies = new Set();
|
|
498
|
+
const versions = new Map();
|
|
499
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
500
|
+
const invalidate = () => {
|
|
501
|
+
// A later batched write must also move already queued consumers into
|
|
502
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
503
|
+
if (isDirty && !isBatching)
|
|
504
|
+
return;
|
|
505
|
+
isDirty = true;
|
|
506
|
+
notifySubscribers(subscribers);
|
|
507
|
+
};
|
|
508
|
+
invalidate.__invalidate = true;
|
|
509
|
+
invalidate.__dependencies = dependencies;
|
|
510
|
+
invalidate.__versions = versions;
|
|
469
511
|
const compute = () => {
|
|
470
512
|
if (!isDirty && !isFirstRun)
|
|
471
513
|
return;
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
value = newValue;
|
|
482
|
-
isFirstRun = false;
|
|
483
|
-
isDirty = false;
|
|
484
|
-
// Notify subscribers
|
|
485
|
-
if (!isBatching) {
|
|
486
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
490
|
-
}
|
|
491
|
-
}
|
|
514
|
+
if (computing)
|
|
515
|
+
throw new Error('[Computed] Circular dependency');
|
|
516
|
+
computing = true;
|
|
517
|
+
const previousEffect = currentEffect;
|
|
518
|
+
try {
|
|
519
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
520
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
521
|
+
isDirty = false;
|
|
522
|
+
return;
|
|
492
523
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
524
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
525
|
+
dependencies.clear();
|
|
526
|
+
versions.clear();
|
|
527
|
+
currentEffect = invalidate;
|
|
528
|
+
const nextValue = fn();
|
|
529
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
530
|
+
value = nextValue;
|
|
531
|
+
source.version++;
|
|
496
532
|
}
|
|
497
|
-
|
|
498
|
-
|
|
533
|
+
isFirstRun = false;
|
|
534
|
+
isDirty = false;
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
// Preserve error isolation and the last successful value.
|
|
538
|
+
console.error('[Computed] Error in computation:', error);
|
|
539
|
+
isDirty = false;
|
|
540
|
+
}
|
|
541
|
+
finally {
|
|
542
|
+
currentEffect = previousEffect;
|
|
543
|
+
computing = false;
|
|
544
|
+
}
|
|
499
545
|
};
|
|
500
546
|
const read = () => {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
// Track dependency
|
|
504
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
505
|
-
subscribers.add(currentEffect);
|
|
506
|
-
if (currentEffect.__dependencies) {
|
|
507
|
-
currentEffect.__dependencies.add(subscribers);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
547
|
+
compute();
|
|
548
|
+
track(source);
|
|
510
549
|
return value;
|
|
511
550
|
};
|
|
512
551
|
// Create callable computed (read-only)
|
|
@@ -531,8 +570,14 @@ function computed(fn) {
|
|
|
531
570
|
},
|
|
532
571
|
subscribe: {
|
|
533
572
|
value: function (fn) {
|
|
534
|
-
|
|
535
|
-
|
|
573
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
574
|
+
let first = true;
|
|
575
|
+
return effect(() => {
|
|
576
|
+
read();
|
|
577
|
+
if (!first)
|
|
578
|
+
untrack(fn);
|
|
579
|
+
first = false;
|
|
580
|
+
});
|
|
536
581
|
},
|
|
537
582
|
enumerable: true,
|
|
538
583
|
configurable: true
|
|
@@ -583,11 +628,15 @@ function computed(fn) {
|
|
|
583
628
|
*/
|
|
584
629
|
function effect(fn) {
|
|
585
630
|
let cleanup;
|
|
586
|
-
|
|
631
|
+
const dependencies = new Set();
|
|
632
|
+
const versions = new Map();
|
|
587
633
|
let active = true;
|
|
634
|
+
let initialized = false;
|
|
588
635
|
const execute = () => {
|
|
589
636
|
if (!active)
|
|
590
637
|
return;
|
|
638
|
+
if (initialized && !dependenciesChanged(versions))
|
|
639
|
+
return;
|
|
591
640
|
// Prevent recursive execution - if already running, skip
|
|
592
641
|
if (runningEffects.has(execute)) {
|
|
593
642
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -602,10 +651,13 @@ function effect(fn) {
|
|
|
602
651
|
});
|
|
603
652
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
604
653
|
dependencies.clear();
|
|
654
|
+
versions.clear();
|
|
605
655
|
// Clean up previous run
|
|
606
656
|
if (cleanup) {
|
|
657
|
+
const previousCleanup = cleanup;
|
|
658
|
+
cleanup = undefined;
|
|
607
659
|
try {
|
|
608
|
-
|
|
660
|
+
untrack(previousCleanup);
|
|
609
661
|
}
|
|
610
662
|
catch (error) {
|
|
611
663
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -616,6 +668,7 @@ function effect(fn) {
|
|
|
616
668
|
currentEffect = execute;
|
|
617
669
|
// Store dependencies for cleanup
|
|
618
670
|
execute.__dependencies = dependencies;
|
|
671
|
+
execute.__versions = versions;
|
|
619
672
|
try {
|
|
620
673
|
const nextCleanup = fn();
|
|
621
674
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -625,6 +678,7 @@ function effect(fn) {
|
|
|
625
678
|
// Don't throw - allow other effects to continue
|
|
626
679
|
}
|
|
627
680
|
finally {
|
|
681
|
+
initialized = true;
|
|
628
682
|
currentEffect = prevEffect;
|
|
629
683
|
effectDepth--;
|
|
630
684
|
runningEffects.delete(execute);
|
|
@@ -641,14 +695,17 @@ function effect(fn) {
|
|
|
641
695
|
if (!active)
|
|
642
696
|
return;
|
|
643
697
|
active = false;
|
|
698
|
+
effectQueue.delete(execute);
|
|
699
|
+
batchedEffects.delete(execute);
|
|
644
700
|
// Remove from all dependencies
|
|
645
701
|
dependencies.forEach(depSet => {
|
|
646
702
|
depSet.delete(execute);
|
|
647
703
|
});
|
|
648
704
|
dependencies.clear();
|
|
705
|
+
versions.clear();
|
|
649
706
|
if (cleanup) {
|
|
650
707
|
try {
|
|
651
|
-
cleanup
|
|
708
|
+
untrack(cleanup);
|
|
652
709
|
}
|
|
653
710
|
catch (error) {
|
|
654
711
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -708,6 +765,8 @@ function batch(fn) {
|
|
|
708
765
|
const effects = Array.from(batchedEffects);
|
|
709
766
|
batchedEffects.clear();
|
|
710
767
|
effects.forEach(effect => {
|
|
768
|
+
// This batch also settles any earlier queued write to this observer.
|
|
769
|
+
effectQueue.delete(effect);
|
|
711
770
|
try {
|
|
712
771
|
effect();
|
|
713
772
|
}
|
|
@@ -5603,6 +5662,21 @@ setMountFunction(mount);
|
|
|
5603
5662
|
* Registry of all scopes
|
|
5604
5663
|
*/
|
|
5605
5664
|
const scopeRegistry = new Map();
|
|
5665
|
+
const warnedReveals = new WeakSet();
|
|
5666
|
+
function diagnoseUnscopedReveals(root) {
|
|
5667
|
+
if (!DEBUG())
|
|
5668
|
+
return;
|
|
5669
|
+
const elements = [...root.querySelectorAll('[g-reveal]')];
|
|
5670
|
+
if (root instanceof Element && root.hasAttribute('g-reveal'))
|
|
5671
|
+
elements.unshift(root);
|
|
5672
|
+
for (const element of elements) {
|
|
5673
|
+
if (warnedReveals.has(element) || isInIgnoredTree(element)
|
|
5674
|
+
|| element.closest('[g-scope]') || getScopeFromElement(element))
|
|
5675
|
+
continue;
|
|
5676
|
+
warnedReveals.add(element);
|
|
5677
|
+
console.warn('[Gyos] g-reveal has no owning scope. Add g-scope to its container; global reveal CSS may otherwise hide this content.', element);
|
|
5678
|
+
}
|
|
5679
|
+
}
|
|
5606
5680
|
/**
|
|
5607
5681
|
* Register a scope
|
|
5608
5682
|
*/
|
|
@@ -5650,6 +5724,7 @@ function mountAll(root) {
|
|
|
5650
5724
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5651
5725
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
5652
5726
|
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
5727
|
+
diagnoseUnscopedReveals(document.body);
|
|
5653
5728
|
}
|
|
5654
5729
|
function mountTree(el) {
|
|
5655
5730
|
if (isInIgnoredTree(el) || !document.body.contains(el))
|
|
@@ -5660,6 +5735,7 @@ function mountTree(el) {
|
|
|
5660
5735
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
5661
5736
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5662
5737
|
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
5738
|
+
diagnoseUnscopedReveals(el);
|
|
5663
5739
|
if (getMountedScope(el))
|
|
5664
5740
|
return;
|
|
5665
5741
|
const ownerScope = getScopeFromElement(el);
|
|
@@ -5678,7 +5754,7 @@ function mount(el) {
|
|
|
5678
5754
|
return;
|
|
5679
5755
|
// Check if element removed but still has g-scope (possible in some edge cases)
|
|
5680
5756
|
getAllMountedScopes().forEach((_, mountedEl) => {
|
|
5681
|
-
if (!
|
|
5757
|
+
if (!mountedEl.isConnected) {
|
|
5682
5758
|
disposeEffects(mountedEl);
|
|
5683
5759
|
}
|
|
5684
5760
|
});
|
|
@@ -6990,7 +7066,8 @@ function getPersistKey(el, generateIfMissing = false) {
|
|
|
6990
7066
|
el.dataset.gyosPersistId = key;
|
|
6991
7067
|
return key;
|
|
6992
7068
|
}
|
|
6993
|
-
//
|
|
7069
|
+
// Keep the parking host outside body: body itself may be the swap target.
|
|
7070
|
+
// A disconnected parking host makes browsers pause otherwise persisted media.
|
|
6994
7071
|
const persistParking = typeof document !== 'undefined'
|
|
6995
7072
|
? (() => {
|
|
6996
7073
|
const park = document.createElement('div');
|
|
@@ -6999,12 +7076,7 @@ const persistParking = typeof document !== 'undefined'
|
|
|
6999
7076
|
park.style.top = '-99999px';
|
|
7000
7077
|
park.style.width = '0';
|
|
7001
7078
|
park.style.height = '0';
|
|
7002
|
-
|
|
7003
|
-
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(park));
|
|
7004
|
-
}
|
|
7005
|
-
else {
|
|
7006
|
-
document.body.appendChild(park);
|
|
7007
|
-
}
|
|
7079
|
+
document.documentElement.appendChild(park);
|
|
7008
7080
|
return park;
|
|
7009
7081
|
})()
|
|
7010
7082
|
: null;
|
|
@@ -7015,8 +7087,8 @@ function elementsIn(root) {
|
|
|
7015
7087
|
return elements;
|
|
7016
7088
|
}
|
|
7017
7089
|
function ensureParkingIsConnected() {
|
|
7018
|
-
if (persistParking &&
|
|
7019
|
-
document.
|
|
7090
|
+
if (persistParking && persistParking.parentElement !== document.documentElement) {
|
|
7091
|
+
document.documentElement.appendChild(persistParking);
|
|
7020
7092
|
}
|
|
7021
7093
|
}
|
|
7022
7094
|
function detachPersist(root = document) {
|
|
@@ -7034,12 +7106,18 @@ function detachPersist(root = document) {
|
|
|
7034
7106
|
});
|
|
7035
7107
|
}
|
|
7036
7108
|
function mergePersistIntoLive(root) {
|
|
7109
|
+
// Return the host to the current body before scope mounting/cleanup inspects it.
|
|
7110
|
+
if (persistParking && persistParking.parentElement !== document.body) {
|
|
7111
|
+
document.body.appendChild(persistParking);
|
|
7112
|
+
}
|
|
7037
7113
|
if (!persistEntries.size)
|
|
7038
7114
|
return;
|
|
7039
7115
|
// If placeholders lack ids but we only have one persist entry, assign its key for convenience
|
|
7040
7116
|
if (persistEntries.size === 1) {
|
|
7041
7117
|
const loneKey = Array.from(persistEntries.keys())[0];
|
|
7042
7118
|
elementsIn(root).forEach(el => {
|
|
7119
|
+
if (persistParking?.contains(el))
|
|
7120
|
+
return;
|
|
7043
7121
|
if (!getPersistKey(el, false)) {
|
|
7044
7122
|
el.dataset.gyosPersistId = loneKey;
|
|
7045
7123
|
}
|
|
@@ -7047,6 +7125,8 @@ function mergePersistIntoLive(root) {
|
|
|
7047
7125
|
}
|
|
7048
7126
|
// Element placeholders
|
|
7049
7127
|
elementsIn(root).forEach(placeholder => {
|
|
7128
|
+
if (persistParking?.contains(placeholder))
|
|
7129
|
+
return;
|
|
7050
7130
|
const key = getPersistKey(placeholder, false);
|
|
7051
7131
|
if (!key)
|
|
7052
7132
|
return;
|
|
@@ -7064,6 +7144,8 @@ function mergePersistIntoLive(root) {
|
|
|
7064
7144
|
const toReplace = [];
|
|
7065
7145
|
while (walker.nextNode()) {
|
|
7066
7146
|
const comment = walker.currentNode;
|
|
7147
|
+
if (persistParking?.contains(comment))
|
|
7148
|
+
continue;
|
|
7067
7149
|
const match = comment.data.match(/g-persist[:=]\s*([A-Za-z0-9_\-:.]+)/);
|
|
7068
7150
|
if (match) {
|
|
7069
7151
|
toReplace.push({ node: comment, key: match[1] });
|
|
@@ -7721,6 +7803,36 @@ function prepareNavigationHtml(html) {
|
|
|
7721
7803
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
7722
7804
|
*/
|
|
7723
7805
|
const submittingForms = new WeakSet();
|
|
7806
|
+
async function visit(url, options, fresh) {
|
|
7807
|
+
const destination = new URL(url, document.baseURI);
|
|
7808
|
+
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
7809
|
+
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
7810
|
+
}
|
|
7811
|
+
if (options.target !== undefined && !(document.querySelector(options.target) instanceof HTMLElement)) {
|
|
7812
|
+
throw new TypeError('Gyos.navigate target does not exist.');
|
|
7813
|
+
}
|
|
7814
|
+
if (!document.querySelector('[g-boost]')) {
|
|
7815
|
+
throw new TypeError('Gyos.navigate requires a g-boost layout.');
|
|
7816
|
+
}
|
|
7817
|
+
startRouter();
|
|
7818
|
+
let result;
|
|
7819
|
+
await navigateRequest({
|
|
7820
|
+
url: destination.href, method: 'GET',
|
|
7821
|
+
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
7822
|
+
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
7823
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, fresh,
|
|
7824
|
+
onEnd: context => { result = context; }
|
|
7825
|
+
});
|
|
7826
|
+
return result;
|
|
7827
|
+
}
|
|
7828
|
+
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
7829
|
+
function navigate(url, options = {}) {
|
|
7830
|
+
return visit(url, options, false);
|
|
7831
|
+
}
|
|
7832
|
+
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
7833
|
+
function refresh(options = {}) {
|
|
7834
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, true);
|
|
7835
|
+
}
|
|
7724
7836
|
const snapshots = new Map();
|
|
7725
7837
|
const preloadCache = new Map();
|
|
7726
7838
|
const preloadControllers = new Map();
|
|
@@ -8107,12 +8219,27 @@ function fallbackFromBoost(opts, url, requestSent) {
|
|
|
8107
8219
|
}
|
|
8108
8220
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8109
8221
|
}
|
|
8110
|
-
async function
|
|
8222
|
+
async function navigateRequest(opts) {
|
|
8223
|
+
const finishUnstarted = () => {
|
|
8224
|
+
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8225
|
+
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8226
|
+
signal: opts.signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8227
|
+
};
|
|
8228
|
+
if (opts.signal?.aborted) {
|
|
8229
|
+
finishUnstarted();
|
|
8230
|
+
return;
|
|
8231
|
+
}
|
|
8111
8232
|
while (activeNavigation) {
|
|
8112
8233
|
const previous = activeNavigation;
|
|
8113
8234
|
if (previous.committing) {
|
|
8114
8235
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8115
|
-
|
|
8236
|
+
try {
|
|
8237
|
+
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8238
|
+
}
|
|
8239
|
+
catch {
|
|
8240
|
+
finishUnstarted();
|
|
8241
|
+
return;
|
|
8242
|
+
}
|
|
8116
8243
|
continue;
|
|
8117
8244
|
}
|
|
8118
8245
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8131,6 +8258,10 @@ async function navigate(opts) {
|
|
|
8131
8258
|
resolveDone
|
|
8132
8259
|
};
|
|
8133
8260
|
activeNavigation = transaction;
|
|
8261
|
+
const abort = () => cancelNavigation(transaction);
|
|
8262
|
+
opts.signal?.addEventListener('abort', abort, { once: true });
|
|
8263
|
+
if (opts.signal?.aborted)
|
|
8264
|
+
abort();
|
|
8134
8265
|
const currentBaseUrl = document.baseURI;
|
|
8135
8266
|
rememberResourceUrls(document, currentBaseUrl);
|
|
8136
8267
|
const context = {
|
|
@@ -8154,6 +8285,7 @@ async function navigate(opts) {
|
|
|
8154
8285
|
}
|
|
8155
8286
|
};
|
|
8156
8287
|
try {
|
|
8288
|
+
assertActiveNavigation(transaction);
|
|
8157
8289
|
if (formEvent)
|
|
8158
8290
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8159
8291
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
@@ -8166,6 +8298,10 @@ async function navigate(opts) {
|
|
|
8166
8298
|
saveScrollPosition();
|
|
8167
8299
|
// Pick target element to swap
|
|
8168
8300
|
let target = resolveTarget(opts.trigger, opts.targetSelector, opts.targetOutletIndex);
|
|
8301
|
+
if (opts.strictTarget && (!opts.targetSelector || !target?.matches(opts.targetSelector))) {
|
|
8302
|
+
context.outcome = 'invalid-response';
|
|
8303
|
+
return; // A queued explicit target disappeared; never broaden the swap.
|
|
8304
|
+
}
|
|
8169
8305
|
context.target = target;
|
|
8170
8306
|
if (!target) {
|
|
8171
8307
|
if (isActiveNavigation(transaction))
|
|
@@ -8210,7 +8346,12 @@ async function navigate(opts) {
|
|
|
8210
8346
|
else {
|
|
8211
8347
|
// Check preload cache if GET
|
|
8212
8348
|
const preloadKey = canonicalUrl(finalUrl, true);
|
|
8213
|
-
if (opts.
|
|
8349
|
+
if (opts.fresh) {
|
|
8350
|
+
preloadControllers.get(preloadKey)?.abort();
|
|
8351
|
+
preloadControllers.delete(preloadKey);
|
|
8352
|
+
preloadCache.delete(preloadKey);
|
|
8353
|
+
}
|
|
8354
|
+
if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
|
|
8214
8355
|
log('[GyosRouter] using preload cache for', finalUrl);
|
|
8215
8356
|
try {
|
|
8216
8357
|
response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
|
|
@@ -8418,7 +8559,10 @@ async function navigate(opts) {
|
|
|
8418
8559
|
finalizeCommit();
|
|
8419
8560
|
}
|
|
8420
8561
|
// Handle scroll after mount scopes
|
|
8421
|
-
if (
|
|
8562
|
+
if (opts.scroll === false) {
|
|
8563
|
+
// Explicit refresh/navigation policy keeps the current viewport.
|
|
8564
|
+
}
|
|
8565
|
+
else if (changesState) {
|
|
8422
8566
|
handleScroll(targetUrl, opts.trigger);
|
|
8423
8567
|
}
|
|
8424
8568
|
else if (opts.popstate) {
|
|
@@ -8483,6 +8627,7 @@ async function navigate(opts) {
|
|
|
8483
8627
|
activeNavigation = null;
|
|
8484
8628
|
progressBar?.complete();
|
|
8485
8629
|
}
|
|
8630
|
+
opts.signal?.removeEventListener('abort', abort);
|
|
8486
8631
|
transaction.resolveDone();
|
|
8487
8632
|
if (formEvent)
|
|
8488
8633
|
submittingForms.delete(formEvent.form);
|
|
@@ -8493,6 +8638,7 @@ async function navigate(opts) {
|
|
|
8493
8638
|
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
8494
8639
|
}));
|
|
8495
8640
|
}
|
|
8641
|
+
opts.onEnd?.({ ...context });
|
|
8496
8642
|
}
|
|
8497
8643
|
}
|
|
8498
8644
|
function shouldBoost(el) {
|
|
@@ -8523,7 +8669,7 @@ function onClickRouter(element) {
|
|
|
8523
8669
|
const scope = getScopeFromElement(element);
|
|
8524
8670
|
const jsonData = evaluateExpression(decodeURIComponent(element.getAttribute(paramsAttr) || ''), scope, false);
|
|
8525
8671
|
// The default changeState is false, as this is commonly used for: load more, infinite scroll, etc.
|
|
8526
|
-
|
|
8672
|
+
navigateRequest({
|
|
8527
8673
|
url: parsedUrl.toString(), method, trigger: element, jsonData, changeState: false
|
|
8528
8674
|
});
|
|
8529
8675
|
}
|
|
@@ -8572,7 +8718,7 @@ function onClick(event) {
|
|
|
8572
8718
|
return;
|
|
8573
8719
|
event.preventDefault();
|
|
8574
8720
|
// The default changeState is true, as this is commonly used for: navigation, etc.
|
|
8575
|
-
|
|
8721
|
+
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
8576
8722
|
}
|
|
8577
8723
|
function onMouseOverCapture(event) {
|
|
8578
8724
|
const target = event.target;
|
|
@@ -8628,7 +8774,7 @@ function onSubmit(event) {
|
|
|
8628
8774
|
return;
|
|
8629
8775
|
const formData = new FormData(form, submitter);
|
|
8630
8776
|
submittingForms.add(form);
|
|
8631
|
-
void
|
|
8777
|
+
void navigateRequest({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
8632
8778
|
}
|
|
8633
8779
|
function onPopState(event) {
|
|
8634
8780
|
const url = window.location.href;
|
|
@@ -8646,14 +8792,14 @@ function onPopState(event) {
|
|
|
8646
8792
|
}
|
|
8647
8793
|
event.preventDefault();
|
|
8648
8794
|
// The browser changes location before popstate fires. Stop any pending page
|
|
8649
|
-
// script immediately, then let
|
|
8795
|
+
// script immediately, then let navigateRequest() wait for its DOM finalizer.
|
|
8650
8796
|
if (activeNavigation?.committing)
|
|
8651
8797
|
cancelNavigation(activeNavigation);
|
|
8652
8798
|
// The browser has already moved to the destination history entry. Keep the
|
|
8653
8799
|
// router's entry pointer aligned before any restored page script can navigate.
|
|
8654
8800
|
currentHistoryEntryId = destinationEntryId;
|
|
8655
8801
|
// No snapshot, do a normal navigation without changing history (changeState: false)
|
|
8656
|
-
|
|
8802
|
+
navigateRequest({
|
|
8657
8803
|
url,
|
|
8658
8804
|
method: 'GET',
|
|
8659
8805
|
replace: true,
|
|
@@ -8735,13 +8881,15 @@ const Gyos = {
|
|
|
8735
8881
|
onAfterNavigate,
|
|
8736
8882
|
onBeforeSwap,
|
|
8737
8883
|
onNavigationEnd,
|
|
8884
|
+
navigate,
|
|
8885
|
+
refresh,
|
|
8738
8886
|
portalCreate,
|
|
8739
8887
|
portalDestroy,
|
|
8740
8888
|
setCspNonce,
|
|
8741
|
-
version: '0.
|
|
8889
|
+
version: '0.5.0'
|
|
8742
8890
|
};
|
|
8743
8891
|
|
|
8744
8892
|
setExpressionRuntime(standardExpressionRuntime);
|
|
8745
8893
|
|
|
8746
|
-
export { applyDirective, applyTransitionStyles, batch, disposeEffects as cleanup, clearAllEvents, computed, debounce, Gyos as default, directive, effect, emit, getEventListeners, getGlobalContainer, getStoreNames, getTransitionConfig, getValidator, getValidatorNames, hasStore, inject, isComputed, isSignal, markRaw, mount, mountAll, mountTree, getAllMountedScopes as mountedScopes, nextTick, off, on, onAfterNavigate, onBeforeNavigate, onBeforeSwap, onNavigationEnd, once, pipe, portalCreate, portalDestroy, provide, ready, registerTransition, removeStore, scope, setCspNonce, shallow, signal, startRouter, store, throttle, unref, untrack, useAsync, useCounter, useDebounce, useFetch, useInterval, useLocalStorage, useMediaQuery, useMouse, useThrottle, useTimeout, useToggle, useWindowSize, validate, validator };
|
|
8894
|
+
export { applyDirective, applyTransitionStyles, batch, disposeEffects as cleanup, clearAllEvents, computed, debounce, Gyos as default, directive, effect, emit, getEventListeners, getGlobalContainer, getStoreNames, getTransitionConfig, getValidator, getValidatorNames, hasStore, inject, isComputed, isSignal, markRaw, mount, mountAll, mountTree, getAllMountedScopes as mountedScopes, navigate, nextTick, off, on, onAfterNavigate, onBeforeNavigate, onBeforeSwap, onNavigationEnd, once, pipe, portalCreate, portalDestroy, provide, ready, refresh, registerTransition, removeStore, scope, setCspNonce, shallow, signal, startRouter, store, throttle, unref, untrack, useAsync, useCounter, useDebounce, useFetch, useInterval, useLocalStorage, useMediaQuery, useMouse, useThrottle, useTimeout, useToggle, useWindowSize, validate, validator };
|
|
8747
8895
|
//# sourceMappingURL=gyos.esm.js.map
|