From 162d3f13ebab51b117ba3a9a9b792273d1186259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C4=82LTEANU?= Date: Tue, 27 Feb 2024 23:36:40 +0200 Subject: [PATCH] WIP diff --git a/Gemfile b/Gemfile index 32f710c54..1d65d9ccf 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,8 @@ gem 'addressable' gem 'rubyzip', '~> 2.4.0' gem 'propshaft', '~> 1.1.0' gem 'rack', '>= 3.1.3' +gem 'stimulus-rails' +gem "importmap-rails" # Ruby Standard Gems gem 'csv', '~> 3.2.8' diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application-legacy.js similarity index 100% rename from app/assets/javascripts/application.js rename to app/assets/javascripts/application-legacy.js diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9bb26bdec..05f19f558 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1805,7 +1805,7 @@ module ApplicationHelper if Setting.wiki_tablesort_enabled? tags << javascript_include_tag('tablesort-5.2.1.min.js', 'tablesort-5.2.1.number.min.js') end - tags << javascript_include_tag('application', 'responsive') + tags << javascript_include_tag('application-legacy', 'responsive') unless User.current.pref.warn_on_leaving_unsaved == '0' warn_text = escape_javascript(l(:text_warn_on_leaving_unsaved)) tags << @@ -1934,9 +1934,14 @@ module ApplicationHelper def copy_object_url_link(url) link_to_function( - sprite_icon('copy-link', l(:button_copy_link)), 'copyTextToClipboard(this);', + sprite_icon('copy-link', l(:button_copy_link)), {}, class: 'icon icon-copy-link', - data: {'clipboard-text' => url} + data: { + 'clipboard-value': url, + controller: "clipboard", + action: "clipboard#copy", + 'clipboard-target': "source", + } ) end diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 000000000..72ef077f8 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1 @@ +import "controllers" diff --git a/app/javascript/controllers/application.js b/app/javascript/controllers/application.js new file mode 100644 index 000000000..1213e85c7 --- /dev/null +++ b/app/javascript/controllers/application.js @@ -0,0 +1,9 @@ +import { Application } from "@hotwired/stimulus" + +const application = Application.start() + +// Configure Stimulus development experience +application.debug = false +window.Stimulus = application + +export { application } diff --git a/app/javascript/controllers/clipboard_controller.js b/app/javascript/controllers/clipboard_controller.js new file mode 100644 index 000000000..4517aaed4 --- /dev/null +++ b/app/javascript/controllers/clipboard_controller.js @@ -0,0 +1,14 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + static targets = [ "source" ] + copy() { + navigator.clipboard.writeText(this.sourceTarget.dataset.clipboardValue).then(() => this.close()) + } + close() { + const drdn = this.sourceTarget.closest('.drdn.expanded') + if (drdn) { + drdn.classList.remove("expanded"); + } + } +} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js new file mode 100644 index 000000000..d72ad948b --- /dev/null +++ b/app/javascript/controllers/index.js @@ -0,0 +1,7 @@ +// Import and register all your controllers from the importmap under controllers/* + +import { application } from "controllers/application" + +// Eager load all controllers defined in the import map under controllers/**/*_controller +import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +eagerLoadControllersFrom("controllers", application) diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index 3432cb655..bf4b5af9e 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -10,6 +10,7 @@ <%= favicon %> <%= stylesheet_link_tag 'jquery/jquery-ui-1.13.2', 'tribute-5.1.3', 'application', 'responsive', :media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> +<%= javascript_importmap_tags %> <%= javascript_heads %> <%= heads_for_theme %> <%= heads_for_auto_complete(@project) %> diff --git a/bin/importmap b/bin/importmap new file mode 100755 index 000000000..36502ab16 --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 000000000..a7b873a9b --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,6 @@ +# Pin npm packages by running ./bin/importmap + +pin "application", preload: true +pin "@hotwired/stimulus", to: "stimulus.min.js" +pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" +pin_all_from "app/javascript/controllers", under: "controllers" -- 2.39.5 (Apple Git-154)