Skip to content

Commit

Permalink
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core
Browse files Browse the repository at this point in the history
… into gh-pages
  • Loading branch information
onsetsu committed Dec 16, 2023
2 parents 58668a3 + 30fb40c commit d27d7be
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 10 deletions.
75 changes: 75 additions & 0 deletions demos/tree-sitter/codemirror.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Code Mirror Shards Sandblocks Proof of Concept

## Issues:

- [ ] (cursor in/out)
- [ ] keep focus while typing
- [X] hide line numbers
- [X] hide scrollbars
- [ ] update RegExp match while editing


## Probe Example

<script>

customElements.define(
"probe-widget",
class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.addEventListener("keyup", evt => {
// evt.preventDefault()
// evt.stopPropagation()
})

this.addEventListener("keydown", evt => {
// evt.preventDefault()
// evt.stopPropagation()
})
this.shadowRoot.innerHTML = `
<div style="border: 1px solid gray">PROBE
<lively-code-mirror class="shard"></lively-code-mirror>
<slot></slot></div>
`;
}
})


var outerLivelyCodeMirror = await (<lively-code-mirror></lively-code-mirror>)
outerLivelyCodeMirror.value = `var a = probe(3 + 4)`


var debugLivelyCodeMirror = await (<lively-code-mirror></lively-code-mirror>)
debugLivelyCodeMirror.editor.swapDoc(outerLivelyCodeMirror.editor.linkedDoc())

var regEx = new RegExp(/((probe\()(.*))\)/, "g");
do {
var m = regEx.exec(outerLivelyCodeMirror.value);
if (m) {
var from = m.index
var to = m.index + m[0].length


var innerFrom = m.index + m[2].length
var innerTo = m.index + m[1].length
var editor = outerLivelyCodeMirror.editor

var comp = await outerLivelyCodeMirror.wrapWidget("probe-widget",
editor.posFromIndex(from),
editor.posFromIndex(to))

var innerLivelyCodeMirror = comp.shadowRoot.querySelector("lively-code-mirror")
innerLivelyCodeMirror.editor.swapDoc(editor.linkedDoc())
const opts = {collapsed: true, clearWhenEmpty: false, inclusiveLeft: false, inclusiveRight: true};
innerLivelyCodeMirror.editor.getDoc().markText(editor.posFromIndex(-1), editor.posFromIndex(innerFrom), opts);
innerLivelyCodeMirror.editor.getDoc().markText(editor.posFromIndex(innerTo), editor.posFromIndex(innerLivelyCodeMirror.value.length), opts);


debugger
}
} while (m);

(<div>{outerLivelyCodeMirror}DEBUG:{debugLivelyCodeMirror}</div>)
</script>
8 changes: 8 additions & 0 deletions doc/journal/2023-12-14.md/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## 2023-12-14 Tom's Window Wishlist for Christmas
*Author: @JensLincke*


- [ ] alt+drag on window moves it
- [ ] open window attached to cursor (centered around cursor)
- [ ] attached window can be resize via press down and drag
- [ ] scale in directions
53 changes: 53 additions & 0 deletions src/client/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {Logging} from "src/client/morphic/component-loader.js"

var debugCounterByClass = new Map()
var debugPrintMap = new WeakMap() // obj -> string
var debugPrintReverseMap = new Map() // string -> obj

// for debugging WeakRefs....
// var debugReg = new FinalizationRegistry(value => console.warn('COLLECTED: ' + value))

/*globals WeakRef */

export {Logging}

function debugPrint(element) {
var print = debugPrintMap.get(element)
if (!print) {
var className = element.constructor.name
var counter = debugCounterByClass.get(className) || 0
counter++
debugCounterByClass.set(className, counter)
print = className + counter
debugPrintMap.set(element, print)
debugSet(print, element)
}
return print
}

export function debugGet(name) {
let ref = debugPrintReverseMap.get(name)
return ref && ref.deref()
}

// debugGet("sb-block61")


// let obj = document.body

export function debugSet(name, obj) {
let ref = new WeakRef(obj)
// debugReg.register(obj, name)
return debugPrintReverseMap.set(name, ref)
}

