@tethys/cdk 19.1.0-next.5 → 19.1.0-next.7

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, NgZone, Injectable, ElementRef, EventEmitter, Output, Input, Directive, NgModule } from '@angular/core';
2
+ import { inject, NgZone, Injectable, ElementRef, input, output, Directive, NgModule } from '@angular/core';
3
3
  import { DOCUMENT } from '@angular/common';
4
4
  import { isString, isUndefinedOrNull, isFormElement } from '@tethys/cdk/is';
5
5
  import { coerceElement } from '@angular/cdk/coercion';
@@ -92,15 +92,24 @@ class ThyHotkeyDirective {
92
92
  this.document = inject(DOCUMENT);
93
93
  this.hotkeyDispatcher = inject(ThyHotkeyDispatcher);
94
94
  this.elementRef = inject(ElementRef);
95
+ /**
96
+ * 热键对应 Code,多个热键组合支持通过数组或逗号分割的形式传入
97
+ */
98
+ this.thyHotkey = input();
99
+ /**
100
+ * 配置热键触发范围,默认绑定在 document 上
101
+ */
102
+ this.thyHotkeyScope = input();
95
103
  /**
96
104
  * 热键触发后的事件
97
105
  */
98
- this.thyHotkeyListener = new EventEmitter();
106
+ this.thyHotkeyListener = output();
99
107
  this.subscription = null;
100
108
  }
101
109
  ngOnInit() {
102
- const scope = isString(this.thyHotkeyScope) ? this.document.querySelector(this.thyHotkeyScope) : this.thyHotkeyScope;
103
- this.subscription = this.hotkeyDispatcher.keydown(this.thyHotkey, scope).subscribe(event => {
110
+ const hotkeyScope = this.thyHotkeyScope();
111
+ const scope = isString(hotkeyScope) ? this.document.querySelector(hotkeyScope) : hotkeyScope;
112
+ this.subscription = this.hotkeyDispatcher.keydown(this.thyHotkey(), scope).subscribe(event => {
104
113
  event.preventDefault();
105
114
  event.stopPropagation();
106
115
  if (isFormElement(this.elementRef)) {
@@ -118,18 +127,12 @@ class ThyHotkeyDirective {
118
127
  }
119
128
  }
120
129
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: ThyHotkeyDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
121
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.8", type: ThyHotkeyDirective, isStandalone: true, selector: "[thyHotkey]", inputs: { thyHotkey: "thyHotkey", thyHotkeyScope: "thyHotkeyScope" }, outputs: { thyHotkeyListener: "thyHotkeyListener" }, ngImport: i0 }); }
130
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.8", type: ThyHotkeyDirective, isStandalone: true, selector: "[thyHotkey]", inputs: { thyHotkey: { classPropertyName: "thyHotkey", publicName: "thyHotkey", isSignal: true, isRequired: false, transformFunction: null }, thyHotkeyScope: { classPropertyName: "thyHotkeyScope", publicName: "thyHotkeyScope", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { thyHotkeyListener: "thyHotkeyListener" }, ngImport: i0 }); }
122
131
  }
123
132
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: ThyHotkeyDirective, decorators: [{
124
133
  type: Directive,
125
134
  args: [{ selector: '[thyHotkey]' }]
126
- }], propDecorators: { thyHotkey: [{
127
- type: Input
128
- }], thyHotkeyScope: [{
129
- type: Input
130
- }], thyHotkeyListener: [{
131
- type: Output
132
- }] } });
135
+ }] });
133
136
 
