@player-ui/check-path-plugin-react 0.8.0--canary.307.9621 → 0.8.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/cjs/index.cjs +117 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +76 -0
- package/dist/index.mjs +76 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +24 -56
- package/src/__tests__/check-path.test.tsx +190 -0
- package/src/context.tsx +2 -2
- package/src/hooks.tsx +10 -10
- package/src/index.tsx +17 -12
- package/types/context.d.ts +8 -0
- package/types/hooks.d.ts +14 -0
- package/types/index.d.ts +12 -0
- package/dist/index.cjs.js +0 -76
- package/dist/index.d.ts +0 -32
- package/dist/index.esm.js +0 -62
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/index.tsx
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
CheckPathContext: () => CheckPathContext,
|
|
34
|
+
CheckPathPlugin: () => CheckPathPlugin,
|
|
35
|
+
useGetParent: () => useGetParent,
|
|
36
|
+
useGetParentProp: () => useGetParentProp,
|
|
37
|
+
useGetPath: () => useGetPath,
|
|
38
|
+
useHasChildContext: () => useHasChildContext,
|
|
39
|
+
useHasParentContext: () => useHasParentContext
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(src_exports);
|
|
42
|
+
var import_react3 = __toESM(require("react"));
|
|
43
|
+
var import_check_path_plugin = require("@player-ui/check-path-plugin");
|
|
44
|
+
|
|
45
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/context.tsx
|
|
46
|
+
var import_react = __toESM(require("react"));
|
|
47
|
+
var CheckPathContext = import_react.default.createContext({
|
|
48
|
+
plugin: void 0
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/hooks.tsx
|
|
52
|
+
var import_react2 = __toESM(require("react"));
|
|
53
|
+
function getId(asset) {
|
|
54
|
+
return typeof asset === "string" ? asset : asset.id;
|
|
55
|
+
}
|
|
56
|
+
function useHasParentContext(asset, query) {
|
|
57
|
+
const { plugin } = import_react2.default.useContext(CheckPathContext);
|
|
58
|
+
if (!plugin || !asset) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return plugin.hasParentContext(getId(asset), query);
|
|
62
|
+
}
|
|
63
|
+
function useHasChildContext(asset, query) {
|
|
64
|
+
const { plugin } = import_react2.default.useContext(CheckPathContext);
|
|
65
|
+
if (!plugin || !asset) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return plugin.hasChildContext(getId(asset), query);
|
|
69
|
+
}
|
|
70
|
+
function useGetParentProp(asset) {
|
|
71
|
+
const { plugin } = import_react2.default.useContext(CheckPathContext);
|
|
72
|
+
if (!plugin || !asset) {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
return plugin.getParentProp(getId(asset));
|
|
76
|
+
}
|
|
77
|
+
function useGetPath(asset, query) {
|
|
78
|
+
const { plugin } = import_react2.default.useContext(CheckPathContext);
|
|
79
|
+
if (!plugin || !asset) {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
return plugin.getPath(getId(asset), query);
|
|
83
|
+
}
|
|
84
|
+
function useGetParent(asset, query) {
|
|
85
|
+
const { plugin } = import_react2.default.useContext(CheckPathContext);
|
|
86
|
+
if (!plugin || !asset) {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
return plugin.getParent(getId(asset), query);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/index.tsx
|
|
93
|
+
var CheckPathPlugin = class extends import_check_path_plugin.CheckPathPlugin {
|
|
94
|
+
constructor() {
|
|
95
|
+
super(...arguments);
|
|
96
|
+
this.name = "check-path-web";
|
|
97
|
+
}
|
|
98
|
+
applyReact(rp) {
|
|
99
|
+
rp.hooks.webComponent.tap(this.name, (Comp) => {
|
|
100
|
+
const plugin = this;
|
|
101
|
+
return function CheckPathContextWrapper() {
|
|
102
|
+
return /* @__PURE__ */ import_react3.default.createElement(CheckPathContext.Provider, { value: { plugin } }, /* @__PURE__ */ import_react3.default.createElement(Comp, null));
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
CheckPathContext,
|
|
110
|
+
CheckPathPlugin,
|
|
111
|
+
useGetParent,
|
|
112
|
+
useGetParentProp,
|
|
113
|
+
useGetPath,
|
|
114
|
+
useHasChildContext,
|
|
115
|
+
useHasParentContext
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/index.tsx","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/context.tsx","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/hooks.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ReactPlayer, ReactPlayerPlugin } from \"@player-ui/react\";\nimport { CheckPathPlugin as CheckPathCorePlugin } from \"@player-ui/check-path-plugin\";\nimport { CheckPathContext } from \"./context\";\n\nexport * from \"./hooks\";\nexport * from \"./context\";\n\n/**\n * A plugin for adding the check-path provider to the web-player\n */\nexport class CheckPathPlugin\n extends CheckPathCorePlugin\n implements ReactPlayerPlugin\n{\n name = \"check-path-web\";\n\n applyReact(rp: ReactPlayer) {\n rp.hooks.webComponent.tap(this.name, (Comp) => {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const plugin = this;\n\n return function CheckPathContextWrapper() {\n return (\n <CheckPathContext.Provider value={{ plugin }}>\n <Comp />\n </CheckPathContext.Provider>\n );\n };\n });\n }\n}\n","import React from \"react\";\nimport type { CheckPathPlugin } from \"@player-ui/check-path-plugin\";\n\nexport interface CheckPathContextType {\n /** The core plugin to talk to */\n plugin?: CheckPathPlugin;\n}\n\nexport const CheckPathContext = React.createContext<CheckPathContextType>({\n plugin: undefined,\n});\n","import React from \"react\";\nimport type { Query } from \"@player-ui/check-path-plugin\";\nimport type { Asset } from \"@player-ui/react\";\nimport { CheckPathContext } from \"./context\";\n\nexport type AssetOrID = Asset | string;\n\n/** get the id for an asset */\nfunction getId(asset: AssetOrID): string {\n return typeof asset === \"string\" ? asset : asset.id;\n}\n\n/** hook to check if the asset has the given parents */\nexport function useHasParentContext(\n asset: AssetOrID | undefined,\n query: Query | Query[],\n): boolean {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return false;\n }\n\n return plugin.hasParentContext(getId(asset), query);\n}\n\n/** hook to check if the asset has the given children */\nexport function useHasChildContext(\n asset: AssetOrID | undefined,\n query: Query | Query[],\n): boolean {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return false;\n }\n\n return plugin.hasChildContext(getId(asset), query);\n}\n\n/** hook to get the prop of the given asset on the parent */\nexport function useGetParentProp(\n asset: AssetOrID | undefined,\n): string | number | undefined {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return undefined;\n }\n\n return plugin.getParentProp(getId(asset));\n}\n\n/** hook to get the path of the asset in the view */\nexport function useGetPath(\n asset: AssetOrID | undefined,\n query?: Query | Query[],\n): Array<string | number> | undefined {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return undefined;\n }\n\n return plugin.getPath(getId(asset), query);\n}\n\n/** get the parent of the given asset */\nexport function useGetParent<T extends Asset>(\n asset: AssetOrID | undefined,\n query?: Query | Query[],\n): T | undefined {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return undefined;\n }\n\n return plugin.getParent(getId(asset), query) as T | undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAkB;AAElB,+BAAuD;;;ACFvD,mBAAkB;AAQX,IAAM,mBAAmB,aAAAC,QAAM,cAAoC;AAAA,EACxE,QAAQ;AACV,CAAC;;;ACVD,IAAAC,gBAAkB;AAQlB,SAAS,MAAM,OAA0B;AACvC,SAAO,OAAO,UAAU,WAAW,QAAQ,MAAM;AACnD;AAGO,SAAS,oBACd,OACA,OACS;AACT,QAAM,EAAE,OAAO,IAAI,cAAAC,QAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,iBAAiB,MAAM,KAAK,GAAG,KAAK;AACpD;AAGO,SAAS,mBACd,OACA,OACS;AACT,QAAM,EAAE,OAAO,IAAI,cAAAA,QAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,gBAAgB,MAAM,KAAK,GAAG,KAAK;AACnD;AAGO,SAAS,iBACd,OAC6B;AAC7B,QAAM,EAAE,OAAO,IAAI,cAAAA,QAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,cAAc,MAAM,KAAK,CAAC;AAC1C;AAGO,SAAS,WACd,OACA,OACoC;AACpC,QAAM,EAAE,OAAO,IAAI,cAAAA,QAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,QAAQ,MAAM,KAAK,GAAG,KAAK;AAC3C;AAGO,SAAS,aACd,OACA,OACe;AACf,QAAM,EAAE,OAAO,IAAI,cAAAA,QAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,UAAU,MAAM,KAAK,GAAG,KAAK;AAC7C;;;AFpEO,IAAM,kBAAN,cACG,yBAAAC,gBAEV;AAAA,EAHO;AAAA;AAIL,gBAAO;AAAA;AAAA,EAEP,WAAW,IAAiB;AAC1B,OAAG,MAAM,aAAa,IAAI,KAAK,MAAM,CAAC,SAAS;AAE7C,YAAM,SAAS;AAEf,aAAO,SAAS,0BAA0B;AACxC,eACE,8BAAAC,QAAA,cAAC,iBAAiB,UAAjB,EAA0B,OAAO,EAAE,OAAO,KACzC,8BAAAA,QAAA,cAAC,UAAK,CACR;AAAA,MAEJ;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["import_react","React","import_react","React","CheckPathCorePlugin","React"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/index.tsx
|
|
2
|
+
import React3 from "react";
|
|
3
|
+
import { CheckPathPlugin as CheckPathCorePlugin } from "@player-ui/check-path-plugin";
|
|
4
|
+
|
|
5
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/context.tsx
|
|
6
|
+
import React from "react";
|
|
7
|
+
var CheckPathContext = React.createContext({
|
|
8
|
+
plugin: void 0
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/hooks.tsx
|
|
12
|
+
import React2 from "react";
|
|
13
|
+
function getId(asset) {
|
|
14
|
+
return typeof asset === "string" ? asset : asset.id;
|
|
15
|
+
}
|
|
16
|
+
function useHasParentContext(asset, query) {
|
|
17
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
18
|
+
if (!plugin || !asset) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return plugin.hasParentContext(getId(asset), query);
|
|
22
|
+
}
|
|
23
|
+
function useHasChildContext(asset, query) {
|
|
24
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
25
|
+
if (!plugin || !asset) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return plugin.hasChildContext(getId(asset), query);
|
|
29
|
+
}
|
|
30
|
+
function useGetParentProp(asset) {
|
|
31
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
32
|
+
if (!plugin || !asset) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
return plugin.getParentProp(getId(asset));
|
|
36
|
+
}
|
|
37
|
+
function useGetPath(asset, query) {
|
|
38
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
39
|
+
if (!plugin || !asset) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
return plugin.getPath(getId(asset), query);
|
|
43
|
+
}
|
|
44
|
+
function useGetParent(asset, query) {
|
|
45
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
46
|
+
if (!plugin || !asset) {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
return plugin.getParent(getId(asset), query);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/index.tsx
|
|
53
|
+
var CheckPathPlugin = class extends CheckPathCorePlugin {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
this.name = "check-path-web";
|
|
57
|
+
}
|
|
58
|
+
applyReact(rp) {
|
|
59
|
+
rp.hooks.webComponent.tap(this.name, (Comp) => {
|
|
60
|
+
const plugin = this;
|
|
61
|
+
return function CheckPathContextWrapper() {
|
|
62
|
+
return /* @__PURE__ */ React3.createElement(CheckPathContext.Provider, { value: { plugin } }, /* @__PURE__ */ React3.createElement(Comp, null));
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
CheckPathContext,
|
|
69
|
+
CheckPathPlugin,
|
|
70
|
+
useGetParent,
|
|
71
|
+
useGetParentProp,
|
|
72
|
+
useGetPath,
|
|
73
|
+
useHasChildContext,
|
|
74
|
+
useHasParentContext
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/index.tsx
|
|
2
|
+
import React3 from "react";
|
|
3
|
+
import { CheckPathPlugin as CheckPathCorePlugin } from "@player-ui/check-path-plugin";
|
|
4
|
+
|
|
5
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/context.tsx
|
|
6
|
+
import React from "react";
|
|
7
|
+
var CheckPathContext = React.createContext({
|
|
8
|
+
plugin: void 0
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/hooks.tsx
|
|
12
|
+
import React2 from "react";
|
|
13
|
+
function getId(asset) {
|
|
14
|
+
return typeof asset === "string" ? asset : asset.id;
|
|
15
|
+
}
|
|
16
|
+
function useHasParentContext(asset, query) {
|
|
17
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
18
|
+
if (!plugin || !asset) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return plugin.hasParentContext(getId(asset), query);
|
|
22
|
+
}
|
|
23
|
+
function useHasChildContext(asset, query) {
|
|
24
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
25
|
+
if (!plugin || !asset) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return plugin.hasChildContext(getId(asset), query);
|
|
29
|
+
}
|
|
30
|
+
function useGetParentProp(asset) {
|
|
31
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
32
|
+
if (!plugin || !asset) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
return plugin.getParentProp(getId(asset));
|
|
36
|
+
}
|
|
37
|
+
function useGetPath(asset, query) {
|
|
38
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
39
|
+
if (!plugin || !asset) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
return plugin.getPath(getId(asset), query);
|
|
43
|
+
}
|
|
44
|
+
function useGetParent(asset, query) {
|
|
45
|
+
const { plugin } = React2.useContext(CheckPathContext);
|
|
46
|
+
if (!plugin || !asset) {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
return plugin.getParent(getId(asset), query);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/index.tsx
|
|
53
|
+
var CheckPathPlugin = class extends CheckPathCorePlugin {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
this.name = "check-path-web";
|
|
57
|
+
}
|
|
58
|
+
applyReact(rp) {
|
|
59
|
+
rp.hooks.webComponent.tap(this.name, (Comp) => {
|
|
60
|
+
const plugin = this;
|
|
61
|
+
return function CheckPathContextWrapper() {
|
|
62
|
+
return /* @__PURE__ */ React3.createElement(CheckPathContext.Provider, { value: { plugin } }, /* @__PURE__ */ React3.createElement(Comp, null));
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
CheckPathContext,
|
|
69
|
+
CheckPathPlugin,
|
|
70
|
+
useGetParent,
|
|
71
|
+
useGetParentProp,
|
|
72
|
+
useGetPath,
|
|
73
|
+
useHasChildContext,
|
|
74
|
+
useHasParentContext
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/context.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/check-path/react/src/hooks.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ReactPlayer, ReactPlayerPlugin } from \"@player-ui/react\";\nimport { CheckPathPlugin as CheckPathCorePlugin } from \"@player-ui/check-path-plugin\";\nimport { CheckPathContext } from \"./context\";\n\nexport * from \"./hooks\";\nexport * from \"./context\";\n\n/**\n * A plugin for adding the check-path provider to the web-player\n */\nexport class CheckPathPlugin\n extends CheckPathCorePlugin\n implements ReactPlayerPlugin\n{\n name = \"check-path-web\";\n\n applyReact(rp: ReactPlayer) {\n rp.hooks.webComponent.tap(this.name, (Comp) => {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const plugin = this;\n\n return function CheckPathContextWrapper() {\n return (\n <CheckPathContext.Provider value={{ plugin }}>\n <Comp />\n </CheckPathContext.Provider>\n );\n };\n });\n }\n}\n","import React from \"react\";\nimport type { CheckPathPlugin } from \"@player-ui/check-path-plugin\";\n\nexport interface CheckPathContextType {\n /** The core plugin to talk to */\n plugin?: CheckPathPlugin;\n}\n\nexport const CheckPathContext = React.createContext<CheckPathContextType>({\n plugin: undefined,\n});\n","import React from \"react\";\nimport type { Query } from \"@player-ui/check-path-plugin\";\nimport type { Asset } from \"@player-ui/react\";\nimport { CheckPathContext } from \"./context\";\n\nexport type AssetOrID = Asset | string;\n\n/** get the id for an asset */\nfunction getId(asset: AssetOrID): string {\n return typeof asset === \"string\" ? asset : asset.id;\n}\n\n/** hook to check if the asset has the given parents */\nexport function useHasParentContext(\n asset: AssetOrID | undefined,\n query: Query | Query[],\n): boolean {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return false;\n }\n\n return plugin.hasParentContext(getId(asset), query);\n}\n\n/** hook to check if the asset has the given children */\nexport function useHasChildContext(\n asset: AssetOrID | undefined,\n query: Query | Query[],\n): boolean {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return false;\n }\n\n return plugin.hasChildContext(getId(asset), query);\n}\n\n/** hook to get the prop of the given asset on the parent */\nexport function useGetParentProp(\n asset: AssetOrID | undefined,\n): string | number | undefined {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return undefined;\n }\n\n return plugin.getParentProp(getId(asset));\n}\n\n/** hook to get the path of the asset in the view */\nexport function useGetPath(\n asset: AssetOrID | undefined,\n query?: Query | Query[],\n): Array<string | number> | undefined {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return undefined;\n }\n\n return plugin.getPath(getId(asset), query);\n}\n\n/** get the parent of the given asset */\nexport function useGetParent<T extends Asset>(\n asset: AssetOrID | undefined,\n query?: Query | Query[],\n): T | undefined {\n const { plugin } = React.useContext(CheckPathContext);\n\n if (!plugin || !asset) {\n return undefined;\n }\n\n return plugin.getParent(getId(asset), query) as T | undefined;\n}\n"],"mappings":";AAAA,OAAOA,YAAW;AAElB,SAAS,mBAAmB,2BAA2B;;;ACFvD,OAAO,WAAW;AAQX,IAAM,mBAAmB,MAAM,cAAoC;AAAA,EACxE,QAAQ;AACV,CAAC;;;ACVD,OAAOC,YAAW;AAQlB,SAAS,MAAM,OAA0B;AACvC,SAAO,OAAO,UAAU,WAAW,QAAQ,MAAM;AACnD;AAGO,SAAS,oBACd,OACA,OACS;AACT,QAAM,EAAE,OAAO,IAAIC,OAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,iBAAiB,MAAM,KAAK,GAAG,KAAK;AACpD;AAGO,SAAS,mBACd,OACA,OACS;AACT,QAAM,EAAE,OAAO,IAAIA,OAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,gBAAgB,MAAM,KAAK,GAAG,KAAK;AACnD;AAGO,SAAS,iBACd,OAC6B;AAC7B,QAAM,EAAE,OAAO,IAAIA,OAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,cAAc,MAAM,KAAK,CAAC;AAC1C;AAGO,SAAS,WACd,OACA,OACoC;AACpC,QAAM,EAAE,OAAO,IAAIA,OAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,QAAQ,MAAM,KAAK,GAAG,KAAK;AAC3C;AAGO,SAAS,aACd,OACA,OACe;AACf,QAAM,EAAE,OAAO,IAAIA,OAAM,WAAW,gBAAgB;AAEpD,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,UAAU,MAAM,KAAK,GAAG,KAAK;AAC7C;;;AFpEO,IAAM,kBAAN,cACG,oBAEV;AAAA,EAHO;AAAA;AAIL,gBAAO;AAAA;AAAA,EAEP,WAAW,IAAiB;AAC1B,OAAG,MAAM,aAAa,IAAI,KAAK,MAAM,CAAC,SAAS;AAE7C,YAAM,SAAS;AAEf,aAAO,SAAS,0BAA0B;AACxC,eACE,gBAAAC,OAAA,cAAC,iBAAiB,UAAjB,EAA0B,OAAO,EAAE,OAAO,KACzC,gBAAAA,OAAA,cAAC,UAAK,CACR;AAAA,MAEJ;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["React","React","React","React"]}
|
package/package.json
CHANGED
|
@@ -1,66 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/check-path-plugin-react",
|
|
3
|
-
"version": "0.8.0
|
|
4
|
-
"
|
|
5
|
-
"publishConfig": {
|
|
6
|
-
"registry": "https://registry.npmjs.org"
|
|
7
|
-
},
|
|
3
|
+
"version": "0.8.0-next.0",
|
|
4
|
+
"main": "dist/cjs/index.cjs",
|
|
8
5
|
"peerDependencies": {
|
|
9
|
-
"@player-ui/react": "0.8.0
|
|
6
|
+
"@player-ui/react": "0.8.0-next.0",
|
|
7
|
+
"react": "^18.2.0",
|
|
8
|
+
"@types/react": "^18.2.39"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@player-ui/make-flow": "workspace:*"
|
|
10
12
|
},
|
|
11
13
|
"dependencies": {
|
|
12
|
-
"@player-ui/check-path-plugin": "0.8.0
|
|
13
|
-
"
|
|
14
|
+
"@player-ui/check-path-plugin": "0.8.0-next.0",
|
|
15
|
+
"tslib": "^2.6.2"
|
|
14
16
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"typings": "dist/index.d.ts",
|
|
17
|
+
"module": "dist/index.legacy-esm.js",
|
|
18
|
+
"types": "types/index.d.ts",
|
|
18
19
|
"sideEffects": false,
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://player-ui.github.io",
|
|
28
|
-
"contributors": [
|
|
29
|
-
{
|
|
30
|
-
"name": "Adam Dierkens",
|
|
31
|
-
"url": "https://github.com/adierkens"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"name": "Spencer Hamm",
|
|
35
|
-
"url": "https://github.com/spentacular"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"name": "Harris Borawski",
|
|
39
|
-
"url": "https://github.com/hborawski"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"name": "Jeremiah Zucker",
|
|
43
|
-
"url": "https://github.com/sugarmanz"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"name": "Ketan Reddy",
|
|
47
|
-
"url": "https://github.com/KetanReddy"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"name": "Brocollie08",
|
|
51
|
-
"url": "https://github.com/brocollie08"
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"name": "Kelly Harrop",
|
|
55
|
-
"url": "https://github.com/kharrop"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"name": "Alejandro Fimbres",
|
|
59
|
-
"url": "https://github.com/lexfm"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"name": "Rafael Campos",
|
|
63
|
-
"url": "https://github.com/rafbcampos"
|
|
20
|
+
"exports": {
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
"./dist/index.css": "./dist/index.css",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./types/index.d.ts",
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"default": "./dist/cjs/index.cjs"
|
|
64
27
|
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"src",
|
|
32
|
+
"types"
|
|
65
33
|
]
|
|
66
34
|
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { describe, test, expect, vitest, afterEach, beforeEach } from "vitest";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ReactPlayer, ReactAsset } from "@player-ui/react";
|
|
4
|
+
import { findByTestId, render } from "@testing-library/react";
|
|
5
|
+
import { makeFlow } from "@player-ui/make-flow";
|
|
6
|
+
import {
|
|
7
|
+
CheckPathPlugin,
|
|
8
|
+
useGetParent,
|
|
9
|
+
useGetParentProp,
|
|
10
|
+
useGetPath,
|
|
11
|
+
useHasChildContext,
|
|
12
|
+
useHasParentContext,
|
|
13
|
+
} from "..";
|
|
14
|
+
|
|
15
|
+
describe("beacon web plugin", () => {
|
|
16
|
+
test("loads in a player", async () => {
|
|
17
|
+
const rp = new ReactPlayer({
|
|
18
|
+
plugins: [new CheckPathPlugin()],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const flow = makeFlow({
|
|
22
|
+
id: "action",
|
|
23
|
+
type: "action",
|
|
24
|
+
value: "Next",
|
|
25
|
+
label: {
|
|
26
|
+
asset: {
|
|
27
|
+
type: "action",
|
|
28
|
+
id: "label",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
rp.assetRegistry.set({ type: "action" }, (props: any) => {
|
|
34
|
+
const parentProp = useGetParentProp(props.id);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div data-testid={props.id}>
|
|
38
|
+
{props.value} - {parentProp}
|
|
39
|
+
{props.label && <ReactAsset {...props.label} />}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
rp.start(flow);
|
|
44
|
+
|
|
45
|
+
const { container } = render(
|
|
46
|
+
<div>
|
|
47
|
+
<React.Suspense fallback="loading...">
|
|
48
|
+
<rp.Component />
|
|
49
|
+
</React.Suspense>
|
|
50
|
+
</div>,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const action = await findByTestId(container, "action");
|
|
54
|
+
|
|
55
|
+
expect(action).toMatchInlineSnapshot(`
|
|
56
|
+
<div
|
|
57
|
+
data-testid="action"
|
|
58
|
+
>
|
|
59
|
+
Next
|
|
60
|
+
-
|
|
61
|
+
<div
|
|
62
|
+
data-testid="label"
|
|
63
|
+
>
|
|
64
|
+
-
|
|
65
|
+
label
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
`);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("check-path tests", () => {
|
|
73
|
+
const spy = vitest.spyOn(React, "useContext");
|
|
74
|
+
const hasParentContextMock = vitest.fn();
|
|
75
|
+
const hasChildContextMock = vitest.fn();
|
|
76
|
+
const getParentPropMock = vitest.fn();
|
|
77
|
+
const getPathMock = vitest.fn();
|
|
78
|
+
const getParentMock = vitest.fn();
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
spy.mockReturnValue({
|
|
82
|
+
plugin: {
|
|
83
|
+
hasParentContext: hasParentContextMock,
|
|
84
|
+
hasChildContext: hasChildContextMock,
|
|
85
|
+
getParentProp: getParentPropMock,
|
|
86
|
+
getPath: getPathMock,
|
|
87
|
+
getParent: getParentMock,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
afterEach(() => {
|
|
93
|
+
vitest.clearAllMocks();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* useHasParent tests
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
test("useHasParentContext undefined asset", () => {
|
|
101
|
+
expect(useHasParentContext(undefined, "query")).toBe(false);
|
|
102
|
+
expect(hasParentContextMock).not.toBeCalled();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("useHasParentContext string asset", () => {
|
|
106
|
+
useHasParentContext("testId", "query");
|
|
107
|
+
expect(hasParentContextMock).toBeCalled();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("useHasParentContext object asset", () => {
|
|
111
|
+
useHasParentContext({ id: "testId", type: "testType" }, "query");
|
|
112
|
+
expect(hasParentContextMock).toBeCalled();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* useHasChildContext tests
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
test("useHasChildContext undefined asset", () => {
|
|
120
|
+
expect(useHasChildContext(undefined, "query")).toBe(false);
|
|
121
|
+
expect(hasChildContextMock).not.toBeCalled();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("useHasChildContext string asset", () => {
|
|
125
|
+
useHasChildContext("testId", "query");
|
|
126
|
+
expect(hasChildContextMock).toBeCalled();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("useHasChildContext object asset", () => {
|
|
130
|
+
useHasChildContext({ id: "testId", type: "testType" }, "query");
|
|
131
|
+
expect(hasChildContextMock).toBeCalled();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* useGetParentProp tests
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
test("useGetParentProp undefined asset", () => {
|
|
139
|
+
expect(useGetParentProp(undefined)).toBe(undefined);
|
|
140
|
+
expect(getParentPropMock).not.toBeCalled();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("useGetParentProp string asset", () => {
|
|
144
|
+
useGetParentProp("testId");
|
|
145
|
+
expect(getParentPropMock).toBeCalled();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("useGetParentProp object asset", () => {
|
|
149
|
+
useGetParentProp({ id: "testId", type: "testType" });
|
|
150
|
+
expect(getParentPropMock).toBeCalled();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* useGetPath tests
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
test("useGetPath undefined asset", () => {
|
|
158
|
+
expect(useGetPath(undefined, "query")).toBe(undefined);
|
|
159
|
+
expect(getPathMock).not.toBeCalled();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("useGetPath string asset", () => {
|
|
163
|
+
useGetPath("testId", "query");
|
|
164
|
+
expect(getPathMock).toBeCalled();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("useGetPath object asset", () => {
|
|
168
|
+
useGetPath({ id: "testId", type: "testType" }, "query");
|
|
169
|
+
expect(getPathMock).toBeCalled();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* useGetParent tests
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
test("useGetParent undefined asset", () => {
|
|
177
|
+
expect(useGetParent(undefined, "query")).toBe(undefined);
|
|
178
|
+
expect(getParentMock).not.toBeCalled();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("useGetParent string asset", () => {
|
|
182
|
+
useGetParent("testId", "query");
|
|
183
|
+
expect(getParentMock).toBeCalled();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("useGetParent object asset", () => {
|
|
187
|
+
useGetParent({ id: "testId", type: "testType" }, "query");
|
|
188
|
+
expect(getParentMock).toBeCalled();
|
|
189
|
+
});
|
|
190
|
+
});
|
package/src/context.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { CheckPathPlugin } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { CheckPathPlugin } from "@player-ui/check-path-plugin";
|
|
3
3
|
|
|
4
4
|
export interface CheckPathContextType {
|
|
5
5
|
/** The core plugin to talk to */
|
package/src/hooks.tsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { Query } from
|
|
3
|
-
import type { Asset } from
|
|
4
|
-
import { CheckPathContext } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Query } from "@player-ui/check-path-plugin";
|
|
3
|
+
import type { Asset } from "@player-ui/react";
|
|
4
|
+
import { CheckPathContext } from "./context";
|
|
5
5
|
|
|
6
6
|
export type AssetOrID = Asset | string;
|
|
7
7
|
|
|
8
8
|
/** get the id for an asset */
|
|
9
9
|
function getId(asset: AssetOrID): string {
|
|
10
|
-
return typeof asset ===
|
|
10
|
+
return typeof asset === "string" ? asset : asset.id;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/** hook to check if the asset has the given parents */
|
|
14
14
|
export function useHasParentContext(
|
|
15
15
|
asset: AssetOrID | undefined,
|
|
16
|
-
query: Query | Query[]
|
|
16
|
+
query: Query | Query[],
|
|
17
17
|
): boolean {
|
|
18
18
|
const { plugin } = React.useContext(CheckPathContext);
|
|
19
19
|
|
|
@@ -27,7 +27,7 @@ export function useHasParentContext(
|
|
|
27
27
|
/** hook to check if the asset has the given children */
|
|
28
28
|
export function useHasChildContext(
|
|
29
29
|
asset: AssetOrID | undefined,
|
|
30
|
-
query: Query | Query[]
|
|
30
|
+
query: Query | Query[],
|
|
31
31
|
): boolean {
|
|
32
32
|
const { plugin } = React.useContext(CheckPathContext);
|
|
33
33
|
|
|
@@ -40,7 +40,7 @@ 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 | undefined
|
|
43
|
+
asset: AssetOrID | undefined,
|
|
44
44
|
): string | number | undefined {
|
|
45
45
|
const { plugin } = React.useContext(CheckPathContext);
|
|
46
46
|
|
|
@@ -54,7 +54,7 @@ export function useGetParentProp(
|
|
|
54
54
|
/** hook to get the path of the asset in the view */
|
|
55
55
|
export function useGetPath(
|
|
56
56
|
asset: AssetOrID | undefined,
|
|
57
|
-
query?: Query | Query[]
|
|
57
|
+
query?: Query | Query[],
|
|
58
58
|
): Array<string | number> | undefined {
|
|
59
59
|
const { plugin } = React.useContext(CheckPathContext);
|
|
60
60
|
|
|
@@ -68,7 +68,7 @@ export function useGetPath(
|
|
|
68
68
|
/** get the parent of the given asset */
|
|
69
69
|
export function useGetParent<T extends Asset>(
|
|
70
70
|
asset: AssetOrID | undefined,
|
|
71
|
-
query?: Query | Query[]
|
|
71
|
+
query?: Query | Query[],
|
|
72
72
|
): T | undefined {
|
|
73
73
|
const { plugin } = React.useContext(CheckPathContext);
|
|
74
74
|
|
package/src/index.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { ReactPlayer, ReactPlayerPlugin } from
|
|
3
|
-
import { CheckPathPlugin as CheckPathCorePlugin } from
|
|
4
|
-
import { CheckPathContext } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ReactPlayer, ReactPlayerPlugin } from "@player-ui/react";
|
|
3
|
+
import { CheckPathPlugin as CheckPathCorePlugin } from "@player-ui/check-path-plugin";
|
|
4
|
+
import { CheckPathContext } from "./context";
|
|
5
5
|
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
6
|
+
export * from "./hooks";
|
|
7
|
+
export * from "./context";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* A plugin for adding the check-path provider to the web-player
|
|
@@ -13,15 +13,20 @@ export class CheckPathPlugin
|
|
|
13
13
|
extends CheckPathCorePlugin
|
|
14
14
|
implements ReactPlayerPlugin
|
|
15
15
|
{
|
|
16
|
-
name =
|
|
16
|
+
name = "check-path-web";
|
|
17
17
|
|
|
18
18
|
applyReact(rp: ReactPlayer) {
|
|
19
19
|
rp.hooks.webComponent.tap(this.name, (Comp) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
21
|
+
const plugin = this;
|
|
22
|
+
|
|
23
|
+
return function CheckPathContextWrapper() {
|
|
24
|
+
return (
|
|
25
|
+
<CheckPathContext.Provider value={{ plugin }}>
|
|
26
|
+
<Comp />
|
|
27
|
+
</CheckPathContext.Provider>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
25
30
|
});
|
|
26
31
|
}
|
|
27
32
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { CheckPathPlugin } from "@player-ui/check-path-plugin";
|
|
3
|
+
export interface CheckPathContextType {
|
|
4
|
+
/** The core plugin to talk to */
|
|
5
|
+
plugin?: CheckPathPlugin;
|
|
6
|
+
}
|
|
7
|
+
export declare const CheckPathContext: React.Context<CheckPathContextType>;
|
|
8
|
+
//# sourceMappingURL=context.d.ts.map
|
package/types/hooks.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Query } from "@player-ui/check-path-plugin";
|
|
2
|
+
import type { Asset } from "@player-ui/react";
|
|
3
|
+
export type AssetOrID = Asset | string;
|
|
4
|
+
/** hook to check if the asset has the given parents */
|
|
5
|
+
export declare function useHasParentContext(asset: AssetOrID | undefined, query: Query | Query[]): boolean;
|
|
6
|
+
/** hook to check if the asset has the given children */
|
|
7
|
+
export declare function useHasChildContext(asset: AssetOrID | undefined, query: Query | Query[]): boolean;
|
|
8
|
+
/** hook to get the prop of the given asset on the parent */
|
|
9
|
+
export declare function useGetParentProp(asset: AssetOrID | undefined): string | number | undefined;
|
|
10
|
+
/** hook to get the path of the asset in the view */
|
|
11
|
+
export declare function useGetPath(asset: AssetOrID | undefined, query?: Query | Query[]): Array<string | number> | undefined;
|
|
12
|
+
/** get the parent of the given asset */
|
|
13
|
+
export declare function useGetParent<T extends Asset>(asset: AssetOrID | undefined, query?: Query | Query[]): T | undefined;
|
|
14
|
+
//# sourceMappingURL=hooks.d.ts.map
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactPlayer, ReactPlayerPlugin } from "@player-ui/react";
|
|
2
|
+
import { CheckPathPlugin as CheckPathCorePlugin } from "@player-ui/check-path-plugin";
|
|
3
|
+
export * from "./hooks";
|
|
4
|
+
export * from "./context";
|
|
5
|
+
/**
|
|
6
|
+
* A plugin for adding the check-path provider to the web-player
|
|
7
|
+
*/
|
|
8
|
+
export declare class CheckPathPlugin extends CheckPathCorePlugin implements ReactPlayerPlugin {
|
|
9
|
+
name: string;
|
|
10
|
+
applyReact(rp: ReactPlayer): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.cjs.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var React = require('react');
|
|
6
|
-
var checkPathPlugin = require('@player-ui/check-path-plugin');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
11
|
-
|
|
12
|
-
const CheckPathContext = React__default["default"].createContext({
|
|
13
|
-
plugin: void 0
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
function getId(asset) {
|
|
17
|
-
return typeof asset === "string" ? asset : asset.id;
|
|
18
|
-
}
|
|
19
|
-
function useHasParentContext(asset, query) {
|
|
20
|
-
const { plugin } = React__default["default"].useContext(CheckPathContext);
|
|
21
|
-
if (!plugin || !asset) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return plugin.hasParentContext(getId(asset), query);
|
|
25
|
-
}
|
|
26
|
-
function useHasChildContext(asset, query) {
|
|
27
|
-
const { plugin } = React__default["default"].useContext(CheckPathContext);
|
|
28
|
-
if (!plugin || !asset) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
return plugin.hasChildContext(getId(asset), query);
|
|
32
|
-
}
|
|
33
|
-
function useGetParentProp(asset) {
|
|
34
|
-
const { plugin } = React__default["default"].useContext(CheckPathContext);
|
|
35
|
-
if (!plugin || !asset) {
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
return plugin.getParentProp(getId(asset));
|
|
39
|
-
}
|
|
40
|
-
function useGetPath(asset, query) {
|
|
41
|
-
const { plugin } = React__default["default"].useContext(CheckPathContext);
|
|
42
|
-
if (!plugin || !asset) {
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
|
-
return plugin.getPath(getId(asset), query);
|
|
46
|
-
}
|
|
47
|
-
function useGetParent(asset, query) {
|
|
48
|
-
const { plugin } = React__default["default"].useContext(CheckPathContext);
|
|
49
|
-
if (!plugin || !asset) {
|
|
50
|
-
return void 0;
|
|
51
|
-
}
|
|
52
|
-
return plugin.getParent(getId(asset), query);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
class CheckPathPlugin extends checkPathPlugin.CheckPathPlugin {
|
|
56
|
-
constructor() {
|
|
57
|
-
super(...arguments);
|
|
58
|
-
this.name = "check-path-web";
|
|
59
|
-
}
|
|
60
|
-
applyReact(rp) {
|
|
61
|
-
rp.hooks.webComponent.tap(this.name, (Comp) => {
|
|
62
|
-
return () => /* @__PURE__ */ React__default["default"].createElement(CheckPathContext.Provider, {
|
|
63
|
-
value: { plugin: this }
|
|
64
|
-
}, /* @__PURE__ */ React__default["default"].createElement(Comp, null));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exports.CheckPathContext = CheckPathContext;
|
|
70
|
-
exports.CheckPathPlugin = CheckPathPlugin;
|
|
71
|
-
exports.useGetParent = useGetParent;
|
|
72
|
-
exports.useGetParentProp = useGetParentProp;
|
|
73
|
-
exports.useGetPath = useGetPath;
|
|
74
|
-
exports.useHasChildContext = useHasChildContext;
|
|
75
|
-
exports.useHasParentContext = useHasParentContext;
|
|
76
|
-
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ReactPlayerPlugin, ReactPlayer } from '@player-ui/react';
|
|
2
|
-
import { Query, CheckPathPlugin as CheckPathPlugin$1 } from '@player-ui/check-path-plugin';
|
|
3
|
-
import { Asset } from '@player-ui/player';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
|
|
6
|
-
declare type AssetOrID = Asset | string;
|
|
7
|
-
/** hook to check if the asset has the given parents */
|
|
8
|
-
declare function useHasParentContext(asset: AssetOrID | undefined, query: Query | Query[]): boolean;
|
|
9
|
-
/** hook to check if the asset has the given children */
|
|
10
|
-
declare function useHasChildContext(asset: AssetOrID | undefined, query: Query | Query[]): boolean;
|
|
11
|
-
/** hook to get the prop of the given asset on the parent */
|
|
12
|
-
declare function useGetParentProp(asset: AssetOrID | undefined): string | number | undefined;
|
|
13
|
-
/** hook to get the path of the asset in the view */
|
|
14
|
-
declare function useGetPath(asset: AssetOrID | undefined, query?: Query | Query[]): Array<string | number> | undefined;
|
|
15
|
-
/** get the parent of the given asset */
|
|
16
|
-
declare function useGetParent<T extends Asset>(asset: AssetOrID | undefined, query?: Query | Query[]): T | undefined;
|
|
17
|
-
|
|
18
|
-
interface CheckPathContextType {
|
|
19
|
-
/** The core plugin to talk to */
|
|
20
|
-
plugin?: CheckPathPlugin$1;
|
|
21
|
-
}
|
|
22
|
-
declare const CheckPathContext: React.Context<CheckPathContextType>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A plugin for adding the check-path provider to the web-player
|
|
26
|
-
*/
|
|
27
|
-
declare class CheckPathPlugin extends CheckPathPlugin$1 implements ReactPlayerPlugin {
|
|
28
|
-
name: string;
|
|
29
|
-
applyReact(rp: ReactPlayer): void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { AssetOrID, CheckPathContext, CheckPathContextType, CheckPathPlugin, useGetParent, useGetParentProp, useGetPath, useHasChildContext, useHasParentContext };
|
package/dist/index.esm.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { CheckPathPlugin as CheckPathPlugin$1 } from '@player-ui/check-path-plugin';
|
|
3
|
-
|
|
4
|
-
const CheckPathContext = React.createContext({
|
|
5
|
-
plugin: void 0
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
function getId(asset) {
|
|
9
|
-
return typeof asset === "string" ? asset : asset.id;
|
|
10
|
-
}
|
|
11
|
-
function useHasParentContext(asset, query) {
|
|
12
|
-
const { plugin } = React.useContext(CheckPathContext);
|
|
13
|
-
if (!plugin || !asset) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return plugin.hasParentContext(getId(asset), query);
|
|
17
|
-
}
|
|
18
|
-
function useHasChildContext(asset, query) {
|
|
19
|
-
const { plugin } = React.useContext(CheckPathContext);
|
|
20
|
-
if (!plugin || !asset) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return plugin.hasChildContext(getId(asset), query);
|
|
24
|
-
}
|
|
25
|
-
function useGetParentProp(asset) {
|
|
26
|
-
const { plugin } = React.useContext(CheckPathContext);
|
|
27
|
-
if (!plugin || !asset) {
|
|
28
|
-
return void 0;
|
|
29
|
-
}
|
|
30
|
-
return plugin.getParentProp(getId(asset));
|
|
31
|
-
}
|
|
32
|
-
function useGetPath(asset, query) {
|
|
33
|
-
const { plugin } = React.useContext(CheckPathContext);
|
|
34
|
-
if (!plugin || !asset) {
|
|
35
|
-
return void 0;
|
|
36
|
-
}
|
|
37
|
-
return plugin.getPath(getId(asset), query);
|
|
38
|
-
}
|
|
39
|
-
function useGetParent(asset, query) {
|
|
40
|
-
const { plugin } = React.useContext(CheckPathContext);
|
|
41
|
-
if (!plugin || !asset) {
|
|
42
|
-
return void 0;
|
|
43
|
-
}
|
|
44
|
-
return plugin.getParent(getId(asset), query);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class CheckPathPlugin extends CheckPathPlugin$1 {
|
|
48
|
-
constructor() {
|
|
49
|
-
super(...arguments);
|
|
50
|
-
this.name = "check-path-web";
|
|
51
|
-
}
|
|
52
|
-
applyReact(rp) {
|
|
53
|
-
rp.hooks.webComponent.tap(this.name, (Comp) => {
|
|
54
|
-
return () => /* @__PURE__ */ React.createElement(CheckPathContext.Provider, {
|
|
55
|
-
value: { plugin: this }
|
|
56
|
-
}, /* @__PURE__ */ React.createElement(Comp, null));
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { CheckPathContext, CheckPathPlugin, useGetParent, useGetParentProp, useGetPath, useHasChildContext, useHasParentContext };
|
|
62
|
-
//# sourceMappingURL=index.esm.js.map
|