Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setContent typing to accept JSONContent #242

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/bridges/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { focusListener } from '../webEditorUtils/focusListener';
import Document from '@tiptap/extension-document';
import Paragraph from '@tiptap/extension-paragraph';
import Text from '@tiptap/extension-text';
import type { Content } from '@tiptap/react';

export type EditorContentType = 'html' | 'text' | 'json';

Expand All @@ -21,7 +22,7 @@ type CoreEditorInstance = {
getHTML: () => Promise<string>;
getJSON: () => Promise<object>;
getText: () => Promise<string>;
setContent: (content: string) => void;
setContent: (content: Content) => void;
setSelection: (from: number, to: number) => void;
updateScrollThresholdAndMargin: (offset: number) => void;
focus: (pos: FocusArgs) => void;
Expand Down Expand Up @@ -102,7 +103,7 @@ export type CoreMessages =
| {
type: CoreEditorActionType.SetContent;
payload: {
content: string;
content: Content;
};
}
| {
Expand Down Expand Up @@ -270,7 +271,7 @@ export const CoreBridge = new BridgeExtension<
},
});
},
setContent: (content: string) => {
setContent: (content: Content) => {
sendBridgeMessage({
type: CoreEditorActionType.SetContent,
payload: {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/api/EditorBridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ an async function that will return the content of the editor in json format <br

#### setContent

`(content: string) => void`<br />
a function that get's html as string and set set's it as the editors content <br /> extended by [CoreBridge](./BridgeExtensions#coreextension)
`(content: Content) => void`<br />
a function that get's html as string or document object and set set's it as the editors content <br /> extended by [CoreBridge](./BridgeExtensions#coreextension)

#### setEditable

Expand Down
Loading