@noy4/docserve 0.3.4 → 0.3.5

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.
Files changed (61) hide show
  1. package/bin.mjs +8 -213
  2. package/dist/gallery/assets/index-CGV64tuk.css +1 -0
  3. package/dist/gallery/assets/index-Cf8Uf0vA.js +10 -0
  4. package/dist/gallery/assets/index-Cf8Uf0vA.js.map +1 -0
  5. package/dist/gallery/index.html +15 -0
  6. package/dist/node/cli.mjs +4095 -0
  7. package/dist/node/cli.mjs.map +7 -0
  8. package/dist/widget/index.js +730 -495
  9. package/package.json +14 -4
  10. package/src/node/cli.mjs +155 -0
  11. package/src/node/{files.mjs → docs/files.mjs} +1 -1
  12. package/src/node/{inject.mjs → docs/inject.mjs} +1 -1
  13. package/src/node/{meta.mjs → docs/meta.mjs} +1 -1
  14. package/src/node/http/app.mjs +20 -0
  15. package/src/node/{assets.mjs → http/assets.mjs} +3 -2
  16. package/src/node/http/gallery.mjs +45 -0
  17. package/src/node/http/response.mjs +31 -0
  18. package/src/node/http/routes.mjs +59 -0
  19. package/src/node/{serve-static.mjs → http/serve-static.mjs} +1 -1
  20. package/src/node/{server.mjs → http/server.mjs} +10 -10
  21. package/src/node/{state.mjs → instances/state.mjs} +9 -5
  22. package/src/node/instances/view.mjs +19 -0
  23. package/src/node/{watch.mjs → live/watch.mjs} +1 -1
  24. package/src/node/paths.mjs +10 -0
  25. package/src/node/rpc/files.mjs +5 -0
  26. package/src/node/rpc/index.mjs +39 -0
  27. package/src/node/rpc/route.mjs +34 -0
  28. package/src/node/rpc/servers.mjs +16 -0
  29. package/src/plugins/servers/client.js +77 -0
  30. package/src/plugins/servers/commands.ts +30 -0
  31. package/src/plugins/servers/model.ts +106 -0
  32. package/src/plugins/servers/servers.css +144 -0
  33. package/src/plugins/servers/ui/ServersPopover.tsx +71 -0
  34. package/src/plugins/sidebar/ui/PageList.tsx +1 -1
  35. package/src/plugins/sidebar/ui/RadioMenu.tsx +1 -1
  36. package/src/plugins/sidebar/ui/Sidebar.tsx +3 -3
  37. package/src/plugins/sidebar/ui/TreeList.tsx +10 -3
  38. package/src/{plugins/sidebar/ui → shared/client}/preview-model.ts +18 -4
  39. package/src/{plugins/sidebar/ui/useModel.ts → shared/client/use-model.ts} +1 -8
  40. package/src/shared/types.d.ts +17 -1
  41. package/src/widget/{pages.js → api/pages.js} +4 -7
  42. package/src/widget/api/rpc-client.js +25 -0
  43. package/src/widget/api/servers.js +46 -0
  44. package/src/widget/host.js +10 -8
  45. package/src/widget/index.js +2 -0
  46. package/src/widget/{docks.js → shell/docks.js} +2 -2
  47. package/src/widget/{palette.js → shell/palette.js} +3 -3
  48. package/src/widget/{placement.js → shell/placement.js} +1 -1
  49. package/src/widget/{ui.js → shell/ui.js} +1 -1
  50. package/index.html +0 -365
  51. package/src/node/adapter.mjs +0 -67
  52. package/src/node/gallery.mjs +0 -33
  53. package/src/node/routes.mjs +0 -105
  54. /package/src/node/{dates.mjs → docs/dates.mjs} +0 -0
  55. /package/src/node/{docs-info.mjs → docs/info.mjs} +0 -0
  56. /package/src/node/{scan.mjs → docs/scan.mjs} +0 -0
  57. /package/src/node/{websocket.mjs → live/websocket.mjs} +0 -0
  58. /package/src/widget/{live.js → api/live.js} +0 -0
  59. /package/src/widget/{rpc.js → api/rpc.js} +0 -0
  60. /package/src/widget/{palette.css → shell/palette.css} +0 -0
  61. /package/src/widget/{styles.js → shell/styles.js} +0 -0
