@knotx/decorators 0.2.4 → 0.2.5

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/index.d.cts CHANGED
@@ -1,14 +1,18 @@
1
- import { RenderType, IPlugin, EdgeOperatorFunction, EdgeOperationPipe, EdgeRenderType, Engine, PluginData, Layer, VerticalAlignment, HorizontalAlignment, Container, NodeOperatorFunction, NodeOperationPipe, NodeRenderType } from '@knotx/core';
1
+ import { BasePlugin, RenderType, IPlugin, EdgeOperatorFunction, EdgeOperationPipe, EdgeRenderType, Engine, PluginData, Layer, VerticalAlignment, HorizontalAlignment, Container, NodeOperatorFunction, NodeOperationPipe, NodeRenderType } from '@knotx/core';
2
2
 
3
3
  interface IInternalPlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> extends IPlugin<TPluginName, any, TRenderType> {
4
4
  }
5
+ type CMDC<TK extends string, TM extends (...args: any[]) => any, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassMethodDecoratorContext<{
6
+ [key in TK]: TM;
7
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TM> & {
8
+ name: TK;
9
+ };
10
+ type CFDC<TK extends string, TV, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassFieldDecoratorContext<{
11
+ [key in TK]: TV;
12
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TV> & {
13
+ name: TK;
14
+ };
5
15
 
6
- declare const edgeOperatorSymbol: unique symbol;
7
- declare module '../internal' {
8
- interface IInternalPlugin {
9
- [edgeOperatorSymbol]?: Record<string | symbol, EdgeOperatorFunction>;
10
- }
11
- }
12
16
  /**
13
17
  * 边操作装饰器
14
18
  * 用于声明一个方法作为边操作函数
@@ -30,14 +34,8 @@ declare module '../internal' {
30
34
  * }
31
35
  * ```
32
36
  */
33
- declare function edgeOperator(): <TRenderType extends RenderType, Args extends any[]>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeOperatorFunction<any, Args>>) => void;
37
+ declare function edgeOperator<K extends string, V extends EdgeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
34
38
 
35
- declare const edgePipeSymbol: unique symbol;
36
- declare module '../internal' {
37
- interface IInternalPlugin {
38
- [edgePipeSymbol]?: Record<string | symbol, EdgeOperationPipe<any>>;
39
- }
40
- }
41
39
  /**
42
40
  * 边操作管道装饰器
43
41
  * 用于声明一个方法作为边操作管道,在边操作执行前后进行处理
@@ -62,15 +60,23 @@ declare module '../internal' {
62
60
  * }
63
61
  * ```
64
62
  */
65
- declare function edgePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => EdgeOperationPipe<T>>) => void;
63
+ declare function edgePipe<K extends string>(): <T, V extends (...args: any[]) => EdgeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
66
64
 
67
- declare const edgeRendererSymbol: unique symbol;
68
- declare module '../internal' {
69
- interface IInternalPlugin {
70
- [edgeRendererSymbol]?: Record<string, EdgeRenderType>;
71
- }
72
- }
73
- declare function edgeType(type: string): <TRenderType extends RenderType>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeRenderType> | ClassFieldDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeRenderType>) => void;
65
+ /**
66
+ * 连线渲染器装饰器
67
+ * 用于声明一个方法作为连线渲染器
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * class MyPlugin extends BasePlugin {
72
+ * @edgeType('my-edge')
73
+ * renderEdge() {
74
+ * return <div>My Edge</div>
75
+ * }
76
+ * }
77
+ * ```
78
+ */
79
+ declare function edgeType<K extends string, T extends string, V extends EdgeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
74
80
 
