@openviking/react 0.1.1 → 0.1.2

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 (164) hide show
  1. package/README.md +18 -15
  2. package/dist/3~0.js +2113 -4
  3. package/dist/ark-message-list-view~0.js +310 -0
  4. package/dist/c7~0.js +24 -0
  5. package/dist/components/agent-connect/agent-connect-copy.d.ts +34 -0
  6. package/dist/components/agent-connect/agent-connect-design.d.ts +1781 -0
  7. package/dist/components/agent-connect/agent-connect-detail.d.ts +13 -0
  8. package/dist/components/agent-connect/agent-connect-installer.d.ts +3 -0
  9. package/dist/components/agent-connect/agent-connect-instructions-view.d.ts +14 -0
  10. package/dist/components/agent-connect/agent-connect-instructions.d.ts +145 -0
  11. package/dist/components/agent-connect/agent-connect-markdown.d.ts +3 -0
  12. package/dist/components/agent-connect/agent-connect.d.ts +3 -3
  13. package/dist/components/agent-connect/content-en.d.ts +137 -0
  14. package/dist/components/agent-connect/content-zh.d.ts +137 -0
  15. package/dist/components/agent-connect/style.css +495 -6
  16. package/dist/components/agent-connect/types.d.ts +20 -166
  17. package/dist/components/file-preview/file-preview-adapters.d.ts +33 -0
  18. package/dist/components/file-preview/file-preview-body.d.ts +24 -12
  19. package/dist/components/file-preview/file-preview-breadcrumb-menu.d.ts +16 -0
  20. package/dist/components/file-preview/file-preview-breadcrumb.d.ts +21 -0
  21. package/dist/components/file-preview/file-preview-copy-path.d.ts +12 -0
  22. package/dist/components/file-preview/file-preview-editor.d.ts +22 -0
  23. package/dist/components/file-preview/file-preview-handle-adapters.d.ts +26 -0
  24. package/dist/components/file-preview/file-preview-header.d.ts +23 -14
  25. package/dist/components/file-preview/file-preview-labels.d.ts +15 -4
  26. package/dist/components/file-preview/file-preview-lazy-viewer.d.ts +3 -0
  27. package/dist/components/file-preview/file-preview-path.d.ts +30 -0
  28. package/dist/components/file-preview/file-preview-source.d.ts +24 -0
  29. package/dist/components/file-preview/file-preview-state.d.ts +28 -0
  30. package/dist/components/file-preview/file-preview-tab-row.d.ts +16 -0
  31. package/dist/components/file-preview/file-preview-viewer.d.ts +31 -0
  32. package/dist/components/file-preview/file-preview.d.ts +8 -11
  33. package/dist/components/file-preview/style.css +3984 -128
  34. package/dist/components/file-preview/types.d.ts +250 -169
  35. package/dist/components/file-preview/use-file-preview-actions-context.d.ts +23 -0
  36. package/dist/components/file-preview/use-file-preview-actions.d.ts +19 -0
  37. package/dist/components/file-preview/use-file-preview-editing.d.ts +21 -2
  38. package/dist/components/file-preview/use-file-preview-ids.d.ts +24 -0
  39. package/dist/components/file-preview.js +1 -442
  40. package/dist/components/file-tree/file-tree-body.d.ts +8 -4
  41. package/dist/components/file-tree/file-tree-entry-row.d.ts +9 -3
  42. package/dist/components/file-tree/file-tree-icons.d.ts +12 -5
  43. package/dist/components/file-tree/file-tree-info-labels.d.ts +21 -0
  44. package/dist/components/file-tree/file-tree-info-tooltip.d.ts +43 -0
  45. package/dist/components/file-tree/file-tree-info.d.ts +29 -0
  46. package/dist/components/file-tree/file-tree-keyboard.d.ts +8 -4
  47. package/dist/components/file-tree/file-tree-row-context.d.ts +31 -9
  48. package/dist/components/file-tree/file-tree-row-shared.d.ts +11 -0
  49. package/dist/components/file-tree/file-tree-spinner.d.ts +10 -0
  50. package/dist/components/file-tree/file-tree-state-row.d.ts +7 -0
  51. package/dist/components/file-tree/file-tree-tooltip-surface.d.ts +22 -0
  52. package/dist/components/file-tree/file-tree-tooltip.d.ts +9 -3
  53. package/dist/components/file-tree/file-tree.d.ts +12 -1
  54. package/dist/components/file-tree/style.css +225 -57
  55. package/dist/components/file-tree/types.d.ts +183 -0
  56. package/dist/components/file-tree/use-file-tree-actions.d.ts +7 -0
  57. package/dist/components/file-tree.js +1 -1
  58. package/dist/components/scope-switcher/scope-panel.d.ts +9 -3
  59. package/dist/components/scope-switcher/scope-selector.d.ts +1 -1
  60. package/dist/components/scope-switcher/scope-switcher.d.ts +1 -1
  61. package/dist/components/scope-switcher/style.css +282 -76
  62. package/dist/components/scope-switcher/types.d.ts +230 -108
  63. package/dist/components/style.css +13845 -372
  64. package/dist/components/tui/command-catalog.d.ts +58 -0
  65. package/dist/components/tui/command-completion.d.ts +19 -0
  66. package/dist/components/tui/command-definitions.d.ts +10 -0
  67. package/dist/components/tui/command-input.d.ts +16 -0
  68. package/dist/components/tui/style.css +1543 -5
  69. package/dist/components/tui/tui-assist.d.ts +15 -0
  70. package/dist/components/tui/tui-code-block.d.ts +8 -0
  71. package/dist/components/tui/tui-command-help.d.ts +9 -0
  72. package/dist/components/tui/tui-command-text.d.ts +6 -0
  73. package/dist/components/tui/tui-composer.d.ts +24 -0
  74. package/dist/components/tui/tui-copy-button.d.ts +9 -0
  75. package/dist/components/tui/tui-input-mirror.d.ts +14 -0
  76. package/dist/components/tui/tui-labels-zh.d.ts +2 -0
  77. package/dist/components/tui/tui-labels.d.ts +5 -0
  78. package/dist/components/tui/tui-markdown-renderers.d.ts +10 -0
  79. package/dist/components/tui/tui-markdown.d.ts +6 -0
  80. package/dist/components/tui/tui-param-hint.d.ts +7 -0
  81. package/dist/components/tui/tui-record-time.d.ts +11 -0
  82. package/dist/components/tui/tui-record.d.ts +13 -0
  83. package/dist/components/tui/tui-resource-preview.d.ts +10 -0
  84. package/dist/components/tui/tui-resource-tree.d.ts +10 -0
  85. package/dist/components/tui/tui-result-header.d.ts +7 -0
  86. package/dist/components/tui/tui-result-text.d.ts +5 -0
  87. package/dist/components/tui/tui-search-list.d.ts +8 -0
  88. package/dist/components/tui/tui-skeleton.d.ts +6 -0
  89. package/dist/components/tui/tui-status-card.d.ts +7 -0
  90. package/dist/components/tui/tui-text.d.ts +10 -0
  91. package/dist/components/tui/tui-uri-text.d.ts +19 -0
  92. package/dist/components/tui/tui-write-result.d.ts +7 -0
  93. package/dist/components/tui/tui.d.ts +10 -2
  94. package/dist/components/tui/types.d.ts +57 -15
  95. package/dist/components/tui/use-tui-assist-position.d.ts +3 -0
  96. package/dist/components/tui/use-tui-completion.d.ts +14 -0
  97. package/dist/components/tui/use-tui-composer-keyboard.d.ts +25 -0
  98. package/dist/components/viking-bot/ark-adapter.d.ts +45 -0
  99. package/dist/components/viking-bot/ark-message-body.d.ts +16 -0
  100. package/dist/components/viking-bot/ark-message-list-view.d.ts +7 -0
  101. package/dist/components/viking-bot/ark-message-row.d.ts +19 -0
  102. package/dist/components/viking-bot/index.d.ts +10 -0
  103. package/dist/components/viking-bot/interaction/ask-human-fields.d.ts +10 -0
  104. package/dist/components/viking-bot/interaction/index.d.ts +4 -0
  105. package/dist/components/viking-bot/interaction/labels.d.ts +7 -0
  106. package/dist/components/viking-bot/interaction/lazy-interaction.d.ts +3 -0
  107. package/dist/components/viking-bot/interaction/schedule-input.d.ts +13 -0
  108. package/dist/components/viking-bot/interaction/style.css +189 -0
  109. package/dist/components/viking-bot/interaction/types.d.ts +188 -0
  110. package/dist/components/viking-bot/interaction/viking-bot-interaction.d.ts +9 -0
  111. package/dist/components/viking-bot/interaction.js +2 -0
  112. package/dist/components/viking-bot/labels.d.ts +2 -0
  113. package/dist/components/viking-bot/lazy-composer.d.ts +3 -0
  114. package/dist/components/viking-bot/message-groups.d.ts +12 -0
  115. package/dist/components/viking-bot/model.d.ts +252 -0
  116. package/dist/components/viking-bot/render-part.d.ts +12 -0
  117. package/dist/components/viking-bot/style.css +7135 -0
  118. package/dist/components/viking-bot/style.js +0 -0
  119. package/dist/components/viking-bot/types.d.ts +140 -0
  120. package/dist/components/viking-bot/viking-bot-composer.d.ts +6 -0
  121. package/dist/components/viking-bot/viking-bot-message-list.d.ts +3 -0
  122. package/dist/components/viking-bot/viking-bot.d.ts +16 -0
  123. package/dist/components/viking-bot.js +4 -0
  124. package/dist/c~0.js +201 -0
  125. package/dist/file-preview-viewer~0.js +191 -0
  126. package/dist/f~0.js +149 -77
  127. package/dist/g~0.js +1207 -0
  128. package/dist/h~0.js +58 -0
  129. package/dist/icons/file-type-icon.d.ts +31 -0
  130. package/dist/icons/index.d.ts +33 -23
  131. package/dist/icons/nextjs-icon.d.ts +19 -0
  132. package/dist/icons.js +1 -25
  133. package/dist/index.d.ts +2 -2
  134. package/dist/index.js +1 -1
  135. package/dist/k~0.js +1440 -0
  136. package/dist/lk~0.js +25 -12
  137. package/dist/modules/console/style.css +83 -1
  138. package/dist/modules/file-browser/style.css +89 -6
  139. package/dist/modules/scope-cascade/style.css +282 -76
  140. package/dist/modules/style.css +533 -110
  141. package/dist/n~0.js +434 -206
  142. package/dist/shared/components/tooltip/index.d.ts +1 -0
  143. package/dist/shared/components/tooltip/tooltip.d.ts +25 -0
  144. package/dist/shared/components/tooltip/types.d.ts +42 -0
  145. package/dist/shared/components/tooltip/use-tooltip-position.d.ts +38 -0
  146. package/dist/style.css +14451 -474
  147. package/dist/u~0.js +1597 -4
  148. package/dist/viking-bot-composer~0.js +164 -0
  149. package/dist/viking-bot-interaction~0.js +284 -0
  150. package/dist/w~0.js +19 -0
  151. package/package.json +18 -10
  152. package/dist/components/file-preview/file-preview-icons.d.ts +0 -2
  153. package/dist/components/file-preview/file-preview-operations.d.ts +0 -1
  154. package/dist/components/file-tree/file-tree-dom.d.ts +0 -4
  155. package/dist/components/file-tree/file-tree-labels.d.ts +0 -5
  156. package/dist/components/file-tree/file-tree-rows.d.ts +0 -12
  157. package/dist/i~0.js +0 -21
  158. package/dist/modules/task-center/columns.d.ts +0 -129
  159. package/dist/modules/task-center/index.d.ts +0 -1
  160. package/dist/modules/task-center/style.css +0 -29
  161. package/dist/modules/task-center/task-center.d.ts +0 -4
  162. package/dist/modules/task-center/types.d.ts +0 -168
  163. package/dist/modules/task-center.js +0 -1
  164. /package/dist/{modules/task-center → components/viking-bot/interaction}/style.js +0 -0
