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