@elementor/editor-ui 3.33.0-99 → 3.34.2
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.d.mts +57 -10
- package/dist/index.d.ts +57 -10
- package/dist/index.js +223 -76
- package/dist/index.mjs +227 -73
- package/package.json +4 -4
- package/src/components/form.tsx +30 -0
- package/src/components/global-dialog/__tests__/global-dialog.test.tsx +272 -0
- package/src/components/global-dialog/__tests__/subscribers.test.ts +90 -0
- package/src/components/global-dialog/components/global-dialog.tsx +30 -0
- package/src/components/global-dialog/index.ts +2 -0
- package/src/components/global-dialog/subscribers.ts +36 -0
- package/src/components/menu-item.tsx +20 -6
- package/src/components/popover/__tests__/menu-list.test.tsx +106 -0
- package/src/components/popover/body.tsx +3 -1
- package/src/components/popover/index.ts +0 -1
- package/src/components/popover/menu-list.tsx +25 -15
- package/src/components/save-changes-dialog.tsx +106 -0
- package/src/components/{popover/search.tsx → search-field.tsx} +6 -4
- package/src/components/warning-infotip.tsx +11 -2
- package/src/hooks/__tests__/use-editable.test.tsx +255 -0
- package/src/hooks/use-editable.ts +15 -4
- package/src/index.ts +5 -0
- package/src/hooks/__tests__/use-editable.test.ts +0 -209
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { act, renderHook } from '@testing-library/react';
|
|
2
|
-
|
|
3
|
-
import { useEditable } from '../use-editable';
|
|
4
|
-
|
|
5
|
-
describe( 'useEditable', () => {
|
|
6
|
-
it( 'should return editable content attributes and handlers', () => {
|
|
7
|
-
// Arrange & Act.
|
|
8
|
-
const { result } = renderHook( () =>
|
|
9
|
-
useEditable( {
|
|
10
|
-
value: '',
|
|
11
|
-
onSubmit: jest.fn(),
|
|
12
|
-
} )
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const props = result.current.getProps();
|
|
16
|
-
|
|
17
|
-
// Assert.
|
|
18
|
-
expect( props ).toEqual( {
|
|
19
|
-
value: '',
|
|
20
|
-
role: 'textbox',
|
|
21
|
-
contentEditable: false,
|
|
22
|
-
suppressContentEditableWarning: undefined,
|
|
23
|
-
onBlur: expect.any( Function ),
|
|
24
|
-
onClick: expect.any( Function ),
|
|
25
|
-
onInput: expect.any( Function ),
|
|
26
|
-
onKeyDown: expect.any( Function ),
|
|
27
|
-
} );
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
it( 'should set editable to true', () => {
|
|
31
|
-
// Arrange & Act.
|
|
32
|
-
const { result } = renderHook( () => useEditable( { value: '', onSubmit: jest.fn() } ) );
|
|
33
|
-
|
|
34
|
-
// Assert.
|
|
35
|
-
expect( result.current.isEditing ).toBe( false );
|
|
36
|
-
|
|
37
|
-
// Act.
|
|
38
|
-
act( result.current.openEditMode );
|
|
39
|
-
|
|
40
|
-
// Assert.
|
|
41
|
-
expect( result.current.isEditing ).toBe( true );
|
|
42
|
-
expect( result.current.getProps() ).toMatchObject( {
|
|
43
|
-
contentEditable: true,
|
|
44
|
-
suppressContentEditableWarning: true,
|
|
45
|
-
} );
|
|
46
|
-
} );
|
|
47
|
-
|
|
48
|
-
it( 'should call onSubmit with the new value on enter', async () => {
|
|
49
|
-
// Arrange.
|
|
50
|
-
const onSubmit = jest.fn();
|
|
51
|
-
const value = 'Some value';
|
|
52
|
-
const newValue = 'New value';
|
|
53
|
-
const validation = jest.fn();
|
|
54
|
-
|
|
55
|
-
// Act.
|
|
56
|
-
const { result } = renderHook( () =>
|
|
57
|
-
useEditable( {
|
|
58
|
-
value,
|
|
59
|
-
onSubmit,
|
|
60
|
-
validation,
|
|
61
|
-
} )
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
act( () => {
|
|
65
|
-
result.current.openEditMode();
|
|
66
|
-
result.current.getProps().onInput( { target: { innerText: newValue } } as never );
|
|
67
|
-
} );
|
|
68
|
-
|
|
69
|
-
// Assert.
|
|
70
|
-
expect( validation ).toHaveBeenCalledWith( newValue );
|
|
71
|
-
|
|
72
|
-
// Act.
|
|
73
|
-
const { onKeyDown } = result.current.getProps();
|
|
74
|
-
|
|
75
|
-
act( () => {
|
|
76
|
-
onKeyDown( {
|
|
77
|
-
key: 'Enter',
|
|
78
|
-
stopPropagation: jest.fn(),
|
|
79
|
-
preventDefault: jest.fn(),
|
|
80
|
-
target: { innerText: newValue },
|
|
81
|
-
} as never );
|
|
82
|
-
} );
|
|
83
|
-
|
|
84
|
-
expect( onSubmit ).toHaveBeenCalledWith( newValue );
|
|
85
|
-
} );
|
|
86
|
-
|
|
87
|
-
it( 'should remove the editable content attribute on blur', () => {
|
|
88
|
-
// Arrange
|
|
89
|
-
const { result } = renderHook( () =>
|
|
90
|
-
useEditable( {
|
|
91
|
-
value: '',
|
|
92
|
-
onSubmit: jest.fn(),
|
|
93
|
-
} )
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
// Act.
|
|
97
|
-
act( result.current.openEditMode );
|
|
98
|
-
|
|
99
|
-
// Assert.
|
|
100
|
-
expect( result.current.isEditing ).toBe( true );
|
|
101
|
-
|
|
102
|
-
// Act.
|
|
103
|
-
act( result.current.getProps().onBlur );
|
|
104
|
-
|
|
105
|
-
// Assert.
|
|
106
|
-
expect( result.current.isEditing ).toBe( false );
|
|
107
|
-
} );
|
|
108
|
-
|
|
109
|
-
it( 'should set error message id validation fails', () => {
|
|
110
|
-
// Arrange.
|
|
111
|
-
const newValue = 'invalid-value';
|
|
112
|
-
const value = 'Some value';
|
|
113
|
-
const onSubmit = jest.fn();
|
|
114
|
-
|
|
115
|
-
const validation = ( v: string ) => {
|
|
116
|
-
if ( v === newValue ) {
|
|
117
|
-
return 'Nope';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return null;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const { result } = renderHook( () =>
|
|
124
|
-
useEditable( {
|
|
125
|
-
value,
|
|
126
|
-
onSubmit,
|
|
127
|
-
validation,
|
|
128
|
-
} )
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
// Act.
|
|
132
|
-
act( result.current.openEditMode );
|
|
133
|
-
|
|
134
|
-
// Assert.
|
|
135
|
-
expect( result.current.error ).toBeNull();
|
|
136
|
-
|
|
137
|
-
// Act.
|
|
138
|
-
act( () => {
|
|
139
|
-
result.current.getProps().onInput( { target: { innerText: newValue } } as never );
|
|
140
|
-
} );
|
|
141
|
-
|
|
142
|
-
// Assert.
|
|
143
|
-
expect( result.current.error ).toBe( 'Nope' );
|
|
144
|
-
|
|
145
|
-
// Act.
|
|
146
|
-
act( () => {
|
|
147
|
-
result.current.getProps().onKeyDown( {
|
|
148
|
-
key: 'Enter',
|
|
149
|
-
stopPropagation: jest.fn(),
|
|
150
|
-
preventDefault: jest.fn(),
|
|
151
|
-
target: { innerText: newValue },
|
|
152
|
-
} as never );
|
|
153
|
-
} );
|
|
154
|
-
|
|
155
|
-
// Assert.
|
|
156
|
-
expect( onSubmit ).not.toHaveBeenCalled();
|
|
157
|
-
} );
|
|
158
|
-
|
|
159
|
-
it( 'should not run validation & submit if the value has not changed', () => {
|
|
160
|
-
// Arrange.
|
|
161
|
-
const value = 'initial value';
|
|
162
|
-
const onSubmit = jest.fn();
|
|
163
|
-
|
|
164
|
-
const validation = () => {
|
|
165
|
-
return 'test-error';
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const { result } = renderHook( () =>
|
|
169
|
-
useEditable( {
|
|
170
|
-
value,
|
|
171
|
-
onSubmit,
|
|
172
|
-
validation,
|
|
173
|
-
} )
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
// Act.
|
|
177
|
-
act( result.current.openEditMode );
|
|
178
|
-
|
|
179
|
-
// Assert.
|
|
180
|
-
expect( result.current.error ).toBeNull();
|
|
181
|
-
|
|
182
|
-
// Act.
|
|
183
|
-
act( () => {
|
|
184
|
-
result.current.getProps().onInput( { target: { innerText: 'new value' } } as never );
|
|
185
|
-
} );
|
|
186
|
-
|
|
187
|
-
// Assert.
|
|
188
|
-
expect( result.current.error ).toBe( 'test-error' );
|
|
189
|
-
|
|
190
|
-
act( () => {
|
|
191
|
-
result.current.getProps().onInput( { target: { innerText: value } } as never );
|
|
192
|
-
} );
|
|
193
|
-
|
|
194
|
-
expect( result.current.error ).toBe( null );
|
|
195
|
-
|
|
196
|
-
// Act.
|
|
197
|
-
act( () => {
|
|
198
|
-
result.current.getProps().onKeyDown( {
|
|
199
|
-
key: 'Enter',
|
|
200
|
-
stopPropagation: jest.fn(),
|
|
201
|
-
preventDefault: jest.fn(),
|
|
202
|
-
target: { innerText: value },
|
|
203
|
-
} as never );
|
|
204
|
-
} );
|
|
205
|
-
|
|
206
|
-
// Assert.
|
|
207
|
-
expect( onSubmit ).not.toHaveBeenCalled();
|
|
208
|
-
} );
|
|
209
|
-
} );
|