Skip to content

Commit

Permalink
Remove global visit options hook (added in #1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinink committed Nov 3, 2022
1 parent 40b128a commit eb25e18
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 209 deletions.
13 changes: 6 additions & 7 deletions packages/inertia-react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export interface InertiaFormProps<TForm = Record<string, any>> {
clearErrors: (...fields: (keyof TForm)[]) => void
setError(field: keyof TForm, value: string): void
setError(errors: Record<keyof TForm, string>): void
submit: (method: Inertia.Method, url: string, options?: Inertia.VisitParams) => void
get: (url: string, options?: Inertia.VisitParams) => void
patch: (url: string, options?: Inertia.VisitParams) => void
post: (url: string, options?: Inertia.VisitParams) => void
put: (url: string, options?: Inertia.VisitParams) => void
delete: (url: string, options?: Inertia.VisitParams) => void
submit: (method: Inertia.Method, url: string, options?: Inertia.VisitOptions) => void
get: (url: string, options?: Inertia.VisitOptions) => void
patch: (url: string, options?: Inertia.VisitOptions) => void
post: (url: string, options?: Inertia.VisitOptions) => void
put: (url: string, options?: Inertia.VisitOptions) => void
delete: (url: string, options?: Inertia.VisitOptions) => void
}

export function useForm<TForm = Record<string, any>>(initialValues?: TForm): InertiaFormProps<TForm>;
Expand Down Expand Up @@ -127,7 +127,6 @@ export type InertiaAppOptionsForCSR<SharedProps> = BaseInertiaAppOptions & {
id?: string,
page?: Inertia.Page|string,
render?: undefined,
visitOptions?: Inertia.VisitOptions,
setup(options: SetupOptions<HTMLElement, SharedProps>): CreateInertiaAppSetupReturnType
}

Expand Down
2 changes: 0 additions & 2 deletions packages/inertia-react/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default function App({
resolveComponent,
titleCallback,
onHeadUpdate,
visitOptions,
}) {
const [current, setCurrent] = useState({
component: initialComponent || null,
Expand All @@ -37,7 +36,6 @@ export default function App({
key: preserveState ? current.key : Date.now(),
}))
},
visitOptions: visitOptions || (() => undefined),
})

Inertia.on('navigate', () => headManager.forceUpdate())
Expand Down
5 changes: 2 additions & 3 deletions packages/inertia-react/src/createInertiaApp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import App from './App'
import { createElement } from 'react'

export default async function createInertiaApp({ id = 'app', resolve, setup, title, visitOptions, page, render }) {
export default async function createInertiaApp({ id = 'app', resolve, setup, title, page, render }) {
const isServer = typeof window === 'undefined'
const el = isServer ? null : document.getElementById(id)
const initialPage = page || JSON.parse(el.dataset.page)
Expand All @@ -19,7 +19,6 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, tit
resolveComponent,
titleCallback: title,
onHeadUpdate: isServer ? elements => (head = elements) : null,
visitOptions,
},
})
})
Expand All @@ -29,7 +28,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, tit
createElement('div', {
id,
'data-page': JSON.stringify(initialPage),
}, reactApp),
}, reactApp)
)

return { head, body }
Expand Down
5 changes: 2 additions & 3 deletions packages/inertia-svelte/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Render, { h } from './Render.svelte'
import { Inertia } from '@inertiajs/inertia'
export let initialPage, resolveComponent, visitOptions
export let initialPage, resolveComponent
Inertia.init({
initialPage,
Expand All @@ -14,8 +14,7 @@
page,
key: preserveState ? current.key : Date.now()
}))
},
visitOptions,
}
})
$: child = $store.component && h($store.component.default, $store.page.props)
Expand Down
3 changes: 1 addition & 2 deletions packages/inertia-svelte/src/createInertiaApp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import App from './App.svelte'

export default async function createInertiaApp({ id = 'app', resolve, setup, visitOptions, page, render }) {
export default async function createInertiaApp({ id = 'app', resolve, setup, page, render }) {
const isServer = typeof window === 'undefined'
const el = isServer ? null : document.getElementById(id)
const initialPage = page || JSON.parse(el.dataset.page)
Expand All @@ -17,7 +17,6 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, vis
initialComponent,
resolveComponent,
onHeadUpdate: isServer ? elements => (head = elements) : null,
visitOptions,
},
})
})
Expand Down
13 changes: 6 additions & 7 deletions packages/inertia-vue/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export interface CreateInertiaAppProps {
title?: (title: string) => string
page?: Inertia.Page
render?: (vm: Vue) => Promise<string>
visitOptions?: Inertia.VisitOptions
}

