Преглед изворни кода

fix(whiteboard): pasting HTML shape issues

Peng Xiao пре 3 година
родитељ
комит
63b83a03d3

+ 1 - 1
src/main/frontend/handler/paste.cljs

@@ -67,7 +67,7 @@
 (defn- get-whiteboard-tldr-from-text
   [text]
   (when-let [matched-text (util/safe-re-find #"<whiteboard-tldr>(.*)</whiteboard-tldr>" text)]
-    (try-parse-as-json (second matched-text))))
+    (try-parse-as-json (js/decodeURIComponent (second matched-text)))))
 
 (defn- get-whiteboard-shape-refs-text
   [text]

+ 2 - 2
tldraw/apps/tldraw-logseq/src/hooks/usePaste.ts

@@ -44,7 +44,7 @@ const safeParseJson = (json: string) => {
 const getWhiteboardsTldrFromText = (text: string) => {
   const innerText = text.match(/<whiteboard-tldr>(.*)<\/whiteboard-tldr>/)?.[1]
   if (innerText) {
-    return safeParseJson(innerText)
+    return safeParseJson(decodeURIComponent(innerText))
   }
 }
 
@@ -450,7 +450,7 @@ export function usePaste() {
           app.createShapes(allShapesToAdd)
         }
 
-        if (app.selectedShapesArray.length === 1 && allShapesToAdd.length === 1) {
+        if (app.selectedShapesArray.length === 1 && allShapesToAdd.length === 1 && !fromDrop) {
           const source = app.selectedShapesArray[0]
           const target = app.getShapeById(allShapesToAdd[0].id!)!
           app.createNewLineBinding(source, target)

+ 1 - 1
tldraw/packages/core/src/lib/TLApp/TLApp.ts

@@ -483,7 +483,7 @@ export class TLApp<
         // convey the bindings to maintain the new links after pasting
         bindings: toJS(this.currentPage.bindings),
       })
-      const tldrawString = `<whiteboard-tldr>${jsonString}</whiteboard-tldr>`
+      const tldrawString = `<whiteboard-tldr>${encodeURIComponent(jsonString)}</whiteboard-tldr>`
       // FIXME: use `writeClipboard` in frontend.utils
       navigator.clipboard.write([
         new ClipboardItem({