Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KeyEventManager

按键事件管理器。

Hierarchy

Index

Constructors

Properties

context: any

If using the new style context, re-declare this in your class to be the React.ContextType of your static contextType. Should be used with type annotation or static contextType.

static contextType = MyContext
// For TS pre-3.7:
context!: React.ContextType<typeof MyContext>
// For TS 3.7 and above:
declare context: React.ContextType<typeof MyContext>
see

https://reactjs.org/docs/context.html

ctrl_key: {}

临时用来记录哪些按键和ctrl一起被按下了的状态。 注意,这个属性不使用state来处理,因为 1)这是一个临时属性,只在ctrl按下时生效, 2)这个属性不影响render,只影响对外提供的操作函数,本质上是操作函数之中的一个变量。 3)这个属性要求其修改即时响应。 XXX 但是我也不知道这样实现是不是合理的....

Type declaration

  • [key: string]: boolean
elements: {}

记录每个空间中有的元素。

Type declaration

non_space_oprations: {}

Type declaration

refs: {}

Type declaration

spaces: {}

Type declaration

contextType?: <internal>.Context<any>

If set, this.context will be set at runtime to the current value of the given Context.

Usage:

type MyContext = number
const Ctx = React.createContext<MyContext>(0)

class Foo extends React.Component {
static contextType = Ctx
context!: React.ContextType<typeof Ctx>
render () {
return <>My context's value: {this.context}</>;
}
}
see

https://reactjs.org/docs/context.html#classcontexttype

Methods

  • UNSAFE_componentWillMount(): void
  • activate_position(space: string, position: string): void
  • 新激活一个位置。 注意,这个函数通常不需要调用,因为会在当前激活元素切换时在componentDidUpdate中自动调用。

    Parameters

    • space: string
    • position: string

    Returns void

  • activate_position_and_unactivate_old(space: string, position: string): void
  • 激活一个位置,并自动修改cur_position状态,并取消激活之前的位置。

    Parameters

    • space: string
    • position: string

    Returns void

  • componentDidCatch(error: Error, errorInfo: ErrorInfo): void
  • Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.

    Parameters

    Returns void

  • componentDidMount(): void
  • Called immediately after a component is mounted. Setting state here will trigger re-rendering.

    Returns void

  • componentWillMount(): void
  • componentWillUnmount(): void
  • Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.

    Returns void

  • ctrl_down(): boolean
  • 目前ctrl键是否处于按下状态。

    Returns boolean

  • 一个处理鼠标事件的代理函数会处理三种情况:没有按下ctrl因此什么也不做、激活了某一个空间或者非空间操作、在某个空间激活的情况下进行移动。 并且在执行了对应操作的情况下阻止事件传播。 这个函数在这三种情况下都什么也不做,只是阻止事件传播。

    Parameters

    Returns boolean

    是否被本管理器处理。返回true表示本管理器(不一定是这个函数)会处理此事件。

  • flush_key_state(keydown: boolean, e: KeyboardEvent<HTMLDivElement>): boolean
  • 给定一个新的按键事件,设置自己的ctrl_key状态。

    Parameters

    Returns boolean

  • forceUpdate(callback?: (() => void)): void
  • Parameters

    • Optional callback: (() => void)
        • (): void
        • Returns void

    Returns void

  • Runs before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it.

    Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated lifecycle events from running.

    Parameters

    Returns any

  • get_cur_activating(): string
  • 查询当前哪个空间正在被激活。

    Returns string

  • get_cur_position(space: string): string
  • 获得一个空间的位置。

    Parameters

    • space: string

    Returns string

  • get_position_list(space: string): string[]
  • 获取一个空间内的所有元素位置。

    Parameters

    • space: string

    Returns string[]

  • 这个函数代理按键按下事件。 一个处理鼠标事件的代理函数会处理三种情况:没有按下ctrl因此什么也不做、激活了某一个空间或者非空间操作、在某个空间激活的情况下进行移动。 并且在执行了对应操作的情况下阻止事件传播。

    这个函数处理激活某个空间和激活某个非空间操作的的事件,而在最后一种情况下什么也不做。

    Parameters

    Returns boolean

    是否被本管理器处理。返回true表示本管理器(不一定是这个函数)会处理此事件。

  • 这个函数代理按键抬起事件。 一个处理鼠标事件的代理函数会处理三种情况:没有按下ctrl因此什么也不做、激活了某一个空间或者非空间操作、在某个空间激活的情况下进行移动。 并且在执行了对应操作的情况下阻止事件传播。

    这个函数在激活了某一个空间或者非空间操作的情况下都什么也不做(只阻止事件传播),而只处理方向键和回车键的事件。

    Parameters

    Returns boolean

    是否被本管理器处理。返回true表示本管理器(不一定是这个函数)会处理此事件。

  • run_position(e: KeyboardEvent<HTMLDivElement>, space: string, position: string): void
  • 调用一个位置。

    Parameters

    Returns void

  • set_cur_position(space: string, position: string): void
  • 设置一个空间的位置。

    Parameters

    • space: string
    • position: string

    Returns void

  • Called to determine whether the change in props and state should trigger a re-render.

    Component always returns true. PureComponent implements a shallow comparison on props and state and returns true if any props or states have changed.

    If false is returned, Component#render, componentWillUpdate and componentDidUpdate will not be called.

    Parameters

    Returns boolean

  • unactivate_position(space: string, position: string, new_position: string): void
  • 取消激活一个位置。 注意,这个函数通常不需要调用,因为会在当前激活元素切换时在componentDidUpdate中自动调用。

    Parameters

    • space: string
    • position: string
    • new_position: string

    Returns void

  • unregister_space(space: string, position: string): void
  • 取消一个空间。

    Parameters

    • space: string
    • position: string

    Returns void

  • update_props(): void
  • 这个函数从props整理出自身的spacesnon_space_oprations属性。

    Returns void

Generated using TypeDoc