@vibe-tiptap/react-adapter 0.0.0-stage → 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 vibe-tiptap contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,61 @@
1
- # Temporary Holding Version
1
+ # @vibe-tiptap/react-adapter
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 供 shadcn/ui、Ant Design 等 React 应用复用的 Tiptap 接入层。应用提供工具栏、弹层和消息提示样式,适配器负责编辑器实例、内容挂载和状态订阅。
4
+
5
+ 安装适配器和 React peer dependencies:
6
+
7
+ ```sh
8
+ pnpm add @vibe-tiptap/react-adapter react react-dom
9
+ ```
10
+
11
+ 适配器会安装 `@vibe-tiptap/core`,可直接从 Core 的公开入口引入编辑器基础样式。
12
+
13
+ ```tsx
14
+ 'use client'
15
+
16
+ import {
17
+ EditorContent,
18
+ useReactEditor,
19
+ useReactEditorState,
20
+ } from '@vibe-tiptap/react-adapter'
21
+ import '@vibe-tiptap/core/style.css'
22
+
23
+ interface RichTextEditorProps {
24
+ initialContent: string
25
+ readOnly?: boolean
26
+ onUpdate: (value: string) => void
27
+ }
28
+
29
+ export function RichTextEditor({ initialContent, readOnly, onUpdate }: RichTextEditorProps) {
30
+ const context = useReactEditor({
31
+ content: initialContent,
32
+ editable: !readOnly,
33
+ onUpdate: (content) => {
34
+ if (typeof content === 'string') onUpdate(content)
35
+ },
36
+ })
37
+ const bold = useReactEditorState(context, (editor) => editor.isActive('bold'))
38
+
39
+ return (
40
+ <div>
41
+ <button
42
+ type="button"
43
+ disabled={!context || readOnly}
44
+ aria-pressed={bold ?? false}
45
+ onMouseDown={(event) => event.preventDefault()}
46
+ onClick={() => context?.commands.bold()}
47
+ >
48
+ 加粗
49
+ </button>
50
+ <EditorContent editor={context?.editor ?? null} />
51
+ </div>
52
+ )
53
+ }
54
+ ```
55
+
56
+ - `useReactEditor` 在客户端挂载后创建编辑器,卸载时销毁。SSR 和首次渲染时返回 `undefined`。
57
+ - `content` 接受 HTML 或 JSON,仅在创建编辑器时读取。后续通过 `setContent()` 写入,通过 `getContent()` 按 `output` 格式读取;编辑器内的文档变化通过 `onUpdate` 通知。
58
+ - `useReactEditorState` 可订阅格式、字数、表格、查找替换、上传与保存状态。选择器返回对象时,可传入第三个参数比较结果。
59
+ - 工具栏可直接调用 `context.commands`,也可复用 Core 导出的 `COMMAND_REGISTRY`、`isToolbarCommandEnabled` 等 API。适配器同时导出 Tiptap 的 `BubbleMenu`、`FloatingMenu` 与 React Node View API。
60
+ - `editable`、输出格式和事件回调随 props 更新。扩展、语言、占位符、`editorProps` 等初始化配置变化时,用 React 的 `key` 重新挂载编辑器。
61
+ - 需要在 React 组件之外创建实例时,可在浏览器调用 `createReactEditor`,使用结束后调用 `destroy()`。
@@ -0,0 +1,7 @@
1
+ export { EditorContent, NodeViewContent, NodeViewWrapper, ReactMarkViewRenderer, ReactNodeViewRenderer, } from '@tiptap/react';
2
+ export { BubbleMenu, FloatingMenu } from '@tiptap/react/menus';
3
+ export * from '@vibe-tiptap/core';
4
+ export type { ReactEditorContext } from './react-editor.js';
5
+ export { createReactEditor, useReactEditor } from './react-editor.js';
6
+ export { useReactEditorState } from './use-react-editor-state.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC9D,cAAc,mBAAmB,CAAA;AACjC,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use client';
2
+ export { EditorContent, NodeViewContent, NodeViewWrapper, ReactMarkViewRenderer, ReactNodeViewRenderer, } from '@tiptap/react';
3
+ export { BubbleMenu, FloatingMenu } from '@tiptap/react/menus';
4
+ export * from '@vibe-tiptap/core';
5
+ export { createReactEditor, useReactEditor } from './react-editor.js';
6
+ export { useReactEditorState } from './use-react-editor-state.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EACL,aAAa,EACb,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC9D,cAAc,mBAAmB,CAAA;AAEjC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { CoreEditorContext, CoreEditorOptions, SlashCommandBridgeOptions } from '@vibe-tiptap/core';
2
+ export interface ReactEditorContext extends CoreEditorContext {
3
+ /** 供 React 订阅的版本号,包含事务及只读状态变更。 */
4
+ readonly getRevision: () => number;
5
+ /** 供工具栏和浮层订阅的版本号,仅包含其依赖的编辑器状态变化。 */
6
+ readonly getToolbarRevision: () => number;
7
+ }
8
+ /** 在浏览器中创建可供 React 订阅的编辑器,调用方负责销毁。 */
9
+ export declare function createReactEditor(options?: CoreEditorOptions, slashCommandBridge?: SlashCommandBridgeOptions): ReactEditorContext;
10
+ /** 挂载后创建编辑器,卸载时销毁。扩展、语言等初始化配置在挂载时读取。 */
11
+ export declare function useReactEditor(options?: CoreEditorOptions, slashCommandBridge?: SlashCommandBridgeOptions): ReactEditorContext | undefined;
12
+ //# sourceMappingURL=react-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-editor.d.ts","sourceRoot":"","sources":["../src/react-editor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,mBAAmB,CAAA;AAI1B,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,kCAAkC;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,MAAM,CAAA;IAClC,oCAAoC;IACpC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,MAAM,CAAA;CAC1C;AAED,sCAAsC;AACtC,wBAAgB,iBAAiB,CAC/B,OAAO,GAAE,iBAAsB,EAC/B,kBAAkB,CAAC,EAAE,yBAAyB,GAC7C,kBAAkB,CAmBpB;AAED,wCAAwC;AACxC,wBAAgB,cAAc,CAC5B,OAAO,GAAE,iBAAsB,EAC/B,kBAAkB,CAAC,EAAE,yBAAyB,GAC7C,kBAAkB,GAAG,SAAS,CAuDhC"}
@@ -0,0 +1,71 @@
1
+ import { createCoreEditor } from '@vibe-tiptap/core';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ /** 在浏览器中创建可供 React 订阅的编辑器,调用方负责销毁。 */
4
+ export function createReactEditor(options = {}, slashCommandBridge) {
5
+ const core = createCoreEditor(options, slashCommandBridge);
6
+ let revision = 0;
7
+ let toolbarRevision = 0;
8
+ core.subscribe((event) => {
9
+ revision += 1;
10
+ if (event.docChanged ||
11
+ event.selectionSet ||
12
+ event.pendingUploadsChanged ||
13
+ event.editableChanged) {
14
+ toolbarRevision += 1;
15
+ }
16
+ });
17
+ return Object.assign(core, {
18
+ getRevision: () => revision,
19
+ getToolbarRevision: () => toolbarRevision,
20
+ });
21
+ }
22
+ /** 挂载后创建编辑器,卸载时销毁。扩展、语言等初始化配置在挂载时读取。 */
23
+ export function useReactEditor(options = {}, slashCommandBridge) {
24
+ const [context, setContext] = useState();
25
+ const current = useRef(undefined);
26
+ const committedOptions = useRef(options);
27
+ const initialSlashCommandBridge = useRef(slashCommandBridge);
28
+ useEffect(() => {
29
+ const previous = committedOptions.current;
30
+ committedOptions.current = options;
31
+ const editor = current.current;
32
+ if (!editor || editor.editor.isDestroyed)
33
+ return;
34
+ if (options.editable !== undefined && options.editable !== previous.editable) {
35
+ editor.setEditable(options.editable);
36
+ }
37
+ });
38
+ useEffect(() => {
39
+ const editor = createReactEditor({
40
+ ...committedOptions.current,
41
+ get output() {
42
+ return committedOptions.current.output;
43
+ },
44
+ get uploadAsset() {
45
+ return committedOptions.current.uploadAsset;
46
+ },
47
+ get editorBehaviorOptions() {
48
+ return committedOptions.current.editorBehaviorOptions;
49
+ },
50
+ get debug() {
51
+ return committedOptions.current.debug;
52
+ },
53
+ get debugLogger() {
54
+ return committedOptions.current.debugLogger;
55
+ },
56
+ get onImagePreview() {
57
+ return committedOptions.current.onImagePreview;
58
+ },
59
+ onUpdate: (value, instance) => committedOptions.current.onUpdate?.(value, instance),
60
+ notify: (...args) => committedOptions.current.notify?.(...args),
61
+ }, initialSlashCommandBridge.current);
62
+ current.current = editor;
63
+ setContext(editor);
64
+ return () => {
65
+ current.current = undefined;
66
+ editor.destroy();
67
+ };
68
+ }, []);
69
+ return context;
70
+ }
71
+ //# sourceMappingURL=react-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-editor.js","sourceRoot":"","sources":["../src/react-editor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AASnD,sCAAsC;AACtC,MAAM,UAAU,iBAAiB,CAC/B,UAA6B,EAAE,EAC/B,kBAA8C;IAE9C,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAA;IAC1D,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,eAAe,GAAG,CAAC,CAAA;IACvB,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,QAAQ,IAAI,CAAC,CAAA;QACb,IACE,KAAK,CAAC,UAAU;YAChB,KAAK,CAAC,YAAY;YAClB,KAAK,CAAC,qBAAqB;YAC3B,KAAK,CAAC,eAAe,EACrB,CAAC;YACD,eAAe,IAAI,CAAC,CAAA;QACtB,CAAC;IACH,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACzB,WAAW,EAAE,GAAG,EAAE,CAAC,QAAQ;QAC3B,kBAAkB,EAAE,GAAG,EAAE,CAAC,eAAe;KAC1C,CAAC,CAAA;AACJ,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,cAAc,CAC5B,UAA6B,EAAE,EAC/B,kBAA8C;IAE9C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,EAAsB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,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC;YACnF,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;SAChE,EACD,yBAAyB,CAAC,OAAO,CAClC,CAAA;QACD,OAAO,CAAC,OAAO,GAAG,MAAM,CAAA;QACxB,UAAU,CAAC,MAAM,CAAC,CAAA;QAElB,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,OAAO,GAAG,SAAS,CAAA;YAC3B,MAAM,CAAC,OAAO,EAAE,CAAA;QAClB,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ReactEditorContext } from './react-editor.js';
2
+ /** 订阅选择器的结果。对象结果可传入比较函数以跳过等价更新。 */
3
+ export declare function useReactEditorState<T>(context: ReactEditorContext | undefined, selector: (context: ReactEditorContext) => T, isEqual?: (previous: T, next: T) => boolean): T | undefined;
4
+ //# sourceMappingURL=use-react-editor-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-react-editor-state.d.ts","sourceRoot":"","sources":["../src/use-react-editor-state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAK3D,mCAAmC;AACnC,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,OAAO,EAAE,kBAAkB,GAAG,SAAS,EACvC,QAAQ,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,CAAC,EAC5C,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,OAAO,GAC1C,CAAC,GAAG,SAAS,CAUf"}
@@ -0,0 +1,9 @@
1
+ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js';
2
+ const subscribeEmpty = () => () => { };
3
+ const getEmptyRevision = () => 0;
4
+ /** 订阅选择器的结果。对象结果可传入比较函数以跳过等价更新。 */
5
+ export function useReactEditorState(context, selector, isEqual) {
6
+ return useSyncExternalStoreWithSelector(context?.subscribe ?? subscribeEmpty, context?.getRevision ?? getEmptyRevision, getEmptyRevision, () => (context ? selector(context) : undefined), (previous, next) => Object.is(previous, next) ||
7
+ (previous !== undefined && next !== undefined && (isEqual?.(previous, next) ?? false)));
8
+ }
9
+ //# sourceMappingURL=use-react-editor-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-react-editor-state.js","sourceRoot":"","sources":["../src/use-react-editor-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAA;AAGhG,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,CAAA;AACrC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,CAAC,CAAA;AAEhC,mCAAmC;AACnC,MAAM,UAAU,mBAAmB,CACjC,OAAuC,EACvC,QAA4C,EAC5C,OAA2C;IAE3C,OAAO,gCAAgC,CACrC,OAAO,EAAE,SAAS,IAAI,cAAc,EACpC,OAAO,EAAE,WAAW,IAAI,gBAAgB,EACxC,gBAAgB,EAChB,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAC/C,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CACjB,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC;QACzB,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CACzF,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@vibe-tiptap/react-adapter",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Vibe Tiptap 的 React 编辑器适配层",
5
+ "license": "ISC",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "@tiptap/core": "3.31.3",
24
+ "@tiptap/pm": "3.31.3",
25
+ "@tiptap/react": "3.31.3",
26
+ "@vibe-tiptap/core": "1.0.0",
27
+ "use-sync-external-store": "^1.7.0"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "^18.0.0 || ^19.0.0",
31
+ "react-dom": "^18.0.0 || ^19.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@testing-library/react": "^16.3.3",
35
+ "@types/react": "^19.3.0",
36
+ "@types/react-dom": "^19.3.0",
37
+ "@types/use-sync-external-store": "^0.0.6",
38
+ "happy-dom": "^20.14.5",
39
+ "react": "^19.3.0",
40
+ "react-dom": "^19.3.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json",
44
+ "typecheck": "tsc -p tsconfig.json --noEmit",
45
+ "test": "vitest run",
46
+ "bench": "vitest bench --run --config vitest.bench.config.ts"
47
+ }
6
48
  }