Skip to content

@fabwcie/free-drawing / components/toolbar/widgets/Text

components/toolbar/widgets/Text ​

Classes ​

TextWidget ​

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:23

Text tool: a click adds a text (or edits the text clicked, or the text of the shape clicked) in a textarea placed over it; once validated, the tool is kept (keepTool) or the selection tool comes back with the text selected. A double click on any text (or title of a frame) edits it, on a rectangle, an ellipse, a path shape or an arrow edits its text (created when it has none, see utils/boundText), whatever the active tool.

Extends

Constructors ​

Constructor ​

new TextWidget(drawer): TextWidget

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:50

Create the text tool, shortcut T: double click on texts of the drawing edits them, fonts preloaded

Parameters
drawer ​

Drawer

Drawer of this widget

Returns

TextWidget

Overrides

BaseWidget.constructor

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

BaseWidget.$button

$container ​

protected readonly $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

BaseWidget.$container

actionOnly ​

readonly actionOnly: 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

BaseWidget.actionOnly

cursor ​

protected cursor: string = 'text'

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:44

Stage cursor while widget is active

Overrides

BaseWidget.cursor

drawer ​

protected drawer: Drawer

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:61

Drawer of this widget

Inherited from

BaseWidget.drawer

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

BaseWidget.id

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

BaseWidget.inAction

isEditing ​

isEditing: boolean = false

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:25

A text is edited in the textarea

options ​

readonly options: WidgetOptions

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:37

Widget options given with drawer widgets option

Inherited from

BaseWidget.options

overlay ​

overlay: TextOverlay

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:43

Options of the tool (color, width...), shown while widget is active (see showOverlayOnActive)

Overrides

BaseWidget.overlay

pressEndedEdit ​

pressEndedEdit: boolean = false

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:32

A press on the canvas ended the edit of a text: the click of a tool writing on click (text, note) adds nothing, read and reset on its press

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

BaseWidget.shortcut

showOverlayOnActive ​

protected showOverlayOnActive: boolean = true

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:47

Show overlay while widget is active (false when overlay depends on something else, e.g. selection)

Inherited from

BaseWidget.showOverlayOnActive

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

TriangleWidget.isDisabled

Methods ​

_afterEdit() ​

private _afterEdit(textNode): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:256

Text validated after a click of this tool: tool kept (keepTool) with its options panel, else selection tool back with the text (or frame of the title) selected

Parameters
textNode ​

Text

Text edited

Returns

void

_createBoundText() ​

private _createBoundText(container): Text

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:134

New text of a shape, placed in it (centered, as wide as its inside), in its frame; in the group of a shape of a group, above it (moved, removed, hidden and duplicated with the group)

Parameters
container ​

Shape

Rectangle, ellipse, path shape or arrow

Returns

Text

The added text node, empty

_createText() ​

private _createText(text, position): Text

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:181

New text added to the drawing (style of the options), in the frame containing it

Parameters
text ​

string

Content, its width fits its longest line when given

position ​

Vector2d

Top left corner of the text, in drawing coordinates

Returns

Text

The added text node

_createTextarea() ​

private _createTextarea(textNode): HTMLTextAreaElement

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:368

Textarea over a text, in floating region: same position, size, font and color whatever zoom and scale, with room around it for glyphs higher than line height

Parameters
textNode ​

Text

Text edited, its absolute position and scale place the textarea

Returns

HTMLTextAreaElement

the textarea, added to the layout

_initEventsTextarea() ​

private _initEventsTextarea(textNode, textarea, onEnd?): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:420

Textarea grows with its content; Enter or a click out of it sets the text, Escape keeps the previous one. Then textarea removed, text shown again (removed if empty, except frame titles which rename their frame) and change fired; edited after a click of this tool: see _afterEdit.

Parameters
textNode ​

Text

Text edited, hidden until the textarea is removed

textarea ​

HTMLTextAreaElement

Textarea over the text, created by _createTextarea

onEnd? ​

(textNode) => void

Called once the edit ended, with the text (null when left empty: removed)

Returns

void

_isEditable() ​

private _isEditable(node): node is Text

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:104

Text of the drawing or title of a frame, edited by a double click or a click of this tool

Parameters
node ​

Node

Node under the pointer

Returns

node is Text

true for a text that can be edited

_loadFonts() ​

private _loadFonts(): Promise<void>

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:80

