🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More

@freenow/react-polygon-editor

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@freenow/react-polygon-editor - npm Package Compare versions

Comparing version

to
1.1.0-rc.2

# Changelog
## [~]
## [1.1.0.rc2] - 11.03.2020
- Feat: Import polygons from GeoJSON
## [1.1.0.rc1] - 06.03.2020
- Feat: Rectangle selection
- Feat: Export polygons as GeoJSON, JTS or LatLng
## [0.0.1] - 08.03.2019

@@ -6,0 +13,0 @@

@@ -10,3 +10,4 @@ import { FunctionComponent } from 'react';

onExport: () => void;
onImport: () => void;
}
export declare const ActionBar: FunctionComponent<Props>;

@@ -19,8 +19,9 @@ import React from 'react';

`;
export const ActionBar = ({ editable, deleteInactive, isVectorModeEnabled, onEnableVectorMode, onFocus, onDelete, onExport }) => (React.createElement(Container, null,
export const ActionBar = ({ editable, deleteInactive, isVectorModeEnabled, onEnableVectorMode, onFocus, onDelete, onExport, onImport }) => (React.createElement(Container, null,
editable && (React.createElement(React.Fragment, null,
React.createElement(ActionButton, { onClick: onEnableVectorMode, icon: ActionButtonIcons.VECTOR_MODE, inactive: !isVectorModeEnabled }, LABELS.PEN),
React.createElement(ActionButton, { onClick: onDelete, icon: ActionButtonIcons.TRASHCAN, activeIconColor: FREEDOM_RED_900, disabled: deleteInactive, inactive: deleteInactive }, LABELS.DELETE))),
React.createElement(ActionButton, { onClick: onImport, icon: ActionButtonIcons.IMPORT }, LABELS.IMPORT),
React.createElement(ActionButton, { onClick: onExport, icon: ActionButtonIcons.EXPORT }, LABELS.EXPORT),
React.createElement(ActionButton, { onClick: onFocus, icon: ActionButtonIcons.FRAME }, LABELS.FOCUS)));
//# sourceMappingURL=ActionBar.js.map

@@ -6,3 +6,4 @@ import { FunctionComponent } from 'react';

VECTOR_MODE = "VECTOR_MODE",
EXPORT = "EXPORT"
EXPORT = "EXPORT",
IMPORT = "IMPORT"
}

@@ -9,0 +10,0 @@ export interface Props {

@@ -19,2 +19,3 @@ var __rest = (this && this.__rest) || function (s, e) {

import { Export } from './Icons/Export';
import { Import } from './Icons/Import';
export var ActionButtonIcons;

@@ -26,2 +27,3 @@ (function (ActionButtonIcons) {

ActionButtonIcons["EXPORT"] = "EXPORT";
ActionButtonIcons["IMPORT"] = "IMPORT";
})(ActionButtonIcons || (ActionButtonIcons = {}));

@@ -70,2 +72,4 @@ const Container = styled('div') `

return React.createElement(Export, Object.assign({}, props));
case ActionButtonIcons.IMPORT:
return React.createElement(Import, Object.assign({}, props));
default:

@@ -72,0 +76,0 @@ return null;

@@ -16,5 +16,5 @@ var __rest = (this && this.__rest) || function (s, e) {

var { iconColor = AUTHENTIC_BLUE_900 } = _a, props = __rest(_a, ["iconColor"]);
return (React.createElement("svg", Object.assign({ viewBox: "0 0 12 12" }, props),
React.createElement("path", { fill: iconColor, d: "M8.625 8.625v.75h-5.25v-.75h5.25zM6 2.625l2.25 2v1.003L6.375 3.961v3.914h-.75V3.962L3.75 5.629V4.625l2.25-2z" })));
return (React.createElement("svg", Object.assign({ viewBox: "0 0 24 24" }, props),
React.createElement("path", { d: "M19 19v2H5v-2h14zM13 3v10.436l5-4.445v2.676L12 17l-6-5.333V8.991l5 4.445V3h2z", fill: iconColor, fillRule: "nonzero" })));
};
//# sourceMappingURL=Export.js.map

