1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-29 18:09:49 +02: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
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: 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 ## Current State Transforms

View File

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

View File

@@ -1,7 +1,7 @@
{ {
"name": "slate", "name": "slate",
"description": "A completely customizable framework for building rich text editors.", "description": "A completely customizable framework for building rich text editors.",
"version": "0.14.13", "version": "0.14.15",
"license": "MIT", "license": "MIT",
"repository": "git://github.com/ianstormtaylor/slate.git", "repository": "git://github.com/ianstormtaylor/slate.git",
"main": "./lib/index.js", "main": "./lib/index.js",
@@ -87,6 +87,7 @@
"lint": "eslint --ignore-pattern 'build.dev.js' --ignore-pattern 'build.prod.js' '{examples,src}/**/*.js'", "lint": "eslint --ignore-pattern 'build.dev.js' --ignore-pattern 'build.prod.js' '{examples,src}/**/*.js'",
"open": "open http://localhost:8080/dev.html", "open": "open http://localhost:8080/dev.html",
"prepublish": "npm run build", "prepublish": "npm run build",
"postpublish": "npm run gh-pages",
"release": "np", "release": "np",
"release:next": "np --tag=next", "release:next": "np --tag=next",
"start": "http-server ./examples", "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. // Make the outer wrapper relative, so the spacer can overlay it.
const style = { const style = {
position: 'relative', position: 'relative'
lineHeight: '0px'
} }
return ( return (
@@ -91,12 +90,32 @@ class Void extends React.Component {
*/ */
renderSpacer = () => { renderSpacer = () => {
const style = { 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', position: 'relative',
top: '0px', top: '0px',
left: '-9999px', left: '-9999px',
textIndent: '-9999px', textIndent: '-9999px',
} }
}
return ( return (
<span style={style}>{this.renderLeaf()}</span> <span style={style}>{this.renderLeaf()}</span>

View File

@@ -5,7 +5,7 @@ import Mark from './mark'
import Selection from './selection' import Selection from './selection'
import Transform from './transform' import Transform from './transform'
import uid from '../utils/uid' import uid from '../utils/uid'
import { Record, Set, Stack } from 'immutable' import { Record, Set, Stack, List } from 'immutable'
/** /**
* History. * History.
@@ -361,7 +361,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get marks() { 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() { 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() { 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() { 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() { 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) 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 React from 'react'
import String from '../utils/string' import String from '../utils/string'
import getWindow from 'get-window' import getWindow from 'get-window'
import { IS_MAC } from '../constants/environment'
/** /**
* Debug. * Debug.
@@ -337,6 +338,7 @@ function Plugin(options = {}) {
case 'right': return onKeyDownRight(e, data, state) case 'right': return onKeyDownRight(e, data, state)
case 'y': return onKeyDownY(e, data, state) case 'y': return onKeyDownY(e, data, state)
case 'z': return onKeyDownZ(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 }) .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. * On paste.
* *

View File

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

View File

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