@elementor/editor-controls 4.3.0-1047 → 4.3.0-1049
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 +29 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/controls/inline-editing-control.tsx +10 -35
- package/src/utils/inline-editing.ts +12 -0
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-
|
|
4
|
+
"version": "4.3.0-1049",
|
|
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-
|
|
44
|
-
"@elementor/editor-elements": "4.3.0-
|
|
45
|
-
"@elementor/editor-props": "4.3.0-
|
|
46
|
-
"@elementor/editor-responsive": "4.3.0-
|
|
47
|
-
"@elementor/editor-ui": "4.3.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "4.3.0-
|
|
49
|
-
"@elementor/env": "4.3.0-
|
|
50
|
-
"@elementor/events": "4.3.0-
|
|
51
|
-
"@elementor/http-client": "4.3.0-
|
|
43
|
+
"@elementor/editor-current-user": "4.3.0-1049",
|
|
44
|
+
"@elementor/editor-elements": "4.3.0-1049",
|
|
45
|
+
"@elementor/editor-props": "4.3.0-1049",
|
|
46
|
+
"@elementor/editor-responsive": "4.3.0-1049",
|
|
47
|
+
"@elementor/editor-ui": "4.3.0-1049",
|
|
48
|
+
"@elementor/editor-v1-adapters": "4.3.0-1049",
|
|
49
|
+
"@elementor/env": "4.3.0-1049",
|
|
50
|
+
"@elementor/events": "4.3.0-1049",
|
|
51
|
+
"@elementor/http-client": "4.3.0-1049",
|
|
52
52
|
"@elementor/icons": "~1.75.1",
|
|
53
|
-
"@elementor/locations": "4.3.0-
|
|
54
|
-
"@elementor/query": "4.3.0-
|
|
55
|
-
"@elementor/schema": "4.3.0-
|
|
56
|
-
"@elementor/session": "4.3.0-
|
|
53
|
+
"@elementor/locations": "4.3.0-1049",
|
|
54
|
+
"@elementor/query": "4.3.0-1049",
|
|
55
|
+
"@elementor/schema": "4.3.0-1049",
|
|
56
|
+
"@elementor/session": "4.3.0-1049",
|
|
57
57
|
"@elementor/ui": "1.37.5",
|
|
58
|
-
"@elementor/utils": "4.3.0-
|
|
59
|
-
"@elementor/wp-media": "4.3.0-
|
|
58
|
+
"@elementor/utils": "4.3.0-1049",
|
|
59
|
+
"@elementor/wp-media": "4.3.0-1049",
|
|
60
60
|
"@monaco-editor/react": "^4.7.0",
|
|
61
61
|
"@tiptap/extension-bold": "^3.11.1",
|
|
62
62
|
"@tiptap/extension-document": "^3.11.1",
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { type ComponentProps, useCallback
|
|
3
|
-
import {
|
|
2
|
+
import { type ComponentProps, useCallback } from 'react';
|
|
3
|
+
import { escapedHtmlPropTypeUtil } from '@elementor/editor-props';
|
|
4
4
|
import { Box, type SxProps, type Theme } from '@elementor/ui';
|
|
5
|
-
import { debounce } from '@elementor/utils';
|
|
6
5
|
|
|
7
|
-
import { useBoundProp } from '../bound-prop-context';
|
|
6
|
+
import { useBoundProp, usePropKeyContext } from '../bound-prop-context';
|
|
8
7
|
import { InlineEditor } from '../components/inline-editor';
|
|
9
8
|
import ControlActions from '../control-actions/control-actions';
|
|
10
9
|
import { createControl } from '../create-control';
|
|
11
|
-
|
|
12
|
-
const CHILDREN_PARSE_DEBOUNCE_MS = 300;
|
|
10
|
+
import { extractInlineHtmlContent } from '../utils/inline-editing';
|
|
13
11
|
|
|
14
12
|
export const InlineEditingControl = createControl(
|
|
15
13
|
( {
|
|
@@ -21,38 +19,19 @@ export const InlineEditingControl = createControl(
|
|
|
21
19
|
attributes?: Record< string, string >;
|
|
22
20
|
props?: ComponentProps< 'div' >;
|
|
23
21
|
} ) => {
|
|
24
|
-
const {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const debouncedParse = useMemo(
|
|
28
|
-
() =>
|
|
29
|
-
debounce( ( html: string ) => {
|
|
30
|
-
const parsed = parseHtmlChildren( html );
|
|
31
|
-
|
|
32
|
-
setValue( {
|
|
33
|
-
content: parsed.content ? stringPropTypeUtil.create( parsed.content ) : null,
|
|
34
|
-
children: parsed.children,
|
|
35
|
-
} );
|
|
36
|
-
}, CHILDREN_PARSE_DEBOUNCE_MS ),
|
|
37
|
-
[ setValue ]
|
|
38
|
-
);
|
|
22
|
+
const { setValue, placeholder, value } = useBoundProp( escapedHtmlPropTypeUtil );
|
|
23
|
+
const { value: rawValue } = usePropKeyContext();
|
|
24
|
+
const content = value ?? extractInlineHtmlContent( rawValue );
|
|
39
25
|
|
|
40
26
|
const handleChange = useCallback(
|
|
41
27
|
( newValue: unknown ) => {
|
|
42
28
|
const html = ( newValue ?? '' ) as string;
|
|
43
29
|
|
|
44
|
-
setValue(
|
|
45
|
-
content: html ? stringPropTypeUtil.create( html ) : null,
|
|
46
|
-
children: value?.children ?? [],
|
|
47
|
-
} );
|
|
48
|
-
|
|
49
|
-
debouncedParse( html );
|
|
30
|
+
setValue( html );
|
|
50
31
|
},
|
|
51
|
-
[ setValue
|
|
32
|
+
[ setValue ]
|
|
52
33
|
);
|
|
53
34
|
|
|
54
|
-
useEffect( () => () => debouncedParse.cancel(), [ debouncedParse ] );
|
|
55
|
-
|
|
56
35
|
return (
|
|
57
36
|
<ControlActions>
|
|
58
37
|
<Box
|
|
@@ -98,11 +77,7 @@ export const InlineEditingControl = createControl(
|
|
|
98
77
|
{ ...attributes }
|
|
99
78
|
{ ...props }
|
|
100
79
|
>
|
|
101
|
-
<InlineEditor
|
|
102
|
-
value={ content }
|
|
103
|
-
setValue={ handleChange }
|
|
104
|
-
placeholder={ placeholder?.content?.value ?? null }
|
|
105
|
-
/>
|
|
80
|
+
<InlineEditor value={ content } setValue={ handleChange } placeholder={ placeholder ?? null } />
|
|
106
81
|
</Box>
|
|
107
82
|
</ControlActions>
|
|
108
83
|
);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { escapedHtmlPropTypeUtil, htmlV3PropTypeUtil, stringPropTypeUtil } from '@elementor/editor-props';
|
|
2
|
+
|
|
1
3
|
export function isEmpty( value: string | null = '' ) {
|
|
2
4
|
if ( ! value ) {
|
|
3
5
|
return true;
|
|
@@ -20,3 +22,13 @@ export function htmlToPlainText( html: string | null ): string {
|
|
|
20
22
|
|
|
21
23
|
return doc.body.textContent ?? '';
|
|
22
24
|
}
|
|
25
|
+
|
|
26
|
+
export function extractInlineHtmlContent( propValue: unknown ): string {
|
|
27
|
+
if ( escapedHtmlPropTypeUtil.isValid( propValue ) ) {
|
|
28
|
+
return escapedHtmlPropTypeUtil.extract( propValue ) ?? '';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const htmlV3 = htmlV3PropTypeUtil.extract( propValue );
|
|
32
|
+
|
|
33
|
+
return stringPropTypeUtil.extract( htmlV3?.content ?? null ) ?? '';
|
|
34
|
+
}
|