A font is loaded by browser when first used in page: texts measured (width, line breaks) or drawn before use a fallback font. Load fonts of texts (default one and saved texts ones), then layout texts again.

Returns

Promise<void>

_placeTextarea() ​

private _placeTextarea(textNode, textarea): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:340

Field placed over its text: same position, size and font size whatever zoom and scale, room around it for glyphs higher than line height

Parameters
textNode ​

Text

Text edited, its absolute position and scale place the textarea

textarea ​

HTMLTextAreaElement

Field of the text

Returns

void

_textAt() ​

private _textAt(target): Text | null

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:114

Text edited at the pointer: the text clicked (or title of a frame), else the text of the shape clicked or of the smallest shape around the pointer (created when it has none)

Parameters
target ​

Node

Node under the pointer (the stage on an empty place)

Returns

Text | null

Text to edit, null when there is none

addTextNode() ​

addTextNode(text?, position?): Text

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:167

New text at a position of drawing (pointer by default, center of view when it is out of canvas), in the frame containing it, then selection tool active (paste)

Parameters
text? ​

string = ''

Content, its width fits its longest line when given

position? ​

Vector2d = ...

Top left corner of the text, in drawing coordinates

Returns

Text

The added text node

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

BaseWidget.addTo

afterDraw() ​

protected afterDraw(): 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

BaseWidget.afterDraw

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

BaseWidget.cancelAction

cancelEdit() ​

cancelEdit(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:408

End the text edit in progress keeping the previous text (as Escape): read only started, a new text left empty is removed. Nothing without edit

Returns

void

clearSelection() ​

clearSelection(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:313

Unselect shapes, with selection widget (implemented by it)

Returns

void

Inherited from

BaseWidget.clearSelection

editTextNode() ​

editTextNode(textNode, onEnd?): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:272

Edit a text in a textarea at its place (same font, size, rotation), text and transformer hidden meanwhile. Enter or a press elsewhere (mouse, touch, pen, click) validates, Shift + Enter adds a line, Escape cancels; an empty text is removed.

Parameters
textNode ​

Text

Text of drawing, or title of a frame

onEnd? ​

(textNode) => void

Called once the edit ended, with the text (null when left empty: removed)

Returns

void

editTextOf() ​

editTextOf(container, onEnd?): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:247

Edit the text of a shape (rectangle, ellipse, path shape, arrow, note), created when it has none

Parameters
container ​

Shape

Shape holding the text

onEnd? ​

(textNode) => void

Called once the edit ended, with the text (null when left empty: removed)

Returns

void

endAction() ​

protected endAction(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:254

Pointer action ends (pointer up)

Returns

void

Inherited from

BaseWidget.endAction

followView() ​

followView(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:318

View moved or zoomed during an edit (wheel, pinch, Space): field placed again on its text, at the new zoom

Returns

void

initEvents() ​

protected initEvents(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:209

Click edits the text under the pointer, else adds an empty text there and edits it (not right or middle button, nor the click whose press validated a text). Options panel hidden meanwhile: a press on it would validate the text.

Returns

void

Overrides

BaseWidget.initEvents

onActive() ​

protected onActive(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:231

Tool activated: no press ended an edit with it yet

Returns

void

Overrides

BaseWidget.onActive

onCancel()? ​

protected optional onCancel(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:249

Result of the pointer action discarded before it is cancelled (see cancelAction), also called without action

Returns

void

Inherited from

BaseWidget.onCancel

onConstrainChange()? ​

protected optional onConstrainChange(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

BaseWidget.onConstrainChange

onDesactive() ​

protected onDesactive(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/Text/Text.ts:238

Tool changed: no click to skip

Returns

void

Overrides

BaseWidget.onDesactive

onStage() ​

protected onStage(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

BaseWidget.onStage

removeEvents() ​

protected removeEvents(): void

Defined in: packages/free-drawing/src/components/toolbar/widgets/BaseWidget.ts:192

Remove widget events, called on deactivation

Returns

void

Inherited from

BaseWidget.removeEvents

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

BaseWidget.setActive

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

BaseWidget.setDisabled

shareLive() ​

protected shareLive(...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

BaseWidget.shareLive

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

BaseWidget.showToolOverlay

startAction() ​

protected startAction(): 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

BaseWidget.startAction

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

BaseWidget.toggleDisable

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

Inherited from

BaseWidget.updateCursor