@parallelworks/ui 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/README.md +1 -1
  2. package/dist/{chunks/memoryStore-CC91S5LP.js → ai/adapter/memoryStore.js} +2 -2
  3. package/dist/ai/adapter/mock/index.js +2 -80
  4. package/dist/ai/adapter/mock/mockAdapter.js +81 -0
  5. package/dist/ai/adapter/openai/createOpenAIStream.js +33 -0
  6. package/dist/ai/adapter/openai/errors.js +37 -0
  7. package/dist/ai/adapter/openai/index.js +5 -333
  8. package/dist/ai/adapter/openai/openaiAdapter.js +54 -0
  9. package/dist/ai/adapter/openai/responses.js +108 -0
  10. package/dist/ai/adapter/openai/sse.js +112 -0
  11. package/dist/{chunks/types-Yy0NrerF.js → ai/adapter/types.js} +1 -1
  12. package/dist/ai/agent/classifier.js +12 -0
  13. package/dist/ai/agent/diff.js +223 -0
  14. package/dist/ai/agent/diffHighlight.js +101 -0
  15. package/dist/ai/agent/permissions.js +29 -0
  16. package/dist/ai/agent/toolfmt.js +383 -0
  17. package/dist/ai/agent/transcript.js +127 -0
  18. package/dist/ai/components/AllocationSelector.js +56 -0
  19. package/dist/ai/components/AttachmentManager.js +147 -0
  20. package/dist/ai/components/AttachmentUpload.js +179 -0
  21. package/dist/ai/components/BlockedGroupBanner.js +29 -0
  22. package/dist/ai/components/BranchNavigator.js +57 -0
  23. package/dist/ai/components/ChatEmptyState.js +171 -0
  24. package/dist/ai/components/ChatInput.js +265 -0
  25. package/dist/ai/components/ChatLayout.js +15 -0
  26. package/dist/ai/components/ChatMessage.js +341 -0
  27. package/dist/ai/components/ChatMessageList.js +301 -0
  28. package/dist/ai/components/ChatSidebar.js +345 -0
  29. package/dist/ai/components/ChatThread.js +198 -0
  30. package/dist/ai/components/ComposerChrome.js +50 -0
  31. package/dist/ai/components/ComposerFrame.js +33 -0
  32. package/dist/ai/components/DragOverlay.js +20 -0
  33. package/dist/ai/components/ModelSelector.js +343 -0
  34. package/dist/ai/components/ShareDialog.js +260 -0
  35. package/dist/ai/components/SlashMenu.js +91 -0
  36. package/dist/ai/components/agent/ActivityLine.js +151 -0
  37. package/dist/ai/components/agent/AgentMessageParts.js +721 -0
  38. package/dist/ai/components/agent/PermissionPicker.js +38 -0
  39. package/dist/ai/components/attachmentKeys.js +10 -0
  40. package/dist/ai/core/ChatProvider.js +848 -0
  41. package/dist/ai/core/KeyboardShortcutsProvider.js +9 -0
  42. package/dist/ai/core/chatReducer.js +223 -0
  43. package/dist/ai/core/config.js +46 -0
  44. package/dist/ai/core/events.js +4 -0
  45. package/dist/ai/core/exportConversation.js +42 -0
  46. package/dist/ai/core/greeting.js +38 -0
  47. package/dist/ai/core/parts.js +84 -0
  48. package/dist/ai/core/useDragDrop.js +36 -0
  49. package/dist/ai/core/useKeyboardShortcuts.js +77 -0
  50. package/dist/ai/core/useSSEStream.js +98 -0
  51. package/dist/ai/index.js +43 -6644
  52. package/dist/ai/strings.js +175 -0
  53. package/dist/ai/ui/Avatar.js +35 -0
  54. package/dist/ai/ui/Dropdown.js +110 -0
  55. package/dist/ai/ui/Markdown.js +79 -0
  56. package/dist/ai/ui/Notice.js +77 -0
  57. package/dist/ai/ui/codeBreaks.js +36 -0
  58. package/dist/ai/ui/prose.js +13 -0
  59. package/dist/ai/ui/sidebar.js +148 -0
  60. package/dist/ai/utils.js +23 -0
  61. package/dist/assets/editor.worker-DfmPPyOL.js +60 -0
  62. package/dist/assets/json.worker-Dqgjpq9F.js +92 -0
  63. package/dist/assets/yaml.worker-DLx0whrM.js +1441 -0
  64. package/dist/components/AddMenu.js +46 -0
  65. package/dist/components/Avatar.js +46 -0
  66. package/dist/{chunks/BareModal-BtRiQezg.js → components/BareModal.js} +1 -1
  67. package/dist/components/Breadcrumbs.js +83 -0
  68. package/dist/components/Button.js +83 -0
  69. package/dist/components/Callout.js +23 -0
  70. package/dist/components/Card.js +31 -0
  71. package/dist/components/CollapsiblePanel.js +77 -0
  72. package/dist/{chunks/ConfirmModal-aOR4O1QE.js → components/ConfirmModal.js} +4 -9
  73. package/dist/components/CopyToClipboard.js +81 -0
  74. package/dist/{chunks/Markdown-CM-FenNE.js → components/CreateModal.js} +9 -116
  75. package/dist/components/DescriptionList.js +42 -0
  76. package/dist/components/Dropdown.js +349 -0
  77. package/dist/components/EmptyState.js +27 -0
  78. package/dist/components/Filter.js +32 -0
  79. package/dist/components/FilterPill.js +13 -0
  80. package/dist/components/IconButton.js +34 -0
  81. package/dist/{chunks/Indicator-hBSIxOPK.js → components/Indicator.js} +1 -1
  82. package/dist/components/Input.js +88 -0
  83. package/dist/components/LetterBadge.js +13 -0
  84. package/dist/components/Listbox.js +123 -0
  85. package/dist/{chunks/Loader-BXoXTZGc.js → components/Loader.js} +1 -1
  86. package/dist/components/Markdown.js +15 -0
  87. package/dist/components/MultiSelect.js +171 -0
  88. package/dist/components/Overview.js +39 -0
  89. package/dist/components/PageHeader.js +194 -0
  90. package/dist/components/Pagination.js +35 -0
  91. package/dist/{chunks/Provider-CDYurraE.js → components/Provider.js} +13 -5
  92. package/dist/{chunks/RequiredMark-DfLdYbYZ.js → components/RequiredMark.js} +1 -1
  93. package/dist/components/SectionHeader.js +11 -0
  94. package/dist/components/SettingModeOption.js +30 -0
  95. package/dist/components/SettingRow.js +35 -0
  96. package/dist/components/SettingsCard.js +31 -0
  97. package/dist/components/SettingsGroup.js +17 -0
  98. package/dist/components/Sort.js +42 -0
  99. package/dist/components/StatusBadge.js +63 -0
  100. package/dist/components/SwitchToggle.js +59 -0
  101. package/dist/{chunks/SwitchToggleSmall-FcsaYSTs.js → components/SwitchToggleSmall.js} +1 -1
  102. package/dist/{chunks/Table-DU2MW8xz.js → components/Table.js} +3 -3
  103. package/dist/components/Toggle.js +20 -0
  104. package/dist/{chunks/Tooltip-K5HJr4_p.js → components/Tooltip.js} +2 -27
  105. package/dist/{chunks/StatusBadge-C1Blx_cW.js → components/dropdownUtils.js} +2 -63
  106. package/dist/{chunks/focus-D_iZJTW1.js → components/focus.js} +1 -1
  107. package/dist/components/ghostButton.js +7 -0
  108. package/dist/components/inputClasses.js +4 -0
  109. package/dist/components/keys.js +27 -0
  110. package/dist/components/relativeTime.js +32 -0
  111. package/dist/{chunks/useCssIsDark-DHr05dG2.js → components/useCssIsDark.js} +1 -1
  112. package/dist/{chunks/duration-BOv8Phl8.js → duration.js} +1 -1
  113. package/dist/editor/Editor.js +13 -0
  114. package/dist/editor/EditorField.js +53 -0
  115. package/dist/editor/FormCodePanel.js +173 -0
  116. package/dist/{chunks/Monaco-DJ8MW-Dq.js → editor/Monaco.js} +5 -26
  117. package/dist/editor/index.js +6 -1
  118. package/dist/editor/themes.js +91 -0
  119. package/dist/editor/workers.d.ts +5 -0
  120. package/dist/editor/workers.js +35 -0
  121. package/dist/editor/yaml.d.ts +9 -1
  122. package/dist/editor/yaml.js +15 -0
  123. package/dist/editor/yaml.worker.d.ts +1 -0
  124. package/dist/editor/yamlLanguage.d.ts +6 -0
  125. package/dist/editor/yamlLanguage.js +312 -0
  126. package/dist/file-explorer/FileExplorer.js +1405 -0
  127. package/dist/file-explorer/FileExplorerContext.js +370 -0
  128. package/dist/{chunks/CodePreviewEditor-YqQBz1YL.js → file-explorer/FilePreview/CodePreviewEditor.js} +3 -2
  129. package/dist/file-explorer/FilePreview/Inline.js +45 -0
  130. package/dist/file-explorer/FilePreview/StreamedBadge.js +16 -0
  131. package/dist/file-explorer/FilePreview/Viewer.js +526 -0
  132. package/dist/file-explorer/FilePreview/index.js +266 -0
  133. package/dist/file-explorer/FilePreview/parse.js +63 -0
  134. package/dist/file-explorer/FilePreview/previewCache.js +98 -0
  135. package/dist/file-explorer/FilePreview/previewType.js +151 -0
  136. package/dist/file-explorer/FilePreview/readCappedBytes.js +196 -0
  137. package/dist/file-explorer/FilePreview/useObjectBlobUrl.js +95 -0
  138. package/dist/file-explorer/FilePreview/useObjectText.js +109 -0
  139. package/dist/file-explorer/FilePreview/usePresignedUrl.js +73 -0
  140. package/dist/file-explorer/FileRow.js +165 -0
  141. package/dist/file-explorer/FileRowsWindow.js +92 -0
  142. package/dist/file-explorer/FileTable.js +172 -0
  143. package/dist/file-explorer/FileTableHeaders.js +49 -0
  144. package/dist/file-explorer/LoadMoreRow.js +46 -0
  145. package/dist/file-explorer/TreeView.js +376 -0
  146. package/dist/file-explorer/helpers.js +537 -0
  147. package/dist/file-explorer/index.js +7 -5671
  148. package/dist/file-explorer/lib/batch.js +39 -0
  149. package/dist/file-explorer/lib/errors.js +9 -0
  150. package/dist/file-explorer/lib/paging.js +124 -0
  151. package/dist/file-explorer/lib/utils.js +322 -0
  152. package/dist/file-explorer/toasts.js +400 -0
  153. package/dist/file-explorer/treeRows.js +73 -0
  154. package/dist/file-explorer/useNearEnd.js +27 -0
  155. package/dist/form/FieldWrapper.js +54 -0
  156. package/dist/form/Fields/BooleanField.js +51 -0
  157. package/dist/form/Fields/CheckboxGroupField.js +72 -0
  158. package/dist/form/Fields/ColorField.js +33 -0
  159. package/dist/form/Fields/DropdownField.js +49 -0
  160. package/dist/form/Fields/DurationField.js +130 -0
  161. package/dist/form/Fields/LabelField.js +19 -0
  162. package/dist/form/Fields/MultiDropdownField.js +40 -0
  163. package/dist/form/Fields/NumberField.js +51 -0
  164. package/dist/form/Fields/ObjectField.js +54 -0
  165. package/dist/form/Fields/RadioField.js +49 -0
  166. package/dist/form/Fields/RangeField.js +58 -0
  167. package/dist/form/Fields/ResourceOptionIcon.js +21 -0
  168. package/dist/form/Fields/StepField.js +6 -0
  169. package/dist/form/Fields/StringField.js +37 -0
  170. package/dist/form/Fields/TextAreaField.js +31 -0
  171. package/dist/form/Fields/durationValidity.js +11 -0
  172. package/dist/form/Form.js +643 -0
  173. package/dist/form/SpecialTypes/DropdownWrapper.js +30 -0
  174. package/dist/form/SpecialTypes/FormikCustomDropdown.js +122 -0
  175. package/dist/form/SpecialTypes/FormikCustomInput.js +111 -0
  176. package/dist/form/SpecialTypes/FormikMultiSelectDropdown.js +31 -0
  177. package/dist/form/SpecialTypes/FormikNumericInput.js +60 -0
  178. package/dist/form/Wizard/WizardContainer.js +138 -0
  179. package/dist/form/Wizard/WizardNavigation.js +92 -0
  180. package/dist/form/Wizard/WizardStepContent.js +35 -0
  181. package/dist/form/Wizard/WizardStepIndicator.js +108 -0
  182. package/dist/form/Wizard/useWizardState.js +118 -0
  183. package/dist/form/Wizard/utils.js +34 -0
  184. package/dist/form/fieldContext.js +26 -0
  185. package/dist/form/fieldRegistry.js +50 -0
  186. package/dist/form/index.js +17 -2321
  187. package/dist/{chunks/FieldWrapper-Cszwg-4B.js → form/lib.js} +2 -97
  188. package/dist/form/useParsedOpts.js +62 -0
  189. package/dist/form/usePrevious.js +11 -0
  190. package/dist/form/utils/checkShowIfObject.js +14 -0
  191. package/dist/form/utils/duration.js +69 -0
  192. package/dist/form/utils/getParentValue.js +23 -0
  193. package/dist/form/utils/getPlaceholder.js +9 -0
  194. package/dist/form/utils/getValueUsingPath.js +23 -0
  195. package/dist/form/utils/secondaryField.js +22 -0
  196. package/dist/graph/AnnotationBanner.js +141 -0
  197. package/dist/graph/Collapse.js +41 -0
  198. package/dist/graph/DependencyGraph.js +1398 -0
  199. package/dist/graph/JobSummary.js +104 -0
  200. package/dist/graph/MatrixGroup.js +107 -0
  201. package/dist/graph/Reveal.js +57 -0
  202. package/dist/graph/TreeView.js +711 -0
  203. package/dist/graph/index.js +1 -2519
  204. package/dist/graph/types.js +6 -0
  205. package/dist/icons.d.ts +4 -4
  206. package/dist/icons.js +5 -5
  207. package/dist/index.js +46 -599
  208. package/dist/list/ActionToolbar.js +184 -0
  209. package/dist/list/HoverCard.js +73 -0
  210. package/dist/list/ListPage.js +145 -0
  211. package/dist/list/ListPager.js +59 -0
  212. package/dist/list/ListTable.js +163 -0
  213. package/dist/list/ListViewControls.js +372 -0
  214. package/dist/list/RowContextMenu.js +351 -0
  215. package/dist/list/UserHoverCard.js +117 -0
  216. package/dist/list/index.js +11 -2
  217. package/dist/list/listSearch.js +137 -0
  218. package/dist/list/listView.js +210 -0
  219. package/dist/list/textEntry.js +10 -0
  220. package/dist/{chunks/logviewer-BTKuQWzw.js → logviewer/LogViewer.js} +4 -82
  221. package/dist/logviewer/index.js +2 -1
  222. package/dist/logviewer/segments.js +80 -0
  223. package/dist/safeUrl.d.ts +6 -0
  224. package/dist/safeUrl.js +22 -0
  225. package/package.json +7 -9
  226. package/dist/assets/editor.worker-BmHUIVG4.js +0 -14807
  227. package/dist/assets/json.worker-D8bJ92nw.js +0 -22207
  228. package/dist/assets/yaml.worker-C4gyGAko.js +0 -50201
  229. package/dist/chunks/PageHeader-0kG_iypP.js +0 -692
  230. package/dist/chunks/SwitchToggle-DShNdcao.js +0 -758
  231. package/dist/chunks/editor-Dk1rbV75.js +0 -361
  232. package/dist/chunks/list-CJm875m7.js +0 -1418
  233. /package/dist/{chunks/MarkdownImpl-CyeTVvSt.js → components/MarkdownImpl.js} +0 -0
