@elementor/locations 0.5.0 → 0.6.1
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/dist/index.d.mts +30 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/index.test.tsx +2 -2
- package/src/{locations.tsx → api.tsx} +9 -9
- package/src/index.ts +1 -1
- package/src/types.ts +6 -5
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.6.1](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.6.0...@elementor/locations@0.6.1) (2023-07-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @elementor/locations
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [0.6.0](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.5.0...@elementor/locations@0.6.0) (2023-06-11)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **editor-panels:** init [ED-10804] ([#44](https://github.com/elementor/elementor-packages/issues/44)) ([1ed4113](https://github.com/elementor/elementor-packages/commit/1ed41131db8fb9151163175bfa614f784159e04b))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
# [0.5.0](https://github.com/elementor/elementor-packages/compare/@elementor/locations@0.4.0...@elementor/locations@0.5.0) (2023-06-06)
|
|
7
26
|
|
|
8
27
|
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
type AnyProps = object;
|
|
4
|
+
type Filler<TProps extends object = AnyProps> = ComponentType<TProps>;
|
|
5
|
+
type Id = string;
|
|
6
|
+
type Priority = number;
|
|
7
|
+
type Injection<TProps extends object = AnyProps> = {
|
|
8
|
+
id: Id;
|
|
9
|
+
filler: Filler<TProps>;
|
|
10
|
+
priority: Priority;
|
|
11
|
+
};
|
|
12
|
+
type InjectArgs<TProps extends object = AnyProps> = {
|
|
13
|
+
id: Id;
|
|
14
|
+
filler: Filler<TProps>;
|
|
15
|
+
options?: {
|
|
16
|
+
priority?: Priority;
|
|
17
|
+
overwrite?: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type Location<TProps extends object = AnyProps> = {
|
|
21
|
+
inject: (args: InjectArgs<TProps>) => void;
|
|
22
|
+
getInjections: () => Injection<TProps>[];
|
|
23
|
+
useInjections: () => Injection<TProps>[];
|
|
24
|
+
Slot: ComponentType<TProps>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare function createLocation<TProps extends object = AnyProps>(): Location<TProps>;
|
|
28
|
+
declare function flushAllInjections(): void;
|
|
29
|
+
|
|
30
|
+
export { AnyProps, Filler, Id, InjectArgs, Injection, Location, Priority, createLocation, flushAllInjections };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
|
|
3
|
-
type
|
|
4
|
-
type Filler<TProps extends object =
|
|
3
|
+
type AnyProps = object;
|
|
4
|
+
type Filler<TProps extends object = AnyProps> = ComponentType<TProps>;
|
|
5
5
|
type Id = string;
|
|
6
6
|
type Priority = number;
|
|
7
|
-
type Injection<TProps extends object =
|
|
7
|
+
type Injection<TProps extends object = AnyProps> = {
|
|
8
8
|
id: Id;
|
|
9
9
|
filler: Filler<TProps>;
|
|
10
10
|
priority: Priority;
|
|
11
11
|
};
|
|
12
|
-
type InjectArgs<TProps extends object =
|
|
12
|
+
type InjectArgs<TProps extends object = AnyProps> = {
|
|
13
13
|
id: Id;
|
|
14
14
|
filler: Filler<TProps>;
|
|
15
15
|
options?: {
|
|
@@ -17,14 +17,14 @@ type InjectArgs<TProps extends object = EmptyObject> = {
|
|
|
17
17
|
overwrite?: boolean;
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
type Location<TProps extends object =
|
|
20
|
+
type Location<TProps extends object = AnyProps> = {
|
|
21
21
|
inject: (args: InjectArgs<TProps>) => void;
|
|
22
22
|
getInjections: () => Injection<TProps>[];
|
|
23
23
|
useInjections: () => Injection<TProps>[];
|
|
24
24
|
Slot: ComponentType<TProps>;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
declare function createLocation<TProps extends object =
|
|
27
|
+
declare function createLocation<TProps extends object = AnyProps>(): Location<TProps>;
|
|
28
28
|
declare function flushAllInjections(): void;
|
|
29
29
|
|
|
30
|
-
export {
|
|
30
|
+
export { AnyProps, Filler, Id, InjectArgs, Injection, Location, Priority, createLocation, flushAllInjections };
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __export(src_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(src_exports);
|
|
37
37
|
|
|
38
|
-
// src/
|
|
38
|
+
// src/api.tsx
|
|
39
39
|
var React2 = __toESM(require("react"));
|
|
40
40
|
|
|
41
41
|
// src/components/filler-wrapper.tsx
|
|
@@ -64,7 +64,7 @@ function FillerWrapper({ children }) {
|
|
|
64
64
|
return /* @__PURE__ */ React.createElement(ErrorBoundary, { fallback: null }, /* @__PURE__ */ React.createElement(import_react2.Suspense, { fallback: null }, children));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
// src/
|
|
67
|
+
// src/api.tsx
|
|
68
68
|
var import_react3 = require("react");
|
|
69
69
|
var DEFAULT_PRIORITY = 10;
|
|
70
70
|
var flushInjectionsFns = [];
|
|
@@ -100,7 +100,7 @@ function createGetInjections(injections) {
|
|
|
100
100
|
function createInject(injections) {
|
|
101
101
|
return ({ filler, id, options = {} }) => {
|
|
102
102
|
if (injections.has(id) && !options?.overwrite) {
|
|
103
|
-
console.
|
|
103
|
+
console.warn(
|
|
104
104
|
`An injection with the id "${id}" already exists. Did you mean to use "options.overwrite"?`
|
|
105
105
|
);
|
|
106
106
|
return;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/api.tsx","../src/components/filler-wrapper.tsx","../src/components/error-boundary.tsx"],"sourcesContent":["export * from './types';\nexport { createLocation, flushAllInjections } from './api';\n","import * as React from 'react';\nimport { Filler, Injection, InjectArgs, AnyProps, Location, Id } from './types';\nimport FillerWrapper from './components/filler-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 wrapFiller<TProps extends object = AnyProps>( FillerComponent: Filler<TProps> ) {\n\treturn ( props: TProps ) => (\n\t\t<FillerWrapper>\n\t\t\t<FillerComponent { ...props } />\n\t\t</FillerWrapper>\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, filler: 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 ( { filler, 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\tfiller: wrapFiller( filler ),\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 FillerWrapper( { 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,cAAgC,EAAE,SAAS,GAA6B;AAC9E,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,WAA8C,iBAAkC;AACxF,SAAO,CAAE,UACR,qCAAC,qBACA,qCAAC,mBAAkB,GAAG,OAAQ,CAC/B;AAEF;AAEA,SAAS,WAA8C,eAAqD;AAC3G,SAAO,CAAE,UAAmB;AAC3B,UAAM,aAAa,cAAc;AAEjC,WACC,4DACG,WAAW,IAAK,CAAE,EAAE,IAAI,QAAQC,WAAU,MAC3C,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,QAAQ,IAAI,UAAU,CAAC,EAAE,MAA2B;AAC9D,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,QAAQ,WAAY,MAAO;AAAA,MAC3B,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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/api.tsx
|
|
2
2
|
import * as React2 from "react";
|
|
3
3
|
|
|
4
4
|
// src/components/filler-wrapper.tsx
|
|
@@ -27,7 +27,7 @@ function FillerWrapper({ children }) {
|
|
|
27
27
|
return /* @__PURE__ */ React.createElement(ErrorBoundary, { fallback: null }, /* @__PURE__ */ React.createElement(Suspense, { fallback: null }, children));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
// src/
|
|
30
|
+
// src/api.tsx
|
|
31
31
|
import { useMemo } from "react";
|
|
32
32
|
var DEFAULT_PRIORITY = 10;
|
|
33
33
|
var flushInjectionsFns = [];
|
|
@@ -63,7 +63,7 @@ function createGetInjections(injections) {
|
|
|
63
63
|
function createInject(injections) {
|
|
64
64
|
return ({ filler, id, options = {} }) => {
|
|
65
65
|
if (injections.has(id) && !options?.overwrite) {
|
|
66
|
-
console.
|
|
66
|
+
console.warn(
|
|
67
67
|
`An injection with the id "${id}" already exists. Did you mean to use "options.overwrite"?`
|
|
68
68
|
);
|
|
69
69
|
return;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/api.tsx","../src/components/filler-wrapper.tsx","../src/components/error-boundary.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Filler, Injection, InjectArgs, AnyProps, Location, Id } from './types';\nimport FillerWrapper from './components/filler-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 wrapFiller<TProps extends object = AnyProps>( FillerComponent: Filler<TProps> ) {\n\treturn ( props: TProps ) => (\n\t\t<FillerWrapper>\n\t\t\t<FillerComponent { ...props } />\n\t\t</FillerWrapper>\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, filler: 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 ( { filler, 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\tfiller: wrapFiller( filler ),\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 FillerWrapper( { 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,YAAYA,YAAW;;;ACAvB,YAAY,WAAW;AACvB,SAAoB,gBAAgB;;;ACDpC,SAAS,iBAA4B;AAWrC,IAAqB,gBAArB,cAA2C,UAAwB;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,cAAgC,EAAE,SAAS,GAA6B;AAC9E,SACC,oCAAC,iBAAc,UAAW,QACzB,oCAAC,YAAS,UAAW,QAClB,QACH,CACD;AAEF;;;ADTA,SAAS,eAAe;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,WAA8C,iBAAkC;AACxF,SAAO,CAAE,UACR,qCAAC,qBACA,qCAAC,mBAAkB,GAAG,OAAQ,CAC/B;AAEF;AAEA,SAAS,WAA8C,eAAqD;AAC3G,SAAO,CAAE,UAAmB;AAC3B,UAAM,aAAa,cAAc;AAEjC,WACC,4DACG,WAAW,IAAK,CAAE,EAAE,IAAI,QAAQC,WAAU,MAC3C,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,QAAQ,IAAI,UAAU,CAAC,EAAE,MAA2B;AAC9D,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,QAAQ,WAAY,MAAO;AAAA,MAC3B,UAAU,QAAQ,YAAY;AAAA,IAC/B,CAAE;AAAA,EACH;AACD;AAEA,SAAS,oBAAuD,eAAqD;AACpH,SAAO,MAAM,QAAS,MAAM,cAAc,GAAG,CAAC,CAAE;AACjD;","names":["React","Component"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/locations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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": "fbb55b97a2581af49559479b6abf63f5acbfc28b"
|
|
38
38
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import { lazy } from 'react';
|
|
4
|
-
import { createLocation } from '../
|
|
4
|
+
import { createLocation } from '../api';
|
|
5
5
|
|
|
6
6
|
describe( '@elementor/locations', () => {
|
|
7
7
|
it( 'should render components based on the location name', () => {
|
|
@@ -130,7 +130,7 @@ describe( '@elementor/locations', () => {
|
|
|
130
130
|
// Assert.
|
|
131
131
|
expect( queryByText( 'First div' ) ).toBeTruthy();
|
|
132
132
|
expect( queryByText( 'Second div' ) ).toBeNull();
|
|
133
|
-
expect( console ).
|
|
133
|
+
expect( console ).toHaveWarned();
|
|
134
134
|
} );
|
|
135
135
|
|
|
136
136
|
it( 'should overwrite the filler if has same name', async () => {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Filler, Injection, InjectArgs,
|
|
2
|
+
import { Filler, Injection, InjectArgs, AnyProps, Location, Id } from './types';
|
|
3
3
|
import FillerWrapper from './components/filler-wrapper';
|
|
4
4
|
import { useMemo } from 'react';
|
|
5
5
|
|
|
6
|
-
type InjectionsMap<TProps extends object =
|
|
6
|
+
type InjectionsMap<TProps extends object = AnyProps> = Map<Id, Injection<TProps>>
|
|
7
7
|
|
|
8
8
|
const DEFAULT_PRIORITY = 10;
|
|
9
9
|
|
|
10
10
|
// Allow flushing all injections at once, for testing purposes.
|
|
11
11
|
const flushInjectionsFns: ( () => void )[] = [];
|
|
12
12
|
|
|
13
|
-
export function createLocation<TProps extends object =
|
|
13
|
+
export function createLocation<TProps extends object = AnyProps>(): Location<TProps> {
|
|
14
14
|
const injections: InjectionsMap<TProps> = new Map();
|
|
15
15
|
|
|
16
16
|
const getInjections = createGetInjections( injections );
|
|
@@ -33,7 +33,7 @@ export function flushAllInjections() {
|
|
|
33
33
|
flushInjectionsFns.forEach( ( flush ) => flush() );
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function wrapFiller<TProps extends object =
|
|
36
|
+
function wrapFiller<TProps extends object = AnyProps>( FillerComponent: Filler<TProps> ) {
|
|
37
37
|
return ( props: TProps ) => (
|
|
38
38
|
<FillerWrapper>
|
|
39
39
|
<FillerComponent { ...props } />
|
|
@@ -41,7 +41,7 @@ function wrapFiller<TProps extends object = EmptyObject>( FillerComponent: Fille
|
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function createSlot<TProps extends object =
|
|
44
|
+
function createSlot<TProps extends object = AnyProps>( useInjections: Location<TProps>[ 'useInjections' ] ) {
|
|
45
45
|
return ( props: TProps ) => {
|
|
46
46
|
const injections = useInjections();
|
|
47
47
|
|
|
@@ -55,16 +55,16 @@ function createSlot<TProps extends object = EmptyObject>( useInjections: Locatio
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function createGetInjections<TProps extends object =
|
|
58
|
+
function createGetInjections<TProps extends object = AnyProps>( injections: InjectionsMap<TProps> ) {
|
|
59
59
|
return () => [ ...injections.values() ]
|
|
60
60
|
.sort( ( a, b ) => a.priority - b.priority );
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function createInject<TProps extends object =
|
|
63
|
+
function createInject<TProps extends object = AnyProps>( injections: InjectionsMap<TProps> ) {
|
|
64
64
|
return ( { filler, id, options = {} }: InjectArgs<TProps> ) => {
|
|
65
65
|
if ( injections.has( id ) && ! options?.overwrite ) {
|
|
66
66
|
// eslint-disable-next-line no-console
|
|
67
|
-
console.
|
|
67
|
+
console.warn(
|
|
68
68
|
`An injection with the id "${ id }" already exists. Did you mean to use "options.overwrite"?`,
|
|
69
69
|
);
|
|
70
70
|
|
|
@@ -79,6 +79,6 @@ function createInject<TProps extends object = EmptyObject>( injections: Injectio
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
function createUseInjections<TProps extends object =
|
|
82
|
+
function createUseInjections<TProps extends object = AnyProps>( getInjections: Location<TProps>[ 'getInjections' ] ) {
|
|
83
83
|
return () => useMemo( () => getInjections(), [] );
|
|
84
84
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './types';
|
|
2
|
-
export { createLocation, flushAllInjections } from './
|
|
2
|
+
export { createLocation, flushAllInjections } from './api';
|
package/src/types.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// Allow passing the `key` prop even when there are no props for the component
|
|
4
|
+
export type AnyProps = object;
|
|
4
5
|
|
|
5
|
-
export type Filler<TProps extends object =
|
|
6
|
+
export type Filler<TProps extends object = AnyProps> = ComponentType<TProps>;
|
|
6
7
|
export type Id = string;
|
|
7
8
|
export type Priority = number;
|
|
8
9
|
|
|
9
|
-
export type Injection<TProps extends object =
|
|
10
|
+
export type Injection<TProps extends object = AnyProps> = {
|
|
10
11
|
id: Id;
|
|
11
12
|
filler: Filler<TProps>;
|
|
12
13
|
priority: Priority;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export type InjectArgs<TProps extends object =
|
|
16
|
+
export type InjectArgs<TProps extends object = AnyProps> = {
|
|
16
17
|
id: Id;
|
|
17
18
|
filler: Filler<TProps>;
|
|
18
19
|
options?: {
|
|
@@ -21,7 +22,7 @@ export type InjectArgs<TProps extends object = EmptyObject> = {
|
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export type Location<TProps extends object =
|
|
25
|
+
export type Location<TProps extends object = AnyProps> = {
|
|
25
26
|
inject: ( args: InjectArgs<TProps> ) => void;
|
|
26
27
|
getInjections: () => Injection<TProps>[];
|
|
27
28
|
useInjections: () => Injection<TProps>[];
|