added format command and added trailing commas to reduce conflicts

This commit is contained in:
dswbx
2025-02-26 20:06:03 +01:00
parent 88b5359f1c
commit 7743f71a11
414 changed files with 3622 additions and 3610 deletions

View File

@@ -10,7 +10,7 @@ import {
addEdge,
useEdgesState,
useNodesState,
useStore
useStore,
} from "@xyflow/react";
import { type Execution, ExecutionEvent, ExecutionState, type Flow, type Task } from "flows";
import { transform } from "lodash-es";
@@ -24,8 +24,8 @@ export default function FlowCanvas({
flow,
execution,
options = {
theme: "dark"
}
theme: "dark",
},
}: {
flow: Flow;
execution: Execution | undefined;
@@ -70,9 +70,9 @@ function RenderedFlow({ nodes, edges, nodeTypes, execution, theme }: any) {
state: {
// @ts-ignore
...node.data.state,
event
}
}
event,
},
},
};
}
@@ -90,9 +90,9 @@ function RenderedFlow({ nodes, edges, nodeTypes, execution, theme }: any) {
state: {
// @ts-ignore
...node.data.state,
event: undefined
}
}
event: undefined,
},
},
}));
});
} else {
@@ -131,7 +131,7 @@ function RenderedFlow({ nodes, edges, nodeTypes, execution, theme }: any) {
fitView
fitViewOptions={{ maxZoom: 1 }}
proOptions={{
hideAttribution: true
hideAttribution: true,
}}
>
<Controls>

View File

@@ -15,11 +15,11 @@ const triggerSchemas = Object.values(
Type.Object(
{
type: Const(name),
config: trigger.cls.schema
config: trigger.cls.schema,
},
{ title: String(name), additionalProperties: false }
)
)
{ title: String(name), additionalProperties: false },
),
),
);
export function TriggerComponent({

View File

@@ -14,7 +14,7 @@ export function TaskForm({ task, onChange, ...props }: TaskFormProps) {
const uiSchema = Object.fromEntries(
Object.keys(schema.properties).map((key) => {
return [key, { "ui:field": "template", "ui:fieldReplacesAnyOrOneOf": true }];
})
}),
);
//console.log("uiSchema", uiSchema);

View File

@@ -9,14 +9,14 @@ type Mode = (typeof modes)[number];
export function TemplateField<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
F extends FormContextType = any,
>(props: FieldProps<T, S, F>) {
const formData = props.formData;
const hasMarkup = SimpleRenderer.hasMarkup(formData!);
const [mode, setMode] = useState<Mode>(hasMarkup ? "code" : "field");
const [values, setValues] = useState<Record<Mode, any>>({
field: hasMarkup ? "" : formData,
code: hasMarkup ? formData : ""
code: hasMarkup ? formData : "",
});
//console.log("TemplateField", props);
const { SchemaField } = props.registry.fields;
@@ -35,7 +35,7 @@ export function TemplateField<
let _schema: any = schema;
if (!("anyOf" in schema)) {
_schema = {
anyOf: [schema, { type: "string" }]
anyOf: [schema, { type: "string" }],
};
}
@@ -48,7 +48,7 @@ export function TemplateField<
: {
"ui:label": false,
"ui:widget": "textarea",
"ui:options": { rows: 1 }
"ui:options": { rows: 1 },
};
return (

View File

@@ -10,8 +10,8 @@ export function RenderTaskComponent(props: TaskComponentProps) {
onChange={console.log}
uiSchema={{
render: {
"ui:field": "LiquidJsField"
}
"ui:field": "LiquidJsField",
},
}}
/>
</TaskComponent>

View File

@@ -29,7 +29,7 @@ export const KeyValueInput: React.FC<KeyValueInputProps> = ({
onChange,
error,
classNames,
mode = "object"
mode = "object",
}) => {
const [items, setItems] = useState(initialValue ? toItems(initialValue) : [ITEM]);

View File

@@ -34,7 +34,7 @@ const Wrapper = ({ children, className, ...props }: ElementProps<"div">) => (
{...props}
className={twMerge(
"flex flex-row bg-lightest border ring-2 ring-muted/5 border-muted rounded-full items-center p-1",
className
className,
)}
>
{children}
@@ -71,7 +71,7 @@ const Text = forwardRef<any, ElementProps<"span"> & { mono?: boolean }>(
>
{children}
</span>
)
),
);
FlowPanel.Wrapper = Wrapper;

View File

@@ -36,7 +36,7 @@ export function BaseNode({ children, className, tabs, Icon, isInvalid, ...props
"w-96",
//props.selected && "ring-4 ring-blue-500/15",
isInvalid && "ring-8 ring-red-500/15",
className
className,
)}
>
<Header
@@ -70,7 +70,7 @@ const BaseNodeTabs = ({ tabs }: { tabs: BaseNodeProps["tabs"] }) => {
onClick={handleClick(i)}
className={twMerge(
"text-sm leading-none",
i === active ? "font-bold opacity-80" : "font-medium opacity-50"
i === active ? "font-bold opacity-80" : "font-medium opacity-50",
)}
>
{tab.label}
@@ -90,7 +90,7 @@ const Header = ({
rightSection,
initialValue,
changable = false,
onChange
onChange,
}: {
Icon: React.FC<any>;
iconProps?: ElementProps<"svg">;
@@ -129,7 +129,7 @@ const Header = ({
disabled={!changable}
onChange={handleChange}
className={twMerge(
"font-mono font-semibold bg-transparent rounded-lg outline-none pl-1.5 w-full hover:bg-lightest/30 transition-colors focus:bg-lightest/60"
"font-mono font-semibold bg-transparent rounded-lg outline-none pl-1.5 w-full hover:bg-lightest/30 transition-colors focus:bg-lightest/60",
)}
/>
) : (

View File

@@ -6,18 +6,18 @@ export function Handle(props: Omit<HandleProps, "position">) {
width: 10,
height: 10,
background: "transparent",
border: "2px solid #999"
border: "2px solid #999",
};
const offset = -10;
const styles = {
target: {
...base,
left: offset
left: offset,
},
source: {
...base,
right: offset
}
right: offset,
},
};
//console.log("type", props.type, styles[props.type]);

View File

@@ -15,15 +15,15 @@ const nodes = [
params: {
method: "GET",
headers: [],
url: ""
}
}
url: "",
},
},
},
{
type: "render",
label: "Render",
description: "Render data using LiquidJS"
}
description: "Render data using LiquidJS",
},
];
export function SelectNode(props) {
@@ -46,13 +46,13 @@ export function SelectNode(props) {
type: "task",
data: {
...node.template,
label
}
label,
},
};
}
return n;
})
}),
);
setTimeout(() => {
reactflow.setEdges((prev) =>
@@ -62,12 +62,12 @@ export function SelectNode(props) {
return {
...e,
id: "task-" + label,
target: "task-" + label
target: "task-" + label,
};
}
return e;
})
}),
);
}, 100);
@@ -92,7 +92,7 @@ export function SelectNode(props) {
key={node.type}
className={twMerge(
"border border-primary/10 rounded-md py-2 px-4 hover:bg-primary/10",
selected === node.type && "bg-primary/10"
selected === node.type && "bg-primary/10",
)}
onClick={() => setSelected(node.type)}
>

View File

@@ -5,5 +5,5 @@ import { TriggerNode } from "./triggers/TriggerNode";
export const nodeTypes = {
select: SelectNode,
trigger: TriggerNode,
task: TaskNode
task: TaskNode,
};

View File

@@ -19,8 +19,8 @@ import { BaseNode } from "../BaseNode";
const schema = Type.Composite([
FetchTask.schema,
Type.Object({
query: Type.Optional(Type.Record(Type.String(), Type.String()))
})
query: Type.Optional(Type.Record(Type.String(), Type.String())),
}),
]);
type TFetchTaskSchema = Static<typeof FetchTask.schema>;
@@ -39,11 +39,11 @@ export function FetchTaskForm({ onChange, params, ...props }: FetchTaskFormProps
getValues,
formState: { isValid, errors },
watch,
control
control,
} = useForm({
resolver: typeboxResolver(schema),
defaultValues: params as Static<typeof schema>,
mode: "onChange"
mode: "onChange",
//defaultValues: (state.relations?.create?.[0] ?? {}) as Static<typeof schema>
});
@@ -130,11 +130,11 @@ const TaskNodeTabs = ({ watch }: any) => [
<div className="scroll-auto">
<JsonViewer json={watch()} expand={2} className="bg-white break-all" />
</div>
)
),
},
{
id: "test",
label: "test",
content: () => <div>test</div>
}
content: () => <div>test</div>,
},
];

