prosemirror-menu 1.3.0-beta.1 → 1.3.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 +42 -0
- package/LICENSE +1 -1
- package/README.md +65 -25
- package/dist/index.cjs +296 -218
- package/dist/index.d.cts +281 -0
- package/dist/index.d.ts +31 -16
- package/dist/index.js +256 -53
- package/package.json +8 -5
- package/src/README.md +29 -0
- package/src/icons.ts +16 -13
- package/src/menu.ts +199 -45
- package/src/menubar.ts +61 -7
- package/style/menu.css +28 -7
- package/dist/index.es.js +0 -639
- package/dist/index.es.js.map +0 -1
- package/dist/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
+
## 1.3.0 (2026-02-17)
|
|
2
|
+
|
|
3
|
+
### New features
|
|
4
|
+
|
|
5
|
+
The menu elements and menu bar now support keyboard navigation and use ARIA attributes for improved accessibility.
|
|
6
|
+
|
|
7
|
+
## 1.2.5 (2025-04-22)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Make sure the menu is re-rendered when the editor's root changes, so that it doesn't reference icons whose SVG lives in another root.
|
|
12
|
+
|
|
13
|
+
## 1.2.4 (2023-08-20)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Fix a bug where icon creation crashed because it couldn't find a Document value.
|
|
18
|
+
|
|
19
|
+
## 1.2.3 (2023-08-16)
|
|
20
|
+
|
|
21
|
+
### Bug fixes
|
|
22
|
+
|
|
23
|
+
Don't directly use the global `window`/`document`, to fix use in a different frame or shadow root.
|
|
24
|
+
|
|
25
|
+
## 1.2.2 (2023-05-17)
|
|
26
|
+
|
|
27
|
+
### Bug fixes
|
|
28
|
+
|
|
29
|
+
Include CommonJS type declarations in the package to please new TypeScript resolution settings.
|
|
30
|
+
|
|
31
|
+
## 1.2.1 (2022-06-22)
|
|
32
|
+
|
|
33
|
+
### Bug fixes
|
|
34
|
+
|
|
35
|
+
Export CSS file from package.json.
|
|
36
|
+
|
|
37
|
+
## 1.2.0 (2022-05-30)
|
|
38
|
+
|
|
39
|
+
### New features
|
|
40
|
+
|
|
41
|
+
Include TypeScript type declarations.
|
|
42
|
+
|
|
1
43
|
## 1.1.4 (2020-03-12)
|
|
2
44
|
|
|
3
45
|
### Bug fixes
|
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (C) 2015-2017 by Marijn Haverbeke <
|
|
1
|
+
Copyright (C) 2015-2017 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -40,13 +40,15 @@ The types defined in this module aren't the only thing you can
|
|
|
40
40
|
display in your menu. Anything that conforms to this interface can
|
|
41
41
|
be put into a menu structure.
|
|
42
42
|
|
|
43
|
-
* **`render`**`(pm: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}`\
|
|
43
|
+
* **`render`**`(pm: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean, focusable?: HTMLElement}`\
|
|
44
44
|
Render the element for display in the menu. Must return a DOM
|
|
45
45
|
element and a function that can be used to update the element to
|
|
46
46
|
a new state. The `update` function must return false if the
|
|
47
|
-
update hid the entire element.
|
|
47
|
+
update hid the entire element. May also return a `focusable`
|
|
48
|
+
DOM node, which is the node that should receive focus when this
|
|
49
|
+
element is focused. If not provided, the `dom` element will be used.
|
|
48
50
|
|
|
49
|
-
### class MenuItem
|
|
51
|
+
### class MenuItem`<E extends HTMLElement = HTMLButtonElement>`
|
|
50
52
|
|
|
51
53
|
implements `MenuElement`An icon or label that, when clicked, executes a command.
|
|
52
54
|
|
|
@@ -56,56 +58,56 @@ be put into a menu structure.
|
|
|
56
58
|
* **`spec`**`: MenuItemSpec`\
|
|
57
59
|
The spec used to create this item.
|
|
58
60
|
|
|
59
|
-
* **`render`**`(view: EditorView) → {dom:
|
|
61
|
+
* **`render`**`(view: EditorView) → {dom: E | HTMLButtonElement, update: fn(state: EditorState) → boolean}`\
|
|
60
62
|
Renders the icon according to its [display
|
|
61
63
|
spec](#menu.MenuItemSpec.display), and adds an event handler which
|
|
62
64
|
executes the command when the representation is clicked.
|
|
63
65
|
|
|
64
|
-
### interface MenuItemSpec
|
|
66
|
+
### interface MenuItemSpec`<E extends HTMLElement = HTMLButtonElement>`
|
|
65
67
|
|
|
66
68
|
The configuration object passed to the `MenuItem` constructor.
|
|
67
69
|
|
|
68
70
|
* **`run`**`(state: EditorState, dispatch: fn(tr: Transaction), view: EditorView, event: Event)`\
|
|
69
71
|
The function to execute when the menu item is activated.
|
|
70
72
|
|
|
71
|
-
* **`select
|
|
73
|
+
* **`select`**`?: fn(state: EditorState) → boolean`\
|
|
72
74
|
Optional function that is used to determine whether the item is
|
|
73
75
|
appropriate at the moment. Deselected items will be hidden.
|
|
74
76
|
|
|
75
|
-
* **`enable
|
|
77
|
+
* **`enable`**`?: fn(state: EditorState) → boolean`\
|
|
76
78
|
Function that is used to determine if the item is enabled. If
|
|
77
79
|
given and returning false, the item will be given a disabled
|
|
78
80
|
styling.
|
|
79
81
|
|
|
80
|
-
* **`active
|
|
82
|
+
* **`active`**`?: fn(state: EditorState) → boolean`\
|
|
81
83
|
A predicate function to determine whether the item is 'active' (for
|
|
82
84
|
example, the item for toggling the strong mark might be active then
|
|
83
85
|
the cursor is in strong text).
|
|
84
86
|
|
|
85
|
-
* **`render
|
|
87
|
+
* **`render`**`?: fn(view: EditorView) → E`\
|
|
86
88
|
A function that renders the item. You must provide either this,
|
|
87
89
|
[`icon`](#menu.MenuItemSpec.icon), or [`label`](#MenuItemSpec.label).
|
|
88
90
|
|
|
89
|
-
* **`icon
|
|
91
|
+
* **`icon`**`?: IconSpec`\
|
|
90
92
|
Describes an icon to show for this item.
|
|
91
93
|
|
|
92
|
-
* **`label
|
|
94
|
+
* **`label`**`?: string`\
|
|
93
95
|
Makes the item show up as a text label. Mostly useful for items
|
|
94
96
|
wrapped in a [drop-down](#menu.Dropdown) or similar menu. The object
|
|
95
97
|
should have a `label` property providing the text to display.
|
|
96
98
|
|
|
97
|
-
* **`title
|
|
99
|
+
* **`title`**`?: string | fn(state: EditorState) → string`\
|
|
98
100
|
Defines DOM title (mouseover) text for the item.
|
|
99
101
|
|
|
100
|
-
* **`class
|
|
102
|
+
* **`class`**`?: string`\
|
|
101
103
|
Optionally adds a CSS class to the item's DOM representation.
|
|
102
104
|
|
|
103
|
-
* **`css
|
|
105
|
+
* **`css`**`?: string`\
|
|
104
106
|
Optionally adds a string of inline CSS to the item's DOM
|
|
105
107
|
representation.
|
|
106
108
|
|
|
107
109
|
* type **`IconSpec`**
|
|
108
|
-
` = {path: string, width: number, height: number} | {text: string, css?:
|
|
110
|
+
` = {path: string, width: number, height: number} | {text: string, css?: string} | {dom: Node}`\
|
|
109
111
|
Specifies an icon. May be either an SVG icon, in which case its
|
|
110
112
|
`path` property should be an [SVG path
|
|
111
113
|
spec](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d),
|
|
@@ -120,28 +122,68 @@ The configuration object passed to the `MenuItem` constructor.
|
|
|
120
122
|
implements `MenuElement`A drop-down menu, displayed as a label with a downwards-pointing
|
|
121
123
|
triangle to the right of it.
|
|
122
124
|
|
|
123
|
-
* `new `**`Dropdown`**`(content: readonly MenuElement[] | MenuElement, options
|
|
125
|
+
* `new `**`Dropdown`**`(content: readonly MenuElement[] | MenuElement, options?: Object = {})`\
|
|
124
126
|
Create a dropdown wrapping the elements.
|
|
125
127
|
|
|
126
|
-
|
|
128
|
+
* **`options`**`?: Object`
|
|
129
|
+
|
|
130
|
+
* **`label`**`?: string`\
|
|
131
|
+
The label to show on the drop-down control.
|
|
132
|
+
|
|
133
|
+
* **`title`**`?: string`\
|
|
134
|
+
Sets the
|
|
135
|
+
[`title`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title)
|
|
136
|
+
attribute given to the menu control.
|
|
137
|
+
|
|
138
|
+
* **`class`**`?: string`\
|
|
139
|
+
When given, adds an extra CSS class to the menu control.
|
|
140
|
+
|
|
141
|
+
* **`css`**`?: string`\
|
|
142
|
+
When given, adds an extra set of CSS styles to the menu control.
|
|
143
|
+
|
|
144
|
+
* **`render`**`(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean, focusable: HTMLElement}`\
|
|
127
145
|
Render the dropdown menu and sub-items.
|
|
128
146
|
|
|
147
|
+
* **`setFocusIndex`**`(index: number)`
|
|
148
|
+
|
|
129
149
|
### class DropdownSubmenu
|
|
130
150
|
|
|
131
151
|
implements `MenuElement`Represents a submenu wrapping a group of elements that start
|
|
132
152
|
hidden and expand to the right when hovered over or tapped.
|
|
133
153
|
|
|
134
|
-
* `new `**`DropdownSubmenu`**`(content: readonly MenuElement[] | MenuElement, options
|
|
154
|
+
* `new `**`DropdownSubmenu`**`(content: readonly MenuElement[] | MenuElement, options?: Object = {})`\
|
|
135
155
|
Creates a submenu for the given group of menu elements. The
|
|
136
156
|
following options are recognized:
|
|
137
157
|
|
|
138
|
-
|
|
158
|
+
* **`options`**`?: Object`
|
|
159
|
+
|
|
160
|
+
* **`label`**`?: string`\
|
|
161
|
+
The label to show on the submenu.
|
|
162
|
+
|
|
163
|
+
* **`render`**`(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean, focusable: HTMLElement}`\
|
|
139
164
|
Renders the submenu.
|
|
140
165
|
|
|
166
|
+
* **`setFocusIndex`**`(index: number)`
|
|
167
|
+
|
|
141
168
|
* **`menuBar`**`(options: Object) → Plugin`\
|
|
142
169
|
A plugin that will place a menu bar above the editor. Note that
|
|
143
170
|
this involves wrapping the editor in an additional `<div>`.
|
|
144
171
|
|
|
172
|
+
* **`options`**`: Object`
|
|
173
|
+
|
|
174
|
+
* **`content`**`: readonly readonly MenuElement[][]`\
|
|
175
|
+
Provides the content of the menu, as a nested array to be
|
|
176
|
+
passed to `renderGrouped`.
|
|
177
|
+
|
|
178
|
+
* **`position`**`?: "before" | "after"`\
|
|
179
|
+
Determines whether the menu is placed before or after the editor in the DOM.
|
|
180
|
+
The default is "before".
|
|
181
|
+
|
|
182
|
+
* **`floating`**`?: boolean`\
|
|
183
|
+
Determines whether the menu floats, i.e. whether it sticks to
|
|
184
|
+
the top of the viewport when the editor is partially scrolled
|
|
185
|
+
out of view.
|
|
186
|
+
|
|
145
187
|
|
|
146
188
|
This module exports the following pre-built items or item
|
|
147
189
|
constructors:
|
|
@@ -161,13 +203,13 @@ constructors:
|
|
|
161
203
|
* **`redoItem`**`: MenuItem`\
|
|
162
204
|
Menu item for the `redo` command.
|
|
163
205
|
|
|
164
|
-
* **`wrapItem`**`(nodeType: NodeType, options: Partial & {attrs?:
|
|
206
|
+
* **`wrapItem`**`(nodeType: NodeType, options: Partial & {attrs?: Attrs}) → MenuItem`\
|
|
165
207
|
Build a menu item for wrapping the selection in a given node type.
|
|
166
208
|
Adds `run` and `select` properties to the ones present in
|
|
167
209
|
`options`. `options.attrs` may be an object that provides
|
|
168
210
|
attributes for the wrapping node.
|
|
169
211
|
|
|
170
|
-
* **`blockTypeItem`**`(nodeType: NodeType, options: Partial & {attrs?:
|
|
212
|
+
* **`blockTypeItem`**`(nodeType: NodeType, options: Partial & {attrs?: Attrs}) → MenuItem`\
|
|
171
213
|
Build a menu item for changing the type of the textblock around the
|
|
172
214
|
selection to the given type. Provides `run`, `active`, and `select`
|
|
173
215
|
properties. Others must be given in `options`. `options.attrs` may
|
|
@@ -184,12 +226,10 @@ To construct your own items, these icons may be useful:
|
|
|
184
226
|
`MenuItem`.
|
|
185
227
|
|
|
186
228
|
|
|
187
|
-
* **`renderGrouped`**`(view: EditorView, content: readonly readonly MenuElement[][]) → {`\
|
|
188
|
-
` dom: DocumentFragment,`\
|
|
189
|
-
` update: fn(state: EditorState) → boolean`\
|
|
190
|
-
`}`\
|
|
229
|
+
* **`renderGrouped`**`(view: EditorView, content: readonly readonly MenuElement[][]) → {dom: DocumentFragment, update: fn(state: EditorState) → boolean, focusables: HTMLElement[]}`\
|
|
191
230
|
Render the given, possibly nested, array of menu elements into a
|
|
192
231
|
document fragment, placing separators between them (and ensuring no
|
|
193
232
|
superfluous separators appear when some of the groups turn out to
|
|
194
233
|
be empty).
|
|
195
234
|
|
|
235
|
+
|