remove markdown element from menu until fixed. Added copy link & open in new tab options in embedded element URL

This commit is contained in:
Jeff Emmett 2024-12-12 20:45:37 -05:00
parent d8bc094b45
commit 1e688c8aa5
5 changed files with 94 additions and 57 deletions

View File

@ -28,9 +28,9 @@ const customShapeUtils = [
ChatBoxShape, ChatBoxShape,
VideoChatShape, VideoChatShape,
EmbedShape, EmbedShape,
MarkdownShape, //MarkdownShape,
] ]
const customTools = [ChatBoxTool, VideoChatTool, EmbedTool, MarkdownTool] const customTools = [ChatBoxTool, VideoChatTool, EmbedTool] //, MarkdownTool]
const callObject = Daily.createCallObject() const callObject = Daily.createCallObject()

View File

@ -21,8 +21,8 @@ import { handleInitialPageLoad } from "@/utils/handleInitialPageLoad"
// Default to production URL if env var isn't available // Default to production URL if env var isn't available
export const WORKER_URL = "https://jeffemmett-canvas.jeffemmett.workers.dev" export const WORKER_URL = "https://jeffemmett-canvas.jeffemmett.workers.dev"
const shapeUtils = [ChatBoxShape, VideoChatShape, EmbedShape, MarkdownShape] const shapeUtils = [ChatBoxShape, VideoChatShape, EmbedShape] //, MarkdownShape]
const tools = [ChatBoxTool, VideoChatTool, EmbedTool, MarkdownTool] // Array of tools const tools = [ChatBoxTool, VideoChatTool, EmbedTool] //, MarkdownTool]
export function Board() { export function Board() {
const { slug } = useParams<{ slug: string }>() const { slug } = useParams<{ slug: string }>()

View File

@ -96,6 +96,7 @@ export class EmbedShape extends BaseBoxShapeUtil<IEmbedShape> {
component(shape: IEmbedShape) { component(shape: IEmbedShape) {
const [inputUrl, setInputUrl] = useState(shape.props.url || "") const [inputUrl, setInputUrl] = useState(shape.props.url || "")
const [error, setError] = useState("") const [error, setError] = useState("")
const [copyStatus, setCopyStatus] = useState(false)
const handleSubmit = useCallback( const handleSubmit = useCallback(
(e: React.FormEvent) => { (e: React.FormEvent) => {
@ -220,7 +221,7 @@ export class EmbedShape extends BaseBoxShapeUtil<IEmbedShape> {
<iframe <iframe
src={transformUrl(shape.props.url)} src={transformUrl(shape.props.url)}
width={shape.props.w} width={shape.props.w}
height={shape.props.h - 40} height={shape.props.h}
style={{ border: "none" }} style={{ border: "none" }}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen allowFullScreen
@ -228,53 +229,89 @@ export class EmbedShape extends BaseBoxShapeUtil<IEmbedShape> {
referrerPolicy="no-referrer" referrerPolicy="no-referrer"
/> />
</div> </div>
<a <div
href={shape.props.url}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => {
console.log("Link clicked, URL:", shape.props.url)
e.preventDefault()
e.stopPropagation()
window.top?.open(
shape.props.url || "",
"_blank",
"noopener,noreferrer",
)
}}
onPointerDown={(e) => {
e.preventDefault()
e.stopPropagation()
}}
onMouseDown={(e) => {
e.preventDefault()
e.stopPropagation()
}}
onTouchStart={(e) => {
e.preventDefault()
e.stopPropagation()
}}
style={{ style={{
display: "block", display: "flex",
justifyContent: "space-between",
alignItems: "center",
padding: "8px", padding: "8px",
textAlign: "center",
color: "#1976d2",
textDecoration: "none",
fontSize: "12px",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
cursor: "pointer",
touchAction: "manipulation",
WebkitTapHighlightColor: "rgba(0,0,0,0)",
userSelect: "none",
minHeight: "24px", minHeight: "24px",
pointerEvents: "all", fontSize: "12px",
zIndex: 999999, position: "absolute",
bottom: "15px",
left: "15px",
right: "15px",
backgroundColor: "rgba(255, 255, 255, 0.9)",
borderRadius: "4px",
}} }}
> >
{shape.props.url} <span
</a> style={{
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
flex: 1,
marginRight: "8px",
color: "#666",
}}
>
{shape.props.url}
</span>
<div
style={{
display: "flex",
gap: "8px",
pointerEvents: "all",
}}
>
<button
onClick={async (e) => {
e.preventDefault()
e.stopPropagation()
try {
await navigator.clipboard.writeText(shape.props.url || "")
setCopyStatus(true)
setTimeout(() => setCopyStatus(false), 2000)
} catch (err) {
console.error("Failed to copy:", err)
}
}}
style={{
border: "none",
background: "transparent",
color: "#1976d2",
cursor: "pointer",
padding: "0 4px",
fontSize: "12px",
}}
onPointerDown={(e) => e.stopPropagation()}
>
{copyStatus ? "Copied" : "Copy link"}
</button>
<button
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
window.top?.open(
shape.props.url || "",
"_blank",
"noopener,noreferrer",
)
}}
style={{
border: "none",
background: "transparent",
color: "#1976d2",
cursor: "pointer",
padding: "0 4px",
fontSize: "12px",
}}
onPointerDown={(e) => e.stopPropagation()}
>
Open in new tab
</button>
</div>
</div>
</div> </div>
) )
} }

View File

@ -130,7 +130,7 @@ export function CustomContextMenu(props: TLUiContextMenuProps) {
editor.setCurrentTool("Embed") editor.setCurrentTool("Embed")
}} }}
/> />
<TldrawUiMenuItem {/* <TldrawUiMenuItem
id="markdown" id="markdown"
label="Create Markdown" label="Create Markdown"
icon="markdown" icon="markdown"
@ -139,7 +139,7 @@ export function CustomContextMenu(props: TLUiContextMenuProps) {
onSelect={() => { onSelect={() => {
editor.setCurrentTool("Markdown") editor.setCurrentTool("Markdown")
}} }}
/> /> */}
</TldrawUiMenuGroup> </TldrawUiMenuGroup>
{/* Frame Controls */} {/* Frame Controls */}

View File

@ -36,14 +36,14 @@ export const overrides: TLUiOverrides = {
readonlyOk: true, readonlyOk: true,
onSelect: () => editor.setCurrentTool("Embed"), onSelect: () => editor.setCurrentTool("Embed"),
}, },
Markdown: { // Markdown: {
id: "Markdown", // id: "Markdown",
icon: "markdown", // icon: "markdown",
label: "Markdown", // label: "Markdown",
kbd: "alt+m", // kbd: "alt+m",
readonlyOk: true, // readonlyOk: true,
onSelect: () => editor.setCurrentTool("Markdown"), // onSelect: () => editor.setCurrentTool("Markdown"),
}, // },
} }
}, },
actions(editor, actions) { actions(editor, actions) {