@@ -9,2 +9,6 @@ export declare const ACTION_BLUE_900 = "#096bdb";

export declare const FREEDOM_RED_900 = "#ff0a2b";
export declare const NEGATIVE_ORANGE_50 = "#fff6f1";
export declare const NEGATIVE_ORANGE_900 = "#ff5e05";
export declare const POSITIVE_GREEN_50 = "#f1faf5";
export declare const POSITIVE_GREEN_900 = "#069d4f";
export declare const WHITE = "#ffffff";

@@ -9,3 +9,7 @@ export const ACTION_BLUE_900 = '#096bdb';

export const FREEDOM_RED_900 = '#ff0a2b';
export const NEGATIVE_ORANGE_50 = '#fff6f1';
export const NEGATIVE_ORANGE_900 = '#ff5e05';
export const POSITIVE_GREEN_50 = '#f1faf5';
export const POSITIVE_GREEN_900 = '#069d4f';
export const WHITE = '#ffffff';
//# sourceMappingURL=colors.js.map

@@ -1,1 +0,5 @@

export declare const Text: import("styled-components").StyledComponent<"p", any, {}, never>;
interface Props {
weak?: boolean;
}
export declare const Text: import("styled-components").StyledComponent<"p", any, Props, never>;
export {};
import styled from 'styled-components';
import { ACTION_BLUE_900, AUTHENTIC_BLUE_550 } from '../colors';
import { ACTION_BLUE_900, AUTHENTIC_BLUE_550, AUTHENTIC_BLUE_1100 } from '../colors';
export const Text = styled.p `
color: ${AUTHENTIC_BLUE_550};
color: ${({ weak }) => (weak ? AUTHENTIC_BLUE_550 : AUTHENTIC_BLUE_1100)};
font-size: 14px;
margin-bottom: 24px;

@@ -8,0 +7,0 @@ a,

@@ -15,4 +15,5 @@ import styled from 'styled-components';

outline: none;
white-space: pre;
width: 100%;
`;
//# sourceMappingURL=Textarea.js.map

@@ -7,2 +7,3 @@ import { LatLngTuple } from 'leaflet';

EXPORT: string;
IMPORT: string;
};

