@openviking/react 0.1.1 → 0.1.3

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 (229) hide show
  1. package/README.md +18 -15
  2. package/dist/1~0.js +506 -0
  3. package/dist/2~0.js +122 -0
  4. package/dist/30~0.js +1332 -0
  5. package/dist/3~0.js +2113 -4
  6. package/dist/ark-message-list-view~0.js +310 -0
  7. package/dist/c7~0.js +24 -0
  8. package/dist/client/index.d.ts +2 -1
  9. package/dist/client/paths.d.ts +64 -0
  10. package/dist/client/response.d.ts +31 -0
  11. package/dist/client/sse.d.ts +39 -0
  12. package/dist/client/stream.d.ts +26 -0
  13. package/dist/client/types.d.ts +104 -0
  14. package/dist/client.js +1 -239
  15. package/dist/components/agent-connect/agent-connect-copy.d.ts +34 -0
  16. package/dist/components/agent-connect/agent-connect-design.d.ts +1781 -0
  17. package/dist/components/agent-connect/agent-connect-detail.d.ts +13 -0
  18. package/dist/components/agent-connect/agent-connect-installer.d.ts +3 -0
  19. package/dist/components/agent-connect/agent-connect-instructions-view.d.ts +14 -0
  20. package/dist/components/agent-connect/agent-connect-instructions.d.ts +145 -0
  21. package/dist/components/agent-connect/agent-connect-markdown.d.ts +3 -0
  22. package/dist/components/agent-connect/agent-connect.d.ts +3 -3
  23. package/dist/components/agent-connect/content-en.d.ts +137 -0
  24. package/dist/components/agent-connect/content-zh.d.ts +137 -0
  25. package/dist/components/agent-connect/style.css +495 -6
  26. package/dist/components/agent-connect/types.d.ts +20 -166
  27. package/dist/components/file-browser-entries/file-browser-entries-icons.d.ts +18 -0
  28. package/dist/components/file-browser-entries/file-browser-entries.d.ts +14 -0
  29. package/dist/components/file-browser-entries/index.d.ts +1 -0
  30. package/dist/components/file-browser-entries/style.css +155 -0
  31. package/dist/components/file-browser-entries/types.d.ts +45 -0
  32. package/dist/components/file-browser-entries.js +1 -0
  33. package/dist/components/file-preview/file-preview-adapters.d.ts +33 -0
  34. package/dist/components/file-preview/file-preview-body.d.ts +24 -12
  35. package/dist/components/file-preview/file-preview-breadcrumb-menu.d.ts +16 -0
  36. package/dist/components/file-preview/file-preview-breadcrumb.d.ts +21 -0
  37. package/dist/components/file-preview/file-preview-copy-path.d.ts +12 -0
  38. package/dist/components/file-preview/file-preview-directory.d.ts +32 -0
  39. package/dist/components/file-preview/file-preview-editor.d.ts +22 -0
  40. package/dist/components/file-preview/file-preview-handle-adapters.d.ts +26 -0
  41. package/dist/components/file-preview/file-preview-header.d.ts +41 -14
  42. package/dist/components/file-preview/file-preview-labels.d.ts +15 -4
  43. package/dist/components/file-preview/file-preview-lazy-viewer.d.ts +3 -0
  44. package/dist/components/file-preview/file-preview-panels.d.ts +41 -0
  45. package/dist/components/file-preview/file-preview-path.d.ts +30 -0
  46. package/dist/components/file-preview/file-preview-source.d.ts +24 -0
  47. package/dist/components/file-preview/file-preview-state.d.ts +35 -0
  48. package/dist/components/file-preview/file-preview-tab-row.d.ts +16 -0
  49. package/dist/components/file-preview/file-preview-viewer.d.ts +31 -0
  50. package/dist/components/file-preview/file-preview.d.ts +9 -11
  51. package/dist/components/file-preview/level-selection.d.ts +25 -0
  52. package/dist/components/file-preview/style.css +4055 -126
  53. package/dist/components/file-preview/types.d.ts +350 -170
  54. package/dist/components/file-preview/use-directory-level.d.ts +30 -0
  55. package/dist/components/file-preview/use-file-preview-actions-context.d.ts +27 -0
  56. package/dist/components/file-preview/use-file-preview-actions.d.ts +19 -0
  57. package/dist/components/file-preview/use-file-preview-editing.d.ts +21 -2
  58. package/dist/components/file-preview/use-file-preview-ids.d.ts +24 -0
  59. package/dist/components/file-preview.js +1 -442
  60. package/dist/components/file-tree/file-tree-body.d.ts +8 -4
  61. package/dist/components/file-tree/file-tree-entry-row.d.ts +9 -3
  62. package/dist/components/file-tree/file-tree-icons.d.ts +12 -5
  63. package/dist/components/file-tree/file-tree-info-labels.d.ts +21 -0
  64. package/dist/components/file-tree/file-tree-info-tooltip.d.ts +43 -0
  65. package/dist/components/file-tree/file-tree-info.d.ts +29 -0
  66. package/dist/components/file-tree/file-tree-keyboard.d.ts +8 -4
  67. package/dist/components/file-tree/file-tree-row-context.d.ts +29 -12
  68. package/dist/components/file-tree/file-tree-row-shared.d.ts +18 -0
  69. package/dist/components/file-tree/file-tree-spinner.d.ts +10 -0
  70. package/dist/components/file-tree/file-tree-state-row.d.ts +7 -0
  71. package/dist/components/file-tree/file-tree-tooltip-surface.d.ts +22 -0
  72. package/dist/components/file-tree/file-tree.d.ts +12 -1
  73. package/dist/components/file-tree/style.css +280 -75
  74. package/dist/components/file-tree/types.d.ts +203 -0
  75. package/dist/components/file-tree/use-file-tree-actions.d.ts +7 -0
  76. package/dist/components/file-tree.js +1 -1
  77. package/dist/components/scope-switcher/scope-panel.d.ts +9 -3
  78. package/dist/components/scope-switcher/scope-selector.d.ts +1 -1
  79. package/dist/components/scope-switcher/scope-switcher.d.ts +1 -1
  80. package/dist/components/scope-switcher/style.css +282 -76
  81. package/dist/components/scope-switcher/types.d.ts +230 -108
  82. package/dist/components/style.css +14128 -390
  83. package/dist/components/tui/command-catalog.d.ts +58 -0
  84. package/dist/components/tui/command-completion.d.ts +19 -0
  85. package/dist/components/tui/command-definitions.d.ts +10 -0
  86. package/dist/components/tui/command-input.d.ts +16 -0
  87. package/dist/components/tui/style.css +1543 -5
  88. package/dist/components/tui/tui-assist.d.ts +15 -0
  89. package/dist/components/tui/tui-code-block.d.ts +8 -0
  90. package/dist/components/tui/tui-command-help.d.ts +9 -0
  91. package/dist/components/tui/tui-command-text.d.ts +6 -0
  92. package/dist/components/tui/tui-composer.d.ts +24 -0
  93. package/dist/components/tui/tui-copy-button.d.ts +9 -0
  94. package/dist/components/tui/tui-input-mirror.d.ts +14 -0
  95. package/dist/components/tui/tui-labels-zh.d.ts +2 -0
  96. package/dist/components/tui/tui-labels.d.ts +5 -0
  97. package/dist/components/tui/tui-markdown-renderers.d.ts +10 -0
  98. package/dist/components/tui/tui-markdown.d.ts +6 -0
  99. package/dist/components/tui/tui-param-hint.d.ts +7 -0
  100. package/dist/components/tui/tui-record-time.d.ts +11 -0
  101. package/dist/components/tui/tui-record.d.ts +13 -0
  102. package/dist/components/tui/tui-resource-preview.d.ts +10 -0
  103. package/dist/components/tui/tui-resource-tree.d.ts +10 -0
  104. package/dist/components/tui/tui-result-header.d.ts +7 -0
  105. package/dist/components/tui/tui-result-text.d.ts +5 -0
  106. package/dist/components/tui/tui-search-list.d.ts +8 -0
  107. package/dist/components/tui/tui-skeleton.d.ts +6 -0
  108. package/dist/components/tui/tui-status-card.d.ts +7 -0
  109. package/dist/components/tui/tui-text.d.ts +10 -0
  110. package/dist/components/tui/tui-uri-text.d.ts +19 -0
  111. package/dist/components/tui/tui-write-result.d.ts +7 -0
  112. package/dist/components/tui/tui.d.ts +10 -2
  113. package/dist/components/tui/types.d.ts +57 -15
  114. package/dist/components/tui/use-tui-assist-position.d.ts +3 -0
  115. package/dist/components/tui/use-tui-completion.d.ts +14 -0
  116. package/dist/components/tui/use-tui-composer-keyboard.d.ts +25 -0
  117. package/dist/components/viking-bot/ark-adapter.d.ts +45 -0
  118. package/dist/components/viking-bot/ark-message-body.d.ts +16 -0
  119. package/dist/components/viking-bot/ark-message-list-view.d.ts +7 -0
  120. package/dist/components/viking-bot/ark-message-row.d.ts +19 -0
  121. package/dist/components/viking-bot/index.d.ts +10 -0
  122. package/dist/components/viking-bot/interaction/ask-human-fields.d.ts +10 -0
  123. package/dist/components/viking-bot/interaction/index.d.ts +4 -0
  124. package/dist/components/viking-bot/interaction/labels.d.ts +7 -0
  125. package/dist/components/viking-bot/interaction/lazy-interaction.d.ts +3 -0
  126. package/dist/components/viking-bot/interaction/schedule-input.d.ts +13 -0
  127. package/dist/components/viking-bot/interaction/style.css +189 -0
  128. package/dist/components/viking-bot/interaction/style.js +0 -0
  129. package/dist/components/viking-bot/interaction/types.d.ts +188 -0
  130. package/dist/components/viking-bot/interaction/viking-bot-interaction.d.ts +9 -0
  131. package/dist/components/viking-bot/interaction.js +2 -0
  132. package/dist/components/viking-bot/labels.d.ts +2 -0
  133. package/dist/components/viking-bot/lazy-composer.d.ts +3 -0
  134. package/dist/components/viking-bot/message-groups.d.ts +12 -0
  135. package/dist/components/viking-bot/model.d.ts +252 -0
  136. package/dist/components/viking-bot/render-part.d.ts +12 -0
  137. package/dist/components/viking-bot/style.css +7135 -0
  138. package/dist/components/viking-bot/style.js +0 -0
  139. package/dist/components/viking-bot/types.d.ts +140 -0
  140. package/dist/components/viking-bot/viking-bot-composer.d.ts +6 -0
  141. package/dist/components/viking-bot/viking-bot-message-list.d.ts +3 -0
  142. package/dist/components/viking-bot/viking-bot.d.ts +16 -0
  143. package/dist/components/viking-bot.js +4 -0
  144. package/dist/c~0.js +201 -0
  145. package/dist/file-preview-viewer~0.js +191 -0
  146. package/dist/f~0.js +149 -77
  147. package/dist/h~0.js +58 -0
  148. package/dist/icons/file-type-icon.d.ts +31 -0
  149. package/dist/icons/index.d.ts +33 -23
  150. package/dist/icons/nextjs-icon.d.ts +19 -0
  151. package/dist/icons.js +1 -25
  152. package/dist/index.d.ts +4 -2
  153. package/dist/index.js +2 -1
  154. package/dist/k~0.js +1440 -0
  155. package/dist/lk~0.js +25 -12
  156. package/dist/l~0.js +1464 -25
  157. package/dist/modules/console/style.css +83 -1
  158. package/dist/modules/file-browser/file-browser-detail-icons.d.ts +10 -0
  159. package/dist/modules/file-browser/file-browser-detail.d.ts +33 -0
  160. package/dist/modules/file-browser/file-browser-empty.d.ts +3 -0
  161. package/dist/modules/file-browser/file-browser-failure.d.ts +22 -0
  162. package/dist/modules/file-browser/file-browser-icons.d.ts +18 -0
  163. package/dist/modules/file-browser/file-browser-labels.d.ts +28 -0
  164. package/dist/modules/file-browser/file-browser-layout.d.ts +27 -0
  165. package/dist/modules/file-browser/file-browser-toolbar.d.ts +18 -0
  166. package/dist/modules/file-browser/file-browser-tree-pane.d.ts +30 -0
  167. package/dist/modules/file-browser/file-browser.d.ts +14 -5
  168. package/dist/modules/file-browser/find-result.d.ts +24 -0
  169. package/dist/modules/file-browser/fs-directories.d.ts +33 -0
  170. package/dist/modules/file-browser/fs-file-kind.d.ts +19 -0
  171. package/dist/modules/file-browser/fs-icon.d.ts +17 -0
  172. package/dist/modules/file-browser/fs-model.d.ts +106 -0
  173. package/dist/modules/file-browser/fs-page.d.ts +16 -0
  174. package/dist/modules/file-browser/fs-path.d.ts +16 -0
  175. package/dist/modules/file-browser/fs-read-directory.d.ts +20 -0
  176. package/dist/modules/file-browser/fs-scope.d.ts +22 -0
  177. package/dist/modules/file-browser/fs-stat.d.ts +25 -0
  178. package/dist/modules/file-browser/index.d.ts +3 -1
  179. package/dist/modules/file-browser/style.css +5009 -34
  180. package/dist/modules/file-browser/tree-info-copy.d.ts +15 -0
  181. package/dist/modules/file-browser/tree-info-copy.zh-CN.d.ts +15 -0
  182. package/dist/modules/file-browser/types.d.ts +189 -44
  183. package/dist/modules/file-browser/use-container-width.d.ts +17 -0
  184. package/dist/modules/file-browser/use-file-browser.d.ts +49 -0
  185. package/dist/modules/file-browser/use-fs-preview.d.ts +51 -0
  186. package/dist/modules/file-browser/use-fs-search.d.ts +35 -0
  187. package/dist/modules/file-browser/use-fs-tree.d.ts +43 -0
  188. package/dist/modules/file-browser/use-request-scope.d.ts +39 -0
  189. package/dist/modules/file-browser.js +1 -1
  190. package/dist/modules/scope-cascade/style.css +282 -76
  191. package/dist/modules/style.css +5445 -130
  192. package/dist/n~0.js +568 -236
  193. package/dist/o~0.js +103 -0
  194. package/dist/shared/components/divider/divider.d.ts +18 -0
  195. package/dist/shared/components/divider/index.d.ts +1 -0
  196. package/dist/shared/components/divider/types.d.ts +35 -0
  197. package/dist/shared/components/overlay/types.d.ts +7 -0
  198. package/dist/shared/components/overlay/use-overlay-position.d.ts +38 -0
  199. package/dist/shared/components/popover/index.d.ts +1 -0
  200. package/dist/shared/components/popover/popover.d.ts +23 -0
  201. package/dist/shared/components/popover/types.d.ts +50 -0
  202. package/dist/shared/components/resizable/clamp.d.ts +13 -0
  203. package/dist/shared/components/resizable/index.d.ts +2 -0
  204. package/dist/shared/components/resizable/resizable-handle.d.ts +25 -0
  205. package/dist/shared/components/resizable/types.d.ts +48 -0
  206. package/dist/shared/components/tooltip/index.d.ts +1 -0
  207. package/dist/shared/components/tooltip/tooltip.d.ts +25 -0
  208. package/dist/shared/components/tooltip/types.d.ts +42 -0
  209. package/dist/style.css +19664 -530
  210. package/dist/u~0.js +1597 -4
  211. package/dist/viking-bot-composer~0.js +164 -0
  212. package/dist/viking-bot-interaction~0.js +284 -0
  213. package/dist/w~0.js +19 -0
  214. package/package.json +23 -10
  215. package/dist/components/file-preview/file-preview-icons.d.ts +0 -2
  216. package/dist/components/file-preview/file-preview-operations.d.ts +0 -1
  217. package/dist/components/file-tree/file-tree-dom.d.ts +0 -4
  218. package/dist/components/file-tree/file-tree-labels.d.ts +0 -5
  219. package/dist/components/file-tree/file-tree-rows.d.ts +0 -12
  220. package/dist/components/file-tree/file-tree-tooltip.d.ts +0 -11
  221. package/dist/i~0.js +0 -21
  222. package/dist/modules/file-browser/file-browser-toolbar-button.d.ts +0 -10
  223. package/dist/modules/task-center/columns.d.ts +0 -129
  224. package/dist/modules/task-center/index.d.ts +0 -1
  225. package/dist/modules/task-center/style.css +0 -29
  226. package/dist/modules/task-center/task-center.d.ts +0 -4
  227. package/dist/modules/task-center/types.d.ts +0 -168
  228. package/dist/modules/task-center.js +0 -1
  229. /package/dist/{modules/task-center → components/file-browser-entries}/style.js +0 -0
