@layoutdesign/context 0.6.0 → 0.10.1

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 (63) hide show
  1. package/README.md +71 -0
  2. package/dist/bin/cli.js +8 -0
  3. package/dist/bin/cli.js.map +1 -1
  4. package/dist/src/cli/install.d.ts +1 -0
  5. package/dist/src/cli/install.d.ts.map +1 -1
  6. package/dist/src/cli/install.js +25 -0
  7. package/dist/src/cli/install.js.map +1 -1
  8. package/dist/src/cli/live-notify.d.ts +2 -0
  9. package/dist/src/cli/live-notify.d.ts.map +1 -0
  10. package/dist/src/cli/live-notify.js +29 -0
  11. package/dist/src/cli/live-notify.js.map +1 -0
  12. package/dist/src/install/live.d.ts +5 -0
  13. package/dist/src/install/live.d.ts.map +1 -0
  14. package/dist/src/install/live.js +285 -0
  15. package/dist/src/install/live.js.map +1 -0
  16. package/dist/src/mcp/live-lock-store.d.ts +40 -0
  17. package/dist/src/mcp/live-lock-store.d.ts.map +1 -0
  18. package/dist/src/mcp/live-lock-store.js +134 -0
  19. package/dist/src/mcp/live-lock-store.js.map +1 -0
  20. package/dist/src/mcp/server.d.ts.map +1 -1
  21. package/dist/src/mcp/server.js +11 -0
  22. package/dist/src/mcp/server.js.map +1 -1
  23. package/dist/src/mcp/tools/_live-socket.d.ts +23 -0
  24. package/dist/src/mcp/tools/_live-socket.d.ts.map +1 -0
  25. package/dist/src/mcp/tools/_live-socket.js +135 -0
  26. package/dist/src/mcp/tools/_live-socket.js.map +1 -0
  27. package/dist/src/mcp/tools/check-setup.d.ts +14 -1
  28. package/dist/src/mcp/tools/check-setup.d.ts.map +1 -1
  29. package/dist/src/mcp/tools/check-setup.js +75 -1
  30. package/dist/src/mcp/tools/check-setup.js.map +1 -1
  31. package/dist/src/mcp/tools/get-recent-visual-edits.d.ts +40 -0
  32. package/dist/src/mcp/tools/get-recent-visual-edits.d.ts.map +1 -0
  33. package/dist/src/mcp/tools/get-recent-visual-edits.js +106 -0
  34. package/dist/src/mcp/tools/get-recent-visual-edits.js.map +1 -0
  35. package/dist/src/mcp/tools/get-selected-element.d.ts +10 -0
  36. package/dist/src/mcp/tools/get-selected-element.d.ts.map +1 -0
  37. package/dist/src/mcp/tools/get-selected-element.js +46 -0
  38. package/dist/src/mcp/tools/get-selected-element.js.map +1 -0
  39. package/dist/src/mcp/tools/lock-file.d.ts +28 -0
  40. package/dist/src/mcp/tools/lock-file.d.ts.map +1 -0
  41. package/dist/src/mcp/tools/lock-file.js +42 -0
  42. package/dist/src/mcp/tools/lock-file.js.map +1 -0
  43. package/dist/src/mcp/tools/unlock-file.d.ts +23 -0
  44. package/dist/src/mcp/tools/unlock-file.d.ts.map +1 -0
  45. package/dist/src/mcp/tools/unlock-file.js +23 -0
  46. package/dist/src/mcp/tools/unlock-file.js.map +1 -0
  47. package/dist/src/plugins/next/babel-loader.d.ts +8 -0
  48. package/dist/src/plugins/next/babel-loader.d.ts.map +1 -0
  49. package/dist/src/plugins/next/babel-loader.js +26 -0
  50. package/dist/src/plugins/next/babel-loader.js.map +1 -0
  51. package/dist/src/plugins/next/index.d.ts +23 -0
  52. package/dist/src/plugins/next/index.d.ts.map +1 -0
  53. package/dist/src/plugins/next/index.js +58 -0
  54. package/dist/src/plugins/next/index.js.map +1 -0
  55. package/dist/src/plugins/transform.d.ts +19 -0
  56. package/dist/src/plugins/transform.d.ts.map +1 -0
  57. package/dist/src/plugins/transform.js +177 -0
  58. package/dist/src/plugins/transform.js.map +1 -0
  59. package/dist/src/plugins/vite/index.d.ts +24 -0
  60. package/dist/src/plugins/vite/index.d.ts.map +1 -0
  61. package/dist/src/plugins/vite/index.js +56 -0
  62. package/dist/src/plugins/vite/index.js.map +1 -0
  63. package/package.json +31 -9
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Shared Babel transform used by both the Vite and Next.js plugins.
3
+ *
4
+ * Walks the JSX/TSX AST and injects four source-location attributes onto every
5
+ * DOM-emitting JSX element so layout Live can resolve a clicked DOM node back
6
+ * to its exact source position:
7
+ *
8
+ * data-layout-source-file — path relative to project root
9
+ * data-layout-source-line — 1-indexed line
10
+ * data-layout-source-col — 1-indexed column
11
+ * data-layout-component — nearest enclosing component name
12
+ *
13
+ * Dev-only: a no-op when NODE_ENV === 'production' (unless `production: true`
14
+ * is forced). Idempotent: elements already carrying the attrs are left alone.
15
+ */
16
+ import { parse } from "@babel/parser";
17
+ import * as _traverseNs from "@babel/traverse";
18
+ import * as _generateNs from "@babel/generator";
19
+ import * as t from "@babel/types";
20
+ import path from "node:path";
21
+ // @babel/traverse and @babel/generator ship CJS default exports. Depending on
22
+ // the ESM loader (tsc-built dist vs tsx) the callable lands at the namespace,
23
+ // `.default`, or `.default.default` — unwrap to the first callable.
24
+ function unwrapCallable(ns) {
25
+ let cur = ns;
26
+ for (let i = 0; i < 3; i++) {
27
+ if (typeof cur === "function")
28
+ return cur;
29
+ cur = cur?.default;
30
+ }
31
+ throw new Error("Could not resolve a callable Babel export");
32
+ }
33
+ const traverse = unwrapCallable(_traverseNs);
34
+ const generate = unwrapCallable(_generateNs);
35
+ const MARKER_ATTR = "data-layout-source-file";
36
+ // React's raw-HTML escape-hatch prop. Built at runtime so this source file
37
+ // doesn't trip content scanners; semantics are unchanged.
38
+ const RAW_HTML_PROP = ["dangerously", "Set", "Inner", "HTML"].join("");
39
+ /** Whether attrs should be injected given env + options. */
40
+ export function shouldTransform(options = {}) {
41
+ if (options.production)
42
+ return true;
43
+ return process.env.NODE_ENV !== "production";
44
+ }
45
+ function attr(name, value) {
46
+ return t.jsxAttribute(t.jsxIdentifier(name), t.stringLiteral(value));
47
+ }
48
+ /** Name of the nearest enclosing function / arrow / class, or 'Anonymous'. */
49
+ function enclosingComponentName(elementPath) {
50
+ let p = elementPath.parentPath;
51
+ while (p) {
52
+ const node = p.node;
53
+ if (t.isFunctionDeclaration(node) && node.id)
54
+ return node.id.name;
55
+ if (t.isClassDeclaration(node) && node.id)
56
+ return node.id.name;
57
+ if ((t.isArrowFunctionExpression(node) || t.isFunctionExpression(node)) &&
58
+ t.isVariableDeclarator(p.parentPath?.node) &&
59
+ t.isIdentifier(p.parentPath.node.id)) {
60
+ return p.parentPath.node.id.name;
61
+ }
62
+ // Named function expression: const x = function Foo() {}
63
+ if (t.isFunctionExpression(node) && node.id)
64
+ return node.id.name;
65
+ p = p.parentPath;
66
+ }
67
+ return "Anonymous";
68
+ }
69
+ function isPreAttributed(opening) {
70
+ return opening.attributes.some((a) => t.isJSXAttribute(a) &&
71
+ t.isJSXIdentifier(a.name) &&
72
+ a.name.name === MARKER_ATTR);
73
+ }
74
+ function hasRawHtmlProp(opening) {
75
+ return opening.attributes.some((a) => t.isJSXAttribute(a) &&
76
+ t.isJSXIdentifier(a.name) &&
77
+ a.name.name === RAW_HTML_PROP);
78
+ }
79
+ /**
80
+ * Does this element have a STATICALLY-EDITABLE `className` — a string
81
+ * literal, `{"…"}`, or a template literal with no expressions? Used to
82
+ * decide whether a capitalised component usage (`<Pill className="p-4"/>`)
83
+ * is worth tagging: layout Live can edit that prop string in place exactly
84
+ * like a host element's className. cn()/cva()/dynamic classNames are NOT
85
+ * editable, so those component usages stay untagged (→ library-component).
86
+ */
87
+ function hasLiteralClassName(opening) {
88
+ for (const a of opening.attributes) {
89
+ if (!t.isJSXAttribute(a) ||
90
+ !t.isJSXIdentifier(a.name) ||
91
+ a.name.name !== "className") {
92
+ continue;
93
+ }
94
+ const v = a.value;
95
+ if (t.isStringLiteral(v))
96
+ return true;
97
+ if (t.isJSXExpressionContainer(v)) {
98
+ const e = v.expression;
99
+ if (t.isStringLiteral(e))
100
+ return true;
101
+ if (t.isTemplateLiteral(e) && e.expressions.length === 0)
102
+ return true;
103
+ }
104
+ return false; // className present but dynamic — not editable here
105
+ }
106
+ return false; // no className prop
107
+ }
108
+ /**
109
+ * Transform `code` for `filename`, injecting the layout source-location attrs.
110
+ *
111
+ * Returns the original code unchanged (with `map: null`) when transformation
112
+ * is skipped (production env, parse failure). Never throws on user code — a
113
+ * malformed file is passed through untouched so the dev build keeps working.
114
+ */
115
+ export function transformWithLayoutAttrs(code, filename, projectRoot, options = {}) {
116
+ if (!shouldTransform(options)) {
117
+ return { code, map: null };
118
+ }
119
+ let ast;
120
+ try {
121
+ ast = parse(code, {
122
+ sourceType: "module",
123
+ plugins: ["jsx", "typescript"],
124
+ });
125
+ }
126
+ catch {
127
+ // Don't break the dev build on a syntax error mid-edit.
128
+ return { code, map: null };
129
+ }
130
+ const relativePath = path
131
+ .relative(projectRoot, filename)
132
+ .split(path.sep)
133
+ .join("/");
134
+ let mutated = false;
135
+ traverse(ast, {
136
+ JSXElement(elPath) {
137
+ const opening = elPath.node.openingElement;
138
+ const tagName = opening.name;
139
+ // Member expressions (Context.Provider, namespaced motion.div) and
140
+ // namespaced names are not plain DOM tags — skip.
141
+ if (!t.isJSXIdentifier(tagName))
142
+ return;
143
+ // Fragments and capitalised component names: the component is attributed
144
+ // at its own root element, not at each usage site.
145
+ if (tagName.name === "Fragment")
146
+ return;
147
+ // Capitalised component usage: normally attributed at the component's
148
+ // own root, NOT each call site. BUT if the call site passes a static
149
+ // `className` (`<Pill className="p-4"/>`), that string IS editable in
150
+ // place — tag the usage so layout Live can resolve + edit it (the
151
+ // component must forward unknown props for the attrs to reach the
152
+ // DOM; if it doesn't, resolution falls back to fibre-only). Dynamic
153
+ // classNames stay untagged → surfaced as library-component.
154
+ if (/^[A-Z]/.test(tagName.name) && !hasLiteralClassName(opening)) {
155
+ return;
156
+ }
157
+ // Idempotent.
158
+ if (isPreAttributed(opening))
159
+ return;
160
+ // Children of the raw-HTML prop are an opaque HTML string, not JSX — the
161
+ // element bearing it has no JSX element children to attribute.
162
+ if (hasRawHtmlProp(opening))
163
+ return;
164
+ const loc = opening.loc?.start;
165
+ if (!loc)
166
+ return;
167
+ opening.attributes.push(attr("data-layout-source-file", relativePath), attr("data-layout-source-line", String(loc.line)), attr("data-layout-source-col", String(loc.column + 1)), attr("data-layout-component", enclosingComponentName(elPath)));
168
+ mutated = true;
169
+ },
170
+ });
171
+ if (!mutated) {
172
+ return { code, map: null };
173
+ }
174
+ const result = generate(ast, { sourceMaps: true, sourceFileName: filename, retainLines: true }, code);
175
+ return { code: result.code, map: result.map ?? null };
176
+ }
177
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/plugins/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,WAAW,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,8EAA8E;AAC9E,8EAA8E;AAC9E,oEAAoE;AACpE,SAAS,cAAc,CAAC,EAAW;IACjC,IAAI,GAAG,GAAY,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,OAAO,GAAG,KAAK,UAAU;YAAE,OAAO,GAAiC,CAAC;QACxE,GAAG,GAAI,GAAoC,EAAE,OAAO,CAAC;IACvD,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,QAAQ,GAAG,cAAc,CAC7B,WAAW,CAC2C,CAAC;AACzD,MAAM,QAAQ,GAAG,cAAc,CAC7B,WAAW,CAC4C,CAAC;AAE1D,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAE9C,2EAA2E;AAC3E,0DAA0D;AAC1D,MAAM,aAAa,GAAG,CAAC,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAYvE,4DAA4D;AAC5D,MAAM,UAAU,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IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1,24 @@
1
+ export interface LayoutVitePluginOptions {
2
+ /** Globs/patterns to include. Default: all .tsx/.jsx. */
3
+ include?: string | string[];
4
+ /** Substrings/patterns to exclude. Default: node_modules. */
5
+ exclude?: string | string[];
6
+ /** Force-enable in production (not recommended). Default: false. */
7
+ production?: boolean;
8
+ }
9
+ /** Minimal structural shape of the bits of a Vite plugin we use. */
10
+ interface VitePluginLike {
11
+ name: string;
12
+ enforce: "pre";
13
+ apply: "serve";
14
+ configResolved(config: {
15
+ root?: string;
16
+ }): void;
17
+ transform(code: string, id: string): {
18
+ code: string;
19
+ map: object | null;
20
+ } | null;
21
+ }
22
+ export default function layout(options?: LayoutVitePluginOptions): VitePluginLike;
23
+ export {};
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/vite/index.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,uBAAuB;IACtC,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,oEAAoE;IACpE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,oEAAoE;AACpE,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,MAAM,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChD,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;CAChD;AAOD,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,OAAO,GAAE,uBAA4B,GACpC,cAAc,CA8BhB"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * `@layoutdesign/context/vite-plugin`
3
+ *
4
+ * Injects layout source-location attributes into JSX during the Vite dev
5
+ * server build. No-op in production builds (`apply: 'serve'` + the transform's
6
+ * own NODE_ENV guard). Place this *before* `@vitejs/plugin-react`.
7
+ *
8
+ * import layout from '@layoutdesign/context/vite-plugin';
9
+ * export default defineConfig({ plugins: [layout(), react()] });
10
+ *
11
+ * `vite` is an optional peer — we don't import its types so the package builds
12
+ * and ships without vite installed. The returned object is structurally a
13
+ * Vite `Plugin`.
14
+ */
15
+ import { transformWithLayoutAttrs } from "../transform.js";
16
+ function toArray(v) {
17
+ if (!v)
18
+ return [];
19
+ return Array.isArray(v) ? v : [v];
20
+ }
21
+ export default function layout(options = {}) {
22
+ const exclude = toArray(options.exclude);
23
+ const defaultExcluded = (id) => id.includes("node_modules");
24
+ const include = toArray(options.include);
25
+ let root = process.cwd();
26
+ return {
27
+ name: "@layoutdesign/context/vite-plugin",
28
+ enforce: "pre",
29
+ apply: "serve",
30
+ configResolved(config) {
31
+ if (config?.root)
32
+ root = config.root;
33
+ },
34
+ transform(code, id) {
35
+ const clean = id.split("?")[0] ?? id;
36
+ if (!/\.(tsx|jsx)$/.test(clean))
37
+ return null;
38
+ if (defaultExcluded(clean))
39
+ return null;
40
+ if (exclude.some((p) => clean.includes(p)))
41
+ return null;
42
+ if (include.length > 0 && !include.some((p) => clean.includes(p))) {
43
+ return null;
44
+ }
45
+ const result = transformWithLayoutAttrs(code, clean, root, {
46
+ production: options.production,
47
+ });
48
+ // transformWithLayoutAttrs returns the input untouched with map:null
49
+ // when nothing changed — signal "no change" to Vite to keep its maps.
50
+ if (result.code === code && result.map === null)
51
+ return null;
52
+ return result;
53
+ },
54
+ };
55
+ }
56
+ //# sourceMappingURL=index.js.map
@@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AE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC;YACxD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAClE,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,MAAM,GAAG,wBAAwB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;gBACzD,UAAU,EAAE,OAAO,CAAC,UAAU;aAC/B,CAAC,CAAC;YACH,qEAAqE;YACrE,sEAAsE;YACtE,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,KAAK,IAAI;gBAAE,OAAO,IAAI,CAAC;YAC7D,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layoutdesign/context",
3
- "version": "0.6.0",
3
+ "version": "0.10.1",
4
4
  "description": "Design system context for AI coding agents — MCP server + CLI + live preview",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -8,12 +8,20 @@
