2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-04-14 20:46:28 +02:00
|
|
|
module TurboStreamHelper
|
|
|
|
def turbo_stream
|
|
|
|
TagBuilder.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
class TagBuilder < Turbo::Streams::TagBuilder
|
2022-10-11 23:39:26 +02:00
|
|
|
include ActionView::Helpers::TagHelper
|
2022-04-14 20:46:28 +02:00
|
|
|
|
|
|
|
def show(target, delay: nil)
|
2023-01-16 21:31:07 +01:00
|
|
|
turbo_stream_action_tag :show, target:, delay:
|
2022-04-14 20:46:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_all(targets, delay: nil)
|
2023-01-16 21:31:07 +01:00
|
|
|
turbo_stream_action_tag :show, targets:, delay:
|
2022-04-14 20:46:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def hide(target, delay: nil)
|
2023-01-16 21:31:07 +01:00
|
|
|
turbo_stream_action_tag :hide, target:, delay:
|
2022-04-14 20:46:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def hide_all(targets, delay: nil)
|
2023-01-16 21:31:07 +01:00
|
|
|
turbo_stream_action_tag :hide, targets:, delay:
|
2022-04-14 20:46:28 +02:00
|
|
|
end
|
|
|
|
|
2023-01-16 21:31:07 +01:00
|
|
|
def focus(target, delay: nil)
|
|
|
|
turbo_stream_action_tag :focus, target:, delay:
|
2022-04-14 20:46:28 +02:00
|
|
|
end
|
|
|
|
|
2023-01-16 21:31:07 +01:00
|
|
|
def focus_all(targets, delay: nil)
|
|
|
|
turbo_stream_action_tag :focus, targets:, delay:
|
2022-10-11 23:39:26 +02:00
|
|
|
end
|
|
|
|
|
2023-01-16 21:31:07 +01:00
|
|
|
def enable(target, delay: nil)
|
|
|
|
turbo_stream_action_tag :enable, target:, delay:
|
2022-10-11 23:39:26 +02:00
|
|
|
end
|
|
|
|
|
2023-01-16 21:31:07 +01:00
|
|
|
def enable_all(targets, delay: nil)
|
|
|
|
turbo_stream_action_tag :enable, targets:, delay:
|
2022-04-14 20:46:28 +02:00
|
|
|
end
|
2022-05-04 12:42:10 +02:00
|
|
|
|
2023-01-16 21:31:07 +01:00
|
|
|
def disable(target, delay: nil)
|
|
|
|
turbo_stream_action_tag :disable, target:, delay:
|
2022-05-04 12:42:10 +02:00
|
|
|
end
|
|
|
|
|
2023-01-16 21:31:07 +01:00
|
|
|
def disable_all(targets, delay: nil)
|
|
|
|
turbo_stream_action_tag :disable, targets:, delay:
|
2022-10-11 23:39:26 +02:00
|
|
|
end
|
|
|
|
|
2023-01-13 11:13:09 +01:00
|
|
|
def dispatch(type, detail = nil)
|
|
|
|
content = detail.present? ? tag.script(cdata_section(detail.to_json), type: 'application/json') : nil
|
|
|
|
action_all :append, 'head', tag.dispatch_event(content, type:)
|
2022-10-11 23:39:26 +02:00
|
|
|
end
|
2022-04-14 20:46:28 +02:00
|
|
|
end
|
|
|
|
end
|