Skip to content

Commit

Permalink
Merge pull request #1457 from geoman-io/develop
Browse files Browse the repository at this point in the history
release v2.16.0
  • Loading branch information
mscno committed Feb 19, 2024
2 parents 9d76409 + 038c7d2 commit d5d4a0f
Show file tree
Hide file tree
Showing 44 changed files with 3,901 additions and 15,802 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Expand Up @@ -19,5 +19,8 @@
"L": true,
"window": true,
"document": true
}
},
"ignorePatterns": [
"cypress/libs"
]
}
38 changes: 31 additions & 7 deletions .github/workflows/nodejs.yml
Expand Up @@ -4,20 +4,44 @@ on: [push, pull_request]

jobs:
build:
name: Test
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 20.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v3
with:
version: 8

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
- run: npm test
cache: pnpm

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: |
${{ env.STORE_PATH }}
/home/runner/.cache/Cypress
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile --store-dir ${{ env.STORE_PATH }}
- run: pnpm run build
- run: pnpm test
env:
CI: true
83 changes: 83 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,83 @@
name: Release

on:
workflow_dispatch:
push:
tags:
- 'v*.*.*'

env:
FILE_NAME_PREFIX: geoman-io-leaflet-geoman-pro
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
build:
name: release job
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set version
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Check version
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ "${{ steps.version.outputs.version }}" != "$PACKAGE_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)"
exit 1
fi
- uses: pnpm/action-setup@v3
with:
version: 8

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: pnpm

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile --store-dir ${{ env.STORE_PATH }}

- name: Prepare package
run: pnpm pack

- name: Release
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.version.outputs.version }}
tag_name: v${{ steps.version.outputs.version }}
token: ${{ secrets.GEOMAN_RELEASE_TOKEN }}
files: |
${{env.FILE_NAME_PREFIX}}-${{ steps.version.outputs.version }}.tgz
LICENSE
- name: Publish to NPM
shell: bash
run: |
#!/bin/bash
# Set npm configurations
pnpm config set shamefully-hoist true
pnpm config set strict-peer-dependencies false
# Set auth token
pnpm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
pnpm publish --no-git-checks
54 changes: 54 additions & 0 deletions bundle.mjs
@@ -0,0 +1,54 @@
import * as esbuild from 'esbuild';
import fs from 'fs';

const plugins = [{
name: 'my-plugin',
setup(build) {
let count = 0;
build.onEnd(({ errors, warnings }) => {
count++;
const message = errors.length === 0 && warnings.length === 0
? 'Build completed.'
: `Build completed with ${errors.length} error(s) and ${warnings.length} warning(s).`;
console.log(`[BUILD #${count.toString().padStart(3, '0')}]:`, message); });
},
}];

const buildOptions = {
bundle: true,
entryPoints: ['./src/js/L.PM.js'],
loader: {
'.js': 'jsx',
'.css': 'css',
'.svg': 'dataurl' },
minify: true,
outfile: './dist/leaflet-geoman.js',
sourcemap: process.env.DEV ? true : false,
}

const ctx = await esbuild.context({ ...buildOptions, plugins });

