@tooee/renderers 0.1.22 → 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/dist/CodeView.d.ts +11 -11
- package/dist/CodeView.d.ts.map +1 -1
- package/dist/CodeView.js +2 -20
- package/dist/CodeView.js.map +1 -1
- package/dist/DocumentBindings.d.ts +16 -0
- package/dist/DocumentBindings.d.ts.map +1 -0
- package/dist/DocumentBindings.js +2 -0
- package/dist/DocumentBindings.js.map +1 -0
- package/dist/MarkdownView.d.ts +23 -28
- package/dist/MarkdownView.d.ts.map +1 -1
- package/dist/MarkdownView.js +4 -110
- package/dist/MarkdownView.js.map +1 -1
- package/dist/RowDocumentRenderable.d.ts +2 -0
- package/dist/RowDocumentRenderable.d.ts.map +1 -1
- package/dist/RowDocumentRenderable.js +11 -0
- package/dist/RowDocumentRenderable.js.map +1 -1
- package/dist/Table.d.ts +9 -10
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +3 -20
- package/dist/Table.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown-blocks.d.ts +41 -0
- package/dist/markdown-blocks.d.ts.map +1 -0
- package/dist/markdown-blocks.js +246 -0
- package/dist/markdown-blocks.js.map +1 -0
- package/dist/source.d.ts +83 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +114 -0
- package/dist/source.js.map +1 -0
- package/package.json +15 -9
- package/src/CodeView.tsx +15 -41
- package/src/DocumentBindings.ts +16 -0
- package/src/MarkdownView.tsx +33 -150
- package/src/RowDocumentRenderable.ts +10 -0
- package/src/Table.tsx +13 -33
- package/src/index.ts +12 -2
- package/src/markdown-blocks.ts +296 -0
- package/src/source.ts +177 -0
package/dist/Table.js
CHANGED
|
@@ -89,12 +89,12 @@ function formatCellValue(value) {
|
|
|
89
89
|
return String(value);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
export function Table({ columns, rows, maxWidth, minColumnWidth = DEFAULT_MIN_COL_WIDTH, maxColumnWidth = DEFAULT_MAX_COL_WIDTH, sampleSize = DEFAULT_SAMPLE_SIZE, showLineNumbers = true,
|
|
92
|
+
export function Table({ columns, rows, maxWidth, minColumnWidth = DEFAULT_MIN_COL_WIDTH, maxColumnWidth = DEFAULT_MAX_COL_WIDTH, sampleSize = DEFAULT_SAMPLE_SIZE, showLineNumbers = true, document, columnWidthMode = "content", }) {
|
|
93
93
|
const { theme } = useTheme();
|
|
94
94
|
const palette = useGutterPalette();
|
|
95
95
|
const { width: terminalWidth } = useTerminalDimensions();
|
|
96
96
|
const internalDocRef = useRef(null);
|
|
97
|
-
const rowDocumentRef =
|
|
97
|
+
const rowDocumentRef = document?.ref ?? internalDocRef;
|
|
98
98
|
// Compute available content width: start with total space, subtract margins and gutter
|
|
99
99
|
const gutterWidth = useMemo(() => computeRowDocumentGutterWidth({
|
|
100
100
|
showLineNumbers,
|
|
@@ -140,30 +140,13 @@ export function Table({ columns, rows, maxWidth, minColumnWidth = DEFAULT_MIN_CO
|
|
|
140
140
|
paddingRight: PADDING,
|
|
141
141
|
}, fg: theme.text }, j));
|
|
142
142
|
}) }, i))), [normalizedRows, colWidths, alignments, theme.text]);
|
|
143
|
-
// Use the shared RowDocumentRenderable screen-Y mapper for table rows too.
|
|
144
|
-
// This keeps table, code, and markdown mouse handling on one code path and
|
|
145
|
-
// avoids per-row mouse closures in the virtualized row tree.
|
|
146
|
-
const handleMouseDown = onRowClick || onRowContextMenu
|
|
147
|
-
? (event) => {
|
|
148
|
-
const row = rowDocumentRef.current?.getRowAtScreenY(event.y);
|
|
149
|
-
if (row == null)
|
|
150
|
-
return;
|
|
151
|
-
if (event.button === 0) {
|
|
152
|
-
onRowClick?.(row);
|
|
153
|
-
}
|
|
154
|
-
else if (event.button === 2) {
|
|
155
|
-
event.preventDefault();
|
|
156
|
-
onRowContextMenu?.(row, event.x, event.y);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
: undefined;
|
|
160
143
|
return (_jsxs("box", { style: {
|
|
161
144
|
flexDirection: "column",
|
|
162
145
|
flexGrow: 1,
|
|
163
146
|
marginLeft: MARGIN,
|
|
164
147
|
marginRight: MARGIN,
|
|
165
148
|
marginBottom: MARGIN,
|
|
166
|
-
}, children: [_jsx("box", { style: { flexDirection: "row", flexShrink: 0, paddingLeft: gutterWidth }, children: headers.map((h, i) => (_jsx("text", { content: h, style: { width: colWidths[i], paddingLeft: PADDING, paddingRight: PADDING }, fg: theme.primary }, i))) }), _jsx("box", { style: { flexDirection: "row", flexShrink: 0, paddingLeft: gutterWidth }, children: colWidths.map((w, i) => (_jsx("text", { content: "\u2500".repeat(w - PADDING * 2), style: { width: w, paddingLeft: PADDING, paddingRight: PADDING }, fg: theme.border }, i))) }), _jsx("row-document", { ref: rowDocumentRef, mode: "multi", rowChildOffset: 0, showGutter: true, showLineNumbers: showLineNumbers, signColumnWidth: DEFAULT_SIGN_COLUMN_WIDTH, palette: palette, decorations:
|
|
149
|
+
}, children: [_jsx("box", { style: { flexDirection: "row", flexShrink: 0, paddingLeft: gutterWidth }, children: headers.map((h, i) => (_jsx("text", { content: h, style: { width: colWidths[i], paddingLeft: PADDING, paddingRight: PADDING }, fg: theme.primary }, i))) }), _jsx("box", { style: { flexDirection: "row", flexShrink: 0, paddingLeft: gutterWidth }, children: colWidths.map((w, i) => (_jsx("text", { content: "\u2500".repeat(w - PADDING * 2), style: { width: w, paddingLeft: PADDING, paddingRight: PADDING }, fg: theme.border }, i))) }), _jsx("row-document", { ref: rowDocumentRef, mode: "multi", rowChildOffset: 0, showGutter: true, showLineNumbers: showLineNumbers, signColumnWidth: DEFAULT_SIGN_COLUMN_WIDTH, palette: palette, decorations: document?.decorations, style: { flexGrow: 1 }, onMouseDown: document?.onMouseDown, children: rowElements })] }));
|
|
167
150
|
}
|
|
168
151
|
// Exported for testing and MarkdownView
|
|
169
152
|
export { computeColumnWidths, isNumeric, sampleRows };
|
package/dist/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../src/Table.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../src/Table.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAGvC,OAAO,EACL,yBAAyB,EACzB,6BAA6B,GAE9B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,mBAAmB,CAAA;AA0B1B,MAAM,OAAO,GAAG,CAAC,CAAA;AACjB,MAAM,MAAM,GAAG,CAAC,CAAA,CAAC,8CAA8C;AAC/D,MAAM,qBAAqB,GAAG,CAAC,CAAA;AAC/B,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAChC,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAE/B,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC7C,CAAC;AASD,SAAS,UAAU,CAAC,IAAgB,EAAE,UAAkB;IACtD,IAAI,IAAI,CAAC,MAAM,IAAI,UAAU;QAAE,OAAO,IAAI,CAAA;IAC1C,2DAA2D;IAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,UAAU,CAAA;IACrC,MAAM,OAAO,GAAe,EAAE,CAAA;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,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AAE,SAAS,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export { MarkdownView
|
|
2
|
-
export
|
|
1
|
+
export { MarkdownView } from "./MarkdownView.js";
|
|
2
|
+
export { flattenMarkdown, flattenTokens, getFlatBlockText } from "./markdown-blocks.js";
|
|
3
|
+
export type { FlatBlock, FlattenMarkdownOptions } from "./markdown-blocks.js";
|
|
4
|
+
export { sourceLines, sourceLineAdapter } from "./source.js";
|
|
5
|
+
export type { DocumentRowAnchor, DocumentRowSource, SourceLineRow, SourcePoint, SourceSpan, } from "./source.js";
|
|
3
6
|
export { CodeBlockChrome, defaultCodeBlockRenderer, mermaidCodeBlockRenderer, DEFAULT_CODE_BLOCK_RENDERERS, getFenceType, } from "./code-blocks.js";
|
|
4
7
|
export type { CodeBlockRenderer, CodeBlockRendererProps, CodeBlockHScroll } from "./code-blocks.js";
|
|
5
8
|
export { CodeView } from "./CodeView.js";
|
|
@@ -16,5 +19,6 @@ export { RowDocumentRenderable } from "./RowDocumentRenderable.js";
|
|
|
16
19
|
export { DEFAULT_SIGN_COLUMN_WIDTH, computeRowDocumentGutterWidth, } from "./RowDocumentRenderable.js";
|
|
17
20
|
export type { RowDocumentOptions, RowDocumentPalette } from "./RowDocumentRenderable.js";
|
|
18
21
|
export type { DecorationLayer, RowDecoration } from "./DecorationLayer.js";
|
|
22
|
+
export type { DocumentBindings } from "./DocumentBindings.js";
|
|
19
23
|
export { useGutterPalette } from "./useGutterPalette.js";
|
|
20
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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AAO,EACL,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,4BAA4B,CAAA;AACnC,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACxF,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAC1E,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { MarkdownView
|
|
1
|
+
export { MarkdownView } from "./MarkdownView.js";
|
|
2
|
+
export { flattenMarkdown, flattenTokens, getFlatBlockText } from "./markdown-blocks.js";
|
|
3
|
+
export { sourceLines, sourceLineAdapter } from "./source.js";
|
|
2
4
|
export { CodeBlockChrome, defaultCodeBlockRenderer, mermaidCodeBlockRenderer, DEFAULT_CODE_BLOCK_RENDERERS, getFenceType, } from "./code-blocks.js";
|
|
3
5
|
export { CodeView } from "./CodeView.js";
|
|
4
6
|
export { Table, computeColumnWidths, isNumeric, sampleRows } from "./Table.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAQ5D,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,YAAY,GACb,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG9E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAErF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EACL,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,4BAA4B,CAAA;AAInC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Token } from "marked";
|
|
2
|
+
import { type DocumentRowSource } from "./source.js";
|
|
3
|
+
/**
|
|
4
|
+
* A flattened block — all blocks exist at the top level with an indent.
|
|
5
|
+
* Nested structures (lists containing code blocks, etc.) are flattened into
|
|
6
|
+
* sibling blocks with appropriate indentation.
|
|
7
|
+
*/
|
|
8
|
+
export interface FlatBlock {
|
|
9
|
+
token: Token;
|
|
10
|
+
indent: number;
|
|
11
|
+
bullet?: string;
|
|
12
|
+
checked?: boolean;
|
|
13
|
+
/** Provenance in the Markdown input; `null` only if resolution genuinely failed. */
|
|
14
|
+
source: DocumentRowSource | null;
|
|
15
|
+
}
|
|
16
|
+
export interface FlattenMarkdownOptions {
|
|
17
|
+
sourceId?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The visible/searchable text for a block. Non-synthetic blocks use the token's
|
|
21
|
+
* `raw`; synthetic bullet rows (empty raw) fall back to the visible
|
|
22
|
+
* bullet/checkbox text, then to the resolved source text. This keeps default
|
|
23
|
+
* search and copy in agreement with the source mapping on synthetic rows.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getFlatBlockText(block: FlatBlock): string;
|
|
26
|
+
/**
|
|
27
|
+
* Lex, flatten, and source-map Markdown in one operation. Every returned block
|
|
28
|
+
* carries a `source` anchor (or `null` when a marked edge case leaves a token
|
|
29
|
+
* genuinely unresolvable), in the exact order used for navigation/rendering.
|
|
30
|
+
*/
|
|
31
|
+
export declare function flattenMarkdown(markdown: string, options?: FlattenMarkdownOptions): FlatBlock[];
|
|
32
|
+
/**
|
|
33
|
+
* The unmapped low-level form: flatten already-lexed tokens with no source
|
|
34
|
+
* provenance (every block's `source` is `null`).
|
|
35
|
+
*
|
|
36
|
+
* @deprecated Prefer `flattenMarkdown(source)` for source-backed rows. Tokens
|
|
37
|
+
* carry no positions and the original source is unavailable here, so offsets
|
|
38
|
+
* cannot be reconstructed.
|
|
39
|
+
*/
|
|
40
|
+
export declare function flattenTokens(tokens: Token[]): FlatBlock[];
|
|
41
|
+
//# sourceMappingURL=markdown-blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-blocks.d.ts","sourceRoot":"","sources":["../src/markdown-blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAe,MAAM,QAAQ,CAAA;AACxD,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAMjE;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,KAAK,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB,oFAAoF;IACpF,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAA;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAOD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAQzD;AAkOD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,SAAS,EAAE,CAK/F;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,CAI1D"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { marked } from "marked";
|
|
2
|
+
import { SourceIndex } from "./source.js";
|
|
3
|
+
/** Empty synthetic token stamped onto bullet-only rows (nested-list/block/empty items). */
|
|
4
|
+
function syntheticTextToken() {
|
|
5
|
+
return { type: "text", raw: "", text: "", tokens: [] };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The visible/searchable text for a block. Non-synthetic blocks use the token's
|
|
9
|
+
* `raw`; synthetic bullet rows (empty raw) fall back to the visible
|
|
10
|
+
* bullet/checkbox text, then to the resolved source text. This keeps default
|
|
11
|
+
* search and copy in agreement with the source mapping on synthetic rows.
|
|
12
|
+
*/
|
|
13
|
+
export function getFlatBlockText(block) {
|
|
14
|
+
const raw = "raw" in block.token && typeof block.token.raw === "string" ? block.token.raw : "";
|
|
15
|
+
if (raw.length > 0)
|
|
16
|
+
return raw;
|
|
17
|
+
if (block.bullet !== undefined) {
|
|
18
|
+
const checkbox = block.checked !== undefined ? (block.checked ? "[x] " : "[ ] ") : "";
|
|
19
|
+
return block.bullet + checkbox;
|
|
20
|
+
}
|
|
21
|
+
return block.source?.primary.text ?? "";
|
|
22
|
+
}
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Markdown provenance resolver
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
/**
|
|
27
|
+
* Deterministic sequential source resolution. Marked exposes `raw` strings but
|
|
28
|
+
* no positions, so we locate each token's exact slice at or after a monotonic
|
|
29
|
+
* cursor, constrained to its parent list-item span. Advancing the cursor past
|
|
30
|
+
* every match is what makes repeated identical blocks resolve to distinct
|
|
31
|
+
* occurrences instead of backtracking to an earlier one.
|
|
32
|
+
*/
|
|
33
|
+
class MarkdownResolver {
|
|
34
|
+
markdown;
|
|
35
|
+
index;
|
|
36
|
+
cursor = 0;
|
|
37
|
+
constructor(markdown, sourceId) {
|
|
38
|
+
this.markdown = markdown;
|
|
39
|
+
this.index = new SourceIndex(markdown, sourceId);
|
|
40
|
+
}
|
|
41
|
+
/** Resolve `raw` at/after the cursor within `[cursor, bound]`, then advance. */
|
|
42
|
+
resolveRaw(raw, bound) {
|
|
43
|
+
const match = this.find(raw, bound);
|
|
44
|
+
if (!match)
|
|
45
|
+
return null;
|
|
46
|
+
this.cursor = match.end;
|
|
47
|
+
return { primary: this.index.span(match.start, match.end) };
|
|
48
|
+
}
|
|
49
|
+
/** Find `raw`'s offset range without advancing the cursor. */
|
|
50
|
+
locate(raw, bound) {
|
|
51
|
+
return this.find(raw, bound);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Locate `raw` at or after the cursor within `[cursor, bound]`. marked
|
|
55
|
+
* normalizes `\r\n` to `\n` inside multi-line token `raw`, so the exact slice
|
|
56
|
+
* can be absent from a CRLF source. When the exact scan fails we retry a
|
|
57
|
+
* newline-tolerant match (a needle `\n` matches a source `\r\n` or `\n`) so
|
|
58
|
+
* offsets keep addressing the original `\r\n` string without normalizing it.
|
|
59
|
+
*/
|
|
60
|
+
find(raw, bound) {
|
|
61
|
+
if (raw.length === 0)
|
|
62
|
+
return null;
|
|
63
|
+
const md = this.markdown;
|
|
64
|
+
const exact = md.indexOf(raw, this.cursor);
|
|
65
|
+
if (exact !== -1 && exact + raw.length <= bound)
|
|
66
|
+
return { start: exact, end: exact + raw.length };
|
|
67
|
+
if (!raw.includes("\n"))
|
|
68
|
+
return null;
|
|
69
|
+
const firstSegment = raw.slice(0, raw.indexOf("\n"));
|
|
70
|
+
if (firstSegment.length === 0)
|
|
71
|
+
return null;
|
|
72
|
+
let from = this.cursor;
|
|
73
|
+
for (;;) {
|
|
74
|
+
const start = md.indexOf(firstSegment, from);
|
|
75
|
+
if (start === -1 || start >= bound)
|
|
76
|
+
return null;
|
|
77
|
+
const end = this.matchFlexibleNewlines(raw, start, bound);
|
|
78
|
+
if (end !== -1)
|
|
79
|
+
return { start, end };
|
|
80
|
+
from = start + 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Match `raw` from `start`, letting a needle `\n` consume a source `\r\n`. */
|
|
84
|
+
matchFlexibleNewlines(raw, start, bound) {
|
|
85
|
+
const md = this.markdown;
|
|
86
|
+
const length = md.length;
|
|
87
|
+
let h = start;
|
|
88
|
+
let n = 0;
|
|
89
|
+
while (n < raw.length) {
|
|
90
|
+
const code = raw.charCodeAt(n);
|
|
91
|
+
if (code === 10 /* \n */) {
|
|
92
|
+
if (h + 1 < length && md.charCodeAt(h) === 13 && md.charCodeAt(h + 1) === 10) {
|
|
93
|
+
h += 2;
|
|
94
|
+
}
|
|
95
|
+
else if (h < length && md.charCodeAt(h) === 10) {
|
|
96
|
+
h += 1;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return -1;
|
|
100
|
+
}
|
|
101
|
+
n += 1;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (h < length && md.charCodeAt(h) === code) {
|
|
105
|
+
h += 1;
|
|
106
|
+
n += 1;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return -1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return h <= bound ? h : -1;
|
|
114
|
+
}
|
|
115
|
+
/** Zero-consumption marker span for a synthetic bullet on the item's first line. */
|
|
116
|
+
markerSource(itemStart, itemEnd) {
|
|
117
|
+
const nl = this.markdown.indexOf("\n", itemStart);
|
|
118
|
+
const lineEnd = nl === -1 ? itemEnd : Math.min(nl, itemEnd);
|
|
119
|
+
const firstLine = this.markdown.slice(itemStart, lineEnd);
|
|
120
|
+
const match = firstLine.match(/^(\s*)(?:[-*+]|\d+[.)])[ \t]*(?:\[[ xX]\])?/);
|
|
121
|
+
if (!match)
|
|
122
|
+
return { primary: this.index.span(itemStart, itemStart, false) };
|
|
123
|
+
const markerStart = itemStart + match[1].length;
|
|
124
|
+
let spanEnd = itemStart + match[0].length;
|
|
125
|
+
while (spanEnd > markerStart) {
|
|
126
|
+
const code = this.markdown.charCodeAt(spanEnd - 1);
|
|
127
|
+
if (code !== 32 && code !== 9)
|
|
128
|
+
break; // space / tab
|
|
129
|
+
spanEnd--;
|
|
130
|
+
}
|
|
131
|
+
return { primary: this.index.span(markerStart, spanEnd, false) };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Flattening (shared by mapped and unmapped forms)
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
function bulletFor(list, itemIndex) {
|
|
138
|
+
return list.ordered ? `${itemIndex + (list.start || 1)}. ` : "- ";
|
|
139
|
+
}
|
|
140
|
+
function flattenList(list, indent, out, res, bound) {
|
|
141
|
+
for (let i = 0; i < list.items.length; i++) {
|
|
142
|
+
const item = list.items[i];
|
|
143
|
+
const bullet = bulletFor(list, i);
|
|
144
|
+
let itemStart = null;
|
|
145
|
+
let itemEnd = bound;
|
|
146
|
+
if (res) {
|
|
147
|
+
const loc = res.locate(item.raw, bound);
|
|
148
|
+
if (loc) {
|
|
149
|
+
itemStart = loc.start;
|
|
150
|
+
itemEnd = loc.end;
|
|
151
|
+
res.cursor = loc.start;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
flattenListItem(item, indent, bullet, out, res, itemStart, itemEnd);
|
|
155
|
+
if (res && itemStart !== null)
|
|
156
|
+
res.cursor = itemEnd;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function flattenListItem(item, indent, bullet, out, res, itemStart, itemEnd) {
|
|
160
|
+
const checked = item.checked != null ? item.checked : undefined;
|
|
161
|
+
const childTokens = item.tokens || [];
|
|
162
|
+
let bulletUsed = false;
|
|
163
|
+
const emitBulletMarker = () => {
|
|
164
|
+
out.push({
|
|
165
|
+
token: syntheticTextToken(),
|
|
166
|
+
indent,
|
|
167
|
+
bullet,
|
|
168
|
+
checked,
|
|
169
|
+
source: res && itemStart !== null ? res.markerSource(itemStart, itemEnd) : null,
|
|
170
|
+
});
|
|
171
|
+
bulletUsed = true;
|
|
172
|
+
};
|
|
173
|
+
for (const token of childTokens) {
|
|
174
|
+
if (token.type === "space" || token.type === "checkbox")
|
|
175
|
+
continue;
|
|
176
|
+
if (token.type === "text" || token.type === "paragraph") {
|
|
177
|
+
// Inline content — attach the bullet to the first one.
|
|
178
|
+
out.push({
|
|
179
|
+
token,
|
|
180
|
+
indent,
|
|
181
|
+
bullet: bulletUsed ? undefined : bullet,
|
|
182
|
+
checked: bulletUsed ? undefined : checked,
|
|
183
|
+
source: res ? res.resolveRaw(token.raw ?? "", itemEnd) : null,
|
|
184
|
+
});
|
|
185
|
+
bulletUsed = true;
|
|
186
|
+
}
|
|
187
|
+
else if (token.type === "list") {
|
|
188
|
+
if (!bulletUsed)
|
|
189
|
+
emitBulletMarker();
|
|
190
|
+
flattenList(token, indent + bullet.length, out, res, itemEnd);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Block content (code, table, blockquote, hr, etc.).
|
|
194
|
+
if (!bulletUsed)
|
|
195
|
+
emitBulletMarker();
|
|
196
|
+
out.push({
|
|
197
|
+
token,
|
|
198
|
+
indent: indent + bullet.length,
|
|
199
|
+
source: res ? res.resolveRaw(token.raw ?? "", itemEnd) : null,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// List item had no content tokens — still emit the bullet.
|
|
204
|
+
if (!bulletUsed)
|
|
205
|
+
emitBulletMarker();
|
|
206
|
+
}
|
|
207
|
+
function flattenWalk(tokens, indent, out, res, bound) {
|
|
208
|
+
for (const token of tokens) {
|
|
209
|
+
if (token.type === "space")
|
|
210
|
+
continue;
|
|
211
|
+
if (token.type === "list") {
|
|
212
|
+
flattenList(token, indent, out, res, bound);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
out.push({ token, indent, source: res ? res.resolveRaw(token.raw ?? "", bound) : null });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// ---------------------------------------------------------------------------
|
|
220
|
+
// Public entry points
|
|
221
|
+
// ---------------------------------------------------------------------------
|
|
222
|
+
/**
|
|
223
|
+
* Lex, flatten, and source-map Markdown in one operation. Every returned block
|
|
224
|
+
* carries a `source` anchor (or `null` when a marked edge case leaves a token
|
|
225
|
+
* genuinely unresolvable), in the exact order used for navigation/rendering.
|
|
226
|
+
*/
|
|
227
|
+
export function flattenMarkdown(markdown, options) {
|
|
228
|
+
const res = new MarkdownResolver(markdown, options?.sourceId);
|
|
229
|
+
const out = [];
|
|
230
|
+
flattenWalk(marked.lexer(markdown), 0, out, res, markdown.length);
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The unmapped low-level form: flatten already-lexed tokens with no source
|
|
235
|
+
* provenance (every block's `source` is `null`).
|
|
236
|
+
*
|
|
237
|
+
* @deprecated Prefer `flattenMarkdown(source)` for source-backed rows. Tokens
|
|
238
|
+
* carry no positions and the original source is unavailable here, so offsets
|
|
239
|
+
* cannot be reconstructed.
|
|
240
|
+
*/
|
|
241
|
+
export function flattenTokens(tokens) {
|
|
242
|
+
const out = [];
|
|
243
|
+
flattenWalk(tokens, 0, out, null, 0);
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=markdown-blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-blocks.js","sourceRoot":"","sources":["../src/markdown-blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA2B,MAAM,QAAQ,CAAA;AACxD,OAAO,EAAE,WAAW,EAA0B,MAAM,aAAa,CAAA;AAyBjE,2FAA2F;AAC3F,SA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AC5D,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAC1F,CAAC;IACH,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,OAAgC;IAChF,MAAM,GAAG,GAAG,IAAI,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC7D,MAAM,GAAG,GAAgB,EAAE,CAAA;IAC3B,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACjE,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe;IAC3C,MAAM,GAAG,GAAgB,EAAE,CAAA;IAC3B,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACpC,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Key } from "react";
|
|
2
|
+
/** A point in the original source. Offsets and columns are UTF-16 code-unit indices. */
|
|
3
|
+
export interface SourcePoint {
|
|
4
|
+
offset: number;
|
|
5
|
+
line: number;
|
|
6
|
+
column: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A half-open source range: `[start, end)`.
|
|
10
|
+
*
|
|
11
|
+
* `start`/`end` carry the line/column of each boundary, while `lastLine` is the
|
|
12
|
+
* inclusive physical line the anchor actually touches. `lastLine` avoids the
|
|
13
|
+
* common error where a range ending at column 0 after a newline appears to
|
|
14
|
+
* cover the following line.
|
|
15
|
+
*/
|
|
16
|
+
export interface SourceSpan {
|
|
17
|
+
sourceId?: string;
|
|
18
|
+
start: SourcePoint;
|
|
19
|
+
end: SourcePoint;
|
|
20
|
+
lastLine: number;
|
|
21
|
+
/** Exact original substring in `[start.offset, end.offset)`. */
|
|
22
|
+
text: string;
|
|
23
|
+
/** Complete physical source lines touched by the span, without newline normalization. */
|
|
24
|
+
lineText: string;
|
|
25
|
+
}
|
|
26
|
+
/** A rendered row can be synthetic, have one source, or relate two/more sources. */
|
|
27
|
+
export interface DocumentRowSource {
|
|
28
|
+
primary: SourceSpan;
|
|
29
|
+
related?: readonly SourceSpan[];
|
|
30
|
+
}
|
|
31
|
+
/** The live anchor a document controller resolves for a rendered/navigation row. */
|
|
32
|
+
export interface DocumentRowAnchor<T> {
|
|
33
|
+
row: T;
|
|
34
|
+
index: number;
|
|
35
|
+
key: Key;
|
|
36
|
+
/** The same semantic text used by default search and copy. */
|
|
37
|
+
text: string;
|
|
38
|
+
/** `null` for generated rows with no meaningful source coordinate. */
|
|
39
|
+
source: DocumentRowSource | null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A CRLF-aware line-start index over an original source string. A `\r\n` is one
|
|
43
|
+
* line break (the break lands on the `\n`); offsets still address the original
|
|
44
|
+
* `\r\n` string, so the `\r` counts as a column on the preceding line.
|
|
45
|
+
*/
|
|
46
|
+
export declare class SourceIndex {
|
|
47
|
+
readonly text: string;
|
|
48
|
+
readonly sourceId?: string | undefined;
|
|
49
|
+
readonly lineStarts: number[];
|
|
50
|
+
constructor(text: string, sourceId?: string | undefined);
|
|
51
|
+
/** The physical line index (0-based) containing `offset`, via binary search. */
|
|
52
|
+
lineAt(offset: number): number;
|
|
53
|
+
point(offset: number): SourcePoint;
|
|
54
|
+
/** End offset of a line's content, excluding its `\n`/`\r\n` delimiter. */
|
|
55
|
+
lineContentEnd(line: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Build a span for `[rawStart, rawEnd)`. When `trimTrailingNewlines` is set,
|
|
58
|
+
* terminal `\n`/`\r\n` sequences are removed from the *display* end so the
|
|
59
|
+
* inclusive `lastLine` stays on the content rather than a following blank
|
|
60
|
+
* line. `text` and `lineText` preserve original characters.
|
|
61
|
+
*/
|
|
62
|
+
span(rawStart: number, rawEnd: number, trimTrailingNewlines?: boolean): SourceSpan;
|
|
63
|
+
}
|
|
64
|
+
export interface SourceLineRow {
|
|
65
|
+
text: string;
|
|
66
|
+
source: DocumentRowSource;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* One navigation row per physical source line. Matches the current View
|
|
70
|
+
* behavior: an empty source yields one empty row, and a trailing newline yields
|
|
71
|
+
* a final empty row. Each row's primary span covers the line contents but not
|
|
72
|
+
* its newline delimiter; CRLF is one line break while offsets keep addressing
|
|
73
|
+
* the original `\r\n` string.
|
|
74
|
+
*/
|
|
75
|
+
export declare function sourceLines(source: string, options?: {
|
|
76
|
+
sourceId?: string;
|
|
77
|
+
}): SourceLineRow[];
|
|
78
|
+
/** Adapter for `sourceLines()` rows: identity mapping in row/line space. */
|
|
79
|
+
export declare const sourceLineAdapter: {
|
|
80
|
+
getText: (row: SourceLineRow) => string;
|
|
81
|
+
getSource: (row: SourceLineRow) => DocumentRowSource;
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAMhC,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;GAOG;AACH,MAAM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CAC1B;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,EAAE,CAY5F;AAED,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB;mBACb,aAAa,KAAG,MAAM;qBACpB,aAAa,KAAG,iBAAiB;CACnD,CAAA"}
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Line index and span construction
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
/** Offsets of the first character of every physical line. */
|
|
5
|
+
function buildLineStarts(text) {
|
|
6
|
+
const starts = [0];
|
|
7
|
+
for (let i = 0; i < text.length; i++) {
|
|
8
|
+
if (text.charCodeAt(i) === 10 /* \n */)
|
|
9
|
+
starts.push(i + 1);
|
|
10
|
+
}
|
|
11
|
+
return starts;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A CRLF-aware line-start index over an original source string. A `\r\n` is one
|
|
15
|
+
* line break (the break lands on the `\n`); offsets still address the original
|
|
16
|
+
* `\r\n` string, so the `\r` counts as a column on the preceding line.
|
|
17
|
+
*/
|
|
18
|
+
export class SourceIndex {
|
|
19
|
+
text;
|
|
20
|
+
sourceId;
|
|
21
|
+
lineStarts;
|
|
22
|
+
constructor(text, sourceId) {
|
|
23
|
+
this.text = text;
|
|
24
|
+
this.sourceId = sourceId;
|
|
25
|
+
this.lineStarts = buildLineStarts(text);
|
|
26
|
+
}
|
|
27
|
+
/** The physical line index (0-based) containing `offset`, via binary search. */
|
|
28
|
+
lineAt(offset) {
|
|
29
|
+
const starts = this.lineStarts;
|
|
30
|
+
let lo = 0;
|
|
31
|
+
let hi = starts.length - 1;
|
|
32
|
+
while (lo < hi) {
|
|
33
|
+
const mid = (lo + hi + 1) >> 1;
|
|
34
|
+
if (starts[mid] <= offset)
|
|
35
|
+
lo = mid;
|
|
36
|
+
else
|
|
37
|
+
hi = mid - 1;
|
|
38
|
+
}
|
|
39
|
+
return lo;
|
|
40
|
+
}
|
|
41
|
+
point(offset) {
|
|
42
|
+
const line = this.lineAt(offset);
|
|
43
|
+
return { offset, line, column: offset - this.lineStarts[line] };
|
|
44
|
+
}
|
|
45
|
+
/** End offset of a line's content, excluding its `\n`/`\r\n` delimiter. */
|
|
46
|
+
lineContentEnd(line) {
|
|
47
|
+
const starts = this.lineStarts;
|
|
48
|
+
const nextStart = line + 1 < starts.length ? starts[line + 1] : this.text.length;
|
|
49
|
+
let end = nextStart;
|
|
50
|
+
if (end > starts[line] && this.text.charCodeAt(end - 1) === 10) {
|
|
51
|
+
end--;
|
|
52
|
+
if (end > starts[line] && this.text.charCodeAt(end - 1) === 13 /* \r */)
|
|
53
|
+
end--;
|
|
54
|
+
}
|
|
55
|
+
return end;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build a span for `[rawStart, rawEnd)`. When `trimTrailingNewlines` is set,
|
|
59
|
+
* terminal `\n`/`\r\n` sequences are removed from the *display* end so the
|
|
60
|
+
* inclusive `lastLine` stays on the content rather than a following blank
|
|
61
|
+
* line. `text` and `lineText` preserve original characters.
|
|
62
|
+
*/
|
|
63
|
+
span(rawStart, rawEnd, trimTrailingNewlines = true) {
|
|
64
|
+
let end = rawEnd;
|
|
65
|
+
if (trimTrailingNewlines) {
|
|
66
|
+
while (end > rawStart && this.text.charCodeAt(end - 1) === 10) {
|
|
67
|
+
end--;
|
|
68
|
+
if (end > rawStart && this.text.charCodeAt(end - 1) === 13)
|
|
69
|
+
end--;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (end < rawStart)
|
|
73
|
+
end = rawStart;
|
|
74
|
+
const start = this.point(rawStart);
|
|
75
|
+
const endPoint = this.point(end);
|
|
76
|
+
const lastLine = end > rawStart ? this.lineAt(end - 1) : start.line;
|
|
77
|
+
const span = {
|
|
78
|
+
start,
|
|
79
|
+
end: endPoint,
|
|
80
|
+
lastLine,
|
|
81
|
+
text: this.text.slice(rawStart, end),
|
|
82
|
+
lineText: this.text.slice(this.lineStarts[start.line], this.lineContentEnd(lastLine)),
|
|
83
|
+
};
|
|
84
|
+
if (this.sourceId !== undefined)
|
|
85
|
+
span.sourceId = this.sourceId;
|
|
86
|
+
return span;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* One navigation row per physical source line. Matches the current View
|
|
91
|
+
* behavior: an empty source yields one empty row, and a trailing newline yields
|
|
92
|
+
* a final empty row. Each row's primary span covers the line contents but not
|
|
93
|
+
* its newline delimiter; CRLF is one line break while offsets keep addressing
|
|
94
|
+
* the original `\r\n` string.
|
|
95
|
+
*/
|
|
96
|
+
export function sourceLines(source, options) {
|
|
97
|
+
const index = new SourceIndex(source, options?.sourceId);
|
|
98
|
+
const rows = [];
|
|
99
|
+
for (let line = 0; line < index.lineStarts.length; line++) {
|
|
100
|
+
const start = index.lineStarts[line];
|
|
101
|
+
const end = index.lineContentEnd(line);
|
|
102
|
+
rows.push({
|
|
103
|
+
text: source.slice(start, end),
|
|
104
|
+
source: { primary: index.span(start, end, false) },
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return rows;
|
|
108
|
+
}
|
|
109
|
+
/** Adapter for `sourceLines()` rows: identity mapping in row/line space. */
|
|
110
|
+
export const sourceLineAdapter = {
|
|
111
|
+
getText: (row) => row.text,
|
|
112
|
+
getSource: (row) => row.source,
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=source.js.map
|