@@ -1,5 +1,5 @@
1
- import type { FileViewerResource } from '@ark-design/ui/file-viewer/core';
2
- import type { ForwardRefExoticComponent, HTMLAttributes, PropsWithoutRef, ReactNode, RefAttributes } from 'react';
1
+ import type { ConfirmSlotProps, DownloadSlotProps, FileViewerResource, ViewerHandle } from '@ark-design/ui/file-viewer/core';
2
+ import type { ComponentType, ForwardRefExoticComponent, HTMLAttributes, PropsWithoutRef, ReactNode, RefAttributes } from 'react';
3
3
  /**
4
4
  * 要预览的内容及文件信息。提供多个来源时,按 `content`、`file`、`url`
5
5
  * 的顺序使用第一个有值的来源。
@@ -9,8 +9,7 @@ import type { ForwardRefExoticComponent, HTMLAttributes, PropsWithoutRef, ReactN
9
9
  export interface FilePreviewSource {
10
10
  /**
11
11
  * 文本内容,适用于 Markdown、JSON、代码等可内联的格式。
12
- * Text content, for formats that can be inlined such as Markdown, JSON and
13
- * code.
12
+ * Text content, for formats that can be inlined such as Markdown, JSON and code.
14
13
  */
15
14
  content?: string;
16
15
  /**
@@ -32,8 +31,9 @@ export interface FilePreviewSource {
32
31
  */
