From 5eedd2d1bfce2750475936c0e8a9064392342cf3 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Fri, 24 Nov 2023 10:40:06 +0100 Subject: [PATCH] Show Spotlight trigger if no dev overlay is enabled --- .changeset/twenty-turtles-rule.md | 5 +++++ .eslintrc.cjs | 1 + packages/astro/src/index.ts | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/twenty-turtles-rule.md diff --git a/.changeset/twenty-turtles-rule.md b/.changeset/twenty-turtles-rule.md new file mode 100644 index 00000000..9e2464b9 --- /dev/null +++ b/.changeset/twenty-turtles-rule.md @@ -0,0 +1,5 @@ +--- +'@spotlightjs/astro': patch +--- + +Show Spotlight button if dev overlay is not enabled diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 6527cfb6..9fa65b2e 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -7,5 +7,6 @@ module.exports = { plugins: ['react-refresh'], rules: { 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], + '@typescript-eslint/ban-ts-comment': 'off', }, }; diff --git a/packages/astro/src/index.ts b/packages/astro/src/index.ts index 5d92815f..1eea4da1 100644 --- a/packages/astro/src/index.ts +++ b/packages/astro/src/index.ts @@ -23,6 +23,7 @@ const createPlugin = (options?: SpotlightOptions): AstroIntegration => { hooks: { 'astro:config:setup': async ({ command, injectScript, addDevOverlayPlugin, logger, config }) => { + console.log(config); if (command === 'dev') { logger.info('[@spotlightjs/astro] Setting up Spotlight'); @@ -36,7 +37,21 @@ const createPlugin = (options?: SpotlightOptions): AstroIntegration => { ...(config.vite.plugins || []), ]; - injectScript('page', buildClientInitSnippet({ importPath: PKG_NAME, showTriggerButton: false, ...options })); + let showTriggerButton = true; + // We suppose with 4.0 this will be promoted top level and expimental will be removed + // to keep backwards compatibility we check both + // @ts-ignore + if (config.devOverlay) { + // @ts-ignore + showTriggerButton = config.devOverlay ? false : true; + } + // @ts-ignore + if (config.experimental?.devOverlay) { + // @ts-ignore + showTriggerButton = config.experimental?.devOverlay ? false : true; + } + + injectScript('page', buildClientInitSnippet({ importPath: PKG_NAME, showTriggerButton, ...options })); injectScript('page-ssr', SPOTLIGHT_SERVER_SNIPPET); const importPath = path.dirname(url.fileURLToPath(import.meta.url));