8
8
  "layout-context": "./dist/bin/cli.js",
9
9
  "layoutdesign-context": "./dist/bin/cli.js"
10
10
  },
11
- "main": "./dist/index.js",
12
- "types": "./dist/index.d.ts",
11
+ "main": "./dist/src/index.js",
12
+ "types": "./dist/src/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./dist/index.js",
16
- "types": "./dist/index.d.ts"
15
+ "import": "./dist/src/index.js",
16
+ "types": "./dist/src/index.d.ts"
17
+ },
18
+ "./vite-plugin": {
19
+ "import": "./dist/src/plugins/vite/index.js",
20
+ "types": "./dist/src/plugins/vite/index.d.ts"
21
+ },
22
+ "./next-plugin": {
23
+ "import": "./dist/src/plugins/next/index.js",
24
+ "types": "./dist/src/plugins/next/index.d.ts"
17
25
  }
18
26
  },
19
27
  "files": [
@@ -23,10 +31,14 @@
23
31
  "README.md",
24
32
  "LICENSE"
25
33
  ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
26
37
  "scripts": {
27
38
  "build": "tsc && mkdir -p dist/src/preview/static && cp src/preview/static/index.html dist/src/preview/static/index.html",
28
39
  "dev": "tsc --watch",
29
40
  "typecheck": "tsc --noEmit",
41
+ "test": "node --import tsx --test test/*.test.ts",
30
42
  "serve": "node dist/bin/cli.js serve",
31
43
  "preview": "node dist/bin/cli.js serve"
32
44
  },
@@ -48,16 +60,26 @@
48
60
  },
