Socket
Socket
Sign inDemoInstall

prosemirror-state

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-state - npm Package Compare versions

Comparing version 0.17.1 to 0.18.0

76

dist/plugin.js

@@ -0,5 +1,57 @@

// PluginSpec:: Object
// A plugin spec provides a definition for a plugin.
//
// props:: ?EditorProps
// The [view props](#view.EditorProps) added by this plugin.
// Note that the
// [`dispatchTransaction`](#view.EditorProps.dispatchTransaction)
// and [`state`](#view.EditorProps.state) props can't be defined
// by plugins, only by the main props object. Props that are
// functions will be bound to have the plugin instance as their
// `this` binding.
//
// state:: ?StateField
// A [state field](#state.StateField) defined by this plugin.
//
// key:: ?PluginKey
// Can optionally be used to make this a keyed plugin. You can
// have only one plugin with a given key in a given state, but
// it is possible to access the plugin's configuration and state
// through the key, without having access to the plugin instance
// itself.
//
// view:: ?(EditorView) → Object
// When the plugin needs to interact with the editor view, or
// set something up in the DOM, use this field. The function
// will be called when the plugin's state is associated with an
// editor view.
//
// return::-
// Should return an object with the following optional
// properties:
//
// update:: ?(view: EditorView, prevState: EditorState)
// Called whenever the view's state is updated.
//
// destroy:: ?()
// Called when the view is destroyed or receives a state
// with different plugins.
//
// filterTransaction:: ?(Transaction, EditorState) → bool
// When present, this will be called before a transaction is
// applied by the state, allowing the plugin to cancel it (by
// returning false).
//
// appendTransaction:: ?(transactions: [Transaction], oldState: EditorState, newState: EditorState) → ?Transaction
// Allows the plugin to append another transaction to be applied
// after the given array of transactions. When another plugin
// appends a transaction after this was called, it is called
// again with the new state and extended array of transactions.
var warnedAboutOptions = false
// ::- Plugins wrap extra functionality that can be added to an
// editor. They can define new [state fields](#state.StateField), and
// add [view props](#view.EditorProps).
var Plugin = function Plugin(options) {
var Plugin = function Plugin(spec) {
var this$1 = this;

@@ -10,4 +62,4 @@

this.props = {}
if (options.props) { for (var prop in options.props) {
var val = options.props[prop]
if (spec.props) { for (var prop in spec.props) {
var val = spec.props[prop]
if (val instanceof Function) { val = val.bind(this$1) }

@@ -18,9 +70,21 @@ this$1.props[prop] = val

// The plugin's configuration object.
this.options = options
this.key = options.key ? options.key.key : createKey("plugin")
this.spec = spec
this.key = spec.key ? spec.key.key : createKey("plugin")
};
var prototypeAccessors = { options: {} };
prototypeAccessors.options.get = function () {
if (!warnedAboutOptions && typeof "console" != "undefined" && console.warn) {
warnedAboutOptions = true
console.warn("Plugin.options was renamed to Plugin.spec")
}
return this.spec
};
// :: (EditorState) → any
// Get the state field for this plugin.
Plugin.prototype.getState = function getState (state) { return state[this.key] };
Object.defineProperties( Plugin.prototype, prototypeAccessors );
exports.Plugin = Plugin

@@ -62,3 +126,3 @@

// ::- A key is used to [tag](#state.Plugin.constructor^options.key)
// ::- A key is used to [tag](#state.PluginSpec.key)
// plugins in a way that makes it possible to find them, given an

@@ -65,0 +129,0 @@ // editor state. Assigning a key does mean only one plugin of that

2

dist/selection.js

@@ -251,3 +251,3 @@ // ::- Superclass for editor selections.

var child = node.child(i)
if (!child.isLeaf) {
if (!child.isAtom) {
var inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text)

@@ -254,0 +254,0 @@ if (inner) { return inner }

@@ -21,3 +21,3 @@ var ref = require("prosemirror-model");

new FieldDesc("doc", {
init: function init(config) { return config.doc || config.schema.nodes.doc.createAndFill() },
init: function init(config) { return config.doc || config.schema.topNodeType.createAndFill() },
apply: function apply(tr) { return tr.doc }

@@ -56,4 +56,4 @@ }),

this$1.pluginsByKey[plugin.key] = plugin
if (plugin.options.state)
{ this$1.fields.push(new FieldDesc(plugin.key, plugin.options.state, plugin)) }
if (plugin.spec.state)
{ this$1.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin)) }
}) }

@@ -110,3 +110,3 @@ };

var plugin = this$1.config.plugins[i]
if (plugin.options.filterTransaction && !plugin.options.filterTransaction.call(plugin, tr, this$1))
if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this$1))
{ return false }

@@ -121,3 +121,3 @@ } }

// be influenced by the [transaction
// hooks](##state.Plugin.constructor^options.filterTransaction) of
// hooks](##state.PluginSpec.filterTransaction) of
// plugins) along with the new state.

