@knotx/decorators 0.2.7 → 0.2.9

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.cjs CHANGED
@@ -26,6 +26,10 @@ function createBehaviorSubject(plugin, key, value) {
26
26
  });
27
27
  return true;
28
28
  }
29
+ function subscribeBehaviorSubject(plugin, key, value) {
30
+ pushSubscription.call(plugin, value.subscribe((v) => Reflect.apply(Reflect.get(plugin, key), plugin, [v])));
31
+ return true;
32
+ }
29
33
  function getPropertyBehaviorSubjectKey(key) {
30
34
  return `__${key}$__`;
31
35
  }
@@ -80,7 +84,7 @@ function edgeType(type) {
80
84
  }
81
85
  context.addInitializer(function() {
82
86
  subscribeEngine.call(this, (engine) => {
83
- pushSubscription.call(this, engine.registerEdgeRenderer(type, this[context.name].bind(this)));
87
+ pushSubscription.call(this, engine.registerEdgeRenderer(type, "bind" in this[context.name] ? this[context.name].bind(this) : this[context.name]));
84
88
  });
85
89
  });
86
90
  };
@@ -312,6 +316,59 @@ function createInjectProxy(...presets) {
312
316
  }
313
317
  const inject = createInjectProxy();
314
318
 
319
+ function subscribeData(context, engineKey) {
320
+ context.addInitializer(function() {
321
+ mergePluginHookFunction.call(this, "onInit", () => {
322
+ const engine = getEngine.call(this);
323
+ if (!engine) {
324
+ return void 0;
325
+ }
326
+ const engineKey$ = `${String(engineKey)}$`;
327
+ const paths = lodashEs.get(engine, engineKey$) ? [engineKey$] : [engineKey];
328
+ subscribeBehaviorSubject(this, context.name, lodashEs.get(engine, paths));
329
+ });
330
+ });
331
+ }
332
+
333
+ function subscribePluginData(context, pluginName, property) {
334
+ context.addInitializer(function() {
335
+ mergePluginHookFunction.call(this, "onInit", () => {
336
+ const engine = getEngine.call(this);
337
+ if (!engine) {
338
+ return void 0;
339
+ }
340
+ const paths = ["_pluginDataContainer", pluginName, property];
341
+ subscribeBehaviorSubject(this, context.name, lodashEs.get(engine, paths));
342
+ });
343
+ });
344
+ }
345
+
346
+ function subscribeDecorator(arg0, arg1) {
347
+ return function(_, context) {
348
+ if (typeof arg1 === "string") {
349
+ return subscribePluginData(context, arg0, arg1);
350
+ }
351
+ const engineKey = arg0;
352
+ return subscribeData(context, engineKey);
353
+ };
354
+ }
355
+
356
+ function createSubscribeProxy(...presets) {
357
+ return new Proxy(
358
+ new Object(() => {
359
+ }),
360
+ {
361
+ get(_, prop) {
362
+ return createSubscribeProxy(...presets, prop);
363
+ },
364
+ apply(_, thisArg, args) {
365
+ return Reflect.apply(subscribeDecorator, thisArg, [...presets, ...args]);
366
+ }
367
+ }
368
+ );
369
+ }
370
+ const subscribe = createSubscribeProxy();
371
+
315
372
  function layer(layer2, offset) {
316
373
  return function(_, context) {
317
374
  if (context.static) {
@@ -484,7 +541,7 @@ function nodeType(type) {
484
541
  }
485
542
  context.addInitializer(function() {
486
543
  subscribeEngine.call(this, (engine) => {
487
- pushSubscription.call(this, engine.registerNodeRenderer(type, this[context.name].bind(this)));
544
+ pushSubscription.call(this, engine.registerNodeRenderer(type, "bind" in this[context.name] ? this[context.name].bind(this) : this[context.name]));
488
545
  });
489
546
  });
490
547
  };
@@ -595,4 +652,5 @@ exports.nodeType = nodeType;
595
652
  exports.observable = observable;
596
653
  exports.panel = panel;
597
654
  exports.register = register;
655
+ exports.subscribe = subscribe;
598
656
  exports.tool = tool;
package/dist/index.d.cts CHANGED
@@ -232,6 +232,59 @@ type InjectDecorator = InjectDecoratorInjectableDataType & InjectDecoratorInject
232
232
  */
233
233
  declare const inject: InjectDecorator;
234
234
 
235
+ type SubscribeDataKey = keyof {
236
+ [K in keyof Engine as Engine[K] extends (...args: any[]) => any ? never : K]: Engine[K];
237
+ };
238
+ type SubscribeDecoratorSelectableDataType = {
239
+ [K in SubscribeDataKey]: {
240
+ (): <TK extends string>(_: any, context: CMDC<TK, (v: Engine[K]) => void>) => void;
241
+ };
242
+ };
243
+ type SubscribeDecoratorSelectablePluginDataType = {
244
+ [K in keyof PluginData]: {
245
+ [P in keyof PluginData[K]]: {
246
+ (): <TK extends string>(_: any, context: CMDC<TK, (v: PluginData[K][P]) => void>) => void;
247
+ };
248
+ };
249
+ };
250
+ interface SubscribeDecoratorCallableDataType {
251
+ /**
252
+ * 注入引擎属性装饰器
253
+ * 用于将引擎的数据属性注入到插件类的字段中
254
+ * @param engineKey 引擎数据的键名
255
+ * @example
256
+ * ```
257
+ * @subscribe('nodes')
258
+ * nodes!: NodeData[]
259
+ * ```
260
+ */
261
+ <T extends SubscribeDataKey>(engineKey: T): <TK extends string>(_: any, context: CMDC<TK, (v: Engine[T]) => void>) => void;
262
+ }
263
+ interface SubscribeDecoratorCallablePluginDataType {
264
+ /**
265
+ * 注入插件属性装饰器
266
+ * 用于将其他插件的数据属性注入到当前插件类的字段中
267
+ * @param pluginName 插件名称
268
+ * @param property 插件属性名
269
+ * @example
270
+ * ```
271
+ * @subscribe.history.canUndo()
272
+ * canUndo!: boolean
273
+ * ```
274
+ */
275
+ <T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP): <TK extends string>(_: any, context: CMDC<TK, (v: PluginData[T][TP]) => void>) => void;
276
+ }
277
+ type SubscribeDecorator = SubscribeDecoratorSelectableDataType & SubscribeDecoratorSelectablePluginDataType & SubscribeDecoratorCallableDataType & SubscribeDecoratorCallablePluginDataType;
278
+
279
+ /**
280
+ * 监听引擎变量
281
+ * \@subscribe.property()
282
+ *
283
+ * 监听插件变量
284
+ * \@subscribe.pluginName.property()
285
+ */
286
+ declare const subscribe: SubscribeDecorator;
287
+
235
288
  declare function layer<K extends string>(layer: Layer, offset?: number): (_: any, context: CMDC<K, () => void>) => void;
236
289
 
237
290
  /**
@@ -433,4 +486,4 @@ type InferSchemaType<T> = T extends Schema ? InferParamsFromSchema<T> : any;
433
486
  */
434
487
  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;
435
488
 
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 };
489
+ 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 SubscribeDataKey, type SubscribeDecorator, type SubscribeDecoratorCallableDataType, type SubscribeDecoratorCallablePluginDataType, type SubscribeDecoratorSelectableDataType, type SubscribeDecoratorSelectablePluginDataType, type ToolParams, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register, subscribe, tool };
package/dist/index.d.mts CHANGED
@@ -232,6 +232,59 @@ type InjectDecorator = InjectDecoratorInjectableDataType & InjectDecoratorInject
232
232
  */
