mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-16 18:52:57 +00:00
Don't trim spaces around semicolons in conditional: tag values
This commit also includes code formatting, and removes some lodash
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import _clone from 'lodash-es/clone';
|
import _clone from 'lodash-es/clone';
|
||||||
import _forEach from 'lodash-es/forEach';
|
|
||||||
import _isEmpty from 'lodash-es/isEmpty';
|
import _isEmpty from 'lodash-es/isEmpty';
|
||||||
import _isEqual from 'lodash-es/isEqual';
|
import _isEqual from 'lodash-es/isEqual';
|
||||||
import _some from 'lodash-es/some';
|
|
||||||
|
|
||||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||||
|
|
||||||
@@ -26,14 +24,14 @@ import { utilRebind } from '../util';
|
|||||||
|
|
||||||
|
|
||||||
export function uiEntityEditor(context) {
|
export function uiEntityEditor(context) {
|
||||||
var dispatch = d3_dispatch('choose'),
|
var dispatch = d3_dispatch('choose');
|
||||||
state = 'select',
|
var _state = 'select';
|
||||||
coalesceChanges = false,
|
var _coalesceChanges = false;
|
||||||
modified = false,
|
var _modified = false;
|
||||||
base,
|
var _base;
|
||||||
entityId,
|
var _entityID;
|
||||||
activePreset,
|
var _activePreset;
|
||||||
reference;
|
var _tagReference;
|
||||||
|
|
||||||
var presetEditor = uiPresetEditor(context)
|
var presetEditor = uiPresetEditor(context)
|
||||||
.on('change', changeTags);
|
.on('change', changeTags);
|
||||||
@@ -42,8 +40,8 @@ export function uiEntityEditor(context) {
|
|||||||
|
|
||||||
|
|
||||||
function entityEditor(selection) {
|
function entityEditor(selection) {
|
||||||
var entity = context.entity(entityId),
|
var entity = context.entity(_entityID);
|
||||||
tags = _clone(entity.tags);
|
var tags = _clone(entity.tags);
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
var header = selection.selectAll('.header')
|
var header = selection.selectAll('.header')
|
||||||
@@ -63,7 +61,7 @@ export function uiEntityEditor(context) {
|
|||||||
.append('button')
|
.append('button')
|
||||||
.attr('class', 'fr preset-close')
|
.attr('class', 'fr preset-close')
|
||||||
.on('click', function() { context.enter(modeBrowse(context)); })
|
.on('click', function() { context.enter(modeBrowse(context)); })
|
||||||
.call(svgIcon(modified ? '#icon-apply' : '#icon-close'));
|
.call(svgIcon(_modified ? '#icon-apply' : '#icon-close'));
|
||||||
|
|
||||||
enter
|
enter
|
||||||
.append('h3')
|
.append('h3')
|
||||||
@@ -75,7 +73,7 @@ export function uiEntityEditor(context) {
|
|||||||
|
|
||||||
header.selectAll('.preset-reset')
|
header.selectAll('.preset-reset')
|
||||||
.on('click', function() {
|
.on('click', function() {
|
||||||
dispatch.call('choose', this, activePreset);
|
dispatch.call('choose', this, _activePreset);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -125,47 +123,49 @@ export function uiEntityEditor(context) {
|
|||||||
body = body
|
body = body
|
||||||
.merge(enter);
|
.merge(enter);
|
||||||
|
|
||||||
body.selectAll('.preset-list-button-wrap')
|
if (_tagReference) {
|
||||||
.call(reference.button);
|
body.selectAll('.preset-list-button-wrap')
|
||||||
|
.call(_tagReference.button);
|
||||||
|
|
||||||
body.selectAll('.preset-list-item')
|
body.selectAll('.preset-list-item')
|
||||||
.call(reference.body);
|
.call(_tagReference.body);
|
||||||
|
}
|
||||||
|
|
||||||
body.selectAll('.preset-reset')
|
body.selectAll('.preset-reset')
|
||||||
.on('click', function() {
|
.on('click', function() {
|
||||||
dispatch.call('choose', this, activePreset);
|
dispatch.call('choose', this, _activePreset);
|
||||||
});
|
});
|
||||||
|
|
||||||
body.select('.preset-list-item button')
|
body.select('.preset-list-item button')
|
||||||
.call(uiPresetIcon()
|
.call(uiPresetIcon()
|
||||||
.geometry(context.geometry(entityId))
|
.geometry(context.geometry(_entityID))
|
||||||
.preset(activePreset)
|
.preset(_activePreset)
|
||||||
);
|
);
|
||||||
|
|
||||||
body.select('.preset-list-item .label')
|
body.select('.preset-list-item .label')
|
||||||
.text(activePreset.name());
|
.text(_activePreset.name());
|
||||||
|
|
||||||
body.select('.preset-editor')
|
body.select('.preset-editor')
|
||||||
.call(presetEditor
|
.call(presetEditor
|
||||||
.preset(activePreset)
|
.preset(_activePreset)
|
||||||
.entityID(entityId)
|
.entityID(_entityID)
|
||||||
.tags(tags)
|
.tags(tags)
|
||||||
.state(state)
|
.state(_state)
|
||||||
);
|
);
|
||||||
|
|
||||||
body.select('.raw-tag-editor')
|
body.select('.raw-tag-editor')
|
||||||
.call(rawTagEditor
|
.call(rawTagEditor
|
||||||
.preset(activePreset)
|
.preset(_activePreset)
|
||||||
.entityID(entityId)
|
.entityID(_entityID)
|
||||||
.tags(tags)
|
.tags(tags)
|
||||||
.state(state)
|
.state(_state)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (entity.type === 'relation') {
|
if (entity.type === 'relation') {
|
||||||
body.select('.raw-member-editor')
|
body.select('.raw-member-editor')
|
||||||
.style('display', 'block')
|
.style('display', 'block')
|
||||||
.call(uiRawMemberEditor(context)
|
.call(uiRawMemberEditor(context)
|
||||||
.entityID(entityId)
|
.entityID(_entityID)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
body.select('.raw-member-editor')
|
body.select('.raw-member-editor')
|
||||||
@@ -174,7 +174,7 @@ export function uiEntityEditor(context) {
|
|||||||
|
|
||||||
body.select('.raw-membership-editor')
|
body.select('.raw-membership-editor')
|
||||||
.call(uiRawMembershipEditor(context)
|
.call(uiRawMembershipEditor(context)
|
||||||
.entityID(entityId)
|
.entityID(_entityID)
|
||||||
);
|
);
|
||||||
|
|
||||||
body.select('.key-trap')
|
body.select('.key-trap')
|
||||||
@@ -192,9 +192,9 @@ export function uiEntityEditor(context) {
|
|||||||
|
|
||||||
|
|
||||||
function historyChanged() {
|
function historyChanged() {
|
||||||
if (state === 'hide') return;
|
if (_state === 'hide') return;
|
||||||
|
|
||||||
var entity = context.hasEntity(entityId);
|
var entity = context.hasEntity(_entityID);
|
||||||
var graph = context.graph();
|
var graph = context.graph();
|
||||||
if (!entity) return;
|
if (!entity) return;
|
||||||
|
|
||||||
@@ -207,23 +207,27 @@ export function uiEntityEditor(context) {
|
|||||||
if (!(weakPreset && match.isFallback())) {
|
if (!(weakPreset && match.isFallback())) {
|
||||||
entityEditor.preset(match);
|
entityEditor.preset(match);
|
||||||
}
|
}
|
||||||
entityEditor.modified(base !== graph);
|
entityEditor.modified(_base !== graph);
|
||||||
entityEditor(selection);
|
entityEditor(selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function clean(o) {
|
function clean(orig) {
|
||||||
|
|
||||||
function cleanVal(k, v) {
|
function cleanVal(k, v) {
|
||||||
function keepSpaces(k) {
|
function keepSpaces(k) {
|
||||||
return k.match(/_hours|_times/) !== null;
|
return /_hours|_times|:conditional$/.test(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
var blacklist = ['description', 'note', 'fixme'];
|
function skip(k) {
|
||||||
if (_some(blacklist, function(s) { return k.indexOf(s) !== -1; })) return v;
|
return /^(description|note|fixme)$/.test(k);
|
||||||
|
}
|
||||||
|
|
||||||
var cleaned = v.split(';')
|
if (skip(k)) return v;
|
||||||
|
|
||||||
|
var cleaned = v
|
||||||
|
.split(';')
|
||||||
.map(function(s) { return s.trim(); })
|
.map(function(s) { return s.trim(); })
|
||||||
.join(keepSpaces(k) ? '; ' : ';');
|
.join(keepSpaces(k) ? '; ' : ';');
|
||||||
|
|
||||||
@@ -241,12 +245,15 @@ export function uiEntityEditor(context) {
|
|||||||
return cleaned;
|
return cleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
var out = {}, k, v;
|
var out = {};
|
||||||
for (k in o) {
|
for (var k in orig) {
|
||||||
if (k && (v = o[k]) !== undefined) {
|
if (!k) continue;
|
||||||
|
var v = orig[k];
|
||||||
|
if (v !== undefined) {
|
||||||
out[k] = cleanVal(k, v);
|
out[k] = cleanVal(k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,62 +261,68 @@ export function uiEntityEditor(context) {
|
|||||||
// Tag changes that fire on input can all get coalesced into a single
|
// Tag changes that fire on input can all get coalesced into a single
|
||||||
// history operation when the user leaves the field. #2342
|
// history operation when the user leaves the field. #2342
|
||||||
function changeTags(changed, onInput) {
|
function changeTags(changed, onInput) {
|
||||||
var entity = context.entity(entityId),
|
var entity = context.entity(_entityID);
|
||||||
annotation = t('operations.change_tags.annotation'),
|
var annotation = t('operations.change_tags.annotation');
|
||||||
tags = _clone(entity.tags);
|
var tags = _clone(entity.tags);
|
||||||
|
|
||||||
_forEach(changed, function(v, k) {
|
for (var k in changed) {
|
||||||
|
if (!k) continue;
|
||||||
|
var v = changed[k];
|
||||||
if (v !== undefined || tags.hasOwnProperty(k)) {
|
if (v !== undefined || tags.hasOwnProperty(k)) {
|
||||||
tags[k] = v;
|
tags[k] = v;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (!onInput) {
|
if (!onInput) {
|
||||||
tags = clean(tags);
|
tags = clean(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_isEqual(entity.tags, tags)) {
|
if (!_isEqual(entity.tags, tags)) {
|
||||||
if (coalesceChanges) {
|
if (_coalesceChanges) {
|
||||||
context.overwrite(actionChangeTags(entityId, tags), annotation);
|
context.overwrite(actionChangeTags(_entityID, tags), annotation);
|
||||||
} else {
|
} else {
|
||||||
context.perform(actionChangeTags(entityId, tags), annotation);
|
context.perform(actionChangeTags(_entityID, tags), annotation);
|
||||||
coalesceChanges = !!onInput;
|
_coalesceChanges = !!onInput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
entityEditor.modified = function(_) {
|
entityEditor.modified = function(_) {
|
||||||
if (!arguments.length) return modified;
|
if (!arguments.length) return _modified;
|
||||||
modified = _;
|
_modified = _;
|
||||||
d3_selectAll('button.preset-close use')
|
d3_selectAll('button.preset-close use')
|
||||||
.attr('xlink:href', (modified ? '#icon-apply' : '#icon-close'));
|
.attr('xlink:href', (_modified ? '#icon-apply' : '#icon-close'));
|
||||||
|
return entityEditor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
entityEditor.state = function(_) {
|
entityEditor.state = function(_) {
|
||||||
if (!arguments.length) return state;
|
if (!arguments.length) return _state;
|
||||||
state = _;
|
_state = _;
|
||||||
return entityEditor;
|
return entityEditor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
entityEditor.entityID = function(_) {
|
entityEditor.entityID = function(_) {
|
||||||
if (!arguments.length) return entityId;
|
if (!arguments.length) return _entityID;
|
||||||
entityId = _;
|
_entityID = _;
|
||||||
base = context.graph();
|
_base = context.graph();
|
||||||
entityEditor.preset(context.presets().match(context.entity(entityId), base));
|
_coalesceChanges = false;
|
||||||
entityEditor.modified(false);
|
|
||||||
coalesceChanges = false;
|
var presetMatch = context.presets().match(context.entity(_entityID), _base);
|
||||||
return entityEditor;
|
|
||||||
|
return entityEditor
|
||||||
|
.preset(presetMatch)
|
||||||
|
.modified(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
entityEditor.preset = function(_) {
|
entityEditor.preset = function(_) {
|
||||||
if (!arguments.length) return activePreset;
|
if (!arguments.length) return _activePreset;
|
||||||
if (_ !== activePreset) {
|
if (_ !== _activePreset) {
|
||||||
activePreset = _;
|
_activePreset = _;
|
||||||
reference = uiTagReference(activePreset.reference(context.geometry(entityId)), context)
|
_tagReference = uiTagReference(_activePreset.tagReference(context.geometry(_entityID)), context)
|
||||||
.showing(false);
|
.showing(false);
|
||||||
}
|
}
|
||||||
return entityEditor;
|
return entityEditor;
|
||||||
|
|||||||
Reference in New Issue
Block a user