Add turbo power so we can use its custom actions in turbo streams

This commit is contained in:
Oliver Günther
2024-07-25 20:59:52 +02:00
parent 49ad86fd3b
commit 42e0fb4008
5 changed files with 25 additions and 0 deletions
+1
View File
@@ -228,6 +228,7 @@ gem "factory_bot", "~> 6.4.0", require: false
gem "factory_bot_rails", "~> 6.4.0", require: false
gem "turbo-rails", "~> 2.0.0"
gem "turbo_power", "~> 0.6.2"
gem "httpx"
+3
View File
@@ -1093,6 +1093,8 @@ GEM
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
turbo_power (0.6.2)
turbo-rails (>= 1.3.0)
typed_dag (2.0.2)
rails (>= 5.0.4)
tzinfo (2.0.6)
@@ -1347,6 +1349,7 @@ DEPENDENCIES
timecop (~> 0.9.0)
ttfunk (~> 1.7.0)
turbo-rails (~> 2.0.0)
turbo_power (~> 0.6.2)
turbo_tests!
typed_dag (~> 2.0.2)
tzinfo-data (~> 1.2024.1)
+15
View File
@@ -99,6 +99,7 @@
"tablesorter": "^2.31.3",
"ts-action": "^11.0.0",
"ts-action-operators": "^9.1.2",
"turbo_power": "^0.6.2",
"typedjson": "^1.5.1",
"urijs": "^1.19.11",
"uuid": "^8.3.2",
@@ -20479,6 +20480,15 @@
"node": ">=16 || 14 >=14.17"
}
},
"node_modules/turbo_power": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/turbo_power/-/turbo_power-0.6.2.tgz",
"integrity": "sha512-GCrwi6+rSLVORqb1LwP9pf/jP1Zo5lJgzGbLVu8g79T6LvB/9GGg7VWdLlWB0RvvDE1/+3hm32MPtEL5g89fsg==",
"license": "MIT",
"peerDependencies": {
"@hotwired/turbo": ">= 7.2"
}
},
"node_modules/type": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz",
@@ -37048,6 +37058,11 @@
}
}
},
"turbo_power": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/turbo_power/-/turbo_power-0.6.2.tgz",
"integrity": "sha512-GCrwi6+rSLVORqb1LwP9pf/jP1Zo5lJgzGbLVu8g79T6LvB/9GGg7VWdLlWB0RvvDE1/+3hm32MPtEL5g89fsg=="
},
"type": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz",
+1
View File
@@ -150,6 +150,7 @@
"tablesorter": "^2.31.3",
"ts-action": "^11.0.0",
"ts-action-operators": "^9.1.2",
"turbo_power": "^0.6.2",
"typedjson": "^1.5.1",
"urijs": "^1.19.11",
"uuid": "^8.3.2",
+5
View File
@@ -1,5 +1,6 @@
import '../typings/shims.d.ts';
import * as Turbo from '@hotwired/turbo';
import TurboPower from 'turbo_power'
import { registerDialogStreamAction } from './dialog-stream-action';
import { addTurboEventListeners } from './turbo-event-listeners';
@@ -8,9 +9,13 @@ Turbo.session.drive = false;
// Start turbo
Turbo.start();
// Register our own actions
addTurboEventListeners();
registerDialogStreamAction();
// Register turbo power actions
TurboPower.initialize(Turbo.StreamActions);
// Error handling when "Content missing" returned
document.addEventListener('turbo:frame-missing', (event:CustomEvent) => {
const { detail: { response, visit } } = event as { detail:{ response:Response, visit:(url:string) => void } };