From ebe731e780d38692eac836fb57f7bc2e25dac23c Mon Sep 17 00:00:00 2001 From: melloware Date: Wed, 3 Aug 2022 07:28:30 -0400 Subject: [PATCH 1/2] Fix #3044: FileUpload expose onFileSelect --- .babelrc | 3 + .github/workflows/node.js.yml | 1 + .gitignore | 1 + components/lib/card/Card.d.ts | 2 +- components/lib/fileupload/FileUpload.d.ts | 3 +- components/lib/fileupload/FileUpload.js | 1 + components/lib/inputmask/InputMask.d.ts | 4 +- components/lib/inputnumber/InputNumber.d.ts | 3 +- components/lib/listbox/ListBox.d.ts | 2 +- components/lib/mention/Mention.d.ts | 4 +- components/lib/steps/Steps.d.ts | 4 +- components/lib/tree/Tree.d.ts | 2 +- components/lib/treeselect/TreeSelect.d.ts | 6 +- next-env.d.ts | 5 + package-lock.json | 117 +++++++++++++++++--- package.json | 12 +- tsconfig.json | 30 +++++ 17 files changed, 167 insertions(+), 33 deletions(-) create mode 100644 .babelrc create mode 100644 next-env.d.ts create mode 100644 tsconfig.json diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000000..1ff94f7ed2 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["next/babel"] +} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 39440015fd..5a9c494e3a 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -29,6 +29,7 @@ jobs: - name: Build run: | npm install + npm run type-check npm run lint npm run security-check npm run build-lib diff --git a/.gitignore b/.gitignore index 6fe87e4d4f..f877de2550 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ # next.js /.next/ /out/ +tsconfig.tsbuildinfo # production /dist diff --git a/components/lib/card/Card.d.ts b/components/lib/card/Card.d.ts index c0cc7bad1e..1d7efd1c49 100644 --- a/components/lib/card/Card.d.ts +++ b/components/lib/card/Card.d.ts @@ -2,7 +2,7 @@ import * as React from 'react'; type CardTemplateTypes = React.ReactNode | ((props: CardProps) => React.ReactNode); -export interface CardProps extends Omit, HTMLDivElement>, 'ref'> { +export interface CardProps extends Omit, HTMLDivElement>, 'ref' | 'title'> { header?: CardTemplateTypes; footer?: CardTemplateTypes; title?: CardTemplateTypes; diff --git a/components/lib/fileupload/FileUpload.d.ts b/components/lib/fileupload/FileUpload.d.ts index a4f2a67995..bac88bbeef 100644 --- a/components/lib/fileupload/FileUpload.d.ts +++ b/components/lib/fileupload/FileUpload.d.ts @@ -82,7 +82,7 @@ interface FileUploadRemoveParams { } interface FileUploadProps { - id?: string; + id?: void; name?: string; url?: string; mode?: FileUploadModeType; @@ -130,6 +130,7 @@ export declare class FileUpload extends React.Component { public upload(): void; public clear(): void; public formatSize(bytes: number): number; + public onFileSelect(event: FileUploadSelectParams): void; public getElement(): HTMLElement; public getInput(): HTMLInputElement; } diff --git a/components/lib/fileupload/FileUpload.js b/components/lib/fileupload/FileUpload.js index af8f3ca9d4..67f0d9b18c 100644 --- a/components/lib/fileupload/FileUpload.js +++ b/components/lib/fileupload/FileUpload.js @@ -317,6 +317,7 @@ export const FileUpload = React.memo(React.forwardRef((props, ref) => { upload, clear, formatSize, + onFileSelect, getInput: () => fileInputRef.current, getContent: () => contentRef.current })); diff --git a/components/lib/inputmask/InputMask.d.ts b/components/lib/inputmask/InputMask.d.ts index c3174c000e..0a859f8be3 100644 --- a/components/lib/inputmask/InputMask.d.ts +++ b/components/lib/inputmask/InputMask.d.ts @@ -21,7 +21,7 @@ interface InputMaskChangeParams { target: InputMaskChangeTargetOptions; } -export interface InputMaskProps extends InputTextProps { +export interface InputMaskProps extends Omit { mask?: string; slotChar?: string; autoClear?: boolean; @@ -38,6 +38,6 @@ export interface InputMaskProps extends InputTextProps { children?: React.ReactNode; } -export declare class InputMask extends React.Component { +export declare class InputMask extends React.Component { public getElement(): InputText; } diff --git a/components/lib/inputnumber/InputNumber.d.ts b/components/lib/inputnumber/InputNumber.d.ts index e75c81b608..992f612e19 100644 --- a/components/lib/inputnumber/InputNumber.d.ts +++ b/components/lib/inputnumber/InputNumber.d.ts @@ -21,7 +21,7 @@ interface InputNumberChangeParams { value: number | null; } -export interface InputNumberProps extends Omit, HTMLSpanElement>, 'ref'> { +export interface InputNumberProps extends Omit, HTMLSpanElement>, 'onChange' | 'ref'> { value?: number | null; inputRef?: React.Ref; format?: boolean; @@ -51,7 +51,6 @@ export interface InputNumberProps extends Omit { +export declare class ListBox extends React.Component { public getElement(): HTMLDivElement; public getVirtualScroller(): VirtualScroller; } diff --git a/components/lib/mention/Mention.d.ts b/components/lib/mention/Mention.d.ts index 4556414cd1..c352f11b15 100644 --- a/components/lib/mention/Mention.d.ts +++ b/components/lib/mention/Mention.d.ts @@ -28,7 +28,7 @@ interface MentionSelectParams { suggestion: any; } -export interface MentionProps extends Omit, HTMLDivElement>, 'onChange' | 'onInput' | 'onFocus' | 'onBlur' | 'ref'> { +export interface MentionProps extends Omit, HTMLDivElement>, 'onSelect' | 'onChange' | 'onInput' | 'onFocus' | 'onBlur' | 'ref'> { inputId?: string; inputRef?: React.Ref; trigger?: MentionTriggerType; @@ -56,7 +56,7 @@ export interface MentionProps extends Omit { +export declare class Mention extends React.Component { public getElement(): HTMLDivElement; public getInput(): InputTextarea; public getOverlay(): HTMLElement; diff --git a/components/lib/steps/Steps.d.ts b/components/lib/steps/Steps.d.ts index 1cdc5e57fd..e866fe7256 100644 --- a/components/lib/steps/Steps.d.ts +++ b/components/lib/steps/Steps.d.ts @@ -7,7 +7,7 @@ interface StepsSelectParams { index: number; } -export interface StepsProps extends Omit, HTMLDivElement>, 'ref'> { +export interface StepsProps extends Omit, HTMLDivElement>, 'onSelect' | 'ref'> { model: MenuItem[]; activeIndex?: number; readOnly?: boolean; @@ -15,6 +15,6 @@ export interface StepsProps extends Omit { +export declare class Steps extends React.Component { public getElement(): HTMLDivElement; } diff --git a/components/lib/tree/Tree.d.ts b/components/lib/tree/Tree.d.ts index 3f1ca899cd..bc089350c4 100644 --- a/components/lib/tree/Tree.d.ts +++ b/components/lib/tree/Tree.d.ts @@ -78,7 +78,7 @@ interface TreeSelectionParams { value: TreeSelectionKeys; } -interface TreeEventNodeParams { +export interface TreeEventNodeParams { originalEvent: React.SyntheticEvent; node: TreeNode; } diff --git a/components/lib/treeselect/TreeSelect.d.ts b/components/lib/treeselect/TreeSelect.d.ts index fb3ff450d0..0bc98013c4 100644 --- a/components/lib/treeselect/TreeSelect.d.ts +++ b/components/lib/treeselect/TreeSelect.d.ts @@ -57,7 +57,9 @@ interface TreeSelectCheckboxSelectionKeyType { partialChecked?: boolean; } -interface TreeSelectEventNodeParams extends TreeEventNodeParams { +interface TreeSelectEventNodeParams { + originalEvent: React.SyntheticEvent; + node: TreeNode; } interface TreeSelectFilterValueChangeParams { @@ -112,6 +114,6 @@ export interface TreeSelectProps extends Omit { +export declare class TreeSelect extends React.Component { public getElement(): HTMLDivElement; } diff --git a/next-env.d.ts b/next-env.d.ts new file mode 100644 index 0000000000..4f11a03dc6 --- /dev/null +++ b/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/package-lock.json b/package-lock.json index c3994241e0..7e86e0a80c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,10 @@ "@rollup/plugin-commonjs": "^19.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-replace": "^2.4.2", + "@types/node": "^18.6.4", + "@types/react": "^18.0.15", + "@types/react-dom": "^18.0.6", + "@types/react-transition-group": "^4.4.5", "@typescript-eslint/parser": "^5.21.0", "eslint": "8.18.0", "eslint-config-next": "12.2.0", @@ -48,7 +52,8 @@ "rollup": "^2.52.1", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-terser": "^7.0.2", - "sass": "^1.53.0" + "sass": "^1.53.0", + "typescript": "^4.7.4" } }, "node_modules/@ampproject/remapping": { @@ -2402,9 +2407,15 @@ "dev": true }, "node_modules/@types/node": { - "version": "16.11.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.0.tgz", - "integrity": "sha512-8MLkBIYQMuhRBQzGN9875bYsOhPnf/0rgXGo66S2FemHkhbn9qtsz9ywV1iCG+vbjigE4WUNVvw37Dx+L0qsPg==", + "version": "18.6.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.4.tgz", + "integrity": "sha512-I4BD3L+6AWiUobfxZ49DlU43gtI+FTHSv9pE2Zekg6KjMpre4ByusaljW3vYSLJrvQ1ck1hUaeVu8HVlY3vzHg==", + "dev": true + }, + "node_modules/@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", "dev": true }, "node_modules/@types/raf": { @@ -2413,6 +2424,35 @@ "integrity": "sha512-taW5/WYqo36N7V39oYyHP9Ipfd5pNFvGTIQsNGj86xV88YQ7GnI30/yMfKDF7Zgin0m3e+ikX88FvImnK4RjGw==", "optional": true }, + "node_modules/@types/react": { + "version": "18.0.15", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.15.tgz", + "integrity": "sha512-iz3BtLuIYH1uWdsv6wXYdhozhqj20oD4/Hk2DNXIn1kFsmp9x8d9QB6FnPhfkbhd2PgEONt9Q1x/ebkwjfFLow==", + "dev": true, + "dependencies": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "node_modules/@types/react-dom": { + "version": "18.0.6", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.6.tgz", + "integrity": "sha512-/5OFZgfIPSwy+YuIBP/FgJnQnsxhZhjjrnxudMddeblOouIodEQ75X14Rr4wGSG/bknL+Omy9iWlLo1u/9GzAA==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, + "node_modules/@types/react-transition-group": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.5.tgz", + "integrity": "sha512-juKD/eiSM3/xZYzjuzH6ZwpP+/lejltmiS3QEzV/vmb/Q8+HfDmxu+Baga8UEMGBqV88Nbg4l2hY/K2DkyaLLA==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/resolve": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz", @@ -2422,6 +2462,12 @@ "@types/node": "*" } }, + "node_modules/@types/scheduler": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", + "dev": true + }, "node_modules/@typescript-eslint/parser": { "version": "5.21.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.21.0.tgz", @@ -10664,11 +10710,10 @@ "dev": true }, "node_modules/typescript": { - "version": "4.6.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz", - "integrity": "sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==", + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", "dev": true, - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -12865,9 +12910,15 @@ "dev": true }, "@types/node": { - "version": "16.11.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.0.tgz", - "integrity": "sha512-8MLkBIYQMuhRBQzGN9875bYsOhPnf/0rgXGo66S2FemHkhbn9qtsz9ywV1iCG+vbjigE4WUNVvw37Dx+L0qsPg==", + "version": "18.6.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.4.tgz", + "integrity": "sha512-I4BD3L+6AWiUobfxZ49DlU43gtI+FTHSv9pE2Zekg6KjMpre4ByusaljW3vYSLJrvQ1ck1hUaeVu8HVlY3vzHg==", + "dev": true + }, + "@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", "dev": true }, "@types/raf": { @@ -12876,6 +12927,35 @@ "integrity": "sha512-taW5/WYqo36N7V39oYyHP9Ipfd5pNFvGTIQsNGj86xV88YQ7GnI30/yMfKDF7Zgin0m3e+ikX88FvImnK4RjGw==", "optional": true }, + "@types/react": { + "version": "18.0.15", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.15.tgz", + "integrity": "sha512-iz3BtLuIYH1uWdsv6wXYdhozhqj20oD4/Hk2DNXIn1kFsmp9x8d9QB6FnPhfkbhd2PgEONt9Q1x/ebkwjfFLow==", + "dev": true, + "requires": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "@types/react-dom": { + "version": "18.0.6", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.0.6.tgz", + "integrity": "sha512-/5OFZgfIPSwy+YuIBP/FgJnQnsxhZhjjrnxudMddeblOouIodEQ75X14Rr4wGSG/bknL+Omy9iWlLo1u/9GzAA==", + "dev": true, + "requires": { + "@types/react": "*" + } + }, + "@types/react-transition-group": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-4.4.5.tgz", + "integrity": "sha512-juKD/eiSM3/xZYzjuzH6ZwpP+/lejltmiS3QEzV/vmb/Q8+HfDmxu+Baga8UEMGBqV88Nbg4l2hY/K2DkyaLLA==", + "dev": true, + "requires": { + "@types/react": "*" + } + }, "@types/resolve": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz", @@ -12885,6 +12965,12 @@ "@types/node": "*" } }, + "@types/scheduler": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", + "dev": true + }, "@typescript-eslint/parser": { "version": "5.21.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.21.0.tgz", @@ -19201,11 +19287,10 @@ "dev": true }, "typescript": { - "version": "4.6.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz", - "integrity": "sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==", - "dev": true, - "peer": true + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true }, "uglify-js": { "version": "3.14.5", diff --git a/package.json b/package.json index e172ac378a..b924ce1920 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "build-api": "node ./api-generator/build-api.js", "security-check": "npm audit --production --audit-level high", "start": "next start", - "lint": "next lint --max-warnings=0" + "lint": "next lint --max-warnings=0", + "type-check": "tsc" }, "dependencies": { "chart.js": "3.8.0", @@ -36,12 +37,16 @@ "@babel/plugin-transform-runtime": "^7.18.6", "@babel/preset-env": "^7.18.6", "@babel/preset-react": "^7.18.6", - "@typescript-eslint/parser": "^5.21.0", "@rollup/plugin-alias": "^3.1.2", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^19.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-replace": "^2.4.2", + "@types/node": "^18.6.4", + "@types/react": "^18.0.15", + "@types/react-dom": "^18.0.6", + "@types/react-transition-group": "^4.4.5", + "@typescript-eslint/parser": "^5.21.0", "eslint": "8.18.0", "eslint-config-next": "12.2.0", "gulp": "^4.0.2", @@ -53,6 +58,7 @@ "rollup": "^2.52.1", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-terser": "^7.0.2", - "sass": "^1.53.0" + "sass": "^1.53.0", + "typescript": "^4.7.4" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..9cd92a9d74 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": false, + "strict": true, + "forceConsistentCasingInFileNames": false, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx" + ], + "exclude": [ + "node_modules", "dist" + ] +} From 310509b6a737f1f308f4d754d84370fffcc2c453 Mon Sep 17 00:00:00 2001 From: melloware Date: Sat, 6 Aug 2022 20:55:07 -0400 Subject: [PATCH 2/2] Fix #3044: FileUpload expose onFileSelect --- .github/workflows/node.js.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 5a9c494e3a..39440015fd 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -29,7 +29,6 @@ jobs: - name: Build run: | npm install - npm run type-check npm run lint npm run security-check npm run build-lib