svelte-on-rails 1.0.14 β†’ 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bff57a06d326d5d82c6723869221aa21a47cb5d26e13c2d12100962610240b94
4
- data.tar.gz: 589902ba14fd77b3c094a92ce2396a0edb0d5bfb8e81f23bf2250953f9d89da2
3
+ metadata.gz: a0e1e1cb1a95e07c184fb9b943315765340d46690f2c6a66f0041aaa233fbc19
4
+ data.tar.gz: 0b93fc9a113b43b5b997e81f912535015415d66e1e6dd480129a5f28091d227b
5
5
  SHA512:
6
- metadata.gz: 35ee591f318848ca0918280f4c633f36896f530a443f97ff6e02444877e6b9b677aeb0a139503a8296f3f47fbb528dc5b60cb277721237d68c5100e1b048267d
7
- data.tar.gz: c119240c35a8a0c74d9606a7cc651f37bb8c107fa9e96d18d8b20ce2b68018fa630d6f3749bd0ecb594834fc5cdf742fc4e1d2c1bfc0095e18d4074b38c9b105
6
+ metadata.gz: 4801f3526444fbc17446bfb06270eae0cf8962be0c1c07c51d3a4b166c0ef2376b3fa73532b3629f18d99e296df9b34b55b34287a9bea6e77dcf194b01ea5adc
7
+ data.tar.gz: 5641533b5e6625231c1a5803e5d2cf75c1e0b1f3749d44e0cb43176b60b0cf03437ade435fb50013b997e5d8b5252ebb42b4946084e416123c1dc5c2d6af7ccb
data/README.md CHANGED
@@ -24,7 +24,7 @@ On every app there are parts where you want it to shine. This is where Svelte co
24
24
  - Super fast
25
25
  - **Compared to Stimulus**
26
26
  - No more writing double logic of the initial HTML state
27
- - Stimulus is great for rails views with some javascript, but, complex parts: Svelte. Nothing else.
27
+ - Stimulus is great for rails views with some javascript, but, complex parts: You will love svelte.
28
28
  - **Compared to React**
29
29
  - No more shadow dom and all those packages that are supposed to improve performance (e.g. useCallback...)
30
30
  - Slimmer packages
@@ -39,9 +39,9 @@ but: Where needed, we want full power.
39
39
 
40
40
  # Features
41
41
 
42
- - 🀝 Fully integrated with `assets:precompile`
43
- - πŸš€ Cero-config deployment
44
42
  - ✍️ Sophisticated error messages
43
+ - πŸš€ Cero-config deployment
44
+ - 🀝 Fully integrated with `assets:precompile`
45
45
  - 😍 Contributor friendly
46
46
 
47
47
  # Known Issues
@@ -163,14 +163,24 @@ and run the minimal installer (you are free to add any options from above)
163
163
  rails g svelte_on_rails:install
164
164
  ```
165
165
 
166
- Restart the server, add a example component like `app/frontend/javascript/HelloWorld.svelte`
167
- and the helper to a view, like
166
+ Restart the server, add a hello world component `app/frontend/javascript/HelloWorld.svelte` like
167
+
168
+ ```sveltehtml
169
+ <script>
170
+ export let title
171
+ </script>
172
+
173
+ <h1>Svelte {title}</h1>
174
+ ```
175
+
176
+ Add it to the view
168
177
 
169
178
  ```erb
