@player-ui/beacon-plugin 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/BeaconPlugin.native.js +11312 -0
- package/dist/BeaconPlugin.native.js.map +1 -0
- package/dist/cjs/index.cjs +163 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +135 -0
- package/dist/index.mjs +135 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +26 -60
- package/src/beacon.ts +19 -18
- package/src/index.test.ts +476 -0
- package/src/index.ts +2 -2
- package/src/symbols.ts +1 -1
- package/{dist/index.d.ts → types/beacon.d.ts} +13 -18
- package/types/index.d.ts +3 -0
- package/types/symbols.d.ts +2 -0
- package/dist/beacon-plugin.dev.js +0 -10749
- package/dist/beacon-plugin.prod.js +0 -2
- package/dist/index.cjs.js +0 -171
- package/dist/index.esm.js +0 -166
package/dist/index.esm.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { AsyncSeriesWaterfallHook, SyncBailHook, SyncHook } from 'tapable-ts';
|
|
2
|
-
import { resolveDataRefs } from '@player-ui/player';
|
|
3
|
-
import { setIn } from 'timm';
|
|
4
|
-
|
|
5
|
-
const BeaconPluginSymbol = Symbol.for("BeaconPlugin");
|
|
6
|
-
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defProps = Object.defineProperties;
|
|
9
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __async = (__this, __arguments, generator) => {
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
var fulfilled = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.next(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var rejected = (value) => {
|
|
36
|
-
try {
|
|
37
|
-
step(generator.throw(value));
|
|
38
|
-
} catch (e) {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
43
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
const _BeaconPlugin = class {
|
|
47
|
-
constructor(options) {
|
|
48
|
-
this.name = "Beacon";
|
|
49
|
-
this.symbol = _BeaconPlugin.Symbol;
|
|
50
|
-
this.beaconContext = {
|
|
51
|
-
view: void 0
|
|
52
|
-
};
|
|
53
|
-
this.hooks = {
|
|
54
|
-
buildBeacon: new AsyncSeriesWaterfallHook(),
|
|
55
|
-
cancelBeacon: new SyncBailHook(),
|
|
56
|
-
publishBeacon: new SyncHook()
|
|
57
|
-
};
|
|
58
|
-
if (options == null ? void 0 : options.plugins) {
|
|
59
|
-
options.plugins.forEach((plugin) => {
|
|
60
|
-
plugin.apply(this);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (options == null ? void 0 : options.callback) {
|
|
64
|
-
this.hooks.publishBeacon.tap("BeaconCallback", (beacon) => {
|
|
65
|
-
if (options.callback) {
|
|
66
|
-
options.callback(beacon);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
apply(player) {
|
|
72
|
-
this.player = player;
|
|
73
|
-
this.logger = player.logger;
|
|
74
|
-
player.hooks.state.tap(this.name, (playerState) => {
|
|
75
|
-
if (playerState.status === "in-progress") {
|
|
76
|
-
this.resolveDataRefs = (data) => resolveDataRefs(data, {
|
|
77
|
-
model: playerState.controllers.data,
|
|
78
|
-
evaluate: playerState.controllers.expression.evaluate
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
player.hooks.viewController.tap(this.name, (vc) => {
|
|
83
|
-
this.beaconContext = {
|
|
84
|
-
view: void 0
|
|
85
|
-
};
|
|
86
|
-
vc.hooks.view.tap(this.name, (view) => {
|
|
87
|
-
let beaconedView = false;
|
|
88
|
-
view.hooks.parser.tap(this.name, (parser) => {
|
|
89
|
-
parser.hooks.onCreateASTNode.tap(this.name, (obj) => {
|
|
90
|
-
var _a, _b, _c, _d;
|
|
91
|
-
if ((obj == null ? void 0 : obj.type) !== "asset" && (obj == null ? void 0 : obj.type) !== "view")
|
|
92
|
-
return void 0;
|
|
93
|
-
const propertiesToSkip = (_c = (_b = (_a = obj.plugins) == null ? void 0 : _a.stringResolver) == null ? void 0 : _b.propertiesToSkip) != null ? _c : [];
|
|
94
|
-
if (propertiesToSkip.includes("beacon"))
|
|
95
|
-
return void 0;
|
|
96
|
-
obj.plugins = setIn((_d = obj.plugins) != null ? _d : {}, ["stringResolver", "propertiesToSkip"], ["beacon", ...propertiesToSkip]);
|
|
97
|
-
return obj;
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
view.hooks.onUpdate.tap(this.name, (viewUpdate) => {
|
|
101
|
-
this.beaconContext = {
|
|
102
|
-
view: viewUpdate
|
|
103
|
-
};
|
|
104
|
-
if (!beaconedView) {
|
|
105
|
-
this.beacon({
|
|
106
|
-
action: "viewed",
|
|
107
|
-
element: "view",
|
|
108
|
-
asset: viewUpdate,
|
|
109
|
-
view: viewUpdate
|
|
110
|
-
});
|
|
111
|
-
beaconedView = true;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {
|
|
117
|
-
evaluator.addExpressionFunction("beacon", (_ctx, action, data) => {
|
|
118
|
-
const view = this.beaconContext.view || {};
|
|
119
|
-
this.beacon({
|
|
120
|
-
action,
|
|
121
|
-
data,
|
|
122
|
-
element: "view",
|
|
123
|
-
asset: view,
|
|
124
|
-
view
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
beacon(event) {
|
|
130
|
-
const { action, element, asset, view } = event;
|
|
131
|
-
const { view: currentView } = this.beaconContext;
|
|
132
|
-
setTimeout(() => __async(this, null, function* () {
|
|
133
|
-
var _a, _b, _c, _d, _e, _f;
|
|
134
|
-
const unresolvedData = (event == null ? void 0 : event.data) || ((_b = (_a = event.asset) == null ? void 0 : _a.metaData) == null ? void 0 : _b.beacon);
|
|
135
|
-
const data = (_d = (_c = this.resolveDataRefs) == null ? void 0 : _c.call(this, unresolvedData)) != null ? _d : unresolvedData;
|
|
136
|
-
const defaultBeacon = {
|
|
137
|
-
action,
|
|
138
|
-
element,
|
|
139
|
-
data,
|
|
140
|
-
assetId: asset == null ? void 0 : asset.id,
|
|
141
|
-
viewId: currentView == null ? void 0 : currentView.id
|
|
142
|
-
};
|
|
143
|
-
const state = (_e = this.player) == null ? void 0 : _e.getState();
|
|
144
|
-
const hookArgs = __spreadProps(__spreadValues({}, event), {
|
|
145
|
-
data,
|
|
146
|
-
state,
|
|
147
|
-
view: view != null ? view : currentView,
|
|
148
|
-
logger: this.logger
|
|
149
|
-
});
|
|
150
|
-
let beacon = (yield this.hooks.buildBeacon.call(defaultBeacon, hookArgs)) || defaultBeacon;
|
|
151
|
-
if (beacon !== defaultBeacon && this.resolveDataRefs) {
|
|
152
|
-
beacon = this.resolveDataRefs(beacon);
|
|
153
|
-
}
|
|
154
|
-
const shouldCancel = this.hooks.cancelBeacon.call(hookArgs) || false;
|
|
155
|
-
if (!shouldCancel) {
|
|
156
|
-
(_f = this.logger) == null ? void 0 : _f.debug("Sending beacon event", beacon);
|
|
157
|
-
this.hooks.publishBeacon.call(beacon);
|
|
158
|
-
}
|
|
159
|
-
}), 0);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
let BeaconPlugin = _BeaconPlugin;
|
|
163
|
-
BeaconPlugin.Symbol = BeaconPluginSymbol;
|
|
164
|
-
|
|
165
|
-
export { BeaconPlugin, BeaconPluginSymbol };
|
|
166
|
-
//# sourceMappingURL=index.esm.js.map
|