From 6f6dbed4c14660c4c73a733892ff0fd37c0addce Mon Sep 17 00:00:00 2001 From: janrywang Date: Sun, 31 Jan 2021 23:34:55 +0800 Subject: [PATCH] refactor(project): remove react-shared-components --- packages/antd/package.json | 1 - .../src/password}/PasswordStrength.tsx | 24 ++- packages/antd/src/password/index.tsx | 2 +- packages/next/package.json | 1 - .../next/src/password/PasswordStrength.tsx | 164 ++++++++++++++++++ packages/next/src/password/index.tsx | 2 +- packages/react-shared-components/.npmignore | 10 -- packages/react-shared-components/LICENSE.md | 20 --- packages/react-shared-components/README.md | 3 - .../react-shared-components/jest.config.js | 1 - packages/react-shared-components/package.json | 37 ---- .../react-shared-components/rollup.config.js | 3 - .../src/DragListView.tsx | 18 -- packages/react-shared-components/src/index.ts | 2 - packages/react-shared-components/src/types.ts | 13 -- .../react-shared-components/tsconfig.json | 13 -- yarn.lock | 8 - 17 files changed, 182 insertions(+), 140 deletions(-) rename packages/{react-shared-components/src => antd/src/password}/PasswordStrength.tsx (89%) create mode 100644 packages/next/src/password/PasswordStrength.tsx delete mode 100644 packages/react-shared-components/.npmignore delete mode 100644 packages/react-shared-components/LICENSE.md delete mode 100644 packages/react-shared-components/README.md delete mode 100644 packages/react-shared-components/jest.config.js delete mode 100644 packages/react-shared-components/package.json delete mode 100644 packages/react-shared-components/rollup.config.js delete mode 100644 packages/react-shared-components/src/DragListView.tsx delete mode 100644 packages/react-shared-components/src/index.ts delete mode 100644 packages/react-shared-components/src/types.ts delete mode 100644 packages/react-shared-components/tsconfig.json diff --git a/packages/antd/package.json b/packages/antd/package.json index a9c5db79b85..ced87a103b4 100644 --- a/packages/antd/package.json +++ b/packages/antd/package.json @@ -45,7 +45,6 @@ "@formily/json-schema": "^2.0.0-beta.3", "@formily/react": "^2.0.0-beta.3", "@formily/react-schema-field": "^2.0.0-beta.3", - "@formily/react-shared-components": "^2.0.0-beta.3", "@formily/shared": "^2.0.0-beta.3", "classnames": "^2.2.6", "react-sortable-hoc": "^1.11.0", diff --git a/packages/react-shared-components/src/PasswordStrength.tsx b/packages/antd/src/password/PasswordStrength.tsx similarity index 89% rename from packages/react-shared-components/src/PasswordStrength.tsx rename to packages/antd/src/password/PasswordStrength.tsx index ef05567466d..269e703f149 100644 --- a/packages/react-shared-components/src/PasswordStrength.tsx +++ b/packages/antd/src/password/PasswordStrength.tsx @@ -1,24 +1,32 @@ import React, { Fragment } from 'react' -import { IPasswordStrengthProps } from './types' import { isFn } from '@formily/shared' -const isNum = function(c) { +type ReactRenderPropsChildren = + | React.ReactNode + | ((props: T) => React.ReactElement) + +interface IPasswordStrengthProps { + value?: React.ReactText + children?: ReactRenderPropsChildren +} + +const isNum = function (c) { return c >= 48 && c <= 57 } -const isLower = function(c) { +const isLower = function (c) { return c >= 97 && c <= 122 } -const isUpper = function(c) { +const isUpper = function (c) { return c >= 65 && c <= 90 } -const isSymbol = function(c) { +const isSymbol = function (c) { return !(isLower(c) || isUpper(c) || isNum(c)) } -const isLetter = function(c) { +const isLetter = function (c) { return isLower(c) || isUpper(c) } -const getStrength = val => { +const getStrength = (val) => { if (!val) return 0 let num = 0 let lower = 0 @@ -147,7 +155,7 @@ const getStrength = val => { } } -export const PasswordStrength: React.FC = props => { +export const PasswordStrength: React.FC = (props) => { if (isFn(props.children)) { return props.children(getStrength(String(props.value))) } else { diff --git a/packages/antd/src/password/index.tsx b/packages/antd/src/password/index.tsx index ef76a9d7c94..0a890f5c6fa 100644 --- a/packages/antd/src/password/index.tsx +++ b/packages/antd/src/password/index.tsx @@ -2,7 +2,7 @@ import React from 'react' import { connect, mapReadPretty } from '@formily/react' import { Input } from 'antd' import { PasswordProps } from 'antd/lib/input' -import { PasswordStrength } from '@formily/react-shared-components' +import { PasswordStrength } from './PasswordStrength' import { PreviewText } from '../preview-text' export interface IPasswordProps extends PasswordProps { diff --git a/packages/next/package.json b/packages/next/package.json index 371a9aa872a..b92bf92584c 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -45,7 +45,6 @@ "@formily/json-schema": "^2.0.0-beta.3", "@formily/react": "^2.0.0-beta.3", "@formily/react-schema-field": "^2.0.0-beta.3", - "@formily/react-shared-components": "^2.0.0-beta.3", "@formily/shared": "^2.0.0-beta.3", "classnames": "^2.2.6", "react-sortable-hoc": "^1.11.0", diff --git a/packages/next/src/password/PasswordStrength.tsx b/packages/next/src/password/PasswordStrength.tsx new file mode 100644 index 00000000000..269e703f149 --- /dev/null +++ b/packages/next/src/password/PasswordStrength.tsx @@ -0,0 +1,164 @@ +import React, { Fragment } from 'react' +import { isFn } from '@formily/shared' + +type ReactRenderPropsChildren = + | React.ReactNode + | ((props: T) => React.ReactElement) + +interface IPasswordStrengthProps { + value?: React.ReactText + children?: ReactRenderPropsChildren +} + +const isNum = function (c) { + return c >= 48 && c <= 57 +} +const isLower = function (c) { + return c >= 97 && c <= 122 +} +const isUpper = function (c) { + return c >= 65 && c <= 90 +} +const isSymbol = function (c) { + return !(isLower(c) || isUpper(c) || isNum(c)) +} +const isLetter = function (c) { + return isLower(c) || isUpper(c) +} + +const getStrength = (val) => { + if (!val) return 0 + let num = 0 + let lower = 0 + let upper = 0 + let symbol = 0 + let MNS = 0 + let rep = 0 + let repC = 0 + let consecutive = 0 + let sequential = 0 + const len = () => num + lower + upper + symbol + const callme = () => { + let re = num > 0 ? 1 : 0 + re += lower > 0 ? 1 : 0 + re += upper > 0 ? 1 : 0 + re += symbol > 0 ? 1 : 0 + if (re > 2 && len() >= 8) { + return re + 1 + } else { + return 0 + } + } + for (let i = 0; i < val.length; i++) { + const c = val.charCodeAt(i) + if (isNum(c)) { + num++ + if (i !== 0 && i !== val.length - 1) { + MNS++ + } + if (i > 0 && isNum(val.charCodeAt(i - 1))) { + consecutive++ + } + } else if (isLower(c)) { + lower++ + if (i > 0 && isLower(val.charCodeAt(i - 1))) { + consecutive++ + } + } else if (isUpper(c)) { + upper++ + if (i > 0 && isUpper(val.charCodeAt(i - 1))) { + consecutive++ + } + } else { + symbol++ + if (i !== 0 && i !== val.length - 1) { + MNS++ + } + } + let exists = false + for (let j = 0; j < val.length; j++) { + if (val[i] === val[j] && i !== j) { + exists = true + repC += Math.abs(val.length / (j - i)) + } + } + if (exists) { + rep++ + const unique = val.length - rep + repC = unique ? Math.ceil(repC / unique) : Math.ceil(repC) + } + if (i > 1) { + const last1 = val.charCodeAt(i - 1) + const last2 = val.charCodeAt(i - 2) + if (isLetter(c)) { + if (isLetter(last1) && isLetter(last2)) { + const v = val.toLowerCase() + const vi = v.charCodeAt(i) + const vi1 = v.charCodeAt(i - 1) + const vi2 = v.charCodeAt(i - 2) + if (vi - vi1 === vi1 - vi2 && Math.abs(vi - vi1) === 1) { + sequential++ + } + } + } else if (isNum(c)) { + if (isNum(last1) && isNum(last2)) { + if (c - last1 === last1 - last2 && Math.abs(c - last1) === 1) { + sequential++ + } + } + } else { + if (isSymbol(last1) && isSymbol(last2)) { + if (c - last1 === last1 - last2 && Math.abs(c - last1) === 1) { + sequential++ + } + } + } + } + } + let sum = 0 + const length = len() + sum += 4 * length + if (lower > 0) { + sum += 2 * (length - lower) + } + if (upper > 0) { + sum += 2 * (length - upper) + } + if (num !== length) { + sum += 4 * num + } + sum += 6 * symbol + sum += 2 * MNS + sum += 2 * callme() + if (length === lower + upper) { + sum -= length + } + if (length === num) { + sum -= num + } + sum -= repC + sum -= 2 * consecutive + sum -= 3 * sequential + sum = sum < 0 ? 0 : sum + sum = sum > 100 ? 100 : sum + + if (sum >= 80) { + return 100 + } else if (sum >= 60) { + return 80 + } else if (sum >= 40) { + return 60 + } else if (sum >= 20) { + return 40 + } else { + return 20 + } +} + +export const PasswordStrength: React.FC = (props) => { + if (isFn(props.children)) { + return props.children(getStrength(String(props.value))) + } else { + return {props.children} + } +} diff --git a/packages/next/src/password/index.tsx b/packages/next/src/password/index.tsx index 3c479097827..157561d6a86 100644 --- a/packages/next/src/password/index.tsx +++ b/packages/next/src/password/index.tsx @@ -2,7 +2,7 @@ import React from 'react' import { connect, mapReadPretty } from '@formily/react' import { Input } from '@alifd/next' import { PasswordProps } from '@alifd/next/lib/input' -import { PasswordStrength } from '@formily/react-shared-components' +import { PasswordStrength } from './PasswordStrength' import { PreviewText } from '../preview-text' export interface IPasswordProps extends PasswordProps { diff --git a/packages/react-shared-components/.npmignore b/packages/react-shared-components/.npmignore deleted file mode 100644 index 478f882570d..00000000000 --- a/packages/react-shared-components/.npmignore +++ /dev/null @@ -1,10 +0,0 @@ -node_modules -*.log -build -dist -docs -doc-site -__tests__ -.eslintrc -jest.config.js -tsconfig.json \ No newline at end of file diff --git a/packages/react-shared-components/LICENSE.md b/packages/react-shared-components/LICENSE.md deleted file mode 100644 index 2bd9316cd51..00000000000 --- a/packages/react-shared-components/LICENSE.md +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015-present, Alibaba Group Holding Limited. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/react-shared-components/README.md b/packages/react-shared-components/README.md deleted file mode 100644 index da369aa55b2..00000000000 --- a/packages/react-shared-components/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @formily/react-shared - -> Formily React 通用库 diff --git a/packages/react-shared-components/jest.config.js b/packages/react-shared-components/jest.config.js deleted file mode 100644 index dfc970503b3..00000000000 --- a/packages/react-shared-components/jest.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('../../scripts/jest.base') diff --git a/packages/react-shared-components/package.json b/packages/react-shared-components/package.json deleted file mode 100644 index 571bf3b8d5c..00000000000 --- a/packages/react-shared-components/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "@formily/react-shared-components", - "version": "2.0.0-beta.3", - "license": "MIT", - "main": "lib", - "module": "esm", - "umd:main": "dist/formily.react-shared-components.umd.production.js", - "unpkg": "dist/formily.react-shared-components.umd.production.js", - "jsdelivr": "dist/formily.react-shared-components.umd.production.js", - "jsnext:main": "esm", - "types": "esm/index.d.ts", - "repository": { - "type": "git", - "url": "git+https://github.com/alibaba/formily.git" - }, - "bugs": { - "url": "https://github.com/alibaba/formily/issues" - }, - "homepage": "https://github.com/alibaba/formily#readme", - "engines": { - "npm": ">=3.0.0" - }, - "publishConfig": { - "access": "public" - }, - "gitHead": "f513fc2dcca781b3f7aa588c4419bce20cba2d8b", - "scripts": { - "build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm && npm run build:umd", - "build:cjs": "tsc --declaration", - "build:esm": "tsc --declaration --module es2015 --outDir esm", - "build:umd": "rollup --config" - }, - "dependencies": { - "react-drag-listview": "^0.1.6", - "@formily/shared": "^2.0.0-beta.3" - } -} \ No newline at end of file diff --git a/packages/react-shared-components/rollup.config.js b/packages/react-shared-components/rollup.config.js deleted file mode 100644 index 0b3e52fd200..00000000000 --- a/packages/react-shared-components/rollup.config.js +++ /dev/null @@ -1,3 +0,0 @@ -import baseConfig from '../../scripts/rollup.base.js' - -export default baseConfig('formily.react-shared-components', 'Formily.React.SharedComponents') diff --git a/packages/react-shared-components/src/DragListView.tsx b/packages/react-shared-components/src/DragListView.tsx deleted file mode 100644 index 1ceef63e05a..00000000000 --- a/packages/react-shared-components/src/DragListView.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import React from 'react' -import ReactDragListView from 'react-drag-listview' -import { IDragListViewProps } from './types' - -export const DragListView: React.FC = ({ - children, - ...props -}) => { - return ( - - {children} - - ) -} diff --git a/packages/react-shared-components/src/index.ts b/packages/react-shared-components/src/index.ts deleted file mode 100644 index d5e3bfd8b44..00000000000 --- a/packages/react-shared-components/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './PasswordStrength' -export * from './DragListView' diff --git a/packages/react-shared-components/src/types.ts b/packages/react-shared-components/src/types.ts deleted file mode 100644 index 477a414d314..00000000000 --- a/packages/react-shared-components/src/types.ts +++ /dev/null @@ -1,13 +0,0 @@ -type ReactRenderPropsChildren = - | React.ReactNode - | ((props: T) => React.ReactElement) -export interface IPasswordStrengthProps { - value?: React.ReactText - children?: ReactRenderPropsChildren -} -export interface IDragListViewProps { - onDragEnd: (fromIndex: number, toIndex: number) => void - handleSelector?: string - nodeSelector?: string - ignoreSelector?: string -} diff --git a/packages/react-shared-components/tsconfig.json b/packages/react-shared-components/tsconfig.json deleted file mode 100644 index c2d76cb89dc..00000000000 --- a/packages/react-shared-components/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib" - }, - "include": [ - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": [ - "./src/__tests__/*" - ] -} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index fdca1e938c6..f4819a8b7c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15313,14 +15313,6 @@ react-dom@^17.0.0, react-dom@^17.0.1: object-assign "^4.1.1" scheduler "^0.20.1" -react-drag-listview@^0.1.6: - version "0.1.8" - resolved "https://registry.yarnpkg.com/react-drag-listview/-/react-drag-listview-0.1.8.tgz#e04de326ecbe97d6ad84fb68664e405765e30d72" - integrity sha512-ZJnjFEz89RPZ1DzI8f6LngmtsmJbLry/pMz2tEqABxHA+d8cUFRmVPS1DxZdoz/htc+uri9fCdv4dqIiPz0xIA== - dependencies: - babel-runtime "^6.26.0" - prop-types "^15.5.8" - react-error-overlay@6.0.8: version "6.0.8" resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.8.tgz#474ed11d04fc6bda3af643447d85e9127ed6b5de"