@element-editor/react 0.3.0 → 0.3.2

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.
@@ -0,0 +1,692 @@
1
+ import { jsx as o, jsxs as T, Fragment as Se } from "react/jsx-runtime";
2
+ import Dt, { useEffect as K, useRef as S, useLayoutEffect as Y, useState as j, Suspense as V, useCallback as W, forwardRef as Kt, useMemo as mt, useImperativeHandle as Ce } from "react";
3
+ import { useElementEditorConfig as pt, useGeoStore as Wt, useUIStore as g, Button as we, ZoomIndicator as Ee, LocateButton as Re, FitBoundsButton as ke, RedoButton as Oe, UndoButton as Me, FloatingToolbar as Te, useShortcutConfig as ht, IconButton as Z, KbdDark as gt, DataTablePanel as Gt, LayersPanel as Ut, FeatureEditModal as Be, ShortcutsModal as Le, SettingsModal as Pe, SchemaModal as Ne, GeoJSONModal as $e, GeoJSONDockPlaceholder as Ae, ElementEditorErrorBoundary as Fe, ElementEditorConfigProvider as je, GeoStoreProvider as Ie, ShortcutConfigProvider as _e, MapControllerProvider as De, useMapController as ze, useAdapterControls as Ve, ThemeContext as Ke, EventProvider as We, EditingToolbar as Ge, ActiveDrawingToolbar as Ue, SimplifyPanel as Je, SmoothPanel as qe, BufferPanel as He, ReadonlyBanner as Xe, ControlGroup as Ye } from "@element-editor/ui";
4
+ import { useGeoJSONFileImport as Ze, layoutGaps as Qe, LAYOUT_SLOTS as to, useRootTokens as eo, RootCssVarsContext as oo, RootTokensContext as ro, visibleLayoutEntries as no, isControlVisible as so } from "@element-editor/ui/internal";
5
+ import { writePersisted as io, readPersisted as ao, getFeatureCollectionBBox as Jt, readStorage as lo } from "@element-editor/core";
6
+ import { warnOnce as I, normalizeBounds as co, isDevBuild as uo } from "@element-editor/core/internal";
7
+ import { Check as fo, Keyboard as mo, SlidersHorizontal as po, Code as ho, TreeStructure as go, Table as bo, FileArrowUp as yo } from "@phosphor-icons/react";
8
+ const qt = "elm_mapView", Ht = 1, vo = { center: [10, 48], zoom: 5 }, Ho = 40, Xo = 16;
9
+ function Xt(e) {
10
+ try {
11
+ const r = ao(qt, Ht, (t) => {
12
+ if (!t || typeof t != "object") return null;
13
+ const n = t;
14
+ return typeof n.lat == "number" && typeof n.lng == "number" && typeof n.zoom == "number" ? { lat: n.lat, lng: n.lng, zoom: n.zoom } : null;
15
+ }, e);
16
+ if (r) return { center: [r.lng, r.lat], zoom: r.zoom };
17
+ } catch {
18
+ }
19
+ return null;
20
+ }
21
+ function Yo(e, r, t, n) {
22
+ io(qt, Ht, { lat: e, lng: r, zoom: t }, n);
23
+ }
24
+ const zt = (...e) => e.every((r) => typeof r == "number" && Number.isFinite(r));
25
+ function Yt(e) {
26
+ if (!e) return null;
27
+ try {
28
+ const r = e, t = r.type === "Feature" ? { type: "FeatureCollection", features: [r] } : r;
29
+ return Jt(t);
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+ function xo(e, r) {
35
+ if (e === "data") return /* @__PURE__ */ ((t) => t ? { bounds: t } : null)(Yt(r));
36
+ if (e && typeof e == "object") {
37
+ if ("bounds" in e) {
38
+ const t = e.bounds;
39
+ if (Array.isArray(t) && t.length === 4 && zt(...t)) return { bounds: [t[0], t[1], t[2], t[3]] };
40
+ } else if ("center" in e) {
41
+ const t = e.center;
42
+ if (Array.isArray(t) && t.length === 2 && zt(t[0], t[1], e.zoom)) return { center: [t[0], t[1]], zoom: e.zoom };
43
+ }
44
+ }
45
+ return I("initialView-invalid", `initialView=${JSON.stringify(e)} is not { center: [lng, lat], zoom }, { bounds: [west, south, east, north] } or 'data'; it was ignored.`), null;
46
+ }
47
+ function Zo({ initialView: e, initialData: r, bounds: t }, n) {
48
+ const s = e === void 0 ? null : xo(e, r);
49
+ if (s) return s;
50
+ const i = Xt(n);
51
+ if (i) return i;
52
+ const m = e === "data" ? null : Yt(r);
53
+ if (m) return { bounds: m };
54
+ const a = co(t);
55
+ return a ? { bounds: a } : vo;
56
+ }
57
+ function Qo(e, r, t) {
58
+ if (!e || typeof e != "object") return {};
59
+ const n = {};
60
+ for (const [s, i] of Object.entries(e))
61
+ s in r ? i !== void 0 && I(`mapOptions-${t}-${s}`, `<ElementEditor mapOptions.${s}> is set by Element and was ignored. ${r[s]}`) : n[s] = i;
62
+ return n;
63
+ }
64
+ const So = "--elm-row-hover", Co = 1500;
65
+ function wo(e, r) {
66
+ K(() => {
67
+ if (!uo()) return;
68
+ const t = e.current;
69
+ if (!t || typeof getComputedStyle != "function") return;
70
+ const n = r === "leaflet" ? "@element-editor/react/leaflet/style.css" : "@element-editor/react/style.css", s = requestAnimationFrame(() => {
71
+ if (!t.isConnected || t.getClientRects().length === 0) return;
72
+ const { width: m, height: a } = t.getBoundingClientRect();
73
+ (a === 0 || m === 0) && I("editor-zero-size", `<ElementEditor> is ${Math.round(m)}×${Math.round(a)} px, so the map is blank. It fills its parent element (width and height 100%): give the parent an explicit size, e.g. <div style={{ height: 600 }}><ElementEditor /></div>, or a flex / grid layout that gives it one (a parent with only \`height: auto\` collapses to 0).`);
74
+ }), i = setTimeout(() => {
75
+ t.isConnected && getComputedStyle(t).getPropertyValue(So).trim() === "" && I("editor-css-missing", `Element's stylesheet is not loaded, so the toolbar and panels are unstyled. Import it once, near your app's entry point: import '${n}'`);
76
+ }, Co);
77
+ return () => {
78
+ cancelAnimationFrame(s), clearTimeout(i);
79
+ };
80
+ }, [e, r]);
81
+ }
82
+ function Eo(e) {
83
+ const r = pt(), { uiStore: t } = Wt(), n = g((a) => a.userTheme), s = S(!1);
84
+ s.current || (s.current = !0, e === void 0 && r.mode !== "system" && (lo("elm_theme", r) || t.setState({ userTheme: r.mode }))), Y(() => {
85
+ e !== void 0 && t.setState({ userTheme: e === "auto" ? "system" : e });
86
+ }, [e, t]);
87
+ const [i, m] = j(
88
+ () => typeof window < "u" && window.matchMedia("(prefers-color-scheme: dark)").matches
89
+ );
90
+ return K(() => {
91
+ if (n !== "system") return;
92
+ const a = window.matchMedia("(prefers-color-scheme: dark)"), p = (d) => m(d.matches);
93
+ return a.addEventListener("change", p), () => a.removeEventListener("change", p);
94
+ }, [n]), n === "dark" ? "dark" : n === "light" ? "light" : i ? "dark" : "light";
95
+ }
96
+ function Ro(e, r) {
97
+ const t = S(null), n = S(null), s = S(null), i = S(null), m = S(null), a = S(null), p = S(null), d = S(null), u = S(null), b = S(null), v = S(null);
98
+ return Y(() => {
99
+ const C = t.current;
100
+ if (!C || e) return;
101
+ const w = () => parseFloat(C.style.getPropertyValue("--elm-panel-offset")) || 0, O = (l) => l && l.offsetWidth > 0 ? l.getBoundingClientRect() : null, _ = (l) => l.flatMap((c) => getComputedStyle(c).display === "contents" ? _([...c.children]) : [c.offsetWidth]), bt = (l) => {
102
+ const c = _([...l.children]).filter((y) => y > 0);
103
+ return c.length ? getComputedStyle(l).flexDirection.startsWith("column") ? Math.max(...c) : c.reduce((y, x) => y + x, 0) + 8 * (c.length - 1) : 0;
104
+ }, Q = (l, c, y) => {
105
+ var h;
106
+ if (!l) return !0;
107
+ const x = (((h = l.parentElement) == null ? void 0 : h.clientWidth) ?? 0) - 32 - w(), R = `${Math.max(0, Math.floor(x))}px`;
108
+ l.style.getPropertyValue("--elm-row-room") !== R && l.style.setProperty("--elm-row-room", R);
109
+ const k = [...l.children].reduce((E, z) => E + bt(z), 16) + c > x + 0.5, M = k && c ? `${c}px` : "";
110
+ return l.dataset.elmClearance = String(c), l.hasAttribute("data-elm-wrap") === k && l.style.paddingRight === M ? !0 : y ? !1 : (l.toggleAttribute("data-elm-wrap", k), l.style.paddingRight = M, !0);
111
+ };
112
+ let G = 0;
113
+ const D = (l = !1) => {
114
+ if (!(Q(n.current, r, l) && Q(s.current, 0, l))) {
115
+ G || (G = requestAnimationFrame(() => {
116
+ G = 0, D();
117
+ }));
118
+ return;
119
+ }
120
+ const y = O(p.current), x = O(s.current), R = O(i.current), L = O(m.current), k = O(a.current), M = (E) => !!(y && E && y.left < E.right + 8 && E.left < y.right + 8);
121
+ let h = L ? L.height + 8 : 0;
122
+ x && (M(R) || M(k)) && (h = Math.max(h, x.height + 8)), C.style.setProperty("--elm-bottom-row-height", `${h}px`), et(b.current, "--elm-left-center-shift"), et(v.current, "--elm-right-center-shift");
123
+ }, tt = {}, et = (l, c) => {
124
+ const y = tt[c] ?? 0, x = O(l);
125
+ let R = 0;
126
+ if (x) {
127
+ const L = x.top - y;
128
+ let k = -1 / 0, M = 1 / 0;
129
+ for (const E of [n.current, s.current])
130
+ for (const z of (E == null ? void 0 : E.children) ?? []) {
131
+ const P = O(z);
132
+ !P || P.height === 0 || P.right + 8 <= x.left || x.right + 8 <= P.left || (E === n.current ? k = Math.max(k, P.bottom + 8) : M = Math.min(M, P.top - 8));
133
+ }
134
+ R = (L < k ? k : L + x.height > M ? Math.max(k, M - x.height) : L) - L;
135
+ }
136
+ R !== y && (tt[c] = R, C.style.setProperty(c, `${R}px`));
137
+ }, U = new ResizeObserver(() => D(!0));
138
+ for (const l of [n, s, i, m, a, p, d, u, b, v])
139
+ l.current && U.observe(l.current);
140
+ for (const l of [n.current, s.current])
141
+ for (const c of (l == null ? void 0 : l.children) ?? []) {
142
+ U.observe(c);
143
+ for (const y of c.querySelectorAll(":scope > *, :scope > .contents > *")) U.observe(y);
144
+ }
145
+ const ot = (l) => {
146
+ var c, y;
147
+ (l.target === C || (y = (c = l.target).matches) != null && y.call(c, "[data-elm-slot], [data-elm-edge]")) && D();
148
+ };
149
+ C.addEventListener("transitionend", ot);
150
+ let rt = w();
151
+ const nt = new MutationObserver(() => {
152
+ w() !== rt && (rt = w(), D());
153
+ });
154
+ return nt.observe(C, { attributes: !0, attributeFilter: ["style"] }), D(), () => {
155
+ cancelAnimationFrame(G), U.disconnect(), nt.disconnect(), C.removeEventListener("transitionend", ot);
156
+ for (const l of ["--elm-bottom-row-height", "--elm-left-center-shift", "--elm-right-center-shift"]) C.style.setProperty(l, "0px");
157
+ };
158
+ }, [e, r]), {
159
+ rootRef: t,
160
+ topRowRef: n,
161
+ bottomRowRef: s,
162
+ bottomLeftRef: i,
163
+ bottomCenterRef: m,
164
+ bottomRightRef: a,
165
+ contextualRef: p,
166
+ leftEdgeRef: d,
167
+ rightEdgeRef: u,
168
+ leftCenterRef: b,
169
+ rightCenterRef: v
170
+ };
171
+ }
172
+ function ko({ size: e, tooltipSide: r }) {
173
+ const t = g((a) => a.shortcutsModalOpen), n = g((a) => a.openShortcutsModal), s = g((a) => a.closeShortcutsModal), { getKey: i } = ht(), m = i("show-shortcuts").toUpperCase();
174
+ return /* @__PURE__ */ o(
175
+ Z,
176
+ {
177
+ label: "Show keyboard shortcuts",
178
+ shortcutId: "show-shortcuts",
179
+ tooltipContent: "Keyboard shortcuts",
180
+ shortcut: /* @__PURE__ */ o(gt, { children: m }),
181
+ onClick: t ? s : n,
182
+ active: t,
183
+ size: e,
184
+ tooltipSide: r,
185
+ children: /* @__PURE__ */ o(mo, { size: 24 })
186
+ }
187
+ );
188
+ }
189
+ function Oo({ size: e, side: r }) {
190
+ const t = g((i) => i.tableOpen), n = g((i) => i.toggleTable), { getKey: s } = ht();
191
+ return /* @__PURE__ */ o(
192
+ Z,
193
+ {
194
+ size: e,
195
+ tooltipSide: r,
196
+ label: t ? "Hide table" : "Show table",
197
+ shortcutId: "toggle-table",
198
+ shortcut: /* @__PURE__ */ o(gt, { children: s("toggle-table").toUpperCase() }),
199
+ onClick: n,
200
+ active: t,
201
+ children: /* @__PURE__ */ o(bo, { size: 24 })
202
+ }
203
+ );
204
+ }
205
+ function Mo({ size: e, side: r }) {
206
+ const t = g((i) => i.schemaModalOpen), n = g((i) => i.toggleSchemaModal), { getKey: s } = ht();
207
+ return /* @__PURE__ */ o(
208
+ Z,
209
+ {
210
+ size: e,
211
+ tooltipSide: r,
212
+ label: "Edit schema",
213
+ shortcutId: "toggle-schema",
214
+ shortcut: /* @__PURE__ */ o(gt, { children: s("toggle-schema").toUpperCase() }),
215
+ onClick: n,
216
+ active: t,
217
+ children: /* @__PURE__ */ o(go, { size: 24 })
218
+ }
219
+ );
220
+ }
221
+ function To({ size: e, side: r }) {
222
+ const t = g((i) => i.codeModalOpen), n = g((i) => i.toggleCodeModal), { getKey: s } = ht();
223
+ return /* @__PURE__ */ o(
224
+ Z,
225
+ {
226
+ size: e,
227
+ tooltipSide: r,
228
+ label: "Show GeoJSON",
229
+ shortcutId: "toggle-geojson",
230
+ shortcut: /* @__PURE__ */ o(gt, { children: s("toggle-geojson").toUpperCase() }),
231
+ onClick: n,
232
+ active: t,
233
+ children: /* @__PURE__ */ o(ho, { size: 24 })
234
+ }
235
+ );
236
+ }
237
+ function Bo({ size: e, side: r }) {
238
+ const t = g((s) => s.settingsModalOpen), n = g((s) => s.setSettingsModalOpen);
239
+ return /* @__PURE__ */ o(
240
+ Z,
241
+ {
242
+ size: e,
243
+ tooltipSide: r,
244
+ label: "Editor settings",
245
+ onClick: () => n(!t),
246
+ active: t,
247
+ children: /* @__PURE__ */ o(po, { size: 24 })
248
+ }
249
+ );
250
+ }
251
+ function Lo({ id: e, size: r, side: t, onSubmit: n, basemapControl: s, attributionRef: i }) {
252
+ switch (e) {
253
+ case "toolbar":
254
+ return /* @__PURE__ */ o(Te, { embedded: !0 });
255
+ case "undo":
256
+ return /* @__PURE__ */ o(Me, { size: r, tooltipSide: t });
257
+ case "redo":
258
+ return /* @__PURE__ */ o(Oe, { size: r, tooltipSide: t });
259
+ case "fitBounds":
260
+ return /* @__PURE__ */ o(ke, { size: r, tooltipSide: t });
261
+ case "locate":
262
+ return /* @__PURE__ */ o(Re, { size: r, tooltipSide: t });
263
+ case "zoomIndicator":
264
+ return /* @__PURE__ */ o(Ee, { size: r, tooltipSide: t });
265
+ case "table":
266
+ return /* @__PURE__ */ o(Oo, { size: r, side: t });
267
+ case "schema":
268
+ return /* @__PURE__ */ o(Mo, { size: r, side: t });
269
+ case "geojson":
270
+ return /* @__PURE__ */ o(To, { size: r, side: t });
271
+ case "settings":
272
+ return /* @__PURE__ */ o(Bo, { size: r, side: t });
273
+ case "keyboard":
274
+ return /* @__PURE__ */ o(ko, { size: r, tooltipSide: t });
275
+ case "applyChanges":
276
+ return /* @__PURE__ */ T(
277
+ we,
278
+ {
279
+ variant: "primary",
280
+ onClick: n,
281
+ className: r === "group" ? "h-8 !rounded-elm-control !px-3 gap-1.5 !text-sm" : "h-12 !rounded-elm shadow-elm-control !px-5 gap-2 !text-sm",
282
+ children: [
283
+ /* @__PURE__ */ o(fo, { size: 20, weight: "bold" }),
284
+ "Apply changes"
285
+ ]
286
+ }
287
+ );
288
+ case "attribution":
289
+ return /* @__PURE__ */ o(
290
+ "span",
291
+ {
292
+ ref: i,
293
+ "data-elm-attribution": "",
294
+ onMouseEnter: (m) => {
295
+ var a;
296
+ m.currentTarget.title = ((a = m.currentTarget.textContent) == null ? void 0 : a.trim()) ?? "";
297
+ }
298
+ }
299
+ );
300
+ // The control is built by the engine wrapper, so it gets the slot's size and tooltip side here (compact in the status bar).
301
+ case "basemap":
302
+ return Dt.isValidElement(s) ? Dt.cloneElement(s, { size: r, tooltipSide: t }) : null;
303
+ default:
304
+ return null;
305
+ }
306
+ }
307
+ function Po() {
308
+ const e = pt();
309
+ return /* @__PURE__ */ T("div", { className: "absolute bottom-0 left-0 w-full h-1/3 bg-elm-surface border-t border-elm-border z-[400] flex shadow-[0_-8px_12px_-8px_rgb(0_0_0/0.12)]", children: [
310
+ e.ui.dataTable && /* @__PURE__ */ o("div", { className: "flex-1 h-full relative overflow-hidden border-r border-elm-border", children: /* @__PURE__ */ o(V, { fallback: null, children: /* @__PURE__ */ o(Gt, { embedded: !0 }) }) }),
311
+ e.ui.layerList && /* @__PURE__ */ o("div", { className: "w-[320px] flex-shrink-0 h-full relative overflow-hidden bg-elm-surface", children: /* @__PURE__ */ o(Ut, {}) })
312
+ ] });
313
+ }
314
+ function No({ layout: e }) {
315
+ const r = pt(), t = g((u) => u.dialogState), n = g((u) => u.schemaModalOpen), s = g((u) => u.toggleSchemaModal), i = g((u) => u.readonly), m = g((u) => u.codeModalOpen), a = g((u) => u.toggleCodeModal), p = g((u) => u.settingsModalOpen), d = g((u) => u.shortcutsModalOpen);
316
+ return /* @__PURE__ */ T(Se, { children: [
317
+ e === "minimal" && t.type !== "closed" && /* @__PURE__ */ o(V, { fallback: null, children: /* @__PURE__ */ o(Be, { dialogState: t }) }),
318
+ r.ui.dataTable && e !== "split" && /* @__PURE__ */ o(V, { fallback: null, children: /* @__PURE__ */ o(Gt, {}) }),
319
+ r.ui.keyboardShortcuts.show && d && /* @__PURE__ */ o(V, { fallback: null, children: /* @__PURE__ */ o(Le, {}) }),
320
+ r.ui.settings && p && /* @__PURE__ */ o(V, { fallback: null, children: /* @__PURE__ */ o(Pe, {}) }),
321
+ r.ui.schemaEditor && n && !i && /* @__PURE__ */ o(V, { fallback: null, children: /* @__PURE__ */ o(Ne, { onClose: s }) }),
322
+ r.ui.geojsonEditor && m && /* @__PURE__ */ o(V, { fallback: /* @__PURE__ */ o(Ae, {}), children: /* @__PURE__ */ o($e, { onClose: a }) })
323
+ ] });
324
+ }
325
+ const ft = (e) => {
326
+ var r, t, n, s;
327
+ return !((t = (r = e.dataTransfer) == null ? void 0 : r.types) != null && t.includes("Files")) || !!((s = (n = e.target).closest) != null && s.call(n, ".cm-editor"));
328
+ };
329
+ function $o(e) {
330
+ const r = Ze(), [t, n] = j(!1), s = S(0), i = W((d) => {
331
+ !e || ft(d) || (d.preventDefault(), d.stopPropagation(), s.current += 1, n(!0));
332
+ }, [e]), m = W((d) => {
333
+ !e || ft(d) || (d.preventDefault(), d.stopPropagation(), d.dataTransfer.dropEffect = "copy");
334
+ }, [e]), a = W((d) => {
335
+ !e || ft(d) || (d.stopPropagation(), s.current = Math.max(0, s.current - 1), s.current === 0 && n(!1));
336
+ }, [e]), p = W((d) => {
337
+ var b;
338
+ if (s.current = 0, n(!1), !e || ft(d)) return;
339
+ d.preventDefault(), d.stopPropagation();
340
+ const u = (b = d.dataTransfer.files) == null ? void 0 : b[0];
341
+ u && r(u);
342
+ }, [e, r]);
343
+ return { active: e && t, handlers: { onDragEnter: i, onDragOver: m, onDragLeave: a, onDrop: p } };
344
+ }
345
+ function Ao({ enabled: e, children: r, footer: t }) {
346
+ const n = $o(e);
347
+ return /* @__PURE__ */ T("div", { style: { display: "contents" }, ...n.handlers, children: [
348
+ /* @__PURE__ */ T("div", { className: "relative flex-1 min-h-0 flex", children: [
349
+ r,
350
+ n.active && /* @__PURE__ */ o("div", { "data-elm-file-drop": "", className: "absolute inset-0 z-[1000] flex items-center justify-center pointer-events-none bg-gray-900/10 dark:bg-black/30 border-2 border-dashed border-primary-500 rounded-sm", children: /* @__PURE__ */ T("div", { className: "flex items-center gap-2 px-4 py-2 bg-elm-surface/95 backdrop-blur-md border border-elm-border/80 shadow-elm rounded-elm text-sm text-(--elm-text-secondary,var(--color-gray-700)) dark:text-(--elm-text-secondary,var(--color-gray-200)) antialiased select-none", children: [
351
+ /* @__PURE__ */ o(yo, { size: 20, className: "text-elm-text-muted" }),
352
+ /* @__PURE__ */ o("span", { children: "Drop GeoJSON to import" })
353
+ ] }) })
354
+ ] }),
355
+ t
356
+ ] });
357
+ }
358
+ const kt = "in-data-[elm-wrap]:flex-wrap in-data-[elm-wrap]:max-w-full", Ot = "in-data-[elm-wrap]:flex-wrap-reverse in-data-[elm-wrap]:max-w-full", Fo = {
359
+ topLeft: [`flex-row items-start ${kt}`, "flex-col items-start"],
360
+ topCenter: [`flex-row items-start justify-center ${kt}`, "flex-col items-center"],
361
+ topRight: [`flex-row-reverse items-start ${kt}`, "flex-col items-end"],
362
+ leftCenter: ["flex-row items-center", "flex-col items-start"],
363
+ rightCenter: ["flex-row-reverse items-center", "flex-col items-end"],
364
+ bottomLeft: [`flex-row items-end ${Ot}`, "flex-col-reverse items-start"],
365
+ bottomCenter: [`flex-row items-end justify-center ${Ot}`, "flex-col-reverse items-center"],
366
+ bottomRight: [`flex-row-reverse items-end ${Ot}`, "flex-col-reverse items-end"]
367
+ }, jo = Kt(({
368
+ initialData: e,
369
+ initialView: r,
370
+ schema: t,
371
+ tools: n,
372
+ maxFeatures: s,
373
+ geometryTypes: i,
374
+ replaceAtLimit: m,
375
+ autoExitAfterDraw: a,
376
+ coordinates: p,
377
+ bounds: d,
378
+ readonly: u = !1,
379
+ layout: b = "panel",
380
+ className: v = "",
381
+ style: C,
382
+ theme: w,
383
+ onChange: O,
384
+ onSubmit: _,
385
+ onValidationError: bt,
386
+ onFeatureSelect: Q,
387
+ onZoomChange: G,
388
+ onEvent: D,
389
+ onError: tt,
390
+ onFeatureAdd: et,
391
+ onFeatureUpdate: U,
392
+ onFeatureDelete: ot,
393
+ onSelectionChange: rt,
394
+ onToolChange: nt,
395
+ onVertexEditChange: l,
396
+ slots: c,
397
+ renderMap: y,
398
+ basemapControl: x,
399
+ extraApi: R,
400
+ fileDrop: L = !0,
401
+ engine: k = "maplibre"
402
+ }, M) => {
403
+ const h = pt(), { dataStore: E, uiStore: z } = Wt(), P = ze(), J = n || (h.tools === "all" ? null : h.tools), [Mt] = j(() => r === "data" || r === void 0 && !Xt(h)), [yt, Tt] = j(null), Zt = W((f, N) => {
404
+ if (!N || !Mt) return;
405
+ const B = Jt({ type: "FeatureCollection", metadata: { schemas: [], groups: [] }, features: E.getState().features });
406
+ B && Tt(B);
407
+ }, [Mt, E]);
408
+ K(() => {
409
+ !yt || !P.fitBounds || (P.fitBounds(yt), Tt(null));
410
+ }, [yt, P]);
411
+ const st = Ve({
412
+ initialData: e,
413
+ schema: t,
414
+ layout: b,
415
+ readonly: u,
416
+ tools: J,
417
+ maxFeatures: s,
418
+ geometryTypes: i,
419
+ replaceAtLimit: m,
420
+ autoExitAfterDraw: a,
421
+ coordinates: p,
422
+ onChange: O,
423
+ onSubmit: _,
424
+ onValidationError: bt,
425
+ onFeatureAdd: et,
426
+ onFeatureUpdate: U,
427
+ onFeatureDelete: ot,
428
+ onSelectionChange: rt,
429
+ onFeatureSelect: Q,
430
+ onZoomChange: G,
431
+ onToolChange: nt,
432
+ onVertexEditChange: l,
433
+ onInitialDataApplied: Zt
434
+ }), vt = mt(() => R ? { ...st, ...R } : st, [st, R]);
435
+ Ce(M, () => vt, [vt]), K(() => {
436
+ }, [E, z, vt]), Y(() => {
437
+ z.getState().setBounds(d);
438
+ }, [d, z]);
439
+ const $ = g((f) => f.tableFullscreen), Qt = g((f) => f.sidebarOpen), xt = w !== null && typeof w == "object";
440
+ K(() => {
441
+ xt && I("theme-object", "<ElementEditor theme> takes only 'light' | 'dark' | 'auto'; the object is ignored. Set CSS variables with `style` (e.g. style={{ '--elm-accent': '#7c3aed' }}) or the brand colour with `accentColor`.");
442
+ }, [xt]);
443
+ const St = Eo(xt ? void 0 : w), te = {
444
+ ...h.accentColor ? { "--elm-accent": h.accentColor } : {},
445
+ // Bottom edge of the contextual bottom-center stack (EditingToolbar, …).
446
+ // --elm-bottom-row-height is the measured lift (see below).
447
+ "--elm-bottom-stack-offset": b === "split" ? "calc(33.33% + 16px + var(--elm-bottom-row-height, 0px))" : "calc(var(--elm-table-offset, 0px) + var(--elm-bottom-row-height, 0px) + 16px)",
448
+ ...C
449
+ }, Bt = C ? Object.entries(C).filter(([f, N]) => f.startsWith("--") && N != null && N !== "") : [], Ct = Bt.length ? JSON.stringify(Bt) : "", ee = mt(
450
+ () => Ct ? Object.fromEntries(JSON.parse(Ct)) : void 0,
451
+ [Ct]
452
+ ), oe = (f) => so(f, h.ui, { readonly: u, canSubmit: !!_, hasBasemaps: !!x }), it = (f) => no(h.ui.layout[f].items, oe), Lt = h.ui.keyboardShortcuts.enabled, re = (J == null ? void 0 : J.join()) ?? null;
453
+ K(() => {
454
+ for (const f of Qe(h.ui.layout, { readonly: u, canSubmit: !!_, tools: J, shortcuts: Lt }))
455
+ I(`layoutGap:${f}`, `config.ui.layout: ${f}.`);
456
+ }, [h.ui.layout, u, !!_, re, Lt]);
457
+ const [Pt, ne] = j(null), [se, ie] = j(null), Nt = (f, N, B) => /* @__PURE__ */ o(
458
+ Lo,
459
+ {
460
+ id: f,
461
+ size: N,
462
+ side: B,
463
+ onSubmit: st.submit,
464
+ basemapControl: x,
465
+ attributionRef: ne
466
+ },
467
+ f
468
+ ), wt = (f, N) => {
469
+ const B = f === "statusLeft" || f === "statusRight", q = h.ui.layout[f].direction === "vertical", ut = q ? f.endsWith("Right") || f === "rightCenter" ? "left" : "right" : f.startsWith("top") ? "bottom" : "top", H = (A) => /* @__PURE__ */ o("div", { "aria-hidden": !0, "data-elm-separator": "", className: `flex-shrink-0 bg-elm-border ${B ? "w-px h-4 mx-1" : q ? "h-px w-5 my-0.5" : "w-px h-5 mx-1"}` }, A);
470
+ return N.map((A, X) => {
471
+ if (A === "separator") return H(`sep-${X}`);
472
+ if (typeof A == "string") return Nt(A, B ? "sm" : "md", ut);
473
+ const dt = A.group.map((_t, xe) => _t === "separator" ? H(`gsep-${xe}`) : Nt(_t, B ? "sm" : "group", ut));
474
+ return B ? /* @__PURE__ */ o("div", { "data-elm-group": "", className: "flex items-center", children: dt }, `group-${X}`) : /* @__PURE__ */ o(Ye, { direction: q ? "vertical" : "horizontal", children: dt }, `group-${X}`);
475
+ });
476
+ }, $t = to.find((f) => it(f).includes("toolbar")), F = (f, N, B, q, ut) => {
477
+ const H = it(f), A = c == null ? void 0 : c[f], [X, dt] = Fo[f];
478
+ return /* @__PURE__ */ T(
479
+ "div",
480
+ {
481
+ ref: q,
482
+ "data-elm-slot": f,
483
+ style: B,
484
+ className: `flex ${h.ui.layout[f].direction === "vertical" ? dt : X} gap-2 ${H.length || A ? "pointer-events-auto" : ""} ${N}`,
485
+ children: [
486
+ ut,
487
+ A,
488
+ wt(f, H)
489
+ ]
490
+ }
491
+ );
492
+ }, at = (...f) => $t && f.includes($t) ? "z-[500]" : "z-[400]", At = b === "panel" && h.ui.layerList && !Qt ? 56 : 0, lt = "var(--elm-panel-offset, 0px)", Et = b === "split" ? "calc(33.33% + 16px)" : "calc(var(--elm-table-offset, 0px) + 16px)", {
493
+ rootRef: ct,
494
+ topRowRef: ae,
495
+ bottomRowRef: le,
496
+ bottomLeftRef: ce,
497
+ bottomCenterRef: ue,
498
+ bottomRightRef: de,
499
+ contextualRef: fe,
500
+ leftEdgeRef: me,
501
+ rightEdgeRef: pe,
502
+ leftCenterRef: he,
503
+ rightCenterRef: ge
504
+ } = Ro($, At);
505
+ wo(ct, k);
506
+ const [be, ye] = j(null);
507
+ Y(() => {
508
+ ye(ct.current);
509
+ }, [ct]);
510
+ const ve = eo(be), Ft = it("statusLeft"), jt = it("statusRight"), It = Ft.length + jt.length > 0, Rt = It && !!Pt;
511
+ return /* @__PURE__ */ o(Ke.Provider, { value: St, children: /* @__PURE__ */ o(oo.Provider, { value: ee, children: /* @__PURE__ */ o(ro.Provider, { value: ve, children: /* @__PURE__ */ o(We, { onEvent: D, onError: tt, toaster: !0, children: /* @__PURE__ */ o(
512
+ "div",
513
+ {
514
+ ref: ct,
515
+ "data-elm-theme": St,
516
+ className: `relative w-full h-full overflow-clip bg-(--elm-surface-sunken,var(--color-gray-50)) dark:bg-(--elm-surface-sunken,var(--color-gray-950)) flex flex-col ${v}`,
517
+ style: te,
518
+ children: /* @__PURE__ */ T(Ao, { enabled: L && !u, footer: It && /* @__PURE__ */ T(
519
+ "div",
520
+ {
521
+ "data-elm-status-bar": "",
522
+ role: "toolbar",
523
+ "aria-label": "Status bar",
524
+ className: "flex-shrink-0 h-7 px-2 flex items-center justify-between gap-1 bg-elm-surface border-t border-elm-border z-[400]",
525
+ children: [
526
+ /* @__PURE__ */ o("div", { "data-elm-slot": "statusLeft", className: "flex items-center gap-1 min-w-0", children: wt("statusLeft", Ft) }),
527
+ /* @__PURE__ */ o("div", { "data-elm-slot": "statusRight", className: "flex items-center gap-1 min-w-0", children: wt("statusRight", jt) })
528
+ ]
529
+ }
530
+ ), children: [
531
+ y({ attributionTarget: Rt ? Pt : null, attributionCorner: Rt ? null : se, themeMode: St }),
532
+ !$ && (c == null ? void 0 : c.toolbar),
533
+ !$ && (c == null ? void 0 : c.mapOverlay) && /* @__PURE__ */ o("div", { className: "absolute inset-0 z-[300] pointer-events-none", children: c.mapOverlay }),
534
+ !$ && /* @__PURE__ */ T(
535
+ "div",
536
+ {
537
+ ref: ae,
538
+ "data-elm-edge": "top",
539
+ style: { top: 16, left: 16, right: `calc(${lt} + 16px)` },
540
+ className: `absolute ${at("topLeft", "topCenter", "topRight")} transition-[right] duration-200 grid grid-cols-[1fr_auto_1fr] items-start gap-2 pointer-events-none data-[elm-wrap]:flex data-[elm-wrap]:flex-wrap`,
541
+ children: [
542
+ F("topLeft", "justify-self-start"),
543
+ F("topCenter", "justify-self-center mx-auto"),
544
+ F("topRight", "justify-self-end ml-auto transition-[margin] duration-200 in-data-[elm-wrap]:mr-0!", { marginRight: At })
545
+ ]
546
+ }
547
+ ),
548
+ !$ && /* @__PURE__ */ o(
549
+ "div",
550
+ {
551
+ ref: me,
552
+ "data-elm-edge": "left",
553
+ style: { top: 16, bottom: Et, left: 16 },
554
+ className: `absolute ${at("leftCenter")} flex flex-col justify-center pointer-events-none`,
555
+ children: F("leftCenter", "relative", { top: "var(--elm-left-center-shift, 0px)" }, he)
556
+ }
557
+ ),
558
+ !$ && /* @__PURE__ */ o(
559
+ "div",
560
+ {
561
+ ref: pe,
562
+ "data-elm-edge": "right",
563
+ style: { top: 16, bottom: Et, right: `calc(${lt} + 16px)` },
564
+ className: `absolute ${at("rightCenter")} flex flex-col justify-center pointer-events-none transition-[right] duration-200`,
565
+ children: F("rightCenter", "relative", { top: "var(--elm-right-center-shift, 0px)" }, ge)
566
+ }
567
+ ),
568
+ !$ && /* @__PURE__ */ T(
569
+ "div",
570
+ {
571
+ ref: le,
572
+ "data-elm-edge": "bottom",
573
+ style: { bottom: Et, left: 16, right: `calc(${lt} + 16px)` },
574
+ className: `absolute ${at("bottomLeft", "bottomCenter", "bottomRight")} transition-[right] duration-200 grid grid-cols-[1fr_auto_1fr] items-end gap-2 pointer-events-none data-[elm-wrap]:flex data-[elm-wrap]:flex-wrap-reverse`,
575
+ children: [
576
+ F("bottomLeft", "justify-self-start", void 0, ce),
577
+ F("bottomCenter", "justify-self-center mx-auto", void 0, ue),
578
+ F(
579
+ "bottomRight",
580
+ "justify-self-end ml-auto max-w-full",
581
+ void 0,
582
+ de,
583
+ // One line when the row has room for it (max-content), else as wide as the whole row
584
+ // (--elm-row-room, written by useSlotAutoLayout): its width never depends on whether
585
+ // the row wraps, so the wrap decision can't flip-flop.
586
+ !Rt && /* @__PURE__ */ o(
587
+ "div",
588
+ {
589
+ ref: ie,
590
+ "data-elm-attribution-corner": "",
591
+ className: "pointer-events-auto flex items-end justify-end w-max",
592
+ style: { maxWidth: "var(--elm-row-room, 100%)" }
593
+ }
594
+ )
595
+ )
596
+ ]
597
+ }
598
+ ),
599
+ !$ && /* @__PURE__ */ o(
600
+ "div",
601
+ {
602
+ className: "absolute z-[400] flex justify-center pointer-events-none transition-[right] duration-200",
603
+ style: { bottom: "var(--elm-bottom-stack-offset)", left: 16, right: `calc(${lt} + 16px)` },
604
+ children: /* @__PURE__ */ T("div", { ref: fe, "data-elm-contextual": "", className: "flex flex-wrap justify-center gap-2 max-w-full min-w-0", children: [
605
+ /* @__PURE__ */ o(Ge, {}),
606
+ /* @__PURE__ */ o(Ue, {}),
607
+ /* @__PURE__ */ o(Je, {}),
608
+ /* @__PURE__ */ o(qe, {}),
609
+ /* @__PURE__ */ o(He, {}),
610
+ /* @__PURE__ */ o(Xe, {})
611
+ ] })
612
+ }
613
+ ),
614
+ !$ && h.ui.layerList && b === "panel" && /* @__PURE__ */ o(Ut, { footer: c == null ? void 0 : c.panelFooter }),
615
+ b === "split" && /* @__PURE__ */ o(Po, {}),
616
+ /* @__PURE__ */ o(No, { layout: b })
617
+ ] })
618
+ }
619
+ ) }) }) }) });
620
+ }), Io = Kt((e, r) => {
621
+ var u;
622
+ const { config: t, accentColor: n, featureColor: s, routingApiKey: i, onError: m } = e;
623
+ i !== void 0 && I("routingApiKey", "The `routingApiKey` prop is deprecated: use `config.network.routing.apiKey`.");
624
+ const a = (u = t == null ? void 0 : t.network) == null ? void 0 : u.routing, p = !!i && a !== !1 && !(a != null && a.apiKey), d = mt(
625
+ () => n || s || p ? {
626
+ ...t,
627
+ ...n && { accentColor: n },
628
+ ...s && { featureColor: s },
629
+ ...p && { network: { ...t == null ? void 0 : t.network, routing: { ...a || {}, apiKey: i } } }
630
+ } : t,
631
+ [t, n, s, p, a, i]
632
+ );
633
+ return /* @__PURE__ */ o(Fe, { onError: m, children: /* @__PURE__ */ o(je, { config: d, children: /* @__PURE__ */ o(Ie, { children: /* @__PURE__ */ o(_e, { children: /* @__PURE__ */ o(De, { children: /* @__PURE__ */ o(jo, { ...e, ref: r }) }) }) }) }) });
634
+ });
635
+ Io.displayName = "ElementEditorShell";
636
+ const _o = 5e3, Do = ".leaflet-control-attribution, .elm-attribution-toggle, .maplibregl-ctrl-attrib";
637
+ function tr(e, r, t = !0) {
638
+ const n = S(r);
639
+ Y(() => {
640
+ n.current = r;
641
+ });
642
+ const s = S(() => {
643
+ });
644
+ return K(() => {
645
+ if (!t || !e) return;
646
+ let i = !1, m;
647
+ const a = () => {
648
+ i = !0, clearTimeout(m), document.removeEventListener("visibilitychange", b);
649
+ for (const v of Vt) e.removeEventListener(v, d, !0);
650
+ }, p = () => {
651
+ i || (a(), n.current());
652
+ }, d = (v) => {
653
+ v.target instanceof Element && v.target.closest(Do) || p();
654
+ }, u = () => {
655
+ m || (m = setTimeout(p, _o));
656
+ };
657
+ function b() {
658
+ document.visibilityState === "visible" && u();
659
+ }
660
+ for (const v of Vt) e.addEventListener(v, d, { capture: !0, passive: !0 });
661
+ return document.visibilityState === "hidden" ? document.addEventListener("visibilitychange", b) : u(), s.current = a, () => {
662
+ a(), s.current = () => {
663
+ };
664
+ };
665
+ }, [e, t]), W(() => s.current(), []);
666
+ }
667
+ const Vt = ["pointerdown", "wheel", "keydown"];
668
+ function er(e, r, t, n, s) {
669
+ const i = e !== void 0;
670
+ i && s && !t && I("basemap-controlled", "<ElementEditor basemap> is controlled: the picker can't change it without `onBasemapChange`. Pass `onBasemapChange` (and update `basemap` in it), or use `defaultBasemap` for a starting basemap the user can change.");
671
+ const [m, a] = j(() => e !== void 0 ? e : r()), p = i ? e : m, d = S({ current: p, controlled: i, onChange: t, remember: n });
672
+ d.current = { current: p, controlled: i, onChange: t, remember: n };
673
+ const u = W((v, C) => {
674
+ var O;
675
+ const w = d.current;
676
+ w.controlled || (a(v), C && w.remember(v)), (O = w.onChange) == null || O.call(w, v);
677
+ }, []), b = mt(() => ({
678
+ getBasemap: () => d.current.current,
679
+ setBasemap: (v) => u(v, !1)
680
+ }), [u]);
681
+ return { current: p, pick: u, api: b };
682
+ }
683
+ export {
684
+ Io as E,
685
+ Xo as F,
686
+ Ho as a,
687
+ er as b,
688
+ Qo as p,
689
+ Zo as r,
690
+ Yo as s,
691
+ tr as u
692
+ };