Skip to content

@fabwcie/free-drawing / components/ContextMenu

components/ContextMenu ​

Classes ​

ContextMenu ​

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:23

Menu of right click (or context menu key, Shift + F10): actions on selection when a shape is under pointer or selected (order, rotate, flip, fit width of texts, duplicate, link, lock, delete, copy as image; unlock for locked shapes), else actions on drawing (paste, select all, copy as image, snapping, grid), with their shortcuts

Constructors ​

Constructor ​

new ContextMenu(drawer): ContextMenu

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:47

Create the menu (hidden) in the floating region and listen to right clicks and the context menu key

Parameters
drawer ​

Drawer

Drawer the menu acts on

Returns

ContextMenu

Properties ​

$gridBtn ​

$gridBtn: HTMLButtonElement

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:35

Checkbox item of the grid (Alt+G), checked by the drawer when the grid is shown or hidden

$list ​

$list: HTMLDivElement

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:29

Sections of items of the menu

$menu: HTMLDivElement

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:27

Menu element (role="menu"), placed at the pointer or in the drawer center

$pasteBtn ​

$pasteBtn: HTMLButtonElement

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:31

Item pasting text of the clipboard at the place of the right click (needs clipboard permission)

$snappingBtn ​

$snappingBtn: HTMLButtonElement

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:33

Checkbox item of snapping (Alt+S), checked by the selection widget when snapping changes

drawer ​

drawer: Drawer

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:25

Drawer the menu acts on

Accessors ​

selectWidget ​
Get Signature

get private selectWidget(): SelectWidget | undefined

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:56

Selection widget, undefined when it is not in the toolbar

Returns

SelectWidget | undefined

Methods ​

_addSection() ​

private _addSection(items): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:270

Section of items at the end of the menu, each item hides the menu then runs its action

Parameters
items ​

ContextMenuItem[]

Items of the section

Returns

void

_createItem() ​

private _createItem(label, shortcut, role?): HTMLButtonElement

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:308

Menu item, focused with arrow keys, shortcut shown at its end

Parameters
label ​

