-
Notifications
You must be signed in to change notification settings - Fork 7
WIP: Add readonly, min-height attributes and faust-editor-basic "passive" variant #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Simon-L
wants to merge
13
commits into
grame-cncm:main
Choose a base branch
from
Simon-L:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8465f4d
Add passive attribute for read-only editor
164d7db
Update
accb8bd
Fix typo in CSS
a76b306
Use minHeight attribute when starting dsp
82ea781
Rename attribute from passive to readonly. Update demo in index.html
35198fd
Handle environment variable FAUST_WEB_BASIC to build only basic variant
006b817
Update README.md
681e15e
Nit
0f4b74f
Always build twice to generate both variants, this is a workaround
fa2adeb
Update readme
26f6753
Nit: remove unneeded logging, unused args and fix comparison operators
476466a
Use CM readOnly facet instead of editable. Check clipboard at templat…
d98d7d3
Nit: normalize readonly naming
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,171 @@ | ||
import { icon } from "@fortawesome/fontawesome-svg-core" | ||
import faustCSS from "@shren/faust-ui/dist/esm/index.css?inline" | ||
import { createEditor, setError, clearError } from "./editor" | ||
import faustSvg from "./faustText.svg" | ||
|
||
function editorTemplate(minHeight: string = "") { | ||
const editorMinHeight = minHeight != "" ? `min-height: ${minHeight};` : "" | ||
const template = document.createElement("template") | ||
let copyButton = `<button title="Copy" class="button" id="copy">${icon({ prefix: "fas", iconName: "copy" }).html[0]}</button>` | ||
if (!navigator.clipboard) { | ||
console.log("Unable to use clipboard") | ||
copyButton = "" | ||
} | ||
template.innerHTML = ` | ||
<div id="root"> | ||
<div id="controls"> | ||
<a title="Open in Faust IDE" id="ide" href="https://faustide.grame.fr/" class="button" target="_blank">${icon({ prefix: "fas", iconName: "up-right-from-square" }).html[0]}</a> | ||
${copyButton} | ||
<a title="Faust website" id="faust" href="https://faust.grame.fr/" target="_blank"><img src="${faustSvg}" height="15px" /></a> | ||
</div> | ||
<div id="content"> | ||
<div id="editor"></div> | ||
</div> | ||
</div> | ||
<style> | ||
#root { | ||
overflow:hidden; | ||
border: 1px solid black; | ||
border-radius: 5px; | ||
box-sizing: border-box; | ||
} | ||
|
||
*, *:before, *:after { | ||
box-sizing: inherit; | ||
} | ||
|
||
#controls { | ||
background-color: #384d64; | ||
border-bottom: 1px solid black; | ||
display: flex; | ||
} | ||
|
||
#faust { | ||
margin-left: auto; | ||
margin-right: 10px; | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
#content { | ||
display: flex; | ||
} | ||
|
||
#editor { | ||
flex-grow: 1; | ||
overflow-y: auto; | ||
} | ||
|
||
#editor .cm-editor { | ||
height: 100%; | ||
${minHeight != "" ? `min-height: ${minHeight};` : ""} | ||
} | ||
|
||
.cm-diagnostic { | ||
font-family: monospace; | ||
} | ||
|
||
.cm-diagnostic-error { | ||
background-color: #fdf2f5 !important; | ||
color: #a4000f !important; | ||
border-color: #a4000f !important; | ||
} | ||
|
||
a.button { | ||
appearance: button; | ||
} | ||
|
||
.button { | ||
background-color: #384d64; | ||
border: 0; | ||
padding: 5px; | ||
width: 25px; | ||
height: 25px; | ||
color: #fff; | ||
} | ||
|
||
.button:hover { | ||
background-color: #4b71a1; | ||
} | ||
|
||
.button:active { | ||
background-color: #373736; | ||
} | ||
|
||
.button:disabled { | ||
opacity: 0.65; | ||
cursor: not-allowed; | ||
pointer-events: none; | ||
} | ||
|
||
#controls > .button > svg { | ||
width: 15px; | ||
height: 15px; | ||
vertical-align: top; | ||
} | ||
|
||
${faustCSS} | ||
</style> | ||
` | ||
return template | ||
} | ||
|
||
export default class FaustEditorBasic extends HTMLElement { | ||
constructor() { | ||
super() | ||
} | ||
|
||
readonly = false | ||
minHeight = null | ||
editor = null | ||
|
||
getCodeString() { | ||
return this.editor.state.doc.toString() | ||
} | ||
|
||
setCode(code) { | ||
this.editor.dispatch({ | ||
changes: {from: 0, to: this.editor.state.doc.length, insert: code} | ||
}) | ||
} | ||
|
||
connectedCallback() { | ||
const code = this.innerHTML.replace("<!--", "").replace("-->", "").trim() | ||
this.attachShadow({ mode: "open" }).appendChild(editorTemplate(this.minHeight).content.cloneNode(true)) | ||
|
||
const ideLink = this.shadowRoot!.querySelector("#ide") as HTMLAnchorElement | ||
ideLink.onfocus = () => { | ||
// Open current contents of editor in IDE | ||
const urlParams = new URLSearchParams() | ||
urlParams.set("inline", btoa(editor.state.doc.toString()).replace("+", "-").replace("/", "_")) | ||
ideLink.href = `https://faustide.grame.fr/?${urlParams.toString()}` | ||
} | ||
|
||
const editorEl = this.shadowRoot!.querySelector("#editor") as HTMLDivElement | ||
const editor = createEditor(editorEl, code, this.readonly) | ||
|
||
const copyButton = this.shadowRoot!.querySelector("#copy") as HTMLButtonElement | ||
|
||
if (copyButton !== null) { | ||
copyButton.onclick = () => { | ||
navigator.clipboard.writeText(editor.state.doc.toString()) | ||
} | ||
} | ||
|
||
this.editor = editor | ||
} | ||
|
||
attributeChangedCallback(name, oldValue, newValue) { | ||
if ((name === "readonly") && (newValue !== null)) { | ||
this.readonly = true | ||
} | ||
if ((name === "min-height") && (newValue !== "")) { | ||
this.minHeight = newValue | ||
} | ||
} | ||
|
||
static get observedAttributes() { | ||
return ["readonly", "min-height"]; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to reduce duplication between this module and
faust-editor.ts
. Perhaps the shared CSS could be moved out to a common module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep that for a later task/PR