233
233
  declare const inject: InjectDecorator;
234
234
 
235
+ type SubscribeDataKey = keyof {
236
+ [K in keyof Engine as Engine[K] extends (...args: any[]) => any ? never : K]: Engine[K];
237
+ };
238
+ type SubscribeDecoratorSelectableDataType = {
239
+ [K in SubscribeDataKey]: {
240
+ (): <TK extends string>(_: any, context: CMDC<TK, (v: Engine[K]) => void>) => void;
241
+ };
242
+ };
243
+ type SubscribeDecoratorSelectablePluginDataType = {
244
+ [K in keyof PluginData]: {
245
+ [P in keyof PluginData[K]]: {
246
+ (): <TK extends string>(_: any, context: CMDC<TK, (v: PluginData[K][P]) => void>) => void;
247
+ };
248
+ };
249
+ };
250
+ interface SubscribeDecoratorCallableDataType {
251
+ /**
252
+ * 注入引擎属性装饰器
253
+ * 用于将引擎的数据属性注入到插件类的字段中
254
+ * @param engineKey 引擎数据的键名
255
+ * @example
256
+ * ```
257
+ * @subscribe('nodes')
258
+ * nodes!: NodeData[]
259
+ * ```
260
+ */
261
+ <T extends SubscribeDataKey>(engineKey: T): <TK extends string>(_: any, context: CMDC<TK, (v: Engine[T]) => void>) => void;
262
+ }
263
+ interface SubscribeDecoratorCallablePluginDataType {
264
+ /**
265
+ * 注入插件属性装饰器
266
+ * 用于将其他插件的数据属性注入到当前插件类的字段中
267
+ * @param pluginName 插件名称
268
+ * @param property 插件属性名
269
+ * @example
270
+ * ```
271
+ * @subscribe.history.canUndo()
272
+ * canUndo!: boolean
273
+ * ```
274
+ */
275
+ <T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP): <TK extends string>(_: any, context: CMDC<TK, (v: PluginData[T][TP]) => void>) => void;
276
+ }
277
+ type SubscribeDecorator = SubscribeDecoratorSelectableDataType & SubscribeDecoratorSelectablePluginDataType & SubscribeDecoratorCallableDataType & SubscribeDecoratorCallablePluginDataType;
278
+
279
+ /**
280
+ * 监听引擎变量
281
+ * \@subscribe.property()
282
+ *
283
+ * 监听插件变量
284
+ * \@subscribe.pluginName.property()
285
+ */
286
+ declare const subscribe: SubscribeDecorator;
287
+
235
288
  declare function layer<K extends string>(layer: Layer, offset?: number): (_: any, context: CMDC<K, () => void>) => void;
