diff --git a/package.json b/package.json index 1102cbd..6842352 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "react" ], "homepage": "https://openscript.github.io/react-dsv-import/", - "version": "0.3.1", + "version": "0.3.2", "main": "dist/index.js", "module": "dist/es/index.js", "types": "dist/index.d.ts", @@ -32,8 +32,8 @@ "@types/node": "^14.0.5", "@types/react": "^16.9.35", "@types/react-dom": "^16.9.8", - "@typescript-eslint/eslint-plugin": "^3.0.0", - "@typescript-eslint/parser": "^3.0.0", + "@typescript-eslint/eslint-plugin": "^3.0.1", + "@typescript-eslint/parser": "^3.0.1", "babel-loader": "^8.1.0", "babel-preset-react-app": "^9.1.2", "eslint": "^7.1.0", diff --git a/src/DSVImport.tsx b/src/DSVImport.tsx index 9ac3a40..26f2057 100644 --- a/src/DSVImport.tsx +++ b/src/DSVImport.tsx @@ -1,5 +1,5 @@ import React, { PropsWithChildren, useReducer, useEffect } from 'react'; -import { ColumnType } from './models/column'; +import { ColumnType, GenericColumnType } from './models/column'; import { getDSVImportContext, useDSVImport, createReducer } from './features/context'; import { createParserMiddleware } from './middlewares/parserMiddleware'; import { State } from './models/state'; @@ -14,7 +14,7 @@ interface EventListenerProps { onValidation?: (errors: ValidationError[]) => void; } -const EventListener = (props: EventListenerProps) => { +const EventListener = (props: EventListenerProps) => { const [context] = useDSVImport(); useEffect(() => { @@ -39,7 +39,7 @@ export interface Props { transformers?: Transformer[]; } -export const DSVImport = (props: PropsWithChildren>) => { +export const DSVImport = (props: PropsWithChildren>) => { const DSVImportContext = getDSVImportContext(); const initialValues: State = { columns: props.columns, transformers: props.transformers }; const [state, dispatch] = useReducer(createReducer(), initialValues); diff --git a/src/features/context.ts b/src/features/context.ts index cd15657..0796ba2 100644 --- a/src/features/context.ts +++ b/src/features/context.ts @@ -1,6 +1,7 @@ import { State, emptyState } from '../models/state'; import { createContext, Dispatch, useContext } from 'react'; import { Actions } from '../models/actions'; +import { GenericColumnType } from '../models/column'; export const reducer = (state: State, action: Actions) => { switch (action.type) { @@ -34,4 +35,4 @@ export const getDSVImportContext = () => { } return contextSingleton as React.Context<[State, Dispatch>]>; }; -export const useDSVImport = () => useContext(getDSVImportContext()); +export const useDSVImport = () => useContext(getDSVImportContext()); diff --git a/src/index.tsx b/src/index.tsx index 323de30..c69bf40 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,16 +1,18 @@ +import { PropsWithChildren } from 'react'; +import { DSVImport as Import, Props } from './DSVImport'; +import { GenericColumnType } from './models/column'; import { TextareaInput } from './components/inputs/TextareaInput'; import { TablePreview } from './components/previews/TablePreview'; -import { DSVImport as Import, Props } from './DSVImport'; -import { PropsWithChildren } from 'react'; -export function DSVImport(props: PropsWithChildren>) { +export function DSVImport(props: PropsWithChildren>) { return Import(props); } DSVImport.TextareaInput = TextareaInput; DSVImport.TablePreview = TablePreview; -export { ColumnType } from './models/column'; +export { ColumnType, GenericColumnType } from './models/column'; export { useDSVImport } from './features/context'; export { Rule } from './models/rule'; export { Transformer } from './models/transformer'; +export { ValidationError } from './models/validation'; diff --git a/src/models/column.ts b/src/models/column.ts index c456470..fa31e26 100644 --- a/src/models/column.ts +++ b/src/models/column.ts @@ -1,4 +1,5 @@ import { Rule } from './rule'; import { Transformer } from './transformer'; +export type GenericColumnType = { [key: string]: string }; export type ColumnType = { key: keyof T; label: string; rules?: Rule[]; transformers?: Transformer[] }; diff --git a/src/models/state.ts b/src/models/state.ts index 364634f..bb9b8bd 100644 --- a/src/models/state.ts +++ b/src/models/state.ts @@ -1,4 +1,4 @@ -import { ColumnType } from './column'; +import { ColumnType, GenericColumnType } from './column'; import { ValidationError } from './validation'; import { Transformer } from './transformer'; @@ -10,6 +10,6 @@ export interface State { columns: ColumnType[]; } -export const emptyState: State<{ [key: string]: string }> = { +export const emptyState: State = { columns: [] }; diff --git a/yarn.lock b/yarn.lock index 6e622f6..e06eb5f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2135,9 +2135,9 @@ loader-utils "^1.2.3" "@testing-library/dom@^7.2.2": - version "7.5.7" - resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.5.7.tgz#c4bf683a65083d4a78644588cfa4ad684c113fc7" - integrity sha512-835MiwAxQE7xjSrhpeJbv41UQRmsPJQ0tGfzWiJMdZj2LBbdG5cT8Z44Viv11/XucCmJHr/v8q7VpZnuSimscg== + version "7.5.8" + resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.5.8.tgz#35eb20f1cfd90629a09728954fd916ea142e5de5" + integrity sha512-aEK4GDeIk3sHuuF8NNvZrmZg5xfF7llvdlVfjely/fPg/GE4yLa0cVZEBWpS6oVUBk2tEXjwTDPFnMOe/M0GTQ== dependencies: "@babel/runtime" "^7.9.6" aria-query "^4.0.2" @@ -2485,41 +2485,41 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@^3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.0.0.tgz#02f8ec6b5ce814bda80dfc22463f108bed1f699b" - integrity sha512-lcZ0M6jD4cqGccYOERKdMtg+VWpoq3NSnWVxpc/AwAy0zhkUYVioOUZmfNqiNH8/eBNGhCn6HXd6mKIGRgNc1Q== +"@typescript-eslint/eslint-plugin@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.0.1.tgz#368fe7d4c3d927e9fd27b7ba150b4b7e83ddfabe" + integrity sha512-RxGldRQD3hgOK2xtBfNfA5MMV3rn5gVChe+MIf14hKm51jO2urqF64xOyVrGtzThkrd4rS1Kihqx2nkSxkXHvA== dependencies: - "@typescript-eslint/experimental-utils" "3.0.0" + "@typescript-eslint/experimental-utils" "3.0.1" functional-red-black-tree "^1.0.1" regexpp "^3.0.0" semver "^7.3.2" tsutils "^3.17.1" -"@typescript-eslint/experimental-utils@3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.0.0.tgz#1ddf53eeb61ac8eaa9a77072722790ac4f641c03" - integrity sha512-BN0vmr9N79M9s2ctITtChRuP1+Dls0x/wlg0RXW1yQ7WJKPurg6X3Xirv61J2sjPif4F8SLsFMs5Nzte0WYoTQ== +"@typescript-eslint/experimental-utils@3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.0.1.tgz#e2721c970068fabd6621709234809c98cd3343ad" + integrity sha512-GdwOVz80MOWxbc/br1DC30eeqlxfpVzexHgHtf3L0hcbOu1xAs1wSCNcaBTLMOMZbh1gj/cKZt0eB207FxWfFA== dependencies: "@types/json-schema" "^7.0.3" - "@typescript-eslint/typescript-estree" "3.0.0" + "@typescript-eslint/typescript-estree" "3.0.1" eslint-scope "^5.0.0" eslint-utils "^2.0.0" -"@typescript-eslint/parser@^3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.0.0.tgz#fe9fdf18a1155c02c04220c14506a320cb6c6944" - integrity sha512-8RRCA9KLxoFNO0mQlrLZA0reGPd/MsobxZS/yPFj+0/XgMdS8+mO8mF3BDj2ZYQj03rkayhSJtF1HAohQ3iylw== +"@typescript-eslint/parser@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.0.1.tgz#f5163e3a789422f5c62f4daf822bfa03b7e4472d" + integrity sha512-Pn2tDmOc4Ri93VQnT70W0pqQr6i/pEZqIPXfWXm4RuiIprL0t6SG13ViVXHgfScknL2Fm2G4IqXhUzxSRCWXCw== dependencies: "@types/eslint-visitor-keys" "^1.0.0" - "@typescript-eslint/experimental-utils" "3.0.0" - "@typescript-eslint/typescript-estree" "3.0.0" + "@typescript-eslint/experimental-utils" "3.0.1" + "@typescript-eslint/typescript-estree" "3.0.1" eslint-visitor-keys "^1.1.0" -"@typescript-eslint/typescript-estree@3.0.0": - version "3.0.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.0.0.tgz#fa40e1b76ccff880130be054d9c398e96004bf42" - integrity sha512-nevQvHyNghsfLrrByzVIH4ZG3NROgJ8LZlfh3ddwPPH4CH7W4GAiSx5qu+xHuX5pWsq6q/eqMc1io840ZhAnUg== +"@typescript-eslint/typescript-estree@3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.0.1.tgz#8c0cfb7cda64bd6f54185a7b7d1923d25d36b2a8" + integrity sha512-FrbMdgVCeIGHKaP9OYTttFTlF8Ds7AkjMca2GzYCE7pVch10PAJc1mmAFt+DfQPgu/2TrLAprg2vI0PK/WTdcg== dependencies: debug "^4.1.1" eslint-visitor-keys "^1.1.0" @@ -3933,9 +3933,9 @@ can-use-dom@^0.1.0: integrity sha1-IsxKNKCrxDlQ9CxkEQJKP2NmtFo= caniuse-lite@^1.0.30000989, caniuse-lite@^1.0.30001043, caniuse-lite@^1.0.30001061: - version "1.0.30001065" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001065.tgz#e8d7fef61cdfd8a7107493ad6bf551a4eb59c68f" - integrity sha512-DDxCLgJ266YnAHQv0jS1wdOaihRFF52Zgmlag39sQJVy2H46oROpJp4hITstqhdB8qnHSrKNoAEkQA9L/oYF9A== + version "1.0.30001066" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001066.tgz#0a8a58a10108f2b9bf38e7b65c237b12fd9c5f04" + integrity sha512-Gfj/WAastBtfxLws0RCh2sDbTK/8rJuSeZMecrSkNGYxPcv7EzblmDGfWQCFEQcSqYE2BRgQiJh8HOD07N5hIw== capture-exit@^2.0.0: version "2.0.0" @@ -4502,9 +4502,9 @@ cross-spawn@6.0.5, cross-spawn@^6.0.0: which "^1.2.9" cross-spawn@^7.0.0, cross-spawn@^7.0.2: - version "7.0.2" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6" - integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw== + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" + integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== dependencies: path-key "^3.1.0" shebang-command "^2.0.0" @@ -5022,9 +5022,9 @@ ejs@^2.7.4: integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA== electron-to-chromium@^1.3.247, electron-to-chromium@^1.3.413: - version "1.3.451" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.451.tgz#0c075af3e2f06d706670bde0279432802ca8c83f" - integrity sha512-2fvco0F2bBIgqzO8GRP0Jt/91pdrf9KfZ5FsmkYkjERmIJG585cFeFZV4+CO6oTmU3HmCTgfcZuEa7kW8VUh3A== + version "1.3.452" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.452.tgz#ef6877702722471aa044a2429336cd450629934d" + integrity sha512-IdbjgCEqDvcU/1kUQa6C49I2NZOY3SBmU9Eus7mdFdJJBqn0Lg1Epfi/T4nqVcxTNBEGhcjwMhY1EysMBsXZrw== element-resize-detector@^1.2.1: version "1.2.1" @@ -5812,9 +5812,9 @@ fork-ts-checker-webpack-plugin@1.5.0: worker-rpc "^0.1.0" fork-ts-checker-webpack-plugin@^4.1.0: - version "4.1.4" - resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-4.1.4.tgz#f0dc3ece19ec5b792d7b8ecd2a7f43509a5285ce" - integrity sha512-R0nTlZSyV0uCCzYe1kgR7Ve8mXyDvMm1pJwUFb6zzRVF5rTNb24G6gn2DFQy+W5aJYp2eq8aexpCOO+1SCyCSA== + version "4.1.5" + resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-4.1.5.tgz#780d52c65183742d8c885fff42a9ec9ea7006672" + integrity sha512-nuD4IDqoOfkEIlS6shhjLGaLBDSNyVJulAlr5lFbPe0saGqlsTo+/HmhtIrs/cNLFtmaudL10byivhxr+Qhh4w== dependencies: "@babel/code-frame" "^7.5.5" chalk "^2.4.1" @@ -9216,9 +9216,9 @@ postcss-value-parser@^4.0.0, postcss-value-parser@^4.0.3, postcss-value-parser@^ integrity sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ== postcss@^7.0.0, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.26, postcss@^7.0.27, postcss@^7.0.30, postcss@^7.0.5, postcss@^7.0.6: - version "7.0.30" - resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.30.tgz#cc9378beffe46a02cbc4506a0477d05fcea9a8e2" - integrity sha512-nu/0m+NtIzoubO+xdAlwZl/u5S5vi/y6BCsoL8D+8IxsD3XvBS8X4YEADNIVXKVuQvduiucnRv+vPIqj56EGMQ== + version "7.0.31" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.31.tgz#332af45cb73e26c0ee2614d7c7fb02dfcc2bd6dd" + integrity sha512-a937VDHE1ftkjk+8/7nj/mrjtmkn69xxzJgRETXdAUU+IgOYPQNJF17haGWbeDxSyk++HA14UA98FurvPyBJOA== dependencies: chalk "^2.4.2" source-map "^0.6.1"