75
81
  type InjectableDataKey = keyof {
76
82
  [K in keyof Engine as Engine[K] extends (...args: any[]) => any ? never : K]: Engine[K];
@@ -235,20 +241,14 @@ declare const inject: InjectDecorator;
235
241
  * @returns 类字段或 getter 装饰器函数
236
242
  * @example
237
243
  * ```
238
- * // 注册普通字段
244
+ * // 注册字段
239
245
  * @register('canUndo')
240
246
  * canUndo = false
241
- *
242
- * // 注册计算属性
243
- * @register('ref')
244
- * get ref() {
245
- * return this
246
- * }
247
247
  * ```
248
248
  */
249
- declare function register<T extends keyof PluginData, TP extends keyof PluginData[T]>(property: TP): <TRenderType extends RenderType>(_: any, context: ClassFieldDecoratorContext<IInternalPlugin<T, TRenderType>, PluginData[T][TP]> | ClassGetterDecoratorContext<IInternalPlugin<T, TRenderType>, PluginData[T][TP]>) => void;
249
+ declare function register<K extends string, TN extends keyof PluginData, TP extends keyof PluginData[TN]>(property: TP): (_: any, context: CFDC<K, PluginData[TN][TP], TN>) => void;
250
250
 
251
- declare function layer<This extends IPlugin>(layer: Layer, offset?: number): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
251
+ declare function layer<K extends string>(layer: Layer, offset?: number): (_: any, context: CMDC<K, () => void>) => void;
252
252
 
253
253
  /**
254
254
  * 面板位置
@@ -283,14 +283,8 @@ declare function createPanelWrapper(position: PanelPosition, offset?: PanelOffse
283
283
  * @param position 面板位置
284
284
  * @param offset 面板偏移
285
285
  */
286
- declare function panel<This extends IPlugin>(position: PanelPosition, offset?: PanelOffset): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
286
+ declare function panel<K extends string>(position: PanelPosition, offset?: PanelOffset): (_: any, context: CMDC<K, () => any>) => void;
287
287
 
288
- declare const nodeOperatorSymbol: unique symbol;
289
- declare module '../internal' {
290
- interface IInternalPlugin {
291
- [nodeOperatorSymbol]?: Record<string | symbol, NodeOperatorFunction>;
292
- }
293
- }
294
288
  /**
295
289
  * 节点操作装饰器
296
290
  * 用于声明一个方法作为节点操作函数
@@ -312,14 +306,8 @@ declare module '../internal' {
312
306
  * }
313
307
  * ```
314
308
  */
315
- declare function nodeOperator(): <TRenderType extends RenderType, Args extends any[]>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, NodeOperatorFunction<any, Args>>) => void;
309
+ declare function nodeOperator<K extends string, V extends NodeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
316
310
 
317
- declare const nodePipeSymbol: unique symbol;
318
- declare module '../internal' {
319
- interface IInternalPlugin {
320
- [nodePipeSymbol]?: Record<string | symbol, NodeOperationPipe<any>>;
321
- }
322
- }
323
311
  /**
324
312
  * 节点操作管道装饰器
325
313
  * 用于声明一个方法作为节点操作管道,在节点操作执行前后进行处理
@@ -344,32 +332,46 @@ declare module '../internal' {
344
332
  * }
345
333
  * ```
346
334
  */
347
- declare function nodePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => NodeOperationPipe<T>>) => void;
335
+ declare function nodePipe<K extends string>(): <T, V extends (...args: any[]) => NodeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
348
336
 
349
- declare const nodeRendererSymbol: unique symbol;
350
- declare module '../internal' {
351
- interface IInternalPlugin {
352
- [nodeRendererSymbol]?: Record<string, NodeRenderType>;
353
- }
354
- }
355
- declare function nodeType(type: string): <TRenderType extends RenderType>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, NodeRenderType> | ClassFieldDecoratorContext<IInternalPlugin<string, TRenderType>, NodeRenderType>) => void;
337
+ /**
338
+ * 节点类型装饰器
339
+ * 用于声明一个方法作为节点类型
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * class MyPlugin extends BasePlugin {
344
+ * @nodeType('my-node')
345
+ * renderNode() {
346
+ * return <div>My Node</div>
347
+ * }
348
+ * }
349
+ * ```
350
+ */
351
+ declare function nodeType<K extends string, T extends string, V extends NodeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
352
+
353
+ /**
354
+ * 配置装饰器
355
+ * 自动绑定 OnInit 和 OnConfigChange 生命周期函数 和 observable 装饰器
356
+ */
357
+ declare function config<K extends string, V extends Record<string, any>>(): (_: any, context: CFDC<K, V, string, V>) => void;
356
358
 
357
359
  /**
358
360
  * 生命周期装饰器
359
361
  * 在插件初始化时调用
360
362
  */
