@player-ui/reference-assets-plugin-components 0.14.1-next.0 → 0.14.1-next.2
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 +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +3 -2
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.test.tsx +83 -1
- package/src/index.tsx +7 -2
- package/types/index.d.ts +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -88,7 +88,7 @@ Collection.Values = (0, import_dsl.createSlot)({
|
|
|
88
88
|
Collection.Label = LabelSlot;
|
|
89
89
|
var Action = (props) => {
|
|
90
90
|
const { exp, children, ...rest } = props;
|
|
91
|
-
return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "action", ...rest }, /* @__PURE__ */ import_react.default.createElement("property", { name: "exp" }, exp?.toValue()), children);
|
|
91
|
+
return /* @__PURE__ */ import_react.default.createElement(import_dsl.Asset, { type: "action", ...rest }, /* @__PURE__ */ import_react.default.createElement("property", { name: "exp" }, Array.isArray(exp) ? (0, import_dsl.toJsonElement)(exp.map((e) => e.toValue())) : exp?.toValue()), children);
|
|
92
92
|
};
|
|
93
93
|
Action.Label = LabelSlot;
|
|
94
94
|
var Image = (props) => {
|
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 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
|
|
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 toJsonElement,\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 | Array<ExpressionTemplateInstance>;\n },\n) => {\n const { exp, children, ...rest } = props;\n\n return (\n <Asset type=\"action\" {...rest}>\n <property name=\"exp\">\n {Array.isArray(exp)\n ? toJsonElement(exp.map((e) => e.toValue()))\n : exp?.toValue()}\n </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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAYlB,iBASO;AAaP,iCAAsC;AAE/B,IAAM,eAAW,gCAGtB,oCAAS;AAEJ,IAAM,qBAAiB,gCAG5B,qCAAU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P,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
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
getObjectReferences,
|
|
8
8
|
toJsonProperties,
|
|
9
9
|
ObjectWithIndexTracking,
|
|
10
|
-
GeneratedIDProperty
|
|
10
|
+
GeneratedIDProperty,
|
|
11
|
+
toJsonElement
|
|
11
12
|
} from "@player-tools/dsl";
|
|
12
13
|
import { dataTypes, validators } from "@player-ui/common-types-plugin";
|
|
13
14
|
var dataRefs = getObjectReferences(dataTypes);
|
|
@@ -45,7 +46,7 @@ Collection.Values = createSlot({
|
|
|
45
46
|
Collection.Label = LabelSlot;
|
|
46
47
|
var Action = (props) => {
|
|
47
48
|
const { exp, children, ...rest } = props;
|
|
48
|
-
return /* @__PURE__ */ React.createElement(Asset, { type: "action", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "exp" }, exp?.toValue()), children);
|
|
49
|
+
return /* @__PURE__ */ React.createElement(Asset, { type: "action", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "exp" }, Array.isArray(exp) ? toJsonElement(exp.map((e) => e.toValue())) : exp?.toValue()), children);
|
|
49
50
|
};
|
|
50
51
|
Action.Label = LabelSlot;
|
|
51
52
|
var Image = (props) => {
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
getObjectReferences,
|
|
8
8
|
toJsonProperties,
|
|
9
9
|
ObjectWithIndexTracking,
|
|
10
|
-
GeneratedIDProperty
|
|
10
|
+
GeneratedIDProperty,
|
|
11
|
+
toJsonElement
|
|
11
12
|
} from "@player-tools/dsl";
|
|
12
13
|
import { dataTypes, validators } from "@player-ui/common-types-plugin";
|
|
13
14
|
var dataRefs = getObjectReferences(dataTypes);
|
|
@@ -45,7 +46,7 @@ Collection.Values = createSlot({
|
|
|
45
46
|
Collection.Label = LabelSlot;
|
|
46
47
|
var Action = (props) => {
|
|
47
48
|
const { exp, children, ...rest } = props;
|
|
48
|
-
return /* @__PURE__ */ React.createElement(Asset, { type: "action", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "exp" }, exp?.toValue()), children);
|
|
49
|
+
return /* @__PURE__ */ React.createElement(Asset, { type: "action", ...rest }, /* @__PURE__ */ React.createElement("property", { name: "exp" }, Array.isArray(exp) ? toJsonElement(exp.map((e) => e.toValue())) : exp?.toValue()), children);
|
|
49
50
|
};
|
|
50
51
|
Action.Label = LabelSlot;
|
|
51
52
|
var Image = (props) => {
|
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 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
|
|
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 toJsonElement,\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 | Array<ExpressionTemplateInstance>;\n },\n) => {\n const { exp, children, ...rest } = props;\n\n return (\n <Asset type=\"action\" {...rest}>\n <property name=\"exp\">\n {Array.isArray(exp)\n ? toJsonElement(exp.map((e) => e.toValue()))\n : exp?.toValue()}\n </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,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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;AAE3B,IAAM,SAAS,CACpB,UAIG;AACH,QAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI;AACvC,SACE,oCAAC,SAAM,MAAK,UAAU,GAAG,QACvB,oCAAC,cAAS,MAAK,aAAW,QAAQ,QAAQ,CAAE,GAC3C,QACH;AAEJ;AAEA,OAAO,QAAQ;AACf,OAAO,OAAO;AACd,OAAO,QAAQ;AAEf,IAAM,aAAa,CACjB,UAOG;AACH,QAAM,EAAE,UAAU,IAAI,GAAG,KAAK,IAAI;AAElC,SACE,oCAAC,+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.14.1-next.
|
|
9
|
+
"version": "0.14.1-next.2",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@player-ui/player": "0.14.1-next.
|
|
12
|
+
"@player-ui/player": "0.14.1-next.2",
|
|
13
13
|
"react": "^18.2.0",
|
|
14
14
|
"@types/react": "^18.2.39",
|
|
15
15
|
"@player-tools/dsl": "0.12.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@player-ui/common-types-plugin": "0.14.1-next.
|
|
19
|
-
"@player-ui/reference-assets-plugin": "0.14.1-next.
|
|
18
|
+
"@player-ui/common-types-plugin": "0.14.1-next.2",
|
|
19
|
+
"@player-ui/reference-assets-plugin": "0.14.1-next.2",
|
|
20
20
|
"tslib": "^2.6.2"
|
|
21
21
|
},
|
|
22
22
|
"module": "dist/index.legacy-esm.js",
|
package/src/index.test.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { describe, test, expect } from "vitest";
|
|
3
|
-
import { render, binding as b } from "@player-tools/dsl";
|
|
3
|
+
import { render, binding as b, expression as e } from "@player-tools/dsl";
|
|
4
4
|
import { Text, Action, Info, Collection, Input, Choice, ChatMessage } from ".";
|
|
5
5
|
|
|
6
6
|
describe("JSON serialization", () => {
|
|
@@ -324,4 +324,86 @@ describe("JSON serialization", () => {
|
|
|
324
324
|
});
|
|
325
325
|
});
|
|
326
326
|
});
|
|
327
|
+
|
|
328
|
+
describe("action", () => {
|
|
329
|
+
test("action allows for an array of expressions", async () => {
|
|
330
|
+
expect(
|
|
331
|
+
(
|
|
332
|
+
await render(
|
|
333
|
+
<Action
|
|
334
|
+
id="action"
|
|
335
|
+
exp={[
|
|
336
|
+
e`${b`local.testValue`} = 1`,
|
|
337
|
+
e`${b`local.otherValue`} = 2`,
|
|
338
|
+
]}
|
|
339
|
+
>
|
|
340
|
+
<Action.Label>
|
|
341
|
+
<Text id="text">Test</Text>
|
|
342
|
+
</Action.Label>
|
|
343
|
+
</Action>,
|
|
344
|
+
)
|
|
345
|
+
).jsonValue,
|
|
346
|
+
).toStrictEqual({
|
|
347
|
+
id: "action",
|
|
348
|
+
type: "action",
|
|
349
|
+
exp: ["{{local.testValue}} = 1", "{{local.otherValue}} = 2"],
|
|
350
|
+
label: {
|
|
351
|
+
asset: {
|
|
352
|
+
id: "text",
|
|
353
|
+
type: "text",
|
|
354
|
+
value: "Test",
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test("action allows for a single expression", async () => {
|
|
361
|
+
expect(
|
|
362
|
+
(
|
|
363
|
+
await render(
|
|
364
|
+
<Action id="action" exp={e`${b`local.testValue`} = 1`}>
|
|
365
|
+
<Action.Label>
|
|
366
|
+
<Text id="text">Test</Text>
|
|
367
|
+
</Action.Label>
|
|
368
|
+
</Action>,
|
|
369
|
+
)
|
|
370
|
+
).jsonValue,
|
|
371
|
+
).toStrictEqual({
|
|
372
|
+
id: "action",
|
|
373
|
+
type: "action",
|
|
374
|
+
exp: "{{local.testValue}} = 1",
|
|
375
|
+
label: {
|
|
376
|
+
asset: {
|
|
377
|
+
id: "text",
|
|
378
|
+
type: "text",
|
|
379
|
+
value: "Test",
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test("action allows for an undefined expression", async () => {
|
|
386
|
+
expect(
|
|
387
|
+
(
|
|
388
|
+
await render(
|
|
389
|
+
<Action id="action">
|
|
390
|
+
<Action.Label>
|
|
391
|
+
<Text id="text">Test</Text>
|
|
392
|
+
</Action.Label>
|
|
393
|
+
</Action>,
|
|
394
|
+
)
|
|
395
|
+
).jsonValue,
|
|
396
|
+
).toStrictEqual({
|
|
397
|
+
id: "action",
|
|
398
|
+
type: "action",
|
|
399
|
+
label: {
|
|
400
|
+
asset: {
|
|
401
|
+
id: "text",
|
|
402
|
+
type: "text",
|
|
403
|
+
value: "Test",
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
});
|
|
327
409
|
});
|
package/src/index.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
toJsonProperties,
|
|
19
19
|
ObjectWithIndexTracking,
|
|
20
20
|
GeneratedIDProperty,
|
|
21
|
+
toJsonElement,
|
|
21
22
|
} from "@player-tools/dsl";
|
|
22
23
|
import type { Asset as AssetType } from "@player-ui/player";
|
|
23
24
|
import type {
|
|
@@ -102,14 +103,18 @@ Collection.Label = LabelSlot;
|
|
|
102
103
|
export const Action = (
|
|
103
104
|
props: Omit<AssetPropsWithChildren<ActionAsset>, "exp"> & {
|
|
104
105
|
/** An optional expression to execute before transitioning */
|
|
105
|
-
exp?: ExpressionTemplateInstance
|
|
106
|
+
exp?: ExpressionTemplateInstance | Array<ExpressionTemplateInstance>;
|
|
106
107
|
},
|
|
107
108
|
) => {
|
|
108
109
|
const { exp, children, ...rest } = props;
|
|
109
110
|
|
|
110
111
|
return (
|
|
111
112
|
<Asset type="action" {...rest}>
|
|
112
|
-
<property name="exp">
|
|
113
|
+
<property name="exp">
|
|
114
|
+
{Array.isArray(exp)
|
|
115
|
+
? toJsonElement(exp.map((e) => e.toValue()))
|
|
116
|
+
: exp?.toValue()}
|
|
117
|
+
</property>
|
|
113
118
|
{children}
|
|
114
119
|
</Asset>
|
|
115
120
|
);
|
package/types/index.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export declare const ItemsSlot: (props: {
|
|
|
68
68
|
export declare const Action: {
|
|
69
69
|
(props: Omit<AssetPropsWithChildren<ActionAsset>, "exp"> & {
|
|
70
70
|
/** An optional expression to execute before transitioning */
|
|
71
|
-
exp?: ExpressionTemplateInstance
|
|
71
|
+
exp?: ExpressionTemplateInstance | Array<ExpressionTemplateInstance>;
|
|
72
72
|
}): React.JSX.Element;
|
|
73
73
|
Label: (props: {
|
|
74
74
|
children?: React.ReactNode;
|