Skip to content

Commit 212e61d

Browse files
Kocaljaviereguiluz
authored andcommitted
[Map] Create Map component
1 parent c1befad commit 212e61d

File tree

115 files changed

+5151
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+5151
-9
lines changed

.github/build-packages.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Symfony\Component\Finder\Finder;
1010

1111
$finder = (new Finder())
12-
->in(__DIR__.'/../src/*/')
12+
->in([__DIR__.'/../src/*/', __DIR__.'/../src/*/src/Bridge/*/'])
1313
->depth(0)
1414
->name('composer.json')
1515
;
@@ -44,6 +44,18 @@
4444
$key = isset($packageData['require']['symfony/stimulus-bundle']) ? 'require' : 'require-dev';
4545
$packageData[$key]['symfony/stimulus-bundle'] = '@dev';
4646
}
47+
48+
if (isset($packageData['require']['symfony/ux-map'])
49+
|| isset($packageData['require-dev']['symfony/ux-map'])
50+
) {
51+
$repositories[] = [
52+
'type' => 'path',
53+
'url' => '../../../',
54+
];
55+
$key = isset($packageData['require']['symfony/ux-map']) ? 'require' : 'require-dev';
56+
$packageData[$key]['symfony/ux-map'] = '@dev';
57+
}
58+
4759
if ($repositories) {
4860
$packageData['repositories'] = $repositories;
4961
}

.github/workflows/test.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171

7272
- id: components
7373
run: |
74-
components=$(tree src -J -d -L 1 | jq -c '.[0].contents | map(.name)')
74+
components=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -printf '%h\n' | jq -R -s -c 'split("\n")[:-1] | map(. | sub("^src/";"")) | sort')
7575
echo "$components"
7676
echo "components=$components" >> $GITHUB_OUTPUT
7777
@@ -89,6 +89,12 @@ jobs:
8989
dependency-version: 'highest'
9090
component: ${{ fromJson(needs.tests-php-components.outputs.components )}}
9191
exclude:
92+
- component: Map # does not support PHP 8.1
93+
php-version: '8.1'
94+
- component: Map/src/Bridge/Google # does not support PHP 8.1
95+
php-version: '8.1'
96+
- component: Map/src/Bridge/Leaflet # does not support PHP 8.1
97+
php-version: '8.1'
9298
- component: Swup # has no tests
9399
- component: Turbo # has its own workflow (test-turbo.yml)
94100
- component: Typed # has no tests

bin/build_javascript.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const files = [
2121
// custom handling for StimulusBundle
2222
'src/StimulusBundle/assets/src/loader.ts',
2323
'src/StimulusBundle/assets/src/controllers.ts',
24+
// custom handling for Bridge
25+
...glob.sync('src/*/src/Bridge/*/assets/src/*controller.ts'),
2426
...glob.sync('src/*/assets/src/*controller.ts'),
2527
];
2628

