WIP: Power-pack for Turbo Streams

Overview

TurboPower

turbo_power is a power-pack for Turbo Streams. It provides Turbo Streams with a bunch of new actions and additionally adds the morph action from turbo-morph and the invoke action from turbo_ready.

Note: Requires Turbo 7.2+

Getting Started

yarn add turbo_power
// application.js
import * as Turbo from '@hotwired/turbo'

+import TurboPower from 'turbo_power'
+TurboPower.initialize(Turbo.StreamActions)

Getting Started with Rails

Checkout the instructions in the turbo_power-rails repo.

Custom Actions

Actions from turbo_ready

Actions from turbo-morph

DOM Actions

  • turbo_stream.graft(target, parent, **attributes)
  • turbo_stream.inner_html(target, html = nil, **attributes, &block)
  • turbo_stream.insert_adjacent_html(target, html = nil, position: 'beforeend', **attributes, &block)
  • turbo_stream.insert_adjacent_text(target, text, position: 'beforebegin', **attributes)
  • turbo_stream.morph(target, html = nil, **attribtues, &block)
  • turbo_stream.outer_html(target, html = nil, **attributes, &block)
  • turbo_stream.text_content(target, text, **attributes)
  • turbo_stream.set_meta(name, content)

Attribute Actions

  • turbo_stream.add_css_class(target, classes, **attributes)
  • turbo_stream.remove_attribute(target, attribute, **attributes)
  • turbo_stream.remove_css_class(target, classes, **attributes)
  • turbo_stream.set_attribute(target, attribute, value, **attributes)
  • turbo_stream.set_dataset_attribute(target, attribute, value, **attributes)
  • turbo_stream.set_property(target, property, value, **attributes)
  • turbo_stream.set_style(target, name, value, **attributes)
  • turbo_stream.set_styles(target, styles, **attributes)
  • turbo_stream.set_value(target, value, **attributes)

Event Actions

  • turbo_stream.dispatch_event(target, name, detail: {}, **attributes)

Storage Actions

  • turbo_stream.clear_storage(type, **attributes)
  • turbo_stream.clear_local_storage(**attributes)
  • turbo_stream.clear_session_storage(**attributes)
  • turbo_stream.remove_storage_item(key, type, **attributes)
  • turbo_stream.remove_local_storage_item(key, **attributes)
  • turbo_stream.remove_session_storage_item(key, **attributes)
  • turbo_stream.set_storage_item(key, value, type, **attributes)
  • turbo_stream.set_local_storage_item(key, value, **attributes)
  • turbo_stream.set_session_storage_item(key, value, **attributes)

Browser Actions

  • turbo_stream.redirect_to(url, action_name = nil, **attributes)
  • turbo_stream.reload(**attributes)
  • turbo_stream.scroll_into_view(target, inline = "nearest")
  • turbo_stream.set_cookie(cookie, **attributes)
  • turbo_stream.set_cookie_item(key, value, **attributes)
  • turbo_stream.set_focus(target, **attributes)
  • turbo_stream.set_title(title, **attributes)

Browser History Actions

  • turbo_stream.history_go(delta, **attributes)
  • turbo_stream.push_state(url, title = nil, state = nil, **attributes)
  • turbo_stream.replace_state(url, title = nil, state = nil, **attributes)

Debug Actions

  • turbo_stream.console_log(message, level = :log, **attributes)
  • turbo_stream.console_table(data, columns, **attributes)

Notification Actions

  • turbo_stream.notification(title, options, **attributes)

Previous Art

TurboPower is heavily inspired by CableReady and it's operations. This library aims to bring the same level of operation-diversity to Turbo Streams.

Acknowledgments

turbo_power is MIT-licensed open-source software from Marco Roth.

turbo_ready is MIT-licensed open-source software from Nate Hopkins.

turbo-morph is MIT-licensed open-source software from Marco Roth.

Turbo is MIT-licensed open-source software from Basecamp.

