@elementor/editor-controls 4.3.0-1057 → 4.3.0-1059

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/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.3.0-1057",
4
+ "version": "4.3.0-1059",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,23 +40,23 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-current-user": "4.3.0-1057",
44
- "@elementor/editor-elements": "4.3.0-1057",
45
- "@elementor/editor-props": "4.3.0-1057",
46
- "@elementor/editor-responsive": "4.3.0-1057",
47
- "@elementor/editor-ui": "4.3.0-1057",
48
- "@elementor/editor-v1-adapters": "4.3.0-1057",
49
- "@elementor/env": "4.3.0-1057",
50
- "@elementor/events": "4.3.0-1057",
51
- "@elementor/http-client": "4.3.0-1057",
43
+ "@elementor/editor-current-user": "4.3.0-1059",
44
+ "@elementor/editor-elements": "4.3.0-1059",
45
+ "@elementor/editor-props": "4.3.0-1059",
46
+ "@elementor/editor-responsive": "4.3.0-1059",
47
+ "@elementor/editor-ui": "4.3.0-1059",
48
+ "@elementor/editor-v1-adapters": "4.3.0-1059",
49
+ "@elementor/env": "4.3.0-1059",
50
+ "@elementor/events": "4.3.0-1059",
51
+ "@elementor/http-client": "4.3.0-1059",
52
52
  "@elementor/icons": "~1.75.1",
53
- "@elementor/locations": "4.3.0-1057",
54
- "@elementor/query": "4.3.0-1057",
55
- "@elementor/schema": "4.3.0-1057",
56
- "@elementor/session": "4.3.0-1057",
53
+ "@elementor/locations": "4.3.0-1059",
54
+ "@elementor/query": "4.3.0-1059",
55
+ "@elementor/schema": "4.3.0-1059",
56
+ "@elementor/session": "4.3.0-1059",
57
57
  "@elementor/ui": "1.37.5",
58
- "@elementor/utils": "4.3.0-1057",
59
- "@elementor/wp-media": "4.3.0-1057",
58
+ "@elementor/utils": "4.3.0-1059",
59
+ "@elementor/wp-media": "4.3.0-1059",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "@tiptap/extension-bold": "^3.11.1",
62
62
  "@tiptap/extension-document": "^3.11.1",
@@ -32,13 +32,19 @@ export type InlineEditorToolbarProps = {
32
32
  editor: Editor;
33
33
  elementId?: ElementID;
34
34
  sx?: SxProps< Theme >;
35
+ inControlPanel?: boolean;
35
36
  };
36
37
 
37
38
  type ToolbarButtonKeys = keyof typeof toolbarButtons;
38
39
 
39
40
  type FormatAction = Omit< ToolbarButtonKeys, 'clear' >;
40
41
 
41
- export const InlineEditorToolbar = ( { editor, elementId, sx = {} }: InlineEditorToolbarProps ) => {
42
+ export const InlineEditorToolbar = ( {
43
+ editor,
44
+ elementId,
45
+ sx = {},
46
+ inControlPanel = false,
47
+ }: InlineEditorToolbarProps ) => {
42
48
  const [ urlValue, setUrlValue ] = useState( '' );
43
49
  const [ openInNewTab, setOpenInNewTab ] = useState( false );
44
50
  const toolbarRef = useRef< HTMLDivElement >( null );
@@ -101,8 +107,10 @@ export const InlineEditorToolbar = ( { editor, elementId, sx = {} }: InlineEdito
101
107
  };
102
108
 
103
109
  useEffect( () => {
104
- editor?.commands?.focus();
105
- }, [ editor ] );
110
+ if ( ! inControlPanel ) {
111
+ editor?.commands?.focus();
112
+ }
113
+ }, [ editor, inControlPanel ] );
106
114
 
107
115
  return (
108
116
  <Box
@@ -118,6 +126,20 @@ export const InlineEditorToolbar = ( { editor, elementId, sx = {} }: InlineEdito
118
126
  visibility: linkPopupState.isOpen ? 'hidden' : 'visible',
119
127
  pointerEvents: linkPopupState.isOpen ? 'none' : 'all',
120
128
  ...sx,
129
+ ...( inControlPanel && {
130
+ width: '100%',
131
+ justifyContent: 'center',
132
+ flexDirection: 'row',
133
+ backgroundColor: 'transparent',
134
+ boxShadow: 'none',
135
+ borderWidth: '0',
136
+ borderBottom: '1px solid',
137
+ borderBottomColor: 'grey.200',
138
+ borderRadius: '0',
139
+ position: 'absolute',
140
+ top: '0',
141
+ left: '0',
142
+ } ),
121
143
  } }
122
144
  >
123
145
  <Tooltip title={ clearButton.label } placement="top" sx={ { borderRadius: '8px' } }>
@@ -144,6 +166,15 @@ export const InlineEditorToolbar = ( { editor, elementId, sx = {} }: InlineEdito
144
166
  marginLeft: 0,
145
167
  },
146
168
  },
169
+ ...( inControlPanel && {
170
+ justifyContent: 'space-between',
171
+ width: '100%',
172
+ '& svg': {
173
+ width: '0.7rem',
174
+ height: '0.7rem',
175
+ fill: 'black',
176
+ },
177
+ } ),
147
178
  } }
148
179
  >
