This commit is contained in:
2025-09-11 07:45:47 -07:00
parent 955946e79d
commit a9425720e9
2759 changed files with 0 additions and 294955 deletions

View File

@@ -1,2 +0,0 @@
import type { Map } from 'leaflet';
export declare function useAttribution(map: Map, attribution: string | null | undefined): void;

View File

@@ -1,18 +0,0 @@
import { useEffect, useRef } from 'react';
export function useAttribution(map, attribution) {
const attributionRef = useRef(attribution);
useEffect(function updateAttribution() {
if (attribution !== attributionRef.current && map.attributionControl != null) {
if (attributionRef.current != null) {
map.attributionControl.removeAttribution(attributionRef.current);
}
if (attribution != null) {
map.attributionControl.addAttribution(attribution);
}
}
attributionRef.current = attribution;
}, [
map,
attribution
]);
}

View File

@@ -1,12 +0,0 @@
import type { Circle as LeafletCircle, CircleMarker as LeafletCircleMarker, CircleMarkerOptions, CircleOptions, LatLngExpression } from 'leaflet';
import type { ReactNode } from 'react';
import type { PathProps } from './path.js';
export interface CircleMarkerProps extends CircleMarkerOptions, PathProps {
center: LatLngExpression;
children?: ReactNode;
}
export interface CircleProps extends CircleOptions, PathProps {
center: LatLngExpression;
children?: ReactNode;
}
export declare function updateCircle<P extends CircleMarkerProps | CircleProps>(layer: LeafletCircle<P> | LeafletCircleMarker<P>, props: P, prevProps: P): void;

View File

@@ -1,8 +0,0 @@
export function updateCircle(layer, props, prevProps) {
if (props.center !== prevProps.center) {
layer.setLatLng(props.center);
}
if (props.radius != null && props.radius !== prevProps.radius) {
layer.setRadius(props.radius);
}
}

View File

@@ -1,11 +0,0 @@
import React, { type MutableRefObject, type ReactNode } from 'react';
import type { DivOverlay, DivOverlayHook } from './div-overlay.js';
import type { LeafletElement } from './element.js';
declare type ElementHook<E, P> = (props: P) => MutableRefObject<LeafletElement<E>>;
export declare type PropsWithChildren = {
children?: ReactNode;
};
export declare function createContainerComponent<E, P extends PropsWithChildren>(useElement: ElementHook<E, P>): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<E>>;
export declare function createDivOverlayComponent<E extends DivOverlay, P extends PropsWithChildren>(useElement: ReturnType<DivOverlayHook<E, P>>): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<E>>;
export declare function createLeafComponent<E, P>(useElement: ElementHook<E, P>): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<E>>;
export {};

View File

@@ -1,41 +0,0 @@
import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
import { createPortal } from 'react-dom';
import { LeafletProvider } from './context.js';
export function createContainerComponent(useElement) {
function ContainerComponent(props, forwardedRef) {
const { instance , context } = useElement(props).current;
useImperativeHandle(forwardedRef, ()=>instance);
return props.children == null ? null : /*#__PURE__*/ React.createElement(LeafletProvider, {
value: context
}, props.children);
}
return /*#__PURE__*/ forwardRef(ContainerComponent);
}
export function createDivOverlayComponent(useElement) {
function OverlayComponent(props, forwardedRef) {
const [isOpen, setOpen] = useState(false);
const { instance } = useElement(props, setOpen).current;
useImperativeHandle(forwardedRef, ()=>instance);
useEffect(function updateOverlay() {
if (isOpen) {
instance.update();
}
}, [
instance,
isOpen,
props.children
]);
// @ts-ignore _contentNode missing in type definition
const contentNode = instance._contentNode;
return contentNode ? /*#__PURE__*/ createPortal(props.children, contentNode) : null;
}
return /*#__PURE__*/ forwardRef(OverlayComponent);
}
export function createLeafComponent(useElement) {
function LeafComponent(props, forwardedRef) {
const { instance } = useElement(props).current;
useImperativeHandle(forwardedRef, ()=>instance);
return null;
}
return /*#__PURE__*/ forwardRef(LeafComponent);
}