170
- <%= svelte_component('HelloWorld') %>
179
+ <%= svelte_component('HelloWorld', title: 'Hello World') %>
171
180
  ```
172
181
 
173
- And you should see your component rendered on the browser! πŸ‘ πŸ€—
182
+
183
+ And you should see "Svelte Hello World" on the browser! πŸ‘ πŸ€—
174
184
 
175
185
  **Explanation**
176
186
 
@@ -259,6 +269,11 @@ loaded on very first load to the frontend, then the most work is done
259
269
  in frontend and the server is relieved, except on initial request.
260
270
  You will see no unpleasant Β«blinkΒ» on the page.
261
271
 
272
+ **Tip: Performance optimisation for dropdowns**
273
+
274
+ For example, if you have Svelte components inside dropdowns, you can pass `ssr: false` to the view helper
275
+ because you will never see a "blink" there. This will reduce the load on the server.
276
+
262
277
  ## More rake tasks
263
278
 
264
279
  This tasks are more for testing/playground purposes
@@ -61,7 +61,10 @@ module SvelteOnRails
61
61
  File.write('package.json', JSON.pretty_generate(pkg_js))
62
62
 
63
63
  if @local_npm_package_url
64
- npm_i.link_local_package(NPM_PACKAGE_NAME, @local_npm_package_url)
64
+ npm_i.link_local_package(NPM_PACKAGE_NAME, @local_npm_package_url)
65
+
66
+ # npm does not resolve peer dependencies on local package url
67
+ npm_i.install_or_update_package('@hotwired/stimulus')
65
68
  else
66
69
  npm_i.install_or_update_package(NPM_PACKAGE_NAME)
67
70
  end
@@ -69,7 +72,7 @@ module SvelteOnRails
69
72
  npm_i.install_or_update_package('@types/node')
70
73
 
71
74
  js_i = SvelteOnRails::Installer::Javascript
72
- init_stat = '../initializers/svelte.js'
75
+ init_stat = '@csedl/svelte-on-rails'
73
76
  js_i.append_import_statement(application_js_path, init_stat, "import '#{init_stat}';")
74
77
  end
75
78
 
@@ -37,6 +37,7 @@ module SvelteOnRails
37
37
 
38
38
  def self.link_local_package(package_name, local_package_url)
39
39
  Dir.chdir(local_package_url) do
40
+ `npm unlink`
40
41
  `npm link`
41
42
  end
42
43
  Dir.chdir(Rails.root) do
@@ -68,7 +68,7 @@ module SvelteOnRails
68
68
  stdout, stderr, status = Open3.capture3(cmd)
69
69
 
70
70
  warnings = stderr.to_s.split("\n")
71
- errors_matcher = Regexp.new('(Could not resolve)')
71
+ errors_matcher = Regexp.new('(Could not resolve|failed to resolve)')
72
72
  error_lines = warnings.select { |e| e.match(errors_matcher) }
73
73
  have_error = error_lines.present? || status.to_s.match(/exit 1/)
74
74
 
@@ -122,6 +122,14 @@ module SvelteOnRails
122
122
 
123
123
  end
124
124
 
125
+ def self.puts_error(text)
126
+ red_background = "\033[97;41m"
127
+ clear_colors = "\033[0m"
128
+ text.split("\n").each do |line|
129
+ puts "#{red_background} #{clear_colors} #{line}"
130
+ end
131
+ end
132
+
125
133
  end
126
134
  end
127
135
  end
@@ -33,7 +33,8 @@ module SvelteOnRails
33
33
 
34
34
  unless status.to_s.match(/^pid [0-9]+ exit 0$/)
35
35
  cmp = "#{@component_files[:svelte_filename]} could not be rendered Server-side\n\n"
36
- raise "#{cmp}Error output from render.js (stderr) =>\n+++\n" + stderr + "+++\n\nRender Svelte Server-side =>\n#{cmd}\n\n"
36
+ msg = "#{cmp}Error output from render.js (stderr) =>\n+++\n" + stderr + "+++\n\nRender Svelte Server-side =>\n#{cmd}\n\n"
37
+ utils.puts_error(msg)
37
38
  end
38
39
 
39
40
  begin
@@ -46,10 +46,11 @@ module SvelteOnRails
46
46
  # set up html
47
47
 
48
48
  options[:class] = options[:class].to_s + ' svelte-component'
49
- options[:class] += ' please-hydrate-me-svelte-on-rails' if hydrate
49
+ #options[:class] += ' please-hydrate-me-svelte-on-rails' if hydrate
50
50
  options[:data] ||= {}
51
51
  options[:data][:props] = props.to_json
52
- options[:data][:svelte_component] = filename
52
+ options[:data][:svelte_component] = "/#{conf.components_folder + filename}"
53
+ options[:data][:controller] = 'svelte-on-rails'
53
54
 
54
55
  if ssr
55
56
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.14
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
@@ -49,7 +49,6 @@ files:
49
49
  - lib/svelte_on_rails/renderer/utils.js
50
50
  - lib/svelte_on_rails/view_helpers.rb
51
51
  - lib/tasks/svelte_on_rails_tasks.rake
52
- - templates/config_base/app/frontend/initializers/svelte.js
53
52
  - templates/config_base/app/frontend/ssr/ssr.js
54
53
  - templates/config_base/config/svelte_on_rails.yml
55
54
  - templates/config_base/vite-ssr.config.ts
@@ -1,18 +0,0 @@
1
-
2
- import { initializeSvelteComponents, cleanupSvelteComponents } from '@csedl/svelte-on-rails';
3
-
4
- const components = import.meta.glob('/javascript/components/**/*.svelte', { eager: true });
5
- const componentsRoot = '/javascript/components';
6
-
7
- // Initialize Svelte components
8
- initializeSvelteComponents(componentsRoot, components, true);
9
-
10
- // Turbo event listener for page load
11
- document.addEventListener('turbo:load', () => {
12
- initializeSvelteComponents(componentsRoot, components, true);
13
- });
14
-
15
- // Turbo event listener for cleanup before page cache
16
- document.addEventListener('turbo:before-cache', () => {
17
- cleanupSvelteComponents(false);
18
- });