mapshaper 0.6.111 → 0.6.112

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.6.111",
3
+ "version": "0.6.112",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
@@ -1937,8 +1937,20 @@
1937
1937
  .on('paste', onpaste);
1938
1938
  area.node().addEventListener('paste', onpaste);
1939
1939
  function ondrop(e) {
1940
+ var files = e.dataTransfer.files;
1941
+ var types = e.dataTransfer.types;
1940
1942
  block(e);
1941
- cb(e.dataTransfer.files);
1943
+ if (files.length) {
1944
+ cb(files);
1945
+ } else if (types.includes('text/uri-list')) {
1946
+ cb(e.dataTransfer.getData('text/uri-list').split(','));
1947
+ } else if (types.includes('text/html')) {
1948
+ // drag-dropping a highlighted link may pull in a chunk of html
1949
+ var urls = e.dataTransfer.getData('text/html').match(/https?:[^"']+/);
1950
+ if (urls.length) {
1951
+ cb(urls);
1952
+ }
1953
+ }
1942
1954
  }
1943
1955
  function onpaste(e) {
1944
1956
  var types = Array.from(e.clipboardData.types || []).join(',');
@@ -1955,15 +1967,18 @@
1955
1967
  // Single files of all types are pasted as a string and an image/png
1956
1968
  // Multiple files are pasted as a string containing a list of file names
1957
1969
 
1958
- // import text from the clipboard (could be csv, json, etc)
1970
+ // import text from the clipboard (could be csv, json, a url, etc)
1959
1971
  // formatted text can be available as both text/plain and text/html (e.g.
1960
1972
  // a JSON data object copied from a GitHub issue).
1961
1973
  //
1962
1974
  if (types.includes('text/plain')) {
1963
- // if (types == 'text/plain') {
1964
1975
  // text from clipboard (supported by Chrome, FF, Safari)
1965
1976
  // TODO: handle FF case of string containing multiple file names.
1966
- files = [pastedTextToFile(e.clipboardData.getData('text/plain'))];
1977
+ var str = e.clipboardData.getData('text/plain');
1978
+ if (isUrl(str)) {
1979
+ return cb(str.split(','));
1980
+ }
1981
+ files = [pastedTextToFile(str)];
1967
1982
  } else {
1968
1983
  files = items.map(function(item) {
1969
1984
  return item.kind == 'file' && !item.type.includes('image') ?
@@ -1997,6 +2012,10 @@
1997
2012
  return new File([blob], name);
1998
2013
  }
1999
2014
 
2015
+ function isUrl(str) {
2016
+ return /^https?:\/\//.test(str);
2017
+ }
2018
+
2000
2019
  // @el DOM element for select button
2001
2020
  // @cb function(<FileList>)
2002
2021
  function FileChooser(el, cb) {
@@ -2040,7 +2059,7 @@
2040
2059
 
2041
2060
  var submitBtn = new SimpleButton('#import-options .submit-btn').on('click', importQueuedFiles);
2042
2061
  new SimpleButton('#import-options .cancel-btn').on('click', gui.clearMode);
2043
- new DropControl(gui, 'body', receiveFilesWithOption);
2062
+ new DropControl(gui, 'body', receiveDroppedItems);
2044
2063
  new FileChooser('#import-options .add-btn', receiveFilesWithOption);
2045
2064
  new FileChooser('#add-file-btn', receiveFiles);
2046
2065
  new SimpleButton('#add-empty-btn').on('click', function() {
@@ -2056,7 +2075,7 @@
2056
2075
 
2057
2076
  function turnOn() {
2058
2077
  if (manifestFiles.length > 0) {
2059
- downloadFiles(manifestFiles, true);
2078
+ downloadFiles(manifestFiles);
2060
2079
  manifestFiles = [];
2061
2080
  } else if (model.isEmpty()) {
2062
2081
  showImportMenu();
@@ -2157,6 +2176,14 @@
2157
2176
  submitBtn.classed('disabled', queuedFiles.length === 0);
2158
2177
  }
2159
2178
 
2179
+ function receiveDroppedItems(arr) {
2180
+ if (utils$1.isString(arr[0])) { // assume array of URLs
2181
+ downloadFiles(arr);
2182
+ } else { // assume array of Files
2183
+ receiveFilesWithOption(arr);
2184
+ }
2185
+ }
2186
+
2160
2187
  function receiveFilesWithOption(files) {
2161
2188
  var quickView = !El('.advanced-import-options').node().checked;
2162
2189
  receiveFiles(files, quickView);
@@ -2312,9 +2339,8 @@
2312
2339
 
2313
2340
  function prepFilesForDownload(names) {
2314
2341
  var items = names.map(function(name) {
2315
- var isUrl = /:\/\//.test(name);
2316
2342
  var item = {name: name};
2317
- if (isUrl) {
2343
+ if (isUrl(name)) {
2318
2344
  item.url = name;
2319
2345
  item.basename = GUI.getUrlFilename(name);
2320
2346
 
@@ -2667,7 +2693,7 @@
2667
2693
  var lyr;
2668
2694
  if (memo) return memo; // already found a match
2669
2695
  // try to match import filename of this dataset
2670
- if (d.info.input_files[0] == src) return d;
2696
+ if (d.info?.input_files?.[0] == src) return d;
2671
2697
  // try to match name of a layer in this dataset
2672
2698
  lyr = utils$1.find(d.layers, function(lyr) {return lyr.name == src;});
2673
2699
  return lyr ? internal.isolateLayer(lyr, d) : null;
@@ -5068,7 +5094,7 @@
5068
5094
  var lyr = o.layer;
5069
5095
  var opts = {
5070
5096
  show_source: layerCount < 5,
5071
- pinnable: pinnableCount > 1 && isPinnable(lyr)
5097
+ pinnable: pinnableCount > 0 && isPinnable(lyr)
5072
5098
  };
5073
5099
  var html, element;
5074
5100
  html = renderLayer(lyr, o.dataset, opts);
@@ -6299,6 +6325,18 @@
6299
6325
  }
6300
6326
  }
6301
6327
 
6328
+ function time(slug) {
6329
+ if (useDebug()) {
6330
+ console.time(slug);
6331
+ }
6332
+ }
6333
+
6334
+ function timeEnd(slug) {
6335
+ if (useDebug()) {
6336
+ console.timeEnd(slug);
6337
+ }
6338
+ }
6339
+
6302
6340
  function printError(err) {
6303
6341
  var msg;
6304
6342
  if (!LOGGING) return;
@@ -7462,8 +7500,13 @@
7462
7500
  if (len >= 2) {
7463
7501
  first = str.charAt(0);
7464
7502
  last = str.charAt(len-1);
7465
- if (first == '"' && last == '"' && !str.includes('","') ||
7466
- first == "'" && last == "'" && !str.includes("','")) {
7503
+ // if (first == '"' && last == '"' && !str.includes('","') ||
7504
+ // first == "'" && last == "'" && !str.includes("','")) {
7505
+ // don't strip if there are unescaped quotes
7506
+ // e.g. expressions that start and end with quotes
7507
+ // e.g. comma-separated list of quoted values
7508
+ if (first == '"' && last == '"' && !/[^\\]"./.test(str) ||
7509
+ first == "'" && last == "'" && !/[^\\]'./.test(str)) {
7467
7510
  str = str.substr(1, len-2);
7468
7511
  // remove string escapes
7469
7512
  str = str.replace(first == '"' ? /\\(?=")/g : /\\(?=')/g, '');