@grapesjs/studio-sdk-plugins 1.0.16 → 1.0.17
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/canvasFullSize/index.cjs.js +6 -2
- package/dist/canvasFullSize/index.es.js +66 -61
- package/dist/canvasFullSize/index.umd.js +7 -3
- package/dist/canvasFullSize/typesSchema.d.ts +7 -0
- package/dist/index.cjs.js +37 -33
- package/dist/index.es.js +2537 -2528
- package/dist/index.umd.js +36 -32
- package/dist/layoutSidebarButtons/index.cjs.js +1 -1
- package/dist/layoutSidebarButtons/index.es.js +176 -172
- package/dist/layoutSidebarButtons/index.umd.js +1 -1
- package/dist/layoutSidebarButtons/types.d.ts +13 -7
- package/dist/layoutSidebarButtons/typesSchema.d.ts +8 -8
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(h,v){typeof exports=="object"&&typeof module<"u"?module.exports=v():typeof define=="function"&&define.amd?define(v):(h=typeof globalThis<"u"?globalThis:h||self,h.StudioSdkPlugins_layoutSidebarButtons=v())})(this,function(){"use strict";var h=(e=>(e.free="free",e.startup="startup",e.business="business",e.enterprise="enterprise",e))(h||{}),v=(e=>(e.toastAdd="studio:toastAdd",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))(v||{}),A=(e=>(e.layoutToggleId="studio:layoutToggle:",e.toggleBlocksPanel="studio:toggleBlocksPanel",e.pageSettingsUpdate="studio:pageSettingsUpdate",e))(A||{});const k="app.grapesjs.com",w="app-stage.grapesjs.com",R=[k,w,"localhost","127.0.0.1",".local-credentialless.webcontainer.io",".local.webcontainer.io","-sandpack.codesandbox.io"],D="license:check:start",H="license:check:end",O=()=>typeof window<"u",_=({isDev:e,isStage:t})=>`${e?"":`https://${t?w:k}`}/api`,N=()=>{const e=O()&&window.location.hostname;return!!e&&(R.includes(e)||R.some(t=>e.endsWith(t)))};async function W({path:e,baseApiUrl:t,method:a="GET",headers:l={},params:c,body:b}){const y=`${t||_({isDev:!1,isStage:!1})}${e}`,r={method:a,headers:{"Content-Type":"application/json",...l}};b&&(r.body=JSON.stringify(b));const n=c?new URLSearchParams(c).toString():"",s=n?`?${n}`:"",g=await fetch(`${y}${s}`,r);if(!g.ok)throw new Error(`HTTP error! status: ${g.status}`);return g.json()}const M={[h.free]:0,[h.startup]:10,[h.business]:20,[h.enterprise]:30};function j(e){const t=e;return t.init=a=>l=>e(l,a),t}const S=e=>j(e);async function m({editor:e,plan:t,pluginName:a,licenseKey:l,cleanup:c}){let b="",f=!1;const y=N(),r=s=>{console.warn("Cleanup plugin:",a,"Reason:",s),c()},n=(s={})=>{var i;const{error:g,sdkLicense:L}=s,o=(i=s.plan)==null?void 0:i.category;if(!(L||s.license)||g)r(g||"Invalid license");else if(o){const p=M[t],d=M[o];p>d&&r({pluginRequiredPlan:t,licensePlan:o})}};e.on(D,s=>{b=s==null?void 0:s.baseApiUrl,f=!0}),e.on(H,s=>{n(s)}),setTimeout(async()=>{if(!f){if(y)return;if(l){const s=await C({licenseKey:l,pluginName:a,baseApiUrl:b});s&&n(s)}else r("The `licenseKey` option not provided")}},2e3)}async function C(e){const{licenseKey:t,pluginName:a,baseApiUrl:l}=e;try{return(await W({baseApiUrl:l,path:`/sdk/${t||"na"}`,method:"POST",params:{d:window.location.hostname,pn:a}})).result||{}}catch(c){return console.error("Error during SDK license check:",c),!1}}var T=(e=>(e.panelBlocks="panelBlocks",e.panelPagesLayers="panelPagesLayers",e.panelGlobalStyles="panelGlobalStyles",e.panelSidebarTabs="panelSidebarTabs",e.panelAssets="panelAssets",e))(T||{});const G="sidebarButtonsTarget",P=e=>{const{id:t,icon:a,label:l,tooltip:c,className:b,skipSelfClose:f,removeLayouts:y,layoutComponent:r,layoutCommand:n}=e,s=t;return{id:I(t),type:"button",icon:a,tooltip:l||c,className:b,editorEvents:{[`${A.layoutToggleId}${s}`]:({fromEvent:g,setState:L,editor:o})=>{L({active:g.isOpen}),setTimeout(()=>o.refresh({tools:!0}),20)}},onClick:({editor:g,state:L})=>{if(L.active&&f)return;const o=(n==null?void 0:n.placer)||{type:"static",layoutId:G},u={...o,skipCleanup:o.type==="static"},i=y||Object.keys(T).filter(d=>d!==s);x(g,{removeLayouts:i,layout:{placer:u}});const p={id:s,placer:o,header:(n==null?void 0:n.header)??{label:l,close:!f},layout:r,style:{width:280,height:"100%",borderRightWidth:1,...n==null?void 0:n.style}};g.runCommand(v.layoutToggle,p)}}},I=e=>`button__${e}`,x=(e,t={})=>{(t.removeLayouts||Object.keys(T)).forEach(l=>e.runCommand(v.layoutRemove,{id:l,layout:t.layout}))},U=e=>{const t=(e==null?void 0:e.breakpointTablet)??1024,a=(e==null?void 0:e.breakpointMobile)??768,l={breakpointTablet:t,breakpointMobile:a},c={},b=[{id:T.panelBlocks,icon:"plusBox",label:"Blocks",layoutComponent:{type:"panelBlocks"}},{id:T.panelPagesLayers,icon:"layers",label:"Pages & Layers",layoutComponent:{type:"panelPagesLayers"}},{id:T.panelGlobalStyles,icon:'<svg viewBox="0 0 24 24"> <path d="M20 14H6c-2.2 0-4 1.8-4 4s1.8 4 4 4h14a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2M6 20c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2m.3-8L13 5.3a2 2 0 0 1 2.8 0l2.8 2.8c.8.8.8 2 0 2.8l-.9 1.1H6.3M2 13.5V4c0-1.1.9-2 2-2h4a2 2 0 0 1 2 2v1.5l-8 8Z"/></svg>',label:"Global Styles",layoutComponent:{type:"panelGlobalStyles"}},{id:T.panelAssets,icon:'<svg viewBox="0 0 24 24"><path d="M22,16V4A2,2 0 0,0 20,2H8A2,2 0 0,0 6,4V16A2,2 0 0,0 8,18H20A2,2 0 0,0 22,16M11,12L13.03,14.71L16,11L20,16H8M2,6V20A2,2 0 0,0 4,22H18V20H4V6" /></svg>',label:"Assets",layoutComponent:{type:"panelAssets",content:{itemsPerRow:2,header:{addUrl:!1}},style:{padding:7},onSelect:({assetProps:o,editor:u})=>{var d;const i=u.getSelected(),p={type:"image",src:o.src};if(i!=null&&i.is("image"))return i.set("src",o.src);if(i&&u.Components.canMove(i,p)){const B=i.append(p)[0];B&&u.select(B)}else if(!i){const B=(d=u.getWrapper())==null?void 0:d.append(p)[0];B&&u.select(B)}}}}],f=[...b,{id:T.panelSidebarTabs,layoutCommand:{header:!1},icon:'<svg viewBox="0 0 24 24"><path d="M17.5 12a1.5 1.5 0 0 1-1.5-1.5A1.5 1.5 0 0 1 17.5 9a1.5 1.5 0 0 1 1.5 1.5 1.5 1.5 0 0 1-1.5 1.5m-3-4A1.5 1.5 0 0 1 13 6.5 1.5 1.5 0 0 1 14.5 5 1.5 1.5 0 0 1 16 6.5 1.5 1.5 0 0 1 14.5 8m-5 0A1.5 1.5 0 0 1 8 6.5 1.5 1.5 0 0 1 9.5 5 1.5 1.5 0 0 1 11 6.5 1.5 1.5 0 0 1 9.5 8m-3 4A1.5 1.5 0 0 1 5 10.5 1.5 1.5 0 0 1 6.5 9 1.5 1.5 0 0 1 8 10.5 1.5 1.5 0 0 1 6.5 12M12 3a9 9 0 0 0-9 9 9 9 0 0 0 9 9 1.5 1.5 0 0 0 1.5-1.5c0-.4-.2-.7-.4-1-.2-.3-.4-.6-.4-1a1.5 1.5 0 0 1 1.5-1.5H16a5 5 0 0 0 5-5c0-4.4-4-8-9-8Z"/></svg>',label:"Styles & Props",layoutComponent:{type:"panelSidebarTabs"}}],y={id:G,type:"column",style:{overflow:"hidden"}},r={type:"sidebarLeft",resizable:!1,style:{padding:"10px 5px",alignItems:"center",width:45,gap:10},children:[]},n={type:"canvasSidebarTop",sidebarTop:{leftContainer:{buttons:[]}}},s=(o,u)=>{const i=o.map(d=>{const B=P(d);return e!=null&&e.sidebarButton?e.sidebarButton({id:d.id,buttonIds:T,breakpoint:u,buttonProps:B,sidebarButtonProps:d,...l,createSidebarButton:K=>P({...d,...K})}):B}).filter(Boolean);return(e!=null&&e.sidebarButtons?e==null?void 0:e.sidebarButtons({buttonIds:T,breakpoint:u,sidebarButtons:i,...l,createSidebarButton:d=>P({...d})}):i).filter(Boolean)},g=(o,u,i)=>{var p;return((p=e==null?void 0:e.rootLayout)==null?void 0:p.call(e,{breakpoint:i,sidebarButtons:u,rootLayout:o,layoutSidebarLeft:r,layoutSidebarTarget:y,...l,createSidebarButton:d=>P({...d})}))??o};if(t){const o=s(f,t);c[t]=g({type:"row",style:{height:"100%"},children:[{...r,children:o},y,n]},o,t)}if(a){const o=f.map(i=>({...i,layoutCommand:{placer:{type:"absolute",position:"left"},style:{height:"calc(100% - 40px)"}}})),u=s(o,a);c[a]=g({type:"column",style:{height:"100%"},children:[{type:"sidebarTop",leftContainer:{buttons:[]}},{type:"canvas"},{type:"sidebarBottom",style:{padding:"0 5px",alignItems:"center",gap:10,minHeight:39},children:u}]},u,a)}const L=s(b,0);return{default:g({type:"row",style:{height:"100%"},children:[{...r,children:L},y,n,{type:"sidebarRight"}]},L,0),responsive:c}},E="layoutSidebarButtons",$=S(function(e,t={}){const{Commands:a}=e,l=a.events,c={...t};(()=>{if(e.runCommand(v.layoutConfigGet)||c.skipLayoutConfig===!0)return;const y=U(c);e.runCommand(v.layoutConfigSet,{...y})})(),a.add(`${E}:toggleButton`,(f,y,r)=>{const n=document.getElementById(I(r==null?void 0:r.id));n==null||n.click()}),e.on(`${l.runCommand}core:preview`,()=>{x(e)}),m({editor:e,licenseKey:c.licenseKey,plan:h.free,pluginName:E,cleanup:()=>{e.runCommand(v.layoutConfigSet)}})});return $.createLayoutConfig=e=>U(e),$});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutCommandProps, LayoutConfig, RootLayoutConfig, StudioLayoutButtonConfigProps, StudioLayoutComponentsConfigProps } from '../types';
|
|
1
|
+
import { LayoutCommandProps, LayoutConfig, RootLayoutConfig, StudioLayoutButtonConfigProps, StudioLayoutComponentsConfigProps, StudioLayoutSidebarLeftConfigProps } from '../types';
|
|
2
2
|
import { PluginWithInit } from '../utils';
|
|
3
3
|
import { LayoutSidebarButtonsOptions as LayoutSidebarButtonsOptionsSchema } from './typesSchema';
|
|
4
4
|
export interface LayoutSidebarButtonsOptions extends Omit<LayoutSidebarButtonsOptionsSchema, 'sidebarButton' | 'rootLayout' | 'sidebarButtons'> {
|
|
@@ -32,33 +32,39 @@ export interface LayoutSidebarButtonsOptions extends Omit<LayoutSidebarButtonsOp
|
|
|
32
32
|
*/
|
|
33
33
|
skipLayoutConfig?: boolean;
|
|
34
34
|
}
|
|
35
|
+
export interface BreakpointProps extends Required<Pick<LayoutSidebarButtonsOptionsSchema, 'breakpointTablet' | 'breakpointMobile'>> {
|
|
36
|
+
}
|
|
35
37
|
export type SidebarButtonResult = StudioLayoutComponentsConfigProps | undefined | null | false;
|
|
36
38
|
export type CreateSidebarButtonFn = (props: SidebarButtonProps) => StudioLayoutButtonConfigProps;
|
|
37
39
|
export type SidebarButtonFn = (props: {
|
|
38
40
|
id: string;
|
|
41
|
+
buttonIds: typeof SidebarButtonIds;
|
|
39
42
|
breakpoint: number;
|
|
40
43
|
sidebarButtonProps: SidebarButtonProps;
|
|
41
44
|
buttonProps: StudioLayoutButtonConfigProps;
|
|
42
45
|
createSidebarButton: (props: Partial<SidebarButtonProps>) => StudioLayoutButtonConfigProps;
|
|
43
|
-
}) => SidebarButtonResult;
|
|
46
|
+
} & BreakpointProps) => SidebarButtonResult;
|
|
44
47
|
export type SidebarButtonsFn = (props: {
|
|
48
|
+
buttonIds: typeof SidebarButtonIds;
|
|
45
49
|
breakpoint: number;
|
|
46
|
-
sidebarButtons:
|
|
50
|
+
sidebarButtons: StudioLayoutComponentsConfigProps[];
|
|
47
51
|
createSidebarButton: CreateSidebarButtonFn;
|
|
48
|
-
}) => SidebarButtonResult[];
|
|
52
|
+
} & BreakpointProps) => SidebarButtonResult[];
|
|
49
53
|
export type CustomRootLayoutFn = (props: {
|
|
50
54
|
breakpoint: number;
|
|
51
|
-
sidebarButtons:
|
|
55
|
+
sidebarButtons: StudioLayoutComponentsConfigProps[];
|
|
52
56
|
rootLayout: RootLayoutConfig;
|
|
57
|
+
layoutSidebarTarget: RootLayoutConfig;
|
|
58
|
+
layoutSidebarLeft: StudioLayoutSidebarLeftConfigProps;
|
|
53
59
|
createSidebarButton: CreateSidebarButtonFn;
|
|
54
|
-
}) => RootLayoutConfig;
|
|
60
|
+
} & BreakpointProps) => RootLayoutConfig;
|
|
55
61
|
export interface SidebarButtonProps {
|
|
56
62
|
id: string;
|
|
57
63
|
icon: string;
|
|
58
64
|
label?: string;
|
|
59
65
|
className?: string;
|
|
60
66
|
layoutComponent: StudioLayoutComponentsConfigProps;
|
|
61
|
-
layoutCommand?: Partial<LayoutCommandProps
|
|
67
|
+
layoutCommand?: Partial<Pick<LayoutCommandProps, 'style' | 'placer' | 'header'>>;
|
|
62
68
|
tooltip?: string;
|
|
63
69
|
skipSelfClose?: boolean;
|
|
64
70
|
removeLayouts?: string[];
|
|
@@ -2,26 +2,26 @@ import { SDKPluginOptions } from '../utils';
|
|
|
2
2
|
export interface LayoutSidebarButtonsOptions extends SDKPluginOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Extend each sidebar button per breakpoint.
|
|
5
|
-
* @
|
|
5
|
+
* @examples
|
|
6
6
|
* sidebarButton: ({ id, buttonProps, breakpoint, createSidebarButton }) => ({
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* ...buttonProps,
|
|
8
|
+
* // custom icon for panelBlocks button
|
|
9
|
+
* icon: buttonProps.id === 'panelBlocks' ? '<svg ...>' : buttonProps.icon,
|
|
10
10
|
* })
|
|
11
11
|
*/
|
|
12
12
|
sidebarButton?: '__fn__';
|
|
13
13
|
/**
|
|
14
14
|
* Add or filter the resultant buttons per breakpoint.
|
|
15
|
-
* @
|
|
15
|
+
* @examples
|
|
16
16
|
* sidebarButtons: ({ breakpoint, sidebarButtons, createSidebarButton }) => {
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* // Add a new button for the default layout
|
|
18
|
+
* return !breakpoint ? [...sidebarButtons, createSidebarButton({...})] sidebarButtons;
|
|
19
19
|
* }
|
|
20
20
|
*/
|
|
21
21
|
sidebarButtons?: '__fn__';
|
|
22
22
|
/**
|
|
23
23
|
* Customize the resultant root layout per breakpoint.
|
|
24
|
-
* @
|
|
24
|
+
* @examples
|
|
25
25
|
* rootLayout({ breakpoint, rootLayout, sidebarButtons, createSidebarButton }) {
|
|
26
26
|
* if (breakpoint === 768) {
|
|
27
27
|
* return {
|
package/dist/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { StudioCommands, StudioEvents } from '@studio/editor/src/plugins/global/
|
|
|
6
6
|
export type { AssetProvider, InputAssetProps } from '@studio/editor/src/typeConfigs/assets';
|
|
7
7
|
export type { Font, FontAssetProps, FontFaceArgs } from '@studio/editor/src/typeConfigs/fonts';
|
|
8
8
|
export type { LayoutCommandProps, LayoutConfig, RootLayoutConfig } from '@studio/editor/src/typeConfigs/layout';
|
|
9
|
-
export type { StudioLayoutButtonConfigProps, StudioLayoutCanvasSidebarTopConfigProps } from '@studio/editor/src/typeConfigs/layoutComponents';
|
|
9
|
+
export type { StudioLayoutButtonConfigProps, StudioLayoutSidebarLeftConfigProps, StudioLayoutCanvasSidebarTopConfigProps } from '@studio/editor/src/typeConfigs/layoutComponents';
|
|
10
10
|
export { ThemeValue } from '@studio/editor/src/typeConfigs/shared';
|
|
11
11
|
export type { RteCustomToolbarProps } from '@studio/editor/src/typeConfigs/shared';
|
|
12
12
|
export { ProjectType } from '@studio/editor/src/utils/types';
|