@publish.os/nextjs 0.0.1-alpha.90 → 0.0.1-alpha.91

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 (223) hide show
  1. package/compiler-assets/nextjs/defaults/group/layout.tsx +1 -5
  2. package/compiler-assets/nextjs/defaults/group/page.tsx +31 -22
  3. package/compiler-assets/nextjs/defaults/project/next.config.mjs +19 -10
  4. package/compiler-assets/nextjs/defaults/project/tsconfig.json.template +10 -0
  5. package/compiler-assets/nextjs/defaults/root/css/components/code-block.css +18 -0
  6. package/compiler-assets/nextjs/shims/document.tsx +38 -0
  7. package/compiler-assets/nextjs/shims/generated-leaf-page.tsx +2 -0
  8. package/compiler-assets/nextjs/shims/global-layout.tsx +8 -42
  9. package/compiler-assets/nextjs/shims/global-not-found.tsx +69 -0
  10. package/compiler-assets/nextjs/shims/markdown-route.ts +2 -0
  11. package/compiler-assets/nextjs/shims/metadata-icons.tsx +39 -0
  12. package/compiler-assets/nextjs/shims/not-found-content.tsx +53 -0
  13. package/compiler-assets/nextjs/shims/not-found-navigation.tsx +60 -0
  14. package/compiler-assets/nextjs/shims/proxy.ts +126 -60
  15. package/compiler-assets/nextjs/shims/site-fenced-code-block.tsx +2 -6
  16. package/compiler-assets/nextjs/shims/site-mdx-components.tsx +28 -16
  17. package/compiler-assets/nextjs/shims/site-mdx.tsx +6 -1
  18. package/dist/{build-operation-2JAYBSKF.js → build-operation-5QMLXF7N.js} +29 -23
  19. package/dist/{button-c3WGnxIj.d.ts → button-BdCScEKi.d.ts} +3 -3
  20. package/dist/capture-local-source-WGGDIUU2.js +258 -0
  21. package/dist/chunk-22RSSUNV.js +13 -0
  22. package/dist/{chunk-WKTEO6RS.js → chunk-4BC2L2KA.js} +46 -12
  23. package/dist/{chunk-WDY4IK6Z.js → chunk-5J3YUNRY.js} +3 -10
  24. package/dist/chunk-5KAD7W53.js +248 -0
  25. package/dist/{chunk-DWA3ZRGW.js → chunk-6C65KV7O.js} +2 -2
  26. package/dist/{chunk-GGKFQ3MA.js → chunk-6D2E6UMD.js} +144 -70
  27. package/dist/{chunk-7OGTPSKI.js → chunk-7NY22B5U.js} +8 -3
  28. package/dist/chunk-EFO6AWXN.js +19 -0
  29. package/dist/{chunk-726GV2NF.js → chunk-F3AGNDF4.js} +100 -67
  30. package/dist/chunk-GBPLER5H.js +426 -0
  31. package/dist/chunk-IL4RJOKI.js +186 -0
  32. package/dist/{chunk-DLDFHU7Y.js → chunk-NNBJZPFM.js} +4 -2
  33. package/dist/{chunk-VO2I7MTM.js → chunk-ORIUWJBQ.js} +8 -6
  34. package/dist/{chunk-H6XILMZX.js → chunk-OXOFRXEI.js} +1806 -831
  35. package/dist/chunk-UYGCOWRF.js +1709 -0
  36. package/dist/{chunk-YLTOLYWM.js → chunk-WL75GQ5M.js} +6 -18
  37. package/dist/compiler.d.ts +15 -2
  38. package/dist/compiler.js +90 -21
  39. package/dist/components/blocks/agent-actions.d.ts +81 -0
  40. package/dist/components/blocks/agent-actions.js +594 -0
  41. package/dist/components/blocks/toc.d.ts +43 -0
  42. package/dist/components/blocks/toc.js +136 -0
  43. package/dist/components/ui/button.d.ts +5 -0
  44. package/dist/components/ui/button.js +94 -0
  45. package/dist/compose-CVBJRAF6.js +16 -0
  46. package/dist/config/createNextConfig.js +17 -3
  47. package/dist/{dev-operation-TZDVJCN7.js → dev-operation-OSHHWRWK.js} +121 -81
  48. package/dist/{framework-selection-X4U6Y6QC.js → framework-selection-ZVO323PK.js} +3 -2
  49. package/dist/ide-support-CU6Z5PVR.js +16 -0
  50. package/dist/index.d.ts +40 -1
  51. package/dist/jsx-dev-runtime.d.ts +6 -0
  52. package/dist/jsx-dev-runtime.js +100 -0
  53. package/dist/jsx-runtime.d.ts +7 -0
  54. package/dist/jsx-runtime.js +97 -0
  55. package/dist/kernel/components/blocks/AgentActions.d.ts +35 -6
  56. package/dist/kernel/components/blocks/AgentActions.js +383 -142
  57. package/dist/kernel/components/blocks/agent-actions.d.ts +5 -0
  58. package/dist/kernel/components/blocks/agent-actions.js +594 -0
  59. package/dist/kernel/components/blocks/animated-icon-swap.js +1 -1
  60. package/dist/kernel/components/blocks/color-palette.js +4 -4
  61. package/dist/kernel/components/blocks/logo-block.js +1 -1
  62. package/dist/kernel/components/blocks/nav-breadcrumb.js +2 -2
  63. package/dist/kernel/components/blocks/navbar.js +17 -17
  64. package/dist/kernel/components/blocks/navigation-progress.js +2 -2
  65. package/dist/kernel/components/blocks/next-prev.js +1 -1
  66. package/dist/kernel/components/blocks/page-list.js +2 -2
  67. package/dist/kernel/components/blocks/search.d.ts +1 -1
  68. package/dist/kernel/components/blocks/search.js +16 -17
  69. package/dist/kernel/components/blocks/sidebar-node.js +1 -1
  70. package/dist/kernel/components/blocks/sidebar.js +7 -4
  71. package/dist/kernel/components/blocks/theme-toggle.d.ts +1 -1
  72. package/dist/kernel/components/blocks/theme-toggle.js +5 -5
  73. package/dist/kernel/components/blocks/toc-client.d.ts +40 -0
  74. package/dist/kernel/components/blocks/toc-client.js +495 -0
  75. package/dist/kernel/components/blocks/toc.d.ts +19 -1
  76. package/dist/kernel/components/blocks/toc.js +121 -179
  77. package/dist/kernel/components/mdx/components/blockquote.js +1 -1
  78. package/dist/kernel/components/mdx/components/callout.js +1 -1
  79. package/dist/kernel/components/mdx/components/code-block.js +2 -2
  80. package/dist/kernel/components/mdx/components/copy-code-button.js +5 -4
  81. package/dist/kernel/components/mdx/components/figure-caption.d.ts +1 -1
  82. package/dist/kernel/components/mdx/components/figure-caption.js +3 -2
  83. package/dist/kernel/components/mdx/components/figure.d.ts +6 -2
  84. package/dist/kernel/components/mdx/components/figure.js +23 -13
  85. package/dist/kernel/components/mdx/components/footnotes.js +1 -1
  86. package/dist/kernel/components/mdx/components/heading-copy-link.js +1 -1
  87. package/dist/kernel/components/mdx/components/heading.js +6 -3
  88. package/dist/kernel/components/mdx/components/hr.js +2 -2
  89. package/dist/kernel/components/mdx/components/image-zoom.js +1 -1
  90. package/dist/kernel/components/mdx/components/image.d.ts +1 -1
  91. package/dist/kernel/components/mdx/components/image.js +21 -16
  92. package/dist/kernel/components/mdx/components/inline-code.js +1 -1
  93. package/dist/kernel/components/mdx/components/kbd.js +2 -2
  94. package/dist/kernel/components/mdx/components/link.d.ts +3 -3
  95. package/dist/kernel/components/mdx/components/link.js +2 -2
  96. package/dist/kernel/components/mdx/components/paragraph.js +1 -1
  97. package/dist/kernel/components/mdx/components/strikethrough.js +1 -1
  98. package/dist/kernel/components/mdx/components/table.js +2 -2
  99. package/dist/kernel/components/mdx/components/task-list.js +1 -1
  100. package/dist/kernel/components/mdx/components/video-player.d.ts +6 -2
  101. package/dist/kernel/components/mdx/components/video-player.js +6 -2
  102. package/dist/kernel/components/mdx/components/video.d.ts +5 -3
  103. package/dist/kernel/components/mdx/components/video.js +7 -5
  104. package/dist/kernel/components/mdx/error-boundary.d.ts +1 -1
  105. package/dist/kernel/components/mdx/error-boundary.js +2 -2
  106. package/dist/kernel/components/mdx/error-fallback.js +1 -1
  107. package/dist/kernel/components/mdx/mdx.d.ts +20 -10
  108. package/dist/kernel/components/mdx/mdx.js +231 -34
  109. package/dist/kernel/components/mdx/rehype-heading-ids.d.ts +1 -0
  110. package/dist/kernel/components/mdx/rehype-heading-ids.js +5 -3
  111. package/dist/kernel/components/mdx/types.d.ts +1 -1
  112. package/dist/kernel/components/next-image.d.ts +12 -0
  113. package/dist/kernel/components/next-image.js +61 -0
  114. package/dist/kernel/components/ui/accordion.js +1 -1
  115. package/dist/kernel/components/ui/breadcrumb-trail.d.ts +2 -2
  116. package/dist/kernel/components/ui/breadcrumb-trail.js +2 -2
  117. package/dist/kernel/components/ui/breadcrumb.d.ts +1 -1
  118. package/dist/kernel/components/ui/breadcrumb.js +4 -4
  119. package/dist/kernel/components/ui/button-group.d.ts +1 -1
  120. package/dist/kernel/components/ui/button-group.js +3 -3
  121. package/dist/kernel/components/ui/button.d.ts +56 -4
  122. package/dist/kernel/components/ui/button.js +43 -39
  123. package/dist/kernel/components/ui/card.js +1 -1
  124. package/dist/kernel/components/ui/dialog.js +1 -1
  125. package/dist/kernel/components/ui/drawer.js +1 -1
  126. package/dist/kernel/components/ui/input.d.ts +2 -2
  127. package/dist/kernel/components/ui/input.js +1 -1
  128. package/dist/kernel/components/ui/kbd.d.ts +1 -1
  129. package/dist/kernel/components/ui/kbd.js +1 -1
  130. package/dist/kernel/components/ui/link.d.ts +8 -2
  131. package/dist/kernel/components/ui/link.js +2 -2
  132. package/dist/kernel/components/ui/menu.js +1 -1
  133. package/dist/kernel/components/ui/mod-key.js +2 -2
  134. package/dist/kernel/components/ui/navigation-menu.js +1 -1
  135. package/dist/kernel/components/ui/popover.js +1 -1
  136. package/dist/kernel/components/ui/progress.js +1 -1
  137. package/dist/kernel/components/ui/scroll-area.d.ts +8 -8
  138. package/dist/kernel/components/ui/scroll-area.js +1 -1
  139. package/dist/kernel/components/ui/select.js +1 -1
  140. package/dist/kernel/components/ui/separator.js +1 -1
  141. package/dist/kernel/components/ui/table.js +1 -1
  142. package/dist/kernel/components/ui/tabs.js +1 -1
  143. package/dist/kernel/components/ui/tag.js +1 -1
  144. package/dist/kernel/components/ui/text.d.ts +1 -1
  145. package/dist/kernel/components/ui/text.js +1 -1
  146. package/dist/kernel/components/ui/toast.js +1 -1
  147. package/dist/kernel/components/ui/tooltip.js +1 -1
  148. package/dist/kernel/defaults.registry.d.ts +2 -15
  149. package/dist/kernel/defaults.registry.js +2 -17
  150. package/dist/kernel/routes/agent/markdown.d.ts +3 -0
  151. package/dist/kernel/routes/agent/markdown.js +219 -48
  152. package/dist/kernel/routes/layouts/group.d.ts +1 -1
  153. package/dist/kernel/routes/layouts/group.js +5 -7
  154. package/dist/kernel/routes/metadata/feed.d.ts +1 -1
  155. package/dist/kernel/routes/metadata/feed.js +109 -83
  156. package/dist/kernel/routes/metadata/llms.d.ts +11 -3
  157. package/dist/kernel/routes/metadata/llms.js +154 -57
  158. package/dist/kernel/routes/metadata/og-image.js +1 -1
  159. package/dist/kernel/routes/metadata/robots.d.ts +1 -1
  160. package/dist/kernel/routes/metadata/sitemap.d.ts +22 -3
  161. package/dist/kernel/routes/metadata/sitemap.js +183 -43
  162. package/dist/kernel/routes/not-found.d.ts +34 -0
  163. package/dist/kernel/routes/not-found.js +213 -0
  164. package/dist/kernel/routes/pages/group.d.ts +2 -2
  165. package/dist/kernel/routes/pages/group.js +1 -1
  166. package/dist/kernel/routes/pages/leaf.d.ts +30 -3
  167. package/dist/kernel/routes/pages/leaf.js +5 -4
  168. package/dist/kernel/routes/pages/root.d.ts +2 -2
  169. package/dist/kernel/routes/pages/root.js +1 -1
  170. package/dist/keyboard-shortcuts.js +1 -1
  171. package/dist/route-metadata-og-image-BeKKFHg7.d.ts +58 -0
  172. package/dist/search.js +7 -9
  173. package/dist/theme-scope.js +1 -1
  174. package/dist/{types-BzkZty3r.d.ts → types-J2w_puPF.d.ts} +1 -20
  175. package/dist/types-sM2g9nW0.d.ts +12 -0
  176. package/dist/types.d.ts +1 -0
  177. package/dist/utils/heading-ids.js +30 -11
  178. package/dist/utils/toc-selection.d.ts +7 -0
  179. package/dist/utils/toc-selection.js +14 -0
  180. package/dist/validate-local-source-SV44DBQT.js +16 -0
  181. package/dist/validate-publish-os-source-NZJF3TB2.js +14 -0
  182. package/init/seed/minimal/publish.os/assets/blog/hello-world.svg +13 -0
  183. package/init/seed/minimal/publish.os/assets/favicon.dark.svg +13 -0
  184. package/init/seed/minimal/publish.os/assets/favicon.svg +13 -0
  185. package/init/seed/minimal/publish.os/blog/content/hello-world.mdx +48 -0
  186. package/init/seed/minimal/publish.os/blog/content/series-a.mdx +11 -0
  187. package/init/seed/minimal/publish.os/blog/index.tsx +82 -0
  188. package/init/seed/minimal/publish.os/blog/layout.tsx +13 -0
  189. package/init/seed/minimal/publish.os/blog/page.tsx +76 -0
  190. package/init/seed/minimal/publish.os/components/blog/copy-link.tsx +64 -0
  191. package/init/seed/minimal/publish.os/docs/content/get-started.mdx +2 -3
  192. package/init/seed/minimal/publish.os/docs/content/groups.mdx +5 -6
  193. package/init/seed/minimal/publish.os/publish.os.config.json +6 -2
  194. package/init/seed/minimal/publish.os/theme.css +3 -3
  195. package/init/seed/minimal/seed.json +11 -4
  196. package/init/seed/scratch/publish.os/docs/content/get-started.mdx +1 -1
  197. package/init/seed/scratch/publish.os/publish.os.config.json +1 -1
  198. package/package.json +45 -20
  199. package/release/app/phosphor/package.json +3 -3
  200. package/release/app/phosphor/pnpm-lock.yaml.template +88 -75
  201. package/release/compiler/package.json +5 -3
  202. package/release/compiler/pnpm-lock.yaml.template +118 -74
  203. package/release/release.json +6 -6
  204. package/dist/button-CtzUJB8u.d.ts +0 -11
  205. package/dist/chunk-535TM4A5.js +0 -1455
  206. package/dist/chunk-B2V22WRT.js +0 -297
  207. package/dist/chunk-NECL5IBJ.js +0 -318
  208. package/dist/chunk-SVYGXXYR.js +0 -36
  209. package/dist/chunk-UF6ATARM.js +0 -1100
  210. package/dist/compose-NN23UJGC.js +0 -13
  211. package/dist/ide-support-ZNW7ODFY.js +0 -15
  212. package/dist/kernel/components/blocks/design-system-preview.d.ts +0 -61
  213. package/dist/kernel/components/blocks/design-system-preview.js +0 -667
  214. package/dist/kernel/components/blocks/link-playground.d.ts +0 -5
  215. package/dist/kernel/components/blocks/link-playground.js +0 -744
  216. package/dist/kernel/components/blocks/navigation-progress-playground.d.ts +0 -5
  217. package/dist/kernel/components/blocks/navigation-progress-playground.js +0 -629
  218. package/dist/kernel/components/ui/theme-toggle.d.ts +0 -24
  219. package/dist/kernel/components/ui/theme-toggle.js +0 -53
  220. package/dist/validate-local-source-XRL2Y7XE.js +0 -14
  221. package/dist/validate-publish-os-source-DAPZ4QGE.js +0 -12
  222. package/init/seed/minimal/publish.os/assets/favicon/favicon.dark.png +0 -0
  223. package/init/seed/minimal/publish.os/assets/favicon/favicon.png +0 -0
