mirror of
https://github.com/maputnik/editor.git
synced 2026-09-01 18:07:37 +00:00
Compare commits
212 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a192b04135 | |||
| a36f56fe93 | |||
| 1a7754c78d | |||
| de777102e1 | |||
| 6c9f0fefc9 | |||
| 6af3eeefb6 | |||
| 1318dd279e | |||
| af8caef9d3 | |||
| 12def85771 | |||
| fa182e66fa | |||
| 3bf0e510e6 | |||
| e8d07fa694 | |||
| 4d1e2e6893 | |||
| f219ff1e17 | |||
| 8eabfa5519 | |||
| ad69cbdb20 | |||
| 17eaa3f204 | |||
| 1df2e36dbb | |||
| 0c46affda9 | |||
| 18f45e932b | |||
| 31d56c9fae | |||
| b7838ad6e1 | |||
| c92fd12854 | |||
| eb55796461 | |||
| 4b97f82980 | |||
| 5d0b6e3201 | |||
| 5ab9be9fdb | |||
| 9659d41b83 | |||
| 52f949e152 | |||
| e4d559f953 | |||
| 577663f706 | |||
| 393f4a38b9 | |||
| 3727c9ad5e | |||
| a99cbc00ba | |||
| fe5f7e8b8c | |||
| 3ed4b8f2d7 | |||
| f17c2e8112 | |||
| 2be447f105 | |||
| 2fe6fa2be6 | |||
| 83dd21414b | |||
| 56d96a248d | |||
| 5b1ee7296b | |||
| 8e0546fba4 | |||
| 2ff3d08bb0 | |||
| afe7a492a7 | |||
| 1f26ab707f | |||
| 233191e27c | |||
| 246f9a191d | |||
| 07f6efe45d | |||
| ccd0402eea | |||
| 8ccee0ba75 | |||
| d6b67be7b2 | |||
| ac56ea4627 | |||
| b00cf66ea6 | |||
| 8e329a0ff9 | |||
| 74cacd5bdf | |||
| 7d5fb23130 | |||
| 08bbd55f13 | |||
| d6d4930513 | |||
| 6220e15723 | |||
| 72053a2dba | |||
| bf27a35ef5 | |||
| 4705bf823a | |||
| a8f6208561 | |||
| af2629be75 | |||
| 8bfad6c9fd | |||
| 5c3713da90 | |||
| 174eae1cf4 | |||
| d73add77e7 | |||
| ab00c9f426 | |||
| d6ab302815 | |||
| f5646f57d1 | |||
| c77d8f6625 | |||
| e34c1ca4be | |||
| 87745f1fc9 | |||
| 9ba0fd5f39 | |||
| 70decbb5c1 | |||
| 51fa4a4377 | |||
| fb6f4d73e2 | |||
| 63b14933ba | |||
| a86c31cefa | |||
| 25e2554412 | |||
| 34bb3bc0a7 | |||
| 852243cd52 | |||
| 40faf86adf | |||
| bb69f143b8 | |||
| bb43200887 | |||
| ae3f79f4ad | |||
| 731a315624 | |||
| 5e441454d5 | |||
| a55716bbd9 | |||
| 44aea3745e | |||
| a572bc02a6 | |||
| 4dee95fa2e | |||
| 381ff6292f | |||
| c12db1703b | |||
| 2676583833 | |||
| 6ca2af7f8a | |||
| 553b17822d | |||
| a6148e5f40 | |||
| 4f77629eb7 | |||
| 9103d9560a | |||
| 06c63509f7 | |||
| bbe0af6c0e | |||
| 7455ccc3b7 | |||
| 8b766777ac | |||
| 8441abe907 | |||
| ca56951256 | |||
| 5981151b27 | |||
| 21dbc6c4d9 | |||
| 6f060c2a0a | |||
| 24327541c5 | |||
| 0d6b9ee9d4 | |||
| 3ad487dce7 | |||
| a46c834874 | |||
| 67bdea1827 | |||
| cc4133aac1 | |||
| 4a6f58d61c | |||
| e3dc98b76d | |||
| 09373dda44 | |||
| c4b05b62b3 | |||
| 06bccfab10 | |||
| b83c9a1ad9 | |||
| 0279daf7bd | |||
| bfada7cace | |||
| 6c751fe1c4 | |||
| 34299c94ee | |||
| 5804b3c72a | |||
| 8ae6e9fc61 | |||
| 40579c3e0c | |||
| f3906c8dd8 | |||
| f911ed3522 | |||
| 2cc179acc1 | |||
| 2912db6e32 | |||
| 70eb3e785a | |||
| 8f944d9973 | |||
| 8faf841f3d | |||
| d8ba8fcbfb | |||
| d6f31ec82e | |||
| b19eacf4f9 | |||
| 3d158a791a | |||
| 04b3b42524 | |||
| af92aac7ec | |||
| 90dfbf37e0 | |||
| e21f412933 | |||
| da297fe82c | |||
| 624ccb5b00 | |||
| 9f0e5641ab | |||
| d07b40ccef | |||
| e0abd8251d | |||
| 324452e714 | |||
| 8d3ad6b1a1 | |||
| 3d4cc34a08 | |||
| ff351716b6 | |||
| c963a8cc59 | |||
| 52ad980aef | |||
| fb04cce650 | |||
| 4b8acb10b0 | |||
| 86d67389fc | |||
| 9dad53e444 | |||
| d5afeb14c1 | |||
| 85bb1d4d40 | |||
| d95e25d185 | |||
| a88f2bc0a3 | |||
| 5a4254d300 | |||
| 6bfe2aa364 | |||
| 0acd1fec0a | |||
| 3046fedb55 | |||
| 1574b49b01 | |||
| 4417a2d8f1 | |||
| 1f34e927e7 | |||
| 9af6a537ef | |||
| 6e07142f13 | |||
| d2853f34a4 | |||
| 7faed0d27e | |||
| 22101f93ad | |||
| 0661899d54 | |||
| 862ac84464 | |||
| 1e4aadbb6d | |||
| ce731e7d6b | |||
| 5448cdbe4e | |||
| 315a9b82c0 | |||
| 9e1c0e4c82 | |||
| 7db675e0d1 | |||
| 0aa629164a | |||
| c2ec77e869 | |||
| b28407a4a0 | |||
| e3e6647e03 | |||
| eb0f833d49 | |||
| c5c1dd12b9 | |||
| b7e414a042 | |||
| 81a6f31803 | |||
| 65cd050a18 | |||
| c426dd7349 | |||
| c5af645546 | |||
| 1bf0abfb5a | |||
| 18338de21a | |||
| 857117eb71 | |||
| 8d86bca8b3 | |||
| dc4e6a0925 | |||
| e9d6119ac6 | |||
| cbdf45c852 | |||
| a191c36f96 | |||
| 0a8d0974ca | |||
| 8e6c54564b | |||
| 4bbe2ce1ea | |||
| 1d48ab7ecf | |||
| d85ed36e70 | |||
| b554f4427b | |||
| 2a832955c4 | |||
| 608b836fe0 | |||
| de9c4fcc4a |
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"presets": [
|
|
||||||
"@babel/preset-env",
|
|
||||||
"@babel/preset-react"
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
"static-fs",
|
|
||||||
"react-hot-loader/babel",
|
|
||||||
"@babel/plugin-proposal-class-properties"
|
|
||||||
],
|
|
||||||
"env": {
|
|
||||||
"test": {
|
|
||||||
"plugins": [
|
|
||||||
["istanbul", {
|
|
||||||
"exclude": ["node_modules/**", "test/**"]
|
|
||||||
}]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
version: 2
|
|
||||||
templates:
|
|
||||||
# Test the build **only** no webdriver
|
|
||||||
build-steps: &build-steps
|
|
||||||
- checkout
|
|
||||||
- run:
|
|
||||||
name: "Create artifacts directory"
|
|
||||||
command: mkdir /tmp/artifacts
|
|
||||||
- restore_cache:
|
|
||||||
key: v1-dependencies-{{ arch }}-{{ checksum "package.json" }}
|
|
||||||
|
|
||||||
- run: npm install
|
|
||||||
|
|
||||||
- save_cache:
|
|
||||||
paths:
|
|
||||||
- node_modules
|
|
||||||
key: v1-dependencies-{{ arch }}-{{ checksum "package.json" }}
|
|
||||||
|
|
||||||
- run: mkdir -p /tmp/artifacts/logs
|
|
||||||
- run: npm run build
|
|
||||||
- run: npm run lint-js
|
|
||||||
- run: npm run lint-css
|
|
||||||
- store_artifacts:
|
|
||||||
path: /tmp/artifacts
|
|
||||||
destination: /artifacts
|
|
||||||
# Test in webdriver
|
|
||||||
wdio-steps: &wdio-steps
|
|
||||||
- checkout
|
|
||||||
- run:
|
|
||||||
name: "Create artifacts directory"
|
|
||||||
command: mkdir /tmp/artifacts
|
|
||||||
- restore_cache:
|
|
||||||
key: v1-dependencies-{{ arch }}-{{ checksum "package.json" }}
|
|
||||||
|
|
||||||
- run: npm install
|
|
||||||
|
|
||||||
- save_cache:
|
|
||||||
paths:
|
|
||||||
- node_modules
|
|
||||||
key: v1-dependencies-{{ arch }}-{{ checksum "package.json" }}
|
|
||||||
|
|
||||||
- run: mkdir -p /tmp/artifacts/logs
|
|
||||||
- run: npm run build
|
|
||||||
- run: npm run profiling-build
|
|
||||||
- run: npm run lint-js
|
|
||||||
- run: npm run lint-css
|
|
||||||
- run: DOCKER_HOST=localhost npm test
|
|
||||||
- run: ./node_modules/.bin/istanbul report --include /tmp/artifacts/coverage/coverage.json --dir /tmp/artifacts/coverage html lcov
|
|
||||||
- store_artifacts:
|
|
||||||
path: /tmp/artifacts
|
|
||||||
destination: /artifacts
|
|
||||||
jobs:
|
|
||||||
build-linux-node-v10:
|
|
||||||
docker:
|
|
||||||
- image: node:10
|
|
||||||
- image: selenium/standalone-chrome:3.141.59
|
|
||||||
working_directory: ~/repo-linux-node-v10
|
|
||||||
steps: *wdio-steps
|
|
||||||
build-linux-node-v12:
|
|
||||||
docker:
|
|
||||||
- image: node:12
|
|
||||||
working_directory: ~/repo-linux-node-v12
|
|
||||||
steps: *build-steps
|
|
||||||
build-linux-node-v13:
|
|
||||||
docker:
|
|
||||||
- image: node:13
|
|
||||||
working_directory: ~/repo-linux-node-v13
|
|
||||||
steps: *build-steps
|
|
||||||
build-osx-node-v10:
|
|
||||||
macos:
|
|
||||||
xcode: "9.0"
|
|
||||||
dependencies:
|
|
||||||
override:
|
|
||||||
- brew install node@10
|
|
||||||
working_directory: ~/repo-osx-node-v10
|
|
||||||
steps: *build-steps
|
|
||||||
build-osx-node-v12:
|
|
||||||
macos:
|
|
||||||
xcode: "9.0"
|
|
||||||
dependencies:
|
|
||||||
override:
|
|
||||||
- brew install node@12
|
|
||||||
working_directory: ~/repo-osx-node-v12
|
|
||||||
steps: *build-steps
|
|
||||||
build-osx-node-v13:
|
|
||||||
macos:
|
|
||||||
xcode: "9.0"
|
|
||||||
dependencies:
|
|
||||||
override:
|
|
||||||
- brew install node@13
|
|
||||||
working_directory: ~/repo-osx-node-v13
|
|
||||||
steps: *build-steps
|
|
||||||
|
|
||||||
workflows:
|
|
||||||
version: 2
|
|
||||||
build:
|
|
||||||
jobs:
|
|
||||||
- build-linux-node-v10
|
|
||||||
- build-linux-node-v12
|
|
||||||
- build-linux-node-v13
|
|
||||||
- build-osx-node-v10
|
|
||||||
- build-osx-node-v12
|
|
||||||
- build-osx-node-v13
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"packages": [],
|
||||||
|
"sandboxes": ["/"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
Dockerfile
|
||||||
|
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# COPIED FROM .gitignore , please keep it in sync
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directory
|
||||||
|
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Ignore build files
|
||||||
|
public
|
||||||
|
/errorShots
|
||||||
|
/old
|
||||||
|
/build
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
env: { browser: true, es2020: true },
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:react/recommended',
|
||||||
|
'plugin:react/jsx-runtime',
|
||||||
|
'plugin:react-hooks/recommended',
|
||||||
|
],
|
||||||
|
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||||
|
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
|
||||||
|
settings: { react: { version: '18.2' } },
|
||||||
|
plugins: ['react-refresh'],
|
||||||
|
rules: {
|
||||||
|
'react-refresh/only-export-components': [
|
||||||
|
'warn',
|
||||||
|
{ allowConstantExport: true },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve Maputnik
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- Thanks for your feedback! Please complete the following information: -->
|
||||||
|
|
||||||
|
**Maputnik version**:<!-- e.g v1.7.0, main -->
|
||||||
|
**Browser**:
|
||||||
|
**OS**:<!-- (Windows, macOS, Linux) -->
|
||||||
|
|
||||||
|
**Description of the bug**:
|
||||||
|
|
||||||
|
**Steps to reproduce the behavior**:
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
|
||||||
|
**Style file or style URL**:
|
||||||
|
<!-- If applicable, attach a style file (zip) or provide a style URL. -->
|
||||||
|
|
||||||
|
**Screenshots**:
|
||||||
|
<!-- If applicable, add screenshots to help explain your problem. -->
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
name: Other issue
|
||||||
|
about: Feature request or other issue which is no bug report
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- Thanks for reaching out! If you are having general Maputnik mapping questions, please asking them at https://gis.stackexchange.com/ using the 'maputnik' tag https://gis.stackexchange.com/questions/tagged/maputnik and read https://gis.stackexchange.com/help/how-to-ask before you do so (please keep in mind that you're asking there in a general GIS forum, not a dedicated support channel) -->
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
open-pull-requests-limit: 2
|
||||||
|
versioning-strategy: increase
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
open-pull-requests-limit: 2
|
||||||
|
versioning-strategy: increase
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-docker:
|
||||||
|
name: build/docker
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- run: docker build -t docker.pkg.github.com/maputnik/editor/editor:main .
|
||||||
|
|
||||||
|
# build the editor
|
||||||
|
build-node:
|
||||||
|
name: "build/node@${{ matrix.node-version }} (${{ matrix.os }})"
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
node-version: [18.x]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run build
|
||||||
|
|
||||||
|
|
||||||
|
build-artifacts:
|
||||||
|
name: "build/artifacts (${{ matrix.os }})"
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
node-version: [18.x]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
- uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run build
|
||||||
|
- run: npm run build-storybook
|
||||||
|
- name: artifacts/editor
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: editor
|
||||||
|
path: dist
|
||||||
|
- name: artifacts/storybook
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: storybook
|
||||||
|
path: build/storybook
|
||||||
|
|
||||||
|
# Build and upload desktop CLI artifacts
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ^1.19.x
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: maputnik/desktop
|
||||||
|
ref: master
|
||||||
|
path: ./src/github.com/maputnik/desktop/
|
||||||
|
|
||||||
|
- name: Make
|
||||||
|
run: cd src/github.com/maputnik/desktop/ && make
|
||||||
|
|
||||||
|
- name: Artifacts/linux
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: maputnik-linux
|
||||||
|
path: ./src/github.com/maputnik/desktop/bin/linux/
|
||||||
|
|
||||||
|
- name: Artifacts/darwin
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: maputnik-darwin
|
||||||
|
path: ./src/github.com/maputnik/desktop/bin/darwin/
|
||||||
|
|
||||||
|
- name: Artifacts/windows
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: maputnik-windows
|
||||||
|
path: ./src/github.com/maputnik/desktop/bin/windows/
|
||||||
|
|
||||||
|
cypress-run:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
browser: [chrome, firefox]
|
||||||
|
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- run: npm ci
|
||||||
|
- name: Cypress run
|
||||||
|
uses: cypress-io/github-action@v6
|
||||||
|
with:
|
||||||
|
build: npm run build
|
||||||
|
start: npm run start
|
||||||
|
browser: ${{ matrix.browser }}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
name: deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# publish docker to GitHub registry
|
||||||
|
deploy-docker:
|
||||||
|
name: deploy/docker
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
if: ${{ github.event_name == 'push' }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u orangemug --password-stdin
|
||||||
|
- run: docker build -t docker.pkg.github.com/maputnik/editor/editor:main .
|
||||||
|
- run: docker push docker.pkg.github.com/maputnik/editor/editor:main
|
||||||
@@ -33,3 +33,5 @@ public
|
|||||||
/errorShots
|
/errorShots
|
||||||
/old
|
/old
|
||||||
/build
|
/build
|
||||||
|
/cypress/screenshots
|
||||||
|
/dist/
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
const config = {
|
||||||
|
stories: ['../stories/**/*.stories.jsx'],
|
||||||
|
addons: ['@storybook/addon-actions', '@storybook/addon-links', '@storybook/addon-a11y/register', '@storybook/addon-storysource'],
|
||||||
|
framework: {
|
||||||
|
name: '@storybook/react-vite',
|
||||||
|
options: {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export default config;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { addons } from '@storybook/addons';
|
||||||
|
import { themes } from '@storybook/theming';
|
||||||
|
import theme from './maputnik.theme';
|
||||||
|
|
||||||
|
addons.setConfig({
|
||||||
|
theme: theme,
|
||||||
|
});
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { create } from '@storybook/theming/create';
|
||||||
|
|
||||||
|
export default create({
|
||||||
|
base: 'light',
|
||||||
|
|
||||||
|
brandTitle: 'Maputnik',
|
||||||
|
brandUrl: 'https://github.com/maputnik/editor',
|
||||||
|
});
|
||||||
+18
-17
@@ -1,21 +1,22 @@
|
|||||||
FROM node:10-slim
|
FROM node:18 as builder
|
||||||
|
WORKDIR /maputnik
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
# Only copy package.json to prevent npm install from running on every build
|
||||||
git \
|
COPY package.json package-lock.json ./
|
||||||
python \
|
RUN npm install
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
EXPOSE 8888
|
# Build maputnik
|
||||||
|
# TODO: we should also do a npm run test here (needs more dependencies)
|
||||||
ENV HOME /maputnik
|
COPY . .
|
||||||
RUN mkdir ${HOME}
|
|
||||||
|
|
||||||
COPY . ${HOME}/
|
|
||||||
|
|
||||||
WORKDIR ${HOME}
|
|
||||||
|
|
||||||
RUN npm install -d
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
WORKDIR ${HOME}/build/build
|
#---------------------------------------------------------------------------
|
||||||
CMD python -m SimpleHTTPServer 8888
|
|
||||||
|
# Create a clean python-based image with just the build results
|
||||||
|
FROM python:3-slim
|
||||||
|
WORKDIR /maputnik
|
||||||
|
|
||||||
|
COPY --from=builder /maputnik/dist .
|
||||||
|
|
||||||
|
EXPOSE 8888
|
||||||
|
CMD python -m http.server 8888
|
||||||
|
|||||||
@@ -1,33 +1,30 @@
|
|||||||
# Maputnik
|
<img width="200" alt="Maputnik logo" src="https://cdn.jsdelivr.net/gh/maputnik/design/logos/logo-color.png" />
|
||||||
|
|
||||||
[][circleci]
|
# Maputnik
|
||||||
[][appveyor]
|
[][github-action-ci]
|
||||||
[][dm-prod]
|
|
||||||
[][dm-dev]
|
|
||||||
[][license]
|
[][license]
|
||||||
|
|
||||||
[circleci]: https://circleci.com/gh/maputnik/editor/tree/master
|
[github-action-ci]: https://github.com/maputnik/editor/actions?query=workflow%3Aci
|
||||||
[appveyor]: https://ci.appveyor.com/project/lukasmartinelli/editor
|
[license]: https://tldrlegal.com/license/mit-license
|
||||||
[dm-prod]: https://david-dm.org/maputnik/editor
|
|
||||||
[dm-dev]: https://david-dm.org/maputnik/editor?type=dev
|
|
||||||
[license]: https://tldrlegal.com/license/mit-license
|
|
||||||
|
|
||||||
<img width="200" align="right" alt="Maputnik" src="https://cdn.jsdelivr.net/gh/maputnik/editor@1.5.0/src/img/maputnik.png" />
|
A free and open visual editor for the [MapLibre GL styles](https://maplibre.org/maplibre-style-spec/)
|
||||||
|
|
||||||
A free and open visual editor for the [Mapbox GL styles](https://www.mapbox.com/mapbox-gl-style-spec/)
|
|
||||||
targeted at developers and map designers.
|
targeted at developers and map designers.
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
- :link: Design your maps online at **<https://maputnik.github.io/editor/>** (all in local storage)
|
- :link: Design your maps online at **<https://maputnik.github.io/editor/>** (all in local storage)
|
||||||
- :link: Try out the v1.7.0-beta release at: https://maputnik.github.io/releases/v1.7.0-beta/
|
|
||||||
- :link: Use the [Maputnik CLI](https://github.com/maputnik/editor/wiki/Maputnik-CLI) for local style development
|
- :link: Use the [Maputnik CLI](https://github.com/maputnik/editor/wiki/Maputnik-CLI) for local style development
|
||||||
|
- In a Docker, run this command and browse to http://localhost:8888, Ctrl+C to stop the server.
|
||||||
|
|
||||||
Mapbox has built one of the best and most amazing OSS ecosystems. A key component to ensure its longevity and independence is an OSS map designer.
|
```bash
|
||||||
|
docker run -it --rm -p 8888:8888 maputnik/editor
|
||||||
|
```
|
||||||
|
|
||||||
## Donations
|
## Donations
|
||||||
|
Mapbox has built one of the best and most amazing OSS ecosystems. A key component to ensure its longevity and independence is an OSS map designer.
|
||||||
If you or your organisation has seen value from Maputnik, please consider donating at <https://maputnik.github.io/donate>
|
If you or your organisation has seen value from Maputnik, please consider donating at <https://maputnik.github.io/donate>
|
||||||
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
The documentation can be found in the [Wiki](https://github.com/maputnik/editor/wiki). You are welcome to collaborate!
|
The documentation can be found in the [Wiki](https://github.com/maputnik/editor/wiki). You are welcome to collaborate!
|
||||||
@@ -39,7 +36,7 @@ The documentation can be found in the [Wiki](https://github.com/maputnik/editor/
|
|||||||
|
|
||||||
## Develop
|
## Develop
|
||||||
|
|
||||||
Maputnik is written in ES6 and is using [React](https://github.com/facebook/react) and [Mapbox GL JS](https://www.mapbox.com/mapbox-gl-js/api/).
|
Maputnik is written in ES6 and is using [React](https://github.com/facebook/react) and [MapLibre GL JS](https://maplibre.org/projects/maplibre-gl-js/).
|
||||||
|
|
||||||
We ensure building and developing Maputnik works with the [current active LTS Node.js version and above](https://github.com/nodejs/Release#release-schedule).
|
We ensure building and developing Maputnik works with the [current active LTS Node.js version and above](https://github.com/nodejs/Release#release-schedule).
|
||||||
|
|
||||||
@@ -49,21 +46,17 @@ Install the deps, start the dev server and open the web browser on `http://local
|
|||||||
# install dependencies
|
# install dependencies
|
||||||
npm install
|
npm install
|
||||||
# start dev server
|
# start dev server
|
||||||
npm start
|
npm run start
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want Maputnik to be accessible externally use the [`--host` option](https://webpack.js.org/configuration/dev-server/#devserverhost):
|
If you want Maputnik to be accessible externally use the [`--host` option](https://vitejs.dev/config/server-options.html#server-host):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# start externally accessible dev server
|
# start externally accessible dev server
|
||||||
npm start -- --host 0.0.0.0
|
npm run start -- --host 0.0.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
The build process will watch for changes to the filesystem, rebuild and autoreload the editor. However note this from the [webpack-dev-server docs](https://webpack.js.org/configuration/dev-server/):
|
The build process will watch for changes to the filesystem, rebuild and autoreload the editor.
|
||||||
|
|
||||||
> webpack uses the file system to get notified of file changes. In some cases this does not work. For example, when using Network File System (NFS). Vagrant also has a lot of problems with this. ([snippet source](https://webpack.js.org/configuration/dev-server/#devserverwatchoptions-))
|
|
||||||
|
|
||||||
To enable polling add `export WEBPACK_DEV_SERVER_POLLING=1` to your environment.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
npm run build
|
npm run build
|
||||||
@@ -79,30 +72,28 @@ npm run lint-styles
|
|||||||
|
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
For testing we use [webdriverio](http://webdriver.io) and [selenium-standalone](https://github.com/vvo/selenium-standalone)
|
For E2E testing we use [Cypress](https://www.cypress.io/)
|
||||||
|
|
||||||
[selenium-standalone](https://github.com/vvo/selenium-standalone) starts a server that will launch browsers on your local machine. We use chrome so you **must** have chrome installed on your machine.
|
[Cypress](https://www.cypress.io/) doesn't starts a server so you'll need to start one manually by running `npm run start`.
|
||||||
|
|
||||||
Now open a terminal and run the following. This will install the drivers on your local machine
|
Now open a terminal and run the following using *chrome*:
|
||||||
|
|
||||||
```
|
```
|
||||||
./node_modules/.bin/selenium-standalone install
|
npm run test
|
||||||
|
```
|
||||||
|
or *firefox*:
|
||||||
|
```
|
||||||
|
npm run test -- --browser firefox
|
||||||
```
|
```
|
||||||
|
|
||||||
Now start the standalone server
|
See the following docs for more info: (Launching Browsers)[https://docs.cypress.io/guides/guides/launching-browsers]
|
||||||
|
|
||||||
|
You can also see the tests as they run or select which suites to run by executing:
|
||||||
|
|
||||||
```
|
```
|
||||||
./node_modules/.bin/selenium-standalone start
|
npm run cy:open
|
||||||
```
|
```
|
||||||
|
|
||||||
Then open another terminal and run
|
|
||||||
|
|
||||||
```
|
|
||||||
npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
After some time you should see a browser launch which will be automated by the test runner.
|
|
||||||
|
|
||||||
|
|
||||||
## Related Projects
|
## Related Projects
|
||||||
|
|
||||||
@@ -166,6 +157,5 @@ Sina Martinelli, Nicholas Doiron, Neil Cawse, Urs42, Benedikt Groß, Manuel Roth
|
|||||||
|
|
||||||
Maputnik is [licensed under MIT](LICENSE) and is Copyright (c) Lukas Martinelli and contributors.
|
Maputnik is [licensed under MIT](LICENSE) and is Copyright (c) Lukas Martinelli and contributors.
|
||||||
|
|
||||||
**Disclaimer** This project is not affiliated with Mapbox or Mapbox Studio. It is an independent style editor for the
|
**Disclaimer** This is an independent style editor.
|
||||||
open source technology in the Mapbox GL ecosystem.
|
|
||||||
As contributor please take extra care of not violating any Mapbox trademarks. Do not get inspired by Mapbox Studio and make your own decisions for a good style editor.
|
As contributor please take extra care of not violating any Mapbox trademarks. Do not get inspired by Mapbox Studio and make your own decisions for a good style editor.
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
image: Visual Studio 2019
|
|
||||||
environment:
|
|
||||||
matrix:
|
|
||||||
- nodejs_version: "10"
|
|
||||||
- nodejs_version: "12"
|
|
||||||
- nodejs_version: "13"
|
|
||||||
platform:
|
|
||||||
- x86
|
|
||||||
- x64
|
|
||||||
install:
|
|
||||||
# https://github.com/appveyor/ci/issues/2921#issuecomment-501016533
|
|
||||||
- ps: |
|
|
||||||
try {
|
|
||||||
Install-Product node $env:nodejs_version $env:platform
|
|
||||||
} catch {
|
|
||||||
echo "Unable to install node $env:nodejs_version, trying update..."
|
|
||||||
Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:platform
|
|
||||||
}
|
|
||||||
- md public
|
|
||||||
- npm install --global windows-build-tools
|
|
||||||
- npm install
|
|
||||||
build_script:
|
|
||||||
- npm run build
|
|
||||||
test_script:
|
|
||||||
- npm run lint-js
|
|
||||||
- npm run lint-css
|
|
||||||
@@ -1,291 +0,0 @@
|
|||||||
var webpack = require("webpack");
|
|
||||||
var WebpackDevServer = require("webpack-dev-server");
|
|
||||||
var webpackConfig = require("./webpack.config");
|
|
||||||
var testConfig = require("../test/config/specs");
|
|
||||||
var artifacts = require("../test/artifacts");
|
|
||||||
var isDocker = require("is-docker");
|
|
||||||
|
|
||||||
|
|
||||||
var server;
|
|
||||||
var SCREENSHOT_PATH = artifacts.pathSync("screenshots");
|
|
||||||
|
|
||||||
exports.config = {
|
|
||||||
//
|
|
||||||
// ====================
|
|
||||||
// Runner Configuration
|
|
||||||
// ====================
|
|
||||||
//
|
|
||||||
// WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or
|
|
||||||
// on a remote machine).
|
|
||||||
runner: 'local',
|
|
||||||
//
|
|
||||||
// ==================
|
|
||||||
// Specify Test Files
|
|
||||||
// ==================
|
|
||||||
// Define which test specs should run. The pattern is relative to the directory
|
|
||||||
// from which `wdio` was called. Notice that, if you are calling `wdio` from an
|
|
||||||
// NPM script (see https://docs.npmjs.com/cli/run-script) then the current working
|
|
||||||
// directory is where your package.json resides, so `wdio` will be called from there.
|
|
||||||
//
|
|
||||||
specs: [
|
|
||||||
'./test/functional/index.js'
|
|
||||||
],
|
|
||||||
// Patterns to exclude.
|
|
||||||
exclude: [
|
|
||||||
// 'path/to/excluded/files'
|
|
||||||
],
|
|
||||||
//
|
|
||||||
// ============
|
|
||||||
// Capabilities
|
|
||||||
// ============
|
|
||||||
// Define your capabilities here. WebdriverIO can run multiple capabilities at the same
|
|
||||||
// time. Depending on the number of capabilities, WebdriverIO launches several test
|
|
||||||
// sessions. Within your capabilities you can overwrite the spec and exclude options in
|
|
||||||
// order to group specific specs to a specific capability.
|
|
||||||
//
|
|
||||||
// First, you can define how many instances should be started at the same time. Let's
|
|
||||||
// say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
|
|
||||||
// set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec
|
|
||||||
// files and you set maxInstances to 10, all spec files will get tested at the same time
|
|
||||||
// and 30 processes will get spawned. The property handles how many capabilities
|
|
||||||
// from the same test should run tests.
|
|
||||||
//
|
|
||||||
maxInstances: 10,
|
|
||||||
//
|
|
||||||
// If you have trouble getting all important capabilities together, check out the
|
|
||||||
// Sauce Labs platform configurator - a great tool to configure your capabilities:
|
|
||||||
// https://docs.saucelabs.com/reference/platforms-configurator
|
|
||||||
//
|
|
||||||
capabilities: [{
|
|
||||||
// maxInstances can get overwritten per capability. So if you have an in-house Selenium
|
|
||||||
// grid with only 5 firefox instances available you can make sure that not more than
|
|
||||||
// 5 instances get started at a time.
|
|
||||||
maxInstances: 5,
|
|
||||||
//
|
|
||||||
browserName: 'chrome',
|
|
||||||
// If outputDir is provided WebdriverIO can capture driver session logs
|
|
||||||
// it is possible to configure which logTypes to include/exclude.
|
|
||||||
// excludeDriverLogs: ['*'], // pass '*' to exclude all driver session logs
|
|
||||||
// excludeDriverLogs: ['bugreport', 'server'],
|
|
||||||
}],
|
|
||||||
//
|
|
||||||
// ===================
|
|
||||||
// Test Configurations
|
|
||||||
// ===================
|
|
||||||
// Define all options that are relevant for the WebdriverIO instance here
|
|
||||||
//
|
|
||||||
// Level of logging verbosity: trace | debug | info | warn | error | silent
|
|
||||||
logLevel: 'info',
|
|
||||||
//
|
|
||||||
// Set specific log levels per logger
|
|
||||||
// loggers:
|
|
||||||
// - webdriver, webdriverio
|
|
||||||
// - @wdio/applitools-service, @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service
|
|
||||||
// - @wdio/mocha-framework, @wdio/jasmine-framework
|
|
||||||
// - @wdio/local-runner, @wdio/lambda-runner
|
|
||||||
// - @wdio/sumologic-reporter
|
|
||||||
// - @wdio/cli, @wdio/config, @wdio/sync, @wdio/utils
|
|
||||||
// Level of logging verbosity: trace | debug | info | warn | error | silent
|
|
||||||
// logLevels: {
|
|
||||||
// webdriver: 'debug',
|
|
||||||
// '@wdio/applitools-service': 'info'
|
|
||||||
// },
|
|
||||||
//
|
|
||||||
// If you only want to run your tests until a specific amount of tests have failed use
|
|
||||||
// bail (default is 0 - don't bail, run all tests).
|
|
||||||
bail: 0,
|
|
||||||
//
|
|
||||||
screenshotPath: SCREENSHOT_PATH,
|
|
||||||
// Note: This is here because @orangemug currently runs Maputnik inside a docker container.
|
|
||||||
hostname: process.env.DOCKER_HOST || "0.0.0.0",
|
|
||||||
// Set a base URL in order to shorten url command calls. If your `url` parameter starts
|
|
||||||
// with `/`, the base url gets prepended, not including the path portion of your baseUrl.
|
|
||||||
// If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
|
|
||||||
// gets prepended directly.
|
|
||||||
baseUrl: 'http://localhost',
|
|
||||||
//
|
|
||||||
// Default timeout for all waitFor* commands.
|
|
||||||
waitforTimeout: 10000,
|
|
||||||
//
|
|
||||||
// Default timeout in milliseconds for request
|
|
||||||
// if Selenium Grid doesn't send response
|
|
||||||
connectionRetryTimeout: 90000,
|
|
||||||
//
|
|
||||||
// Default request retries count
|
|
||||||
connectionRetryCount: 3,
|
|
||||||
//
|
|
||||||
// Test runner services
|
|
||||||
// Services take over a specific job you don't want to take care of. They enhance
|
|
||||||
// your test setup with almost no effort. Unlike plugins, they don't add new
|
|
||||||
// commands. Instead, they hook themselves up into the test process.
|
|
||||||
//
|
|
||||||
// Framework you want to run your specs with.
|
|
||||||
// The following are supported: Mocha, Jasmine, and Cucumber
|
|
||||||
// see also: https://webdriver.io/docs/frameworks.html
|
|
||||||
//
|
|
||||||
// Make sure you have the wdio adapter package for the specific framework installed
|
|
||||||
// before running any tests.
|
|
||||||
framework: 'mocha',
|
|
||||||
//
|
|
||||||
// The number of times to retry the entire specfile when it fails as a whole
|
|
||||||
// specFileRetries: 1,
|
|
||||||
//
|
|
||||||
// Test reporter for stdout.
|
|
||||||
// The only one supported by default is 'dot'
|
|
||||||
// see also: https://webdriver.io/docs/dot-reporter.html
|
|
||||||
reporters: ['spec'],
|
|
||||||
|
|
||||||
//
|
|
||||||
// Options to be passed to Mocha.
|
|
||||||
// See the full list at http://mochajs.org/
|
|
||||||
mochaOpts: {
|
|
||||||
ui: 'bdd',
|
|
||||||
// Because we don't know how long the initial build will take...
|
|
||||||
timeout: 4*60*1000
|
|
||||||
},
|
|
||||||
onPrepare: function (config, capabilities) {
|
|
||||||
return new Promise(function(resolve, reject) {
|
|
||||||
var compiler = webpack(webpackConfig);
|
|
||||||
const serverHost = isDocker() ? "0.0.0.0" : "localhost";
|
|
||||||
|
|
||||||
server = new WebpackDevServer(compiler, {
|
|
||||||
host: serverHost,
|
|
||||||
stats: {
|
|
||||||
colors: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
server.listen(testConfig.port, serverHost, function(err) {
|
|
||||||
if(err) {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
},
|
|
||||||
onComplete: function(exitCode) {
|
|
||||||
server.close()
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// =====
|
|
||||||
// Hooks
|
|
||||||
// =====
|
|
||||||
// WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
|
|
||||||
// it and to build services around it. You can either apply a single function or an array of
|
|
||||||
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
|
|
||||||
// resolved to continue.
|
|
||||||
/**
|
|
||||||
* Gets executed once before all workers get launched.
|
|
||||||
* @param {Object} config wdio configuration object
|
|
||||||
* @param {Array.<Object>} capabilities list of capabilities details
|
|
||||||
*/
|
|
||||||
// onPrepare: function (config, capabilities) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Gets executed just before initialising the webdriver session and test framework. It allows you
|
|
||||||
* to manipulate configurations depending on the capability or spec.
|
|
||||||
* @param {Object} config wdio configuration object
|
|
||||||
* @param {Array.<Object>} capabilities list of capabilities details
|
|
||||||
* @param {Array.<String>} specs List of spec file paths that are to be run
|
|
||||||
*/
|
|
||||||
// beforeSession: function (config, capabilities, specs) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Gets executed before test execution begins. At this point you can access to all global
|
|
||||||
* variables like `browser`. It is the perfect place to define custom commands.
|
|
||||||
* @param {Array.<Object>} capabilities list of capabilities details
|
|
||||||
* @param {Array.<String>} specs List of spec file paths that are to be run
|
|
||||||
*/
|
|
||||||
// before: function (capabilities, specs) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Runs before a WebdriverIO command gets executed.
|
|
||||||
* @param {String} commandName hook command name
|
|
||||||
* @param {Array} args arguments that command would receive
|
|
||||||
*/
|
|
||||||
// beforeCommand: function (commandName, args) {
|
|
||||||
// },
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook that gets executed before the suite starts
|
|
||||||
* @param {Object} suite suite details
|
|
||||||
*/
|
|
||||||
// beforeSuite: function (suite) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
|
|
||||||
* @param {Object} test test details
|
|
||||||
*/
|
|
||||||
// beforeTest: function (test) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
|
|
||||||
* beforeEach in Mocha)
|
|
||||||
*/
|
|
||||||
// beforeHook: function () {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
|
|
||||||
* afterEach in Mocha)
|
|
||||||
*/
|
|
||||||
// afterHook: function () {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
|
|
||||||
* @param {Object} test test details
|
|
||||||
*/
|
|
||||||
// afterTest: function (test) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Hook that gets executed after the suite has ended
|
|
||||||
* @param {Object} suite suite details
|
|
||||||
*/
|
|
||||||
// afterSuite: function (suite) {
|
|
||||||
// },
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs after a WebdriverIO command gets executed
|
|
||||||
* @param {String} commandName hook command name
|
|
||||||
* @param {Array} args arguments that command would receive
|
|
||||||
* @param {Number} result 0 - command success, 1 - command error
|
|
||||||
* @param {Object} error error object if any
|
|
||||||
*/
|
|
||||||
// afterCommand: function (commandName, args, result, error) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Gets executed after all tests are done. You still have access to all global variables from
|
|
||||||
* the test.
|
|
||||||
* @param {Number} result 0 - test pass, 1 - test fail
|
|
||||||
* @param {Array.<Object>} capabilities list of capabilities details
|
|
||||||
* @param {Array.<String>} specs List of spec file paths that ran
|
|
||||||
*/
|
|
||||||
// after: function (result, capabilities, specs) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Gets executed right after terminating the webdriver session.
|
|
||||||
* @param {Object} config wdio configuration object
|
|
||||||
* @param {Array.<Object>} capabilities list of capabilities details
|
|
||||||
* @param {Array.<String>} specs List of spec file paths that ran
|
|
||||||
*/
|
|
||||||
// afterSession: function (config, capabilities, specs) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Gets executed after all workers got shut down and the process is about to exit. An error
|
|
||||||
* thrown in the onComplete hook will result in the test run failing.
|
|
||||||
* @param {Object} exitCode 0 - success, 1 - fail
|
|
||||||
* @param {Object} config wdio configuration object
|
|
||||||
* @param {Array.<Object>} capabilities list of capabilities details
|
|
||||||
* @param {<Object>} results object containing test results
|
|
||||||
*/
|
|
||||||
// onComplete: function(exitCode, config, capabilities, results) {
|
|
||||||
// },
|
|
||||||
/**
|
|
||||||
* Gets executed when a refresh happens.
|
|
||||||
* @param {String} oldSessionId session ID of the old session
|
|
||||||
* @param {String} newSessionId session ID of the new session
|
|
||||||
*/
|
|
||||||
//onReload: function(oldSessionId, newSessionId) {
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var webpack = require('webpack');
|
|
||||||
var path = require('path');
|
|
||||||
var rules = require('./webpack.rules');
|
|
||||||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
||||||
var HtmlWebpackInlineSVGPlugin = require('html-webpack-inline-svg-plugin');
|
|
||||||
var CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
||||||
|
|
||||||
const HOST = process.env.HOST || "127.0.0.1";
|
|
||||||
const PORT = process.env.PORT || "8888";
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
target: 'web',
|
|
||||||
mode: 'development',
|
|
||||||
entry: [
|
|
||||||
`webpack-dev-server/client?http://${HOST}:${PORT}`,
|
|
||||||
`webpack/hot/only-dev-server`,
|
|
||||||
`./src/index.jsx` // Your appʼs entry point
|
|
||||||
],
|
|
||||||
devtool: process.env.WEBPACK_DEVTOOL || 'cheap-module-source-map',
|
|
||||||
output: {
|
|
||||||
path: path.join(__dirname, '..', 'public'),
|
|
||||||
filename: 'bundle.js'
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.js', '.jsx']
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
noParse: [
|
|
||||||
/mapbox-gl\/dist\/mapbox-gl.js/
|
|
||||||
],
|
|
||||||
rules: rules
|
|
||||||
},
|
|
||||||
node: {
|
|
||||||
fs: "empty",
|
|
||||||
net: 'empty',
|
|
||||||
tls: 'empty'
|
|
||||||
},
|
|
||||||
devServer: {
|
|
||||||
contentBase: "./public",
|
|
||||||
// do not print bundle build stats
|
|
||||||
noInfo: true,
|
|
||||||
// enable HMR
|
|
||||||
hot: true,
|
|
||||||
// embed the webpack-dev-server runtime into the bundle
|
|
||||||
inline: true,
|
|
||||||
// serve index.html in place of 404 responses to allow HTML5 history
|
|
||||||
historyApiFallback: true,
|
|
||||||
port: PORT,
|
|
||||||
host: HOST,
|
|
||||||
watchOptions: {
|
|
||||||
// Disabled polling by default as it causes lots of CPU usage and hence drains laptop batteries. To enable polling add WEBPACK_DEV_SERVER_POLLING to your environment
|
|
||||||
// See <https://webpack.js.org/configuration/watch/#watchoptions-poll> for details
|
|
||||||
poll: (!!process.env.WEBPACK_DEV_SERVER_POLLING ? true : false),
|
|
||||||
watch: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new webpack.NoEmitOnErrorsPlugin(),
|
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
title: 'Maputnik',
|
|
||||||
template: './src/template.html'
|
|
||||||
}),
|
|
||||||
new HtmlWebpackInlineSVGPlugin({
|
|
||||||
runPreEmit: true,
|
|
||||||
}),
|
|
||||||
new CopyWebpackPlugin([
|
|
||||||
{
|
|
||||||
from: './src/manifest.json',
|
|
||||||
to: 'manifest.json'
|
|
||||||
}
|
|
||||||
])
|
|
||||||
]
|
|
||||||
};
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
var webpack = require('webpack');
|
|
||||||
var path = require('path');
|
|
||||||
var rules = require('./webpack.rules');
|
|
||||||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
||||||
var HtmlWebpackInlineSVGPlugin = require('html-webpack-inline-svg-plugin');
|
|
||||||
var WebpackCleanupPlugin = require('webpack-cleanup-plugin');
|
|
||||||
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
||||||
var CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
||||||
var artifacts = require("../test/artifacts");
|
|
||||||
|
|
||||||
var OUTPATH = artifacts.pathSync("/build");
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
entry: {
|
|
||||||
app: './src/index.jsx',
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
path: OUTPATH,
|
|
||||||
filename: '[name].[contenthash].js',
|
|
||||||
chunkFilename: '[contenthash].js'
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.js', '.jsx']
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
noParse: [
|
|
||||||
/mapbox-gl\/dist\/mapbox-gl.js/
|
|
||||||
],
|
|
||||||
rules: rules
|
|
||||||
},
|
|
||||||
node: {
|
|
||||||
fs: "empty",
|
|
||||||
net: 'empty',
|
|
||||||
tls: 'empty'
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new webpack.NoEmitOnErrorsPlugin(),
|
|
||||||
new WebpackCleanupPlugin(),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
'process.env': {
|
|
||||||
NODE_ENV: '"production"'
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: './src/template.html',
|
|
||||||
title: 'Maputnik'
|
|
||||||
}),
|
|
||||||
new HtmlWebpackInlineSVGPlugin({
|
|
||||||
runPreEmit: true,
|
|
||||||
}),
|
|
||||||
new CopyWebpackPlugin([
|
|
||||||
{
|
|
||||||
from: './src/manifest.json',
|
|
||||||
to: 'manifest.json'
|
|
||||||
}
|
|
||||||
]),
|
|
||||||
new BundleAnalyzerPlugin({
|
|
||||||
analyzerMode: 'static',
|
|
||||||
defaultSizes: 'gzip',
|
|
||||||
openAnalyzer: false,
|
|
||||||
generateStatsFile: true,
|
|
||||||
reportFilename: 'bundle-stats.html',
|
|
||||||
statsFilename: 'bundle-stats.json',
|
|
||||||
})
|
|
||||||
]
|
|
||||||
};
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
const webpackProdConfig = require('./webpack.production.config');
|
|
||||||
const artifacts = require("../test/artifacts");
|
|
||||||
|
|
||||||
const OUTPATH = artifacts.pathSync("/profiling");
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
...webpackProdConfig,
|
|
||||||
output: {
|
|
||||||
...webpackProdConfig.output,
|
|
||||||
path: OUTPATH,
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
...webpackProdConfig.resolve,
|
|
||||||
alias: {
|
|
||||||
...webpackProdConfig.resolve.alias,
|
|
||||||
'react-dom$': 'react-dom/profiling',
|
|
||||||
'scheduler/tracing': 'scheduler/tracing-profiling',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
const path = require("path");
|
|
||||||
|
|
||||||
module.exports = [
|
|
||||||
{
|
|
||||||
test: /\.jsx?$/,
|
|
||||||
exclude: [
|
|
||||||
path.resolve(__dirname, '../node_modules')
|
|
||||||
],
|
|
||||||
use: 'babel-loader'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(eot|ttf|woff|woff2)$/,
|
|
||||||
use: 'file-loader?name=fonts/[name].[ext]'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.ico$/,
|
|
||||||
use: 'file-loader?name=[name].[ext]'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(gif|jpg|png)$/,
|
|
||||||
use: 'file-loader?name=img/[name].[ext]'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.svg$/,
|
|
||||||
use: [
|
|
||||||
'svg-inline-loader'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /[\/\\](node_modules|global|src)[\/\\].*\.scss$/,
|
|
||||||
use: [
|
|
||||||
'style-loader',
|
|
||||||
"css-loader",
|
|
||||||
"sass-loader"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /[\/\\](node_modules|global|src)[\/\\].*\.css$/,
|
|
||||||
use: [
|
|
||||||
'style-loader',
|
|
||||||
'css-loader'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { defineConfig } from "cypress";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
e2e: {
|
||||||
|
setupNodeEvents(on, config) {
|
||||||
|
// implement node event listeners here
|
||||||
|
},
|
||||||
|
retries: {
|
||||||
|
runMode: 2,
|
||||||
|
openMode: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import MaputnikDriver from "./driver";
|
||||||
|
|
||||||
|
describe("accessibility", () => {
|
||||||
|
let { beforeAndAfter, given, when, get, should } = new MaputnikDriver();
|
||||||
|
beforeAndAfter();
|
||||||
|
|
||||||
|
describe("skip links", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
when.setStyle("layer");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("skip link to layer list", () => {
|
||||||
|
const selector = "root:skip:layer-list";
|
||||||
|
should.exist(selector);
|
||||||
|
when.tab();
|
||||||
|
should.beFocused(selector);
|
||||||
|
when.click(selector);
|
||||||
|
should.beFocused("skip-target-layer-list");
|
||||||
|
});
|
||||||
|
|
||||||
|
// This fails for some reason only in Chrome, but passes in firefox. Adding a skip here to allow merge and later on we'll decide if we want to fix this or not.
|
||||||
|
it.skip("skip link to layer editor", () => {
|
||||||
|
const selector = "root:skip:layer-editor";
|
||||||
|
should.exist(selector);
|
||||||
|
when.tab().tab();
|
||||||
|
should.beFocused(selector);
|
||||||
|
when.click(selector);
|
||||||
|
should.beFocused("skip-target-layer-editor");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("skip link to map view", () => {
|
||||||
|
const selector = "root:skip:map-view";
|
||||||
|
should.exist(selector);
|
||||||
|
when.tab().tab().tab();
|
||||||
|
should.beFocused(selector);
|
||||||
|
when.click(selector);
|
||||||
|
should.canvasBeFocused();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
import { CypressHelper } from "@shellygo/cypress-test-utils";
|
||||||
|
import { v1 as uuid } from "uuid";
|
||||||
|
export default class MaputnikDriver {
|
||||||
|
private helper = new CypressHelper({ defaultDataAttribute: "data-wd-key" });
|
||||||
|
public beforeAndAfter = () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
this.given.setupInterception();
|
||||||
|
this.when.setStyle("both");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
public given = {
|
||||||
|
setupInterception: () => {
|
||||||
|
cy.intercept("GET", "http://localhost:8888/example-style.json", {
|
||||||
|
fixture: "example-style.json",
|
||||||
|
}).as("example-style.json");
|
||||||
|
cy.intercept("GET", "http://localhost:8888/example-layer-style.json", {
|
||||||
|
fixture: "example-layer-style.json",
|
||||||
|
});
|
||||||
|
cy.intercept("GET", "http://localhost:8888/geojson-style.json", {
|
||||||
|
fixture: "geojson-style.json",
|
||||||
|
});
|
||||||
|
cy.intercept("GET", "http://localhost:8888/raster-style.json", {
|
||||||
|
fixture: "raster-style.json",
|
||||||
|
});
|
||||||
|
cy.intercept("GET", "http://localhost:8888/geojson-raster-style.json", {
|
||||||
|
fixture: "geojson-raster-style.json",
|
||||||
|
});
|
||||||
|
cy.intercept({ method: "GET", url: "*example.local/*" }, []);
|
||||||
|
cy.intercept({ method: "GET", url: "*example.com/*" }, []);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
public when = {
|
||||||
|
within: (selector: string, fn: () => void) => {
|
||||||
|
this.helper.when.within(fn, selector);
|
||||||
|
},
|
||||||
|
tab: () => cy.get("body").tab(),
|
||||||
|
waitForExampleFileRequset: () => {
|
||||||
|
this.helper.when.waitForResponse("example-style.json");
|
||||||
|
},
|
||||||
|
chooseExampleFile: () => {
|
||||||
|
cy.get("input[type='file']").selectFile(
|
||||||
|
"cypress/fixtures/example-style.json",
|
||||||
|
{ force: true }
|
||||||
|
);
|
||||||
|
},
|
||||||
|
setStyle: (
|
||||||
|
styleProperties: "geojson" | "raster" | "both" | "layer" | "",
|
||||||
|
zoom?: number
|
||||||
|
) => {
|
||||||
|
let url = "?debug";
|
||||||
|
switch (styleProperties) {
|
||||||
|
case "geojson":
|
||||||
|
url += "&style=http://localhost:8888/geojson-style.json";
|
||||||
|
break;
|
||||||
|
case "raster":
|
||||||
|
url += "&style=http://localhost:8888/raster-style.json";
|
||||||
|
break;
|
||||||
|
case "both":
|
||||||
|
url += "&style=http://localhost:8888/geojson-raster-style.json";
|
||||||
|
break;
|
||||||
|
case "layer":
|
||||||
|
url += "&style=http://localhost:8888/example-layer-style.json";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (zoom) {
|
||||||
|
url += "#" + zoom + "/41.3805/2.1635";
|
||||||
|
}
|
||||||
|
cy.visit("http://localhost:8888/" + url);
|
||||||
|
if (styleProperties) {
|
||||||
|
cy.on("window:confirm", () => true);
|
||||||
|
}
|
||||||
|
cy.get(".maputnik-toolbar-link").should("be.visible");
|
||||||
|
},
|
||||||
|
fillLayersModal: (opts: {type: string, layer?: string, id?: string}) => {
|
||||||
|
var type = opts.type;
|
||||||
|
var layer = opts.layer;
|
||||||
|
var id;
|
||||||
|
if (opts.id) {
|
||||||
|
id = opts.id;
|
||||||
|
} else {
|
||||||
|
id = `${type}:${uuid()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
cy.get(
|
||||||
|
this.get.dataAttribute("add-layer.layer-type", "select")
|
||||||
|
).select(type);
|
||||||
|
cy.get(this.get.dataAttribute("add-layer.layer-id", "input")).type(id);
|
||||||
|
if (layer) {
|
||||||
|
cy.get(
|
||||||
|
this.get.dataAttribute("add-layer.layer-source-block", "input")
|
||||||
|
).type(layer);
|
||||||
|
}
|
||||||
|
this.when.click("add-layer");
|
||||||
|
|
||||||
|
return id;
|
||||||
|
},
|
||||||
|
|
||||||
|
typeKeys: (keys: string) => {
|
||||||
|
cy.get("body").type(keys);
|
||||||
|
},
|
||||||
|
|
||||||
|
click: (selector: string) => {
|
||||||
|
this.helper.when.click(selector);
|
||||||
|
},
|
||||||
|
|
||||||
|
clickZoomin: () => {
|
||||||
|
cy.get(".maplibregl-ctrl-zoom-in").click();
|
||||||
|
},
|
||||||
|
|
||||||
|
selectWithin: (selector: string, value: string) => {
|
||||||
|
this.when.within(selector, () => {
|
||||||
|
cy.get("select").select(value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
select: (selector: string, value: string) => {
|
||||||
|
this.helper.get.element(selector).select(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
focus: (selector: string) => {
|
||||||
|
this.helper.when.focus(selector);
|
||||||
|
},
|
||||||
|
|
||||||
|
setValue: (selector: string, text: string) => {
|
||||||
|
cy.get(selector).clear().type(text, { parseSpecialCharSequences: false });
|
||||||
|
},
|
||||||
|
|
||||||
|
closeModal: (key: string) => {
|
||||||
|
this.helper.when.waitUntil(() => this.helper.get.element(key));
|
||||||
|
this.when.click(key + ".close-modal");
|
||||||
|
},
|
||||||
|
|
||||||
|
openLayersModal: () => {
|
||||||
|
this.helper.when.click("layer-list:add-layer");
|
||||||
|
|
||||||
|
cy.get(this.get.dataAttribute("modal:add-layer")).should("exist");
|
||||||
|
cy.get(this.get.dataAttribute("modal:add-layer")).should("be.visible");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
public get = {
|
||||||
|
isMac: () => {
|
||||||
|
return Cypress.platform === "darwin";
|
||||||
|
},
|
||||||
|
styleFromWindow: (win: Window) => {
|
||||||
|
const styleId = win.localStorage.getItem("maputnik:latest_style");
|
||||||
|
const styleItem = win.localStorage.getItem(`maputnik:style:${styleId}`);
|
||||||
|
const obj = JSON.parse(styleItem || "");
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
exampleFileUrl: () => {
|
||||||
|
return "http://localhost:8888/example-style.json";
|
||||||
|
},
|
||||||
|
dataAttribute: (key: string, selector?: string): string => {
|
||||||
|
return `*[data-wd-key='${key}'] ${selector || ""}`;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
public should = {
|
||||||
|
canvasBeFocused: () => {
|
||||||
|
this.when.within("maplibre:map", () => {
|
||||||
|
cy.get("canvas").should("be.focused");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
notExist: (selector: string) => {
|
||||||
|
cy.get(selector).should("not.exist");
|
||||||
|
},
|
||||||
|
beFocused: (selector: string) => {
|
||||||
|
this.helper.get.element(selector).should("have.focus");
|
||||||
|
},
|
||||||
|
|
||||||
|
notBeFocused: (selector: string) => {
|
||||||
|
this.helper.get.element(selector).should("not.have.focus");
|
||||||
|
},
|
||||||
|
|
||||||
|
beVisible: (selector: string) => {
|
||||||
|
this.helper.get.element(selector).should("be.visible");
|
||||||
|
},
|
||||||
|
|
||||||
|
notBeVisible: (selector: string) => {
|
||||||
|
this.helper.get.element(selector).should("not.be.visible");
|
||||||
|
},
|
||||||
|
|
||||||
|
equalStyleStore: (getter: (obj: any) => any, styleObj: any) => {
|
||||||
|
cy.window().then((win: any) => {
|
||||||
|
const obj = this.get.styleFromWindow(win);
|
||||||
|
assert.deepEqual(getter(obj), styleObj);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
styleStoreEqualToExampleFileData: () => {
|
||||||
|
cy.window().then((win: any) => {
|
||||||
|
const obj = this.get.styleFromWindow(win);
|
||||||
|
cy.fixture("example-style.json").should("deep.equal", obj);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
exist: (selector: string) => {
|
||||||
|
this.helper.get.element(selector).should("exist");
|
||||||
|
},
|
||||||
|
beSelected: (selector: string, value: string) => {
|
||||||
|
this.helper.get.element(selector).find(`option[value="${value}"]`).should("be.selected");
|
||||||
|
},
|
||||||
|
containText: (selector: string, text: string) => {
|
||||||
|
this.helper.get.element(selector).should("contain.text", text);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import MaputnikDriver from "./driver";
|
||||||
|
|
||||||
|
describe("history", () => {
|
||||||
|
let { beforeAndAfter, given, when, get, should } = new MaputnikDriver();
|
||||||
|
beforeAndAfter();
|
||||||
|
|
||||||
|
let undoKeyCombo: string;
|
||||||
|
let redoKeyCombo: string;
|
||||||
|
|
||||||
|
before(() => {
|
||||||
|
const isMac = get.isMac();
|
||||||
|
undoKeyCombo = isMac ? "{meta}z" : "{ctrl}z";
|
||||||
|
redoKeyCombo = isMac ? "{meta}{shift}z" : "{ctrl}y";
|
||||||
|
});
|
||||||
|
|
||||||
|
it("undo/redo", () => {
|
||||||
|
when.setStyle("geojson");
|
||||||
|
when.openLayersModal();
|
||||||
|
|
||||||
|
should.equalStyleStore((a: any) => a.layers, []);
|
||||||
|
|
||||||
|
when.fillLayersModal({
|
||||||
|
id: "step 1",
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "step 1",
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
when.openLayersModal();
|
||||||
|
when.fillLayersModal({
|
||||||
|
id: "step 2",
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "step 1",
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "step 2",
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
when.typeKeys(undoKeyCombo);
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "step 1",
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
when.typeKeys(undoKeyCombo);
|
||||||
|
should.equalStyleStore((a: any) => a.layers, []);
|
||||||
|
|
||||||
|
when.typeKeys(redoKeyCombo);
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "step 1",
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
when.typeKeys(redoKeyCombo);
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "step 1",
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "step 2",
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import MaputnikDriver from "./driver";
|
||||||
|
|
||||||
|
describe("keyboard", () => {
|
||||||
|
let { beforeAndAfter, given, when, get, should } = new MaputnikDriver();
|
||||||
|
beforeAndAfter();
|
||||||
|
describe("shortcuts", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
given.setupInterception();
|
||||||
|
when.setStyle("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("ESC should unfocus", () => {
|
||||||
|
const targetSelector = "maputnik-select";
|
||||||
|
when.focus(targetSelector);
|
||||||
|
should.beFocused(targetSelector);
|
||||||
|
|
||||||
|
when.typeKeys("{esc}");
|
||||||
|
expect(should.notBeFocused(targetSelector));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("'?' should show shortcuts modal", () => {
|
||||||
|
when.typeKeys("?");
|
||||||
|
should.beVisible("modal:shortcuts");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("'o' should show open modal", () => {
|
||||||
|
when.typeKeys("o");
|
||||||
|
should.beVisible("modal:open");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("'e' should show export modal", () => {
|
||||||
|
when.typeKeys("e");
|
||||||
|
should.beVisible("modal:export");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("'d' should show sources modal", () => {
|
||||||
|
when.typeKeys("d");
|
||||||
|
should.beVisible("modal:sources");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("'s' should show settings modal", () => {
|
||||||
|
when.typeKeys("s");
|
||||||
|
should.beVisible("modal:settings");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("'i' should change map to inspect mode", () => {
|
||||||
|
when.typeKeys("i");
|
||||||
|
should.beSelected("nav:inspect", "inspect");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("'m' should focus map", () => {
|
||||||
|
when.typeKeys("m");
|
||||||
|
should.canvasBeFocused();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("'!' should show debug modal", () => {
|
||||||
|
when.typeKeys("!");
|
||||||
|
should.beVisible("modal:debug");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,491 @@
|
|||||||
|
import { v1 as uuid } from "uuid";
|
||||||
|
import MaputnikDriver from "./driver";
|
||||||
|
|
||||||
|
describe("layers", () => {
|
||||||
|
let { beforeAndAfter, given, when, get, should } = new MaputnikDriver();
|
||||||
|
beforeAndAfter();
|
||||||
|
beforeEach(() => {
|
||||||
|
when.setStyle("both");
|
||||||
|
when.openLayersModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ops", () => {
|
||||||
|
it("delete", () => {
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
when.click("layer-list-item:" + id + ":delete");
|
||||||
|
|
||||||
|
should.equalStyleStore((a: any) => a.layers, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("duplicate", () => {
|
||||||
|
var styleObj;
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
when.click("layer-list-item:" + id + ":copy");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id + "-copy",
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("hide", () => {
|
||||||
|
var styleObj;
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
when.click("layer-list-item:" + id + ":toggle-visibility");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "background",
|
||||||
|
layout: {
|
||||||
|
visibility: "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
when.click("layer-list-item:" + id + ":toggle-visibility");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "background",
|
||||||
|
layout: {
|
||||||
|
visibility: "visible",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("background", () => {
|
||||||
|
it("add", () => {
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("modify", () => {
|
||||||
|
function createBackground() {
|
||||||
|
// Setup
|
||||||
|
var id = uuid();
|
||||||
|
|
||||||
|
when.selectWithin("add-layer.layer-type", "background");
|
||||||
|
when.setValue(
|
||||||
|
get.dataAttribute("add-layer.layer-id", "input"),
|
||||||
|
"background:" + id
|
||||||
|
);
|
||||||
|
|
||||||
|
when.click("add-layer");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "background:" + id,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====> THESE SHOULD BE FROM THE SPEC
|
||||||
|
describe("layer", () => {
|
||||||
|
it("expand/collapse");
|
||||||
|
it("id", () => {
|
||||||
|
var bgId = createBackground();
|
||||||
|
|
||||||
|
when.click("layer-list-item:background:" + bgId);
|
||||||
|
|
||||||
|
var id = uuid();
|
||||||
|
when.setValue(
|
||||||
|
get.dataAttribute("layer-editor.layer-id", "input"),
|
||||||
|
"foobar:" + id
|
||||||
|
);
|
||||||
|
when.click("min-zoom");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "foobar:" + id,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("min-zoom", () => {
|
||||||
|
var bgId = createBackground();
|
||||||
|
|
||||||
|
when.click("layer-list-item:background:" + bgId);
|
||||||
|
when.setValue(
|
||||||
|
get.dataAttribute("min-zoom", 'input[type="text"]'),
|
||||||
|
"1"
|
||||||
|
);
|
||||||
|
|
||||||
|
when.click("layer-editor.layer-id");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "background:" + bgId,
|
||||||
|
type: "background",
|
||||||
|
minzoom: 1,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// AND RESET!
|
||||||
|
// driver.setValue(driver.get.dataAttribute("min-zoom", "input"), "")
|
||||||
|
// driver.click(driver.get.dataAttribute("max-zoom", "input"));
|
||||||
|
|
||||||
|
// driver.isStyleStoreEqual((a: any) => a.layers, [
|
||||||
|
// {
|
||||||
|
// "id": 'background:'+bgId,
|
||||||
|
// "type": 'background'
|
||||||
|
// }
|
||||||
|
// ]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("max-zoom", () => {
|
||||||
|
var bgId = createBackground();
|
||||||
|
|
||||||
|
when.click("layer-list-item:background:" + bgId);
|
||||||
|
when.setValue(
|
||||||
|
get.dataAttribute("max-zoom", 'input[type="text"]'),
|
||||||
|
"1"
|
||||||
|
);
|
||||||
|
|
||||||
|
when.click("layer-editor.layer-id");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "background:" + bgId,
|
||||||
|
type: "background",
|
||||||
|
maxzoom: 1,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("comments", () => {
|
||||||
|
var bgId = createBackground();
|
||||||
|
var id = uuid();
|
||||||
|
|
||||||
|
when.click("layer-list-item:background:" + bgId);
|
||||||
|
when.setValue(get.dataAttribute("layer-comment", "textarea"), id);
|
||||||
|
|
||||||
|
when.click("layer-editor.layer-id");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "background:" + bgId,
|
||||||
|
type: "background",
|
||||||
|
metadata: {
|
||||||
|
"maputnik:comment": id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Unset it again.
|
||||||
|
// TODO: This fails
|
||||||
|
// driver.setValue(driver.getDataAttribute("layer-comment", "textarea"), "");
|
||||||
|
// driver.click(driver.getDataAttribute("min-zoom", "input"));
|
||||||
|
|
||||||
|
// driver.isStyleStoreEqual((a: any) => a.layers, [
|
||||||
|
// {
|
||||||
|
// "id": 'background:'+bgId,
|
||||||
|
// "type": 'background'
|
||||||
|
// }
|
||||||
|
// ]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("color", () => {
|
||||||
|
var bgId = createBackground();
|
||||||
|
|
||||||
|
when.click("layer-list-item:background:" + bgId);
|
||||||
|
|
||||||
|
when.click("spec-field:background-color");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "background:" + bgId,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("filter", () => {
|
||||||
|
it("expand/collapse");
|
||||||
|
it("compound filter");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("paint", () => {
|
||||||
|
it("expand/collapse");
|
||||||
|
it("color");
|
||||||
|
it("pattern");
|
||||||
|
it("opacity");
|
||||||
|
});
|
||||||
|
// <=====
|
||||||
|
|
||||||
|
describe("json-editor", () => {
|
||||||
|
it("expand/collapse");
|
||||||
|
it("modify");
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
it.skip("parse error", () => {
|
||||||
|
var bgId = createBackground();
|
||||||
|
|
||||||
|
when.click("layer-list-item:background:" + bgId);
|
||||||
|
|
||||||
|
var errorSelector = ".CodeMirror-lint-marker-error";
|
||||||
|
should.notExist(errorSelector);
|
||||||
|
|
||||||
|
when.click(".CodeMirror");
|
||||||
|
when.typeKeys(
|
||||||
|
"\uE013\uE013\uE013\uE013\uE013\uE013\uE013\uE013\uE013\uE013\uE013\uE013 {"
|
||||||
|
);
|
||||||
|
should.exist(errorSelector);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fill", () => {
|
||||||
|
it("add", () => {
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "fill",
|
||||||
|
layer: "example",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "fill",
|
||||||
|
source: "example",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Change source
|
||||||
|
it("change source");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("line", () => {
|
||||||
|
it("add", () => {
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "line",
|
||||||
|
layer: "example",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "line",
|
||||||
|
source: "example",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("groups", () => {
|
||||||
|
// TODO
|
||||||
|
// Click each of the layer groups.
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("symbol", () => {
|
||||||
|
it("add", () => {
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "symbol",
|
||||||
|
layer: "example",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "symbol",
|
||||||
|
source: "example",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("raster", () => {
|
||||||
|
it("add", () => {
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "raster",
|
||||||
|
layer: "raster",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "raster",
|
||||||
|
source: "raster",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("circle", () => {
|
||||||
|
it("add", () => {
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "circle",
|
||||||
|
layer: "example",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "circle",
|
||||||
|
source: "example",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fill extrusion", () => {
|
||||||
|
it("add", () => {
|
||||||
|
var id = when.fillLayersModal({
|
||||||
|
type: "fill-extrusion",
|
||||||
|
layer: "example",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(a: any) => a.layers,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
type: "fill-extrusion",
|
||||||
|
source: "example",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("groups", () => {
|
||||||
|
it("simple", () => {
|
||||||
|
when.setStyle("geojson");
|
||||||
|
|
||||||
|
when.openLayersModal();
|
||||||
|
when.fillLayersModal({
|
||||||
|
id: "foo",
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
when.openLayersModal();
|
||||||
|
when.fillLayersModal({
|
||||||
|
id: "foo_bar",
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
when.openLayersModal();
|
||||||
|
when.fillLayersModal({
|
||||||
|
id: "foo_bar_baz",
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
|
||||||
|
should.beVisible("layer-list-item:foo");
|
||||||
|
|
||||||
|
should.notBeVisible("layer-list-item:foo_bar");
|
||||||
|
should.notBeVisible("layer-list-item:foo_bar_baz");
|
||||||
|
|
||||||
|
when.click("layer-list-group:foo-0");
|
||||||
|
|
||||||
|
should.beVisible("layer-list-item:foo");
|
||||||
|
should.beVisible("layer-list-item:foo_bar");
|
||||||
|
should.beVisible("layer-list-item:foo_bar_baz");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import MaputnikDriver from "./driver";
|
||||||
|
|
||||||
|
describe("map", () => {
|
||||||
|
let { beforeAndAfter, given, when, get, should } = new MaputnikDriver();
|
||||||
|
beforeAndAfter();
|
||||||
|
describe("zoom level", () => {
|
||||||
|
it("via url", () => {
|
||||||
|
var zoomLevel = 12.37;
|
||||||
|
when.setStyle("geojson", zoomLevel);
|
||||||
|
should.beVisible("maplibre:ctrl-zoom");
|
||||||
|
should.containText("maplibre:ctrl-zoom", "Zoom: " + zoomLevel);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("via map controls", () => {
|
||||||
|
var zoomLevel = 12.37;
|
||||||
|
when.setStyle("geojson", zoomLevel);
|
||||||
|
|
||||||
|
should.beVisible("maplibre:ctrl-zoom");
|
||||||
|
when.clickZoomin();
|
||||||
|
should.containText("maplibre:ctrl-zoom", "Zoom: "+(zoomLevel + 1));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
import MaputnikDriver from "./driver";
|
||||||
|
|
||||||
|
describe("modals", () => {
|
||||||
|
let { beforeAndAfter, given, when, get, should } = new MaputnikDriver();
|
||||||
|
beforeAndAfter();
|
||||||
|
beforeEach(() => {
|
||||||
|
when.setStyle("");
|
||||||
|
});
|
||||||
|
describe("open", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
when.click("nav:open");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("close", () => {
|
||||||
|
when.closeModal("modal:open");
|
||||||
|
should.notExist("modal:open");
|
||||||
|
});
|
||||||
|
|
||||||
|
it.skip("upload", () => {
|
||||||
|
// HM: I was not able to make the following choose file actually to select a file and close the modal...
|
||||||
|
when.chooseExampleFile();
|
||||||
|
|
||||||
|
should.styleStoreEqualToExampleFileData();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("load from url", () => {
|
||||||
|
var styleFileUrl = get.exampleFileUrl();
|
||||||
|
|
||||||
|
when.setValue(get.dataAttribute("modal:open.url.input"), styleFileUrl);
|
||||||
|
when.click("modal:open.url.button");
|
||||||
|
when.waitForExampleFileRequset();
|
||||||
|
|
||||||
|
should.styleStoreEqualToExampleFileData();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("shortcuts", () => {
|
||||||
|
it("open/close", () => {
|
||||||
|
when.setStyle("");
|
||||||
|
when.typeKeys("?");
|
||||||
|
when.closeModal("modal:shortcuts");
|
||||||
|
should.notExist("modal:shortcuts");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("export", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
when.click("nav:export");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("close", () => {
|
||||||
|
when.closeModal("modal:export");
|
||||||
|
should.notExist("modal:export");
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Work out how to download a file and check the contents
|
||||||
|
it("download");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("sources", () => {
|
||||||
|
it("active sources");
|
||||||
|
it("public source");
|
||||||
|
it("add new source");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("inspect", () => {
|
||||||
|
it("toggle", () => {
|
||||||
|
when.setStyle("geojson");
|
||||||
|
|
||||||
|
when.selectWithin("nav:inspect", "inspect");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("style settings", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
when.click("nav:settings");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("name", () => {
|
||||||
|
when.click("field-doc-button-Name");
|
||||||
|
|
||||||
|
should.containText("spec-field-doc", "name for the style");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("show name specifications", () => {
|
||||||
|
when.setValue(get.dataAttribute("modal:settings.name"), "foobar");
|
||||||
|
when.click("modal:settings.owner");
|
||||||
|
|
||||||
|
should.equalStyleStore((obj) => obj.name, "foobar");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("owner", () => {
|
||||||
|
when.setValue(get.dataAttribute("modal:settings.owner"), "foobar");
|
||||||
|
when.click("modal:settings.name");
|
||||||
|
|
||||||
|
should.equalStyleStore((obj) => obj.owner, "foobar");
|
||||||
|
});
|
||||||
|
it("sprite url", () => {
|
||||||
|
when.setValue(
|
||||||
|
get.dataAttribute("modal:settings.sprite"),
|
||||||
|
"http://example.com"
|
||||||
|
);
|
||||||
|
when.click("modal:settings.name");
|
||||||
|
|
||||||
|
should.equalStyleStore((obj) => obj.sprite, "http://example.com");
|
||||||
|
});
|
||||||
|
it("glyphs url", () => {
|
||||||
|
var glyphsUrl = "http://example.com/{fontstack}/{range}.pbf";
|
||||||
|
when.setValue(get.dataAttribute("modal:settings.glyphs"), glyphsUrl);
|
||||||
|
when.click("modal:settings.name");
|
||||||
|
|
||||||
|
should.equalStyleStore((obj) => obj.glyphs, glyphsUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("maptiler access token", () => {
|
||||||
|
var apiKey = "testing123";
|
||||||
|
when.setValue(
|
||||||
|
get.dataAttribute(
|
||||||
|
"modal:settings.maputnik:openmaptiles_access_token"
|
||||||
|
),
|
||||||
|
apiKey
|
||||||
|
);
|
||||||
|
when.click("modal:settings.name");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(obj) => obj.metadata["maputnik:openmaptiles_access_token"],
|
||||||
|
apiKey
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("thunderforest access token", () => {
|
||||||
|
var apiKey = "testing123";
|
||||||
|
when.setValue(
|
||||||
|
get.dataAttribute(
|
||||||
|
"modal:settings.maputnik:thunderforest_access_token"
|
||||||
|
),
|
||||||
|
apiKey
|
||||||
|
);
|
||||||
|
when.click("modal:settings.name");
|
||||||
|
|
||||||
|
should.equalStyleStore(
|
||||||
|
(obj) => obj.metadata["maputnik:thunderforest_access_token"],
|
||||||
|
apiKey
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("style renderer", () => {
|
||||||
|
cy.on("uncaught:exception", () => false); // this is due to the fact that this is an invalid style for openlayers
|
||||||
|
when.select("modal:settings.maputnik:renderer", "ol");
|
||||||
|
should.beSelected("modal:settings.maputnik:renderer", "ol");
|
||||||
|
|
||||||
|
when.click("modal:settings.name");
|
||||||
|
|
||||||
|
should.equalStyleStore((obj) => obj.metadata["maputnik:renderer"], "ol");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("sources", () => {
|
||||||
|
it("toggle");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"id": "test-style",
|
||||||
|
"version": 8,
|
||||||
|
"name": "Test Style",
|
||||||
|
"metadata": {
|
||||||
|
"maputnik:renderer": "mlgljs"
|
||||||
|
},
|
||||||
|
"sources": {},
|
||||||
|
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"sprites": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"layers": [
|
||||||
|
{
|
||||||
|
"id": "background",
|
||||||
|
"type": "background"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": 8,
|
"version": 8,
|
||||||
"name": "Test Style",
|
"name": "Test Style",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"maputnik:renderer": "mbgljs"
|
"maputnik:renderer": "mlgljs"
|
||||||
},
|
},
|
||||||
"sources": {},
|
"sources": {},
|
||||||
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"id": "test-style",
|
||||||
|
"version": 8,
|
||||||
|
"name": "Test Style",
|
||||||
|
"metadata": {
|
||||||
|
"maputnik:renderer": "mlgljs"
|
||||||
|
},
|
||||||
|
"sources": {
|
||||||
|
"example": {
|
||||||
|
"type": "vector",
|
||||||
|
"data": {
|
||||||
|
"type": "FeatureCollection",
|
||||||
|
"features":[{
|
||||||
|
"type": "Feature",
|
||||||
|
"properties": {
|
||||||
|
"name": "Dinagat Islands"
|
||||||
|
},
|
||||||
|
"geometry":{
|
||||||
|
"type": "Point",
|
||||||
|
"coordinates": [125.6, 10.1]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"raster": {
|
||||||
|
"tileSize": 256,
|
||||||
|
"tiles": ["http://localhost/example/{x}/{y}/{z}"],
|
||||||
|
"type": "raster"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"sprites": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"layers": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"id": "test-style",
|
||||||
|
"version": 8,
|
||||||
|
"name": "Test Style",
|
||||||
|
"metadata": {
|
||||||
|
"maputnik:renderer": "mlgljs"
|
||||||
|
},
|
||||||
|
"sources": {
|
||||||
|
"example": {
|
||||||
|
"type": "vector",
|
||||||
|
"data": {
|
||||||
|
"type": "FeatureCollection",
|
||||||
|
"features":[{
|
||||||
|
"type": "Feature",
|
||||||
|
"properties": {
|
||||||
|
"name": "Dinagat Islands"
|
||||||
|
},
|
||||||
|
"geometry":{
|
||||||
|
"type": "Point",
|
||||||
|
"coordinates": [125.6, 10.1]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"sprites": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"layers": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"id": "test-style",
|
||||||
|
"version": 8,
|
||||||
|
"name": "Test Style",
|
||||||
|
"metadata": {
|
||||||
|
"maputnik:renderer": "mlgljs"
|
||||||
|
},
|
||||||
|
"sources": {
|
||||||
|
"raster": {
|
||||||
|
"tileSize": 256,
|
||||||
|
"tiles": ["http://localhost/example/{x}/{y}/{z}"],
|
||||||
|
"type": "raster"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"sprites": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"layers": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/// <reference types="cypress" />
|
||||||
|
// ***********************************************
|
||||||
|
// This example commands.ts shows you how to
|
||||||
|
// create various custom commands and overwrite
|
||||||
|
// existing commands.
|
||||||
|
//
|
||||||
|
// For more comprehensive examples of custom
|
||||||
|
// commands please read more here:
|
||||||
|
// https://on.cypress.io/custom-commands
|
||||||
|
// ***********************************************
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// -- This is a parent command --
|
||||||
|
// Cypress.Commands.add('login', (email, password) => { ... })
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// -- This is a child command --
|
||||||
|
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// -- This is a dual command --
|
||||||
|
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// -- This will overwrite an existing command --
|
||||||
|
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
||||||
|
//
|
||||||
|
// declare global {
|
||||||
|
// namespace Cypress {
|
||||||
|
// interface Chainable {
|
||||||
|
// login(email: string, password: string): Chainable<void>
|
||||||
|
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
|
||||||
|
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
|
||||||
|
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// ***********************************************************
|
||||||
|
// This example support/e2e.ts is processed and
|
||||||
|
// loaded automatically before your test files.
|
||||||
|
//
|
||||||
|
// This is a great place to put global configuration and
|
||||||
|
// behavior that modifies Cypress.
|
||||||
|
//
|
||||||
|
// You can change the location of this file or turn off
|
||||||
|
// automatically serving support files with the
|
||||||
|
// 'supportFile' configuration option.
|
||||||
|
//
|
||||||
|
// You can read more here:
|
||||||
|
// https://on.cypress.io/configuration
|
||||||
|
// ***********************************************************
|
||||||
|
|
||||||
|
// Import commands.js using ES2015 syntax:
|
||||||
|
import "cypress-plugin-tab";
|
||||||
|
import "./commands";
|
||||||
|
|
||||||
|
// Alternatively you can use CommonJS syntax:
|
||||||
|
// require('./commands')
|
||||||
@@ -2,9 +2,10 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
<title>Maputnik</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="src/manifest.json">
|
||||||
|
<link rel="icon" href="src/favicon.ico" type="image/x-icon" />
|
||||||
<style>
|
<style>
|
||||||
html {
|
html {
|
||||||
background-color: rgb(28, 31, 36);
|
background-color: rgb(28, 31, 36);
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading__logo svg {
|
.loading__logo img {
|
||||||
width: 200px;
|
width: 200px;
|
||||||
height: 200px;
|
height: 200px;
|
||||||
}
|
}
|
||||||
@@ -38,9 +39,9 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- TODO: Import dynamically -->
|
|
||||||
<!-- From <https://github.com/hail2u/color-blindness-emulation> -->
|
<!-- From <https://github.com/hail2u/color-blindness-emulation> -->
|
||||||
<svg
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
version="1.1">
|
version="1.1">
|
||||||
<defs>
|
<defs>
|
||||||
@@ -122,10 +123,10 @@
|
|||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<div class="loading">
|
<div class="loading">
|
||||||
<div class="loading__logo">
|
<div class="loading__logo">
|
||||||
<!-- replaced by 'html-webpack-inline-svg-plugin' -->
|
|
||||||
<img inline src="node_modules/maputnik-design/logos/logo-loading.svg" />
|
<img inline src="node_modules/maputnik-design/logos/logo-loading.svg" />
|
||||||
</div>
|
</div>
|
||||||
<div class="loading__text">Loading…</div>
|
<div class="loading__text">Loading…</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script type="module" src="/src/index.jsx"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Generated
+13594
-15238
File diff suppressed because it is too large
Load Diff
+83
-111
@@ -1,18 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "maputnik",
|
"name": "maputnik",
|
||||||
"version": "1.7.0-beta4",
|
"version": "2.0.0-pre.2",
|
||||||
"description": "A MapboxGL visual style editor",
|
"description": "A MapLibre GL visual style editor",
|
||||||
"main": "''",
|
"main": "''",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"stats": "webpack --config config/webpack.production.config.js --profile --json > stats.json",
|
"start": "vite",
|
||||||
"build": "webpack --config config/webpack.production.config.js --progress --profile --colors",
|
"build": "tsc && vite build",
|
||||||
"profiling-build": "webpack --config config/webpack.profiling.config.js --progress --profile --colors",
|
"lint": "eslint ./src --ext ts,tsx,js,jsx --report-unused-disable-directives --max-warnings 0 && npm run lint-css",
|
||||||
"test": "cross-env NODE_ENV=test wdio config/wdio.conf.js",
|
"test": "cypress run",
|
||||||
"test-watch": "cross-env NODE_ENV=test wdio config/wdio.conf.js --watch",
|
"cy:open": "cypress open",
|
||||||
"start": "webpack-dev-server --progress --profile --colors --config config/webpack.config.js",
|
|
||||||
"lint-js": "eslint --ext js --ext jsx src test",
|
|
||||||
"lint-css": "stylelint \"src/styles/*.scss\"",
|
"lint-css": "stylelint \"src/styles/*.scss\"",
|
||||||
"lint": "npm run lint-js && npm run lint-css"
|
"storybook": "storybook dev -h 0.0.0.0 -p 6006",
|
||||||
|
"build-storybook": "storybook build -o build/storybook"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -22,47 +21,50 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://github.com/maputnik/editor#readme",
|
"homepage": "https://github.com/maputnik/editor#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.8.4",
|
|
||||||
"@mapbox/mapbox-gl-rtl-text": "^0.2.3",
|
"@mapbox/mapbox-gl-rtl-text": "^0.2.3",
|
||||||
"@mapbox/mapbox-gl-style-spec": "^13.12.0",
|
"@maplibre/maplibre-gl-style-spec": "^17.0.1",
|
||||||
"@mdi/react": "^1.4.0",
|
"@mdi/js": "^6.6.96",
|
||||||
"array-move": "^2.2.1",
|
"@mdi/react": "^1.5.0",
|
||||||
"classnames": "^2.2.6",
|
"array-move": "^4.0.0",
|
||||||
"codemirror": "^5.52.0",
|
"buffer": "^6.0.3",
|
||||||
"color": "^3.1.2",
|
"classnames": "^2.3.1",
|
||||||
"detect-browser": "^5.0.0",
|
"codemirror": "^5.65.2",
|
||||||
"file-saver": "^2.0.2",
|
"color": "^4.2.3",
|
||||||
|
"detect-browser": "^5.3.0",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
|
"json-stringify-pretty-compact": "^3.0.0",
|
||||||
"json-to-ast": "^2.1.0",
|
"json-to-ast": "^2.1.0",
|
||||||
"jsonlint": "github:josdejong/jsonlint#85a19d7",
|
"jsonlint": "github:josdejong/jsonlint#85a19d7",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.21",
|
||||||
"lodash.capitalize": "^4.2.1",
|
"lodash.capitalize": "^4.2.1",
|
||||||
"lodash.clamp": "^4.0.3",
|
"lodash.clamp": "^4.0.3",
|
||||||
"lodash.clonedeep": "^4.5.0",
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"lodash.get": "^4.4.2",
|
"lodash.get": "^4.4.2",
|
||||||
"lodash.isequal": "^4.5.0",
|
"lodash.isequal": "^4.5.0",
|
||||||
"lodash.throttle": "^4.1.1",
|
"lodash.throttle": "^4.1.1",
|
||||||
"mapbox-gl": "^1.9.1",
|
|
||||||
"mapbox-gl-inspect": "^1.3.1",
|
"mapbox-gl-inspect": "^1.3.1",
|
||||||
"maputnik-design": "github:maputnik/design#f7a2b4d",
|
"maplibre-gl": "^2.4.0",
|
||||||
"ol": "^6.3.1",
|
"maputnik-design": "github:maputnik/design#172b06c",
|
||||||
"ol-mapbox-style": "^6.0.1",
|
"ol": "^6.14.1",
|
||||||
"prop-types": "^15.7.2",
|
"ol-mapbox-style": "^7.1.1",
|
||||||
"react": "^16.12.0",
|
"prop-types": "^15.8.1",
|
||||||
"react-accessible-accordion": "^3.0.1",
|
"react": "^16.0.0",
|
||||||
"react-aria-menubutton": "^6.3.0",
|
"react-accessible-accordion": "^4.0.0",
|
||||||
"react-aria-modal": "^4.0.0",
|
"react-aria-menubutton": "^7.0.3",
|
||||||
|
"react-aria-modal": "^4.0.1",
|
||||||
"react-autobind": "^1.0.6",
|
"react-autobind": "^1.0.6",
|
||||||
"react-autocomplete": "^1.8.1",
|
"react-autocomplete": "^1.8.1",
|
||||||
"react-collapse": "^5.0.1",
|
"react-collapse": "^5.1.1",
|
||||||
"react-color": "^2.18.0",
|
"react-color": "^2.19.3",
|
||||||
"react-dom": "^16.12.0",
|
"react-dom": "^16.0.0",
|
||||||
"react-file-reader-input": "^2.0.0",
|
"react-file-reader-input": "^2.0.0",
|
||||||
"react-icon-base": "^2.1.2",
|
"react-icon-base": "^2.1.2",
|
||||||
"react-icons": "^3.9.0",
|
"react-icons": "^4.3.1",
|
||||||
"react-motion": "^0.5.2",
|
"react-sortable-hoc": "^2.0.0",
|
||||||
"react-sortable-hoc": "^1.11.0",
|
|
||||||
"reconnecting-websocket": "^4.4.0",
|
"reconnecting-websocket": "^4.4.0",
|
||||||
"slugify": "^1.3.6",
|
"sass": "^1.50.0",
|
||||||
|
"slugify": "^1.6.5",
|
||||||
|
"string-hash": "^1.1.3",
|
||||||
"url": "^0.11.0"
|
"url": "^0.11.0"
|
||||||
},
|
},
|
||||||
"jshintConfig": {
|
"jshintConfig": {
|
||||||
@@ -82,83 +84,53 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
|
||||||
"plugins": [
|
|
||||||
"react"
|
|
||||||
],
|
|
||||||
"extends": [
|
|
||||||
"plugin:react/recommended"
|
|
||||||
],
|
|
||||||
"env": {
|
|
||||||
"browser": true,
|
|
||||||
"node": true,
|
|
||||||
"es6": true
|
|
||||||
},
|
|
||||||
"parser": "babel-eslint",
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaVersion": 6,
|
|
||||||
"sourceType": "module",
|
|
||||||
"ecmaFeatures": {
|
|
||||||
"impliedStrict": true,
|
|
||||||
"experimentalObjectRestSpread": true,
|
|
||||||
"jsx": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"settings": {
|
|
||||||
"react": {
|
|
||||||
"version": "detect"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.8.4",
|
"@rollup/plugin-replace": "^5.0.5",
|
||||||
"@babel/plugin-proposal-class-properties": "^7.5.5",
|
"@shellygo/cypress-test-utils": "^2.0.9",
|
||||||
"@babel/plugin-transform-runtime": "^7.6.2",
|
"@storybook/addon-a11y": "^7.6.5",
|
||||||
"@babel/preset-env": "^7.6.3",
|
"@storybook/addon-actions": "^7.6.5",
|
||||||
"@babel/preset-flow": "^7.0.0",
|
"@storybook/addon-links": "^7.6.5",
|
||||||
"@babel/preset-react": "^7.6.3",
|
"@storybook/addon-storysource": "^7.6.5",
|
||||||
"@mdi/js": "^5.0.45",
|
"@storybook/addons": "^7.6.5",
|
||||||
"@wdio/cli": "^6.0.5",
|
"@storybook/builder-vite": "^7.6.5",
|
||||||
"@wdio/local-runner": "^6.0.5",
|
"@storybook/react": "^7.6.5",
|
||||||
"@wdio/mocha-framework": "^6.0.4",
|
"@storybook/react-vite": "^7.6.5",
|
||||||
"@wdio/selenium-standalone-service": "^6.0.4",
|
"@storybook/theming": "^7.6.5",
|
||||||
"@wdio/spec-reporter": "^6.0.4",
|
"@types/codemirror": "^5.60.15",
|
||||||
"@wdio/sync": "^6.0.1",
|
"@types/color": "^3.0.6",
|
||||||
"babel-eslint": "^10.0.3",
|
"@types/cors": "^2.8.17",
|
||||||
"babel-loader": "^8.1.0",
|
"@types/file-saver": "^2.0.7",
|
||||||
"babel-plugin-istanbul": "^6.0.0",
|
"@types/lodash.capitalize": "^4.2.9",
|
||||||
"babel-plugin-static-fs": "^3.0.0",
|
"@types/lodash.isequal": "^4.5.8",
|
||||||
"copy-webpack-plugin": "^5.1.1",
|
"@types/lodash.throttle": "^4.1.9",
|
||||||
|
"@types/react": "^16.14.52",
|
||||||
|
"@types/react-aria-modal": "^4.0.9",
|
||||||
|
"@types/react-autocomplete": "^1.8.9",
|
||||||
|
"@types/react-collapse": "^5.0.4",
|
||||||
|
"@types/react-color": "^3.0.10",
|
||||||
|
"@types/react-dom": "^16.9.24",
|
||||||
|
"@types/react-file-reader-input": "^2.0.4",
|
||||||
|
"@types/react-icon-base": "^2.1.6",
|
||||||
|
"@types/uuid": "^9.0.7",
|
||||||
|
"@vitejs/plugin-react": "^4.2.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cross-env": "^7.0.0",
|
"cypress": "^13.6.1",
|
||||||
"css-loader": "^3.4.2",
|
"eslint": "^8.53.0",
|
||||||
"eslint": "^6.8.0",
|
"eslint-plugin-react": "^7.33.2",
|
||||||
"eslint-plugin-react": "^7.18.3",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
"express": "^4.17.1",
|
"eslint-plugin-react-refresh": "^0.4.4",
|
||||||
"file-loader": "^6.0.0",
|
"express": "^4.17.3",
|
||||||
"html-webpack-inline-svg-plugin": "^1.3.0",
|
|
||||||
"html-webpack-plugin": "^3.2.0",
|
|
||||||
"is-docker": "^2.0.0",
|
|
||||||
"istanbul": "^0.4.5",
|
"istanbul": "^0.4.5",
|
||||||
"istanbul-lib-coverage": "^3.0.0",
|
"istanbul-lib-coverage": "^3.2.0",
|
||||||
"mkdirp": "^1.0.4",
|
"mocha": "^9.2.2",
|
||||||
"mocha": "^7.0.1",
|
"postcss": "^8.4.12",
|
||||||
"node-sass": "^4.13.1",
|
"react-hot-loader": "^4.13.0",
|
||||||
"react-hot-loader": "^4.12.19",
|
"storybook": "^7.6.5",
|
||||||
"sass-loader": "^8.0.2",
|
"stylelint": "^14.6.1",
|
||||||
"selenium-standalone": "^6.17.0",
|
"stylelint-config-recommended-scss": "^6.0.0",
|
||||||
"style-loader": "^1.1.3",
|
"stylelint-scss": "^4.2.0",
|
||||||
"stylelint": "^13.3.0",
|
"typescript": "^5.3.3",
|
||||||
"stylelint-config-recommended-scss": "^4.2.0",
|
"uuid": "^8.3.2",
|
||||||
"stylelint-scss": "^3.14.2",
|
"vite": "^5.0.0"
|
||||||
"svg-inline-loader": "^0.8.2",
|
|
||||||
"transform-loader": "^0.2.4",
|
|
||||||
"uuid": "^7.0.3",
|
|
||||||
"webdriverio": "^6.0.5",
|
|
||||||
"webpack": "^4.41.6",
|
|
||||||
"webpack-bundle-analyzer": "^3.6.0",
|
|
||||||
"webpack-cleanup-plugin": "^0.5.1",
|
|
||||||
"webpack-cli": "^3.3.11",
|
|
||||||
"webpack-dev-server": "^3.10.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+174
-96
@@ -2,29 +2,31 @@ import autoBind from 'react-autobind';
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import cloneDeep from 'lodash.clonedeep'
|
import cloneDeep from 'lodash.clonedeep'
|
||||||
import clamp from 'lodash.clamp'
|
import clamp from 'lodash.clamp'
|
||||||
|
import buffer from 'buffer'
|
||||||
import get from 'lodash.get'
|
import get from 'lodash.get'
|
||||||
import {unset} from 'lodash'
|
import {unset} from 'lodash'
|
||||||
import arrayMove from 'array-move'
|
import {arrayMoveMutable} from 'array-move'
|
||||||
import url from 'url'
|
import url from 'url'
|
||||||
|
import hash from "string-hash";
|
||||||
|
|
||||||
import MapboxGlMap from './map/MapboxGlMap'
|
import MapMaplibreGl from './MapMaplibreGl'
|
||||||
import OpenLayersMap from './map/OpenLayersMap'
|
import MapOpenLayers from './MapOpenLayers'
|
||||||
import LayerList from './layers/LayerList'
|
import LayerList from './LayerList'
|
||||||
import LayerEditor from './layers/LayerEditor'
|
import LayerEditor from './LayerEditor'
|
||||||
import Toolbar from './Toolbar'
|
import AppToolbar from './AppToolbar'
|
||||||
import AppLayout from './AppLayout'
|
import AppLayout from './AppLayout'
|
||||||
import MessagePanel from './MessagePanel'
|
import MessagePanel from './AppMessagePanel'
|
||||||
|
|
||||||
import SettingsModal from './modals/SettingsModal'
|
import ModalSettings from './ModalSettings'
|
||||||
import ExportModal from './modals/ExportModal'
|
import ModalExport from './ModalExport'
|
||||||
import SourcesModal from './modals/SourcesModal'
|
import ModalSources from './ModalSources'
|
||||||
import OpenModal from './modals/OpenModal'
|
import ModalOpen from './ModalOpen'
|
||||||
import ShortcutsModal from './modals/ShortcutsModal'
|
import ModalShortcuts from './ModalShortcuts'
|
||||||
import SurveyModal from './modals/SurveyModal'
|
import ModalSurvey from './ModalSurvey'
|
||||||
import DebugModal from './modals/DebugModal'
|
import ModalDebug from './ModalDebug'
|
||||||
|
|
||||||
import { downloadGlyphsMetadata, downloadSpriteMetadata } from '../libs/metadata'
|
import { downloadGlyphsMetadata, downloadSpriteMetadata } from '../libs/metadata'
|
||||||
import {latest, validate} from '@mapbox/mapbox-gl-style-spec'
|
import {latest, validate} from '@maplibre/maplibre-gl-style-spec'
|
||||||
import style from '../libs/style'
|
import style from '../libs/style'
|
||||||
import { initialStyleUrl, loadStyleUrl, removeStyleQuerystring } from '../libs/urlopen'
|
import { initialStyleUrl, loadStyleUrl, removeStyleQuerystring } from '../libs/urlopen'
|
||||||
import { undoMessages, redoMessages } from '../libs/diffmessage'
|
import { undoMessages, redoMessages } from '../libs/diffmessage'
|
||||||
@@ -35,23 +37,10 @@ import LayerWatcher from '../libs/layerwatcher'
|
|||||||
import tokens from '../config/tokens.json'
|
import tokens from '../config/tokens.json'
|
||||||
import isEqual from 'lodash.isequal'
|
import isEqual from 'lodash.isequal'
|
||||||
import Debug from '../libs/debug'
|
import Debug from '../libs/debug'
|
||||||
import queryUtil from '../libs/query-util'
|
import {formatLayerId} from '../util/format';
|
||||||
import {formatLayerId} from './util/format';
|
|
||||||
|
|
||||||
import MapboxGl from 'mapbox-gl'
|
// Buffer must be defined globally for @maplibre/maplibre-gl-style-spec validate() function to succeed.
|
||||||
|
window.Buffer = buffer.Buffer;
|
||||||
|
|
||||||
// Similar functionality as <https://github.com/mapbox/mapbox-gl-js/blob/7e30aadf5177486c2cfa14fe1790c60e217b5e56/src/util/mapbox.js>
|
|
||||||
function normalizeSourceURL (url, apiToken="") {
|
|
||||||
const matches = url.match(/^mapbox:\/\/(.*)/);
|
|
||||||
if (matches) {
|
|
||||||
// mapbox://mapbox.mapbox-streets-v7
|
|
||||||
return `https://api.mapbox.com/v4/${matches[1]}.json?secure&access_token=${apiToken}`
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setFetchAccessToken(url, mapStyle) {
|
function setFetchAccessToken(url, mapStyle) {
|
||||||
const matchesTilehosting = url.match(/\.tilehosting\.com/);
|
const matchesTilehosting = url.match(/\.tilehosting\.com/);
|
||||||
@@ -147,7 +136,7 @@ export default class App extends React.Component {
|
|||||||
{
|
{
|
||||||
key: "m",
|
key: "m",
|
||||||
handler: () => {
|
handler: () => {
|
||||||
document.querySelector(".mapboxgl-canvas").focus();
|
document.querySelector(".maplibregl-canvas").focus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -189,7 +178,7 @@ export default class App extends React.Component {
|
|||||||
console.log('Falling back to local storage for storing styles')
|
console.log('Falling back to local storage for storing styles')
|
||||||
this.styleStore = new StyleStore()
|
this.styleStore = new StyleStore()
|
||||||
}
|
}
|
||||||
this.styleStore.latestStyle(mapStyle => this.onStyleChanged(mapStyle))
|
this.styleStore.latestStyle(mapStyle => this.onStyleChanged(mapStyle, {initialLoad: true}))
|
||||||
|
|
||||||
if(Debug.enabled()) {
|
if(Debug.enabled()) {
|
||||||
Debug.set("maputnik", "styleStore", this.styleStore);
|
Debug.set("maputnik", "styleStore", this.styleStore);
|
||||||
@@ -231,7 +220,7 @@ export default class App extends React.Component {
|
|||||||
survey: false,
|
survey: false,
|
||||||
debug: false,
|
debug: false,
|
||||||
},
|
},
|
||||||
mapboxGlDebugOptions: {
|
maplibreGlDebugOptions: {
|
||||||
showTileBoundaries: false,
|
showTileBoundaries: false,
|
||||||
showCollisionBoxes: false,
|
showCollisionBoxes: false,
|
||||||
showOverdrawInspector: false,
|
showOverdrawInspector: false,
|
||||||
@@ -301,7 +290,7 @@ export default class App extends React.Component {
|
|||||||
// If we're changing renderer reset the map state.
|
// If we're changing renderer reset the map state.
|
||||||
if (
|
if (
|
||||||
property === 'maputnik:renderer' &&
|
property === 'maputnik:renderer' &&
|
||||||
value !== get(this.state.mapStyle, ['metadata', 'maputnik:renderer'], 'mbgljs')
|
value !== get(this.state.mapStyle, ['metadata', 'maputnik:renderer'], 'mlgljs')
|
||||||
) {
|
) {
|
||||||
this.setState({
|
this.setState({
|
||||||
mapState: 'map'
|
mapState: 'map'
|
||||||
@@ -322,9 +311,14 @@ export default class App extends React.Component {
|
|||||||
opts = {
|
opts = {
|
||||||
save: true,
|
save: true,
|
||||||
addRevision: true,
|
addRevision: true,
|
||||||
|
initialLoad: false,
|
||||||
...opts,
|
...opts,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (opts.initialLoad) {
|
||||||
|
this.getInitialStateFromUrl(newStyle);
|
||||||
|
}
|
||||||
|
|
||||||
const errors = validate(newStyle, latest) || [];
|
const errors = validate(newStyle, latest) || [];
|
||||||
|
|
||||||
// The validate function doesn't give us errors for duplicate error with
|
// The validate function doesn't give us errors for duplicate error with
|
||||||
@@ -440,9 +434,11 @@ export default class App extends React.Component {
|
|||||||
mapStyle: newStyle,
|
mapStyle: newStyle,
|
||||||
dirtyMapStyle: dirtyMapStyle,
|
dirtyMapStyle: dirtyMapStyle,
|
||||||
errors: mappedErrors,
|
errors: mappedErrors,
|
||||||
|
}, () => {
|
||||||
|
this.fetchSources();
|
||||||
|
this.setStateInUrl();
|
||||||
})
|
})
|
||||||
|
|
||||||
this.fetchSources();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onUndo = () => {
|
onUndo = () => {
|
||||||
@@ -478,7 +474,7 @@ export default class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
layers = layers.slice(0);
|
layers = layers.slice(0);
|
||||||
layers = arrayMove(layers, oldIndex, newIndex);
|
arrayMoveMutable(layers, oldIndex, newIndex);
|
||||||
this.onLayersChange(layers);
|
this.onLayersChange(layers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,7 +537,7 @@ export default class App extends React.Component {
|
|||||||
setMapState = (newState) => {
|
setMapState = (newState) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
mapState: newState
|
mapState: newState
|
||||||
})
|
}, this.setStateInUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultValues = (styleObj) => {
|
setDefaultValues = (styleObj) => {
|
||||||
@@ -551,7 +547,7 @@ export default class App extends React.Component {
|
|||||||
...styleObj,
|
...styleObj,
|
||||||
metadata: {
|
metadata: {
|
||||||
...styleObj.metadata,
|
...styleObj.metadata,
|
||||||
'maputnik:renderer': 'mbgljs'
|
'maputnik:renderer': 'mlgljs'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return changedStyle
|
return changedStyle
|
||||||
@@ -566,25 +562,20 @@ export default class App extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchSources() {
|
fetchSources() {
|
||||||
const sourceList = {...this.state.sources};
|
const sourceList = {};
|
||||||
|
|
||||||
for(let [key, val] of Object.entries(this.state.mapStyle.sources)) {
|
for(let [key, val] of Object.entries(this.state.mapStyle.sources)) {
|
||||||
if(sourceList.hasOwnProperty(key)) {
|
if(
|
||||||
continue;
|
!this.state.sources.hasOwnProperty(key) &&
|
||||||
}
|
val.type === "vector" &&
|
||||||
|
val.hasOwnProperty("url")
|
||||||
|
) {
|
||||||
|
sourceList[key] = {
|
||||||
|
type: val.type,
|
||||||
|
layers: []
|
||||||
|
};
|
||||||
|
|
||||||
sourceList[key] = {
|
|
||||||
type: val.type,
|
|
||||||
layers: []
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!this.state.sources.hasOwnProperty(key) && val.type === "vector" && val.hasOwnProperty("url")) {
|
|
||||||
let url = val.url;
|
let url = val.url;
|
||||||
try {
|
|
||||||
url = normalizeSourceURL(url, MapboxGl.accessToken);
|
|
||||||
} catch(err) {
|
|
||||||
console.warn("Failed to normalizeSourceURL: ", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
url = setFetchAccessToken(url, this.state.mapStyle)
|
url = setFetchAccessToken(url, this.state.mapStyle)
|
||||||
@@ -595,29 +586,33 @@ export default class App extends React.Component {
|
|||||||
fetch(url, {
|
fetch(url, {
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then(response => response.json())
|
||||||
return response.json();
|
.then(json => {
|
||||||
})
|
|
||||||
.then((json) => {
|
|
||||||
if(!json.hasOwnProperty("vector_layers")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new objects before setState
|
if(!json.hasOwnProperty("vector_layers")) {
|
||||||
const sources = Object.assign({}, this.state.sources);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for(let layer of json.vector_layers) {
|
// Create new objects before setState
|
||||||
sources[key].layers.push(layer.id)
|
const sources = Object.assign({}, {
|
||||||
}
|
[key]: this.state.sources[key],
|
||||||
|
});
|
||||||
|
|
||||||
console.debug("Updating source: "+key);
|
for(let layer of json.vector_layers) {
|
||||||
this.setState({
|
sources[key].layers.push(layer.id)
|
||||||
sources: sources
|
}
|
||||||
});
|
|
||||||
})
|
console.debug("Updating source: "+key);
|
||||||
.catch((err) => {
|
this.setState({
|
||||||
console.error("Failed to process sources for '%s'", url, err);
|
sources: sources
|
||||||
})
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error("Failed to process sources for '%s'", url, err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sourceList[key] = this.state.sources[key] || this.state.mapStyle.sources[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,7 +626,7 @@ export default class App extends React.Component {
|
|||||||
|
|
||||||
_getRenderer () {
|
_getRenderer () {
|
||||||
const metadata = this.state.mapStyle.metadata || {};
|
const metadata = this.state.mapStyle.metadata || {};
|
||||||
return metadata['maputnik:renderer'] || 'mbgljs';
|
return metadata['maputnik:renderer'] || 'mlgljs';
|
||||||
}
|
}
|
||||||
|
|
||||||
onMapChange = (mapView) => {
|
onMapChange = (mapView) => {
|
||||||
@@ -663,16 +658,16 @@ export default class App extends React.Component {
|
|||||||
|
|
||||||
// Check if OL code has been loaded?
|
// Check if OL code has been loaded?
|
||||||
if(renderer === 'ol') {
|
if(renderer === 'ol') {
|
||||||
mapElement = <OpenLayersMap
|
mapElement = <MapOpenLayers
|
||||||
{...mapProps}
|
{...mapProps}
|
||||||
onChange={this.onMapChange}
|
onChange={this.onMapChange}
|
||||||
debugToolbox={this.state.openlayersDebugOptions.debugToolbox}
|
debugToolbox={this.state.openlayersDebugOptions.debugToolbox}
|
||||||
onLayerSelect={this.onLayerSelect}
|
onLayerSelect={this.onLayerSelect}
|
||||||
/>
|
/>
|
||||||
} else {
|
} else {
|
||||||
mapElement = <MapboxGlMap {...mapProps}
|
mapElement = <MapMaplibreGl {...mapProps}
|
||||||
onChange={this.onMapChange}
|
onChange={this.onMapChange}
|
||||||
options={this.state.mapboxGlDebugOptions}
|
options={this.state.maplibreGlDebugOptions}
|
||||||
inspectModeEnabled={this.state.mapState === "inspect"}
|
inspectModeEnabled={this.state.mapState === "inspect"}
|
||||||
highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]}
|
highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]}
|
||||||
onLayerSelect={this.onLayerSelect} />
|
onLayerSelect={this.onLayerSelect} />
|
||||||
@@ -685,15 +680,98 @@ export default class App extends React.Component {
|
|||||||
const elementStyle = {};
|
const elementStyle = {};
|
||||||
if (filterName) {
|
if (filterName) {
|
||||||
elementStyle.filter = `url('#${filterName}')`;
|
elementStyle.filter = `url('#${filterName}')`;
|
||||||
};
|
}
|
||||||
|
|
||||||
return <div style={elementStyle} className="maputnik-map__container">
|
return <div style={elementStyle} className="maputnik-map__container" data-wd-key="maplibre:container">
|
||||||
{mapElement}
|
{mapElement}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setStateInUrl = () => {
|
||||||
|
const {mapState, mapStyle, isOpen} = this.state;
|
||||||
|
const {selectedLayerIndex} = this.state;
|
||||||
|
const url = new URL(location.href);
|
||||||
|
const hashVal = hash(JSON.stringify(mapStyle));
|
||||||
|
url.searchParams.set("layer", `${hashVal}~${selectedLayerIndex}`);
|
||||||
|
|
||||||
|
const openModals = Object.entries(isOpen)
|
||||||
|
.map(([key, val]) => (val === true ? key : null))
|
||||||
|
.filter(val => val !== null);
|
||||||
|
|
||||||
|
if (openModals.length > 0) {
|
||||||
|
url.searchParams.set("modal", openModals.join(","));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
url.searchParams.delete("modal");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapState === "map") {
|
||||||
|
url.searchParams.delete("view");
|
||||||
|
}
|
||||||
|
else if (mapState === "inspect") {
|
||||||
|
url.searchParams.set("view", "inspect");
|
||||||
|
}
|
||||||
|
|
||||||
|
history.replaceState({selectedLayerIndex}, "Maputnik", url.href);
|
||||||
|
}
|
||||||
|
|
||||||
|
getInitialStateFromUrl = (mapStyle) => {
|
||||||
|
const url = new URL(location.href);
|
||||||
|
const modalParam = url.searchParams.get("modal");
|
||||||
|
if (modalParam && modalParam !== "") {
|
||||||
|
const modals = modalParam.split(",");
|
||||||
|
const modalObj = {};
|
||||||
|
modals.forEach(modalName => {
|
||||||
|
modalObj[modalName] = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
isOpen: {
|
||||||
|
...this.state.isOpen,
|
||||||
|
...modalObj,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const view = url.searchParams.get("view");
|
||||||
|
if (view && view !== "") {
|
||||||
|
this.setMapState(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = url.searchParams.get("layer");
|
||||||
|
if (path) {
|
||||||
|
try {
|
||||||
|
const parts = path.split("~");
|
||||||
|
const [hashVal, selectedLayerIndex] = [
|
||||||
|
parts[0],
|
||||||
|
parseInt(parts[1], 10),
|
||||||
|
];
|
||||||
|
|
||||||
|
let valid = true;
|
||||||
|
if (hashVal !== "-") {
|
||||||
|
const currentHashVal = hash(JSON.stringify(mapStyle));
|
||||||
|
if (currentHashVal !== parseInt(hashVal, 10)) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (valid) {
|
||||||
|
this.setState({
|
||||||
|
selectedLayerIndex,
|
||||||
|
selectedLayerOriginalId: mapStyle.layers[selectedLayerIndex].id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.warn(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onLayerSelect = (index) => {
|
onLayerSelect = (index) => {
|
||||||
this.setState({ selectedLayerIndex: index })
|
this.setState({
|
||||||
|
selectedLayerIndex: index,
|
||||||
|
selectedLayerOriginalId: this.state.mapStyle.layers[index].id,
|
||||||
|
}, this.setStateInUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
setModal(modalName, value) {
|
setModal(modalName, value) {
|
||||||
@@ -706,7 +784,7 @@ export default class App extends React.Component {
|
|||||||
...this.state.isOpen,
|
...this.state.isOpen,
|
||||||
[modalName]: value
|
[modalName]: value
|
||||||
}
|
}
|
||||||
})
|
}, this.setStateInUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleModal(modalName) {
|
toggleModal(modalName) {
|
||||||
@@ -722,10 +800,10 @@ export default class App extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeMaboxGlDebug = (key, value) => {
|
onChangeMaplibreGlDebug = (key, value) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
mapboxGlDebugOptions: {
|
maplibreGlDebugOptions: {
|
||||||
...this.state.mapboxGlDebugOptions,
|
...this.state.maplibreGlDebugOptions,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -736,7 +814,7 @@ export default class App extends React.Component {
|
|||||||
const selectedLayer = layers.length > 0 ? layers[this.state.selectedLayerIndex] : null
|
const selectedLayer = layers.length > 0 ? layers[this.state.selectedLayerIndex] : null
|
||||||
const metadata = this.state.mapStyle.metadata || {}
|
const metadata = this.state.mapStyle.metadata || {}
|
||||||
|
|
||||||
const toolbar = <Toolbar
|
const toolbar = <AppToolbar
|
||||||
renderer={this._getRenderer()}
|
renderer={this._getRenderer()}
|
||||||
mapState={this.state.mapState}
|
mapState={this.state.mapState}
|
||||||
mapStyle={this.state.mapStyle}
|
mapStyle={this.state.mapStyle}
|
||||||
@@ -762,7 +840,7 @@ export default class App extends React.Component {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
const layerEditor = selectedLayer ? <LayerEditor
|
const layerEditor = selectedLayer ? <LayerEditor
|
||||||
key={selectedLayer.id}
|
key={this.state.selectedLayerOriginalId}
|
||||||
layer={selectedLayer}
|
layer={selectedLayer}
|
||||||
layerIndex={this.state.selectedLayerIndex}
|
layerIndex={this.state.selectedLayerIndex}
|
||||||
isFirstLayer={this.state.selectedLayerIndex < 1}
|
isFirstLayer={this.state.selectedLayerIndex < 1}
|
||||||
@@ -790,22 +868,22 @@ export default class App extends React.Component {
|
|||||||
|
|
||||||
|
|
||||||
const modals = <div>
|
const modals = <div>
|
||||||
<DebugModal
|
<ModalDebug
|
||||||
renderer={this._getRenderer()}
|
renderer={this._getRenderer()}
|
||||||
mapboxGlDebugOptions={this.state.mapboxGlDebugOptions}
|
maplibreGlDebugOptions={this.state.maplibreGlDebugOptions}
|
||||||
openlayersDebugOptions={this.state.openlayersDebugOptions}
|
openlayersDebugOptions={this.state.openlayersDebugOptions}
|
||||||
onChangeMaboxGlDebug={this.onChangeMaboxGlDebug}
|
onChangeMaplibreGlDebug={this.onChangeMaplibreGlDebug}
|
||||||
onChangeOpenlayersDebug={this.onChangeOpenlayersDebug}
|
onChangeOpenlayersDebug={this.onChangeOpenlayersDebug}
|
||||||
isOpen={this.state.isOpen.debug}
|
isOpen={this.state.isOpen.debug}
|
||||||
onOpenToggle={this.toggleModal.bind(this, 'debug')}
|
onOpenToggle={this.toggleModal.bind(this, 'debug')}
|
||||||
mapView={this.state.mapView}
|
mapView={this.state.mapView}
|
||||||
/>
|
/>
|
||||||
<ShortcutsModal
|
<ModalShortcuts
|
||||||
ref={(el) => this.shortcutEl = el}
|
ref={(el) => this.shortcutEl = el}
|
||||||
isOpen={this.state.isOpen.shortcuts}
|
isOpen={this.state.isOpen.shortcuts}
|
||||||
onOpenToggle={this.toggleModal.bind(this, 'shortcuts')}
|
onOpenToggle={this.toggleModal.bind(this, 'shortcuts')}
|
||||||
/>
|
/>
|
||||||
<SettingsModal
|
<ModalSettings
|
||||||
mapStyle={this.state.mapStyle}
|
mapStyle={this.state.mapStyle}
|
||||||
onStyleChanged={this.onStyleChanged}
|
onStyleChanged={this.onStyleChanged}
|
||||||
onChangeMetadataProperty={this.onChangeMetadataProperty}
|
onChangeMetadataProperty={this.onChangeMetadataProperty}
|
||||||
@@ -813,24 +891,24 @@ export default class App extends React.Component {
|
|||||||
onOpenToggle={this.toggleModal.bind(this, 'settings')}
|
onOpenToggle={this.toggleModal.bind(this, 'settings')}
|
||||||
openlayersDebugOptions={this.state.openlayersDebugOptions}
|
openlayersDebugOptions={this.state.openlayersDebugOptions}
|
||||||
/>
|
/>
|
||||||
<ExportModal
|
<ModalExport
|
||||||
mapStyle={this.state.mapStyle}
|
mapStyle={this.state.mapStyle}
|
||||||
onStyleChanged={this.onStyleChanged}
|
onStyleChanged={this.onStyleChanged}
|
||||||
isOpen={this.state.isOpen.export}
|
isOpen={this.state.isOpen.export}
|
||||||
onOpenToggle={this.toggleModal.bind(this, 'export')}
|
onOpenToggle={this.toggleModal.bind(this, 'export')}
|
||||||
/>
|
/>
|
||||||
<OpenModal
|
<ModalOpen
|
||||||
isOpen={this.state.isOpen.open}
|
isOpen={this.state.isOpen.open}
|
||||||
onStyleOpen={this.openStyle}
|
onStyleOpen={this.openStyle}
|
||||||
onOpenToggle={this.toggleModal.bind(this, 'open')}
|
onOpenToggle={this.toggleModal.bind(this, 'open')}
|
||||||
/>
|
/>
|
||||||
<SourcesModal
|
<ModalSources
|
||||||
mapStyle={this.state.mapStyle}
|
mapStyle={this.state.mapStyle}
|
||||||
onStyleChanged={this.onStyleChanged}
|
onStyleChanged={this.onStyleChanged}
|
||||||
isOpen={this.state.isOpen.sources}
|
isOpen={this.state.isOpen.sources}
|
||||||
onOpenToggle={this.toggleModal.bind(this, 'sources')}
|
onOpenToggle={this.toggleModal.bind(this, 'sources')}
|
||||||
/>
|
/>
|
||||||
<SurveyModal
|
<ModalSurvey
|
||||||
isOpen={this.state.isOpen.survey}
|
isOpen={this.state.isOpen.survey}
|
||||||
onOpenToggle={this.toggleModal.bind(this, 'survey')}
|
onOpenToggle={this.toggleModal.bind(this, 'survey')}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ import React from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import ScrollContainer from './ScrollContainer'
|
import ScrollContainer from './ScrollContainer'
|
||||||
|
|
||||||
class AppLayout extends React.Component {
|
type AppLayoutProps = {
|
||||||
static propTypes = {
|
toolbar: React.ReactElement
|
||||||
toolbar: PropTypes.element.isRequired,
|
layerList: React.ReactElement
|
||||||
layerList: PropTypes.element.isRequired,
|
layerEditor?: React.ReactElement
|
||||||
layerEditor: PropTypes.element,
|
map: React.ReactElement
|
||||||
map: PropTypes.element.isRequired,
|
bottom?: React.ReactElement
|
||||||
bottom: PropTypes.element,
|
modals?: React.ReactNode
|
||||||
modals: PropTypes.node,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
class AppLayout extends React.Component<AppLayoutProps> {
|
||||||
static childContextTypes = {
|
static childContextTypes = {
|
||||||
reactIconBase: PropTypes.object
|
reactIconBase: PropTypes.object
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,28 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import {formatLayerId} from '../util/format';
|
||||||
import {formatLayerId} from './util/format';
|
import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
|
||||||
|
|
||||||
class MessagePanel extends React.Component {
|
type AppMessagePanelProps = {
|
||||||
static propTypes = {
|
errors?: unknown[]
|
||||||
errors: PropTypes.array,
|
infos?: unknown[]
|
||||||
infos: PropTypes.array,
|
mapStyle?: StyleSpecification
|
||||||
mapStyle: PropTypes.object,
|
onLayerSelect?(...args: unknown[]): unknown
|
||||||
onLayerSelect: PropTypes.func,
|
currentLayer?: object
|
||||||
currentLayer: PropTypes.object,
|
selectedLayerIndex?: number
|
||||||
selectedLayerIndex: PropTypes.number,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
export default class AppMessagePanel extends React.Component<AppMessagePanelProps> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
onLayerSelect: () => {},
|
onLayerSelect: () => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {selectedLayerIndex} = this.props;
|
const {selectedLayerIndex} = this.props;
|
||||||
const errors = this.props.errors.map((error, idx) => {
|
const errors = this.props.errors?.map((error: any, idx) => {
|
||||||
let content;
|
let content;
|
||||||
if (error.parsed && error.parsed.type === "layer") {
|
if (error.parsed && error.parsed.type === "layer") {
|
||||||
const {parsed} = error;
|
const {parsed} = error;
|
||||||
const {mapStyle, currentLayer} = this.props;
|
const layerId = this.props.mapStyle?.layers[parsed.data.index].id;
|
||||||
const layerId = mapStyle.layers[parsed.data.index].id;
|
|
||||||
content = (
|
content = (
|
||||||
<>
|
<>
|
||||||
Layer <span>{formatLayerId(layerId)}</span>: {parsed.data.message}
|
Layer <span>{formatLayerId(layerId)}</span>: {parsed.data.message}
|
||||||
@@ -32,7 +31,7 @@ class MessagePanel extends React.Component {
|
|||||||
—
|
—
|
||||||
<button
|
<button
|
||||||
className="maputnik-message-panel__switch-button"
|
className="maputnik-message-panel__switch-button"
|
||||||
onClick={() => this.props.onLayerSelect(parsed.data.index)}
|
onClick={() => this.props.onLayerSelect!(parsed.data.index)}
|
||||||
>
|
>
|
||||||
switch to layer
|
switch to layer
|
||||||
</button>
|
</button>
|
||||||
@@ -49,7 +48,7 @@ class MessagePanel extends React.Component {
|
|||||||
</p>
|
</p>
|
||||||
})
|
})
|
||||||
|
|
||||||
const infos = this.props.infos.map((m, i) => {
|
const infos = this.props.infos?.map((m, i) => {
|
||||||
return <p key={"info-"+i}>{m}</p>
|
return <p key={"info-"+i}>{m}</p>
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -60,5 +59,3 @@ class MessagePanel extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default MessagePanel
|
|
||||||
@@ -1,38 +1,35 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import {detect} from 'detect-browser';
|
import {detect} from 'detect-browser';
|
||||||
|
|
||||||
import {MdFileDownload, MdOpenInBrowser, MdSettings, MdLayers, MdHelpOutline, MdFindInPage, MdAssignmentTurnedIn} from 'react-icons/md'
|
import {MdFileDownload, MdOpenInBrowser, MdSettings, MdLayers, MdHelpOutline, MdFindInPage, MdAssignmentTurnedIn} from 'react-icons/md'
|
||||||
|
|
||||||
|
|
||||||
import logoImage from 'maputnik-design/logos/logo-color.svg'
|
|
||||||
import pkgJson from '../../package.json'
|
import pkgJson from '../../package.json'
|
||||||
|
|
||||||
|
|
||||||
// This is required because of <https://stackoverflow.com/a/49846426>, there isn't another way to detect support that I'm aware of.
|
// This is required because of <https://stackoverflow.com/a/49846426>, there isn't another way to detect support that I'm aware of.
|
||||||
const browser = detect();
|
const browser = detect();
|
||||||
const colorAccessibilityFiltersEnabled = ['chrome', 'firefox'].indexOf(browser.name) > -1;
|
const colorAccessibilityFiltersEnabled = ['chrome', 'firefox'].indexOf(browser!.name) > -1;
|
||||||
|
|
||||||
|
|
||||||
class IconText extends React.Component {
|
type IconTextProps = {
|
||||||
static propTypes = {
|
children?: React.ReactNode
|
||||||
children: PropTypes.node,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
class IconText extends React.Component<IconTextProps> {
|
||||||
render() {
|
render() {
|
||||||
return <span className="maputnik-icon-text">{this.props.children}</span>
|
return <span className="maputnik-icon-text">{this.props.children}</span>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ToolbarLink extends React.Component {
|
type ToolbarLinkProps = {
|
||||||
static propTypes = {
|
className?: string
|
||||||
className: PropTypes.string,
|
children?: React.ReactNode
|
||||||
children: PropTypes.node,
|
href?: string
|
||||||
href: PropTypes.string,
|
onToggleModal?(...args: unknown[]): unknown
|
||||||
onToggleModal: PropTypes.func,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
class ToolbarLink extends React.Component<ToolbarLinkProps> {
|
||||||
render() {
|
render() {
|
||||||
return <a
|
return <a
|
||||||
className={classnames('maputnik-toolbar-link', this.props.className)}
|
className={classnames('maputnik-toolbar-link', this.props.className)}
|
||||||
@@ -45,14 +42,14 @@ class ToolbarLink extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ToolbarLinkHighlighted extends React.Component {
|
type ToolbarLinkHighlightedProps = {
|
||||||
static propTypes = {
|
className?: string
|
||||||
className: PropTypes.string,
|
children?: React.ReactNode
|
||||||
children: PropTypes.node,
|
href?: string
|
||||||
href: PropTypes.string,
|
onToggleModal?(...args: unknown[]): unknown
|
||||||
onToggleModal: PropTypes.func
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
class ToolbarLinkHighlighted extends React.Component<ToolbarLinkHighlightedProps> {
|
||||||
render() {
|
render() {
|
||||||
return <a
|
return <a
|
||||||
className={classnames('maputnik-toolbar-link', "maputnik-toolbar-link--highlighted", this.props.className)}
|
className={classnames('maputnik-toolbar-link', "maputnik-toolbar-link--highlighted", this.props.className)}
|
||||||
@@ -67,12 +64,12 @@ class ToolbarLinkHighlighted extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ToolbarSelect extends React.Component {
|
type ToolbarSelectProps = {
|
||||||
static propTypes = {
|
children?: React.ReactNode
|
||||||
children: PropTypes.node,
|
wdKey?: string
|
||||||
wdKey: PropTypes.string
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
class ToolbarSelect extends React.Component<ToolbarSelectProps> {
|
||||||
render() {
|
render() {
|
||||||
return <div
|
return <div
|
||||||
className='maputnik-toolbar-select'
|
className='maputnik-toolbar-select'
|
||||||
@@ -83,13 +80,13 @@ class ToolbarSelect extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ToolbarAction extends React.Component {
|
type ToolbarActionProps = {
|
||||||
static propTypes = {
|
children?: React.ReactNode
|
||||||
children: PropTypes.node,
|
onClick?(...args: unknown[]): unknown
|
||||||
onClick: PropTypes.func,
|
wdKey?: string
|
||||||
wdKey: PropTypes.string
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
class ToolbarAction extends React.Component<ToolbarActionProps> {
|
||||||
render() {
|
render() {
|
||||||
return <button
|
return <button
|
||||||
className='maputnik-toolbar-action'
|
className='maputnik-toolbar-action'
|
||||||
@@ -101,22 +98,22 @@ class ToolbarAction extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Toolbar extends React.Component {
|
type AppToolbarProps = {
|
||||||
static propTypes = {
|
mapStyle: object
|
||||||
mapStyle: PropTypes.object.isRequired,
|
inspectModeEnabled: boolean
|
||||||
inspectModeEnabled: PropTypes.bool.isRequired,
|
onStyleChanged(...args: unknown[]): unknown
|
||||||
onStyleChanged: PropTypes.func.isRequired,
|
// A new style has been uploaded
|
||||||
// A new style has been uploaded
|
onStyleOpen(...args: unknown[]): unknown
|
||||||
onStyleOpen: PropTypes.func.isRequired,
|
// A dict of source id's and the available source layers
|
||||||
// A dict of source id's and the available source layers
|
sources: object
|
||||||
sources: PropTypes.object.isRequired,
|
children?: React.ReactNode
|
||||||
children: PropTypes.node,
|
onToggleModal(...args: unknown[]): unknown
|
||||||
onToggleModal: PropTypes.func,
|
onSetMapState(...args: unknown[]): unknown
|
||||||
onSetMapState: PropTypes.func,
|
mapState?: string
|
||||||
mapState: PropTypes.string,
|
renderer?: string
|
||||||
renderer: PropTypes.string,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
export default class AppToolbar extends React.Component<AppToolbarProps> {
|
||||||
state = {
|
state = {
|
||||||
isOpen: {
|
isOpen: {
|
||||||
settings: false,
|
settings: false,
|
||||||
@@ -127,39 +124,55 @@ export default class Toolbar extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSelection(val) {
|
handleSelection(val: string | undefined) {
|
||||||
this.props.onSetMapState(val);
|
this.props.onSetMapState(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSkip = (target: string) => {
|
||||||
|
if (target === "map") {
|
||||||
|
(document.querySelector(".maplibregl-canvas") as HTMLCanvasElement).focus();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const el = document.querySelector("#skip-target-"+target) as HTMLButtonElement;
|
||||||
|
el.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const views = [
|
const views = [
|
||||||
{
|
{
|
||||||
id: "map",
|
id: "map",
|
||||||
|
group: "general",
|
||||||
title: "Map",
|
title: "Map",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "inspect",
|
id: "inspect",
|
||||||
|
group: "general",
|
||||||
title: "Inspect",
|
title: "Inspect",
|
||||||
disabled: this.props.renderer !== 'mbgljs',
|
disabled: this.props.renderer === 'ol',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "filter-deuteranopia",
|
id: "filter-deuteranopia",
|
||||||
title: "Map (deuteranopia)",
|
group: "color-accessibility",
|
||||||
|
title: "Deuteranopia filter",
|
||||||
disabled: !colorAccessibilityFiltersEnabled,
|
disabled: !colorAccessibilityFiltersEnabled,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "filter-protanopia",
|
id: "filter-protanopia",
|
||||||
title: "Map (protanopia)",
|
group: "color-accessibility",
|
||||||
|
title: "Protanopia filter",
|
||||||
disabled: !colorAccessibilityFiltersEnabled,
|
disabled: !colorAccessibilityFiltersEnabled,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "filter-tritanopia",
|
id: "filter-tritanopia",
|
||||||
title: "Map (tritanopia)",
|
group: "color-accessibility",
|
||||||
|
title: "Tritanopia filter",
|
||||||
disabled: !colorAccessibilityFiltersEnabled,
|
disabled: !colorAccessibilityFiltersEnabled,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "filter-achromatopsia",
|
id: "filter-achromatopsia",
|
||||||
title: "Map (achromatopsia)",
|
group: "color-accessibility",
|
||||||
|
title: "Achromatopsia filter",
|
||||||
disabled: !colorAccessibilityFiltersEnabled,
|
disabled: !colorAccessibilityFiltersEnabled,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -168,28 +181,47 @@ export default class Toolbar extends React.Component {
|
|||||||
return view.id === this.props.mapState;
|
return view.id === this.props.mapState;
|
||||||
});
|
});
|
||||||
|
|
||||||
return <div className='maputnik-toolbar'>
|
return <nav className='maputnik-toolbar'>
|
||||||
<div className="maputnik-toolbar__inner">
|
<div className="maputnik-toolbar__inner">
|
||||||
<div
|
<div
|
||||||
className="maputnik-toolbar-logo-container"
|
className="maputnik-toolbar-logo-container"
|
||||||
>
|
>
|
||||||
<a className="maputnik-toolbar-skip" href="#skip-menu">
|
{/* Keyboard accessible quick links */}
|
||||||
Skip navigation
|
<button
|
||||||
</a>
|
data-wd-key="root:skip:layer-list"
|
||||||
<a
|
className="maputnik-toolbar-skip"
|
||||||
href="https://github.com/maputnik/editor"
|
onClick={_e => this.onSkip("layer-list")}
|
||||||
rel="noopener noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
className="maputnik-toolbar-logo"
|
|
||||||
>
|
>
|
||||||
<span dangerouslySetInnerHTML={{__html: logoImage}} />
|
Layers list
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
data-wd-key="root:skip:layer-editor"
|
||||||
|
className="maputnik-toolbar-skip"
|
||||||
|
onClick={_e => this.onSkip("layer-editor")}
|
||||||
|
>
|
||||||
|
Layer editor
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
data-wd-key="root:skip:map-view"
|
||||||
|
className="maputnik-toolbar-skip"
|
||||||
|
onClick={_e => this.onSkip("map")}
|
||||||
|
>
|
||||||
|
Map view
|
||||||
|
</button>
|
||||||
|
<a
|
||||||
|
className="maputnik-toolbar-logo"
|
||||||
|
target="blank"
|
||||||
|
rel="noreferrer noopener"
|
||||||
|
href="https://github.com/maputnik/editor"
|
||||||
|
>
|
||||||
|
<img src="node_modules/maputnik-design/logos/logo-color.svg" />
|
||||||
<h1>
|
<h1>
|
||||||
<span className="maputnik-toolbar-name">{pkgJson.name}</span>
|
<span className="maputnik-toolbar-name">{pkgJson.name}</span>
|
||||||
<span className="maputnik-toolbar-version">v{pkgJson.version}</span>
|
<span className="maputnik-toolbar-version">v{pkgJson.version}</span>
|
||||||
</h1>
|
</h1>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div className="maputnik-toolbar__actions">
|
<div className="maputnik-toolbar__actions" role="navigation" aria-label="Toolbar">
|
||||||
<ToolbarAction wdKey="nav:open" onClick={this.props.onToggleModal.bind(this, 'open')}>
|
<ToolbarAction wdKey="nav:open" onClick={this.props.onToggleModal.bind(this, 'open')}>
|
||||||
<MdOpenInBrowser />
|
<MdOpenInBrowser />
|
||||||
<IconText>Open</IconText>
|
<IconText>Open</IconText>
|
||||||
@@ -209,16 +241,31 @@ export default class Toolbar extends React.Component {
|
|||||||
|
|
||||||
<ToolbarSelect wdKey="nav:inspect">
|
<ToolbarSelect wdKey="nav:inspect">
|
||||||
<MdFindInPage />
|
<MdFindInPage />
|
||||||
<IconText>View </IconText>
|
<label>View
|
||||||
<select onChange={(e) => this.handleSelection(e.target.value)} value={currentView.id}>
|
<select
|
||||||
{views.map((item) => {
|
className="maputnik-select"
|
||||||
return (
|
data-wd-key="maputnik-select"
|
||||||
<option key={item.id} value={item.id} disabled={item.disabled}>
|
onChange={(e) => this.handleSelection(e.target.value)}
|
||||||
{item.title}
|
value={currentView?.id}
|
||||||
</option>
|
>
|
||||||
);
|
{views.filter(v => v.group === "general").map((item) => {
|
||||||
})}
|
return (
|
||||||
</select>
|
<option key={item.id} value={item.id} disabled={item.disabled} data-wd-key={item.id}>
|
||||||
|
{item.title}
|
||||||
|
</option>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
<optgroup label="Color accessibility">
|
||||||
|
{views.filter(v => v.group === "color-accessibility").map((item) => {
|
||||||
|
return (
|
||||||
|
<option key={item.id} value={item.id} disabled={item.disabled}>
|
||||||
|
{item.title}
|
||||||
|
</option>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</optgroup>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
</ToolbarSelect>
|
</ToolbarSelect>
|
||||||
|
|
||||||
<ToolbarLink href={"https://github.com/maputnik/editor/wiki"}>
|
<ToolbarLink href={"https://github.com/maputnik/editor/wiki"}>
|
||||||
@@ -231,6 +278,6 @@ export default class Toolbar extends React.Component {
|
|||||||
</ToolbarLinkHighlighted>
|
</ToolbarLinkHighlighted>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</nav>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import React, {SyntheticEvent} from 'react'
|
||||||
|
import classnames from 'classnames'
|
||||||
|
import FieldDocLabel from './FieldDocLabel'
|
||||||
|
import Doc from './Doc'
|
||||||
|
|
||||||
|
|
||||||
|
type BlockProps = {
|
||||||
|
"data-wd-key"?: string
|
||||||
|
label?: string
|
||||||
|
action?: React.ReactElement
|
||||||
|
style?: object
|
||||||
|
onChange?(...args: unknown[]): unknown
|
||||||
|
fieldSpec?: object
|
||||||
|
wideMode?: boolean
|
||||||
|
error?: unknown[]
|
||||||
|
};
|
||||||
|
|
||||||
|
type BlockState = {
|
||||||
|
showDoc: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Wrap a component with a label */
|
||||||
|
export default class Block extends React.Component<BlockProps, BlockState> {
|
||||||
|
_blockEl: HTMLDivElement | null = null;
|
||||||
|
|
||||||
|
constructor (props: BlockProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
showDoc: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange(e: React.BaseSyntheticEvent<Event, HTMLInputElement, HTMLInputElement>) {
|
||||||
|
const value = e.target.value
|
||||||
|
if (this.props.onChange) {
|
||||||
|
return this.props.onChange(value === "" ? undefined : value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onToggleDoc = (val: boolean) => {
|
||||||
|
this.setState({
|
||||||
|
showDoc: val
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some fields for example <InputColor/> bind click events inside the element
|
||||||
|
* to close the picker. This in turn propagates to the <label/> element
|
||||||
|
* causing the picker to reopen. This causes a scenario where the picker can
|
||||||
|
* never be closed once open.
|
||||||
|
*/
|
||||||
|
onLabelClick = (event: SyntheticEvent<any, any>) => {
|
||||||
|
const el = event.nativeEvent.target;
|
||||||
|
const contains = this._blockEl?.contains(el);
|
||||||
|
|
||||||
|
if (event.nativeEvent.target.nodeName !== "INPUT" && !contains) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <label style={this.props.style}
|
||||||
|
data-wd-key={this.props["data-wd-key"]}
|
||||||
|
className={classnames({
|
||||||
|
"maputnik-input-block": true,
|
||||||
|
"maputnik-input-block--wide": this.props.wideMode,
|
||||||
|
"maputnik-action-block": this.props.action
|
||||||
|
})}
|
||||||
|
onClick={this.onLabelClick}
|
||||||
|
>
|
||||||
|
{this.props.fieldSpec &&
|
||||||
|
<div className="maputnik-input-block-label">
|
||||||
|
<FieldDocLabel
|
||||||
|
label={this.props.label}
|
||||||
|
onToggleDoc={this.onToggleDoc}
|
||||||
|
fieldSpec={this.props.fieldSpec}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{!this.props.fieldSpec &&
|
||||||
|
<div className="maputnik-input-block-label">
|
||||||
|
{this.props.label}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div className="maputnik-input-block-action">
|
||||||
|
{this.props.action}
|
||||||
|
</div>
|
||||||
|
<div className="maputnik-input-block-content" ref={el => this._blockEl = el}>
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
|
{this.props.fieldSpec &&
|
||||||
|
<div
|
||||||
|
className="maputnik-doc-inline"
|
||||||
|
style={{display: this.state.showDoc ? '' : 'none'}}
|
||||||
|
>
|
||||||
|
<Doc fieldSpec={this.props.fieldSpec} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</label>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import classnames from 'classnames'
|
|
||||||
|
|
||||||
class Button extends React.Component {
|
|
||||||
static propTypes = {
|
|
||||||
"data-wd-key": PropTypes.string,
|
|
||||||
"aria-label": PropTypes.string,
|
|
||||||
onClick: PropTypes.func,
|
|
||||||
style: PropTypes.object,
|
|
||||||
className: PropTypes.string,
|
|
||||||
children: PropTypes.node,
|
|
||||||
disabled: PropTypes.bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return <button
|
|
||||||
onClick={this.props.onClick}
|
|
||||||
disabled={this.props.disabled}
|
|
||||||
aria-label={this.props["aria-label"]}
|
|
||||||
className={classnames("maputnik-button", this.props.className)}
|
|
||||||
data-wd-key={this.props["data-wd-key"]}
|
|
||||||
style={this.props.style}
|
|
||||||
>
|
|
||||||
{this.props.children}
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Button
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { Collapse as ReactCollapse } from 'react-collapse'
|
||||||
|
import {reducedMotionEnabled} from '../libs/accessibility'
|
||||||
|
|
||||||
|
|
||||||
|
type CollapseProps = {
|
||||||
|
isActive: boolean
|
||||||
|
children: React.ReactElement
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class Collapse extends React.Component<CollapseProps> {
|
||||||
|
static defaultProps = {
|
||||||
|
isActive: true
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (reducedMotionEnabled()) {
|
||||||
|
return (
|
||||||
|
<div style={{display: this.props.isActive ? "block" : "none"}}>
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return (
|
||||||
|
<ReactCollapse isOpened={this.props.isActive}>
|
||||||
|
{this.props.children}
|
||||||
|
</ReactCollapse>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import {MdArrowDropDown, MdArrowDropUp} from 'react-icons/md'
|
import {MdArrowDropDown, MdArrowDropUp} from 'react-icons/md'
|
||||||
|
|
||||||
export default class Collapser extends React.Component {
|
type CollapserProps = {
|
||||||
static propTypes = {
|
isCollapsed: boolean
|
||||||
isCollapsed: PropTypes.bool.isRequired,
|
style?: object
|
||||||
style: PropTypes.object,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
export default class Collapser extends React.Component<CollapserProps> {
|
||||||
render() {
|
render() {
|
||||||
const iconStyle = {
|
const iconStyle = {
|
||||||
width: 20,
|
width: 20,
|
||||||
@@ -1,28 +1,37 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
export default class SpecDoc extends React.Component {
|
const headers = {
|
||||||
static propTypes = {
|
js: "JS",
|
||||||
fieldSpec: PropTypes.object.isRequired,
|
android: "Android",
|
||||||
|
ios: "iOS",
|
||||||
|
macos: "macOS",
|
||||||
|
};
|
||||||
|
|
||||||
|
type DocProps = {
|
||||||
|
fieldSpec: {
|
||||||
|
doc?: string
|
||||||
|
values?: {
|
||||||
|
[key: string]: {
|
||||||
|
doc?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'sdk-support'?: {
|
||||||
|
[key: string]: typeof headers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class Doc extends React.Component<DocProps> {
|
||||||
render () {
|
render () {
|
||||||
const {fieldSpec} = this.props;
|
const {fieldSpec} = this.props;
|
||||||
|
|
||||||
const {doc, values} = fieldSpec;
|
const {doc, values} = fieldSpec;
|
||||||
const sdkSupport = fieldSpec['sdk-support'];
|
const sdkSupport = fieldSpec['sdk-support'];
|
||||||
|
|
||||||
const headers = {
|
|
||||||
js: "JS",
|
|
||||||
android: "Android",
|
|
||||||
ios: "iOS",
|
|
||||||
macos: "macOS",
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderValues = (
|
const renderValues = (
|
||||||
!!values &&
|
!!values &&
|
||||||
// HACK: Currently we merge additional values into the stylespec, so this is required
|
// HACK: Currently we merge additional values into the style spec, so this is required
|
||||||
// See <https://github.com/maputnik/editor/blob/master/src/components/fields/PropertyGroup.jsx#L16>
|
// See <https://github.com/maputnik/editor/blob/main/src/components/PropertyGroup.jsx#L16>
|
||||||
!Array.isArray(values)
|
!Array.isArray(values)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -30,7 +39,7 @@ export default class SpecDoc extends React.Component {
|
|||||||
<>
|
<>
|
||||||
{doc &&
|
{doc &&
|
||||||
<div className="SpecDoc">
|
<div className="SpecDoc">
|
||||||
<div className="SpecDoc__doc">{doc}</div>
|
<div className="SpecDoc__doc" data-wd-key='spec-field-doc'>{doc}</div>
|
||||||
{renderValues &&
|
{renderValues &&
|
||||||
<ul className="SpecDoc__values">
|
<ul className="SpecDoc__values">
|
||||||
{Object.entries(values).map(([key, value]) => {
|
{Object.entries(values).map(([key, value]) => {
|
||||||
@@ -61,10 +70,9 @@ export default class SpecDoc extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<tr key={key}>
|
<tr key={key}>
|
||||||
<td>{key}</td>
|
<td>{key}</td>
|
||||||
{Object.keys(headers).map(k => {
|
{Object.keys(headers).map((k) => {
|
||||||
const value = supportObj[k];
|
|
||||||
if (supportObj.hasOwnProperty(k)) {
|
if (supportObj.hasOwnProperty(k)) {
|
||||||
return <td key={k}>{supportObj[k]}</td>;
|
return <td key={k}>{supportObj[k as keyof typeof headers]}</td>;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return <td key={k}>no</td>;
|
return <td key={k}>no</td>;
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputArray, { FieldArrayProps as InputArrayProps } from './InputArray'
|
||||||
|
import Fieldset from './Fieldset'
|
||||||
|
|
||||||
|
type FieldArrayProps = InputArrayProps & {
|
||||||
|
name?: string
|
||||||
|
fieldSpec?: {
|
||||||
|
doc: string
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldArray extends React.Component<FieldArrayProps> {
|
||||||
|
render() {
|
||||||
|
return <Fieldset label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
||||||
|
<InputArray {...this.props} />
|
||||||
|
</Fieldset>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputAutocomplete, { InputAutocompleteProps } from './InputAutocomplete'
|
||||||
|
|
||||||
|
|
||||||
|
type FieldAutocompleteProps = InputAutocompleteProps & {
|
||||||
|
label?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldAutocomplete extends React.Component<FieldAutocompleteProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={this.props.label}>
|
||||||
|
<InputAutocomplete {...this.props} />
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputCheckbox, {InputCheckboxProps} from './InputCheckbox'
|
||||||
|
|
||||||
|
|
||||||
|
type FieldCheckboxProps = InputCheckboxProps & {
|
||||||
|
label?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldCheckbox extends React.Component<FieldCheckboxProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={this.props.label}>
|
||||||
|
<InputCheckbox {...this.props} />
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputColor, {InputColorProps} from './InputColor'
|
||||||
|
|
||||||
|
|
||||||
|
type FieldColorProps = InputColorProps & {
|
||||||
|
label?: string
|
||||||
|
fieldSpec?: {
|
||||||
|
doc: string
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldColor extends React.Component<FieldColorProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
||||||
|
<InputColor {...this.props} />
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import Block from './Block'
|
||||||
|
import InputString from './InputString'
|
||||||
|
|
||||||
|
type FieldCommentProps = {
|
||||||
|
value?: string
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldComment extends React.Component<FieldCommentProps> {
|
||||||
|
render() {
|
||||||
|
const fieldSpec = {
|
||||||
|
doc: "Comments for the current layer. This is non-standard and not in the spec."
|
||||||
|
};
|
||||||
|
|
||||||
|
return <Block
|
||||||
|
label={"Comments"}
|
||||||
|
fieldSpec={fieldSpec}
|
||||||
|
data-wd-key="layer-comment"
|
||||||
|
>
|
||||||
|
<InputString
|
||||||
|
multi={true}
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={this.props.onChange}
|
||||||
|
default="Comment..."
|
||||||
|
/>
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,27 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
import {MdInfoOutline, MdHighlightOff} from 'react-icons/md'
|
import {MdInfoOutline, MdHighlightOff} from 'react-icons/md'
|
||||||
|
|
||||||
export default class DocLabel extends React.Component {
|
type FieldDocLabelProps = {
|
||||||
static propTypes = {
|
label: object | string | undefined
|
||||||
label: PropTypes.oneOfType([
|
fieldSpec?: {
|
||||||
PropTypes.object,
|
doc?: string
|
||||||
PropTypes.string
|
|
||||||
]).isRequired,
|
|
||||||
fieldSpec: PropTypes.object,
|
|
||||||
onToggleDoc: PropTypes.func,
|
|
||||||
}
|
}
|
||||||
|
onToggleDoc?(...args: unknown[]): unknown
|
||||||
|
};
|
||||||
|
|
||||||
constructor (props) {
|
type FieldDocLabelState = {
|
||||||
|
open: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldDocLabel extends React.Component<FieldDocLabelProps, FieldDocLabelState> {
|
||||||
|
constructor (props: FieldDocLabelProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
open: false,
|
open: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onToggleDoc = (open) => {
|
onToggleDoc = (open: boolean) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
open,
|
open,
|
||||||
}, () => {
|
}, () => {
|
||||||
@@ -43,6 +44,7 @@ export default class DocLabel extends React.Component {
|
|||||||
aria-label={this.state.open ? "close property documentation" : "open property documentation"}
|
aria-label={this.state.open ? "close property documentation" : "open property documentation"}
|
||||||
className={`maputnik-doc-button maputnik-doc-button--${this.state.open ? 'open' : 'closed'}`}
|
className={`maputnik-doc-button maputnik-doc-button--${this.state.open ? 'open' : 'closed'}`}
|
||||||
onClick={() => this.onToggleDoc(!this.state.open)}
|
onClick={() => this.onToggleDoc(!this.state.open)}
|
||||||
|
data-wd-key={'field-doc-button-'+label}
|
||||||
>
|
>
|
||||||
{this.state.open ? <MdHighlightOff /> : <MdInfoOutline />}
|
{this.state.open ? <MdHighlightOff /> : <MdInfoOutline />}
|
||||||
</button>
|
</button>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputDynamicArray, {FieldDynamicArrayProps as InputDynamicArrayProps} from './InputDynamicArray'
|
||||||
|
import Fieldset from './Fieldset'
|
||||||
|
|
||||||
|
type FieldDynamicArrayProps = InputDynamicArrayProps & {
|
||||||
|
name?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldDynamicArray extends React.Component<FieldDynamicArrayProps> {
|
||||||
|
render() {
|
||||||
|
return <Fieldset label={this.props.label}>
|
||||||
|
<InputDynamicArray {...this.props} />
|
||||||
|
</Fieldset>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputEnum, {InputEnumProps} from './InputEnum'
|
||||||
|
import Fieldset from './Fieldset';
|
||||||
|
|
||||||
|
|
||||||
|
type FieldEnumProps = InputEnumProps & {
|
||||||
|
label?: string;
|
||||||
|
fieldSpec?: {
|
||||||
|
doc: string
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldEnum extends React.Component<FieldEnumProps> {
|
||||||
|
render() {
|
||||||
|
return <Fieldset label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
||||||
|
<InputEnum {...this.props} />
|
||||||
|
</Fieldset>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,18 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
import SpecProperty from './_SpecProperty'
|
import SpecProperty from './_SpecProperty'
|
||||||
import DataProperty from './_DataProperty'
|
import DataProperty, { Stop } from './_DataProperty'
|
||||||
import ZoomProperty from './_ZoomProperty'
|
import ZoomProperty from './_ZoomProperty'
|
||||||
import ExpressionProperty from './_ExpressionProperty'
|
import ExpressionProperty from './_ExpressionProperty'
|
||||||
import {function as styleFunction} from '@mapbox/mapbox-gl-style-spec';
|
import {function as styleFunction} from '@maplibre/maplibre-gl-style-spec';
|
||||||
import {findDefaultFromSpec} from '../util/spec-helper';
|
import {findDefaultFromSpec} from '../util/spec-helper';
|
||||||
|
|
||||||
|
|
||||||
function isLiteralExpression (value) {
|
function isLiteralExpression(value: any) {
|
||||||
return (Array.isArray(value) && value.length === 2 && value[0] === "literal");
|
return (Array.isArray(value) && value.length === 2 && value[0] === "literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isGetExpression (value) {
|
function isGetExpression(value: any) {
|
||||||
return (
|
return (
|
||||||
Array.isArray(value) &&
|
Array.isArray(value) &&
|
||||||
value.length === 2 &&
|
value.length === 2 &&
|
||||||
@@ -21,14 +20,14 @@ function isGetExpression (value) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isZoomField(value) {
|
function isZoomField(value: any) {
|
||||||
return (
|
return (
|
||||||
typeof(value) === 'object' &&
|
typeof(value) === 'object' &&
|
||||||
value.stops &&
|
value.stops &&
|
||||||
typeof(value.property) === 'undefined' &&
|
typeof(value.property) === 'undefined' &&
|
||||||
Array.isArray(value.stops) &&
|
Array.isArray(value.stops) &&
|
||||||
value.stops.length > 1 &&
|
value.stops.length > 1 &&
|
||||||
value.stops.every(stop => {
|
value.stops.every((stop: Stop) => {
|
||||||
return (
|
return (
|
||||||
Array.isArray(stop) &&
|
Array.isArray(stop) &&
|
||||||
stop.length === 2
|
stop.length === 2
|
||||||
@@ -37,7 +36,7 @@ function isZoomField(value) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isIdentityProperty (value) {
|
function isIdentityProperty(value: any) {
|
||||||
return (
|
return (
|
||||||
typeof(value) === 'object' &&
|
typeof(value) === 'object' &&
|
||||||
value.type === "identity" &&
|
value.type === "identity" &&
|
||||||
@@ -45,14 +44,14 @@ function isIdentityProperty (value) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDataStopProperty (value) {
|
function isDataStopProperty(value: any) {
|
||||||
return (
|
return (
|
||||||
typeof(value) === 'object' &&
|
typeof(value) === 'object' &&
|
||||||
value.stops &&
|
value.stops &&
|
||||||
typeof(value.property) !== 'undefined' &&
|
typeof(value.property) !== 'undefined' &&
|
||||||
value.stops.length > 1 &&
|
value.stops.length > 1 &&
|
||||||
Array.isArray(value.stops) &&
|
Array.isArray(value.stops) &&
|
||||||
value.stops.every(stop => {
|
value.stops.every((stop: Stop) => {
|
||||||
return (
|
return (
|
||||||
Array.isArray(stop) &&
|
Array.isArray(stop) &&
|
||||||
stop.length === 2 &&
|
stop.length === 2 &&
|
||||||
@@ -62,26 +61,26 @@ function isDataStopProperty (value) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDataField(value) {
|
function isDataField(value: any) {
|
||||||
return (
|
return (
|
||||||
isIdentityProperty(value) ||
|
isIdentityProperty(value) ||
|
||||||
isDataStopProperty(value)
|
isDataStopProperty(value)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPrimative (value) {
|
function isPrimative(value: any): value is string | boolean | number {
|
||||||
const valid = ["string", "boolean", "number"];
|
const valid = ["string", "boolean", "number"];
|
||||||
return valid.includes(typeof(value));
|
return valid.includes(typeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
function isArrayOfPrimatives (values) {
|
function isArrayOfPrimatives(values: any): values is Array<string | boolean | number> {
|
||||||
if (Array.isArray(values)) {
|
if (Array.isArray(values)) {
|
||||||
return values.every(isPrimative);
|
return values.every(isPrimative);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDataType (value, fieldSpec={}) {
|
function getDataType(value: any, fieldSpec={} as any) {
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
return "value";
|
return "value";
|
||||||
}
|
}
|
||||||
@@ -103,35 +102,33 @@ function getDataType (value, fieldSpec={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type FieldFunctionProps = {
|
||||||
|
onChange(fieldName: string, value: any): unknown
|
||||||
|
fieldName: string
|
||||||
|
fieldType: string
|
||||||
|
fieldSpec: any
|
||||||
|
errors?: unknown[]
|
||||||
|
value?: any
|
||||||
|
};
|
||||||
|
|
||||||
|
type FieldFunctionState = {
|
||||||
|
dataType: string
|
||||||
|
isEditing: boolean
|
||||||
|
}
|
||||||
|
|
||||||
/** Supports displaying spec field for zoom function objects
|
/** Supports displaying spec field for zoom function objects
|
||||||
* https://www.mapbox.com/mapbox-gl-style-spec/#types-function-zoom-property
|
* https://www.mapbox.com/mapbox-gl-style-spec/#types-function-zoom-property
|
||||||
*/
|
*/
|
||||||
export default class FunctionSpecProperty extends React.Component {
|
export default class FieldFunction extends React.Component<FieldFunctionProps, FieldFunctionState> {
|
||||||
static propTypes = {
|
constructor (props: FieldFunctionProps) {
|
||||||
onChange: PropTypes.func.isRequired,
|
super(props);
|
||||||
fieldName: PropTypes.string.isRequired,
|
|
||||||
fieldType: PropTypes.string.isRequired,
|
|
||||||
fieldSpec: PropTypes.object.isRequired,
|
|
||||||
errors: PropTypes.object,
|
|
||||||
|
|
||||||
value: PropTypes.oneOfType([
|
|
||||||
PropTypes.object,
|
|
||||||
PropTypes.string,
|
|
||||||
PropTypes.number,
|
|
||||||
PropTypes.bool,
|
|
||||||
PropTypes.array
|
|
||||||
]),
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor (props) {
|
|
||||||
super();
|
|
||||||
this.state = {
|
this.state = {
|
||||||
dataType: getDataType(props.value, props.fieldSpec),
|
dataType: getDataType(props.value, props.fieldSpec),
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props, state) {
|
static getDerivedStateFromProps(props: FieldFunctionProps, state: FieldFunctionState) {
|
||||||
// Because otherwise when editing values we end up accidentally changing field type.
|
// Because otherwise when editing values we end up accidentally changing field type.
|
||||||
if (state.isEditing) {
|
if (state.isEditing) {
|
||||||
return {};
|
return {};
|
||||||
@@ -144,7 +141,7 @@ export default class FunctionSpecProperty extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getFieldFunctionType(fieldSpec) {
|
getFieldFunctionType(fieldSpec: any) {
|
||||||
if (fieldSpec.expression.interpolated) {
|
if (fieldSpec.expression.interpolated) {
|
||||||
return "exponential"
|
return "exponential"
|
||||||
}
|
}
|
||||||
@@ -183,7 +180,7 @@ export default class FunctionSpecProperty extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteStop = (stopIdx) => {
|
deleteStop = (stopIdx: number) => {
|
||||||
const stops = this.props.value.stops.slice(0)
|
const stops = this.props.value.stops.slice(0)
|
||||||
stops.splice(stopIdx, 1)
|
stops.splice(stopIdx, 1)
|
||||||
|
|
||||||
@@ -200,12 +197,37 @@ export default class FunctionSpecProperty extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
makeZoomFunction = () => {
|
makeZoomFunction = () => {
|
||||||
const zoomFunc = {
|
const {value} = this.props;
|
||||||
stops: [
|
|
||||||
[6, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
|
let zoomFunc;
|
||||||
[10, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]
|
if (typeof(value) === "object") {
|
||||||
]
|
if (value.stops) {
|
||||||
|
zoomFunc = {
|
||||||
|
base: value.base,
|
||||||
|
stops: value.stops.map((stop: Stop) => {
|
||||||
|
return [stop[0].zoom, stop[1] || findDefaultFromSpec(this.props.fieldSpec)];
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
zoomFunc = {
|
||||||
|
base: value.base,
|
||||||
|
stops: [
|
||||||
|
[6, findDefaultFromSpec(this.props.fieldSpec)],
|
||||||
|
[10, findDefaultFromSpec(this.props.fieldSpec)]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
zoomFunc = {
|
||||||
|
stops: [
|
||||||
|
[6, value || findDefaultFromSpec(this.props.fieldSpec)],
|
||||||
|
[10, value || findDefaultFromSpec(this.props.fieldSpec)]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.props.onChange(this.props.fieldName, zoomFunc)
|
this.props.onChange(this.props.fieldName, zoomFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,14 +280,44 @@ export default class FunctionSpecProperty extends React.Component {
|
|||||||
makeDataFunction = () => {
|
makeDataFunction = () => {
|
||||||
const functionType = this.getFieldFunctionType(this.props.fieldSpec);
|
const functionType = this.getFieldFunctionType(this.props.fieldSpec);
|
||||||
const stopValue = functionType === 'categorical' ? '' : 0;
|
const stopValue = functionType === 'categorical' ? '' : 0;
|
||||||
const dataFunc = {
|
const {value} = this.props;
|
||||||
property: "",
|
let dataFunc;
|
||||||
type: functionType,
|
|
||||||
stops: [
|
if (typeof(value) === "object") {
|
||||||
[{zoom: 6, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
|
if (value.stops) {
|
||||||
[{zoom: 10, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]
|
dataFunc = {
|
||||||
]
|
property: "",
|
||||||
|
type: functionType,
|
||||||
|
base: value.base,
|
||||||
|
stops: value.stops.map((stop: Stop) => {
|
||||||
|
return [{zoom: stop[0], value: stopValue}, stop[1] || findDefaultFromSpec(this.props.fieldSpec)];
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dataFunc = {
|
||||||
|
property: "",
|
||||||
|
type: functionType,
|
||||||
|
base: value.base,
|
||||||
|
stops: [
|
||||||
|
[{zoom: 6, value: stopValue}, findDefaultFromSpec(this.props.fieldSpec)],
|
||||||
|
[{zoom: 10, value: stopValue}, findDefaultFromSpec(this.props.fieldSpec)]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
dataFunc = {
|
||||||
|
property: "",
|
||||||
|
type: functionType,
|
||||||
|
base: value.base,
|
||||||
|
stops: [
|
||||||
|
[{zoom: 6, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
|
||||||
|
[{zoom: 10, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.props.onChange(this.props.fieldName, dataFunc)
|
this.props.onChange(this.props.fieldName, dataFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,11 +362,13 @@ export default class FunctionSpecProperty extends React.Component {
|
|||||||
value={this.props.value}
|
value={this.props.value}
|
||||||
onDeleteStop={this.deleteStop}
|
onDeleteStop={this.deleteStop}
|
||||||
onAddStop={this.addStop}
|
onAddStop={this.addStop}
|
||||||
|
onChangeToDataFunction={this.makeDataFunction}
|
||||||
onExpressionClick={this.makeExpression}
|
onExpressionClick={this.makeExpression}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else if (dataType === "data_function") {
|
else if (dataType === "data_function") {
|
||||||
|
// TODO: Rename to FieldFunction **this file** shouldn't be called that
|
||||||
specField = (
|
specField = (
|
||||||
<DataProperty
|
<DataProperty
|
||||||
errors={this.props.errors}
|
errors={this.props.errors}
|
||||||
@@ -325,6 +379,7 @@ export default class FunctionSpecProperty extends React.Component {
|
|||||||
value={this.props.value}
|
value={this.props.value}
|
||||||
onDeleteStop={this.deleteStop}
|
onDeleteStop={this.deleteStop}
|
||||||
onAddStop={this.addStop}
|
onAddStop={this.addStop}
|
||||||
|
onChangeToZoomFunction={this.makeZoomFunction}
|
||||||
onExpressionClick={this.makeExpression}
|
onExpressionClick={this.makeExpression}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import {latest} from '@maplibre/maplibre-gl-style-spec'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputString from './InputString'
|
||||||
|
|
||||||
|
type FieldIdProps = {
|
||||||
|
value: string
|
||||||
|
wdKey: string
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
error?: unknown[]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldId extends React.Component<FieldIdProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={"ID"} fieldSpec={latest.layer.id}
|
||||||
|
data-wd-key={this.props.wdKey}
|
||||||
|
error={this.props.error}
|
||||||
|
>
|
||||||
|
<InputString
|
||||||
|
value={this.props.value}
|
||||||
|
onInput={this.props.onChange}
|
||||||
|
/>
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputJson, {InputJsonProps} from './InputJson'
|
||||||
|
|
||||||
|
|
||||||
|
type FieldJsonProps = InputJsonProps & {};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldJson extends React.Component<FieldJsonProps> {
|
||||||
|
render() {
|
||||||
|
return <InputJson {...this.props} />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import {latest} from '@maplibre/maplibre-gl-style-spec'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputNumber from './InputNumber'
|
||||||
|
|
||||||
|
type FieldMaxZoomProps = {
|
||||||
|
value?: number
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
error?: unknown[]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldMaxZoom extends React.Component<FieldMaxZoomProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={"Max Zoom"} fieldSpec={latest.layer.maxzoom}
|
||||||
|
error={this.props.error}
|
||||||
|
data-wd-key="max-zoom"
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
allowRange={true}
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={this.props.onChange}
|
||||||
|
min={latest.layer.maxzoom.minimum}
|
||||||
|
max={latest.layer.maxzoom.maximum}
|
||||||
|
default={latest.layer.maxzoom.maximum}
|
||||||
|
/>
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import {latest} from '@maplibre/maplibre-gl-style-spec'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputNumber from './InputNumber'
|
||||||
|
|
||||||
|
type FieldMinZoomProps = {
|
||||||
|
value?: number
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
error?: unknown[]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldMinZoom extends React.Component<FieldMinZoomProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={"Min Zoom"} fieldSpec={latest.layer.minzoom}
|
||||||
|
error={this.props.error}
|
||||||
|
data-wd-key="min-zoom"
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
allowRange={true}
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={this.props.onChange}
|
||||||
|
min={latest.layer.minzoom.minimum}
|
||||||
|
max={latest.layer.minzoom.maximum}
|
||||||
|
default={latest.layer.minzoom.minimum}
|
||||||
|
/>
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputMultiInput, {InputMultiInputProps} from './InputMultiInput'
|
||||||
|
import Fieldset from './Fieldset'
|
||||||
|
|
||||||
|
|
||||||
|
type FieldMultiInputProps = InputMultiInputProps & {
|
||||||
|
label?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldMultiInput extends React.Component<FieldMultiInputProps> {
|
||||||
|
render() {
|
||||||
|
return <Fieldset label={this.props.label}>
|
||||||
|
<InputMultiInput {...this.props} />
|
||||||
|
</Fieldset>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputNumber, {InputNumberProps} from './InputNumber'
|
||||||
|
import Block from './Block'
|
||||||
|
|
||||||
|
|
||||||
|
type FieldNumberProps = InputNumberProps & {
|
||||||
|
label?: string
|
||||||
|
fieldSpec?: {
|
||||||
|
doc: string
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldNumber extends React.Component<FieldNumberProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
||||||
|
<InputNumber {...this.props} />
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputSelect, {InputSelectProps} from './InputSelect'
|
||||||
|
|
||||||
|
|
||||||
|
type FieldSelectProps = InputSelectProps & {
|
||||||
|
label?: string
|
||||||
|
fieldSpec?: {
|
||||||
|
doc: string
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldSelect extends React.Component<FieldSelectProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
||||||
|
<InputSelect {...this.props}/>
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import {latest} from '@maplibre/maplibre-gl-style-spec'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputAutocomplete from './InputAutocomplete'
|
||||||
|
|
||||||
|
type FieldSourceProps = {
|
||||||
|
value?: string
|
||||||
|
wdKey?: string
|
||||||
|
onChange?(...args: unknown[]): unknown
|
||||||
|
sourceIds?: unknown[]
|
||||||
|
error?: unknown[]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldSource extends React.Component<FieldSourceProps> {
|
||||||
|
static defaultProps = {
|
||||||
|
onChange: () => {},
|
||||||
|
sourceIds: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <Block
|
||||||
|
label={"Source"}
|
||||||
|
fieldSpec={latest.layer.source}
|
||||||
|
error={this.props.error}
|
||||||
|
data-wd-key={this.props.wdKey}
|
||||||
|
>
|
||||||
|
<InputAutocomplete
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={this.props.onChange}
|
||||||
|
options={this.props.sourceIds?.map(src => [src, src])}
|
||||||
|
/>
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import {latest} from '@maplibre/maplibre-gl-style-spec'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputAutocomplete from './InputAutocomplete'
|
||||||
|
|
||||||
|
type FieldSourceLayerProps = {
|
||||||
|
value?: string
|
||||||
|
onChange?(...args: unknown[]): unknown
|
||||||
|
sourceLayerIds?: unknown[]
|
||||||
|
isFixed?: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldSourceLayer extends React.Component<FieldSourceLayerProps> {
|
||||||
|
static defaultProps = {
|
||||||
|
onChange: () => {},
|
||||||
|
sourceLayerIds: [],
|
||||||
|
isFixed: false
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <Block label={"Source Layer"} fieldSpec={latest.layer['source-layer']}
|
||||||
|
data-wd-key="layer-source-layer"
|
||||||
|
>
|
||||||
|
<InputAutocomplete
|
||||||
|
keepMenuWithinWindowBounds={!!this.props.isFixed}
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={this.props.onChange}
|
||||||
|
options={this.props.sourceLayerIds?.map(l => [l, l])}
|
||||||
|
/>
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputString, {InputStringProps} from './InputString'
|
||||||
|
|
||||||
|
type FieldStringProps = InputStringProps & {
|
||||||
|
name?: string
|
||||||
|
label?: string
|
||||||
|
fieldSpec?: {
|
||||||
|
doc: string
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldString extends React.Component<FieldStringProps> {
|
||||||
|
render() {
|
||||||
|
return <Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
||||||
|
<InputString {...this.props} />
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import {latest} from '@maplibre/maplibre-gl-style-spec'
|
||||||
|
import Block from './Block'
|
||||||
|
import InputSelect from './InputSelect'
|
||||||
|
import InputString from './InputString'
|
||||||
|
|
||||||
|
type FieldTypeProps = {
|
||||||
|
value: string
|
||||||
|
wdKey?: string
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
error?: unknown[] | undefined
|
||||||
|
disabled?: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldType extends React.Component<FieldTypeProps> {
|
||||||
|
static defaultProps = {
|
||||||
|
disabled: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return <Block label={"Type"} fieldSpec={latest.layer.type}
|
||||||
|
data-wd-key={this.props.wdKey}
|
||||||
|
error={this.props.error}
|
||||||
|
>
|
||||||
|
{this.props.disabled &&
|
||||||
|
<InputString
|
||||||
|
value={this.props.value}
|
||||||
|
disabled={true}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
{!this.props.disabled &&
|
||||||
|
<InputSelect
|
||||||
|
options={[
|
||||||
|
['background', 'Background'],
|
||||||
|
['fill', 'Fill'],
|
||||||
|
['line', 'Line'],
|
||||||
|
['symbol', 'Symbol'],
|
||||||
|
['raster', 'Raster'],
|
||||||
|
['circle', 'Circle'],
|
||||||
|
['fill-extrusion', 'Fill Extrusion'],
|
||||||
|
['hillshade', 'Hillshade'],
|
||||||
|
['heatmap', 'Heatmap'],
|
||||||
|
]}
|
||||||
|
onChange={this.props.onChange}
|
||||||
|
value={this.props.value}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</Block>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputUrl, {FieldUrlProps as InputUrlProps} from './InputUrl'
|
||||||
|
import Block from './Block'
|
||||||
|
|
||||||
|
|
||||||
|
type FieldUrlProps = InputUrlProps & {
|
||||||
|
label: string;
|
||||||
|
fieldSpec?: {
|
||||||
|
doc: string
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldUrl extends React.Component<FieldUrlProps> {
|
||||||
|
render () {
|
||||||
|
return (
|
||||||
|
<Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
||||||
|
<InputUrl {...this.props} />
|
||||||
|
</Block>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import React, { ReactElement } from 'react'
|
||||||
|
import FieldDocLabel from './FieldDocLabel'
|
||||||
|
import Doc from './Doc'
|
||||||
|
|
||||||
|
type FieldsetProps = {
|
||||||
|
label?: string,
|
||||||
|
fieldSpec?: { doc?: string },
|
||||||
|
action?: ReactElement,
|
||||||
|
};
|
||||||
|
|
||||||
|
type FieldsetState = {
|
||||||
|
showDoc: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
let IDX = 0;
|
||||||
|
|
||||||
|
export default class Fieldset extends React.Component<FieldsetProps, FieldsetState> {
|
||||||
|
_labelId: string;
|
||||||
|
|
||||||
|
constructor (props: FieldsetProps) {
|
||||||
|
super(props);
|
||||||
|
this._labelId = `fieldset_label_${(IDX++)}`;
|
||||||
|
this.state = {
|
||||||
|
showDoc: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onToggleDoc = (val: boolean) => {
|
||||||
|
this.setState({
|
||||||
|
showDoc: val
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
return <div className="maputnik-input-block" role="group" aria-labelledby={this._labelId}>
|
||||||
|
{this.props.fieldSpec &&
|
||||||
|
<div className="maputnik-input-block-label">
|
||||||
|
<FieldDocLabel
|
||||||
|
label={this.props.label}
|
||||||
|
onToggleDoc={this.onToggleDoc}
|
||||||
|
fieldSpec={this.props.fieldSpec}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{!this.props.fieldSpec &&
|
||||||
|
<div className="maputnik-input-block-label">
|
||||||
|
{this.props.label}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<div className="maputnik-input-block-action">
|
||||||
|
{this.props.action}
|
||||||
|
</div>
|
||||||
|
<div className="maputnik-input-block-content">
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
|
{this.props.fieldSpec &&
|
||||||
|
<div
|
||||||
|
className="maputnik-doc-inline"
|
||||||
|
style={{display: this.state.showDoc ? '' : 'none'}}
|
||||||
|
>
|
||||||
|
<Doc fieldSpec={this.props.fieldSpec} />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { combiningFilterOps } from '../../libs/filterops.js'
|
import {combiningFilterOps} from '../libs/filterops'
|
||||||
import {mdiTableRowPlusAfter} from '@mdi/js';
|
import {mdiTableRowPlusAfter} from '@mdi/js';
|
||||||
|
import {isEqual} from 'lodash';
|
||||||
|
|
||||||
import {latest, validate, migrate} from '@mapbox/mapbox-gl-style-spec'
|
import {latest, migrate, convertFilter} from '@maplibre/maplibre-gl-style-spec'
|
||||||
import DocLabel from '../fields/DocLabel'
|
import InputSelect from './InputSelect'
|
||||||
import SelectInput from '../inputs/SelectInput'
|
import Block from './Block'
|
||||||
import InputBlock from '../inputs/InputBlock'
|
|
||||||
import SingleFilterEditor from './SingleFilterEditor'
|
import SingleFilterEditor from './SingleFilterEditor'
|
||||||
import FilterEditorBlock from './FilterEditorBlock'
|
import FilterEditorBlock from './FilterEditorBlock'
|
||||||
import Button from '../Button'
|
import InputButton from './InputButton'
|
||||||
import SpecDoc from '../inputs/SpecDoc'
|
import Doc from './Doc'
|
||||||
import ExpressionProperty from '../fields/_ExpressionProperty';
|
import ExpressionProperty from './_ExpressionProperty';
|
||||||
import {mdiFunctionVariant} from '@mdi/js';
|
import {mdiFunctionVariant} from '@mdi/js';
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ function createStyleFromFilter (filter) {
|
|||||||
"id": "tmp",
|
"id": "tmp",
|
||||||
"version": 8,
|
"version": 8,
|
||||||
"name": "Empty Style",
|
"name": "Empty Style",
|
||||||
"metadata": {"maputnik:renderer": "mbgljs"},
|
"metadata": {"maputnik:renderer": "mlgljs"},
|
||||||
"sources": {
|
"sources": {
|
||||||
"tmp": {
|
"tmp": {
|
||||||
"type": "geojson",
|
"type": "geojson",
|
||||||
@@ -62,24 +62,19 @@ function createStyleFromFilter (filter) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
const FILTER_OPS = [
|
||||||
* This is doing way more work than we need it to, however validating a whole
|
"all",
|
||||||
* style if the only thing that's exported from mapbox-gl-style-spec at the
|
"any",
|
||||||
* moment. Not really an issue though as it take ~0.1ms to calculate.
|
"none"
|
||||||
*/
|
];
|
||||||
|
|
||||||
|
// If we convert a filter that is an expression to an expression it'll remain the same in value
|
||||||
function checkIfSimpleFilter (filter) {
|
function checkIfSimpleFilter (filter) {
|
||||||
if (!filter || !combiningFilterOps.includes(filter[0])) {
|
if (filter.length === 1 && FILTER_OPS.includes(filter[0])) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
const expression = convertFilter(filter);
|
||||||
// Because "none" isn't supported by the next expression syntax we can test
|
return !isEqual(expression, filter);
|
||||||
// with ["none", ...] because it'll return false if it's a new style
|
|
||||||
// expression.
|
|
||||||
const moddedFilter = ["none", ...filter.slice(1)];
|
|
||||||
const tmpStyle = createStyleFromFilter(moddedFilter)
|
|
||||||
|
|
||||||
const errors = validate(tmpStyle);
|
|
||||||
return (errors.length < 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasCombiningFilter(filter) {
|
function hasCombiningFilter(filter) {
|
||||||
@@ -94,7 +89,7 @@ function hasNestedCombiningFilter(filter) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class CombiningFilterEditor extends React.Component {
|
export default class FilterEditor extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
/** Properties of the vector layer and the available fields */
|
/** Properties of the vector layer and the available fields */
|
||||||
properties: PropTypes.object,
|
properties: PropTypes.object,
|
||||||
@@ -192,14 +187,15 @@ export default class CombiningFilterEditor extends React.Component {
|
|||||||
<p>
|
<p>
|
||||||
Nested filters are not supported.
|
Nested filters are not supported.
|
||||||
</p>
|
</p>
|
||||||
<Button
|
<InputButton
|
||||||
onClick={this.makeExpression}
|
onClick={this.makeExpression}
|
||||||
|
title="Convert to expression"
|
||||||
>
|
>
|
||||||
<svg style={{marginRight: "0.2em", width:"14px", height:"14px", verticalAlign: "middle"}} viewBox="0 0 24 24">
|
<svg style={{marginRight: "0.2em", width:"14px", height:"14px", verticalAlign: "middle"}} viewBox="0 0 24 24">
|
||||||
<path fill="currentColor" d={mdiFunctionVariant} />
|
<path fill="currentColor" d={mdiFunctionVariant} />
|
||||||
</svg>
|
</svg>
|
||||||
Upgrade to expression
|
Upgrade to expression
|
||||||
</Button>
|
</InputButton>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
else if (displaySimpleFilter) {
|
else if (displaySimpleFilter) {
|
||||||
@@ -209,14 +205,15 @@ export default class CombiningFilterEditor extends React.Component {
|
|||||||
|
|
||||||
const actions = (
|
const actions = (
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<InputButton
|
||||||
onClick={this.makeExpression}
|
onClick={this.makeExpression}
|
||||||
|
title="Convert to expression"
|
||||||
className="maputnik-make-zoom-function"
|
className="maputnik-make-zoom-function"
|
||||||
>
|
>
|
||||||
<svg style={{width:"14px", height:"14px", verticalAlign: "middle"}} viewBox="0 0 24 24">
|
<svg style={{width:"14px", height:"14px", verticalAlign: "middle"}} viewBox="0 0 24 24">
|
||||||
<path fill="currentColor" d={mdiFunctionVariant} />
|
<path fill="currentColor" d={mdiFunctionVariant} />
|
||||||
</svg>
|
</svg>
|
||||||
</Button>
|
</InputButton>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -242,24 +239,24 @@ export default class CombiningFilterEditor extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<InputBlock
|
<Block
|
||||||
key="top"
|
key="top"
|
||||||
fieldSpec={fieldSpec}
|
fieldSpec={fieldSpec}
|
||||||
label={"Filter"}
|
label={"Filter"}
|
||||||
action={actions}
|
action={actions}
|
||||||
>
|
>
|
||||||
<SelectInput
|
<InputSelect
|
||||||
value={combiningOp}
|
value={combiningOp}
|
||||||
onChange={this.onFilterPartChanged.bind(this, 0)}
|
onChange={this.onFilterPartChanged.bind(this, 0)}
|
||||||
options={[["all", "every filter matches"], ["none", "no filter matches"], ["any", "any filter matches"]]}
|
options={[["all", "every filter matches"], ["none", "no filter matches"], ["any", "any filter matches"]]}
|
||||||
/>
|
/>
|
||||||
</InputBlock>
|
</Block>
|
||||||
{editorBlocks}
|
{editorBlocks}
|
||||||
<div
|
<div
|
||||||
key="buttons"
|
key="buttons"
|
||||||
className="maputnik-filter-editor-add-wrapper"
|
className="maputnik-filter-editor-add-wrapper"
|
||||||
>
|
>
|
||||||
<Button
|
<InputButton
|
||||||
data-wd-key="layer-filter-button"
|
data-wd-key="layer-filter-button"
|
||||||
className="maputnik-add-filter"
|
className="maputnik-add-filter"
|
||||||
onClick={this.addFilterItem}
|
onClick={this.addFilterItem}
|
||||||
@@ -267,14 +264,14 @@ export default class CombiningFilterEditor extends React.Component {
|
|||||||
<svg style={{width:"14px", height:"14px", verticalAlign: "text-bottom"}} viewBox="0 0 24 24">
|
<svg style={{width:"14px", height:"14px", verticalAlign: "text-bottom"}} viewBox="0 0 24 24">
|
||||||
<path fill="currentColor" d={mdiTableRowPlusAfter} />
|
<path fill="currentColor" d={mdiTableRowPlusAfter} />
|
||||||
</svg> Add filter
|
</svg> Add filter
|
||||||
</Button>
|
</InputButton>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
key="doc"
|
key="doc"
|
||||||
className="maputnik-doc-inline"
|
className="maputnik-doc-inline"
|
||||||
style={{display: this.state.showDoc ? '' : 'none'}}
|
style={{display: this.state.showDoc ? '' : 'none'}}
|
||||||
>
|
>
|
||||||
<SpecDoc fieldSpec={fieldSpec} />
|
<Doc fieldSpec={fieldSpec} />
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -1,23 +1,22 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import InputButton from './InputButton'
|
||||||
import Button from '../Button'
|
|
||||||
import {MdDelete} from 'react-icons/md'
|
import {MdDelete} from 'react-icons/md'
|
||||||
|
|
||||||
class FilterEditorBlock extends React.Component {
|
type FilterEditorBlockProps = {
|
||||||
static propTypes = {
|
onDelete(...args: unknown[]): unknown
|
||||||
onDelete: PropTypes.func.isRequired,
|
};
|
||||||
children: PropTypes.element.isRequired,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export default class FilterEditorBlock extends React.Component<FilterEditorBlockProps> {
|
||||||
render() {
|
render() {
|
||||||
return <div className="maputnik-filter-editor-block">
|
return <div className="maputnik-filter-editor-block">
|
||||||
<div className="maputnik-filter-editor-block-action">
|
<div className="maputnik-filter-editor-block-action">
|
||||||
<Button
|
<InputButton
|
||||||
className="maputnik-delete-filter"
|
className="maputnik-delete-filter"
|
||||||
onClick={this.props.onDelete}
|
onClick={this.props.onDelete}
|
||||||
|
title="Delete filter block"
|
||||||
>
|
>
|
||||||
<MdDelete />
|
<MdDelete />
|
||||||
</Button>
|
</InputButton>
|
||||||
</div>
|
</div>
|
||||||
<div className="maputnik-filter-editor-block-content">
|
<div className="maputnik-filter-editor-block-content">
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
@@ -26,4 +25,3 @@ class FilterEditorBlock extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FilterEditorBlock
|
|
||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import IconBase from 'react-icon-base'
|
import IconBase from 'react-icon-base'
|
||||||
|
|
||||||
|
|
||||||
export default class BackgroundIcon extends React.Component {
|
export default class IconBackground extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<IconBase viewBox="0 0 20 20" {...this.props}>
|
<IconBase viewBox="0 0 20 20" {...this.props}>
|
||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import IconBase from 'react-icon-base'
|
import IconBase from 'react-icon-base'
|
||||||
|
|
||||||
|
|
||||||
export default class FillIcon extends React.Component {
|
export default class IconCircle extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<IconBase viewBox="0 0 20 20" {...this.props}>
|
<IconBase viewBox="0 0 20 20" {...this.props}>
|
||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import IconBase from 'react-icon-base'
|
import IconBase from 'react-icon-base'
|
||||||
|
|
||||||
|
|
||||||
export default class FillIcon extends React.Component {
|
export default class IconFill extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<IconBase viewBox="0 0 20 20" {...this.props}>
|
<IconBase viewBox="0 0 20 20" {...this.props}>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import IconLine from './IconLine'
|
||||||
|
import IconFill from './IconFill'
|
||||||
|
import IconSymbol from './IconSymbol'
|
||||||
|
import IconBackground from './IconBackground'
|
||||||
|
import IconCircle from './IconCircle'
|
||||||
|
import IconMissing from './IconMissing'
|
||||||
|
|
||||||
|
type IconLayerProps = {
|
||||||
|
type: string
|
||||||
|
style?: object
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class IconLayer extends React.Component<IconLayerProps> {
|
||||||
|
render() {
|
||||||
|
const iconProps = { style: this.props.style }
|
||||||
|
switch(this.props.type) {
|
||||||
|
case 'fill-extrusion': return <IconBackground {...iconProps} />
|
||||||
|
case 'raster': return <IconFill {...iconProps} />
|
||||||
|
case 'hillshade': return <IconFill {...iconProps} />
|
||||||
|
case 'heatmap': return <IconFill {...iconProps} />
|
||||||
|
case 'fill': return <IconFill {...iconProps} />
|
||||||
|
case 'background': return <IconBackground {...iconProps} />
|
||||||
|
case 'line': return <IconLine {...iconProps} />
|
||||||
|
case 'symbol': return <IconSymbol {...iconProps} />
|
||||||
|
case 'circle': return <IconCircle {...iconProps} />
|
||||||
|
default: return <IconMissing {...iconProps} />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import IconBase from 'react-icon-base'
|
import IconBase from 'react-icon-base'
|
||||||
|
|
||||||
|
|
||||||
export default class FillIcon extends React.Component {
|
export default class IconLine extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<IconBase viewBox="0 0 20 20" {...this.props}>
|
<IconBase viewBox="0 0 20 20" {...this.props}>
|
||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import {MdPriorityHigh} from 'react-icons/md'
|
import {MdPriorityHigh} from 'react-icons/md'
|
||||||
|
|
||||||
|
|
||||||
export default class MissingIcon extends React.Component {
|
export default class IconMissing extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<MdPriorityHigh {...this.props} />
|
<MdPriorityHigh {...this.props} />
|
||||||
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import IconBase from 'react-icon-base'
|
import IconBase from 'react-icon-base'
|
||||||
|
|
||||||
|
|
||||||
export default class SymbolIcon extends React.Component {
|
export default class IconSymbol extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<IconBase viewBox="0 0 20 20" {...this.props}>
|
<IconBase viewBox="0 0 20 20" {...this.props}>
|
||||||
@@ -1,23 +1,29 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import InputString from './InputString'
|
||||||
import StringInput from './StringInput'
|
import InputNumber from './InputNumber'
|
||||||
import NumberInput from './NumberInput'
|
|
||||||
|
|
||||||
class ArrayInput extends React.Component {
|
export type FieldArrayProps = {
|
||||||
static propTypes = {
|
value: (string | number | undefined)[]
|
||||||
value: PropTypes.array,
|
type?: string
|
||||||
type: PropTypes.string,
|
length?: number
|
||||||
length: PropTypes.number,
|
default?: (string | number | undefined)[]
|
||||||
default: PropTypes.array,
|
onChange?(value: (string | number | undefined)[] | undefined): unknown
|
||||||
onChange: PropTypes.func,
|
'aria-label'?: string
|
||||||
}
|
label?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
type FieldArrayState = {
|
||||||
|
value: (string | number | undefined)[]
|
||||||
|
initialPropsValue: unknown[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class FieldArray extends React.Component<FieldArrayProps, FieldArrayState> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
value: [],
|
value: [],
|
||||||
default: [],
|
default: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (props) {
|
constructor (props: FieldArrayProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
value: this.props.value.slice(0),
|
value: this.props.value.slice(0),
|
||||||
@@ -26,8 +32,8 @@ class ArrayInput extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props, state) {
|
static getDerivedStateFromProps(props: FieldArrayProps, state: FieldArrayState) {
|
||||||
const value = [];
|
const value: any[] = [];
|
||||||
const initialPropsValue = state.initialPropsValue.slice(0);
|
const initialPropsValue = state.initialPropsValue.slice(0);
|
||||||
|
|
||||||
Array(props.length).fill(null).map((_, i) => {
|
Array(props.length).fill(null).map((_, i) => {
|
||||||
@@ -46,24 +52,24 @@ class ArrayInput extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
isComplete (value) {
|
isComplete(value: unknown[]) {
|
||||||
return Array(this.props.length).fill(null).every((_, i) => {
|
return Array(this.props.length).fill(null).every((_, i) => {
|
||||||
const val = value[i]
|
const val = value[i]
|
||||||
return !(val === undefined || val === "");
|
return !(val === undefined || val === "");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
changeValue(idx, newValue) {
|
changeValue(idx: number, newValue: string | number | undefined) {
|
||||||
const value = this.state.value.slice(0);
|
const value = this.state.value.slice(0);
|
||||||
value[idx] = newValue;
|
value[idx] = newValue;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
value,
|
value,
|
||||||
}, () => {
|
}, () => {
|
||||||
if (this.isComplete(value)) {
|
if (this.isComplete(value) && this.props.onChange) {
|
||||||
this.props.onChange(value);
|
this.props.onChange(value);
|
||||||
}
|
}
|
||||||
else {
|
else if (this.props.onChange){
|
||||||
// Unset until complete
|
// Unset until complete
|
||||||
this.props.onChange(undefined);
|
this.props.onChange(undefined);
|
||||||
}
|
}
|
||||||
@@ -82,28 +88,31 @@ class ArrayInput extends React.Component {
|
|||||||
|
|
||||||
const inputs = Array(this.props.length).fill(null).map((_, i) => {
|
const inputs = Array(this.props.length).fill(null).map((_, i) => {
|
||||||
if(this.props.type === 'number') {
|
if(this.props.type === 'number') {
|
||||||
return <NumberInput
|
return <InputNumber
|
||||||
key={i}
|
key={i}
|
||||||
default={containsValues ? undefined : this.props.default[i]}
|
default={containsValues || !this.props.default ? undefined : this.props.default[i] as number}
|
||||||
value={value[i]}
|
value={value[i] as number}
|
||||||
required={containsValues ? true : false}
|
required={containsValues ? true : false}
|
||||||
onChange={this.changeValue.bind(this, i)}
|
onChange={(v) => this.changeValue(i, v)}
|
||||||
|
aria-label={this.props['aria-label'] || this.props.label}
|
||||||
/>
|
/>
|
||||||
} else {
|
} else {
|
||||||
return <StringInput
|
return <InputString
|
||||||
key={i}
|
key={i}
|
||||||
default={containsValues ? undefined : this.props.default[i]}
|
default={containsValues || !this.props.default ? undefined : this.props.default[i] as string}
|
||||||
value={value[i]}
|
value={value[i] as string}
|
||||||
required={containsValues ? true : false}
|
required={containsValues ? true : false}
|
||||||
onChange={this.changeValue.bind(this, i)}
|
onChange={this.changeValue.bind(this, i)}
|
||||||
|
aria-label={this.props['aria-label'] || this.props.label}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return <div className="maputnik-array">
|
return (
|
||||||
{inputs}
|
<div className="maputnik-array">
|
||||||
</div>
|
{inputs}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ArrayInput
|
|
||||||
+17
-13
@@ -1,23 +1,25 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import Autocomplete from 'react-autocomplete'
|
import Autocomplete from 'react-autocomplete'
|
||||||
|
|
||||||
|
|
||||||
const MAX_HEIGHT = 140;
|
const MAX_HEIGHT = 140;
|
||||||
|
|
||||||
class AutocompleteInput extends React.Component {
|
export type InputAutocompleteProps = {
|
||||||
static propTypes = {
|
value?: string
|
||||||
value: PropTypes.string,
|
options: any[]
|
||||||
options: PropTypes.array,
|
onChange(...args: unknown[]): unknown
|
||||||
onChange: PropTypes.func,
|
keepMenuWithinWindowBounds?: boolean
|
||||||
keepMenuWithinWindowBounds: PropTypes.bool
|
'aria-label'?: string
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default class InputAutocomplete extends React.Component<InputAutocompleteProps> {
|
||||||
state = {
|
state = {
|
||||||
maxHeight: MAX_HEIGHT
|
maxHeight: MAX_HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autocompleteMenuEl: HTMLDivElement | null = null;
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
onChange: () => {},
|
onChange: () => {},
|
||||||
options: [],
|
options: [],
|
||||||
@@ -25,7 +27,7 @@ class AutocompleteInput extends React.Component {
|
|||||||
|
|
||||||
calcMaxHeight() {
|
calcMaxHeight() {
|
||||||
if(this.props.keepMenuWithinWindowBounds) {
|
if(this.props.keepMenuWithinWindowBounds) {
|
||||||
const maxHeight = window.innerHeight - this.autocompleteMenuEl.getBoundingClientRect().top;
|
const maxHeight = window.innerHeight - this.autocompleteMenuEl!.getBoundingClientRect().top;
|
||||||
const limitedMaxHeight = Math.min(maxHeight, MAX_HEIGHT);
|
const limitedMaxHeight = Math.min(maxHeight, MAX_HEIGHT);
|
||||||
|
|
||||||
if(limitedMaxHeight != this.state.maxHeight) {
|
if(limitedMaxHeight != this.state.maxHeight) {
|
||||||
@@ -44,7 +46,7 @@ class AutocompleteInput extends React.Component {
|
|||||||
this.calcMaxHeight();
|
this.calcMaxHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange (v) {
|
onChange(v: string) {
|
||||||
this.props.onChange(v === "" ? undefined : v);
|
this.props.onChange(v === "" ? undefined : v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,9 +65,10 @@ class AutocompleteInput extends React.Component {
|
|||||||
}}
|
}}
|
||||||
wrapperProps={{
|
wrapperProps={{
|
||||||
className: "maputnik-autocomplete",
|
className: "maputnik-autocomplete",
|
||||||
style: null
|
style: {}
|
||||||
}}
|
}}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
|
'aria-label': this.props['aria-label'],
|
||||||
className: "maputnik-string",
|
className: "maputnik-string",
|
||||||
spellCheck: false
|
spellCheck: false
|
||||||
}}
|
}}
|
||||||
@@ -73,11 +76,12 @@ class AutocompleteInput extends React.Component {
|
|||||||
items={this.props.options}
|
items={this.props.options}
|
||||||
getItemValue={(item) => item[0]}
|
getItemValue={(item) => item[0]}
|
||||||
onSelect={v => this.onChange(v)}
|
onSelect={v => this.onChange(v)}
|
||||||
onChange={(e, v) => this.onChange(v)}
|
onChange={(_e, v) => this.onChange(v)}
|
||||||
shouldItemRender={(item, value="") => {
|
shouldItemRender={(item, value="") => {
|
||||||
if (typeof(value) === "string") {
|
if (typeof(value) === "string") {
|
||||||
return item[0].toLowerCase().indexOf(value.toLowerCase()) > -1
|
return item[0].toLowerCase().indexOf(value.toLowerCase()) > -1
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}}
|
}}
|
||||||
renderItem={(item, isHighlighted) => (
|
renderItem={(item, isHighlighted) => (
|
||||||
<div
|
<div
|
||||||
@@ -95,4 +99,4 @@ class AutocompleteInput extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AutocompleteInput
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import classnames from 'classnames'
|
||||||
|
|
||||||
|
type InputButtonProps = {
|
||||||
|
"data-wd-key"?: string
|
||||||
|
"aria-label"?: string
|
||||||
|
onClick?(...args: unknown[]): unknown
|
||||||
|
style?: object
|
||||||
|
className?: string
|
||||||
|
children?: React.ReactNode
|
||||||
|
disabled?: boolean
|
||||||
|
type?: typeof HTMLButtonElement.prototype.type
|
||||||
|
id?: string
|
||||||
|
title?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class InputButton extends React.Component<InputButtonProps> {
|
||||||
|
render() {
|
||||||
|
return <button
|
||||||
|
id={this.props.id}
|
||||||
|
title={this.props.title}
|
||||||
|
type={this.props.type}
|
||||||
|
onClick={this.props.onClick}
|
||||||
|
disabled={this.props.disabled}
|
||||||
|
aria-label={this.props["aria-label"]}
|
||||||
|
className={classnames("maputnik-button", this.props.className)}
|
||||||
|
data-wd-key={this.props["data-wd-key"]}
|
||||||
|
style={this.props.style}
|
||||||
|
>
|
||||||
|
{this.props.children}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,28 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
class CheckboxInput extends React.Component {
|
export type InputCheckboxProps = {
|
||||||
static propTypes = {
|
value?: boolean
|
||||||
value: PropTypes.bool,
|
style?: object
|
||||||
style: PropTypes.object,
|
onChange(...args: unknown[]): unknown
|
||||||
onChange: PropTypes.func,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
export default class InputCheckbox extends React.Component<InputCheckboxProps> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
value: false,
|
value: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onChange = () => {
|
||||||
|
this.props.onChange(!this.props.value);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <label className="maputnik-checkbox-wrapper">
|
return <div className="maputnik-checkbox-wrapper">
|
||||||
<input
|
<input
|
||||||
className="maputnik-checkbox"
|
className="maputnik-checkbox"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
style={this.props.style}
|
style={this.props.style}
|
||||||
onChange={e => this.props.onChange(!this.props.value)}
|
onChange={this.onChange}
|
||||||
|
onClick={this.onChange}
|
||||||
checked={this.props.value}
|
checked={this.props.value}
|
||||||
/>
|
/>
|
||||||
<div className="maputnik-checkbox-box">
|
<div className="maputnik-checkbox-box">
|
||||||
@@ -28,8 +32,6 @@ class CheckboxInput extends React.Component {
|
|||||||
<path d='M1 14 L5 10 L13 18 L27 4 L31 8 L13 26 z' />
|
<path d='M1 14 L5 10 L13 18 L27 4 L31 8 L13 26 z' />
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CheckboxInput
|
|
||||||
@@ -1,35 +1,37 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Color from 'color'
|
import Color from 'color'
|
||||||
import ChromePicker from 'react-color/lib/components/chrome/Chrome'
|
import ChromePicker from 'react-color/lib/components/chrome/Chrome'
|
||||||
import PropTypes from 'prop-types'
|
import {ColorResult} from 'react-color';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
|
|
||||||
function formatColor(color) {
|
function formatColor(color: ColorResult): string {
|
||||||
const rgb = color.rgb
|
const rgb = color.rgb
|
||||||
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})`
|
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})`
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** Number fields with support for min, max and units and documentation*/
|
export type InputColorProps = {
|
||||||
class ColorField extends React.Component {
|
onChange(...args: unknown[]): unknown
|
||||||
static propTypes = {
|
name?: string
|
||||||
onChange: PropTypes.func.isRequired,
|
value?: string
|
||||||
name: PropTypes.string,
|
doc?: string
|
||||||
value: PropTypes.string,
|
style?: object
|
||||||
doc: PropTypes.string,
|
default?: string
|
||||||
style: PropTypes.object,
|
'aria-label'?: string
|
||||||
default: PropTypes.string,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
/*** Number fields with support for min, max and units and documentation*/
|
||||||
|
export default class InputColor extends React.Component<InputColorProps> {
|
||||||
state = {
|
state = {
|
||||||
pickerOpened: false
|
pickerOpened: false
|
||||||
}
|
}
|
||||||
|
colorInput: HTMLInputElement | null = null;
|
||||||
|
|
||||||
constructor () {
|
constructor (props: InputColorProps) {
|
||||||
super();
|
super(props);
|
||||||
this.onChangeNoCheck = lodash.throttle(this.onChangeNoCheck, 1000/30);
|
this.onChangeNoCheck = lodash.throttle(this.onChangeNoCheck, 1000/30);
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeNoCheck (v) {
|
onChangeNoCheck(v: string) {
|
||||||
this.props.onChange(v);
|
this.props.onChange(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,31 +69,31 @@ class ColorField extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange (v) {
|
onChange (v: string) {
|
||||||
this.props.onChange(v === "" ? undefined : v);
|
this.props.onChange(v === "" ? undefined : v);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const offset = this.calcPickerOffset()
|
const offset = this.calcPickerOffset()
|
||||||
var currentColor = this.color.object()
|
const currentColor = this.color.object();
|
||||||
currentColor = {
|
const currentChromeColor = {
|
||||||
r: currentColor.r,
|
r: currentColor.r,
|
||||||
g: currentColor.g,
|
g: currentColor.g,
|
||||||
b: currentColor.b,
|
b: currentColor.b,
|
||||||
// Rename alpha -> a for ChromePicker
|
// Rename alpha -> a for ChromePicker
|
||||||
a: currentColor.alpha
|
a: currentColor.alpha!
|
||||||
}
|
}
|
||||||
|
|
||||||
const picker = <div
|
const picker = <div
|
||||||
className="maputnik-color-picker-offset"
|
className="maputnik-color-picker-offset"
|
||||||
style={{
|
style={{
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
zIndex: 1,
|
zIndex: 1,
|
||||||
left: offset.left,
|
left: offset.left,
|
||||||
top: offset.top,
|
top: offset.top,
|
||||||
}}>
|
}}>
|
||||||
<ChromePicker
|
<ChromePicker
|
||||||
color={currentColor}
|
color={currentChromeColor}
|
||||||
onChange={c => this.onChangeNoCheck(formatColor(c))}
|
onChange={c => this.onChangeNoCheck(formatColor(c))}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
@@ -116,7 +118,9 @@ class ColorField extends React.Component {
|
|||||||
{this.state.pickerOpened && picker}
|
{this.state.pickerOpened && picker}
|
||||||
<div className="maputnik-color-swatch" style={swatchStyle}></div>
|
<div className="maputnik-color-swatch" style={swatchStyle}></div>
|
||||||
<input
|
<input
|
||||||
|
aria-label={this.props['aria-label']}
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
|
autoComplete="off"
|
||||||
className="maputnik-color"
|
className="maputnik-color"
|
||||||
ref={(input) => this.colorInput = input}
|
ref={(input) => this.colorInput = input}
|
||||||
onClick={this.togglePicker}
|
onClick={this.togglePicker}
|
||||||
@@ -130,4 +134,3 @@ class ColorField extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ColorField
|
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import capitalize from 'lodash.capitalize'
|
||||||
|
import {MdDelete} from 'react-icons/md'
|
||||||
|
|
||||||
|
import InputString from './InputString'
|
||||||
|
import InputNumber from './InputNumber'
|
||||||
|
import InputButton from './InputButton'
|
||||||
|
import FieldDocLabel from './FieldDocLabel'
|
||||||
|
import InputEnum from './InputEnum'
|
||||||
|
import InputUrl from './InputUrl'
|
||||||
|
|
||||||
|
|
||||||
|
export type FieldDynamicArrayProps = {
|
||||||
|
value?: (string | number | undefined)[]
|
||||||
|
type?: 'url' | 'number' | 'enum' | 'string'
|
||||||
|
default?: (string | number | undefined)[]
|
||||||
|
onChange?(values: (string | number | undefined)[] | undefined): unknown
|
||||||
|
style?: object
|
||||||
|
fieldSpec?: {
|
||||||
|
values?: any
|
||||||
|
}
|
||||||
|
'aria-label'?: string
|
||||||
|
label: string
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class FieldDynamicArray extends React.Component<FieldDynamicArrayProps> {
|
||||||
|
changeValue(idx: number, newValue: string | number | undefined) {
|
||||||
|
const values = this.values.slice(0)
|
||||||
|
values[idx] = newValue
|
||||||
|
if (this.props.onChange) this.props.onChange(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
get values() {
|
||||||
|
return this.props.value || this.props.default || []
|
||||||
|
}
|
||||||
|
|
||||||
|
addValue = () => {
|
||||||
|
const values = this.values.slice(0)
|
||||||
|
if (this.props.type === 'number') {
|
||||||
|
values.push(0)
|
||||||
|
}
|
||||||
|
else if (this.props.type === 'url') {
|
||||||
|
values.push("");
|
||||||
|
}
|
||||||
|
else if (this.props.type === 'enum') {
|
||||||
|
const {fieldSpec} = this.props;
|
||||||
|
const defaultValue = Object.keys(fieldSpec!.values)[0];
|
||||||
|
values.push(defaultValue);
|
||||||
|
} else {
|
||||||
|
values.push("")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.props.onChange) this.props.onChange(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteValue(valueIdx: number) {
|
||||||
|
const values = this.values.slice(0)
|
||||||
|
values.splice(valueIdx, 1)
|
||||||
|
|
||||||
|
if (this.props.onChange) this.props.onChange(values.length > 0 ? values : undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const inputs = this.values.map((v, i) => {
|
||||||
|
const deleteValueBtn= <DeleteValueInputButton onClick={this.deleteValue.bind(this, i)} />
|
||||||
|
let input;
|
||||||
|
if(this.props.type === 'url') {
|
||||||
|
input = <InputUrl
|
||||||
|
value={v as string}
|
||||||
|
onChange={this.changeValue.bind(this, i)}
|
||||||
|
aria-label={this.props['aria-label'] || this.props.label}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
else if (this.props.type === 'number') {
|
||||||
|
input = <InputNumber
|
||||||
|
value={v as number}
|
||||||
|
onChange={this.changeValue.bind(this, i)}
|
||||||
|
aria-label={this.props['aria-label'] || this.props.label}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
else if (this.props.type === 'enum') {
|
||||||
|
const options = Object.keys(this.props.fieldSpec?.values).map(v => [v, capitalize(v)]);
|
||||||
|
input = <InputEnum
|
||||||
|
options={options}
|
||||||
|
value={v as string}
|
||||||
|
onChange={this.changeValue.bind(this, i)}
|
||||||
|
aria-label={this.props['aria-label'] || this.props.label}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
input = <InputString
|
||||||
|
value={v as string}
|
||||||
|
onChange={this.changeValue.bind(this, i)}
|
||||||
|
aria-label={this.props['aria-label'] || this.props.label}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div
|
||||||
|
style={this.props.style}
|
||||||
|
key={i}
|
||||||
|
className="maputnik-array-block"
|
||||||
|
>
|
||||||
|
<div className="maputnik-array-block-action">
|
||||||
|
{deleteValueBtn}
|
||||||
|
</div>
|
||||||
|
<div className="maputnik-array-block-content">
|
||||||
|
{input}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="maputnik-array">
|
||||||
|
{inputs}
|
||||||
|
<InputButton
|
||||||
|
className="maputnik-array-add-value"
|
||||||
|
onClick={this.addValue}
|
||||||
|
>
|
||||||
|
Add value
|
||||||
|
</InputButton>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteValueInputButtonProps = {
|
||||||
|
onClick?(...args: unknown[]): unknown
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeleteValueInputButton extends React.Component<DeleteValueInputButtonProps> {
|
||||||
|
render() {
|
||||||
|
return <InputButton
|
||||||
|
className="maputnik-delete-stop"
|
||||||
|
onClick={this.props.onClick}
|
||||||
|
title="Remove array item"
|
||||||
|
>
|
||||||
|
<FieldDocLabel
|
||||||
|
label={<MdDelete />}
|
||||||
|
fieldSpec={{doc:" Remove array item."}}
|
||||||
|
/>
|
||||||
|
</InputButton>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputSelect from './InputSelect'
|
||||||
|
import InputMultiInput from './InputMultiInput'
|
||||||
|
|
||||||
|
|
||||||
|
function optionsLabelLength(options: any[]) {
|
||||||
|
let sum = 0;
|
||||||
|
options.forEach(([_, label]) => {
|
||||||
|
sum += label.length
|
||||||
|
})
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export type InputEnumProps = {
|
||||||
|
"data-wd-key"?: string
|
||||||
|
value?: string
|
||||||
|
style?: object
|
||||||
|
default?: string
|
||||||
|
name?: string
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
options: any[]
|
||||||
|
'aria-label'?: string
|
||||||
|
label?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default class InputEnum extends React.Component<InputEnumProps> {
|
||||||
|
render() {
|
||||||
|
const {options, value, onChange, name, label} = this.props;
|
||||||
|
|
||||||
|
if(options.length <= 3 && optionsLabelLength(options) <= 20) {
|
||||||
|
return <InputMultiInput
|
||||||
|
name={name}
|
||||||
|
options={options}
|
||||||
|
value={(value || this.props.default)!}
|
||||||
|
onChange={onChange}
|
||||||
|
aria-label={this.props['aria-label'] || label}
|
||||||
|
/>
|
||||||
|
} else {
|
||||||
|
return <InputSelect
|
||||||
|
options={options}
|
||||||
|
value={(value || this.props.default)!}
|
||||||
|
onChange={onChange}
|
||||||
|
aria-label={this.props['aria-label'] || label}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputAutocomplete from './InputAutocomplete'
|
||||||
|
|
||||||
|
export type FieldFontProps = {
|
||||||
|
name: string
|
||||||
|
value?: string[]
|
||||||
|
default?: string[]
|
||||||
|
fonts?: unknown[]
|
||||||
|
style?: object
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
'aria-label'?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class FieldFont extends React.Component<FieldFontProps> {
|
||||||
|
static defaultProps = {
|
||||||
|
fonts: []
|
||||||
|
}
|
||||||
|
|
||||||
|
get values() {
|
||||||
|
const out = this.props.value || this.props.default || [];
|
||||||
|
|
||||||
|
// Always put a "" in the last field to you can keep adding entries
|
||||||
|
if (out[out.length-1] !== ""){
|
||||||
|
return out.concat("");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
changeFont(idx: number, newValue: string) {
|
||||||
|
const changedValues = this.values.slice(0)
|
||||||
|
changedValues[idx] = newValue
|
||||||
|
const filteredValues = changedValues
|
||||||
|
.filter(v => v !== undefined)
|
||||||
|
.filter(v => v !== "")
|
||||||
|
|
||||||
|
this.props.onChange(filteredValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const inputs = this.values.map((value, i) => {
|
||||||
|
return <li
|
||||||
|
key={i}
|
||||||
|
>
|
||||||
|
<InputAutocomplete
|
||||||
|
aria-label={this.props['aria-label'] || this.props.name}
|
||||||
|
value={value}
|
||||||
|
options={this.props.fonts?.map(f => [f, f])}
|
||||||
|
onChange={this.changeFont.bind(this, i)}
|
||||||
|
/>
|
||||||
|
</li>
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ul className="maputnik-font">
|
||||||
|
{inputs}
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import classnames from 'classnames';
|
||||||
|
import CodeMirror, { ModeSpec } from 'codemirror';
|
||||||
|
|
||||||
|
import 'codemirror/mode/javascript/javascript'
|
||||||
|
import 'codemirror/addon/lint/lint'
|
||||||
|
import 'codemirror/addon/edit/matchbrackets'
|
||||||
|
import 'codemirror/lib/codemirror.css'
|
||||||
|
import 'codemirror/addon/lint/lint.css'
|
||||||
|
import stringifyPretty from 'json-stringify-pretty-compact'
|
||||||
|
import '../util/codemirror-mgl';
|
||||||
|
|
||||||
|
|
||||||
|
export type InputJsonProps = {
|
||||||
|
layer: any
|
||||||
|
maxHeight?: number
|
||||||
|
onChange?(...args: unknown[]): unknown
|
||||||
|
lineNumbers?: boolean
|
||||||
|
lineWrapping?: boolean
|
||||||
|
getValue?(data: any): string
|
||||||
|
gutters?: string[]
|
||||||
|
className?: string
|
||||||
|
onFocus?(...args: unknown[]): unknown
|
||||||
|
onBlur?(...args: unknown[]): unknown
|
||||||
|
onJSONValid?(...args: unknown[]): unknown
|
||||||
|
onJSONInvalid?(...args: unknown[]): unknown
|
||||||
|
mode?: ModeSpec<any>
|
||||||
|
lint?: boolean | object
|
||||||
|
};
|
||||||
|
|
||||||
|
type InputJsonState = {
|
||||||
|
isEditing: boolean
|
||||||
|
showMessage: boolean
|
||||||
|
prevValue: string
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class InputJson extends React.Component<InputJsonProps, InputJsonState> {
|
||||||
|
static defaultProps = {
|
||||||
|
lineNumbers: true,
|
||||||
|
lineWrapping: false,
|
||||||
|
gutters: ["CodeMirror-lint-markers"],
|
||||||
|
getValue: (data: any) => {
|
||||||
|
return stringifyPretty(data, {indent: 2, maxLength: 40});
|
||||||
|
},
|
||||||
|
onFocus: () => {},
|
||||||
|
onBlur: () => {},
|
||||||
|
onJSONInvalid: () => {},
|
||||||
|
onJSONValid: () => {},
|
||||||
|
}
|
||||||
|
_keyEvent: string;
|
||||||
|
_doc: CodeMirror.Editor | undefined;
|
||||||
|
_el: HTMLDivElement | null = null;
|
||||||
|
_cancelNextChange: boolean = false;
|
||||||
|
|
||||||
|
constructor(props: InputJsonProps) {
|
||||||
|
super(props);
|
||||||
|
this._keyEvent = "keyboard";
|
||||||
|
this.state = {
|
||||||
|
isEditing: false,
|
||||||
|
showMessage: false,
|
||||||
|
prevValue: this.props.getValue!(this.props.layer),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
this._doc = CodeMirror(this._el!, {
|
||||||
|
value: this.props.getValue!(this.props.layer),
|
||||||
|
mode: this.props.mode || {
|
||||||
|
name: "mgl",
|
||||||
|
},
|
||||||
|
lineWrapping: this.props.lineWrapping,
|
||||||
|
tabSize: 2,
|
||||||
|
theme: 'maputnik',
|
||||||
|
viewportMargin: Infinity,
|
||||||
|
lineNumbers: this.props.lineNumbers,
|
||||||
|
lint: this.props.lint || {
|
||||||
|
context: "layer"
|
||||||
|
},
|
||||||
|
matchBrackets: true,
|
||||||
|
gutters: this.props.gutters,
|
||||||
|
scrollbarStyle: "null",
|
||||||
|
});
|
||||||
|
|
||||||
|
this._doc.on('change', this.onChange);
|
||||||
|
this._doc.on('focus', this.onFocus);
|
||||||
|
this._doc.on('blur', this.onBlur);
|
||||||
|
}
|
||||||
|
|
||||||
|
onPointerDown = () => {
|
||||||
|
this._keyEvent = "pointer";
|
||||||
|
}
|
||||||
|
|
||||||
|
onFocus = () => {
|
||||||
|
if (this.props.onFocus) this.props.onFocus();
|
||||||
|
this.setState({
|
||||||
|
isEditing: true,
|
||||||
|
showMessage: (this._keyEvent === "keyboard"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onBlur = () => {
|
||||||
|
this._keyEvent = "keyboard";
|
||||||
|
if (this.props.onBlur) this.props.onBlur();
|
||||||
|
this.setState({
|
||||||
|
isEditing: false,
|
||||||
|
showMessage: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnMount () {
|
||||||
|
this._doc!.off('change', this.onChange);
|
||||||
|
this._doc!.off('focus', this.onFocus);
|
||||||
|
this._doc!.off('blur', this.onBlur);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps: InputJsonProps) {
|
||||||
|
if (!this.state.isEditing && prevProps.layer !== this.props.layer) {
|
||||||
|
this._cancelNextChange = true;
|
||||||
|
this._doc!.setValue(
|
||||||
|
this.props.getValue!(this.props.layer),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange = (_e: unknown) => {
|
||||||
|
if (this._cancelNextChange) {
|
||||||
|
this._cancelNextChange = false;
|
||||||
|
this.setState({
|
||||||
|
prevValue: this._doc!.getValue(),
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newCode = this._doc!.getValue();
|
||||||
|
|
||||||
|
if (this.state.prevValue !== newCode) {
|
||||||
|
let parsedLayer, err;
|
||||||
|
try {
|
||||||
|
parsedLayer = JSON.parse(newCode);
|
||||||
|
} catch(_err) {
|
||||||
|
err = _err;
|
||||||
|
console.warn(_err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err && this.props.onJSONInvalid) {
|
||||||
|
this.props.onJSONInvalid();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (this.props.onChange) this.props.onChange(parsedLayer)
|
||||||
|
if (this.props.onJSONValid) this.props.onJSONValid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
prevValue: newCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {showMessage} = this.state;
|
||||||
|
const style = {} as {maxHeight?: number};
|
||||||
|
if (this.props.maxHeight) {
|
||||||
|
style.maxHeight = this.props.maxHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div className="JSONEditor" onPointerDown={this.onPointerDown} aria-hidden="true">
|
||||||
|
<div className={classnames("JSONEditor__message", {"JSONEditor__message--on": showMessage})}>
|
||||||
|
Press <kbd>ESC</kbd> to lose focus
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={classnames("codemirror-container", this.props.className)}
|
||||||
|
ref={(el) => this._el = el}
|
||||||
|
style={style}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import classnames from 'classnames'
|
||||||
|
|
||||||
|
export type InputMultiInputProps = {
|
||||||
|
name?: string
|
||||||
|
value: string
|
||||||
|
options: any[]
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
'aria-label'?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class InputMultiInput extends React.Component<InputMultiInputProps> {
|
||||||
|
render() {
|
||||||
|
let options = this.props.options
|
||||||
|
if(options.length > 0 && !Array.isArray(options[0])) {
|
||||||
|
options = options.map(v => [v, v])
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedValue = this.props.value || options[0][0]
|
||||||
|
const radios = options.map(([val, label])=> {
|
||||||
|
return <label
|
||||||
|
key={val}
|
||||||
|
className={classnames("maputnik-radio-as-button", {"maputnik-button-selected": val === selectedValue})}
|
||||||
|
>
|
||||||
|
<input type="radio"
|
||||||
|
name={this.props.name}
|
||||||
|
onChange={_e => this.props.onChange(val)}
|
||||||
|
value={val}
|
||||||
|
checked={val === selectedValue}
|
||||||
|
/>
|
||||||
|
{label}
|
||||||
|
</label>
|
||||||
|
})
|
||||||
|
|
||||||
|
return <fieldset className="maputnik-multibutton" aria-label={this.props['aria-label']}>
|
||||||
|
{radios}
|
||||||
|
</fieldset>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,26 +1,35 @@
|
|||||||
import React from 'react'
|
import React, { BaseSyntheticEvent } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
let IDX = 0;
|
let IDX = 0;
|
||||||
|
|
||||||
class NumberInput extends React.Component {
|
export type InputNumberProps = {
|
||||||
static propTypes = {
|
value?: number
|
||||||
value: PropTypes.number,
|
default?: number
|
||||||
default: PropTypes.number,
|
min?: number
|
||||||
min: PropTypes.number,
|
max?: number
|
||||||
max: PropTypes.number,
|
onChange?(value: number | undefined): unknown
|
||||||
onChange: PropTypes.func,
|
allowRange?: boolean
|
||||||
allowRange: PropTypes.bool,
|
rangeStep?: number
|
||||||
rangeStep: PropTypes.number,
|
wdKey?: string
|
||||||
wdKey: PropTypes.string,
|
required?: boolean
|
||||||
required: PropTypes.bool,
|
"aria-label"?: string
|
||||||
}
|
};
|
||||||
|
|
||||||
|
type InputNumberState = {
|
||||||
|
uuid: number
|
||||||
|
editing: boolean
|
||||||
|
editingRange?: boolean
|
||||||
|
value?: number
|
||||||
|
dirtyValue?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class InputNumber extends React.Component<InputNumberProps, InputNumberState> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
rangeStep: 1
|
rangeStep: 1
|
||||||
}
|
}
|
||||||
|
_keyboardEvent: boolean = false;
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props: InputNumberProps) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
uuid: IDX++,
|
uuid: IDX++,
|
||||||
@@ -30,7 +39,7 @@ class NumberInput extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props, state) {
|
static getDerivedStateFromProps(props: InputNumberProps, state: InputNumberState) {
|
||||||
if (!state.editing && props.value !== state.value) {
|
if (!state.editing && props.value !== state.value) {
|
||||||
return {
|
return {
|
||||||
value: props.value,
|
value: props.value,
|
||||||
@@ -40,16 +49,15 @@ class NumberInput extends React.Component {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
changeValue(newValue) {
|
changeValue(newValue: number | string | undefined) {
|
||||||
const value = (newValue === "" || newValue === undefined) ?
|
const value = (newValue === "" || newValue === undefined) ?
|
||||||
undefined :
|
undefined : +newValue;
|
||||||
parseFloat(newValue);
|
|
||||||
|
|
||||||
const hasChanged = this.props.value !== value;
|
const hasChanged = this.props.value !== value;
|
||||||
if(this.isValid(value) && hasChanged) {
|
if(this.isValid(value) && hasChanged) {
|
||||||
this.props.onChange(value)
|
if (this.props.onChange) this.props.onChange(value)
|
||||||
this.setState({
|
this.setState({
|
||||||
value: newValue,
|
value: value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (!this.isValid(value) && hasChanged) {
|
else if (!this.isValid(value) && hasChanged) {
|
||||||
@@ -59,25 +67,25 @@ class NumberInput extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
dirtyValue: newValue === "" ? undefined : newValue,
|
dirtyValue: newValue === "" ? undefined : value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
isValid(v) {
|
isValid(v: number | string | undefined) {
|
||||||
if (v === undefined) {
|
if (v === undefined) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = parseFloat(v)
|
const value = +v;
|
||||||
if(isNaN(value)) {
|
if(isNaN(value)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isNaN(this.props.min) && value < this.props.min) {
|
if(!isNaN(this.props.min!) && value < this.props.min!) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isNaN(this.props.max) && value > this.props.max) {
|
if(!isNaN(this.props.max!) && value > this.props.max!) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +95,7 @@ class NumberInput extends React.Component {
|
|||||||
resetValue = () => {
|
resetValue = () => {
|
||||||
this.setState({editing: false});
|
this.setState({editing: false});
|
||||||
// Reset explicitly to default value if value has been cleared
|
// Reset explicitly to default value if value has been cleared
|
||||||
if(this.state.value === "") {
|
if(!this.state.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +111,8 @@ class NumberInput extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeRange = (e) => {
|
onChangeRange = (e: BaseSyntheticEvent<Event, HTMLInputElement, HTMLInputElement>) => {
|
||||||
let value = parseFloat(e.target.value, 10);
|
let value = parseFloat(e.target.value);
|
||||||
const step = this.props.rangeStep;
|
const step = this.props.rangeStep;
|
||||||
let dirtyValue = value;
|
let dirtyValue = value;
|
||||||
|
|
||||||
@@ -118,11 +126,11 @@ class NumberInput extends React.Component {
|
|||||||
// for example we might go from 13 to 13.23, however because we know
|
// for example we might go from 13 to 13.23, however because we know
|
||||||
// that came from a keyboard event we always want to increase by a
|
// that came from a keyboard event we always want to increase by a
|
||||||
// single step value.
|
// single step value.
|
||||||
if (value < this.state.dirtyValue) {
|
if (value < this.state.dirtyValue!) {
|
||||||
value = this.state.value - step;
|
value = this.state.value! - step;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
value = this.state.value + step
|
value = this.state.value! + step
|
||||||
}
|
}
|
||||||
dirtyValue = value;
|
dirtyValue = value;
|
||||||
}
|
}
|
||||||
@@ -139,10 +147,10 @@ class NumberInput extends React.Component {
|
|||||||
this._keyboardEvent = false;
|
this._keyboardEvent = false;
|
||||||
|
|
||||||
// Clamp between min/max
|
// Clamp between min/max
|
||||||
value = Math.max(this.props.min, Math.min(this.props.max, value));
|
value = Math.max(this.props.min!, Math.min(this.props.max!, value));
|
||||||
|
|
||||||
this.setState({value, dirtyValue});
|
this.setState({value, dirtyValue});
|
||||||
this.props.onChange(value);
|
if (this.props.onChange) this.props.onChange(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -171,7 +179,6 @@ class NumberInput extends React.Component {
|
|||||||
step="any"
|
step="any"
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
value={value === undefined ? defaultValue : value}
|
value={value === undefined ? defaultValue : value}
|
||||||
aria-hidden="true"
|
|
||||||
onChange={this.onChangeRange}
|
onChange={this.onChangeRange}
|
||||||
onKeyDown={() => {
|
onKeyDown={() => {
|
||||||
this._keyboardEvent = true;
|
this._keyboardEvent = true;
|
||||||
@@ -196,15 +203,15 @@ class NumberInput extends React.Component {
|
|||||||
type="text"
|
type="text"
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
className="maputnik-number"
|
className="maputnik-number"
|
||||||
placeholder={this.props.default}
|
placeholder={this.props.default?.toString()}
|
||||||
value={inputValue === undefined ? "" : inputValue}
|
value={inputValue === undefined ? "" : inputValue}
|
||||||
onFocus={e => {
|
onFocus={_e => {
|
||||||
this.setState({editing: true});
|
this.setState({editing: true});
|
||||||
}}
|
}}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
this.changeValue(e.target.value);
|
this.changeValue(e.target.value);
|
||||||
}}
|
}}
|
||||||
onBlur={e => {
|
onBlur={_e => {
|
||||||
this.setState({editing: false});
|
this.setState({editing: false});
|
||||||
this.resetValue()
|
this.resetValue()
|
||||||
}}
|
}}
|
||||||
@@ -215,9 +222,10 @@ class NumberInput extends React.Component {
|
|||||||
const value = this.state.editing ? this.state.dirtyValue : this.state.value;
|
const value = this.state.editing ? this.state.dirtyValue : this.state.value;
|
||||||
|
|
||||||
return <input
|
return <input
|
||||||
|
aria-label={this.props['aria-label']}
|
||||||
spellCheck="false"
|
spellCheck="false"
|
||||||
className="maputnik-number"
|
className="maputnik-number"
|
||||||
placeholder={this.props.default}
|
placeholder={this.props.default?.toString()}
|
||||||
value={value === undefined ? "" : value}
|
value={value === undefined ? "" : value}
|
||||||
onChange={e => this.changeValue(e.target.value)}
|
onChange={e => this.changeValue(e.target.value)}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
@@ -230,4 +238,4 @@ class NumberInput extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NumberInput
|
|
||||||
@@ -1,21 +1,20 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
class SelectInput extends React.Component {
|
|
||||||
static propTypes = {
|
|
||||||
value: PropTypes.string.isRequired,
|
|
||||||
"data-wd-key": PropTypes.string,
|
|
||||||
options: PropTypes.array.isRequired,
|
|
||||||
style: PropTypes.object,
|
|
||||||
onChange: PropTypes.func.isRequired,
|
|
||||||
title: PropTypes.string,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export type InputSelectProps = {
|
||||||
|
value: string
|
||||||
|
"data-wd-key"?: string
|
||||||
|
options: [string, any][] | string[]
|
||||||
|
style?: object
|
||||||
|
onChange(value: string): unknown
|
||||||
|
title?: string
|
||||||
|
'aria-label'?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class InputSelect extends React.Component<InputSelectProps> {
|
||||||
render() {
|
render() {
|
||||||
let options = this.props.options
|
let options = this.props.options;
|
||||||
if(options.length > 0 && !Array.isArray(options[0])) {
|
if(options.length > 0 && !Array.isArray(options[0])) {
|
||||||
options = options.map(v => [v, v])
|
options = options.map((v) => [v, v]) as [string, any][];
|
||||||
}
|
}
|
||||||
|
|
||||||
return <select
|
return <select
|
||||||
@@ -25,10 +24,11 @@ class SelectInput extends React.Component {
|
|||||||
title={this.props.title}
|
title={this.props.title}
|
||||||
value={this.props.value}
|
value={this.props.value}
|
||||||
onChange={e => this.props.onChange(e.target.value)}
|
onChange={e => this.props.onChange(e.target.value)}
|
||||||
|
aria-label={this.props['aria-label']}
|
||||||
>
|
>
|
||||||
{ options.map(([val, label]) => <option key={val} value={val}>{label}</option>) }
|
{ options.map(([val, label]) => <option key={val} value={val}>{label}</option>) }
|
||||||
</select>
|
</select>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SelectInput
|
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
import React, { ReactElement } from 'react'
|
||||||
|
|
||||||
|
import InputColor, { InputColorProps } from './InputColor'
|
||||||
|
import InputNumber, { InputNumberProps } from './InputNumber'
|
||||||
|
import InputCheckbox, { InputCheckboxProps } from './InputCheckbox'
|
||||||
|
import InputString, { InputStringProps } from './InputString'
|
||||||
|
import InputArray, { FieldArrayProps } from './InputArray'
|
||||||
|
import InputDynamicArray, { FieldDynamicArrayProps } from './InputDynamicArray'
|
||||||
|
import InputFont, { FieldFontProps } from './InputFont'
|
||||||
|
import InputAutocomplete, { InputAutocompleteProps } from './InputAutocomplete'
|
||||||
|
import InputEnum, { InputEnumProps } from './InputEnum'
|
||||||
|
import capitalize from 'lodash.capitalize'
|
||||||
|
|
||||||
|
const iconProperties = ['background-pattern', 'fill-pattern', 'line-pattern', 'fill-extrusion-pattern', 'icon-image']
|
||||||
|
|
||||||
|
export type SpecFieldProps = {
|
||||||
|
onChange?(fieldName: string | undefined, value: number | undefined | (string | number | undefined)[]): unknown
|
||||||
|
fieldName?: string
|
||||||
|
fieldSpec?: {
|
||||||
|
default?: unknown
|
||||||
|
type?: 'number' | 'enum' | 'resolvedImage' | 'formatted' | 'string' | 'color' | 'boolean' | 'array'
|
||||||
|
minimum?: number
|
||||||
|
maximum?: number
|
||||||
|
values?: unknown[]
|
||||||
|
length?: number
|
||||||
|
value?: string
|
||||||
|
}
|
||||||
|
value?: string | number | unknown[] | boolean
|
||||||
|
/** Override the style of the field */
|
||||||
|
style?: object
|
||||||
|
'aria-label'?: string
|
||||||
|
error?: unknown[]
|
||||||
|
label?: string
|
||||||
|
action?: ReactElement
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Display any field from the Maplibre GL style spec and
|
||||||
|
* choose the correct field component based on the @{fieldSpec}
|
||||||
|
* to display @{value}. */
|
||||||
|
export default class SpecField extends React.Component<SpecFieldProps> {
|
||||||
|
|
||||||
|
childNodes() {
|
||||||
|
const commonProps = {
|
||||||
|
error: this.props.error,
|
||||||
|
fieldSpec: this.props.fieldSpec,
|
||||||
|
label: this.props.label,
|
||||||
|
action: this.props.action,
|
||||||
|
style: this.props.style,
|
||||||
|
value: this.props.value,
|
||||||
|
default: this.props.fieldSpec?.default,
|
||||||
|
name: this.props.fieldName,
|
||||||
|
onChange: (newValue: number | undefined | (string | number | undefined)[]) => this.props.onChange!(this.props.fieldName, newValue),
|
||||||
|
'aria-label': this.props['aria-label'],
|
||||||
|
}
|
||||||
|
switch(this.props.fieldSpec?.type) {
|
||||||
|
case 'number': return (
|
||||||
|
<InputNumber
|
||||||
|
{...commonProps as InputNumberProps}
|
||||||
|
min={this.props.fieldSpec.minimum}
|
||||||
|
max={this.props.fieldSpec.maximum}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
case 'enum':
|
||||||
|
const options = Object.keys(this.props.fieldSpec.values || []).map(v => [v, capitalize(v)])
|
||||||
|
|
||||||
|
return <InputEnum
|
||||||
|
{...commonProps as Omit<InputEnumProps, "options">}
|
||||||
|
options={options}
|
||||||
|
/>
|
||||||
|
case 'resolvedImage':
|
||||||
|
case 'formatted':
|
||||||
|
case 'string':
|
||||||
|
if (iconProperties.indexOf(this.props.fieldName!) >= 0) {
|
||||||
|
const options = this.props.fieldSpec.values || [];
|
||||||
|
return <InputAutocomplete
|
||||||
|
{...commonProps as Omit<InputAutocompleteProps, "options">}
|
||||||
|
options={options.map(f => [f, f])}
|
||||||
|
/>
|
||||||
|
} else {
|
||||||
|
return <InputString
|
||||||
|
{...commonProps as InputStringProps}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
case 'color': return (
|
||||||
|
<InputColor
|
||||||
|
{...commonProps as InputColorProps}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
case 'boolean': return (
|
||||||
|
<InputCheckbox
|
||||||
|
{...commonProps as InputCheckboxProps}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
case 'array':
|
||||||
|
if(this.props.fieldName === 'text-font') {
|
||||||
|
return <InputFont
|
||||||
|
{...commonProps as FieldFontProps}
|
||||||
|
fonts={this.props.fieldSpec.values}
|
||||||
|
/>
|
||||||
|
} else {
|
||||||
|
if (this.props.fieldSpec.length) {
|
||||||
|
return <InputArray
|
||||||
|
{...commonProps as FieldArrayProps}
|
||||||
|
type={this.props.fieldSpec.value}
|
||||||
|
length={this.props.fieldSpec.length}
|
||||||
|
/>
|
||||||
|
} else {
|
||||||
|
return <InputDynamicArray
|
||||||
|
{...commonProps as FieldDynamicArrayProps}
|
||||||
|
fieldSpec={this.props.fieldSpec}
|
||||||
|
type={this.props.fieldSpec.value as FieldDynamicArrayProps['type']}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div data-wd-key={"spec-field:"+this.props.fieldName}>
|
||||||
|
{this.childNodes()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +1,31 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
class StringInput extends React.Component {
|
export type InputStringProps = {
|
||||||
static propTypes = {
|
"data-wd-key"?: string
|
||||||
"data-wd-key": PropTypes.string,
|
value?: string
|
||||||
value: PropTypes.string,
|
style?: object
|
||||||
style: PropTypes.object,
|
default?: string
|
||||||
default: PropTypes.string,
|
onChange?(value: string | undefined): unknown
|
||||||
onChange: PropTypes.func,
|
onInput?(value: string | undefined): unknown
|
||||||
onInput: PropTypes.func,
|
multi?: boolean
|
||||||
multi: PropTypes.bool,
|
required?: boolean
|
||||||
required: PropTypes.bool,
|
disabled?: boolean
|
||||||
disabled: PropTypes.bool,
|
spellCheck?: boolean
|
||||||
spellCheck: PropTypes.bool,
|
'aria-label'?: string
|
||||||
}
|
title?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
type InputStringState = {
|
||||||
|
editing: boolean
|
||||||
|
value?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class InputString extends React.Component<InputStringProps, InputStringState> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
onInput: () => {},
|
onInput: () => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props: InputStringProps) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
editing: false,
|
editing: false,
|
||||||
@@ -27,7 +33,7 @@ class StringInput extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props, state) {
|
static getDerivedStateFromProps(props: InputStringProps, state: InputStringState) {
|
||||||
if (!state.editing) {
|
if (!state.editing) {
|
||||||
return {
|
return {
|
||||||
value: props.value
|
value: props.value
|
||||||
@@ -59,6 +65,7 @@ class StringInput extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return React.createElement(tag, {
|
return React.createElement(tag, {
|
||||||
|
"aria-label": this.props["aria-label"],
|
||||||
"data-wd-key": this.props["data-wd-key"],
|
"data-wd-key": this.props["data-wd-key"],
|
||||||
spellCheck: this.props.hasOwnProperty("spellCheck") ? this.props.spellCheck : !(tag === "input"),
|
spellCheck: this.props.hasOwnProperty("spellCheck") ? this.props.spellCheck : !(tag === "input"),
|
||||||
disabled: this.props.disabled,
|
disabled: this.props.disabled,
|
||||||
@@ -66,22 +73,23 @@ class StringInput extends React.Component {
|
|||||||
style: this.props.style,
|
style: this.props.style,
|
||||||
value: this.state.value === undefined ? "" : this.state.value,
|
value: this.state.value === undefined ? "" : this.state.value,
|
||||||
placeholder: this.props.default,
|
placeholder: this.props.default,
|
||||||
onChange: e => {
|
title: this.props.title,
|
||||||
|
onChange: (e: React.BaseSyntheticEvent<Event, HTMLInputElement, HTMLInputElement>) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
editing: true,
|
editing: true,
|
||||||
value: e.target.value
|
value: e.target.value
|
||||||
}, () => {
|
}, () => {
|
||||||
this.props.onInput(this.state.value);
|
if (this.props.onInput) this.props.onInput(this.state.value);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onBlur: () => {
|
onBlur: () => {
|
||||||
if(this.state.value!==this.props.value) {
|
if(this.state.value!==this.props.value) {
|
||||||
this.setState({editing: false});
|
this.setState({editing: false});
|
||||||
this.props.onChange(this.state.value);
|
if (this.props.onChange) this.props.onChange(this.state.value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onKeyDown: (e) => {
|
onKeyDown: (e) => {
|
||||||
if (e.keyCode === 13) {
|
if (e.keyCode === 13 && this.props.onChange) {
|
||||||
this.props.onChange(this.state.value);
|
this.props.onChange(this.state.value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -90,4 +98,4 @@ class StringInput extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default StringInput
|
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import InputString from './InputString'
|
||||||
|
import SmallError from './SmallError'
|
||||||
|
|
||||||
|
|
||||||
|
function validate(url: string) {
|
||||||
|
if (url === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let error;
|
||||||
|
const getProtocol = (url: string) => {
|
||||||
|
try {
|
||||||
|
const urlObj = new URL(url);
|
||||||
|
return urlObj.protocol;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const protocol = getProtocol(url);
|
||||||
|
const isSsl = window.location.protocol === "https:";
|
||||||
|
|
||||||
|
if (!protocol) {
|
||||||
|
error = (
|
||||||
|
<SmallError>
|
||||||
|
Must provide protocol {
|
||||||
|
isSsl
|
||||||
|
? <code>https://</code>
|
||||||
|
: <><code>http://</code> or <code>https://</code></>
|
||||||
|
}
|
||||||
|
</SmallError>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
protocol &&
|
||||||
|
protocol === "http:" &&
|
||||||
|
window.location.protocol === "https:"
|
||||||
|
) {
|
||||||
|
error = (
|
||||||
|
<SmallError>
|
||||||
|
CORS policy won't allow fetching resources served over http from https, use a <code>https://</code> domain
|
||||||
|
</SmallError>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FieldUrlProps = {
|
||||||
|
"data-wd-key"?: string
|
||||||
|
value: string
|
||||||
|
style?: object
|
||||||
|
default?: string
|
||||||
|
onChange(...args: unknown[]): unknown
|
||||||
|
onInput?(...args: unknown[]): unknown
|
||||||
|
multi?: boolean
|
||||||
|
required?: boolean
|
||||||
|
'aria-label'?: string
|
||||||
|
type?: string
|
||||||
|
className?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
type FieldUrlState = {
|
||||||
|
error?: React.ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class FieldUrl extends React.Component<FieldUrlProps, FieldUrlState> {
|
||||||
|
static defaultProps = {
|
||||||
|
onInput: () => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (props: FieldUrlProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
error: validate(props.value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
onInput = (url: string) => {
|
||||||
|
this.setState({
|
||||||
|
error: validate(url)
|
||||||
|
});
|
||||||
|
if (this.props.onInput) this.props.onInput(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange = (url: string) => {
|
||||||
|
this.setState({
|
||||||
|
error: validate(url)
|
||||||
|
});
|
||||||
|
this.props.onChange(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<InputString
|
||||||
|
{...this.props}
|
||||||
|
onInput={this.onInput}
|
||||||
|
onChange={this.onChange}
|
||||||
|
aria-label={this.props['aria-label']}
|
||||||
|
/>
|
||||||
|
{this.state.error}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,23 +2,23 @@ import React from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Wrapper, Button, Menu, MenuItem } from 'react-aria-menubutton'
|
import { Wrapper, Button, Menu, MenuItem } from 'react-aria-menubutton'
|
||||||
|
|
||||||
import JSONEditor from './JSONEditor'
|
import FieldJson from './FieldJson'
|
||||||
import FilterEditor from '../filter/FilterEditor'
|
import FilterEditor from './FilterEditor'
|
||||||
import PropertyGroup from '../fields/PropertyGroup'
|
import PropertyGroup from './PropertyGroup'
|
||||||
import LayerEditorGroup from './LayerEditorGroup'
|
import LayerEditorGroup from './LayerEditorGroup'
|
||||||
import LayerTypeBlock from './LayerTypeBlock'
|
import FieldType from './FieldType'
|
||||||
import LayerIdBlock from './LayerIdBlock'
|
import FieldId from './FieldId'
|
||||||
import MinZoomBlock from './MinZoomBlock'
|
import FieldMinZoom from './FieldMinZoom'
|
||||||
import MaxZoomBlock from './MaxZoomBlock'
|
import FieldMaxZoom from './FieldMaxZoom'
|
||||||
import CommentBlock from './CommentBlock'
|
import FieldComment from './FieldComment'
|
||||||
import LayerSourceBlock from './LayerSourceBlock'
|
import FieldSource from './FieldSource'
|
||||||
import LayerSourceLayerBlock from './LayerSourceLayerBlock'
|
import FieldSourceLayer from './FieldSourceLayer'
|
||||||
import {Accordion} from 'react-accessible-accordion';
|
import {Accordion} from 'react-accessible-accordion';
|
||||||
|
|
||||||
import {MdMoreVert} from 'react-icons/md'
|
import {MdMoreVert} from 'react-icons/md'
|
||||||
|
|
||||||
import { changeType, changeProperty } from '../../libs/layer'
|
import { changeType, changeProperty } from '../libs/layer'
|
||||||
import layout from '../../config/layout.json'
|
import layout from '../config/layout.json'
|
||||||
import {formatLayerId} from '../util/format';
|
import {formatLayerId} from '../util/format';
|
||||||
|
|
||||||
|
|
||||||
@@ -152,13 +152,13 @@ export default class LayerEditor extends React.Component {
|
|||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case 'layer': return <div>
|
case 'layer': return <div>
|
||||||
<LayerIdBlock
|
<FieldId
|
||||||
value={this.props.layer.id}
|
value={this.props.layer.id}
|
||||||
wdKey="layer-editor.layer-id"
|
wdKey="layer-editor.layer-id"
|
||||||
error={errorData.id}
|
error={errorData.id}
|
||||||
onChange={newId => this.props.onLayerIdChange(this.props.layerIndex, this.props.layer.id, newId)}
|
onChange={newId => this.props.onLayerIdChange(this.props.layerIndex, this.props.layer.id, newId)}
|
||||||
/>
|
/>
|
||||||
<LayerTypeBlock
|
<FieldType
|
||||||
disabled={true}
|
disabled={true}
|
||||||
error={errorData.type}
|
error={errorData.type}
|
||||||
value={this.props.layer.type}
|
value={this.props.layer.type}
|
||||||
@@ -167,7 +167,7 @@ export default class LayerEditor extends React.Component {
|
|||||||
changeType(this.props.layer, newType)
|
changeType(this.props.layer, newType)
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
{this.props.layer.type !== 'background' && <LayerSourceBlock
|
{this.props.layer.type !== 'background' && <FieldSource
|
||||||
error={errorData.source}
|
error={errorData.source}
|
||||||
sourceIds={Object.keys(this.props.sources)}
|
sourceIds={Object.keys(this.props.sources)}
|
||||||
value={this.props.layer.source}
|
value={this.props.layer.source}
|
||||||
@@ -175,24 +175,24 @@ export default class LayerEditor extends React.Component {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
{['background', 'raster', 'hillshade', 'heatmap'].indexOf(this.props.layer.type) < 0 &&
|
{['background', 'raster', 'hillshade', 'heatmap'].indexOf(this.props.layer.type) < 0 &&
|
||||||
<LayerSourceLayerBlock
|
<FieldSourceLayer
|
||||||
error={errorData['source-layer']}
|
error={errorData['source-layer']}
|
||||||
sourceLayerIds={sourceLayerIds}
|
sourceLayerIds={sourceLayerIds}
|
||||||
value={this.props.layer['source-layer']}
|
value={this.props.layer['source-layer']}
|
||||||
onChange={v => this.changeProperty(null, 'source-layer', v)}
|
onChange={v => this.changeProperty(null, 'source-layer', v)}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
<MinZoomBlock
|
<FieldMinZoom
|
||||||
error={errorData.minzoom}
|
error={errorData.minzoom}
|
||||||
value={this.props.layer.minzoom}
|
value={this.props.layer.minzoom}
|
||||||
onChange={v => this.changeProperty(null, 'minzoom', v)}
|
onChange={v => this.changeProperty(null, 'minzoom', v)}
|
||||||
/>
|
/>
|
||||||
<MaxZoomBlock
|
<FieldMaxZoom
|
||||||
error={errorData.maxzoom}
|
error={errorData.maxzoom}
|
||||||
value={this.props.layer.maxzoom}
|
value={this.props.layer.maxzoom}
|
||||||
onChange={v => this.changeProperty(null, 'maxzoom', v)}
|
onChange={v => this.changeProperty(null, 'maxzoom', v)}
|
||||||
/>
|
/>
|
||||||
<CommentBlock
|
<FieldComment
|
||||||
error={errorData.comment}
|
error={errorData.comment}
|
||||||
value={comment}
|
value={comment}
|
||||||
onChange={v => this.changeProperty('metadata', 'maputnik:comment', v == "" ? undefined : v)}
|
onChange={v => this.changeProperty('metadata', 'maputnik:comment', v == "" ? undefined : v)}
|
||||||
@@ -208,22 +208,24 @@ export default class LayerEditor extends React.Component {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
case 'properties': return <PropertyGroup
|
case 'properties':
|
||||||
errors={errorData}
|
return <PropertyGroup
|
||||||
layer={this.props.layer}
|
errors={errorData}
|
||||||
groupFields={fields}
|
layer={this.props.layer}
|
||||||
spec={this.props.spec}
|
groupFields={fields}
|
||||||
onChange={this.changeProperty.bind(this)}
|
spec={this.props.spec}
|
||||||
/>
|
onChange={this.changeProperty.bind(this)}
|
||||||
case 'jsoneditor': return <JSONEditor
|
/>
|
||||||
layer={this.props.layer}
|
case 'jsoneditor':
|
||||||
onChange={(layer) => {
|
return <FieldJson
|
||||||
this.props.onLayerChanged(
|
layer={this.props.layer}
|
||||||
this.props.layerIndex,
|
onChange={(layer) => {
|
||||||
layer
|
this.props.onLayerChanged(
|
||||||
);
|
this.props.layerIndex,
|
||||||
}}
|
layer
|
||||||
/>
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,8 +290,10 @@ export default class LayerEditor extends React.Component {
|
|||||||
items[id].handler();
|
items[id].handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div className="maputnik-layer-editor"
|
return <section className="maputnik-layer-editor"
|
||||||
>
|
role="main"
|
||||||
|
aria-label="Layer editor"
|
||||||
|
>
|
||||||
<header>
|
<header>
|
||||||
<div className="layer-header">
|
<div className="layer-header">
|
||||||
<h2 className="layer-header__title">
|
<h2 className="layer-header__title">
|
||||||
@@ -301,7 +305,7 @@ export default class LayerEditor extends React.Component {
|
|||||||
onSelection={handleSelection}
|
onSelection={handleSelection}
|
||||||
closeOnSelection={false}
|
closeOnSelection={false}
|
||||||
>
|
>
|
||||||
<Button className='more-menu__button'>
|
<Button id="skip-target-layer-editor" data-wd-key="skip-target-layer-editor" className='more-menu__button' title="Layer options">
|
||||||
<MdMoreVert className="more-menu__button__svg" />
|
<MdMoreVert className="more-menu__button__svg" />
|
||||||
</Button>
|
</Button>
|
||||||
<Menu>
|
<Menu>
|
||||||
@@ -328,6 +332,6 @@ export default class LayerEditor extends React.Component {
|
|||||||
>
|
>
|
||||||
{groups}
|
{groups}
|
||||||
</Accordion>
|
</Accordion>
|
||||||
</div>
|
</section>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import Icon from '@mdi/react'
|
import Icon from '@mdi/react'
|
||||||
import {
|
import {
|
||||||
mdiMenuDown,
|
mdiMenuDown,
|
||||||
@@ -13,21 +12,22 @@ import {
|
|||||||
} from 'react-accessible-accordion';
|
} from 'react-accessible-accordion';
|
||||||
|
|
||||||
|
|
||||||
export default class LayerEditorGroup extends React.Component {
|
type LayerEditorGroupProps = {
|
||||||
static propTypes = {
|
"id"?: string
|
||||||
"id": PropTypes.string,
|
"data-wd-key"?: string
|
||||||
"data-wd-key": PropTypes.string,
|
title: string
|
||||||
title: PropTypes.string.isRequired,
|
isActive: boolean
|
||||||
isActive: PropTypes.bool.isRequired,
|
children: React.ReactElement
|
||||||
children: PropTypes.element.isRequired,
|
onActiveToggle(...args: unknown[]): unknown
|
||||||
onActiveToggle: PropTypes.func.isRequired
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
export default class LayerEditorGroup extends React.Component<LayerEditorGroupProps> {
|
||||||
render() {
|
render() {
|
||||||
return <AccordionItem uuid={this.props.id}>
|
return <AccordionItem uuid={this.props.id}>
|
||||||
<AccordionItemHeading className="maputnik-layer-editor-group"
|
<AccordionItemHeading className="maputnik-layer-editor-group"
|
||||||
data-wd-key={"layer-editor-group:"+this.props["data-wd-key"]}
|
data-wd-key={"layer-editor-group:"+this.props["data-wd-key"]}
|
||||||
onClick={e => this.props.onActiveToggle(!this.props.isActive)}
|
onClick={_e => this.props.onActiveToggle(!this.props.isActive)}
|
||||||
>
|
>
|
||||||
<AccordionItemButton className="maputnik-layer-editor-group__button">
|
<AccordionItemButton className="maputnik-layer-editor-group__button">
|
||||||
<span style={{flexGrow: 1}}>{this.props.title}</span>
|
<span style={{flexGrow: 1}}>{this.props.title}</span>
|
||||||
@@ -5,7 +5,7 @@ import lodash from 'lodash';
|
|||||||
|
|
||||||
import LayerListGroup from './LayerListGroup'
|
import LayerListGroup from './LayerListGroup'
|
||||||
import LayerListItem from './LayerListItem'
|
import LayerListItem from './LayerListItem'
|
||||||
import AddModal from '../modals/AddModal'
|
import ModalAdd from './ModalAdd'
|
||||||
|
|
||||||
import {SortableContainer} from 'react-sortable-hoc';
|
import {SortableContainer} from 'react-sortable-hoc';
|
||||||
|
|
||||||
@@ -35,6 +35,8 @@ function findClosestCommonPrefix(layers, idx) {
|
|||||||
return closestIdx
|
return closestIdx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let UID = 0;
|
||||||
|
|
||||||
// List of collapsible layer editors
|
// List of collapsible layer editors
|
||||||
class LayerListContainer extends React.Component {
|
class LayerListContainer extends React.Component {
|
||||||
static propTypes = {...layerListPropTypes}
|
static propTypes = {...layerListPropTypes}
|
||||||
@@ -49,6 +51,9 @@ class LayerListContainer extends React.Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
collapsedGroups: {},
|
collapsedGroups: {},
|
||||||
areAllGroupsExpanded: false,
|
areAllGroupsExpanded: false,
|
||||||
|
keys: {
|
||||||
|
add: UID++,
|
||||||
|
},
|
||||||
isOpen: {
|
isOpen: {
|
||||||
add: false,
|
add: false,
|
||||||
}
|
}
|
||||||
@@ -57,6 +62,10 @@ class LayerListContainer extends React.Component {
|
|||||||
|
|
||||||
toggleModal(modalName) {
|
toggleModal(modalName) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
keys: {
|
||||||
|
...this.state.keys,
|
||||||
|
[modalName]: UID++,
|
||||||
|
},
|
||||||
isOpen: {
|
isOpen: {
|
||||||
...this.state.isOpen,
|
...this.state.isOpen,
|
||||||
[modalName]: !this.state.isOpen[modalName]
|
[modalName]: !this.state.isOpen[modalName]
|
||||||
@@ -91,9 +100,18 @@ class LayerListContainer extends React.Component {
|
|||||||
|
|
||||||
groupedLayers() {
|
groupedLayers() {
|
||||||
const groups = []
|
const groups = []
|
||||||
|
const layerIdCount = new Map();
|
||||||
|
|
||||||
for (let i = 0; i < this.props.layers.length; i++) {
|
for (let i = 0; i < this.props.layers.length; i++) {
|
||||||
|
const origLayer = this.props.layers[i];
|
||||||
const previousLayer = this.props.layers[i-1]
|
const previousLayer = this.props.layers[i-1]
|
||||||
const layer = this.props.layers[i]
|
layerIdCount.set(origLayer.id,
|
||||||
|
layerIdCount.has(origLayer.id) ? layerIdCount.get(origLayer.id) + 1 : 0
|
||||||
|
);
|
||||||
|
const layer = {
|
||||||
|
...origLayer,
|
||||||
|
key: `layers-list-${origLayer.id}-${layerIdCount.get(origLayer.id)}`,
|
||||||
|
}
|
||||||
if(previousLayer && layerPrefix(previousLayer.id) == layerPrefix(layer.id)) {
|
if(previousLayer && layerPrefix(previousLayer.id) == layerPrefix(layer.id)) {
|
||||||
const lastGroup = groups[groups.length - 1]
|
const lastGroup = groups[groups.length - 1]
|
||||||
lastGroup.push(layer)
|
lastGroup.push(layer)
|
||||||
@@ -191,14 +209,13 @@ class LayerListContainer extends React.Component {
|
|||||||
|
|
||||||
const listItems = []
|
const listItems = []
|
||||||
let idx = 0
|
let idx = 0
|
||||||
const layerIdCount = new Map();
|
|
||||||
|
|
||||||
const layersByGroup = this.groupedLayers();
|
const layersByGroup = this.groupedLayers();
|
||||||
layersByGroup.forEach(layers => {
|
layersByGroup.forEach(layers => {
|
||||||
const groupPrefix = layerPrefix(layers[0].id)
|
const groupPrefix = layerPrefix(layers[0].id)
|
||||||
if(layers.length > 1) {
|
if(layers.length > 1) {
|
||||||
const grp = <LayerListGroup
|
const grp = <LayerListGroup
|
||||||
data-wd-key={[groupPrefix, idx].join('-')}
|
data-wd-key={[groupPrefix, idx].join('-')}
|
||||||
|
aria-controls={layers.map(l => l.key).join(" ")}
|
||||||
key={`group-${groupPrefix}-${idx}`}
|
key={`group-${groupPrefix}-${idx}`}
|
||||||
title={groupPrefix}
|
title={groupPrefix}
|
||||||
isActive={!this.isCollapsed(groupPrefix, idx) || idx === this.props.selectedLayerIndex}
|
isActive={!this.isCollapsed(groupPrefix, idx) || idx === this.props.selectedLayerIndex}
|
||||||
@@ -223,10 +240,6 @@ class LayerListContainer extends React.Component {
|
|||||||
additionalProps.ref = this.selectedItemRef;
|
additionalProps.ref = this.selectedItemRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
layerIdCount.set(layer.id,
|
|
||||||
layerIdCount.has(layer.id) ? layerIdCount.get(layer.id) + 1 : 0
|
|
||||||
);
|
|
||||||
const key = `${layer.id}-${layerIdCount.get(layer.id)}`;
|
|
||||||
const listItem = <LayerListItem
|
const listItem = <LayerListItem
|
||||||
className={classnames({
|
className={classnames({
|
||||||
'maputnik-layer-list-item-collapsed': layers.length > 1 && this.isCollapsed(groupPrefix, groupIdx) && idx !== this.props.selectedLayerIndex,
|
'maputnik-layer-list-item-collapsed': layers.length > 1 && this.isCollapsed(groupPrefix, groupIdx) && idx !== this.props.selectedLayerIndex,
|
||||||
@@ -234,7 +247,8 @@ class LayerListContainer extends React.Component {
|
|||||||
'maputnik-layer-list-item--error': !!layerError
|
'maputnik-layer-list-item--error': !!layerError
|
||||||
})}
|
})}
|
||||||
index={idx}
|
index={idx}
|
||||||
key={key}
|
key={layer.key}
|
||||||
|
id={layer.key}
|
||||||
layerId={layer.id}
|
layerId={layer.id}
|
||||||
layerIndex={idx}
|
layerIndex={idx}
|
||||||
layerType={layer.type}
|
layerType={layer.type}
|
||||||
@@ -251,8 +265,14 @@ class LayerListContainer extends React.Component {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return <div className="maputnik-layer-list" ref={this.scrollContainerRef}>
|
return <section
|
||||||
<AddModal
|
className="maputnik-layer-list"
|
||||||
|
role="complementary"
|
||||||
|
aria-label="Layers list"
|
||||||
|
ref={this.scrollContainerRef}
|
||||||
|
>
|
||||||
|
<ModalAdd
|
||||||
|
key={this.state.keys.add}
|
||||||
layers={this.props.layers}
|
layers={this.props.layers}
|
||||||
sources={this.props.sources}
|
sources={this.props.sources}
|
||||||
isOpen={this.state.isOpen.add}
|
isOpen={this.state.isOpen.add}
|
||||||
@@ -265,7 +285,8 @@ class LayerListContainer extends React.Component {
|
|||||||
<div className="maputnik-default-property">
|
<div className="maputnik-default-property">
|
||||||
<div className="maputnik-multibutton">
|
<div className="maputnik-multibutton">
|
||||||
<button
|
<button
|
||||||
id="skip-menu"
|
id="skip-target-layer-list"
|
||||||
|
data-wd-key="skip-target-layer-list"
|
||||||
onClick={this.toggleLayers}
|
onClick={this.toggleLayers}
|
||||||
className="maputnik-button">
|
className="maputnik-button">
|
||||||
{this.state.areAllGroupsExpanded === true ? "Collapse" : "Expand"}
|
{this.state.areAllGroupsExpanded === true ? "Collapse" : "Expand"}
|
||||||
@@ -283,10 +304,15 @@ class LayerListContainer extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<ul className="maputnik-layer-list-container">
|
<div
|
||||||
{listItems}
|
role="navigation"
|
||||||
</ul>
|
aria-label="Layers list"
|
||||||
</div>
|
>
|
||||||
|
<ul className="maputnik-layer-list-container">
|
||||||
|
{listItems}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,6 +327,7 @@ export default class LayerList extends React.Component {
|
|||||||
helperClass='sortableHelper'
|
helperClass='sortableHelper'
|
||||||
onSortEnd={this.props.onMoveLayer.bind(this)}
|
onSortEnd={this.props.onMoveLayer.bind(this)}
|
||||||
useDragHandle={true}
|
useDragHandle={true}
|
||||||
|
shouldCancelStart={() => false}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import Collapser from './Collapser'
|
||||||
|
|
||||||
|
type LayerListGroupProps = {
|
||||||
|
title: string
|
||||||
|
"data-wd-key"?: string
|
||||||
|
isActive: boolean
|
||||||
|
onActiveToggle(...args: unknown[]): unknown
|
||||||
|
'aria-controls'?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class LayerListGroup extends React.Component<LayerListGroupProps> {
|
||||||
|
render() {
|
||||||
|
return <li className="maputnik-layer-list-group">
|
||||||
|
<div className="maputnik-layer-list-group-header"
|
||||||
|
data-wd-key={"layer-list-group:"+this.props["data-wd-key"]}
|
||||||
|
onClick={_e => this.props.onActiveToggle(!this.props.isActive)}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
className="maputnik-layer-list-group-title"
|
||||||
|
aria-controls={this.props['aria-controls']}
|
||||||
|
aria-expanded={this.props.isActive}
|
||||||
|
>
|
||||||
|
{this.props.title}
|
||||||
|
</button>
|
||||||
|
<span className="maputnik-space" />
|
||||||
|
<Collapser
|
||||||
|
style={{ height: 14, width: 14 }}
|
||||||
|
isCollapsed={this.props.isActive}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,17 +4,19 @@ import classnames from 'classnames'
|
|||||||
|
|
||||||
import {MdContentCopy, MdVisibility, MdVisibilityOff, MdDelete} from 'react-icons/md'
|
import {MdContentCopy, MdVisibility, MdVisibilityOff, MdDelete} from 'react-icons/md'
|
||||||
|
|
||||||
import LayerIcon from '../icons/LayerIcon'
|
import IconLayer from './IconLayer'
|
||||||
import {SortableElement, SortableHandle} from 'react-sortable-hoc'
|
import {SortableElement, SortableHandle} from 'react-sortable-hoc'
|
||||||
|
|
||||||
|
|
||||||
const DraggableLabel = SortableHandle((props) => {
|
const DraggableLabel = SortableHandle((props) => {
|
||||||
return <div className="maputnik-layer-list-item-handle">
|
return <div className="maputnik-layer-list-item-handle">
|
||||||
<LayerIcon
|
<IconLayer
|
||||||
className="layer-handle__icon"
|
className="layer-handle__icon"
|
||||||
type={props.layerType}
|
type={props.layerType}
|
||||||
/>
|
/>
|
||||||
<span className="maputnik-layer-list-item-id">{props.layerId}</span>
|
<button className="maputnik-layer-list-item-id">
|
||||||
|
{props.layerId}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ class IconAction extends React.Component {
|
|||||||
className={`maputnik-layer-list-icon-action ${classAdditions}`}
|
className={`maputnik-layer-list-icon-action ${classAdditions}`}
|
||||||
data-wd-key={this.props.wdKey}
|
data-wd-key={this.props.wdKey}
|
||||||
onClick={this.props.onClick}
|
onClick={this.props.onClick}
|
||||||
|
aria-hidden="true"
|
||||||
>
|
>
|
||||||
{this.renderIcon()}
|
{this.renderIcon()}
|
||||||
</button>
|
</button>
|
||||||
@@ -97,6 +100,7 @@ class LayerListItem extends React.Component {
|
|||||||
const visibilityAction = this.props.visibility === 'visible' ? 'show' : 'hide';
|
const visibilityAction = this.props.visibility === 'visible' ? 'show' : 'hide';
|
||||||
|
|
||||||
return <li
|
return <li
|
||||||
|
id={this.props.id}
|
||||||
key={this.props.layerId}
|
key={this.props.layerId}
|
||||||
onClick={e => this.props.onLayerSelect(this.props.layerIndex)}
|
onClick={e => this.props.onLayerSelect(this.props.layerIndex)}
|
||||||
data-wd-key={"layer-list-item:"+this.props.layerId}
|
data-wd-key={"layer-list-item:"+this.props.layerId}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user