@figma-vars/hooks 1.2.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -15
- package/dist/figma-vars-hooks.js +559 -799
- package/dist/figma-vars-hooks.umd.cjs +3 -24
- package/dist/index.d.ts +1221 -11
- package/package.json +17 -8
- package/dist/constants/index.d.ts +0 -3
- package/dist/contexts/FigmaTokenContext.d.ts +0 -49
- package/dist/hooks/useFigmaToken.d.ts +0 -17
- package/dist/hooks/useVariableCollections.d.ts +0 -26
- package/dist/hooks/useVariableModes.d.ts +0 -16
- package/dist/hooks/useVariables.d.ts +0 -25
- package/dist/mutations/bulkUpdateVariables.d.ts +0 -25
- package/dist/mutations/createVariable.d.ts +0 -26
- package/dist/mutations/deleteVariable.d.ts +0 -19
- package/dist/mutations/updateVariable.d.ts +0 -26
- package/dist/types/figma.d.ts +0 -111
- package/dist/types/hooks.d.ts +0 -12
- package/dist/types/index.d.ts +0 -3
- package/dist/types/mutations.d.ts +0 -114
- package/dist/utils/fetcher.d.ts +0 -13
- package/dist/utils/filterVariables.d.ts +0 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@figma-vars/hooks",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Typed React hooks for managing Figma Variables, modes, tokens, and bindings via API.",
|
|
5
5
|
"author": "Mark Learst",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"node": ">=18.0.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"react": ">=
|
|
40
|
-
"react-dom": ">=
|
|
39
|
+
"react": ">=18.0.0",
|
|
40
|
+
"react-dom": ">=18.0.0"
|
|
41
41
|
},
|
|
42
42
|
"sideEffects": false,
|
|
43
43
|
"exports": {
|
|
@@ -52,14 +52,21 @@
|
|
|
52
52
|
"url": "https://github.com/sponsors/marklearst"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"react
|
|
55
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
56
|
+
"@testing-library/react": "^16.3.0",
|
|
57
|
+
"@types/node": "^24.0.3",
|
|
58
|
+
"@types/react": "^18.3.3",
|
|
59
|
+
"@types/react-dom": "^18.3.0",
|
|
60
|
+
"@vitejs/plugin-react": "^4.5.2",
|
|
61
|
+
"@vitest/coverage-v8": "^2.0.5",
|
|
62
|
+
"jsdom": "^26.1.0",
|
|
63
|
+
"react": "^18.3.1",
|
|
64
|
+
"react-dom": "^18.3.1",
|
|
59
65
|
"typescript": "~5.8.3",
|
|
60
66
|
"vite": "^6.3.5",
|
|
61
67
|
"vite-plugin-dts": "^4.5.4",
|
|
62
|
-
"vite-tsconfig-paths": "^5.1.4"
|
|
68
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
69
|
+
"vitest": "^2.0.5"
|
|
63
70
|
},
|
|
64
71
|
"directories": {
|
|
65
72
|
"doc": "docs"
|
|
@@ -70,7 +77,9 @@
|
|
|
70
77
|
"scripts": {
|
|
71
78
|
"dev": "vite",
|
|
72
79
|
"build": "tsc && vite build",
|
|
80
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
73
81
|
"preview": "vite preview",
|
|
82
|
+
"test": "vitest",
|
|
74
83
|
"postversion": "git push && git push --tags"
|
|
75
84
|
}
|
|
76
85
|
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
* The shape of the context provided by `FigmaVarsProvider`.
|
|
5
|
-
*/
|
|
6
|
-
interface FigmaTokenContextType {
|
|
7
|
-
/** The Figma Personal Access Token. */
|
|
8
|
-
token: string | null;
|
|
9
|
-
/** The key of the Figma file to access. */
|
|
10
|
-
fileKey: string | null;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Props for the `FigmaVarsProvider` component.
|
|
14
|
-
*/
|
|
15
|
-
interface FigmaVarsProviderProps {
|
|
16
|
-
/** The React children to render within the provider. */
|
|
17
|
-
children: ReactNode;
|
|
18
|
-
/** The Figma Personal Access Token. Can be sourced from anywhere (e.g., env variables, localStorage). */
|
|
19
|
-
token: string | null;
|
|
20
|
-
/** The key of the Figma file to be accessed by the hooks. */
|
|
21
|
-
fileKey: string | null;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A React Context Provider that makes the Figma token and file key available to all `figma-vars-hooks`.
|
|
25
|
-
* Wrap your application or component tree with this provider.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```tsx
|
|
29
|
-
* import { FigmaVarsProvider } from '@figma-vars/hooks';
|
|
30
|
-
*
|
|
31
|
-
* const App = () => (
|
|
32
|
-
* <FigmaVarsProvider
|
|
33
|
-
* token="your-figma-token"
|
|
34
|
-
* fileKey="your-figma-file-key"
|
|
35
|
-
* >
|
|
36
|
-
* <YourComponentThatUsesTheHooks />
|
|
37
|
-
* </FigmaVarsProvider>
|
|
38
|
-
* );
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare const FigmaVarsProvider: ({ children, token, fileKey, }: FigmaVarsProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
* A hook to access the Figma token and file key from the context.
|
|
45
|
-
* Throws an error if used outside of a `FigmaVarsProvider`.
|
|
46
|
-
* @returns The Figma token and file key.
|
|
47
|
-
*/
|
|
48
|
-
export declare const useFigmaTokenContext: () => FigmaTokenContextType;
|
|
49
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves the Figma API token from the FigmaVarsProvider.
|
|
3
|
-
* This hook must be used within a component wrapped by FigmaVarsProvider.
|
|
4
|
-
*
|
|
5
|
-
* @returns The Figma Personal Access Token, or `null` if it has not been provided.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```tsx
|
|
9
|
-
* const MyComponent = () => {
|
|
10
|
-
* const figmaToken = useFigmaToken();
|
|
11
|
-
* // Now you can use the token for manual API calls if needed.
|
|
12
|
-
* return <div>...</div>;
|
|
13
|
-
* };
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
declare const useFigmaToken: () => string | null;
|
|
17
|
-
export default useFigmaToken;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { FigmaCollection } from 'types';
|
|
2
|
-
/**
|
|
3
|
-
* A convenience hook to access the variable collections from the data fetched by `useVariables`.
|
|
4
|
-
* This hook does not perform its own data fetching; it's a lightweight selector on the main data source.
|
|
5
|
-
*
|
|
6
|
-
* It's recommended to use this hook when you only need collection data to avoid re-rendering components unnecessarily when other parts of the Figma data change.
|
|
7
|
-
*
|
|
8
|
-
* @returns An object containing the collections as an array (`collections`) and as a map by ID (`collectionsById`).
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const { collections } = useVariableCollections();
|
|
13
|
-
*
|
|
14
|
-
* return (
|
|
15
|
-
* <ul>
|
|
16
|
-
* {collections.map(collection => (
|
|
17
|
-
* <li key={collection.id}>{collection.name}</li>
|
|
18
|
-
* ))}
|
|
19
|
-
* </ul>
|
|
20
|
-
* );
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare const useVariableCollections: () => {
|
|
24
|
-
collections: FigmaCollection[];
|
|
25
|
-
collectionsById: Record<string, FigmaCollection>;
|
|
26
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { UseVariableModesResult } from '../types/hooks';
|
|
2
|
-
/**
|
|
3
|
-
* A convenience hook to access and process variable modes from the data fetched by `useVariables`.
|
|
4
|
-
* This hook does not perform its own data fetching; it's a lightweight selector that memoizes the processed mode data.
|
|
5
|
-
*
|
|
6
|
-
* Use this hook when you need mode data, structured for easy access.
|
|
7
|
-
*
|
|
8
|
-
* @returns An object containing all modes as an array (`modes`), modes grouped by collection ID (`modesByCollectionId`), and modes indexed by their own ID (`modesById`).
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const { modesById } = useVariableModes();
|
|
13
|
-
* const lightMode = modesById['mode-123'];
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare const useVariableModes: () => UseVariableModesResult;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { LocalVariablesResponse } from 'types';
|
|
2
|
-
/**
|
|
3
|
-
* The primary hook for fetching all local variables, collections, and modes for the file specified in the `FigmaVarsProvider`.
|
|
4
|
-
* This hook serves as the foundation for other data hooks like `useVariableCollections` and `useVariableModes`.
|
|
5
|
-
*
|
|
6
|
-
* It uses `swr` for efficient data fetching, caching, and revalidation.
|
|
7
|
-
*
|
|
8
|
-
* @returns An object containing the raw API response (`data`), loading state (`isLoading`), validation state (`isValidating`), and any errors (`error`).
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const { data, isLoading, error } = useVariables();
|
|
13
|
-
*
|
|
14
|
-
* if (isLoading) return <div>Loading...</div>;
|
|
15
|
-
* if (error) return <div>Error: {error.message}</div>;
|
|
16
|
-
*
|
|
17
|
-
* const collections = Object.values(data?.meta.variableCollections ?? {});
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare const useVariables: () => {
|
|
21
|
-
data: LocalVariablesResponse | undefined;
|
|
22
|
-
isLoading: boolean;
|
|
23
|
-
isValidating: boolean;
|
|
24
|
-
error: any;
|
|
25
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { BulkUpdatePayload } from '../types/mutations';
|
|
2
|
-
/**
|
|
3
|
-
* Performs a bulk update of variables in a Figma file.
|
|
4
|
-
* This endpoint can be used to create, update, or delete multiple variables in a single API call.
|
|
5
|
-
*
|
|
6
|
-
* @param token - The Figma Personal Access Token.
|
|
7
|
-
* @param fileKey - The key of the Figma file where the variables reside.
|
|
8
|
-
* @param payload - The bulk update payload, containing arrays of variables to create, update, and/or delete.
|
|
9
|
-
* @returns A promise that resolves with the metadata from the Figma API about the bulk operation.
|
|
10
|
-
* @throws Will throw an error if the fetch call fails or if the API returns an error response.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const payload = {
|
|
15
|
-
* create: [{ name: "new-var", variableCollectionId: "VC:1:1", resolvedType: "FLOAT" }],
|
|
16
|
-
* update: [{ id: "VariableID:123:456", name: "updated-name" }],
|
|
17
|
-
* delete: ["VariableID:789:101"]
|
|
18
|
-
* };
|
|
19
|
-
*
|
|
20
|
-
* bulkUpdateVariables("your-token", "your-file-key", payload)
|
|
21
|
-
* .then(response => console.log("Bulk update successful:", response))
|
|
22
|
-
* .catch(error => console.error(error));
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare const bulkUpdateVariables: (token: string, fileKey: string, payload: BulkUpdatePayload) => Promise<any>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { CreateVariablePayload } from '../types/mutations';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a new variable in a Figma file.
|
|
4
|
-
*
|
|
5
|
-
* This function sends a POST request to the Figma API to create a new variable.
|
|
6
|
-
* It requires a valid Figma token with `file_variables:write` scope.
|
|
7
|
-
*
|
|
8
|
-
* @param token - The Figma Personal Access Token.
|
|
9
|
-
* @param payload - The data for the new variable, including its name, collection ID, and type.
|
|
10
|
-
* @returns A promise that resolves with the created variable data from the Figma API.
|
|
11
|
-
* @throws Will throw an error if the fetch call fails or if the API returns an error response.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const newVariableData = {
|
|
16
|
-
* name: "new-color",
|
|
17
|
-
* variableCollectionId: "VariableCollectionId:1:1",
|
|
18
|
-
* resolvedType: "COLOR"
|
|
19
|
-
* };
|
|
20
|
-
*
|
|
21
|
-
* createVariable("your-figma-token", newVariableData)
|
|
22
|
-
* .then(result => console.log("Variable created:", result))
|
|
23
|
-
* .catch(error => console.error(error));
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare const createVariable: (token: string, payload: CreateVariablePayload) => Promise<any>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deletes a variable from a Figma file.
|
|
3
|
-
*
|
|
4
|
-
* This function sends a DELETE request to the Figma API to remove a single variable.
|
|
5
|
-
* It requires a valid Figma token with `file_variables:write` scope.
|
|
6
|
-
*
|
|
7
|
-
* @param token - The Figma Personal Access Token.
|
|
8
|
-
* @param variableId - The ID of the variable to delete.
|
|
9
|
-
* @returns A promise that resolves when the variable has been successfully deleted. The Figma API returns no content on a successful DELETE.
|
|
10
|
-
* @throws Will throw an error if the fetch call fails or if the API returns an error response.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* deleteVariable("your-figma-token", "VariableID:1:1")
|
|
15
|
-
* .then(() => console.log("Variable deleted successfully"))
|
|
16
|
-
* .catch(error => console.error(error));
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare const deleteVariable: (token: string, variableId: string) => Promise<void>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { UpdateVariablePayload } from '../types/mutations';
|
|
2
|
-
/**
|
|
3
|
-
* Updates an existing variable in a Figma file.
|
|
4
|
-
*
|
|
5
|
-
* This function sends a PUT request to the Figma API to modify a single variable.
|
|
6
|
-
* It requires a valid Figma token with `file_variables:write` scope.
|
|
7
|
-
*
|
|
8
|
-
* @param token - The Figma Personal Access Token.
|
|
9
|
-
* @param variableId - The ID of the variable to update.
|
|
10
|
-
* @param payload - The data to update for the variable.
|
|
11
|
-
* @returns A promise that resolves when the variable has been successfully updated. The Figma API returns no content on a successful PUT.
|
|
12
|
-
* @throws Will throw an error if the fetch call fails or if the API returns an error response.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const updatedData = {
|
|
17
|
-
* name: "new-color-name",
|
|
18
|
-
* description: "An updated description"
|
|
19
|
-
* };
|
|
20
|
-
*
|
|
21
|
-
* updateVariable("your-figma-token", "VariableID:1:1", updatedData)
|
|
22
|
-
* .then(() => console.log("Variable updated successfully"))
|
|
23
|
-
* .catch(error => console.error(error));
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare const updateVariable: (token: string, variableId: string, payload: UpdateVariablePayload) => Promise<void>;
|
package/dist/types/figma.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The resolved type of a Figma variable.
|
|
3
|
-
*/
|
|
4
|
-
export type ResolvedType = 'BOOLEAN' | 'FLOAT' | 'STRING' | 'COLOR';
|
|
5
|
-
/**
|
|
6
|
-
* The scopes where a Figma variable can be applied.
|
|
7
|
-
* `ALL_SCOPES` is a general-purpose scope. Other values restrict the variable to specific properties.
|
|
8
|
-
*/
|
|
9
|
-
export type VariableScope = 'ALL_SCOPES' | 'TEXT_CONTENT' | 'CORNER_RADIUS' | 'WIDTH_HEIGHT' | 'GAP' | 'STROKE_FLOAT' | 'OPACITY' | 'EFFECT_FLOAT' | 'FONT_WEIGHT' | 'FONT_SIZE' | 'LINE_HEIGHT' | 'LETTER_SPACING' | 'PARAGRAPH_SPACING' | 'PARAGRAPH_INDENT' | 'FONT_FAMILY' | 'FONT_STYLE' | 'FONT_VARIATIONS' | 'ALL_FILLS' | 'FRAME_FILL' | 'SHAPE_FILL' | 'TEXT_FILL' | 'STROKE_COLOR' | 'EFFECT_COLOR';
|
|
10
|
-
/**
|
|
11
|
-
* Represents a color in RGBA format.
|
|
12
|
-
*/
|
|
13
|
-
export interface Color {
|
|
14
|
-
/** The red channel value (0-1). */
|
|
15
|
-
r: number;
|
|
16
|
-
/** The green channel value (0-1). */
|
|
17
|
-
g: number;
|
|
18
|
-
/** The blue channel value (0-1). */
|
|
19
|
-
b: number;
|
|
20
|
-
/** The alpha (opacity) channel value (0-1). */
|
|
21
|
-
a: number;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Represents an alias to another Figma variable.
|
|
25
|
-
* This is used when a variable's value is set to reference another variable.
|
|
26
|
-
*/
|
|
27
|
-
export interface VariableAlias {
|
|
28
|
-
/** The type of the value, indicating it's a variable alias. */
|
|
29
|
-
type: 'VARIABLE_ALIAS';
|
|
30
|
-
/** The ID of the variable being referenced. */
|
|
31
|
-
id: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* The possible value types for a variable in a specific mode.
|
|
35
|
-
* It can be a primitive value, a color object, or an alias to another variable.
|
|
36
|
-
*/
|
|
37
|
-
export type VariableValue = string | boolean | number | Color | VariableAlias;
|
|
38
|
-
/**
|
|
39
|
-
* Represents a single Figma variable.
|
|
40
|
-
*/
|
|
41
|
-
export interface FigmaVariable {
|
|
42
|
-
/** The unique identifier for the variable. */
|
|
43
|
-
id: string;
|
|
44
|
-
/** The name of the variable. */
|
|
45
|
-
name: string;
|
|
46
|
-
/** The ID of the collection this variable belongs to. */
|
|
47
|
-
variableCollectionId: string;
|
|
48
|
-
/** The underlying data type of the variable. */
|
|
49
|
-
resolvedType: ResolvedType;
|
|
50
|
-
/** A map of mode IDs to the variable's value in that mode. */
|
|
51
|
-
valuesByMode: Record<string, VariableValue>;
|
|
52
|
-
/** The description of the variable, as set in Figma. */
|
|
53
|
-
description: string;
|
|
54
|
-
/** Whether the variable is hidden when publishing the library. */
|
|
55
|
-
hiddenFromPublishing: boolean;
|
|
56
|
-
/** The scopes in which this variable can be used. */
|
|
57
|
-
scopes: VariableScope[];
|
|
58
|
-
/** Platform-specific code syntax for this variable (e.g., for Web, iOS, Android). */
|
|
59
|
-
codeSyntax: Record<string, string>;
|
|
60
|
-
/** The timestamp of the last update. */
|
|
61
|
-
updatedAt: string;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Represents a single mode within a variable collection.
|
|
65
|
-
*/
|
|
66
|
-
export interface VariableMode {
|
|
67
|
-
/** The unique identifier for the mode. */
|
|
68
|
-
modeId: string;
|
|
69
|
-
/** The name of the mode (e.g., "Light", "Dark"). */
|
|
70
|
-
name: string;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Represents a collection of Figma variables, which can contain multiple modes.
|
|
74
|
-
*/
|
|
75
|
-
export interface FigmaCollection {
|
|
76
|
-
/** The unique identifier for the collection. */
|
|
77
|
-
id: string;
|
|
78
|
-
/** The name of the collection (e.g., "Brand Colors"). */
|
|
79
|
-
name: string;
|
|
80
|
-
/** An array of modes available in this collection. */
|
|
81
|
-
modes: VariableMode[];
|
|
82
|
-
/** The ID of the default mode for this collection. */
|
|
83
|
-
defaultModeId: string;
|
|
84
|
-
/** An array of variable IDs that belong to this collection. */
|
|
85
|
-
variableIds: string[];
|
|
86
|
-
/** Whether the collection is hidden when publishing the library. */
|
|
87
|
-
hiddenFromPublishing: boolean;
|
|
88
|
-
/** The timestamp of the last update. */
|
|
89
|
-
updatedAt: string;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* The structure of the successful response from the Figma API's `/v1/files/{file_key}/variables/local` endpoint.
|
|
93
|
-
*/
|
|
94
|
-
export interface LocalVariablesResponse {
|
|
95
|
-
/** Contains the metadata about the variables and collections. */
|
|
96
|
-
meta: {
|
|
97
|
-
/** A map of collection IDs to `FigmaCollection` objects. */
|
|
98
|
-
variableCollections: Record<string, FigmaCollection>;
|
|
99
|
-
/** A map of variable IDs to `FigmaVariable` objects. */
|
|
100
|
-
variables: Record<string, FigmaVariable>;
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* A generic error shape for failed Figma API requests.
|
|
105
|
-
*/
|
|
106
|
-
export interface FigmaError {
|
|
107
|
-
/** The HTTP status code of the error. */
|
|
108
|
-
statusCode: number;
|
|
109
|
-
/** The error message from the API. */
|
|
110
|
-
message: string;
|
|
111
|
-
}
|
package/dist/types/hooks.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { VariableMode } from './figma';
|
|
2
|
-
/**
|
|
3
|
-
* The return type for the `useVariableModes` hook.
|
|
4
|
-
*/
|
|
5
|
-
export interface UseVariableModesResult {
|
|
6
|
-
/** A flat array of all modes across all collections. */
|
|
7
|
-
modes: VariableMode[];
|
|
8
|
-
/** A map of collection IDs to an array of modes belonging to that collection. */
|
|
9
|
-
modesByCollectionId: Record<string, VariableMode[]>;
|
|
10
|
-
/** A map of mode IDs to the corresponding mode object for quick lookups. */
|
|
11
|
-
modesById: Record<string, VariableMode>;
|
|
12
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { ResolvedType, VariableScope, VariableValue } from './figma';
|
|
2
|
-
/**
|
|
3
|
-
* The payload for the `createVariable` function.
|
|
4
|
-
* Defines the properties for a new variable.
|
|
5
|
-
*/
|
|
6
|
-
export interface CreateVariablePayload {
|
|
7
|
-
/** The name of the new variable. */
|
|
8
|
-
name: string;
|
|
9
|
-
/** The ID of the collection the new variable should be added to. */
|
|
10
|
-
variableCollectionId: string;
|
|
11
|
-
/** The underlying data type for the new variable. */
|
|
12
|
-
resolvedType: ResolvedType;
|
|
13
|
-
/** An optional description for the new variable. */
|
|
14
|
-
description?: string;
|
|
15
|
-
/** Whether the new variable should be hidden when publishing. Defaults to `false`. */
|
|
16
|
-
hiddenFromPublishing?: boolean;
|
|
17
|
-
/** The scopes in which this variable can be used. */
|
|
18
|
-
scopes?: VariableScope[];
|
|
19
|
-
/** Platform-specific code syntax for this variable. */
|
|
20
|
-
codeSyntax?: Record<string, string>;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The payload for the `updateVariable` function.
|
|
24
|
-
* All properties are optional.
|
|
25
|
-
*/
|
|
26
|
-
export interface UpdateVariablePayload {
|
|
27
|
-
/** The new name for the variable. */
|
|
28
|
-
name?: string;
|
|
29
|
-
/** The new description for the variable. */
|
|
30
|
-
description?: string;
|
|
31
|
-
/** The new hidden status for the variable. */
|
|
32
|
-
hiddenFromPublishing?: boolean;
|
|
33
|
-
/** The new scopes for the variable. */
|
|
34
|
-
scopes?: VariableScope[];
|
|
35
|
-
/** The new code syntax for the variable. */
|
|
36
|
-
codeSyntax?: Record<string, string>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* The action to perform in a bulk update.
|
|
40
|
-
* @internal
|
|
41
|
-
*/
|
|
42
|
-
export type VariableAction = 'CREATE' | 'UPDATE' | 'DELETE';
|
|
43
|
-
/**
|
|
44
|
-
* A change to a variable collection in a bulk update.
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
export interface VariableCollectionChange {
|
|
48
|
-
action: VariableAction;
|
|
49
|
-
id: string;
|
|
50
|
-
name?: string;
|
|
51
|
-
initialModeId?: string;
|
|
52
|
-
hiddenFromPublishing?: boolean;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* A change to a variable mode in a bulk update.
|
|
56
|
-
* @internal
|
|
57
|
-
*/
|
|
58
|
-
export interface VariableModeChange {
|
|
59
|
-
action: VariableAction;
|
|
60
|
-
id: string;
|
|
61
|
-
name?: string;
|
|
62
|
-
variableCollectionId: string;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* A change to a variable's properties in a bulk update.
|
|
66
|
-
* @internal
|
|
67
|
-
*/
|
|
68
|
-
export interface VariableChange {
|
|
69
|
-
action: VariableAction;
|
|
70
|
-
id: string;
|
|
71
|
-
name?: string;
|
|
72
|
-
variableCollectionId?: string;
|
|
73
|
-
resolvedType?: ResolvedType;
|
|
74
|
-
description?: string;
|
|
75
|
-
hiddenFromPublishing?: boolean;
|
|
76
|
-
scopes?: VariableScope[];
|
|
77
|
-
codeSyntax?: Record<string, string>;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* A change to a variable's value in a specific mode in a bulk update.
|
|
81
|
-
*/
|
|
82
|
-
export interface VariableModeValue {
|
|
83
|
-
/** The ID of the variable to update. */
|
|
84
|
-
variableId: string;
|
|
85
|
-
/** The ID of the mode to update. */
|
|
86
|
-
modeId: string;
|
|
87
|
-
/** The new value for the variable in this mode. */
|
|
88
|
-
value: VariableValue;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* The payload for the `bulkUpdateVariables` function.
|
|
92
|
-
* Allows creating, updating, and deleting multiple variables, collections, and modes in one call.
|
|
93
|
-
* This corresponds to the `POST /v1/files/:file_key/variables` endpoint.
|
|
94
|
-
* Note: Figma has deprecated this complex endpoint in favor of simpler, more granular ones.
|
|
95
|
-
* This type is kept for legacy purposes but its usage is not recommended.
|
|
96
|
-
*/
|
|
97
|
-
export interface BulkUpdatePayload {
|
|
98
|
-
/** A list of changes to variable collections. */
|
|
99
|
-
variableCollections?: VariableCollectionChange[];
|
|
100
|
-
/** A list of changes to variable modes. */
|
|
101
|
-
variableModes?: VariableModeChange[];
|
|
102
|
-
/** A list of changes to variables. */
|
|
103
|
-
variables?: VariableChange[];
|
|
104
|
-
/** A list of changes to variable values in specific modes. */
|
|
105
|
-
variableModeValues?: VariableModeValue[];
|
|
106
|
-
}
|
|
107
|
-
export interface BulkUpdateResponse {
|
|
108
|
-
error: boolean;
|
|
109
|
-
status: number;
|
|
110
|
-
message?: string;
|
|
111
|
-
meta?: {
|
|
112
|
-
tempIdToRealId: Record<string, string>;
|
|
113
|
-
};
|
|
114
|
-
}
|
package/dist/utils/fetcher.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
* A generic fetcher function designed to work with SWR.
|
|
4
|
-
* It takes a URL and a Figma token, and returns the JSON response.
|
|
5
|
-
*
|
|
6
|
-
* This function is used by the data-fetching hooks to make authenticated requests to the Figma API.
|
|
7
|
-
*
|
|
8
|
-
* @param url - The API endpoint to fetch.
|
|
9
|
-
* @param token - The Figma Personal Access Token.
|
|
10
|
-
* @returns A promise that resolves with the JSON data from the API.
|
|
11
|
-
* @throws Will throw an error if the fetch call fails or if the API returns an error response.
|
|
12
|
-
*/
|
|
13
|
-
export declare const fetcher: (url: string, token: string) => Promise<any>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FigmaVariable, ResolvedType } from 'types';
|
|
2
|
-
/**
|
|
3
|
-
* Filters an array of Figma variables based on specified criteria.
|
|
4
|
-
* This utility can filter by variable type, a partial name match, or both.
|
|
5
|
-
*
|
|
6
|
-
* @param variables - The array of `FigmaVariable` objects to filter.
|
|
7
|
-
* @param criteria - An object specifying the filter criteria.
|
|
8
|
-
* @param criteria.resolvedType - The variable type (e.g., 'COLOR', 'FLOAT') to filter by.
|
|
9
|
-
* @param criteria.name - A string to search for within the variable names (case-sensitive).
|
|
10
|
-
* @returns A new array containing only the variables that match the criteria.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { filterVariables } from 'utils/filterVariables';
|
|
15
|
-
*
|
|
16
|
-
* const allVariables = [
|
|
17
|
-
* { name: 'primary-color', resolvedType: 'COLOR', ... },
|
|
18
|
-
* { name: 'font-size-large', resolvedType: 'FLOAT', ... }
|
|
19
|
-
* ];
|
|
20
|
-
*
|
|
21
|
-
* // Filter by type
|
|
22
|
-
* const colorVariables = filterVariables(allVariables, { resolvedType: 'COLOR' });
|
|
23
|
-
*
|
|
24
|
-
* // Filter by name
|
|
25
|
-
* const fontVariables = filterVariables(allVariables, { name: 'font' });
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare function filterVariables(variables: FigmaVariable[], criteria: {
|
|
29
|
-
resolvedType?: ResolvedType;
|
|
30
|
-
name?: string;
|
|
31
|
-
}): FigmaVariable[];
|