@tooee/view 0.1.22 → 0.2.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/README.md +67 -12
- package/dist/View.d.ts.map +1 -1
- package/dist/View.js +5 -1
- package/dist/View.js.map +1 -1
- package/dist/components/ViewScreen.d.ts +28 -0
- package/dist/components/ViewScreen.d.ts.map +1 -0
- package/dist/components/ViewScreen.js +29 -0
- package/dist/components/ViewScreen.js.map +1 -0
- package/dist/components/subviews/CodeSubview.d.ts +1 -1
- package/dist/components/subviews/CodeSubview.d.ts.map +1 -1
- package/dist/components/subviews/CodeSubview.js +20 -89
- package/dist/components/subviews/CodeSubview.js.map +1 -1
- package/dist/components/subviews/CustomSubview.d.ts +1 -1
- package/dist/components/subviews/CustomSubview.d.ts.map +1 -1
- package/dist/components/subviews/CustomSubview.js +19 -94
- package/dist/components/subviews/CustomSubview.js.map +1 -1
- package/dist/components/subviews/MarkdownSubview.d.ts +1 -1
- package/dist/components/subviews/MarkdownSubview.d.ts.map +1 -1
- package/dist/components/subviews/MarkdownSubview.js +32 -106
- package/dist/components/subviews/MarkdownSubview.js.map +1 -1
- package/dist/components/subviews/TableSubview.d.ts +1 -1
- package/dist/components/subviews/TableSubview.d.ts.map +1 -1
- package/dist/components/subviews/TableSubview.js +22 -123
- package/dist/components/subviews/TableSubview.js.map +1 -1
- package/dist/components/subviews/index.d.ts +0 -1
- package/dist/components/subviews/index.d.ts.map +1 -1
- package/dist/components/subviews/index.js +0 -1
- package/dist/components/subviews/index.js.map +1 -1
- package/dist/components/subviews/types.d.ts +6 -0
- package/dist/components/subviews/types.d.ts.map +1 -1
- package/dist/default-provider.d.ts +6 -3
- package/dist/default-provider.d.ts.map +1 -1
- package/dist/default-provider.js +24 -34
- package/dist/default-provider.js.map +1 -1
- package/dist/hooks/index.d.ts +2 -3
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useContentCommands.d.ts +15 -0
- package/dist/hooks/useContentCommands.d.ts.map +1 -0
- package/dist/hooks/useContentCommands.js +21 -0
- package/dist/hooks/useContentCommands.js.map +1 -0
- package/dist/hooks/useViewCommandContext.d.ts +10 -42
- package/dist/hooks/useViewCommandContext.d.ts.map +1 -1
- package/dist/hooks/useViewCommandContext.js +3 -30
- package/dist/hooks/useViewCommandContext.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +15 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +14 -14
- package/src/View.tsx +6 -1
- package/src/components/ViewScreen.tsx +76 -0
- package/src/components/subviews/CodeSubview.tsx +30 -120
- package/src/components/subviews/CustomSubview.tsx +32 -123
- package/src/components/subviews/MarkdownSubview.tsx +49 -130
- package/src/components/subviews/TableSubview.tsx +36 -164
- package/src/components/subviews/index.ts +0 -1
- package/src/components/subviews/types.ts +6 -0
- package/src/default-provider.ts +37 -34
- package/src/hooks/index.ts +2 -7
- package/src/hooks/useContentCommands.ts +29 -0
- package/src/hooks/useViewCommandContext.ts +13 -81
- package/src/index.ts +1 -1
- package/src/types.ts +15 -16
- package/dist/components/SubviewLayout.d.ts +0 -16
- package/dist/components/SubviewLayout.d.ts.map +0 -1
- package/dist/components/SubviewLayout.js +0 -18
- package/dist/components/SubviewLayout.js.map +0 -1
- package/dist/hooks/useMarkState.d.ts +0 -14
- package/dist/hooks/useMarkState.d.ts.map +0 -1
- package/dist/hooks/useMarkState.js +0 -71
- package/dist/hooks/useMarkState.js.map +0 -1
- package/dist/hooks/useViewCommands.d.ts +0 -13
- package/dist/hooks/useViewCommands.d.ts.map +0 -1
- package/dist/hooks/useViewCommands.js +0 -20
- package/dist/hooks/useViewCommands.js.map +0 -1
- package/src/components/SubviewLayout.tsx +0 -48
- package/src/hooks/useMarkState.ts +0 -100
- package/src/hooks/useViewCommands.ts +0 -36
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react"
|
|
2
|
-
import { MarkSetBuilder, createMarkState, MarkPriorities } from "@tooee/marks"
|
|
3
|
-
import type { MarkSet, MarkState } from "@tooee/marks"
|
|
4
|
-
import type { NavigationState } from "@tooee/shell"
|
|
5
|
-
import type { SearchState } from "@tooee/search"
|
|
6
|
-
import type { ResolvedTheme } from "@tooee/themes"
|
|
7
|
-
|
|
8
|
-
interface UseMarkStateParams {
|
|
9
|
-
nav: Pick<NavigationState, "cursor" | "selection" | "toggledIndices">
|
|
10
|
-
search: Pick<SearchState, "matchingLines" | "currentMatchIndex">
|
|
11
|
-
theme: ResolvedTheme
|
|
12
|
-
providerMarks: MarkSet[]
|
|
13
|
-
userMarks: MarkSet[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function useMarkState({
|
|
17
|
-
nav,
|
|
18
|
-
search,
|
|
19
|
-
theme,
|
|
20
|
-
providerMarks,
|
|
21
|
-
userMarks,
|
|
22
|
-
}: UseMarkStateParams): MarkState | undefined {
|
|
23
|
-
return useMemo(() => {
|
|
24
|
-
const sets: MarkSet[] = []
|
|
25
|
-
|
|
26
|
-
// Search matches
|
|
27
|
-
if (search.matchingLines.length > 0) {
|
|
28
|
-
const mapped = new Set(search.matchingLines)
|
|
29
|
-
const builder = new MarkSetBuilder()
|
|
30
|
-
for (const idx of mapped) {
|
|
31
|
-
builder.addLine(idx, {
|
|
32
|
-
background: theme.warning,
|
|
33
|
-
signBefore: "\u25CF",
|
|
34
|
-
foreground: theme.warning,
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
sets.push(builder.build("search", MarkPriorities.SEARCH_MATCH))
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Toggled lines
|
|
41
|
-
if (nav.toggledIndices.size > 0) {
|
|
42
|
-
const mapped = new Set(nav.toggledIndices)
|
|
43
|
-
const builder = new MarkSetBuilder()
|
|
44
|
-
for (const idx of mapped) {
|
|
45
|
-
builder.addLine(idx, { background: theme.backgroundPanel })
|
|
46
|
-
}
|
|
47
|
-
sets.push(builder.build("toggled", MarkPriorities.TOGGLED))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Selection range
|
|
51
|
-
if (nav.selection) {
|
|
52
|
-
const builder = new MarkSetBuilder()
|
|
53
|
-
builder.addRange(
|
|
54
|
-
{ line: nav.selection.start },
|
|
55
|
-
{ line: nav.selection.end },
|
|
56
|
-
{ background: theme.selection },
|
|
57
|
-
)
|
|
58
|
-
sets.push(builder.build("selection", MarkPriorities.SELECTION))
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Current match highlight
|
|
62
|
-
if (search.matchingLines.length > 0) {
|
|
63
|
-
const currentLine = search.matchingLines[search.currentMatchIndex]
|
|
64
|
-
if (currentLine != null) {
|
|
65
|
-
const builder = new MarkSetBuilder()
|
|
66
|
-
builder.addLine(currentLine, {
|
|
67
|
-
background: theme.primary,
|
|
68
|
-
signBefore: "\u25CF",
|
|
69
|
-
foreground: theme.primary,
|
|
70
|
-
})
|
|
71
|
-
sets.push(builder.build("currentMatch", MarkPriorities.CURRENT_MATCH))
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Cursor
|
|
76
|
-
if (nav.cursor !== null) {
|
|
77
|
-
const builder = new MarkSetBuilder()
|
|
78
|
-
builder.addLine(nav.cursor, {
|
|
79
|
-
background: theme.cursorLine,
|
|
80
|
-
signBefore: "\u25B8",
|
|
81
|
-
foreground: theme.primary,
|
|
82
|
-
})
|
|
83
|
-
sets.push(builder.build("cursor", MarkPriorities.CURSOR))
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Provider and user marks
|
|
87
|
-
sets.push(...providerMarks, ...userMarks)
|
|
88
|
-
|
|
89
|
-
return sets.length > 0 ? createMarkState(sets) : undefined
|
|
90
|
-
}, [
|
|
91
|
-
search.matchingLines,
|
|
92
|
-
search.currentMatchIndex,
|
|
93
|
-
nav.toggledIndices,
|
|
94
|
-
nav.selection,
|
|
95
|
-
nav.cursor,
|
|
96
|
-
theme,
|
|
97
|
-
providerMarks,
|
|
98
|
-
userMarks,
|
|
99
|
-
])
|
|
100
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useState } from "react"
|
|
2
|
-
import {
|
|
3
|
-
useThemeCommands,
|
|
4
|
-
useQuitCommand,
|
|
5
|
-
useCopyCommand,
|
|
6
|
-
useToggleLineNumbersCommand,
|
|
7
|
-
} from "@tooee/shell"
|
|
8
|
-
import { useActions } from "@tooee/commands"
|
|
9
|
-
import type { ActionDefinition } from "@tooee/commands"
|
|
10
|
-
import { useConfig } from "@tooee/config"
|
|
11
|
-
import type { AnyContent } from "../types.js"
|
|
12
|
-
|
|
13
|
-
interface UseViewCommandsParams {
|
|
14
|
-
content: AnyContent | null
|
|
15
|
-
textContent: string
|
|
16
|
-
actions?: ActionDefinition[]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function useViewCommands({ content, textContent, actions }: UseViewCommandsParams) {
|
|
20
|
-
const config = useConfig()
|
|
21
|
-
const [showLineNumbers, setShowLineNumbers] = useState(config.view?.gutter ?? true)
|
|
22
|
-
|
|
23
|
-
const { name: themeName } = useThemeCommands()
|
|
24
|
-
useQuitCommand()
|
|
25
|
-
useCopyCommand({
|
|
26
|
-
getText: () => (content ? textContent : undefined),
|
|
27
|
-
})
|
|
28
|
-
useToggleLineNumbersCommand({
|
|
29
|
-
showLineNumbers,
|
|
30
|
-
onToggle: () => setShowLineNumbers((v) => !v),
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
useActions(actions)
|
|
34
|
-
|
|
35
|
-
return { themeName, showLineNumbers }
|
|
36
|
-
}
|