149
180
  { formatButtonsList.map( ( button ) => (
@@ -33,6 +33,7 @@ type InlineEditorProps = {
33
33
  autofocus?: boolean;
34
34
  expectedTag?: string | null;
35
35
  onEditorCreate?: Dispatch< SetStateAction< Editor | null > >;
36
+ onEditorDestroy?: () => void;
36
37
  wrapperClassName?: string;
37
38
  onSelectionEnd?: ( view: EditorView ) => void;
38
39
  mountElement?: HTMLElement | null;
@@ -50,6 +51,7 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
50
51
  onBlur = undefined,
51
52
  expectedTag = null,
52
53
  onEditorCreate,
54
+ onEditorDestroy,
53
55
  wrapperClassName,
54
56
  onSelectionEnd,
55
57
  mountElement = null,
@@ -146,6 +148,7 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
146
148
  },
147
149
  },
148
150
  onCreate: onEditorCreate ? ( { editor: mountedEditor } ) => onEditorCreate( mountedEditor ) : undefined,
151
+ onDestroy: onEditorDestroy ? () => onEditorDestroy() : undefined,
149
152
  onBlur: mountElement ? undefined : () => onBlurRef.current?.(),
150
153
  onSelectionUpdate: onSelectionEnd
151
154
  ? ( { editor: updatedEditor } ) => onSelectionEnd( updatedEditor.view )
@@ -1,39 +1,54 @@
1
1
  import * as React from 'react';
2
- import { type ComponentProps, useCallback } from 'react';
2
+ import { type ComponentProps, useCallback, useState } from 'react';
3
3
  import { escapedHtmlPropTypeUtil } from '@elementor/editor-props';
4
4
  import { Box, type SxProps, type Theme } from '@elementor/ui';
5
+ import { type Editor } from '@tiptap/react';
5
6
 
6
7
  import { useBoundProp, usePropKeyContext } from '../bound-prop-context';
7
8
  import { InlineEditor } from '../components/inline-editor';
9
+ import { InlineEditorToolbar } from '../components/inline-editor-toolbar';
8
10
  import ControlActions from '../control-actions/control-actions';
9
11
  import { createControl } from '../create-control';
10
12
  import { extractInlineHtmlContent } from '../utils/inline-editing';
13
+ import { type ControlProps } from '../utils/types';
11
14
 
12
- export const InlineEditingControl = createControl(
13
- ( {
14
- sx,
15
- attributes,
16
- props,
17
- }: {
18
- sx?: SxProps< Theme >;
19
- attributes?: Record< string, string >;
20
- props?: ComponentProps< 'div' >;
21
- } ) => {
22
- const { setValue, placeholder, value } = useBoundProp( escapedHtmlPropTypeUtil );
23
- const { value: rawValue } = usePropKeyContext();
24
- const content = value ?? extractInlineHtmlContent( rawValue );
15
+ type Props = ControlProps< {
16
+ sx?: SxProps< Theme >;
17
+ attributes?: Record< string, string >;
18
+ props?: ComponentProps< 'div' >;
19
+ } >;
25
20
 
26
- const handleChange = useCallback(
27
- ( newValue: unknown ) => {
28
- const html = ( newValue ?? '' ) as string;
21
+ export const InlineEditingControl = createControl( ( { sx, attributes, props, context: { elementId } }: Props ) => {
22
+ const { setValue, placeholder, value } = useBoundProp( escapedHtmlPropTypeUtil );
23
+ const { value: rawValue } = usePropKeyContext();
24
+ const content = value ?? extractInlineHtmlContent( rawValue );
25
+ const [ editor, setEditor ] = useState< Editor | null >( null );
29
26
 
30
- setValue( html );
31
- },
32
- [ setValue ]
33
- );
27
+ const handleChange = useCallback(
28
+ ( newValue: unknown ) => {
29
+ const html = ( newValue ?? '' ) as string;
34
30
 
35
- return (
36
- <ControlActions>
31
+ setValue( html );
32
+ },
33
+ [ setValue ]
34
+ );
35
+
36
+ return (
37
+ <ControlActions>
38
+ <Box sx={ { position: 'relative' } }>
39
+ { editor && editor.isEditable && (
40
+ <InlineEditorToolbar
41
+ editor={ editor }
42
+ elementId={ elementId }
43
+ sx={ {
44
+ boxShadow: 'none',
45
+ border: '1px solid',
46
+ borderColor: 'grey.200',
47
+ mb: 0.5,
48
+ } }
49
+ inControlPanel={ true }
50
+ />
51
+ ) }
37
52
  <Box
38
53
  sx={ {
39
54
  p: 0.8,
@@ -52,7 +67,7 @@ export const InlineEditingControl = createControl(
52
67
  outline: 'none',
53
68
  },
54
69
  '& .ProseMirror': {
55
- minHeight: '70px',
70
+ minHeight: '100px',
56
71
  fontSize: '12px',
57
72
  '& a': {
58
73
  color: 'inherit',
@@ -77,9 +92,18 @@ export const InlineEditingControl = createControl(
77
92
  { ...attributes }
78
93
  { ...props }
79
94
  >
80
- <InlineEditor value={ content } setValue={ handleChange } placeholder={ placeholder ?? null } />
95
+ <InlineEditor
96
+ value={ content }
97
+ setValue={ handleChange }
98
+ placeholder={ placeholder ?? null }
99
+ onEditorCreate={ setEditor }
100
+ onEditorDestroy={ () => setEditor( null ) }
101
+ sx={ {
102
+ paddingBlockStart: 5,
103
+ } }
104
+ />
81
105
  </Box>
82
- </ControlActions>
83
- );
84
- }
85
- );
106
+ </Box>
107
+ </ControlActions>
108
+ );
109
+ } );