Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 42 additions & 21 deletions types/mapbox__mapbox-gl-draw/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
import { BBox, Feature, FeatureCollection, GeoJSON, GeoJsonTypes, Geometry, Point, Position } from "geojson";
import {
CircleLayer,
FillLayer,
CircleLayerSpecification,
ControlPosition,
FillLayerSpecification,
IControl,
LineLayer,
LineLayerSpecification,
Map,
MapboxEvent,
MapEvent,
MapMouseEvent as MapboxMapMouseEvent,
MapTouchEvent as MapboxMapTouchEvent,
} from "mapbox-gl";

export = MapboxDraw;
export as namespace MapboxDraw;

type EventOf<T extends MapboxDraw.DrawEventType, Target = unknown> = keyof MapboxDraw.DrawEvents[T] extends never ? {
type: T;
target: Target;
}
: {
type: T;
target: Target;
} & MapboxDraw.DrawEvents[T];

declare module "mapbox-gl" {
interface Map {
on<T extends MapboxDraw.DrawEventType>(type: T, listener: (event: EventOf<T>) => void): this;
off<T extends MapboxDraw.DrawEventType>(type: T, listener: (event: EventOf<T>) => void): this;
}
}

declare namespace MapboxDraw {
type DrawMode = DrawModes[keyof DrawModes];

type DrawEventType =
| "draw.create"
| "draw.delete"
| "draw.update"
| "draw.render"
| "draw.combine"
| "draw.uncombine"
| "draw.modechange"
| "draw.actionable"
| "draw.selectionchange";
interface DrawEvents {
"draw.create": MapboxDraw.DrawCreateEvent;
"draw.delete": MapboxDraw.DrawDeleteEvent;
"draw.update": MapboxDraw.DrawUpdateEvent;
"draw.selectionchange": MapboxDraw.DrawSelectionChangeEvent;
"draw.render": MapboxDraw.DrawRenderEvent;
"draw.combine": MapboxDraw.DrawCombineEvent;
"draw.uncombine": MapboxDraw.DrawUncombineEvent;
"draw.modechange": MapboxDraw.DrawModeChangeEvent;
"draw.actionable": MapboxDraw.DrawActionableEvent;
}
type DrawEventType = keyof DrawEvents;

interface DrawModes {
DRAW_LINE_STRING: "draw_line_string";
Expand Down Expand Up @@ -178,7 +197,7 @@ declare namespace MapboxDraw {
}

interface DrawCustomModeThis {
map: mapboxgl.Map;
map: Map;

drawConfig: MapboxDrawOptions;

Expand Down Expand Up @@ -389,13 +408,13 @@ declare namespace MapboxDraw {
isOfMetaType: (
type: Constants["meta"][keyof Constants["meta"]],
) => (e: MapMouseEvent | MapTouchEvent) => boolean;
isShiftMousedown: (e: MapboxEvent) => boolean;
isShiftMousedown: (e: MapEvent) => boolean;
isActiveFeature: (e: MapMouseEvent | MapTouchEvent) => boolean;
isInactiveFeature: (e: MapMouseEvent | MapTouchEvent) => boolean;
noTarget: (e: MapMouseEvent | MapTouchEvent) => boolean;
isFeature: (e: MapMouseEvent | MapTouchEvent) => boolean;
isVertex: (e: MapMouseEvent | MapTouchEvent) => boolean;
isShiftDown: (e: MapboxEvent) => boolean;
isShiftDown: (e: MapEvent) => boolean;
isEscapeKey: (e: KeyboardEvent) => boolean;
isEnterKey: (e: KeyboardEvent) => boolean;
isTrue: () => boolean;
Expand Down Expand Up @@ -503,7 +522,9 @@ declare namespace MapboxDraw {

StringSet(items?: Array<string | number>): StringSet;

theme: Array<(FillLayer | LineLayer | CircleLayer) & { id: ThemeLayerId }>;
theme: Array<
(FillLayerSpecification | LineLayerSpecification | CircleLayerSpecification) & { id: ThemeLayerId }
>;

/**
* Derive a dense array (no `undefined`s) from a single value or array.
Expand Down Expand Up @@ -552,7 +573,7 @@ declare class MapboxDraw implements IControl {

modes: MapboxDraw.DrawModes;

getDefaultPosition: () => string;
getDefaultPosition: () => ControlPosition;

constructor(options?: MapboxDraw.MapboxDrawOptions);

Expand Down Expand Up @@ -595,7 +616,7 @@ declare class MapboxDraw implements IControl {

setFeatureProperty(featureId: string, property: string, value: any): this;

onAdd(map: mapboxgl.Map): HTMLElement;
onAdd(map: Map): HTMLElement;

onRemove(map: mapboxgl.Map): any;
onRemove(map: Map): any;
}
4 changes: 2 additions & 2 deletions types/mapbox__mapbox-gl-draw/mapbox__mapbox-gl-draw-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const customMode: CustomMode = {
// $ExpectType DrawFeature
e.featureTarget;

// $ExpectType Map
// $ExpectType Map$1
this.map;

// $ExpectType boolean | undefined
Expand Down Expand Up @@ -169,7 +169,7 @@ const customMode: CustomMode = {
// $ExpectType StringSet
lib.StringSet(["1", 2]);

const FabricDrawingManagerStyles: Lib["theme"] = [
const FabricDrawingManagerStyles: Array<Partial<Lib["theme"][number]>> = [
{
id: "gl-draw-polygon-fill-inactive",
type: "fill",
Expand Down
6 changes: 5 additions & 1 deletion types/mapbox__mapbox-gl-draw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"dependencies": {
"@types/geojson": "*",
"@types/mapbox-gl": "*"
"mapbox-gl": "*"
},
"devDependencies": {
"@types/mapbox__mapbox-gl-draw": "workspace:."
Expand All @@ -24,6 +24,10 @@
{
"name": "Joel Daros",
"githubUsername": "joel-daros"
},
{
"name": "Brook Jordan",
"githubUsername": "brookjordan"
}
]
}