1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-15 19:54:02 +02:00

Reshape void component structure. (#1104)

* Reshape void component structure.
Get rid of offscreen spacer.

* Polish Embeds example `Video` component.

* Fix oversight.

* Force spacer width to be 0.

* Update tests
This commit is contained in:
AlbertHilb
2017-09-12 17:51:26 +02:00
committed by Ian Storm Taylor
parent 597d40f63a
commit 5c840c78e1
3 changed files with 25 additions and 36 deletions

View File

@@ -59,30 +59,22 @@ class Video extends React.Component {
const wrapperStyle = { const wrapperStyle = {
position: 'relative', position: 'relative',
paddingBottom: '66.66%',
paddingTop: '25px',
height: '0',
outline: isSelected ? '2px solid blue' : 'none', outline: isSelected ? '2px solid blue' : 'none',
} }
const maskStyle = { const maskStyle = {
display: isSelected ? 'none' : 'block', display: isSelected ? 'none' : 'block',
position: 'absolute', position: 'absolute',
top: '0px', top: '0',
left: '0px', left: '0',
right: '0px',
bottom: '0px',
height: '100%', height: '100%',
width: '100%',
cursor: 'cell', cursor: 'cell',
zIndex: 1, zIndex: 1,
} }
const iframeStyle = { const iframeStyle = {
position: 'absolute', display: 'block'
top: '0px',
left: '0px',
width: '100%',
height: '100%',
} }
return ( return (
@@ -92,7 +84,7 @@ class Video extends React.Component {
id="ytplayer" id="ytplayer"
type="text/html" type="text/html"
width="640" width="640"
height="390" height="476"
src={video} src={video}
frameBorder="0" frameBorder="0"
style={iframeStyle} style={iframeStyle}
@@ -110,12 +102,17 @@ class Video extends React.Component {
renderInput = () => { renderInput = () => {
const { node } = this.props const { node } = this.props
const video = node.data.get('video') const video = node.data.get('video')
const style = {
marginTop: '5px',
boxSizing: 'border-box'
}
return ( return (
<input <input
value={video} value={video}
onChange={this.onChange} onChange={this.onChange}
onClick={this.onClick} onClick={this.onClick}
style={{ marginTop: '5px' }} style={style}
/> />
) )
} }

View File

@@ -7,7 +7,6 @@ import { Mark } from 'slate'
import Leaf from './leaf' import Leaf from './leaf'
import OffsetKey from '../utils/offset-key' import OffsetKey from '../utils/offset-key'
import { IS_FIREFOX } from '../constants/environment'
/** /**
* Debug. * Debug.
@@ -141,10 +140,12 @@ class Void extends React.Component {
const { children, node } = props const { children, node } = props
let Tag, style let Tag, style
// Make the outer wrapper relative, so the spacer can overlay it.
if (node.kind === 'block') { if (node.kind === 'block') {
Tag = 'div' Tag = 'div'
style = { position: 'relative' } style = {
display: 'inline-block',
verticalAlign: 'top'
}
} else { } else {
Tag = 'span' Tag = 'span'
} }
@@ -154,14 +155,13 @@ class Void extends React.Component {
return ( return (
<Tag <Tag
data-slate-void data-slate-void
style={style}
onClick={this.onClick} onClick={this.onClick}
onDragEnter={this.onDragEnter} onDragEnter={this.onDragEnter}
onDragLeave={this.onDragLeave} onDragLeave={this.onDragLeave}
onDrop={this.onDrop} onDrop={this.onDrop}
> >
{this.renderSpacer()} {this.renderSpacer()}
<Tag contentEditable={this.state.editable}> <Tag contentEditable={this.state.editable} style={style}>
{children} {children}
</Tag> </Tag>
</Tag> </Tag>
@@ -182,20 +182,12 @@ class Void extends React.Component {
let style let style
if (node.kind == 'block') { if (node.kind == 'block') {
style = IS_FIREFOX style = {
? { display: 'inline-block',
pointerEvents: 'none', verticalAlign: 'top',
width: '0px', width: '0',
height: '0px', color: 'transparent'
lineHeight: '0px', }
visibility: 'hidden'
}
: {
position: 'absolute',
top: '0px',
left: '-9999px',
textIndent: '-9999px'
}
} else { } else {
style = { style = {
color: 'transparent' color: 'transparent'

View File

@@ -23,13 +23,13 @@ export const state = (
export const output = ` export const output = `
<div data-slate-editor="true" contenteditable="true" role="textbox"> <div data-slate-editor="true" contenteditable="true" role="textbox">
<div data-slate-void="true" style="position:relative;"> <div data-slate-void="true">
<span style="position:absolute;top:0px;left:-9999px;text-indent:-9999px;"> <span style="display:inline-block;vertical-align:top;width:0px;color:transparent;">
<span> <span>
<span data-slate-zero-width="true">&#x200A;</span> <span data-slate-zero-width="true">&#x200A;</span>
</span> </span>
</span> </span>
<div contenteditable="false"> <div contenteditable="false" style="display:inline-block;vertical-align:top;">
<img src="https://example.com/image.png"> <img src="https://example.com/image.png">
</div> </div>
</div> </div>