export declare function createInertiaApp(props: CreateInertiaAppProps): Promise<{ head: string[], body: string } | void>
Expand Down Expand Up @@ -86,12 +85,12 @@ export interface InertiaFormProps<TForm> {
clearErrors(...fields: (keyof TForm)[]): this
setError(field: keyof TForm, value: string): this
setError(errors: Record<keyof TForm, string>): this
submit(method: string, url: string, options?: Partial<Inertia.VisitParams>): void
get(url: string, options?: Partial<Inertia.VisitParams>): void
post(url: string, options?: Partial<Inertia.VisitParams>): void
put(url: string, options?: Partial<Inertia.VisitParams>): void
patch(url: string, options?: Partial<Inertia.VisitParams>): void
delete(url: string, options?: Partial<Inertia.VisitParams>): void
submit(method: string, url: string, options?: Partial<Inertia.VisitOptions>): void
get(url: string, options?: Partial<Inertia.VisitOptions>): void
post(url: string, options?: Partial<Inertia.VisitOptions>): void
put(url: string, options?: Partial<Inertia.VisitOptions>): void
patch(url: string, options?: Partial<Inertia.VisitOptions>): void
delete(url: string, options?: Partial<Inertia.VisitOptions>): void
cancel(): void
}

Expand Down
6 changes: 0 additions & 6 deletions packages/inertia-vue/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export default {
required: false,
default: () => () => {},
},
visitOptions: {
type: Function,
required: false,
default: () => undefined,
},
},
data() {
return {
Expand All @@ -56,7 +51,6 @@ export default {
this.page = page
this.key = preserveState ? this.key : Date.now()
},
visitOptions: this.visitOptions,
})

Inertia.on('navigate', () => headManager.forceUpdate())
Expand Down
3 changes: 1 addition & 2 deletions packages/inertia-vue/src/createInertiaApp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import App, { plugin } from './app'

