-
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.
- Loading branch information
Showing
5 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
apps/electron-app/src/render/components/react-flow/nodes/Constant.tsx
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,52 @@ | ||
import { ConstantData } from '@microflow/components'; | ||
import { BaseNode, NodeContainer, useNodeData, useNodeSettings } from './Node'; | ||
import { useEffect } from 'react'; | ||
import { Handle } from './Handle'; | ||
import { Position } from '@xyflow/react'; | ||
|
||
const numberFormat = new Intl.NumberFormat(); | ||
|
||
export function Constant(props: Props) { | ||
return ( | ||
<NodeContainer {...props}> | ||
<Value /> | ||
<Settings /> | ||
<Handle type="source" position={Position.Right} id="output" /> | ||
</NodeContainer> | ||
); | ||
} | ||
|
||
function Value() { | ||
const data = useNodeData<ConstantData>(); | ||
|
||
return <section className="text-4xl tabular-nums">{numberFormat.format(data.value)}</section>; | ||
} | ||
|
||
function Settings() { | ||
const { pane, settings } = useNodeSettings<ConstantData>(); | ||
|
||
useEffect(() => { | ||
if (!pane) return; | ||
|
||
const valueBinding = pane.addBinding(settings, 'value', { | ||
index: 0, | ||
type: 'number', | ||
}); | ||
|
||
return () => { | ||
valueBinding.dispose(); | ||
}; | ||
}, [pane]); | ||
|
||
return null; | ||
} | ||
|
||
type Props = BaseNode<ConstantData>; | ||
Constant.defaultProps = { | ||
data: { | ||
value: 4, | ||
group: 'flow', | ||
tags: ['generator'], | ||
label: 'Constant', | ||
} satisfies Props['data'], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { BaseComponent, BaseComponentData } from './BaseComponent'; | ||
|
||
export type ConstantValueType = number; | ||
|
||
export type ConstantData = { | ||
value: number; | ||
}; | ||
|
||
export class Constant extends BaseComponent<ConstantValueType> { | ||
constructor(data: BaseComponentData & ConstantData) { | ||
super(data, data.value); | ||
} | ||
} |