@figma-vars/hooks 1.0.10 → 1.1.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 -64
- package/dist/constants/index.d.ts +0 -8
- package/dist/contexts/FigmaTokenContext.d.ts +11 -0
- package/dist/figma-vars-hooks.js +1153 -201
- package/dist/figma-vars-hooks.umd.cjs +38 -1
- package/dist/hooks/useFigmaToken.d.ts +3 -2
- package/dist/hooks/useVariableCollections.d.ts +13 -3
- package/dist/hooks/useVariableModes.d.ts +8 -5
- package/dist/hooks/useVariables.d.ts +10 -12
- package/dist/index.d.ts +12 -15
- package/dist/mutations/bulkUpdateVariables.d.ts +7 -0
- package/dist/mutations/createVariable.d.ts +7 -8
- package/dist/mutations/deleteVariable.d.ts +7 -8
- package/dist/mutations/updateVariable.d.ts +7 -9
- package/dist/types/figma.d.ts +33 -5
- package/dist/types/hooks.d.ts +9 -0
- package/dist/types/mutations.d.ts +67 -0
- package/dist/utils/authHelpers.d.ts +0 -4
- package/dist/utils/fetchHelpers.d.ts +1 -1
- package/dist/utils/filterVariables.d.ts +2 -2
- package/package.json +6 -3
- package/dist/experimental/usePublishVars.d.ts +0 -2
- package/dist/experimental/useSync.d.ts +0 -2
- package/dist/experimental/useVariableAliases.d.ts +0 -9
- package/dist/experimental/useVariableBindings.d.ts +0 -7
- package/dist/mutations/updateVariableValues.d.ts +0 -8
- package/dist/utils/cache.d.ts +0 -7
|
@@ -1 +1,38 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(A,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],f):(A=typeof globalThis<"u"?globalThis:A||self,f(A.FigmaVarsHooks={},A.require$$0))})(this,function(A,f){"use strict";var ge={exports:{}},le={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var He;function Et(){if(He)return le;He=1;var e=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function t(r,o,a){var i=null;if(a!==void 0&&(i=""+a),o.key!==void 0&&(i=""+o.key),"key"in o){a={};for(var d in o)d!=="key"&&(a[d]=o[d])}else a=o;return o=a.ref,{$$typeof:e,type:r,key:i,ref:o!==void 0?o:null,props:a}}return le.Fragment=n,le.jsx=t,le.jsxs=t,le}var fe={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var Je;function pt(){return Je||(Je=1,process.env.NODE_ENV!=="production"&&function(){function e(s){if(s==null)return null;if(typeof s=="function")return s.$$typeof===x?null:s.displayName||s.name||null;if(typeof s=="string")return s;switch(s){case E:return"Fragment";case c:return"Profiler";case V:return"StrictMode";case C:return"Suspense";case F:return"SuspenseList";case re:return"Activity"}if(typeof s=="object")switch(typeof s.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),s.$$typeof){case _:return"Portal";case se:return(s.displayName||"Context")+".Provider";case Y:return(s._context.displayName||"Context")+".Consumer";case B:var l=s.render;return s=s.displayName,s||(s=l.displayName||l.name||"",s=s!==""?"ForwardRef("+s+")":"ForwardRef"),s;case ne:return l=s.displayName||null,l!==null?l:e(s.type)||"Memo";case O:l=s._payload,s=s._init;try{return e(s(l))}catch{}}return null}function n(s){return""+s}function t(s){try{n(s);var l=!1}catch{l=!0}if(l){l=console;var b=l.error,w=typeof Symbol=="function"&&Symbol.toStringTag&&s[Symbol.toStringTag]||s.constructor.name||"Object";return b.call(l,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",w),n(s)}}function r(s){if(s===E)return"<>";if(typeof s=="object"&&s!==null&&s.$$typeof===O)return"<...>";try{var l=e(s);return l?"<"+l+">":"<...>"}catch{return"<...>"}}function o(){var s=H.A;return s===null?null:s.getOwner()}function a(){return Error("react-stack-top-frame")}function i(s){if(J.call(s,"key")){var l=Object.getOwnPropertyDescriptor(s,"key").get;if(l&&l.isReactWarning)return!1}return s.key!==void 0}function d(s,l){function b(){ae||(ae=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",l))}b.isReactWarning=!0,Object.defineProperty(s,"key",{get:b,configurable:!0})}function p(){var s=e(this.type);return Ee[s]||(Ee[s]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),s=this.props.ref,s!==void 0?s:null}function S(s,l,b,w,M,P,ie,ce){return b=P.ref,s={$$typeof:u,type:s,key:l,props:P,_owner:M},(b!==void 0?b:null)!==null?Object.defineProperty(s,"ref",{enumerable:!1,get:p}):Object.defineProperty(s,"ref",{enumerable:!1,value:null}),s._store={},Object.defineProperty(s._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(s,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(s,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:ie}),Object.defineProperty(s,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ce}),Object.freeze&&(Object.freeze(s.props),Object.freeze(s)),s}function g(s,l,b,w,M,P,ie,ce){var k=l.children;if(k!==void 0)if(w)if(N(k)){for(w=0;w<k.length;w++)m(k[w]);Object.freeze&&Object.freeze(k)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else m(k);if(J.call(l,"key")){k=e(s);var oe=Object.keys(l).filter(function(Re){return Re!=="key"});w=0<oe.length?"{key: someKey, "+oe.join(": ..., ")+": ...}":"{key: someKey}",ve[k+w]||(oe=0<oe.length?"{"+oe.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
|
+
let props = %s;
|
|
19
|
+
<%s {...props} />
|
|
20
|
+
React keys must be passed directly to JSX without using spread:
|
|
21
|
+
let props = %s;
|
|
22
|
+
<%s key={someKey} {...props} />`,w,k,oe,k),ve[k+w]=!0)}if(k=null,b!==void 0&&(t(b),k=""+b),i(l)&&(t(l.key),k=""+l.key),"key"in l){b={};for(var Z in l)Z!=="key"&&(b[Z]=l[Z])}else b=l;return k&&d(b,typeof s=="function"?s.displayName||s.name||"Unknown":s),S(s,k,P,M,o(),b,ie,ce)}function m(s){typeof s=="object"&&s!==null&&s.$$typeof===u&&s._store&&(s._store.validated=1)}var v=f,u=Symbol.for("react.transitional.element"),_=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),V=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),Y=Symbol.for("react.consumer"),se=Symbol.for("react.context"),B=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),F=Symbol.for("react.suspense_list"),ne=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),re=Symbol.for("react.activity"),x=Symbol.for("react.client.reference"),H=v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,J=Object.prototype.hasOwnProperty,N=Array.isArray,K=console.createTask?console.createTask:function(){return null};v={"react-stack-bottom-frame":function(s){return s()}};var ae,Ee={},pe=v["react-stack-bottom-frame"].bind(v,a)(),X=K(r(a)),ve={};fe.Fragment=E,fe.jsx=function(s,l,b,w,M){var P=1e4>H.recentlyCreatedOwnerStacks++;return g(s,l,b,!1,w,M,P?Error("react-stack-top-frame"):pe,P?K(r(s)):X)},fe.jsxs=function(s,l,b,w,M){var P=1e4>H.recentlyCreatedOwnerStacks++;return g(s,l,b,!0,w,M,P?Error("react-stack-top-frame"):pe,P?K(r(s)):X)}}()),fe}var Ke;function vt(){return Ke||(Ke=1,process.env.NODE_ENV==="production"?ge.exports=Et():ge.exports=pt()),ge.exports}var gt=vt();const ze=f.createContext(void 0),St=({children:e,token:n})=>gt.jsx(ze.Provider,{value:{token:n},children:e}),ht=()=>{const e=f.useContext(ze);if(e===void 0)throw new Error("useFigmaTokenContext must be used within a FigmaVarsProvider");return e},$=()=>{const{token:e}=ht();return e};var Se={exports:{}},Oe={};/**
|
|
23
|
+
* @license React
|
|
24
|
+
* use-sync-external-store-shim.production.js
|
|
25
|
+
*
|
|
26
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
27
|
+
*
|
|
28
|
+
* This source code is licensed under the MIT license found in the
|
|
29
|
+
* LICENSE file in the root directory of this source tree.
|
|
30
|
+
*/var Xe;function _t(){if(Xe)return Oe;Xe=1;var e=f;function n(m,v){return m===v&&(m!==0||1/m===1/v)||m!==m&&v!==v}var t=typeof Object.is=="function"?Object.is:n,r=e.useState,o=e.useEffect,a=e.useLayoutEffect,i=e.useDebugValue;function d(m,v){var u=v(),_=r({inst:{value:u,getSnapshot:v}}),E=_[0].inst,V=_[1];return a(function(){E.value=u,E.getSnapshot=v,p(E)&&V({inst:E})},[m,u,v]),o(function(){return p(E)&&V({inst:E}),m(function(){p(E)&&V({inst:E})})},[m]),i(u),u}function p(m){var v=m.getSnapshot;m=m.value;try{var u=v();return!t(m,u)}catch{return!0}}function S(m,v){return v()}var g=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?S:d;return Oe.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:g,Oe}var Te={};/**
|
|
31
|
+
* @license React
|
|
32
|
+
* use-sync-external-store-shim.development.js
|
|
33
|
+
*
|
|
34
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
35
|
+
*
|
|
36
|
+
* This source code is licensed under the MIT license found in the
|
|
37
|
+
* LICENSE file in the root directory of this source tree.
|
|
38
|
+
*/var Ze;function bt(){return Ze||(Ze=1,process.env.NODE_ENV!=="production"&&function(){function e(u,_){return u===_&&(u!==0||1/u===1/_)||u!==u&&_!==_}function n(u,_){g||o.startTransition===void 0||(g=!0,console.error("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."));var E=_();if(!m){var V=_();a(E,V)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),m=!0)}V=i({inst:{value:E,getSnapshot:_}});var c=V[0].inst,Y=V[1];return p(function(){c.value=E,c.getSnapshot=_,t(c)&&Y({inst:c})},[u,E,_]),d(function(){return t(c)&&Y({inst:c}),u(function(){t(c)&&Y({inst:c})})},[u]),S(E),E}function t(u){var _=u.getSnapshot;u=u.value;try{var E=_();return!a(u,E)}catch{return!0}}function r(u,_){return _()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=f,a=typeof Object.is=="function"?Object.is:e,i=o.useState,d=o.useEffect,p=o.useLayoutEffect,S=o.useDebugValue,g=!1,m=!1,v=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:n;Te.useSyncExternalStore=o.useSyncExternalStore!==void 0?o.useSyncExternalStore:v,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Te}var Qe;function Rt(){return Qe||(Qe=1,process.env.NODE_ENV==="production"?Se.exports=_t():Se.exports=bt()),Se.exports}var Ot=Rt();const qe=0,$e=1,et=2,tt=3;var nt=Object.prototype.hasOwnProperty;function we(e,n){var t,r;if(e===n)return!0;if(e&&n&&(t=e.constructor)===n.constructor){if(t===Date)return e.getTime()===n.getTime();if(t===RegExp)return e.toString()===n.toString();if(t===Array){if((r=e.length)===n.length)for(;r--&&we(e[r],n[r]););return r===-1}if(!t||typeof e=="object"){r=0;for(t in e)if(nt.call(e,t)&&++r&&!nt.call(n,t)||!(t in n)||!we(e[t],n[t]))return!1;return Object.keys(n).length===r}}return e!==e&&n!==n}const z=new WeakMap,ee=()=>{},L=ee(),ye=Object,h=e=>e===L,G=e=>typeof e=="function",te=(e,n)=>({...e,...n}),rt=e=>G(e.then),Ae={},he={},Ce="undefined",de=typeof window!=Ce,ke=typeof document!=Ce,Tt=de&&"Deno"in window,wt=()=>de&&typeof window.requestAnimationFrame!=Ce,ot=(e,n)=>{const t=z.get(e);return[()=>!h(n)&&e.get(n)||Ae,r=>{if(!h(n)){const o=e.get(n);n in he||(he[n]=o),t[5](n,te(o,r),o||Ae)}},t[6],()=>!h(n)&&n in he?he[n]:!h(n)&&e.get(n)||Ae]};let De=!0;const yt=()=>De,[Ie,Le]=de&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[ee,ee],At=()=>{const e=ke&&document.visibilityState;return h(e)||e!=="hidden"},Ct=e=>(ke&&document.addEventListener("visibilitychange",e),Ie("focus",e),()=>{ke&&document.removeEventListener("visibilitychange",e),Le("focus",e)}),kt=e=>{const n=()=>{De=!0,e()},t=()=>{De=!1};return Ie("online",n),Ie("offline",t),()=>{Le("online",n),Le("offline",t)}},Dt={isOnline:yt,isVisible:At},It={initFocus:Ct,initReconnect:kt},st=!f.useId,me=!de||Tt,Lt=e=>wt()?window.requestAnimationFrame(e):setTimeout(e,1),Ve=me?f.useEffect:f.useLayoutEffect,Fe=typeof navigator<"u"&&navigator.connection,at=!me&&Fe&&(["slow-2g","2g"].includes(Fe.effectiveType)||Fe.saveData),_e=new WeakMap,Pe=(e,n)=>ye.prototype.toString.call(e)===`[object ${n}]`;let Vt=0;const je=e=>{const n=typeof e,t=Pe(e,"Date"),r=Pe(e,"RegExp"),o=Pe(e,"Object");let a,i;if(ye(e)===e&&!t&&!r){if(a=_e.get(e),a)return a;if(a=++Vt+"~",_e.set(e,a),Array.isArray(e)){for(a="@",i=0;i<e.length;i++)a+=je(e[i])+",";_e.set(e,a)}if(o){a="#";const d=ye.keys(e).sort();for(;!h(i=d.pop());)h(e[i])||(a+=i+":"+je(e[i])+",");_e.set(e,a)}}else a=t?e.toJSON():n=="symbol"?e.toString():n=="string"?JSON.stringify(e):""+e;return a},Ne=e=>{if(G(e))try{e=e()}catch{e=""}const n=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?je(e):"",[e,n]};let Ft=0;const xe=()=>++Ft;async function it(...e){const[n,t,r,o]=e,a=te({populateCache:!0,throwOnError:!0},typeof o=="boolean"?{revalidate:o}:o||{});let i=a.populateCache;const d=a.rollbackOnError;let p=a.optimisticData;const S=v=>typeof d=="function"?d(v):d!==!1,g=a.throwOnError;if(G(t)){const v=t,u=[],_=n.keys();for(const E of _)!/^\$(inf|sub)\$/.test(E)&&v(n.get(E)._k)&&u.push(E);return Promise.all(u.map(m))}return m(t);async function m(v){const[u]=Ne(v);if(!u)return;const[_,E]=ot(n,u),[V,c,Y,se]=z.get(n),B=()=>{const N=V[u];return(G(a.revalidate)?a.revalidate(_().data,v):a.revalidate!==!1)&&(delete Y[u],delete se[u],N&&N[0])?N[0](et).then(()=>_().data):_().data};if(e.length<3)return B();let C=r,F;const ne=xe();c[u]=[ne,0];const O=!h(p),re=_(),x=re.data,H=re._c,J=h(H)?x:H;if(O&&(p=G(p)?p(J,x):p,E({data:p,_c:J})),G(C))try{C=C(J)}catch(N){F=N}if(C&&rt(C))if(C=await C.catch(N=>{F=N}),ne!==c[u][0]){if(F)throw F;return C}else F&&O&&S(F)&&(i=!0,E({data:J,_c:L}));if(i&&!F)if(G(i)){const N=i(C,J);E({data:N,error:L,_c:L})}else E({data:C,error:L,_c:L});if(c[u][1]=xe(),Promise.resolve(B()).then(()=>{E({_c:L})}),F){if(g)throw F;return}return C}}const ct=(e,n)=>{for(const t in e)e[t][0]&&e[t][0](n)},Pt=(e,n)=>{if(!z.has(e)){const t=te(It,n),r=Object.create(null),o=it.bind(L,e);let a=ee;const i=Object.create(null),d=(g,m)=>{const v=i[g]||[];return i[g]=v,v.push(m),()=>v.splice(v.indexOf(m),1)},p=(g,m,v)=>{e.set(g,m);const u=i[g];if(u)for(const _ of u)_(m,v)},S=()=>{if(!z.has(e)&&(z.set(e,[r,Object.create(null),Object.create(null),Object.create(null),o,p,d]),!me)){const g=t.initFocus(setTimeout.bind(L,ct.bind(L,r,qe))),m=t.initReconnect(setTimeout.bind(L,ct.bind(L,r,$e)));a=()=>{g&&g(),m&&m(),z.delete(e)}}};return S(),[e,o,S,a]}return[e,z.get(e)[4]]},jt=(e,n,t,r,o)=>{const a=t.errorRetryCount,i=o.retryCount,d=~~((Math.random()+.5)*(1<<(i<8?i:8)))*t.errorRetryInterval;!h(a)&&i>a||setTimeout(r,d,o)},Nt=we,[ut,xt]=Pt(new Map),Mt=te({onLoadingSlow:ee,onSuccess:ee,onError:ee,onErrorRetry:jt,onDiscarded:ee,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:at?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:at?5e3:3e3,compare:Nt,isPaused:()=>!1,cache:ut,mutate:xt,fallback:{}},Dt),Ut=(e,n)=>{const t=te(e,n);if(n){const{use:r,fallback:o}=e,{use:a,fallback:i}=n;r&&a&&(t.use=r.concat(a)),o&&i&&(t.fallback=te(o,i))}return t},Wt=f.createContext({}),Gt="$inf$",lt=de&&window.__SWR_DEVTOOLS_USE__,Yt=lt?window.__SWR_DEVTOOLS_USE__:[],Bt=()=>{lt&&(window.__SWR_DEVTOOLS_REACT__=f)},Ht=e=>G(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],Jt=()=>te(Mt,f.useContext(Wt)),Kt=e=>(n,t,r)=>e(n,t&&((...a)=>{const[i]=Ne(n),[,,,d]=z.get(ut);if(i.startsWith(Gt))return t(...a);const p=d[i];return h(p)?t(...a):(delete d[i],p)}),r),zt=Yt.concat(Kt),Xt=e=>function(...t){const r=Jt(),[o,a,i]=Ht(t),d=Ut(r,i);let p=e;const{use:S}=d,g=(S||[]).concat(zt);for(let m=g.length;m--;)p=g[m](p);return p(o,a||d.fetcher||null,d)},Zt=(e,n,t)=>{const r=n[e]||(n[e]=[]);return r.push(t),()=>{const o=r.indexOf(t);o>=0&&(r[o]=r[r.length-1],r.pop())}};Bt();const Me=f.use||(e=>{switch(e.status){case"pending":throw e;case"fulfilled":return e.value;case"rejected":throw e.reason;default:throw e.status="pending",e.then(n=>{e.status="fulfilled",e.value=n},n=>{e.status="rejected",e.reason=n}),e}}),Ue={dedupe:!0},We=Xt((e,n,t)=>{const{cache:r,compare:o,suspense:a,fallbackData:i,revalidateOnMount:d,revalidateIfStale:p,refreshInterval:S,refreshWhenHidden:g,refreshWhenOffline:m,keepPreviousData:v}=t,[u,_,E,V]=z.get(r),[c,Y]=Ne(e),se=f.useRef(!1),B=f.useRef(!1),C=f.useRef(c),F=f.useRef(n),ne=f.useRef(t),O=()=>ne.current,re=()=>O().isVisible()&&O().isOnline(),[x,H,J,N]=ot(r,c),K=f.useRef({}).current,ae=h(i)?h(t.fallback)?L:t.fallback[c]:i,Ee=(T,R)=>{for(const I in K){const y=I;if(y==="data"){if(!o(T[y],R[y])&&(!h(T[y])||!o(P,R[y])))return!1}else if(R[y]!==T[y])return!1}return!0},pe=f.useMemo(()=>{const T=!c||!n?!1:h(d)?O().isPaused()||a?!1:p!==!1:d,R=j=>{const Q=te(j);return delete Q._k,T?{isValidating:!0,isLoading:!0,...Q}:Q},I=x(),y=N(),W=R(I),ue=I===y?W:R(y);let D=W;return[()=>{const j=R(x());return Ee(j,D)?(D.data=j.data,D.isLoading=j.isLoading,D.isValidating=j.isValidating,D.error=j.error,D):(D=j,j)},()=>ue]},[r,c]),X=Ot.useSyncExternalStore(f.useCallback(T=>J(c,(R,I)=>{Ee(I,R)||T()}),[r,c]),pe[0],pe[1]),ve=!se.current,s=u[c]&&u[c].length>0,l=X.data,b=h(l)?ae&&rt(ae)?Me(ae):ae:l,w=X.error,M=f.useRef(b),P=v?h(l)?h(M.current)?b:M.current:l:b,ie=s&&!h(w)?!1:ve&&!h(d)?d:O().isPaused()?!1:a?h(b)?!1:p:h(b)||p,ce=!!(c&&n&&ve&&ie),k=h(X.isValidating)?ce:X.isValidating,oe=h(X.isLoading)?ce:X.isLoading,Z=f.useCallback(async T=>{const R=F.current;if(!c||!R||B.current||O().isPaused())return!1;let I,y,W=!0;const ue=T||{},D=!E[c]||!ue.dedupe,j=()=>st?!B.current&&c===C.current&&se.current:c===C.current,Q={isValidating:!1,isLoading:!1},ft=()=>{H(Q)},dt=()=>{const U=E[c];U&&U[1]===y&&delete E[c]},mt={isValidating:!0};h(x().data)&&(mt.isLoading=!0);try{if(D&&(H(mt),t.loadingTimeout&&h(x().data)&&setTimeout(()=>{W&&j()&&O().onLoadingSlow(c,t)},t.loadingTimeout),E[c]=[R(Y),xe()]),[I,y]=E[c],I=await I,D&&setTimeout(dt,t.dedupingInterval),!E[c]||E[c][1]!==y)return D&&j()&&O().onDiscarded(c),!1;Q.error=L;const U=_[c];if(!h(U)&&(y<=U[0]||y<=U[1]||U[1]===0))return ft(),D&&j()&&O().onDiscarded(c),!1;const q=x().data;Q.data=o(q,I)?q:I,D&&j()&&O().onSuccess(I,c,t)}catch(U){dt();const q=O(),{shouldRetryOnError:Ye}=q;q.isPaused()||(Q.error=U,D&&j()&&(q.onError(U,c,q),(Ye===!0||G(Ye)&&Ye(U))&&(!O().revalidateOnFocus||!O().revalidateOnReconnect||re())&&q.onErrorRetry(U,c,q,dn=>{const Be=u[c];Be&&Be[0]&&Be[0](tt,dn)},{retryCount:(ue.retryCount||0)+1,dedupe:!0})))}return W=!1,ft(),!0},[c,r]),Re=f.useCallback((...T)=>it(r,C.current,...T),[]);if(Ve(()=>{F.current=n,ne.current=t,h(l)||(M.current=l)}),Ve(()=>{if(!c)return;const T=Z.bind(L,Ue);let R=0;O().revalidateOnFocus&&(R=Date.now()+O().focusThrottleInterval);const y=Zt(c,u,(W,ue={})=>{if(W==qe){const D=Date.now();O().revalidateOnFocus&&D>R&&re()&&(R=D+O().focusThrottleInterval,T())}else if(W==$e)O().revalidateOnReconnect&&re()&&T();else{if(W==et)return Z();if(W==tt)return Z(ue)}});return B.current=!1,C.current=c,se.current=!0,H({_k:Y}),ie&&(h(b)||me?T():Lt(T)),()=>{B.current=!0,y()}},[c]),Ve(()=>{let T;function R(){const y=G(S)?S(x().data):S;y&&T!==-1&&(T=setTimeout(I,y))}function I(){!x().error&&(g||O().isVisible())&&(m||O().isOnline())?Z(Ue).then(R):R()}return R(),()=>{T&&(clearTimeout(T),T=-1)}},[S,g,m,c]),f.useDebugValue(P),a&&h(b)&&c){if(!st&&me)throw new Error("Fallback data is required when using Suspense in SSR.");F.current=n,ne.current=t,B.current=!1;const T=V[c];if(!h(T)){const R=Re(T);Me(R)}if(h(w)){const R=Z(Ue);h(P)||(R.status="fulfilled",R.value=!0),Me(R)}else throw w}return{mutate:Re,get data(){return K.data=!0,P},get error(){return K.error=!0,w},get isValidating(){return K.isValidating=!0,k},get isLoading(){return K.isLoading=!0,oe}}}),Qt=()=>null,be=async(e,n={method:"GET"})=>{throw new Error("Figma API token is not available.")},qt="https://api.figma.com/v1/files",Ge=e=>`${qt}/${e}/variables`,$t=e=>{const n=$(),{data:t,error:r,isLoading:o,isValidating:a}=We(n?Ge(e):null,be),i=t!=null&&t.meta?Object.values(t.meta.variables):[],d=t!=null&&t.meta?t.meta.variables:{};return{variables:i,variablesById:d,isLoading:o,isValidating:a,error:r??(t&&"message"in t?new Error(t.message):null)}},en=e=>{const n=$(),{data:t,error:r,isLoading:o,isValidating:a}=We(n?Ge(e):null,be),i=t!=null&&t.meta?Object.values(t.meta.variableCollections):[],d=t!=null&&t.meta?t.meta.variableCollections:{};return{collections:i,collectionsById:d,isLoading:o,isValidating:a,error:r??(t&&"message"in t?new Error(t.message):null)}},tn=e=>{const n=$(),{data:t,error:r,isLoading:o,isValidating:a}=We(n?Ge(e):null,be),i=[],d={},p={};if(t!=null&&t.meta)for(const S of Object.values(t.meta.variableCollections)){i.push(...S.modes),d[S.id]=S.modes;for(const g of S.modes)p[g.modeId]=g}return{modes:i,modesByCollectionId:d,modesById:p,isLoading:o,isValidating:a,error:r??(t&&"message"in t?new Error(t.message):null)}};async function nn(e,n,t){const r=`https://api.figma.com/v1/files/${n}/variables`;try{const o=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":e},body:JSON.stringify(t)}),a=await o.json();return o.ok?{error:!1,status:o.status,meta:a.meta}:{error:!0,status:o.status,message:a.message||"Failed to perform bulk update."}}catch(o){return{error:!0,status:500,message:o instanceof Error?o.message:"An unknown error occurred."}}}const rn=()=>{const e=$(),[n,t]=f.useState(!1),[r,o]=f.useState(null),[a,i]=f.useState(null);return{bulkUpdate:f.useCallback(async(p,S)=>{if(!e){o("Figma API token is not provided.");return}t(!0),o(null);const g=await nn(e,p,S);i(g),g.error&&o(g.message||"An error occurred during the bulk update."),t(!1)},[e]),loading:n,error:r,data:a}};async function on(e,n){const t="https://api.figma.com/v1/variables";try{const r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":e},body:JSON.stringify(n)});if(!r.ok){const a=await r.json();return{error:!0,status:r.status,message:a.message||"Failed to create Figma variable"}}const o=await r.json();return{error:!1,status:r.status,variable:o}}catch(r){return{error:!0,status:500,message:r instanceof Error?r.message:"An unknown error occurred"}}}const sn=()=>{const e=$(),[n,t]=f.useState(!1),[r,o]=f.useState(null),[a,i]=f.useState(null);return{createVariable:f.useCallback(async p=>{if(!e){o("Figma API token is not provided.");return}t(!0),o(null);const S=await on(e,p);i(S),S.error&&o(S.message||"An error occurred."),t(!1)},[e]),loading:n,error:r,data:a}};async function an(e,n){const t=`https://api.figma.com/v1/variables/${n}`;try{const r=await fetch(t,{method:"DELETE",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":e}});if(!r.ok){const o=await r.json();return{error:!0,status:r.status,message:o.message||"Failed to delete Figma variable"}}return{error:!1,status:r.status}}catch(r){return{error:!0,status:500,message:r instanceof Error?r.message:"An unknown error occurred"}}}const cn=()=>{const e=$(),[n,t]=f.useState(!1),[r,o]=f.useState(null),[a,i]=f.useState(null);return{deleteVariable:f.useCallback(async p=>{if(!e){o("Figma API token is not provided.");return}t(!0),o(null);const S=await an(e,p);i(S),S.error&&o(S.message||"An error occurred."),t(!1)},[e]),loading:n,error:r,data:a}};async function un(e,n,t){const r=`https://api.figma.com/v1/variables/${n}`;try{const o=await fetch(r,{method:"PUT",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":e},body:JSON.stringify(t)});if(!o.ok){const a=await o.json();return{error:!0,status:o.status,message:a.message||"Failed to update Figma variable"}}return{error:!1,status:o.status}}catch(o){return{error:!0,status:500,message:o instanceof Error?o.message:"An unknown error occurred"}}}const ln=()=>{const e=$(),[n,t]=f.useState(!1),[r,o]=f.useState(null),[a,i]=f.useState(null);return{updateVariable:f.useCallback(async(p,S)=>{if(!e){o("Figma API token is not provided.");return}t(!0),o(null);const g=await un(e,p,S);i(g),g.error&&o(g.message||"An error occurred."),t(!1)},[e]),loading:n,error:r,data:a}};function fn(e,n){return e.filter(t=>{let r=!0;return n.resolvedType&&(r=r&&t.resolvedType===n.resolvedType),n.name&&(r=r&&t.name.includes(n.name)),r})}A.FigmaVarsProvider=St,A.fetchWithAuth=be,A.filterVariables=fn,A.getFigmaToken=Qt,A.useBulkUpdateVariables=rn,A.useCreateVariable=sn,A.useDeleteVariable=cn,A.useFigmaToken=$,A.useUpdateVariable=ln,A.useVariableCollections=en,A.useVariableModes=tn,A.useVariables=$t,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Retrieves the Figma API token from
|
|
2
|
+
* Retrieves the Figma API token from the FigmaVarsProvider.
|
|
3
|
+
* This hook must be used within a component wrapped by FigmaVarsProvider.
|
|
3
4
|
*/
|
|
4
|
-
declare const useFigmaToken: () => string;
|
|
5
|
+
declare const useFigmaToken: () => string | null;
|
|
5
6
|
export default useFigmaToken;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import { FigmaCollection
|
|
2
|
-
|
|
3
|
-
|
|
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,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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,16 +1,14 @@
|
|
|
1
1
|
import { FigmaVariable } from 'types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @param
|
|
6
|
-
* @
|
|
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
7
|
*/
|
|
8
|
-
declare const useVariables: (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
error:
|
|
14
|
-
refresh: () => void;
|
|
8
|
+
export declare const useVariables: (fileKey: string) => {
|
|
9
|
+
variables: FigmaVariable[];
|
|
10
|
+
variablesById: Record<string, FigmaVariable>;
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
isValidating: boolean;
|
|
13
|
+
error: any;
|
|
15
14
|
};
|
|
16
|
-
export default useVariables;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
export { default as useFigmaToken } from './hooks/useFigmaToken';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export * from '
|
|
10
|
-
export * from 'utils/
|
|
11
|
-
export * from 'utils/fetchHelpers';
|
|
12
|
-
export * from 'utils/authHelpers';
|
|
13
|
-
export {
|
|
14
|
-
export { default as useVariableBindings } from 'experimental/useVariableBindings';
|
|
15
|
-
export { default as usePublishVars } from 'experimental/usePublishVars';
|
|
16
|
-
export { default as useSync } from 'experimental/useSync';
|
|
2
|
+
export { useVariables } from './hooks/useVariables';
|
|
3
|
+
export { useVariableCollections } from './hooks/useVariableCollections';
|
|
4
|
+
export { useVariableModes } from './hooks/useVariableModes';
|
|
5
|
+
export { useBulkUpdateVariables } from './mutations/bulkUpdateVariables';
|
|
6
|
+
export { useCreateVariable } from './mutations/createVariable';
|
|
7
|
+
export { useDeleteVariable } from './mutations/deleteVariable';
|
|
8
|
+
export { useUpdateVariable } from './mutations/updateVariable';
|
|
9
|
+
export * from './types';
|
|
10
|
+
export * from './utils/filterVariables';
|
|
11
|
+
export * from './utils/fetchHelpers';
|
|
12
|
+
export * from './utils/authHelpers';
|
|
13
|
+
export { FigmaVarsProvider } from './contexts/FigmaTokenContext';
|
|
@@ -0,0 +1,7 @@
|
|
|
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,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare function createVariable(fileKey: string, variableData: any): Promise<FigmaOperationResponse>;
|
|
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,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare function deleteVariable(fileKey: string, variableId: string): Promise<FigmaOperationResponse>;
|
|
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,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
export declare function updateVariable(fileKey: string, variableId: string, newVariableData: any): Promise<FigmaOperationResponse>;
|
|
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
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
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;
|
|
1
14
|
export interface FigmaVariable {
|
|
2
15
|
id: string;
|
|
3
16
|
name: string;
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
6
29
|
}
|
|
7
30
|
export interface FigmaCollection {
|
|
8
31
|
id: string;
|
|
9
32
|
name: string;
|
|
10
|
-
|
|
33
|
+
modes: VariableMode[];
|
|
34
|
+
defaultModeId: string;
|
|
35
|
+
variableIds: string[];
|
|
36
|
+
hiddenFromPublishing: boolean;
|
|
37
|
+
updatedAt: string;
|
|
11
38
|
}
|
|
12
|
-
export interface
|
|
39
|
+
export interface LocalVariablesResponse {
|
|
13
40
|
meta: {
|
|
14
|
-
|
|
41
|
+
variableCollections: Record<string, FigmaCollection>;
|
|
42
|
+
variables: Record<string, FigmaVariable>;
|
|
15
43
|
};
|
|
16
44
|
}
|
|
17
45
|
export interface FigmaError {
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
import { VariableMode } from './figma';
|
|
1
2
|
export interface HookState<T> {
|
|
2
3
|
data: T | null;
|
|
3
4
|
loading: boolean;
|
|
4
5
|
error: Error | null;
|
|
5
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
|
+
}
|
|
6
15
|
export interface SyncStatus {
|
|
7
16
|
isSyncing: boolean;
|
|
8
17
|
lastSynced: Date | null;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FigmaVariable, ResolvedType, VariableScope, VariableValue } from './figma';
|
|
1
2
|
export interface FigmaOperationResponse {
|
|
2
3
|
success: boolean;
|
|
3
4
|
message?: string;
|
|
@@ -7,3 +8,69 @@ export interface VariableValueUpdate {
|
|
|
7
8
|
value: string;
|
|
8
9
|
}
|
|
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
|
+
}
|
|
@@ -2,7 +2,3 @@
|
|
|
2
2
|
* Retrieves the Figma API token from environment variables or any other secure storage mechanism you've implemented.
|
|
3
3
|
*/
|
|
4
4
|
export declare const getFigmaToken: () => string | null;
|
|
5
|
-
/**
|
|
6
|
-
* Placeholder for a more complex token validation or renewal logic, if needed.
|
|
7
|
-
*/
|
|
8
|
-
export declare const validateToken: () => boolean;
|
|
@@ -6,5 +6,5 @@ interface FetchOptions {
|
|
|
6
6
|
/**
|
|
7
7
|
* A helper function for making authenticated fetch requests to the Figma API.
|
|
8
8
|
*/
|
|
9
|
-
export declare const fetchWithAuth: (
|
|
9
|
+
export declare const fetchWithAuth: (url: string, options?: FetchOptions) => Promise<any>;
|
|
10
10
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@figma-vars/hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"sideEffects": false,
|
|
43
43
|
"exports": {
|
|
44
44
|
".": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
45
46
|
"import": "./dist/index.mjs",
|
|
46
|
-
"require": "./dist/index.js"
|
|
47
|
-
"types": "./dist/index.d.ts"
|
|
47
|
+
"require": "./dist/index.js"
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"funding": {
|
|
@@ -64,6 +64,9 @@
|
|
|
64
64
|
"directories": {
|
|
65
65
|
"doc": "docs"
|
|
66
66
|
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"swr": "^2.3.3"
|
|
69
|
+
},
|
|
67
70
|
"scripts": {
|
|
68
71
|
"dev": "vite",
|
|
69
72
|
"build": "tsc && vite build",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FigmaVariable } from 'types';
|
|
2
|
-
declare const useVariableAliases: () => {
|
|
3
|
-
aliases: {
|
|
4
|
-
[alias: string]: FigmaVariable;
|
|
5
|
-
};
|
|
6
|
-
setAlias: (alias: string, variable: FigmaVariable) => void;
|
|
7
|
-
removeAlias: (alias: string) => void;
|
|
8
|
-
};
|
|
9
|
-
export default useVariableAliases;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FigmaVariable } from 'types';
|
|
2
|
-
declare const useVariableBindings: () => {
|
|
3
|
-
bindings: Map<string, FigmaVariable>;
|
|
4
|
-
bindVariable: (elementId: string, variable: FigmaVariable) => void;
|
|
5
|
-
unbindVariable: (elementId: string) => void;
|
|
6
|
-
};
|
|
7
|
-
export default useVariableBindings;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { FigmaOperationResponse } from 'types';
|
|
2
|
-
/**
|
|
3
|
-
* Update a variable's value across modes (Figma Variables API).
|
|
4
|
-
* @param variableId The variable ID
|
|
5
|
-
* @param values The new values for each mode
|
|
6
|
-
* @returns Promise<FigmaOperationResponse>
|
|
7
|
-
*/
|
|
8
|
-
export declare function updateVariableValues(variableId: string, values: any): Promise<FigmaOperationResponse>;
|
package/dist/utils/cache.d.ts
DELETED