@elementor/editor-canvas 3.35.0-358 → 3.35.0-360

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.
@@ -1,199 +0,0 @@
1
- import * as React from 'react';
2
- import { createRoot, type Root } from 'react-dom/client';
3
- import { InlineEditor } from '@elementor/editor-controls';
4
- import { getElementType } from '@elementor/editor-elements';
5
- import {
6
- htmlPropTypeUtil,
7
- stringPropTypeUtil,
8
- type StringPropValue,
9
- type TransformablePropValue,
10
- } from '@elementor/editor-props';
11
- import { ThemeProvider } from '@elementor/editor-ui';
12
-
13
- import {
14
- getBlockedValue,
15
- getHtmlPropType,
16
- getInitialPopoverPosition,
17
- getInlineEditablePropertyName,
18
- getWidgetType,
19
- legacyWindow,
20
- } from '../utils/inline-editing-utils';
21
- import { type CreateTemplatedElementTypeOptions, createTemplatedElementView } from './create-templated-element-type';
22
- import { type ElementType, type ElementView } from './types';
23
-
24
- export function createInlineEditingElementType( {
25
- type,
26
- renderer,
27
- element,
28
- }: CreateTemplatedElementTypeOptions ): typeof ElementType {
29
- return class extends legacyWindow.elementor.modules.elements.types.Widget {
30
- getType() {
31
- return type;
32
- }
33
-
34
- getView() {
35
- return createInlineEditingElementView( {
36
- type,
37
- renderer,
38
- element,
39
- } );
40
- }
41
- };
42
- }
43
-
44
- export function createInlineEditingElementView( {
45
- type,
46
- renderer,
47
- element,
48
- }: CreateTemplatedElementTypeOptions ): typeof ElementView {
49
- const TemplatedView = createTemplatedElementView( { type, renderer, element } );
50
-
51
- Object.entries( element.twig_templates ).forEach( ( [ key, template ] ) => {
52
- renderer.register( key, template );
53
- } );
54
-
55
- return class extends TemplatedView {
56
- inlineEditorRoot: Root | null = null;
57
- handlerAttached = false;
58
-
59
- render() {
60
- if ( this.inlineEditorRoot ) {
61
- this.resetInlineEditorRoot();
62
- }
63
-
64
- if ( ! this.isValueDynamic() && ! this.handlerAttached ) {
65
- this.$el.on( 'dblclick', '*', this.handleRenderInlineEditor.bind( this ) );
66
- this.handlerAttached = true;
67
- }
68
-
69
- TemplatedView.prototype.render.apply( this );
70
- }
71
-
72
- handleRenderInlineEditor( event: Event ) {
73
- event.stopPropagation();
74
- this.$el.off( 'dblclick', '*' );
75
- this.handlerAttached = false;
76
-
77
- if ( ! this.isValueDynamic() ) {
78
- this.renderInlineEditor();
79
- }
80
- }
81
-
82
- handleUnmountInlineEditor( event: Event ) {
83
- event.stopPropagation();
84
- this.unmountInlineEditor();
85
- }
86
-
87
- onDestroy( ...args: unknown[] ) {
88
- this.resetInlineEditorRoot();
89
- TemplatedView.prototype.onDestroy.apply( this, args );
90
- }
91
-
92
- resetInlineEditorRoot() {
93
- this.$el.off( 'dblclick', '*' );
94
- this.handlerAttached = false;
95
- this.inlineEditorRoot?.unmount?.();
96
- this.inlineEditorRoot = null;
97
- }
98
-
99
- unmountInlineEditor() {
100
- this.resetInlineEditorRoot();
101
- this.render();
102
- }
103
-
104
- isValueDynamic() {
105
- const settingKey = getInlineEditablePropertyName( this.container );
106
- const propValue = this.model.get( 'settings' )?.get( settingKey ) as TransformablePropValue< string >;
107
-
108
- return propValue?.$$type === 'dynamic';
109
- }
110
-
111
- getContentValue() {
112
- const prop = getHtmlPropType( this.container );
113
- const defaultValue = ( prop?.default as StringPropValue | null )?.value ?? '';
114
- const settingKey = getInlineEditablePropertyName( this.container );
115
-
116
- return (
117
- htmlPropTypeUtil.extract( this.model.get( 'settings' )?.get( settingKey ) ?? null ) ??
118
- htmlPropTypeUtil.extract( prop?.default ?? null ) ??
119
- defaultValue ??
120
- ''
121
- );
122
- }
123
-
124
- setContentValue( value: string | null ) {
125
- const settingKey = getInlineEditablePropertyName( this.container );
126
- const valueToSave = value ? htmlPropTypeUtil.create( value ) : null;
127
-
128
- this.model.get( 'settings' )?.set( settingKey, valueToSave );
129
- }
130
-
131
- getExpectedTag() {
132
- const widgetType = getWidgetType( this.container );
133
-
134
- if ( ! widgetType ) {
135
- return null;
136
- }
137
-
138
- const propsSchema = getElementType( widgetType )?.propsSchema;
139
-
140
- if ( ! propsSchema?.tag ) {
141
- return null;
142
- }
143
-
144
- return (
145
- stringPropTypeUtil.extract( this.model.get( 'settings' ).get( 'tag' ) ?? null ) ??
146
- stringPropTypeUtil.extract( propsSchema.tag.default ?? null ) ??
147
- null
148
- );
149
- }
150
-
151
- ensureProperValue() {
152
- const actualValue = this.getContentValue();
153
- const tagSettings = this.getExpectedTag();
154
- const wrappedValue = getBlockedValue( actualValue, tagSettings );
155
-
156
- if ( actualValue !== wrappedValue ) {
157
- this.setContentValue( wrappedValue );
158
- }
159
- }
160
-
161
- renderInlineEditor() {
162
- this.ensureProperValue();
163
-
164
- const propValue = this.getContentValue();
165
- const settingKey = getInlineEditablePropertyName( this.container );
166
- const classes = ( this.el?.children?.[ 0 ]?.classList.toString() ?? '' ) + ' strip-styles';
167
- const expectedTag = this.getExpectedTag();
168
-
169
- const setValue = ( value: string | null ) => {
170
- const valueToSave = value ? htmlPropTypeUtil.create( value ) : null;
171
-
172
- this.model.get( 'settings' )?.set( settingKey, valueToSave );
173
- };
174
-
175
- this.$el.html( '' );
176
-
177
- if ( this.inlineEditorRoot ) {
178
- this.resetInlineEditorRoot();
179
- }
180
-
181
- this.inlineEditorRoot = createRoot( this.el );
182
-
183
- this.inlineEditorRoot.render(
184
- <ThemeProvider>
185
- <InlineEditor
186
- attributes={ { class: classes } }
187
- value={ propValue }
188
- setValue={ setValue }
189
- onBlur={ this.handleUnmountInlineEditor.bind( this ) }
190
- autofocus
191
- showToolbar
192
- getInitialPopoverPosition={ getInitialPopoverPosition }
193
- expectedTag={ expectedTag }
194
- />
195
- </ThemeProvider>
196
- );
197
- }
198
- };
199
- }