View File

@@ -1,34 +0,0 @@
/// <reference types="react" />
import type { Control, Layer, LayerGroup, Map } from 'leaflet';
export declare const CONTEXT_VERSION = 1;
export declare type ControlledLayer = {
addLayer(layer: Layer): void;
removeLayer(layer: Layer): void;
};
export declare type LeafletContextInterface = Readonly<{
__version: number;
map: Map;
layerContainer?: ControlledLayer | LayerGroup;
layersControl?: Control.Layers;
overlayContainer?: Layer;
pane?: string;
}>;
export declare function createLeafletContext(map: Map): LeafletContextInterface;
export declare function extendContext(source: LeafletContextInterface, extra: Partial<LeafletContextInterface>): LeafletContextInterface;
export declare const LeafletContext: import("react").Context<Readonly<{
__version: number;
map: Map;
layerContainer?: LayerGroup<any> | ControlledLayer | undefined;
layersControl?: Control.Layers | undefined;
overlayContainer?: Layer | undefined;
pane?: string | undefined;
}> | null>;
export declare const LeafletProvider: import("react").Provider<Readonly<{
__version: number;
map: Map;
layerContainer?: LayerGroup<any> | ControlledLayer | undefined;
layersControl?: Control.Layers | undefined;
overlayContainer?: Layer | undefined;
pane?: string | undefined;
}> | null>;
export declare function useLeafletContext(): LeafletContextInterface;

View File

@@ -1,23 +0,0 @@
import { createContext, useContext } from 'react';
export const CONTEXT_VERSION = 1;
export function createLeafletContext(map) {
return Object.freeze({
__version: CONTEXT_VERSION,
map
});
}
export function extendContext(source, extra) {
return Object.freeze({
...source,
...extra
});
}
export const LeafletContext = createContext(null);
export const LeafletProvider = LeafletContext.Provider;
export function useLeafletContext() {
const context = useContext(LeafletContext);
if (context == null) {
throw new Error('No context provided: useLeafletContext() can only be used in a descendant of <MapContainer>');
}
return context;
}

View File

@@ -1,3 +0,0 @@
import { Control, type ControlOptions } from 'leaflet';
import type { ElementHook } from './element.js';
export declare function createControlHook<E extends Control, P extends ControlOptions>(useElement: ElementHook<E, P>): (props: P) => ReturnType<ElementHook<E, P>>;

View File

@@ -1,30 +0,0 @@
import { useEffect, useRef } from 'react';
import { useLeafletContext } from './context.js';
export function createControlHook(useElement) {
return function useLeafletControl(props) {
const context = useLeafletContext();
const elementRef = useElement(props, context);
const { instance } = elementRef.current;
const positionRef = useRef(props.position);
const { position } = props;
useEffect(function addControl() {
instance.addTo(context.map);
return function removeControl() {
instance.remove();
};
}, [
context.map,
instance
]);
useEffect(function updateControl() {
if (position != null && position !== positionRef.current) {
instance.setPosition(position);
positionRef.current = position;
}
}, [
instance,
position
]);
return elementRef;
};
}

View File

@@ -1,9 +0,0 @@
import type { Popup, Tooltip } from 'leaflet';
import { type LeafletContextInterface } from './context.js';
import type { LeafletElement, ElementHook } from './element.js';
import type { LayerProps } from './layer.js';
export declare type DivOverlay = Popup | Tooltip;
export declare type SetOpenFunc = (open: boolean) => void;
export declare type DivOverlayLifecycleHook<E, P> = (element: LeafletElement<E>, context: LeafletContextInterface, props: P, setOpen: SetOpenFunc) => void;
export declare type DivOverlayHook<E extends DivOverlay, P> = (useElement: ElementHook<E, P>, useLifecycle: DivOverlayLifecycleHook<E, P>) => (props: P, setOpen: SetOpenFunc) => ReturnType<ElementHook<E, P>>;
export declare function createDivOverlayHook<E extends DivOverlay, P extends LayerProps>(useElement: ElementHook<E, P>, useLifecycle: DivOverlayLifecycleHook<E, P>): (props: P, setOpen: SetOpenFunc) => ReturnType<ElementHook<E, P>>;

