1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-25 01:33:37 +01:00

Merge branch 'master' into fix-normalize-with-schema

This commit is contained in:
Ian Storm Taylor 2016-10-18 09:02:24 -07:00
commit 8150df24be
8 changed files with 74 additions and 20 deletions

View File

@ -89,7 +89,7 @@ Transform methods can either operate on the [`Document`](./document.md), the [`S
Applies all of the current transform steps, returning the newly transformed [`State`](./state.md). An `options` object is optional, containing values of:
- `snapshot: Boolean` — override the editor's built-in logic of whether to create a new snapshot in the history, that can be reverted to later.
- `save: Boolean` — override the editor's built-in logic of whether to create a new snapshot in the history, that can be reverted to later.
## Current State Transforms

View File

@ -128,7 +128,7 @@ class Images extends React.Component {
data: {}
})
.apply({
snapshot: false
save: false
})
this.onChange(normalized)

View File

@ -1,7 +1,7 @@
{
"name": "slate",
"description": "A completely customizable framework for building rich text editors.",
"version": "0.14.13",
"version": "0.14.15",
"license": "MIT",
"repository": "git://github.com/ianstormtaylor/slate.git",
"main": "./lib/index.js",
@ -87,6 +87,7 @@
"lint": "eslint --ignore-pattern 'build.dev.js' --ignore-pattern 'build.prod.js' '{examples,src}/**/*.js'",
"open": "open http://localhost:8080/dev.html",
"prepublish": "npm run build",
"postpublish": "npm run gh-pages",
"release": "np",
"release:next": "np --tag=next",
"start": "http-server ./examples",

View File

@ -67,8 +67,7 @@ class Void extends React.Component {
// Make the outer wrapper relative, so the spacer can overlay it.
const style = {
position: 'relative',
lineHeight: '0px'
position: 'relative'
}
return (
@ -91,11 +90,31 @@ class Void extends React.Component {
*/
renderSpacer = () => {
const style = {
position: 'relative',
top: '0px',
left: '-9999px',
textIndent: '-9999px',
const { node } = this.props
let style
if (node.kind == 'block') {
style = IS_FIREFOX
? {
pointerEvents: 'none',
width: '0px',
height: '0px',
lineHeight: '0px',
visibility: 'hidden'
}
: {
position: 'absolute',
top: '0px',
left: '-9999px',
textIndent: '-9999px'
}
} else {
style = {
position: 'relative',
top: '0px',
left: '-9999px',
textIndent: '-9999px',
}
}
return (

View File

@ -5,7 +5,7 @@ import Mark from './mark'
import Selection from './selection'
import Transform from './transform'
import uid from '../utils/uid'
import { Record, Set, Stack } from 'immutable'
import { Record, Set, Stack, List } from 'immutable'
/**
* History.
@ -361,7 +361,9 @@ class State extends new Record(DEFAULTS) {
*/
get marks() {
return this.selection.marks || this.document.getMarksAtRange(this.selection)
return this.selection.isUnset
? new Set()
: this.selection.marks || this.document.getMarksAtRange(this.selection)
}
/**
@ -371,7 +373,9 @@ class State extends new Record(DEFAULTS) {
*/
get blocks() {
return this.document.getBlocksAtRange(this.selection)
return this.selection.isUnset
? new List()
: this.document.getBlocksAtRange(this.selection)
}
/**
@ -381,7 +385,9 @@ class State extends new Record(DEFAULTS) {
*/
get fragment() {
return this.document.getFragmentAtRange(this.selection)
return this.selection.isUnset
? Document.create()
: this.document.getFragmentAtRange(this.selection)
}
/**
@ -391,7 +397,9 @@ class State extends new Record(DEFAULTS) {
*/
get inlines() {
return this.document.getInlinesAtRange(this.selection)
return this.selection.isUnset
? new List()
: this.document.getInlinesAtRange(this.selection)
}
/**
@ -401,7 +409,9 @@ class State extends new Record(DEFAULTS) {
*/
get texts() {
return this.document.getTextsAtRange(this.selection)
return this.selection.isUnset
? new List()
: this.document.getTextsAtRange(this.selection)
}
/**
@ -429,7 +439,7 @@ class State extends new Record(DEFAULTS) {
rule.normalize(transform, document, value)
}
return transform.apply({ snapshot: false })
return transform.apply({ save: false })
}
/**

View File

@ -6,6 +6,7 @@ import Placeholder from '../components/placeholder'
import React from 'react'
import String from '../utils/string'
import getWindow from 'get-window'
import { IS_MAC } from '../constants/environment'
/**
* Debug.
@ -337,6 +338,7 @@ function Plugin(options = {}) {
case 'right': return onKeyDownRight(e, data, state)
case 'y': return onKeyDownY(e, data, state)
case 'z': return onKeyDownZ(e, data, state)
case 'k': return onKeyDownK(e, data, state)
}
}
@ -573,6 +575,28 @@ function Plugin(options = {}) {
.apply({ save: false })
}
/**
* On `k` key down, delete untill the end of the line (mac only)
*
* @param {Event} e
* @param {Object} data
* @param {State} state
* @return {State}
*/
function onKeyDownK(e, data, state) {
if (!IS_MAC || !data.isCtrl) return
debug('onKeyDownK', { data })
const { startOffset, startBlock } = state
return state
.transform()
.deleteForward(startBlock.text.length - startOffset)
.apply()
}
/**
* On paste.
*

View File

@ -1,7 +1,7 @@
<div contenteditable="true">
<div style="position:relative;line-height:0px;">
<span style="position:relative;top:0px;left:-9999px;text-indent:-9999px;">
<div style="position:relative;">
<span style="position:absolute;top:0px;left:-9999px;text-indent:-9999px;">
<span>
<span class="slate-zero-width-space">&#x200B;</span>
</span>

View File

@ -6,7 +6,7 @@
<span class="slate-zero-width-space">&#x200B;</span>
</span>
</span>
<span style="position:relative;line-height:0px;">
<span style="position:relative;">
<span style="position:relative;top:0px;left:-9999px;text-indent:-9999px;">
<span>
<span class="slate-zero-width-space">&#x200B;</span>