import { useSignal, signal, useComputed, batch, effect } from '@preact/signals' import { TreeView, EXAMPLE_TREE } from '@/client/components/TreeView.jsx' import { Editor } from '@/client/components/Editor.jsx' import clsx from 'clsx' import { useEffect, useState } from 'preact/hooks' import { fetchJson } from '../utils.js' import { Terminal } from './Terminal.jsx' function ensurePrefix(s, prefix) { return s.slice(0, prefix.length) === prefix ? s : prefix + s } function stripPrefix(s, prefix) { return s.slice(0, prefix.length) === prefix ? s.slice(prefix.length) : s } function clamp(min, value, max) { return Math.max(min, Math.min(value, max)) } export const Ide = ({}) => { const ws = useSignal(null) const uuid = useSignal(null) useEffect(() => { ws.value = new WebSocket(`ws://${location.host}/api/docker/node:current-alpine/pty`) ws.value.addEventListener('message', e => { const event = JSON.parse(e.data) if (event.type === 'created') { uuid.value = event.id history.pushState(event.id, '', '/@container/' + event.id) } }) }, []) if (!uuid.value) return <>Creating container...> const activeTab = useSignal(null) const tabs = useSignal([ // { // id: '/project/main.c', // content: signal('...main.c...'), // }, // { // id: '/project/data.csv', // content: signal('...data.csv...'), // }, ]) const activePath = useComputed(() => { if (activeTab.value === null) return null return tabs.value[activeTab.value].id }) const activeContent = useComputed(() => { if (activeTab.value === null) return null return tabs.value[activeTab.value].content }) effect(() => { const path = activePath.value const contentSig = activeContent.value if (contentSig === null || path === null) return console.log(path, contentSig.value) }) return (