@figma-vars/hooks 1.3.3 → 1.4.3
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 +85 -19
- package/dist/figma-vars-hooks.js +312 -296
- package/dist/figma-vars-hooks.umd.cjs +3 -3
- package/dist/src/api/fetcher.d.ts +28 -0
- package/dist/src/api/index.d.ts +25 -0
- package/dist/src/api/mutator.d.ts +33 -0
- package/dist/src/api/mutator.test.d.ts +1 -0
- package/dist/src/constants/index.d.ts +89 -0
- package/dist/src/contexts/FigmaVarsProvider.d.ts +56 -0
- package/dist/src/contexts/index.d.ts +21 -0
- package/dist/src/hooks/index.d.ts +143 -0
- package/dist/src/hooks/useBulkUpdateVariables.d.ts +46 -0
- package/dist/src/hooks/useCreateVariable.d.ts +45 -0
- package/dist/src/hooks/useDeleteVariable.d.ts +33 -0
- package/dist/src/hooks/useFigmaToken.d.ts +21 -0
- package/dist/src/hooks/useMutation.d.ts +53 -0
- package/dist/src/hooks/useUpdateVariable.d.ts +40 -0
- package/dist/src/hooks/useVariableCollections.d.ts +35 -0
- package/dist/src/hooks/useVariableModes.d.ts +32 -0
- package/dist/src/hooks/useVariables.d.ts +32 -0
- package/dist/src/index.d.ts +80 -0
- package/dist/src/types/contexts.d.ts +77 -0
- package/dist/src/types/figma.d.ts +244 -0
- package/dist/src/types/hooks.d.ts +67 -0
- package/dist/src/types/index.d.ts +30 -0
- package/dist/src/types/mutations.d.ts +314 -0
- package/dist/src/utils/filterVariables.d.ts +31 -0
- package/dist/src/utils/index.d.ts +21 -0
- package/dist/tests/FigmaVarsProvider.test.d.ts +1 -0
- package/dist/tests/api/fetcher.test.d.ts +1 -0
- package/dist/tests/api/mutator.test.d.ts +1 -0
- package/dist/tests/constants/index.test.d.ts +1 -0
- package/dist/tests/hooks/useBulkUpdateVariables.test.d.ts +1 -0
- package/dist/tests/hooks/useCreateVariable.test.d.ts +1 -0
- package/dist/tests/hooks/useDeleteVariable.test.d.ts +1 -0
- package/dist/tests/hooks/useMutation.test.d.ts +1 -0
- package/dist/tests/hooks/useUpdateVariable.test.d.ts +1 -0
- package/dist/tests/hooks/useVariableCollections.test.d.ts +1 -0
- package/dist/tests/hooks/useVariableModes.test.d.ts +1 -0
- package/dist/tests/hooks/useVariables.test.d.ts +1 -0
- package/dist/tests/mocks/variables.d.ts +2 -0
- package/dist/tests/setup.d.ts +0 -0
- package/dist/tests/test-utils.d.ts +10 -0
- package/dist/tests/test-utils.test.d.ts +1 -0
- package/package.json +4 -2
- package/dist/index.d.ts +0 -1221
package/dist/figma-vars-hooks.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import et, { createContext as
|
|
3
|
-
const
|
|
1
|
+
import { jsx as Oe } from "react/jsx-runtime";
|
|
2
|
+
import et, { createContext as Zt, useContext as te, useEffect as ve, useLayoutEffect as we, useRef as $, useMemo as ft, useCallback as lt, useDebugValue as Re, useReducer as Te } from "react";
|
|
3
|
+
const ee = Zt(
|
|
4
4
|
void 0
|
|
5
5
|
), En = ({
|
|
6
6
|
children: t,
|
|
7
7
|
token: e,
|
|
8
8
|
fileKey: n
|
|
9
|
-
}) => /* @__PURE__ */
|
|
10
|
-
const t =
|
|
9
|
+
}) => /* @__PURE__ */ Oe(ee.Provider, { value: { token: e, fileKey: n }, children: t }), nt = () => {
|
|
10
|
+
const t = te(ee);
|
|
11
11
|
if (t === void 0)
|
|
12
12
|
throw new Error(
|
|
13
13
|
"useFigmaTokenContext must be used within a FigmaVarsProvider"
|
|
14
14
|
);
|
|
15
15
|
return t;
|
|
16
16
|
};
|
|
17
|
-
var at = { exports: {} },
|
|
17
|
+
var at = { exports: {} }, _t = {};
|
|
18
18
|
/**
|
|
19
19
|
* @license React
|
|
20
20
|
* use-sync-external-store-shim.production.js
|
|
@@ -24,32 +24,32 @@ var at = { exports: {} }, St = {};
|
|
|
24
24
|
* This source code is licensed under the MIT license found in the
|
|
25
25
|
* LICENSE file in the root directory of this source tree.
|
|
26
26
|
*/
|
|
27
|
-
var
|
|
28
|
-
function
|
|
29
|
-
if (
|
|
30
|
-
|
|
27
|
+
var Ht;
|
|
28
|
+
function ye() {
|
|
29
|
+
if (Ht) return _t;
|
|
30
|
+
Ht = 1;
|
|
31
31
|
var t = et;
|
|
32
32
|
function e(u, d) {
|
|
33
33
|
return u === d && (u !== 0 || 1 / u === 1 / d) || u !== u && d !== d;
|
|
34
34
|
}
|
|
35
|
-
var n = typeof Object.is == "function" ? Object.is : e, r = t.useState, o = t.useEffect, s = t.useLayoutEffect,
|
|
36
|
-
function
|
|
37
|
-
var c = d(),
|
|
35
|
+
var n = typeof Object.is == "function" ? Object.is : e, r = t.useState, o = t.useEffect, s = t.useLayoutEffect, i = t.useDebugValue;
|
|
36
|
+
function E(u, d) {
|
|
37
|
+
var c = d(), p = r({ inst: { value: c, getSnapshot: d } }), l = p[0].inst, D = p[1];
|
|
38
38
|
return s(
|
|
39
39
|
function() {
|
|
40
|
-
l.value = c, l.getSnapshot = d,
|
|
40
|
+
l.value = c, l.getSnapshot = d, h(l) && D({ inst: l });
|
|
41
41
|
},
|
|
42
42
|
[u, c, d]
|
|
43
43
|
), o(
|
|
44
44
|
function() {
|
|
45
|
-
return
|
|
46
|
-
|
|
45
|
+
return h(l) && D({ inst: l }), u(function() {
|
|
46
|
+
h(l) && D({ inst: l });
|
|
47
47
|
});
|
|
48
48
|
},
|
|
49
49
|
[u]
|
|
50
|
-
),
|
|
50
|
+
), i(c), c;
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function h(u) {
|
|
53
53
|
var d = u.getSnapshot;
|
|
54
54
|
u = u.value;
|
|
55
55
|
try {
|
|
@@ -62,10 +62,10 @@ function Ae() {
|
|
|
62
62
|
function y(u, d) {
|
|
63
63
|
return d();
|
|
64
64
|
}
|
|
65
|
-
var O = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? y :
|
|
66
|
-
return
|
|
65
|
+
var O = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? y : E;
|
|
66
|
+
return _t.useSyncExternalStore = t.useSyncExternalStore !== void 0 ? t.useSyncExternalStore : O, _t;
|
|
67
67
|
}
|
|
68
|
-
var
|
|
68
|
+
var St = {};
|
|
69
69
|
/**
|
|
70
70
|
* @license React
|
|
71
71
|
* use-sync-external-store-shim.development.js
|
|
@@ -75,67 +75,67 @@ var ht = {};
|
|
|
75
75
|
* This source code is licensed under the MIT license found in the
|
|
76
76
|
* LICENSE file in the root directory of this source tree.
|
|
77
77
|
*/
|
|
78
|
-
var
|
|
79
|
-
function
|
|
80
|
-
return
|
|
81
|
-
function t(c,
|
|
82
|
-
return c ===
|
|
78
|
+
var kt;
|
|
79
|
+
function ge() {
|
|
80
|
+
return kt || (kt = 1, process.env.NODE_ENV !== "production" && function() {
|
|
81
|
+
function t(c, p) {
|
|
82
|
+
return c === p && (c !== 0 || 1 / c === 1 / p) || c !== c && p !== p;
|
|
83
83
|
}
|
|
84
|
-
function e(c,
|
|
84
|
+
function e(c, p) {
|
|
85
85
|
O || o.startTransition === void 0 || (O = !0, console.error(
|
|
86
86
|
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
87
87
|
));
|
|
88
|
-
var l =
|
|
88
|
+
var l = p();
|
|
89
89
|
if (!u) {
|
|
90
|
-
var D =
|
|
90
|
+
var D = p();
|
|
91
91
|
s(l, D) || (console.error(
|
|
92
92
|
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
93
93
|
), u = !0);
|
|
94
94
|
}
|
|
95
|
-
D =
|
|
96
|
-
inst: { value: l, getSnapshot:
|
|
95
|
+
D = i({
|
|
96
|
+
inst: { value: l, getSnapshot: p }
|
|
97
97
|
});
|
|
98
|
-
var
|
|
99
|
-
return
|
|
98
|
+
var a = D[0].inst, P = D[1];
|
|
99
|
+
return h(
|
|
100
100
|
function() {
|
|
101
|
-
|
|
101
|
+
a.value = l, a.getSnapshot = p, n(a) && P({ inst: a });
|
|
102
102
|
},
|
|
103
|
-
[c, l,
|
|
104
|
-
),
|
|
103
|
+
[c, l, p]
|
|
104
|
+
), E(
|
|
105
105
|
function() {
|
|
106
|
-
return n(
|
|
107
|
-
n(
|
|
106
|
+
return n(a) && P({ inst: a }), c(function() {
|
|
107
|
+
n(a) && P({ inst: a });
|
|
108
108
|
});
|
|
109
109
|
},
|
|
110
110
|
[c]
|
|
111
111
|
), y(l), l;
|
|
112
112
|
}
|
|
113
113
|
function n(c) {
|
|
114
|
-
var
|
|
114
|
+
var p = c.getSnapshot;
|
|
115
115
|
c = c.value;
|
|
116
116
|
try {
|
|
117
|
-
var l =
|
|
117
|
+
var l = p();
|
|
118
118
|
return !s(c, l);
|
|
119
119
|
} catch {
|
|
120
120
|
return !0;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
function r(c,
|
|
124
|
-
return
|
|
123
|
+
function r(c, p) {
|
|
124
|
+
return p();
|
|
125
125
|
}
|
|
126
126
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
127
|
-
var o = et, s = typeof Object.is == "function" ? Object.is : t,
|
|
128
|
-
|
|
129
|
-
}()),
|
|
127
|
+
var o = et, s = typeof Object.is == "function" ? Object.is : t, i = o.useState, E = o.useEffect, h = o.useLayoutEffect, y = o.useDebugValue, O = !1, u = !1, d = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? r : e;
|
|
128
|
+
St.useSyncExternalStore = o.useSyncExternalStore !== void 0 ? o.useSyncExternalStore : d, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
129
|
+
}()), St;
|
|
130
130
|
}
|
|
131
|
-
var
|
|
132
|
-
function
|
|
133
|
-
return
|
|
131
|
+
var Kt;
|
|
132
|
+
function Ae() {
|
|
133
|
+
return Kt || (Kt = 1, process.env.NODE_ENV === "production" ? at.exports = ye() : at.exports = ge()), at.exports;
|
|
134
134
|
}
|
|
135
|
-
var
|
|
136
|
-
const
|
|
137
|
-
var
|
|
138
|
-
function
|
|
135
|
+
var De = Ae();
|
|
136
|
+
const ne = 0, re = 1, oe = 2, Jt = 3;
|
|
137
|
+
var Yt = Object.prototype.hasOwnProperty;
|
|
138
|
+
function gt(t, e) {
|
|
139
139
|
var n, r;
|
|
140
140
|
if (t === e) return !0;
|
|
141
141
|
if (t && e && (n = t.constructor) === e.constructor) {
|
|
@@ -143,27 +143,27 @@ function Tt(t, e) {
|
|
|
143
143
|
if (n === RegExp) return t.toString() === e.toString();
|
|
144
144
|
if (n === Array) {
|
|
145
145
|
if ((r = t.length) === e.length)
|
|
146
|
-
for (; r-- &&
|
|
146
|
+
for (; r-- && gt(t[r], e[r]); ) ;
|
|
147
147
|
return r === -1;
|
|
148
148
|
}
|
|
149
149
|
if (!n || typeof t == "object") {
|
|
150
150
|
r = 0;
|
|
151
151
|
for (n in t)
|
|
152
|
-
if (
|
|
152
|
+
if (Yt.call(t, n) && ++r && !Yt.call(e, n) || !(n in e) || !gt(t[n], e[n])) return !1;
|
|
153
153
|
return Object.keys(e).length === r;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
return t !== t && e !== e;
|
|
157
157
|
}
|
|
158
|
-
const
|
|
158
|
+
const M = /* @__PURE__ */ new WeakMap(), U = () => {
|
|
159
159
|
}, A = (
|
|
160
160
|
/*#__NOINLINE__*/
|
|
161
161
|
U()
|
|
162
162
|
), At = Object, f = (t) => t === A, N = (t) => typeof t == "function", G = (t, e) => ({
|
|
163
163
|
...t,
|
|
164
164
|
...e
|
|
165
|
-
}),
|
|
166
|
-
const n =
|
|
165
|
+
}), se = (t) => N(t.then), Ot = {}, ct = {}, Nt = "undefined", rt = typeof window != Nt, Dt = typeof document != Nt, Ie = rt && "Deno" in window, Le = () => rt && typeof window.requestAnimationFrame != Nt, ie = (t, e) => {
|
|
166
|
+
const n = M.get(t);
|
|
167
167
|
return [
|
|
168
168
|
// Getter
|
|
169
169
|
() => !f(e) && t.get(e) || Ot,
|
|
@@ -181,18 +181,18 @@ const P = /* @__PURE__ */ new WeakMap(), U = () => {
|
|
|
181
181
|
];
|
|
182
182
|
};
|
|
183
183
|
let It = !0;
|
|
184
|
-
const
|
|
184
|
+
const Ce = () => It, [Lt, Ct] = rt && window.addEventListener ? [
|
|
185
185
|
window.addEventListener.bind(window),
|
|
186
186
|
window.removeEventListener.bind(window)
|
|
187
187
|
] : [
|
|
188
188
|
U,
|
|
189
189
|
U
|
|
190
|
-
],
|
|
190
|
+
], be = () => {
|
|
191
191
|
const t = Dt && document.visibilityState;
|
|
192
192
|
return f(t) || t !== "hidden";
|
|
193
|
-
},
|
|
193
|
+
}, Ve = (t) => (Dt && document.addEventListener("visibilitychange", t), Lt("focus", t), () => {
|
|
194
194
|
Dt && document.removeEventListener("visibilitychange", t), Ct("focus", t);
|
|
195
|
-
}),
|
|
195
|
+
}), Ne = (t) => {
|
|
196
196
|
const e = () => {
|
|
197
197
|
It = !0, t();
|
|
198
198
|
}, n = () => {
|
|
@@ -201,32 +201,32 @@ const Ve = () => It, [Lt, Ct] = nt && window.addEventListener ? [
|
|
|
201
201
|
return Lt("online", e), Lt("offline", n), () => {
|
|
202
202
|
Ct("online", e), Ct("offline", n);
|
|
203
203
|
};
|
|
204
|
-
},
|
|
205
|
-
isOnline:
|
|
206
|
-
isVisible:
|
|
207
|
-
},
|
|
208
|
-
initFocus:
|
|
209
|
-
initReconnect:
|
|
210
|
-
},
|
|
204
|
+
}, Fe = {
|
|
205
|
+
isOnline: Ce,
|
|
206
|
+
isVisible: be
|
|
207
|
+
}, xe = {
|
|
208
|
+
initFocus: Ve,
|
|
209
|
+
initReconnect: Ne
|
|
210
|
+
}, zt = !et.useId, tt = !rt || Ie, Me = (t) => Le() ? window.requestAnimationFrame(t) : setTimeout(t, 1), vt = tt ? ve : we, wt = typeof navigator < "u" && navigator.connection, Xt = !tt && wt && ([
|
|
211
211
|
"slow-2g",
|
|
212
212
|
"2g"
|
|
213
213
|
].includes(wt.effectiveType) || wt.saveData), ut = /* @__PURE__ */ new WeakMap(), Rt = (t, e) => At.prototype.toString.call(t) === `[object ${e}]`;
|
|
214
|
-
let
|
|
214
|
+
let Pe = 0;
|
|
215
215
|
const bt = (t) => {
|
|
216
216
|
const e = typeof t, n = Rt(t, "Date"), r = Rt(t, "RegExp"), o = Rt(t, "Object");
|
|
217
|
-
let s,
|
|
217
|
+
let s, i;
|
|
218
218
|
if (At(t) === t && !n && !r) {
|
|
219
219
|
if (s = ut.get(t), s) return s;
|
|
220
|
-
if (s = ++
|
|
221
|
-
for (s = "@",
|
|
222
|
-
s += bt(t[
|
|
220
|
+
if (s = ++Pe + "~", ut.set(t, s), Array.isArray(t)) {
|
|
221
|
+
for (s = "@", i = 0; i < t.length; i++)
|
|
222
|
+
s += bt(t[i]) + ",";
|
|
223
223
|
ut.set(t, s);
|
|
224
224
|
}
|
|
225
225
|
if (o) {
|
|
226
226
|
s = "#";
|
|
227
|
-
const
|
|
228
|
-
for (; !f(
|
|
229
|
-
f(t[
|
|
227
|
+
const E = At.keys(t).sort();
|
|
228
|
+
for (; !f(i = E.pop()); )
|
|
229
|
+
f(t[i]) || (s += i + ":" + bt(t[i]) + ",");
|
|
230
230
|
ut.set(t, s);
|
|
231
231
|
}
|
|
232
232
|
} else
|
|
@@ -245,22 +245,22 @@ const bt = (t) => {
|
|
|
245
245
|
e
|
|
246
246
|
];
|
|
247
247
|
};
|
|
248
|
-
let
|
|
249
|
-
const Vt = () => ++
|
|
250
|
-
async function
|
|
248
|
+
let je = 0;
|
|
249
|
+
const Vt = () => ++je;
|
|
250
|
+
async function ae(...t) {
|
|
251
251
|
const [e, n, r, o] = t, s = G({
|
|
252
252
|
populateCache: !0,
|
|
253
253
|
throwOnError: !0
|
|
254
254
|
}, typeof o == "boolean" ? {
|
|
255
255
|
revalidate: o
|
|
256
256
|
} : o || {});
|
|
257
|
-
let
|
|
258
|
-
const
|
|
259
|
-
let
|
|
260
|
-
const y = (d) => typeof
|
|
257
|
+
let i = s.populateCache;
|
|
258
|
+
const E = s.rollbackOnError;
|
|
259
|
+
let h = s.optimisticData;
|
|
260
|
+
const y = (d) => typeof E == "function" ? E(d) : E !== !1, O = s.throwOnError;
|
|
261
261
|
if (N(n)) {
|
|
262
|
-
const d = n, c = [],
|
|
263
|
-
for (const l of
|
|
262
|
+
const d = n, c = [], p = e.keys();
|
|
263
|
+
for (const l of p)
|
|
264
264
|
// Skip the special useSWRInfinite and useSWRSubscription keys.
|
|
265
265
|
!/^\$(inf|sub)\$/.test(l) && d(e.get(l)._k) && c.push(l);
|
|
266
266
|
return Promise.all(c.map(u));
|
|
@@ -269,21 +269,21 @@ async function ie(...t) {
|
|
|
269
269
|
async function u(d) {
|
|
270
270
|
const [c] = Ft(d);
|
|
271
271
|
if (!c) return;
|
|
272
|
-
const [
|
|
272
|
+
const [p, l] = ie(e, c), [D, a, P, Q] = M.get(e), j = () => {
|
|
273
273
|
const C = D[c];
|
|
274
|
-
return (N(s.revalidate) ? s.revalidate(
|
|
274
|
+
return (N(s.revalidate) ? s.revalidate(p().data, d) : s.revalidate !== !1) && (delete P[c], delete Q[c], C && C[0]) ? C[0](oe).then(() => p().data) : p().data;
|
|
275
275
|
};
|
|
276
276
|
if (t.length < 3)
|
|
277
277
|
return j();
|
|
278
278
|
let R = r, I;
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
const q = Vt();
|
|
280
|
+
a[c] = [
|
|
281
|
+
q,
|
|
282
282
|
0
|
|
283
283
|
];
|
|
284
|
-
const
|
|
285
|
-
if (
|
|
286
|
-
data:
|
|
284
|
+
const S = !f(h), H = p(), V = H.data, k = H._c, W = f(k) ? V : k;
|
|
285
|
+
if (S && (h = N(h) ? h(W, V) : h, l({
|
|
286
|
+
data: h,
|
|
287
287
|
_c: W
|
|
288
288
|
})), N(R))
|
|
289
289
|
try {
|
|
@@ -291,19 +291,19 @@ async function ie(...t) {
|
|
|
291
291
|
} catch (C) {
|
|
292
292
|
I = C;
|
|
293
293
|
}
|
|
294
|
-
if (R &&
|
|
294
|
+
if (R && se(R))
|
|
295
295
|
if (R = await R.catch((C) => {
|
|
296
296
|
I = C;
|
|
297
|
-
}),
|
|
297
|
+
}), q !== a[c][0]) {
|
|
298
298
|
if (I) throw I;
|
|
299
299
|
return R;
|
|
300
|
-
} else I &&
|
|
300
|
+
} else I && S && y(I) && (i = !0, l({
|
|
301
301
|
data: W,
|
|
302
302
|
_c: A
|
|
303
303
|
}));
|
|
304
|
-
if (
|
|
305
|
-
if (N(
|
|
306
|
-
const C =
|
|
304
|
+
if (i && !I)
|
|
305
|
+
if (N(i)) {
|
|
306
|
+
const C = i(R, W);
|
|
307
307
|
l({
|
|
308
308
|
data: C,
|
|
309
309
|
error: A,
|
|
@@ -315,7 +315,7 @@ async function ie(...t) {
|
|
|
315
315
|
error: A,
|
|
316
316
|
_c: A
|
|
317
317
|
});
|
|
318
|
-
if (
|
|
318
|
+
if (a[c][1] = Vt(), Promise.resolve(j()).then(() => {
|
|
319
319
|
l({
|
|
320
320
|
_c: A
|
|
321
321
|
});
|
|
@@ -326,35 +326,35 @@ async function ie(...t) {
|
|
|
326
326
|
return R;
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
|
-
const
|
|
329
|
+
const Qt = (t, e) => {
|
|
330
330
|
for (const n in t)
|
|
331
331
|
t[n][0] && t[n][0](e);
|
|
332
|
-
},
|
|
333
|
-
if (!
|
|
334
|
-
const n = G(
|
|
332
|
+
}, Ue = (t, e) => {
|
|
333
|
+
if (!M.has(t)) {
|
|
334
|
+
const n = G(xe, e), r = /* @__PURE__ */ Object.create(null), o = ae.bind(A, t);
|
|
335
335
|
let s = U;
|
|
336
|
-
const
|
|
337
|
-
const d =
|
|
338
|
-
return
|
|
339
|
-
},
|
|
336
|
+
const i = /* @__PURE__ */ Object.create(null), E = (O, u) => {
|
|
337
|
+
const d = i[O] || [];
|
|
338
|
+
return i[O] = d, d.push(u), () => d.splice(d.indexOf(u), 1);
|
|
339
|
+
}, h = (O, u, d) => {
|
|
340
340
|
t.set(O, u);
|
|
341
|
-
const c =
|
|
341
|
+
const c = i[O];
|
|
342
342
|
if (c)
|
|
343
|
-
for (const
|
|
344
|
-
|
|
343
|
+
for (const p of c)
|
|
344
|
+
p(u, d);
|
|
345
345
|
}, y = () => {
|
|
346
|
-
if (!
|
|
346
|
+
if (!M.has(t) && (M.set(t, [
|
|
347
347
|
r,
|
|
348
348
|
/* @__PURE__ */ Object.create(null),
|
|
349
349
|
/* @__PURE__ */ Object.create(null),
|
|
350
350
|
/* @__PURE__ */ Object.create(null),
|
|
351
351
|
o,
|
|
352
|
-
|
|
353
|
-
|
|
352
|
+
h,
|
|
353
|
+
E
|
|
354
354
|
]), !tt)) {
|
|
355
|
-
const O = n.initFocus(setTimeout.bind(A,
|
|
355
|
+
const O = n.initFocus(setTimeout.bind(A, Qt.bind(A, r, ne))), u = n.initReconnect(setTimeout.bind(A, Qt.bind(A, r, re)));
|
|
356
356
|
s = () => {
|
|
357
|
-
O && O(), u && u(),
|
|
357
|
+
O && O(), u && u(), M.delete(t);
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
360
|
};
|
|
@@ -367,18 +367,18 @@ const Xt = (t, e) => {
|
|
|
367
367
|
}
|
|
368
368
|
return [
|
|
369
369
|
t,
|
|
370
|
-
|
|
370
|
+
M.get(t)[4]
|
|
371
371
|
];
|
|
372
|
-
},
|
|
373
|
-
const s = n.errorRetryCount,
|
|
374
|
-
!f(s) &&
|
|
375
|
-
},
|
|
372
|
+
}, Ge = (t, e, n, r, o) => {
|
|
373
|
+
const s = n.errorRetryCount, i = o.retryCount, E = ~~((Math.random() + 0.5) * (1 << (i < 8 ? i : 8))) * n.errorRetryInterval;
|
|
374
|
+
!f(s) && i > s || setTimeout(r, E, o);
|
|
375
|
+
}, We = gt, [ce, Be] = Ue(/* @__PURE__ */ new Map()), $e = G(
|
|
376
376
|
{
|
|
377
377
|
// events
|
|
378
378
|
onLoadingSlow: U,
|
|
379
379
|
onSuccess: U,
|
|
380
380
|
onError: U,
|
|
381
|
-
onErrorRetry:
|
|
381
|
+
onErrorRetry: Ge,
|
|
382
382
|
onDiscarded: U,
|
|
383
383
|
// switches
|
|
384
384
|
revalidateOnFocus: !0,
|
|
@@ -386,29 +386,29 @@ const Xt = (t, e) => {
|
|
|
386
386
|
revalidateIfStale: !0,
|
|
387
387
|
shouldRetryOnError: !0,
|
|
388
388
|
// timeouts
|
|
389
|
-
errorRetryInterval:
|
|
389
|
+
errorRetryInterval: Xt ? 1e4 : 5e3,
|
|
390
390
|
focusThrottleInterval: 5 * 1e3,
|
|
391
391
|
dedupingInterval: 2 * 1e3,
|
|
392
|
-
loadingTimeout:
|
|
392
|
+
loadingTimeout: Xt ? 5e3 : 3e3,
|
|
393
393
|
// providers
|
|
394
|
-
compare:
|
|
394
|
+
compare: We,
|
|
395
395
|
isPaused: () => !1,
|
|
396
|
-
cache:
|
|
397
|
-
mutate:
|
|
396
|
+
cache: ce,
|
|
397
|
+
mutate: Be,
|
|
398
398
|
fallback: {}
|
|
399
399
|
},
|
|
400
400
|
// use web preset by default
|
|
401
|
-
|
|
402
|
-
),
|
|
401
|
+
Fe
|
|
402
|
+
), qe = (t, e) => {
|
|
403
403
|
const n = G(t, e);
|
|
404
404
|
if (e) {
|
|
405
|
-
const { use: r, fallback: o } = t, { use: s, fallback:
|
|
406
|
-
r && s && (n.use = r.concat(s)), o &&
|
|
405
|
+
const { use: r, fallback: o } = t, { use: s, fallback: i } = e;
|
|
406
|
+
r && s && (n.use = r.concat(s)), o && i && (n.fallback = G(o, i));
|
|
407
407
|
}
|
|
408
408
|
return n;
|
|
409
|
-
},
|
|
410
|
-
|
|
411
|
-
},
|
|
409
|
+
}, He = Zt({}), ke = "$inf$", ue = rt && window.__SWR_DEVTOOLS_USE__, Ke = ue ? window.__SWR_DEVTOOLS_USE__ : [], Je = () => {
|
|
410
|
+
ue && (window.__SWR_DEVTOOLS_REACT__ = et);
|
|
411
|
+
}, Ye = (t) => N(t[1]) ? [
|
|
412
412
|
t[0],
|
|
413
413
|
t[1],
|
|
414
414
|
t[2] || {}
|
|
@@ -416,28 +416,28 @@ const Xt = (t, e) => {
|
|
|
416
416
|
t[0],
|
|
417
417
|
null,
|
|
418
418
|
(t[1] === null ? t[2] : t[1]) || {}
|
|
419
|
-
],
|
|
420
|
-
const [
|
|
421
|
-
if (
|
|
419
|
+
], ze = () => G($e, te(He)), Xe = (t) => (e, n, r) => t(e, n && ((...s) => {
|
|
420
|
+
const [i] = Ft(e), [, , , E] = M.get(ce);
|
|
421
|
+
if (i.startsWith(ke))
|
|
422
422
|
return n(...s);
|
|
423
|
-
const
|
|
424
|
-
return f(
|
|
425
|
-
}), r),
|
|
426
|
-
const r =
|
|
427
|
-
let
|
|
428
|
-
const { use: y } =
|
|
423
|
+
const h = E[i];
|
|
424
|
+
return f(h) ? n(...s) : (delete E[i], h);
|
|
425
|
+
}), r), Qe = Ke.concat(Xe), Ze = (t) => function(...n) {
|
|
426
|
+
const r = ze(), [o, s, i] = Ye(n), E = qe(r, i);
|
|
427
|
+
let h = t;
|
|
428
|
+
const { use: y } = E, O = (y || []).concat(Qe);
|
|
429
429
|
for (let u = O.length; u--; )
|
|
430
|
-
|
|
431
|
-
return
|
|
432
|
-
},
|
|
430
|
+
h = O[u](h);
|
|
431
|
+
return h(o, s || E.fetcher || null, E);
|
|
432
|
+
}, tn = (t, e, n) => {
|
|
433
433
|
const r = e[t] || (e[t] = []);
|
|
434
434
|
return r.push(n), () => {
|
|
435
435
|
const o = r.indexOf(n);
|
|
436
436
|
o >= 0 && (r[o] = r[r.length - 1], r.pop());
|
|
437
437
|
};
|
|
438
438
|
};
|
|
439
|
-
|
|
440
|
-
const
|
|
439
|
+
Je();
|
|
440
|
+
const Tt = et.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX sytax
|
|
441
441
|
// and emitting an error.
|
|
442
442
|
// We assume that this is only for the `use(thenable)` case, not `use(context)`.
|
|
443
443
|
// https://github.com/facebook/react/blob/aed00dacfb79d17c53218404c52b1c7aa59c4a89/packages/react-server/src/ReactFizzThenable.js#L45
|
|
@@ -458,93 +458,93 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
|
|
|
458
458
|
}
|
|
459
459
|
}), yt = {
|
|
460
460
|
dedupe: !0
|
|
461
|
-
},
|
|
462
|
-
const { cache: r, compare: o, suspense: s, fallbackData:
|
|
463
|
-
for (const
|
|
464
|
-
const v =
|
|
461
|
+
}, en = (t, e, n) => {
|
|
462
|
+
const { cache: r, compare: o, suspense: s, fallbackData: i, revalidateOnMount: E, revalidateIfStale: h, refreshInterval: y, refreshWhenHidden: O, refreshWhenOffline: u, keepPreviousData: d } = n, [c, p, l, D] = M.get(r), [a, P] = Ft(t), Q = $(!1), j = $(!1), R = $(a), I = $(e), q = $(n), S = () => q.current, H = () => S().isVisible() && S().isOnline(), [V, k, W, C] = ie(r, a), K = $({}).current, ot = f(i) ? f(n.fallback) ? A : n.fallback[a] : i, Mt = (_, m) => {
|
|
463
|
+
for (const T in K) {
|
|
464
|
+
const v = T;
|
|
465
465
|
if (v === "data") {
|
|
466
|
-
if (!o(
|
|
466
|
+
if (!o(_[v], m[v]) && (!f(_[v]) || !o(it, m[v])))
|
|
467
467
|
return !1;
|
|
468
|
-
} else if (
|
|
468
|
+
} else if (m[v] !== _[v])
|
|
469
469
|
return !1;
|
|
470
470
|
}
|
|
471
471
|
return !0;
|
|
472
472
|
}, Pt = ft(() => {
|
|
473
|
-
const
|
|
474
|
-
const F = G(
|
|
475
|
-
return delete F._k,
|
|
473
|
+
const _ = !a || !e ? !1 : f(E) ? S().isPaused() || s ? !1 : h !== !1 : E, m = (g) => {
|
|
474
|
+
const F = G(g);
|
|
475
|
+
return delete F._k, _ ? {
|
|
476
476
|
isValidating: !0,
|
|
477
477
|
isLoading: !0,
|
|
478
478
|
...F
|
|
479
479
|
} : F;
|
|
480
|
-
},
|
|
480
|
+
}, T = V(), v = C(), b = m(T), z = T === v ? b : m(v);
|
|
481
481
|
let w = b;
|
|
482
482
|
return [
|
|
483
483
|
() => {
|
|
484
|
-
const
|
|
485
|
-
return
|
|
484
|
+
const g = m(V());
|
|
485
|
+
return Mt(g, w) ? (w.data = g.data, w.isLoading = g.isLoading, w.isValidating = g.isValidating, w.error = g.error, w) : (w = g, g);
|
|
486
486
|
},
|
|
487
487
|
() => z
|
|
488
488
|
];
|
|
489
489
|
}, [
|
|
490
490
|
r,
|
|
491
|
-
|
|
492
|
-
]), J =
|
|
493
|
-
(
|
|
494
|
-
|
|
491
|
+
a
|
|
492
|
+
]), J = De.useSyncExternalStore(lt(
|
|
493
|
+
(_) => W(a, (m, T) => {
|
|
494
|
+
Mt(T, m) || _();
|
|
495
495
|
}),
|
|
496
496
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
497
497
|
[
|
|
498
498
|
r,
|
|
499
|
-
|
|
499
|
+
a
|
|
500
500
|
]
|
|
501
|
-
), Pt[0], Pt[1]),
|
|
502
|
-
async (
|
|
503
|
-
const
|
|
504
|
-
if (!
|
|
501
|
+
), Pt[0], Pt[1]), jt = !Q.current, me = c[a] && c[a].length > 0, Y = J.data, B = f(Y) ? ot && se(ot) ? Tt(ot) : ot : Y, st = J.error, pt = $(B), it = d ? f(Y) ? f(pt.current) ? B : pt.current : Y : B, Ut = me && !f(st) ? !1 : jt && !f(E) ? E : S().isPaused() ? !1 : s ? f(B) ? !1 : h : f(B) || h, Gt = !!(a && e && jt && Ut), he = f(J.isValidating) ? Gt : J.isValidating, _e = f(J.isLoading) ? Gt : J.isLoading, Z = lt(
|
|
502
|
+
async (_) => {
|
|
503
|
+
const m = I.current;
|
|
504
|
+
if (!a || !m || j.current || S().isPaused())
|
|
505
505
|
return !1;
|
|
506
|
-
let
|
|
507
|
-
const z =
|
|
506
|
+
let T, v, b = !0;
|
|
507
|
+
const z = _ || {}, w = !l[a] || !z.dedupe, g = () => zt ? !j.current && a === R.current && Q.current : a === R.current, F = {
|
|
508
508
|
isValidating: !1,
|
|
509
509
|
isLoading: !1
|
|
510
|
-
},
|
|
511
|
-
|
|
512
|
-
},
|
|
513
|
-
const L = l[
|
|
514
|
-
L && L[1] === v && delete l[
|
|
515
|
-
},
|
|
510
|
+
}, Bt = () => {
|
|
511
|
+
k(F);
|
|
512
|
+
}, $t = () => {
|
|
513
|
+
const L = l[a];
|
|
514
|
+
L && L[1] === v && delete l[a];
|
|
515
|
+
}, qt = {
|
|
516
516
|
isValidating: !0
|
|
517
517
|
};
|
|
518
|
-
f(V().data) && (
|
|
518
|
+
f(V().data) && (qt.isLoading = !0);
|
|
519
519
|
try {
|
|
520
|
-
if (w && (
|
|
521
|
-
b &&
|
|
522
|
-
}, n.loadingTimeout), l[
|
|
523
|
-
|
|
520
|
+
if (w && (k(qt), n.loadingTimeout && f(V().data) && setTimeout(() => {
|
|
521
|
+
b && g() && S().onLoadingSlow(a, n);
|
|
522
|
+
}, n.loadingTimeout), l[a] = [
|
|
523
|
+
m(P),
|
|
524
524
|
Vt()
|
|
525
|
-
]), [
|
|
526
|
-
return w &&
|
|
525
|
+
]), [T, v] = l[a], T = await T, w && setTimeout($t, n.dedupingInterval), !l[a] || l[a][1] !== v)
|
|
526
|
+
return w && g() && S().onDiscarded(a), !1;
|
|
527
527
|
F.error = A;
|
|
528
|
-
const L =
|
|
528
|
+
const L = p[a];
|
|
529
529
|
if (!f(L) && // case 1
|
|
530
530
|
(v <= L[0] || // case 2
|
|
531
531
|
v <= L[1] || // case 3
|
|
532
532
|
L[1] === 0))
|
|
533
|
-
return
|
|
533
|
+
return Bt(), w && g() && S().onDiscarded(a), !1;
|
|
534
534
|
const x = V().data;
|
|
535
|
-
F.data = o(x,
|
|
535
|
+
F.data = o(x, T) ? x : T, w && g() && S().onSuccess(T, a, n);
|
|
536
536
|
} catch (L) {
|
|
537
|
-
|
|
538
|
-
const x =
|
|
539
|
-
x.isPaused() || (F.error = L, w &&
|
|
540
|
-
const
|
|
541
|
-
|
|
537
|
+
$t();
|
|
538
|
+
const x = S(), { shouldRetryOnError: mt } = x;
|
|
539
|
+
x.isPaused() || (F.error = L, w && g() && (x.onError(L, a, x), (mt === !0 || N(mt) && mt(L)) && (!S().revalidateOnFocus || !S().revalidateOnReconnect || H()) && x.onErrorRetry(L, a, x, (Se) => {
|
|
540
|
+
const ht = c[a];
|
|
541
|
+
ht && ht[0] && ht[0](Jt, Se);
|
|
542
542
|
}, {
|
|
543
543
|
retryCount: (z.retryCount || 0) + 1,
|
|
544
544
|
dedupe: !0
|
|
545
545
|
})));
|
|
546
546
|
}
|
|
547
|
-
return b = !1,
|
|
547
|
+
return b = !1, Bt(), !0;
|
|
548
548
|
},
|
|
549
549
|
// `setState` is immutable, and `eventsCallback`, `fnArg`, and
|
|
550
550
|
// `keyValidating` are depending on `key`, so we can exclude them from
|
|
@@ -558,76 +558,76 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
|
|
|
558
558
|
// even though it might cause unexpected behaviors.
|
|
559
559
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
560
560
|
[
|
|
561
|
-
|
|
561
|
+
a,
|
|
562
562
|
r
|
|
563
563
|
]
|
|
564
|
-
),
|
|
564
|
+
), Wt = lt(
|
|
565
565
|
// Use callback to make sure `keyRef.current` returns latest result every time
|
|
566
|
-
(...
|
|
566
|
+
(..._) => ae(r, R.current, ..._),
|
|
567
567
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
568
568
|
[]
|
|
569
569
|
);
|
|
570
570
|
if (vt(() => {
|
|
571
|
-
I.current = e,
|
|
571
|
+
I.current = e, q.current = n, f(Y) || (pt.current = Y);
|
|
572
572
|
}), vt(() => {
|
|
573
|
-
if (!
|
|
574
|
-
const
|
|
575
|
-
let
|
|
576
|
-
|
|
577
|
-
const v =
|
|
578
|
-
if (b ==
|
|
573
|
+
if (!a) return;
|
|
574
|
+
const _ = Z.bind(A, yt);
|
|
575
|
+
let m = 0;
|
|
576
|
+
S().revalidateOnFocus && (m = Date.now() + S().focusThrottleInterval);
|
|
577
|
+
const v = tn(a, c, (b, z = {}) => {
|
|
578
|
+
if (b == ne) {
|
|
579
579
|
const w = Date.now();
|
|
580
|
-
|
|
581
|
-
} else if (b ==
|
|
582
|
-
|
|
580
|
+
S().revalidateOnFocus && w > m && H() && (m = w + S().focusThrottleInterval, _());
|
|
581
|
+
} else if (b == re)
|
|
582
|
+
S().revalidateOnReconnect && H() && _();
|
|
583
583
|
else {
|
|
584
|
-
if (b ==
|
|
584
|
+
if (b == oe)
|
|
585
585
|
return Z();
|
|
586
|
-
if (b ==
|
|
586
|
+
if (b == Jt)
|
|
587
587
|
return Z(z);
|
|
588
588
|
}
|
|
589
589
|
});
|
|
590
|
-
return j.current = !1, R.current =
|
|
591
|
-
_k:
|
|
592
|
-
}),
|
|
590
|
+
return j.current = !1, R.current = a, Q.current = !0, k({
|
|
591
|
+
_k: P
|
|
592
|
+
}), Ut && (f(B) || tt ? _() : Me(_)), () => {
|
|
593
593
|
j.current = !0, v();
|
|
594
594
|
};
|
|
595
595
|
}, [
|
|
596
|
-
|
|
596
|
+
a
|
|
597
597
|
]), vt(() => {
|
|
598
|
-
let
|
|
599
|
-
function
|
|
598
|
+
let _;
|
|
599
|
+
function m() {
|
|
600
600
|
const v = N(y) ? y(V().data) : y;
|
|
601
|
-
v &&
|
|
601
|
+
v && _ !== -1 && (_ = setTimeout(T, v));
|
|
602
602
|
}
|
|
603
|
-
function
|
|
604
|
-
!V().error && (O ||
|
|
603
|
+
function T() {
|
|
604
|
+
!V().error && (O || S().isVisible()) && (u || S().isOnline()) ? Z(yt).then(m) : m();
|
|
605
605
|
}
|
|
606
|
-
return
|
|
607
|
-
|
|
606
|
+
return m(), () => {
|
|
607
|
+
_ && (clearTimeout(_), _ = -1);
|
|
608
608
|
};
|
|
609
609
|
}, [
|
|
610
610
|
y,
|
|
611
611
|
O,
|
|
612
612
|
u,
|
|
613
|
-
|
|
614
|
-
]),
|
|
615
|
-
if (!
|
|
613
|
+
a
|
|
614
|
+
]), Re(it), s && f(B) && a) {
|
|
615
|
+
if (!zt && tt)
|
|
616
616
|
throw new Error("Fallback data is required when using Suspense in SSR.");
|
|
617
|
-
I.current = e,
|
|
618
|
-
const
|
|
619
|
-
if (!f(
|
|
620
|
-
const
|
|
621
|
-
|
|
617
|
+
I.current = e, q.current = n, j.current = !1;
|
|
618
|
+
const _ = D[a];
|
|
619
|
+
if (!f(_)) {
|
|
620
|
+
const m = Wt(_);
|
|
621
|
+
Tt(m);
|
|
622
622
|
}
|
|
623
623
|
if (f(st)) {
|
|
624
|
-
const
|
|
625
|
-
f(it) || (
|
|
624
|
+
const m = Z(yt);
|
|
625
|
+
f(it) || (m.status = "fulfilled", m.value = !0), Tt(m);
|
|
626
626
|
} else
|
|
627
627
|
throw st;
|
|
628
628
|
}
|
|
629
629
|
return {
|
|
630
|
-
mutate:
|
|
630
|
+
mutate: Wt,
|
|
631
631
|
get data() {
|
|
632
632
|
return K.data = !0, it;
|
|
633
633
|
},
|
|
@@ -638,36 +638,45 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
|
|
|
638
638
|
return K.isValidating = !0, he;
|
|
639
639
|
},
|
|
640
640
|
get isLoading() {
|
|
641
|
-
return K.isLoading = !0,
|
|
641
|
+
return K.isLoading = !0, _e;
|
|
642
642
|
}
|
|
643
643
|
};
|
|
644
|
-
},
|
|
644
|
+
}, nn = Ze(en), xt = "https://api.figma.com", rn = `${xt}/v1/files`, le = `${xt}/v1/variables`, fe = le, de = (t) => `${le}/${t}`, on = (t) => `${rn}/${t}/variables/local`, sn = "application/json", Ee = "X-FIGMA-TOKEN", X = "A Figma API token is required.", an = "An error occurred while fetching data from the Figma API.";
|
|
645
|
+
async function cn(t, e) {
|
|
645
646
|
if (!e)
|
|
646
|
-
throw new Error(
|
|
647
|
+
throw new Error(X);
|
|
647
648
|
const n = await fetch(t, {
|
|
649
|
+
method: "GET",
|
|
648
650
|
headers: {
|
|
649
|
-
[
|
|
650
|
-
"Content-Type":
|
|
651
|
+
[Ee]: e,
|
|
652
|
+
"Content-Type": sn
|
|
651
653
|
}
|
|
652
654
|
});
|
|
653
655
|
if (!n.ok) {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
+
let r = an;
|
|
657
|
+
try {
|
|
658
|
+
const o = await n.json();
|
|
659
|
+
o != null && o.message && (r = o.message);
|
|
660
|
+
} catch {
|
|
661
|
+
}
|
|
662
|
+
throw new Error(r);
|
|
656
663
|
}
|
|
657
664
|
return n.json();
|
|
658
|
-
}
|
|
659
|
-
|
|
665
|
+
}
|
|
666
|
+
const pe = () => {
|
|
667
|
+
const { token: t, fileKey: e } = nt(), n = e ? on(e) : null, { data: r, error: o, isLoading: s, isValidating: i, mutate: E } = nn(
|
|
660
668
|
t && n ? [n, t] : null,
|
|
661
669
|
cn
|
|
662
670
|
);
|
|
663
671
|
return {
|
|
664
672
|
data: r,
|
|
665
673
|
isLoading: s,
|
|
666
|
-
isValidating:
|
|
667
|
-
error: o
|
|
674
|
+
isValidating: i,
|
|
675
|
+
error: o,
|
|
676
|
+
mutate: E
|
|
668
677
|
};
|
|
669
678
|
}, pn = () => {
|
|
670
|
-
const { data: t } =
|
|
679
|
+
const { data: t } = pe(), e = ft(
|
|
671
680
|
() => t != null && t.meta ? Object.values(t.meta.variableCollections) : [],
|
|
672
681
|
[t]
|
|
673
682
|
), n = ft(
|
|
@@ -679,7 +688,7 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
|
|
|
679
688
|
collectionsById: n
|
|
680
689
|
};
|
|
681
690
|
}, mn = () => {
|
|
682
|
-
const { data: t } =
|
|
691
|
+
const { data: t } = pe();
|
|
683
692
|
return ft(() => {
|
|
684
693
|
const e = [], n = {}, r = {};
|
|
685
694
|
if (t != null && t.meta)
|
|
@@ -696,9 +705,6 @@ const gt = et.use || // This extra generic is to avoid TypeScript mixing up the
|
|
|
696
705
|
modesById: r
|
|
697
706
|
};
|
|
698
707
|
}, [t]);
|
|
699
|
-
}, _n = () => {
|
|
700
|
-
const { token: t } = X();
|
|
701
|
-
return t;
|
|
702
708
|
};
|
|
703
709
|
function un(t, e) {
|
|
704
710
|
switch (e.type) {
|
|
@@ -723,10 +729,10 @@ const dt = (t) => {
|
|
|
723
729
|
async (s) => {
|
|
724
730
|
r({ type: "loading" });
|
|
725
731
|
try {
|
|
726
|
-
const
|
|
727
|
-
return r({ type: "success", payload:
|
|
728
|
-
} catch (
|
|
729
|
-
r({ type: "error", payload:
|
|
732
|
+
const i = await t(s);
|
|
733
|
+
return r({ type: "success", payload: i }), i;
|
|
734
|
+
} catch (i) {
|
|
735
|
+
r({ type: "error", payload: i });
|
|
730
736
|
return;
|
|
731
737
|
}
|
|
732
738
|
},
|
|
@@ -737,70 +743,81 @@ const dt = (t) => {
|
|
|
737
743
|
isSuccess: n.status === "success",
|
|
738
744
|
isError: n.status === "error"
|
|
739
745
|
};
|
|
740
|
-
}
|
|
746
|
+
};
|
|
747
|
+
async function Et(t, e, n, r) {
|
|
741
748
|
if (!e)
|
|
742
|
-
throw new Error(
|
|
743
|
-
const
|
|
744
|
-
|
|
749
|
+
throw new Error(X);
|
|
750
|
+
const s = {
|
|
751
|
+
CREATE: "POST",
|
|
752
|
+
UPDATE: "PUT",
|
|
753
|
+
DELETE: "DELETE"
|
|
754
|
+
}[n], i = await fetch(`${xt}${t}`, {
|
|
755
|
+
method: s,
|
|
745
756
|
headers: {
|
|
746
|
-
|
|
747
|
-
|
|
757
|
+
"Content-Type": "application/json",
|
|
758
|
+
[Ee]: e
|
|
748
759
|
},
|
|
749
|
-
|
|
760
|
+
body: r ? JSON.stringify(r) : void 0
|
|
750
761
|
});
|
|
751
|
-
if (!
|
|
752
|
-
const
|
|
753
|
-
throw new Error(
|
|
762
|
+
if (!i.ok) {
|
|
763
|
+
const E = await i.json().catch(() => ({}));
|
|
764
|
+
throw new Error(
|
|
765
|
+
E.err || E.message || "An API error occurred"
|
|
766
|
+
);
|
|
754
767
|
}
|
|
755
|
-
return
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
+
return i.status === 204 || !i.body ? {} : i.json();
|
|
769
|
+
}
|
|
770
|
+
const hn = () => {
|
|
771
|
+
const { token: t } = nt();
|
|
772
|
+
return dt(async (n) => {
|
|
773
|
+
if (!t)
|
|
774
|
+
throw new Error(X);
|
|
775
|
+
return await Et(
|
|
776
|
+
fe,
|
|
777
|
+
t,
|
|
778
|
+
"CREATE",
|
|
779
|
+
n
|
|
780
|
+
);
|
|
781
|
+
});
|
|
782
|
+
}, _n = () => {
|
|
783
|
+
const { token: t } = nt();
|
|
768
784
|
if (!t)
|
|
769
|
-
throw new Error(
|
|
770
|
-
return dt(async (n) => await Et(
|
|
771
|
-
de(n),
|
|
772
|
-
t,
|
|
773
|
-
"DELETE"
|
|
774
|
-
));
|
|
775
|
-
}, On = () => {
|
|
776
|
-
const { token: t } = X();
|
|
785
|
+
throw new Error(X);
|
|
777
786
|
return dt(
|
|
778
787
|
async ({ variableId: n, payload: r }) => {
|
|
779
|
-
if (!t)
|
|
780
|
-
throw new Error("A Figma API token is required.");
|
|
781
788
|
const o = de(n);
|
|
782
789
|
return await Et(
|
|
783
790
|
o,
|
|
784
791
|
t,
|
|
785
|
-
"
|
|
792
|
+
"UPDATE",
|
|
786
793
|
r
|
|
787
794
|
);
|
|
788
795
|
}
|
|
789
796
|
);
|
|
790
|
-
},
|
|
791
|
-
const { token: t } =
|
|
797
|
+
}, Sn = () => {
|
|
798
|
+
const { token: t } = nt();
|
|
799
|
+
if (!t)
|
|
800
|
+
throw new Error(X);
|
|
801
|
+
return dt(async (n) => await Et(
|
|
802
|
+
de(n),
|
|
803
|
+
t,
|
|
804
|
+
"DELETE",
|
|
805
|
+
void 0
|
|
806
|
+
));
|
|
807
|
+
}, On = () => {
|
|
808
|
+
const { token: t } = nt();
|
|
792
809
|
return dt(async (n) => {
|
|
793
810
|
if (!t)
|
|
794
|
-
throw new Error(
|
|
811
|
+
throw new Error(X);
|
|
795
812
|
return await Et(
|
|
796
813
|
fe,
|
|
797
814
|
t,
|
|
798
|
-
"
|
|
815
|
+
"CREATE",
|
|
799
816
|
n
|
|
800
817
|
);
|
|
801
818
|
});
|
|
802
819
|
};
|
|
803
|
-
function
|
|
820
|
+
function vn(t, e) {
|
|
804
821
|
return t.filter((n) => {
|
|
805
822
|
let r = !0;
|
|
806
823
|
return e.resolvedType && (r = r && n.resolvedType === e.resolvedType), e.name && (r = r && n.name.includes(e.name)), r;
|
|
@@ -808,13 +825,12 @@ function wn(t, e) {
|
|
|
808
825
|
}
|
|
809
826
|
export {
|
|
810
827
|
En as FigmaVarsProvider,
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
_n as
|
|
816
|
-
On as useUpdateVariable,
|
|
828
|
+
vn as filterVariables,
|
|
829
|
+
On as useBulkUpdateVariables,
|
|
830
|
+
hn as useCreateVariable,
|
|
831
|
+
Sn as useDeleteVariable,
|
|
832
|
+
_n as useUpdateVariable,
|
|
817
833
|
pn as useVariableCollections,
|
|
818
834
|
mn as useVariableModes,
|
|
819
|
-
|
|
835
|
+
pe as useVariables
|
|
820
836
|
};
|