Skip to content

Commit 5239696

Browse files
committed
Component Context is more organized
1 parent 235df0c commit 5239696

File tree

11 files changed

+296
-203
lines changed

11 files changed

+296
-203
lines changed

src/components/commons/Glass/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export function Glass({
1515
className={`glass-card ${className}`}
1616
{...props}
1717
>
18-
<div className="glass-card-background" />
1918
{children}
2019
</div>
2120
</>);

src/components/commons/Glass/style.css

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,5 @@
44
background: #7f7f7f88;
55
border: 0.25rem solid #ffffff1a;
66
border-radius: 1rem;
7-
box-shadow: 0 0 2rem 1rem #0000004d;
8-
}
9-
10-
.glass-card-background {
11-
position: absolute;
12-
width: 100%;
13-
height: 100%;
14-
top: 0;
15-
left: 0;
16-
color: inherit;
17-
opacity: 0.4;
18-
border-radius: calc(var(--icon-size) / 2 - 0.25rem);
19-
filter: blur(0.5rem);
207
}
218

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { NodeModel } from "@defs/Node"
2+
3+
import "./style.css";
4+
5+
export function DecorativeNode({
6+
node,
7+
}: {
8+
node: NodeModel;
9+
}) {
10+
return (<>
11+
<div className="decorative-node">
12+
<span className="decorative-node-name">{node.name}</span>
13+
</div>
14+
</>);
15+
}
16+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.decorative-node {
2+
grid-column: 1 / -1;
3+
margin-top: 0.5rem;
4+
}
5+
6+
.decorative-node:first-child {
7+
margin-top: 0;
8+
}
9+

src/components/engine/Node/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DynamicIcon } from "@components/commons/DynamicIcon";
99
import { Glass } from "@components/commons/Glass";
1010

1111
import { NodeContext } from "@components/engine/NodeContext";
12+
import { DecorativeNode } from "@components/engine/DecorativeNode";
1213

1314
import "./style.css";
1415

@@ -28,6 +29,8 @@ export function Node({
2829
else setActive(prev => !prev);
2930
}, [node]);
3031

32+
if (node.isDecorative) return <DecorativeNode node={node} />;
33+
3134
return (<>
3235
<div className="node-wrapper">
3336
<Glass

src/components/engine/Node/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
.node:hover > .node-name {
7171
opacity: 1;
7272
translate: 0;
73+
z-index: 10;
7374
}
7475

7576
.node-pointer {

src/components/engine/NodeContext/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function NodeContext({
3131
>
3232
{
3333
context?.map((contextNode => <Node
34-
key={contextNode.name}
34+
key={contextNode.id}
3535
node={contextNode}
3636
/>))
3737
}

src/components/engine/NodeContext/style.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
padding: 1rem;
66
cursor: default;
77
display: grid;
8-
grid-template-columns: repeat(5, 3.5rem);
8+
grid-template-columns: repeat(5, 1fr);
99
gap: 0.5rem;
1010
transform: translateX(-50%) translateY(-50%) scale(0);
1111
opacity: 0;
@@ -22,6 +22,9 @@
2222
.node-context.side {
2323
left: calc(100% + 2rem);
2424
top: 50%;
25+
max-height: 50vh;
26+
overflow-y: auto;
27+
overflow-x: hidden;
2528
}
2629

2730
.node.active + .node-context.side {

src/contexts/nodeFactory.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const createNodeFactoryContext = () => {
8080
color: "black",
8181
context: [
8282
nodeTemplate(baseId, {
83+
id: `ANN:BASE:${baseId}`,
8384
name: "Base Node",
8485
code: "base",
8586
icon: "Atom",
@@ -91,10 +92,30 @@ const createNodeFactoryContext = () => {
9192
name: "Components",
9293
icon: "Shapes",
9394
color: "black",
94-
context: componentLib.map(component => nodeTemplate(
95-
baseId,
96-
component,
97-
)),
95+
context: componentLib.sort(
96+
(
97+
a: { order?: number },
98+
b: { order?: number },
99+
) => a.order! - b.order!
100+
).reduce((
101+
acc: NodeModel[],
102+
curr: {
103+
name: string;
104+
icon: string;
105+
color: string;
106+
nodes: NodeModel[];
107+
}
108+
) => [
109+
...acc,
110+
{
111+
id: `ANN:CMP:SECTION:${curr.name}`,
112+
name: curr.name,
113+
color: curr.color,
114+
icon: curr.icon,
115+
isDecorative: true,
116+
},
117+
...curr.nodes.map(node => nodeTemplate(baseId, node)),
118+
], [])
98119
},
99120
{
100121
id: "ANN:CCMP",
@@ -103,6 +124,7 @@ const createNodeFactoryContext = () => {
103124
color: "black",
104125
context: [
105126
{
127+
id: "ANN:CCMP:ADD",
106128
name: "Add Custom Component",
107129
icon: "Plus",
108130
color: "black",
@@ -111,6 +133,7 @@ const createNodeFactoryContext = () => {
111133
...customComponents.map(component => nodeTemplate(
112134
baseId,
113135
{
136+
id: `ANN:CCMP:${component.name}`,
114137
name: component.name,
115138
code: component.name,
116139
icon: "Component",
@@ -126,6 +149,7 @@ const createNodeFactoryContext = () => {
126149
color: "black",
127150
context: [
128151
{
152+
id: "ANN:STATES:ADD",
129153
name: "Add State",
130154
icon: "Plus",
131155
color: "black",
@@ -134,6 +158,7 @@ const createNodeFactoryContext = () => {
134158
...statesList.map(state => nodeTemplate(
135159
baseId,
136160
{
161+
id: `ANN:STATES:${state.name}`,
137162
name: state.name,
138163
code: state.name,
139164
icon: "Puzzle",

src/defs/Node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface NodeModel {
1111
baseType?: string;
1212
isBase?: boolean;
1313
isTopLevel?: boolean;
14+
isDecorative?: boolean;
1415
}
1516

1617
export type NodeGroup = {

0 commit comments

Comments
 (0)