mapshaper 0.7.56 → 0.7.59

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.7.56",
3
+ "version": "0.7.59",
4
4
  "description": "A tool for editing geospatial data for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
@@ -11109,6 +11109,8 @@
11109
11109
 
11110
11110
  var openMenu;
11111
11111
  var openMenuId;
11112
+ // One menu element per parent element, created on demand.
11113
+ var menus = new WeakMap();
11112
11114
  // Prefixes shown to the left of a menu item. The checkmark is what a copyable
11113
11115
  // item shows after it has been copied.
11114
11116
  var BULLET = '•  ';
@@ -11132,14 +11134,26 @@
11132
11134
  }
11133
11135
  }
11134
11136
 
11137
+ // Menus are re-used, rather than created per click: a discarded menu stays in
11138
+ // the DOM, and an empty one is a 10px sliver at the bottom of the page, which
11139
+ // is enough to make the page scrollable (see the note in ContextMenu()).
11140
+ function getContextMenu(parentArg) {
11141
+ var parent = parentArg || document.querySelector('body');
11142
+ var menu = menus.get(parent);
11143
+ if (!menu) {
11144
+ menu = new ContextMenu(parent);
11145
+ menus.set(parent, menu);
11146
+ }
11147
+ return menu;
11148
+ }
11149
+
11135
11150
  function openContextMenu(e, lyr, parent) {
11136
- var menu = new ContextMenu(parent);
11137
11151
  if (e.contextMenuId && e.contextMenuId == openMenuId) {
11138
11152
  closeOpenMenu(true);
11139
11153
  return;
11140
11154
  }
11141
11155
  closeOpenMenu(true);
11142
- menu.open(e, lyr);
11156
+ getContextMenu(parent).open(e, lyr);
11143
11157
  openMenuId = e.contextMenuId || null;
11144
11158
  }
11145
11159
 
@@ -11151,6 +11165,14 @@
11151
11165
  var _open = false;
11152
11166
  var _openCount = 0;
11153
11167
 
11168
+ // The menu is hidden until it is opened. A visible empty menu is 10px of
11169
+ // padding and border at the end of the page, and the page is exactly as tall
11170
+ // as the window, so those 10px make the document scrollable. The body is
11171
+ // overflow:hidden, but that only stops the user from scrolling: the browser
11172
+ // still scrolls the page to reveal a focused element or a caret, and once it
11173
+ // does, the whole UI stays shifted up (mbloch/mapshaper#702).
11174
+ menu.hide();
11175
+
11154
11176
  this.isOpen = function() {
11155
11177
  return _open;
11156
11178
  };
@@ -11292,10 +11314,23 @@
11292
11314
  }
11293
11315
  menu.css('top', (e.pageY - offs.top - 15) + 'px');
11294
11316
  menu.show();
11317
+ keepInsideWindow();
11295
11318
 
11296
11319
  _open = true;
11297
11320
  _openCount++;
11298
11321
 
11322
+ // A menu opened near the bottom of the window would otherwise hang off the
11323
+ // screen, out of reach and adding to the page's scrollable overflow.
11324
+ function keepInsideWindow() {
11325
+ var pad = 6;
11326
+ var rect = menu.node().getBoundingClientRect();
11327
+ var overflow = rect.bottom + pad - document.documentElement.clientHeight;
11328
+ var shift = Math.min(overflow, rect.top - pad);
11329
+ if (shift > 0) {
11330
+ menu.css('top', (parseFloat(menu.node().style.top) - shift) + 'px');
11331
+ }
11332
+ }
11333
+
11299
11334
  function getParentOffset() { // crossbrowser version
11300
11335
  if (parent == body) {
11301
11336
  return {top: 0, left: 0};
@@ -25418,7 +25453,7 @@ GUI and setting the size and crop of SVG output.</p><div><input type="text" clas
25418
25453
  gui.messages = new MessageControl(gui);
25419
25454
  gui.basemap = new Basemap(gui);
25420
25455
  gui.session = new SessionHistory(gui);
25421
- gui.contextMenu = new ContextMenu();
25456
+ gui.contextMenu = getContextMenu();
25422
25457
  gui.undo = new Undo(gui);
25423
25458
  gui.map = new MshpMap(gui);
25424
25459
  // gui.project = new ProjectOptions(gui);