@coldsmirk/inkstone-react 0.9.0 → 0.10.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.
@@ -0,0 +1,360 @@
1
+ import { ReactNode } from "react";
2
+ import { BeforeMount, DiffBeforeMount, DiffOnMount, OnMount } from "@monaco-editor/react";
3
+ import { MonacoHostOptions, MonacoLanguage, MonacoLanguage as MonacoLanguage$1, MonacoUiLocale, monacoLanguages } from "@coldsmirk/inkstone-monaco";
4
+ import { editor } from "monaco-editor";
5
+
6
+ //#region src/monaco-diff-editor.d.ts
7
+ interface MonacoDiffEditorProps {
8
+ /**
9
+ * The controlled original text (the left side). Never editable — Monaco's
10
+ * `originalEditable` stays off because this component gives the original document no
11
+ * change channel; it follows this prop only, reconciled as a minimal replace that keeps
12
+ * the pane's selection and scroll position outside the changed region.
13
+ */
14
+ original: string;
15
+ /**
16
+ * The controlled modified text (the right side) — editable unless `readOnly`. External
17
+ * changes reconcile into the live model as one minimal replace, off the undo stack — same
18
+ * contract as `<CodeMirrorDiffEditor>`: the caret keeps its position outside the changed
19
+ * region, and undo never reverts an external value (though undo entries recorded *before*
20
+ * an external change that overlaps them may restore shifted text — Monaco's history does
21
+ * not remap through unrecorded edits).
22
+ */
23
+ modified: string;
24
+ /**
25
+ * Called with the full modified document after every edit made in the editor. External
26
+ * `modified` prop reconciliations never echo back through this.
27
+ */
28
+ onChange?: (value: string) => void;
29
+ /**
30
+ * Monaco language id, applied to both models. Built-in ids autocomplete; any
31
+ * custom-registered id is also accepted.
32
+ *
33
+ * @default "javascript"
34
+ */
35
+ language?: MonacoLanguage;
36
+ /**
37
+ * Render with the dark theme. The component never reads the OS `prefers-color-scheme`;
38
+ * wire this to your app's color-scheme state.
39
+ *
40
+ * @default false
41
+ */
42
+ dark?: boolean;
43
+ /**
44
+ * UI locale for Monaco's built-in chrome — page-global and locked by the first editor to
45
+ * mount, exactly as on `<MonacoEditor>`. Overrides `hostOptions.locale`.
46
+ *
47
+ * @default "en"
48
+ */
49
+ locale?: MonacoUiLocale;
50
+ /**
51
+ * Lock the modified side too, turning the component into a pure diff viewer (Monaco
52
+ * `readOnly`, which the diff editor applies to the modified pane).
53
+ *
54
+ * @default false
55
+ */
56
+ readOnly?: boolean;
57
+ /**
58
+ * Collapse long unchanged stretches behind expandable region bars (Monaco
59
+ * `hideUnchangedRegions`), keeping context lines around each change — the same toggle
60
+ * `<CodeMirrorDiffEditor>` exposes under this name.
61
+ *
62
+ * @default false
63
+ */
64
+ collapseUnchanged?: boolean;
65
+ /**
66
+ * Soft-wrap long lines on both sides (Monaco `wordWrap`; the diff editor's own
67
+ * `diffWordWrap` inherits it).
68
+ *
69
+ * @default false
70
+ */
71
+ lineWrapping?: boolean;
72
+ /**
73
+ * Show the line-number gutters. On by default — unlike a single document field, a diff
74
+ * reads by line reference.
75
+ *
76
+ * @default true
77
+ */
78
+ showLineNumbers?: boolean;
79
+ /**
80
+ * Editor font size in px (Monaco `fontSize`). Omit to keep the inkstone default (14).
81
+ */
82
+ fontSize?: number;
83
+ /**
84
+ * Line height (Monaco `lineHeight`, and its convention): values below 8 multiply the font
85
+ * size, larger values are absolute pixels. Omit to keep the inkstone default (1.6).
86
+ */
87
+ lineHeight?: number;
88
+ height?: string | number;
89
+ width?: string | number;
90
+ className?: string;
91
+ /**
92
+ * Extra construction options, merged over {@link DEFAULT_MONACO_OPTIONS} and the props
93
+ * above — the escape hatch wins (e.g. `renderSideBySide: false` for the inline view).
94
+ */
95
+ options?: editor.IDiffEditorConstructionOptions;
96
+ /**
97
+ * Host bring-up options (UI locale, language workers). The Monaco host is a process-wide
98
+ * singleton, so the first mounted editor wins and later values are ignored.
99
+ */
100
+ hostOptions?: MonacoHostOptions;
101
+ /**
102
+ * Shown while the host, highlighter, and editor chunk load.
103
+ *
104
+ * @default "Loading editor…"
105
+ */
106
+ loading?: ReactNode;
107
+ /**
108
+ * Shown when the Monaco host fails to load (e.g. a stale chunk 404 after a redeploy).
109
+ * The failure is not cached by the host singleton, so a fresh mount retries.
110
+ *
111
+ * @default "Editor failed to load"
112
+ */
113
+ failure?: ReactNode;
114
+ /**
115
+ * Runs after inkstone's own pre-mount setup (Shiki theme registration).
116
+ */
117
+ beforeMount?: DiffBeforeMount;
118
+ /**
119
+ * Runs once with the created `IStandaloneDiffEditor` — the imperative handle to both
120
+ * panes (`getOriginalEditor()` / `getModifiedEditor()`).
121
+ */
122
+ onMount?: DiffOnMount;
123
+ }
124
+ /**
125
+ * A preconfigured, offline Monaco diff editor — `<MonacoEditor>`'s assembly (bundled
126
+ * workers, Shiki catppuccin highlighting with light/dark switching, opt-in zh-CN chrome)
127
+ * around Monaco's side-by-side diff view.
128
+ *
129
+ * The original side is read-only and follows the `original` prop; the modified side is the
130
+ * editable document behind `modified` / `onChange` (set `readOnly` for a pure viewer). Both
131
+ * components in the pair — this and `<CodeMirrorDiffEditor>` — speak the same core props
132
+ * and the same controlled-value contract: the component owns both reconciles (minimal
133
+ * replace, off the undo stack — see `reconcileModelValue`) instead of leaving them to
134
+ * `@monaco-editor/react`, whose whole-document `executeEdits` lands external values on the
135
+ * user's undo stack and resets the caret.
136
+ *
137
+ * The same global constraints as `<MonacoEditor>` apply: never `import "monaco-editor"`
138
+ * statically (type-only imports are fine), and the first mounted editor wins the host
139
+ * configuration.
140
+ */
141
+ declare function MonacoDiffEditor({
142
+ original,
143
+ modified,
144
+ onChange,
145
+ language,
146
+ dark,
147
+ locale,
148
+ readOnly,
149
+ collapseUnchanged,
150
+ lineWrapping,
151
+ showLineNumbers,
152
+ fontSize,
153
+ lineHeight,
154
+ height,
155
+ width,
156
+ className,
157
+ options,
158
+ hostOptions,
159
+ loading,
160
+ failure,
161
+ beforeMount,
162
+ onMount
163
+ }: MonacoDiffEditorProps): ReactNode;
164
+ //#endregion
165
+ //#region src/monaco-editor.d.ts
166
+ /**
167
+ * Baseline construction options shared by every inkstone Monaco editor: no minimap, compact
168
+ * code type, in-place layout tracking, widgets floated above clipping containers, completion
169
+ * tuned for API-assisted editing, thin scrollbars, and an embedded-friendly find widget.
170
+ * Spread these to extend rather than replace: `options={{ ...DEFAULT_MONACO_OPTIONS, wordWrap: "on" }}`.
171
+ */
172
+ declare const DEFAULT_MONACO_OPTIONS: editor.IStandaloneEditorConstructionOptions;
173
+ interface MonacoEditorProps {
174
+ /**
175
+ * The controlled document text.
176
+ */
177
+ value: string;
178
+ onChange?: (value: string) => void;
179
+ /**
180
+ * Monaco language id. Built-in ids autocomplete; any custom-registered id is also accepted.
181
+ *
182
+ * @default "javascript"
183
+ */
184
+ language?: MonacoLanguage;
185
+ /**
186
+ * Render with the dark theme. The component never reads the OS `prefers-color-scheme`;
187
+ * wire this to your app's color-scheme state.
188
+ *
189
+ * @default false
190
+ */
191
+ dark?: boolean;
192
+ /**
193
+ * UI locale for Monaco's built-in chrome (context menu, find widget, command palette …).
194
+ * Unlike everything else on this component, the locale is **page-global and locked by the
195
+ * first editor to mount** — Monaco resolves its UI strings once, at module evaluation — so
196
+ * later editors with a different value are ignored. Overrides `hostOptions.locale` (the
197
+ * same knob on the framework-agnostic host layer).
198
+ *
199
+ * @default "en"
200
+ */
201
+ locale?: MonacoUiLocale;
202
+ /**
203
+ * Placeholder shown while the document is empty. Maps to Monaco's native `placeholder`
204
+ * editor option (0.47+); an explicit `options.placeholder` still wins.
205
+ */
206
+ placeholder?: string;
207
+ /**
208
+ * Soft-wrap long lines (Monaco `wordWrap`).
209
+ *
210
+ * @default false
211
+ */
212
+ lineWrapping?: boolean;
213
+ /**
214
+ * Show the line-number gutter (Monaco `lineNumbers`). For relative/interval modes pass an
215
+ * explicit `options.lineNumbers`.
216
+ *
217
+ * @default false
218
+ */
219
+ showLineNumbers?: boolean;
220
+ /**
221
+ * Editor font size in px (Monaco `fontSize`). Omit to keep the inkstone default (14).
222
+ */
223
+ fontSize?: number;
224
+ /**
225
+ * Line height (Monaco `lineHeight`, and its convention): values below 8 multiply the font
226
+ * size (e.g. `1.6`), larger values are absolute pixels (e.g. `22`). `<CodeMirrorEditor>`
227
+ * mirrors the same semantics. Omit to keep the inkstone default (1.6).
228
+ */
229
+ lineHeight?: number;
230
+ /**
231
+ * Tab width in spaces (Monaco `tabSize`).
232
+ *
233
+ * @default 2
234
+ */
235
+ tabSize?: number;
236
+ /**
237
+ * Enable code folding (fold gutter + fold ranges). Unifies the toggle with
238
+ * `<CodeMirrorEditor>`; note Monaco folds by default, so this turns its folding off unless
239
+ * set.
240
+ *
241
+ * @default false
242
+ */
243
+ folding?: boolean;
244
+ /**
245
+ * Disable Monaco's right-click context menu (`contextmenu: false`). Right-clicks then fall
246
+ * through to the browser, so its native menu applies — intercept `contextmenu` on a
247
+ * wrapping element to suppress that as well.
248
+ *
249
+ * @default false
250
+ */
251
+ disableContextMenu?: boolean;
252
+ /**
253
+ * Swallow the find/replace widget's keyboard entries — Ctrl/Cmd+F (find), Ctrl+H and
254
+ * Cmd+Alt+F (replace). Scoped to this editor via its own context key: the standalone keybinding
255
+ * service is page-global, so an unscoped rule would rewire every editor on the page, and
256
+ * {@link disableCommandPalette} is gated separately so enabling one never implies the other.
257
+ * Fixed at creation.
258
+ *
259
+ * @default false
260
+ */
261
+ disableFind?: boolean;
262
+ /**
263
+ * Swallow the command palette's keyboard entry, F1 — Monaco never binds Ctrl+Shift+P
264
+ * (that is a VS Code binding). While the context menu is enabled, its "Command Palette"
265
+ * item still opens the palette; pair with {@link disableContextMenu} to remove every
266
+ * entry point. Fixed at creation.
267
+ *
268
+ * @default false
269
+ */
270
+ disableCommandPalette?: boolean;
271
+ /**
272
+ * Model path — give each logically distinct document its own so view state (cursor,
273
+ * folds) survives remounts, and so a document switch never routes the outgoing model's
274
+ * text into the new document's `onChange` (changes from a model this prop no longer
275
+ * names are dropped).
276
+ */
277
+ path?: string;
278
+ height?: string | number;
279
+ width?: string | number;
280
+ className?: string;
281
+ /**
282
+ * Extra construction options, merged over {@link DEFAULT_MONACO_OPTIONS}.
283
+ */
284
+ options?: editor.IStandaloneEditorConstructionOptions;
285
+ /**
286
+ * Host bring-up options (UI locale, language workers). The Monaco host is a process-wide
287
+ * singleton, so the first mounted editor wins and later values are ignored.
288
+ */
289
+ hostOptions?: MonacoHostOptions;
290
+ /**
291
+ * Shown while the host, highlighter, and editor chunk load.
292
+ *
293
+ * @default "Loading editor…"
294
+ */
295
+ loading?: ReactNode;
296
+ /**
297
+ * Shown when the Monaco host fails to load (e.g. a stale chunk 404 after a redeploy).
298
+ * The failure is not cached by the host singleton, so a fresh mount retries.
299
+ *
300
+ * @default "Editor failed to load"
301
+ */
302
+ failure?: ReactNode;
303
+ /**
304
+ * Runs after inkstone's own pre-mount setup (Shiki theme registration).
305
+ */
306
+ beforeMount?: BeforeMount;
307
+ onMount?: OnMount;
308
+ /**
309
+ * Called when the editor's text area gains focus (Monaco `onDidFocusEditorText`).
310
+ */
311
+ onFocus?: () => void;
312
+ /**
313
+ * Called when the editor's text area loses focus (Monaco `onDidBlurEditorText`).
314
+ */
315
+ onBlur?: () => void;
316
+ }
317
+ /**
318
+ * A preconfigured, offline Monaco editor: bundled workers (no CDN), Shiki catppuccin
319
+ * highlighting with light/dark switching, and sensible document defaults — drop it in with
320
+ * `value` / `onChange` and everything else is wired. The UI speaks Monaco's stock English;
321
+ * pass `hostOptions={{ locale: "zh-cn" }}` for the official Simplified-Chinese chrome.
322
+ *
323
+ * Mounting is gated on the Monaco host and the Shiki highlighter so the first paint already
324
+ * has the right theme; if the highlighter fails to load, the editor falls back to Monaco's
325
+ * built-in themes and stays usable.
326
+ *
327
+ * Do not `import "monaco-editor"` statically elsewhere in the app — that would evaluate
328
+ * Monaco before its UI locale is set (see `ensureMonacoHost`). Type-only imports are fine.
329
+ */
330
+ declare function MonacoEditor({
331
+ value,
332
+ onChange,
333
+ language,
334
+ dark,
335
+ locale,
336
+ placeholder,
337
+ lineWrapping,
338
+ showLineNumbers,
339
+ folding,
340
+ disableContextMenu,
341
+ disableFind,
342
+ disableCommandPalette,
343
+ fontSize,
344
+ lineHeight,
345
+ tabSize,
346
+ path,
347
+ height,
348
+ width,
349
+ className,
350
+ options,
351
+ hostOptions,
352
+ loading,
353
+ failure,
354
+ beforeMount,
355
+ onMount,
356
+ onFocus,
357
+ onBlur
358
+ }: MonacoEditorProps): ReactNode;
359
+ //#endregion
360
+ export { MonacoEditorProps as a, MonacoEditor as i, monacoLanguages as n, MonacoDiffEditor as o, DEFAULT_MONACO_OPTIONS as r, MonacoDiffEditorProps as s, MonacoLanguage$1 as t };
@@ -0,0 +1,2 @@
1
+ import { a as MonacoEditorProps, i as MonacoEditor, n as monacoLanguages, o as MonacoDiffEditor, r as DEFAULT_MONACO_OPTIONS, s as MonacoDiffEditorProps, t as MonacoLanguage } from "./monaco-DXifh803.js";
2
+ export { DEFAULT_MONACO_OPTIONS, MonacoDiffEditor, type MonacoDiffEditorProps, MonacoEditor, type MonacoEditorProps, type MonacoLanguage, monacoLanguages };
package/dist/monaco.js ADDED
@@ -0,0 +1,2 @@
1
+ import { i as MonacoEditor, n as MonacoDiffEditor, r as DEFAULT_MONACO_OPTIONS, t as monacoLanguages } from "./monaco-Bzo3cV2q.js";
2
+ export { DEFAULT_MONACO_OPTIONS, MonacoDiffEditor, MonacoEditor, monacoLanguages };
@@ -0,0 +1,20 @@
1
+ import { RefObject } from "react";
2
+ import { HighlighterCore } from "@coldsmirk/inkstone-core";
3
+
4
+ //#region src/use-shiki-highlighter.d.ts
5
+ type ShikiState = "loading" | "ready" | "failed";
6
+ /**
7
+ * Load the shared Shiki highlighter and expose its lifecycle to gate editor mounting:
8
+ * waiting for `ready` before creating the editor avoids a default-theme flash (and the
9
+ * "theme not found" console error) on first paint; on `failed` the caller falls back to
10
+ * the engine's built-in theme so the editor stays usable.
11
+ *
12
+ * `highlighterRef` is for pre-mount hooks (Monaco `beforeMount`) that must read the
13
+ * instance synchronously before the editor is created.
14
+ */
15
+ declare function useShikiHighlighter(): {
16
+ state: ShikiState;
17
+ highlighterRef: RefObject<HighlighterCore | null>;
18
+ };
19
+ //#endregion
20
+ export { useShikiHighlighter as n, ShikiState as t };
@@ -0,0 +1,2 @@
1
+ import { n as useShikiHighlighter, t as ShikiState } from "./shiki-D-IjmhhO.js";
2
+ export { type ShikiState, useShikiHighlighter };
package/dist/shiki.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as useShikiHighlighter } from "./use-shiki-highlighter-CzSQcX2f.js";
2
+ export { useShikiHighlighter };
@@ -0,0 +1,19 @@
1
+ import { useInsertionEffect, useReducer, useRef } from "react";
2
+ //#region src/code-font.ts
3
+ const CODE_FONT_FAMILY = "var(--inkstone-font-family-code, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace)";
4
+ //#endregion
5
+ //#region src/use-controlled-reconcile.ts
6
+ function useControlledReconcileSignal() {
7
+ return useReducer((revision) => revision + 1, 0);
8
+ }
9
+ //#endregion
10
+ //#region src/use-latest.ts
11
+ function useLatest(value) {
12
+ const ref = useRef(value);
13
+ useInsertionEffect(() => {
14
+ ref.current = value;
15
+ });
16
+ return ref;
17
+ }
18
+ //#endregion
19
+ export { useControlledReconcileSignal as n, CODE_FONT_FAMILY as r, useLatest as t };
@@ -0,0 +1,27 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { getHighlighter } from "@coldsmirk/inkstone-core";
3
+ //#region src/use-shiki-highlighter.ts
4
+ function useShikiHighlighter() {
5
+ const [state, setState] = useState("loading");
6
+ const highlighterRef = useRef(null);
7
+ useEffect(() => {
8
+ let cancelled = false;
9
+ getHighlighter().then((highlighter) => {
10
+ if (cancelled) return;
11
+ highlighterRef.current = highlighter;
12
+ setState("ready");
13
+ }).catch((error) => {
14
+ console.error("inkstone: shiki highlighter failed to load", error);
15
+ if (!cancelled) setState("failed");
16
+ });
17
+ return () => {
18
+ cancelled = true;
19
+ };
20
+ }, []);
21
+ return {
22
+ state,
23
+ highlighterRef
24
+ };
25
+ }
26
+ //#endregion
27
+ export { useShikiHighlighter as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coldsmirk/inkstone-react",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Drop-in React code editors: a preconfigured Monaco <MonacoEditor> (offline workers, Shiki catppuccin themes, dark switching, opt-in zh-CN UI) and a controlled CodeMirror 6 <CodeMirrorEditor> (catppuccin themes, dark switching, sizing).",
5
5
  "keywords": [
6
6
  "react",
@@ -28,7 +28,19 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "default": "./dist/index.js"
30
30
  },
31
- "./package.json": "./package.json"
31
+ "./codemirror": {
32
+ "types": "./dist/codemirror.d.ts",
33
+ "default": "./dist/codemirror.js"
34
+ },
35
+ "./monaco": {
36
+ "types": "./dist/monaco.d.ts",
37
+ "default": "./dist/monaco.js"
38
+ },
39
+ "./package.json": "./package.json",
40
+ "./shiki": {
41
+ "types": "./dist/shiki.d.ts",
42
+ "default": "./dist/shiki.js"
43
+ }
32
44
  },
33
45
  "types": "./dist/index.d.ts",
34
46
  "files": [
@@ -39,9 +51,9 @@
39
51
  "@catppuccin/palette": "^1.8.0",
40
52
  "@monaco-editor/react": "^4.7.0",
41
53
  "@shikijs/monaco": "^4.3.1",
42
- "@coldsmirk/inkstone-codemirror": "^0.9.0",
43
- "@coldsmirk/inkstone-core": "^0.9.0",
44
- "@coldsmirk/inkstone-monaco": "^0.9.0"
54
+ "@coldsmirk/inkstone-codemirror": "^0.10.0",
55
+ "@coldsmirk/inkstone-core": "^0.10.0",
56
+ "@coldsmirk/inkstone-monaco": "^0.10.0"
45
57
  },
46
58
  "devDependencies": {
47
59
  "@codemirror/autocomplete": "^6.20.3",