mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-21 15:56:56 +02:00
Add mechanism for fields to support editing during multiselection (re: #7276)
Add `utilCombinedTags` method and use it for the raw tag editor as well as fields Pass `entityIDs` array into fields instead of single `entity` object Give field revertion its own path separate from `change` Add multiselection editing to fields in files: access, address, check, combo, cycleway, input, maxspeed, textarea, and wikidata
This commit is contained in:
@@ -10,6 +10,7 @@ export { utilArrayUniqBy } from './array';
|
||||
|
||||
export { utilAsyncMap } from './util';
|
||||
export { utilCleanTags } from './clean_tags';
|
||||
export { utilCombinedTags } from './util';
|
||||
export { utilDeepMemberSelector } from './util';
|
||||
export { utilDetect } from './detect';
|
||||
export { utilDisplayName } from './util';
|
||||
|
||||
@@ -230,6 +230,93 @@ export function utilEntityRoot(entityType) {
|
||||
}
|
||||
|
||||
|
||||
// Returns a single object containing the tags of all the given entities.
|
||||
// Example:
|
||||
// {
|
||||
// highway: 'service',
|
||||
// service: 'parking_aisle'
|
||||
// }
|
||||
// +
|
||||
// {
|
||||
// highway: 'service',
|
||||
// service: 'driveway',
|
||||
// width: '3'
|
||||
// }
|
||||
// =
|
||||
// {
|
||||
// highway: 'service',
|
||||
// service: [ 'driveway', 'parking_aisle' ],
|
||||
// width: [ '3', undefined ]
|
||||
// }
|
||||
export function utilCombinedTags(entityIDs, graph) {
|
||||
|
||||
var tags = {};
|
||||
var tagCounts = {};
|
||||
var allKeys = new Set();
|
||||
|
||||
var entities = entityIDs.map(function(entityID) {
|
||||
return graph.hasEntity(entityID);
|
||||
}).filter(Boolean);
|
||||
|
||||
// gather the aggregate keys
|
||||
entities.forEach(function(entity) {
|
||||
var keys = Object.keys(entity.tags).filter(Boolean);
|
||||
keys.forEach(function(key) {
|
||||
allKeys.add(key);
|
||||
});
|
||||
});
|
||||
|
||||
entities.forEach(function(entity) {
|
||||
|
||||
allKeys.forEach(function(key) {
|
||||
|
||||
var value = entity.tags[key]; // purposely allow `undefined`
|
||||
|
||||
if (!tags.hasOwnProperty(key)) {
|
||||
// first value, set as raw
|
||||
tags[key] = value;
|
||||
} else {
|
||||
if (!Array.isArray(tags[key])) {
|
||||
if (tags[key] !== value) {
|
||||
// first alternate value, replace single value with array
|
||||
tags[key] = [tags[key], value];
|
||||
}
|
||||
} else { // type is array
|
||||
if (tags[key].indexOf(value) === -1) {
|
||||
// subsequent alternate value, add to array
|
||||
tags[key].push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var tagHash = key + '=' + value;
|
||||
if (!tagCounts[tagHash]) tagCounts[tagHash] = 0;
|
||||
tagCounts[tagHash] += 1;
|
||||
});
|
||||
});
|
||||
|
||||
for (var key in tags) {
|
||||
if (!Array.isArray(tags[key])) continue;
|
||||
|
||||
// sort values by frequency then alphabetically
|
||||
tags[key] = tags[key].sort(function(val1, val2) {
|
||||
var key = key; // capture
|
||||
var count2 = tagCounts[key + '=' + val2];
|
||||
var count1 = tagCounts[key + '=' + val1];
|
||||
if (count2 !== count1) {
|
||||
return count2 - count1;
|
||||
}
|
||||
if (val2 && val1) {
|
||||
return val1.localeCompare(val2);
|
||||
}
|
||||
return val1 ? 1 : -1;
|
||||
});
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
||||
export function utilStringQs(str) {
|
||||
return str.split('&').reduce(function(obj, pair){
|
||||
var parts = pair.split('=');
|
||||
|
||||
Reference in New Issue
Block a user