* create from a widget * @param widget * @returns
(widget: Widget)
| 104 | * @returns |
| 105 | */ |
| 106 | fromWidget(widget: Widget): SDNode { |
| 107 | if (widget.name === NODE_REROUTE) { |
| 108 | return SDNode.newRerouteNode(); |
| 109 | } |
| 110 | if (widget.name === NODE_PRIMITIVE) { |
| 111 | return SDNode.newPrimitiveNode(); |
| 112 | } |
| 113 | const inputs = [...Object.entries(widget.input.required), ...Object.entries(widget.input.optional || {})] |
| 114 | .filter(([name, input]) => { |
| 115 | return !Input.isParameterOrList(input) |
| 116 | }) |
| 117 | .map(([name, input]) => { |
| 118 | return { |
| 119 | name: name, |
| 120 | type: input[0] as any, |
| 121 | link: undefined |
| 122 | } |
| 123 | }); |
| 124 | |
| 125 | |
| 126 | const outputs = widget.output.map((output, index) => { |
| 127 | return { |
| 128 | name: output, |
| 129 | type: output, |
| 130 | links: [], |
| 131 | slot_index: index |
| 132 | } |
| 133 | }); |
| 134 | const ret = { |
| 135 | widget: widget.name, |
| 136 | fields: Widget.getDefaultFields(widget), |
| 137 | inputs: inputs, |
| 138 | color: SDNODE_DEFAULT_COLOR.color, |
| 139 | bgcolor: SDNODE_DEFAULT_COLOR.bgcolor, |
| 140 | outputs: outputs, |
| 141 | } |
| 142 | |
| 143 | if (widget.name === NODE_GROUP) { |
| 144 | ret.color = '#2AAFF7'; |
| 145 | ret.bgcolor = '#21262A'; |
| 146 | } |
| 147 | |
| 148 | if (widget.name === "SaveImage") { |
| 149 | ret.fields["filename_prefix"] = "comflowy_"; |
| 150 | } |
| 151 | |
| 152 | return ret; |
| 153 | }, |
| 154 | newStaticPrimitiveNode(primitiveType: FlowStaticPrimitiveType): SDNode { |
| 155 | return { |
| 156 | widget: NODE_PRIMITIVE, |