@versatiles/svelte 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -135,7 +135,7 @@
135
135
  aria-controls="autocomplete-results"
136
136
  />
137
137
  <div class="autocomplete-results" class:hide-results={!isOpen}>
138
- {#each results as result, i}
138
+ {#each results as result, i (result.key)}
139
139
  <button
140
140
  onclick={() => close(i)}
141
141
  class={i === selectedIndex ? ' is-active' : ''}
@@ -1,7 +1,6 @@
1
1
  <!-- BBoxMap.svelte -->
2
2
  <script lang="ts">
3
3
  import type { CameraOptions, Map as MaplibreMapType } from 'maplibre-gl';
4
- import 'maplibre-gl/dist/maplibre-gl.css';
5
4
  import AutoComplete from './AutoComplete.svelte';
6
5
  import { getCountryName } from '../../utils/location.js';
7
6
  import BasicMap from '../BasicMap/BasicMap.svelte';
@@ -1,4 +1,3 @@
1
- import 'maplibre-gl/dist/maplibre-gl.css';
2
1
  import type { BBox } from 'geojson';
3
2
  type $$ComponentProps = {
4
3
  selectedBBox?: BBox;
@@ -3,7 +3,8 @@
3
3
  import type { Map as MaplibreMapType, MapOptions } from 'maplibre-gl';
4
4
  import 'maplibre-gl/dist/maplibre-gl.css';
5
5
  import { getMapStyle, isDarkMode } from '../../utils/map_style.js';
6
- import { Map as MaplibreMap } from 'maplibre-gl';
6
+ import maplibre from 'maplibre-gl';
7
+ const { Map } = maplibre;
7
8
 
8
9
  // Props
9
10
  let {
@@ -39,7 +40,7 @@
39
40
 
40
41
  const style = getMapStyle(darkMode, styleOptions);
41
42
  style.transition = { duration: 0, delay: 0 };
42
- map = new MaplibreMap({
43
+ map = new Map({
43
44
  container,
44
45
  style,
45
46
  renderWorldCopies: false,
@@ -1,7 +1,6 @@
1
1
  <!-- LocatorMap.svelte -->
2
2
  <script lang="ts">
3
3
  import type { Map as MaplibreMapType, GeoJSONSource } from 'maplibre-gl';
4
- import 'maplibre-gl/dist/maplibre-gl.css';
5
4
  import BasicMap from '../BasicMap/BasicMap.svelte';
6
5
  let map: MaplibreMapType;
7
6
 
@@ -1,4 +1,3 @@
1
- import 'maplibre-gl/dist/maplibre-gl.css';
2
1
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
2
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
3
  $$bindings?: Bindings;
@@ -1,6 +1,5 @@
1
1
  <script lang="ts">
2
2
  import type { Map as MaplibreMapType } from 'maplibre-gl';
3
- import 'maplibre-gl/dist/maplibre-gl.css';
4
3
  import BasicMap from '../BasicMap/BasicMap.svelte';
5
4
  import { onMount } from 'svelte';
6
5
  import Sidebar from './components/Sidebar.svelte';
@@ -1,4 +1,3 @@
1
- import 'maplibre-gl/dist/maplibre-gl.css';
2
1
  declare const MapEditor: import("svelte").Component<Record<string, never>, {}, "">;
3
2
  type MapEditor = ReturnType<typeof MapEditor>;
4
3
  export default MapEditor;
@@ -16,7 +16,7 @@
16
16
  <div class="row-input">
17
17
  <label for="pattern">Pattern:</label>
18
18
  <select id="pattern" bind:value={$pattern}>
19
- {#each fillPatterns as [index, fill]}
19
+ {#each fillPatterns as [index, fill] (index)}
20
20
  <option value={index}>{fill.name}</option>
21
21
  {/each}
22
22
  </select>
@@ -11,7 +11,7 @@
11
11
  <div class="row-input">
12
12
  <label for="dashed">Dashed:</label>
13
13
  <select id="dashed" bind:value={$dashed}>
14
- {#each dashArrays as [index, dash]}
14
+ {#each dashArrays as [index, dash] (index)}
15
15
  <option value={index}>{dash.name}</option>
16
16
  {/each}
17
17
  </select>
@@ -38,7 +38,7 @@
38
38
  <div class="modal" style="display: {open ? 'block' : 'none'};">
39
39
  <button class="close" onclick={() => (open = false)}>&#x2715;</button>
40
40
  <div class="inner">
41
- {#each symbolLibrary.asList() as symbol}
41
+ {#each symbolLibrary.asList() as symbol (symbol.index)}
42
42
  <button
43
43
  class="icon"
44
44
  onclick={() => {
@@ -3,7 +3,8 @@ export declare class Cursor {
3
3
  private readonly element;
4
4
  constructor(element: HTMLElement);
5
5
  private update;
6
- hover(increase: boolean): void;
7
- precise(increase: boolean): void;
8
- grab(increase: boolean): void;
6
+ toggleHover(id: string, add?: boolean): void;
7
+ togglePrecise(id: string, add?: boolean): void;
8
+ toggleGrab(id: string, add?: boolean): void;
9
+ isPrecise(): boolean;
9
10
  }
@@ -1,31 +1,43 @@
1
1
  export class Cursor {
2
2
  element;
3
- #hover = 0;
4
- #precise = 0;
5
- #grab = 0;
3
+ #precise = new Set(); // Priority: high
4
+ #grab = new Set(); // Priority: medium
5
+ #hover = new Set(); // Priority: low
6
6
  constructor(element) {
7
7
  this.element = element;
8
8
  this.update();
9
9
  }
10
10
  update() {
11
- if (this.#precise > 0)
11
+ if (this.#precise.size > 0)
12
12
  return (this.element.style.cursor = 'crosshair');
13
- if (this.#grab > 0)
13
+ if (this.#grab.size > 0)
14
14
  return (this.element.style.cursor = 'grab');
15
- if (this.#hover > 0)
15
+ if (this.#hover.size > 0)
16
16
  return (this.element.style.cursor = 'pointer');
17
17
  this.element.style.cursor = 'default';
18
18
  }
19
- hover(increase) {
20
- this.#hover = Math.max(0, this.#hover + (increase ? 1 : -1));
19
+ toggleHover(id, add = true) {
20
+ if (add)
21
+ this.#hover.add(id);
22
+ else
23
+ this.#hover.delete(id);
21
24
  this.update();
22
25
  }
23
- precise(increase) {
24
- this.#precise = Math.max(0, this.#precise + (increase ? 1 : -1));
26
+ togglePrecise(id, add = true) {
27
+ if (add)
28
+ this.#precise.add(id);
29
+ else
30
+ this.#precise.delete(id);
25
31
  this.update();
26
32
  }
27
- grab(increase) {
28
- this.#grab = Math.max(0, this.#grab + (increase ? 1 : -1));
33
+ toggleGrab(id, add = true) {
34
+ if (add)
35
+ this.#grab.add(id);
36
+ else
37
+ this.#grab.delete(id);
29
38
  this.update();
30
39
  }
40
+ isPrecise() {
41
+ return this.#precise.size > 0;
42
+ }
31
43
  }
@@ -68,8 +68,12 @@ export class GeometryManager {
68
68
  });
69
69
  }
70
70
  });
71
- map.on('mouseenter', 'selection_nodes', () => this.cursor.precise(true));
72
- map.on('mouseleave', 'selection_nodes', () => this.cursor.precise(false));
71
+ map.on('mouseenter', 'selection_nodes', () => {
72
+ this.cursor.togglePrecise('selection_nodes');
73
+ });
74
+ map.on('mouseleave', 'selection_nodes', () => {
75
+ this.cursor.togglePrecise('selection_nodes', false);
76
+ });
73
77
  map.on('click', (e) => {
74
78
  if (!e.originalEvent.shiftKey)
75
79
  this.selectElement(undefined);
@@ -126,7 +130,7 @@ export class GeometryManager {
126
130
  this.map.setCenter({ lng: state.map.point[0], lat: state.map.point[1] });
127
131
  }
128
132
  if (state.elements) {
129
- this.elements.set(state.elements.map((element) => {
133
+ const elements = state.elements.map((element) => {
130
134
  switch (element.type) {
131
135
  case 'marker':
132
136
  return MarkerElement.fromState(this, element);
@@ -137,7 +141,8 @@ export class GeometryManager {
137
141
  default:
138
142
  throw new Error('Unknown element type');
139
143
  }
140
- }));
144
+ });
145
+ this.elements.set(elements);
141
146
  }
142
147
  }
143
148
  catch (error) {
@@ -37,22 +37,26 @@ export class MapLayer {
37
37
  addEvents() {
38
38
  this.map.on('mouseenter', this.id, () => {
39
39
  if (this.isSelected)
40
- this.manager.cursor.grab(true);
41
- this.manager.cursor.hover(true);
40
+ this.manager.cursor.toggleGrab(this.id);
41
+ this.manager.cursor.toggleHover(this.id);
42
42
  });
43
43
  this.map.on('mouseleave', this.id, () => {
44
44
  if (this.isSelected)
45
- this.manager.cursor.grab(false);
46
- this.manager.cursor.hover(false);
45
+ this.manager.cursor.toggleGrab(this.id, false);
46
+ this.manager.cursor.toggleHover(this.id, false);
47
47
  });
48
48
  this.map.on('click', this.id, (e) => {
49
49
  this.dispatchEvent('click', e);
50
50
  if (this.isSelected)
51
- this.manager.cursor.grab(true);
52
- this.manager.cursor.hover(true);
51
+ this.manager.cursor.toggleGrab(this.id);
52
+ this.manager.cursor.toggleHover(this.id);
53
53
  e.preventDefault();
54
54
  });
55
- this.map.on('mousedown', this.id, (e) => this.dispatchEvent('mousedown', e));
55
+ this.map.on('mousedown', this.id, (e) => {
56
+ if (this.manager.cursor.isPrecise())
57
+ return;
58
+ this.dispatchEvent('mousedown', e);
59
+ });
56
60
  this.map.on('mouseup', this.id, (e) => this.dispatchEvent('mouseup', e));
57
61
  this.map.on('mousemove', this.id, (e) => this.dispatchEvent('mousemove', e));
58
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versatiles/svelte",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "build": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json && vite build && npm run package",
@@ -10,16 +10,16 @@
10
10
  "format": "prettier --write .",
11
11
  "lint": "prettier --check . && eslint --color .",
12
12
  "package": "svelte-kit sync && svelte-package && publint",
13
- "prepack": "npm run package",
13
+ "prepack": "npm run build",
14
14
  "prepublishOnly": "npm run package",
15
15
  "preview": "vite preview",
16
16
  "screenshots": "npm run build && npx tsx ./scripts/screenshots.ts && pngquant --nofs --force --ext .png screenshots/*.png && optipng -quiet screenshots/*.png",
17
- "release": "npm run build && npx vrt release-npm",
17
+ "release": "vrt release-npm",
18
18
  "test:integration": "playwright test",
19
19
  "test:unit": "vitest run",
20
20
  "test:coverage": "vitest run --coverage",
21
21
  "test": "npm run test:unit && npm run test:integration",
22
- "upgrade": "npm-check-updates -u && rm -f package-lock.json; rm -rf node_modules; npm update --save && npm install"
22
+ "upgrade": "vrt deps-upgrade"
23
23
  },
24
24
  "exports": {
25
25
  ".": {
@@ -35,46 +35,45 @@
35
35
  "!dist/BBoxMap/helpers/*"
36
36
  ],
37
37
  "peerDependencies": {
38
- "sass-embedded": "^1.83.4",
38
+ "sass-embedded": "^1.86.0",
39
39
  "svelte": "^5.0.3"
40
40
  },
41
41
  "devDependencies": {
42
- "@playwright/test": "^1.50.1",
42
+ "@playwright/test": "^1.51.1",
43
43
  "@sveltejs/adapter-static": "^3.0.8",
44
- "@sveltejs/kit": "^2.17.1",
44
+ "@sveltejs/kit": "^2.20.0",
45
45
  "@sveltejs/package": "^2.3.10",
46
46
  "@sveltejs/vite-plugin-svelte": "^5.0.3",
47
47
  "@turf/turf": "^7.2.0",
48
48
  "@types/eslint": "^9.6.1",
49
- "@types/node": "^22.13.1",
50
- "@versatiles/release-tool": "^1.2.7",
51
- "@vitest/coverage-v8": "^3.0.5",
49
+ "@types/node": "^22.13.10",
50
+ "@versatiles/release-tool": "^2.4.2",
51
+ "@vitest/coverage-v8": "^3.0.9",
52
52
  "cookie": "^1.0.2",
53
- "eslint": "^9.20.0",
54
- "eslint-config-prettier": "^10.0.1",
55
- "eslint-plugin-svelte": "^2.46.1",
53
+ "eslint": "^9.22.0",
54
+ "eslint-config-prettier": "^10.1.1",
55
+ "eslint-plugin-svelte": "^3.3.2",
56
56
  "geojson": "^0.5.0",
57
- "globals": "^15.14.0",
58
- "happy-dom": "^17.0.0",
59
- "npm-check-updates": "^17.1.14",
60
- "prettier": "^3.4.2",
57
+ "globals": "^16.0.0",
58
+ "happy-dom": "^17.4.4",
59
+ "prettier": "^3.5.3",
61
60
  "prettier-plugin-svelte": "^3.3.3",
62
- "publint": "^0.3.4",
63
- "sass": "^1.84.0",
64
- "svelte": "^5.19.9",
65
- "svelte-check": "^4.1.4",
61
+ "publint": "^0.3.9",
62
+ "sass": "^1.86.0",
63
+ "svelte": "^5.23.1",
64
+ "svelte-check": "^4.1.5",
66
65
  "svelte-preprocess": "^6.0.3",
67
- "tsx": "^4.19.2",
68
- "typescript": "^5.7.3",
69
- "typescript-eslint": "^8.23.0",
70
- "vite": "^6.1.0",
71
- "vitest": "^3.0.5"
66
+ "tsx": "^4.19.3",
67
+ "typescript": "^5.8.2",
68
+ "typescript-eslint": "^8.26.1",
69
+ "vite": "^6.2.2",
70
+ "vitest": "^3.0.9"
72
71
  },
73
72
  "svelte": "./dist/index.js",
74
73
  "types": "./dist/index.d.ts",
75
74
  "type": "module",
76
75
  "dependencies": {
77
- "@versatiles/style": "^5.2.9",
78
- "maplibre-gl": "^5.1.0"
76
+ "@versatiles/style": "^5.6.0",
77
+ "maplibre-gl": "^5.2.0"
79
78
  }
80
79
  }