浏览代码

fix: maintain ordering of shapes

Peng Xiao 3 年之前
父节点
当前提交
ae7aaf4edd

+ 7 - 4
src/main/frontend/handler/whiteboard.cljs

@@ -45,8 +45,8 @@
 (defn- block->shape [block]
 (defn- block->shape [block]
   (:block/properties block))
   (:block/properties block))
 
 
-(defn- shape->block [shape page-name]
-  (let [properties (assoc shape :ls-type :whiteboard-shape)
+(defn- shape->block [shape page-name idx]
+  (let [properties (assoc shape :ls-type :whiteboard-shape :index idx)
         block {:block/page {:block/name (util/page-name-sanity-lc page-name)}
         block {:block/page {:block/name (util/page-name-sanity-lc page-name)}
                :block/parent {:block/name page-name}
                :block/parent {:block/name page-name}
                :block/properties properties}
                :block/properties properties}
@@ -68,7 +68,9 @@
                                                                       :block/properties [:ls-type]
                                                                       :block/properties [:ls-type]
                                                                       {:block/parent [:block/uuid]}]})
                                                                       {:block/parent [:block/uuid]}]})
         shapes (:shapes tldr-data)
         shapes (:shapes tldr-data)
-        blocks (mapv #(shape->block % page-name) shapes)
+        ;; we should maintain the order of the shapes in the page
+        ;; bring back/forward is depending on this ordering
+        blocks (map-indexed (fn [idx shape] (shape->block shape page-name idx)) shapes)
         block-ids (->> shapes
         block-ids (->> shapes
                        (map (fn [shape] (when (= (:blockType shape) "B")
                        (map (fn [shape] (when (= (:blockType shape) "B")
                                           (uuid (:pageId shape)))))
                                           (uuid (:pageId shape)))))
@@ -94,7 +96,8 @@
   (let [id (str (:block/uuid page-block))
   (let [id (str (:block/uuid page-block))
         shapes (->> blocks
         shapes (->> blocks
                     (map block->shape)
                     (map block->shape)
-                    (filter #(= :whiteboard-shape (:ls-type %))))
+                    (filter #(= :whiteboard-shape (:ls-type %)))
+                    (sort-by :index))
         page-properties (:block/properties page-block)
         page-properties (:block/properties page-block)
         assets (:assets page-properties)
         assets (:assets page-properties)
         page-properties (dissoc page-properties :assets)]
         page-properties (dissoc page-properties :assets)]

+ 1 - 0
tldraw/apps/tldraw-logseq/src/app.tsx

@@ -18,6 +18,7 @@ import { LogseqContext, LogseqContextValue } from '~lib/logseq-context'
 import { Shape, shapes } from '~lib/shapes'
 import { Shape, shapes } from '~lib/shapes'
 import {
 import {
   BoxTool,
   BoxTool,
+  // DotTool,
   EllipseTool,
   EllipseTool,
   HighlighterTool,
   HighlighterTool,
   HTMLTool,
   HTMLTool,

+ 1 - 1
tldraw/apps/tldraw-logseq/src/components/PrimaryTools/PrimaryTools.tsx

@@ -44,7 +44,7 @@ const GeometryToolButtons = observer(() => {
   const geometries = [
   const geometries = [
     {
     {
       id: 'box',
       id: 'box',
-      icon: 'rectangle',
+      icon: 'square',
       title: 'Rectangle',
       title: 'Rectangle',
     },
     },
     {
     {

+ 1 - 0
tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx

@@ -728,6 +728,7 @@ export class LogseqPortalShape extends TLBoxShape<LogseqPortalShapeProps> {
           ) : (
           ) : (
             <div
             <div
               className="tl-logseq-portal-container"
               className="tl-logseq-portal-container"
+              data-collapsed={this.props.collapsed}
               style={{
               style={{
                 background: this.props.compact ? 'transparent' : fill,
                 background: this.props.compact ? 'transparent' : fill,
                 boxShadow: isBinding
                 boxShadow: isBinding

+ 4 - 0
tldraw/apps/tldraw-logseq/src/styles.css

@@ -544,6 +544,10 @@
   transform: translate(1px, 1px);
   transform: translate(1px, 1px);
   overscroll-behavior: none;
   overscroll-behavior: none;
   opacity: 1;
   opacity: 1;
+
+  &[data-collapsed='true'] {
+    @apply overflow-hidden;
+  }
 }
 }
 
 
 .tl-logseq-portal-header {
 .tl-logseq-portal-header {

+ 5 - 0
tldraw/packages/core/src/lib/TLPage/TLPage.ts

@@ -130,6 +130,7 @@ export class TLPage<S extends TLShape = TLShape, E extends TLEventMap = TLEventM
         this.shapes[index] = this.shapes[index + 1]
         this.shapes[index] = this.shapes[index + 1]
         this.shapes[index + 1] = t
         this.shapes[index + 1] = t
       })
       })
+    this.app.persist()
     return this
     return this
   }
   }
 
 
@@ -146,18 +147,21 @@ export class TLPage<S extends TLShape = TLShape, E extends TLEventMap = TLEventM
         this.shapes[index] = this.shapes[index - 1]
         this.shapes[index] = this.shapes[index - 1]
         this.shapes[index - 1] = t
         this.shapes[index - 1] = t
       })
       })
+    this.app.persist()
     return this
     return this
   }
   }
 
 
   @action bringToFront = (shapes: S[] | string[]): this => {
   @action bringToFront = (shapes: S[] | string[]): this => {
     const shapesToMove = this.parseShapesArg(shapes)
     const shapesToMove = this.parseShapesArg(shapes)
     this.shapes = this.shapes.filter(shape => !shapesToMove.includes(shape)).concat(shapesToMove)
     this.shapes = this.shapes.filter(shape => !shapesToMove.includes(shape)).concat(shapesToMove)
+    this.app.persist()
     return this
     return this
   }
   }
 
 
   @action sendToBack = (shapes: S[] | string[]): this => {
   @action sendToBack = (shapes: S[] | string[]): this => {
     const shapesToMove = this.parseShapesArg(shapes)
     const shapesToMove = this.parseShapesArg(shapes)
     this.shapes = shapesToMove.concat(this.shapes.filter(shape => !shapesToMove.includes(shape)))
     this.shapes = shapesToMove.concat(this.shapes.filter(shape => !shapesToMove.includes(shape)))
+    this.app.persist()
     return this
     return this
   }
   }
 
 
@@ -189,6 +193,7 @@ export class TLPage<S extends TLShape = TLShape, E extends TLEventMap = TLEventM
         })
         })
       }
       }
     })
     })
+    this.app.persist()
     return this
     return this
   }
   }
 
 

+ 1 - 1
tldraw/packages/react/src/components/Canvas/Canvas.tsx

@@ -137,7 +137,7 @@ export const Canvas = observer(function Renderer<S extends TLReactShape>({
                 isSelected={selectedShapesSet.has(shape)}
                 isSelected={selectedShapesSet.has(shape)}
                 isErasing={erasingShapesSet.has(shape)}
                 isErasing={erasingShapesSet.has(shape)}
                 meta={meta}
                 meta={meta}
-                zIndex={(selectedShapesSet.has(shape) ? 2000 : 1000) + i}
+                zIndex={1000 + i}
                 onEditingEnd={onEditingEnd}
                 onEditingEnd={onEditingEnd}
               />
               />
             ))}
             ))}