33
32
  fileName: string;
34
33
  /**
35
- * 完整路径,显示在标题下方。省略时只显示文件名。
36
- * Full path shown under the title. Only the file name is shown when omitted.
34
+ * 完整路径,显示为面包屑。省略时面包屑退化为文件名,不渲染祖先按钮。
35
+ * Full path, rendered as the breadcrumb. When omitted the breadcrumb falls
36
+ * back to the file name and renders no ancestor buttons.
37
37
  */
38
38
  path?: string;
39
39
  /**
@@ -41,6 +41,14 @@ export interface FilePreviewSource {
41
41
  * Explicit format hint, taking precedence over extension and MIME.
42
42
  */
43
43
  fileType?: string;
44
+ /**
45
+ * 正文是否被截断。宿主按读取上限取回部分内容时置为 `true`,组件在正文
46
+ * 下方提示,避免把「只读了一部分」当作完整文件。
47
+ * Whether the body was truncated. A host that read only part of the content
48
+ * sets this so the component can say so instead of passing a partial file off
49
+ * as complete.
50
+ */
51
+ truncated?: boolean;
44
52
  }
45
53
  /**
46
54
  * 所有页签的公共配置,包括标识、标题、图标、文案及标题行操作。
@@ -55,14 +63,23 @@ export interface FilePreviewTabBase {
55
63
  key: string;
56
64
  /**
57
65
  * 页签行显示的内容。可以是纯文本,也可以是带样式或图标的节点。
58
- * What the tab row shows. It can be plain text or a node with styling or
59
- * icons.
66
+ * What the tab row shows. It can be plain text or a node with styling or icons.
60
67
  */
61
68
  title?: ReactNode;
62
69
  /**
63
- * 页签图标。省略时按文件格式自动选择,内容页签使用内置的看板图标。
64
- * Tab icon. Chosen from the file format when omitted; a content tab uses the
65
- * built-in dashboard icon.
70
+ * 页签图标,由宿主提供;省略时该页签只显示标题,不占图标位。
71
+ *
72
+ * 组件不按文件名推断类型:格式识别属于上层职责,内置图标集会把整包图标
73
+ * 拖进产物。需要按格式取图标的宿主可从 `@openviking/react/icons` 引入
74
+ * `getFileTypeIcon`,把结果传进来。
75
+ *
76
+ * The tab icon, supplied by the host. Omit it and the tab shows only its title,
77
+ * with no icon slot.
78
+ *
79
+ * The component does not infer a type from the file name: format detection
80
+ * belongs to the caller, and bundling the icon set would pull every icon into
81
+ * the output. A host that wants a per-format icon can import
82
+ * `getFileTypeIcon` from `@openviking/react/icons` and pass the result in.
66
83
  */
