1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 15:02:51 +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) { query(query, ...args) {
debug('query', { query, args }) debug('query', { query, args })
const { editor } = this
const obj = { type: query, args } 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. * On query, if it exists in our list of queries, call it.
* *
* @param {Object} query * @param {Object} query
* @param {Editor} editor
* @param {Function} next * @param {Function} next
*/ */
function onQuery(query, next) { function onQuery(query, editor, next) {
const { type, args } = query const { type, args } = query
const fn = queries[type] const fn = queries[type]
if (!fn) return next() if (!fn) return next()
@@ -46,7 +47,7 @@ function QueriesPlugin(options = {}) {
if (ret !== undefined) return ret if (ret !== undefined) return ret
} }
const ret = fn(...args) const ret = fn(editor, ...args)
return ret === undefined ? next() : ret 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. * Check if a `mark` is void based on the schema rules.
* *
* @param {Editor} editor
* @param {Mark} mark * @param {Mark} mark
* @return {Boolean} * @return {Boolean}
*/ */
function isAtomic(mark) { function isAtomic(editor, mark) {
const rule = schemaRules.find( const rule = schemaRules.find(
r => 'isAtomic' in r && testRules(mark, r.match) 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. * Check if a `node` is void based on the schema rules.
* *
* @param {Editor} editor
* @param {Node} node * @param {Node} node
* @return {Boolean} * @return {Boolean}
*/ */
function isVoid(node) { function isVoid(editor, node) {
const rule = schemaRules.find( const rule = schemaRules.find(
r => 'isVoid' in r && testRules(node, r.match) r => 'isVoid' in r && testRules(node, r.match)
) )