@grapesjs/studio-sdk-plugins 1.0.26 → 1.0.27
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/dist/iconifyComponent/index.cjs.js +2 -2
- package/dist/iconifyComponent/index.es.js +185 -179
- package/dist/iconifyComponent/index.umd.js +2 -2
- package/dist/iconifyComponent/utils.d.ts +4 -0
- package/dist/index.cjs.js +43 -43
- package/dist/index.es.js +1584 -1578
- package/dist/index.umd.js +44 -44
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(h,y){typeof exports=="object"&&typeof module<"u"?module.exports=y():typeof define=="function"&&define.amd?define(y):(h=typeof globalThis<"u"?globalThis:h||self,h.StudioSdkPlugins_iconifyComponent=y())})(this,function(){"use strict";const h="app.grapesjs.com",y="app-stage.grapesjs.com",
|
|
1
|
+
(function(h,y){typeof exports=="object"&&typeof module<"u"?module.exports=y():typeof define=="function"&&define.amd?define(y):(h=typeof globalThis<"u"?globalThis:h||self,h.StudioSdkPlugins_iconifyComponent=y())})(this,function(){"use strict";const h="app.grapesjs.com",y="app-stage.grapesjs.com",O=[h,y,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],B="license:check:start",H="license:check:end",C=()=>typeof window<"u",F=({isDev:e,isStage:t})=>`${e?"":`https://${t?y:h}`}/api`,W=()=>{const e=C()&&window.location.hostname;return!!e&&(O.includes(e)||O.some(t=>e.endsWith(t)))};async function S({path:e,baseApiUrl:t,method:o="GET",headers:s={},params:u,body:g}){const r=`${t||F({isDev:!1,isStage:!1})}${e}`,n={method:o,headers:{"Content-Type":"application/json",...s}};g&&(n.body=JSON.stringify(g));const c=u?new URLSearchParams(u).toString():"",i=c?`?${c}`:"",p=await fetch(`${r}${i}`,n);if(!p.ok)throw new Error(`HTTP error! status: ${p.status}`);return p.json()}var b=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(b||{}),_=(e=>(e.Info="info",e.Error="error",e.Success="success",e.Warning="warning",e))(_||{}),v=(e=>(e.toastAdd="studio:toastAdd",e.toastRemove="studio:toastRemove",e.dialogOpen="studio:dialogOpen",e.dialogClose="studio:dialogClose",e.sidebarLeftSet="studio:sidebarLeft:set",e.sidebarLeftGet="studio:sidebarLeft:get",e.sidebarLeftToggle="studio:sidebarLeft:toggle",e.sidebarRightSet="studio:sidebarRight:set",e.sidebarRightGet="studio:sidebarRight:get",e.sidebarRightToggle="studio:sidebarRight:toggle",e.sidebarTopSet="studio:sidebarTop:set",e.sidebarTopGet="studio:sidebarTop:get",e.sidebarTopToggle="studio:sidebarTop:toggle",e.sidebarBottomSet="studio:sidebarBottom:set",e.sidebarBottomGet="studio:sidebarBottom:get",e.sidebarBottomToggle="studio:sidebarBottom:toggle",e.symbolAdd="studio:symbolAdd",e.symbolDetach="studio:symbolDetach",e.symbolOverride="studio:symbolOverride",e.symbolPropagateStyles="studio:propagateStyles",e.getPagesConfig="studio:getPagesConfig",e.setPagesConfig="studio:setPagesConfig",e.getPageSettings="studio:getPageSettings",e.setPageSettings="studio:setPageSettings",e.projectFiles="studio:projectFiles",e.canvasReload="studio:canvasReload",e.getBlocksPanel="studio:getBlocksPanel",e.setBlocksPanel="studio:setBlocksPanel",e.getStateContextMenu="studio:getStateContextMenu",e.setStateContextMenu="studio:setStateContextMenu",e.contextMenuComponent="studio:contextMenuComponent",e.layoutAdd="studio:layoutAdd",e.layoutRemove="studio:layoutRemove",e.layoutToggle="studio:layoutToggle",e.layoutUpdate="studio:layoutUpdate",e.layoutGet="studio:layoutGet",e.layoutConfigGet="studio:layoutConfigGet",e.layoutConfigSet="studio:layoutConfigSet",e.getStateTheme="studio:getStateTheme",e.setStateTheme="studio:setStateTheme",e.assetProviderGet="studio:assetProviderGet",e.assetProviderAdd="studio:assetProviderAdd",e.assetProviderRemove="studio:assetProviderRemove",e.fontGet="studio:fontGet",e.fontAdd="studio:fontAdd",e.fontRemove="studio:fontRemove",e.fontManagerOpen="studio:fontManagerOpen",e.menuFontLoad="studio:menuFontLoad",e.toggleStateDataSource="studio:toggleStateDataSource",e.getStateDataSource="studio:getStateDataSource",e.dataSourceSetGlobalData="studio:dataSourceSetGlobalData",e.dataSourceSetImporter="studio:dataSourceSetImporter",e.dataSourceSetExporter="studio:dataSourceSetExporter",e.setDragAbsolute="studio:setDragAbsolute",e))(v||{});const R={[b.free]:0,[b.startup]:10,[b.business]:20,[b.enterprise]:30};function K(e){const t=e;return t.init=o=>s=>e(s,o),t}const m=e=>K(e);async function V({editor:e,plan:t,pluginName:o,licenseKey:s,cleanup:u}){let g="",a=!1;const r=W(),n=i=>{console.warn("Cleanup plugin:",o,"Reason:",i),u()},c=(i={})=>{var T;const{error:p,sdkLicense:L}=i,l=(T=i.plan)==null?void 0:T.category;if(!(L||i.license)||p)n(p||"Invalid license");else if(l){const w=R[t],d=R[l];w>d&&n({pluginRequiredPlan:t,licensePlan:l})}};e.on(B,i=>{g=i==null?void 0:i.baseApiUrl,a=!0}),e.on(H,i=>{c(i)}),setTimeout(async()=>{if(!a){if(r)return;if(s){const i=await Y({licenseKey:s,pluginName:o,baseApiUrl:g});i&&c(i)}else n("The `licenseKey` option not provided")}},2e3)}async function Y(e){const{licenseKey:t,pluginName:o,baseApiUrl:s}=e;try{return(await S({baseApiUrl:s,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:o}})).result||{}}catch(u){return console.error("Error during SDK license check:",u),!1}}const z=(e,t)=>{var o;return!!((o=e==null?void 0:e.hasAttribute)!=null&&o.call(e,t))},q="iconifyComponent",J=b.startup,X={ratioDefault:!0,tc:!1,cl:!1,cr:!1,bc:!1},P=`<svg viewBox="0 0 24 24">
|
|
2
2
|
<path d="M19 0H9C7.9 0 7 .9 7 2V18C7 19.1 7.9 20 9 20H19C20.1 20 21 19.1 21 18V2C21 .9 20.1 0 19 0M19 18H9V2H19V18M3 4V22C3 23.1 3.9 24 5 24H17V22H5V4H3M14 5L11 10L14 15L17 10L14 5Z" />
|
|
3
|
-
</svg>`,
|
|
3
|
+
</svg>`,D="layout-icon-picker",Z="icons-layout-",$="icons-list-layout",U="gs-iconify-picker",A="__iconify_collection",Q="https://api.iconify.design",k=new Map;let E;const ee=({collectionId:e})=>`https://cdn.jsdelivr.net/npm/@iconify-json/${e}@latest/icons.json`;async function M({collectionId:e,editor:t}){try{if(k.has(e))return k.get(e);const o=await fetch(ee({collectionId:e}));if(!o.ok)throw new Error(`Failed to fetch collection: ${o.statusText}`);const s=await o.json();return k.set(e,s),s}catch(o){console.error("Error fetching collection",o),t.runCommand(v.toastAdd,ce());return}}async function te({collectionIds:e,editor:t}){try{if(E)return E;const o=e?`?prefixes=${e.join(",")}`:"",s=await fetch(`${Q}/collections${o}`);if(!s.ok)throw new Error(`Failed to fetch collections: ${s.statusText}`);return E=await s.json(),E}catch(o){console.error("Error fetching collections",o),t.runCommand(v.toastAdd,j());return}}function N(){return{type:"button",label:"Open Icon Picker",name:"onActive",changeProp:!0,command(e){var t;(t=e.getSelected())==null||t.trigger("active")}}}async function oe({collectionIds:e,editor:t,component:o}){const s=await te({collectionIds:e,editor:t});if(!s)return;const u=({icon:n,collectionId:c,iconId:i})=>{o.components(n),o.set({collectionId:c,iconId:i})},g=Object.entries(s).map(([n,c])=>({id:n,...c})).sort((n,c)=>n.name.localeCompare(c.name)),a=o.get("collectionId")??g[0].id;t.runCommand(v.layoutToggle,{id:D,placer:{type:"dialog",size:"l",title:"Select Icon"},header:!1,layout:{type:"column",style:{height:500,gap:10},children:[se({collectionsList:g,collectionId:a,editor:t,handleClick:u}),{id:$,type:"column",grow:!0}]}});const r=await M({collectionId:a,editor:t});r&&(G({editor:t,collection:r}),x({editor:t,collection:r,handleClick:u,collectionId:a}))}function G({editor:e,collection:t}){e.em.set(A,t)}function ne(e){return e.em.get(A)}function x(e){const{editor:t}=e;t.runCommand(v.layoutUpdate,{id:Z,layout:ie(e),header:!1,style:{height:"100%"},placer:{type:"static",layoutId:$}})}function se(e){const{collectionsList:t,collectionId:o,editor:s,handleClick:u}=e,g=t.map(({id:a,name:r,total:n})=>({id:a,label:`${r} (${n})`})).sort((a,r)=>a.label.localeCompare(r.label));return{type:"column",style:{gap:10},className:`${U}__header`,children:[{type:"selectField",value:o,options:g,emptyState:"Select an icon collection",onChange:async({setState:a,value:r})=>{const n=await M({collectionId:r,editor:s});n&&(a({value:r}),G({editor:s,collection:n}),x({editor:s,collection:n,handleClick:u,collectionId:r}))}},{type:"inputField",value:"",placeholder:"Search icons inside collection...",editorEvents:{[`change:${A}`]:({setState:a})=>a({value:""})},onInput:({setState:a,value:r,editor:n})=>{const c=ne(n);if(!c)return;const i=Object.fromEntries(Object.entries(c.icons).filter(([p])=>p.includes(r)));a({value:r}),x({editor:n,collection:c,handleClick:u,collectionId:o,collectionFiltered:{...c,icons:i}})}}]}}function ie({collection:e,collectionFiltered:t,handleClick:o}){const{height:s=24,width:u=24,icons:g,prefix:a}=t||e,r=Object.entries(g).map(([n,c])=>({name:n,...c}),{});return{type:"column",className:`${U}__content`,style:{height:"100%"},children:{type:"virtualList",items:r,itemLayout:({item:n})=>({type:"custom",render:c=>{const{editor:i,addEl:p,removeEl:L}=c,l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttribute("xmlns","http://www.w3.org/2000/svg"),l.innerHTML=n.body;const f=n.width||u,T=n.height||s;l.setAttribute("viewBox",`0 0 ${f} ${T}`),l.style.cssText="width: 48px; height: 48px; cursor: pointer; border-radius: 4px; transition: padding 0.1s ease-in-out;";const w=[["click",()=>{const d=l.cloneNode(!0);d.removeAttribute("style");const I=d.outerHTML;o({icon:I,collectionId:a,iconId:n.name}),i==null||i.runCommand(v.layoutRemove,{id:D})}],["pointerover",()=>{l.style.border="2px solid currentColor",l.style.padding="4px"}],["pointerout",()=>{l.style.border="",l.style.padding=""}]];return w.forEach(([d,I])=>l.addEventListener(d,I)),p(l),()=>{w.forEach(([d,I])=>l.removeEventListener(d,I)),L(l)}}})}}}function j(){return{id:"toast-error-getCollections",header:"Error",content:"Error fetching collections",variant:_.Error}}function ce(){return{...j(),id:"toast-error-getCollection",content:"Error fetching collection"}}return m(function(e,t={}){var l;const{Components:o,Blocks:s}=e,{collections:u,extendIconComponent:g=!0,licenseKey:a,block:r={}}=t,n="icon",c="iconify",i="Iconify",p="data-type-iconify",L={events:()=>({dblclick:"onActive"}),onActive(){oe({collectionIds:u,editor:e,component:this.model})}};if(o.addType(c,{block:r&&{label:i,media:P,content:{type:c},category:"Extra",activate:!0,...r},isComponent:f=>z(f,p),model:{defaults:{name:i,icon:P,droppable:!1,attributes:{[p]:!0},resizable:X,components:P,style:{width:"50px",height:"50px"},traits:[N()]},init(){this.listenTo(this.components(),"change add",this.disableLayers),this.disableLayers()},disableLayers(){this.components().forEach(f=>f.set({layerable:!1,locked:!0}))}},view:L}),g){const f=(l=o.getType(n))==null?void 0:l.model,[T,w,...d]=f.getDefaults().traits;o.addType(n,{model:{defaults:{traits:[T,w,N(),...d]}},view:L})}V({editor:e,licenseKey:a,plan:J,pluginName:q,cleanup:()=>{s.remove(c),o.removeType(c)}})})});
|
|
@@ -16,3 +16,7 @@ export declare function getIconPickerButtonTrait(): {
|
|
|
16
16
|
command(editor: Editor): void;
|
|
17
17
|
};
|
|
18
18
|
export declare function openIconPicker({ collectionIds, editor, component }: OpenIconPickerProps): Promise<void>;
|
|
19
|
+
export declare function getAspectRatio(width: number, height: number): {
|
|
20
|
+
cssWidth: number;
|
|
21
|
+
cssHeight: number;
|
|
22
|
+
};
|