Don't require services/osm in order to get max OSM character lengths

This commit is contained in:
Quincy Morgan
2020-01-28 09:28:23 -05:00
parent b949cc6bb6
commit 89ce98f510
16 changed files with 38 additions and 46 deletions
+13
View File
@@ -207,6 +207,19 @@ export function coreContext() {
};
context.maxCharsForTagKey = function() {
return 255;
};
context.maxCharsForTagValue = function() {
return 255;
};
context.maxCharsForRelationRole = function() {
return 255;
};
/* History */
let _inIntro = false;
context.inIntro = function(val) {
-15
View File
@@ -529,21 +529,6 @@ export default {
},
maxCharsForTagKey: function() {
return 255;
},
maxCharsForTagValue: function() {
return 255;
},
maxCharsForRelationRole: function() {
return 255;
},
entityURL: function(entity) {
return urlroot + '/' + entity.type + '/' + entity.osmId();
},
+2 -2
View File
@@ -52,7 +52,7 @@ export function uiCommit(context) {
var osm = context.connection();
if (!osm) return;
var tagCharLimit = osm.maxCharsForTagValue();
var tagCharLimit = context.maxCharsForTagValue();
// expire stored comment, hashtags, source after cutoff datetime - #3947 #4899
var commentDate = +context.storage('commentDate') || 0;
@@ -515,7 +515,7 @@ export function uiCommit(context) {
function updateChangeset(changed, onInput) {
var tags = Object.assign({}, _changeset.tags); // shallow copy
var tagCharLimit = services.osm.maxCharsForTagValue();
var tagCharLimit = context.maxCharsForTagValue();
Object.keys(changed).forEach(function(k) {
var v = changed[k];
+1 -2
View File
@@ -1,7 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select } from 'd3-selection';
import { services } from '../../services';
import { uiCombobox } from '../combobox';
import { utilGetSetValue, utilNoAuto, utilRebind } from '../../util';
@@ -47,7 +46,7 @@ export function uiFieldAccess(field, context) {
.attr('class', 'preset-input-access-wrap')
.append('input')
.attr('type', 'text')
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.attr('class', function(d) { return 'preset-input-access preset-input-access-' + d; })
.call(utilNoAuto)
.each(function(d) {
+1 -2
View File
@@ -4,7 +4,6 @@ import * as countryCoder from '@ideditor/country-coder';
import { dataAddressFormats } from '../../../data';
import { geoExtent, geoChooseEdge, geoSphericalDistance } from '../../geo';
import { services } from '../../services';
import { uiCombobox } from '../combobox';
import { utilArrayUniqBy, utilGetSetValue, utilNoAuto, utilRebind } from '../../util';
import { t } from '../../util/locale';
@@ -164,7 +163,7 @@ export function uiFieldAddress(field, context) {
var tkey = addrField.strings.placeholders[localkey] ? localkey : d.id;
return addrField.t('placeholders.' + tkey);
})
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.attr('class', function (d) { return 'addr-' + d.id; })
.call(utilNoAuto)
.each(addDropdown)
+3 -3
View File
@@ -359,7 +359,7 @@ export function uiFieldCombo(field, context) {
.append('input')
.attr('type', 'text')
.attr('id', 'preset-input-' + field.safeid)
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.call(utilNoAuto)
.call(initCombo, selection)
.merge(input);
@@ -421,7 +421,7 @@ export function uiFieldCombo(field, context) {
field.keys = _multiData.map(function(d) { return d.key; });
// limit the input length so it fits after prepending the key prefix
maxLength = services.osm.maxCharsForTagKey() - field.key.length;
maxLength = context.maxCharsForTagKey() - field.key.length;
} else if (isSemi) {
var arr = utilArrayUniq((tags[field.key] || '').split(';')).filter(Boolean);
@@ -435,7 +435,7 @@ export function uiFieldCombo(field, context) {
var currLength = arr.join(';').length;
// limit the input length to the remaining available characters
maxLength = services.osm.maxCharsForTagValue() - currLength;
maxLength = context.maxCharsForTagValue() - currLength;
if (currLength > 0) {
// account for the separator if a new value will be appended to existing
+1 -2
View File
@@ -1,7 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select } from 'd3-selection';
import { services } from '../../services';
import { uiCombobox } from '../combobox';
import { utilGetSetValue, utilNoAuto, utilRebind } from '../../util';
@@ -55,7 +54,7 @@ export function uiFieldCycleway(field, context) {
.attr('class', 'preset-input-cycleway-wrap')
.append('input')
.attr('type', 'text')
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.attr('class', function(d) { return 'preset-input-cycleway preset-input-' + stripcolon(d); })
.call(utilNoAuto)
.each(function(d) {
+1 -2
View File
@@ -4,7 +4,6 @@ import * as countryCoder from '@ideditor/country-coder';
import { t, textDirection } from '../../util/locale';
import { dataPhoneFormats } from '../../../data';
import { services } from '../../services';
import { utilGetSetValue, utilNoAuto, utilRebind } from '../../util';
import { svgIcon } from '../../svg/icon';
@@ -46,7 +45,7 @@ export function uiFieldText(field, context) {
.attr('type', field.type === 'identifier' ? 'text' : field.type)
.attr('id', fieldID)
.attr('placeholder', field.placeholder() || t('inspector.unknown'))
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.classed(field.type, true)
.call(utilNoAuto)
.merge(input);
+2 -2
View File
@@ -147,7 +147,7 @@ export function uiFieldLocalized(field, context) {
.attr('id', 'preset-input-' + field.safeid)
.attr('class', 'localized-main')
.attr('placeholder', field.placeholder())
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.call(utilNoAuto)
.merge(input);
@@ -511,7 +511,7 @@ export function uiFieldLocalized(field, context) {
.append('input')
.attr('type', 'text')
.attr('placeholder', t('translate.localized_translation_name'))
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.attr('class', 'localized-value')
.on('blur', changeValue)
.on('change', changeValue);
+1 -2
View File
@@ -2,7 +2,6 @@ import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select } from 'd3-selection';
import * as countryCoder from '@ideditor/country-coder';
import { services } from '../../services';
import { uiCombobox } from '../combobox';
import { utilGetSetValue, utilNoAuto, utilRebind } from '../../util';
@@ -40,7 +39,7 @@ export function uiFieldMaxspeed(field, context) {
.append('input')
.attr('type', 'text')
.attr('id', 'preset-input-' + field.safeid)
.attr('maxlength', services.osm.maxCharsForTagValue() - 4)
.attr('maxlength', context.maxCharsForTagValue() - 4)
.attr('placeholder', field.placeholder())
.call(utilNoAuto)
.call(speedCombo)
+2 -3
View File
@@ -1,7 +1,6 @@
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { select as d3_select } from 'd3-selection';
import { services } from '../../services';
import { t } from '../../util/locale';
import {
utilGetSetValue,
@@ -10,7 +9,7 @@ import {
} from '../../util';
export function uiFieldTextarea(field) {
export function uiFieldTextarea(field, context) {
var dispatch = d3_dispatch('change');
var input = d3_select(null);
@@ -31,7 +30,7 @@ export function uiFieldTextarea(field) {
.append('textarea')
.attr('id', 'preset-input-' + field.safeid)
.attr('placeholder', field.placeholder() || t('inspector.unknown'))
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.call(utilNoAuto)
.on('input', change(true))
.on('blur', change())
+2 -2
View File
@@ -198,7 +198,7 @@ export function uiFieldWikidata(field, context) {
var siteID = lang.replace('-', '_') + 'wiki';
if (entity.sitelinks[siteID]) {
foundPreferred = true;
currTags[_wikipediaKey] = (lang + ':' + entity.sitelinks[siteID].title).substr(0, services.osm.maxCharsForTagValue());
currTags[_wikipediaKey] = (lang + ':' + entity.sitelinks[siteID].title).substr(0, context.maxCharsForTagValue());
// use the first match
break;
}
@@ -220,7 +220,7 @@ export function uiFieldWikidata(field, context) {
} else {
var wikiLang = wikiSiteKeys[0].slice(0, -4).replace('_', '-');
var wikiTitle = entity.sitelinks[wikiSiteKeys[0]].title;
currTags[_wikipediaKey] = (wikiLang + ':' + wikiTitle).substr(0, services.osm.maxCharsForTagValue());
currTags[_wikipediaKey] = (wikiLang + ':' + wikiTitle).substr(0, context.maxCharsForTagValue());
}
}
}
+2 -2
View File
@@ -106,7 +106,7 @@ export function uiFieldWikipedia(field, context) {
.attr('type', 'text')
.attr('class', 'wiki-title')
.attr('id', 'preset-input-' + field.safeid)
.attr('maxlength', services.osm.maxCharsForTagValue() - 4)
.attr('maxlength', context.maxCharsForTagValue() - 4)
.call(utilNoAuto)
.call(titleCombo)
.merge(title);
@@ -185,7 +185,7 @@ export function uiFieldWikipedia(field, context) {
}
if (value) {
syncTags.wikipedia = (language()[2] + ':' + value).substr(0, services.osm.maxCharsForTagValue());
syncTags.wikipedia = (language()[2] + ':' + value).substr(0, context.maxCharsForTagValue());
} else {
syncTags.wikipedia = undefined;
}
+1 -1
View File
@@ -209,7 +209,7 @@ export function uiRawMemberEditor(context) {
.append('input')
.attr('class', 'member-role')
.property('type', 'text')
.attr('maxlength', services.osm.maxCharsForRelationRole())
.attr('maxlength', context.maxCharsForRelationRole())
.attr('placeholder', t('inspector.role'))
.call(utilNoAuto);
+2 -2
View File
@@ -248,7 +248,7 @@ export function uiRawMembershipEditor(context) {
.append('input')
.attr('class', 'member-role')
.property('type', 'text')
.attr('maxlength', services.osm.maxCharsForRelationRole())
.attr('maxlength', context.maxCharsForRelationRole())
.attr('placeholder', t('inspector.role'))
.call(utilNoAuto)
.property('value', function(d) { return d.member.role; })
@@ -296,7 +296,7 @@ export function uiRawMembershipEditor(context) {
.append('input')
.attr('class', 'member-role')
.property('type', 'text')
.attr('maxlength', services.osm.maxCharsForRelationRole())
.attr('maxlength', context.maxCharsForRelationRole())
.attr('placeholder', t('inspector.role'))
.call(utilNoAuto);
+4 -4
View File
@@ -207,7 +207,7 @@ export function uiRawTagEditor(context) {
.append('input')
.property('type', 'text')
.attr('class', 'key')
.attr('maxlength', services.osm.maxCharsForTagKey())
.attr('maxlength', context.maxCharsForTagKey())
.call(utilNoAuto)
.on('blur', keyChange)
.on('change', keyChange);
@@ -218,7 +218,7 @@ export function uiRawTagEditor(context) {
.append('input')
.property('type', 'text')
.attr('class', 'value')
.attr('maxlength', services.osm.maxCharsForTagValue())
.attr('maxlength', context.maxCharsForTagValue())
.call(utilNoAuto)
.on('blur', valueChange)
.on('change', valueChange)
@@ -362,8 +362,8 @@ export function uiRawTagEditor(context) {
function textChanged() {
var newText = this.value.trim();
var newTags = {};
var maxKeyLength = services.osm.maxCharsForTagKey();
var maxValueLength = services.osm.maxCharsForTagValue();
var maxKeyLength = context.maxCharsForTagKey();
var maxValueLength = context.maxCharsForTagValue();
newText.split('\n').forEach(function(row) {
var m = row.match(/^\s*([^=]+)=(.*)$/);
if (m !== null) {