This is an extension and not part of the main GoJS library. Note that the API for this class may change at any time. If you intend to use an extension in production, you should copy the code to your own source directory. Extensions can be found in the GoJS kit under the `extensions` or `extensionsTS` folders. See the Extensions intro page for more information.

### Hierarchy

- CommandHandler
  - LocalStorageCommandHandler

This CommandHandler class uses localStorage as the repository for the clipboard, rather than an in-memory global variable. It requires that the Diagram.model be serializable and deserializable using Model.toJson and Model.fromJson.

The copyToClipboard and pasteFromClipboard functions fall back to using the standard definitions if there are any errors calling `Storage.getItem` or `Storage.setItem`.

Typical usage:

      $(go.Diagram, "myDiagramDiv",
        {
          commandHandler: $(LocalStorageCommandHandler),
          ...
        }
      )

or:

      myDiagram.commandHandler = new LocalStorageCommandHandler();

If you want to experiment with this extension, try the Local Storage Commands sample.

## Index

### Methods

- canPasteSelection
- copyToClipboard
- pasteFromClipboard

## Methods

### Override canPasteSelection

- canPasteSelection(pos?: Point): boolean

- This predicate controls whether or not the user can invoke the pasteSelection command.

  This works just like CommandHandler.canPasteSelection, but looks at LocalStorage instead of a static variable.

  #### Parameters

  - ##### Optional pos: Point

  #### Returns boolean

### Override copyToClipboard

- copyToClipboard(coll: Iterable<Part>): void

- Makes a copy of the given collection of Parts and stores it as JSON in LocalStorage.

  #### Parameters

  - ##### coll: Iterable<Part>

    a collection of Parts.

  #### Returns void

### Override pasteFromClipboard

- pasteFromClipboard(): Set<Part>

- If LocalStorage holds JSON for a collection of Parts, and if the Model.dataFormat matches that stored in the clipboard, this makes a copy of the clipboard's parts and adds the copies to this Diagram.

  #### Returns Set<Part>

  a collection of newly pasted Parts

Copyright © 1998-2019 by Northwoods Software Corporation.