swal_rails 0.5.0 → 0.5.2

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: 958168a17777ae58b1ce198ab3de6df9945942a5065c7311201fc05bd4ee8714
4
- data.tar.gz: 756c79ba6c1bf50bf288a934b807ddda9e09a49eb221097092c72ac3f2981c8b
3
+ metadata.gz: 2ef8664e41d7dfc5b012bacbb96a504664ae32c06f741349c47d37f05e5bd0bf
4
+ data.tar.gz: 733930aa44e423ee3af4e0e3bf90466c069d64cd98b51926456352a85810c6bb
5
5
  SHA512:
6
- metadata.gz: aa8b8b60bb0e2c37cd2669d5dbaaa1e14ccbd3c342f97496679b2829294a050be7250ef131bc2d94cb9d469a51daf3f71bd838edc949beefb2040cbb086b13b5
7
- data.tar.gz: bf4db27a6c234df8aec4e881c99c67578cf575a3c6fdd53092f7f1e827ce01354c2334d677919159cf31a09e2ecc821193cf78f7438409bb89fdcd1e8c71544b
6
+ metadata.gz: d2853982d0e80c7e135e8ed4813d1e8aa127801215da720067ea660600f48c1dc719c7c68dff73c5ae77d879cd4d00e75fd63007958015c772bb0e3c7594aafc
7
+ data.tar.gz: d703a699653f4c6f7d962244bc26cfb9dae7da07fbdeca7842f9d9f5df5c4d2ac008ac44801087920184949d6beb83a9a9dff8ce877582ef440e4e4396667e06
data/CHANGELOG.md CHANGED
@@ -6,6 +6,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.5.2] - 2026-05-28
10
+
11
+ ### Fixed
12
+ - **`turbo_stream.swal_flash` key resolution** — `flash_map` stores Symbol keys
13
+ but `swal_flash` was fetching with `key.to_s`, always missing and emitting a
14
+ tag without `icon`/`toast`/`position`/`timer`. Changed to `key.to_sym`.
15
+ Closes [#29](https://github.com/Metalzoid/swal_rails/issues/29).
16
+
17
+ ## [0.5.1] - 2026-05-28
18
+
19
+ ### Added
20
+ - **Turbo Stream action `swal`** — `Turbo.StreamActions.swal` is registered at
21
+ boot, reading a JSON payload from the `<template>` element and calling
22
+ `Swal.fire()`. Covers `format.turbo_stream` responses, which never fire
23
+ `turbo:load` / `turbo:render` and were therefore silently ignored by the
24
+ existing meta-tag flash path.
25
+ Closes [#27](https://github.com/Metalzoid/swal_rails/issues/27).
26
+ - **`turbo_stream.swal(options)`** — emits a `<turbo-stream action="swal">`
27
+ tag with free-form SweetAlert2 options.
28
+ - **`turbo_stream.swal_flash(key, message, **overrides)`** — flash-map-aware
29
+ shortcut; maps the key through `SwalRails.configuration.flash_map` and
30
+ merges `text:` + any overrides.
31
+ - **npm exports entry `swal_rails/stream`** — added to `package.json` exports
32
+ map for jsbundling users.
33
+
9
34
  ## [0.5.0] - 2026-05-27
10
35
 
11
36
  ### Added
@@ -1,6 +1,7 @@
1
1
  import Swal from "sweetalert2"
2
2
  import { installConfirm } from "swal_rails/confirm"
3
3
  import { installFlash } from "swal_rails/flash"
4
+ import { installStreamAction } from "swal_rails/stream"
4
5
 
5
6
  const readMeta = (name) => {
6
7
  const el = document.querySelector(`meta[name="${name}"]`)
@@ -38,6 +39,7 @@ const boot = () => {
38
39
  }
39
40
 
40
41
  installConfirm(Mixin, config)
42
+ installStreamAction(Mixin)
41
43
  booted = { Swal: Mixin, config }
42
44
  document.dispatchEvent(new CustomEvent("swal-rails:ready", { detail: booted }))
43
45
  }
@@ -0,0 +1,9 @@
1
+ export function installStreamAction(Swal) {
2
+ if (typeof Turbo === "undefined" || !Turbo.StreamActions) return
3
+ Turbo.StreamActions.swal = function () {
4
+ const json = this.templateContent.textContent.trim()
5
+ if (!json) return
6
+ try { Swal.fire(JSON.parse(json)) }
7
+ catch (e) { console.debug("swal_rails stream action: payload invalide", e) }
8
+ }
9
+ }
data/config/importmap.rb CHANGED
@@ -5,5 +5,6 @@ pin "swal_rails", to: "swal_rails/index.js"
5
5
  pin "swal_rails/confirm", to: "swal_rails/confirm.js"
6
6
  pin "swal_rails/flash", to: "swal_rails/flash.js"
7
7
  pin "swal_rails/chain", to: "swal_rails/chain.js"
8
+ pin "swal_rails/stream", to: "swal_rails/stream.js"
8
9
  pin_all_from SwalRails::Engine.root.join("app/assets/javascripts/swal_rails/controllers"),
9
10
  under: "controllers", to: "swal_rails/controllers"
@@ -11,6 +11,7 @@ module SwalRails
11
11
  swal_rails/confirm.js
12
12
  swal_rails/flash.js
13
13
  swal_rails/chain.js
14
+ swal_rails/stream.js
14
15
  swal_rails/controllers/swal_controller.js
15
16
  swal_rails/index.css
16
17
  ].freeze
@@ -29,6 +29,10 @@ module SwalRails
29
29
  app.config.importmap.cache_sweepers << root.join("vendor/javascript")
30
30
  end
31
31
 
32
+ initializer "swal_rails.turbo_stream_helper", after: :load_config_initializers do
33
+ Turbo::Streams::TagBuilder.prepend(SwalRails::TurboStreamHelper) if defined?(Turbo::Streams::TagBuilder)
34
+ end
35
+
32
36
  initializer "swal_rails.helpers" do
33
37
  ActiveSupport.on_load(:action_controller_base) do
34
38
  helper SwalRails::Helpers
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SwalRails
4
+ # Extends Turbo::Streams::TagBuilder with swal-specific stream actions.
5
+ # Prepended at boot (engine initializer) only when turbo-rails is loaded.
6
+ #
7
+ # Usage in a controller:
8
+ # render turbo_stream: [
9
+ # turbo_stream.update("modal-container", ""),
10
+ # turbo_stream.swal_flash(:notice, "Élément créé avec succès"),
11
+ # # or freeform SA2 options:
12
+ # # turbo_stream.swal(icon: "error", title: "Oops", text: "Something went wrong")
13
+ # ]
14
+ module TurboStreamHelper
15
+ # Emit a <turbo-stream action="swal"> tag with raw SA2 options.
16
+ #
17
+ # turbo_stream.swal(icon: "success", title: "OK", toast: true, timer: 3000)
18
+ def swal(options = {})
19
+ payload = ERB::Util.json_escape(options.to_json)
20
+ turbo_stream_action_tag(:swal, template: payload)
21
+ end
22
+
23
+ # Emit a <turbo-stream action="swal"> tag mapped from a flash key.
24
+ # Merges flash_map defaults for the key, then applies text: and any overrides.
25
+ #
26
+ # turbo_stream.swal_flash(:notice, "Élément créé avec succès")
27
+ # turbo_stream.swal_flash(:error, "Échec", timer: 0)
28
+ def swal_flash(key, message = nil, **overrides)
29
+ base = SwalRails.configuration.flash_map.fetch(key.to_sym, {}).dup
30
+ base = base.merge(text: message) if message
31
+ base = base.merge(overrides) unless overrides.empty?
32
+ swal(base)
33
+ end
34
+ end
35
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwalRails
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.2"
5
5
  SWEETALERT2_VERSION = "11.26.24"
6
6
  end
data/lib/swal_rails.rb CHANGED
@@ -32,4 +32,5 @@ require_relative "swal_rails/configuration"
32
32
  require_relative "swal_rails/asset_manifest"
33
33
  require_relative "swal_rails/initializer_version_check"
34
34
  require_relative "swal_rails/helpers"
35
+ require_relative "swal_rails/turbo_stream_helper"
35
36
  require_relative "swal_rails/engine" if defined?(Rails::Engine)
data/npm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import Swal from "sweetalert2"
2
2
  import { installConfirm } from "swal_rails/confirm"
3
3
  import { installFlash } from "swal_rails/flash"
4
+ import { installStreamAction } from "swal_rails/stream"
4
5
 
5
6
  const readMeta = (name) => {
6
7
  const el = document.querySelector(`meta[name="${name}"]`)
@@ -38,6 +39,7 @@ const boot = () => {
38
39
  }
39
40
 
40
41
  installConfirm(Mixin, config)
42
+ installStreamAction(Mixin)
41
43
  booted = { Swal: Mixin, config }
42
44
  document.dispatchEvent(new CustomEvent("swal-rails:ready", { detail: booted }))
43
45
  }
data/npm/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swal_rails",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "SweetAlert2 for Rails 7+ — batteries included (jsbundling companion)",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -10,6 +10,7 @@
10
10
  "./confirm": "./confirm.js",
11
11
  "./flash": "./flash.js",
12
12
  "./chain": "./chain.js",
13
+ "./stream": "./stream.js",
13
14
  "./controllers/swal_controller": "./controllers/swal_controller.js"
14
15
  },
