@player-ui/reference-assets-plugin-react 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.
Files changed (76) hide show
  1. package/dist/cjs/index.cjs +581 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/index.css +703 -0
  4. package/dist/index.legacy-esm.js +529 -0
  5. package/dist/index.mjs +529 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +34 -63
  8. package/src/__tests__/integration.test.tsx +158 -0
  9. package/src/assets/action/Action.tsx +10 -14
  10. package/src/assets/action/hooks.tsx +6 -6
  11. package/src/assets/action/index.ts +2 -2
  12. package/src/assets/choice/Choice.tsx +52 -0
  13. package/src/assets/choice/hooks.tsx +34 -0
  14. package/src/assets/choice/index.ts +2 -0
  15. package/src/assets/collection/Collection.tsx +6 -9
  16. package/src/assets/collection/index.tsx +1 -1
  17. package/src/assets/image/Image.tsx +4 -4
  18. package/src/assets/image/index.tsx +1 -1
  19. package/src/assets/index.tsx +7 -6
  20. package/src/assets/info/Info.tsx +26 -29
  21. package/src/assets/info/index.tsx +1 -1
  22. package/src/assets/input/Input.tsx +27 -19
  23. package/src/assets/input/hooks.tsx +35 -35
  24. package/src/assets/input/index.tsx +2 -2
  25. package/src/assets/input/types.ts +2 -2
  26. package/src/assets/text/Text.tsx +13 -7
  27. package/src/assets/text/hooks.tsx +6 -6
  28. package/src/assets/text/index.tsx +2 -2
  29. package/src/components/Button.tsx +56 -0
  30. package/src/components/ChoiceItem.tsx +31 -0
  31. package/src/components/Input.tsx +26 -0
  32. package/src/components/Label.tsx +26 -0
  33. package/src/components/Separator.tsx +30 -0
  34. package/src/global.css +83 -0
  35. package/src/index.tsx +4 -2
  36. package/src/intro.stories.mdx +9 -9
  37. package/src/plugin.tsx +22 -43
  38. package/src/utils.ts +6 -0
  39. package/types/assets/action/Action.d.ts +7 -0
  40. package/types/assets/action/hooks.d.ts +9 -0
  41. package/types/assets/action/index.d.ts +3 -0
  42. package/types/assets/choice/Choice.d.ts +6 -0
  43. package/types/assets/choice/hooks.d.ts +5 -0
  44. package/types/assets/choice/index.d.ts +3 -0
  45. package/types/assets/collection/Collection.d.ts +4 -0
  46. package/types/assets/collection/index.d.ts +2 -0
  47. package/types/assets/image/Image.d.ts +4 -0
  48. package/types/assets/image/index.d.ts +2 -0
  49. package/types/assets/index.d.ts +8 -0
  50. package/types/assets/info/Info.d.ts +5 -0
  51. package/types/assets/info/index.d.ts +2 -0
  52. package/types/assets/input/Input.d.ts +6 -0
  53. package/types/assets/input/hooks.d.ts +40 -0
  54. package/types/assets/input/index.d.ts +3 -0
  55. package/types/assets/input/types.d.ts +3 -0
  56. package/types/assets/text/Text.d.ts +7 -0
  57. package/types/assets/text/hooks.d.ts +9 -0
  58. package/types/assets/text/index.d.ts +3 -0
  59. package/types/components/Button.d.ts +12 -0
  60. package/types/components/ChoiceItem.d.ts +7 -0
  61. package/types/components/Input.d.ts +6 -0
  62. package/types/components/Label.d.ts +6 -0
  63. package/types/components/Separator.d.ts +5 -0
  64. package/types/index.d.ts +4 -0
  65. package/types/plugin.d.ts +19 -0
  66. package/types/utils.d.ts +3 -0
  67. package/dist/index.cjs.js +0 -501
  68. package/dist/index.d.ts +0 -94
  69. package/dist/index.esm.js +0 -479
  70. package/dist/xlr/ActionAsset.json +0 -126
  71. package/dist/xlr/CollectionAsset.json +0 -40
  72. package/dist/xlr/InfoAsset.json +0 -58
  73. package/dist/xlr/InputAsset.json +0 -109
  74. package/dist/xlr/TextAsset.json +0 -125
  75. package/dist/xlr/manifest.js +0 -16
  76. package/dist/xlr/manifest.json +0 -22
