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