typewright 0.2.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.
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/SPEC.md +327 -0
- package/dist/chunk-CZQO7TTL.js +1533 -0
- package/dist/chunk-CZQO7TTL.js.map +1 -0
- package/dist/chunk-KNEKNZXK.js +286 -0
- package/dist/chunk-KNEKNZXK.js.map +1 -0
- package/dist/chunk-M6IVEMXO.js +1398 -0
- package/dist/chunk-M6IVEMXO.js.map +1 -0
- package/dist/chunk-NJ7PJKHN.js +652 -0
- package/dist/chunk-NJ7PJKHN.js.map +1 -0
- package/dist/commands-Z3ndUSza.d.cts +221 -0
- package/dist/commands-Z3ndUSza.d.ts +221 -0
- package/dist/core/index.cjs +2952 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +410 -0
- package/dist/core/index.d.ts +410 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/mdx/index.cjs +662 -0
- package/dist/mdx/index.cjs.map +1 -0
- package/dist/mdx/index.d.cts +252 -0
- package/dist/mdx/index.d.ts +252 -0
- package/dist/mdx/index.js +3 -0
- package/dist/mdx/index.js.map +1 -0
- package/dist/react/index.cjs +7439 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +140 -0
- package/dist/react/index.d.ts +140 -0
- package/dist/react/index.js +3644 -0
- package/dist/react/index.js.map +1 -0
- package/dist/streaming/index.cjs +1494 -0
- package/dist/streaming/index.cjs.map +1 -0
- package/dist/streaming/index.d.cts +64 -0
- package/dist/streaming/index.d.ts +64 -0
- package/dist/streaming/index.js +4 -0
- package/dist/streaming/index.js.map +1 -0
- package/dist/types-CX1GOx0Y.d.cts +319 -0
- package/dist/types-CX1GOx0Y.d.ts +319 -0
- package/package.json +128 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { E as EditorConfig, a as EditorEvents, D as DocChange, b as DocSelection } from '../types-CX1GOx0Y.js';
|
|
2
|
+
export { A as AnticipationOptions, C as CommentReply, c as CommentThread, d as CommentsOptions, e as ComponentMap, f as DocPosition, g as DocRange, h as EditorMode, i as Extensions, F as FoldingOptions, G as GfmFeatures, K as KeymapOptions, M as MathOptions, j as MdxOptions, k as MdxTransform, l as MermaidOptions, P as PresencePeer, S as SandboxOptions, m as SettingsCommand, n as SettingsOptions, o as StreamController, p as StreamOptions, q as SyntaxHighlightOptions, T as ThemeOptions } from '../types-CX1GOx0Y.js';
|
|
3
|
+
import { P as ParseOptions, D as Document, I as Inline, B as Block, a as Pos, T as Table, C as CellAlign } from '../commands-Z3ndUSza.js';
|
|
4
|
+
export { A as AstNode, b as Autolink, c as Blockquote, d as COMMANDS, e as CodeBlock, f as Command, g as CommandResult, h as DefItem, i as DefList, E as Emphasis, F as FootnoteDef, j as FootnoteRef, H as Heading, k as HtmlBlock, l as Image, m as InlineCode, L as LineBreak, n as Link, o as List, p as ListItem, M as Math, q as MathBlock, r as Paragraph, S as Sel, s as Strikethrough, t as Strong, u as TableCell, v as TaskState, w as TextNode, x as ThematicBreak, y as applyCommand, z as childrenOf, G as isInline, J as walk } from '../commands-Z3ndUSza.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Document model — an immutable text container with transaction-based edits and
|
|
8
|
+
* position mapping. The string is the source of truth (SPEC.md §4.1): every edit
|
|
9
|
+
* is a `{from, to, insert}` change, applying one returns a NEW `TextDoc`, and
|
|
10
|
+
* offsets can be mapped across a change so decorations / anchors survive edits.
|
|
11
|
+
*/
|
|
12
|
+
interface Change {
|
|
13
|
+
/** Inclusive start offset of the replaced range. */
|
|
14
|
+
from: number;
|
|
15
|
+
/** Exclusive end offset of the replaced range. */
|
|
16
|
+
to: number;
|
|
17
|
+
/** Text inserted in place of `[from, to)`. */
|
|
18
|
+
insert: string;
|
|
19
|
+
}
|
|
20
|
+
interface LineInfo {
|
|
21
|
+
/** 1-based line number. */
|
|
22
|
+
number: number;
|
|
23
|
+
/** Offset of the first character of the line. */
|
|
24
|
+
from: number;
|
|
25
|
+
/** Offset just past the last character (before the newline). */
|
|
26
|
+
to: number;
|
|
27
|
+
/** The line's text (without the trailing newline). */
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
interface Position {
|
|
31
|
+
/** 1-based line. */
|
|
32
|
+
line: number;
|
|
33
|
+
/** 1-based column (UTF-16 units within the line). */
|
|
34
|
+
column: number;
|
|
35
|
+
}
|
|
36
|
+
declare class TextDoc {
|
|
37
|
+
readonly text: string;
|
|
38
|
+
private _lineStarts;
|
|
39
|
+
constructor(text?: string);
|
|
40
|
+
get length(): number;
|
|
41
|
+
/** Apply one change, returning a new document. */
|
|
42
|
+
apply(change: Change): TextDoc;
|
|
43
|
+
/**
|
|
44
|
+
* Apply several changes, returning a new document. Changes are given in
|
|
45
|
+
* document coordinates of THIS doc; they are applied right-to-left so earlier
|
|
46
|
+
* offsets stay valid.
|
|
47
|
+
*/
|
|
48
|
+
applyAll(changes: Change[]): TextDoc;
|
|
49
|
+
private lineStarts;
|
|
50
|
+
/** Total number of lines (a trailing newline yields an extra empty line). */
|
|
51
|
+
get lines(): number;
|
|
52
|
+
/** The line (1-based) containing `offset`. */
|
|
53
|
+
lineAt(offset: number): LineInfo;
|
|
54
|
+
/** Line/column (both 1-based) for an offset. */
|
|
55
|
+
positionAt(offset: number): Position;
|
|
56
|
+
/** Offset for a 1-based line/column. */
|
|
57
|
+
offsetAt(line: number, column: number): number;
|
|
58
|
+
/**
|
|
59
|
+
* Map an offset from this document's coordinates to the coordinates AFTER the
|
|
60
|
+
* given change(s). `assoc` controls which side of an insertion at the offset
|
|
61
|
+
* the mapped position sticks to: -1 = before (default), 1 = after.
|
|
62
|
+
*/
|
|
63
|
+
mapOffset(offset: number, changes: Change | Change[], assoc?: -1 | 1): number;
|
|
64
|
+
toString(): string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Typewright block + inline parser — a hand-written, zero-dependency GitHub
|
|
69
|
+
* Flavored Markdown (+ light MDX-flow) parser that produces the offset-exact
|
|
70
|
+
* AST in `./ast`. Every node carries `from`/`to` UTF-16 source offsets; markers
|
|
71
|
+
* (heading `### `, list bullets, emphasis delimiters) are exposed so a consumer
|
|
72
|
+
* can hide/reveal the raw syntax.
|
|
73
|
+
*
|
|
74
|
+
* Design notes:
|
|
75
|
+
* - Block parsing works line-by-line. Container blocks (blockquote, list) build
|
|
76
|
+
* a fresh line list whose `from` is advanced past the stripped prefix; because
|
|
77
|
+
* only `from` moves, `src.slice(from, to)` still equals the line's content, so
|
|
78
|
+
* offsets stay exact through arbitrary nesting.
|
|
79
|
+
* - Inline parsing stitches a block's content lines into one buffer with a
|
|
80
|
+
* per-character source-offset map, so emphasis/code spanning a soft line break
|
|
81
|
+
* still reports correct absolute offsets.
|
|
82
|
+
* - The parser never throws: unterminated emphasis / code / links / fences all
|
|
83
|
+
* degrade to text (or run to end-of-input) rather than failing.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Parse Markdown/MDX source into an offset-exact {@link Document}.
|
|
88
|
+
*
|
|
89
|
+
* `options` gates the opt-in extensions (math, footnotes, definition lists);
|
|
90
|
+
* every flag defaults to `false`, so `parse(src)` is unchanged from before.
|
|
91
|
+
*/
|
|
92
|
+
declare function parse(src: string, options?: ParseOptions): Document;
|
|
93
|
+
/**
|
|
94
|
+
* Incrementally reparse `prev` (the parse of `prevSrc`) after a single
|
|
95
|
+
* {@link Change} produced `nextSrc`. The result is deep-equal to
|
|
96
|
+
* `parse(nextSrc, options)`; pass the SAME `options` that produced `prev`.
|
|
97
|
+
*/
|
|
98
|
+
declare function parseIncremental(prev: Document, prevSrc: string, change: Change, nextSrc: string, options?: ParseOptions): Document;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* AST → sanitized HTML renderer.
|
|
102
|
+
*
|
|
103
|
+
* This is the `read`/`preview` output path (SPEC.md §4): it walks the offset-exact
|
|
104
|
+
* AST produced by the parser and emits HTML that is safe to inject into a host
|
|
105
|
+
* page. Safety is structural, not incidental:
|
|
106
|
+
*
|
|
107
|
+
* - every text / attribute value is HTML-escaped (`&`, `<`, `>`, `"`);
|
|
108
|
+
* - every URL passes {@link safeUrl}, so `javascript:` / `data:` / other active
|
|
109
|
+
* schemes collapse to `#`;
|
|
110
|
+
* - raw HTML / MDX blocks are emitted ESCAPED inside `<pre>` — this renderer
|
|
111
|
+
* never re-emits untrusted markup, so it can be used on model output;
|
|
112
|
+
* - footnote / definition ids are slugged to a URL-safe charset *and* escaped
|
|
113
|
+
* before they reach an `id`/`href` attribute.
|
|
114
|
+
*
|
|
115
|
+
* The renderer never throws: malformed / partial nodes degrade to escaped text.
|
|
116
|
+
*
|
|
117
|
+
* {@link RenderOptions} lets a host plug in escaped-HTML producers for the two
|
|
118
|
+
* constructs the core cannot render on its own — syntax highlighting and a math
|
|
119
|
+
* engine. Both are trusted to return already-escaped HTML; without them the
|
|
120
|
+
* renderer falls back to the safe escaped-source form. Passing no options
|
|
121
|
+
* reproduces the exact default behaviour.
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Optional, host-supplied output producers for constructs the core cannot
|
|
126
|
+
* render itself. Both hooks MUST return already-escaped, safe HTML — the
|
|
127
|
+
* renderer trusts their output and does not re-escape it. Omitting a hook (or
|
|
128
|
+
* the whole object) falls back to the safe escaped-source form.
|
|
129
|
+
*/
|
|
130
|
+
interface RenderOptions {
|
|
131
|
+
/**
|
|
132
|
+
* Syntax highlighter for fenced code. Receives the fence info string and the
|
|
133
|
+
* raw code; returns escaped HTML (e.g. `<span class="tw-tok-…">` runs). The
|
|
134
|
+
* host is responsible for escaping — see {@link highlightToHtml}.
|
|
135
|
+
*/
|
|
136
|
+
highlight?: (lang: string, code: string) => string;
|
|
137
|
+
/**
|
|
138
|
+
* Math engine. Receives the TeX source and whether it is display math;
|
|
139
|
+
* returns escaped/safe HTML. Without it, math renders as escaped source.
|
|
140
|
+
*/
|
|
141
|
+
math?: (src: string, display: boolean) => string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Return `url` when it is safe to place in an `href`/`src`, otherwise `'#'`.
|
|
145
|
+
*
|
|
146
|
+
* Safe = an http/https/mailto absolute URL, OR anything without an explicit
|
|
147
|
+
* scheme (relative paths, `?query`, `#anchor`, protocol-relative `//host`).
|
|
148
|
+
* Any other scheme (`javascript:`, `data:`, `vbscript:`, `file:`, …) is denied.
|
|
149
|
+
*
|
|
150
|
+
* Scheme detection is done against a copy with whitespace + control characters
|
|
151
|
+
* stripped, so obfuscations like `java\tscript:` or a leading newline can't
|
|
152
|
+
* smuggle an active scheme past the check.
|
|
153
|
+
*/
|
|
154
|
+
declare function safeUrl(url: string): string;
|
|
155
|
+
/** Render a run of inline nodes to sanitized HTML. */
|
|
156
|
+
declare function renderInline(nodes: Inline[], options?: RenderOptions): string;
|
|
157
|
+
/** Render a single block node to sanitized HTML. */
|
|
158
|
+
declare function renderNode(node: Block, options?: RenderOptions): string;
|
|
159
|
+
/** Render a whole document to sanitized HTML. */
|
|
160
|
+
declare function renderToHtml(doc: Document, options?: RenderOptions): string;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Unified (Obsidian-style live-preview) source-revealing logic.
|
|
164
|
+
*
|
|
165
|
+
* In `unified` mode the formatting renders inline, but the raw syntax markers
|
|
166
|
+
* (a heading's `### `, an emphasis `*`, a link's `](url)`, …) are hidden UNLESS
|
|
167
|
+
* the caret/selection is on top of them — then they reveal so you can edit the
|
|
168
|
+
* source. This module is pure and offset-exact: it maps the AST to the set of
|
|
169
|
+
* hideable marker ranges (`collectMarkers`) and decides which stay hidden for a
|
|
170
|
+
* given selection (`hiddenMarkers`). It never mutates the tree or the string.
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* A hideable syntax-marker range: `[from, to)` with a `kind` tag.
|
|
175
|
+
*
|
|
176
|
+
* `kind` is an open string (not a closed union) so new marker families can be
|
|
177
|
+
* added without a breaking type change. The kinds currently emitted are
|
|
178
|
+
* `heading`, `emphasis`, `strong`, `strike`, `code`, `link`, `image`,
|
|
179
|
+
* `listMarker`, `math`, `footnoteRef`, `fence` and `blockquote`.
|
|
180
|
+
*/
|
|
181
|
+
interface Marker extends Pos {
|
|
182
|
+
kind: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Every hideable syntax-marker range in the document, in document order.
|
|
186
|
+
*
|
|
187
|
+
* Covers: heading `#… ` prefixes, the two emphasis/strong/strike delimiter runs
|
|
188
|
+
* on each side, inline-code backtick fences, link `[`/`](`/url/`)` pieces, the
|
|
189
|
+
* image `!` (plus its bracket/paren pieces), list-item markers, inline-math `$`
|
|
190
|
+
* (or `$$`) delimiters, and footnote-reference `[^`/`]` brackets.
|
|
191
|
+
*
|
|
192
|
+
* When the original `source` string is supplied it additionally emits the
|
|
193
|
+
* `fence` (opening + closing fenced-code lines) and `blockquote` (the leading
|
|
194
|
+
* `>` run on each quoted line) markers — these need the raw text to be
|
|
195
|
+
* offset-exact, so they are omitted when `source` is not passed (keeping the
|
|
196
|
+
* source-free call identical to before). Always pure; never mutates.
|
|
197
|
+
*/
|
|
198
|
+
declare function collectMarkers(doc: Document, source?: string): Marker[];
|
|
199
|
+
/**
|
|
200
|
+
* The markers that stay HIDDEN for a given selection: those whose `[from, to)`
|
|
201
|
+
* does NOT intersect the selection widened by 1 on each side. Markers that DO
|
|
202
|
+
* intersect are revealed (returned excluded), so the caret can edit the raw
|
|
203
|
+
* syntax it sits on — the live-preview reveal rule.
|
|
204
|
+
*
|
|
205
|
+
* `source` is forwarded to {@link collectMarkers} so the fence/blockquote
|
|
206
|
+
* markers participate in the reveal too; omit it to keep the source-free set.
|
|
207
|
+
* The selection filter itself is unchanged.
|
|
208
|
+
*/
|
|
209
|
+
declare function hiddenMarkers(doc: Document, sel: {
|
|
210
|
+
from: number;
|
|
211
|
+
to: number;
|
|
212
|
+
}, source?: string): Marker[];
|
|
213
|
+
/**
|
|
214
|
+
* Index into `doc.children` of the top-level block whose inclusive `[from, to]`
|
|
215
|
+
* range contains `offset`, or -1 when the offset falls in a gap between blocks.
|
|
216
|
+
*/
|
|
217
|
+
declare function activeBlockIndex(doc: Document, offset: number): number;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Heading-based folding.
|
|
221
|
+
*
|
|
222
|
+
* A heading folds away everything from the end of its line down to (but not
|
|
223
|
+
* including) the next heading of the same or higher level — the standard
|
|
224
|
+
* "collapse a section" affordance. Pure and offset-exact.
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
/** A foldable region owned by a heading. `[from, to)` is the collapsible body. */
|
|
228
|
+
interface FoldRange {
|
|
229
|
+
/** Offset where the owning heading starts (its `#`). */
|
|
230
|
+
headingFrom: number;
|
|
231
|
+
/** The heading's level (1–6). */
|
|
232
|
+
level: number;
|
|
233
|
+
/** Start of the collapsible body — the end of the heading line. */
|
|
234
|
+
from: number;
|
|
235
|
+
/** End of the collapsible body — the next same-or-higher heading, or doc end. */
|
|
236
|
+
to: number;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* One `FoldRange` per top-level heading: `from` is the heading node's `to` (end
|
|
240
|
+
* of the heading line), `to` is the `from` of the next heading whose level is
|
|
241
|
+
* `<=` this heading's level (or the document's `to` if there is none). Ranges
|
|
242
|
+
* with an empty body (`to <= from`) are omitted.
|
|
243
|
+
*/
|
|
244
|
+
declare function headingFoldRanges(doc: Document): FoldRange[];
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Native, zero-dependency syntax highlighter.
|
|
248
|
+
*
|
|
249
|
+
* {@link highlightToHtml} turns a fenced code block's source into an HTML
|
|
250
|
+
* string with tokens wrapped in `<span class="tw-tok-KIND">…</span>`. The
|
|
251
|
+
* tokenizers are small, hand-written, single-pass line/char scanners — NOT
|
|
252
|
+
* full grammars. They recognise the shapes that carry the most colour signal:
|
|
253
|
+
* keywords, strings (including template literals), line + block comments,
|
|
254
|
+
* numbers, punctuation, and a light dusting of function / type / property
|
|
255
|
+
* classification.
|
|
256
|
+
*
|
|
257
|
+
* Safety is the load-bearing invariant: **every** character that reaches the
|
|
258
|
+
* output — token content and the gaps between tokens alike — is HTML-escaped
|
|
259
|
+
* through the local {@link escapeHtml}. A `<script>` (or `<img onerror=…>`)
|
|
260
|
+
* embedded in the code therefore always appears inert/escaped, never as live
|
|
261
|
+
* markup. This mirrors the sanitizing contract of `render.ts` so the
|
|
262
|
+
* highlighter can be handed straight to the renderer without widening the
|
|
263
|
+
* attack surface.
|
|
264
|
+
*
|
|
265
|
+
* Complexity is O(n) in the source length. There are no unbounded-backtracking
|
|
266
|
+
* regexes; scanning advances the cursor monotonically, so pathological input
|
|
267
|
+
* (huge whitespace runs, unterminated strings/comments) is safe.
|
|
268
|
+
*/
|
|
269
|
+
/**
|
|
270
|
+
* Highlight `code` for the given fence `info` string.
|
|
271
|
+
*
|
|
272
|
+
* `info` is the WHOLE fence info (e.g. `"js {1,3}"` or `"ts title=foo"`); the
|
|
273
|
+
* language is the first whitespace-delimited token, lowercased, run through
|
|
274
|
+
* {@link ALIASES}. Unknown / empty / unsupported languages return the escaped
|
|
275
|
+
* source with no spans, so the output is always safe to inject.
|
|
276
|
+
*
|
|
277
|
+
* @param lang the fence info string (language + any attributes)
|
|
278
|
+
* @param code the raw code block source
|
|
279
|
+
* @returns HTML with `<span class="tw-tok-KIND">` tokens; fully HTML-escaped.
|
|
280
|
+
*/
|
|
281
|
+
declare function highlightToHtml(lang: string, code: string): string;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Comment-anchor maintenance (plan-TW-0002 Phase A2).
|
|
285
|
+
*
|
|
286
|
+
* A comment thread is anchored to a text range `{from, to}`. Every time the
|
|
287
|
+
* document is edited we must move that range so the highlight keeps covering
|
|
288
|
+
* the same words — or drop the anchor (return `null`) when the words it pointed
|
|
289
|
+
* at have been deleted. This is the first real consumer of `TextDoc.mapOffset`
|
|
290
|
+
* (previously dead code) — it is built directly on top of that primitive rather
|
|
291
|
+
* than re-deriving the position math here.
|
|
292
|
+
*/
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Re-anchor a comment range across a single document `change`.
|
|
296
|
+
*
|
|
297
|
+
* @returns the mapped `{from, to}` (always `from <= to`), or `null` when the
|
|
298
|
+
* change deleted the entire anchored range.
|
|
299
|
+
*/
|
|
300
|
+
declare function mapAnchor(anchor: {
|
|
301
|
+
from: number;
|
|
302
|
+
to: number;
|
|
303
|
+
}, change: Change): {
|
|
304
|
+
from: number;
|
|
305
|
+
to: number;
|
|
306
|
+
} | null;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Pure table-editing helpers (Phase F1 of plan-TW-0002).
|
|
310
|
+
*
|
|
311
|
+
* These are the headless layer under the in-place table grid: no DOM, no React,
|
|
312
|
+
* just string → string transforms over the offset-exact {@link Table} AST that
|
|
313
|
+
* `./parser` produces. Every mutation keeps the Markdown *canonical* — a GFM
|
|
314
|
+
* pipe table with a delimiter row — so `parse → mutate → parse` round-trips to
|
|
315
|
+
* the same structure.
|
|
316
|
+
*
|
|
317
|
+
* Two edit shapes, matching the plan:
|
|
318
|
+
* - **Single-cell** edits are scoped: {@link cellSourceRange} hands back a
|
|
319
|
+
* cell's *exact* source range so the caller can splice only that slice.
|
|
320
|
+
* - **Structural** ops (add/remove row/column, set alignment) re-serialize the
|
|
321
|
+
* whole table block and return a full-block splice over `[table.from, table.to]`.
|
|
322
|
+
*
|
|
323
|
+
* Addressing convention (documented once, used everywhere):
|
|
324
|
+
* - Rows use a **grid index**: row `0` is the header, rows `1..N` are body rows
|
|
325
|
+
* (this mirrors the rendered grid, where the header is the top row).
|
|
326
|
+
* - Columns are 0-based.
|
|
327
|
+
*
|
|
328
|
+
* The AST contract these helpers lean on (see `src/core/ast.ts:144-156`):
|
|
329
|
+
* - `TableCell extends Pos` — every cell carries exact `{from,to}` UTF-16
|
|
330
|
+
* offsets of its *trimmed* content (`splitRow`, `parser.ts:447-459`).
|
|
331
|
+
* - `Table { from; to; align: CellAlign[]; header: TableCell[]; rows: TableCell[][] }`.
|
|
332
|
+
* The delimiter row has no node of its own, so alignment edits (like every
|
|
333
|
+
* structural op) re-serialize the block rather than splicing that row in place.
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
/** Result of a structural (whole-block) table edit. */
|
|
337
|
+
interface TableEdit {
|
|
338
|
+
/** The full new document text after the splice. */
|
|
339
|
+
text: string;
|
|
340
|
+
/** A sensible caret offset into {@link text} after the edit. */
|
|
341
|
+
selection: number;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Exact source range of a single cell's (trimmed) text, for scoped single-cell
|
|
345
|
+
* splices. Row `0` is the header; rows `1..N` are body rows. Returns `null` when
|
|
346
|
+
* the coordinate is out of bounds.
|
|
347
|
+
*/
|
|
348
|
+
declare function cellSourceRange(table: Table, row: number, col: number): Pos | null;
|
|
349
|
+
/**
|
|
350
|
+
* Insert a new empty body row so it lands at grid position `atRow`
|
|
351
|
+
* (clamped into the body range). Re-serializes the whole block.
|
|
352
|
+
*/
|
|
353
|
+
declare function addRow(text: string, table: Table, atRow: number): TableEdit;
|
|
354
|
+
/**
|
|
355
|
+
* Insert a new empty column at index `atCol` (clamped), widening the header,
|
|
356
|
+
* the alignment row, and every body row. Re-serializes the whole block.
|
|
357
|
+
*/
|
|
358
|
+
declare function addColumn(text: string, table: Table, atCol: number): TableEdit;
|
|
359
|
+
/**
|
|
360
|
+
* Remove the body row at grid position `atRow` (row `0`, the header, and
|
|
361
|
+
* out-of-range indices are no-ops). Re-serializes the whole block.
|
|
362
|
+
*/
|
|
363
|
+
declare function removeRow(text: string, table: Table, atRow: number): TableEdit;
|
|
364
|
+
/**
|
|
365
|
+
* Remove the column at index `atCol` from the header, alignment row, and every
|
|
366
|
+
* body row. The last remaining column is never removed (a GFM table needs ≥1
|
|
367
|
+
* column), and out-of-range indices are no-ops. Re-serializes the whole block.
|
|
368
|
+
*/
|
|
369
|
+
declare function removeColumn(text: string, table: Table, atCol: number): TableEdit;
|
|
370
|
+
/**
|
|
371
|
+
* Set column `col`'s alignment and rewrite the delimiter row (via a canonical
|
|
372
|
+
* re-serialization of the whole block). Out-of-range `col` is a no-op.
|
|
373
|
+
*/
|
|
374
|
+
declare function setAlignment(text: string, table: Table, col: number, align: CellAlign): TableEdit;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* `typewright/core` — the headless, framework-agnostic engine.
|
|
378
|
+
*
|
|
379
|
+
* Status: PRE-ALPHA SCAFFOLD. The from-scratch document model, incremental
|
|
380
|
+
* block-structured parser, and virtualized DOM view described in SPEC.md are
|
|
381
|
+
* not yet implemented. This module defines the public surface those internals
|
|
382
|
+
* will fulfil so integrators can build against a stable contract.
|
|
383
|
+
*/
|
|
384
|
+
|
|
385
|
+
interface EditorViewOptions extends EditorConfig, EditorEvents {
|
|
386
|
+
/** Element the editor mounts into. */
|
|
387
|
+
parent: HTMLElement;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* PRE-ALPHA SCAFFOLD — not yet implemented. Constructing an `EditorView`
|
|
391
|
+
* throws: the stateful mounted engine (document string, incremental parse tree,
|
|
392
|
+
* decoration set, virtualized viewport) described in SPEC.md is still to come.
|
|
393
|
+
* This class only reserves the eventual public surface.
|
|
394
|
+
*
|
|
395
|
+
* To edit or render Markdown today, use the functional headless API exported
|
|
396
|
+
* from this module — {@link parse}, {@link parseIncremental}, {@link renderToHtml} —
|
|
397
|
+
* or the React `TypewrightEditor` component in `typewright`.
|
|
398
|
+
*/
|
|
399
|
+
declare class EditorView {
|
|
400
|
+
readonly dom: HTMLElement;
|
|
401
|
+
constructor(options: EditorViewOptions);
|
|
402
|
+
/** Current document string. */
|
|
403
|
+
get doc(): string;
|
|
404
|
+
/** Apply an edit. */
|
|
405
|
+
dispatch(_change: DocChange): void;
|
|
406
|
+
setSelection(_selection: DocSelection): void;
|
|
407
|
+
destroy(): void;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export { Block, CellAlign, type Change, DocChange, DocSelection, Document, EditorConfig, EditorEvents, EditorView, type EditorViewOptions, type FoldRange, Inline, type LineInfo, type Marker, ParseOptions, Pos, type Position, type RenderOptions, Table, type TableEdit, TextDoc, activeBlockIndex, addColumn, addRow, cellSourceRange, collectMarkers, headingFoldRanges, hiddenMarkers, highlightToHtml, mapAnchor, parse, parseIncremental, removeColumn, removeRow, renderInline, renderNode, renderToHtml, safeUrl, setAlignment };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { COMMANDS, EditorView, TextDoc, activeBlockIndex, addColumn, addRow, applyCommand, cellSourceRange, collectMarkers, headingFoldRanges, hiddenMarkers, highlightToHtml, mapAnchor, removeColumn, removeRow, setAlignment } from '../chunk-CZQO7TTL.js';
|
|
2
|
+
export { childrenOf, isInline, parse, parseIncremental, renderInline, renderNode, renderToHtml, safeUrl, walk } from '../chunk-M6IVEMXO.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|