@coldsmirk/inkstone-react 0.8.3 → 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.
@@ -1,12 +1,164 @@
1
1
  import { Extension } from "@codemirror/state";
2
- import { CodeMirrorLanguage, CodeMirrorLanguage as CodeMirrorLanguage$1, EditorContext, EditorContext as EditorContext$1, codeMirrorLanguages, normalizeContext, searchPhrasesZhCn } from "@coldsmirk/inkstone-codemirror";
3
- import { ReactNode, RefObject } from "react";
4
2
  import { EditorView } from "@codemirror/view";
5
- import { MonacoHostOptions, MonacoLanguage, MonacoLanguage as MonacoLanguage$1, MonacoUiLocale } from "@coldsmirk/inkstone-monaco";
6
- import { BeforeMount, OnMount } from "@monaco-editor/react";
7
- import { editor } from "monaco-editor";
8
- import { HighlighterCore } from "@coldsmirk/inkstone-core";
3
+ import { CodeMirrorLanguage, CodeMirrorLanguage as CodeMirrorLanguage$1, EditorContext, EditorContext as EditorContext$1, MergeView, MergeView as MergeView$1, SqlSchema, SqlSchema as SqlSchema$1, codeMirrorLanguages, normalizeContext as normalizeContext$1, searchPhrasesZhCn as searchPhrasesZhCn$1 } from "@coldsmirk/inkstone-codemirror";
4
+ import { ReactNode } from "react";
9
5
 