View File

@@ -11,7 +11,7 @@ registerCustomTypeboxKinds(TypeRegistry);
const TaskComponents = {
fetch: FetchTaskForm,
render: RenderNode
render: RenderNode,
};
export const TaskNode = (
@@ -24,10 +24,10 @@ export const TaskNode = (
responding?: boolean;
}
>
>
>,
) => {
const {
data: { label, start, last, responding }
data: { label, start, last, responding },
} = props;
const task = useFlowSelector((s) => s.flow!.tasks![label])!;
const { actions } = useFlowCanvas();

View File

@@ -9,7 +9,7 @@ import {
StringEnum,
Type,
registerCustomTypeboxKinds,
transformObject
transformObject,
} from "core/utils";
import { TriggerMap } from "flows";
import type { TAppFlowTriggerSchema } from "flows/AppFlows";
@@ -33,18 +33,18 @@ const schema = Type.Object({
Type.Object(
{
type: Const(name),
config: trigger.cls.schema
config: trigger.cls.schema,
},
{ title: String(name), additionalProperties: false }
)
)
)
)
{ title: String(name), additionalProperties: false },
),
),
),
),
});
export const TriggerNode = (props: NodeProps<Node<TAppFlowTriggerSchema & { label: string }>>) => {
const {
data: { label, ...trigger }
data: { label, ...trigger },
} = props;
//console.log("TriggerNode");
const state = useFlowSelector((s) => s.flow!.trigger!);
@@ -57,11 +57,11 @@ export const TriggerNode = (props: NodeProps<Node<TAppFlowTriggerSchema & { labe
getValues,
formState: { isValid, errors },
watch,
control
control,
} = useForm({
resolver: typeboxResolver(schema),
defaultValues: { trigger: state } as Static<typeof schema>,
mode: "onChange"
mode: "onChange",
});
const data = watch("trigger");
@@ -91,7 +91,7 @@ export const TriggerNode = (props: NodeProps<Node<TAppFlowTriggerSchema & { labe
data={[
{ label: "Manual", value: "manual" },
{ label: "HTTP", value: "http" },
{ label: "Event", value: "event", disabled: true }
{ label: "Event", value: "event", disabled: true },
]}
name="trigger.type"
control={control}
@@ -101,7 +101,7 @@ export const TriggerNode = (props: NodeProps<Node<TAppFlowTriggerSchema & { labe
defaultValue="async"
data={[
{ label: "Async", value: "async" },
{ label: "Sync", value: "sync" }
{ label: "Sync", value: "sync" },
]}
name="trigger.config.mode"
control={control}
@@ -148,7 +148,7 @@ const Http = ({ form }) => {
data={[
{ label: "JSON", value: "json" },
{ label: "HTML", value: "html" },
{ label: "Text", value: "text" }
{ label: "Text", value: "text" },
]}
name="trigger.config.response_type"
control={form.control}
@@ -162,11 +162,11 @@ const TriggerNodeTabs = ({ data, ...props }) => [
{
id: "json",
label: "JSON",
content: () => <JsonViewer json={data} expand={2} className="" />
content: () => <JsonViewer json={data} expand={2} className="" />,
},
{
id: "test",
label: "test",
content: () => <div>test</div>
}
content: () => <div>test</div>,
},
];

View File

@@ -41,7 +41,7 @@ export type TFlowState = {
export const flowStateAtom = atom<TFlowState>({
dirty: false,
name: undefined,
flow: undefined
flow: undefined,
});
const FlowCanvasContext = createContext<FlowContextType>(undefined!);
@@ -65,7 +65,7 @@ export function FlowCanvasProvider({ children, name }: { children: any; name?: s
setName: async (name: string) => {
console.log("set name", name);
setFlowState((state) => ({ ...state, name, dirty: true }));
}
},
},
trigger: {
update: async (trigger: TAppFlowTriggerSchema | any) => {
@@ -75,7 +75,7 @@ export function FlowCanvasProvider({ children, name }: { children: any; name?: s
return { ...state, dirty: true, flow: { ...flow, trigger } };
});
//return s.actions.patch("flows", `flows.flows.${name}`, { trigger });
}
},
},
task: {
create: async (name: string, defaults: object = {}) => {
@@ -95,12 +95,12 @@ export function FlowCanvasProvider({ children, name }: { children: any; name?: s
return {
...state,
dirty: true,
flow: { ...flow, tasks: { ...flow.tasks, [name]: task } }
flow: { ...flow, tasks: { ...flow.tasks, [name]: task } },
};
});
//return s.actions.patch("flows", `flows.flows.${name}.tasks.${name}`, task);
}
}
},
},
};
return (
@@ -120,7 +120,7 @@ export function useFlowCanvasState() {
export function useFlowSelector<Reduced = TFlowState>(
selector: (state: TFlowState) => Reduced,
equalityFn: (a: any, b: any) => boolean = isEqual
equalityFn: (a: any, b: any) => boolean = isEqual,
) {
const selected = selectAtom(flowStateAtom, useCallback(selector, []), equalityFn);
return useAtom(selected)[0];
@@ -133,8 +133,8 @@ export function flowToNodes(flow: TAppFlowSchema, name: string): Node<TFlowNodeD
data: { label: name, type: flow.trigger.type },
type: "trigger",
dragHandle: ".drag-handle",
position: { x: 0, y: 0 }
}
position: { x: 0, y: 0 },
},
];
let i = 1;
@@ -150,7 +150,7 @@ export function flowToNodes(flow: TAppFlowSchema, name: string): Node<TFlowNodeD
type: "task",
dragHandle: ".drag-handle",
// @todo: this is currently static
position: { x: 450 * i + (i - 1) * 64, y: 0 }
position: { x: 450 * i + (i - 1) * 64, y: 0 },
});
i++;
}
@@ -178,14 +178,14 @@ export function flowToEdges(flow: TAppFlowSchema) {
target: `task-${tasks[0]?.[0]}`,
//type: "smoothstep",
style: {
strokeWidth: 2
strokeWidth: 2,
},
markerEnd: {
type: MarkerType.ArrowClosed,
width: 10,
height: 10
}
}
height: 10,
},
},
]
: [];
@@ -195,13 +195,13 @@ export function flowToEdges(flow: TAppFlowSchema) {
source: "task-" + connection.source,
target: "task-" + connection.target,
style: {
strokeWidth: 2
strokeWidth: 2,
},
markerEnd: {
type: MarkerType.ArrowClosed,
width: 10,
height: 10
}
height: 10,
},
});
}

