-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportPanel.tsx
More file actions
161 lines (151 loc) · 5.09 KB
/
Copy pathExportPanel.tsx
File metadata and controls
161 lines (151 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* Export panel — right-side docked panel for the Export extension.
*
* Two sections: "This note" (export the active note as Markdown or
* styled HTML) and "All notes" (zip bundle or one combined HTML page),
* plus a live note/word count. Actions delegate to the command runners
* so panel and palette stay in lock-step.
*/
import { Download, FileArchive, FileCode, FileText } from "lucide-react"
import type { OpenNotesExtensionAPI } from "@/core/extensions/types"
import { cn } from "@/lib/utils"
import { copy } from "./copy"
import { countWords } from "./exportEngine"
import { runExport } from "./index"
interface ExportPanelProps {
api: OpenNotesExtensionAPI
}
function ExportActionButton({
icon: Icon,
label,
hint,
disabled,
onClick,
}: {
icon: typeof FileText
label: string
hint: string
disabled?: boolean
onClick: () => void
}) {
return (
<button
type="button"
disabled={disabled}
onClick={onClick}
className={cn(
"group flex w-full items-center gap-3 rounded-lg border border-border/60 bg-background/60 px-3 py-2.5 text-left transition-colors",
"hover:border-border hover:bg-accent/60",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50",
"disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:border-border/60 disabled:hover:bg-background/60"
)}
>
<span className="flex size-8 flex-none items-center justify-center rounded-md border border-border/50 bg-muted/50 text-muted-foreground transition-colors group-hover:text-foreground">
<Icon className="size-4" aria-hidden="true" />
</span>
<span className="min-w-0 flex-1">
<span className="block text-xs font-medium text-foreground">
{label}
</span>
<span className="block truncate text-[11px] text-muted-foreground">
{hint}
</span>
</span>
<Download
className="size-3.5 flex-none text-muted-foreground/60 transition-colors group-hover:text-foreground"
aria-hidden="true"
/>
</button>
)
}
function SectionHeading({
title,
description,
}: {
title: string
description: string
}) {
return (
<div className="space-y-0.5">
<h3 className="text-[11px] font-semibold uppercase tracking-wider text-muted-foreground">
{title}
</h3>
<p className="text-[11px] leading-relaxed text-muted-foreground/80">
{description}
</p>
</div>
)
}
export function ExportPanel({ api }: ExportPanelProps) {
const notes = api.getNotes()
const activeNote = api.getActiveNote()
const wordCount = notes.reduce((sum, note) => sum + countWords(note.content), 0)
const fire = (commandId: Parameters<typeof runExport>[0]) => {
void runExport(commandId, api)
}
return (
<div className="flex h-full flex-col gap-5 overflow-y-auto bg-background p-4">
{/* Workspace stats */}
<div className="rounded-lg border border-border/40 bg-muted/30 px-3 py-2">
<p className="text-[11px] font-medium text-muted-foreground">
{copy.panel.stats(notes.length, wordCount)}
</p>
</div>
{/* This note */}
<section className="space-y-2.5" aria-label={copy.panel.thisNoteHeading}>
<SectionHeading
title={copy.panel.thisNoteHeading}
description={copy.panel.thisNoteDescription}
/>
{activeNote ? (
<div className="space-y-2">
<ExportActionButton
icon={FileText}
label={copy.panel.markdownButton}
hint={copy.panel.markdownHint}
onClick={() => fire("note-md")}
/>
<ExportActionButton
icon={FileCode}
label={copy.panel.htmlButton}
hint={copy.panel.htmlHint}
onClick={() => fire("note-html")}
/>
</div>
) : (
<p className="rounded-lg border border-dashed border-border/60 bg-muted/20 px-3 py-3 text-[11px] text-muted-foreground">
{copy.panel.noActiveNote}
</p>
)}
</section>
<div className="border-t border-border/40" />
{/* All notes */}
<section className="space-y-2.5" aria-label={copy.panel.allNotesHeading}>
<SectionHeading
title={copy.panel.allNotesHeading}
description={copy.panel.allNotesDescription}
/>
{notes.length > 0 ? (
<div className="space-y-2">
<ExportActionButton
icon={FileArchive}
label={copy.panel.zipButton}
hint={copy.panel.zipHint}
onClick={() => fire("workspace-zip")}
/>
<ExportActionButton
icon={FileCode}
label={copy.panel.combinedHtmlButton}
hint={copy.panel.combinedHtmlHint}
onClick={() => fire("workspace-html")}
/>
</div>
) : (
<p className="rounded-lg border border-dashed border-border/60 bg-muted/20 px-3 py-3 text-[11px] text-muted-foreground">
{copy.panel.emptyWorkspace}
</p>
)}
</section>
</div>
)
}