67
84
  icon?: ReactNode;
68
85
  /**
@@ -77,40 +94,19 @@ export interface FilePreviewTabBase {
77
94
  */
78
95
  disabled?: boolean;
79
96
  /**
80
- * 上级目录成功打开后触发,参数为当前文件路径;失败时不触发。
81
- * Called after the parent directory opens, with the current file path;
97
+ * 祖先导航成功打开后触发,参数为被点击那一级的完整 URI;失败时不触发。
98
+ * Called after an ancestor opens, with the full URI of the clicked level;
82
99
  * not called on failure.
83
100
  */
84
- onOpenParent?: (path: string) => void;
101
+ onOpenParent?: (uri: string) => void;
85
102
  /**
86
103
  * 路径复制成功后触发,参数为已复制的路径;复制失败时不触发。
87
104
  * 省略回调不影响复制。文件页签提供 `source.path` 时显示复制路径按钮。
88
- *
89
105
  * Called after path copying succeeds, with the copied path; not called on
90
106
  * failure. Omitting it does not affect copying. File tabs with `source.path`
91
107
  * show the copy-path button.
92
108
  */
93
109
  onCopyPath?: (path: string) => void;
94
- /**
95
- * 是否显示预览/源码切换,默认 `true`。格式本身没有源码视图时自动隐藏。
96
- *
97
- * 只在文件页签上生效。内容页签的正文由宿主渲染,组件没有可切换的两种视图,
98
- * 传了也不会渲染切换按钮;宿主需要两种视图时在 `content` 里自行实现。
99
- *
100
- * Whether to show the preview/source switch, `true` by default. Hidden
101
- * automatically when the format has no source view.
102
- *
103
- * Only meaningful on file tabs. A content tab's body is rendered by the host,
104
- * so the component has no second view to switch to and renders no control;
105
- * a host that needs two views implements the switch inside `content`.
106
- */
107
- showViewModeSwitch?: boolean;
108
- /**
109
- * 内容区标题行的插槽。页签行本身只显示标题与图标,其余元素都在这一层。
110
- * Slots of the content header row. The tab row itself shows only a title and
111
- * an icon; everything else renders in this layer.
112
- */
113
- slots?: FilePreviewHeaderSlots;
114
110
  }
115
111
  /**
116
112
  * 文件预览页签或宿主自定义内容页签。
@@ -150,14 +146,12 @@ export interface FilePreviewFileTab extends FilePreviewTabBase {
150
146
  editing?: FilePreviewEditing;
151
147
  /**
152
148
  * 文件页签的标题行插槽,在基类之上增加三类状态兜底。
153
- * Header slots of a file tab, adding the three state fallbacks on top of the
154
- * base ones.
149
+ * Header slots of a file tab, adding the three state fallbacks on top of the base ones.
155
150
  */
156
151
  slots?: FilePreviewFileTabSlots;
157
152
  /**
158
153
  * 正文复制成功后触发,参数为已复制的文本;复制失败时不触发。
159
154
  * 省略回调不影响复制。仅文件页签提供正文复制,没有可复制文本时按钮禁用。
160
- *
161
155
  * Called after content copying succeeds, with the copied text; not called on
162
156
  * failure. Omitting it does not affect copying. Only file tabs provide body
163
157
  * copying; the button is disabled when no copyable text is available.
@@ -169,17 +163,27 @@ export interface FilePreviewFileTab extends FilePreviewTabBase {
169
163
  */
170
164
  onDownload?: () => void;
171
165
  /**
172
- * 正文中的资源成功打开后触发,参数为已打开的 URI;失败时不触发。
173
- * Called after a content resource opens, with its URI; not called on failure.
166
+ * 正文中的链接成功打开后触发,参数为被点击的 URI;失败时不触发。只有
167
+ * Markdown 正文会触发。
168
+ *
169
+ * Called after a link inside the body opens, with the clicked URI; not called on
170
+ * failure. Only Markdown bodies fire this.
174
171
  */
175
172
  onOpenUri?: (uri: string) => void;
176
173
  }
177
174
  /**
178
175
  * 展示宿主自定义内容的页签,例如看板或图谱。
179
- * 标题行可通过 `slots` 补充内容与操作;正文及其加载、错误提示由 `content` 提供。
180
- * A tab with host-provided content, such as a dashboard or graph. Use `slots`
181
- * for extra header content and actions, and `content` for the body and any
182
- * loading or error messages.
176
+ *
177
+ * 这类页签只有页签行由组件负责,正文整块交给宿主——组件不渲染内容区标题行,
178
+ * 也不在中间套任何容器。宿主想加工具栏、标题或状态提示,都写在自己的
179
+ * `content` 里,按需要怎么排就怎么排。
180
+ *
181
+ * A tab with host-provided content, such as a dashboard or graph.
182
+ *
183
+ * The component only renders the tab row for these; the whole body belongs to the
184
+ * host. No content header row is rendered and no wrapper is placed in between, so
185
+ * a host that wants a toolbar, a title or a status line puts it inside `content`
186
+ * and lays it out however it needs.
183
187
  */