View File

@@ -1,14 +0,0 @@
import { useAttribution } from './attribution.js';
import { useLeafletContext } from './context.js';
import { useEventHandlers } from './events.js';
import { withPane } from './pane.js';
export function createDivOverlayHook(useElement, useLifecycle) {
return function useDivOverlay(props, setOpen) {
const context = useLeafletContext();
const elementRef = useElement(withPane(props, context), context);
useAttribution(context.map, props.attribution);
useEventHandlers(elementRef.current, props.eventHandlers);
useLifecycle(elementRef.current, context, props, setOpen);
return elementRef;
};
}

View File

@@ -1,3 +0,0 @@
export declare function addClassName(element: HTMLElement, className: string): void;
export declare function removeClassName(element: HTMLElement, className: string): void;
export declare function updateClassName(element?: HTMLElement, prevClassName?: string, nextClassName?: string): void;

View File

@@ -1,24 +0,0 @@
import { DomUtil } from 'leaflet';
function splitClassName(className) {
return className.split(' ').filter(Boolean);
}
export function addClassName(element, className) {
splitClassName(className).forEach((cls)=>{
DomUtil.addClass(element, cls);
});
}
export function removeClassName(element, className) {
splitClassName(className).forEach((cls)=>{
DomUtil.removeClass(element, cls);
});
}
export function updateClassName(element, prevClassName, nextClassName) {
if (element != null && nextClassName !== prevClassName) {
if (prevClassName != null && prevClassName.length > 0) {
removeClassName(element, prevClassName);
}
if (nextClassName != null && nextClassName.length > 0) {
addClassName(element, nextClassName);
}
}
}

View File

@@ -1,10 +0,0 @@
import { type MutableRefObject } from 'react';
import type { LeafletContextInterface } from './context.js';
export declare type LeafletElement<T, C = any> = Readonly<{
instance: T;
context: LeafletContextInterface;
container?: C | null;
}>;
export declare function createElementObject<T, C = any>(instance: T, context: LeafletContextInterface, container?: C | null): LeafletElement<T, C>;
export declare type ElementHook<E, P> = (props: P, context: LeafletContextInterface) => MutableRefObject<LeafletElement<E>>;
export declare function createElementHook<E, P, C = any>(createElement: (props: P, context: LeafletContextInterface) => LeafletElement<E>, updateElement?: (instance: E, props: P, prevProps: P) => void): (props: P, context: LeafletContextInterface) => ReturnType<ElementHook<E, P>>;

View File

@@ -1,34 +0,0 @@
import { useEffect, useRef } from 'react';
export function createElementObject(instance, context, container) {
return Object.freeze({
instance,
context,
container
});
}
export function createElementHook(createElement, updateElement) {
if (updateElement == null) {
return function useImmutableLeafletElement(props, context) {
const elementRef = useRef();
if (!elementRef.current) elementRef.current = createElement(props, context);
return elementRef;
};
}
return function useMutableLeafletElement(props, context) {
const elementRef = useRef();
if (!elementRef.current) elementRef.current = createElement(props, context);
const propsRef = useRef(props);
const { instance } = elementRef.current;
useEffect(function updateElementProps() {
if (propsRef.current !== props) {
updateElement(instance, props, propsRef.current);
propsRef.current = props;
}
}, [
instance,
props,
context
]);
return elementRef;
};
}

View File

@@ -1,6 +0,0 @@
import type { Evented, LeafletEventHandlerFnMap } from 'leaflet';
import type { LeafletElement } from './element.js';
export declare type EventedProps = {
eventHandlers?: LeafletEventHandlerFnMap;
};
export declare function useEventHandlers(element: LeafletElement<Evented>, eventHandlers: LeafletEventHandlerFnMap | null | undefined): void;

