diff --git a/src/components/InputSpec.tsx b/src/components/InputSpec.tsx index f79bb4da..0100f1e8 100644 --- a/src/components/InputSpec.tsx +++ b/src/components/InputSpec.tsx @@ -14,8 +14,8 @@ import capitalize from 'lodash.capitalize' const iconProperties = ['background-pattern', 'fill-pattern', 'line-pattern', 'fill-extrusion-pattern', 'icon-image'] export type SpecFieldProps = { - onChange(...args: unknown[]): unknown - fieldName: string + onChange?(...args: unknown[]): unknown + fieldName?: string fieldSpec: { default?: unknown type: 'number' | 'enum' | 'resolvedImage' | 'formatted' | 'string' | 'color' | 'boolean' | 'array' @@ -49,7 +49,7 @@ export default class SpecField extends React.Component { value: this.props.value, default: this.props.fieldSpec.default, name: this.props.fieldName, - onChange: (newValue: string) => this.props.onChange(this.props.fieldName, newValue), + onChange: (newValue: string) => this.props.onChange!(this.props.fieldName, newValue), 'aria-label': this.props['aria-label'], } switch(this.props.fieldSpec.type) { @@ -70,7 +70,7 @@ export default class SpecField extends React.Component { case 'resolvedImage': case 'formatted': case 'string': - if (iconProperties.indexOf(this.props.fieldName) >= 0) { + if (iconProperties.indexOf(this.props.fieldName!) >= 0) { const options = this.props.fieldSpec.values || []; return } diff --git a/src/components/SpecField.tsx b/src/components/SpecField.tsx index c399cb83..650c70c8 100644 --- a/src/components/SpecField.tsx +++ b/src/components/SpecField.tsx @@ -21,15 +21,13 @@ type SpecFieldProps = InputFieldSpecProps & { export default class SpecField extends React.Component { render() { - const {props} = this; - - const fieldType = props.fieldSpec.type; + const fieldType = this.props.fieldSpec.type; const typeBlockFn = typeMap[fieldType]; let TypeBlock; if (typeBlockFn) { - TypeBlock = typeBlockFn(props); + TypeBlock = typeBlockFn(this.props); } else { console.warn("No such type for '%s'", fieldType); @@ -37,11 +35,11 @@ export default class SpecField extends React.Component { } return - + } } diff --git a/src/components/_DeleteStopButton.jsx b/src/components/_DeleteStopButton.tsx similarity index 66% rename from src/components/_DeleteStopButton.jsx rename to src/components/_DeleteStopButton.tsx index d387cb34..8b0f902f 100644 --- a/src/components/_DeleteStopButton.jsx +++ b/src/components/_DeleteStopButton.tsx @@ -1,15 +1,15 @@ import React from 'react' -import PropTypes from 'prop-types' import InputButton from './InputButton' import {MdDelete} from 'react-icons/md' -export default class DeleteStopButton extends React.Component { - static propTypes = { - onClick: PropTypes.func, - } +type DeleteStopButtonProps = { + onClick?(...args: unknown[]): unknown +}; + +export default class DeleteStopButton extends React.Component { render() { return { render() { const fieldSpec = { doc: "Comments for the current layer. This is non-standard and not in the spec." diff --git a/src/components/_FieldFont.jsx b/src/components/_FieldFont.tsx similarity index 73% rename from src/components/_FieldFont.jsx rename to src/components/_FieldFont.tsx index cd6ca154..23043294 100644 --- a/src/components/_FieldFont.jsx +++ b/src/components/_FieldFont.tsx @@ -1,17 +1,17 @@ import React from 'react' import Block from './Block' -import PropTypes from 'prop-types' import FieldAutocomplete from './FieldAutocomplete' -export default class FieldFont extends React.Component { - static propTypes = { - value: PropTypes.array, - default: PropTypes.array, - fonts: PropTypes.array, - style: PropTypes.object, - onChange: PropTypes.func.isRequired, - } +type FieldFontProps = { + value?: string[] + default?: string[] + fonts?: unknown[] + style?: object + onChange(...args: unknown[]): unknown + label?: string +}; +export default class FieldFont extends React.Component { static defaultProps = { fonts: [] } @@ -28,7 +28,7 @@ export default class FieldFont extends React.Component { } } - changeFont(idx, newValue) { + changeFont(idx: number, newValue: string) { const changedValues = this.values.slice(0) changedValues[idx] = newValue const filteredValues = changedValues @@ -45,7 +45,7 @@ export default class FieldFont extends React.Component { > [f, f])} + options={this.props.fonts!.map(f => [f, f])} onChange={this.changeFont.bind(this, i)} /> diff --git a/src/components/_FieldId.jsx b/src/components/_FieldId.tsx similarity index 61% rename from src/components/_FieldId.jsx rename to src/components/_FieldId.tsx index b12e5eb5..59e8d7e5 100644 --- a/src/components/_FieldId.jsx +++ b/src/components/_FieldId.tsx @@ -1,18 +1,17 @@ import React from 'react' -import PropTypes from 'prop-types' import {latest} from '@maplibre/maplibre-gl-style-spec' import Block from './Block' import FieldString from './FieldString' -export default class BlockId extends React.Component { - static propTypes = { - value: PropTypes.string.isRequired, - wdKey: PropTypes.string.isRequired, - onChange: PropTypes.func.isRequired, - error: PropTypes.object, - } +type BlockIdProps = { + value: string + wdKey: string + onChange(...args: unknown[]): unknown + error?: unknown[] +}; +export default class BlockId extends React.Component { render() { return { render() { return { render() { return { static defaultProps = { onChange: () => {}, sourceIds: [], @@ -28,8 +27,8 @@ export default class BlockSource extends React.Component { > [src, src])} + onChange={this.props.onChange!} + options={this.props.sourceIds!.map(src => [src, src])} /> } diff --git a/src/components/_FieldSourceLayer.jsx b/src/components/_FieldSourceLayer.tsx similarity index 60% rename from src/components/_FieldSourceLayer.jsx rename to src/components/_FieldSourceLayer.tsx index 83e39c6c..06e2f83c 100644 --- a/src/components/_FieldSourceLayer.jsx +++ b/src/components/_FieldSourceLayer.tsx @@ -1,18 +1,17 @@ import React from 'react' -import PropTypes from 'prop-types' import {latest} from '@maplibre/maplibre-gl-style-spec' import Block from './Block' import FieldAutocomplete from './FieldAutocomplete' -export default class BlockSourceLayer extends React.Component { - static propTypes = { - value: PropTypes.string, - onChange: PropTypes.func, - sourceLayerIds: PropTypes.array, - isFixed: PropTypes.bool, - } +type BlockSourceLayerProps = { + value?: string + onChange?(...args: unknown[]): unknown + sourceLayerIds?: unknown[] + isFixed?: boolean +}; +export default class BlockSourceLayer extends React.Component { static defaultProps = { onChange: () => {}, sourceLayerIds: [], @@ -26,8 +25,8 @@ export default class BlockSourceLayer extends React.Component { [l, l])} + onChange={this.props.onChange!} + options={this.props.sourceLayerIds!.map(l => [l, l])} /> } diff --git a/src/components/_FieldSymbol.jsx b/src/components/_FieldSymbol.jsx deleted file mode 100644 index ab546bdd..00000000 --- a/src/components/_FieldSymbol.jsx +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import FieldAutocomplete from './FieldAutocomplete' - - -export default class FieldSymbol extends React.Component { - static propTypes = { - value: PropTypes.string, - icons: PropTypes.array, - style: PropTypes.object, - onChange: PropTypes.func.isRequired, - } - - static defaultProps = { - icons: [] - } - - render() { - return [f, f])} - onChange={this.props.onChange} - wrapperStyle={this.props.style} - /> - } -} - diff --git a/src/components/_FieldSymbol.tsx b/src/components/_FieldSymbol.tsx new file mode 100644 index 00000000..261354e4 --- /dev/null +++ b/src/components/_FieldSymbol.tsx @@ -0,0 +1,25 @@ +import React from 'react' +import FieldAutocomplete from './FieldAutocomplete' + + +type FieldSymbolProps = { + value?: string + icons?: unknown[] + onChange(...args: unknown[]): unknown +}; + + +export default class FieldSymbol extends React.Component { + static defaultProps = { + icons: [] + } + + render() { + return [f, f])} + onChange={this.props.onChange} + /> + } +} + diff --git a/src/components/_FieldType.jsx b/src/components/_FieldType.tsx similarity index 78% rename from src/components/_FieldType.jsx rename to src/components/_FieldType.tsx index 0987ff42..8dc53009 100644 --- a/src/components/_FieldType.jsx +++ b/src/components/_FieldType.tsx @@ -1,20 +1,19 @@ import React from 'react' -import PropTypes from 'prop-types' import {latest} from '@maplibre/maplibre-gl-style-spec' import Block from './Block' import FieldSelect from './FieldSelect' import FieldString from './FieldString' -export default class BlockType extends React.Component { - static propTypes = { - value: PropTypes.string.isRequired, - wdKey: PropTypes.string, - onChange: PropTypes.func.isRequired, - error: PropTypes.object, - disabled: PropTypes.bool, - } +type BlockTypeProps = { + value: string + wdKey?: string + onChange(...args: unknown[]): unknown + error?: unknown[] + disabled?: boolean +}; +export default class BlockType extends React.Component { static defaultProps = { disabled: false, } diff --git a/src/components/_FunctionButtons.jsx b/src/components/_FunctionButtons.tsx similarity index 71% rename from src/components/_FunctionButtons.jsx rename to src/components/_FunctionButtons.tsx index bacd3444..214474bc 100644 --- a/src/components/_FunctionButtons.jsx +++ b/src/components/_FunctionButtons.tsx @@ -1,37 +1,17 @@ import React from 'react' -import PropTypes from 'prop-types' import InputButton from './InputButton' import {MdFunctions, MdInsertChart} from 'react-icons/md' import {mdiFunctionVariant} from '@mdi/js'; +type FunctionInputButtonsProps = { + fieldSpec?: any + onZoomClick?(...args: unknown[]): unknown + onDataClick?(...args: unknown[]): unknown + onExpressionClick?(...args: unknown[]): unknown +}; -/** - * So here we can't just check is `Array.isArray(value)` because certain - * properties accept arrays as values, for example `text-font`. So we must try - * and create an expression. - */ -function isExpression(value, fieldSpec={}) { - if (!Array.isArray(value)) { - return false; - } - try { - expression.createExpression(value, fieldSpec); - return true; - } - catch (err) { - return false; - } -} - -export default class FunctionInputButtons extends React.Component { - static propTypes = { - fieldSpec: PropTypes.object, - onZoomClick: PropTypes.func, - onDataClick: PropTypes.func, - onExpressionClick: PropTypes.func, - } - +export default class FunctionInputButtons extends React.Component { render() { let makeZoomInputButton, makeDataInputButton, expressionInputButton; diff --git a/src/components/_SpecProperty.jsx b/src/components/_SpecProperty.tsx similarity index 53% rename from src/components/_SpecProperty.jsx rename to src/components/_SpecProperty.tsx index e4df5189..f27b4d90 100644 --- a/src/components/_SpecProperty.jsx +++ b/src/components/_SpecProperty.tsx @@ -1,25 +1,24 @@ import React from 'react' -import PropTypes from 'prop-types' import SpecField from './SpecField' import FunctionButtons from './_FunctionButtons' -import Block from './Block' import labelFromFieldName from './_labelFromFieldName' -export default class SpecProperty extends React.Component { - static propTypes = { - onZoomClick: PropTypes.func.isRequired, - onDataClick: PropTypes.func.isRequired, - fieldName: PropTypes.string, - fieldType: PropTypes.string, - fieldSpec: PropTypes.object, - value: PropTypes.any, - errors: PropTypes.object, - onExpressionClick: PropTypes.func, - } +type SpecPropertyProps = { + onZoomClick(...args: unknown[]): unknown + onDataClick(...args: unknown[]): unknown + fieldName?: string + fieldType?: string + fieldSpec?: any + value?: any + errors?: unknown[] + onExpressionClick?(...args: unknown[]): unknown +}; + +export default class SpecProperty extends React.Component { static defaultProps = { errors: {}, } @@ -31,17 +30,16 @@ export default class SpecProperty extends React.Component { fieldSpec={this.props.fieldSpec} onZoomClick={this.props.onZoomClick} onDataClick={this.props.onDataClick} - value={this.props.value} onExpressionClick={this.props.onExpressionClick} /> - const error = errors[fieldType+"."+fieldName]; + const error = errors![fieldType+"."+fieldName as any] as any; return } diff --git a/src/components/_labelFromFieldName.js b/src/components/_labelFromFieldName.ts similarity index 79% rename from src/components/_labelFromFieldName.js rename to src/components/_labelFromFieldName.ts index 666d833c..d6e4a064 100644 --- a/src/components/_labelFromFieldName.js +++ b/src/components/_labelFromFieldName.ts @@ -1,6 +1,6 @@ import capitalize from 'lodash.capitalize' -export default function labelFromFieldName(fieldName) { +export default function labelFromFieldName(fieldName: string) { let label; const parts = fieldName.split('-'); if (parts.length > 1) {