Skip to content

Commit

Permalink
Allow passing custom slate editor creator to slate-hyperscript create…
Browse files Browse the repository at this point in the history
…Editor()

Makes it easier to create your own testing setup
  • Loading branch information
bryanph committed Sep 28, 2021
1 parent 15f8f86 commit 845cadf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/slate-hyperscript/src/creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ export function createText(
* Create a top-level `Editor` object.
*/

export function createEditor(
export const createEditor = (makeEditor: () => Editor) => (
tagName: string,
attributes: { [key: string]: any },
children: any[]
): Editor {
): Editor => {
const otherChildren: any[] = []
let selectionChild: Range | undefined

Expand Down
4 changes: 2 additions & 2 deletions packages/slate-hyperscript/src/hyperscript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isPlainObject } from 'is-plain-object'
import { Element } from 'slate'
import { Element, createEditor as makeEditor } from 'slate'
import {
createAnchor,
createCursor,
Expand All @@ -18,7 +18,7 @@ import {
const DEFAULT_CREATORS = {
anchor: createAnchor,
cursor: createCursor,
editor: createEditor,
editor: createEditor(makeEditor),
element: createElement,
focus: createFocus,
fragment: createFragment,
Expand Down
4 changes: 4 additions & 0 deletions packages/slate-hyperscript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {
HyperscriptCreators,
HyperscriptShorthands,
} from './hyperscript'
import {
createEditor
} from './creators'

/**
* The default hyperscript factory that ships with Slate, without custom tags.
Expand All @@ -11,3 +14,4 @@ import {
const jsx = createHyperscript()

export { jsx, createHyperscript, HyperscriptCreators, HyperscriptShorthands }
export { createEditor }

0 comments on commit 845cadf

Please sign in to comment.