@a10k/iridium-dev-server 0.0.3 → 0.0.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/Readme.md CHANGED
@@ -4,7 +4,7 @@ Local dev server for working with Observable notebooks: edit them in [Iridium](h
4
4
 
5
5
  > Published on npm as `@a10k/iridium-dev-server` (previously `@wishyoulization/iridium-dev-server`).
6
6
 
7
- Cells are compiled by Observable's own engine, [Notebook Kit](https://observablehq.com/notebook-kit/kit): classic Observable JavaScript (`viewof`, `mutable`, `import {x} from "@user/notebook"`, `require(…)`) and plain JavaScript cells (several statements, `const` declarations, `npm:` imports, `display(…)`), as in Observable Notebooks 2.0.
7
+ Cells are compiled by Observable's own engine, [Notebook Kit](https://observablehq.com/notebook-kit/kit): classic Observable JavaScript (`viewof`, `mutable`, `import {x} from "@user/notebook"`, `require(…)`) and plain JavaScript cells (several statements, `const` declarations, `npm:` imports, `display(…)`), as in Observable Notebooks 2.0. Plain JavaScript cells may use TypeScript syntax (type annotations, interfaces): the types are removed and the cell runs as plain JavaScript, without type checking.
8
8
 
9
9
  It also includes an [MCP](https://modelcontextprotocol.io) server and a skill, so AI assistants such as Claude can build notebooks with you, live, in the tab you're watching.
10
10
 
@@ -175,7 +175,7 @@ Notebooks are saved in Notebook Kit's HTML format (`<name>.html`), the open form
175
175
  </notebook>
176
176
  ```
177
177
 
178
- - Classic Observable JavaScript cells are stored as `application/vnd.observable.javascript`, plain JavaScript cells as `module`. Pinned cells (editor visible) have `pinned`.
178
+ - Classic Observable JavaScript cells are stored as `application/vnd.observable.javascript`, plain JavaScript cells as `module`, TypeScript cells as `text/x-typescript` (Observable Desktop's `ts` mode). Pinned cells (editor visible) have `pinned`.
179
179
  - Markdown, HTML, TeX and Graphviz cells from Observable Desktop open as the equivalent `md`/`html`/`tex`/`dot` template and are saved back in their own mode. Other modes (SQL, Python, …) can't run in Iridium but are kept unchanged.
180
180
  - **Legacy `.ojs` notebooks** are still read. The first save writes `<name>.html` next to it; from then on the `.html` file is used. The `.ojs` file is left untouched, so delete it once you're happy with the conversion.
181
181
 
@@ -196,7 +196,7 @@ runtime.module(define, Inspector.into(document.body));
196
196
 
197
197
  - Works with `@observablehq/runtime` 5.9+ (runtime 5 includes the standard library and `fileAttachments`, so `new Runtime()` is enough) and 6 as above.
198
198
  - Every named cell is passed to `observer(name)`, so you can pick cells to render by name.
199
- - Plain JavaScript cells: each `display(…)` call in a run goes to its own observer; top-level declarations are named variables.
199
+ - Plain JavaScript and TypeScript cells: each `display(…)` call in a run goes to its own observer; top-level declarations are named variables.
200
200
  - Built-ins specific to Notebook Kit (such as the sample datasets like `penguins`) aren't in `@observablehq/stdlib`; provide them yourself if an embedded notebook uses them.
201
201
 
202
202
  ## Configuration
@@ -50,9 +50,10 @@ const defineCell = (record, index) => {
50
50
  let runtimeInputs = inputs.map(classicName);
51
51
  const lines = [];
52
52
 
53
- // Plain JavaScript cells may call display()/view(): give them the shim. In
53
+ // Plain JavaScript and TypeScript cells may call display()/view(): give
54
+ // them the shim. In
54
55
  // Observable JavaScript those are ordinary names (e.g. an imported view).
55
- const usesDisplay = record.mode === 'js' && (inputs.includes('display') || inputs.includes('view'));
56
+ const usesDisplay = record.mode !== 'ojs' && (inputs.includes('display') || inputs.includes('view'));
56
57
  if (usesDisplay) {
57
58
  const shim = `display${index}`;
58
59
  lines.push(` const ${shim} = cellDisplay(observer);`);
@@ -115,7 +116,7 @@ const fileAttachments = ({ folder, names = [] } = {}) =>
115
116
 
116
117
  export const compileModule = (cells, { name, files } = {}) => {
117
118
  const definitions = cells
118
- .filter((cell) => !cell.mode || ['ojs', 'js', 'md', 'html', 'tex', 'dot'].includes(cell.mode))
119
+ .filter((cell) => !cell.mode || ['ojs', 'js', 'ts', 'md', 'html', 'tex', 'dot'].includes(cell.mode))
119
120
  .map((cell, index) => defineCell(compileCell(String(cell.sourceCode ?? '')), index + 1));
120
121
  return `// Compiled by iridium-dev-server${name ? ` from ${name}` : ''}. Do not edit.
121
122
  ${HELPERS}
package/lib/mcp.js CHANGED
@@ -12,7 +12,7 @@ The tools work on the notebook open in the user's browser tab, as if the user we
12
12
 
13
13
  Edits are unsaved until saved, like the user's own edits (unsaved_changes in results). Save only when the user asks you to. Address cells by id or by the name they define (cell: "data"). For small changes to a long cell, edit_cell with replace: [{old, new}] patches its code instead of resending it. To open a notebook in a particular browser, pass browser (e.g. "Google Chrome") to create_notebook or open_notebook.
14
14
 
15
- Cells are Observable JavaScript: \`name = expression\`, \`name = { ...; return value; }\` blocks, \`viewof x = Inputs.range([0, 10])\`, \`mutable x = 0\`, generators (yield), \`import {chart} from "@d3/bar-chart"\` from observablehq.com, \`md\\\`...\\\`\` and \`html\\\`...\\\`\` for text and markup. Cells react to each other by name in any order; each named cell is defined once. Plain JavaScript cells also work (several statements, \`const\` declarations shared with other cells, \`import {x} from "npm:pkg"\`, \`display(value)\`). Built-ins include d3, Plot, Inputs, htl, _ (lodash), md, html, svg, tex, dot, mermaid, DuckDBClient, FileAttachment, width, now, invalidation, Generators, require. Prefer Plot for charts and Inputs for controls, and use \`width\` for responsive sizes.`;
15
+ Cells are Observable JavaScript: \`name = expression\`, \`name = { ...; return value; }\` blocks, \`viewof x = Inputs.range([0, 10])\`, \`mutable x = 0\`, generators (yield), \`import {chart} from "@d3/bar-chart"\` from observablehq.com, \`md\\\`...\\\`\` and \`html\\\`...\\\`\` for text and markup. Cells react to each other by name in any order; each named cell is defined once. Plain JavaScript cells also work (several statements, \`const\` declarations shared with other cells, \`import {x} from "npm:pkg"\`, \`display(value)\`), and may use TypeScript syntax (types are stripped, not checked). Built-ins include d3, Plot, Inputs, htl, _ (lodash), md, html, svg, tex, dot, mermaid, DuckDBClient, FileAttachment, width, now, invalidation, Generators, require. Prefer Plot for charts and Inputs for controls, and use \`width\` for responsive sizes.`;
16
16
 
17
17
  const text = (value) => ({
18
18
  content: [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value, null, 2) }],
package/lib/notebooks.js CHANGED
@@ -40,8 +40,9 @@ export const notebookPath = (dir, name) => {
40
40
  // --- Cell types -------------------------------------------------------------
41
41
 
42
42
  // Same rule as Iridium (src/compile.js): Observable JavaScript first, plain
43
- // JavaScript if it is not valid Observable JavaScript; npm:/jsr: imports are
44
- // plain JavaScript. Cells that compile as neither are kept as Observable JS.
43
+ // JavaScript if it is not valid Observable JavaScript, then TypeScript;
44
+ // npm:/jsr: imports are plain JavaScript. Cells that compile as none of these
45
+ // are kept as Observable JS.
45
46
  const PACKAGE_IMPORT = /\bfrom\s*(["'])(npm|jsr):/;
46
47
  export const cellMode = (source) => {
47
48
  const compiles = (mode) => {
@@ -55,6 +56,7 @@ export const cellMode = (source) => {
55
56
  if (PACKAGE_IMPORT.test(source) && compiles('js')) return 'js';
56
57
  if (compiles('ojs')) return 'ojs';
57
58
  if (compiles('js')) return 'js';
59
+ if (compiles('ts')) return 'ts';
58
60
  return 'ojs';
59
61
  };
60
62
 
@@ -85,9 +87,9 @@ export const readNotebookMeta = (path) => {
85
87
 
86
88
  const readHtml = (html) =>
87
89
  deserialize(html, { parser: new window.DOMParser() }).cells.map(({ id, value, mode, pinned }) => {
88
- if (mode === 'ojs' || mode === 'js') return { id, pin: pinned, sourceCode: value };
90
+ if (mode === 'ojs' || mode === 'js' || mode === 'ts') return { id, pin: pinned, sourceCode: value };
89
91
  const tag = TEMPLATE_TAGS[mode];
90
- // Other modes (SQL, Python, TypeScript, …) can't run in Iridium; keep them
92
+ // Other modes (SQL, Python, …) can't run in Iridium; keep them
91
93
  // as they are so saving doesn't lose them.
92
94
  return { id, pin: pinned, mode, sourceCode: tag ? toTemplate(tag, value) : value };
93
95
  });
@@ -125,7 +127,7 @@ const toKitCell = ({ id, pin, sourceCode, mode }, index) => {
125
127
  if (tag) {
126
128
  const inner = fromTemplate(tag, value);
127
129
  if (inner != null) return { ...cell, mode, value: inner };
128
- } else if (mode && mode !== 'ojs' && mode !== 'js') {
130
+ } else if (mode && mode !== 'ojs' && mode !== 'js' && mode !== 'ts') {
129
131
  return { ...cell, mode, value }; // unsupported mode: saved back unchanged
130
132
  }
131
133
  return { ...cell, mode: cellMode(value), value };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a10k/iridium-dev-server",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Local dev server for working with Observable notebooks.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -24,7 +24,7 @@
24
24
  "node": ">=22"
25
25
  },
26
26
  "dependencies": {
27
- "@a10k/iridium": "~0.0.3",
27
+ "@a10k/iridium": "~0.0.4",
28
28
  "@koa/bodyparser": "^6.1.0",
29
29
  "@koa/cors": "^5.0.0",
30
30
  "@koa/router": "^15.7.1",
package/skill/SKILL.md CHANGED
@@ -71,7 +71,7 @@ import {Legend} from "@d3/color-legend" // reuse cells from notebooks
71
71
 
72
72
  Rules: one cell per name; cells can reference each other in any order; a cell is an expression, `name = expression`, or a `{ … return … }` block. Use `viewof name = Inputs.*(…)` for controls (the cell's value is the input's value). `this` is the cell's previous value.
73
73
 
74
- **Plain JavaScript cells** also work (as in Observable Notebooks 2.0): several statements, top-level `const`/`let`/`function` shared with other cells, `import {x} from "npm:package"`, and `display(value)` to show output.
74
+ **Plain JavaScript cells** also work (as in Observable Notebooks 2.0): several statements, top-level `const`/`let`/`function` shared with other cells, `import {x} from "npm:package"`, and `display(value)` to show output. These cells may also use TypeScript syntax (`const n: number = 1`, `interface P { x: number }`); types are stripped, not checked.
75
75
 
76
76
  ```js
77
77
  import {csvParse} from "npm:d3-dsv";