mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-28 09:29:49 +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-window": "^1.0.2",
|
||||
"keycode": "^2.1.2",
|
||||
"lodash": "^4.17.4",
|
||||
"prop-types": "^15.5.8",
|
||||
"react-portal": "^3.1.0",
|
||||
"selection-is-backward": "^1.0.0",
|
||||
|
@@ -125,7 +125,8 @@ class Editor extends React.Component {
|
||||
this.state.state = state
|
||||
|
||||
// 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) => {
|
||||
const next = this.state.stack[method](this.state.state, this, ...args)
|
||||
this.onChange(next)
|
||||
@@ -144,7 +145,8 @@ class Editor extends React.Component {
|
||||
let { stack } = this.state
|
||||
|
||||
// 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
|
||||
const { onChange, ...rest } = props // eslint-disable-line no-unused-vars
|
||||
stack = Stack.create(rest)
|
||||
@@ -259,7 +261,8 @@ class Editor extends React.Component {
|
||||
* 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
|
||||
}
|
||||
|
||||
|
@@ -48,16 +48,16 @@ let OS
|
||||
if (browser) {
|
||||
const { userAgent } = window.navigator
|
||||
|
||||
for (const rule of BROWSER_RULES) {
|
||||
const [ name, regexp ] = rule
|
||||
for (let i = 0; i < BROWSER_RULES.length; i++) {
|
||||
const [ name, regexp ] = BROWSER_RULES[i]
|
||||
if (regexp.test(userAgent)) {
|
||||
BROWSER = name
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for (const rule of OS_RULES) {
|
||||
const [ name, regexp ] = rule
|
||||
for (let i = 0; i < OS_RULES.length; i++) {
|
||||
const [ name, regexp ] = OS_RULES[i]
|
||||
if (regexp.test(userAgent)) {
|
||||
OS = name
|
||||
break
|
||||
|
@@ -526,7 +526,8 @@ const Node = {
|
||||
getDescendantAtPath(path) {
|
||||
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.nodes) return
|
||||
descendant = descendant.nodes.get(index)
|
||||
|
@@ -4,6 +4,7 @@ import isReactComponent from '../utils/is-react-component'
|
||||
import typeOf from 'type-of'
|
||||
import MODEL_TYPES from '../constants/model-types'
|
||||
import { Record } from 'immutable'
|
||||
import find from 'lodash/find'
|
||||
|
||||
/**
|
||||
* Default properties.
|
||||
@@ -90,7 +91,7 @@ class Schema extends new Record(DEFAULTS) {
|
||||
*/
|
||||
|
||||
__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
|
||||
return match.render
|
||||
}
|
||||
@@ -131,7 +132,7 @@ class Schema extends new Record(DEFAULTS) {
|
||||
__validate(object) {
|
||||
let value
|
||||
|
||||
const match = this.rules.find((rule) => {
|
||||
const match = find(this.rules, (rule) => {
|
||||
if (!rule.validate) return
|
||||
if (!rule.match(object)) return
|
||||
|
||||
|
@@ -102,7 +102,8 @@ class Stack extends new Record(DEFAULTS) {
|
||||
const plugins = this.plugins.slice().reverse()
|
||||
let children
|
||||
|
||||
for (const plugin of plugins) {
|
||||
for (let i = 0; i < plugins.length; i++) {
|
||||
const plugin = plugins[i]
|
||||
if (!plugin.render) continue
|
||||
children = plugin.render(props, state, editor)
|
||||
props.children = children
|
||||
@@ -123,7 +124,8 @@ class Stack extends new Record(DEFAULTS) {
|
||||
debug('renderPortal')
|
||||
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
|
||||
const portal = plugin.renderPortal(state, editor)
|
||||
if (portal == null) continue
|
||||
@@ -144,11 +146,13 @@ class Stack extends new Record(DEFAULTS) {
|
||||
* @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) {
|
||||
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
|
||||
const next = plugin[method](...args, state, editor)
|
||||
if (next == null) continue
|
||||
@@ -169,7 +173,8 @@ for (const method of EVENT_HANDLER_METHODS) {
|
||||
* @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) {
|
||||
debug(method)
|
||||
|
||||
@@ -177,7 +182,8 @@ for (const method of STATE_ACCUMULATOR_METHODS) {
|
||||
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
|
||||
const next = plugin[method](...args, state, editor)
|
||||
if (next == null) continue
|
||||
@@ -210,7 +216,8 @@ function assertState(value) {
|
||||
function resolveSchema(plugins) {
|
||||
let rules = []
|
||||
|
||||
for (const plugin of plugins) {
|
||||
for (let i = 0; i < plugins.length; i++) {
|
||||
const plugin = plugins[i]
|
||||
if (plugin.schema == null) continue
|
||||
const schema = Schema.create(plugin.schema)
|
||||
rules = rules.concat(schema.rules)
|
||||
|
@@ -167,7 +167,8 @@ class Text extends new Record(DEFAULTS) {
|
||||
let { characters } = node
|
||||
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)
|
||||
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
|
||||
const ret = rule.deserialize(element, next)
|
||||
const type = typeOf(ret)
|
||||
@@ -311,7 +312,8 @@ class Html {
|
||||
|
||||
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
|
||||
const ret = rule.serialize(node, children)
|
||||
if (ret) return addKey(ret)
|
||||
@@ -332,7 +334,8 @@ class Html {
|
||||
const text = this.serializeString(string)
|
||||
|
||||
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
|
||||
const ret = rule.serialize(mark, children)
|
||||
if (ret) return addKey(ret)
|
||||
@@ -350,7 +353,8 @@ class Html {
|
||||
*/
|
||||
|
||||
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
|
||||
const ret = rule.serialize(string, string.text)
|
||||
if (ret) return ret
|
||||
|
@@ -56,7 +56,8 @@ const UNSET = undefined
|
||||
function memoize(object, properties, 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]
|
||||
|
||||
if (!original) {
|
||||
@@ -121,7 +122,8 @@ function memoize(object, properties, options = {}) {
|
||||
*/
|
||||
|
||||
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)
|
||||
if (map === UNSET) return UNSET
|
||||
}
|
||||
@@ -142,7 +144,8 @@ function setIn(map, keys, value) {
|
||||
let parent = map
|
||||
let child
|
||||
|
||||
for (const key of keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i]
|
||||
child = parent.get(key)
|
||||
|
||||
// If the path was not created yet...
|
||||
|
@@ -3963,7 +3963,7 @@ lodash.pickby@^4.0.0:
|
||||
version "4.6.0"
|
||||
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"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
||||
|
||||
|
Reference in New Issue
Block a user