prosemirror-menu 1.3.0-beta.1 → 1.3.1

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 CHANGED
@@ -1,3 +1,51 @@
1
+ ## 1.3.1 (2026-04-15)
2
+
3
+ ### Bug fixes
4
+
5
+ Move focus to button before closing a submenu, to avoid focus moving back to the document root.
6
+
7
+ ## 1.3.0 (2026-02-17)
8
+
9
+ ### New features
10
+
11
+ The menu elements and menu bar now support keyboard navigation and use ARIA attributes for improved accessibility.
12
+
13
+ ## 1.2.5 (2025-04-22)
14
+
15
+ ### Bug fixes
16
+
17
+ 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.
18
+
19
+ ## 1.2.4 (2023-08-20)
20
+
21
+ ### Bug fixes
22
+
23
+ Fix a bug where icon creation crashed because it couldn't find a Document value.
24
+
25
+ ## 1.2.3 (2023-08-16)
26
+
27
+ ### Bug fixes
28
+
29
+ Don't directly use the global `window`/`document`, to fix use in a different frame or shadow root.
30
+
31
+ ## 1.2.2 (2023-05-17)
32
+
33
+ ### Bug fixes
34
+
35
+ Include CommonJS type declarations in the package to please new TypeScript resolution settings.
36
+
37
+ ## 1.2.1 (2022-06-22)
38
+
39
+ ### Bug fixes
40
+
41
+ Export CSS file from package.json.
42
+
43
+ ## 1.2.0 (2022-05-30)
44
+
45
+ ### New features
46
+
47
+ Include TypeScript type declarations.
48
+
1
49
  ## 1.1.4 (2020-03-12)
2
50
 
3
51
  ### Bug fixes
package/CONTRIBUTING.md CHANGED
@@ -12,7 +12,7 @@ Community discussion, questions, and informal bug reporting is done on the
12
12
  ## Submitting bug reports
13
13
 
14
14
  Report bugs on the
