@bigmistqke/whiteboard 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -18
- package/bin/whiteboard.ts +300 -71
- package/dist/bin/whiteboard.js +21 -0
- package/dist/client/runtime.js +132 -54
- package/dist/define.js +21 -2
- package/dist/plugins/callout/index.js +3 -1
- package/dist/plugins/callout/public/style.css +30 -0
- package/dist/plugins/chat/index.js +7 -4
- package/dist/plugins/chat/{client.js → public/client.js} +1 -1
- package/dist/plugins/chat/public/style.css +98 -0
- package/dist/plugins/code/index.js +3 -1
- package/dist/plugins/code/public/style.css +68 -0
- package/dist/plugins/comments/index.js +4 -5
- package/dist/plugins/comments/public/client.js +19 -0
- package/dist/plugins/comments/public/style.css +185 -0
- package/dist/plugins/details/index.js +7 -2
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/form/index.js +37 -8
- package/dist/plugins/form/public/style.css +126 -0
- package/dist/plugins/gallery/index.js +4 -3
- package/dist/plugins/gallery/public/client.js +1 -0
- package/dist/plugins/gallery/public/style.css +90 -0
- package/dist/plugins/grid/index.js +9 -3
- package/dist/plugins/grid/public/style.css +71 -0
- package/dist/plugins/iframe/index.js +13 -14
- package/dist/plugins/iframe/public/style.css +13 -0
- package/dist/plugins/index.js +7 -1
- package/dist/plugins/mermaid/index.js +3 -1
- package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +99 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/index.js +10 -9
- package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +12 -5
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +99 -0
- package/dist/plugins/window/README.md +29 -0
- package/dist/plugins/window/index.js +64 -0
- package/dist/solid/index.js +14 -11
- package/dist/src/auth.js +2 -1
- package/dist/src/client/page/base.css +1078 -199
- package/dist/src/client/page/main.js +188 -39
- package/dist/src/loader.js +14 -3
- package/dist/src/package.js +3 -6
- package/dist/src/pages/blocks.js +8 -13
- package/dist/src/pages/markdown.js +1 -1
- package/dist/src/pages/render.js +106 -20
- package/dist/src/pages/window.js +31 -0
- package/dist/src/public.js +24 -0
- package/dist/src/server.js +251 -23
- package/package.json +5 -2
- package/plugins/callout/index.ts +3 -1
- package/plugins/callout/public/style.css +30 -0
- package/plugins/chat/autosize.ts +43 -9
- package/plugins/chat/client.tsx +22 -5
- package/plugins/chat/index.ts +22 -8
- package/plugins/chat/public/style.css +98 -0
- package/plugins/claude-code/index.ts +49 -14
- package/plugins/code/diff.ts +28 -8
- package/plugins/code/index.ts +33 -21
- package/plugins/code/public/style.css +68 -0
- package/plugins/comments/client.ts +139 -71
- package/plugins/comments/index.ts +9 -7
- package/plugins/comments/public/style.css +185 -0
- package/plugins/details/index.ts +7 -2
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/index.ts +16 -3
- package/plugins/form/index.ts +75 -27
- package/plugins/form/public/style.css +126 -0
- package/plugins/gallery/client.tsx +9 -3
- package/plugins/gallery/index.ts +31 -9
- package/plugins/gallery/public/style.css +90 -0
- package/plugins/grid/index.ts +19 -5
- package/plugins/grid/public/style.css +71 -0
- package/plugins/iframe/index.ts +20 -23
- package/plugins/iframe/public/style.css +13 -0
- package/plugins/index.ts +20 -1
- package/plugins/mermaid/index.ts +7 -3
- package/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +66 -0
- package/plugins/steps/index.ts +127 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +105 -48
- package/plugins/terminal/host.ts +143 -35
- package/plugins/terminal/index.ts +84 -25
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +64 -13
- package/plugins/terminal/sizes.ts +16 -4
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +90 -30
- package/plugins/toc/index.ts +26 -10
- package/plugins/toc/public/style.css +99 -0
- package/plugins/window/README.md +29 -0
- package/plugins/window/index.ts +85 -0
- package/skills/whiteboard/SKILL.md +3 -1
- package/solid/index.tsx +24 -9
- package/src/auth.ts +28 -9
- package/src/client/forms.ts +74 -28
- package/src/client/markdown.ts +15 -4
- package/src/client/page/base.css +1078 -199
- package/src/client/page/elsewhere.ts +32 -15
- package/src/client/page/fresh.ts +91 -23
- package/src/client/page/hold.ts +11 -2
- package/src/client/page/live.ts +10 -6
- package/src/client/page/main.ts +124 -42
- package/src/client/page/orphans.ts +25 -10
- package/src/client/page/sort.ts +14 -4
- package/src/client/page/sticky.ts +11 -3
- package/src/client/page/theme.ts +11 -7
- package/src/client/page/waiting.ts +141 -34
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +17 -10
- package/src/client/runtime.ts +170 -40
- package/src/client/scroll.ts +14 -4
- package/src/client/toast.ts +19 -5
- package/src/config.ts +20 -5
- package/src/define.ts +119 -31
- package/src/events.ts +111 -24
- package/src/html.ts +6 -2
- package/src/icons.ts +4 -2
- package/src/load.ts +10 -2
- package/src/loader.ts +81 -12
- package/src/package.ts +9 -8
- package/src/pages/blocks.ts +20 -14
- package/src/pages/index.ts +2 -2
- package/src/pages/markdown.ts +113 -34
- package/src/pages/render.ts +233 -41
- package/src/pages/window.ts +78 -0
- package/src/plugins.ts +90 -24
- package/src/public.ts +39 -0
- package/src/running.ts +8 -2
- package/src/serve.ts +29 -7
- package/src/server.ts +591 -110
- package/src/status.ts +15 -9
- package/dist/plugins/callout/style.css +0 -12
- package/dist/plugins/chat/style.css +0 -24
- package/dist/plugins/code/style.css +0 -29
- package/dist/plugins/comments/client.js +0 -10
- package/dist/plugins/comments/style.css +0 -40
- package/dist/plugins/details/style.css +0 -3
- package/dist/plugins/form/style.css +0 -44
- package/dist/plugins/gallery/client.js +0 -1
- package/dist/plugins/gallery/style.css +0 -27
- package/dist/plugins/grid/style.css +0 -25
- package/dist/plugins/iframe/client.js +0 -1
- package/dist/plugins/iframe/style.css +0 -29
- package/dist/plugins/toc/client.js +0 -1
- package/dist/plugins/toc/style.css +0 -19
- package/plugins/callout/style.css +0 -12
- package/plugins/chat/style.css +0 -24
- package/plugins/code/style.css +0 -29
- package/plugins/comments/style.css +0 -40
- package/plugins/details/style.css +0 -3
- package/plugins/form/style.css +0 -44
- package/plugins/gallery/style.css +0 -27
- package/plugins/grid/style.css +0 -25
- package/plugins/iframe/client.ts +0 -46
- package/plugins/iframe/style.css +0 -29
- package/plugins/terminal/style.css +0 -71
- package/plugins/toc/style.css +0 -19
- /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
package/src/public.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// A plugin's public folder: the one place its browser files are served from (its client modules,
|
|
2
|
+
// stylesheets, images, fonts; TypeScript there is served with its types stripped). The server
|
|
3
|
+
// serves what is inside a plugin's public folder, and nothing else of the plugin: not its server
|
|
4
|
+
// code, not the project's files beside it.
|
|
5
|
+
//
|
|
6
|
+
// A plugin says where (`public`); definePlugin defaults it to `public/` next to the module that
|
|
7
|
+
// calls it; a plugin that is a plain object (one written inline in the config, say) has the
|
|
8
|
+
// project's `.whiteboard/public/`. Its files (`client`, `style`, a block's) are named within it.
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import { fileURLToPath } from 'node:url'
|
|
11
|
+
import type { Plugin } from './define.ts'
|
|
12
|
+
|
|
13
|
+
const asPath = (ref: URL | string): string => (ref instanceof URL || ref.startsWith('file:') ? fileURLToPath(ref) : ref)
|
|
14
|
+
|
|
15
|
+
/** The folder a plugin's browser files are served from. */
|
|
16
|
+
export function publicDirOf(plugin: Plugin, wb: string): string {
|
|
17
|
+
return path.resolve(plugin.public != null ? asPath(plugin.public) : path.join(wb, 'public'))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Is `file` inside `dir`? */
|
|
21
|
+
export const within = (file: string, dir: string): boolean => {
|
|
22
|
+
const rel = path.relative(dir, file)
|
|
23
|
+
return !!rel && !rel.startsWith('..') && !path.isAbsolute(rel)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A file a plugin names, as a path: a name within its public folder (`style.css`,
|
|
28
|
+
* `client/main.js`), or a URL or absolute path, which must be inside it. Anything else is an
|
|
29
|
+
* error, said when the config loads, rather than a file that quietly isn't served.
|
|
30
|
+
*/
|
|
31
|
+
export function inPublic(dir: string, ref: URL | string, what: string): string {
|
|
32
|
+
const file =
|
|
33
|
+
typeof ref === 'string' && !ref.startsWith('file:') && !path.isAbsolute(ref)
|
|
34
|
+
? path.resolve(dir, ref)
|
|
35
|
+
: path.resolve(asPath(ref))
|
|
36
|
+
if (!within(file, dir))
|
|
37
|
+
throw new Error(`${what}: ${file} is not in its public folder (${dir}); a plugin's browser files live there`)
|
|
38
|
+
return file
|
|
39
|
+
}
|
package/src/running.ts
CHANGED
|
@@ -6,7 +6,11 @@ import type { Project } from './config.ts'
|
|
|
6
6
|
|
|
7
7
|
/** The port the last server of this project recorded, or null. */
|
|
8
8
|
export function recordedPort(project: Project): number | null {
|
|
9
|
-
try {
|
|
9
|
+
try {
|
|
10
|
+
return Number(JSON.parse(fs.readFileSync(project.serverFile, 'utf8')).port) || null
|
|
11
|
+
} catch {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
/** The base URL of this project's running server, or null. `except`: a process to not count (the asking server itself). */
|
|
@@ -18,5 +22,7 @@ export async function runningServer(project: Project, { except }: { except?: num
|
|
|
18
22
|
const res = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(800) })
|
|
19
23
|
const health = res.ok ? await res.json() : null
|
|
20
24
|
return health?.dir === project.dir && health.pid !== except ? base : null
|
|
21
|
-
} catch {
|
|
25
|
+
} catch {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
22
28
|
}
|
package/src/serve.ts
CHANGED
|
@@ -19,12 +19,26 @@ export async function start(project: Project): Promise<number> {
|
|
|
19
19
|
fs.mkdirSync(project.pagesDir, { recursive: true })
|
|
20
20
|
const wb = createServer(project)
|
|
21
21
|
await wb.config()
|
|
22
|
-
const server = http.createServer((req, res) => {
|
|
23
|
-
|
|
22
|
+
const server = http.createServer((req, res) => {
|
|
23
|
+
void wb.handle(req, res)
|
|
24
|
+
})
|
|
25
|
+
const candidates = [
|
|
26
|
+
...new Set(
|
|
27
|
+
[recordedPort(project), DEFAULT_PORT, ...Array.from({ length: 50 }, (_, i) => DEFAULT_PORT + 1 + i)].filter(
|
|
28
|
+
(p): p is number => !!p,
|
|
29
|
+
),
|
|
30
|
+
),
|
|
31
|
+
]
|
|
24
32
|
for (const port of candidates) {
|
|
25
33
|
const ok = await new Promise<boolean>((resolve, reject) => {
|
|
26
|
-
const onError = (err: NodeJS.ErrnoException) => {
|
|
27
|
-
|
|
34
|
+
const onError = (err: NodeJS.ErrnoException) => {
|
|
35
|
+
server.off('listening', onListening)
|
|
36
|
+
err.code === 'EADDRINUSE' ? resolve(false) : reject(err)
|
|
37
|
+
}
|
|
38
|
+
const onListening = () => {
|
|
39
|
+
server.off('error', onError)
|
|
40
|
+
resolve(true)
|
|
41
|
+
}
|
|
28
42
|
server.once('error', onError)
|
|
29
43
|
server.once('listening', onListening)
|
|
30
44
|
server.listen(port, '127.0.0.1')
|
|
@@ -32,15 +46,23 @@ export async function start(project: Project): Promise<number> {
|
|
|
32
46
|
if (!ok) continue
|
|
33
47
|
fs.writeFileSync(project.serverFile, JSON.stringify({ port, pid: process.pid }, null, 2) + '\n')
|
|
34
48
|
// the command that started this server waits for it; others can now find it
|
|
35
|
-
try {
|
|
49
|
+
try {
|
|
50
|
+
fs.unlinkSync(path.join(project.wb, 'server.lock'))
|
|
51
|
+
} catch {}
|
|
36
52
|
const cleanup = () => {
|
|
37
|
-
try {
|
|
53
|
+
try {
|
|
54
|
+
if (JSON.parse(fs.readFileSync(project.serverFile, 'utf8')).pid === process.pid)
|
|
55
|
+
fs.unlinkSync(project.serverFile)
|
|
56
|
+
} catch {}
|
|
38
57
|
}
|
|
39
58
|
process.on('exit', cleanup)
|
|
40
59
|
// one server per project: should another have started at the same moment, whichever one
|
|
41
60
|
// server.json names last stays, and the others leave (their clients reconnect to it)
|
|
42
61
|
const yieldToOther = async () => {
|
|
43
|
-
if (await runningServer(project, { except: process.pid })) {
|
|
62
|
+
if (await runningServer(project, { except: process.pid })) {
|
|
63
|
+
console.log('whiteboard: another server of this project took over')
|
|
64
|
+
process.exit(0)
|
|
65
|
+
}
|
|
44
66
|
}
|
|
45
67
|
setTimeout(yieldToOther, 1500).unref()
|
|
46
68
|
setInterval(yieldToOther, 30000).unref()
|