Logging.enable()

Logging.setLog((element, ...args) => {

if (element && element instanceof HTMLElement ) {
console.log(debugPrint(element), ...args)
}
})


28 changes: 22 additions & 6 deletions src/client/morphic/component-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ var _log = function(...args) {
}
}

export class Logging {
static enable() {
_loggingEnabled = true
}
static disable() {
_loggingEnabled = false
}

static setLog(func) {
_log = function(...args) {
if (_loggingEnabled) {
func(...args)
}
}
}
}

var _timeEnabled = false
var _timeLog = function(name, msg, ...args) {
if (_timeEnabled) {
Expand Down Expand Up @@ -575,9 +592,8 @@ window.customElements.define = function define(componentName, aClass) {
proxy = class extends HTMLElement {

constructor(...args) {
_log("[component loader] Proxy Constructor " + componentName)

super(...args); // always call super() first in the constructor.
_log(this, "[component loader] Proxy Constructor " + componentName)

ComponentLoader.applyTemplate(this, componentName)
ComponentLoader.onCreatedCallback(this, componentName)
Expand All @@ -592,25 +608,25 @@ window.customElements.define = function define(componentName, aClass) {
}
// We need to declare these callbacks, because they are early bound...
connectedCallback( args) {
_log('connectedCallback ' + componentName )
_log(this, 'connectedCallback ' + componentName )
if (this.constructor.__proto__.prototype.connectedCallback) {
return this.constructor.__proto__.prototype.connectedCallback.apply(this, args)
}
}
disconnectedCallback(...args) {
_log('disconnectedCallback ' + componentName )
_log(this,'disconnectedCallback ' + componentName )
if (this.constructor.__proto__.prototype.disconnectedCallback) {
return this.constructor.__proto__.prototype.disconnectedCallback.apply(this, args)
}
}
attributeChangedCallback(...args) {
_log('attributeChangedCallback ' + componentName )
_log(this, 'attributeChangedCallback ' + componentName )
if (this.constructor.__proto__.prototype.attributeChangedCallback) {
return this.constructor.__proto__.prototype.attributeChangedCallback.apply(this, args)
}
}
adoptedCallback(...args) {
_log('adoptedCallback ' + componentName )
_log(this,'adoptedCallback ' + componentName )
if (this.constructor.__proto__.prototype.adoptedCallback) {
return this.constructor.__proto__.prototype.adoptedCallback.apply(this, args)
}
Expand Down
9 changes: 5 additions & 4 deletions src/components/tools/sandblocks-editor.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import "src/client/tree-sitter.js"
import {Parser} from "src/client/tree-sitter.js"
window.TreeSitter = Parser

// while in dev, we keep sandblocks in a separate git repo
import "../../../../sandblocks-text/md5.js"
import "../../../../sandblocks-text/external/md5.js"


import {setConfig} from "../../../../sandblocks-text/model.js"
import "../../../../sandblocks-text/main.js"

// // initialize language....
var baseDir = lively4url + "/../sandblocks-text/"
setConfig({baseURL: baseDir})

await System.import(baseDir + "/main.js");

import Morph from 'src/components/widgets/lively-morph.js';

Expand Down Expand Up @@ -57,7 +58,7 @@ export default class SandblocksEditor extends Morph {
async setText(source) {

var ui = await (
<sb-extension-scope enable="smalltalkTools" disable="">
<sb-extension-scope extensions="javascriptBase javascriptOutline javascriptWorkspace base identifierSuggestions editorConfig">
<sb-editor text={source} language="javascript"></sb-editor>
</sb-extension-scope>)

Expand Down
10 changes: 10 additions & 0 deletions src/components/widgets/lively-code-mirror.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@
overflow: hidden;
}


:host(.shard) .CodeMirror-gutters {
display: none
}

:host(.shard) .CodeMirror-gutter-wrapper {
display: none
}


</style>
<style id="customStyle"></style>

Expand Down

0 comments on commit d27d7be

Please sign in to comment.