"drawer.label" | "language.auto" | "toast.collaborationUnavailable" | "toast.collaborationFull" | "toast.collaborationTooBig" | "toast.canDraw" | "toast.viewOnly" | "toast.joinedViewOnly" | "toast.presentationStarted" | "toast.presentationEnded" | "toast.requestSent" | "toast.requestReceived" | "toast.requestRefused" | "toast.saveFailed" | "toast.saved" | "toast.styleCopied" | "toast.libraryImported" | "toast.libraryNotSaved" | "toast.loadFailed" | "toast.invalidFile" | "toast.linkCopied" | "toast.linkNotCopied" | "toast.invalidLink" | "toast.invalidShapeLink" | "toast.clipboardUnavailable" | "toast.exportFailed" | "toast.imageCopied" | "toast.storageCleared" | "toast.imageNotCopied" | "error.clipboardUnavailable" | "error.nothingToExport" | "error.notDrawingFile" | "error.notImage" | "error.damagedLink" | "error.drawingTooBig" | "error.imageNotCreated" | "error.serverUnreachable" | "error.notAllowed" | "error.storageFull" | "error.notLibraryFile" | "error.noDrawingInImage" | "error.insecurePage" | "error.roomKey" | "error.encryptionUnsupported" | "toast.selectionTool" | "modal.close" | "confirm.message" | "confirm.clearCanvas" | "confirm.clearStorage" | "confirm.stopCollaboration" | "confirm.leaveCollaboration" | "confirm.cancel" | "confirm.confirm" | "menu.label" | "menu.open" | "menu.saveAs" | "menu.save" | "menu.unsaved" | "menu.copyLink" | "menu.collaboration" | "menu.collaborationOn" | "menu.collaborationUsers" | "menu.export" | "menu.clearCanvas" | "menu.showGrid" | "menu.zenMode" | "menu.darkMode" | "menu.github" | "menu.githubLabel" | "menu.clearStorage" | "menu.background" | "menu.language" | "menu.commands" | "menu.preferences" | "preferences.title" | "preferences.autoSave" | "preferences.shapeRecognition" | "grid.style" | "grid.squares" | "grid.dots" | "grid.lines" | "grid.isometric" | "grid.styleCommand" | "preferences.wheel" | "wheel.zoom" | "wheel.pan" | "wheel.command" | "help.spaceDrag" | "help.wheelDrag" | "preferences.save" | "preferences.appearance" | "preferences.theme" | "preferences.light" | "preferences.dark" | "preferences.system" | "preferences.drawing" | "commands.search" | "commands.empty" | "commands.file" | "commands.language" | "color.white" | "color.lightGray" | "color.lightBlue" | "color.lightYellow" | "color.lightBeige" | "color.lightRed" | "color.lightGreen" | "color.black" | "color.red" | "color.green" | "color.blue" | "color.orange" | "color.yellow" | "color.pink" | "color.transparent" | "color.custom" | "color.pick" | "help.title" | "help.documentation" | "help.issue" | "help.shortcuts" | "help.tools" | "help.editor" | "help.view" | "help.or" | "help.selectAll" | "help.deleteSelection" | "help.duplicate" | "help.group" | "help.selectInGroup" | "help.constrainDrawing" | "help.whileDrawing" | "help.cancelDrawing" | "help.arrowUnlinked" | "help.constrainSelection" | "help.whileTransforming" | "help.move" | "help.forwardBackward" | "help.frontBack" | "help.lock" | "help.paste" | "help.open" | "help.save" | "help.export" | "help.grid" | "help.layers" | "help.layersSelect" | "help.snap" | "help.zoom" | "help.toolsConstrain" | "key.delete" | "key.arrows" | "key.click" | "key.space" | "key.wheel" | "key.ctrl" | "key.shift" | "key.alt" | "key.escape" | "key.enter" | "key.tab" | "key.home" | "key.end" | "key.backspace" | "toolbar.label" | "toolbar.moreTools" | "toolbar.keepTool" | "tools.pan" | "tools.selection" | "tools.brush" | "tools.eraser" | "tools.text" | "tools.note" | "tools.line" | "tools.square" | "tools.circle" | "tools.arrow" | "tools.image" | "tools.triangle" | "tools.diamond" | "tools.laser" | "tools.frame" | "zoom.label" | "zoom.out" | "zoom.in" | "zoom.reset" | "zoom.fit" | "zoom.selection" | "zoom.to100" | "history.label" | "history.undo" | "history.redo" | "position.label" | "position.recenter" | "context.paste" | "context.snap" | "context.lock" | "context.unlock" | "selectionMenu.label" | "action.duplicate" | "action.copyStyle" | "action.pasteStyle" | "library.title" | "library.add" | "library.empty" | "library.hint" | "library.insert" | "library.remove" | "library.import" | "library.export" | "library.close" | "library.shapes" | "search.label" | "search.count" | "search.none" | "slideshow.start" | "slideshow.presentFrom" | "slideshow.label" | "slideshow.previous" | "slideshow.next" | "slideshow.stop" | "slideshow.count" | "slideshow.slide" | "slideshow.slideTitled" | "slideshow.noFrames" | "slideshow.nextPrevious" | "slideshow.firstLast" | "slideshow.whilePresenting" | "replay.start" | "replay.label" | "replay.play" | "replay.pause" | "replay.restart" | "replay.speed" | "replay.stop" | "replay.count" | "replay.empty" | "replay.finished" | "replay.playPause" | "replay.step" | "replay.firstLast" | "replay.whileReplaying" | "navigation.description" | "navigation.text" | "navigation.shapes" | "navigation.from" | "navigation.to" | "navigation.link" | "navigation.locked" | "navigation.in" | "navigation.index" | "navigation.left" | "navigation.nextPrevious" | "navigation.enter" | "navigation.parent" | "navigation.leave" | "navigation.onDrawing" | "search.previous" | "search.next" | "search.close" | "action.group" | "action.ungroup" | "action.sendToBack" | "action.sendBackward" | "action.bringForward" | "action.bringToFront" | "action.delete" | "action.rotateRight" | "action.rotateLeft" | "action.flipHorizontal" | "action.flipVertical" | "action.insertImage" | "toast.imageFailed" | "action.alignLeft" | "action.alignCenter" | "action.alignRight" | "action.alignTop" | "action.alignMiddle" | "action.alignBottom" | "action.distributeHorizontal" | "action.distributeVertical" | "action.stackHorizontal" | "action.stackVertical" | "action.fitTextWidth" | "action.copyPng" | "action.copySvg" | "action.link" | "overlay.tool" | "overlay.selection" | "overlay.shape" | "overlay.brush" | "overlay.recognizeShapes" | "overlay.recognizeShapesHint" | "overlay.note" | "overlay.text" | "overlay.stroke" | "overlay.color" | "overlay.background" | "overlay.strokeWidth" | "overlay.strokeStyle" | "overlay.edges" | "overlay.arrowType" | "overlay.startHead" | "overlay.endHead" | "overlay.opacity" | "overlay.layers" | "overlay.align" | "overlay.distribute" | "overlay.actions" | "link.address" | "link.placeholder" | "link.open" | "link.remove" | "width.thin" | "width.medium" | "width.thick" | "width.extraThick" | "style.solid" | "style.dashed" | "style.dotted" | "edges.sharp" | "edges.round" | "edges.radius" | "edges.auto" | "arrow.straight" | "arrow.curved" | "arrow.elbow" | "arrowhead.none" | "arrowhead.arrow" | "arrowhead.triangle" | "arrowhead.dot" | "arrowhead.bar" | "text.fontFamily" | "text.fontSize" | "text.small" | "text.medium" | "text.large" | "text.extraLarge" | "text.style" | "text.bold" | "text.italic" | "text.underline" | "text.strikethrough" | "text.align" | "text.alignLeft" | "text.alignCenter" | "text.alignRight" | "layers.title" | "layers.group" | "layers.close" | "layers.empty" | "layers.drag" | "layers.shapesOf" | "layers.hide" | "layers.lock" | "layers.delete" | "layers.name" | "layers.toggle" | "layers.range" | "shapes.freehand" | "shapes.line" | "shapes.rect" | "shapes.ellipse" | "shapes.arrow" | "shapes.triangle" | "shapes.diamond" | "shapes.heart" | "shapes.cloud" | "shapes.star" | "shapes.hexagon" | "shapes.blockArrow" | "shapes.bubble" | "shapes.checkbox" | "shapes.shape" | "shapes.highlighter" | "shapes.frame" | "shapes.frameName" | "shapes.text" | "shapes.note" | "shapes.group" | "shapes.image" | "export.title" | "export.empty" | "export.options" | "export.selected" | "export.background" | "export.dark" | "export.withDrawing" | "export.scale" | "export.saveAs" | "export.saveFile" | "export.copy" | "export.preview" | "collab.title" | "collab.intro" | "collab.introInvited" | "collab.introJoined" | "collab.introJoinedOf" | "collab.name" | "collab.anonymous" | "collab.link" | "collab.copy" | "collab.qrCode" | "collab.start" | "collab.join" | "collab.stop" | "collab.leave" | "collab.live" | "collab.liveState" | "collab.connected" | "collab.connecting" | "collab.you" | "collab.invitedBy" | "collab.canDrawLabel" | "collab.canDraw" | "collab.newUsersCanDraw" | "collab.encrypted" | "collab.notEncrypted" | "collab.owner" | "collab.viewOnly" | "collab.present" | "collab.presenting" | "collab.follow" | "collab.followPresentation" | "collab.following" | "collab.youCanDraw" | "collab.youViewOnly" | "collab.requestEdit" | "collab.requestSent" | "collab.requests" | "collab.requestsCount" | "collab.accept" | "collab.refuse" | "collab.acceptLabel" | "collab.refuseLabel" | "collab.users" | "collab.settings"

