@tethys/cdk 14.2.0-next.6 → 14.2.0
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/esm2020/event/click-dispatcher.mjs +25 -0
- package/esm2020/event/event-dispatcher.mjs +59 -0
- package/esm2020/event/index.mjs +4 -0
- package/esm2020/event/keyboard-dispatcher.mjs +32 -0
- package/esm2020/event/tethys-cdk-event.mjs +5 -0
- package/esm2020/hotkey/hotkey-dispatcher.mjs +55 -0
- package/esm2020/hotkey/hotkey.directive.mjs +55 -0
- package/esm2020/hotkey/hotkey.mjs +23 -0
- package/esm2020/hotkey/index.mjs +5 -0
- package/esm2020/hotkey/module.mjs +18 -0
- package/esm2020/hotkey/tethys-cdk-hotkey.mjs +5 -0
- package/esm2020/immutable/immutable.mjs +9 -3
- package/esm2020/immutable/index.mjs +2 -1
- package/esm2020/immutable/object-producer.mjs +25 -0
- package/esm2020/is/utils.mjs +14 -1
- package/esm2020/public-api.mjs +3 -1
- package/event/click-dispatcher.d.ts +10 -0
- package/event/event-dispatcher.d.ts +19 -0
- package/event/index.d.ts +3 -0
- package/event/keyboard-dispatcher.d.ts +10 -0
- package/fesm2015/tethys-cdk-event.mjs +120 -0
- package/fesm2015/tethys-cdk-event.mjs.map +1 -0
- package/fesm2015/tethys-cdk-hotkey.mjs +153 -0
- package/fesm2015/tethys-cdk-hotkey.mjs.map +1 -0
- package/fesm2015/tethys-cdk-immutable.mjs +33 -3
- package/fesm2015/tethys-cdk-immutable.mjs.map +1 -1
- package/fesm2015/tethys-cdk-is.mjs +14 -1
- package/fesm2015/tethys-cdk-is.mjs.map +1 -1
- package/fesm2015/tethys-cdk.mjs +2 -0
- package/fesm2015/tethys-cdk.mjs.map +1 -1
- package/fesm2020/tethys-cdk-event.mjs +116 -0
- package/fesm2020/tethys-cdk-event.mjs.map +1 -0
- package/fesm2020/tethys-cdk-hotkey.mjs +148 -0
- package/fesm2020/tethys-cdk-hotkey.mjs.map +1 -0
- package/fesm2020/tethys-cdk-immutable.mjs +33 -3
- package/fesm2020/tethys-cdk-immutable.mjs.map +1 -1
- package/fesm2020/tethys-cdk-is.mjs +14 -1
- package/fesm2020/tethys-cdk-is.mjs.map +1 -1
- package/fesm2020/tethys-cdk.mjs +2 -0
- package/fesm2020/tethys-cdk.mjs.map +1 -1
- package/hotkey/hotkey-dispatcher.d.ts +15 -0
- package/hotkey/hotkey.d.ts +2 -0
- package/hotkey/hotkey.directive.d.ts +29 -0
- package/hotkey/index.d.ts +4 -0
- package/hotkey/module.d.ts +7 -0
- package/immutable/immutable.d.ts +2 -0
- package/immutable/index.d.ts +1 -0
- package/immutable/object-producer.d.ts +11 -0
- package/is/utils.d.ts +1 -0
- package/package.json +17 -1
- package/public-api.d.ts +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tethys-cdk-event.mjs","sources":["../../../cdk/event/event-dispatcher.ts","../../../cdk/event/click-dispatcher.ts","../../../cdk/event/keyboard-dispatcher.ts","../../../cdk/event/tethys-cdk-event.ts"],"sourcesContent":["import { fromEvent, Observable, Subject, Subscription } from 'rxjs';\nimport { auditTime } from 'rxjs/operators';\n\nimport { Directive, NgZone, OnDestroy } from '@angular/core';\n\nconst DEFAULT_EVENT_TIME = 100;\n\n@Directive()\nexport abstract class ThyEventDispatcher<T = Event> implements OnDestroy {\n private _globalSubscription: Subscription = null;\n\n private _event$ = new Subject<T>();\n\n private _subscriptionCount = 0;\n\n private _addGlobalListener() {\n this._globalSubscription = this.ngZone.runOutsideAngular(() => {\n return fromEvent<T>(this.document, this.eventName).subscribe((event: T) => {\n this._event$.next(event);\n });\n });\n }\n\n private _removeGlobalListener() {\n if (this._globalSubscription) {\n this._globalSubscription.unsubscribe();\n this._globalSubscription = null;\n }\n }\n\n get globalSubscription(): Subscription {\n return this._globalSubscription;\n }\n\n constructor(protected document: Document, private ngZone: NgZone, private eventName: string) {}\n\n protected subscribe(auditTimeInMs: number = DEFAULT_EVENT_TIME): Observable<T> {\n return new Observable(observer => {\n if (!this._globalSubscription) {\n this._addGlobalListener();\n }\n // In the case of a 0ms delay, use an observable without auditTime\n // since it does add a perceptible delay in processing overhead.\n const subscription =\n auditTimeInMs > 0 ? this._event$.pipe(auditTime(auditTimeInMs)).subscribe(observer) : this._event$.subscribe(observer);\n\n this._subscriptionCount++;\n return () => {\n subscription.unsubscribe();\n this._subscriptionCount--;\n\n if (!this._subscriptionCount) {\n this._removeGlobalListener();\n }\n };\n });\n }\n\n ngOnDestroy() {\n this._removeGlobalListener();\n this._event$.complete();\n }\n}\n","import { Injectable, Inject, NgZone, OnDestroy } from '@angular/core';\nimport { DOCUMENT } from '@angular/common';\nimport { Observable } from 'rxjs';\nimport { ThyEventDispatcher } from './event-dispatcher';\n\nconst DEFAULT_CLICKED_TIME = 100;\n\n@Injectable({\n providedIn: 'root'\n})\nexport class ThyClickDispatcher extends ThyEventDispatcher {\n constructor(@Inject(DOCUMENT) document: any, ngZone: NgZone) {\n super(document, ngZone, 'click');\n }\n\n clicked(auditTimeInMs: number = DEFAULT_CLICKED_TIME): Observable<Event> {\n return this.subscribe(auditTimeInMs);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport { DOCUMENT } from '@angular/common';\nimport { Inject, Injectable, NgZone } from '@angular/core';\nimport { Observable } from 'rxjs';\nimport { ThyEventDispatcher } from './event-dispatcher';\n\nconst DEFAULT_KEYDOWN_TIME = 100;\n\n@Injectable({\n providedIn: 'root'\n})\nexport class ThyKeyboardDispatcher extends ThyEventDispatcher {\n constructor(@Inject(DOCUMENT) document: any, ngZone: NgZone) {\n super(document, ngZone, 'keydown');\n }\n\n keydown(auditTimeInMs: number = DEFAULT_KEYDOWN_TIME): Observable<Event> {\n return this.subscribe(auditTimeInMs);\n }\n}\n\n// @Injectable({ providedIn: 'root' })\n// export class ThyKeyboardDispatcher implements OnDestroy {\n// /** Currently attached keydown refs in the order they were attached. */\n// _attachedKeydownSubjects: Subject<KeyboardEvent>[] = [];\n\n// private _document: Document;\n\n// private _isAttached: boolean;\n\n// /** Keyboard event listener that will be attached to the body. */\n// private _keydownListener = (event: KeyboardEvent) => {\n// const keydownRefs = this._attachedKeydownSubjects;\n\n// for (let i = keydownRefs.length - 1; i > -1; i--) {\n// keydownRefs[i].next(event);\n// break;\n// }\n// }\n\n// /** Detaches the global keyboard event listener. */\n// private _detach() {\n// if (this._isAttached) {\n// this._document.body.removeEventListener(\n// 'keydown',\n// this._keydownListener,\n// true\n// );\n// this._isAttached = false;\n// }\n// }\n\n// constructor(@Inject(DOCUMENT) document: any) {\n// this._document = document;\n// }\n\n// ngOnDestroy() {\n// this._detach();\n// }\n\n// /** Add a new overlay to the list of attached overlay refs. */\n// add(keydownSubject: Subject<KeyboardEvent>): void {\n// // Ensure that we don't get the same overlay multiple times.\n// this.remove(keydownSubject);\n\n// // Lazily start dispatcher once first overlay is added\n// if (!this._isAttached) {\n// this._document.body.addEventListener(\n// 'keydown',\n// this._keydownListener,\n// true\n// );\n// this._isAttached = true;\n// }\n\n// this._attachedKeydownSubjects.push(keydownSubject);\n// }\n\n// /** Remove an keydown ref from the list of attached keydown refs. */\n// remove(keydownRef: Subject<KeyboardEvent>): void {\n// const index = this._attachedKeydownSubjects.indexOf(keydownRef);\n\n// if (index > -1) {\n// this._attachedKeydownSubjects.splice(index, 1);\n// }\n\n// // Remove the global listener once there are no more refs.\n// if (this._attachedKeydownSubjects.length === 0) {\n// this._detach();\n// }\n// }\n// }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAKA,MAAM,kBAAkB,GAAG,GAAG,CAAC;MAGT,kBAAkB,CAAA;AA0BpC,IAAA,WAAA,CAAsB,QAAkB,EAAU,MAAc,EAAU,SAAiB,EAAA;QAArE,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAU;QAAU,IAAM,C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A,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,cAFlB,MAAM,EAAA,CAAA,CAAA;2FAET,qBAAqB,EAAA,UAAA,EAAA,CAAA;kBAHjC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,UAAU,EAAE,MAAM;AACrB,iBAAA,CAAA;;0BAEgB,MAAM;2BAAC,QAAQ,CAAA;;;ACnBhC;;AAEG;;;;"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, Inject, EventEmitter, Directive, Input, Output, NgModule } from '@angular/core';
|
|
3
|
+
import { DOCUMENT } from '@angular/common';
|
|
4
|
+
import { isString, isUndefinedOrNull, isFormElement } from '@tethys/cdk/is';
|
|
5
|
+
import { coerceElement } from '@angular/cdk/coercion';
|
|
6
|
+
import { ThyEventDispatcher } from '@tethys/cdk/event';
|
|
7
|
+
import { fromEvent, Observable } from 'rxjs';
|
|
8
|
+
import { filter } from 'rxjs/operators';
|
|
9
|
+
|
|
10
|
+
const modifierKeyNames = [`Control`, 'Alt', 'Meta', 'Shift'];
|
|
11
|
+
// We don't want to show `Shift` when `event.key` is capital
|
|
12
|
+
function showShift(event) {
|
|
13
|
+
const { shiftKey, code, key } = event;
|
|
14
|
+
return shiftKey && !(code.startsWith('Key') && key.toUpperCase() === key);
|
|
15
|
+
}
|
|
16
|
+
function hotkey(event) {
|
|
17
|
+
const { ctrlKey, altKey, metaKey, key } = event;
|
|
18
|
+
const hotkeyString = [];
|
|
19
|
+
const modifiers = [ctrlKey, altKey, metaKey, showShift(event)];
|
|
20
|
+
for (const [i, mod] of modifiers.entries()) {
|
|
21
|
+
if (mod)
|
|
22
|
+
hotkeyString.push(modifierKeyNames[i]);
|
|
23
|
+
}
|
|
24
|
+
if (!modifierKeyNames.includes(key)) {
|
|
25
|
+
hotkeyString.push(key);
|
|
26
|
+
}
|
|
27
|
+
return hotkeyString.join('+');
|
|
28
|
+
}
|
|
29
|
+
function isHotkey(event, key) {
|
|
30
|
+
return key.toUpperCase() === hotkey(event).toUpperCase();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class ThyHotkeyDispatcher extends ThyEventDispatcher {
|
|
34
|
+
constructor(document, ngZone) {
|
|
35
|
+
super(document, ngZone, 'keydown');
|
|
36
|
+
}
|
|
37
|
+
createKeydownObservable(scope) {
|
|
38
|
+
if (scope === this.document) {
|
|
39
|
+
return this.subscribe(null);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return fromEvent(scope, 'keydown');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 热键事件订阅
|
|
47
|
+
*/
|
|
48
|
+
keydown(hotkey, scope) {
|
|
49
|
+
const hotkeys = isString(hotkey) ? hotkey.split(',') : hotkey;
|
|
50
|
+
const scopeElement = coerceElement(isUndefinedOrNull(scope) ? this.document : scope);
|
|
51
|
+
const keydown = this.createKeydownObservable(scopeElement);
|
|
52
|
+
return new Observable(subscriber => {
|
|
53
|
+
const subscription = keydown
|
|
54
|
+
.pipe(filter((event) => hotkeys.some(key => isHotkey(event, key))))
|
|
55
|
+
.subscribe((event) => {
|
|
56
|
+
this.keydownSubscriber = subscriber;
|
|
57
|
+
// setTimeout 是为了解决 Hotkey 冲突时仅执行最后订阅的事件
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
this.keydownSubscriber?.next(event);
|
|
60
|
+
this.keydownSubscriber = null;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return () => {
|
|
64
|
+
subscription.unsubscribe();
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
ThyHotkeyDispatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyDispatcher, deps: [{ token: DOCUMENT }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
70
|
+
ThyHotkeyDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyDispatcher, providedIn: 'root' });
|
|
71
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyDispatcher, decorators: [{
|
|
72
|
+
type: Injectable,
|
|
73
|
+
args: [{ providedIn: 'root' }]
|
|
74
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
75
|
+
type: Inject,
|
|
76
|
+
args: [DOCUMENT]
|
|
77
|
+
}] }, { type: i0.NgZone }]; } });
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @name thyHotkey
|
|
81
|
+
*/
|
|
82
|
+
class ThyHotkeyDirective {
|
|
83
|
+
constructor(document, hotkeyDispatcher, elementRef) {
|
|
84
|
+
this.document = document;
|
|
85
|
+
this.hotkeyDispatcher = hotkeyDispatcher;
|
|
86
|
+
this.elementRef = elementRef;
|
|
87
|
+
/**
|
|
88
|
+
* 热键触发后的事件
|
|
89
|
+
*/
|
|
90
|
+
this.thyHotkeyListener = new EventEmitter();
|
|
91
|
+
this.subscription = null;
|
|
92
|
+
}
|
|
93
|
+
ngOnInit() {
|
|
94
|
+
const scope = isString(this.thyHotkeyScope) ? this.document.querySelector(this.thyHotkeyScope) : this.thyHotkeyScope;
|
|
95
|
+
this.subscription = this.hotkeyDispatcher.keydown(this.thyHotkey, scope).subscribe(event => {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
if (isFormElement(this.elementRef)) {
|
|
98
|
+
this.elementRef.nativeElement.focus();
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.elementRef.nativeElement.click();
|
|
102
|
+
}
|
|
103
|
+
this.thyHotkeyListener.emit(event);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
ngOnDestroy() {
|
|
107
|
+
if (this.subscription) {
|
|
108
|
+
this.subscription.unsubscribe();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
ThyHotkeyDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyDirective, deps: [{ token: DOCUMENT }, { token: ThyHotkeyDispatcher }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
113
|
+
ThyHotkeyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.0", type: ThyHotkeyDirective, selector: "[thyHotkey]", inputs: { thyHotkey: "thyHotkey", thyHotkeyScope: "thyHotkeyScope" }, outputs: { thyHotkeyListener: "thyHotkeyListener" }, ngImport: i0 });
|
|
114
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyDirective, decorators: [{
|
|
115
|
+
type: Directive,
|
|
116
|
+
args: [{ selector: '[thyHotkey]' }]
|
|
117
|
+
}], ctorParameters: function () { return [{ type: Document, decorators: [{
|
|
118
|
+
type: Inject,
|
|
119
|
+
args: [DOCUMENT]
|
|
120
|
+
}] }, { type: ThyHotkeyDispatcher }, { type: i0.ElementRef }]; }, propDecorators: { thyHotkey: [{
|
|
121
|
+
type: Input
|
|
122
|
+
}], thyHotkeyScope: [{
|
|
123
|
+
type: Input
|
|
124
|
+
}], thyHotkeyListener: [{
|
|
125
|
+
type: Output
|
|
126
|
+
}] } });
|
|
127
|
+
|
|
128
|
+
class ThyHotkeyModule {
|
|
129
|
+
}
|
|
130
|
+
ThyHotkeyModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
131
|
+
ThyHotkeyModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyModule, declarations: [ThyHotkeyDirective], exports: [ThyHotkeyDirective] });
|
|
132
|
+
ThyHotkeyModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyModule });
|
|
133
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: ThyHotkeyModule, decorators: [{
|
|
134
|
+
type: NgModule,
|
|
135
|
+
args: [{
|
|
136
|
+
imports: [],
|
|
137
|
+
exports: [ThyHotkeyDirective],
|
|
138
|
+
declarations: [ThyHotkeyDirective],
|
|
139
|
+
providers: []
|
|
140
|
+
}]
|
|
141
|
+
}] });
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Generated bundle index. Do not edit.
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
export { ThyHotkeyDirective, ThyHotkeyDispatcher, ThyHotkeyModule, hotkey, isHotkey };
|
|
148
|
+
//# sourceMappingURL=tethys-cdk-hotkey.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tethys-cdk-hotkey.mjs","sources":["../../../cdk/hotkey/hotkey.ts","../../../cdk/hotkey/hotkey-dispatcher.ts","../../../cdk/hotkey/hotkey.directive.ts","../../../cdk/hotkey/module.ts","../../../cdk/hotkey/tethys-cdk-hotkey.ts"],"sourcesContent":["const modifierKeyNames: string[] = [`Control`, 'Alt', 'Meta', 'Shift'];\n\n// We don't want to show `Shift` when `event.key` is capital\nfunction showShift(event: KeyboardEvent): boolean {\n const { shiftKey, code, key } = event;\n return shiftKey && !(code.startsWith('Key') && key.toUpperCase() === key);\n}\n\nexport function hotkey(event: KeyboardEvent): string {\n const { ctrlKey, altKey, metaKey, key } = event;\n const hotkeyString: string[] = [];\n const modifiers: boolean[] = [ctrlKey, altKey, metaKey, showShift(event)];\n for (const [i, mod] of modifiers.entries()) {\n if (mod) hotkeyString.push(modifierKeyNames[i]);\n }\n\n if (!modifierKeyNames.includes(key)) {\n hotkeyString.push(key);\n }\n\n return hotkeyString.join('+');\n}\n\nexport function isHotkey(event: KeyboardEvent, key: string) {\n return key.toUpperCase() === hotkey(event).toUpperCase();\n}\n","import { coerceElement } from '@angular/cdk/coercion';\nimport { DOCUMENT } from '@angular/common';\nimport { Inject, Injectable, NgZone, ElementRef } from '@angular/core';\nimport { ThyEventDispatcher } from '@tethys/cdk/event';\nimport { fromEvent, Observable, Subscriber } from 'rxjs';\nimport { filter } from 'rxjs/operators';\nimport { isString, isUndefinedOrNull } from '@tethys/cdk/is';\nimport { isHotkey } from './hotkey';\n\n@Injectable({ providedIn: 'root' })\nexport class ThyHotkeyDispatcher extends ThyEventDispatcher {\n private keydownSubscriber: Subscriber<KeyboardEvent>;\n\n constructor(@Inject(DOCUMENT) document: any, ngZone: NgZone) {\n super(document, ngZone, 'keydown');\n }\n\n private createKeydownObservable(scope: Element | Document) {\n if (scope === this.document) {\n return this.subscribe(null);\n } else {\n return fromEvent(scope, 'keydown');\n }\n }\n\n /**\n * 热键事件订阅\n */\n keydown(hotkey: string | string[], scope?: ElementRef<Element> | Element | Document): Observable<KeyboardEvent> {\n const hotkeys = isString(hotkey) ? hotkey.split(',') : hotkey;\n const scopeElement = coerceElement(isUndefinedOrNull(scope) ? this.document : scope);\n const keydown = this.createKeydownObservable(scopeElement);\n return new Observable<KeyboardEvent>(subscriber => {\n const subscription = keydown\n .pipe(filter((event: KeyboardEvent) => hotkeys.some(key => isHotkey(event, key))))\n .subscribe((event: KeyboardEvent) => {\n this.keydownSubscriber = subscriber;\n // setTimeout 是为了解决 Hotkey 冲突时仅执行最后订阅的事件\n setTimeout(() => {\n this.keydownSubscriber?.next(event);\n this.keydownSubscriber = null;\n });\n });\n return () => {\n subscription.unsubscribe();\n };\n });\n }\n}\n","import { DOCUMENT } from '@angular/common';\nimport { Directive, ElementRef, EventEmitter, Inject, Input, OnInit, Output, OnDestroy } from '@angular/core';\nimport { Subscription } from 'rxjs';\nimport { isFormElement, isString } from '@tethys/cdk/is';\nimport { ThyHotkeyDispatcher } from './hotkey-dispatcher';\n\n/**\n * @name thyHotkey\n */\n@Directive({ selector: '[thyHotkey]' })\nexport class ThyHotkeyDirective implements OnInit, OnDestroy {\n /**\n * 热键对应 Code,多个热键组合支持通过数组或逗号分割的形式传入\n */\n @Input() thyHotkey: string | string[];\n\n /**\n * 配置热键触发范围,默认绑定在 document 上\n */\n @Input() thyHotkeyScope?: string | Element | ElementRef<Element>;\n\n /**\n * 热键触发后的事件\n */\n @Output() thyHotkeyListener: EventEmitter<KeyboardEvent> = new EventEmitter();\n\n private subscription: Subscription = null;\n\n constructor(\n @Inject(DOCUMENT) private document: Document,\n private hotkeyDispatcher: ThyHotkeyDispatcher,\n private elementRef: ElementRef<HTMLElement>\n ) {}\n\n ngOnInit(): void {\n const scope = isString(this.thyHotkeyScope) ? this.document.querySelector(this.thyHotkeyScope) : this.thyHotkeyScope;\n this.subscription = this.hotkeyDispatcher.keydown(this.thyHotkey, scope).subscribe(event => {\n event.preventDefault();\n if (isFormElement(this.elementRef)) {\n this.elementRef.nativeElement.focus();\n } else {\n this.elementRef.nativeElement.click();\n }\n this.thyHotkeyListener.emit(event);\n });\n }\n\n ngOnDestroy(): void {\n if (this.subscription) {\n this.subscription.unsubscribe();\n }\n }\n}\n","import { NgModule } from '@angular/core';\nimport { ThyHotkeyDirective } from './hotkey.directive';\n\n@NgModule({\n imports: [],\n exports: [ThyHotkeyDirective],\n declarations: [ThyHotkeyDirective],\n providers: []\n})\nexport class ThyHotkeyModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1.ThyHotkeyDispatcher"],"mappings":";;;;;;;;;AAAA,MAAM,gBAAgB,GAAa,CAAC,CAAS,OAAA,CAAA,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAEvE;AACA,SAAS,SAAS,CAAC,KAAoB,EAAA;IACnC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG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KG,cAAc,EAAA,CAAA;sBAAtB,KAAK;gBAKI,iBAAiB,EAAA,CAAA;sBAA1B,MAAM;;;MCfE,eAAe,CAAA;;4GAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;6GAAf,eAAe,EAAA,YAAA,EAAA,CAHT,kBAAkB,CAAA,EAAA,OAAA,EAAA,CADvB,kBAAkB,CAAA,EAAA,CAAA,CAAA;6GAInB,eAAe,EAAA,CAAA,CAAA;2FAAf,eAAe,EAAA,UAAA,EAAA,CAAA;kBAN3B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACN,oBAAA,OAAO,EAAE,EAAE;oBACX,OAAO,EAAE,CAAC,kBAAkB,CAAC;oBAC7B,YAAY,EAAE,CAAC,kBAAkB,CAAC;AAClC,oBAAA,SAAS,EAAE,EAAE;AAChB,iBAAA,CAAA;;;ACRD;;AAEG;;;;"}
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { coerceArray } from '@angular/cdk/coercion';
|
|
2
|
-
import { isFunction, isUndefinedOrNull } from '@tethys/cdk/is';
|
|
2
|
+
import { isFunction, isUndefinedOrNull, isArray } from '@tethys/cdk/is';
|
|
3
|
+
|
|
4
|
+
class ObjectProducer {
|
|
5
|
+
constructor(entity) {
|
|
6
|
+
this.entity = entity;
|
|
7
|
+
}
|
|
8
|
+
get(propPath) {
|
|
9
|
+
return propPath.split('.').reduce((previousValue, part) => previousValue && previousValue[part], this.entity);
|
|
10
|
+
}
|
|
11
|
+
set(propPath, value) {
|
|
12
|
+
const newEntity = { ...this.entity };
|
|
13
|
+
const split = propPath.split('.');
|
|
14
|
+
const lastIndex = split.length - 1;
|
|
15
|
+
split.reduce((previousValue, part, index) => {
|
|
16
|
+
if (index === lastIndex) {
|
|
17
|
+
previousValue[part] = value;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
previousValue[part] = Array.isArray(previousValue[part]) ? previousValue[part].slice() : { ...previousValue[part] };
|
|
21
|
+
}
|
|
22
|
+
return previousValue && previousValue[part];
|
|
23
|
+
}, newEntity);
|
|
24
|
+
this.entity = newEntity;
|
|
25
|
+
return newEntity;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
3
28
|
|
|
4
29
|
class Producer {
|
|
5
30
|
constructor(entities, options) {
|
|
@@ -105,12 +130,17 @@ class Producer {
|
|
|
105
130
|
}
|
|
106
131
|
}
|
|
107
132
|
function produce(entities, options) {
|
|
108
|
-
|
|
133
|
+
if (isArray(entities)) {
|
|
134
|
+
return new Producer(entities, options);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return new ObjectProducer(entities);
|
|
138
|
+
}
|
|
109
139
|
}
|
|
110
140
|
|
|
111
141
|
/**
|
|
112
142
|
* Generated bundle index. Do not edit.
|
|
113
143
|
*/
|
|
114
144
|
|
|
115
|
-
export { Producer, produce };
|
|
145
|
+
export { ObjectProducer, Producer, produce };
|
|
116
146
|
//# sourceMappingURL=tethys-cdk-immutable.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tethys-cdk-immutable.mjs","sources":["../../../cdk/immutable/immutable.ts","../../../cdk/immutable/tethys-cdk-immutable.ts"],"sourcesContent":["import { coerceArray } from '@angular/cdk/coercion';\nimport { isFunction, isUndefinedOrNull } from '@tethys/cdk/is';\n\nexport type Id = string | number;\n\nexport interface EntityAddOptions {\n prepend?: boolean;\n\n afterId?: Id;\n}\n\nexport interface EntityMoveOptions {\n afterId?: Id;\n\n toIndex?: number;\n}\n\ntype ExtractKeysOfValueType<T, K> = { [I in keyof T]: T[I] extends K ? I : never }[keyof T];\nexport interface ProducerOptions<TEntity> {\n idKey?: ExtractKeysOfValueType<TEntity, Id>;\n}\n\nexport class Producer<TEntity> {\n private idKey = '_id';\n\n private entities: TEntity[];\n\n constructor(entities: TEntity[], options?: ProducerOptions<TEntity>) {\n this.entities = entities || [];\n if (options && options.idKey) {\n this.idKey = options.idKey as string;\n }\n }\n\n /**\n * Add an entity or entities.\n *\n * @example\n * produce([users]).add(Entity);\n * produce([users]).add([Entity, Entity]);\n * produce([users]).add(Entity, { prepend: true });\n * produce([users]).add(Entity, { afterId: '' });\n */\n add(entity: TEntity | TEntity[], addOptions?: EntityAddOptions): TEntity[] {\n const addEntities = coerceArray(entity);\n if (addEntities.length === 0) {\n return this.entities;\n }\n if (addOptions && (addOptions.afterId || addOptions.prepend)) {\n if (addOptions.afterId) {\n const entities = [...this.entities];\n const index =\n this.entities.findIndex(item => {\n return item[this.idKey] === addOptions.afterId;\n }) + 1;\n entities.splice(index, 0, ...addEntities);\n this.entities = [...entities];\n } else if (addOptions.prepend) {\n this.entities = [...addEntities, ...this.entities];\n }\n } else {\n this.entities = [...this.entities, ...addEntities];\n }\n return this.entities;\n }\n\n /**\n *\n * Update an entity or entities.\n *\n * @example\n * produce([users]).update(3, {\n * name: 'New Name'\n * });\n *\n * produce([users]).update(3, entity => {\n * return {\n * ...entity,\n * name: 'New Name'\n * }\n * });\n *\n * produce([users]).update([1,2,3], {\n * name: 'New Name'\n * });\n */\n update(id: Id | Id[] | null, newStateFn: (entity: Readonly<TEntity>) => Partial<TEntity>): TEntity[];\n update(id: Id | Id[] | null, newState?: Partial<TEntity>): TEntity[];\n update(\n idsOrFn: Id | Id[] | null | Partial<TEntity> | ((entity: Readonly<TEntity>) => boolean),\n newStateOrFn?: ((entity: Readonly<TEntity>) => Partial<TEntity>) | Partial<TEntity>\n ): TEntity[] {\n const ids = coerceArray(idsOrFn);\n\n for (let i = 0; i < this.entities.length; i++) {\n const oldEntity = this.entities[i];\n if (ids.indexOf(oldEntity[this.idKey]) >= 0) {\n const newState = isFunction(newStateOrFn) ? newStateOrFn(oldEntity) : newStateOrFn;\n this.entities[i] = { ...oldEntity, ...newState };\n }\n }\n return [...this.entities];\n }\n\n /**\n *\n * Remove one or more entities:\n *\n * @example\n * produce([users]).remove(5);\n * produce([users]).remove([1,2,3]);\n * produce([users]).remove(entity => entity.id === 1);\n */\n remove(id: Id | Id[]): TEntity[];\n remove(predicate: (entity: Readonly<TEntity>) => boolean): TEntity[];\n remove(idsOrFn?: Id | Id[] | ((entity: Readonly<TEntity>) => boolean)): TEntity[] {\n if (isFunction(idsOrFn)) {\n this.entities = this.entities.filter(entity => {\n return !(idsOrFn as any)(entity);\n });\n } else {\n const ids = coerceArray(idsOrFn);\n this.entities = this.entities.filter(entity => {\n return ids.indexOf(entity[this.idKey]) === -1;\n });\n }\n return this.entities;\n }\n\n /**\n *\n * Move one or more entities:\n *\n * @example\n * produce([users]).move(5, {afterId: 2});\n * produce([users]).move(5, {toIndex: 0});\n */\n move(id: Id, moveOptions?: EntityMoveOptions): TEntity[] {\n const fromIndex = this.entities.findIndex(item => item[this.idKey] === id);\n let toIndex = 0;\n const newEntities = [...this.entities];\n\n if (!id || fromIndex < 0) {\n return [...this.entities];\n }\n\n if (moveOptions) {\n if (!isUndefinedOrNull(moveOptions.afterId)) {\n toIndex = this.entities.findIndex(item => item[this.idKey] === moveOptions.afterId);\n } else if (moveOptions.toIndex) {\n toIndex = moveOptions.toIndex;\n }\n }\n toIndex = Math.max(0, Math.min(this.entities.length - 1, toIndex));\n if (toIndex === fromIndex) {\n return [...this.entities];\n } else {\n const target = this.entities[fromIndex];\n const delta = toIndex < fromIndex ? -1 : 1;\n\n for (let i = fromIndex; i !== toIndex; i += delta) {\n newEntities[i] = newEntities[i + delta];\n }\n newEntities[toIndex] = target;\n return [...newEntities];\n }\n }\n}\n\nexport function produce<TEntity>(entities: TEntity[], options?: ProducerOptions<TEntity>) {\n return new Producer<TEntity>(entities, options);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;MAsBa,QAAQ,CAAA;IAKjB,WAAY,CAAA,QAAmB,EAAE,OAAkC,EAAA;QAJ3D,IAAK,CAAA,KAAA,GAAG,KAAK,CAAC;AAKlB,QAAA,IAAI,CAAC,QAAQ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M,KAAK,GAAG,OAAO,GAAG,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAE3C,YAAA,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC,IAAI,KAAK,EAAE;gBAC/C,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;AAC3C,aAAA;AACD,YAAA,WAAW,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;AAC9B,YAAA,OAAO,CAAC,GAAG,WAAW,CAAC,CAAC;AAC3B,SAAA;KACJ;AACJ,CAAA;AAEe,SAAA,OAAO,CAAU,QAAmB,EAAE,OAAkC,EAAA;AACpF,IAAA,OAAO,IAAI,QAAQ,CAAU,QAAQ,EAAE,OAAO,CAAC,CAAC;AACpD;;AC3KA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"tethys-cdk-immutable.mjs","sources":["../../../cdk/immutable/object-producer.ts","../../../cdk/immutable/immutable.ts","../../../cdk/immutable/tethys-cdk-immutable.ts"],"sourcesContent":["/* eslint-disable prettier/prettier */\ntype GetIndexedField<T, K> = K extends keyof T\n ? T[K]\n : K extends `${number}`\n ? '0' extends keyof T\n ? undefined\n : number extends keyof T\n ? T[number]\n : undefined\n : undefined\ntype FieldWithPossiblyUndefined<T, Key> =\n | GetFieldType<Exclude<T, undefined>, Key>\n | Extract<T, undefined>\ntype IndexedFieldWithPossiblyUndefined<T, Key> =\n | GetIndexedField<Exclude<T, undefined>, Key>\n | Extract<T, undefined>\nexport type GetFieldType<T, P> = P extends `${infer Left}.${infer Right}`\n ? Left extends keyof T\n ? FieldWithPossiblyUndefined<T[Left], Right>\n : Left extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? FieldWithPossiblyUndefined<IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>, Right>\n : undefined\n : undefined\n : P extends keyof T\n ? T[P]\n : P extends `${infer FieldKey}[${infer IndexKey}]`\n ? FieldKey extends keyof T\n ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>\n : undefined\n : undefined;\n\nexport class ObjectProducer<TEntity> {\n entity: TEntity;\n\n constructor(entity: TEntity) {\n this.entity = entity;\n }\n\n get<TPath extends string>(propPath: TPath): GetFieldType<TEntity, TPath> {\n return propPath.split('.').reduce((previousValue: any, part: string) => previousValue && previousValue[part], this.entity);\n }\n\n set<TPath extends string>(propPath: TPath, value: GetFieldType<TEntity, TPath>) {\n const newEntity = { ...this.entity };\n\n const split = propPath.split('.');\n const lastIndex = split.length - 1;\n\n split.reduce((previousValue, part, index) => {\n if (index === lastIndex) {\n previousValue[part] = value;\n } else {\n previousValue[part] = Array.isArray(previousValue[part]) ? previousValue[part].slice() : { ...previousValue[part] };\n }\n\n return previousValue && previousValue[part];\n }, newEntity);\n\n this.entity = newEntity\n return newEntity;\n }\n}\n","import { coerceArray } from '@angular/cdk/coercion';\nimport { isFunction, isUndefinedOrNull, isArray } from '@tethys/cdk/is';\nimport { ObjectProducer } from './object-producer';\n\nexport type Id = string | number;\n\nexport interface EntityAddOptions {\n prepend?: boolean;\n\n afterId?: Id;\n}\n\nexport interface EntityMoveOptions {\n afterId?: Id;\n\n toIndex?: number;\n}\n\ntype ExtractKeysOfValueType<T, K> = { [I in keyof T]: T[I] extends K ? I : never }[keyof T];\nexport interface ProducerOptions<TEntity> {\n idKey?: ExtractKeysOfValueType<TEntity, Id>;\n}\n\nexport class Producer<TEntity> {\n private idKey = '_id';\n\n private entities: TEntity[];\n\n constructor(entities: TEntity[], options?: ProducerOptions<TEntity>) {\n this.entities = entities || [];\n if (options && options.idKey) {\n this.idKey = options.idKey as string;\n }\n }\n\n /**\n * Add an entity or entities.\n *\n * @example\n * produce([users]).add(Entity);\n * produce([users]).add([Entity, Entity]);\n * produce([users]).add(Entity, { prepend: true });\n * produce([users]).add(Entity, { afterId: '' });\n */\n add(entity: TEntity | TEntity[], addOptions?: EntityAddOptions): TEntity[] {\n const addEntities = coerceArray(entity);\n if (addEntities.length === 0) {\n return this.entities;\n }\n if (addOptions && (addOptions.afterId || addOptions.prepend)) {\n if (addOptions.afterId) {\n const entities = [...this.entities];\n const index =\n this.entities.findIndex(item => {\n return item[this.idKey] === addOptions.afterId;\n }) + 1;\n entities.splice(index, 0, ...addEntities);\n this.entities = [...entities];\n } else if (addOptions.prepend) {\n this.entities = [...addEntities, ...this.entities];\n }\n } else {\n this.entities = [...this.entities, ...addEntities];\n }\n return this.entities;\n }\n\n /**\n *\n * Update an entity or entities.\n *\n * @example\n * produce([users]).update(3, {\n * name: 'New Name'\n * });\n *\n * produce([users]).update(3, entity => {\n * return {\n * ...entity,\n * name: 'New Name'\n * }\n * });\n *\n * produce([users]).update([1,2,3], {\n * name: 'New Name'\n * });\n */\n update(id: Id | Id[] | null, newStateFn: (entity: Readonly<TEntity>) => Partial<TEntity>): TEntity[];\n update(id: Id | Id[] | null, newState?: Partial<TEntity>): TEntity[];\n update(\n idsOrFn: Id | Id[] | null | Partial<TEntity> | ((entity: Readonly<TEntity>) => boolean),\n newStateOrFn?: ((entity: Readonly<TEntity>) => Partial<TEntity>) | Partial<TEntity>\n ): TEntity[] {\n const ids = coerceArray(idsOrFn);\n\n for (let i = 0; i < this.entities.length; i++) {\n const oldEntity = this.entities[i];\n if (ids.indexOf(oldEntity[this.idKey]) >= 0) {\n const newState = isFunction(newStateOrFn) ? newStateOrFn(oldEntity) : newStateOrFn;\n this.entities[i] = { ...oldEntity, ...newState };\n }\n }\n return [...this.entities];\n }\n\n /**\n *\n * Remove one or more entities:\n *\n * @example\n * produce([users]).remove(5);\n * produce([users]).remove([1,2,3]);\n * produce([users]).remove(entity => entity.id === 1);\n */\n remove(id: Id | Id[]): TEntity[];\n remove(predicate: (entity: Readonly<TEntity>) => boolean): TEntity[];\n remove(idsOrFn?: Id | Id[] | ((entity: Readonly<TEntity>) => boolean)): TEntity[] {\n if (isFunction(idsOrFn)) {\n this.entities = this.entities.filter(entity => {\n return !(idsOrFn as any)(entity);\n });\n } else {\n const ids = coerceArray(idsOrFn);\n this.entities = this.entities.filter(entity => {\n return ids.indexOf(entity[this.idKey]) === -1;\n });\n }\n return this.entities;\n }\n\n /**\n *\n * Move one or more entities:\n *\n * @example\n * produce([users]).move(5, {afterId: 2});\n * produce([users]).move(5, {toIndex: 0});\n */\n move(id: Id, moveOptions?: EntityMoveOptions): TEntity[] {\n const fromIndex = this.entities.findIndex(item => item[this.idKey] === id);\n let toIndex = 0;\n const newEntities = [...this.entities];\n\n if (!id || fromIndex < 0) {\n return [...this.entities];\n }\n\n if (moveOptions) {\n if (!isUndefinedOrNull(moveOptions.afterId)) {\n toIndex = this.entities.findIndex(item => item[this.idKey] === moveOptions.afterId);\n } else if (moveOptions.toIndex) {\n toIndex = moveOptions.toIndex;\n }\n }\n toIndex = Math.max(0, Math.min(this.entities.length - 1, toIndex));\n if (toIndex === fromIndex) {\n return [...this.entities];\n } else {\n const target = this.entities[fromIndex];\n const delta = toIndex < fromIndex ? -1 : 1;\n\n for (let i = fromIndex; i !== toIndex; i += delta) {\n newEntities[i] = newEntities[i + delta];\n }\n newEntities[toIndex] = target;\n return [...newEntities];\n }\n }\n}\n\nexport function produce<TEntity>(entities: TEntity[], options?: ProducerOptions<TEntity>): Producer<TEntity>;\nexport function produce<TEntity>(entities: TEntity): ObjectProducer<TEntity>;\nexport function produce<TEntity>(entities: TEntity | TEntity[], options?: ProducerOptions<TEntity>) {\n if (isArray(entities)) {\n return new Producer<TEntity>(entities, options);\n } else {\n return new ObjectProducer<TEntity>(entities);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;MAgCa,cAAc,CAAA;AAGvB,IAAA,WAAA,CAAY,MAAe,EAAA;AACvB,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;KACxB;AAED,IAAA,GAAG,CAAuB,QAAe,EAAA;QACrC,OAAO,QAAQ,CAAC,KAAK,CAAC,G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,KAAK,OAAO,EAAE,CAAC,IAAI,KAAK,EAAE;gBAC/C,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;AAC3C,aAAA;AACD,YAAA,WAAW,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;AAC9B,YAAA,OAAO,CAAC,GAAG,WAAW,CAAC,CAAC;AAC3B,SAAA;KACJ;AACJ,CAAA;AAIe,SAAA,OAAO,CAAU,QAA6B,EAAE,OAAkC,EAAA;AAC9F,IAAA,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE;AACnB,QAAA,OAAO,IAAI,QAAQ,CAAU,QAAQ,EAAE,OAAO,CAAC,CAAC;AACnD,KAAA;AAAM,SAAA;AACH,QAAA,OAAO,IAAI,cAAc,CAAU,QAAQ,CAAC,CAAC;AAChD,KAAA;AACL;;AClLA;;AAEG;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { coerceElement } from '@angular/cdk/coercion';
|
|
1
2
|
import { TemplateRef, ElementRef } from '@angular/core';
|
|
2
3
|
|
|
3
4
|
function isUndefined(value) {
|
|
@@ -95,10 +96,22 @@ function isHTMLElement(value) {
|
|
|
95
96
|
function isElementRef(value) {
|
|
96
97
|
return value instanceof ElementRef;
|
|
97
98
|
}
|
|
99
|
+
function isFormElement(elementOrRef) {
|
|
100
|
+
const element = coerceElement(elementOrRef);
|
|
101
|
+
if (!(element instanceof HTMLElement)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
const name = element.nodeName.toLowerCase();
|
|
105
|
+
const type = (element.getAttribute('type') || '').toLowerCase();
|
|
106
|
+
return (name === 'select' ||
|
|
107
|
+
name === 'textarea' ||
|
|
108
|
+
(name === 'input' && type !== 'submit' && type !== 'reset' && type !== 'checkbox' && type !== 'radio' && type !== 'file') ||
|
|
109
|
+
element.isContentEditable);
|
|
110
|
+
}
|
|
98
111
|
|
|
99
112
|
/**
|
|
100
113
|
* Generated bundle index. Do not edit.
|
|
101
114
|
*/
|
|
102
115
|
|
|
103
|
-
export { isArray, isBoolean, isDate, isElementRef, isEmpty, isFunction, isHTMLElement, isNull, isNumber, isObject, isString, isTemplateRef, isUndefined, isUndefinedOrNull };
|
|
116
|
+
export { isArray, isBoolean, isDate, isElementRef, isEmpty, isFormElement, isFunction, isHTMLElement, isNull, isNumber, isObject, isString, isTemplateRef, isUndefined, isUndefinedOrNull };
|
|
104
117
|
//# sourceMappingURL=tethys-cdk-is.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tethys-cdk-is.mjs","sources":["../../../cdk/is/utils.ts","../../../cdk/is/tethys-cdk-is.ts"],"sourcesContent":["import { ElementRef, TemplateRef } from '@angular/core';\n\nexport function isUndefined(value: any): value is undefined {\n return value === undefined;\n}\n\nexport function isNull(value: any): value is null {\n return value === null;\n}\n\nexport function isUndefinedOrNull(value: any): value is undefined | null {\n return isUndefined(value) || isNull(value);\n}\n\nexport function isArray<T = any>(value: any): value is Array<T> {\n return value && baseGetTag(value) === '[object Array]';\n}\n\nexport function isEmpty(value?: any): boolean {\n if (isUndefinedOrNull(value)) {\n return true;\n }\n if (isArray(value)) {\n return !value.length;\n }\n const tag = baseGetTag(value);\n if (tag == '[object Map]' || tag == '[object Set]') {\n return !value.size;\n }\n for (const key in value) {\n if (Object.hasOwnProperty.call(value, key)) {\n return false;\n }\n }\n return true;\n}\n\nexport function isString(value?: any): value is string {\n return typeof value == 'string' || (!isArray(value) && isObjectLike(value) && baseGetTag(value) === '[object String]');\n}\n\nfunction isObjectLike(value: any): value is object {\n return value !== null && typeof value === 'object';\n}\n\nfunction baseGetTag(value: any) {\n const objectProto = Object.prototype;\n const hasOwnProperty = objectProto.hasOwnProperty;\n const toString = objectProto.toString;\n const symToStringTag = typeof Symbol !== 'undefined' ? Symbol.toStringTag : undefined;\n\n if (value == null) {\n return value === undefined ? '[object Undefined]' : '[object Null]';\n }\n if (!(symToStringTag && symToStringTag in Object(value))) {\n return toString.call(value);\n }\n const isOwn = hasOwnProperty.call(value, symToStringTag);\n const tag = value[symToStringTag];\n let unmasked = false;\n try {\n value[symToStringTag] = undefined;\n unmasked = true;\n } catch (e) {}\n\n const result = toString.call(value);\n if (unmasked) {\n if (isOwn) {\n value[symToStringTag] = tag;\n } else {\n delete value[symToStringTag];\n }\n }\n return result;\n}\n\nexport function isNumber(value: any): value is number {\n return typeof value === 'number' || (isObjectLike(value) && baseGetTag(value) === '[object Number]');\n}\n\nexport function isObject(value: any): value is object {\n // Avoid a V8 JIT bug in Chrome 19-20.\n // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.\n const type = typeof value;\n return !!value && (type === 'object' || type === 'function');\n}\n\nexport function isFunction(value: any): value is Function {\n const type = typeof value;\n return !!value && type === 'function';\n}\n\nexport function isDate(value: any): value is Date {\n const type = typeof value;\n return !!value && type === 'object' && !!value.getTime;\n}\n\nexport function isBoolean(value: any): value is boolean {\n return value === true || value === false || (isObjectLike(value) && baseGetTag(value) === '[object Boolean]');\n}\n\nexport function isTemplateRef<C = any>(value: any): value is TemplateRef<C> {\n return value instanceof TemplateRef;\n}\n\nexport function isHTMLElement(value: any): value is HTMLElement {\n return value instanceof HTMLElement;\n}\n\nexport function isElementRef(value: any): value is ElementRef {\n return value instanceof ElementRef;\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tethys-cdk-is.mjs","sources":["../../../cdk/is/utils.ts","../../../cdk/is/tethys-cdk-is.ts"],"sourcesContent":["import { coerceElement } from '@angular/cdk/coercion';\nimport { ElementRef, TemplateRef } from '@angular/core';\n\nexport function isUndefined(value: any): value is undefined {\n return value === undefined;\n}\n\nexport function isNull(value: any): value is null {\n return value === null;\n}\n\nexport function isUndefinedOrNull(value: any): value is undefined | null {\n return isUndefined(value) || isNull(value);\n}\n\nexport function isArray<T = any>(value: any): value is Array<T> {\n return value && baseGetTag(value) === '[object Array]';\n}\n\nexport function isEmpty(value?: any): boolean {\n if (isUndefinedOrNull(value)) {\n return true;\n }\n if (isArray(value)) {\n return !value.length;\n }\n const tag = baseGetTag(value);\n if (tag == '[object Map]' || tag == '[object Set]') {\n return !value.size;\n }\n for (const key in value) {\n if (Object.hasOwnProperty.call(value, key)) {\n return false;\n }\n }\n return true;\n}\n\nexport function isString(value?: any): value is string {\n return typeof value == 'string' || (!isArray(value) && isObjectLike(value) && baseGetTag(value) === '[object String]');\n}\n\nfunction isObjectLike(value: any): value is object {\n return value !== null && typeof value === 'object';\n}\n\nfunction baseGetTag(value: any) {\n const objectProto = Object.prototype;\n const hasOwnProperty = objectProto.hasOwnProperty;\n const toString = objectProto.toString;\n const symToStringTag = typeof Symbol !== 'undefined' ? Symbol.toStringTag : undefined;\n\n if (value == null) {\n return value === undefined ? '[object Undefined]' : '[object Null]';\n }\n if (!(symToStringTag && symToStringTag in Object(value))) {\n return toString.call(value);\n }\n const isOwn = hasOwnProperty.call(value, symToStringTag);\n const tag = value[symToStringTag];\n let unmasked = false;\n try {\n value[symToStringTag] = undefined;\n unmasked = true;\n } catch (e) {}\n\n const result = toString.call(value);\n if (unmasked) {\n if (isOwn) {\n value[symToStringTag] = tag;\n } else {\n delete value[symToStringTag];\n }\n }\n return result;\n}\n\nexport function isNumber(value: any): value is number {\n return typeof value === 'number' || (isObjectLike(value) && baseGetTag(value) === '[object Number]');\n}\n\nexport function isObject(value: any): value is object {\n // Avoid a V8 JIT bug in Chrome 19-20.\n // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.\n const type = typeof value;\n return !!value && (type === 'object' || type === 'function');\n}\n\nexport function isFunction(value: any): value is Function {\n const type = typeof value;\n return !!value && type === 'function';\n}\n\nexport function isDate(value: any): value is Date {\n const type = typeof value;\n return !!value && type === 'object' && !!value.getTime;\n}\n\nexport function isBoolean(value: any): value is boolean {\n return value === true || value === false || (isObjectLike(value) && baseGetTag(value) === '[object Boolean]');\n}\n\nexport function isTemplateRef<C = any>(value: any): value is TemplateRef<C> {\n return value instanceof TemplateRef;\n}\n\nexport function isHTMLElement(value: any): value is HTMLElement {\n return value instanceof HTMLElement;\n}\n\nexport function isElementRef(value: any): value is ElementRef {\n return value instanceof ElementRef;\n}\n\nexport function isFormElement<T = Element>(elementOrRef: ElementRef<T> | T): boolean {\n const element = coerceElement(elementOrRef);\n if (!(element instanceof HTMLElement)) {\n return false;\n }\n const name = element.nodeName.toLowerCase();\n const type = (element.getAttribute('type') || '').toLowerCase();\n return (\n name === 'select' ||\n name === 'textarea' ||\n (name === 'input' && type !== 'submit' && type !== 'reset' && type !== 'checkbox' && type !== 'radio' && type !== 'file') ||\n element.isContentEditable\n );\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAGM,SAAU,WAAW,CAAC,KAAU,EAAA;IAClC,OAAO,KAAK,KAAK,SAAS,CAAC;AAC/B,CAAC;AAEK,SAAU,MAAM,CAAC,KAAU,EAAA;IAC7B,OAAO,KAAK,KAAK,IAAI,CAAC;AAC1B,CAAC;AAEK,SAAU,iBAAiB,CAAC,KAAU,EAAA;IACxC,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/C,CAAC;AAEK,SAAU,OAAO,CAAU,KAAU,EAAA;IACvC,OAAO,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,gBAAgB,CAAC;AAC3D,CAAC;AAEK,SAAU,OAAO,CAAC,KAAW,EAAA;AAC/B,IAAA,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE;AAC1B,QAAA,OAAO,IAAI,CAAC;AACf,KAAA;AACD,IAAA,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;AAChB,QAAA,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;AACxB,KAAA;AACD,IAAA,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;AAC9B,IAAA,IAAI,GAAG,IA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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tethys-cdk.mjs","sources":["../../../cdk/public-api.ts","../../../cdk/tethys-cdk.ts"],"sourcesContent":["/*\n * Public API Surface of cdk\n */\n\nexport * from '@tethys/cdk/is';\nexport * from '@tethys/cdk/logger';\nexport * from '@tethys/cdk/immutable';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tethys-cdk.mjs","sources":["../../../cdk/public-api.ts","../../../cdk/tethys-cdk.ts"],"sourcesContent":["/*\n * Public API Surface of cdk\n */\n\nexport * from '@tethys/cdk/is';\nexport * from '@tethys/cdk/logger';\nexport * from '@tethys/cdk/immutable';\nexport * from '@tethys/cdk/event';\nexport * from '@tethys/cdk/hotkey';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAAA;;AAEG;;ACFH;;AAEG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NgZone, ElementRef } from '@angular/core';
|
|
2
|
+
import { ThyEventDispatcher } from '@tethys/cdk/event';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export declare class ThyHotkeyDispatcher extends ThyEventDispatcher {
|
|
6
|
+
private keydownSubscriber;
|
|
7
|
+
constructor(document: any, ngZone: NgZone);
|
|
8
|
+
private createKeydownObservable;
|
|
9
|
+
/**
|
|
10
|
+
* 热键事件订阅
|
|
11
|
+
*/
|
|
12
|
+
keydown(hotkey: string | string[], scope?: ElementRef<Element> | Element | Document): Observable<KeyboardEvent>;
|
|
13
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ThyHotkeyDispatcher, never>;
|
|
14
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ThyHotkeyDispatcher>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ElementRef, EventEmitter, OnInit, OnDestroy } from '@angular/core';
|
|
2
|
+
import { ThyHotkeyDispatcher } from './hotkey-dispatcher';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* @name thyHotkey
|
|
6
|
+
*/
|
|
7
|
+
export declare class ThyHotkeyDirective implements OnInit, OnDestroy {
|
|
8
|
+
private document;
|
|
9
|
+
private hotkeyDispatcher;
|
|
10
|
+
private elementRef;
|
|
11
|
+
/**
|
|
12
|
+
* 热键对应 Code,多个热键组合支持通过数组或逗号分割的形式传入
|
|
13
|
+
*/
|
|
14
|
+
thyHotkey: string | string[];
|
|
15
|
+
/**
|
|
16
|
+
* 配置热键触发范围,默认绑定在 document 上
|
|
17
|
+
*/
|
|
18
|
+
thyHotkeyScope?: string | Element | ElementRef<Element>;
|
|
19
|
+
/**
|
|
20
|
+
* 热键触发后的事件
|
|
21
|
+
*/
|
|
22
|
+
thyHotkeyListener: EventEmitter<KeyboardEvent>;
|
|
23
|
+
private subscription;
|
|
24
|
+
constructor(document: Document, hotkeyDispatcher: ThyHotkeyDispatcher, elementRef: ElementRef<HTMLElement>);
|
|
25
|
+
ngOnInit(): void;
|
|
26
|
+
ngOnDestroy(): void;
|
|
27
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ThyHotkeyDirective, never>;
|
|
28
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<ThyHotkeyDirective, "[thyHotkey]", never, { "thyHotkey": "thyHotkey"; "thyHotkeyScope": "thyHotkeyScope"; }, { "thyHotkeyListener": "thyHotkeyListener"; }, never, never, false>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import * as i1 from "./hotkey.directive";
|
|
3
|
+
export declare class ThyHotkeyModule {
|
|
4
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ThyHotkeyModule, never>;
|
|
5
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<ThyHotkeyModule, [typeof i1.ThyHotkeyDirective], never, [typeof i1.ThyHotkeyDirective]>;
|
|
6
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<ThyHotkeyModule>;
|
|
7
|
+
}
|
package/immutable/immutable.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ObjectProducer } from './object-producer';
|
|
1
2
|
export declare type Id = string | number;
|
|
2
3
|
export interface EntityAddOptions {
|
|
3
4
|
prepend?: boolean;
|
|
@@ -71,4 +72,5 @@ export declare class Producer<TEntity> {
|
|
|
71
72
|
move(id: Id, moveOptions?: EntityMoveOptions): TEntity[];
|
|
72
73
|
}
|
|
73
74
|
export declare function produce<TEntity>(entities: TEntity[], options?: ProducerOptions<TEntity>): Producer<TEntity>;
|
|
75
|
+
export declare function produce<TEntity>(entities: TEntity): ObjectProducer<TEntity>;
|
|
74
76
|
export {};
|
package/immutable/index.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare type GetIndexedField<T, K> = K extends keyof T ? T[K] : K extends `${number}` ? '0' extends keyof T ? undefined : number extends keyof T ? T[number] : undefined : undefined;
|
|
2
|
+
declare type FieldWithPossiblyUndefined<T, Key> = GetFieldType<Exclude<T, undefined>, Key> | Extract<T, undefined>;
|
|
3
|
+
declare type IndexedFieldWithPossiblyUndefined<T, Key> = GetIndexedField<Exclude<T, undefined>, Key> | Extract<T, undefined>;
|
|
4
|
+
export declare type GetFieldType<T, P> = P extends `${infer Left}.${infer Right}` ? Left extends keyof T ? FieldWithPossiblyUndefined<T[Left], Right> : Left extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? FieldWithPossiblyUndefined<IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>, Right> : undefined : undefined : P extends keyof T ? T[P] : P extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey> : undefined : undefined;
|
|
5
|
+
export declare class ObjectProducer<TEntity> {
|
|
6
|
+
entity: TEntity;
|
|
7
|
+
constructor(entity: TEntity);
|
|
8
|
+
get<TPath extends string>(propPath: TPath): GetFieldType<TEntity, TPath>;
|
|
9
|
+
set<TPath extends string>(propPath: TPath, value: GetFieldType<TEntity, TPath>): TEntity;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
package/is/utils.d.ts
CHANGED
|
@@ -13,3 +13,4 @@ export declare function isBoolean(value: any): value is boolean;
|
|
|
13
13
|
export declare function isTemplateRef<C = any>(value: any): value is TemplateRef<C>;
|
|
14
14
|
export declare function isHTMLElement(value: any): value is HTMLElement;
|
|
15
15
|
export declare function isElementRef(value: any): value is ElementRef;
|
|
16
|
+
export declare function isFormElement<T = Element>(elementOrRef: ElementRef<T> | T): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tethys/cdk",
|
|
3
|
-
"version": "14.2.0
|
|
3
|
+
"version": "14.2.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^14.0.0",
|
|
6
6
|
"@angular/core": "^14.0.0",
|
|
@@ -35,6 +35,22 @@
|
|
|
35
35
|
"node": "./fesm2015/tethys-cdk-dom.mjs",
|
|
36
36
|
"default": "./fesm2020/tethys-cdk-dom.mjs"
|
|
37
37
|
},
|
|
38
|
+
"./event": {
|
|
39
|
+
"types": "./event/index.d.ts",
|
|
40
|
+
"esm2020": "./esm2020/event/tethys-cdk-event.mjs",
|
|
41
|
+
"es2020": "./fesm2020/tethys-cdk-event.mjs",
|
|
42
|
+
"es2015": "./fesm2015/tethys-cdk-event.mjs",
|
|
43
|
+
"node": "./fesm2015/tethys-cdk-event.mjs",
|
|
44
|
+
"default": "./fesm2020/tethys-cdk-event.mjs"
|
|
45
|
+
},
|
|
46
|
+
"./hotkey": {
|
|
47
|
+
"types": "./hotkey/index.d.ts",
|
|
48
|
+
"esm2020": "./esm2020/hotkey/tethys-cdk-hotkey.mjs",
|
|
49
|
+
"es2020": "./fesm2020/tethys-cdk-hotkey.mjs",
|
|
50
|
+
"es2015": "./fesm2015/tethys-cdk-hotkey.mjs",
|
|
51
|
+
"node": "./fesm2015/tethys-cdk-hotkey.mjs",
|
|
52
|
+
"default": "./fesm2020/tethys-cdk-hotkey.mjs"
|
|
53
|
+
},
|
|
38
54
|
"./immutable": {
|
|
39
55
|
"types": "./immutable/index.d.ts",
|
|
40
56
|
"esm2020": "./esm2020/immutable/tethys-cdk-immutable.mjs",
|