diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..8f817ec --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,22 @@ +name: Docs + +on: + push: + branches: + - main + + pull_request: + paths: + - 'docs/**' + +jobs: + check_formatting: + runs-on: ubuntu-latest + name: Docs formatting + working-directory: ./docs + steps: + - uses: actions/checkout@v3 + - name: Install dependencies + run: npm install + - name: Check formatting + run: npm run format:check diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a6a9a9..235e4c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,6 +6,8 @@ on: - main pull_request: + paths-ignore: + - 'docs/**' jobs: lint: diff --git a/docs/.prettierignore b/docs/.prettierignore new file mode 100644 index 0000000..7137f7a --- /dev/null +++ b/docs/.prettierignore @@ -0,0 +1,3 @@ +**/node_modules +**/dist +**/cache diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index c41a6fb..019a431 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -1,10 +1,10 @@ -import { defineConfig } from "vitepress"; -import { tabsMarkdownPlugin } from "./vitepress-plugin-tabs/tabsMarkdownPlugin"; +import { defineConfig } from 'vitepress' +import { tabsMarkdownPlugin } from './vitepress-plugin-tabs/tabsMarkdownPlugin' -const title = "Inertia Rails"; -const description = "Community documentation for Inertia.js Rails adapter"; -const site = "https://inertia-rails.netlify.app"; -const image = `${site}/og_image.jpg`; +const title = 'Inertia Rails' +const description = 'Community documentation for Inertia.js Rails adapter' +const site = 'https://inertia-rails.netlify.app' +const image = `${site}/og_image.jpg` // https://vitepress.dev/reference/site-config export default defineConfig({ @@ -13,47 +13,47 @@ export default defineConfig({ markdown: { config(md) { - md.use(tabsMarkdownPlugin); + md.use(tabsMarkdownPlugin) }, }, head: [ - ["link", { rel: "icon", href: "/favicon.ico", sizes: "32x32" }], - ["link", { rel: "icon", href: "/icon.svg", type: "image/svg+xml" }], + ['link', { rel: 'icon', href: '/favicon.ico', sizes: '32x32' }], + ['link', { rel: 'icon', href: '/icon.svg', type: 'image/svg+xml' }], - ["meta", { name: "twitter:card", content: "summary_large_image" }], - ["meta", { name: "twitter:site", content: site }], - ["meta", { name: "twitter:description", value: description }], - ["meta", { name: "twitter:image", content: image }], + ['meta', { name: 'twitter:card', content: 'summary_large_image' }], + ['meta', { name: 'twitter:site', content: site }], + ['meta', { name: 'twitter:description', value: description }], + ['meta', { name: 'twitter:image', content: image }], - ["meta", { property: "og:type", content: "website" }], - ["meta", { property: "og:locale", content: "en_US" }], - ["meta", { property: "og:site", content: site }], - ["meta", { property: "og:site_name", content: title }], - ["meta", { property: "og:image", content: image }], - ["meta", { property: "og:description", content: description }], + ['meta', { property: 'og:type', content: 'website' }], + ['meta', { property: 'og:locale', content: 'en_US' }], + ['meta', { property: 'og:site', content: site }], + ['meta', { property: 'og:site_name', content: title }], + ['meta', { property: 'og:image', content: image }], + ['meta', { property: 'og:description', content: description }], ], themeConfig: { // https://vitepress.dev/reference/default-theme-config nav: [ - { text: "Home", link: "/" }, - { text: "Guide", link: "/guide" }, - { text: "Cookbook", link: "/cookbook/integrating-shadcn-ui" }, + { text: 'Home', link: '/' }, + { text: 'Guide', link: '/guide' }, + { text: 'Cookbook', link: '/cookbook/integrating-shadcn-ui' }, { - text: "Links", + text: 'Links', items: [ - { text: "Official Inertia.js docs", link: "https://inertiajs.com" }, + { text: 'Official Inertia.js docs', link: 'https://inertiajs.com' }, { - text: "Gems", + text: 'Gems', items: [ { - text: "inertia_rails", - link: "https://github.com/inertiajs/inertia-rails", + text: 'inertia_rails', + link: 'https://github.com/inertiajs/inertia-rails', }, { - text: "inertia_rails-contrib", - link: "https://github.com/skryukov/inertia_rails-contrib", + text: 'inertia_rails-contrib', + link: 'https://github.com/skryukov/inertia_rails-contrib', }, ], }, @@ -61,90 +61,93 @@ export default defineConfig({ }, ], - logo: "/logo.svg", + logo: '/logo.svg', sidebar: { - "/guide": [ + '/guide': [ { items: [ - {text: "Introduction", link: "/guide"}, - {text: "Demo app", link: "/guide/demo-application"}, - {text: "Upgrade guide", link: "/guide/upgrade-guide"}, + { text: 'Introduction', link: '/guide' }, + { text: 'Demo app', link: '/guide/demo-application' }, + { text: 'Upgrade guide', link: '/guide/upgrade-guide' }, ], }, { - text: "Installation", + text: 'Installation', items: [ - {text: "Server-side", link: "/guide/server-side-setup"}, - {text: "Client-side", link: "/guide/client-side-setup"}, - ] + { text: 'Server-side', link: '/guide/server-side-setup' }, + { text: 'Client-side', link: '/guide/client-side-setup' }, + ], }, { - text: "Core concepts", + text: 'Core concepts', items: [ - {text: "Who is it for", link: "/guide/who-is-it-for"}, - {text: "How it works", link: "/guide/how-it-works"}, - {text: "The protocol", link: "/guide/the-protocol"}, - ] + { text: 'Who is it for', link: '/guide/who-is-it-for' }, + { text: 'How it works', link: '/guide/how-it-works' }, + { text: 'The protocol', link: '/guide/the-protocol' }, + ], }, { - text: "The basics", + text: 'The basics', items: [ - {text: "Pages", link: "/guide/pages"}, - {text: "Responses", link: "/guide/responses"}, - {text: "Redirects", link: "/guide/redirects"}, - {text: "Routing", link: "/guide/routing"}, - {text: "Title & meta", link: "/guide/title-and-meta"}, - {text: "Links", link: "/guide/links"}, - {text: "Manual visits", link: "/guide/manual-visits"}, - {text: "Forms", link: "/guide/forms"}, - {text: "File uploads", link: "/guide/file-uploads"}, - {text: "Validation", link: "/guide/validation"}, - ] + { text: 'Pages', link: '/guide/pages' }, + { text: 'Responses', link: '/guide/responses' }, + { text: 'Redirects', link: '/guide/redirects' }, + { text: 'Routing', link: '/guide/routing' }, + { text: 'Title & meta', link: '/guide/title-and-meta' }, + { text: 'Links', link: '/guide/links' }, + { text: 'Manual visits', link: '/guide/manual-visits' }, + { text: 'Forms', link: '/guide/forms' }, + { text: 'File uploads', link: '/guide/file-uploads' }, + { text: 'Validation', link: '/guide/validation' }, + ], }, { - text: "Data & Props", + text: 'Data & Props', items: [ - {text: "Shared data", link: "/guide/shared-data"}, - {text: "Partial reloads", link: "/guide/partial-reloads"}, - {text: "Deferred props", link: "/guide/deferred-props"}, - {text: "Polling", link: "/guide/polling"}, - {text: "Prefetching", link: "/guide/prefetching"}, - {text: "Load when visible", link: "/guide/load-when-visible"}, - {text: "Merging props", link: "/guide/merging-props"}, - {text: "Remembering state", link: "/guide/remembering-state"}, - ] + { text: 'Shared data', link: '/guide/shared-data' }, + { text: 'Partial reloads', link: '/guide/partial-reloads' }, + { text: 'Deferred props', link: '/guide/deferred-props' }, + { text: 'Polling', link: '/guide/polling' }, + { text: 'Prefetching', link: '/guide/prefetching' }, + { text: 'Load when visible', link: '/guide/load-when-visible' }, + { text: 'Merging props', link: '/guide/merging-props' }, + { text: 'Remembering state', link: '/guide/remembering-state' }, + ], }, { - text: "Security", + text: 'Security', items: [ - {text: "Authentication", link: "/guide/authentication"}, - {text: "Authorization", link: "/guide/authorization"}, - {text: "CSRF protection", link: "/guide/csrf-protection"}, - {text: "History encryption", link: "/guide/history-encryption"}, - ] + { text: 'Authentication', link: '/guide/authentication' }, + { text: 'Authorization', link: '/guide/authorization' }, + { text: 'CSRF protection', link: '/guide/csrf-protection' }, + { text: 'History encryption', link: '/guide/history-encryption' }, + ], }, { - text: "Advanced", + text: 'Advanced', items: [ - {text: "Asset versioning", link: "/guide/asset-versioning"}, - {text: "Code splitting", link: "/guide/code-splitting"}, - {text: "Error handling", link: "/guide/error-handling"}, - {text: "Events", link: "/guide/events"}, - {text: "Progress indicators", link: "/guide/progress-indicators"}, - {text: "Scroll management", link: "/guide/scroll-management"}, - {text: "Server-side rendering", link: "/guide/server-side-rendering"}, - {text: "Testing", link: "/guide/testing"}, - ] + { text: 'Asset versioning', link: '/guide/asset-versioning' }, + { text: 'Code splitting', link: '/guide/code-splitting' }, + { text: 'Error handling', link: '/guide/error-handling' }, + { text: 'Events', link: '/guide/events' }, + { text: 'Progress indicators', link: '/guide/progress-indicators' }, + { text: 'Scroll management', link: '/guide/scroll-management' }, + { + text: 'Server-side rendering', + link: '/guide/server-side-rendering', + }, + { text: 'Testing', link: '/guide/testing' }, + ], }, ], - "/cookbook": [ + '/cookbook': [ { items: [ { - text: "Integrations", + text: 'Integrations', items: [ - { text: "shadcn/ui", link: "/cookbook/integrating-shadcn-ui" }, + { text: 'shadcn/ui', link: '/cookbook/integrating-shadcn-ui' }, ], }, ], @@ -153,24 +156,24 @@ export default defineConfig({ }, search: { - provider: "algolia", + provider: 'algolia', options: { - appId: "NFLARHZ4Q4", - apiKey: "5e79b6038b027b5bb342ea5a31d0a2e8", - indexName: "inertia-rails", + appId: 'NFLARHZ4Q4', + apiKey: '5e79b6038b027b5bb342ea5a31d0a2e8', + indexName: 'inertia-rails', }, }, editLink: { pattern: - "https://github.com/skryukov/inertia_rails-contrib/edit/main/docs/:path", - text: "Edit this page on GitHub", + 'https://github.com/skryukov/inertia_rails-contrib/edit/main/docs/:path', + text: 'Edit this page on GitHub', }, socialLinks: [ - { icon: "github", link: "https://github.com/inertiajs/inertia-rails" }, - { icon: "x", link: "https://x.com/inertiajs" }, - { icon: "discord", link: "https://discord.gg/inertiajs" }, + { icon: 'github', link: 'https://github.com/inertiajs/inertia-rails' }, + { icon: 'x', link: 'https://x.com/inertiajs' }, + { icon: 'discord', link: 'https://discord.gg/inertiajs' }, ], }, -}); +}) diff --git a/docs/.vitepress/theme/frameworksTabs.ts b/docs/.vitepress/theme/frameworksTabs.ts index 4868801..626883d 100644 --- a/docs/.vitepress/theme/frameworksTabs.ts +++ b/docs/.vitepress/theme/frameworksTabs.ts @@ -1,24 +1,24 @@ -const localStorageKey = "vitepress:tabsSharedState"; -const ls = typeof localStorage !== "undefined" ? localStorage : null; +const localStorageKey = 'vitepress:tabsSharedState' +const ls = typeof localStorage !== 'undefined' ? localStorage : null const getLocalStorageValue = (): Record => { - const rawValue = ls?.getItem(localStorageKey); + const rawValue = ls?.getItem(localStorageKey) if (rawValue) { try { - return JSON.parse(rawValue); + return JSON.parse(rawValue) } catch {} } - return {}; -}; + return {} +} const setLocalStorageValue = (v: Record) => { - if (!ls) return; - ls.setItem(localStorageKey, JSON.stringify(v)); -}; + if (!ls) return + ls.setItem(localStorageKey, JSON.stringify(v)) +} export const setupFrameworksTabs = () => { - const v = getLocalStorageValue(); + const v = getLocalStorageValue() if (!v.frameworks) { - setLocalStorageValue({ frameworks: "React" }); + setLocalStorageValue({ frameworks: 'React' }) } -}; +} diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index b21c9a1..fc1acce 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -1,22 +1,22 @@ // https://vitepress.dev/guide/custom-theme -import { h } from "vue"; -import type { Theme } from "vitepress"; -import DefaultTheme from "vitepress/theme"; -import { enhanceAppWithTabs } from "vitepress-plugin-tabs/client"; -import { setupFrameworksTabs } from "./frameworksTabs"; -import "./style.css"; +import type { Theme } from 'vitepress' +import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client' +import DefaultTheme from 'vitepress/theme' +import { h } from 'vue' +import { setupFrameworksTabs } from './frameworksTabs' +import './style.css' export default { extends: DefaultTheme, Layout: () => { return h(DefaultTheme.Layout, null, { // https://vitepress.dev/guide/extending-default-theme#layout-slots - }); + }) }, enhanceApp({ app, router, siteData }) { - enhanceAppWithTabs(app); + enhanceAppWithTabs(app) }, setup() { - setupFrameworksTabs(); + setupFrameworksTabs() }, -} satisfies Theme; +} satisfies Theme diff --git a/docs/.vitepress/theme/style.css b/docs/.vitepress/theme/style.css index 83bf35e..400f66d 100644 --- a/docs/.vitepress/theme/style.css +++ b/docs/.vitepress/theme/style.css @@ -153,11 +153,11 @@ padding: 0 !important; } -.plugin-tabs--content div[class*="language-"] { +.plugin-tabs--content div[class*='language-'] { background-color: var(--vp-code-block-bg) !important; } -.plugin-tabs--content div[class*="language-"]:first-child { +.plugin-tabs--content div[class*='language-']:first-child { border-top-left-radius: 0 !important; border-top-right-radius: 0 !important; } diff --git a/docs/.vitepress/vitepress-plugin-tabs/ruleBlockTab.ts b/docs/.vitepress/vitepress-plugin-tabs/ruleBlockTab.ts index 7968694..ea1b618 100644 --- a/docs/.vitepress/vitepress-plugin-tabs/ruleBlockTab.ts +++ b/docs/.vitepress/vitepress-plugin-tabs/ruleBlockTab.ts @@ -77,19 +77,23 @@ export const ruleBlockTab: RuleBlock = (state, startLine, endLine, silent) => { // this will prevent lazy continuations from ever going past our end marker state.lineMax = nextLine - state.src.slice(pos, max).trimStart().split('|').forEach((label) => { - const startToken = state.push('tab_open', 'div', 1) - startToken.markup = state.src.slice(mem, pos) - startToken.block = true - startToken.info = label - startToken.map = [startLine, nextLine - 1] - - state.md.block.tokenize(state, startLine + 1, nextLine) - - const endToken = state.push('tab_close', 'div', -1) - endToken.markup = state.src.slice(endStart, endPos) - endToken.block = true - }) + state.src + .slice(pos, max) + .trimStart() + .split('|') + .forEach((label) => { + const startToken = state.push('tab_open', 'div', 1) + startToken.markup = state.src.slice(mem, pos) + startToken.block = true + startToken.info = label + startToken.map = [startLine, nextLine - 1] + + state.md.block.tokenize(state, startLine + 1, nextLine) + + const endToken = state.push('tab_close', 'div', -1) + endToken.markup = state.src.slice(endStart, endPos) + endToken.block = true + }) state.parentType = oldParent state.lineMax = oldLineMax diff --git a/docs/.vitepress/vitepress-plugin-tabs/tabsMarkdownPlugin.ts b/docs/.vitepress/vitepress-plugin-tabs/tabsMarkdownPlugin.ts index 7a81079..d372397 100644 --- a/docs/.vitepress/vitepress-plugin-tabs/tabsMarkdownPlugin.ts +++ b/docs/.vitepress/vitepress-plugin-tabs/tabsMarkdownPlugin.ts @@ -1,8 +1,8 @@ import type MarkdownIt from 'markdown-it' import container from 'markdown-it-container' +import type Renderer from 'markdown-it/lib/renderer' import type Token from 'markdown-it/lib/token' import { ruleBlockTab } from './ruleBlockTab' -import type Renderer from 'markdown-it/lib/renderer' type Params = { shareStateKey: string | undefined @@ -11,7 +11,7 @@ type Params = { const parseTabsParams = (input: string): Params => { const match = input.match(/key:(\S+)/) return { - shareStateKey: match?.[1] + shareStateKey: match?.[1], } } @@ -28,7 +28,7 @@ export const tabsMarkdownPlugin = (md: MarkdownIt) => { } else { return `\n` } - } + }, }) md.block.ruler.after('container_tabs', 'tab', ruleBlockTab) diff --git a/docs/cookbook/integrating-shadcn-ui.md b/docs/cookbook/integrating-shadcn-ui.md index f80de12..79664bd 100644 --- a/docs/cookbook/integrating-shadcn-ui.md +++ b/docs/cookbook/integrating-shadcn-ui.md @@ -42,40 +42,35 @@ Installing Inertia's Rails adapter Let's configure our project to work seamlessly with `shadcn/ui`. Choose your path based on whether you're using TypeScript or JavaScript. - :::tabs key:languages == TypeScript You'll need to configure two files. First, update your `tsconfig.app.json`: -```json5 +```json lines { "compilerOptions": { // ... "baseUrl": ".", "paths": { - "@/*": [ - "./app/frontend/*" - ] + "@/*": ["./app/frontend/*"] } - }, + } // ... } ``` Then, set up your `tsconfig.json` to match `shadcn/ui`'s requirements (note the `baseUrl` and `paths` properties are different from the `tsconfig.app.json`): -```json5 +```json lines { //... "compilerOptions": { /* Required for shadcn-ui/ui */ "baseUrl": "./app/frontend", "paths": { - "@/*": [ - "./*" - ] + "@/*": ["./*"] } } } diff --git a/docs/guide/client-side-setup.md b/docs/guide/client-side-setup.md index c42425b..9516f2b 100644 --- a/docs/guide/client-side-setup.md +++ b/docs/guide/client-side-setup.md @@ -100,7 +100,7 @@ import { createInertiaApp } from '@inertiajs/svelte' import { mount } from 'svelte' createInertiaApp({ - resolve: name => { + resolve: (name) => { const pages = import.meta.glob('./Pages/**/*.svelte', { eager: true }) return pages[`./Pages/${name}.svelte`] }, @@ -109,6 +109,7 @@ createInertiaApp({ }, }) ``` + ::: The `setup` callback receives everything necessary to initialize the client-side framework, including the root Inertia `App` component. @@ -124,7 +125,7 @@ The `resolve` callback tells Inertia how to load a page component. It receives a // Vite // frontend/entrypoints/inertia.js createInertiaApp({ - resolve: name => { + resolve: (name) => { const pages = import.meta.glob('../pages/**/*.vue', { eager: true }) return pages[`../pages/${name}.vue`] }, @@ -134,7 +135,7 @@ createInertiaApp({ // Webpacker/Shakapacker // javascript/packs/inertia.js createInertiaApp({ - resolve: name => require(`../pages/${name}`), + resolve: (name) => require(`../pages/${name}`), // ... }) ``` @@ -145,8 +146,8 @@ createInertiaApp({ // Vite // frontend/entrypoints/inertia.js createInertiaApp({ - resolve: name => { - const pages = import.meta.glob('../pages/**/*.jsx', {eager: true}) + resolve: (name) => { + const pages = import.meta.glob('../pages/**/*.jsx', { eager: true }) return pages[`../pages/${name}.jsx`] }, //... @@ -155,7 +156,7 @@ createInertiaApp({ // Webpacker/Shakapacker // javascript/packs/inertia.js createInertiaApp({ - resolve: name => require(`../pages/${name}`), + resolve: (name) => require(`../pages/${name}`), //... }) ``` @@ -166,8 +167,8 @@ createInertiaApp({ // Vite // frontend/entrypoints/inertia.js createInertiaApp({ - resolve: name => { - const pages = import.meta.glob('../pages/**/*.svelte', {eager: true}) + resolve: (name) => { + const pages = import.meta.glob('../pages/**/*.svelte', { eager: true }) return pages[`../pages/${name}.svelte`] }, //... @@ -176,7 +177,7 @@ createInertiaApp({ // Webpacker/Shakapacker // javascript/packs/inertia.js createInertiaApp({ - resolve: name => require(`../pages/${name}.svelte`), + resolve: (name) => require(`../pages/${name}.svelte`), //... }) ``` diff --git a/docs/guide/code-splitting.md b/docs/guide/code-splitting.md index b49d4f2..b62f32f 100644 --- a/docs/guide/code-splitting.md +++ b/docs/guide/code-splitting.md @@ -16,7 +16,7 @@ Vite enables code splitting (or lazy-loading as they call it) by default when us ```js // frontend/entrypoints/inertia.js createInertiaApp({ - resolve: name => { + resolve: (name) => { const pages = import.meta.glob('../pages/**/*.vue', { eager: true }) // [!code --] return pages[`../pages/${name}.vue`] // [!code --] const pages = import.meta.glob('../pages/**/*.vue') // [!code ++] @@ -31,7 +31,7 @@ createInertiaApp({ ```js // frontend/entrypoints/inertia.js createInertiaApp({ - resolve: name => { + resolve: (name) => { const pages = import.meta.glob('../pages/**/*.jsx', { eager: true }) // [!code --] return pages[`../pages/${name}.jsx`] // [!code --] const pages = import.meta.glob('../pages/**/*.jsx') // [!code ++] @@ -46,7 +46,7 @@ createInertiaApp({ ```js // frontend/entrypoints/inertia.js createInertiaApp({ - resolve: name => { + resolve: (name) => { const pages = import.meta.glob('../pages/**/*.svelte', { eager: true }) // [!code --] return pages[`../pages/${name}.svelte`] // [!code --] const pages = import.meta.glob('../pages/**/*.svelte') // [!code ++] @@ -85,8 +85,8 @@ Finally, update the `resolve` callback in your app's initialization code to use ```js // javascript/packs/inertia.js createInertiaApp({ - resolve: name => require(`../pages/${name}`), // [!code ii] - resolve: name => import(`../pages/${name}`), // [!code ++] + resolve: (name) => require(`../pages/${name}`), // [!code ii] + resolve: (name) => import(`../pages/${name}`), // [!code ++] //... }) ``` @@ -96,8 +96,8 @@ createInertiaApp({ ```js // javascript/packs/inertia.js createInertiaApp({ - resolve: name => require(`../pages/${name}`), // [!code ii] - resolve: name => import(`../pages/${name}`), // [!code ++] + resolve: (name) => require(`../pages/${name}`), // [!code ii] + resolve: (name) => import(`../pages/${name}`), // [!code ++] //... }) ``` @@ -107,8 +107,8 @@ createInertiaApp({ ```js // javascript/packs/inertia.js createInertiaApp({ - resolve: name => require(`../pages/${name}.svelte`), // [!code ii] - resolve: name => import(`../pages/${name}.svelte`), // [!code ++] + resolve: (name) => require(`../pages/${name}.svelte`), // [!code ii] + resolve: (name) => import(`../pages/${name}.svelte`), // [!code ++] //... }) ``` diff --git a/docs/guide/deferred-props.md b/docs/guide/deferred-props.md index fe6c5e4..7918d79 100644 --- a/docs/guide/deferred-props.md +++ b/docs/guide/deferred-props.md @@ -191,4 +191,5 @@ export default () => ( ``` + ::: diff --git a/docs/guide/error-handling.md b/docs/guide/error-handling.md index 40c2713..04faffc 100644 --- a/docs/guide/error-handling.md +++ b/docs/guide/error-handling.md @@ -104,12 +104,13 @@ export default function ErrorPage({ status }) { -Home + ``` == React @@ -20,13 +24,15 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' -Home +export default () => Home ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + Home @@ -44,12 +50,15 @@ By default, Inertia renders links as anchor `` elements. However, you can cha == Vue ```vue + -Logout - -// Renders as... -// + ``` == React @@ -58,7 +67,9 @@ import { Link } from '@inertiajs/vue3' import { Link } from '@inertiajs/react' export default () => ( - Logout + + Logout + ) // Renders as... @@ -74,8 +85,8 @@ export default () => ( Logout -// Renders as... -// + + ``` ::: @@ -91,9 +102,13 @@ You can specify the HTTP request method for an Inertia link request using the `m == Vue ```vue + -Logout + ``` == React @@ -101,15 +116,19 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' - - Logout - +export default () => ( + + Logout + +) ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + @@ -126,14 +145,15 @@ When making `POST` or `PUT` requests, you may wish to add additional data to the == Vue ```vue + -Save + ``` == React @@ -141,17 +161,26 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' - - Save - +export default () => ( + + Save + +) ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + - + Save ``` @@ -166,9 +195,13 @@ The `headers` prop allows you to add custom headers to an Inertia link. However, == Vue ```vue + -Save + ``` == React @@ -176,15 +209,19 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' - - Save - +export default () => ( + + Save + +) ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + @@ -201,9 +238,13 @@ The `replace` prop allows you to specify the browser's history behavior. By defa == Vue ```vue + -Home + ``` == React @@ -211,15 +252,19 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' - - Home - +export default () => ( + + Home + +) ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + Home @@ -236,11 +281,15 @@ You can preserve a page component's local state using the `preserveState` prop. == Vue ```vue + - + ``` == React @@ -248,19 +297,29 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' - +export default () => ( + <> + -Search + + Search + + +) ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + - + Search ``` @@ -275,9 +334,13 @@ You can use the `preserveScroll` prop to prevent Inertia from automatically rese == Vue ```vue + -Home + ``` == React @@ -285,15 +348,19 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' - - Home - +export default () => ( + + Home + +) ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + Home @@ -312,9 +379,13 @@ The `only` prop allows you to specify that only a subset of a page's props (data == Vue ```vue + -Show active + ``` == React @@ -322,15 +393,19 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' - - Show active - +export default () => ( + + Show active + +) ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + Show active @@ -349,28 +424,29 @@ It's often desirable to set an active state for navigation links based on the cu == Vue ```vue + -// URL exact match... -Users - -// Component exact match... -Users - -// URL starts with (/users, /users/create, /users/1, etc.)... -Users - -// Component starts with (Users/Index, Users/Create, Users/Show, etc.)... -Users + ``` == React @@ -378,37 +454,67 @@ import { Link } from '@inertiajs/vue3' ```jsx import { usePage } from '@inertiajs/react' -const { url, component } = usePage() - -// URL exact match... -Users - -// Component exact match... -Users - -// URL starts with (/users, /users/create, /users/1, etc.)... -Users - -// Component starts with (Users/Index, Users/Create, Users/Show, etc.)... -Users +export default () => { + const { url, component } = usePage() + + return ( + <> + // URL exact match... + + Users + + // Component exact match... + + Users + + // URL starts with (/users, /users/create, /users/1, etc.)... + + Users + + // Component starts with (Users/Index, Users/Create, Users/Show, etc.)... + + Users + + + ) +} ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link, page } from '@inertiajs/svelte' - -// URL exact match... -Users - -// Component exact match... -Users - -// URL starts with (/users, /users/create, /users/1, etc.)... -Users + -// Component starts with (Users/Index, Users/Create, Users/Show, etc.)... -Users + ``` ::: diff --git a/docs/guide/load-when-visible.md b/docs/guide/load-when-visible.md index 493adaa..a2752e9 100644 --- a/docs/guide/load-when-visible.md +++ b/docs/guide/load-when-visible.md @@ -141,10 +141,11 @@ export default () => ( {#snippet fallback()}
Loading...
{/snippet} - + ``` + ::: ## Loading before visible @@ -197,7 +198,7 @@ export default () => (
Loading...
- + {#each permissions as permission} {/each} @@ -267,7 +268,7 @@ export default () => ( - // ... + ``` @@ -284,6 +285,7 @@ export default () => ( ``` + ::: ## Always trigger @@ -336,7 +338,7 @@ export default () => ( ``` == Svelte 5 - + ```svelte

Welcome

+

Hello {user.name}, welcome to your first Inertia app!

``` @@ -265,6 +267,7 @@ export default Home

Welcome

+

Hello {user.name}, welcome to your first Inertia app!

``` @@ -357,6 +360,7 @@ export default Home

Welcome

+

Hello {user.name}, welcome to your first Inertia app!

``` @@ -379,6 +383,7 @@ export default Home

Welcome

+

Hello {user.name}, welcome to your first Inertia app!

``` diff --git a/docs/guide/partial-reloads.md b/docs/guide/partial-reloads.md index f7a6102..871e769 100644 --- a/docs/guide/partial-reloads.md +++ b/docs/guide/partial-reloads.md @@ -88,7 +88,7 @@ Since partial reloads can only be made to the same page component the user is al :::tabs key:frameworks == Vue -```vue +```js import { router } from '@inertiajs/vue3' router.reload({ only: ['users'] }) @@ -96,7 +96,7 @@ router.reload({ only: ['users'] }) == React -```jsx +```js import { router } from '@inertiajs/react' router.reload({ only: ['users'] }) @@ -104,7 +104,7 @@ router.reload({ only: ['users'] }) == Svelte 4|Svelte 5 -```svelte +```js import { router } from '@inertiajs/svelte' router.reload({ only: ['users'] }) @@ -120,9 +120,13 @@ It's also possible to perform partial reloads with Inertia links using the `only == Vue ```vue + -Show active + ``` == React @@ -130,15 +134,19 @@ import { Link } from '@inertiajs/vue3' ```jsx import { Link } from '@inertiajs/react' - - Show active - +export default () => ( + + Show active + +) ``` == Svelte 4|Svelte 5 ```svelte -import { inertia, Link } from '@inertiajs/svelte' + Show active diff --git a/docs/guide/polling.md b/docs/guide/polling.md index 1c111f4..ec035ae 100644 --- a/docs/guide/polling.md +++ b/docs/guide/polling.md @@ -27,11 +27,11 @@ usePoll(2000) import { usePoll } from '@inertiajs/svelte' usePoll(2000) ``` + ::: If you need to pass additional request options to the poll helper, you can pass any of the `router.reload` options as the second parameter. - :::tabs key:frameworks == Vue @@ -40,11 +40,11 @@ import { usePoll } from '@inertiajs/vue3' usePoll(2000, { onStart() { - console.log('Polling request started') + console.log('Polling request started') }, onFinish() { - console.log('Polling request finished') - } + console.log('Polling request finished') + }, }) ``` @@ -55,11 +55,11 @@ import { usePoll } from '@inertiajs/react' usePoll(2000, { onStart() { - console.log('Polling request started') + console.log('Polling request started') }, onFinish() { - console.log('Polling request finished') - } + console.log('Polling request finished') + }, }) ``` @@ -70,16 +70,17 @@ import { usePoll } from '@inertiajs/svelte' usePoll(2000, { onStart() { - console.log('Polling request started') + console.log('Polling request started') }, onFinish() { - console.log('Polling request finished') - } + console.log('Polling request finished') + }, }) ``` + ::: -If you'd like more control over the polling behavior, the poll helper provides `stop` and `start` methods that allow you to manually start and stop polling. You can pass the `autoStart: false` option to the poll helper to prevent it from automatically starting polling when the component is mounted. +If you'd like more control over the polling behavior, the poll helper provides `stop` and `start` methods that allow you to manually start and stop polling. You can pass the `autoStart: false` option to the poll helper to prevent it from automatically starting polling when the component is mounted. :::tabs key:frameworks == Vue @@ -87,16 +88,19 @@ If you'd like more control over the polling behavior, the poll helper provides ` ```vue - ``` == React @@ -105,9 +109,13 @@ const { start, stop } = usePoll(2000, {}, { import { usePoll } from '@inertiajs/react' export default () => { - const { start, stop } = usePoll(2000, {}, { - autoStart: false, - }) + const { start, stop } = usePoll( + 2000, + {}, + { + autoStart: false, + }, + ) return (
@@ -121,18 +129,22 @@ export default () => { ```svelte ``` -::: +::: ## Throttling @@ -144,9 +156,13 @@ By default, the poll helper will throttle requests by 90% when the browser tab i ```js import { usePoll } from '@inertiajs/vue3' -usePoll(2000, {}, { - keepAlive: true, -}) +usePoll( + 2000, + {}, + { + keepAlive: true, + }, +) ``` == React @@ -154,9 +170,13 @@ usePoll(2000, {}, { ```js import { usePoll } from '@inertiajs/react' -usePoll(2000, {}, { - keepAlive: true, -}) +usePoll( + 2000, + {}, + { + keepAlive: true, + }, +) ``` == Svelte 4|Svelte 5 @@ -164,8 +184,13 @@ usePoll(2000, {}, { ```js import { usePoll } from '@inertiajs/svelte' -usePoll(2000, {}, { - keepAlive: true, -}) +usePoll( + 2000, + {}, + { + keepAlive: true, + }, +) ``` + ::: diff --git a/docs/guide/prefetching.md b/docs/guide/prefetching.md index 82e34db..0a227e6 100644 --- a/docs/guide/prefetching.md +++ b/docs/guide/prefetching.md @@ -11,7 +11,7 @@ To prefetch data for a page, you can use the `prefetch` method on the Inertia li ```vue