@figma-vars/hooks 1.1.0 → 1.2.0
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/dist/contexts/FigmaTokenContext.d.ts +39 -1
- package/dist/figma-vars-hooks.js +661 -775
- package/dist/figma-vars-hooks.umd.cjs +6 -6
- package/dist/hooks/useFigmaToken.d.ts +11 -0
- package/dist/hooks/useVariableCollections.d.ts +20 -7
- package/dist/hooks/useVariableModes.d.ts +12 -4
- package/dist/hooks/useVariables.d.ts +18 -7
- package/dist/index.d.ts +4 -6
- package/dist/mutations/bulkUpdateVariables.d.ts +25 -7
- package/dist/mutations/createVariable.d.ts +26 -7
- package/dist/mutations/deleteVariable.d.ts +19 -7
- package/dist/mutations/updateVariable.d.ts +26 -7
- package/dist/types/figma.d.ts +63 -0
- package/dist/types/hooks.d.ts +6 -13
- package/dist/types/mutations.d.ts +54 -16
- package/dist/utils/fetcher.d.ts +13 -0
- package/dist/utils/filterVariables.d.ts +26 -0
- package/package.json +1 -1
- package/dist/utils/authHelpers.d.ts +0 -4
- package/dist/utils/fetchHelpers.d.ts +0 -10
|
@@ -1,36 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export interface VariableValueUpdate {
|
|
7
|
-
modeId: string;
|
|
8
|
-
value: string;
|
|
9
|
-
}
|
|
10
|
-
export type SpecificType = VariableValueUpdate[];
|
|
1
|
+
import { ResolvedType, VariableScope, VariableValue } from './figma';
|
|
2
|
+
/**
|
|
3
|
+
* The payload for the `createVariable` function.
|
|
4
|
+
* Defines the properties for a new variable.
|
|
5
|
+
*/
|
|
11
6
|
export interface CreateVariablePayload {
|
|
7
|
+
/** The name of the new variable. */
|
|
12
8
|
name: string;
|
|
9
|
+
/** The ID of the collection the new variable should be added to. */
|
|
13
10
|
variableCollectionId: string;
|
|
11
|
+
/** The underlying data type for the new variable. */
|
|
14
12
|
resolvedType: ResolvedType;
|
|
13
|
+
/** An optional description for the new variable. */
|
|
15
14
|
description?: string;
|
|
15
|
+
/** Whether the new variable should be hidden when publishing. Defaults to `false`. */
|
|
16
16
|
hiddenFromPublishing?: boolean;
|
|
17
|
+
/** The scopes in which this variable can be used. */
|
|
17
18
|
scopes?: VariableScope[];
|
|
19
|
+
/** Platform-specific code syntax for this variable. */
|
|
18
20
|
codeSyntax?: Record<string, string>;
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
variable?: FigmaVariable;
|
|
25
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* The payload for the `updateVariable` function.
|
|
24
|
+
* All properties are optional.
|
|
25
|
+
*/
|
|
26
26
|
export interface UpdateVariablePayload {
|
|
27
|
+
/** The new name for the variable. */
|
|
27
28
|
name?: string;
|
|
29
|
+
/** The new description for the variable. */
|
|
28
30
|
description?: string;
|
|
31
|
+
/** The new hidden status for the variable. */
|
|
29
32
|
hiddenFromPublishing?: boolean;
|
|
33
|
+
/** The new scopes for the variable. */
|
|
30
34
|
scopes?: VariableScope[];
|
|
35
|
+
/** The new code syntax for the variable. */
|
|
31
36
|
codeSyntax?: Record<string, string>;
|
|
32
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The action to perform in a bulk update.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
33
42
|
export type VariableAction = 'CREATE' | 'UPDATE' | 'DELETE';
|
|
43
|
+
/**
|
|
44
|
+
* A change to a variable collection in a bulk update.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
34
47
|
export interface VariableCollectionChange {
|
|
35
48
|
action: VariableAction;
|
|
36
49
|
id: string;
|
|
@@ -38,12 +51,20 @@ export interface VariableCollectionChange {
|
|
|
38
51
|
initialModeId?: string;
|
|
39
52
|
hiddenFromPublishing?: boolean;
|
|
40
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* A change to a variable mode in a bulk update.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
41
58
|
export interface VariableModeChange {
|
|
42
59
|
action: VariableAction;
|
|
43
60
|
id: string;
|
|
44
61
|
name?: string;
|
|
45
62
|
variableCollectionId: string;
|
|
46
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* A change to a variable's properties in a bulk update.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
47
68
|
export interface VariableChange {
|
|
48
69
|
action: VariableAction;
|
|
49
70
|
id: string;
|
|
@@ -55,15 +76,32 @@ export interface VariableChange {
|
|
|
55
76
|
scopes?: VariableScope[];
|
|
56
77
|
codeSyntax?: Record<string, string>;
|
|
57
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* A change to a variable's value in a specific mode in a bulk update.
|
|
81
|
+
*/
|
|
58
82
|
export interface VariableModeValue {
|
|
83
|
+
/** The ID of the variable to update. */
|
|
59
84
|
variableId: string;
|
|
85
|
+
/** The ID of the mode to update. */
|
|
60
86
|
modeId: string;
|
|
87
|
+
/** The new value for the variable in this mode. */
|
|
61
88
|
value: VariableValue;
|
|
62
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
|
+
*/
|
|
63
97
|
export interface BulkUpdatePayload {
|
|
98
|
+
/** A list of changes to variable collections. */
|
|
64
99
|
variableCollections?: VariableCollectionChange[];
|
|
100
|
+
/** A list of changes to variable modes. */
|
|
65
101
|
variableModes?: VariableModeChange[];
|
|
102
|
+
/** A list of changes to variables. */
|
|
66
103
|
variables?: VariableChange[];
|
|
104
|
+
/** A list of changes to variable values in specific modes. */
|
|
67
105
|
variableModeValues?: VariableModeValue[];
|
|
68
106
|
}
|
|
69
107
|
export interface BulkUpdateResponse {
|
|
@@ -0,0 +1,13 @@
|
|
|
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,4 +1,30 @@
|
|
|
1
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
|
+
*/
|
|
2
28
|
export declare function filterVariables(variables: FigmaVariable[], criteria: {
|
|
3
29
|
resolvedType?: ResolvedType;
|
|
4
30
|
name?: string;
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
interface FetchOptions {
|
|
2
|
-
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
3
|
-
body?: BodyInit | null;
|
|
4
|
-
headers?: HeadersInit;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* A helper function for making authenticated fetch requests to the Figma API.
|
|
8
|
-
*/
|
|
9
|
-
export declare const fetchWithAuth: (url: string, options?: FetchOptions) => Promise<any>;
|
|
10
|
-
export {};
|