@player-ui/reference-assets-plugin-components 0.10.4-next.2 → 0.10.4
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/cjs/index.cjs +7 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +6 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.test.tsx +36 -1
- package/src/index.tsx +17 -0
- package/types/index.d.ts +9 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
Action: () => Action,
|
|
34
34
|
ActionsSlot: () => ActionsSlot,
|
|
35
|
+
ChatMessage: () => ChatMessage,
|
|
35
36
|
Choice: () => Choice,
|
|
36
37
|
Collection: () => Collection,
|
|
37
38
|
Image: () => Image,
|
|
@@ -121,10 +122,16 @@ var ChoiceItem = (props) => {
|
|
|
121
122
|
};
|
|
122
123
|
ChoiceItem.Label = LabelSlot;
|
|
123
124
|
Choice.Item = ChoiceItem;
|
|
125
|
+
var ChatMessage = (props) => {
|
|
126
|
+
const { id, children } = props;
|
|
127
|
+
return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "chat-message" }, /* @__PURE__ */ import_react.default.createElement("property", { name: "id" }, id), children);
|
|
128
|
+
};
|
|
129
|
+
ChatMessage.Value = ValueSlot;
|
|
124
130
|
// Annotate the CommonJS export names for ESM import in node:
|
|
125
131
|
0 && (module.exports = {
|
|
126
132
|
Action,
|
|
127
133
|
ActionsSlot,
|
|
134
|
+
ChatMessage,
|
|
128
135
|
Choice,
|
|
129
136
|
Collection,
|
|
130
137
|
Image,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAYlB,iBAQO;
|
|
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 ChatMessageAsset,\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\nexport const ChatMessage = (\n props: Omit<AssetPropsWithChildren<ChatMessageAsset>, \"id\"> & {\n id: string;\n },\n) => {\n const { id, children } = props;\n return (\n <Asset type=\"chat-message\">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E,6BAAAA,QAAA,cAAC,0CACE,MACC,6BAAAA,QAAA,cAAC,cAAS,MAAK,QACb,6BAAAA,QAAA,cAAC,eAAO,EAAG,CACb,GAED,CAAC,MAAM,6BAAAA,QAAA,cAAC,oCAAoB,OAC5B,6BAAiB,MAAM,EAAE,kBAAkB,CAAC,eAAe,EAAE,CAAC,GAC9D,QACH;AAEJ;AAEA,WAAW,QAAQ;AACnB,OAAO,OAAO;AAEP,IAAM,cAAc,CACzB,UAGG;AACH,QAAM,EAAE,IAAI,SAAS,IAAI;AACzB,SACE,6BAAAA,QAAA,cAAC,oBAAM,MAAK,kBACV,6BAAAA,QAAA,cAAC,cAAS,MAAK,QAAM,EAAG,GACvB,QACH;AAEJ;AAEA,YAAY,QAAQ;","names":["React"]}
|
package/dist/index.legacy-esm.js
CHANGED
|
@@ -79,9 +79,15 @@ var ChoiceItem = (props) => {
|
|
|
79
79
|
};
|
|
80
80
|
ChoiceItem.Label = LabelSlot;
|
|
81
81
|
Choice.Item = ChoiceItem;
|
|
82
|
+
var ChatMessage = (props) => {
|
|
83
|
+
const { id, children } = props;
|
|
84
|
+
return /* @__PURE__ */ React.createElement(Asset, { type: "chat-message" }, /* @__PURE__ */ React.createElement("property", { name: "id" }, id), children);
|
|
85
|
+
};
|
|
86
|
+
ChatMessage.Value = ValueSlot;
|
|
82
87
|
export {
|
|
83
88
|
Action,
|
|
84
89
|
ActionsSlot,
|
|
90
|
+
ChatMessage,
|
|
85
91
|
Choice,
|
|
86
92
|
Collection,
|
|
87
93
|
Image,
|
package/dist/index.mjs
CHANGED
|
@@ -79,9 +79,15 @@ var ChoiceItem = (props) => {
|
|
|
79
79
|
};
|
|
80
80
|
ChoiceItem.Label = LabelSlot;
|
|
81
81
|
Choice.Item = ChoiceItem;
|
|
82
|
+
var ChatMessage = (props) => {
|
|
83
|
+
const { id, children } = props;
|
|
84
|
+
return /* @__PURE__ */ React.createElement(Asset, { type: "chat-message" }, /* @__PURE__ */ React.createElement("property", { name: "id" }, id), children);
|
|
85
|
+
};
|
|
86
|
+
ChatMessage.Value = ValueSlot;
|
|
82
87
|
export {
|
|
83
88
|
Action,
|
|
84
89
|
ActionsSlot,
|
|
90
|
+
ChatMessage,
|
|
85
91
|
Choice,
|
|
86
92
|
Collection,
|
|
87
93
|
Image,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +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":";AAAA,OAAO,WAAW;AAYlB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
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 ChatMessageAsset,\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\nexport const ChatMessage = (\n props: Omit<AssetPropsWithChildren<ChatMessageAsset>, \"id\"> & {\n id: string;\n },\n) => {\n const { id, children } = props;\n return (\n <Asset type=\"chat-message\">\n <property name=\"id\">{id}</property>\n {children}\n </Asset>\n );\n};\n\nChatMessage.Value = ValueSlot;\n"],"mappings":";AAAA,OAAO,WAAW;AAYlB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaP,SAAS,WAAW,kBAAkB;AAE/B,IAAM,WAAW,oBAGtB,SAAS;AAEJ,IAAM,iBAAiB,oBAG5B,UAAU;AAML,IAAM,OAAO,CAClB,UAGG;AACH,SACE,oCAAC,SAAM,MAAK,QAAQ,GAAG,SACrB,oCAAC,cAAS,MAAK,WAAS,MAAM,QAAS,CACzC;AAEJ;AAEO,IAAM,aAAa,CAAC,UAAmD;AAC5E,SAAO,oCAAC,SAAM,MAAK,cAAc,GAAG,OAAO;AAC7C;AAEA,IAAM,iBAAiB,CAAC,UAA6C;AACnE,SACE,oCAAC,kBACC,oCAAC,WAAW,QAAX,MAAmB,MAAM,QAAS,CACrC;AAEJ;AAGA,IAAM,cAAc,CAAC,MAAc,UAAU,OAAO,cAAc,SAChE,WAAW;AAAA,EACT;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEI,IAAM,YAAY,YAAY,OAAO;AACrC,IAAM,YAAY,YAAY,OAAO;AACrC,IAAM,YAAY,YAAY,OAAO;AACrC,IAAM,WAAW,YAAY,MAAM;AACnC,IAAM,eAAe,YAAY,UAAU;AAC3C,IAAM,cAAc,YAAY,WAAW,IAAI;AAC/C,IAAM,kBAAkB,YAAY,aAAa;AACjD,IAAM,YAAY,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,+BACE,MACC,oCAAC,cAAS,MAAK,QACb,oCAAC,eAAO,EAAG,CACb,GAED,CAAC,MAAM,oCAAC,yBAAoB,GAC5B,iBAAiB,MAAM,EAAE,kBAAkB,CAAC,eAAe,EAAE,CAAC,GAC9D,QACH;AAEJ;AAEA,WAAW,QAAQ;AACnB,OAAO,OAAO;AAEP,IAAM,cAAc,CACzB,UAGG;AACH,QAAM,EAAE,IAAI,SAAS,IAAI;AACzB,SACE,oCAAC,SAAM,MAAK,kBACV,oCAAC,cAAS,MAAK,QAAM,EAAG,GACvB,QACH;AAEJ;AAEA,YAAY,QAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
"types"
|
|
7
7
|
],
|
|
8
8
|
"name": "@player-ui/reference-assets-plugin-components",
|
|
9
|
-
"version": "0.10.4
|
|
9
|
+
"version": "0.10.4",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@player-ui/player": "0.10.4
|
|
12
|
+
"@player-ui/player": "0.10.4",
|
|
13
13
|
"react": "^18.2.0",
|
|
14
14
|
"@types/react": "^18.2.39",
|
|
15
15
|
"@player-tools/dsl": "0.8.1"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@player-ui/common-types-plugin": "0.10.4
|
|
19
|
-
"@player-ui/reference-assets-plugin": "0.10.4
|
|
18
|
+
"@player-ui/common-types-plugin": "0.10.4",
|
|
19
|
+
"@player-ui/reference-assets-plugin": "0.10.4",
|
|
20
20
|
"tslib": "^2.6.2"
|
|
21
21
|
},
|
|
22
22
|
"module": "dist/index.legacy-esm.js",
|
package/src/index.test.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { describe, test, expect } from "vitest";
|
|
3
3
|
import { render, binding as b } from "@player-tools/dsl";
|
|
4
|
-
import { Text, Action, Info, Collection, Input, Choice } from ".";
|
|
4
|
+
import { Text, Action, Info, Collection, Input, Choice, ChatMessage } from ".";
|
|
5
5
|
|
|
6
6
|
describe("JSON serialization", () => {
|
|
7
7
|
describe("text", () => {
|
|
@@ -289,4 +289,39 @@ describe("JSON serialization", () => {
|
|
|
289
289
|
});
|
|
290
290
|
});
|
|
291
291
|
});
|
|
292
|
+
|
|
293
|
+
describe("chat message", () => {
|
|
294
|
+
test("works for chat-message value", async () => {
|
|
295
|
+
expect(
|
|
296
|
+
(
|
|
297
|
+
await render(
|
|
298
|
+
<ChatMessage id="1">
|
|
299
|
+
<ChatMessage.Value>
|
|
300
|
+
<Text>Hello World!</Text>
|
|
301
|
+
</ChatMessage.Value>
|
|
302
|
+
</ChatMessage>,
|
|
303
|
+
)
|
|
304
|
+
).jsonValue,
|
|
305
|
+
).toStrictEqual({
|
|
306
|
+
id: "1",
|
|
307
|
+
type: "chat-message",
|
|
308
|
+
value: {
|
|
309
|
+
asset: {
|
|
310
|
+
id: "value",
|
|
311
|
+
type: "text",
|
|
312
|
+
value: "Hello World!",
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("works with value is null", async () => {
|
|
319
|
+
expect(
|
|
320
|
+
(await render(<ChatMessage id="1"></ChatMessage>)).jsonValue,
|
|
321
|
+
).toStrictEqual({
|
|
322
|
+
id: "1",
|
|
323
|
+
type: "chat-message",
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
292
327
|
});
|
package/src/index.tsx
CHANGED
|
@@ -29,6 +29,7 @@ import type {
|
|
|
29
29
|
ImageAsset,
|
|
30
30
|
ChoiceAsset,
|
|
31
31
|
ChoiceItem as ChoiceItemType,
|
|
32
|
+
ChatMessageAsset,
|
|
32
33
|
} from "@player-ui/reference-assets-plugin";
|
|
33
34
|
import { dataTypes, validators } from "@player-ui/common-types-plugin";
|
|
34
35
|
|
|
@@ -196,3 +197,19 @@ const ChoiceItem = (
|
|
|
196
197
|
|
|
197
198
|
ChoiceItem.Label = LabelSlot;
|
|
198
199
|
Choice.Item = ChoiceItem;
|
|
200
|
+
|
|
201
|
+
export const ChatMessage = (
|
|
202
|
+
props: Omit<AssetPropsWithChildren<ChatMessageAsset>, "id"> & {
|
|
203
|
+
id: string;
|
|
204
|
+
},
|
|
205
|
+
) => {
|
|
206
|
+
const { id, children } = props;
|
|
207
|
+
return (
|
|
208
|
+
<Asset type="chat-message">
|
|
209
|
+
<property name="id">{id}</property>
|
|
210
|
+
{children}
|
|
211
|
+
</Asset>
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
ChatMessage.Value = ValueSlot;
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
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";
|
|
3
|
+
import type { ActionAsset, TextAsset, CollectionAsset, InfoAsset, InputAsset, ImageAsset, ChoiceAsset, ChoiceItem as ChoiceItemType, ChatMessageAsset } from "@player-ui/reference-assets-plugin";
|
|
4
4
|
import { dataTypes, validators } from "@player-ui/common-types-plugin";
|
|
5
5
|
export declare const dataRefs: DataTypeRefs<typeof dataTypes>;
|
|
6
6
|
export declare const validationRefs: ValidatorFunctionRefs<typeof validators>;
|
|
@@ -109,4 +109,12 @@ export declare const Choice: {
|
|
|
109
109
|
}) => React.JSX.Element;
|
|
110
110
|
};
|
|
111
111
|
};
|
|
112
|
+
export declare const ChatMessage: {
|
|
113
|
+
(props: Omit<AssetPropsWithChildren<ChatMessageAsset>, "id"> & {
|
|
114
|
+
id: string;
|
|
115
|
+
}): React.JSX.Element;
|
|
116
|
+
Value: (props: {
|
|
117
|
+
children?: React.ReactNode;
|
|
118
|
+
}) => React.JSX.Element;
|
|
119
|
+
};
|
|
112
120
|
//# sourceMappingURL=index.d.ts.map
|