biome.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
{
22
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
33
"files": {
4-
"include": ["src/*/assets/src/**", "src/*/assets/test/**", "src/*/*.json", "src/*/*/md", "*.json", "*.md"],
4+
"include": [
5+
"*.json",
6+
"*.md",
7+
"src/*/*.json",
8+
"src/*/*/md",
9+
"src/*/assets/src/**",
10+
"src/*/assets/test/**",
11+
"src/*/src/Bridge/*.json",
12+
"src/*/src/Bridge/*.md",
13+
"src/*/src/Bridge/*/assets/src/**",
14+
"src/*/src/Bridge/*/assets/test/**"
15+
],
516
"ignore": ["**/composer.json", "**/vendor", "**/node_modules"]
617
},
718
"linter": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"workspaces": ["src/*/assets"],
3+
"workspaces": ["src/*/assets", "src/*/src/Bridge/*/assets"],
44
"scripts": {
55
"build": "node bin/build_javascript.js && node bin/build_styles.js",
66
"test": "bin/run-vitest-all.sh",

rollup.config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ const wildcardExternalsPlugin = (peerDependencies) => ({
4646
const moveTypescriptDeclarationsPlugin = (packagePath) => ({
4747
name: 'move-ts-declarations',
4848
writeBundle: async () => {
49-
const files = glob.sync(path.join(packagePath, 'dist', '*', 'assets', 'src', '**/*.d.ts'));
49+
const isBridge = packagePath.includes('src/Bridge');
50+
const globPattern = isBridge
51+
? path.join(packagePath, 'dist', packagePath.replace(/^src\//, ''), '**/*.d.ts')
52+
: path.join(packagePath, 'dist', '*', 'assets', 'src', '**/*.d.ts')
53+
const files = glob.sync(globPattern);
5054
files.forEach((file) => {
51-
// a bit odd, but remove first 7 directories, which will leave
55+
// a bit odd, but remove first 7 or 13 directories, which will leave
5256
// only the relative path to the file
53-
const relativePath = file.split('/').slice(7).join('/');
57+
const relativePath = file.split('/').slice(isBridge ? 13 : 7).join('/');
5458

5559
const targetFile = path.join(packagePath, 'dist', relativePath);
5660
if (!fs.existsSync(path.dirname(targetFile))) {

src/Map/.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.symfony.bundle.yaml export-ignore
4+
/phpunit.xml.dist export-ignore
5+
/assets/src export-ignore
6+
/assets/test export-ignore
7+
/assets/vitest.config.js export-ignore
8+
/tests export-ignore

src/Map/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor
2+
composer.lock
3+
.phpunit.result.cache

src/Map/.symfony.bundle.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
branches: ["2.x"]
2+
maintained_branches: ["2.x"]
3+
doc_dir: "doc"

src/Map/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## Unreleased
4+
5+
- Component added

src/Map/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2024-present Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

src/Map/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Symfony UX Map
2+
3+
**EXPERIMENTAL** This component is currently experimental and is
4+
likely to change, or even change drastically.
5+
6+
Symfony UX Map integrates interactive Maps in Symfony applications, like Leaflet or Google Maps.
7+
8+
**This repository is a READ-ONLY sub-tree split**. See
9+
https://github.com/symfony/ux to create issues or submit pull requests.
10+
11+
## Resources
12+
13+
- [Documentation](https://symfony.com/bundles/ux-map/current/index.html)
14+
- [Report issues](https://github.com/symfony/ux/issues) and
15+
[send Pull Requests](https://github.com/symfony/ux/pulls)
16+
in the [main Symfony UX repository](https://github.com/symfony/ux)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Controller } from '@hotwired/stimulus';
2+
export type Point = {
3+
lat: number;
4+
lng: number;
5+
};
6+
export type MapView<Options, MarkerOptions, InfoWindowOptions> = {
7+
center: Point;
8+
zoom: number;
9+
fitBoundsToMarkers: boolean;
10+
markers: Array<MarkerDefinition<MarkerOptions, InfoWindowOptions>>;
11+
options: Options;
12+
};
13+
export type MarkerDefinition<MarkerOptions, InfoWindowOptions> = {
14+
position: Point;
15+
title: string | null;
16+
infoWindow?: Omit<InfoWindowDefinition<InfoWindowOptions>, 'position'>;
17+
rawOptions?: MarkerOptions;
18+
};
19+
export type InfoWindowDefinition<InfoWindowOptions> = {
20+
headerContent: string | null;
21+
content: string | null;
22+
position: Point;
23+
opened: boolean;
24+
autoClose: boolean;
25+
rawOptions?: InfoWindowOptions;
26+
};
27+
export default abstract class<MapOptions, Map, MarkerOptions, Marker, InfoWindowOptions, InfoWindow> extends Controller<HTMLElement> {
28+
static values: {
29+
providerOptions: ObjectConstructor;
30+
view: ObjectConstructor;
31+
};
32+
viewValue: MapView<MapOptions, MarkerOptions, InfoWindowOptions>;
33+
protected map: Map;
34+
protected markers: Array<Marker>;
35+
protected infoWindows: Array<InfoWindow>;
36+
initialize(): void;
37+
connect(): void;
38+
protected abstract doCreateMap({ center, zoom, options, }: {
39+
center: Point;
40+
zoom: number;
41+
options: MapOptions;
42+
}): Map;
43+
createMarker(definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>): Marker;
44+
protected abstract doCreateMarker(definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>): Marker;
45+
protected createInfoWindow({ definition, marker, }: {
46+
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
47+
marker: Marker;
48+
}): InfoWindow;
49+
protected abstract doCreateInfoWindow({ definition, marker, }: {
50+
definition: MarkerDefinition<MarkerOptions, InfoWindowOptions>['infoWindow'];
51+
marker: Marker;
52+
}): InfoWindow;
53+
protected abstract doFitBoundsToMarkers(): void;
54+
private dispatchEvent;
55+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Controller } from '@hotwired/stimulus';
2+
3+
class default_1 extends Controller {
4+
constructor() {
5+
super(...arguments);
6+
this.markers = [];
7+
this.infoWindows = [];
8+
}
9+
initialize() { }
10+
connect() {
11+
const { center, zoom, options, markers, fitBoundsToMarkers } = this.viewValue;
12+
this.dispatchEvent('pre-connect', { options });
13+
this.map = this.doCreateMap({ center, zoom, options });
14+
markers.forEach((marker) => this.createMarker(marker));
15+
if (fitBoundsToMarkers) {
16+
this.doFitBoundsToMarkers();
17+
}
18+
this.dispatchEvent('connect', {
19+
map: this.map,
20+
markers: this.markers,
21+
infoWindows: this.infoWindows,
22+
});
23+
}
24+
createMarker(definition) {
25+
this.dispatchEvent('marker:before-create', { definition });
26+
const marker = this.doCreateMarker(definition);
27+
this.dispatchEvent('marker:after-create', { marker });
28+
this.markers.push(marker);
29+
return marker;
30+
}
31+
createInfoWindow({ definition, marker, }) {
32+
this.dispatchEvent('info-window:before-create', { definition, marker });
33+
const infoWindow = this.doCreateInfoWindow({ definition, marker });
34+
this.dispatchEvent('info-window:after-create', { infoWindow, marker });
35+
this.infoWindows.push(infoWindow);
36+
return infoWindow;
37+
}
38+
dispatchEvent(name, payload = {}) {
39+
this.dispatch(name, { prefix: 'ux:map', detail: payload });
40+
}
41+
}
42+
default_1.values = {
43+
providerOptions: Object,
44+
view: Object,
45+
};
46+
47+
export { default_1 as default };

src/Map/assets/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@symfony/ux-map",
3+
"description": "Integrates interactive maps in your Symfony applications",
4+
"license": "MIT",
5+
"version": "1.0.0",
6+
"type": "module",
7+
"main": "dist/abstract_map_controller.js",
8+
"types": "dist/abstract_map_controller.d.ts",
9+
"symfony": {
10+
"importmap": {
11+
"@hotwired/stimulus": "^3.0.0",
12+
"@symfony/ux-map/abstract-map-controller": "path:%PACKAGE%/dist/abstract_map_controller.js"
13+
}
14+
},
15+
"peerDependencies": {
16+
"@hotwired/stimulus": "^3.0.0"
17+
},
18+
"devDependencies": {
19+
"@hotwired/stimulus": "^3.0.0"
20+
}
21+
}

0 commit comments

Comments
 (0)