@@ -0,0 +1,526 @@
1
+ import { useStrings } from "../../components/Provider.js";
2
+ import { DownloadFileIcon, FileIcon, LockIcon, MusicIcon, ZipIcon } from "../../icons.js";
3
+ import { positionKeys, withPositionKeys } from "../../components/keys.js";
4
+ import Loader from "../../components/Loader.js";
5
+ import Markdown from "../../components/Markdown.js";
6
+ import { formatFileSize, getFileExtension } from "../lib/utils.js";
7
+ import { CODE_PREVIEW_MAX_BYTES, CODE_PREVIEW_MAX_LINES, PDF_PREVIEW_MAX_BYTES, TABULAR_PREVIEW_MAX_BYTES, getMonacoLanguage } from "./previewType.js";
8
+ import { CorsIssuePreview } from "../helpers.js";
9
+ import { joinSource, parseDelimited, parseNotebook, stripAnsi } from "./parse.js";
10
+ import { countLines } from "./readCappedBytes.js";
11
+ import { useObjectBlobUrl } from "./useObjectBlobUrl.js";
12
+ import { useObjectText } from "./useObjectText.js";
13
+ import cx from "classnames";
14
+ import { Suspense, lazy, useCallback, useMemo, useState } from "react";
15
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
16
+ //#region src/file-explorer/FilePreview/Viewer.tsx
17
+ var CodePreviewEditor = lazy(() => import("./CodePreviewEditor.js"));
18
+ var PREVIEW_MARKDOWN_CONTROLS = {
19
+ table: { fullscreen: false },
20
+ mermaid: { fullscreen: false }
21
+ };
22
+ function FilePreviewViewer({ node, kind, url, urlLoading, urlError, zoom = 100, onDownload, storage = null }) {
23
+ const t = useStrings().fileExplorer;
24
+ const [reloadNonce, setReloadNonce] = useState(0);
25
+ const onCorsRetry = useCallback(async (opts) => {
26
+ if (opts?.silent) {
27
+ if (!url) return { corsError: true };
28
+ try {
29
+ (await fetch(url)).body?.cancel().catch(() => {});
30
+ return { corsError: false };
31
+ } catch {
32
+ return { corsError: true };
33
+ }
34
+ }
35
+ setReloadNonce((n) => n + 1);
36
+ return { corsError: false };
37
+ }, [url]);
38
+ if (urlError) return /* @__PURE__ */ jsx(NotPreviewable, {
39
+ icon: /* @__PURE__ */ jsx(FileIcon, { className: "h-9 w-9 theme-muted-text" }),
40
+ title: t.preview.errorTitle,
41
+ message: urlError,
42
+ onDownload
43
+ });
44
+ if (kind === "archive") return /* @__PURE__ */ jsx(NotPreviewable, {
45
+ icon: /* @__PURE__ */ jsx(ZipIcon, { className: "h-9 w-9 text-(--theme-link)" }),
46
+ title: t.preview.archiveTitle,
47
+ message: t.preview.archiveMessage,
48
+ onDownload
49
+ });
50
+ if (kind === "unsupported") return /* @__PURE__ */ jsx(NotPreviewable, {
51
+ icon: /* @__PURE__ */ jsx(FileIcon, { className: "h-9 w-9 theme-muted-text" }),
52
+ title: t.preview.unsupportedTitle,
53
+ message: t.preview.unsupportedMessage,
54
+ onDownload
55
+ });
56
+ if (urlLoading || !url) return /* @__PURE__ */ jsx("div", {
57
+ className: "flex h-full w-full items-center justify-center",
58
+ children: /* @__PURE__ */ jsx(Loader, {
59
+ size: 40,
60
+ text: t.preview.loading
61
+ })
62
+ });
63
+ switch (kind) {
64
+ case "image": return /* @__PURE__ */ jsx(ImageView, {
65
+ node,
66
+ url,
67
+ zoom,
68
+ onDownload
69
+ });
70
+ case "video": return /* @__PURE__ */ jsx(VideoView, {
71
+ node,
72
+ url,
73
+ onDownload
74
+ });
75
+ case "audio": return /* @__PURE__ */ jsx(AudioView, {
76
+ node,
77
+ url,
78
+ onDownload
79
+ });
80
+ case "pdf": return /* @__PURE__ */ jsx(PdfView, {
81
+ node,
82
+ url,
83
+ onDownload,
84
+ storage,
85
+ onCorsRetry
86
+ }, reloadNonce);
87
+ case "code": return /* @__PURE__ */ jsx(CodeView, {
88
+ node,
89
+ url,
90
+ onDownload,
91
+ storage,
92
+ onCorsRetry
93
+ }, reloadNonce);
94
+ case "csv": return /* @__PURE__ */ jsx(CsvView, {
95
+ node,
96
+ url,
97
+ onDownload,
98
+ storage,
99
+ onCorsRetry
100
+ }, reloadNonce);
101
+ case "notebook": return /* @__PURE__ */ jsx(NotebookView, {
102
+ node,
103
+ url,
104
+ onDownload,
105
+ storage,
106
+ onCorsRetry
107
+ }, reloadNonce);
108
+ default: return null;
109
+ }
110
+ }
111
+ function ImageView({ node, url, zoom, onDownload }) {
112
+ const [hasError, setHasError] = useState(false);
113
+ if (hasError) return /* @__PURE__ */ jsx(PreviewError, { onDownload });
114
+ const fit = zoom === 100;
115
+ return /* @__PURE__ */ jsx("div", {
116
+ className: "flex h-full w-full items-center justify-center overflow-auto bg-(--theme-app-bg) p-4",
117
+ children: /* @__PURE__ */ jsx("img", {
118
+ src: url,
119
+ alt: node.name,
120
+ className: cx("block rounded-md shadow-lg", fit && "object-contain"),
121
+ style: fit ? {
122
+ maxWidth: "100%",
123
+ maxHeight: "100%"
124
+ } : {
125
+ width: `${zoom}%`,
126
+ maxWidth: "none"
127
+ },
128
+ onError: () => setHasError(true)
129
+ })
130
+ });
131
+ }
132
+ function VideoView({ node, url, onDownload }) {
133
+ const [hasError, setHasError] = useState(false);
134
+ if (hasError) return /* @__PURE__ */ jsx(PreviewError, { onDownload });
135
+ return /* @__PURE__ */ jsx("div", {
136
+ className: "h-full w-full bg-black",
137
+ children: /* @__PURE__ */ jsx("video", {
138
+ src: url,
139
+ controls: true,
140
+ className: "h-full w-full object-contain",
141
+ "aria-label": node.name,
142
+ onError: () => setHasError(true)
143
+ })
144
+ });
145
+ }
146
+ function AudioView({ node, url, onDownload }) {
147
+ const [hasError, setHasError] = useState(false);
148
+ if (hasError) return /* @__PURE__ */ jsx(PreviewError, { onDownload });
149
+ return /* @__PURE__ */ jsx("div", {
150
+ className: "flex h-full w-full items-center justify-center p-6",
151
+ children: /* @__PURE__ */ jsxs("div", {
152
+ className: "flex w-full max-w-xl flex-col items-center gap-6",
153
+ children: [
154
+ /* @__PURE__ */ jsx("div", {
155
+ className: "flex h-28 w-28 items-center justify-center rounded-2xl bg-linear-to-br from-(--theme-element) to-(--theme-link) shadow-lg",
156
+ children: /* @__PURE__ */ jsx(MusicIcon, { className: "h-12 w-12 text-white" })
157
+ }),
158
+ /* @__PURE__ */ jsxs("div", {
159
+ className: "text-center",
160
+ children: [/* @__PURE__ */ jsx("div", {
161
+ className: "break-all font-medium",
162
+ children: node.name
163
+ }), /* @__PURE__ */ jsxs("div", {
164
+ className: "mt-0.5 text-xs theme-muted-text",
165
+ children: [node.contentType, typeof node.size === "number" && ` · ${formatFileSize(node.size)}`]
166
+ })]
167
+ }),
168
+ /* @__PURE__ */ jsx("audio", {
169
+ src: url,
170
+ controls: true,
171
+ className: "w-full",
172
+ "aria-label": node.name,
173
+ onError: () => setHasError(true)
174
+ })
175
+ ]
176
+ })
177
+ });
178
+ }
179
+ function PreviewError({ onDownload }) {
180
+ const t = useStrings().fileExplorer;
181
+ return /* @__PURE__ */ jsx(NotPreviewable, {
182
+ icon: /* @__PURE__ */ jsx(FileIcon, { className: "h-9 w-9 theme-muted-text" }),
183
+ title: t.preview.errorTitle,
184
+ message: t.preview.previewError,
185
+ onDownload
186
+ });
187
+ }
188
+ function PdfView({ node, url, onDownload, storage, onCorsRetry }) {
189
+ const { blobUrl, loading, error, tooLarge, corsError } = useObjectBlobUrl(url, {
190
+ enabled: true,
191
+ maxBytes: PDF_PREVIEW_MAX_BYTES,
192
+ knownSize: node.size,
193
+ mimeType: "application/pdf",
194
+ cacheKey: node.path
195
+ });
196
+ return /* @__PURE__ */ jsx(PreviewFetchState, {
197
+ loading,
198
+ tooLarge,
199
+ error,
200
+ corsError,
201
+ storage,
202
+ onCorsRetry,
203
+ onDownload,
204
+ children: blobUrl ? /* @__PURE__ */ jsx("iframe", {
205
+ src: blobUrl,
206
+ title: node.name,
207
+ className: "h-full w-full border-0 bg-(--theme-app-bg)"
208
+ }) : null
209
+ });
210
+ }
211
+ function CodeView({ node, url, onDownload, storage, onCorsRetry }) {
212
+ const t = useStrings().fileExplorer;
213
+ const language = getMonacoLanguage(node);
214
+ const [tail, setTail] = useState(false);
215
+ const { text, loading, error, tooLarge, truncated, corsError } = useObjectText(url, {
216
+ enabled: true,
217
+ maxBytes: CODE_PREVIEW_MAX_BYTES,
218
+ maxLines: CODE_PREVIEW_MAX_LINES,
219
+ knownSize: node.size,
220
+ cacheKey: node.path,
221
+ tail
222
+ });
223
+ const shownLines = useMemo(() => countLines(text ?? ""), [text]);
224
+ const canToggle = truncated || tail;
225
+ return /* @__PURE__ */ jsxs("div", {
226
+ className: "flex h-full w-full flex-col bg-(--theme-app-bg)",
227
+ children: [/* @__PURE__ */ jsxs("div", {
228
+ className: "flex shrink-0 items-center gap-2 border-b theme-border px-3.5 py-2",
229
+ children: [
230
+ /* @__PURE__ */ jsx("span", {
231
+ className: "truncate font-mono text-xs theme-muted-text",
232
+ children: node.name
233
+ }),
234
+ /* @__PURE__ */ jsx("span", { className: "flex-1" }),
235
+ truncated && text !== null && /* @__PURE__ */ jsx("span", {
236
+ className: "shrink-0 font-mono text-[11px] theme-muted-text",
237
+ children: tail ? t.preview.lastLines(shownLines) : t.preview.firstLines(shownLines)
238
+ }),
239
+ canToggle && /* @__PURE__ */ jsxs("div", {
240
+ className: "inline-flex shrink-0 overflow-hidden rounded-full border theme-border text-[11px]",
241
+ children: [/* @__PURE__ */ jsx("button", {
242
+ type: "button",
243
+ className: cx("cursor-pointer px-2 py-0.5", tail ? "theme-muted-text theme-hover" : "theme-element"),
244
+ onClick: () => setTail(false),
245
+ children: t.preview.head
246
+ }), /* @__PURE__ */ jsx("button", {
247
+ type: "button",
248
+ className: cx("cursor-pointer px-2 py-0.5", tail ? "theme-element" : "theme-muted-text theme-hover"),
249
+ onClick: () => setTail(true),
250
+ children: t.preview.tail
251
+ })]
252
+ }),
253
+ /* @__PURE__ */ jsxs("span", {
254
+ className: "inline-flex shrink-0 items-center gap-1 rounded-full border theme-border px-2 py-0.5 text-[11px] theme-muted-text",
255
+ children: [/* @__PURE__ */ jsx(LockIcon, { className: "h-2.5 w-2.5" }), t.readOnly]
256
+ })
257
+ ]
258
+ }), /* @__PURE__ */ jsx("div", {
259
+ className: "min-h-0 flex-1 overflow-hidden",
260
+ children: /* @__PURE__ */ jsx(PreviewFetchState, {
261
+ loading,
262
+ tooLarge,
263
+ error,
264
+ corsError,
265
+ storage,
266
+ onCorsRetry,
267
+ onDownload,
268
+ children: language === "markdown" ? /* @__PURE__ */ jsx("div", {
269
+ className: "h-full overflow-auto px-5 py-4",
270
+ children: /* @__PURE__ */ jsx(Markdown, {
271
+ controls: PREVIEW_MARKDOWN_CONTROLS,
272
+ children: text ?? ""
273
+ })
274
+ }) : /* @__PURE__ */ jsx(Suspense, {
275
+ fallback: /* @__PURE__ */ jsx(PreviewLoading, {}),
276
+ children: /* @__PURE__ */ jsx(CodePreviewEditor, {
277
+ value: text ?? "",
278
+ language
279
+ })
280
+ })
281
+ })
282
+ })]
283
+ });
284
+ }
285
+ /** Wrap code in a fenced block for the markdown renderer, using a fence long
286
+ * enough to survive backtick runs inside the content. */
287
+ function toFencedCode(text, language) {
288
+ const longestRun = (text.match(/`+/g) ?? []).reduce((max, run) => Math.max(max, run.length), 0);
289
+ const fence = "`".repeat(Math.max(3, longestRun + 1));
290
+ return `${fence}${language}\n${text}\n${fence}`;
291
+ }
292
+ function CsvView({ node, url, onDownload, storage, onCorsRetry }) {
293
+ const { text, loading, error, tooLarge, corsError } = useObjectText(url, {
294
+ enabled: true,
295
+ maxBytes: TABULAR_PREVIEW_MAX_BYTES,
296
+ maxLines: 502,
297
+ knownSize: node.size,
298
+ cacheKey: node.path
299
+ });
300
+ return /* @__PURE__ */ jsx(PreviewFetchState, {
301
+ loading,
302
+ tooLarge,
303
+ error,
304
+ corsError,
305
+ storage,
306
+ onCorsRetry,
307
+ onDownload,
308
+ children: /* @__PURE__ */ jsx(CsvTable, {
309
+ node,
310
+ text: text ?? ""
311
+ })
312
+ });
313
+ }
314
+ function CsvTable({ node, text }) {
315
+ const t = useStrings().fileExplorer;
316
+ const delimiter = getFileExtension(node.name) === "tsv" ? " " : ",";
317
+ const rows = parseDelimited(text, delimiter, 502);
318
+ const header = rows[0] ?? [];
319
+ const body = rows.slice(1);
320
+ const shown = body.slice(0, 500);
321
+ const truncated = body.length > 500;
322
+ const columnCount = Math.max(header.length, ...shown.map((r) => r.length));
323
+ return /* @__PURE__ */ jsxs("div", {
324
+ className: "flex h-full w-full flex-col bg-(--theme-app-bg)",
325
+ children: [/* @__PURE__ */ jsx("div", {
326
+ className: "min-h-0 flex-1 overflow-auto",
327
+ children: /* @__PURE__ */ jsxs("table", {
328
+ className: "w-full border-collapse font-mono text-xs",
329
+ children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", {
330
+ className: "sticky top-0 bg-(--theme-panel-bg)",
331
+ children: [/* @__PURE__ */ jsx("th", {
332
+ className: "w-11 border-b theme-border px-3.5 py-2 text-right font-semibold theme-muted-text",
333
+ children: "#"
334
+ }), positionKeys(columnCount, "column").map((key, i) => /* @__PURE__ */ jsx("th", {
335
+ className: "border-b theme-border px-3.5 py-2 text-left font-semibold",
336
+ children: header[i] ?? ""
337
+ }, key))]
338
+ }) }), /* @__PURE__ */ jsx("tbody", { children: withPositionKeys(shown, "row").map(({ key, item: row }, r) => /* @__PURE__ */ jsxs("tr", {
339
+ className: cx(r % 2 === 1 && "bg-(--theme-panel-bg)/50"),
340
+ children: [/* @__PURE__ */ jsx("td", {
341
+ className: "px-3.5 py-1.5 text-right theme-muted-text",
342
+ children: r + 1
343
+ }), positionKeys(columnCount, "cell").map((cellKey, c) => /* @__PURE__ */ jsx("td", {
344
+ className: "px-3.5 py-1.5",
345
+ children: row[c] ?? ""
346
+ }, cellKey))]
347
+ }, key)) })]
348
+ })
349
+ }), /* @__PURE__ */ jsx("div", {
350
+ className: "shrink-0 border-t theme-border px-3.5 py-1.5 font-mono text-[11px] theme-muted-text",
351
+ children: truncated ? t.preview.csvFirstRows(shown.length, columnCount) : t.preview.csvRows(body.length, columnCount)
352
+ })]
353
+ });
354
+ }
355
+ function NotebookView({ node, url, onDownload, storage, onCorsRetry }) {
356
+ const { text, loading, error, tooLarge, corsError } = useObjectText(url, {
357
+ enabled: true,
358
+ maxBytes: TABULAR_PREVIEW_MAX_BYTES,
359
+ knownSize: node.size,
360
+ cacheKey: node.path
361
+ });
362
+ return /* @__PURE__ */ jsx(PreviewFetchState, {
363
+ loading,
364
+ tooLarge,
365
+ error,
366
+ corsError,
367
+ storage,
368
+ onCorsRetry,
369
+ onDownload,
370
+ children: /* @__PURE__ */ jsx(NotebookBody, {
371
+ text: text ?? "",
372
+ onDownload
373
+ })
374
+ });
375
+ }
376
+ function NotebookBody({ text, onDownload }) {
377
+ const t = useStrings().fileExplorer;
378
+ const notebook = parseNotebook(text);
379
+ if (!notebook) return /* @__PURE__ */ jsx(InlineError, {
380
+ message: t.preview.notebookParseError,
381
+ onDownload
382
+ });
383
+ return /* @__PURE__ */ jsx("div", {
384
+ className: "h-full w-full overflow-auto bg-(--theme-app-bg) p-4",
385
+ children: /* @__PURE__ */ jsx("div", {
386
+ className: "mx-auto flex max-w-4xl flex-col gap-3",
387
+ children: withPositionKeys(notebook.cells, "cell").map(({ key, item: cell }) => {
388
+ const source = joinSource(cell.source);
389
+ if (cell.cell_type === "markdown") return /* @__PURE__ */ jsx("div", {
390
+ className: "rounded-lg border theme-border px-4 py-3",
391
+ children: /* @__PURE__ */ jsx(Markdown, {
392
+ controls: PREVIEW_MARKDOWN_CONTROLS,
393
+ children: source
394
+ })
395
+ }, key);
396
+ if (cell.cell_type === "code") return /* @__PURE__ */ jsxs("div", {
397
+ className: "flex gap-2",
398
+ children: [/* @__PURE__ */ jsx("span", {
399
+ className: "w-14 shrink-0 pt-3 font-mono text-[11px] theme-muted-text",
400
+ children: typeof cell.execution_count === "number" ? `In [${cell.execution_count}]:` : "In [ ]:"
401
+ }), /* @__PURE__ */ jsxs("div", {
402
+ className: "min-w-0 flex-1",
403
+ children: [/* @__PURE__ */ jsx("div", {
404
+ className: "rounded-lg border theme-border px-1 py-1 text-xs",
405
+ children: /* @__PURE__ */ jsx(Markdown, { children: toFencedCode(source, "python") })
406
+ }), withPositionKeys(cell.outputs ?? [], "output").map(({ key: outputKey, item: output }) => /* @__PURE__ */ jsx(NotebookOutputView, { output }, outputKey))]
407
+ })]
408
+ }, key);
409
+ return null;
410
+ })
411
+ })
412
+ });
413
+ }
414
+ function NotebookOutputView({ output }) {
415
+ const t = useStrings().fileExplorer;
416
+ const [imgError, setImgError] = useState(false);
417
+ const png = output.data?.["image/png"];
418
+ if ((typeof png === "string" || Array.isArray(png)) && !imgError) return /* @__PURE__ */ jsx("div", {
419
+ className: "mt-2 rounded-lg bg-white p-3",
420
+ children: /* @__PURE__ */ jsx("img", {
421
+ src: `data:image/png;base64,${joinSource(png)}`,
422
+ alt: t.preview.notebookOutput,
423
+ className: "max-w-full",
424
+ onError: () => setImgError(true)
425
+ })
426
+ });
427
+ if (output.output_type === "stream") return /* @__PURE__ */ jsx("pre", {
428
+ className: "mt-2 overflow-auto rounded-lg bg-(--theme-panel-bg) px-3 py-2 font-mono text-[11px] theme-muted-text",
429
+ children: joinSource(output.text)
430
+ });
431
+ if (output.output_type === "error") return /* @__PURE__ */ jsx("pre", {
432
+ className: "mt-2 overflow-auto rounded-lg bg-red-500/15 px-3 py-2 font-mono text-[11px] text-red-500",
433
+ children: stripAnsi((output.traceback ?? []).join("\n"))
434
+ });
435
+ const plain = output.data?.["text/plain"];
436
+ if (plain !== void 0) return /* @__PURE__ */ jsx("pre", {
437
+ className: "mt-2 overflow-auto rounded-lg bg-(--theme-panel-bg) px-3 py-2 font-mono text-[11px]",
438
+ children: joinSource(plain)
439
+ });
440
+ return null;
441
+ }
442
+ function PreviewLoading() {
443
+ return /* @__PURE__ */ jsx("div", {
444
+ className: "flex h-full items-center justify-center",
445
+ children: /* @__PURE__ */ jsx(Loader, { size: 36 })
446
+ });
447
+ }
448
+ function PreviewFetchState({ loading, tooLarge, error, corsError, storage, onCorsRetry, onDownload, children }) {
449
+ if (loading) return /* @__PURE__ */ jsx(PreviewLoading, {});
450
+ if (corsError) return /* @__PURE__ */ jsx("div", {
451
+ className: "flex h-full w-full items-center justify-center p-6",
452
+ children: /* @__PURE__ */ jsx(CorsIssuePreview, {
453
+ selectedStorage: storage,
454
+ onRefresh: onCorsRetry
455
+ })
456
+ });
457
+ if (tooLarge) return /* @__PURE__ */ jsx(TooLargeInline, { onDownload });
458
+ if (error) return /* @__PURE__ */ jsx(PreviewError, { onDownload });
459
+ return /* @__PURE__ */ jsx(Fragment$1, { children });
460
+ }
461
+ function NotPreviewable({ icon, title, message, onDownload }) {
462
+ const t = useStrings().fileExplorer;
463
+ return /* @__PURE__ */ jsx("div", {
464
+ className: "flex h-full w-full items-center justify-center p-6",
465
+ children: /* @__PURE__ */ jsxs("div", {
466
+ className: "flex max-w-md flex-col items-center gap-4 text-center",
467
+ children: [
468
+ /* @__PURE__ */ jsx("div", {
469
+ className: "flex h-18 w-18 items-center justify-center rounded-2xl theme-muted-panel",
470
+ children: icon
471
+ }),
472
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
473
+ className: "font-semibold",
474
+ children: title
475
+ }), /* @__PURE__ */ jsx("div", {
476
+ className: "mt-1 text-sm theme-muted-text",
477
+ children: message
478
+ })] }),
479
+ onDownload && /* @__PURE__ */ jsxs("button", {
480
+ type: "button",
481
+ className: "btn btn-info cursor-pointer",
482
+ onClick: onDownload,
483
+ children: [/* @__PURE__ */ jsx(DownloadFileIcon, { className: "mr-2 h-4 w-4" }), t.preview.downloadInstead]
484
+ })
485
+ ]
486
+ })
487
+ });
488
+ }
489
+ function TooLargeInline({ onDownload }) {
490
+ const t = useStrings().fileExplorer;
491
+ return /* @__PURE__ */ jsx("div", {
492
+ className: "flex h-full items-center justify-center p-6",
493
+ children: /* @__PURE__ */ jsxs("div", {
494
+ className: "flex max-w-md flex-col items-center gap-3 text-center",
495
+ children: [/* @__PURE__ */ jsx("div", {
496
+ className: "text-sm theme-muted-text",
497
+ children: t.preview.tooLarge
498
+ }), onDownload && /* @__PURE__ */ jsxs("button", {
499
+ type: "button",
500
+ className: "btn btn-info cursor-pointer",
501
+ onClick: onDownload,
502
+ children: [/* @__PURE__ */ jsx(DownloadFileIcon, { className: "mr-2 h-4 w-4" }), t.preview.downloadInstead]
503
+ })]
504
+ })
505
+ });
506
+ }
507
+ function InlineError({ message, onDownload }) {
508
+ const t = useStrings().fileExplorer;
509
+ return /* @__PURE__ */ jsx("div", {
510
+ className: "flex h-full items-center justify-center p-6",
511
+ children: /* @__PURE__ */ jsxs("div", {
512
+ className: "flex max-w-md flex-col items-center gap-3 text-center",
513
+ children: [/* @__PURE__ */ jsx("div", {
514
+ className: "text-sm theme-muted-text",
515
+ children: message
516
+ }), onDownload && /* @__PURE__ */ jsxs("button", {
517
+ type: "button",
518
+ className: "btn btn-neutral cursor-pointer",
519
+ onClick: onDownload,
520
+ children: [/* @__PURE__ */ jsx(DownloadFileIcon, { className: "mr-2 h-4 w-4" }), t.preview.downloadInstead]
521
+ })]
522
+ })
523
+ });
524
+ }
525
+ //#endregion
526
+ export { FilePreviewViewer };