Skip to content

Commit

Permalink
feat: allow component metadata storage (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
Traveller23 authored Feb 29, 2024
1 parent d07899b commit 246fa3c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-onions-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@craftjs/core': patch
---

Add a property `info` to `UserComponent`, which will be copied to `Node`, but will not be serialized.
2 changes: 2 additions & 0 deletions packages/core/src/interfaces/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type UserComponentConfig<T> = {
related: Partial<NodeRelated>;
props: Partial<T>;
custom: Record<string, any>;
info: Record<string, any>;
isCanvas: boolean;

// TODO: Deprecate
Expand All @@ -26,6 +27,7 @@ export type NodeEventTypes = 'selected' | 'dragged' | 'hovered';
export type Node = {
id: NodeId;
data: NodeData;
info: Record<string, any>;
events: Record<NodeEventTypes, boolean>;
dom: HTMLElement | null;
related: Record<string, React.ElementType>;
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/utils/createNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function createNode(
linkedNodes: {},
...newNode.data,
},
info: {},
related: {},
events: {
selected: false,
Expand Down Expand Up @@ -136,6 +137,10 @@ export function createNode(
);
});
}

if (userComponentConfig.info) {
node.info = userComponentConfig.info;
}
}

return node;
Expand Down

0 comments on commit 246fa3c

Please sign in to comment.