184
188
  export interface FilePreviewContentTab extends FilePreviewTabBase {
185
189
  /**
@@ -188,31 +192,51 @@ export interface FilePreviewContentTab extends FilePreviewTabBase {
188
192
  */
189
193
  kind: 'content';
190
194
  /**
191
- * 页签行显示的内容。内容页签没有 `source.fileName` 可以回落,因此这里是
192
- * 必填。
195
+ * 页签行显示的内容。内容页签没有 `source.fileName` 可以回落,因此这里是必填。
193
196
  * What the tab row shows. A content tab has no `source.fileName` to fall back
194
197
  * to, so it is required here.
195
198
  */
196
199
  title: ReactNode;
197
200
  /**
198
- * 页签正文,由宿主渲染。
199
- * The tab body, rendered by the host.
201
+ * 页签正文,由宿主渲染,铺满页签行以下的整个区域。
202
+ * The tab body, rendered by the host and filling everything below the tab row.
200
203
  */
201
204
  content: ReactNode;
202
205
  }
203
- /** 文件操作的执行能力。File operation capabilities. */
206
+ /**
207
+ * 文件操作的执行能力。方法返回的 Promise 完成后才触发对应的成功通知。
208
+ * File operation capabilities. The matching success notification fires only
209
+ * after the returned promise resolves.
210
+ */
204
211
  export interface FilePreviewOperations {
205
- /** 打开当前文件的上级目录。Opens the current file's parent directory. */
206
- openParent?: (path: string) => Promise<void>;
212
+ /**
213
+ * 打开给定的祖先 URI,参数可能指向任意一级目录,不限于当前文件的直接父级。
214
+ * Opens the given ancestor URI. The argument may point at any level, not only
215
+ * the immediate parent of the current file.
216
+ */
217
+ openParent?: (uri: string) => Promise<void>;
207
218
  /** 下载当前文件,完成后返回。Downloads the current file and resolves on completion. */
208
219
  download?: () => Promise<void>;
209
- /** 打开正文引用的资源。Opens a resource referenced by the content. */
220
+ /**
221
+ * 打开正文里被点击的链接,完成后返回。传入后由宿主接管导航,组件阻止默认
222
+ * 跳转;相对路径的解析也归宿主,组件给出的是 Markdown 里的原始目标。
223
+ *
224
+ * 目前只有 Markdown 正文会触发:其它格式的渲染器不提供链接点击回调。
225
+ *
226
+ * Opens a link clicked inside the body and resolves on completion. Supplying it
227
+ * hands navigation to the host — the component prevents the default jump — and
228
+ * resolving relative paths is the host's job too; the component passes the raw
229
+ * target as written in the Markdown.
230
+ *
231
+ * Only Markdown bodies fire this today: the other renderers expose no link-click
232
+ * callback.
233
+ */
210
234
  openUri?: (uri: string) => Promise<void>;
211
235
  }
212
236
  /**
213
237
  * 文件编辑配置。省略时只读;可提供编辑所需的完整文本,并处理保存与取消操作。
214
- * File-editing options. Omit them for a read-only preview. Provide the full
215
- * text to edit and handle save and cancel actions as needed.
238
+ * File-editing options. Omit them for a read-only preview. Provide the full text
239
+ * to edit and handle save and cancel actions as needed.
216
240
  */
