@knotx/decorators 0.2.4 → 0.2.6

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,19 @@
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, PluginTools } from '@knotx/core';
2
+ import { Schema } from 'jsonschema';
2
3
 
3
4
  interface IInternalPlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> extends IPlugin<TPluginName, any, TRenderType> {
4
5
  }
6
+ type CMDC<TK extends string, TM extends (...args: any[]) => any, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassMethodDecoratorContext<{
7
+ [key in TK]: TM;
8
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TM> & {
9
+ name: TK;
10
+ };
11
+ type CFDC<TK extends string, TV, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassFieldDecoratorContext<{
12
+ [key in TK]: TV;
13
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TV> & {
14
+ name: TK;
15
+ };
5
16
 
6
- declare const edgeOperatorSymbol: unique symbol;
7
- declare module '../internal' {
8
- interface IInternalPlugin {
9
- [edgeOperatorSymbol]?: Record<string | symbol, EdgeOperatorFunction>;
10
- }
11
- }
12
17
  /**
13
18
  * 边操作装饰器
14
19
  * 用于声明一个方法作为边操作函数
@@ -30,14 +35,8 @@ declare module '../internal' {
30
35
  * }
31
36
  * ```
32
37
  */
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;
38
+ declare function edgeOperator<K extends string, V extends EdgeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
34
39
 
35
- declare const edgePipeSymbol: unique symbol;
36
- declare module '../internal' {
37
- interface IInternalPlugin {
38
- [edgePipeSymbol]?: Record<string | symbol, EdgeOperationPipe<any>>;
39
- }
40
- }
41
40
  /**
42
41
  * 边操作管道装饰器
43
42
  * 用于声明一个方法作为边操作管道,在边操作执行前后进行处理
@@ -62,15 +61,23 @@ declare module '../internal' {
62
61
  * }
63
62
  * ```
64
63
  */
65
- declare function edgePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => EdgeOperationPipe<T>>) => void;
64
+ declare function edgePipe<K extends string>(): <T, V extends (...args: any[]) => EdgeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
66
65
 
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;
66
+ /**
67
+ * 连线渲染器装饰器
68
+ * 用于声明一个方法作为连线渲染器
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * class MyPlugin extends BasePlugin {
73
+ * @edgeType('my-edge')
74
+ * renderEdge() {
75
+ * return <div>My Edge</div>
76
+ * }
77
+ * }
78
+ * ```
79
+ */
80
+ declare function edgeType<K extends string, T extends string, V extends EdgeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
74
81
 
75
82
  type InjectableDataKey = keyof {
76
83
  [K in keyof Engine as Engine[K] extends (...args: any[]) => any ? never : K]: Engine[K];
@@ -225,30 +232,7 @@ type InjectDecorator = InjectDecoratorInjectableDataType & InjectDecoratorInject
225
232
  */
226
233
  declare const inject: InjectDecorator;
227
234
 
228
- /**
229
- * 注册插件属性装饰器
230
- *
231
- * 用于将插件的属性注册到引擎中,使其他插件可以通过 inject 访问该属性
232
- * 支持装饰字段和 getter,当装饰字段时,属性值变化会自动通知订阅者
233
- *
234
- * @param property 要注册的属性名
235
- * @returns 类字段或 getter 装饰器函数
236
- * @example
237
- * ```
238
- * // 注册普通字段
239
- * @register('canUndo')
240
- * canUndo = false
241
- *
242
- * // 注册计算属性
243
- * @register('ref')
244
- * get ref() {
245
- * return this
246
- * }
247
- * ```
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;
250
-
251
- declare function layer<This extends IPlugin>(layer: Layer, offset?: number): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
235
+ declare function layer<K extends string>(layer: Layer, offset?: number): (_: any, context: CMDC<K, () => void>) => void;
252
236
 
253
237
  /**
254
238
  * 面板位置
@@ -283,14 +267,8 @@ declare function createPanelWrapper(position: PanelPosition, offset?: PanelOffse
283
267
  * @param position 面板位置
284
268
  * @param offset 面板偏移
285
269
  */
286
- declare function panel<This extends IPlugin>(position: PanelPosition, offset?: PanelOffset): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
270
+ declare function panel<K extends string>(position: PanelPosition, offset?: PanelOffset): (_: any, context: CMDC<K, () => any>) => void;
287
271
 
288
- declare const nodeOperatorSymbol: unique symbol;
289
- declare module '../internal' {
290
- interface IInternalPlugin {
291
- [nodeOperatorSymbol]?: Record<string | symbol, NodeOperatorFunction>;
292
- }
293
- }
294
272
  /**
295
273
  * 节点操作装饰器
296
274
  * 用于声明一个方法作为节点操作函数
@@ -312,14 +290,8 @@ declare module '../internal' {
312
290
  * }
313
291
  * ```
314
292
  */
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;
293
+ declare function nodeOperator<K extends string, V extends NodeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
316
294
 
317
- declare const nodePipeSymbol: unique symbol;
318
- declare module '../internal' {
319
- interface IInternalPlugin {
320
- [nodePipeSymbol]?: Record<string | symbol, NodeOperationPipe<any>>;
321
- }
322
- }
323
295
  /**
324
296
  * 节点操作管道装饰器
325
297
  * 用于声明一个方法作为节点操作管道,在节点操作执行前后进行处理
@@ -344,32 +316,121 @@ declare module '../internal' {
344
316
  * }
345
317
  * ```
346
318
  */
347
- declare function nodePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => NodeOperationPipe<T>>) => void;
319
+ declare function nodePipe<K extends string>(): <T, V extends (...args: any[]) => NodeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
348
320
 
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;
321
+ /**
322
+ * 节点类型装饰器
323
+ * 用于声明一个方法作为节点类型
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * class MyPlugin extends BasePlugin {
328
+ * @nodeType('my-node')
329
+ * renderNode() {
330
+ * return <div>My Node</div>
331
+ * }
332
+ * }
333
+ * ```
334
+ */
335
+ declare function nodeType<K extends string, T extends string, V extends NodeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
336
+
337
+ /**
338
+ * 配置装饰器
339
+ * 自动绑定 OnInit 和 OnConfigChange 生命周期函数 和 observable 装饰器
340
+ */
341
+ declare function config<K extends string, V extends Record<string, any>>(): (_: any, context: CFDC<K, V, string, V>) => void;
356
342
 
357
343
  /**
358
344
  * 生命周期装饰器
359
345
  * 在插件初始化时调用
360
346
  */
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;
347
+ 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
348
  /**
363
349
  * 销毁装饰器
364
350
  * 在插件销毁时调用
365
351
  */
366
- declare function OnDestroy<This extends IPlugin>(originalMethod: (this: This) => void, context: ClassMethodDecoratorContext<This>): void;
352
+ declare function OnDestroy<K extends string>(_: any, context: CMDC<K, () => void> | CFDC<K, () => void>): void;
367
353
  /**
368
354
  * 配置变更装饰器
369
355
  * 在插件配置变更时调用
370
356
  */
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;
357
+ 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;
358
+
359
+ declare function observable<K extends string, T>(): (_: any, context: CFDC<K, T>) => void;
372
360
 
373
- declare function observable<T>(): (_: any, context: ClassFieldDecoratorContext<IPlugin, T>) => void;
361
+ /**
362
+ * 注册插件属性装饰器
363
+ *
364
+ * 用于将插件的属性注册到引擎中,使其他插件可以通过 inject 访问该属性
365
+ * 支持装饰字段和 getter,当装饰字段时,属性值变化会自动通知订阅者
366
+ *
367
+ * @param property 要注册的属性名
368
+ * @returns 类字段或 getter 装饰器函数
369
+ * @example
370
+ * ```
371
+ * // 注册字段
372
+ * @register('canUndo')
373
+ * canUndo = false
374
+ * ```
375
+ */
376
+ 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;
377
+
378
+ /**
379
+ * 工具函数参数定义
380
+ */
381
+ interface ToolParams {
382
+ description: string;
383
+ params: Schema;
384
+ }
385
+ /**
386
+ * 从JSONSchema推断参数类型的辅助类型
387
+ */
388
+ type InferParamsFromSchema<T extends Schema> = T extends {
389
+ type: 'object';
390
+ properties: infer P;
391
+ required?: infer R;
392
+ } ? {
393
+ [K in keyof P as K extends Extract<R extends string[] ? R[number] : never, string> ? K : never]: InferSchemaType<P[K]>;
394
+ } & {
395
+ [K in keyof P as K extends Extract<R extends string[] ? R[number] : never, string> ? never : K]?: InferSchemaType<P[K]>;
396
+ } : T extends {
397
+ type: 'array';
398
+ items: infer I;
399
+ } ? Array<InferSchemaType<I>> : T extends {
400
+ type: 'string';
401
+ } ? string : T extends {
402
+ type: 'number';
403
+ } ? number : T extends {
404
+ type: 'boolean';
405
+ } ? boolean : T extends {
406
+ type: 'null';
407
+ } ? null : T extends {
408
+ type: 'integer';
409
+ } ? number : any;
410
+ /**
411
+ * 从 JSONSchema 推断类型的辅助类型
412
+ */
413
+ type InferSchemaType<T> = T extends Schema ? InferParamsFromSchema<T> : any;
414
+ /**
415
+ * 工具函数装饰器
416
+ *
417
+ * 用于装饰插件中的工具函数,使其能被 engine 和其他 plugin 调用
418
+ *
419
+ * @param description 工具函数描述
420
+ * @param params 工具函数参数
421
+ * @returns 方法装饰器函数
422
+ * @example
423
+ * ```
424
+ * class MyPlugin extends BasePlugin {
425
+ * @tool('calculateDistance')
426
+ * calculateDistance(params: { x1: number, y1: number, x2: number, y2: number }): number {
427
+ * const dx = params.x2 - params.x1;
428
+ * const dy = params.y2 - params.y1;
429
+ * return Math.sqrt(dx * dx + dy * dy);
430
+ * }
431
+ * }
432
+ * ```
433
+ */
434
+ declare function tool<TN extends keyof PluginTools, TP extends keyof PluginTools[TN], TS extends Schema>(description: string, params: TS): (_: any, context: CMDC<Extract<TP, string>, PluginTools[TN][TP], TN>) => void;
374
435
 
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 };
436
+ export { type InferParamsFromSchema, type InferSchemaType, 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, type ToolParams, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register, tool };
package/dist/index.d.mts CHANGED
@@ -1,14 +1,19 @@
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, PluginTools } from '@knotx/core';
2
+ import { Schema } from 'jsonschema';
2
3
 
