@tooee/renderers 0.7.3 → 0.9.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/dist/chooser/choose-filter.d.ts +13 -0
- package/dist/chooser/choose-filter.d.ts.map +1 -0
- package/dist/chooser/choose-filter.js +22 -0
- package/dist/chooser/choose-filter.js.map +1 -0
- package/dist/chooser/choose-highlighted-text.d.ts +9 -0
- package/dist/chooser/choose-highlighted-text.d.ts.map +1 -0
- package/dist/chooser/choose-highlighted-text.js +32 -0
- package/dist/chooser/choose-highlighted-text.js.map +1 -0
- package/dist/chooser/choose-list.d.ts +29 -0
- package/dist/chooser/choose-list.d.ts.map +1 -0
- package/dist/chooser/choose-list.js +66 -0
- package/dist/chooser/choose-list.js.map +1 -0
- package/dist/chooser/choose-store.d.ts +58 -0
- package/dist/chooser/choose-store.d.ts.map +1 -0
- package/dist/chooser/choose-store.js +102 -0
- package/dist/chooser/choose-store.js.map +1 -0
- package/dist/chooser/chooser.d.ts +18 -0
- package/dist/chooser/chooser.d.ts.map +1 -0
- package/dist/chooser/chooser.js +25 -0
- package/dist/chooser/chooser.js.map +1 -0
- package/dist/chooser/fuzzy.d.ts +9 -0
- package/dist/chooser/fuzzy.d.ts.map +1 -0
- package/dist/chooser/fuzzy.js +5 -0
- package/dist/chooser/fuzzy.js.map +1 -0
- package/dist/chooser/source.d.ts +5 -0
- package/dist/chooser/source.d.ts.map +1 -0
- package/dist/chooser/source.js +26 -0
- package/dist/chooser/source.js.map +1 -0
- package/dist/chooser/types.d.ts +22 -0
- package/dist/chooser/types.d.ts.map +1 -0
- package/dist/chooser/types.js +2 -0
- package/dist/chooser/types.js.map +1 -0
- package/dist/chooser/use-choose.d.ts +84 -0
- package/dist/chooser/use-choose.d.ts.map +1 -0
- package/dist/chooser/use-choose.js +382 -0
- package/dist/chooser/use-choose.js.map +1 -0
- package/dist/code-blocks.d.ts +2 -1
- package/dist/code-blocks.d.ts.map +1 -1
- package/dist/code-blocks.js +20 -18
- package/dist/code-blocks.js.map +1 -1
- package/dist/code-view.d.ts +2 -1
- package/dist/code-view.d.ts.map +1 -1
- package/dist/code-view.js.map +1 -1
- package/dist/command-palette.d.ts +2 -1
- package/dist/command-palette.d.ts.map +1 -1
- package/dist/command-palette.js +15 -76
- package/dist/command-palette.js.map +1 -1
- package/dist/context-menu.d.ts +2 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +50 -15
- package/dist/context-menu.js.map +1 -1
- package/dist/index.d.ts +19 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown/blocks/blockquote.d.ts +11 -0
- package/dist/markdown/blocks/blockquote.d.ts.map +1 -0
- package/dist/markdown/blocks/blockquote.js +26 -0
- package/dist/markdown/blocks/blockquote.js.map +1 -0
- package/dist/markdown/blocks/flat-block.d.ts +20 -0
- package/dist/markdown/blocks/flat-block.d.ts.map +1 -0
- package/dist/markdown/blocks/flat-block.js +52 -0
- package/dist/markdown/blocks/flat-block.js.map +1 -0
- package/dist/markdown/blocks/heading.d.ts +11 -0
- package/dist/markdown/blocks/heading.d.ts.map +1 -0
- package/dist/markdown/blocks/heading.js +23 -0
- package/dist/markdown/blocks/heading.js.map +1 -0
- package/dist/markdown/blocks/horizontal-rule.d.ts +7 -0
- package/dist/markdown/blocks/horizontal-rule.d.ts.map +1 -0
- package/dist/markdown/blocks/horizontal-rule.js +5 -0
- package/dist/markdown/blocks/horizontal-rule.js.map +1 -0
- package/dist/markdown/blocks/list-line.d.ts +10 -0
- package/dist/markdown/blocks/list-line.d.ts.map +1 -0
- package/dist/markdown/blocks/list-line.js +21 -0
- package/dist/markdown/blocks/list-line.js.map +1 -0
- package/dist/markdown/blocks/paragraph.d.ts +12 -0
- package/dist/markdown/blocks/paragraph.d.ts.map +1 -0
- package/dist/markdown/blocks/paragraph.js +27 -0
- package/dist/markdown/blocks/paragraph.js.map +1 -0
- package/dist/markdown/blocks/table.d.ts +7 -0
- package/dist/markdown/blocks/table.d.ts.map +1 -0
- package/dist/markdown/blocks/table.js +30 -0
- package/dist/markdown/blocks/table.js.map +1 -0
- package/dist/markdown/chunks.d.ts +5 -0
- package/dist/markdown/chunks.d.ts.map +1 -0
- package/dist/markdown/chunks.js +29 -0
- package/dist/markdown/chunks.js.map +1 -0
- package/dist/markdown/inline.d.ts +8 -0
- package/dist/markdown/inline.d.ts.map +1 -0
- package/dist/markdown/inline.js +27 -0
- package/dist/markdown/inline.js.map +1 -0
- package/dist/markdown/links.d.ts +11 -0
- package/dist/markdown/links.d.ts.map +1 -0
- package/dist/markdown/links.js +107 -0
- package/dist/markdown/links.js.map +1 -0
- package/dist/markdown/plain-text.d.ts +4 -0
- package/dist/markdown/plain-text.d.ts.map +1 -0
- package/dist/markdown/plain-text.js +21 -0
- package/dist/markdown/plain-text.js.map +1 -0
- package/dist/markdown/tokens.d.ts +32 -0
- package/dist/markdown/tokens.d.ts.map +1 -0
- package/dist/markdown/tokens.js +25 -0
- package/dist/markdown/tokens.js.map +1 -0
- package/dist/markdown/visit-inline.d.ts +17 -0
- package/dist/markdown/visit-inline.d.ts.map +1 -0
- package/dist/markdown/visit-inline.js +61 -0
- package/dist/markdown/visit-inline.js.map +1 -0
- package/dist/markdown-blocks.d.ts.map +1 -1
- package/dist/markdown-blocks.js +6 -4
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/markdown-images.d.ts.map +1 -1
- package/dist/markdown-images.js +14 -5
- package/dist/markdown-images.js.map +1 -1
- package/dist/markdown-view.d.ts +10 -32
- package/dist/markdown-view.d.ts.map +1 -1
- package/dist/markdown-view.js +9 -468
- package/dist/markdown-view.js.map +1 -1
- package/dist/mermaid.d.ts +5 -4
- package/dist/mermaid.d.ts.map +1 -1
- package/dist/mermaid.js +5 -5
- package/dist/mermaid.js.map +1 -1
- package/dist/parsers.d.ts +6 -13
- package/dist/parsers.d.ts.map +1 -1
- package/dist/parsers.js +66 -46
- package/dist/parsers.js.map +1 -1
- package/dist/row-document-renderable.d.ts +7 -6
- package/dist/row-document-renderable.d.ts.map +1 -1
- package/dist/row-document-renderable.js +2 -7
- package/dist/row-document-renderable.js.map +1 -1
- package/dist/table-types.d.ts +4 -0
- package/dist/table-types.d.ts.map +1 -1
- package/dist/table.d.ts +4 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +30 -23
- package/dist/table.js.map +1 -1
- package/package.json +9 -5
- package/src/chooser/choose-filter.tsx +66 -0
- package/src/chooser/choose-highlighted-text.tsx +49 -0
- package/src/chooser/choose-list.tsx +159 -0
- package/src/chooser/choose-store.ts +147 -0
- package/src/chooser/chooser.tsx +80 -0
- package/src/chooser/fuzzy.ts +13 -0
- package/src/chooser/source.ts +36 -0
- package/src/chooser/types.ts +28 -0
- package/src/chooser/use-choose.ts +540 -0
- package/src/code-blocks.tsx +28 -26
- package/src/code-view.tsx +2 -1
- package/src/command-palette.tsx +49 -137
- package/src/context-menu.tsx +54 -15
- package/src/index.ts +46 -3
- package/src/markdown/blocks/blockquote.tsx +53 -0
- package/src/markdown/blocks/flat-block.tsx +119 -0
- package/src/markdown/blocks/heading.tsx +53 -0
- package/src/markdown/blocks/horizontal-rule.tsx +16 -0
- package/src/markdown/blocks/list-line.tsx +52 -0
- package/src/markdown/blocks/paragraph.tsx +90 -0
- package/src/markdown/blocks/table.tsx +55 -0
- package/src/markdown/chunks.ts +42 -0
- package/src/markdown/inline.tsx +45 -0
- package/src/markdown/links.ts +133 -0
- package/src/markdown/plain-text.ts +22 -0
- package/src/markdown/tokens.ts +53 -0
- package/src/markdown/visit-inline.ts +82 -0
- package/src/markdown-blocks.ts +6 -4
- package/src/markdown-images.ts +15 -6
- package/src/markdown-view.tsx +20 -845
- package/src/mermaid.ts +11 -9
- package/src/parsers.ts +86 -62
- package/src/row-document-renderable.ts +13 -15
- package/src/table-types.ts +5 -0
- package/src/table.tsx +36 -30
package/src/command-palette.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { useTheme
|
|
4
|
-
import {
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { useTheme } from "@tooee/themes";
|
|
4
|
+
import { Chooser } from "./chooser/chooser.js";
|
|
5
|
+
import { ChooseHighlightedText } from "./chooser/choose-highlighted-text.js";
|
|
6
|
+
import type { ChooseItem } from "./chooser/types.js";
|
|
5
7
|
|
|
6
8
|
export interface CommandPaletteEntry {
|
|
7
9
|
id: string;
|
|
@@ -21,143 +23,53 @@ export const CommandPalette = function CommandPalette({
|
|
|
21
23
|
commands,
|
|
22
24
|
onSelect,
|
|
23
25
|
onClose,
|
|
24
|
-
}: CommandPaletteProps):
|
|
26
|
+
}: CommandPaletteProps): ReactNode {
|
|
25
27
|
const { theme } = useTheme();
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
results.push({ entry, score });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
results.sort((a, b) => b.score - a.score);
|
|
41
|
-
return results.map((r) => r.entry);
|
|
42
|
-
}, [commands, filter]);
|
|
43
|
-
|
|
44
|
-
const handleSelect = useCallback(() => {
|
|
45
|
-
const item = filtered[activeIndex];
|
|
46
|
-
if (item !== undefined) {
|
|
47
|
-
onSelect(item.id);
|
|
28
|
+
const entriesById = useMemo(
|
|
29
|
+
() => new Map(commands.map((entry) => [entry.id, entry])),
|
|
30
|
+
[commands],
|
|
31
|
+
);
|
|
32
|
+
const items = useMemo<ChooseItem[]>(
|
|
33
|
+
() => commands.map((entry) => ({ text: entry.title, value: entry.id })),
|
|
34
|
+
[commands],
|
|
35
|
+
);
|
|
36
|
+
const handleSelect = (item: ChooseItem): void => {
|
|
37
|
+
if (item.value !== undefined) {
|
|
38
|
+
onSelect(item.value);
|
|
48
39
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const moveUp = useCallback(() => {
|
|
52
|
-
setActiveIndex((i) => Math.max(0, i - 1));
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
|
-
const moveDown = useCallback(() => {
|
|
56
|
-
setActiveIndex((i) => Math.min(filtered.length - 1, i + 1));
|
|
57
|
-
}, [filtered.length]);
|
|
58
|
-
|
|
59
|
-
useCommand({
|
|
60
|
-
handler: onClose,
|
|
61
|
-
hidden: true,
|
|
62
|
-
hotkey: "Escape",
|
|
63
|
-
id: "command-palette:close",
|
|
64
|
-
modes: ["insert", "cursor"],
|
|
65
|
-
title: "Close command palette",
|
|
66
|
-
});
|
|
67
|
-
useCommand({
|
|
68
|
-
handler: handleSelect,
|
|
69
|
-
hidden: true,
|
|
70
|
-
hotkey: "Enter",
|
|
71
|
-
id: "command-palette:select",
|
|
72
|
-
modes: ["insert", "cursor"],
|
|
73
|
-
title: "Run selected command",
|
|
74
|
-
});
|
|
75
|
-
useCommand({
|
|
76
|
-
handler: moveUp,
|
|
77
|
-
hidden: true,
|
|
78
|
-
hotkey: "up",
|
|
79
|
-
id: "command-palette:move-up",
|
|
80
|
-
modes: ["insert", "cursor"],
|
|
81
|
-
title: "Move up",
|
|
82
|
-
});
|
|
83
|
-
useCommand({
|
|
84
|
-
handler: moveDown,
|
|
85
|
-
hidden: true,
|
|
86
|
-
hotkey: "down",
|
|
87
|
-
id: "command-palette:move-down",
|
|
88
|
-
modes: ["insert", "cursor"],
|
|
89
|
-
title: "Move down",
|
|
90
|
-
});
|
|
40
|
+
};
|
|
91
41
|
|
|
92
42
|
return (
|
|
93
|
-
<
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
<input
|
|
108
|
-
focused
|
|
109
|
-
placeholder="Filter commands..."
|
|
110
|
-
onSubmit={handleSelect}
|
|
111
|
-
onInput={(value: string) => {
|
|
112
|
-
setFilter(value);
|
|
113
|
-
setActiveIndex(0);
|
|
114
|
-
}}
|
|
115
|
-
backgroundColor="transparent"
|
|
116
|
-
focusedBackgroundColor="transparent"
|
|
117
|
-
textColor={theme.text}
|
|
118
|
-
placeholderColor={theme.textMuted}
|
|
119
|
-
cursorColor={theme.accent}
|
|
120
|
-
style={{ flexGrow: 1 }}
|
|
121
|
-
/>
|
|
122
|
-
<text content={` ${filtered.length}`} fg={theme.textMuted} />
|
|
123
|
-
<CloseButton onClose={onClose} />
|
|
124
|
-
</box>
|
|
125
|
-
|
|
126
|
-
{/* Separator */}
|
|
127
|
-
<box height={1} width="100%" backgroundColor={theme.border} />
|
|
128
|
-
|
|
129
|
-
{/* Command list */}
|
|
130
|
-
<scrollbox focused={false} style={{ flexGrow: 1 }}>
|
|
131
|
-
{filtered.map(
|
|
132
|
-
(entry, i): React.ReactNode => (
|
|
133
|
-
<box
|
|
134
|
-
key={entry.id}
|
|
135
|
-
flexDirection="row"
|
|
136
|
-
paddingLeft={1}
|
|
137
|
-
paddingRight={1}
|
|
138
|
-
height={1}
|
|
139
|
-
backgroundColor={i === activeIndex ? theme.backgroundElement : undefined}
|
|
140
|
-
onMouseDown={(event) => {
|
|
141
|
-
// Left-click runs the entry — same code path as Enter.
|
|
142
|
-
if (event.button !== 0) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
event.preventDefault();
|
|
146
|
-
event.stopPropagation();
|
|
147
|
-
onSelect(entry.id);
|
|
148
|
-
}}
|
|
149
|
-
>
|
|
150
|
-
<text content={entry.title} fg={theme.text} style={{ flexGrow: 1 }} />
|
|
151
|
-
{(entry.hotkey?.length ?? 0) > 0 && (
|
|
152
|
-
<text content={entry.hotkey} fg={theme.textMuted} />
|
|
153
|
-
)}
|
|
154
|
-
{(entry.category?.length ?? 0) > 0 && (
|
|
155
|
-
<text content={` ${entry.category}`} fg={theme.textMuted} />
|
|
43
|
+
<Chooser
|
|
44
|
+
items={items}
|
|
45
|
+
commandScope="command-palette"
|
|
46
|
+
prompt={<text content=":" fg={theme.accent} />}
|
|
47
|
+
placeholder="Filter commands..."
|
|
48
|
+
onCancel={onClose}
|
|
49
|
+
onSelect={handleSelect}
|
|
50
|
+
renderItem={({ item, positions }): ReactNode => {
|
|
51
|
+
const entry = item.value === undefined ? undefined : entriesById.get(item.value);
|
|
52
|
+
return (
|
|
53
|
+
<>
|
|
54
|
+
<text fg={theme.text} style={{ flexGrow: 1 }}>
|
|
55
|
+
{(entry?.icon?.length ?? 0) > 0 && (
|
|
56
|
+
<span fg={theme.textMuted}>{`${entry?.icon} `}</span>
|
|
156
57
|
)}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
58
|
+
<ChooseHighlightedText
|
|
59
|
+
text={item.text}
|
|
60
|
+
positions={positions}
|
|
61
|
+
highlightColor={theme.warning}
|
|
62
|
+
/>
|
|
63
|
+
</text>
|
|
64
|
+
{(entry?.hotkey?.length ?? 0) > 0 && (
|
|
65
|
+
<text content={entry?.hotkey} fg={theme.textMuted} />
|
|
66
|
+
)}
|
|
67
|
+
{(entry?.category?.length ?? 0) > 0 && (
|
|
68
|
+
<text content={` ${entry?.category}`} fg={theme.textMuted} />
|
|
69
|
+
)}
|
|
70
|
+
</>
|
|
71
|
+
);
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
162
74
|
);
|
|
163
75
|
};
|
package/src/context-menu.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useState, useCallback } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { useTerminalDimensions } from "@opentui/react";
|
|
3
|
+
import { useCommand } from "@tooee/commands";
|
|
3
4
|
import { useTheme } from "@tooee/themes";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
4
6
|
|
|
5
7
|
export interface ContextMenuEntry {
|
|
6
8
|
id: string;
|
|
@@ -35,7 +37,7 @@ export const ContextMenu = function ContextMenu({
|
|
|
35
37
|
y,
|
|
36
38
|
onSelect,
|
|
37
39
|
onClose,
|
|
38
|
-
}: ContextMenuProps):
|
|
40
|
+
}: ContextMenuProps): ReactNode {
|
|
39
41
|
const { theme } = useTheme();
|
|
40
42
|
const { width: termWidth, height: termHeight } = useTerminalDimensions();
|
|
41
43
|
const [activeIndex, setActiveIndex] = useState(0);
|
|
@@ -50,18 +52,55 @@ export const ContextMenu = function ContextMenu({
|
|
|
50
52
|
[entries, onSelect],
|
|
51
53
|
);
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
const moveUp = useCallback(() => {
|
|
56
|
+
setActiveIndex((index) => Math.max(0, index - 1));
|
|
57
|
+
}, []);
|
|
58
|
+
const moveDown = useCallback(() => {
|
|
59
|
+
setActiveIndex((index) => Math.min(entries.length - 1, index + 1));
|
|
60
|
+
}, [entries.length]);
|
|
61
|
+
const selectActive = useCallback(() => {
|
|
62
|
+
select(activeIndex);
|
|
63
|
+
}, [activeIndex, select]);
|
|
64
|
+
|
|
65
|
+
useCommand({
|
|
66
|
+
handler: moveUp,
|
|
67
|
+
hidden: true,
|
|
68
|
+
hotkey: "up",
|
|
69
|
+
id: "context-menu:move-up",
|
|
70
|
+
modes: ["insert", "cursor"],
|
|
71
|
+
title: "Move up",
|
|
72
|
+
});
|
|
73
|
+
useCommand({
|
|
74
|
+
handler: moveUp,
|
|
75
|
+
hidden: true,
|
|
76
|
+
hotkey: "k",
|
|
77
|
+
id: "context-menu:move-up-vim",
|
|
78
|
+
modes: ["insert", "cursor"],
|
|
79
|
+
title: "Move up",
|
|
80
|
+
});
|
|
81
|
+
useCommand({
|
|
82
|
+
handler: moveDown,
|
|
83
|
+
hidden: true,
|
|
84
|
+
hotkey: "down",
|
|
85
|
+
id: "context-menu:move-down",
|
|
86
|
+
modes: ["insert", "cursor"],
|
|
87
|
+
title: "Move down",
|
|
88
|
+
});
|
|
89
|
+
useCommand({
|
|
90
|
+
handler: moveDown,
|
|
91
|
+
hidden: true,
|
|
92
|
+
hotkey: "j",
|
|
93
|
+
id: "context-menu:move-down-vim",
|
|
94
|
+
modes: ["insert", "cursor"],
|
|
95
|
+
title: "Move down",
|
|
96
|
+
});
|
|
97
|
+
useCommand({
|
|
98
|
+
handler: selectActive,
|
|
99
|
+
hidden: true,
|
|
100
|
+
hotkey: "Enter",
|
|
101
|
+
id: "context-menu:select",
|
|
102
|
+
modes: ["insert", "cursor"],
|
|
103
|
+
title: "Select action",
|
|
65
104
|
});
|
|
66
105
|
|
|
67
106
|
// Size the panel from its contents (terminal cell width, not code units,
|
|
@@ -122,7 +161,7 @@ export const ContextMenu = function ContextMenu({
|
|
|
122
161
|
</box>
|
|
123
162
|
) : (
|
|
124
163
|
entries.map(
|
|
125
|
-
(entry, i):
|
|
164
|
+
(entry, i): ReactNode => (
|
|
126
165
|
<box
|
|
127
166
|
key={entry.id}
|
|
128
167
|
flexDirection="row"
|
package/src/index.ts
CHANGED
|
@@ -25,21 +25,64 @@ export {
|
|
|
25
25
|
} from "./code-blocks.js";
|
|
26
26
|
export type { CodeBlockRenderer, CodeBlockRendererProps, CodeBlockHScroll } from "./code-blocks.js";
|
|
27
27
|
export { CodeView } from "./code-view.js";
|
|
28
|
-
export { Table, computeColumnWidths, isNumeric, sampleRows } from "./table.js";
|
|
28
|
+
export { Table, computeColumnWidths, formatTableCell, isNumeric, sampleRows } from "./table.js";
|
|
29
29
|
export type { TableProps, ColumnWidthOptions } from "./table.js";
|
|
30
30
|
export type { ColumnDef, TableRow } from "./table-types.js";
|
|
31
31
|
export { CommandPalette } from "./command-palette.js";
|
|
32
32
|
export type { CommandPaletteEntry } from "./command-palette.js";
|
|
33
|
+
export { Chooser } from "./chooser/chooser.js";
|
|
34
|
+
export type { ChooserProps } from "./chooser/chooser.js";
|
|
35
|
+
export { ChooseFilter } from "./chooser/choose-filter.js";
|
|
36
|
+
export type { ChooseFilterProps } from "./chooser/choose-filter.js";
|
|
37
|
+
export { ChooseHighlightedText } from "./chooser/choose-highlighted-text.js";
|
|
38
|
+
export type { ChooseHighlightedTextProps } from "./chooser/choose-highlighted-text.js";
|
|
39
|
+
export { ChooseList } from "./chooser/choose-list.js";
|
|
40
|
+
export type { ChooseItemRenderContext, ChooseListProps } from "./chooser/choose-list.js";
|
|
41
|
+
export {
|
|
42
|
+
createChooseStore,
|
|
43
|
+
selectActiveIndex,
|
|
44
|
+
selectError,
|
|
45
|
+
selectFilterQuery,
|
|
46
|
+
selectItems,
|
|
47
|
+
selectLoading,
|
|
48
|
+
selectMatches,
|
|
49
|
+
selectReloadRevision,
|
|
50
|
+
selectSelectedOriginalIndices,
|
|
51
|
+
} from "./chooser/choose-store.js";
|
|
52
|
+
export type { ChooseStore, ChooseStoreContext, ChooseStoreEvents } from "./chooser/choose-store.js";
|
|
53
|
+
export { fuzzyFilter } from "./chooser/fuzzy.js";
|
|
54
|
+
export type { FuzzyMatch } from "./chooser/fuzzy.js";
|
|
55
|
+
export { loadChooseSource } from "./chooser/source.js";
|
|
56
|
+
export { useChoose } from "./chooser/use-choose.js";
|
|
57
|
+
export type {
|
|
58
|
+
ChooseCommandGroup,
|
|
59
|
+
ChooseController,
|
|
60
|
+
ChooseState,
|
|
61
|
+
ChooseViewModel,
|
|
62
|
+
UseChooseOptions,
|
|
63
|
+
UseChooseResult,
|
|
64
|
+
} from "./chooser/use-choose.js";
|
|
65
|
+
export type {
|
|
66
|
+
ChooseContentProvider,
|
|
67
|
+
ChooseItem,
|
|
68
|
+
ChooseOptions,
|
|
69
|
+
ChooseResult,
|
|
70
|
+
ChooseSource,
|
|
71
|
+
} from "./chooser/types.js";
|
|
33
72
|
export { ContextMenu } from "./context-menu.js";
|
|
34
73
|
export type { ContextMenuEntry } from "./context-menu.js";
|
|
35
74
|
export { parseCSV, parseTSV, parseJSON, parseAuto, detectFormat } from "./parsers.js";
|
|
36
|
-
export type { Format, ParsedTable } from "./parsers.js";
|
|
75
|
+
export type { Format, ParsedTable, TableData } from "./parsers.js";
|
|
37
76
|
export { RowDocumentRenderable } from "./row-document-renderable.js";
|
|
38
77
|
export {
|
|
39
78
|
DEFAULT_SIGN_COLUMN_WIDTH,
|
|
40
79
|
computeRowDocumentGutterWidth,
|
|
41
80
|
} from "./row-document-renderable.js";
|
|
42
|
-
export type {
|
|
81
|
+
export type {
|
|
82
|
+
RowDocumentOptions,
|
|
83
|
+
RowDocumentPalette,
|
|
84
|
+
VisibleRowRange,
|
|
85
|
+
} from "./row-document-renderable.js";
|
|
43
86
|
export type { DecorationLayer, RowDecoration } from "./decoration-layer.js";
|
|
44
87
|
export type { DocumentBindings } from "./document-bindings.js";
|
|
45
88
|
export { useGutterPalette } from "./use-gutter-palette.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Token, Tokens } from "marked";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { ResolvedTheme } from "@tooee/themes";
|
|
4
|
+
import { InlineTokens } from "../inline.js";
|
|
5
|
+
import { linkMouseHandler } from "../links.js";
|
|
6
|
+
import type { MarkdownLinkHandler } from "../links.js";
|
|
7
|
+
import { hasMarkedText } from "../tokens.js";
|
|
8
|
+
|
|
9
|
+
export const BlockquoteRenderer = function BlockquoteRenderer({
|
|
10
|
+
token,
|
|
11
|
+
theme,
|
|
12
|
+
indent,
|
|
13
|
+
onLinkActivate,
|
|
14
|
+
}: {
|
|
15
|
+
token: Tokens.Blockquote;
|
|
16
|
+
theme: ResolvedTheme;
|
|
17
|
+
indent: number;
|
|
18
|
+
onLinkActivate?: MarkdownLinkHandler;
|
|
19
|
+
}): ReactNode {
|
|
20
|
+
const inlineTokens: Token[] = [];
|
|
21
|
+
for (const child of token.tokens) {
|
|
22
|
+
if ("tokens" in child && Array.isArray(child.tokens)) {
|
|
23
|
+
if (inlineTokens.length > 0) {
|
|
24
|
+
inlineTokens.push({ raw: "\n", type: "br" });
|
|
25
|
+
}
|
|
26
|
+
inlineTokens.push(...child.tokens);
|
|
27
|
+
} else if (hasMarkedText(child)) {
|
|
28
|
+
inlineTokens.push(child);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<box
|
|
34
|
+
border={["left"]}
|
|
35
|
+
borderColor={theme.markdownBlockQuote}
|
|
36
|
+
borderStyle="single"
|
|
37
|
+
style={{
|
|
38
|
+
marginBottom: 1,
|
|
39
|
+
marginLeft: 1 + indent,
|
|
40
|
+
marginRight: 1,
|
|
41
|
+
marginTop: 0,
|
|
42
|
+
paddingLeft: 1,
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<text
|
|
46
|
+
style={{ fg: theme.textMuted }}
|
|
47
|
+
onMouseDown={linkMouseHandler(inlineTokens, onLinkActivate)}
|
|
48
|
+
>
|
|
49
|
+
<InlineTokens tokens={inlineTokens} theme={theme} />
|
|
50
|
+
</text>
|
|
51
|
+
</box>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ReactNode, RefObject } from "react";
|
|
2
|
+
import type { SyntaxStyle, TextBufferRenderable } from "@opentui/core";
|
|
3
|
+
import type { ResolvedTheme } from "@tooee/themes";
|
|
4
|
+
import { CodeBlock } from "../../code-blocks.js";
|
|
5
|
+
import type { CodeBlockRenderer } from "../../code-blocks.js";
|
|
6
|
+
import type { FlatBlock } from "../../markdown-blocks.js";
|
|
7
|
+
import { BlockquoteRenderer } from "./blockquote.js";
|
|
8
|
+
import { HeadingRenderer } from "./heading.js";
|
|
9
|
+
import { HorizontalRule } from "./horizontal-rule.js";
|
|
10
|
+
import { ListLineRenderer } from "./list-line.js";
|
|
11
|
+
import { ParagraphRenderer } from "./paragraph.js";
|
|
12
|
+
import { MarkdownTableRenderer } from "./table.js";
|
|
13
|
+
import type { MarkdownLinkHandler } from "../links.js";
|
|
14
|
+
import { hasMarkedText, narrowToken } from "../tokens.js";
|
|
15
|
+
|
|
16
|
+
type CodeBlockRendererRegistry = Record<string, CodeBlockRenderer>;
|
|
17
|
+
|
|
18
|
+
export const FlatBlockRenderer = function FlatBlockRenderer({
|
|
19
|
+
block,
|
|
20
|
+
blockIndex,
|
|
21
|
+
theme,
|
|
22
|
+
syntax,
|
|
23
|
+
contentWidth,
|
|
24
|
+
hScrollableBlocksRef,
|
|
25
|
+
codeBlockRenderers,
|
|
26
|
+
onLinkActivate,
|
|
27
|
+
imageBasePath,
|
|
28
|
+
}: {
|
|
29
|
+
block: FlatBlock;
|
|
30
|
+
blockIndex: number;
|
|
31
|
+
theme: ResolvedTheme;
|
|
32
|
+
syntax: SyntaxStyle;
|
|
33
|
+
contentWidth: number;
|
|
34
|
+
hScrollableBlocksRef?: RefObject<Map<number, TextBufferRenderable>>;
|
|
35
|
+
codeBlockRenderers?: CodeBlockRendererRegistry;
|
|
36
|
+
onLinkActivate?: MarkdownLinkHandler;
|
|
37
|
+
imageBasePath?: string;
|
|
38
|
+
}): ReactNode {
|
|
39
|
+
const { token, indent, bullet } = block;
|
|
40
|
+
|
|
41
|
+
if (bullet !== undefined) {
|
|
42
|
+
return <ListLineRenderer block={block} theme={theme} onLinkActivate={onLinkActivate} />;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const heading = narrowToken(token, "heading");
|
|
46
|
+
if (heading !== null) {
|
|
47
|
+
return (
|
|
48
|
+
<HeadingRenderer
|
|
49
|
+
token={heading}
|
|
50
|
+
theme={theme}
|
|
51
|
+
indent={indent}
|
|
52
|
+
onLinkActivate={onLinkActivate}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const paragraph = narrowToken(token, "paragraph");
|
|
57
|
+
if (paragraph !== null) {
|
|
58
|
+
return (
|
|
59
|
+
<ParagraphRenderer
|
|
60
|
+
token={paragraph}
|
|
61
|
+
theme={theme}
|
|
62
|
+
indent={indent}
|
|
63
|
+
onLinkActivate={onLinkActivate}
|
|
64
|
+
imageBasePath={imageBasePath}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const code = narrowToken(token, "code");
|
|
69
|
+
if (code !== null) {
|
|
70
|
+
return (
|
|
71
|
+
<CodeBlock
|
|
72
|
+
token={code}
|
|
73
|
+
blockIndex={blockIndex}
|
|
74
|
+
theme={theme}
|
|
75
|
+
syntax={syntax}
|
|
76
|
+
indent={indent}
|
|
77
|
+
contentWidth={contentWidth}
|
|
78
|
+
hScrollableBlocksRef={hScrollableBlocksRef}
|
|
79
|
+
renderers={codeBlockRenderers}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const blockquote = narrowToken(token, "blockquote");
|
|
84
|
+
if (blockquote !== null) {
|
|
85
|
+
return (
|
|
86
|
+
<BlockquoteRenderer
|
|
87
|
+
token={blockquote}
|
|
88
|
+
theme={theme}
|
|
89
|
+
indent={indent}
|
|
90
|
+
onLinkActivate={onLinkActivate}
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const table = narrowToken(token, "table");
|
|
95
|
+
if (table !== null) {
|
|
96
|
+
return <MarkdownTableRenderer token={table} indent={indent} />;
|
|
97
|
+
}
|
|
98
|
+
if (token.type === "hr") {
|
|
99
|
+
return <HorizontalRule theme={theme} indent={indent} />;
|
|
100
|
+
}
|
|
101
|
+
if (token.type === "space" || token.type === "html") {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (!hasMarkedText(token)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return (
|
|
108
|
+
<text
|
|
109
|
+
content={token.text}
|
|
110
|
+
style={{
|
|
111
|
+
fg: theme.markdownText,
|
|
112
|
+
marginBottom: 1,
|
|
113
|
+
marginLeft: 1 + indent,
|
|
114
|
+
marginRight: 1,
|
|
115
|
+
marginTop: 0,
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Tokens } from "marked";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { ResolvedTheme } from "@tooee/themes";
|
|
4
|
+
import { InlineTokens } from "../inline.js";
|
|
5
|
+
import { linkMouseHandler } from "../links.js";
|
|
6
|
+
import type { MarkdownLinkHandler } from "../links.js";
|
|
7
|
+
|
|
8
|
+
export const HeadingRenderer = function HeadingRenderer({
|
|
9
|
+
token,
|
|
10
|
+
theme,
|
|
11
|
+
indent,
|
|
12
|
+
onLinkActivate,
|
|
13
|
+
}: {
|
|
14
|
+
token: Tokens.Heading;
|
|
15
|
+
theme: ResolvedTheme;
|
|
16
|
+
indent: number;
|
|
17
|
+
onLinkActivate?: MarkdownLinkHandler;
|
|
18
|
+
}): ReactNode {
|
|
19
|
+
const headingColors = new Map<number, string>([
|
|
20
|
+
[1, theme.markdownHeading],
|
|
21
|
+
[2, theme.secondary],
|
|
22
|
+
[3, theme.accent],
|
|
23
|
+
[4, theme.text],
|
|
24
|
+
[5, theme.textMuted],
|
|
25
|
+
[6, theme.textMuted],
|
|
26
|
+
]);
|
|
27
|
+
const prefixes = new Map<number, string>([
|
|
28
|
+
[1, "# "],
|
|
29
|
+
[2, "## "],
|
|
30
|
+
[3, "### "],
|
|
31
|
+
[4, "#### "],
|
|
32
|
+
[5, "##### "],
|
|
33
|
+
[6, "###### "],
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<box style={{ marginBottom: 1, marginLeft: indent, marginTop: 1 }}>
|
|
38
|
+
<text
|
|
39
|
+
style={{ fg: headingColors.get(token.depth) ?? theme.text }}
|
|
40
|
+
onMouseDown={linkMouseHandler(
|
|
41
|
+
token.tokens,
|
|
42
|
+
onLinkActivate,
|
|
43
|
+
Bun.stringWidth(prefixes.get(token.depth) ?? ""),
|
|
44
|
+
)}
|
|
45
|
+
>
|
|
46
|
+
<span fg={theme.textMuted}>{prefixes.get(token.depth)}</span>
|
|
47
|
+
<strong>
|
|
48
|
+
<InlineTokens tokens={token.tokens} theme={theme} />
|
|
49
|
+
</strong>
|
|
50
|
+
</text>
|
|
51
|
+
</box>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ResolvedTheme } from "@tooee/themes";
|
|
3
|
+
|
|
4
|
+
export const HorizontalRule = function HorizontalRule({
|
|
5
|
+
theme,
|
|
6
|
+
indent,
|
|
7
|
+
}: {
|
|
8
|
+
theme: ResolvedTheme;
|
|
9
|
+
indent: number;
|
|
10
|
+
}): ReactNode {
|
|
11
|
+
return (
|
|
12
|
+
<box style={{ marginBottom: 1, marginLeft: 1 + indent, marginRight: 1, marginTop: 0 }}>
|
|
13
|
+
<text style={{ fg: theme.markdownHorizontalRule }} content={"─".repeat(40)} />
|
|
14
|
+
</box>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Token } from "marked";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { ResolvedTheme } from "@tooee/themes";
|
|
4
|
+
import { checkboxMarker } from "../../markdown-blocks.js";
|
|
5
|
+
import type { FlatBlock } from "../../markdown-blocks.js";
|
|
6
|
+
import { InlineTokens } from "../inline.js";
|
|
7
|
+
import { linkMouseHandler } from "../links.js";
|
|
8
|
+
import type { MarkdownLinkHandler } from "../links.js";
|
|
9
|
+
import { hasMarkedText } from "../tokens.js";
|
|
10
|
+
|
|
11
|
+
export const ListLineRenderer = function ListLineRenderer({
|
|
12
|
+
block,
|
|
13
|
+
theme,
|
|
14
|
+
onLinkActivate,
|
|
15
|
+
}: {
|
|
16
|
+
block: FlatBlock;
|
|
17
|
+
theme: ResolvedTheme;
|
|
18
|
+
onLinkActivate?: MarkdownLinkHandler;
|
|
19
|
+
}): ReactNode {
|
|
20
|
+
const { token, indent, bullet, checked } = block;
|
|
21
|
+
const checkboxPrefix = checkboxMarker(checked);
|
|
22
|
+
const inlineTokens: Token[] =
|
|
23
|
+
"tokens" in token && Array.isArray(token.tokens) ? token.tokens : [];
|
|
24
|
+
const tokenText = hasMarkedText(token) ? token.text : "";
|
|
25
|
+
const hasContent = inlineTokens.length > 0 || tokenText.length > 0;
|
|
26
|
+
|
|
27
|
+
let content: ReactNode = null;
|
|
28
|
+
if (inlineTokens.length > 0) {
|
|
29
|
+
content = <InlineTokens tokens={inlineTokens} theme={theme} />;
|
|
30
|
+
} else if (tokenText.length > 0) {
|
|
31
|
+
content = tokenText;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<box style={{ marginLeft: 1 + indent, marginRight: 1 }}>
|
|
36
|
+
<text
|
|
37
|
+
style={{ fg: theme.markdownText }}
|
|
38
|
+
onMouseDown={linkMouseHandler(
|
|
39
|
+
inlineTokens,
|
|
40
|
+
onLinkActivate,
|
|
41
|
+
Bun.stringWidth(`${bullet}${checkboxPrefix}`),
|
|
42
|
+
)}
|
|
43
|
+
>
|
|
44
|
+
<span fg={theme.markdownListItem}>{bullet}</span>
|
|
45
|
+
{checkboxPrefix !== "" && (
|
|
46
|
+
<span fg={checked === true ? theme.accent : theme.textMuted}>{checkboxPrefix}</span>
|
|
47
|
+
)}
|
|
48
|
+
{hasContent && content}
|
|
49
|
+
</text>
|
|
50
|
+
</box>
|
|
51
|
+
);
|
|
52
|
+
};
|