mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
external modules for util
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
|
||||
"globals": {
|
||||
"d3": false,
|
||||
"iD": false,
|
||||
# "iD": false,
|
||||
"_": false,
|
||||
"t": false,
|
||||
"bootstrap": false,
|
||||
|
||||
@@ -48,13 +48,10 @@ MODULE_TARGETS = \
|
||||
js/lib/id/presets.js \
|
||||
js/lib/id/renderer.js \
|
||||
js/lib/id/services.js \
|
||||
js/lib/id/ui/intro.js \
|
||||
js/lib/id/svg.js \
|
||||
js/lib/id/ui/index.js \
|
||||
js/lib/id/ui/core.js \
|
||||
js/lib/id/ui/intro.js \
|
||||
js/lib/id/ui/preset.js \
|
||||
js/lib/id/util.js \
|
||||
js/lib/id/validations.js
|
||||
|
||||
js/lib/id/index.js: $(shell find modules/index.js -type f)
|
||||
@@ -97,10 +94,6 @@ js/lib/id/ui/preset.js: $(shell find modules/ui/preset -type f)
|
||||
@rm -f $@
|
||||
node_modules/.bin/rollup -f umd -n iD.ui.preset modules/ui/preset/index.js --no-strict -o $@
|
||||
|
||||
js/lib/id/util.js: $(shell find modules/util -type f)
|
||||
@rm -f $@
|
||||
node_modules/.bin/rollup -f umd -n iD.util modules/util/index.js --no-strict -o $@
|
||||
|
||||
js/lib/id/validations.js: $(shell find modules/validations -type f)
|
||||
@rm -f $@
|
||||
node_modules/.bin/rollup -f umd -n iD.validations modules/validations/index.js --no-strict -o $@
|
||||
|
||||
@@ -41,8 +41,6 @@
|
||||
<script src='js/lib/id/presets.js'></script>
|
||||
<script src='js/lib/id/renderer.js'></script>
|
||||
<script src='js/lib/id/services.js'></script>
|
||||
<script src='js/lib/id/svg.js'></script>
|
||||
<script src='js/lib/id/util.js'></script>
|
||||
|
||||
<script src='js/lib/id/ui/index.js'></script>
|
||||
<script src='js/lib/id/ui/core.js'></script>
|
||||
|
||||
@@ -1571,8 +1571,17 @@
|
||||
return difference;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
function tagText(entity) {
|
||||
return d3.entries(entity.tags).map(function(e) {
|
||||
return e.key + '=' + e.value;
|
||||
}).join(', ');
|
||||
}
|
||||
|
||||
>>>>>>> 42ce4cf... external modules for util
|
||||
function entitySelector(ids) {
|
||||
return ids.length ? '.' + ids.join(',.') : 'nothing';
|
||||
}
|
||||
@@ -1683,9 +1692,65 @@
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> ef619c2... external modules for behavior
|
||||
=======
|
||||
function editDistance(a, b) {
|
||||
if (a.length === 0) return b.length;
|
||||
if (b.length === 0) return a.length;
|
||||
var matrix = [];
|
||||
for (var i = 0; i <= b.length; i++) { matrix[i] = [i]; }
|
||||
for (var j = 0; j <= a.length; j++) { matrix[0][j] = j; }
|
||||
for (i = 1; i <= b.length; i++) {
|
||||
for (j = 1; j <= a.length; j++) {
|
||||
if (b.charAt(i-1) === a.charAt(j-1)) {
|
||||
matrix[i][j] = matrix[i-1][j-1];
|
||||
} else {
|
||||
matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
|
||||
Math.min(matrix[i][j-1] + 1, // insertion
|
||||
matrix[i-1][j] + 1)); // deletion
|
||||
}
|
||||
}
|
||||
}
|
||||
return matrix[b.length][a.length];
|
||||
}
|
||||
|
||||
// a d3.mouse-alike which
|
||||
// 1. Only works on HTML elements, not SVG
|
||||
// 2. Does not cause style recalculation
|
||||
function fastMouse(container) {
|
||||
var rect = container.getBoundingClientRect(),
|
||||
rectLeft = rect.left,
|
||||
rectTop = rect.top,
|
||||
clientLeft = +container.clientLeft,
|
||||
clientTop = +container.clientTop;
|
||||
return function(e) {
|
||||
return [
|
||||
e.clientX - rectLeft - clientLeft,
|
||||
e.clientY - rectTop - clientTop];
|
||||
};
|
||||
}
|
||||
|
||||
>>>>>>> 42ce4cf... external modules for util
|
||||
/* eslint-disable no-proto */
|
||||
var getPrototypeOf = Object.getPrototypeOf || function(obj) { return obj.__proto__; };
|
||||
/* eslint-enable no-proto */
|
||||
|
||||
function asyncMap(inputs, func, callback) {
|
||||
var remaining = inputs.length,
|
||||
results = [],
|
||||
errors = [];
|
||||
|
||||
inputs.forEach(function(d, i) {
|
||||
func(d, function done(err, data) {
|
||||
errors[i] = err;
|
||||
results[i] = data;
|
||||
remaining--;
|
||||
if (!remaining) callback(errors, results);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// wraps an index to an interval [0..length-1]
|
||||
function Wrap(index, length) {
|
||||
if (index < 0)
|
||||
@@ -1730,6 +1795,58 @@
|
||||
return mutex;
|
||||
}
|
||||
|
||||
function SuggestNames(preset, suggestions) {
|
||||
preset = preset.id.split('/', 2);
|
||||
var k = preset[0],
|
||||
v = preset[1];
|
||||
|
||||
return function(value, callback) {
|
||||
var result = [];
|
||||
if (value && value.length > 2) {
|
||||
if (suggestions[k] && suggestions[k][v]) {
|
||||
for (var sugg in suggestions[k][v]) {
|
||||
var dist = editDistance(value, sugg.substring(0, value.length));
|
||||
if (dist < 3) {
|
||||
result.push({
|
||||
title: sugg,
|
||||
value: sugg,
|
||||
dist: dist
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
result.sort(function(a, b) {
|
||||
return a.dist - b.dist;
|
||||
});
|
||||
}
|
||||
result = result.slice(0,3);
|
||||
callback(result);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
var util = Object.freeze({
|
||||
tagText: tagText,
|
||||
entitySelector: entitySelector,
|
||||
entityOrMemberSelector: entityOrMemberSelector,
|
||||
displayName: displayName,
|
||||
displayType: displayType,
|
||||
stringQs: stringQs,
|
||||
qsString: qsString,
|
||||
prefixDOMProperty: prefixDOMProperty,
|
||||
prefixCSSProperty: prefixCSSProperty,
|
||||
setTransform: setTransform,
|
||||
getStyle: getStyle,
|
||||
editDistance: editDistance,
|
||||
fastMouse: fastMouse,
|
||||
getPrototypeOf: getPrototypeOf,
|
||||
asyncMap: asyncMap,
|
||||
wrap: Wrap,
|
||||
SessionMutex: SessionMutex,
|
||||
SuggestNames: SuggestNames
|
||||
});
|
||||
|
||||
function Graph(other, mutable) {
|
||||
if (!(this instanceof Graph)) return new Graph(other, mutable);
|
||||
|
||||
@@ -12255,7 +12372,11 @@
|
||||
>>>>>>> ef619c2... external modules for behavior
|
||||
=======
|
||||
exports.modes = modes;
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> 75901f6... external modules for modes
|
||||
=======
|
||||
exports.util = util;
|
||||
>>>>>>> 42ce4cf... external modules for util
|
||||
exports.Connection = Connection;
|
||||
exports.Difference = Difference;
|
||||
exports.Entity = Entity;
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@ import * as actions from './actions/index';
|
||||
import * as geo from './geo/index';
|
||||
import * as behavior from './behavior/index';
|
||||
import * as modes from './modes/index';
|
||||
import * as util from './util/index';
|
||||
|
||||
export { Connection } from './core/connection';
|
||||
export { Difference } from './core/difference';
|
||||
@@ -18,5 +19,6 @@ export {
|
||||
actions,
|
||||
geo,
|
||||
behavior,
|
||||
modes
|
||||
modes,
|
||||
util
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { editDistance } from './util';
|
||||
|
||||
export function SuggestNames(preset, suggestions) {
|
||||
preset = preset.id.split('/', 2);
|
||||
var k = preset[0],
|
||||
@@ -8,7 +10,7 @@ export function SuggestNames(preset, suggestions) {
|
||||
if (value && value.length > 2) {
|
||||
if (suggestions[k] && suggestions[k][v]) {
|
||||
for (var sugg in suggestions[k][v]) {
|
||||
var dist = iD.util.editDistance(value, sugg.substring(0, value.length));
|
||||
var dist = editDistance(value, sugg.substring(0, value.length));
|
||||
if (dist < 3) {
|
||||
result.push({
|
||||
title: sugg,
|
||||
|
||||
@@ -46,8 +46,6 @@
|
||||
<script src='../js/lib/id/presets.js'></script>
|
||||
<script src='../js/lib/id/renderer.js'></script>
|
||||
<script src='../js/lib/id/services.js'></script>
|
||||
<script src='../js/lib/id/svg.js'></script>
|
||||
<script src='../js/lib/id/util.js'></script>
|
||||
|
||||
<script src='../js/lib/id/ui/index.js'></script>
|
||||
<script src='../js/lib/id/ui/core.js'></script>
|
||||
|
||||
Reference in New Issue
Block a user