Skip to content

Commit 1744944

Browse files
committed
.
1 parent c8830d1 commit 1744944

File tree

3 files changed

+213
-20
lines changed

3 files changed

+213
-20
lines changed

.github/workflows/dist-files-size-diff.yaml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,42 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15+
- name: Configure git
16+
run: |
17+
git config --global user.email ""
18+
git config --global user.name "github-action[bot]"
19+
1520
- uses: marocchino/sticky-pull-request-comment@v2
1621
with:
1722
message: |
1823
⏳ The dist files size difference is being calculated...
19-
24+
2025
- uses: actions/checkout@v4
21-
22-
- uses: actions/setup-node@v4
2326
with:
24-
node-version: '22'
25-
26-
- name: Configure git
27-
run: |
28-
git config --global user.email ""
29-
git config --global user.name "github-action[bot]"
27+
ref: ${{ github.base_ref }}
3028

31-
- name: Get dist files size (from pull request)
32-
id: pr-dist-files
29+
- name: Get dist files size (from base branch)
30+
id: base-dist-files
3331
run: |
3432
set -e
35-
33+
3634
FILES=$(find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' -o -path '*/vendor/*' \) | sort | while read -r file; do
3735
echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}"
3836
done | jq -s 'add' -c)
39-
37+
4038
echo "files=$FILES" >> $GITHUB_OUTPUT
4139
42-
- name: Get dist files size (from base branch)
43-
id: base-dist-files
40+
- uses: actions/checkout@v4
41+
42+
- name: Get dist files size (from pull request)
43+
id: pr-dist-files
4444
run: |
4545
set -e
46-
47-
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
48-
46+
4947
FILES=$(find src -mindepth 2 -path '*/assets/dist/*' \( -name "*.js" -o -name "*.css" \) -not \( -path '*/tests/*' -o -path '*/public/*' -o -path '*/vendor/*' \) | sort | while read -r file; do
5048
echo "{\"$file\": {\"size\": $(wc -c < "$file"), \"size_gz\": $(gzip -c "$file" | wc -c), \"size_brotli\": $(brotli -c "$file" | wc -c)}}"
5149
done | jq -s 'add' -c)
52-
50+
5351
echo "files=$FILES" >> $GITHUB_OUTPUT
5452
5553
- name: Generate the diff
@@ -63,7 +61,7 @@ jobs:
6361
script: |
6462
const { main } = await import('${{ github.workspace }}/.github/generate-dist-files-size-diff.mjs')
6563
66-
return await(main())
64+
return await main()
6765
6866
- name: Comment on the pull request (if any failure)
6967
if: ${{ failure() }}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Controller } from '@hotwired/stimulus';
2+
import { registerables, Chart } from 'chart.js';
3+
4+
if (registerables) {
5+
Chart.register(...registerables);
6+
}
7+
let isChartInitialized = false;
8+
class default_1 extends Controller {
9+
constructor() {
10+
super(...arguments);
11+
this.chart = null;
12+
}
13+
connect() {
14+
if (!isChartInitialized) {
15+
isChartInitialized = true;
16+
this.dispatchEvent('init', {
17+
Chart,
18+
});
19+
}
20+
if (!(this.element instanceof HTMLCanvasElement)) {
21+
throw new Error('Invalid element');
22+
}
23+
const payload = this.viewValue;
24+
if (Array.isArray(payload.options) && 0 === payload.options.length) {
25+
payload.options = {};
26+
}
27+
this.dispatchEvent('pre-connect', {
28+
options: payload.options,
29+
config: payload,
30+
});
31+
const canvasContext = this.element.getContext('2d');
32+
if (!canvasContext) {
33+
throw new Error('Could not getContext() from Element');
34+
}
35+
this.chart = new Chart(canvasContext, payload);
36+
this.dispatchEvent('connect', { chart: this.chart });
37+
}
38+
viewValueChanged() {
39+
if (this.chart) {
40+
const viewValue = { data: this.viewValue.data, options: this.viewValue.options };
41+
if (Array.isArray(viewValue.options) && 0 === viewValue.options.length) {
42+
viewValue.options = {};
43+
}
44+
this.dispatchEvent('view-value-change', viewValue);
45+
this.chart.data = viewValue.data;
46+
this.chart.options = viewValue.options;
47+
this.chart.update();
48+
const parentElement = this.element.parentElement;
49+
if (parentElement && this.chart.options.responsive) {
50+
const originalWidth = parentElement.style.width;
51+
parentElement.style.width = `${parentElement.offsetWidth + 1}px`;
52+
setTimeout(() => {
53+
parentElement.style.width = originalWidth;
54+
}, 0);
55+
}
56+
}
57+
}
58+
dispatchEvent(name, payload) {
59+
this.dispatch(name, { detail: payload, prefix: 'chartjs' });
60+
}
61+
}
62+
default_1.values = {
63+
view: Object,
64+
};
65+
66+
export { default_1 as default };
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { Controller } from '@hotwired/stimulus';
2+
import 'leaflet/dist/leaflet.min.css';
3+
import * as L from 'leaflet';
4+
5+
class default_1 extends Controller {
6+
constructor() {
7+
super(...arguments);
8+
this.markers = [];
9+
this.infoWindows = [];
10+
this.polygons = [];
11+
}
12+
connect() {
13+
const { center, zoom, options, markers, polygons, fitBoundsToMarkers } = this.viewValue;
14+
this.dispatchEvent('pre-connect', { options });
15+
this.map = this.doCreateMap({ center, zoom, options });
16+
markers.forEach((marker) => this.createMarker(marker));
17+
polygons.forEach((polygon) => this.createPolygon(polygon));
18+
if (fitBoundsToMarkers) {
19+
this.doFitBoundsToMarkers();
20+
}
21+
this.dispatchEvent('connect', {
22+
map: this.map,
23+
markers: this.markers,
24+
polygons: this.polygons,
25+
infoWindows: this.infoWindows,
26+
});
27+
}
28+
createMarker(definition) {
29+
this.dispatchEvent('marker:before-create', { definition });
30+
const marker = this.doCreateMarker(definition);
31+
this.dispatchEvent('marker:after-create', { marker });
32+
this.markers.push(marker);
33+
return marker;
34+
}
35+
createPolygon(definition) {
36+
this.dispatchEvent('polygon:before-create', { definition });
37+
const polygon = this.doCreatePolygon(definition);
38+
this.dispatchEvent('polygon:after-create', { polygon });
39+
this.polygons.push(polygon);
40+
return polygon;
41+
}
42+
createInfoWindow({ definition, element, }) {
43+
this.dispatchEvent('info-window:before-create', { definition, element });
44+
const infoWindow = this.doCreateInfoWindow({ definition, element });
45+
this.dispatchEvent('info-window:after-create', { infoWindow, element });
46+
this.infoWindows.push(infoWindow);
47+
return infoWindow;
48+
}
49+
}
50+
default_1.values = {
51+
providerOptions: Object,
52+
view: Object,
53+
};
54+
55+
class map_controller extends default_1 {
56+
connect() {
57+
L.Marker.prototype.options.icon = L.divIcon({
58+
html: '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" fill-rule="evenodd" stroke-linecap="round" clip-rule="evenodd" viewBox="0 0 500 820"><defs><linearGradient id="__sf_ux_map_gradient_marker_fill" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -37.57 37.57 0 416.45 541)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#126FC6"/><stop offset="1" stop-color="#4C9CD1"/></linearGradient><linearGradient id="__sf_ux_map_gradient_marker_border" x1="0" x2="1" y1="0" y2="0" gradientTransform="matrix(0 -19.05 19.05 0 414.48 522.49)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#2E6C97"/><stop offset="1" stop-color="#3883B7"/></linearGradient></defs><circle cx="252.31" cy="266.24" r="83.99" fill="#fff"/><path fill="url(#__sf_ux_map_gradient_marker_fill)" stroke="url(#__sf_ux_map_gradient_marker_border)" stroke-width="1.1" d="M416.54 503.61c-6.57 0-12.04 5.7-12.04 11.87 0 2.78 1.56 6.3 2.7 8.74l9.3 17.88 9.26-17.88c1.13-2.43 2.74-5.79 2.74-8.74 0-6.18-5.38-11.87-11.96-11.87Zm0 7.16a4.69 4.69 0 1 1-.02 9.4 4.69 4.69 0 0 1 .02-9.4Z" transform="translate(-7889.1 -9807.44) scale(19.54)"/></svg>',
59+
iconSize: [25, 41],
60+
iconAnchor: [12.5, 41],
61+
popupAnchor: [0, -41],
62+
className: '',
63+
});
64+
super.connect();
65+
}
66+
dispatchEvent(name, payload = {}) {
67+
this.dispatch(name, {
68+
prefix: 'ux:map',
69+
detail: {
70+
...payload,
71+
L,
72+
},
73+
});
74+
}
75+
doCreateMap({ center, zoom, options, }) {
76+
const map = L.map(this.element, {
77+
...options,
78+
center: center === null ? undefined : center,
79+
zoom: zoom === null ? undefined : zoom,
80+
});
81+
L.tileLayer(options.tileLayer.url, {
82+
attribution: options.tileLayer.attribution,
83+
...options.tileLayer.options,
84+
}).addTo(map);
85+
return map;
86+
}
87+
doCreateMarker(definition) {
88+
const { position, title, infoWindow, extra, rawOptions = {}, ...otherOptions } = definition;
89+
const marker = L.marker(position, { title, ...otherOptions, ...rawOptions }).addTo(this.map);
90+
if (infoWindow) {
91+
this.createInfoWindow({ definition: infoWindow, element: marker });
92+
}
93+
return marker;
94+
}
95+
doCreatePolygon(definition) {
96+
const { points, title, infoWindow, rawOptions = {} } = definition;
97+
const polygon = L.polygon(points, { ...rawOptions }).addTo(this.map);
98+
if (title) {
99+
polygon.bindPopup(title);
100+
}
101+
if (infoWindow) {
102+
this.createInfoWindow({ definition: infoWindow, element: polygon });
103+
}
104+
return polygon;
105+
}
106+
doCreateInfoWindow({ definition, element, }) {
107+
const { headerContent, content, rawOptions = {}, ...otherOptions } = definition;
108+
element.bindPopup([headerContent, content].filter((x) => x).join('<br>'), { ...otherOptions, ...rawOptions });
109+
if (definition.opened) {
110+
element.openPopup();
111+
}
112+
const popup = element.getPopup();
113+
if (!popup) {
114+
throw new Error('Unable to get the Popup associated with the element.');
115+
}
116+
return popup;
117+
}
118+
doFitBoundsToMarkers() {
119+
if (this.markers.length === 0) {
120+
return;
121+
}
122+
this.map.fitBounds(this.markers.map((marker) => {
123+
const position = marker.getLatLng();
124+
return [position.lat, position.lng];
125+
}));
126+
}
127+
}
128+
129+
export { map_controller as default };

0 commit comments

Comments
 (0)