mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 01:50:06 +02:00
IE11 compat (#996)
* Convert "for ... of" loops to simple "for(;;)" * Add .editorconfig * Convert "for ... of" loops to simple "for(;;)"; Array.find => filter * Replace Array.prototype.find via local "find" method implementation * Replase utils/find by lodash/find * Remove .editorconfig * Fix lint errors
This commit is contained in:
committed by
Ian Storm Taylor
parent
31601d9a26
commit
577b5c7570
@@ -16,6 +16,7 @@
|
|||||||
"is-in-browser": "^1.1.3",
|
"is-in-browser": "^1.1.3",
|
||||||
"is-window": "^1.0.2",
|
"is-window": "^1.0.2",
|
||||||
"keycode": "^2.1.2",
|
"keycode": "^2.1.2",
|
||||||
|
"lodash": "^4.17.4",
|
||||||
"prop-types": "^15.5.8",
|
"prop-types": "^15.5.8",
|
||||||
"react-portal": "^3.1.0",
|
"react-portal": "^3.1.0",
|
||||||
"selection-is-backward": "^1.0.0",
|
"selection-is-backward": "^1.0.0",
|
||||||
|
@@ -125,7 +125,8 @@ class Editor extends React.Component {
|
|||||||
this.state.state = state
|
this.state.state = state
|
||||||
|
|
||||||
// Create a bound event handler for each event.
|
// Create a bound event handler for each event.
|
||||||
for (const method of EVENT_HANDLERS) {
|
for (let i = 0; i < EVENT_HANDLERS.length; i++) {
|
||||||
|
const method = EVENT_HANDLERS[i]
|
||||||
this[method] = (...args) => {
|
this[method] = (...args) => {
|
||||||
const next = this.state.stack[method](this.state.state, this, ...args)
|
const next = this.state.stack[method](this.state.state, this, ...args)
|
||||||
this.onChange(next)
|
this.onChange(next)
|
||||||
@@ -144,7 +145,8 @@ class Editor extends React.Component {
|
|||||||
let { stack } = this.state
|
let { stack } = this.state
|
||||||
|
|
||||||
// If any plugin-related properties will change, create a new `Stack`.
|
// If any plugin-related properties will change, create a new `Stack`.
|
||||||
for (const prop of PLUGINS_PROPS) {
|
for (let i = 0; i < PLUGINS_PROPS.length; i++) {
|
||||||
|
const prop = PLUGINS_PROPS[i]
|
||||||
if (props[prop] == this.props[prop]) continue
|
if (props[prop] == this.props[prop]) continue
|
||||||
const { onChange, ...rest } = props // eslint-disable-line no-unused-vars
|
const { onChange, ...rest } = props // eslint-disable-line no-unused-vars
|
||||||
stack = Stack.create(rest)
|
stack = Stack.create(rest)
|
||||||
@@ -259,7 +261,8 @@ class Editor extends React.Component {
|
|||||||
* Mix in the property types for the event handlers.
|
* Mix in the property types for the event handlers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (const property of EVENT_HANDLERS) {
|
for (let i = 0; i < EVENT_HANDLERS.length; i++) {
|
||||||
|
const property = EVENT_HANDLERS[i]
|
||||||
Editor.propTypes[property] = Types.func
|
Editor.propTypes[property] = Types.func
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,16 +48,16 @@ let OS
|
|||||||
if (browser) {
|
if (browser) {
|
||||||
const { userAgent } = window.navigator
|
const { userAgent } = window.navigator
|
||||||
|
|
||||||
for (const rule of BROWSER_RULES) {
|
for (let i = 0; i < BROWSER_RULES.length; i++) {
|
||||||
const [ name, regexp ] = rule
|
const [ name, regexp ] = BROWSER_RULES[i]
|
||||||
if (regexp.test(userAgent)) {
|
if (regexp.test(userAgent)) {
|
||||||
BROWSER = name
|
BROWSER = name
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const rule of OS_RULES) {
|
for (let i = 0; i < OS_RULES.length; i++) {
|
||||||
const [ name, regexp ] = rule
|
const [ name, regexp ] = OS_RULES[i]
|
||||||
if (regexp.test(userAgent)) {
|
if (regexp.test(userAgent)) {
|
||||||
OS = name
|
OS = name
|
||||||
break
|
break
|
||||||
|
@@ -526,7 +526,8 @@ const Node = {
|
|||||||
getDescendantAtPath(path) {
|
getDescendantAtPath(path) {
|
||||||
let descendant = this
|
let descendant = this
|
||||||
|
|
||||||
for (const index of path) {
|
for (let i = 0; i < path.length; i++) {
|
||||||
|
const index = path[i]
|
||||||
if (!descendant) return
|
if (!descendant) return
|
||||||
if (!descendant.nodes) return
|
if (!descendant.nodes) return
|
||||||
descendant = descendant.nodes.get(index)
|
descendant = descendant.nodes.get(index)
|
||||||
|
@@ -4,6 +4,7 @@ import isReactComponent from '../utils/is-react-component'
|
|||||||
import typeOf from 'type-of'
|
import typeOf from 'type-of'
|
||||||
import MODEL_TYPES from '../constants/model-types'
|
import MODEL_TYPES from '../constants/model-types'
|
||||||
import { Record } from 'immutable'
|
import { Record } from 'immutable'
|
||||||
|
import find from 'lodash/find'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default properties.
|
* Default properties.
|
||||||
@@ -90,7 +91,7 @@ class Schema extends new Record(DEFAULTS) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
__getComponent(object) {
|
__getComponent(object) {
|
||||||
const match = this.rules.find(rule => rule.render && rule.match(object))
|
const match = find(this.rules, rule => rule.render && rule.match(object))
|
||||||
if (!match) return
|
if (!match) return
|
||||||
return match.render
|
return match.render
|
||||||
}
|
}
|
||||||
@@ -131,7 +132,7 @@ class Schema extends new Record(DEFAULTS) {
|
|||||||
__validate(object) {
|
__validate(object) {
|
||||||
let value
|
let value
|
||||||
|
|
||||||
const match = this.rules.find((rule) => {
|
const match = find(this.rules, (rule) => {
|
||||||
if (!rule.validate) return
|
if (!rule.validate) return
|
||||||
if (!rule.match(object)) return
|
if (!rule.match(object)) return
|
||||||
|
|
||||||
|
@@ -102,7 +102,8 @@ class Stack extends new Record(DEFAULTS) {
|
|||||||
const plugins = this.plugins.slice().reverse()
|
const plugins = this.plugins.slice().reverse()
|
||||||
let children
|
let children
|
||||||
|
|
||||||
for (const plugin of plugins) {
|
for (let i = 0; i < plugins.length; i++) {
|
||||||
|
const plugin = plugins[i]
|
||||||
if (!plugin.render) continue
|
if (!plugin.render) continue
|
||||||
children = plugin.render(props, state, editor)
|
children = plugin.render(props, state, editor)
|
||||||
props.children = children
|
props.children = children
|
||||||
@@ -123,7 +124,8 @@ class Stack extends new Record(DEFAULTS) {
|
|||||||
debug('renderPortal')
|
debug('renderPortal')
|
||||||
const portals = []
|
const portals = []
|
||||||
|
|
||||||
for (const plugin of this.plugins) {
|
for (let i = 0; i < this.plugins.length; i++) {
|
||||||
|
const plugin = this.plugins[i]
|
||||||
if (!plugin.renderPortal) continue
|
if (!plugin.renderPortal) continue
|
||||||
const portal = plugin.renderPortal(state, editor)
|
const portal = plugin.renderPortal(state, editor)
|
||||||
if (portal == null) continue
|
if (portal == null) continue
|
||||||
@@ -144,11 +146,13 @@ class Stack extends new Record(DEFAULTS) {
|
|||||||
* @return {State|Null}
|
* @return {State|Null}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (const method of EVENT_HANDLER_METHODS) {
|
for (let i = 0; i < EVENT_HANDLER_METHODS.length; i++) {
|
||||||
|
const method = EVENT_HANDLER_METHODS[i]
|
||||||
Stack.prototype[method] = function (state, editor, ...args) {
|
Stack.prototype[method] = function (state, editor, ...args) {
|
||||||
debug(method)
|
debug(method)
|
||||||
|
|
||||||
for (const plugin of this.plugins) {
|
for (let k = 0; k < this.plugins.length; k++) {
|
||||||
|
const plugin = this.plugins[k]
|
||||||
if (!plugin[method]) continue
|
if (!plugin[method]) continue
|
||||||
const next = plugin[method](...args, state, editor)
|
const next = plugin[method](...args, state, editor)
|
||||||
if (next == null) continue
|
if (next == null) continue
|
||||||
@@ -169,7 +173,8 @@ for (const method of EVENT_HANDLER_METHODS) {
|
|||||||
* @return {State|Null}
|
* @return {State|Null}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (const method of STATE_ACCUMULATOR_METHODS) {
|
for (let i = 0; i < STATE_ACCUMULATOR_METHODS.length; i++) {
|
||||||
|
const method = STATE_ACCUMULATOR_METHODS[i]
|
||||||
Stack.prototype[method] = function (state, editor, ...args) {
|
Stack.prototype[method] = function (state, editor, ...args) {
|
||||||
debug(method)
|
debug(method)
|
||||||
|
|
||||||
@@ -177,7 +182,8 @@ for (const method of STATE_ACCUMULATOR_METHODS) {
|
|||||||
state = this.onBeforeChange(state, editor)
|
state = this.onBeforeChange(state, editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const plugin of this.plugins) {
|
for (let k = 0; k < this.plugins.length; k++) {
|
||||||
|
const plugin = this.plugins[k]
|
||||||
if (!plugin[method]) continue
|
if (!plugin[method]) continue
|
||||||
const next = plugin[method](...args, state, editor)
|
const next = plugin[method](...args, state, editor)
|
||||||
if (next == null) continue
|
if (next == null) continue
|
||||||
@@ -210,7 +216,8 @@ function assertState(value) {
|
|||||||
function resolveSchema(plugins) {
|
function resolveSchema(plugins) {
|
||||||
let rules = []
|
let rules = []
|
||||||
|
|
||||||
for (const plugin of plugins) {
|
for (let i = 0; i < plugins.length; i++) {
|
||||||
|
const plugin = plugins[i]
|
||||||
if (plugin.schema == null) continue
|
if (plugin.schema == null) continue
|
||||||
const schema = Schema.create(plugin.schema)
|
const schema = Schema.create(plugin.schema)
|
||||||
rules = rules.concat(schema.rules)
|
rules = rules.concat(schema.rules)
|
||||||
|
@@ -167,7 +167,8 @@ class Text extends new Record(DEFAULTS) {
|
|||||||
let { characters } = node
|
let { characters } = node
|
||||||
if (characters.size == 0) return characters
|
if (characters.size == 0) return characters
|
||||||
|
|
||||||
for (const decorator of decorators) {
|
for (let i = 0; i < decorators.length; i++) {
|
||||||
|
const decorator = decorators[i]
|
||||||
const decorateds = decorator(node)
|
const decorateds = decorator(node)
|
||||||
characters = characters.merge(decorateds)
|
characters = characters.merge(decorateds)
|
||||||
}
|
}
|
||||||
|
@@ -219,7 +219,8 @@ class Html {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const rule of this.rules) {
|
for (let i = 0; i < this.rules.length; i++) {
|
||||||
|
const rule = this.rules[i]
|
||||||
if (!rule.deserialize) continue
|
if (!rule.deserialize) continue
|
||||||
const ret = rule.deserialize(element, next)
|
const ret = rule.deserialize(element, next)
|
||||||
const type = typeOf(ret)
|
const type = typeOf(ret)
|
||||||
@@ -311,7 +312,8 @@ class Html {
|
|||||||
|
|
||||||
const children = node.nodes.map(this.serializeNode)
|
const children = node.nodes.map(this.serializeNode)
|
||||||
|
|
||||||
for (const rule of this.rules) {
|
for (let i = 0; i < this.rules.length; i++) {
|
||||||
|
const rule = this.rules[i]
|
||||||
if (!rule.serialize) continue
|
if (!rule.serialize) continue
|
||||||
const ret = rule.serialize(node, children)
|
const ret = rule.serialize(node, children)
|
||||||
if (ret) return addKey(ret)
|
if (ret) return addKey(ret)
|
||||||
@@ -332,7 +334,8 @@ class Html {
|
|||||||
const text = this.serializeString(string)
|
const text = this.serializeString(string)
|
||||||
|
|
||||||
return range.marks.reduce((children, mark) => {
|
return range.marks.reduce((children, mark) => {
|
||||||
for (const rule of this.rules) {
|
for (let i = 0; i < this.rules.length; i++) {
|
||||||
|
const rule = this.rules[i]
|
||||||
if (!rule.serialize) continue
|
if (!rule.serialize) continue
|
||||||
const ret = rule.serialize(mark, children)
|
const ret = rule.serialize(mark, children)
|
||||||
if (ret) return addKey(ret)
|
if (ret) return addKey(ret)
|
||||||
@@ -350,7 +353,8 @@ class Html {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
serializeString = (string) => {
|
serializeString = (string) => {
|
||||||
for (const rule of this.rules) {
|
for (let i = 0; i < this.rules.length; i++) {
|
||||||
|
const rule = this.rules[i]
|
||||||
if (!rule.serialize) continue
|
if (!rule.serialize) continue
|
||||||
const ret = rule.serialize(string, string.text)
|
const ret = rule.serialize(string, string.text)
|
||||||
if (ret) return ret
|
if (ret) return ret
|
||||||
|
@@ -56,7 +56,8 @@ const UNSET = undefined
|
|||||||
function memoize(object, properties, options = {}) {
|
function memoize(object, properties, options = {}) {
|
||||||
const { takesArguments = true } = options
|
const { takesArguments = true } = options
|
||||||
|
|
||||||
for (const property of properties) {
|
for (let i = 0; i < properties.length; i++) {
|
||||||
|
const property = properties[i]
|
||||||
const original = object[property]
|
const original = object[property]
|
||||||
|
|
||||||
if (!original) {
|
if (!original) {
|
||||||
@@ -121,7 +122,8 @@ function memoize(object, properties, options = {}) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function getIn(map, keys) {
|
function getIn(map, keys) {
|
||||||
for (const key of keys) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
|
const key = keys[i]
|
||||||
map = map.get(key)
|
map = map.get(key)
|
||||||
if (map === UNSET) return UNSET
|
if (map === UNSET) return UNSET
|
||||||
}
|
}
|
||||||
@@ -142,7 +144,8 @@ function setIn(map, keys, value) {
|
|||||||
let parent = map
|
let parent = map
|
||||||
let child
|
let child
|
||||||
|
|
||||||
for (const key of keys) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
|
const key = keys[i]
|
||||||
child = parent.get(key)
|
child = parent.get(key)
|
||||||
|
|
||||||
// If the path was not created yet...
|
// If the path was not created yet...
|
||||||
|
@@ -3963,7 +3963,7 @@ lodash.pickby@^4.0.0:
|
|||||||
version "4.6.0"
|
version "4.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff"
|
resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff"
|
||||||
|
|
||||||
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.2.0, lodash@^4.3.0:
|
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0:
|
||||||
version "4.17.4"
|
version "4.17.4"
|
||||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user