prosemirror-menu 1.2.4 → 1.2.5

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,9 @@
1
+ ## 1.2.5 (2025-04-22)
2
+
3
+ ### Bug fixes
4
+
5
+ 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.
6
+
1
7
  ## 1.2.4 (2023-08-20)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1,54 +1,37 @@
1
1
  'use strict';
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6
-
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
7
6
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
-
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
9
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
-
11
10
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
-
13
11
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
-
15
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
16
-
17
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
18
-
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
14
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
-
21
15
  var crel = require('crelt');
22
-
23
16
  var prosemirrorCommands = require('prosemirror-commands');
24
-
25
17
  var prosemirrorHistory = require('prosemirror-history');
26
-
27
18
  var prosemirrorState = require('prosemirror-state');
28
-
29
19
  var SVG = "http://www.w3.org/2000/svg";
30
20
  var XLINK = "http://www.w3.org/1999/xlink";
31
21
  var prefix$2 = "ProseMirror-icon";
32
-
33
22
  function hashPath(path) {
34
23
  var hash = 0;
35
-
36
- for (var i = 0; i < path.length; i++) {
37
- hash = (hash << 5) - hash + path.charCodeAt(i) | 0;
38
- }
39
-
24
+ for (var i = 0; i < path.length; i++) hash = (hash << 5) - hash + path.charCodeAt(i) | 0;
40
25
  return hash;
41
26
  }
