Skip to content

Commit

Permalink
unify importmap and npm use on 'blacklight-frontend', modernize packa…
Browse files Browse the repository at this point in the history
…ge.json with exports
  • Loading branch information
jrochkind committed Oct 18, 2024
1 parent da60832 commit f1f881e
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CheckboxSubmit from 'blacklight/checkbox_submit'
import CheckboxSubmit from 'blacklight-frontend/checkbox_submit'

const BookmarkToggle = (e) => {
if (e.target.matches('[data-checkboxsubmit-target="checkbox"]')) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debounce from "blacklight/debounce";
import debounce from "blacklight-frontend/debounce";

const FacetSuggest = async (e) => {
if (e.target.matches('.facet-suggest')) {
Expand All @@ -11,9 +11,9 @@ const FacetSuggest = async (e) => {
if (response.ok) {
const blob = await response.blob()
const text = await blob.text()

const facetArea = document.querySelector('.facet-extended-list');

if (text && facetArea) {
facetArea.innerHTML = text
}
Expand Down
16 changes: 16 additions & 0 deletions app/javascript/blacklight-frontend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import BookmarkToggle from 'blacklight-frontend/bookmark_toggle'
import ButtonFocus from 'blacklight-frontend/button_focus'
import FacetSuggest from 'blacklight-frontend/facet_suggest'
import Modal from 'blacklight-frontend/modal'
import SearchContext from 'blacklight-frontend/search_context'
import Core from 'blacklight-frontend/core'

export default {
BookmarkToggle,
ButtonFocus,
FacetSuggest,
Modal,
SearchContext,
Core,
onLoad: Core.onLoad
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
can be a turbo-stream that defines some HTML fragementsand where on the page to put them:
https://turbo.hotwired.dev/handbook/streams
*/
import ModalForm from 'blacklight/modalForm'
import ModalForm from 'blacklight-frontend/modalForm'

const Modal = (() => {
const modal = {}
Expand Down Expand Up @@ -111,7 +111,7 @@ const Modal = (() => {
}
elements.forEach((el) => frag.appendChild(el))
modal.activateScripts(frag)

document.querySelector(`${modal.modalSelector} .modal-content`).replaceChildren(frag)

modal.show();
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions app/javascript/blacklight/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

pin_all_from File.expand_path("../app/javascript/blacklight", __dir__), under: "blacklight"
pin_all_from File.expand_path("../app/javascript/blacklight-frontend", __dir__), under: "blacklight-frontend"
2 changes: 1 addition & 1 deletion lib/generators/blacklight/assets/importmap_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def append_blacklight_javascript
append_to_file 'app/javascript/application.js' do
<<~CONTENT
import githubAutoCompleteElement from "@github/auto-complete-element"
import Blacklight from "blacklight"
import Blacklight from "blacklight-frontend"
CONTENT
end
end
Expand Down
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
"name": "blacklight-frontend",
"version": "9.0.0-alpha",
"description": "The frontend code and styles for Blacklight",
"main": "app/assets/javascripts/blacklight",
"module": "app/assets/javascripts/blacklight/blacklight.esm.js",

"exports": {
"./blacklight.esm.js": "./app/assets/javascripts/blacklight/blacklight.esm.js",
"./stylesheets/*": "./app/assets/stylesheets/blacklight/*",
".": {
"import": "./app/javascript/blacklight-frontend/index.js",
"require": "./app/assets/javascripts/blacklight.js"
},
"./*": "./app/javascript/blacklight-frontend/*.js"
},

"scripts": {
"prepare": "rollup --config rollup.config.js --sourcemap && ESM=true rollup --config rollup.config.js --sourcemap"
},
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let includePathOptions = {
};

const rollupConfig = {
input: path.resolve(__dirname, `app/javascript/blacklight/index.js`),
input: path.resolve(__dirname, `app/javascript/blacklight-frontend/index.js`),
output: {
file: path.resolve(__dirname, `app/assets/javascripts/blacklight/${fileDest}.js`),
format: ESM ? 'esm' : 'umd',
Expand Down

0 comments on commit f1f881e

Please sign in to comment.