361
- declare function OnInit<TPluginConfig extends Record<string, any> | undefined, This extends IPlugin<string, TPluginConfig>>(originalMethod: (this: This, config: TPluginConfig) => void, context: ClassMethodDecoratorContext<This>): void;
363
+ declare function OnInit<K extends string, TPluginConfig extends Record<string, any> | undefined>(_: any, context: CMDC<K, (config: TPluginConfig) => void, string, TPluginConfig> | CFDC<K, (config: TPluginConfig) => void, string, TPluginConfig>): void;
362
364
  /**
363
365
  * 销毁装饰器
364
366
  * 在插件销毁时调用
365
367
  */
366
- declare function OnDestroy<This extends IPlugin>(originalMethod: (this: This) => void, context: ClassMethodDecoratorContext<This>): void;
368
+ declare function OnDestroy<K extends string>(_: any, context: CMDC<K, () => void> | CFDC<K, () => void>): void;
367
369
  /**
368
370
  * 配置变更装饰器
369
371
  * 在插件配置变更时调用
370
372
  */
371
- declare function OnConfigChange<TPluginConfig extends Record<string, any> | undefined, This extends IPlugin<string, TPluginConfig>>(originalMethod: (this: This, config: TPluginConfig) => void, context: ClassMethodDecoratorContext<This>): void;
373
+ declare function OnConfigChange<K extends string, TPluginConfig extends Record<string, any> | undefined>(_: any, context: CMDC<K, (config: TPluginConfig) => void, string, TPluginConfig> | CFDC<K, (config: TPluginConfig) => void, string, TPluginConfig>): void;
372
374
 
373
- declare function observable<T>(): (_: any, context: ClassFieldDecoratorContext<IPlugin, T>) => void;
375
+ declare function observable<K extends string, T>(): (_: any, context: CFDC<K, T>) => void;
374
376
 
375
- export { type InjectDecorator, type InjectDecoratorCallableDataType, type InjectDecoratorCallableMethodType, type InjectDecoratorCallablePluginDataType, type InjectDecoratorInjectableDataType, type InjectDecoratorInjectableMethodType, type InjectDecoratorInjectablePluginDataType, type InjectDecoratorInjectableType, type InjectWithContext, type Injectable, type InjectableDataKey, type InjectableMethodKey, OnConfigChange, OnDestroy, OnInit, type PanelOffset, type PanelPosition, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register };
377
+ export { type InjectDecorator, type InjectDecoratorCallableDataType, type InjectDecoratorCallableMethodType, type InjectDecoratorCallablePluginDataType, type InjectDecoratorInjectableDataType, type InjectDecoratorInjectableMethodType, type InjectDecoratorInjectablePluginDataType, type InjectDecoratorInjectableType, type InjectWithContext, type Injectable, type InjectableDataKey, type InjectableMethodKey, OnConfigChange, OnDestroy, OnInit, type PanelOffset, type PanelPosition, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register };
package/dist/index.d.mts CHANGED
@@ -1,14 +1,18 @@
1
- import { RenderType, IPlugin, EdgeOperatorFunction, EdgeOperationPipe, EdgeRenderType, Engine, PluginData, Layer, VerticalAlignment, HorizontalAlignment, Container, NodeOperatorFunction, NodeOperationPipe, NodeRenderType } from '@knotx/core';
1
+ import { BasePlugin, RenderType, IPlugin, EdgeOperatorFunction, EdgeOperationPipe, EdgeRenderType, Engine, PluginData, Layer, VerticalAlignment, HorizontalAlignment, Container, NodeOperatorFunction, NodeOperationPipe, NodeRenderType } from '@knotx/core';
2
2
 
3
3
  interface IInternalPlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> extends IPlugin<TPluginName, any, TRenderType> {
4
4
  }