217
241
  export interface FilePreviewEditing {
218
242
  /**
@@ -221,14 +245,14 @@ export interface FilePreviewEditing {
221
245
  * 返回 `undefined` 时放弃本次编辑,保持预览态。
222
246
  * Provides the full text when editing is requested, for example for a truncated
223
247
  * preview or a file URL. When omitted, text from `content` or `file` is used;
224
- * URL-only sources require this loader. Returning `undefined` cancels the
225
- * edit request and keeps the preview open.
248
+ * URL-only sources require this loader. Returning `undefined` cancels the edit
249
+ * request and keeps the preview open.
226
250
  */
227
251
  loadContent?: (source: FilePreviewSource) => Promise<string | undefined>;
228
252
  /**
229
253
  * 保存草稿时调用。抛错或 reject 时组件展示失败提示并保留草稿。
230
- * Invoked when the draft is saved. A thrown error or rejection keeps the
231
- * draft and shows a failure message.
254
+ * Invoked when the draft is saved. A thrown error or rejection keeps the draft
255
+ * and shows a failure message.
232
256
  */
233
257
  save: (value: string) => Promise<void>;
234
258
  /**
@@ -244,29 +268,84 @@ export interface FilePreviewEditing {
244
268
  onCancel?: (value: string) => void;
245
269
  }
246
270
  /**
247
- * 所有页签共用的内容区标题行插槽。
248
- * Content-header slots shared by every tab.
271
+ * 交给宿主的动作上下文:组件持有的视图与编辑状态,以及改变它们的方法。
272
+ *
273
+ * 组件只渲染外壳与正文,不内置复制、下载、视图切换、编辑这些按钮;宿主在
274
+ * `slots.actions` 里用这份上下文自己拼。状态仍由组件维护,宿主不必接管。
275
+ *
276
+ * The action context handed to the host: the view and editing state the component
277
+ * owns, plus the methods that change it.
278
+ *
279
+ * The component renders only the shell and the body — it ships no copy, download,
280
+ * view-switch or edit buttons. A host composes them in `slots.actions` from this
281
+ * context. The state stays with the component; the host does not take it over.
282
+ */
283
+ export interface FilePreviewActions {
284
+ /** 当前视图模式。The current view mode. */
285
+ viewMode: FilePreviewViewMode;
286
+ /** 切换到指定视图模式。Switches to the given view mode. */
287
+ setViewMode: (mode: FilePreviewViewMode) => void;
288
+ /**
289
+ * 该页签的格式是否同时支持预览与源码。为 `false` 时不该渲染切换控件。
290
+ * Whether the format supports both preview and source. Do not render a switch
291
+ * when it is `false`.
292
+ */
293
+ canSwitchView: boolean;
294
+ /** 是否处于编辑态。Whether the tab is being edited. */
295
+ editing: boolean;
296
+ /** 是否有保存或读取在进行中。Whether a save or load is in flight. */
297
+ busy: boolean;
298
+ /** 该页签是否可编辑,即可提供 `editing`。Whether the tab is editable. */
299
+ canEdit: boolean;
300
+ /** 进入编辑态。Enters editing. */
301
+ startEditing: () => void;
302
+ /** 保存草稿,成功返回 `true`。Saves the draft, resolving to `true` on success. */
303
+ saveEditing: () => Promise<boolean>;
304
+ /** 放弃草稿并退出编辑态。Discards the draft and leaves editing. */
305
+ cancelEditing: () => void;
306
+ /** 该页签是否有可复制的正文。Whether the tab has copyable body text. */
307
+ canCopyContent: boolean;
308
+ /** 复制正文,成功返回 `true`。Copies the body, resolving to `true` on success. */
309
+ copyContent: () => Promise<boolean>;
310
+ /** 该页签是否有可复制的路径。Whether the tab has a copyable path. */
311
+ canCopyPath: boolean;
312
+ /** 复制路径,成功返回 `true`。Copies the path, resolving to `true` on success. */
313
+ copyPath: () => Promise<boolean>;
314
+ /** 该页签是否可下载。Whether the tab can be downloaded. */
315
+ canDownload: boolean;
316
+ /** 下载当前文件。Downloads the current file. */
317
+ download: () => void;
318
+ }
319
+ /**
320
+ * 文件页签内容区标题行的插槽。内容页签不消费这些——它整块正文由宿主渲染,
321
+ * 没有组件提供的标题行可言。
322
+ *
323
+ * Slots of a file tab's content header. Content tabs do not use them: their whole
324
+ * body is the host's, so there is no component-provided header to fill.
249
325
  */
250
326
  export interface FilePreviewHeaderSlots {
251
327
  /**
252
- * 标题行右侧的额外动作,例如权限设置或删除。
328
+ * 标题行右侧的动作区。组件不内置任何按钮,复制、下载、视图切换、编辑都由
329
+ * 宿主用上下文里的状态与方法自行渲染。
253
330
  *
254
- * 复制与下载使用已有按钮,不需要在这里重复添加。
255
- *
256
- * Extra actions on the right of the header, for example permissions or
257
- * delete.
258
- *
259
- * Use the existing copy and download buttons instead of adding duplicates here.
331
+ * The action area on the right of the header. The component ships no buttons of
332
+ * its own: copy, download, view switch and editing are all rendered by the host
333
+ * from the state and methods in the context.
260
334
  */
261
- actions?: ReactNode;
335
+ actions?: ReactNode | ((actions: FilePreviewActions) => ReactNode);
262
336
  /**
263
- * 标题旁的额外内容。宿主想放在文件名之后的任何东西都可以从这里注入,
264
- * 例如权限标记、状态徽标或版本号;不需要时不传。
265
- * Extra content next to the title. Anything the host wants after the file
266
- * name can go here, for example a permission tag, a status badge or a
267
- * version label; omit it when not needed.
337
+ * 标题旁的额外内容,例如权限标记、状态徽标或版本号;不需要时不传。
338
+ * Extra content next to the title, for example a permission tag, a status badge
339
+ * or a version label; omit it when not needed.
268
340
  */
269
341
  titleExtra?: ReactNode;
342
+ /**
343
+ * 正文下方的补充信息,例如字符数、更新时间或保留策略控件。渲染在正文与
344
+ * 滚动容器之外,不随正文滚动。
345
+ * Supplementary information under the body, for example a character count, an
346
+ * update time or retention controls. Rendered outside the scrolling body.
347
+ */
348
+ footer?: ReactNode;
270
349
  }
271
350
  /**
272
351
  * 文件页签的标题行插槽,以及加载、失败或格式不支持时的替代内容。
@@ -287,11 +366,34 @@ export interface FilePreviewFileTabSlots extends FilePreviewHeaderSlots {
287
366
  */
288
367
  errorFallback?: ReactNode;
289
368
  /**
290
- * 格式不支持时的兜底内容。不传时使用内置提示。
291
- * Fallback when the format cannot be previewed. A built-in message is used
292
- * when omitted.
369
+ * 格式不支持时的兜底内容。格式是否可预览由底座判定,因此这个节点会交给
370
+ * 底座,而不是在组件这边提前判断。传了就由它接管整个不支持态(含底座原本
371
+ * 会给出的下载入口);不传时使用内置提示。
372
+ *
373
+ * Fallback when the format cannot be previewed. Whether a format can be
374
+ * previewed is the base component's call, so this node is handed to it rather
375
+ * than decided here. Supplying it takes over the whole unsupported state,
376
+ * including the download entry the base would otherwise offer; omit it for the
377
+ * built-in message.
293
378
  */
294
379
  unsupportedFallback?: ReactNode;
380
+ /**
381
+ * 大文件确认态的替代内容。需要拿到确认与取消回调,因此是组件而不是节点。
382
+ * 不传时使用内置确认态与底座文案。
383
+ * Replacement for the large-file confirmation state. It receives the confirm
384
+ * and cancel callbacks, so it is a component rather than a node. A built-in
385
+ * state with base copy is used when omitted.
386
+ */
387
+ confirmFallback?: ComponentType<ConfirmSlotProps>;
388
+ /**
389
+ * 无法内联预览时的替代内容,通常包含下载入口。需要拿到下载与重试回调,
390
+ * 因此是组件而不是节点。不传时使用内置提示与底座文案。
391
+ * Replacement for the state where inline preview is impossible, usually with a
392
+ * download entry. It receives the download and retry callbacks, so it is a
393
+ * component rather than a node. A built-in message with base copy is used when
394
+ * omitted.
395
+ */
396
+ downloadFallback?: ComponentType<DownloadSlotProps>;
295
397
  }
