@vibe-tiptap/shadcn-ui 1.1.0 → 1.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.
- package/README.md +24 -4
- package/dist/index.js +550 -516
- package/dist/mention-menu.d.ts +3 -1
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/vibe-tiptap-provider.d.ts +4 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vibe-tiptap/shadcn-ui
|
|
2
2
|
|
|
3
|
-
React 编辑器与 Naive UI 版共用 Tiptap schema
|
|
3
|
+
React 编辑器与 Naive UI 版共用 Tiptap schema、编辑命令和文档格式。默认启用工具栏、斜杠菜单和字数统计。
|
|
4
4
|
|
|
5
5
|
```tsx
|
|
6
6
|
import { useVibeTiptap, VibeTiptap, VibeTiptapProvider } from '@vibe-tiptap/shadcn-ui'
|
|
@@ -8,7 +8,12 @@ import '@vibe-tiptap/shadcn-ui/style.css'
|
|
|
8
8
|
import { shadcnTiptapComponents } from './shadcn-tiptap-components'
|
|
9
9
|
|
|
10
10
|
export function DocumentEditor() {
|
|
11
|
-
const editor = useVibeTiptap({
|
|
11
|
+
const editor = useVibeTiptap({
|
|
12
|
+
initialContent: {
|
|
13
|
+
type: 'doc',
|
|
14
|
+
content: [{ type: 'paragraph', content: [{ type: 'text', text: '正文' }] }],
|
|
15
|
+
},
|
|
16
|
+
})
|
|
12
17
|
return <VibeTiptap editor={editor} />
|
|
13
18
|
}
|
|
14
19
|
|
|
@@ -16,6 +21,10 @@ export function App() {
|
|
|
16
21
|
return (
|
|
17
22
|
<VibeTiptapProvider
|
|
18
23
|
components={shadcnTiptapComponents}
|
|
24
|
+
mediaResources={{
|
|
25
|
+
prefix: 'https://cdn.example.com/assets/',
|
|
26
|
+
resolve: (path, prefix) => new URL(path, prefix).href,
|
|
27
|
+
}}
|
|
19
28
|
ui={{ toolbar: { className: 'gap-2' } }}
|
|
20
29
|
showWordCount={false}
|
|
21
30
|
>
|
|
@@ -25,14 +34,16 @@ export function App() {
|
|
|
25
34
|
}
|
|
26
35
|
```
|
|
27
36
|
|
|
28
|
-
`useVibeTiptap` 接收 `UseVibeTiptapOptions`。`initialContent`
|
|
37
|
+
`useVibeTiptap` 接收 `UseVibeTiptapOptions`。`initialContent` 接受用于恢复编辑的 JSON,也可接收待导入的 HTML。它与扩展、语言、placeholder 和斜杠菜单配置一起在初始化时读取。需要重建实例时,将 `key` 放在调用 hook 的组件上。
|
|
29
38
|
|
|
30
|
-
`editor.context` 在客户端挂载后可用,可调用 `setContent()`、`getContent()` 和 `editor.commands.focus()`(`editor` 为上下文中的 Tiptap
|
|
39
|
+
`editor.context` 在客户端挂载后可用,可调用 `setContent()`、`getContent()` 和 `editor.commands.focus()`(`editor` 为上下文中的 Tiptap 实例)。保存前必须等待上下文的 `canSave` 为 `true`,再调用 `getContent()` 读取最新 JSON。分发时可调用 `getHTML()` 或 `getMarkdown()`。将 `onImagePreview` 传给 hook,回调会收到按文档顺序排列的图片 URL 和当前索引。
|
|
31
40
|
|
|
32
41
|
每个 hook 实例可挂载一个 `VibeTiptap` 视图。卸载视图后仍可通过上下文读写文档,调用 hook 的组件卸载时销毁实例。工具栏、字数统计、色板和样式由 `VibeTiptap` 配置。
|
|
33
42
|
|
|
34
43
|
`VibeTiptapProvider` 为其子树中的编辑器和独立工具栏提供 `components`、`ui`、`toolbar`、`toolbarOptions`、`colors`、`highlights`、`markdownOptions` 和 `printOptions` 的默认值,也可通过 `showWordCount` 配置编辑器的字数统计。组件可以直接接收 `components`,也可以从 Provider 继承。嵌套 Provider 继承外层默认值,各组件可通过自身 props 覆盖。每个 prop 按整体覆盖,例如传入 `ui` 会替换整个默认 `ui` 对象。
|
|
35
44
|
|
|
45
|
+
在 `VibeTiptapProvider` 下调用 `useVibeTiptap()` 时,hook 会在初始化时读取继承的 `mediaResources`,用于解析上传资源的展示和导出地址。嵌套 Provider 或 hook 显式传入的 `mediaResources` 会整体覆盖继承值,传入 `{}` 可关闭路径解析。
|
|
46
|
+
|
|
36
47
|
## 宿主组件
|
|
37
48
|
|
|
38
49
|
使用宿主的 shadcn/ui 控件建立完整映射,并用 `satisfies ShadcnTiptapComponents` 检查类型。以下名称对应宿主适配后的组件。[Playground 完整适配源码](../../apps/playground/src/components/shadcn-tiptap-components.tsx)
|
|
@@ -130,6 +141,13 @@ export const shadcnTiptapComponents = {
|
|
|
130
141
|
contentClassName: 'pt-1',
|
|
131
142
|
},
|
|
132
143
|
},
|
|
144
|
+
mentionMenu: {
|
|
145
|
+
className: 'w-80',
|
|
146
|
+
button: { className: 'min-h-10 rounded-md' },
|
|
147
|
+
groupClassName: 'pb-2',
|
|
148
|
+
groupLabelClassName: 'text-sm',
|
|
149
|
+
statusClassName: 'text-center',
|
|
150
|
+
},
|
|
133
151
|
imagePreview: {
|
|
134
152
|
iconButton: { size: 'icon-sm' },
|
|
135
153
|
button: { size: 'sm', variant: 'outline' },
|
|
@@ -148,6 +166,8 @@ export const shadcnTiptapComponents = {
|
|
|
148
166
|
|
|
149
167
|
斜杠菜单和表格尺寸网格使用原生按钮,通过 `slashMenu.button.className` 和 `tablePicker.button.className` 覆盖尺寸和外观。
|
|
150
168
|
|
|
169
|
+
`mentionMenu.className` 作用于 Mention 菜单容器。`button.className`、`groupClassName` 和 `groupLabelClassName` 分别作用于候选按钮、具名分组和组标题。`statusClassName` 作用于加载中和无结果提示。
|
|
170
|
+
|
|
151
171
|
媒体插入浮层的 `insertionPopover.tabs` 支持通过 `className`、`listClassName` 和 `contentClassName` 分别设置 Tabs 容器、页签列表和内容区。`trigger` 支持 `size`、`variant` 和 `className`,优先于浮层的 `button` 配置。
|
|
152
172
|
|
|
153
173
|
链接浮层的 `insertionPopover.checkbox` 控制「在新窗口打开」复选框,支持 `size`、`variant` 和 `className`,优先于浮层的 `button` 配置。
|