inertiax-svelte 11.0.39 → 11.0.41
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/dist/components/App.svelte +2 -2
- package/dist/components/Frame.svelte +30 -12
- package/dist/frameContext.svelte.d.ts +2 -2
- package/dist/frameContext.svelte.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/page.svelte.js +2 -2
- package/dist/useFormState.svelte.js +2 -2
- package/package.json +9 -9
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
<script lang="ts">
|
|
14
14
|
import { router } from 'inertiax-core'
|
|
15
|
-
import {
|
|
15
|
+
import { DEFAULT_FRAME } from '../frameContext.svelte'
|
|
16
16
|
import Frame from './Frame.svelte'
|
|
17
17
|
|
|
18
18
|
interface Props {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</script>
|
|
27
27
|
|
|
28
28
|
<Frame
|
|
29
|
-
id={
|
|
29
|
+
id={DEFAULT_FRAME}
|
|
30
30
|
{router}
|
|
31
31
|
{initialComponent}
|
|
32
32
|
{initialPage}
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
import { onDestroy, onMount } from 'svelte'
|
|
29
29
|
import { toStore } from 'svelte/store'
|
|
30
30
|
import type { Component } from 'svelte'
|
|
31
|
-
import {
|
|
31
|
+
import { DEFAULT_FRAME, setFrameContext, useFrameContext, useGlobalResolveComponent } from '../frameContext.svelte'
|
|
32
32
|
import { resetLayoutProps, storeState } from '../layoutProps.svelte'
|
|
33
33
|
import globalPage, { setPage } from '../page.svelte'
|
|
34
34
|
import type { LayoutResolver, LayoutType } from '../types'
|
|
@@ -77,15 +77,15 @@
|
|
|
77
77
|
return `frame-${Math.random().toString(36).slice(2, 10)}`
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
// Use explicit id > src > random UUID. Using src as the
|
|
80
|
+
// Use explicit id > src > random UUID. Using src as the frame gives
|
|
81
81
|
// frames a deterministic identity — remounts with the same src share
|
|
82
82
|
// history state, so the history-restore optimisation works naturally.
|
|
83
|
-
const
|
|
84
|
-
const shouldRenderLayout = renderLayout ??
|
|
83
|
+
const frame = id ?? src ?? createFrameId()
|
|
84
|
+
const shouldRenderLayout = renderLayout ?? frame === DEFAULT_FRAME
|
|
85
85
|
|
|
86
86
|
function resolveFrameComponent(name: string, page?: Page) {
|
|
87
87
|
if (!frameResolveComponent) {
|
|
88
|
-
throw new Error(`No resolveComponent available for frame "${
|
|
88
|
+
throw new Error(`No resolveComponent available for frame "${frame}"`)
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
// Empty component names occur during initial frame setup when the router
|
|
@@ -98,10 +98,10 @@
|
|
|
98
98
|
return frameResolveComponent(name, page)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
const frameRouter = router ?? createRouter(
|
|
101
|
+
const frameRouter = router ?? createRouter(frame)
|
|
102
102
|
|
|
103
103
|
// Frame-level visit options: non-top frames default to { replace: true, updateBrowserUrl: false }
|
|
104
|
-
const defaultFrameVisitOptions =
|
|
104
|
+
const defaultFrameVisitOptions = frame !== DEFAULT_FRAME
|
|
105
105
|
? { replace: true, updateBrowserUrl: false }
|
|
106
106
|
: { replace: false, updateBrowserUrl: true }
|
|
107
107
|
const frameVisitOptions = $derived({ ...defaultFrameVisitOptions, ...visitOptions })
|
|
@@ -137,19 +137,19 @@
|
|
|
137
137
|
|
|
138
138
|
|
|
139
139
|
setFrameContext({
|
|
140
|
-
id:
|
|
140
|
+
id: frame,
|
|
141
141
|
router: frameRouter,
|
|
142
142
|
resolveComponent: frameResolveComponent,
|
|
143
143
|
page: toStore(() => page ?? emptyPage),
|
|
144
144
|
visitOptions: frameVisitOptions,
|
|
145
145
|
})
|
|
146
146
|
|
|
147
|
-
if (
|
|
147
|
+
if (frame === DEFAULT_FRAME && page) {
|
|
148
148
|
setPage(page)
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
$effect.pre(() => {
|
|
152
|
-
if (
|
|
152
|
+
if (frame === DEFAULT_FRAME && page) {
|
|
153
153
|
setPage(page)
|
|
154
154
|
}
|
|
155
155
|
})
|
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
swapComponent: async (args) => {
|
|
177
177
|
// Sync the global page store for the top frame so usePage()
|
|
178
178
|
// outside of any Frame context stays up to date.
|
|
179
|
-
if (
|
|
179
|
+
if (frame === DEFAULT_FRAME) {
|
|
180
180
|
setPage(args.page)
|
|
181
181
|
}
|
|
182
182
|
component = args.component
|
|
@@ -243,6 +243,24 @@
|
|
|
243
243
|
},
|
|
244
244
|
})
|
|
245
245
|
|
|
246
|
+
// Handle 409 conflict responses (version mismatch / external redirect)
|
|
247
|
+
if (response.status === 409) {
|
|
248
|
+
const location = response.headers?.['x-inertia-location']
|
|
249
|
+
const redirect = response.headers?.['x-inertia-redirect']
|
|
250
|
+
|
|
251
|
+
if (location || redirect) {
|
|
252
|
+
if (frame !== DEFAULT_FRAME) {
|
|
253
|
+
// Non-top frames can't redirect the browser — reload the page so
|
|
254
|
+
// the app recovers at the document level.
|
|
255
|
+
window.location.reload()
|
|
256
|
+
} else {
|
|
257
|
+
window.location.href = location || redirect
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
246
264
|
let data: any = response.data
|
|
247
265
|
if (typeof data === 'string') {
|
|
248
266
|
try {
|
|
@@ -464,4 +482,4 @@
|
|
|
464
482
|
Invisible anchor used to find the nearest DOM parent for delegated click
|
|
465
483
|
handling and as a scroll-region anchor. display:contents so no layout box.
|
|
466
484
|
-->
|
|
467
|
-
<span style="display:contents" data-inertia-frame={
|
|
485
|
+
<span style="display:contents" data-inertia-frame={frame} {@attach attachClickHandler}></span>
|
|
@@ -2,7 +2,7 @@ import { type Router, type VisitOptions } from 'inertiax-core';
|
|
|
2
2
|
import type { Page } from 'inertiax-core';
|
|
3
3
|
import type { Readable } from 'svelte/store';
|
|
4
4
|
import type { ComponentResolver } from './types';
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const DEFAULT_FRAME = "_top";
|
|
6
6
|
export type FrameContext = {
|
|
7
7
|
id: string;
|
|
8
8
|
router: Router;
|
|
@@ -16,4 +16,4 @@ export declare function useFrameRouter(): Router;
|
|
|
16
16
|
export declare function useFrameResolveComponent(): ComponentResolver | undefined;
|
|
17
17
|
export declare function setGlobalResolveComponent(resolveComponent: ComponentResolver | undefined): void;
|
|
18
18
|
export declare function useGlobalResolveComponent(): ComponentResolver | undefined;
|
|
19
|
-
export declare function
|
|
19
|
+
export declare function useFrame(): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getContext, hasContext, setContext } from 'svelte';
|
|
2
2
|
import { router as globalRouter } from 'inertiax-core';
|
|
3
|
-
export const
|
|
3
|
+
export const DEFAULT_FRAME = '_top';
|
|
4
4
|
const FRAME_CONTEXT_KEY = Symbol('inertia:frame-context');
|
|
5
5
|
let globalResolveComponent;
|
|
6
6
|
export function setFrameContext(context) {
|
|
@@ -21,6 +21,6 @@ export function setGlobalResolveComponent(resolveComponent) {
|
|
|
21
21
|
export function useGlobalResolveComponent() {
|
|
22
22
|
return globalResolveComponent;
|
|
23
23
|
}
|
|
24
|
-
export function
|
|
25
|
-
return useFrameContext()?.id ??
|
|
24
|
+
export function useFrame() {
|
|
25
|
+
return useFrameContext()?.id ?? DEFAULT_FRAME;
|
|
26
26
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,5 +18,5 @@ export { default as useHttp } from './useHttp.svelte';
|
|
|
18
18
|
export { default as usePoll } from './usePoll';
|
|
19
19
|
export { default as usePrefetch } from './usePrefetch.svelte';
|
|
20
20
|
export { default as useRemember } from './useRemember.svelte';
|
|
21
|
-
export {
|
|
21
|
+
export { DEFAULT_FRAME, setFrameContext, useFrameContext, useFrame, useFrameRouter } from './frameContext.svelte';
|
|
22
22
|
export declare const config: import("inertiax-core").Config<import("inertiax-core").InertiaAppConfig>;
|
package/dist/index.js
CHANGED
|
@@ -19,5 +19,5 @@ export { default as useHttp } from './useHttp.svelte';
|
|
|
19
19
|
export { default as usePoll } from './usePoll';
|
|
20
20
|
export { default as usePrefetch } from './usePrefetch.svelte';
|
|
21
21
|
export { default as useRemember } from './useRemember.svelte';
|
|
22
|
-
export {
|
|
22
|
+
export { DEFAULT_FRAME, setFrameContext, useFrameContext, useFrame, useFrameRouter } from './frameContext.svelte';
|
|
23
23
|
export const config = coreConfig.extend({});
|
package/dist/page.svelte.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {} from 'inertiax-core';
|
|
2
2
|
import { get } from 'svelte/store';
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_FRAME, useFrameContext } from './frameContext.svelte';
|
|
4
4
|
const page = $state({
|
|
5
5
|
component: '',
|
|
6
6
|
props: {},
|
|
@@ -12,7 +12,7 @@ export function setPage(newPage) {
|
|
|
12
12
|
}
|
|
13
13
|
export function usePage() {
|
|
14
14
|
const context = useFrameContext();
|
|
15
|
-
if (!context || context.id ===
|
|
15
|
+
if (!context || context.id === DEFAULT_FRAME) {
|
|
16
16
|
return page;
|
|
17
17
|
}
|
|
18
18
|
return get(context.page);
|
|
@@ -3,10 +3,10 @@ import { cloneDeep, isEqual } from 'es-toolkit';
|
|
|
3
3
|
import { get, has, set } from 'es-toolkit/compat';
|
|
4
4
|
import { createValidator, resolveName, toSimpleValidationErrors } from 'laravel-precognition';
|
|
5
5
|
import { config } from '.';
|
|
6
|
-
import {
|
|
6
|
+
import { useFrame, useFrameRouter } from './frameContext.svelte';
|
|
7
7
|
export default function useFormState(options) {
|
|
8
8
|
const frameRouter = useFrameRouter();
|
|
9
|
-
const frameId =
|
|
9
|
+
const frameId = useFrame();
|
|
10
10
|
const { data: dataOption, rememberKey, precognitionEndpoint: initialPrecognitionEndpoint } = options;
|
|
11
11
|
const scopedRememberKey = rememberKey ? `${frameId}:${rememberKey}` : null;
|
|
12
12
|
const isDataFunction = typeof dataOption === 'function';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inertiax-svelte",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.41",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The Svelte adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -38,27 +38,27 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@sveltejs/adapter-auto": "^7.0.1",
|
|
41
|
-
"@sveltejs/kit": "^2.
|
|
41
|
+
"@sveltejs/kit": "^2.70.1",
|
|
42
42
|
"@sveltejs/package": "^2.5.8",
|
|
43
|
-
"@sveltejs/vite-plugin-svelte": "^7.
|
|
43
|
+
"@sveltejs/vite-plugin-svelte": "^7.2.0",
|
|
44
44
|
"es-check": "9.5.3",
|
|
45
45
|
"publint": "^0.3.21",
|
|
46
|
-
"svelte": "^5.56.
|
|
47
|
-
"svelte-check": "^4.
|
|
46
|
+
"svelte": "^5.56.7",
|
|
47
|
+
"svelte-check": "^4.7.3",
|
|
48
48
|
"tslib": "^2.8.1",
|
|
49
49
|
"typescript": "^6.0.3",
|
|
50
|
-
"vite": "^8.
|
|
50
|
+
"vite": "^8.1.5"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"svelte": "^5.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"es-toolkit": "^1.
|
|
56
|
+
"es-toolkit": "^1.49.0",
|
|
57
57
|
"laravel-precognition": "^2.0.0",
|
|
58
|
-
"inertiax-core": "11.0.
|
|
58
|
+
"inertiax-core": "11.0.41"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
|
-
"build": "pnpm package && svelte-check --tsconfig ./tsconfig.json
|
|
61
|
+
"build": "pnpm package && svelte-check --tsconfig ./tsconfig.json",
|
|
62
62
|
"build:with-deps": "svelte-kit sync && vite build --config vite-with-deps.config.js",
|
|
63
63
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
64
64
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|