@@ -0,0 +1,30 @@
1
+ import type { FilePreviewDirectoryTab, FilePreviewSource } from './types.js';
2
+ /**
3
+ * 目录页签当前看的是哪一级摘要。
4
+ *
5
+ * 它必须由预览外壳持有,而不是留在正文组件内部:复制正文取的是「用户正在看的
6
+ * 那一份」,标题行的路径也来自同一级,两处都在外壳这一层取值;留在正文里,复制
7
+ * 到的永远是第一级。
8
+ *
9
+ * 宿主给了 `activeLevelKey` 时以宿主的为准,这里只记非受控页签自己的选择。
10
+ *
11
+ * Which summary level of a directory tab is on screen.
12
+ *
13
+ * It belongs to the preview shell rather than inside the body component: copy-content
14
+ * takes "what the user is looking at" and the header path comes from the same level,
15
+ * both read at this layer — kept in the body, a copy would always take the first
16
+ * level.
17
+ *
18
+ * A host-supplied `activeLevelKey` wins; this only records the choice of an
19
+ * uncontrolled tab.
20
+ */
21
+ export interface DirectoryLevelState {
22
+ /** 实际渲染的那一级。The level actually rendered. */
23
+ activeLevel?: FilePreviewDirectoryTab['levels'][number];
24
+ /** 把当前层级固定下来的目录页签,交给正文组件。 */
25
+ /** The directory tab with the level pinned, handed to the body. */
26
+ directoryTab?: FilePreviewDirectoryTab;
27
+ /** 复制路径与复制正文共用的来源。The source shared by copy-path and copy-content. */
28
+ source?: FilePreviewSource;
29
+ }
30
+ export declare function useDirectoryLevel(tab: FilePreviewDirectoryTab | undefined): DirectoryLevelState;
@@ -0,0 +1,27 @@
1
+ import type { useFilePreviewActions } from './use-file-preview-actions.js';
2
+ import type { useFilePreviewEditing } from './use-file-preview-editing.js';
3
+ import type { FilePreviewActions, FilePreviewFileTab, FilePreviewSource, FilePreviewTab, FilePreviewViewMode } from './types.js';
4
+ type Operations = ReturnType<typeof useFilePreviewActions>;
5
+ type Editing = ReturnType<typeof useFilePreviewEditing>;
6
+ /**
7
+ * 组装交给宿主的动作上下文:把组件内部的视图、编辑与操作状态,连同改变它们
8
+ * 的方法收成一个对象,供 `slots.actions` 渲染按钮时使用。
9
+ *
10
+ * Assembles the action context handed to the host: the component's view, editing
11
+ * and operation state together with the methods that change them, so a
12
+ * `slots.actions` renderer can build its own buttons.
13
+ */
14
+ export declare function useFilePreviewActionsContext({ activeTab, fileTab, currentPath, currentSource, viewMode, canSwitchView, setViewMode, editing, operations, }: {
15
+ activeTab: FilePreviewTab;
16
+ fileTab?: FilePreviewFileTab;
17
+ /** 当前页签的路径;目录页签也有。The current tab's path; a directory has one too. */
18
+ currentPath?: string;
19
+ /** 当前页签的正文来源;目录页签取当前那一级。The body source; a directory uses its active level. */
20
+ currentSource?: FilePreviewSource;
21
+ viewMode: FilePreviewViewMode;
22
+ canSwitchView: boolean;
23
+ setViewMode: (mode: FilePreviewViewMode) => void;
24
+ editing: Editing;
25
+ operations: Operations;
26
+ }): FilePreviewActions;
27
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { FilePreviewFileTab, FilePreviewTab } from './types.js';
2
+ /**
3
+ * 文件页签的操作执行与成功通知。
4
+ *
5
+ * 沿用文件树的约定:`operations` 里的异步方法成功后才触发对应的 `on…`
6
+ * 回调,失败静默;同一操作在飞时忽略重复调用。
7
+ *
8
+ * Executes file-tab operations and reports success. Follows the file-tree
9
+ * convention: the matching `on…` callback fires only after the async operation
10
+ * resolves, failures stay silent, and repeated calls are ignored while one is
11
+ * still in flight.
12
+ */
13
+ export declare function useFilePreviewActions(): {
14
+ openParent: (tab: FilePreviewTab, uri: string) => Promise<void>;
15
+ download: (tab: FilePreviewFileTab) => Promise<void>;
16
+ openUri: (tab: FilePreviewFileTab, uri: string) => Promise<void>;
17
+ copyPath: (tab: FilePreviewTab, path: string) => Promise<boolean>;
18
+ copyContent: (tab: FilePreviewTab, text: string) => Promise<boolean>;
19
+ };
@@ -1,5 +1,24 @@
1
1
  import type { FilePreviewFileTab, FilePreviewTab } from './types.js';