5
+ type CMDC<TK extends string, TM extends (...args: any[]) => any, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassMethodDecoratorContext<{
6
+ [key in TK]: TM;
7
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TM> & {
8
+ name: TK;
9
+ };
10
+ type CFDC<TK extends string, TV, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassFieldDecoratorContext<{
11
+ [key in TK]: TV;
12
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TV> & {
13
+ name: TK;
14
+ };
5
15
 
6
- declare const edgeOperatorSymbol: unique symbol;
7
- declare module '../internal' {
8
- interface IInternalPlugin {
9
- [edgeOperatorSymbol]?: Record<string | symbol, EdgeOperatorFunction>;
10
- }
11
- }
12
16
  /**
13
17
  * 边操作装饰器
14
18
  * 用于声明一个方法作为边操作函数
@@ -30,14 +34,8 @@ declare module '../internal' {
30
34
  * }
31
35
  * ```
32
36
  */
33
- declare function edgeOperator(): <TRenderType extends RenderType, Args extends any[]>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeOperatorFunction<any, Args>>) => void;
37
+ declare function edgeOperator<K extends string, V extends EdgeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
34
38
 
35
- declare const edgePipeSymbol: unique symbol;
36
- declare module '../internal' {
37
- interface IInternalPlugin {
38
- [edgePipeSymbol]?: Record<string | symbol, EdgeOperationPipe<any>>;
39
- }
40
- }
41
39
  /**
42
40
  * 边操作管道装饰器
43
41
  * 用于声明一个方法作为边操作管道,在边操作执行前后进行处理
@@ -62,15 +60,23 @@ declare module '../internal' {
62
60
  * }
63
61
  * ```
64
62
  */
65
- declare function edgePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => EdgeOperationPipe<T>>) => void;
63
+ declare function edgePipe<K extends string>(): <T, V extends (...args: any[]) => EdgeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
66
64
 
67
- declare const edgeRendererSymbol: unique symbol;
68
- declare module '../internal' {
69
- interface IInternalPlugin {
70
- [edgeRendererSymbol]?: Record<string, EdgeRenderType>;
71
- }
72
- }
73
- declare function edgeType(type: string): <TRenderType extends RenderType>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeRenderType> | ClassFieldDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeRenderType>) => void;
65
+ /**
66
+ * 连线渲染器装饰器
67
+ * 用于声明一个方法作为连线渲染器
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * class MyPlugin extends BasePlugin {
72
+ * @edgeType('my-edge')
73
+ * renderEdge() {
74
+ * return <div>My Edge</div>
75
+ * }
76
+ * }
77
+ * ```
78
+ */
79
+ declare function edgeType<K extends string, T extends string, V extends EdgeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
74
80
 
75
81
  type InjectableDataKey = keyof {
76
82
  [K in keyof Engine as Engine[K] extends (...args: any[]) => any ? never : K]: Engine[K];
@@ -235,20 +241,14 @@ declare const inject: InjectDecorator;
235
241
  * @returns 类字段或 getter 装饰器函数
236
242
  * @example
237
243
  * ```
238
- * // 注册普通字段
244
+ * // 注册字段
239
245
  * @register('canUndo')
240
246
  * canUndo = false
241
- *
242
- * // 注册计算属性
243
- * @register('ref')
244
- * get ref() {
245
- * return this
246
- * }
247
247
  * ```
248
248
  */
249
- declare function register<T extends keyof PluginData, TP extends keyof PluginData[T]>(property: TP): <TRenderType extends RenderType>(_: any, context: ClassFieldDecoratorContext<IInternalPlugin<T, TRenderType>, PluginData[T][TP]> | ClassGetterDecoratorContext<IInternalPlugin<T, TRenderType>, PluginData[T][TP]>) => void;
249
+ declare function register<K extends string, TN extends keyof PluginData, TP extends keyof PluginData[TN]>(property: TP): (_: any, context: CFDC<K, PluginData[TN][TP], TN>) => void;
250
250
 
251
- declare function layer<This extends IPlugin>(layer: Layer, offset?: number): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
251
+ declare function layer<K extends string>(layer: Layer, offset?: number): (_: any, context: CMDC<K, () => void>) => void;
252
252
 
253
253
  /**
254
254
  * 面板位置
@@ -283,14 +283,8 @@ declare function createPanelWrapper(position: PanelPosition, offset?: PanelOffse
283
283
  * @param position 面板位置
284
284
  * @param offset 面板偏移
285
285
  */
286
- declare function panel<This extends IPlugin>(position: PanelPosition, offset?: PanelOffset): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
286
+ declare function panel<K extends string>(position: PanelPosition, offset?: PanelOffset): (_: any, context: CMDC<K, () => any>) => void;
287
287
 
288
- declare const nodeOperatorSymbol: unique symbol;
289
- declare module '../internal' {
290
- interface IInternalPlugin {
291
- [nodeOperatorSymbol]?: Record<string | symbol, NodeOperatorFunction>;
292
- }
293
- }
294
288
  /**
295
289
  * 节点操作装饰器
296
290
  * 用于声明一个方法作为节点操作函数
@@ -312,14 +306,8 @@ declare module '../internal' {
312
306
  * }
313
307
  * ```
314
308
  */
315
- declare function nodeOperator(): <TRenderType extends RenderType, Args extends any[]>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, NodeOperatorFunction<any, Args>>) => void;
309
+ declare function nodeOperator<K extends string, V extends NodeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
316
310
 
