Skip to content

Commit

Permalink
Merge pull request #265 from tokens-studio/fix-flatten-sets
Browse files Browse the repository at this point in the history
Fix flatten node
  • Loading branch information
roppazvan authored Jun 12, 2024
2 parents 9cf20bb + f58af89 commit c5ced6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions packages/graph-editor/src/hooks/useIsValidConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ export const useIsValidConnection = ({
}

const strippedVariadic = stripVariadic(connection.targetHandle!);

let targetType = target?.inputs[strippedVariadic].type!;
const sourceType = source?.outputs[connection.sourceHandle!].type!;
let sourceType = source?.outputs[connection.sourceHandle!].type!;

//Check if the target is variadic
if (target.inputs[strippedVariadic].variadic) {
if (target.inputs[strippedVariadic].type.items) {
targetType = target.inputs[strippedVariadic].type.items;
}
if (source.outputs[connection.sourceHandle!].type.items) {
sourceType = source.outputs[connection.sourceHandle!].type.items;
}

const canConvert = canConvertSchemaTypes(sourceType, targetType);

Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-design-tokens/src/nodes/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class FlattenNode extends Node {
super(props);
this.addInput("tokens", {
type: {
...createVariadicSchema(TokenSetSchema),
...createVariadicSchema(TokenSchema),
default: [],
},
variadic: true,
Expand Down
7 changes: 5 additions & 2 deletions packages/nodes-design-tokens/src/ui/controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { TokenArrayField } from "./tokenSet.js"
import { TokenField } from "./token.js"
import { VariadicTokenSet } from "./variadicTokenSet.js"
import { variadicMatcher } from "@tokens-studio/graph-editor"
import type { Port } from "@tokens-studio/graph-engine"
import type { Input, Port } from "@tokens-studio/graph-engine"

export const controls = [{
matcher: (port: Port) => port.type.type === 'array' && port.type.items?.$id === TOKEN,
matcher: (port: Port) => {
const inputPort = port as Input;
return inputPort.type.type === 'array' && inputPort.type.items?.$id === TOKEN && !inputPort.variadic
},
component: TokenArrayField,
},
{
Expand Down

0 comments on commit c5ced6d

Please sign in to comment.