@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
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
 
3
3
  // src/modules/agent-actions/agent-actions.tsx
4
- import { AnimatedIconSwap } from "@publish.os/nextjs/kernel/components/blocks/animated-icon-swap";
4
+ import { AnimatedIconSwap } from "@components/blocks/animated-icon-swap";
5
5
  import {
6
6
  Button,
7
7
  buttonVariants
8
- } from "@publish.os/nextjs/kernel/components/ui/button";
9
- import { ButtonGroup, ButtonGroupSeparator } from "@publish.os/nextjs/kernel/components/ui/button-group";
8
+ } from "@components/ui/button";
9
+ import { ButtonGroup, ButtonGroupSeparator } from "@components/ui/button-group";
10
10
  import {
11
11
  Menu,
12
12
  MenuGroup,
@@ -18,7 +18,7 @@ import {
18
18
  MenuPositioner,
19
19
  MenuSeparator,
20
20
  MenuTrigger
21
- } from "@publish.os/nextjs/kernel/components/ui/menu";
21
+ } from "@components/ui/menu";
22
22
  import {
23
23
  CaretDownIcon,
24
24
  CheckIcon,
@@ -27,14 +27,16 @@ import {
27
27
  } from "@phosphor-icons/react/ssr";
28
28
  import { cn } from "@publish.os/nextjs/utils/cn";
29
29
  import {
30
+ createContext,
30
31
  Fragment,
32
+ use,
31
33
  useCallback,
32
34
  useEffect,
33
35
  useRef,
34
36
  useState
35
37
  } from "react";
36
38
  import { flushSync } from "react-dom";
37
- import { jsx, jsxs } from "react/jsx-runtime";
39
+ import { jsx, jsxs } from "@publish.os/nextjs/jsx-runtime";
38
40
  var DEFAULT_PROMPT_SUFFIX = "I want to ask questions about it.", COPY_FEEDBACK_MS = 1600;
39
41
  function normalizePath(path) {
40
42
  let [pathname = "/"] = path.split(/[?#]/), prefixed = pathname.startsWith("/") ? pathname : `/${pathname}`;
@@ -120,7 +122,7 @@ var DEFAULT_PRIMARY_ACTION = {
120
122
  actions: [
121
123
  {
122
124
  id: "copy-page-markdown",
123
- title: "Copy page Markdown",
125
+ title: "Copy markdown",
124
126
  copy: "page-markdown"
125
127
  },
126
128
  {
@@ -130,7 +132,7 @@ var DEFAULT_PRIMARY_ACTION = {
130
132
  },
131
133
  {
132
134
  id: "copy-page-link",
133
- title: "Copy page link",
135
+ title: "Copy link",
134
136
  copy: "page-link"
135
137
  }
136
138
  ]
@@ -140,37 +142,67 @@ function resolveValue(value, context) {
140
142
  return typeof value == "function" ? value(context) : value;
141
143
  }
142
144
  async function copyText(text) {
143
- await navigator.clipboard?.writeText(text);
145
+ if (!navigator.clipboard?.writeText)
146
+ throw new Error("Clipboard access is not available in this browser.");
147
+ await navigator.clipboard.writeText(text);
144
148
  }
145
- function AgentActions({
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({
146
176
  actionGroups,
147
177
  buttonSize = "xs",
148
178
  buttonVariant = "outline",
149
179
  className,
150
180
  markdown,
151
181
  markdownPath,
182
+ markdownRevision,
152
183
  markdownUrl,
153
184
  menuLabel = "More agent actions",
185
+ markdownLinkLabel = "View as Markdown",
154
186
  pagePath,
155
187
  pageUrl,
156
188
  primaryAction,
157
189
  prompt,
158
190
  siteUrl,
159
191
  sourceUrl,
192
+ showMarkdownLink = !0,
193
+ children,
160
194
  ...props
161
195
  }) {
162
- let [copiedActionId, setCopiedActionId] = useState(), [menuOpen, setMenuOpen] = useState(!1), menuActionsRef = useRef(null), menuOpenRef = useRef(!1), resetTimerRef = useRef(
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(
163
197
  void 0
164
- ), setMenuOpenState = useCallback((open) => {
165
- menuOpenRef.current = open, setMenuOpen(open);
166
- }, []), closeMenu = useCallback(() => {
198
+ ), closeMenu = useCallback(() => {
167
199
  flushSync(() => {
168
200
  menuOpenRef.current = !1, setMenuOpen(!1), menuActionsRef.current?.close(), menuActionsRef.current?.unmount();
169
201
  });
170
202
  }, []);
171
- useEffect(() => (window.addEventListener("pagehide", closeMenu), window.addEventListener("pageshow", closeMenu), () => {
172
- window.removeEventListener("pagehide", closeMenu), window.removeEventListener("pageshow", closeMenu), resetTimerRef.current && clearTimeout(resetTimerRef.current);
173
- }), [closeMenu]);
203
+ useEffect(() => () => {
204
+ resetTimerRef.current && clearTimeout(resetTimerRef.current);
205
+ }, []);
174
206
  let resolvedPagePath = pagePath ?? "/", resolvedMarkdownPath = markdownPath ?? markdownPathForPagePath(resolvedPagePath), resolvedMarkdownUrl = absoluteUrl(
175
207
  markdownUrl ?? resolvedMarkdownPath,
176
208
  siteUrl
@@ -182,30 +214,140 @@ function AgentActions({
182
214
  pageUrl: absoluteUrl(pageUrl ?? resolvedPagePath, siteUrl),
183
215
  prompt: prompt ?? createPrompt(resolvedMarkdownUrl),
184
216
  sourceUrl
185
- }, resolvedPrimaryAction = primaryAction ?? DEFAULT_PRIMARY_ACTION, resolvedActionGroups = actionGroups ?? DEFAULT_ACTION_GROUPS, markCopied = (actionId) => {
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) => {
186
228
  resetTimerRef.current && clearTimeout(resetTimerRef.current), setCopiedActionId(actionId), resetTimerRef.current = setTimeout(() => {
187
229
  setCopiedActionId(void 0);
188
230
  }, COPY_FEEDBACK_MS);
189
- }, copyValueForAction = async (action) => {
190
- if (action.copy === "page-markdown") {
191
- if (context.markdownUrl)
192
- try {
193
- let response = await fetch(context.markdownUrl);
194
- if (response.ok) return response.text();
195
- } catch {
196
- return context.markdown ?? "";
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
+ );
197
306
  }
198
- return context.markdown ?? "";
307
+ );
308
+ return;
199
309
  }
200
- return action.copy === "page-link" ? context.pageUrl : action.copy === "markdown-link" ? context.markdownUrl : action.copy ?? "";
201
- }, handleAction = async (action) => {
202
- if (!resolveValue(action.disabled, context)) {
203
- if (action.copy) {
204
- let value = await copyValueForAction(action);
205
- value && (await copyText(value), markCopied(action.id));
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;
206
314
  }
207
- await action.onSelect?.(context);
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;
208
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));
209
351
  }, iconForAction = (action) => {
210
352
  let copied = copiedActionId === action.id;
211
353
  return action.copy === "page-markdown" ? /* @__PURE__ */ jsx(
@@ -217,68 +359,132 @@ function AgentActions({
217
359
  size: 16
218
360
  }
219
361
  ) : copied ? /* @__PURE__ */ jsx(CheckIcon, { "aria-hidden": "true", className: "size-4" }) : action.icon;
220
- }, renderPrimaryAction = () => {
221
- let href = resolveValue(resolvedPrimaryAction.href, context), disabled = resolveValue(resolvedPrimaryAction.disabled, context), target = resolvedPrimaryAction.target ?? (resolvedPrimaryAction.openInNew ? "_blank" : void 0), rel = target === "_blank" ? mergeRel(resolvedPrimaryAction.rel) : void 0;
222
- return href && !resolvedPrimaryAction.copy && !resolvedPrimaryAction.onSelect ? /* @__PURE__ */ jsxs(
362
+ }, contextValue = {
363
+ buttonSize,
364
+ buttonVariant,
365
+ closeMenu,
366
+ copyFeedback,
367
+ menuActionsRef,
368
+ menuLabel,
369
+ menuOpen,
370
+ menuTriggerRef,
371
+ markdownLink: showMarkdownLink ? /* @__PURE__ */ jsxs(
223
372
  "a",
224
373
  {
225
- "aria-disabled": disabled ? "true" : void 0,
226
- className: cn(
227
- buttonVariants({
228
- iconOnly: !1,
229
- size: buttonSize,
230
- variant: buttonVariant
231
- }),
232
- disabled && "pointer-events-none opacity-50"
233
- ),
234
- "data-disabled": disabled ? "" : void 0,
235
- href: disabled ? void 0 : href,
236
- rel,
237
- target,
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,
238
377
  children: [
239
- iconForAction(resolvedPrimaryAction),
240
- /* @__PURE__ */ jsx("span", { children: resolvedPrimaryAction.title })
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 })
241
387
  ]
242
388
  }
243
- ) : /* @__PURE__ */ jsx(
244
- Button,
245
- {
246
- disabled: !!disabled,
247
- leftIcon: iconForAction(resolvedPrimaryAction),
248
- onClick: () => {
249
- handleAction(resolvedPrimaryAction);
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
+ ]
250
444
  },
251
- size: buttonSize,
252
- variant: buttonVariant,
253
- children: resolvedPrimaryAction.title
254
- }
255
- );
256
- }, renderMenuAction = (action) => {
257
- 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;
258
- return href && !action.copy && !action.onSelect && !disabled ? /* @__PURE__ */ jsx(
259
- MenuLinkItem,
260
- {
261
- closeOnClick: !0,
262
- href,
263
- onClick: closeMenu,
264
- rel,
265
- target,
266
- children: /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: label })
267
- },
268
- action.id
269
- ) : /* @__PURE__ */ jsx(
270
- MenuItem,
271
- {
272
- disabled: !!disabled,
273
- onClick: () => {
274
- handleAction(action);
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
+ ]
275
460
  },
276
- children: /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: label })
277
- },
278
- action.id
279
- );
461
+ action.id
462
+ );
463
+ },
464
+ resolvedActionGroups,
465
+ setMenuOpenState
280
466
  };
281
- return /* @__PURE__ */ jsxs(
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(
282
488
  "div",
283
489
  {
284
490
  className: cn(
@@ -286,68 +492,103 @@ function AgentActions({
286
492
  className
287
493
  ),
288
494
  "data-slot": "agent-actions",
289
- ...props,
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,
290
546
  children: [
291
- /* @__PURE__ */ jsxs(
292
- "a",
547
+ /* @__PURE__ */ jsx(
548
+ MenuTrigger,
293
549
  {
294
- 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",
295
- "data-slot": "agent-actions-markdown-link",
296
- href: resolvedMarkdownPath,
297
- children: [
298
- /* @__PURE__ */ jsx(
299
- MarkdownLogoIcon,
300
- {
301
- "aria-hidden": "true",
302
- className: "size-4 shrink-0",
303
- weight: "fill"
304
- }
305
- ),
306
- /* @__PURE__ */ jsx("span", { children: "View as Markdown" })
307
- ]
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" })
308
561
  }
309
562
  ),
310
- /* @__PURE__ */ jsxs(ButtonGroup, { children: [
311
- renderPrimaryAction(),
312
- /* @__PURE__ */ jsx(ButtonGroupSeparator, {}),
313
- /* @__PURE__ */ jsxs(
314
- Menu,
315
- {
316
- actionsRef: menuActionsRef,
317
- modal: !1,
318
- onOpenChange: setMenuOpenState,
319
- open: menuOpen,
320
- children: [
321
- /* @__PURE__ */ jsx(
322
- MenuTrigger,
323
- {
324
- "aria-label": menuLabel,
325
- className: cn(
326
- buttonVariants({
327
- iconOnly: !0,
328
- size: buttonSize,
329
- variant: buttonVariant
330
- }),
331
- "data-popup-open:rounded-r-button!"
332
- ),
333
- children: /* @__PURE__ */ jsx(CaretDownIcon, { "aria-hidden": "true", className: "size-4" })
334
- }
335
- ),
336
- /* @__PURE__ */ jsx(MenuPortal, { children: /* @__PURE__ */ jsx(MenuPositioner, { align: "end", children: /* @__PURE__ */ jsx(MenuPopup, { className: "min-w-56", children: resolvedActionGroups.map((group, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
337
- index > 0 ? /* @__PURE__ */ jsx(MenuSeparator, {}) : null,
338
- /* @__PURE__ */ jsxs(MenuGroup, { children: [
339
- group.title ? /* @__PURE__ */ jsx(MenuGroupLabel, { children: group.title }) : null,
340
- group.actions.map(renderMenuAction)
341
- ] })
342
- ] }, group.id)) }) }) })
343
- ]
344
- }
345
- )
346
- ] })
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)) }) }) })
347
567
  ]
348
568
  }
349
569
  );
350
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
+ });
351
584
  export {
352
- AgentActions
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
353
594
  };
@@ -0,0 +1,5 @@
1
+ import 'react/jsx-runtime';
2
+ export { AgentActionConfig, AgentActionContext, AgentActionCopyTarget, AgentActionGroup, AgentActions, AgentActionsProps, Feedback, Group, Item, MarkdownLink, Menu, PrimaryAction, Root, Toolbar } from './AgentActions.js';
3
+ import 'react';
4
+ import 'class-variance-authority/types';
5
+ import 'class-variance-authority';