@player-ui/reference-assets-plugin-components 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.
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/components/src/index.tsx
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Action: () => Action,
34
+ ActionsSlot: () => ActionsSlot,
35
+ Choice: () => Choice,
36
+ Collection: () => Collection,
37
+ Image: () => Image,
38
+ Info: () => Info,
39
+ Input: () => Input,
40
+ ItemsSlot: () => ItemsSlot,
41
+ LabelSlot: () => LabelSlot,
42
+ NoteSlot: () => NoteSlot,
43
+ PrimaryInfoSlot: () => PrimaryInfoSlot,
44
+ SubtitleSlot: () => SubtitleSlot,
45
+ Text: () => Text,
46
+ TitleSlot: () => TitleSlot,
47
+ ValueSlot: () => ValueSlot,
48
+ dataRefs: () => dataRefs,
49
+ validationRefs: () => validationRefs
50
+ });
51
+ module.exports = __toCommonJS(src_exports);
52
+ var import_react = __toESM(require("react"));
53
+ var import_dsl = require("@player-tools/dsl");
54
+ var import_common_types_plugin = require("@player-ui/common-types-plugin");
55
+ var dataRefs = (0, import_dsl.getObjectReferences)(import_common_types_plugin.dataTypes);
56
+ var validationRefs = (0, import_dsl.getObjectReferences)(import_common_types_plugin.validators);
57
+ var Text = (props) => {
58
+ return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "text", ...props }, /* @__PURE__ */ import_react.default.createElement("property", { name: "value" }, props.children));
59
+ };
60
+ var Collection = (props) => {
61
+ return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "collection", ...props });
62
+ };
63
+ var CollectionComp = (props) => {
64
+ return /* @__PURE__ */ import_react.default.createElement(Collection, null, /* @__PURE__ */ import_react.default.createElement(Collection.Values, null, props.children));
65
+ };
66
+ var slotFactory = (name, isArray = false, wrapInAsset = true) => (0, import_dsl.createSlot)({
67
+ name,
68
+ TextComp: Text,
69
+ CollectionComp,
70
+ isArray,
71
+ wrapInAsset
72
+ });
73
+ var LabelSlot = slotFactory("label");
74
+ var ValueSlot = slotFactory("value");
75
+ var TitleSlot = slotFactory("title");
76
+ var NoteSlot = slotFactory("note");
77
+ var SubtitleSlot = slotFactory("subtitle");
78
+ var ActionsSlot = slotFactory("actions", true);
79
+ var PrimaryInfoSlot = slotFactory("primaryInfo");
80
+ var ItemsSlot = slotFactory("items", true, false);
81
+ Collection.Values = (0, import_dsl.createSlot)({
82
+ name: "values",
83
+ isArray: true,
84
+ TextComp: Text,
85
+ wrapInAsset: true
86
+ });
87
+ Collection.Label = LabelSlot;
88
+ var Action = (props) => {
89
+ const { exp, children, ...rest } = props;
90
+ return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "action", ...rest }, /* @__PURE__ */ import_react.default.createElement("property", { name: "exp" }, exp?.toValue()), children);
91
+ };
92
+ Action.Label = LabelSlot;
93
+ var Image = (props) => {
94
+ return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "image", ...props });
95
+ };
96
+ Image.Caption = slotFactory("caption");
97
+ var Input = (props) => {
98
+ const { binding, children, ...rest } = props;
99
+ return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "input", ...rest }, /* @__PURE__ */ import_react.default.createElement("property", { name: "binding" }, binding.toValue()), children);
100
+ };
101
+ Input.Label = LabelSlot;
102
+ Input.Note = NoteSlot;
103
+ var Info = (props) => {
104
+ return /* @__PURE__ */ import_react.default.createElement(import_dsl.View, { type: "info", ...props });
105
+ };
106
+ Info.Title = TitleSlot;
107
+ Info.Subtitle = SubtitleSlot;
108
+ Info.PrimaryInfo = PrimaryInfoSlot;
109
+ Info.Actions = ActionsSlot;
110
+ Info.Footer = slotFactory("footer");
111
+ var Choice = (props) => {
112
+ const { binding, children, ...rest } = props;
113
+ return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "choice", ...rest }, /* @__PURE__ */ import_react.default.createElement("property", { name: "binding" }, binding.toValue()), children);
114
+ };
115
+ Choice.Title = TitleSlot;
116
+ Choice.Note = NoteSlot;
117
+ Choice.Items = ItemsSlot;
118
+ var ChoiceItem = (props) => {
119
+ const { children, id, ...rest } = props;
120
+ return /* @__PURE__ */ import_react.default.createElement(import_dsl.ObjectWithIndexTracking, null, id && /* @__PURE__ */ import_react.default.createElement("property", { name: "id" }, /* @__PURE__ */ import_react.default.createElement("value", null, id)), !id && /* @__PURE__ */ import_react.default.createElement(import_dsl.GeneratedIDProperty, null), (0, import_dsl.toJsonProperties)(rest, { propertiesToSkip: ["applicability"] }), children);
121
+ };
122
+ ChoiceItem.Label = LabelSlot;
123
+ Choice.Item = ChoiceItem;
124
+ // Annotate the CommonJS export names for ESM import in node:
125
+ 0 && (module.exports = {
126
+ Action,
127
+ ActionsSlot,
128
+ Choice,
129
+ Collection,
130
+ Image,
131
+ Info,
132
+ Input,
133
+ ItemsSlot,
134
+ LabelSlot,
135
+ NoteSlot,
136
+ PrimaryInfoSlot,
137
+ SubtitleSlot,
138
+ Text,
139
+ TitleSlot,
140
+ ValueSlot,
141
+ dataRefs,
142
+ validationRefs
143
+ });
144
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/components/src/index.tsx"],"sourcesContent":["import React from \"react\";\nimport type {\n WithChildren,\n AssetPropsWithChildren,\n BindingTemplateInstance,\n ExpressionTemplateInstance,\n DSLSchema as PlayerDSLSchema,\n DataTypeReference,\n DataTypeRefs,\n ValidatorFunctionRefs,\n WithPlayerTypes,\n} from \"@player-tools/dsl\";\nimport {\n createSlot,\n Asset,\n View,\n getObjectReferences,\n toJsonProperties,\n ObjectWithIndexTracking,\n GeneratedIDProperty,\n} from \"@player-tools/dsl\";\nimport type { Asset as AssetType } from \"@player-ui/player\";\nimport type {\n ActionAsset,\n TextAsset,\n CollectionAsset,\n InfoAsset,\n InputAsset,\n ImageAsset,\n ChoiceAsset,\n ChoiceItem as ChoiceItemType,\n} from \"@player-ui/reference-assets-plugin\";\nimport { dataTypes, validators } from \"@player-ui/common-types-plugin\";\n\nexport const dataRefs = getObjectReferences<\n typeof dataTypes,\n DataTypeRefs<typeof dataTypes>\n>(dataTypes);\n\nexport const validationRefs = getObjectReferences<\n typeof validators,\n ValidatorFunctionRefs<typeof validators>\n>(validators);\n\nexport type DSLSchema = PlayerDSLSchema<\n DataTypeReference<typeof dataTypes, ValidatorFunctionRefs<typeof validators>>\n>;\n\nexport const Text = (\n props: Omit<AssetPropsWithChildren<TextAsset>, \"value\"> & {\n value?: string;\n },\n) => {\n return (\n <Asset type=\"text\" {...props}>\n <property name=\"value\">{props.children}</property>\n </Asset>\n );\n};\n\nexport const Collection = (props: AssetPropsWithChildren<CollectionAsset>) => {\n return <Asset type=\"collection\" {...props} />;\n};\n\nconst CollectionComp = (props: AssetPropsWithChildren<AssetType>) => {\n return (\n <Collection>\n <Collection.Values>{props.children}</Collection.Values>\n </Collection>\n );\n};\n\n/** A utility for quickly creating named slots using the text and collection factories */\nconst slotFactory = (name: string, isArray = false, wrapInAsset = true) =>\n createSlot({\n name,\n TextComp: Text,\n CollectionComp,\n isArray,\n wrapInAsset,\n });\n\nexport const LabelSlot = slotFactory(\"label\");\nexport const ValueSlot = slotFactory(\"value\");\nexport const TitleSlot = slotFactory(\"title\");\nexport const NoteSlot = slotFactory(\"note\");\nexport const SubtitleSlot = slotFactory(\"subtitle\");\nexport const ActionsSlot = slotFactory(\"actions\", true);\nexport const PrimaryInfoSlot = slotFactory(\"primaryInfo\");\nexport const ItemsSlot = slotFactory(\"items\", true, false);\n\nCollection.Values = createSlot({\n name: \"values\",\n isArray: true,\n TextComp: Text,\n wrapInAsset: true,\n});\n\nCollection.Label = LabelSlot;\n\nexport const Action = (\n props: Omit<AssetPropsWithChildren<ActionAsset>, \"exp\"> & {\n /** An optional expression to execute before transitioning */\n exp?: ExpressionTemplateInstance;\n },\n) => {\n const { exp, children, ...rest } = props;\n\n return (\n <Asset type=\"action\" {...rest}>\n <property name=\"exp\">{exp?.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nAction.Label = LabelSlot;\n\nexport const Image = (props: AssetPropsWithChildren<ImageAsset>) => {\n return <Asset type=\"image\" {...props} />;\n};\n\nImage.Caption = slotFactory(\"caption\");\n\nexport const Input = (\n props: Omit<AssetPropsWithChildren<InputAsset>, \"binding\"> & {\n /** The binding */\n binding: BindingTemplateInstance;\n },\n) => {\n const { binding, children, ...rest } = props;\n return (\n <Asset type=\"input\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nInput.Label = LabelSlot;\nInput.Note = NoteSlot;\n\nexport const Info = (props: AssetPropsWithChildren<InfoAsset>) => {\n return <View type=\"info\" {...props} />;\n};\n\nInfo.Title = TitleSlot;\nInfo.Subtitle = SubtitleSlot;\nInfo.PrimaryInfo = PrimaryInfoSlot;\nInfo.Actions = ActionsSlot;\nInfo.Footer = slotFactory(\"footer\");\n\nexport const Choice = (\n props: Omit<AssetPropsWithChildren<ChoiceAsset>, \"binding\"> & {\n /** The binding */\n binding: BindingTemplateInstance;\n },\n) => {\n const { binding, children, ...rest } = props;\n return (\n <Asset type=\"choice\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nChoice.Title = TitleSlot;\nChoice.Note = NoteSlot;\nChoice.Items = ItemsSlot;\n\nconst ChoiceItem = (\n props: WithChildren<\n WithPlayerTypes<\n Omit<ChoiceItemType, \"id\"> & {\n id?: string;\n }\n >\n >,\n) => {\n const { children, id, ...rest } = props;\n\n return (\n <ObjectWithIndexTracking>\n {id && (\n <property name=\"id\">\n <value>{id}</value>\n </property>\n )}\n {!id && <GeneratedIDProperty />}\n {toJsonProperties(rest, { propertiesToSkip: [\"applicability\"] })}\n {children}\n </ObjectWithIndexTracking>\n );\n};\n\nChoiceItem.Label = LabelSlot;\nChoice.Item = ChoiceItem;\n"],"mappings":"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","names":["React"]}
@@ -0,0 +1,101 @@
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/components/src/index.tsx
2
+ import React from "react";
3
+ import {
4
+ createSlot,
5
+ Asset,
6
+ View,
7
+ getObjectReferences,
8
+ toJsonProperties,
9
+ ObjectWithIndexTracking,
10
+ GeneratedIDProperty
11
+ } from "@player-tools/dsl";
12
+ import { dataTypes, validators } from "@player-ui/common-types-plugin";
13
+ var dataRefs = getObjectReferences(dataTypes);
14
+ var validationRefs = getObjectReferences(validators);
15
+ var Text = (props) => {
16
+ return /* @__PURE__ */ React.createElement(Asset, { type: "text", ...props }, /* @__PURE__ */ React.createElement("property", { name: "value" }, props.children));
17
+ };
18
+ var Collection = (props) => {
19
+ return /* @__PURE__ */ React.createElement(Asset, { type: "collection", ...props });
20
+ };
21
+ var CollectionComp = (props) => {
22
+ return /* @__PURE__ */ React.createElement(Collection, null, /* @__PURE__ */ React.createElement(Collection.Values, null, props.children));
23
+ };
24
+ var slotFactory = (name, isArray = false, wrapInAsset = true) => createSlot({
25
+ name,
26
+ TextComp: Text,
27
+ CollectionComp,
28
+ isArray,
29
+ wrapInAsset
30
+ });
31
+ var LabelSlot = slotFactory("label");
32
+ var ValueSlot = slotFactory("value");
33
+ var TitleSlot = slotFactory("title");
34
+ var NoteSlot = slotFactory("note");
35
+ var SubtitleSlot = slotFactory("subtitle");
36
+ var ActionsSlot = slotFactory("actions", true);
37
+ var PrimaryInfoSlot = slotFactory("primaryInfo");
38
+ var ItemsSlot = slotFactory("items", true, false);
39
+ Collection.Values = createSlot({
40
+ name: "values",
41
+ isArray: true,
42
+ TextComp: Text,
43
+ wrapInAsset: true
44
+ });
45
+ Collection.Label = LabelSlot;
46
+ var Action = (props) => {
47
+ const { exp, children, ...rest } = props;
48
+ return /* @__PURE__ */ React.createElement(Asset, { type: "action", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "exp" }, exp?.toValue()), children);
49
+ };
50
+ Action.Label = LabelSlot;
51
+ var Image = (props) => {
52
+ return /* @__PURE__ */ React.createElement(Asset, { type: "image", ...props });
53
+ };
54
+ Image.Caption = slotFactory("caption");
55
+ var Input = (props) => {
56
+ const { binding, children, ...rest } = props;
57
+ return /* @__PURE__ */ React.createElement(Asset, { type: "input", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "binding" }, binding.toValue()), children);
58
+ };
59
+ Input.Label = LabelSlot;
60
+ Input.Note = NoteSlot;
61
+ var Info = (props) => {
62
+ return /* @__PURE__ */ React.createElement(View, { type: "info", ...props });
63
+ };
64
+ Info.Title = TitleSlot;
65
+ Info.Subtitle = SubtitleSlot;
66
+ Info.PrimaryInfo = PrimaryInfoSlot;
67
+ Info.Actions = ActionsSlot;
68
+ Info.Footer = slotFactory("footer");
69
+ var Choice = (props) => {
70
+ const { binding, children, ...rest } = props;
71
+ return /* @__PURE__ */ React.createElement(Asset, { type: "choice", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "binding" }, binding.toValue()), children);
72
+ };
73
+ Choice.Title = TitleSlot;
74
+ Choice.Note = NoteSlot;
75
+ Choice.Items = ItemsSlot;
76
+ var ChoiceItem = (props) => {
77
+ const { children, id, ...rest } = props;
78
+ return /* @__PURE__ */ React.createElement(ObjectWithIndexTracking, null, id && /* @__PURE__ */ React.createElement("property", { name: "id" }, /* @__PURE__ */ React.createElement("value", null, id)), !id && /* @__PURE__ */ React.createElement(GeneratedIDProperty, null), toJsonProperties(rest, { propertiesToSkip: ["applicability"] }), children);
79
+ };
80
+ ChoiceItem.Label = LabelSlot;
81
+ Choice.Item = ChoiceItem;
82
+ export {
83
+ Action,
84
+ ActionsSlot,
85
+ Choice,
86
+ Collection,
87
+ Image,
88
+ Info,
89
+ Input,
90
+ ItemsSlot,
91
+ LabelSlot,
92
+ NoteSlot,
93
+ PrimaryInfoSlot,
94
+ SubtitleSlot,
95
+ Text,
96
+ TitleSlot,
97
+ ValueSlot,
98
+ dataRefs,
99
+ validationRefs
100
+ };
101
+ //# sourceMappingURL=index.mjs.map
package/dist/index.mjs ADDED
@@ -0,0 +1,101 @@
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/components/src/index.tsx
2
+ import React from "react";
3
+ import {
4
+ createSlot,
5
+ Asset,
6
+ View,
7
+ getObjectReferences,
8
+ toJsonProperties,
9
+ ObjectWithIndexTracking,
10
+ GeneratedIDProperty
11
+ } from "@player-tools/dsl";
12
+ import { dataTypes, validators } from "@player-ui/common-types-plugin";
13
+ var dataRefs = getObjectReferences(dataTypes);
14
+ var validationRefs = getObjectReferences(validators);
15
+ var Text = (props) => {
16
+ return /* @__PURE__ */ React.createElement(Asset, { type: "text", ...props }, /* @__PURE__ */ React.createElement("property", { name: "value" }, props.children));
17
+ };
18
+ var Collection = (props) => {
19
+ return /* @__PURE__ */ React.createElement(Asset, { type: "collection", ...props });
20
+ };
21
+ var CollectionComp = (props) => {
22
+ return /* @__PURE__ */ React.createElement(Collection, null, /* @__PURE__ */ React.createElement(Collection.Values, null, props.children));
23
+ };
24
+ var slotFactory = (name, isArray = false, wrapInAsset = true) => createSlot({
25
+ name,
26
+ TextComp: Text,
27
+ CollectionComp,
28
+ isArray,
29
+ wrapInAsset
30
+ });
31
+ var LabelSlot = slotFactory("label");
32
+ var ValueSlot = slotFactory("value");
33
+ var TitleSlot = slotFactory("title");
34
+ var NoteSlot = slotFactory("note");
35
+ var SubtitleSlot = slotFactory("subtitle");
36
+ var ActionsSlot = slotFactory("actions", true);
37
+ var PrimaryInfoSlot = slotFactory("primaryInfo");
38
+ var ItemsSlot = slotFactory("items", true, false);
39
+ Collection.Values = createSlot({
40
+ name: "values",
41
+ isArray: true,
42
+ TextComp: Text,
43
+ wrapInAsset: true
44
+ });
45
+ Collection.Label = LabelSlot;
46
+ var Action = (props) => {
47
+ const { exp, children, ...rest } = props;
48
+ return /* @__PURE__ */ React.createElement(Asset, { type: "action", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "exp" }, exp?.toValue()), children);
49
+ };
50
+ Action.Label = LabelSlot;
51
+ var Image = (props) => {
52
+ return /* @__PURE__ */ React.createElement(Asset, { type: "image", ...props });
53
+ };
54
+ Image.Caption = slotFactory("caption");
55
+ var Input = (props) => {
56
+ const { binding, children, ...rest } = props;
57
+ return /* @__PURE__ */ React.createElement(Asset, { type: "input", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "binding" }, binding.toValue()), children);
58
+ };
59
+ Input.Label = LabelSlot;
60
+ Input.Note = NoteSlot;
61
+ var Info = (props) => {
62
+ return /* @__PURE__ */ React.createElement(View, { type: "info", ...props });
63
+ };
64
+ Info.Title = TitleSlot;
65
+ Info.Subtitle = SubtitleSlot;
66
+ Info.PrimaryInfo = PrimaryInfoSlot;
67
+ Info.Actions = ActionsSlot;
68
+ Info.Footer = slotFactory("footer");
69
+ var Choice = (props) => {
70
+ const { binding, children, ...rest } = props;
71
+ return /* @__PURE__ */ React.createElement(Asset, { type: "choice", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "binding" }, binding.toValue()), children);
72
+ };
73
+ Choice.Title = TitleSlot;
74
+ Choice.Note = NoteSlot;
75
+ Choice.Items = ItemsSlot;
76
+ var ChoiceItem = (props) => {
77
+ const { children, id, ...rest } = props;
78
+ return /* @__PURE__ */ React.createElement(ObjectWithIndexTracking, null, id && /* @__PURE__ */ React.createElement("property", { name: "id" }, /* @__PURE__ */ React.createElement("value", null, id)), !id && /* @__PURE__ */ React.createElement(GeneratedIDProperty, null), toJsonProperties(rest, { propertiesToSkip: ["applicability"] }), children);
79
+ };
80
+ ChoiceItem.Label = LabelSlot;
81
+ Choice.Item = ChoiceItem;
82
+ export {
83
+ Action,
84
+ ActionsSlot,
85
+ Choice,
86
+ Collection,
87
+ Image,
88
+ Info,
89
+ Input,
90
+ ItemsSlot,
91
+ LabelSlot,
92
+ NoteSlot,
93
+ PrimaryInfoSlot,
94
+ SubtitleSlot,
95
+ Text,
96
+ TitleSlot,
97
+ ValueSlot,
98
+ dataRefs,
99
+ validationRefs
100
+ };
101
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/reference-assets/components/src/index.tsx"],"sourcesContent":["import React from \"react\";\nimport type {\n WithChildren,\n AssetPropsWithChildren,\n BindingTemplateInstance,\n ExpressionTemplateInstance,\n DSLSchema as PlayerDSLSchema,\n DataTypeReference,\n DataTypeRefs,\n ValidatorFunctionRefs,\n WithPlayerTypes,\n} from \"@player-tools/dsl\";\nimport {\n createSlot,\n Asset,\n View,\n getObjectReferences,\n toJsonProperties,\n ObjectWithIndexTracking,\n GeneratedIDProperty,\n} from \"@player-tools/dsl\";\nimport type { Asset as AssetType } from \"@player-ui/player\";\nimport type {\n ActionAsset,\n TextAsset,\n CollectionAsset,\n InfoAsset,\n InputAsset,\n ImageAsset,\n ChoiceAsset,\n ChoiceItem as ChoiceItemType,\n} from \"@player-ui/reference-assets-plugin\";\nimport { dataTypes, validators } from \"@player-ui/common-types-plugin\";\n\nexport const dataRefs = getObjectReferences<\n typeof dataTypes,\n DataTypeRefs<typeof dataTypes>\n>(dataTypes);\n\nexport const validationRefs = getObjectReferences<\n typeof validators,\n ValidatorFunctionRefs<typeof validators>\n>(validators);\n\nexport type DSLSchema = PlayerDSLSchema<\n DataTypeReference<typeof dataTypes, ValidatorFunctionRefs<typeof validators>>\n>;\n\nexport const Text = (\n props: Omit<AssetPropsWithChildren<TextAsset>, \"value\"> & {\n value?: string;\n },\n) => {\n return (\n <Asset type=\"text\" {...props}>\n <property name=\"value\">{props.children}</property>\n </Asset>\n );\n};\n\nexport const Collection = (props: AssetPropsWithChildren<CollectionAsset>) => {\n return <Asset type=\"collection\" {...props} />;\n};\n\nconst CollectionComp = (props: AssetPropsWithChildren<AssetType>) => {\n return (\n <Collection>\n <Collection.Values>{props.children}</Collection.Values>\n </Collection>\n );\n};\n\n/** A utility for quickly creating named slots using the text and collection factories */\nconst slotFactory = (name: string, isArray = false, wrapInAsset = true) =>\n createSlot({\n name,\n TextComp: Text,\n CollectionComp,\n isArray,\n wrapInAsset,\n });\n\nexport const LabelSlot = slotFactory(\"label\");\nexport const ValueSlot = slotFactory(\"value\");\nexport const TitleSlot = slotFactory(\"title\");\nexport const NoteSlot = slotFactory(\"note\");\nexport const SubtitleSlot = slotFactory(\"subtitle\");\nexport const ActionsSlot = slotFactory(\"actions\", true);\nexport const PrimaryInfoSlot = slotFactory(\"primaryInfo\");\nexport const ItemsSlot = slotFactory(\"items\", true, false);\n\nCollection.Values = createSlot({\n name: \"values\",\n isArray: true,\n TextComp: Text,\n wrapInAsset: true,\n});\n\nCollection.Label = LabelSlot;\n\nexport const Action = (\n props: Omit<AssetPropsWithChildren<ActionAsset>, \"exp\"> & {\n /** An optional expression to execute before transitioning */\n exp?: ExpressionTemplateInstance;\n },\n) => {\n const { exp, children, ...rest } = props;\n\n return (\n <Asset type=\"action\" {...rest}>\n <property name=\"exp\">{exp?.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nAction.Label = LabelSlot;\n\nexport const Image = (props: AssetPropsWithChildren<ImageAsset>) => {\n return <Asset type=\"image\" {...props} />;\n};\n\nImage.Caption = slotFactory(\"caption\");\n\nexport const Input = (\n props: Omit<AssetPropsWithChildren<InputAsset>, \"binding\"> & {\n /** The binding */\n binding: BindingTemplateInstance;\n },\n) => {\n const { binding, children, ...rest } = props;\n return (\n <Asset type=\"input\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nInput.Label = LabelSlot;\nInput.Note = NoteSlot;\n\nexport const Info = (props: AssetPropsWithChildren<InfoAsset>) => {\n return <View type=\"info\" {...props} />;\n};\n\nInfo.Title = TitleSlot;\nInfo.Subtitle = SubtitleSlot;\nInfo.PrimaryInfo = PrimaryInfoSlot;\nInfo.Actions = ActionsSlot;\nInfo.Footer = slotFactory(\"footer\");\n\nexport const Choice = (\n props: Omit<AssetPropsWithChildren<ChoiceAsset>, \"binding\"> & {\n /** The binding */\n binding: BindingTemplateInstance;\n },\n) => {\n const { binding, children, ...rest } = props;\n return (\n <Asset type=\"choice\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nChoice.Title = TitleSlot;\nChoice.Note = NoteSlot;\nChoice.Items = ItemsSlot;\n\nconst ChoiceItem = (\n props: WithChildren<\n WithPlayerTypes<\n Omit<ChoiceItemType, \"id\"> & {\n id?: string;\n }\n >\n >,\n) => {\n const { children, id, ...rest } = props;\n\n return (\n <ObjectWithIndexTracking>\n {id && (\n <property name=\"id\">\n <value>{id}</value>\n </property>\n )}\n {!id && <GeneratedIDProperty />}\n {toJsonProperties(rest, { propertiesToSkip: [\"applicability\"] })}\n {children}\n </ObjectWithIndexTracking>\n );\n};\n\nChoiceItem.Label = LabelSlot;\nChoice.Item = ChoiceItem;\n"],"mappings":"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","names":[]}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@player-ui/reference-assets-plugin-components",
3
+ "version": "0.8.0-next.0",
4
+ "main": "dist/cjs/index.cjs",
5
+ "peerDependencies": {
6
+ "@player-ui/player": "0.8.0-next.0",
7
+ "react": "^18.2.0",
8
+ "@types/react": "^18.2.39",
9
+ "@player-tools/dsl": "0.6.1-next.2"
10
+ },
11
+ "dependencies": {
12
+ "@player-ui/common-types-plugin": "0.8.0-next.0",
13
+ "@player-ui/reference-assets-plugin": "0.8.0-next.0",
14
+ "tslib": "^2.6.2"
15
+ },
16
+ "module": "dist/index.legacy-esm.js",
17
+ "types": "types/index.d.ts",
18
+ "sideEffects": false,
19
+ "exports": {
20
+ "./package.json": "./package.json",
21
+ "./dist/index.css": "./dist/index.css",
22
+ ".": {
23
+ "types": "./types/index.d.ts",
24
+ "import": "./dist/index.mjs",
25
+ "default": "./dist/cjs/index.cjs"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "src",
31
+ "types"
32
+ ]
33
+ }
@@ -0,0 +1,284 @@
1
+ import React from "react";
2
+ import { describe, test, expect } from "vitest";
3
+ import { render, binding as b } from "@player-tools/dsl";
4
+ import { Text, Action, Info, Collection, Input, Choice } from ".";
5
+
6
+ describe("JSON serialization", () => {
7
+ describe("text", () => {
8
+ test("works for basic text", async () => {
9
+ expect((await render(<Text>Hello World</Text>)).jsonValue).toStrictEqual({
10
+ id: "root",
11
+ type: "text",
12
+ value: "Hello World",
13
+ });
14
+ });
15
+
16
+ test("works for value prop", async () => {
17
+ expect(
18
+ (await render(<Text value="Hello World" />)).jsonValue,
19
+ ).toStrictEqual({
20
+ id: "root",
21
+ type: "text",
22
+ value: "Hello World",
23
+ });
24
+ });
25
+ });
26
+
27
+ describe("collection", () => {
28
+ test("adds a label", async () => {
29
+ expect(
30
+ (
31
+ await render(
32
+ <Collection id="test-id">
33
+ <Collection.Label>Test</Collection.Label>
34
+ </Collection>,
35
+ )
36
+ ).jsonValue,
37
+ ).toStrictEqual({
38
+ id: "test-id",
39
+ type: "collection",
40
+ label: {
41
+ asset: {
42
+ id: "test-id-label",
43
+ type: "text",
44
+ value: "Test",
45
+ },
46
+ },
47
+ });
48
+ });
49
+
50
+ test("adds values", async () => {
51
+ expect(
52
+ (
53
+ await render(
54
+ <Collection>
55
+ <Collection.Values>
56
+ <Text>First</Text>
57
+ <Text>Second</Text>
58
+ </Collection.Values>
59
+ </Collection>,
60
+ )
61
+ ).jsonValue,
62
+ ).toStrictEqual({
63
+ id: "root",
64
+ type: "collection",
65
+ values: [
66
+ {
67
+ asset: {
68
+ id: "values-0",
69
+ type: "text",
70
+ value: "First",
71
+ },
72
+ },
73
+ {
74
+ asset: {
75
+ id: "values-1",
76
+ type: "text",
77
+ value: "Second",
78
+ },
79
+ },
80
+ ],
81
+ });
82
+ });
83
+ });
84
+
85
+ describe("info", () => {
86
+ test("works for a large view", async () => {
87
+ expect(
88
+ (
89
+ await render(
90
+ <Info id="info-view">
91
+ <Info.Title>Info Title</Info.Title>
92
+ <Info.PrimaryInfo>
93
+ <Input binding={b`foo.bar`}>
94
+ <Input.Label>Input Label</Input.Label>
95
+ </Input>
96
+ <Text id="input-result" value={b`foo.bar`.toString()} />
97
+ </Info.PrimaryInfo>
98
+ <Info.Actions>
99
+ <Action value="next">
100
+ <Action.Label>Continue</Action.Label>
101
+ </Action>
102
+ </Info.Actions>
103
+ </Info>,
104
+ )
105
+ ).jsonValue,
106
+ ).toStrictEqual({
107
+ id: "info-view",
108
+ type: "info",
109
+ title: {
110
+ asset: {
111
+ id: "info-view-title",
112
+ type: "text",
113
+ value: "Info Title",
114
+ },
115
+ },
116
+ primaryInfo: {
117
+ asset: {
118
+ id: "info-view-primaryInfo",
119
+ type: "collection",
120
+ values: [
121
+ {
122
+ asset: {
123
+ id: "info-view-primaryInfo-values-0",
124
+ type: "input",
125
+ binding: "foo.bar",
126
+ label: {
127
+ asset: {
128
+ id: "info-view-primaryInfo-values-0-label",
129
+ type: "text",
130
+ value: "Input Label",
131
+ },
132
+ },
133
+ },
134
+ },
135
+ {
136
+ asset: {
137
+ id: "input-result",
138
+ type: "text",
139
+ value: "{{foo.bar}}",
140
+ },
141
+ },
142
+ ],
143
+ },
144
+ },
145
+ actions: [
146
+ {
147
+ asset: {
148
+ id: "info-view-actions-0",
149
+ type: "action",
150
+ value: "next",
151
+ label: {
152
+ asset: {
153
+ id: "info-view-actions-0-label",
154
+ type: "text",
155
+ value: "Continue",
156
+ },
157
+ },
158
+ },
159
+ },
160
+ ],
161
+ });
162
+ });
163
+ });
164
+
165
+ describe("choice", () => {
166
+ test("works for title and choices", async () => {
167
+ expect(
168
+ (
169
+ await render(
170
+ <Choice id="choice-without-note" binding={b`foo.bar`}>
171
+ <Choice.Title>This is a list of choices</Choice.Title>
172
+ <Choice.Items>
173
+ <Choice.Item id="item-1" value="Item 1">
174
+ <Choice.Item.Label>Item 1</Choice.Item.Label>
175
+ </Choice.Item>
176
+ <Choice.Item id="item-2" value="Item 2">
177
+ <Choice.Item.Label>Item 2</Choice.Item.Label>
178
+ </Choice.Item>
179
+ </Choice.Items>
180
+ </Choice>,
181
+ )
182
+ ).jsonValue,
183
+ ).toStrictEqual({
184
+ id: "choice-without-note",
185
+ type: "choice",
186
+ binding: "foo.bar",
187
+ title: {
188
+ asset: {
189
+ id: "choice-without-note-title",
190
+ type: "text",
191
+ value: "This is a list of choices",
192
+ },
193
+ },
194
+ items: [
195
+ {
196
+ id: "item-1",
197
+ value: "Item 1",
198
+ label: {
199
+ asset: {
200
+ id: "choice-without-note-items-0-label",
201
+ type: "text",
202
+ value: "Item 1",
203
+ },
204
+ },
205
+ },
206
+ {
207
+ id: "item-2",
208
+ value: "Item 2",
209
+ label: {
210
+ asset: {
211
+ id: "choice-without-note-items-1-label",
212
+ type: "text",
213
+ value: "Item 2",
214
+ },
215
+ },
216
+ },
217
+ ],
218
+ });
219
+ });
220
+
221
+ test("works with a note", async () => {
222
+ expect(
223
+ (
224
+ await render(
225
+ <Choice id="choice-with-note" binding={b`foo.bar`}>
226
+ <Choice.Title>This is a list of choices</Choice.Title>
227
+ <Choice.Note>This is a note</Choice.Note>
228
+ <Choice.Items>
229
+ <Choice.Item id="item-1" value="Item 1">
230
+ <Choice.Item.Label>Item 1</Choice.Item.Label>
231
+ </Choice.Item>
232
+ <Choice.Item id="item-2" value="Item 2">
233
+ <Choice.Item.Label>Item 2</Choice.Item.Label>
234
+ </Choice.Item>
235
+ </Choice.Items>
236
+ </Choice>,
237
+ )
238
+ ).jsonValue,
239
+ ).toStrictEqual({
240
+ id: "choice-with-note",
241
+ type: "choice",
242
+ binding: "foo.bar",
243
+ title: {
244
+ asset: {
245
+ id: "choice-with-note-title",
246
+ type: "text",
247
+ value: "This is a list of choices",
248
+ },
249
+ },
250
+ note: {
251
+ asset: {
252
+ id: "choice-with-note-note",
253
+ type: "text",
254
+ value: "This is a note",
255
+ },
256
+ },
257
+ items: [
258
+ {
259
+ id: "item-1",
260
+ value: "Item 1",
261
+ label: {
262
+ asset: {
263
+ id: "choice-with-note-items-0-label",
264
+ type: "text",
265
+ value: "Item 1",
266
+ },
267
+ },
268
+ },
269
+ {
270
+ id: "item-2",
271
+ value: "Item 2",
272
+ label: {
273
+ asset: {
274
+ id: "choice-with-note-items-1-label",
275
+ type: "text",
276
+ value: "Item 2",
277
+ },
278
+ },
279
+ },
280
+ ],
281
+ });
282
+ });
283
+ });
284
+ });
package/src/index.tsx ADDED
@@ -0,0 +1,198 @@
1
+ import React from "react";
2
+ import type {
3
+ WithChildren,
4
+ AssetPropsWithChildren,
5
+ BindingTemplateInstance,
6
+ ExpressionTemplateInstance,
7
+ DSLSchema as PlayerDSLSchema,
8
+ DataTypeReference,
9
+ DataTypeRefs,
10
+ ValidatorFunctionRefs,
11
+ WithPlayerTypes,
12
+ } from "@player-tools/dsl";
13
+ import {
14
+ createSlot,
15
+ Asset,
16
+ View,
17
+ getObjectReferences,
18
+ toJsonProperties,
19
+ ObjectWithIndexTracking,
20
+ GeneratedIDProperty,
21
+ } from "@player-tools/dsl";
22
+ import type { Asset as AssetType } from "@player-ui/player";
23
+ import type {
24
+ ActionAsset,
25
+ TextAsset,
26
+ CollectionAsset,
27
+ InfoAsset,
28
+ InputAsset,
29
+ ImageAsset,
30
+ ChoiceAsset,
31
+ ChoiceItem as ChoiceItemType,
32
+ } from "@player-ui/reference-assets-plugin";
33
+ import { dataTypes, validators } from "@player-ui/common-types-plugin";
34
+
35
+ export const dataRefs = getObjectReferences<
36
+ typeof dataTypes,
37
+ DataTypeRefs<typeof dataTypes>
38
+ >(dataTypes);
39
+
40
+ export const validationRefs = getObjectReferences<
41
+ typeof validators,
42
+ ValidatorFunctionRefs<typeof validators>
43
+ >(validators);
44
+
45
+ export type DSLSchema = PlayerDSLSchema<
46
+ DataTypeReference<typeof dataTypes, ValidatorFunctionRefs<typeof validators>>
47
+ >;
48
+
49
+ export const Text = (
50
+ props: Omit<AssetPropsWithChildren<TextAsset>, "value"> & {
51
+ value?: string;
52
+ },
53
+ ) => {
54
+ return (
55
+ <Asset type="text" {...props}>
56
+ <property name="value">{props.children}</property>
57
+ </Asset>
58
+ );
59
+ };
60
+
61
+ export const Collection = (props: AssetPropsWithChildren<CollectionAsset>) => {
62
+ return <Asset type="collection" {...props} />;
63
+ };
64
+
65
+ const CollectionComp = (props: AssetPropsWithChildren<AssetType>) => {
66
+ return (
67
+ <Collection>
68
+ <Collection.Values>{props.children}</Collection.Values>
69
+ </Collection>
70
+ );
71
+ };
72
+
73
+ /** A utility for quickly creating named slots using the text and collection factories */
74
+ const slotFactory = (name: string, isArray = false, wrapInAsset = true) =>
75
+ createSlot({
76
+ name,
77
+ TextComp: Text,
78
+ CollectionComp,
79
+ isArray,
80
+ wrapInAsset,
81
+ });
82
+
83
+ export const LabelSlot = slotFactory("label");
84
+ export const ValueSlot = slotFactory("value");
85
+ export const TitleSlot = slotFactory("title");
86
+ export const NoteSlot = slotFactory("note");
87
+ export const SubtitleSlot = slotFactory("subtitle");
88
+ export const ActionsSlot = slotFactory("actions", true);
89
+ export const PrimaryInfoSlot = slotFactory("primaryInfo");
90
+ export const ItemsSlot = slotFactory("items", true, false);
91
+
92
+ Collection.Values = createSlot({
93
+ name: "values",
94
+ isArray: true,
95
+ TextComp: Text,
96
+ wrapInAsset: true,
97
+ });
98
+
99
+ Collection.Label = LabelSlot;
100
+
101
+ export const Action = (
102
+ props: Omit<AssetPropsWithChildren<ActionAsset>, "exp"> & {
103
+ /** An optional expression to execute before transitioning */
104
+ exp?: ExpressionTemplateInstance;
105
+ },
106
+ ) => {
107
+ const { exp, children, ...rest } = props;
108
+
109
+ return (
110
+ <Asset type="action" {...rest}>
111
+ <property name="exp">{exp?.toValue()}</property>
112
+ {children}
113
+ </Asset>
114
+ );
115
+ };
116
+
117
+ Action.Label = LabelSlot;
118
+
119
+ export const Image = (props: AssetPropsWithChildren<ImageAsset>) => {
120
+ return <Asset type="image" {...props} />;
121
+ };
122
+
123
+ Image.Caption = slotFactory("caption");
124
+
125
+ export const Input = (
126
+ props: Omit<AssetPropsWithChildren<InputAsset>, "binding"> & {
127
+ /** The binding */
128
+ binding: BindingTemplateInstance;
129
+ },
130
+ ) => {
131
+ const { binding, children, ...rest } = props;
132
+ return (
133
+ <Asset type="input" {...rest}>
134
+ <property name="binding">{binding.toValue()}</property>
135
+ {children}
136
+ </Asset>
137
+ );
138
+ };
139
+
140
+ Input.Label = LabelSlot;
141
+ Input.Note = NoteSlot;
142
+
143
+ export const Info = (props: AssetPropsWithChildren<InfoAsset>) => {
144
+ return <View type="info" {...props} />;
145
+ };
146
+
147
+ Info.Title = TitleSlot;
148
+ Info.Subtitle = SubtitleSlot;
149
+ Info.PrimaryInfo = PrimaryInfoSlot;
150
+ Info.Actions = ActionsSlot;
151
+ Info.Footer = slotFactory("footer");
152
+
153
+ export const Choice = (
154
+ props: Omit<AssetPropsWithChildren<ChoiceAsset>, "binding"> & {
155
+ /** The binding */
156
+ binding: BindingTemplateInstance;
157
+ },
158
+ ) => {
159
+ const { binding, children, ...rest } = props;
160
+ return (
161
+ <Asset type="choice" {...rest}>
162
+ <property name="binding">{binding.toValue()}</property>
163
+ {children}
164
+ </Asset>
165
+ );
166
+ };
167
+
168
+ Choice.Title = TitleSlot;
169
+ Choice.Note = NoteSlot;
170
+ Choice.Items = ItemsSlot;
171
+
172
+ const ChoiceItem = (
173
+ props: WithChildren<
174
+ WithPlayerTypes<
175
+ Omit<ChoiceItemType, "id"> & {
176
+ id?: string;
177
+ }
178
+ >
179
+ >,
180
+ ) => {
181
+ const { children, id, ...rest } = props;
182
+
183
+ return (
184
+ <ObjectWithIndexTracking>
185
+ {id && (
186
+ <property name="id">
187
+ <value>{id}</value>
188
+ </property>
189
+ )}
190
+ {!id && <GeneratedIDProperty />}
191
+ {toJsonProperties(rest, { propertiesToSkip: ["applicability"] })}
192
+ {children}
193
+ </ObjectWithIndexTracking>
194
+ );
195
+ };
196
+
197
+ ChoiceItem.Label = LabelSlot;
198
+ Choice.Item = ChoiceItem;
@@ -0,0 +1,112 @@
1
+ import React from "react";
2
+ import type { WithChildren, AssetPropsWithChildren, BindingTemplateInstance, ExpressionTemplateInstance, DSLSchema as PlayerDSLSchema, DataTypeReference, DataTypeRefs, ValidatorFunctionRefs, WithPlayerTypes } from "@player-tools/dsl";
3
+ import type { ActionAsset, TextAsset, CollectionAsset, InfoAsset, InputAsset, ImageAsset, ChoiceAsset, ChoiceItem as ChoiceItemType } from "@player-ui/reference-assets-plugin";
4
+ import { dataTypes, validators } from "@player-ui/common-types-plugin";
5
+ export declare const dataRefs: DataTypeRefs<typeof dataTypes>;
6
+ export declare const validationRefs: ValidatorFunctionRefs<typeof validators>;
7
+ export type DSLSchema = PlayerDSLSchema<DataTypeReference<typeof dataTypes, ValidatorFunctionRefs<typeof validators>>>;
8
+ export declare const Text: (props: Omit<AssetPropsWithChildren<TextAsset>, "value"> & {
9
+ value?: string;
10
+ }) => React.JSX.Element;
11
+ export declare const Collection: {
12
+ (props: AssetPropsWithChildren<CollectionAsset>): React.JSX.Element;
13
+ Values: (props: {
14
+ children?: React.ReactNode;
15
+ }) => React.JSX.Element;
16
+ Label: (props: {
17
+ children?: React.ReactNode;
18
+ }) => React.JSX.Element;
19
+ };
20
+ export declare const LabelSlot: (props: {
21
+ children?: React.ReactNode;
22
+ }) => React.JSX.Element;
23
+ export declare const ValueSlot: (props: {
24
+ children?: React.ReactNode;
25
+ }) => React.JSX.Element;
26
+ export declare const TitleSlot: (props: {
27
+ children?: React.ReactNode;
28
+ }) => React.JSX.Element;
29
+ export declare const NoteSlot: (props: {
30
+ children?: React.ReactNode;
31
+ }) => React.JSX.Element;
32
+ export declare const SubtitleSlot: (props: {
33
+ children?: React.ReactNode;
34
+ }) => React.JSX.Element;
35
+ export declare const ActionsSlot: (props: {
36
+ children?: React.ReactNode;
37
+ }) => React.JSX.Element;
38
+ export declare const PrimaryInfoSlot: (props: {
39
+ children?: React.ReactNode;
40
+ }) => React.JSX.Element;
41
+ export declare const ItemsSlot: (props: {
42
+ children?: React.ReactNode;
43
+ }) => React.JSX.Element;
44
+ export declare const Action: {
45
+ (props: Omit<AssetPropsWithChildren<ActionAsset>, "exp"> & {
46
+ /** An optional expression to execute before transitioning */
47
+ exp?: ExpressionTemplateInstance;
48
+ }): React.JSX.Element;
49
+ Label: (props: {
50
+ children?: React.ReactNode;
51
+ }) => React.JSX.Element;
52
+ };
53
+ export declare const Image: {
54
+ (props: AssetPropsWithChildren<ImageAsset>): React.JSX.Element;
55
+ Caption: (props: {
56
+ children?: React.ReactNode;
57
+ }) => React.JSX.Element;
58
+ };
59
+ export declare const Input: {
60
+ (props: Omit<AssetPropsWithChildren<InputAsset>, "binding"> & {
61
+ /** The binding */
62
+ binding: BindingTemplateInstance;
63
+ }): React.JSX.Element;
64
+ Label: (props: {
65
+ children?: React.ReactNode;
66
+ }) => React.JSX.Element;
67
+ Note: (props: {
68
+ children?: React.ReactNode;
69
+ }) => React.JSX.Element;
70
+ };
71
+ export declare const Info: {
72
+ (props: AssetPropsWithChildren<InfoAsset>): React.JSX.Element;
73
+ Title: (props: {
74
+ children?: React.ReactNode;
75
+ }) => React.JSX.Element;
76
+ Subtitle: (props: {
77
+ children?: React.ReactNode;
78
+ }) => React.JSX.Element;
79
+ PrimaryInfo: (props: {
80
+ children?: React.ReactNode;
81
+ }) => React.JSX.Element;
82
+ Actions: (props: {
83
+ children?: React.ReactNode;
84
+ }) => React.JSX.Element;
85
+ Footer: (props: {
86
+ children?: React.ReactNode;
87
+ }) => React.JSX.Element;
88
+ };
89
+ export declare const Choice: {
90
+ (props: Omit<AssetPropsWithChildren<ChoiceAsset>, "binding"> & {
91
+ /** The binding */
92
+ binding: BindingTemplateInstance;
93
+ }): React.JSX.Element;
94
+ Title: (props: {
95
+ children?: React.ReactNode;
96
+ }) => React.JSX.Element;
97
+ Note: (props: {
98
+ children?: React.ReactNode;
99
+ }) => React.JSX.Element;
100
+ Items: (props: {
101
+ children?: React.ReactNode;
102
+ }) => React.JSX.Element;
103
+ Item: {
104
+ (props: WithChildren<WithPlayerTypes<Omit<ChoiceItemType, "id"> & {
105
+ id?: string;
106
+ }>>): React.JSX.Element;
107
+ Label: (props: {
108
+ children?: React.ReactNode;
109
+ }) => React.JSX.Element;
110
+ };
111
+ };
112
+ //# sourceMappingURL=index.d.ts.map