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