@figma-vars/hooks 1.1.1 → 1.3.1
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 +588 -942
- package/dist/figma-vars-hooks.umd.cjs +3 -24
- package/dist/index.d.ts +936 -13
- package/package.json +17 -8
- package/dist/constants/index.d.ts +0 -3
- package/dist/contexts/FigmaTokenContext.d.ts +0 -11
- package/dist/hooks/useFigmaToken.d.ts +0 -6
- package/dist/hooks/useVariableCollections.d.ts +0 -13
- package/dist/hooks/useVariableModes.d.ts +0 -8
- package/dist/hooks/useVariables.d.ts +0 -14
- package/dist/mutations/bulkUpdateVariables.d.ts +0 -7
- package/dist/mutations/createVariable.d.ts +0 -7
- package/dist/mutations/deleteVariable.d.ts +0 -7
- package/dist/mutations/updateVariable.d.ts +0 -7
- package/dist/types/figma.d.ts +0 -48
- package/dist/types/hooks.d.ts +0 -19
- package/dist/types/index.d.ts +0 -3
- package/dist/types/mutations.d.ts +0 -76
- package/dist/utils/authHelpers.d.ts +0 -4
- package/dist/utils/fetchHelpers.d.ts +0 -10
- package/dist/utils/filterVariables.d.ts +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@figma-vars/hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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,11 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
interface FigmaTokenContextType {
|
|
3
|
-
token: string | null;
|
|
4
|
-
}
|
|
5
|
-
interface FigmaVarsProviderProps {
|
|
6
|
-
children: ReactNode;
|
|
7
|
-
token: string | null;
|
|
8
|
-
}
|
|
9
|
-
export declare const FigmaVarsProvider: ({ children, token, }: FigmaVarsProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export declare const useFigmaTokenContext: () => FigmaTokenContextType;
|
|
11
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FigmaCollection } from 'types';
|
|
2
|
-
/**
|
|
3
|
-
* A hook to fetch all variable collections for a given file.
|
|
4
|
-
* @param fileKey - The key of the Figma file to fetch collections from.
|
|
5
|
-
* @returns An object containing the variable collections, loading state, and any errors.
|
|
6
|
-
*/
|
|
7
|
-
export declare const useVariableCollections: (fileKey: string) => {
|
|
8
|
-
collections: FigmaCollection[];
|
|
9
|
-
collectionsById: Record<string, FigmaCollection>;
|
|
10
|
-
isLoading: boolean;
|
|
11
|
-
isValidating: boolean;
|
|
12
|
-
error: any;
|
|
13
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UseVariableModesResult } from '../types/hooks';
|
|
2
|
-
/**
|
|
3
|
-
* A hook to fetch all variable modes for a given file.
|
|
4
|
-
*
|
|
5
|
-
* @param fileKey - The key of the file to fetch variables from.
|
|
6
|
-
* @returns An object containing the variable modes, loading state, and any errors.
|
|
7
|
-
*/
|
|
8
|
-
export declare const useVariableModes: (fileKey: string) => UseVariableModesResult;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FigmaVariable } from 'types';
|
|
2
|
-
/**
|
|
3
|
-
* A hook to fetch all local variables for a given file.
|
|
4
|
-
*
|
|
5
|
-
* @param fileKey - The key of the file to fetch variables from.
|
|
6
|
-
* @returns An object containing the variables, loading state, and any errors.
|
|
7
|
-
*/
|
|
8
|
-
export declare const useVariables: (fileKey: string) => {
|
|
9
|
-
variables: FigmaVariable[];
|
|
10
|
-
variablesById: Record<string, FigmaVariable>;
|
|
11
|
-
isLoading: boolean;
|
|
12
|
-
isValidating: boolean;
|
|
13
|
-
error: any;
|
|
14
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BulkUpdatePayload, BulkUpdateResponse } from '../types/mutations';
|
|
2
|
-
export declare const useBulkUpdateVariables: () => {
|
|
3
|
-
bulkUpdate: (fileKey: string, payload: BulkUpdatePayload) => Promise<void>;
|
|
4
|
-
loading: boolean;
|
|
5
|
-
error: string | null;
|
|
6
|
-
data: BulkUpdateResponse | null;
|
|
7
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CreateVariablePayload, VariableActionResponse } from '../types/mutations';
|
|
2
|
-
export declare const useCreateVariable: () => {
|
|
3
|
-
createVariable: (payload: CreateVariablePayload) => Promise<void>;
|
|
4
|
-
loading: boolean;
|
|
5
|
-
error: string | null;
|
|
6
|
-
data: VariableActionResponse | null;
|
|
7
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { VariableActionResponse } from '../types/mutations';
|
|
2
|
-
export declare const useDeleteVariable: () => {
|
|
3
|
-
deleteVariable: (variableId: string) => Promise<void>;
|
|
4
|
-
loading: boolean;
|
|
5
|
-
error: string | null;
|
|
6
|
-
data: Omit<VariableActionResponse, "variable"> | null;
|
|
7
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { UpdateVariablePayload, VariableActionResponse } from '../types/mutations';
|
|
2
|
-
export declare const useUpdateVariable: () => {
|
|
3
|
-
updateVariable: (variableId: string, payload: UpdateVariablePayload) => Promise<void>;
|
|
4
|
-
loading: boolean;
|
|
5
|
-
error: string | null;
|
|
6
|
-
data: VariableActionResponse | null;
|
|
7
|
-
};
|
package/dist/types/figma.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export type ResolvedType = 'BOOLEAN' | 'FLOAT' | 'STRING' | 'COLOR';
|
|
2
|
-
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';
|
|
3
|
-
export interface Color {
|
|
4
|
-
r: number;
|
|
5
|
-
g: number;
|
|
6
|
-
b: number;
|
|
7
|
-
a: number;
|
|
8
|
-
}
|
|
9
|
-
export interface VariableAlias {
|
|
10
|
-
type: 'VARIABLE_ALIAS';
|
|
11
|
-
id: string;
|
|
12
|
-
}
|
|
13
|
-
export type VariableValue = string | boolean | number | Color | VariableAlias;
|
|
14
|
-
export interface FigmaVariable {
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
variableCollectionId: string;
|
|
18
|
-
resolvedType: ResolvedType;
|
|
19
|
-
valuesByMode: Record<string, VariableValue>;
|
|
20
|
-
description: string;
|
|
21
|
-
hiddenFromPublishing: boolean;
|
|
22
|
-
scopes: VariableScope[];
|
|
23
|
-
codeSyntax: Record<string, string>;
|
|
24
|
-
updatedAt: string;
|
|
25
|
-
}
|
|
26
|
-
export interface VariableMode {
|
|
27
|
-
modeId: string;
|
|
28
|
-
name: string;
|
|
29
|
-
}
|
|
30
|
-
export interface FigmaCollection {
|
|
31
|
-
id: string;
|
|
32
|
-
name: string;
|
|
33
|
-
modes: VariableMode[];
|
|
34
|
-
defaultModeId: string;
|
|
35
|
-
variableIds: string[];
|
|
36
|
-
hiddenFromPublishing: boolean;
|
|
37
|
-
updatedAt: string;
|
|
38
|
-
}
|
|
39
|
-
export interface LocalVariablesResponse {
|
|
40
|
-
meta: {
|
|
41
|
-
variableCollections: Record<string, FigmaCollection>;
|
|
42
|
-
variables: Record<string, FigmaVariable>;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export interface FigmaError {
|
|
46
|
-
statusCode: number;
|
|
47
|
-
message: string;
|
|
48
|
-
}
|
package/dist/types/hooks.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { VariableMode } from './figma';
|
|
2
|
-
export interface HookState<T> {
|
|
3
|
-
data: T | null;
|
|
4
|
-
loading: boolean;
|
|
5
|
-
error: Error | null;
|
|
6
|
-
}
|
|
7
|
-
export interface UseVariableModesResult {
|
|
8
|
-
modes: VariableMode[];
|
|
9
|
-
modesByCollectionId: Record<string, VariableMode[]>;
|
|
10
|
-
modesById: Record<string, VariableMode>;
|
|
11
|
-
isLoading: boolean;
|
|
12
|
-
isValidating: boolean;
|
|
13
|
-
error: Error | null;
|
|
14
|
-
}
|
|
15
|
-
export interface SyncStatus {
|
|
16
|
-
isSyncing: boolean;
|
|
17
|
-
lastSynced: Date | null;
|
|
18
|
-
error: string | null;
|
|
19
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
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[];
|
|
11
|
-
export interface CreateVariablePayload {
|
|
12
|
-
name: string;
|
|
13
|
-
variableCollectionId: string;
|
|
14
|
-
resolvedType: ResolvedType;
|
|
15
|
-
description?: string;
|
|
16
|
-
hiddenFromPublishing?: boolean;
|
|
17
|
-
scopes?: VariableScope[];
|
|
18
|
-
codeSyntax?: Record<string, string>;
|
|
19
|
-
}
|
|
20
|
-
export interface VariableActionResponse {
|
|
21
|
-
error: boolean;
|
|
22
|
-
status: number;
|
|
23
|
-
message?: string;
|
|
24
|
-
variable?: FigmaVariable;
|
|
25
|
-
}
|
|
26
|
-
export interface UpdateVariablePayload {
|
|
27
|
-
name?: string;
|
|
28
|
-
description?: string;
|
|
29
|
-
hiddenFromPublishing?: boolean;
|
|
30
|
-
scopes?: VariableScope[];
|
|
31
|
-
codeSyntax?: Record<string, string>;
|
|
32
|
-
}
|
|
33
|
-
export type VariableAction = 'CREATE' | 'UPDATE' | 'DELETE';
|
|
34
|
-
export interface VariableCollectionChange {
|
|
35
|
-
action: VariableAction;
|
|
36
|
-
id: string;
|
|
37
|
-
name?: string;
|
|
38
|
-
initialModeId?: string;
|
|
39
|
-
hiddenFromPublishing?: boolean;
|
|
40
|
-
}
|
|
41
|
-
export interface VariableModeChange {
|
|
42
|
-
action: VariableAction;
|
|
43
|
-
id: string;
|
|
44
|
-
name?: string;
|
|
45
|
-
variableCollectionId: string;
|
|
46
|
-
}
|
|
47
|
-
export interface VariableChange {
|
|
48
|
-
action: VariableAction;
|
|
49
|
-
id: string;
|
|
50
|
-
name?: string;
|
|
51
|
-
variableCollectionId?: string;
|
|
52
|
-
resolvedType?: ResolvedType;
|
|
53
|
-
description?: string;
|
|
54
|
-
hiddenFromPublishing?: boolean;
|
|
55
|
-
scopes?: VariableScope[];
|
|
56
|
-
codeSyntax?: Record<string, string>;
|
|
57
|
-
}
|
|
58
|
-
export interface VariableModeValue {
|
|
59
|
-
variableId: string;
|
|
60
|
-
modeId: string;
|
|
61
|
-
value: VariableValue;
|
|
62
|
-
}
|
|
63
|
-
export interface BulkUpdatePayload {
|
|
64
|
-
variableCollections?: VariableCollectionChange[];
|
|
65
|
-
variableModes?: VariableModeChange[];
|
|
66
|
-
variables?: VariableChange[];
|
|
67
|
-
variableModeValues?: VariableModeValue[];
|
|
68
|
-
}
|
|
69
|
-
export interface BulkUpdateResponse {
|
|
70
|
-
error: boolean;
|
|
71
|
-
status: number;
|
|
72
|
-
message?: string;
|
|
73
|
-
meta?: {
|
|
74
|
-
tempIdToRealId: Record<string, string>;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
@@ -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 {};
|