6
+ //#region src/codemirror-diff-editor.d.ts
7
+ interface CodeMirrorDiffEditorProps {
8
+ /**
9
+ * The controlled original text (the left side). Always read-only in the view — it changes
10
+ * only through this prop, and external changes reconcile in place without a rebuild.
11
+ */
12
+ original: string;
13
+ /**
14
+ * The controlled modified text (the right side) — editable unless `readOnly`; external
15
+ * changes reconcile into the live editor without resetting the caret.
16
+ */
17
+ modified: string;
18
+ /**
19
+ * Called with the full modified document after every edit made in the view — typing, or a
20
+ * revert-control copy from the original side. Same contract as `<CodeMirrorEditor>`'s
21
+ * `onChange`.
22
+ */
23
+ onChange?: (value: string) => void;
24
+ /**
25
+ * Language id, applied to both sides — lazily loads the matching CodeMirror grammar as its
26
+ * own chunk, exactly like `<CodeMirrorEditor>`. For anything beyond the built-in set, pass
27
+ * your own support through `extensions`.
28
+ */
29
+ language?: CodeMirrorLanguage;
30
+ /**
31
+ * Lock the modified side too, turning the component into a pure diff viewer. The original
32
+ * side is read-only regardless. Revert controls stay disabled while this is set.
33
+ *
34
+ * @default false
35
+ */
36
+ readOnly?: boolean;
37
+ /**
38
+ * Show a per-chunk revert arrow between the editors that copies the original chunk into
39
+ * the modified document (the edit flows through `onChange`). Swaps in place, and remains
40
+ * unavailable while `readOnly` is set.
41
+ *
42
+ * @default false
43
+ */
44
+ revertControls?: boolean;
45
+ /**
46
+ * Collapse long unchanged stretches behind an expandable "⦚ n lines ⦚" bar, keeping a few
47
+ * context lines around each change. Swaps in place.
48
+ *
49
+ * @default false
50
+ */
51
+ collapseUnchanged?: boolean;
52
+ /**
53
+ * Soft-wrap long lines on both sides. Swaps in place.
54
+ *
55
+ * @default false
56
+ */
57
+ lineWrapping?: boolean;
58
+ /**
59
+ * Show the line-number gutters. On by default — unlike a single document field, a diff
60
+ * reads by line reference. Swaps in place.
61
+ *
62
+ * @default true
63
+ */
64
+ showLineNumbers?: boolean;
65
+ /**
66
+ * Static extensions applied to both sides, fixed for the view's lifetime. Hoist the
67
+ * array — a new identity per render is ignored by design (create-once).
68
+ */
69
+ extensions?: Extension[];
70
+ /**
71
+ * Extensions swapped in place on both sides when the identity changes — memoize with
72
+ * `useMemo` keyed on what actually changes. Layered after (and so able to override)
73
+ * inkstone's default catppuccin theme.
74
+ */
75
+ dynamicExtensions?: Extension[];
76
+ /**
77
+ * Use the dark catppuccin flavor (macchiato) instead of the light one (latte). The
78
+ * component never reads the OS `prefers-color-scheme` — same policy as every inkstone
79
+ * editor.
80
+ *
81
+ * @default false
82
+ */
83
+ dark?: boolean;
84
+ /**
85
+ * View height — a number is treated as px. The merge view scrolls as one surface (both
86
+ * sides together, which is what keeps chunks aligned); omit to grow with content.
87
+ */
88
+ height?: string | number;
89
+ /**
90
+ * View width — a number is treated as px. Omit to fill the container.
91
+ */
92
+ width?: string | number;
93
+ /**
94
+ * Editor font size in px, applied to both sides.
95
+ *
96
+ * @default 14
97
+ */
98
+ fontSize?: number;
99
+ /**
100
+ * Line height, both sides — same convention as the other inkstone editors: values below 8
101
+ * multiply the font size, larger values are absolute pixels.
102
+ *
103
+ * @default 1.6
104
+ */
105
+ lineHeight?: number;
106
+ className?: string;
107
+ /**
108
+ * Accessible name for the original (read-only) textbox. English by default — same policy
109
+ * as every inkstone label; localizing hosts pass their own. Fixed for the view's lifetime,
110
+ * like the other create-once wiring.
111
+ *
112
+ * @default "Original content"
113
+ */
114
+ originalAriaLabel?: string;
115
+ /**
116
+ * Accessible name for the modified (editable) textbox. Fixed for the view's lifetime.
117
+ *
118
+ * @default "Modified content"
119
+ */
120
+ modifiedAriaLabel?: string;
121
+ /**
122
+ * Runs once after the view is created, with the `MergeView` — the imperative handle to
123
+ * both `EditorView`s (`view.a` is the original, `view.b` the modified) and the computed
124
+ * chunks.
125
+ */
126
+ onMount?: (view: MergeView) => void;
127
+ }
128
+ /**
129
+ * A controlled side-by-side CodeMirror diff editor: `@codemirror/merge`'s `MergeView` behind
130
+ * the same create-once / reconcile-in-place discipline as `<CodeMirrorEditor>`, with the
131
+ * catppuccin flavors extended to the diff chrome (red deletions, green insertions, themed
132
+ * collapse bars and revert controls).
133
+ *
134
+ * The original side is read-only and follows the `original` prop; the modified side is the
135
+ * editable document behind `modified` / `onChange` (set `readOnly` for a pure viewer). Both
136
+ * sides share `language`, `extensions`, and the theme; dark flips, language loads, and
137
+ * `revertControls` / `collapseUnchanged` all swap in place without rebuilding the view.
138
+ */
139
+ declare function CodeMirrorDiffEditor({
140
+ original,
141
+ modified,
142
+ onChange,
143
+ language,
144
+ readOnly,
145
+ revertControls,
146
+ collapseUnchanged,
147
+ lineWrapping,
148
+ showLineNumbers,
149
+ extensions,
150
+ dynamicExtensions,
151
+ dark,
152
+ height,
153
+ width,
154
+ fontSize,
155
+ lineHeight,
156
+ className,
157
+ originalAriaLabel,
158
+ modifiedAriaLabel,
159
+ onMount
160
+ }: CodeMirrorDiffEditorProps): ReactNode;
161
+ //#endregion
10
162
  //#region src/codemirror-editor.d.ts
