@elementor/editor-controls 4.0.0-551 → 4.0.0-564

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.0.0-551",
4
+ "version": "4.0.0-564",
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.0.0-551",
44
- "@elementor/editor-elements": "4.0.0-551",
45
- "@elementor/editor-props": "4.0.0-551",
46
- "@elementor/editor-responsive": "4.0.0-551",
47
- "@elementor/editor-ui": "4.0.0-551",
48
- "@elementor/editor-v1-adapters": "4.0.0-551",
49
- "@elementor/env": "4.0.0-551",
50
- "@elementor/http-client": "4.0.0-551",
43
+ "@elementor/editor-current-user": "4.0.0-564",
44
+ "@elementor/editor-elements": "4.0.0-564",
45
+ "@elementor/editor-props": "4.0.0-564",
46
+ "@elementor/editor-responsive": "4.0.0-564",
47
+ "@elementor/editor-ui": "4.0.0-564",
48
+ "@elementor/editor-v1-adapters": "4.0.0-564",
49
+ "@elementor/env": "4.0.0-564",
50
+ "@elementor/http-client": "4.0.0-564",
51
51
  "@elementor/icons": "^1.63.0",
52
- "@elementor/locations": "4.0.0-551",
53
- "@elementor/events": "4.0.0-551",
54
- "@elementor/query": "4.0.0-551",
55
- "@elementor/session": "4.0.0-551",
52
+ "@elementor/locations": "4.0.0-564",
53
+ "@elementor/events": "4.0.0-564",
54
+ "@elementor/query": "4.0.0-564",
55
+ "@elementor/session": "4.0.0-564",
56
56
  "@elementor/ui": "1.36.17",
57
- "@elementor/utils": "4.0.0-551",
58
- "@elementor/wp-media": "4.0.0-551",
57
+ "@elementor/utils": "4.0.0-564",
58
+ "@elementor/wp-media": "4.0.0-564",
59
59
  "@wordpress/i18n": "^5.13.0",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "dayjs": "^1.11.18",
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { type SyntheticEvent } from 'react';
3
- import { stringArrayPropTypeUtil } from '@elementor/editor-props';
3
+ import { stringArrayPropTypeUtil, stringPropTypeUtil } from '@elementor/editor-props';
4
4
  import { Autocomplete, Chip, TextField } from '@elementor/ui';
5
5
 
6
6
  import { useBoundProp } from '../bound-prop-context';
@@ -21,14 +21,16 @@ const SIZE = 'tiny';
21
21
  export const ChipsControl = createControl( ( { options }: ChipsControlProps ) => {
22
22
  const { value, setValue, disabled } = useBoundProp( stringArrayPropTypeUtil );
23
23
 
24
- const selectedValues: string[] = value || [];
24
+ const selectedValues: string[] = ( value || [] )
25
+ .map( ( item ) => stringPropTypeUtil.extract( item ) )
26
+ .filter( ( val ): val is string => val !== null );
25
27
 
26
28
  const selectedOptions = selectedValues
27
29
  .map( ( val ) => options.find( ( opt ) => opt.value === val ) )
28
30
  .filter( ( opt ): opt is ChipsOption => opt !== undefined );
29
31
 
30
32
  const handleChange = ( _: SyntheticEvent, newValue: ChipsOption[] ) => {
31
- const values = newValue.map( ( option ) => option.value );
33
+ const values = newValue.map( ( option ) => stringPropTypeUtil.create( option.value ) );
32
34
  setValue( values.length > 0 ? values : null );
33
35
  };
34
36
 
@@ -1,13 +1,16 @@
1
1
  import * as React from 'react';
2
- import { type ComponentProps } from 'react';
3
- import { htmlPropTypeUtil } from '@elementor/editor-props';
2
+ import { type ComponentProps, useCallback, useEffect, useMemo } from 'react';
3
+ import { htmlV2PropTypeUtil, parseHtmlChildren } from '@elementor/editor-props';
4
4
  import { Box, type SxProps, type Theme } from '@elementor/ui';
5
+ import { debounce } from '@elementor/utils';
5
6
 
6
7
  import { useBoundProp } from '../bound-prop-context';
7
8
  import { InlineEditor } from '../components/inline-editor';
8
9
  import ControlActions from '../control-actions/control-actions';
9
10
  import { createControl } from '../create-control';
10
11
 
12
+ const CHILDREN_PARSE_DEBOUNCE_MS = 300;
13
+
11
14
  export const InlineEditingControl = createControl(
12
15
  ( {
13
16
  sx,
@@ -18,8 +21,37 @@ export const InlineEditingControl = createControl(
18
21
  attributes?: Record< string, string >;
19
22
  props?: ComponentProps< 'div' >;
20
23
  } ) => {
21
- const { value, setValue } = useBoundProp( htmlPropTypeUtil );
22
- const handleChange = ( newValue: unknown ) => setValue( ( newValue ?? '' ) as string );
24
+ const { value, setValue } = useBoundProp( htmlV2PropTypeUtil );
25
+ const content = value?.content ?? '';
26
+
27
+ const debouncedParse = useMemo(
28
+ () =>
29
+ debounce( ( html: string ) => {
30
+ const parsed = parseHtmlChildren( html );
31
+
32
+ setValue( {
33
+ content: parsed.content || null,
34
+ children: parsed.children,
35
+ } );
36
+ }, CHILDREN_PARSE_DEBOUNCE_MS ),
37
+ [ setValue ]
38
+ );
39
+
40
+ const handleChange = useCallback(
41
+ ( newValue: unknown ) => {
42
+ const html = ( newValue ?? '' ) as string;
43
+
44
+ setValue( {
45
+ content: html || null,
46
+ children: value?.children ?? [],
47
+ } );
48
+
49
+ debouncedParse( html );
50
+ },
51
+ [ setValue, value?.children, debouncedParse ]
52
+ );
53
+
54
+ useEffect( () => () => debouncedParse.cancel(), [ debouncedParse ] );
23
55
 
24
56
  return (
25
57
  <ControlActions>
@@ -59,7 +91,7 @@ export const InlineEditingControl = createControl(
59
91
  { ...attributes }
60
92
  { ...props }
61
93
  >
62
- <InlineEditor value={ value || '' } setValue={ handleChange } />
94
+ <InlineEditor value={ content } setValue={ handleChange } />
63
95
  </Box>
64
96
  </ControlActions>
65
97
  );