@figma-vars/hooks 1.4.5 → 1.5.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 +1 -1
- package/dist/index.js +17 -0
- package/dist/index.mjs +838 -0
- package/package.json +1 -1
- package/dist/figma-vars-hooks.js +0 -838
- package/dist/figma-vars-hooks.umd.cjs +0 -17
- package/dist/src/api/mutator.test.d.ts +0 -1
- package/dist/tests/FigmaVarsProvider.test.d.ts +0 -1
- package/dist/tests/api/fetcher.test.d.ts +0 -1
- package/dist/tests/api/index.test.d.ts +0 -1
- package/dist/tests/api/mutator.test.d.ts +0 -1
- package/dist/tests/constants/index.test.d.ts +0 -1
- package/dist/tests/contexts/index.test.d.ts +0 -1
- package/dist/tests/hooks/index.test.d.ts +0 -1
- package/dist/tests/hooks/useBulkUpdateVariables.test.d.ts +0 -1
- package/dist/tests/hooks/useCreateVariable.test.d.ts +0 -1
- package/dist/tests/hooks/useDeleteVariable.test.d.ts +0 -1
- package/dist/tests/hooks/useFigmaToken.test.d.ts +0 -1
- package/dist/tests/hooks/useMutation.test.d.ts +0 -1
- package/dist/tests/hooks/useUpdateVariable.test.d.ts +0 -1
- package/dist/tests/hooks/useVariableCollections.test.d.ts +0 -1
- package/dist/tests/hooks/useVariableModes.test.d.ts +0 -1
- package/dist/tests/hooks/useVariables.test.d.ts +0 -1
- package/dist/tests/index.test.d.ts +0 -1
- package/dist/tests/mocks/variables.d.ts +0 -2
- package/dist/tests/setup.d.ts +0 -0
- package/dist/tests/test-utils.d.ts +0 -10
- package/dist/tests/test-utils.test.d.ts +0 -1
- package/dist/tests/types.test.d.ts +0 -1
- package/dist/tests/utils/filterVariables.test.d.ts +0 -1
- package/dist/tests/utils/index.test.d.ts +0 -1
- /package/dist/{src/api → api}/fetcher.d.ts +0 -0
- /package/dist/{src/api → api}/index.d.ts +0 -0
- /package/dist/{src/api → api}/mutator.d.ts +0 -0
- /package/dist/{src/constants → constants}/index.d.ts +0 -0
- /package/dist/{src/contexts → contexts}/FigmaVarsProvider.d.ts +0 -0
- /package/dist/{src/contexts → contexts}/index.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/index.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useBulkUpdateVariables.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useCreateVariable.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useDeleteVariable.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useFigmaToken.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useMutation.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useUpdateVariable.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useVariableCollections.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useVariableModes.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useVariables.d.ts +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/types → types}/contexts.d.ts +0 -0
- /package/dist/{src/types → types}/figma.d.ts +0 -0
- /package/dist/{src/types → types}/hooks.d.ts +0 -0
- /package/dist/{src/types → types}/index.d.ts +0 -0
- /package/dist/{src/types → types}/mutations.d.ts +0 -0
- /package/dist/{src/utils → utils}/filterVariables.d.ts +0 -0
- /package/dist/{src/utils → utils}/index.d.ts +0 -0
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
(function(y,Z){typeof exports=="object"&&typeof module<"u"?Z(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],Z):(y=typeof globalThis<"u"?globalThis:y||self,Z(y["@figma-vars/hooks"]={},y["react/jsx-runtime"],y.React))})(this,function(y,Z,p){"use strict";const Pe=p.createContext(void 0),dt=({children:e,token:t,fileKey:n})=>Z.jsx(Pe.Provider,{value:{token:t,fileKey:n},children:e}),ee=()=>{const e=p.useContext(Pe);if(e===void 0)throw new Error("useFigmaTokenContext must be used within a FigmaVarsProvider");return e};var se={exports:{}},Ee={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* use-sync-external-store-shim.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 je;function Et(){if(je)return Ee;je=1;var e=p;function t(c,d){return c===d&&(c!==0||1/c===1/d)||c!==c&&d!==d}var n=typeof Object.is=="function"?Object.is:t,r=e.useState,o=e.useEffect,s=e.useLayoutEffect,i=e.useDebugValue;function E(c,d){var u=d(),m=r({inst:{value:u,getSnapshot:d}}),l=m[0].inst,I=m[1];return s(function(){l.value=u,l.getSnapshot=d,S(l)&&I({inst:l})},[c,u,d]),o(function(){return S(l)&&I({inst:l}),c(function(){S(l)&&I({inst:l})})},[c]),i(u),u}function S(c){var d=c.getSnapshot;c=c.value;try{var u=d();return!n(c,u)}catch{return!0}}function D(c,d){return d()}var O=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?D:E;return Ee.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:O,Ee}var me={};/**
|
|
10
|
-
* @license React
|
|
11
|
-
* use-sync-external-store-shim.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 xe;function mt(){return xe||(xe=1,process.env.NODE_ENV!=="production"&&function(){function e(u,m){return u===m&&(u!==0||1/u===1/m)||u!==u&&m!==m}function t(u,m){O||o.startTransition===void 0||(O=!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 l=m();if(!c){var I=m();s(l,I)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}I=i({inst:{value:l,getSnapshot:m}});var a=I[0].inst,W=I[1];return S(function(){a.value=l,a.getSnapshot=m,n(a)&&W({inst:a})},[u,l,m]),E(function(){return n(a)&&W({inst:a}),u(function(){n(a)&&W({inst:a})})},[u]),D(l),l}function n(u){var m=u.getSnapshot;u=u.value;try{var l=m();return!s(u,l)}catch{return!0}}function r(u,m){return m()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=p,s=typeof Object.is=="function"?Object.is:e,i=o.useState,E=o.useEffect,S=o.useLayoutEffect,D=o.useDebugValue,O=!1,c=!1,d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:t;me.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())}()),me}var Ue;function pt(){return Ue||(Ue=1,process.env.NODE_ENV==="production"?se.exports=Et():se.exports=mt()),se.exports}var ht=pt();const Ge=0,We=1,ke=2,qe=3;var Be=Object.prototype.hasOwnProperty;function pe(e,t){var n,r;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((r=e.length)===t.length)for(;r--&&pe(e[r],t[r]););return r===-1}if(!n||typeof e=="object"){r=0;for(n in e)if(Be.call(e,n)&&++r&&!Be.call(t,n)||!(n in t)||!pe(e[n],t[n]))return!1;return Object.keys(t).length===r}}return e!==e&&t!==t}const P=new WeakMap,U=()=>{},R=U(),he=Object,f=e=>e===R,F=e=>typeof e=="function",G=(e,t)=>({...e,...t}),$e=e=>F(e.then),Se={},ie={},_e="undefined",te=typeof window!=_e,ve=typeof document!=_e,St=te&&"Deno"in window,_t=()=>te&&typeof window.requestAnimationFrame!=_e,He=(e,t)=>{const n=P.get(e);return[()=>!f(t)&&e.get(t)||Se,r=>{if(!f(t)){const o=e.get(t);t in ie||(ie[t]=o),n[5](t,G(o,r),o||Se)}},n[6],()=>!f(t)&&t in ie?ie[t]:!f(t)&&e.get(t)||Se]};let Oe=!0;const vt=()=>Oe,[we,Te]=te&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[U,U],Ot=()=>{const e=ve&&document.visibilityState;return f(e)||e!=="hidden"},wt=e=>(ve&&document.addEventListener("visibilitychange",e),we("focus",e),()=>{ve&&document.removeEventListener("visibilitychange",e),Te("focus",e)}),Tt=e=>{const t=()=>{Oe=!0,e()},n=()=>{Oe=!1};return we("online",t),we("offline",n),()=>{Te("online",t),Te("offline",n)}},yt={isOnline:vt,isVisible:Ot},gt={initFocus:wt,initReconnect:Tt},Ke=!p.useId,ne=!te||St,At=e=>_t()?window.requestAnimationFrame(e):setTimeout(e,1),ye=ne?p.useEffect:p.useLayoutEffect,ge=typeof navigator<"u"&&navigator.connection,Je=!ne&&ge&&(["slow-2g","2g"].includes(ge.effectiveType)||ge.saveData),ae=new WeakMap,Ae=(e,t)=>he.prototype.toString.call(e)===`[object ${t}]`;let Rt=0;const Re=e=>{const t=typeof e,n=Ae(e,"Date"),r=Ae(e,"RegExp"),o=Ae(e,"Object");let s,i;if(he(e)===e&&!n&&!r){if(s=ae.get(e),s)return s;if(s=++Rt+"~",ae.set(e,s),Array.isArray(e)){for(s="@",i=0;i<e.length;i++)s+=Re(e[i])+",";ae.set(e,s)}if(o){s="#";const E=he.keys(e).sort();for(;!f(i=E.pop());)f(e[i])||(s+=i+":"+Re(e[i])+",");ae.set(e,s)}}else s=n?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return s},De=e=>{if(F(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?Re(e):"",[e,t]};let Dt=0;const Ce=()=>++Dt;async function Ye(...e){const[t,n,r,o]=e,s=G({populateCache:!0,throwOnError:!0},typeof o=="boolean"?{revalidate:o}:o||{});let i=s.populateCache;const E=s.rollbackOnError;let S=s.optimisticData;const D=d=>typeof E=="function"?E(d):E!==!1,O=s.throwOnError;if(F(n)){const d=n,u=[],m=t.keys();for(const l of m)!/^\$(inf|sub)\$/.test(l)&&d(t.get(l)._k)&&u.push(l);return Promise.all(u.map(c))}return c(n);async function c(d){const[u]=De(d);if(!u)return;const[m,l]=He(t,u),[I,a,W,re]=P.get(t),k=()=>{const V=I[u];return(F(s.revalidate)?s.revalidate(m().data,d):s.revalidate!==!1)&&(delete W[u],delete re[u],V&&V[0])?V[0](ke).then(()=>m().data):m().data};if(e.length<3)return k();let g=r,b;const H=Ce();a[u]=[H,0];const v=!f(S),K=m(),M=K.data,J=K._c,q=f(J)?M:J;if(v&&(S=F(S)?S(q,M):S,l({data:S,_c:q})),F(g))try{g=g(q)}catch(V){b=V}if(g&&$e(g))if(g=await g.catch(V=>{b=V}),H!==a[u][0]){if(b)throw b;return g}else b&&v&&D(b)&&(i=!0,l({data:q,_c:R}));if(i&&!b)if(F(i)){const V=i(g,q);l({data:V,error:R,_c:R})}else l({data:g,error:R,_c:R});if(a[u][1]=Ce(),Promise.resolve(k()).then(()=>{l({_c:R})}),b){if(O)throw b;return}return g}}const ze=(e,t)=>{for(const n in e)e[n][0]&&e[n][0](t)},Ct=(e,t)=>{if(!P.has(e)){const n=G(gt,t),r=Object.create(null),o=Ye.bind(R,e);let s=U;const i=Object.create(null),E=(O,c)=>{const d=i[O]||[];return i[O]=d,d.push(c),()=>d.splice(d.indexOf(c),1)},S=(O,c,d)=>{e.set(O,c);const u=i[O];if(u)for(const m of u)m(c,d)},D=()=>{if(!P.has(e)&&(P.set(e,[r,Object.create(null),Object.create(null),Object.create(null),o,S,E]),!ne)){const O=n.initFocus(setTimeout.bind(R,ze.bind(R,r,Ge))),c=n.initReconnect(setTimeout.bind(R,ze.bind(R,r,We)));s=()=>{O&&O(),c&&c(),P.delete(e)}}};return D(),[e,o,D,s]}return[e,P.get(e)[4]]},It=(e,t,n,r,o)=>{const s=n.errorRetryCount,i=o.retryCount,E=~~((Math.random()+.5)*(1<<(i<8?i:8)))*n.errorRetryInterval;!f(s)&&i>s||setTimeout(r,E,o)},bt=pe,[Xe,Lt]=Ct(new Map),Vt=G({onLoadingSlow:U,onSuccess:U,onError:U,onErrorRetry:It,onDiscarded:U,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Je?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Je?5e3:3e3,compare:bt,isPaused:()=>!1,cache:Xe,mutate:Lt,fallback:{}},yt),Nt=(e,t)=>{const n=G(e,t);if(t){const{use:r,fallback:o}=e,{use:s,fallback:i}=t;r&&s&&(n.use=r.concat(s)),o&&i&&(n.fallback=G(o,i))}return n},Ft=p.createContext({}),Mt="$inf$",Qe=te&&window.__SWR_DEVTOOLS_USE__,Pt=Qe?window.__SWR_DEVTOOLS_USE__:[],jt=()=>{Qe&&(window.__SWR_DEVTOOLS_REACT__=p)},xt=e=>F(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],Ut=()=>G(Vt,p.useContext(Ft)),Gt=e=>(t,n,r)=>e(t,n&&((...s)=>{const[i]=De(t),[,,,E]=P.get(Xe);if(i.startsWith(Mt))return n(...s);const S=E[i];return f(S)?n(...s):(delete E[i],S)}),r),Wt=Pt.concat(Gt),kt=e=>function(...n){const r=Ut(),[o,s,i]=xt(n),E=Nt(r,i);let S=e;const{use:D}=E,O=(D||[]).concat(Wt);for(let c=O.length;c--;)S=O[c](S);return S(o,s||E.fetcher||null,E)},qt=(e,t,n)=>{const r=t[e]||(t[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o>=0&&(r[o]=r[r.length-1],r.pop())}};jt();const Ie=p.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(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e}}),be={dedupe:!0},Bt=kt((e,t,n)=>{const{cache:r,compare:o,suspense:s,fallbackData:i,revalidateOnMount:E,revalidateIfStale:S,refreshInterval:D,refreshWhenHidden:O,refreshWhenOffline:c,keepPreviousData:d}=n,[u,m,l,I]=P.get(r),[a,W]=De(e),re=p.useRef(!1),k=p.useRef(!1),g=p.useRef(a),b=p.useRef(t),H=p.useRef(n),v=()=>H.current,K=()=>v().isVisible()&&v().isOnline(),[M,J,q,V]=He(r,a),Y=p.useRef({}).current,le=f(i)?f(n.fallback)?R:n.fallback[a]:i,rt=(_,h)=>{for(const A in Y){const w=A;if(w==="data"){if(!o(_[w],h[w])&&(!f(_[w])||!o(de,h[w])))return!1}else if(h[w]!==_[w])return!1}return!0},ot=p.useMemo(()=>{const _=!a||!t?!1:f(E)?v().isPaused()||s?!1:S!==!1:E,h=C=>{const j=G(C);return delete j._k,_?{isValidating:!0,isLoading:!0,...j}:j},A=M(),w=V(),N=h(A),Q=A===w?N:h(w);let T=N;return[()=>{const C=h(M());return rt(C,T)?(T.data=C.data,T.isLoading=C.isLoading,T.isValidating=C.isValidating,T.error=C.error,T):(T=C,C)},()=>Q]},[r,a]),z=ht.useSyncExternalStore(p.useCallback(_=>q(a,(h,A)=>{rt(A,h)||_()}),[r,a]),ot[0],ot[1]),st=!re.current,on=u[a]&&u[a].length>0,X=z.data,B=f(X)?le&&$e(le)?Ie(le):le:X,fe=z.error,Ne=p.useRef(B),de=d?f(X)?f(Ne.current)?B:Ne.current:X:B,it=on&&!f(fe)?!1:st&&!f(E)?E:v().isPaused()?!1:s?f(B)?!1:S:f(B)||S,at=!!(a&&t&&st&&it),sn=f(z.isValidating)?at:z.isValidating,an=f(z.isLoading)?at:z.isLoading,oe=p.useCallback(async _=>{const h=b.current;if(!a||!h||k.current||v().isPaused())return!1;let A,w,N=!0;const Q=_||{},T=!l[a]||!Q.dedupe,C=()=>Ke?!k.current&&a===g.current&&re.current:a===g.current,j={isValidating:!1,isLoading:!1},ct=()=>{J(j)},lt=()=>{const L=l[a];L&&L[1]===w&&delete l[a]},ft={isValidating:!0};f(M().data)&&(ft.isLoading=!0);try{if(T&&(J(ft),n.loadingTimeout&&f(M().data)&&setTimeout(()=>{N&&C()&&v().onLoadingSlow(a,n)},n.loadingTimeout),l[a]=[h(W),Ce()]),[A,w]=l[a],A=await A,T&&setTimeout(lt,n.dedupingInterval),!l[a]||l[a][1]!==w)return T&&C()&&v().onDiscarded(a),!1;j.error=R;const L=m[a];if(!f(L)&&(w<=L[0]||w<=L[1]||L[1]===0))return ct(),T&&C()&&v().onDiscarded(a),!1;const x=M().data;j.data=o(x,A)?x:A,T&&C()&&v().onSuccess(A,a,n)}catch(L){lt();const x=v(),{shouldRetryOnError:Fe}=x;x.isPaused()||(j.error=L,T&&C()&&(x.onError(L,a,x),(Fe===!0||F(Fe)&&Fe(L))&&(!v().revalidateOnFocus||!v().revalidateOnReconnect||K())&&x.onErrorRetry(L,a,x,un=>{const Me=u[a];Me&&Me[0]&&Me[0](qe,un)},{retryCount:(Q.retryCount||0)+1,dedupe:!0})))}return N=!1,ct(),!0},[a,r]),ut=p.useCallback((..._)=>Ye(r,g.current,..._),[]);if(ye(()=>{b.current=t,H.current=n,f(X)||(Ne.current=X)}),ye(()=>{if(!a)return;const _=oe.bind(R,be);let h=0;v().revalidateOnFocus&&(h=Date.now()+v().focusThrottleInterval);const w=qt(a,u,(N,Q={})=>{if(N==Ge){const T=Date.now();v().revalidateOnFocus&&T>h&&K()&&(h=T+v().focusThrottleInterval,_())}else if(N==We)v().revalidateOnReconnect&&K()&&_();else{if(N==ke)return oe();if(N==qe)return oe(Q)}});return k.current=!1,g.current=a,re.current=!0,J({_k:W}),it&&(f(B)||ne?_():At(_)),()=>{k.current=!0,w()}},[a]),ye(()=>{let _;function h(){const w=F(D)?D(M().data):D;w&&_!==-1&&(_=setTimeout(A,w))}function A(){!M().error&&(O||v().isVisible())&&(c||v().isOnline())?oe(be).then(h):h()}return h(),()=>{_&&(clearTimeout(_),_=-1)}},[D,O,c,a]),p.useDebugValue(de),s&&f(B)&&a){if(!Ke&&ne)throw new Error("Fallback data is required when using Suspense in SSR.");b.current=t,H.current=n,k.current=!1;const _=I[a];if(!f(_)){const h=ut(_);Ie(h)}if(f(fe)){const h=oe(be);f(de)||(h.status="fulfilled",h.value=!0),Ie(h)}else throw fe}return{mutate:ut,get data(){return Y.data=!0,de},get error(){return Y.error=!0,fe},get isValidating(){return Y.isValidating=!0,sn},get isLoading(){return Y.isLoading=!0,an}}}),Le="https://api.figma.com",$t=`${Le}/v1/files`,Ze=`${Le}/v1/variables`,et=Ze,tt=e=>`${Ze}/${e}`,Ht=e=>`${$t}/${e}/variables/local`,Kt="application/json",nt="X-FIGMA-TOKEN",$="A Figma API token is required.",Jt="An error occurred while fetching data from the Figma API.";async function Yt(e,t){if(!t)throw new Error($);const n=await fetch(e,{method:"GET",headers:{[nt]:t,"Content-Type":Kt}});if(!n.ok){let r=Jt;try{const o=await n.json();o!=null&&o.message&&(r=o.message)}catch{}throw new Error(r)}return n.json()}const Ve=()=>{const{token:e,fileKey:t}=ee(),n=t?Ht(t):null,{data:r,error:o,isLoading:s,isValidating:i,mutate:E}=Bt(e&&n?[n,e]:null,Yt);return{data:r,isLoading:s,isValidating:i,error:o,mutate:E}},zt=()=>{const{data:e}=Ve(),t=p.useMemo(()=>e!=null&&e.meta?Object.values(e.meta.variableCollections):[],[e]),n=p.useMemo(()=>e!=null&&e.meta?e.meta.variableCollections:{},[e]);return{collections:t,collectionsById:n}},Xt=()=>{const{data:e}=Ve();return p.useMemo(()=>{const t=[],n={},r={};if(e!=null&&e.meta)for(const o of Object.values(e.meta.variableCollections)){t.push(...o.modes),n[o.id]=o.modes;for(const s of o.modes)r[s.modeId]=s}return{modes:t,modesByCollectionId:n,modesById:r}},[e])};function Qt(e,t){switch(t.type){case"loading":return{...e,status:"loading",error:null};case"success":return{...e,status:"success",data:t.payload};case"error":return{...e,status:"error",error:t.payload};default:return e}}const ue=e=>{const t={status:"idle",data:null,error:null},[n,r]=p.useReducer(Qt,t);return{mutate:p.useCallback(async s=>{r({type:"loading"});try{const i=await e(s);return r({type:"success",payload:i}),i}catch(i){r({type:"error",payload:i});return}},[e]),...n,isLoading:n.status==="loading",isSuccess:n.status==="success",isError:n.status==="error"}};async function ce(e,t,n,r){if(!t)throw new Error($);const s={CREATE:"POST",UPDATE:"PUT",DELETE:"DELETE"}[n],i=await fetch(`${Le}${e}`,{method:s,headers:{"Content-Type":"application/json",[nt]:t},body:r?JSON.stringify(r):void 0});if(!i.ok){const E=await i.json().catch(()=>({}));throw new Error(E.err||E.message||"An API error occurred")}return i.status===204||!i.body?{}:i.json()}const Zt=()=>{const{token:e}=ee();return ue(async n=>{if(!e)throw new Error($);return await ce(et,e,"CREATE",n)})},en=()=>{const{token:e}=ee();return ue(async({variableId:n,payload:r})=>{if(!e)throw new Error($);const o=tt(n);return await ce(o,e,"UPDATE",r)})},tn=()=>{const{token:e}=ee();return ue(async n=>{if(!e)throw new Error($);return await ce(tt(n),e,"DELETE",void 0)})},nn=()=>{const{token:e}=ee();return ue(async n=>{if(!e)throw new Error($);return await ce(et,e,"CREATE",n)})};function rn(e,t){return e.filter(n=>{let r=!0;return t.resolvedType&&(r=r&&n.resolvedType===t.resolvedType),t.name&&(r=r&&n.name.includes(t.name)),r})}y.FigmaVarsProvider=dt,y.filterVariables=rn,y.useBulkUpdateVariables=nn,y.useCreateVariable=Zt,y.useDeleteVariable=tn,y.useUpdateVariable=en,y.useVariableCollections=zt,y.useVariableModes=Xt,y.useVariables=Ve,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/tests/setup.d.ts
DELETED
|
File without changes
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
export declare const TestWrapper: ({ children }: {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
/**
|
|
6
|
-
* Custom renderHook function that automatically wraps hooks with the TestWrapper.
|
|
7
|
-
* @param hook The hook to render.
|
|
8
|
-
*/
|
|
9
|
-
export declare const renderHookWithWrapper: (hook: () => any) => import('@testing-library/react').RenderHookResult<any, unknown>;
|
|
10
|
-
export * from '@testing-library/react';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|