15
- [GitHub issue tracker](http://github.com/prosemirror/prosemirror/issues).
15
+ [issue tracker](https://code.haverbeke.berlin/prosemirror/prosemirror/issues).
16
16
  Before reporting a bug, please read these pointers.
17
17
 
18
18
  - The issue tracker is for *bugs*, not requests for help. Questions
@@ -34,21 +34,28 @@ Before reporting a bug, please read these pointers.
34
34
 
35
35
  ## Contributing code
36
36
 
37
- - Make sure you have a [GitHub Account](https://github.com/signup/free)
37
+ Code generated by a language model is not welcome in this project.
38
+ Please don't waste my time with it.
38
39
 
39
- - Fork the relevant repository
40
- ([how to fork a repo](https://help.github.com/articles/fork-a-repo))
40
+ If you want to make a change that involves a significant overhaul of
41
+ the code or introduces a user-visible new feature, create an
42
+ [issue](https://code.haverbeke.berlin/prosemirror/prosemirror/issues/)
43
+ first with your proposal.
44
+
45
+ - Make sure you have a [Codeberg](https://codeberg.org/user/sign_up)
46
+ or [GitHub](https://github.com/signup/free) account.
47
+
48
+ - Use that to create a [code.haverbeke.berlin
49
+ account](https://code.haverbeke.berlin/user/login).
50
+
51
+ - Fork the relevant repository.
41
52
 
42
53
  - Create a local checkout of the code. You can use the
43
- [main repository](https://github.com/prosemirror/prosemirror) to
54
+ [main repository](https://code.haverbeke.berlin/prosemirror/prosemirror) to
44
55
  easily check out all core modules.
45
56
 
46
57
  - Make your changes, and commit them
47
58
 
48
- - Follow the code style of the rest of the project (see below). Run
49
- `npm run lint` (in the main repository checkout) to make sure that
50
- the linter is happy.
51
-
52
59
  - If your changes are easy to test or likely to regress, add tests in
53
60
  the relevant `test/` directory. Either put them in an existing
54
61
  `test-*.js` file, if they fit there, or add a new file.
@@ -56,13 +63,13 @@ Before reporting a bug, please read these pointers.
56
63
  - Make sure all tests pass. Run `npm run test` to verify tests pass
57
64
  (you will need Node.js v6+).
58
65
 
59
- - Submit a pull request ([how to create a pull request](https://help.github.com/articles/fork-a-repo)).
60
- Don't put more than one feature/fix in a single pull request.
66
+ - Submit a pull request. Don't put more than one feature/fix in a
67
+ single pull request.
61
68
 
62
69
  By contributing code to ProseMirror you
63
70
 
64
71
  - Agree to license the contributed code under the project's [MIT
65
- license](https://github.com/ProseMirror/prosemirror/blob/master/LICENSE).
72
+ license](https://code.haverbeke.berlin/prosemirror/prosemirror/blob/main/LICENSE).
66
73
 
67
74
  - Confirm that you have the right to contribute and license the code
68
75
  in question. (Either you hold all rights on the code, or the rights
@@ -82,19 +89,16 @@ By contributing code to ProseMirror you
82
89
  - Follow the surrounding code when it comes to spacing, brace
83
90
  placement, etc.
84
91
 
85
- - Brace-less single-statement bodies are encouraged (whenever they
86
- don't impact readability).
92
+ - Brace-less single-statement bodies are encouraged whenever they
93
+ don't impact readability.
87
94
 
88
- - [getdocs](https://github.com/marijnh/getdocs)-style doc comments
95
+ - [getdocs-ts](https://code.haverbeke.berlin/marijn/getdocs-ts)-style doc comments
89
96
  above items that are part of the public API.
90
97
 
91
98
  - When documenting non-public items, you can put the type after a
92
99
  single colon, so that getdocs doesn't pick it up and add it to the
93
100
  API reference.
94
101
 
95
- - The linter (`npm run lint`) complains about unused variables and
96
- functions. Prefix their names with an underscore to muffle it.
97
-
98
102
  - ProseMirror does *not* follow JSHint or JSLint prescribed style.
99
103
  Patches that try to 'fix' code to pass one of these linters will not
100
104
  be accepted.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2015-2017 by Marijn Haverbeke <marijnh@gmail.com> and others
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
@@ -1,6 +1,6 @@
1
1
  # prosemirror-menu
2
2
 
3
- [ [**WEBSITE**](https://prosemirror.net) | [**ISSUES**](https://github.com/prosemirror/prosemirror-menu/issues) | [**FORUM**](https://discuss.prosemirror.net) | [**GITTER**](https://gitter.im/ProseMirror/prosemirror) ]
3
+ [ [**WEBSITE**](https://prosemirror.net) | [**ISSUES**](https://code.haverbeke.berlin/prosemirror/prosemirror-menu/issues) | [**FORUM**](https://discuss.prosemirror.net) | [**GITTER**](https://gitter.im/ProseMirror/prosemirror) ]
4
4
 
5
5
  This is a non-core example module for [ProseMirror](https://prosemirror.net).
6
6
  ProseMirror is a well-behaved rich semantic content editor based on
@@ -19,10 +19,10 @@ ProseMirror, publish your fork, and if it works for me, I'll gladly
19
19
  deprecate this in favor of your module.
20
20
 
21
21
  This code is released under an
22
- [MIT license](https://github.com/prosemirror/prosemirror/tree/master/LICENSE).
22
+ [MIT license](https://code.haverbeke.berlin/prosemirror/prosemirror/src/branch/main/LICENSE).
23
23
  There's a [forum](http://discuss.prosemirror.net) for general
24
24
  discussion and support requests, and the
25
- [Github bug tracker](https://github.com/prosemirror/prosemirror-menu/issues)
25
+ [bug tracker](https://code.haverbeke.berlin/prosemirror/prosemirror-menu/issues)
26
26
  is the place to report issues.
27
27
 
28
28
  ## Documentation
@@ -31,7 +31,7 @@ This module defines a number of building blocks for ProseMirror menus,
31
31
  along with a [menu bar](#menu.menuBar) implementation.
32
32
 
33
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)
34
+ [`style/menu.css`](https://code.haverbeke.berlin/prosemirror/prosemirror-menu/src/branch/main/style/menu.css)
35
35
  file is loaded into your page.
36
36
 
37
37
  ### interface MenuElement
@@ -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: HTMLElement, update: fn(state: EditorState) → boolean}`\
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`**`: ?fn(state: EditorState) → boolean`\
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`**`: ?fn(state: EditorState) → boolean`\
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`**`: ?fn(state: EditorState) → boolean`\
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`**`: ?fn(view: EditorView) → HTMLElement`\
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`**`: ?IconSpec`\
91
+ * **`icon`**`?: IconSpec`\
90
92
  Describes an icon to show for this item.
91
93
 
92
- * **`label`**`: ?string`\
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`**`: ?string | fn(state: EditorState) → string`\
99
+ * **`title`**`?: string | fn(state: EditorState) → string`\
98
100
  Defines DOM title (mouseover) text for the item.
99
101
 
100
- * **`class`**`: ?string`\
102
+ * **`class`**`?: string`\
101
103
  Optionally adds a CSS class to the item's DOM representation.
102
104
 
103
- * **`css`**`: ?string`\
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?: ?string} | {dom: Node}`\
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: ?Object = {})`\
125
+ * `new `**`Dropdown`**`(content: readonly MenuElement[] | MenuElement, options?: Object = {})`\
124
126
  Create a dropdown wrapping the elements.
125
127
 
126
- * **`render`**`(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}`\
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: ?Object = {})`\
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
- * **`render`**`(view: EditorView) → {dom: HTMLElement, update: fn(state: EditorState) → boolean}`\
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?: ?Attrs}) → MenuItem`\
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?: ?Attrs}) → MenuItem`\
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
+