@@ -9,0 +10,0 @@ export declare const LEAFLET: {

@@ -1,2 +0,2 @@

import { ACTION_BLUE_900, FREEDOM_RED_900, AUTHENTIC_BLUE_550, WHITE, AUTHENTIC_BLUE_350, } from './common/colors';
import { ACTION_BLUE_900, FREEDOM_RED_900, AUTHENTIC_BLUE_550, WHITE, AUTHENTIC_BLUE_350 } from './common/colors';
export const LABELS = {

@@ -6,3 +6,4 @@ PEN: 'Pen',

FOCUS: 'Focus',
EXPORT: 'Export'
EXPORT: 'Export',
IMPORT: 'Import'
};

@@ -9,0 +10,0 @@ export const LEAFLET = {

@@ -17,2 +17,5 @@ import React, { useState, useMemo } from 'react';

`;
const Description = styled(Text).attrs(() => ({ weak: true })) `
margin-bottom: 24px;
`;
const rippleAnimation = keyframes `

@@ -46,3 +49,3 @@ 0% {

? css `
animation: ${rippleAnimation} 0.3s ease-out;
animation: ${rippleAnimation} 0.4s ease-out;
`

@@ -66,2 +69,3 @@ : ''}

const [copyButtonClicked, setCopyButtonClicked] = useState(false);
const [copyOverlayIsActive, setCopyOverlayIsActive] = useState(false);
const [copyOverlayClicked, setCopyOverlayClicked] = useState(false);

@@ -75,4 +79,8 @@ const dismiss = useDismiss();

const handleCopyOverlayClicked = () => {
setCopyOverlayClicked(true);
onSubmit(value);
if (!copyOverlayClicked) {
setCopyOverlayIsActive(true);
setCopyOverlayClicked(true);
setTimeout(() => setCopyOverlayClicked(false), 1000);
onSubmit(value);
}
};

@@ -90,7 +98,7 @@ const handleOnSubmit = e => {

React.createElement(Select, { id: "fn-export-format-select", label: "Export format", value: outputFormat.name, onChange: handleOutputFormatChanged }, Object.values(format).map(f => (React.createElement("option", { key: f.name, value: f.name }, f.displayName)))),
outputFormat.description && React.createElement(Text, { dangerouslySetInnerHTML: { __html: outputFormat.description } }),
outputFormat.description && React.createElement(Description, { dangerouslySetInnerHTML: { __html: outputFormat.description } }),
React.createElement(CopyTextarea, { value: value, readOnly: true }),
React.createElement(CopyOverlay, { isActive: copyOverlayClicked, onClick: handleCopyOverlayClicked, onAnimationEnd: () => setCopyOverlayClicked(false) },
React.createElement(CopyOverlay, { isActive: copyOverlayIsActive, onClick: handleCopyOverlayClicked, onAnimationEnd: () => setCopyOverlayIsActive(false) },
React.createElement(Export, { iconColor: WHITE, height: 48, width: 48 }),
React.createElement(CopyOverlayLabel, null, "Copy to clipboard")),
React.createElement(CopyOverlayLabel, null, copyOverlayClicked ? 'Copied!' : 'Copy to clipboard')),
React.createElement(ButtonGroup, null,

@@ -97,0 +105,0 @@ React.createElement(Button, null, copyButtonClicked ? 'Copied!' : 'Copy code'),

@@ -12,2 +12,3 @@ import { ActionsUnion, Coordinate } from '../types';

export declare const CHANGE_POLYGON = "POLYGON_DRAW/CHANGE_POLYGON";
export declare const SET_POLYGON = "POLYGON_DRAW/SET_POLYGON";
export declare const actions: {

@@ -27,3 +28,4 @@ selectPoints: (indices: number[]) => import("../types").ActionWithPayload<"POLYGON_DRAW/SELECT_POINTS", number[]>;

changePolygon: (polygon: Coordinate[][]) => import("../types").ActionWithPayload<"POLYGON_DRAW/CHANGE_POLYGON", Coordinate[][]>;
setPolygon: (polygon: Coordinate[]) => import("../types").ActionWithPayload<"POLYGON_DRAW/SET_POLYGON", Coordinate[]>;
};
export declare type Actions = ActionsUnion<typeof actions>;

@@ -17,2 +17,3 @@ import { createAction } from '../actionUtils';

export const CHANGE_POLYGON = 'POLYGON_DRAW/CHANGE_POLYGON';
export const SET_POLYGON = 'POLYGON_DRAW/SET_POLYGON';
export const actions = {

@@ -33,4 +34,5 @@ // Selections action creators

// Change Polygon
changePolygon: (polygon) => createAction(CHANGE_POLYGON, polygon)
changePolygon: (polygon) => createAction(CHANGE_POLYGON, polygon),
setPolygon: (polygon) => createAction(SET_POLYGON, polygon)
};
//# sourceMappingURL=actions.js.map

@@ -34,2 +34,3 @@ import React from 'react';

selectAllPoints: () => void;
setPolygon: (polygon: Coordinate[]) => void;
}

@@ -49,2 +50,3 @@ export interface State {

showExportPolygonModal: boolean;
showImportPolygonModal: boolean;
}

@@ -67,2 +69,5 @@ export declare class BaseMap extends React.Component<Props, State> {

handleExportPolygonModalClosed: () => void;
handleImportPolygon: (coordinates: Coordinate[]) => void;
handleImportPolygonActionClicked: () => void;
handleImportPolygonModalClosed: () => void;
handleMapClick: (event: LeafletMouseEvent) => void;

@@ -69,0 +74,0 @@ handleMouseDownOnMap: (event: LeafletMouseEvent) => void;

@@ -9,2 +9,3 @@ import React, { memo } from 'react';

import { ExportPolygonForm } from '../conversion/ExportPolygonForm';
import { ImportPolygonForm } from '../conversion/ImportPolygonForm';
import { TileLayer } from '../leaflet/TileLayer';

@@ -30,3 +31,4 @@ import { MAP } from '../constants';

newPointPosition: null,
showExportPolygonModal: false
showExportPolygonModal: false,
showImportPolygonModal: false
};

@@ -73,3 +75,3 @@ this.reframe = () => {

///////////////////////////////////////////////////////////////////////////
// Export methods //
// Export / Import methods //
///////////////////////////////////////////////////////////////////////////

@@ -85,2 +87,11 @@ this.handleExportPolygon = (serialized) => {

};
this.handleImportPolygon = (coordinates) => {
this.props.setPolygon(coordinates);
};
this.handleImportPolygonActionClicked = () => {
this.setState({ showImportPolygonModal: true });
};
this.handleImportPolygonModalClosed = () => {
this.setState({ showImportPolygonModal: false });
};
///////////////////////////////////////////////////////////////////////////

@@ -360,5 +371,7 @@ // Map Events methods //

React.createElement(TileLayer, null)),
React.createElement(ActionBar, { editable: editable, isVectorModeEnabled: isPenToolActive, onDelete: this.props.deletePolygonPoints, onFocus: this.handleOnFocusClicked, onEnableVectorMode: this.toggleVectorMode, deleteInactive: selection.size === 0, onExport: this.handleExportPolygonActionClicked }),
React.createElement(ActionBar, { editable: editable, isVectorModeEnabled: isPenToolActive, onDelete: this.props.deletePolygonPoints, onFocus: this.handleOnFocusClicked, onEnableVectorMode: this.toggleVectorMode, deleteInactive: selection.size === 0, onExport: this.handleExportPolygonActionClicked, onImport: this.handleImportPolygonActionClicked }),
this.state.showExportPolygonModal && (React.createElement(Modal, { onClose: this.handleExportPolygonModalClosed },
React.createElement(ExportPolygonForm, { polygon: this.props.polygonCoordinates[this.props.activePolygonIndex], onSubmit: this.handleExportPolygon })))));
React.createElement(ExportPolygonForm, { polygon: this.props.polygonCoordinates[this.props.activePolygonIndex], onSubmit: this.handleExportPolygon }))),
this.state.showImportPolygonModal && (React.createElement(Modal, { onClose: this.handleImportPolygonModalClosed },
React.createElement(ImportPolygonForm, { onSubmit: this.handleImportPolygon })))));
}

