doccupine 0.0.134 → 0.0.135

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.
Files changed (85) hide show
  1. package/README.md +10 -9
  2. package/dist/index.js +222 -44
  3. package/dist/lib/metadata.d.ts +5 -0
  4. package/dist/lib/metadata.js +15 -4
  5. package/dist/lib/rss.d.ts +24 -0
  6. package/dist/lib/rss.js +137 -0
  7. package/dist/lib/structures.js +22 -2
  8. package/dist/templates/app/rssRoute.d.ts +11 -0
  9. package/dist/templates/app/rssRoute.js +30 -0
  10. package/dist/templates/components/Docs.d.ts +1 -1
  11. package/dist/templates/components/Docs.js +5 -2
  12. package/dist/templates/components/MDXComponents.d.ts +1 -1
  13. package/dist/templates/components/MDXComponents.js +29 -0
  14. package/dist/templates/components/SideBar.d.ts +1 -1
  15. package/dist/templates/components/SideBar.js +5 -2
  16. package/dist/templates/components/layout/ActionBar.d.ts +1 -1
  17. package/dist/templates/components/layout/ActionBar.js +44 -13
  18. package/dist/templates/components/layout/ApiPlayground.d.ts +1 -1
  19. package/dist/templates/components/layout/ApiPlayground.js +20 -28
  20. package/dist/templates/components/layout/Badge.d.ts +1 -0
  21. package/dist/templates/components/layout/Badge.js +455 -0
  22. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  23. package/dist/templates/components/layout/DocsComponents.js +5 -30
  24. package/dist/templates/components/layout/Prompt.d.ts +1 -0
  25. package/dist/templates/components/layout/Prompt.js +149 -0
  26. package/dist/templates/components/layout/Tooltip.d.ts +1 -0
  27. package/dist/templates/components/layout/Tooltip.js +222 -0
  28. package/dist/templates/components/layout/Tree.d.ts +1 -0
  29. package/dist/templates/components/layout/Tree.js +322 -0
  30. package/dist/templates/components/layout/TreeData.d.ts +1 -0
  31. package/dist/templates/components/layout/TreeData.js +131 -0
  32. package/dist/templates/components/layout/Update.d.ts +1 -1
  33. package/dist/templates/components/layout/Update.js +3 -0
  34. package/dist/templates/lib/rss.d.ts +1 -0
  35. package/dist/templates/lib/rss.js +78 -0
  36. package/dist/templates/mdx/accordion.mdx.d.ts +1 -1
  37. package/dist/templates/mdx/accordion.mdx.js +1 -1
  38. package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
  39. package/dist/templates/mdx/api-playground.mdx.js +1 -1
  40. package/dist/templates/mdx/badges.mdx.d.ts +1 -0
  41. package/dist/templates/mdx/badges.mdx.js +237 -0
  42. package/dist/templates/mdx/buttons.mdx.d.ts +1 -1
  43. package/dist/templates/mdx/buttons.mdx.js +1 -1
  44. package/dist/templates/mdx/callouts.mdx.d.ts +1 -1
  45. package/dist/templates/mdx/callouts.mdx.js +1 -1
  46. package/dist/templates/mdx/cards.mdx.d.ts +1 -1
  47. package/dist/templates/mdx/cards.mdx.js +1 -1
  48. package/dist/templates/mdx/color-swatches.mdx.d.ts +1 -1
  49. package/dist/templates/mdx/color-swatches.mdx.js +1 -1
  50. package/dist/templates/mdx/columns.mdx.d.ts +1 -1
  51. package/dist/templates/mdx/columns.mdx.js +1 -1
  52. package/dist/templates/mdx/components.mdx.d.ts +1 -1
  53. package/dist/templates/mdx/components.mdx.js +14 -2
  54. package/dist/templates/mdx/fields.mdx.d.ts +1 -1
  55. package/dist/templates/mdx/fields.mdx.js +1 -1
  56. package/dist/templates/mdx/frames.mdx.d.ts +1 -1
  57. package/dist/templates/mdx/frames.mdx.js +1 -1
  58. package/dist/templates/mdx/icons.mdx.d.ts +1 -1
  59. package/dist/templates/mdx/icons.mdx.js +1 -1
  60. package/dist/templates/mdx/image-and-embeds.mdx.d.ts +1 -1
  61. package/dist/templates/mdx/image-and-embeds.mdx.js +1 -1
  62. package/dist/templates/mdx/images-and-embeds.mdx.d.ts +1 -0
  63. package/dist/templates/mdx/images-and-embeds.mdx.js +118 -0
  64. package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
  65. package/dist/templates/mdx/mermaid.mdx.js +1 -1
  66. package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
  67. package/dist/templates/mdx/navigation.mdx.js +5 -1
  68. package/dist/templates/mdx/prompt.mdx.d.ts +1 -0
  69. package/dist/templates/mdx/prompt.mdx.js +69 -0
  70. package/dist/templates/mdx/steps.mdx.d.ts +1 -1
  71. package/dist/templates/mdx/steps.mdx.js +1 -1
  72. package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
  73. package/dist/templates/mdx/tabs.mdx.js +1 -1
  74. package/dist/templates/mdx/tooltips.mdx.d.ts +1 -0
  75. package/dist/templates/mdx/tooltips.mdx.js +57 -0
  76. package/dist/templates/mdx/tree.mdx.d.ts +1 -0
  77. package/dist/templates/mdx/tree.mdx.js +158 -0
  78. package/dist/templates/mdx/update.mdx.d.ts +1 -1
  79. package/dist/templates/mdx/update.mdx.js +42 -2
  80. package/dist/templates/package.js +1 -1
  81. package/package.json +2 -2
  82. package/dist/templates/mdx/platform/external-links.mdx.d.ts +0 -1
  83. package/dist/templates/mdx/platform/external-links.mdx.js +0 -47
  84. package/dist/templates/utils/apiAnchors.d.ts +0 -1
  85. package/dist/templates/utils/apiAnchors.js +0 -39
