@fabwcie/free-drawing / components/toolbar/widgets/Select
components/toolbar/widgets/Select
Classes
SelectWidget
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:52
Selection tool: selects shapes (click, Shift toggles, Alt selects the one behind, rectangle selects shapes entirely in it), moves and transforms them with its Konva Transformer (also used by other components), shows the overlay of selected shapes and applies its options to them. Optional snapping of moves and resizes to other shapes.
Extends
Constructors
Constructor
new SelectWidget(
drawer):SelectWidget
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:134
Create the selection tool, shortcut S: transformer events (frames resized, texts rewrapped, change fired on transform or drag end), Shift moves along an axis, resize anchors snapped
Parameters
drawer
Drawer of this widget
Returns
Overrides
Properties
$button
$button:
HTMLButtonElement
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:29
Button activating the widget, pressed while it is active, named by the title of the tool
Inherited from
$container
protectedreadonly$container:HTMLElement
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:21
Container of the button in toolbar (or menu of its group), with a class from widget id
Inherited from
actionOnly
readonlyactionOnly:boolean=false
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:27
Button runs an action (setActive(true)), the widget never becomes the active tool (e.g. image tool)
Inherited from
color
color:
ColorLike='rgba(152, 158, 255, 1)'
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:69
Color of transformer box and anchors, and of snapping guides
cursor
protectedcursor:string='default'
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:49
Stage cursor while widget is active
Inherited from
defaultAnchors
defaultAnchors:
string[]
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:58
Resize anchors of the transformer: corners and middles of sides (texts: no top / bottom middle)
drawer
protecteddrawer:Drawer
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:61
Drawer of this widget
Inherited from
gridAnchorBound
gridAnchorBound: ((
oldPos,newPos) =>Vector2d) |null=null
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:122
Snap of resize anchors to grid (set by drawer while grid is shown), applied when anchor is not snapped to objects
id
id:
AvailableTools
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:31
Id of the tool, key of the widget in toolbar (drawer.getWidget(id)) and namespace of its stage events
Inherited from
inAction
inAction:
boolean=false
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:39
Pointer action in progress (drawing, erasing, selecting...), see startAction / endAction
Inherited from
options
readonlyoptions:WidgetOptions
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:37
Widget options given with drawer widgets option
Inherited from
overlay
overlay:
SelectOverlay
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:125
Options of the tool (color, width...), shown while widget is active (see showOverlayOnActive)
Overrides
selectionRectangle
selectionRectangle:
Rect
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:71
Rectangle drawn by a drag from an empty place: selects shapes entirely in it (selection layer)
shortcut
shortcut:
string|undefined
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:33
Key activating the tool, lower case (shortcut widget option, else default of the widget), none if undefined
Inherited from
showOverlayOnActive
protectedshowOverlayOnActive:boolean=false
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:127
Show overlay while widget is active (false when overlay depends on something else, e.g. selection)
Overrides
BaseWidget.showOverlayOnActive
snapping
snapping:
boolean=false
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:124
Moves and resizes snap to edges and centers of other shapes, with guides (snapping preference)
transformer
transformer:
Transformer
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:76
Konva transformer of selected shapes (box, resize and rotation anchors), in selection layer. Its nodes are the selection. Created with the widget, so other components can use it whatever the active tool.
Accessors
isDisabled
Get Signature
get isDisabled():
boolean
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:138
Widget can not be activated (see setDisabled)
Returns
boolean
Inherited from
isSelecting
Get Signature
get isSelecting():
boolean
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:643
Selection rectangle being drawn (pointer action in progress)
Deprecated
use inAction
Returns
boolean
Methods
_boundAnchor()
private_boundAnchor(oldPos,newPos):Vector2d
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:780
Resize anchor position (absolute): side or corner aligned on edges and centers of other shapes (snapping), else on grid. Not when rotating, nor for a rotated selection
Parameters
oldPos
Vector2d
Anchor position before this move (absolute)
newPos
Vector2d
Anchor position given by the pointer (absolute)
Returns
Vector2d
Position of the anchor, snapped or unchanged
_clearGuides()
private_clearGuides():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:769
Remove snapping guides of selection layer
Returns
void
_drawGuides()
private_drawGuides(guides):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1010
Draw guides as dashed lines across the view whatever the zoom (width and dashes on screen), in selection layer
Parameters
guides
object[]
Guides of _getGuides
Returns
void
_getBox()
private_getBox(nodes):IRect
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:753
Box of nodes together (absolute)
Parameters
nodes
Node<NodeConfig>[]
Nodes moved together (selection), or the node dragged alone
Returns
IRect
Box around their boxes
_getDrawingShape()
private_getDrawingShape(node):DrawingShape
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:454
Drawing shape (or group) of a node of draw layer: the node itself or its top group, in drawing or in a frame
Parameters
node
Node
Node of draw layer (konva hit, part of a frame)
Returns
Node or group selected by a click on it
_getGuides()
private_getGuides(lineGuideStops,itemBounds):object[]
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:918
Guides a dragged node snaps to: on each axis, the stop nearest to one of its points, closer than 5 px
Parameters
lineGuideStops
Positions to snap to, see _getLineGuideStops
horizontal
number[]
vertical
number[]
itemBounds
Points of the node, see _getObjectSnappingEdges
horizontal
object[]
vertical
object[]
Returns
object[]
Vertical guide then horizontal one, if any
_getLineGuideStops()
private_getLineGuideStops(skipShapes):SnapStops
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:832
Positions a shape can snap to (absolute): edges and centers of visible drawing shapes, shapes of frames too, the frame of a moved shape, and the center of the view (not its edges: infinite drawing); not moved shapes, their shapes and their groups (moved with them)
Parameters
skipShapes
Node<NodeConfig>[]
Moved shapes, not guides themselves
Returns
Positions of vertical and horizontal guides
_getObjectSnappingEdges()
private_getObjectSnappingEdges(box,node):object
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:863
Points of dragged nodes which snap to guides: edges and center of their box on each axis (absolute)
Parameters
box
IRect
Box of the nodes moved together (selection), or of the node dragged alone (see _getBox)
node
Node
Node being dragged, whose position gives the offsets
Returns
Points of the box on each axis, with the offset to the position of the node
horizontal
horizontal:
object[]
Top, center and bottom of node box
vertical
vertical:
object[]
Left, center and right of node box
_getSelected()
private_getSelected(): (Group|Shape<ShapeConfig>)[]
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:483
Selected nodes (drawing shapes)
Returns
(Group | Shape<ShapeConfig>)[]
Nodes of the transformer
_initShiftEvents()
private_initShiftEvents():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:595
Shift while moving: horizontally or vertically (resize: see keepRatio, rotation by 15 degrees: konva transformer)
Returns
void
_initSnapEvents()
private_initSnapEvents():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:680
Turn snapping on: a dragged shape is moved to the nearest guide (edges and centers of other shapes, see _getLineGuideStops) closer than 5 px on each axis, guides shown until drag end
Returns
void
_inSelectionBox()
private_inSelectionBox(pos):boolean
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:473
Point (absolute position) in box of selection, rotated with it (dragged from it), not for locked shapes
Parameters
pos
Vector2d
Point in view (pointer)
Returns
boolean
True when the point is in the transformer box of an unlocked selection
_removeSnapEvents()
private_removeSnapEvents():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:816
Turn snapping off: drag listeners of snapping (.snap) removed; during a drag, its guides removed and its stops forgotten (the next drag finds its own)
Returns
void
_selectAt()
private_selectAt(pos,hit,__namedParameters?,keep?):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:493
Click selection: shape under pointer, Shift adds or removes it, Alt selects the one behind selected shape
Parameters
pos
Vector2d
Point clicked in view (pointer)
hit
DrawingShape | null
Shape pressed (konva hit, or its group), null on empty place
__namedParameters?
altKey?
boolean = false
deep?
boolean = false
shiftKey?
boolean = false
keep?
boolean = false
Selection kept without shape under pointer (click in selection box)
Returns
void
_setNested()
private_setNested(shapes):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:462
Selected shapes of groups are dragged alone (shapes of groups are moved with their group)
Parameters
shapes
Selected shapes of groups, draggable while the selection tool is active (previous ones no longer)
Returns
void
_setupAnchors()
private_setupAnchors(shapes,locked):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:619
Anchors of selected shapes: text has no top / bottom anchors (it would be stretched), its side anchors resize text box and its corners scale it; locked shapes have none (dashed box around their outline)
Parameters
shapes
(Group | Shape<ShapeConfig>)[]
Shapes being selected
locked
boolean
Shapes are locked: no anchors nor rotation, dashed box
Returns
void
_updateSelected()
private_updateSelected(update,updateFrame?):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1044
Apply update on each selected shape, then fire change once
Parameters
update
(shape) => void
Change of one shape, called for each selected shape (shapes of groups, not locked shapes nor frames)
updateFrame?
(frame) => void
Change of a selected frame (as a whole), frames are not modified without it
Returns
void
addTo()
addTo(
parent):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:96
Internal
Adds the button of this widget (icon, shortcut letter) in its container, at the end of parent
Parameters
parent
HTMLElement
Element receiving the button container: toolbar root or menu of a group
Returns
void
Inherited from
afterDraw()
protectedafterDraw():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:320
Shape drawn with this tool: selection tool activated, nothing selected, unless tool is kept (keepTool preference)
Returns
void
Inherited from
batchUpdates()
batchUpdates(
updates):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1063
Updates of the selection grouped in one change (one entry of history, one message of collaboration): style pasted
Parameters
updates
() => void
Calls of setters of the selection (setColor, setFillColor...)
Returns
void
cancelAction()
cancelAction():
void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:241
Pointer action cancelled (two finger gesture of the drawer: zoom and move of the view): its result is discarded (onCancel: shape being drawn removed...), then it ends without change
Returns
void
Inherited from
clearSelection()
clearSelection():
void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:583
Unselect shapes and hide selection overlays, overlay of active tool (brush, text...) is shown again
Returns
void
Overrides
endAction()
protectedendAction():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:254
Pointer action ends (pointer up)
Returns
void
Inherited from
getShapesAt()
getShapesAt(
pos,hit?,deep?):DrawingShape[]
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:422
Shapes (or groups) under a point (absolute position), from top to bottom: drawn there (fill, stroke, text box), then rectangles and ellipses without background around it, smallest first, then locked shapes (or their locked groups) in the same order
Parameters
pos
Vector2d
Point in view (pointer), absolute position
hit?
DrawingShape | null = null
Shape drawn on top (konva hit of pointer event, or its group), none by default
deep?
boolean = false
Shapes of groups instead of groups
Returns
Visible shapes at the point, the first one is selected by a click
hideOverlay()
hideOverlay():
void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:575
Hide overlays of selection (selection overlay and text overlay), selection is kept
Returns
void
initEvents()
protectedinitEvents():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:226
Press selects the shape under pointer (dragged at once) or drags the selection from its box, else starts a selection rectangle; release selects shapes touched by the rectangle, or the shape clicked (_selectAt)
Returns
void
Overrides
isLocked()
isLocked():
boolean
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:407
Selected shapes are locked: selected to be unlocked, not modified
Returns
boolean
True when shapes are selected and none of them listens (locked)
onActive()
protectedonActive():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:517
New selection rectangle in selection layer, drawing shapes (also of frames) draggable
Returns
void
Overrides
onCancel()
protectedonCancel():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:650
Press cancelled (two finger gesture): no selection rectangle, nothing selected by its release
Returns
void
Overrides
onConstrainChange()?
protectedoptionalonConstrainChange(constrain):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:218
Shift pressed or released during a pointer action (square, circle, straight line...), without pointer move
Parameters
constrain
boolean
Shift pressed
Returns
void
Inherited from
onDesactive()
protectedonDesactive():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:670
Selection rectangle removed, selection cleared, drawing shapes no longer draggable
Returns
void
Overrides
onStage()
protectedonStage(events,handler):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:150
Listen stage events while widget is active. Events are namespaced with widget id, so they are removed on deactivation without removing other listeners. One pointer at a time: during a pointer action, another press (second finger, other button) is ignored, and a touch action ends when its finger is lifted, where it is lifted. Touches of a two finger gesture are ignored.
Parameters
events
string
Space separated event names
handler
KonvaEventListener<Stage, any>
Konva listener called with the stage event
Returns
void
Inherited from
removeEvents()
protectedremoveEvents():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:192
Remove widget events, called on deactivation
Returns
void
Inherited from
select()
select(
shapes):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:374
Select shapes (none clears selection): transformer, anchors, selection options instead of options of active tool. Hidden shapes are not selectable, locked ones only without other shapes: selected as a whole (locked group) to be unlocked, not modified (no anchors, options nor move)
Parameters
shapes
(Group | Shape<ShapeConfig>)[]
Drawing shapes or shapes of groups to select, replacing the selection
Returns
void
selectAll()
selectAll():
void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:658
Select every shape of the drawing (nothing if drawing is empty), focus back on drawer
Returns
void
setActive()
setActive(
active):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:353
Activate widget (nothing if disabled): previous widget deactivated, button pressed, then initEvents, updateCursor, overlay shown (if showOverlayOnActive), onActive and drawer focused. Deactivate it: pointer action ended, removeEvents, overlay hidden, onDesactive, button released.
Parameters
active
boolean
Activate (true) or deactivate (false) widget
Returns
void
Inherited from
setArrowheads()
setArrowheads(
heads):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1113
Heads of selected arrows (given ends only)
Parameters
heads
Partial<Arrowheads>
Head of the start, of the end
Returns
void
setArrowType()
setArrowType(
type):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1099
Path of selected arrows, routed again between their ends (on their linked shapes)
Parameters
type
'straight', 'curved' or 'elbow'
Returns
void
setBgColor()
setBgColor(
color):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1091
Change background color of selected rectangles and ellipses
Parameters
color
'transparent' for none
Returns
void
Deprecated
use setFillColor
setColor()
setColor(
color):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1123
Set color for draw
Parameters
color
Fill and stroke of lines and arrows (fill only of highlights), fill of texts, stroke of other shapes
Returns
void
setDisabled()
setDisabled(
disabled):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:123
Disable or enable widget: a disabled widget can not be activated and its button is disabled (also its group when all its widgets are). Drawing tools are disabled in read only.
Parameters
disabled
boolean
Disable widget
Returns
void
Inherited from
setEdges()
setEdges(
edges):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1178
Set corners of selected rectangles: sharp, round (radius from their size) or radius
Parameters
edges
'sharp', 'round' or corner radius
Returns
void
setFillColor()
setFillColor(
color):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1079
Change background color of selected rectangles and ellipses
Parameters
color
'transparent' for none
Returns
void
setOpacity()
setOpacity(
opacity):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1190
Set opacity of shape 0 to 1
Parameters
opacity
number
Opacity of selected shapes, from 0 (transparent) to 1, of frames as a whole (border, title, shapes)
Returns
void
setStrokeStyle()
setStrokeStyle(
style):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1165
Set stroke style of selected outline shapes (not brush lines, which are filled outlines)
Parameters
style
Solid, dashed or dotted: dash computed from stroke width of each shape
Returns
void
setStrokeWidth()
setStrokeWidth(
width):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1143
Set stroke width for draw
Parameters
width
number
Stroke width of selected shapes (not highlights), dashes and arrow heads follow it
Returns
void
setTextStyle()
setTextStyle(
style):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1201
Set text style of selected text
Parameters
style
Partial<TextStyle>
Text attributes to change (font, size, style, alignment...), width kept or widened for font changes
Returns
void
shareLive()
protectedshareLive(...shapes):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:306
Shapes being drawn shown to collaborators while drawing (final state is sent on change)
Parameters
shapes
...DrawingShape[]
Shapes in their current state, sent as a live change of the collaboration session
Returns
void
Inherited from
showOverlay()
showOverlay(
nodes):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:538
Show overlay for selected shapes, text overlay if selection contains only text. Frames have no style: opacity, stacking order and actions only
Parameters
nodes
(Group | Shape<ShapeConfig>)[]
Selected shapes (shapes of groups are used) and frames
Returns
void
showToolOverlay()
showToolOverlay():
void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:210
Overlay shown again (selection cleared), only for a tool showing it while active (not the frame tool, sharing the overlay of shape tools: it would stay shown once the tool is changed)
Returns
void
Inherited from
startAction()
protectedstartAction():void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:231
Pointer action starts (pointer down): shortcuts are disabled and UI (toolbar, overlays...) ignores pointer, pointer followed out of the canvas until it is released
Returns
void
Inherited from
toggleDisable()
toggleDisable():
void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:114
Disable / enable widget, a disabled widget can not be activated
Returns
void
Inherited from
toggleSnapping()
toggleSnapping(
active?):void
Defined in: packages/free-drawing/src/components/toolbar/widgets/Select/Select.ts:1230
Turn snapping to objects on (grid hidden: one snapping at a time) or off, update context menu button, save preferences; nothing when unchanged. Not a change of the drawing (not saved with it, a drag in progress not cut in history). Use drawer.setting.toggleSnapping() to toggle it.
Parameters
active?
boolean = true
Turn snapping on (default) or off
Returns
void
updateCursor()
updateCursor():
void
Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:223
Set stage cursor to the cursor of widget: on activation, and to restore it after a temporary one (pan grabbing)
Returns
void