Skip to content

charton API


charton API / @chart-on/core / index / ActionRegistry

Class: ActionRegistry ​

Defined in: packages/core/src/actions.ts:232

Commands by id and the shortcuts bound to them.

Constructors ​

Constructor ​

new ActionRegistry(): ActionRegistry

Returns ​

ActionRegistry

Accessors ​

keymap ​

Get Signature ​

get keymap(): Record<string, string[]>

Defined in: packages/core/src/actions.ts:301

The app's shortcut changes by action id, to save and pass to setKeymap later.

Returns ​

Record<string, string[]>

Methods ​

actionsFor() ​

actionsFor(keys): string[]

Defined in: packages/core/src/actions.ts:340

Ids of the actions a shortcut runs, e.g. to warn before binding it. Mod checks both Ctrl and Meta.

Parameters ​

keys ​

string

Returns ​

string[]


clear() ​

clear(): void

Defined in: packages/core/src/actions.ts:387

Remove every action, shortcut change and listener.

Returns ​

void


conflicts() ​

conflicts(): ShortcutConflict[]

Defined in: packages/core/src/actions.ts:347

Shortcuts bound to more than one action.

Returns ​

ShortcutConflict[]


get() ​

get(id): ActionState | null

Defined in: packages/core/src/actions.ts:264

The action's state, or null when no action has this id.

Parameters ​

id ​

string

Returns ​

ActionState | null


handleKey() ​

handleKey(e, active?): boolean

Defined in: packages/core/src/actions.ts:370

Run the first enabled action bound to the event's shortcut that does something. active: the chart is hovered or focused, which local actions need. Returns true when one ran.

Parameters ​

e ​

ShortcutEvent

active? ​

boolean = true

Returns ​

boolean


has() ​

has(id): boolean

Defined in: packages/core/src/actions.ts:259

Parameters ​

id ​

string

Returns ​

boolean


keys() ​

keys(id): string[]

Defined in: packages/core/src/actions.ts:296

The shortcuts in effect for an id: the app's if set, else the defaults.

Parameters ​

id ​

string

Returns ​

string[]


list() ​

list(): ActionState[]

Defined in: packages/core/src/actions.ts:270

Every action, in registration order.

Returns ​

ActionState[]


match() ​

match(e): string[]

Defined in: packages/core/src/actions.ts:354

Ids of the actions a key event's shortcut is bound to, best match first, enabled or not.

Parameters ​

e ​

ShortcutEvent

Returns ​

string[]


on() ​

on(event, listener): () => void

Defined in: packages/core/src/actions.ts:380

Called when actions or shortcuts change. Returns an unsubscribe function.

Parameters ​

event ​

"actions:change"

listener ​

() => void

Returns ​

() => void


register() ​

register(def): () => void

Defined in: packages/core/src/actions.ts:245

Add an action. Throws when the id is taken or a default shortcut is invalid. Returns a function that removes it again.

Parameters ​

def ​

ActionDefinition

Returns ​

() => void


run() ​

run(id): boolean

Defined in: packages/core/src/actions.ts:275

Run an action. False when the id is unknown, the action is disabled or it changed nothing.

Parameters ​

id ​

string

Returns ​

boolean


setKeymap() ​

setKeymap(map): KeymapError[]

Defined in: packages/core/src/actions.ts:311

Replace every shortcut change with map (e.g. a saved keymap). Invalid entries are left out and returned; the rest apply.

Parameters ​

map ​

unknown

Returns ​

KeymapError[]


setKeys() ​

setKeys(id, keys): void

Defined in: packages/core/src/actions.ts:285

Set an action's shortcuts: a list replaces its defaults, [] turns its shortcuts off and null restores the defaults. Works for ids registered later too. Throws a RangeError for an invalid shortcut.

Parameters ​

id ​

string

keys ​

readonly string[] | null

Returns ​

void