@typbase/codemirror 0.3.1 → 0.4.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/LICENSE +190 -661
- package/dist/index.d.mts +133 -75
- package/dist/index.mjs +585 -352
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -5,41 +5,63 @@ import { Diagnostic } from "@codemirror/lint";
|
|
|
5
5
|
import { LRUCache } from "lru-cache";
|
|
6
6
|
import { FileId, SvgRangedFrame, TypstDiagnostic, TypstState } from "@typbase/engine";
|
|
7
7
|
//#region src/notebook.d.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export type NotebookCellType = "prose" | "code" | "log" | "hidden";
|
|
9
|
+
/** Every type, in the order the menu lists them. */
|
|
10
|
+
export declare const NOTEBOOK_CELL_TYPES: readonly NotebookCellType[];
|
|
11
|
+
/** True when the cell renders in place rather than showing source plus output. */
|
|
12
|
+
export declare function rendersInPlace(kind: NotebookCellType): boolean;
|
|
13
|
+
/** True when the cell's source is not part of what the reader sees. */
|
|
14
|
+
export declare function hidesSource(kind: NotebookCellType): boolean;
|
|
15
|
+
/** True when the cell has an output area below its source. */
|
|
16
|
+
export declare function hasOutput(kind: NotebookCellType): boolean;
|
|
14
17
|
export interface NotebookCell {
|
|
15
18
|
kind: NotebookCellType;
|
|
19
|
+
/** `name=` from the attribute line, when it carries one. */
|
|
20
|
+
name?: string | null;
|
|
16
21
|
marker_start: number;
|
|
17
22
|
marker_end: number;
|
|
18
23
|
content_start: number;
|
|
19
24
|
content_end: number;
|
|
20
25
|
}
|
|
21
|
-
/** Per-cell state the host owns: run counters and visibility. */
|
|
22
26
|
export interface NotebookCellState {
|
|
23
|
-
/** Execution counter shown as `[n]`; undefined until the cell is run. */
|
|
24
|
-
count?: number;
|
|
25
|
-
/** Output hidden until the next run. */
|
|
26
|
-
cleared?: boolean;
|
|
27
27
|
/** Source hidden behind the header. */
|
|
28
28
|
collapsed?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Keep the output this cell had when it was held. For the cells where a live
|
|
31
|
+
* render is wrong or expensive: a heavy query, a non-deterministic one, one
|
|
32
|
+
* with a side effect. See the note in `NotebookOptions.onCompile`.
|
|
33
|
+
*/
|
|
34
|
+
held?: boolean;
|
|
35
|
+
/** The held cell's last output, kept by the host. */
|
|
36
|
+
frozen?: NotebookCellOutput;
|
|
37
|
+
/** Output hidden until the cell is refreshed. */
|
|
38
|
+
cleared?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** One cell's rendered output: its frames and the diagnostics inside it. */
|
|
41
|
+
export interface NotebookCellOutput {
|
|
42
|
+
frames: SvgRangedFrame[];
|
|
43
|
+
diagnostics: TypstDiagnostic[];
|
|
29
44
|
}
|
|
30
45
|
/** UI strings, injected by the app so the package stays i18n-free. */
|
|
31
46
|
export interface NotebookLabels {
|
|
32
|
-
run: string;
|
|
33
47
|
code: string;
|
|
34
|
-
|
|
48
|
+
prose: string;
|
|
49
|
+
log: string;
|
|
50
|
+
hidden: string;
|
|
51
|
+
menu: string;
|
|
52
|
+
split: string;
|
|
53
|
+
merge: string;
|
|
35
54
|
moveUp: string;
|
|
36
55
|
moveDown: string;
|
|
37
56
|
duplicate: string;
|
|
38
57
|
remove: string;
|
|
58
|
+
copy: string;
|
|
59
|
+
hold: string;
|
|
60
|
+
release: string;
|
|
39
61
|
clearOutput: string;
|
|
40
62
|
toggleSource: string;
|
|
41
63
|
noOutput: string;
|
|
42
|
-
|
|
64
|
+
held: string;
|
|
43
65
|
}
|
|
44
66
|
export interface NotebookCompileResult {
|
|
45
67
|
text: string;
|
|
@@ -47,43 +69,49 @@ export interface NotebookCompileResult {
|
|
|
47
69
|
diagnostics: TypstDiagnostic[];
|
|
48
70
|
}
|
|
49
71
|
export interface NotebookOptions {
|
|
50
|
-
/** Cells for a document text
|
|
72
|
+
/** Cells for a document text. The host reads them from the engine. */
|
|
51
73
|
cells: (text: string) => NotebookCell[];
|
|
52
|
-
/**
|
|
74
|
+
/** Per-cell state. The host owns it. */
|
|
53
75
|
state?: (index: number) => NotebookCellState | undefined;
|
|
54
|
-
/** Show `[n]` execution counters. */
|
|
55
|
-
counters?: () => boolean;
|
|
56
76
|
labels?: NotebookLabels;
|
|
57
77
|
/** Fires whenever the extension re-extracts cells. */
|
|
58
78
|
onCells?: (cells: NotebookCell[]) => void;
|
|
59
79
|
/** Fires when the cursor moves to a different cell. */
|
|
60
80
|
onActiveCell?: (index: number | null) => void;
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Fires after a compile with the fresh frames and diagnostics.
|
|
83
|
+
*/
|
|
64
84
|
onCompile?: (result: NotebookCompileResult) => void;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
|
|
85
|
+
/** A cell's state changed and the decorations need a rebuild. */
|
|
86
|
+
onStateChange?: () => void;
|
|
87
|
+
/** A command from the rail's overflow menu, so the app owns the actions. */
|
|
88
|
+
onCommand?: (command: string, index: number) => void;
|
|
89
|
+
/** Read-only pages show cells without source or chrome. */
|
|
90
|
+
readOnly?: () => boolean;
|
|
69
91
|
}
|
|
70
92
|
/** The options of the notebook extension active in this state, if any. */
|
|
71
93
|
export declare const notebookOptionsFacet: Facet<NotebookOptions, NotebookOptions | undefined>;
|
|
72
94
|
export declare function notebookOptions(state: EditorState): NotebookOptions | undefined;
|
|
73
95
|
/** Re-renders notebooks from cached frames without recompiling. */
|
|
74
96
|
export declare const notebookRefreshEffect: import("@codemirror/state").StateEffectType<null>;
|
|
75
|
-
/**
|
|
76
|
-
export declare const notebookRunEffect: import("@codemirror/state").StateEffectType<{
|
|
77
|
-
index: number | "all";
|
|
78
|
-
}>;
|
|
79
|
-
/** First position that belongs to the cell (marker line, or content). */
|
|
97
|
+
/** First position that belongs to the cell (attribute line, or content). */
|
|
80
98
|
export declare function cellStart(cell: NotebookCell): number;
|
|
81
|
-
|
|
82
|
-
|
|
99
|
+
/** True when the cell opened with an attribute line rather than a heading. */
|
|
100
|
+
export declare function hasAttribute(cell: NotebookCell): boolean;
|
|
101
|
+
/** Index of the cell containing `pos`. Gaps belong to the cell above. */
|
|
83
102
|
export declare function cellIndexAt(cells: NotebookCell[], pos: number): number;
|
|
84
103
|
export declare function cellsOf(state: EditorState): NotebookCell[];
|
|
85
|
-
/**
|
|
86
|
-
|
|
104
|
+
/**
|
|
105
|
+
* The attribute line for a cell type. Prose needs no `kind=`, so a plain cell is
|
|
106
|
+
* three characters.
|
|
107
|
+
*/
|
|
108
|
+
export declare function attributeText(type: NotebookCellType, name?: string | null): string;
|
|
109
|
+
/**
|
|
110
|
+
* Removes cell attribute lines. Notebooks are comments-plus-content, so a
|
|
111
|
+
* cleaned file is the same document for anyone who does not know the
|
|
112
|
+
* convention. Only `//%` goes: any other comment is left as written.
|
|
113
|
+
*/
|
|
114
|
+
export declare function stripCellAttributes(text: string): string;
|
|
87
115
|
/** A text replacement plus where the cursor should land after it. */
|
|
88
116
|
export interface CellEdit {
|
|
89
117
|
changes: {
|
|
@@ -93,38 +121,41 @@ export interface CellEdit {
|
|
|
93
121
|
};
|
|
94
122
|
anchor: number;
|
|
95
123
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Splits a cell at `pos` inside its content. The new cell takes the text from
|
|
126
|
+
* `pos` and inherits the old cell's kind, because a split is a continuation.
|
|
127
|
+
*/
|
|
100
128
|
export declare function splitCellText(text: string, cells: NotebookCell[], index: number, pos: number): CellEdit | null;
|
|
101
|
-
export declare function mergeCellText(text: string, cells: NotebookCell[], index: number): CellEdit | null;
|
|
102
|
-
export declare function setCellTypeText(text: string, cells: NotebookCell[], index: number, type: NotebookCellType): CellEdit;
|
|
103
129
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* convention.
|
|
130
|
+
* Merges a cell into the one above. The result takes the lower cell's kind,
|
|
131
|
+
* since that is the one the reader was last looking at.
|
|
107
132
|
*/
|
|
108
|
-
export declare function
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
-
|
|
133
|
+
export declare function mergeCellText(cells: NotebookCell[], index: number): CellEdit | null;
|
|
134
|
+
/**
|
|
135
|
+
* Rewrites a cell's attribute line. A cell that began at a heading has no line
|
|
136
|
+
* to rewrite, so one is inserted.
|
|
137
|
+
*/
|
|
138
|
+
export declare function setCellTypeText(text: string, cells: NotebookCell[], index: number, type: NotebookCellType): CellEdit | null;
|
|
139
|
+
/** Appends a cell of `type` after `index` (or at the end of the document). */
|
|
140
|
+
export declare function insertCellText(text: string, cells: NotebookCell[], index: number, type: NotebookCellType, content?: string): CellEdit | null;
|
|
141
|
+
export declare function deleteCellText(cells: NotebookCell[], index: number, docLength: number): CellEdit | null;
|
|
142
|
+
/** Copies a cell's kind, name, and body below it. */
|
|
143
|
+
export declare function duplicateCellText(text: string, cells: NotebookCell[], index: number): CellEdit | null;
|
|
144
|
+
/** Selects a cell's content so the keyboard commands act on it. */
|
|
112
145
|
export declare function focusCell(view: EditorView, index: number, edge?: "start" | "end"): boolean;
|
|
113
|
-
export declare function
|
|
114
|
-
|
|
115
|
-
export declare function
|
|
116
|
-
export declare function
|
|
117
|
-
export declare function deleteCell(view: EditorView): boolean;
|
|
118
|
-
|
|
119
|
-
export declare function moveCell(view: EditorView, delta:
|
|
120
|
-
export declare function
|
|
146
|
+
export declare function currentCell(view: EditorView): number;
|
|
147
|
+
/** Inserts a cell below `index`, or at the end of the document. */
|
|
148
|
+
export declare function insertCell(view: EditorView, type: NotebookCellType, content?: string, index?: number): boolean;
|
|
149
|
+
export declare function duplicateCell(view: EditorView, index?: number): boolean;
|
|
150
|
+
export declare function deleteCell(view: EditorView, index?: number): boolean;
|
|
151
|
+
/** Moves the active cell up or down. */
|
|
152
|
+
export declare function moveCell(view: EditorView, delta: number): boolean;
|
|
153
|
+
export declare function setCellType(view: EditorView, index: number, type: NotebookCellType): boolean;
|
|
121
154
|
export declare function splitCell(view: EditorView): boolean;
|
|
122
155
|
export declare function mergeCell(view: EditorView): boolean;
|
|
123
|
-
export declare function toggleCellType(view: EditorView, index: number): boolean;
|
|
124
|
-
export declare function setCellType(view: EditorView, index: number, type: NotebookCellType): boolean;
|
|
125
156
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
157
|
+
* The editor's cell commands. Everything here is also in the cell menu, and
|
|
158
|
+
* every one of them is a text edit, so the undo stack covers them all.
|
|
128
159
|
*/
|
|
129
160
|
export declare const notebookKeymap: import("@codemirror/state").Extension;
|
|
130
161
|
//#endregion
|
|
@@ -152,23 +183,29 @@ export interface TypstPluginOptions {
|
|
|
152
183
|
/**
|
|
153
184
|
* Called when a compile into the wasm instance threw. On wasm32 a panic
|
|
154
185
|
* aborts the instance, so the host must recreate `typstState` and remount
|
|
155
|
-
* the editor
|
|
186
|
+
* the editor. The plugin drops the decorations for the failed pass.
|
|
156
187
|
*/
|
|
157
188
|
onPanic?: (fileId: FileId) => void;
|
|
158
|
-
/** Called after a compile pass succeeds
|
|
189
|
+
/** Called after a compile pass succeeds. The host resets its health and
|
|
159
190
|
* heap watchdog on it. */
|
|
160
191
|
onCompile?: () => void;
|
|
161
192
|
/**
|
|
162
193
|
* Opens a link clicked inside a rendered frame. Defaults to a new browser
|
|
163
|
-
* tab
|
|
194
|
+
* tab. The app passes its Tauri-aware `openExternal`.
|
|
164
195
|
*/
|
|
165
196
|
onExternalLink?: (url: string) => void;
|
|
166
197
|
/**
|
|
167
198
|
* Cell rendering and cell commands. When set, the editor behaves like a
|
|
168
|
-
* notebook:
|
|
199
|
+
* notebook: prose cells render inline, code cells render below, and the
|
|
169
200
|
* notebook keymap takes precedence over the line editing bindings.
|
|
170
201
|
*/
|
|
171
202
|
notebook?: NotebookOptions;
|
|
203
|
+
/**
|
|
204
|
+
* Draw the frames, or show plain source. Defaults to true. A notebook page in
|
|
205
|
+
* source mode passes false: the cells and their rails stay, but nothing is
|
|
206
|
+
* rendered, which is the only difference between its write and source modes.
|
|
207
|
+
*/
|
|
208
|
+
renderFrames?: boolean;
|
|
172
209
|
}
|
|
173
210
|
export declare const typstPlugin: (fileId: FileId, spaceId: string, path: string, text: TextRef, prelude: TextRef, locked: boolean, typstState: TypstState, options?: TypstPluginOptions) => Extension;
|
|
174
211
|
//#endregion
|
|
@@ -206,17 +243,16 @@ export interface TypstLinterOptions {
|
|
|
206
243
|
}
|
|
207
244
|
/**
|
|
208
245
|
* Typst diagnostics as a CodeMirror linter source.
|
|
209
|
-
*
|
|
210
|
-
* This runs in every editor mode and combines with other sources (the
|
|
211
|
-
* spellcheck linter), so neither one replaces the other. The WYSIWYG plugin's
|
|
212
|
-
* compile feeds the cache; split and source mode fall back to a compile here
|
|
213
|
-
* so they get diagnostics too.
|
|
214
246
|
*/
|
|
215
247
|
export declare const typstLinter: (fileId: FileId, spaceId: string, path: string, prelude: TextRef, typstState: TypstState, options?: TypstLinterOptions) => import("@codemirror/state").Extension;
|
|
216
248
|
//#endregion
|
|
217
249
|
//#region src/frames.d.ts
|
|
218
250
|
/**
|
|
219
|
-
*
|
|
251
|
+
* Places the glyph and gradient definitions a frame set references.
|
|
252
|
+
*/
|
|
253
|
+
export declare function installSharedDefs(defs: string | null | undefined): void;
|
|
254
|
+
/**
|
|
255
|
+
* Opens an external link for the host. Browsers get a new tab. The app passes
|
|
220
256
|
* its `openExternal`, which hands the URL to the system browser in Tauri
|
|
221
257
|
* (a webview has no tab strip, so `window.open` is dropped there).
|
|
222
258
|
*/
|
|
@@ -241,8 +277,8 @@ export declare function frameSize(frame: SvgRangedFrame): {
|
|
|
241
277
|
* container keeps max-width: 100% so it never exceeds the line. An explicit
|
|
242
278
|
* container width would make CodeMirror's flex layout grow the content width
|
|
243
279
|
* forever (resize -> wider widget -> wider content). The pinned SVG overflows
|
|
244
|
-
* the clamped container while the pane is narrower than the compiled width
|
|
245
|
-
*
|
|
280
|
+
* the clamped container while the pane is narrower than the compiled width.
|
|
281
|
+
* The scroller clips it, so the render stays its size instead of scaling.
|
|
246
282
|
*/
|
|
247
283
|
export declare function syncFrameContainer(container: HTMLElement, frame: SvgRangedFrame): void;
|
|
248
284
|
/** Fresh frame container for widgets that own their DOM (notebook outputs). */
|
|
@@ -266,7 +302,7 @@ export declare function frameIsInactive(view: EditorView, state: EditorState, st
|
|
|
266
302
|
* the source stays visible with the frame's height reserved, so the pane does
|
|
267
303
|
* not jump between render and source. Matches the inline WYSIWYG behavior.
|
|
268
304
|
*
|
|
269
|
-
* `lineHeights` carries measured source heights from the remeasure pass
|
|
305
|
+
* `lineHeights` carries measured source heights from the remeasure pass. When
|
|
270
306
|
* it is absent the view still reports the widget's height for those lines.
|
|
271
307
|
*/
|
|
272
308
|
export declare function frameActiveDecorations(view: EditorView, state: EditorState, frame: SvgRangedFrame, lineHeights?: Map<number, number>): Range<Decoration>[];
|
|
@@ -304,6 +340,12 @@ export declare const typstLanguageData: import("@codemirror/state").Extension;
|
|
|
304
340
|
//#region src/static-highlight.d.ts
|
|
305
341
|
export declare const typstStaticHighlighting: StateField<DecorationSet>;
|
|
306
342
|
//#endregion
|
|
343
|
+
//#region src/sync.d.ts
|
|
344
|
+
/**
|
|
345
|
+
* Keeps the engine's sources in step with the editor, without rendering.
|
|
346
|
+
*/
|
|
347
|
+
export declare const typstSourceSync: (fileId: FileId, prelude: TextRef, typstState: TypstState) => Extension;
|
|
348
|
+
//#endregion
|
|
307
349
|
//#region src/tooltip.d.ts
|
|
308
350
|
export declare const tooltipStateField: StateField<Tooltip | null>;
|
|
309
351
|
export declare const tooltipViewPlugin: () => ViewPlugin<{
|
|
@@ -311,9 +353,14 @@ export declare const tooltipViewPlugin: () => ViewPlugin<{
|
|
|
311
353
|
}, undefined>;
|
|
312
354
|
//#endregion
|
|
313
355
|
//#region src/widgets.d.ts
|
|
356
|
+
/**
|
|
357
|
+
* Compiled frames per cache key, where the key is `path:revision:appRevision`.
|
|
358
|
+
*/
|
|
314
359
|
export declare const compileCache: LRUCache<string, {
|
|
315
360
|
frames: SvgRangedFrame[];
|
|
316
361
|
tooltips: SvgRangedFrame[];
|
|
362
|
+
/** Every equation in the note, not only the one the caret was in. */
|
|
363
|
+
equationRanges: [number, number][];
|
|
317
364
|
diagnostics: TypstDiagnostic[];
|
|
318
365
|
}, unknown>;
|
|
319
366
|
/**
|
|
@@ -321,8 +368,18 @@ export declare const compileCache: LRUCache<string, {
|
|
|
321
368
|
* app data changed (fonts installed, workspace data, query results).
|
|
322
369
|
*/
|
|
323
370
|
export declare const typstRecompileEffect: import("@codemirror/state").StateEffectType<null>;
|
|
324
|
-
export
|
|
325
|
-
|
|
371
|
+
export interface EquationOverlays {
|
|
372
|
+
/** Rendered overlays, at most one when the render was given a caret. */
|
|
373
|
+
tooltips: SvgRangedFrame[];
|
|
374
|
+
/**
|
|
375
|
+
* Every equation range in the note, not only the one the caret was in. The
|
|
376
|
+
* popup compares the cursor against these to know when it has entered math
|
|
377
|
+
* whose overlay the last render skipped.
|
|
378
|
+
*/
|
|
379
|
+
ranges: [number, number][];
|
|
380
|
+
}
|
|
381
|
+
export declare const tooltipsStateEffect: import("@codemirror/state").StateEffectType<EquationOverlays>;
|
|
382
|
+
export declare const tooltipsStateField: StateField<EquationOverlays>;
|
|
326
383
|
export declare const typstStateField: StateField<DecorationSet>;
|
|
327
384
|
export interface TypstViewPluginOptions {
|
|
328
385
|
onRequests?: TypstRequestHandler;
|
|
@@ -330,13 +387,14 @@ export interface TypstViewPluginOptions {
|
|
|
330
387
|
revision?: () => string | number | undefined;
|
|
331
388
|
/** See TypstPluginOptions#onPanic. */
|
|
332
389
|
onPanic?: (fileId: FileId) => void;
|
|
333
|
-
/** Called after a compile pass succeeds
|
|
390
|
+
/** Called after a compile pass succeeds. The host resets its health and
|
|
334
391
|
* heap watchdog on it. */
|
|
335
392
|
onCompile?: () => void;
|
|
336
393
|
/** See TypstPluginOptions#onExternalLink. */
|
|
337
394
|
onExternalLink?: ExternalLinkOpener;
|
|
338
395
|
/** Cell rendering, run effects, and cell commands for notebook mode. */
|
|
339
396
|
notebook?: NotebookOptions;
|
|
397
|
+
renderFrames?: boolean;
|
|
340
398
|
}
|
|
341
399
|
export declare const typstViewPlugin: (fileId: FileId, spaceId: string, path: string, text: TextRef, prelude: TextRef, locked: boolean, typstState: TypstState, options?: TypstViewPluginOptions) => ViewPlugin<{
|
|
342
400
|
update(update: ViewUpdate): void;
|