add thought

This commit is contained in:
“chrisshank” 2024-10-16 13:41:25 -07:00
parent fa4bc138b7
commit a52b7f4133
2 changed files with 25 additions and 1 deletions

View File

@ -14,11 +14,16 @@
}
body {
min-height: 100%;
height: 100%;
position: relative;
margin: 0;
}
main {
height: 100%;
width: 100%;
}
spatial-connection {
display: block;
position: absolute;

View File

@ -24,6 +24,10 @@ interface ChainOfThought {
const html = String.raw;
function parseHTML(html: string): Element {
return document.createRange().createContextualFragment(html).firstElementChild!;
}
function renderThought(thought: Thought) {
return html` <spatial-geometry data-id="${thought.id}" x="${thought.x}" y="${thought.y}" width="200" height="100">
<textarea>${thought.text}</textarea>
@ -62,6 +66,21 @@ const saveAsButton = document.querySelector('button[name="save-as"]')!;
const main = document.querySelector('main')!;
const fileSaver = new FileSaver('chains-of-thought', 'json', 'application/json');
main.addEventListener('dblclick', (e) => {
if (e.target === main) {
const spatialGeometry = parseHTML(
renderThought({
id: String(document.querySelectorAll('spatial-geometry').length + 1),
text: '',
x: e.clientX,
y: e.clientY,
})
);
main.appendChild(spatialGeometry);
spatialGeometry.querySelector('textarea')?.focus();
}
});
async function openFile(showPicker = true) {
try {
const text = await fileSaver.open(showPicker);