296
398
  /**
297
399
  * 可替换文案,组件内置英文默认值。
@@ -299,128 +401,97 @@ export interface FilePreviewFileTabSlots extends FilePreviewHeaderSlots {
299
401
  */
300
402
  export interface FilePreviewLabels {
301
403
  /**
302
- * 复制内容按钮的文案。
303
- * Label of the copy-content button.
304
- */
305
- copyContent?: string;
306
- /**
307
- * 复制内容成功后的提示。
308
- * Message shown after the content was copied.
309
- */
310
- copyContentSuccess?: string;
311
- /**
312
- * 没有内容可复制时的提示。
313
- * Message shown when there is no content to copy.
314
- */
315
- copyContentEmpty?: string;
316
- /**
317
- * 复制路径按钮的文案。
318
- * Label of the copy-path button.
404
+ * 复制路径按钮的文案。这是组件自己渲染的唯一按钮——其余动作按钮由宿主在
405
+ * `slots.actions` 里自绘,文案也归宿主。
406
+ *
407
+ * Label of the copy-path button. It is the only button the component renders
408
+ * itself; every other action button belongs to the host's `slots.actions`,
409
+ * copy included.
319
410
  */
320
411
  copyPath?: string;
321
- /**
322
- * 复制路径成功后的提示。
323
- * Message shown after the path was copied.
324
- */
325
- copyPathSuccess?: string;
326
- /**
327
- * 打开上级目录的按钮文案。
328
- * Label of the control that opens the parent directory.
329
- */
330
- openParent?: string;
331
- /**
332
- * 进入编辑状态的按钮文案。
333
- * Label of the control that enters editing.
334
- */
335
- edit?: string;
336
- /**
337
- * 保存按钮文案。
338
- * Save button label.
339
- */
340
- save?: string;
341
- /**
342
- * 取消编辑的按钮文案。
343
- * Label of the control that leaves editing.
344
- */
345
- cancel?: string;
346
- /**
347
- * 预览视图的文案。
348
- * Label of the preview view.
349
- */
350
- preview?: string;
351
- /**
352
- * 源码视图的文案。
353
- * Label of the source view.
354
- */
355
- source?: string;
356
- /**
357
- * 重试按钮文案。
358
- * Retry button label.
359
- */
412
+ /** 编辑区文本框的无障碍名称。Accessible name of the editor textarea. */
413
+ editor?: string;
414
+ /** 读取失败后退出编辑态的按钮文案。Label of the button that leaves editing after a failed load. */
415
+ leaveEditing?: string;
416
+ /** 重试按钮文案。Retry button label. */
360
417
  retry?: string;
361
- /**
362
- * 读取失败时的提示。
363
- * Message shown when reading failed.
364
- */
418
+ /** 读取失败时的提示。Message shown when reading failed. */
365
419
  loadFailed?: string;
366
- /**
367
- * 保存失败时的提示。
368
- * Message shown when saving failed.
369
- */
420
+ /** 保存失败时的提示。Message shown when saving failed. */
370
421
  saveFailed?: string;
371
- /**
372
- * 无法预览该格式时的提示。
373
- * Message shown when the format cannot be previewed.
374
- */
422
+ /** 无法预览该格式时的提示。Message shown when the format cannot be previewed. */
375
423
  unsupported?: string;
376
- /**
377
- * 取回正文时的加载提示。
378
- * Message shown while the text is being fetched.
379
- */
424
+ /** 取回正文时的加载提示。Message shown while the text is being fetched. */
380
425
  loading?: string;
381
- /**
382
- * 下载按钮文案。
383
- * Label of the download button.
384
- */
426
+ /** 下载按钮文案。Label of the download button. */
385
427
  download?: string;
386
- /**
387
- * 无法预览二进制文件时的提示。
388
- * Message shown when a binary file cannot be previewed.
389
- */
390
- binaryUnsupported?: string;
428
+ /** 文件长度为 0 时的提示。Message shown when the file itself is empty. */
429
+ fileEmpty?: string;
430
+ /** 文件非空但没有可展示内容时的提示。Message shown for a non-empty file with nothing to render. */
431
+ noContent?: string;
432
+ /** 正文被截断时的提示。Message shown when the body was truncated. */
433
+ truncated?: string;
391
434
  }
