From b767179ea3d720dba9be1c62495aa07d453305fb Mon Sep 17 00:00:00 2001 From: Aryan Deora Date: Sat, 3 Jun 2023 11:35:01 -0400 Subject: [PATCH] feat(query-devtools): Lazyload Query Devtools Core (#5527) --- packages/query-devtools/package.json | 24 +- packages/query-devtools/rollup.config.js | 21 +- packages/query-devtools/src/Devtools.tsx | 40 ++++ packages/query-devtools/src/Explorer.tsx | 34 ++- packages/query-devtools/src/index.tsx | 17 +- packages/query-devtools/src/utils.tsx | 14 +- pnpm-lock.yaml | 274 +++++++++++++++++++++++ 7 files changed, 381 insertions(+), 43 deletions(-) diff --git a/packages/query-devtools/package.json b/packages/query-devtools/package.json index 63aa7bdf90..48efbe00d5 100644 --- a/packages/query-devtools/package.json +++ b/packages/query-devtools/package.json @@ -11,16 +11,20 @@ "url": "https://github.com/sponsors/tannerlinsley" }, "type": "module", - "types": "build/lib/index.d.ts", - "main": "build/lib/index.cjs", - "module": "build/lib/index.js", + "types": "build/types/index.d.ts", + "main": "build/cjs/index.js", + "module": "build/esm/index.js", "exports": { ".": { - "types": "./build/lib/index.d.ts", - "solid": "./build/lib/index.js", - "import": "./build/lib/index.js", - "require": "./build/lib/index.cjs", - "default": "./build/lib/index.cjs" + "types": "./build/types/index.d.ts", + "solid": "./build/source/index.jsx", + "import": "./build/esm/index.js", + "browser": { + "import": "./build/esm/index.js", + "require": "./build/cjs/index.js" + }, + "require": "./build/cjs/index.js", + "node": "./build/cjs/index.js" }, "./package.json": "./package.json" }, @@ -31,7 +35,8 @@ "test:lib": "vitest run --coverage", "test:lib:dev": "pnpm run test:lib --watch", "test:build": "publint", - "build": "pnpm build:rollup && pnpm build:types", + "build": "pnpm build:rollup && pnpm rename-build-dir", + "rename-build-dir": "rimraf ./build && mv ./dist ./build", "build:rollup": "rollup --config rollup.config.js", "build:types": "tsc --emitDeclarationOnly" }, @@ -51,6 +56,7 @@ }, "devDependencies": { "@tanstack/query-core": "^5.0.0-alpha.43", + "rollup-preset-solid": "^2.0.1", "vite-plugin-solid": "^2.5.0" } } diff --git a/packages/query-devtools/rollup.config.js b/packages/query-devtools/rollup.config.js index c8c12a90e6..540dc9e36f 100644 --- a/packages/query-devtools/rollup.config.js +++ b/packages/query-devtools/rollup.config.js @@ -1,14 +1,13 @@ // @ts-check +import withSolid from 'rollup-preset-solid' -import { defineConfig } from 'rollup' -import { buildConfigs } from '../../scripts/getRollupConfig.js' +const config = withSolid({ + input: 'src/index.tsx', + targets: ['esm', 'cjs'], +}) -export default defineConfig( - buildConfigs({ - name: 'query-devtools', - outputFile: 'index', - entryFile: './src/index.tsx', - forceBundle: true, - bundleDeps: true, - }), -) +if (!Array.isArray(config)) { + config.external = [] +} + +export default config diff --git a/packages/query-devtools/src/Devtools.tsx b/packages/query-devtools/src/Devtools.tsx index 2781bf6ee0..81aaf4b526 100644 --- a/packages/query-devtools/src/Devtools.tsx +++ b/packages/query-devtools/src/Devtools.tsx @@ -20,6 +20,7 @@ import { getQueryStatusColorByLabel, sortFns, convertRemToPixels, + getSidedProp, } from './utils' import { ArrowDown, @@ -82,6 +83,8 @@ export const DevtoolsComponent: Component = (props) => { ) } +export default DevtoolsComponent + export const Devtools = () => { loadFonts() @@ -315,6 +318,42 @@ export const DevtoolsPanel: Component = (props) => { setSettingsOpen(false) } + createEffect(() => { + const rootContainer = panelRef.parentElement?.parentElement?.parentElement + if (!rootContainer) return + const styleProp = getSidedProp( + 'padding', + props.localStore.position as DevtoolsPosition, + ) + const isVertical = + props.localStore.position === 'left' || + props.localStore.position === 'right' + const previousPaddings = (({ + padding, + paddingTop, + paddingBottom, + paddingLeft, + paddingRight, + }) => ({ + padding, + paddingTop, + paddingBottom, + paddingLeft, + paddingRight, + }))(rootContainer.style) + + rootContainer.style[styleProp] = `${ + isVertical ? props.localStore.width : props.localStore.height + }px` + + onCleanup(() => { + Object.entries(previousPaddings).forEach(([property, previousValue]) => { + rootContainer.style[property as keyof typeof previousPaddings] = + previousValue + }) + }) + }) + return (