@vibe-tiptap/shadcn-ui 1.0.0 → 1.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.
- package/README.md +24 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.js +878 -733
- package/dist/mention-menu.d.ts +12 -0
- package/dist/mention-popover.d.ts +10 -0
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +9 -2
- package/dist/use-vibe-tiptap.d.ts +3 -1
- 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)
|
|
@@ -73,20 +84,6 @@ export const shadcnTiptapComponents = {
|
|
|
73
84
|
- Select、Tooltip、Popover、DropdownMenu 和 Dialog 的 `Content` 将浮层 Portal 到传入的 `container`。Select 宿主也提供选项文本和 Viewport。Popover 的 `Anchor` 支持通过 `virtualRef` 读取选区坐标。
|
|
74
85
|
- 浮层转发组件类型中定义的 Escape、外部交互和自动聚焦回调,保留事件的 `preventDefault()` 行为。宿主提供浮层面板外观和 Dialog 遮罩颜色。Dialog 将 `overlayClassName` 用于遮罩、将 `className` 转发给面板,以应用编辑器的全屏布局。
|
|
75
86
|
- 分别组合工具栏、内容区和状态栏时,将三者置于带 `vibe-shadcn-tiptap` 类的容器中。独立的 `ShadcnTiptapToolbar` 同时接收 `components` 和 `context`,可通过 `overlayTarget` 指定当前主题容器内的浮层挂载点。内容区和状态栏接收 `context`。
|
|
76
|
-
|
|
77
|
-
## 从 Radix UI 包迁移
|
|
78
|
-
|
|
79
|
-
| 原接口 | 新接口 |
|
|
80
|
-
| --- | --- |
|
|
81
|
-
| `@vibe-tiptap/radix-ui` | `@vibe-tiptap/shadcn-ui` |
|
|
82
|
-
| `@vibe-tiptap/radix-ui/style.css` | `@vibe-tiptap/shadcn-ui/style.css` |
|
|
83
|
-
| `RadixTiptapEditor`、`RadixTiptapToolbar`、`RadixTiptapContent`、`RadixTiptapStatusBar` 及其 Props 和 Expose 类型 | 将 `RadixTiptap` 前缀替换为 `ShadcnTiptap` |
|
|
84
|
-
| `RadixToolbarBuiltinKey`、`RadixToolbarConfig`、`RadixToolbarProp` | `ShadcnTiptapToolbarBuiltinKey`、`ShadcnTiptapToolbarConfig`、`ShadcnTiptapToolbarProp` |
|
|
85
|
-
| `RADIX_UI_DEFAULT_TOOLBAR` | `SHADCN_UI_DEFAULT_TOOLBAR` |
|
|
86
|
-
| `vibe-radix-tiptap` CSS 前缀 | `vibe-shadcn-tiptap` CSS 前缀 |
|
|
87
|
-
|
|
88
|
-
迁移后,为编辑器和独立工具栏传入宿主组件映射,并更新自定义样式与测试选择器。
|
|
89
|
-
|
|
90
87
|
## Tailwind CSS v4
|
|
91
88
|
|
|
92
89
|
在应用入口导入包样式,并在宿主的 Tailwind 样式表中用 `@source` 扫描包的构建产物,以生成工具栏、气泡菜单和表单使用的工具类。路径以该样式表所在目录为基准。
|
|
@@ -144,6 +141,13 @@ export const shadcnTiptapComponents = {
|
|
|
144
141
|
contentClassName: 'pt-1',
|
|
145
142
|
},
|
|
146
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
|
+
},
|
|
147
151
|
imagePreview: {
|
|
148
152
|
iconButton: { size: 'icon-sm' },
|
|
149
153
|
button: { size: 'sm', variant: 'outline' },
|
|
@@ -162,6 +166,8 @@ export const shadcnTiptapComponents = {
|
|
|
162
166
|
|
|
163
167
|
斜杠菜单和表格尺寸网格使用原生按钮,通过 `slashMenu.button.className` 和 `tablePicker.button.className` 覆盖尺寸和外观。
|
|
164
168
|
|
|
169
|
+
`mentionMenu.className` 作用于 Mention 菜单容器。`button.className`、`groupClassName` 和 `groupLabelClassName` 分别作用于候选按钮、具名分组和组标题。`statusClassName` 作用于加载中和无结果提示。
|
|
170
|
+
|
|
165
171
|
媒体插入浮层的 `insertionPopover.tabs` 支持通过 `className`、`listClassName` 和 `contentClassName` 分别设置 Tabs 容器、页签列表和内容区。`trigger` 支持 `size`、`variant` 和 `className`,优先于浮层的 `button` 配置。
|
|
166
172
|
|
|
167
173
|
链接浮层的 `insertionPopover.checkbox` 控制「在新窗口打开」复选框,支持 `size`、`variant` 和 `className`,优先于浮层的 `button` 配置。
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type { PrintActionOptions, PrintOptions, } from '@vibe-tiptap/editor-ui/p
|
|
|
5
5
|
export { printEditorContent } from '@vibe-tiptap/editor-ui/print-editor-content';
|
|
6
6
|
export type { CodeBlockLanguageOption, HorizontalRuleOption, ResolvedToolbarMenuOptions, ResolvedToolbarTableGridOptions, ToolbarAlignOption, ToolbarHeadingLevel, ToolbarHeadingOption, ToolbarOptions as ToolbarMenuOptions, ToolbarTableGridOptions, ToolbarTextAlign, } from '@vibe-tiptap/editor-ui/toolbar-config';
|
|
7
7
|
export { DEFAULT_CODE_BLOCK_LANGUAGES, DEFAULT_HORIZONTAL_RULES, NAIVE_UI_DEFAULT_TOOLBAR as SHADCN_UI_DEFAULT_TOOLBAR, normalizeToolbarConfig, TOOLBAR_ALIGN_OPTIONS, TOOLBAR_HEADING_OPTIONS, TOOLBAR_TABLE_GRID, } from '@vibe-tiptap/editor-ui/toolbar-config';
|
|
8
|
-
export type { ImagePreviewEvent, ReactEditorContext } from '@vibe-tiptap/react-adapter';
|
|
8
|
+
export type { ImagePreviewEvent, MentionClickEvent, MentionItem, MentionOptions, MentionTarget, ReactEditorContext, } from '@vibe-tiptap/react-adapter';
|
|
9
9
|
export type { ShadcnTiptapComponents } from './components.js';
|
|
10
10
|
export { ShadcnTiptapContent, ShadcnTiptapStatusBar } from './editor-content.js';
|
|
11
11
|
export { ShadcnTiptapEditor, ShadcnTiptapEditor as VibeTiptap } from './shadcn-tiptap-editor.js';
|