@coldsmirk/inkstone-monaco 0.16.0 → 0.17.0

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
@@ -11,6 +11,7 @@ Part of [inkstone](https://github.com/coldsmirk/inkstone). For a drop-in React c
11
11
  - **`monacoLanguages`** — the sorted catalog of every built-in language id the installed Monaco registers (with the `MonacoBuiltInLanguage` union type behind it), held to the installed `monaco-editor` by an upgrade-tripwire test. These are *ids*, not display names (`proto`, `sol`, `aes`); an unknown id silently falls back to `plaintext`.
12
12
  - **`disabledKeybindings` / `installDisabledKeybindings`** — swallow the find/replace chords and the command palette's F1 for editors that opt in. Monaco's standalone keybinding service is page-global and its rules are permanent, so the install registers each chord once per monaco module's service (duplicate copies of this package share the ledger; independent monaco bundles register their own) and scopes it with a per-capability context key created on the opted-in editor; the chord table is held to the installed `monaco-editor` by an upgrade-tripwire test.
13
13
  - **`installJsxTagClosing`** — VS Code's auto-closing JSX tags: a typed `>` that completes an opening tag inserts the matching closing tag and keeps the caret between the pair. Parser-backed: the bundled TS worker subclasses monaco's stock worker to expose `getJsxClosingTagAtPosition` — a language-service call monaco never proxied (VS Code ships the feature in its TypeScript extension, outside the editor core) — so generics, comparisons, arrow functions, and already-closed elements never trigger. The keystroke handler gates itself to TypeScript/JavaScript models whose path ends in `.tsx` / `.jsx`; a `getWorker` override that routes the `typescript` label to a worker without the subclass downgrades the feature to a no-op. `<MonacoEditor>` installs it automatically.
14
+ - **`dropMonacoWorkerFallbacks()`** (from **`@coldsmirk/inkstone-monaco/vite`**) — a Vite plugin that removes monaco's built-in worker fallbacks at build time. Monaco's language workerManagers statically reference their workers as `new Worker(new URL(...))` fallbacks that never run under `ensureMonacoHost` (the environment check prefers `getWorker`), yet bundlers emit a chunk per reference — including a ~7MB TypeScript worker duplicate that is never fetched. The plugin rewrites the fallbacks into located throws so the duplicates are never emitted; if a monaco bump reshapes the pattern it warns and leaves the file untouched (the dead chunk returns, nothing breaks).
14
15
  - **Embedded-editor fix** — works around [microsoft/monaco-editor#5177](https://github.com/microsoft/monaco-editor/issues/5177) (find-widget button tooltips landing on top of the buttons they describe) with a `width: max-content` hover-layer style tagged `data-inkstone="monaco-hover-geometry"`; deleted the moment upstream fixes it. The tooltip layer positions against the editor's container — give that container `position: relative`.
15
16
  - **`StreamingEditorController`** — stream generated text into an editor without routing every token through app state: `begin()` / `append(chunk)` / `end()` / `discard()`, `attach(editor)` / `detach(editor)` with buffered replay for late-mounting editors (and for a model swapped onto the attached editor mid-stream, including after the final chunk), and `isStreaming()` for the onChange guard. The stream locks every editor it touches read-only and `end()` / `discard()` restore each one's own setting — by handle, so an editor detached mid-stream is restored too; `discard()` puts every displaced document back into the model it came from, and `end()` does the same for every model except the one keeping the streamed text. Full-buffer writes and restorations preserve each model's UTF-8 BOM. Editors and models the app disposed mid-stream are skipped, never touched — teardown can race the stream without wedging it.
16
17
  - **`replaceInEditor(editor, old, new, all)`** — exact find-and-replace on an editor handle via `executeEdits`, preserving undo/cursor/folds; returns whether the edit landed (`false` = no editor / empty search / no match / a read-only editor refused it — e.g. one locked by a stream in progress), so a tool-call handler knows to fall back to a state write.
package/dist/vite.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { Plugin } from "vite";
2
+ //#region src/vite.d.ts
3
+ /**
4
+ * A Vite plugin that drops monaco's built-in worker fallbacks so no duplicate worker chunks
5
+ * are emitted: the statically-referenced fallback expressions become located throws, which
6
+ * never run while `ensureMonacoHost` owns `MonacoEnvironment` — and fail honestly, naming the
7
+ * worker, if some path reaches a fallback anyway. Apply it in any app whose workers ride this
8
+ * package's routing:
9
+ *
10
+ * ```ts
11
+ * import { dropMonacoWorkerFallbacks } from "@coldsmirk/inkstone-monaco/vite";
12
+ *
13
+ * export default defineConfig({ plugins: [dropMonacoWorkerFallbacks(), …] });
14
+ * ```
15
+ *
16
+ * If a monaco-editor bump reshapes the fallback so nothing matches, the plugin warns at build
17
+ * time and leaves the file untouched — the duplicate chunk returns (dead weight, nothing
18
+ * breaks) until the pattern catches up.
19
+ */
20
+ declare function dropMonacoWorkerFallbacks(): Plugin;
21
+ //#endregion
22
+ export { dropMonacoWorkerFallbacks };
package/dist/vite.js ADDED
@@ -0,0 +1,25 @@
1
+ //#region src/vite.ts
2
+ const WORKER_FALLBACK = /new Worker\(new URL\('(?<worker>[\w.]+\.worker\.js)', import\.meta\.url\), \{ type: "module" \}\)/g;
3
+ function dropMonacoWorkerFallbacks() {
4
+ return {
5
+ name: "inkstone:drop-monaco-worker-fallbacks",
6
+ transform(code, id) {
7
+ if (!id.includes("monaco-editor") || !id.endsWith("workerManager.js")) return;
8
+ let matched = false;
9
+ const transformed = code.replaceAll(WORKER_FALLBACK, (_expression, file) => {
10
+ matched = true;
11
+ return `(() => { throw new Error("inkstone: monaco's '${file}' fallback was dropped at build; MonacoEnvironment.getWorker must route it"); })()`;
12
+ });
13
+ if (!matched) {
14
+ this.warn("no monaco worker fallback matched — a monaco-editor bump likely reshaped it, and the duplicate worker chunk is back until this plugin catches up");
15
+ return;
16
+ }
17
+ return {
18
+ code: transformed,
19
+ map: null
20
+ };
21
+ }
22
+ };
23
+ }
24
+ //#endregion
25
+ export { dropMonacoWorkerFallbacks };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coldsmirk/inkstone-monaco",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Framework-agnostic Monaco assembly: lazy offline host (all language workers bundled, no CDN), opt-in Simplified-Chinese UI via monaco's official NLS catalog, a streaming editor controller for AI-typed content, and the shared Shiki highlighting bridge.",
5
5
  "keywords": [
6
6
  "monaco",
@@ -28,6 +28,10 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "default": "./dist/index.js"
30
30
  },
31
+ "./vite": {
32
+ "types": "./dist/vite.d.ts",
33
+ "default": "./dist/vite.js"
34
+ },
31
35
  "./package.json": "./package.json"
32
36
  },
33
37
  "types": "./dist/index.d.ts",
@@ -36,13 +40,20 @@
36
40
  ],
37
41
  "dependencies": {
38
42
  "@shikijs/monaco": "^4.4.3",
39
- "@coldsmirk/inkstone-core": "^0.16.0"
43
+ "@coldsmirk/inkstone-core": "^0.17.0"
40
44
  },
41
45
  "devDependencies": {
42
- "monaco-editor": "^0.56.0"
46
+ "monaco-editor": "^0.56.0",
47
+ "vite": "^8.2.2"
43
48
  },
44
49
  "peerDependencies": {
45
- "monaco-editor": "^0.56.0"
50
+ "monaco-editor": "^0.56.0",
51
+ "vite": ">=6"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "vite": {
55
+ "optional": true
56
+ }
46
57
  },
47
58
  "engines": {
48
59
  "node": ">=24"