@figma-vars/hooks 3.0.0-beta.1 → 3.0.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/README.md +371 -177
- package/dist/api/fetcher.d.ts.map +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/mutator.d.ts +10 -9
- package/dist/api/mutator.d.ts.map +1 -1
- package/dist/constants/index.d.ts +2 -28
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/contexts/FigmaTokenContext.d.ts.map +1 -1
- package/dist/contexts/FigmaVarsProvider.d.ts +1 -1
- package/dist/contexts/FigmaVarsProvider.d.ts.map +1 -1
- package/dist/contexts/index.d.ts +1 -1
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/contexts/useFigmaTokenContext.d.ts.map +1 -1
- package/dist/core/index.d.cts +8 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core.cjs +1 -0
- package/dist/core.d.cts +2 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.mjs +20 -0
- package/dist/hooks/index.d.ts +19 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
- package/dist/hooks/useCreateVariable.d.ts.map +1 -1
- package/dist/hooks/useDeleteVariable.d.ts.map +1 -1
- package/dist/hooks/useFigmaToken.d.ts.map +1 -1
- package/dist/hooks/useInvalidateVariables.d.ts +31 -0
- package/dist/hooks/useInvalidateVariables.d.ts.map +1 -0
- package/dist/hooks/usePublishedVariables.d.ts +42 -0
- package/dist/hooks/usePublishedVariables.d.ts.map +1 -0
- package/dist/hooks/useUpdateVariable.d.ts.map +1 -1
- package/dist/hooks/useVariableCollections.d.ts.map +1 -1
- package/dist/hooks/useVariableModes.d.ts.map +1 -1
- package/dist/hooks/useVariables.d.ts +3 -1
- package/dist/hooks/useVariables.d.ts.map +1 -1
- package/dist/index-BIUpDTdr.cjs +1 -0
- package/dist/index-Cd4HQQHO.js +94 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +235 -162
- package/dist/types/contexts.d.ts +29 -3
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/figma.d.ts +56 -3
- package/dist/types/figma.d.ts.map +1 -1
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mutations.d.ts +4 -4
- package/dist/types/mutations.d.ts.map +1 -1
- package/dist/utils/errorHelpers.d.ts +96 -0
- package/dist/utils/errorHelpers.d.ts.map +1 -0
- package/dist/utils/filterVariables.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +75 -31
- package/scripts/export-variables.mjs +101 -0
- package/dist/index.d.mts +0 -2
package/dist/index.mjs
CHANGED
|
@@ -1,201 +1,274 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { jsx as K } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as L, useMemo as m, useContext as T, useReducer as V, useRef as w, useEffect as k, useCallback as _ } from "react";
|
|
3
|
+
import A, { useSWRConfig as S } from "swr";
|
|
4
|
+
import { f as I, E as v, a as p, m as E, F as b, b as h, c as P } from "./index-Cd4HQQHO.js";
|
|
5
|
+
import { d as te } from "./index-Cd4HQQHO.js";
|
|
6
|
+
const g = L(void 0);
|
|
7
|
+
let R = 0;
|
|
8
|
+
const G = ({
|
|
9
|
+
children: e,
|
|
10
|
+
token: t,
|
|
11
|
+
fileKey: r,
|
|
12
|
+
fallbackFile: o,
|
|
13
|
+
swrConfig: n
|
|
9
14
|
}) => {
|
|
10
|
-
const s =
|
|
11
|
-
|
|
15
|
+
const s = m(() => (R += 1, `figma-vars-provider-${R}`), []), c = m(() => {
|
|
16
|
+
const a = {
|
|
17
|
+
token: t,
|
|
18
|
+
fileKey: r,
|
|
19
|
+
providerId: s,
|
|
20
|
+
...n !== void 0 && { swrConfig: n }
|
|
21
|
+
};
|
|
22
|
+
return o === void 0 ? a : { ...a, fallbackFile: o };
|
|
23
|
+
}, [t, r, o, s, n]);
|
|
24
|
+
return /* @__PURE__ */ K(g.Provider, { value: c, children: e });
|
|
12
25
|
}, u = () => {
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
throw new Error(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
[
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
s != null && s.message && (r = s.message);
|
|
33
|
-
} catch {
|
|
34
|
-
}
|
|
35
|
-
throw new Error(r);
|
|
36
|
-
}
|
|
37
|
-
return e.json();
|
|
38
|
-
}
|
|
39
|
-
const y = () => {
|
|
40
|
-
const { token: t, fileKey: o } = u(), e = t && o ? `https://api.figma.com/v1/files/${o}/variables/local` : null;
|
|
41
|
-
return C(
|
|
42
|
-
e && t ? [e, t] : null,
|
|
43
|
-
e && t ? ([s, n]) => M(s, n) : () => Promise.resolve(void 0)
|
|
26
|
+
const e = T(g);
|
|
27
|
+
if (e === void 0)
|
|
28
|
+
throw new Error(
|
|
29
|
+
"useFigmaTokenContext must be used within a FigmaVarsProvider"
|
|
30
|
+
);
|
|
31
|
+
return e;
|
|
32
|
+
}, C = () => {
|
|
33
|
+
const { token: e, fileKey: t, fallbackFile: r, providerId: o, swrConfig: n } = u(), s = t ? `https://api.figma.com/v1/files/${t}/variables/local` : null, l = !!(e && s) ? [s, e] : !!r ? [`fallback-${o ?? "default"}`, "fallback"] : null;
|
|
34
|
+
return A(
|
|
35
|
+
l,
|
|
36
|
+
async (...i) => {
|
|
37
|
+
const [f, d] = Array.isArray(i[0]) ? i[0] : [i[0], i[1]];
|
|
38
|
+
if (r)
|
|
39
|
+
return typeof r == "string" ? JSON.parse(r) : r;
|
|
40
|
+
if (!f || !d)
|
|
41
|
+
throw new Error("Missing URL or token for live API request");
|
|
42
|
+
return I(f, d);
|
|
43
|
+
},
|
|
44
|
+
n
|
|
44
45
|
);
|
|
45
|
-
},
|
|
46
|
-
const { data:
|
|
47
|
-
() =>
|
|
48
|
-
[
|
|
49
|
-
),
|
|
50
|
-
() =>
|
|
51
|
-
[
|
|
46
|
+
}, N = () => {
|
|
47
|
+
const { data: e } = C(), t = m(
|
|
48
|
+
() => e != null && e.meta ? Object.values(e.meta.variableCollections) : [],
|
|
49
|
+
[e]
|
|
50
|
+
), r = m(
|
|
51
|
+
() => e != null && e.meta ? e.meta.variableCollections : {},
|
|
52
|
+
[e]
|
|
52
53
|
);
|
|
53
54
|
return {
|
|
54
|
-
collections:
|
|
55
|
-
collectionsById:
|
|
55
|
+
collections: t,
|
|
56
|
+
collectionsById: r
|
|
56
57
|
};
|
|
57
|
-
},
|
|
58
|
-
const { data:
|
|
59
|
-
return
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
for (const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
}, j = () => {
|
|
59
|
+
const { data: e } = C();
|
|
60
|
+
return m(() => {
|
|
61
|
+
const t = [], r = {}, o = {};
|
|
62
|
+
if (e != null && e.meta)
|
|
63
|
+
for (const n of Object.values(
|
|
64
|
+
e.meta.variableCollections
|
|
65
|
+
)) {
|
|
66
|
+
t.push(...n.modes), r[n.id] = n.modes;
|
|
67
|
+
for (const s of n.modes)
|
|
68
|
+
o[s.modeId] = s;
|
|
66
69
|
}
|
|
67
70
|
return {
|
|
68
|
-
modes:
|
|
69
|
-
modesByCollectionId:
|
|
70
|
-
modesById:
|
|
71
|
+
modes: t,
|
|
72
|
+
modesByCollectionId: r,
|
|
73
|
+
modesById: o
|
|
71
74
|
};
|
|
72
|
-
}, [
|
|
75
|
+
}, [e]);
|
|
73
76
|
};
|
|
74
|
-
function
|
|
75
|
-
switch (
|
|
77
|
+
function B(e, t) {
|
|
78
|
+
switch (t.type) {
|
|
76
79
|
case "loading":
|
|
77
|
-
return { ...
|
|
80
|
+
return { ...e, status: "loading", error: null };
|
|
78
81
|
case "success":
|
|
79
|
-
return { ...
|
|
82
|
+
return { ...e, status: "success", data: t.payload };
|
|
80
83
|
case "error":
|
|
81
|
-
return { ...
|
|
84
|
+
return { ...e, status: "error", error: t.payload };
|
|
82
85
|
default:
|
|
83
|
-
return
|
|
86
|
+
return e;
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
|
-
const
|
|
87
|
-
const
|
|
89
|
+
const y = (e) => {
|
|
90
|
+
const t = {
|
|
88
91
|
status: "idle",
|
|
89
92
|
data: null,
|
|
90
93
|
error: null
|
|
91
|
-
}, [
|
|
92
|
-
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
}, [r, o] = V(B, t), n = w(e), s = w(!0);
|
|
95
|
+
return k(() => {
|
|
96
|
+
n.current = e;
|
|
97
|
+
}, [e]), k(() => (s.current = !0, () => {
|
|
98
|
+
s.current = !1;
|
|
99
|
+
}), []), {
|
|
100
|
+
mutate: _(
|
|
101
|
+
async (a) => {
|
|
102
|
+
if (s.current) {
|
|
103
|
+
o({ type: "loading" });
|
|
104
|
+
try {
|
|
105
|
+
const l = await n.current(a);
|
|
106
|
+
return s.current && o({ type: "success", payload: l }), l;
|
|
107
|
+
} catch (l) {
|
|
108
|
+
s.current && o({ type: "error", payload: l });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
102
111
|
}
|
|
103
112
|
},
|
|
104
|
-
[
|
|
113
|
+
[]
|
|
114
|
+
// Empty deps array - mutationFn is accessed via ref
|
|
105
115
|
),
|
|
106
|
-
...
|
|
107
|
-
isLoading:
|
|
108
|
-
isSuccess:
|
|
109
|
-
isError:
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
async function m(t, o, e, r) {
|
|
113
|
-
if (!o)
|
|
114
|
-
throw new Error(c);
|
|
115
|
-
const a = {
|
|
116
|
-
method: {
|
|
117
|
-
CREATE: "POST",
|
|
118
|
-
UPDATE: "PUT",
|
|
119
|
-
DELETE: "DELETE"
|
|
120
|
-
}[e],
|
|
121
|
-
headers: {
|
|
122
|
-
"Content-Type": "application/json",
|
|
123
|
-
[T]: o
|
|
124
|
-
}
|
|
116
|
+
...r,
|
|
117
|
+
isLoading: r.status === "loading",
|
|
118
|
+
isSuccess: r.status === "success",
|
|
119
|
+
isError: r.status === "error"
|
|
125
120
|
};
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
return i.status === 204 || !i.body ? {} : i.json();
|
|
133
|
-
}
|
|
134
|
-
const G = () => {
|
|
135
|
-
const { token: t } = u();
|
|
136
|
-
return l(async (e) => {
|
|
121
|
+
}, H = () => {
|
|
122
|
+
const { token: e, fileKey: t } = u();
|
|
123
|
+
return y(async (o) => {
|
|
124
|
+
if (!e)
|
|
125
|
+
throw new Error(v);
|
|
137
126
|
if (!t)
|
|
138
|
-
throw new Error(
|
|
139
|
-
return await
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
127
|
+
throw new Error(p);
|
|
128
|
+
return await E(b(t), e, "CREATE", {
|
|
129
|
+
variables: [
|
|
130
|
+
{
|
|
131
|
+
action: "CREATE",
|
|
132
|
+
...o
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
});
|
|
145
136
|
});
|
|
146
|
-
},
|
|
147
|
-
const { token: t } = u();
|
|
148
|
-
return
|
|
149
|
-
async ({
|
|
137
|
+
}, q = () => {
|
|
138
|
+
const { token: e, fileKey: t } = u();
|
|
139
|
+
return y(
|
|
140
|
+
async ({
|
|
141
|
+
variableId: o,
|
|
142
|
+
payload: n
|
|
143
|
+
}) => {
|
|
144
|
+
if (!e)
|
|
145
|
+
throw new Error(v);
|
|
150
146
|
if (!t)
|
|
151
|
-
throw new Error(
|
|
152
|
-
return await
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
throw new Error(p);
|
|
148
|
+
return await E(
|
|
149
|
+
b(t),
|
|
150
|
+
e,
|
|
155
151
|
"UPDATE",
|
|
156
|
-
|
|
152
|
+
{
|
|
153
|
+
variables: [
|
|
154
|
+
{
|
|
155
|
+
action: "UPDATE",
|
|
156
|
+
id: o,
|
|
157
|
+
...n
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
157
161
|
);
|
|
158
162
|
}
|
|
159
163
|
);
|
|
160
|
-
},
|
|
161
|
-
const { token: t } = u();
|
|
162
|
-
return
|
|
164
|
+
}, J = () => {
|
|
165
|
+
const { token: e, fileKey: t } = u();
|
|
166
|
+
return y(async (o) => {
|
|
167
|
+
if (!e)
|
|
168
|
+
throw new Error(v);
|
|
163
169
|
if (!t)
|
|
164
|
-
throw new Error(
|
|
165
|
-
return await
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
throw new Error(p);
|
|
171
|
+
return await E(b(t), e, "DELETE", {
|
|
172
|
+
variables: [
|
|
173
|
+
{
|
|
174
|
+
action: "DELETE",
|
|
175
|
+
id: o
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
});
|
|
171
179
|
});
|
|
172
|
-
},
|
|
173
|
-
const { token: t } = u();
|
|
174
|
-
return
|
|
180
|
+
}, Q = () => {
|
|
181
|
+
const { token: e, fileKey: t } = u();
|
|
182
|
+
return y(async (o) => {
|
|
183
|
+
if (!e)
|
|
184
|
+
throw new Error(v);
|
|
175
185
|
if (!t)
|
|
176
|
-
throw new Error(
|
|
177
|
-
return await
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"
|
|
181
|
-
|
|
186
|
+
throw new Error(p);
|
|
187
|
+
return await E(
|
|
188
|
+
b(t),
|
|
189
|
+
e,
|
|
190
|
+
"UPDATE",
|
|
191
|
+
o
|
|
182
192
|
);
|
|
183
193
|
});
|
|
194
|
+
}, W = () => {
|
|
195
|
+
const { mutate: e } = S(), { fileKey: t, providerId: r } = u();
|
|
196
|
+
return {
|
|
197
|
+
invalidate: () => {
|
|
198
|
+
if (!t) return;
|
|
199
|
+
const s = [
|
|
200
|
+
`https://api.figma.com/v1/files/${t}/variables/local`,
|
|
201
|
+
"token-placeholder"
|
|
202
|
+
];
|
|
203
|
+
e(s);
|
|
204
|
+
const c = [
|
|
205
|
+
h(t),
|
|
206
|
+
"token-placeholder"
|
|
207
|
+
];
|
|
208
|
+
if (e(c), r) {
|
|
209
|
+
const a = [`fallback-${r}`, "fallback"];
|
|
210
|
+
e(a);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
revalidate: () => {
|
|
214
|
+
if (!t) return;
|
|
215
|
+
const s = [
|
|
216
|
+
`https://api.figma.com/v1/files/${t}/variables/local`,
|
|
217
|
+
"token-placeholder"
|
|
218
|
+
];
|
|
219
|
+
e(s, void 0, { revalidate: !0 });
|
|
220
|
+
const c = [
|
|
221
|
+
h(t),
|
|
222
|
+
"token-placeholder"
|
|
223
|
+
];
|
|
224
|
+
if (e(c, void 0, { revalidate: !0 }), r) {
|
|
225
|
+
const a = [`fallback-${r}`, "fallback"];
|
|
226
|
+
e(a, void 0, { revalidate: !0 });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}, Y = () => {
|
|
231
|
+
const { token: e, fileKey: t, fallbackFile: r, providerId: o, swrConfig: n } = u(), s = t ? h(t) : null, l = !!(e && s) ? [s, e] : !!r ? [`fallback-${o ?? "default"}`, "fallback"] : null;
|
|
232
|
+
return A(
|
|
233
|
+
l,
|
|
234
|
+
async (...i) => {
|
|
235
|
+
const [f, d] = Array.isArray(i[0]) ? i[0] : [i[0], i[1]];
|
|
236
|
+
if (r)
|
|
237
|
+
return typeof r == "string" ? JSON.parse(r) : r;
|
|
238
|
+
if (!f || !d)
|
|
239
|
+
throw new Error("Missing URL or token for live API request");
|
|
240
|
+
return I(f, d);
|
|
241
|
+
},
|
|
242
|
+
n
|
|
243
|
+
);
|
|
184
244
|
};
|
|
185
|
-
function
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
245
|
+
function M(e) {
|
|
246
|
+
return e instanceof P;
|
|
247
|
+
}
|
|
248
|
+
function U(e) {
|
|
249
|
+
return M(e) ? e.statusCode : null;
|
|
250
|
+
}
|
|
251
|
+
function z(e, t = "An error occurred") {
|
|
252
|
+
return e instanceof Error ? e.message || t : typeof e == "string" ? e : t;
|
|
253
|
+
}
|
|
254
|
+
function X(e, t) {
|
|
255
|
+
return U(e) === t;
|
|
190
256
|
}
|
|
191
257
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
258
|
+
P as FigmaApiError,
|
|
259
|
+
G as FigmaVarsProvider,
|
|
260
|
+
te as filterVariables,
|
|
261
|
+
z as getErrorMessage,
|
|
262
|
+
U as getErrorStatus,
|
|
263
|
+
X as hasErrorStatus,
|
|
264
|
+
M as isFigmaApiError,
|
|
265
|
+
Q as useBulkUpdateVariables,
|
|
266
|
+
H as useCreateVariable,
|
|
267
|
+
J as useDeleteVariable,
|
|
268
|
+
W as useInvalidateVariables,
|
|
269
|
+
Y as usePublishedVariables,
|
|
270
|
+
q as useUpdateVariable,
|
|
271
|
+
N as useVariableCollections,
|
|
272
|
+
j as useVariableModes,
|
|
273
|
+
C as useVariables
|
|
201
274
|
};
|
package/dist/types/contexts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { SWRConfiguration } from 'swr';
|
|
3
|
+
import { LocalVariablesResponse, PublishedVariablesResponse } from 'types';
|
|
3
4
|
/**
|
|
4
5
|
* Central context shape for FigmaVars—provides authentication and file context to all hooks and consumers in the tree.
|
|
5
6
|
*
|
|
@@ -41,7 +42,12 @@ export interface FigmaTokenContextType {
|
|
|
41
42
|
* Optional fallback variable JSON file for offline or static use cases.
|
|
42
43
|
* Allows FigmaVars to function without a live API request.
|
|
43
44
|
*/
|
|
44
|
-
fallbackFile?: LocalVariablesResponse | string;
|
|
45
|
+
fallbackFile?: LocalVariablesResponse | PublishedVariablesResponse | string;
|
|
46
|
+
/**
|
|
47
|
+
* Optional SWR configuration to customize caching, revalidation, and error handling behavior.
|
|
48
|
+
* Applied to all SWR hooks within this provider.
|
|
49
|
+
*/
|
|
50
|
+
swrConfig?: SWRConfiguration | undefined;
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
53
|
* Props for the FigmaVarsProvider component, which injects Figma API authentication and file scoping for all descendant hooks and utilities.
|
|
@@ -83,6 +89,26 @@ export interface FigmaVarsProviderProps {
|
|
|
83
89
|
/**
|
|
84
90
|
* Optional fallback variable JSON file used when the API is unavailable or skipped.
|
|
85
91
|
*/
|
|
86
|
-
fallbackFile?: LocalVariablesResponse | string;
|
|
92
|
+
fallbackFile?: LocalVariablesResponse | PublishedVariablesResponse | string;
|
|
93
|
+
/**
|
|
94
|
+
* Optional SWR configuration to customize caching, revalidation, and error handling.
|
|
95
|
+
* Common options: `revalidateOnFocus`, `dedupingInterval`, `errorRetryCount`, `onError`, etc.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <FigmaVarsProvider
|
|
100
|
+
* token={token}
|
|
101
|
+
* fileKey={fileKey}
|
|
102
|
+
* swrConfig={{
|
|
103
|
+
* revalidateOnFocus: false,
|
|
104
|
+
* dedupingInterval: 5000,
|
|
105
|
+
* errorRetryCount: 3,
|
|
106
|
+
* }}
|
|
107
|
+
* >
|
|
108
|
+
* <App />
|
|
109
|
+
* </FigmaVarsProvider>
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
swrConfig?: SWRConfiguration;
|
|
87
113
|
}
|
|
88
114
|
//# sourceMappingURL=contexts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/types/contexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/types/contexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAA;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,sBAAsB,GAAG,0BAA0B,GAAG,MAAM,CAAA;IAM3E;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAA;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB;;OAEG;IACH,YAAY,CAAC,EAAE,sBAAsB,GAAG,0BAA0B,GAAG,MAAM,CAAA;IAC3E;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAC7B"}
|
package/dist/types/figma.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
|
-
export type ResolvedType =
|
|
14
|
+
export type ResolvedType = 'BOOLEAN' | 'FLOAT' | 'STRING' | 'COLOR';
|
|
15
15
|
/**
|
|
16
16
|
* Enum of all valid Figma variable scopes.
|
|
17
17
|
*
|
|
@@ -26,7 +26,7 @@ export type ResolvedType = "BOOLEAN" | "FLOAT" | "STRING" | "COLOR";
|
|
|
26
26
|
*
|
|
27
27
|
* @public
|
|
28
28
|
*/
|
|
29
|
-
export type VariableScope =
|
|
29
|
+
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';
|
|
30
30
|
/**
|
|
31
31
|
* RGBA color value used by Figma variables of type COLOR.
|
|
32
32
|
*
|
|
@@ -66,7 +66,7 @@ export interface Color {
|
|
|
66
66
|
*/
|
|
67
67
|
export interface VariableAlias {
|
|
68
68
|
/** Type identifier for variable alias objects. Always 'VARIABLE_ALIAS'. */
|
|
69
|
-
type:
|
|
69
|
+
type: 'VARIABLE_ALIAS';
|
|
70
70
|
/** The referenced variable's Figma variable ID. */
|
|
71
71
|
id: string;
|
|
72
72
|
}
|
|
@@ -216,6 +216,28 @@ export interface LocalVariablesResponse {
|
|
|
216
216
|
variables: Record<string, FigmaVariable>;
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
+
export interface PublishedVariable {
|
|
220
|
+
id: string;
|
|
221
|
+
subscribed_id: string;
|
|
222
|
+
name: string;
|
|
223
|
+
key: string;
|
|
224
|
+
variableCollectionId: string;
|
|
225
|
+
resolvedType: ResolvedType;
|
|
226
|
+
updatedAt: string;
|
|
227
|
+
}
|
|
228
|
+
export interface PublishedVariableCollection {
|
|
229
|
+
id: string;
|
|
230
|
+
subscribed_id: string;
|
|
231
|
+
name: string;
|
|
232
|
+
key: string;
|
|
233
|
+
updatedAt: string;
|
|
234
|
+
}
|
|
235
|
+
export interface PublishedVariablesResponse {
|
|
236
|
+
meta: {
|
|
237
|
+
variableCollections: Record<string, PublishedVariableCollection>;
|
|
238
|
+
variables: Record<string, PublishedVariable>;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
219
241
|
/**
|
|
220
242
|
* Standard error response shape for Figma API error objects.
|
|
221
243
|
*
|
|
@@ -242,4 +264,35 @@ export interface FigmaError {
|
|
|
242
264
|
/** Human-readable error message describing the failure. */
|
|
243
265
|
message: string;
|
|
244
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Custom Error class for Figma API errors that preserves HTTP status codes.
|
|
269
|
+
*
|
|
270
|
+
* @remarks
|
|
271
|
+
* Extends the standard Error class to include HTTP status code information,
|
|
272
|
+
* making it easier for consumers to handle different error types (401, 403, 404, 429, etc.).
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* import { FigmaApiError } from '@figma-vars/hooks';
|
|
277
|
+
*
|
|
278
|
+
* try {
|
|
279
|
+
* await fetcher(url, token);
|
|
280
|
+
* } catch (error) {
|
|
281
|
+
* if (error instanceof FigmaApiError) {
|
|
282
|
+
* if (error.statusCode === 401) {
|
|
283
|
+
* // Handle authentication error
|
|
284
|
+
* } else if (error.statusCode === 429) {
|
|
285
|
+
* // Handle rate limit
|
|
286
|
+
* }
|
|
287
|
+
* }
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* @public
|
|
292
|
+
*/
|
|
293
|
+
export declare class FigmaApiError extends Error {
|
|
294
|
+
/** HTTP status code from the API response. */
|
|
295
|
+
readonly statusCode: number;
|
|
296
|
+
constructor(message: string, statusCode: number);
|
|
297
|
+
}
|
|
245
298
|
//# sourceMappingURL=figma.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figma.d.ts","sourceRoot":"","sources":["../../src/types/figma.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"figma.d.ts","sourceRoot":"","sources":["../../src/types/figma.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEnE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,cAAc,GACd,eAAe,GACf,cAAc,GACd,KAAK,GACL,cAAc,GACd,SAAS,GACT,cAAc,GACd,aAAa,GACb,WAAW,GACX,aAAa,GACb,gBAAgB,GAChB,mBAAmB,GACnB,kBAAkB,GAClB,aAAa,GACb,YAAY,GACZ,iBAAiB,GACjB,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,cAAc,GACd,cAAc,CAAA;AAElB;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,KAAK;IACpB,uBAAuB;IACvB,CAAC,EAAE,MAAM,CAAA;IACT,yBAAyB;IACzB,CAAC,EAAE,MAAM,CAAA;IACT,wBAAwB;IACxB,CAAC,EAAE,MAAM,CAAA;IACT,mCAAmC;IACnC,CAAC,EAAE,MAAM,CAAA;CACV;AAED;;;;;;;;;;;;GA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AY,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/types/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAA;IAClB,mEAAmE;IACnE,OAAO,EAAE,qBAAqB,CAAA;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,sBAAsB;IACrC,0DAA0D;IAC1D,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,sEAAsE;IACtE,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAA;IACnD,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CACxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,cAAc,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedType, VariableScope, VariableValue } from './figma';
|
|
1
|
+
import { ResolvedType, VariableScope, VariableValue } from './figma.js';
|
|
2
2
|
/**
|
|
3
3
|
* Payload for creating a new Figma variable in a specific collection.
|
|
4
4
|
*
|
|
@@ -80,7 +80,7 @@ export interface UpdateVariablePayload {
|
|
|
80
80
|
*
|
|
81
81
|
* @public
|
|
82
82
|
*/
|
|
83
|
-
export type VariableAction =
|
|
83
|
+
export type VariableAction = 'CREATE' | 'UPDATE' | 'DELETE';
|
|
84
84
|
/**
|
|
85
85
|
* Represents a change operation on a Figma variable collection.
|
|
86
86
|
*
|
|
@@ -288,7 +288,7 @@ export interface BulkUpdateResponse {
|
|
|
288
288
|
* @public
|
|
289
289
|
*/
|
|
290
290
|
export interface MutationState<TData> {
|
|
291
|
-
status:
|
|
291
|
+
status: 'idle' | 'loading' | 'success' | 'error';
|
|
292
292
|
data: TData | null;
|
|
293
293
|
error: Error | null;
|
|
294
294
|
}
|
|
@@ -305,7 +305,7 @@ export interface MutationState<TData> {
|
|
|
305
305
|
*/
|
|
306
306
|
export interface MutationResult<TData, TPayload> {
|
|
307
307
|
mutate: (payload: TPayload) => Promise<TData | undefined>;
|
|
308
|
-
status:
|
|
308
|
+
status: 'idle' | 'loading' | 'success' | 'error';
|
|
309
309
|
data: TData | null;
|
|
310
310
|
error: Error | null;
|
|
311
311
|
isLoading: boolean;
|