From 83f7d4bcf956c449df9e7cdd8e232b3f054522ec Mon Sep 17 00:00:00 2001 From: Erhan Gundogan Date: Wed, 21 Oct 2020 21:49:27 +0200 Subject: [PATCH] update for tsconfig, types and npm config --- package.json | 11 ++-- src/components/KVEditor/KVEditor.tsx | 2 +- src/components/KVEditor/KVEditor.types.ts | 20 +++++++ .../KVEditor/__tests__/KVEditor.test.tsx | 2 +- .../__snapshots__/KVEditor.test.tsx.snap | 3 +- src/components/KVItemEdit/KVItemEdit.tsx | 2 +- src/components/KVItemEdit/KVItemEdit.types.ts | 13 +++++ .../KVItemEdit/__tests__/KVItemEdit.test.tsx | 2 +- .../__snapshots__/KVItemEdit.test.tsx.snap | 3 +- src/components/KVItemView/KVItemView.tsx | 2 +- src/components/KVItemView/KVItemView.types.ts | 13 +++++ .../KVItemView/__tests__/KVItemView.test.tsx | 2 +- .../__snapshots__/KVItemView.test.tsx.snap | 2 +- src/example.tsx | 2 +- src/hooks/KVReducer.ts | 2 +- src/hooks/KVReducer.types.ts | 16 ++++++ src/hooks/__tests__/KVReducer.test.ts | 2 +- tsconfig.json | 3 +- types.d.ts | 55 ------------------- 19 files changed, 83 insertions(+), 74 deletions(-) create mode 100644 src/components/KVEditor/KVEditor.types.ts create mode 100644 src/components/KVItemEdit/KVItemEdit.types.ts create mode 100644 src/components/KVItemView/KVItemView.types.ts create mode 100644 src/hooks/KVReducer.types.ts delete mode 100644 types.d.ts diff --git a/package.json b/package.json index f64a3c7..6c57599 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@imagemarker/kveditor", - "version": "0.3.0", - "description": "React key/value UI component library", + "version": "0.4.0", + "description": "React key/value component library", "repository": "github:imagemarker/kveditor", "keywords": [ "react", @@ -11,7 +11,7 @@ "key-value", "editor" ], - "types": "types.d.ts", + "types": "./dist/index.d.ts", "license": "MIT", "main": "./dist/index.js", "module": "./dist/index.js", @@ -20,8 +20,7 @@ "dist", "package.json", "LICENSE.md", - "README.md", - "types.d.ts" + "README.md" ], "scripts": { "clean": "rimraf dist", @@ -32,7 +31,7 @@ "build:prod": "NODE_ENV=production rollup -c rollup.config.js", "build:example": "yarn clean && NODE_ENV=development rollup -c rollup.examples.config.js", "start": "yarn build:example && serve dist", - "prepublish": "yarn build" + "prepublishOnly": "yarn build" }, "devDependencies": { "@rollup/plugin-html": "^0.2.0", diff --git a/src/components/KVEditor/KVEditor.tsx b/src/components/KVEditor/KVEditor.tsx index f13f97b..a6208c8 100644 --- a/src/components/KVEditor/KVEditor.tsx +++ b/src/components/KVEditor/KVEditor.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useReducer } from 'react'; -import { KVEditConfigType, KVEditorType, KVItemType } from '@base/types'; +import { KVEditConfigType, KVEditorType, KVItemType } from '@base/src/components/KVEditor/KVEditor.types'; import KVReducer from '../../hooks/KVReducer'; import KVItemEdit from '../KVItemEdit/KVItemEdit'; import KVItemView from '../KVItemView/KVItemView'; diff --git a/src/components/KVEditor/KVEditor.types.ts b/src/components/KVEditor/KVEditor.types.ts new file mode 100644 index 0000000..2b6427e --- /dev/null +++ b/src/components/KVEditor/KVEditor.types.ts @@ -0,0 +1,20 @@ +import { ReactElement } from 'react'; + +export interface KVEditConfigType { + typeNotation?: string; + nested?: boolean; + validateKey?: RegExp; + theme?: string; +} +export interface KVEditorPropsType { + items?: KVItemType[]; + options?: KVEditConfigType; + onChange?: (state: any) => void; +} +export interface KVEditorType { + (props: KVEditorPropsType): ReactElement; +} +export interface KVItemType { + key: string; + value: any; +} diff --git a/src/components/KVEditor/__tests__/KVEditor.test.tsx b/src/components/KVEditor/__tests__/KVEditor.test.tsx index 02b9562..f4f4f09 100644 --- a/src/components/KVEditor/__tests__/KVEditor.test.tsx +++ b/src/components/KVEditor/__tests__/KVEditor.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { render } from '@testing-library/react'; +import { KVEditConfigType } from '@base/src/components/KVEditor/KVEditor.types'; import KVReducer from '../../../hooks/KVReducer'; -import { KVEditConfigType } from '@base/types'; import KVEditor from '../KVEditor'; jest.mock('../../../hooks/KVReducer'); diff --git a/src/components/KVEditor/__tests__/__snapshots__/KVEditor.test.tsx.snap b/src/components/KVEditor/__tests__/__snapshots__/KVEditor.test.tsx.snap index 815527f..bd35fa1 100644 --- a/src/components/KVEditor/__tests__/__snapshots__/KVEditor.test.tsx.snap +++ b/src/components/KVEditor/__tests__/__snapshots__/KVEditor.test.tsx.snap @@ -33,8 +33,9 @@ exports[`KVEditor renders properly 1`] = ` diff --git a/src/components/KVItemEdit/KVItemEdit.tsx b/src/components/KVItemEdit/KVItemEdit.tsx index bcf4144..87781e1 100644 --- a/src/components/KVItemEdit/KVItemEdit.tsx +++ b/src/components/KVItemEdit/KVItemEdit.tsx @@ -1,5 +1,5 @@ import React, { useRef, useState } from 'react'; -import { KVItemEditType } from '@base/types'; +import { KVItemEditType } from '@base/src/components/KVItemEdit/KVItemEdit.types'; import './styles.scss'; const KVItemEdit: KVItemEditType = ({ dispatch, keys, editorOptions, item = { key: '', value: '' } }) => { diff --git a/src/components/KVItemEdit/KVItemEdit.types.ts b/src/components/KVItemEdit/KVItemEdit.types.ts new file mode 100644 index 0000000..1d1c9bd --- /dev/null +++ b/src/components/KVItemEdit/KVItemEdit.types.ts @@ -0,0 +1,13 @@ +import { Dispatch, Reducer, ReducerAction } from 'react'; +import { KVAction, KVState } from '@base/src/hooks/KVReducer.types'; +import { KVEditConfigType, KVItemType } from '@base/src/components/KVEditor/KVEditor.types'; + +export interface KVItemEditPropsType { + dispatch: Dispatch>>; + keys: string[]; + editorOptions: KVEditConfigType; + item?: KVItemType; +} +export interface KVItemEditType { + (props: KVItemEditPropsType): JSX.Element; +} diff --git a/src/components/KVItemEdit/__tests__/KVItemEdit.test.tsx b/src/components/KVItemEdit/__tests__/KVItemEdit.test.tsx index 54ea146..7816f6c 100644 --- a/src/components/KVItemEdit/__tests__/KVItemEdit.test.tsx +++ b/src/components/KVItemEdit/__tests__/KVItemEdit.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { render } from '@testing-library/react'; +import { KVEditConfigType } from '@base/src/components/KVEditor/KVEditor.types'; import KVItemEdit from '../KVItemEdit'; -import { KVEditConfigType } from '@base/types'; describe('KVItemEdit', () => { const validateKey = new RegExp(/^[a-zA-Z][a-zA-Z0-9]*$/); diff --git a/src/components/KVItemEdit/__tests__/__snapshots__/KVItemEdit.test.tsx.snap b/src/components/KVItemEdit/__tests__/__snapshots__/KVItemEdit.test.tsx.snap index 77ad538..7a993fd 100644 --- a/src/components/KVItemEdit/__tests__/__snapshots__/KVItemEdit.test.tsx.snap +++ b/src/components/KVItemEdit/__tests__/__snapshots__/KVItemEdit.test.tsx.snap @@ -30,8 +30,9 @@ exports[`KVItemEdit renders properly 1`] = ` diff --git a/src/components/KVItemView/KVItemView.tsx b/src/components/KVItemView/KVItemView.tsx index fcda84e..abb8ab6 100644 --- a/src/components/KVItemView/KVItemView.tsx +++ b/src/components/KVItemView/KVItemView.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { KVItemViewType } from '@base/types'; +import { KVItemViewType } from '@base/src/components/KVItemView/KVItemView.types'; import './styles.scss'; const KVItemView: KVItemViewType = ({ item, dispatch, editorOptions }) => { diff --git a/src/components/KVItemView/KVItemView.types.ts b/src/components/KVItemView/KVItemView.types.ts new file mode 100644 index 0000000..9c5cdf7 --- /dev/null +++ b/src/components/KVItemView/KVItemView.types.ts @@ -0,0 +1,13 @@ +import { Dispatch, Reducer, ReducerAction } from 'react'; +import { KVEditConfigType, KVItemType } from '@base/src/components/KVEditor/KVEditor.types'; +import { KVAction, KVState } from '@base/src/hooks/KVReducer.types'; + +export interface KVItemViewPropsType { + dispatch: Dispatch>>; + item: KVItemType; + editorOptions: KVEditConfigType; + viewOptions: any; +} +export interface KVItemViewType { + (props: KVItemViewPropsType): JSX.Element; +} diff --git a/src/components/KVItemView/__tests__/KVItemView.test.tsx b/src/components/KVItemView/__tests__/KVItemView.test.tsx index ed4ead8..8150037 100644 --- a/src/components/KVItemView/__tests__/KVItemView.test.tsx +++ b/src/components/KVItemView/__tests__/KVItemView.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { render } from '@testing-library/react'; +import { KVEditConfigType } from '@base/src/components/KVEditor/KVEditor.types'; import KVItemView from '../KVItemView'; -import { KVEditConfigType } from '@base/types'; describe('KVItemView', () => { const validateKey = new RegExp(/^[a-zA-Z][a-zA-Z0-9]*$/); diff --git a/src/components/KVItemView/__tests__/__snapshots__/KVItemView.test.tsx.snap b/src/components/KVItemView/__tests__/__snapshots__/KVItemView.test.tsx.snap index 8720acb..f5e3ad3 100644 --- a/src/components/KVItemView/__tests__/__snapshots__/KVItemView.test.tsx.snap +++ b/src/components/KVItemView/__tests__/__snapshots__/KVItemView.test.tsx.snap @@ -22,8 +22,8 @@ exports[`KVItemView renders properly 1`] = ` diff --git a/src/example.tsx b/src/example.tsx index 14c6daf..20c5102 100644 --- a/src/example.tsx +++ b/src/example.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; +import { KVItemType } from '@base/src/components/KVEditor/KVEditor.types'; import KVEditor from './components/KVEditor/KVEditor'; -import { KVItemType } from '@base/types'; const App = () => { const [darkTheme, setDarkScheme] = useState(false); diff --git a/src/hooks/KVReducer.ts b/src/hooks/KVReducer.ts index 4120390..5f0da73 100644 --- a/src/hooks/KVReducer.ts +++ b/src/hooks/KVReducer.ts @@ -1,5 +1,5 @@ import { Reducer } from 'react'; -import { KVAction, KVState } from '@base/types'; +import { KVAction, KVState } from '@base/src/hooks/KVReducer.types'; const KVReducer: Reducer = (state, action) => { switch (action.type) { diff --git a/src/hooks/KVReducer.types.ts b/src/hooks/KVReducer.types.ts new file mode 100644 index 0000000..f08c452 --- /dev/null +++ b/src/hooks/KVReducer.types.ts @@ -0,0 +1,16 @@ +import { KVItemType } from '@base/src/components/KVEditor/KVEditor.types'; + +export interface KVState { + items: KVItemType[]; + keys: string[]; +} +export interface KVActionBase { + type: string; +} +export interface KVActionAdd extends KVActionBase { + item?: KVItemType; +} +export interface KVActionRemove extends KVActionBase { + key?: string; +} +export interface KVAction extends KVActionAdd, KVActionRemove {} diff --git a/src/hooks/__tests__/KVReducer.test.ts b/src/hooks/__tests__/KVReducer.test.ts index 227e813..d5e5967 100644 --- a/src/hooks/__tests__/KVReducer.test.ts +++ b/src/hooks/__tests__/KVReducer.test.ts @@ -1,5 +1,5 @@ import KVReducer from '../KVReducer'; -import { KVState } from '@base/types'; +import { KVState } from '@base/src/hooks/KVReducer.types'; describe('KVReducer', () => { test('ADD works', () => { diff --git a/tsconfig.json b/tsconfig.json index 340f1c7..6385319 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,8 @@ "baseUrl": ".", "rootDir": "src", "outDir": "dist", - "declaration": false, + "declaration": true, + "declarationDir": "dist", "moduleResolution": "Node", "module": "ESNext", "target": "ES6", diff --git a/types.d.ts b/types.d.ts deleted file mode 100644 index 34269a7..0000000 --- a/types.d.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Reducer -import { Dispatch, Reducer, ReducerAction } from 'react'; - -export interface KVItemType { - key: string; - value: any; -} -export interface KVState { - items: KVItemType[]; - keys: string[]; -} -export interface KVActionBase { - type: string; -} -export interface KVActionAdd extends KVActionBase { - item?: KVItemType; -} -export interface KVActionRemove extends KVActionBase { - key?: string; -} -export interface KVAction extends KVActionAdd, KVActionRemove {} - -// Components -export interface KVItemEditPropsType { - dispatch: Dispatch>>; - keys: string[]; - editorOptions: KVEditConfigType; - item?: KVItemType; -} -export interface KVItemEditType { - (props: KVItemEditPropsType): JSX.Element; -} -export interface KVItemViewPropsType { - dispatch: Dispatch>>; - item: KVItemType; - editorOptions: KVEditConfigType; - viewOptions: any; -} -export interface KVItemViewType { - (props: KVItemViewPropsType): JSX.Element; -} -export interface KVEditConfigType { - typeNotation?: string; - nested?: boolean; - validateKey?: RegExp; - theme?: string; -} -export interface KVEditorPropsType { - items?: KVItemType[]; - options?: KVEditConfigType; - onChange?: (state: any) => void; -} -export interface KVEditorType { - (props: KVEditorPropsType): JSX.Element; -}