49
61
  "homepage": "https://layout.design",
50
62
  "dependencies": {
63
+ "@babel/generator": "^7.29.1",
64
+ "@babel/parser": "^7.29.3",
65
+ "@babel/traverse": "^7.29.0",
66
+ "@babel/types": "^7.29.0",
51
67
  "@modelcontextprotocol/sdk": "^1.12.1",
52
- "commander": "^13.1.0",
53
68
  "chalk": "^5.4.1",
54
- "ws": "^8.18.0",
69
+ "commander": "^13.1.0",
55
70
  "open": "^10.1.0",
56
- "typescript": "^5.7.3"
71
+ "proper-lockfile": "^4.1.2",
72
+ "recast": "^0.23.11",
73
+ "typescript": "^5.7.3",
74
+ "ws": "^8.18.0"
57
75
  },
58
76
  "devDependencies": {
77
+ "@types/babel__generator": "^7.27.0",
78
+ "@types/babel__traverse": "^7.28.0",
59
79
  "@types/node": "^22.13.10",
60
- "@types/ws": "^8.5.14"
80
+ "@types/proper-lockfile": "^4.1.4",
81
+ "@types/ws": "^8.5.14",
82
+ "tsx": "^4.22.0"
61
83
  },
62
84
  "engines": {
63
85
  "node": ">=18"