236
289
 
237
290
  /**
@@ -433,4 +486,4 @@ type InferSchemaType<T> = T extends Schema ? InferParamsFromSchema<T> : any;
433
486
  */
434
487
  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;
435
488
 
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 };
489
+ 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 SubscribeDataKey, type SubscribeDecorator, type SubscribeDecoratorCallableDataType, type SubscribeDecoratorCallablePluginDataType, type SubscribeDecoratorSelectableDataType, type SubscribeDecoratorSelectablePluginDataType, type ToolParams, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register, subscribe, tool };
package/dist/index.d.ts CHANGED
@@ -232,6 +232,59 @@ type InjectDecorator = InjectDecoratorInjectableDataType & InjectDecoratorInject
232
232
  */
233
233
  declare const inject: InjectDecorator;
234
234
 
235
+ type SubscribeDataKey = keyof {
236
+ [K in keyof Engine as Engine[K] extends (...args: any[]) => any ? never : K]: Engine[K];
237
+ };
238
+ type SubscribeDecoratorSelectableDataType = {
239
+ [K in SubscribeDataKey]: {
240
+ (): <TK extends string>(_: any, context: CMDC<TK, (v: Engine[K]) => void>) => void;
241
+ };
242
+ };
243
+ type SubscribeDecoratorSelectablePluginDataType = {
244
+ [K in keyof PluginData]: {
245
+ [P in keyof PluginData[K]]: {
246
+ (): <TK extends string>(_: any, context: CMDC<TK, (v: PluginData[K][P]) => void>) => void;
247
+ };
248
+ };
249
+ };
250
+ interface SubscribeDecoratorCallableDataType {
251
+ /**
252
+ * 注入引擎属性装饰器
253
+ * 用于将引擎的数据属性注入到插件类的字段中
254
+ * @param engineKey 引擎数据的键名
255
+ * @example
256
+ * ```
257
+ * @subscribe('nodes')
258
+ * nodes!: NodeData[]
259
+ * ```
260
+ */
261
+ <T extends SubscribeDataKey>(engineKey: T): <TK extends string>(_: any, context: CMDC<TK, (v: Engine[T]) => void>) => void;
262
+ }
263
+ interface SubscribeDecoratorCallablePluginDataType {
264
+ /**
265
+ * 注入插件属性装饰器
266
+ * 用于将其他插件的数据属性注入到当前插件类的字段中
267
+ * @param pluginName 插件名称
268
+ * @param property 插件属性名
269
+ * @example
270
+ * ```
271
+ * @subscribe.history.canUndo()
272
+ * canUndo!: boolean
273
+ * ```
274
+ */
275
+ <T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP): <TK extends string>(_: any, context: CMDC<TK, (v: PluginData[T][TP]) => void>) => void;
276
+ }
277
+ type SubscribeDecorator = SubscribeDecoratorSelectableDataType & SubscribeDecoratorSelectablePluginDataType & SubscribeDecoratorCallableDataType & SubscribeDecoratorCallablePluginDataType;
278
+
279
+ /**
280
+ * 监听引擎变量
281
+ * \@subscribe.property()
282
+ *
283
+ * 监听插件变量
284
+ * \@subscribe.pluginName.property()
285
+ */
286
+ declare const subscribe: SubscribeDecorator;
287
+
235
288
  declare function layer<K extends string>(layer: Layer, offset?: number): (_: any, context: CMDC<K, () => void>) => void;
