-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Macrofy 'Get Attribute' + generic util for simple string macros (#91)
- Loading branch information
Showing
9 changed files
with
135 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { InputPinMap, MacroNode } from "@flyde/core"; | ||
import { ConfigurableInput } from "../../lib/ConfigurableInput"; | ||
|
||
export interface GetAttributeConfig { | ||
key: ConfigurableInput<{ value: string }>; | ||
} | ||
|
||
export const GetAttribute: MacroNode<GetAttributeConfig> = { | ||
id: "GetAttribute", | ||
searchKeywords: ["pick", "dot"], | ||
namespace: "Lists", | ||
defaultStyle: { | ||
icon: "fa-magnifying-glass", | ||
}, | ||
description: "Gets an attribute from an object", | ||
definitionBuilder: (config) => { | ||
const inputs: InputPinMap = { | ||
object: { | ||
description: "Object to get attribute from", | ||
}, | ||
}; | ||
if (config.key.mode === "dynamic") { | ||
inputs.attribute = { | ||
description: "Attribute to get", | ||
}; | ||
} | ||
return { | ||
inputs, | ||
outputs: { | ||
value: { | ||
description: "The value of the attribute", | ||
}, | ||
}, | ||
displayName: `Get Attribute${ | ||
config.key.mode === "static" ? ` "${config.key.value}"` : "" | ||
}`, | ||
}; | ||
}, | ||
|
||
runFnBuilder: | ||
(config) => | ||
({ object, attribute }, { value }) => { | ||
const _attribute = | ||
config.key.mode === "static" ? config.key.value : attribute; | ||
value.next(_attribute.split(".").reduce((obj, i) => obj[i], object)); | ||
}, | ||
defaultData: { key: { mode: "static", value: "" } }, | ||
editorComponentBundlePath: "../../../../dist/ui/GetAttribute.js", | ||
}; |
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,7 @@ | ||
import { MacroEditorComp } from "../../lib/MacroEditorComp"; | ||
import { GetAttributeConfig } from "./GetAttribute.flyde"; | ||
import { SimpleStringMacroEditor } from "../../lib/SimpleStringMacroEditor"; | ||
|
||
const GetAttributeEditor: MacroEditorComp<GetAttributeConfig> = | ||
SimpleStringMacroEditor<"key">("key", "Key:"); | ||
export default GetAttributeEditor; |
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
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,37 @@ | ||
import React from "react"; | ||
import { FormGroup, InputGroup } from "@blueprintjs/core"; | ||
import { ConfigurableInput } from "./ConfigurableInput"; | ||
import { ConfigurableInputEditor } from "./ConfigurableInputEditor"; | ||
import { MacroEditorComp } from "./MacroEditorComp"; | ||
|
||
export function SimpleStringMacroEditor<K extends string>( | ||
key: K, | ||
label: string | ||
): MacroEditorComp<{ [P in K]: ConfigurableInput<{ value: string }> }> { | ||
const Editor: MacroEditorComp<{ | ||
[P in K]: ConfigurableInput<{ value: string }>; | ||
}> = function Editor({ value, onChange }) { | ||
return ( | ||
<ConfigurableInputEditor | ||
value={value[key]} | ||
onChange={(newValue) => onChange({ ...value, [key]: newValue })} | ||
valueRenderer={(vrProps) => ( | ||
<FormGroup label={label} inline> | ||
<InputGroup | ||
value={vrProps.value.value} | ||
onChange={(e) => | ||
vrProps.onChange({ | ||
...vrProps.value, | ||
value: e.target.value, | ||
}) | ||
} | ||
/> | ||
</FormGroup> | ||
)} | ||
modeLabel="Key:" | ||
defaultStaticValue={{ value: "" }} | ||
/> | ||
); | ||
}; | ||
return Editor; | ||
} |
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