317
- declare const nodePipeSymbol: unique symbol;
318
- declare module '../internal' {
319
- interface IInternalPlugin {
320
- [nodePipeSymbol]?: Record<string | symbol, NodeOperationPipe<any>>;
321
- }
322
- }
323
311
  /**
324
312
  * 节点操作管道装饰器
325
313
  * 用于声明一个方法作为节点操作管道,在节点操作执行前后进行处理
@@ -344,32 +332,46 @@ declare module '../internal' {
344
332
  * }
345
333
  * ```
346
334
  */
347
- declare function nodePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => NodeOperationPipe<T>>) => void;
335
+ declare function nodePipe<K extends string>(): <T, V extends (...args: any[]) => NodeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
348
336
 
349
- declare const nodeRendererSymbol: unique symbol;
350
- declare module '../internal' {
351
- interface IInternalPlugin {
352
- [nodeRendererSymbol]?: Record<string, NodeRenderType>;
353
- }
354
- }
355
- declare function nodeType(type: string): <TRenderType extends RenderType>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, NodeRenderType> | ClassFieldDecoratorContext<IInternalPlugin<string, TRenderType>, NodeRenderType>) => void;
337
+ /**
338
+ * 节点类型装饰器
339
+ * 用于声明一个方法作为节点类型
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * class MyPlugin extends BasePlugin {
344
+ * @nodeType('my-node')
345
+ * renderNode() {
346
+ * return <div>My Node</div>
347
+ * }
348
+ * }
349
+ * ```
350
+ */
351
+ declare function nodeType<K extends string, T extends string, V extends NodeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
352
+
353
+ /**
354
+ * 配置装饰器
355
+ * 自动绑定 OnInit 和 OnConfigChange 生命周期函数 和 observable 装饰器
356
+ */
357
+ declare function config<K extends string, V extends Record<string, any>>(): (_: any, context: CFDC<K, V, string, V>) => void;
356
358
 
357
359
  /**
358
360
  * 生命周期装饰器
359
361
  * 在插件初始化时调用
360
362
  */
361
- declare function OnInit<TPluginConfig extends Record<string, any> | undefined, This extends IPlugin<string, TPluginConfig>>(originalMethod: (this: This, config: TPluginConfig) => void, context: ClassMethodDecoratorContext<This>): void;
363
+ declare function OnInit<K extends string, TPluginConfig extends Record<string, any> | undefined>(_: any, context: CMDC<K, (config: TPluginConfig) => void, string, TPluginConfig> | CFDC<K, (config: TPluginConfig) => void, string, TPluginConfig>): void;
362
364
  /**
363
365
  * 销毁装饰器
364
366
  * 在插件销毁时调用
365
367
  */
366
- declare function OnDestroy<This extends IPlugin>(originalMethod: (this: This) => void, context: ClassMethodDecoratorContext<This>): void;
368
+ declare function OnDestroy<K extends string>(_: any, context: CMDC<K, () => void> | CFDC<K, () => void>): void;
367
369
  /**
368
370
  * 配置变更装饰器
369
371
  * 在插件配置变更时调用
370
372
  */
371
- declare function OnConfigChange<TPluginConfig extends Record<string, any> | undefined, This extends IPlugin<string, TPluginConfig>>(originalMethod: (this: This, config: TPluginConfig) => void, context: ClassMethodDecoratorContext<This>): void;
373
+ declare function OnConfigChange<K extends string, TPluginConfig extends Record<string, any> | undefined>(_: any, context: CMDC<K, (config: TPluginConfig) => void, string, TPluginConfig> | CFDC<K, (config: TPluginConfig) => void, string, TPluginConfig>): void;
372
374
 
