Skip to content

Commit

Permalink
use NcReferenceList in whiteboard
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <[email protected]>
  • Loading branch information
grnd-alt committed Jul 17, 2024
1 parent 568d917 commit 01c7672
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 26 deletions.
10 changes: 9 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { distance2d, resolvablePromise, withBatchedUpdates, withBatchedUpdatesTh

import type { ExcalidrawImperativeAPI } from '@excalidraw/excalidraw/types/types'
import { Collab } from './collaboration/collab'
import Embeddable from './Embeddable'
import type { NonDeletedExcalidrawElement } from '@excalidraw/excalidraw/types/element/types'

declare global {
interface Window {
Expand Down Expand Up @@ -467,10 +469,16 @@ export default function App({ fileId, isEmbedded }: WhiteboardAppProps) {
)
}

const renderEmbeddableTest = (element: NonDeletedExcalidrawElement) => {
return React.createElement(Embeddable,{react: React, url: element.link})
}

return (
<div className="App" ref={appRef}>
<div className="excalidraw-wrapper">
<Excalidraw
validateEmbeddable={()=>true}
renderEmbeddable={(element) => renderEmbeddableTest(element)}
excalidrawAPI={(api: ExcalidrawImperativeAPI) => {
console.log(api)
console.log('Setting API')
Expand All @@ -491,7 +499,7 @@ export default function App({ fileId, isEmbedded }: WhiteboardAppProps) {
loadScene: false,
},
}}
renderTopRightUI={renderTopRightUI}
// renderTopRightUI={renderTopRightUI}
onLinkOpen={onLinkOpen}
onPointerDown={onPointerDown}
onScrollChange={rerenderCommentIcons}
Expand Down
20 changes: 20 additions & 0 deletions src/Embeddable.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<VueWrapper componentProps={referenceProps} />
)
}
47 changes: 47 additions & 0 deletions src/VueWrapper.tsx
Original file line number Diff line number Diff line change
@@ -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 <div id="vue-component" ref={vueRef}></div>
}

export default VueWrapper
55 changes: 30 additions & 25 deletions src/sidebar/ExampleSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,38 @@

// https://github.com/excalidraw/excalidraw/blob/4dc4590f247a0a0d9c3f5d39fe09c00c5cef87bf/examples/excalidraw

import { useState } from "react";
import "./ExampleSidebar.scss";
import { useEffect, useState } from 'react'
import './ExampleSidebar.scss'
/**
*
* @param root0
* @param root0.children
*/
export default function Sidebar({ children }: { children: React.ReactNode }) {
const [open, setOpen] = useState(false);
const [open, setOpen] = useState(false)

return (
<>
<div id="mySidebar" className={`sidebar ${open ? "open" : ""}`}>
<button className="closebtn" onClick={() => setOpen(false)}>
return (
<>
<div id="mySidebar" className={`sidebar ${open ? 'open' : ''}`}>
<button className="closebtn" onClick={() => setOpen(false)}>
x
</button>
<div className="sidebar-links">
<button>Dummy Home</button>
<button>Dummy About</button>{" "}
</div>
</div>
<div className={`${open ? "sidebar-open" : ""}`}>
<button
className="openbtn"
onClick={() => {
setOpen(!open);
}}
>
</button>
<div className="sidebar-links">
<button>Dummy Home</button>
<button>Dummy About</button>{' '}
</div>
</div>
<div className={`${open ? 'sidebar-open' : ''}`}>
<button
className="openbtn"
onClick={() => {
setOpen(!open)
}}
>
Open Sidebar
</button>
{children}
</div>
</>
);
</button>
{children}
</div>
</>
)
}

0 comments on commit 01c7672

Please sign in to comment.