@@ -1,105 +0,0 @@
1
- // HTTP routing: an ordered table of handlers over one docs static handler.
2
- // Nothing here knows about listening, signals or sockets.
3
- import { resolve } from "node:path"
4
- import { serveAsset } from "./assets.mjs"
5
- import { apiFiles } from "./files.mjs"
6
- import { galleryResponse } from "./gallery.mjs"
7
- import { injectIntoHtml } from "./inject.mjs"
8
- import { createStaticHandler } from "./serve-static.mjs"
9
-
10
- const WIDGET_DIR = resolve(import.meta.dirname, "..", "widget")
11
- const PLUGINS_DIR = resolve(import.meta.dirname, "..", "plugins")
12
- const DIST_WIDGET_DIR = resolve(import.meta.dirname, "..", "..", "dist", "widget")
13
- const INTERNAL_PREFIX = "/__docserve/"
14
- const WIDGET_PREFIX = `${INTERNAL_PREFIX}widget/`
15
- const PLUGINS_PREFIX = `${INTERNAL_PREFIX}plugins/`
16
-
17
- /**
18
- * @param {{ docsDir: string }} options
19
- * @returns {(request: Request) => Promise<Response>}
20
- */
21
- export function createHandler({ docsDir }) {
22
- // Every other HTML response is injected; the gallery template is not.
23
- const docs = createStaticHandler({
24
- root: docsDir,
25
- headers: { "cache-control": "no-store" },
26
- transform: (html, relative) => injectIntoHtml(html, relative, docsDir),
27
- })
28
-
29
- /** @type {Array<{ match: (pathname: string) => boolean, handle: (request: Request, url: URL) => Promise<Response> }>} */
30
- const routes = [
31
- { match: (pathname) => pathname === "/api/files", handle: serveFiles },
32
- { match: (pathname) => pathname.startsWith(INTERNAL_PREFIX), handle: serveInternal },
33
- { match: (pathname) => pathname === "/" || pathname === "/index.html", handle: serveGallery },
34
- { match: () => true, handle: serveDocs },
35
- ]
36
-
37
- return async function handler(request) {
38
- const url = new URL(request.url)
39
- const route = routes.find((candidate) => candidate.match(url.pathname))
40
- return route.handle(request, url)
41
- }
42
-
43
- /**
44
- * @returns {Promise<Response>}
45
- */
46
- async function serveFiles() {
47
- try {
48
- return Response.json(await apiFiles(docsDir), { headers: { "cache-control": "no-store" } })
49
- } catch (err) {
50
- console.error(err)
51
- return Response.json([], { headers: { "cache-control": "no-store" } })
52
- }
53
- }
54
-
55
- /**
56
- * Widget bundle and plugin sources, read per request (widget JS comes from dist).
57
- * @param {Request} request
58
- * @param {URL} url
59
- * @returns {Promise<Response>}
60
- */
61
- async function serveInternal(request, url) {
62
- if (url.pathname.startsWith(WIDGET_PREFIX))
63
- return serveWidget(url.pathname.slice(WIDGET_PREFIX.length))
64
- if (url.pathname.startsWith(PLUGINS_PREFIX))
65
- return serveAsset(PLUGINS_DIR, url.pathname.slice(PLUGINS_PREFIX.length))
66
- return new Response("Not Found", { status: 404 })
67
- }
68
-
69
- /**
70
- * Built widget first, source files (CSS) as the fallback. A JS request that
71
- * misses the build is an error: the source entry now has bare imports.
72
- * @param {string} relative
73
- * @returns {Promise<Response>}
74
- */
75
- async function serveWidget(relative) {
76
- if (!relative) return new Response("Not Found", { status: 404 })
77
-
78
- const built = await serveAsset(DIST_WIDGET_DIR, relative)
79
- if (built.status !== 404) return built
80
-
81
- if (/\.m?js$/.test(relative)) {
82
- return new Response("Widget bundle missing: run `pnpm -C cli build`", {
83
- status: 503,
84
- headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" },
85
- })
86
- }
87
-
88
- return serveAsset(WIDGET_DIR, relative)
89
- }
90
-
91
- /**
92
- * @returns {Promise<Response>}
93
- */
94
- async function serveGallery() {
95
- return galleryResponse(docsDir)
96
- }
97
-
98
- /**
99
- * @param {Request} request
100
- * @returns {Promise<Response>}
101
- */
102
- async function serveDocs(request) {
103
- return (await docs(request)) ?? new Response("Not Found", { status: 404 })
104
- }
105
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes