nodality 1.5.1 → 1.5.2
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/mcp-server.mjs +0 -98
- package/bin/nodality.mjs +3 -28
- package/dist/animator.cjs.js.LICENSE.txt +1 -1
- package/dist/animator.esm.js.LICENSE.txt +1 -1
- package/dist/audionew.cjs.js.LICENSE.txt +1 -1
- package/dist/audionew.esm.js.LICENSE.txt +1 -1
- package/dist/base.cjs.js.LICENSE.txt +1 -1
- package/dist/base.esm.js.LICENSE.txt +1 -1
- package/dist/beta-desktop-bar.cjs.js.LICENSE.txt +1 -1
- package/dist/beta-desktop-bar.esm.js.LICENSE.txt +1 -1
- package/dist/beta-mobile-bar.cjs.js.LICENSE.txt +1 -1
- package/dist/beta-mobile-bar.esm.js.LICENSE.txt +1 -1
- package/dist/bundle.umd.js.LICENSE.txt +1 -1
- package/dist/button.cjs.js.LICENSE.txt +1 -1
- package/dist/button.esm.js.LICENSE.txt +1 -1
- package/dist/card-getter.cjs.js.LICENSE.txt +1 -1
- package/dist/card-getter.esm.js.LICENSE.txt +1 -1
- package/dist/center.cjs.js.LICENSE.txt +1 -1
- package/dist/center.esm.js.LICENSE.txt +1 -1
- package/dist/checkbox.cjs.js.LICENSE.txt +1 -1
- package/dist/checkbox.esm.js.LICENSE.txt +1 -1
- package/dist/code.cjs.js.LICENSE.txt +1 -1
- package/dist/code.esm.js.LICENSE.txt +1 -1
- package/dist/container.cjs.js.LICENSE.txt +1 -1
- package/dist/container.esm.js.LICENSE.txt +1 -1
- package/dist/data-list.cjs.js.LICENSE.txt +1 -1
- package/dist/data-list.esm.js.LICENSE.txt +1 -1
- package/dist/designer.cjs.js.LICENSE.txt +1 -1
- package/dist/designer.esm.js.LICENSE.txt +1 -1
- package/dist/element-mapper.cjs.js.LICENSE.txt +1 -1
- package/dist/element-mapper.esm.js.LICENSE.txt +1 -1
- package/dist/finalresult.esm.js.LICENSE.txt +1 -1
- package/dist/flex-card.cjs.js.LICENSE.txt +1 -1
- package/dist/flex-card.esm.js.LICENSE.txt +1 -1
- package/dist/flex-grid.cjs.js.LICENSE.txt +1 -1
- package/dist/flex-grid.esm.js.LICENSE.txt +1 -1
- package/dist/flex-row.cjs.js.LICENSE.txt +1 -1
- package/dist/flex-row.esm.js.LICENSE.txt +1 -1
- package/dist/floating-input.cjs.js.LICENSE.txt +1 -1
- package/dist/floating-input.esm.js.LICENSE.txt +1 -1
- package/dist/free.cjs.js.LICENSE.txt +1 -1
- package/dist/free.esm.js.LICENSE.txt +1 -1
- package/dist/horizontal-scroller.cjs.js.LICENSE.txt +1 -1
- package/dist/horizontal-scroller.esm.js.LICENSE.txt +1 -1
- package/dist/image-picker.cjs.js.LICENSE.txt +1 -1
- package/dist/image-picker.esm.js.LICENSE.txt +1 -1
- package/dist/image.cjs.js.LICENSE.txt +1 -1
- package/dist/image.esm.js.LICENSE.txt +1 -1
- package/dist/index.cjs.js.LICENSE.txt +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js.LICENSE.txt +1 -1
- package/dist/keyframe-animation.cjs.js.LICENSE.txt +1 -1
- package/dist/keyframe-animation.esm.js.LICENSE.txt +1 -1
- package/dist/link-getter.cjs.js.LICENSE.txt +1 -1
- package/dist/link-getter.esm.js.LICENSE.txt +1 -1
- package/dist/link.cjs.js.LICENSE.txt +1 -1
- package/dist/link.esm.js.LICENSE.txt +1 -1
- package/dist/meta-adder.cjs.js.LICENSE.txt +1 -1
- package/dist/meta-adder.esm.js.LICENSE.txt +1 -1
- package/dist/modal-2025.cjs.js.LICENSE.txt +1 -1
- package/dist/modal-2025.esm.js.LICENSE.txt +1 -1
- package/dist/multiswitcher.cjs.js.LICENSE.txt +1 -1
- package/dist/multiswitcher.esm.js.LICENSE.txt +1 -1
- package/dist/new-nav-bar.cjs.js.LICENSE.txt +1 -1
- package/dist/new-nav-bar.esm.js.LICENSE.txt +1 -1
- package/dist/picker.cjs.js.LICENSE.txt +1 -1
- package/dist/picker.esm.js.LICENSE.txt +1 -1
- package/dist/progress.cjs.js.LICENSE.txt +1 -1
- package/dist/progress.esm.js.LICENSE.txt +1 -1
- package/dist/radio.cjs.js.LICENSE.txt +1 -1
- package/dist/radio.esm.js.LICENSE.txt +1 -1
- package/dist/range.cjs.js.LICENSE.txt +1 -1
- package/dist/range.esm.js.LICENSE.txt +1 -1
- package/dist/scroll-video.cjs.js.LICENSE.txt +1 -1
- package/dist/scroll-video.esm.js.LICENSE.txt +1 -1
- package/dist/side-bar.cjs.js.LICENSE.txt +1 -1
- package/dist/side-bar.esm.js.LICENSE.txt +1 -1
- package/dist/side-nav-bar.cjs.js.LICENSE.txt +1 -1
- package/dist/side-nav-bar.esm.js.LICENSE.txt +1 -1
- package/dist/simple-bar.cjs.js.LICENSE.txt +1 -1
- package/dist/simple-bar.esm.js.LICENSE.txt +1 -1
- package/dist/slider-2025.cjs.js.LICENSE.txt +1 -1
- package/dist/slider-2025.esm.js.LICENSE.txt +1 -1
- package/dist/spacer.cjs.js.LICENSE.txt +1 -1
- package/dist/spacer.esm.js.LICENSE.txt +1 -1
- package/dist/stack.cjs.js.LICENSE.txt +1 -1
- package/dist/stack.esm.js.LICENSE.txt +1 -1
- package/dist/stacker.cjs.js.LICENSE.txt +1 -1
- package/dist/stacker.esm.js.LICENSE.txt +1 -1
- package/dist/table.cjs.js.LICENSE.txt +1 -1
- package/dist/table.esm.js.LICENSE.txt +1 -1
- package/dist/text-field.cjs.js.LICENSE.txt +1 -1
- package/dist/text-field.esm.js.LICENSE.txt +1 -1
- package/dist/text.cjs.js.LICENSE.txt +1 -1
- package/dist/text.esm.js.LICENSE.txt +1 -1
- package/dist/theme.cjs.js.LICENSE.txt +1 -1
- package/dist/theme.esm.js.LICENSE.txt +1 -1
- package/dist/transform-anim.cjs.js.LICENSE.txt +1 -1
- package/dist/transform-anim.esm.js.LICENSE.txt +1 -1
- package/dist/ulist.cjs.js.LICENSE.txt +1 -1
- package/dist/ulist.esm.js.LICENSE.txt +1 -1
- package/dist/video.cjs.js.LICENSE.txt +1 -1
- package/dist/video.esm.js.LICENSE.txt +1 -1
- package/dist/wrap.cjs.js.LICENSE.txt +1 -1
- package/dist/wrap.esm.js.LICENSE.txt +1 -1
- package/dist/zoom-card.cjs.js.LICENSE.txt +1 -1
- package/dist/zoom-card.esm.js.LICENSE.txt +1 -1
- package/layout/animator.js +1 -1
- package/layout/audio.js +1 -1
- package/layout/audionew.js +1 -1
- package/layout/base.js +1 -1
- package/layout/beta-desktop-bar.js +1 -1
- package/layout/beta-mobile-bar.js +1 -1
- package/layout/button.js +1 -1
- package/layout/center.js +1 -1
- package/layout/checkbox.js +1 -1
- package/layout/circle.js +1 -1
- package/layout/code.js +1 -1
- package/layout/container.js +1 -1
- package/layout/dropdown-2025.js +1 -1
- package/layout/flex-card.js +1 -1
- package/layout/flex-grid.js +1 -1
- package/layout/flex-row.js +1 -1
- package/layout/form-components/custom.js +1 -1
- package/layout/form-components/data-list.js +1 -1
- package/layout/form-components/floating-input.js +1 -1
- package/layout/form-components/form-all.js +1 -1
- package/layout/form-components/form.js +1 -1
- package/layout/form-components/image-picker.js +1 -1
- package/layout/form-components/picker.js +1 -1
- package/layout/form-components/radio.js +1 -1
- package/layout/form-components/radiogroup.js +1 -1
- package/layout/form-components/range.js +1 -1
- package/layout/free.js +1 -1
- package/layout/grid-overlay.js +1 -1
- package/layout/grid-switcher.js +1 -1
- package/layout/grid.js +1 -1
- package/layout/horizontal-scroller.js +1 -1
- package/layout/image.js +1 -1
- package/layout/index.js +1 -1
- package/layout/link.js +1 -1
- package/layout/list.js +1 -1
- package/layout/meta-adder.js +1 -1
- package/layout/modal-2025.js +1 -1
- package/layout/morph.js +1 -1
- package/layout/multiswitcher.js +1 -1
- package/layout/nav-bar.js +1 -1
- package/layout/nav-factor/custom-div.js +1 -1
- package/layout/new-nav-bar.js +1 -1
- package/layout/polygon.js +1 -1
- package/layout/prerender-site.js +1 -1
- package/layout/prerender.js +1 -1
- package/layout/progress.js +1 -1
- package/layout/row.js +1 -1
- package/layout/scroll-video.js +1 -1
- package/layout/shop.js +1 -1
- package/layout/side-bar.js +1 -1
- package/layout/side-nav-bar.js +1 -1
- package/layout/simple-bar.js +1 -1
- package/layout/slider-2025.js +1 -1
- package/layout/spacer.js +1 -1
- package/layout/stack.js +1 -1
- package/layout/svg.js +1 -1
- package/layout/switcher.js +1 -1
- package/layout/table.js +1 -1
- package/layout/text-field.js +1 -1
- package/layout/text.js +1 -1
- package/layout/ulist.js +1 -1
- package/layout/video.js +1 -1
- package/layout/wrap.js +1 -1
- package/layout/zoom-card.js +1 -1
- package/lib/agent-surface.js +1 -1
- package/lib/card-getter.js +1 -1
- package/lib/check-page.js +1 -1
- package/lib/codegen.js +1 -1
- package/lib/data.js +1 -1
- package/lib/designer.js +1 -1
- package/lib/element-mapper.js +1 -1
- package/lib/element-params.generated.js +1 -1
- package/lib/grid-geometry.js +1 -1
- package/lib/keyframe-animation.js +1 -1
- package/lib/known-inert.js +1 -1
- package/lib/link-getter.js +1 -1
- package/lib/morph-node.js +1 -1
- package/lib/normalize-spec.js +1 -1
- package/lib/parse-html.js +1 -1
- package/lib/raster-inspect.js +1 -1
- package/lib/raster-ops.js +1 -1
- package/lib/raster-presets.js +1 -1
- package/lib/react.js +1 -1
- package/lib/resolve-refs.js +1 -1
- package/lib/responsive.js +1 -1
- package/lib/scroll-video.js +1 -1
- package/lib/seo.js +1 -1
- package/lib/stacker.js +1 -1
- package/lib/suggest.js +1 -1
- package/lib/theme.js +1 -1
- package/lib/transform-anim.js +1 -1
- package/lib/transition.js +1 -1
- package/lib/validate-nodes.js +1 -1
- package/lib/view-transition.js +1 -1
- package/lib/webmcp-adapter.js +1 -1
- package/package.json +1 -1
- package/bin/dev-server.mjs +0 -200
- package/lib/dev-inspector.js +0 -295
- package/lib/dev-state.js +0 -257
- package/skills/nodality-apply-comments/SKILL.md +0 -52
- package/skills/nodality-current/SKILL.md +0 -69
package/bin/dev-server.mjs
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
// bin/dev-server.mjs — `npx nodality dev`: serve the site with the inspector.
|
|
2
|
-
//
|
|
3
|
-
// npx nodality dev [--upload=DIR] [--port=4000] [--watch=src,pages] [--no-reload]
|
|
4
|
-
//
|
|
5
|
-
// Serves the upload folder (from nodality.config.json, else `upload/`) on
|
|
6
|
-
// 127.0.0.1 only, and adds two things to every HTML page it serves:
|
|
7
|
-
//
|
|
8
|
-
// 1. `window.__NODALITY_DEV__`, defined before any page script runs. The
|
|
9
|
-
// Designer sees it and annotates the page and registers its (E, N)
|
|
10
|
-
// pair. Nothing else defines it, so a built page never carries it.
|
|
11
|
-
// 2. lib/dev-inspector.js, the in-page toolbar (S select, C comment).
|
|
12
|
-
//
|
|
13
|
-
// What the person points at lands in `.nodality/` in the folder this was
|
|
14
|
-
// started from (the project root, never the upload folder, so it is never
|
|
15
|
-
// deployed): current.json and comments.json, read by the agent through the
|
|
16
|
-
// MCP tools current_selection / list_comments / resolve_comment, or directly.
|
|
17
|
-
//
|
|
18
|
-
// A change to any file under the upload folder (or a --watch folder)
|
|
19
|
-
// reloads the open pages, so an agent's edit shows as soon as it is built.
|
|
20
|
-
|
|
21
|
-
import fs from "node:fs";
|
|
22
|
-
import http from "node:http";
|
|
23
|
-
import path from "node:path";
|
|
24
|
-
import { fileURLToPath } from "node:url";
|
|
25
|
-
import { readComments, writeCurrent, addComment, normalizePage, STATE_DIR } from "../lib/dev-state.js";
|
|
26
|
-
|
|
27
|
-
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
28
|
-
const INSPECTOR = path.join(HERE, "..", "lib", "dev-inspector.js");
|
|
29
|
-
const API = "/__nodality";
|
|
30
|
-
const MAX_BODY = 64 * 1024;
|
|
31
|
-
|
|
32
|
-
const TYPES = {
|
|
33
|
-
".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8",
|
|
34
|
-
".css": "text/css; charset=utf-8", ".json": "application/json; charset=utf-8", ".svg": "image/svg+xml",
|
|
35
|
-
".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp", ".gif": "image/gif",
|
|
36
|
-
".avif": "image/avif", ".ico": "image/x-icon", ".woff": "font/woff", ".woff2": "font/woff2", ".ttf": "font/ttf",
|
|
37
|
-
".mp4": "video/mp4", ".webm": "video/webm", ".mp3": "audio/mpeg", ".txt": "text/plain; charset=utf-8", ".xml": "application/xml",
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// `sourceOf` turns a stack into the page's own line that created a component
|
|
41
|
-
// (pages/index.js:60:5): the first frame on this origin that is not the
|
|
42
|
-
// library (dist/, lib/, layout/, the bundle) or the inspector. It has to exist
|
|
43
|
-
// before any page script runs, so it lives here rather than in the inspector.
|
|
44
|
-
const SOURCE_OF = `function(stack){var ls=String(stack||"").split("\\n");for(var i=0;i<ls.length;i++){` +
|
|
45
|
-
`var m=/(https?:\\/\\/[^\\s()]+?):(\\d+):(\\d+)/.exec(ls[i]);if(!m)continue;var u;try{u=new URL(m[1])}catch(e){continue}` +
|
|
46
|
-
`if(u.origin!==location.origin)continue;var p=u.pathname;` +
|
|
47
|
-
`if(/\\/(dist|lib|layout|__nodality)\\//.test(p)||/lib\\.bundle|node_modules/.test(p))continue;` +
|
|
48
|
-
`return p.replace(/^\\//,"")+":"+m[2]+":"+m[3]}return null}`;
|
|
49
|
-
|
|
50
|
-
export const DEV_SNIPPET =
|
|
51
|
-
`<script>window.__NODALITY_DEV__=window.__NODALITY_DEV__||{pages:[],annotate:true,sourceOf:${SOURCE_OF}};</script>` +
|
|
52
|
-
`<script src="${API}/inspector.js" defer></script>`;
|
|
53
|
-
|
|
54
|
-
/** Put the snippet first inside <head>, so it runs before any page script. */
|
|
55
|
-
export function injectDev(html) {
|
|
56
|
-
const m = /<head(\s[^>]*)?>/i.exec(html);
|
|
57
|
-
if (m) return html.slice(0, m.index + m[0].length) + DEV_SNIPPET + html.slice(m.index + m[0].length);
|
|
58
|
-
const d = /<!doctype[^>]*>/i.exec(html);
|
|
59
|
-
return d ? html.slice(0, d.index + d[0].length) + DEV_SNIPPET + html.slice(d.index + d[0].length) : DEV_SNIPPET + html;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function send(res, status, body, type = "application/json; charset=utf-8") {
|
|
63
|
-
res.writeHead(status, { "content-type": type, "cache-control": "no-store" });
|
|
64
|
-
res.end(typeof body === "string" || Buffer.isBuffer(body) ? body : JSON.stringify(body));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function readBody(req) {
|
|
68
|
-
return new Promise((resolve, reject) => {
|
|
69
|
-
let size = 0;
|
|
70
|
-
const chunks = [];
|
|
71
|
-
req.on("data", (c) => {
|
|
72
|
-
size += c.length;
|
|
73
|
-
if (size > MAX_BODY) { reject(new Error("too large")); req.destroy(); return; }
|
|
74
|
-
chunks.push(c);
|
|
75
|
-
});
|
|
76
|
-
req.on("end", () => {
|
|
77
|
-
try { resolve(JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}")); } catch { reject(new Error("bad json")); }
|
|
78
|
-
});
|
|
79
|
-
req.on("error", reject);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Only a page served from this machine's own name may read or write. The Host
|
|
84
|
-
// header is checked against loopback names first: with DNS rebinding an
|
|
85
|
-
// attacker's name resolves to 127.0.0.1 and sends its own Host, so comparing
|
|
86
|
-
// Origin with Host alone would let it read upload/ and post notes.
|
|
87
|
-
const LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
88
|
-
function loopbackHost(req) {
|
|
89
|
-
try { return LOOPBACK.has(new URL(`http://${req.headers.host || ""}`).hostname); } catch { return false; }
|
|
90
|
-
}
|
|
91
|
-
// Browsers send Origin on cross-site POSTs, so a foreign one is refused too.
|
|
92
|
-
function sameOrigin(req) {
|
|
93
|
-
const o = req.headers.origin;
|
|
94
|
-
if (!o) return true;
|
|
95
|
-
try { return new URL(o).host === req.headers.host; } catch { return false; }
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* The server, not yet listening — so tests can bind it to port 0.
|
|
100
|
-
* @param {{ root: string, upload: string }} opts
|
|
101
|
-
*/
|
|
102
|
-
export function createDevServer({ root, upload }) {
|
|
103
|
-
const uploadDir = path.resolve(upload);
|
|
104
|
-
const clients = new Set();
|
|
105
|
-
|
|
106
|
-
const server = http.createServer(async (req, res) => {
|
|
107
|
-
const url = new URL(req.url, "http://localhost");
|
|
108
|
-
const p = url.pathname;
|
|
109
|
-
if (!loopbackHost(req)) return send(res, 403, "nodality dev answers to localhost only", TYPES[".txt"]);
|
|
110
|
-
try {
|
|
111
|
-
if (p === `${API}/inspector.js`) return send(res, 200, fs.readFileSync(INSPECTOR), TYPES[".js"]);
|
|
112
|
-
if (p === `${API}/events`) {
|
|
113
|
-
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" });
|
|
114
|
-
res.write(": nodality dev\n\n");
|
|
115
|
-
clients.add(res);
|
|
116
|
-
req.on("close", () => clients.delete(res));
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (p === `${API}/comments` && req.method === "GET") {
|
|
120
|
-
const page = normalizePage(url.searchParams.get("page") || "/");
|
|
121
|
-
return send(res, 200, readComments(root).filter((c) => normalizePage(c.page) === page));
|
|
122
|
-
}
|
|
123
|
-
if ((p === `${API}/current` || p === `${API}/comments`) && req.method === "POST") {
|
|
124
|
-
if (!sameOrigin(req)) return send(res, 403, { ok: false, error: { code: "FOREIGN_ORIGIN" } });
|
|
125
|
-
let body;
|
|
126
|
-
try { body = await readBody(req); } catch (e) { return send(res, 400, { ok: false, error: { code: "BAD_BODY", detail: e.message } }); }
|
|
127
|
-
if (p === `${API}/current`) return send(res, 200, { ok: true, current: writeCurrent(root, body, { uploadDir }) });
|
|
128
|
-
const r = addComment(root, body, { uploadDir });
|
|
129
|
-
return send(res, r.ok ? 200 : 400, r);
|
|
130
|
-
}
|
|
131
|
-
if (p.startsWith(API)) return send(res, 404, { ok: false, error: { code: "NOT_FOUND" } });
|
|
132
|
-
if (req.method !== "GET" && req.method !== "HEAD") return send(res, 405, "method not allowed", TYPES[".txt"]);
|
|
133
|
-
|
|
134
|
-
// Static files, confined to the upload folder.
|
|
135
|
-
let rel;
|
|
136
|
-
try { rel = decodeURIComponent(p); } catch { return send(res, 400, "bad path", TYPES[".txt"]); }
|
|
137
|
-
let file = path.resolve(uploadDir, "." + path.posix.normalize("/" + rel));
|
|
138
|
-
if (file !== uploadDir && !file.startsWith(uploadDir + path.sep)) return send(res, 403, "outside the upload folder", TYPES[".txt"]);
|
|
139
|
-
if (fs.existsSync(file) && fs.statSync(file).isDirectory()) file = path.join(file, "index.html");
|
|
140
|
-
if (!fs.existsSync(file) && !path.extname(file) && fs.existsSync(file + ".html")) file += ".html";
|
|
141
|
-
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) return send(res, 404, "not found", TYPES[".txt"]);
|
|
142
|
-
const ext = path.extname(file).toLowerCase();
|
|
143
|
-
if (ext === ".html") return send(res, 200, injectDev(fs.readFileSync(file, "utf8")), TYPES[".html"]);
|
|
144
|
-
return send(res, 200, fs.readFileSync(file), TYPES[ext] || "application/octet-stream");
|
|
145
|
-
} catch (e) {
|
|
146
|
-
return send(res, 500, { ok: false, error: { code: "DEV_SERVER_FAILED", detail: String(e && e.message || e) } });
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
server.reload = () => { for (const c of clients) c.write("event: reload\ndata: {}\n\n"); };
|
|
151
|
-
server.uploadDir = uploadDir;
|
|
152
|
-
return server;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function watchForReload(server, dirs) {
|
|
156
|
-
let timer = null;
|
|
157
|
-
const fire = (file) => {
|
|
158
|
-
if (file && (String(file).includes(STATE_DIR) || /\.tmp$/.test(String(file)))) return;
|
|
159
|
-
clearTimeout(timer);
|
|
160
|
-
timer = setTimeout(() => server.reload(), 150);
|
|
161
|
-
};
|
|
162
|
-
const watchers = [];
|
|
163
|
-
for (const d of dirs) {
|
|
164
|
-
try { watchers.push(fs.watch(d, { recursive: true }, (_e, f) => fire(f))); }
|
|
165
|
-
catch (e) { console.warn(`[nodality] dev: cannot watch ${d} (${e.message}); reload by hand there`); }
|
|
166
|
-
}
|
|
167
|
-
server.on("close", () => watchers.forEach((w) => w.close()));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export async function runDev(args) {
|
|
171
|
-
const flag = (name) => { const a = args.find((x) => x.startsWith(`--${name}=`)); return a ? a.slice(name.length + 3) : null; };
|
|
172
|
-
const root = process.cwd();
|
|
173
|
-
let upload = flag("upload");
|
|
174
|
-
if (!upload) {
|
|
175
|
-
try { upload = JSON.parse(fs.readFileSync(path.join(root, "nodality.config.json"), "utf8")).uploadDir; } catch {}
|
|
176
|
-
}
|
|
177
|
-
upload = path.resolve(root, upload || "upload");
|
|
178
|
-
if (!fs.existsSync(upload)) {
|
|
179
|
-
console.error(`[nodality] dev: no upload folder at ${upload}. Pass --upload=DIR.`);
|
|
180
|
-
process.exitCode = 1;
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const port = Number(flag("port") || 4000);
|
|
184
|
-
const server = createDevServer({ root, upload });
|
|
185
|
-
if (!args.includes("--no-reload")) {
|
|
186
|
-
const extra = (flag("watch") || "").split(",").filter(Boolean).map((d) => path.resolve(root, d));
|
|
187
|
-
watchForReload(server, [upload, ...extra]);
|
|
188
|
-
}
|
|
189
|
-
await new Promise((resolve, reject) => {
|
|
190
|
-
server.once("error", reject);
|
|
191
|
-
server.listen(port, "127.0.0.1", resolve);
|
|
192
|
-
}).catch((e) => {
|
|
193
|
-
console.error(`[nodality] dev: cannot listen on 127.0.0.1:${port} (${e.code || e.message}). Try --port=4001.`);
|
|
194
|
-
process.exit(1);
|
|
195
|
-
});
|
|
196
|
-
console.log(`[nodality] dev: http://localhost:${server.address().port}/ (serving ${path.relative(root, upload) || "."})`);
|
|
197
|
-
console.log(`[nodality] dev: S select · C comment · Esc off. Picks and notes go to ${path.join(STATE_DIR, "current.json")} and ${path.join(STATE_DIR, "comments.json")}.`);
|
|
198
|
-
console.log(`[nodality] dev: add ${STATE_DIR}/ to .gitignore if the notes should stay on this machine.`);
|
|
199
|
-
await new Promise(() => {});
|
|
200
|
-
}
|
package/lib/dev-inspector.js
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* nodality v1.5.1
|
|
3
|
-
* (c) 2026 Filip Vabrousek
|
|
4
|
-
* License: MIT
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/*!
|
|
8
|
-
* dev-inspector.js — the in-page half of `nodality dev`.
|
|
9
|
-
*
|
|
10
|
-
* Served by the dev server only; never imported, never bundled, never in a
|
|
11
|
-
* built page. It lets a person point at what they mean and leaves the
|
|
12
|
-
* meaning in two files an agent reads (see lib/dev-state.js):
|
|
13
|
-
*
|
|
14
|
-
* S select: click an element → .nodality/current.json
|
|
15
|
-
* C comment: click an element, or drag across several, and type a
|
|
16
|
-
* note → .nodality/comments.json
|
|
17
|
-
* Esc off: the page behaves as a page again (the starting state)
|
|
18
|
-
*
|
|
19
|
-
* It finds elements by their `id`, which every Nodality element renders, and
|
|
20
|
-
* reads the (E, N) pair the Designer registers in __NODALITY_DEV__.pages to
|
|
21
|
-
* report which nodes target the pick and which width ranges are in force.
|
|
22
|
-
* Everything it draws lives in one shadow root, so page styles cannot reach
|
|
23
|
-
* it and it never edits the page's own nodes.
|
|
24
|
-
*/
|
|
25
|
-
(function () {
|
|
26
|
-
if (typeof window === "undefined" || window.__NODALITY_INSPECTOR__) return;
|
|
27
|
-
window.__NODALITY_INSPECTOR__ = true;
|
|
28
|
-
const DEV = (window.__NODALITY_DEV__ = window.__NODALITY_DEV__ || { pages: [], annotate: true });
|
|
29
|
-
const API = "/__nodality";
|
|
30
|
-
const PAGE = location.pathname;
|
|
31
|
-
|
|
32
|
-
// ── the pair: id → spec, node indexes, ranges ──────────────────────
|
|
33
|
-
let index = new Map();
|
|
34
|
-
const bare = (s) => (typeof s === "string" ? s.replace(/^#/, "") : null);
|
|
35
|
-
function names(v, out) {
|
|
36
|
-
if (typeof v === "string") out.push(bare(v));
|
|
37
|
-
else if (Array.isArray(v)) v.forEach((x) => names(x, out));
|
|
38
|
-
else if (v && typeof v === "object") Object.values(v).forEach((x) => names(x, out));
|
|
39
|
-
return out;
|
|
40
|
-
}
|
|
41
|
-
function walk(list, visit) {
|
|
42
|
-
for (const el of Array.isArray(list) ? list : []) {
|
|
43
|
-
if (Array.isArray(el)) { walk(el, visit); continue; }
|
|
44
|
-
if (!el || typeof el !== "object") continue;
|
|
45
|
-
if (typeof el.id === "string") visit(el);
|
|
46
|
-
walk(el.children, visit);
|
|
47
|
-
if (Array.isArray(el.items)) walk(el.items, visit);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function rebuild() {
|
|
51
|
-
index = new Map();
|
|
52
|
-
for (const pg of DEV.pages) {
|
|
53
|
-
walk(pg.elements, (el) => { if (!index.has(el.id)) index.set(el.id, { spec: el, nodes: [], ranges: [] }); });
|
|
54
|
-
(pg.nodes || []).forEach((n, i) => {
|
|
55
|
-
if (!n || typeof n !== "object") return;
|
|
56
|
-
const hit = names([n.target, n.from, n.to], []);
|
|
57
|
-
if (Array.isArray(n.chain)) n.chain.forEach((e) => names([e && e.from, e && e.to], hit));
|
|
58
|
-
for (const id of new Set(hit)) {
|
|
59
|
-
const rec = index.get(id);
|
|
60
|
-
if (!rec) continue;
|
|
61
|
-
rec.nodes.push(i);
|
|
62
|
-
if (Array.isArray(n.range)) rec.ranges.push({ node: i, range: n.range });
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
window.addEventListener("nodality:rendered", () => { rebuild(); drawPins(); });
|
|
68
|
-
|
|
69
|
-
// ── shadow UI ──────────────────────────────────────────────────────
|
|
70
|
-
const host = document.createElement("div");
|
|
71
|
-
host.setAttribute("data-nodality", "dev-inspector");
|
|
72
|
-
host.style.cssText = "position:fixed;inset:0;pointer-events:none;z-index:2147483647";
|
|
73
|
-
const root = host.attachShadow({ mode: "open" });
|
|
74
|
-
root.innerHTML = `<style>
|
|
75
|
-
:host{all:initial}
|
|
76
|
-
*{box-sizing:border-box;font:12px/1.4 -apple-system,system-ui,sans-serif}
|
|
77
|
-
.box{position:fixed;border:1.5px solid #378ADD;border-radius:3px;display:none;pointer-events:none}
|
|
78
|
-
.box.sel{border:2px solid #185FA5;background:rgba(55,138,221,.08)}
|
|
79
|
-
.lab{position:absolute;top:-20px;left:-2px;background:#185FA5;color:#fff;padding:1px 6px;border-radius:3px;white-space:nowrap;font:11px ui-monospace,Menlo,monospace}
|
|
80
|
-
.drag{position:fixed;border:1.5px dashed #BA7517;background:rgba(239,159,39,.08);display:none}
|
|
81
|
-
.pin{position:fixed;width:18px;height:18px;border-radius:50%;background:#FAC775;color:#633806;border:1px solid #BA7517;display:flex;align-items:center;justify-content:center;font-size:11px;pointer-events:auto;cursor:default}
|
|
82
|
-
.bar{position:fixed;right:12px;bottom:12px;background:#fff;color:#2C2C2A;border:1px solid #D3D1C7;border-radius:10px;padding:6px;display:flex;flex-direction:column;gap:6px;pointer-events:auto;min-width:220px}
|
|
83
|
-
.row{display:flex;gap:6px;align-items:center}
|
|
84
|
-
button{border:1px solid #D3D1C7;background:#fff;color:#2C2C2A;border-radius:6px;padding:3px 8px;cursor:pointer}
|
|
85
|
-
button.on{background:#E6F1FB;color:#0C447C;border-color:#378ADD}
|
|
86
|
-
.st{color:#5F5E5A;margin-left:auto;font-size:11px}
|
|
87
|
-
input{flex:1;border:1px solid #B4B2A9;border-radius:6px;padding:4px 6px;min-width:0}
|
|
88
|
-
.err{color:#A32D2D;font-size:11px}
|
|
89
|
-
.note{display:none}
|
|
90
|
-
</style>
|
|
91
|
-
<div class="box" id="hover"><span class="lab"></span></div>
|
|
92
|
-
<div class="box sel" id="sel"><span class="lab"></span></div>
|
|
93
|
-
<div class="drag" id="drag"></div>
|
|
94
|
-
<div id="pins"></div>
|
|
95
|
-
<div class="bar">
|
|
96
|
-
<div class="row"><button id="bS">Select (S)</button><button id="bC">Comment (C)</button><span class="st" id="st"></span></div>
|
|
97
|
-
<div class="row note" id="noteRow"><input id="note" maxlength="2000" placeholder="what should change here?"><button id="add">Add</button></div>
|
|
98
|
-
<div class="err" id="err"></div>
|
|
99
|
-
</div>`;
|
|
100
|
-
const $ = (id) => root.getElementById(id);
|
|
101
|
-
const mount = () => { if (!host.isConnected) document.body.appendChild(host); };
|
|
102
|
-
if (document.body) mount(); else document.addEventListener("DOMContentLoaded", mount);
|
|
103
|
-
|
|
104
|
-
let mode = "off";
|
|
105
|
-
let pending = null; // { target: [ids], rect } awaiting a note
|
|
106
|
-
function setMode(m) {
|
|
107
|
-
mode = mode === m ? "off" : m;
|
|
108
|
-
$("bS").classList.toggle("on", mode === "select");
|
|
109
|
-
$("bC").classList.toggle("on", mode === "comment");
|
|
110
|
-
if (mode !== "comment") { pending = null; $("noteRow").style.display = "none"; }
|
|
111
|
-
$("hover").style.display = "none";
|
|
112
|
-
status();
|
|
113
|
-
}
|
|
114
|
-
function status(msg) {
|
|
115
|
-
$("st").textContent = msg || `${mode === "off" ? "off" : mode} · ${innerWidth}px`;
|
|
116
|
-
}
|
|
117
|
-
$("bS").onclick = () => setMode("select");
|
|
118
|
-
$("bC").onclick = () => setMode("comment");
|
|
119
|
-
status();
|
|
120
|
-
|
|
121
|
-
// ── finding what was pointed at ─────────────────────────────────────
|
|
122
|
-
const ours = (e) => e.composedPath && e.composedPath().includes(host);
|
|
123
|
-
// An element is addressable by an id from the pair (or any id, on a page
|
|
124
|
-
// with no pair), or — on a page written with the imperative layer — by the
|
|
125
|
-
// line that created it (data-nod-src, set in dev by the component base).
|
|
126
|
-
const idOk = (n) => n.id && n !== host && (index.size === 0 || index.has(n.id));
|
|
127
|
-
const srcOf = (n) => (n.getAttribute && n.getAttribute("data-nod-src")) || null;
|
|
128
|
-
function known(node) {
|
|
129
|
-
for (let n = node; n && n !== document.documentElement; n = n.parentElement) {
|
|
130
|
-
if (idOk(n) || srcOf(n)) return n;
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
function label(node) {
|
|
135
|
-
const rec = idOk(node) ? index.get(node.id) : null;
|
|
136
|
-
const kind = (rec && rec.spec.type) || node.tagName.toLowerCase();
|
|
137
|
-
if (idOk(node)) return `#${node.id} · ${kind}`;
|
|
138
|
-
return `${srcOf(node).replace(/:\d+$/, "")} · ${kind}`;
|
|
139
|
-
}
|
|
140
|
-
function place(box, node) {
|
|
141
|
-
const r = node.getBoundingClientRect();
|
|
142
|
-
Object.assign(box.style, { display: "block", left: r.left - 3 + "px", top: r.top - 3 + "px", width: r.width + 6 + "px", height: r.height + 6 + "px" });
|
|
143
|
-
box.querySelector(".lab").textContent = label(node);
|
|
144
|
-
}
|
|
145
|
-
function describe(nodes) {
|
|
146
|
-
const first = nodes[0];
|
|
147
|
-
const rec = (idOk(first) && index.get(first.id)) || { spec: {}, nodes: [], ranges: [] };
|
|
148
|
-
const w = innerWidth;
|
|
149
|
-
return {
|
|
150
|
-
ids: nodes.filter(idOk).map((n) => n.id),
|
|
151
|
-
src: srcOf(first),
|
|
152
|
-
type: rec.spec.type || null,
|
|
153
|
-
tag: first.tagName.toLowerCase(),
|
|
154
|
-
text: (first.textContent || "").replace(/\s+/g, " ").trim().slice(0, 120),
|
|
155
|
-
nodesTargeting: rec.nodes,
|
|
156
|
-
activeRanges: rec.ranges.filter(({ range: [a, b] }) => w >= (a ?? 0) && w <= (b ?? Infinity)),
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
const post = (path, body) => fetch(API + path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) })
|
|
160
|
-
.then((r) => r.json()).catch(() => ({ ok: false }));
|
|
161
|
-
const viewport = () => ({ width: innerWidth, height: innerHeight });
|
|
162
|
-
|
|
163
|
-
// ── select ─────────────────────────────────────────────────────────
|
|
164
|
-
let selected = null;
|
|
165
|
-
function select(node) {
|
|
166
|
-
selected = node;
|
|
167
|
-
place($("sel"), node);
|
|
168
|
-
post("/current", { page: PAGE, viewport: viewport(), selection: describe([node]) })
|
|
169
|
-
.then((r) => status(r.ok ? `picked ${label(node).split(" · ")[0]}` : "could not save the pick"));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// ── comment: click one element, or drag across several ─────────────
|
|
173
|
-
let drag = null;
|
|
174
|
-
let skipClick = false; // the click a finished drag also fires
|
|
175
|
-
function askNote(target, rect, src) {
|
|
176
|
-
pending = { target, rect, src: src || null };
|
|
177
|
-
$("noteRow").style.display = "flex";
|
|
178
|
-
$("err").textContent = "";
|
|
179
|
-
$("note").value = "";
|
|
180
|
-
$("note").focus();
|
|
181
|
-
status(`note on ${target.length ? target.map((t) => "#" + t).join(", ") : String(src).replace(/:\d+$/, "")}`);
|
|
182
|
-
}
|
|
183
|
-
function addNote() {
|
|
184
|
-
const note = $("note").value.trim();
|
|
185
|
-
if (!note) { $("err").textContent = "Write a note first."; return; }
|
|
186
|
-
post("/comments", { page: PAGE, viewport: viewport(), target: pending.target, rect: pending.rect, src: pending.src, note })
|
|
187
|
-
.then((r) => {
|
|
188
|
-
if (!r.ok) { $("err").textContent = "The note was not saved."; return; }
|
|
189
|
-
pending = null;
|
|
190
|
-
$("noteRow").style.display = "none";
|
|
191
|
-
status("note saved");
|
|
192
|
-
loadPins();
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
$("add").onclick = addNote;
|
|
196
|
-
$("note").addEventListener("keydown", (e) => { if (e.key === "Enter") addNote(); e.stopPropagation(); });
|
|
197
|
-
$("note").addEventListener("input", () => { $("err").textContent = ""; });
|
|
198
|
-
|
|
199
|
-
// ── pins ───────────────────────────────────────────────────────────
|
|
200
|
-
let pins = [];
|
|
201
|
-
function loadPins() {
|
|
202
|
-
fetch(`${API}/comments?page=${encodeURIComponent(PAGE)}`).then((r) => r.json())
|
|
203
|
-
.then((list) => { pins = (Array.isArray(list) ? list : []).filter((c) => c.status === "open"); drawPins(); })
|
|
204
|
-
.catch(() => {});
|
|
205
|
-
}
|
|
206
|
-
function drawPins() {
|
|
207
|
-
const box = $("pins");
|
|
208
|
-
box.textContent = "";
|
|
209
|
-
pins.forEach((c, i) => {
|
|
210
|
-
const node = c.target.length ? document.getElementById(c.target[0])
|
|
211
|
-
: c.source ? [...document.querySelectorAll("[data-nod-src]")].find((n) => srcOf(n).startsWith(`${c.source.file}:${c.source.line}:`)) : null;
|
|
212
|
-
if (!node) return;
|
|
213
|
-
const r = node.getBoundingClientRect();
|
|
214
|
-
const p = document.createElement("div");
|
|
215
|
-
p.className = "pin";
|
|
216
|
-
p.textContent = String(i + 1);
|
|
217
|
-
p.title = c.note;
|
|
218
|
-
p.style.left = r.right - 9 + "px";
|
|
219
|
-
p.style.top = r.top - 9 + "px";
|
|
220
|
-
box.appendChild(p);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
let raf = 0;
|
|
224
|
-
const redraw = () => {
|
|
225
|
-
cancelAnimationFrame(raf);
|
|
226
|
-
raf = requestAnimationFrame(() => { drawPins(); if (selected && selected.isConnected) place($("sel"), selected); status(); });
|
|
227
|
-
};
|
|
228
|
-
addEventListener("scroll", redraw, true);
|
|
229
|
-
addEventListener("resize", redraw);
|
|
230
|
-
|
|
231
|
-
// ── events: capture phase, so the page never sees an inspector click ──
|
|
232
|
-
document.addEventListener("mousemove", (e) => {
|
|
233
|
-
if (mode === "off" || ours(e)) return;
|
|
234
|
-
if (drag) {
|
|
235
|
-
const x = Math.min(drag.x, e.clientX), y = Math.min(drag.y, e.clientY);
|
|
236
|
-
const w = Math.abs(e.clientX - drag.x), h = Math.abs(e.clientY - drag.y);
|
|
237
|
-
if (w + h > 6) { drag.moved = true; Object.assign($("drag").style, { display: "block", left: x + "px", top: y + "px", width: w + "px", height: h + "px" }); }
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const node = known(e.target);
|
|
241
|
-
if (node) place($("hover"), node); else $("hover").style.display = "none";
|
|
242
|
-
}, true);
|
|
243
|
-
document.addEventListener("mousedown", (e) => {
|
|
244
|
-
if (mode !== "comment" || ours(e)) return;
|
|
245
|
-
e.preventDefault();
|
|
246
|
-
drag = { x: e.clientX, y: e.clientY, moved: false };
|
|
247
|
-
}, true);
|
|
248
|
-
document.addEventListener("mouseup", (e) => {
|
|
249
|
-
if (!drag) return;
|
|
250
|
-
const d = drag; drag = null;
|
|
251
|
-
$("drag").style.display = "none";
|
|
252
|
-
if (!d.moved) return;
|
|
253
|
-
skipClick = true;
|
|
254
|
-
const box = { l: Math.min(d.x, e.clientX), t: Math.min(d.y, e.clientY), r: Math.max(d.x, e.clientX), b: Math.max(d.y, e.clientY) };
|
|
255
|
-
const inside = [...document.querySelectorAll("[id], [data-nod-src]")].filter((n) => {
|
|
256
|
-
if (n === host || !(idOk(n) || srcOf(n))) return false;
|
|
257
|
-
const r = n.getBoundingClientRect();
|
|
258
|
-
return r.width > 0 && r.left >= box.l && r.right <= box.r && r.top >= box.t && r.bottom <= box.b;
|
|
259
|
-
});
|
|
260
|
-
const outer = inside.filter((n) => !inside.some((m) => m !== n && m.contains(n)));
|
|
261
|
-
if (!outer.length) { status("nothing addressable inside that area"); return; }
|
|
262
|
-
askNote(outer.filter(idOk).map((n) => n.id), { x: box.l + scrollX, y: box.t + scrollY, w: box.r - box.l, h: box.b - box.t }, srcOf(outer[0]));
|
|
263
|
-
}, true);
|
|
264
|
-
document.addEventListener("click", (e) => {
|
|
265
|
-
if (mode === "off" || ours(e)) return;
|
|
266
|
-
e.preventDefault();
|
|
267
|
-
e.stopPropagation();
|
|
268
|
-
if (skipClick) { skipClick = false; return; }
|
|
269
|
-
const node = known(e.target);
|
|
270
|
-
if (!node) { status("nothing addressable here: no id, no source line"); return; }
|
|
271
|
-
if (mode === "select") select(node);
|
|
272
|
-
else askNote(idOk(node) ? [node.id] : [], null, srcOf(node));
|
|
273
|
-
}, true);
|
|
274
|
-
document.addEventListener("keydown", (e) => {
|
|
275
|
-
if (ours(e)) return;
|
|
276
|
-
const t = e.target;
|
|
277
|
-
if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;
|
|
278
|
-
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
|
279
|
-
if (e.key === "s" || e.key === "S") setMode("select");
|
|
280
|
-
else if (e.key === "c" || e.key === "C") setMode("comment");
|
|
281
|
-
else if (e.key === "Escape" && mode !== "off") setMode(mode);
|
|
282
|
-
}, true);
|
|
283
|
-
|
|
284
|
-
// ── reload when the site changes; report the page on arrival ───────
|
|
285
|
-
try {
|
|
286
|
-
const es = new EventSource(`${API}/events`);
|
|
287
|
-
es.addEventListener("reload", () => location.reload());
|
|
288
|
-
} catch { /* no live reload; everything else still works */ }
|
|
289
|
-
rebuild();
|
|
290
|
-
addEventListener("load", () => {
|
|
291
|
-
rebuild();
|
|
292
|
-
loadPins();
|
|
293
|
-
post("/current", { page: PAGE, viewport: viewport(), selection: null });
|
|
294
|
-
});
|
|
295
|
-
})();
|