Accessing clipboard in Perspective

Exactly.

Here's a simple example, reading the clipboard as text.

# Get Clipboard Button
def runAction(self, event):
	
	def withClipboard(clipboard):
		self.view.custom.clipboard = clipboard
		
	
	system.perspective.runJavaScriptAsync('''async () => {
		return await navigator.clipboard.readText()
	}''', {}, withClipboard)

View JSON
{
  "custom": {
    "clipboard": ""
  },
  "params": {},
  "propConfig": {
    "custom.clipboard": {
      "persistent": true
    }
  },
  "props": {},
  "root": {
    "children": [
      {
        "events": {
          "dom": {
            "onClick": {
              "config": {
                "script": "\t\n\tdef withClipboard(clipboard):\n\t\tself.view.custom.clipboard \u003d clipboard\n\t\t\n\t\n\tsystem.perspective.runJavaScriptAsync(\u0027\u0027\u0027async () \u003d\u003e {\n\t\treturn await navigator.clipboard.readText()\n\t}\u0027\u0027\u0027, {}, withClipboard)"
              },
              "scope": "G",
              "type": "script"
            }
          }
        },
        "meta": {
          "name": "Button"
        },
        "position": {
          "height": 34,
          "width": 193,
          "x": 499,
          "y": 167
        },
        "props": {
          "text": "Get Clipboard"
        },
        "type": "ia.input.button"
      },
      {
        "children": [
          {
            "meta": {
              "name": "Label"
            },
            "props": {
              "text": "Clipboard Contents"
            },
            "type": "ia.display.label"
          },
          {
            "meta": {
              "name": "Markdown"
            },
            "position": {
              "grow": 1
            },
            "propConfig": {
              "props.source": {
                "binding": {
                  "config": {
                    "path": "view.custom.clipboard"
                  },
                  "type": "property"
                }
              }
            },
            "type": "ia.display.markdown"
          }
        ],
        "meta": {
          "name": "FlexContainer"
        },
        "position": {
          "height": 200,
          "width": 200,
          "x": 499,
          "y": 211
        },
        "props": {
          "direction": "column"
        },
        "type": "ia.container.flex"
      },
      {
        "children": [
          {
            "meta": {
              "name": "Label"
            },
            "props": {
              "text": "This"
            },
            "type": "ia.display.label"
          },
          {
            "meta": {
              "name": "Label_0"
            },
            "props": {
              "text": "That"
            },
            "type": "ia.display.label"
          },
          {
            "meta": {
              "name": "Label_1"
            },
            "props": {
              "text": "Those"
            },
            "type": "ia.display.label"
          },
          {
            "meta": {
              "name": "Label_2"
            },
            "props": {
              "text": "Other"
            },
            "type": "ia.display.label"
          }
        ],
        "meta": {
          "name": "FlexContainer_0"
        },
        "position": {
          "height": 200,
          "width": 200,
          "x": 200,
          "y": 211
        },
        "props": {
          "direction": "column",
          "style": {
            "gap": "1rem"
          }
        },
        "type": "ia.container.flex"
      }
    ],
    "meta": {
      "name": "root"
    },
    "type": "ia.container.coord"
  }
}
5 Likes