@terrafirmagreg-team/ui 0.0.0-stage → 0.1.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 +48 -0
- package/src/components/blocks/canvas/chevron-edge.tsx +134 -0
- package/src/components/blocks/canvas/flow-canvas.tsx +177 -0
- package/src/components/blocks/canvas/flow-toolbar.tsx +32 -0
- package/src/components/blocks/canvas/flow-viewport.tsx +243 -0
- package/src/components/blocks/git/github-info.tsx +77 -0
- package/src/components/blocks/lang/content.tsx +22 -0
- package/src/components/blocks/lang/flag.tsx +24 -0
- package/src/components/blocks/lang/link.tsx +22 -0
- package/src/components/blocks/lang/redirect.tsx +47 -0
- package/src/components/blocks/lang/switcher.tsx +53 -0
- package/src/components/blocks/lang/untranslated-callout.tsx +28 -0
- package/src/components/blocks/link/link-preview.tsx +256 -0
- package/src/components/blocks/list/row.tsx +91 -0
- package/src/components/blocks/media/glb/model.tsx +243 -0
- package/src/components/blocks/media/glb/scene.tsx +372 -0
- package/src/components/blocks/media/glb/viewer.tsx +51 -0
- package/src/components/blocks/media/image.tsx +135 -0
- package/src/components/blocks/media/slideshow.tsx +177 -0
- package/src/components/blocks/nav/breadcrumb.tsx +50 -0
- package/src/components/blocks/nav/link.tsx +85 -0
- package/src/components/blocks/nav/site-menu.tsx +77 -0
- package/src/components/blocks/nav/site-title.tsx +60 -0
- package/src/components/blocks/nav/switcher.tsx +205 -0
- package/src/components/blocks/page/empty-state.tsx +31 -0
- package/src/components/blocks/page/heading.tsx +53 -0
- package/src/components/blocks/page/pager.tsx +112 -0
- package/src/components/blocks/readability/menu.tsx +431 -0
- package/src/components/blocks/readability/track.tsx +164 -0
- package/src/components/blocks/search/command.tsx +79 -0
- package/src/components/blocks/search/dialog.tsx +712 -0
- package/src/components/blocks/search/provider.tsx +117 -0
- package/src/components/blocks/sidebar.tsx +406 -0
- package/src/components/blocks/theme/toggle.tsx +71 -0
- package/src/components/blocks/tooltip/hint.tsx +27 -0
- package/src/components/blocks/viewer/controls.tsx +279 -0
- package/src/components/blocks/viewer/float-bar.tsx +50 -0
- package/src/components/layouts/layout.tsx +93 -0
- package/src/components/layouts/left-sidebar/content.tsx +62 -0
- package/src/components/layouts/left-sidebar/context.tsx +54 -0
- package/src/components/layouts/left-sidebar/expand.tsx +22 -0
- package/src/components/layouts/left-sidebar/footer.tsx +105 -0
- package/src/components/layouts/left-sidebar/index.ts +28 -0
- package/src/components/layouts/left-sidebar/items.tsx +102 -0
- package/src/components/layouts/left-sidebar/search.tsx +74 -0
- package/src/components/layouts/left-sidebar/sidebar.tsx +188 -0
- package/src/components/layouts/left-sidebar/tree.tsx +156 -0
- package/src/components/layouts/right-sidebar.tsx +95 -0
- package/src/components/layouts/tree-context.tsx +41 -0
- package/src/components/mdx/accordion.tsx +184 -0
- package/src/components/mdx/banner.tsx +154 -0
- package/src/components/mdx/callout.tsx +96 -0
- package/src/components/mdx/card.tsx +49 -0
- package/src/components/mdx/codeblock.tsx +249 -0
- package/src/components/mdx/collapsible.tsx +32 -0
- package/src/components/mdx/files.tsx +62 -0
- package/src/components/mdx/glow-header.tsx +40 -0
- package/src/components/mdx/gradient-text.tsx +27 -0
- package/src/components/mdx/image-zoom.tsx +314 -0
- package/src/components/mdx/mermaid.tsx +16 -0
- package/src/components/mdx/multiblock.tsx +18 -0
- package/src/components/mdx/preview.tsx +100 -0
- package/src/components/mdx/steps.tsx +9 -0
- package/src/components/mdx/table.tsx +13 -0
- package/src/components/mdx/tabs.tsx +353 -0
- package/src/components/mdx/type-table.tsx +170 -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 +18 -0
- package/src/hooks/canvas/use-flow-viewport-persist.ts +33 -0
- package/src/hooks/lang.ts +8 -0
- package/src/hooks/layout.ts +18 -0
- package/src/hooks/page/use-fit-pages.ts +91 -0
- package/src/hooks/page/use-location-search.ts +25 -0
- package/src/hooks/page/use-page-preview.ts +40 -0
- package/src/hooks/page/use-paged-list.ts +20 -0
- package/src/hooks/readability/provider.ts +86 -0
- package/src/hooks/search/dialog.ts +41 -0
- package/src/hooks/search/provider.ts +25 -0
- package/src/hooks/search/use-highlight-query.ts +51 -0
- package/src/hooks/sidebar.ts +63 -0
- package/src/hooks/use-async-value.ts +57 -0
- package/src/hooks/use-close-on-scroll.ts +23 -0
- package/src/hooks/use-copy-button.ts +46 -0
- package/src/hooks/use-cycle-index.ts +75 -0
- package/src/hooks/use-document-title.ts +9 -0
- package/src/hooks/use-element-size.ts +35 -0
- package/src/hooks/use-external-meta.ts +132 -0
- package/src/hooks/use-hot-key.ts +33 -0
- package/src/hooks/use-hover-follow.ts +54 -0
- package/src/hooks/use-in-view.ts +30 -0
- package/src/hooks/use-last-value.ts +15 -0
- package/src/hooks/use-marquee.ts +51 -0
- package/src/hooks/use-media-query.ts +14 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-modifier-keys.ts +31 -0
- package/src/hooks/use-on-change.ts +35 -0
- package/src/hooks/use-pane-keys.ts +28 -0
- package/src/hooks/use-swipe.ts +26 -0
- package/src/hooks/use-tree.ts +102 -0
- package/src/hooks/viewer/use-in-float-bar.ts +6 -0
- package/src/hooks/viewer/use-viewer-prefs.ts +77 -0
- package/src/lib/canvas/edge.ts +173 -0
- package/src/lib/canvas/geometry.ts +53 -0
- package/src/lib/canvas/state.ts +47 -0
- package/src/lib/canvas/viewport.ts +37 -0
- package/src/lib/canvas/xyflow.ts +1 -0
- package/src/lib/config.ts +81 -0
- package/src/lib/mdx/callout.ts +20 -0
- package/src/lib/mdx/gradient.ts +15 -0
- package/src/lib/mdx/mermaid.ts +14 -0
- package/src/lib/media/crop-opaque.ts +76 -0
- package/src/lib/media/nearby-indexes.ts +6 -0
- package/src/lib/media/trim-transparent.ts +117 -0
- package/src/lib/readability/config.ts +10 -0
- package/src/lib/readability/spotlight.ts +186 -0
- package/src/lib/readability/store.ts +146 -0
- package/src/lib/tree.ts +92 -0
- package/src/lib/utils/async-cache.ts +32 -0
- package/src/lib/utils/cn.ts +1 -0
- package/src/lib/utils/format.ts +22 -0
- package/src/lib/utils/history.ts +9 -0
- package/src/lib/utils/merge-refs.ts +13 -0
- package/src/lib/utils/nav-active.ts +58 -0
- package/src/lib/utils/stored-value.ts +136 -0
- package/src/lib/utils/urls.ts +17 -0
- package/src/locales/en_us.json +119 -0
- package/src/locales/pl_pl.json +35 -0
- package/src/locales/ru_ru.json +119 -0
- package/src/locales/uk_ua.json +35 -0
- package/src/locales/zh_cn.json +17 -0
- package/src/locales/zh_tw.json +17 -0
- package/src/locales.ts +5 -0
- package/src/provider.tsx +141 -0
- package/src/types/canvas.ts +49 -0
- package/src/types/glb.ts +25 -0
- package/src/types/nav.ts +95 -0
- package/src/types/preview.ts +9 -0
- package/src/types/readability.ts +28 -0
- package/src/types/search.ts +56 -0
- package/src/types/tree.ts +18 -0
- package/src/types/viewer.ts +53 -0
- package/styles/content/base.css +194 -0
- package/styles/content/default-colors.css +51 -0
- package/styles/content/shiki.css +108 -0
- package/styles/content/typography.mjs +3941 -0
- package/styles/content.css +7 -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 +413 -0
- package/README.md +0 -3
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { usePathname } from 'next/navigation';
|
|
4
|
+
import { useReadability } from '@terrafirmagreg-team/ui/hooks/readability/provider';
|
|
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
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
}
|