@element-editor/react 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/element-editor-leaflet.css +1 -1
- package/dist/element-editor.cjs +1 -1
- package/dist/element-editor.css +1 -1
- package/dist/element-editor.es.js +23 -22
- package/dist/leaflet.cjs +1 -1
- package/dist/leaflet.es.js +26 -26
- package/dist/shell/types.d.cts +8 -0
- package/dist/shell/types.d.ts +8 -0
- package/dist/useBasemapState-DxeagojX.js +692 -0
- package/dist/useBasemapState-ItAucr9T.cjs +1 -0
- package/package.json +7 -7
- package/dist/useBasemapState-8kWJmLD9.cjs +0 -1
- package/dist/useBasemapState-EEM8j7r8.js +0 -690
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),l=require("react"),n=require("@element-editor/ui"),$=require("@element-editor/ui/internal"),J=require("@element-editor/core"),L=require("@element-editor/core/internal"),D=require("@phosphor-icons/react"),Pe="elm_mapView",Ae=1,it={center:[10,48],zoom:5},ct=40,ut=16;function Ne(o){try{const r=J.readPersisted(Pe,Ae,e=>{if(!e||typeof e!="object")return null;const s=e;return typeof s.lat=="number"&&typeof s.lng=="number"&&typeof s.zoom=="number"?{lat:s.lat,lng:s.lng,zoom:s.zoom}:null},o);if(r)return{center:[r.lng,r.lat],zoom:r.zoom}}catch{}return null}function dt(o,r,e,s){J.writePersisted(Pe,Ae,{lat:o,lng:r,zoom:e},s)}const Be=(...o)=>o.every(r=>typeof r=="number"&&Number.isFinite(r));function $e(o){if(!o)return null;try{const r=o,e=r.type==="Feature"?{type:"FeatureCollection",features:[r]}:r;return J.getFeatureCollectionBBox(e)}catch{return null}}function ft(o,r){if(o==="data")return(e=>e?{bounds:e}:null)($e(r));if(o&&typeof o=="object"){if("bounds"in o){const e=o.bounds;if(Array.isArray(e)&&e.length===4&&Be(...e))return{bounds:[e[0],e[1],e[2],e[3]]}}else if("center"in o){const e=o.center;if(Array.isArray(e)&&e.length===2&&Be(e[0],e[1],o.zoom))return{center:[e[0],e[1]],zoom:o.zoom}}}return L.warnOnce("initialView-invalid",`initialView=${JSON.stringify(o)} is not { center: [lng, lat], zoom }, { bounds: [west, south, east, north] } or 'data'; it was ignored.`),null}function mt({initialView:o,initialData:r,bounds:e},s){const a=o===void 0?null:ft(o,r);if(a)return a;const i=Ne(s);if(i)return i;const h=o==="data"?null:$e(r);if(h)return{bounds:h};const c=L.normalizeBounds(e);return c?{bounds:c}:it}function pt(o,r,e){if(!o||typeof o!="object")return{};const s={};for(const[a,i]of Object.entries(o))a in r?i!==void 0&&L.warnOnce(`mapOptions-${e}-${a}`,`<ElementEditor mapOptions.${a}> is set by Element and was ignored. ${r[a]}`):s[a]=i;return s}const ht="--elm-row-hover",gt=1500;function xt(o,r){l.useEffect(()=>{if(!L.isDevBuild())return;const e=o.current;if(!e||typeof getComputedStyle!="function")return;const s=r==="leaflet"?"@element-editor/react/leaflet/style.css":"@element-editor/react/style.css",a=requestAnimationFrame(()=>{if(!e.isConnected||e.getClientRects().length===0)return;const{width:h,height:c}=e.getBoundingClientRect();(c===0||h===0)&&L.warnOnce("editor-zero-size",`<ElementEditor> is ${Math.round(h)}×${Math.round(c)} 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).`)}),i=setTimeout(()=>{e.isConnected&&getComputedStyle(e).getPropertyValue(ht).trim()===""&&L.warnOnce("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 '${s}'`)},gt);return()=>{cancelAnimationFrame(a),clearTimeout(i)}},[o,r])}function bt(o){const r=n.useElementEditorConfig(),{uiStore:e}=n.useGeoStore(),s=n.useUIStore(c=>c.userTheme),a=l.useRef(!1);a.current||(a.current=!0,o===void 0&&r.mode!=="system"&&(J.readStorage("elm_theme",r)||e.setState({userTheme:r.mode}))),l.useLayoutEffect(()=>{o!==void 0&&e.setState({userTheme:o==="auto"?"system":o})},[o,e]);const[i,h]=l.useState(()=>typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches);return l.useEffect(()=>{if(s!=="system")return;const c=window.matchMedia("(prefers-color-scheme: dark)"),g=m=>h(m.matches);return c.addEventListener("change",g),()=>c.removeEventListener("change",g)},[s]),s==="dark"?"dark":s==="light"?"light":i?"dark":"light"}function yt(o,r){const e=l.useRef(null),s=l.useRef(null),a=l.useRef(null),i=l.useRef(null),h=l.useRef(null),c=l.useRef(null),g=l.useRef(null),m=l.useRef(null),f=l.useRef(null),b=l.useRef(null),v=l.useRef(null);return l.useLayoutEffect(()=>{const j=e.current;if(!j||o)return;const C=()=>parseFloat(j.style.getPropertyValue("--elm-panel-offset"))||0,k=u=>u&&u.offsetWidth>0?u.getBoundingClientRect():null,F=u=>u.flatMap(d=>getComputedStyle(d).display==="contents"?F([...d.children]):[d.offsetWidth]),ce=u=>{const d=F([...u.children]).filter(y=>y>0);return d.length?getComputedStyle(u).flexDirection.startsWith("column")?Math.max(...d):d.reduce((y,S)=>y+S,0)+8*(d.length-1):0},H=(u,d,y)=>{var x;if(!u)return!0;const S=(((x=u.parentElement)==null?void 0:x.clientWidth)??0)-32-C(),E=`${Math.max(0,Math.floor(S))}px`;u.style.getPropertyValue("--elm-row-room")!==E&&u.style.setProperty("--elm-row-room",E);const R=[...u.children].reduce((w,U)=>w+ce(U),16)+d>S+.5,O=R&&d?`${d}px`:"";return u.dataset.elmClearance=String(d),u.hasAttribute("data-elm-wrap")===R&&u.style.paddingRight===O?!0:y?!1:(u.toggleAttribute("data-elm-wrap",R),u.style.paddingRight=O,!0)};let z=0;const _=(u=!1)=>{if(!(H(s.current,r,u)&&H(a.current,0,u))){z||(z=requestAnimationFrame(()=>{z=0,_()}));return}const y=k(g.current),S=k(a.current),E=k(i.current),M=k(h.current),R=k(c.current),O=w=>!!(y&&w&&y.left<w.right+8&&w.left<y.right+8);let x=M?M.height+8:0;S&&(O(E)||O(R))&&(x=Math.max(x,S.height+8)),j.style.setProperty("--elm-bottom-row-height",`${x}px`),Z(b.current,"--elm-left-center-shift"),Z(v.current,"--elm-right-center-shift")},X={},Z=(u,d)=>{const y=X[d]??0,S=k(u);let E=0;if(S){const M=S.top-y;let R=-1/0,O=1/0;for(const w of[s.current,a.current])for(const U of(w==null?void 0:w.children)??[]){const T=k(U);!T||T.height===0||T.right+8<=S.left||S.right+8<=T.left||(w===s.current?R=Math.max(R,T.bottom+8):O=Math.min(O,T.top-8))}E=(M<R?R:M+S.height>O?Math.max(R,O-S.height):M)-M}E!==y&&(X[d]=E,j.style.setProperty(d,`${E}px`))},V=new ResizeObserver(()=>_(!0));for(const u of[s,a,i,h,c,g,m,f,b,v])u.current&&V.observe(u.current);for(const u of[s.current,a.current])for(const d of(u==null?void 0:u.children)??[]){V.observe(d);for(const y of d.querySelectorAll(":scope > *, :scope > .contents > *"))V.observe(y)}const Y=u=>{var d,y;(u.target===j||(y=(d=u.target).matches)!=null&&y.call(d,"[data-elm-slot], [data-elm-edge]"))&&_()};j.addEventListener("transitionend",Y);let Q=C();const ee=new MutationObserver(()=>{C()!==Q&&(Q=C(),_())});return ee.observe(j,{attributes:!0,attributeFilter:["style"]}),_(),()=>{cancelAnimationFrame(z),V.disconnect(),ee.disconnect(),j.removeEventListener("transitionend",Y);for(const u of["--elm-bottom-row-height","--elm-left-center-shift","--elm-right-center-shift"])j.style.setProperty(u,"0px")}},[o,r]),{rootRef:e,topRowRef:s,bottomRowRef:a,bottomLeftRef:i,bottomCenterRef:h,bottomRightRef:c,contextualRef:g,leftEdgeRef:m,rightEdgeRef:f,leftCenterRef:b,rightCenterRef:v}}function vt({size:o,tooltipSide:r}){const e=n.useUIStore(c=>c.shortcutsModalOpen),s=n.useUIStore(c=>c.openShortcutsModal),a=n.useUIStore(c=>c.closeShortcutsModal),{getKey:i}=n.useShortcutConfig(),h=i("show-shortcuts").toUpperCase();return t.jsx(n.IconButton,{label:"Show keyboard shortcuts",shortcutId:"show-shortcuts",tooltipContent:"Keyboard shortcuts",shortcut:t.jsx(n.KbdDark,{children:h}),onClick:e?a:s,active:e,size:o,tooltipSide:r,children:t.jsx(D.Keyboard,{size:24})})}function St({size:o,side:r}){const e=n.useUIStore(i=>i.tableOpen),s=n.useUIStore(i=>i.toggleTable),{getKey:a}=n.useShortcutConfig();return t.jsx(n.IconButton,{size:o,tooltipSide:r,label:e?"Hide table":"Show table",shortcutId:"toggle-table",shortcut:t.jsx(n.KbdDark,{children:a("toggle-table").toUpperCase()}),onClick:s,active:e,children:t.jsx(D.Table,{size:24})})}function jt({size:o,side:r}){const e=n.useUIStore(i=>i.schemaModalOpen),s=n.useUIStore(i=>i.toggleSchemaModal),{getKey:a}=n.useShortcutConfig();return t.jsx(n.IconButton,{size:o,tooltipSide:r,label:"Edit schema",shortcutId:"toggle-schema",shortcut:t.jsx(n.KbdDark,{children:a("toggle-schema").toUpperCase()}),onClick:s,active:e,children:t.jsx(D.TreeStructure,{size:24})})}function Ct({size:o,side:r}){const e=n.useUIStore(i=>i.codeModalOpen),s=n.useUIStore(i=>i.toggleCodeModal),{getKey:a}=n.useShortcutConfig();return t.jsx(n.IconButton,{size:o,tooltipSide:r,label:"Show GeoJSON",shortcutId:"toggle-geojson",shortcut:t.jsx(n.KbdDark,{children:a("toggle-geojson").toUpperCase()}),onClick:s,active:e,children:t.jsx(D.Code,{size:24})})}function wt({size:o,side:r}){const e=n.useUIStore(a=>a.settingsModalOpen),s=n.useUIStore(a=>a.setSettingsModalOpen);return t.jsx(n.IconButton,{size:o,tooltipSide:r,label:"Editor settings",onClick:()=>s(!e),active:e,children:t.jsx(D.SlidersHorizontal,{size:24})})}function Et({id:o,size:r,side:e,onSubmit:s,basemapControl:a,attributionRef:i}){switch(o){case"toolbar":return t.jsx(n.FloatingToolbar,{embedded:!0});case"undo":return t.jsx(n.UndoButton,{size:r,tooltipSide:e});case"redo":return t.jsx(n.RedoButton,{size:r,tooltipSide:e});case"fitBounds":return t.jsx(n.FitBoundsButton,{size:r,tooltipSide:e});case"locate":return t.jsx(n.LocateButton,{size:r,tooltipSide:e});case"zoomIndicator":return t.jsx(n.ZoomIndicator,{size:r,tooltipSide:e});case"table":return t.jsx(St,{size:r,side:e});case"schema":return t.jsx(jt,{size:r,side:e});case"geojson":return t.jsx(Ct,{size:r,side:e});case"settings":return t.jsx(wt,{size:r,side:e});case"keyboard":return t.jsx(vt,{size:r,tooltipSide:e});case"applyChanges":return t.jsxs(n.Button,{variant:"primary",onClick:s,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",children:[t.jsx(D.Check,{size:20,weight:"bold"}),"Apply changes"]});case"attribution":return t.jsx("span",{ref:i,"data-elm-attribution":"",onMouseEnter:h=>{var c;h.currentTarget.title=((c=h.currentTarget.textContent)==null?void 0:c.trim())??""}});case"basemap":return l.isValidElement(a)?l.cloneElement(a,{size:r,tooltipSide:e}):null;default:return null}}function Rt(){const o=n.useElementEditorConfig();return t.jsxs("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:[o.ui.dataTable&&t.jsx("div",{className:"flex-1 h-full relative overflow-hidden border-r border-elm-border",children:t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.DataTablePanel,{embedded:!0})})}),o.ui.layerList&&t.jsx("div",{className:"w-[320px] flex-shrink-0 h-full relative overflow-hidden bg-elm-surface",children:t.jsx(n.LayersPanel,{})})]})}function kt({layout:o}){const r=n.useElementEditorConfig(),e=n.useUIStore(f=>f.dialogState),s=n.useUIStore(f=>f.schemaModalOpen),a=n.useUIStore(f=>f.toggleSchemaModal),i=n.useUIStore(f=>f.readonly),h=n.useUIStore(f=>f.codeModalOpen),c=n.useUIStore(f=>f.toggleCodeModal),g=n.useUIStore(f=>f.settingsModalOpen),m=n.useUIStore(f=>f.shortcutsModalOpen);return t.jsxs(t.Fragment,{children:[o==="minimal"&&e.type!=="closed"&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.FeatureEditModal,{dialogState:e})}),r.ui.dataTable&&o!=="split"&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.DataTablePanel,{})}),r.ui.keyboardShortcuts.show&&m&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.ShortcutsModal,{})}),r.ui.settings&&g&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.SettingsModal,{})}),r.ui.schemaEditor&&s&&!i&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.SchemaModal,{onClose:a})}),r.ui.geojsonEditor&&h&&t.jsx(l.Suspense,{fallback:t.jsx(n.GeoJSONDockPlaceholder,{}),children:t.jsx(n.GeoJSONModal,{onClose:c})})]})}const ie=o=>{var r,e,s,a;return!((e=(r=o.dataTransfer)==null?void 0:r.types)!=null&&e.includes("Files"))||!!((a=(s=o.target).closest)!=null&&a.call(s,".cm-editor"))};function Ot(o){const r=$.useGeoJSONFileImport(),[e,s]=l.useState(!1),a=l.useRef(0),i=l.useCallback(m=>{!o||ie(m)||(m.preventDefault(),m.stopPropagation(),a.current+=1,s(!0))},[o]),h=l.useCallback(m=>{!o||ie(m)||(m.preventDefault(),m.stopPropagation(),m.dataTransfer.dropEffect="copy")},[o]),c=l.useCallback(m=>{!o||ie(m)||(m.stopPropagation(),a.current=Math.max(0,a.current-1),a.current===0&&s(!1))},[o]),g=l.useCallback(m=>{var b;if(a.current=0,s(!1),!o||ie(m))return;m.preventDefault(),m.stopPropagation();const f=(b=m.dataTransfer.files)==null?void 0:b[0];f&&r(f)},[o,r]);return{active:o&&e,handlers:{onDragEnter:i,onDragOver:h,onDragLeave:c,onDrop:g}}}function It({enabled:o,children:r,footer:e}){const s=Ot(o);return t.jsxs("div",{style:{display:"contents"},...s.handlers,children:[t.jsxs("div",{className:"relative flex-1 min-h-0 flex",children:[r,s.active&&t.jsx("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:t.jsxs("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:[t.jsx(D.FileArrowUp,{size:20,className:"text-elm-text-muted"}),t.jsx("span",{children:"Drop GeoJSON to import"})]})})]}),e]})}const be="in-data-[elm-wrap]:flex-wrap in-data-[elm-wrap]:max-w-full",ye="in-data-[elm-wrap]:flex-wrap-reverse in-data-[elm-wrap]:max-w-full",Mt={topLeft:[`flex-row items-start ${be}`,"flex-col items-start"],topCenter:[`flex-row items-start justify-center ${be}`,"flex-col items-center"],topRight:[`flex-row-reverse items-start ${be}`,"flex-col items-end"],leftCenter:["flex-row items-center","flex-col items-start"],rightCenter:["flex-row-reverse items-center","flex-col items-end"],bottomLeft:[`flex-row items-end ${ye}`,"flex-col-reverse items-start"],bottomCenter:[`flex-row items-end justify-center ${ye}`,"flex-col-reverse items-center"],bottomRight:[`flex-row-reverse items-end ${ye}`,"flex-col-reverse items-end"]},Tt=l.forwardRef(({initialData:o,initialView:r,schema:e,tools:s,maxFeatures:a,geometryTypes:i,replaceAtLimit:h,autoExitAfterDraw:c,coordinates:g,bounds:m,readonly:f=!1,layout:b="panel",className:v="",style:j,theme:C,onChange:k,onSubmit:F,onValidationError:ce,onFeatureSelect:H,onZoomChange:z,onEvent:_,onError:X,onFeatureAdd:Z,onFeatureUpdate:V,onFeatureDelete:Y,onSelectionChange:Q,onToolChange:ee,onVertexEditChange:u,slots:d,renderMap:y,basemapControl:S,extraApi:E,fileDrop:M=!0,engine:R="maplibre"},O)=>{const x=n.useElementEditorConfig(),{dataStore:w,uiStore:U}=n.useGeoStore(),T=n.useMapController(),K=s||(x.tools==="all"?null:x.tools),[ve]=l.useState(()=>r==="data"||r===void 0&&!Ne(x)),[ue,Se]=l.useState(null),_e=l.useCallback((p,B)=>{if(!B||!ve)return;const I=J.getFeatureCollectionBBox({type:"FeatureCollection",metadata:{schemas:[],groups:[]},features:w.getState().features});I&&Se(I)},[ve,w]);l.useEffect(()=>{!ue||!T.fitBounds||(T.fitBounds(ue),Se(null))},[ue,T]);const te=n.useAdapterControls({initialData:o,schema:e,layout:b,readonly:f,tools:K,maxFeatures:a,geometryTypes:i,replaceAtLimit:h,autoExitAfterDraw:c,coordinates:g,onChange:k,onSubmit:F,onValidationError:ce,onFeatureAdd:Z,onFeatureUpdate:V,onFeatureDelete:Y,onSelectionChange:Q,onFeatureSelect:H,onZoomChange:z,onToolChange:ee,onVertexEditChange:u,onInitialDataApplied:_e}),de=l.useMemo(()=>E?{...te,...E}:te,[te,E]);l.useImperativeHandle(O,()=>de,[de]),l.useEffect(()=>{},[w,U,de]),l.useLayoutEffect(()=>{U.getState().setBounds(m)},[m,U]);const P=n.useUIStore(p=>p.tableFullscreen),Ue=n.useUIStore(p=>p.sidebarOpen),fe=C!==null&&typeof C=="object";l.useEffect(()=>{fe&&L.warnOnce("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`.")},[fe]);const me=bt(fe?void 0:C),De={...x.accentColor?{"--elm-accent":x.accentColor}:{},"--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)",...j},je=j?Object.entries(j).filter(([p,B])=>p.startsWith("--")&&B!=null&&B!==""):[],pe=je.length?JSON.stringify(je):"",ze=l.useMemo(()=>pe?Object.fromEntries(JSON.parse(pe)):void 0,[pe]),Ve=p=>$.isControlVisible(p,x.ui,{readonly:f,canSubmit:!!F,hasBasemaps:!!S}),oe=p=>$.visibleLayoutEntries(x.ui.layout[p].items,Ve),Ce=x.ui.keyboardShortcuts.enabled,Ke=(K==null?void 0:K.join())??null;l.useEffect(()=>{for(const p of $.layoutGaps(x.ui.layout,{readonly:f,canSubmit:!!F,tools:K,shortcuts:Ce}))L.warnOnce(`layoutGap:${p}`,`config.ui.layout: ${p}.`)},[x.ui.layout,f,!!F,Ke,Ce]);const[we,Ge]=l.useState(null),[We,qe]=l.useState(null),Ee=(p,B,I)=>t.jsx(Et,{id:p,size:B,side:I,onSubmit:te.submit,basemapControl:S,attributionRef:Ge},p),he=(p,B)=>{const I=p==="statusLeft"||p==="statusRight",G=x.ui.layout[p].direction==="vertical",ae=G?p.endsWith("Right")||p==="rightCenter"?"left":"right":p.startsWith("top")?"bottom":"top",W=A=>t.jsx("div",{"aria-hidden":!0,"data-elm-separator":"",className:`flex-shrink-0 bg-elm-border ${I?"w-px h-4 mx-1":G?"h-px w-5 my-0.5":"w-px h-5 mx-1"}`},A);return B.map((A,q)=>{if(A==="separator")return W(`sep-${q}`);if(typeof A=="string")return Ee(A,I?"sm":"md",ae);const le=A.group.map((Te,lt)=>Te==="separator"?W(`gsep-${lt}`):Ee(Te,I?"sm":"group",ae));return I?t.jsx("div",{"data-elm-group":"",className:"flex items-center",children:le},`group-${q}`):t.jsx(n.ControlGroup,{direction:G?"vertical":"horizontal",children:le},`group-${q}`)})},Re=$.LAYOUT_SLOTS.find(p=>oe(p).includes("toolbar")),N=(p,B,I,G,ae)=>{const W=oe(p),A=d==null?void 0:d[p],[q,le]=Mt[p];return t.jsxs("div",{ref:G,"data-elm-slot":p,style:I,className:`flex ${x.ui.layout[p].direction==="vertical"?le:q} gap-2 ${W.length||A?"pointer-events-auto":""} ${B}`,children:[ae,A,he(p,W)]})},re=(...p)=>Re&&p.includes(Re)?"z-[500]":"z-[400]",ke=b==="panel"&&x.ui.layerList&&!Ue?56:0,ne="var(--elm-panel-offset, 0px)",ge=b==="split"?"calc(33.33% + 16px)":"calc(var(--elm-table-offset, 0px) + 16px)",{rootRef:se,topRowRef:Je,bottomRowRef:He,bottomLeftRef:Xe,bottomCenterRef:Ze,bottomRightRef:Ye,contextualRef:Qe,leftEdgeRef:et,rightEdgeRef:tt,leftCenterRef:ot,rightCenterRef:rt}=yt(P,ke);xt(se,R);const[nt,st]=l.useState(null);l.useLayoutEffect(()=>{st(se.current)},[se]);const at=$.useRootTokens(nt),Oe=oe("statusLeft"),Ie=oe("statusRight"),Me=Oe.length+Ie.length>0,xe=Me&&!!we;return t.jsx(n.ThemeContext.Provider,{value:me,children:t.jsx($.RootCssVarsContext.Provider,{value:ze,children:t.jsx($.RootTokensContext.Provider,{value:at,children:t.jsx(n.EventProvider,{onEvent:_,onError:X,toaster:!0,children:t.jsx("div",{ref:se,"data-elm-theme":me,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}`,style:De,children:t.jsxs(It,{enabled:M&&!f,footer:Me&&t.jsxs("div",{"data-elm-status-bar":"",role:"toolbar","aria-label":"Status bar",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]",children:[t.jsx("div",{"data-elm-slot":"statusLeft",className:"flex items-center gap-1 min-w-0",children:he("statusLeft",Oe)}),t.jsx("div",{"data-elm-slot":"statusRight",className:"flex items-center gap-1 min-w-0",children:he("statusRight",Ie)})]}),children:[y({attributionTarget:xe?we:null,attributionCorner:xe?null:We,themeMode:me}),!P&&(d==null?void 0:d.toolbar),!P&&(d==null?void 0:d.mapOverlay)&&t.jsx("div",{className:"absolute inset-0 z-[300] pointer-events-none",children:d.mapOverlay}),!P&&t.jsxs("div",{ref:Je,"data-elm-edge":"top",style:{top:16,left:16,right:`calc(${ne} + 16px)`},className:`absolute ${re("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`,children:[N("topLeft","justify-self-start"),N("topCenter","justify-self-center mx-auto"),N("topRight","justify-self-end ml-auto transition-[margin] duration-200 in-data-[elm-wrap]:mr-0!",{marginRight:ke})]}),!P&&t.jsx("div",{ref:et,"data-elm-edge":"left",style:{top:16,bottom:ge,left:16},className:`absolute ${re("leftCenter")} flex flex-col justify-center pointer-events-none`,children:N("leftCenter","relative",{top:"var(--elm-left-center-shift, 0px)"},ot)}),!P&&t.jsx("div",{ref:tt,"data-elm-edge":"right",style:{top:16,bottom:ge,right:`calc(${ne} + 16px)`},className:`absolute ${re("rightCenter")} flex flex-col justify-center pointer-events-none transition-[right] duration-200`,children:N("rightCenter","relative",{top:"var(--elm-right-center-shift, 0px)"},rt)}),!P&&t.jsxs("div",{ref:He,"data-elm-edge":"bottom",style:{bottom:ge,left:16,right:`calc(${ne} + 16px)`},className:`absolute ${re("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`,children:[N("bottomLeft","justify-self-start",void 0,Xe),N("bottomCenter","justify-self-center mx-auto",void 0,Ze),N("bottomRight","justify-self-end ml-auto max-w-full",void 0,Ye,!xe&&t.jsx("div",{ref:qe,"data-elm-attribution-corner":"",className:"pointer-events-auto flex items-end justify-end w-max",style:{maxWidth:"var(--elm-row-room, 100%)"}}))]}),!P&&t.jsx("div",{className:"absolute z-[400] flex justify-center pointer-events-none transition-[right] duration-200",style:{bottom:"var(--elm-bottom-stack-offset)",left:16,right:`calc(${ne} + 16px)`},children:t.jsxs("div",{ref:Qe,"data-elm-contextual":"",className:"flex flex-wrap justify-center gap-2 max-w-full min-w-0",children:[t.jsx(n.EditingToolbar,{}),t.jsx(n.ActiveDrawingToolbar,{}),t.jsx(n.SimplifyPanel,{}),t.jsx(n.SmoothPanel,{}),t.jsx(n.BufferPanel,{}),t.jsx(n.ReadonlyBanner,{})]})}),!P&&x.ui.layerList&&b==="panel"&&t.jsx(n.LayersPanel,{footer:d==null?void 0:d.panelFooter}),b==="split"&&t.jsx(Rt,{}),t.jsx(kt,{layout:b})]})})})})})})}),Fe=l.forwardRef((o,r)=>{var f;const{config:e,accentColor:s,featureColor:a,routingApiKey:i,onError:h}=o;i!==void 0&&L.warnOnce("routingApiKey","The `routingApiKey` prop is deprecated: use `config.network.routing.apiKey`.");const c=(f=e==null?void 0:e.network)==null?void 0:f.routing,g=!!i&&c!==!1&&!(c!=null&&c.apiKey),m=l.useMemo(()=>s||a||g?{...e,...s&&{accentColor:s},...a&&{featureColor:a},...g&&{network:{...e==null?void 0:e.network,routing:{...c||{},apiKey:i}}}}:e,[e,s,a,g,c,i]);return t.jsx(n.ElementEditorErrorBoundary,{onError:h,children:t.jsx(n.ElementEditorConfigProvider,{config:m,children:t.jsx(n.GeoStoreProvider,{children:t.jsx(n.ShortcutConfigProvider,{children:t.jsx(n.MapControllerProvider,{children:t.jsx(Tt,{...o,ref:r})})})})})})});Fe.displayName="ElementEditorShell";const Bt=5e3,Lt=".leaflet-control-attribution, .elm-attribution-toggle, .maplibregl-ctrl-attrib";function Pt(o,r,e=!0){const s=l.useRef(r);l.useLayoutEffect(()=>{s.current=r});const a=l.useRef(()=>{});return l.useEffect(()=>{if(!e||!o)return;let i=!1,h;const c=()=>{i=!0,clearTimeout(h),document.removeEventListener("visibilitychange",b);for(const v of Le)o.removeEventListener(v,m,!0)},g=()=>{i||(c(),s.current())},m=v=>{v.target instanceof Element&&v.target.closest(Lt)||g()},f=()=>{h||(h=setTimeout(g,Bt))};function b(){document.visibilityState==="visible"&&f()}for(const v of Le)o.addEventListener(v,m,{capture:!0,passive:!0});return document.visibilityState==="hidden"?document.addEventListener("visibilitychange",b):f(),a.current=c,()=>{c(),a.current=()=>{}}},[o,e]),l.useCallback(()=>a.current(),[])}const Le=["pointerdown","wheel","keydown"];function At(o,r,e,s,a){const i=o!==void 0;i&&a&&!e&&L.warnOnce("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.");const[h,c]=l.useState(()=>o!==void 0?o:r()),g=i?o:h,m=l.useRef({current:g,controlled:i,onChange:e,remember:s});m.current={current:g,controlled:i,onChange:e,remember:s};const f=l.useCallback((v,j)=>{var k;const C=m.current;C.controlled||(c(v),j&&C.remember(v)),(k=C.onChange)==null||k.call(C,v)},[]),b=l.useMemo(()=>({getBasemap:()=>m.current.current,setBasemap:v=>f(v,!1)}),[f]);return{current:g,pick:f,api:b}}exports.ElementEditorShell=Fe;exports.FIT_MAX_ZOOM=ut;exports.FIT_PADDING=ct;exports.pickMapOptions=pt;exports.resolveInitialView=mt;exports.saveView=dt;exports.useAttributionAutoCollapse=Pt;exports.useBasemapState=At;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@element-editor/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Drop-in React map editor: one component with drawing tools, vertex editing, snapping, a data table and a GeoJSON inspector, on MapLibre GL or Leaflet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"element-editor",
|
|
@@ -85,9 +85,9 @@
|
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@phosphor-icons/react": "^2.1.10",
|
|
87
87
|
"sonner": "^2.0.7",
|
|
88
|
-
"@element-editor/adapter-maplibre": "0.3.
|
|
89
|
-
"@element-editor/core": "0.3.
|
|
90
|
-
"@element-editor/ui": "0.3.
|
|
88
|
+
"@element-editor/adapter-maplibre": "0.3.1",
|
|
89
|
+
"@element-editor/core": "0.3.1",
|
|
90
|
+
"@element-editor/ui": "0.3.1"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@playwright/test": "^1.65.1",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"vite": "^6.0.5",
|
|
115
115
|
"vite-plugin-dts": "^4.5.4",
|
|
116
116
|
"vitest": "^4.1.0",
|
|
117
|
-
"@element-editor/adapter-leaflet": "0.3.
|
|
117
|
+
"@element-editor/adapter-leaflet": "0.3.1"
|
|
118
118
|
},
|
|
119
119
|
"peerDependencies": {
|
|
120
120
|
"leaflet": "^1.9.0",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"react": "^19.2.0",
|
|
123
123
|
"react-dom": "^19.2.0",
|
|
124
124
|
"react-leaflet": "^5.0.0",
|
|
125
|
-
"@element-editor/adapter-leaflet": "^0.3.
|
|
125
|
+
"@element-editor/adapter-leaflet": "^0.3.1"
|
|
126
126
|
},
|
|
127
127
|
"peerDependenciesMeta": {
|
|
128
128
|
"@element-editor/adapter-leaflet": {
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
},
|
|
141
141
|
"scripts": {
|
|
142
142
|
"dev": "vite",
|
|
143
|
-
"build": "vite build && node ../../scripts/fix-dts.mjs",
|
|
143
|
+
"build": "vite build && node ../../scripts/flatten-css.mjs dist/element-editor.css dist/element-editor-leaflet.css && node ../../scripts/fix-dts.mjs",
|
|
144
144
|
"preview": "vite preview",
|
|
145
145
|
"test": "vitest",
|
|
146
146
|
"test:run": "vitest run",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const t=require("react/jsx-runtime"),l=require("react"),n=require("@element-editor/ui"),$=require("@element-editor/ui/internal"),W=require("@element-editor/core"),L=require("@element-editor/core/internal"),U=require("@phosphor-icons/react"),Le="elm_mapView",Pe=1,lt={center:[10,48],zoom:5},it=40,ct=16;function Ae(o){try{const r=W.readPersisted(Le,Pe,e=>{if(!e||typeof e!="object")return null;const s=e;return typeof s.lat=="number"&&typeof s.lng=="number"&&typeof s.zoom=="number"?{lat:s.lat,lng:s.lng,zoom:s.zoom}:null},o);if(r)return{center:[r.lng,r.lat],zoom:r.zoom}}catch{}return null}function ut(o,r,e,s){W.writePersisted(Le,Pe,{lat:o,lng:r,zoom:e},s)}const Te=(...o)=>o.every(r=>typeof r=="number"&&Number.isFinite(r));function Ne(o){if(!o)return null;try{const r=o,e=r.type==="Feature"?{type:"FeatureCollection",features:[r]}:r;return W.getFeatureCollectionBBox(e)}catch{return null}}function dt(o,r){if(o==="data")return(e=>e?{bounds:e}:null)(Ne(r));if(o&&typeof o=="object"){if("bounds"in o){const e=o.bounds;if(Array.isArray(e)&&e.length===4&&Te(...e))return{bounds:[e[0],e[1],e[2],e[3]]}}else if("center"in o){const e=o.center;if(Array.isArray(e)&&e.length===2&&Te(e[0],e[1],o.zoom))return{center:[e[0],e[1]],zoom:o.zoom}}}return L.warnOnce("initialView-invalid",`initialView=${JSON.stringify(o)} is not { center: [lng, lat], zoom }, { bounds: [west, south, east, north] } or 'data'; it was ignored.`),null}function ft({initialView:o,initialData:r,bounds:e},s){const a=o===void 0?null:dt(o,r);if(a)return a;const c=Ae(s);if(c)return c;const p=o==="data"?null:Ne(r);if(p)return{bounds:p};const u=L.normalizeBounds(e);return u?{bounds:u}:lt}function mt(o,r,e){if(!o||typeof o!="object")return{};const s={};for(const[a,c]of Object.entries(o))a in r?c!==void 0&&L.warnOnce(`mapOptions-${e}-${a}`,`<ElementEditor mapOptions.${a}> is set by Element and was ignored. ${r[a]}`):s[a]=c;return s}const pt="--elm-row-hover",ht=1500;function gt(o,r){l.useEffect(()=>{if(!L.isDevBuild())return;const e=o.current;if(!e||typeof getComputedStyle!="function")return;const s=r==="leaflet"?"@element-editor/react/leaflet/style.css":"@element-editor/react/style.css",a=requestAnimationFrame(()=>{if(!e.isConnected||e.getClientRects().length===0)return;const{width:p,height:u}=e.getBoundingClientRect();(u===0||p===0)&&L.warnOnce("editor-zero-size",`<ElementEditor> is ${Math.round(p)}×${Math.round(u)} 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).`)}),c=setTimeout(()=>{e.isConnected&&getComputedStyle(e).getPropertyValue(pt).trim()===""&&L.warnOnce("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 '${s}'`)},ht);return()=>{cancelAnimationFrame(a),clearTimeout(c)}},[o,r])}function xt(o){const r=n.useElementEditorConfig(),{uiStore:e}=n.useGeoStore(),s=n.useUIStore(u=>u.userTheme),a=l.useRef(!1);a.current||(a.current=!0,o===void 0&&r.mode!=="system"&&(W.readStorage("elm_theme",r)||e.setState({userTheme:r.mode}))),l.useLayoutEffect(()=>{o!==void 0&&e.setState({userTheme:o==="auto"?"system":o})},[o,e]);const[c,p]=l.useState(()=>typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches);return l.useEffect(()=>{if(s!=="system")return;const u=window.matchMedia("(prefers-color-scheme: dark)"),x=f=>p(f.matches);return u.addEventListener("change",x),()=>u.removeEventListener("change",x)},[s]),s==="dark"?"dark":s==="light"?"light":c?"dark":"light"}function bt(o,r){const e=l.useRef(null),s=l.useRef(null),a=l.useRef(null),c=l.useRef(null),p=l.useRef(null),u=l.useRef(null),x=l.useRef(null),f=l.useRef(null),d=l.useRef(null),w=l.useRef(null),b=l.useRef(null);return l.useLayoutEffect(()=>{const S=e.current;if(!S||o)return;const R=()=>parseFloat(S.style.getPropertyValue("--elm-panel-offset"))||0,j=i=>i&&i.offsetWidth>0?i.getBoundingClientRect():null,q=i=>i.flatMap(h=>getComputedStyle(h).display==="contents"?q([...h.children]):[h.offsetWidth]),ie=i=>{const h=q([...i.children]).filter(y=>y>0);return h.length?getComputedStyle(i).flexDirection.startsWith("column")?Math.max(...h):h.reduce((y,v)=>y+v,0)+8*(h.length-1):0},J=(i,h,y)=>{var I;if(!i)return!0;const v=(((I=i.parentElement)==null?void 0:I.clientWidth)??0)-32-R(),O=`${Math.max(0,Math.floor(v))}px`;i.style.getPropertyValue("--elm-row-room")!==O&&i.style.setProperty("--elm-row-room",O);const E=[...i.children].reduce((C,_)=>C+ie(_),16)+h>v+.5,g=E&&h?`${h}px`:"";return i.dataset.elmClearance=String(h),i.hasAttribute("data-elm-wrap")===E&&i.style.paddingRight===g?!0:y?!1:(i.toggleAttribute("data-elm-wrap",E),i.style.paddingRight=g,!0)};let D=0;const F=(i=!1)=>{if(!(J(s.current,r,i)&&J(a.current,0,i))){D||(D=requestAnimationFrame(()=>{D=0,F()}));return}const y=j(x.current),v=j(a.current),O=j(c.current),T=j(p.current),E=j(u.current),g=C=>!!(y&&C&&y.left<C.right+8&&C.left<y.right+8);let I=T?T.height+8:0;v&&(g(O)||g(E))&&(I=Math.max(I,v.height+8)),S.style.setProperty("--elm-bottom-row-height",`${I}px`),X(w.current,"--elm-left-center-shift"),X(b.current,"--elm-right-center-shift")},H={},X=(i,h)=>{const y=H[h]??0,v=j(i);let O=0;if(v){const T=v.top-y;let E=-1/0,g=1/0;for(const C of[s.current,a.current])for(const _ of(C==null?void 0:C.children)??[]){const k=j(_);!k||k.height===0||k.right+8<=v.left||v.right+8<=k.left||(C===s.current?E=Math.max(E,k.bottom+8):g=Math.min(g,k.top-8))}O=(T<E?E:T+v.height>g?Math.max(E,g-v.height):T)-T}O!==y&&(H[h]=O,S.style.setProperty(h,`${O}px`))},z=new ResizeObserver(()=>F(!0));for(const i of[s,a,c,p,u,x,f,d,w,b])i.current&&z.observe(i.current);for(const i of[s.current,a.current])for(const h of(i==null?void 0:i.children)??[]){z.observe(h);for(const y of h.querySelectorAll(":scope > *, :scope > .contents > *"))z.observe(y)}const Z=i=>{var h,y;(i.target===S||(y=(h=i.target).matches)!=null&&y.call(h,"[data-elm-slot], [data-elm-edge]"))&&F()};S.addEventListener("transitionend",Z);let Y=R();const Q=new MutationObserver(()=>{R()!==Y&&(Y=R(),F())});return Q.observe(S,{attributes:!0,attributeFilter:["style"]}),F(),()=>{cancelAnimationFrame(D),z.disconnect(),Q.disconnect(),S.removeEventListener("transitionend",Z);for(const i of["--elm-bottom-row-height","--elm-left-center-shift","--elm-right-center-shift"])S.style.setProperty(i,"0px")}},[o,r]),{rootRef:e,topRowRef:s,bottomRowRef:a,bottomLeftRef:c,bottomCenterRef:p,bottomRightRef:u,contextualRef:x,leftEdgeRef:f,rightEdgeRef:d,leftCenterRef:w,rightCenterRef:b}}function yt({size:o,tooltipSide:r}){const e=n.useUIStore(u=>u.shortcutsModalOpen),s=n.useUIStore(u=>u.openShortcutsModal),a=n.useUIStore(u=>u.closeShortcutsModal),{getKey:c}=n.useShortcutConfig(),p=c("show-shortcuts").toUpperCase();return t.jsx(n.IconButton,{label:"Show keyboard shortcuts",shortcutId:"show-shortcuts",tooltipContent:"Keyboard shortcuts",shortcut:t.jsx(n.KbdDark,{children:p}),onClick:e?a:s,active:e,size:o,tooltipSide:r,children:t.jsx(U.Keyboard,{size:24})})}function vt({size:o,side:r}){const e=n.useUIStore(c=>c.tableOpen),s=n.useUIStore(c=>c.toggleTable),{getKey:a}=n.useShortcutConfig();return t.jsx(n.IconButton,{size:o,tooltipSide:r,label:e?"Hide table":"Show table",shortcutId:"toggle-table",shortcut:t.jsx(n.KbdDark,{children:a("toggle-table").toUpperCase()}),onClick:s,active:e,children:t.jsx(U.Table,{size:24})})}function St({size:o,side:r}){const e=n.useUIStore(c=>c.schemaModalOpen),s=n.useUIStore(c=>c.toggleSchemaModal),{getKey:a}=n.useShortcutConfig();return t.jsx(n.IconButton,{size:o,tooltipSide:r,label:"Edit schema",shortcutId:"toggle-schema",shortcut:t.jsx(n.KbdDark,{children:a("toggle-schema").toUpperCase()}),onClick:s,active:e,children:t.jsx(U.TreeStructure,{size:24})})}function jt({size:o,side:r}){const e=n.useUIStore(c=>c.codeModalOpen),s=n.useUIStore(c=>c.toggleCodeModal),{getKey:a}=n.useShortcutConfig();return t.jsx(n.IconButton,{size:o,tooltipSide:r,label:"Show GeoJSON",shortcutId:"toggle-geojson",shortcut:t.jsx(n.KbdDark,{children:a("toggle-geojson").toUpperCase()}),onClick:s,active:e,children:t.jsx(U.Code,{size:24})})}function Ct({size:o,side:r}){const e=n.useUIStore(a=>a.settingsModalOpen),s=n.useUIStore(a=>a.setSettingsModalOpen);return t.jsx(n.IconButton,{size:o,tooltipSide:r,label:"Editor settings",onClick:()=>s(!e),active:e,children:t.jsx(U.SlidersHorizontal,{size:24})})}function wt({id:o,size:r,side:e,onSubmit:s,basemapControl:a,attributionRef:c}){switch(o){case"toolbar":return t.jsx(n.FloatingToolbar,{embedded:!0});case"undo":return t.jsx(n.UndoButton,{size:r,tooltipSide:e});case"redo":return t.jsx(n.RedoButton,{size:r,tooltipSide:e});case"fitBounds":return t.jsx(n.FitBoundsButton,{size:r,tooltipSide:e});case"locate":return t.jsx(n.LocateButton,{size:r,tooltipSide:e});case"zoomIndicator":return t.jsx(n.ZoomIndicator,{size:r,tooltipSide:e});case"table":return t.jsx(vt,{size:r,side:e});case"schema":return t.jsx(St,{size:r,side:e});case"geojson":return t.jsx(jt,{size:r,side:e});case"settings":return t.jsx(Ct,{size:r,side:e});case"keyboard":return t.jsx(yt,{size:r,tooltipSide:e});case"applyChanges":return t.jsxs(n.Button,{variant:"primary",onClick:s,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",children:[t.jsx(U.Check,{size:20,weight:"bold"}),"Apply changes"]});case"attribution":return t.jsx("span",{ref:c,"data-elm-attribution":"",onMouseEnter:p=>{var u;p.currentTarget.title=((u=p.currentTarget.textContent)==null?void 0:u.trim())??""}});case"basemap":return l.isValidElement(a)?l.cloneElement(a,{size:r,tooltipSide:e}):null;default:return null}}function Et(){const o=n.useElementEditorConfig();return t.jsxs("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:[o.ui.dataTable&&t.jsx("div",{className:"flex-1 h-full relative overflow-hidden border-r border-elm-border",children:t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.DataTablePanel,{embedded:!0})})}),o.ui.layerList&&t.jsx("div",{className:"w-[320px] flex-shrink-0 h-full relative overflow-hidden bg-elm-surface",children:t.jsx(n.LayersPanel,{})})]})}function Rt({layout:o}){const r=n.useElementEditorConfig(),e=n.useUIStore(d=>d.dialogState),s=n.useUIStore(d=>d.schemaModalOpen),a=n.useUIStore(d=>d.toggleSchemaModal),c=n.useUIStore(d=>d.readonly),p=n.useUIStore(d=>d.codeModalOpen),u=n.useUIStore(d=>d.toggleCodeModal),x=n.useUIStore(d=>d.settingsModalOpen),f=n.useUIStore(d=>d.shortcutsModalOpen);return t.jsxs(t.Fragment,{children:[o==="minimal"&&e.type!=="closed"&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.FeatureEditModal,{dialogState:e})}),r.ui.dataTable&&o!=="split"&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.DataTablePanel,{})}),r.ui.keyboardShortcuts.show&&f&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.ShortcutsModal,{})}),r.ui.settings&&x&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.SettingsModal,{})}),r.ui.schemaEditor&&s&&!c&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(n.SchemaModal,{onClose:a})}),r.ui.geojsonEditor&&p&&t.jsx(l.Suspense,{fallback:t.jsx(n.GeoJSONDockPlaceholder,{}),children:t.jsx(n.GeoJSONModal,{onClose:u})})]})}const le=o=>{var r,e,s,a;return!((e=(r=o.dataTransfer)==null?void 0:r.types)!=null&&e.includes("Files"))||!!((a=(s=o.target).closest)!=null&&a.call(s,".cm-editor"))};function kt(o){const r=$.useGeoJSONFileImport(),[e,s]=l.useState(!1),a=l.useRef(0),c=l.useCallback(f=>{!o||le(f)||(f.preventDefault(),f.stopPropagation(),a.current+=1,s(!0))},[o]),p=l.useCallback(f=>{!o||le(f)||(f.preventDefault(),f.stopPropagation(),f.dataTransfer.dropEffect="copy")},[o]),u=l.useCallback(f=>{!o||le(f)||(f.stopPropagation(),a.current=Math.max(0,a.current-1),a.current===0&&s(!1))},[o]),x=l.useCallback(f=>{var w;if(a.current=0,s(!1),!o||le(f))return;f.preventDefault(),f.stopPropagation();const d=(w=f.dataTransfer.files)==null?void 0:w[0];d&&r(d)},[o,r]);return{active:o&&e,handlers:{onDragEnter:c,onDragOver:p,onDragLeave:u,onDrop:x}}}function Ot({enabled:o,children:r,footer:e}){const s=kt(o);return t.jsxs("div",{style:{display:"contents"},...s.handlers,children:[t.jsxs("div",{className:"relative flex-1 min-h-0 flex",children:[r,s.active&&t.jsx("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:t.jsxs("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:[t.jsx(U.FileArrowUp,{size:20,className:"text-elm-text-muted"}),t.jsx("span",{children:"Drop GeoJSON to import"})]})})]}),e]})}const xe="in-data-[elm-wrap]:flex-wrap in-data-[elm-wrap]:max-w-full",be="in-data-[elm-wrap]:flex-wrap-reverse in-data-[elm-wrap]:max-w-full",It={topLeft:[`flex-row items-start ${xe}`,"flex-col items-start"],topCenter:[`flex-row items-start justify-center ${xe}`,"flex-col items-center"],topRight:[`flex-row-reverse items-start ${xe}`,"flex-col items-end"],leftCenter:["flex-row items-center","flex-col items-start"],rightCenter:["flex-row-reverse items-center","flex-col items-end"],bottomLeft:[`flex-row items-end ${be}`,"flex-col-reverse items-start"],bottomCenter:[`flex-row items-end justify-center ${be}`,"flex-col-reverse items-center"],bottomRight:[`flex-row-reverse items-end ${be}`,"flex-col-reverse items-end"]},Mt=l.forwardRef(({initialData:o,initialView:r,schema:e,tools:s,maxFeatures:a,geometryTypes:c,replaceAtLimit:p,coordinates:u,bounds:x,readonly:f=!1,layout:d="panel",className:w="",style:b,theme:S,onChange:R,onSubmit:j,onValidationError:q,onFeatureSelect:ie,onZoomChange:J,onEvent:D,onError:F,onFeatureAdd:H,onFeatureUpdate:X,onFeatureDelete:z,onSelectionChange:Z,onToolChange:Y,onVertexEditChange:Q,slots:i,renderMap:h,basemapControl:y,extraApi:v,fileDrop:O=!0,engine:T="maplibre"},E)=>{const g=n.useElementEditorConfig(),{dataStore:I,uiStore:C}=n.useGeoStore(),_=n.useMapController(),k=s||(g.tools==="all"?null:g.tools),[ye]=l.useState(()=>r==="data"||r===void 0&&!Ae(g)),[ce,ve]=l.useState(null),Fe=l.useCallback((m,B)=>{if(!B||!ye)return;const M=W.getFeatureCollectionBBox({type:"FeatureCollection",metadata:{schemas:[],groups:[]},features:I.getState().features});M&&ve(M)},[ye,I]);l.useEffect(()=>{!ce||!_.fitBounds||(_.fitBounds(ce),ve(null))},[ce,_]);const ee=n.useAdapterControls({initialData:o,schema:e,layout:d,readonly:f,tools:k,maxFeatures:a,geometryTypes:c,replaceAtLimit:p,coordinates:u,onChange:R,onSubmit:j,onValidationError:q,onFeatureAdd:H,onFeatureUpdate:X,onFeatureDelete:z,onSelectionChange:Z,onFeatureSelect:ie,onZoomChange:J,onToolChange:Y,onVertexEditChange:Q,onInitialDataApplied:Fe}),ue=l.useMemo(()=>v?{...ee,...v}:ee,[ee,v]);l.useImperativeHandle(E,()=>ue,[ue]),l.useEffect(()=>{},[I,C,ue]),l.useLayoutEffect(()=>{C.getState().setBounds(x)},[x,C]);const P=n.useUIStore(m=>m.tableFullscreen),_e=n.useUIStore(m=>m.sidebarOpen),de=S!==null&&typeof S=="object";l.useEffect(()=>{de&&L.warnOnce("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`.")},[de]);const fe=xt(de?void 0:S),Ue={...g.accentColor?{"--elm-accent":g.accentColor}:{},"--elm-bottom-stack-offset":d==="split"?"calc(33.33% + 16px + var(--elm-bottom-row-height, 0px))":"calc(var(--elm-table-offset, 0px) + var(--elm-bottom-row-height, 0px) + 16px)",...b},Se=b?Object.entries(b).filter(([m,B])=>m.startsWith("--")&&B!=null&&B!==""):[],me=Se.length?JSON.stringify(Se):"",De=l.useMemo(()=>me?Object.fromEntries(JSON.parse(me)):void 0,[me]),ze=m=>$.isControlVisible(m,g.ui,{readonly:f,canSubmit:!!j,hasBasemaps:!!y}),te=m=>$.visibleLayoutEntries(g.ui.layout[m].items,ze),je=g.ui.keyboardShortcuts.enabled,Ve=(k==null?void 0:k.join())??null;l.useEffect(()=>{for(const m of $.layoutGaps(g.ui.layout,{readonly:f,canSubmit:!!j,tools:k,shortcuts:je}))L.warnOnce(`layoutGap:${m}`,`config.ui.layout: ${m}.`)},[g.ui.layout,f,!!j,Ve,je]);const[Ce,Ke]=l.useState(null),[Ge,We]=l.useState(null),we=(m,B,M)=>t.jsx(wt,{id:m,size:B,side:M,onSubmit:ee.submit,basemapControl:y,attributionRef:Ke},m),pe=(m,B)=>{const M=m==="statusLeft"||m==="statusRight",V=g.ui.layout[m].direction==="vertical",se=V?m.endsWith("Right")||m==="rightCenter"?"left":"right":m.startsWith("top")?"bottom":"top",K=A=>t.jsx("div",{"aria-hidden":!0,"data-elm-separator":"",className:`flex-shrink-0 bg-elm-border ${M?"w-px h-4 mx-1":V?"h-px w-5 my-0.5":"w-px h-5 mx-1"}`},A);return B.map((A,G)=>{if(A==="separator")return K(`sep-${G}`);if(typeof A=="string")return we(A,M?"sm":"md",se);const ae=A.group.map((Me,at)=>Me==="separator"?K(`gsep-${at}`):we(Me,M?"sm":"group",se));return M?t.jsx("div",{"data-elm-group":"",className:"flex items-center",children:ae},`group-${G}`):t.jsx(n.ControlGroup,{direction:V?"vertical":"horizontal",children:ae},`group-${G}`)})},Ee=$.LAYOUT_SLOTS.find(m=>te(m).includes("toolbar")),N=(m,B,M,V,se)=>{const K=te(m),A=i==null?void 0:i[m],[G,ae]=It[m];return t.jsxs("div",{ref:V,"data-elm-slot":m,style:M,className:`flex ${g.ui.layout[m].direction==="vertical"?ae:G} gap-2 ${K.length||A?"pointer-events-auto":""} ${B}`,children:[se,A,pe(m,K)]})},oe=(...m)=>Ee&&m.includes(Ee)?"z-[500]":"z-[400]",Re=d==="panel"&&g.ui.layerList&&!_e?56:0,re="var(--elm-panel-offset, 0px)",he=d==="split"?"calc(33.33% + 16px)":"calc(var(--elm-table-offset, 0px) + 16px)",{rootRef:ne,topRowRef:qe,bottomRowRef:Je,bottomLeftRef:He,bottomCenterRef:Xe,bottomRightRef:Ze,contextualRef:Ye,leftEdgeRef:Qe,rightEdgeRef:et,leftCenterRef:tt,rightCenterRef:ot}=bt(P,Re);gt(ne,T);const[rt,nt]=l.useState(null);l.useLayoutEffect(()=>{nt(ne.current)},[ne]);const st=$.useRootTokens(rt),ke=te("statusLeft"),Oe=te("statusRight"),Ie=ke.length+Oe.length>0,ge=Ie&&!!Ce;return t.jsx(n.ThemeContext.Provider,{value:fe,children:t.jsx($.RootCssVarsContext.Provider,{value:De,children:t.jsx($.RootTokensContext.Provider,{value:st,children:t.jsx(n.EventProvider,{onEvent:D,onError:F,toaster:!0,children:t.jsx("div",{ref:ne,"data-elm-theme":fe,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 ${w}`,style:Ue,children:t.jsxs(Ot,{enabled:O&&!f,footer:Ie&&t.jsxs("div",{"data-elm-status-bar":"",role:"toolbar","aria-label":"Status bar",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]",children:[t.jsx("div",{"data-elm-slot":"statusLeft",className:"flex items-center gap-1 min-w-0",children:pe("statusLeft",ke)}),t.jsx("div",{"data-elm-slot":"statusRight",className:"flex items-center gap-1 min-w-0",children:pe("statusRight",Oe)})]}),children:[h({attributionTarget:ge?Ce:null,attributionCorner:ge?null:Ge,themeMode:fe}),!P&&(i==null?void 0:i.toolbar),!P&&(i==null?void 0:i.mapOverlay)&&t.jsx("div",{className:"absolute inset-0 z-[300] pointer-events-none",children:i.mapOverlay}),!P&&t.jsxs("div",{ref:qe,"data-elm-edge":"top",style:{top:16,left:16,right:`calc(${re} + 16px)`},className:`absolute ${oe("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`,children:[N("topLeft","justify-self-start"),N("topCenter","justify-self-center mx-auto"),N("topRight","justify-self-end ml-auto transition-[margin] duration-200 in-data-[elm-wrap]:mr-0!",{marginRight:Re})]}),!P&&t.jsx("div",{ref:Qe,"data-elm-edge":"left",style:{top:16,bottom:he,left:16},className:`absolute ${oe("leftCenter")} flex flex-col justify-center pointer-events-none`,children:N("leftCenter","relative",{top:"var(--elm-left-center-shift, 0px)"},tt)}),!P&&t.jsx("div",{ref:et,"data-elm-edge":"right",style:{top:16,bottom:he,right:`calc(${re} + 16px)`},className:`absolute ${oe("rightCenter")} flex flex-col justify-center pointer-events-none transition-[right] duration-200`,children:N("rightCenter","relative",{top:"var(--elm-right-center-shift, 0px)"},ot)}),!P&&t.jsxs("div",{ref:Je,"data-elm-edge":"bottom",style:{bottom:he,left:16,right:`calc(${re} + 16px)`},className:`absolute ${oe("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`,children:[N("bottomLeft","justify-self-start",void 0,He),N("bottomCenter","justify-self-center mx-auto",void 0,Xe),N("bottomRight","justify-self-end ml-auto max-w-full",void 0,Ze,!ge&&t.jsx("div",{ref:We,"data-elm-attribution-corner":"",className:"pointer-events-auto flex items-end justify-end w-max",style:{maxWidth:"var(--elm-row-room, 100%)"}}))]}),!P&&t.jsx("div",{className:"absolute z-[400] flex justify-center pointer-events-none transition-[right] duration-200",style:{bottom:"var(--elm-bottom-stack-offset)",left:16,right:`calc(${re} + 16px)`},children:t.jsxs("div",{ref:Ye,"data-elm-contextual":"",className:"flex flex-wrap justify-center gap-2 max-w-full min-w-0",children:[t.jsx(n.EditingToolbar,{}),t.jsx(n.ActiveDrawingToolbar,{}),t.jsx(n.SimplifyPanel,{}),t.jsx(n.SmoothPanel,{}),t.jsx(n.BufferPanel,{}),t.jsx(n.ReadonlyBanner,{})]})}),!P&&g.ui.layerList&&d==="panel"&&t.jsx(n.LayersPanel,{footer:i==null?void 0:i.panelFooter}),d==="split"&&t.jsx(Et,{}),t.jsx(Rt,{layout:d})]})})})})})})}),$e=l.forwardRef((o,r)=>{var d;const{config:e,accentColor:s,featureColor:a,routingApiKey:c,onError:p}=o;c!==void 0&&L.warnOnce("routingApiKey","The `routingApiKey` prop is deprecated: use `config.network.routing.apiKey`.");const u=(d=e==null?void 0:e.network)==null?void 0:d.routing,x=!!c&&u!==!1&&!(u!=null&&u.apiKey),f=l.useMemo(()=>s||a||x?{...e,...s&&{accentColor:s},...a&&{featureColor:a},...x&&{network:{...e==null?void 0:e.network,routing:{...u||{},apiKey:c}}}}:e,[e,s,a,x,u,c]);return t.jsx(n.ElementEditorErrorBoundary,{onError:p,children:t.jsx(n.ElementEditorConfigProvider,{config:f,children:t.jsx(n.GeoStoreProvider,{children:t.jsx(n.ShortcutConfigProvider,{children:t.jsx(n.MapControllerProvider,{children:t.jsx(Mt,{...o,ref:r})})})})})})});$e.displayName="ElementEditorShell";const Tt=5e3,Bt=".leaflet-control-attribution, .elm-attribution-toggle, .maplibregl-ctrl-attrib";function Lt(o,r,e=!0){const s=l.useRef(r);l.useLayoutEffect(()=>{s.current=r});const a=l.useRef(()=>{});return l.useEffect(()=>{if(!e||!o)return;let c=!1,p;const u=()=>{c=!0,clearTimeout(p),document.removeEventListener("visibilitychange",w);for(const b of Be)o.removeEventListener(b,f,!0)},x=()=>{c||(u(),s.current())},f=b=>{b.target instanceof Element&&b.target.closest(Bt)||x()},d=()=>{p||(p=setTimeout(x,Tt))};function w(){document.visibilityState==="visible"&&d()}for(const b of Be)o.addEventListener(b,f,{capture:!0,passive:!0});return document.visibilityState==="hidden"?document.addEventListener("visibilitychange",w):d(),a.current=u,()=>{u(),a.current=()=>{}}},[o,e]),l.useCallback(()=>a.current(),[])}const Be=["pointerdown","wheel","keydown"];function Pt(o,r,e,s,a){const c=o!==void 0;c&&a&&!e&&L.warnOnce("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.");const[p,u]=l.useState(()=>o!==void 0?o:r()),x=c?o:p,f=l.useRef({current:x,controlled:c,onChange:e,remember:s});f.current={current:x,controlled:c,onChange:e,remember:s};const d=l.useCallback((b,S)=>{var j;const R=f.current;R.controlled||(u(b),S&&R.remember(b)),(j=R.onChange)==null||j.call(R,b)},[]),w=l.useMemo(()=>({getBasemap:()=>f.current.current,setBasemap:b=>d(b,!1)}),[d]);return{current:x,pick:d,api:w}}exports.ElementEditorShell=$e;exports.FIT_MAX_ZOOM=ct;exports.FIT_PADDING=it;exports.pickMapOptions=mt;exports.resolveInitialView=ft;exports.saveView=ut;exports.useAttributionAutoCollapse=Lt;exports.useBasemapState=Pt;
|