373
- declare function observable<T>(): (_: any, context: ClassFieldDecoratorContext<IPlugin, T>) => void;
375
+ declare function observable<K extends string, T>(): (_: any, context: CFDC<K, T>) => void;
374
376
 
375
- export { type InjectDecorator, type InjectDecoratorCallableDataType, type InjectDecoratorCallableMethodType, type InjectDecoratorCallablePluginDataType, type InjectDecoratorInjectableDataType, type InjectDecoratorInjectableMethodType, type InjectDecoratorInjectablePluginDataType, type InjectDecoratorInjectableType, type InjectWithContext, type Injectable, type InjectableDataKey, type InjectableMethodKey, OnConfigChange, OnDestroy, OnInit, type PanelOffset, type PanelPosition, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register };
377
+ export { type InjectDecorator, type InjectDecoratorCallableDataType, type InjectDecoratorCallableMethodType, type InjectDecoratorCallablePluginDataType, type InjectDecoratorInjectableDataType, type InjectDecoratorInjectableMethodType, type InjectDecoratorInjectablePluginDataType, type InjectDecoratorInjectableType, type InjectWithContext, type Injectable, type InjectableDataKey, type InjectableMethodKey, OnConfigChange, OnDestroy, OnInit, type PanelOffset, type PanelPosition, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,18 @@
1
- import { RenderType, IPlugin, EdgeOperatorFunction, EdgeOperationPipe, EdgeRenderType, Engine, PluginData, Layer, VerticalAlignment, HorizontalAlignment, Container, NodeOperatorFunction, NodeOperationPipe, NodeRenderType } from '@knotx/core';
1
+ import { BasePlugin, RenderType, IPlugin, EdgeOperatorFunction, EdgeOperationPipe, EdgeRenderType, Engine, PluginData, Layer, VerticalAlignment, HorizontalAlignment, Container, NodeOperatorFunction, NodeOperationPipe, NodeRenderType } from '@knotx/core';
2
2
 
3
3
  interface IInternalPlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> extends IPlugin<TPluginName, any, TRenderType> {
4
4
  }
5
+ type CMDC<TK extends string, TM extends (...args: any[]) => any, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassMethodDecoratorContext<{
6
+ [key in TK]: TM;
7
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TM> & {
8
+ name: TK;
9
+ };
10
+ type CFDC<TK extends string, TV, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassFieldDecoratorContext<{
11
+ [key in TK]: TV;
12
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TV> & {
13
+ name: TK;
14
+ };
5
15
 
6
- declare const edgeOperatorSymbol: unique symbol;
7
- declare module '../internal' {
8
- interface IInternalPlugin {
9
- [edgeOperatorSymbol]?: Record<string | symbol, EdgeOperatorFunction>;
10
- }
11
- }
12
16
  /**
13
17
  * 边操作装饰器
14
18
  * 用于声明一个方法作为边操作函数
@@ -30,14 +34,8 @@ declare module '../internal' {
30
34
  * }
31
35
  * ```
32
36
  */
33
- declare function edgeOperator(): <TRenderType extends RenderType, Args extends any[]>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeOperatorFunction<any, Args>>) => void;
37
+ declare function edgeOperator<K extends string, V extends EdgeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
34
38
 
35
- declare const edgePipeSymbol: unique symbol;
36
- declare module '../internal' {
37
- interface IInternalPlugin {
38
- [edgePipeSymbol]?: Record<string | symbol, EdgeOperationPipe<any>>;
39
- }
40
- }
41
39
  /**
42
40
  * 边操作管道装饰器
43
41
  * 用于声明一个方法作为边操作管道,在边操作执行前后进行处理
@@ -62,15 +60,23 @@ declare module '../internal' {
62
60
  * }
63
61
  * ```
64
62
  */
65
- declare function edgePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => EdgeOperationPipe<T>>) => void;
63
+ declare function edgePipe<K extends string>(): <T, V extends (...args: any[]) => EdgeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
66
64
 
67
- declare const edgeRendererSymbol: unique symbol;
68
- declare module '../internal' {
69
- interface IInternalPlugin {
70
- [edgeRendererSymbol]?: Record<string, EdgeRenderType>;
71
- }
72
- }
73
- declare function edgeType(type: string): <TRenderType extends RenderType>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeRenderType> | ClassFieldDecoratorContext<IInternalPlugin<string, TRenderType>, EdgeRenderType>) => void;
65
+ /**
66
+ * 连线渲染器装饰器
67
+ * 用于声明一个方法作为连线渲染器
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * class MyPlugin extends BasePlugin {
72
+ * @edgeType('my-edge')
73
+ * renderEdge() {
74
+ * return <div>My Edge</div>
75
+ * }
76
+ * }
77
+ * ```
78
+ */
79
+ declare function edgeType<K extends string, T extends string, V extends EdgeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
74
80
 