@@ -0,0 +1,149 @@
1
+ export const promptTemplate = `"use client";
2
+ import React from "react";
3
+ import styled from "styled-components";
4
+ import {
5
+ interactiveStyles,
6
+ styledSmall,
7
+ styledText,
8
+ } from "cherry-styled-components";
9
+ import { Theme } from "@/app/theme";
10
+ import { Icon } from "@/components/layout/Icon";
11
+ import { CopyButton } from "@/components/layout/CopyButton";
12
+
13
+ type PromptAction = "copy" | "cursor";
14
+
15
+ const CURSOR_DEEPLINK = "cursor://anysphere.cursor-deeplink/prompt?text=";
16
+
17
+ // The prompt body arrives as rendered MDX elements, but the copy and Cursor
18
+ // actions need plain text. Paragraphs and lists become separate lines and
19
+ // list items keep a "- " marker so the copied prompt stays readable.
20
+ function promptText(node: React.ReactNode): string {
21
+ if (node == null || typeof node === "boolean") return "";
22
+ if (typeof node === "string" || typeof node === "number") {
23
+ return String(node);
24
+ }
25
+ if (Array.isArray(node)) return node.map(promptText).join("");
26
+ if (React.isValidElement(node)) {
27
+ const element = node as React.ReactElement<{
28
+ children?: React.ReactNode;
29
+ }>;
30
+ const inner = promptText(element.props.children);
31
+ if (element.type === "p") return inner + "\\n\\n";
32
+ if (element.type === "ul" || element.type === "ol") return inner + "\\n";
33
+ if (element.type === "li") return "- " + inner + "\\n";
34
+ return inner;
35
+ }
36
+ return "";
37
+ }
38
+
39
+ const StyledPrompt = styled.div<{ theme: Theme }>\`
40
+ background: \${({ theme }) => theme.colors.light};
41
+ border: solid 1px \${({ theme }) => theme.colors.grayLight};
42
+ border-radius: \${({ theme }) => theme.spacing.radius.lg};
43
+ padding: 20px;
44
+ width: 100%;
45
+ \`;
46
+
47
+ const StyledPromptHeader = styled.div<{ theme: Theme }>\`
48
+ display: flex;
49
+ align-items: center;
50
+ gap: 10px;
51
+ margin: 0 0 15px;
52
+ \${({ theme }) => styledSmall(theme)};
53
+ font-weight: 700;
54
+ color: \${({ theme }) => theme.colors.dark};
55
+
56
+ & > svg.lucide {
57
+ flex-shrink: 0;
58
+ color: inherit;
59
+ }
60
+ \`;
61
+
62
+ const StyledPromptDescription = styled.span\`
63
+ flex: 1;
64
+ min-width: 0;
65
+ \`;
66
+
67
+ const StyledPromptActions = styled.span\`
68
+ display: flex;
69
+ align-items: center;
70
+ gap: 5px;
71
+ flex-shrink: 0;
72
+ \`;
73
+
74
+ // Matches the CopyButton chrome so the two actions read as one control
75
+ // group; a link rather than a button because it navigates to the Cursor
76
+ // deeplink.
77
+ const StyledCursorLink = styled.a<{ theme: Theme }>\`
78
+ \${interactiveStyles}
79
+ display: flex;
80
+ align-items: center;
81
+ gap: 5px;
82
+ background: \${({ theme }) => theme.colors.light};
83
+ border-color: \${({ theme }) => theme.colors.grayLight};
84
+ border-radius: \${({ theme }) => theme.spacing.radius.xs};
85
+ padding: 4px 8px;
86
+ font-size: 12px;
87
+ line-height: 16px;
88
+ font-weight: 600;
89
+ color: \${({ theme }) => theme.colors.grayDark};
90
+ text-decoration: none;
91
+
92
+ & svg.lucide {
93
+ margin: 0;
94
+ color: inherit;
95
+ }
96
+ \`;
97
+
98
+ const StyledPromptBody = styled.div<{ theme: Theme }>\`
99
+ \${({ theme }) => styledText(theme)};
100
+ color: \${({ theme }) => theme.colors.grayDark};
101
+ display: flex;
102
+ flex-direction: column;
103
+ gap: 20px;
104
+ \`;
105
+
106
+ interface PromptProps {
107
+ children: React.ReactNode;
108
+ description: string;
109
+ icon?: string;
110
+ actions?: PromptAction[];
111
+ }
112
+
113
+ function Prompt({
114
+ children,
115
+ description,
116
+ icon,
117
+ actions = ["copy"],
118
+ }: PromptProps) {
119
+ const text = promptText(children)
120
+ .replace(/\\n{3,}/g, "\\n\\n")
121
+ .trim();
122
+
123
+ return (
124
+ <StyledPrompt>
125
+ <StyledPromptHeader>
126
+ {icon ? <Icon name={icon} size={16} /> : null}
127
+ <StyledPromptDescription>{description}</StyledPromptDescription>
128
+ <StyledPromptActions>
129
+ {actions.includes("copy") && (
130
+ <CopyButton text={text} label="Copy prompt" size={16} />
131
+ )}
132
+ {actions.includes("cursor") && (
133
+ <StyledCursorLink
134
+ href={CURSOR_DEEPLINK + encodeURIComponent(text)}
135
+ aria-label="Open prompt in Cursor"
136
+ >
137
+ Cursor
138
+ <Icon name="arrow-up-right" size={12} />
139
+ </StyledCursorLink>
140
+ )}
141
+ </StyledPromptActions>
142
+ </StyledPromptHeader>
143
+ <StyledPromptBody>{children}</StyledPromptBody>
144
+ </StyledPrompt>
145
+ );
146
+ }
147
+
148
+ export { Prompt };
149
+ `;
@@ -0,0 +1 @@
1
+ export declare const tooltipTemplate = "\"use client\";\nimport { useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport Link from \"next/link\";\nimport styled, { css } from \"styled-components\";\nimport { styledSmall } from \"cherry-styled-components\";\nimport { Theme } from \"@/app/theme\";\n\n// Layout cannot be measured during SSR; fall back to useEffect there so\n// prerendering stays warning-free while the browser still measures before\n// paint.\nconst useIsomorphicLayoutEffect =\n typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\nconst VIEWPORT_MARGIN = 8;\n\nconst StyledTooltip = styled.span`\n position: relative;\n display: inline-block;\n`;\n\nconst StyledTooltipTrigger = styled.span<{ theme: Theme }>`\n cursor: help;\n text-decoration: underline dotted 1.5px;\n text-decoration-color: ${({ theme }) => theme.colors.gray};\n text-underline-offset: 4px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n\n &:focus-visible {\n outline: none;\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\n// The gap between trigger and bubble is padding on the positioner (not a\n// margin) so the pointer never crosses empty space on its way to the CTA\n// link, which would fire mouseleave and close the tooltip early.\nconst StyledTooltipBubble = styled.span<{\n theme: Theme;\n $isOpen: boolean;\n $placement: \"top\" | \"bottom\";\n $shift: number;\n}>`\n position: absolute;\n left: 50%;\n transform: translateX(calc(-50% + ${({ $shift }) => $shift}px));\n width: max-content;\n max-width: min(260px, calc(100vw - 16px));\n z-index: 10;\n opacity: 0;\n visibility: hidden;\n transition:\n opacity 0.2s ease,\n visibility 0.2s ease;\n\n ${({ $placement }) =>\n $placement === \"top\"\n ? css`\n bottom: 100%;\n padding-bottom: 8px;\n `\n : css`\n top: 100%;\n padding-top: 8px;\n `}\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n opacity: 1;\n visibility: visible;\n `}\n`;\n\nconst StyledTooltipContent = styled.span<{ theme: Theme }>`\n display: block;\n background: ${({ theme }) => theme.colors.light};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 10px 14px;\n ${({ theme }) => styledSmall(theme)};\n color: ${({ theme }) => theme.colors.grayDark};\n text-align: left;\n`;\n\nconst StyledTooltipHeadline = styled.span<{ theme: Theme }>`\n display: block;\n font-weight: 700;\n color: ${({ theme }) => theme.colors.dark};\n`;\n\nconst StyledTooltipCta = styled.a<{ theme: Theme }>`\n display: block;\n margin-top: 5px;\n font-weight: 700;\n color: ${({ theme }) => theme.colors.primary};\n text-decoration: none;\n transition: color 0.3s ease;\n\n &:hover {\n color: ${({ theme }) => theme.colors.primaryDark};\n }\n`;\n\ninterface TooltipProps {\n children: React.ReactNode;\n tip: string;\n headline?: string;\n cta?: string;\n href?: string;\n}\n\nfunction Tooltip({ children, tip, headline, cta, href }: TooltipProps) {\n const [isOpen, setIsOpen] = useState(false);\n const [placement, setPlacement] = useState<\"top\" | \"bottom\">(\"top\");\n const [shift, setShift] = useState(0);\n const wrapperRef = useRef<HTMLSpanElement>(null);\n const bubbleRef = useRef<HTMLSpanElement>(null);\n const tooltipId = useId();\n\n // Keep the bubble inside the viewport: shift it horizontally when the\n // trigger sits near a screen edge, and flip it below the trigger when\n // there is no room above. The hidden bubble still has layout, so it can\n // be measured the moment it opens.\n useIsomorphicLayoutEffect(() => {\n if (!isOpen) return;\n const wrapper = wrapperRef.current;\n const bubble = bubbleRef.current;\n if (!wrapper || !bubble) return;\n const triggerRect = wrapper.getBoundingClientRect();\n const bubbleRect = bubble.getBoundingClientRect();\n setPlacement(\n triggerRect.top - bubbleRect.height - VIEWPORT_MARGIN < 0\n ? \"bottom\"\n : \"top\",\n );\n const center = triggerRect.left + triggerRect.width / 2;\n const half = bubbleRect.width / 2;\n if (center - half < VIEWPORT_MARGIN) {\n setShift(VIEWPORT_MARGIN - (center - half));\n } else if (center + half > window.innerWidth - VIEWPORT_MARGIN) {\n setShift(window.innerWidth - VIEWPORT_MARGIN - (center + half));\n } else {\n setShift(0);\n }\n }, [isOpen]);\n\n // Touch devices have no hover and fire blur unreliably, so a tap anywhere\n // outside must close the tooltip explicitly.\n useEffect(() => {\n if (!isOpen) return;\n const closeOnOutsidePointer = (event: PointerEvent) => {\n const wrapper = wrapperRef.current;\n if (\n wrapper &&\n event.target instanceof Node &&\n !wrapper.contains(event.target)\n ) {\n setIsOpen(false);\n }\n };\n document.addEventListener(\"pointerdown\", closeOnOutsidePointer);\n return () =>\n document.removeEventListener(\"pointerdown\", closeOnOutsidePointer);\n }, [isOpen]);\n\n return (\n <StyledTooltip\n ref={wrapperRef}\n onMouseEnter={() => setIsOpen(true)}\n onMouseLeave={() => setIsOpen(false)}\n onFocus={() => setIsOpen(true)}\n onBlur={(e) =>\n !e.currentTarget.contains(e.relatedTarget) && setIsOpen(false)\n }\n onKeyDown={(e) => e.key === \"Escape\" && setIsOpen(false)}\n >\n {/* Click opens but never toggles closed: on touch, a tap can fire\n focus and click in the same gesture, and a toggle would close the\n tooltip the instant it opened. */}\n <StyledTooltipTrigger\n tabIndex={0}\n aria-describedby={tooltipId}\n onClick={() => setIsOpen(true)}\n >\n {children}\n </StyledTooltipTrigger>\n <StyledTooltipBubble\n ref={bubbleRef}\n id={tooltipId}\n role=\"tooltip\"\n $isOpen={isOpen}\n $placement={placement}\n $shift={shift}\n >\n <StyledTooltipContent>\n {headline && (\n <StyledTooltipHeadline>{headline}</StyledTooltipHeadline>\n )}\n {tip}\n {cta &&\n href &&\n (href.startsWith(\"/\") ? (\n <StyledTooltipCta as={Link} href={href}>\n {cta}\n </StyledTooltipCta>\n ) : (\n <StyledTooltipCta\n href={href}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n {cta}\n </StyledTooltipCta>\n ))}\n </StyledTooltipContent>\n </StyledTooltipBubble>\n </StyledTooltip>\n );\n}\n\nexport { Tooltip };\n";
@@ -0,0 +1,222 @@
1
+ export const tooltipTemplate = `"use client";
2
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
3
+ import Link from "next/link";
4
+ import styled, { css } from "styled-components";
5
+ import { styledSmall } from "cherry-styled-components";
6
+ import { Theme } from "@/app/theme";
7
+
8
+ // Layout cannot be measured during SSR; fall back to useEffect there so
9
+ // prerendering stays warning-free while the browser still measures before
10
+ // paint.
11
+ const useIsomorphicLayoutEffect =
12
+ typeof window === "undefined" ? useEffect : useLayoutEffect;
13
+
14
+ const VIEWPORT_MARGIN = 8;
15
+
16
+ const StyledTooltip = styled.span\`
17
+ position: relative;
18
+ display: inline-block;
19
+ \`;
20
+
21
+ const StyledTooltipTrigger = styled.span<{ theme: Theme }>\`
22
+ cursor: help;
23
+ text-decoration: underline dotted 1.5px;
24
+ text-decoration-color: \${({ theme }) => theme.colors.gray};
25
+ text-underline-offset: 4px;
26
+ border-radius: \${({ theme }) => theme.spacing.radius.xs};
27
+
28
+ &:focus-visible {
29
+ outline: none;
30
+ box-shadow: 0 0 0 2px \${({ theme }) => theme.colors.primaryLight};
31
+ }
32
+ \`;
33
+
34
+ // The gap between trigger and bubble is padding on the positioner (not a
35
+ // margin) so the pointer never crosses empty space on its way to the CTA
36
+ // link, which would fire mouseleave and close the tooltip early.
37
+ const StyledTooltipBubble = styled.span<{
38
+ theme: Theme;
39
+ $isOpen: boolean;
40
+ $placement: "top" | "bottom";
41
+ $shift: number;
42
+ }>\`
43
+ position: absolute;
44
+ left: 50%;
45
+ transform: translateX(calc(-50% + \${({ $shift }) => $shift}px));
46
+ width: max-content;
47
+ max-width: min(260px, calc(100vw - 16px));
48
+ z-index: 10;
49
+ opacity: 0;
50
+ visibility: hidden;
51
+ transition:
52
+ opacity 0.2s ease,
53
+ visibility 0.2s ease;
54
+
55
+ \${({ $placement }) =>
56
+ $placement === "top"
57
+ ? css\`
58
+ bottom: 100%;
59
+ padding-bottom: 8px;
60
+ \`
61
+ : css\`
62
+ top: 100%;
63
+ padding-top: 8px;
64
+ \`}
65
+
66
+ \${({ $isOpen }) =>
67
+ $isOpen &&
68
+ css\`
69
+ opacity: 1;
70
+ visibility: visible;
71
+ \`}
72
+ \`;
73
+
74
+ const StyledTooltipContent = styled.span<{ theme: Theme }>\`
75
+ display: block;
76
+ background: \${({ theme }) => theme.colors.light};
77
+ border: solid 1px \${({ theme }) => theme.colors.grayLight};
78
+ border-radius: \${({ theme }) => theme.spacing.radius.lg};
79
+ padding: 10px 14px;
80
+ \${({ theme }) => styledSmall(theme)};
81
+ color: \${({ theme }) => theme.colors.grayDark};
82
+ text-align: left;
83
+ \`;
84
+
85
+ const StyledTooltipHeadline = styled.span<{ theme: Theme }>\`
86
+ display: block;
87
+ font-weight: 700;
88
+ color: \${({ theme }) => theme.colors.dark};
89
+ \`;
90
+
91
+ const StyledTooltipCta = styled.a<{ theme: Theme }>\`
92
+ display: block;
93
+ margin-top: 5px;
94
+ font-weight: 700;
95
+ color: \${({ theme }) => theme.colors.primary};
96
+ text-decoration: none;
97
+ transition: color 0.3s ease;
98
+
99
+ &:hover {
100
+ color: \${({ theme }) => theme.colors.primaryDark};
101
+ }
102
+ \`;
103
+
104
+ interface TooltipProps {
105
+ children: React.ReactNode;
106
+ tip: string;
107
+ headline?: string;
108
+ cta?: string;
109
+ href?: string;
110
+ }
111
+
112
+ function Tooltip({ children, tip, headline, cta, href }: TooltipProps) {
113
+ const [isOpen, setIsOpen] = useState(false);
114
+ const [placement, setPlacement] = useState<"top" | "bottom">("top");
115
+ const [shift, setShift] = useState(0);
116
+ const wrapperRef = useRef<HTMLSpanElement>(null);
117
+ const bubbleRef = useRef<HTMLSpanElement>(null);
118
+ const tooltipId = useId();
119
+
120
+ // Keep the bubble inside the viewport: shift it horizontally when the
121
+ // trigger sits near a screen edge, and flip it below the trigger when
122
+ // there is no room above. The hidden bubble still has layout, so it can
123
+ // be measured the moment it opens.
124
+ useIsomorphicLayoutEffect(() => {
125
+ if (!isOpen) return;
126
+ const wrapper = wrapperRef.current;
127
+ const bubble = bubbleRef.current;
128
+ if (!wrapper || !bubble) return;
129
+ const triggerRect = wrapper.getBoundingClientRect();
130
+ const bubbleRect = bubble.getBoundingClientRect();
131
+ setPlacement(
132
+ triggerRect.top - bubbleRect.height - VIEWPORT_MARGIN < 0
133
+ ? "bottom"
134
+ : "top",
135
+ );
136
+ const center = triggerRect.left + triggerRect.width / 2;
137
+ const half = bubbleRect.width / 2;
138
+ if (center - half < VIEWPORT_MARGIN) {
139
+ setShift(VIEWPORT_MARGIN - (center - half));
140
+ } else if (center + half > window.innerWidth - VIEWPORT_MARGIN) {
141
+ setShift(window.innerWidth - VIEWPORT_MARGIN - (center + half));
142
+ } else {
143
+ setShift(0);
144
+ }
145
+ }, [isOpen]);
146
+
147
+ // Touch devices have no hover and fire blur unreliably, so a tap anywhere
148
+ // outside must close the tooltip explicitly.
149
+ useEffect(() => {
150
+ if (!isOpen) return;
151
+ const closeOnOutsidePointer = (event: PointerEvent) => {
152
+ const wrapper = wrapperRef.current;
153
+ if (
154
+ wrapper &&
155
+ event.target instanceof Node &&
156
+ !wrapper.contains(event.target)
157
+ ) {
158
+ setIsOpen(false);
159
+ }
160
+ };
161
+ document.addEventListener("pointerdown", closeOnOutsidePointer);
162
+ return () =>
163
+ document.removeEventListener("pointerdown", closeOnOutsidePointer);
164
+ }, [isOpen]);
165
+
166
+ return (
167
+ <StyledTooltip
168
+ ref={wrapperRef}
169
+ onMouseEnter={() => setIsOpen(true)}
170
+ onMouseLeave={() => setIsOpen(false)}
171
+ onFocus={() => setIsOpen(true)}
172
+ onBlur={(e) =>
173
+ !e.currentTarget.contains(e.relatedTarget) && setIsOpen(false)
174
+ }
175
+ onKeyDown={(e) => e.key === "Escape" && setIsOpen(false)}
176
+ >
177
+ {/* Click opens but never toggles closed: on touch, a tap can fire
178
+ focus and click in the same gesture, and a toggle would close the
179
+ tooltip the instant it opened. */}
180
+ <StyledTooltipTrigger
181
+ tabIndex={0}
182
+ aria-describedby={tooltipId}
183
+ onClick={() => setIsOpen(true)}
184
+ >
185
+ {children}
186
+ </StyledTooltipTrigger>
187
+ <StyledTooltipBubble
188
+ ref={bubbleRef}
189
+ id={tooltipId}
190
+ role="tooltip"
191
+ $isOpen={isOpen}
192
+ $placement={placement}
193
+ $shift={shift}
194
+ >
195
+ <StyledTooltipContent>
196
+ {headline && (
197
+ <StyledTooltipHeadline>{headline}</StyledTooltipHeadline>
198
+ )}
199
+ {tip}
200
+ {cta &&
201
+ href &&
202
+ (href.startsWith("/") ? (
203
+ <StyledTooltipCta as={Link} href={href}>
204
+ {cta}
205
+ </StyledTooltipCta>
206
+ ) : (
207
+ <StyledTooltipCta
208
+ href={href}
209
+ target="_blank"
210
+ rel="noopener noreferrer"
211
+ >
212
+ {cta}
213
+ </StyledTooltipCta>
214
+ ))}
215
+ </StyledTooltipContent>
216
+ </StyledTooltipBubble>
217
+ </StyledTooltip>
218
+ );
219
+ }
220
+
221
+ export { Tooltip };
222
+ `;
@@ -0,0 +1 @@
1
+ export declare const treeTemplate = "\"use client\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport styled, { css } from \"styled-components\";\nimport { Theme } from \"@/app/theme\";\nimport { Icon } from \"@/components/layout/Icon\";\nimport { thinScrollbar } from \"@/components/layout/SharedStyled\";\nimport type { TreeNode } from \"@/components/layout/TreeData\";\n\nconst TYPE_AHEAD_RESET_MS = 600;\n\ninterface FlatItem {\n node: TreeNode;\n parentId: string | null;\n}\n\n// The prose container styles every descendant \"ul li\" (bullet dots, padding,\n// min-height) at (0,1,2)+ specificity, so the tree's own lists and items use\n// && to reach (0,2,0) and win.\nconst StyledTree = styled.ul<{ theme: Theme }>`\n && {\n background: ${({ theme }) => theme.colors.light};\n border: solid 1px ${({ theme }) => theme.colors.grayLight};\n border-radius: ${({ theme }) => theme.spacing.radius.lg};\n padding: 12px;\n margin: 0;\n width: 100%;\n list-style: none;\n overflow-x: auto;\n ${thinScrollbar};\n }\n`;\n\nconst StyledTreeGroup = styled.ul<{ theme: Theme }>`\n && {\n list-style: none;\n margin: 0 0 0 13px;\n padding: 0 0 0 9px;\n border-left: solid 1px ${({ theme }) => theme.colors.grayLight};\n }\n`;\n\nconst StyledTreeRow = styled.span<{ theme: Theme; $isInteractive: boolean }>`\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 4px 6px;\n border-radius: ${({ theme }) => theme.spacing.radius.xs};\n transition: background 0.2s ease;\n\n ${({ $isInteractive, theme }) =>\n $isInteractive &&\n css`\n cursor: pointer;\n\n &:hover {\n background: ${theme.colors.grayLight};\n }\n `}\n`;\n\nconst StyledTreeItem = styled.li<{ theme: Theme }>`\n && {\n display: block;\n padding: 0;\n margin: 0;\n min-height: 0;\n outline: none;\n }\n\n &&::before {\n content: none;\n }\n\n &:focus-visible > ${StyledTreeRow} {\n box-shadow: 0 0 0 2px ${({ theme }) => theme.colors.primaryLight};\n }\n`;\n\nconst StyledTreeChevron = styled.span<{ theme: Theme; $isOpen: boolean }>`\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n width: 16px;\n height: 16px;\n color: ${({ theme }) => theme.colors.gray};\n transition: transform 0.2s ease;\n\n ${({ $isOpen }) =>\n $isOpen &&\n css`\n transform: rotate(90deg);\n `}\n`;\n\nconst StyledTreeSpacer = styled.span`\n flex-shrink: 0;\n width: 16px;\n height: 16px;\n`;\n\nconst StyledTreeIcon = styled.span<{ theme: Theme }>`\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n color: ${({ theme }) => theme.colors.gray};\n`;\n\nconst StyledTreeName = styled.span<{ theme: Theme; $isFolder: boolean }>`\n font-family: ${({ theme }) => theme.fonts.mono};\n font-size: 14px;\n line-height: 1.6;\n white-space: nowrap;\n color: ${({ theme, $isFolder }) =>\n $isFolder ? theme.colors.dark : theme.colors.grayDark};\n`;\n\ninterface TreeProps {\n nodes: TreeNode[];\n}\n\n// Renders the TreeNode data that the Tree compound in MDXComponents parses\n// out of either authoring syntax. Receiving plain data (never elements)\n// keeps the server/client boundary trivially serializable.\nfunction Tree({ nodes }: TreeProps) {\n // Open state is stored as overrides on top of each folder's defaultOpen so\n // nodes parsed after a re-render keep their authored state until toggled.\n const [overrides, setOverrides] = useState<Record<string, boolean>>({});\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const itemRefs = useRef<Map<string, HTMLLIElement>>(new Map());\n const typeAheadBuffer = useRef(\"\");\n const typeAheadTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n useEffect(\n () => () => {\n if (typeAheadTimer.current) clearTimeout(typeAheadTimer.current);\n },\n [],\n );\n\n const isOpen = useCallback(\n (node: TreeNode) => overrides[node.id] ?? node.defaultOpen,\n [overrides],\n );\n\n // The flattened list of currently visible items drives keyboard\n // navigation in document order.\n const visible = useMemo(() => {\n const out: FlatItem[] = [];\n const walk = (list: TreeNode[], parentId: string | null) => {\n list.forEach((node) => {\n out.push({ node, parentId });\n if (node.isFolder && isOpen(node)) {\n walk(node.children, node.id);\n }\n });\n };\n walk(nodes, null);\n return out;\n }, [nodes, isOpen]);\n\n // Roving tabindex: exactly one visible item is tabbable. Falls back to the\n // first item when focus points at a node hidden by a collapsed ancestor.\n const activeId = useMemo(() => {\n if (focusedId && visible.some((item) => item.node.id === focusedId)) {\n return focusedId;\n }\n return visible.length > 0 ? visible[0].node.id : null;\n }, [focusedId, visible]);\n\n const setOpen = (node: TreeNode, open: boolean) => {\n if (!node.isFolder || !node.openable) return;\n setOverrides((prev) => ({ ...prev, [node.id]: open }));\n };\n\n const focusItem = (id: string) => {\n setFocusedId(id);\n itemRefs.current.get(id)?.focus();\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>) => {\n if (event.ctrlKey || event.metaKey || event.altKey) return;\n const index = visible.findIndex((item) => item.node.id === activeId);\n if (index < 0) return;\n const current = visible[index];\n const node = current.node;\n const key = event.key;\n\n if (key === \"ArrowDown\") {\n event.preventDefault();\n if (index + 1 < visible.length) focusItem(visible[index + 1].node.id);\n } else if (key === \"ArrowUp\") {\n event.preventDefault();\n if (index > 0) focusItem(visible[index - 1].node.id);\n } else if (key === \"ArrowRight\") {\n event.preventDefault();\n if (!node.isFolder) return;\n if (!isOpen(node)) setOpen(node, true);\n else if (node.children.length > 0) focusItem(node.children[0].id);\n } else if (key === \"ArrowLeft\") {\n event.preventDefault();\n if (node.isFolder && isOpen(node) && node.openable) {\n setOpen(node, false);\n } else if (current.parentId) {\n focusItem(current.parentId);\n }\n } else if (key === \"Home\") {\n event.preventDefault();\n focusItem(visible[0].node.id);\n } else if (key === \"End\") {\n event.preventDefault();\n focusItem(visible[visible.length - 1].node.id);\n } else if (key === \"Enter\" || key === \" \") {\n event.preventDefault();\n setOpen(node, !isOpen(node));\n } else if (key === \"*\") {\n event.preventDefault();\n setOverrides((prev) => {\n const next = { ...prev };\n visible.forEach((item) => {\n if (\n item.parentId === current.parentId &&\n item.node.isFolder &&\n item.node.openable\n ) {\n next[item.node.id] = true;\n }\n });\n return next;\n });\n } else if (key.length === 1 && key !== \" \") {\n // Type-ahead: buffered characters jump to the next item whose name\n // starts with what was typed.\n if (typeAheadTimer.current) clearTimeout(typeAheadTimer.current);\n typeAheadBuffer.current += key.toLowerCase();\n typeAheadTimer.current = setTimeout(() => {\n typeAheadBuffer.current = \"\";\n }, TYPE_AHEAD_RESET_MS);\n const query = typeAheadBuffer.current;\n const start = query.length === 1 ? index + 1 : index;\n for (let offset = 0; offset < visible.length; offset++) {\n const item = visible[(start + offset) % visible.length];\n if (item.node.name.toLowerCase().startsWith(query)) {\n focusItem(item.node.id);\n break;\n }\n }\n }\n };\n\n const renderItems = (list: TreeNode[], level: number) =>\n list.map((node, index) => {\n const open = node.isFolder && isOpen(node);\n const isInteractive = node.isFolder && node.openable;\n return (\n <StyledTreeItem\n key={node.id}\n role=\"treeitem\"\n aria-level={level}\n aria-setsize={list.length}\n aria-posinset={index + 1}\n aria-expanded={node.isFolder ? open : undefined}\n tabIndex={node.id === activeId ? 0 : -1}\n ref={(element) => {\n if (element) itemRefs.current.set(node.id, element);\n else itemRefs.current.delete(node.id);\n }}\n onFocus={(event) => {\n // Focus events bubble through nested treeitems; without this a\n // child's focus would also mark every ancestor as focused.\n event.stopPropagation();\n setFocusedId(node.id);\n }}\n >\n {/* Safari does not reliably focus the item on click, so focus is\n set explicitly before toggling. */}\n <StyledTreeRow\n $isInteractive={isInteractive}\n onClick={(event) => {\n event.stopPropagation();\n focusItem(node.id);\n if (isInteractive) setOpen(node, !open);\n }}\n >\n {isInteractive ? (\n <StyledTreeChevron $isOpen={open} aria-hidden>\n <Icon name=\"ChevronRight\" size={14} />\n </StyledTreeChevron>\n ) : (\n <StyledTreeSpacer aria-hidden />\n )}\n <StyledTreeIcon aria-hidden>\n <Icon\n name={node.isFolder ? (open ? \"FolderOpen\" : \"Folder\") : \"File\"}\n size={16}\n />\n </StyledTreeIcon>\n <StyledTreeName $isFolder={node.isFolder}>\n {node.name}\n </StyledTreeName>\n </StyledTreeRow>\n {node.isFolder && open && node.children.length > 0 && (\n <StyledTreeGroup role=\"group\">\n {renderItems(node.children, level + 1)}\n </StyledTreeGroup>\n )}\n </StyledTreeItem>\n );\n });\n\n if (nodes.length === 0) return null;\n\n return (\n <StyledTree role=\"tree\" aria-label=\"File tree\" onKeyDown={handleKeyDown}>\n {renderItems(nodes, 1)}\n </StyledTree>\n );\n}\n\nexport { Tree };\n";