@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,247 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { usePathname } from 'next/navigation';
|
|
3
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
AlignStartVertical,
|
|
6
|
+
Columns2,
|
|
7
|
+
Flashlight,
|
|
8
|
+
FoldHorizontal,
|
|
9
|
+
Layers,
|
|
10
|
+
Maximize2,
|
|
11
|
+
Minimize2,
|
|
12
|
+
Palette,
|
|
13
|
+
PanelLeft,
|
|
14
|
+
Proportions,
|
|
15
|
+
Settings,
|
|
16
|
+
UnfoldHorizontal,
|
|
17
|
+
} from 'lucide-react';
|
|
18
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
19
|
+
import { useReadability } from '@terrafirmagreg-team/ui/hooks/readability/use-readability';
|
|
20
|
+
import { readabilityConfig } from '@terrafirmagreg-team/ui/lib/readability/config';
|
|
21
|
+
import {
|
|
22
|
+
Popover,
|
|
23
|
+
PopoverContent,
|
|
24
|
+
PopoverTrigger,
|
|
25
|
+
} from '@terrafirmagreg-team/ui/components/ui/popover';
|
|
26
|
+
import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
|
|
27
|
+
import {
|
|
28
|
+
readabilityLayouts,
|
|
29
|
+
spotlightStyles,
|
|
30
|
+
type ReadabilityLayout,
|
|
31
|
+
type SpotlightStyle,
|
|
32
|
+
} from '@terrafirmagreg-team/ui/types/readability';
|
|
33
|
+
import {
|
|
34
|
+
ReadabilityField,
|
|
35
|
+
ReadabilityHelp,
|
|
36
|
+
Segment,
|
|
37
|
+
WidthField,
|
|
38
|
+
} from './fields';
|
|
39
|
+
|
|
40
|
+
const layoutIcons: Record<ReadabilityLayout, ReactNode> = {
|
|
41
|
+
full: <Maximize2 />,
|
|
42
|
+
sidebar: <PanelLeft />,
|
|
43
|
+
both: <Columns2 />,
|
|
44
|
+
original: <Minimize2 />,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const styleIcons: Record<SpotlightStyle, ReactNode> = {
|
|
48
|
+
under: <Layers />,
|
|
49
|
+
aside: <AlignStartVertical />,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const switches = ['on', 'off'] as const;
|
|
53
|
+
|
|
54
|
+
export function ReadabilityMenu({
|
|
55
|
+
anchor,
|
|
56
|
+
}: {
|
|
57
|
+
anchor?: ComponentProps<typeof PopoverContent>['anchor'];
|
|
58
|
+
}) {
|
|
59
|
+
const t = useTranslations();
|
|
60
|
+
const {
|
|
61
|
+
layout,
|
|
62
|
+
setLayout,
|
|
63
|
+
pageWidth,
|
|
64
|
+
setPageWidth,
|
|
65
|
+
contentWidth,
|
|
66
|
+
setContentWidth,
|
|
67
|
+
spotlight,
|
|
68
|
+
setSpotlight,
|
|
69
|
+
spotlightStyle,
|
|
70
|
+
setSpotlightStyle,
|
|
71
|
+
coarsePointer,
|
|
72
|
+
smallScreen,
|
|
73
|
+
} = useReadability();
|
|
74
|
+
|
|
75
|
+
const layoutT: Record<ReadabilityLayout, { label: string; help: string }> = {
|
|
76
|
+
full: {
|
|
77
|
+
label: t('Expand all', { note: 'ui.readability.layout.full' }),
|
|
78
|
+
help: t('The article takes the full panel width; the sidebar stays at the screen edge', { note: 'ui.readability.layout.full.help' }),
|
|
79
|
+
},
|
|
80
|
+
sidebar: {
|
|
81
|
+
label: t('Adjustable page width', { note: 'ui.readability.layout.sidebar' }),
|
|
82
|
+
help: t('The slider narrows the whole page block: the sidebar moves with it', { note: 'ui.readability.layout.sidebar.help' }),
|
|
83
|
+
},
|
|
84
|
+
both: {
|
|
85
|
+
label: t('Adjustable page and content', { note: 'ui.readability.layout.both' }),
|
|
86
|
+
help: t('Both sliders apply: page block width and the text column inside', { note: 'ui.readability.layout.both.help' }),
|
|
87
|
+
},
|
|
88
|
+
original: {
|
|
89
|
+
label: t('Original width', { note: 'ui.readability.layout.original' }),
|
|
90
|
+
help: t('Default centered page width', { note: 'ui.readability.layout.original.help' }),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const spotlightT: Record<
|
|
94
|
+
SpotlightStyle | 'on' | 'off',
|
|
95
|
+
{ label: string; help: string }
|
|
96
|
+
> = {
|
|
97
|
+
on: {
|
|
98
|
+
label: t('On', { note: 'ui.readability.spotlight.on' }),
|
|
99
|
+
help: t('Turn on Spotlight', { note: 'ui.readability.spotlight.on.help' }),
|
|
100
|
+
},
|
|
101
|
+
off: {
|
|
102
|
+
label: t('Off', { note: 'ui.readability.spotlight.off' }),
|
|
103
|
+
help: t('Turn off Spotlight', { note: 'ui.readability.spotlight.off.help' }),
|
|
104
|
+
},
|
|
105
|
+
under: {
|
|
106
|
+
label: t('Under', { note: 'ui.readability.spotlight.under' }),
|
|
107
|
+
help: t('A solid background under the hovered block shows where the cursor is', { note: 'ui.readability.spotlight.under.help' }),
|
|
108
|
+
},
|
|
109
|
+
aside: {
|
|
110
|
+
label: t('Aside', { note: 'ui.readability.spotlight.aside' }),
|
|
111
|
+
help: t('A solid line beside the hovered element shows where the cursor is', { note: 'ui.readability.spotlight.aside.help' }),
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const layoutDisabled = smallScreen;
|
|
116
|
+
const pathname = usePathname();
|
|
117
|
+
const spotlightDisabled =
|
|
118
|
+
coarsePointer || (readabilityConfig().isSpotlightDisabled?.(pathname) ?? false);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Popover>
|
|
122
|
+
<PopoverTrigger
|
|
123
|
+
render={
|
|
124
|
+
<IconButton
|
|
125
|
+
variant="ghost"
|
|
126
|
+
size="icon-sm"
|
|
127
|
+
tooltip={false}
|
|
128
|
+
label={t('Readability', { note: 'ui.readability.menu' })}
|
|
129
|
+
className="text-muted-foreground! data-[popup-open]:bg-accent! data-[popup-open]:text-accent-foreground!"
|
|
130
|
+
>
|
|
131
|
+
<Settings />
|
|
132
|
+
</IconButton>
|
|
133
|
+
}
|
|
134
|
+
/>
|
|
135
|
+
<PopoverContent
|
|
136
|
+
anchor={anchor}
|
|
137
|
+
side="top"
|
|
138
|
+
align="center"
|
|
139
|
+
sideOffset={8}
|
|
140
|
+
className="w-64 space-y-3 p-3"
|
|
141
|
+
>
|
|
142
|
+
<ReadabilityField
|
|
143
|
+
label={t('Layout', { note: 'ui.readability.layout' })}
|
|
144
|
+
icon={<Proportions />}
|
|
145
|
+
help={
|
|
146
|
+
<ReadabilityHelp
|
|
147
|
+
title={t('Layout', { note: 'ui.readability.layout' })}
|
|
148
|
+
description={
|
|
149
|
+
layoutDisabled
|
|
150
|
+
? t('Layout switch is not available on small screens', { note: 'ui.readability.layout.unavailable' })
|
|
151
|
+
: t('Adjust the site layout to fit different reading needs and screens', { note: 'ui.readability.layout.help' })
|
|
152
|
+
}
|
|
153
|
+
items={readabilityLayouts.map((id) => ({
|
|
154
|
+
icon: layoutIcons[id],
|
|
155
|
+
label: layoutT[id].label,
|
|
156
|
+
help: layoutT[id].help,
|
|
157
|
+
}))}
|
|
158
|
+
/>
|
|
159
|
+
}
|
|
160
|
+
>
|
|
161
|
+
<Segment
|
|
162
|
+
options={readabilityLayouts}
|
|
163
|
+
value={layout}
|
|
164
|
+
onChange={setLayout}
|
|
165
|
+
disabled={layoutDisabled}
|
|
166
|
+
itemContent={(id) => layoutIcons[id]}
|
|
167
|
+
itemLabel={(id) => layoutT[id].label}
|
|
168
|
+
itemHelp={(id) => layoutT[id].help}
|
|
169
|
+
/>
|
|
170
|
+
</ReadabilityField>
|
|
171
|
+
{(layout === 'sidebar' || layout === 'both') && !smallScreen && (
|
|
172
|
+
<WidthField
|
|
173
|
+
field="page_width"
|
|
174
|
+
icon={<UnfoldHorizontal />}
|
|
175
|
+
value={pageWidth}
|
|
176
|
+
onChange={setPageWidth}
|
|
177
|
+
/>
|
|
178
|
+
)}
|
|
179
|
+
{layout === 'both' && !smallScreen && (
|
|
180
|
+
<WidthField
|
|
181
|
+
field="content_width"
|
|
182
|
+
icon={<FoldHorizontal />}
|
|
183
|
+
value={contentWidth}
|
|
184
|
+
onChange={setContentWidth}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
<ReadabilityField
|
|
188
|
+
label={t('Spotlight', { note: 'ui.readability.spotlight' })}
|
|
189
|
+
icon={<Flashlight />}
|
|
190
|
+
help={
|
|
191
|
+
<ReadabilityHelp
|
|
192
|
+
title={t('Spotlight', { note: 'ui.readability.spotlight' })}
|
|
193
|
+
description={
|
|
194
|
+
spotlightDisabled
|
|
195
|
+
? t('Spotlight is not available on touch screens', { note: 'ui.readability.spotlight.unavailable' })
|
|
196
|
+
: t('Highlight the line or block under the cursor to help readers stay focused', { note: 'ui.readability.spotlight.help' })
|
|
197
|
+
}
|
|
198
|
+
items={switches.map((id) => ({
|
|
199
|
+
label: spotlightT[id].label,
|
|
200
|
+
help: spotlightT[id].help,
|
|
201
|
+
}))}
|
|
202
|
+
/>
|
|
203
|
+
}
|
|
204
|
+
>
|
|
205
|
+
<Segment
|
|
206
|
+
options={switches}
|
|
207
|
+
value={spotlight ? 'on' : 'off'}
|
|
208
|
+
onChange={(id) => setSpotlight(id === 'on')}
|
|
209
|
+
disabled={spotlightDisabled}
|
|
210
|
+
itemContent={(id) => spotlightT[id].label}
|
|
211
|
+
itemLabel={(id) => spotlightT[id].label}
|
|
212
|
+
itemHelp={(id) => spotlightT[id].help}
|
|
213
|
+
itemClassName="text-xs"
|
|
214
|
+
/>
|
|
215
|
+
</ReadabilityField>
|
|
216
|
+
{spotlight && !spotlightDisabled && (
|
|
217
|
+
<ReadabilityField
|
|
218
|
+
label={t('Style', { note: 'ui.readability.spotlight.styles' })}
|
|
219
|
+
icon={<Palette />}
|
|
220
|
+
help={
|
|
221
|
+
<ReadabilityHelp
|
|
222
|
+
title={t('Style', { note: 'ui.readability.spotlight.styles' })}
|
|
223
|
+
description={t('Adjust how the spotlight highlight is drawn', { note: 'ui.readability.spotlight.styles.help' })}
|
|
224
|
+
items={spotlightStyles.map((id) => ({
|
|
225
|
+
icon: styleIcons[id],
|
|
226
|
+
label: spotlightT[id].label,
|
|
227
|
+
help: spotlightT[id].help,
|
|
228
|
+
}))}
|
|
229
|
+
/>
|
|
230
|
+
}
|
|
231
|
+
>
|
|
232
|
+
<Segment
|
|
233
|
+
options={spotlightStyles}
|
|
234
|
+
value={spotlightStyle}
|
|
235
|
+
onChange={setSpotlightStyle}
|
|
236
|
+
disabled={spotlightDisabled || !spotlight}
|
|
237
|
+
itemContent={(id) => styleIcons[id]}
|
|
238
|
+
itemLabel={(id) => spotlightT[id].label}
|
|
239
|
+
itemHelp={(id) => spotlightT[id].help}
|
|
240
|
+
/>
|
|
241
|
+
</ReadabilityField>
|
|
242
|
+
)}
|
|
243
|
+
</PopoverContent>
|
|
244
|
+
</Popover>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { usePathname } from 'next/navigation';
|
|
4
|
+
import { useReadability } from '@terrafirmagreg-team/ui/hooks/readability/use-readability';
|
|
5
|
+
import { readabilityConfig } from '@terrafirmagreg-team/ui/lib/readability/config';
|
|
6
|
+
import {
|
|
7
|
+
contentRoot,
|
|
8
|
+
resolveSpotlight,
|
|
9
|
+
rowBand,
|
|
10
|
+
} from '@terrafirmagreg-team/ui/lib/readability/spotlight';
|
|
11
|
+
import type { SpotlightStyle } from '@terrafirmagreg-team/ui/types/readability';
|
|
12
|
+
|
|
13
|
+
function SpotlightBox({
|
|
14
|
+
enabled,
|
|
15
|
+
style,
|
|
16
|
+
}: {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
style: SpotlightStyle;
|
|
19
|
+
}) {
|
|
20
|
+
const boxRef = useRef<HTMLDivElement>(null);
|
|
21
|
+
const pathname = usePathname();
|
|
22
|
+
const mouse = useRef({ x: 0, y: 0 });
|
|
23
|
+
const highlighted = useRef<HTMLElement | undefined>(undefined);
|
|
24
|
+
const observer = useRef<IntersectionObserver | null>(null);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const box = boxRef.current;
|
|
28
|
+
if (!box || !enabled) {
|
|
29
|
+
if (box) box.style.display = 'none';
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const root = contentRoot();
|
|
33
|
+
if (!root) return;
|
|
34
|
+
|
|
35
|
+
box.style.display = 'none';
|
|
36
|
+
highlighted.current = undefined;
|
|
37
|
+
|
|
38
|
+
const hide = () => {
|
|
39
|
+
box.style.display = 'none';
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const place = (
|
|
43
|
+
top: number,
|
|
44
|
+
left: number,
|
|
45
|
+
width: number,
|
|
46
|
+
height: number,
|
|
47
|
+
) => {
|
|
48
|
+
box.style.display = 'block';
|
|
49
|
+
box.style.top = `${top - 4}px`;
|
|
50
|
+
box.style.left = `${left - 4}px`;
|
|
51
|
+
box.style.width = `${width + 8}px`;
|
|
52
|
+
box.style.height = `${height + 8}px`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const watchVisibility = (el: HTMLElement | undefined) => {
|
|
56
|
+
observer.current?.disconnect();
|
|
57
|
+
observer.current = null;
|
|
58
|
+
if (!el) return;
|
|
59
|
+
observer.current = new IntersectionObserver(([entry]) => {
|
|
60
|
+
if (!entry.isIntersecting) hide();
|
|
61
|
+
});
|
|
62
|
+
observer.current.observe(el);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const placeForElement = (el: HTMLElement) => {
|
|
66
|
+
const { y } = mouse.current;
|
|
67
|
+
if (el.tagName === 'P') {
|
|
68
|
+
const lineHeight = Number.parseFloat(
|
|
69
|
+
window.getComputedStyle(el).lineHeight,
|
|
70
|
+
);
|
|
71
|
+
const lines = Math.floor(el.offsetHeight / lineHeight);
|
|
72
|
+
if (Number.isFinite(lineHeight) && lineHeight > 0 && lines > 0) {
|
|
73
|
+
const rect = el.getBoundingClientRect();
|
|
74
|
+
const relativeY = y - rect.top;
|
|
75
|
+
for (let i = 0; i < lines; i++) {
|
|
76
|
+
const top = i * lineHeight;
|
|
77
|
+
if (relativeY >= top && relativeY < top + lineHeight) {
|
|
78
|
+
place(rect.top + top, rect.left, el.offsetWidth, lineHeight);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const rect = rowBand(el, root, style) ?? el.getBoundingClientRect();
|
|
87
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
88
|
+
hide();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
place(rect.top, rect.left, rect.width, rect.height);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const page = document.getElementById('page') ?? root;
|
|
95
|
+
const update = () => {
|
|
96
|
+
const { x, y } = mouse.current;
|
|
97
|
+
const bounds = page.getBoundingClientRect();
|
|
98
|
+
if (
|
|
99
|
+
x < bounds.left ||
|
|
100
|
+
x > bounds.right ||
|
|
101
|
+
y < bounds.top ||
|
|
102
|
+
y > bounds.bottom
|
|
103
|
+
) {
|
|
104
|
+
hide();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const point = document.elementFromPoint(x, y);
|
|
108
|
+
const target =
|
|
109
|
+
point instanceof HTMLElement ? point : point?.parentElement;
|
|
110
|
+
const el =
|
|
111
|
+
target &&
|
|
112
|
+
target !== root &&
|
|
113
|
+
root.contains(target) &&
|
|
114
|
+
!target.closest('nav') &&
|
|
115
|
+
!target.closest('#toc')
|
|
116
|
+
? resolveSpotlight(target, root, style)
|
|
117
|
+
: null;
|
|
118
|
+
if (el !== highlighted.current) {
|
|
119
|
+
highlighted.current = el ?? undefined;
|
|
120
|
+
watchVisibility(el ?? undefined);
|
|
121
|
+
}
|
|
122
|
+
if (el) placeForElement(el);
|
|
123
|
+
else hide();
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const onMove = (event: MouseEvent) => {
|
|
127
|
+
mouse.current = { x: event.clientX, y: event.clientY };
|
|
128
|
+
update();
|
|
129
|
+
};
|
|
130
|
+
window.addEventListener('mousemove', onMove, { passive: true });
|
|
131
|
+
window.addEventListener('scroll', update, true);
|
|
132
|
+
window.addEventListener('resize', update);
|
|
133
|
+
return () => {
|
|
134
|
+
window.removeEventListener('mousemove', onMove);
|
|
135
|
+
window.removeEventListener('scroll', update, true);
|
|
136
|
+
window.removeEventListener('resize', update);
|
|
137
|
+
observer.current?.disconnect();
|
|
138
|
+
};
|
|
139
|
+
}, [enabled, pathname, style]);
|
|
140
|
+
|
|
141
|
+
if (!enabled) return null;
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<div
|
|
145
|
+
ref={boxRef}
|
|
146
|
+
aria-hidden
|
|
147
|
+
data-spotlight-style={style}
|
|
148
|
+
className="pointer-events-none fixed z-20 rounded-lg transition-all duration-200 data-[spotlight-style=under]:bg-(--spotlight-under-bg-color) before:absolute before:inset-y-0 before:-start-4 before:w-1 before:rounded-full before:bg-primary before:content-[''] data-[spotlight-style=under]:before:hidden"
|
|
149
|
+
style={{ display: 'none' }}
|
|
150
|
+
/>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function SpotlightTrack() {
|
|
155
|
+
const { spotlight, spotlightStyle, coarsePointer } = useReadability();
|
|
156
|
+
const pathname = usePathname();
|
|
157
|
+
const disabled = readabilityConfig().isSpotlightDisabled?.(pathname) ?? false;
|
|
158
|
+
return (
|
|
159
|
+
<SpotlightBox
|
|
160
|
+
enabled={spotlight && !coarsePointer && !disabled}
|
|
161
|
+
style={spotlightStyle}
|
|
162
|
+
/>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
CommandDialog,
|
|
5
|
+
CommandEmpty,
|
|
6
|
+
CommandInput,
|
|
7
|
+
CommandItem,
|
|
8
|
+
CommandList,
|
|
9
|
+
} from '@terrafirmagreg-team/ui/components/ui/command';
|
|
10
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
11
|
+
|
|
12
|
+
export type CommandSearchItem<T = unknown> = {
|
|
13
|
+
id: string;
|
|
14
|
+
label: ReactNode;
|
|
15
|
+
icon?: ReactNode;
|
|
16
|
+
meta?: ReactNode;
|
|
17
|
+
data?: T;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function CommandSearch<T = unknown>({
|
|
21
|
+
open,
|
|
22
|
+
onClose,
|
|
23
|
+
query,
|
|
24
|
+
onQuery,
|
|
25
|
+
title,
|
|
26
|
+
placeholder,
|
|
27
|
+
emptyLabel,
|
|
28
|
+
items,
|
|
29
|
+
onPick,
|
|
30
|
+
className,
|
|
31
|
+
}: {
|
|
32
|
+
open: boolean;
|
|
33
|
+
onClose: () => void;
|
|
34
|
+
query: string;
|
|
35
|
+
onQuery: (value: string) => void;
|
|
36
|
+
title: string;
|
|
37
|
+
placeholder?: string;
|
|
38
|
+
emptyLabel: ReactNode;
|
|
39
|
+
items: CommandSearchItem<T>[];
|
|
40
|
+
onPick: (item: CommandSearchItem<T>) => void;
|
|
41
|
+
className?: string;
|
|
42
|
+
}) {
|
|
43
|
+
return (
|
|
44
|
+
<CommandDialog
|
|
45
|
+
open={open}
|
|
46
|
+
onOpenChange={(next) => {
|
|
47
|
+
if (!next) onClose();
|
|
48
|
+
}}
|
|
49
|
+
title={title}
|
|
50
|
+
description={placeholder ?? title}
|
|
51
|
+
className={cn('max-w-lg', className)}
|
|
52
|
+
commandProps={{ shouldFilter: false }}
|
|
53
|
+
>
|
|
54
|
+
<CommandInput value={query} onValueChange={onQuery} placeholder={placeholder} />
|
|
55
|
+
{query.trim() ? (
|
|
56
|
+
<CommandList className="max-h-80">
|
|
57
|
+
{items.length === 0 ? (
|
|
58
|
+
<CommandEmpty>{emptyLabel}</CommandEmpty>
|
|
59
|
+
) : (
|
|
60
|
+
items.map((item) => (
|
|
61
|
+
<CommandItem
|
|
62
|
+
key={item.id}
|
|
63
|
+
value={item.id}
|
|
64
|
+
onSelect={() => {
|
|
65
|
+
onPick(item);
|
|
66
|
+
onClose();
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
{item.icon}
|
|
70
|
+
<span className="min-w-0 truncate">{item.label}</span>
|
|
71
|
+
{item.meta && <span className="ml-auto text-xs text-muted-foreground">{item.meta}</span>}
|
|
72
|
+
</CommandItem>
|
|
73
|
+
))
|
|
74
|
+
)}
|
|
75
|
+
</CommandList>
|
|
76
|
+
) : null}
|
|
77
|
+
</CommandDialog>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|