@elementor/editor-controls 4.1.0-747 → 4.1.0-749

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.1.0-747",
4
+ "version": "4.1.0-749",
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-747",
44
- "@elementor/editor-elements": "4.1.0-747",
45
- "@elementor/editor-props": "4.1.0-747",
46
- "@elementor/editor-responsive": "4.1.0-747",
47
- "@elementor/editor-ui": "4.1.0-747",
48
- "@elementor/editor-v1-adapters": "4.1.0-747",
49
- "@elementor/env": "4.1.0-747",
50
- "@elementor/http-client": "4.1.0-747",
43
+ "@elementor/editor-current-user": "4.1.0-749",
44
+ "@elementor/editor-elements": "4.1.0-749",
45
+ "@elementor/editor-props": "4.1.0-749",
46
+ "@elementor/editor-responsive": "4.1.0-749",
47
+ "@elementor/editor-ui": "4.1.0-749",
48
+ "@elementor/editor-v1-adapters": "4.1.0-749",
49
+ "@elementor/env": "4.1.0-749",
50
+ "@elementor/http-client": "4.1.0-749",
51
51
  "@elementor/icons": "^1.68.0",
52
- "@elementor/locations": "4.1.0-747",
53
- "@elementor/events": "4.1.0-747",
54
- "@elementor/query": "4.1.0-747",
55
- "@elementor/session": "4.1.0-747",
52
+ "@elementor/locations": "4.1.0-749",
53
+ "@elementor/events": "4.1.0-749",
54
+ "@elementor/query": "4.1.0-749",
55
+ "@elementor/session": "4.1.0-749",
56
56
  "@elementor/ui": "1.36.17",
57
- "@elementor/utils": "4.1.0-747",
58
- "@elementor/wp-media": "4.1.0-747",
57
+ "@elementor/utils": "4.1.0-749",
58
+ "@elementor/wp-media": "4.1.0-749",
59
59
  "@wordpress/i18n": "^5.13.0",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "dayjs": "^1.11.18",
@@ -16,7 +16,7 @@ import Underline from '@tiptap/extension-underline';
16
16
  import { type EditorProps, type EditorView } from '@tiptap/pm/view';
17
17
  import { type Editor, EditorContent, useEditor } from '@tiptap/react';
18
18
 
19
- import { isEmpty } from '../utils/inline-editing';
19
+ import { htmlToPlainText, isEmpty } from '../utils/inline-editing';
20
20
 
21
21
  const ITALIC_KEYBOARD_SHORTCUT = 'i';
22
22
  const BOLD_KEYBOARD_SHORTCUT = 'b';
@@ -141,7 +141,7 @@ export const InlineEditor = React.forwardRef( ( props: InlineEditorProps, ref )
141
141
  attributes: {
142
142
  ...( editorProps.attributes ?? {} ),
143
143
  role: 'textbox',
144
- ...( placeholder ? { 'data-placeholder': placeholder } : {} ),
144
+ ...( placeholder ? { 'data-placeholder': htmlToPlainText( placeholder ) } : {} ),
145
145
  ...( value === null || value === '' ? { class: 'is-empty' } : {} ),
146
146
  },
147
147
  },
@@ -9,6 +9,7 @@ import { useBoundProp } from '../bound-prop-context';
9
9
  import { ConditionalControlInfotip } from '../components/conditional-control-infotip';
10
10
  import ControlActions from '../control-actions/control-actions';
11
11
  import { createControl } from '../create-control';
12
+ import { type ControlProps } from '../utils/types';
12
13
 
13
14
  export type SelectOption = {
14
15
  label: string;
@@ -16,15 +17,22 @@ export type SelectOption = {
16
17
  disabled?: boolean;
17
18
  };
18
19
 
19
- type Props = {
20
+ type Props = ControlProps< {
20
21
  options: SelectOption[];
21
22
  onChange?: ( newValue: string | null, previousValue: string | null | undefined ) => void;
22
23
  fallbackLabels?: Record< string, string >;
23
- };
24
+ } >;
24
25
 
25
26
  const StyledSelect = styled( Select )( () => ( { '.MuiSelect-select.Mui-disabled': { cursor: 'not-allowed' } } ) );
26
27
 
27
- export const HtmlTagControl = createControl( ( { options, onChange, fallbackLabels = {} }: Props ) => {
28
+ export const HtmlTagControl = createControl( ( props: Props ) => {
29
+ const {
30
+ options,
31
+ onChange,
32
+ fallbackLabels = {},
33
+ context: { elementId },
34
+ } = props;
35
+
28
36
  const { value, setValue, disabled, placeholder } = useBoundProp( stringPropTypeUtil );
29
37
  const handleChange = ( event: SelectChangeEvent< StringPropValue[ 'value' ] > ) => {
30
38
  const newValue = event.target.value || null;
@@ -33,7 +41,7 @@ export const HtmlTagControl = createControl( ( { options, onChange, fallbackLabe
33
41
  setValue( newValue );
34
42
  };
35
43
 
36
- const elementLabel = getElementLabel() ?? 'element';
44
+ const elementLabel = getElementLabel( elementId ) ?? 'element';
37
45
  const infoTipProps = {
38
46
  title: __( 'HTML Tag', 'elementor' ),
39
47
  /* translators: %s is the element name. */
@@ -78,8 +86,8 @@ export const HtmlTagControl = createControl( ( { options, onChange, fallbackLabe
78
86
  disabled={ disabled }
79
87
  fullWidth
80
88
  >
81
- { options.map( ( { label, ...props } ) => (
82
- <MenuListItem key={ props.value } { ...props } value={ props.value ?? '' }>
89
+ { options.map( ( { label, ...itemProps } ) => (
90
+ <MenuListItem key={ itemProps.value } { ...itemProps } value={ itemProps.value ?? '' }>
83
91
  { label }
84
92
  </MenuListItem>
85
93
  ) ) }
@@ -9,3 +9,14 @@ export function isEmpty( value: string | null = '' ) {
9
9
 
10
10
  return ! pseudoElement.textContent?.length;
11
11
  }
12
+
13
+ export function htmlToPlainText( html: string | null ): string {
14
+ if ( ! html ) {
15
+ return '';
16
+ }
17
+
18
+ const normalizedHtml = html.replace( /<br\s*\/?>/gi, '\n' ).replace( /<\/p>\s*<p[^>]*>/gi, '\n' );
19
+ const doc = new DOMParser().parseFromString( normalizedHtml, 'text/html' );
20
+
21
+ return doc.body.textContent ?? '';
22
+ }