2
- export declare function useFilePreviewEditing(): {
2
+ /**
3
+ * 文件页签的编辑态:进入编辑时向宿主取完整文本,保存成功才退出编辑。
4
+ *
5
+ * 进入编辑前用请求号作废旧请求,避免快速切换页签时迟到的结果写进新草稿;
6
+ * 保存期间拦住重复提交与页签切换,失败时保留草稿。
7
+ *
8
+ * 受控模式下宿主可以直接改 `activeKey`,不经过 `switchTab`;因此这里比对页签
9
+ * key,变化时在渲染期间就把草稿丢掉,否则会拿上一个页签的草稿去保存新页签。
10
+ *
11
+ * Editing state of a file tab. The full text is requested when editing starts,
12
+ * and the draft only leaves editing after a successful save. A request id
13
+ * invalidates stale loads when the tab changes quickly; duplicate saves and tab
14
+ * switches are blocked while saving, and a failed save keeps the draft.
15
+ *
16
+ * Under a controlled `activeKey` the host can switch tabs without going through
17
+ * `switchTab`, so the hook compares the active key and drops the draft during
18
+ * render when it changes — otherwise the previous tab's draft would be saved to
19
+ * the new one.
20
+ */
21
+ export declare function useFilePreviewEditing(activeTabKey: string): {
3
22
  editing: boolean;
4
23
  loadingEdit: boolean;
5
24
  editFailed: boolean;
@@ -8,6 +27,6 @@ export declare function useFilePreviewEditing(): {
8
27
  draft: string;
9
28
  discard: (tab: FilePreviewTab) => void;
10
29
  start: (tab: FilePreviewFileTab) => Promise<void>;
11
- save: (tab: FilePreviewFileTab) => Promise<void>;
30
+ save: (tab: FilePreviewFileTab) => Promise<boolean>;
12
31
  updateDraft: (value: string) => void;
13
32
  };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 页签与面板的 DOM id 生成器,带实例前缀。
3
+ *
4
+ * 只用宿主给的 `tab.key` 拼 id,两个预览同时挂载时会产生重复 id,`aria-controls`
5
+ * 与 `aria-labelledby` 因此可能指向另一个实例的元素。`useId` 给出每个实例唯一
6
+ * 的前缀,页签行与面板两侧共用同一份。
7
+ *
8
+ * DOM id generators for tabs and panels, prefixed per instance.
9
+ *
10
+ * Building ids from the host's `tab.key` alone collides when two previews are
11
+ * mounted at once, so `aria-controls` and `aria-labelledby` could point at the
12
+ * other instance's elements. `useId` supplies a unique prefix per instance, shared
13
+ * by the tab row and the panels.
14
+ */
15
+ export declare function useFilePreviewIds(activeKey: string): {
16
+ tabId: (key: string) => string;
17
+ panelId: (key: string) => string;
18
+ /** 面板的公共属性:id、role 与 aria 关联,随当前页签变化。 */
19
+ panelProps: {
20
+ id: string;
21
+ role: 'tabpanel';
22
+ 'aria-labelledby': string;
23
+ };
24
+ };
@@ -1,442 +1 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useId, useImperativeHandle, useRef, useState } from "react";
3
- function FilePreviewBody({ fileTab, contentTab, text, editing, loadingEdit, editFailed, saving, saveFailed, draft, onDraftChange }) {
4
- const errorId = useId();
5
- if (contentTab) return contentTab.content;
6
- if (!fileTab) return null;
7
- const { source } = fileTab;
8
- if (loadingEdit) return /*#__PURE__*/ jsx("div", {
9
- className: "ov-file-preview__state",
10
- children: /*#__PURE__*/ jsx("span", {
11
- className: "ov-file-preview__muted",
12
- children: text.loading
13
- })
14
- });
15
- if (editFailed) return /*#__PURE__*/ jsx("div", {
16
- className: "ov-file-preview__state",
17
- "data-tone": "error",
18
- children: /*#__PURE__*/ jsx("span", {
19
- className: "ov-file-preview__muted",
20
- children: text.loadFailed
21
- })
22
- });
23
- if (editing && fileTab.editing) return /*#__PURE__*/ jsxs("div", {
24
- className: "ov-file-preview__editor",
25
- "aria-busy": saving || void 0,
26
- children: [
27
- saveFailed ? /*#__PURE__*/ jsx("div", {
28
- id: errorId,
29
- role: "alert",
30
- className: "ov-file-preview__save-error",
31
- children: text.saveFailed
32
- }) : null,
33
- /*#__PURE__*/ jsx("textarea", {
34
- className: "ov-file-preview__textarea",
35
- "aria-label": text.edit,
36
- "aria-describedby": saveFailed ? errorId : void 0,
37
- readOnly: saving,
38
- value: draft,
39
- onChange: (event)=>onDraftChange(event.target.value)
40
- })
41
- ]
42
- });
43
- if ('string' != typeof source.content) return /*#__PURE__*/ jsx("div", {
44
- className: "ov-file-preview__state",
45
- children: fileTab.slots?.unsupportedFallback ?? /*#__PURE__*/ jsx("span", {
46
- className: "ov-file-preview__muted",
47
- children: source.file || source.url ? text.binaryUnsupported : text.unsupported
48
- })
49
- });
50
- return /*#__PURE__*/ jsx("div", {
51
- className: "ov-file-preview__text-body",
52
- children: /*#__PURE__*/ jsx("pre", {
53
- className: "ov-file-preview__pre",
54
- children: source.content
55
- })
56
- });
57
- }
58
- function FileIcon() {
59
- return /*#__PURE__*/ jsxs("svg", {
60
- "aria-hidden": "true",
61
- className: "ov-file-preview__icon",
62
- viewBox: "0 0 16 16",
63
- width: "14",
64
- height: "14",
65
- children: [
66
- /*#__PURE__*/ jsx("path", {
67
- d: "M4 1.5h5L12.5 5v9.5h-8.5V1.5Z",
68
- fill: "none",
69
- stroke: "currentColor",
70
- strokeLinejoin: "round",
71
- strokeWidth: "1.2"
72
- }),
73
- /*#__PURE__*/ jsx("path", {
74
- d: "M9 1.5V5h3.5",
75
- fill: "none",
76
- stroke: "currentColor",
77
- strokeWidth: "1.2"
78
- })
79
- ]
80
- });
81
- }
82
- function CopyIcon() {
83
- return /*#__PURE__*/ jsxs("svg", {
84
- "aria-hidden": "true",
85
- className: "ov-file-preview__action-icon",
86
- viewBox: "0 0 16 16",
87
- width: "12",
88
- height: "12",
89
- children: [
90
- /*#__PURE__*/ jsx("rect", {
91
- x: "5.5",
92
- y: "5.5",
93
- width: "8",
94
- height: "9",
95
- rx: "1.2",
96
- fill: "none",
97
- stroke: "currentColor",
98
- strokeWidth: "1.2"
99
- }),
100
- /*#__PURE__*/ jsx("path", {
101
- d: "M10.5 5.5v-2a1 1 0 0 0-1-1h-7a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h2",
102
- fill: "none",
103
- stroke: "currentColor",
104
- strokeWidth: "1.2"
105
- })
106
- ]
107
- });
108
- }
109
- const DEFAULT_LABELS = {
110
- copyContent: 'Copy content',
111
- copyContentSuccess: 'Content copied',
112
- copyContentEmpty: 'Nothing to copy',
113
- copyPath: 'Copy path',
114
- copyPathSuccess: 'Path copied',
115
- openParent: 'Open parent directory',
116
- edit: 'Edit',
117
- save: 'Save',
118
- cancel: 'Cancel',
119
- preview: 'Preview',
120
- source: 'Source',
121
- retry: 'Retry',
122
- loadFailed: 'Failed to load the file',
123
- saveFailed: 'Failed to save',
124
- unsupported: 'Preview is not supported for this format',
125
- loading: 'Loading…',
126
- download: 'Download',
127
- binaryUnsupported: 'Binary preview requires FileViewer'
128
- };
129
- function readCopyableText(tab) {
130
- const { content } = tab.source;
131
- return 'string' == typeof content && content.length > 0 ? content : void 0;
132
- }
133
- async function performPreviewOperation(execute, notify) {
134
- if (!execute) return;
135
- try {
136
- await execute();
137
- } catch {
138
- return;
139
- }
140
- notify?.();
141
- }
142
- async function copyText(value, onCopied) {
143
- try {
144
- await navigator.clipboard.writeText(value);
145
- } catch {
146
- return;
147
- }
148
- onCopied?.(value);
149
- }
150
- function FilePreviewHeader({ activeTab, fileTab, text, viewMode, editing, loadingEdit, saving, onViewModeChange, onEditStart, onEditCancel, onEditSave }) {
151
- const titleExtra = activeTab.slots?.titleExtra;
152
- const headerActions = activeTab.slots?.actions;
153
- const path = fileTab?.source.path;
154
- return /*#__PURE__*/ jsxs("div", {
155
- className: "ov-file-preview__header",
156
- children: [
157
- /*#__PURE__*/ jsxs("div", {
158
- className: "ov-file-preview__path-row",
159
- children: [
160
- path ? /*#__PURE__*/ jsx("button", {
161
- type: "button",
162
- className: "ov-file-preview__breadcrumb",
163
- onClick: (event)=>{
164
- event.stopPropagation();
165
- performPreviewOperation(fileTab.operations?.openParent ? ()=>fileTab.operations.openParent(path) : void 0, ()=>fileTab.onOpenParent?.(path));
166
- },
167
- disabled: !fileTab.operations?.openParent || saving,
168
- title: path,
169
- children: path
170
- }) : /*#__PURE__*/ jsx("span", {
171
- className: "ov-file-preview__breadcrumb",
172
- children: activeTab.key
173
- }),
174
- path ? /*#__PURE__*/ jsx("button", {
175
- type: "button",
176
- className: "ov-file-preview__action",
177
- "aria-label": text.copyPath,
178
- title: text.copyPath,
179
- onClick: ()=>void copyText(path, fileTab.onCopyPath),
180
- children: /*#__PURE__*/ jsx(CopyIcon, {})
181
- }) : null,
182
- titleExtra ? /*#__PURE__*/ jsx("span", {
183
- className: "ov-file-preview__title-extra",
184
- children: titleExtra
185
- }) : null
186
- ]
187
- }),
188
- /*#__PURE__*/ jsxs("div", {
189
- className: "ov-file-preview__header-actions",
190
- children: [
191
- fileTab && false !== fileTab.showViewModeSwitch ? /*#__PURE__*/ jsxs("span", {
192
- className: "ov-file-preview__switch",
193
- children: [
194
- /*#__PURE__*/ jsx("button", {
195
- type: "button",
196
- className: "ov-file-preview__switch-item",
197
- "data-active": 'preview' === viewMode || void 0,
198
- onClick: ()=>onViewModeChange('preview'),
199
- children: text.preview
200
- }),
201
- /*#__PURE__*/ jsx("button", {
202
- type: "button",
203
- className: "ov-file-preview__switch-item",
204
- "data-active": 'source' === viewMode || void 0,
205
- onClick: ()=>onViewModeChange('source'),
206
- children: text.source
207
- })
208
- ]
209
- }) : null,
210
- fileTab ? /*#__PURE__*/ jsx("button", {
211
- type: "button",
212
- className: "ov-file-preview__action",
213
- "aria-label": text.copyContent,
214
- title: readCopyableText(fileTab) ? text.copyContent : text.copyContentEmpty,
215
- disabled: !readCopyableText(fileTab),
216
- onClick: ()=>{
217
- const value = readCopyableText(fileTab);
218
- if (value) copyText(value, fileTab.onCopyContent);
219
- },
220
- children: /*#__PURE__*/ jsx(CopyIcon, {})
221
- }) : null,
222
- fileTab?.editing && !editing ? /*#__PURE__*/ jsx("button", {
223
- type: "button",
224
- className: "ov-file-preview__button",
225
- disabled: loadingEdit || !fileTab.editing.loadContent && void 0 === fileTab.source.content && !fileTab.source.file,
226
- onClick: onEditStart,
227
- children: text.edit
228
- }) : null,
229
- fileTab?.editing && editing ? /*#__PURE__*/ jsxs(Fragment, {
230
- children: [
231
- /*#__PURE__*/ jsx("button", {
232
- type: "button",
233
- className: "ov-file-preview__button",
234
- onClick: onEditCancel,
235
- disabled: saving,
236
- children: text.cancel
237
- }),
238
- /*#__PURE__*/ jsx("button", {
239
- type: "button",
240
- className: "ov-file-preview__button--primary",
241
- onClick: onEditSave,
242
- disabled: saving,
243
- children: text.save
244
- })
245
- ]
246
- }) : null,
247
- fileTab?.operations?.download ? /*#__PURE__*/ jsx("button", {
248
- type: "button",
249
- className: "ov-file-preview__button",
250
- onClick: ()=>{
251
- performPreviewOperation(fileTab.operations?.download, fileTab.onDownload);
252
- },
253
- children: text.download
254
- }) : null,
255
- headerActions ? /*#__PURE__*/ jsx("span", {
256
- className: "ov-file-preview__extra-actions",
257
- children: headerActions
258
- }) : null
259
- ]
260
- })
261
- ]
262
- });
263
- }
264
- function useFilePreviewEditing() {
265
- const [editing, setEditing] = useState(false);
266
- const [loadingEdit, setLoadingEdit] = useState(false);
267
- const [editFailed, setEditFailed] = useState(false);
268
- const [saving, setSaving] = useState(false);
269
- const [saveFailed, setSaveFailed] = useState(false);
270
- const [draft, setDraft] = useState('');
271
- const requestId = useRef(0);
272
- const loading = useRef(false);
273
- const pendingSave = useRef(false);
274
- function discard(tab) {
275
- requestId.current += 1;
276
- loading.current = false;
277
- setEditing(false);
278
- setLoadingEdit(false);
279
- setEditFailed(false);
280
- setSaveFailed(false);
281
- setDraft('');
282
- if (editing && 'file' === tab.kind) tab.editing?.onCancel?.(draft);
283
- }
284
- async function start(tab) {
285
- if (loading.current || pendingSave.current) return;
286
- const id = ++requestId.current;
287
- loading.current = true;
288
- setLoadingEdit(true);
289
- setEditFailed(false);
290
- setSaveFailed(false);
291
- let content;
292
- try {
293
- content = tab.editing?.loadContent ? await tab.editing.loadContent(tab.source) : tab.source.content ?? await tab.source.file?.text();
294
- } catch {
295
- if (id === requestId.current) setEditFailed(true);
296
- }
297
- if (id !== requestId.current) return;
298
- loading.current = false;
299
- setLoadingEdit(false);
300
- if (void 0 !== content) {
301
- setDraft(content);
302
- setEditing(true);
303
- }
304
- }
305
- async function save(tab) {
306
- if (!editing || !tab.editing || pendingSave.current) return;
307
- pendingSave.current = true;
308
- setSaving(true);
309
- setSaveFailed(false);
310
- const value = draft;
311
- try {
312
- await tab.editing.save(value);
313
- } catch {
314
- setSaveFailed(true);
315
- return;
316
- } finally{
317
- pendingSave.current = false;
318
- setSaving(false);
319
- }
320
- setEditing(false);
321
- setDraft('');
322
- tab.editing.onSave?.(value);
323
- }
324
- return {
325
- editing,
326
- loadingEdit,
327
- editFailed,
328
- saving,
329
- saveFailed,
330
- draft,
331
- discard,
332
- start,
333
- save,
334
- updateDraft: (value)=>{
335
- setDraft(value);
336
- setSaveFailed(false);
337
- }
338
- };
339
- }
340
- function isFileTab(tab) {
341
- return 'file' === tab.kind;
342
- }
343
- const file_preview_FilePreview = /*#__PURE__*/ forwardRef(function({ tabs, labels, className, ...rest }, ref) {
344
- const text = {
345
- ...DEFAULT_LABELS,
346
- ...labels
347
- };
348
- const [activeKey, setActiveKey] = useState(()=>tabs[0].key);
349
- const [viewMode, setViewMode] = useState('preview');
350
- const editor = useFilePreviewEditing();
351
- const activeTab = tabs.find((tab)=>tab.key === activeKey) ?? tabs[0];
352
- const tabText = {
353
- ...text,
354
- ...activeTab.labels
355
- };
356
- const fileTab = isFileTab(activeTab) ? activeTab : void 0;
357
- const contentTab = isFileTab(activeTab) ? void 0 : activeTab;
358
- const switchTab = (key)=>{
359
- if (key === activeKey) return true;
360
- if (editor.saving) return false;
361
- setActiveKey(key);
362
- setViewMode('preview');
363
- editor.discard(activeTab);
364
- return true;
365
- };
366
- useImperativeHandle(ref, ()=>({
367
- setActiveTab: (key)=>{
368
- const target = tabs.find((tab)=>tab.key === key);
369
- if (!target || target.disabled) return false;
370
- return switchTab(key);
371
- },
372
- getActiveTab: ()=>activeKey
373
- }));
374
- const handleTabClick = (tab)=>{
375
- if (tab.disabled) return;
376
- switchTab(tab.key);
377
- };
378
- return /*#__PURE__*/ jsxs("div", {
379
- ...rest,
380
- className: [
381
- 'ov-file-preview',
382
- className
383
- ].filter(Boolean).join(' '),
384
- children: [
385
- /*#__PURE__*/ jsx("div", {
386
- role: "tablist",
387
- className: "ov-file-preview__tab-row",
388
- children: tabs.map((tab)=>/*#__PURE__*/ jsxs("button", {
389
- type: "button",
390
- role: "tab",
391
- "aria-selected": tab.key === activeTab.key,
392
- disabled: tab.disabled || editor.saving,
393
- className: "ov-file-preview__tab",
394
- onClick: ()=>handleTabClick(tab),
395
- children: [
396
- /*#__PURE__*/ jsx("span", {
397
- className: "ov-file-preview__icon-slot",
398
- children: tab.icon ?? /*#__PURE__*/ jsx(FileIcon, {})
399
- }),
400
- /*#__PURE__*/ jsx("span", {
401
- className: "ov-file-preview__tab-title",
402
- children: tab.title ?? (isFileTab(tab) ? tab.source.fileName : tab.key)
403
- })
404
- ]
405
- }, tab.key))
406
- }),
407
- /*#__PURE__*/ jsx(FilePreviewHeader, {
408
- activeTab: activeTab,
409
- fileTab: fileTab,
410
- text: tabText,
411
- viewMode: viewMode,
412
- editing: editor.editing,
413
- loadingEdit: editor.loadingEdit,
414
- saving: editor.saving,
415
- onViewModeChange: setViewMode,
416
- onEditStart: ()=>{
417
- if (fileTab) editor.start(fileTab);
418
- },
419
- onEditCancel: ()=>editor.discard(activeTab),
420
- onEditSave: ()=>{
421
- if (fileTab) editor.save(fileTab);
422
- }
423
- }),
424
- /*#__PURE__*/ jsx("div", {
425
- className: "ov-file-preview__body",
426
- children: /*#__PURE__*/ jsx(FilePreviewBody, {
427
- fileTab: fileTab,
428
- contentTab: contentTab,
429
- text: tabText,
430
- editing: editor.editing,
431
- loadingEdit: editor.loadingEdit,
432
- editFailed: editor.editFailed,
433
- saving: editor.saving,
434
- saveFailed: editor.saveFailed,
435
- draft: editor.draft,
436
- onDraftChange: editor.updateDraft
437
- })
438
- })
439
- ]
440
- });
441
- });
442
- export { file_preview_FilePreview as FilePreview };
1
+ export { FilePreview, LoadingState } from "../30~0.js";
@@ -1,14 +1,18 @@
1
1
  import type { ReactNode } from 'react';
2
- import type { FileTreeRowContext } from './file-tree-row-context.js';
3
- import type { FileTreeLabels, FileTreeRow } from './types.js';
2
+ import type { FileTreeRowContext, ResolvedLabels } from './file-tree-row-context.js';
3
+ import type { FileTreeRow } from './types.js';
4
4
  export interface FileTreeBodyProps {
5
5
  rows: readonly FileTreeRow[];
6
6
  isReady: boolean;
7
- text: Required<FileTreeLabels>;
7
+ text: ResolvedLabels;
8
8
  loadingFallback?: ReactNode;
9
9
  errorFallback?: ReactNode;
10
10
  emptyFallback?: ReactNode;
11
11
  ctx: FileTreeRowContext;
12
12
  }
13
- /** 树内容区:加载中、整树失败、空态与正常行列表。 */
13
+ /**
14
+ * 树内容区:首次加载、整树失败、空态与正常行列表。
15
+ *
16
+ * The tree body: first load, whole-tree failure, empty state, and the row list.
17
+ */
14
18
  export declare function FileTreeBody({ rows, isReady, text, loadingFallback, errorFallback, emptyFallback, ctx, }: FileTreeBodyProps): import("react").JSX.Element;
@@ -1,6 +1,12 @@
1
- import { type FileTreeRowContext } from './file-tree-row-context.js';
2
- import { type FileTreeEntryRow } from './types.js';
3
- export declare function FileTreeEntryRowView({ row, ctx, }: {
1
+ import type { FileTreeRowContext } from './file-tree-row-context.js';
2
+ import type { FileTreeEntryRow } from './types.js';
3
+ /**
4
+ * 一条条目行:展开箭头、图标、名称、行内说明、行尾指示器与悬停浮层。
5
+ *
6
+ * One entry row: chevron, icon, name, inline description, the row-end indicator
7
+ * and the hover tooltip.
8
+ */
9
+ export declare function FileTreeRowView({ row, ctx, }: {
4
10
  row: FileTreeEntryRow;
5
11
  ctx: FileTreeRowContext;
6
12
  }): import("react").JSX.Element;
@@ -1,8 +1,15 @@
1
- export declare function Chevron({ expanded }: {
2
- expanded: boolean;
1
+ /**
2
+ * 文件夹图标。展开态与收起态叠放在一起交叉淡入,和宿主一致。
3
+ *
4
+ * The folder icon. The open and collapsed states sit stacked and cross-fade,
5
+ * matching the host tree.
6
+ */
7
+ export declare function FileTreeFolderIcon({ open }: {
8
+ open: boolean;
3
9
  }): import("react").JSX.Element;
4
- export declare function FolderIcon({ open }: {
10
+ /** 宿主没有提供 `renderRowIcon` 时的文件图标。Fallback file icon. */
11
+ export declare function FileTreeFileIcon(): import("react").JSX.Element;
12
+ /** 展开箭头,展开时旋转 90°。The expand chevron, rotated when open. */
13
+ export declare function FileTreeChevron({ open }: {
5
14
  open: boolean;
6
15
  }): import("react").JSX.Element;
7
- export declare function FileIcon(): import("react").JSX.Element;
8
- export declare function Spinner(): import("react").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import type { FileTreeInfoKey, FileTreeInfoLabels } from './types.js';
2
+ /**
3
+ * 内置英文文案。`FileTreeLabels.info` 未提供的键沿用这里的值。
4
+ *
5
+ * Built-in English copy. Keys missing from `FileTreeLabels.info` fall back here.
6
+ */
7
+ export declare const DEFAULT_INFO_LABELS: FileTreeInfoLabels;
8
+ /**
9
+ * 按宿主的覆盖合并内置文案,键为单位。宿主的空字符串表示该键不显示,因此
10
+ * 合并时保留空串,由渲染方判断。
11
+ *
12
+ * Merges host overrides over the built-in copy, key by key. An empty host string
13
+ * means "hide this key", so it is kept and the renderer decides.
14
+ *
15
+ * Returns the copy of one key, or `undefined` when the key is hidden or has no
16
+ * copy.
17
+ */
18
+ export declare function resolveInfoCopy(key: FileTreeInfoKey, hostLabels: FileTreeInfoLabels | undefined): {
19
+ description?: string;
20
+ triggerBehavior?: string;
21
+ };