42
-
43
27
  function getIcon(root, icon) {
44
28
  var doc = (root.nodeType == 9 ? root : root.ownerDocument) || document;
45
29
  var node = doc.createElement("div");
46
30
  node.className = prefix$2;
47
-
48
31
  if (icon.path) {
49
32
  var path = icon.path,
50
- width = icon.width,
51
- height = icon.height;
33
+ width = icon.width,
34
+ height = icon.height;
52
35
  var name = "pm-icon-" + hashPath(path).toString(16);
53
36
  if (!doc.getElementById(name)) buildSVG(root, name, icon);
54
37
  var svg = node.appendChild(doc.createElementNS(SVG, "svg"));
@@ -59,29 +42,24 @@ function getIcon(root, icon) {
59
42
  node.appendChild(icon.dom.cloneNode(true));
60
43
  } else {
61
44
  var text = icon.text,
62
- css = icon.css;
45
+ css = icon.css;
63
46
  node.appendChild(doc.createElement("span")).textContent = text || '';
64
47
  if (css) node.firstChild.style.cssText = css;
65
48
  }
66
-
67
49
  return node;
68
50
  }
69
-
70
51
  function buildSVG(root, name, data) {
71
52
  var _ref = root.nodeType == 9 ? [root, root.body] : [root.ownerDocument || document, root],
72
- _ref2 = _slicedToArray(_ref, 2),
73
- doc = _ref2[0],
74
- top = _ref2[1];
75
-
53
+ _ref2 = _slicedToArray(_ref, 2),
54
+ doc = _ref2[0],
55
+ top = _ref2[1];
76
56
  var collection = doc.getElementById(prefix$2 + "-collection");
77
-
78
57
  if (!collection) {
79
58
  collection = doc.createElementNS(SVG, "svg");
80
59
  collection.id = prefix$2 + "-collection";
81
60
  collection.style.display = "none";
82
61
  top.insertBefore(collection, top.firstChild);
83
62
  }
84
-
85
63
  var sym = doc.createElementNS(SVG, "symbol");
86
64
  sym.id = name;
87
65
  sym.setAttribute("viewBox", "0 0 " + data.width + " " + data.height);
@@ -89,101 +67,79 @@ function buildSVG(root, name, data) {
89
67
  path.setAttribute("d", data.path);
90
68
  collection.appendChild(sym);
91
69
  }
92
-
93
70
  var prefix$1 = "ProseMirror-menu";
94
-
95
71
  var MenuItem = function () {
96
72
  function MenuItem(spec) {
97
73
  _classCallCheck(this, MenuItem);
98
-
99
74
  this.spec = spec;
100
75
  }
101
-
102
76
  _createClass(MenuItem, [{
103
77
  key: "render",
104
78
  value: function render(view) {
105
79
  var spec = this.spec;
106
80
  var dom = spec.render ? spec.render(view) : spec.icon ? getIcon(view.root, spec.icon) : spec.label ? crel("div", null, translate(view, spec.label)) : null;
107
81
  if (!dom) throw new RangeError("MenuItem without icon or label property");
108
-
109
82
  if (spec.title) {
110
83
  var title = typeof spec.title === "function" ? spec.title(view.state) : spec.title;
111
84
  dom.setAttribute("title", translate(view, title));
112
85
  }
113
-
114
86
  if (spec["class"]) dom.classList.add(spec["class"]);
115
87
  if (spec.css) dom.style.cssText += spec.css;
116
88
  dom.addEventListener("mousedown", function (e) {
117
89
  e.preventDefault();
118
90
  if (!dom.classList.contains(prefix$1 + "-disabled")) spec.run(view.state, view.dispatch, view, e);
119
91
  });
120
-
121
92
  function update(state) {
122
93
  if (spec.select) {
123
94
  var selected = spec.select(state);
124
95
  dom.style.display = selected ? "" : "none";
125
96
  if (!selected) return false;
126
97
  }
127
-
128
98
  var enabled = true;
129
-
130
99
  if (spec.enable) {
131
100
  enabled = spec.enable(state) || false;
132
101
  setClass(dom, prefix$1 + "-disabled", !enabled);
133
102
  }
134
-
135
103
  if (spec.active) {
136
104
  var active = enabled && spec.active(state) || false;
137
105
  setClass(dom, prefix$1 + "-active", active);
138
106
  }
139
-
140
107
  return true;
141
108
  }
142
-
143
109
  return {
144
110
  dom: dom,
145
111
  update: update
146
112
  };
147
113
  }
148
114
  }]);
149
-
150
115
  return MenuItem;
151
116
  }();
152
-
153
117
  function translate(view, text) {
154
118
  return view._props.translate ? view._props.translate(text) : text;
155
119
  }
156
-
157
120
  var lastMenuEvent = {
158
121
  time: 0,
159
122
  node: null
160
123
  };
161
-
162
124
  function markMenuEvent(e) {
163
125
  lastMenuEvent.time = Date.now();
164
126
  lastMenuEvent.node = e.target;
165
127
  }
166
-
167
128
  function isMenuEvent(wrapper) {
168
129
  return Date.now() - 100 < lastMenuEvent.time && lastMenuEvent.node && wrapper.contains(lastMenuEvent.node);
169
130
  }
170
-
171
131
  var Dropdown = function () {
172
132
  function Dropdown(content) {
173
133
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
174
-
175
134
  _classCallCheck(this, Dropdown);
176
-
177
135
  this.options = options;
178
136
  this.options = options || {};
179
137
  this.content = Array.isArray(content) ? content : [content];
180
138
  }
181
-
182
139
  _createClass(Dropdown, [{
183
140
  key: "render",
184
141
  value: function render(view) {
185
142
  var _this = this;
186
-
187
143
  var content = renderDropdownItems(this.content, view);
188
144
  var win = view.dom.ownerDocument.defaultView || window;
189
145
  var label = crel("div", {
@@ -196,18 +152,15 @@ var Dropdown = function () {
196
152
  }, label);
197
153
  var open = null;
198
154
  var listeningOnClose = null;
199
-
200
155
  var close = function close() {
201
156
  if (open && open.close()) {
202
157
  open = null;
203
158
  win.removeEventListener("mousedown", listeningOnClose);
204
159
  }
205
160
  };
206
-
207
161
  label.addEventListener("mousedown", function (e) {
208
162
  e.preventDefault();
209
163
  markMenuEvent(e);
210
-
211
164
  if (open) {
212
165
  close();
213
166
  } else {
@@ -217,13 +170,11 @@ var Dropdown = function () {
217
170
  });
218
171
  }
219
172
  });
220
-
221
173
  function update(state) {
222
174
  var inner = content.update(state);
223
175
  wrap.style.display = inner ? "" : "none";
224
176
  return inner;
225
177
  }
226
-
227
178
  return {
228
179
  dom: wrap,
229
180
  update: update
@@ -236,14 +187,12 @@ var Dropdown = function () {
236
187
  "class": prefix$1 + "-dropdown-menu " + (this.options["class"] || "")
237
188
  }, items);
238
189
  var done = false;
239
-
240
190
  function close() {
241
191
  if (done) return false;
242
192
  done = true;
243
193
  dom.removeChild(menuDOM);
244
194
  return true;
245
195
  }
246
-
247
196
  dom.appendChild(menuDOM);
248
197
  return {
249
198
  close: close,
@@ -251,55 +200,43 @@ var Dropdown = function () {
251
200
  };
252
201
  }
253
202
  }]);
254
-
255
203
  return Dropdown;
256
204
  }();
257
-
258
205
  function renderDropdownItems(items, view) {
259
206
  var rendered = [],
260
- updates = [];
261
-
207
+ updates = [];
262
208
  for (var i = 0; i < items.length; i++) {
263
209
  var _items$i$render = items[i].render(view),
264
- dom = _items$i$render.dom,
265
- update = _items$i$render.update;
266
-
210
+ dom = _items$i$render.dom,
211
+ update = _items$i$render.update;
267
212
  rendered.push(crel("div", {
268
213
  "class": prefix$1 + "-dropdown-item"
269
214
  }, dom));
270
215
  updates.push(update);
271
216
  }
272
-
273
217
  return {
274
218
  dom: rendered,
275
219
  update: combineUpdates(updates, rendered)
276
220
  };
277
221
  }
278
-
279
222
  function combineUpdates(updates, nodes) {
280
223
  return function (state) {
281
224
  var something = false;
282
-
283
225
  for (var i = 0; i < updates.length; i++) {
284
226
  var up = updates[i](state);
285
227
  nodes[i].style.display = up ? "" : "none";
286
228
  if (up) something = true;
287
229
  }
288
-
289
230
  return something;
290
231
  };
291
232
  }
292
-
293
233
  var DropdownSubmenu = function () {
294
234
  function DropdownSubmenu(content) {
295
235
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
296
-
297
236
  _classCallCheck(this, DropdownSubmenu);
298
-
299
237
  this.options = options;
300
238
  this.content = Array.isArray(content) ? content : [content];
301
239
  }
302
-
303
240
  _createClass(DropdownSubmenu, [{
304
241
  key: "render",
305
242
  value: function render(view) {
@@ -326,38 +263,31 @@ var DropdownSubmenu = function () {
326
263
  }
327
264
  });
328
265
  });
329
-
330
266
  function update(state) {
331
267
  var inner = items.update(state);
332
268
  wrap.style.display = inner ? "" : "none";
333
269
  return inner;
334
270
  }
335
-
336
271
  return {
337
272
  dom: wrap,
338
273
  update: update
339
274
  };
340
275
  }
341
276
  }]);
