# Class LocalStorageCommandHandler

GoJS® Diagramming Components
version 3.0.14
by Northwoods Software®

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. 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 go.Diagram.model be serializable and deserializable using go.Model.toJson and go.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:

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

or:

      myDiagram.commandHandler = new LocalStorageCommandHandler();

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

#####
Index

### Constructors

constructor

### Methods

canPasteSelection
copyToClipboard
pasteFromClipboard

#####
Inherited Index

### Accessors

CommandHandler.archetypeGroupData
CommandHandler.copiesConnectedLinks
CommandHandler.copiesGroupKey
CommandHandler.copiesParentKey
CommandHandler.copiesTree
CommandHandler.deletesConnectedLinks
CommandHandler.deletesTree
CommandHandler.diagram
CommandHandler.isZoomToFitRestoreEnabled
CommandHandler.memberValidation
CommandHandler.zoomFactor

### Methods

CommandHandler.addTopLevelParts
CommandHandler.canCollapseSubGraph
CommandHandler.canCollapseTree
CommandHandler.canCopySelection
CommandHandler.canCutSelection
CommandHandler.canDecreaseZoom
CommandHandler.canDeleteSelection
CommandHandler.canEditTextBlock
CommandHandler.canExpandSubGraph
CommandHandler.canExpandTree
CommandHandler.canGroupSelection
CommandHandler.canIncreaseZoom
CommandHandler.canRedo
CommandHandler.canResetZoom
CommandHandler.canScrollToPart
CommandHandler.canSelectAll
CommandHandler.canShowContextMenu
CommandHandler.canStopCommand
CommandHandler.canUndo
CommandHandler.canUngroupSelection
CommandHandler.canZoomToFit
CommandHandler.collapseSubGraph
CommandHandler.collapseTree
CommandHandler.computeEffectiveCollection
CommandHandler.copySelection
CommandHandler.cutSelection
CommandHandler.decreaseZoom
CommandHandler.deleteSelection
CommandHandler.doKeyDown
CommandHandler.doKeyUp
CommandHandler.editTextBlock
CommandHandler.expandSubGraph
CommandHandler.expandTree
CommandHandler.groupSelection
CommandHandler.increaseZoom
CommandHandler.isValidMember
CommandHandler.pasteSelection
CommandHandler.redo
CommandHandler.resetZoom
CommandHandler.scrollToPart
CommandHandler.selectAll
CommandHandler.showContextMenu
CommandHandler.stopCommand
CommandHandler.undo
CommandHandler.ungroupSelection
CommandHandler.zoomToFit

## Constructors

### constructor

- new LocalStorageCommandHandler(init?: Partial<LocalStorageCommandHandler>): LocalStorageCommandHandler

- #### Parameters

  - ##### `Optional` init: Partial<LocalStorageCommandHandler>

  #### Returns LocalStorageCommandHandler

## Methods

### `Override` canPasteSelection

- canPasteSelection(pos?: Point): boolean

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

  This works just like go.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 go.Parts and stores it as JSON in LocalStorage.

  #### Parameters

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

    a collection of go.Parts.

  #### Returns void

### `Override` pasteFromClipboard

- pasteFromClipboard(): Set<Part>

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

  #### Returns Set<Part>

  a collection of newly pasted go.Parts

Copyright © 1998-2024 by Northwoods Software Corporation.