mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-13 11:44:55 +01:00
* fold Stack into Editor * switch Change objects to be tied to editors, not values * introduce controller * add the "commands" concept * convert history into commands on `value.data` * add the ability to not normalize on editor creation/setting * convert schema to a mutable constructor * add editor.command method * convert plugin handlers to receive `next` * switch commands to use the onCommand middleware * add queries support, convert schema to queries * split out browser plugin * remove noop util * fixes * fixes * start fixing tests, refactor hyperscript to be more literal * fix slate-html-serializer tests * fix schema tests with hyperscript * fix text model tests with hyperscript * fix more tests * get all tests passing * fix lint * undo decorations example update * update examples * small changes to the api to make it nicer * update docs * update commands/queries plugin logic * change normalizeNode and validateNode to be middleware * fix decoration removal * rename commands tests * add useful errors to existing APIs * update changelogs * cleanup * fixes * update docs * add editor docs
101 lines
2.1 KiB
JavaScript
101 lines
2.1 KiB
JavaScript
/** @jsx h */
|
|
|
|
import React from 'react'
|
|
import h from '../../helpers/h'
|
|
|
|
function Image(props) {
|
|
return React.createElement('img', {
|
|
className: props.isFocused ? 'focused' : '',
|
|
src: props.node.data.get('src'),
|
|
...props.attributes,
|
|
})
|
|
}
|
|
|
|
function renderNode(props) {
|
|
switch (props.node.type) {
|
|
case 'image':
|
|
return Image(props)
|
|
}
|
|
}
|
|
|
|
export const props = {
|
|
renderNode,
|
|
schema: {
|
|
blocks: {
|
|
image: {
|
|
isVoid: true,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
export const value = (
|
|
<value>
|
|
<document>
|
|
<paragraph>
|
|
<text key="a">
|
|
<anchor />
|
|
</text>
|
|
</paragraph>
|
|
<image src="https://example.com/image.png">
|
|
<text />
|
|
</image>
|
|
<paragraph>
|
|
<text key="b">
|
|
<focus />
|
|
</text>
|
|
</paragraph>
|
|
<image src="https://example.com/image2.png">
|
|
<text />
|
|
</image>
|
|
</document>
|
|
<selection isFocused={false}>
|
|
<anchor key="a" offset={0} />
|
|
<focus key="b" offset={0} />
|
|
</selection>
|
|
</value>
|
|
)
|
|
|
|
export const output = `
|
|
<div data-slate-editor="true" contenteditable="true" role="textbox">
|
|
<div style="position:relative">
|
|
<span>
|
|
<span>
|
|
<span data-slate-zero-width="n"></span>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<div data-slate-void="true">
|
|
<div data-slate-spacer="true" style="height:0;color:transparent;outline:none;position:absolute">
|
|
<span>
|
|
<span>
|
|
<span data-slate-zero-width="z"></span>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<div contenteditable="false">
|
|
<img class="" src="https://example.com/image.png">
|
|
</div>
|
|
</div>
|
|
<div style="position:relative">
|
|
<span>
|
|
<span>
|
|
<span data-slate-zero-width="n"></span>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<div data-slate-void="true">
|
|
<div data-slate-spacer="true" style="height:0;color:transparent;outline:none;position:absolute">
|
|
<span>
|
|
<span>
|
|
<span data-slate-zero-width="z"></span>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
<div contenteditable="false">
|
|
<img class="" src="https://example.com/image2.png">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`.trim()
|