@terrafirmagreg-team/ui 0.0.0-stage → 1.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/package.json +93 -3
- package/src/components/blocks/button/icon-button.tsx +49 -0
- package/src/components/blocks/canvas/chevron-edge.tsx +242 -0
- package/src/components/blocks/canvas/flow-canvas.tsx +181 -0
- package/src/components/blocks/canvas/flow-toolbar.tsx +33 -0
- package/src/components/blocks/canvas/flow-viewport.tsx +244 -0
- package/src/components/blocks/fit-box.tsx +26 -0
- package/src/components/blocks/git/github-info.tsx +78 -0
- package/src/components/blocks/lang/content.tsx +52 -0
- package/src/components/blocks/lang/flag.tsx +25 -0
- package/src/components/blocks/lang/link.tsx +23 -0
- package/src/components/blocks/lang/redirect.tsx +48 -0
- package/src/components/blocks/lang/switcher.tsx +54 -0
- package/src/components/blocks/lang/untranslated-callout.tsx +29 -0
- package/src/components/blocks/lang/untranslated-chip.tsx +53 -0
- package/src/components/blocks/link/link-preview.tsx +257 -0
- package/src/components/blocks/list/row.tsx +92 -0
- package/src/components/blocks/media/glb/model.tsx +244 -0
- package/src/components/blocks/media/glb/scene.tsx +373 -0
- package/src/components/blocks/media/glb/viewer.tsx +52 -0
- package/src/components/blocks/media/image.tsx +136 -0
- package/src/components/blocks/media/slideshow.tsx +178 -0
- package/src/components/blocks/nav/breadcrumb.tsx +51 -0
- package/src/components/blocks/nav/copy-menu.tsx +37 -0
- package/src/components/blocks/nav/link.tsx +86 -0
- package/src/components/blocks/nav/site-menu.tsx +78 -0
- package/src/components/blocks/nav/site-title.tsx +61 -0
- package/src/components/blocks/nav/switcher.tsx +206 -0
- package/src/components/blocks/page/empty-state.tsx +32 -0
- package/src/components/blocks/page/heading.tsx +54 -0
- package/src/components/blocks/page/pager.tsx +220 -0
- package/src/components/blocks/readability/fields.tsx +250 -0
- package/src/components/blocks/readability/menu.tsx +247 -0
- package/src/components/blocks/readability/track.tsx +165 -0
- package/src/components/blocks/search/command.tsx +80 -0
- package/src/components/blocks/search/dialog.tsx +724 -0
- package/src/components/blocks/search/provider.tsx +118 -0
- package/src/components/blocks/sidebar.tsx +406 -0
- package/src/components/blocks/sprite.tsx +231 -0
- package/src/components/blocks/text/format-text.tsx +110 -0
- package/src/components/blocks/theme/toggle.tsx +75 -0
- package/src/components/blocks/tooltip/hint.tsx +28 -0
- package/src/components/blocks/tooltip/lazy.tsx +41 -0
- package/src/components/blocks/viewer/controls.tsx +284 -0
- package/src/components/blocks/viewer/float-bar.tsx +51 -0
- package/src/components/layouts/layout.tsx +94 -0
- package/src/components/layouts/left-sidebar/content.tsx +63 -0
- package/src/components/layouts/left-sidebar/context.tsx +55 -0
- package/src/components/layouts/left-sidebar/expand.tsx +23 -0
- package/src/components/layouts/left-sidebar/footer.tsx +111 -0
- package/src/components/layouts/left-sidebar/index.ts +29 -0
- package/src/components/layouts/left-sidebar/items.tsx +103 -0
- package/src/components/layouts/left-sidebar/search.tsx +75 -0
- package/src/components/layouts/left-sidebar/sidebar.tsx +189 -0
- package/src/components/layouts/left-sidebar/tree.tsx +157 -0
- package/src/components/layouts/right-sidebar.tsx +96 -0
- package/src/components/layouts/tree-context.tsx +42 -0
- package/src/components/mdx/accordion.tsx +185 -0
- package/src/components/mdx/banner.tsx +157 -0
- package/src/components/mdx/callout.tsx +97 -0
- package/src/components/mdx/card.tsx +56 -0
- package/src/components/mdx/codeblock.tsx +250 -0
- package/src/components/mdx/collapsible.tsx +33 -0
- package/src/components/mdx/files.tsx +63 -0
- package/src/components/mdx/glow-header.tsx +54 -0
- package/src/components/mdx/gradient-text.tsx +28 -0
- package/src/components/mdx/icon.tsx +35 -0
- package/src/components/mdx/image-zoom.tsx +315 -0
- package/src/components/mdx/math.tsx +30 -0
- package/src/components/mdx/mermaid.tsx +23 -0
- package/src/components/mdx/multiblock.tsx +19 -0
- package/src/components/mdx/preview.tsx +101 -0
- package/src/components/mdx/steps.tsx +10 -0
- package/src/components/mdx/table.tsx +14 -0
- package/src/components/mdx/tabs.tsx +354 -0
- package/src/components/mdx/type-table.tsx +171 -0
- package/src/components/provider.tsx +139 -0
- package/src/components/ui/accordion.tsx +71 -0
- package/src/components/ui/alert-dialog.tsx +187 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/attachment.tsx +207 -0
- package/src/components/ui/avatar.tsx +108 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +124 -0
- package/src/components/ui/bubble.tsx +127 -0
- package/src/components/ui/button-group.tsx +87 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/calendar.tsx +221 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +242 -0
- package/src/components/ui/chart.tsx +371 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/collapsible.tsx +21 -0
- package/src/components/ui/combobox.tsx +297 -0
- package/src/components/ui/command.tsx +198 -0
- package/src/components/ui/context-menu.tsx +270 -0
- package/src/components/ui/dialog.tsx +160 -0
- package/src/components/ui/direction.tsx +6 -0
- package/src/components/ui/drawer.tsx +227 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +103 -0
- package/src/components/ui/field.tsx +238 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +158 -0
- package/src/components/ui/input-otp.tsx +86 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +201 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/marker.tsx +70 -0
- package/src/components/ui/menubar.tsx +280 -0
- package/src/components/ui/message-scroller.tsx +131 -0
- package/src/components/ui/message.tsx +91 -0
- package/src/components/ui/native-select.tsx +60 -0
- package/src/components/ui/navigation-menu.tsx +167 -0
- package/src/components/ui/pagination.tsx +130 -0
- package/src/components/ui/popover.tsx +91 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/questionnaire.tsx +324 -0
- package/src/components/ui/radio-group.tsx +37 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +54 -0
- package/src/components/ui/select.tsx +200 -0
- package/src/components/ui/separator.tsx +24 -0
- package/src/components/ui/sheet.tsx +138 -0
- package/src/components/ui/sidebar.tsx +730 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/spinner.tsx +10 -0
- package/src/components/ui/switch.tsx +31 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +81 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toast.tsx +234 -0
- package/src/components/ui/toggle-group.tsx +89 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +65 -0
- package/src/hooks/canvas/use-flow-hover.ts +19 -0
- package/src/hooks/canvas/use-flow-viewport-persist.ts +34 -0
- package/src/hooks/page/use-fit-pages.ts +92 -0
- package/src/hooks/page/use-location-search.ts +31 -0
- package/src/hooks/page/use-page-preview.ts +41 -0
- package/src/hooks/page/use-paged-list.ts +21 -0
- package/src/hooks/readability/use-readability.ts +87 -0
- package/src/hooks/search/use-dialog.ts +42 -0
- package/src/hooks/search/use-highlight-query.ts +58 -0
- package/src/hooks/search/use-provider.ts +26 -0
- package/src/hooks/use-async-value.ts +60 -0
- package/src/hooks/use-close-on-scroll.ts +24 -0
- package/src/hooks/use-copy-button.ts +47 -0
- package/src/hooks/use-cycle-index.ts +76 -0
- package/src/hooks/use-document-title.ts +10 -0
- package/src/hooks/use-element-size.ts +36 -0
- package/src/hooks/use-external-meta.ts +133 -0
- package/src/hooks/use-hot-key.ts +34 -0
- package/src/hooks/use-hover-follow.ts +55 -0
- package/src/hooks/use-in-view.ts +31 -0
- package/src/hooks/use-lang.ts +9 -0
- package/src/hooks/use-last-value.ts +16 -0
- package/src/hooks/use-layout.ts +19 -0
- package/src/hooks/use-marquee.ts +52 -0
- package/src/hooks/use-media-query.ts +15 -0
- package/src/hooks/use-mobile.ts +20 -0
- package/src/hooks/use-modifier-keys.ts +32 -0
- package/src/hooks/use-on-change.ts +36 -0
- package/src/hooks/use-pane-keys.ts +29 -0
- package/src/hooks/use-sidebar.ts +64 -0
- package/src/hooks/use-swipe.ts +27 -0
- package/src/hooks/use-tree.ts +100 -0
- package/src/hooks/viewer/use-in-float-bar.ts +7 -0
- package/src/hooks/viewer/use-viewer-prefs.ts +78 -0
- package/src/lib/canvas/edge.ts +202 -0
- package/src/lib/canvas/geometry.ts +54 -0
- package/src/lib/canvas/state.ts +48 -0
- package/src/lib/canvas/viewport.ts +38 -0
- package/src/lib/canvas/xyflow.ts +2 -0
- package/src/lib/config.ts +106 -0
- package/src/lib/mdx/callout.ts +21 -0
- package/src/lib/mdx/gradient.ts +16 -0
- package/src/lib/mdx/mermaid.ts +15 -0
- package/src/lib/media/crop-opaque.ts +77 -0
- package/src/lib/media/nearby-indexes.ts +7 -0
- package/src/lib/media/trim-transparent.ts +118 -0
- package/src/lib/readability/config.ts +11 -0
- package/src/lib/readability/spotlight.ts +187 -0
- package/src/lib/readability/store.ts +147 -0
- package/src/lib/tree.ts +90 -0
- package/src/lib/utils/cn.ts +2 -0
- package/src/lib/utils/format.ts +22 -0
- package/src/lib/utils/highlight-style.ts +10 -0
- package/src/lib/utils/history.ts +10 -0
- package/src/lib/utils/merge-refs.ts +14 -0
- package/src/lib/utils/nav-active.ts +59 -0
- package/src/lib/utils/stored-value.ts +137 -0
- package/src/lib/utils/urls.ts +18 -0
- package/src/locales/en_us.json +110 -0
- package/src/locales/pl_pl.json +33 -0
- package/src/locales/ru_ru.json +110 -0
- package/src/locales/uk_ua.json +33 -0
- package/src/locales/zh_cn.json +15 -0
- package/src/locales/zh_tw.json +15 -0
- package/src/locales.ts +6 -0
- package/src/types/canvas.ts +54 -0
- package/src/types/glb.ts +26 -0
- package/src/types/mdx-directives.ts +106 -0
- package/src/types/nav.ts +96 -0
- package/src/types/preview.ts +15 -0
- package/src/types/readability.ts +29 -0
- package/src/types/search.ts +57 -0
- package/src/types/tree.ts +19 -0
- package/src/types/viewer.ts +54 -0
- package/styles/content/base.css +198 -0
- package/styles/content/default-colors.css +51 -0
- package/styles/content/shiki.css +107 -0
- package/styles/content/typography.mjs +3637 -0
- package/styles/content.css +5 -0
- package/styles/image-zoom.css +83 -0
- package/styles/layout.css +28 -0
- package/styles/left-sidebar.css +140 -0
- package/styles/readability.css +50 -0
- package/styles/right-sidebar.css +6 -0
- package/styles/workspace.css +26 -0
- package/styles.css +430 -0
- package/README.md +0 -3
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState, type ReactNode } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
ChevronLeft,
|
|
6
|
+
ChevronRight,
|
|
7
|
+
Expand,
|
|
8
|
+
Maximize2,
|
|
9
|
+
Settings2,
|
|
10
|
+
Shrink,
|
|
11
|
+
ZoomIn,
|
|
12
|
+
ZoomOut,
|
|
13
|
+
} from 'lucide-react';
|
|
14
|
+
import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
|
|
15
|
+
import { ButtonGroupText } from '@terrafirmagreg-team/ui/components/ui/button-group';
|
|
16
|
+
import { useInFloatBar } from '@terrafirmagreg-team/ui/hooks/viewer/use-in-float-bar';
|
|
17
|
+
import { FloatBar } from '@terrafirmagreg-team/ui/components/blocks/viewer/float-bar';
|
|
18
|
+
import {
|
|
19
|
+
Popover,
|
|
20
|
+
PopoverContent,
|
|
21
|
+
PopoverTrigger,
|
|
22
|
+
} from '@terrafirmagreg-team/ui/components/ui/popover';
|
|
23
|
+
import {
|
|
24
|
+
Field,
|
|
25
|
+
FieldContent,
|
|
26
|
+
FieldGroup,
|
|
27
|
+
FieldLabel,
|
|
28
|
+
} from '@terrafirmagreg-team/ui/components/ui/field';
|
|
29
|
+
import { Slider } from '@terrafirmagreg-team/ui/components/ui/slider';
|
|
30
|
+
import { Switch } from '@terrafirmagreg-team/ui/components/ui/switch';
|
|
31
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
32
|
+
import type {
|
|
33
|
+
ExpandButtonProps,
|
|
34
|
+
PagerControlsProps,
|
|
35
|
+
ViewerControlsProps,
|
|
36
|
+
ViewerSettingsProps,
|
|
37
|
+
ViewerSliderSetting,
|
|
38
|
+
ZoomControlsProps,
|
|
39
|
+
} from '@terrafirmagreg-team/ui/types/viewer';
|
|
40
|
+
|
|
41
|
+
export function ViewerToolbar({ children }: { children: ReactNode }) {
|
|
42
|
+
return (
|
|
43
|
+
<div className="absolute right-2 top-2 z-10">
|
|
44
|
+
<FloatBar>{children}</FloatBar>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function ViewerZoomControls({
|
|
50
|
+
onZoomIn,
|
|
51
|
+
onZoomOut,
|
|
52
|
+
onFit,
|
|
53
|
+
fitLabel,
|
|
54
|
+
}: ZoomControlsProps) {
|
|
55
|
+
const t = useTranslations();
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<IconButton overlay label={t('Zoom in', { note: 'ui.canvas.zoom_in' })} onClick={onZoomIn}>
|
|
59
|
+
<ZoomIn className="size-3.5" />
|
|
60
|
+
</IconButton>
|
|
61
|
+
<IconButton overlay label={t('Zoom out', { note: 'ui.canvas.zoom_out' })} onClick={onZoomOut}>
|
|
62
|
+
<ZoomOut className="size-3.5" />
|
|
63
|
+
</IconButton>
|
|
64
|
+
{onFit ? (
|
|
65
|
+
<IconButton
|
|
66
|
+
overlay
|
|
67
|
+
label={fitLabel ?? t('Fit view', { note: 'ui.canvas.fit' })}
|
|
68
|
+
onClick={onFit}
|
|
69
|
+
>
|
|
70
|
+
<Maximize2 className="size-3.5" />
|
|
71
|
+
</IconButton>
|
|
72
|
+
) : null}
|
|
73
|
+
</>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function ViewerPagerControls({
|
|
78
|
+
index,
|
|
79
|
+
count,
|
|
80
|
+
onSelect,
|
|
81
|
+
}: PagerControlsProps) {
|
|
82
|
+
const t = useTranslations();
|
|
83
|
+
const inFloatBar = useInFloatBar();
|
|
84
|
+
return (
|
|
85
|
+
<>
|
|
86
|
+
<IconButton
|
|
87
|
+
overlay
|
|
88
|
+
label={t('Previous', { note: 'ui.canvas.prev' })}
|
|
89
|
+
disabled={index === 0}
|
|
90
|
+
onClick={() => onSelect(index - 1)}
|
|
91
|
+
>
|
|
92
|
+
<ChevronLeft className="size-3.5" />
|
|
93
|
+
</IconButton>
|
|
94
|
+
<ButtonGroupText
|
|
95
|
+
className={
|
|
96
|
+
inFloatBar
|
|
97
|
+
? 'border-0 bg-transparent text-xs'
|
|
98
|
+
: 'bg-float/92 text-xs backdrop-blur-md'
|
|
99
|
+
}
|
|
100
|
+
>
|
|
101
|
+
{index + 1} / {count}
|
|
102
|
+
</ButtonGroupText>
|
|
103
|
+
<IconButton
|
|
104
|
+
overlay
|
|
105
|
+
label={t('Next', { note: 'ui.canvas.next' })}
|
|
106
|
+
disabled={index === count - 1}
|
|
107
|
+
onClick={() => onSelect(index + 1)}
|
|
108
|
+
>
|
|
109
|
+
<ChevronRight className="size-3.5" />
|
|
110
|
+
</IconButton>
|
|
111
|
+
</>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function ViewerExpandButton({ target }: ExpandButtonProps) {
|
|
116
|
+
const t = useTranslations();
|
|
117
|
+
const [active, setActive] = useState(false);
|
|
118
|
+
const [fallback, setFallback] = useState(false);
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const onChange = () =>
|
|
122
|
+
setActive(document.fullscreenElement === target.current);
|
|
123
|
+
document.addEventListener('fullscreenchange', onChange);
|
|
124
|
+
return () => document.removeEventListener('fullscreenchange', onChange);
|
|
125
|
+
}, [target]);
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
const el = target.current;
|
|
129
|
+
if (!fallback || !el) return;
|
|
130
|
+
el.classList.add('viewer-fallback-fullscreen');
|
|
131
|
+
const previousOverflow = document.body.style.overflow;
|
|
132
|
+
document.body.style.overflow = 'hidden';
|
|
133
|
+
const onKey = (event: KeyboardEvent) => {
|
|
134
|
+
if (event.key === 'Escape') setFallback(false);
|
|
135
|
+
};
|
|
136
|
+
document.addEventListener('keydown', onKey);
|
|
137
|
+
return () => {
|
|
138
|
+
el.classList.remove('viewer-fallback-fullscreen');
|
|
139
|
+
document.body.style.overflow = previousOverflow;
|
|
140
|
+
document.removeEventListener('keydown', onKey);
|
|
141
|
+
};
|
|
142
|
+
}, [fallback, target]);
|
|
143
|
+
|
|
144
|
+
const expanded = active || fallback;
|
|
145
|
+
return (
|
|
146
|
+
<IconButton
|
|
147
|
+
overlay
|
|
148
|
+
aria-expanded={expanded}
|
|
149
|
+
label={
|
|
150
|
+
expanded
|
|
151
|
+
? t('Exit fullscreen', { note: 'ui.canvas.exit_fullscreen' })
|
|
152
|
+
: t('Fullscreen', { note: 'ui.canvas.fullscreen' })
|
|
153
|
+
}
|
|
154
|
+
onClick={() => {
|
|
155
|
+
const el = target.current;
|
|
156
|
+
if (fallback) {
|
|
157
|
+
setFallback(false);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!el) return;
|
|
161
|
+
if (document.fullscreenElement) {
|
|
162
|
+
void document.exitFullscreen();
|
|
163
|
+
} else if (el.requestFullscreen) {
|
|
164
|
+
void el.requestFullscreen().catch(() => setFallback(true));
|
|
165
|
+
} else {
|
|
166
|
+
setFallback(true);
|
|
167
|
+
}
|
|
168
|
+
}}
|
|
169
|
+
>
|
|
170
|
+
{expanded ? (
|
|
171
|
+
<Shrink className="size-3.5" />
|
|
172
|
+
) : (
|
|
173
|
+
<Expand className="size-3.5" />
|
|
174
|
+
)}
|
|
175
|
+
</IconButton>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function ViewerSlider({
|
|
180
|
+
label,
|
|
181
|
+
icon,
|
|
182
|
+
value,
|
|
183
|
+
onChange,
|
|
184
|
+
min = 0,
|
|
185
|
+
max = 100,
|
|
186
|
+
step = 1,
|
|
187
|
+
format = String,
|
|
188
|
+
disabled,
|
|
189
|
+
live,
|
|
190
|
+
}: ViewerSliderSetting) {
|
|
191
|
+
const [draft, setDraft] = useState<{ key: number; value: number }>({
|
|
192
|
+
key: value,
|
|
193
|
+
value,
|
|
194
|
+
});
|
|
195
|
+
const shown = draft.key === value ? draft.value : value;
|
|
196
|
+
return (
|
|
197
|
+
<Field className="gap-1.5">
|
|
198
|
+
<FieldLabel className="text-xs text-muted-foreground">
|
|
199
|
+
{icon}
|
|
200
|
+
{label}
|
|
201
|
+
</FieldLabel>
|
|
202
|
+
<FieldContent className="rounded-lg bg-muted/70 px-3 py-2.5">
|
|
203
|
+
<div className="flex items-center gap-3">
|
|
204
|
+
<Slider
|
|
205
|
+
min={min}
|
|
206
|
+
max={max}
|
|
207
|
+
step={step}
|
|
208
|
+
value={shown}
|
|
209
|
+
disabled={disabled}
|
|
210
|
+
className="flex-1 [&_[data-slot=slider-track]]:bg-muted-foreground/25"
|
|
211
|
+
onValueChange={(next) => {
|
|
212
|
+
if (live) onChange(next as number);
|
|
213
|
+
else setDraft({ key: value, value: next as number });
|
|
214
|
+
}}
|
|
215
|
+
onValueCommitted={() => {
|
|
216
|
+
if (!live && shown !== value) onChange(shown);
|
|
217
|
+
}}
|
|
218
|
+
/>
|
|
219
|
+
<span className="w-9 shrink-0 text-end text-xs tabular-nums text-muted-foreground">
|
|
220
|
+
{format(shown)}
|
|
221
|
+
</span>
|
|
222
|
+
</div>
|
|
223
|
+
</FieldContent>
|
|
224
|
+
</Field>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function ViewerSettings({
|
|
229
|
+
label,
|
|
230
|
+
sliders,
|
|
231
|
+
toggles,
|
|
232
|
+
}: ViewerSettingsProps) {
|
|
233
|
+
if (!sliders?.length && !toggles?.length) return null;
|
|
234
|
+
return (
|
|
235
|
+
<Popover>
|
|
236
|
+
<PopoverTrigger render={<IconButton overlay label={label} />}>
|
|
237
|
+
<Settings2 className="size-3.5" />
|
|
238
|
+
</PopoverTrigger>
|
|
239
|
+
<PopoverContent side="bottom" align="end" className="w-60 space-y-3 p-3">
|
|
240
|
+
{sliders?.map((slider, index) => (
|
|
241
|
+
<ViewerSlider key={index} {...slider} />
|
|
242
|
+
))}
|
|
243
|
+
{toggles?.length ? (
|
|
244
|
+
<FieldGroup className="gap-1.5 rounded-lg bg-muted/60 p-2">
|
|
245
|
+
{toggles.map((toggle, index) => (
|
|
246
|
+
<Field key={index} orientation="horizontal" className="w-auto gap-1.5">
|
|
247
|
+
<Switch
|
|
248
|
+
size="sm"
|
|
249
|
+
checked={toggle.checked}
|
|
250
|
+
onCheckedChange={toggle.onChange}
|
|
251
|
+
/>
|
|
252
|
+
{toggle.icon}
|
|
253
|
+
<FieldLabel className="text-sm font-normal">
|
|
254
|
+
{toggle.label}
|
|
255
|
+
</FieldLabel>
|
|
256
|
+
</Field>
|
|
257
|
+
))}
|
|
258
|
+
</FieldGroup>
|
|
259
|
+
) : null}
|
|
260
|
+
</PopoverContent>
|
|
261
|
+
</Popover>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function ViewerControls({
|
|
266
|
+
start,
|
|
267
|
+
pager,
|
|
268
|
+
zoom,
|
|
269
|
+
expand,
|
|
270
|
+
extra,
|
|
271
|
+
settings,
|
|
272
|
+
}: ViewerControlsProps) {
|
|
273
|
+
return (
|
|
274
|
+
<>
|
|
275
|
+
{start}
|
|
276
|
+
{pager ? <ViewerPagerControls {...pager} /> : null}
|
|
277
|
+
{zoom ? <ViewerZoomControls {...zoom} /> : null}
|
|
278
|
+
{expand ? <ViewerExpandButton {...expand} /> : null}
|
|
279
|
+
{extra}
|
|
280
|
+
{settings ? <ViewerSettings {...settings} /> : null}
|
|
281
|
+
</>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
3
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
4
|
+
|
|
5
|
+
import { FloatBarContext } from '@terrafirmagreg-team/ui/hooks/viewer/use-in-float-bar';
|
|
6
|
+
|
|
7
|
+
export function FloatBar({ className, children, ...props }: ComponentProps<'div'>) {
|
|
8
|
+
return (
|
|
9
|
+
<FloatBarContext.Provider value>
|
|
10
|
+
<div
|
|
11
|
+
role="group"
|
|
12
|
+
data-slot="float-bar"
|
|
13
|
+
className={cn(
|
|
14
|
+
'flex h-7 items-stretch overflow-hidden rounded-lg bg-float/92 shadow-sm ring-1 ring-foreground/10 backdrop-blur-md',
|
|
15
|
+
className,
|
|
16
|
+
)}
|
|
17
|
+
{...props}
|
|
18
|
+
>
|
|
19
|
+
{children}
|
|
20
|
+
</div>
|
|
21
|
+
</FloatBarContext.Provider>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function FloatBarItem({
|
|
26
|
+
label,
|
|
27
|
+
className,
|
|
28
|
+
children,
|
|
29
|
+
}: {
|
|
30
|
+
label?: ReactNode;
|
|
31
|
+
className?: string;
|
|
32
|
+
children?: ReactNode;
|
|
33
|
+
}) {
|
|
34
|
+
return (
|
|
35
|
+
<span
|
|
36
|
+
data-slot="float-bar-item"
|
|
37
|
+
className={cn(
|
|
38
|
+
'inline-flex items-center justify-center gap-1 px-3 font-mono text-[11.5px] leading-none whitespace-pre text-foreground',
|
|
39
|
+
className,
|
|
40
|
+
)}
|
|
41
|
+
>
|
|
42
|
+
{label != null && (
|
|
43
|
+
<span className="text-[9px] font-semibold uppercase tracking-[0.06em] text-foreground/65">
|
|
44
|
+
{label}
|
|
45
|
+
</span>
|
|
46
|
+
)}
|
|
47
|
+
{children}
|
|
48
|
+
</span>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
useMemo,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
type ComponentType,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import type * as PageTree from '@terrafirmagreg-team/translate/types/tree';
|
|
9
|
+
import Link from '@terrafirmagreg-team/ui/components/blocks/nav/link';
|
|
10
|
+
import { SidebarIcon } from 'lucide-react';
|
|
11
|
+
|
|
12
|
+
import { LayoutContext, useLayout } from '@terrafirmagreg-team/ui/hooks/use-layout';
|
|
13
|
+
import { TreeContextProvider } from '@terrafirmagreg-team/ui/components/layouts/tree-context';
|
|
14
|
+
import {
|
|
15
|
+
SidebarProvider,
|
|
16
|
+
SidebarTrigger,
|
|
17
|
+
} from '@terrafirmagreg-team/ui/components/blocks/sidebar';
|
|
18
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
19
|
+
import { buttonVariants } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
20
|
+
import { RightSidebar } from '@terrafirmagreg-team/ui/components/layouts/right-sidebar';
|
|
21
|
+
import {
|
|
22
|
+
LeftSidebarPortalProvider,
|
|
23
|
+
LeftSidebarSearch,
|
|
24
|
+
} from '@terrafirmagreg-team/ui/components/layouts/left-sidebar';
|
|
25
|
+
|
|
26
|
+
export type LayoutProps = {
|
|
27
|
+
tree: PageTree.Root;
|
|
28
|
+
|
|
29
|
+
sidebar?: ReactNode;
|
|
30
|
+
navTitle?: ComponentType<ComponentProps<'a'>>;
|
|
31
|
+
header?: ReactNode;
|
|
32
|
+
children?: ReactNode;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const EmptyTitle: ComponentType<ComponentProps<'a'>> = (props) => (
|
|
36
|
+
<Link href="/" {...props} />
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export function Layout({
|
|
40
|
+
tree,
|
|
41
|
+
sidebar,
|
|
42
|
+
navTitle: Title = EmptyTitle,
|
|
43
|
+
header = <LayoutHeader />,
|
|
44
|
+
children,
|
|
45
|
+
}: LayoutProps) {
|
|
46
|
+
return (
|
|
47
|
+
<LayoutContext value={useMemo(() => ({ navTitle: Title }), [Title])}>
|
|
48
|
+
<TreeContextProvider tree={tree}>
|
|
49
|
+
<SidebarProvider>
|
|
50
|
+
<LeftSidebarPortalProvider>
|
|
51
|
+
<div
|
|
52
|
+
id="spacious-layout"
|
|
53
|
+
data-slot="layout"
|
|
54
|
+
className="relative grid min-h-(--layout-height) bg-card transition-[grid-template-columns] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none [--layout-height:calc(100dvh_-_var(--banner-height,0px))] [--header-height:--spacing(14)] [--page-width:100%] [--sidebar-width:0px] [--sidebar-col:var(--sidebar-width)] [--toc-width:0px] max-md:[--docs-row-3:calc(var(--banner-height,0px)+var(--header-height)+var(--toc-popover-height,0px))] md:h-(--layout-height) md:overflow-clip print:h-auto print:overflow-visible"
|
|
55
|
+
style={{
|
|
56
|
+
gridTemplate: `"sidebar header right" auto
|
|
57
|
+
"sidebar toc-popover right" var(--toc-popover-height, 0px)
|
|
58
|
+
"sidebar main right" 1fr / var(--sidebar-col) minmax(0, 1fr) auto`,
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
{sidebar}
|
|
62
|
+
{header}
|
|
63
|
+
<RightSidebar>{children}</RightSidebar>
|
|
64
|
+
</div>
|
|
65
|
+
</LeftSidebarPortalProvider>
|
|
66
|
+
</SidebarProvider>
|
|
67
|
+
</TreeContextProvider>
|
|
68
|
+
</LayoutContext>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function LayoutHeader({ className, ...props }: ComponentProps<'header'>) {
|
|
73
|
+
const { navTitle: Title } = useLayout();
|
|
74
|
+
return (
|
|
75
|
+
<header
|
|
76
|
+
id="subnav"
|
|
77
|
+
data-slot="layout-header"
|
|
78
|
+
className={cn(
|
|
79
|
+
'sticky top-(--banner-height,0px) z-30 [grid-area:header] flex items-center h-(--header-height) ps-4 pe-2.5 bg-card md:hidden',
|
|
80
|
+
className,
|
|
81
|
+
)}
|
|
82
|
+
{...props}
|
|
83
|
+
>
|
|
84
|
+
<Title className="inline-flex items-center gap-2.5 me-auto font-semibold" />
|
|
85
|
+
<LeftSidebarSearch variant="icon" />
|
|
86
|
+
<SidebarTrigger
|
|
87
|
+
className={buttonVariants({ variant: 'ghost', size: 'icon-sm', className: 'p-2' })}
|
|
88
|
+
>
|
|
89
|
+
<SidebarIcon />
|
|
90
|
+
</SidebarTrigger>
|
|
91
|
+
</header>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
3
|
+
import type { ComponentProps } from 'react';
|
|
4
|
+
import { ScrollArea } from '@base-ui/react/scroll-area';
|
|
5
|
+
import { useHoverFollow } from '@terrafirmagreg-team/ui/hooks/use-hover-follow';
|
|
6
|
+
import type { NavItemMatch } from '@terrafirmagreg-team/ui/lib/utils/nav-active';
|
|
7
|
+
import { LeftSidebarPortalTarget } from './context';
|
|
8
|
+
import { LeftSidebarTree } from './tree';
|
|
9
|
+
|
|
10
|
+
export function LeftSidebarContent({
|
|
11
|
+
children,
|
|
12
|
+
match,
|
|
13
|
+
navKeys,
|
|
14
|
+
className,
|
|
15
|
+
viewportClassName,
|
|
16
|
+
...props
|
|
17
|
+
}: ComponentProps<'div'> & {
|
|
18
|
+
match?: NavItemMatch;
|
|
19
|
+
navKeys?: ReadonlySet<string>;
|
|
20
|
+
viewportClassName?: string;
|
|
21
|
+
}) {
|
|
22
|
+
return (
|
|
23
|
+
<ScrollArea.Root
|
|
24
|
+
data-slot="left-sidebar-content"
|
|
25
|
+
className={cn('relative min-h-0 flex-1', className)}
|
|
26
|
+
{...props}
|
|
27
|
+
>
|
|
28
|
+
<ScrollArea.Viewport
|
|
29
|
+
data-slot="left-sidebar-viewport"
|
|
30
|
+
className={cn(
|
|
31
|
+
'size-full overscroll-contain px-3 py-2 mask-[linear-gradient(to_bottom,transparent,white_12px,white_calc(100%-12px),transparent)]',
|
|
32
|
+
viewportClassName,
|
|
33
|
+
)}
|
|
34
|
+
>
|
|
35
|
+
<nav
|
|
36
|
+
ref={useHoverFollow()}
|
|
37
|
+
className="relative flex flex-col gap-1"
|
|
38
|
+
>
|
|
39
|
+
<div
|
|
40
|
+
aria-hidden
|
|
41
|
+
className="absolute top-0 left-0 py-0.5 rounded-lg bg-accent/60 bg-clip-content opacity-0 pointer-events-none transition-opacity duration-200 ease-expo motion-safe:transition-[translate,width,height,opacity]"
|
|
42
|
+
/>
|
|
43
|
+
<LeftSidebarPortalTarget />
|
|
44
|
+
<div data-slot="left-sidebar-tree" className="flex flex-col">
|
|
45
|
+
{children ?? <LeftSidebarTree match={match} navKeys={navKeys} />}
|
|
46
|
+
</div>
|
|
47
|
+
</nav>
|
|
48
|
+
</ScrollArea.Viewport>
|
|
49
|
+
<ScrollArea.Scrollbar
|
|
50
|
+
className={(state) =>
|
|
51
|
+
cn(
|
|
52
|
+
'flex h-full w-1.5 touch-none p-px transition-opacity select-none',
|
|
53
|
+
!state.hovering && 'opacity-0',
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
>
|
|
57
|
+
<ScrollArea.Thumb className="relative flex-1 rounded-full bg-border" />
|
|
58
|
+
</ScrollArea.Scrollbar>
|
|
59
|
+
<ScrollArea.Corner />
|
|
60
|
+
</ScrollArea.Root>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
use,
|
|
5
|
+
useMemo,
|
|
6
|
+
useState,
|
|
7
|
+
type ComponentProps,
|
|
8
|
+
type ComponentType,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { createPortal } from 'react-dom';
|
|
12
|
+
import type { PopoverContent } from '@terrafirmagreg-team/ui/components/ui/popover';
|
|
13
|
+
import type { NavItemMatch } from '@terrafirmagreg-team/ui/lib/utils/nav-active';
|
|
14
|
+
|
|
15
|
+
export type SettingsMenuComponent = ComponentType<{
|
|
16
|
+
anchor?: ComponentProps<typeof PopoverContent>['anchor'];
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
export type LeftSidebarParts = {
|
|
20
|
+
controls?: ReactNode;
|
|
21
|
+
content?: ReactNode;
|
|
22
|
+
footer?: ReactNode;
|
|
23
|
+
|
|
24
|
+
menu?: ReactNode;
|
|
25
|
+
match?: NavItemMatch;
|
|
26
|
+
navKeys?: ReadonlySet<string>;
|
|
27
|
+
settings?: SettingsMenuComponent;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const LeftSidebarPortalContext = createContext<{
|
|
31
|
+
target: HTMLElement | null;
|
|
32
|
+
setTarget: (el: HTMLElement | null) => void;
|
|
33
|
+
} | null>(null);
|
|
34
|
+
|
|
35
|
+
export function LeftSidebarPortalProvider({ children }: { children: ReactNode }) {
|
|
36
|
+
const [target, setTarget] = useState<HTMLElement | null>(null);
|
|
37
|
+
return (
|
|
38
|
+
<LeftSidebarPortalContext
|
|
39
|
+
value={useMemo(() => ({ target, setTarget }), [target])}
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
</LeftSidebarPortalContext>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function LeftSidebarPortal({ children }: { children?: ReactNode }) {
|
|
47
|
+
const ctx = use(LeftSidebarPortalContext);
|
|
48
|
+
return ctx?.target ? createPortal(children, ctx.target) : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function LeftSidebarPortalTarget() {
|
|
52
|
+
const ctx = use(LeftSidebarPortalContext);
|
|
53
|
+
return <div data-slot="left-sidebar-portal" ref={ctx?.setTarget} />;
|
|
54
|
+
}
|
|
55
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
3
|
+
import { buttonVariants } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
4
|
+
import { SidebarIcon } from 'lucide-react';
|
|
5
|
+
import { useSidebar } from '@terrafirmagreg-team/ui/hooks/use-sidebar';
|
|
6
|
+
import { SidebarCollapseTrigger } from '@terrafirmagreg-team/ui/components/blocks/sidebar';
|
|
7
|
+
|
|
8
|
+
export function LeftSidebarExpand() {
|
|
9
|
+
const { collapsed } = useSidebar();
|
|
10
|
+
if (!collapsed) return;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<SidebarCollapseTrigger
|
|
14
|
+
className={cn(
|
|
15
|
+
buttonVariants({ variant: 'ghost', size: 'icon-sm' }),
|
|
16
|
+
'-ms-2 size-8 text-muted-foreground',
|
|
17
|
+
)}
|
|
18
|
+
>
|
|
19
|
+
<SidebarIcon />
|
|
20
|
+
</SidebarCollapseTrigger>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
3
|
+
import {
|
|
4
|
+
isValidElement,
|
|
5
|
+
useRef,
|
|
6
|
+
type ComponentProps,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { useTheme } from 'next-themes';
|
|
10
|
+
import { useLang } from '@terrafirmagreg-team/translate/provider';
|
|
11
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
12
|
+
import { LangSwitcher } from '@terrafirmagreg-team/ui/components/blocks/lang/switcher';
|
|
13
|
+
import { ThemeToggle } from '@terrafirmagreg-team/ui/components/blocks/theme/toggle';
|
|
14
|
+
import { Separator } from '@terrafirmagreg-team/ui/components/ui/separator';
|
|
15
|
+
import type { SettingsMenuComponent } from './context';
|
|
16
|
+
|
|
17
|
+
export function LeftSidebarFooter({
|
|
18
|
+
settings,
|
|
19
|
+
}: {
|
|
20
|
+
settings?: SettingsMenuComponent;
|
|
21
|
+
}) {
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<LeftSidebarLanguage />
|
|
25
|
+
<LeftSidebarActions settings={settings} />
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function LeftSidebarLanguage() {
|
|
31
|
+
const t = useTranslations();
|
|
32
|
+
const { locale, locales, onLocaleChange } = useLang();
|
|
33
|
+
if (!locales?.length) return null;
|
|
34
|
+
return (
|
|
35
|
+
<LangSwitcher
|
|
36
|
+
locales={locales}
|
|
37
|
+
selected={locale}
|
|
38
|
+
onSelect={(value) => onLocaleChange?.(value)}
|
|
39
|
+
label={t('Choose a language', { note: 'ui.choose_language' })}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const isThemeProps = (
|
|
45
|
+
value: unknown,
|
|
46
|
+
): value is ComponentProps<typeof ThemeToggle> =>
|
|
47
|
+
typeof value === 'object' && value !== null && !isValidElement(value);
|
|
48
|
+
|
|
49
|
+
export function LeftSidebarPlate({
|
|
50
|
+
tools,
|
|
51
|
+
theme,
|
|
52
|
+
className,
|
|
53
|
+
children,
|
|
54
|
+
...props
|
|
55
|
+
}: ComponentProps<'div'> & {
|
|
56
|
+
tools?: ReactNode;
|
|
57
|
+
theme?: ComponentProps<typeof ThemeToggle> | ReactNode;
|
|
58
|
+
}) {
|
|
59
|
+
return (
|
|
60
|
+
<div
|
|
61
|
+
data-slot="left-sidebar-plate"
|
|
62
|
+
className={cn(
|
|
63
|
+
'flex h-10 items-center gap-0.5 rounded-xl border bg-secondary/50 px-1',
|
|
64
|
+
className,
|
|
65
|
+
)}
|
|
66
|
+
{...props}
|
|
67
|
+
>
|
|
68
|
+
{children}
|
|
69
|
+
{(tools != null || theme != null) && (
|
|
70
|
+
<div className="ms-auto flex items-center gap-0.5">
|
|
71
|
+
{tools}
|
|
72
|
+
{tools != null && theme != null && (
|
|
73
|
+
<Separator
|
|
74
|
+
orientation="vertical"
|
|
75
|
+
className="mx-1 h-5 self-center! bg-muted-foreground/30"
|
|
76
|
+
aria-hidden
|
|
77
|
+
/>
|
|
78
|
+
)}
|
|
79
|
+
{isThemeProps(theme) ? <ThemeToggle {...theme} /> : theme}
|
|
80
|
+
</div>
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function LeftSidebarActions({
|
|
87
|
+
settings: SettingsMenu,
|
|
88
|
+
children,
|
|
89
|
+
}: {
|
|
90
|
+
settings?: SettingsMenuComponent;
|
|
91
|
+
|
|
92
|
+
children?: ReactNode;
|
|
93
|
+
}) {
|
|
94
|
+
const { theme, setTheme } = useTheme();
|
|
95
|
+
const plateRef = useRef<HTMLDivElement>(null);
|
|
96
|
+
return (
|
|
97
|
+
<LeftSidebarPlate
|
|
98
|
+
ref={plateRef}
|
|
99
|
+
tools={SettingsMenu ? <SettingsMenu anchor={plateRef} /> : undefined}
|
|
100
|
+
theme={{
|
|
101
|
+
value: theme,
|
|
102
|
+
onValueChange: setTheme,
|
|
103
|
+
className: 'p-0',
|
|
104
|
+
buttonClassName: 'size-7',
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
{children}
|
|
108
|
+
</LeftSidebarPlate>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|