@rise-x/apps-sdk 0.9.0 → 0.11.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.
- package/README.md +116 -31
- package/build/rsbuild/index.d.ts +6 -1
- package/build/rsbuild/index.js +23 -2
- package/build/ui/classes.json +209 -0
- package/build/ui/components/ai.d.ts +33 -1
- package/build/ui/components/app-frame.d.ts +16 -10
- package/build/ui/components/chat-input.d.ts +28 -0
- package/build/ui/components/message-scroller.d.ts +34 -10
- package/build/ui/components/sheet.d.ts +10 -0
- package/build/ui/components/thinking-rings.d.ts +4 -0
- package/build/ui/demo.html +26794 -0
- package/build/ui/index.d.ts +2 -0
- package/build/ui/standalone.js +59 -58
- package/build/ui/styles.css +1 -1
- package/package.json +4 -3
- package/template/AGENTS.md +3 -3
- package/template/README.md +5 -5
- package/template/package.json +8 -9
- package/template/rsbuild.config.mts +17 -0
- package/template/src/App.tsx +4 -1
- package/template/tsconfig.json +3 -1
- package/build/ui/reference/README.md +0 -11
- package/build/ui/reference/components/accordion.tsx +0 -85
- package/build/ui/reference/components/ai.tsx +0 -293
- package/build/ui/reference/components/alert-dialog.tsx +0 -207
- package/build/ui/reference/components/alert.tsx +0 -112
- package/build/ui/reference/components/app-frame.tsx +0 -71
- package/build/ui/reference/components/aspect-ratio.tsx +0 -28
- package/build/ui/reference/components/avatar.tsx +0 -158
- package/build/ui/reference/components/badge.tsx +0 -160
- package/build/ui/reference/components/button-group.tsx +0 -77
- package/build/ui/reference/components/button.tsx +0 -109
- package/build/ui/reference/components/calendar.tsx +0 -119
- package/build/ui/reference/components/card.tsx +0 -144
- package/build/ui/reference/components/carousel.tsx +0 -248
- package/build/ui/reference/components/chart.tsx +0 -704
- package/build/ui/reference/components/checkbox.tsx +0 -44
- package/build/ui/reference/components/collapsible.tsx +0 -43
- package/build/ui/reference/components/combobox.tsx +0 -146
- package/build/ui/reference/components/command.tsx +0 -181
- package/build/ui/reference/components/context-menu.tsx +0 -243
- package/build/ui/reference/components/data-table.tsx +0 -650
- package/build/ui/reference/components/date-picker.tsx +0 -218
- package/build/ui/reference/components/dialog.tsx +0 -172
- package/build/ui/reference/components/direction.tsx +0 -22
- package/build/ui/reference/components/dropdown-menu.tsx +0 -245
- package/build/ui/reference/components/empty-state.tsx +0 -63
- package/build/ui/reference/components/field.tsx +0 -252
- package/build/ui/reference/components/file-upload.tsx +0 -116
- package/build/ui/reference/components/hover-card.tsx +0 -64
- package/build/ui/reference/components/input-group.tsx +0 -157
- package/build/ui/reference/components/input-otp.tsx +0 -106
- package/build/ui/reference/components/input.tsx +0 -86
- package/build/ui/reference/components/item.tsx +0 -188
- package/build/ui/reference/components/kbd.tsx +0 -43
- package/build/ui/reference/components/label.tsx +0 -19
- package/build/ui/reference/components/list.tsx +0 -191
- package/build/ui/reference/components/map.css +0 -251
- package/build/ui/reference/components/map.tsx +0 -294
- package/build/ui/reference/components/menubar.tsx +0 -275
- package/build/ui/reference/components/message-scroller.tsx +0 -141
- package/build/ui/reference/components/message.tsx +0 -177
- package/build/ui/reference/components/nav.tsx +0 -127
- package/build/ui/reference/components/navigation-menu.tsx +0 -191
- package/build/ui/reference/components/page-header.tsx +0 -245
- package/build/ui/reference/components/popover.tsx +0 -76
- package/build/ui/reference/components/progress.tsx +0 -31
- package/build/ui/reference/components/radio.tsx +0 -65
- package/build/ui/reference/components/resizable.tsx +0 -40
- package/build/ui/reference/components/scroll-area.tsx +0 -55
- package/build/ui/reference/components/segmented.tsx +0 -45
- package/build/ui/reference/components/select.tsx +0 -188
- package/build/ui/reference/components/separator.tsx +0 -26
- package/build/ui/reference/components/sheet.tsx +0 -184
- package/build/ui/reference/components/skeleton.tsx +0 -15
- package/build/ui/reference/components/slider.tsx +0 -161
- package/build/ui/reference/components/snackbar.tsx +0 -27
- package/build/ui/reference/components/sonner.tsx +0 -43
- package/build/ui/reference/components/spinner.tsx +0 -27
- package/build/ui/reference/components/statistic.tsx +0 -122
- package/build/ui/reference/components/stepper.tsx +0 -138
- package/build/ui/reference/components/switch.tsx +0 -47
- package/build/ui/reference/components/table.tsx +0 -246
- package/build/ui/reference/components/textarea.tsx +0 -28
- package/build/ui/reference/components/timeline.tsx +0 -101
- package/build/ui/reference/components/toggle-group.tsx +0 -86
- package/build/ui/reference/components/toggle.tsx +0 -46
- package/build/ui/reference/components/tooltip.tsx +0 -53
- package/build/ui/reference/index.ts +0 -69
- package/build/ui/reference/lib/utils.ts +0 -34
- package/template/webpack.config.js +0 -112
- package/template/webpack.local.config.js +0 -68
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Rise-X chrome for Leaflet — zoom cluster, tooltip, popup, attribution, pin.
|
|
3
|
-
*
|
|
4
|
-
* Plain CSS, imported straight after leaflet.css in map.tsx. Leaflet ships its
|
|
5
|
-
* stylesheet UNLAYERED, so it outranks anything in Tailwind's utility layer;
|
|
6
|
-
* matching Leaflet's own selectors and winning on source order is the only
|
|
7
|
-
* override that holds in both hosts. Selectors are prefixed with
|
|
8
|
-
* `.leaflet-container` to clear Leaflet's `.leaflet-touch ...` variants, which
|
|
9
|
-
* are a class more specific than the base rules.
|
|
10
|
-
*
|
|
11
|
-
* Colours come from the runtime tokens in tokens.css, so the map follows
|
|
12
|
-
* light/dark and any ecosystem rebrand for free. Shadows are written out
|
|
13
|
-
* because theme.css declares them in `@theme inline`, which resolves into
|
|
14
|
-
* utilities at build time and emits no custom property to read at runtime —
|
|
15
|
-
* the values below mirror --shadow-pill and --shadow-pop exactly.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
.leaflet-container {
|
|
19
|
-
/* Inherit the host's typeface rather than Leaflet's Helvetica stack, and use
|
|
20
|
-
* the design system's muted grey as the pre-tile backdrop. */
|
|
21
|
-
font-family: inherit;
|
|
22
|
-
background: var(--muted);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/* ---------- control clusters: zoom, layers, anything on .leaflet-bar ------- */
|
|
26
|
-
|
|
27
|
-
.leaflet-container .leaflet-bar {
|
|
28
|
-
border: 1px solid var(--border-strong);
|
|
29
|
-
border-radius: var(--radius);
|
|
30
|
-
background: var(--card);
|
|
31
|
-
box-shadow: 0 1px 2px rgb(16 24 40 / 0.04);
|
|
32
|
-
overflow: hidden;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/* A ghost icon button, per button.tsx: muted glyph that comes up to full
|
|
36
|
-
* strength on hover. The stack reads as ONE control, so the buttons are square
|
|
37
|
-
* inside it and only a hairline separates them. */
|
|
38
|
-
.leaflet-container .leaflet-bar a,
|
|
39
|
-
.leaflet-container .leaflet-bar a:hover {
|
|
40
|
-
width: var(--h-sm);
|
|
41
|
-
height: var(--h-sm);
|
|
42
|
-
line-height: var(--h-sm);
|
|
43
|
-
border: 0;
|
|
44
|
-
border-radius: 0;
|
|
45
|
-
background: var(--card);
|
|
46
|
-
color: var(--muted-foreground);
|
|
47
|
-
font-size: 16px;
|
|
48
|
-
font-weight: 400;
|
|
49
|
-
transition:
|
|
50
|
-
background-color 150ms var(--ease),
|
|
51
|
-
color 150ms var(--ease);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/* Leaflet rounds the end caps to its own 2px through `.leaflet-touch .leaflet-bar
|
|
55
|
-
* a:first-child` — a pseudo-class more specific than the rule above, so the
|
|
56
|
-
* reset has to be spelled out at the same weight. The cluster's own radius
|
|
57
|
-
* comes from .leaflet-bar, which clips these corners. */
|
|
58
|
-
.leaflet-container .leaflet-bar a:first-child,
|
|
59
|
-
.leaflet-container .leaflet-bar a:last-child {
|
|
60
|
-
border-radius: 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.leaflet-container .leaflet-bar a + a {
|
|
64
|
-
border-top: 1px solid var(--border);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.leaflet-container .leaflet-bar a:hover {
|
|
68
|
-
background: var(--muted);
|
|
69
|
-
color: var(--foreground);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.leaflet-container .leaflet-bar a:active {
|
|
73
|
-
background: var(--fill-2);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/* Focus is the NEUTRAL ring — these are controls you operate, not fields you
|
|
77
|
-
* type into (button.tsx). Drawn inset because the cluster clips overflow. */
|
|
78
|
-
.leaflet-container .leaflet-bar a:focus-visible {
|
|
79
|
-
outline: none;
|
|
80
|
-
box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--ring-control) 35%, transparent);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.leaflet-container .leaflet-bar a.leaflet-disabled,
|
|
84
|
-
.leaflet-container .leaflet-bar a.leaflet-disabled:hover {
|
|
85
|
-
background: var(--card);
|
|
86
|
-
color: var(--muted-foreground);
|
|
87
|
-
opacity: 0.45;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/* ---------- attribution ---------------------------------------------------- */
|
|
91
|
-
|
|
92
|
-
.leaflet-container .leaflet-control-attribution {
|
|
93
|
-
padding: 1px 6px;
|
|
94
|
-
border-radius: calc(var(--radius) - 4px) 0 0 0;
|
|
95
|
-
background: color-mix(in srgb, var(--card) 86%, transparent);
|
|
96
|
-
color: var(--text-subtle);
|
|
97
|
-
font-size: 11px;
|
|
98
|
-
line-height: 1.5;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.leaflet-container .leaflet-control-attribution a {
|
|
102
|
-
color: var(--text-subtle);
|
|
103
|
-
text-decoration: none;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
.leaflet-container .leaflet-control-attribution a:hover {
|
|
107
|
-
color: var(--foreground);
|
|
108
|
-
text-decoration: underline;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/* The Leaflet flag is the one piece of foreign branding in the chrome. The text
|
|
112
|
-
* credit — the part attribution actually requires — stays. !important is not a
|
|
113
|
-
* shortcut here: Leaflet declares `display: inline !important` on this element,
|
|
114
|
-
* so nothing else can reach it. */
|
|
115
|
-
.leaflet-container .leaflet-attribution-flag {
|
|
116
|
-
display: none !important;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/* ---------- tooltip: twin of TooltipContent -------------------------------- */
|
|
120
|
-
|
|
121
|
-
.leaflet-container .leaflet-tooltip {
|
|
122
|
-
padding: 6px 10px;
|
|
123
|
-
border: 0;
|
|
124
|
-
border-radius: calc(var(--radius) - 2px);
|
|
125
|
-
background: var(--foreground);
|
|
126
|
-
color: var(--background);
|
|
127
|
-
font-size: 12px;
|
|
128
|
-
line-height: 1.5;
|
|
129
|
-
font-weight: 400;
|
|
130
|
-
box-shadow: none;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
.leaflet-container .leaflet-tooltip-top:before {
|
|
134
|
-
border-top-color: var(--foreground);
|
|
135
|
-
}
|
|
136
|
-
.leaflet-container .leaflet-tooltip-bottom:before {
|
|
137
|
-
border-bottom-color: var(--foreground);
|
|
138
|
-
}
|
|
139
|
-
.leaflet-container .leaflet-tooltip-left:before {
|
|
140
|
-
border-left-color: var(--foreground);
|
|
141
|
-
}
|
|
142
|
-
.leaflet-container .leaflet-tooltip-right:before {
|
|
143
|
-
border-right-color: var(--foreground);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/* ---------- popup: twin of PopoverContent ---------------------------------- */
|
|
147
|
-
|
|
148
|
-
/*
|
|
149
|
-
* Spacing lives on the WRAPPER, not as a margin on the content. Leaflet spaces
|
|
150
|
-
* its popup with `.leaflet-popup-content { margin: 13px 24px ... }`, which only
|
|
151
|
-
* works because the wrapper carries a 1px padding to block margin collapse.
|
|
152
|
-
* Take that padding away and the child's vertical margins collapse straight
|
|
153
|
-
* out of the wrapper: the white card shrinks to exactly the text box, and the
|
|
154
|
-
* escaped bottom margin pushes the tip clear of the card.
|
|
155
|
-
*
|
|
156
|
-
* The right side is wider on purpose — it is the lane the close button sits in,
|
|
157
|
-
* so a long first line cannot run underneath it.
|
|
158
|
-
*/
|
|
159
|
-
.leaflet-container .leaflet-popup-content-wrapper {
|
|
160
|
-
padding: 12px 32px 12px 14px;
|
|
161
|
-
border-radius: calc(var(--radius) + 4px);
|
|
162
|
-
background: var(--popover);
|
|
163
|
-
color: var(--popover-foreground);
|
|
164
|
-
box-shadow:
|
|
165
|
-
0 8px 28px -6px rgb(16 24 40 / 0.16),
|
|
166
|
-
0 2px 6px -2px rgb(16 24 40 / 0.08),
|
|
167
|
-
0 0 0 1px rgb(16 24 40 / 0.04);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
.leaflet-container .leaflet-popup-content {
|
|
171
|
-
margin: 0;
|
|
172
|
-
font-size: 13px;
|
|
173
|
-
line-height: 1.5;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.leaflet-container .leaflet-popup-tip {
|
|
177
|
-
background: var(--popover);
|
|
178
|
-
box-shadow: none;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/* Ghost icon button, sized like the xs control. */
|
|
182
|
-
.leaflet-container .leaflet-popup-close-button {
|
|
183
|
-
top: 5px;
|
|
184
|
-
right: 5px;
|
|
185
|
-
width: var(--h-xs);
|
|
186
|
-
height: var(--h-xs);
|
|
187
|
-
border-radius: calc(var(--radius) - 2px);
|
|
188
|
-
color: var(--muted-foreground);
|
|
189
|
-
font-size: 15px;
|
|
190
|
-
font-weight: 400;
|
|
191
|
-
line-height: var(--h-xs);
|
|
192
|
-
transition:
|
|
193
|
-
background-color 150ms var(--ease),
|
|
194
|
-
color 150ms var(--ease);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
.leaflet-container .leaflet-popup-close-button:hover {
|
|
198
|
-
background: var(--muted);
|
|
199
|
-
color: var(--foreground);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/* ---------- pin ------------------------------------------------------------ */
|
|
203
|
-
|
|
204
|
-
/*
|
|
205
|
-
* A ringed dot, not a teardrop: it is what every Rise-X map already draws (ports,
|
|
206
|
-
* vessels, sites), it stays legible where markers cluster, and it does not add a
|
|
207
|
-
* piece of skeuomorphism to an otherwise flat system.
|
|
208
|
-
*
|
|
209
|
-
* The dot is a CHILD of the icon element on purpose — Leaflet positions markers
|
|
210
|
-
* by writing `transform` on the icon itself, so any transform of ours there
|
|
211
|
-
* (the selected state below) would throw the marker off its coordinates.
|
|
212
|
-
*/
|
|
213
|
-
.rx-map-pin .rx-map-pin-dot {
|
|
214
|
-
display: block;
|
|
215
|
-
/* Explicit, not inherited from a preflight: the classic host's embed.css
|
|
216
|
-
* deliberately ships no `box-sizing` reset, and content-box would push the
|
|
217
|
-
* ring outside the icon box Leaflet anchors on. */
|
|
218
|
-
box-sizing: border-box;
|
|
219
|
-
width: 100%;
|
|
220
|
-
height: 100%;
|
|
221
|
-
border-radius: 50%;
|
|
222
|
-
background: var(--rx-pin, var(--foreground));
|
|
223
|
-
border: 2px solid var(--card);
|
|
224
|
-
box-shadow:
|
|
225
|
-
0 1px 2px rgb(16 24 40 / 0.24),
|
|
226
|
-
0 0 0 1px rgb(16 24 40 / 0.06);
|
|
227
|
-
transition: transform 150ms var(--ease);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/* Semantic tones, so a pin can carry the same meaning a Badge does. */
|
|
231
|
-
.rx-map-pin-dot[data-tone='brand'] {
|
|
232
|
-
--rx-pin: var(--brand);
|
|
233
|
-
}
|
|
234
|
-
.rx-map-pin-dot[data-tone='success'] {
|
|
235
|
-
--rx-pin: var(--success);
|
|
236
|
-
}
|
|
237
|
-
.rx-map-pin-dot[data-tone='warning'] {
|
|
238
|
-
--rx-pin: var(--warning);
|
|
239
|
-
}
|
|
240
|
-
.rx-map-pin-dot[data-tone='error'] {
|
|
241
|
-
--rx-pin: var(--error);
|
|
242
|
-
}
|
|
243
|
-
.rx-map-pin-dot[data-tone='info'] {
|
|
244
|
-
--rx-pin: var(--info);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/* Toggleable from an app without rebuilding the icon:
|
|
248
|
-
* `marker.getElement()?.classList.add('is-selected')`. */
|
|
249
|
-
.rx-map-pin.is-selected .rx-map-pin-dot {
|
|
250
|
-
transform: scale(1.3);
|
|
251
|
-
}
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
DivIconOptions,
|
|
4
|
-
LatLngBoundsExpression,
|
|
5
|
-
LatLngExpression,
|
|
6
|
-
Map as LeafletMap,
|
|
7
|
-
MapOptions,
|
|
8
|
-
TileLayerOptions,
|
|
9
|
-
} from 'leaflet';
|
|
10
|
-
import 'leaflet/dist/leaflet.css';
|
|
11
|
-
// Relative, unlike the `@rise-x/ui/...` self-references elsewhere in the
|
|
12
|
-
// package: the exports map appends `.tsx` to `./components/*`, and this
|
|
13
|
-
// stylesheet is internal — nothing outside the package imports it. It must
|
|
14
|
-
// come after leaflet.css; the overrides win on source order.
|
|
15
|
-
import './map.css';
|
|
16
|
-
|
|
17
|
-
import { cn } from '@rise-x/ui/lib/utils';
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
* A Leaflet map and nothing else — no markers, no popups, no legend. Every
|
|
21
|
-
* Rise-X map draws different things on top (vessels and voyage legs, telecom
|
|
22
|
-
* sites and coverage, procurement lots), so the shared piece is the part they
|
|
23
|
-
* all rebuilt identically: the container, the basemap, and the embedding.
|
|
24
|
-
*
|
|
25
|
-
* Named MapView, not Map: the barrel is flat, so `import { Map }` would shadow
|
|
26
|
-
* the global Map in the importing module.
|
|
27
|
-
*
|
|
28
|
-
* Leaflet itself is loaded with a dynamic import. `@rise-x/ui` is bundled whole
|
|
29
|
-
* by both hosts (the shell and the classic app provide it through the module
|
|
30
|
-
* federation share scope), so a static import would put ~112 kB gzipped of
|
|
31
|
-
* mapping code in every EOP page load. The stylesheet is imported statically:
|
|
32
|
-
* at ~4 kB gzipped it is cheap enough to ride along with the design system's
|
|
33
|
-
* CSS, where it is already in place rather than arriving with the chunk.
|
|
34
|
-
*
|
|
35
|
-
* Everything past "show me a basemap" is done through the Leaflet instance,
|
|
36
|
-
* handed over by `onReady` (or a ref). That is deliberate: layers, markers and
|
|
37
|
-
* fly-to choreography are app decisions, and wrapping them in props would mean
|
|
38
|
-
* re-inventing Leaflet's API one prop at a time.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
type MapTilePreset = 'light' | 'dark' | 'streets' | 'satellite';
|
|
42
|
-
|
|
43
|
-
type MapTileSpec = TileLayerOptions & { url: string };
|
|
44
|
-
|
|
45
|
-
/* Exported so apps can start from a preset and tweak it, e.g.
|
|
46
|
-
* `tiles={{ ...MAP_TILES.light, maxZoom: 12 }}`. */
|
|
47
|
-
const MAP_TILES: Record<MapTilePreset, MapTileSpec> = {
|
|
48
|
-
light: {
|
|
49
|
-
url: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png',
|
|
50
|
-
attribution: '© OpenStreetMap, © CARTO',
|
|
51
|
-
subdomains: 'abcd',
|
|
52
|
-
maxZoom: 20,
|
|
53
|
-
},
|
|
54
|
-
dark: {
|
|
55
|
-
url: 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png',
|
|
56
|
-
attribution: '© OpenStreetMap, © CARTO',
|
|
57
|
-
subdomains: 'abcd',
|
|
58
|
-
maxZoom: 20,
|
|
59
|
-
},
|
|
60
|
-
streets: {
|
|
61
|
-
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
62
|
-
attribution: '© OpenStreetMap',
|
|
63
|
-
maxZoom: 19,
|
|
64
|
-
},
|
|
65
|
-
satellite: {
|
|
66
|
-
url: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
|
|
67
|
-
attribution: '© Esri',
|
|
68
|
-
maxZoom: 19,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
type MapPinTone = 'default' | 'brand' | 'success' | 'warning' | 'error' | 'info';
|
|
73
|
-
|
|
74
|
-
type MapPinOptions = { tone?: MapPinTone; selected?: boolean };
|
|
75
|
-
|
|
76
|
-
/*
|
|
77
|
-
* The design system's marker: `L.marker(pos, { icon: L.divIcon(mapPin()) })`.
|
|
78
|
-
* It returns divIcon OPTIONS rather than an icon so describing a pin needs no
|
|
79
|
-
* Leaflet instance in scope — and MapView installs it as Leaflet's DEFAULT
|
|
80
|
-
* marker icon, so a plain `L.marker(pos)` is already on brand (and no longer
|
|
81
|
-
* reaches for the bundled blue PNG, which bundlers routinely fail to resolve).
|
|
82
|
-
*/
|
|
83
|
-
function mapPin({ tone = 'default', selected = false }: MapPinOptions = {}): DivIconOptions {
|
|
84
|
-
return {
|
|
85
|
-
className: selected ? 'rx-map-pin is-selected' : 'rx-map-pin',
|
|
86
|
-
html: `<span class="rx-map-pin-dot" data-tone="${tone}"></span>`,
|
|
87
|
-
iconSize: [18, 18],
|
|
88
|
-
iconAnchor: [9, 9],
|
|
89
|
-
popupAnchor: [0, -11],
|
|
90
|
-
tooltipAnchor: [0, -11],
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
type MapViewProps = React.ComponentProps<'div'> & {
|
|
95
|
-
/* Initial view. Not tracked afterwards — later changes are the app's call to
|
|
96
|
-
* make on the instance (`map.flyTo(...)`), so a re-render can't yank the map
|
|
97
|
-
* out from under someone who is panning. */
|
|
98
|
-
center?: LatLngExpression;
|
|
99
|
-
zoom?: number;
|
|
100
|
-
/* Initial view by extent instead. Wins over center/zoom when set. */
|
|
101
|
-
bounds?: LatLngBoundsExpression;
|
|
102
|
-
boundsPadding?: number;
|
|
103
|
-
/* 'auto' follows the design system's theme — the light basemap normally, the
|
|
104
|
-
* dark one whenever a `.dark` ancestor is present, switching live with it.
|
|
105
|
-
* Otherwise a preset name, a custom tile layer, or null for no basemap at all
|
|
106
|
-
* (apps that bring their own WMS or offline tile source). */
|
|
107
|
-
tiles?: 'auto' | MapTilePreset | MapTileSpec | null;
|
|
108
|
-
/* false locks the map down to a static picture — for cards, list rows and
|
|
109
|
-
* previews where a map that pans and zooms would fight the page. */
|
|
110
|
-
interactive?: boolean;
|
|
111
|
-
/* Raw Leaflet options, merged last. */
|
|
112
|
-
options?: MapOptions;
|
|
113
|
-
/* Handed the map and the Leaflet module it was built from. Passing `L` back
|
|
114
|
-
* matters: it is the host's single copy, so apps add layers without taking
|
|
115
|
-
* their own leaflet dependency and without a second copy of the library
|
|
116
|
-
* meeting the first one at `map.addLayer`. */
|
|
117
|
-
onReady?: (map: LeafletMap, leaflet: typeof import('leaflet')) => void;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
let defaultPinInstalled = false;
|
|
121
|
-
|
|
122
|
-
const MapView = React.forwardRef<LeafletMap | null, MapViewProps>(function MapView(
|
|
123
|
-
{
|
|
124
|
-
className,
|
|
125
|
-
children,
|
|
126
|
-
center = [20, 0],
|
|
127
|
-
zoom = 2,
|
|
128
|
-
bounds,
|
|
129
|
-
boundsPadding = 32,
|
|
130
|
-
tiles = 'auto',
|
|
131
|
-
interactive = true,
|
|
132
|
-
options,
|
|
133
|
-
onReady,
|
|
134
|
-
...props
|
|
135
|
-
},
|
|
136
|
-
ref,
|
|
137
|
-
) {
|
|
138
|
-
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
139
|
-
const leafletRef = React.useRef<typeof import('leaflet') | null>(null);
|
|
140
|
-
const [map, setMap] = React.useState<LeafletMap | null>(null);
|
|
141
|
-
|
|
142
|
-
/* Read by the init effect, which must run exactly once — re-creating the map
|
|
143
|
-
* because a parent re-rendered would drop every layer the app has added. */
|
|
144
|
-
const initRef = React.useRef({
|
|
145
|
-
center,
|
|
146
|
-
zoom,
|
|
147
|
-
bounds,
|
|
148
|
-
boundsPadding,
|
|
149
|
-
interactive,
|
|
150
|
-
options,
|
|
151
|
-
onReady,
|
|
152
|
-
});
|
|
153
|
-
initRef.current = { center, zoom, bounds, boundsPadding, interactive, options, onReady };
|
|
154
|
-
|
|
155
|
-
/* Explicit generics: inference narrows T to LeafletMap and then rejects the
|
|
156
|
-
* null the handle legitimately holds until the chunk lands. */
|
|
157
|
-
React.useImperativeHandle<LeafletMap | null, LeafletMap | null>(ref, () => map, [map]);
|
|
158
|
-
|
|
159
|
-
React.useEffect(() => {
|
|
160
|
-
const container = containerRef.current;
|
|
161
|
-
if (!container) return;
|
|
162
|
-
|
|
163
|
-
let disposed = false;
|
|
164
|
-
let instance: LeafletMap | null = null;
|
|
165
|
-
let observer: ResizeObserver | null = null;
|
|
166
|
-
let frame = 0;
|
|
167
|
-
|
|
168
|
-
void import('leaflet').then(({ default: L }) => {
|
|
169
|
-
// StrictMode's double mount (and any fast unmount) resolves here after
|
|
170
|
-
// cleanup already ran; creating the map now would leak it and leave the
|
|
171
|
-
// container tagged, so the next L.map() throws "already initialized".
|
|
172
|
-
if (disposed) return;
|
|
173
|
-
|
|
174
|
-
// Once per Leaflet copy, on the host's single shared instance: markers
|
|
175
|
-
// made without an explicit icon get the design system's pin instead of
|
|
176
|
-
// Leaflet's blue teardrop. Apps that pass their own `icon` are untouched.
|
|
177
|
-
if (!defaultPinInstalled) {
|
|
178
|
-
L.Marker.prototype.options.icon = L.divIcon(mapPin());
|
|
179
|
-
defaultPinInstalled = true;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const init = initRef.current;
|
|
183
|
-
const fit = init.bounds;
|
|
184
|
-
instance = L.map(container, {
|
|
185
|
-
center: init.center,
|
|
186
|
-
zoom: init.zoom,
|
|
187
|
-
...(init.interactive
|
|
188
|
-
? {}
|
|
189
|
-
: {
|
|
190
|
-
dragging: false,
|
|
191
|
-
touchZoom: false,
|
|
192
|
-
doubleClickZoom: false,
|
|
193
|
-
scrollWheelZoom: false,
|
|
194
|
-
boxZoom: false,
|
|
195
|
-
keyboard: false,
|
|
196
|
-
zoomControl: false,
|
|
197
|
-
}),
|
|
198
|
-
...init.options,
|
|
199
|
-
});
|
|
200
|
-
if (fit) instance.fitBounds(fit, { padding: [init.boundsPadding, init.boundsPadding] });
|
|
201
|
-
|
|
202
|
-
// The embedding fix. Leaflet sizes its panes once and then trusts that
|
|
203
|
-
// number, so a map inside anything that resizes — a detail panel sliding
|
|
204
|
-
// open, a resizable split, a window resize — renders at its stale size
|
|
205
|
-
// and leaves grey gutters. Coalesced into a frame so a width transition
|
|
206
|
-
// drives it smoothly rather than 60 relayouts.
|
|
207
|
-
let fitted = !fit;
|
|
208
|
-
observer = new ResizeObserver(() => {
|
|
209
|
-
cancelAnimationFrame(frame);
|
|
210
|
-
frame = requestAnimationFrame(() => {
|
|
211
|
-
if (!instance) return;
|
|
212
|
-
instance.invalidateSize({ animate: false });
|
|
213
|
-
// Mounted hidden (an inactive tab, a collapsed panel) the initial fit
|
|
214
|
-
// ran against a 0x0 viewport. Redo it once the box is real.
|
|
215
|
-
if (!fitted && fit && container.clientWidth > 0 && container.clientHeight > 0) {
|
|
216
|
-
fitted = true;
|
|
217
|
-
instance.fitBounds(fit, { padding: [init.boundsPadding, init.boundsPadding] });
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
observer.observe(container);
|
|
222
|
-
|
|
223
|
-
leafletRef.current = L;
|
|
224
|
-
setMap(instance);
|
|
225
|
-
init.onReady?.(instance, L);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
return () => {
|
|
229
|
-
disposed = true;
|
|
230
|
-
cancelAnimationFrame(frame);
|
|
231
|
-
observer?.disconnect();
|
|
232
|
-
instance?.remove();
|
|
233
|
-
leafletRef.current = null;
|
|
234
|
-
setMap(null);
|
|
235
|
-
};
|
|
236
|
-
}, []);
|
|
237
|
-
|
|
238
|
-
/* Theme-following basemap. The tokens do the work for the map's own chrome
|
|
239
|
-
* (it is all var(--card) / var(--foreground)), but tiles are images on a
|
|
240
|
-
* server — a light basemap under a dark UI is the one part that cannot
|
|
241
|
-
* follow by cascade, so watch the class the shell's ThemeProvider toggles. */
|
|
242
|
-
const [dark, setDark] = React.useState(false);
|
|
243
|
-
|
|
244
|
-
React.useEffect(() => {
|
|
245
|
-
if (tiles !== 'auto') return;
|
|
246
|
-
const read = () => setDark(!!containerRef.current?.closest('.dark'));
|
|
247
|
-
read();
|
|
248
|
-
const observer = new MutationObserver(read);
|
|
249
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
|
250
|
-
return () => observer.disconnect();
|
|
251
|
-
}, [tiles]);
|
|
252
|
-
|
|
253
|
-
const resolved = tiles === 'auto' ? (dark ? 'dark' : 'light') : tiles;
|
|
254
|
-
|
|
255
|
-
/* Serialised so an inline `tiles={{ url: ... }}` doesn't re-add the layer on
|
|
256
|
-
* every render, and so switching preset (light -> satellite) swaps it. */
|
|
257
|
-
const tileKey = JSON.stringify(
|
|
258
|
-
typeof resolved === 'string' ? MAP_TILES[resolved] : (resolved ?? null),
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
React.useEffect(() => {
|
|
262
|
-
const L = leafletRef.current;
|
|
263
|
-
const spec = JSON.parse(tileKey) as MapTileSpec | null;
|
|
264
|
-
if (!map || !L || !spec) return;
|
|
265
|
-
const { url, ...tileOptions } = spec;
|
|
266
|
-
const layer = L.tileLayer(url, tileOptions).addTo(map);
|
|
267
|
-
return () => {
|
|
268
|
-
layer.remove();
|
|
269
|
-
};
|
|
270
|
-
}, [map, tileKey]);
|
|
271
|
-
|
|
272
|
-
return (
|
|
273
|
-
<div
|
|
274
|
-
data-slot="map"
|
|
275
|
-
/* `isolate`: Leaflet's panes and controls climb to z-index 1000, which is
|
|
276
|
-
* high enough to paint over dialogs, dropdowns and the shell's own
|
|
277
|
-
* chrome. A stacking context keeps that ladder inside the map's box.
|
|
278
|
-
* Fills its parent by default — give the parent a height, or override
|
|
279
|
-
* with a height class. */
|
|
280
|
-
className={cn('relative isolate h-full w-full overflow-hidden', className)}
|
|
281
|
-
{...props}
|
|
282
|
-
>
|
|
283
|
-
{/* Surface and typeface are set in map.css, not here: Leaflet's own
|
|
284
|
-
* .leaflet-container rules are unlayered and outrank any utility. */}
|
|
285
|
-
<div ref={containerRef} data-slot="map-canvas" className="absolute inset-0" />
|
|
286
|
-
{/* Overlays — legends, counters, toolbars. Position them absolutely; the
|
|
287
|
-
* map's panes sit at z-index 400-700 and its controls at 800-1000. */}
|
|
288
|
-
{children}
|
|
289
|
-
</div>
|
|
290
|
-
);
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
export { MapView, MAP_TILES, mapPin };
|
|
294
|
-
export type { MapViewProps, MapTilePreset, MapTileSpec, MapPinOptions, MapPinTone };
|