Skip to content

Commit

Permalink
Merge branch 'the-sacrifice'
Browse files Browse the repository at this point in the history
Testing the waters with CI.
  • Loading branch information
erictheise committed Jul 6, 2024
2 parents 1c07ace + 8f8a34c commit 87040cb
Show file tree
Hide file tree
Showing 22 changed files with 5,500 additions and 3,639 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ jobs:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18"
- run: yarn install --no-progress --frozen-lockfile
node-version: "20"
- run: corepack enable
- run: yarn install
- run: yarn test
- run: yarn build
- name: Deploy to https://${{ github.actor }}.github.io/${{ github.event.repository.name }}/
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ overpass-turbo-ffs.min.js
build
node_modules
transifex.auth
.yarn/
build/
dist/
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint-staged
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
4 changes: 3 additions & 1 deletion css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ kbd {
background-color: #e1e3e5;
border: 1px solid #adb3b8;
border-radius: 3px;
box-shadow: 0 1px 0 rgba(12, 13, 14, 0.2), 0 0 0 2px #fff inset;
box-shadow:
0 1px 0 rgba(12, 13, 14, 0.2),
0 0 0 2px #fff inset;
white-space: nowrap;
}
28 changes: 14 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta
Expand Down Expand Up @@ -322,10 +322,10 @@ <h4 class="t" data-t="help.export.query_data.title"></h4>
</div>
<h3 class="t" data-t="help.section.about"></h3>
<div>
<a href="http://overpass-api.de">
<a href="https://overpass-api.de">
<img
style="float: right"
src="//wiki.openstreetmap.org/w/images/b/b3/Powered_by_Overpass_API.png"
src="https://wiki.openstreetmap.org/w/images/b/b3/Powered_by_Overpass_API.png"
alt="powered by Overpass API"
/></a>
<p class="t" data-t="[html]help.about.maintained"></p>
Expand All @@ -342,12 +342,12 @@ <h4 class="t" data-t="help.attr.data_sources"></h4>
<li class="t" data-t="[html]help.attr.data"></li>
<li>
<span class="t" data-t="help.attr.mining"></span>
<a href="http://overpass-api.de/">Overpass API</a>
<a href="https://overpass-api.de/">Overpass API</a>
</li>
<li class="t" data-t="[html]help.attr.tiles"></li>
<li>
<span class="t" data-t="help.attr.search"></span>
<a href="http://wiki.openstreetmap.org/wiki/Nominatim"
<a href="https://wiki.openstreetmap.org/wiki/Nominatim"
>Nominatim</a
>
</li>
Expand All @@ -356,11 +356,11 @@ <h4 class="t" data-t="help.attr.software"></h4>
<ul class="plain">
<li>
<span class="t" data-t="help.attr.leaflet"></span>
<a href="http://leaflet.cloudmade.com">Leaflet</a>
<a href="https://leafletjs.com/">Leaflet</a>
</li>
<li>
<span class="t" data-t="help.attr.codemirror"></span>
<a href="http://codemirror.net/">CodeMirror</a>
<a href="https://codemirror.net/">CodeMirror</a>
</li>
<li>
<span class="t" data-t="help.attr.other_libs"></span>
Expand Down Expand Up @@ -1110,13 +1110,13 @@ <h3 class="t subtitle" data-t="share.options"></h3>
running (significant parts of) this Application.
<small>
It must support
<a href="http://en.wikipedia.org/wiki/Web_storage#localStorage">
<a href="https://en.wikipedia.org/wiki/Web_storage#localStorage">
Web Storage API
</a>

