doccupine 0.0.158 → 0.0.159
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 +51 -1
- package/dist/generator/app-scaffolder.js +11 -3
- package/dist/generator/generated-page-publisher.d.ts +6 -6
- package/dist/generator/generated-page-publisher.js +7 -5
- package/dist/generator/mdx-pass-builder.d.ts +4 -4
- package/dist/generator/mdx-pass-builder.js +8 -1
- package/dist/generator/mdx-reconciliation-coordinator.d.ts +23 -9
- package/dist/generator/mdx-reconciliation-coordinator.js +63 -9
- package/dist/generator/page-catalog.d.ts +2 -4
- package/dist/generator/page-catalog.js +7 -2
- package/dist/generator/page-renderer.d.ts +15 -5
- package/dist/generator/page-renderer.js +38 -11
- package/dist/generator/project-config-repository.d.ts +4 -1
- package/dist/generator/project-config-repository.js +26 -0
- package/dist/generator/public-asset-manager.d.ts +10 -0
- package/dist/generator/public-asset-manager.js +63 -3
- package/dist/generator/section-index-generator.d.ts +10 -1
- package/dist/generator/section-index-generator.js +43 -15
- package/dist/generator/section-resolver.d.ts +8 -0
- package/dist/generator/site-artifacts.d.ts +4 -3
- package/dist/generator/site-artifacts.js +94 -9
- package/dist/generator/watch-coordinator.js +6 -1
- package/dist/lib/generated-artifacts.d.ts +3 -0
- package/dist/lib/generated-artifacts.js +36 -0
- package/dist/lib/layout.d.ts +6 -3
- package/dist/lib/layout.js +107 -4
- package/dist/lib/metadata.d.ts +7 -0
- package/dist/lib/metadata.js +33 -10
- package/dist/lib/structures.js +20 -0
- package/dist/lib/types.d.ts +28 -0
- package/dist/lib/ui-strings.d.ts +44 -0
- package/dist/lib/ui-strings.js +48 -0
- package/dist/lib/variants.d.ts +91 -0
- package/dist/lib/variants.js +411 -0
- package/dist/mdx-to-nextjs-generator.d.ts +22 -5
- package/dist/mdx-to-nextjs-generator.js +89 -10
- package/dist/templates/app/api/mcp/route.d.ts +1 -1
- package/dist/templates/app/api/mcp/route.js +14 -1
- package/dist/templates/app/api/rag/route.d.ts +1 -1
- package/dist/templates/app/api/rag/route.js +13 -2
- package/dist/templates/app/api/search/route.d.ts +1 -1
- package/dist/templates/app/api/search/route.js +16 -1
- package/dist/templates/app/sitemap.d.ts +2 -0
- package/dist/templates/app/sitemap.js +48 -3
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +40 -12
- package/dist/templates/components/Docs.d.ts +1 -1
- package/dist/templates/components/Docs.js +5 -2
- package/dist/templates/components/DocsSideBar.d.ts +1 -1
- package/dist/templates/components/DocsSideBar.js +3 -1
- package/dist/templates/components/SearchDocs.d.ts +1 -1
- package/dist/templates/components/SearchDocs.js +17 -3
- package/dist/templates/components/SearchModalContent.d.ts +1 -1
- package/dist/templates/components/SearchModalContent.js +22 -14
- package/dist/templates/components/SectionNavProvider.d.ts +1 -1
- package/dist/templates/components/SectionNavProvider.js +32 -20
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +26 -12
- package/dist/templates/components/layout/ActionBar.d.ts +1 -1
- package/dist/templates/components/layout/ActionBar.js +9 -7
- package/dist/templates/components/layout/Code.d.ts +1 -1
- package/dist/templates/components/layout/Code.js +6 -3
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +38 -5
- package/dist/templates/components/layout/DocsNavigation.d.ts +1 -1
- package/dist/templates/components/layout/DocsNavigation.js +4 -2
- package/dist/templates/components/layout/Dropdown.d.ts +1 -0
- package/dist/templates/components/layout/Dropdown.js +308 -0
- package/dist/templates/components/layout/FocusModeToggle.d.ts +1 -1
- package/dist/templates/components/layout/FocusModeToggle.js +7 -4
- package/dist/templates/components/layout/Footer.d.ts +1 -1
- package/dist/templates/components/layout/Footer.js +4 -2
- package/dist/templates/components/layout/Header.d.ts +1 -1
- package/dist/templates/components/layout/Header.js +18 -8
- package/dist/templates/components/layout/SectionBar.d.ts +1 -1
- package/dist/templates/components/layout/SectionBar.js +16 -10
- package/dist/templates/components/layout/VariantSwitchers.d.ts +1 -0
- package/dist/templates/components/layout/VariantSwitchers.js +313 -0
- package/dist/templates/components/useStrings.d.ts +1 -0
- package/dist/templates/components/useStrings.js +10 -0
- package/dist/templates/components/useVariant.d.ts +1 -0
- package/dist/templates/components/useVariant.js +13 -0
- package/dist/templates/llms/llmsIndex.d.ts +13 -0
- package/dist/templates/llms/llmsIndex.js +18 -3
- package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/ai-assistant.mdx.js +2 -0
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +2 -0
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +1 -1
- package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
- package/dist/templates/mdx/fonts.mdx.js +1 -1
- package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
- package/dist/templates/mdx/footer-links.mdx.js +1 -1
- package/dist/templates/mdx/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/index.mdx.js +2 -0
- package/dist/templates/mdx/languages.mdx.d.ts +1 -0
- package/dist/templates/mdx/languages.mdx.js +94 -0
- package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
- package/dist/templates/mdx/media-and-assets.mdx.js +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +6 -0
- package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
- package/dist/templates/mdx/navigation.mdx.js +2 -0
- package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/ai-assistant.mdx.js +2 -0
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/api-playground.mdx.js +2 -0
- package/dist/templates/mdx/platform/file-editor.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/file-editor.mdx.js +2 -0
- package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/index.mdx.js +1 -1
- package/dist/templates/mdx/platform/languages.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/languages.mdx.js +50 -0
- package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/mcp.mdx.js +2 -0
- package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.js +2 -0
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +4 -0
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +2 -0
- package/dist/templates/mdx/platform/versions.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/versions.mdx.js +33 -0
- package/dist/templates/mdx/sections.mdx.d.ts +1 -1
- package/dist/templates/mdx/sections.mdx.js +1 -1
- package/dist/templates/mdx/theme.mdx.d.ts +1 -1
- package/dist/templates/mdx/theme.mdx.js +1 -1
- package/dist/templates/mdx/versions.mdx.d.ts +1 -0
- package/dist/templates/mdx/versions.mdx.js +78 -0
- package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
- package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
- package/dist/templates/prettierignore.d.ts +1 -1
- package/dist/templates/prettierignore.js +2 -0
- package/dist/templates/services/mcp/server.d.ts +1 -1
- package/dist/templates/services/mcp/server.js +54 -10
- package/dist/templates/services/mcp/tools.d.ts +1 -1
- package/dist/templates/services/mcp/tools.js +81 -6
- package/dist/templates/services/mcp/types.d.ts +1 -1
- package/dist/templates/services/mcp/types.js +10 -0
- package/dist/templates/services/search.d.ts +1 -1
- package/dist/templates/services/search.js +34 -4
- package/dist/templates/utils/orderNavItems.d.ts +1 -1
- package/dist/templates/utils/orderNavItems.js +2 -0
- package/dist/templates/utils/strings.d.ts +1 -0
- package/dist/templates/utils/strings.js +27 -0
- package/dist/templates/utils/variants.d.ts +1 -0
- package/dist/templates/utils/variants.js +170 -0
- package/package.json +1 -1
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
export const dropdownTemplate = `"use client";
|
|
2
|
+
import React, { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import styled, { css } from "styled-components";
|
|
4
|
+
import { interactiveStyles, useOnClickOutside } from "cherry-styled-components";
|
|
5
|
+
import { Theme } from "@/app/theme";
|
|
6
|
+
|
|
7
|
+
// The Doccupine platform's Dropdown, ported for the generated site: a
|
|
8
|
+
// bordered trigger that mirrors the search trigger, a menu that scales in and
|
|
9
|
+
// out, and click-outside dismissal. Menus that hold a set of choices pass
|
|
10
|
+
// role="menu" and render DropdownItem entries; the menu then also handles
|
|
11
|
+
// Escape (close, refocus the trigger), ArrowUp/ArrowDown (cycle the items),
|
|
12
|
+
// and moves focus to the checked entry when it opens.
|
|
13
|
+
|
|
14
|
+
interface DropdownProps {
|
|
15
|
+
trigger: React.ReactNode;
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
align?: "left" | "right";
|
|
18
|
+
/** Open below the trigger (default) or above it (sidebar footer). */
|
|
19
|
+
placement?: "bottom" | "top";
|
|
20
|
+
/** Stretch the trigger to its container's width. */
|
|
21
|
+
fullWidth?: boolean;
|
|
22
|
+
/** 30px pill trigger, for rows of icon buttons (the sidebar footer). */
|
|
23
|
+
compact?: boolean;
|
|
24
|
+
/** Accessible name of the menu, and of the trigger unless overridden. */
|
|
25
|
+
label?: string;
|
|
26
|
+
/** Accessible name of the trigger when its content does not say enough. */
|
|
27
|
+
triggerLabel?: string;
|
|
28
|
+
/** A menu of choices gets role="menu" and keyboard handling. */
|
|
29
|
+
role?: "menu";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const DropdownContainer = styled.div<{ $fullWidth: boolean }>\`
|
|
33
|
+
position: relative;
|
|
34
|
+
display: \${({ $fullWidth }) => ($fullWidth ? "flex" : "inline-block")};
|
|
35
|
+
\${({ $fullWidth }) =>
|
|
36
|
+
$fullWidth &&
|
|
37
|
+
css\`
|
|
38
|
+
flex: 1;
|
|
39
|
+
min-width: 0;
|
|
40
|
+
\`}
|
|
41
|
+
\`;
|
|
42
|
+
|
|
43
|
+
// Mirrors the header's search trigger: the same bordered pill with Cherry's
|
|
44
|
+
// interactiveStyles for hover, focus, and active, applied to the focusable
|
|
45
|
+
// button itself so keyboard focus shows the rounded ring.
|
|
46
|
+
const DropdownTrigger = styled.button<{
|
|
47
|
+
theme: Theme;
|
|
48
|
+
$fullWidth: boolean;
|
|
49
|
+
$compact: boolean;
|
|
50
|
+
}>\`
|
|
51
|
+
\${interactiveStyles};
|
|
52
|
+
display: flex;
|
|
53
|
+
align-items: center;
|
|
54
|
+
gap: 8px;
|
|
55
|
+
width: \${({ $fullWidth }) => ($fullWidth ? "100%" : "auto")};
|
|
56
|
+
min-width: 0;
|
|
57
|
+
padding: 5px 10px;
|
|
58
|
+
border-radius: \${({ theme }) => theme.spacing.radius.xs};
|
|
59
|
+
border: 1px solid
|
|
60
|
+
var(--border-color, \${({ theme }) => theme.colors.grayLight});
|
|
61
|
+
background: transparent;
|
|
62
|
+
color: inherit;
|
|
63
|
+
font-family: inherit;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
|
|
66
|
+
/* Standing in a row of icon buttons: the same 30px pill, filled surface and
|
|
67
|
+
border as the toggles beside it, so the whole row shares one rhythm. */
|
|
68
|
+
\${({ $compact, theme }) =>
|
|
69
|
+
$compact &&
|
|
70
|
+
css\`
|
|
71
|
+
gap: 6px;
|
|
72
|
+
height: 30px;
|
|
73
|
+
min-height: 0;
|
|
74
|
+
padding: 0 10px;
|
|
75
|
+
border-radius: \${theme.spacing.radius.xl};
|
|
76
|
+
background: \${theme.colors.light};
|
|
77
|
+
\`}
|
|
78
|
+
\`;
|
|
79
|
+
|
|
80
|
+
const DropdownMenu = styled.div<{
|
|
81
|
+
theme: Theme;
|
|
82
|
+
$align: "left" | "right";
|
|
83
|
+
$placement: "bottom" | "top";
|
|
84
|
+
$compact: boolean;
|
|
85
|
+
$closing: boolean;
|
|
86
|
+
}>\`
|
|
87
|
+
position: absolute;
|
|
88
|
+
\${({ $placement }) =>
|
|
89
|
+
$placement === "top"
|
|
90
|
+
? "bottom: calc(100% + 8px);"
|
|
91
|
+
: "top: calc(100% + 8px);"}
|
|
92
|
+
\${({ $align }) => ($align === "right" ? "right: 0;" : "left: 0;")}
|
|
93
|
+
/* A compact trigger sits in a narrow rail, so its menu starts narrower too
|
|
94
|
+
and still clears both edges of that rail whichever way it is aligned. */
|
|
95
|
+
min-width: \${({ $compact }) => ($compact ? "160px" : "200px")};
|
|
96
|
+
max-height: 280px;
|
|
97
|
+
overflow-y: auto;
|
|
98
|
+
background: \${({ theme }) => theme.colors.light};
|
|
99
|
+
border: 1px solid \${({ theme }) => theme.colors.grayLight};
|
|
100
|
+
border-radius: \${({ theme }) => theme.spacing.radius.xs};
|
|
101
|
+
box-shadow: \${({ theme }) => theme.shadows.xs};
|
|
102
|
+
z-index: 1000;
|
|
103
|
+
transform-origin: \${({ $align, $placement }) =>
|
|
104
|
+
\`\${$placement === "top" ? "bottom" : "top"} \${$align}\`};
|
|
105
|
+
animation: \${({ $closing }) => ($closing ? "dropdownOut" : "dropdownIn")}
|
|
106
|
+
0.15s ease forwards;
|
|
107
|
+
|
|
108
|
+
@keyframes dropdownIn {
|
|
109
|
+
from {
|
|
110
|
+
opacity: 0;
|
|
111
|
+
transform: scale(0.95) translateY(-4px);
|
|
112
|
+
}
|
|
113
|
+
to {
|
|
114
|
+
opacity: 1;
|
|
115
|
+
transform: scale(1) translateY(0);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@keyframes dropdownOut {
|
|
120
|
+
from {
|
|
121
|
+
opacity: 1;
|
|
122
|
+
transform: scale(1) translateY(0);
|
|
123
|
+
}
|
|
124
|
+
to {
|
|
125
|
+
opacity: 0;
|
|
126
|
+
transform: scale(0.95) translateY(-4px);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
\`;
|
|
130
|
+
|
|
131
|
+
const DropdownDivider = styled.div<{ theme: Theme }>\`
|
|
132
|
+
height: 1px;
|
|
133
|
+
background: \${({ theme }) => theme.colors.grayLight};
|
|
134
|
+
margin: 0;
|
|
135
|
+
\`;
|
|
136
|
+
|
|
137
|
+
// One entry of a menu: the platform's menu link, as a button. The checked
|
|
138
|
+
// entry of a choice menu is tinted like a hovered one and keeps its weight.
|
|
139
|
+
const DropdownItem = styled.button<{ theme: Theme; $checked?: boolean }>\`
|
|
140
|
+
display: flex;
|
|
141
|
+
align-items: center;
|
|
142
|
+
gap: 8px;
|
|
143
|
+
width: 100%;
|
|
144
|
+
padding: 10px;
|
|
145
|
+
background: none;
|
|
146
|
+
border: none;
|
|
147
|
+
text-align: left;
|
|
148
|
+
font-family: inherit;
|
|
149
|
+
font-size: \${({ theme }) => theme.fontSizes.small.xs};
|
|
150
|
+
color: \${({ theme }) => theme.colors.primary};
|
|
151
|
+
font-weight: 600;
|
|
152
|
+
text-decoration: none;
|
|
153
|
+
white-space: nowrap;
|
|
154
|
+
cursor: pointer;
|
|
155
|
+
transition: all 0.3s ease;
|
|
156
|
+
|
|
157
|
+
& svg {
|
|
158
|
+
flex-shrink: 0;
|
|
159
|
+
transition: color 0.3s;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* A hairline between neighbours only: the first entry meets the menu's own
|
|
163
|
+
border, and no entry draws a line on both edges. */
|
|
164
|
+
& + & {
|
|
165
|
+
border-top: 1px solid \${({ theme }) => theme.colors.grayLight};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&:hover {
|
|
169
|
+
background: color-mix(
|
|
170
|
+
in srgb,
|
|
171
|
+
\${({ theme }) => theme.colors.primaryLight} 10%,
|
|
172
|
+
transparent
|
|
173
|
+
);
|
|
174
|
+
color: \${({ theme }) =>
|
|
175
|
+
theme.isDark ? theme.colors.primaryLight : theme.colors.primaryDark};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* Inset so the menu's overflow does not clip it, square so the menu's own
|
|
179
|
+
rounded corners shape it. */
|
|
180
|
+
&:focus-visible {
|
|
181
|
+
outline: none;
|
|
182
|
+
box-shadow: inset 0 0 0 2px \${({ theme }) => theme.colors.primaryLight};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
\${({ $checked, theme }) =>
|
|
186
|
+
$checked &&
|
|
187
|
+
css\`
|
|
188
|
+
background: color-mix(
|
|
189
|
+
in srgb,
|
|
190
|
+
\${theme.colors.primaryLight} 10%,
|
|
191
|
+
transparent
|
|
192
|
+
);
|
|
193
|
+
\`}
|
|
194
|
+
\`;
|
|
195
|
+
|
|
196
|
+
function Dropdown({
|
|
197
|
+
trigger,
|
|
198
|
+
children,
|
|
199
|
+
align = "right",
|
|
200
|
+
placement = "bottom",
|
|
201
|
+
fullWidth = false,
|
|
202
|
+
compact = false,
|
|
203
|
+
label,
|
|
204
|
+
triggerLabel,
|
|
205
|
+
role,
|
|
206
|
+
}: DropdownProps) {
|
|
207
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
208
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
209
|
+
const [isClosing, setIsClosing] = useState(false);
|
|
210
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
211
|
+
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
212
|
+
const menuRef = useRef<HTMLDivElement>(null);
|
|
213
|
+
const menuId = useId();
|
|
214
|
+
|
|
215
|
+
const close = useCallback(() => {
|
|
216
|
+
setIsClosing(true);
|
|
217
|
+
}, []);
|
|
218
|
+
|
|
219
|
+
const open = useCallback(() => {
|
|
220
|
+
setIsVisible(true);
|
|
221
|
+
setIsOpen(true);
|
|
222
|
+
setIsClosing(false);
|
|
223
|
+
}, []);
|
|
224
|
+
|
|
225
|
+
const handleToggle = useCallback(() => {
|
|
226
|
+
if (isOpen) {
|
|
227
|
+
close();
|
|
228
|
+
} else {
|
|
229
|
+
open();
|
|
230
|
+
}
|
|
231
|
+
}, [isOpen, close, open]);
|
|
232
|
+
|
|
233
|
+
const handleAnimationEnd = useCallback(() => {
|
|
234
|
+
if (isClosing) {
|
|
235
|
+
setIsOpen(false);
|
|
236
|
+
setIsVisible(false);
|
|
237
|
+
setIsClosing(false);
|
|
238
|
+
}
|
|
239
|
+
}, [isClosing]);
|
|
240
|
+
|
|
241
|
+
useOnClickOutside([containerRef], isOpen && !isClosing ? close : () => {});
|
|
242
|
+
|
|
243
|
+
// A choice menu lands focus on the checked entry (or the first one).
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
if (!isOpen || isClosing || role !== "menu") return;
|
|
246
|
+
const menu = menuRef.current;
|
|
247
|
+
if (!menu) return;
|
|
248
|
+
const checked = menu.querySelector<HTMLElement>('[aria-checked="true"]');
|
|
249
|
+
(checked ?? menu.querySelector<HTMLElement>("button, a"))?.focus();
|
|
250
|
+
}, [isOpen, isClosing, role]);
|
|
251
|
+
|
|
252
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
253
|
+
if (event.key === "Escape") {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
close();
|
|
256
|
+
triggerRef.current?.focus();
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (role !== "menu") return;
|
|
260
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
261
|
+
event.preventDefault();
|
|
262
|
+
const items = Array.from(
|
|
263
|
+
event.currentTarget.querySelectorAll<HTMLElement>("button, a"),
|
|
264
|
+
);
|
|
265
|
+
if (items.length === 0) return;
|
|
266
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
267
|
+
const index = items.indexOf(document.activeElement as HTMLElement);
|
|
268
|
+
items[(index + step + items.length) % items.length]?.focus();
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<DropdownContainer ref={containerRef} $fullWidth={fullWidth}>
|
|
273
|
+
<DropdownTrigger
|
|
274
|
+
ref={triggerRef}
|
|
275
|
+
type="button"
|
|
276
|
+
$fullWidth={fullWidth}
|
|
277
|
+
$compact={compact}
|
|
278
|
+
aria-label={triggerLabel ?? label}
|
|
279
|
+
aria-haspopup={role}
|
|
280
|
+
aria-expanded={role ? isOpen && !isClosing : undefined}
|
|
281
|
+
aria-controls={role ? menuId : undefined}
|
|
282
|
+
onClick={handleToggle}
|
|
283
|
+
>
|
|
284
|
+
{trigger}
|
|
285
|
+
</DropdownTrigger>
|
|
286
|
+
{isVisible && (
|
|
287
|
+
<DropdownMenu
|
|
288
|
+
id={role ? menuId : undefined}
|
|
289
|
+
ref={menuRef}
|
|
290
|
+
role={role}
|
|
291
|
+
aria-label={role ? label : undefined}
|
|
292
|
+
$align={align}
|
|
293
|
+
$placement={placement}
|
|
294
|
+
$compact={compact}
|
|
295
|
+
$closing={isClosing}
|
|
296
|
+
onClick={close}
|
|
297
|
+
onKeyDown={handleKeyDown}
|
|
298
|
+
onAnimationEnd={handleAnimationEnd}
|
|
299
|
+
>
|
|
300
|
+
{children}
|
|
301
|
+
</DropdownMenu>
|
|
302
|
+
)}
|
|
303
|
+
</DropdownContainer>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export { Dropdown, DropdownDivider, DropdownItem };
|
|
308
|
+
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const focusModeToggleTemplate = "\"use client\";\nimport { useEffect, useRef, useState } from \"react\";\nimport styled from \"styled-components\";\nimport { resetButton } from \"cherry-styled-components\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { mq, Theme } from \"@/app/theme\";\nimport { interactiveStyles } from \"@/components/layout/SharedStyled\";\n\n// Desktop-only affordance that collapses both rails for distraction-free\n// reading. The button is fixed rather than living in the sidebar footer next\n// to the ThemeToggle: the footer slides away with the sidebar, and the way\n// back out of focus mode has to stay on screen.\nconst StyledFocusToggle = styled.button<{ theme: Theme }>`\n display: none;\n\n ${mq(\"lg\")} {\n ${resetButton};\n ${interactiveStyles};\n display: flex;\n align-items: center;\n justify-content: center;\n position: fixed;\n /* Above the sidebar (99) so it stays clickable once the rails are out,\n below the chat panel (1000). */\n z-index: 100;\n /*
|
|
1
|
+
export declare const focusModeToggleTemplate = "\"use client\";\nimport { useEffect, useRef, useState } from \"react\";\nimport styled from \"styled-components\";\nimport { resetButton } from \"cherry-styled-components\";\nimport { useStrings } from \"@/components/useStrings\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { mq, Theme } from \"@/app/theme\";\nimport { interactiveStyles } from \"@/components/layout/SharedStyled\";\n\n// Desktop-only affordance that collapses both rails for distraction-free\n// reading. The button is fixed rather than living in the sidebar footer next\n// to the ThemeToggle: the footer slides away with the sidebar, and the way\n// back out of focus mode has to stay on screen.\nconst StyledFocusToggle = styled.button<{ theme: Theme }>`\n display: none;\n\n ${mq(\"lg\")} {\n ${resetButton};\n ${interactiveStyles};\n display: flex;\n align-items: center;\n justify-content: center;\n position: fixed;\n /* Above the sidebar (99) so it stays clickable once the rails are out,\n below the chat panel (1000). */\n z-index: 100;\n /* Left end of the sidebar footer row, flush with the footer's left\n padding; the switchers follow and the ThemeToggle holds the right end,\n all of them 30px tall. */\n left: 20px;\n bottom: 16px;\n width: 30px;\n height: 30px;\n border-radius: 50%;\n background: ${({ theme }) => theme.colors.light};\n border-color: ${({ theme }) => theme.colors.grayLight};\n\n & svg {\n width: 16px;\n height: 16px;\n }\n\n & svg[stroke] {\n stroke: ${({ theme }) => theme.colors.primary};\n }\n\n &:hover svg[stroke] {\n stroke: ${({ theme }) => theme.colors.accent};\n }\n }\n`;\n\nfunction FocusModeToggle() {\n const [isFocusMode, setIsFocusMode] = useState(false);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const t = useStrings();\n\n // Cmd/Ctrl+B, the editor convention for collapsing the side columns. Sits\n // alongside the app's other chords (Cmd+K search, Cmd+I chat,\n // Cmd+Shift+L theme) and stays out of the way while the reader is typing.\n useEffect(() => {\n function handleKeyDown(e: KeyboardEvent) {\n if (!(e.metaKey || e.ctrlKey) || e.shiftKey || e.altKey) return;\n if (e.key.toLowerCase() !== \"b\") return;\n const target = e.target as HTMLElement | null;\n if (target?.closest(\"input, textarea, [contenteditable='true']\")) return;\n // The button is display:none below \"lg\" and focus mode is a desktop\n // layout, so the shortcut is live exactly when the button is.\n const button = buttonRef.current;\n if (!button || getComputedStyle(button).display === \"none\") return;\n e.preventDefault();\n setIsFocusMode((value) => !value);\n }\n document.addEventListener(\"keydown\", handleKeyDown);\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, []);\n\n // The nav sidebar, the right rail and the content columns sit in separate\n // subtrees, so the state rides on the root element and each of them reacts\n // in CSS (see focusModeHide / focusModeColumn in SharedStyled).\n useEffect(() => {\n const root = document.documentElement;\n if (isFocusMode) {\n root.setAttribute(\"data-focus-mode\", \"\");\n } else {\n root.removeAttribute(\"data-focus-mode\");\n }\n return () => root.removeAttribute(\"data-focus-mode\");\n }, [isFocusMode]);\n\n return (\n <StyledFocusToggle\n ref={buttonRef}\n type=\"button\"\n onClick={() => setIsFocusMode((value) => !value)}\n aria-pressed={isFocusMode}\n aria-label={isFocusMode ? t.exitFocusMode : t.enterFocusMode}\n title={(isFocusMode ? t.exitFocusMode : t.focusMode) + \" (\u2318B)\"}\n >\n <Icon name={isFocusMode ? \"minimize\" : \"maximize\"} size={16} />\n </StyledFocusToggle>\n );\n}\n\nexport { FocusModeToggle };\n";
|
|
@@ -2,6 +2,7 @@ export const focusModeToggleTemplate = `"use client";
|
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
import styled from "styled-components";
|
|
4
4
|
import { resetButton } from "cherry-styled-components";
|
|
5
|
+
import { useStrings } from "@/components/useStrings";
|
|
5
6
|
import { Icon } from "@/components/layout/Icon";
|
|
6
7
|
import { mq, Theme } from "@/app/theme";
|
|
7
8
|
import { interactiveStyles } from "@/components/layout/SharedStyled";
|
|
@@ -23,8 +24,9 @@ const StyledFocusToggle = styled.button<{ theme: Theme }>\`
|
|
|
23
24
|
/* Above the sidebar (99) so it stays clickable once the rails are out,
|
|
24
25
|
below the chat panel (1000). */
|
|
25
26
|
z-index: 100;
|
|
26
|
-
/*
|
|
27
|
-
|
|
27
|
+
/* Left end of the sidebar footer row, flush with the footer's left
|
|
28
|
+
padding; the switchers follow and the ThemeToggle holds the right end,
|
|
29
|
+
all of them 30px tall. */
|
|
28
30
|
left: 20px;
|
|
29
31
|
bottom: 16px;
|
|
30
32
|
width: 30px;
|
|
@@ -51,6 +53,7 @@ const StyledFocusToggle = styled.button<{ theme: Theme }>\`
|
|
|
51
53
|
function FocusModeToggle() {
|
|
52
54
|
const [isFocusMode, setIsFocusMode] = useState(false);
|
|
53
55
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
56
|
+
const t = useStrings();
|
|
54
57
|
|
|
55
58
|
// Cmd/Ctrl+B, the editor convention for collapsing the side columns. Sits
|
|
56
59
|
// alongside the app's other chords (Cmd+K search, Cmd+I chat,
|
|
@@ -91,8 +94,8 @@ function FocusModeToggle() {
|
|
|
91
94
|
type="button"
|
|
92
95
|
onClick={() => setIsFocusMode((value) => !value)}
|
|
93
96
|
aria-pressed={isFocusMode}
|
|
94
|
-
aria-label={isFocusMode ?
|
|
95
|
-
title={isFocusMode ?
|
|
97
|
+
aria-label={isFocusMode ? t.exitFocusMode : t.enterFocusMode}
|
|
98
|
+
title={(isFocusMode ? t.exitFocusMode : t.focusMode) + " (⌘B)"}
|
|
96
99
|
>
|
|
97
100
|
<Icon name={isFocusMode ? "minimize" : "maximize"} size={16} />
|
|
98
101
|
</StyledFocusToggle>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const footerTemplate = "\"use client\";\nimport styled, { css } from \"styled-components\";\nimport { Space, styledSmall, useChat } from \"cherry-styled-components\";\nimport { mq, Theme } from \"@/app/theme\";\nimport { GitHubLogo } from \"@/components/layout/Pictograms\";\nimport {\n focusModeColumn,\n sidePanelOffset,\n} from \"@/components/layout/SharedStyled\";\nimport linksData from \"@/links.json\";\n\ninterface LinkProps {\n title: string;\n url: string;\n icon?: string;\n}\n\nconst links = linksData as LinkProps[];\n\nconst StyledFooter = styled.footer<{\n theme: Theme;\n $isChatOpen?: boolean;\n $hasLinks?: boolean;\n}>`\n padding: 0 20px;\n transition: all 0.3s ease;\n\n ${({ $hasLinks }) =>\n $hasLinks &&\n css`\n margin-top: 20px;\n `}\n\n ${mq(\"lg\")} {\n margin: 0;\n padding: 0 300px 0 300px;\n\n ${({ $isChatOpen }) =>\n $isChatOpen &&\n css`\n padding: 0 440px 0 300px;\n `}\n }\n\n ${sidePanelOffset};\n ${({ $isChatOpen }) => !$isChatOpen && focusModeColumn};\n`;\n\nconst StyledFooterInner = styled.div<{ theme: Theme }>`\n border-top: solid 1px ${({ theme }) => theme.colors.grayLight};\n max-width: 640px;\n margin: 0 auto;\n padding: 28px 0;\n color: ${({ theme }) => theme.colors.grayDark};\n ${({ theme }) => styledSmall(theme)};\n\n ${mq(\"lg\")} {\n padding: 20px 0;\n }\n\n & a {\n font-weight: 700;\n color: ${({ theme }) => theme.colors.accent};\n text-decoration: none;\n transition: all 0.3s ease;\n display: inline-flex;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primary};\n }\n\n /* The GitHub logo is an icon-only link - round the global focus ring so it\n hugs the icon instead of drawing a rectangle. */\n &:has(svg):focus-visible {\n border-radius: 100%;\n }\n\n & svg {\n width: 18px;\n height: 18px;\n }\n }\n`;\n\nconst StyledFooterFlex = styled.div`\n display: flex;\n justify-content: flex-start;\n align-items: center;\n gap: 20px;\n\n ${mq(\"lg\")} {\n justify-content: space-between;\n }\n`;\n\nfunction Footer({ hideBranding }: { hideBranding?: boolean }) {\n const { isOpen } = useChat();\n\n if (hideBranding) return <Space $xs={80} $lg=\"none\" />;\n\n return (\n <StyledFooter $isChatOpen={isOpen} $hasLinks={links.length > 0}>\n <StyledFooterInner>\n <StyledFooterFlex>\n <span>\n
|
|
1
|
+
export declare const footerTemplate = "\"use client\";\nimport styled, { css } from \"styled-components\";\nimport { useStrings } from \"@/components/useStrings\";\nimport { Space, styledSmall, useChat } from \"cherry-styled-components\";\nimport { mq, Theme } from \"@/app/theme\";\nimport { GitHubLogo } from \"@/components/layout/Pictograms\";\nimport {\n focusModeColumn,\n sidePanelOffset,\n} from \"@/components/layout/SharedStyled\";\nimport linksData from \"@/links.json\";\n\ninterface LinkProps {\n title: string;\n url: string;\n icon?: string;\n}\n\nconst links = linksData as LinkProps[];\n\nconst StyledFooter = styled.footer<{\n theme: Theme;\n $isChatOpen?: boolean;\n $hasLinks?: boolean;\n}>`\n padding: 0 20px;\n transition: all 0.3s ease;\n\n ${({ $hasLinks }) =>\n $hasLinks &&\n css`\n margin-top: 20px;\n `}\n\n ${mq(\"lg\")} {\n margin: 0;\n padding: 0 300px 0 300px;\n\n ${({ $isChatOpen }) =>\n $isChatOpen &&\n css`\n padding: 0 440px 0 300px;\n `}\n }\n\n ${sidePanelOffset};\n ${({ $isChatOpen }) => !$isChatOpen && focusModeColumn};\n`;\n\nconst StyledFooterInner = styled.div<{ theme: Theme }>`\n border-top: solid 1px ${({ theme }) => theme.colors.grayLight};\n max-width: 640px;\n margin: 0 auto;\n padding: 28px 0;\n color: ${({ theme }) => theme.colors.grayDark};\n ${({ theme }) => styledSmall(theme)};\n\n ${mq(\"lg\")} {\n padding: 20px 0;\n }\n\n & a {\n font-weight: 700;\n color: ${({ theme }) => theme.colors.accent};\n text-decoration: none;\n transition: all 0.3s ease;\n display: inline-flex;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primary};\n }\n\n /* The GitHub logo is an icon-only link - round the global focus ring so it\n hugs the icon instead of drawing a rectangle. */\n &:has(svg):focus-visible {\n border-radius: 100%;\n }\n\n & svg {\n width: 18px;\n height: 18px;\n }\n }\n`;\n\nconst StyledFooterFlex = styled.div`\n display: flex;\n justify-content: flex-start;\n align-items: center;\n gap: 20px;\n\n ${mq(\"lg\")} {\n justify-content: space-between;\n }\n`;\n\nfunction Footer({ hideBranding }: { hideBranding?: boolean }) {\n const { isOpen } = useChat();\n const t = useStrings();\n\n if (hideBranding) return <Space $xs={80} $lg=\"none\" />;\n\n return (\n <StyledFooter $isChatOpen={isOpen} $hasLinks={links.length > 0}>\n <StyledFooterInner>\n <StyledFooterFlex>\n <span>\n {t.poweredBy}{\" \"}\n <a\n href=\"https://doccupine.com\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Doccupine\n </a>\n </span>\n <a\n href=\"https://github.com/doccupine/cli\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n aria-label={t.githubLink}\n >\n <GitHubLogo />\n </a>\n </StyledFooterFlex>\n </StyledFooterInner>\n </StyledFooter>\n );\n}\n\nexport { Footer };\n";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SIDEBAR_WIDTH, CHAT_WIDTH } from "../../app/theme.js";
|
|
2
2
|
export const footerTemplate = `"use client";
|
|
3
3
|
import styled, { css } from "styled-components";
|
|
4
|
+
import { useStrings } from "@/components/useStrings";
|
|
4
5
|
import { Space, styledSmall, useChat } from "cherry-styled-components";
|
|
5
6
|
import { mq, Theme } from "@/app/theme";
|
|
6
7
|
import { GitHubLogo } from "@/components/layout/Pictograms";
|
|
@@ -96,6 +97,7 @@ const StyledFooterFlex = styled.div\`
|
|
|
96
97
|
|
|
97
98
|
function Footer({ hideBranding }: { hideBranding?: boolean }) {
|
|
98
99
|
const { isOpen } = useChat();
|
|
100
|
+
const t = useStrings();
|
|
99
101
|
|
|
100
102
|
if (hideBranding) return <Space $xs={80} $lg="none" />;
|
|
101
103
|
|
|
@@ -104,7 +106,7 @@ function Footer({ hideBranding }: { hideBranding?: boolean }) {
|
|
|
104
106
|
<StyledFooterInner>
|
|
105
107
|
<StyledFooterFlex>
|
|
106
108
|
<span>
|
|
107
|
-
|
|
109
|
+
{t.poweredBy}{" "}
|
|
108
110
|
<a
|
|
109
111
|
href="https://doccupine.com"
|
|
110
112
|
target="_blank"
|
|
@@ -117,7 +119,7 @@ function Footer({ hideBranding }: { hideBranding?: boolean }) {
|
|
|
117
119
|
href="https://github.com/doccupine/cli"
|
|
118
120
|
target="_blank"
|
|
119
121
|
rel="noopener noreferrer"
|
|
120
|
-
aria-label=
|
|
122
|
+
aria-label={t.githubLink}
|
|
121
123
|
>
|
|
122
124
|
<GitHubLogo />
|
|
123
125
|
</a>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const headerTemplate = "\"use client\";\nimport React from \"react\";\nimport { useCallback, useContext, useEffect, useRef, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport Link from \"next/link\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {
|
|
1
|
+
export declare const headerTemplate = "\"use client\";\nimport React from \"react\";\nimport { useCallback, useContext, useEffect, useRef, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport Link from \"next/link\";\nimport { mq, Theme } from \"@/app/theme\";\nimport {\n ChatLauncher,\n Icon,\n useOnClickOutside,\n} from \"cherry-styled-components\";\nimport { Search, Sparkles } from \"lucide-react\";\nimport { Logo } from \"@/components/layout/Pictograms\";\nimport { ChatContext } from \"@/components/Chat\";\nimport { useStrings } from \"@/components/useStrings\";\nimport {\n SearchContext,\n SearchKbd,\n StyledSearchButton,\n} from \"@/components/SearchDocs\";\nimport themeJson from \"@/theme.json\";\n\nconst customThemeJson = themeJson as typeof themeJson & {\n logo?: { dark: string; light: string };\n};\n\nconst StyledHeader = styled.header<{\n theme: Theme;\n $hasChildren: boolean;\n $pinned: boolean;\n}>`\n /* In normal flow at the top of the page, fixed only once the page scrolls.\n iOS Safari refuses to color its toolbar from the theme-color meta while\n a sticky or fixed element touches the top edge - whatever that element's\n background (transparent, frosted, or opaque; the Doccupine platform\n site's header is position: relative on its app pages for the same\n reason). At scroll position zero an in-flow header occupies exactly the\n place a sticky one would, so the swap is invisible; while scrolled, the\n toolbar is collapsed anyway. StyledHeaderShell holds the header's\n measured height while it is fixed, so pinning never shifts the page. */\n position: relative;\n top: 0;\n margin: 0;\n z-index: 1000;\n width: 100%;\n border-bottom: solid 1px ${({ theme }) => theme.colors.grayLight};\n\n ${({ $pinned }) =>\n $pinned &&\n css`\n position: fixed;\n left: 0;\n `}\n\n ${({ $hasChildren }) =>\n !$hasChildren &&\n css`\n ${mq(\"lg\")} {\n padding-bottom: 16px;\n padding-top: 16px;\n }\n `}\n\n &::before,\n &::after {\n display: block;\n content: \"\";\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n background: ${({ theme }) => theme.colors.light};\n z-index: -2;\n }\n\n &::after {\n background: ${({ theme }) =>\n `color-mix(in srgb, ${theme.colors.primaryLight} 5%, transparent)`};\n z-index: -1;\n }\n\n & .logo {\n display: flex;\n min-width: max-content;\n\n & svg,\n & img {\n margin: auto;\n height: auto;\n width: fit-content;\n min-width: fit-content;\n max-width: 182px;\n max-height: 30px;\n\n & [fill]:not(.ignore-fill) {\n fill: ${({ theme }) => theme.colors.primary};\n }\n }\n }\n`;\n\n/**\n * In-flow placeholder that owns the header's space. While the header is\n * pinned (position: fixed, out of flow), the shell keeps the header's\n * measured height so pinning never shifts the page; at the top of the page\n * it collapses to its content.\n */\nconst StyledHeaderShell = styled.div<{ $pinned: boolean; $height: number }>`\n ${({ $pinned, $height }) =>\n $pinned &&\n $height > 0 &&\n css`\n height: ${$height}px;\n `}\n`;\n\nconst StyledHeaderInner = styled.div<{ $hasChildren: boolean }>`\n display: flex;\n align-items: center;\n justify-content: space-between;\n flex-wrap: wrap;\n padding: 16px 0 0 20px;\n\n ${({ $hasChildren }) =>\n !$hasChildren &&\n css`\n padding-bottom: 16px;\n `}\n\n ${mq(\"lg\")} {\n flex-wrap: nowrap;\n padding: 0 20px;\n }\n`;\n\nconst StyledLeftWrapper = styled.div`\n display: flex;\n align-items: center;\n gap: 10px;\n min-width: fit-content;\n padding-right: 20px;\n\n ${mq(\"lg\")} {\n padding-right: 0;\n }\n`;\n\ninterface HeaderProps {\n children?: React.ReactNode;\n}\n\nfunction Header({ children }: HeaderProps) {\n const [isOptionActive, setIsOptionActive] = useState(false);\n const [isPinned, setIsPinned] = useState(false);\n const [headerHeight, setHeaderHeight] = useState(0);\n const headerRef = useRef<HTMLElement>(null);\n\n useEffect(() => {\n const onScroll = () => {\n if (headerRef.current) {\n setHeaderHeight(headerRef.current.getBoundingClientRect().height);\n }\n setIsPinned(window.scrollY > 0);\n };\n onScroll();\n window.addEventListener(\"scroll\", onScroll, { passive: true });\n window.addEventListener(\"resize\", onScroll);\n return () => {\n window.removeEventListener(\"scroll\", onScroll);\n window.removeEventListener(\"resize\", onScroll);\n };\n }, []);\n\n const wrapperRef = useRef<HTMLSpanElement>(null);\n const elmRef = useRef<HTMLDivElement>(null);\n const closeMenu = useCallback(() => {\n setIsOptionActive(false);\n }, []);\n\n useOnClickOutside(\n [elmRef, wrapperRef],\n isOptionActive ? closeMenu : () => {},\n );\n const { isChatActive } = useContext(ChatContext);\n const { openSearch } = useContext(SearchContext);\n const t = useStrings();\n\n return (\n <StyledHeaderShell $pinned={isPinned} $height={headerHeight}>\n <StyledHeader\n $hasChildren={children ? true : false}\n $pinned={isPinned}\n id=\"header\"\n ref={headerRef}\n >\n <StyledHeaderInner $hasChildren={children ? true : false}>\n <Link href=\"/\" className=\"logo\" aria-label=\"Logo\">\n {customThemeJson.logo ? (\n <>\n {/* Both logos render; .light-only and .dark-only classes in\n GlobalStyles hide the inactive one based on the \"dark\" class\n on <html>. Avoids a JS-driven swap so no flash on first load. */}\n {/* eslint-disable-next-line @next/next/no-img-element */}\n <img\n className=\"light-only\"\n src={customThemeJson.logo.light}\n alt=\"Logo\"\n width=\"100\"\n height=\"100\"\n />\n {/* eslint-disable-next-line @next/next/no-img-element */}\n <img\n className=\"dark-only\"\n src={customThemeJson.logo.dark}\n alt=\"Logo\"\n width=\"100\"\n height=\"100\"\n />\n </>\n ) : (\n <Logo />\n )}\n </Link>\n {children}\n <StyledLeftWrapper>\n <StyledSearchButton\n onClick={openSearch}\n aria-label={t.searchButton}\n >\n <Search size={14} />\n <SearchKbd>⌘K</SearchKbd>\n </StyledSearchButton>\n {isChatActive && (\n <ChatLauncher $glow aria-label={t.askAiAssistant}>\n <Icon icon={Sparkles} />\n {t.askAi}\n </ChatLauncher>\n )}\n </StyledLeftWrapper>\n </StyledHeaderInner>\n </StyledHeader>\n </StyledHeaderShell>\n );\n}\n\nexport { Header };\n";
|
|
@@ -4,10 +4,15 @@ import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
|
4
4
|
import styled, { css } from "styled-components";
|
|
5
5
|
import Link from "next/link";
|
|
6
6
|
import { mq, Theme } from "@/app/theme";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
ChatLauncher,
|
|
9
|
+
Icon,
|
|
10
|
+
useOnClickOutside,
|
|
11
|
+
} from "cherry-styled-components";
|
|
12
|
+
import { Search, Sparkles } from "lucide-react";
|
|
9
13
|
import { Logo } from "@/components/layout/Pictograms";
|
|
10
14
|
import { ChatContext } from "@/components/Chat";
|
|
15
|
+
import { useStrings } from "@/components/useStrings";
|
|
11
16
|
import {
|
|
12
17
|
SearchContext,
|
|
13
18
|
SearchKbd,
|
|
@@ -148,7 +153,6 @@ interface HeaderProps {
|
|
|
148
153
|
|
|
149
154
|
function Header({ children }: HeaderProps) {
|
|
150
155
|
const [isOptionActive, setIsOptionActive] = useState(false);
|
|
151
|
-
const [isLangActive, setIsLangActive] = useState(false);
|
|
152
156
|
const [isPinned, setIsPinned] = useState(false);
|
|
153
157
|
const [headerHeight, setHeaderHeight] = useState(0);
|
|
154
158
|
const headerRef = useRef<HTMLElement>(null);
|
|
@@ -171,19 +175,17 @@ function Header({ children }: HeaderProps) {
|
|
|
171
175
|
|
|
172
176
|
const wrapperRef = useRef<HTMLSpanElement>(null);
|
|
173
177
|
const elmRef = useRef<HTMLDivElement>(null);
|
|
174
|
-
const langRef = useRef<HTMLSpanElement>(null);
|
|
175
178
|
const closeMenu = useCallback(() => {
|
|
176
179
|
setIsOptionActive(false);
|
|
177
|
-
setIsLangActive(false);
|
|
178
180
|
}, []);
|
|
179
181
|
|
|
180
182
|
useOnClickOutside(
|
|
181
183
|
[elmRef, wrapperRef],
|
|
182
184
|
isOptionActive ? closeMenu : () => {},
|
|
183
185
|
);
|
|
184
|
-
useOnClickOutside([langRef, wrapperRef], isLangActive ? closeMenu : () => {});
|
|
185
186
|
const { isChatActive } = useContext(ChatContext);
|
|
186
187
|
const { openSearch } = useContext(SearchContext);
|
|
188
|
+
const t = useStrings();
|
|
187
189
|
|
|
188
190
|
return (
|
|
189
191
|
<StyledHeaderShell $pinned={isPinned} $height={headerHeight}>
|
|
@@ -223,11 +225,19 @@ function Header({ children }: HeaderProps) {
|
|
|
223
225
|
</Link>
|
|
224
226
|
{children}
|
|
225
227
|
<StyledLeftWrapper>
|
|
226
|
-
<StyledSearchButton
|
|
228
|
+
<StyledSearchButton
|
|
229
|
+
onClick={openSearch}
|
|
230
|
+
aria-label={t.searchButton}
|
|
231
|
+
>
|
|
227
232
|
<Search size={14} />
|
|
228
233
|
<SearchKbd>⌘K</SearchKbd>
|
|
229
234
|
</StyledSearchButton>
|
|
230
|
-
{isChatActive &&
|
|
235
|
+
{isChatActive && (
|
|
236
|
+
<ChatLauncher $glow aria-label={t.askAiAssistant}>
|
|
237
|
+
<Icon icon={Sparkles} />
|
|
238
|
+
{t.askAi}
|
|
239
|
+
</ChatLauncher>
|
|
240
|
+
)}
|
|
231
241
|
</StyledLeftWrapper>
|
|
232
242
|
</StyledHeaderInner>
|
|
233
243
|
</StyledHeader>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const sectionBarTemplate = "\"use client\";\nimport
|
|
1
|
+
export declare const sectionBarTemplate = "\"use client\";\nimport Link from \"next/link\";\nimport styled from \"styled-components\";\nimport { styledText } from \"cherry-styled-components\";\nimport { mq, Theme } from \"@/app/theme\";\nimport { useVariant } from \"@/components/useVariant\";\nimport { joinVariantSlug } from \"@/utils/variants\";\n\ninterface SectionConfig {\n label: string;\n slug: string;\n directory?: string;\n}\n\ninterface SectionBarProps {\n sections: SectionConfig[];\n /** Section slugs that have pages in each language/version prefix; a\n * section absent from the current prefix is not shown there. */\n variantSections?: Record<string, string[]>;\n}\n\nconst StyledSectionBar = styled.nav<{ theme: Theme }>`\n display: flex;\n order: 3;\n width: calc(100% + 20px);\n margin: 0 0 0 -10px;\n padding: 0;\n overflow-x: auto;\n -webkit-overflow-scrolling: touch;\n position: relative;\n\n &::-webkit-scrollbar {\n display: none;\n }\n\n ${mq(\"lg\")} {\n padding: 0 10px;\n order: unset;\n width: 100%;\n margin: 0;\n justify-content: flex-end;\n }\n`;\n\nconst StyledSectionLink = styled(Link)<{\n theme: Theme;\n $isActive: boolean;\n}>`\n ${({ theme }) => styledText(theme)};\n text-decoration: none;\n padding: 16px 10px;\n white-space: nowrap;\n font-weight: ${({ $isActive }) => ($isActive ? \"600\" : \"500\")};\n color: ${({ theme, $isActive }) =>\n $isActive ? theme.colors.primary : theme.colors.gray};\n border-bottom: solid 2px\n ${({ theme, $isActive }) =>\n $isActive ? theme.colors.primary : \"transparent\"};\n transition: all 0.3s ease;\n min-width: fit-content;\n position: relative;\n\n /* The section bar scrolls horizontally, and overflow-x:auto makes it clip\n vertically too, so an edge-drawn ring gets shaved top and bottom. Draw the\n ring on an inset pseudo-element so it sits fully inside the link and can't\n be clipped on any side. */\n &:focus-visible {\n outline: none;\n /* Opt out of the global a:focus-visible ring; the ::after below draws it\n inset so the scroll container can't clip it. */\n box-shadow: none;\n }\n\n &:focus-visible::after {\n content: \"\";\n position: absolute;\n inset: 3px;\n border: solid 2px ${({ theme }) => theme.colors.primaryLight};\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n pointer-events: none;\n }\n\n &:hover {\n color: ${({ theme }) => theme.colors.primary};\n }\n`;\n\nfunction SectionBar({ sections, variantSections }: SectionBarProps) {\n const { prefix, rest } = useVariant();\n const visibleSections = variantSections\n ? sections.filter((section) =>\n (variantSections[prefix] ?? []).includes(section.slug),\n )\n : sections;\n\n const activeSection = visibleSections.find((section) => {\n if (section.slug === \"\") return false;\n return rest === section.slug || rest.startsWith(section.slug + \"/\");\n });\n\n const activeSectionSlug = activeSection ? activeSection.slug : \"\";\n\n return (\n <StyledSectionBar>\n {visibleSections.map((section) => (\n <StyledSectionLink\n key={section.slug}\n href={\"/\" + joinVariantSlug(prefix, section.slug)}\n $isActive={activeSectionSlug === section.slug}\n >\n {section.label}\n </StyledSectionLink>\n ))}\n </StyledSectionBar>\n );\n}\n\nexport { SectionBar };\n";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export const sectionBarTemplate = `"use client";
|
|
2
|
-
import { usePathname } from "next/navigation";
|
|
3
2
|
import Link from "next/link";
|
|
4
3
|
import styled from "styled-components";
|
|
5
4
|
import { styledText } from "cherry-styled-components";
|
|
6
5
|
import { mq, Theme } from "@/app/theme";
|
|
6
|
+
import { useVariant } from "@/components/useVariant";
|
|
7
|
+
import { joinVariantSlug } from "@/utils/variants";
|
|
7
8
|
|
|
8
9
|
interface SectionConfig {
|
|
9
10
|
label: string;
|
|
@@ -13,6 +14,9 @@ interface SectionConfig {
|
|
|
13
14
|
|
|
14
15
|
interface SectionBarProps {
|
|
15
16
|
sections: SectionConfig[];
|
|
17
|
+
/** Section slugs that have pages in each language/version prefix; a
|
|
18
|
+
* section absent from the current prefix is not shown there. */
|
|
19
|
+
variantSections?: Record<string, string[]>;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
const StyledSectionBar = styled.nav<{ theme: Theme }>\`
|
|
@@ -81,25 +85,27 @@ const StyledSectionLink = styled(Link)<{
|
|
|
81
85
|
}
|
|
82
86
|
\`;
|
|
83
87
|
|
|
84
|
-
function SectionBar({ sections }: SectionBarProps) {
|
|
85
|
-
const
|
|
86
|
-
const
|
|
88
|
+
function SectionBar({ sections, variantSections }: SectionBarProps) {
|
|
89
|
+
const { prefix, rest } = useVariant();
|
|
90
|
+
const visibleSections = variantSections
|
|
91
|
+
? sections.filter((section) =>
|
|
92
|
+
(variantSections[prefix] ?? []).includes(section.slug),
|
|
93
|
+
)
|
|
94
|
+
: sections;
|
|
87
95
|
|
|
88
|
-
const activeSection =
|
|
96
|
+
const activeSection = visibleSections.find((section) => {
|
|
89
97
|
if (section.slug === "") return false;
|
|
90
|
-
return (
|
|
91
|
-
currentPath === section.slug || currentPath.startsWith(section.slug + "/")
|
|
92
|
-
);
|
|
98
|
+
return rest === section.slug || rest.startsWith(section.slug + "/");
|
|
93
99
|
});
|
|
94
100
|
|
|
95
101
|
const activeSectionSlug = activeSection ? activeSection.slug : "";
|
|
96
102
|
|
|
97
103
|
return (
|
|
98
104
|
<StyledSectionBar>
|
|
99
|
-
{
|
|
105
|
+
{visibleSections.map((section) => (
|
|
100
106
|
<StyledSectionLink
|
|
101
107
|
key={section.slug}
|
|
102
|
-
href={
|
|
108
|
+
href={"/" + joinVariantSlug(prefix, section.slug)}
|
|
103
109
|
$isActive={activeSectionSlug === section.slug}
|
|
104
110
|
>
|
|
105
111
|
{section.label}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const variantSwitchersTemplate = "\"use client\";\nimport { useRouter } from \"next/navigation\";\nimport styled, { css } from \"styled-components\";\nimport { Check, ChevronDown, Languages, Tag } from \"lucide-react\";\nimport { mq, Theme } from \"@/app/theme\";\nimport { Dropdown, DropdownItem } from \"@/components/layout/Dropdown\";\nimport { useStrings } from \"@/components/useStrings\";\nimport { useVariant } from \"@/components/useVariant\";\nimport type { PagesProps } from \"@/utils/orderNavItems\";\nimport {\n defaultLanguage,\n joinVariantSlug,\n languages,\n pageVariantPrefix,\n stripLanguagePrefix,\n stripVariantPrefix,\n variantPrefix,\n versions,\n} from \"@/utils/variants\";\n\n// The switchers share the footer row with the focus-mode toggle at its left\n// end and the theme toggle at its right. A lone pill claims only the width\n// its label needs; a pair grows from its labels' widths into the rail's free\n// width and gives up characters, never height, when that is not enough.\nconst StyledSwitchers = styled.div<{ $dense: boolean }>`\n display: flex;\n align-items: center;\n gap: 8px;\n min-width: 0;\n\n ${({ $dense }) =>\n $dense &&\n css`\n ${mq(\"lg\")} {\n flex: 1;\n }\n `}\n`;\n\n// One pill: its trigger carries the Lucide glyph, the current label, and a\n// chevron that turns while open.\nconst StyledSwitcher = styled.div<{ $dense: boolean }>`\n display: flex;\n min-width: 0;\n\n ${({ $dense }) =>\n $dense &&\n css`\n ${mq(\"lg\")} {\n flex: 1 1 auto;\n }\n `}\n`;\n\nconst truncatedLabel = css`\n flex: 1;\n overflow: hidden;\n text-align: left;\n text-overflow: ellipsis;\n white-space: nowrap;\n`;\n\n// Fills the trigger so the label takes the width and the chevron keeps the\n// right edge when the pill is stretched across the rail.\nconst StyledTriggerContent = styled.span<{ theme: Theme }>`\n display: flex;\n align-items: center;\n gap: 6px;\n width: 100%;\n min-width: 0;\n font-size: ${({ theme }) => theme.fontSizes.small.xs};\n font-weight: 600;\n line-height: 1;\n color: ${({ theme }) => theme.colors.accentStrong};\n\n /* The glyphs sit at the toggles' own resting color and pick up the accent\n on hover, so all four controls of the row light up the same way. */\n & svg {\n flex-shrink: 0;\n color: ${({ theme }) => theme.colors.primary};\n transition: color 0.3s ease;\n }\n\n & > svg:last-child {\n transition:\n color 0.3s ease,\n transform 0.3s ease;\n }\n\n button:hover > & svg {\n color: ${({ theme }) => theme.colors.accent};\n }\n\n [aria-expanded=\"true\"] > & > svg:last-child {\n transform: rotate(180deg);\n }\n`;\n\n// Below \"lg\" the sidebar is the full-width mobile menu, so every trigger shows\n// its glyph and full label there. On the rail the two of them share about\n// 130px beside the toggles: a lone switcher still spells its label out, while\n// a pair drops to the glyphless short form (a language's code, a version's\n// own label) rather than truncating both.\nconst StyledTriggerIcon = styled.span<{ $dense: boolean }>`\n display: flex;\n\n ${({ $dense }) =>\n $dense &&\n css`\n ${mq(\"lg\")} {\n display: none;\n }\n `}\n`;\n\nconst StyledTriggerLabel = styled.span<{ $dense: boolean }>`\n ${truncatedLabel};\n\n ${({ $dense }) =>\n $dense &&\n css`\n ${mq(\"lg\")} {\n display: none;\n }\n `}\n`;\n\nconst StyledTriggerShortLabel = styled.span`\n ${truncatedLabel};\n display: none;\n\n ${mq(\"lg\")} {\n display: block;\n }\n`;\n\n// Keeps every label aligned whether or not the entry carries the check mark.\nconst StyledItemMark = styled.span`\n display: flex;\n flex-shrink: 0;\n width: 14px;\n`;\n\ninterface SwitcherOption {\n value: string;\n label: string;\n /** Rail-sized form of the label; falls back to the label itself. */\n short?: string;\n}\n\ninterface VariantSwitcherProps {\n label: string;\n icon: React.ReactNode;\n options: SwitcherOption[];\n value: string;\n /** Which edge of the trigger the menu hangs from, so it opens into the\n sidebar rather than past one of its edges. */\n align: \"left\" | \"right\";\n /** Both switchers are on the row, so the rail shows the short labels. */\n dense: boolean;\n onSelect: (value: string) => void;\n}\n\n// One dropdown of radio items above its trigger: the platform's Dropdown, so\n// the language and version pickers look like every other menu on Doccupine.\nfunction VariantSwitcher({\n label,\n icon,\n options,\n value,\n align,\n dense,\n onSelect,\n}: VariantSwitcherProps) {\n const current = options.find((option) => option.value === value);\n const currentLabel = current?.label ?? label;\n return (\n <StyledSwitcher $dense={dense}>\n <Dropdown\n role=\"menu\"\n label={label}\n triggerLabel={`${label}: ${currentLabel}`}\n align={align}\n placement=\"top\"\n compact\n fullWidth={dense}\n trigger={\n <StyledTriggerContent>\n <StyledTriggerIcon $dense={dense}>{icon}</StyledTriggerIcon>\n <StyledTriggerLabel $dense={dense}>\n {currentLabel}\n </StyledTriggerLabel>\n {dense && (\n <StyledTriggerShortLabel>\n {current?.short ?? currentLabel}\n </StyledTriggerShortLabel>\n )}\n <ChevronDown size={12} aria-hidden=\"true\" />\n </StyledTriggerContent>\n }\n >\n {options.map((option) => (\n <DropdownItem\n key={option.value}\n type=\"button\"\n role=\"menuitemradio\"\n aria-checked={option.value === value}\n $checked={option.value === value}\n onClick={() => onSelect(option.value)}\n >\n <StyledItemMark aria-hidden=\"true\">\n {option.value === value && <Check size={14} />}\n </StyledItemMark>\n {option.label}\n </DropdownItem>\n ))}\n </Dropdown>\n </StyledSwitcher>\n );\n}\n\ninterface VariantSwitchersProps {\n pages: PagesProps[];\n}\n\n// The language and version switchers on the sidebar footer row, between the\n// focus-mode and theme toggles. Each is rendered only when its file declares\n// at least two entries, so a site without languages.json or versions.json\n// renders nothing here and the row keeps just its two toggles.\nfunction VariantSwitchers({ pages }: VariantSwitchersProps) {\n const router = useRouter();\n const current = useVariant();\n const t = useStrings();\n const showLanguages = (languages?.length ?? 0) >= 2;\n const showVersions = (versions?.length ?? 0) >= 2;\n if (!showLanguages && !showVersions) return null;\n\n const currentSlug = joinVariantSlug(current.prefix, current.rest);\n const currentLocale = current.locale ?? defaultLanguage()?.code;\n const currentVersion = current.version ?? \"\";\n const go = (slug: string) => router.push(slug === \"\" ? \"/\" : \"/\" + slug);\n const hasPagesIn = (prefix: string) =>\n pages.some((page) => pageVariantPrefix(page) === prefix);\n\n // The same page in the target language when it exists, otherwise that\n // language's home for the current version, otherwise its default home.\n const switchLanguage = (code: string) => {\n const key = stripLanguagePrefix(currentSlug, currentLocale);\n const match = pages.find(\n (page) =>\n page.locale === code &&\n stripLanguagePrefix(page.slug, page.locale) === key,\n );\n if (match) return go(match.slug);\n const withVersion = variantPrefix(code, currentVersion);\n go(hasPagesIn(withVersion) ? withVersion : variantPrefix(code, \"\"));\n };\n\n // The same page in the target version for the current language when it\n // exists, otherwise that version's home for the current language.\n const switchVersion = (slug: string) => {\n const key = stripVariantPrefix(currentSlug, currentLocale, currentVersion);\n const match = pages.find(\n (page) =>\n (page.locale ?? currentLocale) === currentLocale &&\n (page.version ?? \"\") === slug &&\n stripVariantPrefix(page.slug, page.locale, page.version) === key,\n );\n go(match ? match.slug : variantPrefix(currentLocale, slug));\n };\n\n // A pair spreads across the rail, so the first menu hangs from its\n // trigger's left edge and the second from its right edge: either way the\n // menu opens over the sidebar instead of past one of its sides.\n const dense = showLanguages && showVersions;\n\n return (\n <StyledSwitchers $dense={dense}>\n {showLanguages && languages && (\n <VariantSwitcher\n label={t.language}\n icon={<Languages size={16} aria-hidden=\"true\" />}\n value={currentLocale ?? \"\"}\n align=\"left\"\n dense={dense}\n onSelect={switchLanguage}\n options={languages.map((language) => ({\n value: language.code,\n label: language.label,\n short: language.code.toUpperCase(),\n }))}\n />\n )}\n {showVersions && versions && (\n <VariantSwitcher\n label={t.version}\n icon={<Tag size={16} aria-hidden=\"true\" />}\n value={currentVersion}\n align={dense ? \"right\" : \"left\"}\n dense={dense}\n onSelect={switchVersion}\n options={versions.map((version) => ({\n value: version.slug,\n label: version.label,\n }))}\n />\n )}\n </StyledSwitchers>\n );\n}\n\nexport { VariantSwitchers };\n";
|