prosemirror-menu 1.1.2 → 1.2.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/CHANGELOG.md +18 -0
- package/README.md +49 -71
- package/dist/index.cjs +720 -0
- package/dist/index.d.ts +266 -0
- package/dist/index.es.js +21 -24
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +534 -602
- package/dist/index.js.map +1 -1
- package/package.json +13 -9
- package/src/README.md +8 -0
- package/src/{icons.js → icons.ts} +18 -14
- package/src/index.ts +4 -0
- package/src/{menu.js → menu.ts} +189 -176
- package/src/{menubar.js → menubar.ts} +49 -48
- package/rollup.config.js +0 -14
- package/src/index.js +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 1.2.0 (2022-05-30)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
Include TypeScript type declarations.
|
|
6
|
+
|
|
7
|
+
## 1.1.4 (2020-03-12)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Restore compatibility with IE11.
|
|
12
|
+
|
|
13
|
+
## 1.1.3 (2020-03-04)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Update crel dependency to a version that exposes an ES module.
|
|
18
|
+
|
|
1
19
|
## 1.1.2 (2019-12-02)
|
|
2
20
|
|
|
3
21
|
### Bug fixes
|
package/README.md
CHANGED
|
@@ -27,8 +27,12 @@ is the place to report issues.
|
|
|
27
27
|
|
|
28
28
|
## Documentation
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
This module defines a number of building blocks for ProseMirror menus,
|
|
31
|
+
along with a [menu bar](#menu.menuBar) implementation.
|
|
32
|
+
|
|
33
|
+
When using this module, you should make sure its
|
|
34
|
+
[`style/menu.css`](https://github.com/ProseMirror/prosemirror-menu/blob/master/style/menu.css)
|
|
35
|
+
file is loaded into your page.
|
|
32
36
|
|
|
33
37
|
### interface MenuElement
|
|
34
38
|
|
|
@@ -36,22 +40,23 @@ The types defined in this module aren't the only thing you can
|
|
|
36
40
|
display in your menu. Anything that conforms to this interface can
|
|
37
41
|
be put into a menu structure.
|
|
38
42
|
|
|
39
|
-
* **`render`**`(pm: EditorView) → {dom:
|
|
43
|
+
* **`render`**`(pm: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}`\
|
|
40
44
|
Render the element for display in the menu. Must return a DOM
|
|
41
45
|
element and a function that can be used to update the element to
|
|
42
|
-
a new state. The `update` function
|
|
46
|
+
a new state. The `update` function must return false if the
|
|
43
47
|
update hid the entire element.
|
|
44
48
|
|
|
45
49
|
### class MenuItem
|
|
46
50
|
|
|
47
|
-
An icon or label that, when clicked, executes a command.
|
|
51
|
+
implements `MenuElement`An icon or label that, when clicked, executes a command.
|
|
48
52
|
|
|
49
|
-
* `new `**`MenuItem`**`(spec: MenuItemSpec)
|
|
53
|
+
* `new `**`MenuItem`**`(spec: MenuItemSpec)`\
|
|
54
|
+
Create a menu item.
|
|
50
55
|
|
|
51
56
|
* **`spec`**`: MenuItemSpec`\
|
|
52
|
-
The spec used to create
|
|
57
|
+
The spec used to create this item.
|
|
53
58
|
|
|
54
|
-
* **`render`**`(view: EditorView) → {dom:
|
|
59
|
+
* **`render`**`(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}`\
|
|
55
60
|
Renders the icon according to its [display
|
|
56
61
|
spec](#menu.MenuItemSpec.display), and adds an event handler which
|
|
57
62
|
executes the command when the representation is clicked.
|
|
@@ -60,115 +65,83 @@ An icon or label that, when clicked, executes a command.
|
|
|
60
65
|
|
|
61
66
|
The configuration object passed to the `MenuItem` constructor.
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
* **`run`**`(EditorState, fn(Transaction), EditorView, dom.Event)`\
|
|
68
|
+
* **`run`**`(state: EditorState, dispatch: fn(tr: Transaction), view: EditorView, event: Event)`\
|
|
65
69
|
The function to execute when the menu item is activated.
|
|
66
70
|
|
|
67
|
-
* **`select`**`: ?fn(EditorState) →
|
|
71
|
+
* **`select`**`: ?fn(state: EditorState) → boolean`\
|
|
68
72
|
Optional function that is used to determine whether the item is
|
|
69
73
|
appropriate at the moment. Deselected items will be hidden.
|
|
70
74
|
|
|
71
|
-
* **`enable`**`: ?fn(EditorState) →
|
|
75
|
+
* **`enable`**`: ?fn(state: EditorState) → boolean`\
|
|
72
76
|
Function that is used to determine if the item is enabled. If
|
|
73
77
|
given and returning false, the item will be given a disabled
|
|
74
78
|
styling.
|
|
75
79
|
|
|
76
|
-
* **`active`**`: ?fn(EditorState) →
|
|
80
|
+
* **`active`**`: ?fn(state: EditorState) → boolean`\
|
|
77
81
|
A predicate function to determine whether the item is 'active' (for
|
|
78
82
|
example, the item for toggling the strong mark might be active then
|
|
79
83
|
the cursor is in strong text).
|
|
80
84
|
|
|
81
|
-
* **`render`**`: ?fn(EditorView) →
|
|
85
|
+
* **`render`**`: ?fn(view: EditorView) → HTMLElement`\
|
|
82
86
|
A function that renders the item. You must provide either this,
|
|
83
87
|
[`icon`](#menu.MenuItemSpec.icon), or [`label`](#MenuItemSpec.label).
|
|
84
88
|
|
|
85
|
-
* **`icon`**`: ?
|
|
86
|
-
Describes an icon to show for this item.
|
|
87
|
-
an SVG icon, in which case its `path` property should be an [SVG
|
|
88
|
-
path
|
|
89
|
-
spec](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d),
|
|
90
|
-
and `width` and `height` should provide the viewbox in which that
|
|
91
|
-
path exists. Alternatively, it may have a `text` property
|
|
92
|
-
specifying a string of text that makes up the icon, with an
|
|
93
|
-
optional `css` property giving additional CSS styling for the
|
|
94
|
-
text. _Or_ it may contain `dom` property containing a DOM node.
|
|
89
|
+
* **`icon`**`: ?IconSpec`\
|
|
90
|
+
Describes an icon to show for this item.
|
|
95
91
|
|
|
96
92
|
* **`label`**`: ?string`\
|
|
97
93
|
Makes the item show up as a text label. Mostly useful for items
|
|
98
94
|
wrapped in a [drop-down](#menu.Dropdown) or similar menu. The object
|
|
99
95
|
should have a `label` property providing the text to display.
|
|
100
96
|
|
|
101
|
-
* **`title`**`: ?string | fn(EditorState) → string`\
|
|
97
|
+
* **`title`**`: ?string | fn(state: EditorState) → string`\
|
|
102
98
|
Defines DOM title (mouseover) text for the item.
|
|
103
99
|
|
|
104
|
-
* **`class`**`: string`\
|
|
100
|
+
* **`class`**`: ?string`\
|
|
105
101
|
Optionally adds a CSS class to the item's DOM representation.
|
|
106
102
|
|
|
107
|
-
* **`css`**`: string`\
|
|
103
|
+
* **`css`**`: ?string`\
|
|
108
104
|
Optionally adds a string of inline CSS to the item's DOM
|
|
109
105
|
representation.
|
|
110
106
|
|
|
111
|
-
* **`
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
* type **`IconSpec`**
|
|
108
|
+
` = {path: string, width: number, height: number} | {text: string, css?: ?string} | {dom: Node}`\
|
|
109
|
+
Specifies an icon. May be either an SVG icon, in which case its
|
|
110
|
+
`path` property should be an [SVG path
|
|
111
|
+
spec](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d),
|
|
112
|
+
and `width` and `height` should provide the viewbox in which that
|
|
113
|
+
path exists. Alternatively, it may have a `text` property
|
|
114
|
+
specifying a string of text that makes up the icon, with an
|
|
115
|
+
optional `css` property giving additional CSS styling for the
|
|
116
|
+
text. _Or_ it may contain `dom` property containing a DOM node.
|
|
114
117
|
|
|
115
118
|
### class Dropdown
|
|
116
119
|
|
|
117
|
-
A drop-down menu, displayed as a label with a downwards-pointing
|
|
120
|
+
implements `MenuElement`A drop-down menu, displayed as a label with a downwards-pointing
|
|
118
121
|
triangle to the right of it.
|
|
119
122
|
|
|
120
|
-
* `new `**`Dropdown`**`(content: [MenuElement
|
|
121
|
-
Create a dropdown wrapping the elements.
|
|
122
|
-
the following properties:
|
|
123
|
-
|
|
124
|
-
**`label`**`: string`
|
|
125
|
-
: The label to show on the drop-down control.
|
|
126
|
-
|
|
127
|
-
**`title`**`: string`
|
|
128
|
-
: Sets the
|
|
129
|
-
[`title`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title)
|
|
130
|
-
attribute given to the menu control.
|
|
131
|
-
|
|
132
|
-
**`class`**`: string`
|
|
133
|
-
: When given, adds an extra CSS class to the menu control.
|
|
134
|
-
|
|
135
|
-
**`css`**`: string`
|
|
136
|
-
: When given, adds an extra set of CSS styles to the menu control.
|
|
123
|
+
* `new `**`Dropdown`**`(content: readonly MenuElement[] | MenuElement, options: ?Object = {})`\
|
|
124
|
+
Create a dropdown wrapping the elements.
|
|
137
125
|
|
|
138
|
-
* **`render`**`(view: EditorView) → {dom:
|
|
126
|
+
* **`render`**`(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}`\
|
|
139
127
|
Render the dropdown menu and sub-items.
|
|
140
128
|
|
|
141
129
|
### class DropdownSubmenu
|
|
142
130
|
|
|
143
|
-
Represents a submenu wrapping a group of elements that start
|
|
131
|
+
implements `MenuElement`Represents a submenu wrapping a group of elements that start
|
|
144
132
|
hidden and expand to the right when hovered over or tapped.
|
|
145
133
|
|
|
146
|
-
* `new `**`DropdownSubmenu`**`(content: [MenuElement
|
|
134
|
+
* `new `**`DropdownSubmenu`**`(content: readonly MenuElement[] | MenuElement, options: ?Object = {})`\
|
|
147
135
|
Creates a submenu for the given group of menu elements. The
|
|
148
136
|
following options are recognized:
|
|
149
137
|
|
|
150
|
-
|
|
151
|
-
: The label to show on the submenu.
|
|
152
|
-
|
|
153
|
-
* **`render`**`(view: EditorView) → {dom: dom.Node, update: fn(EditorState) → bool}`\
|
|
138
|
+
* **`render`**`(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}`\
|
|
154
139
|
Renders the submenu.
|
|
155
140
|
|
|
156
141
|
* **`menuBar`**`(options: Object) → Plugin`\
|
|
157
142
|
A plugin that will place a menu bar above the editor. Note that
|
|
158
143
|
this involves wrapping the editor in an additional `<div>`.
|
|
159
144
|
|
|
160
|
-
* **`options`**`: Object`\
|
|
161
|
-
Supports the following options:
|
|
162
|
-
|
|
163
|
-
* **`content`**`: [[MenuElement]]`\
|
|
164
|
-
Provides the content of the menu, as a nested array to be
|
|
165
|
-
passed to `renderGrouped`.
|
|
166
|
-
|
|
167
|
-
* **`floating`**`: ?bool`\
|
|
168
|
-
Determines whether the menu floats, i.e. whether it sticks to
|
|
169
|
-
the top of the viewport when the editor is partially scrolled
|
|
170
|
-
out of view.
|
|
171
|
-
|
|
172
145
|
|
|
173
146
|
This module exports the following pre-built items or item
|
|
174
147
|
constructors:
|
|
@@ -188,12 +161,13 @@ constructors:
|
|
|
188
161
|
* **`redoItem`**`: MenuItem`\
|
|
189
162
|
Menu item for the `redo` command.
|
|
190
163
|
|
|
191
|
-
* **`wrapItem`**`(nodeType: NodeType, options:
|
|
164
|
+
* **`wrapItem`**`(nodeType: NodeType, options: Partial & {attrs?: ?Attrs}) → MenuItem`\
|
|
192
165
|
Build a menu item for wrapping the selection in a given node type.
|
|
193
166
|
Adds `run` and `select` properties to the ones present in
|
|
194
|
-
`options`. `options.attrs` may be an object
|
|
167
|
+
`options`. `options.attrs` may be an object that provides
|
|
168
|
+
attributes for the wrapping node.
|
|
195
169
|
|
|
196
|
-
* **`blockTypeItem`**`(nodeType: NodeType, options:
|
|
170
|
+
* **`blockTypeItem`**`(nodeType: NodeType, options: Partial & {attrs?: ?Attrs}) → MenuItem`\
|
|
197
171
|
Build a menu item for changing the type of the textblock around the
|
|
198
172
|
selection to the given type. Provides `run`, `active`, and `select`
|
|
199
173
|
properties. Others must be given in `options`. `options.attrs` may
|
|
@@ -210,8 +184,12 @@ To construct your own items, these icons may be useful:
|
|
|
210
184
|
`MenuItem`.
|
|
211
185
|
|
|
212
186
|
|
|
213
|
-
* **`renderGrouped`**`(view: EditorView, content:
|
|
187
|
+
* **`renderGrouped`**`(view: EditorView, content: readonly readonly MenuElement[][]) → {`\
|
|
188
|
+
` dom: DocumentFragment,`\
|
|
189
|
+
` update: fn(state: EditorState) → boolean`\
|
|
190
|
+
`}`\
|
|
214
191
|
Render the given, possibly nested, array of menu elements into a
|
|
215
192
|
document fragment, placing separators between them (and ensuring no
|
|
216
193
|
superfluous separators appear when some of the groups turn out to
|
|
217
194
|
be empty).
|
|
195
|
+
|