and
<a
href="http://en.wikipedia.org/wiki/Cross-origin_resource_sharing"
href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing"
>
cross origin resource sharing (CORS)
</a>
Expand All @@ -1130,11 +1130,11 @@ <h3 class="t subtitle" data-t="share.options"></h3>
<p class="t" data-t="[html]warning.browser.expl.3">
Please upgrade to a more up-to-date version of your browser or
switch to a more capable one! Recent versions of
<a href="http://www.opera.com">Opera</a>,
<a href="http://www.google.com/intl/de/chrome/browser/">Chrome</a>
and <a href="http://www.mozilla.org/de/firefox/">Firefox</a> have
been tested to work. Alternatively, you can still use the
<a href="http://overpass-api.de/query_form.html">
<a href="https://www.opera.com">Opera</a>,
<a href="https://www.google.com/chrome/">Chrome</a>
and <a href="https://www.mozilla.org/firefox/">Firefox</a> have been
tested to work. Alternatively, you can still use the
<a href="https://overpass-api.de/query_form.html">
Overpass_API query form
</a>
.
Expand Down
4 changes: 2 additions & 2 deletions js/autorepair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ export default function autorepair(q, lng) {
"$1xml$3/*fixed by auto repair*/"
);
// 2. fix print statements: non meta output, overpass geometries
const prints = q.match(/(\.([^;.]+?)\s+)?(out[^:;"\]]*;)/g) || [];
const prints = q.match(/(\.([^;.]+?)\s+)?(\bout\b[^:;"\]]*;)/g) || [];
for (const print_i of prints) {
// eslint-disable-next-line prefer-const
let [print, , out_set, out_statement] = print_i.match(
/(\.([^;.]+?)\s+)?(out[^:;"\]]*;)/
/(\.([^;.]+?)\s+)?(\bout[^:;"\]]*;)/
);
let new_print = print;
let new_out_statement;
Expand Down
44 changes: 37 additions & 7 deletions js/ffs/free.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@
import i18n from "../i18n";
import {levenshteinDistance} from "../misc";

type Presets = Record<string, Preset>;

type Preset = {
// overpass-turbo
name?: string;
nameCased?: string;
terms?: string[];
translated?: boolean;
// upstream
fields?: string[];
moreFields?: string[];
geometry: string[];
tags: {[key: string]: string};
searchable?: boolean;
icon?: string;
matchScore?: number;
addTags?: {[key: string]: string};
removeTags?: Record<string, string>;
reference?: {key: string; value?: string};
replacement?: string;
locationSet?: {exclude?: string[]; include?: string[]};
};

const freeFormQuery = {};
let presets = {};
let presets: Presets = {};

export function setPresets(newPresets) {
export function setPresets(newPresets: Presets) {
presets = newPresets;
Object.values(presets).forEach((preset) => {
preset.nameCased = preset.name;
Expand Down Expand Up @@ -40,16 +63,23 @@ export default function ffs_free(callback) {
}
// load preset translations
async function loadPresetTranslations() {
const language = i18n.getLanguage();
let language = i18n.getLanguage();
if (!language) return;
try {
let {default: data} = await import(
`../../node_modules/@openstreetmap/id-tagging-schema/dist/translations/${language}.json`
);
if (language.length > 2 && !data[language]?.presets?.presets) {
language = language.slice(0, 2);
const {default: data2} = await import(
`../../node_modules/@openstreetmap/id-tagging-schema/dist/translations/${language}.json`
);
data = data2;
}
data = data[language].presets.presets;
// load translated names and terms into presets object
Object.entries(data).forEach(([preset, translation]) => {
preset = presets[preset];
Object.entries(data).forEach(([presetName, translation]) => {
const preset = presets[presetName];
preset.translated = true;
// save original preset name under alternative terms
const oriPresetName = preset.name;
Expand Down Expand Up @@ -134,8 +164,8 @@ freeFormQuery.fuzzy_search = (condition) => {
}
const candidates = Object.values(presets).filter((preset) => {
if (preset.searchable === false) return false;
if (fuzzyMatch(preset.name)) return true;
return preset.terms.some(fuzzyMatch);
if (preset.name && fuzzyMatch(preset.name)) return true;
return Array.isArray(preset.terms) && preset.terms.some(fuzzyMatch);
});
if (candidates.length === 0) return false;
// sort candidates
Expand Down
2 changes: 1 addition & 1 deletion js/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class i18n {
static getSupportedLanguagesDescriptions() {
return languages;
}
static getLanguage(lng: Language | string): Language {
static getLanguage(lng?: Language | string): Language {
lng = lng || settings.ui_language;
if (lng == "auto") {
// get user agent's language
Expand Down
53 changes: 24 additions & 29 deletions js/ide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1552,18 +1552,16 @@ class IDE {
queryWithMapCSS += `{{data:${this.queryParser.getStatement("data")}}}`;
else if (settings.server !== configs.defaultServer)
queryWithMapCSS += `{{data:overpass,server=${settings.server}}}`;
$(
"#export-dialog a#export-interactive-map"
)[0].href = `${baseurl}map.html?${new URLSearchParams({
Q: queryWithMapCSS
})}`;
$("#export-dialog a#export-interactive-map")[0].href =
`${baseurl}map.html?${new URLSearchParams({
Q: queryWithMapCSS
})}`;
// encoding exclamation marks for better command line usability (bash)
$(
"#export-dialog a#export-overpass-api"
)[0].href = `${server}interpreter?data=${encodeURIComponent(query)
.replace(/!/g, "%21")
.replace(/\(/g, "%28")
.replace(/\)/g, "%29")}`;
$("#export-dialog a#export-overpass-api")[0].href =
`${server}interpreter?data=${encodeURIComponent(query)
.replace(/!/g, "%21")
.replace(/\(/g, "%28")
.replace(/\)/g, "%29")}`;
function toDataURL(text, mediatype) {
return `data:${mediatype || "text/plain"};charset=${
document.characterSet || document.charset
Expand Down Expand Up @@ -2060,24 +2058,21 @@ class IDE {
return false;
});

$(
"#export-dialog a#export-convert-xml"
)[0].href = `${server}convert?${new URLSearchParams({
data: query,
target: "xml"
})}`;
$(
"#export-dialog a#export-convert-ql"
)[0].href = `${server}convert?${new URLSearchParams({
data: query,
target: "mapql"
})}`;
$(
"#export-dialog a#export-convert-compact"
)[0].href = `${server}convert?${new URLSearchParams({
data: query,
target: "compact"
})}`;
$("#export-dialog a#export-convert-xml")[0].href =
`${server}convert?${new URLSearchParams({
data: query,
target: "xml"
})}`;
$("#export-dialog a#export-convert-ql")[0].href =
`${server}convert?${new URLSearchParams({
data: query,
target: "mapql"
})}`;
$("#export-dialog a#export-convert-compact")[0].href =
`${server}convert?${new URLSearchParams({
data: query,
target: "compact"
})}`;

// OSM editors
// first check for possible mistakes in query.
Expand Down
7 changes: 6 additions & 1 deletion js/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ export function featurePopupContent(feature: GeoJSON.Feature) {
(k.match(/(^|:)wikipedia$/) &&
(wiki_lang = v.match(/^([a-zA-Z]+):(.*)$/)) &&
(wiki_page = wiki_lang[2]))
)
) {
wiki_page = wiki_page.replace(/#.*$/, (match) =>
// 'Target page#Section header' -> 'Target page#Section_header'
match.replace(/ /g, "_")
);
v = `<a href="//${wiki_lang[1]}.wikipedia.org/wiki/${wiki_page}" target="_blank">${v}</a>`;
}
// hyperlinks for wikidata entries
if (k.match(/(^|:)wikidata$/))
v = v.replace(
Expand Down
2 changes: 1 addition & 1 deletion land.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head></head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion map.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta
Expand Down
19 changes: 8 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"homepage": "http://overpass-turbo.eu/",
"repository": "git+https://github.com/OpenHistoricalMap/overpass-turbo.git",
"license": "MIT",
"packageManager": "[email protected]",
"scripts": {
"prepare": "husky",
"test": "yarn run test:eslint && yarn run test:style && yarn run test:vitest",
"test:eslint": "eslint .",
"test:style": "prettier --check .",
Expand All @@ -23,16 +25,16 @@
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.38.0",
"happy-dom": "^8.1.5",
"husky": "^4.3.0",
"lint-staged": "^13.2.1",
"happy-dom": "^14.12.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"peggy": "^3.0.2",
"prettier": "^2.8.7",
"prettier": "^3.3.2",
"request": "^2.67.0",
"typescript": "^5.0.4",
"vite": "^4.5.2",
"vite": "^5.2.13",
"vite-plugin-favicons-inject": "^2.2.0",
"vitest": "^0.29.8"
"vitest": "^1.6.0"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.13.0",
Expand Down Expand Up @@ -62,11 +64,6 @@
"bracketSpacing": false,
"trailingComma": "none"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
}
Expand Down
8 changes: 6 additions & 2 deletions tests/test.autorepair.josm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ describe("ide.autorepair.josm", () => {
},
{
// more complex real world example
inp: '<osm-script output="xml">\n <query type="node">\n <has-kv k="amenity" v="drinking_water"/>\n <bbox-query {{bbox}}/>\n </query>\n <print mode="body" order="quadtile"/>\n</osm-script>',
outp: '<osm-script output="xml">\n <query type="node">\n <has-kv k="amenity" v="drinking_water"/>\n <bbox-query {{bbox}}/>\n </query>\n <print mode="meta" order="quadtile"></print><!-- fixed by auto repair -->\n</osm-script>'
inp: '<osm-script output="xml">\n <query type="node">\n <has-kv k="amenity" v="drinking_water"/>\n <bbox-query {{bbox}}/>\n </query>\n <print order="quadtile" mode="body"/>\n</osm-script>',
outp: '<osm-script output="xml">\n <query type="node">\n <has-kv k="amenity" v="drinking_water"/>\n <bbox-query {{bbox}}/>\n </query>\n <print order="quadtile" mode="meta"></print><!-- fixed by auto repair -->\n</osm-script>'
}
];
vi.spyOn(ide, "getQueryLang").mockImplementation(() => "xml");
Expand Down Expand Up @@ -121,6 +121,10 @@ describe("ide.autorepair.josm", () => {
// more complex real world example
inp: '/*bla*/\n[out:xml];\nway\n ["amenity"]\n ({{bbox}})\n->.foo;\n.foo out qt;',
outp: '/*bla*/\n[out:xml];\nway\n ["amenity"]\n ({{bbox}})\n->.foo;\n.foo out meta qt;/*fixed by auto repair*/'
},
{
inp: "{{geocodeArea:South Carolina}}->.searchArea;",
outp: "{{geocodeArea:South Carolina}}->.searchArea;"
}
];
vi.spyOn(ide, "getQueryLang").mockImplementation(() => "OverpassQL");
Expand Down
Loading

0 comments on commit 87040cb

Please sign in to comment.