@elementor/editor-styles-repository 4.4.0-1089 → 4.4.0-1091
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
CHANGED
|
@@ -197,7 +197,25 @@ var documentElementsStylesProvider = createStylesProvider({
|
|
|
197
197
|
},
|
|
198
198
|
priority: 50,
|
|
199
199
|
isPregeneratedLink: ({ id }) => PREGENERATED_LINK_PATTERN.test(id),
|
|
200
|
-
subscribe: (cb) =>
|
|
200
|
+
subscribe: (cb) => {
|
|
201
|
+
let scheduledFrame = null;
|
|
202
|
+
const unsubscribe = (0, import_editor_v1_adapters.__privateListenTo)(import_editor_elements.styleRerenderEvents, () => {
|
|
203
|
+
if (scheduledFrame !== null) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
scheduledFrame = requestAnimationFrame(() => {
|
|
207
|
+
scheduledFrame = null;
|
|
208
|
+
cb();
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
return () => {
|
|
212
|
+
if (scheduledFrame !== null) {
|
|
213
|
+
cancelAnimationFrame(scheduledFrame);
|
|
214
|
+
scheduledFrame = null;
|
|
215
|
+
}
|
|
216
|
+
unsubscribe();
|
|
217
|
+
};
|
|
218
|
+
},
|
|
201
219
|
actions: {
|
|
202
220
|
all: (meta = {}) => {
|
|
203
221
|
let elements = (0, import_editor_elements.getElements)();
|
package/dist/index.mjs
CHANGED
|
@@ -167,7 +167,25 @@ var documentElementsStylesProvider = createStylesProvider({
|
|
|
167
167
|
},
|
|
168
168
|
priority: 50,
|
|
169
169
|
isPregeneratedLink: ({ id }) => PREGENERATED_LINK_PATTERN.test(id),
|
|
170
|
-
subscribe: (cb) =>
|
|
170
|
+
subscribe: (cb) => {
|
|
171
|
+
let scheduledFrame = null;
|
|
172
|
+
const unsubscribe = listenTo(styleRerenderEvents, () => {
|
|
173
|
+
if (scheduledFrame !== null) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
scheduledFrame = requestAnimationFrame(() => {
|
|
177
|
+
scheduledFrame = null;
|
|
178
|
+
cb();
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
return () => {
|
|
182
|
+
if (scheduledFrame !== null) {
|
|
183
|
+
cancelAnimationFrame(scheduledFrame);
|
|
184
|
+
scheduledFrame = null;
|
|
185
|
+
}
|
|
186
|
+
unsubscribe();
|
|
187
|
+
};
|
|
188
|
+
},
|
|
171
189
|
actions: {
|
|
172
190
|
all: (meta = {}) => {
|
|
173
191
|
let elements = getElements();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-styles-repository",
|
|
3
3
|
"description": "Elementor Editor Styles Repository",
|
|
4
|
-
"version": "4.4.0-
|
|
4
|
+
"version": "4.4.0-1091",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@elementor/editor-current-user": "4.4.0-
|
|
37
|
-
"@elementor/editor-elements": "4.4.0-
|
|
38
|
-
"@elementor/editor-props": "4.4.0-
|
|
39
|
-
"@elementor/editor-styles": "4.4.0-
|
|
40
|
-
"@elementor/editor-v1-adapters": "4.4.0-
|
|
41
|
-
"@elementor/schema": "4.4.0-
|
|
42
|
-
"@elementor/utils": "4.4.0-
|
|
36
|
+
"@elementor/editor-current-user": "4.4.0-1091",
|
|
37
|
+
"@elementor/editor-elements": "4.4.0-1091",
|
|
38
|
+
"@elementor/editor-props": "4.4.0-1091",
|
|
39
|
+
"@elementor/editor-styles": "4.4.0-1091",
|
|
40
|
+
"@elementor/editor-v1-adapters": "4.4.0-1091",
|
|
41
|
+
"@elementor/schema": "4.4.0-1091",
|
|
42
|
+
"@elementor/utils": "4.4.0-1091",
|
|
43
43
|
"@wordpress/i18n": "^5.13.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { createMockElement, createMockStyleDefinition } from 'test-utils';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ELEMENT_STYLE_CHANGE_EVENT,
|
|
4
|
+
getCurrentDocumentId,
|
|
5
|
+
getElements,
|
|
6
|
+
getElementStyles,
|
|
7
|
+
updateElementStyle,
|
|
8
|
+
} from '@elementor/editor-elements';
|
|
3
9
|
import type { StyleDefinition } from '@elementor/editor-styles';
|
|
10
|
+
import { __privateListenTo as listenTo } from '@elementor/editor-v1-adapters';
|
|
4
11
|
|
|
5
12
|
import { InvalidElementsStyleProviderMetaError } from '../errors';
|
|
6
13
|
import { documentElementsStylesProvider } from '../providers/document-elements-styles-provider';
|
|
7
14
|
|
|
8
15
|
jest.mock( '@elementor/editor-elements' );
|
|
9
16
|
|
|
17
|
+
jest.mock( '@elementor/editor-v1-adapters', () => ( {
|
|
18
|
+
...jest.requireActual( '@elementor/editor-v1-adapters' ),
|
|
19
|
+
__privateListenTo: jest.fn(),
|
|
20
|
+
} ) );
|
|
21
|
+
|
|
10
22
|
describe( 'documentElementsStylesProvider', () => {
|
|
11
23
|
beforeEach( () => {
|
|
12
24
|
jest.mocked( getElements ).mockReturnValue( [
|
|
@@ -155,4 +167,94 @@ describe( 'documentElementsStylesProvider', () => {
|
|
|
155
167
|
)
|
|
156
168
|
).toThrow( new InvalidElementsStyleProviderMetaError() );
|
|
157
169
|
} );
|
|
170
|
+
|
|
171
|
+
describe( 'subscribe', () => {
|
|
172
|
+
const setupListener = () => {
|
|
173
|
+
const unsubscribeFromEvents = jest.fn();
|
|
174
|
+
let emit = () => {};
|
|
175
|
+
|
|
176
|
+
jest.mocked( listenTo ).mockImplementation( ( _events, callback ) => {
|
|
177
|
+
emit = () =>
|
|
178
|
+
callback( {
|
|
179
|
+
type: 'window-event',
|
|
180
|
+
event: ELEMENT_STYLE_CHANGE_EVENT,
|
|
181
|
+
originalEvent: new CustomEvent( ELEMENT_STYLE_CHANGE_EVENT ),
|
|
182
|
+
} );
|
|
183
|
+
|
|
184
|
+
return unsubscribeFromEvents;
|
|
185
|
+
} );
|
|
186
|
+
|
|
187
|
+
const frames: FrameRequestCallback[] = [];
|
|
188
|
+
|
|
189
|
+
jest.spyOn( window, 'requestAnimationFrame' ).mockImplementation( ( frame: FrameRequestCallback ) => {
|
|
190
|
+
frames.push( frame );
|
|
191
|
+
|
|
192
|
+
return frames.length;
|
|
193
|
+
} );
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
emitStyleRerenderEvent: () => emit(),
|
|
197
|
+
runFrame: ( index: number ) => frames[ index ]( 0 ),
|
|
198
|
+
frames: () => frames,
|
|
199
|
+
unsubscribeFromEvents,
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
it( 'should notify subscribers once per frame regardless of the number of events', () => {
|
|
204
|
+
// Arrange.
|
|
205
|
+
const listener = setupListener();
|
|
206
|
+
const subscriber = jest.fn();
|
|
207
|
+
|
|
208
|
+
documentElementsStylesProvider.subscribe( subscriber );
|
|
209
|
+
|
|
210
|
+
// Act.
|
|
211
|
+
listener.emitStyleRerenderEvent();
|
|
212
|
+
listener.emitStyleRerenderEvent();
|
|
213
|
+
listener.emitStyleRerenderEvent();
|
|
214
|
+
|
|
215
|
+
// Assert.
|
|
216
|
+
expect( listener.frames() ).toHaveLength( 1 );
|
|
217
|
+
expect( subscriber ).not.toHaveBeenCalled();
|
|
218
|
+
|
|
219
|
+
// Act.
|
|
220
|
+
listener.runFrame( 0 );
|
|
221
|
+
|
|
222
|
+
// Assert.
|
|
223
|
+
expect( subscriber ).toHaveBeenCalledTimes( 1 );
|
|
224
|
+
} );
|
|
225
|
+
|
|
226
|
+
it( 'should schedule a new frame after the pending one ran', () => {
|
|
227
|
+
// Arrange.
|
|
228
|
+
const listener = setupListener();
|
|
229
|
+
const subscriber = jest.fn();
|
|
230
|
+
|
|
231
|
+
documentElementsStylesProvider.subscribe( subscriber );
|
|
232
|
+
|
|
233
|
+
// Act.
|
|
234
|
+
listener.emitStyleRerenderEvent();
|
|
235
|
+
listener.runFrame( 0 );
|
|
236
|
+
listener.emitStyleRerenderEvent();
|
|
237
|
+
listener.runFrame( 1 );
|
|
238
|
+
|
|
239
|
+
// Assert.
|
|
240
|
+
expect( subscriber ).toHaveBeenCalledTimes( 2 );
|
|
241
|
+
} );
|
|
242
|
+
|
|
243
|
+
it( 'should cancel a pending frame when unsubscribing', () => {
|
|
244
|
+
// Arrange.
|
|
245
|
+
const listener = setupListener();
|
|
246
|
+
const subscriber = jest.fn();
|
|
247
|
+
const cancelAnimationFrameSpy = jest.spyOn( window, 'cancelAnimationFrame' ).mockImplementation();
|
|
248
|
+
|
|
249
|
+
const unsubscribe = documentElementsStylesProvider.subscribe( subscriber );
|
|
250
|
+
|
|
251
|
+
// Act.
|
|
252
|
+
listener.emitStyleRerenderEvent();
|
|
253
|
+
unsubscribe();
|
|
254
|
+
|
|
255
|
+
// Assert.
|
|
256
|
+
expect( cancelAnimationFrameSpy ).toHaveBeenCalledTimes( 1 );
|
|
257
|
+
expect( listener.unsubscribeFromEvents ).toHaveBeenCalledTimes( 1 );
|
|
258
|
+
} );
|
|
259
|
+
} );
|
|
158
260
|
} );
|
|
@@ -30,7 +30,29 @@ export const documentElementsStylesProvider = createStylesProvider( {
|
|
|
30
30
|
},
|
|
31
31
|
priority: 50,
|
|
32
32
|
isPregeneratedLink: ( { id } ) => PREGENERATED_LINK_PATTERN.test( id ),
|
|
33
|
-
subscribe: ( cb ) =>
|
|
33
|
+
subscribe: ( cb ) => {
|
|
34
|
+
let scheduledFrame: number | null = null;
|
|
35
|
+
|
|
36
|
+
const unsubscribe = listenTo( styleRerenderEvents, () => {
|
|
37
|
+
if ( scheduledFrame !== null ) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
scheduledFrame = requestAnimationFrame( () => {
|
|
42
|
+
scheduledFrame = null;
|
|
43
|
+
cb();
|
|
44
|
+
} );
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
return () => {
|
|
48
|
+
if ( scheduledFrame !== null ) {
|
|
49
|
+
cancelAnimationFrame( scheduledFrame );
|
|
50
|
+
scheduledFrame = null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
unsubscribe();
|
|
54
|
+
};
|
|
55
|
+
},
|
|
34
56
|
actions: {
|
|
35
57
|
all: ( meta = {} ) => {
|
|
36
58
|
let elements = getElements();
|