mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-03 04:02:33 +02:00
Remove deprecations (#2113)
#### Is this adding or improving a _feature_ or fixing a _bug_? Debt. #### What's the new behavior? This removes almost all existing deprecations from previous API changes, to save on filesize and reduce complexity in the codebase going forward. It also changes from using the `slate-dev-logger` to using the Facebook-inspired `slate-dev-warning` which can be compiled out of production builds with [`babel-plugin-dev-expression`](https://github.com/4Catalyzer/babel-plugin-dev-expression) to save even further on file size. The only deprecations it keeps are in the `fromJSON` methods for data model changes like `.kind` and `.leaves` which may still may not have been migrated in databases, since this is a bigger pain point. #### Have you checked that...? * [x] The new code matches the existing patterns and styles. * [x] The tests pass with `yarn test`. * [x] The linter passes with `yarn lint`. (Fix errors with `yarn prettier`.) * [x] The relevant examples still work. (Run examples with `yarn watch`.) #### Does this fix any issues or need any specific reviewers? Fixes: #1922 Fixes: #2105 Fixes: #646 Fixes: #2109 Fixes: #2107 Fixes: #2018
This commit is contained in:
@@ -11,6 +11,5 @@ Slate's codebase is monorepo managed with [Lerna](https://lernajs.io/). It consi
|
||||
| [`slate-plain-serializer`](./slate-plain-serializer) | [](./slate-plain-serializer/package.json) | [](https://unpkg.com/slate-plain-serializer/dist/slate-plain-serializer.min.js) | A plain text serializer for Slate documents. |
|
||||
| [`slate-prop-types`](./slate-prop-types) | [](./slate-prop-types/package.json) | [](https://unpkg.com/slate-prop-types/dist/slate-prop-types.min.js) | React prop types for checking Slate values. |
|
||||
| [`slate-react`](./slate-react) | [](./slate-react/package.json) | [](https://unpkg.com/slate-react/dist/slate-react.min.js) | React components for rendering Slate editors. |
|
||||
| [`slate-schema-violations`](./slate-schema-violations) | [](./slate-schema-violations/package.json) | [](https://unpkg.com/slate-schema-violations/dist/slate-schema-violations.min.js) | Constants for the built-in schema violations. |
|
||||
| [`slate-simulator`](./slate-simulator) | [](./slate-simulator/package.json) | [](https://unpkg.com/slate-simulator/dist/slate-simulator.min.js) | A simulator for testing Slate editors and plugins. |
|
||||
| [`slate-hotkeys`](./slate-hotkeys) | [](./slate-hotkeys/package.json) | [](https://unpkg.com/slate-hotkeys/dist/slate-hotkeys.min.js) | Detect common keypresses in a platform-agnostic way |
|
||||
|
@@ -1 +0,0 @@
|
||||
This package contains the logger that Slate uses to log warnings and deprecations only when in development environments.
|
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"name": "slate-dev-logger",
|
||||
"description": "INTERNAL: A simple, development-only logger for Slate.",
|
||||
"version": "0.1.43",
|
||||
"license": "MIT",
|
||||
"repository": "git://github.com/ianstormtaylor/slate.git",
|
||||
"main": "lib/slate-dev-logger.js",
|
||||
"module": "lib/slate-dev-logger.es.js",
|
||||
"umd": "dist/slate-dev-logger.js",
|
||||
"umdMin": "dist/slate-dev-logger.min.js",
|
||||
"files": [
|
||||
"dist/",
|
||||
"lib/"
|
||||
],
|
||||
"devDependencies": {
|
||||
"mocha": "^2.5.3"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -rf ./dist ./lib ./node_modules"
|
||||
}
|
||||
}
|
@@ -1,110 +0,0 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
/**
|
||||
* Is deprecate interface forbidden?
|
||||
*/
|
||||
|
||||
const FORBID_DEPRECATE =
|
||||
process && process.env && process.env.FORBID_DEPRECATIONS
|
||||
|
||||
/**
|
||||
* Is warning scenarios forbidden?
|
||||
*/
|
||||
|
||||
const FORBID_WARNING = process && process.env && process.env.FORBID_WARNINGS
|
||||
|
||||
/**
|
||||
* Is in development?
|
||||
*
|
||||
* @type {Boolean}
|
||||
*/
|
||||
|
||||
const IS_DEV =
|
||||
typeof process !== 'undefined' &&
|
||||
process.env &&
|
||||
process.env.NODE_ENV !== 'production'
|
||||
|
||||
/**
|
||||
* Has console?
|
||||
*
|
||||
* @type {Boolean}
|
||||
*/
|
||||
|
||||
const HAS_CONSOLE =
|
||||
typeof console != 'undefined' &&
|
||||
typeof console.log == 'function' &&
|
||||
typeof console.warn == 'function' &&
|
||||
typeof console.error == 'function'
|
||||
|
||||
/**
|
||||
* Log a `message` at `level`.
|
||||
*
|
||||
* @param {String} level
|
||||
* @param {String} message
|
||||
* @param {Any} ...args
|
||||
*/
|
||||
|
||||
function log(level, message, ...args) {
|
||||
if (!IS_DEV) {
|
||||
return
|
||||
}
|
||||
|
||||
if (HAS_CONSOLE) {
|
||||
console[level](message, ...args)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an error `message`.
|
||||
*
|
||||
* @param {String} message
|
||||
* @param {Any} ...args
|
||||
*/
|
||||
|
||||
function error(message, ...args) {
|
||||
if (HAS_CONSOLE) {
|
||||
console.error(message, ...args)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a warning `message` in development only.
|
||||
*
|
||||
* @param {String} message
|
||||
* @param {Any} ...args
|
||||
*/
|
||||
|
||||
function warn(message, ...args) {
|
||||
const logger = FORBID_WARNING ? forbidden : log
|
||||
logger('warn', `Warning: ${message}`, ...args)
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a deprecation warning `message`, with helpful `version` number in
|
||||
* development only.
|
||||
*
|
||||
* @param {String} version
|
||||
* @param {String} message
|
||||
* @param {Any} ...args
|
||||
*/
|
||||
|
||||
function deprecate(version, message, ...args) {
|
||||
const logger = FORBID_DEPRECATE ? forbidden : log
|
||||
logger('warn', `Deprecation (${version}): ${message}`, ...args)
|
||||
}
|
||||
|
||||
function forbidden(level, message) {
|
||||
throw new Error(message)
|
||||
}
|
||||
|
||||
/**
|
||||
* Export.
|
||||
*
|
||||
* @type {Function}
|
||||
*/
|
||||
|
||||
export default {
|
||||
deprecate,
|
||||
error,
|
||||
warn,
|
||||
}
|
1
packages/slate-dev-warning/Readme.md
Normal file
1
packages/slate-dev-warning/Readme.md
Normal file
@@ -0,0 +1 @@
|
||||
This package contains the warning logger that Slate uses to log warnings and deprecations only when in development environments.
|
21
packages/slate-dev-warning/package.json
Normal file
21
packages/slate-dev-warning/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "slate-dev-warning",
|
||||
"description": "INTERNAL: A simple, development-only warning helper for Slate.",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"repository": "git://github.com/ianstormtaylor/slate.git",
|
||||
"main": "lib/slate-dev-warning.js",
|
||||
"module": "lib/slate-dev-warning.es.js",
|
||||
"umd": "dist/slate-dev-warning.js",
|
||||
"umdMin": "dist/slate-dev-warning.min.js",
|
||||
"files": [
|
||||
"dist/",
|
||||
"lib/"
|
||||
],
|
||||
"devDependencies": {
|
||||
"mocha": "^2.5.3"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -rf ./dist ./lib ./node_modules"
|
||||
}
|
||||
}
|
19
packages/slate-dev-warning/src/index.js
Normal file
19
packages/slate-dev-warning/src/index.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* A `warning` helper, modeled after Facebook's and the `tiny-invariant` library.
|
||||
*
|
||||
* @param {Mixed} condition
|
||||
* @param {String} message
|
||||
*/
|
||||
|
||||
export default function warning(condition, message = '') {
|
||||
if (condition) return
|
||||
|
||||
const isProduction = process.env.NODE_ENV === 'production'
|
||||
const log = console.warn || console.log // eslint-disable-line no-console
|
||||
|
||||
if (isProduction) {
|
||||
log('Warning')
|
||||
} else {
|
||||
log(`Warning: ${message}`)
|
||||
}
|
||||
}
|
@@ -4,6 +4,14 @@ This document maintains a list of changes to the `slate-html-serializer` package
|
||||
|
||||
---
|
||||
|
||||
### `0.7.0` — August 22, 2018
|
||||
|
||||
###### BREAKING
|
||||
|
||||
**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version.
|
||||
|
||||
---
|
||||
|
||||
### `0.6.0` — March 22, 2018
|
||||
|
||||
###### BREAKING
|
||||
|
@@ -13,7 +13,6 @@
|
||||
"lib/"
|
||||
],
|
||||
"dependencies": {
|
||||
"slate-dev-logger": "^0.1.43",
|
||||
"type-of": "^2.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
@@ -144,7 +144,6 @@ class Html {
|
||||
const block = {
|
||||
object: 'block',
|
||||
data: {},
|
||||
isVoid: false,
|
||||
...defaultBlock,
|
||||
nodes: [node],
|
||||
}
|
||||
@@ -159,7 +158,6 @@ class Html {
|
||||
{
|
||||
object: 'block',
|
||||
data: {},
|
||||
isVoid: false,
|
||||
...defaultBlock,
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -11,7 +11,6 @@ export const config = {
|
||||
return {
|
||||
object: 'block',
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ export const config = {
|
||||
return {
|
||||
object: 'inline',
|
||||
type: 'emoji',
|
||||
isVoid: true,
|
||||
nodes: next(el.childNodes),
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ export const config = {
|
||||
return {
|
||||
object: 'inline',
|
||||
type: 'linebreak',
|
||||
isVoid: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ export const config = {
|
||||
return {
|
||||
object: 'block',
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,23 +12,14 @@ const h = createHyperscript({
|
||||
paragraph: 'paragraph',
|
||||
quote: 'quote',
|
||||
code: 'code',
|
||||
image: {
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
},
|
||||
image: 'image',
|
||||
},
|
||||
inlines: {
|
||||
link: 'link',
|
||||
hashtag: 'hashtag',
|
||||
comment: 'comment',
|
||||
emoji: {
|
||||
type: 'emoji',
|
||||
isVoid: true,
|
||||
},
|
||||
linebreak: {
|
||||
type: 'linebreak',
|
||||
isVoid: true,
|
||||
},
|
||||
emoji: 'emoji',
|
||||
linebreak: 'linebreak',
|
||||
},
|
||||
marks: {
|
||||
b: 'bold',
|
||||
|
@@ -4,6 +4,14 @@ This document maintains a list of changes to the `slate-hyperscript` package wit
|
||||
|
||||
---
|
||||
|
||||
### `0.10.0` — August 22, 2018
|
||||
|
||||
###### BREAKING
|
||||
|
||||
**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version.
|
||||
|
||||
---
|
||||
|
||||
### `0.9.0` — August 22, 2018
|
||||
|
||||
###### NEW
|
||||
|
@@ -13,9 +13,7 @@
|
||||
"lib/"
|
||||
],
|
||||
"dependencies": {
|
||||
"is-empty": "^1.0.0",
|
||||
"is-plain-object": "^2.0.4",
|
||||
"slate-dev-logger": "^0.1.43"
|
||||
"is-plain-object": "^2.0.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"slate": ">=0.37.0"
|
||||
|
@@ -7,7 +7,6 @@ import {
|
||||
Mark,
|
||||
Node,
|
||||
Point,
|
||||
Schema,
|
||||
Selection,
|
||||
Text,
|
||||
Value,
|
||||
@@ -173,7 +172,6 @@ const CREATORS = {
|
||||
|
||||
value(tagName, attributes, children) {
|
||||
const { data, normalize = true } = attributes
|
||||
const schema = Schema.create(attributes.schema || {})
|
||||
const document = children.find(Document.isDocument)
|
||||
let selection = children.find(Selection.isSelection) || Selection.create()
|
||||
let anchor
|
||||
@@ -263,7 +261,7 @@ const CREATORS = {
|
||||
}
|
||||
|
||||
let value = Value.fromJSON(
|
||||
{ data, document, selection, schema },
|
||||
{ data, document, selection, ...attributes },
|
||||
{ normalize }
|
||||
)
|
||||
|
||||
@@ -471,19 +469,19 @@ function resolveCreators(options) {
|
||||
}
|
||||
|
||||
Object.keys(blocks).map(key => {
|
||||
creators[key] = normalizeNode(key, blocks[key], 'block')
|
||||
creators[key] = normalizeNode(blocks[key], 'block')
|
||||
})
|
||||
|
||||
Object.keys(inlines).map(key => {
|
||||
creators[key] = normalizeNode(key, inlines[key], 'inline')
|
||||
creators[key] = normalizeNode(inlines[key], 'inline')
|
||||
})
|
||||
|
||||
Object.keys(marks).map(key => {
|
||||
creators[key] = normalizeMark(key, marks[key])
|
||||
creators[key] = normalizeMark(marks[key])
|
||||
})
|
||||
|
||||
Object.keys(decorations).map(key => {
|
||||
creators[key] = normalizeNode(key, decorations[key], 'decoration')
|
||||
creators[key] = normalizeNode(decorations[key], 'decoration')
|
||||
})
|
||||
|
||||
creators.value = (tagName, attributes = {}, children) => {
|
||||
@@ -495,15 +493,14 @@ function resolveCreators(options) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a node creator with `key` and `value`, of `object`.
|
||||
* Normalize a node creator of `value` and `object`.
|
||||
*
|
||||
* @param {String} key
|
||||
* @param {Function|Object|String} value
|
||||
* @param {String} object
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
function normalizeNode(key, value, object) {
|
||||
function normalizeNode(value, object) {
|
||||
if (typeof value == 'function') {
|
||||
return value
|
||||
}
|
||||
@@ -514,11 +511,11 @@ function normalizeNode(key, value, object) {
|
||||
|
||||
if (isPlainObject(value)) {
|
||||
return (tagName, attributes, children) => {
|
||||
const { key: attrKey, ...rest } = attributes
|
||||
const { key, ...rest } = attributes
|
||||
const attrs = {
|
||||
...value,
|
||||
object,
|
||||
key: attrKey,
|
||||
key,
|
||||
data: {
|
||||
...(value.data || {}),
|
||||
...rest,
|
||||
@@ -535,14 +532,13 @@ function normalizeNode(key, value, object) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a mark creator with `key` and `value`.
|
||||
* Normalize a mark creator of `value`.
|
||||
*
|
||||
* @param {String} key
|
||||
* @param {Function|Object|String} value
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
function normalizeMark(key, value) {
|
||||
function normalizeMark(value) {
|
||||
if (typeof value == 'function') {
|
||||
return value
|
||||
}
|
||||
|
@@ -33,7 +33,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -51,7 +50,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -37,7 +37,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -36,13 +36,11 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'ul',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
object: 'block',
|
||||
type: 'li',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -60,7 +58,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'li',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -37,7 +37,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -33,7 +33,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -51,7 +50,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -33,7 +33,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -51,7 +50,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -15,7 +15,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -28,7 +28,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -35,7 +35,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '3',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -53,7 +52,6 @@ export const output = {
|
||||
object: 'inline',
|
||||
key: '1',
|
||||
type: 'link',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -86,7 +84,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '7',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -104,7 +101,6 @@ export const output = {
|
||||
object: 'inline',
|
||||
key: '5',
|
||||
type: 'link',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -31,7 +31,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -51,7 +50,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '3',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -31,7 +31,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -51,7 +50,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '3',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -31,7 +31,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -51,7 +50,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '3',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -52,7 +51,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '3',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -72,7 +70,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '5',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -52,7 +51,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '3',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -72,7 +70,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '5',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -52,7 +51,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '3',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -72,7 +70,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '5',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -28,7 +28,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -28,7 +28,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -28,7 +28,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -34,7 +34,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '4',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -50,7 +49,6 @@ export const output = {
|
||||
object: 'inline',
|
||||
key: '1',
|
||||
type: 'link',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '4',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -50,7 +49,6 @@ export const output = {
|
||||
object: 'inline',
|
||||
key: '1',
|
||||
type: 'link',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '4',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -50,7 +49,6 @@ export const output = {
|
||||
object: 'inline',
|
||||
key: '1',
|
||||
type: 'link',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -5,10 +5,7 @@ import { createHyperscript } from 'slate-hyperscript'
|
||||
const h = createHyperscript({
|
||||
blocks: {
|
||||
paragraph: 'paragraph',
|
||||
image: {
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
},
|
||||
image: 'image',
|
||||
},
|
||||
inlines: {
|
||||
link: 'link',
|
||||
@@ -39,7 +36,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -71,7 +67,6 @@ export const output = {
|
||||
{
|
||||
object: 'inline',
|
||||
type: 'link',
|
||||
isVoid: false,
|
||||
data: {
|
||||
src: 'http://slatejs.org',
|
||||
},
|
||||
@@ -103,7 +98,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
data: {
|
||||
src: 'https://...',
|
||||
},
|
||||
|
@@ -40,7 +40,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -60,7 +59,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '3',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -37,7 +37,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '1',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -17,7 +17,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -20,7 +20,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -20,7 +20,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -32,7 +32,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '0',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -24,7 +24,6 @@ export const output = {
|
||||
object: 'block',
|
||||
key: '4',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -43,7 +42,6 @@ export const output = {
|
||||
key: '1',
|
||||
type: 'link',
|
||||
data: {},
|
||||
isVoid: false,
|
||||
nodes: [
|
||||
{
|
||||
object: 'text',
|
||||
|
@@ -12,7 +12,7 @@ export const input = (
|
||||
</inline>{' '}
|
||||
editor!
|
||||
</block>
|
||||
<block type="image" data={{ src: 'https://...' }} isVoid />
|
||||
<block type="image" data={{ src: 'https://...' }} />
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
@@ -26,7 +26,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
@@ -58,7 +57,6 @@ export const output = {
|
||||
{
|
||||
object: 'inline',
|
||||
type: 'link',
|
||||
isVoid: false,
|
||||
data: {
|
||||
src: 'http://slatejs.org',
|
||||
},
|
||||
@@ -90,7 +88,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
data: {
|
||||
src: 'https://...',
|
||||
},
|
||||
|
@@ -4,6 +4,14 @@ This document maintains a list of changes to the `slate-plain-serializer` packag
|
||||
|
||||
---
|
||||
|
||||
### `0.6.0` — August 22, 2018
|
||||
|
||||
###### BREAKING
|
||||
|
||||
**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version.
|
||||
|
||||
---
|
||||
|
||||
### `0.5.0` — January 4, 2018
|
||||
|
||||
###### BREAKING
|
||||
|
@@ -12,9 +12,6 @@
|
||||
"dist/",
|
||||
"lib/"
|
||||
],
|
||||
"dependencies": {
|
||||
"slate-dev-logger": "^0.1.43"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"immutable": ">=3.8.1",
|
||||
"slate": ">=0.32.0"
|
||||
|
@@ -31,7 +31,6 @@ function deserialize(string, options = {}) {
|
||||
return {
|
||||
...defaultBlock,
|
||||
object: 'block',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -11,7 +11,6 @@ export const output = {
|
||||
{
|
||||
object: 'block',
|
||||
type: 'line',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
|
@@ -12,19 +12,13 @@ const h = createHyperscript({
|
||||
paragraph: 'paragraph',
|
||||
quote: 'quote',
|
||||
code: 'code',
|
||||
image: {
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
},
|
||||
image: 'image',
|
||||
},
|
||||
inlines: {
|
||||
link: 'link',
|
||||
hashtag: 'hashtag',
|
||||
comment: 'comment',
|
||||
emoji: {
|
||||
type: 'emoji',
|
||||
isVoid: true,
|
||||
},
|
||||
emoji: 'emoji',
|
||||
},
|
||||
marks: {
|
||||
b: 'bold',
|
||||
|
@@ -12,9 +12,6 @@
|
||||
"dist/",
|
||||
"lib/"
|
||||
],
|
||||
"dependencies": {
|
||||
"slate-dev-logger": "^0.1.43"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"immutable": ">=3.8.1",
|
||||
"slate": ">=0.32.0"
|
||||
|
@@ -4,6 +4,14 @@ This document maintains a list of changes to the `slate-react` package with each
|
||||
|
||||
---
|
||||
|
||||
### `0.18.0` — August 22, 2018
|
||||
|
||||
###### BREAKING
|
||||
|
||||
**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version.
|
||||
|
||||
---
|
||||
|
||||
### `0.17.0` — August 22, 2018
|
||||
|
||||
###### NEW
|
||||
|
@@ -16,16 +16,14 @@
|
||||
"debug": "^3.1.0",
|
||||
"get-window": "^1.1.1",
|
||||
"is-window": "^1.0.2",
|
||||
"keycode": "^2.1.2",
|
||||
"lodash": "^4.1.1",
|
||||
"memoize-one": "^4.0.0",
|
||||
"prop-types": "^15.5.8",
|
||||
"react-immutable-proptypes": "^2.1.0",
|
||||
"react-portal": "^3.1.0",
|
||||
"selection-is-backward": "^1.0.0",
|
||||
"slate-base64-serializer": "^0.2.60",
|
||||
"slate-dev-environment": "^0.2.0",
|
||||
"slate-dev-logger": "^0.1.43",
|
||||
"slate-dev-warning": "^0.0.0",
|
||||
"slate-hotkeys": "^0.2.3",
|
||||
"slate-plain-serializer": "^0.5.41",
|
||||
"slate-prop-types": "^0.4.58"
|
||||
|
@@ -2,9 +2,9 @@ import Debug from 'debug'
|
||||
import React from 'react'
|
||||
import Types from 'prop-types'
|
||||
import getWindow from 'get-window'
|
||||
import { IS_FIREFOX, HAS_INPUT_EVENTS_LEVEL_2 } from 'slate-dev-environment'
|
||||
import logger from 'slate-dev-logger'
|
||||
import warning from 'slate-dev-warning'
|
||||
import throttle from 'lodash/throttle'
|
||||
import { IS_FIREFOX, HAS_INPUT_EVENTS_LEVEL_2 } from 'slate-dev-environment'
|
||||
|
||||
import EVENT_HANDLERS from '../constants/event-handlers'
|
||||
import Node from './node'
|
||||
@@ -37,7 +37,6 @@ class Content extends React.Component {
|
||||
|
||||
static propTypes = {
|
||||
autoCorrect: Types.bool.isRequired,
|
||||
children: Types.any.isRequired,
|
||||
className: Types.string,
|
||||
editor: Types.object.isRequired,
|
||||
readOnly: Types.bool.isRequired,
|
||||
@@ -165,10 +164,11 @@ class Content extends React.Component {
|
||||
const range = findDOMRange(selection, window)
|
||||
|
||||
if (!range) {
|
||||
logger.error(
|
||||
'Unable to find a native DOM range from the current selection.',
|
||||
{ selection }
|
||||
warning(
|
||||
false,
|
||||
'Unable to find a native DOM range from the current selection.'
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -426,7 +426,6 @@ class Content extends React.Component {
|
||||
data-gramm={false}
|
||||
>
|
||||
{children}
|
||||
{this.props.children}
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import Debug from 'debug'
|
||||
import Portal from 'react-portal'
|
||||
import React from 'react'
|
||||
import SlateTypes from 'slate-prop-types'
|
||||
import Types from 'prop-types'
|
||||
import logger from 'slate-dev-logger'
|
||||
import warning from 'slate-dev-warning'
|
||||
import { Schema, Stack } from 'slate'
|
||||
import memoizeOne from 'memoize-one'
|
||||
|
||||
@@ -136,11 +135,10 @@ class Editor extends React.Component {
|
||||
|
||||
// If we've resolved a few times already, and it's exactly in line with
|
||||
// the updates, then warn the user that they may be doing something wrong.
|
||||
if (resolves > 5 && resolves === updates) {
|
||||
logger.warn(
|
||||
'A Slate <Editor> component is re-resolving `props.plugins` or `props.schema` on each update, which leads to poor performance. This is often due to passing in a new `schema` or `plugins` prop with each render by declaring them inline in your render function. Do not do this!'
|
||||
)
|
||||
}
|
||||
warning(
|
||||
resolves < 5 || resolves !== updates,
|
||||
'A Slate <Editor> component is re-resolving `props.plugins` or `props.schema` on each update, which leads to poor performance. This is often due to passing in a new `schema` or `plugins` prop with each render by declaring them inline in your render function. Do not do this!'
|
||||
)
|
||||
|
||||
if (change) {
|
||||
this.onChange(change)
|
||||
@@ -155,16 +153,7 @@ class Editor extends React.Component {
|
||||
|
||||
render() {
|
||||
debug('render', this)
|
||||
|
||||
const children = this.stack
|
||||
.map('renderPortal', this.value, this)
|
||||
.map((child, i) => (
|
||||
<Portal key={i} isOpened>
|
||||
{child}
|
||||
</Portal>
|
||||
))
|
||||
|
||||
const props = { ...this.props, children }
|
||||
const props = { ...this.props }
|
||||
const tree = this.stack.render('renderEditor', props, this)
|
||||
return tree
|
||||
}
|
||||
@@ -231,7 +220,8 @@ class Editor extends React.Component {
|
||||
|
||||
change = (...args) => {
|
||||
if (this.tmp.isChanging) {
|
||||
logger.warn(
|
||||
warning(
|
||||
false,
|
||||
"The `editor.change` method was called from within an existing `editor.change` callback. This is not allowed, and often due to calling `editor.change` directly from a plugin's event handler which is unnecessary."
|
||||
)
|
||||
|
||||
|
@@ -143,13 +143,13 @@ class Leaf extends React.Component {
|
||||
text === '' &&
|
||||
parent.object === 'block' &&
|
||||
parent.text === '' &&
|
||||
parent.nodes.size === 1
|
||||
parent.nodes.last() === node
|
||||
) {
|
||||
return <span data-slate-zero-width="n">{'\u200B'}</span>
|
||||
}
|
||||
|
||||
// COMPAT: If the text is empty, it's because it's on the edge of an inline
|
||||
// void node, so we render a zero-width space so that the selection can be
|
||||
// node, so we render a zero-width space so that the selection can be
|
||||
// inserted next to it still.
|
||||
if (text === '') {
|
||||
return <span data-slate-zero-width="z">{'\u200B'}</span>
|
||||
|
@@ -2,7 +2,7 @@ import Debug from 'debug'
|
||||
import ImmutableTypes from 'react-immutable-proptypes'
|
||||
import React from 'react'
|
||||
import SlateTypes from 'slate-prop-types'
|
||||
import logger from 'slate-dev-logger'
|
||||
import warning from 'slate-dev-warning'
|
||||
import Types from 'prop-types'
|
||||
|
||||
import Void from './void'
|
||||
@@ -81,11 +81,10 @@ class Node extends React.Component {
|
||||
return true
|
||||
}
|
||||
|
||||
if (shouldUpdate === false) {
|
||||
logger.warn(
|
||||
"Returning false in `shouldNodeComponentUpdate` does not disable Slate's internal `shouldComponentUpdate` logic. If you want to prevent updates, use React's `shouldComponentUpdate` instead."
|
||||
)
|
||||
}
|
||||
warning(
|
||||
shouldUpdate !== false,
|
||||
"Returning false in `shouldNodeComponentUpdate` does not disable Slate's internal `shouldComponentUpdate` logic. If you want to prevent updates, use React's `shouldComponentUpdate` instead."
|
||||
)
|
||||
}
|
||||
|
||||
// If the `readOnly` status has changed, re-render in case there is any
|
||||
|
@@ -64,7 +64,7 @@ function AfterPlugin() {
|
||||
event.preventDefault()
|
||||
|
||||
const { value } = change
|
||||
const { selection } = value
|
||||
const { document, selection, schema } = value
|
||||
const range = findRange(targetRange, value)
|
||||
|
||||
switch (event.inputType) {
|
||||
@@ -101,7 +101,12 @@ function AfterPlugin() {
|
||||
|
||||
case 'insertLineBreak':
|
||||
case 'insertParagraph': {
|
||||
if (change.value.isInVoid) {
|
||||
const hasVoidParent = document.hasVoidParent(
|
||||
selection.start.path,
|
||||
schema
|
||||
)
|
||||
|
||||
if (hasVoidParent) {
|
||||
change.moveToStartOfNextText()
|
||||
} else {
|
||||
change.splitBlockAtRange(range)
|
||||
@@ -450,13 +455,14 @@ function AfterPlugin() {
|
||||
debug('onKeyDown', { event })
|
||||
|
||||
const { value } = change
|
||||
const { schema } = value
|
||||
const { document, selection, schema } = value
|
||||
const hasVoidParent = document.hasVoidParent(selection.start.path, schema)
|
||||
|
||||
// COMPAT: In iOS, some of these hotkeys are handled in the
|
||||
// `onNativeBeforeInput` handler of the `<Content>` component in order to
|
||||
// preserve native autocorrect behavior, so they shouldn't be handled here.
|
||||
if (Hotkeys.isSplitBlock(event) && !IS_IOS) {
|
||||
return value.isInVoid
|
||||
return hasVoidParent
|
||||
? change.moveToStartOfNextText()
|
||||
: change.splitBlock()
|
||||
}
|
||||
@@ -520,44 +526,44 @@ function AfterPlugin() {
|
||||
// an inline is selected, we need to handle these hotkeys manually because
|
||||
// browsers won't know what to do.
|
||||
if (Hotkeys.isMoveBackward(event)) {
|
||||
const { document, isInVoid, previousText, startText } = value
|
||||
const { previousText, startText } = value
|
||||
const isPreviousInVoid =
|
||||
previousText && document.hasVoidParent(previousText.key, schema)
|
||||
|
||||
if (isInVoid || isPreviousInVoid || startText.text == '') {
|
||||
if (hasVoidParent || isPreviousInVoid || startText.text == '') {
|
||||
event.preventDefault()
|
||||
return change.moveBackward()
|
||||
}
|
||||
}
|
||||
|
||||
if (Hotkeys.isMoveForward(event)) {
|
||||
const { document, isInVoid, nextText, startText } = value
|
||||
const { nextText, startText } = value
|
||||
const isNextInVoid =
|
||||
nextText && document.hasVoidParent(nextText.key, schema)
|
||||
|
||||
if (isInVoid || isNextInVoid || startText.text == '') {
|
||||
if (hasVoidParent || isNextInVoid || startText.text == '') {
|
||||
event.preventDefault()
|
||||
return change.moveForward()
|
||||
}
|
||||
}
|
||||
|
||||
if (Hotkeys.isExtendBackward(event)) {
|
||||
const { document, isInVoid, previousText, startText } = value
|
||||
const { previousText, startText } = value
|
||||
const isPreviousInVoid =
|
||||
previousText && document.hasVoidParent(previousText.key, schema)
|
||||
|
||||
if (isInVoid || isPreviousInVoid || startText.text == '') {
|
||||
if (hasVoidParent || isPreviousInVoid || startText.text == '') {
|
||||
event.preventDefault()
|
||||
return change.moveFocusBackward()
|
||||
}
|
||||
}
|
||||
|
||||
if (Hotkeys.isExtendForward(event)) {
|
||||
const { document, isInVoid, nextText, startText } = value
|
||||
const { nextText, startText } = value
|
||||
const isNextInVoid =
|
||||
nextText && document.hasVoidParent(nextText.key, schema)
|
||||
|
||||
if (isInVoid || isNextInVoid || startText.text == '') {
|
||||
if (hasVoidParent || isNextInVoid || startText.text == '') {
|
||||
event.preventDefault()
|
||||
return change.moveFocusForward()
|
||||
}
|
||||
@@ -686,13 +692,11 @@ function AfterPlugin() {
|
||||
|
||||
function renderEditor(props, editor) {
|
||||
const { handlers } = editor
|
||||
|
||||
return (
|
||||
<Content
|
||||
{...handlers}
|
||||
autoCorrect={props.autoCorrect}
|
||||
className={props.className}
|
||||
children={props.children}
|
||||
editor={editor}
|
||||
readOnly={props.readOnly}
|
||||
role={props.role}
|
||||
|
@@ -12,19 +12,13 @@ const h = createHyperscript({
|
||||
paragraph: 'paragraph',
|
||||
quote: 'quote',
|
||||
code: 'code',
|
||||
image: {
|
||||
type: 'image',
|
||||
isVoid: true,
|
||||
},
|
||||
image: 'image',
|
||||
},
|
||||
inlines: {
|
||||
link: 'link',
|
||||
hashtag: 'hashtag',
|
||||
comment: 'comment',
|
||||
emoji: {
|
||||
type: 'emoji',
|
||||
isVoid: true,
|
||||
},
|
||||
emoji: 'emoji',
|
||||
},
|
||||
marks: {
|
||||
b: 'bold',
|
||||
|
16
packages/slate-react/test/helpers/schema.js
Normal file
16
packages/slate-react/test/helpers/schema.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Schema } from 'slate'
|
||||
|
||||
const schema = Schema.create({
|
||||
blocks: {
|
||||
image: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
inlines: {
|
||||
emoji: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export default schema
|
@@ -20,6 +20,13 @@ function renderNode(props) {
|
||||
|
||||
export const props = {
|
||||
renderNode,
|
||||
schema: {
|
||||
blocks: {
|
||||
image: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const value = (
|
@@ -20,6 +20,13 @@ function renderNode(props) {
|
||||
|
||||
export const props = {
|
||||
renderNode,
|
||||
schema: {
|
||||
blocks: {
|
||||
image: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const value = (
|
@@ -20,6 +20,13 @@ function renderNode(props) {
|
||||
|
||||
export const props = {
|
||||
renderNode,
|
||||
schema: {
|
||||
blocks: {
|
||||
image: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const value = (
|
@@ -19,6 +19,13 @@ function renderNode(props) {
|
||||
|
||||
export const props = {
|
||||
renderNode,
|
||||
schema: {
|
||||
blocks: {
|
||||
image: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const value = (
|
||||
|
@@ -16,6 +16,13 @@ function renderNode(props) {
|
||||
|
||||
export const props = {
|
||||
renderNode,
|
||||
schema: {
|
||||
inlines: {
|
||||
emoji: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const value = (
|
||||
@@ -50,7 +57,7 @@ export const output = `
|
||||
</span>
|
||||
<span>
|
||||
<span>
|
||||
<span data-slate-zero-width="z">​</span>
|
||||
<span data-slate-zero-width="n">​</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
@@ -1,27 +0,0 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../helpers/h'
|
||||
|
||||
export const props = {}
|
||||
|
||||
export const value = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<link />
|
||||
</paragraph>
|
||||
</document>
|
||||
</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">\u200B</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
`.trim()
|
@@ -20,6 +20,13 @@ function renderNode(props) {
|
||||
export const props = {
|
||||
readOnly: true,
|
||||
renderNode,
|
||||
schema: {
|
||||
blocks: {
|
||||
image: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const value = (
|
||||
|
@@ -17,6 +17,13 @@ function renderNode(props) {
|
||||
export const props = {
|
||||
readOnly: true,
|
||||
renderNode,
|
||||
schema: {
|
||||
inlines: {
|
||||
emoji: {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const value = (
|
||||
@@ -44,7 +51,7 @@ export const output = `
|
||||
</span>
|
||||
<span>
|
||||
<span>
|
||||
<span data-slate-zero-width="z">​</span>
|
||||
<span data-slate-zero-width="n">​</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
@@ -1,9 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
This document maintains a list of changes to the `slate-schema-violations` package with each new version. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and smaller changes won't be accounted for since the library is moving quickly.
|
||||
|
||||
---
|
||||
|
||||
### `0.1.0` — January 26, 2018
|
||||
|
||||
:tada:
|
@@ -1 +0,0 @@
|
||||
This package contains a set of constants for the built-in violations in a Slate schema.
|
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"name": "slate-schema-violations",
|
||||
"description": "A set of constants for the built-in violations in a Slate schema.",
|
||||
"version": "0.1.39",
|
||||
"license": "MIT",
|
||||
"repository": "git://github.com/ianstormtaylor/slate.git",
|
||||
"main": "lib/slate-schema-violations.js",
|
||||
"module": "lib/slate-schema-violations.es.js",
|
||||
"umd": "dist/slate-schema-violations.js",
|
||||
"umdMin": "dist/slate-schema-violations.min.js",
|
||||
"files": [
|
||||
"dist/",
|
||||
"lib/"
|
||||
],
|
||||
"devDependencies": {
|
||||
"mocha": "^2.5.3",
|
||||
"slate": "^0.39.3"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -rf ./dist ./lib ./node_modules"
|
||||
},
|
||||
"keywords": [
|
||||
"constants",
|
||||
"schema",
|
||||
"slate",
|
||||
"violation"
|
||||
]
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Schema violations.
|
||||
*
|
||||
* @type {String}
|
||||
*/
|
||||
|
||||
export const CHILD_OBJECT_INVALID = 'child_object_invalid'
|
||||
export const CHILD_REQUIRED = 'child_required'
|
||||
export const CHILD_TYPE_INVALID = 'child_type_invalid'
|
||||
export const CHILD_UNKNOWN = 'child_unknown'
|
||||
export const FIRST_CHILD_OBJECT_INVALID = 'first_child_object_invalid'
|
||||
export const FIRST_CHILD_TYPE_INVALID = 'first_child_type_invalid'
|
||||
export const LAST_CHILD_OBJECT_INVALID = 'last_child_object_invalid'
|
||||
export const LAST_CHILD_TYPE_INVALID = 'last_child_type_invalid'
|
||||
export const NEXT_SIBLING_OBJECT_INVALID = 'next_sibling_object_invalid'
|
||||
export const NEXT_SIBLING_TYPE_INVALID = 'next_sibling_type_invalid'
|
||||
export const NODE_DATA_INVALID = 'node_data_invalid'
|
||||
export const NODE_IS_VOID_INVALID = 'node_is_void_invalid'
|
||||
export const NODE_MARK_INVALID = 'node_mark_invalid'
|
||||
export const NODE_OBJECT_INVALID = 'node_object_invalid'
|
||||
export const NODE_TEXT_INVALID = 'node_text_invalid'
|
||||
export const NODE_TYPE_INVALID = 'node_type_invalid'
|
||||
export const PARENT_OBJECT_INVALID = 'parent_object_invalid'
|
||||
export const PARENT_TYPE_INVALID = 'parent_type_invalid'
|
||||
export const PREVIOUS_SIBLING_OBJECT_INVALID = 'previous_sibling_object_invalid'
|
||||
export const PREVIOUS_SIBLING_TYPE_INVALID = 'previous_sibling_type_invalid'
|
@@ -4,6 +4,14 @@ A list of changes to the `slate` package with each new version. Until `1.0.0` is
|
||||
|
||||
---
|
||||
|
||||
### `0.40.0` — August 22, 2018
|
||||
|
||||
###### BREAKING
|
||||
|
||||
**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version.
|
||||
|
||||
---
|
||||
|
||||
### `0.39.0` — August 22, 2018
|
||||
|
||||
###### NEW
|
||||
|
@@ -16,11 +16,9 @@
|
||||
"debug": "^3.1.0",
|
||||
"direction": "^0.1.5",
|
||||
"esrever": "^0.2.0",
|
||||
"is-empty": "^1.0.0",
|
||||
"is-plain-object": "^2.0.4",
|
||||
"lodash": "^4.17.4",
|
||||
"slate-dev-logger": "^0.1.43",
|
||||
"slate-schema-violations": "^0.1.39",
|
||||
"slate-dev-warning": "^0.0.0",
|
||||
"type-of": "^2.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
@@ -1,4 +1,3 @@
|
||||
import logger from 'slate-dev-logger'
|
||||
import Block from '../models/block'
|
||||
import Inline from '../models/inline'
|
||||
import Mark from '../models/mark'
|
||||
@@ -49,24 +48,6 @@ PROXY_TRANSFORMS.forEach(method => {
|
||||
}
|
||||
})
|
||||
|
||||
Changes.setBlock = (...args) => {
|
||||
logger.deprecate(
|
||||
'slate@0.33.0',
|
||||
'The `setBlock` method of Slate changes has been renamed to `setBlocks`.'
|
||||
)
|
||||
|
||||
Changes.setBlocks(...args)
|
||||
}
|
||||
|
||||
Changes.setInline = (...args) => {
|
||||
logger.deprecate(
|
||||
'slate@0.33.0',
|
||||
'The `setInline` method of Slate changes has been renamed to `setInlines`.'
|
||||
)
|
||||
|
||||
Changes.setInlines(...args)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a `mark` to the characters in the current selection.
|
||||
*
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import { List } from 'immutable'
|
||||
import logger from 'slate-dev-logger'
|
||||
import Block from '../models/block'
|
||||
import Inline from '../models/inline'
|
||||
import Mark from '../models/mark'
|
||||
@@ -965,15 +964,6 @@ Changes.setBlocksAtRange = (change, range, properties, options = {}) => {
|
||||
})
|
||||
}
|
||||
|
||||
Changes.setBlockAtRange = (...args) => {
|
||||
logger.deprecate(
|
||||
'slate@0.33.0',
|
||||
'The `setBlockAtRange` method of Slate changes has been renamed to `setBlocksAtRange`.'
|
||||
)
|
||||
|
||||
Changes.setBlocksAtRange(...args)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the `properties` of inline nodes in a `range`.
|
||||
*
|
||||
@@ -995,15 +985,6 @@ Changes.setInlinesAtRange = (change, range, properties, options = {}) => {
|
||||
})
|
||||
}
|
||||
|
||||
Changes.setInlineAtRange = (...args) => {
|
||||
logger.deprecate(
|
||||
'slate@0.33.0',
|
||||
'The `setInlineAtRange` method of Slate changes has been renamed to `setInlinesAtRange`.'
|
||||
)
|
||||
|
||||
Changes.setInlinesAtRange(...args)
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the block nodes at a `range`, to optional `height`.
|
||||
*
|
||||
@@ -1016,10 +997,9 @@ Changes.setInlineAtRange = (...args) => {
|
||||
|
||||
Changes.splitBlockAtRange = (change, range, height = 1, options = {}) => {
|
||||
const normalize = change.getFlag('normalize', options)
|
||||
|
||||
const { start, end } = range
|
||||
const { value } = change
|
||||
const { document } = value
|
||||
let { value } = change
|
||||
let { document } = value
|
||||
let node = document.assertDescendant(start.key)
|
||||
let parent = document.getClosestBlock(node.key)
|
||||
let h = 0
|
||||
@@ -1034,15 +1014,20 @@ Changes.splitBlockAtRange = (change, range, height = 1, options = {}) => {
|
||||
normalize: normalize && range.isCollapsed,
|
||||
})
|
||||
|
||||
value = change.value
|
||||
document = value.document
|
||||
|
||||
if (range.isExpanded) {
|
||||
if (range.isBackward) range = range.flip()
|
||||
const nextBlock = change.value.document.getNextBlock(node.key)
|
||||
const nextBlock = document.getNextBlock(node.key)
|
||||
range = range.moveAnchorToStartOfNode(nextBlock)
|
||||
range = range.setFocus(range.focus.setPath(null))
|
||||
|
||||
if (start.key === end.key) {
|
||||
range = range.moveFocusTo(range.anchor.key, end.offset - start.offset)
|
||||
}
|
||||
|
||||
range = document.resolveRange(range)
|
||||
change.deleteAtRange(range, { normalize })
|
||||
}
|
||||
}
|
||||
@@ -1130,7 +1115,7 @@ Changes.unwrapBlockAtRange = (change, range, properties, options = {}) => {
|
||||
|
||||
const normalize = change.getFlag('normalize', options)
|
||||
const { value } = change
|
||||
let { document, schema } = value
|
||||
let { document } = value
|
||||
const blocks = document.getBlocksAtRange(range)
|
||||
const wrappers = blocks
|
||||
.map(block => {
|
||||
@@ -1138,11 +1123,6 @@ Changes.unwrapBlockAtRange = (change, range, properties, options = {}) => {
|
||||
if (parent.object != 'block') return false
|
||||
if (properties.type != null && parent.type != properties.type)
|
||||
return false
|
||||
if (
|
||||
properties.isVoid != null &&
|
||||
schema.isVoid(parent) != properties.isVoid
|
||||
)
|
||||
return false
|
||||
if (properties.data != null && !parent.data.isSuperset(properties.data))
|
||||
return false
|
||||
return true
|
||||
@@ -1232,7 +1212,7 @@ Changes.unwrapInlineAtRange = (change, range, properties, options = {}) => {
|
||||
|
||||
const normalize = change.getFlag('normalize', options)
|
||||
const { value } = change
|
||||
const { document, schema } = value
|
||||
const { document } = value
|
||||
const texts = document.getTextsAtRange(range)
|
||||
const inlines = texts
|
||||
.map(text => {
|
||||
@@ -1240,11 +1220,6 @@ Changes.unwrapInlineAtRange = (change, range, properties, options = {}) => {
|
||||
if (parent.object != 'inline') return false
|
||||
if (properties.type != null && parent.type != properties.type)
|
||||
return false
|
||||
if (
|
||||
properties.isVoid != null &&
|
||||
schema.isVoid(parent) != properties.isVoid
|
||||
)
|
||||
return false
|
||||
if (properties.data != null && !parent.data.isSuperset(properties.data))
|
||||
return false
|
||||
return true
|
||||
@@ -1263,6 +1238,8 @@ Changes.unwrapInlineAtRange = (change, range, properties, options = {}) => {
|
||||
normalize: false,
|
||||
})
|
||||
})
|
||||
|
||||
change.removeNodeByKey(inline.key, { normalize: false })
|
||||
})
|
||||
|
||||
// TODO: optmize to only normalize the right block
|
||||
|
@@ -1,6 +1,4 @@
|
||||
import { is } from 'immutable'
|
||||
import isEmpty from 'is-empty'
|
||||
import logger from 'slate-dev-logger'
|
||||
import pick from 'lodash/pick'
|
||||
|
||||
import Selection from '../models/selection'
|
||||
@@ -576,7 +574,7 @@ Changes.select = (change, properties, options = {}) => {
|
||||
}
|
||||
|
||||
// If there are no new properties to set, abort to avoid extra operations.
|
||||
if (isEmpty(props)) {
|
||||
if (Object.keys(props).lengtgh === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -660,10 +658,10 @@ function pointBackward(change, point, n = 1) {
|
||||
const { value } = change
|
||||
const { document, selection, schema } = value
|
||||
const p = selection[point]
|
||||
const isInVoid = document.hasVoidParent(p.path, schema)
|
||||
const hasVoidParent = document.hasVoidParent(p.path, schema)
|
||||
|
||||
// what is this?
|
||||
if (!isInVoid && p.offset - n >= 0) {
|
||||
if (!hasVoidParent && p.offset - n >= 0) {
|
||||
const range = selection[`move${Point}Backward`](n)
|
||||
change.select(range)
|
||||
return
|
||||
@@ -679,7 +677,7 @@ function pointBackward(change, point, n = 1) {
|
||||
change[`move${Point}ToEndOfNode`](previous)
|
||||
|
||||
// when is this called?
|
||||
if (!isInVoid && !isPreviousInVoid && isInBlock) {
|
||||
if (!hasVoidParent && !isPreviousInVoid && isInBlock) {
|
||||
const range = change.value.selection[`move${Point}Backward`](n)
|
||||
change.select(range)
|
||||
}
|
||||
@@ -694,10 +692,10 @@ function pointForward(change, point, n = 1) {
|
||||
const { document, selection, schema } = value
|
||||
const p = selection[point]
|
||||
const text = document.getNode(p.path)
|
||||
const isInVoid = document.hasVoidParent(p.path, schema)
|
||||
const hasVoidParent = document.hasVoidParent(p.path, schema)
|
||||
|
||||
// what is this?
|
||||
if (!isInVoid && p.offset + n <= text.text.length) {
|
||||
if (!hasVoidParent && p.offset + n <= text.text.length) {
|
||||
const range = selection[`move${Point}Forward`](n)
|
||||
change.select(range)
|
||||
return
|
||||
@@ -712,112 +710,10 @@ function pointForward(change, point, n = 1) {
|
||||
change[`move${Point}ToStartOfNode`](next)
|
||||
|
||||
// when is this called?
|
||||
if (!isInVoid && !isNextInVoid && isInBlock) {
|
||||
if (!hasVoidParent && !isNextInVoid && isInBlock) {
|
||||
const range = change.value.selection[`move${Point}Forward`](n)
|
||||
change.select(range)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated.
|
||||
*/
|
||||
|
||||
Changes.moveOffsetsTo = (change, start, end = start) => {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Change.moveOffsetsTo` method is deprecated, please use `Change.moveAnchorTo` and `Change.moveFocusTo` instead.'
|
||||
)
|
||||
|
||||
change.moveAnchorTo(start).moveFocusTo(end)
|
||||
}
|
||||
|
||||
const DEPRECATEDS = [
|
||||
['collapseCharBackward', 'moveBackward'],
|
||||
['collapseCharForward', 'moveForward'],
|
||||
['collapseLineBackward', 'moveLineBackward'],
|
||||
['collapseLineForward', 'moveLineForward'],
|
||||
['collapseTo', 'moveTo'],
|
||||
['collapseToAnchor', 'moveToAnchor'],
|
||||
['collapseToEnd', 'moveToEnd'],
|
||||
['collapseToEndOf', 'moveToEndOfNode'],
|
||||
['collapseToEndOfBlock', 'moveToEndOfBlock'],
|
||||
['collapseToEndOfNextBlock', 'moveToEndOfNextBlock'],
|
||||
['collapseToEndOfNextInline', 'moveToEndOfNextInline'],
|
||||
['collapseToEndOfNextText', 'moveToEndOfNextText'],
|
||||
['collapseToEndOfPreviousBlock', 'moveToEndOfPreviousBlock'],
|
||||
['collapseToEndOfPreviousInline', 'moveToEndOfPreviousInline'],
|
||||
['collapseToEndOfPreviousText', 'moveToEndOfPreviousText'],
|
||||
['collapseToFocus', 'moveToFocus'],
|
||||
['collapseToStart', 'moveToStart'],
|
||||
['collapseToStartOf', 'moveToStartOfNode'],
|
||||
['collapseToStartOfBlock', 'moveToStartOfBlock'],
|
||||
['collapseToStartOfNextBlock', 'moveToStartOfNextBlock'],
|
||||
['collapseToStartOfNextInline', 'moveToStartOfNextInline'],
|
||||
['collapseToStartOfNextText', 'moveToStartOfNextText'],
|
||||
['collapseToStartOfPreviousBlock', 'moveToStartOfPreviousBlock'],
|
||||
['collapseToStartOfPreviousInline', 'moveToStartOfPreviousInline'],
|
||||
['collapseToStartOfPreviousText', 'moveToStartOfPreviousText'],
|
||||
['extend', 'moveFocusForward'],
|
||||
['extendCharBackward', 'moveFocusBackward'],
|
||||
['extendCharForward', 'moveFocusForward'],
|
||||
['extendLineBackward', 'moveFocusToStartOfBlock'],
|
||||
['extendLineForward', 'moveFocusToEndOfBlock'],
|
||||
['extendTo', 'moveFocusTo'],
|
||||
['extendToEndOf', 'moveFocusToEndOfNode'],
|
||||
['extendToEndOfBlock', 'moveFocusToEndOfBlock'],
|
||||
['extendToEndOfBlock', 'moveFocusToEndOfBlock'],
|
||||
['extendToEndOfNextBlock', 'moveFocusToEndOfNextBlock'],
|
||||
['extendToEndOfNextInline', 'moveFocusToEndOfNextInline'],
|
||||
['extendToEndOfNextText', 'moveFocusToEndOfNextText'],
|
||||
['extendToEndOfPreviousBlock', 'moveFocusToEndOfPreviousBlock'],
|
||||
['extendToEndOfPreviousInline', 'moveFocusToEndOfPreviousInline'],
|
||||
['extendToEndOfPreviousText', 'moveFocusToEndOfPreviousText'],
|
||||
['extendToStartOf', 'moveFocusToStartOfNode'],
|
||||
['extendToStartOfBlock', 'moveFocusToStartOfBlock'],
|
||||
['extendToStartOfNextBlock', 'moveFocusToStartOfNextBlock'],
|
||||
['extendToStartOfNextInline', 'moveFocusToStartOfNextInline'],
|
||||
['extendToStartOfNextText', 'moveFocusToStartOfNextText'],
|
||||
['extendToStartOfPreviousBlock', 'moveFocusToStartOfPreviousBlock'],
|
||||
['extendToStartOfPreviousInline', 'moveFocusToStartOfPreviousInline'],
|
||||
['extendToStartOfPreviousText', 'moveFocusToStartOfPreviousText'],
|
||||
['move', 'moveForward'],
|
||||
['moveAnchor', 'moveAnchorForward'],
|
||||
['moveAnchorCharBackward', 'moveAnchorBackward'],
|
||||
['moveAnchorCharForward', 'moveAnchorForward'],
|
||||
['moveAnchorOffsetTo', 'moveAnchorTo'],
|
||||
['moveAnchorToEndOf', 'moveAnchorToEndOfNode'],
|
||||
['moveAnchorToStartOf', 'moveAnchorToStartOfNode'],
|
||||
['moveCharBackward', 'moveBackward'],
|
||||
['moveCharForward', 'moveForward'],
|
||||
['moveEnd', 'moveEndForward'],
|
||||
['moveEndCharBackward', 'moveEndBackward'],
|
||||
['moveEndCharForward', 'moveEndForward'],
|
||||
['moveEndOffsetTo', 'moveEndTo'],
|
||||
['moveFocus', 'moveFocusForward'],
|
||||
['moveFocusCharBackward', 'moveFocusBackward'],
|
||||
['moveFocusCharForward', 'moveFocusForward'],
|
||||
['moveFocusOffsetTo', 'moveFocusTo'],
|
||||
['moveFocusToEndOf', 'moveFocusToEndOfNode'],
|
||||
['moveFocusToStartOf', 'moveFocusToStartOfNode'],
|
||||
['moveStart', 'moveStartForward'],
|
||||
['moveStartCharBackward', 'moveStartBackward'],
|
||||
['moveStartCharForward', 'moveStartForward'],
|
||||
['moveStartOffsetTo', 'moveStartTo'],
|
||||
['moveToEndOf', 'moveToEndOfNode'],
|
||||
['moveToRangeOf', 'moveToRangeOfNode'],
|
||||
['moveToStartOf', 'moveToStartOfNode'],
|
||||
['selectAll', 'moveToRangeOfDocument'],
|
||||
]
|
||||
|
||||
DEPRECATEDS.forEach(([deprecated, method]) => {
|
||||
Changes[deprecated] = function(change, ...args) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
`The \`Change.${deprecated}\` method is deprecated, please use \`Change.${method}\` instead.`
|
||||
)
|
||||
|
||||
change[method](...args)
|
||||
}
|
||||
})
|
||||
|
||||
export default Changes
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import './interfaces/common'
|
||||
import './interfaces/element'
|
||||
import './interfaces/node'
|
||||
import './interfaces/range'
|
||||
|
||||
import Block from './models/block'
|
||||
import Change from './models/change'
|
||||
import Changes from './changes'
|
||||
@@ -24,7 +26,6 @@ import Stack from './models/stack'
|
||||
import Text from './models/text'
|
||||
import TextUtils from './utils/text-utils'
|
||||
import Value from './models/value'
|
||||
import { resetKeyGenerator, setKeyGenerator } from './utils/generate-key'
|
||||
import { resetMemoization, useMemoization } from './utils/memoize'
|
||||
|
||||
/**
|
||||
@@ -51,11 +52,9 @@ export {
|
||||
PathUtils,
|
||||
Point,
|
||||
Range,
|
||||
resetKeyGenerator,
|
||||
resetMemoization,
|
||||
Schema,
|
||||
Selection,
|
||||
setKeyGenerator,
|
||||
Stack,
|
||||
Text,
|
||||
TextUtils,
|
||||
@@ -80,11 +79,9 @@ export default {
|
||||
PathUtils,
|
||||
Point,
|
||||
Range,
|
||||
resetKeyGenerator,
|
||||
resetMemoization,
|
||||
Schema,
|
||||
Selection,
|
||||
setKeyGenerator,
|
||||
Stack,
|
||||
Text,
|
||||
TextUtils,
|
||||
|
@@ -1,5 +1,3 @@
|
||||
import logger from 'slate-dev-logger'
|
||||
|
||||
import mixin from '../utils/mixin'
|
||||
import Block from '../models/block'
|
||||
import Change from '../models/change'
|
||||
@@ -41,19 +39,6 @@ class CommonInterface {
|
||||
toJS(...args) {
|
||||
return this.toJSON(...args)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated.
|
||||
*/
|
||||
|
||||
get kind() {
|
||||
logger.deprecate(
|
||||
'slate@0.32.0',
|
||||
'The `kind` property of Slate objects has been renamed to `object`.'
|
||||
)
|
||||
|
||||
return this.object
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
1826
packages/slate/src/interfaces/element.js
Normal file
1826
packages/slate/src/interfaces/element.js
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,3 @@
|
||||
import logger from 'slate-dev-logger'
|
||||
|
||||
import mixin from '../utils/mixin'
|
||||
import Decoration from '../models/decoration'
|
||||
import PathUtils from '../utils/path-utils'
|
||||
@@ -646,573 +644,8 @@ class RangeInterface {
|
||||
const range = this.updatePoints(p => p.unset())
|
||||
return range
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated.
|
||||
*/
|
||||
|
||||
get anchorKey() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.anchorKey` property has been deprecated, use `range.anchor.key` instead.'
|
||||
)
|
||||
|
||||
return this.anchor.key
|
||||
}
|
||||
|
||||
get anchorOffset() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.anchorOffset` property has been deprecated, use `range.anchor.offset` instead.'
|
||||
)
|
||||
|
||||
return this.anchor.offset
|
||||
}
|
||||
|
||||
get anchorPath() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.anchorPath` property has been deprecated, use `range.anchor.path` instead.'
|
||||
)
|
||||
|
||||
return this.anchor.path
|
||||
}
|
||||
|
||||
get focusKey() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.focusKey` property has been deprecated, use `range.focus.key` instead.'
|
||||
)
|
||||
|
||||
return this.focus.key
|
||||
}
|
||||
|
||||
get focusOffset() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.focusOffset` property has been deprecated, use `range.focus.offset` instead.'
|
||||
)
|
||||
|
||||
return this.focus.offset
|
||||
}
|
||||
|
||||
get focusPath() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.focusPath` property has been deprecated, use `range.focus.path` instead.'
|
||||
)
|
||||
|
||||
return this.focus.path
|
||||
}
|
||||
|
||||
get startKey() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.startKey` property has been deprecated, use `range.start.key` instead.'
|
||||
)
|
||||
|
||||
return this.start.key
|
||||
}
|
||||
|
||||
get startOffset() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.startOffset` property has been deprecated, use `range.start.offset` instead.'
|
||||
)
|
||||
|
||||
return this.start.offset
|
||||
}
|
||||
|
||||
get startPath() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.startPath` property has been deprecated, use `range.start.path` instead.'
|
||||
)
|
||||
|
||||
return this.start.path
|
||||
}
|
||||
|
||||
get endKey() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.endKey` property has been deprecated, use `range.end.key` instead.'
|
||||
)
|
||||
|
||||
return this.end.key
|
||||
}
|
||||
|
||||
get endOffset() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.endOffset` property has been deprecated, use `range.end.offset` instead.'
|
||||
)
|
||||
|
||||
return this.end.offset
|
||||
}
|
||||
|
||||
get endPath() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `range.endPath` property has been deprecated, use `range.end.path` instead.'
|
||||
)
|
||||
|
||||
return this.end.path
|
||||
}
|
||||
|
||||
hasAnchorAtStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasAnchorAtStartOf` method is deprecated, please use `Range.anchor.isAtStartOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.anchor.isAtStartOfNode(node)
|
||||
}
|
||||
|
||||
hasAnchorAtEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasAnchorAtEndOf` method is deprecated, please use `Range.anchor.isAtEndOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.anchor.isAtEndOfNode(node)
|
||||
}
|
||||
|
||||
hasAnchorBetween(node, start, end) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasAnchorBetween` method is deprecated, please use the `Range.anchor` methods and properties directly instead.'
|
||||
)
|
||||
|
||||
return (
|
||||
this.anchor.offset <= end &&
|
||||
start <= this.anchor.offset &&
|
||||
this.anchor.isInNode(node)
|
||||
)
|
||||
}
|
||||
|
||||
hasAnchorIn(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasAnchorAtEndOf` method is deprecated, please use `Range.anchor.isInNode` instead.'
|
||||
)
|
||||
|
||||
return this.anchor.isInNode(node)
|
||||
}
|
||||
|
||||
hasEdgeAtStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasEdgeAtStartOf` method is deprecated.'
|
||||
)
|
||||
|
||||
return this.anchor.isAtStartOfNode(node) || this.focus.isAtStartOfNode(node)
|
||||
}
|
||||
|
||||
hasEdgeAtEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasEdgeAtEndOf` method is deprecated.'
|
||||
)
|
||||
|
||||
return this.anchor.isAtEndOfNode(node) || this.focus.isAtEndOfNode(node)
|
||||
}
|
||||
|
||||
hasEdgeBetween(node, start, end) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasEdgeBetween` method is deprecated.'
|
||||
)
|
||||
|
||||
return (
|
||||
(this.anchor.offset <= end &&
|
||||
start <= this.anchor.offset &&
|
||||
this.anchor.isInNode(node)) ||
|
||||
(this.focus.offset <= end &&
|
||||
start <= this.focus.offset &&
|
||||
this.focus.isInNode(node))
|
||||
)
|
||||
}
|
||||
|
||||
hasEdgeIn(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasEdgeAtEndOf` method is deprecated.'
|
||||
)
|
||||
|
||||
return this.anchor.isInNode(node) || this.focus.isInNode(node)
|
||||
}
|
||||
|
||||
hasEndAtStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasEndAtStartOf` method is deprecated, please use `Range.end.isAtStartOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.end.isAtStartOfNode(node)
|
||||
}
|
||||
|
||||
hasEndAtEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasEndAtEndOf` method is deprecated, please use `Range.end.isAtEndOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.end.isAtEndOfNode(node)
|
||||
}
|
||||
|
||||
hasEndBetween(node, start, end) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasEndBetween` method is deprecated, please use the `Range.end` methods and properties directly instead.'
|
||||
)
|
||||
|
||||
return (
|
||||
this.end.offset <= end &&
|
||||
start <= this.end.offset &&
|
||||
this.end.isInNode(node)
|
||||
)
|
||||
}
|
||||
|
||||
hasEndIn(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasEndAtEndOf` method is deprecated, please use `Range.end.isInNode` instead.'
|
||||
)
|
||||
|
||||
return this.end.isInNode(node)
|
||||
}
|
||||
|
||||
hasFocusAtEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasFocusAtEndOf` method is deprecated, please use `Range.focus.isAtEndOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.focus.isAtEndOfNode(node)
|
||||
}
|
||||
|
||||
hasFocusAtStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasFocusAtStartOf` method is deprecated, please use `Range.focus.isAtStartOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.focus.isAtStartOfNode(node)
|
||||
}
|
||||
|
||||
hasFocusBetween(node, start, end) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasFocusBetween` method is deprecated, please use the `Range.focus` methods and properties directly instead.'
|
||||
)
|
||||
|
||||
return (
|
||||
start <= this.focus.offset &&
|
||||
this.focus.offset <= end &&
|
||||
this.focus.isInNode(node)
|
||||
)
|
||||
}
|
||||
|
||||
hasFocusIn(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasFocusAtEndOf` method is deprecated, please use `Range.focus.isInNode` instead.'
|
||||
)
|
||||
|
||||
return this.focus.isInNode(node)
|
||||
}
|
||||
|
||||
hasStartAtStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasStartAtStartOf` method is deprecated, please use `Range.start.isAtStartOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.start.isAtStartOfNode(node)
|
||||
}
|
||||
|
||||
hasStartAtEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasStartAtEndOf` method is deprecated, please use `Range.start.isAtEndOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.start.isAtEndOfNode(node)
|
||||
}
|
||||
|
||||
hasStartBetween(node, start, end) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasStartBetween` method is deprecated, please use the `Range.start` methods and properties directly instead.'
|
||||
)
|
||||
|
||||
return (
|
||||
this.start.offset <= end &&
|
||||
start <= this.start.offset &&
|
||||
this.start.isInNode(node)
|
||||
)
|
||||
}
|
||||
|
||||
hasStartIn(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.hasStartAtEndOf` method is deprecated, please use `Range.start.isInNode` instead.'
|
||||
)
|
||||
|
||||
return this.start.isInNode(node)
|
||||
}
|
||||
|
||||
isAtStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.isAtStartOf` method is deprecated, please use `Range.isCollapsed` and `Point.isAtStartOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.isCollapsed && this.anchor.isAtStartOfNode(node)
|
||||
}
|
||||
|
||||
isAtEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.isAtEndOf` method is deprecated, please use `Range.isCollapsed` and `Point.isAtEndOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.isCollapsed && this.anchor.isAtEndOfNode(node)
|
||||
}
|
||||
|
||||
blur() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.blur` method is deprecated, please use `Range.merge` directly instead.'
|
||||
)
|
||||
|
||||
return this.merge({ isFocused: false })
|
||||
}
|
||||
|
||||
deselect() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.deselect` method is deprecated, please use `Range.create` to create a new unset range instead.'
|
||||
)
|
||||
|
||||
return Range.create()
|
||||
}
|
||||
|
||||
moveAnchorOffsetTo(o) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveAnchorOffsetTo` method is deprecated, please use `Range.moveAnchorTo(offset)` instead.'
|
||||
)
|
||||
|
||||
return this.moveAnchorTo(o)
|
||||
}
|
||||
|
||||
moveFocusOffsetTo(fo) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveFocusOffsetTo` method is deprecated, please use `Range.moveFocusTo(offset)` instead.'
|
||||
)
|
||||
|
||||
return this.moveFocusTo(fo)
|
||||
}
|
||||
|
||||
moveStartOffsetTo(o) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveStartOffsetTo` method is deprecated, please use `Range.moveStartTo(offset)` instead.'
|
||||
)
|
||||
|
||||
return this.moveStartTo(o)
|
||||
}
|
||||
|
||||
moveEndOffsetTo(o) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveEndOffsetTo` method is deprecated, please use `Range.moveEndTo(offset)` instead.'
|
||||
)
|
||||
|
||||
return this.moveEndTo(o)
|
||||
}
|
||||
|
||||
moveOffsetsTo(ao, fo = ao) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveOffsetsTo` method is deprecated, please use `Range.moveAnchorTo` and `Range.moveFocusTo` in sequence instead.'
|
||||
)
|
||||
|
||||
return this.moveAnchorTo(ao).moveFocusTo(fo)
|
||||
}
|
||||
|
||||
moveAnchorToStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveAnchorToStartOf` method is deprecated, please use `Range.moveAnchorToStartOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.moveAnchorToStartOfNode(node)
|
||||
}
|
||||
|
||||
moveAnchorToEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveAnchorToEndOf` method is deprecated, please use `Range.moveAnchorToEndOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.moveAnchorToEndOfNode(node)
|
||||
}
|
||||
|
||||
moveFocusToStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveFocusToStartOf` method is deprecated, please use `Range.moveFocusToStartOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.moveFocusToStartOfNode(node)
|
||||
}
|
||||
|
||||
moveFocusToEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveFocusToEndOf` method is deprecated, please use `Range.moveFocusToEndOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.moveFocusToEndOfNode(node)
|
||||
}
|
||||
|
||||
moveToStartOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveToStartOf` method is deprecated, please use `Range.moveToStartOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.moveToStartOfNode(node)
|
||||
}
|
||||
|
||||
moveToEndOf(node) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveToEndOf` method is deprecated, please use `Range.moveToEndOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.moveToEndOfNode(node)
|
||||
}
|
||||
|
||||
moveToRangeOf(...args) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveToRangeOf` method is deprecated, please use `Range.moveToRangeOfNode` instead.'
|
||||
)
|
||||
|
||||
return this.moveToRangeOfNode(...args)
|
||||
}
|
||||
|
||||
collapseToAnchor() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.collapseToAnchor` method is deprecated, please use `Range.moveToAnchor` instead.'
|
||||
)
|
||||
|
||||
return this.moveToAnchor()
|
||||
}
|
||||
|
||||
collapseToEnd() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.collapseToEnd` method is deprecated, please use `Range.moveToEnd` instead.'
|
||||
)
|
||||
|
||||
return this.moveToEnd()
|
||||
}
|
||||
|
||||
collapseToFocus() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.collapseToFocus` method is deprecated, please use `Range.moveToFocus` instead.'
|
||||
)
|
||||
|
||||
return this.moveToFocus()
|
||||
}
|
||||
|
||||
collapseToStart() {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.collapseToStart` method is deprecated, please use `Range.moveToStart` instead.'
|
||||
)
|
||||
|
||||
return this.moveToStart()
|
||||
}
|
||||
|
||||
move(n = 1) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.move` method is deprecated, please use `Range.moveForward` or `Range.moveBackward` instead.'
|
||||
)
|
||||
|
||||
return n > 0 ? this.moveForward(n) : this.moveBackward(-n)
|
||||
}
|
||||
|
||||
moveAnchor(n = 1) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveAnchor` method is deprecated, please use `Range.moveAnchorForward` or `Range.moveAnchorBackward` instead.'
|
||||
)
|
||||
|
||||
return n > 0 ? this.moveAnchorForward(n) : this.moveAnchorBackward(-n)
|
||||
}
|
||||
|
||||
moveEnd(n = 1) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveEnd` method is deprecated, please use `Range.moveEndForward` or `Range.moveEndBackward` instead.'
|
||||
)
|
||||
|
||||
return n > 0 ? this.moveEndForward(n) : this.moveEndBackward(-n)
|
||||
}
|
||||
|
||||
moveFocus(n = 1) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveFocus` method is deprecated, please use `Range.moveFocusForward` or `Range.moveFocusBackward` instead.'
|
||||
)
|
||||
|
||||
return n > 0 ? this.moveFocusForward(n) : this.moveFocusBackward(-n)
|
||||
}
|
||||
|
||||
moveStart(n = 1) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'The `Range.moveStart` method is deprecated, please use `Range.moveStartForward` or `Range.moveStartBackward` instead.'
|
||||
)
|
||||
|
||||
return n > 0 ? this.moveStartForward(n) : this.moveStartBackward(-n)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mix in some aliases for convenience / parallelism with the browser APIs.
|
||||
*/
|
||||
|
||||
const ALIAS_METHODS = [
|
||||
['collapseTo', 'moveTo'],
|
||||
['collapseToStartOf', 'moveToStartOfNode'],
|
||||
['collapseToEndOf', 'moveToEndOfNode'],
|
||||
['extend', 'moveFocus'],
|
||||
['extendTo', 'moveFocusTo'],
|
||||
['extendToStartOf', 'moveFocusToStartOfNode'],
|
||||
['extendToEndOf', 'moveFocusToEndOfNode'],
|
||||
]
|
||||
|
||||
ALIAS_METHODS.forEach(([alias, method]) => {
|
||||
RangeInterface.prototype[alias] = function(...args) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
`The \`Range.${alias}\` method is deprecated, please use \`Range.${method}\` instead.`
|
||||
)
|
||||
|
||||
return this[method](...args)
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Mix in the range interface.
|
||||
*
|
||||
|
@@ -13,7 +13,6 @@ import Node from './node'
|
||||
|
||||
const DEFAULTS = {
|
||||
data: new Map(),
|
||||
isVoid: false,
|
||||
key: undefined,
|
||||
nodes: new List(),
|
||||
type: undefined,
|
||||
@@ -81,13 +80,7 @@ class Block extends Record(DEFAULTS) {
|
||||
return object
|
||||
}
|
||||
|
||||
const {
|
||||
data = {},
|
||||
isVoid = false,
|
||||
key = KeyUtils.create(),
|
||||
nodes = [],
|
||||
type,
|
||||
} = object
|
||||
const { data = {}, key = KeyUtils.create(), nodes = [], type } = object
|
||||
|
||||
if (typeof type != 'string') {
|
||||
throw new Error('`Block.fromJSON` requires a `type` string.')
|
||||
@@ -96,7 +89,6 @@ class Block extends Record(DEFAULTS) {
|
||||
const block = new Block({
|
||||
key,
|
||||
type,
|
||||
isVoid: !!isVoid,
|
||||
data: Map(data),
|
||||
nodes: Node.createList(nodes),
|
||||
})
|
||||
@@ -145,7 +137,6 @@ class Block extends Record(DEFAULTS) {
|
||||
const object = {
|
||||
object: this.object,
|
||||
type: this.type,
|
||||
isVoid: this.get('isVoid'),
|
||||
data: this.data.toJSON(),
|
||||
nodes: this.nodes.toArray().map(n => n.toJSON(options)),
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Record } from 'immutable'
|
||||
|
||||
import Mark from './mark'
|
||||
@@ -106,18 +105,7 @@ class Decoration extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
static fromJSON(object) {
|
||||
const { anchor, focus } = object
|
||||
let { mark } = object
|
||||
|
||||
if (object.marks) {
|
||||
logger.deprecate(
|
||||
'0.39.0',
|
||||
'The `marks` property of decorations has been changed to a single `mark` property instead.'
|
||||
)
|
||||
|
||||
mark = object.marks[0]
|
||||
}
|
||||
|
||||
const { anchor, focus, mark } = object
|
||||
const decoration = new Decoration({
|
||||
anchor: Point.fromJSON(anchor || {}),
|
||||
focus: Point.fromJSON(focus || {}),
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import Debug from 'debug'
|
||||
import isEqual from 'lodash/isEqual'
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import { List, Record, Stack } from 'immutable'
|
||||
|
||||
@@ -196,11 +195,11 @@ function shouldMerge(o, p) {
|
||||
(o.type == 'insert_text' &&
|
||||
p.type == 'insert_text' &&
|
||||
o.offset == p.offset + p.text.length &&
|
||||
isEqual(o.path, p.path)) ||
|
||||
o.path.equals(p.path)) ||
|
||||
(o.type == 'remove_text' &&
|
||||
p.type == 'remove_text' &&
|
||||
o.offset + o.text.length == p.offset &&
|
||||
isEqual(o.path, p.path))
|
||||
o.path.equals(p.path))
|
||||
|
||||
return merge
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ import Node from './node'
|
||||
|
||||
const DEFAULTS = {
|
||||
data: new Map(),
|
||||
isVoid: false,
|
||||
key: undefined,
|
||||
nodes: new List(),
|
||||
type: undefined,
|
||||
@@ -81,13 +80,7 @@ class Inline extends Record(DEFAULTS) {
|
||||
return object
|
||||
}
|
||||
|
||||
const {
|
||||
data = {},
|
||||
isVoid = false,
|
||||
key = KeyUtils.create(),
|
||||
nodes = [],
|
||||
type,
|
||||
} = object
|
||||
const { data = {}, key = KeyUtils.create(), nodes = [], type } = object
|
||||
|
||||
if (typeof type != 'string') {
|
||||
throw new Error('`Inline.fromJS` requires a `type` string.')
|
||||
@@ -96,7 +89,6 @@ class Inline extends Record(DEFAULTS) {
|
||||
const inline = new Inline({
|
||||
key,
|
||||
type,
|
||||
isVoid: !!isVoid,
|
||||
data: new Map(data),
|
||||
nodes: Node.createList(nodes),
|
||||
})
|
||||
@@ -145,7 +137,6 @@ class Inline extends Record(DEFAULTS) {
|
||||
const object = {
|
||||
object: this.object,
|
||||
type: this.type,
|
||||
isVoid: this.get('isVoid'),
|
||||
data: this.data.toJSON(),
|
||||
nodes: this.nodes.toArray().map(n => n.toJSON(options)),
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import warning from 'slate-dev-warning'
|
||||
import { List } from 'immutable'
|
||||
|
||||
import Block from './block'
|
||||
@@ -32,9 +32,9 @@ class Node {
|
||||
let { object } = attrs
|
||||
|
||||
if (!object && attrs.kind) {
|
||||
logger.deprecate(
|
||||
'slate@0.32.0',
|
||||
'The `kind` property of Slate objects has been renamed to `object`.'
|
||||
warning(
|
||||
false,
|
||||
'As of slate@0.32.0, the `kind` property of Slate objects has been renamed to `object`.'
|
||||
)
|
||||
|
||||
object = attrs.kind
|
||||
@@ -90,7 +90,6 @@ class Node {
|
||||
if (Block.isBlock(attrs) || Inline.isInline(attrs)) {
|
||||
return {
|
||||
data: attrs.data,
|
||||
isVoid: attrs.isVoid,
|
||||
type: attrs.type,
|
||||
}
|
||||
}
|
||||
@@ -103,7 +102,6 @@ class Node {
|
||||
const props = {}
|
||||
if ('type' in attrs) props.type = attrs.type
|
||||
if ('data' in attrs) props.data = Data.create(attrs.data)
|
||||
if ('isVoid' in attrs) props.isVoid = attrs.isVoid
|
||||
return props
|
||||
}
|
||||
|
||||
@@ -123,9 +121,9 @@ class Node {
|
||||
let { object } = value
|
||||
|
||||
if (!object && value.kind) {
|
||||
logger.deprecate(
|
||||
'slate@0.32.0',
|
||||
'The `kind` property of Slate objects has been renamed to `object`.'
|
||||
warning(
|
||||
false,
|
||||
'As of slate@0.32.0, the `kind` property of Slate objects has been renamed to `object`.'
|
||||
)
|
||||
|
||||
object = value.kind
|
||||
|
@@ -267,7 +267,6 @@ class Operation extends Record(DEFAULTS) {
|
||||
if (key == 'properties' && type == 'set_node') {
|
||||
const v = {}
|
||||
if ('data' in value) v.data = value.data.toJS()
|
||||
if ('isVoid' in value) v.isVoid = value.get('isVoid')
|
||||
if ('type' in value) v.type = value.type
|
||||
value = v
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import warning from 'slate-dev-warning'
|
||||
import { Record } from 'immutable'
|
||||
|
||||
import KeyUtils from '../utils/key-utils'
|
||||
@@ -289,7 +289,7 @@ class Point extends Record(DEFAULTS) {
|
||||
const target = node.getNode(key || path)
|
||||
|
||||
if (!target) {
|
||||
logger.warn("A point's `path` or `key` invalid and was reset:", this)
|
||||
warning(false, "A point's `path` or `key` invalid and was reset!")
|
||||
|
||||
const text = node.getFirstText()
|
||||
if (!text) return Point.create()
|
||||
@@ -304,7 +304,7 @@ class Point extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
if (target.object !== 'text') {
|
||||
logger.warn('A point should not reference a non-text node:', target)
|
||||
warning(false, 'A point should not reference a non-text node!')
|
||||
|
||||
const text = target.getTextAtOffset(offset)
|
||||
const before = target.getOffset(text.key)
|
||||
@@ -318,7 +318,7 @@ class Point extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
if (target && path && key && key !== target.key) {
|
||||
logger.warn("A point's `key` did not match its `path`:", this, target)
|
||||
warning(false, "A point's `key` did not match its `path`!")
|
||||
}
|
||||
|
||||
const point = this.merge({
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import isPlainObject from 'is-plain-object'
|
||||
import logger from 'slate-dev-logger'
|
||||
import { List, Record } from 'immutable'
|
||||
|
||||
import Decoration from './decoration'
|
||||
@@ -42,24 +41,6 @@ class Range extends Record(DEFAULTS) {
|
||||
}
|
||||
|
||||
if (isPlainObject(attrs)) {
|
||||
if ('isFocused' in attrs || 'marks' in attrs) {
|
||||
logger.deprecate(
|
||||
'0.39.0',
|
||||
'Using `Range.create` for selections is deprecated, please use `Selection.create` instead.'
|
||||
)
|
||||
|
||||
return Selection.create(attrs)
|
||||
}
|
||||
|
||||
if ('isAtomic' in attrs) {
|
||||
logger.deprecate(
|
||||
'0.39.0',
|
||||
'Using `Range.create` for decorations is deprecated, please use `Decoration.create` instead.'
|
||||
)
|
||||
|
||||
return Decoration.create(attrs)
|
||||
}
|
||||
|
||||
return Range.fromJSON(attrs)
|
||||
}
|
||||
|
||||
@@ -121,39 +102,7 @@ class Range extends Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
static fromJSON(object) {
|
||||
let { anchor, focus } = object
|
||||
|
||||
if (
|
||||
!anchor &&
|
||||
(object.anchorKey || object.anchorOffset || object.anchorPath)
|
||||
) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'`Range` objects now take a `Point` object as an `anchor` instead of taking `anchorKey/Offset/Path` properties. But you passed:',
|
||||
object
|
||||
)
|
||||
|
||||
anchor = {
|
||||
key: object.anchorKey,
|
||||
offset: object.anchorOffset,
|
||||
path: object.anchorPath,
|
||||
}
|
||||
}
|
||||
|
||||
if (!focus && (object.focusKey || object.focusOffset || object.focusPath)) {
|
||||
logger.deprecate(
|
||||
'0.37.0',
|
||||
'`Range` objects now take a `Point` object as a `focus` instead of taking `focusKey/Offset/Path` properties. But you passed:',
|
||||
object
|
||||
)
|
||||
|
||||
focus = {
|
||||
key: object.focusKey,
|
||||
offset: object.focusOffset,
|
||||
path: object.focusPath,
|
||||
}
|
||||
}
|
||||
|
||||
const { anchor, focus } = object
|
||||
const range = new Range({
|
||||
anchor: Point.fromJSON(anchor || {}),
|
||||
focus: Point.fromJSON(focus || {}),
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user