-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/custom-preview
- Loading branch information
Showing
19 changed files
with
297 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tokens-studio/graph-engine-ui": patch | ||
--- | ||
|
||
Add utils css to fix visuals |
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,5 @@ | ||
--- | ||
"@tokens-studio/graph-engine": minor | ||
--- | ||
|
||
Adds a new array node that removes an item at a specified index and returns both the modified array and the removed item. Supports both positive and negative indices for flexible array manipulation. |
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,5 @@ | ||
--- | ||
"@tokens-studio/graph-engine-nodes-design-tokens": minor | ||
--- | ||
|
||
Added array group/ungroup nodes for token arrays |
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,54 @@ | ||
import { AnyArraySchema, NumberSchema } from '../../schemas/index.js'; | ||
import { INodeDefinition, ToInput, ToOutput } from '../../index.js'; | ||
import { Node } from '../../programmatic/node.js'; | ||
|
||
export default class NodeDefinition<T> extends Node { | ||
static title = 'Remove Item'; | ||
static type = 'studio.tokens.array.remove'; | ||
static description = | ||
'Removes an item from an array at a specified index and returns both the modified array and the removed item.'; | ||
|
||
declare inputs: ToInput<{ | ||
array: T[]; | ||
index: number; | ||
}>; | ||
|
||
declare outputs: ToOutput<{ | ||
array: T[]; | ||
item: T; | ||
}>; | ||
|
||
constructor(props: INodeDefinition) { | ||
super(props); | ||
this.addInput('array', { | ||
type: AnyArraySchema | ||
}); | ||
this.addInput('index', { | ||
type: NumberSchema | ||
}); | ||
this.addOutput('array', { | ||
type: AnyArraySchema | ||
}); | ||
this.addOutput('item', { | ||
type: AnyArraySchema.items | ||
}); | ||
} | ||
|
||
execute(): void | Promise<void> { | ||
const { index, array } = this.getAllInputs(); | ||
const arrayType = this.inputs.array.type; | ||
|
||
// Create a copy and remove item if index is valid | ||
const result = [...array]; | ||
const [removedItem] = | ||
index >= -result.length && index < result.length | ||
? result.splice(index, 1) | ||
: []; | ||
|
||
// Set the outputs | ||
this.outputs.array.set(result, arrayType); | ||
if (removedItem !== undefined) { | ||
this.outputs.item.set(removedItem, arrayType.items); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/graph-engine/tests/suites/nodes/array/remove.test.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Graph } from '../../../../src/graph/graph.js'; | ||
import { describe, expect, test } from 'vitest'; | ||
import Node from '../../../../src/nodes/array/remove.js'; | ||
|
||
describe('array/remove', () => { | ||
test('removes an item at a positive index', async () => { | ||
const graph = new Graph(); | ||
const node = new Node({ graph }); | ||
|
||
node.inputs.array.setValue([1, 2, 3, 4, 5]); | ||
node.inputs.index.setValue(2); | ||
|
||
await node.execute(); | ||
|
||
expect(node.outputs.array.value).to.eql([1, 2, 4, 5]); | ||
expect(node.outputs.item.value).to.eql(3); | ||
}); | ||
|
||
test('removes an item at a negative index', async () => { | ||
const graph = new Graph(); | ||
const node = new Node({ graph }); | ||
|
||
node.inputs.array.setValue(['a', 'b', 'c', 'd']); | ||
node.inputs.index.setValue(-2); | ||
|
||
await node.execute(); | ||
|
||
expect(node.outputs.array.value).to.eql(['a', 'b', 'd']); | ||
expect(node.outputs.item.value).to.eql('c'); | ||
}); | ||
|
||
test('does not modify array when index is out of bounds', async () => { | ||
const graph = new Graph(); | ||
const node = new Node({ graph }); | ||
|
||
node.inputs.array.setValue([1, 2, 3]); | ||
node.inputs.index.setValue(5); | ||
|
||
await node.execute(); | ||
|
||
expect(node.outputs.array.value).to.eql([1, 2, 3]); | ||
expect(node.outputs.item.value).to.be.undefined; | ||
}); | ||
|
||
test('does not mutate the original array', async () => { | ||
const graph = new Graph(); | ||
const node = new Node({ graph }); | ||
|
||
const originalArray = [1, 2, 3, 4]; | ||
node.inputs.array.setValue(originalArray); | ||
node.inputs.index.setValue(1); | ||
|
||
await node.execute(); | ||
|
||
expect(originalArray).to.eql([1, 2, 3, 4]); | ||
}); | ||
}); |
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,48 @@ | ||
import { | ||
INodeDefinition, | ||
Node, | ||
StringSchema, | ||
ToInput, | ||
ToOutput | ||
} from '@tokens-studio/graph-engine'; | ||
import { TokenSchema } from '../../schemas/index.js'; | ||
import { arrayOf } from '../../schemas/utils.js'; | ||
import type { SingleToken } from '@tokens-studio/types'; | ||
|
||
export default class GroupArrayNode extends Node { | ||
static title = 'Group token array'; | ||
static type = 'studio.tokens.design.array.group'; | ||
static description = 'Groups an array of tokens by adding a namespace'; | ||
|
||
declare inputs: ToInput<{ | ||
name: string; | ||
tokens: SingleToken[]; | ||
}>; | ||
|
||
declare outputs: ToOutput<{ | ||
tokens: SingleToken[]; | ||
}>; | ||
|
||
constructor(props: INodeDefinition) { | ||
super(props); | ||
this.addInput('name', { | ||
type: StringSchema | ||
}); | ||
this.addInput('tokens', { | ||
type: arrayOf(TokenSchema) | ||
}); | ||
this.addOutput('tokens', { | ||
type: arrayOf(TokenSchema) | ||
}); | ||
} | ||
|
||
execute(): void | Promise<void> { | ||
const { name, tokens } = this.getAllInputs(); | ||
const output = tokens.map(token => ({ | ||
...token, | ||
name: `${name}.${token.name}` | ||
})); | ||
|
||
this.outputs.tokens.set(output); | ||
} | ||
} |
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,4 @@ | ||
import GroupArrayNode from './group.js'; | ||
import UngroupArrayNode from './ungroup.js'; | ||
|
||
export const nodes = [GroupArrayNode, UngroupArrayNode]; |
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,53 @@ | ||
import { | ||
INodeDefinition, | ||
Node, | ||
StringSchema, | ||
ToInput, | ||
ToOutput | ||
} from '@tokens-studio/graph-engine'; | ||
import { TokenSchema } from '../../schemas/index.js'; | ||
import { arrayOf } from '../../schemas/utils.js'; | ||
import type { SingleToken } from '@tokens-studio/types'; | ||
|
||
export default class UngroupArrayNode extends Node { | ||
static title = 'Ungroup token array'; | ||
static type = 'studio.tokens.design.array.ungroup'; | ||
static description = | ||
'Ungroups an array of tokens by removing their namespace'; | ||
|
||
declare inputs: ToInput<{ | ||
name: string; | ||
tokens: SingleToken[]; | ||
}>; | ||
|
||
declare outputs: ToOutput<{ | ||
tokens: SingleToken[]; | ||
}>; | ||
|
||
constructor(props: INodeDefinition) { | ||
super(props); | ||
this.addInput('name', { | ||
type: StringSchema | ||
}); | ||
this.addInput('tokens', { | ||
type: arrayOf(TokenSchema) | ||
}); | ||
this.addOutput('tokens', { | ||
type: arrayOf(TokenSchema) | ||
}); | ||
} | ||
|
||
execute(): void | Promise<void> { | ||
const { name, tokens } = this.getAllInputs(); | ||
const prefix = `${name}.`; | ||
|
||
const output = tokens | ||
.filter(token => token.name.startsWith(prefix)) | ||
.map(token => ({ | ||
...token, | ||
name: token.name.slice(prefix.length) | ||
})); | ||
|
||
this.outputs.tokens.set(output); | ||
} | ||
} |
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,25 @@ | ||
import { Graph } from '@tokens-studio/graph-engine'; | ||
import { SingleToken } from '@tokens-studio/types'; | ||
import { describe, expect, it } from 'vitest'; | ||
import GroupArrayNode from '../../src/nodes/arrays/group.js'; | ||
|
||
describe('GroupArrayNode', () => { | ||
it('should add namespace to token names', async () => { | ||
const graph = new Graph(); | ||
const node = new GroupArrayNode({ graph }); | ||
|
||
const tokens = [ | ||
{ name: 'color', value: '#ff0000', type: 'color' }, | ||
{ name: 'size', value: '16px', type: 'dimension' } | ||
] as SingleToken[]; | ||
|
||
node.inputs.name.setValue('theme'); | ||
node.inputs.tokens.setValue(tokens); | ||
await node.execute(); | ||
|
||
expect(node.outputs.tokens.value).toEqual([ | ||
{ name: 'theme.color', value: '#ff0000', type: 'color' }, | ||
{ name: 'theme.size', value: '16px', type: 'dimension' } | ||
]); | ||
}); | ||
}); |
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,26 @@ | ||
import { Graph } from '@tokens-studio/graph-engine'; | ||
import { SingleToken } from '@tokens-studio/types'; | ||
import { describe, expect, it } from 'vitest'; | ||
import UngroupArrayNode from '../../src/nodes/arrays/ungroup.js'; | ||
|
||
describe('UngroupArrayNode', () => { | ||
it('should remove namespace from token names', async () => { | ||
const graph = new Graph(); | ||
const node = new UngroupArrayNode({ graph }); | ||
|
||
const tokens = [ | ||
{ name: 'theme.color', value: '#ff0000', type: 'color' }, | ||
{ name: 'theme.size', value: '16px', type: 'dimension' }, | ||
{ name: 'other.value', value: '20px', type: 'dimension' } | ||
] as SingleToken[]; | ||
|
||
node.inputs.name.setValue('theme'); | ||
node.inputs.tokens.setValue(tokens); | ||
await node.execute(); | ||
|
||
expect(node.outputs.tokens.value).toEqual([ | ||
{ name: 'color', value: '#ff0000', type: 'color' }, | ||
{ name: 'size', value: '16px', type: 'dimension' } | ||
]); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -6147,10 +6147,10 @@ | |
resolved "https://registry.yarnpkg.com/@tokens-studio/types/-/types-0.5.1.tgz#5037e58c4b2c306762f12e8d9685e9aeebb21685" | ||
integrity sha512-LdCF9ZH5ej4Gb6n58x5fTkhstxjXDZc1SWteMWY6EiddLQJVONMIgYOrWrf1extlkSLjagX8WS0B63bAqeltnA== | ||
|
||
"@tokens-studio/ui@^1.0.10": | ||
version "1.0.10" | ||
resolved "https://registry.yarnpkg.com/@tokens-studio/ui/-/ui-1.0.10.tgz#8529bfaae9f663e6d0683b03ae2b5f0135c643f2" | ||
integrity sha512-FJCzMg9geaYWWpfxsGRTxGyDDE+IIExAE05ek78ljz3R5BftgGafnS3plLx5sMBPLN61k2aMUBiJah2bW1PBIQ== | ||
"@tokens-studio/ui@^1.0.13": | ||
version "1.0.13" | ||
resolved "https://registry.yarnpkg.com/@tokens-studio/ui/-/ui-1.0.13.tgz#e4e7356b2cbfa506f871227d4b21a35607fd09b1" | ||
integrity sha512-KvFBpWpWtShnsXXPyLU4xsMYI3Hws1A9N4IIbqOMbv7hpihcixktF81yq44txPkvn8JNw1xob9ZhofqDa1cwwg== | ||
dependencies: | ||
"@radix-ui/react-accordion" "^1.1.2" | ||
"@radix-ui/react-avatar" "^1.0.2" | ||
|
@@ -6169,7 +6169,6 @@ | |
"@radix-ui/react-toast" "^1.1.3" | ||
"@radix-ui/react-toggle-group" "^1.0.2" | ||
"@radix-ui/react-tooltip" "^1.0.4" | ||
"@tokens-studio/icons" "^0.1.4" | ||
clsx "^2.1.1" | ||
|
||
"@trysound/[email protected]": | ||
|