Vanilla JavaScript
No framework? No problem. ProseKit works with plain JavaScript out of the box via prosekit/core.
Minimal editor
Section titled “Minimal editor”import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'
import { defineBasicExtension function defineBasicExtension(): BasicExtensionDefine a basic extension that includes some common functionality. You can
copy this function and customize it to your needs.
It's a combination of the following extension functions:
-
{@link
defineDoc
}
-
{@link
defineText
}
-
{@link
defineParagraph
}
-
{@link
defineHeading
}
-
{@link
defineList
}
-
{@link
defineBlockquote
}
-
{@link
defineImage
}
-
{@link
defineHorizontalRule
}
-
{@link
defineHardBreak
}
-
{@link
defineTable
}
-
{@link
defineCodeBlock
}
-
{@link
defineItalic
}
-
{@link
defineBold
}
-
{@link
defineUnderline
}
-
{@link
defineStrike
}
-
{@link
defineCode
}
-
{@link
defineLink
}
-
{@link
defineBaseKeymap
}
-
{@link
defineBaseCommands
}
-
{@link
defineHistory
}
-
{@link
defineGapCursor
}
-
{@link
defineVirtualSelection
}
-
{@link
defineModClickPrevention
} } from 'prosekit/basic'
import { createEditor function createEditor<E extends Extension>(options: EditorOptions<E>): Editor<E> } from 'prosekit/core'
const editor const editor: Editor<BasicExtension> = createEditor createEditor<BasicExtension>(options: EditorOptions<BasicExtension>): Editor<BasicExtension> ({ extension EditorOptions<BasicExtension>.extension: BasicExtensionThe extension to use when creating the editor. : defineBasicExtension function defineBasicExtension(): BasicExtensionDefine a basic extension that includes some common functionality. You can
copy this function and customize it to your needs.
It's a combination of the following extension functions:
-
{@link
defineDoc
}
-
{@link
defineText
}
-
{@link
defineParagraph
}
-
{@link
defineHeading
}
-
{@link
defineList
}
-
{@link
defineBlockquote
}
-
{@link
defineImage
}
-
{@link
defineHorizontalRule
}
-
{@link
defineHardBreak
}
-
{@link
defineTable
}
-
{@link
defineCodeBlock
}
-
{@link
defineItalic
}
-
{@link
defineBold
}
-
{@link
defineUnderline
}
-
{@link
defineStrike
}
-
{@link
defineCode
}
-
{@link
defineLink
}
-
{@link
defineBaseKeymap
}
-
{@link
defineBaseCommands
}
-
{@link
defineHistory
}
-
{@link
defineGapCursor
}
-
{@link
defineVirtualSelection
}
-
{@link
defineModClickPrevention
} () })
const root const root: Element | null = document var document: Document**`window.document`** returns a reference to the document contained in the window.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/document) .querySelector ParentNode.querySelector<Element>(selectors: string): Element | null (+4 overloads)Returns the first element that is a descendant of node that matches selectors.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/querySelector) ('#editor')
if (root const root: Element | null ) {
editor const editor: Editor<BasicExtension> .mount Editor<BasicExtension>.mount: (place: HTMLElement | null | undefined) => void | VoidFunctionMount the editor to the given HTML element. Pass `null` or `undefined` to
unmount the editor. When an element is passed, this method returns a
function to unmount the editor. (root const root: Element as HTMLElement)
}Lifecycle
Section titled “Lifecycle”You’re responsible for mount / unmount and any clean-up. There is no provider; pass the editor instance to anything that needs it.
editor const editor: Editor<BasicExtension> .mount Editor<BasicExtension>.mount: (place: HTMLElement | null | undefined) => void | VoidFunctionMount the editor to the given HTML element. Pass `null` or `undefined` to
unmount the editor. When an element is passed, this method returns a
function to unmount the editor. (root const root: HTMLElement )
// when you're done with the editor:
editor const editor: Editor<BasicExtension> .unmount Editor<BasicExtension>.unmount: () => voidUnmount the editor. This is equivalent to `mount(null)`. ()editor.use(extension) and the per-event handlers from prosekit/core (e.g. defineKeymap, defineDocChangeHandler) let you wire dynamic behavior without a framework.
Reacting to changes
Section titled “Reacting to changes”Listen for state updates with defineUpdateHandler or the view.dom element directly:
import { defineBasicExtension function defineBasicExtension(): BasicExtensionDefine a basic extension that includes some common functionality. You can
copy this function and customize it to your needs.
It's a combination of the following extension functions:
-
{@link
defineDoc
}
-
{@link
defineText
}
-
{@link
defineParagraph
}
-
{@link
defineHeading
}
-
{@link
defineList
}
-
{@link
defineBlockquote
}
-
{@link
defineImage
}
-
{@link
defineHorizontalRule
}
-
{@link
defineHardBreak
}
-
{@link
defineTable
}
-
{@link
defineCodeBlock
}
-
{@link
defineItalic
}
-
{@link
defineBold
}
-
{@link
defineUnderline
}
-
{@link
defineStrike
}
-
{@link
defineCode
}
-
{@link
defineLink
}
-
{@link
defineBaseKeymap
}
-
{@link
defineBaseCommands
}
-
{@link
defineHistory
}
-
{@link
defineGapCursor
}
-
{@link
defineVirtualSelection
}
-
{@link
defineModClickPrevention
} } from 'prosekit/basic'
import { createEditor function createEditor<E extends Extension>(options: EditorOptions<E>): Editor<E> , defineUpdateHandler function defineUpdateHandler(handler: UpdateHandler): PlainExtensionRegisters a event handler that is called when the editor state is updated. } from 'prosekit/core'
const editor const editor: Editor<BasicExtension> = createEditor createEditor<BasicExtension>(options: EditorOptions<BasicExtension>): Editor<BasicExtension> ({ extension EditorOptions<BasicExtension>.extension: BasicExtensionThe extension to use when creating the editor. : defineBasicExtension function defineBasicExtension(): BasicExtensionDefine a basic extension that includes some common functionality. You can
copy this function and customize it to your needs.
It's a combination of the following extension functions:
-
{@link
defineDoc
}
-
{@link
defineText
}
-
{@link
defineParagraph
}
-
{@link
defineHeading
}
-
{@link
defineList
}
-
{@link
defineBlockquote
}
-
{@link
defineImage
}
-
{@link
defineHorizontalRule
}
-
{@link
defineHardBreak
}
-
{@link
defineTable
}
-
{@link
defineCodeBlock
}
-
{@link
defineItalic
}
-
{@link
defineBold
}
-
{@link
defineUnderline
}
-
{@link
defineStrike
}
-
{@link
defineCode
}
-
{@link
defineLink
}
-
{@link
defineBaseKeymap
}
-
{@link
defineBaseCommands
}
-
{@link
defineHistory
}
-
{@link
defineGapCursor
}
-
{@link
defineVirtualSelection
}
-
{@link
defineModClickPrevention
} () })
editor const editor: Editor<BasicExtension> .use Editor<BasicExtension>.use: (extension: Extension) => VoidFunctionRegister an extension to the editor. Return a function to unregister the
extension. (defineUpdateHandler function defineUpdateHandler(handler: UpdateHandler): PlainExtensionRegisters a event handler that is called when the editor state is updated. ((view view: EditorView ) => {
console var console: Console .log Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static) (view view: EditorView .state EditorView.state: EditorStateThe view's current [state](https://prosemirror.net/docs/ref/#state.EditorState). .doc EditorState.doc: NodeThe current document. .textContent Node.textContent: stringConcatenates all the text nodes found in this fragment and its
children. )
}))For input events, use the per-event handlers in prosekit/core, including defineKeyDownHandler, defineClickHandler, and definePasteHandler.
Components
Section titled “Components”The pre-built UI components are shipped as native custom elements via prosekit/web/*. They work in any framework, or none at all, because they’re standard Web Components. Import the component subpaths you want; each one registers its <prosekit-…> elements as a side effect.
import 'prosekit/web/menu'
import 'prosekit/web/inline-popover'