Skip to content

Commit afc543a

Browse files
committed
fix: omg I can't believe everything works
Signed-off-by: Saulo Vallory <me@saulo.engineer>
1 parent b123fa6 commit afc543a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2673
-5759
lines changed

packages/plugma/.cursor/rules/code-style.mdc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Preferences regarding code style
33
globs: *.ts,*.js,*.svelte,*.tsx
44
---
55
- Your notes folder is `.claude-notes` (at the root of the workspace or projects in monorepos) is yours to use. Only you will ever read the contents in there. Use it to store plans, task lists, notes, learnings, and important reminders for you.
6-
- Always use "~~~" for code blocks inside markdown files
6+
- When your response contains the code of a markdown file, code blocks inside said markdown file MUST use "~~~"
77
- when importing node native modules, like fs or url, always prepend them with 'node:', like in 'node:fs' and 'node:url'
88
- Always document exported functions, classes, types, etc with a robust TSDoc comment. Also document complex functions, even if not exported.
99
- Use "for ... of" loops instead `.forEach`.

packages/plugma/.cursorrules

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- Your notes folder is `.claude-notes` (at the root of the workspace or projects in monorepos) is yours to use. Only you will ever read the contents in there. Use it to store plans, task lists, notes, learnings, and important reminders for you.
2-
- Always use "~~~" for NESTED code blocks
2+
- When your response contains the code of a markdown file, code blocks inside said markdown file MUST use "~~~"
33
- when importing node native modules, like fs or url, always prepend them with 'node:', like in 'node:fs' and 'node:url'
44
- Always document exported functions, classes, types, etc with a robust TSDoc comment. Also document complex functions, even if not exported.
55
- Use "for ... of" loops instead `.forEach`.

packages/plugma/apps/dev-server/App.svelte

