prosemirror-menu 1.2.2 → 1.2.3
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 +6 -0
- package/dist/index.cjs +43 -23
- package/dist/index.js +26 -21
- package/package.json +1 -1
- package/src/icons.ts +15 -12
- package/src/menu.ts +7 -5
- package/src/menubar.ts +3 -2
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,18 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
6
6
|
|
|
7
7
|
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
8
|
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
|
|
11
|
+
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
|
+
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
|
+
|
|
19
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
|
+
|
|
9
21
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
10
22
|
|
|
11
23
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -42,8 +54,9 @@ function hashPath(path) {
|
|
|
42
54
|
return hash;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
|
-
function getIcon(icon) {
|
|
46
|
-
var
|
|
57
|
+
function getIcon(root, icon) {
|
|
58
|
+
var doc = root.ownerDocument;
|
|
59
|
+
var node = doc.createElement("div");
|
|
47
60
|
node.className = prefix$2;
|
|
48
61
|
|
|
49
62
|
if (icon.path) {
|
|
@@ -51,37 +64,42 @@ function getIcon(icon) {
|
|
|
51
64
|
width = icon.width,
|
|
52
65
|
height = icon.height;
|
|
53
66
|
var name = "pm-icon-" + hashPath(path).toString(16);
|
|
54
|
-
if (!
|
|
55
|
-
var svg = node.appendChild(
|
|
67
|
+
if (!doc.getElementById(name)) buildSVG(root, name, icon);
|
|
68
|
+
var svg = node.appendChild(doc.createElementNS(SVG, "svg"));
|
|
56
69
|
svg.style.width = width / height + "em";
|
|
57
|
-
var use = svg.appendChild(
|
|
58
|
-
use.setAttributeNS(XLINK, "href", /([^#]*)/.exec(
|
|
70
|
+
var use = svg.appendChild(doc.createElementNS(SVG, "use"));
|
|
71
|
+
use.setAttributeNS(XLINK, "href", /([^#]*)/.exec(doc.location.toString())[1] + "#" + name);
|
|
59
72
|
} else if (icon.dom) {
|
|
60
73
|
node.appendChild(icon.dom.cloneNode(true));
|
|
61
74
|
} else {
|
|
62
75
|
var text = icon.text,
|
|
63
76
|
css = icon.css;
|
|
64
|
-
node.appendChild(
|
|
77
|
+
node.appendChild(doc.createElement("span")).textContent = text || '';
|
|
65
78
|
if (css) node.firstChild.style.cssText = css;
|
|
66
79
|
}
|
|
67
80
|
|
|
68
81
|
return node;
|
|
69
82
|
}
|
|
70
83
|
|
|
71
|
-
function buildSVG(name, data) {
|
|
72
|
-
var
|
|
84
|
+
function buildSVG(root, name, data) {
|
|
85
|
+
var _ref = root.nodeType == 9 ? [root, root.body] : [root.ownerDocument, root],
|
|
86
|
+
_ref2 = _slicedToArray(_ref, 2),
|
|
87
|
+
doc = _ref2[0],
|
|
88
|
+
top = _ref2[1];
|
|
89
|
+
|
|
90
|
+
var collection = doc.getElementById(prefix$2 + "-collection");
|
|
73
91
|
|
|
74
92
|
if (!collection) {
|
|
75
|
-
collection =
|
|
93
|
+
collection = doc.createElementNS(SVG, "svg");
|
|
76
94
|
collection.id = prefix$2 + "-collection";
|
|
77
95
|
collection.style.display = "none";
|
|
78
|
-
|
|
96
|
+
top.insertBefore(collection, top.firstChild);
|
|
79
97
|
}
|
|
80
98
|
|
|
81
|
-
var sym =
|
|
99
|
+
var sym = doc.createElementNS(SVG, "symbol");
|
|
82
100
|
sym.id = name;
|
|
83
101
|
sym.setAttribute("viewBox", "0 0 " + data.width + " " + data.height);
|
|
84
|
-
var path = sym.appendChild(
|
|
102
|
+
var path = sym.appendChild(doc.createElementNS(SVG, "path"));
|
|
85
103
|
path.setAttribute("d", data.path);
|
|
86
104
|
collection.appendChild(sym);
|
|
87
105
|
}
|
|
@@ -99,7 +117,7 @@ var MenuItem = function () {
|
|
|
99
117
|
key: "render",
|
|
100
118
|
value: function render(view) {
|
|
101
119
|
var spec = this.spec;
|
|
102
|
-
var dom = spec.render ? spec.render(view) : spec.icon ? getIcon(spec.icon) : spec.label ? crel__default["default"]("div", null, translate(view, spec.label)) : null;
|
|
120
|
+
var dom = spec.render ? spec.render(view) : spec.icon ? getIcon(view.root, spec.icon) : spec.label ? crel__default["default"]("div", null, translate(view, spec.label)) : null;
|
|
103
121
|
if (!dom) throw new RangeError("MenuItem without icon or label property");
|
|
104
122
|
|
|
105
123
|
if (spec.title) {
|
|
@@ -181,6 +199,7 @@ var Dropdown = function () {
|
|
|
181
199
|
var _this = this;
|
|
182
200
|
|
|
183
201
|
var content = renderDropdownItems(this.content, view);
|
|
202
|
+
var win = view.dom.ownerDocument.defaultView || window;
|
|
184
203
|
var label = crel__default["default"]("div", {
|
|
185
204
|
"class": prefix$1 + "-dropdown " + (this.options["class"] || ""),
|
|
186
205
|
style: this.options.css
|
|
@@ -195,7 +214,7 @@ var Dropdown = function () {
|
|
|
195
214
|
var close = function close() {
|
|
196
215
|
if (open && open.close()) {
|
|
197
216
|
open = null;
|
|
198
|
-
|
|
217
|
+
win.removeEventListener("mousedown", listeningOnClose);
|
|
199
218
|
}
|
|
200
219
|
};
|
|
201
220
|
|
|
@@ -207,7 +226,7 @@ var Dropdown = function () {
|
|
|
207
226
|
close();
|
|
208
227
|
} else {
|
|
209
228
|
open = _this.expand(wrap, content.dom);
|
|
210
|
-
|
|
229
|
+
win.addEventListener("mousedown", listeningOnClose = function listeningOnClose() {
|
|
211
230
|
if (!isMenuEvent(wrap)) close();
|
|
212
231
|
});
|
|
213
232
|
}
|
|
@@ -299,6 +318,7 @@ var DropdownSubmenu = function () {
|
|
|
299
318
|
key: "render",
|
|
300
319
|
value: function render(view) {
|
|
301
320
|
var items = renderDropdownItems(this.content, view);
|
|
321
|
+
var win = view.dom.ownerDocument.defaultView || window;
|
|
302
322
|
var label = crel__default["default"]("div", {
|
|
303
323
|
"class": prefix$1 + "-submenu-label"
|
|
304
324
|
}, translate(view, this.options.label || ""));
|
|
@@ -312,10 +332,10 @@ var DropdownSubmenu = function () {
|
|
|
312
332
|
e.preventDefault();
|
|
313
333
|
markMenuEvent(e);
|
|
314
334
|
setClass(wrap, prefix$1 + "-submenu-wrap-active", false);
|
|
315
|
-
if (!_listeningOnClose)
|
|
335
|
+
if (!_listeningOnClose) win.addEventListener("mousedown", _listeningOnClose = function listeningOnClose() {
|
|
316
336
|
if (!isMenuEvent(wrap)) {
|
|
317
337
|
wrap.classList.remove(prefix$1 + "-submenu-wrap-active");
|
|
318
|
-
|
|
338
|
+
win.removeEventListener("mousedown", _listeningOnClose);
|
|
319
339
|
_listeningOnClose = null;
|
|
320
340
|
}
|
|
321
341
|
});
|
|
@@ -370,10 +390,10 @@ function renderGrouped(view, content) {
|
|
|
370
390
|
var something = false,
|
|
371
391
|
needSep = false;
|
|
372
392
|
|
|
373
|
-
for (var
|
|
374
|
-
var hasContent = updates[
|
|
393
|
+
for (var _i2 = 0; _i2 < updates.length; _i2++) {
|
|
394
|
+
var hasContent = updates[_i2](state);
|
|
375
395
|
|
|
376
|
-
if (
|
|
396
|
+
if (_i2) separators[_i2 - 1].style.display = needSep && hasContent ? "" : "none";
|
|
377
397
|
needSep = hasContent;
|
|
378
398
|
if (hasContent) something = true;
|
|
379
399
|
}
|
|
@@ -655,7 +675,7 @@ var MenuBarView = function () {
|
|
|
655
675
|
} else {
|
|
656
676
|
var border = (parent.offsetWidth - parent.clientWidth) / 2;
|
|
657
677
|
this.menu.style.left = editorRect.left + border + "px";
|
|
658
|
-
this.menu.style.display = editorRect.top > window.innerHeight ? "none" : "";
|
|
678
|
+
this.menu.style.display = editorRect.top > (this.editorView.dom.ownerDocument.defaultView || window).innerHeight ? "none" : "";
|
|
659
679
|
if (scrollAncestor) this.menu.style.top = top + "px";
|
|
660
680
|
}
|
|
661
681
|
} else {
|
|
@@ -696,7 +716,7 @@ function findWrappingScrollable(node) {
|
|
|
696
716
|
}
|
|
697
717
|
|
|
698
718
|
function getAllWrapping(node) {
|
|
699
|
-
var res = [window];
|
|
719
|
+
var res = [node.ownerDocument.defaultView || window];
|
|
700
720
|
|
|
701
721
|
for (var cur = node.parentNode; cur; cur = cur.parentNode) {
|
|
702
722
|
res.push(cur);
|
package/dist/index.js
CHANGED
|
@@ -12,42 +12,44 @@ function hashPath(path) {
|
|
|
12
12
|
hash = (((hash << 5) - hash) + path.charCodeAt(i)) | 0;
|
|
13
13
|
return hash;
|
|
14
14
|
}
|
|
15
|
-
function getIcon(icon) {
|
|
16
|
-
let
|
|
15
|
+
function getIcon(root, icon) {
|
|
16
|
+
let doc = root.ownerDocument;
|
|
17
|
+
let node = doc.createElement("div");
|
|
17
18
|
node.className = prefix$2;
|
|
18
19
|
if (icon.path) {
|
|
19
20
|
let { path, width, height } = icon;
|
|
20
21
|
let name = "pm-icon-" + hashPath(path).toString(16);
|
|
21
|
-
if (!
|
|
22
|
-
buildSVG(name, icon);
|
|
23
|
-
let svg = node.appendChild(
|
|
22
|
+
if (!doc.getElementById(name))
|
|
23
|
+
buildSVG(root, name, icon);
|
|
24
|
+
let svg = node.appendChild(doc.createElementNS(SVG, "svg"));
|
|
24
25
|
svg.style.width = (width / height) + "em";
|
|
25
|
-
let use = svg.appendChild(
|
|
26
|
-
use.setAttributeNS(XLINK, "href", /([^#]*)/.exec(
|
|
26
|
+
let use = svg.appendChild(doc.createElementNS(SVG, "use"));
|
|
27
|
+
use.setAttributeNS(XLINK, "href", /([^#]*)/.exec(doc.location.toString())[1] + "#" + name);
|
|
27
28
|
}
|
|
28
29
|
else if (icon.dom) {
|
|
29
30
|
node.appendChild(icon.dom.cloneNode(true));
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
32
33
|
let { text, css } = icon;
|
|
33
|
-
node.appendChild(
|
|
34
|
+
node.appendChild(doc.createElement("span")).textContent = text || '';
|
|
34
35
|
if (css)
|
|
35
36
|
node.firstChild.style.cssText = css;
|
|
36
37
|
}
|
|
37
38
|
return node;
|
|
38
39
|
}
|
|
39
|
-
function buildSVG(name, data) {
|
|
40
|
-
let
|
|
40
|
+
function buildSVG(root, name, data) {
|
|
41
|
+
let [doc, top] = root.nodeType == 9 ? [root, root.body] : [root.ownerDocument, root];
|
|
42
|
+
let collection = doc.getElementById(prefix$2 + "-collection");
|
|
41
43
|
if (!collection) {
|
|
42
|
-
collection =
|
|
44
|
+
collection = doc.createElementNS(SVG, "svg");
|
|
43
45
|
collection.id = prefix$2 + "-collection";
|
|
44
46
|
collection.style.display = "none";
|
|
45
|
-
|
|
47
|
+
top.insertBefore(collection, top.firstChild);
|
|
46
48
|
}
|
|
47
|
-
let sym =
|
|
49
|
+
let sym = doc.createElementNS(SVG, "symbol");
|
|
48
50
|
sym.id = name;
|
|
49
51
|
sym.setAttribute("viewBox", "0 0 " + data.width + " " + data.height);
|
|
50
|
-
let path = sym.appendChild(
|
|
52
|
+
let path = sym.appendChild(doc.createElementNS(SVG, "path"));
|
|
51
53
|
path.setAttribute("d", data.path);
|
|
52
54
|
collection.appendChild(sym);
|
|
53
55
|
}
|
|
@@ -75,7 +77,7 @@ class MenuItem {
|
|
|
75
77
|
render(view) {
|
|
76
78
|
let spec = this.spec;
|
|
77
79
|
let dom = spec.render ? spec.render(view)
|
|
78
|
-
: spec.icon ? getIcon(spec.icon)
|
|
80
|
+
: spec.icon ? getIcon(view.root, spec.icon)
|
|
79
81
|
: spec.label ? crel("div", null, translate(view, spec.label))
|
|
80
82
|
: null;
|
|
81
83
|
if (!dom)
|
|
@@ -148,6 +150,7 @@ class Dropdown {
|
|
|
148
150
|
*/
|
|
149
151
|
render(view) {
|
|
150
152
|
let content = renderDropdownItems(this.content, view);
|
|
153
|
+
let win = view.dom.ownerDocument.defaultView || window;
|
|
151
154
|
let label = crel("div", { class: prefix$1 + "-dropdown " + (this.options.class || ""),
|
|
152
155
|
style: this.options.css }, translate(view, this.options.label || ""));
|
|
153
156
|
if (this.options.title)
|
|
@@ -158,7 +161,7 @@ class Dropdown {
|
|
|
158
161
|
let close = () => {
|
|
159
162
|
if (open && open.close()) {
|
|
160
163
|
open = null;
|
|
161
|
-
|
|
164
|
+
win.removeEventListener("mousedown", listeningOnClose);
|
|
162
165
|
}
|
|
163
166
|
};
|
|
164
167
|
label.addEventListener("mousedown", e => {
|
|
@@ -169,7 +172,7 @@ class Dropdown {
|
|
|
169
172
|
}
|
|
170
173
|
else {
|
|
171
174
|
open = this.expand(wrap, content.dom);
|
|
172
|
-
|
|
175
|
+
win.addEventListener("mousedown", listeningOnClose = () => {
|
|
173
176
|
if (!isMenuEvent(wrap))
|
|
174
177
|
close();
|
|
175
178
|
});
|
|
@@ -242,6 +245,7 @@ class DropdownSubmenu {
|
|
|
242
245
|
*/
|
|
243
246
|
render(view) {
|
|
244
247
|
let items = renderDropdownItems(this.content, view);
|
|
248
|
+
let win = view.dom.ownerDocument.defaultView || window;
|
|
245
249
|
let label = crel("div", { class: prefix$1 + "-submenu-label" }, translate(view, this.options.label || ""));
|
|
246
250
|
let wrap = crel("div", { class: prefix$1 + "-submenu-wrap" }, label, crel("div", { class: prefix$1 + "-submenu" }, items.dom));
|
|
247
251
|
let listeningOnClose = null;
|
|
@@ -250,10 +254,10 @@ class DropdownSubmenu {
|
|
|
250
254
|
markMenuEvent(e);
|
|
251
255
|
setClass(wrap, prefix$1 + "-submenu-wrap-active", false);
|
|
252
256
|
if (!listeningOnClose)
|
|
253
|
-
|
|
257
|
+
win.addEventListener("mousedown", listeningOnClose = () => {
|
|
254
258
|
if (!isMenuEvent(wrap)) {
|
|
255
259
|
wrap.classList.remove(prefix$1 + "-submenu-wrap-active");
|
|
256
|
-
|
|
260
|
+
win.removeEventListener("mousedown", listeningOnClose);
|
|
257
261
|
listeningOnClose = null;
|
|
258
262
|
}
|
|
259
263
|
});
|
|
@@ -547,7 +551,8 @@ class MenuBarView {
|
|
|
547
551
|
else {
|
|
548
552
|
let border = (parent.offsetWidth - parent.clientWidth) / 2;
|
|
549
553
|
this.menu.style.left = (editorRect.left + border) + "px";
|
|
550
|
-
this.menu.style.display =
|
|
554
|
+
this.menu.style.display = editorRect.top > (this.editorView.dom.ownerDocument.defaultView || window).innerHeight
|
|
555
|
+
? "none" : "";
|
|
551
556
|
if (scrollAncestor)
|
|
552
557
|
this.menu.style.top = top + "px";
|
|
553
558
|
}
|
|
@@ -583,7 +588,7 @@ function findWrappingScrollable(node) {
|
|
|
583
588
|
return cur;
|
|
584
589
|
}
|
|
585
590
|
function getAllWrapping(node) {
|
|
586
|
-
let res = [window];
|
|
591
|
+
let res = [node.ownerDocument.defaultView || window];
|
|
587
592
|
for (let cur = node.parentNode; cur; cur = cur.parentNode)
|
|
588
593
|
res.push(cur);
|
|
589
594
|
return res;
|
package/package.json
CHANGED
package/src/icons.ts
CHANGED
|
@@ -11,40 +11,43 @@ function hashPath(path: string) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function getIcon(
|
|
14
|
+
root: Document | ShadowRoot,
|
|
14
15
|
icon: {path: string, width: number, height: number} | {text: string, css?: string} | {dom: Node}
|
|
15
16
|
): HTMLElement {
|
|
16
|
-
let
|
|
17
|
+
let doc = root.ownerDocument!
|
|
18
|
+
let node = doc.createElement("div")
|
|
17
19
|
node.className = prefix
|
|
18
20
|
if ((icon as any).path) {
|
|
19
21
|
let {path, width, height} = icon as {path: string, width: number, height: number}
|
|
20
22
|
let name = "pm-icon-" + hashPath(path).toString(16)
|
|
21
|
-
if (!
|
|
22
|
-
let svg = node.appendChild(
|
|
23
|
+
if (!doc.getElementById(name)) buildSVG(root, name, icon as {path: string, width: number, height: number})
|
|
24
|
+
let svg = node.appendChild(doc.createElementNS(SVG, "svg"))
|
|
23
25
|
svg.style.width = (width / height) + "em"
|
|
24
|
-
let use = svg.appendChild(
|
|
25
|
-
use.setAttributeNS(XLINK, "href", /([^#]*)/.exec(
|
|
26
|
+
let use = svg.appendChild(doc.createElementNS(SVG, "use"))
|
|
27
|
+
use.setAttributeNS(XLINK, "href", /([^#]*)/.exec(doc.location.toString())![1] + "#" + name)
|
|
26
28
|
} else if ((icon as any).dom) {
|
|
27
29
|
node.appendChild((icon as any).dom.cloneNode(true))
|
|
28
30
|
} else {
|
|
29
31
|
let {text, css} = icon as {text: string, css?: string}
|
|
30
|
-
node.appendChild(
|
|
32
|
+
node.appendChild(doc.createElement("span")).textContent = text || ''
|
|
31
33
|
if (css) (node.firstChild as HTMLElement).style.cssText = css
|
|
32
34
|
}
|
|
33
35
|
return node
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
function buildSVG(name: string, data: {width: number, height: number, path: string}) {
|
|
37
|
-
let
|
|
38
|
+
function buildSVG(root: Document | ShadowRoot, name: string, data: {width: number, height: number, path: string}) {
|
|
39
|
+
let [doc, top] = root.nodeType == 9 ? [root as Document, (root as Document).body] : [root.ownerDocument!, root]
|
|
40
|
+
let collection = doc.getElementById(prefix + "-collection") as Element
|
|
38
41
|
if (!collection) {
|
|
39
|
-
collection =
|
|
42
|
+
collection = doc.createElementNS(SVG, "svg")
|
|
40
43
|
collection.id = prefix + "-collection"
|
|
41
44
|
;(collection as HTMLElement).style.display = "none"
|
|
42
|
-
|
|
45
|
+
top.insertBefore(collection, top.firstChild)
|
|
43
46
|
}
|
|
44
|
-
let sym =
|
|
47
|
+
let sym = doc.createElementNS(SVG, "symbol")
|
|
45
48
|
sym.id = name
|
|
46
49
|
sym.setAttribute("viewBox", "0 0 " + data.width + " " + data.height)
|
|
47
|
-
let path = sym.appendChild(
|
|
50
|
+
let path = sym.appendChild(doc.createElementNS(SVG, "path"))
|
|
48
51
|
path.setAttribute("d", data.path)
|
|
49
52
|
collection.appendChild(sym)
|
|
50
53
|
}
|
package/src/menu.ts
CHANGED
|
@@ -34,7 +34,7 @@ export class MenuItem implements MenuElement {
|
|
|
34
34
|
render(view: EditorView) {
|
|
35
35
|
let spec = this.spec
|
|
36
36
|
let dom = spec.render ? spec.render(view)
|
|
37
|
-
: spec.icon ? getIcon(spec.icon)
|
|
37
|
+
: spec.icon ? getIcon(view.root, spec.icon)
|
|
38
38
|
: spec.label ? crel("div", null, translate(view, spec.label))
|
|
39
39
|
: null
|
|
40
40
|
if (!dom) throw new RangeError("MenuItem without icon or label property")
|
|
@@ -171,6 +171,7 @@ export class Dropdown implements MenuElement {
|
|
|
171
171
|
/// Render the dropdown menu and sub-items.
|
|
172
172
|
render(view: EditorView) {
|
|
173
173
|
let content = renderDropdownItems(this.content, view)
|
|
174
|
+
let win = view.dom.ownerDocument.defaultView || window
|
|
174
175
|
|
|
175
176
|
let label = crel("div", {class: prefix + "-dropdown " + (this.options.class || ""),
|
|
176
177
|
style: this.options.css},
|
|
@@ -182,7 +183,7 @@ export class Dropdown implements MenuElement {
|
|
|
182
183
|
let close = () => {
|
|
183
184
|
if (open && open.close()) {
|
|
184
185
|
open = null
|
|
185
|
-
|
|
186
|
+
win.removeEventListener("mousedown", listeningOnClose!)
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
label.addEventListener("mousedown", e => {
|
|
@@ -192,7 +193,7 @@ export class Dropdown implements MenuElement {
|
|
|
192
193
|
close()
|
|
193
194
|
} else {
|
|
194
195
|
open = this.expand(wrap, content.dom)
|
|
195
|
-
|
|
196
|
+
win.addEventListener("mousedown", listeningOnClose = () => {
|
|
196
197
|
if (!isMenuEvent(wrap)) close()
|
|
197
198
|
})
|
|
198
199
|
}
|
|
@@ -270,6 +271,7 @@ export class DropdownSubmenu implements MenuElement {
|
|
|
270
271
|
/// Renders the submenu.
|
|
271
272
|
render(view: EditorView) {
|
|
272
273
|
let items = renderDropdownItems(this.content, view)
|
|
274
|
+
let win = view.dom.ownerDocument.defaultView || window
|
|
273
275
|
|
|
274
276
|
let label = crel("div", {class: prefix + "-submenu-label"}, translate(view, this.options.label || ""))
|
|
275
277
|
let wrap = crel("div", {class: prefix + "-submenu-wrap"}, label,
|
|
@@ -280,10 +282,10 @@ export class DropdownSubmenu implements MenuElement {
|
|
|
280
282
|
markMenuEvent(e)
|
|
281
283
|
setClass(wrap, prefix + "-submenu-wrap-active", false)
|
|
282
284
|
if (!listeningOnClose)
|
|
283
|
-
|
|
285
|
+
win.addEventListener("mousedown", listeningOnClose = () => {
|
|
284
286
|
if (!isMenuEvent(wrap)) {
|
|
285
287
|
wrap.classList.remove(prefix + "-submenu-wrap-active")
|
|
286
|
-
|
|
288
|
+
win.removeEventListener("mousedown", listeningOnClose!)
|
|
287
289
|
listeningOnClose = null
|
|
288
290
|
}
|
|
289
291
|
})
|
package/src/menubar.ts
CHANGED
|
@@ -114,7 +114,8 @@ class MenuBarView {
|
|
|
114
114
|
} else {
|
|
115
115
|
let border = (parent.offsetWidth - parent.clientWidth) / 2
|
|
116
116
|
this.menu.style.left = (editorRect.left + border) + "px"
|
|
117
|
-
this.menu.style.display =
|
|
117
|
+
this.menu.style.display = editorRect.top > (this.editorView.dom.ownerDocument.defaultView || window).innerHeight
|
|
118
|
+
? "none" : ""
|
|
118
119
|
if (scrollAncestor) this.menu.style.top = top + "px"
|
|
119
120
|
}
|
|
120
121
|
} else {
|
|
@@ -149,7 +150,7 @@ function findWrappingScrollable(node: Node) {
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
function getAllWrapping(node: Node) {
|
|
152
|
-
let res: (Node | Window)[] = [window]
|
|
153
|
+
let res: (Node | Window)[] = [node.ownerDocument!.defaultView || window]
|
|
153
154
|
for (let cur = node.parentNode; cur; cur = cur.parentNode)
|
|
154
155
|
res.push(cur)
|
|
155
156
|
return res
|