Comments
  • `redirect_to` Action: rename `action` attribute to `action_name`

    `redirect_to` Action: rename `action` attribute to `action_name`

    The redirect_to action has an action attribute which is being passed to Turbo.visit(..., { action }) to control the Turbo visit behaviour.

    But the action attribute name is clashing with the <turbo-stream> element, since it's using the action attribute for determining the stream action to execute.

    We should rename the attribute for the redirect_to action to either action_name or turbo_action.

    bug good first issue 
    opened by marcoroth 2
  • Deprecate `invoke` action

    Deprecate `invoke` action

    This Pull Request deprecates the invoke stream action. If you'd like to continue using it you should use the successor library (@turbo-boost/streams) instead.

    TurboPower will still register a stubbed out invoke stream action if the action wasn't registered yet, so you get a deprecation warning in the browser console.

    opened by marcoroth 0
  • Add `typecast` util function

    Add `typecast` util function

    This Pull Request adds a typecast util function in order to convert any string value to its typecast representation.

    Due to the fact that HTML attributes are always strings we have to do the conversion.

    enhancement 
    opened by marcoroth 0
  • Implement `reset_form` action

    Implement `reset_form` action

    Action signature:

    turbo_stream.reset_form(target, **attributes)
    

    Reference:

    • https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reset
    • https://twitter.com/excid3/status/1601285720106094592
    help wanted good first issue new custom action 
    opened by marcoroth 0
  • Think about creating a `turbo.ts` actions file

    Think about creating a `turbo.ts` actions file

    Maybe it would makes sense to extract all the Turbo related actions into a src/actions/turbo.ts file.

    For now this is:

    • redirect_to (or a potential turbo_visit)
    • turbo_clear_cache
    enhancement 
    opened by marcoroth 0
  • Remove `Turbolinks` from all actions

    Remove `Turbolinks` from all actions

    The Turbolinks cases in all actions were taken over from the CableReady operations.

    But technically Turbolinks isn't really compatible with TurboPower since you actually need to have Turbo installed in your app if you want to use Custom Turbo Stream Actions.

    enhancement 
    opened by marcoroth 0
  • Implement `turbo_clear_cache` action

    Implement `turbo_clear_cache` action

    Action signature:

    turbo_stream.turbo_clear_cache()
    

    Action content:

    Turbo.cache.clear()
    

    Reference: https://turbo.hotwired.dev/reference/drive#turbo.cache.clear

    help wanted good first issue new custom action 
    opened by marcoroth 0
  • Add CodeQL workflow for GitHub code scanning

    Add CodeQL workflow for GitHub code scanning

    Hi marcoroth/turbo_power!

    This is a one-off automatically generated pull request from LGTM.com :robot:. You might have heard that we’ve integrated LGTM’s underlying CodeQL analysis engine natively into GitHub. The result is GitHub code scanning!

    With LGTM fully integrated into code scanning, we are focused on improving CodeQL within the native GitHub code scanning experience. In order to take advantage of current and future improvements to our analysis capabilities, we suggest you enable code scanning on your repository. Please take a look at our blog post for more information.

    This pull request enables code scanning by adding an auto-generated codeql.yml workflow file for GitHub Actions to your repository — take a look! We tested it before opening this pull request, so all should be working :heavy_check_mark:. In fact, you might already have seen some alerts appear on this pull request!

    Where needed and if possible, we’ve adjusted the configuration to the needs of your particular repository. But of course, you should feel free to tweak it further! Check this page for detailed documentation.

    Questions? Check out the FAQ below!

    FAQ

    Click here to expand the FAQ section

    How often will the code scanning analysis run?

    By default, code scanning will trigger a scan with the CodeQL engine on the following events:

    • On every pull request — to flag up potential security problems for you to investigate before merging a PR.
    • On every push to your default branch and other protected branches — this keeps the analysis results on your repository’s Security tab up to date.
    • Once a week at a fixed time — to make sure you benefit from the latest updated security analysis even when no code was committed or PRs were opened.

    What will this cost?

    Nothing! The CodeQL engine will run inside GitHub Actions, making use of your unlimited free compute minutes for public repositories.

    What types of problems does CodeQL find?

    The CodeQL engine that powers GitHub code scanning is the exact same engine that powers LGTM.com. The exact set of rules has been tweaked slightly, but you should see almost exactly the same types of alerts as you were used to on LGTM.com: we’ve enabled the security-and-quality query suite for you.

    How do I upgrade my CodeQL engine?

    No need! New versions of the CodeQL analysis are constantly deployed on GitHub.com; your repository will automatically benefit from the most recently released version.

    The analysis doesn’t seem to be working

    If you get an error in GitHub Actions that indicates that CodeQL wasn’t able to analyze your code, please follow the instructions here to debug the analysis.

    How do I disable LGTM.com?

    If you have LGTM’s automatic pull request analysis enabled, then you can follow these steps to disable the LGTM pull request analysis. You don’t actually need to remove your repository from LGTM.com; it will automatically be removed in the next few months as part of the deprecation of LGTM.com (more info here).

    Which source code hosting platforms does code scanning support?

    GitHub code scanning is deeply integrated within GitHub itself. If you’d like to scan source code that is hosted elsewhere, we suggest that you create a mirror of that code on GitHub.

    How do I know this PR is legitimate?

    This PR is filed by the official LGTM.com GitHub App, in line with the deprecation timeline that was announced on the official GitHub Blog. The proposed GitHub Action workflow uses the official open source GitHub CodeQL Action. If you have any other questions or concerns, please join the discussion here in the official GitHub community!

    I have another question / how do I get in touch?

    Please join the discussion here to ask further questions and send us suggestions!

    opened by lgtm-com[bot] 0
  • Implements the `set_turbo_frame_src` operation

    Implements the `set_turbo_frame_src` operation

    closes #6

    This PR adds the set_turbo_frame_src operation.
    I created a new src/actions/turbo_frames.ts file for turbo_frame operations. The reason for this is that in the future there might be more custom TurboFrame operations and it would be nice to have them all in one place.

    Another way would have been to implement the set_turbo_frame_src operation in existing files like src/actions/dom.ts or src/actions/attributes.ts.

    Would love to hear what you think about it

    opened by leon-vogt 0
  • Implement `console_table` action

    Implement `console_table` action

    Action signature:

    turbo_stream.console_table(data, columns = nil, **attributes)
    

    Reference: https://developer.mozilla.org/en-US/docs/Web/API/Console/table

    help wanted good first issue new custom action 
    opened by marcoroth 0
  • Implement `console_log` action

    Implement `console_log` action

    Action signature:

    turbo_stream.console_log(message, level = :log, **attributes)
    

    Reference: https://developer.mozilla.org/en-US/docs/Web/API/Console/log

    help wanted good first issue new custom action 
    opened by marcoroth 0
  • Implement Action to set a `window.onbeforeunload` callback

    Implement Action to set a `window.onbeforeunload` callback

    Not sure how useful this is, but it might be interesting to have an action to set a window.onbeforeunload callback. This can be handy to set from the server-side when you are sending down some data which is not persisted yet. And with this you would get a warning when you attempt to close the window/tab. Like:

    Screenshot 2022-11-29 at 02 49 30

    The example above can be achieved with this snippet:

    window.onbeforeunload = function() {
      return true;
    }
    

    Obviously we would also need an action to clear the event-listener again.

    enhancement new custom action 
    opened by marcoroth 0
  • Make sure you can just enable some actions and not just

    Make sure you can just enable some actions and not just "all or nothing"

    Something like:

    import * as Turbo from '@hotwired/turbo'
    import TurboPower, { AttributeActions, BrowserActions } from 'turbo_power'
    
    TurboPower.initialize(Turbo.StreamActions, [AttributeActions, BrowserActions])
    
    
    enhancement 
    opened by marcoroth 0
  • Implement `turbo_set_progress_bar` action

    Implement `turbo_set_progress_bar` action

    Add an action/multiple actions for controlling the Turbo progress bar

    Turbo.navigator.adapter.progressBar.setValue(value)
    Turbo.navigator.adapter.progressBar.show()
    Turbo.navigator.adapter.progressBar.hide()
    
    help wanted good first issue new custom action 
    opened by marcoroth 0
  • Implement `turbo_visit` action

    Implement `turbo_visit` action

    Action signature:

    turbo_stream.turbo_visit(location, action = "advance", **attributes)
    

    Action content:

    Turbo.visit(location)
    Turbo.visit(location, { action: turbo_action })
    

    Check out the existing redirect_to action, which technically already covers the use-case for this action.

    Reference: https://turbo.hotwired.dev/reference/drive#turbo.visit

    help wanted good first issue new custom action 
    opened by marcoroth 0
  • Action `redirect_to` should use Turbo by default

    Action `redirect_to` should use Turbo by default

    Currently you need to pass turbo="true" to the <turbo-stream> element in order that is uses Turbo.visit():

    <turbo-stream turbo="true" url="http://localhost:3000/" action="redirect_to"><template></template></turbo-stream>
    

    It should use Turbo.visit() by default unless turbo="false" gets explicitly passed to the stream element.

    The action already accounts for when Turbo/Turbolinks is not installed in the application and will fallback to window.location.href = url

    https://github.com/marcoroth/turbo_power/blob/623a6f5b11608073ac36880bd1f0cc4745a52e56/src/actions/browser.ts#L17

    enhancement good first issue 
    opened by marcoroth 5
  • [Feature Request] Add or improve history actions

    [Feature Request] Add or improve history actions

    Thanks for the great lib!

    It would be nice to have a shortcut to modify Turbo.navigator.history. I find it an essential action since the Back button is not doing what is expected when the browser history is modified without touching Turbo.navigator.history. As a workaround, the invoke action can be used at the moment.

    More on the issue: https://discuss.hotwired.dev/t/back-button-not-working/3012

    P.S. I'd really love to help but I'm not very familiar with Typescript yet :/

    opened by pySilver 5
