@elementor/editor-controls 4.1.0-740 → 4.1.0-742
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/components/inline-editor.tsx +16 -57
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-controls",
|
|
3
3
|
"description": "This package contains the controls model and utils for the Elementor editor",
|
|
4
|
-
"version": "4.1.0-
|
|
4
|
+
"version": "4.1.0-742",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,22 +40,22 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-current-user": "4.1.0-
|
|
44
|
-
"@elementor/editor-elements": "4.1.0-
|
|
45
|
-
"@elementor/editor-props": "4.1.0-
|
|
46
|
-
"@elementor/editor-responsive": "4.1.0-
|
|
47
|
-
"@elementor/editor-ui": "4.1.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "4.1.0-
|
|
49
|
-
"@elementor/env": "4.1.0-
|
|
50
|
-
"@elementor/http-client": "4.1.0-
|
|
43
|
+
"@elementor/editor-current-user": "4.1.0-742",
|
|
44
|
+
"@elementor/editor-elements": "4.1.0-742",
|
|
45
|
+
"@elementor/editor-props": "4.1.0-742",
|
|
46
|
+
"@elementor/editor-responsive": "4.1.0-742",
|
|
47
|
+
"@elementor/editor-ui": "4.1.0-742",
|
|
48
|
+
"@elementor/editor-v1-adapters": "4.1.0-742",
|
|
49
|
+
"@elementor/env": "4.1.0-742",
|
|
50
|
+
"@elementor/http-client": "4.1.0-742",
|
|
51
51
|
"@elementor/icons": "^1.68.0",
|
|
52
|
-
"@elementor/locations": "4.1.0-
|
|
53
|
-
"@elementor/events": "4.1.0-
|
|
54
|
-
"@elementor/query": "4.1.0-
|
|
55
|
-
"@elementor/session": "4.1.0-
|
|
52
|
+
"@elementor/locations": "4.1.0-742",
|
|
53
|
+
"@elementor/events": "4.1.0-742",
|
|
54
|
+
"@elementor/query": "4.1.0-742",
|
|
55
|
+
"@elementor/session": "4.1.0-742",
|
|
56
56
|
"@elementor/ui": "1.36.17",
|
|
57
|
-
"@elementor/utils": "4.1.0-
|
|
58
|
-
"@elementor/wp-media": "4.1.0-
|
|
57
|
+
"@elementor/utils": "4.1.0-742",
|
|
58
|
+
"@elementor/wp-media": "4.1.0-742",
|
|
59
59
|
"@wordpress/i18n": "^5.13.0",
|
|
60
60
|
"@monaco-editor/react": "^4.7.0",
|
|
61
61
|
"dayjs": "^1.11.18",
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type Dispatch,
|
|
5
|
-
type PropsWithChildren,
|
|
6
|
-
type RefObject,
|
|
7
|
-
type SetStateAction,
|
|
8
|
-
useEffect,
|
|
9
|
-
useRef,
|
|
10
|
-
} from 'react';
|
|
11
|
-
import { Box, ClickAwayListener, type SxProps, type Theme } from '@elementor/ui';
|
|
2
|
+
import { type DependencyList, type Dispatch, type SetStateAction, useEffect, useRef } from 'react';
|
|
3
|
+
import { Box, type SxProps, type Theme } from '@elementor/ui';
|
|
12
4
|
import Bold from '@tiptap/extension-bold';
|
|
13
5
|
import Document from '@tiptap/extension-document';
|
|
14
6
|
import HardBreak from '@tiptap/extension-hard-break';
|
|
@@ -42,16 +34,9 @@ type InlineEditorProps = {
|
|
|
42
34
|
onEditorCreate?: Dispatch< SetStateAction< Editor | null > >;
|
|
43
35
|
wrapperClassName?: string;
|
|
44
36
|
onSelectionEnd?: ( view: EditorView ) => void;
|
|
37
|
+
mountElement?: HTMLElement | null;
|
|
45
38
|
};
|
|
46
39
|
|
|
47
|
-
type WrapperProps = PropsWithChildren< {
|
|
48
|
-
containerRef: RefObject< HTMLDivElement >;
|
|
49
|
-
editor: ReturnType< typeof useEditor >;
|
|
50
|
-
sx: SxProps< Theme >;
|
|
51
|
-
onBlur?: () => void;
|
|
52
|
-
className?: string;
|
|
53
|
-
} >;
|
|
54
|
-
|
|
55
40
|
export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref ) => {
|
|
56
41
|
const {
|
|
57
42
|
value,
|
|
@@ -65,9 +50,12 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
|
|
|
65
50
|
onEditorCreate,
|
|
66
51
|
wrapperClassName,
|
|
67
52
|
onSelectionEnd,
|
|
53
|
+
mountElement = null,
|
|
68
54
|
} = props;
|
|
69
55
|
|
|
70
56
|
const containerRef = useRef< HTMLDivElement >( null );
|
|
57
|
+
const onBlurRef = useRef( onBlur );
|
|
58
|
+
onBlurRef.current = onBlur;
|
|
71
59
|
const documentContentSettings = !! expectedTag ? 'block+' : 'inline*';
|
|
72
60
|
|
|
73
61
|
const onUpdate = ( { editor: updatedEditor }: { editor: Editor } ) => {
|
|
@@ -78,7 +66,7 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
|
|
|
78
66
|
|
|
79
67
|
const onKeyDown = ( _: Editor[ 'view' ], event: KeyboardEvent ) => {
|
|
80
68
|
if ( event.key === 'Escape' ) {
|
|
81
|
-
|
|
69
|
+
onBlurRef.current?.();
|
|
82
70
|
}
|
|
83
71
|
|
|
84
72
|
if ( ( ! event.metaKey && ! event.ctrlKey ) || event.altKey ) {
|
|
@@ -96,6 +84,7 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
|
|
|
96
84
|
} );
|
|
97
85
|
|
|
98
86
|
const editor = useEditor( {
|
|
87
|
+
...( mountElement ? { element: mountElement } : {} ),
|
|
99
88
|
extensions: [
|
|
100
89
|
Document.extend( {
|
|
101
90
|
content: documentContentSettings,
|
|
@@ -153,6 +142,7 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
|
|
|
153
142
|
},
|
|
154
143
|
},
|
|
155
144
|
onCreate: onEditorCreate ? ( { editor: mountedEditor } ) => onEditorCreate( mountedEditor ) : undefined,
|
|
145
|
+
onBlur: mountElement ? undefined : () => onBlurRef.current?.(),
|
|
156
146
|
onSelectionUpdate: onSelectionEnd
|
|
157
147
|
? ( { editor: updatedEditor } ) => onSelectionEnd( updatedEditor.view )
|
|
158
148
|
: undefined,
|
|
@@ -170,47 +160,16 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
|
|
|
170
160
|
}
|
|
171
161
|
}, [ editor, value ] );
|
|
172
162
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
containerRef={ containerRef }
|
|
177
|
-
editor={ editor }
|
|
178
|
-
sx={ sx }
|
|
179
|
-
onBlur={ onBlur }
|
|
180
|
-
className={ wrapperClassName }
|
|
181
|
-
>
|
|
182
|
-
<EditorContent ref={ ref } editor={ editor } />
|
|
183
|
-
</Wrapper>
|
|
184
|
-
</>
|
|
185
|
-
);
|
|
186
|
-
} );
|
|
163
|
+
if ( mountElement ) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
187
166
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
{ children }
|
|
167
|
+
return (
|
|
168
|
+
<Box ref={ containerRef } sx={ sx } className={ wrapperClassName }>
|
|
169
|
+
<EditorContent ref={ ref } editor={ editor } />
|
|
192
170
|
</Box>
|
|
193
171
|
);
|
|
194
|
-
|
|
195
|
-
return onBlur ? (
|
|
196
|
-
<ClickAwayListener
|
|
197
|
-
onClickAway={ ( event: PointerEvent ) => {
|
|
198
|
-
if (
|
|
199
|
-
containerRef.current?.contains( event.target as Node ) ||
|
|
200
|
-
editor.view.dom.contains( event.target as Node )
|
|
201
|
-
) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
onBlur?.();
|
|
206
|
-
} }
|
|
207
|
-
>
|
|
208
|
-
{ wrappedChildren }
|
|
209
|
-
</ClickAwayListener>
|
|
210
|
-
) : (
|
|
211
|
-
<>{ wrappedChildren }</>
|
|
212
|
-
);
|
|
213
|
-
};
|
|
172
|
+
} );
|
|
214
173
|
|
|
215
174
|
const useOnUpdate = ( callback: () => void, dependencies: DependencyList ): void => {
|
|
216
175
|
const hasMounted = useRef( false );
|