@figma-vars/hooks 3.0.0-beta.1 → 3.1.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 +417 -173
- package/dist/api/fetcher.d.ts +32 -1
- package/dist/api/fetcher.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/mutator.d.ts +36 -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 +3 -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 +64 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
- package/dist/hooks/useCollectionById.d.ts +31 -0
- package/dist/hooks/useCollectionById.d.ts.map +1 -0
- 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 +34 -0
- package/dist/hooks/useInvalidateVariables.d.ts.map +1 -0
- package/dist/hooks/useModesByCollection.d.ts +34 -0
- package/dist/hooks/useModesByCollection.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/useVariableById.d.ts +31 -0
- package/dist/hooks/useVariableById.d.ts.map +1 -0
- 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-5ZyKWuYv.cjs +1 -0
- package/dist/index-ClHLYVvu.js +142 -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 +319 -163
- package/dist/types/contexts.d.ts +30 -3
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/figma.d.ts +64 -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 +18 -4
- package/dist/types/mutations.d.ts.map +1 -1
- package/dist/utils/errorHelpers.d.ts +142 -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 +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/swrKeys.d.ts +24 -0
- package/dist/utils/swrKeys.d.ts.map +1 -0
- package/dist/utils/typeGuards.d.ts +50 -0
- package/dist/utils/typeGuards.d.ts.map +1 -0
- 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,357 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { jsx as O } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as P, useId as _, useMemo as p, useContext as x, useReducer as L, useRef as m, useEffect as g, useCallback as T } from "react";
|
|
3
|
+
import V, { useSWRConfig as j } from "swr";
|
|
4
|
+
import { f as A, E as b, a as E, m as y, F as h, b as D } from "./index-ClHLYVvu.js";
|
|
5
|
+
import { c as ie } from "./index-ClHLYVvu.js";
|
|
6
|
+
const C = P(void 0);
|
|
7
|
+
function S(e) {
|
|
8
|
+
if (typeof e != "object" || e === null)
|
|
9
|
+
return !1;
|
|
10
|
+
const r = e;
|
|
11
|
+
if (typeof r.meta != "object" || r.meta === null)
|
|
12
|
+
return !1;
|
|
13
|
+
const t = r.meta;
|
|
14
|
+
return !(typeof t.variableCollections != "object" || t.variableCollections === null || typeof t.variables != "object" || t.variables === null);
|
|
15
|
+
}
|
|
16
|
+
function I(e) {
|
|
17
|
+
if (S(e))
|
|
18
|
+
return e;
|
|
19
|
+
}
|
|
20
|
+
const W = ({
|
|
21
|
+
children: e,
|
|
22
|
+
token: r,
|
|
23
|
+
fileKey: t,
|
|
24
|
+
fallbackFile: o,
|
|
25
|
+
swrConfig: n
|
|
9
26
|
}) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
const a = _(), c = p(() => `figma-vars-provider-${a}`, [a]), u = p(() => {
|
|
28
|
+
if (o) {
|
|
29
|
+
if (typeof o == "object") {
|
|
30
|
+
const s = I(o);
|
|
31
|
+
if (s)
|
|
32
|
+
return s;
|
|
33
|
+
process.env.NODE_ENV !== "production" && console.warn(
|
|
34
|
+
"[figma-vars-hooks] fallbackFile object does not match expected Figma Variables API response structure. Expected { meta: { variableCollections: {...}, variables: {...} } }"
|
|
35
|
+
);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (typeof o == "string")
|
|
39
|
+
try {
|
|
40
|
+
const s = JSON.parse(o), l = I(s);
|
|
41
|
+
if (l)
|
|
42
|
+
return l;
|
|
43
|
+
process.env.NODE_ENV !== "production" && console.warn(
|
|
44
|
+
"[figma-vars-hooks] Parsed fallbackFile JSON does not match expected Figma Variables API response structure. Expected { meta: { variableCollections: {...}, variables: {...} } }"
|
|
45
|
+
);
|
|
46
|
+
return;
|
|
47
|
+
} catch (s) {
|
|
48
|
+
process.env.NODE_ENV !== "production" && console.error(
|
|
49
|
+
`[figma-vars-hooks] Failed to parse fallbackFile JSON: ${s instanceof Error ? s.message : "Unknown error"}`
|
|
50
|
+
);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
34
53
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
}, [o]), i = p(() => {
|
|
55
|
+
const s = {
|
|
56
|
+
token: r,
|
|
57
|
+
fileKey: t,
|
|
58
|
+
providerId: c,
|
|
59
|
+
...n !== void 0 && { swrConfig: n }
|
|
60
|
+
};
|
|
61
|
+
return o === void 0 ? s : {
|
|
62
|
+
...s,
|
|
63
|
+
fallbackFile: o,
|
|
64
|
+
// Keep for backward compatibility
|
|
65
|
+
parsedFallbackFile: u
|
|
66
|
+
// Pre-parsed version for hooks to use
|
|
67
|
+
};
|
|
68
|
+
}, [r, t, o, u, c, n]);
|
|
69
|
+
return /* @__PURE__ */ O(C.Provider, { value: i, children: e });
|
|
70
|
+
}, d = () => {
|
|
71
|
+
const e = x(C);
|
|
72
|
+
if (e === void 0)
|
|
73
|
+
throw new Error(
|
|
74
|
+
"useFigmaTokenContext must be used within a FigmaVarsProvider"
|
|
75
|
+
);
|
|
76
|
+
return e;
|
|
77
|
+
};
|
|
78
|
+
function N(e) {
|
|
79
|
+
const { fileKey: r, token: t, providerId: o, hasFallback: n } = e;
|
|
80
|
+
return !!(t && r) && t && r ? [`https://api.figma.com/v1/files/${r}/variables/local`, t] : n ? [`fallback-${o ?? "default"}`, "fallback"] : null;
|
|
81
|
+
}
|
|
82
|
+
function B(e) {
|
|
83
|
+
const { fileKey: r, token: t, providerId: o, hasFallback: n } = e;
|
|
84
|
+
return !!(t && r) && t && r ? [`https://api.figma.com/v1/files/${r}/variables/published`, t] : n ? [`fallback-${o ?? "default"}`, "fallback"] : null;
|
|
38
85
|
}
|
|
39
|
-
|
|
40
|
-
const { token: t,
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
86
|
+
function F(e) {
|
|
87
|
+
const { fileKey: r, token: t, providerId: o, hasFallback: n } = e, a = [];
|
|
88
|
+
return t && r && (a.push([
|
|
89
|
+
`https://api.figma.com/v1/files/${r}/variables/local`,
|
|
90
|
+
t
|
|
91
|
+
]), a.push([
|
|
92
|
+
`https://api.figma.com/v1/files/${r}/variables/published`,
|
|
93
|
+
t
|
|
94
|
+
])), n && o && a.push([`fallback-${o}`, "fallback"]), a;
|
|
95
|
+
}
|
|
96
|
+
const K = () => {
|
|
97
|
+
const {
|
|
98
|
+
token: e,
|
|
99
|
+
fileKey: r,
|
|
100
|
+
fallbackFile: t,
|
|
101
|
+
parsedFallbackFile: o,
|
|
102
|
+
providerId: n,
|
|
103
|
+
swrConfig: a
|
|
104
|
+
} = d(), u = N({
|
|
105
|
+
fileKey: r,
|
|
106
|
+
token: e,
|
|
107
|
+
providerId: n,
|
|
108
|
+
hasFallback: !!(t || o)
|
|
109
|
+
});
|
|
110
|
+
return V(
|
|
111
|
+
u,
|
|
112
|
+
async (...s) => {
|
|
113
|
+
if (o)
|
|
114
|
+
return o;
|
|
115
|
+
if (t && typeof t == "object")
|
|
116
|
+
return t;
|
|
117
|
+
const [l, f] = Array.isArray(s[0]) ? s[0] : [s[0], s[1]];
|
|
118
|
+
if (!l || !f)
|
|
119
|
+
throw new Error("Missing URL or token for live API request");
|
|
120
|
+
return A(l, f);
|
|
121
|
+
},
|
|
122
|
+
a
|
|
44
123
|
);
|
|
45
|
-
},
|
|
46
|
-
const { data:
|
|
47
|
-
() =>
|
|
48
|
-
[
|
|
49
|
-
),
|
|
50
|
-
() =>
|
|
51
|
-
[
|
|
124
|
+
}, H = () => {
|
|
125
|
+
const { data: e } = K(), r = p(
|
|
126
|
+
() => e != null && e.meta ? Object.values(e.meta.variableCollections) : [],
|
|
127
|
+
[e]
|
|
128
|
+
), t = p(
|
|
129
|
+
() => e != null && e.meta ? e.meta.variableCollections : {},
|
|
130
|
+
[e]
|
|
52
131
|
);
|
|
53
132
|
return {
|
|
54
|
-
collections:
|
|
55
|
-
collectionsById:
|
|
133
|
+
collections: r,
|
|
134
|
+
collectionsById: t
|
|
56
135
|
};
|
|
57
|
-
},
|
|
58
|
-
const { data:
|
|
59
|
-
return
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
for (const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
136
|
+
}, Y = () => {
|
|
137
|
+
const { data: e } = K();
|
|
138
|
+
return p(() => {
|
|
139
|
+
const r = [], t = {}, o = {};
|
|
140
|
+
if (e != null && e.meta)
|
|
141
|
+
for (const n of Object.values(
|
|
142
|
+
e.meta.variableCollections
|
|
143
|
+
)) {
|
|
144
|
+
r.push(...n.modes), t[n.id] = n.modes;
|
|
145
|
+
for (const a of n.modes)
|
|
146
|
+
o[a.modeId] = a;
|
|
66
147
|
}
|
|
67
148
|
return {
|
|
68
|
-
modes:
|
|
69
|
-
modesByCollectionId:
|
|
70
|
-
modesById:
|
|
149
|
+
modes: r,
|
|
150
|
+
modesByCollectionId: t,
|
|
151
|
+
modesById: o
|
|
71
152
|
};
|
|
72
|
-
}, [
|
|
153
|
+
}, [e]);
|
|
73
154
|
};
|
|
74
|
-
function
|
|
75
|
-
switch (
|
|
155
|
+
function M(e, r) {
|
|
156
|
+
switch (r.type) {
|
|
76
157
|
case "loading":
|
|
77
|
-
return { ...
|
|
158
|
+
return { ...e, status: "loading", error: null };
|
|
78
159
|
case "success":
|
|
79
|
-
return { ...
|
|
160
|
+
return { ...e, status: "success", data: r.payload };
|
|
80
161
|
case "error":
|
|
81
|
-
return { ...
|
|
162
|
+
return { ...e, status: "error", error: r.payload };
|
|
82
163
|
default:
|
|
83
|
-
return
|
|
164
|
+
return e;
|
|
84
165
|
}
|
|
85
166
|
}
|
|
86
|
-
const
|
|
87
|
-
const o = {
|
|
167
|
+
const k = (e, r) => {
|
|
168
|
+
const { throwOnError: t = !1 } = {}, o = {
|
|
88
169
|
status: "idle",
|
|
89
170
|
data: null,
|
|
90
171
|
error: null
|
|
91
|
-
}, [
|
|
92
|
-
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
172
|
+
}, [n, a] = L(M, o), c = m(e), u = m({ throwOnError: t }), i = m(!0), s = m(0);
|
|
173
|
+
return g(() => {
|
|
174
|
+
c.current = e, u.current = { throwOnError: t };
|
|
175
|
+
}, [e, t]), g(() => (i.current = !0, () => {
|
|
176
|
+
i.current = !1;
|
|
177
|
+
}), []), {
|
|
178
|
+
mutate: T(
|
|
179
|
+
async (f) => {
|
|
180
|
+
if (!i.current)
|
|
181
|
+
return;
|
|
182
|
+
const w = ++s.current;
|
|
183
|
+
a({ type: "loading" });
|
|
96
184
|
try {
|
|
97
|
-
const
|
|
98
|
-
return
|
|
99
|
-
} catch (
|
|
100
|
-
|
|
185
|
+
const v = await c.current(f);
|
|
186
|
+
return i.current && w === s.current && a({ type: "success", payload: v }), v;
|
|
187
|
+
} catch (v) {
|
|
188
|
+
const R = v;
|
|
189
|
+
if (i.current && w === s.current && a({ type: "error", payload: R }), u.current.throwOnError)
|
|
190
|
+
throw R;
|
|
101
191
|
return;
|
|
102
192
|
}
|
|
103
193
|
},
|
|
104
|
-
[
|
|
194
|
+
[]
|
|
195
|
+
// Empty deps array - mutationFn and options are accessed via refs
|
|
105
196
|
),
|
|
106
|
-
...
|
|
107
|
-
isLoading:
|
|
108
|
-
isSuccess:
|
|
109
|
-
isError:
|
|
197
|
+
...n,
|
|
198
|
+
isLoading: n.status === "loading",
|
|
199
|
+
isSuccess: n.status === "success",
|
|
200
|
+
isError: n.status === "error"
|
|
110
201
|
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
r && (a.body = JSON.stringify(r));
|
|
127
|
-
const i = await fetch(`${p}${t}`, a);
|
|
128
|
-
if (!i.ok) {
|
|
129
|
-
const E = await i.json().catch(() => ({}));
|
|
130
|
-
throw new Error(E.err || E.message || "An API error occurred");
|
|
131
|
-
}
|
|
132
|
-
return i.status === 204 || !i.body ? {} : i.json();
|
|
133
|
-
}
|
|
134
|
-
const G = () => {
|
|
135
|
-
const { token: t } = u();
|
|
136
|
-
return l(async (e) => {
|
|
137
|
-
if (!t)
|
|
138
|
-
throw new Error(c);
|
|
139
|
-
return await m(
|
|
140
|
-
w,
|
|
141
|
-
t,
|
|
142
|
-
"CREATE",
|
|
143
|
-
e
|
|
144
|
-
);
|
|
202
|
+
}, z = () => {
|
|
203
|
+
const { token: e, fileKey: r } = d();
|
|
204
|
+
return k(async (o) => {
|
|
205
|
+
if (!e)
|
|
206
|
+
throw new Error(b);
|
|
207
|
+
if (!r)
|
|
208
|
+
throw new Error(E);
|
|
209
|
+
return await y(h(r), e, "CREATE", {
|
|
210
|
+
variables: [
|
|
211
|
+
{
|
|
212
|
+
action: "CREATE",
|
|
213
|
+
...o
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
});
|
|
145
217
|
});
|
|
146
|
-
},
|
|
147
|
-
const { token:
|
|
148
|
-
return
|
|
149
|
-
async ({
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
218
|
+
}, X = () => {
|
|
219
|
+
const { token: e, fileKey: r } = d();
|
|
220
|
+
return k(
|
|
221
|
+
async ({
|
|
222
|
+
variableId: o,
|
|
223
|
+
payload: n
|
|
224
|
+
}) => {
|
|
225
|
+
if (!e)
|
|
226
|
+
throw new Error(b);
|
|
227
|
+
if (!r)
|
|
228
|
+
throw new Error(E);
|
|
229
|
+
return await y(
|
|
230
|
+
h(r),
|
|
231
|
+
e,
|
|
155
232
|
"UPDATE",
|
|
156
|
-
|
|
233
|
+
{
|
|
234
|
+
variables: [
|
|
235
|
+
{
|
|
236
|
+
action: "UPDATE",
|
|
237
|
+
id: o,
|
|
238
|
+
...n
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
}
|
|
157
242
|
);
|
|
158
243
|
}
|
|
159
244
|
);
|
|
160
|
-
},
|
|
161
|
-
const { token:
|
|
162
|
-
return
|
|
163
|
-
if (!
|
|
164
|
-
throw new Error(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
245
|
+
}, Z = () => {
|
|
246
|
+
const { token: e, fileKey: r } = d();
|
|
247
|
+
return k(async (o) => {
|
|
248
|
+
if (!e)
|
|
249
|
+
throw new Error(b);
|
|
250
|
+
if (!r)
|
|
251
|
+
throw new Error(E);
|
|
252
|
+
return await y(h(r), e, "DELETE", {
|
|
253
|
+
variables: [
|
|
254
|
+
{
|
|
255
|
+
action: "DELETE",
|
|
256
|
+
id: o
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
});
|
|
171
260
|
});
|
|
172
|
-
},
|
|
173
|
-
const { token:
|
|
174
|
-
return
|
|
175
|
-
if (!
|
|
176
|
-
throw new Error(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
e
|
|
261
|
+
}, ee = () => {
|
|
262
|
+
const { token: e, fileKey: r } = d();
|
|
263
|
+
return k(async (o) => {
|
|
264
|
+
if (!e)
|
|
265
|
+
throw new Error(b);
|
|
266
|
+
if (!r)
|
|
267
|
+
throw new Error(E);
|
|
268
|
+
return await y(
|
|
269
|
+
h(r),
|
|
270
|
+
e,
|
|
271
|
+
"UPDATE",
|
|
272
|
+
o
|
|
182
273
|
);
|
|
183
274
|
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
275
|
+
}, re = () => {
|
|
276
|
+
const { mutate: e } = j(), { token: r, fileKey: t, fallbackFile: o, providerId: n } = d(), a = !!o;
|
|
277
|
+
return {
|
|
278
|
+
invalidate: () => {
|
|
279
|
+
const i = F({
|
|
280
|
+
fileKey: t,
|
|
281
|
+
token: r,
|
|
282
|
+
providerId: n,
|
|
283
|
+
hasFallback: a
|
|
284
|
+
});
|
|
285
|
+
for (const s of i)
|
|
286
|
+
e(s);
|
|
287
|
+
},
|
|
288
|
+
revalidate: () => {
|
|
289
|
+
const i = F({
|
|
290
|
+
fileKey: t,
|
|
291
|
+
token: r,
|
|
292
|
+
providerId: n,
|
|
293
|
+
hasFallback: a
|
|
294
|
+
});
|
|
295
|
+
for (const s of i)
|
|
296
|
+
e(s, void 0, { revalidate: !0 });
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}, te = () => {
|
|
300
|
+
const {
|
|
301
|
+
token: e,
|
|
302
|
+
fileKey: r,
|
|
303
|
+
fallbackFile: t,
|
|
304
|
+
parsedFallbackFile: o,
|
|
305
|
+
providerId: n,
|
|
306
|
+
swrConfig: a
|
|
307
|
+
} = d(), u = B({
|
|
308
|
+
fileKey: r,
|
|
309
|
+
token: e,
|
|
310
|
+
providerId: n,
|
|
311
|
+
hasFallback: !!(t || o)
|
|
189
312
|
});
|
|
313
|
+
return V(
|
|
314
|
+
u,
|
|
315
|
+
async (...s) => {
|
|
316
|
+
if (o)
|
|
317
|
+
return o;
|
|
318
|
+
if (t && typeof t == "object")
|
|
319
|
+
return t;
|
|
320
|
+
const [l, f] = Array.isArray(s[0]) ? s[0] : [s[0], s[1]];
|
|
321
|
+
if (!l || !f)
|
|
322
|
+
throw new Error("Missing URL or token for live API request");
|
|
323
|
+
return A(l, f);
|
|
324
|
+
},
|
|
325
|
+
a
|
|
326
|
+
);
|
|
327
|
+
};
|
|
328
|
+
function U(e) {
|
|
329
|
+
return e instanceof D;
|
|
330
|
+
}
|
|
331
|
+
function $(e) {
|
|
332
|
+
return U(e) ? e.statusCode : null;
|
|
333
|
+
}
|
|
334
|
+
function oe(e, r = "An error occurred") {
|
|
335
|
+
return e instanceof Error ? e.message || r : typeof e == "string" ? e : r;
|
|
336
|
+
}
|
|
337
|
+
function ne(e, r) {
|
|
338
|
+
return $(e) === r;
|
|
190
339
|
}
|
|
191
340
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
341
|
+
D as FigmaApiError,
|
|
342
|
+
W as FigmaVarsProvider,
|
|
343
|
+
ie as filterVariables,
|
|
344
|
+
oe as getErrorMessage,
|
|
345
|
+
$ as getErrorStatus,
|
|
346
|
+
ne as hasErrorStatus,
|
|
347
|
+
U as isFigmaApiError,
|
|
348
|
+
ee as useBulkUpdateVariables,
|
|
349
|
+
z as useCreateVariable,
|
|
350
|
+
Z as useDeleteVariable,
|
|
351
|
+
re as useInvalidateVariables,
|
|
352
|
+
te as usePublishedVariables,
|
|
353
|
+
X as useUpdateVariable,
|
|
354
|
+
H as useVariableCollections,
|
|
355
|
+
Y as useVariableModes,
|
|
356
|
+
K as useVariables
|
|
201
357
|
};
|
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
|
*
|
|
@@ -40,8 +41,14 @@ export interface FigmaTokenContextType {
|
|
|
40
41
|
/**
|
|
41
42
|
* Optional fallback variable JSON file for offline or static use cases.
|
|
42
43
|
* Allows FigmaVars to function without a live API request.
|
|
44
|
+
* @deprecated Use parsedFallbackFile instead. This is kept for backward compatibility.
|
|
43
45
|
*/
|
|
44
|
-
fallbackFile?: LocalVariablesResponse | string;
|
|
46
|
+
fallbackFile?: LocalVariablesResponse | PublishedVariablesResponse | string;
|
|
47
|
+
/**
|
|
48
|
+
* Optional SWR configuration to customize caching, revalidation, and error handling behavior.
|
|
49
|
+
* Applied to all SWR hooks within this provider.
|
|
50
|
+
*/
|
|
51
|
+
swrConfig?: SWRConfiguration | undefined;
|
|
45
52
|
}
|
|
46
53
|
/**
|
|
47
54
|
* Props for the FigmaVarsProvider component, which injects Figma API authentication and file scoping for all descendant hooks and utilities.
|
|
@@ -83,6 +90,26 @@ export interface FigmaVarsProviderProps {
|
|
|
83
90
|
/**
|
|
84
91
|
* Optional fallback variable JSON file used when the API is unavailable or skipped.
|
|
85
92
|
*/
|
|
86
|
-
fallbackFile?: LocalVariablesResponse | string;
|
|
93
|
+
fallbackFile?: LocalVariablesResponse | PublishedVariablesResponse | string;
|
|
94
|
+
/**
|
|
95
|
+
* Optional SWR configuration to customize caching, revalidation, and error handling.
|
|
96
|
+
* Common options: `revalidateOnFocus`, `dedupingInterval`, `errorRetryCount`, `onError`, etc.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```tsx
|
|
100
|
+
* <FigmaVarsProvider
|
|
101
|
+
* token={token}
|
|
102
|
+
* fileKey={fileKey}
|
|
103
|
+
* swrConfig={{
|
|
104
|
+
* revalidateOnFocus: false,
|
|
105
|
+
* dedupingInterval: 5000,
|
|
106
|
+
* errorRetryCount: 3,
|
|
107
|
+
* }}
|
|
108
|
+
* >
|
|
109
|
+
* <App />
|
|
110
|
+
* </FigmaVarsProvider>
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
swrConfig?: SWRConfiguration;
|
|
87
114
|
}
|
|
88
115
|
//# 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;;;;OAIG;IACH,YAAY,CAAC,EAAE,sBAAsB,GAAG,0BAA0B,GAAG,MAAM,CAAA;IAe3E;;;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"}
|