@@ -1,7 +1,7 @@
1
- import React from 'react';
2
- import { useBeacon } from '@player-ui/beacon-plugin-react';
3
- import type { TransformedInput } from '@player-ui/reference-assets-plugin';
4
- import type { KeyDownHandler } from './types';
1
+ import React from "react";
2
+ import { useBeacon } from "@player-ui/beacon-plugin-react";
3
+ import type { TransformedInput } from "@player-ui/reference-assets-plugin";
4
+ import type { KeyDownHandler } from "./types";
5
5
 
6
6
  export interface InputHookConfig {
7
7
  /** Format the input as the user keys down */
@@ -30,21 +30,21 @@ export interface InputHookConfig {
30
30
  }
31
31
 
32
32
  const defaultKeyStrings = [
33
- 'Delete',
34
- 'Backspace',
35
- 'Tab',
36
- 'Home',
37
- 'End',
38
- 'ArrowLeft',
39
- 'ArrowRight',
40
- 'ArrowUp',
41
- 'ArrowDown',
42
- 'Escape',
33
+ "Delete",
34
+ "Backspace",
35
+ "Tab",
36
+ "Home",
37
+ "End",
38
+ "ArrowLeft",
39
+ "ArrowRight",
40
+ "ArrowUp",
41
+ "ArrowDown",
42
+ "Escape",
43
43
  ];
44
44
 
45
45
  /** Create a valid config mixing in defaults and user overrides */
46
46
  export const getConfig = (
47
- userConfig: InputHookConfig = {}
47
+ userConfig: InputHookConfig = {},
48
48
  ): Required<InputHookConfig> => {
49
49
  return {
50
50
  liveFormat: true,
@@ -52,28 +52,28 @@ export const getConfig = (
52
52
  quickFormatDelay: 200,
53
53
  slowFormatDelay: 1000,
54
54
  slowFormatKeys: defaultKeyStrings,
55
- decimalSymbol: '.',
56
- prefix: '',
57
- suffix: '',
55
+ decimalSymbol: ".",
56
+ prefix: "",
57
+ suffix: "",
58
58
  ...userConfig,
59
59
  };
60
60
  };
61
61
 
62
62
  /** A hook to manage beacon changes for input assets */
63
63
  export const useInputBeacon = (props: TransformedInput) => {
64
- const beaconHandler = useBeacon({ element: 'text_input', asset: props });
64
+ const beaconHandler = useBeacon({ element: "text_input", asset: props });
65
65
 
66
66
  return (newValue: string) => {
67
- let action = 'modified';
67
+ let action = "modified";
68
68
 
69
69
  if (newValue === props.value) {
70
70
  return;
71
71
  }
72
72
 
73
73
  if (newValue && !props.value) {
74
- action = 'added';
74
+ action = "added";
75
75
  } else if (!newValue && props.value) {
76
- action = 'deleted';
76
+ action = "deleted";
77
77
  }
78
78
 
79
79
  beaconHandler({ action });
@@ -90,9 +90,9 @@ export const useInputBeacon = (props: TransformedInput) => {
90
90
  */
91
91
  export const useInputAsset = (
92
92
  props: TransformedInput,
93
- config?: InputHookConfig
93
+ config?: InputHookConfig,
94
94
  ) => {
95
- const [localValue, setLocalValue] = React.useState(props.value ?? '');
95
+ const [localValue, setLocalValue] = React.useState(props.value ?? "");
96
96
  const formatTimerRef = React.useRef<NodeJS.Timeout | undefined>(undefined);
97
97
  const inputBeacon = useInputBeacon(props);
98
98
 
@@ -117,7 +117,7 @@ export const useInputAsset = (
117
117
 
118
118
  /** Determines whether pressed key should trigger slow format or quick format delay */
119
119
  function getFormatDelaySpeed(e: React.KeyboardEvent<HTMLInputElement>) {
120
- const key = slowFormatKeys.every((k) => typeof k === 'number')
120
+ const key = slowFormatKeys.every((k) => typeof k === "number")
121
121
  ? e.which
122
122
  : e.key;
123
123
 
@@ -150,9 +150,9 @@ export const useInputAsset = (
150
150
  e.preventDefault();
151
151
  target.setSelectionRange(pl, end - start + pl);
152
152
  } else if (
153
- (e.key === 'ArrowLeft' && atStart) ||
154
- (e.key === 'Backspace' && atStart && atEnd) ||
155
- e.key === 'Home'
153
+ (e.key === "ArrowLeft" && atStart) ||
154
+ (e.key === "Backspace" && atStart && atEnd) ||
155
+ e.key === "Home"
156
156
  ) {
157
157
  e.preventDefault();
158
158
  target.setSelectionRange(prefix.length, prefix.length);
@@ -161,7 +161,7 @@ export const useInputAsset = (
161
161
 
162
162
  /** Helper to add affixes to value where appropriate */
163
163
  function formatValueWithAffix(value: string | undefined) {
164
- if (!value) return '';
164
+ if (!value) return "";
165
165
 
166
166
  return `${prefix}${value}${suffix}`;
167
167
  }
@@ -169,7 +169,7 @@ export const useInputAsset = (
169
169
  /** Value handling logic on key down */
170
170
  const onKeyDownHandler: KeyDownHandler = (currentValue: string) => {
171
171
  const symbolPosition = currentValue.indexOf(decimalSymbol);
172
- const newValue = props.format(currentValue) ?? '';
172
+ const newValue = props.format(currentValue) ?? "";
173
173
  const newSymbolPosition = newValue.indexOf(decimalSymbol);
174
174
 
175
175
  if (
@@ -200,15 +200,15 @@ export const useInputAsset = (
200
200
 
201
201
  const formatted =
202
202
  (prefix
203
- ? e.target.value.replace(prefix, '')
204
- : props.format(e.target.value)) ?? '';
203
+ ? e.target.value.replace(prefix, "")
204
+ : props.format(e.target.value)) ?? "";
205
205
 
206
206
  if (formatted) {
207
207
  props.set(formatted);
208
208
  setLocalValue(formatValueWithAffix(formatted));
209
209
  } else {
210
- props.set('');
211
- setLocalValue('');
210
+ props.set("");
211
+ setLocalValue("");
212
212
  }
213
213
 
214
214
  if (!suppressBeacons) {
@@ -251,7 +251,7 @@ export const useInputAsset = (
251
251
  /** Format value onFocus if affixes exist */
252
252
  const onFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {
253
253
  const target = e.target as HTMLInputElement;
254
- const inputEmpty = target.value === '';
254
+ const inputEmpty = target.value === "";
255
255
 
256
256
  if ((!inputEmpty && suffix) || (inputEmpty && prefix)) {
257
257
  setLocalValue(handleAffixOnFocus(target));
@@ -1,2 +1,2 @@
1
- export * from './Input';
2
- export * from './hooks';
1
+ export * from "./Input";
2
+ export * from "./hooks";
@@ -1,6 +1,6 @@
1
- import type { TransformedInput } from '@player-ui/reference-assets-plugin';
1
+ import type { TransformedInput } from "@player-ui/reference-assets-plugin";
2
2
 
3
3
  export type KeyDownHandler = (
4
4
  currentValue: string,
5
- props?: TransformedInput
5
+ props?: TransformedInput,
6
6
  ) => any;
@@ -1,17 +1,16 @@
1
- import React from 'react';
2
- import { Link } from '@chakra-ui/react';
1
+ import React from "react";
3
2
  import type {
4
3
  TextAsset,
5
4
  LinkModifier,
6
- } from '@player-ui/reference-assets-plugin';
7
- import { useText } from './hooks';
5
+ } from "@player-ui/reference-assets-plugin";
6
+ import { useText } from "./hooks";
8
7
 
9
8
  /** Find any link modifiers on the text */
10
9
  export const getLinkModifier = (asset: TextAsset): LinkModifier | undefined => {
11
10
  return asset.modifiers?.find(
12
11
  (mod) =>
13
- mod.type === 'link' &&
14
- (mod.metaData as LinkModifier['metaData'])?.ref !== undefined
12
+ mod.type === "link" &&
13
+ (mod.metaData as LinkModifier["metaData"])?.ref !== undefined,
15
14
  ) as LinkModifier;
16
15
  };
17
16
 
@@ -22,7 +21,14 @@ export const Text = (props: TextAsset) => {
22
21
  const { value } = props;
23
22
 
24
23
  if (linkModifier) {
25
- return <Link href={linkModifier.metaData.ref}>{value}</Link>;
24
+ return (
25
+ <a
26
+ className="underline text-blue-600 hover:text-blue-800 visited:text-purple-600"
27
+ href={linkModifier.metaData.ref}
28
+ >
29
+ {value}
30
+ </a>
31
+ );
26
32
  }
27
33
 
28
34
  return <span {...spanProps}>{value}</span>;
@@ -1,7 +1,7 @@
1
- import React, { useContext } from 'react';
2
- import makeClass from 'clsx';
3
- import { useAssetProps } from '@player-ui/react';
4
- import type { TextAsset } from '@player-ui/reference-assets-plugin';
1
+ import React, { useContext } from "react";
2
+ import makeClass from "clsx";
3
+ import { useAssetProps } from "@player-ui/react";
4
+ import type { TextAsset } from "@player-ui/reference-assets-plugin";
5
5
 
6
6
  export interface TextModifierContextType {
7
7
  getClassForModifier?<T>(modifier: T): string | undefined;
@@ -12,14 +12,14 @@ export const TextModifierContext = React.createContext<
12
12
  >(undefined);
13
13
 
14
14
  /** Get the props for a basic text element */
15
- export const useText = (props: TextAsset): JSX.IntrinsicElements['span'] => {
15
+ export const useText = (props: TextAsset): JSX.IntrinsicElements["span"] => {
16
16
  let className: string | undefined;
17
17
 
18
18
  const modifierContext = useContext(TextModifierContext);
19
19
 
20
20
  if (props.modifiers && modifierContext?.getClassForModifier) {
21
21
  className = makeClass(
22
- ...props.modifiers.map(modifierContext.getClassForModifier)
22
+ ...props.modifiers.map(modifierContext.getClassForModifier),
23
23
  );
24
24
  }
25
25
 
@@ -1,2 +1,2 @@
1
- export * from './Text';
2
- export * from './hooks';
1
+ export * from "./Text";
2
+ export * from "./hooks";
@@ -0,0 +1,56 @@
1
+ import * as React from "react";
2
+ import { Slot } from "@radix-ui/react-slot";
3
+ import { cva, type VariantProps } from "class-variance-authority";
4
+ import { cn } from "../utils";
5
+
6
+ const buttonVariants = cva(
7
+ "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default:
12
+ "bg-primary text-primary-foreground shadow hover:bg-primary/90",
13
+ destructive:
14
+ "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
15
+ outline:
16
+ "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
17
+ secondary:
18
+ "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
19
+ ghost: "hover:bg-accent hover:text-accent-foreground",
20
+ link: "text-primary underline-offset-4 hover:underline",
21
+ },
22
+ size: {
23
+ default: "h-9 px-4 py-2",
24
+ sm: "h-8 rounded-md px-3 text-xs",
25
+ lg: "h-10 rounded-md px-8",
26
+ icon: "h-9 w-9",
27
+ },
28
+ },
29
+ defaultVariants: {
30
+ variant: "default",
31
+ size: "default",
32
+ },
33
+ },
34
+ );
35
+
36
+ export interface ButtonProps
37
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
38
+ VariantProps<typeof buttonVariants> {
39
+ asChild?: boolean;
40
+ }
41
+
42
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
43
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
44
+ const Comp = asChild ? Slot : "button";
45
+ return (
46
+ <Comp
47
+ className={cn(buttonVariants({ variant, size, className }))}
48
+ ref={ref}
49
+ {...props}
50
+ />
51
+ );
52
+ },
53
+ );
54
+ Button.displayName = "Button";
55
+
56
+ export { Button, buttonVariants };
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ import { ReactAsset } from "@player-ui/react";
3
+ import { Input as InputComp } from "./Input";
4
+ import { Label } from "./Label";
5
+ import type { ChoiceItem as ChoiceItemType } from "@player-ui/reference-assets-plugin";
6
+
7
+ export type ChoiceItemProps = React.InputHTMLAttributes<HTMLInputElement> &
8
+ Pick<ChoiceItemType, "label">;
9
+
10
+ /** A choice item */
11
+ export const ChoiceItem = (props: ChoiceItemProps) => {
12
+ const { label, id, ...rest } = props;
13
+
14
+ return (
15
+ <div className="flex items-center gap-1.5">
16
+ <InputComp
17
+ type="radio"
18
+ className="h-fit w-fit shadow-none"
19
+ id={id}
20
+ {...rest}
21
+ />
22
+ {label && (
23
+ <Label htmlFor={id}>
24
+ <ReactAsset {...label} />
25
+ </Label>
26
+ )}
27
+ </div>
28
+ );
29
+ };
30
+
31
+ export default ChoiceItem;
@@ -0,0 +1,26 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-interface */
2
+ import * as React from "react";
3
+
4
+ import { cn } from "../utils";
5
+
6
+ export interface InputProps
7
+ extends React.InputHTMLAttributes<HTMLInputElement> {}
8
+
9
+ const Input = React.forwardRef<HTMLInputElement, InputProps>(
10
+ ({ className, type, ...props }, ref) => {
11
+ return (
12
+ <input
13
+ type={type}
14
+ className={cn(
15
+ "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
16
+ className,
17
+ )}
18
+ ref={ref}
19
+ {...props}
20
+ />
21
+ );
22
+ },
23
+ );
24
+ Input.displayName = "Input";
25
+
26
+ export { Input };
@@ -0,0 +1,26 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import * as LabelPrimitive from "@radix-ui/react-label";
5
+ import { cva, type VariantProps } from "class-variance-authority";
6
+
7
+ import { cn } from "../utils";
8
+
9
+ const labelVariants = cva(
10
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
11
+ );
12
+
13
+ const Label = React.forwardRef<
14
+ React.ElementRef<typeof LabelPrimitive.Root>,
15
+ React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
16
+ VariantProps<typeof labelVariants>
17
+ >(({ className, ...props }, ref) => (
18
+ <LabelPrimitive.Root
19
+ ref={ref}
20
+ className={cn(labelVariants(), className)}
21
+ {...props}
22
+ />
23
+ ));
24
+ Label.displayName = LabelPrimitive.Root.displayName;
25
+
26
+ export { Label };
@@ -0,0 +1,30 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import * as SeparatorPrimitive from "@radix-ui/react-separator";
5
+ import { cn } from "../utils";
6
+
7
+ const Separator = React.forwardRef<
8
+ React.ElementRef<typeof SeparatorPrimitive.Root>,
9
+ SeparatorPrimitive.SeparatorProps
10
+ >(
11
+ (
12
+ { className, orientation = "horizontal", decorative = true, ...props },
13
+ ref,
14
+ ) => (
15
+ <SeparatorPrimitive.Root
16
+ ref={ref}
17
+ decorative={decorative}
18
+ orientation={orientation}
19
+ className={cn(
20
+ "shrink-0 bg-border",
21
+ orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
22
+ className,
23
+ )}
24
+ {...props}
25
+ />
26
+ ),
27
+ );
28
+ Separator.displayName = SeparatorPrimitive.Root.displayName;
29
+
30
+ export { Separator };
package/src/global.css ADDED
@@ -0,0 +1,83 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ @layer base {
6
+ :root {
7
+ --background: 0 0% 100%;
8
+ --foreground: 222.2 47.4% 11.2%;
9
+
10
+ --muted: 210 40% 96.1%;
11
+ --muted-foreground: 215.4 16.3% 46.9%;
12
+
13
+ --popover: 0 0% 100%;
14
+ --popover-foreground: 222.2 47.4% 11.2%;
15
+
16
+ --border: 214.3 31.8% 91.4%;
17
+ --input: 214.3 31.8% 91.4%;
18
+
19
+ --card: 0 0% 100%;
20
+ --card-foreground: 222.2 47.4% 11.2%;
21
+
22
+ --primary: 222.2 47.4% 11.2%;
23
+ --primary-foreground: 210 40% 98%;
24
+
25
+ --secondary: 210 40% 96.1%;
26
+ --secondary-foreground: 222.2 47.4% 11.2%;
27
+
28
+ --accent: 210 40% 96.1%;
29
+ --accent-foreground: 222.2 47.4% 11.2%;
30
+
31
+ --destructive: 0 100% 50%;
32
+ --destructive-foreground: 210 40% 98%;
33
+
34
+ --ring: 215 20.2% 65.1%;
35
+
36
+ --radius: 0.5rem;
37
+ }
38
+
39
+ .dark {
40
+ --background: 224 71% 4%;
41
+ --foreground: 213 31% 91%;
42
+
43
+ --muted: 223 47% 11%;
44
+ --muted-foreground: 215.4 16.3% 56.9%;
45
+
46
+ --accent: 216 34% 17%;
47
+ --accent-foreground: 210 40% 98%;
48
+
49
+ --popover: 224 71% 4%;
50
+ --popover-foreground: 215 20.2% 65.1%;
51
+
52
+ --border: 216 34% 17%;
53
+ --input: 216 34% 17%;
54
+
55
+ --card: 224 71% 4%;
56
+ --card-foreground: 213 31% 91%;
57
+
58
+ --primary: 210 40% 98%;
59
+ --primary-foreground: 222.2 47.4% 1.2%;
60
+
61
+ --secondary: 222.2 47.4% 11.2%;
62
+ --secondary-foreground: 210 40% 98%;
63
+
64
+ --destructive: 0 63% 31%;
65
+ --destructive-foreground: 210 40% 98%;
66
+
67
+ --ring: 216 34% 17%;
68
+
69
+ --radius: 0.5rem;
70
+ }
71
+ }
72
+
73
+ @layer base {
74
+ * {
75
+ @apply border-border;
76
+ }
77
+ body {
78
+ @apply bg-background text-foreground;
79
+ font-feature-settings:
80
+ "rlig" 1,
81
+ "calt" 1;
82
+ }
83
+ }
package/src/index.tsx CHANGED
@@ -1,2 +1,4 @@
1
- export * from './plugin';
2
- export * from './assets';
1
+ import "./global.css";
2
+
3
+ export * from "./plugin";
4
+ export * from "./assets";
@@ -1,4 +1,4 @@
1
- import { Meta } from '@storybook/addon-docs/blocks';
1
+ import { Meta } from "@storybook/addon-docs";
2
2
 
3
3
  <Meta title="Reference Assets/Intro" />
4
4
 
@@ -7,20 +7,20 @@ import { Meta } from '@storybook/addon-docs/blocks';
7
7
  The assets in this section are an example implementation of an Asset Library for Player.
8
8
  Each of the Asset components follows the same basic pattern:
9
9
 
10
- | Export | Description |
11
- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
12
- | `<Name>Asset` | Typescript type interface representing the authored player content |
13
- | `Transformed<Name>Asset` | (optional) - A Typescript interface representing the _transformed_ version of the asset interface. This extends the base interface and includes any state/properties added by the associated transform. |
14
- | `transform` | (optional) - A function (used by the `AssetTransformPlugin`) to adopt Player's current state with the component state. If no `transfrom` is present, the component state is the same as the authored content. |
15
- | `Component` | React component rendering of the given asset. The props are the _transformed_ type (if supplied) or the _authored_ type. |
10
+ | Export | Description |
11
+ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
12
+ | `<Name>Asset` | Typescript type interface representing the authored player content |
13
+ | `Transformed<Name>Asset` | (optional) - A Typescript interface representing the _transformed_ version of the asset interface. This extends the base interface and includes any state/properties added by the associated transform. |
14
+ | `transform` | (optional) - A function (used by the `AssetTransformPlugin`) to adopt Player's current state with the component state. If no `transfrom` is present, the component state is the same as the authored content. |
15
+ | `Component` | React component rendering of the given asset. The props are the _transformed_ type (if supplied) or the _authored_ type. |
16
16
 
17
17
  ## Usage
18
18
 
19
19
  To import and use these Assets in your App, simply import the `plugin` and attach it to Player:
20
20
 
21
21
  ```tsx
22
- import { useReactPlayer, ReactPlayerPlugin } from '@player-ui/react';
23
- import ReferenceAssetsPlugin from '@player-ui/reference-assets/plugin-react';
22
+ import { useReactPlayer, ReactPlayerPlugin } from "@player-ui/react";
23
+ import ReferenceAssetsPlugin from "@player-ui/reference-assets/plugin-react";
24
24
 
25
25
  const plugins: Array<ReactPlayerPlugin> = [new ReferenceAssetsPlugin()];
26
26
 
package/src/plugin.tsx CHANGED
@@ -1,33 +1,21 @@
1
- import React from 'react';
2
- import type { ReactPlayer, ReactPlayerPlugin } from '@player-ui/react';
3
- import type { Player, ExtendedPlayerPlugin } from '@player-ui/player';
4
- import { AssetProviderPlugin } from '@player-ui/asset-provider-plugin-react';
5
- import { ChakraProvider, useTheme } from '@chakra-ui/react';
1
+ import React from "react";
2
+ import type {
3
+ ReactPlayer,
4
+ ReactPlayerPlugin,
5
+ Player,
6
+ ExtendedPlayerPlugin,
7
+ } from "@player-ui/react";
8
+ import { AssetProviderPlugin } from "@player-ui/asset-provider-plugin-react";
6
9
  import type {
7
10
  InputAsset,
8
11
  TextAsset,
9
12
  CollectionAsset,
10
13
  ActionAsset,
11
14
  InfoAsset,
12
- } from '@player-ui/reference-assets-plugin';
13
- import { ReferenceAssetsPlugin as ReferenceAssetsCorePlugin } from '@player-ui/reference-assets-plugin';
14
- import { Input, Text, Collection, Action, Info, Image } from './assets';
15
-
16
- /**
17
- *
18
- */
19
- const OptionalChakraThemeProvider = (
20
- props: React.PropsWithChildren<unknown>
21
- ) => {
22
- const theme = useTheme();
23
-
24
- if (theme) {
25
- // eslint-disable-next-line react/jsx-no-useless-fragment
26
- return <>{props.children}</>;
27
- }
28
-
29
- return <ChakraProvider>{props.children}</ChakraProvider>;
30
- };
15
+ ChoiceAsset,
16
+ } from "@player-ui/reference-assets-plugin";
17
+ import { ReferenceAssetsPlugin as ReferenceAssetsCorePlugin } from "@player-ui/reference-assets-plugin";
18
+ import { Input, Text, Collection, Action, Info, Image, Choice } from "./assets";
31
19
 
32
20
  /**
33
21
  * A plugin to register the base reference assets
@@ -36,33 +24,24 @@ export class ReferenceAssetsPlugin
36
24
  implements
37
25
  ReactPlayerPlugin,
38
26
  ExtendedPlayerPlugin<
39
- [InputAsset, TextAsset, ActionAsset, CollectionAsset],
27
+ [InputAsset, TextAsset, ActionAsset, CollectionAsset, ChoiceAsset],
40
28
  [InfoAsset]
41
29
  >
42
30
  {
43
- name = 'reference-assets-web-plugin';
31
+ name = "reference-assets-web-plugin";
44
32
 
45
33
  applyReact(reactPlayer: ReactPlayer) {
46
34
  reactPlayer.registerPlugin(
47
35
  new AssetProviderPlugin([
48
- ['input', Input],
49
- ['text', Text],
50
- ['action', Action],
51
- ['info', Info],
52
- ['collection', Collection],
53
- ['image', Image],
54
- ])
36
+ ["input", Input],
37
+ ["text", Text],
38
+ ["action", Action],
39
+ ["info", Info],
40
+ ["collection", Collection],
41
+ ["image", Image],
42
+ ["choice", Choice],
43
+ ]),
55
44
  );
56
-
57
- reactPlayer.hooks.webComponent.tap(this.name, (Comp) => {
58
- return () => {
59
- return (
60
- <OptionalChakraThemeProvider>
61
- <Comp />
62
- </OptionalChakraThemeProvider>
63
- );
64
- };
65
- });
66
45
  }
67
46
 
68
47
  apply(player: Player) {
package/src/utils.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import type { TransformedAction } from "@player-ui/reference-assets-plugin";
3
+ /**
4
+ * An action that a user can take
5
+ */
6
+ export declare const Action: (props: TransformedAction) => React.JSX.Element;
7
+ //# sourceMappingURL=Action.d.ts.map
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import type { TransformedAction } from "@player-ui/reference-assets-plugin";
3
+ /** Hook to get all the props for a button */
4
+ export declare const useAction: (props: TransformedAction) => {
5
+ readonly id: string;
6
+ readonly onClick: () => void;
7
+ readonly children: React.JSX.Element | null;
8
+ };
9
+ //# sourceMappingURL=hooks.d.ts.map