From 89ce98f510dc39430f9687a6744ae941a9541479 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Tue, 28 Jan 2020 09:28:23 -0500 Subject: [PATCH] Don't require services/osm in order to get max OSM character lengths --- modules/core/context.js | 13 +++++++++++++ modules/services/osm.js | 15 --------------- modules/ui/commit.js | 4 ++-- modules/ui/fields/access.js | 3 +-- modules/ui/fields/address.js | 3 +-- modules/ui/fields/combo.js | 6 +++--- modules/ui/fields/cycleway.js | 3 +-- modules/ui/fields/input.js | 3 +-- modules/ui/fields/localized.js | 4 ++-- modules/ui/fields/maxspeed.js | 3 +-- modules/ui/fields/textarea.js | 5 ++--- modules/ui/fields/wikidata.js | 4 ++-- modules/ui/fields/wikipedia.js | 4 ++-- modules/ui/raw_member_editor.js | 2 +- modules/ui/raw_membership_editor.js | 4 ++-- modules/ui/raw_tag_editor.js | 8 ++++---- 16 files changed, 38 insertions(+), 46 deletions(-) diff --git a/modules/core/context.js b/modules/core/context.js index 75ff71036..dd9eab7b2 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -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) { diff --git a/modules/services/osm.js b/modules/services/osm.js index 52fb389c7..082a84ea5 100644 --- a/modules/services/osm.js +++ b/modules/services/osm.js @@ -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(); }, diff --git a/modules/ui/commit.js b/modules/ui/commit.js index 3be15faf8..3713705df 100644 --- a/modules/ui/commit.js +++ b/modules/ui/commit.js @@ -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]; diff --git a/modules/ui/fields/access.js b/modules/ui/fields/access.js index 15f902960..262f0a673 100644 --- a/modules/ui/fields/access.js +++ b/modules/ui/fields/access.js @@ -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) { diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index 9425208a7..6783a4611 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -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) diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index e9cc277b1..aeec7a2d4 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -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 diff --git a/modules/ui/fields/cycleway.js b/modules/ui/fields/cycleway.js index abc833a73..199192424 100644 --- a/modules/ui/fields/cycleway.js +++ b/modules/ui/fields/cycleway.js @@ -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) { diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index 7a0152702..7335f9bae 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -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); diff --git a/modules/ui/fields/localized.js b/modules/ui/fields/localized.js index deaad2d38..1f42e2036 100644 --- a/modules/ui/fields/localized.js +++ b/modules/ui/fields/localized.js @@ -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); diff --git a/modules/ui/fields/maxspeed.js b/modules/ui/fields/maxspeed.js index e1c853b1b..bfd2e171a 100644 --- a/modules/ui/fields/maxspeed.js +++ b/modules/ui/fields/maxspeed.js @@ -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) diff --git a/modules/ui/fields/textarea.js b/modules/ui/fields/textarea.js index be218e074..66efba529 100644 --- a/modules/ui/fields/textarea.js +++ b/modules/ui/fields/textarea.js @@ -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()) diff --git a/modules/ui/fields/wikidata.js b/modules/ui/fields/wikidata.js index 2668dc8c4..bcd4107da 100644 --- a/modules/ui/fields/wikidata.js +++ b/modules/ui/fields/wikidata.js @@ -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()); } } } diff --git a/modules/ui/fields/wikipedia.js b/modules/ui/fields/wikipedia.js index af9175cb4..bfef413e8 100644 --- a/modules/ui/fields/wikipedia.js +++ b/modules/ui/fields/wikipedia.js @@ -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; } diff --git a/modules/ui/raw_member_editor.js b/modules/ui/raw_member_editor.js index 67a957d94..bf6a616be 100644 --- a/modules/ui/raw_member_editor.js +++ b/modules/ui/raw_member_editor.js @@ -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); diff --git a/modules/ui/raw_membership_editor.js b/modules/ui/raw_membership_editor.js index d557000ac..78422ec6b 100644 --- a/modules/ui/raw_membership_editor.js +++ b/modules/ui/raw_membership_editor.js @@ -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); diff --git a/modules/ui/raw_tag_editor.js b/modules/ui/raw_tag_editor.js index 9691ff4f0..39cd4eb40 100644 --- a/modules/ui/raw_tag_editor.js +++ b/modules/ui/raw_tag_editor.js @@ -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) {