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.auto.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
|
*/
|
|
@@ -183,10 +183,35 @@ function hasStructuralParent(el) {
|
|
|
183
183
|
* count.value++; // Triggers effect
|
|
184
184
|
* ```
|
|
185
185
|
*/
|
|
186
|
-
/**
|
|
187
|
-
* Current effect being tracked
|
|
188
|
-
*/
|
|
189
186
|
let currentEffect = null;
|
|
187
|
+
function track(source) {
|
|
188
|
+
if (!currentEffect)
|
|
189
|
+
return;
|
|
190
|
+
source.subscribers.add(currentEffect);
|
|
191
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
192
|
+
currentEffect.__versions?.set(source, source.version);
|
|
193
|
+
}
|
|
194
|
+
function dependenciesChanged(versions) {
|
|
195
|
+
return untrack(() => {
|
|
196
|
+
for (const [source, version] of versions) {
|
|
197
|
+
source.refresh?.();
|
|
198
|
+
if (source.version !== version)
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
return false;
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
205
|
+
function notifySubscribers(subscribers) {
|
|
206
|
+
for (const sub of Array.from(subscribers)) {
|
|
207
|
+
if (sub.__invalidate)
|
|
208
|
+
sub();
|
|
209
|
+
else if (isBatching)
|
|
210
|
+
batchedEffects.add(sub);
|
|
211
|
+
else
|
|
212
|
+
queueEffect(sub);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
190
215
|
// Simple counter for debug-friendly IDs
|
|
191
216
|
let signalIdCounter = 0;
|
|
192
217
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -224,6 +249,9 @@ function flushEffectQueue() {
|
|
|
224
249
|
}
|
|
225
250
|
});
|
|
226
251
|
isFlushingQueue = false;
|
|
252
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
253
|
+
if (effectQueue.size > 0)
|
|
254
|
+
queueMicrotask(flushEffectQueue);
|
|
227
255
|
}
|
|
228
256
|
/**
|
|
229
257
|
* Queue an effect for execution in next microtask
|
|
@@ -282,17 +310,14 @@ function signal(initialValue, debugOrOptions) {
|
|
|
282
310
|
const debugId = ++signalIdCounter;
|
|
283
311
|
let value = initialValue;
|
|
284
312
|
const subscribers = new Set();
|
|
313
|
+
const source = { subscribers, version: 0 };
|
|
285
314
|
let warnedSubscribers = false;
|
|
286
315
|
const read = () => {
|
|
287
316
|
// Track dependency
|
|
288
317
|
if (currentEffect) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
293
|
-
if (currentEffect.__dependencies) {
|
|
294
|
-
currentEffect.__dependencies.add(subscribers);
|
|
295
|
-
}
|
|
318
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
319
|
+
track(source);
|
|
320
|
+
if (!wasSubscribed) {
|
|
296
321
|
if (DEBUG_VERBOSE()) {
|
|
297
322
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
298
323
|
}
|
|
@@ -311,18 +336,13 @@ function signal(initialValue, debugOrOptions) {
|
|
|
311
336
|
// For objects/arrays, check if it's actually the same reference
|
|
312
337
|
// Deep equality is expensive, let user handle it
|
|
313
338
|
value = newValue;
|
|
339
|
+
source.version++;
|
|
314
340
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
315
341
|
notify();
|
|
316
342
|
};
|
|
317
343
|
const notify = () => {
|
|
318
344
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
319
|
-
|
|
320
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
// Always queue effects to prevent cascading updates
|
|
324
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
325
|
-
}
|
|
345
|
+
notifySubscribers(subscribers);
|
|
326
346
|
};
|
|
327
347
|
// Create callable signal (like Angular/SolidJS)
|
|
328
348
|
// Call without args = read, call with arg = write
|
|
@@ -357,8 +377,16 @@ function signal(initialValue, debugOrOptions) {
|
|
|
357
377
|
},
|
|
358
378
|
subscribe: {
|
|
359
379
|
value: function (fn) {
|
|
360
|
-
|
|
361
|
-
|
|
380
|
+
let active = true;
|
|
381
|
+
const callback = () => { if (active)
|
|
382
|
+
untrack(fn); };
|
|
383
|
+
subscribers.add(callback);
|
|
384
|
+
return () => {
|
|
385
|
+
active = false;
|
|
386
|
+
subscribers.delete(callback);
|
|
387
|
+
effectQueue.delete(callback);
|
|
388
|
+
batchedEffects.delete(callback);
|
|
389
|
+
};
|
|
362
390
|
},
|
|
363
391
|
enumerable: true,
|
|
364
392
|
configurable: true
|
|
@@ -418,49 +446,60 @@ function computed(fn) {
|
|
|
418
446
|
let value;
|
|
419
447
|
let isDirty = true;
|
|
420
448
|
let isFirstRun = true;
|
|
449
|
+
let computing = false;
|
|
421
450
|
const subscribers = new Set();
|
|
422
|
-
|
|
451
|
+
const dependencies = new Set();
|
|
452
|
+
const versions = new Map();
|
|
453
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
454
|
+
const invalidate = () => {
|
|
455
|
+
// A later batched write must also move already queued consumers into
|
|
456
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
457
|
+
if (isDirty && !isBatching)
|
|
458
|
+
return;
|
|
459
|
+
isDirty = true;
|
|
460
|
+
notifySubscribers(subscribers);
|
|
461
|
+
};
|
|
462
|
+
invalidate.__invalidate = true;
|
|
463
|
+
invalidate.__dependencies = dependencies;
|
|
464
|
+
invalidate.__versions = versions;
|
|
423
465
|
const compute = () => {
|
|
424
466
|
if (!isDirty && !isFirstRun)
|
|
425
467
|
return;
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
value = newValue;
|
|
436
|
-
isFirstRun = false;
|
|
437
|
-
isDirty = false;
|
|
438
|
-
// Notify subscribers
|
|
439
|
-
if (!isBatching) {
|
|
440
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
444
|
-
}
|
|
445
|
-
}
|
|
468
|
+
if (computing)
|
|
469
|
+
throw new Error('[Computed] Circular dependency');
|
|
470
|
+
computing = true;
|
|
471
|
+
const previousEffect = currentEffect;
|
|
472
|
+
try {
|
|
473
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
474
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
475
|
+
isDirty = false;
|
|
476
|
+
return;
|
|
446
477
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
478
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
479
|
+
dependencies.clear();
|
|
480
|
+
versions.clear();
|
|
481
|
+
currentEffect = invalidate;
|
|
482
|
+
const nextValue = fn();
|
|
483
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
484
|
+
value = nextValue;
|
|
485
|
+
source.version++;
|
|
450
486
|
}
|
|
451
|
-
|
|
452
|
-
|
|
487
|
+
isFirstRun = false;
|
|
488
|
+
isDirty = false;
|
|
489
|
+
}
|
|
490
|
+
catch (error) {
|
|
491
|
+
// Preserve error isolation and the last successful value.
|
|
492
|
+
console.error('[Computed] Error in computation:', error);
|
|
493
|
+
isDirty = false;
|
|
494
|
+
}
|
|
495
|
+
finally {
|
|
496
|
+
currentEffect = previousEffect;
|
|
497
|
+
computing = false;
|
|
498
|
+
}
|
|
453
499
|
};
|
|
454
500
|
const read = () => {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
// Track dependency
|
|
458
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
459
|
-
subscribers.add(currentEffect);
|
|
460
|
-
if (currentEffect.__dependencies) {
|
|
461
|
-
currentEffect.__dependencies.add(subscribers);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
501
|
+
compute();
|
|
502
|
+
track(source);
|
|
464
503
|
return value;
|
|
465
504
|
};
|
|
466
505
|
// Create callable computed (read-only)
|
|
@@ -485,8 +524,14 @@ function computed(fn) {
|
|
|
485
524
|
},
|
|
486
525
|
subscribe: {
|
|
487
526
|
value: function (fn) {
|
|
488
|
-
|
|
489
|
-
|
|
527
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
528
|
+
let first = true;
|
|
529
|
+
return effect(() => {
|
|
530
|
+
read();
|
|
531
|
+
if (!first)
|
|
532
|
+
untrack(fn);
|
|
533
|
+
first = false;
|
|
534
|
+
});
|
|
490
535
|
},
|
|
491
536
|
enumerable: true,
|
|
492
537
|
configurable: true
|
|
@@ -537,11 +582,15 @@ function computed(fn) {
|
|
|
537
582
|
*/
|
|
538
583
|
function effect(fn) {
|
|
539
584
|
let cleanup;
|
|
540
|
-
|
|
585
|
+
const dependencies = new Set();
|
|
586
|
+
const versions = new Map();
|
|
541
587
|
let active = true;
|
|
588
|
+
let initialized = false;
|
|
542
589
|
const execute = () => {
|
|
543
590
|
if (!active)
|
|
544
591
|
return;
|
|
592
|
+
if (initialized && !dependenciesChanged(versions))
|
|
593
|
+
return;
|
|
545
594
|
// Prevent recursive execution - if already running, skip
|
|
546
595
|
if (runningEffects.has(execute)) {
|
|
547
596
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -556,10 +605,13 @@ function effect(fn) {
|
|
|
556
605
|
});
|
|
557
606
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
558
607
|
dependencies.clear();
|
|
608
|
+
versions.clear();
|
|
559
609
|
// Clean up previous run
|
|
560
610
|
if (cleanup) {
|
|
611
|
+
const previousCleanup = cleanup;
|
|
612
|
+
cleanup = undefined;
|
|
561
613
|
try {
|
|
562
|
-
|
|
614
|
+
untrack(previousCleanup);
|
|
563
615
|
}
|
|
564
616
|
catch (error) {
|
|
565
617
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -570,6 +622,7 @@ function effect(fn) {
|
|
|
570
622
|
currentEffect = execute;
|
|
571
623
|
// Store dependencies for cleanup
|
|
572
624
|
execute.__dependencies = dependencies;
|
|
625
|
+
execute.__versions = versions;
|
|
573
626
|
try {
|
|
574
627
|
const nextCleanup = fn();
|
|
575
628
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -579,6 +632,7 @@ function effect(fn) {
|
|
|
579
632
|
// Don't throw - allow other effects to continue
|
|
580
633
|
}
|
|
581
634
|
finally {
|
|
635
|
+
initialized = true;
|
|
582
636
|
currentEffect = prevEffect;
|
|
583
637
|
effectDepth--;
|
|
584
638
|
runningEffects.delete(execute);
|
|
@@ -595,14 +649,17 @@ function effect(fn) {
|
|
|
595
649
|
if (!active)
|
|
596
650
|
return;
|
|
597
651
|
active = false;
|
|
652
|
+
effectQueue.delete(execute);
|
|
653
|
+
batchedEffects.delete(execute);
|
|
598
654
|
// Remove from all dependencies
|
|
599
655
|
dependencies.forEach(depSet => {
|
|
600
656
|
depSet.delete(execute);
|
|
601
657
|
});
|
|
602
658
|
dependencies.clear();
|
|
659
|
+
versions.clear();
|
|
603
660
|
if (cleanup) {
|
|
604
661
|
try {
|
|
605
|
-
cleanup
|
|
662
|
+
untrack(cleanup);
|
|
606
663
|
}
|
|
607
664
|
catch (error) {
|
|
608
665
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -662,6 +719,8 @@ function batch(fn) {
|
|
|
662
719
|
const effects = Array.from(batchedEffects);
|
|
663
720
|
batchedEffects.clear();
|
|
664
721
|
effects.forEach(effect => {
|
|
722
|
+
// This batch also settles any earlier queued write to this observer.
|
|
723
|
+
effectQueue.delete(effect);
|
|
665
724
|
try {
|
|
666
725
|
effect();
|
|
667
726
|
}
|
|
@@ -5571,6 +5630,21 @@ setMountFunction(mount);
|
|
|
5571
5630
|
* Registry of all scopes
|
|
5572
5631
|
*/
|
|
5573
5632
|
const scopeRegistry = new Map();
|
|
5633
|
+
const warnedReveals = new WeakSet();
|
|
5634
|
+
function diagnoseUnscopedReveals(root) {
|
|
5635
|
+
if (!DEBUG())
|
|
5636
|
+
return;
|
|
5637
|
+
const elements = [...root.querySelectorAll('[g-reveal]')];
|
|
5638
|
+
if (root instanceof Element && root.hasAttribute('g-reveal'))
|
|
5639
|
+
elements.unshift(root);
|
|
5640
|
+
for (const element of elements) {
|
|
5641
|
+
if (warnedReveals.has(element) || isInIgnoredTree(element)
|
|
5642
|
+
|| element.closest('[g-scope]') || getScopeFromElement(element))
|
|
5643
|
+
continue;
|
|
5644
|
+
warnedReveals.add(element);
|
|
5645
|
+
console.warn('[Gyos] g-reveal has no owning scope. Add g-scope to its container; global reveal CSS may otherwise hide this content.', element);
|
|
5646
|
+
}
|
|
5647
|
+
}
|
|
5574
5648
|
/**
|
|
5575
5649
|
* Register a scope
|
|
5576
5650
|
*/
|
|
@@ -5618,6 +5692,7 @@ function mountAll(root) {
|
|
|
5618
5692
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5619
5693
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
5620
5694
|
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
5695
|
+
diagnoseUnscopedReveals(document.body);
|
|
5621
5696
|
}
|
|
5622
5697
|
function mountTree(el) {
|
|
5623
5698
|
if (isInIgnoredTree(el) || !document.body.contains(el))
|
|
@@ -5628,6 +5703,7 @@ function mountTree(el) {
|
|
|
5628
5703
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
5629
5704
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5630
5705
|
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
5706
|
+
diagnoseUnscopedReveals(el);
|
|
5631
5707
|
if (getMountedScope(el))
|
|
5632
5708
|
return;
|
|
5633
5709
|
const ownerScope = getScopeFromElement(el);
|
|
@@ -5646,7 +5722,7 @@ function mount(el) {
|
|
|
5646
5722
|
return;
|
|
5647
5723
|
// Check if element removed but still has g-scope (possible in some edge cases)
|
|
5648
5724
|
getAllMountedScopes().forEach((_, mountedEl) => {
|
|
5649
|
-
if (!
|
|
5725
|
+
if (!mountedEl.isConnected) {
|
|
5650
5726
|
disposeEffects(mountedEl);
|
|
5651
5727
|
}
|
|
5652
5728
|
});
|
|
@@ -6958,7 +7034,8 @@ function getPersistKey(el, generateIfMissing = false) {
|
|
|
6958
7034
|
el.dataset.gyosPersistId = key;
|
|
6959
7035
|
return key;
|
|
6960
7036
|
}
|
|
6961
|
-
//
|
|
7037
|
+
// Keep the parking host outside body: body itself may be the swap target.
|
|
7038
|
+
// A disconnected parking host makes browsers pause otherwise persisted media.
|
|
6962
7039
|
const persistParking = typeof document !== 'undefined'
|
|
6963
7040
|
? (() => {
|
|
6964
7041
|
const park = document.createElement('div');
|
|
@@ -6967,12 +7044,7 @@ const persistParking = typeof document !== 'undefined'
|
|
|
6967
7044
|
park.style.top = '-99999px';
|
|
6968
7045
|
park.style.width = '0';
|
|
6969
7046
|
park.style.height = '0';
|
|
6970
|
-
|
|
6971
|
-
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(park));
|
|
6972
|
-
}
|
|
6973
|
-
else {
|
|
6974
|
-
document.body.appendChild(park);
|
|
6975
|
-
}
|
|
7047
|
+
document.documentElement.appendChild(park);
|
|
6976
7048
|
return park;
|
|
6977
7049
|
})()
|
|
6978
7050
|
: null;
|
|
@@ -6983,8 +7055,8 @@ function elementsIn(root) {
|
|
|
6983
7055
|
return elements;
|
|
6984
7056
|
}
|
|
6985
7057
|
function ensureParkingIsConnected() {
|
|
6986
|
-
if (persistParking &&
|
|
6987
|
-
document.
|
|
7058
|
+
if (persistParking && persistParking.parentElement !== document.documentElement) {
|
|
7059
|
+
document.documentElement.appendChild(persistParking);
|
|
6988
7060
|
}
|
|
6989
7061
|
}
|
|
6990
7062
|
function detachPersist(root = document) {
|
|
@@ -7002,12 +7074,18 @@ function detachPersist(root = document) {
|
|
|
7002
7074
|
});
|
|
7003
7075
|
}
|
|
7004
7076
|
function mergePersistIntoLive(root) {
|
|
7077
|
+
// Return the host to the current body before scope mounting/cleanup inspects it.
|
|
7078
|
+
if (persistParking && persistParking.parentElement !== document.body) {
|
|
7079
|
+
document.body.appendChild(persistParking);
|
|
7080
|
+
}
|
|
7005
7081
|
if (!persistEntries.size)
|
|
7006
7082
|
return;
|
|
7007
7083
|
// If placeholders lack ids but we only have one persist entry, assign its key for convenience
|
|
7008
7084
|
if (persistEntries.size === 1) {
|
|
7009
7085
|
const loneKey = Array.from(persistEntries.keys())[0];
|
|
7010
7086
|
elementsIn(root).forEach(el => {
|
|
7087
|
+
if (persistParking?.contains(el))
|
|
7088
|
+
return;
|
|
7011
7089
|
if (!getPersistKey(el, false)) {
|
|
7012
7090
|
el.dataset.gyosPersistId = loneKey;
|
|
7013
7091
|
}
|
|
@@ -7015,6 +7093,8 @@ function mergePersistIntoLive(root) {
|
|
|
7015
7093
|
}
|
|
7016
7094
|
// Element placeholders
|
|
7017
7095
|
elementsIn(root).forEach(placeholder => {
|
|
7096
|
+
if (persistParking?.contains(placeholder))
|
|
7097
|
+
return;
|
|
7018
7098
|
const key = getPersistKey(placeholder, false);
|
|
7019
7099
|
if (!key)
|
|
7020
7100
|
return;
|
|
@@ -7032,6 +7112,8 @@ function mergePersistIntoLive(root) {
|
|
|
7032
7112
|
const toReplace = [];
|
|
7033
7113
|
while (walker.nextNode()) {
|
|
7034
7114
|
const comment = walker.currentNode;
|
|
7115
|
+
if (persistParking?.contains(comment))
|
|
7116
|
+
continue;
|
|
7035
7117
|
const match = comment.data.match(/g-persist[:=]\s*([A-Za-z0-9_\-:.]+)/);
|
|
7036
7118
|
if (match) {
|
|
7037
7119
|
toReplace.push({ node: comment, key: match[1] });
|
|
@@ -7689,6 +7771,36 @@ function prepareNavigationHtml(html) {
|
|
|
7689
7771
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
7690
7772
|
*/
|
|
7691
7773
|
const submittingForms = new WeakSet();
|
|
7774
|
+
async function visit(url, options, fresh) {
|
|
7775
|
+
const destination = new URL(url, document.baseURI);
|
|
7776
|
+
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
7777
|
+
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
7778
|
+
}
|
|
7779
|
+
if (options.target !== undefined && !(document.querySelector(options.target) instanceof HTMLElement)) {
|
|
7780
|
+
throw new TypeError('Gyos.navigate target does not exist.');
|
|
7781
|
+
}
|
|
7782
|
+
if (!document.querySelector('[g-boost]')) {
|
|
7783
|
+
throw new TypeError('Gyos.navigate requires a g-boost layout.');
|
|
7784
|
+
}
|
|
7785
|
+
startRouter();
|
|
7786
|
+
let result;
|
|
7787
|
+
await navigateRequest({
|
|
7788
|
+
url: destination.href, method: 'GET',
|
|
7789
|
+
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
7790
|
+
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
7791
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, fresh,
|
|
7792
|
+
onEnd: context => { result = context; }
|
|
7793
|
+
});
|
|
7794
|
+
return result;
|
|
7795
|
+
}
|
|
7796
|
+
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
7797
|
+
function navigate(url, options = {}) {
|
|
7798
|
+
return visit(url, options, false);
|
|
7799
|
+
}
|
|
7800
|
+
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
7801
|
+
function refresh(options = {}) {
|
|
7802
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, true);
|
|
7803
|
+
}
|
|
7692
7804
|
const snapshots = new Map();
|
|
7693
7805
|
const preloadCache = new Map();
|
|
7694
7806
|
const preloadControllers = new Map();
|
|
@@ -8075,12 +8187,27 @@ function fallbackFromBoost(opts, url, requestSent) {
|
|
|
8075
8187
|
}
|
|
8076
8188
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8077
8189
|
}
|
|
8078
|
-
async function
|
|
8190
|
+
async function navigateRequest(opts) {
|
|
8191
|
+
const finishUnstarted = () => {
|
|
8192
|
+
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8193
|
+
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8194
|
+
signal: opts.signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8195
|
+
};
|
|
8196
|
+
if (opts.signal?.aborted) {
|
|
8197
|
+
finishUnstarted();
|
|
8198
|
+
return;
|
|
8199
|
+
}
|
|
8079
8200
|
while (activeNavigation) {
|
|
8080
8201
|
const previous = activeNavigation;
|
|
8081
8202
|
if (previous.committing) {
|
|
8082
8203
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8083
|
-
|
|
8204
|
+
try {
|
|
8205
|
+
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8206
|
+
}
|
|
8207
|
+
catch {
|
|
8208
|
+
finishUnstarted();
|
|
8209
|
+
return;
|
|
8210
|
+
}
|
|
8084
8211
|
continue;
|
|
8085
8212
|
}
|
|
8086
8213
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8099,6 +8226,10 @@ async function navigate(opts) {
|
|
|
8099
8226
|
resolveDone
|
|
8100
8227
|
};
|
|
8101
8228
|
activeNavigation = transaction;
|
|
8229
|
+
const abort = () => cancelNavigation(transaction);
|
|
8230
|
+
opts.signal?.addEventListener('abort', abort, { once: true });
|
|
8231
|
+
if (opts.signal?.aborted)
|
|
8232
|
+
abort();
|
|
8102
8233
|
const currentBaseUrl = document.baseURI;
|
|
8103
8234
|
rememberResourceUrls(document, currentBaseUrl);
|
|
8104
8235
|
const context = {
|
|
@@ -8122,6 +8253,7 @@ async function navigate(opts) {
|
|
|
8122
8253
|
}
|
|
8123
8254
|
};
|
|
8124
8255
|
try {
|
|
8256
|
+
assertActiveNavigation(transaction);
|
|
8125
8257
|
if (formEvent)
|
|
8126
8258
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8127
8259
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
@@ -8134,6 +8266,10 @@ async function navigate(opts) {
|
|
|
8134
8266
|
saveScrollPosition();
|
|
8135
8267
|
// Pick target element to swap
|
|
8136
8268
|
let target = resolveTarget(opts.trigger, opts.targetSelector, opts.targetOutletIndex);
|
|
8269
|
+
if (opts.strictTarget && (!opts.targetSelector || !target?.matches(opts.targetSelector))) {
|
|
8270
|
+
context.outcome = 'invalid-response';
|
|
8271
|
+
return; // A queued explicit target disappeared; never broaden the swap.
|
|
8272
|
+
}
|
|
8137
8273
|
context.target = target;
|
|
8138
8274
|
if (!target) {
|
|
8139
8275
|
if (isActiveNavigation(transaction))
|
|
@@ -8178,7 +8314,12 @@ async function navigate(opts) {
|
|
|
8178
8314
|
else {
|
|
8179
8315
|
// Check preload cache if GET
|
|
8180
8316
|
const preloadKey = canonicalUrl(finalUrl, true);
|
|
8181
|
-
if (opts.
|
|
8317
|
+
if (opts.fresh) {
|
|
8318
|
+
preloadControllers.get(preloadKey)?.abort();
|
|
8319
|
+
preloadControllers.delete(preloadKey);
|
|
8320
|
+
preloadCache.delete(preloadKey);
|
|
8321
|
+
}
|
|
8322
|
+
if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
|
|
8182
8323
|
log('[GyosRouter] using preload cache for', finalUrl);
|
|
8183
8324
|
try {
|
|
8184
8325
|
response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
|
|
@@ -8386,7 +8527,10 @@ async function navigate(opts) {
|
|
|
8386
8527
|
finalizeCommit();
|
|
8387
8528
|
}
|
|
8388
8529
|
// Handle scroll after mount scopes
|
|
8389
|
-
if (
|
|
8530
|
+
if (opts.scroll === false) {
|
|
8531
|
+
// Explicit refresh/navigation policy keeps the current viewport.
|
|
8532
|
+
}
|
|
8533
|
+
else if (changesState) {
|
|
8390
8534
|
handleScroll(targetUrl, opts.trigger);
|
|
8391
8535
|
}
|
|
8392
8536
|
else if (opts.popstate) {
|
|
@@ -8451,6 +8595,7 @@ async function navigate(opts) {
|
|
|
8451
8595
|
activeNavigation = null;
|
|
8452
8596
|
progressBar?.complete();
|
|
8453
8597
|
}
|
|
8598
|
+
opts.signal?.removeEventListener('abort', abort);
|
|
8454
8599
|
transaction.resolveDone();
|
|
8455
8600
|
if (formEvent)
|
|
8456
8601
|
submittingForms.delete(formEvent.form);
|
|
@@ -8461,6 +8606,7 @@ async function navigate(opts) {
|
|
|
8461
8606
|
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
8462
8607
|
}));
|
|
8463
8608
|
}
|
|
8609
|
+
opts.onEnd?.({ ...context });
|
|
8464
8610
|
}
|
|
8465
8611
|
}
|
|
8466
8612
|
function shouldBoost(el) {
|
|
@@ -8491,7 +8637,7 @@ function onClickRouter(element) {
|
|
|
8491
8637
|
const scope = getScopeFromElement(element);
|
|
8492
8638
|
const jsonData = evaluateExpression(decodeURIComponent(element.getAttribute(paramsAttr) || ''), scope, false);
|
|
8493
8639
|
// The default changeState is false, as this is commonly used for: load more, infinite scroll, etc.
|
|
8494
|
-
|
|
8640
|
+
navigateRequest({
|
|
8495
8641
|
url: parsedUrl.toString(), method, trigger: element, jsonData, changeState: false
|
|
8496
8642
|
});
|
|
8497
8643
|
}
|
|
@@ -8540,7 +8686,7 @@ function onClick(event) {
|
|
|
8540
8686
|
return;
|
|
8541
8687
|
event.preventDefault();
|
|
8542
8688
|
// The default changeState is true, as this is commonly used for: navigation, etc.
|
|
8543
|
-
|
|
8689
|
+
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
8544
8690
|
}
|
|
8545
8691
|
function onMouseOverCapture(event) {
|
|
8546
8692
|
const target = event.target;
|
|
@@ -8596,7 +8742,7 @@ function onSubmit(event) {
|
|
|
8596
8742
|
return;
|
|
8597
8743
|
const formData = new FormData(form, submitter);
|
|
8598
8744
|
submittingForms.add(form);
|
|
8599
|
-
void
|
|
8745
|
+
void navigateRequest({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
8600
8746
|
}
|
|
8601
8747
|
function onPopState(event) {
|
|
8602
8748
|
const url = window.location.href;
|
|
@@ -8614,14 +8760,14 @@ function onPopState(event) {
|
|
|
8614
8760
|
}
|
|
8615
8761
|
event.preventDefault();
|
|
8616
8762
|
// The browser changes location before popstate fires. Stop any pending page
|
|
8617
|
-
// script immediately, then let
|
|
8763
|
+
// script immediately, then let navigateRequest() wait for its DOM finalizer.
|
|
8618
8764
|
if (activeNavigation?.committing)
|
|
8619
8765
|
cancelNavigation(activeNavigation);
|
|
8620
8766
|
// The browser has already moved to the destination history entry. Keep the
|
|
8621
8767
|
// router's entry pointer aligned before any restored page script can navigate.
|
|
8622
8768
|
currentHistoryEntryId = destinationEntryId;
|
|
8623
8769
|
// No snapshot, do a normal navigation without changing history (changeState: false)
|
|
8624
|
-
|
|
8770
|
+
navigateRequest({
|
|
8625
8771
|
url,
|
|
8626
8772
|
method: 'GET',
|
|
8627
8773
|
replace: true,
|
|
@@ -8703,10 +8849,12 @@ const Gyos = {
|
|
|
8703
8849
|
onAfterNavigate,
|
|
8704
8850
|
onBeforeSwap,
|
|
8705
8851
|
onNavigationEnd,
|
|
8852
|
+
navigate,
|
|
8853
|
+
refresh,
|
|
8706
8854
|
portalCreate,
|
|
8707
8855
|
portalDestroy,
|
|
8708
8856
|
setCspNonce,
|
|
8709
|
-
version: '0.
|
|
8857
|
+
version: '0.5.0'
|
|
8710
8858
|
};
|
|
8711
8859
|
|
|
8712
8860
|
const standardExpressionRuntime = {
|