@tooee/renderers 0.1.11 → 0.1.14
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 +3 -7
- package/dist/CodeView.d.ts.map +1 -1
- package/dist/CodeView.js +5 -31
- package/dist/CodeView.js.map +1 -1
- package/dist/CommandPalette.d.ts.map +1 -1
- package/dist/CommandPalette.js +1 -23
- package/dist/CommandPalette.js.map +1 -1
- package/dist/DecorationLayer.d.ts +14 -0
- package/dist/DecorationLayer.d.ts.map +1 -0
- package/dist/DecorationLayer.js +2 -0
- package/dist/DecorationLayer.js.map +1 -0
- package/dist/MarkdownView.d.ts +16 -9
- package/dist/MarkdownView.d.ts.map +1 -1
- package/dist/MarkdownView.js +256 -107
- package/dist/MarkdownView.js.map +1 -1
- package/dist/RowDocumentRenderable.d.ts +14 -26
- package/dist/RowDocumentRenderable.d.ts.map +1 -1
- package/dist/RowDocumentRenderable.js +74 -78
- package/dist/RowDocumentRenderable.js.map +1 -1
- package/dist/Table.d.ts +5 -9
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +17 -46
- package/dist/Table.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/parsers.d.ts.map +1 -1
- package/dist/parsers.js.map +1 -1
- package/dist/useGutterPalette.d.ts +3 -0
- package/dist/useGutterPalette.d.ts.map +1 -0
- package/dist/useGutterPalette.js +10 -0
- package/dist/useGutterPalette.js.map +1 -0
- package/package.json +18 -16
- package/src/CodeView.tsx +11 -54
- package/src/CommandPalette.tsx +1 -25
- package/src/DecorationLayer.ts +11 -0
- package/src/MarkdownView.tsx +382 -164
- package/src/RowDocumentRenderable.ts +91 -135
- package/src/Table.tsx +35 -71
- package/src/index.ts +6 -8
- package/src/parsers.ts +4 -1
- package/src/useGutterPalette.ts +15 -0
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tooee/renderers",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Content renderers (markdown, code, image, table) for Tooee",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"image",
|
|
8
|
+
"markdown",
|
|
9
|
+
"opentui",
|
|
10
|
+
"syntax-highlighting",
|
|
11
|
+
"terminal",
|
|
12
|
+
"tui"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/gingerhendrix/tooee",
|
|
15
|
+
"bugs": "https://github.com/gingerhendrix/tooee/issues",
|
|
5
16
|
"license": "MIT",
|
|
6
17
|
"author": "Gareth Andrew",
|
|
7
18
|
"repository": {
|
|
@@ -9,16 +20,9 @@
|
|
|
9
20
|
"url": "https://github.com/gingerhendrix/tooee.git",
|
|
10
21
|
"directory": "packages/renderers"
|
|
11
22
|
},
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"tui",
|
|
16
|
-
"terminal",
|
|
17
|
-
"cli",
|
|
18
|
-
"opentui",
|
|
19
|
-
"markdown",
|
|
20
|
-
"syntax-highlighting",
|
|
21
|
-
"image"
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src"
|
|
22
26
|
],
|
|
23
27
|
"type": "module",
|
|
24
28
|
"exports": {
|
|
@@ -29,15 +33,13 @@
|
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
|
-
"files": [
|
|
33
|
-
"dist",
|
|
34
|
-
"src"
|
|
35
|
-
],
|
|
36
36
|
"scripts": {
|
|
37
37
|
"typecheck": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@tooee/
|
|
40
|
+
"@tooee/fuzzy": "0.1.14",
|
|
41
|
+
"@tooee/marks": "0.1.14",
|
|
42
|
+
"@tooee/themes": "0.1.14",
|
|
41
43
|
"marked": "^17.0.4"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
package/src/CodeView.tsx
CHANGED
|
@@ -1,75 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type RefObject } from "react"
|
|
2
2
|
import { useTheme } from "@tooee/themes"
|
|
3
|
-
import type {
|
|
3
|
+
import type { MarkState } from "@tooee/marks"
|
|
4
|
+
import type { RowDocumentRenderable } from "./RowDocumentRenderable.js"
|
|
5
|
+
import { useGutterPalette } from "./useGutterPalette.js"
|
|
4
6
|
import "./row-document.js"
|
|
5
7
|
|
|
6
8
|
interface CodeViewProps {
|
|
7
9
|
content: string
|
|
8
10
|
language?: string
|
|
9
11
|
showLineNumbers?: boolean
|
|
10
|
-
|
|
11
|
-
selectionStart?: number
|
|
12
|
-
selectionEnd?: number
|
|
13
|
-
matchingLines?: Set<number>
|
|
14
|
-
currentMatchLine?: number
|
|
15
|
-
toggledLines?: Set<number>
|
|
12
|
+
marks?: MarkState
|
|
16
13
|
docRef?: RefObject<RowDocumentRenderable | null>
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
export function CodeView({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
showLineNumbers = true,
|
|
23
|
-
cursor,
|
|
24
|
-
selectionStart,
|
|
25
|
-
selectionEnd,
|
|
26
|
-
matchingLines,
|
|
27
|
-
currentMatchLine,
|
|
28
|
-
toggledLines,
|
|
29
|
-
docRef,
|
|
30
|
-
}: CodeViewProps) {
|
|
31
|
-
const { syntax, theme } = useTheme()
|
|
32
|
-
const internalRef = useRef<RowDocumentRenderable>(null)
|
|
33
|
-
const effectiveRef = docRef ?? internalRef
|
|
34
|
-
|
|
35
|
-
const palette: RowDocumentPalette = {
|
|
36
|
-
gutterFg: theme.textMuted,
|
|
37
|
-
gutterBg: theme.backgroundElement,
|
|
38
|
-
cursorBg: theme.cursorLine,
|
|
39
|
-
selectionBg: theme.selection,
|
|
40
|
-
matchBg: theme.warning,
|
|
41
|
-
currentMatchBg: theme.primary,
|
|
42
|
-
toggledBg: theme.backgroundPanel,
|
|
43
|
-
cursorSignFg: theme.primary,
|
|
44
|
-
matchSignFg: theme.warning,
|
|
45
|
-
currentMatchSignFg: theme.primary,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
const decorations: RowDocumentDecorations = {
|
|
50
|
-
cursorRow: cursor,
|
|
51
|
-
selection: selectionStart != null && selectionEnd != null
|
|
52
|
-
? { start: selectionStart, end: selectionEnd }
|
|
53
|
-
: null,
|
|
54
|
-
matchingRows: matchingLines,
|
|
55
|
-
currentMatchRow: currentMatchLine,
|
|
56
|
-
toggledRows: toggledLines,
|
|
57
|
-
}
|
|
58
|
-
effectiveRef.current?.setDecorations(decorations)
|
|
59
|
-
}, [cursor, selectionStart, selectionEnd, matchingLines, currentMatchLine, toggledLines])
|
|
60
|
-
|
|
61
|
-
const codeElement = <code content={content} filetype={language} syntaxStyle={syntax} />
|
|
16
|
+
export function CodeView({ content, language, showLineNumbers = true, marks, docRef }: CodeViewProps) {
|
|
17
|
+
const { syntax } = useTheme()
|
|
18
|
+
const palette = useGutterPalette()
|
|
62
19
|
|
|
63
20
|
return (
|
|
64
21
|
<row-document
|
|
65
|
-
ref={
|
|
66
|
-
key={theme.textMuted + theme.backgroundElement}
|
|
22
|
+
ref={docRef}
|
|
67
23
|
showLineNumbers={showLineNumbers}
|
|
68
24
|
palette={palette}
|
|
25
|
+
decorations={marks?.sets}
|
|
69
26
|
signColumnWidth={1}
|
|
70
27
|
style={{ flexGrow: 1 }}
|
|
71
28
|
>
|
|
72
|
-
{
|
|
29
|
+
<code content={content} filetype={language} syntaxStyle={syntax} />
|
|
73
30
|
</row-document>
|
|
74
31
|
)
|
|
75
32
|
}
|
package/src/CommandPalette.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState, useMemo, useCallback } from "react"
|
|
2
2
|
import { useKeyboard } from "@opentui/react"
|
|
3
3
|
import { useTheme } from "@tooee/themes"
|
|
4
|
+
import { fuzzyMatch } from "@tooee/fuzzy"
|
|
4
5
|
|
|
5
6
|
export interface CommandPaletteEntry {
|
|
6
7
|
id: string
|
|
@@ -16,31 +17,6 @@ interface CommandPaletteProps {
|
|
|
16
17
|
onClose: () => void
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
function fuzzyMatch(query: string, text: string): number | null {
|
|
20
|
-
const lowerQuery = query.toLowerCase()
|
|
21
|
-
const lowerText = text.toLowerCase()
|
|
22
|
-
|
|
23
|
-
let qi = 0
|
|
24
|
-
let score = 0
|
|
25
|
-
let lastMatchIndex = -2
|
|
26
|
-
|
|
27
|
-
for (let ti = 0; ti < lowerText.length && qi < lowerQuery.length; ti++) {
|
|
28
|
-
if (lowerText[ti] === lowerQuery[qi]) {
|
|
29
|
-
// Start of string bonus
|
|
30
|
-
if (ti === 0) score += 3
|
|
31
|
-
// Word boundary bonus (after space, hyphen, dot, slash)
|
|
32
|
-
else if (" -./".includes(lowerText[ti - 1]!)) score += 2
|
|
33
|
-
// Consecutive bonus
|
|
34
|
-
else if (ti === lastMatchIndex + 1) score += 1
|
|
35
|
-
|
|
36
|
-
lastMatchIndex = ti
|
|
37
|
-
qi++
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return qi === lowerQuery.length ? score : null
|
|
42
|
-
}
|
|
43
|
-
|
|
44
20
|
export function CommandPalette({ commands, onSelect, onClose }: CommandPaletteProps) {
|
|
45
21
|
const { theme } = useTheme()
|
|
46
22
|
const [filter, setFilter] = useState("")
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RowDecoration {
|
|
2
|
+
row: number
|
|
3
|
+
background?: string
|
|
4
|
+
gutterBackground?: string
|
|
5
|
+
sign?: { text: string; fg?: string }
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface DecorationLayer {
|
|
9
|
+
readonly priority: number
|
|
10
|
+
forVisibleRows(from: number, to: number): Iterable<RowDecoration>
|
|
11
|
+
}
|