mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Presets no longer inherit fields for keys that define them
This commit is contained in:
+1
-1
@@ -1640,7 +1640,7 @@ en:
|
||||
label: Type
|
||||
shop:
|
||||
# shop=*
|
||||
label: Shop Type
|
||||
label: Type
|
||||
siren/purpose:
|
||||
# 'siren:purpose=*'
|
||||
label: Purpose
|
||||
|
||||
@@ -88,6 +88,9 @@ If `fields` or `moreFields` are not defined, the values of the preset's "parent"
|
||||
preset are used. For example, `shop/convenience` automatically uses the same
|
||||
fields as `shop`.
|
||||
|
||||
In both explicit and implicit inheritance, fields for keys that define the
|
||||
preset are not inherited. E.g. the `shop` field is not inherited by `shop/…` presets.
|
||||
|
||||
##### `searchable`
|
||||
|
||||
Deprecated or generic presets can include the property `"searchable": false`.
|
||||
|
||||
@@ -281,7 +281,7 @@
|
||||
"service/vehicle": {"key": "service:vehicle:", "type": "multiCombo", "label": "Services"},
|
||||
"shelter_type": {"key": "shelter_type", "type": "combo", "label": "Type"},
|
||||
"shelter": {"key": "shelter", "type": "check", "label": "Shelter"},
|
||||
"shop": {"key": "shop", "type": "typeCombo", "label": "Shop Type"},
|
||||
"shop": {"key": "shop", "type": "typeCombo", "label": "Type"},
|
||||
"siren/purpose": {"key": "siren:purpose", "type": "combo", "label": "Purpose"},
|
||||
"siren/type": {"key": "siren:type", "type": "combo", "label": "Type", "strings": {"options": {"pneumatic": "Pneumatic", "electronic": "Electronic", "other": "Other"}}},
|
||||
"site_type": {"key": "site_type", "type": "combo", "label": "Site Type"},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"key": "shop",
|
||||
"type": "typeCombo",
|
||||
"label": "Shop Type"
|
||||
"label": "Type"
|
||||
}
|
||||
|
||||
+1
-1
@@ -5403,7 +5403,7 @@
|
||||
},
|
||||
{
|
||||
"key": "shop",
|
||||
"description": "🄿 Shop, 🄵 Shop Type",
|
||||
"description": "🄿 Shop, 🄵 Type",
|
||||
"object_types": ["node", "area"],
|
||||
"icon_url": "https://raw.githubusercontent.com/mapbox/maki/master/icons/shop-15.svg?sanitize=true"
|
||||
},
|
||||
|
||||
Vendored
+1
-1
@@ -3194,7 +3194,7 @@
|
||||
"label": "Shelter"
|
||||
},
|
||||
"shop": {
|
||||
"label": "Shop Type"
|
||||
"label": "Type"
|
||||
},
|
||||
"siren/purpose": {
|
||||
"label": "Purpose"
|
||||
|
||||
@@ -23,6 +23,18 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
|
||||
// For a preset without fields, use the fields of the parent preset.
|
||||
// Replace {preset} placeholders with the fields of the specified presets.
|
||||
function resolveFieldInheritance() {
|
||||
|
||||
function filterTargetFields(targetFieldIDs) {
|
||||
// only inherit `fields` that don't define this preset
|
||||
return _filter(targetFieldIDs, function(targetFieldID) {
|
||||
var targetField = fields[targetFieldID];
|
||||
if (targetField.key) {
|
||||
return preset.tags[targetField.key] === undefined;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
var betweenBracketsRegex = /([^{]*?)(?=\})/;
|
||||
// the keys for properties that contain arrays of field ids
|
||||
var fieldKeys = ['fields', 'moreFields'];
|
||||
@@ -33,10 +45,13 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
|
||||
});
|
||||
wrappedTargetPresets.forEach(function(wrappedTargetPresetID) {
|
||||
var targetPresetID = betweenBracketsRegex.exec(wrappedTargetPresetID)[0];
|
||||
var targetPreset = rawPresets[targetPresetID];
|
||||
var targetFields = rawPresets[targetPresetID][fieldsKey];
|
||||
if (fieldsKey === 'fields') {
|
||||
targetFields = filterTargetFields(targetFields);
|
||||
}
|
||||
var targetIndex = preset[fieldsKey].indexOf(wrappedTargetPresetID);
|
||||
// replace the {preset} placeholder with the target preset's fields
|
||||
preset[fieldsKey].splice.apply(preset[fieldsKey], [targetIndex, 1].concat(targetPreset[fieldsKey]));
|
||||
preset[fieldsKey].splice.apply(preset[fieldsKey], [targetIndex, 1].concat(targetFields));
|
||||
});
|
||||
// remove duplicates
|
||||
preset[fieldsKey] = _union(preset[fieldsKey]);
|
||||
@@ -44,7 +59,11 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
|
||||
// there are no fields defined, so use the parent's if possible
|
||||
var parentPreset = rawPresets[preset.parentPresetID()];
|
||||
if (parentPreset && parentPreset[fieldsKey]) {
|
||||
preset[fieldsKey] = parentPreset[fieldsKey];
|
||||
var parentFields = parentPreset[fieldsKey];
|
||||
if (fieldsKey === 'fields') {
|
||||
parentFields = filterTargetFields(parentFields);
|
||||
}
|
||||
preset[fieldsKey] = parentFields;
|
||||
}
|
||||
}
|
||||
// update the raw object to allow for multiple levels of inheritance
|
||||
|
||||
Reference in New Issue
Block a user