MCPcopy Index your code
hub / github.com/bernaferrari/FigmaToCode / standardMode

Function standardMode

apps/plugin/plugin-src/code.ts:134–243  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

132};
133
134const standardMode = async () => {
135 console.log("[DEBUG] standardMode - Starting standard mode initialization");
136 figma.showUI(__html__, { width: 450, height: 700, themeColors: true });
137 let initialized = false;
138 const initializeOnce = async () => {
139 if (initialized) {
140 return;
141 }
142 initialized = true;
143 await initSettings();
144 };
145
146 // Listen for selection changes
147 figma.on("selectionchange", () => {
148 console.log(
149 "[DEBUG] selectionchange event - New selection count:",
150 figma.currentPage.selection.length,
151 );
152 safeRun(userPluginSettings);
153 });
154
155 // Listen for page changes
156 figma.loadAllPagesAsync();
157 figma.on("documentchange", () => {
158 console.log("[DEBUG] documentchange event triggered");
159 // Node: This was causing an infinite load when you try to export a background image from a group that contains children.
160 // The reason for this is that the code will temporarily hide the children of the group in order to export a clean image
161 // then restores the visibility of the children. This constitutes a document change so it's restarting the whole conversion.
162 // In order to stop this, we disable safeRun() when doing conversions (while isLoading === true).
163 safeRun(userPluginSettings);
164 });
165
166 figma.ui.onmessage = async (msg) => {
167 console.log(
168 "[DEBUG] figma.ui.onmessage",
169 msg?.type ? `type=${msg.type}` : "unknown type",
170 );
171
172 if (msg.type === "ui-ready") {
173 await initializeOnce();
174 } else if (msg.type === "pluginSettingWillChange") {
175 const { key, value } = msg as SettingWillChangeMessage<unknown>;
176 console.log(`[DEBUG] Setting changed: ${key} = ${value}`);
177 (userPluginSettings as any)[key] = value;
178 figma.clientStorage.setAsync("userPluginSettings", userPluginSettings);
179 safeRun(userPluginSettings);
180 } else if (msg.type === "get-selection-json") {
181 console.log("[DEBUG] get-selection-json message received");
182
183 const nodes = figma.currentPage.selection;
184 if (nodes.length === 0) {
185 figma.ui.postMessage({
186 type: "selection-json",
187 data: { message: "No nodes selected" },
188 });
189 return;
190 }
191 const result: {

Callers 1

code.tsFile · 0.85

Calls 3

nodesToJSONFunction · 0.90
safeRunFunction · 0.85
initializeOnceFunction · 0.85

Tested by

no test coverage detected