1.10.0 • Published 3 years ago

short-cutting v1.10.0

Weekly downloads
35
License
MIT
Repository
github
Last release
3 years ago

Short-cutting 快捷键事件统一解决方案

安装

yarn add short-cutting

or

npm i short-cutting

内置了 Typescript 支持

使用

ES6 项目中使用

  import { ShortCutting } from 'short-cutting/lib-esm'
  // 引入样式文件
  import 'short-cutting/index.css'

  // 最简使用
  const shortCutting = new ShortCutting()
  shortCutting.on({
    key: 'a',
  }, () => {
    console.log('a is clicked')
  })
  • 主键 支持 key 和 code 两种键声明方式

      shortCutting.on({
        key: 'a',
      }, () => {
        console.log('a is clicked')
      })
    
      shortCutting.on({
        code: 65
      }, () => {
        console.log('a is clicked')
      })
  • 支持 >=1 个辅助键,当前支持 ctrl, command/win, alt, shift

      shortCut.on({
        code: 65,
        content: '全选',
        ctrl: true,
        shift: true,
      }, () => {
        console.log('a')
      } )
  • 支持多种组合键,如果你想使用多套快捷键对应一种行为,比如 ctrl + c, command + c 都表示复制当前内容,那么可以使用 assistArray 数组来表示

      shortCut.on({
        content: '复制',
        assistArray: [{ctrl: true}, { meta: true}],
        showTip: true,
      }, () => {
        console.log('c')
      })

    注意:assistArray 的优先级高于 key 和 code

  • 支持 keyUp 事件 第三个可选参数表示 keyUp 的回调函数

  • 支持多种闪烁时间选择

      const shortCut = new ShortCut({ duration: 'fast' }) // fast | medium | slow

    CDN

    js: https://unpkg.com/short-cutting/_bundles/index.js css: https://unpkg.com/short-cutting/_bundles/index.css

    调起快捷键一览,用于展示所有支持的快捷键

shortCutting.showInstruction()

当前支持的辅助键:

  • ctrl
  • meta (win | command)
  • shift
  • alt

@TODO 功能点:

    1. 支持可选键,比如复制,可以使用 ctrl + c,也可以支持 command + c
    1. 支持快捷键一览表,暴露方法调用
    1. 支持多种主题
    1. 支持八个方向的位置自定义(默认左下)
    1. 支持 onbeforeunload 事件劫持
    1. 支持三种闪烁间隔时间选择:fast | medium | slow
    1. 抽离单独的 type.d.ts 包
    1. 支持 CDN 加载
1.10.0

3 years ago

1.9.3

3 years ago

1.9.2

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago