@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.
@@ -1,36 +1,49 @@
1
- import { FigmaVariable, ResolvedType, VariableScope, VariableValue } from './figma';
2
- export interface FigmaOperationResponse {
3
- success: boolean;
4
- message?: string;
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
- export interface VariableActionResponse {
21
- error: boolean;
22
- status: number;
23
- message?: string;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@figma-vars/hooks",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
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",
@@ -1,4 +0,0 @@
1
- /**
2
- * Retrieves the Figma API token from environment variables or any other secure storage mechanism you've implemented.
3
- */
4
- export declare const getFigmaToken: () => string | null;
@@ -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 {};