+14-7
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
let message = null;
1717
let isWebsocketServerActive = false;
1818
let isWebsocketsEnabled = window.runtimeData.websockets || false;
19+
let isServerActive = false;
1920
20-
// let ws = new WebSocket('ws://localhost:9001/ws')
2121
let ws = setupWebSocket(null, window.runtimeData.websockets, true);
2222
let url = `http://localhost:${window.runtimeData.port}`;
2323
@@ -215,8 +215,6 @@
215215
isWebsocketServerActive = false;
216216
});
217217
218-
let isServerActive = true;
219-
220218
$: monitorUrl(url, null, (isActive) => {
221219
isServerActive = isActive;
222220
});
@@ -269,13 +267,22 @@
269267
{#if !(isInsideIframe || isInsideFigma)}
270268
{#if isServerActive}
271269
{#if !isWebsocketsEnabled}
272-
<ServerStatus message="Websockets disababled"></ServerStatus>
270+
<ServerStatus
271+
message="Websockets disababled"
272+
isConnected={isServerActive && isWebsocketServerActive}
273+
/>
273274
{:else if !isWebsocketServerActive}
274-
<ServerStatus message="Connecting to websocket server..."></ServerStatus>
275+
<ServerStatus
276+
message="Connecting to websocket server..."
277+
isConnected={isServerActive && isWebsocketServerActive}
278+
/>
275279
{:else if $pluginWindowClients.length < 1}
276-
<ServerStatus message="Open plugin inside Figma"></ServerStatus>
280+
<ServerStatus
281+
message="Open plugin inside Figma"
282+
isConnected={isServerActive && isWebsocketServerActive}
283+
/>
277284
{/if}
278285
{:else}
279-
<ServerStatus></ServerStatus>
286+
<ServerStatus isConnected={isServerActive && isWebsocketServerActive} />
280287
{/if}
281288
{/if}

packages/plugma/apps/dev-server/main.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import App from './App.svelte';
22

3-
if (!PLUGMA_APP_NAME) {
4-
throw new Error('PLUGMA_APP_NAME environment variable is not defined');
5-
}
3+
// if (!PLUGMA_APP_NAME) {
4+
// throw new Error('PLUGMA_APP_NAME environment variable is not defined');
5+
// }
66

77
const app = new App({
88
// biome-ignore lint/style/noNonNullAssertion: <explanation>

packages/plugma/apps/figma-bridge/main.js

-12
This file was deleted.

packages/plugma/apps/figma-bridge/main.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import App from './App.svelte';
22
import "./app.css";
33

4-
if (!PLUGMA_APP_NAME) {
5-
throw new Error('PLUGMA_APP_NAME environment variable is not defined');
6-
}
4+
// if (!PLUGMA_APP_NAME) {
5+
// throw new Error('PLUGMA_APP_NAME environment variable is not defined');
6+
// }
77

88
const app = new App({
99
// biome-ignore lint/style/noNonNullAssertion: <explanation>

packages/plugma/apps/index.html

-2
This file was deleted.

packages/plugma/apps/main.ts

-12
This file was deleted.

packages/plugma/apps/plugma-runtime/figma-api-interceptors/custom-show-ui.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ export function customShowUI(
3737

3838
const zoom = figma.viewport.zoom;
3939
options.position = {
40-
x: figma.viewport.bounds.x + 12 / zoom,
41-
y:
42-
figma.viewport.bounds.y +
43-
(figma.viewport.bounds.height - (80 + 12) / zoom),
40+
x: figma.viewport.bounds.x + (12 / zoom),
41+
y: figma.viewport.bounds.y + (figma.viewport.bounds.height - ((80 + 12) / zoom))
4442
};
4543
}
4644

packages/plugma/apps/plugma-runtime/figma-api-interceptors/figma-api.d.ts

-10
This file was deleted.

packages/plugma/apps/plugma-runtime/handlers/delete-root-pluginData.ts

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Global runtime data
3-
* Vite will inject the runtimeData object below
4-
*/
5-
/*--[ RUNTIME_DATA ]--*/
61
/**
72
* Handles deletion of all plugin data from the root node
83
*/
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@index('./*', f => `export * from '${f.path}.js';`)
1+
//@index('./!(*.test).*', f => `export * from '${f.path}.js';`)
22
export * from './delete-client-storage.js';
33
export * from './delete-file-storage.js';
44
export * from './delete-root-pluginData.js';
@@ -8,6 +8,5 @@ export * from './maximize-window.js';
88
export * from './minimize-window.js';
99
export * from './save-on-run-messages.js';
1010
export * from './save-window-settings.js';
11-
export * from './save-window-settings.test.js';
1211
export * from './setup.js';
1312
//@endindex

packages/plugma/apps/plugma-runtime/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,22 @@ import {
1919
handleMinimizeWindow,
2020
handleSaveWindowSettings
2121
} from './handlers/index.js';
22+
2223
import type { PlugmaRuntimeData } from './types.js';
2324

2425
// NOTE: the comment must come after the declare stmt
2526
// otherwise tsc will remove it
2627
export declare const runtimeData: PlugmaRuntimeData;
2728

29+
/**
30+
* Global runtime data
31+
* Vite will inject the runtimeData object below
32+
* DO NOT REMOVE THE COMMENT BELOW! IT IS A VITE INJECTION POINT
33+
*/
34+
/*--[ RUNTIME_DATA ]--*/
35+
36+
export * from './figma-api-interceptors';
37+
2838
/**
2939
* Map of event handlers for window management
3040
*/

packages/plugma/apps/plugma-runtime/plugma-runtime.ts

-48
This file was deleted.

packages/plugma/apps/plugma-runtime/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { PluginOptions } from '#core/types.js';
1+
import type { PlugmaCommand, PlugmaRuntimeData } from '#core/types.js';
22

3-
export type PlugmaRuntimeData = PluginOptions;
3+
export type { PlugmaRuntimeData };
44

55
/**
66
* Interface for window settings that can be persisted
@@ -18,7 +18,7 @@ export interface WindowSettings {
1818
}
1919

2020
export interface CommandHistory {
21-
previousCommand: 'dev' | 'preview' | 'test' | null;
21+
previousCommand: PlugmaCommand | null;
2222
previousInstanceId: string | null;
2323
}
2424

packages/plugma/apps/plugma-runtime/utils/get-command-history.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ export async function getCommandHistory(): Promise<CommandHistory> {
2424
const previousCommand = commandHistory.previousCommand;
2525
const previousInstanceId = commandHistory.previousInstanceId;
2626

27-
// Update command history
28-
commandHistory.previousCommand = runtimeData.command
29-
? runtimeData.command === 'build'
30-
? null
31-
: runtimeData.command
32-
: null;
27+
// Set the current command as the new previous command for future retrievals
28+
commandHistory.previousCommand = runtimeData.command ?? null;
3329
commandHistory.previousInstanceId = runtimeData.instanceId;
3430
await figma.clientStorage.setAsync('PLUGMA_COMMAND_HISTORY', commandHistory);
3531

packages/plugma/apps/plugma-runtime/utils/get-window-settings.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const DEFAULT_WINDOW_SETTINGS: {
3131
test: defaultSettings,
3232
} as const;
3333

34+
const TOOLBAR_HEIGHT = 41;
35+
3436
/**
3537
* Retrieves window settings from client storage based on the current command mode.
3638
* @param options - Optional UI options that may override stored settings
@@ -76,8 +78,8 @@ export async function getWindowSettings(
7678
pluginWindowSettings.height = 300;
7779
pluginWindowSettings.width = 400;
7880

79-
if (pluginWindowSettings?.toolbarEnabled) {
80-
pluginWindowSettings.height = 341; // 300 + 41 (toolbar height)
81+
if (pluginWindowSettings.toolbarEnabled) {
82+
pluginWindowSettings.height += TOOLBAR_HEIGHT;
8183
}
8284
}
8385

packages/plugma/apps/plugma-runtime/vite.config.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@ export default defineConfig({
1414
rollupOptions: {
1515
output: {
1616
inlineDynamicImports: true,
17+
// Prevents generating export default
18+
exports: 'named'
1719
}
1820
},
21+
target: 'es6',
1922
outDir: 'dist', // Vite default output directory
2023
minify: false,
2124
sourcemap: false,
22-
emptyOutDir: true,
25+
emptyOutDir: false,
2326
},
2427
plugins: [
2528
gatherBuildOutputs({
26-
sourceDir: `dist`,
27-
outputDir: '../../dist/apps',
28-
// getOutputPath: (file) => path.join('plugma-runtime', file),
29-
removeSourceDir: true,
29+
from: `dist`,
30+
to: '../../dist/apps',
31+
transformPath: (file) => file.replace('.cjs', '.js'),
32+
removeSource: false,
3033
})
3134
],
3235
});

packages/plugma/apps/shared/components/ServerStatus.svelte

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
<script lang="ts">
2-
export let message: string | null = null
2+
export let message: string | null = null;
3+
export let isConnected: boolean = false;
4+
5+
$: displayMessage = isConnected
6+
? message || "Dev server active"
7+
: "Dev server inactive";
38
</script>
49

510
<div id="plugma-status" class="container">
611
<div class="panel">
7-
<div class="server-not-active">
8-
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
12+
<div class="server-status" class:active={isConnected}>
13+
<svg
14+
width="32"
15+
height="32"
16+
viewBox="0 0 32 32"
17+
fill="none"
18+
xmlns="http://www.w3.org/2000/svg"
19+
>
920
<path
1021
fill-rule="evenodd"
1122
clip-rule="evenodd"
@@ -14,11 +25,7 @@
1425
fill-opacity="0.8"
1526
/>
1627
</svg>
17-
{#if message}
18-
{message}
19-
{:else}
20-
<p>Dev server inactive</p>
21-
{/if}
28+
<p>{displayMessage}</p>
2229
</div>
2330
</div>
2431
</div>
@@ -43,15 +50,19 @@
4350
font-display: optional;
4451
font-size: 12px;
4552
box-sizing: border-box;
46-
/* 11/16 */
4753
justify-content: center;
4854
align-items: center;
4955
height: 100%;
5056
}
5157
52-
.server-not-active {
58+
.server-status {
5359
display: flex;
5460
gap: 4px;
5561
align-items: center;
62+
color: var(--figma-color-text-danger);
63+
}
64+
65+
.server-status.active {
66+
color: var(--figma-color-text-success);
5667
}
5768
</style>

0 commit comments

Comments
 (0)