From 8f0eda94b125f1411785791812b1a6aa670ec054 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Sun, 20 Nov 2022 00:40:45 +0800 Subject: [PATCH] wip: forward links --- .../ContextBar/contextBarActionFactory.tsx | 89 +++++++++++++++---- tldraw/apps/tldraw-logseq/src/styles.css | 28 +++++- 2 files changed, 96 insertions(+), 21 deletions(-) diff --git a/tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx b/tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx index 5cca8ac7b..f5be73441 100644 --- a/tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx +++ b/tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx @@ -1,4 +1,4 @@ -import { Decoration, isNonNullable } from '@tldraw/core' +import { Decoration, isNonNullable, validUUID } from '@tldraw/core' import { useApp } from '@tldraw/react' import { observer } from 'mobx-react-lite' import React from 'react' @@ -503,25 +503,80 @@ const TextStyleAction = observer(() => { const ReferencesAction = observer(() => { const app = useApp() const shape = app.selectedShapesArray[0] - const handleChange = React.useCallback((e: React.ChangeEvent) => { - shape.update({ refs: [e.target.value] }) - app.persist() - }, []) - const [value, setValue] = React.useState(shape.props.refs?.[0] ?? '') + const [value, setValue] = React.useState('') + + const [show, setShow] = React.useState(false) + + const { handlers } = React.useContext(LogseqContext) + + const handleChange = () => { + const refs = shape.props.refs ?? [] + if (refs.includes(value)) return + shape.update({ refs: [...refs, value] }) + app.persist() + } + + const hasLinks = shape.props.refs && shape.props.refs.length > 0 return ( - - {shape.props.refs?.length} - { - setValue(e.target.value) - }} - onBlur={handleChange} - /> + + setShow(s)} + title="Open References and Links" + > + + {hasLinks &&
{shape.props.refs?.length}
} +
+ + {show && ( +
+ { + setValue(e.target.value) + }} + onKeyDown={e => { + if (e.key === 'Enter') { + handleChange() + } + e.stopPropagation() + }} + /> +
+ + Your Links +
+ {shape.props.refs?.map((ref, i) => { + return ( +
+
{ref}
+
+ + +
+ ) + })} +
+ )} ) }) diff --git a/tldraw/apps/tldraw-logseq/src/styles.css b/tldraw/apps/tldraw-logseq/src/styles.css index 594625a0e..8ffd213e2 100644 --- a/tldraw/apps/tldraw-logseq/src/styles.css +++ b/tldraw/apps/tldraw-logseq/src/styles.css @@ -246,10 +246,10 @@ html[data-theme='light'] { } .tl-button { - @apply relative flex items-center justify-center rounded border-0; + @apply relative flex items-center justify-center rounded border-0 gap-1; height: 32px; - width: 32px; + min-width: 32px; font-family: var(--ls-font-family); background: none; cursor: pointer; @@ -859,7 +859,7 @@ html[data-theme='dark'] { .tl-toggle-input { @apply inline-flex items-center justify-center; height: 32px; - width: 32px; + min-width: 32px; color: var(--ls-secondary-text-color); &:hover { @@ -993,4 +993,24 @@ html[data-theme='dark'] { background-color: var(--color-selectedFill); border-top-right-radius: 6px; border-bottom-right-radius: 6px; -} \ No newline at end of file +} + +.tl-shape-references-count { + @apply px-1; + background-color: var(--ls-page-properties-background-color); +} + +.tl-shape-references-panel { + @apply absolute shadow-lg rounded-lg p-3; + width: 320px; + transform: translate(20px, -8px); + left: 100%; + top: 0; + background-color: var(--ls-secondary-background-color); +} + +.tl-shape-references-panel-item { + @apply rounded py-1 px-4 flex items-center justify-center gap-1; + color: var(--color-text); + background-color: var(--ls-tertiary-background-color); +}