392
435
  /**
393
- * 通过组件 ref 切换或查询当前页签。
394
- * Switches or queries the active tab through the component ref.
436
+ * 通过组件 ref 切换或查询当前页签,并透传底座的命令式能力。
437
+ * Switches or queries the active tab through the component ref, and exposes the
438
+ * base component's imperative capabilities.
395
439
  */
396
440
  export interface FilePreviewHandle {
397
441
  /**
398
442
  * 切到指定 key 的页签。该页签不存在或被禁用时返回 `false`。
399
- * Switches to the tab with the given key. Returns `false` when the tab does
400
- * not exist or is disabled.
443
+ * Switches to the tab with the given key. Returns `false` when the tab does not
444
+ * exist or is disabled.
401
445
  */
402
446
  setActiveTab: (key: string) => boolean;
447
+ /** 取当前激活页签的 key。Returns the key of the active tab. */
448
+ getActiveTab: () => string;
403
449
  /**
404
- * 取当前激活页签的 key。
405
- * Returns the key of the active tab.
450
+ * 取当前文件页签的底座句柄,用于翻页、搜索、缩放等命令式操作。
451
+ * 当前页签不是文件页签、或底座尚未就绪时返回 `null`。
452
+ * Returns the base handle of the active file tab for page, search and zoom
453
+ * commands. Returns `null` when the active tab is a content tab or the base is
454
+ * not ready yet.
406
455
  */
407
- getActiveTab: () => string;
456
+ getViewerHandle: () => ViewerHandle | null;
408
457
  }
409
458
  /**
410
459
  * 文件预览配置,支持文件页签与自定义内容页签。
411
460
  * 通过页签配置内容与操作,文件页签可提供编辑能力与状态提示。
412
- * File-preview options supporting file tabs and custom-content tabs.
413
- * Configure content and actions per tab; file tabs also support editing options
414
- * and status content.
461
+ * File-preview options supporting file tabs and custom-content tabs. Configure
462
+ * content and actions per tab; file tabs also support editing options and status
463
+ * content.
415
464
  */
416
465
  export interface FilePreviewProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
417
466
  /**
418
- * 页签列表,至少一个。每个页签用 `source` 交给组件按格式渲染,或用
419
- * `content` 完全自定义渲染。
467
+ * 页签列表,至少一个。每个页签用 `source` 交给组件按格式渲染,或用 `content`
468
+ * 完全自定义渲染。
420
469
  * The tab list, at least one entry. Each tab either hands `source` to the
421
470
  * component for format rendering or renders fully custom `content`.
422
471
  */
423
472
  tabs: readonly [FilePreviewTab, ...FilePreviewTab[]];
473
+ /**
474
+ * 受控的当前页签 key。传入时由宿主决定当前页签,组件只上报切换意图。
475
+ * The controlled active tab key. When given, the host owns the active tab and
476
+ * the component only reports switch intent.
477
+ */
478
+ activeKey?: string;
479
+ /**
480
+ * 非受控时的初始页签 key,省略时选中第一个。
481
+ * Initial tab key when uncontrolled; the first tab is selected when omitted.
482
+ */
483
+ defaultActiveKey?: string;
484
+ /**
485
+ * 底座内置文案的语言。组件自身文案仍由 `labels` 控制。
486
+ * Language of the base component's built-in copy. The component's own copy is
487
+ * still controlled by `labels`.
488
+ */
489
+ locale?: 'en-US' | 'zh-CN';
490
+ /**
491
+ * 当前页签变化后触发,参数为新的页签 key。
492
+ * Called after the active tab changes, with the new tab key.
493
+ */
494
+ onActiveKeyChange?: (key: string) => void;
424
495
  /**
425
496
  * 所有页签的默认文案,缺省为英文。页签可以逐项覆盖。
426
497
  * Default copy for every tab, English by default. A tab can override it field
@@ -433,3 +504,13 @@ export interface FilePreviewProps extends Omit<HTMLAttributes<HTMLDivElement>, '
433
504
  * A file-preview component whose ref supports switching and querying tabs.
434
505
  */
435
506
  export type FilePreviewComponent = ForwardRefExoticComponent<PropsWithoutRef<FilePreviewProps> & RefAttributes<FilePreviewHandle>>;
507
+ /**
508
+ * 文件页签的视图模式。底座的 `ViewerViewMode` 是不透明的字符串,这里只收
509
+ * 组件自己会切换的两种;其它格式的私有模式(Word 版式/阅读、CAD 2D/3D)
510
+ * 由底座与 Adapter 自行管理,不经过组件。
511
+ *
512
+ * View modes of a file tab. The base `ViewerViewMode` is an opaque string; only
513
+ * the two the component switches between are listed here. Format-private modes
514
+ * (Word layout/reading, CAD 2D/3D) are managed by the base and its adapters.
515
+ */
516
+ export type FilePreviewViewMode = 'preview' | 'source';
@@ -0,0 +1,23 @@
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, 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, viewMode, canSwitchView, setViewMode, editing, operations, }: {
15
+ activeTab: FilePreviewTab;
16
+ fileTab?: FilePreviewFileTab;
17
+ viewMode: FilePreviewViewMode;
18
+ canSwitchView: boolean;
19
+ setViewMode: (mode: FilePreviewViewMode) => void;
20
+ editing: Editing;
21
+ operations: Operations;
22
+ }): FilePreviewActions;
23
+ 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: FilePreviewFileTab, 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
  };