@@ -137,6 +137,6 @@ EditorState.prototype.applyTransaction = function applyTransaction (tr) {

var plugin = this$1.config.plugins[i]
if (plugin.options.appendTransaction) {
if (plugin.spec.appendTransaction) {
var n = seen ? seen[i].n : 0, oldState = seen ? seen[i].state : this$1
var tr$1 = n < trs.length &&
plugin.options.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState)
plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState)
if (tr$1 && newState.filterTransaction(tr$1, i)) {

@@ -223,3 +223,3 @@ if (!seen) {

{ throw new RangeError("The JSON fields `doc` and `selection` are reserved") }
var plugin = pluginFields[prop], state = plugin.options.state
var plugin = pluginFields[prop], state = plugin.spec.state
if (state && state.toJSON) { result[prop] = state.toJSON.call(plugin, this$1[plugin.key]) }

@@ -247,3 +247,3 @@ } }

if (pluginFields) { for (var prop in pluginFields) {
var plugin = pluginFields[prop], state = plugin.options.state
var plugin = pluginFields[prop], state = plugin.spec.state
if (plugin.key == field.name && state && state.fromJSON &&

@@ -250,0 +250,0 @@ Object.prototype.hasOwnProperty.call(json, prop)) {

@@ -50,10 +50,4 @@ var ref = require("prosemirror-transform");

var prototypeAccessors = { docChanged: {},selection: {},selectionSet: {},storedMarksSet: {},isGeneric: {},scrolledIntoView: {} };
var prototypeAccessors = { selection: {},selectionSet: {},storedMarksSet: {},isGeneric: {},scrolledIntoView: {} };
// :: bool
// True when this transaction changes the document.
prototypeAccessors.docChanged.get = function () {
return this.steps.length > 0
};
// :: Selection

@@ -60,0 +54,0 @@ // The transform's current selection. This defaults to the

{
"name": "prosemirror-state",
"version": "0.17.1",
"version": "0.18.0",
"description": "ProseMirror editor state",

@@ -19,4 +19,4 @@ "main": "dist/index.js",

"dependencies": {
"prosemirror-model": "^0.17.0",
"prosemirror-transform": "^0.17.0"
"prosemirror-model": "^0.18.0",
"prosemirror-transform": "^0.18.0"
},

@@ -23,0 +23,0 @@ "devDependencies": {

@@ -0,1 +1,53 @@

// PluginSpec:: Object
// A plugin spec provides a definition for a plugin.
//
// props:: ?EditorProps
// The [view props](#view.EditorProps) added by this plugin.
// Note that the
// [`dispatchTransaction`](#view.EditorProps.dispatchTransaction)
// and [`state`](#view.EditorProps.state) props can't be defined
// by plugins, only by the main props object. Props that are
// functions will be bound to have the plugin instance as their
// `this` binding.
//
// state:: ?StateField
// A [state field](#state.StateField) defined by this plugin.
//
// key:: ?PluginKey
// Can optionally be used to make this a keyed plugin. You can
// have only one plugin with a given key in a given state, but
// it is possible to access the plugin's configuration and state
// through the key, without having access to the plugin instance
// itself.
//
// view:: ?(EditorView) → Object
// When the plugin needs to interact with the editor view, or
// set something up in the DOM, use this field. The function
// will be called when the plugin's state is associated with an
// editor view.
//
// return::-
// Should return an object with the following optional
// properties:
//
// update:: ?(view: EditorView, prevState: EditorState)
// Called whenever the view's state is updated.
//
// destroy:: ?()
// Called when the view is destroyed or receives a state
// with different plugins.
//
// filterTransaction:: ?(Transaction, EditorState) → bool
// When present, this will be called before a transaction is
// applied by the state, allowing the plugin to cancel it (by
// returning false).
//
// appendTransaction:: ?(transactions: [Transaction], oldState: EditorState, newState: EditorState) → ?Transaction
// Allows the plugin to append another transaction to be applied
// after the given array of transactions. When another plugin
// appends a transaction after this was called, it is called
// again with the new state and extended array of transactions.
let warnedAboutOptions = false
// ::- Plugins wrap extra functionality that can be added to an

@@ -5,59 +57,10 @@ // editor. They can define new [state fields](#state.StateField), and

class Plugin {
// :: (Object)
// :: (PluginSpec)
// Create a plugin.
//
// options::-
//
// props:: ?EditorProps
// The [view props](#view.EditorProps) added by this plugin.
// Note that the
// [`dispatchTransaction`](#view.EditorProps.dispatchTransaction)
// and [`state`](#view.EditorProps.state) props can't be defined
// by plugins, only by the main props object. Props that are
// functions will be bound to have the plugin instance as their
// `this` binding.
//
// state:: ?StateField
// A [state field](#state.StateField) defined by this plugin.
//
// key:: ?PluginKey
// Can optionally be used to make this a keyed plugin. You can
// have only one plugin with a given key in a given state, but
// it is possible to access the plugin's configuration and state
// through the key, without having access to the plugin instance
// itself.
//
// view:: ?(EditorView) → Object
// When the plugin needs to interact with the editor view, or
// set something up in the DOM, use this field. The function
// will be called when the plugin's state is associated with an
// editor view.
//
// return::-
// Should return an object with the following optional
// properties:
//
// update:: ?(EditorView)
// Called whenever the view's state is updated.
//
// destroy:: ?()
// Called when the view is destroyed or receives a state
// with different plugins.
//
// filterTransaction:: ?(Transaction, EditorState) → bool
// When present, this will be called before a transaction is
// applied by the state, allowing the plugin to cancel it (by
// returning false).
//
// appendTransaction:: ?(transactions: [Transaction], oldState: EditorState, newState: EditorState) → ?Transaction
// Allows the plugin to append another transaction to be applied
// after the given array of transactions. When another plugin
// appends a transaction after this was called, it is called
// again with the new state and extended array of transactions.
constructor(options) {
constructor(spec) {
// :: EditorProps
// The props exported by this plugin.
this.props = {}
if (options.props) for (let prop in options.props) {
let val = options.props[prop]
if (spec.props) for (let prop in spec.props) {
let val = spec.props[prop]
if (val instanceof Function) val = val.bind(this)

@@ -68,6 +71,14 @@ this.props[prop] = val

// The plugin's configuration object.
this.options = options
this.key = options.key ? options.key.key : createKey("plugin")
this.spec = spec
this.key = spec.key ? spec.key.key : createKey("plugin")
}
get options() {
if (!warnedAboutOptions && typeof "console" != "undefined" && console.warn) {
warnedAboutOptions = true
console.warn("Plugin.options was renamed to Plugin.spec")
}
return this.spec
}
// :: (EditorState) → any

@@ -113,3 +124,3 @@ // Get the state field for this plugin.

// ::- A key is used to [tag](#state.Plugin.constructor^options.key)
// ::- A key is used to [tag](#state.PluginSpec.key)
// plugins in a way that makes it possible to find them, given an

@@ -116,0 +127,0 @@ // editor state. Assigning a key does mean only one plugin of that

@@ -30,4 +30,5 @@ This module implements the state object of a ProseMirror editor, along

@PluginSpec
@Plugin
@StateField
@PluginKey

@@ -236,3 +236,3 @@ // ::- Superclass for editor selections.

let child = node.child(i)
if (!child.isLeaf) {
if (!child.isAtom) {
let inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text)

@@ -239,0 +239,0 @@ if (inner) return inner

@@ -20,3 +20,3 @@ const {Node} = require("prosemirror-model")

new FieldDesc("doc", {
init(config) { return config.doc || config.schema.nodes.doc.createAndFill() },
init(config) { return config.doc || config.schema.topNodeType.createAndFill() },
apply(tr) { return tr.doc }

@@ -54,4 +54,4 @@ }),

this.pluginsByKey[plugin.key] = plugin
if (plugin.options.state)
this.fields.push(new FieldDesc(plugin.key, plugin.options.state, plugin))
if (plugin.spec.state)
this.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin))
})

@@ -105,3 +105,3 @@ }

let plugin = this.config.plugins[i]
if (plugin.options.filterTransaction && !plugin.options.filterTransaction.call(plugin, tr, this))
if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this))
return false

@@ -116,3 +116,3 @@ }

// be influenced by the [transaction
// hooks](##state.Plugin.constructor^options.filterTransaction) of
// hooks](##state.PluginSpec.filterTransaction) of
// plugins) along with the new state.

@@ -130,6 +130,6 @@ applyTransaction(tr) {

let plugin = this.config.plugins[i]
if (plugin.options.appendTransaction) {
if (plugin.spec.appendTransaction) {
let n = seen ? seen[i].n : 0, oldState = seen ? seen[i].state : this
let tr = n < trs.length &&
plugin.options.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState)
plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState)
if (tr && newState.filterTransaction(tr, i)) {

@@ -210,3 +210,3 @@ if (!seen) {

throw new RangeError("The JSON fields `doc` and `selection` are reserved")
let plugin = pluginFields[prop], state = plugin.options.state
let plugin = pluginFields[prop], state = plugin.spec.state
if (state && state.toJSON) result[prop] = state.toJSON.call(plugin, this[plugin.key])

@@ -234,3 +234,3 @@ }

if (pluginFields) for (let prop in pluginFields) {
let plugin = pluginFields[prop], state = plugin.options.state
let plugin = pluginFields[prop], state = plugin.spec.state
if (plugin.key == field.name && state && state.fromJSON &&

@@ -237,0 +237,0 @@ Object.prototype.hasOwnProperty.call(json, prop)) {

@@ -43,8 +43,2 @@ const {Transform} = require("prosemirror-transform")

// :: bool
// True when this transaction changes the document.
get docChanged() {
return this.steps.length > 0
}
// :: Selection

@@ -51,0 +45,0 @@ // The transform's current selection. This defaults to the

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc