@elementor/locations 0.6.2 → 0.6.3
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/CHANGELOG.md +8 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/package.json +2 -2
- package/src/__tests__/index.test.tsx +24 -24
- package/src/types.ts +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.6.3](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.6.2...@elementor/locations@0.6.3) (2023-08-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @elementor/locations
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [0.6.2](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.6.1...@elementor/locations@0.6.2) (2023-07-17)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @elementor/locations
|
package/dist/index.d.mts
CHANGED
|
@@ -5,20 +5,48 @@ type InjectedComponent<TProps extends object = AnyProps> = ComponentType<TProps>
|
|
|
5
5
|
type Id = string;
|
|
6
6
|
type Priority = number;
|
|
7
7
|
type Injection<TProps extends object = AnyProps> = {
|
|
8
|
+
/**
|
|
9
|
+
* A unique id (per location) of the injected component.
|
|
10
|
+
*/
|
|
8
11
|
id: Id;
|
|
12
|
+
/**
|
|
13
|
+
* The injected component.
|
|
14
|
+
*/
|
|
9
15
|
component: InjectedComponent<TProps>;
|
|
16
|
+
/**
|
|
17
|
+
* Priority of the injected component inside the location. Lower value means higher priority.
|
|
18
|
+
*/
|
|
10
19
|
priority: Priority;
|
|
11
20
|
};
|
|
12
21
|
type InjectArgs<TProps extends object = AnyProps> = {
|
|
22
|
+
/**
|
|
23
|
+
* A unique id (per location) of the component to be injected.
|
|
24
|
+
*/
|
|
13
25
|
id: Id;
|
|
26
|
+
/**
|
|
27
|
+
* The component to be injected.
|
|
28
|
+
*/
|
|
14
29
|
component: InjectedComponent<TProps>;
|
|
15
30
|
options?: {
|
|
31
|
+
/**
|
|
32
|
+
* Priority of the injected component inside the location. Lower value means higher priority.
|
|
33
|
+
*/
|
|
16
34
|
priority?: Priority;
|
|
35
|
+
/**
|
|
36
|
+
* When true, if an injected component with the same id already exists it will be overridden with this one. Otherwise, this injection will be ignored. Default is false.
|
|
37
|
+
*/
|
|
17
38
|
overwrite?: boolean;
|
|
18
39
|
};
|
|
19
40
|
};
|
|
20
41
|
type Location<TProps extends object = AnyProps> = {
|
|
42
|
+
/**
|
|
43
|
+
* Inject a component into the location.
|
|
44
|
+
*/
|
|
21
45
|
inject: (args: InjectArgs<TProps>) => void;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @return All the injections in the location.
|
|
49
|
+
*/
|
|
22
50
|
getInjections: () => Injection<TProps>[];
|
|
23
51
|
useInjections: () => Injection<TProps>[];
|
|
24
52
|
Slot: ComponentType<TProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,20 +5,48 @@ type InjectedComponent<TProps extends object = AnyProps> = ComponentType<TProps>
|
|
|
5
5
|
type Id = string;
|
|
6
6
|
type Priority = number;
|
|
7
7
|
type Injection<TProps extends object = AnyProps> = {
|
|
8
|
+
/**
|
|
9
|
+
* A unique id (per location) of the injected component.
|
|
10
|
+
*/
|
|
8
11
|
id: Id;
|
|
12
|
+
/**
|
|
13
|
+
* The injected component.
|
|
14
|
+
*/
|
|
9
15
|
component: InjectedComponent<TProps>;
|
|
16
|
+
/**
|
|
17
|
+
* Priority of the injected component inside the location. Lower value means higher priority.
|
|
18
|
+
*/
|
|
10
19
|
priority: Priority;
|
|
11
20
|
};
|
|
12
21
|
type InjectArgs<TProps extends object = AnyProps> = {
|
|
22
|
+
/**
|
|
23
|
+
* A unique id (per location) of the component to be injected.
|
|
24
|
+
*/
|
|
13
25
|
id: Id;
|
|
26
|
+
/**
|
|
27
|
+
* The component to be injected.
|
|
28
|
+
*/
|
|
14
29
|
component: InjectedComponent<TProps>;
|
|
15
30
|
options?: {
|
|
31
|
+
/**
|
|
32
|
+
* Priority of the injected component inside the location. Lower value means higher priority.
|
|
33
|
+
*/
|
|
16
34
|
priority?: Priority;
|
|
35
|
+
/**
|
|
36
|
+
* When true, if an injected component with the same id already exists it will be overridden with this one. Otherwise, this injection will be ignored. Default is false.
|
|
37
|
+
*/
|
|
17
38
|
overwrite?: boolean;
|
|
18
39
|
};
|
|
19
40
|
};
|
|
20
41
|
type Location<TProps extends object = AnyProps> = {
|
|
42
|
+
/**
|
|
43
|
+
* Inject a component into the location.
|
|
44
|
+
*/
|
|
21
45
|
inject: (args: InjectArgs<TProps>) => void;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @return All the injections in the location.
|
|
49
|
+
*/
|
|
22
50
|
getInjections: () => Injection<TProps>[];
|
|
23
51
|
useInjections: () => Injection<TProps>[];
|
|
24
52
|
Slot: ComponentType<TProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/locations",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "18.x"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "43abed846a5beaf6b0c6c5a8420c81a5bea33152"
|
|
38
38
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { lazy } from 'react';
|
|
4
4
|
import { createLocation } from '../api';
|
|
5
5
|
|
|
@@ -25,10 +25,10 @@ describe( '@elementor/locations', () => {
|
|
|
25
25
|
} );
|
|
26
26
|
|
|
27
27
|
// Act.
|
|
28
|
-
|
|
28
|
+
render( <TestSlot /> );
|
|
29
29
|
|
|
30
30
|
// Assert.
|
|
31
|
-
const elements = getAllByTestId( 'element' );
|
|
31
|
+
const elements = screen.getAllByTestId( 'element' );
|
|
32
32
|
|
|
33
33
|
expect( elements ).toHaveLength( 2 );
|
|
34
34
|
expect( elements[ 0 ].innerHTML ).toBe( 'First div' );
|
|
@@ -58,10 +58,10 @@ describe( '@elementor/locations', () => {
|
|
|
58
58
|
} );
|
|
59
59
|
|
|
60
60
|
// Act.
|
|
61
|
-
|
|
61
|
+
render( <Slot /> );
|
|
62
62
|
|
|
63
63
|
// Assert.
|
|
64
|
-
const elements = getAllByTestId( 'element' );
|
|
64
|
+
const elements = screen.getAllByTestId( 'element' );
|
|
65
65
|
|
|
66
66
|
expect( elements ).toHaveLength( 3 );
|
|
67
67
|
expect( elements[ 0 ].innerHTML ).toBe( 'First div' );
|
|
@@ -77,7 +77,7 @@ describe( '@elementor/locations', () => {
|
|
|
77
77
|
const { container } = render( <Slot /> );
|
|
78
78
|
|
|
79
79
|
// Assert.
|
|
80
|
-
expect( container
|
|
80
|
+
expect( container ).toBeEmptyDOMElement( );
|
|
81
81
|
} );
|
|
82
82
|
|
|
83
83
|
it( 'should render lazy components', async () => {
|
|
@@ -97,17 +97,17 @@ describe( '@elementor/locations', () => {
|
|
|
97
97
|
} );
|
|
98
98
|
|
|
99
99
|
// Act.
|
|
100
|
-
|
|
100
|
+
render( <Slot /> );
|
|
101
101
|
|
|
102
102
|
// Assert.
|
|
103
|
-
expect(
|
|
104
|
-
expect( queryByText( 'Second div' ) ).
|
|
103
|
+
expect( screen.getByText( 'First div' ) ).toBeInTheDocument();
|
|
104
|
+
expect( screen.queryByText( 'Second div' ) ).not.toBeInTheDocument();
|
|
105
105
|
|
|
106
106
|
// Waits for the lazy component to be loaded.
|
|
107
|
-
await findByText( 'Second div' );
|
|
107
|
+
await screen.findByText( 'Second div' );
|
|
108
108
|
|
|
109
|
-
expect(
|
|
110
|
-
expect(
|
|
109
|
+
expect( screen.getByText( 'First div' ) ).toBeInTheDocument();
|
|
110
|
+
expect( screen.getByText( 'Second div' ) ).toBeInTheDocument();
|
|
111
111
|
} );
|
|
112
112
|
|
|
113
113
|
it( 'should error when injecting a component with the same name (without overwrite option)', async () => {
|
|
@@ -125,11 +125,11 @@ describe( '@elementor/locations', () => {
|
|
|
125
125
|
} );
|
|
126
126
|
|
|
127
127
|
// Act
|
|
128
|
-
|
|
128
|
+
render( <Slot /> );
|
|
129
129
|
|
|
130
130
|
// Assert.
|
|
131
|
-
expect(
|
|
132
|
-
expect( queryByText( 'Second div' ) ).
|
|
131
|
+
expect( screen.getByText( 'First div' ) ).toBeInTheDocument();
|
|
132
|
+
expect( screen.queryByText( 'Second div' ) ).not.toBeInTheDocument();
|
|
133
133
|
expect( console ).toHaveWarned();
|
|
134
134
|
} );
|
|
135
135
|
|
|
@@ -155,12 +155,12 @@ describe( '@elementor/locations', () => {
|
|
|
155
155
|
} );
|
|
156
156
|
|
|
157
157
|
// Act
|
|
158
|
-
|
|
158
|
+
render( <Slot /> );
|
|
159
159
|
|
|
160
160
|
// Assert.
|
|
161
|
-
expect( queryByText( 'First div' ) ).
|
|
162
|
-
expect(
|
|
163
|
-
expect(
|
|
161
|
+
expect( screen.queryByText( 'First div' ) ).not.toBeInTheDocument();
|
|
162
|
+
expect( screen.getByText( 'Second div' ) ).toBeInTheDocument();
|
|
163
|
+
expect( screen.getByText( 'Third div' ) ).toBeInTheDocument();
|
|
164
164
|
} );
|
|
165
165
|
|
|
166
166
|
it( 'should overwrite the injection priority', () => {
|
|
@@ -206,11 +206,11 @@ describe( '@elementor/locations', () => {
|
|
|
206
206
|
} );
|
|
207
207
|
|
|
208
208
|
// Act.
|
|
209
|
-
|
|
209
|
+
render( <Slot /> );
|
|
210
210
|
|
|
211
211
|
// Assert.
|
|
212
|
-
expect(
|
|
213
|
-
expect(
|
|
212
|
+
expect( screen.getByText( 'Test 1' ) ).toBeInTheDocument();
|
|
213
|
+
expect( screen.getByText( 'Test 3' ) ).toBeInTheDocument();
|
|
214
214
|
expect( console ).toHaveErrored();
|
|
215
215
|
} );
|
|
216
216
|
|
|
@@ -224,9 +224,9 @@ describe( '@elementor/locations', () => {
|
|
|
224
224
|
} );
|
|
225
225
|
|
|
226
226
|
// Act.
|
|
227
|
-
|
|
227
|
+
render( <Slot text="The number is" number={ 1 } /> );
|
|
228
228
|
|
|
229
229
|
// Assert.
|
|
230
|
-
expect(
|
|
230
|
+
expect( screen.getByText( 'The number is: 1' ) ).toBeInTheDocument();
|
|
231
231
|
} );
|
|
232
232
|
} );
|
package/src/types.ts
CHANGED
|
@@ -8,22 +8,51 @@ export type Id = string;
|
|
|
8
8
|
export type Priority = number;
|
|
9
9
|
|
|
10
10
|
export type Injection<TProps extends object = AnyProps> = {
|
|
11
|
+
/**
|
|
12
|
+
* A unique id (per location) of the injected component.
|
|
13
|
+
*/
|
|
11
14
|
id: Id;
|
|
15
|
+
/**
|
|
16
|
+
* The injected component.
|
|
17
|
+
*/
|
|
12
18
|
component: InjectedComponent<TProps>;
|
|
19
|
+
/**
|
|
20
|
+
* Priority of the injected component inside the location. Lower value means higher priority.
|
|
21
|
+
*/
|
|
13
22
|
priority: Priority;
|
|
14
23
|
}
|
|
15
24
|
|
|
16
25
|
export type InjectArgs<TProps extends object = AnyProps> = {
|
|
26
|
+
/**
|
|
27
|
+
* A unique id (per location) of the component to be injected.
|
|
28
|
+
*/
|
|
17
29
|
id: Id;
|
|
30
|
+
/**
|
|
31
|
+
* The component to be injected.
|
|
32
|
+
*/
|
|
18
33
|
component: InjectedComponent<TProps>;
|
|
34
|
+
|
|
19
35
|
options?: {
|
|
36
|
+
/**
|
|
37
|
+
* Priority of the injected component inside the location. Lower value means higher priority.
|
|
38
|
+
*/
|
|
20
39
|
priority?: Priority;
|
|
40
|
+
/**
|
|
41
|
+
* When true, if an injected component with the same id already exists it will be overridden with this one. Otherwise, this injection will be ignored. Default is false.
|
|
42
|
+
*/
|
|
21
43
|
overwrite?: boolean;
|
|
22
44
|
};
|
|
23
45
|
}
|
|
24
46
|
|
|
25
47
|
export type Location<TProps extends object = AnyProps> = {
|
|
48
|
+
/**
|
|
49
|
+
* Inject a component into the location.
|
|
50
|
+
*/
|
|
26
51
|
inject: ( args: InjectArgs<TProps> ) => void;
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @return All the injections in the location.
|
|
55
|
+
*/
|
|
27
56
|
getInjections: () => Injection<TProps>[];
|
|
28
57
|
useInjections: () => Injection<TProps>[];
|
|
29
58
|
Slot: ComponentType<TProps>;
|