@ibiz-template/core 0.0.1-beta.17 → 0.0.1-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/system/index.system.js +1 -1
- package/out/ibizsys.d.ts +0 -9
- package/out/ibizsys.d.ts.map +1 -1
- package/out/ibizsys.js +0 -9
- package/out/index.d.ts +0 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +0 -1
- package/package.json +2 -3
- package/src/ibizsys.ts +0 -10
- package/src/index.ts +0 -1
- package/LICENSE +0 -21
- package/out/command/command-register.d.ts +0 -66
- package/out/command/command-register.d.ts.map +0 -1
- package/out/command/command-register.js +0 -113
- package/out/command/command.d.ts +0 -54
- package/out/command/command.d.ts.map +0 -1
- package/out/command/command.js +0 -71
- package/out/command/index.d.ts +0 -10
- package/out/command/index.d.ts.map +0 -1
- package/out/command/index.js +0 -9
- package/out/command/interface/command/command-option.d.ts +0 -23
- package/out/command/interface/command/command-option.d.ts.map +0 -1
- package/out/command/interface/command/command-option.js +0 -1
- package/out/command/interface/command/command.d.ts +0 -74
- package/out/command/interface/command/command.d.ts.map +0 -1
- package/out/command/interface/command/command.js +0 -1
- package/out/command/interface/disposable/disposable.d.ts +0 -4
- package/out/command/interface/disposable/disposable.d.ts.map +0 -1
- package/out/command/interface/disposable/disposable.js +0 -1
- package/out/command/interface/index.d.ts +0 -4
- package/out/command/interface/index.d.ts.map +0 -1
- package/out/command/interface/index.js +0 -1
- package/out/command/utils/index.d.ts +0 -3
- package/out/command/utils/index.d.ts.map +0 -1
- package/out/command/utils/index.js +0 -2
- package/out/command/utils/linked-list.d.ts +0 -16
- package/out/command/utils/linked-list.d.ts.map +0 -1
- package/out/command/utils/linked-list.js +0 -120
- package/out/command/utils/util.d.ts +0 -27
- package/out/command/utils/util.d.ts.map +0 -1
- package/out/command/utils/util.js +0 -77
- package/src/command/command-register.ts +0 -135
- package/src/command/command.ts +0 -79
- package/src/command/index.ts +0 -11
- package/src/command/interface/command/command-option.ts +0 -22
- package/src/command/interface/command/command.ts +0 -86
- package/src/command/interface/disposable/disposable.ts +0 -3
- package/src/command/interface/index.ts +0 -9
- package/src/command/utils/index.ts +0 -2
- package/src/command/utils/linked-list.ts +0 -136
- package/src/command/utils/util.ts +0 -95
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { IDisposable } from '../disposable/disposable';
|
|
2
|
-
import { ICommandOption } from './command-option';
|
|
3
|
-
/**
|
|
4
|
-
* 注册指令
|
|
5
|
-
*
|
|
6
|
-
* @author chitanda
|
|
7
|
-
* @date 2022-06-27 13:06:25
|
|
8
|
-
* @export
|
|
9
|
-
* @interface ICommand
|
|
10
|
-
*/
|
|
11
|
-
export interface ICommand {
|
|
12
|
-
id: string;
|
|
13
|
-
handler: ICommandHandler;
|
|
14
|
-
opts?: ICommandOption;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* 触发指令声明
|
|
18
|
-
*
|
|
19
|
-
* @author chitanda
|
|
20
|
-
* @date 2022-06-28 17:06:10
|
|
21
|
-
* @export
|
|
22
|
-
* @interface Command
|
|
23
|
-
*/
|
|
24
|
-
export interface Command {
|
|
25
|
-
/**
|
|
26
|
-
* Title of the command, like `save`.
|
|
27
|
-
*/
|
|
28
|
-
title: string;
|
|
29
|
-
/**
|
|
30
|
-
* The identifier of the actual command handler.
|
|
31
|
-
* @see {@link commands.registerCommand}
|
|
32
|
-
*/
|
|
33
|
-
command: string;
|
|
34
|
-
/**
|
|
35
|
-
* A tooltip for the command, when represented in the UI.
|
|
36
|
-
*/
|
|
37
|
-
tooltip?: string;
|
|
38
|
-
/**
|
|
39
|
-
* Arguments that the command handler should be
|
|
40
|
-
* invoked with.
|
|
41
|
-
*/
|
|
42
|
-
arguments?: any[];
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 指令处理回调
|
|
46
|
-
*
|
|
47
|
-
* @author chitanda
|
|
48
|
-
* @date 2022-06-27 13:06:33
|
|
49
|
-
* @export
|
|
50
|
-
* @interface ICommandHandler
|
|
51
|
-
*/
|
|
52
|
-
export interface ICommandHandler {
|
|
53
|
-
(...args: any[]): unknown | Promise<unknown>;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 指令控制器集
|
|
57
|
-
*/
|
|
58
|
-
export type ICommandsMap = Map<string, ICommand>;
|
|
59
|
-
/**
|
|
60
|
-
* 注册服务
|
|
61
|
-
*
|
|
62
|
-
* @author chitanda
|
|
63
|
-
* @date 2022-06-27 13:06:16
|
|
64
|
-
* @export
|
|
65
|
-
* @interface ICommandRegistry
|
|
66
|
-
*/
|
|
67
|
-
export interface ICommandRegistry {
|
|
68
|
-
registerCommand(id: string, command: ICommandHandler, opts: ICommandOption): IDisposable;
|
|
69
|
-
registerCommand(id: string, command: ICommandHandler): IDisposable;
|
|
70
|
-
registerCommand(command: ICommand): IDisposable;
|
|
71
|
-
getCommand(id: string): ICommand | undefined;
|
|
72
|
-
getCommands(): ICommandsMap;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=command.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/command/interface/command/command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,eAAe,CACb,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,cAAc,GACnB,WAAW,CAAC;IACf,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,WAAW,CAAC;IACnE,eAAe,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,CAAC;IAChD,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC7C,WAAW,IAAI,YAAY,CAAC;CAC7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"disposable.d.ts","sourceRoot":"","sources":["../../../../src/command/interface/disposable/disposable.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/command/interface/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,OAAO,EACP,eAAe,EACf,YAAY,EACZ,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/command/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare class LinkedList<E> {
|
|
2
|
-
private _first;
|
|
3
|
-
private _last;
|
|
4
|
-
private _size;
|
|
5
|
-
get size(): number;
|
|
6
|
-
isEmpty(): boolean;
|
|
7
|
-
clear(): void;
|
|
8
|
-
unshift(element: E): () => void;
|
|
9
|
-
push(element: E): () => void;
|
|
10
|
-
private _insert;
|
|
11
|
-
shift(): E | undefined;
|
|
12
|
-
pop(): E | undefined;
|
|
13
|
-
private _remove;
|
|
14
|
-
[Symbol.iterator](): Iterator<E>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=linked-list.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"linked-list.d.ts","sourceRoot":"","sources":["../../../src/command/utils/linked-list.ts"],"names":[],"mappings":"AAoBA,qBAAa,UAAU,CAAC,CAAC;IACvB,OAAO,CAAC,MAAM,CAA2B;IAEzC,OAAO,CAAC,KAAK,CAA2B;IAExC,OAAO,CAAC,KAAK,CAAa;IAE1B,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,IAAI,OAAO;IAIlB,KAAK,IAAI,IAAI;IAcb,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,IAAI;IAI/B,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,IAAI;IAI5B,OAAO,CAAC,OAAO;IA6Bf,KAAK,IAAI,CAAC,GAAG,SAAS;IAStB,GAAG,IAAI,CAAC,GAAG,SAAS;IASpB,OAAO,CAAC,OAAO;IAwBd,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;CAOlC"}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
-
/* eslint-disable no-underscore-dangle */
|
|
3
|
-
/* eslint-disable max-classes-per-file */
|
|
4
|
-
class Node {
|
|
5
|
-
constructor(element) {
|
|
6
|
-
this.element = element;
|
|
7
|
-
this.next = Node.Undefined;
|
|
8
|
-
this.prev = Node.Undefined;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
Node.Undefined = new Node(undefined);
|
|
13
|
-
export class LinkedList {
|
|
14
|
-
constructor() {
|
|
15
|
-
this._first = Node.Undefined;
|
|
16
|
-
this._last = Node.Undefined;
|
|
17
|
-
this._size = 0;
|
|
18
|
-
}
|
|
19
|
-
get size() {
|
|
20
|
-
return this._size;
|
|
21
|
-
}
|
|
22
|
-
isEmpty() {
|
|
23
|
-
return this._first === Node.Undefined;
|
|
24
|
-
}
|
|
25
|
-
clear() {
|
|
26
|
-
let node = this._first;
|
|
27
|
-
while (node !== Node.Undefined) {
|
|
28
|
-
const { next } = node;
|
|
29
|
-
node.prev = Node.Undefined;
|
|
30
|
-
node.next = Node.Undefined;
|
|
31
|
-
node = next;
|
|
32
|
-
}
|
|
33
|
-
this._first = Node.Undefined;
|
|
34
|
-
this._last = Node.Undefined;
|
|
35
|
-
this._size = 0;
|
|
36
|
-
}
|
|
37
|
-
unshift(element) {
|
|
38
|
-
return this._insert(element, false);
|
|
39
|
-
}
|
|
40
|
-
push(element) {
|
|
41
|
-
return this._insert(element, true);
|
|
42
|
-
}
|
|
43
|
-
_insert(element, atTheEnd) {
|
|
44
|
-
const newNode = new Node(element);
|
|
45
|
-
if (this._first === Node.Undefined) {
|
|
46
|
-
this._first = newNode;
|
|
47
|
-
this._last = newNode;
|
|
48
|
-
}
|
|
49
|
-
else if (atTheEnd) {
|
|
50
|
-
// push
|
|
51
|
-
const oldLast = this._last;
|
|
52
|
-
this._last = newNode;
|
|
53
|
-
newNode.prev = oldLast;
|
|
54
|
-
oldLast.next = newNode;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
// unshift
|
|
58
|
-
const oldFirst = this._first;
|
|
59
|
-
this._first = newNode;
|
|
60
|
-
newNode.next = oldFirst;
|
|
61
|
-
oldFirst.prev = newNode;
|
|
62
|
-
}
|
|
63
|
-
this._size += 1;
|
|
64
|
-
let didRemove = false;
|
|
65
|
-
return () => {
|
|
66
|
-
if (!didRemove) {
|
|
67
|
-
didRemove = true;
|
|
68
|
-
this._remove(newNode);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
shift() {
|
|
73
|
-
if (this._first === Node.Undefined) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
const res = this._first.element;
|
|
77
|
-
this._remove(this._first);
|
|
78
|
-
return res;
|
|
79
|
-
}
|
|
80
|
-
pop() {
|
|
81
|
-
if (this._last === Node.Undefined) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
const res = this._last.element;
|
|
85
|
-
this._remove(this._last);
|
|
86
|
-
return res;
|
|
87
|
-
}
|
|
88
|
-
_remove(node) {
|
|
89
|
-
if (node.prev !== Node.Undefined && node.next !== Node.Undefined) {
|
|
90
|
-
// middle
|
|
91
|
-
const anchor = node.prev;
|
|
92
|
-
anchor.next = node.next;
|
|
93
|
-
node.next.prev = anchor;
|
|
94
|
-
}
|
|
95
|
-
else if (node.prev === Node.Undefined && node.next === Node.Undefined) {
|
|
96
|
-
// only node
|
|
97
|
-
this._first = Node.Undefined;
|
|
98
|
-
this._last = Node.Undefined;
|
|
99
|
-
}
|
|
100
|
-
else if (node.next === Node.Undefined) {
|
|
101
|
-
// last
|
|
102
|
-
this._last = this._last.prev;
|
|
103
|
-
this._last.next = Node.Undefined;
|
|
104
|
-
}
|
|
105
|
-
else if (node.prev === Node.Undefined) {
|
|
106
|
-
// first
|
|
107
|
-
this._first = this._first.next;
|
|
108
|
-
this._first.prev = Node.Undefined;
|
|
109
|
-
}
|
|
110
|
-
// done
|
|
111
|
-
this._size -= 1;
|
|
112
|
-
}
|
|
113
|
-
*[Symbol.iterator]() {
|
|
114
|
-
let node = this._first;
|
|
115
|
-
while (node !== Node.Undefined) {
|
|
116
|
-
yield node.element;
|
|
117
|
-
node = node.next;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { IDisposable } from '../interface';
|
|
2
|
-
export declare function once<T extends Function>(this: unknown, fn: T): T;
|
|
3
|
-
export declare function toDisposable(fn: () => void): IDisposable;
|
|
4
|
-
/**
|
|
5
|
-
* 函数防抖---“立即执行版本” 和 “非立即执行版本” 的组合版本
|
|
6
|
-
*
|
|
7
|
-
* @author chitanda
|
|
8
|
-
* @date 2022-06-29 19:06:15
|
|
9
|
-
* @export
|
|
10
|
-
* @param {((...args: unknown[]) => void | Promise<void>)} func 处理函数
|
|
11
|
-
* @param {number} wait 延迟执行时间(毫秒)
|
|
12
|
-
* @param {boolean} [immediate] 是否立即执行
|
|
13
|
-
* @return {*} {(...args: unknown[]) => void}
|
|
14
|
-
*/
|
|
15
|
-
export declare function debounce(func: (...args: unknown[]) => void | Promise<void>, wait: number, immediate?: boolean): (...args: unknown[]) => void;
|
|
16
|
-
/**
|
|
17
|
-
* 节流函数
|
|
18
|
-
*
|
|
19
|
-
* @author chitanda
|
|
20
|
-
* @date 2022-06-29 20:06:38
|
|
21
|
-
* @export
|
|
22
|
-
* @param {((...args: unknown[]) => void | Promise<void>)} fn
|
|
23
|
-
* @param {number} wait
|
|
24
|
-
* @return {*} {(...args: unknown[]) => void}
|
|
25
|
-
*/
|
|
26
|
-
export declare function throttle(fn: (...args: unknown[]) => void | Promise<void>, wait: number): (...args: unknown[]) => void;
|
|
27
|
-
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/command/utils/util.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,wBAAgB,IAAI,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAgBhE;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,WAAW,CAOxD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAClD,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,OAAO,GAClB,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAqB9B;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACtB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAChD,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAU9B"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
2
|
-
export function once(fn) {
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
4
|
-
const _this = this;
|
|
5
|
-
let didCall = false;
|
|
6
|
-
let result;
|
|
7
|
-
return function () {
|
|
8
|
-
if (didCall) {
|
|
9
|
-
return result;
|
|
10
|
-
}
|
|
11
|
-
didCall = true;
|
|
12
|
-
result = fn.apply(_this, arguments);
|
|
13
|
-
return result;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export function toDisposable(fn) {
|
|
17
|
-
const self = {
|
|
18
|
-
dispose: once(() => {
|
|
19
|
-
fn();
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
return self;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* 函数防抖---“立即执行版本” 和 “非立即执行版本” 的组合版本
|
|
26
|
-
*
|
|
27
|
-
* @author chitanda
|
|
28
|
-
* @date 2022-06-29 19:06:15
|
|
29
|
-
* @export
|
|
30
|
-
* @param {((...args: unknown[]) => void | Promise<void>)} func 处理函数
|
|
31
|
-
* @param {number} wait 延迟执行时间(毫秒)
|
|
32
|
-
* @param {boolean} [immediate] 是否立即执行
|
|
33
|
-
* @return {*} {(...args: unknown[]) => void}
|
|
34
|
-
*/
|
|
35
|
-
export function debounce(func, wait, immediate) {
|
|
36
|
-
let timer;
|
|
37
|
-
return function (...args) {
|
|
38
|
-
if (timer) {
|
|
39
|
-
clearTimeout(timer);
|
|
40
|
-
}
|
|
41
|
-
if (immediate) {
|
|
42
|
-
const callNow = !timer;
|
|
43
|
-
timer = setTimeout(() => {
|
|
44
|
-
timer = null;
|
|
45
|
-
}, wait);
|
|
46
|
-
if (callNow) {
|
|
47
|
-
func.apply(this, args);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
timer = setTimeout(() => {
|
|
52
|
-
func.apply(this, args);
|
|
53
|
-
}, wait);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* 节流函数
|
|
59
|
-
*
|
|
60
|
-
* @author chitanda
|
|
61
|
-
* @date 2022-06-29 20:06:38
|
|
62
|
-
* @export
|
|
63
|
-
* @param {((...args: unknown[]) => void | Promise<void>)} fn
|
|
64
|
-
* @param {number} wait
|
|
65
|
-
* @return {*} {(...args: unknown[]) => void}
|
|
66
|
-
*/
|
|
67
|
-
export function throttle(fn, wait) {
|
|
68
|
-
let timer = null;
|
|
69
|
-
return function (...args) {
|
|
70
|
-
if (!timer) {
|
|
71
|
-
timer = setTimeout(() => {
|
|
72
|
-
fn.apply(this, args);
|
|
73
|
-
timer = null;
|
|
74
|
-
}, wait);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ICommand,
|
|
3
|
-
ICommandHandler,
|
|
4
|
-
ICommandOption,
|
|
5
|
-
ICommandRegistry,
|
|
6
|
-
ICommandsMap,
|
|
7
|
-
IDisposable,
|
|
8
|
-
} from './interface';
|
|
9
|
-
import { LinkedList, toDisposable } from './utils';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 命令注册中心
|
|
13
|
-
*
|
|
14
|
-
* @author chitanda
|
|
15
|
-
* @date 2022-06-27 13:06:50
|
|
16
|
-
* @export
|
|
17
|
-
* @class CommandRegisterService
|
|
18
|
-
* @implements {ICommandRegistry}
|
|
19
|
-
*/
|
|
20
|
-
export class CommandsRegistry implements ICommandRegistry {
|
|
21
|
-
/**
|
|
22
|
-
* 已经注册的所有指令
|
|
23
|
-
*
|
|
24
|
-
* @author chitanda
|
|
25
|
-
* @date 2022-07-21 15:07:47
|
|
26
|
-
* @private
|
|
27
|
-
*/
|
|
28
|
-
private readonly commands = new Map<string, LinkedList<ICommand>>();
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 注册指令
|
|
32
|
-
*
|
|
33
|
-
* @author chitanda
|
|
34
|
-
* @date 2022-06-27 13:06:31
|
|
35
|
-
* @param {(string | ICommand)} idOrCommand
|
|
36
|
-
* @param {ICommandHandler} [handler]
|
|
37
|
-
* @return {*} {IDisposable}
|
|
38
|
-
*/
|
|
39
|
-
registerCommand(
|
|
40
|
-
idOrCommand: string | ICommand,
|
|
41
|
-
handler?: ICommandHandler,
|
|
42
|
-
opts?: ICommandOption,
|
|
43
|
-
): IDisposable {
|
|
44
|
-
if (!idOrCommand) {
|
|
45
|
-
throw new Error(`invalid command`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (typeof idOrCommand === 'string') {
|
|
49
|
-
if (!handler) {
|
|
50
|
-
throw new Error(`invalid command`);
|
|
51
|
-
}
|
|
52
|
-
return this.registerCommand({ id: idOrCommand, handler, opts });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const { id } = idOrCommand;
|
|
56
|
-
|
|
57
|
-
let commands = this.commands.get(id);
|
|
58
|
-
if (!commands) {
|
|
59
|
-
commands = new LinkedList<ICommand>();
|
|
60
|
-
this.commands.set(id, commands);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const removeFn = commands.unshift(idOrCommand);
|
|
64
|
-
|
|
65
|
-
const ret = toDisposable(() => {
|
|
66
|
-
removeFn();
|
|
67
|
-
const command = this.commands.get(id);
|
|
68
|
-
if (command?.isEmpty()) {
|
|
69
|
-
this.commands.delete(id);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return ret;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 指令是否已经注册
|
|
78
|
-
*
|
|
79
|
-
* @author chitanda
|
|
80
|
-
* @date 2022-07-21 15:07:58
|
|
81
|
-
* @param {string} id
|
|
82
|
-
* @return {*} {boolean}
|
|
83
|
-
*/
|
|
84
|
-
hasCommand(id: string): boolean {
|
|
85
|
-
return this.commands.has(id);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 查找指令
|
|
90
|
-
*
|
|
91
|
-
* @author chitanda
|
|
92
|
-
* @date 2022-07-21 16:07:12
|
|
93
|
-
* @param {string} id
|
|
94
|
-
* @return {*} {(ICommand | undefined)}
|
|
95
|
-
*/
|
|
96
|
-
getCommand(id: string): ICommand | undefined {
|
|
97
|
-
const list = this.commands.get(id);
|
|
98
|
-
if (!list || list.isEmpty()) {
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
return list[Symbol.iterator]().next().value;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 获取所有指令
|
|
106
|
-
*
|
|
107
|
-
* @author chitanda
|
|
108
|
-
* @date 2022-07-21 16:07:20
|
|
109
|
-
* @return {*} {ICommandsMap}
|
|
110
|
-
*/
|
|
111
|
-
getCommands(): ICommandsMap {
|
|
112
|
-
const result = new Map<string, ICommand>();
|
|
113
|
-
const keys = this.commands.keys();
|
|
114
|
-
for (const key of keys) {
|
|
115
|
-
const command = this.getCommand(key);
|
|
116
|
-
if (command) {
|
|
117
|
-
result.set(key, command);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 获取指令配置参数
|
|
125
|
-
*
|
|
126
|
-
* @author chitanda
|
|
127
|
-
* @date 2022-07-21 16:07:27
|
|
128
|
-
* @param {string} id
|
|
129
|
-
* @return {*} {(ICommandOption | undefined)}
|
|
130
|
-
*/
|
|
131
|
-
getCommandOpt(id: string): ICommandOption | undefined {
|
|
132
|
-
const cmd = this.getCommand(id);
|
|
133
|
-
return cmd?.opts;
|
|
134
|
-
}
|
|
135
|
-
}
|
package/src/command/command.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { ICommandHandler, ICommandOption, IDisposable } from './interface';
|
|
2
|
-
import { CommandsRegistry } from './command-register';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 指令控制器
|
|
6
|
-
*
|
|
7
|
-
* @author chitanda
|
|
8
|
-
* @date 2022-06-28 19:06:51
|
|
9
|
-
* @export
|
|
10
|
-
* @class CommandController
|
|
11
|
-
*/
|
|
12
|
-
export class CommandController {
|
|
13
|
-
private commandRegister = new CommandsRegistry();
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 注册指令
|
|
17
|
-
*
|
|
18
|
-
* @author chitanda
|
|
19
|
-
* @date 2022-06-28 19:06:45
|
|
20
|
-
* @param {string} id
|
|
21
|
-
* @param {ICommandHandler} handler
|
|
22
|
-
* @param {ICommandOption} [opts]
|
|
23
|
-
* @return {*} {IDisposable}
|
|
24
|
-
*/
|
|
25
|
-
register(
|
|
26
|
-
id: string,
|
|
27
|
-
handler: ICommandHandler,
|
|
28
|
-
opts?: ICommandOption,
|
|
29
|
-
): IDisposable {
|
|
30
|
-
return this.commandRegister.registerCommand(id, handler, opts);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 执行指令
|
|
35
|
-
*
|
|
36
|
-
* @author chitanda
|
|
37
|
-
* @date 2022-06-28 19:06:38
|
|
38
|
-
* @template T
|
|
39
|
-
* @param {string} id
|
|
40
|
-
* @param {...unknown[]} args
|
|
41
|
-
* @return {*} {Promise<T>}
|
|
42
|
-
*/
|
|
43
|
-
async execute<T = undefined>(id: string, ...args: unknown[]): Promise<T> {
|
|
44
|
-
const command = this.commandRegister.getCommand(id);
|
|
45
|
-
if (command) {
|
|
46
|
-
return command.handler(...args) as T | Promise<T>;
|
|
47
|
-
}
|
|
48
|
-
throw new Error(`未注册指令: ${id},请先注册指令`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 判断指令是否存在,可直接抛出异常
|
|
53
|
-
*
|
|
54
|
-
* @author chitanda
|
|
55
|
-
* @date 2022-06-28 19:06:11
|
|
56
|
-
* @param {string} id
|
|
57
|
-
* @param {boolean} [err]
|
|
58
|
-
* @return {*} {boolean}
|
|
59
|
-
*/
|
|
60
|
-
hasCommand(id: string, err?: boolean): boolean {
|
|
61
|
-
const bol = !!this.commandRegister.hasCommand(id);
|
|
62
|
-
if (err === true && bol === true) {
|
|
63
|
-
throw new Error(`未注册指令: ${id},请先注册指令`);
|
|
64
|
-
}
|
|
65
|
-
return bol;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 获取指令配置参数
|
|
70
|
-
*
|
|
71
|
-
* @author chitanda
|
|
72
|
-
* @date 2022-07-21 17:07:11
|
|
73
|
-
* @param {string} id
|
|
74
|
-
* @return {*} {(ICommandOption | undefined)}
|
|
75
|
-
*/
|
|
76
|
-
getCommandOpts(id: string): ICommandOption | undefined {
|
|
77
|
-
return this.commandRegister.getCommandOpt(id);
|
|
78
|
-
}
|
|
79
|
-
}
|
package/src/command/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CommandController } from './command';
|
|
2
|
-
|
|
3
|
-
export * from './interface';
|
|
4
|
-
export * from './utils';
|
|
5
|
-
export { CommandsRegistry } from './command-register';
|
|
6
|
-
export { CommandController } from './command';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 命令控制器
|
|
10
|
-
*/
|
|
11
|
-
export const commands = new CommandController();
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 指令参数, 主要用于在指令呈现时的展示参数
|
|
3
|
-
*
|
|
4
|
-
* @author chitanda
|
|
5
|
-
* @date 2022-06-28 17:06:47
|
|
6
|
-
* @export
|
|
7
|
-
* @interface ICommandOption
|
|
8
|
-
*/
|
|
9
|
-
export interface ICommandOption {
|
|
10
|
-
readonly id: string;
|
|
11
|
-
readonly title: string;
|
|
12
|
-
readonly tooltip?: string;
|
|
13
|
-
readonly description?: string;
|
|
14
|
-
/**
|
|
15
|
-
* 只支持 svg 图标
|
|
16
|
-
*
|
|
17
|
-
* @author chitanda
|
|
18
|
-
* @date 2022-06-29 14:06:42
|
|
19
|
-
* @type {string}
|
|
20
|
-
*/
|
|
21
|
-
readonly icon?: string;
|
|
22
|
-
}
|