prosemirror-view
Advanced tools
Comparing version 1.19.3 to 1.20.0
@@ -0,1 +1,7 @@ | ||
## 1.20.0 (2021-09-03) | ||
### New features | ||
It is now possible to pass plugins directly to the view with the `plugins` direct prop. | ||
## 1.19.3 (2021-08-20) | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "prosemirror-view", | ||
"version": "1.19.3", | ||
"version": "1.20.0", | ||
"description": "ProseMirror's view component", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -422,5 +422,5 @@ function compareObjs(a, b) { | ||
// | ||
// map:: (Mapping, Node) → DecorationSource | ||
// Map the set of decorations in response to a change in the | ||
// document. | ||
// map:: (Mapping, Node) → DecorationSource | ||
// Map the set of decorations in response to a change in the | ||
// document. | ||
@@ -427,0 +427,0 @@ const empty = new DecorationSet() |
@@ -33,2 +33,5 @@ import {NodeSelection} from "prosemirror-state" | ||
this.directPlugins = props.plugins || [] | ||
this.directPlugins.forEach(checkStateComponent) | ||
this.dispatch = this.dispatch.bind(this) | ||
@@ -69,2 +72,3 @@ | ||
this.prevDirectPlugins = [] | ||
this.pluginViews = [] | ||
@@ -97,2 +101,6 @@ this.updatePluginViews() | ||
this._props = props | ||
if (props.plugins) { | ||
props.plugins.forEach(checkStateComponent) | ||
this.directPlugins = props.plugins | ||
} | ||
this.updateStateInner(props.state, true) | ||
@@ -207,4 +215,9 @@ } | ||
updatePluginViews(prevState) { | ||
if (!prevState || prevState.plugins != this.state.plugins) { | ||
if (!prevState || prevState.plugins != this.state.plugins || this.directPlugins != this.prevDirectPlugins) { | ||
this.prevDirectPlugins = this.directPlugins | ||
this.destroyPluginViews() | ||
for (let i = 0; i < this.directPlugins.length; i++) { | ||
let plugin = this.directPlugins[i] | ||
if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this)) | ||
} | ||
for (let i = 0; i < this.state.plugins.length; i++) { | ||
@@ -224,10 +237,14 @@ let plugin = this.state.plugins[i] | ||
// Goes over the values of a prop, first those provided directly, | ||
// then those from plugins (in order), and calls `f` every time a | ||
// non-undefined value is found. When `f` returns a truthy value, | ||
// that is immediately returned. When `f` isn't provided, it is | ||
// treated as the identity function (the prop value is returned | ||
// directly). | ||
// then those from plugins given to the view, then from plugins in | ||
// the state (in order), and calls `f` every time a non-undefined | ||
// value is found. When `f` returns a truthy value, that is | ||
// immediately returned. When `f` isn't provided, it is treated as | ||
// the identity function (the prop value is returned directly). | ||
someProp(propName, f) { | ||
let prop = this._props && this._props[propName], value | ||
if (prop != null && (value = f ? f(prop) : prop)) return value | ||
for (let i = 0; i < this.directPlugins.length; i++) { | ||
let prop = this.directPlugins[i].props[propName] | ||
if (prop != null && (value = f ? f(prop) : prop)) return value | ||
} | ||
let plugins = this.state.plugins | ||
@@ -442,2 +459,7 @@ if (plugins) for (let i = 0; i < plugins.length; i++) { | ||
function checkStateComponent(plugin) { | ||
if (plugin.spec.state || plugin.spec.filterTransaction || plugin.spec.appendTransaction) | ||
throw new RangeError("Plugins passed directly to the view must not have a state component") | ||
} | ||
// EditorProps:: interface | ||
@@ -621,2 +643,11 @@ // | ||
// | ||
// plugins:: [Plugin] | ||
// A set of plugins to use in the view, applying their [plugin | ||
// view](#state.PluginSpec.view) and | ||
// [props](#state.PluginSpec.props). Passing plugins with a state | ||
// component (a [state field](#state.PluginSpec.state) field or a | ||
// [transaction)[#state.PluginSpec.filterTransaction] filter or | ||
// appender) will result in an error, since such plugins must be | ||
// present in the state to work. | ||
// | ||
// dispatchTransaction:: ?(tr: Transaction) | ||
@@ -623,0 +654,0 @@ // The callback over which to send transactions (state updates) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1567589
14590