diff --git a/.github/workflows/generators.yml b/.github/workflows/generators.yml index d0147da3..4ab4eabb 100644 --- a/.github/workflows/generators.yml +++ b/.github/workflows/generators.yml @@ -20,10 +20,10 @@ jobs: strategy: fail-fast: false matrix: - framework: [react, vue, svelte, svelte4] + framework: [react, vue, svelte] typescript: [true, false] tailwind: [true, false] - ruby: ['3.3'] + ruby: ['3.4'] node: ['22'] inertia_version: ['latest'] diff --git a/bin/generate_scaffold_example b/bin/generate_scaffold_example index 65b9fb02..a0ddf53f 100755 --- a/bin/generate_scaffold_example +++ b/bin/generate_scaffold_example @@ -14,8 +14,8 @@ options = { OptionParser.new do |opts| opts.banner = "Usage: #{$PROGRAM_NAME} [options]" - opts.on('--framework FRAMEWORK', %w[react vue svelte svelte4], - 'Choose framework (react/vue/svelte4/svelte)') do |f| + opts.on('--framework FRAMEWORK', %w[react vue svelte], + 'Choose framework (react/vue/svelte)') do |f| options[:framework] = f end diff --git a/docs/guide/server-side-setup.md b/docs/guide/server-side-setup.md index 510c5f0e..1fa54fc8 100644 --- a/docs/guide/server-side-setup.md +++ b/docs/guide/server-side-setup.md @@ -27,7 +27,7 @@ This command will: - Check for Vite Rails and install it if not present - Ask if you want to use TypeScript -- Ask you to choose your preferred frontend framework (React, Vue, Svelte 4, or Svelte 5) +- Ask you to choose your preferred frontend framework (React, Vue, Svelte) - Ask if you want to install Tailwind CSS - Install necessary dependencies - Set up the application to work with Inertia @@ -49,7 +49,7 @@ Vite Rails gem successfully installed Vite Rails successfully installed Would you like to use TypeScript? (y/n) y Adding TypeScript support -What framework do you want to use with Inertia? [react, vue, svelte4, svelte] (react) +What framework do you want to use with Inertia? [react, vue, svelte] (react) run npm add @types/react @types/react-dom typescript --silent from "." Would you like to install Tailwind CSS? (y/n) y Installing Tailwind CSS diff --git a/lib/generators/inertia/install/frameworks.yml b/lib/generators/inertia/install/frameworks.yml index 24c26cbc..1fe2aeef 100644 --- a/lib/generators/inertia/install/frameworks.yml +++ b/lib/generators/inertia/install/frameworks.yml @@ -12,15 +12,17 @@ react: vite_plugin_import: "import react from '@vitejs/plugin-react'" vite_plugin_call: "react()" copy_files_ts: - "InertiaExample.tsx": "%{js_destination_path}/pages/InertiaExample.tsx" + "InertiaExample.tsx": "%{js_destination_path}/pages/inertia_example/index.tsx" "tsconfig.json": "tsconfig.json" "tsconfig.app.json": "tsconfig.app.json" "tsconfig.node.json": "tsconfig.node.json" - "vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts" + "types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts" + "types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts" + "types/index.ts": "%{js_destination_path}/types/index.ts" copy_files_js: - "InertiaExample.jsx": "%{js_destination_path}/pages/InertiaExample.jsx" + "InertiaExample.jsx": "%{js_destination_path}/pages/inertia_example/index.jsx" copy_files: - "InertiaExample.module.css": "%{js_destination_path}/pages/InertiaExample.module.css" + "InertiaExample.module.css": "%{js_destination_path}/pages/inertia_example/index.module.css" "../assets/react.svg": "%{js_destination_path}/assets/react.svg" "../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg" "../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg" @@ -41,39 +43,15 @@ vue: "../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg" "../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg" copy_files_ts: - "InertiaExample.ts.vue": "%{js_destination_path}/pages/InertiaExample.vue" + "InertiaExample.ts.vue": "%{js_destination_path}/pages/inertia_example/index.vue" "tsconfig.json": "tsconfig.json" "tsconfig.app.json": "tsconfig.app.json" "tsconfig.node.json": "tsconfig.node.json" - "vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts" + "types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts" + "types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts" + "types/index.ts": "%{js_destination_path}/types/index.ts" copy_files_js: - "InertiaExample.vue": "%{js_destination_path}/pages/InertiaExample.vue" - -svelte4: - inertia_package: "@inertiajs/svelte" - packages: - - "svelte@4" - - "@sveltejs/vite-plugin-svelte@3" - - "vite@5" - packages_ts: - - "@tsconfig/svelte@4" - - "svelte-check" - - "typescript" - - "tslib" - vite_plugin_import: "import { svelte } from '@sveltejs/vite-plugin-svelte'" - vite_plugin_call: "svelte()" - copy_files_ts: - "InertiaExample.ts.svelte": "%{js_destination_path}/pages/InertiaExample.svelte" - "tsconfig.json": "tsconfig.json" - "tsconfig.node.json": "tsconfig.node.json" - "vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts" - copy_files_js: - "InertiaExample.svelte": "%{js_destination_path}/pages/InertiaExample.svelte" - copy_files: - "svelte.config.js": "svelte.config.js" - "../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg" - "../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg" - "../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg" + "InertiaExample.vue": "%{js_destination_path}/pages/inertia_example/index.vue" svelte: inertia_package: "@inertiajs/svelte" @@ -89,12 +67,14 @@ svelte: vite_plugin_import: "import { svelte } from '@sveltejs/vite-plugin-svelte'" vite_plugin_call: "svelte()" copy_files_ts: - "InertiaExample.ts.svelte": "%{js_destination_path}/pages/InertiaExample.svelte" + "InertiaExample.ts.svelte": "%{js_destination_path}/pages/inertia_example/index.svelte" "tsconfig.json": "tsconfig.json" "tsconfig.node.json": "tsconfig.node.json" - "vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts" + "types/vite-env.d.ts": "%{js_destination_path}/types/vite-env.d.ts" + "types/globals.d.ts": "%{js_destination_path}/types/globals.d.ts" + "types/index.ts": "%{js_destination_path}/types/index.ts" copy_files_js: - "InertiaExample.svelte": "%{js_destination_path}/pages/InertiaExample.svelte" + "InertiaExample.svelte": "%{js_destination_path}/pages/inertia_example/index.svelte" copy_files: "svelte.config.js": "svelte.config.js" "../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg" diff --git a/lib/generators/inertia/install/install_generator.rb b/lib/generators/inertia/install/install_generator.rb index 6ef0d507..e54b7c2d 100644 --- a/lib/generators/inertia/install/install_generator.rb +++ b/lib/generators/inertia/install/install_generator.rb @@ -65,9 +65,21 @@ def install install_example_page if options[:example_page] say 'Copying bin/dev' - copy_file "#{__dir__}/templates/dev", 'bin/dev' + copy_file 'dev', 'bin/dev' chmod 'bin/dev', 0o755, verbose: verbose? + if install_vite? + say 'Adding redirect to localhost' + routing_code = <<~RUBY + \n # Redirect to localhost from 127.0.0.1 to use same IP address with Vite server + constraints(host: "127.0.0.1") do + get "(*path)", to: redirect { |params, req| "\#{req.protocol}localhost:\#{req.port}/\#{params[:path]}" } + end + RUBY + + route routing_code + end + say "Inertia's Rails adapter successfully installed", :green end @@ -87,12 +99,15 @@ def install_inertia end say "Copying #{inertia_entrypoint} entrypoint" - template "#{framework}/#{inertia_entrypoint}", js_file_path("entrypoints/#{inertia_entrypoint}") + copy_file "#{framework}/#{inertia_entrypoint}", js_file_path("entrypoints/#{inertia_entrypoint}") + + say 'Copying InertiaController' + copy_file 'inertia_controller.rb', file_path('app/controllers/inertia_controller.rb') if application_layout.exist? say "Adding #{inertia_entrypoint} script tag to the application layout" headers = <<-ERB - <%= #{vite_tag} "inertia" %> + <%= #{vite_tag} %> <%= inertia_ssr_head %> ERB insert_into_file application_layout.to_s, headers, after: "<%= vite_client_tag %>\n" @@ -103,14 +118,14 @@ def install_inertia before: '<%= vite_client_tag %>' end - gsub_file application_layout.to_s, //, '<title inertia>' unless svelte? + gsub_file application_layout.to_s, /<title>/, '<title data-inertia>' unless svelte? else say_error 'Could not find the application layout file. Please add the following tags manually:', :red say_error '- <title>...' - say_error '+ ...' + say_error '+ ...' say_error '+ <%= inertia_ssr_head %>' say_error '+ <%= vite_react_refresh_tag %>' if framework == 'react' - say_error "+ <%= #{vite_tag} \"inertia\" %>" + say_error "+ <%= #{vite_tag} %>" end end @@ -192,6 +207,8 @@ def install_vite say_error 'Failed to install Vite Rails', :red exit(false) end + + add_package_manager_to_bin_setup end end end @@ -258,11 +275,13 @@ def typescript? end def inertia_entrypoint - "inertia.#{typescript? ? 'ts' : 'js'}" + "inertia.#{typescript? ? 'ts' : 'js'}#{'x' if react?}" end def vite_tag - typescript? ? 'vite_typescript_tag' : 'vite_javascript_tag' + tag = typescript? ? 'vite_typescript_tag' : 'vite_javascript_tag' + filename = "\"#{react? ? inertia_entrypoint : 'inertia'}\"" + "#{tag} #{filename}" end def inertia_resolved_version @@ -280,6 +299,10 @@ def svelte? framework.start_with? 'svelte' end + def react? + framework.start_with? 'react' + end + def inertia_package "#{FRAMEWORKS[framework]['inertia_package']}@#{options[:inertia_version]}" end @@ -288,6 +311,26 @@ def framework @framework ||= options[:framework] || ask('What framework do you want to use with Inertia?', :green, limited_to: FRAMEWORKS.keys, default: 'react') end + + def add_package_manager_to_bin_setup + setup_file = file_path('bin/setup') + return unless File.exist?(setup_file) + + content = File.read(setup_file) + pm_name = package_manager.name + + # Check if package manager install already exists + return if content.include?("#{pm_name} install") + + if content.match?(/system\('bundle check'\) \|\| system!\('bundle install'\)/) + say 'Adding package manager install to bin/setup' + cmd = "system! '#{pm_name} install'" + insert_into_file setup_file, " #{cmd}\n", + after: /system\('bundle check'\) \|\| system!\('bundle install'\)\n/ + else + say_status "Couldn't add `#{cmd}` script to bin/setup, add it manually", :red + end + end end end end diff --git a/lib/generators/inertia/install/js_package_manager.rb b/lib/generators/inertia/install/js_package_manager.rb index 24b0f1a6..4687b5d9 100644 --- a/lib/generators/inertia/install/js_package_manager.rb +++ b/lib/generators/inertia/install/js_package_manager.rb @@ -12,22 +12,22 @@ def initialize(generator) end def present? - package_manager.present? + name.present? end def add_dependencies(*dependencies) options = @generator.options[:verbose] ? '' : ' --silent' @generator.in_root do - @generator.run "#{package_manager} add #{dependencies.join(' ')}#{options}" + @generator.run "#{name} add #{dependencies.join(' ')}#{options}" end end - private - - def package_manager - @package_manager ||= @generator.options[:package_manager] || detect_package_manager + def name + @name ||= @generator.options[:package_manager] || detect_package_manager end + private + def detect_package_manager return nil unless file?('package.json') diff --git a/lib/generators/inertia/install/templates/controller.rb b/lib/generators/inertia/install/templates/controller.rb index 0c95ffe9..369a3716 100644 --- a/lib/generators/inertia/install/templates/controller.rb +++ b/lib/generators/inertia/install/templates/controller.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -class InertiaExampleController < ApplicationController +class InertiaExampleController < InertiaController def index - render inertia: 'InertiaExample', props: { - name: params.fetch(:name, 'World'), - } + render inertia: { name: params.fetch(:name, 'World') } end end diff --git a/lib/generators/inertia/install/templates/inertia_controller.rb b/lib/generators/inertia/install/templates/inertia_controller.rb new file mode 100644 index 00000000..62ce6470 --- /dev/null +++ b/lib/generators/inertia/install/templates/inertia_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class InertiaController < ApplicationController + inertia_share flash: -> { flash.to_hash } +end diff --git a/lib/generators/inertia/install/templates/react/InertiaExample.jsx b/lib/generators/inertia/install/templates/react/InertiaExample.jsx index 77d2402c..aabe43f3 100644 --- a/lib/generators/inertia/install/templates/react/InertiaExample.jsx +++ b/lib/generators/inertia/install/templates/react/InertiaExample.jsx @@ -5,7 +5,7 @@ import inertiaSvg from '/assets/inertia.svg' import reactSvg from '/assets/react.svg' import viteRubySvg from '/assets/vite_ruby.svg' -import cs from './InertiaExample.module.css' +import cs from './index.module.css' export default function InertiaExample({ name }) { const [count, setCount] = useState(0) @@ -47,7 +47,7 @@ export default function InertiaExample({ name }) { count is {count}

- Edit app/frontend/pages/InertiaExample.jsx and save to + Edit app/frontend/pages/inertia_example/index.jsx and save to test HMR

diff --git a/lib/generators/inertia/install/templates/react/InertiaExample.tsx b/lib/generators/inertia/install/templates/react/InertiaExample.tsx index b5061b03..3c657e99 100644 --- a/lib/generators/inertia/install/templates/react/InertiaExample.tsx +++ b/lib/generators/inertia/install/templates/react/InertiaExample.tsx @@ -5,7 +5,7 @@ import inertiaSvg from '/assets/inertia.svg' import reactSvg from '/assets/react.svg' import viteRubySvg from '/assets/vite_ruby.svg' -import cs from './InertiaExample.module.css' +import cs from './index.module.css' export default function InertiaExample({ name }: { name: string }) { const [count, setCount] = useState(0) @@ -47,7 +47,7 @@ export default function InertiaExample({ name }: { name: string }) { count is {count}

- Edit app/frontend/pages/InertiaExample.jsx and save to + Edit app/frontend/pages/inertia_example/index.tsx and save to test HMR

diff --git a/lib/generators/inertia/install/templates/react/inertia.js b/lib/generators/inertia/install/templates/react/inertia.js deleted file mode 100644 index ca6396af..00000000 --- a/lib/generators/inertia/install/templates/react/inertia.js +++ /dev/null @@ -1,45 +0,0 @@ -import { createInertiaApp } from '@inertiajs/react' -import { createElement } from 'react' -import { createRoot } from 'react-dom/client' - -createInertiaApp({ - // Set default page title - // see https://inertia-rails.dev/guide/title-and-meta - // - // title: title => title ? `${title} - App` : 'App', - - // Disable progress bar - // - // see https://inertia-rails.dev/guide/progress-indicators - // progress: false, - - resolve: (name) => { - const pages = import.meta.glob('../pages/**/*.jsx', { - eager: true, - }) - const page = pages[`../pages/${name}.jsx`] - if (!page) { - console.error(`Missing Inertia page component: '${name}.jsx'`) - } - - // To use a default layout, import the Layout component - // and use the following lines. - // see https://inertia-rails.dev/guide/pages#default-layouts - // - // page.default.layout ||= (page) => createElement(Layout, null, page) - - return page - }, - - setup({ el, App, props }) { - if (el) { - createRoot(el).render(createElement(App, props)) - } else { - console.error( - 'Missing root element.\n\n' + - 'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' + - 'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.', - ) - } - }, -}) diff --git a/lib/generators/inertia/install/templates/react/inertia.jsx b/lib/generators/inertia/install/templates/react/inertia.jsx new file mode 100644 index 00000000..75c6b17b --- /dev/null +++ b/lib/generators/inertia/install/templates/react/inertia.jsx @@ -0,0 +1,65 @@ +import { createInertiaApp } from '@inertiajs/react' +import { StrictMode } from 'react' +import { createRoot } from 'react-dom/client' + +createInertiaApp({ + // Set default page title + // see https://inertia-rails.dev/guide/title-and-meta + // + // title: title => title ? `${title} - App` : 'App', + + // Disable progress bar + // + // see https://inertia-rails.dev/guide/progress-indicators + // progress: false, + + resolve: (name) => { + const pages = import.meta.glob('../pages/**/*.jsx', { + eager: true, + }) + const page = pages[`../pages/${name}.jsx`] + if (!page) { + console.error(`Missing Inertia page component: '${name}.jsx'`) + } + + // To use a default layout, import the Layout component + // and use the following lines. + // see https://inertia-rails.dev/guide/pages#default-layouts + // + // page.default.layout ||= (page) => ({page}) + + return page + }, + + setup({ el, App, props }) { + createRoot(el).render( + + + + ) + }, + + defaults: { + form: { + forceIndicesArrayFormatInFormData: true, + }, + future: { + useDataInertiaHeadAttribute: true, + useDialogForErrorModal: true, + preserveEqualProps: true, + }, + }, +}).catch((error) => { + // This ensures this entrypoint is only loaded on Inertia pages + // by checking for the presence of the root element (#app by default). + // Feel free to remove this `catch` if you don't need it. + if (document.getElementById("app")) { + throw error + } else { + console.error( + "Missing root element.\n\n" + + "If you see this error, it probably means you loaded Inertia.js on non-Inertia pages.\n" + + 'Consider moving <%= vite_javascript_tag "inertia.jsx" %> to the Inertia-specific layout instead.', + ) + } +}) diff --git a/lib/generators/inertia/install/templates/react/inertia.ts b/lib/generators/inertia/install/templates/react/inertia.ts deleted file mode 100644 index 9998974d..00000000 --- a/lib/generators/inertia/install/templates/react/inertia.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { createInertiaApp } from '@inertiajs/react' -import { createElement, ReactNode } from 'react' -import { createRoot } from 'react-dom/client' - -// Temporary type definition, until @inertiajs/react provides one -type ResolvedComponent = { - default: ReactNode - layout?: (page: ReactNode) => ReactNode -} - -createInertiaApp({ - // Set default page title - // see https://inertia-rails.dev/guide/title-and-meta - // - // title: title => title ? `${title} - App` : 'App', - - // Disable progress bar - // - // see https://inertia-rails.dev/guide/progress-indicators - // progress: false, - - resolve: (name) => { - const pages = import.meta.glob('../pages/**/*.tsx', { - eager: true, - }) - const page = pages[`../pages/${name}.tsx`] - if (!page) { - console.error(`Missing Inertia page component: '${name}.tsx'`) - } - - // To use a default layout, import the Layout component - // and use the following line. - // see https://inertia-rails.dev/guide/pages#default-layouts - // - // page.default.layout ||= (page) => createElement(Layout, null, page) - - return page - }, - - setup({ el, App, props }) { - if (el) { - createRoot(el).render(createElement(App, props)) - } else { - console.error( - 'Missing root element.\n\n' + - 'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' + - 'Consider moving <%%= vite_typescript_tag "inertia" %> to the Inertia-specific layout instead.', - ) - } - }, -}) diff --git a/lib/generators/inertia/install/templates/react/inertia.tsx b/lib/generators/inertia/install/templates/react/inertia.tsx new file mode 100644 index 00000000..db2238f9 --- /dev/null +++ b/lib/generators/inertia/install/templates/react/inertia.tsx @@ -0,0 +1,65 @@ +import { createInertiaApp, type ResolvedComponent } from '@inertiajs/react' +import { StrictMode } from 'react' +import { createRoot } from 'react-dom/client' + +void createInertiaApp({ + // Set default page title + // see https://inertia-rails.dev/guide/title-and-meta + // + // title: title => title ? `${title} - App` : 'App', + + // Disable progress bar + // + // see https://inertia-rails.dev/guide/progress-indicators + // progress: false, + + resolve: (name) => { + const pages = import.meta.glob('../pages/**/*.tsx', { + eager: true, + }) + const page = pages[`../pages/${name}.tsx`] + if (!page) { + console.error(`Missing Inertia page component: '${name}.tsx'`) + } + + // To use a default layout, import the Layout component + // and use the following line. + // see https://inertia-rails.dev/guide/pages#default-layouts + // + // page.default.layout ||= (page) => ({page}) + + return page + }, + + setup({ el, App, props }) { + createRoot(el).render( + + + + ) + }, + + defaults: { + form: { + forceIndicesArrayFormatInFormData: true, + }, + future: { + useDataInertiaHeadAttribute: true, + useDialogForErrorModal: true, + preserveEqualProps: true, + }, + }, +}).catch((error) => { + // This ensures this entrypoint is only loaded on Inertia pages + // by checking for the presence of the root element (#app by default). + // Feel free to remove this `catch` if you don't need it. + if (document.getElementById("app")) { + throw error + } else { + console.error( + "Missing root element.\n\n" + + "If you see this error, it probably means you loaded Inertia.js on non-Inertia pages.\n" + + 'Consider moving <%= vite_typescript_tag "inertia.tsx" %> to the Inertia-specific layout instead.', + ) + } +}) diff --git a/lib/generators/inertia/install/templates/react/tsconfig.app.json b/lib/generators/inertia/install/templates/react/tsconfig.app.json index ff1c5b10..4a22ca01 100644 --- a/lib/generators/inertia/install/templates/react/tsconfig.app.json +++ b/lib/generators/inertia/install/templates/react/tsconfig.app.json @@ -22,6 +22,13 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, + + /* Aliases */ + "baseUrl": ".", + "paths": { + "@/*": ["<%= js_destination_path %>/*"], + "~/*": ["<%= js_destination_path %>/*"] + } }, "include": ["<%= js_destination_path %>"] } diff --git a/lib/generators/inertia/install/templates/react/types/globals.d.ts b/lib/generators/inertia/install/templates/react/types/globals.d.ts new file mode 100644 index 00000000..d163a308 --- /dev/null +++ b/lib/generators/inertia/install/templates/react/types/globals.d.ts @@ -0,0 +1,8 @@ +import type { SharedProps } from '@/types' + +declare module '@inertiajs/core' { + export interface InertiaConfig { + sharedPageProps: SharedProps + errorValueType: string[] + } +} diff --git a/lib/generators/inertia/install/templates/react/types/index.ts b/lib/generators/inertia/install/templates/react/types/index.ts new file mode 100644 index 00000000..774d62d5 --- /dev/null +++ b/lib/generators/inertia/install/templates/react/types/index.ts @@ -0,0 +1,8 @@ +export type Flash = { + notice?: string + alert?: string +} + +export type SharedProps = { + flash: Flash +} diff --git a/lib/generators/inertia/install/templates/react/vite-env.d.ts b/lib/generators/inertia/install/templates/react/types/vite-env.d.ts similarity index 100% rename from lib/generators/inertia/install/templates/react/vite-env.d.ts rename to lib/generators/inertia/install/templates/react/types/vite-env.d.ts diff --git a/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte b/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte index cdaf667b..8c69883f 100644 --- a/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +++ b/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte @@ -34,7 +34,7 @@ count is {count}

- Edit app/frontend/pages/InertiaExample.svelte and save to test + Edit app/frontend/pages/inertia_example/index.svelte and save to test HMR

diff --git a/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte b/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte index a4e31248..9ec790c8 100644 --- a/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +++ b/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte @@ -34,7 +34,7 @@ count is {count}

- Edit app/frontend/pages/InertiaExample.svelte and save to test + Edit app/frontend/pages/inertia_example/index.svelte and save to test HMR

diff --git a/lib/generators/inertia/install/templates/svelte/inertia.js b/lib/generators/inertia/install/templates/svelte/inertia.js index 15e490f1..4412cc22 100644 --- a/lib/generators/inertia/install/templates/svelte/inertia.js +++ b/lib/generators/inertia/install/templates/svelte/inertia.js @@ -30,10 +30,21 @@ createInertiaApp({ mount(App, { target: el, props }) } else { console.error( - 'Missing root element.\n\n' + - 'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' + - 'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.', + "Missing root element.\n\n" + + "If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n" + + 'Consider moving <%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.', ) } }, + + defaults: { + form: { + forceIndicesArrayFormatInFormData: true, + }, + future: { + useDataInertiaHeadAttribute: true, + useDialogForErrorModal: true, + preserveEqualProps: true, + }, + }, }) diff --git a/lib/generators/inertia/install/templates/svelte/inertia.ts.tt b/lib/generators/inertia/install/templates/svelte/inertia.ts similarity index 76% rename from lib/generators/inertia/install/templates/svelte/inertia.ts.tt rename to lib/generators/inertia/install/templates/svelte/inertia.ts index 0953756e..9d4b818b 100644 --- a/lib/generators/inertia/install/templates/svelte/inertia.ts.tt +++ b/lib/generators/inertia/install/templates/svelte/inertia.ts @@ -27,14 +27,24 @@ createInertiaApp({ setup({ el, App, props }) { if (el) { -<%= " // @ts-expect-error 1.3.0 contains types mismatch\n" if inertia_resolved_version.release == Gem::Version.new('1.3.0') -%> mount(App, { target: el, props }) } else { console.error( 'Missing root element.\n\n' + 'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' + - 'Consider moving <%%= vite_typescript_tag "inertia" %> to the Inertia-specific layout instead.', + 'Consider moving <%= vite_typescript_tag "inertia" %> to the Inertia-specific layout instead.', ) } }, + + defaults: { + form: { + forceIndicesArrayFormatInFormData: true, + }, + future: { + useDataInertiaHeadAttribute: true, + useDialogForErrorModal: true, + preserveEqualProps: true, + }, + }, }) diff --git a/lib/generators/inertia/install/templates/svelte/tsconfig.json b/lib/generators/inertia/install/templates/svelte/tsconfig.json index acbc1cdf..c0f6c401 100644 --- a/lib/generators/inertia/install/templates/svelte/tsconfig.json +++ b/lib/generators/inertia/install/templates/svelte/tsconfig.json @@ -15,7 +15,15 @@ "checkJs": true, "isolatedModules": true, "moduleDetection": "force", + + /* Aliases */ + "baseUrl": ".", + "paths": { + "@/*": ["<%= js_destination_path %>/*"], + "~/*": ["<%= js_destination_path %>/*"] + } }, + "include": ["<%= js_destination_path %>/**/*.ts", "<%= js_destination_path %>/**/*.js", "<%= js_destination_path %>/**/*.svelte"], "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/lib/generators/inertia/install/templates/svelte/types/globals.d.ts b/lib/generators/inertia/install/templates/svelte/types/globals.d.ts new file mode 100644 index 00000000..d163a308 --- /dev/null +++ b/lib/generators/inertia/install/templates/svelte/types/globals.d.ts @@ -0,0 +1,8 @@ +import type { SharedProps } from '@/types' + +declare module '@inertiajs/core' { + export interface InertiaConfig { + sharedPageProps: SharedProps + errorValueType: string[] + } +} diff --git a/lib/generators/inertia/install/templates/svelte/types/index.ts b/lib/generators/inertia/install/templates/svelte/types/index.ts new file mode 100644 index 00000000..774d62d5 --- /dev/null +++ b/lib/generators/inertia/install/templates/svelte/types/index.ts @@ -0,0 +1,8 @@ +export type Flash = { + notice?: string + alert?: string +} + +export type SharedProps = { + flash: Flash +} diff --git a/lib/generators/inertia/install/templates/svelte/vite-env.d.ts b/lib/generators/inertia/install/templates/svelte/types/vite-env.d.ts similarity index 100% rename from lib/generators/inertia/install/templates/svelte/vite-env.d.ts rename to lib/generators/inertia/install/templates/svelte/types/vite-env.d.ts diff --git a/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte b/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte deleted file mode 100644 index b3589c42..00000000 --- a/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte +++ /dev/null @@ -1,116 +0,0 @@ - - - - Inertia + Vite Ruby + Svelte Example - - -
-

Hello {name}!

- -
- - - - - - - - - -
- -

Inertia + Vite Ruby + Svelte

- -
- -

- Edit app/frontend/pages/InertiaExample.svelte and save to test - HMR -

-
-

- Click on the Inertia, Vite Ruby, and Svelte logos to learn more -

-
- - diff --git a/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte b/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte deleted file mode 100644 index 0ae6e21a..00000000 --- a/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte +++ /dev/null @@ -1,116 +0,0 @@ - - - - Inertia + Vite Ruby + Svelte Example - - -
-

Hello {name}!

- -
- - - - - - - - - -
- -

Inertia + Vite Ruby + Svelte

- -
- -

- Edit app/frontend/pages/InertiaExample.svelte and save to test - HMR -

-
-

- Click on the Inertia, Vite Ruby, and Svelte logos to learn more -

-
- - diff --git a/lib/generators/inertia/install/templates/svelte4/inertia.js b/lib/generators/inertia/install/templates/svelte4/inertia.js deleted file mode 100644 index e0b39358..00000000 --- a/lib/generators/inertia/install/templates/svelte4/inertia.js +++ /dev/null @@ -1,43 +0,0 @@ -import { createInertiaApp } from '@inertiajs/svelte' - -createInertiaApp({ - // Set default page title - // see https://inertia-rails.dev/guide/title-and-meta - // - // title: title => title ? `${title} - App` : 'App', - - // Disable progress bar - // - // see https://inertia-rails.dev/guide/progress-indicators - // progress: false, - - resolve: (name) => { - const pages = import.meta.glob('../pages/**/*.svelte', { - eager: true, - }) - const page = pages[`../pages/${name}.svelte`] - if (!page) { - console.error(`Missing Inertia page component: '${name}.svelte'`) - } - - // To use a default layout, import the Layout component - // and use the following lines. - // see https://inertia-rails.dev/guide/pages#default-layouts - // - // return { default: page.default, layout: page.layout || Layout } - - return page - }, - - setup({ el, App, props }) { - if (el) { - new App({ target: el, props }) - } else { - console.error( - 'Missing root element.\n\n' + - 'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' + - 'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.', - ) - } - }, -}) diff --git a/lib/generators/inertia/install/templates/svelte4/inertia.ts.tt b/lib/generators/inertia/install/templates/svelte4/inertia.ts.tt deleted file mode 100644 index 6655d224..00000000 --- a/lib/generators/inertia/install/templates/svelte4/inertia.ts.tt +++ /dev/null @@ -1,44 +0,0 @@ -import { createInertiaApp, type ResolvedComponent } from '@inertiajs/svelte' - -createInertiaApp({ - // Set default page title - // see https://inertia-rails.dev/guide/title-and-meta - // - // title: title => title ? `${title} - App` : 'App', - - // Disable progress bar - // - // see https://inertia-rails.dev/guide/progress-indicators - // progress: false, - - resolve: (name) => { - const pages = import.meta.glob('../pages/**/*.svelte', { - eager: true, - }) - const page = pages[`../pages/${name}.svelte`] - if (!page) { - console.error(`Missing Inertia page component: '${name}.svelte'`) - } - - // To use a default layout, import the Layout component - // and use the following line. - // see https://inertia-rails.dev/guide/pages#default-layouts - // - // return { default: page.default, layout: page.layout || Layout } - - return page - }, - - setup({ el, App, props }) { - if (el) { - <%= "// @ts-expect-error 1.3.0 beta contains types mismatch\n" if inertia_resolved_version.release == Gem::Version.new('1.3.0') -%> - new App({ target: el, props }) - } else { - console.error( - 'Missing root element.\n\n' + - 'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' + - 'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.', - ) - } - }, -}) diff --git a/lib/generators/inertia/install/templates/svelte4/svelte.config.js b/lib/generators/inertia/install/templates/svelte4/svelte.config.js deleted file mode 100644 index b0683fd2..00000000 --- a/lib/generators/inertia/install/templates/svelte4/svelte.config.js +++ /dev/null @@ -1,7 +0,0 @@ -import { vitePreprocess } from '@sveltejs/vite-plugin-svelte' - -export default { - // Consult https://svelte.dev/docs#compile-time-svelte-preprocess - // for more information about preprocessors - preprocess: vitePreprocess(), -} diff --git a/lib/generators/inertia/install/templates/svelte4/tsconfig.json b/lib/generators/inertia/install/templates/svelte4/tsconfig.json deleted file mode 100644 index acbc1cdf..00000000 --- a/lib/generators/inertia/install/templates/svelte4/tsconfig.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extends": "@tsconfig/svelte/tsconfig.json", - "compilerOptions": { - "target": "ESNext", - "useDefineForClassFields": true, - "module": "ESNext", - "resolveJsonModule": true, - /** - * Typecheck JS in `.svelte` and `.js` files by default. - * Disable checkJs if you'd like to use dynamic types in JS. - * Note that setting allowJs false does not prevent the use - * of JS in `.svelte` files. - */ - "allowJs": true, - "checkJs": true, - "isolatedModules": true, - "moduleDetection": "force", - }, - "include": ["<%= js_destination_path %>/**/*.ts", "<%= js_destination_path %>/**/*.js", "<%= js_destination_path %>/**/*.svelte"], - "references": [{ "path": "./tsconfig.node.json" }] -} diff --git a/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json b/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json deleted file mode 100644 index 3126cd74..00000000 --- a/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "composite": true, - "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", - "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "bundler", - "strict": true, - "noEmit": true, - }, - "include": ["vite.config.ts"] -} diff --git a/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts b/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts deleted file mode 100644 index 4078e747..00000000 --- a/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/// -/// diff --git a/lib/generators/inertia/install/templates/tailwind/application.css b/lib/generators/inertia/install/templates/tailwind/application.css index 7577becc..d93dbc6f 100644 --- a/lib/generators/inertia/install/templates/tailwind/application.css +++ b/lib/generators/inertia/install/templates/tailwind/application.css @@ -1,4 +1,4 @@ -@import "tailwindcss"; +@import 'tailwindcss'; -@plugin "@tailwindcss/typography"; -@plugin "@tailwindcss/forms"; +@plugin '@tailwindcss/typography'; +@plugin '@tailwindcss/forms'; diff --git a/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue b/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue index 7392fc5a..fc637a43 100644 --- a/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +++ b/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue @@ -23,7 +23,7 @@ count is {{ count }}

- Edit app/frontend/pages/InertiaExample.vue and save to test + Edit app/frontend/pages/inertia_example/index.vue and save to test HMR

diff --git a/lib/generators/inertia/install/templates/vue/InertiaExample.vue b/lib/generators/inertia/install/templates/vue/InertiaExample.vue index dd14bdea..49b4170d 100644 --- a/lib/generators/inertia/install/templates/vue/InertiaExample.vue +++ b/lib/generators/inertia/install/templates/vue/InertiaExample.vue @@ -23,7 +23,7 @@ count is {{ count }}

- Edit app/frontend/pages/InertiaExample.vue and save to test + Edit app/frontend/pages/inertia_example/index.vue and save to test HMR

diff --git a/lib/generators/inertia/install/templates/vue/inertia.js b/lib/generators/inertia/install/templates/vue/inertia.js index 624015a7..93f9a475 100644 --- a/lib/generators/inertia/install/templates/vue/inertia.js +++ b/lib/generators/inertia/install/templates/vue/inertia.js @@ -16,15 +16,18 @@ createInertiaApp({ const pages = import.meta.glob('../pages/**/*.vue', { eager: true, }) - return pages[`../pages/${name}.vue`] + const page = pages[`../pages/${name}.vue`] + if (!page) { + console.error(`Missing Inertia page component: '${name}.vue'`) + } // To use a default layout, import the Layout component // and use the following lines. // see https://inertia-rails.dev/guide/pages#default-layouts // - // const page = pages[`../pages/${name}.vue`] // page.default.layout = page.default.layout || Layout - // return page + + return page }, setup({ el, App, props, plugin }) { @@ -32,4 +35,28 @@ createInertiaApp({ .use(plugin) .mount(el) }, + + defaults: { + future: { + useDataInertiaHeadAttribute: true, + useDialogForErrorModal: true, + preserveEqualProps: true, + }, + visitOptions: () => { + return { queryStringArrayFormat: "brackets" } + }, + }, +}).catch((error) => { + // This ensures this entrypoint is only loaded on Inertia pages + // by checking for the presence of the root element (#app by default). + // Feel free to remove this `catch` if you don't need it. + if (document.getElementById("app")) { + throw error + } else { + console.error( + "Missing root element.\n\n" + + "If you see this error, it probably means you loaded Inertia.js on non-Inertia pages.\n" + + 'Consider moving <%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.', + ) + } }) diff --git a/lib/generators/inertia/install/templates/vue/inertia.ts b/lib/generators/inertia/install/templates/vue/inertia.ts index 7b043f6a..684af134 100644 --- a/lib/generators/inertia/install/templates/vue/inertia.ts +++ b/lib/generators/inertia/install/templates/vue/inertia.ts @@ -16,15 +16,18 @@ createInertiaApp({ const pages = import.meta.glob('../pages/**/*.vue', { eager: true, }) - return pages[`../pages/${name}.vue`] + const page = pages[`../pages/${name}.vue`] + if (!page) { + console.error(`Missing Inertia page component: '${name}.vue'`) + } // To use a default layout, import the Layout component // and use the following lines. // see https://inertia-rails.dev/guide/pages#default-layouts // - // const page = pages[`../pages/${name}.vue`] // page.default.layout = page.default.layout || Layout - // return page + + return page }, setup({ el, App, props, plugin }) { @@ -32,4 +35,29 @@ createInertiaApp({ .use(plugin) .mount(el) }, + + defaults: { + future: { + useDataInertiaHeadAttribute: true, + useDialogForErrorModal: true, + preserveEqualProps: true, + }, + visitOptions: () => { + return { queryStringArrayFormat: "brackets" } + }, + }, +}).catch((error) => { + // This ensures this entrypoint is only loaded on Inertia pages + // by checking for the presence of the root element (#app by default). + // Feel free to remove this `catch` if you don't need it. + if (document.getElementById("app")) { + throw error + } else { + console.error( + "Missing root element.\n\n" + + "If you see this error, it probably means you loaded Inertia.js on non-Inertia pages.\n" + + 'Consider moving <%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.', + ) + } }) + diff --git a/lib/generators/inertia/install/templates/vue/tsconfig.app.json b/lib/generators/inertia/install/templates/vue/tsconfig.app.json index dc7d6ca1..666c65e4 100644 --- a/lib/generators/inertia/install/templates/vue/tsconfig.app.json +++ b/lib/generators/inertia/install/templates/vue/tsconfig.app.json @@ -18,7 +18,14 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + + /* Aliases */ + "baseUrl": ".", + "paths": { + "@/*": ["<%= js_destination_path %>/*"], + "~/*": ["<%= js_destination_path %>/*"] + } }, "include": ["<%= js_destination_path %>/**/*.ts", "<%= js_destination_path %>/**/*.tsx", "<%= js_destination_path %>/**/*.vue"] } diff --git a/lib/generators/inertia/install/templates/vue/types/globals.d.ts b/lib/generators/inertia/install/templates/vue/types/globals.d.ts new file mode 100644 index 00000000..d163a308 --- /dev/null +++ b/lib/generators/inertia/install/templates/vue/types/globals.d.ts @@ -0,0 +1,8 @@ +import type { SharedProps } from '@/types' + +declare module '@inertiajs/core' { + export interface InertiaConfig { + sharedPageProps: SharedProps + errorValueType: string[] + } +} diff --git a/lib/generators/inertia/install/templates/vue/types/index.ts b/lib/generators/inertia/install/templates/vue/types/index.ts new file mode 100644 index 00000000..774d62d5 --- /dev/null +++ b/lib/generators/inertia/install/templates/vue/types/index.ts @@ -0,0 +1,8 @@ +export type Flash = { + notice?: string + alert?: string +} + +export type SharedProps = { + flash: Flash +} diff --git a/lib/generators/inertia/install/templates/vue/vite-env.d.ts b/lib/generators/inertia/install/templates/vue/types/vite-env.d.ts similarity index 100% rename from lib/generators/inertia/install/templates/vue/vite-env.d.ts rename to lib/generators/inertia/install/templates/vue/types/vite-env.d.ts diff --git a/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt b/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt deleted file mode 100644 index cd54d13d..00000000 --- a/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt +++ /dev/null @@ -1,2 +0,0 @@ -

<%= class_name %>#<%= @action %>

-

Find me in <%= @path %>

diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt deleted file mode 100644 index 994d246c..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt +++ /dev/null @@ -1,37 +0,0 @@ - - - - Editing <%= human_name.downcase %> - - -

Editing <%= human_name.downcase %>

- -
} - submitText="Update <%= human_name %>" - on:submit={handleSubmit} -/> - -
- -
- `}>Show this <%= human_name.downcase %> | - Back to <%= human_name.pluralize.downcase %> -
diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt deleted file mode 100644 index fe533a22..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +++ /dev/null @@ -1,38 +0,0 @@ - - - - Editing <%= human_name.downcase %> - - -

Editing <%= human_name.downcase %>

- -} - submitText="Update <%= human_name %>" - on:submit={handleSubmit} -/> - -
- -
- `}>Show this <%= human_name.downcase %> | - Back to <%= human_name.pluralize.downcase %> -
diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt deleted file mode 100644 index d02915e6..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt +++ /dev/null @@ -1,96 +0,0 @@ - - - -<% attributes.each do |attribute| -%> -<% if attribute.password_digest? -%> -
- - - {#if $form.errors.password} -
{$form.errors.password.join(', ')}
- {/if} -
- -
- - - {#if $form.errors.password_confirmation} -
{$form.errors.password_confirmation.join(', ')}
- {/if} -
-<% else -%> -
- -<% if input_type(attribute) == "text_area" -%> - -<% elsif attribute.attachment? -%> - ($form.<%= attribute.column_name %> = e.target.files[0])} - /> -<% elsif attribute.attachments? -%> - ($form.<%= attribute.column_name %> = Array.from(e.target.files))} - /> -<% else -%> - ={$form.<%= attribute.column_name %>} - /> -<% end -%> - {#if $form.errors.<%= attribute.column_name %>} -
{$form.errors.<%= attribute.column_name %>.join(', ')}
- {/if} -
-<% end -%> -<% end -%> -
- -
-
- - diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.ts.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.ts.svelte.tt deleted file mode 100644 index 925299f6..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +++ /dev/null @@ -1,106 +0,0 @@ - - -
dispatch('submit', { form: $form })}> -<% attributes.each do |attribute| -%> -<% if attribute.password_digest? -%> -
- - - {#if $form.errors.password} -
{$form.errors.password}
- {/if} -
- -
- - - {#if $form.errors.password_confirmation} -
{$form.errors.password_confirmation}
- {/if} -
-<% else -%> -
- -<% if input_type(attribute) == "text_area" -%> - -<% elsif attribute.attachment? -%> - ($form.<%= attribute.column_name %> = filesFromEvent(e)[0])} - /> -<% elsif attribute.attachments? -%> - ($form.<%= attribute.column_name %> = filesFromEvent(e))} - /> -<% else -%> - ={$form.<%= attribute.column_name %>} - /> -<% end -%> - {#if $form.errors.<%= attribute.column_name %>} -
{$form.errors.<%= attribute.column_name %>}
- {/if} -
-<% end -%> -<% end -%> -
- -
-
- - diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt deleted file mode 100644 index 7164c7b7..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt +++ /dev/null @@ -1,36 +0,0 @@ - - - - <%= human_name.pluralize %> - - -{#if flash.notice} -

{flash.notice}

-{/if} - -

<%= human_name.pluralize %>

- -
- {#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)} -
- <<%= inertia_component_name %> {<%= singular_table_name %>} /> -

- `}>Show this <%= human_name.downcase %> -

-
- {/each} -
- -New <%= human_name.downcase %> - - diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.ts.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.ts.svelte.tt deleted file mode 100644 index 9b7590b5..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +++ /dev/null @@ -1,37 +0,0 @@ - - - - <%= human_name.pluralize %> - - -{#if flash.notice} -

{flash.notice}

-{/if} - -

<%= human_name.pluralize %>

- -
- {#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)} -
- <<%= inertia_component_name %> {<%= singular_table_name %>} /> -

- `}>Show this <%= human_name.downcase %> -

-
- {/each} -
- -New <%= human_name.downcase %> - - diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt deleted file mode 100644 index 75ebd463..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt +++ /dev/null @@ -1,30 +0,0 @@ - - - - New <%= human_name.downcase %> - - -

New <%= human_name.downcase %>

- -
} - submitText="Create <%= human_name %>" - on:submit={handleSubmit} -/> - -
- -
- Back to <%= human_name.pluralize.downcase %> -
diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/New.ts.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/New.ts.svelte.tt deleted file mode 100644 index ff46c982..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/New.ts.svelte.tt +++ /dev/null @@ -1,31 +0,0 @@ - - - - New <%= human_name.downcase %> - - -

New <%= human_name.downcase %>

- -} - submitText="Create <%= human_name %>" - on:submit={handleSubmit} -/> - -
- -
- Back to <%= human_name.pluralize.downcase %> -
diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt deleted file mode 100644 index 01b918a8..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt +++ /dev/null @@ -1,28 +0,0 @@ - - -
-<% attributes.reject(&:password_digest?).each do |attribute| -%> -

- <%= attribute.human_name %>: -<% if attribute.attachment? -%> - {#if <%= singular_table_name %>.<%= attribute.column_name %>} - .<%= attribute.column_name %>.url}> - {<%= singular_table_name %>.<%= attribute.column_name %>.filename} - - {/if} -

-<% elsif attribute.attachments? -%> -

- {#each <%= singular_table_name %>.<%= attribute.column_name %> as { url, filename }} - - {/each} -<% else -%> - {<%= singular_table_name %>.<%= attribute.column_name %>} -

-<% end -%> -<% end -%> -
diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/One.ts.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/One.ts.svelte.tt deleted file mode 100644 index 1698c0c3..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/One.ts.svelte.tt +++ /dev/null @@ -1,30 +0,0 @@ - - -
-<% attributes.reject(&:password_digest?).each do |attribute| -%> -

- <%= attribute.human_name %>: -<% if attribute.attachment? -%> - {#if <%= singular_table_name %>.<%= attribute.column_name %>} - .<%= attribute.column_name %>.url}> - {<%= singular_table_name %>.<%= attribute.column_name %>.filename} - - {/if} -

-<% elsif attribute.attachments? -%> -

- {#each <%= singular_table_name %>.<%= attribute.column_name %> as { url, filename }} - - {/each} -<% else -%> - {<%= singular_table_name %>.<%= attribute.column_name %>} -

-<% end -%> -<% end -%> -
diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt deleted file mode 100644 index fc57c990..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt +++ /dev/null @@ -1,39 +0,0 @@ - - - - <%= human_name %> #{<%= singular_table_name %>.id} - - -{#if flash.notice} -

{flash.notice}

-{/if} - -

<%= human_name %> #{<%= singular_table_name %>.id}

- -<<%= inertia_component_name %> {<%= singular_table_name %>} /> - -
- `}>Edit this <%= human_name.downcase %> | - Back to <%= human_name.pluralize.downcase %> - -
- - -
- - diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.ts.svelte.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.ts.svelte.tt deleted file mode 100644 index 80acd126..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +++ /dev/null @@ -1,40 +0,0 @@ - - - - <%= human_name %> #{<%= singular_table_name %>.id} - - -{#if flash.notice} -

{flash.notice}

-{/if} - -

<%= human_name %> #{<%= singular_table_name %>.id}

- -<<%= inertia_component_name %> {<%= singular_table_name %>} /> - -
- `}>Edit this <%= human_name.downcase %> | - Back to <%= human_name.pluralize.downcase %> - -
- - -
- - diff --git a/lib/generators/inertia_templates/scaffold/templates/svelte4/types.ts.tt b/lib/generators/inertia_templates/scaffold/templates/svelte4/types.ts.tt deleted file mode 100644 index c5c5e6c1..00000000 --- a/lib/generators/inertia_templates/scaffold/templates/svelte4/types.ts.tt +++ /dev/null @@ -1,19 +0,0 @@ -export interface <%= inertia_model_type %> { - id: number -<% attributes.reject(&:password_digest?).each do |attribute| -%> - <%= attribute.column_name %>: <%= ts_type(attribute) %> -<% end -%> -} - -export type <%= inertia_model_form_type %> = Omit<<%= inertia_model_type %>, <%= omit_input_attributes.map { |a| "'#{a}'" }.join(' | ') %>><% if custom_form_attributes.any? -%> & { -<% custom_form_attributes.map do |attribute| -%> -<% if attribute.password_digest? -%> - password: string - password_confirmation: string -<% elsif attribute.attachment? -%> - <%= attribute.column_name %>?: File -<% elsif attribute.attachments? -%> - <%= attribute.column_name %>?: File[] -<% end -%> -<% end -%> -}<% end %> diff --git a/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt b/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt deleted file mode 100644 index 764fff82..00000000 --- a/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt +++ /dev/null @@ -1,2 +0,0 @@ -

<%= class_name %>#<%= @action %>

-

Find me in <%= @path %>

diff --git a/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt b/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt deleted file mode 100644 index 28cf9344..00000000 --- a/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt +++ /dev/null @@ -1,45 +0,0 @@ - - - - Editing <%= human_name.downcase %> - - -
-

Editing <%= human_name.downcase %>

- - } - submitText="Update <%= human_name %>" - on:submit={handleSubmit} - /> - - `} - class="mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" - > - Show this <%= human_name.downcase %> - - - Back to <%= human_name.pluralize.downcase %> - -
diff --git a/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt b/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt deleted file mode 100644 index b5596d58..00000000 --- a/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +++ /dev/null @@ -1,46 +0,0 @@ - - - - Editing <%= human_name.downcase %> - - -
-

Editing <%= human_name.downcase %>

- - } - submitText="Update <%= human_name %>" - on:submit={handleSubmit} - /> - - `} - class="mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" - > - Show this <%= human_name.downcase %> - - - Back to <%= human_name.pluralize.downcase %> - -
diff --git a/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt b/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt deleted file mode 100644 index 3eed8b68..00000000 --- a/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt +++ /dev/null @@ -1,120 +0,0 @@ - - - -<% attributes.each do |attribute| -%> -
-<% if attribute.password_digest? -%> - - - {#if $form.errors.password} -
- {$form.errors.password.join(', ')} -
- {/if} -
- -
- - - {#if $form.errors.password_confirmation} -
- {$form.errors.password_confirmation.join(', ')} -
- {/if} -<% else -%> - -<% if input_type(attribute) == "text_area" -%> -