@noy4/docserve 0.3.2 → 0.3.4
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/bin.mjs +2 -2
- package/dist/widget/index.js +11803 -0
- package/package.json +24 -3
- package/src/node/adapter.mjs +67 -0
- package/src/node/assets.mjs +36 -0
- package/src/node/dates.mjs +73 -0
- package/src/node/docs-info.mjs +39 -0
- package/src/node/files.mjs +43 -0
- package/src/node/gallery.mjs +33 -0
- package/src/node/inject.mjs +43 -0
- package/src/node/meta.mjs +137 -0
- package/src/node/routes.mjs +105 -0
- package/src/node/scan.mjs +87 -0
- package/src/node/serve-static.mjs +158 -0
- package/src/node/server.mjs +69 -0
- package/src/node/watch.mjs +119 -0
- package/src/plugins/collapse/client.js +45 -0
- package/src/plugins/collapse/collapse.css +74 -0
- package/src/plugins/collapse/commands.ts +81 -0
- package/src/plugins/collapse/model.ts +123 -0
- package/src/plugins/collapse/sections.ts +105 -0
- package/src/plugins/collapse/view.ts +84 -0
- package/src/plugins/copy/client.js +72 -0
- package/src/plugins/copy/copy.css +21 -0
- package/src/plugins/home/client.js +24 -0
- package/src/plugins/sidebar/client.js +106 -0
- package/src/plugins/sidebar/grouping.js +108 -0
- package/src/plugins/sidebar/icons.js +25 -0
- package/src/plugins/sidebar/model.ts +91 -0
- package/src/plugins/sidebar/resize-model.ts +47 -0
- package/src/plugins/sidebar/sidebar.css +663 -0
- package/src/plugins/sidebar/tree-model.ts +23 -0
- package/src/plugins/sidebar/tree.ts +69 -0
- package/src/plugins/sidebar/ui/PageList.tsx +153 -0
- package/src/plugins/sidebar/ui/RadioMenu.tsx +201 -0
- package/src/plugins/sidebar/ui/Sidebar.tsx +95 -0
- package/src/plugins/sidebar/ui/SidebarHeader.tsx +87 -0
- package/src/plugins/sidebar/ui/TreeList.tsx +121 -0
- package/src/plugins/sidebar/ui/preview-model.ts +134 -0
- package/src/plugins/sidebar/ui/useModel.ts +25 -0
- package/src/plugins/toc/client.js +55 -0
- package/src/plugins/toc/commands.ts +49 -0
- package/src/plugins/toc/heading-html.ts +40 -0
- package/src/plugins/toc/model.ts +178 -0
- package/src/plugins/toc/outline.js +94 -0
- package/src/plugins/toc/scroll-spy.ts +35 -0
- package/src/plugins/toc/toc.css +214 -0
- package/src/plugins/toc/ui/TocPanel.tsx +87 -0
- package/src/shared/types.d.ts +193 -0
- package/src/widget/commands.js +214 -0
- package/src/widget/docks.js +127 -0
- package/src/widget/host.js +187 -0
- package/src/widget/index.js +22 -0
- package/src/widget/lib/disposables.js +44 -0
- package/src/widget/lib/dom.js +106 -0
- package/src/widget/lib/events.js +65 -0
- package/src/widget/lib/headings.js +132 -0
- package/src/widget/lib/persisted-signal.js +40 -0
- package/src/widget/lib/storage.js +70 -0
- package/src/widget/live.js +86 -0
- package/src/widget/pages.js +65 -0
- package/src/widget/palette.css +162 -0
- package/src/widget/palette.js +259 -0
- package/src/widget/placement.js +204 -0
- package/src/widget/plugins.js +39 -0
- package/src/widget/rpc.js +32 -0
- package/src/widget/styles.js +31 -0
- package/src/widget/ui.js +50 -0
- package/src/widget/widget.css +206 -0
- package/server/files.mjs +0 -261
- package/server/index.mjs +0 -198
- package/server/inject.html +0 -88
- package/server/inject.mjs +0 -28
- package/server/watch.mjs +0 -104
- /package/{server → src/node}/state.mjs +0 -0
- /package/{server → src/node}/websocket.mjs +0 -0
package/server/inject.html
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
(() => {
|
|
3
|
-
// iframes: no reload loop from dropped sockets, no copy button
|
|
4
|
-
if (window.self !== window.top) return
|
|
5
|
-
|
|
6
|
-
const pageId = __DOCSERVE_PAGE_ID__
|
|
7
|
-
const absPath = __DOCSERVE_ABS_PATH__
|
|
8
|
-
const wsPath = __DOCSERVE_WS_PATH__
|
|
9
|
-
|
|
10
|
-
const proto = location.protocol === "https:" ? "wss:" : "ws:"
|
|
11
|
-
const ws = new WebSocket(proto + "//" + location.host + wsPath)
|
|
12
|
-
ws.addEventListener("message", (e) => {
|
|
13
|
-
let change
|
|
14
|
-
try { change = JSON.parse(e.data) } catch { return }
|
|
15
|
-
if (change?.type === "change" && Array.isArray(change.pages) && change.pages.includes(pageId)) {
|
|
16
|
-
location.reload()
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
ws.addEventListener("close", () => setTimeout(() => location.reload(), 1000))
|
|
20
|
-
|
|
21
|
-
const style = document.createElement("style")
|
|
22
|
-
style.textContent = `#docserve-copy {
|
|
23
|
-
position: fixed;
|
|
24
|
-
top: 12px;
|
|
25
|
-
right: 12px;
|
|
26
|
-
z-index: 2147483647;
|
|
27
|
-
display: inline-flex;
|
|
28
|
-
align-items: center;
|
|
29
|
-
gap: 6px;
|
|
30
|
-
height: 28px;
|
|
31
|
-
padding: 0 10px 0 9px;
|
|
32
|
-
border: 1px solid rgba(127, 127, 138, 0.35);
|
|
33
|
-
border-radius: 8px;
|
|
34
|
-
background: rgba(127, 127, 138, 0.14);
|
|
35
|
-
color: inherit;
|
|
36
|
-
cursor: pointer;
|
|
37
|
-
opacity: 0.55;
|
|
38
|
-
transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
|
|
39
|
-
}
|
|
40
|
-
#docserve-copy svg {
|
|
41
|
-
width: 14px;
|
|
42
|
-
height: 14px;
|
|
43
|
-
pointer-events: none;
|
|
44
|
-
}
|
|
45
|
-
#docserve-copy .label {
|
|
46
|
-
font: 500 11.5px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", sans-serif;
|
|
47
|
-
letter-spacing: 0.01em;
|
|
48
|
-
white-space: nowrap;
|
|
49
|
-
}
|
|
50
|
-
#docserve-copy:hover {
|
|
51
|
-
opacity: 1;
|
|
52
|
-
border-color: #6c8cff;
|
|
53
|
-
color: #6c8cff;
|
|
54
|
-
}
|
|
55
|
-
#docserve-copy.copied {
|
|
56
|
-
opacity: 1;
|
|
57
|
-
color: #4ade80;
|
|
58
|
-
border-color: #4ade80;
|
|
59
|
-
}
|
|
60
|
-
@media (prefers-color-scheme: light) {
|
|
61
|
-
#docserve-copy:hover { border-color: #2563eb; color: #2563eb; }
|
|
62
|
-
#docserve-copy.copied { color: #16a34a; border-color: #16a34a; }
|
|
63
|
-
}
|
|
64
|
-
#docserve-copy .ic-check { display: none; }
|
|
65
|
-
#docserve-copy.copied .ic-copy { display: none; }
|
|
66
|
-
#docserve-copy.copied .ic-check { display: block; }`
|
|
67
|
-
const COPY = '<svg class="ic-copy" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>'
|
|
68
|
-
const CHECK = '<svg class="ic-check" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>'
|
|
69
|
-
const btn = document.createElement("button")
|
|
70
|
-
btn.id = "docserve-copy"
|
|
71
|
-
btn.type = "button"
|
|
72
|
-
btn.title = absPath
|
|
73
|
-
btn.innerHTML = COPY + CHECK + '<span class="label">Copy file path</span>'
|
|
74
|
-
btn.addEventListener("click", async () => {
|
|
75
|
-
try {
|
|
76
|
-
await navigator.clipboard.writeText(absPath)
|
|
77
|
-
btn.classList.add("copied")
|
|
78
|
-
btn.querySelector(".label").textContent = "Copied"
|
|
79
|
-
setTimeout(() => {
|
|
80
|
-
btn.classList.remove("copied")
|
|
81
|
-
btn.querySelector(".label").textContent = "Copy file path"
|
|
82
|
-
}, 1200)
|
|
83
|
-
} catch {}
|
|
84
|
-
})
|
|
85
|
-
document.head.appendChild(style)
|
|
86
|
-
document.body.appendChild(btn)
|
|
87
|
-
})()
|
|
88
|
-
</script>
|
package/server/inject.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// Injection: every text/html response served from docsDir gets one client script
|
|
2
|
-
// before the last </body> (appended at the end if the tag is missing). The script
|
|
3
|
-
// exits immediately inside iframes, so previews get neither part; the gallery
|
|
4
|
-
// template ships its own client. The client template is loaded once at startup.
|
|
5
|
-
import { readFileSync } from "node:fs"
|
|
6
|
-
|
|
7
|
-
export const WS_PATH = "/__reload"
|
|
8
|
-
|
|
9
|
-
const clientTemplate = readFileSync(new URL("./inject.html", import.meta.url), "utf8")
|
|
10
|
-
|
|
11
|
-
export function injectIntoHtml(html, pageId, absPath) {
|
|
12
|
-
const idx = html.toLowerCase().lastIndexOf("</body>")
|
|
13
|
-
if (idx === -1) return html + clientJs(pageId, absPath)
|
|
14
|
-
return html.slice(0, idx) + clientJs(pageId, absPath) + html.slice(idx)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function clientJs(pageId, absPath) {
|
|
18
|
-
const values = {
|
|
19
|
-
PAGE_ID: JSON.stringify(pageId).replaceAll("<", "\\u003c"),
|
|
20
|
-
ABS_PATH: JSON.stringify(absPath).replaceAll("<", "\\u003c"),
|
|
21
|
-
WS_PATH: JSON.stringify(WS_PATH),
|
|
22
|
-
}
|
|
23
|
-
let rendered = clientTemplate
|
|
24
|
-
for (const [key, value] of Object.entries(values)) {
|
|
25
|
-
rendered = rendered.replaceAll(`__DOCSERVE_${key}__`, () => value)
|
|
26
|
-
}
|
|
27
|
-
return rendered
|
|
28
|
-
}
|
package/server/watch.mjs
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// FileWatcher: watch docsDir recursively for *.html changes and broadcast
|
|
2
|
-
// debounced batches over the reload socket. The gallery template is watched
|
|
3
|
-
// too; its edits set templateChanged so gallery tabs pick them up even though
|
|
4
|
-
// nothing in docsDir changed.
|
|
5
|
-
//
|
|
6
|
-
// The gallery list is every *.html except any index.html; files outside that
|
|
7
|
-
// set never flip contentSetChanged.
|
|
8
|
-
import { existsSync, watch } from "node:fs"
|
|
9
|
-
import { basename, dirname, resolve } from "node:path"
|
|
10
|
-
import { isWithin, listHtmlFiles, normalizedRelative, shouldIgnore } from "./files.mjs"
|
|
11
|
-
|
|
12
|
-
const DEBOUNCE_MS = 50 // like livePreview.previewDebounceDelay
|
|
13
|
-
const TEMPLATE_TOUCH = "\u0000template" // sentinel: never a real docsDir-relative path
|
|
14
|
-
|
|
15
|
-
export class FileWatcher {
|
|
16
|
-
constructor(options = {}) {
|
|
17
|
-
this.wss = options.wss
|
|
18
|
-
this.docsDir = options.docsDir
|
|
19
|
-
this.templatePath = options.templatePath
|
|
20
|
-
this.debounceMs = options.debounceMs ?? DEBOUNCE_MS
|
|
21
|
-
this.knownFiles = new Set()
|
|
22
|
-
this.broadcastQueue = Promise.resolve()
|
|
23
|
-
this.watchers = []
|
|
24
|
-
|
|
25
|
-
this.queueBroadcast = debounceBatch((touched) => {
|
|
26
|
-
this.broadcastQueue = this.broadcastQueue
|
|
27
|
-
.then(() => this.broadcastChanges(touched))
|
|
28
|
-
.catch((error) => console.error(error))
|
|
29
|
-
}, this.debounceMs)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async start() {
|
|
33
|
-
try {
|
|
34
|
-
this.knownFiles = new Set(
|
|
35
|
-
(await listHtmlFiles(this.docsDir)).map((p) => normalizedRelative(this.docsDir, p)),
|
|
36
|
-
)
|
|
37
|
-
} catch {
|
|
38
|
-
this.knownFiles = new Set()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.watchers.push(
|
|
42
|
-
watch(this.docsDir, { recursive: true }, (event, filename) => {
|
|
43
|
-
if (!filename?.endsWith(".html")) return
|
|
44
|
-
if (shouldIgnore(filename)) return
|
|
45
|
-
const full = resolve(this.docsDir, filename)
|
|
46
|
-
if (!isWithin(this.docsDir, full)) return
|
|
47
|
-
this.queueBroadcast(normalizedRelative(this.docsDir, full))
|
|
48
|
-
}).on("error", () => {}),
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
if (this.templatePath) {
|
|
52
|
-
// Watch the template's directory: atomic saves replace the file, so the
|
|
53
|
-
// file itself would miss events.
|
|
54
|
-
const templateName = basename(this.templatePath)
|
|
55
|
-
this.watchers.push(
|
|
56
|
-
watch(dirname(this.templatePath), (event, filename) => {
|
|
57
|
-
if (filename === templateName) this.queueBroadcast(TEMPLATE_TOUCH)
|
|
58
|
-
}).on("error", () => {}),
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async broadcastChanges(touched) {
|
|
64
|
-
let contentSetChanged = false
|
|
65
|
-
const templateChanged = touched.includes(TEMPLATE_TOUCH)
|
|
66
|
-
const pages = touched.filter((rel) => rel !== TEMPLATE_TOUCH)
|
|
67
|
-
|
|
68
|
-
for (const rel of pages) {
|
|
69
|
-
if (basename(rel) === "index.html") continue // never a gallery card
|
|
70
|
-
const full = resolve(this.docsDir, rel)
|
|
71
|
-
const exists = existsSync(full)
|
|
72
|
-
const wasKnown = this.knownFiles.has(rel)
|
|
73
|
-
|
|
74
|
-
if (exists && !wasKnown) {
|
|
75
|
-
this.knownFiles.add(rel)
|
|
76
|
-
contentSetChanged = true
|
|
77
|
-
} else if (!exists && wasKnown) {
|
|
78
|
-
this.knownFiles.delete(rel)
|
|
79
|
-
contentSetChanged = true
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
this.wss.broadcast({ type: "change", pages, contentSetChanged, templateChanged })
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
close() {
|
|
87
|
-
this.watchers.forEach((w) => w.close())
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Accumulate items during the debounce window and deliver them as one batch.
|
|
92
|
-
function debounceBatch(fn, ms) {
|
|
93
|
-
let timer = null
|
|
94
|
-
const pending = new Set()
|
|
95
|
-
return (item) => {
|
|
96
|
-
pending.add(item)
|
|
97
|
-
clearTimeout(timer)
|
|
98
|
-
timer = setTimeout(() => {
|
|
99
|
-
const items = [...pending]
|
|
100
|
-
pending.clear()
|
|
101
|
-
fn(items)
|
|
102
|
-
}, ms)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
File without changes
|
|
File without changes
|