From 406b487ec040d0f2c6ab732995c119bee62f77c5 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 20 Oct 2024 15:35:35 +0900 Subject: [PATCH 1/6] feat: Add inject key in types.ts Update types.ts to include a new injection key for showing the preview reference. --- src/types.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 19b8c609..466a378f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import type { Component, ComputedRef, InjectionKey, ToRefs } from 'vue' +import type { Component, ComputedRef, InjectionKey, Ref, ToRefs } from 'vue' import { Props } from './Repl.vue' export type EditorMode = 'js' | 'css' | 'ssr' @@ -21,3 +21,5 @@ export const injectKeyProps: InjectionKey< export const injectKeyPreviewRef: InjectionKey< ComputedRef > = Symbol('preview-ref') +export const injectKeyShowPreviewRef: InjectionKey> = + Symbol('show-preview-ref') From 360b8968aba295d9a9c91bc82cdd1c6e994bd71c Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 20 Oct 2024 15:38:54 +0900 Subject: [PATCH 2/6] feat: add showPreview ref to injectKeyShowPreviewRef - add showPreview ref to provider - apply showPreview ref to editroSlot --- src/Repl.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Repl.vue b/src/Repl.vue index 66138ec7..b6733658 100644 --- a/src/Repl.vue +++ b/src/Repl.vue @@ -2,11 +2,12 @@ import SplitPane from './SplitPane.vue' import Output from './output/Output.vue' import { type Store, useStore } from './store' -import { computed, provide, toRefs, useTemplateRef } from 'vue' +import { computed, provide, ref, toRefs, useTemplateRef } from 'vue' import { type EditorComponentType, injectKeyPreviewRef, injectKeyProps, + injectKeyShowPreviewRef, } from './types' import EditorContainer from './editor/EditorContainer.vue' import type * as monaco from 'monaco-editor-core' @@ -84,6 +85,9 @@ provide( computed(() => outputRef.value?.previewRef?.container ?? null), ) +const showPreview = ref(true) +provide(injectKeyShowPreviewRef, showPreview) + /** * Reload the preview iframe */ @@ -97,7 +101,7 @@ defineExpose({ reload })