1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-13 18:53:59 +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 { import { Element, Descendant, Node, Range, Text, Editor } from 'slate'
Element,
Descendant,
Node,
Range,
Text,
Editor,
createEditor as makeEditor,
} from 'slate'
import { import {
AnchorToken, AnchorToken,
FocusToken, FocusToken,
@@ -217,11 +209,11 @@ export function createText(
* Create a top-level `Editor` object. * Create a top-level `Editor` object.
*/ */
export function createEditor( export const createEditor = (makeEditor: () => Editor) => (
tagName: string, tagName: string,
attributes: { [key: string]: any }, attributes: { [key: string]: any },
children: any[] children: any[]
): Editor { ): Editor => {
const otherChildren: any[] = [] const otherChildren: any[] = []
let selectionChild: Range | undefined let selectionChild: Range | undefined

View File

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

View File

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