@depup/prosemirror-state 1.4.4-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tern-project +8 -0
- package/CHANGELOG.md +296 -0
- package/CONTRIBUTING.md +104 -0
- package/LICENSE +19 -0
- package/README.md +33 -0
- package/changes.json +18 -0
- package/dist/index.cjs +884 -0
- package/dist/index.d.cts +709 -0
- package/dist/index.d.ts +709 -0
- package/dist/index.js +1002 -0
- package/package.json +67 -0
- package/src/README.md +42 -0
- package/src/index.ts +7 -0
- package/src/plugin.ts +142 -0
- package/src/selection.ts +462 -0
- package/src/state.ts +266 -0
- package/src/transaction.ts +215 -0
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/prosemirror-state",
|
|
3
|
+
"version": "1.4.4-depup.0",
|
|
4
|
+
"description": "ProseMirror editor state (with updated dependencies)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"maintainers": [
|
|
16
|
+
{
|
|
17
|
+
"name": "Marijn Haverbeke",
|
|
18
|
+
"email": "marijn@haverbeke.berlin",
|
|
19
|
+
"web": "http://marijnhaverbeke.nl"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git://github.com/prosemirror/prosemirror-state.git"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"prosemirror-model": "^1.25.4",
|
|
28
|
+
"prosemirror-transform": "^1.11.0",
|
|
29
|
+
"prosemirror-view": "^1.41.7"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@prosemirror/buildhelper": "^0.1.5",
|
|
33
|
+
"prosemirror-test-builder": "^1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "pm-runtests"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"prosemirror-state",
|
|
40
|
+
"depup",
|
|
41
|
+
"updated-dependencies",
|
|
42
|
+
"security",
|
|
43
|
+
"latest",
|
|
44
|
+
"patched"
|
|
45
|
+
],
|
|
46
|
+
"depup": {
|
|
47
|
+
"changes": {
|
|
48
|
+
"prosemirror-model": {
|
|
49
|
+
"from": "^1.0.0",
|
|
50
|
+
"to": "^1.25.4"
|
|
51
|
+
},
|
|
52
|
+
"prosemirror-transform": {
|
|
53
|
+
"from": "^1.0.0",
|
|
54
|
+
"to": "^1.11.0"
|
|
55
|
+
},
|
|
56
|
+
"prosemirror-view": {
|
|
57
|
+
"from": "^1.27.0",
|
|
58
|
+
"to": "^1.41.7"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"depsUpdated": 3,
|
|
62
|
+
"originalPackage": "prosemirror-state",
|
|
63
|
+
"originalVersion": "1.4.4",
|
|
64
|
+
"processedAt": "2026-03-18T22:41:01.299Z",
|
|
65
|
+
"smokeTest": "passed"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
This module implements the state object of a ProseMirror editor, along
|
|
2
|
+
with the representation of the selection and the plugin abstraction.
|
|
3
|
+
|
|
4
|
+
### Editor State
|
|
5
|
+
|
|
6
|
+
ProseMirror keeps all editor state (the things, basically, that would
|
|
7
|
+
be required to create an editor just like the current one) in a single
|
|
8
|
+
[object](#state.EditorState). That object is updated (creating a new
|
|
9
|
+
state) by applying [transactions](#state.Transaction) to it.
|
|
10
|
+
|
|
11
|
+
@EditorState
|
|
12
|
+
@EditorStateConfig
|
|
13
|
+
@Transaction
|
|
14
|
+
@Command
|
|
15
|
+
|
|
16
|
+
### Selection
|
|
17
|
+
|
|
18
|
+
A ProseMirror selection can be one of several types. This module
|
|
19
|
+
defines types for classical [text selections](#state.TextSelection)
|
|
20
|
+
(of which cursors are a special case) and [_node_
|
|
21
|
+
selections](#state.NodeSelection), where a specific document node is
|
|
22
|
+
selected. It is possible to extend the editor with custom selection
|
|
23
|
+
types.
|
|
24
|
+
|
|
25
|
+
@Selection
|
|
26
|
+
@TextSelection
|
|
27
|
+
@NodeSelection
|
|
28
|
+
@AllSelection
|
|
29
|
+
|
|
30
|
+
@SelectionRange
|
|
31
|
+
@SelectionBookmark
|
|
32
|
+
|
|
33
|
+
### Plugin System
|
|
34
|
+
|
|
35
|
+
To make it easy to package and enable extra editor functionality,
|
|
36
|
+
ProseMirror has a plugin system.
|
|
37
|
+
|
|
38
|
+
@PluginSpec
|
|
39
|
+
@StateField
|
|
40
|
+
@PluginView
|
|
41
|
+
@Plugin
|
|
42
|
+
@PluginKey
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export {Selection, SelectionRange, TextSelection, NodeSelection, AllSelection, SelectionBookmark} from "./selection"
|
|
2
|
+
|
|
3
|
+
export {Transaction, Command} from "./transaction"
|
|
4
|
+
|
|
5
|
+
export {EditorState, EditorStateConfig} from "./state"
|
|
6
|
+
|
|
7
|
+
export {Plugin, PluginKey, PluginSpec, StateField, PluginView} from "./plugin"
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {type EditorView, type EditorProps} from "prosemirror-view"
|
|
2
|
+
import {EditorState, EditorStateConfig} from "./state"
|
|
3
|
+
import {Transaction} from "./transaction"
|
|
4
|
+
|
|
5
|
+
/// This is the type passed to the [`Plugin`](#state.Plugin)
|
|
6
|
+
/// constructor. It provides a definition for a plugin.
|
|
7
|
+
export interface PluginSpec<PluginState> {
|
|
8
|
+
/// The [view props](#view.EditorProps) added by this plugin. Props
|
|
9
|
+
/// that are functions will be bound to have the plugin instance as
|
|
10
|
+
/// their `this` binding.
|
|
11
|
+
props?: EditorProps<Plugin<PluginState>>
|
|
12
|
+
|
|
13
|
+
/// Allows a plugin to define a [state field](#state.StateField), an
|
|
14
|
+
/// extra slot in the state object in which it can keep its own data.
|
|
15
|
+
state?: StateField<PluginState>
|
|
16
|
+
|
|
17
|
+
/// Can be used to make this a keyed plugin. You can have only one
|
|
18
|
+
/// plugin with a given key in a given state, but it is possible to
|
|
19
|
+
/// access the plugin's configuration and state through the key,
|
|
20
|
+
/// without having access to the plugin instance object.
|
|
21
|
+
key?: PluginKey
|
|
22
|
+
|
|
23
|
+
/// When the plugin needs to interact with the editor view, or
|
|
24
|
+
/// set something up in the DOM, use this field. The function
|
|
25
|
+
/// will be called when the plugin's state is associated with an
|
|
26
|
+
/// editor view.
|
|
27
|
+
view?: (view: EditorView) => PluginView
|
|
28
|
+
|
|
29
|
+
/// When present, this will be called before a transaction is
|
|
30
|
+
/// applied by the state, allowing the plugin to cancel it (by
|
|
31
|
+
/// returning false).
|
|
32
|
+
filterTransaction?: (tr: Transaction, state: EditorState) => boolean
|
|
33
|
+
|
|
34
|
+
/// Allows the plugin to append another transaction to be applied
|
|
35
|
+
/// after the given array of transactions. When another plugin
|
|
36
|
+
/// appends a transaction after this was called, it is called again
|
|
37
|
+
/// with the new state and new transactions—but only the new
|
|
38
|
+
/// transactions, i.e. it won't be passed transactions that it
|
|
39
|
+
/// already saw.
|
|
40
|
+
appendTransaction?: (transactions: readonly Transaction[], oldState: EditorState, newState: EditorState) => Transaction | null | undefined
|
|
41
|
+
|
|
42
|
+
/// Additional properties are allowed on plugin specs, which can be
|
|
43
|
+
/// read via [`Plugin.spec`](#state.Plugin.spec).
|
|
44
|
+
[key: string]: any
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// A stateful object that can be installed in an editor by a
|
|
48
|
+
/// [plugin](#state.PluginSpec.view).
|
|
49
|
+
export type PluginView = {
|
|
50
|
+
/// Called whenever the view's state is updated.
|
|
51
|
+
update?: (view: EditorView, prevState: EditorState) => void
|
|
52
|
+
|
|
53
|
+
/// Called when the view is destroyed or receives a state
|
|
54
|
+
/// with different plugins.
|
|
55
|
+
destroy?: () => void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function bindProps(obj: {[prop: string]: any}, self: any, target: {[prop: string]: any}) {
|
|
59
|
+
for (let prop in obj) {
|
|
60
|
+
let val = obj[prop]
|
|
61
|
+
if (val instanceof Function) val = val.bind(self)
|
|
62
|
+
else if (prop == "handleDOMEvents") val = bindProps(val, self, {})
|
|
63
|
+
target[prop] = val
|
|
64
|
+
}
|
|
65
|
+
return target
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// Plugins bundle functionality that can be added to an editor.
|
|
69
|
+
/// They are part of the [editor state](#state.EditorState) and
|
|
70
|
+
/// may influence that state and the view that contains it.
|
|
71
|
+
export class Plugin<PluginState = any> {
|
|
72
|
+
/// Create a plugin.
|
|
73
|
+
constructor(
|
|
74
|
+
/// The plugin's [spec object](#state.PluginSpec).
|
|
75
|
+
readonly spec: PluginSpec<PluginState>
|
|
76
|
+
) {
|
|
77
|
+
if (spec.props) bindProps(spec.props, this, this.props)
|
|
78
|
+
this.key = spec.key ? spec.key.key : createKey("plugin")
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// The [props](#view.EditorProps) exported by this plugin.
|
|
82
|
+
readonly props: EditorProps<Plugin<PluginState>> = {}
|
|
83
|
+
|
|
84
|
+
/// @internal
|
|
85
|
+
key: string
|
|
86
|
+
|
|
87
|
+
/// Extract the plugin's state field from an editor state.
|
|
88
|
+
getState(state: EditorState): PluginState | undefined { return (state as any)[this.key] }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// A plugin spec may provide a state field (under its
|
|
92
|
+
/// [`state`](#state.PluginSpec.state) property) of this type, which
|
|
93
|
+
/// describes the state it wants to keep. Functions provided here are
|
|
94
|
+
/// always called with the plugin instance as their `this` binding.
|
|
95
|
+
export interface StateField<T> {
|
|
96
|
+
/// Initialize the value of the field. `config` will be the object
|
|
97
|
+
/// passed to [`EditorState.create`](#state.EditorState^create). Note
|
|
98
|
+
/// that `instance` is a half-initialized state instance, and will
|
|
99
|
+
/// not have values for plugin fields initialized after this one.
|
|
100
|
+
init: (config: EditorStateConfig, instance: EditorState) => T
|
|
101
|
+
|
|
102
|
+
/// Apply the given transaction to this state field, producing a new
|
|
103
|
+
/// field value. Note that the `newState` argument is again a partially
|
|
104
|
+
/// constructed state does not yet contain the state from plugins
|
|
105
|
+
/// coming after this one.
|
|
106
|
+
apply: (tr: Transaction, value: T, oldState: EditorState, newState: EditorState) => T
|
|
107
|
+
|
|
108
|
+
/// Convert this field to JSON. Optional, can be left off to disable
|
|
109
|
+
/// JSON serialization for the field.
|
|
110
|
+
toJSON?: (value: T) => any
|
|
111
|
+
|
|
112
|
+
/// Deserialize the JSON representation of this field. Note that the
|
|
113
|
+
/// `state` argument is again a half-initialized state.
|
|
114
|
+
fromJSON?: (config: EditorStateConfig, value: any, state: EditorState) => T
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const keys = Object.create(null)
|
|
118
|
+
|
|
119
|
+
function createKey(name: string) {
|
|
120
|
+
if (name in keys) return name + "$" + ++keys[name]
|
|
121
|
+
keys[name] = 0
|
|
122
|
+
return name + "$"
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// A key is used to [tag](#state.PluginSpec.key) plugins in a way
|
|
126
|
+
/// that makes it possible to find them, given an editor state.
|
|
127
|
+
/// Assigning a key does mean only one plugin of that type can be
|
|
128
|
+
/// active in a state.
|
|
129
|
+
export class PluginKey<PluginState = any> {
|
|
130
|
+
/// @internal
|
|
131
|
+
key: string
|
|
132
|
+
|
|
133
|
+
/// Create a plugin key.
|
|
134
|
+
constructor(name = "key") { this.key = createKey(name) }
|
|
135
|
+
|
|
136
|
+
/// Get the active plugin with this key, if any, from an editor
|
|
137
|
+
/// state.
|
|
138
|
+
get(state: EditorState): Plugin<PluginState> | undefined { return state.config.pluginsByKey[this.key] }
|
|
139
|
+
|
|
140
|
+
/// Get the plugin's state from an editor state.
|
|
141
|
+
getState(state: EditorState): PluginState | undefined { return (state as any)[this.key] }
|
|
142
|
+
}
|