15
16
  "files": [
data/npm/stream.js ADDED
@@ -0,0 +1,9 @@
1
+ export function installStreamAction(Swal) {
2
+ if (typeof Turbo === "undefined" || !Turbo.StreamActions) return
3
+ Turbo.StreamActions.swal = function () {
4
+ const json = this.templateContent.textContent.trim()
5
+ if (!json) return
6
+ try { Swal.fire(JSON.parse(json)) }
7
+ catch (e) { console.debug("swal_rails stream action: payload invalide", e) }
8
+ }
9
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swal_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Gagnaire
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-05-27 00:00:00.000000000 Z
11
+ date: 2026-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -58,6 +58,7 @@ files:
58
58
  - app/assets/javascripts/swal_rails/controllers/swal_controller.js
59
59
  - app/assets/javascripts/swal_rails/flash.js
60
60
  - app/assets/javascripts/swal_rails/index.js
61
+ - app/assets/javascripts/swal_rails/stream.js
61
62
  - app/assets/stylesheets/swal_rails/index.css
62
63
  - config/importmap.rb
63
64
  - config/locales/swal_rails.en.yml
@@ -75,6 +76,7 @@ files:
75
76
  - lib/swal_rails/engine.rb
76
77
  - lib/swal_rails/helpers.rb
77
78
  - lib/swal_rails/initializer_version_check.rb
79
+ - lib/swal_rails/turbo_stream_helper.rb
78
80
  - lib/swal_rails/version.rb
79
81
  - npm/chain.js
80
82
  - npm/confirm.js
@@ -82,6 +84,7 @@ files:
82
84
  - npm/flash.js
83
85
  - npm/index.js
84
86
  - npm/package.json
87
+ - npm/stream.js
85
88
  - vendor/javascript/sweetalert2/LICENSE
86
89
  - vendor/javascript/sweetalert2/sweetalert2.all.js
87
90
  - vendor/javascript/sweetalert2/sweetalert2.all.min.js