@coldsmirk/inkstone-react 0.9.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.
@@ -0,0 +1,348 @@
1
+ import { Extension } from "@codemirror/state";
2
+ import { EditorView } from "@codemirror/view";
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";
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
162
+ //#region src/codemirror-editor.d.ts
163
+ interface CodeMirrorEditorProps {
164
+ /**
165
+ * The controlled document text — external changes reconcile into the live editor
166
+ * without resetting the caret.
167
+ */
168
+ value: string;
169
+ onChange?: (value: string) => void;
170
+ /**
171
+ * Language id — lazily loads the matching CodeMirror grammar as its own chunk (only the
172
+ * selected language is fetched, never the whole catalog). For a language outside this set,
173
+ * or for parser options / mixed languages, pass your own support through `extensions`.
174
+ */
175
+ language?: CodeMirrorLanguage;
176
+ /**
177
+ * Render-context schema for variable / member autocomplete — currently consumed by the
178
+ * `minijinja` languages, where it makes `{{ }}` / `{% if %}` / `{% for x in %}` suggest the
179
+ * template's context variables and walk member access (`user.address.city`). Pass a JSON Schema
180
+ * (`{ schema }`, e.g. what Rust `schemars` derives) or a sample value (`{ sample }`); it updates
181
+ * reactively without recreating the editor. Memoize/hoist it — a new identity each render
182
+ * re-normalizes and re-dispatches. No effect on languages that don't read it.
183
+ */
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;
191
+ placeholder?: string;
192
+ /**
193
+ * Soft-wrap long lines.
194
+ *
195
+ * @default false
196
+ */
197
+ lineWrapping?: boolean;
198
+ /**
199
+ * Show the line-number gutter. Fixed at creation, like `lineWrapping` / `placeholder`.
200
+ *
201
+ * @default false
202
+ */
203
+ showLineNumbers?: boolean;
204
+ /**
205
+ * Enable code folding (fold gutter + keymap). Fixed at creation; fold points come from the
206
+ * language, so set `language` too.
207
+ *
208
+ * @default false
209
+ */
210
+ folding?: boolean;
211
+ /**
212
+ * Turn native browser spell-check on. Off by default (CodeMirror's own default, right for
213
+ * code); enable for prose-grade documents like prompt templates. Fixed at creation.
214
+ *
215
+ * @default false
216
+ */
217
+ spellcheck?: boolean;
218
+ /**
219
+ * Enable in-editor search: Ctrl/Cmd-F opens a catppuccin-styled search/replace panel; F3 /
220
+ * Ctrl/Cmd-G cycle matches, Ctrl/Cmd-D selects the next occurrence, Alt-G jumps to a line.
221
+ * The panel speaks CodeMirror's stock English — set `locale="zh-cn"` (or pass
222
+ * `searchPhrasesZhCn` through `extensions`) for Simplified Chinese. Off by default —
223
+ * embedded fields rarely want a search UI. Fixed at creation.
224
+ *
225
+ * @default false
226
+ */
227
+ search?: boolean;
228
+ /**
229
+ * Editor font size in px, applied as a theme extension.
230
+ *
231
+ * @default 14
232
+ */
233
+ fontSize?: number;
234
+ /**
235
+ * Line height, applied as a theme extension on the scroller so content and gutters stay
236
+ * in step. Same convention as `<MonacoEditor>` (Monaco's own): values below 8 multiply the
237
+ * font size (e.g. `1.6` — CSS's unitless line-height), larger values are absolute pixels
238
+ * (e.g. `22`).
239
+ *
240
+ * @default 1.6
241
+ */
242
+ lineHeight?: number;
243
+ /**
244
+ * Tab width in spaces — sets both the displayed tab width (`EditorState.tabSize`) and the
245
+ * indent string inserted on Tab (`indentUnit`), so display and indentation stay in sync.
246
+ */
247
+ tabSize?: number;
248
+ /**
249
+ * Static extensions (language support, keymaps …), fixed for the editor's lifetime.
250
+ * Hoist the array — a new identity per render is ignored by design (create-once).
251
+ */
252
+ extensions?: Extension[];
253
+ /**
254
+ * Extensions swapped in place when the identity changes (theme, language config) —
255
+ * memoize with `useMemo` keyed on what actually changes. Layered after (and so able to
256
+ * override) inkstone's default catppuccin theme.
257
+ */
258
+ dynamicExtensions?: Extension[];
259
+ /**
260
+ * Use the dark catppuccin flavor (macchiato) instead of the light one (latte). The
261
+ * component never reads the OS `prefers-color-scheme`; wire this to your app's
262
+ * color-scheme state — same policy as `<MonacoEditor>`.
263
+ *
264
+ * @default false
265
+ */
266
+ dark?: boolean;
267
+ /**
268
+ * Locale for the phrase tables inkstone ships for CodeMirror's stock UI strings —
269
+ * currently the search / goto-line panel. Unlike Monaco's page-global locale, this is
270
+ * genuinely per-editor (`EditorState.phrases`) and swaps in place. Equivalent to passing
271
+ * `searchPhrasesZhCn` through `extensions`, which stays the framework-agnostic surface.
272
+ *
273
+ * @default "en"
274
+ */
275
+ locale?: "en" | "zh-cn";
276
+ /**
277
+ * Editor height — a number is treated as px. Sizes the editor box and hands overflow to
278
+ * the scroller; omit to grow with content.
279
+ */
280
+ height?: string | number;
281
+ /**
282
+ * Editor width — a number is treated as px. Omit to fill the container.
283
+ */
284
+ width?: string | number;
285
+ className?: string;
286
+ /**
287
+ * Runs once after the editor is created, with the CodeMirror `EditorView` — the imperative
288
+ * handle for focus, dispatch, scrolling, selection, etc. This is CodeMirror's analog of
289
+ * Monaco's `onMount`. Monaco's `loading` / `beforeMount` have no counterpart here: the
290
+ * editor mounts synchronously (no host or editor chunk to await — only the optional
291
+ * `language` grammar streams in behind an already-usable editor), and pre-creation setup is
292
+ * the `extensions` prop rather than a global instance to configure.
293
+ */
294
+ onMount?: (view: EditorView) => void;
295
+ /**
296
+ * Called when the editor gains focus.
297
+ */
298
+ onFocus?: () => void;
299
+ /**
300
+ * Called when the editor loses focus.
301
+ */
302
+ onBlur?: () => void;
303
+ /**
304
+ * Accessible name for the editor textbox.
305
+ *
306
+ * @default "Editor content"
307
+ */
308
+ ariaLabel?: string;
309
+ }
310
+ /**
311
+ * A controlled CodeMirror 6 document editor: the standard document extension bundle
312
+ * (line numbers, history, brackets, completion UI — see `documentExtensions`) plus the
313
+ * create-once / reconcile-in-place plumbing of `ControlledEditorHost`, exposed as a plain
314
+ * React component.
315
+ *
316
+ * Ships the catppuccin theme by default (latte / macchiato, flipped by `dark`) and takes
317
+ * `height` / `width` for sizing — parity with `<MonacoEditor>`. Bring your own language
318
+ * support via `extensions`; a theme passed through `dynamicExtensions` overrides the default.
319
+ */
320
+ declare function CodeMirrorEditor({
321
+ value,
322
+ onChange,
323
+ language,
324
+ context,
325
+ sqlSchema,
326
+ placeholder,
327
+ lineWrapping,
328
+ showLineNumbers,
329
+ folding,
330
+ spellcheck,
331
+ search,
332
+ extensions,
333
+ dynamicExtensions,
334
+ dark,
335
+ locale,
336
+ height,
337
+ width,
338
+ fontSize,
339
+ lineHeight,
340
+ tabSize,
341
+ className,
342
+ onMount,
343
+ onFocus,
344
+ onBlur,
345
+ ariaLabel
346
+ }: CodeMirrorEditorProps): ReactNode;
347
+ //#endregion
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 };