@player-ui/reference-assets-plugin 0.7.4-next.4 → 0.7.5--canary.434.14868

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.
Files changed (70) hide show
  1. package/dist/ReferenceAssetsPlugin.native.js +821 -0
  2. package/dist/ReferenceAssetsPlugin.native.js.map +1 -0
  3. package/dist/cjs/index.cjs +215 -0
  4. package/dist/cjs/index.cjs.map +1 -0
  5. package/dist/index.legacy-esm.js +181 -0
  6. package/dist/index.mjs +181 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/xlr/ActionAsset.json +126 -0
  9. package/dist/xlr/ChoiceAsset.json +191 -0
  10. package/dist/xlr/CollectionAsset.json +40 -0
  11. package/dist/xlr/ImageAsset.json +65 -0
  12. package/dist/xlr/InfoAsset.json +58 -0
  13. package/dist/xlr/InputAsset.json +109 -0
  14. package/dist/xlr/TextAsset.json +125 -0
  15. package/dist/xlr/manifest.js +18 -0
  16. package/dist/xlr/manifest.json +24 -0
  17. package/package.json +27 -60
  18. package/src/assets/action/__tests__/transform.test.ts +118 -0
  19. package/src/assets/action/index.ts +2 -2
  20. package/src/assets/action/transform.ts +10 -10
  21. package/src/assets/action/types.ts +3 -3
  22. package/src/assets/choice/__tests__/transform.test.ts +145 -0
  23. package/src/assets/choice/index.ts +2 -0
  24. package/src/assets/choice/transform.ts +55 -0
  25. package/src/assets/choice/types.ts +73 -0
  26. package/src/assets/collection/index.ts +1 -1
  27. package/src/assets/collection/types.ts +2 -2
  28. package/src/assets/image/__tests__/transform.test.ts +35 -0
  29. package/src/assets/image/index.ts +2 -2
  30. package/src/assets/image/transform.ts +4 -4
  31. package/src/assets/image/types.ts +3 -3
  32. package/src/assets/index.ts +7 -6
  33. package/src/assets/info/__tests__/transform.test.ts +143 -0
  34. package/src/assets/info/index.ts +2 -2
  35. package/src/assets/info/transform.ts +8 -8
  36. package/src/assets/info/types.ts +3 -3
  37. package/src/assets/input/index.ts +2 -2
  38. package/src/assets/input/transform.ts +4 -4
  39. package/src/assets/input/types.ts +3 -3
  40. package/src/assets/text/index.ts +1 -1
  41. package/src/assets/text/types.ts +4 -4
  42. package/src/index.ts +2 -2
  43. package/src/plugin.ts +34 -10
  44. package/types/assets/action/index.d.ts +3 -0
  45. package/types/assets/action/transform.d.ts +14 -0
  46. package/types/assets/action/types.d.ts +32 -0
  47. package/types/assets/choice/index.d.ts +3 -0
  48. package/types/assets/choice/transform.d.ts +7 -0
  49. package/types/assets/choice/types.d.ts +51 -0
  50. package/types/assets/collection/index.d.ts +2 -0
  51. package/types/assets/collection/types.d.ts +8 -0
  52. package/types/assets/image/index.d.ts +3 -0
  53. package/types/assets/image/transform.d.ts +7 -0
  54. package/types/assets/image/types.d.ts +21 -0
  55. package/types/assets/index.d.ts +8 -0
  56. package/types/assets/info/index.d.ts +3 -0
  57. package/types/assets/info/transform.d.ts +8 -0
  58. package/types/assets/info/types.d.ts +28 -0
  59. package/types/assets/input/index.d.ts +3 -0
  60. package/types/assets/input/transform.d.ts +7 -0
  61. package/types/assets/input/types.d.ts +34 -0
  62. package/types/assets/text/index.d.ts +2 -0
  63. package/types/assets/text/types.d.ts +31 -0
  64. package/types/index.d.ts +3 -0
  65. package/types/plugin.d.ts +19 -0
  66. package/dist/index.cjs.js +0 -204
  67. package/dist/index.d.ts +0 -185
  68. package/dist/index.esm.js +0 -194
  69. package/dist/reference-assets-plugin.dev.js +0 -675
  70. package/dist/reference-assets-plugin.prod.js +0 -1
