├── .prettierignore ├── example ├── react-vite │ ├── .gitignore │ ├── src │ │ ├── vite-env.d.ts │ │ ├── App.tsx │ │ ├── main.tsx │ │ └── index.css │ ├── _gitignore │ ├── vite.config.ts │ ├── index.html │ ├── tsconfig.json │ ├── package.json │ ├── deploy-vercel.js │ ├── public │ │ └── favicon.svg │ └── CHANGELOG.md ├── vanilla-ts │ ├── src │ │ ├── vite-env.d.ts │ │ ├── style.css │ │ └── main.ts │ ├── .gitignore │ ├── index.html │ ├── package.json │ ├── tsconfig.json │ ├── favicon.svg │ └── CHANGELOG.md ├── react-next │ ├── next.config.js │ ├── pages │ │ ├── index.tsx │ │ └── _app.tsx │ ├── next-env.d.ts │ ├── styles │ │ └── globals.css │ ├── tsconfig.json │ ├── README.md │ ├── package.json │ └── CHANGELOG.md └── vue-vite │ ├── postcss.config.cjs │ ├── src │ ├── main.ts │ ├── vite-env.d.ts │ ├── App.vue │ ├── components │ │ ├── Ready.vue │ │ ├── Fallback.vue │ │ └── Button.vue │ ├── style.css │ ├── hooks │ │ └── useNativeState.ts │ └── Home.vue │ ├── tsconfig.node.json │ ├── vite.config.ts │ ├── tailwind.config.cjs │ ├── .gitignore │ ├── index.html │ ├── tsconfig.json │ ├── package.json │ ├── README.md │ ├── public │ └── vite.svg │ └── CHANGELOG.md ├── .npmrc ├── pnpm-workspace.yaml ├── packages ├── debug-tools │ ├── src │ │ ├── vite-env.d.ts │ │ ├── hooks │ │ │ ├── index.tsx │ │ │ ├── theme.tsx │ │ │ └── request.tsx │ │ ├── api │ │ │ ├── common.ts │ │ │ └── preview.ts │ │ ├── main.tsx │ │ ├── components │ │ │ ├── Space.tsx │ │ │ ├── Inspector.tsx │ │ │ ├── Debuggable.tsx │ │ │ ├── SiteInfo.tsx │ │ │ ├── Tooltip.tsx │ │ │ ├── Modal.tsx │ │ │ └── CopyableScript.tsx │ │ ├── shim.d.ts │ │ ├── utils │ │ │ └── index.ts │ │ ├── server.ts │ │ └── app.tsx │ ├── bin.js │ ├── .gitignore │ ├── server │ │ └── package.json │ ├── index.html │ ├── README.md │ ├── tsconfig.json │ ├── vite.config.ts │ ├── CHANGELOG.md │ └── package.json ├── lib │ ├── src │ │ ├── index.ts │ │ ├── utils.ts │ │ ├── constant.ts │ │ └── debug.ts │ ├── debug │ │ └── package.json │ ├── README.md │ ├── package.json │ └── CHANGELOG.md ├── create │ ├── bin.js │ ├── README.md │ ├── package.json │ ├── CHANGELOG.md │ └── src │ │ ├── utils.ts │ │ └── index.ts ├── debug │ ├── bin.js │ ├── src │ │ ├── mincud │ │ │ ├── commands │ │ │ │ ├── index.ts │ │ │ │ ├── simulator.ts │ │ │ │ ├── adb.ts │ │ │ │ ├── incu.ts │ │ │ │ └── vscode.ts │ │ │ ├── StringMatcher.ts │ │ │ ├── server.ts │ │ │ ├── logToConsole.ts │ │ │ ├── client.ts │ │ │ └── openBrowser.ts │ │ └── index.ts │ ├── mincud │ │ └── cli │ │ │ └── package.json │ ├── package.json │ ├── README.md │ └── CHANGELOG.md ├── ui │ ├── src │ │ ├── orientation.ts │ │ ├── toast.ts │ │ ├── back-press.ts │ │ └── index.ts │ ├── README.md │ ├── package.json │ └── CHANGELOG.md ├── demos │ └── react-demo-shared │ │ ├── src │ │ ├── index.ts │ │ ├── mincu-bench.ts │ │ ├── Fallback.tsx │ │ ├── Button.tsx │ │ └── Modal.tsx │ │ ├── tsconfig.json │ │ ├── package.json │ │ └── CHANGELOG.md ├── react │ ├── src │ │ ├── index.ts │ │ └── components │ │ │ ├── Ready.tsx │ │ │ ├── Fallback.tsx │ │ │ └── ReadySSR.tsx │ ├── README.md │ ├── package.json │ └── CHANGELOG.md ├── hooks │ ├── src │ │ ├── index.ts │ │ ├── useAppReady.ts │ │ ├── useSafeArea.ts │ │ ├── useNativeState.ts │ │ └── useReady.ts │ ├── README.md │ ├── package.json │ └── CHANGELOG.md ├── core │ ├── README.md │ ├── package.json │ ├── src │ │ ├── channel.ts │ │ ├── types │ │ │ ├── ncuos.ts │ │ │ └── rn │ │ │ │ ├── orientation.ts │ │ │ │ ├── index.ts │ │ │ │ ├── net_info.ts │ │ │ │ └── clipboard.ts │ │ ├── interface.ts │ │ └── index.ts │ └── CHANGELOG.md ├── data │ ├── README.md │ ├── package.json │ ├── src │ │ ├── storage.ts │ │ └── index.ts │ └── CHANGELOG.md ├── event │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.ts │ └── CHANGELOG.md ├── network │ ├── README.md │ ├── package.json │ ├── CHANGELOG.md │ └── src │ │ └── index.ts └── vanilla │ ├── README.md │ ├── package.json │ ├── src │ ├── utils.ts │ └── index.ts │ └── CHANGELOG.md ├── .eslintignore ├── .prettierrc ├── babel.config.js ├── tests └── run_example_scripts.mjs ├── .eslintrc.js ├── lerna.json ├── CONTRIBUTING.md ├── tsconfig.json ├── .gitignore ├── package.json └── README.md /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist -------------------------------------------------------------------------------- /example/react-vite/.gitignore: -------------------------------------------------------------------------------- 1 | .vercel 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | auto-install-peers=true 2 | strict-peer-dependencies=false -------------------------------------------------------------------------------- /example/react-vite/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /example/vanilla-ts/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'packages/**' 3 | - 'example/**' 4 | -------------------------------------------------------------------------------- /packages/debug-tools/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /packages/lib/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './constant' 2 | export * from './utils' 3 | -------------------------------------------------------------------------------- /example/vanilla-ts/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local -------------------------------------------------------------------------------- /packages/create/bin.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict' 3 | require('create-mincu') 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | example 3 | node_modules 4 | .eslintrc.js 5 | packages/debug-tools 6 | tests -------------------------------------------------------------------------------- /example/react-vite/_gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | -------------------------------------------------------------------------------- /packages/debug-tools/bin.js: -------------------------------------------------------------------------------- 1 | const server = require('./server') 2 | 3 | server.startDevTool() 4 | -------------------------------------------------------------------------------- /packages/debug-tools/src/hooks/index.tsx: -------------------------------------------------------------------------------- 1 | export * from './theme' 2 | export * from './request' 3 | -------------------------------------------------------------------------------- /packages/debug-tools/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | output 6 | *.local 7 | -------------------------------------------------------------------------------- /packages/debug/bin.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict' 3 | require('v8-compile-cache') 4 | require('./mincud/cli').startCli() 5 | -------------------------------------------------------------------------------- /example/react-next/next.config.js: -------------------------------------------------------------------------------- 1 | const withPreconstruct = require("@preconstruct/next"); 2 | 3 | module.exports = withPreconstruct(); -------------------------------------------------------------------------------- /packages/lib/debug/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "dist/mincu-lib-debug.cjs.js", 3 | "module": "dist/mincu-lib-debug.esm.js" 4 | } 5 | -------------------------------------------------------------------------------- /example/vue-vite/postcss.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /packages/lib/src/utils.ts: -------------------------------------------------------------------------------- 1 | export const noop = () => {} 2 | export const _window = typeof window == 'undefined' ? global : (window as any) 3 | -------------------------------------------------------------------------------- /packages/debug-tools/server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-debug-tools-server", 3 | "main": "dist/mincu-debug-tools-server.cjs.js" 4 | } 5 | -------------------------------------------------------------------------------- /packages/debug/src/mincud/commands/index.ts: -------------------------------------------------------------------------------- 1 | export * from './incu' 2 | export * from './adb' 3 | export * from './simulator' 4 | export * from './vscode' 5 | -------------------------------------------------------------------------------- /packages/ui/src/orientation.ts: -------------------------------------------------------------------------------- 1 | import mincuCore from 'mincu-core' 2 | 3 | export const orientation = mincuCore.makeProxyFromNativeFunc('Orientation') 4 | -------------------------------------------------------------------------------- /example/vue-vite/src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import './style.css' 3 | import App from './App.vue' 4 | 5 | createApp(App).mount('#app') 6 | -------------------------------------------------------------------------------- /packages/debug/mincud/cli/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-debug-mincud-cli", 3 | "main": "dist/mincu-debug-mincud-cli.cjs.js", 4 | "module": "dist/mincu-debug-mincud-cli.esm.js" 5 | } 6 | -------------------------------------------------------------------------------- /packages/demos/react-demo-shared/src/index.ts: -------------------------------------------------------------------------------- 1 | export { Fallback } from './Fallback' 2 | export { Demo } from './Demo' 3 | export { Button } from './Button' 4 | export * from './mincu-bench' 5 | -------------------------------------------------------------------------------- /packages/react/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from 'mincu-vanilla' 2 | export * from 'mincu-hooks' 3 | export { ReadySSR } from './components/ReadySSR' 4 | export { Ready } from './components/Ready' 5 | -------------------------------------------------------------------------------- /example/react-next/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import { Demo } from 'mincu-react-demo-shared'; 2 | 3 | const App = () => { 4 | return ( 5 | 6 | ) 7 | } 8 | 9 | export default App 10 | -------------------------------------------------------------------------------- /packages/hooks/src/index.ts: -------------------------------------------------------------------------------- 1 | export { default as useNativeState } from './useNativeState' 2 | export { default as useSafeArea } from './useSafeArea' 3 | export { default as useAppReady } from './useAppReady' 4 | -------------------------------------------------------------------------------- /example/react-vite/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()] 7 | }) 8 | -------------------------------------------------------------------------------- /example/vue-vite/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module '*.vue' { 4 | import type { DefineComponent } from 'vue' 5 | const component: DefineComponent<{}, {}, any> 6 | export default component 7 | } 8 | -------------------------------------------------------------------------------- /example/react-next/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /example/vanilla-ts/src/style.css: -------------------------------------------------------------------------------- 1 | #app { 2 | font-family: Avenir, Helvetica, Arial, sans-serif; 3 | -webkit-font-smoothing: antialiased; 4 | -moz-osx-font-smoothing: grayscale; 5 | text-align: center; 6 | color: #2c3e50; 7 | margin-top: 60px; 8 | } 9 | -------------------------------------------------------------------------------- /example/vue-vite/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "allowSyntheticDefaultImports": true 7 | }, 8 | "include": ["vite.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": false, 6 | "singleQuote": true, 7 | "jsxSingleQuote": false, 8 | "bracketSpacing": true, 9 | "arrowParens": "always", 10 | "printWidth": 80 11 | } 12 | -------------------------------------------------------------------------------- /example/vue-vite/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [vue()], 7 | server: { 8 | port: 3000 9 | } 10 | }) 11 | -------------------------------------------------------------------------------- /packages/debug/src/mincud/commands/simulator.ts: -------------------------------------------------------------------------------- 1 | import execa from 'execa' 2 | 3 | export function openUrlSimulator(url: string) { 4 | try { 5 | return execa('xcrun', ['simctl', 'openurl', 'booted', url]) 6 | } catch (e) { 7 | throw e 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/vue-vite/tailwind.config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | "./index.html", 5 | "./src/**/*.{vue,js,ts,jsx,tsx}", 6 | ], 7 | theme: { 8 | extend: {}, 9 | }, 10 | plugins: [], 11 | } 12 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@babel/preset-typescript', 4 | [ 5 | '@babel/preset-env', 6 | { 7 | targets: { 8 | node: '12', 9 | }, 10 | }, 11 | ], 12 | '@babel/preset-react' 13 | ] 14 | } -------------------------------------------------------------------------------- /example/react-vite/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { Ready } from 'mincu-react' 2 | import { Demo, Fallback } from 'mincu-react-demo-shared'; 3 | 4 | const App = () => { 5 | return ( 6 | }> 7 | 8 | 9 | ) 10 | } 11 | 12 | export default App 13 | -------------------------------------------------------------------------------- /packages/debug-tools/src/api/common.ts: -------------------------------------------------------------------------------- 1 | import { IncomingMessage, ServerResponse } from 'http' 2 | 3 | type Listeners = (req: IncomingMessage, res: ServerResponse) => void 4 | 5 | export const makeApi = (cb: Listeners) => { 6 | return (req: IncomingMessage, res: ServerResponse) => cb(req, res) 7 | } 8 | -------------------------------------------------------------------------------- /packages/ui/README.md: -------------------------------------------------------------------------------- 1 | # mincu-ui 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-ui?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-ui 11 | # or 12 | $ npm install mincu-ui 13 | ``` -------------------------------------------------------------------------------- /packages/lib/README.md: -------------------------------------------------------------------------------- 1 | # mincu-lib 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-lib?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-lib 11 | # or 12 | $ npm install mincu-lib 13 | ``` -------------------------------------------------------------------------------- /example/vue-vite/src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /packages/core/README.md: -------------------------------------------------------------------------------- 1 | # mincu-core 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-core?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-core 11 | # or 12 | $ npm install mincu-core 13 | ``` -------------------------------------------------------------------------------- /packages/data/README.md: -------------------------------------------------------------------------------- 1 | # mincu-data 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-data?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-data 11 | # or 12 | $ npm install mincu-data 13 | ``` -------------------------------------------------------------------------------- /example/react-next/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import '../styles/globals.css' 2 | 3 | import { ReadySSR } from "mincu-react" 4 | import { Fallback } from "mincu-react-demo-shared" 5 | 6 | export default function App({ Component, pageProps }) { 7 | return }> 8 | } 9 | -------------------------------------------------------------------------------- /packages/event/README.md: -------------------------------------------------------------------------------- 1 | # mincu-event 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-event?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-event 11 | # or 12 | $ npm install mincu-event 13 | ``` -------------------------------------------------------------------------------- /packages/hooks/README.md: -------------------------------------------------------------------------------- 1 | # mincu-hooks 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-hooks?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-hooks 11 | # or 12 | $ npm install mincu-hooks 13 | ``` -------------------------------------------------------------------------------- /packages/react/README.md: -------------------------------------------------------------------------------- 1 | # mincu-react 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-react?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-react 11 | # or 12 | $ npm install mincu-react 13 | ``` -------------------------------------------------------------------------------- /packages/network/README.md: -------------------------------------------------------------------------------- 1 | # mincu-network 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-network?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-network 11 | # or 12 | $ npm install mincu-network 13 | ``` -------------------------------------------------------------------------------- /packages/vanilla/README.md: -------------------------------------------------------------------------------- 1 | # mincu-vanilla 2 | 3 | ![npm bundle size](https://img.shields.io/bundlephobia/min/mincu-vanilla?style=flat-square) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | ## Install 8 | 9 | ```cmd 10 | $ yarn add mincu-vanilla 11 | # or 12 | $ npm install mincu-vanilla 13 | ``` -------------------------------------------------------------------------------- /tests/run_example_scripts.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zx 2 | 3 | process.env.FORCE_COLOR=3 4 | 5 | const examplePath = path.join(__dirname, '..', 'example'); 6 | 7 | const pkgs = await glob(`${examplePath}/*/package.json`); 8 | 9 | for (const pkg of pkgs) { 10 | const example = path.dirname(pkg) 11 | cd(example) 12 | await $`npm run build` 13 | } 14 | -------------------------------------------------------------------------------- /packages/debug-tools/src/main.tsx: -------------------------------------------------------------------------------- 1 | import 'virtual:uno.css' 2 | import '@unocss/reset/tailwind.css' 3 | import 'allotment/dist/style.css' 4 | import 'simplebar/src/simplebar.css' 5 | 6 | import React from 'react' 7 | import ReactDOM from 'react-dom/client' 8 | import { App } from './app' 9 | 10 | ReactDOM.createRoot(document.getElementById('app')!).render() 11 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: ['@typescript-eslint/eslint-plugin', 'prettier'], 3 | parser: '@typescript-eslint/parser', 4 | parserOptions: { 5 | project: './tsconfig.json', 6 | tsconfigRootDir: __dirname, 7 | ecmaVersion: 2018, 8 | sourceType: 'module', 9 | }, 10 | rules: { 11 | 'prettier/prettier': 'error', 12 | }, 13 | } 14 | -------------------------------------------------------------------------------- /packages/hooks/src/useAppReady.ts: -------------------------------------------------------------------------------- 1 | import { useState } from 'react' 2 | import mincuCore from 'mincu-core' 3 | import useReady from './useReady' 4 | 5 | export default (reject = () => {}): boolean => { 6 | const [isReady, setIsReady] = useState(mincuCore.isReady && mincuCore.isApp) 7 | 8 | useReady(() => setIsReady(true), reject, []) 9 | 10 | return isReady 11 | } 12 | -------------------------------------------------------------------------------- /packages/debug-tools/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Mincu Debug Tools 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/vue-vite/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /packages/hooks/src/useSafeArea.ts: -------------------------------------------------------------------------------- 1 | import { useState } from 'react' 2 | import { EdgeInsets } from 'mincu-core' 3 | import useReady from './useReady' 4 | import dataModule from 'mincu-data' 5 | 6 | export default () => { 7 | const [inset, setInset] = useState({} as EdgeInsets) 8 | 9 | useReady(() => { 10 | setInset(dataModule.inset) 11 | }, []) 12 | 13 | return inset 14 | } 15 | -------------------------------------------------------------------------------- /example/react-vite/src/main.tsx: -------------------------------------------------------------------------------- 1 | import { StrictMode } from 'react' 2 | import { createRoot } from 'react-dom/client' 3 | import './index.css' 4 | import App from './App' 5 | 6 | import debug from 'mincu-debug' 7 | 8 | debug.connect() 9 | 10 | const rootElement = document.getElementById('root') 11 | const root = createRoot(rootElement!) 12 | 13 | root.render( 14 | 15 | 16 | 17 | ) 18 | -------------------------------------------------------------------------------- /packages/create/README.md: -------------------------------------------------------------------------------- 1 | # create-mincu 2 | 3 | [Mincu - 南大家园](https://github.com/ncuhome/mincu) 4 | 5 | ## Quick Start 6 | 7 | 快速创建 mincu 项目: 8 | 9 | ```sh 10 | # npm 11 | $ npm init mincu@latest 12 | # yarn 13 | $ yarn create mincu 14 | # pnpm 15 | $ pnpm create mincu 16 | # or 17 | $ npx create-mincu 18 | ``` 19 | 20 | ## Thanks 21 | 22 | - [create-vite](https://github.com/vitejs/vite/tree/main/packages/create-vite) 23 | -------------------------------------------------------------------------------- /example/vanilla-ts/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/react-vite/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/vue-vite/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + Vue + TS 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/react-vite/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /example/react-next/styles/globals.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /example/vanilla-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "debug-module", 3 | "private": true, 4 | "version": "2.13.2", 5 | "scripts": { 6 | "start": "mincud npm run dev", 7 | "dev": "vite --host", 8 | "build": "vite build", 9 | "serve": "vite preview" 10 | }, 11 | "devDependencies": { 12 | "typescript": "^4.7.4", 13 | "vite": "^3.0.4" 14 | }, 15 | "dependencies": { 16 | "mincu-debug": "workspace:2.13.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/ui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-ui", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-ui.cjs.js", 11 | "module": "dist/mincu-ui.esm.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "dependencies": { 16 | "mincu-core": "workspace:2.13.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/demos/react-demo-shared/src/mincu-bench.ts: -------------------------------------------------------------------------------- 1 | import { mincu } from 'mincu-react' 2 | import { Bench } from 'tinybench' 3 | 4 | export const mincuBench = (times = 10) => { 5 | const bench = new Bench({ iterations: times }) 6 | 7 | bench.add('handleShowHeader', async () => { 8 | await mincu.handleShowHeader(true) 9 | await mincu.handleShowHeader(false) 10 | await mincu.handleShowHeader(true) 11 | }) 12 | 13 | return bench.run() 14 | } 15 | -------------------------------------------------------------------------------- /packages/event/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-event", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-event.cjs.js", 11 | "module": "dist/mincu-event.esm.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "dependencies": { 16 | "mincu-core": "workspace:2.13.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/react/src/components/Ready.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from 'react' 2 | import { useAppReady } from 'mincu-hooks' 3 | import { Fallback } from './Fallback' 4 | 5 | export interface Props { 6 | fallback?: React.ReactNode 7 | children?: React.ReactNode 8 | } 9 | 10 | export const Ready: FC = ({ 11 | fallback = () as any, 12 | children, 13 | }) => { 14 | const isReady = useAppReady() 15 | 16 | return isReady ? children : fallback 17 | } 18 | -------------------------------------------------------------------------------- /example/vue-vite/src/components/Ready.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | -------------------------------------------------------------------------------- /packages/core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-core", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-core.cjs.js", 11 | "module": "dist/mincu-core.esm.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "dependencies": { 16 | "events": "^3.3.0", 17 | "mincu-lib": "workspace:2.13.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/debug-tools/README.md: -------------------------------------------------------------------------------- 1 | # mincu-debug-tools 2 | 3 | [![npm install size](https://packagephobia.com/badge?p=mincu-debug-tools)](https://packagephobia.com/result?p=mincu-debug-tools) 4 | 5 | [Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu) 6 | 7 | Devtools for mincu-debug 8 | 9 | ## Install 10 | 11 | ```cmd 12 | $ yarn add mincu-debug-tools 13 | # or 14 | $ npm install mincu-debug-tools 15 | ``` 16 | 17 | ## Thanks 18 | 19 | - [expo/expo-cli](https://github.com/expo/expo-cli) -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*", 4 | "packages/demos/*", 5 | "example/*" 6 | ], 7 | "command": { 8 | "publish": { 9 | "conventionalCommits": true, 10 | "exact": true, 11 | "message": "chore: publish %s", 12 | "registry": "https://registry.npmjs.org/" 13 | }, 14 | "version": { 15 | "conventionalCommits": true, 16 | "syncWorkspaceLock": true 17 | } 18 | }, 19 | "version": "2.13.2", 20 | "npmClient": "pnpm" 21 | } 22 | -------------------------------------------------------------------------------- /packages/data/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-data", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-data.cjs.js", 11 | "module": "dist/mincu-data.esm.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "dependencies": { 16 | "mincu-core": "workspace:2.13.2", 17 | "mincu-lib": "workspace:2.13.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example/vue-vite/src/style.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | body { 6 | margin: 0; 7 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 8 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 9 | sans-serif; 10 | -webkit-font-smoothing: antialiased; 11 | -moz-osx-font-smoothing: grayscale; 12 | } 13 | 14 | code { 15 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 16 | monospace; 17 | } 18 | -------------------------------------------------------------------------------- /example/vanilla-ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "module": "ESNext", 5 | "lib": ["ESNext", "DOM"], 6 | "moduleResolution": "Node", 7 | "strict": false, 8 | "sourceMap": true, 9 | "resolveJsonModule": true, 10 | "esModuleInterop": true, 11 | "noEmit": true, 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "noImplicitReturns": true, 15 | "skipLibCheck": true, 16 | "baseUrl": "." 17 | }, 18 | "include": ["./src"] 19 | } 20 | -------------------------------------------------------------------------------- /packages/lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-lib", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-lib.cjs.js", 11 | "module": "dist/mincu-lib.esm.js", 12 | "files": [ 13 | "dist", 14 | "debug" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "preconstruct": { 20 | "entrypoints": [ 21 | "index.ts", 22 | "debug.ts" 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-react", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-react.cjs.js", 11 | "module": "dist/mincu-react.esm.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "dependencies": { 16 | "mincu-hooks": "workspace:2.13.2", 17 | "mincu-vanilla": "workspace:2.13.2" 18 | }, 19 | "peerDependencies": { 20 | "react": ">=17" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/debug-tools/src/components/Space.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react' 2 | 3 | interface Props { 4 | /** 5 | * @default 4 6 | */ 7 | x?: number | string 8 | /** 9 | * @default 4 10 | */ 11 | y?: number | string 12 | direction?: 'row' | 'column' 13 | } 14 | 15 | const Space: FC = ({ x = 4, y = 4, direction = 'column' }) => { 16 | return ( 17 | 23 | ) 24 | } 25 | 26 | export default Space 27 | -------------------------------------------------------------------------------- /packages/network/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-network", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-network.cjs.js", 11 | "module": "dist/mincu-network.esm.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "dependencies": { 16 | "mincu-core": "workspace:2.13.2", 17 | "mincu-data": "workspace:2.13.2" 18 | }, 19 | "devDependencies": { 20 | "axios": "^0.27.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/lib/src/constant.ts: -------------------------------------------------------------------------------- 1 | export const defaultUserData = { 2 | token: '', 3 | colorScheme: 'light', 4 | colors: {}, 5 | inset: { top: 0, right: 0, bottom: 0, left: 0 }, 6 | profile: { 7 | basicProfile: { 8 | app_avatar_url: '', 9 | department: '', 10 | department_id: '', 11 | head_pic_url: '', 12 | max_role_level: 0, 13 | message: '', 14 | name: '', 15 | status: 0, 16 | }, 17 | entireProfile: { 18 | base_info: null, 19 | is_teacher: false, 20 | message: '', 21 | status: 0, 22 | }, 23 | }, 24 | } 25 | -------------------------------------------------------------------------------- /packages/hooks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-hooks", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-hooks.cjs.js", 11 | "module": "dist/mincu-hooks.esm.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "dependencies": { 16 | "lodash": "^4.17.21", 17 | "mincu-core": "workspace:2.13.2", 18 | "mincu-data": "workspace:2.13.2" 19 | }, 20 | "peerDependencies": { 21 | "react": ">=17" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/vue-vite/src/hooks/useNativeState.ts: -------------------------------------------------------------------------------- 1 | import { ref, onBeforeUnmount, onMounted } from 'vue' 2 | import { States, mincuCore, dataModule } from 'mincu-vanilla' 3 | 4 | export default (key: T, defaultVal?: any) => { 5 | const state = ref(defaultVal) 6 | 7 | const handle = (res: States[T]) => { 8 | state.value = res 9 | } 10 | 11 | onMounted(() => { 12 | handle(dataModule?.[key] ?? {}) 13 | mincuCore.listener(key, handle) 14 | }) 15 | 16 | onBeforeUnmount(() => { 17 | mincuCore.remove(key, handle) 18 | }) 19 | 20 | return state 21 | } 22 | -------------------------------------------------------------------------------- /example/react-next/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": false, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true 17 | }, 18 | "exclude": ["node_modules"], 19 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"] 20 | } 21 | -------------------------------------------------------------------------------- /example/react-vite/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["./src"] 20 | } 21 | -------------------------------------------------------------------------------- /packages/demos/react-demo-shared/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["./src"] 20 | } 21 | -------------------------------------------------------------------------------- /example/vue-vite/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "moduleResolution": "Node", 7 | "strict": true, 8 | "jsx": "preserve", 9 | "sourceMap": true, 10 | "resolveJsonModule": true, 11 | "isolatedModules": true, 12 | "esModuleInterop": true, 13 | "lib": ["ESNext", "DOM"], 14 | "skipLibCheck": true, 15 | "types": [ 16 | "vite/client", 17 | ] 18 | }, 19 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /packages/data/src/storage.ts: -------------------------------------------------------------------------------- 1 | import mincuCore from 'mincu-core' 2 | 3 | export class MincuStorage { 4 | async getItem(key: string) { 5 | return mincuCore.callPromise('Storage', 'getItem', [key]) 6 | } 7 | 8 | async setItem(key: string, value: any) { 9 | return mincuCore.callPromise('Storage', 'setItem', [key, value]) 10 | } 11 | 12 | async removeItem(key: string) { 13 | return this.remove(key) 14 | } 15 | 16 | async remove(key: string) { 17 | return mincuCore.callPromise('Storage', 'remove', [key]) 18 | } 19 | 20 | async reset() { 21 | return mincuCore.callPromise('Storage', 'reset', null) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/vanilla/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-vanilla", 3 | "version": "2.13.2", 4 | "homepage": "https://github.com/ncuhome", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:ncuhome/mincu.git" 8 | }, 9 | "license": "MIT", 10 | "main": "dist/mincu-vanilla.cjs.js", 11 | "module": "dist/mincu-vanilla.esm.js", 12 | "files": [ 13 | "dist" 14 | ], 15 | "dependencies": { 16 | "mincu-core": "workspace:2.13.2", 17 | "mincu-data": "workspace:2.13.2", 18 | "mincu-event": "workspace:2.13.2", 19 | "mincu-network": "workspace:2.13.2", 20 | "mincu-ui": "workspace:2.13.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/react-next/README.md: -------------------------------------------------------------------------------- 1 | # Mincu React 模板 2 | 3 | 1. 目前没有发包,请自行 link 后再进行调试 4 | 2. 考虑将 lib/hooks 代码放在主包里 5 | 3. 之后使用 deeplink 在 app 端内调试 6 | 7 | ## Link 步骤 8 | 9 | ```shell 10 | # 1. mincu/ 11 | yarn link 12 | 13 | # 2. mincu/example/react-next/ 14 | yarn link mincu 15 | 16 | # 3. mincu/example/react-next/node_modules/react/ 17 | yarn link 18 | 19 | # 4. mincu/ 20 | yarn link react 21 | ``` 22 | 23 | ## 如何调试 24 | 25 | [iOS 调试方法](https://github.com/react-native-webview/react-native-webview/blob/master/docs/Debugging.md#ios--safari) 26 | 27 | [Android 调试方法](https://github.com/react-native-webview/react-native-webview/blob/master/docs/Debugging.md#android--chrome) -------------------------------------------------------------------------------- /example/vue-vite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-vite", 3 | "private": true, 4 | "version": "2.13.2", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vue-tsc --noEmit && vite build", 9 | "preview": "vite preview" 10 | }, 11 | "dependencies": { 12 | "mincu-vanilla": "workspace:2.13.2", 13 | "qrcode.vue": "^3.3.3", 14 | "vue": "^3.2.37" 15 | }, 16 | "devDependencies": { 17 | "@vitejs/plugin-vue": "^3.0.1", 18 | "autoprefixer": "^10.4.8", 19 | "postcss": "^8.4.16", 20 | "tailwindcss": "^3.1.8", 21 | "typescript": "^4.7.4", 22 | "vite": "^3.0.4", 23 | "vue-tsc": "^0.39.5" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/react/src/components/Fallback.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export const Fallback = () => ( 4 |
15 | 16 | 请在 17 | 25 | 南大家园 26 | 27 | 中打开😊 28 | 29 |
30 | ) 31 | -------------------------------------------------------------------------------- /packages/react/src/components/ReadySSR.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, Fragment, useEffect, useState } from 'react' 2 | import { useAppReady } from 'mincu-hooks' 3 | import { Fallback } from './Fallback' 4 | 5 | export interface Props { 6 | fallback?: React.ReactNode 7 | children?: React.ReactNode 8 | } 9 | 10 | export const ReadySSR: FC = ({ 11 | fallback = () as any, 12 | children, 13 | }) => { 14 | const [isSSR, setIsSSR] = useState(true) 15 | const isReady = useAppReady() 16 | 17 | useEffect(() => { 18 | setIsSSR(false) 19 | }, []) 20 | 21 | const content = isReady ? children : fallback 22 | 23 | return {!isSSR && content} 24 | } 25 | -------------------------------------------------------------------------------- /packages/debug-tools/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": true, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "jsx": "preserve", 14 | "moduleResolution": "Node", 15 | "resolveJsonModule": true, 16 | "isolatedModules": true, 17 | "noEmit": true, 18 | "baseUrl": ".", 19 | "paths": { 20 | "@/*": ["src/*"] 21 | } 22 | }, 23 | "include": ["src"] 24 | } 25 | -------------------------------------------------------------------------------- /example/vanilla-ts/src/main.ts: -------------------------------------------------------------------------------- 1 | import './style.css' 2 | 3 | if (import.meta.env.DEV) { 4 | // only enables it in DEV mode 5 | import('mincu-debug').then(({ default: debugModule }) => { 6 | debugModule.applyConsole() 7 | }) 8 | } 9 | 10 | const fakePromise = () => new Promise((_, reject) => { 11 | reject(new Error('fake error')) 12 | }) 13 | 14 | const a = async () => { 15 | const res = await fakePromise() 16 | console.log(res) 17 | } 18 | 19 | setTimeout(() => { 20 | a() 21 | }, 1000) 22 | 23 | const app = document.querySelector('#app')! 24 | 25 | app.innerHTML = ` 26 |

Hello Vite!

27 | Documentation 28 | ` 29 | -------------------------------------------------------------------------------- /packages/demos/react-demo-shared/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mincu-react-demo-shared", 3 | "version": "2.13.2", 4 | "main": "dist/mincu-react-demo-shared.cjs.js", 5 | "module": "dist/mincu-react-demo-shared.esm.js", 6 | "dependencies": { 7 | "@headlessui/react": "^1.6.5", 8 | "axios": "^0.27.2", 9 | "mincu-react": "workspace:*", 10 | "qrcode.react": "^3.1.0", 11 | "tinybench": "^2.0.9", 12 | "twind": "^0.16.17" 13 | }, 14 | "peerDependencies": { 15 | "react": ">=17" 16 | }, 17 | "devDependencies": { 18 | "@types/react": "^18.0.17", 19 | "@types/react-dom": "^18.0.6", 20 | "@vitejs/plugin-react": "^2.0.0", 21 | "typescript": "^4.7.4", 22 | "vite": "^3.0.4" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/hooks/src/useNativeState.ts: -------------------------------------------------------------------------------- 1 | import { useState, useCallback } from 'react' 2 | import { States } from 'mincu-core' 3 | import mincuCore from 'mincu-core' 4 | import dataModule from 'mincu-data' 5 | import useReady from './useReady' 6 | 7 | /** 8 | * 返回 app 的状态 9 | */ 10 | export default (key: T): States[T] => { 11 | const [value, setValue] = useState({}) 12 | 13 | const handle = useCallback((res: States[T]) => { 14 | setValue(res) 15 | }, []) 16 | 17 | useReady(() => { 18 | setValue(dataModule?.[key] ?? {}) 19 | mincuCore.listener(key, handle) 20 | 21 | return () => { 22 | mincuCore.remove(key, handle) 23 | } 24 | }, []) 25 | 26 | return value 27 | } 28 | -------------------------------------------------------------------------------- /packages/debug-tools/src/components/Inspector.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC, useRef, useCallback } from 'react' 2 | import { DebugTarget } from '@/shim' 3 | import { chiiFrontUrl } from '@/utils' 4 | import { useThemeChange } from '@/hooks' 5 | 6 | const Inspector: FC<{ 7 | data: DebugTarget 8 | }> = ({ data }) => { 9 | const ref = useRef(null) 10 | 11 | useThemeChange(() => { 12 | if (ref.current) { 13 | ref.current.src = chiiFrontUrl(data.id, data.id) 14 | } 15 | }) 16 | 17 | const getUrl = useCallback(() => { 18 | return chiiFrontUrl(data.id, data.id) 19 | }, [data.id]) 20 | 21 | return