-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ts * ts rewrite --------- Co-authored-by: devin.chenyang <devin.chenyang@grabtaxi.com>
- Loading branch information
1 parent
1dd4200
commit 3132bd6
Showing
114 changed files
with
2,888 additions
and
1,915 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ | |
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/NodeEditor/AddComponent.js → src/NodeEditor/AddComponent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// @ts-nocheck | ||
|
||
import Rete from 'rete'; | ||
import MyNode from './MyNode'; | ||
import NumControl from './NumControl'; | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import { Control, NodeEditor } from 'rete'; | ||
|
||
const ButtonComponent = ({ | ||
text, | ||
onClick, | ||
}: { | ||
text: string; | ||
onClick: () => void; | ||
}) => ( | ||
<button type="button" onClick={onClick}> | ||
{text} | ||
</button> | ||
); | ||
|
||
type ControlInternalProps = { | ||
text: string; | ||
onClick: () => void; | ||
}; | ||
|
||
export default class ButtonControl extends Control { | ||
static component = ButtonComponent; | ||
|
||
emitter: NodeEditor; | ||
component: typeof ButtonComponent; | ||
props: ControlInternalProps; | ||
|
||
constructor( | ||
emitter: NodeEditor, | ||
key: string, | ||
{ text, onClick }: { text: string; onClick: () => void }, | ||
) { | ||
super(key); | ||
this.emitter = emitter; | ||
this.key = key; | ||
this.component = ButtonControl.component; | ||
|
||
this.props = { | ||
text, | ||
onClick: () => { | ||
onClick(); | ||
this.emitter.trigger('process'); | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Control, NodeEditor, Node } from 'rete'; | ||
import ColorPickerAndExpressionField from './components/ColorPicker/ColorPickerAndExpressionField'; | ||
|
||
declare module 'rete' { | ||
interface ColorPickerAndExpressionControl { | ||
update: () => void; | ||
} | ||
} | ||
|
||
/** | ||
* this.key="fill-color" | ||
* ```json | ||
* // expression disabled | ||
* nodeData = { | ||
* "fill-color": "#112233", | ||
* "fill-color.color": "#112233", | ||
* "fill-color.expression": "[\"get\", \"colorProp\"]", | ||
* } | ||
* // expression enabled | ||
* nodeData = { | ||
* "fill-color": ["get", "colorProp"], | ||
* "fill-color.color": "#112233", | ||
* "fill-color.expression": "[\"get\", \"colorProp\"]", | ||
* } | ||
* ``` | ||
*/ | ||
export default class ColorPickerAndExpressionControl extends Control { | ||
static component = ColorPickerAndExpressionField; | ||
|
||
emitter: NodeEditor; | ||
|
||
component: typeof ColorPickerAndExpressionField; | ||
|
||
props: any; | ||
|
||
// `update` function for control is defined when event "rendercontrol" | ||
// so `update` function may be undefined at the initial stage of page loading | ||
// https://github.com/retejs/rete/blob/master/src/view/control.ts#L9 | ||
// https://github.com/retejs/react-render-plugin/blob/master/src/index.jsx#L25 | ||
update: () => void = () => {}; | ||
|
||
constructor(emitter: NodeEditor, key: string, node: Node, props: any = {}) { | ||
super(key); | ||
this.emitter = emitter; | ||
this.key = key; | ||
this.component = ColorPickerAndExpressionControl.component; | ||
|
||
let initial = '#000'; | ||
if (node.data[key]) { | ||
initial = node.data[key] as string; | ||
} else if (props.defaultValue) { | ||
initial = props.defaultValue; | ||
} | ||
|
||
node.data[key] = initial; | ||
this.props = { | ||
...props, | ||
value: initial, | ||
defaultValue: initial, | ||
onChange: (v: string) => { | ||
this.setValue(v); | ||
this.emitter.trigger('process'); | ||
}, | ||
}; | ||
} | ||
|
||
setValue(val: string) { | ||
this.props.value = val; | ||
this.putData(this.key, val); | ||
this.update(); | ||
} | ||
|
||
getValue() { | ||
return this.props.value; | ||
} | ||
} |
Oops, something went wrong.