package/dist/index.d.ts DELETED
@@ -1,185 +0,0 @@
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
- /** string value to decide for the left anchor sign */
62
- role?: string;
63
- };
64
- }
65
- /** A stateful instance of an action */
66
- interface TransformedAction extends ActionAsset {
67
- /** A method to execute the action */
68
- run: () => void;
69
- }
70
-
71
- /**
72
- * Function to find prev button
73
- */
74
- declare function isBackAction(action: ActionAsset): boolean;
75
- /**
76
- * Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
77
- *
78
- * @param asset - Asset to apply the transform to
79
- */
80
- declare const expPropTransform: BeforeTransformFunction<Asset>;
81
- declare const actionTransform: _player_ui_player.TransformFunctions;
82
-
83
- interface CollectionAsset extends Asset<'collection'> {
84
- /** An optional label to title the collection */
85
- label?: AssetWrapper;
86
- /** The string value to show */
87
- values?: Array<AssetWrapper>;
88
- }
89
-
90
- interface InfoAsset extends Asset<'info'> {
91
- /** The string value to show */
92
- title?: AssetWrapper;
93
- /** subtitle */
94
- subTitle?: AssetWrapper;
95
- /** Primary place for info */
96
- primaryInfo?: AssetWrapper;
97
- /** List of actions to show at the bottom of the page */
98
- actions?: Array<AssetWrapper>;
99
- }
100
- interface InfoAssetTransform extends InfoAsset {
101
- /**
102
- * This is an array of next and prev actions
103
- */
104
- segmentedActions?: {
105
- /**
106
- * Array of next actions
107
- */
108
- next: Array<AssetWrapper<ActionAsset>>;
109
- /**
110
- * Array of prev actions
111
- */
112
- prev: Array<AssetWrapper<ActionAsset>>;
113
- };
114
- }
115
-
116
- /**
117
- * This transform should add segmentedActions to the info asset.
118
- * Segmented actions display side by side in larger viewports. Segmented Actions is an object of next and prev actions
119
- */
120
- declare const infoTransform: TransformFunction<InfoAsset, InfoAssetTransform>;
121
-
122
- interface TextAsset extends Asset<'text'> {
123
- /** The text to display */
124
- value: string;
125
- /** Any modifiers on the text */
126
- modifiers?: Array<TextModifier>;
127
- }
128
- declare type TextModifier = BasicTextModifier | LinkModifier;
129
- interface BasicTextModifier {
130
- /** The modifier type */
131
- type: string;
132
- /** Modifiers can be named when used in strings */
133
- name?: string;
134
- /** A spot for other metaData or properties */
135
- [key: string]: unknown;
136
- }
137
- /** A modifier to turn the text into a link */
138
- interface LinkModifier {
139
- /** The link type denotes this as a link */
140
- type: 'link';
141
- /** An optional expression to run before the link is opened */
142
- exp?: Expression;
143
- /** metaData about the link's target */
144
- metaData: {
145
- /** The location of the link to load */
146
- ref: string;
147
- /** Used to indicate an application specific resolver to use */
148
- 'mime-type'?: string;
149
- };
150
- }
151
-
152
- interface ImageAsset extends Asset<'image'> {
153
- /** Reference to the image */
154
- metaData: ImageMetaData;
155
- /** Optional placeholder text */
156
- placeholder?: string;
157
- /** Optional caption */
158
- caption?: Asset;
159
- }
160
- /** A modifier to turn the text into a link */
161
- interface ImageMetaData {
162
- /** The location of the image to load */
163
- ref: string;
164
- /** Used for accessibility support */
165
- accessibility?: string;
166
- }
167
- interface TransformedImage extends ImageAsset {
168
- /** Alt text */
169
- altText: string;
170
- }
171
-
172
- /**
173
- * Sets the Image's placeholder and accessibilty
174
- */
175
- declare const imageTransform: TransformFunction<ImageAsset, TransformedImage>;
176
-
177
- /**
178
- * A plugin to add transforms for the reference assets
179
- */
180
- declare class ReferenceAssetsPlugin implements PlayerPlugin {
181
- name: string;
182
- apply(player: Player): void;
183
- }
184
-
185
- export { ActionAsset, BasicTextModifier, CollectionAsset, ImageAsset, ImageMetaData, InfoAsset, InfoAssetTransform, InputAsset, LinkModifier, ReferenceAssetsPlugin, TextAsset, TextModifier, TransformedAction, TransformedImage, TransformedInput, actionTransform, expPropTransform, imageTransform, infoTransform, inputTransform, isBackAction };
package/dist/index.esm.js DELETED
@@ -1,194 +0,0 @@
1
- import { compose, composeBefore, AssetTransformPlugin } from '@player-ui/asset-transform-plugin';
2
-
3
- var __defProp$3 = Object.defineProperty;
4
- var __defProps$3 = Object.defineProperties;
5
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
7
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
8
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues$3 = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp$3.call(b, prop))
13
- __defNormalProp$3(a, prop, b[prop]);
14
- if (__getOwnPropSymbols$3)
15
- for (var prop of __getOwnPropSymbols$3(b)) {
16
- if (__propIsEnum$3.call(b, prop))
17
- __defNormalProp$3(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
22
- const inputTransform = (asset, options) => {
23
- var _a, _b;
24
- return __spreadProps$3(__spreadValues$3({}, 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$2 = Object.defineProperty;
49
- var __defProps$2 = Object.defineProperties;
50
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
51
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
52
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
53
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
54
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
55
- var __spreadValues$2 = (a, b) => {
56
- for (var prop in b || (b = {}))
57
- if (__hasOwnProp$2.call(b, prop))
58
- __defNormalProp$2(a, prop, b[prop]);
59
- if (__getOwnPropSymbols$2)
60
- for (var prop of __getOwnPropSymbols$2(b)) {
61
- if (__propIsEnum$2.call(b, prop))
62
- __defNormalProp$2(a, prop, b[prop]);
63
- }
64
- return a;
65
- };
66
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
67
- function isBackAction(action) {
68
- return action.value === "Prev";
69
- }
70
- const transform = (action, options) => {
71
- return __spreadProps$2(__spreadValues$2({}, 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 backIconTransform = (action) => {
85
- var _a;
86
- if (isBackAction(action) && ((_a = action == null ? void 0 : action.metaData) == null ? void 0 : _a.role) === void 0) {
87
- return __spreadProps$2(__spreadValues$2({}, action), {
88
- metaData: __spreadProps$2(__spreadValues$2({}, action == null ? void 0 : action.metaData), {
89
- role: "back"
90
- })
91
- });
92
- }
93
- return action;
94
- };
95
- const expPropTransform = (asset) => {
96
- var _a, _b, _c, _d, _e, _f;
97
- const skipArray = (_b = (_a = asset.plugins) == null ? void 0 : _a.stringResolver) == null ? void 0 : _b.propertiesToSkip;
98
- if (skipArray && skipArray.indexOf("exp") > 1) {
99
- return asset;
100
- }
101
- return __spreadProps$2(__spreadValues$2({}, asset), {
102
- plugins: __spreadProps$2(__spreadValues$2({}, asset.plugins), {
103
- stringResolver: __spreadProps$2(__spreadValues$2({}, (_c = asset == null ? void 0 : asset.plugins) == null ? void 0 : _c.stringResolver), {
104
- propertiesToSkip: [
105
- ...(_f = (_e = (_d = asset.plugins) == null ? void 0 : _d.stringResolver) == null ? void 0 : _e.propertiesToSkip) != null ? _f : [],
106
- "exp"
107
- ]
108
- })
109
- })
110
- });
111
- };
112
- const actionTransform = compose(transform, backIconTransform, composeBefore(expPropTransform));
113
-
114
- var __defProp$1 = Object.defineProperty;
115
- var __defProps$1 = Object.defineProperties;
116
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
117
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
118
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
119
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
120
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
121
- var __spreadValues$1 = (a, b) => {
122
- for (var prop in b || (b = {}))
123
- if (__hasOwnProp$1.call(b, prop))
124
- __defNormalProp$1(a, prop, b[prop]);
125
- if (__getOwnPropSymbols$1)
126
- for (var prop of __getOwnPropSymbols$1(b)) {
127
- if (__propIsEnum$1.call(b, prop))
128
- __defNormalProp$1(a, prop, b[prop]);
129
- }
130
- return a;
131
- };
132
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
133
- const infoTransform = (infoAsset) => {
134
- const actions = infoAsset == null ? void 0 : infoAsset.actions;
135
- const segmentedActions = actions == null ? void 0 : actions.reduce((segmentedActionsArray, action) => {
136
- segmentedActionsArray[isBackAction(action.asset) ? "prev" : "next"].push(action);
137
- return segmentedActionsArray;
138
- }, { next: [], prev: [] });
139
- return __spreadProps$1(__spreadValues$1({}, infoAsset), {
140
- segmentedActions
141
- });
142
- };
143
-
144
- var __defProp = Object.defineProperty;
145
- var __defProps = Object.defineProperties;
146
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
147
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
148
- var __hasOwnProp = Object.prototype.hasOwnProperty;
149
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
150
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
151
- var __spreadValues = (a, b) => {
152
- for (var prop in b || (b = {}))
153
- if (__hasOwnProp.call(b, prop))
154
- __defNormalProp(a, prop, b[prop]);
155
- if (__getOwnPropSymbols)
156
- for (var prop of __getOwnPropSymbols(b)) {
157
- if (__propIsEnum.call(b, prop))
158
- __defNormalProp(a, prop, b[prop]);
159
- }
160
- return a;
161
- };
162
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
163
- const getImageAlt = (props) => {
164
- const { metaData, placeholder } = props;
165
- if (metaData.accessibility)
166
- return metaData.accessibility;
167
- if (placeholder)
168
- return placeholder;
169
- return "Image";
170
- };
171
- const imageTransform = (props) => {
172
- const altText = getImageAlt(props);
173
- const newImage = __spreadProps(__spreadValues({}, props), {
174
- altText
175
- });
176
- return newImage;
177
- };
178
-
179
- class ReferenceAssetsPlugin {
180
- constructor() {
181
- this.name = "reference-assets-transforms";
182
- }
183
- apply(player) {
184
- player.registerPlugin(new AssetTransformPlugin([
185
- [{ type: "action" }, actionTransform],
186
- [{ type: "input" }, inputTransform],
187
- [{ type: "image" }, imageTransform],
188
- [{ type: "info" }, infoTransform]
189
- ]));
190
- }
191
- }
192
-
193
- export { ReferenceAssetsPlugin, actionTransform, expPropTransform, imageTransform, infoTransform, inputTransform, isBackAction };
194
- //# sourceMappingURL=index.esm.js.map