Skip to content

Commit

Permalink
Fix circular dependency in copy-manager (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
origami-z authored Feb 14, 2024
1 parent 604b639 commit af9479d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
6 changes: 3 additions & 3 deletions packages/copy-manager/plugin-src/code.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ParseResult } from "papaparse";
import {
CSV_HEADER_FIELDS,
CsvNodeInfo,
CsvNodeInfoWithLang,
CSV_HEADER_FIELDS,
DEFAULT_LANG,
PostToFigmaMessage,
PostToUIMessage,
} from "../shared-src/messages";
import {
persistInFigma,
PLUGIN_RELAUNCH_KEY_REVIEW_REVISION,
persistInFigma,
readPersistedData,
updateNodeKey,
updateNodeSelected,
Expand All @@ -21,10 +21,10 @@ import {
getNodeInfoMap,
parseCsvString,
} from "./processors/csvProcessor";
import { scanTextNodesInfo } from "./processors/textNodeInfoProcessor";
import {
DEFAULT_HEADING_SETTINGS,
focusNode,
scanTextNodesInfo,
sendTextNodesInfoToUI,
sortNodeByPosition,
} from "./utils";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ import { getNodeKey, getSelected } from "../pluginDataUtils";
import { sortNodeByPosition } from "../utils";
import { iterate } from "./iterate";

export async function scanTextNodesInfo(autoTrigger: boolean) {
if (figma.currentPage.selection.length === 0) {
if (!autoTrigger) {
figma.notify(`Please select something for scanning`);
}
return [];
}

const textNodesInfo: SelectableTextNodeInfo[] = [];

for (const selectedNode of figma.currentPage.selection) {
const info = await textNodeInfoProcessor(selectedNode, {});
textNodesInfo.push(...info);
}

return textNodesInfo;
}

export const textNodeInfoTextNodeProcess = (
node: TextNode,
settings: any
Expand Down
25 changes: 1 addition & 24 deletions packages/copy-manager/plugin-src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { PostToUIMessage, SelectableTextNodeInfo } from "../shared-src";
import {
PLUGIN_DATA_KEY_PERSISTED_DATA,
PLUGIN_DATA_SHARED_NAMESPACE,
PLUGIN_RELAUNCH_KEY_REVIEW_REVISION,
} from "./pluginDataUtils";
import { textNodeInfoProcessor } from "./processors/textNodeInfoProcessor";
import { PLUGIN_RELAUNCH_KEY_REVIEW_REVISION } from "./pluginDataUtils";

export type HeadingSettings = {
h1: number;
Expand Down Expand Up @@ -88,24 +83,6 @@ export const setRelaunchButton = (node: SceneNode) => {
node.setRelaunchData({ [PLUGIN_RELAUNCH_KEY_REVIEW_REVISION]: "" });
};

export async function scanTextNodesInfo(autoTrigger: boolean) {
if (figma.currentPage.selection.length === 0) {
if (!autoTrigger) {
figma.notify(`Please select something for scanning`);
}
return [];
}

const textNodesInfo: SelectableTextNodeInfo[] = [];

for (const selectedNode of figma.currentPage.selection) {
const info = await textNodeInfoProcessor(selectedNode, {});
textNodesInfo.push(...info);
}

return textNodesInfo;
}

export function sendTextNodesInfoToUI(nodesInfo: SelectableTextNodeInfo[]) {
figma.ui.postMessage({
type: "scan-text-node-info-result",
Expand Down

0 comments on commit af9479d

Please sign in to comment.