342
-
343
277
  return DropdownSubmenu;
344
278
  }();
345
-
346
279
  function renderGrouped(view, content) {
347
280
  var result = document.createDocumentFragment();
348
281
  var updates = [],
349
- separators = [];
350
-
282
+ separators = [];
351
283
  for (var i = 0; i < content.length; i++) {
352
284
  var items = content[i],
353
- localUpdates = [],
354
- localNodes = [];
355
-
285
+ localUpdates = [],
286
+ localNodes = [];
356
287
  for (var j = 0; j < items.length; j++) {
357
288
  var _items$j$render = items[j].render(view),
358
- dom = _items$j$render.dom,
359
- _update = _items$j$render.update;
360
-
289
+ dom = _items$j$render.dom,
290
+ _update = _items$j$render.update;
361
291
  var span = crel("span", {
362
292
  "class": prefix$1 + "item"
363
293
  }, dom);
@@ -365,40 +295,32 @@ function renderGrouped(view, content) {
365
295
  localNodes.push(span);
366
296
  localUpdates.push(_update);
367
297
  }
368
-
369
298
  if (localUpdates.length) {
370
299
  updates.push(combineUpdates(localUpdates, localNodes));
371
300
  if (i < content.length - 1) separators.push(result.appendChild(separator()));
372
301
  }
373
302
  }
374
-
375
303
  function update(state) {
376
304
  var something = false,
377
- needSep = false;
378
-
379
- for (var _i2 = 0; _i2 < updates.length; _i2++) {
380
- var hasContent = updates[_i2](state);
381
-
382
- if (_i2) separators[_i2 - 1].style.display = needSep && hasContent ? "" : "none";
305
+ needSep = false;
306
+ for (var _i = 0; _i < updates.length; _i++) {
307
+ var hasContent = updates[_i](state);
308
+ if (_i) separators[_i - 1].style.display = needSep && hasContent ? "" : "none";
383
309
  needSep = hasContent;
384
310
  if (hasContent) something = true;
385
311
  }
386
-
387
312
  return something;
388
313
  }
389
-
390
314
  return {
391
315
  dom: result,
392
316
  update: update
393
317
  };
394
318
  }
395
-
396
319
  function separator() {
397
320
  return crel("span", {
398
321
  "class": prefix$1 + "separator"
399
322
  });
400
323
  }
401
-
402
324
  var icons = {
403
325
  join: {
404
326
  width: 800,
@@ -500,7 +422,6 @@ var redoItem = new MenuItem({
500
422
  },
501
423
  icon: icons.redo
502
424
  });
503
-
504
425
  function wrapItem(nodeType, options) {
505
426
  var passedOptions = {
506
427
  run: function run(state, dispatch) {
@@ -510,14 +431,9 @@ function wrapItem(nodeType, options) {
510
431
  return prosemirrorCommands.wrapIn(nodeType, options.attrs)(state);
511
432
  }
512
433
  };
513
-
514
- for (var prop in options) {
515
- passedOptions[prop] = options[prop];
516
- }
517
-
434
+ for (var prop in options) passedOptions[prop] = options[prop];
518
435
  return new MenuItem(passedOptions);
519
436
  }
520
-
521
437
  function blockTypeItem(nodeType, options) {
522
438
  var command = prosemirrorCommands.setBlockType(nodeType, options.attrs);
523
439
  var passedOptions = {
@@ -527,33 +443,25 @@ function blockTypeItem(nodeType, options) {
527
443
  },
528
444
  active: function active(state) {
529
445
  var _state$selection = state.selection,
530
- $from = _state$selection.$from,
531
- to = _state$selection.to,
532
- node = _state$selection.node;
446
+ $from = _state$selection.$from,
447
+ to = _state$selection.to,
448
+ node = _state$selection.node;
533
449
  if (node) return node.hasMarkup(nodeType, options.attrs);
534
450
  return to <= $from.end() && $from.parent.hasMarkup(nodeType, options.attrs);
535
451
  }
536
452
  };
537
-
538
- for (var prop in options) {
539
- passedOptions[prop] = options[prop];
540
- }
541
-
453
+ for (var prop in options) passedOptions[prop] = options[prop];
542
454
  return new MenuItem(passedOptions);
543
455
  }
544
-
545
456
  function setClass(dom, cls, on) {
546
457
  if (on) dom.classList.add(cls);else dom.classList.remove(cls);
547
458
  }
548
-
549
459
  var prefix = "ProseMirror-menubar";
550
-
551
460
  function isIOS() {
552
461
  if (typeof navigator == "undefined") return false;
553
462
  var agent = navigator.userAgent;
554
463
  return !/Edge\/\d/.test(agent) && /AppleWebKit/.test(agent) && /Mobile\/\w+/.test(agent);
555
464
  }
556
-
557
465
  function menuBar(options) {
558
466
  return new prosemirrorState.Plugin({
559
467
  view: function view(editorView) {
@@ -561,13 +469,10 @@ function menuBar(options) {
561
469
  }
562
470
  });
563
471
  }
564
-
565
472
  var MenuBarView = function () {
566
473
  function MenuBarView(editorView, options) {
567
474
  var _this2 = this;
568
-
569
475
  _classCallCheck(this, MenuBarView);
570
-
571
476
  this.editorView = editorView;
572
477
  this.options = options;
573
478
  this.spacer = null;
@@ -575,6 +480,7 @@ var MenuBarView = function () {
575
480
  this.widthForMaxHeight = 0;
576
481
  this.floating = false;
577
482
  this.scrollHandler = null;
483
+ this.root = editorView.root;
578
484
  this.wrapper = crel("div", {
579
485
  "class": prefix + "-wrapper"
580
486
  });
@@ -584,37 +490,38 @@ var MenuBarView = function () {
584
490
  this.menu.className = prefix;
585
491
  if (editorView.dom.parentNode) editorView.dom.parentNode.replaceChild(this.wrapper, editorView.dom);
586
492
  this.wrapper.appendChild(editorView.dom);
587
-
588
493
  var _renderGrouped = renderGrouped(this.editorView, this.options.content),
589
- dom = _renderGrouped.dom,
590
- update = _renderGrouped.update;
591
-
494
+ dom = _renderGrouped.dom,
495
+ update = _renderGrouped.update;
592
496
  this.contentUpdate = update;
593
497
  this.menu.appendChild(dom);
594
498
  this.update();
595
-
596
499
  if (options.floating && !isIOS()) {
597
500
  this.updateFloat();
598
501
  var potentialScrollers = getAllWrapping(this.wrapper);
599
-
600
502
  this.scrollHandler = function (e) {
601
503
  var root = _this2.editorView.root;
602
504
  if (!(root.body || root).contains(_this2.wrapper)) potentialScrollers.forEach(function (el) {
603
505
  return el.removeEventListener("scroll", _this2.scrollHandler);
604
506
  });else _this2.updateFloat(e.target.getBoundingClientRect ? e.target : undefined);
605
507
  };
606
-
607
508
  potentialScrollers.forEach(function (el) {
608
509
  return el.addEventListener('scroll', _this2.scrollHandler);
609
510
  });
610
511
  }
611
512
  }
612
-
613
513
  _createClass(MenuBarView, [{
614
514
  key: "update",
615
515
  value: function update() {
516
+ if (this.editorView.root != this.root) {
517
+ var _renderGrouped2 = renderGrouped(this.editorView, this.options.content),
518
+ dom = _renderGrouped2.dom,
519
+ update = _renderGrouped2.update;
520
+ this.contentUpdate = update;
521
+ this.menu.replaceChild(dom, this.menu.firstChild);
522
+ this.root = this.editorView.root;
523
+ }
616
524
  this.contentUpdate(this.editorView.state);
617
-
618
525
  if (this.floating) {
619
526
  this.updateScrollCursor();
620
527
  } else {
@@ -622,7 +529,6 @@ var MenuBarView = function () {
622
529
  this.widthForMaxHeight = this.menu.offsetWidth;
623
530
  this.maxHeight = 0;
624
531
  }
625
-
626
532
  if (this.menu.offsetHeight > this.maxHeight) {
627
533
  this.maxHeight = this.menu.offsetHeight;
628
534
  this.menu.style.minHeight = this.maxHeight + "px";
@@ -638,7 +544,6 @@ var MenuBarView = function () {
638
544
  var selRect = rects[selectionIsInverted(selection) ? 0 : rects.length - 1];
639
545
  if (!selRect) return;
640
546
  var menuRect = this.menu.getBoundingClientRect();
641
-
642
547
  if (selRect.top < menuRect.bottom && selRect.bottom > menuRect.top) {
643
548
  var scrollable = findWrappingScrollable(this.wrapper);
644
549
  if (scrollable) scrollable.scrollTop -= menuRect.bottom - selRect.top;
@@ -648,9 +553,8 @@ var MenuBarView = function () {
648
553
  key: "updateFloat",
649
554
  value: function updateFloat(scrollAncestor) {
650
555
  var parent = this.wrapper,
651
- editorRect = parent.getBoundingClientRect(),
652
- top = scrollAncestor ? Math.max(0, scrollAncestor.getBoundingClientRect().top) : 0;
653
-
556
+ editorRect = parent.getBoundingClientRect(),
557
+ top = scrollAncestor ? Math.max(0, scrollAncestor.getBoundingClientRect().top) : 0;
654
558
  if (this.floating) {
655
559
  if (editorRect.top >= top || editorRect.bottom < this.menu.offsetHeight + 10) {
656
560
  this.floating = false;
@@ -686,31 +590,20 @@ var MenuBarView = function () {
686
590
  if (this.wrapper.parentNode) this.wrapper.parentNode.replaceChild(this.editorView.dom, this.wrapper);
687
591
  }
688
592
  }]);
689
-
690
593
  return MenuBarView;
691
594
  }();
692
-
693
595
  function selectionIsInverted(selection) {
694
596
  if (selection.anchorNode == selection.focusNode) return selection.anchorOffset > selection.focusOffset;
695
597
  return selection.anchorNode.compareDocumentPosition(selection.focusNode) == Node.DOCUMENT_POSITION_FOLLOWING;
696
598
  }
697
-
698
599
  function findWrappingScrollable(node) {
699
- for (var cur = node.parentNode; cur; cur = cur.parentNode) {
700
- if (cur.scrollHeight > cur.clientHeight) return cur;
701
- }
600
+ for (var cur = node.parentNode; cur; cur = cur.parentNode) if (cur.scrollHeight > cur.clientHeight) return cur;
702
601
  }
703
-
704
602
  function getAllWrapping(node) {
705
603
  var res = [node.ownerDocument.defaultView || window];
706
-
707
- for (var cur = node.parentNode; cur; cur = cur.parentNode) {
708
- res.push(cur);
709
- }
710
-
604
+ for (var cur = node.parentNode; cur; cur = cur.parentNode) res.push(cur);
711
605
  return res;
712
606
  }
713
-
714
607
  exports.Dropdown = Dropdown;
715
608
  exports.DropdownSubmenu = DropdownSubmenu;
716
609
  exports.MenuItem = MenuItem;
package/dist/index.d.cts CHANGED
@@ -263,4 +263,4 @@ declare function menuBar(options: {
263
263
  floating?: boolean;
264
264
  }): Plugin;
265
265
 
266
- export { Dropdown, DropdownSubmenu, IconSpec, MenuElement, MenuItem, MenuItemSpec, blockTypeItem, icons, joinUpItem, liftItem, menuBar, redoItem, renderGrouped, selectParentNodeItem, undoItem, wrapItem };
266
+ export { Dropdown, DropdownSubmenu, type IconSpec, type MenuElement, MenuItem, type MenuItemSpec, blockTypeItem, icons, joinUpItem, liftItem, menuBar, redoItem, renderGrouped, selectParentNodeItem, undoItem, wrapItem };
package/dist/index.d.ts CHANGED
@@ -263,4 +263,4 @@ declare function menuBar(options: {
263
263
  floating?: boolean;
264
264
  }): Plugin;
265
265
 
266
- export { Dropdown, DropdownSubmenu, IconSpec, MenuElement, MenuItem, MenuItemSpec, blockTypeItem, icons, joinUpItem, liftItem, menuBar, redoItem, renderGrouped, selectParentNodeItem, undoItem, wrapItem };
266
+ export { Dropdown, DropdownSubmenu, type IconSpec, type MenuElement, MenuItem, type MenuItemSpec, blockTypeItem, icons, joinUpItem, liftItem, menuBar, redoItem, renderGrouped, selectParentNodeItem, undoItem, wrapItem };
package/dist/index.js CHANGED
@@ -484,6 +484,7 @@ class MenuBarView {
484
484
  this.widthForMaxHeight = 0;
485
485
  this.floating = false;
486
486
  this.scrollHandler = null;
487
+ this.root = editorView.root;
487
488
  this.wrapper = crel("div", { class: prefix + "-wrapper" });
488
489
  this.menu = this.wrapper.appendChild(crel("div", { class: prefix }));
489
490
  this.menu.className = prefix;
@@ -508,6 +509,12 @@ class MenuBarView {
508
509
  }
509
510
  }
510
511
  update() {
512
+ if (this.editorView.root != this.root) {
513
+ let { dom, update } = renderGrouped(this.editorView, this.options.content);
514
+ this.contentUpdate = update;
515
+ this.menu.replaceChild(dom, this.menu.firstChild);
516
+ this.root = this.editorView.root;
517
+ }
511
518
  this.contentUpdate(this.editorView.state);
512
519
  if (this.floating) {
513
520
  this.updateScrollCursor();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-menu",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Simple menu elements for ProseMirror",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/menubar.ts CHANGED
@@ -38,11 +38,13 @@ class MenuBarView {
38
38
  floating = false
39
39
  contentUpdate: (state: EditorState) => boolean
40
40
  scrollHandler: ((event: Event) => void) | null = null
41
+ root: Document | ShadowRoot
41
42
 
42
43
  constructor(
43
44
  readonly editorView: EditorView,
44
45
  readonly options: Parameters<typeof menuBar>[0]
45
46
  ) {
47
+ this.root = editorView.root
46
48
  this.wrapper = crel("div", {class: prefix + "-wrapper"})
47
49
  this.menu = this.wrapper.appendChild(crel("div", {class: prefix}))
48
50
  this.menu.className = prefix
@@ -71,6 +73,12 @@ class MenuBarView {
71
73
  }
72
74
 
73
75
  update() {
76
+ if (this.editorView.root != this.root) {
77
+ let {dom, update} = renderGrouped(this.editorView, this.options.content)
78
+ this.contentUpdate = update
79
+ this.menu.replaceChild(dom, this.menu.firstChild!)
80
+ this.root = this.editorView.root
81
+ }
74
82
  this.contentUpdate(this.editorView.state)
75
83
 
76
84
  if (this.floating) {