From da5252a70bee50dc006a9a2ee52db90fa9a3e2bf Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 28 Jun 2023 11:15:38 +0200 Subject: [PATCH] Move ESM code into app/javascript/alchemy_admin Follows Rails conventions and removes potential conflicts. --- app/assets/config/alchemy_manifest.js | 2 +- app/javascript/alchemy_admin.js | 34 +++++++++++++++++++ .../alchemy_admin}/__tests__/i18n.spec.js | 0 .../javascript/alchemy_admin}/datepicker.js | 0 .../javascript/alchemy_admin}/file_editors.js | 0 .../javascript/alchemy_admin}/i18n.js | 0 .../alchemy_admin}/image_cropper.js | 0 .../javascript/alchemy_admin}/image_loader.js | 0 .../alchemy_admin}/ingredient_anchor_link.js | 0 .../javascript/alchemy_admin}/node_tree.js | 0 .../alchemy_admin}/page_publication_fields.js | 0 .../javascript/alchemy_admin}/page_sorter.js | 0 .../alchemy_admin}/picture_editors.js | 0 .../javascript/alchemy_admin}/sitemap.js | 0 .../javascript/alchemy_admin}/tinymce.js | 0 .../javascript/alchemy_admin}/translations.js | 0 .../utils/__tests__/ajax.spec.js | 0 .../utils/__tests__/events.spec.js | 0 .../javascript/alchemy_admin}/utils/ajax.js | 0 .../javascript/alchemy_admin}/utils/events.js | 0 app/views/layouts/alchemy/admin.html.erb | 2 +- config/importmap.rb | 2 +- lib/alchemy/engine.rb | 2 +- package.json | 4 +-- package/admin.js | 34 ------------------- 25 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 app/javascript/alchemy_admin.js rename {package/src => app/javascript/alchemy_admin}/__tests__/i18n.spec.js (100%) rename {package/src => app/javascript/alchemy_admin}/datepicker.js (100%) rename {package/src => app/javascript/alchemy_admin}/file_editors.js (100%) rename {package/src => app/javascript/alchemy_admin}/i18n.js (100%) rename {package/src => app/javascript/alchemy_admin}/image_cropper.js (100%) rename {package/src => app/javascript/alchemy_admin}/image_loader.js (100%) rename {package/src => app/javascript/alchemy_admin}/ingredient_anchor_link.js (100%) rename {package/src => app/javascript/alchemy_admin}/node_tree.js (100%) rename {package/src => app/javascript/alchemy_admin}/page_publication_fields.js (100%) rename {package/src => app/javascript/alchemy_admin}/page_sorter.js (100%) rename {package/src => app/javascript/alchemy_admin}/picture_editors.js (100%) rename {package/src => app/javascript/alchemy_admin}/sitemap.js (100%) rename {package/src => app/javascript/alchemy_admin}/tinymce.js (100%) rename {package/src => app/javascript/alchemy_admin}/translations.js (100%) rename {package/src => app/javascript/alchemy_admin}/utils/__tests__/ajax.spec.js (100%) rename {package/src => app/javascript/alchemy_admin}/utils/__tests__/events.spec.js (100%) rename {package/src => app/javascript/alchemy_admin}/utils/ajax.js (100%) rename {package/src => app/javascript/alchemy_admin}/utils/events.js (100%) delete mode 100644 package/admin.js diff --git a/app/assets/config/alchemy_manifest.js b/app/assets/config/alchemy_manifest.js index 90c42fc744..f493c437b2 100644 --- a/app/assets/config/alchemy_manifest.js +++ b/app/assets/config/alchemy_manifest.js @@ -13,4 +13,4 @@ //= link_tree ../images/alchemy/ //= link_tree ../../../vendor/assets/fonts/ //= link_tree ../../../vendor/assets/images/ -//= link admin.js +//= link alchemy_admin.js diff --git a/app/javascript/alchemy_admin.js b/app/javascript/alchemy_admin.js new file mode 100644 index 0000000000..e1192f594b --- /dev/null +++ b/app/javascript/alchemy_admin.js @@ -0,0 +1,34 @@ +import translate from "./alchemy_admin/i18n" +import translationData from "./alchemy_admin/translations" +import NodeTree from "./alchemy_admin/node_tree" +import fileEditors from "./alchemy_admin/file_editors" +import IngredientAnchorLink from "./alchemy_admin/ingredient_anchor_link" +import pictureEditors from "./alchemy_admin/picture_editors" +import ImageLoader from "./alchemy_admin/image_loader" +import ImageCropper from "./alchemy_admin/image_cropper" +import Datepicker from "./alchemy_admin/datepicker" +import Sitemap from "./alchemy_admin/sitemap" +import Tinymce from "./alchemy_admin/tinymce" +import PagePublicationFields from "./alchemy_admin/page_publication_fields.js" + +// Global Alchemy object +if (typeof window.Alchemy === "undefined") { + window.Alchemy = {} +} + +// Enhance the global Alchemy object with imported features +Object.assign(Alchemy, { + // Global utility method for translating a given string + t: translate, + translations: Object.assign(Alchemy.translations || {}, translationData), + NodeTree, + fileEditors, + pictureEditors, + ImageLoader: ImageLoader.init, + ImageCropper, + IngredientAnchorLink, + Datepicker, + Sitemap, + Tinymce, + PagePublicationFields +}) diff --git a/package/src/__tests__/i18n.spec.js b/app/javascript/alchemy_admin/__tests__/i18n.spec.js similarity index 100% rename from package/src/__tests__/i18n.spec.js rename to app/javascript/alchemy_admin/__tests__/i18n.spec.js diff --git a/package/src/datepicker.js b/app/javascript/alchemy_admin/datepicker.js similarity index 100% rename from package/src/datepicker.js rename to app/javascript/alchemy_admin/datepicker.js diff --git a/package/src/file_editors.js b/app/javascript/alchemy_admin/file_editors.js similarity index 100% rename from package/src/file_editors.js rename to app/javascript/alchemy_admin/file_editors.js diff --git a/package/src/i18n.js b/app/javascript/alchemy_admin/i18n.js similarity index 100% rename from package/src/i18n.js rename to app/javascript/alchemy_admin/i18n.js diff --git a/package/src/image_cropper.js b/app/javascript/alchemy_admin/image_cropper.js similarity index 100% rename from package/src/image_cropper.js rename to app/javascript/alchemy_admin/image_cropper.js diff --git a/package/src/image_loader.js b/app/javascript/alchemy_admin/image_loader.js similarity index 100% rename from package/src/image_loader.js rename to app/javascript/alchemy_admin/image_loader.js diff --git a/package/src/ingredient_anchor_link.js b/app/javascript/alchemy_admin/ingredient_anchor_link.js similarity index 100% rename from package/src/ingredient_anchor_link.js rename to app/javascript/alchemy_admin/ingredient_anchor_link.js diff --git a/package/src/node_tree.js b/app/javascript/alchemy_admin/node_tree.js similarity index 100% rename from package/src/node_tree.js rename to app/javascript/alchemy_admin/node_tree.js diff --git a/package/src/page_publication_fields.js b/app/javascript/alchemy_admin/page_publication_fields.js similarity index 100% rename from package/src/page_publication_fields.js rename to app/javascript/alchemy_admin/page_publication_fields.js diff --git a/package/src/page_sorter.js b/app/javascript/alchemy_admin/page_sorter.js similarity index 100% rename from package/src/page_sorter.js rename to app/javascript/alchemy_admin/page_sorter.js diff --git a/package/src/picture_editors.js b/app/javascript/alchemy_admin/picture_editors.js similarity index 100% rename from package/src/picture_editors.js rename to app/javascript/alchemy_admin/picture_editors.js diff --git a/package/src/sitemap.js b/app/javascript/alchemy_admin/sitemap.js similarity index 100% rename from package/src/sitemap.js rename to app/javascript/alchemy_admin/sitemap.js diff --git a/package/src/tinymce.js b/app/javascript/alchemy_admin/tinymce.js similarity index 100% rename from package/src/tinymce.js rename to app/javascript/alchemy_admin/tinymce.js diff --git a/package/src/translations.js b/app/javascript/alchemy_admin/translations.js similarity index 100% rename from package/src/translations.js rename to app/javascript/alchemy_admin/translations.js diff --git a/package/src/utils/__tests__/ajax.spec.js b/app/javascript/alchemy_admin/utils/__tests__/ajax.spec.js similarity index 100% rename from package/src/utils/__tests__/ajax.spec.js rename to app/javascript/alchemy_admin/utils/__tests__/ajax.spec.js diff --git a/package/src/utils/__tests__/events.spec.js b/app/javascript/alchemy_admin/utils/__tests__/events.spec.js similarity index 100% rename from package/src/utils/__tests__/events.spec.js rename to app/javascript/alchemy_admin/utils/__tests__/events.spec.js diff --git a/package/src/utils/ajax.js b/app/javascript/alchemy_admin/utils/ajax.js similarity index 100% rename from package/src/utils/ajax.js rename to app/javascript/alchemy_admin/utils/ajax.js diff --git a/package/src/utils/events.js b/app/javascript/alchemy_admin/utils/events.js similarity index 100% rename from package/src/utils/events.js rename to app/javascript/alchemy_admin/utils/events.js diff --git a/app/views/layouts/alchemy/admin.html.erb b/app/views/layouts/alchemy/admin.html.erb index e26e1aad8c..eeb4da2915 100644 --- a/app/views/layouts/alchemy/admin.html.erb +++ b/app/views/layouts/alchemy/admin.html.erb @@ -34,7 +34,7 @@ <%= render 'alchemy/admin/partials/routes' %> <%= javascript_include_tag('alchemy/admin/all', 'data-turbolinks-track' => true) %> - <%= javascript_importmap_tags("@alchemy_cms/admin", importmap: Alchemy.importmap) %> + <%= javascript_importmap_tags("alchemy_admin", importmap: Alchemy.importmap) %> <%= yield :javascript_includes %> <%= content_tag :body, id: 'alchemy', class: alchemy_body_class do %> diff --git a/config/importmap.rb b/config/importmap.rb index 1f84ec32d0..96b2f5558b 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -3,4 +3,4 @@ pin "lodash-es/max", to: "https://ga.jspm.io/npm:lodash-es@4.17.21/max.js", preload: true pin "sortablejs", to: "https://ga.jspm.io/npm:sortablejs@1.15.0/modular/sortable.esm.js", preload: true -pin "@alchemy_cms/admin", to: "admin.js", preload: true +pin "alchemy_admin", to: "alchemy_admin.js", preload: true diff --git a/lib/alchemy/engine.rb b/lib/alchemy/engine.rb index 4e4ebf80ba..cf64f29259 100644 --- a/lib/alchemy/engine.rb +++ b/lib/alchemy/engine.rb @@ -23,7 +23,7 @@ class Engine < Rails::Engine initializer "alchemy.importmap" do |app| Alchemy.importmap.draw(Engine.root.join("config", "importmap.rb")) - package_path = Engine.root.join("package") + package_path = Engine.root.join("app/javascript") app.config.assets.paths << package_path if app.config.importmap.sweep_cache diff --git a/package.json b/package.json index e29a32d317..3e1b8c99ed 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@alchemy_cms/admin", + "name": "alchemy_admin", "scripts": { "test": "jest" }, @@ -22,7 +22,7 @@ "Alchemy": {} }, "roots": [ - "package" + "app/javascript/alchemy_admin" ] } } diff --git a/package/admin.js b/package/admin.js deleted file mode 100644 index b53c7c2475..0000000000 --- a/package/admin.js +++ /dev/null @@ -1,34 +0,0 @@ -import translate from "./src/i18n" -import translationData from "./src/translations" -import NodeTree from "./src/node_tree" -import fileEditors from "./src/file_editors" -import IngredientAnchorLink from "./src/ingredient_anchor_link" -import pictureEditors from "./src/picture_editors" -import ImageLoader from "./src/image_loader" -import ImageCropper from "./src/image_cropper" -import Datepicker from "./src/datepicker" -import Sitemap from "./src/sitemap" -import Tinymce from "./src/tinymce" -import PagePublicationFields from "./src/page_publication_fields.js" - -// Global Alchemy object -if (typeof window.Alchemy === "undefined") { - window.Alchemy = {} -} - -// Enhance the global Alchemy object with imported features -Object.assign(Alchemy, { - // Global utility method for translating a given string - t: translate, - translations: Object.assign(Alchemy.translations || {}, translationData), - NodeTree, - fileEditors, - pictureEditors, - ImageLoader: ImageLoader.init, - ImageCropper, - IngredientAnchorLink, - Datepicker, - Sitemap, - Tinymce, - PagePublicationFields -})