@@ -365,0 +378,0 @@ }

@@ -7,5 +7,5 @@ import React from 'react';

export function PolygonDraw({ polygon, activeIndex = 0, highlightedIndex, boundary, initialCenter, initialZoom, editable = true, onChange, onClick, onMouseEnter, onMouseLeave }) {
const { polygons, selection, addPoint, addPointToEdge, deselectAllPoints, removePointFromSelection, addPointsToSelection, selectPoints, moveSelectedPoints, deletePolygonPoints, selectAllPoints, isPolygonClosed } = usePolygonEditor(onChange, polygon, activeIndex);
return (React.createElement(Map, { selection: selection, editable: editable, initialCenter: initialCenter ? createLeafletLatLngTupleFromCoordinate(initialCenter) : MAP.DEFAULT_CENTER, initialZoom: initialZoom || MAP.DEFAULT_ZOOM, boundaryPolygonCoordinates: boundary || MAP.WORLD_COORDINATES, activePolygonIndex: activeIndex, highlightedPolygonIndex: highlightedIndex, polygonCoordinates: polygons, addPoint: addPoint, addPointToEdge: addPointToEdge, deselectAllPoints: deselectAllPoints, removePointFromSelection: removePointFromSelection, addPointsToSelection: addPointsToSelection, selectPoints: selectPoints, moveSelectedPoints: moveSelectedPoints, deletePolygonPoints: deletePolygonPoints, selectAllPoints: selectAllPoints, isPolygonClosed: isPolygonClosed, onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }));
const { polygons, selection, addPoint, addPointToEdge, setPolygon, deselectAllPoints, removePointFromSelection, addPointsToSelection, selectPoints, moveSelectedPoints, deletePolygonPoints, selectAllPoints, isPolygonClosed } = usePolygonEditor(onChange, polygon, activeIndex);
return (React.createElement(Map, { selection: selection, editable: editable, initialCenter: initialCenter ? createLeafletLatLngTupleFromCoordinate(initialCenter) : MAP.DEFAULT_CENTER, initialZoom: initialZoom || MAP.DEFAULT_ZOOM, boundaryPolygonCoordinates: boundary || MAP.WORLD_COORDINATES, activePolygonIndex: activeIndex, highlightedPolygonIndex: highlightedIndex, polygonCoordinates: polygons, setPolygon: setPolygon, addPoint: addPoint, addPointToEdge: addPointToEdge, deselectAllPoints: deselectAllPoints, removePointFromSelection: removePointFromSelection, addPointsToSelection: addPointsToSelection, selectPoints: selectPoints, moveSelectedPoints: moveSelectedPoints, deletePolygonPoints: deletePolygonPoints, selectAllPoints: selectAllPoints, isPolygonClosed: isPolygonClosed, onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }));
}
//# sourceMappingURL=PolygonDraw.js.map