@@ -0,0 +1,594 @@
1
+ "use client";
2
+
3
+ // src/modules/agent-actions/agent-actions.tsx
4
+ import { AnimatedIconSwap } from "@components/blocks/animated-icon-swap";
5
+ import {
6
+ Button,
7
+ buttonVariants
8
+ } from "@components/ui/button";
9
+ import { ButtonGroup, ButtonGroupSeparator } from "@components/ui/button-group";
10
+ import {
11
+ Menu,
12
+ MenuGroup,
13
+ MenuGroupLabel,
14
+ MenuItem,
15
+ MenuLinkItem,
16
+ MenuPopup,
17
+ MenuPortal,
18
+ MenuPositioner,
19
+ MenuSeparator,
20
+ MenuTrigger
21
+ } from "@components/ui/menu";
22
+ import {
23
+ CaretDownIcon,
24
+ CheckIcon,
25
+ CopyIcon,
26
+ MarkdownLogoIcon
27
+ } from "@phosphor-icons/react/ssr";
28
+ import { cn } from "@publish.os/nextjs/utils/cn";
29
+ import {
30
+ createContext,
31
+ Fragment,
32
+ use,
33
+ useCallback,
34
+ useEffect,
35
+ useRef,
36
+ useState
37
+ } from "react";
38
+ import { flushSync } from "react-dom";
39
+ import { jsx, jsxs } from "@publish.os/nextjs/jsx-runtime";
40
+ var DEFAULT_PROMPT_SUFFIX = "I want to ask questions about it.", COPY_FEEDBACK_MS = 1600;
41
+ function normalizePath(path) {
42
+ let [pathname = "/"] = path.split(/[?#]/), prefixed = pathname.startsWith("/") ? pathname : `/${pathname}`;
43
+ return prefixed === "/" ? prefixed : prefixed.replace(/\/+$/, "");
44
+ }
45
+ function markdownPathForPagePath(path) {
46
+ let normalized = normalizePath(path);
47
+ return normalized === "/" ? "/index.md" : normalized.endsWith(".md") ? normalized : `${normalized}.md`;
48
+ }
49
+ function isAbsoluteUrl(url) {
50
+ return /^[a-z][a-z\d+\-.]*:/i.test(url);
51
+ }
52
+ function absoluteUrl(url, siteUrl) {
53
+ if (isAbsoluteUrl(url) || !siteUrl) return url;
54
+ try {
55
+ return new URL(url, siteUrl).toString();
56
+ } catch {
57
+ return url;
58
+ }
59
+ }
60
+ function mergeRel(rel) {
61
+ let values = new Set((rel ?? "").split(/\s+/).filter(Boolean));
62
+ return values.add("noreferrer"), Array.from(values).join(" ");
63
+ }
64
+ function createPrompt(markdownUrl) {
65
+ return `Read ${markdownUrl}, ${DEFAULT_PROMPT_SUFFIX}`;
66
+ }
67
+ function providerPromptUrl(baseUrl, prompt, param = "q") {
68
+ let url = new URL(baseUrl);
69
+ return url.searchParams.set(param, prompt), url.toString();
70
+ }
71
+ var DEFAULT_PRIMARY_ACTION = {
72
+ id: "copy-page-markdown-primary",
73
+ title: "Copy Markdown",
74
+ copy: "page-markdown"
75
+ }, DEFAULT_ACTION_GROUPS = [
76
+ {
77
+ id: "open-in-ai",
78
+ title: "Open in",
79
+ actions: [
80
+ {
81
+ id: "open-claude",
82
+ title: "Claude",
83
+ href: ({ prompt }) => providerPromptUrl("https://claude.ai/new", prompt),
84
+ openInNew: !0
85
+ },
86
+ {
87
+ id: "open-chatgpt",
88
+ title: "ChatGPT",
89
+ href: ({ prompt }) => providerPromptUrl("https://chatgpt.com/?hints=search", prompt),
90
+ openInNew: !0
91
+ },
92
+ {
93
+ id: "open-cursor",
94
+ title: "Cursor",
95
+ href: ({ prompt }) => providerPromptUrl("https://cursor.com/link/prompt", prompt, "text"),
96
+ openInNew: !0
97
+ },
98
+ {
99
+ id: "open-copilot",
100
+ title: "Copilot",
101
+ href: ({ prompt }) => providerPromptUrl("https://copilot.microsoft.com/", prompt),
102
+ openInNew: !0
103
+ },
104
+ {
105
+ id: "open-t3-chat",
106
+ title: "T3 Chat",
107
+ href: ({ prompt }) => providerPromptUrl("https://t3.chat/new", prompt),
108
+ openInNew: !0
109
+ },
110
+ {
111
+ id: "open-github",
112
+ title: "GitHub source",
113
+ href: ({ sourceUrl }) => sourceUrl,
114
+ openInNew: !0,
115
+ disabled: ({ sourceUrl }) => !sourceUrl
116
+ }
117
+ ]
118
+ },
119
+ {
120
+ id: "page-actions",
121
+ title: "Page",
122
+ actions: [
123
+ {
124
+ id: "copy-page-markdown",
125
+ title: "Copy markdown",
126
+ copy: "page-markdown"
127
+ },
128
+ {
129
+ id: "view-page-markdown",
130
+ title: "View as Markdown",
131
+ href: ({ markdownPath }) => markdownPath
132
+ },
133
+ {
134
+ id: "copy-page-link",
135
+ title: "Copy link",
136
+ copy: "page-link"
137
+ }
138
+ ]
139
+ }
140
+ ];
141
+ function resolveValue(value, context) {
142
+ return typeof value == "function" ? value(context) : value;
143
+ }
144
+ async function copyText(text) {
145
+ if (!navigator.clipboard?.writeText)
146
+ throw new Error("Clipboard access is not available in this browser.");
147
+ await navigator.clipboard.writeText(text);
148
+ }
149
+ function revisionRequestPath(path, revision) {
150
+ if (!revision) return path;
151
+ let separator = path.includes("?") ? "&" : "?";
152
+ return `${path}${separator}publishos_revision=${encodeURIComponent(revision)}`;
153
+ }
154
+ async function markdownHash(text) {
155
+ if (!globalThis.crypto?.subtle)
156
+ throw new Error("This browser cannot verify the current Markdown version.");
157
+ let digest = await globalThis.crypto.subtle.digest(
158
+ "SHA-256",
159
+ new TextEncoder().encode(text)
160
+ );
161
+ return `sha256-${Array.from(
162
+ new Uint8Array(digest),
163
+ (byte) => byte.toString(16).padStart(2, "0")
164
+ ).join("").slice(0, 32)}`;
165
+ }
166
+ var AgentActionsContext = createContext(
167
+ null
168
+ );
169
+ function useAgentActions() {
170
+ let context = use(AgentActionsContext);
171
+ if (!context)
172
+ throw new Error("AgentActions parts must be inside AgentActions.Root.");
173
+ return context;
174
+ }
175
+ function AgentActionsProvider({
176
+ actionGroups,
177
+ buttonSize = "xs",
178
+ buttonVariant = "outline",
179
+ className,
180
+ markdown,
181
+ markdownPath,
182
+ markdownRevision,
183
+ markdownUrl,
184
+ menuLabel = "More agent actions",
185
+ markdownLinkLabel = "View as Markdown",
186
+ pagePath,
187
+ pageUrl,
188
+ primaryAction,
189
+ prompt,
190
+ siteUrl,
191
+ sourceUrl,
192
+ showMarkdownLink = !0,
193
+ children,
194
+ ...props
195
+ }) {
196
+ let [copiedActionId, setCopiedActionId] = useState(), [copyFeedback, setCopyFeedback] = useState(), [menuOpen, setMenuOpen] = useState(!1), menuTriggerRef = useRef(null), menuActionsRef = useRef(null), menuOpenRef = useRef(!1), markdownPreparationRef = useRef(null), currentMarkdownKeyRef = useRef(""), resetTimerRef = useRef(
197
+ void 0
198
+ ), closeMenu = useCallback(() => {
199
+ flushSync(() => {
200
+ menuOpenRef.current = !1, setMenuOpen(!1), menuActionsRef.current?.close(), menuActionsRef.current?.unmount();
201
+ });
202
+ }, []);
203
+ useEffect(() => () => {
204
+ resetTimerRef.current && clearTimeout(resetTimerRef.current);
205
+ }, []);
206
+ let resolvedPagePath = pagePath ?? "/", resolvedMarkdownPath = markdownPath ?? markdownPathForPagePath(resolvedPagePath), resolvedMarkdownUrl = absoluteUrl(
207
+ markdownUrl ?? resolvedMarkdownPath,
208
+ siteUrl
209
+ ), context = {
210
+ markdown,
211
+ markdownPath: resolvedMarkdownPath,
212
+ markdownUrl: resolvedMarkdownUrl,
213
+ pagePath: resolvedPagePath,
214
+ pageUrl: absoluteUrl(pageUrl ?? resolvedPagePath, siteUrl),
215
+ prompt: prompt ?? createPrompt(resolvedMarkdownUrl),
216
+ sourceUrl
217
+ }, markdownKey = `${context.markdownUrl}\0${markdownRevision ?? "unversioned"}`;
218
+ currentMarkdownKeyRef.current = markdownKey, useEffect(
219
+ () => () => {
220
+ markdownPreparationRef.current?.controller?.abort(), markdownPreparationRef.current = null;
221
+ },
222
+ []
223
+ ), useEffect(() => {
224
+ let preparation = markdownPreparationRef.current;
225
+ preparation && preparation.key !== markdownKey && (preparation.controller?.abort(), markdownPreparationRef.current = null, setCopyFeedback(void 0), setCopiedActionId(void 0));
226
+ }, [markdownKey]);
227
+ let resolvedPrimaryAction = primaryAction ?? DEFAULT_PRIMARY_ACTION, resolvedActionGroups = actionGroups ?? DEFAULT_ACTION_GROUPS, markCopied = (actionId) => {
228
+ resetTimerRef.current && clearTimeout(resetTimerRef.current), setCopiedActionId(actionId), resetTimerRef.current = setTimeout(() => {
229
+ setCopiedActionId(void 0);
230
+ }, COPY_FEEDBACK_MS);
231
+ }, markdownPreparation = () => {
232
+ let current = markdownPreparationRef.current;
233
+ if (current?.key === markdownKey) return current;
234
+ current?.controller?.abort();
235
+ let next = { key: markdownKey };
236
+ return markdownPreparationRef.current = next, next;
237
+ }, prepareMarkdown = () => {
238
+ if (context.markdown !== void 0 || !context.markdownUrl) return;
239
+ let record = markdownPreparation();
240
+ if (record.text !== void 0 || record.pending) return;
241
+ let controller = new AbortController();
242
+ record.controller = controller;
243
+ let requestPath = revisionRequestPath(
244
+ context.markdownPath,
245
+ markdownRevision
246
+ ), localPreview = process.env.NODE_ENV !== "production", request = async (cache) => {
247
+ let response;
248
+ try {
249
+ response = await fetch(requestPath, {
250
+ cache,
251
+ signal: controller.signal
252
+ });
253
+ } catch {
254
+ throw new Error("The Markdown page could not be loaded.");
255
+ }
256
+ if (!response.ok)
257
+ throw new Error(
258
+ `The Markdown page could not be loaded (${response.status}).`
259
+ );
260
+ return response.text();
261
+ }, pending = (async () => {
262
+ let firstBody = await request(localPreview ? "no-store" : "default");
263
+ if (!markdownRevision || await markdownHash(firstBody) === markdownRevision)
264
+ return firstBody;
265
+ let refreshedBody = await request(localPreview ? "no-store" : "reload");
266
+ if (await markdownHash(refreshedBody) !== markdownRevision)
267
+ throw new Error(
268
+ "The Markdown page changed while loading. Refresh the page and try again."
269
+ );
270
+ return refreshedBody;
271
+ })().then((text) => (markdownPreparationRef.current === record && currentMarkdownKeyRef.current === record.key && (record.text = text), text)).catch((error) => {
272
+ throw markdownPreparationRef.current === record && (markdownPreparationRef.current = null), error;
273
+ }).finally(() => {
274
+ record.pending = void 0, record.controller = void 0;
275
+ });
276
+ record.pending = pending, pending.catch(() => {
277
+ });
278
+ }, setMenuOpenState = (open) => {
279
+ menuOpenRef.current = open, setMenuOpen(open), open && resolvedActionGroups.some(
280
+ (group) => group.actions.some(
281
+ (action) => action.copy === "page-markdown" && !resolveValue(action.disabled, context)
282
+ )
283
+ ) && prepareMarkdown();
284
+ }, prepareAction = (action) => {
285
+ action.copy === "page-markdown" && !resolveValue(action.disabled, context) && prepareMarkdown();
286
+ }, finishAction = async (action, clipboardWrite, actionMarkdownKey) => {
287
+ try {
288
+ if (await clipboardWrite, actionMarkdownKey && currentMarkdownKeyRef.current !== actionMarkdownKey)
289
+ return;
290
+ markCopied(action.id), setCopyFeedback("Copied to clipboard."), await action.onSelect?.(context);
291
+ } catch (error) {
292
+ if (actionMarkdownKey && currentMarkdownKeyRef.current !== actionMarkdownKey)
293
+ return;
294
+ setCopyFeedback(
295
+ error instanceof Error ? `${error.message} Try again.` : "The action failed. Try again."
296
+ );
297
+ }
298
+ }, handleAction = (action) => {
299
+ if (resolveValue(action.disabled, context)) return;
300
+ if (setCopyFeedback(void 0), setCopiedActionId(void 0), !action.copy) {
301
+ Promise.resolve(action.onSelect?.(context)).catch(
302
+ (error) => {
303
+ setCopyFeedback(
304
+ error instanceof Error ? `${error.message} Try again.` : "The action failed. Try again."
305
+ );
306
+ }
307
+ );
308
+ return;
309
+ }
310
+ if (action.copy === "page-markdown" && context.markdown === void 0) {
311
+ if (!context.markdownUrl) {
312
+ setCopyFeedback("The Markdown page URL is not available. Try again.");
313
+ return;
314
+ }
315
+ let record = markdownPreparation();
316
+ if (record.text !== void 0) {
317
+ if (!record.text) {
318
+ setCopyFeedback("There is no Markdown content to copy. Try again.");
319
+ return;
320
+ }
321
+ finishAction(action, copyText(record.text), record.key);
322
+ return;
323
+ }
324
+ setCopyFeedback("Preparing Markdown\u2026"), prepareMarkdown();
325
+ let pending = markdownPreparationRef.current?.pending;
326
+ if (!pending) return;
327
+ pending.then(
328
+ (text) => {
329
+ if (currentMarkdownKeyRef.current === record.key) {
330
+ if (!text) {
331
+ setCopyFeedback("There is no Markdown content to copy. Try again.");
332
+ return;
333
+ }
334
+ finishAction(action, copyText(text), record.key);
335
+ }
336
+ },
337
+ (error) => {
338
+ currentMarkdownKeyRef.current === record.key && setCopyFeedback(
339
+ error instanceof Error ? `${error.message} Try again.` : "The action failed. Try again."
340
+ );
341
+ }
342
+ );
343
+ return;
344
+ }
345
+ let value = action.copy === "page-markdown" ? context.markdown : action.copy === "page-link" ? context.pageUrl : action.copy === "markdown-link" ? context.markdownUrl : action.copy;
346
+ if (!value) {
347
+ setCopyFeedback("There is no Markdown content to copy. Try again.");
348
+ return;
349
+ }
350
+ finishAction(action, copyText(value));
351
+ }, iconForAction = (action) => {
352
+ let copied = copiedActionId === action.id;
353
+ return action.copy === "page-markdown" ? /* @__PURE__ */ jsx(
354
+ AnimatedIconSwap,
355
+ {
356
+ active: copied,
357
+ activeIcon: /* @__PURE__ */ jsx(CheckIcon, { "aria-hidden": "true", className: "size-4" }),
358
+ defaultIcon: action.icon ?? /* @__PURE__ */ jsx(CopyIcon, { "aria-hidden": "true", className: "size-4" }),
359
+ size: 16
360
+ }
361
+ ) : copied ? /* @__PURE__ */ jsx(CheckIcon, { "aria-hidden": "true", className: "size-4" }) : action.icon;
362
+ }, contextValue = {
363
+ buttonSize,
364
+ buttonVariant,
365
+ closeMenu,
366
+ copyFeedback,
367
+ menuActionsRef,
368
+ menuLabel,
369
+ menuOpen,
370
+ menuTriggerRef,
371
+ markdownLink: showMarkdownLink ? /* @__PURE__ */ jsxs(
372
+ "a",
373
+ {
374
+ className: "inline-flex min-h-7 items-center gap-1.5 text-xs font-medium text-foreground-2 no-underline transition-colors hover:text-foreground-1 hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-stroke motion-reduce:transition-none",
375
+ "data-slot": "agent-actions-markdown-link",
376
+ href: resolvedMarkdownPath,
377
+ children: [
378
+ /* @__PURE__ */ jsx(
379
+ MarkdownLogoIcon,
380
+ {
381
+ "aria-hidden": "true",
382
+ className: "size-4 shrink-0",
383
+ weight: "fill"
384
+ }
385
+ ),
386
+ /* @__PURE__ */ jsx("span", { children: markdownLinkLabel })
387
+ ]
388
+ }
389
+ ) : null,
390
+ renderPrimaryAction: (action = resolvedPrimaryAction) => {
391
+ let href = resolveValue(action.href, context), disabled = resolveValue(action.disabled, context), target = action.target ?? (action.openInNew ? "_blank" : void 0), rel = target === "_blank" ? mergeRel(action.rel) : void 0;
392
+ return href && !action.copy && !action.onSelect ? /* @__PURE__ */ jsxs(
393
+ "a",
394
+ {
395
+ "aria-disabled": disabled ? "true" : void 0,
396
+ className: cn(
397
+ buttonVariants({
398
+ iconOnly: !1,
399
+ size: buttonSize,
400
+ variant: buttonVariant
401
+ }),
402
+ disabled && "pointer-events-none opacity-50"
403
+ ),
404
+ "data-disabled": disabled ? "" : void 0,
405
+ href: disabled ? void 0 : href,
406
+ rel,
407
+ target,
408
+ children: [
409
+ iconForAction(action),
410
+ /* @__PURE__ */ jsx("span", { children: action.title })
411
+ ]
412
+ }
413
+ ) : /* @__PURE__ */ jsx(
414
+ Button,
415
+ {
416
+ disabled: !!disabled,
417
+ leftIcon: iconForAction(action),
418
+ onFocus: () => prepareAction(action),
419
+ onClick: () => {
420
+ handleAction(action);
421
+ },
422
+ onPointerDown: () => prepareAction(action),
423
+ onPointerEnter: () => prepareAction(action),
424
+ size: buttonSize,
425
+ variant: buttonVariant,
426
+ children: action.title
427
+ }
428
+ );
429
+ },
430
+ renderMenuAction: (action) => {
431
+ let href = resolveValue(action.href, context), disabled = resolveValue(action.disabled, context), target = action.target ?? (action.openInNew ? "_blank" : void 0), rel = target === "_blank" ? mergeRel(action.rel) : void 0, label = action.title;
432
+ return href && !action.copy && !action.onSelect && !disabled ? /* @__PURE__ */ jsxs(
433
+ MenuLinkItem,
434
+ {
435
+ closeOnClick: !0,
436
+ href,
437
+ onClick: closeMenu,
438
+ rel,
439
+ target,
440
+ children: [
441
+ action.icon ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "shrink-0", children: action.icon }) : null,
442
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: label })
443
+ ]
444
+ },
445
+ action.id
446
+ ) : /* @__PURE__ */ jsxs(
447
+ MenuItem,
448
+ {
449
+ disabled: !!disabled,
450
+ onFocus: () => prepareAction(action),
451
+ onClick: () => {
452
+ handleAction(action);
453
+ },
454
+ onPointerDown: () => prepareAction(action),
455
+ onPointerEnter: () => prepareAction(action),
456
+ children: [
457
+ action.icon ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "shrink-0", children: action.icon }) : null,
458
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: label })
459
+ ]
460
+ },
461
+ action.id
462
+ );
463
+ },
464
+ resolvedActionGroups,
465
+ setMenuOpenState
466
+ };
467
+ return /* @__PURE__ */ jsx(AgentActionsContext.Provider, { value: contextValue, children: children ?? /* @__PURE__ */ jsx(AgentActionsDefaultLayout, { className, ...props }) });
468
+ }
469
+ function AgentActionsDefaultLayout({
470
+ className,
471
+ ...props
472
+ }) {
473
+ return /* @__PURE__ */ jsxs(AgentActionsToolbar, { className, ...props, children: [
474
+ /* @__PURE__ */ jsx(AgentActionsMarkdownLink, {}),
475
+ /* @__PURE__ */ jsxs(ButtonGroup, { children: [
476
+ /* @__PURE__ */ jsx(AgentActionsPrimaryAction, {}),
477
+ /* @__PURE__ */ jsx(ButtonGroupSeparator, {}),
478
+ /* @__PURE__ */ jsx(AgentActionsMenu, {})
479
+ ] }),
480
+ /* @__PURE__ */ jsx(AgentActionsFeedback, {})
481
+ ] });
482
+ }
483
+ function AgentActionsToolbar({
484
+ className,
485
+ ...props
486
+ }) {
487
+ return /* @__PURE__ */ jsx(
488
+ "div",
489
+ {
490
+ className: cn(
491
+ "inline-flex flex-wrap items-center gap-x-3 gap-y-2",
492
+ className
493
+ ),
494
+ "data-slot": "agent-actions",
495
+ ...props
496
+ }
497
+ );
498
+ }
499
+ function AgentActionsMarkdownLink() {
500
+ return useAgentActions().markdownLink;
501
+ }
502
+ function AgentActionsPrimaryAction({ action }) {
503
+ return useAgentActions().renderPrimaryAction(action);
504
+ }
505
+ function AgentActionsFeedback() {
506
+ let { copyFeedback } = useAgentActions();
507
+ return /* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "sr-only", role: "status", children: copyFeedback });
508
+ }
509
+ function AgentActionsGroup({
510
+ title,
511
+ children
512
+ }) {
513
+ return /* @__PURE__ */ jsxs(MenuGroup, { children: [
514
+ title ? /* @__PURE__ */ jsx(MenuGroupLabel, { children: title }) : null,
515
+ children
516
+ ] });
517
+ }
518
+ function AgentActionsItem({ action }) {
519
+ return useAgentActions().renderMenuAction(action);
520
+ }
521
+ function AgentActionsMenu({ children }) {
522
+ let {
523
+ buttonSize,
524
+ buttonVariant,
525
+ closeMenu,
526
+ menuActionsRef,
527
+ menuLabel,
528
+ menuOpen,
529
+ menuTriggerRef,
530
+ resolvedActionGroups,
531
+ setMenuOpenState
532
+ } = useAgentActions();
533
+ return useEffect(() => {
534
+ let view = menuTriggerRef.current?.ownerDocument.defaultView;
535
+ if (view)
536
+ return view.addEventListener("pagehide", closeMenu), view.addEventListener("pageshow", closeMenu), () => {
537
+ view.removeEventListener("pagehide", closeMenu), view.removeEventListener("pageshow", closeMenu);
538
+ };
539
+ }, [closeMenu, menuTriggerRef]), /* @__PURE__ */ jsxs(
540
+ Menu,
541
+ {
542
+ actionsRef: menuActionsRef,
543
+ modal: !1,
544
+ onOpenChange: setMenuOpenState,
545
+ open: menuOpen,
546
+ children: [
547
+ /* @__PURE__ */ jsx(
548
+ MenuTrigger,
549
+ {
550
+ "aria-label": menuLabel,
551
+ ref: menuTriggerRef,
552
+ className: cn(
553
+ buttonVariants({
554
+ iconOnly: !0,
555
+ size: buttonSize,
556
+ variant: buttonVariant
557
+ }),
558
+ "data-popup-open:rounded-r-button!"
559
+ ),
560
+ children: /* @__PURE__ */ jsx(CaretDownIcon, { "aria-hidden": "true", className: "size-4" })
561
+ }
562
+ ),
563
+ /* @__PURE__ */ jsx(MenuPortal, { children: /* @__PURE__ */ jsx(MenuPositioner, { align: "end", children: /* @__PURE__ */ jsx(MenuPopup, { className: "min-w-56", onClick: closeMenu, children: children ?? resolvedActionGroups.map((group, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
564
+ index > 0 ? /* @__PURE__ */ jsx(MenuSeparator, {}) : null,
565
+ /* @__PURE__ */ jsx(AgentActionsGroup, { title: group.title, children: group.actions.map((action) => /* @__PURE__ */ jsx(AgentActionsItem, { action }, action.id)) })
566
+ ] }, group.id)) }) }) })
567
+ ]
568
+ }
569
+ );
570
+ }
571
+ function AgentActionsRoot(props) {
572
+ return /* @__PURE__ */ jsx(AgentActionsProvider, { ...props });
573
+ }
574
+ var AgentActions = Object.assign(AgentActionsRoot, {
575
+ Feedback: AgentActionsFeedback,
576
+ Group: AgentActionsGroup,
577
+ Item: AgentActionsItem,
578
+ MarkdownLink: AgentActionsMarkdownLink,
579
+ Menu: AgentActionsMenu,
580
+ PrimaryAction: AgentActionsPrimaryAction,
581
+ Root: AgentActionsRoot,
582
+ Toolbar: AgentActionsToolbar
583
+ });
584
+ export {
585
+ AgentActions,
586
+ AgentActionsFeedback as Feedback,
587
+ AgentActionsGroup as Group,
588
+ AgentActionsItem as Item,
589
+ AgentActionsMarkdownLink as MarkdownLink,
590
+ AgentActionsMenu as Menu,
591
+ AgentActionsPrimaryAction as PrimaryAction,
592
+ AgentActionsRoot as Root,
593
+ AgentActionsToolbar as Toolbar
594
+ };
@@ -0,0 +1,43 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ declare function TocDesktop({ children }: {
5
+ children?: ReactNode;
6
+ }): react_jsx_runtime.JSX.Element;
7
+ declare function TocMobile({ children }: {
8
+ children?: ReactNode;
9
+ }): react_jsx_runtime.JSX.Element;
10
+ declare function TocMobileHeader({ children }: {
11
+ children?: ReactNode;
12
+ }): react_jsx_runtime.JSX.Element;
13
+ declare function TocLinksSlot({ className, listClassName, viewport, }: {
14
+ className?: string;
15
+ listClassName?: string;
16
+ viewport?: "desktop" | "mobile";
17
+ }): react_jsx_runtime.JSX.Element;
18
+ declare function TocTitle({ children, className, ...props }: React.ComponentPropsWithoutRef<"span">): react_jsx_runtime.JSX.Element;
19
+
20
+ type TocProps = {
21
+ children?: ReactNode;
22
+ className?: string;
23
+ content?: string;
24
+ desktopClassName?: string;
25
+ desktopListClassName?: string;
26
+ levels?: [number, number];
27
+ listClassName?: string;
28
+ mobileClassName?: string;
29
+ mobileQuery?: string;
30
+ readingOffset?: number;
31
+ title?: string;
32
+ };
33
+ declare function TocRoot({ className, content, desktopClassName, desktopListClassName, levels, listClassName, mobileClassName, mobileQuery, readingOffset, title, children, }: TocProps): react_jsx_runtime.JSX.Element | null;
34
+ declare const Toc: typeof TocRoot & {
35
+ Desktop: typeof TocDesktop;
36
+ Links: typeof TocLinksSlot;
37
+ Mobile: typeof TocMobile;
38
+ MobileHeader: typeof TocMobileHeader;
39
+ Root: typeof TocRoot;
40
+ Title: typeof TocTitle;
41
+ };
42
+
43
+ export { Toc, type TocProps };