Releases(v0.2.0)
  • v0.2.0(Jan 4, 2023)

    What's Changed

    • Extract Turbo actions in a custom `turbo.ts file by @leon-vogt in https://github.com/marcoroth/turbo_power/pull/23
    • Remove Turbolinks from the redirect_to action by @leon-vogt in https://github.com/marcoroth/turbo_power/pull/25
    • Add typecast util function by @marcoroth in https://github.com/marcoroth/turbo_power/pull/28
    • Fix typecasting in set_property action by @minimul in https://github.com/marcoroth/turbo_power/pull/27
    • Implement reset_form action by @marcoroth in https://github.com/marcoroth/turbo_power/pull/30
    • Deprecate invoke action by @marcoroth in https://github.com/marcoroth/turbo_power/pull/29

      Use the successor library @turbo-boost/streams instead

    Commits

    Full Changelog: https://github.com/marcoroth/turbo_power/compare/v0.1.6...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.6(Nov 19, 2022)

    What's Changed

    • Add CodeQL workflow for GitHub code scanning by @lgtm-com in https://github.com/marcoroth/turbo_power/pull/12
    • Implement turbo_clear_cache action by @leon-vogt in https://github.com/marcoroth/turbo_power/pull/21
    • Rename action attribute to turbo_action in redirect_to action by @leon-vogt in https://github.com/marcoroth/turbo_power/pull/22

    New Contributors

    • @lgtm-com made their first contribution in https://github.com/marcoroth/turbo_power/pull/12
    • @leon-vogt made their first contribution in https://github.com/marcoroth/turbo_power/pull/21

    Commits

    Full Changelog: https://github.com/marcoroth/turbo_power/compare/v0.1.5...v0.1.6

    Source code(tar.gz)
    Source code(zip)
  • v0.1.5(Nov 2, 2022)

    What's Changed

    • Implement turbo_frame_reload and turbo_frame_set_src actions by @minimul in https://github.com/marcoroth/turbo_power/pull/10

    New Contributors

    • @minimul made their first contribution in https://github.com/marcoroth/turbo_power/pull/10

    Commits

    Full Changelog: https://github.com/marcoroth/turbo_power/compare/v0.1.4...v0.1.5

    Source code(tar.gz)
    Source code(zip)
  • v0.1.4(Oct 6, 2022)

    What's Changed

    • How to run tests by @drnic in https://github.com/marcoroth/turbo_power/pull/7
    • Add console_log and console_table actions by @drnic in https://github.com/marcoroth/turbo_power/pull/8

    New Contributors

    • @drnic made their first contribution in https://github.com/marcoroth/turbo_power/pull/7

    Commits

    Full Changelog: https://github.com/marcoroth/turbo_power/compare/v0.1.3...v0.1.4

    Source code(tar.gz)
    Source code(zip)
  • v0.1.3(Sep 25, 2022)

  • v0.1.2(Sep 24, 2022)

  • v0.1.0-beta.2(Sep 13, 2022)

    Added

    Internal

    • Added tests for various actions
    • Upgraded Turbo to 7.2.0-rc.1

    Full Changelog: https://github.com/marcoroth/turbo_power/compare/0.1.0-beta.1...v0.1.0-beta.2

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0-beta.1(Sep 5, 2022)

Owner
Marco Roth
Rubyist, part-time developer and part-time computer science student.
Marco Roth
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
This Is a Whatsapp Bot Made By Turbo Do Not Recode

This Is a Whatsapp Bot Made By Turbo Do Not Recode

TURBOMODS 7 Dec 6, 2022
Provides event handling and an HTMLElement mixin for Declarative Shadow DOM in Hotwire Turbo.

Turbo Shadow Provides event handling and an HTMLElement mixin for Declarative Shadow DOM support in Hotwire Turbo. Requires Turbo 7.2 or higher. Quick

Whitefusion 17 Sep 28, 2022
Nuxt.js 3 x Histoire x Vitest x VitePress x Turbo (pnpm)

Turborepo nuxt starter This is a monorepo with Nuxt, Histoire, Vitest & VitePress as a starter for any project that can be easily extended. You can al

Gurvan 19 Dec 19, 2022
This repository contains a fullstack chatbot project based on the ChatGPT `gpt-3.5-turbo` model.

This is a fullstack chatbot created with React, Nodejs, OpenAi, and ChatGPT while developing the following tutorial: How To Build A Chat Bot Applicati

NJOKU SAMSON EBERE 6 May 10, 2023
lua-pack is an advanced lua bundler similar to webpack made for lua 5.1+ written in js

lua-pack is an advanced lua bundler similar to webpack made for lua 5.1+ written in js that makes working on large scale projects easy and fast. it takes all the files in your project and packs them into a single production ready file.

Chris 10 May 14, 2022
Web-pack based Todo-List Website built using HTML, CSS and JavaScript. Tested Using Jest.

To-DO List Live Link Additional description about the project and its features: Built With HTML and CSS Javascript HTML & CSS3 & JavaScript Linters Gi

Saadat Ali 8 Mar 31, 2022
🦸‍♀️ A super template for Next.js with a pack of incredible tools

Next-Plate ??‍♀️ A super template for Next.js with a pack of incredible tools ?? Translations ?? Demo → Deploy your own copy of this template in just

Gustavo Matheus Morinaga Cardoso 80 Dec 30, 2022
Make a release for Jitsi test browser page (minify js/css files, pack the app in one file).

JitsiTestBrowserTool This tools allows you to make a release for Jitsi test browser page (minify js/css files, pack the app in one file). /!\ Not work

GIP Renater 4 Aug 15, 2022
Pack all your node_modules and other files you want inside your project to a zip file.

?? Node Modules Packer Use Cases | Usage | Examples | Headless | Benchmarks | Reference This is a library to package all your node_modules and other f

Vinicius Lourenço 14 Dec 1, 2022
Generates MIDI chords and scales, which can be downloaded as a free MIDI pack.

MIDI Chords and Scales Pack Description This projects generates (~400) MIDI chords and (~300) MIDI scales, which can be downloaded as a free MIDI pack

Simon Heimler 10 Dec 14, 2022
Simple utils to pack arrays, objects and strings to a flat object (and back again).

packrup Simple utils to pack (and unpack) arrays and strings to a flat object. Status: In Development Please report any issues ?? Made possible by my

Harlan Wilton 15 Dec 23, 2022
Leader Board is a simple project based on JavaScript programing language. The purpose of this project is to work with APIs and ASYNC & AWAIT methods. I have used vanilla JavaScript with web pack to implement this project

Leader Board - JavaScript Project Table of contents Overview The challenge Screenshot Links Project Setup commands My process Built with What I learne

Mahdi Rezaei 7 Oct 21, 2022
Trusted timestamps that you can physically include in photos, videos and live streams using QR codes and audible data signals.

QR Date This is the reference implementation for the first version of QR Date, a signed timestamp inside a QR code that you can use to verify the date

QR Date 36 Oct 5, 2022
Iterables, streams for typescript

Iterable for Typescript Similar to what we know from C#, Dart or any other language which supports them, we use Iterables to stream over collections.

null 3 Oct 15, 2022
... a contemporary perspective on how to integrate B2C Commerce and the Salesforce Customer 360 Platform to power frictionless customer experiences in the B2C domain.

Salesforce B2C Commerce / Customer 360 Platform Integration Introduction Salesforce B2C Commerce / CRM Sync is an enablement solution designed by Sale

Salesforce CommerceCloud 45 Dec 9, 2022
The aim is to provide a hassle-free way to use the data to build applications to show close-to-realtime power-outage info in Mauritius

Mauritius Dataset for Electricity Dataset View Dataset The aim is to provide a hassle-free way to use the data to build applications. Example applicat

Sandeep Ramgolam 5 Dec 15, 2022