gyosjs 0.4.1 → 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 +1 -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 +110 -21
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +110 -21
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +110 -21
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +110 -21
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +111 -22
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +112 -21
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +111 -22
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +112 -21
- 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/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ GyosJS is not trying to replace a full SPA framework. If your app is primarily c
|
|
|
34
34
|
Use the browser auto-init build when you want HTML-first usage with minimal setup.
|
|
35
35
|
|
|
36
36
|
```html
|
|
37
|
-
<script src="https://cdn.jsdelivr.net/npm/gyosjs@0.
|
|
37
|
+
<script src="https://cdn.jsdelivr.net/npm/gyosjs@0.5.0/dist/gyos.auto.min.js"></script>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
That build attaches `window.Gyos`, starts the router when `g-boost` exists, injects transition styles, and mounts scopes when the page is ready.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/core/component.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,eAAe,EAAkC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/core/component.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,eAAe,EAAkC,MAAM,UAAU,CAAC;AAkCvF;;GAEG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,UAAU,EAAE,eAAe,GAAG,IAAI,CAWnF;AAWD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CA0BzE;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,CAe/C;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,CAe3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persist.d.ts","sourceRoot":"","sources":["../../../src/core/router/persist.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"persist.d.ts","sourceRoot":"","sources":["../../../src/core/router/persist.ts"],"names":[],"mappings":"AAgDA,wBAAgB,aAAa,CAAC,IAAI,GAAE,UAAqB,GAAG,IAAI,CAU/D;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAkD3D;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC"}
|
|
@@ -44,10 +44,28 @@ interface NavigateOptions {
|
|
|
44
44
|
targetOutletIndex?: number | null;
|
|
45
45
|
swapMode?: string;
|
|
46
46
|
currentHead?: boolean;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
scroll?: boolean;
|
|
49
|
+
fresh?: boolean;
|
|
50
|
+
strictTarget?: boolean;
|
|
51
|
+
onEnd?: (context: NavigationContext) => void;
|
|
47
52
|
historyFragment?: HTMLElement;
|
|
48
53
|
historyEntryId?: string | null;
|
|
49
54
|
scrollSourceEntryId?: string | null;
|
|
50
55
|
}
|
|
56
|
+
/** Options for an explicit same-origin GET navigation. */
|
|
57
|
+
export interface NavigationOptions {
|
|
58
|
+
history?: 'push' | 'replace' | 'none';
|
|
59
|
+
target?: string;
|
|
60
|
+
swap?: 'inner' | 'replace' | 'morph' | 'append' | 'prepend';
|
|
61
|
+
scroll?: boolean;
|
|
62
|
+
currentHead?: boolean;
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
}
|
|
65
|
+
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
66
|
+
export declare function navigate(url: string | URL, options?: NavigationOptions): Promise<NavigationContext>;
|
|
67
|
+
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
68
|
+
export declare function refresh(options?: NavigationOptions): Promise<NavigationContext>;
|
|
51
69
|
interface Snapshot {
|
|
52
70
|
html: string;
|
|
53
71
|
fullDocument: boolean;
|
|
@@ -58,10 +76,10 @@ export declare function onBeforeSwap(callback: NavigationHook): () => void;
|
|
|
58
76
|
export declare function onNavigationEnd(callback: (context: NavigationContext) => void): () => void;
|
|
59
77
|
export declare function startRouter(options?: RouterOptions): void;
|
|
60
78
|
declare function saveSnapshot(url: string, html: string): void;
|
|
61
|
-
declare function
|
|
79
|
+
declare function navigateRequest(opts: NavigateOptions): Promise<void>;
|
|
62
80
|
declare function resetRouterState(): void;
|
|
63
81
|
export declare const __routerTest: {
|
|
64
|
-
navigate: typeof
|
|
82
|
+
navigate: typeof navigateRequest;
|
|
65
83
|
saveSnapshot: typeof saveSnapshot;
|
|
66
84
|
snapshots: Map<string, Snapshot>;
|
|
67
85
|
preloadCache: Map<string, Promise<Response>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/core/router/router.ts"],"names":[],"mappings":"AAoBA,MAAM,WA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MAAM,GAAG,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAEvG;AAED,6EAA6E;AAC7E,wBAAgB,OAAO,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAEnF;AAgBD,UAAU,QAAQ;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,OAAO,CAAC;CACtB;AA6CD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAErE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAEpE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAEjE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,MAAM,IAAI,CAE1F;AAED,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CA4BzD;AAiED,iBAAS,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAcrD;AA0RD,iBAAe,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA4ZnE;AAwKD,iBAAS,gBAAgB,IAAI,IAAI,CAwBhC;AAGD,eAAO,MAAM,YAAY;;;;;;CAMxB,CAAC"}
|
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
|
*/
|
|
@@ -5630,6 +5630,21 @@ setMountFunction(mount);
|
|
|
5630
5630
|
* Registry of all scopes
|
|
5631
5631
|
*/
|
|
5632
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
|
+
}
|
|
5633
5648
|
/**
|
|
5634
5649
|
* Register a scope
|
|
5635
5650
|
*/
|
|
@@ -5677,6 +5692,7 @@ function mountAll(root) {
|
|
|
5677
5692
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5678
5693
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
5679
5694
|
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
5695
|
+
diagnoseUnscopedReveals(document.body);
|
|
5680
5696
|
}
|
|
5681
5697
|
function mountTree(el) {
|
|
5682
5698
|
if (isInIgnoredTree(el) || !document.body.contains(el))
|
|
@@ -5687,6 +5703,7 @@ function mountTree(el) {
|
|
|
5687
5703
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
5688
5704
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5689
5705
|
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
5706
|
+
diagnoseUnscopedReveals(el);
|
|
5690
5707
|
if (getMountedScope(el))
|
|
5691
5708
|
return;
|
|
5692
5709
|
const ownerScope = getScopeFromElement(el);
|
|
@@ -5705,7 +5722,7 @@ function mount(el) {
|
|
|
5705
5722
|
return;
|
|
5706
5723
|
// Check if element removed but still has g-scope (possible in some edge cases)
|
|
5707
5724
|
getAllMountedScopes().forEach((_, mountedEl) => {
|
|
5708
|
-
if (!
|
|
5725
|
+
if (!mountedEl.isConnected) {
|
|
5709
5726
|
disposeEffects(mountedEl);
|
|
5710
5727
|
}
|
|
5711
5728
|
});
|
|
@@ -7017,7 +7034,8 @@ function getPersistKey(el, generateIfMissing = false) {
|
|
|
7017
7034
|
el.dataset.gyosPersistId = key;
|
|
7018
7035
|
return key;
|
|
7019
7036
|
}
|
|
7020
|
-
//
|
|
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.
|
|
7021
7039
|
const persistParking = typeof document !== 'undefined'
|
|
7022
7040
|
? (() => {
|
|
7023
7041
|
const park = document.createElement('div');
|
|
@@ -7026,12 +7044,7 @@ const persistParking = typeof document !== 'undefined'
|
|
|
7026
7044
|
park.style.top = '-99999px';
|
|
7027
7045
|
park.style.width = '0';
|
|
7028
7046
|
park.style.height = '0';
|
|
7029
|
-
|
|
7030
|
-
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(park));
|
|
7031
|
-
}
|
|
7032
|
-
else {
|
|
7033
|
-
document.body.appendChild(park);
|
|
7034
|
-
}
|
|
7047
|
+
document.documentElement.appendChild(park);
|
|
7035
7048
|
return park;
|
|
7036
7049
|
})()
|
|
7037
7050
|
: null;
|
|
@@ -7042,8 +7055,8 @@ function elementsIn(root) {
|
|
|
7042
7055
|
return elements;
|
|
7043
7056
|
}
|
|
7044
7057
|
function ensureParkingIsConnected() {
|
|
7045
|
-
if (persistParking &&
|
|
7046
|
-
document.
|
|
7058
|
+
if (persistParking && persistParking.parentElement !== document.documentElement) {
|
|
7059
|
+
document.documentElement.appendChild(persistParking);
|
|
7047
7060
|
}
|
|
7048
7061
|
}
|
|
7049
7062
|
function detachPersist(root = document) {
|
|
@@ -7061,12 +7074,18 @@ function detachPersist(root = document) {
|
|
|
7061
7074
|
});
|
|
7062
7075
|
}
|
|
7063
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
|
+
}
|
|
7064
7081
|
if (!persistEntries.size)
|
|
7065
7082
|
return;
|
|
7066
7083
|
// If placeholders lack ids but we only have one persist entry, assign its key for convenience
|
|
7067
7084
|
if (persistEntries.size === 1) {
|
|
7068
7085
|
const loneKey = Array.from(persistEntries.keys())[0];
|
|
7069
7086
|
elementsIn(root).forEach(el => {
|
|
7087
|
+
if (persistParking?.contains(el))
|
|
7088
|
+
return;
|
|
7070
7089
|
if (!getPersistKey(el, false)) {
|
|
7071
7090
|
el.dataset.gyosPersistId = loneKey;
|
|
7072
7091
|
}
|
|
@@ -7074,6 +7093,8 @@ function mergePersistIntoLive(root) {
|
|
|
7074
7093
|
}
|
|
7075
7094
|
// Element placeholders
|
|
7076
7095
|
elementsIn(root).forEach(placeholder => {
|
|
7096
|
+
if (persistParking?.contains(placeholder))
|
|
7097
|
+
return;
|
|
7077
7098
|
const key = getPersistKey(placeholder, false);
|
|
7078
7099
|
if (!key)
|
|
7079
7100
|
return;
|
|
@@ -7091,6 +7112,8 @@ function mergePersistIntoLive(root) {
|
|
|
7091
7112
|
const toReplace = [];
|
|
7092
7113
|
while (walker.nextNode()) {
|
|
7093
7114
|
const comment = walker.currentNode;
|
|
7115
|
+
if (persistParking?.contains(comment))
|
|
7116
|
+
continue;
|
|
7094
7117
|
const match = comment.data.match(/g-persist[:=]\s*([A-Za-z0-9_\-:.]+)/);
|
|
7095
7118
|
if (match) {
|
|
7096
7119
|
toReplace.push({ node: comment, key: match[1] });
|
|
@@ -7748,6 +7771,36 @@ function prepareNavigationHtml(html) {
|
|
|
7748
7771
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
7749
7772
|
*/
|
|
7750
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
|
+
}
|
|
7751
7804
|
const snapshots = new Map();
|
|
7752
7805
|
const preloadCache = new Map();
|
|
7753
7806
|
const preloadControllers = new Map();
|
|
@@ -8134,12 +8187,27 @@ function fallbackFromBoost(opts, url, requestSent) {
|
|
|
8134
8187
|
}
|
|
8135
8188
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8136
8189
|
}
|
|
8137
|
-
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
|
+
}
|
|
8138
8200
|
while (activeNavigation) {
|
|
8139
8201
|
const previous = activeNavigation;
|
|
8140
8202
|
if (previous.committing) {
|
|
8141
8203
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8142
|
-
|
|
8204
|
+
try {
|
|
8205
|
+
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8206
|
+
}
|
|
8207
|
+
catch {
|
|
8208
|
+
finishUnstarted();
|
|
8209
|
+
return;
|
|
8210
|
+
}
|
|
8143
8211
|
continue;
|
|
8144
8212
|
}
|
|
8145
8213
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8158,6 +8226,10 @@ async function navigate(opts) {
|
|
|
8158
8226
|
resolveDone
|
|
8159
8227
|
};
|
|
8160
8228
|
activeNavigation = transaction;
|
|
8229
|
+
const abort = () => cancelNavigation(transaction);
|
|
8230
|
+
opts.signal?.addEventListener('abort', abort, { once: true });
|
|
8231
|
+
if (opts.signal?.aborted)
|
|
8232
|
+
abort();
|
|
8161
8233
|
const currentBaseUrl = document.baseURI;
|
|
8162
8234
|
rememberResourceUrls(document, currentBaseUrl);
|
|
8163
8235
|
const context = {
|
|
@@ -8181,6 +8253,7 @@ async function navigate(opts) {
|
|
|
8181
8253
|
}
|
|
8182
8254
|
};
|
|
8183
8255
|
try {
|
|
8256
|
+
assertActiveNavigation(transaction);
|
|
8184
8257
|
if (formEvent)
|
|
8185
8258
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8186
8259
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
@@ -8193,6 +8266,10 @@ async function navigate(opts) {
|
|
|
8193
8266
|
saveScrollPosition();
|
|
8194
8267
|
// Pick target element to swap
|
|
8195
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
|
+
}
|
|
8196
8273
|
context.target = target;
|
|
8197
8274
|
if (!target) {
|
|
8198
8275
|
if (isActiveNavigation(transaction))
|
|
@@ -8237,7 +8314,12 @@ async function navigate(opts) {
|
|
|
8237
8314
|
else {
|
|
8238
8315
|
// Check preload cache if GET
|
|
8239
8316
|
const preloadKey = canonicalUrl(finalUrl, true);
|
|
8240
|
-
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)) {
|
|
8241
8323
|
log('[GyosRouter] using preload cache for', finalUrl);
|
|
8242
8324
|
try {
|
|
8243
8325
|
response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
|
|
@@ -8445,7 +8527,10 @@ async function navigate(opts) {
|
|
|
8445
8527
|
finalizeCommit();
|
|
8446
8528
|
}
|
|
8447
8529
|
// Handle scroll after mount scopes
|
|
8448
|
-
if (
|
|
8530
|
+
if (opts.scroll === false) {
|
|
8531
|
+
// Explicit refresh/navigation policy keeps the current viewport.
|
|
8532
|
+
}
|
|
8533
|
+
else if (changesState) {
|
|
8449
8534
|
handleScroll(targetUrl, opts.trigger);
|
|
8450
8535
|
}
|
|
8451
8536
|
else if (opts.popstate) {
|
|
@@ -8510,6 +8595,7 @@ async function navigate(opts) {
|
|
|
8510
8595
|
activeNavigation = null;
|
|
8511
8596
|
progressBar?.complete();
|
|
8512
8597
|
}
|
|
8598
|
+
opts.signal?.removeEventListener('abort', abort);
|
|
8513
8599
|
transaction.resolveDone();
|
|
8514
8600
|
if (formEvent)
|
|
8515
8601
|
submittingForms.delete(formEvent.form);
|
|
@@ -8520,6 +8606,7 @@ async function navigate(opts) {
|
|
|
8520
8606
|
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
8521
8607
|
}));
|
|
8522
8608
|
}
|
|
8609
|
+
opts.onEnd?.({ ...context });
|
|
8523
8610
|
}
|
|
8524
8611
|
}
|
|
8525
8612
|
function shouldBoost(el) {
|
|
@@ -8550,7 +8637,7 @@ function onClickRouter(element) {
|
|
|
8550
8637
|
const scope = getScopeFromElement(element);
|
|
8551
8638
|
const jsonData = evaluateExpression(decodeURIComponent(element.getAttribute(paramsAttr) || ''), scope, false);
|
|
8552
8639
|
// The default changeState is false, as this is commonly used for: load more, infinite scroll, etc.
|
|
8553
|
-
|
|
8640
|
+
navigateRequest({
|
|
8554
8641
|
url: parsedUrl.toString(), method, trigger: element, jsonData, changeState: false
|
|
8555
8642
|
});
|
|
8556
8643
|
}
|
|
@@ -8599,7 +8686,7 @@ function onClick(event) {
|
|
|
8599
8686
|
return;
|
|
8600
8687
|
event.preventDefault();
|
|
8601
8688
|
// The default changeState is true, as this is commonly used for: navigation, etc.
|
|
8602
|
-
|
|
8689
|
+
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
8603
8690
|
}
|
|
8604
8691
|
function onMouseOverCapture(event) {
|
|
8605
8692
|
const target = event.target;
|
|
@@ -8655,7 +8742,7 @@ function onSubmit(event) {
|
|
|
8655
8742
|
return;
|
|
8656
8743
|
const formData = new FormData(form, submitter);
|
|
8657
8744
|
submittingForms.add(form);
|
|
8658
|
-
void
|
|
8745
|
+
void navigateRequest({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
8659
8746
|
}
|
|
8660
8747
|
function onPopState(event) {
|
|
8661
8748
|
const url = window.location.href;
|
|
@@ -8673,14 +8760,14 @@ function onPopState(event) {
|
|
|
8673
8760
|
}
|
|
8674
8761
|
event.preventDefault();
|
|
8675
8762
|
// The browser changes location before popstate fires. Stop any pending page
|
|
8676
|
-
// script immediately, then let
|
|
8763
|
+
// script immediately, then let navigateRequest() wait for its DOM finalizer.
|
|
8677
8764
|
if (activeNavigation?.committing)
|
|
8678
8765
|
cancelNavigation(activeNavigation);
|
|
8679
8766
|
// The browser has already moved to the destination history entry. Keep the
|
|
8680
8767
|
// router's entry pointer aligned before any restored page script can navigate.
|
|
8681
8768
|
currentHistoryEntryId = destinationEntryId;
|
|
8682
8769
|
// No snapshot, do a normal navigation without changing history (changeState: false)
|
|
8683
|
-
|
|
8770
|
+
navigateRequest({
|
|
8684
8771
|
url,
|
|
8685
8772
|
method: 'GET',
|
|
8686
8773
|
replace: true,
|
|
@@ -8762,10 +8849,12 @@ const Gyos = {
|
|
|
8762
8849
|
onAfterNavigate,
|
|
8763
8850
|
onBeforeSwap,
|
|
8764
8851
|
onNavigationEnd,
|
|
8852
|
+
navigate,
|
|
8853
|
+
refresh,
|
|
8765
8854
|
portalCreate,
|
|
8766
8855
|
portalDestroy,
|
|
8767
8856
|
setCspNonce,
|
|
8768
|
-
version: '0.
|
|
8857
|
+
version: '0.5.0'
|
|
8769
8858
|
};
|
|
8770
8859
|
|
|
8771
8860
|
const standardExpressionRuntime = {
|