mirror of
https://github.com/maputnik/editor.git
synced 2026-08-27 15:37:27 +00:00
More typescript migration
This commit is contained in:
Generated
+10
@@ -78,6 +78,7 @@
|
|||||||
"@types/react-autocomplete": "^1.8.9",
|
"@types/react-autocomplete": "^1.8.9",
|
||||||
"@types/react-color": "^3.0.10",
|
"@types/react-color": "^3.0.10",
|
||||||
"@types/react-dom": "^16.9.24",
|
"@types/react-dom": "^16.9.24",
|
||||||
|
"@types/react-file-reader-input": "^2.0.4",
|
||||||
"@types/react-icon-base": "^2.1.6",
|
"@types/react-icon-base": "^2.1.6",
|
||||||
"@types/uuid": "^9.0.7",
|
"@types/uuid": "^9.0.7",
|
||||||
"@vitejs/plugin-react": "^4.2.0",
|
"@vitejs/plugin-react": "^4.2.0",
|
||||||
@@ -4917,6 +4918,15 @@
|
|||||||
"@types/react": "^16"
|
"@types/react": "^16"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/react-file-reader-input": {
|
||||||
|
"version": "2.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/react-file-reader-input/-/react-file-reader-input-2.0.4.tgz",
|
||||||
|
"integrity": "sha512-Jqrfn+w42j8t8Q3npMXXKPdk+reIM0UHLKVc3ykrA7q7bN3Z62SGhsClZX0+Edlqm66lcKwmDQl+WMm+Xor7Xg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/react": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/react-icon-base": {
|
"node_modules/@types/react-icon-base": {
|
||||||
"version": "2.1.6",
|
"version": "2.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/@types/react-icon-base/-/react-icon-base-2.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react-icon-base/-/react-icon-base-2.1.6.tgz",
|
||||||
|
|||||||
@@ -107,6 +107,7 @@
|
|||||||
"@types/react-autocomplete": "^1.8.9",
|
"@types/react-autocomplete": "^1.8.9",
|
||||||
"@types/react-color": "^3.0.10",
|
"@types/react-color": "^3.0.10",
|
||||||
"@types/react-dom": "^16.9.24",
|
"@types/react-dom": "^16.9.24",
|
||||||
|
"@types/react-file-reader-input": "^2.0.4",
|
||||||
"@types/react-icon-base": "^2.1.6",
|
"@types/react-icon-base": "^2.1.6",
|
||||||
"@types/uuid": "^9.0.7",
|
"@types/uuid": "^9.0.7",
|
||||||
"@vitejs/plugin-react": "^4.2.0",
|
"@vitejs/plugin-react": "^4.2.0",
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ export type FieldUrlProps = {
|
|||||||
multi?: boolean
|
multi?: boolean
|
||||||
required?: boolean
|
required?: boolean
|
||||||
'aria-label'?: string
|
'aria-label'?: string
|
||||||
|
type?: string
|
||||||
|
className?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
type FieldUrlState = {
|
type FieldUrlState = {
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
import InputButton from './InputButton'
|
import InputButton from './InputButton'
|
||||||
import Modal from './Modal'
|
import Modal from './Modal'
|
||||||
|
|
||||||
|
|
||||||
export default class ModalLoading extends React.Component {
|
type ModalLoadingProps = {
|
||||||
static propTypes = {
|
isOpen: boolean
|
||||||
isOpen: PropTypes.bool.isRequired,
|
onCancel(...args: unknown[]): unknown
|
||||||
onCancel: PropTypes.func.isRequired,
|
title: string
|
||||||
title: PropTypes.string.isRequired,
|
message: React.ReactNode
|
||||||
message: PropTypes.node.isRequired,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
underlayOnClick(e) {
|
|
||||||
|
export default class ModalLoading extends React.Component<ModalLoadingProps> {
|
||||||
|
underlayOnClick(e: Event) {
|
||||||
// This stops click events falling through to underlying modals.
|
// This stops click events falling through to underlying modals.
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
@@ -24,9 +24,9 @@ export default class ModalLoading extends React.Component {
|
|||||||
isOpen={this.props.isOpen}
|
isOpen={this.props.isOpen}
|
||||||
underlayClickExits={false}
|
underlayClickExits={false}
|
||||||
underlayProps={{
|
underlayProps={{
|
||||||
onClick: (e) => underlayProps(e)
|
// @ts-ignore
|
||||||
|
onClick: (e: Event) => underlayProps(e)
|
||||||
}}
|
}}
|
||||||
closeable={false}
|
|
||||||
title={this.props.title}
|
title={this.props.title}
|
||||||
onOpenToggle={() => this.props.onCancel()}
|
onOpenToggle={() => this.props.onCancel()}
|
||||||
>
|
>
|
||||||
@@ -1,25 +1,24 @@
|
|||||||
import React from 'react'
|
import React, { FormEvent } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import {MdFileUpload} from 'react-icons/md'
|
||||||
|
import {MdAddCircleOutline} from 'react-icons/md'
|
||||||
|
import FileReaderInput, { Result } from 'react-file-reader-input'
|
||||||
|
|
||||||
import ModalLoading from './ModalLoading'
|
import ModalLoading from './ModalLoading'
|
||||||
import Modal from './Modal'
|
import Modal from './Modal'
|
||||||
import InputButton from './InputButton'
|
import InputButton from './InputButton'
|
||||||
import FileReaderInput from 'react-file-reader-input'
|
|
||||||
import InputUrl from './InputUrl'
|
import InputUrl from './InputUrl'
|
||||||
|
|
||||||
import {MdFileUpload} from 'react-icons/md'
|
|
||||||
import {MdAddCircleOutline} from 'react-icons/md'
|
|
||||||
|
|
||||||
import style from '../libs/style'
|
import style from '../libs/style'
|
||||||
import publicStyles from '../config/styles.json'
|
import publicStyles from '../config/styles.json'
|
||||||
|
|
||||||
class PublicStyle extends React.Component {
|
type PublicStyleProps = {
|
||||||
static propTypes = {
|
url: string
|
||||||
url: PropTypes.string.isRequired,
|
thumbnailUrl: string
|
||||||
thumbnailUrl: PropTypes.string.isRequired,
|
title: string
|
||||||
title: PropTypes.string.isRequired,
|
onSelect(...args: unknown[]): unknown
|
||||||
onSelect: PropTypes.func.isRequired,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
class PublicStyle extends React.Component<PublicStyleProps> {
|
||||||
render() {
|
render() {
|
||||||
return <div className="maputnik-public-style">
|
return <div className="maputnik-public-style">
|
||||||
<InputButton
|
<InputButton
|
||||||
@@ -43,14 +42,21 @@ class PublicStyle extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ModalOpen extends React.Component {
|
type ModalOpenProps = {
|
||||||
static propTypes = {
|
isOpen: boolean
|
||||||
isOpen: PropTypes.bool.isRequired,
|
onOpenToggle(...args: unknown[]): unknown
|
||||||
onOpenToggle: PropTypes.func.isRequired,
|
onStyleOpen(...args: unknown[]): unknown
|
||||||
onStyleOpen: PropTypes.func.isRequired,
|
};
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props) {
|
type ModalOpenState = {
|
||||||
|
styleUrl: string
|
||||||
|
error?: string | null
|
||||||
|
activeRequest?: any
|
||||||
|
activeRequestUrl?: string | null
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class ModalOpen extends React.Component<ModalOpenProps, ModalOpenState> {
|
||||||
|
constructor(props: ModalOpenProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
styleUrl: ""
|
styleUrl: ""
|
||||||
@@ -63,7 +69,7 @@ export default class ModalOpen extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onCancelActiveRequest(e) {
|
onCancelActiveRequest(e: Event) {
|
||||||
// Else the click propagates to the underlying modal
|
// Else the click propagates to the underlying modal
|
||||||
if(e) e.stopPropagation();
|
if(e) e.stopPropagation();
|
||||||
|
|
||||||
@@ -76,12 +82,12 @@ export default class ModalOpen extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onStyleSelect = (styleUrl) => {
|
onStyleSelect = (styleUrl: string) => {
|
||||||
this.clearError();
|
this.clearError();
|
||||||
|
|
||||||
let canceled;
|
let canceled: boolean = false;
|
||||||
|
|
||||||
const activeRequest = fetch(styleUrl, {
|
fetch(styleUrl, {
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
credentials: "same-origin"
|
credentials: "same-origin"
|
||||||
})
|
})
|
||||||
@@ -123,13 +129,13 @@ export default class ModalOpen extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmitUrl = (e) => {
|
onSubmitUrl = (e: FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.onStyleSelect(this.state.styleUrl);
|
this.onStyleSelect(this.state.styleUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpload = (_, files) => {
|
onUpload = (_: any, files: Result[]) => {
|
||||||
const [e, file] = files[0];
|
const [_e, file] = files[0];
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
|
|
||||||
this.clearError();
|
this.clearError();
|
||||||
@@ -138,11 +144,11 @@ export default class ModalOpen extends React.Component {
|
|||||||
reader.onload = e => {
|
reader.onload = e => {
|
||||||
let mapStyle;
|
let mapStyle;
|
||||||
try {
|
try {
|
||||||
mapStyle = JSON.parse(e.target.result)
|
mapStyle = JSON.parse(e.target?.result as string)
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
this.setState({
|
this.setState({
|
||||||
error: err.toString()
|
error: (err as Error).toString()
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -161,7 +167,7 @@ export default class ModalOpen extends React.Component {
|
|||||||
this.props.onOpenToggle();
|
this.props.onOpenToggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeUrl = (url) => {
|
onChangeUrl = (url: string) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
styleUrl: url,
|
styleUrl: url,
|
||||||
});
|
});
|
||||||
@@ -200,7 +206,7 @@ export default class ModalOpen extends React.Component {
|
|||||||
<section className="maputnik-modal-section">
|
<section className="maputnik-modal-section">
|
||||||
<h1>Upload Style</h1>
|
<h1>Upload Style</h1>
|
||||||
<p>Upload a JSON style from your computer.</p>
|
<p>Upload a JSON style from your computer.</p>
|
||||||
<FileReaderInput onChange={this.onUpload} tabIndex="-1" aria-label="Style file">
|
<FileReaderInput onChange={this.onUpload} tabIndex={-1} aria-label="Style file">
|
||||||
<InputButton className="maputnik-upload-button"><MdFileUpload /> Upload</InputButton>
|
<InputButton className="maputnik-upload-button"><MdFileUpload /> Upload</InputButton>
|
||||||
</FileReaderInput>
|
</FileReaderInput>
|
||||||
</section>
|
</section>
|
||||||
@@ -246,7 +252,7 @@ export default class ModalOpen extends React.Component {
|
|||||||
<ModalLoading
|
<ModalLoading
|
||||||
isOpen={!!this.state.activeRequest}
|
isOpen={!!this.state.activeRequest}
|
||||||
title={'Loading style'}
|
title={'Loading style'}
|
||||||
onCancel={(e) => this.onCancelActiveRequest(e)}
|
onCancel={(e: Event) => this.onCancelActiveRequest(e)}
|
||||||
message={"Loading: "+this.state.activeRequestUrl}
|
message={"Loading: "+this.state.activeRequestUrl}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user