@player-ui/reference-assets-plugin 0.3.1-next.1 → 0.3.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.
- package/dist/index.cjs.js +117 -37
- package/dist/index.d.ts +52 -1
- package/dist/index.esm.js +116 -38
- package/dist/reference-assets-plugin.dev.js +675 -0
- package/dist/reference-assets-plugin.prod.js +1 -0
- package/package.json +14 -5
- package/src/assets/action/transform.ts +26 -0
- package/src/assets/action/types.ts +3 -0
- package/src/assets/image/index.ts +2 -0
- package/src/assets/image/transform.ts +32 -0
- package/src/assets/image/types.ts +26 -0
- package/src/assets/index.ts +1 -0
- package/src/assets/info/index.ts +1 -0
- package/src/assets/info/transform.ts +38 -0
- package/src/assets/info/types.ts +17 -0
- package/src/plugin.ts +8 -1
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/reference-assets-plugin",
|
|
3
|
-
"version": "0.3.1
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@player-ui/player": "0.3.1
|
|
9
|
+
"@player-ui/player": "0.3.1"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-ui/beacon-plugin": "0.3.1
|
|
13
|
-
"@player-ui/asset-transform-plugin": "0.3.1
|
|
12
|
+
"@player-ui/beacon-plugin": "0.3.1",
|
|
13
|
+
"@player-ui/asset-transform-plugin": "0.3.1",
|
|
14
14
|
"@babel/runtime": "7.15.4"
|
|
15
15
|
},
|
|
16
16
|
"main": "dist/index.cjs.js",
|
|
@@ -54,6 +54,15 @@
|
|
|
54
54
|
{
|
|
55
55
|
"name": "Kelly Harrop",
|
|
56
56
|
"url": "https://github.com/kharrop"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "Alejandro Fimbres",
|
|
60
|
+
"url": "https://github.com/lexfm"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "Rafael Campos",
|
|
64
|
+
"url": "https://github.com/rafbcampos"
|
|
57
65
|
}
|
|
58
|
-
]
|
|
66
|
+
],
|
|
67
|
+
"bundle": "./dist/reference-assets-plugin.prod.js"
|
|
59
68
|
}
|
|
@@ -6,6 +6,9 @@ import type {
|
|
|
6
6
|
import { compose, composeBefore } from '@player-ui/asset-transform-plugin';
|
|
7
7
|
import type { ActionAsset, TransformedAction } from './types';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Function to find prev button
|
|
11
|
+
*/
|
|
9
12
|
export function isBackAction(action: ActionAsset): boolean {
|
|
10
13
|
return action.value === 'Prev';
|
|
11
14
|
}
|
|
@@ -32,6 +35,28 @@ const transform: TransformFunction<ActionAsset, TransformedAction> = (
|
|
|
32
35
|
};
|
|
33
36
|
};
|
|
34
37
|
|
|
38
|
+
/**
|
|
39
|
+
* De couples back button from the back icon
|
|
40
|
+
*/
|
|
41
|
+
const backIconTransform: TransformFunction<ActionAsset, ActionAsset> = (
|
|
42
|
+
action
|
|
43
|
+
) => {
|
|
44
|
+
/** For previous versions of player, the back button would already have the back icon.
|
|
45
|
+
* This ensures that the old functionality does not break and back button is still visible when they update the player.
|
|
46
|
+
*/
|
|
47
|
+
if (isBackAction(action) && action?.metaData?.role === undefined) {
|
|
48
|
+
return {
|
|
49
|
+
...action,
|
|
50
|
+
metaData: {
|
|
51
|
+
...action?.metaData,
|
|
52
|
+
role: 'back',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return action;
|
|
58
|
+
};
|
|
59
|
+
|
|
35
60
|
/**
|
|
36
61
|
* Appends `exp` to the plugins.stringResolver.propertiesToSkip array or creates it if it doesn't exist
|
|
37
62
|
*
|
|
@@ -61,5 +86,6 @@ export const expPropTransform: BeforeTransformFunction<Asset> = (asset) => {
|
|
|
61
86
|
|
|
62
87
|
export const actionTransform = compose(
|
|
63
88
|
transform,
|
|
89
|
+
backIconTransform,
|
|
64
90
|
composeBefore(expPropTransform)
|
|
65
91
|
);
|
|
@@ -27,6 +27,9 @@ export interface ActionAsset<AnyTextAsset extends Asset = Asset>
|
|
|
27
27
|
|
|
28
28
|
/** Force transition to the next view without checking for validation */
|
|
29
29
|
skipValidation?: boolean;
|
|
30
|
+
|
|
31
|
+
/** string value to decide for the left anchor sign */
|
|
32
|
+
role?: string;
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
35
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TransformFunction } from '@player-ui/player';
|
|
2
|
+
import type { ImageAsset, TransformedImage } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Function to retrieve the desired alt text based on passed in props.
|
|
6
|
+
* @param props Image props
|
|
7
|
+
* @returns The alt text for the image asset
|
|
8
|
+
*/
|
|
9
|
+
const getImageAlt = (props: ImageAsset): string => {
|
|
10
|
+
const { metaData, placeholder } = props;
|
|
11
|
+
if (metaData.accessibility) return metaData.accessibility;
|
|
12
|
+
|
|
13
|
+
if (placeholder) return placeholder;
|
|
14
|
+
|
|
15
|
+
return 'Image';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sets the Image's placeholder and accessibilty
|
|
20
|
+
*/
|
|
21
|
+
export const imageTransform: TransformFunction<ImageAsset, TransformedImage> = (
|
|
22
|
+
props
|
|
23
|
+
) => {
|
|
24
|
+
const altText = getImageAlt(props);
|
|
25
|
+
|
|
26
|
+
const newImage = {
|
|
27
|
+
...props,
|
|
28
|
+
altText,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return newImage;
|
|
32
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Asset } from '@player-ui/player';
|
|
2
|
+
|
|
3
|
+
export interface ImageAsset extends Asset<'image'> {
|
|
4
|
+
/** Reference to the image */
|
|
5
|
+
metaData: ImageMetaData;
|
|
6
|
+
|
|
7
|
+
/** Optional placeholder text */
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
|
|
10
|
+
/** Optional caption */
|
|
11
|
+
caption?: Asset;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A modifier to turn the text into a link */
|
|
15
|
+
export interface ImageMetaData {
|
|
16
|
+
/** The location of the image to load */
|
|
17
|
+
ref: string;
|
|
18
|
+
|
|
19
|
+
/** Used for accessibility support */
|
|
20
|
+
accessibility?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TransformedImage extends ImageAsset {
|
|
24
|
+
/** Alt text */
|
|
25
|
+
altText: string;
|
|
26
|
+
}
|
package/src/assets/index.ts
CHANGED
package/src/assets/info/index.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TransformFunction } from '@player-ui/player';
|
|
2
|
+
import type { AssetWrapper } from '@player-ui/player';
|
|
3
|
+
import type { InfoAsset, InfoAssetTransform } from './types';
|
|
4
|
+
import type { ActionAsset } from '../action/types';
|
|
5
|
+
import { isBackAction } from '../action/transform';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This transform should add segmentedActions to the info asset.
|
|
9
|
+
* Segmented actions display side by side in larger viewports. Segmented Actions is an object of next and prev actions
|
|
10
|
+
*/
|
|
11
|
+
export const infoTransform: TransformFunction<InfoAsset, InfoAssetTransform> = (
|
|
12
|
+
infoAsset
|
|
13
|
+
) => {
|
|
14
|
+
const actions = infoAsset?.actions;
|
|
15
|
+
const segmentedActions = actions?.reduce(
|
|
16
|
+
(segmentedActionsArray, action) => {
|
|
17
|
+
segmentedActionsArray[
|
|
18
|
+
isBackAction(action.asset as ActionAsset) ? 'prev' : 'next'
|
|
19
|
+
].push(action as AssetWrapper<ActionAsset>);
|
|
20
|
+
return segmentedActionsArray;
|
|
21
|
+
},
|
|
22
|
+
{ next: [], prev: [] } as {
|
|
23
|
+
/**
|
|
24
|
+
* next is an array of next actions
|
|
25
|
+
*/
|
|
26
|
+
next: Array<AssetWrapper<ActionAsset>>;
|
|
27
|
+
/**
|
|
28
|
+
* prev is an array of prev actions
|
|
29
|
+
*/
|
|
30
|
+
prev: Array<AssetWrapper<ActionAsset>>;
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
...infoAsset,
|
|
36
|
+
segmentedActions,
|
|
37
|
+
};
|
|
38
|
+
};
|
package/src/assets/info/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AssetWrapper, Asset } from '@player-ui/player';
|
|
2
|
+
import type { ActionAsset } from '../action/types';
|
|
2
3
|
|
|
3
4
|
export interface InfoAsset extends Asset<'info'> {
|
|
4
5
|
/** The string value to show */
|
|
@@ -13,3 +14,19 @@ export interface InfoAsset extends Asset<'info'> {
|
|
|
13
14
|
/** List of actions to show at the bottom of the page */
|
|
14
15
|
actions?: Array<AssetWrapper>;
|
|
15
16
|
}
|
|
17
|
+
|
|
18
|
+
export interface InfoAssetTransform extends InfoAsset {
|
|
19
|
+
/**
|
|
20
|
+
* This is an array of next and prev actions
|
|
21
|
+
*/
|
|
22
|
+
segmentedActions?: {
|
|
23
|
+
/**
|
|
24
|
+
* Array of next actions
|
|
25
|
+
*/
|
|
26
|
+
next: Array<AssetWrapper<ActionAsset>>;
|
|
27
|
+
/**
|
|
28
|
+
* Array of prev actions
|
|
29
|
+
*/
|
|
30
|
+
prev: Array<AssetWrapper<ActionAsset>>;
|
|
31
|
+
};
|
|
32
|
+
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Player, PlayerPlugin } from '@player-ui/player';
|
|
2
2
|
import { AssetTransformPlugin } from '@player-ui/asset-transform-plugin';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
inputTransform,
|
|
5
|
+
actionTransform,
|
|
6
|
+
imageTransform,
|
|
7
|
+
infoTransform,
|
|
8
|
+
} from './assets';
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* A plugin to add transforms for the reference assets
|
|
@@ -13,6 +18,8 @@ export class ReferenceAssetsPlugin implements PlayerPlugin {
|
|
|
13
18
|
new AssetTransformPlugin([
|
|
14
19
|
[{ type: 'action' }, actionTransform],
|
|
15
20
|
[{ type: 'input' }, inputTransform],
|
|
21
|
+
[{ type: 'image' }, imageTransform],
|
|
22
|
+
[{ type: 'info' }, infoTransform],
|
|
16
23
|
])
|
|
17
24
|
);
|
|
18
25
|
}
|