View File

@@ -1,19 +0,0 @@
import { useEffect, useRef } from 'react';
export function useEventHandlers(element, eventHandlers) {
const eventHandlersRef = useRef();
useEffect(function addEventHandlers() {
if (eventHandlers != null) {
element.instance.on(eventHandlers);
}
eventHandlersRef.current = eventHandlers;
return function removeEventHandlers() {
if (eventHandlersRef.current != null) {
element.instance.off(eventHandlersRef.current);
}
eventHandlersRef.current = null;
};
}, [
element,
eventHandlers
]);
}

View File

@@ -1,18 +0,0 @@
/// <reference types="react" />
import type { Control, ControlOptions, FeatureGroup, Layer, Path } from 'leaflet';
import { type PropsWithChildren } from './component.js';
import type { LeafletContextInterface } from './context.js';
import { type LeafletElement } from './element.js';
import { type LayerProps } from './layer.js';
import { type DivOverlay, type DivOverlayLifecycleHook } from './div-overlay.js';
import { type PathProps } from './path.js';
interface LayerWithChildrenProps extends LayerProps, PropsWithChildren {
}
interface PathWithChildrenProps extends PathProps, PropsWithChildren {
}
export declare function createControlComponent<E extends Control, P extends ControlOptions>(createInstance: (props: P) => E): import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<P> & import("react").RefAttributes<E>>;
export declare function createLayerComponent<E extends Layer, P extends LayerWithChildrenProps>(createElement: (props: P, context: LeafletContextInterface) => LeafletElement<E>, updateElement?: (instance: E, props: P, prevProps: P) => void): import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<P> & import("react").RefAttributes<E>>;
export declare function createOverlayComponent<E extends DivOverlay, P extends LayerWithChildrenProps>(createElement: (props: P, context: LeafletContextInterface) => LeafletElement<E>, useLifecycle: DivOverlayLifecycleHook<E, P>): import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<P> & import("react").RefAttributes<E>>;
export declare function createPathComponent<E extends FeatureGroup | Path, P extends PathWithChildrenProps>(createElement: (props: P, context: LeafletContextInterface) => LeafletElement<E>, updateElement?: (instance: E, props: P, prevProps: P) => void): import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<P> & import("react").RefAttributes<E>>;
export declare function createTileLayerComponent<E extends Layer, P extends LayerProps>(createElement: (props: P, context: LeafletContextInterface) => LeafletElement<E>, updateElement?: (instance: E, props: P, prevProps: P) => void): import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<P> & import("react").RefAttributes<E>>;
export {};

View File

@@ -1,34 +0,0 @@
import { createContainerComponent, createDivOverlayComponent, createLeafComponent } from './component.js';
import { createControlHook } from './control.js';
import { createElementHook, createElementObject } from './element.js';
import { createLayerHook } from './layer.js';
import { createDivOverlayHook } from './div-overlay.js';
import { createPathHook } from './path.js';
export function createControlComponent(createInstance) {
function createElement(props, context) {
return createElementObject(createInstance(props), context);
}
const useElement = createElementHook(createElement);
const useControl = createControlHook(useElement);
return createLeafComponent(useControl);
}
export function createLayerComponent(createElement, updateElement) {
const useElement = createElementHook(createElement, updateElement);
const useLayer = createLayerHook(useElement);
return createContainerComponent(useLayer);
}
export function createOverlayComponent(createElement, useLifecycle) {
const useElement = createElementHook(createElement);
const useOverlay = createDivOverlayHook(useElement, useLifecycle);
return createDivOverlayComponent(useOverlay);
}
export function createPathComponent(createElement, updateElement) {
const useElement = createElementHook(createElement, updateElement);
const usePath = createPathHook(useElement);
return createContainerComponent(usePath);
}
export function createTileLayerComponent(createElement, updateElement) {
const useElement = createElementHook(createElement, updateElement);
const useLayer = createLayerHook(useElement);
return createLeafComponent(useLayer);
}

