@elementor/editor-panels 0.12.1 → 0.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c3a0125: Clean modified status on global classes save.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [e798985]
12
+ - Updated dependencies [4c2935b]
13
+ - Updated dependencies [0909b4b]
14
+ - @elementor/editor-v1-adapters@0.11.0
15
+ - @elementor/editor@0.18.3
16
+
17
+ ## 0.12.2
18
+
19
+ ### Patch Changes
20
+
21
+ - 959e02c: Disable canvas and app bar buttons when opening the class manager panel
22
+ - Updated dependencies [959e02c]
23
+ - @elementor/editor-v1-adapters@0.10.2
24
+ - @elementor/editor@0.18.2
25
+
3
26
  ## 0.12.1
4
27
 
5
28
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,26 +1,32 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentType } from 'react';
3
+ import { UseRouteStatusOptions } from '@elementor/editor-v1-adapters';
3
4
  import { DrawerProps, BoxProps, TypographyProps } from '@elementor/ui';
4
5
 
5
- type PanelDeclaration = {
6
+ type PanelDeclaration<TOnOpenReturn = unknown> = {
6
7
  id: string;
7
8
  component: ComponentType;
8
- };
9
- declare function createPanel({ id, component }: PanelDeclaration): {
9
+ } & UseActionsOptions<TOnOpenReturn> & UseRouteStatusOptions;
10
+ declare function createPanel<TOnOpenReturn>({ id, component, onOpen, onClose, allowedEditModes, blockOnKitRoutes, }: PanelDeclaration<TOnOpenReturn>): {
10
11
  panel: {
11
12
  id: string;
12
13
  component: ComponentType;
13
14
  };
14
- usePanelStatus: () => {
15
- isOpen: boolean;
16
- isBlocked: boolean;
17
- };
15
+ usePanelStatus: UseStatus;
18
16
  usePanelActions: () => {
19
17
  open: () => Promise<void>;
20
18
  close: () => Promise<void>;
21
19
  };
22
20
  };
23
21
  declare function registerPanel({ id, component }: Pick<PanelDeclaration, 'id' | 'component'>): void;
22
+ type UseStatus = () => {
23
+ isOpen: boolean;
24
+ isBlocked: boolean;
25
+ };
26
+ type UseActionsOptions<TOnOpenReturn> = {
27
+ onOpen?: () => TOnOpenReturn;
28
+ onClose?: (state: TOnOpenReturn) => void;
29
+ };
24
30
 
25
31
  declare function Panel({ children, sx, ...props }: DrawerProps): React.JSX.Element;
26
32
 
package/dist/index.d.ts CHANGED
@@ -1,26 +1,32 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentType } from 'react';
3
+ import { UseRouteStatusOptions } from '@elementor/editor-v1-adapters';
3
4
  import { DrawerProps, BoxProps, TypographyProps } from '@elementor/ui';
4
5
 
