From ac12d025d92921f499464023f55eaca85a478746 Mon Sep 17 00:00:00 2001 From: Marvin <454846659@qq.com> Date: Fri, 10 May 2024 18:09:47 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=A2=9E=E5=8A=A0vue?= =?UTF-8?q?=E7=9A=84hooks=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- src/client/hooks/index.ts | 1 + src/client/hooks/vue/index.ts | 4 +++ .../hooks/vue/useOnStandalonePluginInitVue.ts | 15 ++++++++++ src/client/hooks/vue/usePluginSettingsVue.ts | 20 +++++++++++++ src/client/hooks/vue/usePluginStateVue.ts | 28 +++++++++++++++++ .../hooks/vue/useWatchPluginMessageVue.ts | 30 +++++++++++++++++++ 7 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/client/hooks/vue/index.ts create mode 100644 src/client/hooks/vue/useOnStandalonePluginInitVue.ts create mode 100644 src/client/hooks/vue/usePluginSettingsVue.ts create mode 100644 src/client/hooks/vue/usePluginStateVue.ts create mode 100644 src/client/hooks/vue/useWatchPluginMessageVue.ts diff --git a/package.json b/package.json index ece6226..8b022ab 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,8 @@ "stylelint": "^15", "ts-json-schema-generator": "^1.4.0", "typescript": "^5", - "vitest": "^1" + "vitest": "^1", + "vue": "^3.4.27" }, "peerDependencies": { "react": ">=18", diff --git a/src/client/hooks/index.ts b/src/client/hooks/index.ts index 42ef7d9..b9d07e9 100644 --- a/src/client/hooks/index.ts +++ b/src/client/hooks/index.ts @@ -2,3 +2,4 @@ export * from './useOnStandalonePluginInit'; export * from './usePluginSettings'; export * from './usePluginState'; export * from './useWatchPluginMessage'; +export * from './vue'; diff --git a/src/client/hooks/vue/index.ts b/src/client/hooks/vue/index.ts new file mode 100644 index 0000000..6a45795 --- /dev/null +++ b/src/client/hooks/vue/index.ts @@ -0,0 +1,4 @@ +export * from './useOnStandalonePluginInitVue'; +export * from './usePluginSettingsVue'; +export * from './usePluginStateVue'; +export * from './useWatchPluginMessageVue'; diff --git a/src/client/hooks/vue/useOnStandalonePluginInitVue.ts b/src/client/hooks/vue/useOnStandalonePluginInitVue.ts new file mode 100644 index 0000000..7db725e --- /dev/null +++ b/src/client/hooks/vue/useOnStandalonePluginInitVue.ts @@ -0,0 +1,15 @@ +import { onMounted } from 'vue'; + +import { PluginPayload, lobeChat } from '@/client'; + +export const useOnStandalonePluginInitVue = ( + callback: (payload: PluginPayload) => void, +) => { + onMounted(() => { + lobeChat.getPluginPayload().then((e) => { + if (!e) return; + + callback(e); + }); + }); +}; diff --git a/src/client/hooks/vue/usePluginSettingsVue.ts b/src/client/hooks/vue/usePluginSettingsVue.ts new file mode 100644 index 0000000..a2eb7fd --- /dev/null +++ b/src/client/hooks/vue/usePluginSettingsVue.ts @@ -0,0 +1,20 @@ +import { UnwrapRef, onMounted, ref } from 'vue'; + +import { lobeChat } from '@/client'; + +export const usePluginSettingsVue = (initialValue: T) => { + const value = ref(initialValue); + onMounted(() => { + lobeChat.getPluginSettings().then((e) => { + if (!e) return; + value.value = e; + }); + }); + + const updateValue = (newValue: T) => { + value.value = newValue as UnwrapRef; + lobeChat.setPluginSettings(newValue); + }; + + return [value, updateValue] as const; +}; diff --git a/src/client/hooks/vue/usePluginStateVue.ts b/src/client/hooks/vue/usePluginStateVue.ts new file mode 100644 index 0000000..8d2ec51 --- /dev/null +++ b/src/client/hooks/vue/usePluginStateVue.ts @@ -0,0 +1,28 @@ +import { UnwrapRef, ref, watch } from 'vue'; + +import { lobeChat } from '@/client'; + +export const usePluginStateVue = (key: string, initialValue: T) => { + const value = ref(initialValue); + + watch( + () => key, + (newValue) => { + lobeChat.getPluginState(newValue).then((e) => { + if (!e) return; + + value.value = e; + }); + }, + { + immediate: true, + }, + ); + + const updateValue = (newValue: T) => { + value.value = newValue as UnwrapRef; + lobeChat.setPluginState(key, value); + }; + + return [value, updateValue] as const; +}; diff --git a/src/client/hooks/vue/useWatchPluginMessageVue.ts b/src/client/hooks/vue/useWatchPluginMessageVue.ts new file mode 100644 index 0000000..4c66677 --- /dev/null +++ b/src/client/hooks/vue/useWatchPluginMessageVue.ts @@ -0,0 +1,30 @@ +import { UnwrapRef, onMounted, ref } from 'vue'; + +import { PluginChannel } from '../../const'; +import { PluginRenderProps } from '../../type'; +import { onReceiveData } from '../../utils'; + +export const useWatchPluginMessageVue = () => { + const result = ref<{ data: T; loading: boolean }>({ + data: undefined as T, + loading: true, + }); + + const receiverData = (e: MessageEvent) => { + onReceiveData(e, (data: PluginRenderProps) => { + result.value = { data: data.content as UnwrapRef, loading: false }; + }); + }; + + onMounted(() => { + window?.addEventListener('message', receiverData); + + top?.postMessage({ type: PluginChannel.pluginReadyForRender }, '*'); + + return () => { + window?.removeEventListener('message', receiverData); + }; + }); + + return result; +}; From 760d582165b2ece827320e7a6d28bf51e1b97219 Mon Sep 17 00:00:00 2001 From: Marvin <454846659@qq.com> Date: Fri, 10 May 2024 18:19:30 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Revert=20"=E2=9C=A8=20feat:=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0vue=E7=9A=84hooks=E5=87=BD=E6=95=B0"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ac12d025d92921f499464023f55eaca85a478746. --- package.json | 3 +- src/client/hooks/index.ts | 1 - src/client/hooks/vue/index.ts | 4 --- .../hooks/vue/useOnStandalonePluginInitVue.ts | 15 ---------- src/client/hooks/vue/usePluginSettingsVue.ts | 20 ------------- src/client/hooks/vue/usePluginStateVue.ts | 28 ----------------- .../hooks/vue/useWatchPluginMessageVue.ts | 30 ------------------- 7 files changed, 1 insertion(+), 100 deletions(-) delete mode 100644 src/client/hooks/vue/index.ts delete mode 100644 src/client/hooks/vue/useOnStandalonePluginInitVue.ts delete mode 100644 src/client/hooks/vue/usePluginSettingsVue.ts delete mode 100644 src/client/hooks/vue/usePluginStateVue.ts delete mode 100644 src/client/hooks/vue/useWatchPluginMessageVue.ts diff --git a/package.json b/package.json index 8b022ab..ece6226 100644 --- a/package.json +++ b/package.json @@ -115,8 +115,7 @@ "stylelint": "^15", "ts-json-schema-generator": "^1.4.0", "typescript": "^5", - "vitest": "^1", - "vue": "^3.4.27" + "vitest": "^1" }, "peerDependencies": { "react": ">=18", diff --git a/src/client/hooks/index.ts b/src/client/hooks/index.ts index b9d07e9..42ef7d9 100644 --- a/src/client/hooks/index.ts +++ b/src/client/hooks/index.ts @@ -2,4 +2,3 @@ export * from './useOnStandalonePluginInit'; export * from './usePluginSettings'; export * from './usePluginState'; export * from './useWatchPluginMessage'; -export * from './vue'; diff --git a/src/client/hooks/vue/index.ts b/src/client/hooks/vue/index.ts deleted file mode 100644 index 6a45795..0000000 --- a/src/client/hooks/vue/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './useOnStandalonePluginInitVue'; -export * from './usePluginSettingsVue'; -export * from './usePluginStateVue'; -export * from './useWatchPluginMessageVue'; diff --git a/src/client/hooks/vue/useOnStandalonePluginInitVue.ts b/src/client/hooks/vue/useOnStandalonePluginInitVue.ts deleted file mode 100644 index 7db725e..0000000 --- a/src/client/hooks/vue/useOnStandalonePluginInitVue.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { onMounted } from 'vue'; - -import { PluginPayload, lobeChat } from '@/client'; - -export const useOnStandalonePluginInitVue = ( - callback: (payload: PluginPayload) => void, -) => { - onMounted(() => { - lobeChat.getPluginPayload().then((e) => { - if (!e) return; - - callback(e); - }); - }); -}; diff --git a/src/client/hooks/vue/usePluginSettingsVue.ts b/src/client/hooks/vue/usePluginSettingsVue.ts deleted file mode 100644 index a2eb7fd..0000000 --- a/src/client/hooks/vue/usePluginSettingsVue.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { UnwrapRef, onMounted, ref } from 'vue'; - -import { lobeChat } from '@/client'; - -export const usePluginSettingsVue = (initialValue: T) => { - const value = ref(initialValue); - onMounted(() => { - lobeChat.getPluginSettings().then((e) => { - if (!e) return; - value.value = e; - }); - }); - - const updateValue = (newValue: T) => { - value.value = newValue as UnwrapRef; - lobeChat.setPluginSettings(newValue); - }; - - return [value, updateValue] as const; -}; diff --git a/src/client/hooks/vue/usePluginStateVue.ts b/src/client/hooks/vue/usePluginStateVue.ts deleted file mode 100644 index 8d2ec51..0000000 --- a/src/client/hooks/vue/usePluginStateVue.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { UnwrapRef, ref, watch } from 'vue'; - -import { lobeChat } from '@/client'; - -export const usePluginStateVue = (key: string, initialValue: T) => { - const value = ref(initialValue); - - watch( - () => key, - (newValue) => { - lobeChat.getPluginState(newValue).then((e) => { - if (!e) return; - - value.value = e; - }); - }, - { - immediate: true, - }, - ); - - const updateValue = (newValue: T) => { - value.value = newValue as UnwrapRef; - lobeChat.setPluginState(key, value); - }; - - return [value, updateValue] as const; -}; diff --git a/src/client/hooks/vue/useWatchPluginMessageVue.ts b/src/client/hooks/vue/useWatchPluginMessageVue.ts deleted file mode 100644 index 4c66677..0000000 --- a/src/client/hooks/vue/useWatchPluginMessageVue.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { UnwrapRef, onMounted, ref } from 'vue'; - -import { PluginChannel } from '../../const'; -import { PluginRenderProps } from '../../type'; -import { onReceiveData } from '../../utils'; - -export const useWatchPluginMessageVue = () => { - const result = ref<{ data: T; loading: boolean }>({ - data: undefined as T, - loading: true, - }); - - const receiverData = (e: MessageEvent) => { - onReceiveData(e, (data: PluginRenderProps) => { - result.value = { data: data.content as UnwrapRef, loading: false }; - }); - }; - - onMounted(() => { - window?.addEventListener('message', receiverData); - - top?.postMessage({ type: PluginChannel.pluginReadyForRender }, '*'); - - return () => { - window?.removeEventListener('message', receiverData); - }; - }); - - return result; -}; From 1e914ede7f2eb3ef73424c6a06a3f086aa89b2ca Mon Sep 17 00:00:00 2001 From: Marvin <454846659@qq.com> Date: Fri, 10 May 2024 18:26:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=A2=9E=E5=8A=A0vue?= =?UTF-8?q?=E7=9A=84hooks=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- src/client/hooks/index.ts | 1 + src/client/hooks/vue/index.ts | 4 +++ .../hooks/vue/useOnStandalonePluginInitVue.ts | 15 ++++++++ src/client/hooks/vue/usePluginSettingsVue.ts | 26 ++++++++++++++ src/client/hooks/vue/usePluginStateVue.ts | 34 +++++++++++++++++++ .../hooks/vue/useWatchPluginMessageVue.ts | 30 ++++++++++++++++ 7 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/client/hooks/vue/index.ts create mode 100644 src/client/hooks/vue/useOnStandalonePluginInitVue.ts create mode 100644 src/client/hooks/vue/usePluginSettingsVue.ts create mode 100644 src/client/hooks/vue/usePluginStateVue.ts create mode 100644 src/client/hooks/vue/useWatchPluginMessageVue.ts diff --git a/package.json b/package.json index ece6226..8b022ab 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,8 @@ "stylelint": "^15", "ts-json-schema-generator": "^1.4.0", "typescript": "^5", - "vitest": "^1" + "vitest": "^1", + "vue": "^3.4.27" }, "peerDependencies": { "react": ">=18", diff --git a/src/client/hooks/index.ts b/src/client/hooks/index.ts index 42ef7d9..b9d07e9 100644 --- a/src/client/hooks/index.ts +++ b/src/client/hooks/index.ts @@ -2,3 +2,4 @@ export * from './useOnStandalonePluginInit'; export * from './usePluginSettings'; export * from './usePluginState'; export * from './useWatchPluginMessage'; +export * from './vue'; diff --git a/src/client/hooks/vue/index.ts b/src/client/hooks/vue/index.ts new file mode 100644 index 0000000..6a45795 --- /dev/null +++ b/src/client/hooks/vue/index.ts @@ -0,0 +1,4 @@ +export * from './useOnStandalonePluginInitVue'; +export * from './usePluginSettingsVue'; +export * from './usePluginStateVue'; +export * from './useWatchPluginMessageVue'; diff --git a/src/client/hooks/vue/useOnStandalonePluginInitVue.ts b/src/client/hooks/vue/useOnStandalonePluginInitVue.ts new file mode 100644 index 0000000..7db725e --- /dev/null +++ b/src/client/hooks/vue/useOnStandalonePluginInitVue.ts @@ -0,0 +1,15 @@ +import { onMounted } from 'vue'; + +import { PluginPayload, lobeChat } from '@/client'; + +export const useOnStandalonePluginInitVue = ( + callback: (payload: PluginPayload) => void, +) => { + onMounted(() => { + lobeChat.getPluginPayload().then((e) => { + if (!e) return; + + callback(e); + }); + }); +}; diff --git a/src/client/hooks/vue/usePluginSettingsVue.ts b/src/client/hooks/vue/usePluginSettingsVue.ts new file mode 100644 index 0000000..adc2db2 --- /dev/null +++ b/src/client/hooks/vue/usePluginSettingsVue.ts @@ -0,0 +1,26 @@ +import { UnwrapRef, onMounted, ref, watch } from 'vue'; + +import { lobeChat } from '@/client'; + +export const usePluginSettingsVue = (initialValue: T) => { + const value = ref(initialValue); + onMounted(() => { + lobeChat.getPluginSettings().then((e) => { + if (!e) return; + value.value = e; + }); + }); + + const updateValue = (newValue: T) => { + value.value = newValue as UnwrapRef; + }; + + watch( + () => value.value, + (newValue) => { + lobeChat.setPluginSettings(newValue); + }, + ); + + return [value, updateValue] as const; +}; diff --git a/src/client/hooks/vue/usePluginStateVue.ts b/src/client/hooks/vue/usePluginStateVue.ts new file mode 100644 index 0000000..3f7adec --- /dev/null +++ b/src/client/hooks/vue/usePluginStateVue.ts @@ -0,0 +1,34 @@ +import { UnwrapRef, ref, watch } from 'vue'; + +import { lobeChat } from '@/client'; + +export const usePluginStateVue = (key: string, initialValue: T) => { + const value = ref(initialValue); + + watch( + () => key, + (newValue) => { + lobeChat.getPluginState(newValue).then((e) => { + if (!e) return; + + value.value = e; + }); + }, + { + immediate: true, + }, + ); + + const updateValue = (newValue: T) => { + value.value = newValue as UnwrapRef; + }; + + watch( + () => value.value, + (newValue) => { + lobeChat.setPluginState(key, newValue); + }, + ); + + return [value, updateValue] as const; +}; diff --git a/src/client/hooks/vue/useWatchPluginMessageVue.ts b/src/client/hooks/vue/useWatchPluginMessageVue.ts new file mode 100644 index 0000000..462bf35 --- /dev/null +++ b/src/client/hooks/vue/useWatchPluginMessageVue.ts @@ -0,0 +1,30 @@ +import { UnwrapRef, onMounted, onUnmounted, ref } from 'vue'; + +import { PluginChannel } from '../../const'; +import { PluginRenderProps } from '../../type'; +import { onReceiveData } from '../../utils'; + +export const useWatchPluginMessageVue = () => { + const result = ref<{ data: T; loading: boolean }>({ + data: undefined as T, + loading: true, + }); + + const receiverData = (e: MessageEvent) => { + onReceiveData(e, (data: PluginRenderProps) => { + result.value = { data: data.content as UnwrapRef, loading: false }; + }); + }; + + onMounted(() => { + window?.addEventListener('message', receiverData); + + top?.postMessage({ type: PluginChannel.pluginReadyForRender }, '*'); + }); + + onUnmounted(() => { + window?.removeEventListener('message', receiverData); + }); + + return result; +}; From 0b018b9c9d0c35eae85a120729b1e54bd77cef18 Mon Sep 17 00:00:00 2001 From: Marvin <454846659@qq.com> Date: Thu, 16 May 2024 17:39:56 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E7=BB=93=E6=9E=84=EF=BC=8C=E9=9B=86=E4=B8=AD=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=88=B0vue=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/hooks/index.ts | 2 +- src/client/hooks/vue/index.ts | 8 ++--- ...nitVue.ts => useOnStandalonePluginInit.ts} | 2 +- ...ginSettingsVue.ts => usePluginSettings.ts} | 4 +-- src/client/hooks/vue/usePluginState.ts | 28 +++++++++++++++ src/client/hooks/vue/usePluginStateVue.ts | 34 ------------------- ...MessageVue.ts => useWatchPluginMessage.ts} | 4 +-- 7 files changed, 38 insertions(+), 44 deletions(-) rename src/client/hooks/vue/{useOnStandalonePluginInitVue.ts => useOnStandalonePluginInit.ts} (82%) rename src/client/hooks/vue/{usePluginSettingsVue.ts => usePluginSettings.ts} (81%) create mode 100644 src/client/hooks/vue/usePluginState.ts delete mode 100644 src/client/hooks/vue/usePluginStateVue.ts rename src/client/hooks/vue/{useWatchPluginMessageVue.ts => useWatchPluginMessage.ts} (90%) diff --git a/src/client/hooks/index.ts b/src/client/hooks/index.ts index b9d07e9..c8f27d4 100644 --- a/src/client/hooks/index.ts +++ b/src/client/hooks/index.ts @@ -2,4 +2,4 @@ export * from './useOnStandalonePluginInit'; export * from './usePluginSettings'; export * from './usePluginState'; export * from './useWatchPluginMessage'; -export * from './vue'; +export * as vue from './vue'; diff --git a/src/client/hooks/vue/index.ts b/src/client/hooks/vue/index.ts index 6a45795..42ef7d9 100644 --- a/src/client/hooks/vue/index.ts +++ b/src/client/hooks/vue/index.ts @@ -1,4 +1,4 @@ -export * from './useOnStandalonePluginInitVue'; -export * from './usePluginSettingsVue'; -export * from './usePluginStateVue'; -export * from './useWatchPluginMessageVue'; +export * from './useOnStandalonePluginInit'; +export * from './usePluginSettings'; +export * from './usePluginState'; +export * from './useWatchPluginMessage'; diff --git a/src/client/hooks/vue/useOnStandalonePluginInitVue.ts b/src/client/hooks/vue/useOnStandalonePluginInit.ts similarity index 82% rename from src/client/hooks/vue/useOnStandalonePluginInitVue.ts rename to src/client/hooks/vue/useOnStandalonePluginInit.ts index 7db725e..07afeed 100644 --- a/src/client/hooks/vue/useOnStandalonePluginInitVue.ts +++ b/src/client/hooks/vue/useOnStandalonePluginInit.ts @@ -2,7 +2,7 @@ import { onMounted } from 'vue'; import { PluginPayload, lobeChat } from '@/client'; -export const useOnStandalonePluginInitVue = ( +export const useOnStandalonePluginInit = ( callback: (payload: PluginPayload) => void, ) => { onMounted(() => { diff --git a/src/client/hooks/vue/usePluginSettingsVue.ts b/src/client/hooks/vue/usePluginSettings.ts similarity index 81% rename from src/client/hooks/vue/usePluginSettingsVue.ts rename to src/client/hooks/vue/usePluginSettings.ts index adc2db2..e106f32 100644 --- a/src/client/hooks/vue/usePluginSettingsVue.ts +++ b/src/client/hooks/vue/usePluginSettings.ts @@ -2,7 +2,7 @@ import { UnwrapRef, onMounted, ref, watch } from 'vue'; import { lobeChat } from '@/client'; -export const usePluginSettingsVue = (initialValue: T) => { +export const usePluginSettings = (initialValue: T) => { const value = ref(initialValue); onMounted(() => { lobeChat.getPluginSettings().then((e) => { @@ -22,5 +22,5 @@ export const usePluginSettingsVue = (initialValue: T) => { }, ); - return [value, updateValue] as const; + return [value.value, updateValue] as const; }; diff --git a/src/client/hooks/vue/usePluginState.ts b/src/client/hooks/vue/usePluginState.ts new file mode 100644 index 0000000..acfe07a --- /dev/null +++ b/src/client/hooks/vue/usePluginState.ts @@ -0,0 +1,28 @@ +import { UnwrapRef, ref, watch, watchEffect } from 'vue'; + +import { lobeChat } from '@/client'; + +export const usePluginState = (key: string, initialValue: T) => { + const value = ref(initialValue); + + watchEffect(() => { + lobeChat.getPluginState(key).then((e) => { + if (!e) return; + + value.value = e; + }); + }); + + const updateValue = (newValue: T) => { + value.value = newValue as UnwrapRef; + }; + + watch( + () => value.value, + (newValue) => { + lobeChat.setPluginState(key, newValue); + }, + ); + + return [value.value, updateValue] as const; +}; diff --git a/src/client/hooks/vue/usePluginStateVue.ts b/src/client/hooks/vue/usePluginStateVue.ts deleted file mode 100644 index 3f7adec..0000000 --- a/src/client/hooks/vue/usePluginStateVue.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { UnwrapRef, ref, watch } from 'vue'; - -import { lobeChat } from '@/client'; - -export const usePluginStateVue = (key: string, initialValue: T) => { - const value = ref(initialValue); - - watch( - () => key, - (newValue) => { - lobeChat.getPluginState(newValue).then((e) => { - if (!e) return; - - value.value = e; - }); - }, - { - immediate: true, - }, - ); - - const updateValue = (newValue: T) => { - value.value = newValue as UnwrapRef; - }; - - watch( - () => value.value, - (newValue) => { - lobeChat.setPluginState(key, newValue); - }, - ); - - return [value, updateValue] as const; -}; diff --git a/src/client/hooks/vue/useWatchPluginMessageVue.ts b/src/client/hooks/vue/useWatchPluginMessage.ts similarity index 90% rename from src/client/hooks/vue/useWatchPluginMessageVue.ts rename to src/client/hooks/vue/useWatchPluginMessage.ts index 462bf35..c8875cb 100644 --- a/src/client/hooks/vue/useWatchPluginMessageVue.ts +++ b/src/client/hooks/vue/useWatchPluginMessage.ts @@ -4,7 +4,7 @@ import { PluginChannel } from '../../const'; import { PluginRenderProps } from '../../type'; import { onReceiveData } from '../../utils'; -export const useWatchPluginMessageVue = () => { +export const useWatchPluginMessage = () => { const result = ref<{ data: T; loading: boolean }>({ data: undefined as T, loading: true, @@ -26,5 +26,5 @@ export const useWatchPluginMessageVue = () => { window?.removeEventListener('message', receiverData); }); - return result; + return result.value; }; From 901e45caf892b697946ea7caa883ac67f256b32c Mon Sep 17 00:00:00 2001 From: Marvin <454846659@qq.com> Date: Thu, 23 May 2024 10:05:24 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=90=9B=20fix:=20vue=E7=9A=84hooks?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=9B=B4=E6=94=B9=E4=B8=BA=E4=BB=8Eclient-vu?= =?UTF-8?q?e=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ client-vue.ts | 1 + package.json | 2 +- src/client/hooks/index.ts | 1 - 4 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 client-vue.ts diff --git a/.gitignore b/.gitignore index ca8aa31..c88fa88 100644 --- a/.gitignore +++ b/.gitignore @@ -48,5 +48,7 @@ client.d.ts client.js openapi.d.ts openapi.js +client-vue.d.ts +client-vue.js bun.lockb schema.json diff --git a/client-vue.ts b/client-vue.ts new file mode 100644 index 0000000..1f0fece --- /dev/null +++ b/client-vue.ts @@ -0,0 +1 @@ +export * from './lib/client/hooks/vue'; diff --git a/package.json b/package.json index 8b022ab..ff1f74a 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ ], "scripts": { "build": "father build && npm run build:entry && npm run build:schema", - "build:entry": "tsc client.ts --declaration && tsc openapi.ts --declaration", + "build:entry": "tsc client.ts --declaration && tsc openapi.ts --declaration && tsc client-vue.ts --declaration", "build:schema": "ts-json-schema-generator --path src/types/manifest.ts --type LobeChatPluginManifest -o schema.json", "build:watch": "father dev", "ci": "npm run lint && npm run type-check && npm run doctor", diff --git a/src/client/hooks/index.ts b/src/client/hooks/index.ts index c8f27d4..42ef7d9 100644 --- a/src/client/hooks/index.ts +++ b/src/client/hooks/index.ts @@ -2,4 +2,3 @@ export * from './useOnStandalonePluginInit'; export * from './usePluginSettings'; export * from './usePluginState'; export * from './useWatchPluginMessage'; -export * as vue from './vue';