From b0800c10ed0fcc483c410cf1f83eb1848c4a2269 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 5 Jan 2021 10:32:01 -0500 Subject: [PATCH] Update to name-suggestion-index v5 Merge in NSI presets after UI has initialized --- modules/core/context.js | 28 +++++++++++++++++++++------- modules/core/file_fetcher.js | 11 +++++++++++ package.json | 2 +- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/modules/core/context.js b/modules/core/context.js index c0d902e9e..9427aaf6b 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -6,7 +6,7 @@ import { select as d3_select } from 'd3-selection'; import { t } from '../core/localizer'; -import { fileFetcher as data } from './file_fetcher'; +import { fileFetcher } from './file_fetcher'; import { localizer } from './localizer'; import { prefs } from './preferences'; import { coreHistory } from './history'; @@ -447,7 +447,7 @@ export function coreContext() { context.assetPath = function(val) { if (!arguments.length) return _assetPath; _assetPath = val; - data.assetPath(val); + fileFetcher.assetPath(val); return context; }; @@ -455,7 +455,7 @@ export function coreContext() { context.assetMap = function(val) { if (!arguments.length) return _assetMap; _assetMap = val; - data.assetMap(val); + fileFetcher.assetMap(val); return context; }; @@ -576,13 +576,27 @@ export function coreContext() { // if the container isn't available, e.g. when testing, don't load the UI if (!context.container().empty()) { - _ui.ensureLoaded().then(function() { - _photos.init(); - }); + _ui.ensureLoaded() + .then(() => { + _photos.init(); + loadNSIPresets(); + }); } } - }; + function loadNSIPresets() { + return fileFetcher.get('nsi_presets') + .then(d => { + // Add `suggestion=true` to all the nsi presets + // The preset json schema doesn't include it, but the iD code still uses it + Object.values(d.presets).forEach(preset => preset.suggestion = true); + presetManager.merge({ presets: d.presets }); + }) + .catch(() => { /* ignore */ }); + } + + }; + return context; } diff --git a/modules/core/file_fetcher.js b/modules/core/file_fetcher.js index a51b61c47..548ed3d6e 100644 --- a/modules/core/file_fetcher.js +++ b/modules/core/file_fetcher.js @@ -19,8 +19,19 @@ export function coreFileFetcher() { 'keepRight': 'data/keepRight.min.json', 'languages': 'data/languages.min.json', 'locales': 'locales/index.min.json', + + // old 'nsi_brands': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@4/dist/brands.min.json', 'nsi_filters': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@4/dist/filters.min.json', + + // new + 'nsi_presets': 'https://raw.githubusercontent.com/osmlab/name-suggestion-index/main/dist/presets/nsi-id-presets.min.json', + 'nsi_data': 'https://raw.githubusercontent.com/osmlab/name-suggestion-index/main/dist/nsi.min.json', + 'nsi_features': 'https://raw.githubusercontent.com/osmlab/name-suggestion-index/main/dist/featureCollection.min.json', + 'nsi_generics': 'https://raw.githubusercontent.com/osmlab/name-suggestion-index/main/dist/genericWords.min.json', + 'nsi_replacements': 'https://raw.githubusercontent.com/osmlab/name-suggestion-index/main/dist/replacements.min.json', + 'nsi_trees': 'https://raw.githubusercontent.com/osmlab/name-suggestion-index/main/dist/trees.min.json', + 'oci_features': 'https://cdn.jsdelivr.net/npm/osm-community-index@3/dist/featureCollection.min.json', 'oci_resources': 'https://cdn.jsdelivr.net/npm/osm-community-index@3/dist/resources.min.json', 'preset_categories': 'https://cdn.jsdelivr.net/npm/@openstreetmap/id-tagging-schema@3/dist/preset_categories.min.json', diff --git a/package.json b/package.json index 7b0f70a21..18b2365d1 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "minimist": "^1.2.3", "mocha": "^7.0.1", "mocha-phantomjs-core": "^2.1.0", - "name-suggestion-index": "4.0.2", + "name-suggestion-index": "^5.0.0", "node-fetch": "^2.6.1", "npm-run-all": "^4.0.0", "object-inspect": "1.9.0",