@@ -10,2 +10,2 @@ import { Coordinate } from 'types';

index: number;
}> | import("../types").Action<"POLYGON_DRAW/DELETE_POLYGON_POINTS"> | import("../types").ActionWithPayload<"POLYGON_DRAW/CHANGE_POLYGON", Coordinate[][]>) => PolygonEditState;
}> | import("../types").Action<"POLYGON_DRAW/DELETE_POLYGON_POINTS"> | import("../types").ActionWithPayload<"POLYGON_DRAW/CHANGE_POLYGON", Coordinate[][]> | import("../types").ActionWithPayload<"POLYGON_DRAW/SET_POLYGON", Coordinate[]>) => PolygonEditState;

@@ -1,2 +0,2 @@

import { SELECT_POINTS, ADD_POINT_TO_SELECTION, REMOVE_POINT_FROM_SELECTION, DESELECT_ALL_POINTS, SELECT_ALL_POINTS, MOVE_SELECTED_POINTS, DELETE_POLYGON_POINTS, ADD_POINT, ADD_POINT_TO_EDGE, CHANGE_POLYGON } from './actions';
import { SELECT_POINTS, ADD_POINT_TO_SELECTION, REMOVE_POINT_FROM_SELECTION, DESELECT_ALL_POINTS, SELECT_ALL_POINTS, MOVE_SELECTED_POINTS, DELETE_POLYGON_POINTS, ADD_POINT, ADD_POINT_TO_EDGE, CHANGE_POLYGON, SET_POLYGON } from './actions';
import { movePolygonCoordinates, removeSelectedPoints } from '../helpers';

@@ -11,2 +11,7 @@ export const polygonEditReducer = (state, action) => {

}
case SET_POLYGON: {
const newPolygons = state.polygons.slice();
newPolygons[state.activeIndex] = action.payload;
return Object.assign(Object.assign({}, state), { polygons: newPolygons });
}
///////////////////////////////////////////////////////////////////////////////////

@@ -13,0 +18,0 @@ /// MOVE COORDINATES CASES ///

@@ -15,2 +15,3 @@ import { Coordinate } from 'types';

selectAllPoints: () => void;
setPolygon: (polygon: Coordinate[]) => void;
};

@@ -25,2 +25,5 @@ import { useMemo, useState } from 'react';

