├── .npmrc ├── packages ├── nextjs │ ├── template │ │ ├── customRoutes.json │ │ ├── src │ │ │ └── app.jsx │ │ ├── postcss.config.ejs │ │ ├── babel.config.ejs │ │ ├── tsconfig.json │ │ └── pages │ │ │ ├── _app.ejs │ │ │ └── _document.jsx │ ├── taro │ │ ├── index.js │ │ └── src │ │ │ ├── media │ │ │ └── index.ts │ │ │ ├── internal │ │ │ └── index.tsx │ │ │ ├── ui │ │ │ ├── index.ts │ │ │ ├── navigationBar.ts │ │ │ ├── background.ts │ │ │ ├── menu.ts │ │ │ └── roll.ts │ │ │ ├── _util │ │ │ ├── env.ts │ │ │ ├── typings.ts │ │ │ ├── dom.ts │ │ │ ├── raf.ts │ │ │ └── handler.ts │ │ │ ├── device │ │ │ ├── index.ts │ │ │ ├── phone.ts │ │ │ ├── vibrate.ts │ │ │ ├── battery.ts │ │ │ └── clipboard.ts │ │ │ ├── basics │ │ │ ├── performance.ts │ │ │ ├── update.ts │ │ │ ├── debug.ts │ │ │ └── index.ts │ │ │ ├── dom │ │ │ ├── index.ts │ │ │ └── nodesRef.ts │ │ │ ├── canvas │ │ │ ├── index.ts │ │ │ ├── createCanvasContext.ts │ │ │ ├── canvasToTempFilePath.ts │ │ │ ├── canvasPutImageData.ts │ │ │ └── canvasGetImageData.ts │ │ │ ├── router.ts │ │ │ └── location.ts │ ├── router │ │ ├── index.js │ │ └── src │ │ │ └── index.tsx │ ├── components │ │ └── src │ │ │ └── index.ts │ ├── src │ │ ├── taroUtils │ │ │ ├── index.ts │ │ │ └── mergeTaroPages.ts │ │ ├── constants.ts │ │ ├── nextUtils │ │ │ ├── isDynamicPage.ts │ │ │ └── recursiveReadDir.ts │ │ └── openBrowser.ts │ ├── README.md │ ├── babel │ │ ├── after.js │ │ ├── before.js │ │ ├── taro-import-plugin.js │ │ └── taro-app-plugin.js │ ├── build │ │ ├── getTSCommonConfig.js │ │ ├── projectHelper.js │ │ └── getBabelCommonConfig.js │ ├── tsconfig.json │ └── postcss │ │ └── index.js └── components │ ├── src │ ├── style │ │ ├── index.ts │ │ └── index.scss │ ├── form │ │ ├── style │ │ │ └── index.ts │ │ ├── index.md │ │ ├── formContext.ts │ │ ├── useField.ts │ │ └── demos │ │ │ └── demo1.scss │ ├── icon │ │ ├── style │ │ │ └── index.ts │ │ ├── index.md │ │ ├── demos │ │ │ └── demo1.scss │ │ └── index.tsx │ ├── label │ │ ├── style │ │ │ └── index.ts │ │ └── index.tsx │ ├── modal │ │ └── style │ │ │ └── index.ts │ ├── video │ │ ├── style │ │ │ └── index.ts │ │ ├── index.md │ │ └── demos │ │ │ └── demo1.tsx │ ├── view │ │ ├── style │ │ │ └── index.ts │ │ ├── index.md │ │ ├── index.tsx │ │ └── demos │ │ │ ├── demo1.scss │ │ │ └── demo1.tsx │ ├── swiper-item │ │ ├── style │ │ │ └── index.ts │ │ └── index.tsx │ ├── picker-view-column │ │ ├── style │ │ │ └── index.ts │ │ ├── index.md │ │ └── index.tsx │ ├── button │ │ ├── style │ │ │ ├── index.scss │ │ │ └── index.ts │ │ ├── index.md │ │ └── demos │ │ │ └── demo1.scss │ ├── image │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ ├── index.md │ │ └── demos │ │ │ └── demo1.scss │ ├── input │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ ├── index.md │ │ └── demos │ │ │ └── demo1.scss │ ├── mask │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ └── index.tsx │ ├── picker │ │ ├── style │ │ │ ├── index.js │ │ │ └── index.scss │ │ ├── constant.js │ │ └── date.js │ ├── switch │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ ├── index.md │ │ ├── demos │ │ │ └── demo1.scss │ │ └── index.tsx │ ├── text │ │ ├── style │ │ │ ├── index.scss │ │ │ └── index.ts │ │ ├── index.md │ │ ├── demos │ │ │ ├── demo1.scss │ │ │ └── demo1.tsx │ │ └── index.tsx │ ├── navigator │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ ├── index.md │ │ └── demos │ │ │ ├── demo2.tsx │ │ │ └── demo1.tsx │ ├── picker-view │ │ ├── style │ │ │ └── index.ts │ │ ├── index.md │ │ └── demos │ │ │ ├── demo1.scss │ │ │ └── demo1.tsx │ ├── progress │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ ├── index.md │ │ └── demos │ │ │ └── demo1.scss │ ├── rich-text │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ ├── index.md │ │ └── demos │ │ │ ├── demo1.scss │ │ │ └── demo1.tsx │ ├── scroll-view │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ ├── index.md │ │ └── demos │ │ │ └── demo1.scss │ ├── textarea │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ ├── demos │ │ │ ├── demo1.scss │ │ │ └── demo1.tsx │ │ ├── index.md │ │ ├── forceHiddenStyles.ts │ │ └── getSizingData.ts │ ├── web-view │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ └── index.tsx │ ├── swiper │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ └── index.md │ ├── toast │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ └── index.tsx │ ├── preview │ │ ├── style │ │ │ ├── index.ts │ │ │ └── index.scss │ │ └── index.tsx │ ├── _util │ │ ├── dom │ │ │ └── requestIdleCallback.ts │ │ ├── children │ │ │ └── toArray.ts │ │ └── hooks │ │ │ └── useMergedState.ts │ └── index.ts │ ├── taror-tools.config.js │ ├── index.js │ ├── .dumi │ └── theme │ │ └── components │ │ ├── layout │ │ └── index.scss │ │ └── subMenu │ │ └── index.scss │ ├── webpack.config.js │ ├── README.md │ ├── tsconfig.json │ ├── .umirc.ts │ ├── index-style-only.js │ └── package.json ├── examples ├── dynamic-routing │ ├── src │ │ ├── pages │ │ │ ├── post │ │ │ │ ├── index.tsx │ │ │ │ ├── index.config.ts │ │ │ │ ├── [id] │ │ │ │ │ ├── index.tsx │ │ │ │ │ └── [comment].tsx │ │ │ │ └── view.tsx │ │ │ └── index │ │ │ │ └── index.tsx │ │ ├── app.config.ts │ │ ├── app.ts │ │ ├── app.scss │ │ └── index.html │ ├── config │ │ ├── dev.js │ │ └── prod.js │ ├── project.tt.json │ ├── babel.config.js │ ├── project.config.json │ ├── README.md │ ├── global.d.ts │ ├── tsconfig.json │ └── package.json ├── data-fetch │ ├── src │ │ ├── pages │ │ │ ├── index │ │ │ │ ├── index.config.ts │ │ │ │ ├── index.h5.tsx │ │ │ │ ├── view.tsx │ │ │ │ └── index.tsx │ │ │ └── stars │ │ │ │ ├── index.h5.tsx │ │ │ │ ├── view.tsx │ │ │ │ └── index.tsx │ │ ├── app.config.ts │ │ ├── app.ts │ │ ├── app.scss │ │ └── index.html │ ├── config │ │ ├── dev.js │ │ └── prod.js │ ├── project.tt.json │ ├── README.md │ ├── babel.config.js │ ├── project.config.json │ ├── global.d.ts │ ├── tsconfig.json │ └── package.json └── reactions │ ├── src │ ├── pages │ │ └── index │ │ │ ├── index.config.ts │ │ │ ├── index.tsx │ │ │ └── index.h5.tsx │ ├── app.config.ts │ ├── app.ts │ ├── index.html │ └── app.scss │ ├── config │ ├── dev.js │ └── prod.js │ ├── project.tt.json │ ├── babel.config.js │ ├── README.md │ ├── project.config.json │ ├── global.d.ts │ ├── tsconfig.json │ └── package.json ├── .vscode └── settings.json ├── tests ├── integration │ ├── dynamic-routing │ │ ├── src │ │ │ ├── pages │ │ │ │ ├── index │ │ │ │ │ ├── index.js │ │ │ │ │ ├── view.js │ │ │ │ │ └── [id].js │ │ │ │ ├── me │ │ │ │ │ ├── index.h5.js │ │ │ │ │ ├── index.js │ │ │ │ │ └── view.js │ │ │ │ ├── post │ │ │ │ │ ├── [id].js │ │ │ │ │ ├── index.js │ │ │ │ │ └── view.js │ │ │ │ └── comment │ │ │ │ │ ├── index.js │ │ │ │ │ ├── view.js │ │ │ │ │ └── [id] │ │ │ │ │ ├── index.js │ │ │ │ │ └── [comment].js │ │ │ ├── app.js │ │ │ └── app.config.js │ │ └── config │ │ │ ├── dev.js │ │ │ ├── prod.js │ │ │ └── index.js │ ├── watch │ │ ├── src │ │ │ ├── app.js │ │ │ └── app.config.js │ │ └── config │ │ │ ├── dev.js │ │ │ ├── prod.js │ │ │ └── index.js │ └── config │ │ ├── src │ │ ├── app.js │ │ ├── pages │ │ │ └── index │ │ │ │ └── index.js │ │ └── app.config.js │ │ ├── config │ │ ├── dev.js │ │ ├── prod.js │ │ └── index.js │ │ └── index.spec.ts ├── babel │ ├── next-ssg-plugin │ │ ├── __fixtures__ │ │ │ ├── full-re-export │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── remove-named-export │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── babel-style-memoized-function │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── remove-combined-named-export │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── remove-named-export-function │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── remove-named-export-variable │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── remove-re-exported-function │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── remove-named-export-async-function │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── remove-named-export-async-variable │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── class-declarations │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── remove-re-exported-variable │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── class-exports │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── retain-extra-named-export-variable │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── retain-extra-named-export-function │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── retain-extra-named-export │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── destructuring-assignment-array │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── destructuring-assignment-object │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ ├── not-mix-up-bindings │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ │ └── remove-re-exported-function-dependents-variables-functions-imports │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ └── index.spec.js │ ├── taro-app-plugin │ │ ├── __fixtures__ │ │ │ └── basic │ │ │ │ ├── output.js │ │ │ │ └── code.js │ │ └── index.spec.js │ ├── next-app-plugin │ │ ├── app.js │ │ ├── __fixtures__ │ │ │ └── basic │ │ │ │ ├── code.js │ │ │ │ └── output.js │ │ └── index.spec.js │ ├── class-component-taro-router-plugin │ │ ├── __fixtures__ │ │ │ ├── property │ │ │ │ ├── code.js │ │ │ │ └── output.js │ │ │ ├── ignore-function-component │ │ │ │ ├── code.js │ │ │ │ └── output.js │ │ │ ├── method │ │ │ │ ├── code.js │ │ │ │ └── output.js │ │ │ └── trasformed │ │ │ │ ├── code.js │ │ │ │ └── output.js │ │ └── index.spec.js │ └── taro-import-plugin │ │ ├── index.spec.js │ │ └── __fixtures__ │ │ └── basic │ │ ├── code.js │ │ └── output.js ├── __fixtures__ │ ├── getNextExportedFunctions │ │ ├── named.js │ │ ├── function.js │ │ └── variable.js │ └── template │ │ └── nextConfig │ │ ├── default.js │ │ └── basic.js ├── taro │ ├── device │ │ └── clipboard.spec.ts │ └── dataCache.spec.ts ├── utils.spec.ts └── template │ └── nextConfig.spec.ts ├── jest.config.js ├── .editorconfig ├── lerna.json ├── tsconfig.json ├── LICENSE ├── package.json ├── typings └── event-stream.d.ts ├── .eslintrc.js └── .gitignore /.npmrc: -------------------------------------------------------------------------------- 1 | registry=https://registry.npmjs.org/ 2 | -------------------------------------------------------------------------------- /packages/nextjs/template/customRoutes.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /packages/components/src/style/index.ts: -------------------------------------------------------------------------------- 1 | import './index.scss' 2 | -------------------------------------------------------------------------------- /packages/nextjs/taro/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib') 2 | -------------------------------------------------------------------------------- /packages/nextjs/router/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib') 2 | -------------------------------------------------------------------------------- /packages/nextjs/components/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from '@taror/components' 2 | -------------------------------------------------------------------------------- /packages/components/src/form/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | -------------------------------------------------------------------------------- /packages/components/src/icon/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | -------------------------------------------------------------------------------- /packages/components/src/label/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | -------------------------------------------------------------------------------- /packages/components/src/modal/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | -------------------------------------------------------------------------------- /packages/components/src/video/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | -------------------------------------------------------------------------------- /packages/components/src/view/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | -------------------------------------------------------------------------------- /examples/dynamic-routing/src/pages/post/index.tsx: -------------------------------------------------------------------------------- 1 | export {default} from './view'; 2 | -------------------------------------------------------------------------------- /packages/components/src/swiper-item/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib" 3 | } 4 | -------------------------------------------------------------------------------- /packages/components/src/picker-view-column/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | -------------------------------------------------------------------------------- /packages/nextjs/src/taroUtils/index.ts: -------------------------------------------------------------------------------- 1 | export {mergeTaroPages} from './mergeTaroPages' 2 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/index/index.js: -------------------------------------------------------------------------------- 1 | export {default} from './view' 2 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/me/index.h5.js: -------------------------------------------------------------------------------- 1 | export {default} from './view' 2 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/me/index.js: -------------------------------------------------------------------------------- 1 | export {default} from './view' 2 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/post/[id].js: -------------------------------------------------------------------------------- 1 | export {default} from './view' 2 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/post/index.js: -------------------------------------------------------------------------------- 1 | export {default} from './view' 2 | -------------------------------------------------------------------------------- /packages/nextjs/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const SCRIPT_EXTS = ['.js', '.jsx', '.ts', '.tsx'] 2 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/media/index.ts: -------------------------------------------------------------------------------- 1 | export * from './image' 2 | export * from './video' 3 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/full-re-export/output.js: -------------------------------------------------------------------------------- 1 | export { default } from "a"; 2 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/comment/index.js: -------------------------------------------------------------------------------- 1 | export {default} from './view' 2 | -------------------------------------------------------------------------------- /packages/components/taror-tools.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | libraryName: 'taror' 3 | } 4 | -------------------------------------------------------------------------------- /tests/integration/watch/src/app.js: -------------------------------------------------------------------------------- 1 | const App = ({children}) => children 2 | 3 | export default App 4 | -------------------------------------------------------------------------------- /packages/components/index.js: -------------------------------------------------------------------------------- 1 | require('./index-style-only') 2 | 3 | module.exports = require('./src') 4 | -------------------------------------------------------------------------------- /packages/components/src/button/style/index.scss: -------------------------------------------------------------------------------- 1 | .weui-btn:after { 2 | pointer-events: none; 3 | } 4 | -------------------------------------------------------------------------------- /packages/components/src/button/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/image/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/input/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/mask/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/picker/style/index.js: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/switch/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/text/style/index.scss: -------------------------------------------------------------------------------- 1 | .taro-text_selectable { 2 | user-select: text; 3 | } 4 | -------------------------------------------------------------------------------- /packages/components/src/text/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /tests/integration/config/src/app.js: -------------------------------------------------------------------------------- 1 | const App = ({children}) => children 2 | 3 | export default App 4 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/me/view.js: -------------------------------------------------------------------------------- 1 | const Me = () => null 2 | 3 | export default Me 4 | -------------------------------------------------------------------------------- /packages/components/src/navigator/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/picker-view/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/progress/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/rich-text/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/scroll-view/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/textarea/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /packages/components/src/web-view/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/full-re-export/code.js: -------------------------------------------------------------------------------- 1 | export { getStaticProps, default } from 'a' 2 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/app.js: -------------------------------------------------------------------------------- 1 | const App = ({children}) => children 2 | 3 | export default App 4 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/post/view.js: -------------------------------------------------------------------------------- 1 | const Post = () => null 2 | 3 | export default Post 4 | -------------------------------------------------------------------------------- /examples/data-fetch/src/pages/index/index.config.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | navigationBarTitleText: '首页' 3 | } 4 | -------------------------------------------------------------------------------- /packages/components/src/picker/style/index.scss: -------------------------------------------------------------------------------- 1 | .weui-picker, .weui-picker__hd { 2 | font-size: 12px; 3 | } 4 | -------------------------------------------------------------------------------- /packages/components/src/rich-text/style/index.scss: -------------------------------------------------------------------------------- 1 | .taro-rich-text__selectable { 2 | user-select: auto; 3 | } 4 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/index/view.js: -------------------------------------------------------------------------------- 1 | const Index = () => null 2 | 3 | export default Index 4 | -------------------------------------------------------------------------------- /examples/dynamic-routing/src/pages/post/index.config.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | navigationBarTitleText: '首页' 3 | } 4 | -------------------------------------------------------------------------------- /packages/components/src/textarea/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .taro-textarea { 2 | width: 100%; 3 | padding: 17px; 4 | } 5 | -------------------------------------------------------------------------------- /tests/integration/config/src/pages/index/index.js: -------------------------------------------------------------------------------- 1 | const Index = () => 'hello, world!' 2 | 3 | export default Index 4 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/comment/view.js: -------------------------------------------------------------------------------- 1 | const Comment = () => null 2 | 3 | export default Comment 4 | -------------------------------------------------------------------------------- /packages/components/src/icon/index.md: -------------------------------------------------------------------------------- 1 | # Icon 图标 2 | 3 | 图片组件。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/components/src/text/index.md: -------------------------------------------------------------------------------- 1 | # Text 文本 2 | 3 | 文本元素。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/integration/config/src/app.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | pages: [ 3 | 'pages/index/index' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/watch/src/app.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | pages: [ 3 | 'pages/index/index' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /examples/reactions/src/pages/index/index.config.ts: -------------------------------------------------------------------------------- 1 | export default definePageConfig({ 2 | navigationBarTitleText: '首页' 3 | }) 4 | -------------------------------------------------------------------------------- /packages/components/src/input/index.md: -------------------------------------------------------------------------------- 1 | # Input 输入框 2 | 3 | 输入框。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/nextjs/README.md: -------------------------------------------------------------------------------- 1 | # Taro 插件,用于编译为 Next.js 应用 2 | 3 | 访问 https://github.com/NervJS/tarojs-plugin-platform-nextjs 完整文档。 4 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/internal/index.tsx: -------------------------------------------------------------------------------- 1 | export * from './taroApp' 2 | 3 | export {default as TaroPage} from './taroPage' 4 | -------------------------------------------------------------------------------- /packages/components/src/progress/index.md: -------------------------------------------------------------------------------- 1 | # Progress 进度条 2 | 3 | 进度条。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/components/src/rich-text/index.md: -------------------------------------------------------------------------------- 1 | # RichText 富文本 2 | 3 | 富文本。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/components/src/switch/index.md: -------------------------------------------------------------------------------- 1 | # Switch 开关选择器 2 | 3 | 开关选择器。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export/output.js: -------------------------------------------------------------------------------- 1 | export default function Test() { 2 | return
; 3 | } 4 | -------------------------------------------------------------------------------- /packages/components/src/button/index.md: -------------------------------------------------------------------------------- 1 | # Button 按钮 2 | 3 | 按钮用于开始一个即时操作。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/components/src/swiper/style/index.ts: -------------------------------------------------------------------------------- 1 | import 'swiper/swiper.scss' 2 | import '../../style/index.scss' 3 | import './index.scss' 4 | -------------------------------------------------------------------------------- /tests/integration/watch/config/dev.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: JSON.stringify('development') 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/watch/config/prod.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: JSON.stringify('production') 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/babel-style-memoized-function/output.js: -------------------------------------------------------------------------------- 1 | export default function Home() { 2 | return
; 3 | } 4 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-combined-named-export/output.js: -------------------------------------------------------------------------------- 1 | export default function Test() { 2 | return
; 3 | } 4 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export-function/output.js: -------------------------------------------------------------------------------- 1 | export default function Test() { 2 | return
; 3 | } 4 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export-variable/output.js: -------------------------------------------------------------------------------- 1 | export default function Test() { 2 | return
; 3 | } 4 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-re-exported-function/output.js: -------------------------------------------------------------------------------- 1 | export default function Test() { 2 | return
; 3 | } 4 | -------------------------------------------------------------------------------- /tests/integration/config/config/dev.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: JSON.stringify('development') 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/config/config/prod.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: JSON.stringify('production') 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/components/src/picker-view/index.md: -------------------------------------------------------------------------------- 1 | # PickerView 滚动选择器 2 | 3 | 可嵌页面的滚动选择器。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/components/src/textarea/index.md: -------------------------------------------------------------------------------- 1 | # Textarea 多行输入框 2 | 3 | 多行输入框。内部不支持嵌套其他组件。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export-async-function/output.js: -------------------------------------------------------------------------------- 1 | export default function Test() { 2 | return
; 3 | } 4 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export-async-variable/output.js: -------------------------------------------------------------------------------- 1 | export default function Test() { 2 | return
; 3 | } 4 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/config/dev.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: JSON.stringify('development') 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/config/prod.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: JSON.stringify('production') 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/components/.dumi/theme/components/layout/index.scss: -------------------------------------------------------------------------------- 1 | .__dumi-default-mobile-content>article { 2 | min-width: auto; 3 | width: 100%; 4 | } 5 | -------------------------------------------------------------------------------- /packages/components/src/video/index.md: -------------------------------------------------------------------------------- 1 | # Video 视频 2 | 3 | 视频。video 组件默认宽度 300px 、高度 225px 。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/components/.dumi/theme/components/subMenu/index.scss: -------------------------------------------------------------------------------- 1 | .__dumi-default-menu-inner ul li a { 2 | line-height: 1.4; 3 | padding: 12px 0; 4 | } 5 | -------------------------------------------------------------------------------- /packages/components/src/picker/constant.js: -------------------------------------------------------------------------------- 1 | export const TOP = 102 2 | 3 | export const LINE_HEIGHT = 34 4 | 5 | export const MASK_HEIGHT = LINE_HEIGHT * 7 6 | -------------------------------------------------------------------------------- /packages/components/webpack.config.js: -------------------------------------------------------------------------------- 1 | const getWebpackConfig = require('@taror/tools/lib/getWebpackConfig') 2 | 3 | module.exports = getWebpackConfig(false) 4 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/class-declarations/output.js: -------------------------------------------------------------------------------- 1 | export class MyClass {} 2 | export default function Test() { 3 | return
; 4 | } 5 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-re-exported-variable/output.js: -------------------------------------------------------------------------------- 1 | const a = 2; 2 | export default function Test() { 3 | return
; 4 | } 5 | -------------------------------------------------------------------------------- /packages/components/src/toast/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | 4 | // style dependencies 5 | import '../../mask/style' 6 | -------------------------------------------------------------------------------- /packages/nextjs/src/nextUtils/isDynamicPage.ts: -------------------------------------------------------------------------------- 1 | export function isDynamicPage(str: string): boolean { 2 | return str.startsWith('[') && str.endsWith(']') 3 | } 4 | -------------------------------------------------------------------------------- /packages/components/src/swiper/index.md: -------------------------------------------------------------------------------- 1 | # Swiper 视图容器 2 | 3 | 滑块视图容器。内部只允许使用 SwiperItem 组件描述滑块内容,否则会导致未定义的行为。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/__fixtures__/getNextExportedFunctions/named.js: -------------------------------------------------------------------------------- 1 | export {default as getStaticPaths} from './getStaticPaths'; 2 | 3 | export {getStaticProps} from './getStaticProps'; 4 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/class-exports/output.js: -------------------------------------------------------------------------------- 1 | export default class Test extends React.Component { 2 | render() { 3 | return
; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/retain-extra-named-export-variable/output.js: -------------------------------------------------------------------------------- 1 | export const foo = 2; 2 | export default function Test() { 3 | return
; 4 | } 5 | -------------------------------------------------------------------------------- /packages/components/src/picker-view/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .item { 2 | text-align: center; 3 | } 4 | 5 | .selected-date { 6 | margin: 30px; 7 | text-align: center; 8 | } 9 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/retain-extra-named-export-function/output.js: -------------------------------------------------------------------------------- 1 | export function Noop() {} 2 | export default function Test() { 3 | return
; 4 | } 5 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/retain-extra-named-export/output.js: -------------------------------------------------------------------------------- 1 | export { foo, bar as baz } from "."; 2 | export default function Test() { 3 | return
; 4 | } 5 | -------------------------------------------------------------------------------- /packages/components/src/image/index.md: -------------------------------------------------------------------------------- 1 | # Image 图片 2 | 3 | 图片,支持 JPG、PNG、GIF、BMP、WEBP 等格式。image 组件默认宽度 300px 、高度 225px 。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/components/src/switch/style/index.scss: -------------------------------------------------------------------------------- 1 | .weui-agree__checkbox { 2 | width: 22px; 3 | height: 22px; 4 | 5 | &::before { 6 | font-size: 22px; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/data-fetch/config/dev.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: '"development"' 4 | }, 5 | defineConstants: { 6 | }, 7 | mini: {}, 8 | h5: {} 9 | } 10 | -------------------------------------------------------------------------------- /examples/reactions/config/dev.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: '"development"' 4 | }, 5 | defineConstants: { 6 | }, 7 | mini: {}, 8 | h5: {} 9 | } 10 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/ui/index.ts: -------------------------------------------------------------------------------- 1 | export * from './background' 2 | export * from './interactive' 3 | export * from './menu' 4 | export * from './navigationBar' 5 | export * from './roll' 6 | -------------------------------------------------------------------------------- /examples/dynamic-routing/config/dev.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | NODE_ENV: '"development"' 4 | }, 5 | defineConstants: { 6 | }, 7 | mini: {}, 8 | h5: {} 9 | } 10 | -------------------------------------------------------------------------------- /packages/components/src/view/index.md: -------------------------------------------------------------------------------- 1 | # View 视图容器 2 | 3 | 视图容器。相当于 HTML 中的 div 标签,可将页面分割为独立的、不同的部分。如果需要使用滚动视图,请使用 ScrollView 组件。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/_util/env.ts: -------------------------------------------------------------------------------- 1 | export function isAndroid() { 2 | const {userAgent} = window.navigator 3 | return /(Android);?[\s\/]+([\d.]+)?|Baidu;.*P1/.test(userAgent) 4 | } 5 | -------------------------------------------------------------------------------- /examples/dynamic-routing/src/pages/post/[id]/index.tsx: -------------------------------------------------------------------------------- 1 | export {default} from '../view'; 2 | 3 | export const getServerSideProps = async () => { 4 | return { 5 | props: {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/components/src/preview/style/index.ts: -------------------------------------------------------------------------------- 1 | import '../../style/index.scss' 2 | import './index.scss' 3 | 4 | // style dependencies 5 | import '../../mask/style' 6 | import '../../swiper/style' 7 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/destructuring-assignment-array/output.js: -------------------------------------------------------------------------------- 1 | import other from "other"; 2 | const [foo] = other; 3 | export default function Home() { 4 | return
; 5 | } 6 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-combined-named-export/code.js: -------------------------------------------------------------------------------- 1 | export { getStaticPaths, a as getStaticProps } from "."; 2 | export default function Test() { 3 | return
; 4 | } 5 | -------------------------------------------------------------------------------- /examples/dynamic-routing/src/pages/post/[id]/[comment].tsx: -------------------------------------------------------------------------------- 1 | export {default} from '../view'; 2 | 3 | export const getServerSideProps = async () => { 4 | return { 5 | props: {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/components/src/picker-view-column/index.md: -------------------------------------------------------------------------------- 1 | # PickerViewColumn 滚动选择器子项 2 | 3 | 可嵌页面的滚动选择器子项。仅可放置于 PickerView 中,其孩子节点的高度会自动设置成与 picker-view 的选中框的高度一致。 4 | 5 | ## 示例 6 | 7 | 参见 PickerView 示例内容。 8 | -------------------------------------------------------------------------------- /packages/components/src/scroll-view/index.md: -------------------------------------------------------------------------------- 1 | # ScrollView 可滚动视图区域 2 | 3 | 可滚动视图区域,可实现横向滚动和竖向滚动。使用竖向滚动时,需要给定该组件一个固定高度,可以通过 CSS 设置 height 。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/index/[id].js: -------------------------------------------------------------------------------- 1 | export {default} from './view' 2 | 3 | export const getServerSideProps = async () => { 4 | return { 5 | props: {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/destructuring-assignment-object/output.js: -------------------------------------------------------------------------------- 1 | import other from "other"; 2 | const { a, cat: bar } = other; 3 | export default function Home() { 4 | return
; 5 | } 6 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/comment/[id]/index.js: -------------------------------------------------------------------------------- 1 | export {default} from '../view' 2 | 3 | export const getServerSideProps = async () => { 4 | return { 5 | props: {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node', 5 | testRegex: '(\\.|/)(test|spec)\\.[jt]sx?$' 6 | } 7 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/retain-extra-named-export/code.js: -------------------------------------------------------------------------------- 1 | export { getStaticPaths, a as getStaticProps, foo, bar as baz } from '.'; 2 | export default function Test() { 3 | return
; 4 | } 5 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/pages/comment/[id]/[comment].js: -------------------------------------------------------------------------------- 1 | export {default} from '../view' 2 | 3 | export const getServerSideProps = async () => { 4 | return { 5 | props: {} 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/data-fetch/project.tt.json: -------------------------------------------------------------------------------- 1 | { 2 | "miniprogramRoot": "./", 3 | "projectname": "data", 4 | "appid": "testAppId", 5 | "setting": { 6 | "es6": false, 7 | "minified": false 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/reactions/project.tt.json: -------------------------------------------------------------------------------- 1 | { 2 | "miniprogramRoot": "./", 3 | "projectname": "data", 4 | "appid": "testAppId", 5 | "setting": { 6 | "es6": false, 7 | "minified": false 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export/code.js: -------------------------------------------------------------------------------- 1 | export { getStaticPaths } from "."; 2 | export { a as getStaticProps } from "."; 3 | export default function Test() { 4 | return
; 5 | }; 6 | -------------------------------------------------------------------------------- /examples/dynamic-routing/project.tt.json: -------------------------------------------------------------------------------- 1 | { 2 | "miniprogramRoot": "./", 3 | "projectname": "data", 4 | "appid": "testAppId", 5 | "setting": { 6 | "es6": false, 7 | "minified": false 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/components/src/web-view/style/index.scss: -------------------------------------------------------------------------------- 1 | .taro-webview { 2 | position: fixed; 3 | top: 0; 4 | bottom: 0; 5 | width: 100%; 6 | height: 100%; 7 | border: none; 8 | z-index: 999; 9 | } 10 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/src/app.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | pages: [ 3 | 'pages/index/index', 4 | 'pages/comment/index', 5 | 'pages/post/index', 6 | 'pages/me/index' 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /tests/babel/taro-app-plugin/__fixtures__/basic/output.js: -------------------------------------------------------------------------------- 1 | import { Component } from "react"; 2 | 3 | class App extends Component { 4 | render() { 5 | return this.props.children; 6 | } 7 | } 8 | 9 | export default App; 10 | -------------------------------------------------------------------------------- /tests/babel/next-app-plugin/app.js: -------------------------------------------------------------------------------- 1 | import { Component } from "react"; 2 | import "./app.scss"; 3 | 4 | class App extends Component { 5 | render() { 6 | return this.props.children; 7 | } 8 | } 9 | 10 | export default App; 11 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-re-exported-function/code.js: -------------------------------------------------------------------------------- 1 | function getStaticPaths() { 2 | return []; 3 | } 4 | 5 | export { getStaticPaths } 6 | 7 | export default function Test() { 8 | return
; 9 | } 10 | -------------------------------------------------------------------------------- /examples/data-fetch/README.md: -------------------------------------------------------------------------------- 1 | # 数据请求示例 2 | 3 | 通过导出 `getStaticProps` Next.js 将在构建阶段获取数据,并将页面预渲染为静态页面。 4 | 5 | ## 执行 Next.js 6 | 7 | ```bash 8 | yarn dev:nextjs 9 | ``` 10 | 11 | ## 执行小程序 12 | 13 | ```bash 14 | yarn dev:swan 15 | ``` 16 | -------------------------------------------------------------------------------- /packages/components/src/navigator/index.md: -------------------------------------------------------------------------------- 1 | # Navigator 页面导航 2 | 3 | 页面链接,控制小程序的跳转,既可在当前小程序内部进行跳转,也可跳转至其他小程序。navigator 的子节点背景色应为透明色。 4 | 5 | ## 示例 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-re-exported-variable/code.js: -------------------------------------------------------------------------------- 1 | const getStaticPaths = () => { 2 | return []; 3 | }, a = 2 4 | 5 | export { getStaticPaths }; 6 | 7 | export default function Test() { 8 | return
; 9 | } 10 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/class-exports/code.js: -------------------------------------------------------------------------------- 1 | export function getStaticProps() { 2 | return { props: {} }; 3 | } 4 | 5 | export default class Test extends React.Component { 6 | render() { 7 | return
; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/components/src/input/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .normalInput { 2 | height: 51px; 3 | margin: 0 17px; 4 | } 5 | 6 | .textarea { 7 | min-height: 51px; 8 | margin: 0 17px; 9 | padding: 10px; 10 | background-color: #f8f8f8; 11 | } 12 | -------------------------------------------------------------------------------- /packages/components/src/text/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .text-box { 2 | margin: 17px; 3 | } 4 | 5 | .text-block { 6 | display: block; 7 | height: 24px; 8 | overflow: hidden; 9 | white-space: nowrap; 10 | text-overflow: ellipsis; 11 | } 12 | -------------------------------------------------------------------------------- /tests/babel/taro-app-plugin/__fixtures__/basic/code.js: -------------------------------------------------------------------------------- 1 | import { Component } from "react"; 2 | import "./app.scss"; 3 | 4 | class App extends Component { 5 | render() { 6 | return this.props.children; 7 | } 8 | } 9 | 10 | export default App; 11 | -------------------------------------------------------------------------------- /packages/components/src/form/index.md: -------------------------------------------------------------------------------- 1 | # Form 表单 2 | 3 | 表单,将 Form 组件内用户输入的 Switch、Input、Checkbox、Slider、Radio、Picker 提交。当表单中 formType 为 submit 时,点击的 Button 组件会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key 。 4 | 5 | ## 示例 6 | 7 | 8 | -------------------------------------------------------------------------------- /packages/components/src/progress/style/index.scss: -------------------------------------------------------------------------------- 1 | .weui-progress { 2 | &__bar { 3 | overflow: hidden; 4 | } 5 | 6 | &__inner-bar { 7 | width: 100%; 8 | height: 100%; 9 | transform-origin: left; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/class-declarations/code.js: -------------------------------------------------------------------------------- 1 | function getStaticPaths() { 2 | return []; 3 | } 4 | 5 | export { getStaticPaths } 6 | 7 | export class MyClass {} 8 | 9 | export default function Test() { 10 | return
; 11 | } 12 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/retain-extra-named-export-function/code.js: -------------------------------------------------------------------------------- 1 | export function getStaticProps() { 2 | return { props: {} } 3 | } 4 | 5 | export function Noop() {} 6 | 7 | export default function Test() { 8 | return
; 9 | } 10 | -------------------------------------------------------------------------------- /packages/components/src/navigator/style/index.scss: -------------------------------------------------------------------------------- 1 | .taro-nav { 2 | display: block; 3 | width: auto; 4 | height: auto; 5 | color: inherit; 6 | } 7 | 8 | .navigator-hover { 9 | opacity: .7; 10 | background-color: rgba(0, 0, 0, .1) 11 | } 12 | -------------------------------------------------------------------------------- /packages/components/README.md: -------------------------------------------------------------------------------- 1 | # Taro 组件的 React 实现 2 | 3 | ## 文档 4 | 5 | https://nervjs.github.io/tarojs-plugin-platform-nextjs/ 6 | 7 | ## 安装 8 | 9 | ```bash 10 | npm install @taror/components 11 | ``` 12 | 13 | ```bash 14 | yarn add @taror/components 15 | ``` 16 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/__fixtures__/property/code.js: -------------------------------------------------------------------------------- 1 | import Taro from "@tarojs/taro"; 2 | 3 | export default class Index extends Component { 4 | $instance = Taro.getCurrentInstance(); 5 | 6 | render() { 7 | return null; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/babel-style-memoized-function/code.js: -------------------------------------------------------------------------------- 1 | function fn() { 2 | fn = function () {}; 3 | return fn.apply(this, arguments); 4 | } 5 | export function getStaticProps() { 6 | fn; 7 | } 8 | export default function Home() { return
; } 9 | -------------------------------------------------------------------------------- /packages/components/src/progress/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .progress, 2 | .inner-progress { 3 | margin: 35px 23px; 4 | } 5 | 6 | .inner-progress .progress-bar { 7 | border-radius: 25px; 8 | } 9 | .inner-progress .progress-inner-bar { 10 | border-radius: 25px; 11 | } 12 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/device/index.ts: -------------------------------------------------------------------------------- 1 | export * from './accelerometer' 2 | export * from './battery' 3 | export * from './clipboard' 4 | export * from './compass' 5 | export * from './motion' 6 | export * from './network' 7 | export * from './phone' 8 | export * from './vibrate' 9 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export-function/code.js: -------------------------------------------------------------------------------- 1 | export function getStaticPaths() { 2 | return [] 3 | } 4 | export function getStaticProps() { 5 | return { props: {} } 6 | } 7 | export default function Test() { 8 | return
9 | } 10 | -------------------------------------------------------------------------------- /examples/reactions/babel.config.js: -------------------------------------------------------------------------------- 1 | // babel-preset-taro 更多选项和默认值: 2 | // https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md 3 | module.exports = { 4 | presets: [ 5 | ['taro', { 6 | framework: 'react', 7 | ts: true 8 | }] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/not-mix-up-bindings/output.js: -------------------------------------------------------------------------------- 1 | function Function1() { 2 | return { 3 | a: function bug(a) { 4 | return 2; 5 | }, 6 | }; 7 | } 8 | 9 | function Function2() { 10 | var bug = 1; 11 | return { 12 | bug, 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /examples/data-fetch/babel.config.js: -------------------------------------------------------------------------------- 1 | // babel-preset-taro 更多选项和默认值: 2 | // https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md 3 | module.exports = { 4 | presets: [ 5 | ['taro', { 6 | framework: 'react', 7 | ts: true 8 | }] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /tests/taro/device/clipboard.spec.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @jest-environment jsdom 3 | */ 4 | 5 | import {getClipboardData} from 'tarojs-plugin-platform-nextjs/taro' 6 | 7 | it('storage', async () => { 8 | const {data: data1} = await getClipboardData() 9 | expect(data1).toBe('') 10 | }) 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | indent_style = space 11 | indent_size = 4 12 | -------------------------------------------------------------------------------- /examples/dynamic-routing/babel.config.js: -------------------------------------------------------------------------------- 1 | // babel-preset-taro 更多选项和默认值: 2 | // https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md 3 | module.exports = { 4 | presets: [ 5 | ['taro', { 6 | framework: 'react', 7 | ts: true 8 | }] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/__fixtures__/ignore-function-component/code.js: -------------------------------------------------------------------------------- 1 | import Taro from "@tarojs/taro"; 2 | 3 | function Index() { 4 | const $instance = Taro.getCurrentInstance(); 5 | console.log($instance); 6 | return null; 7 | } 8 | 9 | export default Index; 10 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/__fixtures__/ignore-function-component/output.js: -------------------------------------------------------------------------------- 1 | import Taro from "@tarojs/taro"; 2 | 3 | function Index() { 4 | const $instance = Taro.getCurrentInstance(); 5 | console.log($instance); 6 | return null; 7 | } 8 | 9 | export default Index; 10 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export-variable/code.js: -------------------------------------------------------------------------------- 1 | export const getStaticPaths = () => { 2 | return []; 3 | } 4 | 5 | export const getStaticProps = function() { 6 | return { props: {} }; 7 | } 8 | 9 | export default function Test() { 10 | return
; 11 | } 12 | -------------------------------------------------------------------------------- /packages/components/src/switch/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .init-switch { 2 | margin: 14px 0 14px 17px; 3 | vertical-align: middle; 4 | } 5 | 6 | .init-switch-after { 7 | margin: 14px 0 14px 50px; 8 | vertical-align: middle; 9 | } 10 | 11 | .switch-text { 12 | vertical-align: middle; 13 | } 14 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export-async-function/code.js: -------------------------------------------------------------------------------- 1 | export async function getStaticPaths() { 2 | return []; 3 | } 4 | 5 | export async function getStaticProps() { 6 | return { props: {} }; 7 | } 8 | 9 | export default function Test() { 10 | return
; 11 | } 12 | -------------------------------------------------------------------------------- /packages/components/src/picker-view-column/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export interface PickerViewColumnProps { 4 | children?: React.ReactNode 5 | } 6 | 7 | const PickerViewColumn: React.FC = ({children}) => <>{children} 8 | 9 | export default PickerViewColumn 10 | -------------------------------------------------------------------------------- /examples/reactions/README.md: -------------------------------------------------------------------------------- 1 | # ISR 示例 2 | 3 | 这个演示展示了 Next.js 的 ISR 功能,使用 GitHub Issues 作为数据源。 4 | 5 | ## 执行 Next.js 6 | 7 | ```bash 8 | export GITHUB_TOKEN= && yarn dev:nextjs 9 | ``` 10 | 11 | ## 执行小程序 12 | 13 | ```bash 14 | export GITHUB_TOKEN= && yarn dev:swan 15 | ``` 16 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-named-export-async-variable/code.js: -------------------------------------------------------------------------------- 1 | export const getStaticPaths = async () => { 2 | return []; 3 | } 4 | 5 | export const getStaticProps = async function() { 6 | return { props: {} }; 7 | } 8 | 9 | export default function Test() { 10 | return
; 11 | } 12 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/retain-extra-named-export-variable/code.js: -------------------------------------------------------------------------------- 1 | export const getStaticPaths = () => { 2 | return []; 3 | }, foo = 2 4 | 5 | export const getStaticProps = function() { 6 | return { props: {} }; 7 | } 8 | 9 | export default function Test() { 10 | return
; 11 | } 12 | -------------------------------------------------------------------------------- /examples/reactions/src/app.config.ts: -------------------------------------------------------------------------------- 1 | export default defineAppConfig({ 2 | pages: [ 3 | 'pages/index/index' 4 | ], 5 | window: { 6 | backgroundTextStyle: 'light', 7 | navigationBarBackgroundColor: '#fff', 8 | navigationBarTitleText: 'WeChat', 9 | navigationBarTextStyle: 'black' 10 | } 11 | }) 12 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/basics/performance.ts: -------------------------------------------------------------------------------- 1 | import {unsupported} from '../_util' 2 | 3 | /** 4 | * 小程序测速上报。使用前,需要在小程序管理后台配置。 5 | */ 6 | export const reportPerformance = unsupported._void('reportPerformance') 7 | 8 | /** 9 | * 获取当前小程序性能相关的信息。 10 | */ 11 | export const getPerformance = unsupported._void('getPerformance') 12 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/not-mix-up-bindings/code.js: -------------------------------------------------------------------------------- 1 | function Function1() { 2 | return { 3 | a: function bug(a) { 4 | return 2; 5 | }, 6 | }; 7 | } 8 | 9 | function Function2() { 10 | var bug = 1; 11 | return { 12 | bug, 13 | }; 14 | } 15 | 16 | export { getStaticProps } from 'a'; 17 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "npmClient": "yarn", 3 | "useWorkspaces": true, 4 | "packages": [ 5 | "packages/*" 6 | ], 7 | "command": { 8 | "publish": { 9 | "npmClient": "npm", 10 | "registry": "https://registry.npmjs.org/" 11 | } 12 | }, 13 | "version": "2.0.3" 14 | } 15 | -------------------------------------------------------------------------------- /examples/reactions/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "miniprogramRoot": "./dist", 3 | "projectname": "data", 4 | "description": "数据请求示例", 5 | "appid": "touristappid", 6 | "setting": { 7 | "urlCheck": true, 8 | "es6": false, 9 | "postcss": false, 10 | "minified": false 11 | }, 12 | "compileType": "miniprogram" 13 | } 14 | -------------------------------------------------------------------------------- /packages/components/src/form/formContext.ts: -------------------------------------------------------------------------------- 1 | import {createContext} from 'react' 2 | 3 | export interface FormContextProps { 4 | subscribe(cb: () => void): void 5 | collect(name: string | undefined, value: any) 6 | } 7 | 8 | const FormContext = createContext(null) 9 | 10 | export default FormContext 11 | -------------------------------------------------------------------------------- /examples/data-fetch/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "miniprogramRoot": "./dist", 3 | "projectname": "data", 4 | "description": "数据请求示例", 5 | "appid": "touristappid", 6 | "setting": { 7 | "urlCheck": true, 8 | "es6": false, 9 | "postcss": false, 10 | "minified": false 11 | }, 12 | "compileType": "miniprogram" 13 | } 14 | -------------------------------------------------------------------------------- /examples/dynamic-routing/project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "miniprogramRoot": "./dist", 3 | "projectname": "data", 4 | "description": "数据请求示例", 5 | "appid": "touristappid", 6 | "setting": { 7 | "urlCheck": true, 8 | "es6": false, 9 | "postcss": false, 10 | "minified": false 11 | }, 12 | "compileType": "miniprogram" 13 | } 14 | -------------------------------------------------------------------------------- /examples/data-fetch/src/app.config.ts: -------------------------------------------------------------------------------- 1 | export default defineAppConfig({ 2 | pages: [ 3 | 'pages/index/index', 4 | 'pages/stars/index' 5 | ], 6 | window: { 7 | backgroundTextStyle: 'light', 8 | navigationBarBackgroundColor: '#fff', 9 | navigationBarTitleText: 'WeChat', 10 | navigationBarTextStyle: 'black' 11 | } 12 | }) 13 | -------------------------------------------------------------------------------- /examples/dynamic-routing/src/app.config.ts: -------------------------------------------------------------------------------- 1 | export default defineAppConfig({ 2 | pages: [ 3 | 'pages/index/index', 4 | 'pages/post/index' 5 | ], 6 | window: { 7 | backgroundTextStyle: 'light', 8 | navigationBarBackgroundColor: '#fff', 9 | navigationBarTitleText: 'WeChat', 10 | navigationBarTextStyle: 'black' 11 | } 12 | }) 13 | -------------------------------------------------------------------------------- /packages/nextjs/template/src/app.jsx: -------------------------------------------------------------------------------- 1 | import {Component} from 'react' 2 | 3 | class App extends Component { 4 | componentDidMount() {} 5 | 6 | componentDidShow() {} 7 | 8 | componentDidHide() {} 9 | 10 | componentDidCatchError() {} 11 | 12 | render() { 13 | return this.props.children 14 | } 15 | } 16 | 17 | export default App 18 | -------------------------------------------------------------------------------- /tests/__fixtures__/getNextExportedFunctions/function.js: -------------------------------------------------------------------------------- 1 | export async function getStaticPaths() { 2 | return { 3 | paths: [], 4 | fallback: 'blocking' 5 | } 6 | } 7 | 8 | export async function getStaticProps() { 9 | return { 10 | revalidate: 60, 11 | props: { 12 | data: {} 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/destructuring-assignment-array/code.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import other from 'other'; 3 | 4 | const [a, b, ...rest]= fs.promises; 5 | const [foo, bar] = other; 6 | 7 | export async function getStaticProps() { 8 | a; 9 | b; 10 | rest; 11 | bar; 12 | } 13 | export default function Home() { return
; } 14 | -------------------------------------------------------------------------------- /tests/__fixtures__/getNextExportedFunctions/variable.js: -------------------------------------------------------------------------------- 1 | export const getStaticPaths = async () => { 2 | return { 3 | paths: [], 4 | fallback: 'blocking' 5 | } 6 | } 7 | 8 | export const getStaticProps = async () => { 9 | return { 10 | revalidate: 60, 11 | props: { 12 | data: {} 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/basics/update.ts: -------------------------------------------------------------------------------- 1 | import {unsupported} from '../_util' 2 | 3 | /** 4 | * 更新客户端版本。当判断用户小程序所在客户端版本过低时,可使用该接口跳转到更新微信页面。 5 | */ 6 | export const updateWeChatApp = unsupported._void('updateWeChatApp') 7 | 8 | /** 9 | * 获取全局唯一的版本更新管理器,用于管理小程序更新。关于小程序的更新机制,可以查看运行机制文档。 10 | */ 11 | export const getUpdateManager = unsupported._void('getUpdateManager') 12 | -------------------------------------------------------------------------------- /examples/dynamic-routing/README.md: -------------------------------------------------------------------------------- 1 | # 动态路由示例 2 | 3 | 这个例子展示如何使用动态路由。它包含两个动态路由: 4 | 5 | 1. pages/post/[id]/index.tsx 6 | * 例如,匹配 /post?id=my-example 7 | 2. pages/comment/[id]/[comment].tsx 8 | * 例如,匹配 /comment?id=my-example&comment=a-comment 9 | 10 | ## 执行 Next.js 11 | 12 | ```bash 13 | yarn dev:nextjs 14 | ``` 15 | 16 | ## 执行小程序 17 | 18 | ```bash 19 | yarn dev:swan 20 | ``` 21 | -------------------------------------------------------------------------------- /packages/components/src/image/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .wrap { 2 | margin-top: 20px; 3 | } 4 | .image-area { 5 | width: 100%; 6 | height: 155px; 7 | } 8 | 9 | .bottom-description { 10 | height: auto; 11 | margin: 17px; 12 | } 13 | 14 | .back-ground { 15 | background-color: #e6e6e6; 16 | } 17 | 18 | .image-custom { 19 | width: 100%; 20 | margin-bottom: -4px; 21 | } 22 | -------------------------------------------------------------------------------- /tests/babel/taro-import-plugin/index.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default 3 | const taroImportPlugin = require('tarojs-plugin-platform-nextjs/babel/taro-import-plugin') 4 | 5 | pluginTester({ 6 | plugin: taroImportPlugin, 7 | pluginName: 'taro-import-plugin', 8 | fixtures: path.join(__dirname, '__fixtures__') 9 | }) 10 | -------------------------------------------------------------------------------- /examples/dynamic-routing/src/pages/post/view.tsx: -------------------------------------------------------------------------------- 1 | import {useRouter} from '@tarojs/taro' 2 | import {View} from '@tarojs/components' 3 | 4 | const PostView = () => { 5 | const {id, comment} = useRouter().params 6 | return ( 7 | <> 8 | Post: {id} 9 | Comment: {comment} 10 | 11 | ) 12 | } 13 | 14 | export default PostView 15 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/remove-re-exported-function-dependents-variables-functions-imports/output.js: -------------------------------------------------------------------------------- 1 | import keep_me from "hello"; 2 | import { keep_me2 } from "hello2"; 3 | import * as keep_me3 from "hello3"; 4 | import { but_not_me } from "bar"; 5 | var leave_me_alone = 1; 6 | 7 | function dont_bug_me_either() {} 8 | 9 | export default function Test() { 10 | return
; 11 | } 12 | -------------------------------------------------------------------------------- /packages/nextjs/template/postcss.config.ejs: -------------------------------------------------------------------------------- 1 | const withTaro = require('tarojs-plugin-platform-nextjs/postcss') 2 | 3 | module.exports = withTaro(<%- designWidth %>, <%- autoprefixerOption %>)({ 4 | plugins: [ 5 | <%_ for (const {request, option} of plugins) { _%> 6 | [require.resolve(<%- JSON.stringify(request) -%>), <%- JSON.stringify(option) -%>], 7 | <%_ } _%> 8 | ] 9 | }) 10 | -------------------------------------------------------------------------------- /examples/reactions/src/app.ts: -------------------------------------------------------------------------------- 1 | import { Component } from 'react' 2 | import './app.scss' 3 | 4 | class App extends Component { 5 | 6 | componentDidMount () {} 7 | 8 | componentDidShow () {} 9 | 10 | componentDidHide () {} 11 | 12 | componentDidCatchError () {} 13 | 14 | // this.props.children 是将要会渲染的页面 15 | render () { 16 | return this.props.children 17 | } 18 | } 19 | 20 | export default App 21 | -------------------------------------------------------------------------------- /examples/data-fetch/src/app.ts: -------------------------------------------------------------------------------- 1 | import { Component } from 'react' 2 | import './app.scss' 3 | 4 | class App extends Component { 5 | 6 | componentDidMount () {} 7 | 8 | componentDidShow () {} 9 | 10 | componentDidHide () {} 11 | 12 | componentDidCatchError () {} 13 | 14 | // this.props.children 是将要会渲染的页面 15 | render () { 16 | return this.props.children 17 | } 18 | } 19 | 20 | export default App 21 | -------------------------------------------------------------------------------- /packages/components/src/style/index.scss: -------------------------------------------------------------------------------- 1 | @import '~weui/dist/style/weui.min.css'; 2 | 3 | body, html { 4 | width: 100%; 5 | margin: 0; 6 | padding: 0; 7 | font-family: STHeiti SC, Microsoft YaHei, Helvetica Neue, Helvetica, Arial, "sans-serif"; 8 | user-select: none; 9 | } 10 | 11 | ::-webkit-scrollbar { 12 | display: none; 13 | } 14 | 15 | * { 16 | margin: 0; 17 | padding: 0; 18 | } 19 | -------------------------------------------------------------------------------- /examples/dynamic-routing/src/app.ts: -------------------------------------------------------------------------------- 1 | import { Component } from 'react' 2 | import './app.scss' 3 | 4 | class App extends Component { 5 | 6 | componentDidMount () {} 7 | 8 | componentDidShow () {} 9 | 10 | componentDidHide () {} 11 | 12 | componentDidCatchError () {} 13 | 14 | // this.props.children 是将要会渲染的页面 15 | render () { 16 | return this.props.children 17 | } 18 | } 19 | 20 | export default App 21 | -------------------------------------------------------------------------------- /packages/components/src/icon/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .icon-area { 2 | margin-top: 15px; 3 | } 4 | 5 | .icon-item { 6 | display: inline-block; 7 | flex-direction: column; 8 | width: 80px; 9 | height: 95px; 10 | margin: 7px; 11 | text-align: center; 12 | 13 | justify-content: center; 14 | } 15 | 16 | .icon-text { 17 | width: 80px; 18 | margin-top: 15px; 19 | word-break: break-all; 20 | } 21 | -------------------------------------------------------------------------------- /tests/babel/next-ssg-plugin/__fixtures__/destructuring-assignment-object/code.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import other from 'other'; 3 | 4 | const {readFile, readdir, access: foo} = fs.promises; 5 | const {a,b, cat: bar,...rem} = other; 6 | 7 | export async function getStaticProps() { 8 | readFile; 9 | readdir; 10 | foo; 11 | b; 12 | cat; 13 | rem; 14 | } 15 | export default function Home() { return
; } 16 | -------------------------------------------------------------------------------- /examples/data-fetch/src/pages/index/index.h5.tsx: -------------------------------------------------------------------------------- 1 | import {request} from '@tarojs/taro' 2 | export {default} from './view'; 3 | 4 | export async function getStaticProps() { 5 | const res = await request({ 6 | method: 'GET', 7 | url: 'https://api.github.com/repos/NervJS/taro' 8 | }) 9 | 10 | return { 11 | props: { 12 | stars: res.data.stargazers_count 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/data-fetch/src/pages/stars/index.h5.tsx: -------------------------------------------------------------------------------- 1 | import {request} from '@tarojs/taro' 2 | 3 | export {default} from './view'; 4 | 5 | export async function getStaticProps() { 6 | const res = await request({ 7 | method: 'GET', 8 | url: 'https://api.github.com/repos/NervJS/tarojs-plugin-platform-nextjs' 9 | }) 10 | 11 | return { 12 | props: { 13 | stars: res.data.stargazers_count 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/basics/debug.ts: -------------------------------------------------------------------------------- 1 | import {unsupported} from '../_util' 2 | 3 | /** 4 | * 设置是否打开调试开关,此开关对正式版也能生效。 5 | */ 6 | export const setEnableDebug = unsupported._void('setEnableDebug') 7 | 8 | /** 9 | * 获取实时日志管理器对象。 10 | */ 11 | export const getRealtimeLogManager = unsupported._void('getRealtimeLogManager') 12 | 13 | /** 14 | * 获取日志管理器对象。 15 | */ 16 | export const getLogManager = unsupported._void('getLogManager') 17 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/index.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default 3 | const taroRouterPlugin = require('tarojs-plugin-platform-nextjs/babel/class-component-taro-router-plugin') 4 | 5 | pluginTester({ 6 | plugin: taroRouterPlugin, 7 | pluginName: 'class-component-taro-router-plugin', 8 | fixtures: path.join(__dirname, '__fixtures__') 9 | }) 10 | -------------------------------------------------------------------------------- /examples/data-fetch/src/app.scss: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 16px!important; 3 | margin: 8px!important; 4 | font-family: Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji!important; 5 | line-height: 1.5!important; 6 | } 7 | 8 | .paragraph { 9 | margin: 16px 0 16px; 10 | } 11 | 12 | .taro-nav { 13 | text-decoration: underline!important; 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": false, 4 | "noEmit": true, 5 | "allowJs": true, 6 | "jsx": "react-jsx", 7 | "module": "esnext", 8 | "target": "esnext", 9 | "skipLibCheck": true, 10 | "esModuleInterop": true, 11 | "moduleResolution": "node", 12 | "baseUrl": "." 13 | }, 14 | "include": [ 15 | "tests/**/*" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /examples/dynamic-routing/src/app.scss: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 16px!important; 3 | margin: 8px!important; 4 | font-family: Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji!important; 5 | line-height: 1.5!important; 6 | } 7 | 8 | .paragraph { 9 | margin: 16px 0 16px; 10 | } 11 | 12 | .taro-nav { 13 | text-decoration: underline!important; 14 | } 15 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/__fixtures__/method/code.js: -------------------------------------------------------------------------------- 1 | import Taro from "@tarojs/taro"; 2 | 3 | export default class Index extends Component { 4 | constructor(props) { 5 | super(props) 6 | const $instance = Taro.getCurrentInstance(); 7 | console.log($instance); 8 | } 9 | 10 | render() { 11 | const $instance = Taro.getCurrentInstance(); 12 | console.log($instance); 13 | return null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/device/phone.ts: -------------------------------------------------------------------------------- 1 | import promisify from 'mpromisify' 2 | import {limited} from '../_util' 3 | import type * as swan from '../swan' 4 | 5 | const makePhoneCallInternal: typeof swan.makePhoneCall = ({phoneNumber, success, complete}) => { 6 | location.href = `tel:${phoneNumber}` 7 | success?.() 8 | complete?.() 9 | } 10 | 11 | export const makePhoneCall = promisify(limited.async('makePhoneCall', makePhoneCallInternal)) 12 | -------------------------------------------------------------------------------- /packages/components/src/scroll-view/style/index.scss: -------------------------------------------------------------------------------- 1 | .taro-scroll { 2 | -webkit-overflow-scrolling: auto; 3 | } 4 | 5 | .taro-scroll::-webkit-scrollbar { 6 | display: none; 7 | } 8 | 9 | .taro-scroll-view { 10 | overflow: hidden; 11 | } 12 | 13 | .taro-scroll-view__scroll-x { 14 | overflow-x: scroll; 15 | overflow-y: hidden; 16 | } 17 | 18 | .taro-scroll-view__scroll-y { 19 | overflow-x: hidden; 20 | overflow-y: scroll; 21 | } 22 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/_util/typings.ts: -------------------------------------------------------------------------------- 1 | export interface TaroRouter = Record> { 2 | /** 3 | * 路由参数。 4 | */ 5 | params: T 6 | 7 | /** 8 | * 页面路径。 9 | */ 10 | path: string 11 | } 12 | 13 | export interface TaroPage { 14 | data?: Record 15 | route?: string 16 | options?: Record 17 | } 18 | 19 | export type CustomRoutes = Record 20 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/__fixtures__/property/output.js: -------------------------------------------------------------------------------- 1 | import { withRouter } from "tarojs-plugin-platform-nextjs/router"; 2 | import Taro from "@tarojs/taro"; 3 | 4 | let _Index; 5 | 6 | class Index extends Component { 7 | $instance = Taro.getCurrentInstance({ 8 | type: "class", 9 | component: this, 10 | }); 11 | 12 | render() { 13 | return null; 14 | } 15 | } 16 | 17 | _Index = withRouter(Index); 18 | export { _Index as default }; 19 | -------------------------------------------------------------------------------- /tests/babel/next-app-plugin/__fixtures__/basic/code.js: -------------------------------------------------------------------------------- 1 | import Head from "next/head"; 2 | import TaroApp from "./app"; 3 | 4 | const MyApp = ({Component, pageProps}) => ( 5 | <> 6 | 7 | 11 | 12 | 13 | 14 | 15 | 16 | ) 17 | 18 | export default MyApp 19 | -------------------------------------------------------------------------------- /packages/components/src/mask/style/index.scss: -------------------------------------------------------------------------------- 1 | .taro-mask { 2 | position: fixed; 3 | top: 0; 4 | left: 0; 5 | display: block; 6 | width: 100%; 7 | height: 100%; 8 | z-index: 1000; 9 | 10 | &_button { 11 | position: absolute; 12 | top: 0; 13 | right: 0; 14 | left: 0; 15 | bottom: 0; 16 | background: #000; 17 | 18 | &-transparent { 19 | background: transparent; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/data-fetch/src/pages/index/view.tsx: -------------------------------------------------------------------------------- 1 | import {View, Navigator} from '@tarojs/components' 2 | 3 | const IndexView = ({ stars }) => ( 4 | <> 5 | Tarojs has {stars} ⭐️ 6 | 11 | How about tarojs-plugin-platform-nextjs? 12 | 13 | 14 | ) 15 | 16 | export default IndexView 17 | -------------------------------------------------------------------------------- /tests/babel/taro-app-plugin/index.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default 3 | const taroAppPlugin = require('tarojs-plugin-platform-nextjs/babel/taro-app-plugin') 4 | 5 | pluginTester({ 6 | plugin: taroAppPlugin, 7 | pluginName: 'taro-app-plugin', 8 | pluginOptions: { 9 | outputAppFilePath: path.join(__dirname, '__fixtures__/basic/code.js') 10 | }, 11 | fixtures: path.join(__dirname, '__fixtures__') 12 | }) 13 | -------------------------------------------------------------------------------- /packages/components/src/rich-text/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .rich-text { 2 | font-size: 16px; 3 | margin-left: 17px; 4 | } 5 | 6 | .p { 7 | color: #4F99FB; 8 | line-height: 48px; 9 | } 10 | 11 | .taro-scroll-view { 12 | width: 100%; 13 | height: 215px; 14 | background-color: #FFF; 15 | box-sizing: border-box; 16 | line-height: 30px; 17 | } 18 | .cont { 19 | width: 100%; 20 | height: 100%; 21 | white-space: pre; 22 | padding: 10px 16px; 23 | color: #999; 24 | } 25 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/dom/index.ts: -------------------------------------------------------------------------------- 1 | import {unsupported, limited} from '../_util' 2 | import {SelectorQuery} from './selectorQuery' 3 | 4 | const createSelectorQueryInternal = () => new SelectorQuery() 5 | 6 | /** 7 | * 返回一个 SelectorQuery 对象实例 8 | */ 9 | export const createSelectorQuery = limited.never('createSelectorQuery', createSelectorQueryInternal) 10 | 11 | /** 12 | * 创建并返回一个 IntersectionObserver 对象实例。 13 | */ 14 | export const createIntersectionObserver = unsupported.never('createIntersectionObserver') 15 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/_util/dom.ts: -------------------------------------------------------------------------------- 1 | export function createInput(sourceType: string[]): HTMLInputElement { 2 | const el = document.createElement('input') 3 | el.setAttribute('type', 'file') 4 | // 仅能限制只通过相机拍摄,不能限制只允许从相册选择 5 | if (sourceType.length === 1 && sourceType[0] === 'camera') { 6 | el.setAttribute('capture', 'environment') 7 | } 8 | el.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;') 9 | document.body.appendChild(el) 10 | return el 11 | } 12 | -------------------------------------------------------------------------------- /tests/babel/next-app-plugin/__fixtures__/basic/output.js: -------------------------------------------------------------------------------- 1 | import "../../app.scss"; 2 | import Head from "next/head"; 3 | import TaroApp from "./app"; 4 | 5 | const MyApp = ({ Component, pageProps }) => ( 6 | <> 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | ); 18 | 19 | export default MyApp; 20 | -------------------------------------------------------------------------------- /packages/nextjs/babel/after.js: -------------------------------------------------------------------------------- 1 | function afterPreset(api, options = {}) { 2 | const isServer = api.caller(caller => !!caller && caller.isServer) 3 | const {taroPages} = options 4 | 5 | return { 6 | sourceType: 'unambiguous', 7 | plugins: [ 8 | !isServer && [ 9 | require.resolve('tarojs-plugin-platform-nextjs/babel/taro-ssg-plugin'), 10 | {taroPages} 11 | ] 12 | ].filter(Boolean) 13 | } 14 | } 15 | 16 | module.exports = afterPreset 17 | -------------------------------------------------------------------------------- /examples/data-fetch/global.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module '*.png'; 4 | declare module '*.gif'; 5 | declare module '*.jpg'; 6 | declare module '*.jpeg'; 7 | declare module '*.svg'; 8 | declare module '*.css'; 9 | declare module '*.less'; 10 | declare module '*.scss'; 11 | declare module '*.sass'; 12 | declare module '*.styl'; 13 | 14 | declare namespace NodeJS { 15 | interface ProcessEnv { 16 | TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd' 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/reactions/global.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module '*.png'; 4 | declare module '*.gif'; 5 | declare module '*.jpg'; 6 | declare module '*.jpeg'; 7 | declare module '*.svg'; 8 | declare module '*.css'; 9 | declare module '*.less'; 10 | declare module '*.scss'; 11 | declare module '*.sass'; 12 | declare module '*.styl'; 13 | 14 | declare namespace NodeJS { 15 | interface ProcessEnv { 16 | TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd' 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/dynamic-routing/global.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module '*.png'; 4 | declare module '*.gif'; 5 | declare module '*.jpg'; 6 | declare module '*.jpeg'; 7 | declare module '*.svg'; 8 | declare module '*.css'; 9 | declare module '*.less'; 10 | declare module '*.scss'; 11 | declare module '*.sass'; 12 | declare module '*.styl'; 13 | 14 | declare namespace NodeJS { 15 | interface ProcessEnv { 16 | TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd' 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/canvas/index.ts: -------------------------------------------------------------------------------- 1 | import { unsupported } from '../_util' 2 | 3 | // 画布 4 | 5 | /** 6 | * 创建离屏 canvas 实例 7 | */ 8 | export const createOffscreenCanvas = unsupported.never('createOffscreenCanvas') 9 | 10 | /** 创建 canvas 的绘图上下文 CanvasContext 对象 */ 11 | export * from './createCanvasContext' 12 | 13 | /** 把当前画布指定区域的内容导出生成指定大小的图片 */ 14 | export * from './canvasToTempFilePath' 15 | 16 | /** 将像素数据绘制到画布 */ 17 | export * from './canvasPutImageData' 18 | 19 | /** 获取 canvas 区域隐含的像素数据 */ 20 | export * from './canvasGetImageData' 21 | -------------------------------------------------------------------------------- /tests/babel/taro-import-plugin/__fixtures__/basic/code.js: -------------------------------------------------------------------------------- 1 | import { createElement, Component } from "react"; 2 | import Taro from "@tarojs/taro"; 3 | import { View } from "@tarojs/components"; 4 | 5 | class Index extends Component { 6 | handleClick() { 7 | Taro.navigateTo({ 8 | url: "/home", 9 | }); 10 | } 11 | 12 | render() { 13 | return createElement( 14 | View, 15 | { 16 | onClick: this.handleClick, 17 | }, 18 | "hello, world!" 19 | ); 20 | } 21 | } 22 | 23 | export default Index; 24 | -------------------------------------------------------------------------------- /examples/data-fetch/src/pages/stars/view.tsx: -------------------------------------------------------------------------------- 1 | import {View, Navigator} from '@tarojs/components' 2 | 3 | const TarojsPluginPlatformNextjsStarsView = ({ stars }) => ( 4 | <> 5 | tarojs-plugin-platform-nextjs has {stars} ⭐ 6 | 11 | I bet tarojs has more stars (?) 12 | 13 | 14 | ) 15 | 16 | export default TarojsPluginPlatformNextjsStarsView 17 | -------------------------------------------------------------------------------- /tests/integration/config/config/index.js: -------------------------------------------------------------------------------- 1 | const config = { 2 | sourceRoot: 'src', 3 | outputRoot: 'dist', 4 | projectName: 'config', 5 | framework: 'react', 6 | plugins: [ 7 | ['tarojs-plugin-platform-nextjs', { 8 | runNextjs: false, 9 | browser: false 10 | }] 11 | ] 12 | } 13 | 14 | module.exports = function (merge) { 15 | if (process.env.NODE_ENV === 'development') { 16 | return merge({}, config, require('./dev')) 17 | } 18 | 19 | return merge({}, config, require('./prod')) 20 | } 21 | -------------------------------------------------------------------------------- /tests/integration/watch/config/index.js: -------------------------------------------------------------------------------- 1 | const config = { 2 | sourceRoot: 'src', 3 | outputRoot: 'dist', 4 | projectName: 'config', 5 | framework: 'react', 6 | plugins: [ 7 | ['tarojs-plugin-platform-nextjs', { 8 | runNextjs: false, 9 | browser: false 10 | }] 11 | ] 12 | } 13 | 14 | module.exports = function (merge) { 15 | if (process.env.NODE_ENV === 'development') { 16 | return merge({}, config, require('./dev')) 17 | } 18 | 19 | return merge({}, config, require('./prod')) 20 | } 21 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/ui/navigationBar.ts: -------------------------------------------------------------------------------- 1 | export function setNavigationBarColor() { 2 | console.log('TODO: setNavigationBarColor') 3 | } 4 | 5 | export function showNavigationBarLoading() { 6 | console.log('TODO: showNavigationBarLoading') 7 | } 8 | 9 | export function hideNavigationBarLoading() { 10 | console.log('TODO: hideNavigationBarLoading') 11 | } 12 | 13 | export function setNavigationBarTitle() { 14 | console.log('TODO: setNavigationBarTitle') 15 | } 16 | 17 | export function hideHomeButton() { 18 | console.log('TODO: hideHomeButton') 19 | } 20 | -------------------------------------------------------------------------------- /packages/components/src/form/useField.ts: -------------------------------------------------------------------------------- 1 | import {useContext, useEffect} from 'react' 2 | import FormContext from './formContext' 3 | 4 | function useField(name: string | undefined, value: any): void { 5 | const formContext = useContext(FormContext) 6 | 7 | useEffect(() => { 8 | if (!formContext) { 9 | return 10 | } 11 | const unsubscribe = formContext.subscribe(() => { 12 | formContext.collect(name, value) 13 | }) 14 | return unsubscribe 15 | }, [name, value]) 16 | } 17 | 18 | export default useField 19 | -------------------------------------------------------------------------------- /packages/components/src/navigator/demos/demo2.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {View, Button, Navigator} from '@taror/components' 3 | 4 | const App: React.FC = () => ( 5 | 6 | 7 | 16 | 17 | 18 | ) 19 | 20 | export default App 21 | -------------------------------------------------------------------------------- /tests/babel/taro-import-plugin/__fixtures__/basic/output.js: -------------------------------------------------------------------------------- 1 | import { createElement, Component } from "react"; 2 | import Taro from "tarojs-plugin-platform-nextjs/taro"; 3 | import { View } from "tarojs-plugin-platform-nextjs/components/lib"; 4 | 5 | class Index extends Component { 6 | handleClick() { 7 | Taro.navigateTo({ 8 | url: "/home", 9 | }); 10 | } 11 | 12 | render() { 13 | return createElement( 14 | View, 15 | { 16 | onClick: this.handleClick, 17 | }, 18 | "hello, world!" 19 | ); 20 | } 21 | } 22 | 23 | export default Index; 24 | -------------------------------------------------------------------------------- /tests/utils.spec.ts: -------------------------------------------------------------------------------- 1 | import {unIndent} from 'tarojs-plugin-platform-nextjs/lib/utils' 2 | 3 | describe('utils', () => { 4 | it('unIndent', () => { 5 | expect(unIndent` 6 | function (a, b) { 7 | return a + b 8 | } 9 | `).toEqual('function (a, b) {\n return a + b\n}') 10 | 11 | const a = 'a' 12 | const b = 'b' 13 | expect(unIndent` 14 | function (${a}, ${b}) { 15 | return ${a} + ${b} 16 | } 17 | `).toEqual('function (a, b) {\n return a + b\n}') 18 | }) 19 | }) 20 | -------------------------------------------------------------------------------- /packages/components/src/navigator/demos/demo1.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {View, Button, Navigator} from '@taror/components' 3 | 4 | declare const BASE_PATH: string 5 | 6 | const App: React.FC = () => ( 7 | 8 | 17 | 18 | ) 19 | 20 | export default App 21 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/basics/index.ts: -------------------------------------------------------------------------------- 1 | import {fromByteArray, toByteArray} from 'base64-js' 2 | import {unsupported} from '../_util' 3 | 4 | /** 5 | * 判断智能小程序的 API ,回调,参数,组件等是否在当前版本和当前系统下可用。 6 | */ 7 | export const canIUse = unsupported.never('canIUse') 8 | 9 | /** 10 | * 将 ArrayBuffer 对象转成 Base64 字符串 11 | */ 12 | export const arrayBufferToBase64 = fromByteArray 13 | 14 | /** 15 | * 将 Base64 字符串转成 ArrayBuffer 对象 16 | */ 17 | export const base64ToArrayBuffer = toByteArray 18 | 19 | export * from './system' 20 | export * from './update' 21 | export * from './debug' 22 | export * from './performance' 23 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/ui/background.ts: -------------------------------------------------------------------------------- 1 | import promisify from 'mpromisify' 2 | import {unsupported, limited} from '../_util' 3 | import * as swan from '../swan' 4 | 5 | const setBackgroundColorInternal: typeof swan.setBackgroundColor = ({backgroundColor = '', success, complete}) => { 6 | document.documentElement.style.backgroundColor = backgroundColor 7 | success?.() 8 | complete?.() 9 | } 10 | 11 | export const setBackgroundColor = promisify(limited._void('setBackgroundColor', setBackgroundColorInternal)) 12 | 13 | export const setBackgroundTextStyle = unsupported._void('setBackgroundColor') 14 | -------------------------------------------------------------------------------- /examples/data-fetch/src/pages/index/index.tsx: -------------------------------------------------------------------------------- 1 | import {useEffect, useState} from 'react' 2 | import {request} from '@tarojs/taro' 3 | import IndexView from './view'; 4 | 5 | function Index() { 6 | const [stars, setStars] = useState() 7 | 8 | useEffect(() => { 9 | (async function () { 10 | const res = await request({ 11 | method: 'GET', 12 | url: 'https://api.github.com/repos/NervJS/taro' 13 | }) 14 | setStars(res.data.stargazers_count) 15 | })() 16 | }, []) 17 | 18 | return 19 | } 20 | 21 | export default Index 22 | -------------------------------------------------------------------------------- /tests/babel/next-app-plugin/index.spec.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const pluginTester = require('babel-plugin-tester').default 3 | const nextAppPlugin = require('tarojs-plugin-platform-nextjs/babel/next-app-plugin') 4 | 5 | pluginTester({ 6 | plugin: nextAppPlugin, 7 | pluginName: 'next-app-plugin', 8 | pluginOptions: { 9 | outputAppFilePath: path.join(__dirname, 'app.js'), 10 | nextAppFilePath: path.join(__dirname, '__fixtures__/basic/code.js') 11 | }, 12 | babelOptions: { 13 | plugins: ['@babel/plugin-syntax-jsx'] 14 | }, 15 | fixtures: path.join(__dirname, '__fixtures__') 16 | }) 17 | -------------------------------------------------------------------------------- /packages/nextjs/template/babel.config.ejs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ['tarojs-plugin-platform-nextjs/babel/after', { 4 | <%_ if (taroPages) { _%> 5 | taroPages: <%- taroPages %> 6 | <%_ } _%> 7 | }], 8 | 'next/babel', 9 | ['tarojs-plugin-platform-nextjs/babel/before', { 10 | <%_ if (nextAppFilePath) { _%> 11 | nextAppFilePath: <%- nextAppFilePath %>, 12 | <%_ } _%> 13 | <%_ if (outputAppFilePath) { _%> 14 | outputAppFilePath: <%- outputAppFilePath %> 15 | <%_ } _%> 16 | }] 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/canvas/createCanvasContext.ts: -------------------------------------------------------------------------------- 1 | import { findDOM } from '../_util' 2 | import { CanvasContext } from './CanvasContext' 3 | 4 | /** 5 | * 创建 canvas 的绘图上下文 CanvasContext 对象 6 | */ 7 | export const createCanvasContext = (canvasId, inst) => { 8 | const el = findDOM(inst) as HTMLElement 9 | const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement 10 | const ctx = canvas?.getContext('2d') as CanvasRenderingContext2D 11 | const context = new CanvasContext(canvas, ctx) 12 | if (!ctx) return context 13 | context.canvas = canvas 14 | context.ctx = ctx 15 | 16 | return context 17 | } 18 | -------------------------------------------------------------------------------- /examples/data-fetch/src/pages/stars/index.tsx: -------------------------------------------------------------------------------- 1 | import {useEffect, useState} from 'react' 2 | import {request} from '@tarojs/taro' 3 | import IndexView from './view'; 4 | 5 | function TarojsPluginPlatformNextjsStarsView() { 6 | const [stars, setStars] = useState() 7 | 8 | useEffect(() => { 9 | (async function() { 10 | const res = await request({ 11 | method: 'GET', 12 | url: 'https://api.github.com/repos/NervJS/tarojs-plugin-platform-nextjs' 13 | }) 14 | setStars(res.data.stargazers_count) 15 | })() 16 | }, []) 17 | 18 | return 19 | } 20 | 21 | export default TarojsPluginPlatformNextjsStarsView 22 | -------------------------------------------------------------------------------- /packages/components/src/textarea/forceHiddenStyles.ts: -------------------------------------------------------------------------------- 1 | const HIDDEN_TEXTAREA_STYLE = { 2 | 'min-height': '0', 3 | 'max-height': 'none', 4 | height: '0', 5 | visibility: 'hidden', 6 | overflow: 'hidden', 7 | position: 'absolute', 8 | 'z-index': '-1000', 9 | top: '0', 10 | right: '0' 11 | } as const 12 | 13 | const forceHiddenStyles = (node: HTMLElement) => { 14 | Object.keys(HIDDEN_TEXTAREA_STYLE).forEach((key) => { 15 | node.style.setProperty( 16 | key, 17 | HIDDEN_TEXTAREA_STYLE[key as keyof typeof HIDDEN_TEXTAREA_STYLE], 18 | 'important' 19 | ) 20 | }) 21 | } 22 | 23 | export default forceHiddenStyles 24 | -------------------------------------------------------------------------------- /packages/components/src/preview/style/index.scss: -------------------------------------------------------------------------------- 1 | .taro-preview { 2 | &_img { 3 | width: 100%; 4 | max-width: 100%; 5 | max-height: 100%; 6 | object-fit: contain; 7 | } 8 | 9 | &_swiper { 10 | position: absolute; 11 | top: 50%; 12 | width: 100%; 13 | height: fit-content; 14 | transform: translateY(-50%); 15 | 16 | &-item { 17 | display: flex; 18 | align-items: center; 19 | } 20 | } 21 | 22 | &_pagination { 23 | position: absolute; 24 | left: 20px; 25 | bottom: 30px; 26 | font-size: 16px; 27 | color: #fff; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/__fixtures__/method/output.js: -------------------------------------------------------------------------------- 1 | import { withRouter } from "tarojs-plugin-platform-nextjs/router"; 2 | import Taro from "@tarojs/taro"; 3 | 4 | let _Index; 5 | 6 | class Index extends Component { 7 | constructor(props) { 8 | super(props); 9 | const $instance = Taro.getCurrentInstance({ 10 | type: "class", 11 | component: this, 12 | }); 13 | console.log($instance); 14 | } 15 | 16 | render() { 17 | const $instance = Taro.getCurrentInstance({ 18 | type: "class", 19 | component: this, 20 | }); 21 | console.log($instance); 22 | return null; 23 | } 24 | } 25 | 26 | _Index = withRouter(Index); 27 | export { _Index as default }; 28 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/__fixtures__/trasformed/code.js: -------------------------------------------------------------------------------- 1 | import { withRouter } from "tarojs-plugin-platform-nextjs/router"; 2 | import Taro from "@tarojs/taro"; 3 | 4 | let _Index; 5 | 6 | class Index extends Component { 7 | constructor(props) { 8 | super(props); 9 | const $instance = Taro.getCurrentInstance({ 10 | type: "class", 11 | component: this, 12 | }); 13 | console.log($instance); 14 | } 15 | 16 | render() { 17 | const $instance = Taro.getCurrentInstance({ 18 | type: "class", 19 | component: this, 20 | }); 21 | console.log($instance); 22 | return null; 23 | } 24 | } 25 | 26 | _Index = withRouter(Index); 27 | export { _Index as default }; 28 | -------------------------------------------------------------------------------- /tests/babel/class-component-taro-router-plugin/__fixtures__/trasformed/output.js: -------------------------------------------------------------------------------- 1 | import { withRouter } from "tarojs-plugin-platform-nextjs/router"; 2 | import Taro from "@tarojs/taro"; 3 | 4 | let _Index; 5 | 6 | class Index extends Component { 7 | constructor(props) { 8 | super(props); 9 | const $instance = Taro.getCurrentInstance({ 10 | type: "class", 11 | component: this, 12 | }); 13 | console.log($instance); 14 | } 15 | 16 | render() { 17 | const $instance = Taro.getCurrentInstance({ 18 | type: "class", 19 | component: this, 20 | }); 21 | console.log($instance); 22 | return null; 23 | } 24 | } 25 | 26 | _Index = withRouter(Index); 27 | export { _Index as default }; 28 | -------------------------------------------------------------------------------- /packages/components/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "outDir": "lib", 5 | "strictNullChecks": true, 6 | "module": "esnext", 7 | "moduleResolution": "node", 8 | "esModuleInterop": true, 9 | "experimentalDecorators": true, 10 | "jsx": "react-jsx", 11 | "noUnusedParameters": true, 12 | "noUnusedLocals": true, 13 | "noImplicitAny": false, 14 | "target": "es6", 15 | "lib": [ 16 | "dom", 17 | "dom.iterable", 18 | "es2017" 19 | ], 20 | "skipLibCheck": true, 21 | "allowJs": true 22 | }, 23 | "include": [ 24 | "src/**/*" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /packages/components/.umirc.ts: -------------------------------------------------------------------------------- 1 | import {defineConfig} from 'dumi' 2 | 3 | const BASE_PATH = '/tarojs-plugin-platform-nextjs' 4 | 5 | export default defineConfig({ 6 | title: 'taror', 7 | base: BASE_PATH, 8 | outputPath: 'docs-dist', 9 | publicPath: `${BASE_PATH}/`, 10 | define: { 11 | BASE_PATH 12 | }, 13 | extraBabelPlugins: [ 14 | [ 15 | 'import', 16 | { 17 | libraryName: '@taror/components', 18 | libraryDirectory: 'src', 19 | style: true 20 | } 21 | ] 22 | ], 23 | themeConfig: { 24 | carrier: 'SyMind', 25 | hd: { 26 | rules: [{ mode: 'none' }] 27 | } 28 | } 29 | }) 30 | -------------------------------------------------------------------------------- /packages/components/src/_util/dom/requestIdleCallback.ts: -------------------------------------------------------------------------------- 1 | export const requestIdleCallback = (typeof globalThis !== 'undefined') && globalThis.requestIdleCallback 2 | || function (cb: IdleRequestCallback): number { 3 | const start = Date.now() 4 | return setTimeout(function () { 5 | cb({ 6 | didTimeout: false, 7 | timeRemaining: function () { 8 | return Math.max(0, 50 - (Date.now() - start)) 9 | } 10 | }) 11 | }, 1) as unknown as number 12 | } 13 | 14 | export const cancelIdleCallback = (typeof globalThis !== 'undefined') && globalThis.cancelIdleCallback 15 | || function (id: number) { 16 | return clearTimeout(id) 17 | } 18 | -------------------------------------------------------------------------------- /packages/nextjs/router/src/index.tsx: -------------------------------------------------------------------------------- 1 | import {forwardRef, ForwardRefExoticComponent, ComponentClass} from 'react' 2 | import {useRouter} from 'next/router' 3 | 4 | export function withRouter( 5 | ComposedComponent: ComponentClass 6 | ): ForwardRefExoticComponent { 7 | const WithRouterWrapper = forwardRef((props, ref) => { 8 | const router = useRouter() 9 | return 10 | }) 11 | 12 | if (process.env.NODE_ENV !== 'production') { 13 | const name = ComposedComponent.displayName || ComposedComponent.name || 'Unknown' 14 | WithRouterWrapper.displayName = `withRouter(${name})` 15 | } 16 | 17 | return WithRouterWrapper 18 | } 19 | -------------------------------------------------------------------------------- /packages/components/src/view/index.tsx: -------------------------------------------------------------------------------- 1 | import React, {forwardRef} from 'react' 2 | import {TaroHoverableProps} from '../_util/typings' 3 | import useTaroHoverableEvents from '../_util/hooks/useTaroHoverableEvents' 4 | 5 | export interface ViewProps extends TaroHoverableProps { 6 | /** 7 | * View 内容 8 | */ 9 | children?: React.ReactNode 10 | } 11 | 12 | const View: React.ForwardRefRenderFunction = ({ 13 | children, 14 | ...rest 15 | }, ref) => { 16 | const props = useTaroHoverableEvents(rest, 'none') 17 | 18 | return ( 19 |
23 | {children} 24 |
25 | ) 26 | } 27 | 28 | export default forwardRef(View) 29 | -------------------------------------------------------------------------------- /tests/integration/dynamic-routing/config/index.js: -------------------------------------------------------------------------------- 1 | const config = { 2 | sourceRoot: 'src', 3 | outputRoot: 'dist', 4 | projectName: 'config', 5 | framework: 'react', 6 | plugins: [ 7 | ['tarojs-plugin-platform-nextjs', { 8 | runNextjs: false, 9 | browser: false 10 | }] 11 | ], 12 | h5: { 13 | router: { 14 | mode: 'browser', 15 | customRoutes: { 16 | '/pages/post/index': '/post' 17 | } 18 | } 19 | } 20 | } 21 | 22 | module.exports = function (merge) { 23 | if (process.env.NODE_ENV === 'development') { 24 | return merge({}, config, require('./dev')) 25 | } 26 | 27 | return merge({}, config, require('./prod')) 28 | } 29 | -------------------------------------------------------------------------------- /packages/components/src/form/demos/demo1.scss: -------------------------------------------------------------------------------- 1 | .switch-scroll { 2 | margin: 17px!important; 3 | } 4 | 5 | .block { 6 | margin: 0 17px; 7 | padding: 17px 0; 8 | display: block; 9 | background-color: #fff; 10 | } 11 | 12 | .switch-text { 13 | vertical-align: 2px; 14 | } 15 | 16 | .radio-item { 17 | padding: 15px 0; 18 | margin: 0 15px; 19 | } 20 | 21 | .checkbox-item { 22 | padding: 15px 0; 23 | margin: 0 15px; 24 | display: block; 25 | } 26 | 27 | .input { 28 | height: 51px; 29 | margin: 0; 30 | } 31 | 32 | .plh { 33 | line-height: 18px; 34 | color: #CCC; 35 | font-family: PingFangSC-Regular; 36 | } 37 | 38 | .slider { 39 | margin: 3px; 40 | } 41 | 42 | .ipt { 43 | height: 51px; 44 | margin: 0 17px; 45 | } 46 | -------------------------------------------------------------------------------- /examples/data-fetch/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "removeComments": false, 6 | "preserveConstEnums": true, 7 | "moduleResolution": "node", 8 | "experimentalDecorators": true, 9 | "noImplicitAny": false, 10 | "allowSyntheticDefaultImports": true, 11 | "outDir": "lib", 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "strictNullChecks": true, 15 | "sourceMap": true, 16 | "baseUrl": ".", 17 | "rootDir": ".", 18 | "jsx": "react-jsx", 19 | "allowJs": true, 20 | "resolveJsonModule": true, 21 | "typeRoots": [ 22 | "node_modules/@types" 23 | ] 24 | }, 25 | "include": ["./src", "global.d.ts"], 26 | "compileOnSave": false 27 | } 28 | -------------------------------------------------------------------------------- /examples/reactions/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "removeComments": false, 6 | "preserveConstEnums": true, 7 | "moduleResolution": "node", 8 | "experimentalDecorators": true, 9 | "noImplicitAny": false, 10 | "allowSyntheticDefaultImports": true, 11 | "outDir": "lib", 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "strictNullChecks": true, 15 | "sourceMap": true, 16 | "baseUrl": ".", 17 | "rootDir": ".", 18 | "jsx": "react-jsx", 19 | "allowJs": true, 20 | "resolveJsonModule": true, 21 | "typeRoots": [ 22 | "node_modules/@types" 23 | ] 24 | }, 25 | "include": ["./src", "global.d.ts"], 26 | "compileOnSave": false 27 | } 28 | -------------------------------------------------------------------------------- /examples/dynamic-routing/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "removeComments": false, 6 | "preserveConstEnums": true, 7 | "moduleResolution": "node", 8 | "experimentalDecorators": true, 9 | "noImplicitAny": false, 10 | "allowSyntheticDefaultImports": true, 11 | "outDir": "lib", 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "strictNullChecks": true, 15 | "sourceMap": true, 16 | "baseUrl": ".", 17 | "rootDir": ".", 18 | "jsx": "react-jsx", 19 | "allowJs": true, 20 | "resolveJsonModule": true, 21 | "typeRoots": [ 22 | "node_modules/@types" 23 | ] 24 | }, 25 | "include": ["./src", "global.d.ts"], 26 | "compileOnSave": false 27 | } 28 | -------------------------------------------------------------------------------- /packages/nextjs/build/getTSCommonConfig.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const merge = require('lodash/merge') 3 | const {getPluginProjectPath} = require('./projectHelper') 4 | 5 | module.exports = function () { 6 | let my = {} 7 | const pluginProjectPath = getPluginProjectPath('tsconfig.json') 8 | if (fs.existsSync(pluginProjectPath)) { 9 | my = require(pluginProjectPath) 10 | } 11 | return merge( 12 | my.compilerOptions, 13 | { 14 | noUnusedParameters: true, 15 | noUnusedLocals: true, 16 | strictNullChecks: true, 17 | target: 'es6', 18 | jsx: 'preserve', 19 | module: 'commonjs', 20 | moduleResolution: 'node', 21 | allowSyntheticDefaultImports: true 22 | } 23 | ) 24 | } 25 | -------------------------------------------------------------------------------- /packages/nextjs/src/taroUtils/mergeTaroPages.ts: -------------------------------------------------------------------------------- 1 | import {ensureLeadingSlash} from '../utils' 2 | 3 | interface SubPackages { 4 | root: string 5 | pages: string[] 6 | } 7 | 8 | export function mergeTaroPages(pages?: string[], subPackages?: SubPackages): string[] { 9 | const taroPages: string[] = [] 10 | if (Array.isArray(pages)) { 11 | for (const page of pages) { 12 | taroPages.push(ensureLeadingSlash(page)) 13 | } 14 | } 15 | if (Array.isArray(subPackages)) { 16 | for (const pkg of subPackages) { 17 | if (Array.isArray(pkg.pages)) { 18 | for (const page of pkg.pages) { 19 | taroPages.push(ensureLeadingSlash(`${pkg.root}/${page}`)) 20 | } 21 | } 22 | } 23 | } 24 | return taroPages 25 | } 26 | -------------------------------------------------------------------------------- /packages/nextjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "outDir": "lib", 5 | "strictNullChecks": true, 6 | "module": "esnext", 7 | "moduleResolution": "node", 8 | "esModuleInterop": true, 9 | "experimentalDecorators": true, 10 | "jsx": "react-jsx", 11 | "noUnusedParameters": true, 12 | "noUnusedLocals": true, 13 | "noImplicitAny": false, 14 | "target": "es6", 15 | "lib": [ 16 | "dom", 17 | "dom.iterable", 18 | "es2017" 19 | ], 20 | "skipLibCheck": true, 21 | "allowJs": true 22 | }, 23 | "include": [ 24 | "src/**/*", 25 | "taro/src/**/*", 26 | "router/src/**/*", 27 | "components/src/**/*" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /packages/nextjs/taro/src/router.ts: -------------------------------------------------------------------------------- 1 | import promisify from 'mpromisify' 2 | import {getTaroApp} from './internal' 3 | import swan from './swan' 4 | 5 | export function switchTab() { 6 | } 7 | 8 | export function reLaunch(param: swan.reLaunch.Param) { 9 | const taroApp = getTaroApp() 10 | return promisify(taroApp.reLaunch)(param) 11 | } 12 | 13 | export function redirectTo(param: swan.redirectTo.Param) { 14 | const taroApp = getTaroApp() 15 | return promisify(taroApp.redirectTo)(param) 16 | } 17 | 18 | export function navigateTo(param: swan.navigateTo.Param) { 19 | const taroApp = getTaroApp() 20 | return promisify(taroApp.navigateTo)(param) 21 | } 22 | 23 | export function navigateBack(param: swan.navigateBack.Param) { 24 | const taroApp = getTaroApp() 25 | return promisify(taroApp.navigateBack)(param) 26 | } 27 | -------------------------------------------------------------------------------- /packages/components/src/web-view/index.tsx: -------------------------------------------------------------------------------- 1 | import {forwardRef, ForwardRefRenderFunction} from 'react' 2 | 3 | export interface WebViewEvent { 4 | src: string 5 | } 6 | 7 | export interface WebViewProps { 8 | src: string 9 | onLoad?: (event: WebViewEvent) => void 10 | onError?: (event: WebViewEvent) => void 11 | } 12 | 13 | const WebView: ForwardRefRenderFunction = ({src, onLoad, onError}, ref) => ( 14 |