236
289
 
237
290
  /**
@@ -433,4 +486,4 @@ type InferSchemaType<T> = T extends Schema ? InferParamsFromSchema<T> : any;
433
486
  */
434
487
  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;
435
488
 
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 };
489
+ 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 SubscribeDataKey, type SubscribeDecorator, type SubscribeDecoratorCallableDataType, type SubscribeDecoratorCallablePluginDataType, type SubscribeDecoratorSelectableDataType, type SubscribeDecoratorSelectablePluginDataType, type ToolParams, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register, subscribe, tool };
package/dist/index.js CHANGED
@@ -24,6 +24,10 @@ function createBehaviorSubject(plugin, key, value) {
24
24
  });
25
25
  return true;
26
26
  }
27
+ function subscribeBehaviorSubject(plugin, key, value) {
28
+ pushSubscription.call(plugin, value.subscribe((v) => Reflect.apply(Reflect.get(plugin, key), plugin, [v])));
29
+ return true;
30
+ }
27
31
  function getPropertyBehaviorSubjectKey(key) {
28
32
  return `__${key}$__`;
29
33
  }
@@ -78,7 +82,7 @@ function edgeType(type) {
78
82
  }
79
83
  context.addInitializer(function() {
80
84
  subscribeEngine.call(this, (engine) => {
81
- pushSubscription.call(this, engine.registerEdgeRenderer(type, this[context.name].bind(this)));
85
+ pushSubscription.call(this, engine.registerEdgeRenderer(type, "bind" in this[context.name] ? this[context.name].bind(this) : this[context.name]));
82
86
  });
83
87
  });
84
88
  };
@@ -310,6 +314,59 @@ function createInjectProxy(...presets) {
310
314
  }
311
315
  const inject = createInjectProxy();
312
316
 
