1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-12 10:14:02 +02:00

Allow passing custom editor creator to slate-hyperscript createEditor (#4555)

* Allow passing custom slate editor creator to slate-hyperscript createEditor()

Makes it easier to create your own testing setup

* run fix:prettier

* remove unused createEditor

* Add changeset

* fix lint and remove accidentally committed file
This commit is contained in:
Bryan Haakman
2021-10-12 02:33:52 +02:00
committed by GitHub
parent b18dd40026
commit c29eea022e
4 changed files with 32 additions and 14 deletions

View File

@@ -0,0 +1,19 @@
---
'slate-hyperscript': patch
---
createEditor is now exported from slate-hyperscript, making it easier to set up custom editor tests
For example:
```
const jsx = createHyperscript({
creators: {
editor: createEditor(aFunctionThatReturnsAnEditorObject)
},
elements: {
block: { type: 'block' },
inline: { type: 'inline' }
}
})
```

View File

@@ -1,12 +1,4 @@
import {
Element,
Descendant,
Node,
Range,
Text,
Editor,
createEditor as makeEditor,
} from 'slate'
import { Element, Descendant, Node, Range, Text, Editor } from 'slate'
import {
AnchorToken,
FocusToken,
@@ -217,11 +209,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

View File

@@ -1,5 +1,5 @@
import { isPlainObject } from 'is-plain-object'
import { Element } from 'slate'
import { Element, createEditor as makeEditor } from 'slate'
import {
createAnchor,
createCursor,
@@ -18,7 +18,7 @@ import {
const DEFAULT_CREATORS = {
anchor: createAnchor,
cursor: createCursor,
editor: createEditor,
editor: createEditor(makeEditor),
element: createElement,
focus: createFocus,
fragment: createFragment,

View File

@@ -3,6 +3,7 @@ import {
HyperscriptCreators,
HyperscriptShorthands,
} from './hyperscript'
import { createEditor } from './creators'
/**
* The default hyperscript factory that ships with Slate, without custom tags.
@@ -10,4 +11,10 @@ import {
const jsx = createHyperscript()
export { jsx, createHyperscript, HyperscriptCreators, HyperscriptShorthands }
export {
jsx,
createHyperscript,
createEditor,
HyperscriptCreators,
HyperscriptShorthands,
}