From 2932ae57eacec5d89688afdf15756ea41c0600c6 Mon Sep 17 00:00:00 2001 From: grnd-alt Date: Wed, 17 Jul 2024 09:52:02 +0200 Subject: [PATCH] use NcReferenceList in whiteboard Signed-off-by: grnd-alt --- src/App.tsx | 8 ++++++++ src/Embeddable.tsx | 20 ++++++++++++++++++++ src/VueWrapper.tsx | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/Embeddable.tsx create mode 100644 src/VueWrapper.tsx diff --git a/src/App.tsx b/src/App.tsx index 2d0678e..22b666c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -20,6 +20,8 @@ import type { ExcalidrawInitialDataState, } from '@excalidraw/excalidraw/types/types' import { Collab } from './collaboration/collab' +import Embeddable from './Embeddable' +import type { NonDeletedExcalidrawElement } from '@excalidraw/excalidraw/types/element/types' import type { ResolvablePromise } from '@excalidraw/excalidraw/types/utils' import type { NonDeletedExcalidrawElement } from '@excalidraw/excalidraw/types/element/types' interface WhiteboardAppProps { @@ -122,10 +124,16 @@ export default function App({ fileId, isEmbedded }: WhiteboardAppProps) { ) } + const renderEmbeddableTest = (element: NonDeletedExcalidrawElement) => { + return React.createElement(Embeddable,{react: React, url: element.link}) + } + return (
true} + renderEmbeddable={(element) => renderEmbeddableTest(element)} excalidrawAPI={(api: ExcalidrawImperativeAPI) => { console.log(api) console.log('Setting API') diff --git a/src/Embeddable.tsx b/src/Embeddable.tsx new file mode 100644 index 0000000..60e2d7e --- /dev/null +++ b/src/Embeddable.tsx @@ -0,0 +1,20 @@ +import VueWrapper from "./VueWrapper" + +/** + * + */ +export default function(props) { + const {react} = props + let testing = react.useRef('') + + react.useEffect(()=> { + fetch("/").then(async resp => { + testing.current = await resp.text() + }) + },[]) + + const referenceProps = {text: props.url, limit: "1", interactive: true} + return ( + + ) +} diff --git a/src/VueWrapper.tsx b/src/VueWrapper.tsx new file mode 100644 index 0000000..5e0a0aa --- /dev/null +++ b/src/VueWrapper.tsx @@ -0,0 +1,47 @@ +import { NcReferenceList } from '@nextcloud/vue/dist/Components/NcRichText.js' +import Vue from 'vue' + +const VueWrapper = function( + { componentProps }) { + const vueRef = React.useRef(null) + const [vueInstance, setVueInstance] = React.useState(undefined) + + React.useEffect(() => { + /** + * + */ + async function createVueInstance() { + } + + createVueInstance() + + setVueInstance(new Vue({ + el: vueRef.current, + data() { + return { + props: componentProps, + } + }, + render(h) { + return h(NcReferenceList, { + props: this.props, + }) + }, + })) + + return () => { + vueInstance?.$destroy() + } + }, []) + + React.useEffect(() => { + if (vueInstance) { + const keys = Object.keys(componentProps) + keys.forEach(key => vueInstance.props[key] = componentProps[key]) + } + }, [Object.values(componentProps)]) + + return
+} + +export default VueWrapper