inertia_rails 3.12.1 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/lib/generators/inertia/controller/templates/controller.rb.tt +1 -1
  4. data/lib/generators/inertia/install/frameworks.yml +10 -45
  5. data/lib/generators/inertia/install/install_generator.rb +102 -14
  6. data/lib/generators/inertia/install/js_package_manager.rb +6 -6
  7. data/lib/generators/inertia/install/templates/assets/rails.svg +9 -0
  8. data/lib/generators/inertia/install/templates/controller.rb +6 -3
  9. data/lib/generators/inertia/install/templates/inertia_controller.rb +5 -0
  10. data/lib/generators/inertia/install/templates/react/InertiaExample.jsx +43 -47
  11. data/lib/generators/inertia/install/templates/react/InertiaExample.module.css +63 -41
  12. data/lib/generators/inertia/install/templates/react/InertiaExample.tsx +46 -47
  13. data/lib/generators/inertia/install/templates/react/inertia.jsx +65 -0
  14. data/lib/generators/inertia/install/templates/react/inertia.tsx +65 -0
  15. data/lib/generators/inertia/install/templates/react/tsconfig.app.json +7 -0
  16. data/lib/generators/inertia/install/templates/react/types/globals.d.ts +8 -0
  17. data/lib/generators/inertia/install/templates/react/types/index.ts +8 -0
  18. data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +103 -69
  19. data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +104 -69
  20. data/lib/generators/inertia/install/templates/svelte/inertia.js +14 -3
  21. data/lib/generators/inertia/install/templates/svelte/{inertia.ts.tt → inertia.ts} +12 -2
  22. data/lib/generators/inertia/install/templates/svelte/tsconfig.json +8 -0
  23. data/lib/generators/inertia/install/templates/svelte/types/globals.d.ts +8 -0
  24. data/lib/generators/inertia/install/templates/svelte/types/index.ts +8 -0
  25. data/lib/generators/inertia/install/templates/tailwind/application.css +3 -3
  26. data/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +107 -70
  27. data/lib/generators/inertia/install/templates/vue/InertiaExample.vue +129 -92
  28. data/lib/generators/inertia/install/templates/vue/inertia.js +30 -3
  29. data/lib/generators/inertia/install/templates/vue/inertia.ts +31 -3
  30. data/lib/generators/inertia/install/templates/vue/tsconfig.app.json +9 -1
  31. data/lib/generators/inertia/install/templates/vue/types/globals.d.ts +8 -0
  32. data/lib/generators/inertia/install/templates/vue/types/index.ts +8 -0
  33. data/lib/generators/inertia/scaffold_controller/scaffold_controller_generator.rb +4 -0
  34. data/lib/generators/inertia/scaffold_controller/templates/controller.rb.tt +7 -5
  35. data/lib/generators/inertia_templates/scaffold/templates/react/{Edit.jsx.tt → edit.jsx.tt} +5 -8
  36. data/lib/generators/inertia_templates/scaffold/templates/react/{Edit.tsx.tt → edit.tsx.tt} +7 -9
  37. data/lib/generators/inertia_templates/scaffold/templates/react/form.jsx.tt +94 -0
  38. data/lib/generators/inertia_templates/scaffold/templates/react/form.tsx.tt +109 -0
  39. data/lib/generators/inertia_templates/scaffold/templates/react/{Index.jsx.tt → index.jsx.tt} +1 -1
  40. data/lib/generators/inertia_templates/scaffold/templates/react/{Index.tsx.tt → index.tsx.tt} +1 -1
  41. data/lib/generators/inertia_templates/scaffold/templates/react/{New.jsx.tt → new.jsx.tt} +3 -5
  42. data/lib/generators/inertia_templates/scaffold/templates/react/{New.tsx.tt → new.tsx.tt} +5 -6
  43. data/lib/generators/inertia_templates/scaffold/templates/react/{Show.jsx.tt → show.jsx.tt} +1 -1
  44. data/lib/generators/inertia_templates/scaffold/templates/react/{Show.tsx.tt → show.tsx.tt} +1 -1
  45. data/lib/generators/inertia_templates/scaffold/templates/svelte/{Edit.svelte.tt → edit.svelte.tt} +9 -13
  46. data/lib/generators/inertia_templates/scaffold/templates/{svelte4/Edit.svelte.tt → svelte/edit.ts.svelte.tt} +11 -15
  47. data/lib/generators/inertia_templates/scaffold/templates/svelte/form.svelte.tt +96 -0
  48. data/lib/generators/inertia_templates/scaffold/templates/svelte/form.ts.svelte.tt +103 -0
  49. data/lib/generators/inertia_templates/scaffold/templates/svelte/{Index.svelte.tt → index.svelte.tt} +1 -1
  50. data/lib/generators/inertia_templates/scaffold/templates/svelte/{Index.ts.svelte.tt → index.ts.svelte.tt} +1 -1
  51. data/lib/generators/inertia_templates/scaffold/templates/svelte/{New.svelte.tt → new.svelte.tt} +4 -7
  52. data/lib/generators/inertia_templates/scaffold/templates/{svelte4/New.svelte.tt → svelte/new.ts.svelte.tt} +6 -9
  53. data/lib/generators/inertia_templates/scaffold/templates/svelte/{Show.svelte.tt → show.svelte.tt} +1 -1
  54. data/lib/generators/inertia_templates/scaffold/templates/svelte/{Show.ts.svelte.tt → show.ts.svelte.tt} +1 -1
  55. data/lib/generators/inertia_templates/scaffold/templates/vue/{Edit.ts.vue.tt → edit.ts.vue.tt} +11 -15
  56. data/lib/generators/inertia_templates/scaffold/templates/vue/{Edit.vue.tt → edit.vue.tt} +9 -13
  57. data/lib/generators/inertia_templates/scaffold/templates/vue/form.ts.vue.tt +102 -0
  58. data/lib/generators/inertia_templates/scaffold/templates/vue/form.vue.tt +98 -0
  59. data/lib/generators/inertia_templates/scaffold/templates/vue/{Index.ts.vue.tt → index.ts.vue.tt} +1 -1
  60. data/lib/generators/inertia_templates/scaffold/templates/vue/{Index.vue.tt → index.vue.tt} +1 -1
  61. data/lib/generators/inertia_templates/scaffold/templates/vue/{New.ts.vue.tt → new.ts.vue.tt} +6 -9
  62. data/lib/generators/inertia_templates/scaffold/templates/vue/{New.vue.tt → new.vue.tt} +4 -7
  63. data/lib/generators/inertia_templates/scaffold/templates/vue/{Show.ts.vue.tt → show.ts.vue.tt} +1 -1
  64. data/lib/generators/inertia_templates/scaffold/templates/vue/{Show.vue.tt → show.vue.tt} +1 -1
  65. data/lib/generators/inertia_tw_templates/scaffold/templates/react/{Edit.jsx.tt → edit.jsx.tt} +5 -8
  66. data/lib/generators/inertia_tw_templates/scaffold/templates/react/{Edit.tsx.tt → edit.tsx.tt} +6 -9
  67. data/lib/generators/inertia_tw_templates/scaffold/templates/react/form.jsx.tt +106 -0
  68. data/lib/generators/inertia_tw_templates/scaffold/templates/react/form.tsx.tt +122 -0
  69. data/lib/generators/inertia_tw_templates/scaffold/templates/react/{Index.jsx.tt → index.jsx.tt} +1 -1
  70. data/lib/generators/inertia_tw_templates/scaffold/templates/react/{Index.tsx.tt → index.tsx.tt} +1 -1
  71. data/lib/generators/inertia_tw_templates/scaffold/templates/react/{New.jsx.tt → new.jsx.tt} +3 -5
  72. data/lib/generators/inertia_tw_templates/scaffold/templates/react/{New.tsx.tt → new.tsx.tt} +4 -6
  73. data/lib/generators/inertia_tw_templates/scaffold/templates/react/{Show.jsx.tt → show.jsx.tt} +1 -1
  74. data/lib/generators/inertia_tw_templates/scaffold/templates/react/{Show.tsx.tt → show.tsx.tt} +1 -1
  75. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/{Edit.svelte.tt → edit.svelte.tt} +9 -13
  76. data/lib/generators/inertia_tw_templates/scaffold/templates/{svelte4/Edit.svelte.tt → svelte/edit.ts.svelte.tt} +11 -15
  77. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/form.svelte.tt +109 -0
  78. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/form.ts.svelte.tt +115 -0
  79. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/{Index.svelte.tt → index.svelte.tt} +1 -1
  80. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/{Index.ts.svelte.tt → index.ts.svelte.tt} +1 -1
  81. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/{New.svelte.tt → new.svelte.tt} +4 -7
  82. data/lib/generators/inertia_tw_templates/scaffold/templates/{svelte4/New.svelte.tt → svelte/new.ts.svelte.tt} +6 -9
  83. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/{Show.svelte.tt → show.svelte.tt} +1 -1
  84. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/{Show.ts.svelte.tt → show.ts.svelte.tt} +1 -1
  85. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{Edit.ts.vue.tt → edit.ts.vue.tt} +10 -15
  86. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{Edit.vue.tt → edit.vue.tt} +8 -13
  87. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{Form.ts.vue.tt → form.ts.vue.tt} +19 -42
  88. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{Form.vue.tt → form.vue.tt} +18 -38
  89. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{Index.ts.vue.tt → index.ts.vue.tt} +1 -1
  90. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{Index.vue.tt → index.vue.tt} +1 -1
  91. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{New.ts.vue.tt → new.ts.vue.tt} +6 -9
  92. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{New.vue.tt → new.vue.tt} +4 -7
  93. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{Show.ts.vue.tt → show.ts.vue.tt} +1 -1
  94. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{Show.vue.tt → show.vue.tt} +1 -1
  95. data/lib/inertia_rails/generators/controller_template_base.rb +1 -1
  96. data/lib/inertia_rails/generators/helper.rb +2 -3
  97. data/lib/inertia_rails/generators/scaffold_template_base.rb +3 -3
  98. data/lib/inertia_rails/version.rb +1 -1
  99. data/lib/inertia_rails.rb +1 -0
  100. metadata +88 -116
  101. data/lib/generators/inertia/install/templates/react/inertia.js +0 -45
  102. data/lib/generators/inertia/install/templates/react/inertia.ts +0 -51
  103. data/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte +0 -116
  104. data/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte +0 -116
  105. data/lib/generators/inertia/install/templates/svelte4/inertia.js +0 -43
  106. data/lib/generators/inertia/install/templates/svelte4/inertia.ts.tt +0 -44
  107. data/lib/generators/inertia/install/templates/svelte4/svelte.config.js +0 -7
  108. data/lib/generators/inertia/install/templates/svelte4/tsconfig.json +0 -21
  109. data/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json +0 -12
  110. data/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts +0 -2
  111. data/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt +0 -2
  112. data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +0 -111
  113. data/lib/generators/inertia_templates/scaffold/templates/react/Form.tsx.tt +0 -130
  114. data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.ts.svelte.tt +0 -37
  115. data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +0 -97
  116. data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.ts.svelte.tt +0 -102
  117. data/lib/generators/inertia_templates/scaffold/templates/svelte/New.ts.svelte.tt +0 -30
  118. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +0 -38
  119. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt +0 -96
  120. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +0 -106
  121. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt +0 -36
  122. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +0 -37
  123. data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.ts.svelte.tt +0 -31
  124. data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt +0 -28
  125. data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.ts.svelte.tt +0 -30
  126. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt +0 -39
  127. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +0 -40
  128. data/lib/generators/inertia_templates/scaffold/templates/svelte4/types.ts.tt +0 -19
  129. data/lib/generators/inertia_templates/scaffold/templates/vue/Form.ts.vue.tt +0 -101
  130. data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +0 -94
  131. data/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt +0 -2
  132. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +0 -122
  133. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.tsx.tt +0 -142
  134. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.ts.svelte.tt +0 -45
  135. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +0 -118
  136. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.ts.svelte.tt +0 -123
  137. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.ts.svelte.tt +0 -33
  138. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +0 -46
  139. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt +0 -120
  140. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +0 -130
  141. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.svelte.tt +0 -43
  142. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +0 -44
  143. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.ts.svelte.tt +0 -34
  144. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.svelte.tt +0 -28
  145. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.ts.svelte.tt +0 -30
  146. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.svelte.tt +0 -51
  147. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +0 -52
  148. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/types.ts.tt +0 -19
  149. /data/lib/generators/inertia/install/templates/react/{vite-env.d.ts → types/vite-env.d.ts} +0 -0
  150. /data/lib/generators/inertia/install/templates/svelte/{vite-env.d.ts → types/vite-env.d.ts} +0 -0
  151. /data/lib/generators/inertia/install/templates/vue/{vite-env.d.ts → types/vite-env.d.ts} +0 -0
  152. /data/lib/generators/inertia_templates/scaffold/templates/react/{One.jsx.tt → one.jsx.tt} +0 -0
  153. /data/lib/generators/inertia_templates/scaffold/templates/react/{One.tsx.tt → one.tsx.tt} +0 -0
  154. /data/lib/generators/inertia_templates/scaffold/templates/svelte/{One.svelte.tt → one.svelte.tt} +0 -0
  155. /data/lib/generators/inertia_templates/scaffold/templates/svelte/{One.ts.svelte.tt → one.ts.svelte.tt} +0 -0
  156. /data/lib/generators/inertia_templates/scaffold/templates/vue/{One.ts.vue.tt → one.ts.vue.tt} +0 -0
  157. /data/lib/generators/inertia_templates/scaffold/templates/vue/{One.vue.tt → one.vue.tt} +0 -0
  158. /data/lib/generators/inertia_tw_templates/scaffold/templates/react/{One.jsx.tt → one.jsx.tt} +0 -0
  159. /data/lib/generators/inertia_tw_templates/scaffold/templates/react/{One.tsx.tt → one.tsx.tt} +0 -0
  160. /data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/{One.svelte.tt → one.svelte.tt} +0 -0
  161. /data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/{One.ts.svelte.tt → one.ts.svelte.tt} +0 -0
  162. /data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{One.ts.vue.tt → one.ts.vue.tt} +0 -0
  163. /data/lib/generators/inertia_tw_templates/scaffold/templates/vue/{One.vue.tt → one.vue.tt} +0 -0