75
81
  type InjectableDataKey = keyof {
76
82
  [K in keyof Engine as Engine[K] extends (...args: any[]) => any ? never : K]: Engine[K];
@@ -235,20 +241,14 @@ declare const inject: InjectDecorator;
235
241
  * @returns 类字段或 getter 装饰器函数
236
242
  * @example
237
243
  * ```
238
- * // 注册普通字段
244
+ * // 注册字段
239
245
  * @register('canUndo')
240
246
  * canUndo = false
241
- *
242
- * // 注册计算属性
243
- * @register('ref')
244
- * get ref() {
245
- * return this
246
- * }
247
247
  * ```
248
248
  */
249
- declare function register<T extends keyof PluginData, TP extends keyof PluginData[T]>(property: TP): <TRenderType extends RenderType>(_: any, context: ClassFieldDecoratorContext<IInternalPlugin<T, TRenderType>, PluginData[T][TP]> | ClassGetterDecoratorContext<IInternalPlugin<T, TRenderType>, PluginData[T][TP]>) => void;
249
+ declare function register<K extends string, TN extends keyof PluginData, TP extends keyof PluginData[TN]>(property: TP): (_: any, context: CFDC<K, PluginData[TN][TP], TN>) => void;
250
250
 
251
- declare function layer<This extends IPlugin>(layer: Layer, offset?: number): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
251
+ declare function layer<K extends string>(layer: Layer, offset?: number): (_: any, context: CMDC<K, () => void>) => void;
252
252
 
253
253
  /**
254
254
  * 面板位置
@@ -283,14 +283,8 @@ declare function createPanelWrapper(position: PanelPosition, offset?: PanelOffse
283
283
  * @param position 面板位置
284
284
  * @param offset 面板偏移
285
285
  */
286
- declare function panel<This extends IPlugin>(position: PanelPosition, offset?: PanelOffset): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
286
+ declare function panel<K extends string>(position: PanelPosition, offset?: PanelOffset): (_: any, context: CMDC<K, () => any>) => void;
287
287
 
288
- declare const nodeOperatorSymbol: unique symbol;
289
- declare module '../internal' {
290
- interface IInternalPlugin {
291
- [nodeOperatorSymbol]?: Record<string | symbol, NodeOperatorFunction>;
292
- }
293
- }
294
288
  /**
295
289
  * 节点操作装饰器
296
290
  * 用于声明一个方法作为节点操作函数
@@ -312,14 +306,8 @@ declare module '../internal' {
312
306
  * }
313
307
  * ```
314
308
  */
315
- declare function nodeOperator(): <TRenderType extends RenderType, Args extends any[]>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, NodeOperatorFunction<any, Args>>) => void;
309
+ declare function nodeOperator<K extends string, V extends NodeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
316
310
 
317
- declare const nodePipeSymbol: unique symbol;
318
- declare module '../internal' {
319
- interface IInternalPlugin {
320
- [nodePipeSymbol]?: Record<string | symbol, NodeOperationPipe<any>>;
321
- }
322
- }
323
311
  /**
324
312
  * 节点操作管道装饰器
325
313
  * 用于声明一个方法作为节点操作管道,在节点操作执行前后进行处理
@@ -344,32 +332,46 @@ declare module '../internal' {
344
332
  * }
345
333
  * ```
346
334
  */
347
- declare function nodePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => NodeOperationPipe<T>>) => void;
335
+ declare function nodePipe<K extends string>(): <T, V extends (...args: any[]) => NodeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
348
336
 