5
- type PanelDeclaration = {
6
+ type PanelDeclaration<TOnOpenReturn = unknown> = {
6
7
  id: string;
7
8
  component: ComponentType;
8
- };
9
- declare function createPanel({ id, component }: PanelDeclaration): {
9
+ } & UseActionsOptions<TOnOpenReturn> & UseRouteStatusOptions;
10
+ declare function createPanel<TOnOpenReturn>({ id, component, onOpen, onClose, allowedEditModes, blockOnKitRoutes, }: PanelDeclaration<TOnOpenReturn>): {
10
11
  panel: {
11
12
  id: string;
12
13
  component: ComponentType;
13
14
  };
14
- usePanelStatus: () => {
15
- isOpen: boolean;
16
- isBlocked: boolean;
17
- };
15
+ usePanelStatus: UseStatus;
18
16
  usePanelActions: () => {
19
17
  open: () => Promise<void>;
20
18
  close: () => Promise<void>;
21
19
  };
22
20
  };
23
21
  declare function registerPanel({ id, component }: Pick<PanelDeclaration, 'id' | 'component'>): void;
22
+ type UseStatus = () => {
23
+ isOpen: boolean;
24
+ isBlocked: boolean;
25
+ };
26
+ type UseActionsOptions<TOnOpenReturn> = {
27
+ onOpen?: () => TOnOpenReturn;
28
+ onClose?: (state: TOnOpenReturn) => void;
29
+ };
24
30
 
25
31
  declare function Panel({ children, sx, ...props }: DrawerProps): React.JSX.Element;
26
32
 
package/dist/index.js CHANGED
@@ -97,12 +97,6 @@ var V2_PANEL = "panel/v2";
97
97
  function getPortalContainer() {
98
98
  return document.querySelector("#elementor-panel-inner");
99
99
  }
100
- function useV1PanelStatus() {
101
- return (0, import_editor_v1_adapters.__privateUseRouteStatus)(V2_PANEL, {
102
- blockOnKitRoutes: true,
103
- blockOnPreviewMode: true
104
- });
105
- }
106
100
  function sync() {
107
101
  (0, import_editor_v1_adapters.__privateListenTo)((0, import_editor_v1_adapters.windowEvent)("elementor/panel/init"), () => (0, import_editor_v1_adapters.__privateRegisterRoute)(V2_PANEL));
108
102
  (0, import_editor_v1_adapters.__privateListenTo)((0, import_editor_v1_adapters.routeOpenEvent)(V2_PANEL), () => {
@@ -192,10 +186,24 @@ function init() {
192
186
  }
193
187
 
194
188
  // src/api.ts
189
+ var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
195
190
  var import_store8 = require("@elementor/store");
196
- function createPanel({ id, component }) {
197
- const usePanelStatus = createUseStatus(id);
198
- const usePanelActions = createUseActions(id, usePanelStatus);
191
+ function createPanel({
192
+ id,
193
+ component,
194
+ onOpen,
195
+ onClose,
196
+ allowedEditModes,
197
+ blockOnKitRoutes
198
+ }) {
199
+ const usePanelStatus = createUseStatus(id, {
200
+ allowedEditModes,
201
+ blockOnKitRoutes
202
+ });
203
+ const usePanelActions = createUseActions(id, usePanelStatus, {
204
+ onOpen,
205
+ onClose
206
+ });
199
207
  return {
200
208
  panel: {
201
209
  id,
@@ -211,17 +219,18 @@ function registerPanel({ id, component }) {
211
219
  component
212
220
  });
213
221
  }
214
- function createUseStatus(id) {
222
+ function createUseStatus(id, options = {}) {
215
223
  return () => {
216
224
  const openPanelId = (0, import_store8.__useSelector)(selectOpenId);
217
- const v1PanelStatus = useV1PanelStatus();
225
+ const v1PanelStatus = (0, import_editor_v1_adapters2.__privateUseRouteStatus)(V2_PANEL, options);
218
226
  return {
219
227
  isOpen: openPanelId === id && v1PanelStatus.isActive,
220
228
  isBlocked: v1PanelStatus.isBlocked
221
229
  };
222
230
  };
223
231
  }
224
- function createUseActions(id, useStatus) {
232
+ function createUseActions(id, useStatus, options = {}) {
233
+ let stateSnapshot = null;
225
234
  return () => {
226
235
  const dispatch = (0, import_store8.__useDispatch)();
227
236
  const { isBlocked } = useStatus();
@@ -231,12 +240,14 @@ function createUseActions(id, useStatus) {
231
240
  return;
232
241
  }
233
242
  dispatch(slice_default.actions.open(id));
243
+ stateSnapshot = options.onOpen?.() ?? null;
234
244
  },
235
245
  close: async () => {
236
246
  if (isBlocked) {
237
247
  return;
238
248
  }
239
249
  dispatch(slice_default.actions.close(id));
250
+ options.onClose?.(stateSnapshot);
240
251
  }
241
252
  };
242
253
  };
@@ -274,7 +285,8 @@ var Header = (0, import_ui3.styled)(import_ui3.Box)(({ theme }) => ({
274
285
  height: theme?.spacing(6) || "48px",
275
286
  display: "flex",
276
287
  alignItems: "center",
277
- justifyContent: "center"
288
+ justifyContent: "center",
289
+ gap: theme?.spacing(0.5) || "4px"
278
290
  }));
279
291
  function PanelHeader({ children, ...props }) {
280
292
  return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(Header, { component: "header", ...props }, children), /* @__PURE__ */ React4.createElement(import_ui3.Divider, null));
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/init.ts","../src/components/internal/panels.tsx","../src/hooks/use-open-panel-injection.ts","../src/location.ts","../src/store/selectors.ts","../src/store/slice.ts","../src/components/internal/portal.tsx","../src/sync.ts","../src/api.ts","../src/components/external/panel.tsx","../src/components/external/panel-header.tsx","../src/components/external/panel-header-title.tsx","../src/components/external/panel-body.tsx","../src/components/external/panel-footer.tsx"],"sourcesContent":["import init from './init';\n\nexport { createPanel as __createPanel, registerPanel as __registerPanel } from './api';\n\nexport * from './components/external';\n\ninit();\n","import { injectIntoTop } from '@elementor/editor';\nimport { __registerSlice } from '@elementor/store';\n\nimport Panels from './components/internal/panels';\nimport { slice } from './store';\nimport { sync } from './sync';\n\nexport default function init() {\n\tsync();\n\n\t__registerSlice( slice );\n\n\tinjectIntoTop( { id: 'panels', component: Panels } );\n}\n","import * as React from 'react';\n\nimport useOpenPanelInjection from '../../hooks/use-open-panel-injection';\nimport Portal from './portal';\n\nexport default function Panels() {\n\tconst openPanel = useOpenPanelInjection();\n\tconst Component = openPanel?.component ?? null;\n\n\tif ( ! Component ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Portal>\n\t\t\t<Component />\n\t\t</Portal>\n\t);\n}\n","import { useMemo } from 'react';\nimport { __useSelector as useSelector } from '@elementor/store';\n\nimport { usePanelsInjections } from '../location';\nimport { selectOpenId } from '../store';\n\nexport default function useOpenPanelInjection() {\n\tconst injections = usePanelsInjections();\n\tconst openId = useSelector( selectOpenId );\n\n\treturn useMemo( () => injections.find( ( injection ) => openId === injection.id ), [ injections, openId ] );\n}\n","import { createLocation } from '@elementor/locations';\n\nexport const { inject: injectIntoPanels, useInjections: usePanelsInjections } = createLocation();\n","import { type SliceState } from '@elementor/store';\n\nimport type slice from './slice';\n\ntype State = SliceState< typeof slice >;\n\nexport const selectOpenId = ( state: State ) => state.panels.openId;\n","import { __createSlice, type PayloadAction } from '@elementor/store';\n\nconst initialState: {\n\topenId: string | null;\n} = {\n\topenId: null,\n};\n\nexport default __createSlice( {\n\tname: 'panels',\n\tinitialState,\n\treducers: {\n\t\topen( state, action: PayloadAction< string > ) {\n\t\t\tstate.openId = action.payload;\n\t\t},\n\t\tclose( state, action: PayloadAction< string | undefined > ) {\n\t\t\tif ( ! action.payload || state.openId === action.payload ) {\n\t\t\t\tstate.openId = null;\n\t\t\t}\n\t\t},\n\t},\n} );\n","import * as React from 'react';\nimport { useRef } from 'react';\nimport { Portal as BasePortal, type PortalProps } from '@elementor/ui';\n\nimport { getPortalContainer } from '../../sync';\n\ntype Props = Omit< PortalProps, 'container' >;\n\nexport default function Portal( props: Props ) {\n\tconst containerRef = useRef( getPortalContainer );\n\n\tif ( ! containerRef.current ) {\n\t\treturn null;\n\t}\n\n\treturn <BasePortal container={ containerRef.current } { ...props } />;\n}\n","import {\n\t__privateIsRouteActive as isRouteActive,\n\t__privateListenTo as listenTo,\n\t__privateOpenRoute as openRoute,\n\t__privateRegisterRoute as registerRoute,\n\t__privateUseRouteStatus as useRouteStatus,\n\trouteCloseEvent,\n\trouteOpenEvent,\n\twindowEvent,\n} from '@elementor/editor-v1-adapters';\nimport { __dispatch, __getState, __subscribe as originalSubscribe } from '@elementor/store';\n\nimport { selectOpenId, slice } from './store';\n\nconst V2_PANEL = 'panel/v2';\n\nexport function getPortalContainer() {\n\treturn document.querySelector( '#elementor-panel-inner' );\n}\n\nexport function useV1PanelStatus() {\n\t// For now supporting only panels that are not part of the kit and not in preview mode.\n\treturn useRouteStatus( V2_PANEL, {\n\t\tblockOnKitRoutes: true,\n\t\tblockOnPreviewMode: true,\n\t} );\n}\n\nexport function sync() {\n\t// Register the V2 panel route on panel init.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () => registerRoute( V2_PANEL ) );\n\n\t// On empty route open, hide V1 panel elements.\n\tlistenTo( routeOpenEvent( V2_PANEL ), () => {\n\t\tgetV1PanelElements().forEach( ( el ) => {\n\t\t\tel.setAttribute( 'hidden', 'hidden' );\n\t\t\tel.setAttribute( 'inert', 'true' );\n\t\t} );\n\t} );\n\n\t// On empty route close, close the V2 panel.\n\tlistenTo( routeCloseEvent( V2_PANEL ), () => selectOpenId( __getState() ) && __dispatch( slice.actions.close() ) );\n\n\t// On empty route close, show V1 panel elements.\n\tlistenTo( routeCloseEvent( V2_PANEL ), () => {\n\t\tgetV1PanelElements().forEach( ( el ) => {\n\t\t\tel.removeAttribute( 'hidden' );\n\t\t\tel.removeAttribute( 'inert' );\n\t\t} );\n\t} );\n\n\t// On V2 panel open, open the V2 panel route.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () =>\n\t\tsubscribe( {\n\t\t\ton: ( state ) => selectOpenId( state ),\n\t\t\twhen: ( { prev, current } ) => !! ( ! prev && current ), // is panel opened\n\t\t\tcallback: () => openRoute( V2_PANEL ),\n\t\t} )\n\t);\n\n\t// On V2 panel close, close the V2 panel route.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () =>\n\t\tsubscribe( {\n\t\t\ton: ( state ) => selectOpenId( state ),\n\t\t\twhen: ( { prev, current } ) => !! ( ! current && prev ), // is panel closed\n\t\t\tcallback: () => isRouteActive( V2_PANEL ) && openRoute( getDefaultRoute() ),\n\t\t} )\n\t);\n}\n\nfunction getV1PanelElements() {\n\tconst v1ElementsSelector = [\n\t\t'#elementor-panel-header-wrapper',\n\t\t'#elementor-panel-content-wrapper',\n\t\t'#elementor-panel-state-loading',\n\t\t'#elementor-panel-footer',\n\t].join( ', ' );\n\n\treturn document.querySelectorAll( v1ElementsSelector );\n}\n\nfunction getDefaultRoute() {\n\ttype ExtendedWindow = Window & {\n\t\telementor?: {\n\t\t\tdocuments?: {\n\t\t\t\tgetCurrent?: () => {\n\t\t\t\t\tconfig?: {\n\t\t\t\t\t\tpanel?: {\n\t\t\t\t\t\t\tdefault_route?: string;\n\t\t\t\t\t\t};\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n\n\tconst defaultRoute = ( window as unknown as ExtendedWindow )?.elementor?.documents?.getCurrent?.()?.config?.panel\n\t\t?.default_route;\n\n\treturn defaultRoute || 'panel/elements/categories';\n}\n\nfunction subscribe< TVal >( {\n\ton,\n\twhen,\n\tcallback,\n}: {\n\ton: ( state: ReturnType< typeof __getState > ) => TVal;\n\twhen: ( { prev, current }: { prev: TVal; current: TVal } ) => boolean;\n\tcallback: ( { prev, current }: { prev: TVal; current: TVal } ) => void;\n} ) {\n\tlet prev: TVal;\n\n\toriginalSubscribe( () => {\n\t\tconst current = on( __getState() );\n\n\t\tif ( when( { prev, current } ) ) {\n\t\t\tcallback( { prev, current } );\n\t\t}\n\n\t\tprev = current;\n\t} );\n}\n","import { type ComponentType } from 'react';\nimport { __useDispatch as useDispatch, __useSelector as useSelector } from '@elementor/store';\n\nimport { injectIntoPanels } from './location';\nimport { selectOpenId, slice } from './store';\nimport { useV1PanelStatus } from './sync';\n\ntype PanelDeclaration = {\n\tid: string;\n\tcomponent: ComponentType;\n};\n\nexport function createPanel( { id, component }: PanelDeclaration ) {\n\tconst usePanelStatus = createUseStatus( id );\n\tconst usePanelActions = createUseActions( id, usePanelStatus );\n\n\treturn {\n\t\tpanel: {\n\t\t\tid,\n\t\t\tcomponent,\n\t\t},\n\t\tusePanelStatus,\n\t\tusePanelActions,\n\t};\n}\n\nexport function registerPanel( { id, component }: Pick< PanelDeclaration, 'id' | 'component' > ) {\n\tinjectIntoPanels( {\n\t\tid,\n\t\tcomponent,\n\t} );\n}\n\nfunction createUseStatus( id: PanelDeclaration[ 'id' ] ) {\n\treturn () => {\n\t\tconst openPanelId = useSelector( selectOpenId );\n\t\tconst v1PanelStatus = useV1PanelStatus();\n\n\t\treturn {\n\t\t\tisOpen: openPanelId === id && v1PanelStatus.isActive,\n\t\t\tisBlocked: v1PanelStatus.isBlocked,\n\t\t};\n\t};\n}\n\nfunction createUseActions( id: PanelDeclaration[ 'id' ], useStatus: ReturnType< typeof createUseStatus > ) {\n\treturn () => {\n\t\tconst dispatch = useDispatch();\n\t\tconst { isBlocked } = useStatus();\n\n\t\treturn {\n\t\t\topen: async () => {\n\t\t\t\tif ( isBlocked ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdispatch( slice.actions.open( id ) );\n\t\t\t},\n\t\t\tclose: async () => {\n\t\t\t\tif ( isBlocked ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdispatch( slice.actions.close( id ) );\n\t\t\t},\n\t\t};\n\t};\n}\n","import * as React from 'react';\nimport { Drawer, type DrawerProps } from '@elementor/ui';\n\nexport default function Panel( { children, sx, ...props }: DrawerProps ) {\n\treturn (\n\t\t<Drawer\n\t\t\topen={ true }\n\t\t\tvariant=\"persistent\"\n\t\t\tanchor=\"left\"\n\t\t\tPaperProps={ {\n\t\t\t\tsx: {\n\t\t\t\t\tposition: 'relative',\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\tbgcolor: 'background.default',\n\t\t\t\t\tborder: 'none',\n\t\t\t\t},\n\t\t\t} }\n\t\t\tsx={ { height: '100%', ...sx } }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</Drawer>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps, Divider, styled } from '@elementor/ui';\n\nconst Header = styled( Box )( ( { theme } ) => ( {\n\theight: theme?.spacing( 6 ) || '48px',\n\tdisplay: 'flex',\n\talignItems: 'center',\n\tjustifyContent: 'center',\n} ) );\n\nexport default function PanelHeader( { children, ...props }: BoxProps ) {\n\treturn (\n\t\t<>\n\t\t\t<Header component=\"header\" { ...props }>\n\t\t\t\t{ children }\n\t\t\t</Header>\n\t\t\t<Divider />\n\t\t</>\n\t);\n}\n","import * as React from 'react';\nimport { styled, Typography as TypographySource, type TypographyProps } from '@elementor/ui';\n\n// This is to override Editor reset.scss that overrides eui styles\nconst Typography = styled( TypographySource )< TypographyProps >( ( { theme, variant = 'body1' } ) => {\n\tif ( variant === 'inherit' ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t'&.MuiTypography-root': {\n\t\t\t...theme.typography[ variant ],\n\t\t},\n\t};\n} );\n\nexport default function PanelHeaderTitle( { children, ...props }: TypographyProps ) {\n\treturn (\n\t\t<Typography component=\"h2\" variant=\"subtitle1\" { ...props }>\n\t\t\t{ children }\n\t\t</Typography>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps } from '@elementor/ui';\n\nexport default function PanelBody( { children, sx, ...props }: BoxProps ) {\n\treturn (\n\t\t<Box\n\t\t\tcomponent=\"main\"\n\t\t\tsx={ {\n\t\t\t\toverflowY: 'auto',\n\t\t\t\theight: '100%',\n\t\t\t\t...sx,\n\t\t\t} }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</Box>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps, Divider } from '@elementor/ui';\n\nexport default function PanelFooter( { children, sx, ...props }: BoxProps ) {\n\treturn (\n\t\t<>\n\t\t\t<Divider />\n\t\t\t<Box\n\t\t\t\tcomponent=\"footer\"\n\t\t\t\tsx={ {\n\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\tposition: 'sticky',\n\t\t\t\t\tbottom: 0,\n\t\t\t\t\tpx: 2,\n\t\t\t\t\tpy: 1.5,\n\t\t\t\t} }\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</Box>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA8B;AAC9B,IAAAA,gBAAgC;;;ACDhC,IAAAC,SAAuB;;;ACAvB,mBAAwB;AACxB,IAAAC,gBAA6C;;;ACD7C,uBAA+B;AAExB,IAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB,QAAI,iCAAe;;;ACIxF,IAAM,eAAe,CAAE,UAAkB,MAAM,OAAO;;;ACN7D,mBAAkD;AAElD,IAAM,eAEF;AAAA,EACH,QAAQ;AACT;AAEA,IAAO,oBAAQ,4BAAe;AAAA,EAC7B,MAAM;AAAA,EACN;AAAA,EACA,UAAU;AAAA,IACT,KAAM,OAAO,QAAkC;AAC9C,YAAM,SAAS,OAAO;AAAA,IACvB;AAAA,IACA,MAAO,OAAO,QAA8C;AAC3D,UAAK,CAAE,OAAO,WAAW,MAAM,WAAW,OAAO,SAAU;AAC1D,cAAM,SAAS;AAAA,MAChB;AAAA,IACD;AAAA,EACD;AACD,CAAE;;;AHfa,SAAR,wBAAyC;AAC/C,QAAM,aAAa,oBAAoB;AACvC,QAAM,aAAS,cAAAC,eAAa,YAAa;AAEzC,aAAO,sBAAS,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AAG;AAAA;AAAA,IAEH;AAAA,EACH;AAEF;;;ACjBA,IAAAC,SAAuB;AACvB,IAAAC,aAA4C;AAE7B,SAAR,YAA8B,EAAE,UAAU,IAAI,GAAG,MAAM,GAAc;AAC3E,SACC,4DACC,qCAAC,wBAAQ,GACT;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,IAAK;AAAA,QACJ,SAAS;AAAA,QACT,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,IAAI;AAAA,QACJ,IAAI;AAAA,MACL;AAAA,MACE,GAAG;AAAA;AAAA,IAEH;AAAA,EACH,CACD;AAEF;;;AdhBA,KAAK;","names":["import_store","React","import_store","useSelector","import_react","import_store","useRouteStatus","listenTo","registerRoute","openRoute","isRouteActive","originalSubscribe","BasePortal","import_store","useSelector","useDispatch","React","import_ui","React","import_ui","React","import_ui","TypographySource","React","import_ui","React","import_ui"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/init.ts","../src/components/internal/panels.tsx","../src/hooks/use-open-panel-injection.ts","../src/location.ts","../src/store/selectors.ts","../src/store/slice.ts","../src/components/internal/portal.tsx","../src/sync.ts","../src/api.ts","../src/components/external/panel.tsx","../src/components/external/panel-header.tsx","../src/components/external/panel-header-title.tsx","../src/components/external/panel-body.tsx","../src/components/external/panel-footer.tsx"],"sourcesContent":["import init from './init';\n\nexport { createPanel as __createPanel, registerPanel as __registerPanel } from './api';\n\nexport * from './components/external';\n\ninit();\n","import { injectIntoTop } from '@elementor/editor';\nimport { __registerSlice } from '@elementor/store';\n\nimport Panels from './components/internal/panels';\nimport { slice } from './store';\nimport { sync } from './sync';\n\nexport default function init() {\n\tsync();\n\n\t__registerSlice( slice );\n\n\tinjectIntoTop( { id: 'panels', component: Panels } );\n}\n","import * as React from 'react';\n\nimport useOpenPanelInjection from '../../hooks/use-open-panel-injection';\nimport Portal from './portal';\n\nexport default function Panels() {\n\tconst openPanel = useOpenPanelInjection();\n\tconst Component = openPanel?.component ?? null;\n\n\tif ( ! Component ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Portal>\n\t\t\t<Component />\n\t\t</Portal>\n\t);\n}\n","import { useMemo } from 'react';\nimport { __useSelector as useSelector } from '@elementor/store';\n\nimport { usePanelsInjections } from '../location';\nimport { selectOpenId } from '../store';\n\nexport default function useOpenPanelInjection() {\n\tconst injections = usePanelsInjections();\n\tconst openId = useSelector( selectOpenId );\n\n\treturn useMemo( () => injections.find( ( injection ) => openId === injection.id ), [ injections, openId ] );\n}\n","import { createLocation } from '@elementor/locations';\n\nexport const { inject: injectIntoPanels, useInjections: usePanelsInjections } = createLocation();\n","import { type SliceState } from '@elementor/store';\n\nimport type slice from './slice';\n\ntype State = SliceState< typeof slice >;\n\nexport const selectOpenId = ( state: State ) => state.panels.openId;\n","import { __createSlice, type PayloadAction } from '@elementor/store';\n\nconst initialState: {\n\topenId: string | null;\n} = {\n\topenId: null,\n};\n\nexport default __createSlice( {\n\tname: 'panels',\n\tinitialState,\n\treducers: {\n\t\topen( state, action: PayloadAction< string > ) {\n\t\t\tstate.openId = action.payload;\n\t\t},\n\t\tclose( state, action: PayloadAction< string | undefined > ) {\n\t\t\tif ( ! action.payload || state.openId === action.payload ) {\n\t\t\t\tstate.openId = null;\n\t\t\t}\n\t\t},\n\t},\n} );\n","import * as React from 'react';\nimport { useRef } from 'react';\nimport { Portal as BasePortal, type PortalProps } from '@elementor/ui';\n\nimport { getPortalContainer } from '../../sync';\n\ntype Props = Omit< PortalProps, 'container' >;\n\nexport default function Portal( props: Props ) {\n\tconst containerRef = useRef( getPortalContainer );\n\n\tif ( ! containerRef.current ) {\n\t\treturn null;\n\t}\n\n\treturn <BasePortal container={ containerRef.current } { ...props } />;\n}\n","import {\n\t__privateIsRouteActive as isRouteActive,\n\t__privateListenTo as listenTo,\n\t__privateOpenRoute as openRoute,\n\t__privateRegisterRoute as registerRoute,\n\trouteCloseEvent,\n\trouteOpenEvent,\n\twindowEvent,\n} from '@elementor/editor-v1-adapters';\nimport { __dispatch, __getState, __subscribe as originalSubscribe } from '@elementor/store';\n\nimport { selectOpenId, slice } from './store';\n\nexport const V2_PANEL = 'panel/v2';\n\nexport function getPortalContainer() {\n\treturn document.querySelector( '#elementor-panel-inner' );\n}\n\nexport function sync() {\n\t// Register the V2 panel route on panel init.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () => registerRoute( V2_PANEL ) );\n\n\t// On empty route open, hide V1 panel elements.\n\tlistenTo( routeOpenEvent( V2_PANEL ), () => {\n\t\tgetV1PanelElements().forEach( ( el ) => {\n\t\t\tel.setAttribute( 'hidden', 'hidden' );\n\t\t\tel.setAttribute( 'inert', 'true' );\n\t\t} );\n\t} );\n\n\t// On empty route close, close the V2 panel.\n\tlistenTo( routeCloseEvent( V2_PANEL ), () => selectOpenId( __getState() ) && __dispatch( slice.actions.close() ) );\n\n\t// On empty route close, show V1 panel elements.\n\tlistenTo( routeCloseEvent( V2_PANEL ), () => {\n\t\tgetV1PanelElements().forEach( ( el ) => {\n\t\t\tel.removeAttribute( 'hidden' );\n\t\t\tel.removeAttribute( 'inert' );\n\t\t} );\n\t} );\n\n\t// On V2 panel open, open the V2 panel route.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () =>\n\t\tsubscribe( {\n\t\t\ton: ( state ) => selectOpenId( state ),\n\t\t\twhen: ( { prev, current } ) => !! ( ! prev && current ), // is panel opened\n\t\t\tcallback: () => openRoute( V2_PANEL ),\n\t\t} )\n\t);\n\n\t// On V2 panel close, close the V2 panel route.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () =>\n\t\tsubscribe( {\n\t\t\ton: ( state ) => selectOpenId( state ),\n\t\t\twhen: ( { prev, current } ) => !! ( ! current && prev ), // is panel closed\n\t\t\tcallback: () => isRouteActive( V2_PANEL ) && openRoute( getDefaultRoute() ),\n\t\t} )\n\t);\n}\n\nfunction getV1PanelElements() {\n\tconst v1ElementsSelector = [\n\t\t'#elementor-panel-header-wrapper',\n\t\t'#elementor-panel-content-wrapper',\n\t\t'#elementor-panel-state-loading',\n\t\t'#elementor-panel-footer',\n\t].join( ', ' );\n\n\treturn document.querySelectorAll( v1ElementsSelector );\n}\n\nfunction getDefaultRoute() {\n\ttype ExtendedWindow = Window & {\n\t\telementor?: {\n\t\t\tdocuments?: {\n\t\t\t\tgetCurrent?: () => {\n\t\t\t\t\tconfig?: {\n\t\t\t\t\t\tpanel?: {\n\t\t\t\t\t\t\tdefault_route?: string;\n\t\t\t\t\t\t};\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n\n\tconst defaultRoute = ( window as unknown as ExtendedWindow )?.elementor?.documents?.getCurrent?.()?.config?.panel\n\t\t?.default_route;\n\n\treturn defaultRoute || 'panel/elements/categories';\n}\n\nfunction subscribe< TVal >( {\n\ton,\n\twhen,\n\tcallback,\n}: {\n\ton: ( state: ReturnType< typeof __getState > ) => TVal;\n\twhen: ( { prev, current }: { prev: TVal; current: TVal } ) => boolean;\n\tcallback: ( { prev, current }: { prev: TVal; current: TVal } ) => void;\n} ) {\n\tlet prev: TVal;\n\n\toriginalSubscribe( () => {\n\t\tconst current = on( __getState() );\n\n\t\tif ( when( { prev, current } ) ) {\n\t\t\tcallback( { prev, current } );\n\t\t}\n\n\t\tprev = current;\n\t} );\n}\n","import { type ComponentType } from 'react';\nimport { __privateUseRouteStatus as useRouteStatus, type UseRouteStatusOptions } from '@elementor/editor-v1-adapters';\nimport { __useDispatch as useDispatch, __useSelector as useSelector } from '@elementor/store';\n\nimport { injectIntoPanels } from './location';\nimport { selectOpenId, slice } from './store';\nimport { V2_PANEL } from './sync';\n\nexport type PanelDeclaration< TOnOpenReturn = unknown > = {\n\tid: string;\n\tcomponent: ComponentType;\n} & UseActionsOptions< TOnOpenReturn > &\n\tUseRouteStatusOptions;\n\nexport function createPanel< TOnOpenReturn >( {\n\tid,\n\tcomponent,\n\tonOpen,\n\tonClose,\n\tallowedEditModes,\n\tblockOnKitRoutes,\n}: PanelDeclaration< TOnOpenReturn > ) {\n\tconst usePanelStatus = createUseStatus( id, {\n\t\tallowedEditModes,\n\t\tblockOnKitRoutes,\n\t} );\n\n\tconst usePanelActions = createUseActions( id, usePanelStatus, {\n\t\tonOpen,\n\t\tonClose,\n\t} );\n\n\treturn {\n\t\tpanel: {\n\t\t\tid,\n\t\t\tcomponent,\n\t\t},\n\t\tusePanelStatus,\n\t\tusePanelActions,\n\t};\n}\n\nexport function registerPanel( { id, component }: Pick< PanelDeclaration, 'id' | 'component' > ) {\n\tinjectIntoPanels( {\n\t\tid,\n\t\tcomponent,\n\t} );\n}\n\ntype UseStatus = () => {\n\tisOpen: boolean;\n\tisBlocked: boolean;\n};\n\nfunction createUseStatus( id: PanelDeclaration[ 'id' ], options: UseRouteStatusOptions = {} ): UseStatus {\n\treturn () => {\n\t\tconst openPanelId = useSelector( selectOpenId );\n\t\tconst v1PanelStatus = useRouteStatus( V2_PANEL, options );\n\n\t\treturn {\n\t\t\tisOpen: openPanelId === id && v1PanelStatus.isActive,\n\t\t\tisBlocked: v1PanelStatus.isBlocked,\n\t\t};\n\t};\n}\n\ntype UseActionsOptions< TOnOpenReturn > = {\n\tonOpen?: () => TOnOpenReturn;\n\tonClose?: ( state: TOnOpenReturn ) => void;\n};\n\nfunction createUseActions< TOnOpenReturn >(\n\tid: PanelDeclaration[ 'id' ],\n\tuseStatus: UseStatus,\n\toptions: UseActionsOptions< TOnOpenReturn > = {}\n) {\n\tlet stateSnapshot: TOnOpenReturn | null = null;\n\n\treturn () => {\n\t\tconst dispatch = useDispatch();\n\t\tconst { isBlocked } = useStatus();\n\n\t\treturn {\n\t\t\topen: async () => {\n\t\t\t\tif ( isBlocked ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdispatch( slice.actions.open( id ) );\n\n\t\t\t\tstateSnapshot = options.onOpen?.() ?? null;\n\t\t\t},\n\t\t\tclose: async () => {\n\t\t\t\tif ( isBlocked ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdispatch( slice.actions.close( id ) );\n\n\t\t\t\toptions.onClose?.( stateSnapshot as TOnOpenReturn );\n\t\t\t},\n\t\t};\n\t};\n}\n","import * as React from 'react';\nimport { Drawer, type DrawerProps } from '@elementor/ui';\n\nexport default function Panel( { children, sx, ...props }: DrawerProps ) {\n\treturn (\n\t\t<Drawer\n\t\t\topen={ true }\n\t\t\tvariant=\"persistent\"\n\t\t\tanchor=\"left\"\n\t\t\tPaperProps={ {\n\t\t\t\tsx: {\n\t\t\t\t\tposition: 'relative',\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\tbgcolor: 'background.default',\n\t\t\t\t\tborder: 'none',\n\t\t\t\t},\n\t\t\t} }\n\t\t\tsx={ { height: '100%', ...sx } }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</Drawer>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps, Divider, styled } from '@elementor/ui';\n\nconst Header = styled( Box )( ( { theme } ) => ( {\n\theight: theme?.spacing( 6 ) || '48px',\n\tdisplay: 'flex',\n\talignItems: 'center',\n\tjustifyContent: 'center',\n\tgap: theme?.spacing( 0.5 ) || '4px',\n} ) );\n\nexport default function PanelHeader( { children, ...props }: BoxProps ) {\n\treturn (\n\t\t<>\n\t\t\t<Header component=\"header\" { ...props }>\n\t\t\t\t{ children }\n\t\t\t</Header>\n\t\t\t<Divider />\n\t\t</>\n\t);\n}\n","import * as React from 'react';\nimport { styled, Typography as TypographySource, type TypographyProps } from '@elementor/ui';\n\n// This is to override Editor reset.scss that overrides eui styles\nconst Typography = styled( TypographySource )< TypographyProps >( ( { theme, variant = 'body1' } ) => {\n\tif ( variant === 'inherit' ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t'&.MuiTypography-root': {\n\t\t\t...theme.typography[ variant ],\n\t\t},\n\t};\n} );\n\nexport default function PanelHeaderTitle( { children, ...props }: TypographyProps ) {\n\treturn (\n\t\t<Typography component=\"h2\" variant=\"subtitle1\" { ...props }>\n\t\t\t{ children }\n\t\t</Typography>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps } from '@elementor/ui';\n\nexport default function PanelBody( { children, sx, ...props }: BoxProps ) {\n\treturn (\n\t\t<Box\n\t\t\tcomponent=\"main\"\n\t\t\tsx={ {\n\t\t\t\toverflowY: 'auto',\n\t\t\t\theight: '100%',\n\t\t\t\t...sx,\n\t\t\t} }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</Box>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps, Divider } from '@elementor/ui';\n\nexport default function PanelFooter( { children, sx, ...props }: BoxProps ) {\n\treturn (\n\t\t<>\n\t\t\t<Divider />\n\t\t\t<Box\n\t\t\t\tcomponent=\"footer\"\n\t\t\t\tsx={ {\n\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\tposition: 'sticky',\n\t\t\t\t\tbottom: 0,\n\t\t\t\t\tpx: 2,\n\t\t\t\t\tpy: 1.5,\n\t\t\t\t} }\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</Box>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA8B;AAC9B,IAAAA,gBAAgC;;;ACDhC,IAAAC,SAAuB;;;ACAvB,mBAAwB;AACxB,IAAAC,gBAA6C;;;ACD7C,uBAA+B;AAExB,IAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB,QAAI,iCAAe;;;ACIxF,IAAM,eAAe,CAAE,UAAkB,MAAM,OAAO;;;ACN7D,mBAAkD;AAElD,IAAM,eAEF;AAAA,EACH,QAAQ;AACT;AAEA,IAAO,oBAAQ,4BAAe;AAAA,EAC7B,MAAM;AAAA,EACN;AAAA,EACA,UAAU;AAAA,IACT,KAAM,OAAO,QAAkC;AAC9C,YAAM,S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AY;AAC5B,WAAO,CAAC;AAAA,EACT;AAEA,SAAO;AAAA,IACN,wBAAwB;AAAA,MACvB,GAAG,MAAM,WAAY,OAAQ;AAAA,IAC9B;AAAA,EACD;AACD,CAAE;AAEa,SAAR,iBAAmC,EAAE,UAAU,GAAG,MAAM,GAAqB;AACnF,SACC,qCAAC,cAAW,WAAU,MAAK,SAAQ,aAAc,GAAG,SACjD,QACH;AAEF;;;ACtBA,IAAAC,SAAuB;AACvB,IAAAC,aAAmC;AAEpB,SAAR,UAA4B,EAAE,UAAU,IAAI,GAAG,MAAM,GAAc;AACzE,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,IAAK;AAAA,QACJ,WAAW;AAAA,QACX,QAAQ;AAAA,QACR,GAAG;AAAA,MACJ;AAAA,MACE,GAAG;AAAA;AAAA,IAEH;AAAA,EACH;AAEF;;;ACjBA,IAAAC,SAAuB;AACvB,IAAAC,aAA4C;AAE7B,SAAR,YAA8B,EAAE,UAAU,IAAI,GAAG,MAAM,GAAc;AAC3E,SACC,4DACC,qCAAC,wBAAQ,GACT;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,IAAK;AAAA,QACJ,SAAS;AAAA,QACT,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,IAAI;AAAA,QACJ,IAAI;AAAA,MACL;AAAA,MACE,GAAG;AAAA;AAAA,IAEH;AAAA,EACH,CACD;AAEF;;;AdhBA,KAAK;","names":["import_store","React","import_store","useSelector","import_react","import_store","listenTo","registerRoute","openRoute","isRouteActive","originalSubscribe","BasePortal","import_editor_v1_adapters","import_store","useSelector","useRouteStatus","useDispatch","React","import_ui","React","import_ui","React","import_ui","TypographySource","React","import_ui","React","import_ui"]}
package/dist/index.mjs CHANGED
@@ -54,7 +54,6 @@ import {
54
54
  __privateListenTo as listenTo,
55
55
  __privateOpenRoute as openRoute,
56
56
  __privateRegisterRoute as registerRoute,
57
- __privateUseRouteStatus as useRouteStatus,
58
57
  routeCloseEvent,
59
58
  routeOpenEvent,
60
59
  windowEvent
@@ -64,12 +63,6 @@ var V2_PANEL = "panel/v2";
64
63
  function getPortalContainer() {
65
64
  return document.querySelector("#elementor-panel-inner");
66
65
  }
67
- function useV1PanelStatus() {
68
- return useRouteStatus(V2_PANEL, {
69
- blockOnKitRoutes: true,
70
- blockOnPreviewMode: true
71
- });
72
- }
73
66
  function sync() {
74
67
  listenTo(windowEvent("elementor/panel/init"), () => registerRoute(V2_PANEL));
75
68
  listenTo(routeOpenEvent(V2_PANEL), () => {
@@ -159,10 +152,24 @@ function init() {
159
152
  }
160
153
 
161
154
  // src/api.ts
155
+ import { __privateUseRouteStatus as useRouteStatus } from "@elementor/editor-v1-adapters";
162
156
  import { __useDispatch as useDispatch, __useSelector as useSelector2 } from "@elementor/store";
163
- function createPanel({ id, component }) {
164
- const usePanelStatus = createUseStatus(id);
165
- const usePanelActions = createUseActions(id, usePanelStatus);
157
+ function createPanel({
158
+ id,
159
+ component,
160
+ onOpen,
161
+ onClose,
162
+ allowedEditModes,
163
+ blockOnKitRoutes
164
+ }) {
165
+ const usePanelStatus = createUseStatus(id, {
166
+ allowedEditModes,
167
+ blockOnKitRoutes
168
+ });
169
+ const usePanelActions = createUseActions(id, usePanelStatus, {
170
+ onOpen,
171
+ onClose
172
+ });
166
173
  return {
167
174
  panel: {
168
175
  id,
@@ -178,17 +185,18 @@ function registerPanel({ id, component }) {
178
185
  component
179
186
  });
180
187
  }
181
- function createUseStatus(id) {
188
+ function createUseStatus(id, options = {}) {
182
189
  return () => {
183
190
  const openPanelId = useSelector2(selectOpenId);
184
- const v1PanelStatus = useV1PanelStatus();
191
+ const v1PanelStatus = useRouteStatus(V2_PANEL, options);
185
192
  return {
186
193
  isOpen: openPanelId === id && v1PanelStatus.isActive,
187
194
  isBlocked: v1PanelStatus.isBlocked
188
195
  };
189
196
  };
190
197
  }
191
- function createUseActions(id, useStatus) {
198
+ function createUseActions(id, useStatus, options = {}) {
199
+ let stateSnapshot = null;
192
200
  return () => {
193
201
  const dispatch = useDispatch();
194
202
  const { isBlocked } = useStatus();
@@ -198,12 +206,14 @@ function createUseActions(id, useStatus) {
198
206
  return;
199
207
  }
200
208
  dispatch(slice_default.actions.open(id));
209
+ stateSnapshot = options.onOpen?.() ?? null;
201
210
  },
202
211
  close: async () => {
203
212
  if (isBlocked) {
204
213
  return;
205
214
  }
206
215
  dispatch(slice_default.actions.close(id));
216
+ options.onClose?.(stateSnapshot);
207
217
  }
208
218
  };
209
219
  };
@@ -241,7 +251,8 @@ var Header = styled(Box)(({ theme }) => ({
241
251
  height: theme?.spacing(6) || "48px",
242
252
  display: "flex",
243
253
  alignItems: "center",
244
- justifyContent: "center"
254
+ justifyContent: "center",
255
+ gap: theme?.spacing(0.5) || "4px"
245
256
  }));
246
257
  function PanelHeader({ children, ...props }) {
247
258
  return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(Header, { component: "header", ...props }, children), /* @__PURE__ */ React4.createElement(Divider, null));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/init.ts","../src/components/internal/panels.tsx","../src/hooks/use-open-panel-injection.ts","../src/location.ts","../src/store/selectors.ts","../src/store/slice.ts","../src/components/internal/portal.tsx","../src/sync.ts","../src/api.ts","../src/components/external/panel.tsx","../src/components/external/panel-header.tsx","../src/components/external/panel-header-title.tsx","../src/components/external/panel-body.tsx","../src/components/external/panel-footer.tsx","../src/index.ts"],"sourcesContent":["import { injectIntoTop } from '@elementor/editor';\nimport { __registerSlice } from '@elementor/store';\n\nimport Panels from './components/internal/panels';\nimport { slice } from './store';\nimport { sync } from './sync';\n\nexport default function init() {\n\tsync();\n\n\t__registerSlice( slice );\n\n\tinjectIntoTop( { id: 'panels', component: Panels } );\n}\n","import * as React from 'react';\n\nimport useOpenPanelInjection from '../../hooks/use-open-panel-injection';\nimport Portal from './portal';\n\nexport default function Panels() {\n\tconst openPanel = useOpenPanelInjection();\n\tconst Component = openPanel?.component ?? null;\n\n\tif ( ! Component ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Portal>\n\t\t\t<Component />\n\t\t</Portal>\n\t);\n}\n","import { useMemo } from 'react';\nimport { __useSelector as useSelector } from '@elementor/store';\n\nimport { usePanelsInjections } from '../location';\nimport { selectOpenId } from '../store';\n\nexport default function useOpenPanelInjection() {\n\tconst injections = usePanelsInjections();\n\tconst openId = useSelector( selectOpenId );\n\n\treturn useMemo( () => injections.find( ( injection ) => openId === injection.id ), [ injections, openId ] );\n}\n","import { createLocation } from '@elementor/locations';\n\nexport const { inject: injectIntoPanels, useInjections: usePanelsInjections } = createLocation();\n","import { type SliceState } from '@elementor/store';\n\nimport type slice from './slice';\n\ntype State = SliceState< typeof slice >;\n\nexport const selectOpenId = ( state: State ) => state.panels.openId;\n","import { __createSlice, type PayloadAction } from '@elementor/store';\n\nconst initialState: {\n\topenId: string | null;\n} = {\n\topenId: null,\n};\n\nexport default __createSlice( {\n\tname: 'panels',\n\tinitialState,\n\treducers: {\n\t\topen( state, action: PayloadAction< string > ) {\n\t\t\tstate.openId = action.payload;\n\t\t},\n\t\tclose( state, action: PayloadAction< string | undefined > ) {\n\t\t\tif ( ! action.payload || state.openId === action.payload ) {\n\t\t\t\tstate.openId = null;\n\t\t\t}\n\t\t},\n\t},\n} );\n","import * as React from 'react';\nimport { useRef } from 'react';\nimport { Portal as BasePortal, type PortalProps } from '@elementor/ui';\n\nimport { getPortalContainer } from '../../sync';\n\ntype Props = Omit< PortalProps, 'container' >;\n\nexport default function Portal( props: Props ) {\n\tconst containerRef = useRef( getPortalContainer );\n\n\tif ( ! containerRef.current ) {\n\t\treturn null;\n\t}\n\n\treturn <BasePortal container={ containerRef.current } { ...props } />;\n}\n","import {\n\t__privateIsRouteActive as isRouteActive,\n\t__privateListenTo as listenTo,\n\t__privateOpenRoute as openRoute,\n\t__privateRegisterRoute as registerRoute,\n\t__privateUseRouteStatus as useRouteStatus,\n\trouteCloseEvent,\n\trouteOpenEvent,\n\twindowEvent,\n} from '@elementor/editor-v1-adapters';\nimport { __dispatch, __getState, __subscribe as originalSubscribe } from '@elementor/store';\n\nimport { selectOpenId, slice } from './store';\n\nconst V2_PANEL = 'panel/v2';\n\nexport function getPortalContainer() {\n\treturn document.querySelector( '#elementor-panel-inner' );\n}\n\nexport function useV1PanelStatus() {\n\t// For now supporting only panels that are not part of the kit and not in preview mode.\n\treturn useRouteStatus( V2_PANEL, {\n\t\tblockOnKitRoutes: true,\n\t\tblockOnPreviewMode: true,\n\t} );\n}\n\nexport function sync() {\n\t// Register the V2 panel route on panel init.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () => registerRoute( V2_PANEL ) );\n\n\t// On empty route open, hide V1 panel elements.\n\tlistenTo( routeOpenEvent( V2_PANEL ), () => {\n\t\tgetV1PanelElements().forEach( ( el ) => {\n\t\t\tel.setAttribute( 'hidden', 'hidden' );\n\t\t\tel.setAttribute( 'inert', 'true' );\n\t\t} );\n\t} );\n\n\t// On empty route close, close the V2 panel.\n\tlistenTo( routeCloseEvent( V2_PANEL ), () => selectOpenId( __getState() ) && __dispatch( slice.actions.close() ) );\n\n\t// On empty route close, show V1 panel elements.\n\tlistenTo( routeCloseEvent( V2_PANEL ), () => {\n\t\tgetV1PanelElements().forEach( ( el ) => {\n\t\t\tel.removeAttribute( 'hidden' );\n\t\t\tel.removeAttribute( 'inert' );\n\t\t} );\n\t} );\n\n\t// On V2 panel open, open the V2 panel route.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () =>\n\t\tsubscribe( {\n\t\t\ton: ( state ) => selectOpenId( state ),\n\t\t\twhen: ( { prev, current } ) => !! ( ! prev && current ), // is panel opened\n\t\t\tcallback: () => openRoute( V2_PANEL ),\n\t\t} )\n\t);\n\n\t// On V2 panel close, close the V2 panel route.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () =>\n\t\tsubscribe( {\n\t\t\ton: ( state ) => selectOpenId( state ),\n\t\t\twhen: ( { prev, current } ) => !! ( ! current && prev ), // is panel closed\n\t\t\tcallback: () => isRouteActive( V2_PANEL ) && openRoute( getDefaultRoute() ),\n\t\t} )\n\t);\n}\n\nfunction getV1PanelElements() {\n\tconst v1ElementsSelector = [\n\t\t'#elementor-panel-header-wrapper',\n\t\t'#elementor-panel-content-wrapper',\n\t\t'#elementor-panel-state-loading',\n\t\t'#elementor-panel-footer',\n\t].join( ', ' );\n\n\treturn document.querySelectorAll( v1ElementsSelector );\n}\n\nfunction getDefaultRoute() {\n\ttype ExtendedWindow = Window & {\n\t\telementor?: {\n\t\t\tdocuments?: {\n\t\t\t\tgetCurrent?: () => {\n\t\t\t\t\tconfig?: {\n\t\t\t\t\t\tpanel?: {\n\t\t\t\t\t\t\tdefault_route?: string;\n\t\t\t\t\t\t};\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n\n\tconst defaultRoute = ( window as unknown as ExtendedWindow )?.elementor?.documents?.getCurrent?.()?.config?.panel\n\t\t?.default_route;\n\n\treturn defaultRoute || 'panel/elements/categories';\n}\n\nfunction subscribe< TVal >( {\n\ton,\n\twhen,\n\tcallback,\n}: {\n\ton: ( state: ReturnType< typeof __getState > ) => TVal;\n\twhen: ( { prev, current }: { prev: TVal; current: TVal } ) => boolean;\n\tcallback: ( { prev, current }: { prev: TVal; current: TVal } ) => void;\n} ) {\n\tlet prev: TVal;\n\n\toriginalSubscribe( () => {\n\t\tconst current = on( __getState() );\n\n\t\tif ( when( { prev, current } ) ) {\n\t\t\tcallback( { prev, current } );\n\t\t}\n\n\t\tprev = current;\n\t} );\n}\n","import { type ComponentType } from 'react';\nimport { __useDispatch as useDispatch, __useSelector as useSelector } from '@elementor/store';\n\nimport { injectIntoPanels } from './location';\nimport { selectOpenId, slice } from './store';\nimport { useV1PanelStatus } from './sync';\n\ntype PanelDeclaration = {\n\tid: string;\n\tcomponent: ComponentType;\n};\n\nexport function createPanel( { id, component }: PanelDeclaration ) {\n\tconst usePanelStatus = createUseStatus( id );\n\tconst usePanelActions = createUseActions( id, usePanelStatus );\n\n\treturn {\n\t\tpanel: {\n\t\t\tid,\n\t\t\tcomponent,\n\t\t},\n\t\tusePanelStatus,\n\t\tusePanelActions,\n\t};\n}\n\nexport function registerPanel( { id, component }: Pick< PanelDeclaration, 'id' | 'component' > ) {\n\tinjectIntoPanels( {\n\t\tid,\n\t\tcomponent,\n\t} );\n}\n\nfunction createUseStatus( id: PanelDeclaration[ 'id' ] ) {\n\treturn () => {\n\t\tconst openPanelId = useSelector( selectOpenId );\n\t\tconst v1PanelStatus = useV1PanelStatus();\n\n\t\treturn {\n\t\t\tisOpen: openPanelId === id && v1PanelStatus.isActive,\n\t\t\tisBlocked: v1PanelStatus.isBlocked,\n\t\t};\n\t};\n}\n\nfunction createUseActions( id: PanelDeclaration[ 'id' ], useStatus: ReturnType< typeof createUseStatus > ) {\n\treturn () => {\n\t\tconst dispatch = useDispatch();\n\t\tconst { isBlocked } = useStatus();\n\n\t\treturn {\n\t\t\topen: async () => {\n\t\t\t\tif ( isBlocked ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdispatch( slice.actions.open( id ) );\n\t\t\t},\n\t\t\tclose: async () => {\n\t\t\t\tif ( isBlocked ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdispatch( slice.actions.close( id ) );\n\t\t\t},\n\t\t};\n\t};\n}\n","import * as React from 'react';\nimport { Drawer, type DrawerProps } from '@elementor/ui';\n\nexport default function Panel( { children, sx, ...props }: DrawerProps ) {\n\treturn (\n\t\t<Drawer\n\t\t\topen={ true }\n\t\t\tvariant=\"persistent\"\n\t\t\tanchor=\"left\"\n\t\t\tPaperProps={ {\n\t\t\t\tsx: {\n\t\t\t\t\tposition: 'relative',\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\tbgcolor: 'background.default',\n\t\t\t\t\tborder: 'none',\n\t\t\t\t},\n\t\t\t} }\n\t\t\tsx={ { height: '100%', ...sx } }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</Drawer>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps, Divider, styled } from '@elementor/ui';\n\nconst Header = styled( Box )( ( { theme } ) => ( {\n\theight: theme?.spacing( 6 ) || '48px',\n\tdisplay: 'flex',\n\talignItems: 'center',\n\tjustifyContent: 'center',\n} ) );\n\nexport default function PanelHeader( { children, ...props }: BoxProps ) {\n\treturn (\n\t\t<>\n\t\t\t<Header component=\"header\" { ...props }>\n\t\t\t\t{ children }\n\t\t\t</Header>\n\t\t\t<Divider />\n\t\t</>\n\t);\n}\n","import * as React from 'react';\nimport { styled, Typography as TypographySource, type TypographyProps } from '@elementor/ui';\n\n// This is to override Editor reset.scss that overrides eui styles\nconst Typography = styled( TypographySource )< TypographyProps >( ( { theme, variant = 'body1' } ) => {\n\tif ( variant === 'inherit' ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t'&.MuiTypography-root': {\n\t\t\t...theme.typography[ variant ],\n\t\t},\n\t};\n} );\n\nexport default function PanelHeaderTitle( { children, ...props }: TypographyProps ) {\n\treturn (\n\t\t<Typography component=\"h2\" variant=\"subtitle1\" { ...props }>\n\t\t\t{ children }\n\t\t</Typography>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps } from '@elementor/ui';\n\nexport default function PanelBody( { children, sx, ...props }: BoxProps ) {\n\treturn (\n\t\t<Box\n\t\t\tcomponent=\"main\"\n\t\t\tsx={ {\n\t\t\t\toverflowY: 'auto',\n\t\t\t\theight: '100%',\n\t\t\t\t...sx,\n\t\t\t} }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</Box>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps, Divider } from '@elementor/ui';\n\nexport default function PanelFooter( { children, sx, ...props }: BoxProps ) {\n\treturn (\n\t\t<>\n\t\t\t<Divider />\n\t\t\t<Box\n\t\t\t\tcomponent=\"footer\"\n\t\t\t\tsx={ {\n\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\tposition: 'sticky',\n\t\t\t\t\tbottom: 0,\n\t\t\t\t\tpx: 2,\n\t\t\t\t\tpy: 1.5,\n\t\t\t\t} }\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</Box>\n\t\t</>\n\t);\n}\n","import init from './init';\n\nexport { createPanel as __createPanel, registerPanel as __registerPanel } from './api';\n\nexport * from './components/external';\n\ninit();\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;;;ACDhC,YAAYA,YAAW;;;ACAvB,SAAS,eAAe;AACxB,SAAS,iBAAiB,mBAAmB;;;ACD7C,SAAS,sBAAsB;AAExB,IAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB,IAAI,eAAe;;;ACIxF,IAAM,eAAe,CAAE,UAAkB,MAAM,OAAO;;;ACN7D,SAAS,qBAAyC;AAElD,IAAM,eAEF;AAAA,EACH,QAAQ;AACT;AAEA,IAAO,gBAAQ,cAAe;AAAA,EAC7B,MAAM;AAAA,EACN;AAAA,EACA,UAAU;AAAA,IACT,KAAM,OAAO,QAAkC;AAC9C,YAAM,SAAS,OAAO;AAAA,IACvB;AAAA,IACA,MAAO,OAAO,QAA8C;AAC3D,UAAK,CAAE,OAAO,WAAW,MAAM,WAAW,OAAO,SAAU;AAC1D,cAAM,SAAS;AAAA,MAChB;AAAA,IACD;AAAA,EACD;AACD,CAAE;;;AHfa,SAAR,wBAAyC;AAC/C,QAAM,aAAa,oBAAoB;AACvC,QAAM,SAAS,YAAa,YAAa;AAEzC,SAAO,QAAS,MAAM,WAAW,KAAM,CAAE,cAAe,WAAW,UAAU,EAAG,GAAG,CAAE,YAAY,MAAO,CAAE;AAC3G;;;AIXA,YAAY,WAAW;AACvB,SAAS,cAAc;AACvB,SAAS,UAAU,kBAAoC;;;ACFvD;AAAA,EACC,0BAA0B;AAAA,EAC1B,qBAAqB;AAAA,EACrB,sBAAsB;AAAA,EACtB,0BAA0B;AAAA,E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C,qCAACA,UAAA,IAAQ,GACT;AAAA,IAACD;AAAA,IAAA;AAAA,MACA,WAAU;AAAA,MACV,IAAK;AAAA,QACJ,SAAS;AAAA,QACT,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,IAAI;AAAA,QACJ,IAAI;AAAA,MACL;AAAA,MACE,GAAG;AAAA;AAAA,IAEH;AAAA,EACH,CACD;AAEF;;;AChBA,KAAK;","names":["React","useSelector","useSelector","React","React","React","styled","React","Box","React","Box","Divider"]}
1
+ {"version":3,"sources":["../src/init.ts","../src/components/internal/panels.tsx","../src/hooks/use-open-panel-injection.ts","../src/location.ts","../src/store/selectors.ts","../src/store/slice.ts","../src/components/internal/portal.tsx","../src/sync.ts","../src/api.ts","../src/components/external/panel.tsx","../src/components/external/panel-header.tsx","../src/components/external/panel-header-title.tsx","../src/components/external/panel-body.tsx","../src/components/external/panel-footer.tsx","../src/index.ts"],"sourcesContent":["import { injectIntoTop } from '@elementor/editor';\nimport { __registerSlice } from '@elementor/store';\n\nimport Panels from './components/internal/panels';\nimport { slice } from './store';\nimport { sync } from './sync';\n\nexport default function init() {\n\tsync();\n\n\t__registerSlice( slice );\n\n\tinjectIntoTop( { id: 'panels', component: Panels } );\n}\n","import * as React from 'react';\n\nimport useOpenPanelInjection from '../../hooks/use-open-panel-injection';\nimport Portal from './portal';\n\nexport default function Panels() {\n\tconst openPanel = useOpenPanelInjection();\n\tconst Component = openPanel?.component ?? null;\n\n\tif ( ! Component ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Portal>\n\t\t\t<Component />\n\t\t</Portal>\n\t);\n}\n","import { useMemo } from 'react';\nimport { __useSelector as useSelector } from '@elementor/store';\n\nimport { usePanelsInjections } from '../location';\nimport { selectOpenId } from '../store';\n\nexport default function useOpenPanelInjection() {\n\tconst injections = usePanelsInjections();\n\tconst openId = useSelector( selectOpenId );\n\n\treturn useMemo( () => injections.find( ( injection ) => openId === injection.id ), [ injections, openId ] );\n}\n","import { createLocation } from '@elementor/locations';\n\nexport const { inject: injectIntoPanels, useInjections: usePanelsInjections } = createLocation();\n","import { type SliceState } from '@elementor/store';\n\nimport type slice from './slice';\n\ntype State = SliceState< typeof slice >;\n\nexport const selectOpenId = ( state: State ) => state.panels.openId;\n","import { __createSlice, type PayloadAction } from '@elementor/store';\n\nconst initialState: {\n\topenId: string | null;\n} = {\n\topenId: null,\n};\n\nexport default __createSlice( {\n\tname: 'panels',\n\tinitialState,\n\treducers: {\n\t\topen( state, action: PayloadAction< string > ) {\n\t\t\tstate.openId = action.payload;\n\t\t},\n\t\tclose( state, action: PayloadAction< string | undefined > ) {\n\t\t\tif ( ! action.payload || state.openId === action.payload ) {\n\t\t\t\tstate.openId = null;\n\t\t\t}\n\t\t},\n\t},\n} );\n","import * as React from 'react';\nimport { useRef } from 'react';\nimport { Portal as BasePortal, type PortalProps } from '@elementor/ui';\n\nimport { getPortalContainer } from '../../sync';\n\ntype Props = Omit< PortalProps, 'container' >;\n\nexport default function Portal( props: Props ) {\n\tconst containerRef = useRef( getPortalContainer );\n\n\tif ( ! containerRef.current ) {\n\t\treturn null;\n\t}\n\n\treturn <BasePortal container={ containerRef.current } { ...props } />;\n}\n","import {\n\t__privateIsRouteActive as isRouteActive,\n\t__privateListenTo as listenTo,\n\t__privateOpenRoute as openRoute,\n\t__privateRegisterRoute as registerRoute,\n\trouteCloseEvent,\n\trouteOpenEvent,\n\twindowEvent,\n} from '@elementor/editor-v1-adapters';\nimport { __dispatch, __getState, __subscribe as originalSubscribe } from '@elementor/store';\n\nimport { selectOpenId, slice } from './store';\n\nexport const V2_PANEL = 'panel/v2';\n\nexport function getPortalContainer() {\n\treturn document.querySelector( '#elementor-panel-inner' );\n}\n\nexport function sync() {\n\t// Register the V2 panel route on panel init.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () => registerRoute( V2_PANEL ) );\n\n\t// On empty route open, hide V1 panel elements.\n\tlistenTo( routeOpenEvent( V2_PANEL ), () => {\n\t\tgetV1PanelElements().forEach( ( el ) => {\n\t\t\tel.setAttribute( 'hidden', 'hidden' );\n\t\t\tel.setAttribute( 'inert', 'true' );\n\t\t} );\n\t} );\n\n\t// On empty route close, close the V2 panel.\n\tlistenTo( routeCloseEvent( V2_PANEL ), () => selectOpenId( __getState() ) && __dispatch( slice.actions.close() ) );\n\n\t// On empty route close, show V1 panel elements.\n\tlistenTo( routeCloseEvent( V2_PANEL ), () => {\n\t\tgetV1PanelElements().forEach( ( el ) => {\n\t\t\tel.removeAttribute( 'hidden' );\n\t\t\tel.removeAttribute( 'inert' );\n\t\t} );\n\t} );\n\n\t// On V2 panel open, open the V2 panel route.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () =>\n\t\tsubscribe( {\n\t\t\ton: ( state ) => selectOpenId( state ),\n\t\t\twhen: ( { prev, current } ) => !! ( ! prev && current ), // is panel opened\n\t\t\tcallback: () => openRoute( V2_PANEL ),\n\t\t} )\n\t);\n\n\t// On V2 panel close, close the V2 panel route.\n\tlistenTo( windowEvent( 'elementor/panel/init' ), () =>\n\t\tsubscribe( {\n\t\t\ton: ( state ) => selectOpenId( state ),\n\t\t\twhen: ( { prev, current } ) => !! ( ! current && prev ), // is panel closed\n\t\t\tcallback: () => isRouteActive( V2_PANEL ) && openRoute( getDefaultRoute() ),\n\t\t} )\n\t);\n}\n\nfunction getV1PanelElements() {\n\tconst v1ElementsSelector = [\n\t\t'#elementor-panel-header-wrapper',\n\t\t'#elementor-panel-content-wrapper',\n\t\t'#elementor-panel-state-loading',\n\t\t'#elementor-panel-footer',\n\t].join( ', ' );\n\n\treturn document.querySelectorAll( v1ElementsSelector );\n}\n\nfunction getDefaultRoute() {\n\ttype ExtendedWindow = Window & {\n\t\telementor?: {\n\t\t\tdocuments?: {\n\t\t\t\tgetCurrent?: () => {\n\t\t\t\t\tconfig?: {\n\t\t\t\t\t\tpanel?: {\n\t\t\t\t\t\t\tdefault_route?: string;\n\t\t\t\t\t\t};\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t};\n\t\t};\n\t};\n\n\tconst defaultRoute = ( window as unknown as ExtendedWindow )?.elementor?.documents?.getCurrent?.()?.config?.panel\n\t\t?.default_route;\n\n\treturn defaultRoute || 'panel/elements/categories';\n}\n\nfunction subscribe< TVal >( {\n\ton,\n\twhen,\n\tcallback,\n}: {\n\ton: ( state: ReturnType< typeof __getState > ) => TVal;\n\twhen: ( { prev, current }: { prev: TVal; current: TVal } ) => boolean;\n\tcallback: ( { prev, current }: { prev: TVal; current: TVal } ) => void;\n} ) {\n\tlet prev: TVal;\n\n\toriginalSubscribe( () => {\n\t\tconst current = on( __getState() );\n\n\t\tif ( when( { prev, current } ) ) {\n\t\t\tcallback( { prev, current } );\n\t\t}\n\n\t\tprev = current;\n\t} );\n}\n","import { type ComponentType } from 'react';\nimport { __privateUseRouteStatus as useRouteStatus, type UseRouteStatusOptions } from '@elementor/editor-v1-adapters';\nimport { __useDispatch as useDispatch, __useSelector as useSelector } from '@elementor/store';\n\nimport { injectIntoPanels } from './location';\nimport { selectOpenId, slice } from './store';\nimport { V2_PANEL } from './sync';\n\nexport type PanelDeclaration< TOnOpenReturn = unknown > = {\n\tid: string;\n\tcomponent: ComponentType;\n} & UseActionsOptions< TOnOpenReturn > &\n\tUseRouteStatusOptions;\n\nexport function createPanel< TOnOpenReturn >( {\n\tid,\n\tcomponent,\n\tonOpen,\n\tonClose,\n\tallowedEditModes,\n\tblockOnKitRoutes,\n}: PanelDeclaration< TOnOpenReturn > ) {\n\tconst usePanelStatus = createUseStatus( id, {\n\t\tallowedEditModes,\n\t\tblockOnKitRoutes,\n\t} );\n\n\tconst usePanelActions = createUseActions( id, usePanelStatus, {\n\t\tonOpen,\n\t\tonClose,\n\t} );\n\n\treturn {\n\t\tpanel: {\n\t\t\tid,\n\t\t\tcomponent,\n\t\t},\n\t\tusePanelStatus,\n\t\tusePanelActions,\n\t};\n}\n\nexport function registerPanel( { id, component }: Pick< PanelDeclaration, 'id' | 'component' > ) {\n\tinjectIntoPanels( {\n\t\tid,\n\t\tcomponent,\n\t} );\n}\n\ntype UseStatus = () => {\n\tisOpen: boolean;\n\tisBlocked: boolean;\n};\n\nfunction createUseStatus( id: PanelDeclaration[ 'id' ], options: UseRouteStatusOptions = {} ): UseStatus {\n\treturn () => {\n\t\tconst openPanelId = useSelector( selectOpenId );\n\t\tconst v1PanelStatus = useRouteStatus( V2_PANEL, options );\n\n\t\treturn {\n\t\t\tisOpen: openPanelId === id && v1PanelStatus.isActive,\n\t\t\tisBlocked: v1PanelStatus.isBlocked,\n\t\t};\n\t};\n}\n\ntype UseActionsOptions< TOnOpenReturn > = {\n\tonOpen?: () => TOnOpenReturn;\n\tonClose?: ( state: TOnOpenReturn ) => void;\n};\n\nfunction createUseActions< TOnOpenReturn >(\n\tid: PanelDeclaration[ 'id' ],\n\tuseStatus: UseStatus,\n\toptions: UseActionsOptions< TOnOpenReturn > = {}\n) {\n\tlet stateSnapshot: TOnOpenReturn | null = null;\n\n\treturn () => {\n\t\tconst dispatch = useDispatch();\n\t\tconst { isBlocked } = useStatus();\n\n\t\treturn {\n\t\t\topen: async () => {\n\t\t\t\tif ( isBlocked ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdispatch( slice.actions.open( id ) );\n\n\t\t\t\tstateSnapshot = options.onOpen?.() ?? null;\n\t\t\t},\n\t\t\tclose: async () => {\n\t\t\t\tif ( isBlocked ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tdispatch( slice.actions.close( id ) );\n\n\t\t\t\toptions.onClose?.( stateSnapshot as TOnOpenReturn );\n\t\t\t},\n\t\t};\n\t};\n}\n","import * as React from 'react';\nimport { Drawer, type DrawerProps } from '@elementor/ui';\n\nexport default function Panel( { children, sx, ...props }: DrawerProps ) {\n\treturn (\n\t\t<Drawer\n\t\t\topen={ true }\n\t\t\tvariant=\"persistent\"\n\t\t\tanchor=\"left\"\n\t\t\tPaperProps={ {\n\t\t\t\tsx: {\n\t\t\t\t\tposition: 'relative',\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\tbgcolor: 'background.default',\n\t\t\t\t\tborder: 'none',\n\t\t\t\t},\n\t\t\t} }\n\t\t\tsx={ { height: '100%', ...sx } }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</Drawer>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps, Divider, styled } from '@elementor/ui';\n\nconst Header = styled( Box )( ( { theme } ) => ( {\n\theight: theme?.spacing( 6 ) || '48px',\n\tdisplay: 'flex',\n\talignItems: 'center',\n\tjustifyContent: 'center',\n\tgap: theme?.spacing( 0.5 ) || '4px',\n} ) );\n\nexport default function PanelHeader( { children, ...props }: BoxProps ) {\n\treturn (\n\t\t<>\n\t\t\t<Header component=\"header\" { ...props }>\n\t\t\t\t{ children }\n\t\t\t</Header>\n\t\t\t<Divider />\n\t\t</>\n\t);\n}\n","import * as React from 'react';\nimport { styled, Typography as TypographySource, type TypographyProps } from '@elementor/ui';\n\n// This is to override Editor reset.scss that overrides eui styles\nconst Typography = styled( TypographySource )< TypographyProps >( ( { theme, variant = 'body1' } ) => {\n\tif ( variant === 'inherit' ) {\n\t\treturn {};\n\t}\n\n\treturn {\n\t\t'&.MuiTypography-root': {\n\t\t\t...theme.typography[ variant ],\n\t\t},\n\t};\n} );\n\nexport default function PanelHeaderTitle( { children, ...props }: TypographyProps ) {\n\treturn (\n\t\t<Typography component=\"h2\" variant=\"subtitle1\" { ...props }>\n\t\t\t{ children }\n\t\t</Typography>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps } from '@elementor/ui';\n\nexport default function PanelBody( { children, sx, ...props }: BoxProps ) {\n\treturn (\n\t\t<Box\n\t\t\tcomponent=\"main\"\n\t\t\tsx={ {\n\t\t\t\toverflowY: 'auto',\n\t\t\t\theight: '100%',\n\t\t\t\t...sx,\n\t\t\t} }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t</Box>\n\t);\n}\n","import * as React from 'react';\nimport { Box, type BoxProps, Divider } from '@elementor/ui';\n\nexport default function PanelFooter( { children, sx, ...props }: BoxProps ) {\n\treturn (\n\t\t<>\n\t\t\t<Divider />\n\t\t\t<Box\n\t\t\t\tcomponent=\"footer\"\n\t\t\t\tsx={ {\n\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\tposition: 'sticky',\n\t\t\t\t\tbottom: 0,\n\t\t\t\t\tpx: 2,\n\t\t\t\t\tpy: 1.5,\n\t\t\t\t} }\n\t\t\t\t{ ...props }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</Box>\n\t\t</>\n\t);\n}\n","import init from './init';\n\nexport { createPanel as __createPanel, registerPanel as __registerPanel } from './api';\n\nexport * from './components/external';\n\ninit();\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;;;ACDhC,YAAYA,YAAW;;;ACAvB,SAAS,eAAe;AACxB,SAAS,iBAAiB,mBAAmB;;;ACD7C,SAAS,sBAAsB;AAExB,IAAM,EAAE,QAAQ,kBAAkB,eAAe,oBAAoB,IAAI,eAAe;;;ACIxF,IAAM,eAAe,CAAE,UAAkB,MAAM,OAAO;;;ACN7D,SAAS,qBAAyC;AAElD,IAAM,eAEF;AAAA,EACH,QAAQ;AACT;AAEA,IAAO,gBAAQ,cAAe;AAAA,EAC7B,MAAM;AAAA,EACN;AAAA,EACA,UAAU;AAAA,IACT,KAAM,OAAO,QAAkC;AAC9C,YAAM,SAAS,OAAO;AAAA,IACvB;AAAA,IACA,MAAO,OAAO,QAA8C;AAC3D,UAAK,CAAE,OAAO,WAAW,MAAM,WAAW,OAAO,SAAU;AAC1D,cAAM,SAAS;AAAA,MAChB;AAAA,IACD;AAAA,EACD;AACD,CAAE;;;AHfa,SAAR,wBAAyC;AAC/C,QAAM,aAAa,oBAAoB;AACvC,QAAM,SAAS,YAAa,YAAa;AAEzC,SAAO,QAAS,MAAM,WAAW,KAAM,CAAE,cAAe,WAAW,UAAU,EAAG,GAAG,CAAE,Y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,OAAAC,YAA0B;AAEpB,SAAR,UAA4B,EAAE,UAAU,IAAI,GAAG,MAAM,GAAc;AACzE,SACC;AAAA,IAACA;AAAA,IAAA;AAAA,MACA,WAAU;AAAA,MACV,IAAK;AAAA,QACJ,WAAW;AAAA,QACX,QAAQ;AAAA,QACR,GAAG;AAAA,MACJ;AAAA,MACE,GAAG;AAAA;AAAA,IAEH;AAAA,EACH;AAEF;;;ACjBA,YAAYC,YAAW;AACvB,SAAS,OAAAC,MAAoB,WAAAC,gBAAe;AAE7B,SAAR,YAA8B,EAAE,UAAU,IAAI,GAAG,MAAM,GAAc;AAC3E,SACC,4DACC,qCAACA,UAAA,IAAQ,GACT;AAAA,IAACD;AAAA,IAAA;AAAA,MACA,WAAU;AAAA,MACV,IAAK;AAAA,QACJ,SAAS;AAAA,QACT,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,IAAI;AAAA,QACJ,IAAI;AAAA,MACL;AAAA,MACE,GAAG;AAAA;AAAA,IAEH;AAAA,EACH,CACD;AAEF;;;AChBA,KAAK;","names":["React","useSelector","useSelector","React","React","React","styled","React","Box","React","Box","Divider"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-panels",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,8 +39,8 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "0.18.1",
43
- "@elementor/editor-v1-adapters": "0.10.1",
42
+ "@elementor/editor": "0.18.3",
43
+ "@elementor/editor-v1-adapters": "0.11.0",
44
44
  "@elementor/locations": "0.7.6",
45
45
  "@elementor/store": "0.9.0",
46
46
  "@elementor/ui": "1.26.0"
package/src/api.ts CHANGED
@@ -1,18 +1,34 @@
1
1
  import { type ComponentType } from 'react';
2
+ import { __privateUseRouteStatus as useRouteStatus, type UseRouteStatusOptions } from '@elementor/editor-v1-adapters';
2
3
  import { __useDispatch as useDispatch, __useSelector as useSelector } from '@elementor/store';
3
4
 
4
5
  import { injectIntoPanels } from './location';
5
6
  import { selectOpenId, slice } from './store';
6
- import { useV1PanelStatus } from './sync';
7
+ import { V2_PANEL } from './sync';
7
8
 
8
- type PanelDeclaration = {
9
+ export type PanelDeclaration< TOnOpenReturn = unknown > = {
9
10
  id: string;
10
11
  component: ComponentType;
11
- };
12
+ } & UseActionsOptions< TOnOpenReturn > &
13
+ UseRouteStatusOptions;
14
+
15
+ export function createPanel< TOnOpenReturn >( {
16
+ id,
17
+ component,
18
+ onOpen,
19
+ onClose,
20
+ allowedEditModes,
21
+ blockOnKitRoutes,
22
+ }: PanelDeclaration< TOnOpenReturn > ) {
23
+ const usePanelStatus = createUseStatus( id, {
24
+ allowedEditModes,
25
+ blockOnKitRoutes,
26
+ } );
12
27
 
13
- export function createPanel( { id, component }: PanelDeclaration ) {
14
- const usePanelStatus = createUseStatus( id );
15
- const usePanelActions = createUseActions( id, usePanelStatus );
28
+ const usePanelActions = createUseActions( id, usePanelStatus, {
29
+ onOpen,
30
+ onClose,
31
+ } );
16
32
 
17
33
  return {
18
34
  panel: {
@@ -31,10 +47,15 @@ export function registerPanel( { id, component }: Pick< PanelDeclaration, 'id' |
31
47
  } );
32
48
  }
33
49
 
34
- function createUseStatus( id: PanelDeclaration[ 'id' ] ) {
50
+ type UseStatus = () => {
51
+ isOpen: boolean;
52
+ isBlocked: boolean;
53
+ };
54
+
55
+ function createUseStatus( id: PanelDeclaration[ 'id' ], options: UseRouteStatusOptions = {} ): UseStatus {
35
56
  return () => {
36
57
  const openPanelId = useSelector( selectOpenId );
37
- const v1PanelStatus = useV1PanelStatus();
58
+ const v1PanelStatus = useRouteStatus( V2_PANEL, options );
38
59
 
39
60
  return {
40
61
  isOpen: openPanelId === id && v1PanelStatus.isActive,
@@ -43,7 +64,18 @@ function createUseStatus( id: PanelDeclaration[ 'id' ] ) {
43
64
  };
44
65
  }
45
66
 
46
- function createUseActions( id: PanelDeclaration[ 'id' ], useStatus: ReturnType< typeof createUseStatus > ) {
67
+ type UseActionsOptions< TOnOpenReturn > = {
68
+ onOpen?: () => TOnOpenReturn;
69
+ onClose?: ( state: TOnOpenReturn ) => void;
70
+ };
71
+
72
+ function createUseActions< TOnOpenReturn >(
73
+ id: PanelDeclaration[ 'id' ],
74
+ useStatus: UseStatus,
75
+ options: UseActionsOptions< TOnOpenReturn > = {}
76
+ ) {
77
+ let stateSnapshot: TOnOpenReturn | null = null;
78
+
47
79
  return () => {
48
80
  const dispatch = useDispatch();
49
81
  const { isBlocked } = useStatus();
@@ -55,6 +87,8 @@ function createUseActions( id: PanelDeclaration[ 'id' ], useStatus: ReturnType<
55
87
  }
56
88
 
57
89
  dispatch( slice.actions.open( id ) );
90
+
91
+ stateSnapshot = options.onOpen?.() ?? null;
58
92
  },
59
93
  close: async () => {
60
94
  if ( isBlocked ) {
@@ -62,6 +96,8 @@ function createUseActions( id: PanelDeclaration[ 'id' ], useStatus: ReturnType<
62
96
  }
63
97
 
64
98
  dispatch( slice.actions.close( id ) );
99
+
100
+ options.onClose?.( stateSnapshot as TOnOpenReturn );
65
101
  },
66
102
  };
67
103
  };
@@ -6,6 +6,7 @@ const Header = styled( Box )( ( { theme } ) => ( {
6
6
  display: 'flex',
7
7
  alignItems: 'center',
8
8
  justifyContent: 'center',
9
+ gap: theme?.spacing( 0.5 ) || '4px',
9
10
  } ) );
10
11
 
11
12
  export default function PanelHeader( { children, ...props }: BoxProps ) {
package/src/sync.ts CHANGED
@@ -3,7 +3,6 @@ import {
3
3
  __privateListenTo as listenTo,
4
4
  __privateOpenRoute as openRoute,
5
5
  __privateRegisterRoute as registerRoute,
6
- __privateUseRouteStatus as useRouteStatus,
7
6
  routeCloseEvent,
8
7
  routeOpenEvent,
9
8
  windowEvent,
@@ -12,20 +11,12 @@ import { __dispatch, __getState, __subscribe as originalSubscribe } from '@eleme
12
11
 
13
12
  import { selectOpenId, slice } from './store';
14
13
 
15
- const V2_PANEL = 'panel/v2';
14
+ export const V2_PANEL = 'panel/v2';
16
15
 
17
16
  export function getPortalContainer() {
18
17
  return document.querySelector( '#elementor-panel-inner' );
19
18
  }
20
19
 
21
- export function useV1PanelStatus() {
22
- // For now supporting only panels that are not part of the kit and not in preview mode.
23
- return useRouteStatus( V2_PANEL, {
24
- blockOnKitRoutes: true,
25
- blockOnPreviewMode: true,
26
- } );
27
- }
28
-
29
20
  export function sync() {
30
21
  // Register the V2 panel route on panel init.
31
22
  listenTo( windowEvent( 'elementor/panel/init' ), () => registerRoute( V2_PANEL ) );