polygonEditReducer(state, actions.changePolygon(polygonList));
const setPolygon = (polygon) => {
dispatch(actions.setPolygon(polygon));
};
const addPoint = (coordinate) => {

@@ -65,5 +68,6 @@ dispatch(actions.addPoint(coordinate));

deletePolygonPoints,
selectAllPoints
selectAllPoints,
setPolygon
};
};
//# sourceMappingURL=usePolygonEditor.js.map
{
"name": "@freenow/react-polygon-editor",
"version": "1.1.0-rc.1",
"version": "1.1.0-rc.2",
"description": "A react component for displaying and drawing geo polygons",

@@ -8,2 +8,3 @@ "main": "dist/index.js",

"test": "jest",
"test:watch": "jest --watch",
"start": "start-storybook -p 9001 -c .storybook",

@@ -42,2 +43,4 @@ "lint": "tslint ./src/**/*.{ts,tsx}",

"dependencies": {
"@mapbox/geojson-rewind": "^0.4.0",
"@mapbox/geojsonhint": "^3.0.0",
"clipboard-polyfill": "^2.8.6",

@@ -51,3 +54,2 @@ "leaflet-path-drag": "^1.1.0",

"@dump247/storybook-state": "^1.6.1",
"@mapbox/geojsonhint": "^3.0.0",
"@storybook/addon-actions": "^5.2.4",

@@ -54,0 +56,0 @@ "@storybook/addon-storysource": "^5.2.4",

@@ -1,2 +0,2 @@

import { ACTION_BLUE_900, FREEDOM_RED_900, AUTHENTIC_BLUE_550, WHITE, AUTHENTIC_BLUE_350, } from './common/colors';
import { ACTION_BLUE_900, FREEDOM_RED_900, AUTHENTIC_BLUE_550, WHITE, AUTHENTIC_BLUE_350 } from './common/colors';
import { LatLngTuple } from 'leaflet';

@@ -8,3 +8,4 @@

FOCUS: 'Focus',
EXPORT: 'Export'
EXPORT: 'Export',
IMPORT: 'Import'
};

@@ -11,0 +12,0 @@

@@ -23,2 +23,3 @@ import { createAction } from '../actionUtils';

export const CHANGE_POLYGON = 'POLYGON_DRAW/CHANGE_POLYGON';
export const SET_POLYGON = 'POLYGON_DRAW/SET_POLYGON';

@@ -44,5 +45,6 @@ export const actions = {

// Change Polygon
changePolygon: (polygon: Coordinate[][]) => createAction(CHANGE_POLYGON, polygon)
changePolygon: (polygon: Coordinate[][]) => createAction(CHANGE_POLYGON, polygon),
setPolygon: (polygon: Coordinate[]) => createAction(SET_POLYGON, polygon)
};
export type Actions = ActionsUnion<typeof actions>;

@@ -12,3 +12,4 @@ import {

ADD_POINT_TO_EDGE,
CHANGE_POLYGON
CHANGE_POLYGON,
SET_POLYGON
} from './actions';

@@ -36,2 +37,10 @@ import { Coordinate } from 'types';

}
case SET_POLYGON: {
const newPolygons = state.polygons.slice();
newPolygons[state.activeIndex] = action.payload;
return {
...state,
polygons: newPolygons
};
}

@@ -38,0 +47,0 @@ ///////////////////////////////////////////////////////////////////////////////////

@@ -38,2 +38,6 @@ import { useMemo, useState } from 'react';

const setPolygon = (polygon: Coordinate[]) => {
dispatch(actions.setPolygon(polygon));
};
const addPoint = (coordinate: Coordinate) => {

@@ -87,4 +91,5 @@ dispatch(actions.addPoint(coordinate));

deletePolygonPoints,
selectAllPoints
selectAllPoints,
setPolygon
};
};
declare module '@mapbox/geojsonhint' {
type Hint = {
line: number;
message: string;
};
export function hint(
value: string,
// tslint:disable-next-line:no-any
value: any,
options: {

@@ -8,6 +14,3 @@ noDuplicateMembers?: boolean;

}
): {
line: number;
message: string;
}[];
): Hint[];
}

@@ -25,3 +25,2 @@ {

"max-line-length": [true, { "limit": 160, "ignore-pattern": "^\\s*d=|^\\s*points=" }],
"member-ordering": [true, ["static-before-instance", "variables-before-functions"]],
"member-access": [true, "no-public"],

@@ -28,0 +27,0 @@ "no-any": true,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet