@elementor/locations 0.6.2 → 0.7.0
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 +19 -0
- package/README.md +1 -2
- package/dist/index.d.mts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
- package/src/__tests__/index.test.tsx +24 -24
- package/src/index.ts +5 -1
- package/src/types.ts +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
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.7.0](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.6.3...@elementor/locations@0.7.0) (2023-09-11)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **locations:** mark experimental functions [ED-12077] ([#116](https://github.com/elementor/elementor-packages/issues/116)) ([47d72cd](https://github.com/elementor/elementor-packages/commit/47d72cd464e6164860c5f14a92b0264058da053c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.6.3](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.6.2...@elementor/locations@0.6.3) (2023-08-02)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @elementor/locations
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.6.2](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.6.1...@elementor/locations@0.6.2) (2023-07-17)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @elementor/locations
|
package/README.md
CHANGED
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>;
|
|
@@ -27,4 +55,4 @@ type Location<TProps extends object = AnyProps> = {
|
|
|
27
55
|
declare function createLocation<TProps extends object = AnyProps>(): Location<TProps>;
|
|
28
56
|
declare function flushAllInjections(): void;
|
|
29
57
|
|
|
30
|
-
export { AnyProps, Id, InjectArgs, InjectedComponent, Injection, Location, Priority,
|
|
58
|
+
export { AnyProps, Id, InjectArgs, InjectedComponent, Injection, Location, Priority, flushAllInjections as __flushAllInjections, createLocation };
|
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>;
|
|
@@ -27,4 +55,4 @@ type Location<TProps extends object = AnyProps> = {
|
|
|
27
55
|
declare function createLocation<TProps extends object = AnyProps>(): Location<TProps>;
|
|
28
56
|
declare function flushAllInjections(): void;
|
|
29
57
|
|
|
30
|
-
export { AnyProps, Id, InjectArgs, InjectedComponent, Injection, Location, Priority,
|
|
58
|
+
export { AnyProps, Id, InjectArgs, InjectedComponent, Injection, Location, Priority, flushAllInjections as __flushAllInjections, createLocation };
|
package/dist/index.js
CHANGED
|
@@ -30,8 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
__flushAllInjections: () => flushAllInjections,
|
|
34
|
+
createLocation: () => createLocation
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
37
|
|
|
@@ -117,7 +117,7 @@ function createUseInjections(getInjections) {
|
|
|
117
117
|
}
|
|
118
118
|
// Annotate the CommonJS export names for ESM import in node:
|
|
119
119
|
0 && (module.exports = {
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
__flushAllInjections,
|
|
121
|
+
createLocation
|
|
122
122
|
});
|
|
123
123
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/api.tsx","../src/components/injected-component-wrapper.tsx","../src/components/error-boundary.tsx"],"sourcesContent":["export * from './types';\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/api.tsx","../src/components/injected-component-wrapper.tsx","../src/components/error-boundary.tsx"],"sourcesContent":["export * from './types';\n\nexport {\n\tcreateLocation,\n\tflushAllInjections as __flushAllInjections,\n} from './api';\n","import * as React from 'react';\nimport { InjectedComponent, Injection, InjectArgs, AnyProps, Location, Id } from './types';\nimport InjectedComponentWrapper from './components/injected-component-wrapper';\nimport { useMemo } from 'react';\n\ntype InjectionsMap<TProps extends object = AnyProps> = Map<Id, Injection<TProps>>\n\nconst DEFAULT_PRIORITY = 10;\n\n// Allow flushing all injections at once, for testing purposes.\nconst flushInjectionsFns: ( () => void )[] = [];\n\nexport function createLocation<TProps extends object = AnyProps>(): Location<TProps> {\n\tconst injections: InjectionsMap<TProps> = new Map();\n\n\tconst getInjections = createGetInjections( injections );\n\tconst useInjections = createUseInjections( getInjections );\n\tconst Slot = createSlot( useInjections );\n\tconst inject = createInject( injections );\n\n\t// Push the clear function to the flushInjectionsFns array, so we can flush all injections at once.\n\tflushInjectionsFns.push( () => injections.clear() );\n\n\treturn {\n\t\tinject,\n\t\tgetInjections,\n\t\tuseInjections,\n\t\tSlot,\n\t};\n}\n\nexport function flushAllInjections() {\n\tflushInjectionsFns.forEach( ( flush ) => flush() );\n}\n\nfunction wrapInjectedComponent<TProps extends object = AnyProps>( Component: InjectedComponent<TProps> ) {\n\treturn ( props: TProps ) => (\n\t\t<InjectedComponentWrapper>\n\t\t\t<Component { ...props } />\n\t\t</InjectedComponentWrapper>\n\t);\n}\n\nfunction createSlot<TProps extends object = AnyProps>( useInjections: Location<TProps>[ 'useInjections' ] ) {\n\treturn ( props: TProps ) => {\n\t\tconst injections = useInjections();\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ injections.map( ( { id, component: Component } ) => (\n\t\t\t\t\t<Component { ...props } key={ id } />\n\t\t\t\t) ) }\n\t\t\t</>\n\t\t);\n\t};\n}\n\nfunction createGetInjections<TProps extends object = AnyProps>( injections: InjectionsMap<TProps> ) {\n\treturn () => [ ...injections.values() ]\n\t\t.sort( ( a, b ) => a.priority - b.priority );\n}\n\nfunction createInject<TProps extends object = AnyProps>( injections: InjectionsMap<TProps> ) {\n\treturn ( { component, id, options = {} }: InjectArgs<TProps> ) => {\n\t\tif ( injections.has( id ) && ! options?.overwrite ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`An injection with the id \"${ id }\" already exists. Did you mean to use \"options.overwrite\"?`,\n\t\t\t);\n\n\t\t\treturn;\n\t\t}\n\n\t\tinjections.set( id, {\n\t\t\tid,\n\t\t\tcomponent: wrapInjectedComponent( component ),\n\t\t\tpriority: options.priority ?? DEFAULT_PRIORITY,\n\t\t} );\n\t};\n}\n\nfunction createUseInjections<TProps extends object = AnyProps>( getInjections: Location<TProps>[ 'getInjections' ] ) {\n\treturn () => useMemo( () => getInjections(), [] );\n}\n","import * as React from 'react';\nimport { ReactNode, Suspense } from 'react';\nimport ErrorBoundary from './error-boundary';\n\nexport default function InjectedComponentWrapper( { children }: { children: ReactNode } ) {\n\treturn (\n\t\t<ErrorBoundary fallback={ null }>\n\t\t\t<Suspense fallback={ null }>\n\t\t\t\t{ children }\n\t\t\t</Suspense>\n\t\t</ErrorBoundary>\n\t);\n}\n","import { Component, ReactNode } from 'react';\n\ninterface Props {\n\tchildren?: ReactNode;\n\tfallback: ReactNode;\n}\n\ninterface State {\n\thasError: boolean;\n}\n\nexport default class ErrorBoundary extends Component<Props, State> {\n\tpublic state: State = {\n\t\thasError: false,\n\t};\n\n\tpublic static getDerivedStateFromError(): State {\n\t\t// Update state so the next render will show the fallback UI.\n\t\treturn { hasError: true };\n\t}\n\n\tpublic render() {\n\t\tif ( this.state.hasError ) {\n\t\t\treturn this.props.fallback;\n\t\t}\n\n\t\treturn this.props.children;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,SAAuB;;;ACAvB,YAAuB;AACvB,IAAAC,gBAAoC;;;ACDpC,mBAAqC;AAWrC,IAAqB,gBAArB,cAA2C,uBAAwB;AAAA,EAC3D,QAAe;AAAA,IACrB,UAAU;AAAA,EACX;AAAA,EAEA,OAAc,2BAAkC;AAE/C,WAAO,EAAE,UAAU,KAAK;AAAA,EACzB;AAAA,EAEO,SAAS;AACf,QAAK,KAAK,MAAM,UAAW;AAC1B,aAAO,KAAK,MAAM;AAAA,IACnB;AAEA,WAAO,KAAK,MAAM;AAAA,EACnB;AACD;;;ADxBe,SAAR,yBAA2C,EAAE,SAAS,GAA6B;AACzF,SACC,oCAAC,iBAAc,UAAW,QACzB,oCAAC,0BAAS,UAAW,QAClB,QACH,CACD;AAEF;;;ADTA,IAAAC,gBAAwB;AAIxB,IAAM,mBAAmB;AAGzB,IAAM,qBAAuC,CAAC;AAEvC,SAAS,iBAAqE;AACpF,QAAM,aAAoC,oBAAI,IAAI;AAElD,QAAM,gBAAgB,oBAAqB,UAAW;AACtD,QAAM,gBAAgB,oBAAqB,aAAc;AACzD,QAAM,OAAO,WAAY,aAAc;AACvC,QAAM,SAAS,aAAc,UAAW;AAGxC,qBAAmB,KAAM,MAAM,WAAW,MAAM,CAAE;AAElD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEO,SAAS,qBAAqB;AACpC,qBAAmB,QAAS,CAAE,UAAW,MAAM,CAAE;AAClD;AAEA,SAAS,sBAAyDC,YAAuC;AACxG,SAAO,CAAE,UACR,qCAAC,gCACA,qCAACA,YAAA,EAAY,GAAG,OAAQ,CACzB;AAEF;AAEA,SAAS,WAA8C,eAAqD;AAC3G,SAAO,CAAE,UAAmB;AAC3B,UAAM,aAAa,cAAc;AAEjC,WACC,4DACG,WAAW,IAAK,CAAE,EAAE,IAAI,WAAWA,WAAU,MAC9C,qCAACA,YAAA,EAAY,GAAG,OAAQ,KAAM,IAAK,CAClC,CACH;AAAA,EAEF;AACD;AAEA,SAAS,oBAAuD,YAAoC;AACnG,SAAO,MAAM,CAAE,GAAG,WAAW,OAAO,CAAE,EACpC,KAAM,CAAE,GAAG,MAAO,EAAE,WAAW,EAAE,QAAS;AAC7C;AAEA,SAAS,aAAgD,YAAoC;AAC5F,SAAO,CAAE,EAAE,WAAW,IAAI,UAAU,CAAC,EAAE,MAA2B;AACjE,QAAK,WAAW,IAAK,EAAG,KAAK,CAAE,SAAS,WAAY;AAEnD,cAAQ;AAAA,QACP,6BAA8B,EAAG;AAAA,MAClC;AAEA;AAAA,IACD;AAEA,eAAW,IAAK,IAAI;AAAA,MACnB;AAAA,MACA,WAAW,sBAAuB,SAAU;AAAA,MAC5C,UAAU,QAAQ,YAAY;AAAA,IAC/B,CAAE;AAAA,EACH;AACD;AAEA,SAAS,oBAAuD,eAAqD;AACpH,SAAO,UAAM,uBAAS,MAAM,cAAc,GAAG,CAAC,CAAE;AACjD;","names":["React","import_react","import_react","Component"]}
|
package/dist/index.mjs
CHANGED
|
@@ -79,7 +79,7 @@ function createUseInjections(getInjections) {
|
|
|
79
79
|
return () => useMemo(() => getInjections(), []);
|
|
80
80
|
}
|
|
81
81
|
export {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
flushAllInjections as __flushAllInjections,
|
|
83
|
+
createLocation
|
|
84
84
|
};
|
|
85
85
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/locations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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": "7dc3971d2dd061848d6547aa2caed8332e7b9167"
|
|
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/index.ts
CHANGED
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>;
|