11
163
  interface CodeMirrorEditorProps {
12
164
  /**
@@ -20,7 +172,7 @@ interface CodeMirrorEditorProps {
20
172
  * selected language is fetched, never the whole catalog). For a language outside this set,
21
173
  * or for parser options / mixed languages, pass your own support through `extensions`.
22
174
  */
23
- language?: CodeMirrorLanguage$1;
175
+ language?: CodeMirrorLanguage;
24
176
  /**
25
177
  * Render-context schema for variable / member autocomplete — currently consumed by the
26
178
  * `minijinja` languages, where it makes `{{ }}` / `{% if %}` / `{% for x in %}` suggest the
@@ -29,7 +181,13 @@ interface CodeMirrorEditorProps {
29
181
  * reactively without recreating the editor. Memoize/hoist it — a new identity each render
30
182
  * re-normalizes and re-dispatches. No effect on languages that don't read it.
31
183
  */
32
- context?: EditorContext$1;
184
+ context?: EditorContext;
185
+ /**
186
+ * Database schema for SQL table / column autocomplete. Updates reactively without
187
+ * recreating the editor; memoize/hoist it to avoid redundant serialization. No effect on
188
+ * languages that do not consume it.
189
+ */
190
+ sqlSchema?: SqlSchema;
33
191
  placeholder?: string;
34
192
  /**
35
193
  * Soft-wrap long lines.
@@ -142,6 +300,12 @@ interface CodeMirrorEditorProps {
142
300
  * Called when the editor loses focus.
143
301
  */
144
302
  onBlur?: () => void;
303
+ /**
304
+ * Accessible name for the editor textbox.
305
+ *
306
+ * @default "Editor content"
307
+ */
308
+ ariaLabel?: string;
145
309
  }