View File

@@ -1,2 +0,0 @@
import type { GridLayer, GridLayerOptions } from 'leaflet';
export declare function updateGridLayer<E extends GridLayer, P extends GridLayerOptions>(layer: E, props: P, prevProps: P): void;

View File

@@ -1,9 +0,0 @@
export function updateGridLayer(layer, props, prevProps) {
const { opacity , zIndex } = props;
if (opacity != null && opacity !== prevProps.opacity) {
layer.setOpacity(opacity);
}
if (zIndex != null && zIndex !== prevProps.zIndex) {
layer.setZIndex(zIndex);
}
}

View File

@@ -1,15 +0,0 @@
export { useAttribution } from './attribution.js';
export { type CircleMarkerProps, type CircleProps, updateCircle, } from './circle.js';
export { createContainerComponent, createDivOverlayComponent, createLeafComponent, } from './component.js';
export { CONTEXT_VERSION, type LeafletContextInterface, LeafletContext, LeafletProvider, createLeafletContext, extendContext, useLeafletContext, } from './context.js';
export { createControlHook } from './control.js';
export { type DivOverlayHook, type DivOverlayLifecycleHook, type SetOpenFunc, createDivOverlayHook, } from './div-overlay.js';
export { addClassName, removeClassName, updateClassName } from './dom.js';
export { type ElementHook, type LeafletElement, createElementHook, createElementObject, } from './element.js';
export { type EventedProps, useEventHandlers } from './events.js';
export { createControlComponent, createLayerComponent, createOverlayComponent, createPathComponent, createTileLayerComponent, } from './generic.js';
export { updateGridLayer } from './grid-layer.js';
export { type InteractiveLayerProps, type LayerProps, createLayerHook, useLayerLifecycle, } from './layer.js';
export { type MediaOverlayProps, updateMediaOverlay } from './media-overlay.js';
export { withPane } from './pane.js';
export { type PathProps, createPathHook, usePathOptions } from './path.js';

View File

@@ -1,15 +0,0 @@
export { useAttribution } from './attribution.js';
export { updateCircle } from './circle.js';
export { createContainerComponent, createDivOverlayComponent, createLeafComponent } from './component.js';
export { CONTEXT_VERSION, LeafletContext, LeafletProvider, createLeafletContext, extendContext, useLeafletContext } from './context.js';
export { createControlHook } from './control.js';
export { createDivOverlayHook } from './div-overlay.js';
export { addClassName, removeClassName, updateClassName } from './dom.js';
export { createElementHook, createElementObject } from './element.js';
export { useEventHandlers } from './events.js';
export { createControlComponent, createLayerComponent, createOverlayComponent, createPathComponent, createTileLayerComponent } from './generic.js';
export { updateGridLayer } from './grid-layer.js';
export { createLayerHook, useLayerLifecycle } from './layer.js';
export { updateMediaOverlay } from './media-overlay.js';
export { withPane } from './pane.js';
export { createPathHook, usePathOptions } from './path.js';

View File

@@ -1,10 +0,0 @@
import type { InteractiveLayerOptions, Layer, LayerOptions } from 'leaflet';
import { type LeafletContextInterface } from './context.js';
import type { LeafletElement, ElementHook } from './element.js';
import { type EventedProps } from './events.js';
export interface LayerProps extends EventedProps, LayerOptions {
}
export interface InteractiveLayerProps extends LayerProps, InteractiveLayerOptions {
}
export declare function useLayerLifecycle(element: LeafletElement<Layer>, context: LeafletContextInterface): void;
export declare function createLayerHook<E extends Layer, P extends LayerProps>(useElement: ElementHook<E, P>): (props: P) => ReturnType<ElementHook<E, P>>;

View File