349
- declare const nodeRendererSymbol: unique symbol;
350
- declare module '../internal' {
351
- interface IInternalPlugin {
352
- [nodeRendererSymbol]?: Record<string, NodeRenderType>;
353
- }
354
- }
355
- declare function nodeType(type: string): <TRenderType extends RenderType>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, NodeRenderType> | ClassFieldDecoratorContext<IInternalPlugin<string, TRenderType>, NodeRenderType>) => void;
337
+ /**
338
+ * 节点类型装饰器
339
+ * 用于声明一个方法作为节点类型
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * class MyPlugin extends BasePlugin {
344
+ * @nodeType('my-node')
345
+ * renderNode() {
346
+ * return <div>My Node</div>
347
+ * }
348
+ * }
349
+ * ```
350
+ */
351
+ declare function nodeType<K extends string, T extends string, V extends NodeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
352
+
353
+ /**
354
+ * 配置装饰器
355
+ * 自动绑定 OnInit 和 OnConfigChange 生命周期函数 和 observable 装饰器
356
+ */
357
+ declare function config<K extends string, V extends Record<string, any>>(): (_: any, context: CFDC<K, V, string, V>) => void;
356
358
 
357
359
  /**
358
360
  * 生命周期装饰器
359
361
  * 在插件初始化时调用
360
362
  */
361
- declare function OnInit<TPluginConfig extends Record<string, any> | undefined, This extends IPlugin<string, TPluginConfig>>(originalMethod: (this: This, config: TPluginConfig) => void, context: ClassMethodDecoratorContext<This>): void;
363
+ declare function OnInit<K extends string, TPluginConfig extends Record<string, any> | undefined>(_: any, context: CMDC<K, (config: TPluginConfig) => void, string, TPluginConfig> | CFDC<K, (config: TPluginConfig) => void, string, TPluginConfig>): void;
362
364
  /**
363
365
  * 销毁装饰器
364
366
  * 在插件销毁时调用
365
367
  */
366
- declare function OnDestroy<This extends IPlugin>(originalMethod: (this: This) => void, context: ClassMethodDecoratorContext<This>): void;
368
+ declare function OnDestroy<K extends string>(_: any, context: CMDC<K, () => void> | CFDC<K, () => void>): void;
367
369
  /**
368
370
  * 配置变更装饰器
369
371
  * 在插件配置变更时调用
370
372
  */
371
- declare function OnConfigChange<TPluginConfig extends Record<string, any> | undefined, This extends IPlugin<string, TPluginConfig>>(originalMethod: (this: This, config: TPluginConfig) => void, context: ClassMethodDecoratorContext<This>): void;
373
+ declare function OnConfigChange<K extends string, TPluginConfig extends Record<string, any> | undefined>(_: any, context: CMDC<K, (config: TPluginConfig) => void, string, TPluginConfig> | CFDC<K, (config: TPluginConfig) => void, string, TPluginConfig>): void;
372
374
 
373
- declare function observable<T>(): (_: any, context: ClassFieldDecoratorContext<IPlugin, T>) => void;
375
+ declare function observable<K extends string, T>(): (_: any, context: CFDC<K, T>) => void;
374
376
 
375
- export { type InjectDecorator, type InjectDecoratorCallableDataType, type InjectDecoratorCallableMethodType, type InjectDecoratorCallablePluginDataType, type InjectDecoratorInjectableDataType, type InjectDecoratorInjectableMethodType, type InjectDecoratorInjectablePluginDataType, type InjectDecoratorInjectableType, type InjectWithContext, type Injectable, type InjectableDataKey, type InjectableMethodKey, OnConfigChange, OnDestroy, OnInit, type PanelOffset, type PanelPosition, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register };
377
+ export { type InjectDecorator, type InjectDecoratorCallableDataType, type InjectDecoratorCallableMethodType, type InjectDecoratorCallablePluginDataType, type InjectDecoratorInjectableDataType, type InjectDecoratorInjectableMethodType, type InjectDecoratorInjectablePluginDataType, type InjectDecoratorInjectableType, type InjectWithContext, type Injectable, type InjectableDataKey, type InjectableMethodKey, OnConfigChange, OnDestroy, OnInit, type PanelOffset, type PanelPosition, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register };