export default async function createInertiaApp({ id = 'app', resolve, setup, title, visitOptions, page, render }) {
export default async function createInertiaApp({ id = 'app', resolve, setup, title, page, render }) {
const isServer = typeof window === 'undefined'
const el = isServer ? null : document.getElementById(id)
const initialPage = page || JSON.parse(el.dataset.page)
Expand All @@ -24,7 +24,6 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, tit
resolveComponent,
titleCallback: title,
onHeadUpdate: isServer ? elements => (head = elements) : null,
visitOptions,
},
},
plugin,
Expand Down
1 change: 0 additions & 1 deletion packages/inertia-vue/src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default {
data.on = {
click: () => ({}),
cancelToken: () => ({}),
before: () => ({}),
start: () => ({}),
progress: () => ({}),
finish: () => ({}),
Expand Down
130 changes: 6 additions & 124 deletions packages/inertia-vue3/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,124 +1,6 @@
import * as Inertia from '@inertiajs/inertia'
import { Ref, ComputedRef, App as VueApp, DefineComponent, Plugin } from 'vue'

export interface InertiaAppProps {
initialPage: Inertia.Page
initialComponent?: object
resolveComponent?: (name: string) => DefineComponent | Promise<DefineComponent>
onHeadUpdate?: (elements: string[]) => void
}

type InertiaApp = DefineComponent<InertiaAppProps>

export declare const App: InertiaApp

export declare const plugin: Plugin

export interface CreateInertiaAppProps {
id?: string
resolve: (name: string) =>
DefineComponent |
Promise<DefineComponent> |
{ default: DefineComponent }
setup: (props: {
el: Element
app: InertiaApp
props: InertiaAppProps
plugin: Plugin
}) => void | VueApp
title?: (title: string) => string
page?: Inertia.Page
render?: (app: VueApp) => Promise<string>
visitOptions?: Inertia.VisitOptions
}

export declare function createInertiaApp(props: CreateInertiaAppProps): Promise<{ head: string[], body: string } | void>

export interface InertiaLinkProps {
as?: string
data?: object
href: string
method?: string
headers?: object
onClick?: (event: MouseEvent | KeyboardEvent) => void
preserveScroll?: boolean | ((props: Inertia.PageProps) => boolean)
preserveState?: boolean | ((props: Inertia.PageProps) => boolean) | null
replace?: boolean
only?: string[]
onCancelToken?: (cancelToken: import('axios').CancelTokenSource) => void
onBefore?: () => void
onStart?: () => void
onProgress?: (progress: Inertia.Progress) => void
onFinish?: () => void
onCancel?: () => void
onSuccess?: () => void
}

export type InertiaLink = DefineComponent<InertiaLinkProps>

export declare const Link: InertiaLink

export interface InertiaFormProps<TForm> {
isDirty: boolean
errors: Record<keyof TForm, string>
hasErrors: boolean
processing: boolean
progress: Inertia.Progress | null
wasSuccessful: boolean
recentlySuccessful: boolean
data(): TForm
transform(callback: (data: TForm) => object): this
defaults(): this
defaults(field: keyof TForm, value: string): this
defaults(fields: Record<keyof TForm, string>): this
reset(...fields: (keyof TForm)[]): this
clearErrors(...fields: (keyof TForm)[]): this
setError(field: keyof TForm, value: string): this
setError(errors: Record<keyof TForm, string>): this
submit(method: string, url: string, options?: Partial<Inertia.VisitParams>): void
get(url: string, options?: Partial<Inertia.VisitParams>): void
post(url: string, options?: Partial<Inertia.VisitParams>): void
put(url: string, options?: Partial<Inertia.VisitParams>): void
patch(url: string, options?: Partial<Inertia.VisitParams>): void
delete(url: string, options?: Partial<Inertia.VisitParams>): void
cancel(): void
}

export type InertiaForm<TForm> = TForm & InertiaFormProps<TForm>

export declare function useForm<TForm>(data: TForm): InertiaForm<TForm>

export declare function useForm<TForm>(rememberKey: string, data: TForm): InertiaForm<TForm>

export declare function useRemember(data: object, key?: string): Ref<object>

export declare function usePage<PageProps>(): {
props: ComputedRef<PageProps & Inertia.PageProps>
url: ComputedRef<string>
component: ComputedRef<string>
version: ComputedRef<string | null>
}

export type InertiaHead = DefineComponent<{
title?: string
}>

export declare const Head: InertiaHead

declare module '@vue/runtime-core' {
export interface ComponentCustomProperties {
$inertia: typeof Inertia.Inertia
$page: Inertia.Page
$headManager: ReturnType<typeof Inertia.createHeadManager>
}

export interface ComponentCustomOptions {
remember?:
string |
string[] |
{
data: string | string[]
key?: string | (() => string)
}
}
}
export { default as useForm } from "./useForm";
export { default as useRemember } from "./useRemember";
export { default as createInertiaApp } from "./createInertiaApp";
export { default as Head, default as InertiaHead } from "./head";
export { default as Link, default as InertiaLink, default as link } from "./link";
export { default as App, default as InertiaApp, default as app, plugin, usePage } from "./app";
8 changes: 1 addition & 7 deletions packages/inertia-vue3/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ export default {
required: false,
default: () => () => {},
},
visitOptions: {
type: Function,
required: false,
default: () => undefined,
},
},
setup({ initialPage, initialComponent, resolveComponent, titleCallback, onHeadUpdate, visitOptions }) {
setup({ initialPage, initialComponent, resolveComponent, titleCallback, onHeadUpdate }) {
component.value = initialComponent ? markRaw(initialComponent) : null
page.value = initialPage
key.value = null
Expand All @@ -56,7 +51,6 @@ export default {
page.value = args.page
key.value = args.preserveState ? key.value : Date.now()
},
visitOptions,
})

Inertia.on('navigate', () => headManager.forceUpdate())
Expand Down
3 changes: 1 addition & 2 deletions packages/inertia-vue3/src/createInertiaApp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSSRApp, h } from 'vue'
import App, { plugin } from './app'

export default async function createInertiaApp({ id = 'app', resolve, setup, title, visitOptions, page, render }) {
export default async function createInertiaApp({ id = 'app', resolve, setup, title, page, render }) {
const isServer = typeof window === 'undefined'
const el = isServer ? null : document.getElementById(id)
const initialPage = page || JSON.parse(el.dataset.page)
Expand All @@ -20,7 +20,6 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, tit
resolveComponent,
titleCallback: title,
onHeadUpdate: isServer ? elements => (head = elements) : null,
visitOptions,
},
plugin,
})
Expand Down
Loading

0 comments on commit eb25e18

Please sign in to comment.