@@ -1,118 +0,0 @@
1
- <script>
2
- import { useForm } from '@inertiajs/svelte'
3
-
4
- let { <%= singular_table_name %>, submitText, onSubmit } = $props()
5
-
6
- const form = useForm({
7
- <% attributes.each do |attribute| -%>
8
- <% if attribute.password_digest? -%>
9
- password: '',
10
- password_confirmation: '',
11
- <% else -%>
12
- <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
13
- <% end -%>
14
- <% end -%>
15
- })
16
-
17
- const handleSubmit = (e) => {
18
- e.preventDefault()
19
- onSubmit({ form: $form })
20
- }
21
- </script>
22
-
23
- <form class="contents" onsubmit={handleSubmit}>
24
- <% attributes.each do |attribute| -%>
25
- <div class="my-5">
26
- <% if attribute.password_digest? -%>
27
- <label for="password">Password</label>
28
- <input
29
- type="password"
30
- name="password"
31
- id="password"
32
- bind:value={$form.password}
33
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
34
- />
35
- {#if $form.errors.password}
36
- <div class="text-red-500 px-3 py-2 font-medium">
37
- {$form.errors.password.join(', ')}
38
- </div>
39
- {/if}
40
- </div>
41
-
42
- <div class="my-5">
43
- <label for="password_confirmation">Password confirmation</label>
44
- <input
45
- type="password"
46
- name="password_confirmation"
47
- id="password_confirmation"
48
- bind:value={$form.password_confirmation}
49
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
50
- />
51
- {#if $form.errors.password_confirmation}
52
- <div class="text-red-500 px-3 py-2 font-medium">
53
- {$form.errors.password_confirmation.join(', ')}
54
- </div>
55
- {/if}
56
- <% else -%>
57
- <label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
58
- <% if input_type(attribute) == "text_area" -%>
59
- <textarea
60
- name="<%= attribute.singular_name %>"
61
- id="<%= attribute.singular_name %>"
62
- bind:value={$form.<%= attribute.column_name %>}
63
- rows="4"
64
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
65
- ></textarea>
66
- <% elsif attribute.attachment? -%>
67
- <input
68
- type="file"
69
- name="<%= attribute.singular_name %>"
70
- id="<%= attribute.singular_name %>"
71
- oninput={(e) => ($form.<%= attribute.column_name %> = e.target.files[0])}
72
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
73
- />
74
- <% elsif attribute.attachments? -%>
75
- <input
76
- type="file"
77
- multiple
78
- name="<%= attribute.singular_name %>[]"
79
- id="<%= attribute.singular_name %>"
80
- oninput={(e) => ($form.<%= attribute.column_name %> = Array.from(e.target.files))}
81
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
82
- />
83
- <% elsif input_type(attribute) == "checkbox" -%>
84
- <input
85
- type="<%= input_type(attribute) %>"
86
- name="<%= attribute.singular_name %>"
87
- id="<%= attribute.singular_name %>"
88
- bind:checked={$form.<%= attribute.column_name %>}
89
- class="block mt-2 h-5 w-5"
90
- />
91
- <% else -%>
92
- <input
93
- type="<%= input_type(attribute) %>"
94
- name="<%= attribute.singular_name %>"
95
- id="<%= attribute.singular_name %>"
96
- bind:value={$form.<%= attribute.column_name %>}
97
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
98
- />
99
- <% end -%>
100
- {#if $form.errors.<%= attribute.column_name %>}
101
- <div class="text-red-500 px-3 py-2 font-medium">
102
- {$form.errors.<%= attribute.column_name %>.join(', ')}
103
- </div>
104
- {/if}
105
- <% end -%>
106
- </div>
107
-
108
- <% end -%>
109
- <div class="inline">
110
- <button
111
- type="submit"
112
- disabled={$form.processing}
113
- class="rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer"
114
- >
115
- {submitText}
116
- </button>
117
- </div>
118
- </form>
@@ -1,123 +0,0 @@
1
- <script lang="ts">
2
- import { useForm, type InertiaFormProps } from '@inertiajs/svelte'
3
- import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
4
-
5
- let { <%= singular_table_name %>, submitText, onSubmit } = $props<{
6
- <%= singular_table_name %>: <%= inertia_model_type %>
7
- onSubmit: (props: { form: InertiaFormProps<<%= inertia_model_form_type %>> }) => void
8
- submitText: string
9
- }>()
10
-
11
- const form = useForm<<%= inertia_model_form_type %>>({
12
- <% attributes.reject { |a| a.attachment? || a.attachments? }.each do |attribute| -%>
13
- <% if attribute.password_digest? -%>
14
- password: '',
15
- password_confirmation: '',
16
- <% else -%>
17
- <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
18
- <% end -%>
19
- <% end -%>
20
- })
21
-
22
- const handleSubmit = (e: SubmitEvent) => {
23
- e.preventDefault()
24
- onSubmit({ form: $form })
25
- }
26
- </script>
27
-
28
- <form class="contents" onsubmit={handleSubmit}>
29
- <% attributes.each do |attribute| -%>
30
- <div class="my-5">
31
- <% if attribute.password_digest? -%>
32
- <label for="password">Password</label>
33
- <input
34
- type="password"
35
- name="password"
36
- id="password"
37
- bind:value={$form.password}
38
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
39
- />
40
- {#if $form.errors.password}
41
- <div class="text-red-500 px-3 py-2 font-medium">
42
- {$form.errors.password}
43
- </div>
44
- {/if}
45
- </div>
46
-
47
- <div class="my-5">
48
- <label for="password_confirmation">Password confirmation</label>
49
- <input
50
- type="password"
51
- name="password_confirmation"
52
- id="password_confirmation"
53
- bind:value={$form.password_confirmation}
54
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
55
- />
56
- {#if $form.errors.password_confirmation}
57
- <div class="text-red-500 px-3 py-2 font-medium">
58
- {$form.errors.password_confirmation}
59
- </div>
60
- {/if}
61
- <% else -%>
62
- <label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
63
- <% if input_type(attribute) == "text_area" -%>
64
- <textarea
65
- name="<%= attribute.singular_name %>"
66
- id="<%= attribute.singular_name %>"
67
- bind:value={$form.<%= attribute.column_name %>}
68
- rows="4"
69
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
70
- ></textarea>
71
- <% elsif attribute.attachment? -%>
72
- <input
73
- type="file"
74
- name="<%= attribute.singular_name %>"
75
- id="<%= attribute.singular_name %>"
76
- oninput={(e) => ($form.<%= attribute.column_name %> = ((e.target as HTMLInputElement).files || [])[0])}
77
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
78
- />
79
- <% elsif attribute.attachments? -%>
80
- <input
81
- type="file"
82
- multiple
83
- name="<%= attribute.singular_name %>[]"
84
- id="<%= attribute.singular_name %>"
85
- oninput={(e) => ($form.<%= attribute.column_name %> = Array.from((e.target as HTMLInputElement).files || []))}
86
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
87
- />
88
- <% elsif input_type(attribute) == "checkbox" -%>
89
- <input
90
- type="<%= input_type(attribute) %>"
91
- name="<%= attribute.singular_name %>"
92
- id="<%= attribute.singular_name %>"
93
- bind:checked={$form.<%= attribute.column_name %>}
94
- class="block mt-2 h-5 w-5"
95
- />
96
- <% else -%>
97
- <input
98
- type="<%= input_type(attribute) %>"
99
- name="<%= attribute.singular_name %>"
100
- id="<%= attribute.singular_name %>"
101
- bind:value={$form.<%= attribute.column_name %>}
102
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
103
- />
104
- <% end -%>
105
- {#if $form.errors.<%= attribute.column_name %>}
106
- <div class="text-red-500 px-3 py-2 font-medium">
107
- {$form.errors.<%= attribute.column_name %>}
108
- </div>
109
- {/if}
110
- <% end -%>
111
- </div>
112
-
113
- <% end -%>
114
- <div class="inline">
115
- <button
116
- type="submit"
117
- disabled={$form.processing}
118
- class="rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer"
119
- >
120
- {submitText}
121
- </button>
122
- </div>
123
- </form>
@@ -1,33 +0,0 @@
1
- <script lang="ts">
2
- import { Link, type InertiaFormProps } from '@inertiajs/svelte'
3
- import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
4
- import Form from './Form.svelte'
5
-
6
- let { <%= singular_table_name %> } = $props<{ <%= singular_table_name %>: <%= inertia_model_type %> }>()
7
-
8
- const handleSubmit = ({ form }: { form: InertiaFormProps<<%= inertia_model_form_type %>> }) => {
9
- form.transform((data) => ({ <%= singular_table_name %>: data }))
10
- form.post('<%= js_resources_path %>')
11
- }
12
- </script>
13
-
14
- <svelte:head>
15
- <title>New <%= human_name.downcase %></title>
16
- </svelte:head>
17
-
18
- <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
19
- <h1 class="font-bold text-4xl">New <%= human_name.downcase %></h1>
20
-
21
- <Form
22
- {<%= singular_table_name %>}
23
- submitText="Create <%= human_name %>"
24
- onSubmit={handleSubmit}
25
- />
26
-
27
- <Link
28
- href="<%= js_resources_path %>"
29
- class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
30
- >
31
- Back to <%= human_name.pluralize.downcase %>
32
- </Link>
33
- </div>
@@ -1,46 +0,0 @@
1
- <script lang="ts">
2
- import { Link, type InertiaForm } from '@inertiajs/svelte'
3
- import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
4
- import Form from './Form.svelte'
5
-
6
- export let <%= singular_table_name %>: <%= inertia_model_type %>
7
-
8
- const handleSubmit = (e: CustomEvent<{ form: InertiaForm<<%= inertia_model_form_type %>> }>) => {
9
- const { form } = e.detail
10
- form.transform((data) => ({ <%= singular_table_name %>: data }))
11
- <% if attributes.any?(&:attachments?) -%>
12
- form.post(`<%= js_resource_path %>`, {
13
- headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
14
- })
15
- <% else -%>
16
- form.patch(`<%= js_resource_path %>`)
17
- <% end -%>
18
- }
19
- </script>
20
-
21
- <svelte:head>
22
- <title>Editing <%= human_name.downcase %></title>
23
- </svelte:head>
24
-
25
- <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
26
- <h1 class="font-bold text-4xl">Editing <%= human_name.downcase %></h1>
27
-
28
- <Form
29
- {<%= singular_table_name %>}
30
- submitText="Update <%= human_name %>"
31
- on:submit={handleSubmit}
32
- />
33
-
34
- <Link
35
- href={`<%= js_resource_path %>`}
36
- class="mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
37
- >
38
- Show this <%= human_name.downcase %>
39
- </Link>
40
- <Link
41
- href="<%= js_resources_path %>"
42
- class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
43
- >
44
- Back to <%= human_name.pluralize.downcase %>
45
- </Link>
46
- </div>
@@ -1,120 +0,0 @@
1
- <script>
2
- import { useForm } from '@inertiajs/svelte'
3
- import { createEventDispatcher } from 'svelte'
4
-
5
- const dispatch = createEventDispatcher()
6
-
7
- export let <%= singular_table_name %>
8
- export let submitText
9
-
10
- const form = useForm({
11
- <% attributes.each do |attribute| -%>
12
- <% if attribute.password_digest? -%>
13
- password: '',
14
- password_confirmation: '',
15
- <% else -%>
16
- <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
17
- <% end -%>
18
- <% end -%>
19
- })
20
- </script>
21
-
22
- <form
23
- class="contents"
24
- on:submit|preventDefault={dispatch('submit', { form: $form })}
25
- >
26
- <% attributes.each do |attribute| -%>
27
- <div class="my-5">
28
- <% if attribute.password_digest? -%>
29
- <label for="password">Password</label>
30
- <input
31
- type="password"
32
- name="password"
33
- id="password"
34
- bind:value={$form.password}
35
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
36
- />
37
- {#if $form.errors.password}
38
- <div class="text-red-500 px-3 py-2 font-medium">
39
- {$form.errors.password.join(', ')}
40
- </div>
41
- {/if}
42
- </div>
43
-
44
- <div class="my-5">
45
- <label for="password_confirmation">Password confirmation</label>
46
- <input
47
- type="password"
48
- name="password_confirmation"
49
- id="password_confirmation"
50
- bind:value={$form.password_confirmation}
51
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
52
- />
53
- {#if $form.errors.password_confirmation}
54
- <div class="text-red-500 px-3 py-2 font-medium">
55
- {$form.errors.password_confirmation.join(', ')}
56
- </div>
57
- {/if}
58
- <% else -%>
59
- <label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
60
- <% if input_type(attribute) == "text_area" -%>
61
- <textarea
62
- name="<%= attribute.singular_name %>"
63
- id="<%= attribute.singular_name %>"
64
- bind:value={$form.<%= attribute.column_name %>}
65
- rows="4"
66
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
67
- />
68
- <% elsif attribute.attachment? -%>
69
- <input
70
- type="file"
71
- name="<%= attribute.singular_name %>"
72
- id="<%= attribute.singular_name %>"
73
- on:input={(e) => ($form.<%= attribute.column_name %> = e.target.files[0])}
74
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
75
- />
76
- <% elsif attribute.attachments? -%>
77
- <input
78
- type="file"
79
- multiple
80
- name="<%= attribute.singular_name %>[]"
81
- id="<%= attribute.singular_name %>"
82
- on:input={(e) => ($form.<%= attribute.column_name %> = Array.from(e.target.files))}
83
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
84
- />
85
- <% elsif input_type(attribute) == "checkbox" -%>
86
- <input
87
- type="<%= input_type(attribute) %>"
88
- name="<%= attribute.singular_name %>"
89
- id="<%= attribute.singular_name %>"
90
- bind:checked={$form.<%= attribute.column_name %>}
91
- class="block mt-2 h-5 w-5"
92
- />
93
- <% else -%>
94
- <input
95
- type="<%= input_type(attribute) %>"
96
- name="<%= attribute.singular_name %>"
97
- id="<%= attribute.singular_name %>"
98
- bind:value={$form.<%= attribute.column_name %>}
99
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
100
- />
101
- <% end -%>
102
- {#if $form.errors.<%= attribute.column_name %>}
103
- <div class="text-red-500 px-3 py-2 font-medium">
104
- {$form.errors.<%= attribute.column_name %>.join(', ')}
105
- </div>
106
- {/if}
107
- <% end -%>
108
- </div>
109
-
110
- <% end -%>
111
- <div class="inline">
112
- <button
113
- type="submit"
114
- disabled={$form.processing}
115
- class="rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer"
116
- >
117
- {submitText}
118
- </button>
119
- </div>
120
- </form>
@@ -1,130 +0,0 @@
1
- <script lang="ts">
2
- import { useForm, type InertiaForm } from '@inertiajs/svelte'
3
- import { createEventDispatcher } from 'svelte'
4
- import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
5
-
6
- const dispatch = createEventDispatcher<{
7
- submit: { form: InertiaForm<<%= inertia_model_form_type %>> }
8
- }>()
9
-
10
- export let <%= singular_table_name %>: <%= inertia_model_type %>
11
- export let submitText: string
12
-
13
- <% if attributes.any? { |a| a.attachment? || a.attachments? } -%>
14
- const filesFromEvent = (e: Event) => {
15
- const target = e.target as HTMLInputElement
16
- return Array.from(target.files || [])
17
- }
18
-
19
- <% end -%>
20
- const form = useForm<<%= inertia_model_form_type %>>({
21
- <% attributes.reject { |a| a.attachment? || a.attachments? }.each do |attribute| -%>
22
- <% if attribute.password_digest? -%>
23
- password: '',
24
- password_confirmation: '',
25
- <% else -%>
26
- <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %>,
27
- <% end -%>
28
- <% end -%>
29
- })
30
- </script>
31
-
32
- <form
33
- class="contents"
34
- on:submit|preventDefault={() => dispatch('submit', { form: $form })}
35
- >
36
- <% attributes.each do |attribute| -%>
37
- <div class="my-5">
38
- <% if attribute.password_digest? -%>
39
- <label for="password">Password</label>
40
- <input
41
- type="password"
42
- name="password"
43
- id="password"
44
- bind:value={$form.password}
45
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
46
- />
47
- {#if $form.errors.password}
48
- <div class="text-red-500 px-3 py-2 font-medium">
49
- {$form.errors.password}
50
- </div>
51
- {/if}
52
- </div>
53
-
54
- <div class="my-5">
55
- <label for="password_confirmation">Password confirmation</label>
56
- <input
57
- type="password"
58
- name="password_confirmation"
59
- id="password_confirmation"
60
- bind:value={$form.password_confirmation}
61
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
62
- />
63
- {#if $form.errors.password_confirmation}
64
- <div class="text-red-500 px-3 py-2 font-medium">
65
- {$form.errors.password_confirmation}
66
- </div>
67
- {/if}
68
- <% else -%>
69
- <label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
70
- <% if input_type(attribute) == "text_area" -%>
71
- <textarea
72
- name="<%= attribute.singular_name %>"
73
- id="<%= attribute.singular_name %>"
74
- bind:value={$form.<%= attribute.column_name %>}
75
- rows="4"
76
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
77
- />
78
- <% elsif attribute.attachment? -%>
79
- <input
80
- type="file"
81
- name="<%= attribute.singular_name %>"
82
- id="<%= attribute.singular_name %>"
83
- on:input={(e) => ($form.<%= attribute.column_name %> = filesFromEvent(e)[0])}
84
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
85
- />
86
- <% elsif attribute.attachments? -%>
87
- <input
88
- type="file"
89
- multiple
90
- name="<%= attribute.singular_name %>[]"
91
- id="<%= attribute.singular_name %>"
92
- on:input={(e) => ($form.<%= attribute.column_name %> = filesFromEvent(e))}
93
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
94
- />
95
- <% elsif input_type(attribute) == "checkbox" -%>
96
- <input
97
- type="<%= input_type(attribute) %>"
98
- name="<%= attribute.singular_name %>"
99
- id="<%= attribute.singular_name %>"
100
- bind:checked={$form.<%= attribute.column_name %>}
101
- class="block mt-2 h-5 w-5"
102
- />
103
- <% else -%>
104
- <input
105
- type="<%= input_type(attribute) %>"
106
- name="<%= attribute.singular_name %>"
107
- id="<%= attribute.singular_name %>"
108
- bind:value={$form.<%= attribute.column_name %>}
109
- class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
110
- />
111
- <% end -%>
112
- {#if $form.errors.<%= attribute.column_name %>}
113
- <div class="text-red-500 px-3 py-2 font-medium">
114
- {$form.errors.<%= attribute.column_name %>}
115
- </div>
116
- {/if}
117
- <% end -%>
118
- </div>
119
-
120
- <% end -%>
121
- <div class="inline">
122
- <button
123
- type="submit"
124
- disabled={$form.processing}
125
- class="rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer"
126
- >
127
- {submitText}
128
- </button>
129
- </div>
130
- </form>
@@ -1,43 +0,0 @@
1
- <script>
2
- import { Link } from '@inertiajs/svelte'
3
- import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
4
-
5
- export let <%= plural_table_name %>
6
- export let flash
7
- </script>
8
-
9
- <svelte:head>
10
- <title><%= human_name.pluralize %></title>
11
- </svelte:head>
12
-
13
- <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
14
- {#if flash.notice}
15
- <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
16
- {flash.notice}
17
- </p>
18
- {/if}
19
-
20
- <div class="flex justify-between items-center">
21
- <h1 class="font-bold text-4xl"><%= human_name.pluralize %></h1>
22
- <Link
23
- href="<%= js_new_resource_path %>"
24
- class="rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium"
25
- >
26
- New <%= human_name.downcase %>
27
- </Link>
28
- </div>
29
-
30
- <div class="min-w-full">
31
- {#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)}
32
- <<%= inertia_component_name %> {<%= singular_table_name %>} />
33
- <p>
34
- <Link
35
- href={`<%= js_resource_path %>`}
36
- class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
37
- >
38
- Show this <%= human_name.downcase %>
39
- </Link>
40
- </p>
41
- {/each}
42
- </div>
43
- </div>
@@ -1,44 +0,0 @@
1
- <script lang="ts">
2
- import { Link } from '@inertiajs/svelte'
3
- import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
4
- import type { <%= inertia_model_type %> } from './types'
5
-
6
- export let <%= plural_table_name %>: <%= inertia_model_type %>[]
7
- export let flash: { notice?: string }
8
- </script>
9
-
10
- <svelte:head>
11
- <title><%= human_name.pluralize %></title>
12
- </svelte:head>
13
-
14
- <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
15
- {#if flash.notice}
16
- <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
17
- {flash.notice}
18
- </p>
19
- {/if}
20
-
21
- <div class="flex justify-between items-center">
22
- <h1 class="font-bold text-4xl"><%= human_name.pluralize %></h1>
23
- <Link
24
- href="<%= js_new_resource_path %>"
25
- class="rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium"
26
- >
27
- New <%= human_name.downcase %>
28
- </Link>
29
- </div>
30
-
31
- <div class="min-w-full">
32
- {#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)}
33
- <<%= inertia_component_name %> {<%= singular_table_name %>} />
34
- <p>
35
- <Link
36
- href={`<%= js_resource_path %>`}
37
- class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
38
- >
39
- Show this <%= human_name.downcase %>
40
- </Link>
41
- </p>
42
- {/each}
43
- </div>
44
- </div>