@elementor/editor-editing-panel 4.4.1 → 4.4.2
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/index.d.mts +21 -33
- package/dist/index.d.ts +21 -33
- package/dist/index.js +360 -682
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +224 -554
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -25
- package/src/components/css-classes/css-class-menu.tsx +1 -4
- package/src/components/css-classes/css-class-selector.tsx +0 -3
- package/src/components/section.tsx +1 -19
- package/src/components/style-tab-section.tsx +0 -6
- package/src/components/style-tab.tsx +0 -3
- package/src/controls-registry/controls-registry.tsx +1 -1
- package/src/controls-registry/element-controls/registry.ts +0 -2
- package/src/index.ts +0 -7
- package/src/init.ts +0 -3
- package/src/components/custom-css-header-location.tsx +0 -11
- package/src/components/style-section-header-location.tsx +0 -29
- package/src/components/style-tab-header-location.tsx +0 -12
- package/src/controls-registry/element-controls/menu-items-control/menu-items-control.tsx +0 -188
- package/src/controls-registry/element-controls/menu-items-control/use-actions.ts +0 -126
- package/src/controls-registry/element-controls/menu-items-control/use-entry-item.ts +0 -33
- package/src/hooks/use-broadcast-style-state.ts +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-editing-panel",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,32 +39,32 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor": "4.4.
|
|
43
|
-
"@elementor/editor-canvas": "4.4.
|
|
44
|
-
"@elementor/editor-controls": "4.4.
|
|
45
|
-
"@elementor/editor-current-user": "4.4.
|
|
46
|
-
"@elementor/editor-documents": "4.4.
|
|
47
|
-
"@elementor/editor-elements": "4.4.
|
|
48
|
-
"@elementor/editor-interactions": "4.4.
|
|
49
|
-
"@elementor/editor-notifications": "4.4.
|
|
50
|
-
"@elementor/editor-panels": "4.4.
|
|
51
|
-
"@elementor/editor-props": "4.4.
|
|
52
|
-
"@elementor/editor-responsive": "4.4.
|
|
53
|
-
"@elementor/editor-styles": "4.4.
|
|
54
|
-
"@elementor/editor-styles-repository": "4.4.
|
|
55
|
-
"@elementor/editor-ui": "4.4.
|
|
56
|
-
"@elementor/editor-v1-adapters": "4.4.
|
|
57
|
-
"@elementor/http-client": "4.4.
|
|
42
|
+
"@elementor/editor": "4.4.2",
|
|
43
|
+
"@elementor/editor-canvas": "4.4.2",
|
|
44
|
+
"@elementor/editor-controls": "4.4.2",
|
|
45
|
+
"@elementor/editor-current-user": "4.4.2",
|
|
46
|
+
"@elementor/editor-documents": "4.4.2",
|
|
47
|
+
"@elementor/editor-elements": "4.4.2",
|
|
48
|
+
"@elementor/editor-interactions": "4.4.2",
|
|
49
|
+
"@elementor/editor-notifications": "4.4.2",
|
|
50
|
+
"@elementor/editor-panels": "4.4.2",
|
|
51
|
+
"@elementor/editor-props": "4.4.2",
|
|
52
|
+
"@elementor/editor-responsive": "4.4.2",
|
|
53
|
+
"@elementor/editor-styles": "4.4.2",
|
|
54
|
+
"@elementor/editor-styles-repository": "4.4.2",
|
|
55
|
+
"@elementor/editor-ui": "4.4.2",
|
|
56
|
+
"@elementor/editor-v1-adapters": "4.4.2",
|
|
57
|
+
"@elementor/http-client": "4.4.2",
|
|
58
58
|
"@elementor/icons": "~1.78.1",
|
|
59
|
-
"@elementor/editor-variables": "4.4.
|
|
60
|
-
"@elementor/locations": "4.4.
|
|
61
|
-
"@elementor/menus": "4.4.
|
|
62
|
-
"@elementor/query": "4.4.
|
|
63
|
-
"@elementor/schema": "4.4.
|
|
64
|
-
"@elementor/session": "4.4.
|
|
59
|
+
"@elementor/editor-variables": "4.4.2",
|
|
60
|
+
"@elementor/locations": "4.4.2",
|
|
61
|
+
"@elementor/menus": "4.4.2",
|
|
62
|
+
"@elementor/query": "4.4.2",
|
|
63
|
+
"@elementor/schema": "4.4.2",
|
|
64
|
+
"@elementor/session": "4.4.2",
|
|
65
65
|
"@elementor/ui": "1.41.4",
|
|
66
|
-
"@elementor/utils": "4.4.
|
|
67
|
-
"@elementor/wp-media": "4.4.
|
|
66
|
+
"@elementor/utils": "4.4.2",
|
|
67
|
+
"@elementor/wp-media": "4.4.2",
|
|
68
68
|
"@wordpress/i18n": "^5.13.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
@@ -130,9 +130,6 @@ const CLASS_STATES_MAP: Record< string, { label: string } > = {
|
|
|
130
130
|
disabled: {
|
|
131
131
|
label: __( 'disabled', 'elementor' ),
|
|
132
132
|
},
|
|
133
|
-
current: {
|
|
134
|
-
label: __( 'current', 'elementor' ),
|
|
135
|
-
},
|
|
136
133
|
};
|
|
137
134
|
|
|
138
135
|
export function useElementStates() {
|
|
@@ -143,7 +140,7 @@ export function useElementStates() {
|
|
|
143
140
|
const elementStates = styleStates.map( ( { value, name } ) => ( {
|
|
144
141
|
key: value,
|
|
145
142
|
value,
|
|
146
|
-
label: CLASS_STATES_MAP[
|
|
143
|
+
label: CLASS_STATES_MAP[ value ]?.label ?? name,
|
|
147
144
|
} ) );
|
|
148
145
|
|
|
149
146
|
return {
|
|
@@ -38,7 +38,6 @@ import {
|
|
|
38
38
|
type ValidationEvent,
|
|
39
39
|
type ValidationResult,
|
|
40
40
|
} from '../creatable-autocomplete';
|
|
41
|
-
import { StyleTabHeaderSlot } from '../style-tab-header-location';
|
|
42
41
|
import { CssClassItem } from './css-class-item';
|
|
43
42
|
import { MissingClassesAlert } from './missing-classes-alert';
|
|
44
43
|
import {
|
|
@@ -83,7 +82,6 @@ export const { Slot: ClassSelectorActionsSlot, inject: injectIntoClassSelectorAc
|
|
|
83
82
|
*/
|
|
84
83
|
|
|
85
84
|
export function CssClassSelector() {
|
|
86
|
-
const { element } = useElement();
|
|
87
85
|
const options = useOptions();
|
|
88
86
|
|
|
89
87
|
const { id: activeId, setId: setActiveId } = useStyle();
|
|
@@ -119,7 +117,6 @@ export function CssClassSelector() {
|
|
|
119
117
|
{ __( 'Classes', 'elementor' ) }
|
|
120
118
|
</FormLabel>
|
|
121
119
|
<Stack direction="row" gap={ 1 }>
|
|
122
|
-
<StyleTabHeaderSlot elementId={ element.id } />
|
|
123
120
|
<ClassSelectorActionsSlot />
|
|
124
121
|
</Stack>
|
|
125
122
|
</Stack>
|
|
@@ -9,20 +9,11 @@ type Props = PropsWithChildren< {
|
|
|
9
9
|
title: string;
|
|
10
10
|
defaultExpanded?: boolean;
|
|
11
11
|
titleEnd?: CollapsibleValue< ReactNode | string >;
|
|
12
|
-
titleActions?: ReactNode;
|
|
13
12
|
unmountOnExit?: boolean;
|
|
14
13
|
action?: { component: ReactNode; onClick: () => void };
|
|
15
14
|
} >;
|
|
16
15
|
|
|
17
|
-
export function Section( {
|
|
18
|
-
title,
|
|
19
|
-
children,
|
|
20
|
-
defaultExpanded = false,
|
|
21
|
-
titleEnd,
|
|
22
|
-
titleActions,
|
|
23
|
-
unmountOnExit = true,
|
|
24
|
-
action,
|
|
25
|
-
}: Props ) {
|
|
16
|
+
export function Section( { title, children, defaultExpanded = false, titleEnd, unmountOnExit = true, action }: Props ) {
|
|
26
17
|
const [ isOpen, setIsOpen ] = useStateByElement( title, !! defaultExpanded );
|
|
27
18
|
const ref = useRef< HTMLElement >( null );
|
|
28
19
|
const isDisabled = !! action;
|
|
@@ -55,15 +46,6 @@ export function Section( {
|
|
|
55
46
|
sx={ { flexGrow: 0, flexShrink: 1, marginInlineEnd: 1 } }
|
|
56
47
|
/>
|
|
57
48
|
{ getCollapsibleValue( titleEnd, isOpen ) }
|
|
58
|
-
{ titleActions && (
|
|
59
|
-
<Stack
|
|
60
|
-
direction="row"
|
|
61
|
-
alignItems="center"
|
|
62
|
-
onClick={ ( event: React.MouseEvent ) => event.stopPropagation() }
|
|
63
|
-
>
|
|
64
|
-
{ titleActions }
|
|
65
|
-
</Stack>
|
|
66
|
-
) }
|
|
67
49
|
</Stack>
|
|
68
50
|
{ action?.component }
|
|
69
51
|
<CollapseIcon
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
import { useElement } from '../contexts/element-context';
|
|
5
4
|
import { useDefaultPanelSettings } from '../hooks/use-default-panel-settings';
|
|
6
5
|
import { Section } from './section';
|
|
7
|
-
import { StyleSectionHeaderSlot } from './style-section-header-location';
|
|
8
6
|
import { getStylesInheritanceIndicators } from './style-tab-collapsible-content';
|
|
9
7
|
|
|
10
8
|
type SectionType = {
|
|
@@ -18,7 +16,6 @@ type Props = { section: SectionType; fields?: string[]; unmountOnExit?: boolean
|
|
|
18
16
|
|
|
19
17
|
export const StyleTabSection = ( { section, fields = [], unmountOnExit = true }: Props ) => {
|
|
20
18
|
const { component, name, title, action } = section;
|
|
21
|
-
const { element } = useElement();
|
|
22
19
|
const tabDefaults = useDefaultPanelSettings();
|
|
23
20
|
const SectionComponent = component || ( () => <></> );
|
|
24
21
|
const isExpanded = tabDefaults.defaultSectionsExpanded.style?.includes( name );
|
|
@@ -28,9 +25,6 @@ export const StyleTabSection = ( { section, fields = [], unmountOnExit = true }:
|
|
|
28
25
|
title={ title }
|
|
29
26
|
defaultExpanded={ isExpanded }
|
|
30
27
|
titleEnd={ getStylesInheritanceIndicators( fields ) }
|
|
31
|
-
titleActions={
|
|
32
|
-
element ? <StyleSectionHeaderSlot elementId={ element.id } sectionName={ name } /> : undefined
|
|
33
|
-
}
|
|
34
28
|
unmountOnExit={ unmountOnExit }
|
|
35
29
|
action={ action }
|
|
36
30
|
>
|
|
@@ -13,7 +13,6 @@ import { useScrollDirection } from '../contexts/scroll-context';
|
|
|
13
13
|
import { StyleProvider } from '../contexts/style-context';
|
|
14
14
|
import { StyleInheritanceProvider } from '../contexts/styles-inheritance-context';
|
|
15
15
|
import { useActiveStyleDefId } from '../hooks/use-active-style-def-id';
|
|
16
|
-
import { useBroadcastStyleState } from '../hooks/use-broadcast-style-state';
|
|
17
16
|
import { CssClassSelector } from './css-classes/css-class-selector';
|
|
18
17
|
import { SectionsList } from './sections-list';
|
|
19
18
|
import { StyleSections } from './style-sections';
|
|
@@ -36,8 +35,6 @@ export const StyleTab = () => {
|
|
|
36
35
|
const [ activeStyleState, setActiveStyleState ] = useState< StyleDefinitionState | null >( null );
|
|
37
36
|
const breakpoint = useActiveBreakpoint();
|
|
38
37
|
|
|
39
|
-
useBroadcastStyleState( activeStyleState );
|
|
40
|
-
|
|
41
38
|
if ( ! currentClassesProp ) {
|
|
42
39
|
return null;
|
|
43
40
|
}
|
|
@@ -87,7 +87,7 @@ const controlTypes = {
|
|
|
87
87
|
toggle: { component: ToggleControl, layout: 'full', propTypeUtil: stringPropTypeUtil },
|
|
88
88
|
'date-time': { component: DateTimeControl, layout: 'full', propTypeUtil: DateTimePropTypeUtil },
|
|
89
89
|
video: { component: VideoMediaControl, layout: 'full', propTypeUtil: videoSrcPropTypeUtil },
|
|
90
|
-
'inline-editing': { component: InlineEditingControl, layout: '
|
|
90
|
+
'inline-editing': { component: InlineEditingControl, layout: 'full', propTypeUtil: escapedHtmlPropTypeUtil },
|
|
91
91
|
email: { component: EmailFormActionControl, layout: 'custom', propTypeUtil: emailsPropTypeUtil },
|
|
92
92
|
'date-range': {
|
|
93
93
|
component: DateRangeControl,
|
|
@@ -3,12 +3,10 @@ import { type ControlComponent } from '@elementor/editor-controls';
|
|
|
3
3
|
import { type ControlRegistry, controlsRegistry } from '../controls-registry';
|
|
4
4
|
import { AccordionItemsControl } from './accordion-items-control/accordion-items-control';
|
|
5
5
|
import { ListItemsControl } from './list-items-control/list-items-control';
|
|
6
|
-
import { MenuItemsControl } from './menu-items-control/menu-items-control';
|
|
7
6
|
import { TabsControl } from './tabs-control/tabs-control';
|
|
8
7
|
|
|
9
8
|
const controlTypes = {
|
|
10
9
|
'list-items': { component: ListItemsControl as ControlComponent, layout: 'full' },
|
|
11
|
-
'menu-items': { component: MenuItemsControl as ControlComponent, layout: 'full' },
|
|
12
10
|
tabs: { component: TabsControl as ControlComponent, layout: 'full' },
|
|
13
11
|
'accordion-items': { component: AccordionItemsControl as ControlComponent, layout: 'full' },
|
|
14
12
|
} as const satisfies ControlRegistry;
|
package/src/index.ts
CHANGED
|
@@ -28,13 +28,6 @@ export { PseudoStateMenuItems } from './components/style-states/pseudo-state-men
|
|
|
28
28
|
export { usePseudoStates } from './components/style-states/use-pseudo-states';
|
|
29
29
|
export { injectIntoGridFields } from './components/style-sections/layout-section/layout-section';
|
|
30
30
|
export { StyleTabSection } from './components/style-tab-section';
|
|
31
|
-
export {
|
|
32
|
-
CustomCssHeaderSlot,
|
|
33
|
-
injectIntoCustomCssHeader,
|
|
34
|
-
type CustomCssHeaderProps,
|
|
35
|
-
} from './components/custom-css-header-location';
|
|
36
|
-
export { injectIntoStyleSectionHeader, type StyleSectionHeaderProps } from './components/style-section-header-location';
|
|
37
|
-
export { injectIntoStyleTabHeader, type StyleTabHeaderProps } from './components/style-tab-header-location';
|
|
38
31
|
export { ClassesPropProvider, useClassesProp } from './contexts/classes-prop-context';
|
|
39
32
|
export { ElementProvider, useElement } from './contexts/element-context';
|
|
40
33
|
export { StyleProvider, useStyle } from './contexts/style-context';
|
package/src/init.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { injectIntoLogic } from '@elementor/editor';
|
|
2
|
-
import { init as initEditorControls } from '@elementor/editor-controls';
|
|
3
2
|
import { registerPanel } from '@elementor/editor-panels';
|
|
4
3
|
import { blockCommand } from '@elementor/editor-v1-adapters';
|
|
5
4
|
|
|
@@ -13,8 +12,6 @@ import { init as initStylesInheritance } from './styles-inheritance/init';
|
|
|
13
12
|
import { isAtomicWidgetSelected } from './sync/is-atomic-widget-selected';
|
|
14
13
|
|
|
15
14
|
export function init() {
|
|
16
|
-
initEditorControls();
|
|
17
|
-
|
|
18
15
|
registerPanel( panel );
|
|
19
16
|
blockV1Panel();
|
|
20
17
|
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createLocation } from '@elementor/locations';
|
|
2
|
-
|
|
3
|
-
export type CustomCssHeaderProps = {
|
|
4
|
-
elementId: string;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const {
|
|
8
|
-
Slot: CustomCssHeaderSlot,
|
|
9
|
-
inject: injectIntoCustomCssHeader,
|
|
10
|
-
useInjections: useCustomCssHeaderInjections,
|
|
11
|
-
} = createLocation< CustomCssHeaderProps >();
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type ComponentType, createElement } from 'react';
|
|
2
|
-
import { type ElementID } from '@elementor/editor-elements';
|
|
3
|
-
import { createLocation, type InjectArgs } from '@elementor/locations';
|
|
4
|
-
|
|
5
|
-
export type StyleSectionHeaderProps = {
|
|
6
|
-
elementId: ElementID;
|
|
7
|
-
sectionName: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const { Slot: StyleSectionHeaderSlot, inject: injectStyleSectionHeader } = createLocation< StyleSectionHeaderProps >();
|
|
11
|
-
|
|
12
|
-
type StyleSectionHeaderInjectArgs = Pick< InjectArgs< StyleSectionHeaderProps >, 'id' | 'component' > & {
|
|
13
|
-
sections?: string[];
|
|
14
|
-
options?: InjectArgs< StyleSectionHeaderProps >[ 'options' ];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const injectIntoStyleSectionHeader = ( { id, component, sections, options }: StyleSectionHeaderInjectArgs ) => {
|
|
18
|
-
const filteredComponent: ComponentType< StyleSectionHeaderProps > = ( props ) => {
|
|
19
|
-
if ( sections && ! sections.includes( props.sectionName ) ) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return createElement( component, props );
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
injectStyleSectionHeader( { id, component: filteredComponent, options } );
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { StyleSectionHeaderSlot };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type ElementID } from '@elementor/editor-elements';
|
|
2
|
-
import { createLocation } from '@elementor/locations';
|
|
3
|
-
|
|
4
|
-
export type StyleTabHeaderProps = {
|
|
5
|
-
elementId: ElementID;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const {
|
|
9
|
-
Slot: StyleTabHeaderSlot,
|
|
10
|
-
inject: injectIntoStyleTabHeader,
|
|
11
|
-
useInjections: useStyleTabHeaderInjections,
|
|
12
|
-
} = createLocation< StyleTabHeaderProps >();
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useId } from 'react';
|
|
3
|
-
import { ControlFormLabel, Repeater, type RepeaterItem, type SetRepeaterValuesMeta } from '@elementor/editor-controls';
|
|
4
|
-
import {
|
|
5
|
-
type Control,
|
|
6
|
-
type ControlItem,
|
|
7
|
-
getElementType,
|
|
8
|
-
updateElementEditorSettings,
|
|
9
|
-
useElementChildren,
|
|
10
|
-
useElementEditorSettings,
|
|
11
|
-
type V1Element,
|
|
12
|
-
} from '@elementor/editor-elements';
|
|
13
|
-
import { type CreateOptions } from '@elementor/editor-props';
|
|
14
|
-
import { SessionStorageProvider } from '@elementor/session';
|
|
15
|
-
import { Stack, TextField } from '@elementor/ui';
|
|
16
|
-
import { __ } from '@wordpress/i18n';
|
|
17
|
-
|
|
18
|
-
import { SettingsControl } from '../../../components/settings-control';
|
|
19
|
-
import { ElementProvider, useElement } from '../../../contexts/element-context';
|
|
20
|
-
import { getElementByType } from '../get-element-by-type';
|
|
21
|
-
import {
|
|
22
|
-
MENU_ENTRY_ELEMENT_TYPE,
|
|
23
|
-
MENU_ITEM_ELEMENT_TYPE,
|
|
24
|
-
MENU_ITEMS_ELEMENT_TYPE,
|
|
25
|
-
type MenuItem,
|
|
26
|
-
useActions,
|
|
27
|
-
} from './use-actions';
|
|
28
|
-
import { useEntryItem } from './use-entry-item';
|
|
29
|
-
|
|
30
|
-
const LINK_BIND = 'link';
|
|
31
|
-
|
|
32
|
-
export const MenuItemsControl = ( { label }: { label: string } ) => {
|
|
33
|
-
const { element } = useElement();
|
|
34
|
-
const { addItem, duplicateItem, moveItem, removeItem } = useActions();
|
|
35
|
-
|
|
36
|
-
const { [ MENU_ENTRY_ELEMENT_TYPE ]: entries } = useElementChildren( element.id, {
|
|
37
|
-
[ MENU_ITEMS_ELEMENT_TYPE ]: MENU_ENTRY_ELEMENT_TYPE,
|
|
38
|
-
} );
|
|
39
|
-
|
|
40
|
-
const menuItems = getElementByType( element.id, MENU_ITEMS_ELEMENT_TYPE ) as V1Element | null;
|
|
41
|
-
|
|
42
|
-
const repeaterValues: RepeaterItem< MenuItem >[] = entries.map( ( entry, index ) => ( {
|
|
43
|
-
id: entry.id,
|
|
44
|
-
title: entry.editorSettings?.title,
|
|
45
|
-
index,
|
|
46
|
-
} ) );
|
|
47
|
-
|
|
48
|
-
const setValue = (
|
|
49
|
-
_newValues: RepeaterItem< MenuItem >[],
|
|
50
|
-
_options: CreateOptions,
|
|
51
|
-
meta?: SetRepeaterValuesMeta< RepeaterItem< MenuItem > >
|
|
52
|
-
) => {
|
|
53
|
-
if ( ! menuItems ) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if ( meta?.action?.type === 'add' ) {
|
|
58
|
-
return addItem( {
|
|
59
|
-
menuItemsId: menuItems.id,
|
|
60
|
-
items: meta.action.payload,
|
|
61
|
-
} );
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if ( meta?.action?.type === 'remove' ) {
|
|
65
|
-
return removeItem( { menuItemsId: menuItems.id, items: meta.action.payload } );
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if ( meta?.action?.type === 'duplicate' ) {
|
|
69
|
-
return duplicateItem( { items: meta.action.payload } );
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if ( meta?.action?.type === 'reorder' ) {
|
|
73
|
-
const { from, to } = meta.action.payload;
|
|
74
|
-
|
|
75
|
-
return moveItem( {
|
|
76
|
-
menuItemsId: menuItems.id,
|
|
77
|
-
movedElementId: entries[ from ].id,
|
|
78
|
-
toIndex: to,
|
|
79
|
-
} );
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<Repeater
|
|
85
|
-
showToggle={ false }
|
|
86
|
-
values={ repeaterValues }
|
|
87
|
-
setValues={ setValue }
|
|
88
|
-
showRemove={ repeaterValues.length > 1 }
|
|
89
|
-
label={ label }
|
|
90
|
-
adornment={ () => null }
|
|
91
|
-
itemSettings={ {
|
|
92
|
-
getId: ( { item } ) => item.id,
|
|
93
|
-
initialValues: { id: '', title: __( 'Menu item', 'elementor' ) },
|
|
94
|
-
Label: ItemLabel,
|
|
95
|
-
Content: ItemContent,
|
|
96
|
-
Icon: () => null,
|
|
97
|
-
} }
|
|
98
|
-
/>
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const ItemLabel = ( { value }: { value: MenuItem } ) => (
|
|
103
|
-
<Stack sx={ { minHeight: 20 } } direction="row" alignItems="center" gap={ 1.5 }>
|
|
104
|
-
{ value.id ? (
|
|
105
|
-
<EntryLabel elementId={ value.id } fallbackTitle={ value.title } />
|
|
106
|
-
) : (
|
|
107
|
-
<span>{ value?.title }</span>
|
|
108
|
-
) }
|
|
109
|
-
</Stack>
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const EntryLabel = ( { elementId, fallbackTitle }: { elementId: string; fallbackTitle?: string } ) => {
|
|
113
|
-
const editorSettings = useElementEditorSettings( elementId );
|
|
114
|
-
|
|
115
|
-
return <span>{ editorSettings?.title ?? fallbackTitle ?? '' }</span>;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const ItemContent = ( { value }: { value: MenuItem } ) => {
|
|
119
|
-
if ( ! value.id ) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return (
|
|
124
|
-
<Stack p={ 2 } gap={ 1.5 }>
|
|
125
|
-
<ItemNameControl elementId={ value.id } />
|
|
126
|
-
<ItemLinkControl entryId={ value.id } />
|
|
127
|
-
</Stack>
|
|
128
|
-
);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const ItemNameControl = ( { elementId }: { elementId: string } ) => {
|
|
132
|
-
const editorSettings = useElementEditorSettings( elementId );
|
|
133
|
-
const inputId = useId();
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<Stack gap={ 1 }>
|
|
137
|
-
<ControlFormLabel htmlFor={ inputId }>{ __( 'Item name', 'elementor' ) }</ControlFormLabel>
|
|
138
|
-
<TextField
|
|
139
|
-
id={ inputId }
|
|
140
|
-
size="tiny"
|
|
141
|
-
value={ editorSettings?.title ?? '' }
|
|
142
|
-
onChange={ ( { target }: React.ChangeEvent< HTMLInputElement > ) => {
|
|
143
|
-
updateElementEditorSettings( { elementId, settings: { title: target.value } } );
|
|
144
|
-
} }
|
|
145
|
-
/>
|
|
146
|
-
</Stack>
|
|
147
|
-
);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const ItemLinkControl = ( { entryId }: { entryId: string } ) => {
|
|
151
|
-
const { itemId, settings } = useEntryItem( entryId );
|
|
152
|
-
const elementType = itemId ? getElementType( MENU_ITEM_ELEMENT_TYPE ) : null;
|
|
153
|
-
const linkControl = elementType ? findControlByBind( elementType.controls, LINK_BIND ) : null;
|
|
154
|
-
|
|
155
|
-
if ( ! itemId || ! elementType || ! linkControl ) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return (
|
|
160
|
-
<ElementProvider
|
|
161
|
-
element={ { id: itemId, type: MENU_ITEM_ELEMENT_TYPE } }
|
|
162
|
-
elementType={ elementType }
|
|
163
|
-
settings={ settings }
|
|
164
|
-
>
|
|
165
|
-
<SessionStorageProvider prefix={ itemId }>
|
|
166
|
-
<SettingsControl control={ linkControl } />
|
|
167
|
-
</SessionStorageProvider>
|
|
168
|
-
</ElementProvider>
|
|
169
|
-
);
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const findControlByBind = ( items: ControlItem[], bind: string ): Control | null => {
|
|
173
|
-
for ( const item of items ) {
|
|
174
|
-
if ( item.type === 'section' ) {
|
|
175
|
-
const found = findControlByBind( item.value.items, bind );
|
|
176
|
-
|
|
177
|
-
if ( found ) {
|
|
178
|
-
return found;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if ( item.type === 'control' && item.value.bind === bind ) {
|
|
183
|
-
return item;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return null;
|
|
188
|
-
};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { type ItemsActionPayload } from '@elementor/editor-controls';
|
|
2
|
-
import {
|
|
3
|
-
type CreateElementParams,
|
|
4
|
-
createElements,
|
|
5
|
-
duplicateElements,
|
|
6
|
-
generateElementId,
|
|
7
|
-
getContainer,
|
|
8
|
-
moveElements,
|
|
9
|
-
removeElements,
|
|
10
|
-
type V1ElementData,
|
|
11
|
-
} from '@elementor/editor-elements';
|
|
12
|
-
import { escapedHtmlPropTypeUtil } from '@elementor/editor-props';
|
|
13
|
-
import { __ } from '@wordpress/i18n';
|
|
14
|
-
|
|
15
|
-
export type MenuItem = {
|
|
16
|
-
id: string;
|
|
17
|
-
title?: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const MENU_ITEMS_ELEMENT_TYPE = 'e-menu-items';
|
|
21
|
-
export const MENU_ENTRY_ELEMENT_TYPE = 'e-menu-entry';
|
|
22
|
-
export const MENU_ITEM_ELEMENT_TYPE = 'e-menu-item';
|
|
23
|
-
const MIN_ENTRIES = 1;
|
|
24
|
-
const PARAGRAPH_WIDGET_TYPE = 'e-paragraph';
|
|
25
|
-
|
|
26
|
-
const getEntryTitle = () => __( 'Menu item', 'elementor' );
|
|
27
|
-
|
|
28
|
-
const buildEntryModel = ( title: string ): V1ElementData => ( {
|
|
29
|
-
elType: MENU_ENTRY_ELEMENT_TYPE,
|
|
30
|
-
id: generateElementId(),
|
|
31
|
-
editor_settings: { title },
|
|
32
|
-
elements: [
|
|
33
|
-
{
|
|
34
|
-
elType: MENU_ITEM_ELEMENT_TYPE,
|
|
35
|
-
id: generateElementId(),
|
|
36
|
-
elements: [
|
|
37
|
-
{
|
|
38
|
-
elType: 'widget',
|
|
39
|
-
widgetType: PARAGRAPH_WIDGET_TYPE,
|
|
40
|
-
id: generateElementId(),
|
|
41
|
-
elements: [],
|
|
42
|
-
settings: {
|
|
43
|
-
paragraph: escapedHtmlPropTypeUtil.create( title ),
|
|
44
|
-
tag: { $$type: 'string', value: 'span' },
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
} );
|
|
51
|
-
|
|
52
|
-
export const useActions = () => {
|
|
53
|
-
const addItem = ( { menuItemsId, items }: { menuItemsId: string; items: ItemsActionPayload< MenuItem > } ) => {
|
|
54
|
-
const menuItems = getContainer( menuItemsId );
|
|
55
|
-
|
|
56
|
-
if ( ! menuItems ) {
|
|
57
|
-
throw new Error( 'Menu items container not found' );
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
items.forEach( () => {
|
|
61
|
-
createElements( {
|
|
62
|
-
title: __( 'Menu', 'elementor' ),
|
|
63
|
-
elements: [
|
|
64
|
-
{
|
|
65
|
-
container: menuItems,
|
|
66
|
-
model: buildEntryModel( getEntryTitle() ) as CreateElementParams[ 'model' ],
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
} );
|
|
70
|
-
} );
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const removeItem = ( { menuItemsId, items }: { menuItemsId: string; items: ItemsActionPayload< MenuItem > } ) => {
|
|
74
|
-
const entriesCount =
|
|
75
|
-
getContainer( menuItemsId )?.children?.filter(
|
|
76
|
-
( child ) => child.model.get( 'elType' ) === MENU_ENTRY_ELEMENT_TYPE
|
|
77
|
-
).length ?? 0;
|
|
78
|
-
const removableCount = Math.max( 0, Math.min( items.length, entriesCount - MIN_ENTRIES ) );
|
|
79
|
-
|
|
80
|
-
if ( removableCount === 0 ) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
removeElements( {
|
|
85
|
-
title: __( 'Menu', 'elementor' ),
|
|
86
|
-
elementIds: items.slice( 0, removableCount ).map( ( { item } ) => item.id ),
|
|
87
|
-
} );
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const duplicateItem = ( { items }: { items: ItemsActionPayload< MenuItem > } ) => {
|
|
91
|
-
duplicateElements( {
|
|
92
|
-
title: __( 'Duplicate Menu item', 'elementor' ),
|
|
93
|
-
elementIds: items.map( ( { item } ) => item.id ),
|
|
94
|
-
} );
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const moveItem = ( {
|
|
98
|
-
menuItemsId,
|
|
99
|
-
movedElementId,
|
|
100
|
-
toIndex,
|
|
101
|
-
}: {
|
|
102
|
-
menuItemsId: string;
|
|
103
|
-
movedElementId: string;
|
|
104
|
-
toIndex: number;
|
|
105
|
-
} ) => {
|
|
106
|
-
const menuItems = getContainer( menuItemsId );
|
|
107
|
-
const movedElement = getContainer( movedElementId );
|
|
108
|
-
|
|
109
|
-
if ( ! menuItems || ! movedElement ) {
|
|
110
|
-
throw new Error( 'Menu item or container not found' );
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
moveElements( {
|
|
114
|
-
title: __( 'Reorder Menu items', 'elementor' ),
|
|
115
|
-
moves: [
|
|
116
|
-
{
|
|
117
|
-
element: movedElement,
|
|
118
|
-
targetContainer: menuItems,
|
|
119
|
-
options: { at: toIndex },
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
} );
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
return { addItem, removeItem, duplicateItem, moveItem };
|
|
126
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type ElementID, getContainer, getElementSettings, getElementType } from '@elementor/editor-elements';
|
|
2
|
-
import { type AnyTransformable } from '@elementor/editor-props';
|
|
3
|
-
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
4
|
-
|
|
5
|
-
import { MENU_ITEM_ELEMENT_TYPE } from './use-actions';
|
|
6
|
-
|
|
7
|
-
type EntryItem = {
|
|
8
|
-
itemId: ElementID | null;
|
|
9
|
-
settings: Record< string, AnyTransformable | null >;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const useEntryItem = ( entryId: ElementID ): EntryItem => {
|
|
13
|
-
return useListenTo(
|
|
14
|
-
[ commandEndEvent( 'document/elements/set-settings' ), commandEndEvent( 'document/elements/settings' ) ],
|
|
15
|
-
() => {
|
|
16
|
-
const item = getContainer( entryId )?.children?.find(
|
|
17
|
-
( child ) => child.model.get( 'elType' ) === MENU_ITEM_ELEMENT_TYPE
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
itemId: item?.id ?? null,
|
|
22
|
-
settings: item ? getEntrySettings( item.id ) : {},
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
[ entryId ]
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const getEntrySettings = ( itemId: ElementID ): EntryItem[ 'settings' ] => {
|
|
30
|
-
const propsSchema = getElementType( MENU_ITEM_ELEMENT_TYPE )?.propsSchema ?? {};
|
|
31
|
-
|
|
32
|
-
return getElementSettings< AnyTransformable >( itemId, Object.keys( propsSchema ) );
|
|
33
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
import { type StyleDefinitionState } from '@elementor/editor-styles';
|
|
3
|
-
|
|
4
|
-
import { useElement } from '../contexts/element-context';
|
|
5
|
-
|
|
6
|
-
export const STYLE_STATE_EVENT = 'elementor/editor/style-state/change';
|
|
7
|
-
|
|
8
|
-
function broadcast( id: string, state: StyleDefinitionState | null ) {
|
|
9
|
-
window.dispatchEvent( new CustomEvent( STYLE_STATE_EVENT, { detail: { id, state } } ) );
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function useBroadcastStyleState( state: StyleDefinitionState | null ) {
|
|
13
|
-
const { element } = useElement();
|
|
14
|
-
|
|
15
|
-
useEffect( () => {
|
|
16
|
-
broadcast( element.id, state );
|
|
17
|
-
|
|
18
|
-
return () => broadcast( element.id, null );
|
|
19
|
-
}, [ element.id, state ] );
|
|
20
|
-
}
|