Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions packages/tokens-studio-for-figma/src/plugin/SharedDataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@ class SharedDataHandler {
}

keys(node: BaseNode) {
return node.getSharedPluginDataKeys(this.namespace);
try {
return node.getSharedPluginDataKeys(this.namespace);
} catch (e) {
console.error('Error getting shared plugin data keys', e);
return [];
}
}

get<Result = string>(node: BaseNode, key: string, transformer?: (value: string) => Result) {
const value = node.getSharedPluginData(this.namespace, key);
if (value) {
return (transformer ? transformer(value) : value) as Result;
try {
const value = node.getSharedPluginData(this.namespace, key);
if (value) {
return (transformer ? transformer(value) : value) as Result;
}
return value;
} catch (e) {
console.error('Error getting shared plugin data', e);
return null;
}
return value;
}

getAll<Result = string>(node: BaseNode) {
Expand All @@ -43,7 +53,12 @@ class SharedDataHandler {
}

set(node: BaseNode, key: string, value: string) {
return node.setSharedPluginData(this.namespace, key, value);
try {
return node.setSharedPluginData(this.namespace, key, value);
} catch (e) {
console.error('Error setting shared plugin data', e);
return null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StyleIdMap, StyleThemeMap } from '@/types/StyleIdMap';
// Goes through all styleable properties of a node and swaps the style - this traverses the whole tree of a node
export async function applySiblingStyleId(node: BaseNode, styleIds: StyleIdMap, styleMap: StyleThemeMap, activeThemes: string[]) {
try {
if (node.removed) return;
switch (node.type) {
// Text layers can have stroke, effects and fill styles.
case 'TEXT':
Expand Down Expand Up @@ -80,7 +81,7 @@ export async function applySiblingStyleId(node: BaseNode, styleIds: StyleIdMap,
node.effectStyleId = newEffectStyleId;
}
if (['COMPONENT', 'COMPONENT_SET', 'SECTION', 'INSTANCE', 'FRAME', 'SLOT', 'BOOLEAN_OPERATION'].includes(node.type) && 'children' in node) {
await Promise.all(node.children.map((child) => applySiblingStyleId(child, styleIds, styleMap, activeThemes)));
await Promise.all(node.children.filter((child) => !child.removed).map((child) => applySiblingStyleId(child, styleIds, styleMap, activeThemes)));
}
}
break;
Expand Down
Loading