Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: sync mobile-vue to react-vue #375

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@
"postsite:preview": "cp _site/index.html _site/404.html",
"lint": "eslint --ext .ts,.tsx ./ --max-warnings 0",
"lint:fix": "eslint --ext .ts,.tsx ./ --max-warnings 0 --fix",
"test": "npm run test:unit",
"test:update": "npm run test:unit-update",
"test:unit": "bash -c 'jest --coverage --config test/config/jest.unit.conf.js ${1}' -- ",
"test:unit-update": "jest --config test/config/jest.unit.conf.js --updateSnapshot --coverage",
"test:node": "jest --config test/config/jest.ssr.conf.js",
"test:node-update": "jest --config test/config/jest.ssr.conf.js --updateSnapshot --coverage",
"test:watch": "jest --config test/config/jest.unit.conf.js --watch",
"test:coverage": "npm run test:update",
"test": "vitest",
"test:ui": "vitest --ui",
"test:snap": "cross-env NODE_ENV=test-snap vitest run",
"test:snap-update": "cross-env NODE_ENV=test-snap vitest run -u",
"test:coverage": "vitest run --coverage",
"prebuild": "rimraf es/* lib/* dist/* esm/*",
"build": "cross-env NODE_ENV=production rollup -c script/rollup.config.js && npm run build:tsc",
"build:tsc": "concurrently \"npm:build:tsc-*\"",
Expand Down Expand Up @@ -85,15 +82,18 @@
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-replace": "^3.0.0",
"@rollup/plugin-url": "^6.0.0",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^12.1.4",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.14.178",
"@types/node": "^20.11.19",
"@types/react": "^17.0.38",
"@types/react-transition-group": "^4.4.4",
"@typescript-eslint/eslint-plugin": "^5.6.0",
"@typescript-eslint/parser": "^5.6.0",
"@vitejs/plugin-react": "^1.1.1",
"@vitest/coverage-istanbul": "^1.3.1",
"autoprefixer": "^10.4.0",
"babel-jest": "^27.5.1",
"babel-polyfill": "^6.26.0",
Expand All @@ -114,6 +114,7 @@
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"find-node-modules": "^2.1.2",
"glob": "^10.3.10",
"gray-matter": "^4.0.3",
"husky": "^7.0.4",
"inquirer": "^8.2.0",
Expand All @@ -123,6 +124,7 @@
"jest-watch-typeahead": "^1.0.0",
"less": "^4.1.2",
"markdown-it-fence": "^0.1.3",
"mockdate": "^3.0.5",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.5",
"prismjs": "^1.25.0",
Expand All @@ -147,12 +149,14 @@
"vite": "^2.7.0",
"vite-plugin-pwa": "^0.11.11",
"vite-plugin-tdoc": "^2.0.0",
"vitest": "^1.3.1",
"workbox-precaching": "^6.3.0"
},
"dependencies": {
"@use-gesture/react": "^10.2.10",
"ahooks": "^3.1.9",
"classnames": "^2.3.1",
"framer-motion": "^11.0.21",
"hoist-non-react-statics": "^3.3.2",
"lodash": "^4.17.21",
"react-spring": "^9.4.4",
Expand Down
2 changes: 1 addition & 1 deletion src/_common
Submodule _common updated 915 files
14 changes: 14 additions & 0 deletions src/_util/callBoth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// eslint-disable-next-line space-before-function-paren
export default function callBoth<T extends (...args: any[]) => any>(...fns: T[]): T {
return ((...args: any[]) => {
let lastResult: any;

// eslint-disable-next-line no-restricted-syntax
for (const fn of fns) {
if (typeof fn === 'function') {
lastResult = fn(...args);
}
}
return lastResult;
}) as T;
}
15 changes: 15 additions & 0 deletions src/_util/composeRefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Ref } from 'react';

// 同时处理多个 ref
export default function composeRefs<T>(...refs: Ref<T>[]) {
return (instance: T) => {
// eslint-disable-next-line no-restricted-syntax
for (const ref of refs) {
if (typeof ref === 'function') {
ref(instance);
} else if (ref) {
(ref as any).current = instance;
}
}
};
}
22 changes: 22 additions & 0 deletions src/_util/copyText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default function copyText(text: string) {
if ('clipboard' in navigator) {
navigator.clipboard.writeText(text);
return;
}

const textarea = document.createElement('textarea');
textarea.textContent = text;
textarea.style.width = '0px';
textarea.style.height = '0px';
document.body.appendChild(textarea);

const selection = document.getSelection();
const range = document.createRange();
range.selectNode(textarea);
selection.removeAllRanges();
selection.addRange(range);

document.execCommand('copy');
selection.removeAllRanges();
document.body.removeChild(textarea);
}
28 changes: 28 additions & 0 deletions src/_util/createHookContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { createContext, PropsWithChildren, useContext } from 'react';

/**
* 基于 Hook 创建一个 Context
* @param hook
* @returns
*/
export function createHookContext<T, P>(hook: (value: P) => T) {
const Context = createContext<T>(null);

function Provider(
props: PropsWithChildren<{
value: P;
}>,
) {
return <Context.Provider value={hook(props.value)}>{props.children}</Context.Provider>;
}

function use() {
// eslint-disable-next-line react-hooks/rules-of-hooks
return useContext(Context);
}

return {
Provider,
use,
};
}
Loading
Loading