3
4
  interface IInternalPlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> extends IPlugin<TPluginName, any, TRenderType> {
4
5
  }
6
+ type CMDC<TK extends string, TM extends (...args: any[]) => any, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassMethodDecoratorContext<{
7
+ [key in TK]: TM;
8
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TM> & {
9
+ name: TK;
10
+ };
11
+ type CFDC<TK extends string, TV, TN extends string = string, TC extends Record<string, any> | undefined = any> = ClassFieldDecoratorContext<{
12
+ [key in TK]: TV;
13
+ } & BasePlugin<TN, TC, RenderType> & IPlugin<TN, TC, RenderType>, TV> & {
14
+ name: TK;
15
+ };
5
16
 
6
- declare const edgeOperatorSymbol: unique symbol;
7
- declare module '../internal' {
8
- interface IInternalPlugin {
9
- [edgeOperatorSymbol]?: Record<string | symbol, EdgeOperatorFunction>;
10
- }
11
- }
12
17
  /**
13
18
  * 边操作装饰器
14
19
  * 用于声明一个方法作为边操作函数
@@ -30,14 +35,8 @@ declare module '../internal' {
30
35
  * }
31
36
  * ```
32
37
  */
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;
38
+ declare function edgeOperator<K extends string, V extends EdgeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
34
39
 
35
- declare const edgePipeSymbol: unique symbol;
36
- declare module '../internal' {
37
- interface IInternalPlugin {
38
- [edgePipeSymbol]?: Record<string | symbol, EdgeOperationPipe<any>>;
39
- }
40
- }
41
40
  /**
42
41
  * 边操作管道装饰器
43
42
  * 用于声明一个方法作为边操作管道,在边操作执行前后进行处理
@@ -62,15 +61,23 @@ declare module '../internal' {
62
61
  * }
63
62
  * ```
64
63
  */
65
- declare function edgePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => EdgeOperationPipe<T>>) => void;
64
+ declare function edgePipe<K extends string>(): <T, V extends (...args: any[]) => EdgeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
66
65
 
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;
66
+ /**
67
+ * 连线渲染器装饰器
68
+ * 用于声明一个方法作为连线渲染器
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * class MyPlugin extends BasePlugin {
73
+ * @edgeType('my-edge')
74
+ * renderEdge() {
75
+ * return <div>My Edge</div>
76
+ * }
77
+ * }
78
+ * ```
79
+ */
80
+ declare function edgeType<K extends string, T extends string, V extends EdgeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
74
81
 
