@player-ui/expression-plugin 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,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ class ExpressionPlugin {
6
+ constructor(expressionMap) {
7
+ this.name = "ExpressionPlugin";
8
+ this.expressions = expressionMap;
9
+ }
10
+ apply(player) {
11
+ player.hooks.expressionEvaluator.tap(this.name, (expEvaluator) => {
12
+ this.expressions.forEach((handler, name) => {
13
+ expEvaluator.addExpressionFunction(name, handler);
14
+ });
15
+ });
16
+ }
17
+ }
18
+
19
+ exports.ExpressionPlugin = ExpressionPlugin;
20
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1,18 @@
1
+ import { PlayerPlugin, Player } from '@player-ui/player';
2
+ import { ExpressionHandler } from '@player-ui/expressions';
3
+
4
+ declare type ExpressionMap = Map<string, ExpressionHandler<any[], any>>;
5
+ /**
6
+ * The ExpressionPlugin is an easy way to inject custom expression handlers into the running player instance.
7
+ * Simply supply a map of function name to handler, and the expressions will be available inside of the Content.
8
+ *
9
+ * Any subsequent expressions registered with the same name will override previous handlers.
10
+ */
11
+ declare class ExpressionPlugin implements PlayerPlugin {
12
+ name: string;
13
+ private expressions;
14
+ constructor(expressionMap: ExpressionMap);
15
+ apply(player: Player): void;
16
+ }
17
+
18
+ export { ExpressionMap, ExpressionPlugin };
@@ -0,0 +1,16 @@
1
+ class ExpressionPlugin {
2
+ constructor(expressionMap) {
3
+ this.name = "ExpressionPlugin";
4
+ this.expressions = expressionMap;
5
+ }
6
+ apply(player) {
7
+ player.hooks.expressionEvaluator.tap(this.name, (expEvaluator) => {
8
+ this.expressions.forEach((handler, name) => {
9
+ expEvaluator.addExpressionFunction(name, handler);
10
+ });
11
+ });
12
+ }
13
+ }
14
+
15
+ export { ExpressionPlugin };
16
+ //# sourceMappingURL=index.esm.js.map
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@player-ui/expression-plugin",
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
+ "tapable": "1.1.3",
13
+ "@types/tapable": "^1.0.5",
14
+ "@babel/runtime": "7.15.4"
15
+ },
16
+ "main": "dist/index.cjs.js",
17
+ "module": "dist/index.esm.js",
18
+ "typings": "dist/index.d.ts"
19
+ }
package/src/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { Player, PlayerPlugin } from '@player-ui/player';
2
+ import type { ExpressionHandler } from '@player-ui/expressions';
3
+
4
+ export type ExpressionMap = Map<string, ExpressionHandler<any[], any>>;
5
+
6
+ /**
7
+ * The ExpressionPlugin is an easy way to inject custom expression handlers into the running player instance.
8
+ * Simply supply a map of function name to handler, and the expressions will be available inside of the Content.
9
+ *
10
+ * Any subsequent expressions registered with the same name will override previous handlers.
11
+ */
12
+ export class ExpressionPlugin implements PlayerPlugin {
13
+ name = 'ExpressionPlugin';
14
+ private expressions: ExpressionMap;
15
+
16
+ constructor(expressionMap: ExpressionMap) {
17
+ this.expressions = expressionMap;
18
+ }
19
+
20
+ apply(player: Player) {
21
+ player.hooks.expressionEvaluator.tap(this.name, (expEvaluator) => {
22
+ this.expressions.forEach((handler, name) => {
23
+ expEvaluator.addExpressionFunction(name, handler);
24
+ });
25
+ });
26
+ }
27
+ }