From e960f0c4f02ffcc1801db9b143c2280557c9e93c Mon Sep 17 00:00:00 2001 From: fantasticsoul Date: Mon, 15 Jan 2024 21:06:01 +0800 Subject: [PATCH] chore: support url params n&s for playground --- docs/docs/playground/demos/Playground/index.tsx | 6 +++++- docs/docs/playground/index.md | 2 +- docs/package.json | 1 + pnpm-lock.yaml | 5 +++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/docs/playground/demos/Playground/index.tsx b/docs/docs/playground/demos/Playground/index.tsx index 9c82c933..be1cf406 100644 --- a/docs/docs/playground/demos/Playground/index.tsx +++ b/docs/docs/playground/demos/Playground/index.tsx @@ -1,5 +1,6 @@ import React from 'react' import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live"; +import qs from "qs"; import * as prism from 'prism-react-renderer'; import * as helux from 'helux'; import ApiMenus from './ApiMenus'; @@ -15,6 +16,9 @@ const subNames: Record = { modular: 'defineActions', }; const cachedSubNames: Record = {}; +const obj = qs.parse(window.location.search, { ignoreQueryPrefix: true }); +const name = obj.n || 'atom'; +const subName = obj.s || 'primitive'; function getCode(name: string, subName: string) { const codeDict: any = codes; @@ -22,7 +26,7 @@ function getCode(name: string, subName: string) { } export default () => { - const [info, setInfo] = React.useState({ name: 'atom', subName: 'primitive', code: getCode('atom', 'primitive'), }); + const [info, setInfo] = React.useState({ name, subName, code: getCode('atom', 'primitive'), }); const changeCode = (name: string) => { const subName = cachedSubNames[name] || subNames[name] || 'primitive'; setInfo({ name, subName, code: getCode(name, subName) }); diff --git a/docs/docs/playground/index.md b/docs/docs/playground/index.md index e4706350..cbe54b3c 100644 --- a/docs/docs/playground/index.md +++ b/docs/docs/playground/index.md @@ -1,6 +1,6 @@ --- nav: - title: 生态 + title: Playground order: 3 --- diff --git a/docs/package.json b/docs/package.json index 787d3be3..01dfb60c 100644 --- a/docs/package.json +++ b/docs/package.json @@ -57,6 +57,7 @@ "lodash.throttle": "^4.1.1", "prism-react-renderer": "^2.3.1", "prism-themes": "^1.9.0", + "qs": "^6.11.2", "rc-motion": "^2.9.0", "rc-tree": "^5.8.2", "react-copy-to-clipboard": "^5.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec0cb93d..fa23271b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -95,7 +95,7 @@ importers: dumi: ^2.2.16 eslint: ^8.23.0 father: ^4.1.0 - helux: 4.1.5 + helux: 4.1.6 husky: ^8.0.1 lint-staged: ^13.0.3 lodash: ^4.17.21 @@ -105,6 +105,7 @@ importers: prettier-plugin-packagejson: ^2.2.18 prism-react-renderer: ^2.3.1 prism-themes: ^1.9.0 + qs: ^6.11.2 rc-motion: ^2.9.0 rc-tree: ^5.8.2 react: ^18.0.0 @@ -124,6 +125,7 @@ importers: lodash.throttle: 4.1.1 prism-react-renderer: 2.3.1_react@18.2.0 prism-themes: 1.9.0 + qs: 6.11.2 rc-motion: 2.9.0_biqbaboplfbrettd7655fr4n2y rc-tree: 5.8.2_biqbaboplfbrettd7655fr4n2y react-copy-to-clipboard: 5.1.0_react@18.2.0 @@ -15354,7 +15356,6 @@ packages: engines: {node: '>=0.6'} dependencies: side-channel: 1.0.4 - dev: true /query-string/6.14.1: resolution: {integrity: sha512-XDxAeVmpfu1/6IjyT/gXHOl+S0vQ9owggJ30hhWKdHAsNPOcasn5o9BW0eejZqL2e4vMjhAxoW3jVHcD6mbcYw==}