@@ -1,28 +0,0 @@
import { useEffect } from 'react';
import { useAttribution } from './attribution.js';
import { useLeafletContext } from './context.js';
import { useEventHandlers } from './events.js';
import { withPane } from './pane.js';
export function useLayerLifecycle(element, context) {
useEffect(function addLayer() {
const container = context.layerContainer ?? context.map;
container.addLayer(element.instance);
return function removeLayer() {
context.layerContainer?.removeLayer(element.instance);
context.map.removeLayer(element.instance);
};
}, [
context,
element
]);
}
export function createLayerHook(useElement) {
return function useLayer(props) {
const context = useLeafletContext();
const elementRef = useElement(withPane(props, context), context);
useAttribution(context.map, props.attribution);
useEventHandlers(elementRef.current, props.eventHandlers);
useLayerLifecycle(elementRef.current, context);
return elementRef;
};
}

View File

@@ -1,6 +0,0 @@
import { type LatLngBoundsExpression, type ImageOverlay as LeafletImageOverlay, type ImageOverlayOptions, type SVGOverlay as LeafletSVGOverlay, type VideoOverlay as LeafletVideoOverlay } from 'leaflet';
import type { InteractiveLayerProps } from './layer.js';
export interface MediaOverlayProps extends ImageOverlayOptions, InteractiveLayerProps {
bounds: LatLngBoundsExpression;
}
export declare function updateMediaOverlay<E extends LeafletImageOverlay | LeafletSVGOverlay | LeafletVideoOverlay, P extends MediaOverlayProps>(overlay: E, props: P, prevProps: P): void;

View File

@@ -1,13 +0,0 @@
import { LatLngBounds } from 'leaflet';
export function updateMediaOverlay(overlay, props, prevProps) {
if (props.bounds instanceof LatLngBounds && props.bounds !== prevProps.bounds) {
overlay.setBounds(props.bounds);
}
if (props.opacity != null && props.opacity !== prevProps.opacity) {
overlay.setOpacity(props.opacity);
}
if (props.zIndex != null && props.zIndex !== prevProps.zIndex) {
// @ts-ignore missing in definition but inherited from ImageOverlay
overlay.setZIndex(props.zIndex);
}
}

View File

@@ -1,3 +0,0 @@
import type { LayerOptions } from 'leaflet';
import type { LeafletContextInterface } from './context.js';
export declare function withPane<P extends LayerOptions>(props: P, context: LeafletContextInterface): P;

View File

@@ -1,7 +0,0 @@
export function withPane(props, context) {
const pane = props.pane ?? context.pane;
return pane ? {
...props,
pane
} : props;
}

View File

@@ -1,8 +0,0 @@
import type { FeatureGroup, Path, PathOptions } from 'leaflet';
import type { LeafletElement, ElementHook } from './element.js';
import { type InteractiveLayerProps } from './layer.js';
export interface PathProps extends InteractiveLayerProps {
pathOptions?: PathOptions;
}
export declare function usePathOptions(element: LeafletElement<FeatureGroup | Path>, props: PathProps): void;
export declare function createPathHook<E extends FeatureGroup | Path, P extends PathProps>(useElement: ElementHook<E, P>): (props: P) => ReturnType<ElementHook<E, P>>;

View File

@@ -1,28 +0,0 @@
import { useEffect, useRef } from 'react';
import { useLeafletContext } from './context.js';
import { useEventHandlers } from './events.js';
import { useLayerLifecycle } from './layer.js';
import { withPane } from './pane.js';
export function usePathOptions(element, props) {
const optionsRef = useRef();
useEffect(function updatePathOptions() {
if (props.pathOptions !== optionsRef.current) {
const options = props.pathOptions ?? {};
element.instance.setStyle(options);
optionsRef.current = options;
}
}, [
element,
props
]);
}
export function createPathHook(useElement) {
return function usePath(props) {
const context = useLeafletContext();
const elementRef = useElement(withPane(props, context), context);
useEventHandlers(elementRef.current, props.eventHandlers);
useLayerLifecycle(elementRef.current, context);
usePathOptions(elementRef.current, props);
return elementRef;
};
}