146
310
  /**
147
311
  * A controlled CodeMirror 6 document editor: the standard document extension bundle
@@ -158,6 +322,7 @@ declare function CodeMirrorEditor({
158
322
  onChange,
159
323
  language,
160
324
  context,
325
+ sqlSchema,
161
326
  placeholder,
162
327
  lineWrapping,
163
328
  showLineNumbers,
@@ -176,215 +341,8 @@ declare function CodeMirrorEditor({
176
341
  className,
177
342
  onMount,
178
343
  onFocus,
179
- onBlur
344
+ onBlur,
345
+ ariaLabel
180
346
  }: CodeMirrorEditorProps): ReactNode;
181
347
  //#endregion
182
- //#region src/monaco-editor.d.ts
183
- /**
184
- * Baseline construction options shared by every inkstone Monaco editor: no minimap, compact
185
- * code type, in-place layout tracking, widgets floated above clipping containers, completion
186
- * tuned for API-assisted editing, thin scrollbars, and an embedded-friendly find widget.
187
- * Spread these to extend rather than replace: `options={{ ...DEFAULT_MONACO_OPTIONS, wordWrap: "on" }}`.
188
- */
189
- declare const DEFAULT_MONACO_OPTIONS: editor.IStandaloneEditorConstructionOptions;
190
- interface MonacoEditorProps {
191
- /**
192
- * The controlled document text.
193
- */
194
- value: string;
195
- onChange?: (value: string) => void;
196
- /**
197
- * Monaco language id. Built-in ids autocomplete; any custom-registered id is also accepted.
198
- *
199
- * @default "javascript"
200
- */
201
- language?: MonacoLanguage$1;
202
- /**
203
- * Render with the dark theme. The component never reads the OS `prefers-color-scheme`;
204
- * wire this to your app's color-scheme state.
205
- *
206
- * @default false
207
- */
208
- dark?: boolean;
209
- /**
210
- * UI locale for Monaco's built-in chrome (context menu, find widget, command palette …).
211
- * Unlike everything else on this component, the locale is **page-global and locked by the
212
- * first editor to mount** — Monaco resolves its UI strings once, at module evaluation — so
213
- * later editors with a different value are ignored. Overrides `hostOptions.locale` (the
214
- * same knob on the framework-agnostic host layer).
215
- *
216
- * @default "en"
217
- */
218
- locale?: MonacoUiLocale;
219
- /**
220
- * Placeholder shown while the document is empty. Maps to Monaco's native `placeholder`
221
- * editor option (0.47+); an explicit `options.placeholder` still wins.
222
- */
223
- placeholder?: string;
224
- /**
225
- * Soft-wrap long lines (Monaco `wordWrap`).
226
- *
227
- * @default false
228
- */
229
- lineWrapping?: boolean;
230
- /**
231
- * Show the line-number gutter (Monaco `lineNumbers`). For relative/interval modes pass an
232
- * explicit `options.lineNumbers`.
233
- *
234
- * @default false
235
- */
236
- showLineNumbers?: boolean;
237
- /**
238
- * Editor font size in px (Monaco `fontSize`). Omit to keep the inkstone default (14).
239
- */
240
- fontSize?: number;
241
- /**
242
- * Line height (Monaco `lineHeight`, and its convention): values below 8 multiply the font
243
- * size (e.g. `1.6`), larger values are absolute pixels (e.g. `22`). `<CodeMirrorEditor>`
244
- * mirrors the same semantics. Omit to keep the inkstone default (1.6).
245
- */
246
- lineHeight?: number;
247
- /**
248
- * Tab width in spaces (Monaco `tabSize`).
249
- *
250
- * @default 2
251
- */
252
- tabSize?: number;
253
- /**
254
- * Enable code folding (fold gutter + fold ranges). Unifies the toggle with
255
- * `<CodeMirrorEditor>`; note Monaco folds by default, so this turns its folding off unless
256
- * set.
257
- *
258
- * @default false
259
- */
260
- folding?: boolean;
261
- /**
262
- * Disable Monaco's right-click context menu (`contextmenu: false`). Right-clicks then fall
263
- * through to the browser, so its native menu applies — intercept `contextmenu` on a
264
- * wrapping element to suppress that as well.
265
- *
266
- * @default false
267
- */
268
- disableContextMenu?: boolean;
269
- /**
270
- * Swallow the find/replace widget's keyboard entries — Ctrl/Cmd+F (find), Ctrl+H and
271
- * Cmd+Alt+F (replace). Scoped to this editor via a context key: the standalone keybinding
272
- * service is page-global, so an unscoped rule would rewire every editor on the page.
273
- * Fixed at creation.
274
- *
275
- * @default false
276
- */
277
- disableFind?: boolean;
278
- /**
279
- * Swallow the command palette's keyboard entry, F1 — Monaco never binds Ctrl+Shift+P
280
- * (that is a VS Code binding). While the context menu is enabled, its "Command Palette"
281
- * item still opens the palette; pair with {@link disableContextMenu} to remove every
282
- * entry point. Fixed at creation.
283
- *
284
- * @default false
285
- */
286
- disableCommandPalette?: boolean;
287
- /**
288
- * Model path — give each logically distinct document its own so view state (cursor,
289
- * folds) survives remounts.
290
- */
291
- path?: string;
292
- height?: string | number;
293
- width?: string | number;
294
- className?: string;
295
- /**
296
- * Extra construction options, merged over {@link DEFAULT_MONACO_OPTIONS}.
297
- */
298
- options?: editor.IStandaloneEditorConstructionOptions;
299
- /**
300
- * Host bring-up options (UI locale, language workers). The Monaco host is a process-wide
301
- * singleton, so the first mounted editor wins and later values are ignored.
302
- */
303
- hostOptions?: MonacoHostOptions;
304
- /**
305
- * Shown while the host, highlighter, and editor chunk load.
306
- *
307
- * @default "Loading editor…"
308
- */
309
- loading?: ReactNode;
310
- /**
311
- * Shown when the Monaco host fails to load (e.g. a stale chunk 404 after a redeploy).
312
- * The failure is not cached by the host singleton, so a fresh mount retries.
313
- *
314
- * @default "Editor failed to load"
315
- */
316
- failure?: ReactNode;
317
- /**
318
- * Runs after inkstone's own pre-mount setup (Shiki theme registration).
319
- */
320
- beforeMount?: BeforeMount;
321
- onMount?: OnMount;
322
- /**
323
- * Called when the editor's text area gains focus (Monaco `onDidFocusEditorText`).
324
- */
325
- onFocus?: () => void;
326
- /**
327
- * Called when the editor's text area loses focus (Monaco `onDidBlurEditorText`).
328
- */
329
- onBlur?: () => void;
330
- }
331
- /**
332
- * A preconfigured, offline Monaco editor: bundled workers (no CDN), Shiki catppuccin
333
- * highlighting with light/dark switching, and sensible document defaults — drop it in with
334
- * `value` / `onChange` and everything else is wired. The UI speaks Monaco's stock English;
335
- * pass `hostOptions={{ locale: "zh-cn" }}` for the official Simplified-Chinese chrome.
336
- *
337
- * Mounting is gated on the Monaco host and the Shiki highlighter so the first paint already
338
- * has the right theme; if the highlighter fails to load, the editor falls back to Monaco's
339
- * built-in themes and stays usable.
340
- *
341
- * Do not `import "monaco-editor"` statically elsewhere in the app — that would evaluate
342
- * Monaco before its UI locale is set (see `ensureMonacoHost`). Type-only imports are fine.
343
- */
344
- declare function MonacoEditor({
345
- value,
346
- onChange,
347
- language,
348
- dark,
349
- locale,
350
- placeholder,
351
- lineWrapping,
352
- showLineNumbers,
353
- folding,
354
- disableContextMenu,
355
- disableFind,
356
- disableCommandPalette,
357
- fontSize,
358
- lineHeight,
359
- tabSize,
360
- path,
361
- height,
362
- width,
363
- className,
364
- options,
365
- hostOptions,
366
- loading,
367
- failure,
368
- beforeMount,
369
- onMount,
370
- onFocus,
371
- onBlur
372
- }: MonacoEditorProps): ReactNode;
373
- //#endregion
374
- //#region src/use-shiki-highlighter.d.ts
375
- type ShikiState = "loading" | "ready" | "failed";
376
- /**
377
- * Load the shared Shiki highlighter and expose its lifecycle to gate editor mounting:
378
- * waiting for `ready` before creating the editor avoids a default-theme flash (and the
379
- * "theme not found" console error) on first paint; on `failed` the caller falls back to
380
- * the engine's built-in theme so the editor stays usable.
381
- *
382
- * `highlighterRef` is for pre-mount hooks (Monaco `beforeMount`) that must read the
383
- * instance synchronously before the editor is created.
384
- */
385
- declare function useShikiHighlighter(): {
386
- state: ShikiState;
387
- highlighterRef: RefObject<HighlighterCore | null>;
388
- };
389
- //#endregion
390
- export { CodeMirrorEditor, type CodeMirrorEditorProps, type CodeMirrorLanguage, DEFAULT_MONACO_OPTIONS, type EditorContext, MonacoEditor, type MonacoEditorProps, type MonacoLanguage, type ShikiState, codeMirrorLanguages, normalizeContext, searchPhrasesZhCn, useShikiHighlighter };
348
+ export { codeMirrorLanguages as a, CodeMirrorEditor as c, CodeMirrorDiffEditorProps as d, SqlSchema$1 as i, CodeMirrorEditorProps as l, EditorContext$1 as n, normalizeContext$1 as o, MergeView$1 as r, searchPhrasesZhCn$1 as s, CodeMirrorLanguage$1 as t, CodeMirrorDiffEditor as u };
@@ -0,0 +1,2 @@
1
+ import { a as codeMirrorLanguages, c as CodeMirrorEditor, d as CodeMirrorDiffEditorProps, i as SqlSchema, l as CodeMirrorEditorProps, n as EditorContext, o as normalizeContext, r as MergeView, s as searchPhrasesZhCn, t as CodeMirrorLanguage, u as CodeMirrorDiffEditor } from "./codemirror-B3GlIVaX.js";
2
+ export { CodeMirrorDiffEditor, type CodeMirrorDiffEditorProps, CodeMirrorEditor, type CodeMirrorEditorProps, type CodeMirrorLanguage, type EditorContext, type MergeView, type SqlSchema, codeMirrorLanguages, normalizeContext, searchPhrasesZhCn };
@@ -0,0 +1,2 @@
1
+ import { a as CodeMirrorDiffEditor, i as CodeMirrorEditor, n as normalizeContext, r as searchPhrasesZhCn, t as codeMirrorLanguages } from "./codemirror-B27C5np1.js";
2
+ export { CodeMirrorDiffEditor, CodeMirrorEditor, codeMirrorLanguages, normalizeContext, searchPhrasesZhCn };