@player-ui/beacon-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,59 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var beaconPlugin = require('@player-ui/beacon-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
+ var __defProp = Object.defineProperty;
13
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols)
22
+ for (var prop of __getOwnPropSymbols(b)) {
23
+ if (__propIsEnum.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ }
26
+ return a;
27
+ };
28
+ const BeaconContext = React__default["default"].createContext({
29
+ handler: () => void 0
30
+ });
31
+ function useBeacon(initialArgs) {
32
+ const { handler } = React__default["default"].useContext(BeaconContext);
33
+ return (options) => {
34
+ handler(__spreadValues(__spreadValues({}, initialArgs), options != null ? options : {}));
35
+ };
36
+ }
37
+ class BeaconPlugin extends beaconPlugin.BeaconPlugin {
38
+ constructor() {
39
+ super(...arguments);
40
+ this.name = "beacon-web-plugin";
41
+ }
42
+ applyWeb(webPlayer) {
43
+ const handler = this.beacon.bind(this);
44
+ webPlayer.hooks.webComponent.tap(this.name, (Comp) => () => /* @__PURE__ */ React__default["default"].createElement(BeaconContext.Provider, {
45
+ value: { handler }
46
+ }, /* @__PURE__ */ React__default["default"].createElement(Comp, null)));
47
+ }
48
+ }
49
+
50
+ exports.BeaconContext = BeaconContext;
51
+ exports.BeaconPlugin = BeaconPlugin;
52
+ exports.useBeacon = useBeacon;
53
+ Object.keys(beaconPlugin).forEach(function (k) {
54
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
55
+ enumerable: true,
56
+ get: function () { return beaconPlugin[k]; }
57
+ });
58
+ });
59
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { WebPlayerPlugin, WebPlayer } from '@player-ui/react';
3
+ import { BeaconArgs, BeaconPlugin as BeaconPlugin$1 } from '@player-ui/beacon-plugin';
4
+ export * from '@player-ui/beacon-plugin';
5
+
6
+ declare type BeaconHandler = (options: BeaconArgs) => void;
7
+ interface BeaconContextType {
8
+ /** A callback for when assets beacon data */
9
+ handler: BeaconHandler;
10
+ }
11
+ declare const BeaconContext: React.Context<BeaconContextType>;
12
+ declare type BeaconCallbackArgs = Omit<BeaconArgs, 'view'>;
13
+ declare type BeaconCallbackFn<T extends Partial<BeaconCallbackArgs>> = (options?: T) => void;
14
+ /** A hook for creating a beacon handler */
15
+ declare function useBeacon<T extends Partial<BeaconCallbackArgs>>(initialArgs: T): BeaconCallbackFn<Omit<BeaconCallbackArgs, keyof T>>;
16
+ /**
17
+ * A plugin for adding beacon support to a web-player
18
+ */
19
+ declare class BeaconPlugin extends BeaconPlugin$1 implements WebPlayerPlugin {
20
+ name: string;
21
+ applyWeb(webPlayer: WebPlayer): void;
22
+ }
23
+
24
+ export { BeaconCallbackArgs, BeaconCallbackFn, BeaconContext, BeaconContextType, BeaconHandler, BeaconPlugin, useBeacon };
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import { BeaconPlugin as BeaconPlugin$1 } from '@player-ui/beacon-plugin';
3
+ export * from '@player-ui/beacon-plugin';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ const BeaconContext = React.createContext({
22
+ handler: () => void 0
23
+ });
24
+ function useBeacon(initialArgs) {
25
+ const { handler } = React.useContext(BeaconContext);
26
+ return (options) => {
27
+ handler(__spreadValues(__spreadValues({}, initialArgs), options != null ? options : {}));
28
+ };
29
+ }
30
+ class BeaconPlugin extends BeaconPlugin$1 {
31
+ constructor() {
32
+ super(...arguments);
33
+ this.name = "beacon-web-plugin";
34
+ }
35
+ applyWeb(webPlayer) {
36
+ const handler = this.beacon.bind(this);
37
+ webPlayer.hooks.webComponent.tap(this.name, (Comp) => () => /* @__PURE__ */ React.createElement(BeaconContext.Provider, {
38
+ value: { handler }
39
+ }, /* @__PURE__ */ React.createElement(Comp, null)));
40
+ }
41
+ }
42
+
43
+ export { BeaconContext, BeaconPlugin, useBeacon };
44
+ //# sourceMappingURL=index.esm.js.map
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@player-ui/beacon-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/binding-grammar": "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
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import type { WebPlayer, WebPlayerPlugin } from '@player-ui/react';
3
+ import type { BeaconArgs } from '@player-ui/beacon-plugin';
4
+ import { BeaconPlugin as BeaconCorePlugin } from '@player-ui/beacon-plugin';
5
+
6
+ export * from '@player-ui/beacon-plugin';
7
+
8
+ export type BeaconHandler = (options: BeaconArgs) => void;
9
+
10
+ export interface BeaconContextType {
11
+ /** A callback for when assets beacon data */
12
+ handler: BeaconHandler;
13
+ }
14
+
15
+ export const BeaconContext = React.createContext<BeaconContextType>({
16
+ handler: () => undefined,
17
+ });
18
+
19
+ export type BeaconCallbackArgs = Omit<BeaconArgs, 'view'>;
20
+
21
+ export type BeaconCallbackFn<T extends Partial<BeaconCallbackArgs>> = (
22
+ options?: T
23
+ ) => void;
24
+
25
+ /** A hook for creating a beacon handler */
26
+ export function useBeacon<T extends Partial<BeaconCallbackArgs>>(
27
+ initialArgs: T
28
+ ): BeaconCallbackFn<Omit<BeaconCallbackArgs, keyof T>> {
29
+ const { handler } = React.useContext(BeaconContext);
30
+
31
+ return (options?: Omit<BeaconCallbackArgs, keyof T>) => {
32
+ handler({
33
+ ...initialArgs,
34
+ ...(options ?? {}),
35
+ } as BeaconCallbackArgs);
36
+ };
37
+ }
38
+
39
+ /**
40
+ * A plugin for adding beacon support to a web-player
41
+ */
42
+ export class BeaconPlugin extends BeaconCorePlugin implements WebPlayerPlugin {
43
+ name = 'beacon-web-plugin';
44
+
45
+ applyWeb(webPlayer: WebPlayer) {
46
+ const handler = this.beacon.bind(this);
47
+
48
+ webPlayer.hooks.webComponent.tap(this.name, (Comp) => () => (
49
+ <BeaconContext.Provider value={{ handler }}>
50
+ <Comp />
51
+ </BeaconContext.Provider>
52
+ ));
53
+ }
54
+ }