75
82
  type InjectableDataKey = keyof {
76
83
  [K in keyof Engine as Engine[K] extends (...args: any[]) => any ? never : K]: Engine[K];
@@ -225,30 +232,7 @@ type InjectDecorator = InjectDecoratorInjectableDataType & InjectDecoratorInject
225
232
  */
226
233
  declare const inject: InjectDecorator;
227
234
 
228
- /**
229
- * 注册插件属性装饰器
230
- *
231
- * 用于将插件的属性注册到引擎中,使其他插件可以通过 inject 访问该属性
232
- * 支持装饰字段和 getter,当装饰字段时,属性值变化会自动通知订阅者
233
- *
234
- * @param property 要注册的属性名
235
- * @returns 类字段或 getter 装饰器函数
236
- * @example
237
- * ```
238
- * // 注册普通字段
239
- * @register('canUndo')
240
- * canUndo = false
241
- *
242
- * // 注册计算属性
243
- * @register('ref')
244
- * get ref() {
245
- * return this
246
- * }
247
- * ```
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;
250
-
251
- declare function layer<This extends IPlugin>(layer: Layer, offset?: number): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
235
+ declare function layer<K extends string>(layer: Layer, offset?: number): (_: any, context: CMDC<K, () => void>) => void;
252
236
 
253
237
  /**
254
238
  * 面板位置
@@ -283,14 +267,8 @@ declare function createPanelWrapper(position: PanelPosition, offset?: PanelOffse
283
267
  * @param position 面板位置
284
268
  * @param offset 面板偏移
285
269
  */
286
- declare function panel<This extends IPlugin>(position: PanelPosition, offset?: PanelOffset): (_target: any, { name, kind, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<This>) => void;
270
+ declare function panel<K extends string>(position: PanelPosition, offset?: PanelOffset): (_: any, context: CMDC<K, () => any>) => void;
287
271
 
288
- declare const nodeOperatorSymbol: unique symbol;
289
- declare module '../internal' {
290
- interface IInternalPlugin {
291
- [nodeOperatorSymbol]?: Record<string | symbol, NodeOperatorFunction>;
292
- }
293
- }
294
272
  /**
295
273
  * 节点操作装饰器
296
274
  * 用于声明一个方法作为节点操作函数
@@ -312,14 +290,8 @@ declare module '../internal' {
312
290
  * }
313
291
  * ```
314
292
  */
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;
293
+ declare function nodeOperator<K extends string, V extends NodeOperatorFunction>(): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
316
294
 
317
- declare const nodePipeSymbol: unique symbol;
318
- declare module '../internal' {
319
- interface IInternalPlugin {
320
- [nodePipeSymbol]?: Record<string | symbol, NodeOperationPipe<any>>;
321
- }
322
- }
323
295
  /**
324
296
  * 节点操作管道装饰器
325
297
  * 用于声明一个方法作为节点操作管道,在节点操作执行前后进行处理
@@ -344,32 +316,121 @@ declare module '../internal' {
344
316
  * }
345
317
  * ```
346
318
  */
347
- declare function nodePipe(): <TRenderType extends RenderType, T = any>(_target: any, { name, static: isStatic, private: isPrivate, addInitializer }: ClassMethodDecoratorContext<IInternalPlugin<string, TRenderType>, () => NodeOperationPipe<T>>) => void;
319
+ declare function nodePipe<K extends string>(): <T, V extends (...args: any[]) => NodeOperationPipe<T>>(_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
348
320
 
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;
321
+ /**
322
+ * 节点类型装饰器
323
+ * 用于声明一个方法作为节点类型
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * class MyPlugin extends BasePlugin {
328
+ * @nodeType('my-node')
329
+ * renderNode() {
330
+ * return <div>My Node</div>
331
+ * }
332
+ * }
333
+ * ```
334
+ */
335
+ declare function nodeType<K extends string, T extends string, V extends NodeRenderType>(type: T): (_: any, context: CMDC<K, V> | CFDC<K, V>) => void;
336
+
337
+ /**
338
+ * 配置装饰器
339
+ * 自动绑定 OnInit 和 OnConfigChange 生命周期函数 和 observable 装饰器
340
+ */
341
+ declare function config<K extends string, V extends Record<string, any>>(): (_: any, context: CFDC<K, V, string, V>) => void;
356
342
 
357
343
  /**
358
344
  * 生命周期装饰器
359
345
  * 在插件初始化时调用
360
346
  */
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;
347
+ 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
348
  /**
363
349
  * 销毁装饰器
364
350
  * 在插件销毁时调用
365
351
  */
366
- declare function OnDestroy<This extends IPlugin>(originalMethod: (this: This) => void, context: ClassMethodDecoratorContext<This>): void;
352
+ declare function OnDestroy<K extends string>(_: any, context: CMDC<K, () => void> | CFDC<K, () => void>): void;
367
353
  /**
368
354
  * 配置变更装饰器
369
355
  * 在插件配置变更时调用
370
356
  */
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;
357
+ 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;
358
+
359
+ declare function observable<K extends string, T>(): (_: any, context: CFDC<K, T>) => void;
372
360
 
373
- declare function observable<T>(): (_: any, context: ClassFieldDecoratorContext<IPlugin, T>) => void;
361
+ /**
362
+ * 注册插件属性装饰器
363
+ *
364
+ * 用于将插件的属性注册到引擎中,使其他插件可以通过 inject 访问该属性
365
+ * 支持装饰字段和 getter,当装饰字段时,属性值变化会自动通知订阅者
366
+ *
367
+ * @param property 要注册的属性名
368
+ * @returns 类字段或 getter 装饰器函数
369
+ * @example
370
+ * ```
371
+ * // 注册字段
372
+ * @register('canUndo')
373
+ * canUndo = false
374
+ * ```
375
+ */
376
+ 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;
377
+
378
+ /**
379
+ * 工具函数参数定义
380
+ */
381
+ interface ToolParams {
382
+ description: string;
383
+ params: Schema;
384
+ }
385
+ /**
386
+ * 从JSONSchema推断参数类型的辅助类型
387
+ */
388
+ type InferParamsFromSchema<T extends Schema> = T extends {
389
+ type: 'object';
390
+ properties: infer P;
391
+ required?: infer R;
392
+ } ? {
393
+ [K in keyof P as K extends Extract<R extends string[] ? R[number] : never, string> ? K : never]: InferSchemaType<P[K]>;
394
+ } & {
395
+ [K in keyof P as K extends Extract<R extends string[] ? R[number] : never, string> ? never : K]?: InferSchemaType<P[K]>;
396
+ } : T extends {
397
+ type: 'array';
398
+ items: infer I;
399
+ } ? Array<InferSchemaType<I>> : T extends {
400
+ type: 'string';
401
+ } ? string : T extends {
402
+ type: 'number';
403
+ } ? number : T extends {
404
+ type: 'boolean';
405
+ } ? boolean : T extends {
406
+ type: 'null';
407
+ } ? null : T extends {
408
+ type: 'integer';
409
+ } ? number : any;
410
+ /**
411
+ * 从 JSONSchema 推断类型的辅助类型
412
+ */
413
+ type InferSchemaType<T> = T extends Schema ? InferParamsFromSchema<T> : any;
414
+ /**
415
+ * 工具函数装饰器
416
+ *
417
+ * 用于装饰插件中的工具函数,使其能被 engine 和其他 plugin 调用
418
+ *
419
+ * @param description 工具函数描述
420
+ * @param params 工具函数参数
421
+ * @returns 方法装饰器函数
422
+ * @example
423
+ * ```
424
+ * class MyPlugin extends BasePlugin {
425
+ * @tool('calculateDistance')
426
+ * calculateDistance(params: { x1: number, y1: number, x2: number, y2: number }): number {
427
+ * const dx = params.x2 - params.x1;
428
+ * const dy = params.y2 - params.y1;
429
+ * return Math.sqrt(dx * dx + dy * dy);
430
+ * }
431
+ * }
432
+ * ```
433
+ */
434
+ declare function tool<TN extends keyof PluginTools, TP extends keyof PluginTools[TN], TS extends Schema>(description: string, params: TS): (_: any, context: CMDC<Extract<TP, string>, PluginTools[TN][TP], TN>) => void;
374
435
 
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 };
436
+ export { type InferParamsFromSchema, type InferSchemaType, 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, type ToolParams, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register, tool };