134
137
  class ThyHotkeyModule {
135
138
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.8", ngImport: i0, type: ThyHotkeyModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
@@ -1 +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 { Injectable, NgZone, ElementRef, inject } from '@angular/core';\nimport { ThyEventDispatcher } from '@tethys/cdk/event';\nimport { fromEvent, Observable, OperatorFunction, Subscriber } from 'rxjs';\nimport { filter } from 'rxjs/operators';\nimport { isFormElement, isString, isUndefinedOrNull } from '@tethys/cdk/is';\nimport { isHotkey } from './hotkey';\n\nfunction runInZone<T>(zone: NgZone): OperatorFunction<T, T> {\n return source => {\n return new Observable(observer => {\n const onNext = (value: T) => zone.run(() => observer.next(value));\n const onError = (e: any) => zone.run(() => observer.error(e));\n const onComplete = () => zone.run(() => observer.complete());\n return source.subscribe(onNext, onError, onComplete);\n });\n };\n}\n\n@Injectable({ providedIn: 'root' })\nexport class ThyHotkeyDispatcher extends ThyEventDispatcher {\n constructor() {\n const document = inject(DOCUMENT);\n const ngZone = inject(NgZone);\n\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 // 如果当前焦点的元素是表单元素并且焦点原色不是Hotkey绑定元素则忽略快捷键\n if (isFormElement(this.document.activeElement) && this.document.activeElement !== scope) {\n return;\n }\n subscriber.next(event);\n });\n return () => {\n subscription.unsubscribe();\n };\n }).pipe(runInZone(this.ngZone));\n }\n}\n","import { DOCUMENT } from '@angular/common';\nimport { Directive, ElementRef, EventEmitter, Input, OnInit, Output, OnDestroy, inject } 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 private document = inject(DOCUMENT);\n private hotkeyDispatcher = inject(ThyHotkeyDispatcher);\n private elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n\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 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 event.stopPropagation();\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: [ThyHotkeyDirective],\n exports: [ThyHotkeyDirective]\n})\nexport class ThyHotkeyModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,gBAAgB,GAAa,CAAC,CAAS,OAAA,CAAA,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;AAEtE;AACA,SAAS,SAAS,CAAC,KAAoB,EAAA;IACnC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK;AACrC,IAAA,OAAO,QAAQ,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC;AAC7E;AAEM,SAAU,MAAM,CAAC,KAAoB,EAAA;IACvC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK;IAC/C,MAAM,YAAY,GAAa,EAAE;AACjC,IAAA,MAAM,SAAS,GAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;AACzE,IAAA,KAAK,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE;AACxC,QAAA,IAAI,GAAG;YAAE,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;;IAGnD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AACjC,QAAA,YAAY,CAAC,IAAI,CAAC,GAAG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kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;kGAAlB,kBAAkB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,aAAA,EAAA,MAAA,EAAA,EAAA,SAAA,EAAA,WAAA,EAAA,cAAA,EAAA,gBAAA,EAAA,EAAA,OAAA,EAAA,EAAA,iBAAA,EAAA,mBAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA,CAAA;;2FAAlB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAD9B,SAAS;mBAAC,EAAE,QAAQ,EAAE,aAAa,EAAE;8BASzB,SAAS,EAAA,CAAA;sBAAjB;gBAKQ,cAAc,EAAA,CAAA;sBAAtB;gBAKS,iBAAiB,EAAA,CAAA;sBAA1B;;;MCrBQ,eAAe,CAAA;8GAAf,eAAe,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;+GAAf,eAAe,EAAA,OAAA,EAAA,CAHd,kBAAkB,CAAA,EAAA,OAAA,EAAA,CAClB,kBAAkB,CAAA,EAAA,CAAA,CAAA;+GAEnB,eAAe,EAAA,CAAA,CAAA;;2FAAf,eAAe,EAAA,UAAA,EAAA,CAAA;kBAJ3B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;oBACN,OAAO,EAAE,CAAC,kBAAkB,CAAC;oBAC7B,OAAO,EAAE,CAAC,kBAAkB;AAC/B,iBAAA;;;ACND;;AAEG;;;;"}
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 { Injectable, NgZone, ElementRef, inject } from '@angular/core';\nimport { ThyEventDispatcher } from '@tethys/cdk/event';\nimport { fromEvent, Observable, OperatorFunction, Subscriber } from 'rxjs';\nimport { filter } from 'rxjs/operators';\nimport { isFormElement, isString, isUndefinedOrNull } from '@tethys/cdk/is';\nimport { isHotkey } from './hotkey';\n\nfunction runInZone<T>(zone: NgZone): OperatorFunction<T, T> {\n return source => {\n return new Observable(observer => {\n const onNext = (value: T) => zone.run(() => observer.next(value));\n const onError = (e: any) => zone.run(() => observer.error(e));\n const onComplete = () => zone.run(() => observer.complete());\n return source.subscribe(onNext, onError, onComplete);\n });\n };\n}\n\n@Injectable({ providedIn: 'root' })\nexport class ThyHotkeyDispatcher extends ThyEventDispatcher {\n constructor() {\n const document = inject(DOCUMENT);\n const ngZone = inject(NgZone);\n\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 // 如果当前焦点的元素是表单元素并且焦点原色不是Hotkey绑定元素则忽略快捷键\n if (isFormElement(this.document.activeElement) && this.document.activeElement !== scope) {\n return;\n }\n subscriber.next(event);\n });\n return () => {\n subscription.unsubscribe();\n };\n }).pipe(runInZone(this.ngZone));\n }\n}\n","import { DOCUMENT } from '@angular/common';\nimport { Directive, ElementRef, OnInit, OnDestroy, inject, input, output } 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 private document = inject(DOCUMENT);\n private hotkeyDispatcher = inject(ThyHotkeyDispatcher);\n private elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n\n /**\n * 热键对应 Code,多个热键组合支持通过数组或逗号分割的形式传入\n */\n readonly thyHotkey = input<string | string[]>();\n\n /**\n * 配置热键触发范围,默认绑定在 document 上\n */\n readonly thyHotkeyScope = input<string | Element | ElementRef<Element>>();\n\n /**\n * 热键触发后的事件\n */\n readonly thyHotkeyListener = output<KeyboardEvent>();\n\n private subscription: Subscription = null;\n\n ngOnInit(): void {\n const hotkeyScope = this.thyHotkeyScope();\n const scope = isString(hotkeyScope) ? this.document.querySelector(hotkeyScope) : hotkeyScope;\n this.subscription = this.hotkeyDispatcher.keydown(this.thyHotkey(), scope).subscribe(event => {\n event.preventDefault();\n event.stopPropagation();\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: [ThyHotkeyDirective],\n exports: [ThyHotkeyDirective]\n})\nexport class ThyHotkeyModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,gBAAgB,GAAa,CAAC,CAAS,OAAA,CAAA,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;AAEtE;AACA,SAAS,SAAS,CAAC,KAAoB,EAAA;IACnC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK;AACrC,IAAA,OAAO,QAAQ,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC;AAC7E;AAEM,SAAU,MAAM,CAAC,KAAoB,EAAA;IACvC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK;IAC/C,MAAM,YAAY,GAAa,EAAE;AACjC,IAAA,MAAM,SAAS,GAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;AACzE,IAAA,KAAK,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE;AACxC,QAAA,IAAI,GAAG;YAAE,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;;IAGnD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AACjC,QAAA,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;;AAG1B,IAAA,OAAO,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;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itter, OnInit, OnDestroy } from '@angular/core';
1
+ import { ElementRef, OnInit, OnDestroy } from '@angular/core';
2
2
  import * as i0 from "@angular/core";
3
3
  /**
4
4
  * @name thyHotkey
@@ -10,18 +10,18 @@ export declare class ThyHotkeyDirective implements OnInit, OnDestroy {
10
10
  /**
11
11
  * 热键对应 Code,多个热键组合支持通过数组或逗号分割的形式传入
12
12
  */
13
- thyHotkey: string | string[];
13
+ readonly thyHotkey: import("@angular/core").InputSignal<string | string[]>;
14
14
  /**
15
15
  * 配置热键触发范围,默认绑定在 document 上
16
16
  */
17
- thyHotkeyScope?: string | Element | ElementRef<Element>;
17
+ readonly thyHotkeyScope: import("@angular/core").InputSignal<string | Element | ElementRef<Element>>;
18
18
  /**
19
19
  * 热键触发后的事件
20
20
  */
21
- thyHotkeyListener: EventEmitter<KeyboardEvent>;
21
+ readonly thyHotkeyListener: import("@angular/core").OutputEmitterRef<KeyboardEvent>;
22
22
  private subscription;
23
23
  ngOnInit(): void;
24
24
  ngOnDestroy(): void;
25
25
  static ɵfac: i0.ɵɵFactoryDeclaration<ThyHotkeyDirective, never>;
26
- static ɵdir: i0.ɵɵDirectiveDeclaration<ThyHotkeyDirective, "[thyHotkey]", never, { "thyHotkey": { "alias": "thyHotkey"; "required": false; }; "thyHotkeyScope": { "alias": "thyHotkeyScope"; "required": false; }; }, { "thyHotkeyListener": "thyHotkeyListener"; }, never, never, true, never>;
26
+ static ɵdir: i0.ɵɵDirectiveDeclaration<ThyHotkeyDirective, "[thyHotkey]", never, { "thyHotkey": { "alias": "thyHotkey"; "required": false; "isSignal": true; }; "thyHotkeyScope": { "alias": "thyHotkeyScope"; "required": false; "isSignal": true; }; }, { "thyHotkeyListener": "thyHotkeyListener"; }, never, never, true, never>;
27
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tethys/cdk",
3
- "version": "19.1.0-next.5",
3
+ "version": "19.1.0-next.7",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^19.0.0",
6
6
  "@angular/core": "^19.0.0",