if (process.env.DEV) {
// Watch in dev mode
await ctx.watch();
console.log('watching...');
const { host, port } = await ctx.serve({
port: 5500,
servedir: '.',
fallback: "./index.html"
});
console.log(`Serving app at ${host}:${port}.`);
} else {
// Clean /dist folder
fs.rmSync("./dist", { recursive: true, force: true });

// Build
await ctx.rebuild();

// Dispose context
ctx.dispose();

// Copy types
fs.copyFileSync('leaflet-geoman.d.ts', './dist/leaflet-geoman.d.ts');
fs.copyFileSync('./dist/leaflet-geoman.js', './dist/leaflet-geoman.min.js');
}
25 changes: 25 additions & 0 deletions cypress/integration/mixins.spec.js
@@ -0,0 +1,25 @@
describe('KeyboardMixin', () => {
it('Should unbind event listeners that bound by the KeyboardMixin after the map is destroyed', () => {
cy.window().then((window) => {
const { map, document } = window;

map.remove();

const isWindowBlurEventUnbound = !Object.entries(
window._leaflet_events
).some(([name, handler]) => name.startsWith('blur') && handler);
expect(
isWindowBlurEventUnbound,
'window blur event listener is not unbound'
).to.eq(true);

const isKeyUpDownEventUnbound = !Object.entries(
document._leaflet_events
).some(([name, handler]) => name.startsWith('key') && handler);
expect(
isKeyUpDownEventUnbound,
'document keyboard event listener is not unbound'
).to.eq(true);
});
});
});
59 changes: 53 additions & 6 deletions cypress/integration/polygon.spec.js
Expand Up @@ -716,9 +716,8 @@ describe('Draw & Edit Poly', () => {
onStop() {
expect(poly.pm.hasSelfIntersection()).to.equal(true);

const toucherSelfIntersectionFalse = handSelfIntersectionFalse.growFinger(
'mouse'
);
const toucherSelfIntersectionFalse =
handSelfIntersectionFalse.growFinger('mouse');
toucherSelfIntersectionFalse
.wait(100)
.moveTo(504, 337, 100)
Expand All @@ -744,9 +743,8 @@ describe('Draw & Edit Poly', () => {
allowSelfIntersectionEdit: true,
});

const toucherSelfIntersectionTrue = handSelfIntersectionTrue.growFinger(
'mouse'
);
const toucherSelfIntersectionTrue =
handSelfIntersectionTrue.growFinger('mouse');
toucherSelfIntersectionTrue
.wait(100)
.moveTo(294, 114, 100)
Expand Down Expand Up @@ -1280,4 +1278,53 @@ describe('Draw & Edit Poly', () => {
expect(hintLine.options.color).to.eql('red');
});
});

it('snap to start marker instead of to the layer below', () => {
cy.window().then(({ map, L }) => {
// it was not possible to create this test with creating the polygon by clicking
const polygon = L.polygon([
[
[20.53507732696281, 71.98242187500001],
[19.87005983797396, 71.97143554687501],
[19.782211275967995, 73.35021972656251],
[20.55565240377338, 73.48754882812501],
[20.53507732696281, 71.98242187500001],
],
]);
polygon.addTo(map);
map.fitBounds(polygon.getBounds(), { animate: false });
map.setZoom(8, { animate: false });

map.pm.enableDraw('Polygon');

map.pm.Draw.Polygon._hintMarker.setLatLng([
20.53837097209846, 72.22334801861803,
]);
map.pm.Draw.Polygon._createVertex({
latlng: [20.53837097209846, 72.22334801861803],
});

map.pm.Draw.Polygon._hintMarker.setLatLng([
20.21581109239457, 72.13073730468751,
]);
map.pm.Draw.Polygon._createVertex({
latlng: [20.21581109239457, 72.13073730468751],
});

map.pm.Draw.Polygon._hintMarker.setLatLng([
20.205501205844214, 72.77893066406251,
]);
map.pm.Draw.Polygon._createVertex({
latlng: [20.205501205844214, 72.77893066406251],
});
});

cy.get(mapSelector).trigger('mousemove', 413, 180);

cy.window().then(({ map }) => {
const hintMarker = map.pm.Draw.Polygon._hintMarker;
expect(hintMarker.getLatLng().lat).to.eq(20.53837097209846);
expect(hintMarker.getLatLng().lng).to.eq(72.22334801861803);
});
});
});
1 change: 1 addition & 0 deletions cypress/integration/rotation.spec.js
Expand Up @@ -37,6 +37,7 @@ describe('Rotation', () => {

cy.window().then(({ map }) => {
const layer = map.pm.getGeomanDrawLayers()[0];
expect(layer.pm.rotateEnabled()).to.equal(false);

layer.pm.enableRotate();
expect(layer.pm.rotateEnabled()).to.equal(true);
Expand Down
20 changes: 20 additions & 0 deletions cypress/integration/toolbar.spec.js
Expand Up @@ -500,4 +500,24 @@ describe('Testing the Toolbar', () => {
expect(eventFired).to.equal('drawPolygon');
});
});

it("After disabling & enabling of a button, while a mode is active, don't call disable on the draw layer", (done) => {
let eventFired = '';

cy.toolbarButton('edit').click();

cy.window().then(({ map }) => {
map.on('pm:drawend', ({ shape }) => {
eventFired = shape;
});
map.pm.Toolbar.setButtonDisabled('drawText', true);
map.pm.Toolbar.setButtonDisabled('drawText', false);
});
cy.toolbarButton('text').click();

cy.window().then(() => {
expect(eventFired).to.equal('');
done();
});
});
});
4 changes: 2 additions & 2 deletions demo/customcontrols.html
Expand Up @@ -28,9 +28,9 @@ <h2>Custom Controls in the Toolbar</h2>
</article>
</div>
<script src="https://unpkg.com/leaflet@latest/dist/leaflet.js"></script>
<script src="../dist/leaflet-geoman.min.js"></script>
<script src="../dist/leaflet-geoman.js"></script>
<!-- You can change from the local source to the cdn: -->
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.min.js"></script> -->
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.js"></script> -->
<script src="customcontrols.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion demo/demo-canvas.js
Expand Up @@ -114,7 +114,7 @@ const geoJsonData = {
coordinates: [
[
[-0.15483856201171872, 51.527329038465936],
[-0.16977310180664062, 51.51643437722083],
[-0.1697731018066406, 51.51643437722083],
[-0.15964508056640625, 51.50094238217541],
[-0.13149261474609375, 51.5042549065934],
[-0.11758804321289061, 51.518463972439385],
Expand Down
4 changes: 2 additions & 2 deletions demo/events.html
Expand Up @@ -21,9 +21,9 @@ <h2>Overview of the available events (Console)</h2>
</article>
</div>
<script src="https://unpkg.com/leaflet@latest/dist/leaflet.js"></script>
<script src="../dist/leaflet-geoman.min.js"></script>
<script src="../dist/leaflet-geoman.js"></script>
<!-- You can change from the local source to the cdn: -->
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.min.js"></script> -->
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.js"></script> -->
<script src="events.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions demo/index-canvas.html
Expand Up @@ -40,9 +40,9 @@ <h2>Editing A Layer Group</h2>
</article>
</div>
<script src="https://unpkg.com/leaflet@latest/dist/leaflet.js"></script>
<script src="../dist/leaflet-geoman.min.js"></script>
<script src="../dist/leaflet-geoman.js"></script>
<!-- You can change from the local source to the cdn: -->
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.min.js"></script> -->
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.js"></script> -->
<script src="demo-canvas.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions demo/index.html
Expand Up @@ -40,9 +40,9 @@ <h2>Editing A Layer Group</h2>
</article>
</div>
<script src="https://unpkg.com/leaflet@latest/dist/leaflet.js"></script>
<script src="../dist/leaflet-geoman.min.js"></script>
<script src="../dist/leaflet-geoman.js"></script>
<!-- You can change from the local source to the cdn: -->
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.min.js"></script> -->
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.js"></script> -->
<script src="demo.js"></script>
</body>
</html>

0 comments on commit d5d4a0f

Please sign in to comment.