Skip to content

Commit

Permalink
hotfix empty export
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Jul 31, 2023
1 parent bef1cfe commit 4d5bf33
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@
display: grid;
grid-template-columns: repeat(3, 1fr);
}
`,hr=()=>{const{settings:n,updateSettings:t}=(0,e.useContext)(an),{tokens:r,setTokens:a}=(0,e.useContext)(ln),{figmaUIApi:l}=(0,e.useContext)(rn),o=(0,e.useRef)();return e.createElement("form",{onSubmit:e=>{if(e.preventDefault(),!0===e.target.checkValidity()){const{accessToken:e}=n,t=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++)n.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(t[r[a]]=e[r[a]])}return t}(n,["accessToken"]);if(l.postMessage({pluginMessage:{command:tn.saveSettings,payload:{settings:t,accessToken:e}}},"*"),!r||!r.length||"string"==typeof r)return void l.postMessage({pluginMessage:{command:tn.closePlugin,payload:{notification:"No tokens to export!"}}},"*");const i=fr(r,t);a(i),((e,n,t)=>{if("[]"!==t)try{n.href=`data:application/design-tokens+json;charset=utf-8,${encodeURIComponent(t)}`,n.click(),e.postMessage({pluginMessage:{command:tn.closePlugin,payload:{notification:"🎉 Design token export successful!"}}},"*")}catch(n){e.postMessage({pluginMessage:{payload:{notification:"⛔️ Design token failed!"}}},"*"),console.error("Export error: ",n)}else e.postMessage({pluginMessage:{payload:{notification:"⛔️ No design token detected!"}}},"*")})(parent,o.current,pr(i,t.compression))}},className:gr},e.createElement(Je,{size:"xlarge",weight:"bold"},"File Export settings"),e.createElement(fn,null,e.createElement(Be,{label:"Compress JSON output file",type:"switch",checked:n.compression,onChange:e=>t((n=>{n.compression=e}))}),e.createElement(gn,{width:240,label:"Compression removes line breaks and whitespace from the json string"}),"standard"===n.tokenFormat&&e.createElement(e.Fragment,null,e.createElement(Be,{label:"Exclude extension property",type:"switch",checked:n.excludeExtensionProp,onChange:e=>t((n=>{n.excludeExtensionProp=e}))}),e.createElement(gn,{width:240,label:"The extension property holds additional information about the token"}))),e.createElement(Je,{size:"large",weight:"bold"},"Include types in export"),e.createElement("div",{className:"grid-3-col"},Object.entries(sr).map((([,{key:r,label:a,exclude:l}])=>(void 0===l||!l.includes(n.tokenFormat))&&e.createElement(Be,{key:r,label:a,checked:n.exports[r],onChange:e=>t((n=>{n.exports[r]=e}))})))),e.createElement(cn,null,e.createElement(bn,{align:"start",href:"https://github.com/lukasoppermann/design-tokens#design-tokens"},"Documentation"),e.createElement(on,null),e.createElement(He,{type:"submit",autofocus:!0},"Save & Export")),e.createElement("a",{ref:o,download:`${n.filename}${n.extension}`,title:`${n.filename}${n.extension}`}))},mr=e=>401===e.status?"🚨 401: Check your access token":404===e.status?"🚨 404: Check your server url, auth type and the access token":e.status>399?`🚨 ${e.status}: An error occurred, please check the console for details.`:"🎉 Design tokens pushed to server!",vr=e=>{e.onerror=e=>{parent.postMessage({pluginMessage:{command:tn.closePlugin,payload:{notification:"🚨 An error occurred while sending the tokens: check your settings & your server."}}},"*")},e.onload=e=>{parent.postMessage({pluginMessage:{command:tn.closePlugin,payload:{notification:mr(e.target)}}},"*")}};const br=je`
`,hr=()=>{const{settings:n,updateSettings:t}=(0,e.useContext)(an),{tokens:r,setTokens:a}=(0,e.useContext)(ln),{figmaUIApi:l}=(0,e.useContext)(rn),o=(0,e.useRef)();return e.createElement("form",{onSubmit:e=>{if(e.preventDefault(),!0===e.target.checkValidity()){const{accessToken:e}=n,t=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++)n.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(t[r[a]]=e[r[a]])}return t}(n,["accessToken"]);if(l.postMessage({pluginMessage:{command:tn.saveSettings,payload:{settings:t,accessToken:e}}},"*"),!r||"[]"===r)return void l.postMessage({pluginMessage:{command:tn.closePlugin,payload:{notification:"No tokens to export!"}}},"*");const i=fr(r,t);a(i),((e,n,t)=>{if("[]"!==t)try{n.href=`data:application/design-tokens+json;charset=utf-8,${encodeURIComponent(t)}`,n.click(),e.postMessage({pluginMessage:{command:tn.closePlugin,payload:{notification:"🎉 Design token export successful!"}}},"*")}catch(n){e.postMessage({pluginMessage:{payload:{notification:"⛔️ Design token failed!"}}},"*"),console.error("Export error: ",n)}else e.postMessage({pluginMessage:{payload:{notification:"⛔️ No design token detected!"}}},"*")})(parent,o.current,pr(i,t.compression))}},className:gr},e.createElement(Je,{size:"xlarge",weight:"bold"},"File Export settings"),e.createElement(fn,null,e.createElement(Be,{label:"Compress JSON output file",type:"switch",checked:n.compression,onChange:e=>t((n=>{n.compression=e}))}),e.createElement(gn,{width:240,label:"Compression removes line breaks and whitespace from the json string"}),"standard"===n.tokenFormat&&e.createElement(e.Fragment,null,e.createElement(Be,{label:"Exclude extension property",type:"switch",checked:n.excludeExtensionProp,onChange:e=>t((n=>{n.excludeExtensionProp=e}))}),e.createElement(gn,{width:240,label:"The extension property holds additional information about the token"}))),e.createElement(Je,{size:"large",weight:"bold"},"Include types in export"),e.createElement("div",{className:"grid-3-col"},Object.entries(sr).map((([,{key:r,label:a,exclude:l}])=>(void 0===l||!l.includes(n.tokenFormat))&&e.createElement(Be,{key:r,label:a,checked:n.exports[r],onChange:e=>t((n=>{n.exports[r]=e}))})))),e.createElement(cn,null,e.createElement(bn,{align:"start",href:"https://github.com/lukasoppermann/design-tokens#design-tokens"},"Documentation"),e.createElement(on,null),e.createElement(He,{type:"submit",autofocus:!0},"Save & Export")),e.createElement("a",{ref:o,download:`${n.filename}${n.extension}`,title:`${n.filename}${n.extension}`}))},mr=e=>401===e.status?"🚨 401: Check your access token":404===e.status?"🚨 404: Check your server url, auth type and the access token":e.status>399?`🚨 ${e.status}: An error occurred, please check the console for details.`:"🎉 Design tokens pushed to server!",vr=e=>{e.onerror=e=>{parent.postMessage({pluginMessage:{command:tn.closePlugin,payload:{notification:"🚨 An error occurred while sending the tokens: check your settings & your server."}}},"*")},e.onload=e=>{parent.postMessage({pluginMessage:{command:tn.closePlugin,payload:{notification:mr(e.target)}}},"*")}};const br=je`
display: flex;
flex-direction: column;
h1:first-child {
Expand Down
2 changes: 1 addition & 1 deletion dist/ui.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/ui/components/FileExportSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const FileExportSettings = () => {
"*"
);
// prepare token json
if (!tokens || !tokens.length || typeof tokens === "string") {
if (!tokens || tokens === "[]") {
figmaUIApi.postMessage(
{
pluginMessage: {
Expand Down

0 comments on commit 4d5bf33

Please sign in to comment.