File size: 1,822 Bytes
b39afbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
 * Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
 * All rights reserved.
 */

import { Control } from 'rete';

interface IWorkflowComponentControlDefOpts {
  readonly?: boolean;
  default?: any;
  min?: number;
  max?: number;
  placeholder?: string;
  choices?:
    | Array<{
        id: string;
        name: string;
      }>
    | string[];
}

interface IWorkflowComponentControlDef {
  key: string;
  emitter: any;
  title: string;
  clientControl: any;
  displays?: string;
  description?: string;
  opts: IWorkflowComponentControlDefOpts;
}

interface IOpenAPIComponentControlDef {
  key: string;
  emitter: any;
  title?: string;
  control: any;
  displays?: string;
  rules?: any;
  opts: any;
  description?: string;
  slot?: string;
}

class OpenAPIComponentControl extends Control {
  props: any;
  config: IOpenAPIComponentControlDef;
  title?: string;
  opts: {};
  emitter?: any;
  description?: string;
  slot?: string;
  required: boolean;
  constructor(config: IOpenAPIComponentControlDef) {
    super(config.key);
    config.opts ??= {
      readonly: false
    };
    this.config = config;
    this.title = config.title;
    this.opts = config.opts ?? {};
    this.props = {
      emitter: config.emitter,
      ikey: config.key,
      title: config.title,
      rules: config.rules,
      opts: config.opts
    };
    this.emitter = config.emitter;
    this.description = config.description;
    // @ts-ignore
    this.component = config.control;
    this.slot = config.slot ?? 'top';
    this.required = config.opts.required === true;
  }

  setValue(val: any) {
    this.putData(this.props.ikey, val);
    // @ts-ignore
    this.update();
  }
}

export {
  OpenAPIComponentControl,
  type IOpenAPIComponentControlDef,
  type IWorkflowComponentControlDef,
  type IWorkflowComponentControlDefOpts
};