Key of the item text (translated again when language changes)

shortcut ​

string

Keys of the item (Ctrl+Shift+Up, Delete), shown at its end (formatShortcut, hidden to assistive technologies) and set as aria-keyshortcuts, empty without one

role? ​

"menuitemcheckbox" | "menuitem" = 'menuitem'

menuitemcheckbox for a toggle (snapping, grid), else menuitem

Returns

HTMLButtonElement

Item button (not in tab order), its click listener is added by _init

_getDrawingShape() ​

private _getDrawingShape(node): DrawingShape

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:430

Drawing shape of a node of draw layer: the node itself or its top group, in drawing or in a frame

Parameters
node ​

Node

Node hit by the right click

Returns

DrawingShape

Drawing shape holding the node

_getItems() ​

private _getItems(): HTMLElement[]

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:332

Shown items, in menu order

Returns

HTMLElement[]

Items not hidden, navigated with arrow keys

_init() ​

private _init(): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:63

Creates the menu and its sections of items (action, condition to be shown), each item hides the menu then runs

Returns

void

_initEvents() ​

private _initEvents(): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:339

Right click on stage or context menu key on drawer shows the menu, a click anywhere, Escape or Tab hide it

Returns

void

_linkedShape() ​

private _linkedShape(hit): DrawingShape | null

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:389

Shape whose link the menu opens: the shape under the pointer (its group or frame with a link too), else the shape reached with the keyboard or the first selected one with a link

Parameters
hit ​

Node<NodeConfig> | null

Node of the drawing under the right click, null for the keyboard

Returns

DrawingShape | null

Shape with a link, null without one

_moveTo() ​

private _moveTo(left, top): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:439

Menu at a position of drawer, kept in it (taller than the drawer: its height is limited, the rest scrolls)

Parameters
left ​

number

Wanted left of the menu from the drawer container left (px)

top ​

number

Wanted top of the menu from the drawer container top (px)

Returns

void

_paste() ​

private _paste(): Promise<void>

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:453

Adds text of the clipboard as a text node at the place of the right click (menu opened with keyboard: pointer position, center of view when out of canvas), warns when the clipboard cannot be read

Returns

Promise<void>

_selectAll() ​

private _selectAll(): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:473

Selects all shapes with the selection tool (activated if needed)

Returns

void

_selectAt() ​

private _selectAt(e): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:404

Shape under pointer selected (its group, with selection tool) unless it is selected, selection kept in its box, removed elsewhere

Parameters
e ​

KonvaEventObject<PointerEvent>

Konva contextmenu event of the stage, its target is the hit node

Returns

void

addSection() ​

addSection(items): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:290

Section of items added at the end of the menu (commands of plugins)

Parameters
items ​

ContextMenuItemOptions[]

Text (key or text), shortcut, condition to be shown and action of each item

Returns

void

hide() ​

hide(): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:504

Hide the context menu, focus back on drawer if it was in menu

Returns

void

isVisible() ​

isVisible(): boolean

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:515

Whether the menu is shown

Returns

boolean

True while the menu is shown

show() ​

show(): void

Defined in: packages/free-drawing/src/components/ContextMenu/ContextMenu.ts:484

Show items of selection or drawing, first one focused (keyboard navigation)

Returns

void