@asteby/metacore-maps 0.0.0-stage → 0.1.1

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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Asteby, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,122 @@
1
- # Temporary Holding Version
1
+ # @asteby/metacore-maps
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lazy maps for the metacore ERP and its addons. One package, three jobs:
4
+
5
+ - **Components** — `MapView`, `Marker`, `ClusterLayer`, `Polyline`/`Route`, `Geofence`, `LocationPicker`, `TrackingTimeline`.
6
+ - **Declarative renderers** — `view_type: map` and `kind: map | timeline` detail panels of the kernel's manifest, registered in `@asteby/metacore-runtime-react`'s registry.
7
+ - **No lock-in, no keys** — [MapLibre GL](https://maplibre.org) renders; the base map is a style (or PMTiles) **URL your host serves**. No API key, no third party seeing your customers' locations.
8
+
9
+ Performance contract (plan §0.2): the package's own initial chunk is **~11 KB gzip** (enforced by `src/size-budget.test.ts`, limit 15 KB) and `maplibre-gl` is **never** in a static import graph — it is fetched the first time a map mounts. The registration entry (`/register`) is under 1 KB, so a host that never shows a map pays almost nothing.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pnpm add @asteby/metacore-maps maplibre-gl
15
+ # optional, only for pmtiles:// base maps
16
+ pnpm add pmtiles
17
+ ```
18
+
19
+ `react`, `maplibre-gl` and (for the renderers) `@asteby/metacore-runtime-react`, `@asteby/metacore-sdk`, `react-i18next` are peers. In a federated page `@asteby/metacore-maps` and `maplibre-gl` are lazy shares (`METACORE_PAGE_SHARES`): the remote never bundles its own copy.
20
+
21
+ ## Configure the base map (once, in the host)
22
+
23
+ ```ts
24
+ import { configureMaps } from '@asteby/metacore-maps'
25
+
26
+ configureMaps({
27
+ style: {
28
+ light: 'https://cdn.example.com/map/light.json', // style JSON URL, or an inline style object
29
+ dark: 'https://cdn.example.com/map/dark.json',
30
+ },
31
+ // PMTiles (self-hosted, range requests, no key): style sources use `pmtiles://https://…/mx.pmtiles`.
32
+ pmtiles: () => import('pmtiles'),
33
+ attribution: '© OpenStreetMap contributors', // credit for the data in the tiles you serve
34
+ center: [-102.5, 23.6], zoom: 4, // used when there is nothing to fit
35
+ })
36
+ ```
37
+
38
+ Without `style` the map draws on a plain themed background (your points, routes and zones still render) and makes **no** network request besides MapLibre itself. Helpers: `blankStyle(scheme)`, `rasterStyle(['https://tiles/{z}/{x}/{y}.png'], attribution)`.
39
+
40
+ The colour scheme follows the host (`.dark` class / `data-theme="dark"` on `<html>`, then the OS); pass `theme="light|dark"` to pin it. Layers survive a theme switch.
41
+
42
+ ## Components
43
+
44
+ ```tsx
45
+ import { MapView, Route, Geofence, LocationPicker, TrackingTimeline } from '@asteby/metacore-maps'
46
+
47
+ // Points with popups (focusable markers; clusters automatically above 150 points)
48
+ <MapView
49
+ ariaLabel="Envíos activos"
50
+ points={[
51
+ { key: 's1', lat: 19.43, lng: -99.13, label: 'TRK-1', status: 'in_transit', statusLabel: 'En tránsito',
52
+ details: [{ label: 'Paquetería', value: 'DHL' }] },
53
+ ]}
54
+ colors={{ in_transit: '#0072B2' }}
55
+ onSelect={(p) => console.log(p.key)}
56
+ >
57
+ {/* layers and extra markers are children */}
58
+ <Route path={[{ lat: 19.4, lng: -99.1 }, { lat: 19.9, lng: -100.2 }]} fit />
59
+ <Geofence zones={[{ key: 'z', label: 'Cobertura', center: { lat: 19.43, lng: -99.13 }, radiusM: 5000 }]} />
60
+ </MapView>
61
+
62
+ // Pick a place: click, drag the pin, type coordinates, device GPS, optional address search
63
+ <LocationPicker value={point} onChange={setPoint} geocode={(q) => api.geocode(q)} />
64
+
65
+ // Shipment tracking — no map required
66
+ <TrackingTimeline
67
+ events={[{ status: 'En tránsito', at: '2026-10-17T09:00:00Z', location: { label: 'Querétaro', lat: 20.59, lng: -100.39 } }]}
68
+ timeZone="America/Mexico_City"
69
+ />
70
+ ```
71
+
72
+ | Export | What it does |
73
+ |---|---|
74
+ | `MapView` | Container + lazy MapLibre. Props: `points`, `cluster`, `colors`, `fit`, `theme`, `mapStyle`, `height`, `labels`, `selectedKey`, `onSelect`, `onMapClick`, `listExtra`, children. |
75
+ | `Marker` | Focusable DOM marker (`aria-label`, glyph, popup children, `draggable`). A few hundred at most. |
76
+ | `ClusterLayer` | WebGL points with native clustering for thousands of features. |
77
+ | `Polyline` / `Route` | Line over ordered points; `Route` adds numbered stops. Straight segments — no routing service needed. |
78
+ | `Geofence` | Polygons and circles (`center` + `radiusM`). |
79
+ | `LocationPicker` | Map + labelled latitude/longitude inputs (the accessible path) + GPS + optional geocoder. |
80
+ | `TrackingTimeline` | Status / time / place events, with state spelled out in words. Helpers `toTrackingEvents`, `sortTrackingEvents`. |
81
+ | `MapList` | The list equivalent of a map (used by `MapView`). |
82
+ | `configureMaps`, `loadMaplibre`, `useMap`, `useMapScheme` | Host config, the shared lazy loader, and hooks for custom layers. |
83
+ | `distanceKm`, `formatDistance`, `isValidPoint`, `parseLatLng`, `directionsUrl` | Re-exported from `@asteby/storefront/geo` — the one geo module shared with the storefronts. |
84
+
85
+ ### Accessibility
86
+
87
+ - Every map has an equivalent **list** ("Ver lista"), keyboard reachable, with each status written out and an "open in map" link. When WebGL or MapLibre are unavailable the list is the only view and a message says so.
88
+ - Markers are buttons with `aria-label`; colour is never the only channel (status text, glyphs); popups are built from text nodes (no HTML injection).
89
+ - `prefers-reduced-motion` makes `fitBounds` / `easeTo` instant. Strings are overridable through `labels` (and `metacore.maps.*` keys in the renderers).
90
+
91
+ ## Declarative views (kernel contract)
92
+
93
+ ```ts
94
+ // host start-up — tiny and MapLibre-free
95
+ import { registerMapRenderers } from '@asteby/metacore-maps/register'
96
+
97
+ registerMapRenderers({ config: { style: { light: '…', dark: '…' } } })
98
+ ```
99
+
100
+ This calls `registerViewRenderer('map', …)`, `registerPanelRenderer('map', …)` and `registerPanelRenderer('timeline', …)` with lazy loaders (`/view`, `/panel`, `/timeline-panel`). Pass `{ timeline: false }` to keep the runtime's built-in timeline panel. Manifest fragments it renders:
101
+
102
+ ```jsonc
103
+ { "view_type": "map",
104
+ "view": { "map": { "point": { "lat": "dest_lat", "lng": "dest_lng" }, "color_by": "status",
105
+ "popup": ["tracking_number", "carrier", "status"], "cluster": true,
106
+ "layers": [{ "kind": "points", "model": "Branch", "point": { "lat": "lat", "lng": "lng" }, "label": "name" },
107
+ { "kind": "zones", "model": "Zone", "geometry": "area", "label": "name" }] } } }
108
+
109
+ { "kind": "map", "map": { "point": {…}, "route": { "relation": "stops", "point": {…}, "order_by": "seq" } } }
110
+ { "kind": "timeline", "timeline": { "date_field": "at", "title_field": "description", "status_field": "status",
111
+ "source": { "capability": "commerce.shipping.track", "input": { "tracking_number": "record.tracking_number" }, "items": "events" } } }
112
+ ```
113
+
114
+ Rows become features through the same pure helpers the runtime uses for its list fallback (`@asteby/metacore-runtime-react/views/map`), so both renderers read the manifest identically. Option colours and labels of the `color_by` column come from the model metadata; renderers display what the server returns and never compute business values. Timeline events pick up `location`/`city` and `lat`/`lng` columns when present.
115
+
116
+ ## Testing
117
+
118
+ jsdom/happy-dom have no WebGL. In your own tests pass a stub through the loader:
119
+
120
+ ```ts
121
+ configureMaps({ loadMaplibre: async () => myStub, supportsWebGL: () => true })
122
+ ```
@@ -0,0 +1,64 @@
1
+ import { useMapLabels, useTimelineLabels } from './chunk-V53ZKCMA.js';
2
+ import { toTrackingEvents, TrackingTimeline } from './chunk-ZGR7H4XP.js';
3
+ import * as React from 'react';
4
+ import { pickItems, resolveCapabilityInput, buildRelationFilterParams } from '@asteby/metacore-runtime-react';
5
+ import { jsx } from 'react/jsx-runtime';
6
+
7
+ var first = (rows, keys) => keys.find((k) => rows.some((r) => r[k] !== void 0 && r[k] !== null));
8
+ function TimelinePanelRenderer({ panel, record, metadata, data, locale, timeZone }) {
9
+ const view = panel.timeline;
10
+ const source = view?.source;
11
+ const labels = useMapLabels();
12
+ const tl = useTimelineLabels();
13
+ const [rows, setRows] = React.useState(null);
14
+ const [error, setError] = React.useState(false);
15
+ const recordId = record.id;
16
+ const sig = JSON.stringify([source, recordId]);
17
+ React.useEffect(() => {
18
+ if (!view || !source) return;
19
+ let cancelled = false;
20
+ setRows(null);
21
+ setError(false);
22
+ const run = async () => {
23
+ if (source.capability) {
24
+ return pickItems(await data.capability(source.capability, resolveCapabilityInput(source.input, record)), source.items);
25
+ }
26
+ if (source.relation) {
27
+ const rel = metadata?.relations?.find((r) => r.name === source.relation);
28
+ if (!rel || recordId === void 0 || recordId === null) return [];
29
+ const res = await data.list(rel.through, { ...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope), per_page: 50, sortBy: view.date_field, order: "desc" });
30
+ return res.rows;
31
+ }
32
+ return [];
33
+ };
34
+ run().then(
35
+ (r) => !cancelled && setRows(r),
36
+ () => !cancelled && setError(true)
37
+ );
38
+ return () => {
39
+ cancelled = true;
40
+ };
41
+ }, [data, sig, metadata]);
42
+ const events = React.useMemo(() => {
43
+ if (!view || !rows) return [];
44
+ const fields = {
45
+ status: view.status_field ?? view.title_field,
46
+ at: view.date_field,
47
+ description: view.status_field ? view.title_field : view.description_field,
48
+ location: first(rows, ["location", "city", "place"]),
49
+ lat: first(rows, ["lat", "latitude"]),
50
+ lng: first(rows, ["lng", "lon", "longitude"])
51
+ };
52
+ return toTrackingEvents(rows, fields);
53
+ }, [view, rows]);
54
+ if (!view) return null;
55
+ if (error) {
56
+ return /* @__PURE__ */ jsx("p", { role: "alert", style: { fontSize: 14 }, children: labels.unavailable });
57
+ }
58
+ if (!rows) return /* @__PURE__ */ jsx("div", { role: "status", "aria-busy": "true", "aria-label": labels.loading, style: { height: 120 } });
59
+ return /* @__PURE__ */ jsx(TrackingTimeline, { events, locale, timeZone, labels: tl });
60
+ }
61
+
62
+ export { TimelinePanelRenderer };
63
+ //# sourceMappingURL=chunk-5GYJRCOR.js.map
64
+ //# source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A;AAAA,MACT,WAAA,EAAa,IAAA,CAAK,YAAA,GAAe,IAAA,CAAK,cAAc,IAAA,CAAK,iBAAA;AAAA,MACzD,UAAU,KAAA,CAAM,IAAA,EAAM,CAAC,UAAA,EAAY,MAAA,EAAQ,OAAO,CAAC,CAAA;AAAA,MACnD,KAAK,KAAA,CAAM,IAAA,EAAM,CAAC,KAAA,EAAO,UAAU,CAAC,CAAA;AAAA,MACpC,KAAK,KAAA,CAAM,IAAA,EAAM,CAAC,KAAA,EAAO,KAAA,EAAO,WAAW,CAAC;AAAA,KAChD;AACA,IAAA,OAAO,gBAAA,CAAiB,MAAM,MAAM,CAAA;AAAA,EACxC,CAAA,EAAG,CAAC,IAAA,EAAM,IAAI,CAAC,CAAA;AAEf,EAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAClB,EAAA,IAAI,KAAA,EAAO;AACP,IAAA,uBACI,GAAA,CAAC,GAAA,EAAA,EAAE,IAAA,EAAK,OAAA,EAAQ,KAAA,EAAO,EAAE,QAAA,EAAU,EAAA,EAAG,EACjC,QAAA,EAAA,MAAA,CAAO,WAAA,EACZ,CAAA;AAAA,EAER;AACA,EAAA,IAAI,CAAC,IAAA,EAAM,uBAAO,GAAA,CAAC,KAAA,EAAA,EAAI,MAAK,QAAA,EAAS,WAAA,EAAU,MAAA,EAAO,YAAA,EAAY,OAAO,OAAA,EAAS,KAAA,EAAO,EAAE,MAAA,EAAQ,KAAI,EAAG,CAAA;AAC1G,EAAA,2BAAQ,gBAAA,EAAA,EAAiB,MAAA,EAAgB,MAAA,EAAgB,QAAA,EAAoB,QAAQ,EAAA,EAAI,CAAA;AAC7F","file":"chunk-5GYJRCOR.js","sourcesContent":["// `kind: timeline` detail panel: the record's tracking events (child rows of a\n// relation, or the `items` of a capability such as `commerce.shipping.track`).\n// Shown as a TrackingTimeline: status, time and — when the events carry\n// `lat`/`lng` or a location text — the place, with an \"open in map\" link.\nimport * as React from 'react'\nimport { buildRelationFilterParams, pickItems, resolveCapabilityInput, type PanelRendererProps } from '@asteby/metacore-runtime-react'\nimport { toTrackingEvents, TrackingTimeline, type TrackingFieldMap } from '../tracking-timeline'\nimport { useMapLabels, useTimelineLabels } from './shared'\n\nconst first = (rows: Array<Record<string, unknown>>, keys: string[]): string | undefined => keys.find((k) => rows.some((r) => r[k] !== undefined && r[k] !== null))\n\nexport default function TimelinePanelRenderer({ panel, record, metadata, data, locale, timeZone }: PanelRendererProps) {\n const view = panel.timeline\n const source = view?.source\n const labels = useMapLabels()\n const tl = useTimelineLabels()\n const [rows, setRows] = React.useState<Array<Record<string, unknown>> | null>(null)\n const [error, setError] = React.useState(false)\n const recordId = record.id\n const sig = JSON.stringify([source, recordId])\n\n React.useEffect(() => {\n if (!view || !source) return\n let cancelled = false\n setRows(null)\n setError(false)\n const run = async (): Promise<Array<Record<string, unknown>>> => {\n if (source.capability) {\n return pickItems(await data.capability(source.capability, resolveCapabilityInput(source.input, record)), source.items)\n }\n if (source.relation) {\n const rel = metadata?.relations?.find((r) => r.name === source.relation)\n if (!rel || recordId === undefined || recordId === null) return []\n const res = await data.list(rel.through, { ...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope), per_page: 50, sortBy: view.date_field, order: 'desc' })\n return res.rows\n }\n return []\n }\n run().then(\n (r) => !cancelled && setRows(r),\n () => !cancelled && setError(true),\n )\n return () => {\n cancelled = true\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [data, sig, metadata])\n\n const events = React.useMemo(() => {\n if (!view || !rows) return []\n const fields: TrackingFieldMap = {\n status: view.status_field ?? view.title_field,\n at: view.date_field,\n description: view.status_field ? view.title_field : view.description_field,\n location: first(rows, ['location', 'city', 'place']),\n lat: first(rows, ['lat', 'latitude']),\n lng: first(rows, ['lng', 'lon', 'longitude']),\n }\n return toTrackingEvents(rows, fields)\n }, [view, rows])\n\n if (!view) return null\n if (error) {\n return (\n <p role=\"alert\" style={{ fontSize: 14 }}>\n {labels.unavailable}\n </p>\n )\n }\n if (!rows) return <div role=\"status\" aria-busy=\"true\" aria-label={labels.loading} style={{ height: 120 }} />\n return <TrackingTimeline events={events} locale={locale} timeZone={timeZone} labels={tl} />\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import { MapView, Polyline } from './chunk-KWMP7YH4.js';
2
+ import { useMapLabels, MAX_FEATURES } from './chunk-V53ZKCMA.js';
3
+ import * as React from 'react';
4
+ import { buildRelationFilterParams } from '@asteby/metacore-runtime-react';
5
+ import { toRoutePoints, toMapFeatures } from '@asteby/metacore-runtime-react/views/map';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ function MapPanelRenderer({ panel, record, metadata, data, locale }) {
9
+ const labels = useMapLabels();
10
+ const view = panel.map;
11
+ const route = view?.route;
12
+ const rel = route ? metadata?.relations?.find((r) => r.name === route.relation) : void 0;
13
+ const [stops, setStops] = React.useState([]);
14
+ const recordId = record.id;
15
+ React.useEffect(() => {
16
+ if (!route || !rel || recordId === void 0 || recordId === null) return;
17
+ let cancelled = false;
18
+ data.list(rel.through, { ...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope), per_page: MAX_FEATURES, sortBy: route.order_by, order: "asc" }).then((res) => !cancelled && setStops(toRoutePoints(res.rows, route))).catch(() => void 0);
19
+ return () => {
20
+ cancelled = true;
21
+ };
22
+ }, [data, route, rel, recordId]);
23
+ const points = React.useMemo(() => {
24
+ if (!view) return [];
25
+ const stopItems = stops.map((s, i) => ({ key: `stop-${i}`, ...s, label: `${labels.point} ${i + 1}`, glyph: String(i + 1) }));
26
+ const own = toMapFeatures([record], { ...view, popup: view.popup ?? [] }).map((f) => ({
27
+ key: f.key,
28
+ lat: f.lat,
29
+ lng: f.lng,
30
+ label: f.popup[0]?.value || labels.point,
31
+ details: f.popup.slice(1).filter((p) => p.value).map((p) => ({ label: p.field, value: p.value }))
32
+ }));
33
+ return [...stopItems, ...own];
34
+ }, [view, stops, record, labels.point]);
35
+ if (!view) return null;
36
+ return /* @__PURE__ */ jsx(MapView, { points, height: 260, labels, locale, cluster: false, children: stops.length > 1 ? /* @__PURE__ */ jsx(Polyline, { path: stops }) : null });
37
+ }
38
+
39
+ export { MapPanelRenderer };
40
+ //# sourceMappingURL=chunk-BZP7NBAA.js.map
41
+ //# sourceMappingURL=chunk-BZP7NBAA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/renderers/panel.tsx"],"names":[],"mappings":";;;;;;;AASe,SAAR,iBAAkC,EAAE,KAAA,EAAO,QAAQ,QAAA,EAAU,IAAA,EAAM,QAAO,EAAuB;AACpG,EAAA,MAAM,SAAS,YAAA,EAAa;AAC5B,EAAA,MAAM,OAAO,KAAA,CAAM,GAAA;AACnB,EAAA,MAAM,QAAQ,IAAA,EAAM,KAAA;AACpB,EAAA,MAAM,GAAA,GAAM,KAAA,GAAQ,QAAA,EAAU,SAAA,EAAW,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,KAAS,KAAA,CAAM,QAAQ,CAAA,GAAI,MAAA;AAClF,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAU,KAAA,CAAA,QAAA,CAA8C,EAAE,CAAA;AAChF,EAAA,MAAM,WAAW,MAAA,CAAO,EAAA;AAExB,EAAM,gBAAU,MAAM;AAClB,IAAA,IAAI,CAAC,KAAA,IAAS,CAAC,OAAO,QAAA,KAAa,MAAA,IAAa,aAAa,IAAA,EAAM;AACnE,IAAA,IAAI,SAAA,GAAY,KAAA;AAChB,IAAA,IAAA,CACK,KAAK,GAAA,CAAI,OAAA,EAAS,EAAE,GAAG,0BAA0B,GAAA,CAAI,WAAA,EAAa,MAAA,CAAO,QAAQ,GAAG,GAAA,CAAI,KAAK,GAAG,QAAA,EAAU,YAAA,EAAc,QAAQ,KAAA,CAAM,QAAA,EAAU,KAAA,EAAO,KAAA,EAAO,CAAA,CAC9J,IAAA,CAAK,CAAC,GAAA,KAAQ,CAAC,SAAA,IAAa,QAAA,CAAS,aAAA,CAAc,GAAA,CAAI,MAAM,KA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A;AACF,IAAA,OAAO,CAAC,GAAG,SAAA,EAAW,GAAG,GAAG,CAAA;AAAA,EAChC,GAAG,CAAC,IAAA,EAAM,OAAO,MAAA,EAAQ,MAAA,CAAO,KAAK,CAAC,CAAA;AAEtC,EAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAClB,EAAA,2BACK,OAAA,EAAA,EAAQ,MAAA,EAAgB,MAAA,EAAQ,GAAA,EAAK,QAAgB,MAAA,EAAgB,OAAA,EAAS,KAAA,EAC1E,QAAA,EAAA,KAAA,CAAM,SAAS,CAAA,mBAAI,GAAA,CAAC,YAAS,IAAA,EAAM,KAAA,EAAO,IAAK,IAAA,EACpD,CAAA;AAER","file":"chunk-BZP7NBAA.js","sourcesContent":["// `kind: map` detail panel: the record's point plus its ordered route stops.\nimport * as React from 'react'\nimport { buildRelationFilterParams, type PanelRendererProps } from '@asteby/metacore-runtime-react'\nimport { toMapFeatures, toRoutePoints } from '@asteby/metacore-runtime-react/views/map'\nimport { Polyline } from '../layers'\nimport { MapView } from '../map-view'\nimport type { MapPointItem } from '../types'\nimport { MAX_FEATURES, useMapLabels } from './shared'\n\nexport default function MapPanelRenderer({ panel, record, metadata, data, locale }: PanelRendererProps) {\n const labels = useMapLabels()\n const view = panel.map\n const route = view?.route\n const rel = route ? metadata?.relations?.find((r) => r.name === route.relation) : undefined\n const [stops, setStops] = React.useState<Array<{ lat: number; lng: number }>>([])\n const recordId = record.id\n\n React.useEffect(() => {\n if (!route || !rel || recordId === undefined || recordId === null) return\n let cancelled = false\n data\n .list(rel.through, { ...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope), per_page: MAX_FEATURES, sortBy: route.order_by, order: 'asc' })\n .then((res) => !cancelled && setStops(toRoutePoints(res.rows, route)))\n .catch(() => undefined)\n return () => {\n cancelled = true\n }\n }, [data, route, rel, recordId])\n\n const points = React.useMemo<MapPointItem[]>(() => {\n if (!view) return []\n const stopItems = stops.map((s, i) => ({ key: `stop-${i}`, ...s, label: `${labels.point} ${i + 1}`, glyph: String(i + 1) }))\n const own = toMapFeatures([record], { ...view, popup: view.popup ?? [] }).map((f) => ({\n key: f.key,\n lat: f.lat,\n lng: f.lng,\n label: f.popup[0]?.value || labels.point,\n details: f.popup.slice(1).filter((p) => p.value).map((p) => ({ label: p.field, value: p.value })),\n }))\n return [...stopItems, ...own]\n }, [view, stops, record, labels.point])\n\n if (!view) return null\n return (\n <MapView points={points} height={260} labels={labels} locale={locale} cluster={false}>\n {stops.length > 1 ? <Polyline path={stops} /> : null}\n </MapView>\n )\n}\n"]}
@@ -0,0 +1,73 @@
1
+ // src/config.ts
2
+ var config = {};
3
+ var maplibrePromise = null;
4
+ var protocolFor = /* @__PURE__ */ new WeakSet();
5
+ function configureMaps(next) {
6
+ config = { ...config, ...next, style: { ...config.style, ...next.style } };
7
+ if (next.loadMaplibre) maplibrePromise = null;
8
+ }
9
+ function getMapsConfig() {
10
+ return config;
11
+ }
12
+ function supportsWebGL() {
13
+ if (config.supportsWebGL) return config.supportsWebGL();
14
+ try {
15
+ const canvas = document.createElement("canvas");
16
+ return !!(canvas.getContext("webgl2") || canvas.getContext("webgl"));
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
21
+ async function defaultLoad() {
22
+ const mod = await import('maplibre-gl');
23
+ return mod.default ?? mod;
24
+ }
25
+ function loadMaplibre() {
26
+ if (!maplibrePromise) {
27
+ const p = (async () => {
28
+ const [mod] = await Promise.all([
29
+ (config.loadMaplibre ?? defaultLoad)(),
30
+ config.injectCss === false || config.loadMaplibre ? Promise.resolve() : (
31
+ // CSS side-effect import, resolved by the host bundler
32
+ import('maplibre-gl/dist/maplibre-gl.css').catch(() => void 0)
33
+ )
34
+ ]);
35
+ return mod;
36
+ })();
37
+ maplibrePromise = p;
38
+ p.catch(() => {
39
+ if (maplibrePromise === p) maplibrePromise = null;
40
+ });
41
+ }
42
+ return maplibrePromise;
43
+ }
44
+ var hasPmtiles = (style) => !!style && (typeof style === "string" ? style.startsWith("pmtiles://") : JSON.stringify(style).includes("pmtiles://"));
45
+ async function ensureProtocols(ml, style) {
46
+ if (!hasPmtiles(style) || protocolFor.has(ml) || !config.pmtiles) return;
47
+ const { Protocol } = await config.pmtiles();
48
+ ml.addProtocol("pmtiles", new Protocol().tile);
49
+ protocolFor.add(ml);
50
+ }
51
+ function blankStyle(scheme) {
52
+ return {
53
+ version: 8,
54
+ sources: {},
55
+ layers: [{ id: "background", type: "background", paint: { "background-color": scheme === "dark" ? "#16181d" : "#eef1f4" } }]
56
+ };
57
+ }
58
+ function rasterStyle(tiles, attribution, tileSize = 256) {
59
+ return {
60
+ version: 8,
61
+ sources: { base: { type: "raster", tiles, tileSize, attribution } },
62
+ layers: [{ id: "base", type: "raster", source: "base" }]
63
+ };
64
+ }
65
+ function resolveStyle(scheme, override) {
66
+ const o = override && (typeof override === "string" || "version" in override) ? { light: override, dark: override } : override;
67
+ const s = o?.[scheme] ?? config.style?.[scheme] ?? config.style?.light;
68
+ return s ?? blankStyle(scheme);
69
+ }
70
+
71
+ export { blankStyle, configureMaps, ensureProtocols, getMapsConfig, loadMaplibre, rasterStyle, resolveStyle, supportsWebGL };
72
+ //# sourceMappingURL=chunk-HE2XC52R.js.map
73
+ //# sourceMappingURL=chunk-HE2XC52R.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config.ts"],"names":[],"mappings":";AAyCA,IAAI,SAAqB,EAAC;AAC1B,IAAI,eAAA,GAAkD,IAAA;AACtD,IAAM,WAAA,uBAAkB,OAAA,EAAgB;AAGjC,SAAS,cAAc,IAAA,EAAwB;AAClD,EAAA,MAAA,GAAS,EAAE,GAAG,MAAA,EAAQ,GAAG,IAAA,EAAM,KAAA,EAAO,EAAE,GAAG,MAAA,CAAO,KAAA,EAAO,GAAG,IAAA,CAAK,OAAM,EAAE;AACzE,EAAA,IAAI,IAAA,CAAK,cAAc,eAAA,GAAkB,IAAA;AAC7C;AAEO,SAAS,aAAA,GAAsC;AAClD,EAAA,OAAO,MAAA;AACX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EAAO,QAAA,EAAU,IAAA,EAAM,QAAA,EAAS,GAAI,QAAA;AACtH,EAAA,MAAM,CAAA,GAAK,IAA0D,MAAM,CAAA,IAAK,OAAO,KAAA,GAAQ,MAAM,CAAA,IAAK,MAAA,CAAO,KAAA,EAAO,KAAA;AACxH,EAAA,OAAO,CAAA,IAAK,WAAW,MAAM,CAAA;AACjC","file":"chunk-HE2XC52R.js","sourcesContent":["// Host configuration and the lazy MapLibre loader. Nothing here imports\n// `maplibre-gl` statically: it is fetched the first time a map mounts, so a\n// host (or an addon remote) that never shows a map pays 0 bytes for it.\nimport type * as ML from 'maplibre-gl'\n\nexport type MapLibreModule = typeof ML\nexport type MapStyle = string | ML.StyleSpecification\nexport type MapScheme = 'light' | 'dark'\n\n/** Minimal PMTiles surface (`pmtiles` package): the protocol MapLibre registers. */\nexport interface PMTilesModule {\n Protocol: new () => { tile: (...args: any[]) => any }\n}\n\nexport interface MapsConfig {\n /**\n * Base map style per colour scheme: a style JSON URL (the host's CDN) or an\n * inline style object. `pmtiles://` sources are supported when `pmtiles` is\n * configured. Without a style the map draws on a plain themed background —\n * the data layers and the list alternative still work, and no request is\n * made to any third party.\n */\n style?: { light?: MapStyle; dark?: MapStyle }\n /** Replace the default `import('maplibre-gl')` (tests, custom builds, CDN). */\n loadMaplibre?: () => Promise<MapLibreModule>\n /**\n * Enables `pmtiles://` styles: pass `() => import('pmtiles')` (the host\n * bundler resolves it; the package never imports it on its own).\n */\n pmtiles?: () => Promise<PMTilesModule>\n /** Inject the MapLibre CSS with the chunk. Default true. */\n injectCss?: boolean\n /** Initial view when there is nothing to fit: `[lng, lat]` and zoom. */\n center?: [number, number]\n zoom?: number\n /** Extra attribution text (the OSM credit of a basemap you serve). */\n attribution?: string\n /** Override the WebGL probe (default: try to create a context). */\n supportsWebGL?: () => boolean\n}\n\nlet config: MapsConfig = {}\nlet maplibrePromise: Promise<MapLibreModule> | null = null\nconst protocolFor = new WeakSet<object>()\n\n/** Merge host configuration. Call once, before the first map mounts. */\nexport function configureMaps(next: MapsConfig): void {\n config = { ...config, ...next, style: { ...config.style, ...next.style } }\n if (next.loadMaplibre) maplibrePromise = null\n}\n\nexport function getMapsConfig(): Readonly<MapsConfig> {\n return config\n}\n\n/** Test helper: back to defaults and drop the cached module. */\nexport function resetMapsConfig(): void {\n config = {}\n maplibrePromise = null\n}\n\nexport function supportsWebGL(): boolean {\n if (config.supportsWebGL) return config.supportsWebGL()\n try {\n const canvas = document.createElement('canvas')\n return !!(canvas.getContext('webgl2') || canvas.getContext('webgl'))\n } catch {\n return false\n }\n}\n\nasync function defaultLoad(): Promise<MapLibreModule> {\n const mod = (await import('maplibre-gl')) as unknown as { default?: MapLibreModule } & MapLibreModule\n return (mod.default ?? mod) as MapLibreModule\n}\n\n/**\n * Load MapLibre once (shared by every map on the page, and with the host when\n * `maplibre-gl` is a federation share). A failed load is not cached.\n */\nexport function loadMaplibre(): Promise<MapLibreModule> {\n if (!maplibrePromise) {\n const p = (async () => {\n const [mod] = await Promise.all([\n (config.loadMaplibre ?? defaultLoad)(),\n config.injectCss === false || config.loadMaplibre\n ? Promise.resolve()\n : // CSS side-effect import, resolved by the host bundler\n import('maplibre-gl/dist/maplibre-gl.css').catch(() => undefined),\n ])\n return mod\n })()\n maplibrePromise = p\n p.catch(() => {\n if (maplibrePromise === p) maplibrePromise = null\n })\n }\n return maplibrePromise\n}\n\nconst hasPmtiles = (style: MapStyle | undefined): boolean =>\n !!style && (typeof style === 'string' ? style.startsWith('pmtiles://') : JSON.stringify(style).includes('pmtiles://'))\n\n/** Register the `pmtiles://` protocol once per MapLibre when the style needs it. */\nexport async function ensureProtocols(ml: MapLibreModule, style: MapStyle | undefined): Promise<void> {\n if (!hasPmtiles(style) || protocolFor.has(ml) || !config.pmtiles) return\n const { Protocol } = await config.pmtiles()\n ml.addProtocol('pmtiles', new Protocol().tile)\n protocolFor.add(ml)\n}\n\n/** Themed blank style: a background only (no network, no glyphs). */\nexport function blankStyle(scheme: MapScheme): ML.StyleSpecification {\n return {\n version: 8,\n sources: {},\n layers: [{ id: 'background', type: 'background', paint: { 'background-color': scheme === 'dark' ? '#16181d' : '#eef1f4' } }],\n }\n}\n\n/** Raster style over `{z}/{x}/{y}` tile URLs you serve (no key needed). */\nexport function rasterStyle(tiles: string[], attribution?: string, tileSize = 256): ML.StyleSpecification {\n return {\n version: 8,\n sources: { base: { type: 'raster', tiles, tileSize, attribution } },\n layers: [{ id: 'base', type: 'raster', source: 'base' }],\n }\n}\n\nexport function resolveStyle(scheme: MapScheme, override?: { light?: MapStyle; dark?: MapStyle } | MapStyle): MapStyle {\n const o = override && (typeof override === 'string' || 'version' in override) ? { light: override, dark: override } : override\n const s = (o as { light?: MapStyle; dark?: MapStyle } | undefined)?.[scheme] ?? config.style?.[scheme] ?? config.style?.light\n return s ?? blankStyle(scheme)\n}\n"]}