317
+ function subscribeData(context, engineKey) {
318
+ context.addInitializer(function() {
319
+ mergePluginHookFunction.call(this, "onInit", () => {
320
+ const engine = getEngine.call(this);
321
+ if (!engine) {
322
+ return void 0;
323
+ }
324
+ const engineKey$ = `${String(engineKey)}$`;
325
+ const paths = get(engine, engineKey$) ? [engineKey$] : [engineKey];
326
+ subscribeBehaviorSubject(this, context.name, get(engine, paths));
327
+ });
328
+ });
329
+ }
330
+
331
+ function subscribePluginData(context, pluginName, property) {
332
+ context.addInitializer(function() {
333
+ mergePluginHookFunction.call(this, "onInit", () => {
334
+ const engine = getEngine.call(this);
335
+ if (!engine) {
336
+ return void 0;
337
+ }
338
+ const paths = ["_pluginDataContainer", pluginName, property];
339
+ subscribeBehaviorSubject(this, context.name, get(engine, paths));
340
+ });
341
+ });
342
+ }
343
+
344
+ function subscribeDecorator(arg0, arg1) {
345
+ return function(_, context) {
346
+ if (typeof arg1 === "string") {
347
+ return subscribePluginData(context, arg0, arg1);
348
+ }
349
+ const engineKey = arg0;
350
+ return subscribeData(context, engineKey);
351
+ };
352
+ }
353
+
354
+ function createSubscribeProxy(...presets) {
355
+ return new Proxy(
356
+ new Object(() => {
357
+ }),
358
+ {
359
+ get(_, prop) {
360
+ return createSubscribeProxy(...presets, prop);
361
+ },
362
+ apply(_, thisArg, args) {
363
+ return Reflect.apply(subscribeDecorator, thisArg, [...presets, ...args]);
364
+ }
365
+ }
366
+ );
367
+ }
368
+ const subscribe = createSubscribeProxy();
369
+
313
370
  function layer(layer2, offset) {
314
371
  return function(_, context) {
315
372
  if (context.static) {
@@ -482,7 +539,7 @@ function nodeType(type) {
482
539
  }
483
540
  context.addInitializer(function() {
484
541
  subscribeEngine.call(this, (engine) => {
485
- pushSubscription.call(this, engine.registerNodeRenderer(type, this[context.name].bind(this)));
542
+ pushSubscription.call(this, engine.registerNodeRenderer(type, "bind" in this[context.name] ? this[context.name].bind(this) : this[context.name]));
486
543
  });
487
544
  });
488
545
  };
@@ -577,4 +634,4 @@ function tool(description, params) {
577
634
  };
578
635
  }
579
636
 
580
- export { OnConfigChange, OnDestroy, OnInit, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register, tool };
637
+ export { OnConfigChange, OnDestroy, OnInit, config, createPanelWrapper, edgeOperator, edgePipe, edgeType, inject, layer, nodeOperator, nodePipe, nodeType, observable, panel, register, subscribe, tool };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/decorators",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Decorators for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -28,20 +28,20 @@
28
28
  "dist"
29
29
  ],
30
30
  "peerDependencies": {
31
- "@knotx/jsx": "0.2.7"
31
+ "@knotx/jsx": "0.2.9"
32
32
  },
33
33
  "dependencies": {
34
34
  "jsonschema": "^1.5.0",
35
35
  "lodash-es": "^4.17.21",
36
36
  "rxjs": "^7.8.1",
37
- "@knotx/core": "0.2.7"
37
+ "@knotx/core": "0.2.9"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/lodash-es": "^4.14.12",
41
- "@knotx/build-config": "0.2.7",
42
- "@knotx/eslint-config": "0.2.7",
43
- "@knotx/jsx": "0.2.7",
44
- "@knotx/typescript-config": "0.2.7"
41
+ "@knotx/build-config": "0.2.9",
42
+ "@knotx/eslint-config": "0.2.9",
43
+ "@knotx/jsx": "0.2.9",
44
+ "@knotx/typescript-config": "0.2.9"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "unbuild",