@player-ui/check-path-plugin-react 0.3.1-next.0 → 0.4.0-next.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/dist/index.cjs.js CHANGED
@@ -18,35 +18,35 @@ function getId(asset) {
18
18
  }
19
19
  function useHasParentContext(asset, query) {
20
20
  const { plugin } = React__default["default"].useContext(CheckPathContext);
21
- if (!plugin) {
21
+ if (!plugin || !asset) {
22
22
  return false;
23
23
  }
24
24
  return plugin.hasParentContext(getId(asset), query);
25
25
  }
26
26
  function useHasChildContext(asset, query) {
27
27
  const { plugin } = React__default["default"].useContext(CheckPathContext);
28
- if (!plugin) {
28
+ if (!plugin || !asset) {
29
29
  return false;
30
30
  }
31
31
  return plugin.hasChildContext(getId(asset), query);
32
32
  }
33
33
  function useGetParentProp(asset) {
34
34
  const { plugin } = React__default["default"].useContext(CheckPathContext);
35
- if (!plugin) {
35
+ if (!plugin || !asset) {
36
36
  return void 0;
37
37
  }
38
38
  return plugin.getParentProp(getId(asset));
39
39
  }
40
40
  function useGetPath(asset, query) {
41
41
  const { plugin } = React__default["default"].useContext(CheckPathContext);
42
- if (!plugin) {
42
+ if (!plugin || !asset) {
43
43
  return void 0;
44
44
  }
45
45
  return plugin.getPath(getId(asset), query);
46
46
  }
47
47
  function useGetParent(asset, query) {
48
48
  const { plugin } = React__default["default"].useContext(CheckPathContext);
49
- if (!plugin) {
49
+ if (!plugin || !asset) {
50
50
  return void 0;
51
51
  }
52
52
  return plugin.getParent(getId(asset), query);
package/dist/index.d.ts CHANGED
@@ -5,15 +5,15 @@ import React from 'react';
5
5
 
6
6
  declare type AssetOrID = Asset | string;
7
7
  /** hook to check if the asset has the given parents */
8
- declare function useHasParentContext(asset: AssetOrID, query: Query | Query[]): boolean;
8
+ declare function useHasParentContext(asset: AssetOrID | undefined, query: Query | Query[]): boolean;
9
9
  /** hook to check if the asset has the given children */
10
- declare function useHasChildContext(asset: AssetOrID, query: Query | Query[]): boolean;
10
+ declare function useHasChildContext(asset: AssetOrID | undefined, query: Query | Query[]): boolean;
11
11
  /** hook to get the prop of the given asset on the parent */
12
- declare function useGetParentProp(asset: AssetOrID): string | number | undefined;
12
+ declare function useGetParentProp(asset: AssetOrID | undefined): string | number | undefined;
13
13
  /** hook to get the path of the asset in the view */
14
- declare function useGetPath(asset: AssetOrID, query?: Query | Query[]): Array<string | number> | undefined;
14
+ declare function useGetPath(asset: AssetOrID | undefined, query?: Query | Query[]): Array<string | number> | undefined;
15
15
  /** get the parent of the given asset */
16
- declare function useGetParent<T extends Asset>(asset: AssetOrID, query?: Query | Query[]): T | undefined;
16
+ declare function useGetParent<T extends Asset>(asset: AssetOrID | undefined, query?: Query | Query[]): T | undefined;
17
17
 
18
18
  interface CheckPathContextType {
19
19
  /** The core plugin to talk to */
package/dist/index.esm.js CHANGED
@@ -10,35 +10,35 @@ function getId(asset) {
10
10
  }
11
11
  function useHasParentContext(asset, query) {
12
12
  const { plugin } = React.useContext(CheckPathContext);
13
- if (!plugin) {
13
+ if (!plugin || !asset) {
14
14
  return false;
15
15
  }
16
16
  return plugin.hasParentContext(getId(asset), query);
17
17
  }
18
18
  function useHasChildContext(asset, query) {
19
19
  const { plugin } = React.useContext(CheckPathContext);
20
- if (!plugin) {
20
+ if (!plugin || !asset) {
21
21
  return false;
22
22
  }
23
23
  return plugin.hasChildContext(getId(asset), query);
24
24
  }
25
25
  function useGetParentProp(asset) {
26
26
  const { plugin } = React.useContext(CheckPathContext);
27
- if (!plugin) {
27
+ if (!plugin || !asset) {
28
28
  return void 0;
29
29
  }
30
30
  return plugin.getParentProp(getId(asset));
31
31
  }
32
32
  function useGetPath(asset, query) {
33
33
  const { plugin } = React.useContext(CheckPathContext);
34
- if (!plugin) {
34
+ if (!plugin || !asset) {
35
35
  return void 0;
36
36
  }
37
37
  return plugin.getPath(getId(asset), query);
38
38
  }
39
39
  function useGetParent(asset, query) {
40
40
  const { plugin } = React.useContext(CheckPathContext);
41
- if (!plugin) {
41
+ if (!plugin || !asset) {
42
42
  return void 0;
43
43
  }
44
44
  return plugin.getParent(getId(asset), query);
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@player-ui/check-path-plugin-react",
3
- "version": "0.3.1-next.0",
3
+ "version": "0.4.0-next.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
7
7
  },
8
8
  "peerDependencies": {
9
- "@player-ui/react": "0.3.1-next.0"
9
+ "@player-ui/react": "0.4.0-next.0"
10
10
  },
11
11
  "dependencies": {
12
- "@player-ui/check-path-plugin": "0.3.1-next.0",
12
+ "@player-ui/check-path-plugin": "0.4.0-next.0",
13
13
  "@babel/runtime": "7.15.4"
14
14
  },
15
15
  "main": "dist/index.cjs.js",
package/src/hooks.tsx CHANGED
@@ -12,12 +12,12 @@ function getId(asset: AssetOrID): string {
12
12
 
13
13
  /** hook to check if the asset has the given parents */
14
14
  export function useHasParentContext(
15
- asset: AssetOrID,
15
+ asset: AssetOrID | undefined,
16
16
  query: Query | Query[]
17
17
  ): boolean {
18
18
  const { plugin } = React.useContext(CheckPathContext);
19
19
 
20
- if (!plugin) {
20
+ if (!plugin || !asset) {
21
21
  return false;
22
22
  }
23
23
 
@@ -26,12 +26,12 @@ export function useHasParentContext(
26
26
 
27
27
  /** hook to check if the asset has the given children */
28
28
  export function useHasChildContext(
29
- asset: AssetOrID,
29
+ asset: AssetOrID | undefined,
30
30
  query: Query | Query[]
31
31
  ): boolean {
32
32
  const { plugin } = React.useContext(CheckPathContext);
33
33
 
34
- if (!plugin) {
34
+ if (!plugin || !asset) {
35
35
  return false;
36
36
  }
37
37
 
@@ -40,11 +40,11 @@ export function useHasChildContext(
40
40
 
41
41
  /** hook to get the prop of the given asset on the parent */
42
42
  export function useGetParentProp(
43
- asset: AssetOrID
43
+ asset: AssetOrID | undefined
44
44
  ): string | number | undefined {
45
45
  const { plugin } = React.useContext(CheckPathContext);
46
46
 
47
- if (!plugin) {
47
+ if (!plugin || !asset) {
48
48
  return undefined;
49
49
  }
50
50
 
@@ -53,12 +53,12 @@ export function useGetParentProp(
53
53
 
54
54
  /** hook to get the path of the asset in the view */
55
55
  export function useGetPath(
56
- asset: AssetOrID,
56
+ asset: AssetOrID | undefined,
57
57
  query?: Query | Query[]
58
58
  ): Array<string | number> | undefined {
59
59
  const { plugin } = React.useContext(CheckPathContext);
60
60
 
61
- if (!plugin) {
61
+ if (!plugin || !asset) {
62
62
  return undefined;
63
63
  }
64
64
 
@@ -67,12 +67,12 @@ export function useGetPath(
67
67
 
68
68
  /** get the parent of the given asset */
69
69
  export function useGetParent<T extends Asset>(
70
- asset: AssetOrID,
70
+ asset: AssetOrID | undefined,
71
71
  query?: Query | Query[]
72
72
  ): T | undefined {
73
73
  const { plugin } = React.useContext(CheckPathContext);
74
74
 
75
- if (!plugin) {
75
+ if (!plugin || !asset) {
76
76
  return undefined;
77
77
  }
78
78