@elementor/editor-editing-panel 1.8.1 → 1.10.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.
@@ -1,18 +1,20 @@
1
- import { updateSettings, useElementSetting } from '@elementor/editor-elements';
1
+ import { updateElementSettings, useElementSetting } from '@elementor/editor-elements';
2
2
  import { type ClassesPropValue } from '@elementor/editor-props';
3
3
 
4
4
  import { useClassesProp } from '../contexts/classes-prop-context';
5
5
  import { useElement } from '../contexts/element-context';
6
+ import { useStyle } from '../contexts/style-context';
6
7
 
7
8
  export const useUnapplyClass = ( classId: string ) => {
8
9
  const { element } = useElement();
10
+ const { setId: setStyleId } = useStyle();
9
11
  const classesProp = useClassesProp();
10
12
 
11
13
  const classes = useElementSetting< ClassesPropValue >( element.id, classesProp );
12
- const filteredClasses = classes?.value.filter( ( className ) => className !== classId );
14
+ const filteredClasses = classes?.value.filter( ( className ) => className !== classId ) ?? [];
13
15
 
14
16
  return () => {
15
- updateSettings( {
17
+ updateElementSettings( {
16
18
  id: element.id,
17
19
  props: {
18
20
  [ classesProp ]: {
@@ -21,5 +23,7 @@ export const useUnapplyClass = ( classId: string ) => {
21
23
  },
22
24
  },
23
25
  } );
26
+
27
+ setStyleId( null );
24
28
  };
25
29
  };
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { useBoundProp } from '@elementor/editor-controls';
2
2
  export type { PopoverActionProps } from './popover-action';
3
3
  export { replaceControl } from './control-replacement';
4
- export { registerGlobalClassMenuItem, registerStateMenuItem } from './components/css-class-menu';
4
+ export { injectIntoClassSelectorActions } from './components/css-class-selector';
5
+ export { usePanelActions, usePanelStatus } from './panel';
5
6
 
6
7
  import init from './init';
7
8
 
package/src/init.ts CHANGED
@@ -3,7 +3,6 @@ import { __registerPanel as registerPanel } from '@elementor/editor-panels';
3
3
  import { __privateBlockDataCommand as blockDataCommand } from '@elementor/editor-v1-adapters';
4
4
 
5
5
  import { EditingPanelHooks } from './components/editing-panel-hooks';
6
- import { initCssClasses } from './css-classes';
7
6
  import { init as initDynamics } from './dynamics/init';
8
7
  import { panel } from './panel';
9
8
  import { isAtomicWidgetSelected } from './sync/is-atomic-widget-selected';
@@ -19,7 +18,6 @@ export default function init() {
19
18
 
20
19
  // TODO: Move it from here once we have dynamic package.
21
20
  initDynamics();
22
- initCssClasses();
23
21
  }
24
22
 
25
23
  const blockV1Panel = () => {
@@ -1,58 +0,0 @@
1
- import { useEffect, useRef, useState } from 'react';
2
- import * as React from 'react';
3
- import { Box, Tooltip } from '@elementor/ui';
4
-
5
- type ConditionalTooltipWrapperProps = {
6
- maxWidth: React.CSSProperties[ 'maxWidth' ];
7
- title: string;
8
- };
9
-
10
- export const ConditionalTooltipWrapper = ( { maxWidth, title }: ConditionalTooltipWrapperProps ) => {
11
- const elRef = useRef< HTMLElement >( null );
12
- const [ isOverflown, setIsOverflown ] = useState( false );
13
-
14
- useEffect( () => {
15
- const onResize = () => {
16
- const element = elRef.current;
17
-
18
- if ( element ) {
19
- setIsOverflown( element.scrollWidth > element.clientWidth );
20
- }
21
- };
22
-
23
- onResize();
24
-
25
- window.addEventListener( 'resize', onResize );
26
-
27
- return () => {
28
- window.removeEventListener( 'resize', onResize );
29
- };
30
- }, [] );
31
-
32
- if ( isOverflown ) {
33
- return (
34
- <Tooltip title={ title } placement="top">
35
- <Content maxWidth={ maxWidth } ref={ elRef }>
36
- { title }
37
- </Content>
38
- </Tooltip>
39
- );
40
- }
41
-
42
- return (
43
- <Content maxWidth={ maxWidth } ref={ elRef }>
44
- { title }
45
- </Content>
46
- );
47
- };
48
-
49
- type ContentProps = React.PropsWithChildren< Omit< ConditionalTooltipWrapperProps, 'title' > >;
50
-
51
- const Content = React.forwardRef( ( { maxWidth, ...tooltipProps }: ContentProps, ref ) => (
52
- <Box
53
- ref={ ref }
54
- position="relative"
55
- sx={ { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth } }
56
- { ...tooltipProps }
57
- />
58
- ) );
@@ -1,31 +0,0 @@
1
- import * as React from 'react';
2
- import { createContext, type PropsWithChildren } from 'react';
3
-
4
- type ClassItemContextType = {
5
- styleId: string;
6
- isGlobal: boolean;
7
- isActive: boolean;
8
- };
9
- const ClassItemContext = createContext< ClassItemContextType >( {
10
- styleId: '',
11
- isGlobal: false,
12
- isActive: false,
13
- } );
14
-
15
- type ClassItemProviderProps = PropsWithChildren< ClassItemContextType >;
16
-
17
- export function CssClassItemProvider( { styleId, isGlobal, isActive, children }: ClassItemProviderProps ) {
18
- return (
19
- <ClassItemContext.Provider value={ { styleId, isGlobal, isActive } }>{ children }</ClassItemContext.Provider>
20
- );
21
- }
22
-
23
- export function useCssClassItem() {
24
- const context = React.useContext( ClassItemContext );
25
-
26
- if ( ! context ) {
27
- throw new Error( 'useCssClassItem must be used within a CssClassItemProvider' );
28
- }
29
-
30
- return context;
31
- }
@@ -1,45 +0,0 @@
1
- import { type StyleState } from '@elementor/editor-styles';
2
-
3
- import { registerGlobalClassMenuItem, registerStateMenuItem } from './components/css-class-menu';
4
- import { useCssClassItem } from './contexts/css-class-item-context';
5
- import { useUnapplyClass } from './hooks/use-unapply-class';
6
-
7
- const STATES: NonNullable< StyleState >[] = [ 'hover', 'focus', 'active' ];
8
-
9
- export function initCssClasses() {
10
- registerStateItems();
11
- registerGlobalClassItems();
12
- }
13
-
14
- function registerStateItems() {
15
- registerStateMenuItem( {
16
- id: 'normal',
17
- props: {
18
- state: null,
19
- },
20
- } );
21
-
22
- STATES.forEach( ( state ) => {
23
- registerStateMenuItem( {
24
- id: state,
25
- props: {
26
- state,
27
- },
28
- } );
29
- } );
30
- }
31
-
32
- function registerGlobalClassItems() {
33
- registerGlobalClassMenuItem( {
34
- id: 'unapply-class',
35
- useProps: () => {
36
- const { styleId: currentClass } = useCssClassItem();
37
- const unapplyClass = useUnapplyClass( currentClass );
38
-
39
- return {
40
- text: 'Remove',
41
- onClick: unapplyClass,
42
- };
43
- },
44
- } );
45
- }