@player-ui/reference-assets-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,124 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var assetTransformPlugin = require('@player-ui/asset-transform-plugin');
6
+
7
+ var __defProp$1 = Object.defineProperty;
8
+ var __defProps$1 = Object.defineProperties;
9
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
10
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues$1 = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp$1.call(b, prop))
17
+ __defNormalProp$1(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols$1)
19
+ for (var prop of __getOwnPropSymbols$1(b)) {
20
+ if (__propIsEnum$1.call(b, prop))
21
+ __defNormalProp$1(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
26
+ const inputTransform = (asset, options) => {
27
+ var _a, _b;
28
+ return __spreadProps$1(__spreadValues$1({}, asset), {
29
+ format(val) {
30
+ if (asset.binding === void 0) {
31
+ return val;
32
+ }
33
+ return options.data.format(asset.binding, val);
34
+ },
35
+ set(val) {
36
+ if (asset.binding === void 0) {
37
+ return;
38
+ }
39
+ return options.data.model.set([[asset.binding, val]], {
40
+ formatted: true
41
+ });
42
+ },
43
+ value: asset.binding === void 0 ? "" : options.data.model.get(asset.binding, {
44
+ includeInvalid: true,
45
+ formatted: true
46
+ }),
47
+ validation: asset.binding === void 0 ? void 0 : (_a = options.validation) == null ? void 0 : _a.get(asset.binding, { track: true }),
48
+ dataType: asset.binding === void 0 ? void 0 : (_b = options.validation) == null ? void 0 : _b.type(asset.binding)
49
+ });
50
+ };
51
+
52
+ var __defProp = Object.defineProperty;
53
+ var __defProps = Object.defineProperties;
54
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
55
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
56
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
57
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
58
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
59
+ var __spreadValues = (a, b) => {
60
+ for (var prop in b || (b = {}))
61
+ if (__hasOwnProp.call(b, prop))
62
+ __defNormalProp(a, prop, b[prop]);
63
+ if (__getOwnPropSymbols)
64
+ for (var prop of __getOwnPropSymbols(b)) {
65
+ if (__propIsEnum.call(b, prop))
66
+ __defNormalProp(a, prop, b[prop]);
67
+ }
68
+ return a;
69
+ };
70
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
71
+ function isBackAction(action) {
72
+ return action.value === "Prev";
73
+ }
74
+ const transform = (action, options) => {
75
+ return __spreadProps(__spreadValues({}, action), {
76
+ run() {
77
+ var _a, _b;
78
+ if (action.exp) {
79
+ options.evaluate(action.exp);
80
+ }
81
+ if (action.value) {
82
+ const skipValidation = (_a = action.metaData) == null ? void 0 : _a.skipValidation;
83
+ (_b = options.transition) == null ? void 0 : _b.call(options, action.value, { force: skipValidation });
84
+ }
85
+ }
86
+ });
87
+ };
88
+ const expPropTransform = (asset) => {
89
+ var _a, _b, _c, _d, _e, _f;
90
+ const skipArray = (_b = (_a = asset.plugins) == null ? void 0 : _a.stringResolver) == null ? void 0 : _b.propertiesToSkip;
91
+ if (skipArray && skipArray.indexOf("exp") > 1) {
92
+ return asset;
93
+ }
94
+ return __spreadProps(__spreadValues({}, asset), {
95
+ plugins: __spreadProps(__spreadValues({}, asset.plugins), {
96
+ stringResolver: __spreadProps(__spreadValues({}, (_c = asset == null ? void 0 : asset.plugins) == null ? void 0 : _c.stringResolver), {
97
+ propertiesToSkip: [
98
+ ...(_f = (_e = (_d = asset.plugins) == null ? void 0 : _d.stringResolver) == null ? void 0 : _e.propertiesToSkip) != null ? _f : [],
99
+ "exp"
100
+ ]
101
+ })
102
+ })
103
+ });
104
+ };
105
+ const actionTransform = assetTransformPlugin.compose(transform, assetTransformPlugin.composeBefore(expPropTransform));
106
+
107
+ class ReferenceAssetsPlugin {
108
+ constructor() {
109
+ this.name = "reference-assets-transforms";
110
+ }
111
+ apply(player) {
112
+ player.registerPlugin(new assetTransformPlugin.AssetTransformPlugin([
113
+ [{ type: "action" }, actionTransform],
114
+ [{ type: "input" }, inputTransform]
115
+ ]));
116
+ }
117
+ }
118
+
119
+ exports.ReferenceAssetsPlugin = ReferenceAssetsPlugin;
120
+ exports.actionTransform = actionTransform;
121
+ exports.expPropTransform = expPropTransform;
122
+ exports.inputTransform = inputTransform;
123
+ exports.isBackAction = isBackAction;
124
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1,134 @@
1
+ import * as _player_ui_player from '@player-ui/player';
2
+ import { Asset, AssetWrapper, Binding, ValidationResponse, Schema, TransformFunction, Expression, BeforeTransformFunction, PlayerPlugin, Player } from '@player-ui/player';
3
+ import { BeaconDataType } from '@player-ui/beacon-plugin';
4
+
5
+ /**
6
+ * This is the most generic way of gathering data. The input is bound to a data model using the 'binding' property.
7
+ * Players can get field type information from the 'schema' definition, thus to decide the input controls for visual rendering.
8
+ * */
9
+ interface InputAsset<AnyTextAsset extends Asset = Asset> extends Asset<'input'> {
10
+ /** Asset container for a field label. */
11
+ label?: AssetWrapper<AnyTextAsset>;
12
+ /** Asset container for a note. */
13
+ note?: AssetWrapper<AnyTextAsset>;
14
+ /** The location in the data-model to store the data */
15
+ binding: Binding;
16
+ /** Optional additional data */
17
+ metaData?: {
18
+ /** Additional data to beacon when this input changes */
19
+ beacon?: BeaconDataType;
20
+ };
21
+ }
22
+ declare type ValueType = string | undefined;
23
+ interface TransformedInput extends InputAsset {
24
+ /** A function to commit the new value to the data-model */
25
+ set: (newValue: ValueType) => void;
26
+ /** A function to format a value */
27
+ format: (newValue: ValueType) => ValueType;
28
+ /** The current value of the input from the data-model */
29
+ value: ValueType;
30
+ /** Any validation associated with the current input's value */
31
+ validation?: ValidationResponse;
32
+ /** The dataType defined from the schema */
33
+ dataType?: Schema.DataType;
34
+ }
35
+
36
+ /**
37
+ * Docs about the asset transform
38
+ */
39
+ declare const inputTransform: TransformFunction<InputAsset, TransformedInput>;
40
+
41
+ /**
42
+ * User actions can be represented in several places.
43
+ * Each view typically has one or more actions that allow the user to navigate away from that view.
44
+ * In addition, several asset types can have actions that apply to that asset only.
45
+ */
46
+ interface ActionAsset<AnyTextAsset extends Asset = Asset> extends Asset<'action'> {
47
+ /** The transition value of the action in the state machine */
48
+ value?: string;
49
+ /** A text-like asset for the action's label */
50
+ label?: AssetWrapper<AnyTextAsset>;
51
+ /** An optional expression to execute before transitioning */
52
+ exp?: Expression;
53
+ /** An optional string that describes the action for screen-readers */
54
+ accessibility?: string;
55
+ /** Additional optional data to assist with the action interactions on the page */
56
+ metaData?: {
57
+ /** Additional data to beacon */
58
+ beacon?: BeaconDataType;
59
+ /** Force transition to the next view without checking for validation */
60
+ skipValidation?: boolean;
61
+ };
62
+ }
63
+ /** A stateful instance of an action */
64
+ interface TransformedAction extends ActionAsset {
65
+ /** A method to execute the action */
66
+ run: () => void;
67
+ }
68
+
69
+ declare function isBackAction(action: ActionAsset): boolean;
70
+ /**
71
+ * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
72
+ *
73
+ * @param asset - Asset to apply the transform to
74
+ */
75
+ declare const expPropTransform: BeforeTransformFunction<Asset>;
76
+ declare const actionTransform: _player_ui_player.TransformFunctions;
77
+
78
+ interface CollectionAsset extends Asset<'collection'> {
79
+ /** An optional label to title the collection */
80
+ label?: AssetWrapper;
81
+ /** The string value to show */
82
+ values?: Array<AssetWrapper>;
83
+ }
84
+
85
+ interface InfoAsset extends Asset<'info'> {
86
+ /** The string value to show */
87
+ title?: AssetWrapper;
88
+ /** subtitle */
89
+ subTitle?: AssetWrapper;
90
+ /** Primary place for info */
91
+ primaryInfo?: AssetWrapper;
92
+ /** List of actions to show at the bottom of the page */
93
+ actions?: Array<AssetWrapper>;
94
+ }
95
+
96
+ interface TextAsset extends Asset<'text'> {
97
+ /** The text to display */
98
+ value: string;
99
+ /** Any modifiers on the text */
100
+ modifiers?: Array<TextModifier>;
101
+ }
102
+ declare type TextModifier = BasicTextModifier | LinkModifier;
103
+ interface BasicTextModifier {
104
+ /** The modifier type */
105
+ type: string;
106
+ /** Modifiers can be named when used in strings */
107
+ name?: string;
108
+ /** A spot for other metaData or properties */
109
+ [key: string]: unknown;
110
+ }
111
+ /** A modifier to turn the text into a link */
112
+ interface LinkModifier {
113
+ /** The link type denotes this as a link */
114
+ type: 'link';
115
+ /** An optional expression to run before the link is opened */
116
+ exp?: Expression;
117
+ /** metaData about the link's target */
118
+ metaData: {
119
+ /** The location of the link to load */
120
+ ref: string;
121
+ /** Used to indicate an application specific resolver to use */
122
+ 'mime-type'?: string;
123
+ };
124
+ }
125
+
126
+ /**
127
+ * A plugin to add transforms for the reference assets
128
+ */
129
+ declare class ReferenceAssetsPlugin implements PlayerPlugin {
130
+ name: string;
131
+ apply(player: Player): void;
132
+ }
133
+
134
+ export { ActionAsset, BasicTextModifier, CollectionAsset, InfoAsset, InputAsset, LinkModifier, ReferenceAssetsPlugin, TextAsset, TextModifier, TransformedAction, TransformedInput, actionTransform, expPropTransform, inputTransform, isBackAction };
@@ -0,0 +1,116 @@
1
+ import { compose, composeBefore, AssetTransformPlugin } from '@player-ui/asset-transform-plugin';
2
+
3
+ var __defProp$1 = Object.defineProperty;
4
+ var __defProps$1 = Object.defineProperties;
5
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues$1 = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp$1.call(b, prop))
13
+ __defNormalProp$1(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols$1)
15
+ for (var prop of __getOwnPropSymbols$1(b)) {
16
+ if (__propIsEnum$1.call(b, prop))
17
+ __defNormalProp$1(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
22
+ const inputTransform = (asset, options) => {
23
+ var _a, _b;
24
+ return __spreadProps$1(__spreadValues$1({}, asset), {
25
+ format(val) {
26
+ if (asset.binding === void 0) {
27
+ return val;
28
+ }
29
+ return options.data.format(asset.binding, val);
30
+ },
31
+ set(val) {
32
+ if (asset.binding === void 0) {
33
+ return;
34
+ }
35
+ return options.data.model.set([[asset.binding, val]], {
36
+ formatted: true
37
+ });
38
+ },
39
+ value: asset.binding === void 0 ? "" : options.data.model.get(asset.binding, {
40
+ includeInvalid: true,
41
+ formatted: true
42
+ }),
43
+ validation: asset.binding === void 0 ? void 0 : (_a = options.validation) == null ? void 0 : _a.get(asset.binding, { track: true }),
44
+ dataType: asset.binding === void 0 ? void 0 : (_b = options.validation) == null ? void 0 : _b.type(asset.binding)
45
+ });
46
+ };
47
+
48
+ var __defProp = Object.defineProperty;
49
+ var __defProps = Object.defineProperties;
50
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
51
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
52
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
53
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
54
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
55
+ var __spreadValues = (a, b) => {
56
+ for (var prop in b || (b = {}))
57
+ if (__hasOwnProp.call(b, prop))
58
+ __defNormalProp(a, prop, b[prop]);
59
+ if (__getOwnPropSymbols)
60
+ for (var prop of __getOwnPropSymbols(b)) {
61
+ if (__propIsEnum.call(b, prop))
62
+ __defNormalProp(a, prop, b[prop]);
63
+ }
64
+ return a;
65
+ };
66
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
67
+ function isBackAction(action) {
68
+ return action.value === "Prev";
69
+ }
70
+ const transform = (action, options) => {
71
+ return __spreadProps(__spreadValues({}, action), {
72
+ run() {
73
+ var _a, _b;
74
+ if (action.exp) {
75
+ options.evaluate(action.exp);
76
+ }
77
+ if (action.value) {
78
+ const skipValidation = (_a = action.metaData) == null ? void 0 : _a.skipValidation;
79
+ (_b = options.transition) == null ? void 0 : _b.call(options, action.value, { force: skipValidation });
80
+ }
81
+ }
82
+ });
83
+ };
84
+ const expPropTransform = (asset) => {
85
+ var _a, _b, _c, _d, _e, _f;
86
+ const skipArray = (_b = (_a = asset.plugins) == null ? void 0 : _a.stringResolver) == null ? void 0 : _b.propertiesToSkip;
87
+ if (skipArray && skipArray.indexOf("exp") > 1) {
88
+ return asset;
89
+ }
90
+ return __spreadProps(__spreadValues({}, asset), {
91
+ plugins: __spreadProps(__spreadValues({}, asset.plugins), {
92
+ stringResolver: __spreadProps(__spreadValues({}, (_c = asset == null ? void 0 : asset.plugins) == null ? void 0 : _c.stringResolver), {
93
+ propertiesToSkip: [
94
+ ...(_f = (_e = (_d = asset.plugins) == null ? void 0 : _d.stringResolver) == null ? void 0 : _e.propertiesToSkip) != null ? _f : [],
95
+ "exp"
96
+ ]
97
+ })
98
+ })
99
+ });
100
+ };
101
+ const actionTransform = compose(transform, composeBefore(expPropTransform));
102
+
103
+ class ReferenceAssetsPlugin {
104
+ constructor() {
105
+ this.name = "reference-assets-transforms";
106
+ }
107
+ apply(player) {
108
+ player.registerPlugin(new AssetTransformPlugin([
109
+ [{ type: "action" }, actionTransform],
110
+ [{ type: "input" }, inputTransform]
111
+ ]));
112
+ }
113
+ }
114
+
115
+ export { ReferenceAssetsPlugin, actionTransform, expPropTransform, inputTransform, isBackAction };
116
+ //# sourceMappingURL=index.esm.js.map
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@player-ui/reference-assets-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
+ "@player-ui/binding-grammar": "0.0.1-next.1",
13
+ "@player-ui/partial-match-registry": "0.0.1-next.1",
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
+ }
@@ -0,0 +1,2 @@
1
+ export * from './transform';
2
+ export * from './types';
@@ -0,0 +1,65 @@
1
+ import type {
2
+ Asset,
3
+ TransformFunction,
4
+ BeforeTransformFunction,
5
+ } from '@player-ui/player';
6
+ import { compose, composeBefore } from '@player-ui/asset-transform-plugin';
7
+ import type { ActionAsset, TransformedAction } from './types';
8
+
9
+ export function isBackAction(action: ActionAsset): boolean {
10
+ return action.value === 'Prev';
11
+ }
12
+
13
+ /**
14
+ * Attaches the methods to execute an action to an action
15
+ */
16
+ const transform: TransformFunction<ActionAsset, TransformedAction> = (
17
+ action,
18
+ options
19
+ ) => {
20
+ return {
21
+ ...action,
22
+ run() {
23
+ if (action.exp) {
24
+ options.evaluate(action.exp);
25
+ }
26
+
27
+ if (action.value) {
28
+ const skipValidation = action.metaData?.skipValidation;
29
+ options.transition?.(action.value, { force: skipValidation });
30
+ }
31
+ },
32
+ };
33
+ };
34
+
35
+ /**
36
+ * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
37
+ *
38
+ * @param asset - Asset to apply the transform to
39
+ */
40
+ export const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {
41
+ const skipArray = asset.plugins?.stringResolver?.propertiesToSkip;
42
+
43
+ if (skipArray && skipArray.indexOf('exp') > 1) {
44
+ return asset;
45
+ }
46
+
47
+ return {
48
+ ...asset,
49
+ plugins: {
50
+ ...asset.plugins,
51
+ stringResolver: {
52
+ ...asset?.plugins?.stringResolver,
53
+ propertiesToSkip: [
54
+ ...(asset.plugins?.stringResolver?.propertiesToSkip ?? []),
55
+ 'exp',
56
+ ],
57
+ },
58
+ },
59
+ };
60
+ };
61
+
62
+ export const actionTransform = compose(
63
+ transform,
64
+ composeBefore(expPropTransform)
65
+ );
@@ -0,0 +1,37 @@
1
+ import type { Asset, AssetWrapper, Expression } from '@player-ui/player';
2
+ import type { BeaconDataType } from '@player-ui/beacon-plugin';
3
+
4
+ /**
5
+ * User actions can be represented in several places.
6
+ * Each view typically has one or more actions that allow the user to navigate away from that view.
7
+ * In addition, several asset types can have actions that apply to that asset only.
8
+ */
9
+ export interface ActionAsset<AnyTextAsset extends Asset = Asset>
10
+ extends Asset<'action'> {
11
+ /** The transition value of the action in the state machine */
12
+ value?: string;
13
+
14
+ /** A text-like asset for the action's label */
15
+ label?: AssetWrapper<AnyTextAsset>;
16
+
17
+ /** An optional expression to execute before transitioning */
18
+ exp?: Expression;
19
+
20
+ /** An optional string that describes the action for screen-readers */
21
+ accessibility?: string;
22
+
23
+ /** Additional optional data to assist with the action interactions on the page */
24
+ metaData?: {
25
+ /** Additional data to beacon */
26
+ beacon?: BeaconDataType;
27
+
28
+ /** Force transition to the next view without checking for validation */
29
+ skipValidation?: boolean;
30
+ };
31
+ }
32
+
33
+ /** A stateful instance of an action */
34
+ export interface TransformedAction extends ActionAsset {
35
+ /** A method to execute the action */
36
+ run: () => void;
37
+ }
@@ -0,0 +1 @@
1
+ export * from './types';
@@ -0,0 +1,8 @@
1
+ import type { AssetWrapper, Asset } from '@player-ui/player';
2
+
3
+ export interface CollectionAsset extends Asset<'collection'> {
4
+ /** An optional label to title the collection */
5
+ label?: AssetWrapper;
6
+ /** The string value to show */
7
+ values?: Array<AssetWrapper>;
8
+ }
@@ -0,0 +1,5 @@
1
+ export * from './input';
2
+ export * from './action';
3
+ export * from './collection';
4
+ export * from './info';
5
+ export * from './text';
@@ -0,0 +1 @@
1
+ export * from './types';
@@ -0,0 +1,15 @@
1
+ import type { AssetWrapper, Asset } from '@player-ui/player';
2
+
3
+ export interface InfoAsset extends Asset<'info'> {
4
+ /** The string value to show */
5
+ title?: AssetWrapper;
6
+
7
+ /** subtitle */
8
+ subTitle?: AssetWrapper;
9
+
10
+ /** Primary place for info */
11
+ primaryInfo?: AssetWrapper;
12
+
13
+ /** List of actions to show at the bottom of the page */
14
+ actions?: Array<AssetWrapper>;
15
+ }
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './transform';
@@ -0,0 +1,45 @@
1
+ import type { TransformFunction } from '@player-ui/player';
2
+ import type { InputAsset, TransformedInput } from './types';
3
+
4
+ /**
5
+ * Docs about the asset transform
6
+ */
7
+ export const inputTransform: TransformFunction<InputAsset, TransformedInput> = (
8
+ asset,
9
+ options
10
+ ) => {
11
+ return {
12
+ ...asset,
13
+ format(val) {
14
+ if (asset.binding === undefined) {
15
+ return val;
16
+ }
17
+
18
+ return options.data.format(asset.binding, val);
19
+ },
20
+ set(val) {
21
+ if (asset.binding === undefined) {
22
+ return;
23
+ }
24
+
25
+ return options.data.model.set([[asset.binding, val]], {
26
+ formatted: true,
27
+ });
28
+ },
29
+ value:
30
+ asset.binding === undefined
31
+ ? ''
32
+ : options.data.model.get(asset.binding, {
33
+ includeInvalid: true,
34
+ formatted: true,
35
+ }),
36
+ validation:
37
+ asset.binding === undefined
38
+ ? undefined
39
+ : options.validation?.get(asset.binding, { track: true }),
40
+ dataType:
41
+ asset.binding === undefined
42
+ ? undefined
43
+ : options.validation?.type(asset.binding),
44
+ };
45
+ };
@@ -0,0 +1,49 @@
1
+ import type {
2
+ Asset,
3
+ AssetWrapper,
4
+ Schema,
5
+ Binding,
6
+ ValidationResponse,
7
+ } from '@player-ui/player';
8
+ import type { BeaconDataType } from '@player-ui/beacon-plugin';
9
+
10
+ /**
11
+ * This is the most generic way of gathering data. The input is bound to a data model using the 'binding' property.
12
+ * Players can get field type information from the 'schema' definition, thus to decide the input controls for visual rendering.
13
+ * */
14
+ export interface InputAsset<AnyTextAsset extends Asset = Asset>
15
+ extends Asset<'input'> {
16
+ /** Asset container for a field label. */
17
+ label?: AssetWrapper<AnyTextAsset>;
18
+
19
+ /** Asset container for a note. */
20
+ note?: AssetWrapper<AnyTextAsset>;
21
+
22
+ /** The location in the data-model to store the data */
23
+ binding: Binding;
24
+
25
+ /** Optional additional data */
26
+ metaData?: {
27
+ /** Additional data to beacon when this input changes */
28
+ beacon?: BeaconDataType;
29
+ };
30
+ }
31
+
32
+ type ValueType = string | undefined;
33
+
34
+ export interface TransformedInput extends InputAsset {
35
+ /** A function to commit the new value to the data-model */
36
+ set: (newValue: ValueType) => void;
37
+
38
+ /** A function to format a value */
39
+ format: (newValue: ValueType) => ValueType;
40
+
41
+ /** The current value of the input from the data-model */
42
+ value: ValueType;
43
+
44
+ /** Any validation associated with the current input's value */
45
+ validation?: ValidationResponse;
46
+
47
+ /** The dataType defined from the schema */
48
+ dataType?: Schema.DataType;
49
+ }
@@ -0,0 +1 @@
1
+ export * from './types';
@@ -0,0 +1,40 @@
1
+ import type { Asset, Expression } from '@player-ui/player';
2
+
3
+ export interface TextAsset extends Asset<'text'> {
4
+ /** The text to display */
5
+ value: string;
6
+
7
+ /** Any modifiers on the text */
8
+ modifiers?: Array<TextModifier>;
9
+ }
10
+
11
+ export type TextModifier = BasicTextModifier | LinkModifier;
12
+
13
+ export interface BasicTextModifier {
14
+ /** The modifier type */
15
+ type: string;
16
+
17
+ /** Modifiers can be named when used in strings */
18
+ name?: string;
19
+
20
+ /** A spot for other metaData or properties */
21
+ [key: string]: unknown;
22
+ }
23
+
24
+ /** A modifier to turn the text into a link */
25
+ export interface LinkModifier {
26
+ /** The link type denotes this as a link */
27
+ type: 'link';
28
+
29
+ /** An optional expression to run before the link is opened */
30
+ exp?: Expression;
31
+
32
+ /** metaData about the link's target */
33
+ metaData: {
34
+ /** The location of the link to load */
35
+ ref: string;
36
+
37
+ /** Used to indicate an application specific resolver to use */
38
+ 'mime-type'?: string;
39
+ };
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './assets';
2
+ export * from './plugin';
package/src/plugin.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { Player, PlayerPlugin } from '@player-ui/player';
2
+ import { AssetTransformPlugin } from '@player-ui/asset-transform-plugin';
3
+ import { inputTransform, actionTransform } from './assets';
4
+
5
+ /**
6
+ * A plugin to add transforms for the reference assets
7
+ */
8
+ export class ReferenceAssetsPlugin implements PlayerPlugin {
9
+ name = 'reference-assets-transforms';
10
+
11
+ apply(player: Player) {
12
+ player.registerPlugin(
13
+ new AssetTransformPlugin([
14
+ [{ type: 'action' }, actionTransform],
15
+ [{ type: 'input' }, inputTransform],
16
+ ])
17
+ );
18
+ }
19
+ }