@elementor/editor-components 3.33.0-215 → 3.33.0-216
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.js +73 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/api.ts +31 -0
- package/src/components/in-edit-mode.tsx +43 -0
- package/src/create-component-type.ts +39 -23
- package/src/init.ts +9 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { closeDialog, openDialog } from '@elementor/editor-ui';
|
|
3
|
+
import { InfoCircleFilledIcon } from '@elementor/icons';
|
|
4
|
+
import { Box, Button, DialogActions, DialogContent, DialogHeader, Icon, Stack, Typography } from '@elementor/ui';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
|
|
7
|
+
export const openEditModeDialog = ( lockedBy: string ) => {
|
|
8
|
+
openDialog( {
|
|
9
|
+
component: <EditModeDialog lockedBy={ lockedBy } />,
|
|
10
|
+
} );
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const EditModeDialog = ( { lockedBy }: { lockedBy: string } ) => {
|
|
14
|
+
/* translators: %s is the name of the user who is currently editing the document */
|
|
15
|
+
const content = __( '%s is currently editing this document', 'elementor' ).replace( '%s', lockedBy );
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
<DialogHeader logo={ false }>
|
|
19
|
+
<Box display="flex" alignItems="center" gap={ 1 }>
|
|
20
|
+
<Icon color="secondary">
|
|
21
|
+
<InfoCircleFilledIcon fontSize="medium" />
|
|
22
|
+
</Icon>
|
|
23
|
+
<Typography variant="subtitle1">{ content }</Typography>
|
|
24
|
+
</Box>
|
|
25
|
+
</DialogHeader>
|
|
26
|
+
<DialogContent>
|
|
27
|
+
<Stack spacing={ 2 } direction="column">
|
|
28
|
+
<Typography variant="body2">
|
|
29
|
+
{ __(
|
|
30
|
+
'You can wait for them to finish or reach out to coordinate your changes together.',
|
|
31
|
+
'elementor'
|
|
32
|
+
) }
|
|
33
|
+
</Typography>
|
|
34
|
+
<DialogActions>
|
|
35
|
+
<Button color="secondary" variant="contained" onClick={ closeDialog }>
|
|
36
|
+
{ __( 'Close', 'elementor' ) }
|
|
37
|
+
</Button>
|
|
38
|
+
</DialogActions>
|
|
39
|
+
</Stack>
|
|
40
|
+
</DialogContent>
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -9,9 +9,13 @@ import { type NumberPropValue } from '@elementor/editor-props';
|
|
|
9
9
|
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
10
10
|
import { __ } from '@wordpress/i18n';
|
|
11
11
|
|
|
12
|
+
import { apiClient } from './api';
|
|
13
|
+
|
|
12
14
|
export const TYPE = 'e-component';
|
|
13
15
|
|
|
14
|
-
export function createComponentType(
|
|
16
|
+
export function createComponentType(
|
|
17
|
+
options: CreateTemplatedElementTypeOptions & { showLockedByModal?: ( lockedBy: string ) => void }
|
|
18
|
+
): typeof ElementType {
|
|
15
19
|
const legacyWindow = window as unknown as LegacyWindow;
|
|
16
20
|
|
|
17
21
|
return class extends legacyWindow.elementor.modules.elements.types.Widget {
|
|
@@ -25,7 +29,9 @@ export function createComponentType( options: CreateTemplatedElementTypeOptions
|
|
|
25
29
|
};
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
function createComponentView(
|
|
32
|
+
function createComponentView(
|
|
33
|
+
options: CreateTemplatedElementTypeOptions & { showLockedByModal?: ( lockedBy: string ) => void }
|
|
34
|
+
): typeof ElementView {
|
|
29
35
|
return class extends createTemplatedElementView( options ) {
|
|
30
36
|
legacyWindow = window as unknown as LegacyWindow;
|
|
31
37
|
|
|
@@ -57,33 +63,43 @@ function createComponentView( options: CreateTemplatedElementTypeOptions ): type
|
|
|
57
63
|
|
|
58
64
|
getContextMenuGroups() {
|
|
59
65
|
const filteredGroups = super.getContextMenuGroups().filter( ( group ) => group.name !== 'save' );
|
|
60
|
-
const componentId = this.getComponentId()?.value;
|
|
61
|
-
|
|
66
|
+
const componentId = this.getComponentId()?.value as number;
|
|
62
67
|
if ( ! componentId ) {
|
|
63
68
|
return filteredGroups;
|
|
64
69
|
}
|
|
65
70
|
|
|
66
|
-
const newGroup =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
const newGroup = [
|
|
72
|
+
{
|
|
73
|
+
name: 'edit component',
|
|
74
|
+
actions: [
|
|
75
|
+
{
|
|
76
|
+
name: 'edit component',
|
|
77
|
+
icon: 'eicon-edit',
|
|
78
|
+
title: () => __( 'Edit Component', 'elementor' ),
|
|
79
|
+
isEnabled: () => true,
|
|
80
|
+
callback: () => this.switchDocument(),
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
return [ ...filteredGroups, ...newGroup ];
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
switchDocument() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
async switchDocument() {
|
|
89
|
+
const { isAllowedToSwitchDocument, lockedBy } = await apiClient.getComponentLockStatus(
|
|
90
|
+
this.getComponentId()?.value as number
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if ( ! isAllowedToSwitchDocument ) {
|
|
94
|
+
options.showLockedByModal?.( lockedBy || '' );
|
|
95
|
+
} else {
|
|
96
|
+
runCommand( 'editor/documents/switch', {
|
|
97
|
+
id: this.getComponentId()?.value as number,
|
|
98
|
+
mode: 'autosave',
|
|
99
|
+
selector: `[data-id="${ this.model.get( 'id' ) }"]`,
|
|
100
|
+
} );
|
|
101
|
+
apiClient.lockComponent( this.getComponentId()?.value as number );
|
|
102
|
+
}
|
|
87
103
|
}
|
|
88
104
|
|
|
89
105
|
ui() {
|
package/src/init.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { injectIntoLogic, injectIntoTop } from '@elementor/editor';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type CreateTemplatedElementTypeOptions,
|
|
4
|
+
registerElementType,
|
|
5
|
+
settingsTransformersRegistry,
|
|
6
|
+
} from '@elementor/editor-canvas';
|
|
3
7
|
import { getV1CurrentDocument } from '@elementor/editor-documents';
|
|
4
8
|
import { injectTab } from '@elementor/editor-elements-panel';
|
|
5
9
|
import { stylesRepository } from '@elementor/editor-styles-repository';
|
|
@@ -10,6 +14,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
10
14
|
import { componentIdTransformer } from './component-id-transformer';
|
|
11
15
|
import { Components } from './components/components-tab/components';
|
|
12
16
|
import { CreateComponentForm } from './components/create-component-form/create-component-form';
|
|
17
|
+
import { openEditModeDialog } from './components/in-edit-mode';
|
|
13
18
|
import { createComponentType, TYPE } from './create-component-type';
|
|
14
19
|
import { PopulateStore } from './populate-store';
|
|
15
20
|
import { componentsStylesProvider } from './store/components-styles-provider';
|
|
@@ -24,7 +29,9 @@ const COMPONENT_DOCUMENT_TYPE = 'elementor_component';
|
|
|
24
29
|
export function init() {
|
|
25
30
|
stylesRepository.register( componentsStylesProvider );
|
|
26
31
|
registerSlice( slice );
|
|
27
|
-
registerElementType( TYPE,
|
|
32
|
+
registerElementType( TYPE, ( options: CreateTemplatedElementTypeOptions ) =>
|
|
33
|
+
createComponentType( { ...options, showLockedByModal: openEditModeDialog } )
|
|
34
|
+
);
|
|
28
35
|
registerDataHook( 'dependency', 'editor/documents/close', ( args ) => {
|
|
29
36
|
const document = getV1CurrentDocument();
|
|
30
37
|
if ( document.config.type === COMPONENT_DOCUMENT_TYPE ) {
|