View File

@@ -2,5 +2,5 @@ import { atom } from "jotai";
const flowStateAtom = atom({
dirty: false,
flow: undefined
flow: undefined,
});

View File

@@ -29,7 +29,7 @@ export function getFlowNodes(flow: Flow): Node[] {
type: "trigger",
position: { x: 0, y: 0 },
data: { trigger: flow.trigger },
dragHandle: ".drag-handle"
dragHandle: ".drag-handle",
});
console.log("adding node", { id: "trigger" });
@@ -47,7 +47,7 @@ export function getFlowNodes(flow: Flow): Node[] {
type: task.type,
position: { x: xs[j]!, y: (i + 1) * spacing.y },
data: { task, state: { i: 0, isRespondingTask, isStartTask, event: undefined } },
dragHandle: ".drag-handle"
dragHandle: ".drag-handle",
});
});
});
@@ -63,7 +63,7 @@ export function getFlowEdges(flow: Flow): Edge[] {
edges.push({
id: `trigger-${startTask.name}${new Date().getTime()}`,
source: "trigger",
target: startTask.name
target: startTask.name,
//type: "",
});
@@ -72,7 +72,7 @@ export function getFlowEdges(flow: Flow): Edge[] {
edges.push({
id: `${c.source.name}-${c.target.name}${new Date().getTime()}`,
source: c.source.name,
target: c.target.name
target: c.target.name,
//type: "",
});
});
@@ -84,6 +84,6 @@ export function getNodeTypes(flow: Flow) {
trigger: TriggerComponent,
render: RenderTaskComponent,
log: TaskComponent,
fetch: TaskComponent
fetch: TaskComponent,
};
}