1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 23:12:52 +02:00

fix to pass editor to queries

This commit is contained in:
Ian Storm Taylor
2018-10-09 15:06:35 -07:00
parent 02c0f8e763
commit bd24739411
3 changed files with 9 additions and 5 deletions

View File

@@ -147,8 +147,9 @@ class Editor {
query(query, ...args) {
debug('query', { query, args })
const { editor } = this
const obj = { type: query, args }
return this.run('onQuery', obj)
return this.run('onQuery', obj, editor)
}
/**

View File

@@ -33,10 +33,11 @@ function QueriesPlugin(options = {}) {
* On query, if it exists in our list of queries, call it.
*
* @param {Object} query
* @param {Editor} editor
* @param {Function} next
*/
function onQuery(query, next) {
function onQuery(query, editor, next) {
const { type, args } = query
const fn = queries[type]
if (!fn) return next()
@@ -46,7 +47,7 @@ function QueriesPlugin(options = {}) {
if (ret !== undefined) return ret
}
const ret = fn(...args)
const ret = fn(editor, ...args)
return ret === undefined ? next() : ret
}

View File

@@ -53,11 +53,12 @@ function SchemaPlugin(schema) {
/**
* Check if a `mark` is void based on the schema rules.
*
* @param {Editor} editor
* @param {Mark} mark
* @return {Boolean}
*/
function isAtomic(mark) {
function isAtomic(editor, mark) {
const rule = schemaRules.find(
r => 'isAtomic' in r && testRules(mark, r.match)
)
@@ -68,11 +69,12 @@ function SchemaPlugin(schema) {
/**
* Check if a `node` is void based on the schema rules.
*
* @param {Editor} editor
* @param {Node} node
* @return {Boolean}
*/
function isVoid(node) {
function isVoid(editor, node) {
const rule = schemaRules.find(
r => 'isVoid' in r && testRules(node, r.match)
)