2024-09-17 18:59:38 +02:00
|
|
|
if( AFRAME.components.codemirror ) delete AFRAME.components.codemirror
|
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
AFRAME.registerComponent('codemirror', {
|
|
|
|
schema: {
|
2024-09-23 16:58:48 +02:00
|
|
|
file: { type:"string"},
|
|
|
|
term: { type:"selector", default: "[isoterminal]" },
|
2024-10-24 16:57:54 +02:00
|
|
|
width: { type:"number", default:700},
|
|
|
|
height: { type:"number", default:500},
|
2024-09-16 13:28:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
init: function () {
|
|
|
|
this.el.object3D.visible = false
|
2024-09-23 16:58:48 +02:00
|
|
|
if( !this.data.term || !this.data.term.components ) throw 'codemirror cannot get isoterminal'
|
|
|
|
if( this.data.file && this.data.file[0] != '/'){
|
|
|
|
this.data.file = "root/"+this.data.file
|
|
|
|
}
|
2024-10-15 12:32:16 +02:00
|
|
|
this.isoterminal = this.data.term.components.isoterminal.term
|
2024-09-16 13:28:28 +02:00
|
|
|
//this.el.innerHTML = ` `
|
|
|
|
this.requireAll()
|
|
|
|
},
|
|
|
|
|
|
|
|
requireAll: async function(){
|
|
|
|
let s = await AFRAME.utils.require(this.requires)
|
|
|
|
setTimeout( () => this.el.setAttribute("dom",""), 300 )
|
|
|
|
},
|
|
|
|
|
|
|
|
requires:{
|
2024-09-23 16:58:48 +02:00
|
|
|
window: "com/window.js"
|
2024-09-16 13:28:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
dom: {
|
|
|
|
scale: 0.5,
|
|
|
|
events: ['click','keydown'],
|
|
|
|
html: (me) => `<div class="codemirror">
|
|
|
|
</div>`,
|
|
|
|
|
2024-10-18 13:50:56 +02:00
|
|
|
css: (me) => `.CodeMirror{
|
|
|
|
width: ${me.com.data.width}px !important;
|
2024-10-23 18:50:07 +02:00
|
|
|
height: ${me.com.data.height-30}px !important;
|
2024-09-16 13:28:28 +02:00
|
|
|
}
|
2024-09-17 18:59:38 +02:00
|
|
|
.codemirror *{
|
|
|
|
font-size: 14px;
|
|
|
|
font-family: "Cousine",Liberation Mono,DejaVu Sans Mono,Courier New,monospace;
|
|
|
|
font-weight:500 !important;
|
|
|
|
letter-spacing: 0 !important;
|
|
|
|
text-shadow: 0px 0px 10px #F075;
|
|
|
|
}
|
2024-10-23 18:50:07 +02:00
|
|
|
|
|
|
|
.wb-body:has(> .codemirror){
|
|
|
|
overflow:hidden;
|
|
|
|
}
|
2024-10-18 13:50:56 +02:00
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
.CodeMirror {
|
|
|
|
margin-top:18px;
|
|
|
|
}
|
|
|
|
.cm-s-shadowfox.CodeMirror {
|
|
|
|
background:transparent !important;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
},
|
|
|
|
|
2024-09-23 16:58:48 +02:00
|
|
|
createEditor: function(value){
|
2024-10-18 13:50:56 +02:00
|
|
|
this.el.setAttribute("window", `title: codemirror; uid: ${this.el.dom.id}; attach: #overlay; dom: #${this.el.dom.id}; width: ${this.data.width}px; height: ${this.data.height}px`)
|
2024-09-23 16:58:48 +02:00
|
|
|
this.editor = CodeMirror( this.el.dom, {
|
|
|
|
value,
|
|
|
|
mode: "htmlmixed",
|
|
|
|
lineNumbers: true,
|
|
|
|
styleActiveLine: true,
|
|
|
|
matchBrackets: true,
|
|
|
|
Tab: "indentMore",
|
|
|
|
defaultTab: function(cm) {
|
|
|
|
if (cm.somethingSelected()) cm.indentSelection("add");
|
|
|
|
else cm.replaceSelection(" ", "end");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.editor.setOption("theme", "shadowfox")
|
2024-10-18 13:50:56 +02:00
|
|
|
this.editor.updateFile = AFRAME.utils.throttle( (file,str) => {
|
|
|
|
this.updateFile(file,str)
|
|
|
|
}, 1500)
|
2024-09-23 16:58:48 +02:00
|
|
|
this.editor.on('change', (instance,changeObj) => {
|
|
|
|
this.editor.updateFile( this.data.file, instance.getValue() )
|
|
|
|
})
|
|
|
|
|
2024-10-23 18:50:07 +02:00
|
|
|
this
|
|
|
|
.handleFocus()
|
|
|
|
|
2024-09-23 16:58:48 +02:00
|
|
|
setTimeout( () => {
|
|
|
|
this.el.setAttribute("html-as-texture-in-xr", `domid: #${this.el.dom.id}`) // only show aframe-html in xr
|
|
|
|
},1500)
|
|
|
|
},
|
|
|
|
|
2024-10-23 18:50:07 +02:00
|
|
|
handleFocus: function(){
|
|
|
|
const focus = (showdom) => (e) => {
|
|
|
|
if( this.editor ){
|
|
|
|
this.editor.focus()
|
|
|
|
}
|
|
|
|
if( this.el.components.window && this.data.renderer == 'canvas'){
|
|
|
|
this.el.components.window.show( showdom )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.el.addEventListener('obbcollisionstarted', focus(false) )
|
|
|
|
this.el.sceneEl.addEventListener('enter-vr', focus(false) )
|
|
|
|
this.el.sceneEl.addEventListener('enter-ar', focus(false) )
|
|
|
|
this.el.sceneEl.addEventListener('exit-vr', focus(true) )
|
|
|
|
this.el.sceneEl.addEventListener('exit-ar', focus(true) )
|
|
|
|
},
|
|
|
|
|
2024-09-23 16:58:48 +02:00
|
|
|
updateFile: async function(file,str){
|
|
|
|
// we don't do via shellcmd: isoterminal.exec(`echo '${str}' > ${file}`,1)
|
|
|
|
// as it would require all kindof ugly stringescaping
|
|
|
|
console.log("updating "+file)
|
2024-11-01 17:39:56 +01:00
|
|
|
await this.isoterminal.worker.update_file(file, this.isoterminal.convert.toUint8Array(str) )
|
2024-09-23 16:58:48 +02:00
|
|
|
},
|
|
|
|
|
2024-09-16 13:28:28 +02:00
|
|
|
events:{
|
|
|
|
|
|
|
|
// component events
|
|
|
|
DOMready: function(e){
|
2024-10-15 12:32:16 +02:00
|
|
|
|
2024-11-01 17:39:56 +01:00
|
|
|
this.isoterminal.worker.read_file(this.data.file)
|
2024-09-23 16:58:48 +02:00
|
|
|
.then( this.isoterminal.convert.Uint8ArrayToString )
|
|
|
|
.then( (str) => {
|
2024-10-15 12:32:16 +02:00
|
|
|
console.log("creating editor")
|
2024-09-23 16:58:48 +02:00
|
|
|
this.createEditor( str )
|
|
|
|
})
|
|
|
|
.catch( (e) => {
|
|
|
|
console.log("error opening "+this.data.file+", creating new one")
|
|
|
|
this.createEditor("")
|
2024-09-16 13:28:28 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
manifest: { // HTML5 manifest to identify app to xrsh
|
|
|
|
"short_name": "Paste",
|
|
|
|
"name": "Paste",
|
|
|
|
"icons": [
|
|
|
|
{
|
|
|
|
"src": "https://css.gg/clipboard.svg",
|
|
|
|
"type": "image/svg+xml",
|
|
|
|
"sizes": "512x512"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"id": "/?source=pwa",
|
|
|
|
"start_url": "/?source=pwa",
|
|
|
|
"background_color": "#3367D6",
|
|
|
|
"display": "standalone",
|
|
|
|
"scope": "/",
|
|
|
|
"theme_color": "#3367D6",
|
|
|
|
"shortcuts": [
|
|
|
|
{
|
|
|
|
"name": "What is the latest news?",
|
|
|
|
"cli":{
|
|
|
|
"usage": "helloworld <type> [options]",
|
|
|
|
"example": "helloworld news",
|
|
|
|
"args":{
|
|
|
|
"--latest": {type:"string"}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"short_name": "Today",
|
|
|
|
"description": "View weather information for today",
|
|
|
|
"url": "/today?source=pwa",
|
|
|
|
"icons": [{ "src": "/images/today.png", "sizes": "192x192" }]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"description": "Paste the clipboard",
|
|
|
|
"screenshots": [
|
|
|
|
{
|
|
|
|
"src": "/images/screenshot1.png",
|
|
|
|
"type": "image/png",
|
|
|
|
"sizes": "540x720",
|
|
|
|
"form_factor": "narrow"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"help":`
|
|
|
|
Helloworld application
|
|
|
|
|
|
|
|
This is a help file which describes the application.
|
|
|
|
It will be rendered thru troika text, and will contain
|
|
|
|
headers based on non-punctualized lines separated by linebreaks,
|
|
|
|
in above's case "\nHelloworld application\n" will qualify as header.
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|