Просмотр исходного кода

fix: make backlinks display nicer on small shapes

Peng Xiao 3 лет назад
Родитель
Сommit
623893bf9c

+ 1 - 2
src/main/frontend/components/whiteboard.cljs

@@ -70,7 +70,7 @@
     [:div.inline-block.dropdown-anchor {:ref anchor-ref}
     [:div.inline-block.dropdown-anchor {:ref anchor-ref}
      label
      label
      (if portal?
      (if portal?
-       ;; FIXME: refactor the following code 
+       ;; FIXME: refactor the following code ...
        (ui/portal
        (ui/portal
         [:div.fixed.shadow-lg.color-level.px-2.rounded-lg.transition.md:w-64.lg:w-128.overflow-auto
         [:div.fixed.shadow-lg.color-level.px-2.rounded-lg.transition.md:w-64.lg:w-128.overflow-auto
          {:ref (juxt content-ref click-outside-ref)
          {:ref (juxt content-ref click-outside-ref)
@@ -108,7 +108,6 @@
      children open? #(set-open-flag 0) portal?)))
      children open? #(set-open-flag 0) portal?)))
 
 
 ;; TODO: move to frontend.components.reference
 ;; TODO: move to frontend.components.reference
-;; TODO: reactivity when ref count change
 (rum/defc references-count < rum/reactive db-mixins/query
 (rum/defc references-count < rum/reactive db-mixins/query
   "Shows a references count for any block or page.
   "Shows a references count for any block or page.
    When clicked, a dropdown menu will show the reference details"
    When clicked, a dropdown menu will show the reference details"

+ 21 - 21
tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx

@@ -42,7 +42,7 @@ export const contextBarActionTypes = [
   'LogseqPortalViewMode',
   'LogseqPortalViewMode',
   'ArrowMode',
   'ArrowMode',
   'OpenPage',
   'OpenPage',
-  'References',
+  'Links',
 ] as const
 ] as const
 
 
 type ContextBarActionType = typeof contextBarActionTypes[number]
 type ContextBarActionType = typeof contextBarActionTypes[number]
@@ -51,7 +51,7 @@ const singleShapeActions: ContextBarActionType[] = [
   'YoutubeLink',
   'YoutubeLink',
   'IFrameSource',
   'IFrameSource',
   'OpenPage',
   'OpenPage',
-  'References',
+  'Links',
 ]
 ]
 
 
 const contextBarActionMapping = new Map<ContextBarActionType, React.FC>()
 const contextBarActionMapping = new Map<ContextBarActionType, React.FC>()
@@ -66,20 +66,20 @@ export const shapeMapping: Record<ShapeType, ContextBarActionType[]> = {
     'ScaleLevel',
     'ScaleLevel',
     'OpenPage',
     'OpenPage',
     'AutoResizing',
     'AutoResizing',
-    'References',
+    'Links',
   ],
   ],
-  youtube: ['YoutubeLink', 'References'],
-  iframe: ['IFrameSource', 'References'],
-  box: ['Swatch', 'NoFill', 'StrokeType', 'References'],
-  ellipse: ['Swatch', 'NoFill', 'StrokeType', 'References'],
-  polygon: ['Swatch', 'NoFill', 'StrokeType', 'References'],
-  line: ['Edit', 'Swatch', 'ArrowMode', 'References'],
-  pencil: ['Swatch', 'References'],
-  highlighter: ['Swatch', 'References'],
-  text: ['Edit', 'Swatch', 'ScaleLevel', 'AutoResizing', 'TextStyle', 'References'],
-  html: ['ScaleLevel', 'AutoResizing', 'References'],
-  image: ['References'],
-  video: ['References'],
+  youtube: ['YoutubeLink', 'Links'],
+  iframe: ['IFrameSource', 'Links'],
+  box: ['Swatch', 'NoFill', 'StrokeType', 'Links'],
+  ellipse: ['Swatch', 'NoFill', 'StrokeType', 'Links'],
+  polygon: ['Swatch', 'NoFill', 'StrokeType', 'Links'],
+  line: ['Edit', 'Swatch', 'ArrowMode', 'Links'],
+  pencil: ['Swatch', 'Links'],
+  highlighter: ['Swatch', 'Links'],
+  text: ['Edit', 'Swatch', 'ScaleLevel', 'AutoResizing', 'TextStyle', 'Links'],
+  html: ['ScaleLevel', 'AutoResizing', 'Links'],
+  image: ['Links'],
+  video: ['Links'],
 }
 }
 
 
 export const withFillShapes = Object.entries(shapeMapping)
 export const withFillShapes = Object.entries(shapeMapping)
@@ -500,7 +500,7 @@ const TextStyleAction = observer(() => {
   )
   )
 })
 })
 
 
-const ReferencesAction = observer(() => {
+const LinksAction = observer(() => {
   const app = useApp<Shape>()
   const app = useApp<Shape>()
   const shape = app.selectedShapesArray[0]
   const shape = app.selectedShapesArray[0]
 
 
@@ -525,14 +525,14 @@ const ReferencesAction = observer(() => {
         className="px-2 tl-button"
         className="px-2 tl-button"
         pressed={show}
         pressed={show}
         onPressedChange={s => setShow(s)}
         onPressedChange={s => setShow(s)}
-        title="Open References and Links"
+        title="Open References & Links"
       >
       >
         <TablerIcon name="link" />
         <TablerIcon name="link" />
-        {hasLinks && <div className="tl-shape-references-count">{shape.props.refs?.length}</div>}
+        {hasLinks && <div className="tl-shape-links-count">{shape.props.refs?.length}</div>}
       </ToggleInput>
       </ToggleInput>
 
 
       {show && (
       {show && (
-        <div className="tl-shape-references-panel">
+        <div className="tl-shape-links-panel">
           <TextInput
           <TextInput
             title="Website Url"
             title="Website Url"
             className="tl-iframe-src"
             className="tl-iframe-src"
@@ -553,7 +553,7 @@ const ReferencesAction = observer(() => {
           </div>
           </div>
           {shape.props.refs?.map((ref, i) => {
           {shape.props.refs?.map((ref, i) => {
             return (
             return (
-              <div className="tl-shape-references-panel-item">
+              <div className="tl-shape-links-panel-item">
                 <div>{ref}</div>
                 <div>{ref}</div>
                 <div className="flex-1" />
                 <div className="flex-1" />
                 <Button
                 <Button
@@ -593,7 +593,7 @@ contextBarActionMapping.set('Swatch', SwatchAction)
 contextBarActionMapping.set('StrokeType', StrokeTypeAction)
 contextBarActionMapping.set('StrokeType', StrokeTypeAction)
 contextBarActionMapping.set('ArrowMode', ArrowModeAction)
 contextBarActionMapping.set('ArrowMode', ArrowModeAction)
 contextBarActionMapping.set('TextStyle', TextStyleAction)
 contextBarActionMapping.set('TextStyle', TextStyleAction)
-contextBarActionMapping.set('References', ReferencesAction)
+contextBarActionMapping.set('Links', LinksAction)
 
 
 const getContextBarActionTypes = (type: ShapeType) => {
 const getContextBarActionTypes = (type: ShapeType) => {
   return (shapeMapping[type] ?? []).filter(isNonNullable)
   return (shapeMapping[type] ?? []).filter(isNonNullable)

+ 27 - 5
tldraw/apps/tldraw-logseq/src/styles.css

@@ -988,19 +988,41 @@ html[data-theme='dark'] {
   }
   }
 }
 }
 
 
-.tl-reference-count-container {
-  @apply inline-flex items-center justify-center p-1;
+.tl-references-count-container {
+  z-index: 10003;
+}
+
+.tl-references-count {
+  @apply inline-flex items-center justify-center p-1 transition-all;
   background-color: var(--color-selectedFill);
   background-color: var(--color-selectedFill);
+
   border-top-right-radius: 6px;
   border-top-right-radius: 6px;
   border-bottom-right-radius: 6px;
   border-bottom-right-radius: 6px;
+
+
+  &:hover, &.open {
+    @apply p-1.5;
+  }
+}
+
+.tl-references-count-rounded {
+  border-radius: 50%;
+  width: 32px;
+  height: 32px;
+  transform: translate(4px, -6px);
+
+  &:hover, &.open {
+    height: 36px;
+    width: 36px;
+  }
 }
 }
 
 
-.tl-shape-references-count {
+.tl-shape-links-count {
   @apply px-1;
   @apply px-1;
   background-color: var(--ls-page-properties-background-color);
   background-color: var(--ls-page-properties-background-color);
 }
 }
 
 
-.tl-shape-references-panel {
+.tl-shape-links-panel {
   @apply absolute shadow-lg rounded-lg p-3;
   @apply absolute shadow-lg rounded-lg p-3;
   width: 320px;
   width: 320px;
   transform: translate(20px, -8px);
   transform: translate(20px, -8px);
@@ -1009,7 +1031,7 @@ html[data-theme='dark'] {
   background-color: var(--ls-secondary-background-color);
   background-color: var(--ls-secondary-background-color);
 }
 }
 
 
-.tl-shape-references-panel-item {
+.tl-shape-links-panel-item {
   @apply rounded py-1 px-4 flex items-center justify-center gap-1;
   @apply rounded py-1 px-4 flex items-center justify-center gap-1;
   color: var(--color-text);
   color: var(--color-text);
   background-color: var(--ls-tertiary-background-color);
   background-color: var(--ls-tertiary-background-color);

+ 3 - 0
tldraw/packages/core/src/lib/shapes/TLLineShape/TLLineShape.tsx

@@ -21,6 +21,9 @@ export class TLLineShape<
     makeObservable(this)
     makeObservable(this)
   }
   }
 
 
+  hideResizeHandles = true
+  hideRotateHandle = true
+
   static id = 'line'
   static id = 'line'
 
 
   static defaultProps: TLLineShapeProps = {
   static defaultProps: TLLineShapeProps = {

+ 14 - 5
tldraw/packages/react/src/components/ReferencesCountContainer/ReferencesCountContainer.tsx

@@ -11,10 +11,14 @@ export interface TLReferencesCountContainerProps<S extends TLReactShape> {
   shape: S
   shape: S
 }
 }
 
 
+// backlinks
 export const ReferencesCountContainer = observer(function ReferencesCountContainer<
 export const ReferencesCountContainer = observer(function ReferencesCountContainer<
   S extends TLReactShape
   S extends TLReactShape
 >({ bounds, hidden, shape }: TLReferencesCountContainerProps<S>) {
 >({ bounds, hidden, shape }: TLReferencesCountContainerProps<S>) {
   const {
   const {
+    viewport: {
+      camera: { zoom },
+    },
     components: { ReferencesCount },
     components: { ReferencesCount },
   } = useRendererContext()
   } = useRendererContext()
 
 
@@ -22,12 +26,12 @@ export const ReferencesCountContainer = observer(function ReferencesCountContain
 
 
   const stop: React.EventHandler<any> = e => e.stopPropagation()
   const stop: React.EventHandler<any> = e => e.stopPropagation()
 
 
+  const rounded = bounds.height * zoom < 50
+
   return (
   return (
     <Container
     <Container
-      style={{
-        zIndex: 10003,
-      }}
       bounds={bounds}
       bounds={bounds}
+      className="tl-references-count-container"
       aria-label="references-count-container"
       aria-label="references-count-container"
     >
     >
       <HTMLContainer>
       <HTMLContainer>
@@ -37,12 +41,17 @@ export const ReferencesCountContainer = observer(function ReferencesCountContain
             left: '100%',
             left: '100%',
             pointerEvents: 'all',
             pointerEvents: 'all',
             transformOrigin: 'left top',
             transformOrigin: 'left top',
-            transform: 'translateY(6px)',
+            transform: 'translateY(6px) scale(var(--tl-scale))',
           }}
           }}
           onPointerDown={stop}
           onPointerDown={stop}
           onWheelCapture={stop}
           onWheelCapture={stop}
+          title="Shape Backlinks"
         >
         >
-          <ReferencesCount className="tl-reference-count-container" id={shape.id} shape={shape} />
+          <ReferencesCount
+            className={'tl-references-count ' + (rounded ? 'tl-references-count-rounded' : '')}
+            id={shape.id}
+            shape={shape}
+          />
         </span>
         </span>
       </HTMLContainer>
       </HTMLContainer>
     </Container>
     </Container>