Class: Clipboard

PD. Clipboard


new Clipboard()

A static controller class for managing the system clipboard.

This class uses the Clipboard API via navigator.clipboard to set/set JSON text on the OS clipboard.

Author:
  • drajmarsh

Members


:boolean

isCopying <static>

Active only when model data is being copied to the clipboard.

This is typically used in toJSON() methods as a flag to not copy UUID and other instance-defining data.

Type
  • boolean

:string

lastCopiedType <static>

This is provided to support a generic paste action in some host applications that pastes just the last copied data.

Type
  • string

:BIM.Level

level <static>

Stores the level of the last copy element.

This is used check if the element is being pasted onto the same level, so that it can be displaced.

Type

Methods


convertAndStoreJSON(type, object) <static>

Calls the toJSON() method on the given object and stores the stringified text on clipboard as the given type.

Parameters:
Name Type Description
type string

The type of textual data to store.

object object

An object suitable for conversion to JSON.

Returns:

Returns true if data was set.

Type
boolean

getJSON() <static>

Retrieves a JSON object from text currently on the operating system clipboard.

NOTE: This must be an asynchronous method as some browsers will display a system prompt requiring the user to approve access to the system clipboard. Thus, it could take any amount of time for the user to notice the prompt and respond.

Returns:

Returns a JSON POJO retrieved from the clipboard, of null if not JSON.

Type
object | null

getLastError() <static>

Retrieves the last error message when accessing the system clipboard.

Returns:

Returns a message describing the error, or an empty string if no error was encountered.

Type
string

getLastText() <static>

Retrieves the last text value retrieved from the system clipboard.

Returns:

Returns any text previously received.

Type
string

getLocalType(type) <static>

Retrieves the clipboard has data for the given type.

Parameters:
Name Type Description
type string

The type of textual data to retrieve.

Returns:

Returns the textual data stored for the type, or an empty string.

Type
string

getText() <static>

Retrieves any text currently on the operating system clipboard.

NOTE: This must be an asynchronous method as most browsers will display a system prompt requiring the user to approve access to the system clipboard. Thus, it could take any amount of time for the user to notice the prompt and respond.

Returns:

Returns the text retrieved from the clipboard.

Type
string

hasLocalType(type) <static>

Retrieves whether or not the clipboard has textual data for the given type.

Parameters:
Name Type Description
type string

The type of data to check for.

Returns:

Returns true if data is available.

Type
boolean

setLocalType(type, text) <static>

Stores the given textual data on clipboard as the given type.

Parameters:
Name Type Description
type string

The type of textual data to retrieve.

text string

The textual data to store.


setText(text) <static>

Copies the given text to the operating system clipboard.

NOTE: This is an asynchronous method as it must await the navigator.clipboard.writeText() method.

Parameters:
Name Type Description
text string

The text to put on the clipboard.

Returns:

Returns true if the text was copied.

Type
boolean