-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow the Stanford example for selectively importing the ace editor - …
…sul-dlss/purl#765 - Use stimilus to activate the editor on connect() with a data-controller. This allows us to appropiately use ImportMap, ditch public/ace, and have everything work with turbo with no need for a hard load.
- Loading branch information
Showing
13 changed files
with
53 additions
and
25,482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.4.3 | ||
2.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails | ||
// This is just for preview to separate out its JS imports. | ||
import "preview_controllers" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Import and register all your controllers from the importmap under controllers/* | ||
|
||
import { application } from "preview_controllers/application" | ||
|
||
// Eager load all controllers defined in the import map under controllers/**/*_controller | ||
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" | ||
eagerLoadControllersFrom("preview_controllers", application) | ||
|
||
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) | ||
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" | ||
// lazyLoadControllersFrom("controllers", application) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import ace from 'ace-builds'; | ||
|
||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
connect() { | ||
ace.config.set('basePath', 'https://cdn.jsdelivr.net/npm/[email protected]/src-noconflict/'); | ||
var editor = ace.edit("editor"); | ||
editor.setTheme("ace/theme/eclipse"); | ||
editor.session.setMode("ace/mode/xml"); | ||
|
||
document.querySelector('#editor').addEventListener('change', (event) => { | ||
//$("#raw_xml").val(editor.getSession().getValue().trim()); | ||
document.getElementById("raw_xml").value = editor.getSession().getValue().trim(); | ||
}); | ||
|
||
document.getElementById('validate_button').onclick = function(){ | ||
$("#content").css({visibility:"visible", opacity: 100}).animate({opacity: 0}, 500); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,9 @@ | |
pin "@github/auto-complete-element", to: "https://cdn.skypack.dev/@github/auto-complete-element" | ||
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/[email protected]/dist/umd/popper.min.js" | ||
pin "bootstrap", to: "https://ga.jspm.io/npm:[email protected]/dist/js/bootstrap.js" | ||
pin "ace-builds", to: "https://ga.jspm.io/npm:[email protected]/src-noconflict/ace.js" | ||
|
||
pin_all_from "app/javascript/cerberus", under: "cerberus" | ||
pin_all_from "app/javascript/preview_controllers", under: "preview_controllers" | ||
# Preview is a separate application to avoid loading ace-builds for every page | ||
pin 'preview_application' |
Oops, something went wrong.